Lower checked shared edges into the portable graph model

This commit is contained in:
Timothy J. Aveni
2026-09-25 12:34:13 -07:00
parent c482a99aca
commit 58a75da83f
6 changed files with 105 additions and 42 deletions
+27 -27
View File
@@ -22,11 +22,11 @@ export function compileKernelProgram(plan: ExecutionPlan): unknown {
if (hexDigest(plan.definition) !== plan.digest)
throw new ExecutionPlanError("INVALID_PLAN", "kernel", "Plan digest mismatch");
const workspace = plan.definition.workspace;
if (workspace.sharedAttachments.length)
if (workspace.sharedAttachments.some((attachment) => attachment.kind !== "edge"))
throw new ExecutionPlanError(
"UNSUPPORTED_SHARED_STORAGE",
"kernel",
"Stage 0 requires explicit conformance-owned storage",
"Shared scalar storage is not implemented; use conformance-owned state",
);
const schema = (type: ValueType): unknown | null => {
try {
@@ -36,7 +36,30 @@ export function compileKernelProgram(plan: ExecutionPlan): unknown {
}
};
const ownerBySlot = new Map<string, string>();
const edges: { id: string; owner: string; a: unknown; b: unknown }[] = [];
const edges: { id: string; owner: string | null; a: unknown; b: unknown }[] = [];
const lowerEdge = (storage: Extract<PersistentAttachment, { kind: "edge" }>, owner: string | null) => {
const endpoints = storage.endpoints.map((endpoint) => {
if (endpoint.ordered || (endpoint.keyType && endpoint.keyType !== "string") || endpoint.retainOther)
throw new ExecutionPlanError(
"UNSUPPORTED_GRAPH_FEATURE",
storage.id,
"Ordered relations, non-string keys and automatic retention are not implemented",
);
return {
projection: endpoint.projectionId,
constraint: {
kind: endpoint.constraint.kind,
id:
endpoint.constraint.kind === "atom" ? endpoint.constraint.atomId : endpoint.constraint.interfaceRevisionId,
},
cardinality: endpoint.cardinality,
...(endpoint.keyType ? { keyType: endpoint.keyType } : {}),
...(endpoint.onDelete ? { onDelete: endpoint.onDelete } : {}),
};
});
edges.push({ id: storage.id, owner, a: endpoints[0], b: endpoints[1] });
};
for (const storage of workspace.sharedAttachments) if (storage.kind === "edge") lowerEdge(storage, null);
const owners = plan.definition.owners.map((owner) => {
const slots: unknown[] = [];
for (const storage of owner.storage as PersistentAttachment[]) {
@@ -51,30 +74,7 @@ export function compileKernelProgram(plan: ExecutionPlan): unknown {
policy: storage.storagePolicy.kind === "register" ? "register" : "crdt",
...(Object.hasOwn(storage, "defaultValue") ? { defaultLiteral: storage.defaultValue } : {}),
});
} else {
const endpoints = storage.endpoints.map((endpoint) => {
if (endpoint.ordered || (endpoint.keyType && endpoint.keyType !== "string") || endpoint.retainOther)
throw new ExecutionPlanError(
"UNSUPPORTED_GRAPH_FEATURE",
storage.id,
"Ordered relations, non-string keys and automatic retention are not implemented",
);
return {
projection: endpoint.projectionId,
constraint: {
kind: endpoint.constraint.kind,
id:
endpoint.constraint.kind === "atom"
? endpoint.constraint.atomId
: endpoint.constraint.interfaceRevisionId,
},
cardinality: endpoint.cardinality,
...(endpoint.keyType ? { keyType: endpoint.keyType } : {}),
...(endpoint.onDelete ? { onDelete: endpoint.onDelete } : {}),
};
});
edges.push({ id: storage.id, owner: owner.id, a: endpoints[0], b: endpoints[1] });
}
} else lowerEdge(storage, owner.id);
}
return {
id: owner.id,