Preserve nested CRDT recovery and serialize compound editor submissions
This commit is contained in:
@@ -8,6 +8,14 @@ import type {
|
||||
} from "../capability-model/types.js";
|
||||
import { type ExecutionPlan, ExecutionPlanError, hexDigest } from "./plan.js";
|
||||
import { portableValueSchema } from "../bindings/portable.js";
|
||||
function preparedInputPaths(type: ValueType, path: (string | null)[] = []): (string | null)[][] {
|
||||
if (type.kind === "change") return [path];
|
||||
if (type.kind === "optional") return preparedInputPaths(type.value, path);
|
||||
if (type.kind === "list") return preparedInputPaths(type.value, [...path, null]);
|
||||
if (type.kind === "record")
|
||||
return Object.entries(type.fields).flatMap(([key, value]) => preparedInputPaths(value, [...path, key]));
|
||||
return [];
|
||||
}
|
||||
/** Small data-only interpreter input; no compiler, parser, Node module or SQL dependency reaches the browser. */
|
||||
export function compileKernelProgram(plan: ExecutionPlan): unknown {
|
||||
if (hexDigest(plan.definition) !== plan.digest)
|
||||
@@ -172,6 +180,7 @@ export function compileKernelProgram(plan: ExecutionPlan): unknown {
|
||||
: {}),
|
||||
};
|
||||
}
|
||||
const inputChanges = preparedInputPaths(operation.input);
|
||||
const input = schema(operation.input),
|
||||
output = schema(operation.output);
|
||||
return {
|
||||
@@ -183,6 +192,7 @@ export function compileKernelProgram(plan: ExecutionPlan): unknown {
|
||||
effect: operation.execution.kind,
|
||||
targets: operation.execution.kind === "remote" ? [] : operation.execution.targets,
|
||||
input,
|
||||
...(inputChanges.length ? { inputChanges } : {}),
|
||||
output,
|
||||
unsupported: unsupported ?? (input && output ? null : "UNSUPPORTED_OPERATION_CODEC"),
|
||||
binding: target,
|
||||
|
||||
Reference in New Issue
Block a user