diff --git a/dist/bindings.d.ts.map b/dist/bindings.d.ts.map index 27a75e5..707de7f 100644 --- a/dist/bindings.d.ts.map +++ b/dist/bindings.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"bindings.d.ts","sourceRoot":"","sources":["../src/bindings.ts"],"names":[],"mappings":"AACA,OAAO,EAAkC,KAAK,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAChF,OAAO,EAA2B,SAAS,EACpB,KAAK,cAAc,EAAE,KAAK,cAAc,EAAE,MAAM,YAAY,CAAC;AAEpF,YAAY,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEnD,OAAO,CAAC,MAAM,UAAU,EAAE,OAAO,MAAM,CAAC;AACxC,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG;IAAE,QAAQ,CAAC,CAAC,UAAU,CAAC,EAAE,IAAI,CAAA;CAAE,CAAC;AACrE,MAAM,MAAM,cAAc,CAAC,CAAC,IAAI;IAAE,MAAM,CAAC,KAAK,EAAE,CAAC,GAAG,KAAK,CAAC;IAAC,MAAM,CAAC,KAAK,EAAE,KAAK,GAAG,CAAC,CAAA;CAAE,CAAC;AACrF,MAAM,MAAM,WAAW,GAAG,UAAU,CAAC,OAAO,SAAS,CAAC,CAAC;AAIvD,eAAO,MAAM,uBAAuB,EAAE,cAAc,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAS3E,CAAC;AACF,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,CAAC,SAAS,cAAc,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAC5E,MAAM,MAAM,SAAS,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAC7D,MAAM,MAAM,SAAS,CAAC,CAAC,EAAE,CAAC,IAAI;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,GAAG,EAAE,SAAS,CAAC,CAAC,EAAE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AE,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,WAAW,CAAC;IAAC,UAAU,EAAE,MAAM,EAAE,CAAA;CAAE,GAC3E;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,EAAE,CAAA;CAAE,GAClD;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAA;CAAE,GAC9E;IAAE,IAAI,EAAE,aAAa,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,WAAW,CAAA;CAAE,CAAC;AAChE,MAAM,MAAM,aAAa,GAAG;IAC1B,SAAS,EAAE,WAAW,CAAC;IACvB,UAAU,EAAE,WAAW,CAAC;IACxB,SAAS,CAAC,EAAE,WAAW,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;CACnC,CAAC;AACF,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC;AAG7D,eAAO,MAAM,aAAa,SAAU,WAAW,SAAS,KAAK,GAAG,SAAS,YAAY,UAAU,KAAG,GAyCjG,CAAC;AAOF,eAAO,MAAM,aAAa,SAAU,WAAW,SAAS,GAAG,YAAY,UAAU,KAAG,KA8BnF,CAAC;AAmBF,uFAAuF;AACvF,eAAO,MAAM,aAAa,GAAI,CAAC,EAAE,CAAC,QAC1B,aAAa,WACV,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,YAChC,UAAU,KACnB,cAAc,GAAG,cA4GnB,CAAC"} \ No newline at end of file diff --git a/dist/bindings.js b/dist/bindings.js index a023e83..f00ec7a 100644 --- a/dist/bindings.js +++ b/dist/bindings.js @@ -1,6 +1,6 @@ import { create } from "@bufbuild/protobuf"; import { ValueSchema, ObjectValueSchema } from "./camino/api_pb.js"; -import { derived, jsToProtoValue, liveValue, protoValueToJs } from "./index.js"; +import { derived, jsToProtoValue, liveValue, protoValueToJs, } from "./index.js"; import { assertReferenceFree, referenceToWire } from "./references.js"; const reactPropsDescriptor = "org.quixos.web-studio.ReactProps"; // Explicit temporary props exception, matching orch's RPC contract. Field shapes @@ -111,8 +111,9 @@ export const encodeQxValue = (type, value, messages) => { }; const inputValue = (context, type) => { if (type.kind === "message" || type.kind === "record") - return create(ValueSchema, { kind: { case: "objectValue", - value: create(ObjectValueSchema, { fields: context.inputProto }) } }); + return create(ValueSchema, { + kind: { case: "objectValue", value: create(ObjectValueSchema, { fields: context.inputProto }) }, + }); return context.inputProto.value; }; const inputFields = (type, value, messages) => { @@ -133,37 +134,86 @@ export const bindQxHandler = (spec, handler, messages) => { switch (port.kind) { case "state": { const state = raw.state(port.id); - return [name, { - ...(port.primitives.includes("read") ? { get: async () => decodeQxValue(port.valueType, (await state.live()).$quixosValue, messages), live: () => state.live() } : {}), - ...(port.primitives.includes("write") ? { set: async (value) => state.set(liveValue(encodeQxValue(port.valueType, value, messages))) } : {}), - }]; + return [ + name, + { + ...(port.primitives.includes("read") + ? { + get: async () => decodeQxValue(port.valueType, (await state.live()).$quixosValue, messages), + live: () => state.live(), + } + : {}), + ...(port.primitives.includes("write") + ? { + set: async (value) => state.set(liveValue(encodeQxValue(port.valueType, value, messages))), + } + : {}), + }, + ]; } case "edge": { const edge = raw.edge(port.id); - return [name, { ...Object.fromEntries(port.primitives.map((primitive) => [primitive, edge[primitive]])), + return [ + name, + { + ...Object.fromEntries(port.primitives.map((primitive) => [ + primitive, + edge[primitive], + ])), ...(port.primitives.includes("resolve") ? { collection: edge.collection } : {}), - ...(port.primitives.includes("resolve") && port.primitives.includes("connect") && port.primitives.includes("disconnect") ? { replace: edge.replace } : {}) }]; + ...(port.primitives.includes("resolve") && + port.primitives.includes("connect") && + port.primitives.includes("disconnect") + ? { replace: edge.replace } + : {}), + }, + ]; } case "interface": { const target = raw.interface(port.id); - return [name, { objectId: target.objectId, - live: Object.fromEntries(Object.entries(port.operations).map(([name, operation]) => [name, + return [ + name, + { + objectId: target.objectId, + live: Object.fromEntries(Object.entries(port.operations).map(([name, operation]) => [ + name, (input) => target.live(operation.id, inputFields(operation.inputType, input, messages)), ])), - ...Object.fromEntries(Object.entries(port.operations).map(([name, operation]) => [name, - async (input) => decodeQxValue(operation.outputType, (await target.live(operation.id, inputFields(operation.inputType, input, messages))).$quixosValue, messages), - ])) }]; + ...Object.fromEntries(Object.entries(port.operations).map(([name, operation]) => [ + name, + async (input) => decodeQxValue(operation.outputType, (await target.live(operation.id, inputFields(operation.inputType, input, messages))) + .$quixosValue, messages), + ])), + }, + ]; } - case "constructor": return [name, { construct: (input) => raw.constructor(port.id).construct(inputFields(port.inputType, input, messages)) }]; + case "constructor": + return [ + name, + { + construct: (input) => raw.constructor(port.id).construct(inputFields(port.inputType, input, messages)), + }, + ]; } })); - return { objectId: raw.objectId, signal: raw.signal, - ...(raw.openSession ? { openSession: async () => { - const session = await raw.openSession(); - return { id: session.id, close: () => session.close(), - run: (work) => session.run((next) => work(bindContext(next))) }; - } } : {}), - input: decodeQxValue(spec.inputType, inputValue(raw, spec.inputType), messages), ports }; + return { + objectId: raw.objectId, + signal: raw.signal, + ...(raw.openSession + ? { + openSession: async () => { + const session = await raw.openSession(); + return { + id: session.id, + close: () => session.close(), + run: (work) => session.run((next) => work(bindContext(next))), + }; + }, + } + : {}), + input: decodeQxValue(spec.inputType, inputValue(raw, spec.inputType), messages), + ports, + }; }; const execute = async (raw) => { const context = bindContext(raw); diff --git a/dist/index.d.ts b/dist/index.d.ts index cbd3426..3023fa0 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -2,7 +2,7 @@ import http from "node:http"; import { type QxObjectRef } from "./references.js"; export * from "./bindings.js"; export { relationshipMap, relationshipList, relationshipSet } from "./relationships.js"; -export { createMigrationContext, migrationObjectId, serveMigration, type MigrationContext, type MigrationInput, type MigrationOutput, type MigrationEdge } from "./migration.js"; +export { createMigrationContext, migrationObjectId, serveMigration, type MigrationContext, type MigrationInput, type MigrationOutput, type MigrationEdge, } from "./migration.js"; import { type Client, type ConnectRouter } from "@connectrpc/connect"; import { CaminoService, type Value } from "./camino/api_pb.js"; import { OrchestratorRuntime } from "./quixos/orch_pb.js"; diff --git a/dist/index.d.ts.map b/dist/index.d.ts.map index 7768e9d..ca712e6 100644 --- a/dist/index.d.ts.map +++ b/dist/index.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAG7B,OAAO,EAA8E,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC/H,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAC,eAAe,EAAE,gBAAgB,EAAE,eAAe,EAAC,MAAM,oBAAoB,CAAC;AAGtF,OAAO,EAAC,sBAAsB,EAAE,iBAAiB,EAAE,cAAc,EAAE,KAAK,gBAAgB,EAAE,KAAK,cAAc,EAAE,KAAK,eAAe,EAAE,KAAK,aAAa,EAAC,MAAM,gBAAgB,CAAC;AAE/K,OAAO,EAAoC,KAAK,MAAM,EAAE,KAAK,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAExG,OAAO,EACL,aAAa,EAOb,KAAK,KAAK,EACX,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAU1D,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,OAAO,aAAa,CAAC,CAAC;AACxD,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAE5D,MAAM,MAAM,iBAAiB,GACzB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;C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A;CAAE,CAAC;AACtE,eAAO,MAAM,OAAO,QAAS,cAAc,KAAG,cAA4C,CAAC;AA0B3F,eAAO,MAAM,0BAA0B,WAAY;IACjD,iBAAiB,EAAE,MAAM,CAAC;IAC1B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,GAAG,cAAc,CAAC,CAAC;IACzD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,cAwJiB,aAAa,kBAgN9B,CAAC;AAEF,eAAO,MAAM,mBAAmB,WAAY;IAC1C,iBAAiB,EAAE,MAAM,CAAC;IAC1B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,GAAG,cAAc,CAAC,CAAC;CAC1D,yEAaA,CAAC;AACF,KAAK,cAAc,GAAG;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAC7B,YAAY,EAAE,OAAO,qBAAqB,EAAE,kBAAkB,EAAE,CAAC;CAClE,CAAC"} \ No newline at end of file diff --git a/dist/index.js b/dist/index.js index 248ec48..106e5fa 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,12 +1,12 @@ import http from "node:http"; import { readFileSync } from "node:fs"; import { createInvocationRegistry } from "./invocations.js"; -import { isObjectReference, referenceFromWire, referenceToWire, assertReferenceFree } from "./references.js"; +import { isObjectReference, referenceFromWire, referenceToWire, assertReferenceFree, } from "./references.js"; export * from "./bindings.js"; export { relationshipMap, relationshipList, relationshipSet } from "./relationships.js"; import { AsyncLocalStorage } from "node:async_hooks"; import { createHmac, randomBytes, randomUUID, timingSafeEqual } from "node:crypto"; -export { createMigrationContext, migrationObjectId, serveMigration } from "./migration.js"; +export { createMigrationContext, migrationObjectId, serveMigration, } from "./migration.js"; import { create, equals } from "@bufbuild/protobuf"; import { Code, ConnectError, createClient } from "@connectrpc/connect"; import { connectNodeAdapter, createConnectTransport } from "@connectrpc/connect-node"; @@ -27,13 +27,20 @@ const recordDependency = async (dependency) => { const bytesToBase64 = (value) => Buffer.from(value).toString("base64"); const base64ToBytes = (value) => Buffer.from(value, "base64"); const isRecord = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value); -const isWrappedValue = (value) => isRecord(value) && "$quixosValue" in value && - isRecord(value.$quixosValue) && value.$quixosValue.$typeName === "camino.Value"; -export const objectRef = (reference) => { referenceToWire(reference); return reference; }; +const isWrappedValue = (value) => isRecord(value) && + "$quixosValue" in value && + isRecord(value.$quixosValue) && + value.$quixosValue.$typeName === "camino.Value"; +export const objectRef = (reference) => { + referenceToWire(reference); + return reference; +}; export const liveValue = (value) => ({ $quixosValue: value }); export const jsToProtoValue = (value) => { if (isObjectReference(value)) - return create(ValueSchema, { kind: { case: "refValue", value: create(RefValueSchema, { objectId: referenceToWire(value) }) } }); + return create(ValueSchema, { + kind: { case: "refValue", value: create(RefValueSchema, { objectId: referenceToWire(value) }) }, + }); if (isWrappedValue(value)) return value.$quixosValue; if (value === null || value === undefined) { @@ -56,49 +63,65 @@ export const jsToProtoValue = (value) => { } if (isRecord(value) && "$quixosRef" in value) throw new Error("Raw ID wrappers are not object references"); - if (isRecord(value) && typeof value.$quixosCrdtType === "string" && - typeof value.$quixosCrdtPayload === "string") { + if (isRecord(value) && typeof value.$quixosCrdtType === "string" && typeof value.$quixosCrdtPayload === "string") { return create(ValueSchema, { - kind: { case: "crdtValue", value: create(CrdtValueSchema, { + kind: { + case: "crdtValue", + value: create(CrdtValueSchema, { type: value.$quixosCrdtType, encoding: typeof value.$quixosCrdtEncoding === "string" ? value.$quixosCrdtEncoding : "base64", payload: base64ToBytes(value.$quixosCrdtPayload), - }) }, + }), + }, }); } if (!isRecord(value)) throw new Error(`Unsupported runtime value ${typeof value}`); return create(ValueSchema, { - kind: { case: "objectValue", value: create(ObjectValueSchema, { + kind: { + case: "objectValue", + value: create(ObjectValueSchema, { fields: Object.fromEntries(Object.entries(value).map(([key, entry]) => [key, jsToProtoValue(entry)])), - }) }, + }), + }, }); }; export const protoValueToJs = (value) => { switch (value?.kind.case) { case "nullValue": - case undefined: return null; + case undefined: + return null; case "boolValue": case "numberValue": case "stringValue": - case "integerValue": return value.kind.value; - case "bytesValue": return bytesToBase64(value.kind.value); - case "refValue": return referenceFromWire(value.kind.value.objectId); - case "listValue": return value.kind.value.values.map(protoValueToJs); - case "objectValue": return Object.fromEntries(Object.entries(value.kind.value.fields).map(([key, entry]) => [key, protoValueToJs(entry)])); - case "crdtValue": return { - $quixosCrdtType: value.kind.value.type, - $quixosCrdtEncoding: value.kind.value.encoding, - $quixosCrdtPayload: bytesToBase64(value.kind.value.payload), - }; + case "integerValue": + return value.kind.value; + case "bytesValue": + return bytesToBase64(value.kind.value); + case "refValue": + return referenceFromWire(value.kind.value.objectId); + case "listValue": + return value.kind.value.values.map(protoValueToJs); + case "objectValue": + return Object.fromEntries(Object.entries(value.kind.value.fields).map(([key, entry]) => [key, protoValueToJs(entry)])); + case "crdtValue": + return { + $quixosCrdtType: value.kind.value.type, + $quixosCrdtEncoding: value.kind.value.encoding, + $quixosCrdtPayload: bytesToBase64(value.kind.value.payload), + }; } }; export const protoFieldsToJs = (fields) => Object.fromEntries(Object.entries(fields).map(([key, value]) => [key, protoValueToJs(value)])); export class RuntimeAuthorityError extends Error { retryable; - constructor(message) { super(message); this.name = "RuntimeAuthorityError"; this.retryable = /WORKSPACE_FENCED|STALE_EPOCH/.test(message); } + constructor(message) { + super(message); + this.name = "RuntimeAuthorityError"; + this.retryable = /WORKSPACE_FENCED|STALE_EPOCH/.test(message); + } } -const targetForEdge = (edge, projectionId) => edge.firstProjectionId === projectionId ? edge.secondObjectId : edge.firstObjectId; +const targetForEdge = (edge, projectionId) => (edge.firstProjectionId === projectionId ? edge.secondObjectId : edge.firstObjectId); export const createRuntimeContext = (camino, orch, request) => { const ports = new Map(); for (const dependency of request.dependencies) { @@ -130,25 +153,55 @@ export const createRuntimeContext = (camino, orch, request) => { case "edge": { const { edgeTypeId, projectionId } = dependency.binding.value; const dependencyObjectId = dependency.objectId || request.objectId; - const collectionResult = (response) => ({ revision: response.revision, - entries: response.entries.map((entry) => ({ edgeId: entry.edgeId, target: referenceFromWire(entry.targetObjectId), - ...(entry.key ? { key: entry.key.kind.case === "integerValue" ? BigInt(entry.key.kind.value) : protoValueToJs(entry.key) } : {}) })) }); + const collectionResult = (response) => ({ + revision: response.revision, + entries: response.entries.map((entry) => ({ + edgeId: entry.edgeId, + target: referenceFromWire(entry.targetObjectId), + ...(entry.key + ? { + key: entry.key.kind.case === "integerValue" + ? BigInt(entry.key.kind.value) + : protoValueToJs(entry.key), + } + : {}), + })), + }); const edge = { edgeTypeId, projectionId, async collection() { - await recordDependency({ kind: "edge", objectId: dependencyObjectId, attachmentId: edgeTypeId, projectionId }); + await recordDependency({ + kind: "edge", + objectId: dependencyObjectId, + attachmentId: edgeTypeId, + projectionId, + }); return collectionResult(await camino.readCollection({ objectId: dependencyObjectId, edgeTypeId, projectionId })); }, async replace(entries, expectedRevision) { - return collectionResult(await camino.replaceCollection({ objectId: dependencyObjectId, edgeTypeId, projectionId, expectedRevision, + return collectionResult(await camino.replaceCollection({ + objectId: dependencyObjectId, + edgeTypeId, + projectionId, + expectedRevision, entries: entries.map((entry) => { assertReferenceFree(entry.key); - return { edgeId: entry.edgeId ?? "", targetObjectId: referenceToWire(entry.target), key: entry.key === undefined ? undefined : jsToProtoValue(entry.key) }; - }) })); + return { + edgeId: entry.edgeId ?? "", + targetObjectId: referenceToWire(entry.target), + key: entry.key === undefined ? undefined : jsToProtoValue(entry.key), + }; + }), + })); }, async resolve() { - await recordDependency({ kind: "edge", objectId: dependencyObjectId, attachmentId: edgeTypeId, projectionId }); + await recordDependency({ + kind: "edge", + objectId: dependencyObjectId, + attachmentId: edgeTypeId, + projectionId, + }); const result = await camino.resolveEdge({ objectId: dependencyObjectId, edgeTypeId, projectionId }); return result.edges.map((entry) => referenceFromWire(targetForEdge(entry, projectionId))); }, @@ -265,8 +318,10 @@ const protoDependencies = (dependencies) => dependencies.map((entry) => create(D export const createPackageRuntimeRoutes = (config) => { const invocations = createInvocationRegistry(); const headers = {}; - const processToken = process.env.CAMINO_RUNTIME_AUTH_TOKEN ?? (process.env.CAMINO_RUNTIME_AUTH_TOKEN_FILE - ? readFileSync(process.env.CAMINO_RUNTIME_AUTH_TOKEN_FILE, "utf8").trim() : ""); + const processToken = process.env.CAMINO_RUNTIME_AUTH_TOKEN ?? + (process.env.CAMINO_RUNTIME_AUTH_TOKEN_FILE + ? readFileSync(process.env.CAMINO_RUNTIME_AUTH_TOKEN_FILE, "utf8").trim() + : ""); if (processToken) { headers["x-camino-runtime-token"] = processToken; } @@ -276,12 +331,14 @@ export const createPackageRuntimeRoutes = (config) => { const camino = createClient(CaminoService, createConnectTransport({ baseUrl: config.caminoUrl ?? process.env.CAMINO_URL ?? "http://127.0.0.1:7310", httpVersion: "1.1", - interceptors: headers["x-camino-runtime-token"] ? [ - (next) => async (request) => { - request.header.set("x-camino-runtime-token", headers["x-camino-runtime-token"]); - return await next(request); - }, - ] : [], + interceptors: headers["x-camino-runtime-token"] + ? [ + (next) => async (request) => { + request.header.set("x-camino-runtime-token", headers["x-camino-runtime-token"]); + return await next(request); + }, + ] + : [], })); const orch = createClient(OrchestratorRuntime, createConnectTransport({ baseUrl: config.orchUrl ?? process.env.QUIXOS_ORCH_URL ?? "http://127.0.0.1:7311", @@ -298,16 +355,23 @@ export const createPackageRuntimeRoutes = (config) => { }; const clientsFor = (request) => { const context = request.context; - if (process.env.QUIXOS_RUNTIME_INSTANCE_ID && (!context?.grant || context.instanceId !== process.env.QUIXOS_RUNTIME_INSTANCE_ID || !context.workspaceEpoch)) { + if (process.env.QUIXOS_RUNTIME_INSTANCE_ID && + (!context?.grant || context.instanceId !== process.env.QUIXOS_RUNTIME_INSTANCE_ID || !context.workspaceEpoch)) { throw new ConnectError("Managed invocation requires an exact instance and epoch grant", Code.Unauthenticated); } if (!context?.grant) return { camino, orch }; - const transport = (url) => createConnectTransport({ baseUrl: url, httpVersion: "1.1", interceptors: [(next) => async (call) => { + const transport = (url) => createConnectTransport({ + baseUrl: url, + httpVersion: "1.1", + interceptors: [ + (next) => async (call) => { call.header.set("x-quixos-invocation-grant", context.grant); call.header.set("x-camino-runtime-token", processToken); return next(call); - }] }); + }, + ], + }); return { camino: createClient(CaminoService, transport(config.caminoUrl ?? process.env.CAMINO_URL ?? "http://127.0.0.1:7310")), orch: createClient(OrchestratorRuntime, transport(config.orchUrl ?? process.env.QUIXOS_ORCH_URL ?? "http://127.0.0.1:7311")), @@ -315,9 +379,12 @@ export const createPackageRuntimeRoutes = (config) => { }; const runtimeControl = async (operation, input) => { const response = await fetch(`${config.caminoUrl ?? process.env.CAMINO_URL ?? "http://127.0.0.1:7310"}/__runtime/${operation}`, { - method: "POST", headers: { "content-type": "application/json", "x-camino-runtime-token": processToken }, body: JSON.stringify(input), signal: AbortSignal.timeout(10_000), + method: "POST", + headers: { "content-type": "application/json", "x-camino-runtime-token": processToken }, + body: JSON.stringify(input), + signal: AbortSignal.timeout(10_000), }); - const value = await response.json(); + const value = (await response.json()); if (!response.ok) throw new RuntimeAuthorityError(value.error ?? "Runtime authority request failed"); return value; @@ -327,8 +394,13 @@ export const createPackageRuntimeRoutes = (config) => { return; runtimeContext.openSession = async () => { const ownerId = request.context.ownerConformanceId; - const registration = { grant: request.context.grant, objectId: request.objectId, ownerId, - sessionId: `session:${randomBytes(16).toString("hex")}`, token: randomBytes(32).toString("base64url") }; + const registration = { + grant: request.context.grant, + objectId: request.objectId, + ownerId, + sessionId: `session:${randomBytes(16).toString("hex")}`, + token: randomBytes(32).toString("base64url"), + }; const register = () => runtimeControl("register-session", registration); const registered = await register().catch((error) => { // Retry a transport/lost-response failure with exactly the same identity. @@ -347,7 +419,10 @@ export const createPackageRuntimeRoutes = (config) => { // by the caller without replaying a side-effecting callback. const grant = await runtimeControl("acquire-session", registered); const execution = invocations.begin(grant.invocationId); - const sessionRequest = { ...request, context: { grant: grant.grant, instanceId: grant.instanceId, workspaceEpoch: grant.epoch } }; + const sessionRequest = { + ...request, + context: { grant: grant.grant, instanceId: grant.instanceId, workspaceEpoch: grant.epoch }, + }; const clients = clientsFor(sessionRequest); const context = createRuntimeContext(clients.camino, clients.orch, sessionRequest); context.signal = execution.signal; @@ -359,7 +434,10 @@ export const createPackageRuntimeRoutes = (config) => { await runtimeControl("complete-invocation", { invocationId: grant.invocationId }).catch((error) => console.error("Session completion will be reconciled by the host", error)); } }, - async close() { await runtimeControl("close-session", registered); closed = true; }, + async close() { + await runtimeControl("close-session", registered); + closed = true; + }, }; }; }; @@ -370,9 +448,15 @@ export const createPackageRuntimeRoutes = (config) => { exportIds: Object.keys(config.exports), capabilities: ["invocation-completion-v1", "instance-authentication-v1", "epoch-grants-v1"], instanceId: process.env.QUIXOS_RUNTIME_INSTANCE_ID ?? "", - authenticationProof: request.nonce && processToken ? createHmac("sha256", processToken) - .update(JSON.stringify([request.nonce, process.env.QUIXOS_RUNTIME_INSTANCE_ID ?? "", config.packageRevisionId])) - .digest("hex") : "", + authenticationProof: request.nonce && processToken + ? createHmac("sha256", processToken) + .update(JSON.stringify([ + request.nonce, + process.env.QUIXOS_RUNTIME_INSTANCE_ID ?? "", + config.packageRevisionId, + ])) + .digest("hex") + : "", }), getInvocationStatus: (request, context) => { authenticateInstance(context.requestHeader); @@ -437,7 +521,12 @@ export const createPackageRuntimeRoutes = (config) => { return await pending; const establish = (async () => { const controller = new AbortController(); - const stream = camino.watchObject({ objectId: dependency.objectId, includeSnapshot: true, attachmentIds: request.context?.grant ? [dependency.attachmentId] : [] }, { signal: controller.signal })[Symbol.asyncIterator](); + const stream = camino + .watchObject({ + objectId: dependency.objectId, + includeSnapshot: true, + attachmentIds: request.context?.grant ? [dependency.attachmentId] : [], + }, { signal: controller.signal })[Symbol.asyncIterator](); try { // Camino subscribes before producing the snapshot, so once this // resolves the following state/edge read cannot race the stream. @@ -507,10 +596,7 @@ export const createPackageRuntimeRoutes = (config) => { await abort; break; } - const outcome = await Promise.race([ - ...[...subscriptions.values()].map((entry) => entry.next), - abort, - ]); + const outcome = await Promise.race([...[...subscriptions.values()].map((entry) => entry.next), abort]); if (outcome === "abort") break; const subscription = subscriptions.get(outcome.key); diff --git a/dist/invocations.d.ts.map b/dist/invocations.d.ts.map index e8eaf0d..6a35a0f 100644 --- a/dist/invocations.d.ts.map +++ b/dist/invocations.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"invocations.d.ts","sourceRoot":"","sources":["../src/invocations.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,eAAO,MAAM,wBAAwB;IAGjC,KAAK,KAAK,MAAM;QAOL,MAAM;QAA2B,MAAM;;IAElD,MAAM,KAAK,MAAM;QAAa,YAAY;QAAM,KAAK;;IACrD,MAAM,KAAK,MAAM;;;;CASpB,CAAC"} \ No newline at end of file +{"version":3,"file":"invocations.d.ts","sourceRoot":"","sources":["../src/invocations.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,eAAO,MAAM,wBAAwB;IAGjC,KAAK,KAAK,MAAM;QASZ,MAAM;QACN,MAAM;;IAKV,MAAM,KAAK,MAAM;QACN,YAAY;QAAM,KAAK;;IAElC,MAAM,KAAK,MAAM;;;;CASpB,CAAC"} \ No newline at end of file diff --git a/dist/invocations.js b/dist/invocations.js index 25280b9..7013233 100644 --- a/dist/invocations.js +++ b/dist/invocations.js @@ -11,9 +11,16 @@ export const createInvocationRegistry = () => { throw new Error("Invocation registry full; explicit runtime retirement required"); const entry = { state: "running", controller: new AbortController() }; entries.set(id, entry); - return { signal: entry.controller.signal, finish(failed = false) { entry.state = failed ? "failed" : "completed"; } }; + return { + signal: entry.controller.signal, + finish(failed = false) { + entry.state = failed ? "failed" : "completed"; + }, + }; + }, + status(id) { + return { invocationId: id, state: entries.get(id)?.state ?? "unknown" }; }, - status(id) { return { invocationId: id, state: entries.get(id)?.state ?? "unknown" }; }, cancel(id) { const entry = entries.get(id); if (entry && ["running", "cancellation-requested"].includes(entry.state)) { diff --git a/dist/migration.d.ts.map b/dist/migration.d.ts.map index e003bdd..0d94e01 100644 --- a/dist/migration.d.ts.map +++ b/dist/migration.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"migration.d.ts","sourceRoot":"","sources":["../src/migration.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,cAAc,GAAG;IAC3B,aAAa,EAAE,CAAC,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IACxD,KAAK,EAAE;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,KAAK,GAAG,KAAK,CAAC;QAAC,MAAM,EAAE,CAAC,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,MAAM,CAAC,EAAE,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAC5H,cAAc,CAAC,EAAE,MAAM,CAAC;QAAC,YAAY,CAAC,EAAE,OAAO,CAAC;QAChD,MAAM,CAAC,EAAE;YAAC,QAAQ,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,OAAO,CAAA;SAAC,EAAE,CAAC;QAAC,KAAK,CAAC,EAAE,aAAa,EAAE,CAAA;KAAC,EAAE,CAAC;CAC7E,CAAC;AACF,MAAM,MAAM,aAAa,GAAG;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAC;IAAC,cAAc,EAAE,MAAM,CAAC;IAAC,iBAAiB,EAAE,MAAM,CAAC;IAAC,kBAAkB,EAAE,MAAM,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAAC,aAAa,CAAC,EAAE,MAAM,CAAA;CAAC,CAAC;AACjQ,MAAM,MAAM,eAAe,GAAG;IAAC,aAAa,EAAE,CA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H,CAAC"} \ No newline at end of file diff --git a/dist/migration.js b/dist/migration.js index 5bf1173..db59b78 100644 --- a/dist/migration.js +++ b/dist/migration.js @@ -1,11 +1,21 @@ import { createHash } from "node:crypto"; -export const migrationObjectId = (executionId, port, logicalKey) => `obj:migration:${createHash("sha256").update(JSON.stringify([executionId, port, logicalKey])).digest("hex")}`; +export const migrationObjectId = (executionId, port, logicalKey) => `obj:migration:${createHash("sha256") + .update(JSON.stringify([executionId, port, logicalKey])) + .digest("hex")}`; /** No ordinary RuntimeContext or network/database clients are supplied here. * Process isolation belongs to the host, not this convenience API. */ export const createMigrationContext = (input) => { - if (input.schemaVersion !== 1 || !input.executionId || new Set(input.ports.map((entry) => entry.name)).size !== input.ports.length) + if (input.schemaVersion !== 1 || + !input.executionId || + new Set(input.ports.map((entry) => entry.name)).size !== input.ports.length) throw new Error("Invalid migration input"); - const output = { schemaVersion: 1, executionId: input.executionId, writes: [], creates: [], edgeReplacements: [] }; + const output = { + schemaVersion: 1, + executionId: input.executionId, + writes: [], + creates: [], + edgeReplacements: [], + }; const port = (name, access) => { const selected = input.ports.find((entry) => entry.name === name); if (!selected?.access.includes(access) || (selected.view === "old" && access !== "read")) @@ -17,7 +27,8 @@ export const createMigrationContext = (input) => { const selected = port(name, "read"), states = structuredClone(selected.states ?? []); if (selected.view === "new" && Object.hasOwn(selected, "defaultValue")) for (const helper of output.creates) { - if (input.ports.find((entry) => entry.name === helper.port)?.atomId === selected.attachedAtomId && !states.some((entry) => entry.objectId === helper.objectId)) + if (input.ports.find((entry) => entry.name === helper.port)?.atomId === selected.attachedAtomId && + !states.some((entry) => entry.objectId === helper.objectId)) states.push({ objectId: helper.objectId, value: structuredClone(selected.defaultValue) }); } if (selected.view === "new") @@ -30,9 +41,11 @@ export const createMigrationContext = (input) => { else states[existing] = entry; } - return states.sort((a, b) => a.objectId < b.objectId ? -1 : a.objectId > b.objectId ? 1 : 0); + return states.sort((a, b) => (a.objectId < b.objectId ? -1 : a.objectId > b.objectId ? 1 : 0)); + }, + read(name, objectId) { + return context.enumerate(name).find((entry) => entry.objectId === objectId)?.value; }, - read(name, objectId) { return context.enumerate(name).find((entry) => entry.objectId === objectId)?.value; }, write(name, objectId, value) { port(name, "write"); const previous = output.writes.findIndex((entry) => entry.port === name && entry.objectId === objectId); @@ -53,7 +66,9 @@ export const createMigrationContext = (input) => { }, edges(name) { const selected = port(name, "read"); - const replacement = selected.view === "new" ? output.edgeReplacements.find((entry) => input.ports.find((candidate) => candidate.name === entry.port)?.binding === selected.binding) : undefined; + const replacement = selected.view === "new" + ? output.edgeReplacements.find((entry) => input.ports.find((candidate) => candidate.name === entry.port)?.binding === selected.binding) + : undefined; return structuredClone(replacement?.edges ?? selected.edges ?? []); }, replaceEdges(name, edges) { diff --git a/dist/references.d.ts.map b/dist/references.d.ts.map index 9fa618a..1b5f0d3 100644 --- a/dist/references.d.ts.map +++ b/dist/references.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"references.d.ts","sourceRoot":"","sources":["../src/references.ts"],"names":[],"mappings":"AAGA,OAAO,CAAC,MAAM,cAAc,EAAE,OAAO,MAAM,CAAC;AAC5C,MAAM,WAAW,WAAW,CAAC,QAAQ,SAAS,MAAM,GAAG,MAAM;IAC3D,QAAQ,CAAC,CAAC,cAAc,CAAC,EAAE;QAAC,QAAQ,EAAE,CAAC,IAAI,QAAQ,GAAG,IAAI;KAAC,CAAC;IAC5D,MAAM,CAAC,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC;CAC7C;AAQD,eAAO,MAAM,iBAAiB,UAAW,OAAO,KAAG,KAAK,IAAI,WACU,CAAC;AAEvE,kFAAkF;AAClF,eAAO,MAAM,iBAAiB,OAAQ,MAAM,KAAG,WAG9C,CAAC;AACF,eAAO,MAAM,eAAe,UAAW,OAAO,KAAG,MAGhD,CAAC;AACF,eAAO,MAAM,mBAAmB,UAAW,OAAO,yBAA6B,IAO9E,CAAC"} \ No newline at end of file +{"version":3,"file":"references.d.ts","sourceRoot":"","sources":["../src/references.ts"],"names":[],"mappings":"AAGA,OAAO,CAAC,MAAM,cAAc,EAAE,OAAO,MAAM,CAAC;AAC5C,MAAM,WAAW,WAAW,CAAC,QAAQ,SAAS,MAAM,GAAG,MAAM;IAC3D,QAAQ,CAAC,CAAC,cAAc,CAAC,EAAE;QAAE,QAAQ,EAAE,CAAC,IAAI,QAAQ,GAAG,IAAI;KAAE,CAAC;IAC9D,MAAM,CAAC,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC;CAC7C;AAmBD,eAAO,MAAM,iBAAiB,UAAW,OAAO,KAAG,KAAK,IAAI,WACU,CAAC;AAEvE,kFAAkF;AAClF,eAAO,MAAM,iBAAiB,OAAQ,MAAM,KAAG,WAG9C,CAAC;AACF,eAAO,MAAM,eAAe,UAAW,OAAO,KAAG,MAGhD,CAAC;AACF,eAAO,MAAM,mBAAmB,UAAW,OAAO,yBAA6B,IAU9E,CAAC"} \ No newline at end of file diff --git a/dist/references.js b/dist/references.js index 74f234e..44e7c08 100644 --- a/dist/references.js +++ b/dist/references.js @@ -2,11 +2,22 @@ * the raw ID. These handles do not themselves confer authority or a lease. */ const identities = new WeakMap(); class Reference { - constructor(id) { identities.set(this, id); Object.freeze(this); } - equals(other) { return isObjectReference(other) && identities.get(this) === identities.get(other); } - toJSON() { throw new Error("Object references cannot be serialized into ordinary data"); } - toString() { throw new Error("Object references cannot be coerced to strings"); } - [Symbol.toPrimitive]() { throw new Error("Object references cannot be coerced to scalar values"); } + constructor(id) { + identities.set(this, id); + Object.freeze(this); + } + equals(other) { + return isObjectReference(other) && identities.get(this) === identities.get(other); + } + toJSON() { + throw new Error("Object references cannot be serialized into ordinary data"); + } + toString() { + throw new Error("Object references cannot be coerced to strings"); + } + [Symbol.toPrimitive]() { + throw new Error("Object references cannot be coerced to scalar values"); + } } export const isObjectReference = (value) => typeof value === "object" && value !== null && identities.has(value); /** Internal transport boundary; intentionally not exported from the SDK entry. */ diff --git a/dist/relationships.d.ts.map b/dist/relationships.d.ts.map index 022dfdf..e9fbb45 100644 --- a/dist/relationships.d.ts.map +++ b/dist/relationships.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"relationships.d.ts","sourceRoot":"","sources":["../src/relationships.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAC,sBAAsB,EAAE,iBAAiB,EAAC,MAAM,YAAY,CAAC;AAC1E,KAAK,GAAG,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC;AACrC,KAAK,IAAI,CAAC,CAAC,SAAS,WAAW,IAAI;IAAC,UAAU,IAAI,OAAO,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC,CAAC;IAAC,OAAO,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC,EAAE,EAAE,gBAAgB,EAAE,MAAM,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC,CAAA;CAAC,CAAC;AAM9L,+EAA+E;AAC/E,eAAO,MAAM,eAAe,GAAI,CAAC,SAAS,WAAW,EAAE,CAAC,SAAS,GAAG,GAAG,GAAG,QAAQ,IAAI,CAAC,CAAC,CAAC;IACvF,IAAI;IACE,GAAG,MAAM,CAAC;;;;IACV,GAAG,MAAM,CAAC,UAAU,CAAC,oBAAoB,MAAM;IAO/C,MAAM,MAAM,CAAC,oBAAoB,MAAM;CAI7C,CAAC;AACH,eAAO,MAAM,gBAAgB,GAAI,CAAC,SAAS,WAAW,QAAQ,IAAI,CAAC,CAAC,CAAC;IACnE,IAAI;IACE,MAAM,QAAQ,MAAM,UAAU,CAAC,oBAAoB,MAAM;IAMzD,IAAI,SAAS,MAAM,SAAS,MAAM,oBAAoB,MAAM;IAQ5D,MAAM,SAAS,MAAM,oBAAoB,MAAM;CAKrD,CAAC;AACH,eAAO,MAAM,eAAe,GAAI,CAAC,SAAS,WAAW,QAAQ,IAAI,C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Q,IAAI,CAAC,CAAC,CAAC;IAClE,IAAI;IACE,GAAG,SAAS,CAAC,oBAAoB,MAAM;IAKvC,MAAM,SAAS,CAAC,oBAAoB,MAAM;CAOhD,CAAC"} \ No newline at end of file diff --git a/dist/relationships.js b/dist/relationships.js index 9f1cb21..2b4a066 100644 --- a/dist/relationships.js +++ b/dist/relationships.js @@ -7,7 +7,10 @@ const checked = async (port, revision) => { /** Helpers never retry a failed CAS or silently overwrite concurrent edits. */ export const relationshipMap = (port) => ({ read: () => port.collection(), - async get(key) { const snapshot = await port.collection(); return { revision: snapshot.revision, value: snapshot.entries.find((entry) => entry.key === key)?.target }; }, + async get(key) { + const snapshot = await port.collection(); + return { revision: snapshot.revision, value: snapshot.entries.find((entry) => entry.key === key)?.target }; + }, async set(key, target, expectedRevision) { const snapshot = await checked(port, expectedRevision); const entries = snapshot.entries.filter((entry) => entry.key !== key);