Compare commits
2 Commits
056b3eaa8e
...
97e91221d7
| Author | SHA1 | Date | |
|---|---|---|---|
| 97e91221d7 | |||
| 2bf0e44646 |
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"version": 1,
|
"version": 1,
|
||||||
"sourceRepo": "https://gitea-external.egads.tutti.syntaxblitz.net/quixos/quixos.git",
|
"sourceRepo": "https://gitea-external.egads.tutti.syntaxblitz.net/quixos/quixos.git",
|
||||||
"sourceCommit": "3feca0fc7f9face8c43f12dc0edbb46173059de5",
|
"sourceCommit": "ea0fcae12ae515b454cd60405dcc482415836294",
|
||||||
"sourcePath": "quixos-instance/packages/camino-package-runtime",
|
"sourcePath": "quixos-instance/packages/camino-package-runtime",
|
||||||
"exportName": "camino-package-runtime",
|
"exportName": "camino-package-runtime",
|
||||||
"mirrorRemote": "https://gitea-external.egads.tutti.syntaxblitz.net/quixos/camino-package-runtime.git"
|
"mirrorRemote": "https://gitea-external.egads.tutti.syntaxblitz.net/quixos/camino-package-runtime.git"
|
||||||
|
|||||||
+51
-5
@@ -414,6 +414,12 @@ export type RuntimeFunctionSpec<ExportName extends string = string> = {
|
|||||||
exportName: ExportName;
|
exportName: ExportName;
|
||||||
symbol: string;
|
symbol: string;
|
||||||
operation?: string;
|
operation?: string;
|
||||||
|
field?: {
|
||||||
|
name: string;
|
||||||
|
type?: string;
|
||||||
|
storage?: string;
|
||||||
|
conflict?: string;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
class AsyncEventQueue<T> implements AsyncIterableIterator<T> {
|
class AsyncEventQueue<T> implements AsyncIterableIterator<T> {
|
||||||
@@ -698,10 +704,43 @@ const derivedDependencyToProto = (dependency: DerivedDependency) =>
|
|||||||
sourceField: dependency.kind === "edges" ? dependency.sourceField ?? "" : "",
|
sourceField: dependency.kind === "edges" ? dependency.sourceField ?? "" : "",
|
||||||
});
|
});
|
||||||
|
|
||||||
const derivedEmissionToProto = (event: DerivedWatchEmission): WatchEvent =>
|
const fieldSourceForSpec = (
|
||||||
|
spec: RuntimeFunctionSpec,
|
||||||
|
objectId: string,
|
||||||
|
): LiveFieldValue<unknown>["$caminoSource"] | undefined => {
|
||||||
|
if (!spec.field) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
field: {
|
||||||
|
objectId,
|
||||||
|
fieldName: spec.field.name,
|
||||||
|
...(spec.field.type ? { fieldType: spec.field.type } : {}),
|
||||||
|
...(spec.field.storage ? { fieldStorage: spec.field.storage } : {}),
|
||||||
|
...(spec.field.conflict ? { conflictStrategy: spec.field.conflict } : {}),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const wrapFieldResult = (
|
||||||
|
spec: RuntimeFunctionSpec,
|
||||||
|
objectId: string,
|
||||||
|
value: unknown,
|
||||||
|
) => {
|
||||||
|
const source = fieldSourceForSpec(spec, objectId);
|
||||||
|
return source ? { $caminoValue: value, $caminoSource: source } : value;
|
||||||
|
};
|
||||||
|
|
||||||
|
const derivedEmissionToProtoForSpec = (
|
||||||
|
spec: RuntimeFunctionSpec,
|
||||||
|
objectId: string,
|
||||||
|
event: DerivedWatchEmission,
|
||||||
|
): WatchEvent =>
|
||||||
create(WatchEventSchema, {
|
create(WatchEventSchema, {
|
||||||
watchId: event.watchId,
|
watchId: event.watchId,
|
||||||
value: jsToProtoValue(event.value ?? null),
|
value: jsToProtoValue(
|
||||||
|
event.error ? null : wrapFieldResult(spec, objectId, event.value ?? null),
|
||||||
|
),
|
||||||
dependencies: event.dependencies.map(derivedDependencyToProto),
|
dependencies: event.dependencies.map(derivedDependencyToProto),
|
||||||
error: event.error ?? "",
|
error: event.error ?? "",
|
||||||
initial: event.initial,
|
initial: event.initial,
|
||||||
@@ -895,11 +934,16 @@ export const serveQuixosPackageRuntime = <
|
|||||||
|
|
||||||
async invoke(request) {
|
async invoke(request) {
|
||||||
try {
|
try {
|
||||||
const { runtimeFunction } = resolveRuntimeFunction(request.function);
|
const { spec, runtimeFunction } = resolveRuntimeFunction(request.function);
|
||||||
|
const value = await runtimeFunction(
|
||||||
|
params.createContext(trackingCamino, request),
|
||||||
|
);
|
||||||
return create(InvokeResponseSchema, {
|
return create(InvokeResponseSchema, {
|
||||||
ok: true,
|
ok: true,
|
||||||
result: jsToProtoValue(
|
result: jsToProtoValue(
|
||||||
await runtimeFunction(params.createContext(trackingCamino, request)),
|
spec.operation === "get"
|
||||||
|
? wrapFieldResult(spec, request.objectId, value)
|
||||||
|
: value,
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -929,7 +973,9 @@ export const serveQuixosPackageRuntime = <
|
|||||||
}
|
}
|
||||||
const sink: DerivedWatchSink = {
|
const sink: DerivedWatchSink = {
|
||||||
publish(event) {
|
publish(event) {
|
||||||
queue.push(derivedEmissionToProto(event));
|
queue.push(
|
||||||
|
derivedEmissionToProtoForSpec(spec, request.objectId, event),
|
||||||
|
);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const result = await watchSinkStorage.run(sink, async () =>
|
const result = await watchSinkStorage.run(sink, async () =>
|
||||||
|
|||||||
Reference in New Issue
Block a user