@party-stack/ontology-server 0.13.0 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -265,6 +265,7 @@ export declare const bindOntologyServer: <R>(prepared: {
265
265
  name: string;
266
266
  sourceId: string;
267
267
  supportsIdempotency: boolean;
268
+ networks?: readonly string[];
268
269
  loadSubset: (subset: import("@party-stack/ontology-spec/query").ObjectSubset) => Effect.Effect<import("@party-stack/ontology-backend").BackendSnapshot, BackendError>;
269
270
  query: (document: import("@party-stack/ontology-spec").QueryDocument, options?: {
270
271
  readonly inputs?: Record<string, unknown>;
@@ -313,6 +314,7 @@ export declare const bindOntologyServer: <R>(prepared: {
313
314
  name: string;
314
315
  sourceId: string;
315
316
  supportsIdempotency: boolean;
317
+ networks?: readonly string[];
316
318
  loadSubset: (subset: import("@party-stack/ontology-spec/query").ObjectSubset) => Effect.Effect<import("@party-stack/ontology-backend").BackendSnapshot, BackendError>;
317
319
  query: (document: import("@party-stack/ontology-spec").QueryDocument, options?: {
318
320
  readonly inputs?: Record<string, unknown>;
@@ -362,6 +364,7 @@ export declare const bindOntologyServer: <R>(prepared: {
362
364
  name: string;
363
365
  sourceId: string;
364
366
  supportsIdempotency: boolean;
367
+ networks?: readonly string[];
365
368
  loadSubset: (subset: import("@party-stack/ontology-spec/query").ObjectSubset) => Effect.Effect<import("@party-stack/ontology-backend").BackendSnapshot, BackendError>;
366
369
  query: (document: import("@party-stack/ontology-spec").QueryDocument, options?: {
367
370
  readonly inputs?: Record<string, unknown>;
@@ -412,6 +415,7 @@ export declare const bindOntologyServer: <R>(prepared: {
412
415
  name: string;
413
416
  sourceId: string;
414
417
  supportsIdempotency: boolean;
418
+ networks?: readonly string[];
415
419
  loadSubset: (subset: import("@party-stack/ontology-spec/query").ObjectSubset) => Effect.Effect<import("@party-stack/ontology-backend").BackendSnapshot, BackendError>;
416
420
  query: (document: import("@party-stack/ontology-spec").QueryDocument, options?: {
417
421
  readonly inputs?: Record<string, unknown>;
@@ -1 +1 @@
1
- {"version":3,"file":"composition.d.ts","names":["_$__attachmentTransfers_js0.AttachmentTransferPolicy","_$__rpc_js0.OntologyRpcRequest","_$__errorProjection_js0.OntologyErrorProjection"],"sources":["../src/composition.ts"],"mappings":";;;;;;;;;;YAeY,qBAAqB,cAC7B,SAAS,YACR,OAAO,OAAO,yBAAyB,cAAc,IAAI,MAAM;KAG/D,OAAO,KAAK,KACb,yBAAyB;KAGxB;WACY;WAAwB,SAAS;;WACjC;WAAwB,SAAS;;WAE/B;WACA,SAAS;WACT,OAAO;;WAGP;WACA,SAAS;WACT,SAAS;WACT;WACA;;KAEd;WAEc,SAAS;WACT,iCAAiC;;WAEnC;WAA0B;;;YAG/B,6BAA6B,aAAa,OAAO,KAAK,OAAO;;YAE7D,uBAAuB,aAAa,OAAO,KACnD,SAEO;WAAqB;;WAET;WACA;WACA,eAAe,qBAAqB;;WAGpC;WACA,iCAAiC;WACjC,cAAc,qBAAqB;;qBAM7C,wBAAuE,GAAC,SAAA,OAAA,KAAA,SAAA,OAAA;;;;;;;;;;EA1C9D;;;;;;;;;;;;;;;EACA;;;;;;;;;;;;;;;EAEE;EAEC,OAAA;;;;;;;;;;;;;;;EAGD;EAEG,SAAA;EACuB;;;;;GA0DjD,iWAAA,MAAA;qBAEW,qBAAiE,GAAC;;;;;;;;;;EAvExD;;;;;;;;;;;;;;;EACA;;;;;;;;;;;;;;;EAEE;EAEC,OAAA;;;;;;;;;;;;;;;EAGD;EAEG,SAAA;EACuB;;;;;;;;;;;;;;;EAX5B;;;;;EAmG4B;;;;;;;;;;;;EAlG5B;;;;;EAkG4B;;;;;;;;;;;;EAhG1B;EAEC,OAAA;;;;;EA8FyB;;;;;;;;;;;;EA3F1B;EAEG,SAAA;EACuB;;;;;EAwFA;;;;;;;;;;;;;;EAnG5B;EAkHP;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAjHO;EAiHP;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA/GS;EAEC,OAAA;EA6GV;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA1GS;EAEG,SAAA;EACuB;EAuGnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAMd;;qBAGW,uBAAoB,SACpB,gBAAc,SACd,2BACV;;qBA0CU,yBAA0B,WAAS,SAAW,6BAA6B,OAAE,MAAA,+BAAA,6CAAA,kDAAA,kDAAA,kDAAA,yDAAA,8CAAA,oDAAA,uDAAA,8CAAA,sDAAA,6CAAA,+CAAA,iDAAA,iDAAA,kDAAA,4CAAA,oDAAA,2CAAA,qDAAA,mDAAA,oDAAA,8DAAA,6CAAA,yDAAA,qDAAA,6CAAA,iDAAA,qDAAA,mDAAA,kDAAA,kCAA/BE,yBAA+B,iWAAA,QAAA,QAAA,WAAA,MAAA,SAAA,QAAA,QAAA,QAAA,WAAA,MAAA,QAAA,MAAA"}
1
+ {"version":3,"file":"composition.d.ts","names":["_$__attachmentTransfers_js0.AttachmentTransferPolicy","_$__rpc_js0.OntologyRpcRequest","_$__errorProjection_js0.OntologyErrorProjection"],"sources":["../src/composition.ts"],"mappings":";;;;;;;;;;YAeY,qBAAqB,cAC7B,SAAS,YACR,OAAO,OAAO,yBAAyB,cAAc,IAAI,MAAM;KAG/D,OAAO,KAAK,KACb,yBAAyB;KAGxB;WACY;WAAwB,SAAS;;WACjC;WAAwB,SAAS;;WAE/B;WACA,SAAS;WACT,OAAO;;WAGP;WACA,SAAS;WACT,SAAS;WACT;WACA;;KAEd;WAEc,SAAS;WACT,iCAAiC;;WAEnC;WAA0B;;;YAG/B,6BAA6B,aAAa,OAAO,KAAK,OAAO;;YAE7D,uBAAuB,aAAa,OAAO,KACnD,SAEO;WAAqB;;WAET;WACA;WACA,eAAe,qBAAqB;;WAGpC;WACA,iCAAiC;WACjC,cAAc,qBAAqB;;qBAM7C,wBAAuE,GAAC,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,7 @@ const withInternalCommands = (authorize, enabled) => (request, headers) => enabl
5
5
  "ReplicaStatus",
6
6
  "Traces",
7
7
  "ControlOutbox",
8
- "Pins",
8
+ "System",
9
9
  "DeleteLocalData",
10
10
  "ReleaseOwner"
11
11
  ].includes(request.operation) ? Effect.void : authorize(request, headers);
@@ -1 +1 @@
1
- {"version":3,"file":"internalAccess.js","names":[],"sources":["../src/internalAccess.ts"],"sourcesContent":["import { Effect } from \"effect\";\nimport type { OntologyRpcServerOptions } from \"./rpc.js\";\n\n/** Internal commands can inspect or change state outside the caller's IR policy.\n * Policy/context binding remain enforced. Without a policy, exposes raw capabilities.\n */\nexport type OntologyInternalAccess = true | ((context: Record<string, unknown>) => boolean);\n\n/** Adds internal commands without changing domain permissions or exposing raw replication. */\nexport const withInternalCommands =\n <R>(\n authorize: OntologyRpcServerOptions<R>[\"authorize\"],\n enabled: boolean\n ): OntologyRpcServerOptions<R>[\"authorize\"] =>\n (request, headers) =>\n enabled &&\n [\"ReplicaStatus\", \"Traces\", \"ControlOutbox\", \"Pins\", \"DeleteLocalData\", \"ReleaseOwner\"].includes(\n request.operation\n )\n ? Effect.void\n : authorize(request, headers);\n"],"mappings":";;;AASA,MAAa,wBAEL,WACA,aAEH,SAAS,YACN,WACA;CAAC;CAAiB;CAAU;CAAiB;CAAQ;CAAmB;AAAc,CAAC,CAAC,SACpF,QAAQ,SACZ,IACM,OAAO,OACP,UAAU,SAAS,OAAO"}
1
+ {"version":3,"file":"internalAccess.js","names":[],"sources":["../src/internalAccess.ts"],"sourcesContent":["import { Effect } from \"effect\";\nimport type { OntologyRpcServerOptions } from \"./rpc.js\";\n\n/** Internal commands can inspect or change state outside the caller's IR policy.\n * Policy/context binding remain enforced. Without a policy, exposes raw capabilities.\n */\nexport type OntologyInternalAccess = true | ((context: Record<string, unknown>) => boolean);\n\n/** Adds internal commands without changing domain permissions or exposing raw replication. */\nexport const withInternalCommands =\n <R>(\n authorize: OntologyRpcServerOptions<R>[\"authorize\"],\n enabled: boolean\n ): OntologyRpcServerOptions<R>[\"authorize\"] =>\n (request, headers) =>\n enabled &&\n [\"ReplicaStatus\", \"Traces\", \"ControlOutbox\", \"System\", \"DeleteLocalData\", \"ReleaseOwner\"].includes(\n request.operation\n )\n ? Effect.void\n : authorize(request, headers);\n"],"mappings":";;;AASA,MAAa,wBAEL,WACA,aAEH,SAAS,YACN,WACA;CAAC;CAAiB;CAAU;CAAiB;CAAU;CAAmB;AAAc,CAAC,CAAC,SACtF,QAAQ,SACZ,IACM,OAAO,OACP,UAAU,SAAS,OAAO"}
@@ -30,6 +30,7 @@ export declare const OntologyOperationRpcs: RpcGroup.RpcGroup<Rpc.Rpc<"ApplyActi
30
30
  readonly now: string;
31
31
  readonly seed: string;
32
32
  } | undefined;
33
+ readonly timeoutMs?: number | undefined;
33
34
  }, string, never, never>, Schema.Struct<{
34
35
  readonly operationId: Schema.String;
35
36
  readonly outcome: Schema.Literal<"committed">;
@@ -77,8 +78,8 @@ export declare const OntologyOperationRpcs: RpcGroup.RpcGroup<Rpc.Rpc<"ApplyActi
77
78
  readonly now: string;
78
79
  readonly seed: string;
79
80
  } | undefined;
81
+ readonly timeoutMs?: number | undefined;
80
82
  } | undefined;
81
- readonly allowUnknownOutcome?: boolean | undefined;
82
83
  }, string, never, never>, Schema.Void, typeof BackendError, never, never> | Rpc.Rpc<"CreateAttachment", Schema.Struct<{
83
84
  readonly size: Schema.optional<Schema.Int>;
84
85
  readonly type: Schema.String;
@@ -445,9 +446,10 @@ export type OntologyOperationRequest = {
445
446
  readonly command: "remove" | "retry" | "edit";
446
447
  readonly invocation?: Schema.Schema.Type<typeof ActionRequestSchema>;
447
448
  } |
448
- /** Reads and writes of the replica's download inventory (the `pins` resource). */
449
+ /** Reads and writes of the endpoint's system ontology (the `system` resource): its replica's
450
+ * downloads and status. */
449
451
  {
450
- readonly operation: "Pins";
452
+ readonly operation: "System";
451
453
  } | {
452
454
  readonly operation: "ReplicaStatus" | "Traces" | "DeleteLocalData" | "ReleaseOwner";
453
455
  };
@@ -1 +1 @@
1
- {"version":3,"file":"operations.d.ts","names":["_$__attachmentTransfers_js0.AttachmentUpload","_$__attachmentTransfers_js0.AttachmentValue"],"sources":["../src/operations.ts"],"mappings":";;;;;;;;;;;;;cAyEM,UAAQ,OAAA;;;;;;;;;qBA+FD,uBAAqB,SAAA,SAAA,IAAA,mBAAA,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAA2C,OAAA,aAAA;YACjE;WAEO;WACA,+CAA+C;WAC/C,SAAS;;WAEX;;WACA;WAAmC;WAA0B;;WAE3D;WACA,QAAQ;;WAGR;WACA,oDAAoD;;WAGpD;WACA,mDAAmD;WACnD;;WAGA;WACA;WACA,YAAY;WACZ;;WAGA;WACA;WACA,SAAS,OAAO,OAAO,YAAY;WACnC;WACA;;WAGA;WACA,YAAY,OAAO,OAAO,YAAY;WACtC;;WAGA;WACA;WACA;WACA,aAAa,OAAO,OAAO,YAAY;;;;WAGzC;;WACA;;YAkBL,yBAAyB,aAAa;WACrC,sBAAsB,yBAAyB;WAC/C,UAAU;WACV,SAAS;WACT,kDAAkD;WAClD,QAAQ,OAAO,aAAa,cAAc;WAC1C,kBAAkB,OAAO,aAAa,cAAc;WACpD,eAAe,OAAO,aAAa,cAAc;WACjD,YACL,SA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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAgMvC,OAAA,OAAA,iCAAA,MAAA"}
package/lib/operations.js CHANGED
@@ -138,8 +138,7 @@ const HelperRpcs = RpcGroup.make(Rpc.make("Query", {
138
138
  "edit"
139
139
  ]),
140
140
  id: Schema.NonEmptyString,
141
- invocation: Schema.optional(ActionRequestSchema),
142
- allowUnknownOutcome: Schema.optional(Schema.Boolean)
141
+ invocation: Schema.optional(ActionRequestSchema)
143
142
  })),
144
143
  error: BackendError
145
144
  }), Rpc.make("ReplicaStatus", {
@@ -372,8 +371,8 @@ const ontologyOperationHandlers = (options, authorize = options.authorize) => {
372
371
  if (request.operation === "edit") {
373
372
  if (!request.invocation || request.invocation.id !== request.id) return yield* missing("edit invocation");
374
373
  yield* outbox.edit(request.id, request.invocation);
375
- } else if (request.operation === "remove") yield* outbox.remove(request.id, { allowUnknownOutcome: request.allowUnknownOutcome });
376
- else yield* outbox.retry(request.id, { allowUnknownOutcome: request.allowUnknownOutcome });
374
+ } else if (request.operation === "remove") yield* outbox.remove(request.id);
375
+ else yield* outbox.retry(request.id);
377
376
  }),
378
377
  ReplicaStatus: (_, context) => Stream.unwrap(Effect.gen(function* () {
379
378
  yield* Effect.annotateCurrentSpan("activity", "subscription");
@@ -540,15 +539,13 @@ const makeOntologyOperationsClient = Effect.fnUntraced(function* (client) {
540
539
  }).pipe(Effect.mapError(failure)),
541
540
  attachments,
542
541
  outbox: {
543
- remove: (id, settings) => client.ControlOutbox({
542
+ remove: (id) => client.ControlOutbox({
544
543
  operation: "remove",
545
- id,
546
- allowUnknownOutcome: settings?.allowUnknownOutcome
544
+ id
547
545
  }).pipe(Effect.mapError(failure)),
548
- retry: (id, settings) => client.ControlOutbox({
546
+ retry: (id) => client.ControlOutbox({
549
547
  operation: "retry",
550
- id,
551
- allowUnknownOutcome: settings?.allowUnknownOutcome
548
+ id
552
549
  }).pipe(Effect.mapError(failure)),
553
550
  edit: (id, invocation) => client.ControlOutbox({
554
551
  operation: "edit",
@@ -1 +1 @@
1
- {"version":3,"file":"operations.js","names":[],"sources":["../src/operations.ts"],"sourcesContent":["import {\n BackendError,\n classifyBackendFailure,\n BackendSnapshotSchema,\n BackendChangePageSchema,\n ValidationReportSchema,\n ActionReceiptSchema,\n EncryptedValueSchema,\n DecryptedValueSchema,\n encryptedPropertyCodec,\n} from \"@party-stack/ontology-backend\";\nimport {\n ActionRequestSchema,\n ObjectSubsetCodec,\n protocolValueCodec,\n} from \"@party-stack/ontology-backend/protocol\";\nimport { ReplicaStatusSchema, makeReplicaMonitor } from \"@party-stack/ontology-replica\";\nimport { QueryDocumentSchema } from \"@party-stack/ontology-spec/effect\";\nimport { getTargetValueType } from \"@party-stack/ontology-spec/utils\";\nimport { withObjectSources } from \"@party-stack/ontology-storage\";\nimport {\n attachmentByteSource,\n byteChunks,\n collectByteBlob,\n scopedByteSource,\n type ByteSource,\n} from \"@party-stack/ontology-storage/blobs\";\nimport { Effect, Exit, Option, Queue, Schema, Sink, Stream, Fiber, Scope, Layer } from \"effect\";\nimport { Rpc, RpcGroup, RpcClient } from \"effect/rpc\";\nimport {\n Attachment,\n Target,\n AttachmentTransferRpcs,\n attachmentTransferHandlers,\n splitAttachmentChunk,\n} from \"./attachmentTransfers.js\";\nimport { projectValidationReport, type ErrorProjectionOptions } from \"./errorProjection.js\";\nimport type { AttachmentTransferPolicy } from \"./attachmentTransfers.js\";\nimport type { ReplicaService } from \"@party-stack/ontology-replica\";\nimport type { AttachmentCreateOptions } from \"@party-stack/ontology-replica\";\nimport type { ObjectSubset } from \"@party-stack/ontology-spec/query\";\nimport type { attachment } from \"@party-stack/ontology-spec/values\";\nimport type { ByteInput, ReadableByteInput } from \"@party-stack/ontology-storage/blobs\";\nimport type { TraceStore, TraceRecord } from \"@party-stack/runtime/tracing\";\nimport type { Headers } from \"effect/http/Headers\";\nconst Validation = ValidationReportSchema;\nconst Trace = Schema.Struct({\n id: Schema.String,\n traceId: Schema.String,\n parentId: Schema.optional(Schema.String),\n name: Schema.String,\n startedAt: Schema.Number,\n durationMs: Schema.Number,\n outcome: Schema.Literals([\"running\", \"success\", \"failure\", \"interrupted\"]),\n error: Schema.optional(\n Schema.Struct({ kind: Schema.Literals([\"Error\", \"Defect\"]), message: Schema.String })\n ),\n events: Schema.optional(\n Schema.Array(\n Schema.Struct({\n name: Schema.String,\n at: Schema.Number,\n attributes: Schema.Record(\n Schema.String,\n Schema.Union([Schema.String, Schema.Number, Schema.Boolean])\n ),\n })\n )\n ),\n eventCount: Schema.optional(Schema.Number),\n attributes: Schema.Record(Schema.String, Schema.Union([Schema.String, Schema.Number, Schema.Boolean])),\n});\nconst Parameters = Schema.Record(Schema.String, Schema.Unknown);\nconst Metadata = Schema.Struct({\n size: Schema.optional(Schema.Number),\n type: Schema.optional(Schema.String),\n name: Schema.optional(Schema.String),\n dimensions: Schema.optional(Schema.Struct({ width: Schema.Number, height: Schema.Number })),\n});\n\n/** Explicit helper operations alongside replica transfer. These do not bypass row replication. */\nconst HelperRpcs = RpcGroup.make(\n Rpc.make(\"Query\", {\n payload: protocolValueCodec(\n Schema.Struct({ document: QueryDocumentSchema, inputs: Schema.optional(Parameters) })\n ),\n success: protocolValueCodec(Parameters),\n error: BackendError,\n }),\n Rpc.make(\"LoadSubset\", {\n payload: ObjectSubsetCodec,\n success: protocolValueCodec(BackendSnapshotSchema),\n error: BackendError,\n }),\n Rpc.make(\"WatchChanges\", { success: Schema.Literal(\"invalidate\"), error: BackendError, stream: true }),\n Rpc.make(\"WatchSubset\", {\n payload: ObjectSubsetCodec,\n success: Schema.Literals([\"reset\", \"invalidate\"]),\n error: BackendError,\n stream: true,\n }),\n Rpc.make(\"PullChanges\", {\n payload: Schema.Struct({\n cursor: Schema.optional(Schema.String),\n limit: Schema.optional(Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 10_000 }))),\n }),\n success: protocolValueCodec(BackendChangePageSchema),\n error: BackendError,\n }),\n Rpc.make(\"ApplyAction\", {\n payload: protocolValueCodec(ActionRequestSchema),\n success: ActionReceiptSchema,\n error: BackendError,\n }),\n Rpc.make(\"Decrypt\", {\n payload: Schema.Struct({ value: EncryptedValueSchema, cache: Schema.optional(Schema.Boolean) }),\n success: protocolValueCodec(DecryptedValueSchema),\n error: BackendError,\n }),\n Rpc.make(\"QueryFunction\", {\n payload: protocolValueCodec(Schema.Struct({ name: Schema.NonEmptyString, parameters: Parameters })),\n success: protocolValueCodec(Schema.Unknown),\n error: BackendError,\n }),\n Rpc.make(\"ResolveActionParameters\", {\n payload: protocolValueCodec(Schema.Struct({ name: Schema.NonEmptyString, parameters: Parameters })),\n success: protocolValueCodec(Parameters),\n error: BackendError,\n }),\n Rpc.make(\"ValidateAction\", {\n payload: protocolValueCodec(\n Schema.Struct({\n name: Schema.NonEmptyString,\n parameters: Parameters,\n knownParameters: Schema.optional(Schema.Array(Schema.String)),\n })\n ),\n success: protocolValueCodec(Validation),\n error: BackendError,\n }),\n Rpc.make(\"AttachmentMetadata\", {\n payload: Schema.Struct({\n attachment: Attachment,\n select: Schema.optional(Schema.Array(Schema.Literals([\"size\", \"type\", \"name\", \"dimensions\"]))),\n }),\n success: Metadata,\n error: BackendError,\n }),\n Rpc.make(\"ControlOutbox\", {\n payload: protocolValueCodec(\n Schema.Struct({\n operation: Schema.Literals([\"remove\", \"retry\", \"edit\"]),\n id: Schema.NonEmptyString,\n invocation: Schema.optional(ActionRequestSchema),\n allowUnknownOutcome: Schema.optional(Schema.Boolean),\n })\n ),\n error: BackendError,\n }),\n Rpc.make(\"ReplicaStatus\", {\n success: protocolValueCodec(ReplicaStatusSchema),\n error: BackendError,\n stream: true,\n }),\n Rpc.make(\"Traces\", { success: Schema.Array(Trace), error: BackendError, stream: true }),\n Rpc.make(\"DeleteLocalData\", { error: BackendError }),\n Rpc.make(\"ReleaseOwner\", { error: BackendError })\n);\nexport const OntologyOperationRpcs = HelperRpcs.merge(AttachmentTransferRpcs);\nexport type OntologyOperationRequest =\n | {\n readonly operation: \"Query\";\n readonly document: import(\"@party-stack/ontology-spec\").QueryDocument;\n readonly inputs?: Record<string, unknown>;\n }\n | { readonly operation: \"WatchChanges\" }\n | { readonly operation: \"PullChanges\"; readonly cursor?: string; readonly limit?: number }\n | {\n readonly operation: \"LoadSubset\" | \"WatchSubset\";\n readonly subset: ObjectSubset;\n }\n | {\n readonly operation: \"ApplyAction\";\n readonly invocation: import(\"@party-stack/ontology-backend\").ActionRequest;\n }\n | {\n readonly operation: \"Decrypt\";\n readonly value: import(\"@party-stack/ontology-spec/values\").Encrypted;\n readonly cache?: boolean;\n }\n | {\n readonly operation: \"QueryFunction\" | \"ValidateAction\" | \"ResolveActionParameters\";\n readonly name: string;\n readonly parameters: Record<string, unknown>;\n readonly knownParameters?: readonly string[];\n }\n | {\n readonly operation: \"CreateAttachment\";\n readonly id?: string;\n readonly target?: Schema.Schema.Type<typeof Target>;\n readonly type: string;\n readonly size?: number;\n }\n | {\n readonly operation: \"ReadAttachment\" | \"AttachmentMetadata\";\n readonly attachment: Schema.Schema.Type<typeof Attachment>;\n readonly select?: readonly string[];\n }\n | {\n readonly operation: \"ControlOutbox\";\n readonly id: string;\n readonly command: \"remove\" | \"retry\" | \"edit\";\n readonly invocation?: Schema.Schema.Type<typeof ActionRequestSchema>;\n }\n /** Reads and writes of the replica's download inventory (the `pins` resource). */\n | { readonly operation: \"Pins\" }\n | { readonly operation: \"ReplicaStatus\" | \"Traces\" | \"DeleteLocalData\" | \"ReleaseOwner\" };\n\nconst failure = (cause: unknown) => classifyBackendFailure(\"ontology.operations\", cause);\nconst decryptFailure = (cause: unknown) =>\n new BackendError({\n operation: \"decrypt\",\n kind: cause instanceof BackendError ? cause.kind : \"Unavailable\",\n retryable: cause instanceof BackendError ? cause.retryable : true,\n message: \"Decryption failed.\",\n });\nconst missing = (name: string) =>\n new BackendError({\n operation: name,\n kind: \"NotImplemented\",\n message: `Ontology operation ${name} is unavailable.`,\n retryable: false,\n });\n\nexport type OntologyOperationOptions<R = never> = ErrorProjectionOptions & {\n readonly attachmentTransfers?: AttachmentTransferPolicy<R>;\n readonly replica?: ReplicaService;\n readonly traces?: TraceStore;\n readonly backend?: import(\"@party-stack/ontology-backend\").OntologyBackendService;\n readonly ready?: Effect.Effect<void, BackendError, R>;\n readonly deleteLocalData?: Effect.Effect<void, BackendError, R>;\n readonly releaseOwner?: Effect.Effect<void, BackendError, R>;\n readonly authorize: (\n request: OntologyOperationRequest,\n headers: Headers\n ) => Effect.Effect<void, BackendError, R>;\n};\n\n/** Shared storage/application operation; transports supply framing and authorization. */\nexport const ontologyAttachmentHandlers = <R>(\n options: OntologyOperationOptions<R>,\n authorize: OntologyOperationOptions<R>[\"authorize\"] = options.authorize\n) => ({\n create: (\n request: import(\"./attachmentTransfers.js\").AttachmentUpload,\n blob: import(\"@party-stack/ontology-storage/blobs\").ByteInput\n ) =>\n Effect.gen(function* () {\n yield* options.ready ?? Effect.void;\n if (options.backend) {\n if (!options.backend.attachments?.stage) return yield* missing(\"CreateAttachment\");\n const ir = options.ir ?? options.replica?.ir;\n const type =\n request.target && ir\n ? yield* Effect.try({\n try: () => getTargetValueType(ir, request.target!),\n catch: () =>\n new BackendError({\n operation: \"attachment.stage\",\n kind: \"InvalidRequest\",\n message: \"Invalid attachment target.\",\n retryable: false,\n }),\n })\n : undefined;\n if (type && type.kind !== \"attachment\")\n return yield* new BackendError({\n operation: \"attachment.stage\",\n kind: \"InvalidRequest\",\n message: \"Target is not an attachment.\",\n retryable: false,\n });\n return yield* options.backend.attachments.stage(\n { id: request.id ?? crypto.randomUUID(), type: request.type },\n blob,\n { target: type?.kind === \"attachment\" ? type.value : undefined }\n );\n }\n if (!options.replica) return yield* missing(\"CreateAttachment\");\n const created = yield* options.replica.attachments.create(blob, request);\n if (created.isMaterialized) yield* created.isMaterialized;\n return created.attachment;\n }),\n read: (attachment: import(\"./attachmentTransfers.js\").AttachmentValue, headers: Headers) =>\n Effect.gen(function* () {\n yield* authorize({ operation: \"ReadAttachment\", attachment }, headers);\n yield* options.ready ?? Effect.void;\n if (options.backend) {\n if (!options.backend.attachments?.read) return yield* missing(\"ReadAttachment\");\n return yield* options.backend.attachments.read(attachment);\n }\n if (!options.replica) return yield* missing(\"ReadAttachment\");\n return yield* options.replica.attachments.source(attachment);\n }),\n});\n\nexport const ontologyOperationHandlers = <R>(\n options: OntologyOperationOptions<R>,\n authorize: OntologyOperationOptions<R>[\"authorize\"] = options.authorize\n) => {\n return HelperRpcs.toLayer({\n Query: (request, context) =>\n Effect.gen(function* () {\n yield* authorize({ operation: \"Query\", ...request }, context.headers);\n yield* options.ready ?? Effect.void;\n if (!options.backend) return yield* missing(\"Query\");\n return yield* options.backend.query(request.document, { inputs: request.inputs });\n }),\n LoadSubset: (subset, context) =>\n Effect.gen(function* () {\n yield* authorize({ operation: \"LoadSubset\", subset }, context.headers);\n yield* options.ready ?? Effect.void;\n if (!options.backend) return yield* missing(\"LoadSubset\");\n const snapshot = yield* options.backend.loadSubset(subset);\n const ir = options.ir ?? options.replica?.ir;\n const objectType = ir?.objectTypes.find(\n (type) => type.name === subset.from.source.objectType\n );\n return !ir || !objectType\n ? snapshot\n : {\n ...snapshot,\n rows: snapshot.rows.map((row) => ({\n ...row,\n value: withObjectSources({ ir, objectType, object: row.value, key: row.key }),\n })),\n };\n }),\n WatchChanges: (_, context) =>\n Stream.unwrap(\n Effect.gen(function* () {\n yield* authorize({ operation: \"WatchChanges\" }, context.headers);\n yield* options.ready ?? Effect.void;\n if (!options.backend?.changes?.watch) return yield* missing(\"WatchChanges\");\n return Stream.concat(\n Stream.make(\"invalidate\" as const),\n (yield* options.backend.changes.watch).pipe(Stream.map(() => \"invalidate\" as const))\n );\n })\n ),\n WatchSubset: (subset, context) =>\n Stream.unwrap(\n Effect.gen(function* () {\n yield* authorize({ operation: \"WatchSubset\", subset }, context.headers);\n yield* options.ready ?? Effect.void;\n if (!options.backend) return yield* missing(\"WatchSubset\");\n const watched = options.backend.watchSubset?.(subset);\n const interval = options.backend.refresh?.(subset)?.pollIntervalMs ?? false;\n if (!watched && interval !== false && (!Number.isFinite(interval) || interval < 100))\n return yield* new BackendError({\n operation: \"WatchSubset\",\n kind: \"InvalidConfiguration\",\n retryable: false,\n message: \"Invalid subset poll interval.\",\n });\n if (!watched && interval === false) return yield* missing(\"WatchSubset\");\n const changes = watched ? yield* watched : Stream.tick(interval as number);\n // Opening a watch is a repair boundary, not an observed change.\n // A replica with another maintained covering watch can reuse its proof.\n return Stream.concat(\n Stream.make(\"reset\" as const),\n changes.pipe(\n Stream.map((event) =>\n event === \"reset\" ? (\"reset\" as const) : (\"invalidate\" as const)\n )\n )\n );\n })\n ),\n PullChanges: (request, context) =>\n Effect.gen(function* () {\n yield* authorize({ operation: \"PullChanges\", ...request }, context.headers);\n yield* options.ready ?? Effect.void;\n if (!options.backend?.changes) return yield* missing(\"PullChanges\");\n return yield* options.backend.changes.pull(request);\n }),\n ApplyAction: (invocation, context) =>\n Effect.gen(function* () {\n yield* authorize({ operation: \"ApplyAction\", invocation }, context.headers);\n yield* options.ready ?? Effect.void;\n if (!options.backend) return yield* missing(\"ApplyAction\");\n return yield* options.backend.applyAction(invocation);\n }),\n Decrypt: (request, context) =>\n Effect.gen(function* () {\n yield* authorize({ operation: \"Decrypt\", ...request }, context.headers);\n yield* options.ready ?? Effect.void;\n if (options.backend) {\n if (!options.backend.encrypted) return yield* missing(\"Decrypt\");\n const result = yield* options.backend.encrypted.decrypt(request.value);\n if (result.ciphertext !== undefined && result.ciphertext !== request.value.ciphertext)\n return yield* new BackendError({\n operation: \"decrypt\",\n kind: \"Conflict\",\n message: \"The encrypted value changed.\",\n retryable: false,\n });\n return result;\n }\n if (!options.replica) return yield* missing(\"Decrypt\");\n const result = yield* options.replica.decrypt(request.value, { cache: request.cache });\n return {\n ...result,\n value: encryptedPropertyCodec(options.replica.ir, request.value).encode(result.value),\n };\n }).pipe(Effect.mapError(decryptFailure)),\n ResolveActionParameters: (request, context) =>\n Effect.gen(function* () {\n yield* authorize({ operation: \"ResolveActionParameters\", ...request }, context.headers);\n yield* options.ready ?? Effect.void;\n // Describe advertises resolution for either implementation. A managed\n // replica resolves from its IR when the provider has no resolver.\n if (options.backend?.resolveActionParameters)\n return yield* options.backend.resolveActionParameters(request.name, request.parameters);\n if (!options.replica) return yield* missing(\"ResolveActionParameters\");\n return yield* options.replica.actions.resolveParameters(request.name, request.parameters);\n }),\n QueryFunction: (request, context) =>\n Effect.gen(function* () {\n yield* authorize({ operation: \"QueryFunction\", ...request }, context.headers);\n if (options.backend) {\n yield* options.ready ?? Effect.void;\n if (!options.backend.queryFunction) return yield* missing(request.name);\n return yield* options.backend.queryFunction(request.name, request.parameters);\n }\n return yield* missing(request.name);\n }),\n ValidateAction: (request, context) =>\n Effect.gen(function* () {\n yield* authorize({ operation: \"ValidateAction\", ...request }, context.headers);\n if (options.backend?.validateAction)\n return yield* options.backend\n .validateAction(request.name, request.parameters, {\n knownParameters: request.knownParameters,\n })\n .pipe(Effect.map((report) => projectValidationReport(report, options, request.name)));\n const report = options.replica\n ? yield* options.replica.actions.validate(request.name, request.parameters, {\n knownParameters: request.knownParameters,\n })\n : { certain: false as const };\n return projectValidationReport(report, options, request.name);\n }),\n AttachmentMetadata: (request, context) =>\n Effect.gen(function* () {\n yield* authorize({ operation: \"AttachmentMetadata\", ...request }, context.headers);\n if (options.backend) {\n yield* options.ready ?? Effect.void;\n if (!options.backend.attachments?.metadata) return yield* missing(\"AttachmentMetadata\");\n return yield* options.backend.attachments.metadata(request.attachment, {\n select: request.select,\n });\n }\n if (!options.replica) return yield* missing(\"AttachmentMetadata\");\n return yield* options.replica.attachments\n .metadata(request.attachment, { select: request.select })\n .pipe(\n Effect.map(({ name, dimensions, ...rest }) => ({\n ...rest,\n name: name ?? undefined,\n dimensions: dimensions ?? undefined,\n }))\n );\n }),\n ControlOutbox: (request, context) =>\n Effect.gen(function* () {\n yield* authorize(\n {\n operation: \"ControlOutbox\",\n id: request.id,\n command: request.operation,\n invocation: request.invocation,\n },\n context.headers\n );\n const outbox = options.replica?.outbox;\n if (!outbox) return yield* missing(\"ControlOutbox\");\n if (request.operation === \"edit\") {\n if (!request.invocation || request.invocation.id !== request.id)\n return yield* missing(\"edit invocation\");\n yield* outbox.edit(request.id, request.invocation);\n } else if (request.operation === \"remove\")\n yield* outbox.remove(request.id, { allowUnknownOutcome: request.allowUnknownOutcome });\n else yield* outbox.retry(request.id, { allowUnknownOutcome: request.allowUnknownOutcome });\n }),\n ReplicaStatus: (_, context) =>\n Stream.unwrap(\n Effect.gen(function* () {\n yield* Effect.annotateCurrentSpan(\"activity\", \"subscription\");\n yield* authorize({ operation: \"ReplicaStatus\" }, context.headers);\n yield* options.ready ?? Effect.void;\n if (!options.replica) return yield* missing(\"ReplicaStatus\");\n return options.replica.status.changes;\n })\n ),\n Traces: (_, context) =>\n Stream.unwrap(\n Effect.gen(function* () {\n yield* Effect.annotateCurrentSpan(\"activity\", \"subscription\");\n yield* authorize({ operation: \"Traces\" }, context.headers);\n yield* options.ready ?? Effect.void;\n const traces = options.traces;\n if (!traces) return Stream.succeed([]);\n return Stream.callback<readonly Schema.Schema.Type<typeof Trace>[]>(\n (queue) =>\n Effect.acquireRelease(\n Effect.sync(() => {\n const send = (record?: TraceRecord) =>\n Queue.offerUnsafe(queue, record ? [record] : traces.getSnapshot());\n const unsubscribe = traces.subscribe(send);\n send();\n return unsubscribe;\n }),\n (unsubscribe) => Effect.sync(unsubscribe)\n ),\n { bufferSize: 500, strategy: \"sliding\" }\n );\n })\n ),\n DeleteLocalData: (_, context) =>\n authorize({ operation: \"DeleteLocalData\" }, context.headers).pipe(\n Effect.andThen(options.deleteLocalData ?? Effect.fail(missing(\"DeleteLocalData\")))\n ),\n ReleaseOwner: (_, context) =>\n authorize({ operation: \"ReleaseOwner\" }, context.headers).pipe(\n Effect.andThen(options.releaseOwner ?? Effect.fail(missing(\"ReleaseOwner\")))\n ),\n }).pipe(\n Layer.merge(\n attachmentTransferHandlers({\n ...options.attachmentTransfers,\n authorizeUpload: (request, headers) =>\n authorize(\n {\n operation: \"CreateAttachment\",\n id: request.id,\n target: request.target,\n type: request.type,\n size: request.size,\n },\n headers\n ),\n ...ontologyAttachmentHandlers(options, authorize),\n })\n )\n );\n};\n\ntype OperationsRpcClient = Effect.Success<\n ReturnType<typeof RpcClient.make<RpcGroup.Rpcs<typeof OntologyOperationRpcs>>>\n>;\nexport interface ProtocolAttachments {\n readonly create: (\n input: ByteInput | ReadableByteInput,\n options?: AttachmentCreateOptions\n ) => Effect.Effect<{ readonly attachment: attachment }, BackendError>;\n readonly source: (attachment: attachment) => Effect.Effect<ByteSource, BackendError, Scope.Scope>;\n readonly blob: (attachment: attachment) => Effect.Effect<Blob, BackendError>;\n readonly metadata: (\n attachment: attachment,\n options?: { readonly select?: readonly (\"size\" | \"type\" | \"name\" | \"dimensions\")[] }\n ) => Effect.Effect<Schema.Schema.Type<typeof Metadata>, BackendError>;\n}\nexport interface OntologyOperationsClient {\n readonly query: (\n document: import(\"@party-stack/ontology-spec\").QueryDocument,\n inputs?: Record<string, unknown>\n ) => Effect.Effect<Record<string, unknown>, BackendError>;\n /** Portable plaintext; the view decodes it against its ontology definition. Cache policy runs at the owner. */\n readonly decrypt: (\n value: import(\"@party-stack/ontology-spec/values\").Encrypted,\n options?: { cache?: boolean }\n ) => Effect.Effect<unknown, BackendError>;\n readonly queryFunction: (\n name: string,\n parameters: Record<string, unknown>\n ) => Effect.Effect<unknown, BackendError>;\n readonly resolveActionParameters: (\n name: string,\n parameters: Record<string, unknown>\n ) => Effect.Effect<Record<string, unknown>, BackendError>;\n readonly validate: (\n name: string,\n parameters: Record<string, unknown>,\n knownParameters?: readonly string[]\n ) => Effect.Effect<import(\"@party-stack/ontology-backend\").ValidationReport, BackendError>;\n readonly attachments: ProtocolAttachments;\n readonly outbox: Pick<\n import(\"@party-stack/ontology-replica\").ReplicaService[\"outbox\"],\n \"remove\" | \"retry\" | \"edit\"\n >;\n readonly traces: TraceStore;\n readonly replicaMonitor: import(\"@party-stack/ontology-replica\").ReplicaMonitor;\n readonly deleteLocalData: Effect.Effect<void, BackendError>;\n readonly releaseOwner: Effect.Effect<void, BackendError>;\n}\n\nexport const makeOntologyOperationsClient = Effect.fnUntraced(function* (\n client: OperationsRpcClient\n): Effect.fn.Return<OntologyOperationsClient, never, Scope.Scope> {\n const replicaMonitor = yield* makeReplicaMonitor(client.ReplicaStatus().pipe(Stream.mapError(failure)));\n const scope = yield* Effect.scope;\n const context = yield* Effect.context<never>();\n const listeners = new Set<() => void>();\n let spans: readonly TraceRecord[] = [];\n let watcher: Fiber.Fiber<void> | undefined;\n const notify = () => {\n for (const listener of listeners) {\n try {\n listener();\n } catch {\n /* Observers do not own the transport. */\n }\n }\n };\n const watch = Stream.runForEach(client.Traces(), (snapshot) =>\n Effect.sync(() => {\n for (const record of snapshot) {\n const index = spans.findIndex(\n (previous) => previous.id === record.id && previous.traceId === record.traceId\n );\n spans =\n index < 0\n ? [...spans.slice(-499), record]\n : spans.map((previous, at) => (at === index ? record : previous));\n }\n notify();\n })\n ).pipe(Effect.catch(() => Effect.void));\n const traces = {\n getSnapshot: () => spans,\n subscribe: (listener: () => void) => {\n listeners.add(listener);\n if (!watcher) watcher = Effect.runSyncWith(context)(Effect.forkIn(watch, scope));\n return () => {\n listeners.delete(listener);\n if (!listeners.size && watcher) {\n Effect.runFork(Fiber.interrupt(watcher));\n watcher = undefined;\n }\n };\n },\n clear: () => {\n spans = [];\n notify();\n },\n };\n yield* Effect.addFinalizer(() => (watcher ? Fiber.interrupt(watcher).pipe(Effect.asVoid) : Effect.void));\n const attachments: ProtocolAttachments = {\n create: (input, opts) =>\n Effect.gen(function* () {\n const blob = attachmentByteSource(input);\n const attachment = yield* Effect.gen(function* () {\n let result: Schema.Schema.Type<typeof Attachment> | undefined;\n yield* Stream.runForEach(\n client.CreateAttachment({\n size: blob.size,\n type: blob.type,\n name: blob.name,\n ...opts,\n }),\n (event) =>\n Effect.gen(function* () {\n if (event.kind === \"complete\") {\n result = event.attachment;\n return;\n }\n let sequence = 0;\n yield* Stream.runForEach(\n byteChunks(blob).pipe(Stream.mapError(failure)),\n (chunk) =>\n Effect.forEach(\n splitAttachmentChunk(chunk),\n (bytes) =>\n client.WriteAttachmentChunk({\n uploadId: event.uploadId,\n sequence: sequence++,\n bytes,\n end: false,\n }),\n { discard: true }\n )\n );\n yield* client.WriteAttachmentChunk({\n uploadId: event.uploadId,\n sequence,\n bytes: new Uint8Array(0),\n end: true,\n });\n })\n );\n if (!result) return yield* missing(\"completed attachment transfer\");\n return result;\n });\n return { attachment };\n }).pipe(Effect.mapError(failure)),\n source: (attachment) =>\n scopedByteSource(\n Effect.gen(function* () {\n const readScope = yield* Scope.fork(yield* Effect.scope);\n return yield* Effect.gen(function* () {\n // Read the stream's own header. A separate metadata request can\n // otherwise download the whole body to derive unknown size/name.\n const [header, tail] = yield* Scope.provide(\n Stream.peel(\n client.ReadAttachment(attachment),\n Sink.head<Stream.Success<ReturnType<OperationsRpcClient[\"ReadAttachment\"]>>>()\n ),\n readScope\n );\n if (Option.isNone(header) || header.value.kind !== \"metadata\")\n return yield* failure(new Error(\"Missing attachment metadata.\"));\n const { kind: _kind, ...metadata } = header.value;\n let consumed = false;\n return {\n ...metadata,\n stream: Stream.suspend(() => {\n if (consumed)\n return Stream.unwrap(\n attachments\n .source(attachment)\n .pipe(Effect.map((source) => source.stream))\n );\n consumed = true;\n let received = 0;\n return Stream.concat(\n tail.pipe(\n Stream.mapEffect((event) =>\n Effect.gen(function* () {\n if (event.kind !== \"bytes\")\n return yield* failure(\n new Error(\"Duplicate attachment metadata.\")\n );\n received += event.bytes.length;\n if (metadata.size !== undefined && received > metadata.size)\n return yield* failure(\n new Error(\"Attachment exceeds its declared size.\")\n );\n return event.bytes;\n })\n )\n ),\n Stream.fromEffect(\n Effect.gen(function* () {\n if (metadata.size !== undefined && received !== metadata.size)\n return yield* failure(\n new Error(\"Incomplete attachment download.\")\n );\n })\n ).pipe(Stream.drain)\n ).pipe(Stream.ensuring(Scope.close(readScope, Exit.void)));\n }),\n };\n }).pipe(Effect.onError(() => Scope.close(readScope, Exit.void)));\n }),\n scope\n ).pipe(Effect.mapError(failure)),\n blob: (attachment) =>\n Effect.scoped(\n attachments.source(attachment).pipe(Effect.flatMap(collectByteBlob), Effect.mapError(failure))\n ),\n metadata: (attachment, opts) =>\n client.AttachmentMetadata({ attachment, select: opts?.select }).pipe(Effect.mapError(failure)),\n };\n return {\n query: (document, inputs) => client.Query({ document, inputs }).pipe(Effect.mapError(failure)),\n decrypt: (value, settings) =>\n client.Decrypt({ value, cache: settings?.cache }).pipe(\n Effect.map((result) => result.value),\n Effect.mapError(decryptFailure)\n ),\n deleteLocalData: client.DeleteLocalData().pipe(Effect.mapError(failure)),\n releaseOwner: client.ReleaseOwner(undefined, { discard: true }).pipe(Effect.mapError(failure)),\n queryFunction: (name, parameters) =>\n client.QueryFunction({ name, parameters }).pipe(Effect.mapError(failure)),\n resolveActionParameters: (name, parameters) =>\n client.ResolveActionParameters({ name, parameters }).pipe(Effect.mapError(failure)),\n validate: (name, parameters, knownParameters) =>\n client.ValidateAction({ name, parameters, knownParameters }).pipe(Effect.mapError(failure)),\n attachments,\n outbox: {\n remove: (id, settings) =>\n client\n .ControlOutbox({\n operation: \"remove\",\n id,\n allowUnknownOutcome: settings?.allowUnknownOutcome,\n })\n .pipe(Effect.mapError(failure)),\n retry: (id, settings) =>\n client\n .ControlOutbox({\n operation: \"retry\",\n id,\n allowUnknownOutcome: settings?.allowUnknownOutcome,\n })\n .pipe(Effect.mapError(failure)),\n edit: (id, invocation) =>\n client.ControlOutbox({ operation: \"edit\", id, invocation }).pipe(Effect.mapError(failure)),\n },\n traces,\n replicaMonitor,\n };\n});\n"],"mappings":";;;;;;;;;;;;AA6CA,MAAM,aAAa;AACnB,MAAM,QAAQ,OAAO,OAAO;CACxB,IAAI,OAAO;CACX,SAAS,OAAO;CAChB,UAAU,OAAO,SAAS,OAAO,MAAM;CACvC,MAAM,OAAO;CACb,WAAW,OAAO;CAClB,YAAY,OAAO;CACnB,SAAS,OAAO,SAAS;EAAC;EAAW;EAAW;EAAW;CAAa,CAAC;CACzE,OAAO,OAAO,SACV,OAAO,OAAO;EAAE,MAAM,OAAO,SAAS,CAAC,SAAS,QAAQ,CAAC;EAAG,SAAS,OAAO;CAAO,CAAC,CACxF;CACA,QAAQ,OAAO,SACX,OAAO,MACH,OAAO,OAAO;EACV,MAAM,OAAO;EACb,IAAI,OAAO;EACX,YAAY,OAAO,OACf,OAAO,QACP,OAAO,MAAM;GAAC,OAAO;GAAQ,OAAO;GAAQ,OAAO;EAAO,CAAC,CAC/D;CACJ,CAAC,CACL,CACJ;CACA,YAAY,OAAO,SAAS,OAAO,MAAM;CACzC,YAAY,OAAO,OAAO,OAAO,QAAQ,OAAO,MAAM;EAAC,OAAO;EAAQ,OAAO;EAAQ,OAAO;CAAO,CAAC,CAAC;AACzG,CAAC;AACD,MAAM,aAAa,OAAO,OAAO,OAAO,QAAQ,OAAO,OAAO;AAC9D,MAAM,WAAW,OAAO,OAAO;CAC3B,MAAM,OAAO,SAAS,OAAO,MAAM;CACnC,MAAM,OAAO,SAAS,OAAO,MAAM;CACnC,MAAM,OAAO,SAAS,OAAO,MAAM;CACnC,YAAY,OAAO,SAAS,OAAO,OAAO;EAAE,OAAO,OAAO;EAAQ,QAAQ,OA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AW,CAAC,CAAC,CAAC,KAAK,OAAO,SAAS,OAAO,CAAC;EACjG;EACA;EACA;CACJ;AACJ,CAAC"}
1
+ {"version":3,"file":"operations.js","names":[],"sources":["../src/operations.ts"],"sourcesContent":["import {\n BackendError,\n classifyBackendFailure,\n BackendSnapshotSchema,\n BackendChangePageSchema,\n ValidationReportSchema,\n ActionReceiptSchema,\n EncryptedValueSchema,\n DecryptedValueSchema,\n encryptedPropertyCodec,\n} from \"@party-stack/ontology-backend\";\nimport {\n ActionRequestSchema,\n ObjectSubsetCodec,\n protocolValueCodec,\n} from \"@party-stack/ontology-backend/protocol\";\nimport { ReplicaStatusSchema, makeReplicaMonitor } from \"@party-stack/ontology-replica\";\nimport { QueryDocumentSchema } from \"@party-stack/ontology-spec/effect\";\nimport { getTargetValueType } from \"@party-stack/ontology-spec/utils\";\nimport { withObjectSources } from \"@party-stack/ontology-storage\";\nimport {\n attachmentByteSource,\n byteChunks,\n collectByteBlob,\n scopedByteSource,\n type ByteSource,\n} from \"@party-stack/ontology-storage/blobs\";\nimport { Effect, Exit, Option, Queue, Schema, Sink, Stream, Fiber, Scope, Layer } from \"effect\";\nimport { Rpc, RpcGroup, RpcClient } from \"effect/rpc\";\nimport {\n Attachment,\n Target,\n AttachmentTransferRpcs,\n attachmentTransferHandlers,\n splitAttachmentChunk,\n} from \"./attachmentTransfers.js\";\nimport { projectValidationReport, type ErrorProjectionOptions } from \"./errorProjection.js\";\nimport type { AttachmentTransferPolicy } from \"./attachmentTransfers.js\";\nimport type { ReplicaService } from \"@party-stack/ontology-replica\";\nimport type { AttachmentCreateOptions } from \"@party-stack/ontology-replica\";\nimport type { ObjectSubset } from \"@party-stack/ontology-spec/query\";\nimport type { attachment } from \"@party-stack/ontology-spec/values\";\nimport type { ByteInput, ReadableByteInput } from \"@party-stack/ontology-storage/blobs\";\nimport type { TraceStore, TraceRecord } from \"@party-stack/runtime/tracing\";\nimport type { Headers } from \"effect/http/Headers\";\nconst Validation = ValidationReportSchema;\nconst Trace = Schema.Struct({\n id: Schema.String,\n traceId: Schema.String,\n parentId: Schema.optional(Schema.String),\n name: Schema.String,\n startedAt: Schema.Number,\n durationMs: Schema.Number,\n outcome: Schema.Literals([\"running\", \"success\", \"failure\", \"interrupted\"]),\n error: Schema.optional(\n Schema.Struct({ kind: Schema.Literals([\"Error\", \"Defect\"]), message: Schema.String })\n ),\n events: Schema.optional(\n Schema.Array(\n Schema.Struct({\n name: Schema.String,\n at: Schema.Number,\n attributes: Schema.Record(\n Schema.String,\n Schema.Union([Schema.String, Schema.Number, Schema.Boolean])\n ),\n })\n )\n ),\n eventCount: Schema.optional(Schema.Number),\n attributes: Schema.Record(Schema.String, Schema.Union([Schema.String, Schema.Number, Schema.Boolean])),\n});\nconst Parameters = Schema.Record(Schema.String, Schema.Unknown);\nconst Metadata = Schema.Struct({\n size: Schema.optional(Schema.Number),\n type: Schema.optional(Schema.String),\n name: Schema.optional(Schema.String),\n dimensions: Schema.optional(Schema.Struct({ width: Schema.Number, height: Schema.Number })),\n});\n\n/** Explicit helper operations alongside replica transfer. These do not bypass row replication. */\nconst HelperRpcs = RpcGroup.make(\n Rpc.make(\"Query\", {\n payload: protocolValueCodec(\n Schema.Struct({ document: QueryDocumentSchema, inputs: Schema.optional(Parameters) })\n ),\n success: protocolValueCodec(Parameters),\n error: BackendError,\n }),\n Rpc.make(\"LoadSubset\", {\n payload: ObjectSubsetCodec,\n success: protocolValueCodec(BackendSnapshotSchema),\n error: BackendError,\n }),\n Rpc.make(\"WatchChanges\", { success: Schema.Literal(\"invalidate\"), error: BackendError, stream: true }),\n Rpc.make(\"WatchSubset\", {\n payload: ObjectSubsetCodec,\n success: Schema.Literals([\"reset\", \"invalidate\"]),\n error: BackendError,\n stream: true,\n }),\n Rpc.make(\"PullChanges\", {\n payload: Schema.Struct({\n cursor: Schema.optional(Schema.String),\n limit: Schema.optional(Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 10_000 }))),\n }),\n success: protocolValueCodec(BackendChangePageSchema),\n error: BackendError,\n }),\n Rpc.make(\"ApplyAction\", {\n payload: protocolValueCodec(ActionRequestSchema),\n success: ActionReceiptSchema,\n error: BackendError,\n }),\n Rpc.make(\"Decrypt\", {\n payload: Schema.Struct({ value: EncryptedValueSchema, cache: Schema.optional(Schema.Boolean) }),\n success: protocolValueCodec(DecryptedValueSchema),\n error: BackendError,\n }),\n Rpc.make(\"QueryFunction\", {\n payload: protocolValueCodec(Schema.Struct({ name: Schema.NonEmptyString, parameters: Parameters })),\n success: protocolValueCodec(Schema.Unknown),\n error: BackendError,\n }),\n Rpc.make(\"ResolveActionParameters\", {\n payload: protocolValueCodec(Schema.Struct({ name: Schema.NonEmptyString, parameters: Parameters })),\n success: protocolValueCodec(Parameters),\n error: BackendError,\n }),\n Rpc.make(\"ValidateAction\", {\n payload: protocolValueCodec(\n Schema.Struct({\n name: Schema.NonEmptyString,\n parameters: Parameters,\n knownParameters: Schema.optional(Schema.Array(Schema.String)),\n })\n ),\n success: protocolValueCodec(Validation),\n error: BackendError,\n }),\n Rpc.make(\"AttachmentMetadata\", {\n payload: Schema.Struct({\n attachment: Attachment,\n select: Schema.optional(Schema.Array(Schema.Literals([\"size\", \"type\", \"name\", \"dimensions\"]))),\n }),\n success: Metadata,\n error: BackendError,\n }),\n Rpc.make(\"ControlOutbox\", {\n payload: protocolValueCodec(\n Schema.Struct({\n operation: Schema.Literals([\"remove\", \"retry\", \"edit\"]),\n id: Schema.NonEmptyString,\n invocation: Schema.optional(ActionRequestSchema),\n })\n ),\n error: BackendError,\n }),\n Rpc.make(\"ReplicaStatus\", {\n success: protocolValueCodec(ReplicaStatusSchema),\n error: BackendError,\n stream: true,\n }),\n Rpc.make(\"Traces\", { success: Schema.Array(Trace), error: BackendError, stream: true }),\n Rpc.make(\"DeleteLocalData\", { error: BackendError }),\n Rpc.make(\"ReleaseOwner\", { error: BackendError })\n);\nexport const OntologyOperationRpcs = HelperRpcs.merge(AttachmentTransferRpcs);\nexport type OntologyOperationRequest =\n | {\n readonly operation: \"Query\";\n readonly document: import(\"@party-stack/ontology-spec\").QueryDocument;\n readonly inputs?: Record<string, unknown>;\n }\n | { readonly operation: \"WatchChanges\" }\n | { readonly operation: \"PullChanges\"; readonly cursor?: string; readonly limit?: number }\n | {\n readonly operation: \"LoadSubset\" | \"WatchSubset\";\n readonly subset: ObjectSubset;\n }\n | {\n readonly operation: \"ApplyAction\";\n readonly invocation: import(\"@party-stack/ontology-backend\").ActionRequest;\n }\n | {\n readonly operation: \"Decrypt\";\n readonly value: import(\"@party-stack/ontology-spec/values\").Encrypted;\n readonly cache?: boolean;\n }\n | {\n readonly operation: \"QueryFunction\" | \"ValidateAction\" | \"ResolveActionParameters\";\n readonly name: string;\n readonly parameters: Record<string, unknown>;\n readonly knownParameters?: readonly string[];\n }\n | {\n readonly operation: \"CreateAttachment\";\n readonly id?: string;\n readonly target?: Schema.Schema.Type<typeof Target>;\n readonly type: string;\n readonly size?: number;\n }\n | {\n readonly operation: \"ReadAttachment\" | \"AttachmentMetadata\";\n readonly attachment: Schema.Schema.Type<typeof Attachment>;\n readonly select?: readonly string[];\n }\n | {\n readonly operation: \"ControlOutbox\";\n readonly id: string;\n readonly command: \"remove\" | \"retry\" | \"edit\";\n readonly invocation?: Schema.Schema.Type<typeof ActionRequestSchema>;\n }\n /** Reads and writes of the endpoint's system ontology (the `system` resource): its replica's\n * downloads and status. */\n | { readonly operation: \"System\" }\n | { readonly operation: \"ReplicaStatus\" | \"Traces\" | \"DeleteLocalData\" | \"ReleaseOwner\" };\n\nconst failure = (cause: unknown) => classifyBackendFailure(\"ontology.operations\", cause);\nconst decryptFailure = (cause: unknown) =>\n new BackendError({\n operation: \"decrypt\",\n kind: cause instanceof BackendError ? cause.kind : \"Unavailable\",\n retryable: cause instanceof BackendError ? cause.retryable : true,\n message: \"Decryption failed.\",\n });\nconst missing = (name: string) =>\n new BackendError({\n operation: name,\n kind: \"NotImplemented\",\n message: `Ontology operation ${name} is unavailable.`,\n retryable: false,\n });\n\nexport type OntologyOperationOptions<R = never> = ErrorProjectionOptions & {\n readonly attachmentTransfers?: AttachmentTransferPolicy<R>;\n readonly replica?: ReplicaService;\n readonly traces?: TraceStore;\n readonly backend?: import(\"@party-stack/ontology-backend\").OntologyBackendService;\n readonly ready?: Effect.Effect<void, BackendError, R>;\n readonly deleteLocalData?: Effect.Effect<void, BackendError, R>;\n readonly releaseOwner?: Effect.Effect<void, BackendError, R>;\n readonly authorize: (\n request: OntologyOperationRequest,\n headers: Headers\n ) => Effect.Effect<void, BackendError, R>;\n};\n\n/** Shared storage/application operation; transports supply framing and authorization. */\nexport const ontologyAttachmentHandlers = <R>(\n options: OntologyOperationOptions<R>,\n authorize: OntologyOperationOptions<R>[\"authorize\"] = options.authorize\n) => ({\n create: (\n request: import(\"./attachmentTransfers.js\").AttachmentUpload,\n blob: import(\"@party-stack/ontology-storage/blobs\").ByteInput\n ) =>\n Effect.gen(function* () {\n yield* options.ready ?? Effect.void;\n if (options.backend) {\n if (!options.backend.attachments?.stage) return yield* missing(\"CreateAttachment\");\n const ir = options.ir ?? options.replica?.ir;\n const type =\n request.target && ir\n ? yield* Effect.try({\n try: () => getTargetValueType(ir, request.target!),\n catch: () =>\n new BackendError({\n operation: \"attachment.stage\",\n kind: \"InvalidRequest\",\n message: \"Invalid attachment target.\",\n retryable: false,\n }),\n })\n : undefined;\n if (type && type.kind !== \"attachment\")\n return yield* new BackendError({\n operation: \"attachment.stage\",\n kind: \"InvalidRequest\",\n message: \"Target is not an attachment.\",\n retryable: false,\n });\n return yield* options.backend.attachments.stage(\n { id: request.id ?? crypto.randomUUID(), type: request.type },\n blob,\n { target: type?.kind === \"attachment\" ? type.value : undefined }\n );\n }\n if (!options.replica) return yield* missing(\"CreateAttachment\");\n const created = yield* options.replica.attachments.create(blob, request);\n if (created.isMaterialized) yield* created.isMaterialized;\n return created.attachment;\n }),\n read: (attachment: import(\"./attachmentTransfers.js\").AttachmentValue, headers: Headers) =>\n Effect.gen(function* () {\n yield* authorize({ operation: \"ReadAttachment\", attachment }, headers);\n yield* options.ready ?? Effect.void;\n if (options.backend) {\n if (!options.backend.attachments?.read) return yield* missing(\"ReadAttachment\");\n return yield* options.backend.attachments.read(attachment);\n }\n if (!options.replica) return yield* missing(\"ReadAttachment\");\n return yield* options.replica.attachments.source(attachment);\n }),\n});\n\nexport const ontologyOperationHandlers = <R>(\n options: OntologyOperationOptions<R>,\n authorize: OntologyOperationOptions<R>[\"authorize\"] = options.authorize\n) => {\n return HelperRpcs.toLayer({\n Query: (request, context) =>\n Effect.gen(function* () {\n yield* authorize({ operation: \"Query\", ...request }, context.headers);\n yield* options.ready ?? Effect.void;\n if (!options.backend) return yield* missing(\"Query\");\n return yield* options.backend.query(request.document, { inputs: request.inputs });\n }),\n LoadSubset: (subset, context) =>\n Effect.gen(function* () {\n yield* authorize({ operation: \"LoadSubset\", subset }, context.headers);\n yield* options.ready ?? Effect.void;\n if (!options.backend) return yield* missing(\"LoadSubset\");\n const snapshot = yield* options.backend.loadSubset(subset);\n const ir = options.ir ?? options.replica?.ir;\n const objectType = ir?.objectTypes.find(\n (type) => type.name === subset.from.source.objectType\n );\n return !ir || !objectType\n ? snapshot\n : {\n ...snapshot,\n rows: snapshot.rows.map((row) => ({\n ...row,\n value: withObjectSources({ ir, objectType, object: row.value, key: row.key }),\n })),\n };\n }),\n WatchChanges: (_, context) =>\n Stream.unwrap(\n Effect.gen(function* () {\n yield* authorize({ operation: \"WatchChanges\" }, context.headers);\n yield* options.ready ?? Effect.void;\n if (!options.backend?.changes?.watch) return yield* missing(\"WatchChanges\");\n return Stream.concat(\n Stream.make(\"invalidate\" as const),\n (yield* options.backend.changes.watch).pipe(Stream.map(() => \"invalidate\" as const))\n );\n })\n ),\n WatchSubset: (subset, context) =>\n Stream.unwrap(\n Effect.gen(function* () {\n yield* authorize({ operation: \"WatchSubset\", subset }, context.headers);\n yield* options.ready ?? Effect.void;\n if (!options.backend) return yield* missing(\"WatchSubset\");\n const watched = options.backend.watchSubset?.(subset);\n const interval = options.backend.refresh?.(subset)?.pollIntervalMs ?? false;\n if (!watched && interval !== false && (!Number.isFinite(interval) || interval < 100))\n return yield* new BackendError({\n operation: \"WatchSubset\",\n kind: \"InvalidConfiguration\",\n retryable: false,\n message: \"Invalid subset poll interval.\",\n });\n if (!watched && interval === false) return yield* missing(\"WatchSubset\");\n const changes = watched ? yield* watched : Stream.tick(interval as number);\n // Opening a watch is a repair boundary, not an observed change.\n // A replica with another maintained covering watch can reuse its proof.\n return Stream.concat(\n Stream.make(\"reset\" as const),\n changes.pipe(\n Stream.map((event) =>\n event === \"reset\" ? (\"reset\" as const) : (\"invalidate\" as const)\n )\n )\n );\n })\n ),\n PullChanges: (request, context) =>\n Effect.gen(function* () {\n yield* authorize({ operation: \"PullChanges\", ...request }, context.headers);\n yield* options.ready ?? Effect.void;\n if (!options.backend?.changes) return yield* missing(\"PullChanges\");\n return yield* options.backend.changes.pull(request);\n }),\n ApplyAction: (invocation, context) =>\n Effect.gen(function* () {\n yield* authorize({ operation: \"ApplyAction\", invocation }, context.headers);\n yield* options.ready ?? Effect.void;\n if (!options.backend) return yield* missing(\"ApplyAction\");\n return yield* options.backend.applyAction(invocation);\n }),\n Decrypt: (request, context) =>\n Effect.gen(function* () {\n yield* authorize({ operation: \"Decrypt\", ...request }, context.headers);\n yield* options.ready ?? Effect.void;\n if (options.backend) {\n if (!options.backend.encrypted) return yield* missing(\"Decrypt\");\n const result = yield* options.backend.encrypted.decrypt(request.value);\n if (result.ciphertext !== undefined && result.ciphertext !== request.value.ciphertext)\n return yield* new BackendError({\n operation: \"decrypt\",\n kind: \"Conflict\",\n message: \"The encrypted value changed.\",\n retryable: false,\n });\n return result;\n }\n if (!options.replica) return yield* missing(\"Decrypt\");\n const result = yield* options.replica.decrypt(request.value, { cache: request.cache });\n return {\n ...result,\n value: encryptedPropertyCodec(options.replica.ir, request.value).encode(result.value),\n };\n }).pipe(Effect.mapError(decryptFailure)),\n ResolveActionParameters: (request, context) =>\n Effect.gen(function* () {\n yield* authorize({ operation: \"ResolveActionParameters\", ...request }, context.headers);\n yield* options.ready ?? Effect.void;\n // Describe advertises resolution for either implementation. A managed\n // replica resolves from its IR when the provider has no resolver.\n if (options.backend?.resolveActionParameters)\n return yield* options.backend.resolveActionParameters(request.name, request.parameters);\n if (!options.replica) return yield* missing(\"ResolveActionParameters\");\n return yield* options.replica.actions.resolveParameters(request.name, request.parameters);\n }),\n QueryFunction: (request, context) =>\n Effect.gen(function* () {\n yield* authorize({ operation: \"QueryFunction\", ...request }, context.headers);\n if (options.backend) {\n yield* options.ready ?? Effect.void;\n if (!options.backend.queryFunction) return yield* missing(request.name);\n return yield* options.backend.queryFunction(request.name, request.parameters);\n }\n return yield* missing(request.name);\n }),\n ValidateAction: (request, context) =>\n Effect.gen(function* () {\n yield* authorize({ operation: \"ValidateAction\", ...request }, context.headers);\n if (options.backend?.validateAction)\n return yield* options.backend\n .validateAction(request.name, request.parameters, {\n knownParameters: request.knownParameters,\n })\n .pipe(Effect.map((report) => projectValidationReport(report, options, request.name)));\n const report = options.replica\n ? yield* options.replica.actions.validate(request.name, request.parameters, {\n knownParameters: request.knownParameters,\n })\n : { certain: false as const };\n return projectValidationReport(report, options, request.name);\n }),\n AttachmentMetadata: (request, context) =>\n Effect.gen(function* () {\n yield* authorize({ operation: \"AttachmentMetadata\", ...request }, context.headers);\n if (options.backend) {\n yield* options.ready ?? Effect.void;\n if (!options.backend.attachments?.metadata) return yield* missing(\"AttachmentMetadata\");\n return yield* options.backend.attachments.metadata(request.attachment, {\n select: request.select,\n });\n }\n if (!options.replica) return yield* missing(\"AttachmentMetadata\");\n return yield* options.replica.attachments\n .metadata(request.attachment, { select: request.select })\n .pipe(\n Effect.map(({ name, dimensions, ...rest }) => ({\n ...rest,\n name: name ?? undefined,\n dimensions: dimensions ?? undefined,\n }))\n );\n }),\n ControlOutbox: (request, context) =>\n Effect.gen(function* () {\n yield* authorize(\n {\n operation: \"ControlOutbox\",\n id: request.id,\n command: request.operation,\n invocation: request.invocation,\n },\n context.headers\n );\n const outbox = options.replica?.outbox;\n if (!outbox) return yield* missing(\"ControlOutbox\");\n if (request.operation === \"edit\") {\n if (!request.invocation || request.invocation.id !== request.id)\n return yield* missing(\"edit invocation\");\n yield* outbox.edit(request.id, request.invocation);\n } else if (request.operation === \"remove\") yield* outbox.remove(request.id);\n else yield* outbox.retry(request.id);\n }),\n ReplicaStatus: (_, context) =>\n Stream.unwrap(\n Effect.gen(function* () {\n yield* Effect.annotateCurrentSpan(\"activity\", \"subscription\");\n yield* authorize({ operation: \"ReplicaStatus\" }, context.headers);\n yield* options.ready ?? Effect.void;\n if (!options.replica) return yield* missing(\"ReplicaStatus\");\n return options.replica.status.changes;\n })\n ),\n Traces: (_, context) =>\n Stream.unwrap(\n Effect.gen(function* () {\n yield* Effect.annotateCurrentSpan(\"activity\", \"subscription\");\n yield* authorize({ operation: \"Traces\" }, context.headers);\n yield* options.ready ?? Effect.void;\n const traces = options.traces;\n if (!traces) return Stream.succeed([]);\n return Stream.callback<readonly Schema.Schema.Type<typeof Trace>[]>(\n (queue) =>\n Effect.acquireRelease(\n Effect.sync(() => {\n const send = (record?: TraceRecord) =>\n Queue.offerUnsafe(queue, record ? [record] : traces.getSnapshot());\n const unsubscribe = traces.subscribe(send);\n send();\n return unsubscribe;\n }),\n (unsubscribe) => Effect.sync(unsubscribe)\n ),\n { bufferSize: 500, strategy: \"sliding\" }\n );\n })\n ),\n DeleteLocalData: (_, context) =>\n authorize({ operation: \"DeleteLocalData\" }, context.headers).pipe(\n Effect.andThen(options.deleteLocalData ?? Effect.fail(missing(\"DeleteLocalData\")))\n ),\n ReleaseOwner: (_, context) =>\n authorize({ operation: \"ReleaseOwner\" }, context.headers).pipe(\n Effect.andThen(options.releaseOwner ?? Effect.fail(missing(\"ReleaseOwner\")))\n ),\n }).pipe(\n Layer.merge(\n attachmentTransferHandlers({\n ...options.attachmentTransfers,\n authorizeUpload: (request, headers) =>\n authorize(\n {\n operation: \"CreateAttachment\",\n id: request.id,\n target: request.target,\n type: request.type,\n size: request.size,\n },\n headers\n ),\n ...ontologyAttachmentHandlers(options, authorize),\n })\n )\n );\n};\n\ntype OperationsRpcClient = Effect.Success<\n ReturnType<typeof RpcClient.make<RpcGroup.Rpcs<typeof OntologyOperationRpcs>>>\n>;\nexport interface ProtocolAttachments {\n readonly create: (\n input: ByteInput | ReadableByteInput,\n options?: AttachmentCreateOptions\n ) => Effect.Effect<{ readonly attachment: attachment }, BackendError>;\n readonly source: (attachment: attachment) => Effect.Effect<ByteSource, BackendError, Scope.Scope>;\n readonly blob: (attachment: attachment) => Effect.Effect<Blob, BackendError>;\n readonly metadata: (\n attachment: attachment,\n options?: { readonly select?: readonly (\"size\" | \"type\" | \"name\" | \"dimensions\")[] }\n ) => Effect.Effect<Schema.Schema.Type<typeof Metadata>, BackendError>;\n}\nexport interface OntologyOperationsClient {\n readonly query: (\n document: import(\"@party-stack/ontology-spec\").QueryDocument,\n inputs?: Record<string, unknown>\n ) => Effect.Effect<Record<string, unknown>, BackendError>;\n /** Portable plaintext; the view decodes it against its ontology definition. Cache policy runs at the owner. */\n readonly decrypt: (\n value: import(\"@party-stack/ontology-spec/values\").Encrypted,\n options?: { cache?: boolean }\n ) => Effect.Effect<unknown, BackendError>;\n readonly queryFunction: (\n name: string,\n parameters: Record<string, unknown>\n ) => Effect.Effect<unknown, BackendError>;\n readonly resolveActionParameters: (\n name: string,\n parameters: Record<string, unknown>\n ) => Effect.Effect<Record<string, unknown>, BackendError>;\n readonly validate: (\n name: string,\n parameters: Record<string, unknown>,\n knownParameters?: readonly string[]\n ) => Effect.Effect<import(\"@party-stack/ontology-backend\").ValidationReport, BackendError>;\n readonly attachments: ProtocolAttachments;\n readonly outbox: Pick<\n import(\"@party-stack/ontology-replica\").ReplicaService[\"outbox\"],\n \"remove\" | \"retry\" | \"edit\"\n >;\n readonly traces: TraceStore;\n readonly replicaMonitor: import(\"@party-stack/ontology-replica\").ReplicaMonitor;\n readonly deleteLocalData: Effect.Effect<void, BackendError>;\n readonly releaseOwner: Effect.Effect<void, BackendError>;\n}\n\nexport const makeOntologyOperationsClient = Effect.fnUntraced(function* (\n client: OperationsRpcClient\n): Effect.fn.Return<OntologyOperationsClient, never, Scope.Scope> {\n const replicaMonitor = yield* makeReplicaMonitor(client.ReplicaStatus().pipe(Stream.mapError(failure)));\n const scope = yield* Effect.scope;\n const context = yield* Effect.context<never>();\n const listeners = new Set<() => void>();\n let spans: readonly TraceRecord[] = [];\n let watcher: Fiber.Fiber<void> | undefined;\n const notify = () => {\n for (const listener of listeners) {\n try {\n listener();\n } catch {\n /* Observers do not own the transport. */\n }\n }\n };\n const watch = Stream.runForEach(client.Traces(), (snapshot) =>\n Effect.sync(() => {\n for (const record of snapshot) {\n const index = spans.findIndex(\n (previous) => previous.id === record.id && previous.traceId === record.traceId\n );\n spans =\n index < 0\n ? [...spans.slice(-499), record]\n : spans.map((previous, at) => (at === index ? record : previous));\n }\n notify();\n })\n ).pipe(Effect.catch(() => Effect.void));\n const traces = {\n getSnapshot: () => spans,\n subscribe: (listener: () => void) => {\n listeners.add(listener);\n if (!watcher) watcher = Effect.runSyncWith(context)(Effect.forkIn(watch, scope));\n return () => {\n listeners.delete(listener);\n if (!listeners.size && watcher) {\n Effect.runFork(Fiber.interrupt(watcher));\n watcher = undefined;\n }\n };\n },\n clear: () => {\n spans = [];\n notify();\n },\n };\n yield* Effect.addFinalizer(() => (watcher ? Fiber.interrupt(watcher).pipe(Effect.asVoid) : Effect.void));\n const attachments: ProtocolAttachments = {\n create: (input, opts) =>\n Effect.gen(function* () {\n const blob = attachmentByteSource(input);\n const attachment = yield* Effect.gen(function* () {\n let result: Schema.Schema.Type<typeof Attachment> | undefined;\n yield* Stream.runForEach(\n client.CreateAttachment({\n size: blob.size,\n type: blob.type,\n name: blob.name,\n ...opts,\n }),\n (event) =>\n Effect.gen(function* () {\n if (event.kind === \"complete\") {\n result = event.attachment;\n return;\n }\n let sequence = 0;\n yield* Stream.runForEach(\n byteChunks(blob).pipe(Stream.mapError(failure)),\n (chunk) =>\n Effect.forEach(\n splitAttachmentChunk(chunk),\n (bytes) =>\n client.WriteAttachmentChunk({\n uploadId: event.uploadId,\n sequence: sequence++,\n bytes,\n end: false,\n }),\n { discard: true }\n )\n );\n yield* client.WriteAttachmentChunk({\n uploadId: event.uploadId,\n sequence,\n bytes: new Uint8Array(0),\n end: true,\n });\n })\n );\n if (!result) return yield* missing(\"completed attachment transfer\");\n return result;\n });\n return { attachment };\n }).pipe(Effect.mapError(failure)),\n source: (attachment) =>\n scopedByteSource(\n Effect.gen(function* () {\n const readScope = yield* Scope.fork(yield* Effect.scope);\n return yield* Effect.gen(function* () {\n // Read the stream's own header. A separate metadata request can\n // otherwise download the whole body to derive unknown size/name.\n const [header, tail] = yield* Scope.provide(\n Stream.peel(\n client.ReadAttachment(attachment),\n Sink.head<Stream.Success<ReturnType<OperationsRpcClient[\"ReadAttachment\"]>>>()\n ),\n readScope\n );\n if (Option.isNone(header) || header.value.kind !== \"metadata\")\n return yield* failure(new Error(\"Missing attachment metadata.\"));\n const { kind: _kind, ...metadata } = header.value;\n let consumed = false;\n return {\n ...metadata,\n stream: Stream.suspend(() => {\n if (consumed)\n return Stream.unwrap(\n attachments\n .source(attachment)\n .pipe(Effect.map((source) => source.stream))\n );\n consumed = true;\n let received = 0;\n return Stream.concat(\n tail.pipe(\n Stream.mapEffect((event) =>\n Effect.gen(function* () {\n if (event.kind !== \"bytes\")\n return yield* failure(\n new Error(\"Duplicate attachment metadata.\")\n );\n received += event.bytes.length;\n if (metadata.size !== undefined && received > metadata.size)\n return yield* failure(\n new Error(\"Attachment exceeds its declared size.\")\n );\n return event.bytes;\n })\n )\n ),\n Stream.fromEffect(\n Effect.gen(function* () {\n if (metadata.size !== undefined && received !== metadata.size)\n return yield* failure(\n new Error(\"Incomplete attachment download.\")\n );\n })\n ).pipe(Stream.drain)\n ).pipe(Stream.ensuring(Scope.close(readScope, Exit.void)));\n }),\n };\n }).pipe(Effect.onError(() => Scope.close(readScope, Exit.void)));\n }),\n scope\n ).pipe(Effect.mapError(failure)),\n blob: (attachment) =>\n Effect.scoped(\n attachments.source(attachment).pipe(Effect.flatMap(collectByteBlob), Effect.mapError(failure))\n ),\n metadata: (attachment, opts) =>\n client.AttachmentMetadata({ attachment, select: opts?.select }).pipe(Effect.mapError(failure)),\n };\n return {\n query: (document, inputs) => client.Query({ document, inputs }).pipe(Effect.mapError(failure)),\n decrypt: (value, settings) =>\n client.Decrypt({ value, cache: settings?.cache }).pipe(\n Effect.map((result) => result.value),\n Effect.mapError(decryptFailure)\n ),\n deleteLocalData: client.DeleteLocalData().pipe(Effect.mapError(failure)),\n releaseOwner: client.ReleaseOwner(undefined, { discard: true }).pipe(Effect.mapError(failure)),\n queryFunction: (name, parameters) =>\n client.QueryFunction({ name, parameters }).pipe(Effect.mapError(failure)),\n resolveActionParameters: (name, parameters) =>\n client.ResolveActionParameters({ name, parameters }).pipe(Effect.mapError(failure)),\n validate: (name, parameters, knownParameters) =>\n client.ValidateAction({ name, parameters, knownParameters }).pipe(Effect.mapError(failure)),\n attachments,\n outbox: {\n remove: (id) => client.ControlOutbox({ operation: \"remove\", id }).pipe(Effect.mapError(failure)),\n retry: (id) => client.ControlOutbox({ operation: \"retry\", id }).pipe(Effect.mapError(failure)),\n edit: (id, invocation) =>\n client.ControlOutbox({ operation: \"edit\", id, invocation }).pipe(Effect.mapError(failure)),\n },\n traces,\n replicaMonitor,\n };\n});\n"],"mappings":";;;;;;;;;;;;AA6CA,MAAM,aAAa;AACnB,MAAM,QAAQ,OAAO,OAAO;CACxB,IAAI,OAAO;CACX,SAAS,OAAO;CAChB,UAAU,OAAO,SAAS,OAAO,MAAM;CACvC,MAAM,OAAO;CACb,WAAW,OAAO;CAClB,YAAY,OAAO;CACnB,SAAS,OAAO,SAAS;EAAC;EAAW;EAAW;EAAW;CAAa,CAAC;CACzE,OAAO,OAAO,SACV,OAAO,OAAO;EAAE,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CAAC,KAAK,OAAO,SAAS,OAAO,CAAC;EAC5E,0BAA0B,MAAM,eAC5B,OAAO,wBAAwB;GAAE;GAAM;EAAW,CAAC,CAAC,CAAC,KAAK,OAAO,SAAS,OAAO,CAAC;EACtF,WAAW,MAAM,YAAY,oBACzB,OAAO,eAAe;GAAE;GAAM;GAAY;EAAgB,CAAC,CAAC,CAAC,KAAK,OAAO,SAAS,OAAO,CAAC;EAC9F;EACA,QAAQ;GACJ,SAAS,OAAO,OAAO,cAAc;IAAE,WAAW;IAAU;GAAG,CAAC,CAAC,CAAC,KAAK,OAAO,SAAS,OAAO,CAAC;GAC/F,QAAQ,OAAO,OAAO,cAAc;IAAE,WAAW;IAAS;GAAG,CAAC,CAAC,CAAC,KAAK,OAAO,SAAS,OAAO,CAAC;GAC7F,OAAO,IAAI,eACP,OAAO,cAAc;IAAE,WAAW;IAAQ;IAAI;GAAW,CAAC,CAAC,CAAC,KAAK,OAAO,SAAS,OAAO,CAAC;EACjG;EACA;EACA;CACJ;AACJ,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"replicaBootstrap.d.ts","names":[],"sources":["../src/replicaBootstrap.ts"],"mappings":";;;;;;;iBAciB;WACJ,QAAQ;WACR;;YAGD,8BAA8B,KAAK;WAClC,UAAU;;WAEV,SAAS;;;;;;WAMT,KAAK;;;;;;;;qBA4DL,8BAA2B,kBAAA,aAAA,6BAAA;;;;;;;;;;;;;;;;;;MAuEtC,OAAA,OAAA,qBAAA,iWAAA,MAAA"}
1
+ {"version":3,"file":"replicaBootstrap.d.ts","names":[],"sources":["../src/replicaBootstrap.ts"],"mappings":";;;;;;;iBAeiB;WACJ,QAAQ;WACR;;YAGD,8BAA8B,KAAK;WAClC,UAAU;;WAEV,SAAS;;;;;;WAMT,KAAK;;;;;;;;qBA+DL,8BAA2B,kBAAA,aAAA,6BAAA;;;;;;;;;;;;;;;;;;MAuEtC,OAAA,OAAA,qBAAA,iWAAA,MAAA"}
@@ -1,6 +1,7 @@
1
1
  import { BackendError } from "@party-stack/ontology-backend";
2
2
  import { Effect, Option, Ref, Scope, Stream, SynchronizedRef } from "effect";
3
3
  import { ontologyDefinitionContractHash } from "@party-stack/ontology-storage";
4
+ import { Table } from "@party-stack/ontology-storage/tables";
4
5
  //#region src/replicaBootstrap.ts
5
6
  const mismatch = (message) => new BackendError({
6
7
  operation: "replica.definition",
@@ -8,9 +9,10 @@ const mismatch = (message) => new BackendError({
8
9
  retryable: false,
9
10
  message
10
11
  });
12
+ const contextIdentity = Table.make({ name: "context-identity" });
11
13
  const sameValue = (left, right) => {
12
14
  try {
13
- return JSON.stringify(left) === JSON.stringify(right);
15
+ return contextIdentity.encode(left) === contextIdentity.encode(right);
14
16
  } catch {
15
17
  return false;
16
18
  }
@@ -1 +1 @@
1
- {"version":3,"file":"replicaBootstrap.js","names":[],"sources":["../src/replicaBootstrap.ts"],"sourcesContent":["import { BackendError } from \"@party-stack/ontology-backend\";\nimport { ontologyDefinitionContractHash } from \"@party-stack/ontology-storage\";\nimport { Effect, Option, Ref, Scope, Stream, SynchronizedRef } from \"effect\";\nimport type { OntologyClient, OntologyServerClient } from \"./rpc.js\";\nimport type { OntologyBackendService } from \"@party-stack/ontology-backend\";\nimport type { OntologyDescription } from \"@party-stack/ontology-backend/description\";\nimport type { ReplicaConnection } from \"@party-stack/ontology-replica\";\nimport type {\n ReplicaRegistration,\n ReplicaRegistrationCommon,\n makeReplicaPartitionCatalog,\n} from \"@party-stack/ontology-replica/registry\";\nimport type { OntologyIR } from \"@party-stack/ontology-spec\";\n\nexport interface ReplicaUpstream {\n readonly client: OntologyServerClient;\n readonly ontology?: string;\n}\n\nexport type UpstreamReplicaRegistration = Omit<ReplicaRegistrationCommon, \"context\"> & {\n readonly upstream: ReplicaUpstream;\n /** Select the local account before opening its retained definition or data. */\n readonly context: Record<string, unknown>;\n /**\n * The application's contract, when it has one. The upstream's definition must match it, and\n * `onDefinitionChange` never replaces it. Without it, the replica takes the upstream's\n * definition, and with `onDefinitionChange: \"reset\"` follows it as it changes.\n */\n readonly ir?: OntologyIR;\n};\n\nconst mismatch = (message: string) =>\n new BackendError({ operation: \"replica.definition\", kind: \"SchemaMismatch\", retryable: false, message });\n\nconst sameValue = (left: unknown, right: unknown) => {\n try {\n return JSON.stringify(left) === JSON.stringify(right);\n } catch {\n return false;\n }\n};\n\n/**\n * The upstream's `meta` resource as a backend the replica can open before the upstream is\n * reachable: it connects on first use, and again after a failed connection.\n */\nconst lazyMetaBackend = Effect.fnUntraced(function* (upstream: ReplicaUpstream, sourceId: string) {\n const scope = yield* Effect.scope;\n const connected = yield* SynchronizedRef.make(Option.none<OntologyClient>());\n const client = SynchronizedRef.modifyEffect(connected, (current) =>\n Option.isSome(current)\n ? Effect.succeed([current.value, current] as const)\n : Effect.map(\n Scope.provide(upstream.client.ontology(upstream.ontology, { resource: \"meta\" }), scope),\n (opened) => [opened, Option.some(opened)] as const\n )\n );\n const backend = Effect.map(client, (opened) => opened.backend);\n const readOnly = (operation: string) =>\n Effect.fail(\n new BackendError({\n operation,\n kind: \"NotImplemented\",\n retryable: false,\n message: \"Metadata is read-only.\",\n })\n );\n return {\n name: \"upstream-metadata\",\n sourceId: `${sourceId}#meta`,\n supportsIdempotency: false,\n loadSubset: (subset) => Effect.flatMap(backend, (meta) => meta.loadSubset(subset)),\n query: (document, settings) => Effect.flatMap(backend, (meta) => meta.query(document, settings)),\n // Without a watch on the upstream, the endpoint closing ends this stream and the\n // replica watches again.\n watchSubset: (subset) =>\n Effect.flatMap(backend, (meta) => meta.watchSubset?.(subset) ?? Effect.succeed(Stream.never)),\n applyAction: () => readOnly(\"applyAction\"),\n queryFunction: () => readOnly(\"queryFunction\"),\n } satisfies OntologyBackendService;\n});\n\n/**\n * A replica fed by another party-stack server. It reopens its partition from the retained\n * binding (the upstream's description) without contacting the upstream. Without an application\n * contract its definition is dynamic: read from the upstream's `meta` resource through a meta\n * replica in the same storage, so it starts offline and follows the upstream's definition.\n */\nexport const upstreamReplicaRegistration = Effect.fn(\"OntologyServer.upstreamReplica\")(function* (\n ontology: string,\n declaration: UpstreamReplicaRegistration,\n catalog: Effect.Success<ReturnType<typeof makeReplicaPartitionCatalog>>\n): Effect.fn.Return<ReplicaRegistration, BackendError, Scope.Scope> {\n const { upstream, ir: contract, ...registration } = declaration;\n const stored = yield* catalog.lookup(ontology);\n const retained =\n stored?.bootstrap && (stored.context === undefined || sameValue(stored.context, declaration.context))\n ? stored.bootstrap\n : undefined;\n const initial =\n retained ??\n (yield* Effect.scoped(\n Effect.map(upstream.client.ontology(upstream.ontology), (client) => client.description)\n ));\n if (contract && initial.contractHash !== undefined) {\n const expected = yield* Effect.orElseSucceed(\n ontologyDefinitionContractHash(contract),\n () => undefined\n );\n if (expected !== initial.contractHash)\n return yield* mismatch(\"The upstream definition is incompatible with the application contract.\");\n }\n // The latest accepted binding. Capabilities may change while the definition does not.\n const binding = yield* Ref.make(initial);\n const follows = declaration.onDefinitionChange === \"reset\" && !contract;\n const connect = (ir: OntologyIR) =>\n Effect.gen(function* () {\n const accepted = yield* Ref.get(binding);\n const client = yield* upstream.client.ontology(upstream.ontology, {\n description: accepted,\n ir,\n // Keep the refreshed binding. A different definition is followed: requests under\n // the old one fail with SchemaMismatch, which revalidates the replica's metadata\n // (as the upstream's metadata watch does for a live replica), and it reopens.\n // Without following, it is a mismatch.\n validate: (fresh) =>\n Effect.gen(function* () {\n const expected = yield* Effect.orElseSucceed(\n ontologyDefinitionContractHash(ir),\n () => undefined\n );\n if (fresh.contractHash !== expected && !follows)\n return yield* mismatch(\"The upstream ontology definition changed.\");\n yield* Ref.set(binding, fresh);\n yield* catalog\n .saveBootstrap(ontology, fresh)\n .pipe(\n Effect.catch((error) =>\n Effect.logWarning(\"Could not retain the upstream description\", error)\n )\n );\n }),\n });\n // Following the definition status checks the upstream's binding as it changes.\n yield* client.definition.changes.pipe(Stream.runDrain, Effect.forkScoped);\n return {\n backend: client.backend,\n ...(client.replication.kind === \"speculative\" ? { source: client.replication.source } : {}),\n } satisfies ReplicaConnection;\n });\n return {\n ...registration,\n context: initial.context ?? {},\n definition: contract\n ? { kind: \"static\", ir: contract }\n : { kind: \"dynamic\", meta: yield* lazyMetaBackend(upstream, initial.sourceId) },\n backend: connect,\n bootstrap: initial,\n } satisfies ReplicaRegistration;\n});\n\nexport type { OntologyDescription };\n"],"mappings":";;;;AA+BA,MAAM,YAAY,YACd,IAAI,aAAa;CAAE,WAAW;CAAsB,MAAM;CAAkB,WAAW;CAAO;AAAQ,CAAC;AAE3G,MAAM,aAAa,MAAe,UAAmB;CACjD,IAAI;EACA,OAAO,KAAK,UAAU,IAAI,MAAM,KAAK,UAAU,KAAK;CACxD,QAAQ;EACJ,OAAO;CACX;AACJ;;;;;AAMA,MAAM,kBAAkB,OAAO,WAAW,WAAW,UAA2B,UAAkB;CAC9F,MAAM,QAAQ,OAAO,OAAO;CAC5B,MAAM,YAAY,OAAO,gBAAgB,KAAK,OAAO,KAAqB,CAAC;CAC3E,MAAM,SAAS,gBAAgB,aAAa,YAAY,YACpD,OAAO,OAAO,OAAO,IACf,OAAO,QAAQ,CAAC,QAAQ,OAAO,OAAO,CAAU,IAChD,OAAO,IACH,MAAM,QAAQ,SAAS,OAAO,SAAS,SAAS,UAAU,EAAE,UAAU,OAAO,CAAC,GAAG,KAAK,IACrF,WAAW,CAAC,QAAQ,OAAO,KAAK,MAAM,CAAC,CAC5C,CACV;CACA,MAAM,UAAU,OAAO,IAAI,SAAS,WAAW,OAAO,OAAO;CAC7D,MAAM,YAAY,cACd,OAAO,KACH,IAAI,aAAa;EACb;EACA,MAAM;EACN,WAAW;EACX,SAAS;CACb,CAAC,CACL;CACJ,OAAO;EACH,MAAM;EACN,UAAU,GAAG,SAAS;EACtB,qBAAqB;EACrB,aAAa,WAAW,OAAO,QAAQ,UAAU,SAAS,KAAK,WAAW,MAAM,CAAC;EACjF,QAAQ,UAAU,aAAa,OAAO,QAAQ,UAAU,SAAS,KAAK,MAAM,UAAU,QAAQ,CAAC;EAG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V,OAAO,WAAW,6CAA6C,KAAK,CACxE,CACJ;GACR,CAAC;EACT,CAAC;EAED,OAAO,OAAO,WAAW,QAAQ,KAAK,OAAO,UAAU,OAAO,UAAU;EACxE,OAAO;GACH,SAAS,OAAO;GAChB,GAAI,OAAO,YAAY,SAAS,gBAAgB,EAAE,QAAQ,OAAO,YAAY,OAAO,IAAI,CAAC;EAC7F;CACJ,CAAC;CACL,OAAO;EACH,GAAG;EACH,SAAS,QAAQ,WAAW,CAAC;EAC7B,YAAY,WACN;GAAE,MAAM;GAAU,IAAI;EAAS,IAC/B;GAAE,MAAM;GAAW,MAAM,OAAO,gBAAgB,UAAU,QAAQ,QAAQ;EAAE;EAClF,SAAS;EACT,WAAW;CACf;AACJ,CAAC"}
1
+ {"version":3,"file":"replicaBootstrap.js","names":[],"sources":["../src/replicaBootstrap.ts"],"sourcesContent":["import { BackendError } from \"@party-stack/ontology-backend\";\nimport { ontologyDefinitionContractHash } from \"@party-stack/ontology-storage\";\nimport { Table } from \"@party-stack/ontology-storage/tables\";\nimport { Effect, Option, Ref, Scope, Stream, SynchronizedRef } from \"effect\";\nimport type { OntologyClient, OntologyServerClient } from \"./rpc.js\";\nimport type { OntologyBackendService } from \"@party-stack/ontology-backend\";\nimport type { OntologyDescription } from \"@party-stack/ontology-backend/description\";\nimport type { ReplicaConnection } from \"@party-stack/ontology-replica\";\nimport type {\n ReplicaRegistration,\n ReplicaRegistrationCommon,\n makeReplicaPartitionCatalog,\n} from \"@party-stack/ontology-replica/registry\";\nimport type { OntologyIR } from \"@party-stack/ontology-spec\";\n\nexport interface ReplicaUpstream {\n readonly client: OntologyServerClient;\n readonly ontology?: string;\n}\n\nexport type UpstreamReplicaRegistration = Omit<ReplicaRegistrationCommon, \"context\"> & {\n readonly upstream: ReplicaUpstream;\n /** Select the local account before opening its retained definition or data. */\n readonly context: Record<string, unknown>;\n /**\n * The application's contract, when it has one. The upstream's definition must match it, and\n * `onDefinitionChange` never replaces it. Without it, the replica takes the upstream's\n * definition, and with `onDefinitionChange: \"reset\"` follows it as it changes.\n */\n readonly ir?: OntologyIR;\n};\n\nconst mismatch = (message: string) =>\n new BackendError({ operation: \"replica.definition\", kind: \"SchemaMismatch\", retryable: false, message });\n\n// Through the value codec: it orders object keys and keeps dates, bigints, maps and sets, so a\n// context matches regardless of the order the app wrote its fields in.\nconst contextIdentity = Table.make<unknown>({ name: \"context-identity\" });\nconst sameValue = (left: unknown, right: unknown) => {\n try {\n return contextIdentity.encode(left) === contextIdentity.encode(right);\n } catch {\n return false;\n }\n};\n\n/**\n * The upstream's `meta` resource as a backend the replica can open before the upstream is\n * reachable: it connects on first use, and again after a failed connection.\n */\nconst lazyMetaBackend = Effect.fnUntraced(function* (upstream: ReplicaUpstream, sourceId: string) {\n const scope = yield* Effect.scope;\n const connected = yield* SynchronizedRef.make(Option.none<OntologyClient>());\n const client = SynchronizedRef.modifyEffect(connected, (current) =>\n Option.isSome(current)\n ? Effect.succeed([current.value, current] as const)\n : Effect.map(\n Scope.provide(upstream.client.ontology(upstream.ontology, { resource: \"meta\" }), scope),\n (opened) => [opened, Option.some(opened)] as const\n )\n );\n const backend = Effect.map(client, (opened) => opened.backend);\n const readOnly = (operation: string) =>\n Effect.fail(\n new BackendError({\n operation,\n kind: \"NotImplemented\",\n retryable: false,\n message: \"Metadata is read-only.\",\n })\n );\n return {\n name: \"upstream-metadata\",\n sourceId: `${sourceId}#meta`,\n supportsIdempotency: false,\n loadSubset: (subset) => Effect.flatMap(backend, (meta) => meta.loadSubset(subset)),\n query: (document, settings) => Effect.flatMap(backend, (meta) => meta.query(document, settings)),\n // Without a watch on the upstream, the endpoint closing ends this stream and the\n // replica watches again.\n watchSubset: (subset) =>\n Effect.flatMap(backend, (meta) => meta.watchSubset?.(subset) ?? Effect.succeed(Stream.never)),\n applyAction: () => readOnly(\"applyAction\"),\n queryFunction: () => readOnly(\"queryFunction\"),\n } satisfies OntologyBackendService;\n});\n\n/**\n * A replica fed by another party-stack server. It reopens its partition from the retained\n * binding (the upstream's description) without contacting the upstream. Without an application\n * contract its definition is dynamic: read from the upstream's `meta` resource through a meta\n * replica in the same storage, so it starts offline and follows the upstream's definition.\n */\nexport const upstreamReplicaRegistration = Effect.fn(\"OntologyServer.upstreamReplica\")(function* (\n ontology: string,\n declaration: UpstreamReplicaRegistration,\n catalog: Effect.Success<ReturnType<typeof makeReplicaPartitionCatalog>>\n): Effect.fn.Return<ReplicaRegistration, BackendError, Scope.Scope> {\n const { upstream, ir: contract, ...registration } = declaration;\n const stored = yield* catalog.lookup(ontology);\n const retained =\n stored?.bootstrap && (stored.context === undefined || sameValue(stored.context, declaration.context))\n ? stored.bootstrap\n : undefined;\n const initial =\n retained ??\n (yield* Effect.scoped(\n Effect.map(upstream.client.ontology(upstream.ontology), (client) => client.description)\n ));\n if (contract && initial.contractHash !== undefined) {\n const expected = yield* Effect.orElseSucceed(\n ontologyDefinitionContractHash(contract),\n () => undefined\n );\n if (expected !== initial.contractHash)\n return yield* mismatch(\"The upstream definition is incompatible with the application contract.\");\n }\n // The latest accepted binding. Capabilities may change while the definition does not.\n const binding = yield* Ref.make(initial);\n const follows = declaration.onDefinitionChange === \"reset\" && !contract;\n const connect = (ir: OntologyIR) =>\n Effect.gen(function* () {\n const accepted = yield* Ref.get(binding);\n const client = yield* upstream.client.ontology(upstream.ontology, {\n description: accepted,\n ir,\n // Keep the refreshed binding. A different definition is followed: requests under\n // the old one fail with SchemaMismatch, which revalidates the replica's metadata\n // (as the upstream's metadata watch does for a live replica), and it reopens.\n // Without following, it is a mismatch.\n validate: (fresh) =>\n Effect.gen(function* () {\n const expected = yield* Effect.orElseSucceed(\n ontologyDefinitionContractHash(ir),\n () => undefined\n );\n if (fresh.contractHash !== expected && !follows)\n return yield* mismatch(\"The upstream ontology definition changed.\");\n yield* Ref.set(binding, fresh);\n yield* catalog\n .saveBootstrap(ontology, fresh)\n .pipe(\n Effect.catch((error) =>\n Effect.logWarning(\"Could not retain the upstream description\", error)\n )\n );\n }),\n });\n // Following the definition status checks the upstream's binding as it changes.\n yield* client.definition.changes.pipe(Stream.runDrain, Effect.forkScoped);\n return {\n backend: client.backend,\n ...(client.replication.kind === \"speculative\" ? { source: client.replication.source } : {}),\n } satisfies ReplicaConnection;\n });\n return {\n ...registration,\n context: initial.context ?? {},\n definition: contract\n ? { kind: \"static\", ir: contract }\n : { kind: \"dynamic\", meta: yield* lazyMetaBackend(upstream, initial.sourceId) },\n backend: connect,\n bootstrap: initial,\n } satisfies ReplicaRegistration;\n});\n\nexport type { OntologyDescription };\n"],"mappings":";;;;;AAgCA,MAAM,YAAY,YACd,IAAI,aAAa;CAAE,WAAW;CAAsB,MAAM;CAAkB,WAAW;CAAO;AAAQ,CAAC;AAI3G,MAAM,kBAAkB,MAAM,KAAc,EAAE,MAAM,mBAAmB,CAAC;AACxE,MAAM,aAAa,MAAe,UAAmB;CACjD,IAAI;EACA,OAAO,gBAAgB,OAAO,IAAI,MAAM,gBAAgB,OAAO,KAAK;CACxE,QAAQ;EACJ,OAAO;CACX;AACJ;;;;;AAMA,MAAM,kBAAkB,OAAO,WAAW,WAAW,UAA2B,UAAkB;CAC9F,MAAM,QAAQ,OAAO,OAAO;CAC5B,MAAM,YAAY,OAAO,gBAAgB,KAAK,OAAO,KAAqB,CAAC;CAC3E,MAAM,SAAS,gBAAgB,aAAa,YAAY,YACpD,OAAO,OAAO,OAAO,IACf,OAAO,QAAQ,CAAC,QAAQ,OAAO,OAAO,CAAU,IAChD,OAAO,IACH,MAAM,QAAQ,SAAS,OAAO,SAAS,SAAS,UAAU,EAAE,UAAU,OAAO,CAAC,GAAG,KAAK,IACrF,WAAW,CAAC,QAAQ,OAAO,KAAK,MAAM,CAAC,CAC5C,CACV;CACA,MAAM,UAAU,OAAO,IAAI,SAAS,WAAW,OAAO,OAAO;CAC7D,MAAM,YAAY,cACd,OAAO,KACH,IAAI,aAAa;EACb;EACA,MAAM;EACN,WAAW;EACX,SAAS;CACb,CAAC,CACL;CACJ,OAAO;EACH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AAK,uBAAuB;iBA0X/E;GACZ,iBAAiB,+BACd,SACM,qBAAqB,GAAG,OAAO,QAAQ,oBAAoB,IAAI,oBAAoB,OACnF,uBAAuB,KAC9B,OAAO,OAAO,eAAe,QAAQ,GAAG,MAAM,SAAS,cAAc,IAAI,MAAM;GACjF,iBAAiB,+BACd,SAAS,qBAAqB,GAAG,SAClC,OAAO,OAAO,eAAe,QAAQ,GAAG,MAAM,SAAS,cAAc,IAAI,WAAW,MAAM;;qBAEpF,oBAAoB;;qBAGpB,yBAA0B,WAAS,QAAU,eAAe,OAAE,MAAA,MAAA,IAAA,oBAAA,IAAA,yBAAA,IAAA,yBAAA,IAAA,yBAAA,IAAA,gCAAA,IAAA,qBAAA,IAAA,2BAAA,IAAA,8BAAA,IAAA,qBAAA,IAAA,6BAAA,IAAA,oBAAA,IAAA,sBAAA,IAAA,wBAAA,IAAA,wBAAA,IAAA,yBAAA,IAAA,mBAAA,IAAA,2BAAA,IAAA,kBAAA,IAAA,4BAAA,IAAA,0BAAA,IAAA,2BAAA,IAAA,qCAAA,IAAA,oBAAA,IAAA,gCAAA,IAAA,4BAAA,IAAA,oBAAA,IAAA,wBAAA,IAAA,4BAAA,IAAA,0BAAA,IAAA,yBAAA,IAAA,kCAAA,gCAAA,QAAA,QAAA,WAAA,MAAA"}
package/lib/routing.js CHANGED
@@ -5,6 +5,7 @@ import { upstreamReplicaRegistration } from "./replicaBootstrap.js";
5
5
  import { BackendError, projectBackendError } from "@party-stack/ontology-backend";
6
6
  import { Context, Effect, Equal, Exit, Hash, Layer, Option, RcMap, Schema, Scope, Stream } from "effect";
7
7
  import { RpcSchema } from "effect/rpc";
8
+ import { Table } from "@party-stack/ontology-storage/tables";
8
9
  import { CurrentExecutionContext } from "@party-stack/ontology-backend/policy";
9
10
  import { replicaBackend } from "@party-stack/ontology-replica/infrastructure";
10
11
  import { makeReplicaPartitionCatalog } from "@party-stack/ontology-replica/registry";
@@ -55,6 +56,7 @@ const replicaGeneration = (target) => {
55
56
  backend
56
57
  };
57
58
  };
59
+ const contextIdentity = Table.make({ name: "endpoint-context" });
58
60
  var EndpointKey = class EndpointKey {
59
61
  ontology;
60
62
  options;
@@ -70,7 +72,7 @@ var EndpointKey = class EndpointKey {
70
72
  options.backend,
71
73
  options.kind === "replica" ? options.replica : options.kind === "cached-proxy" ? options.cache : void 0,
72
74
  options.ir,
73
- JSON.stringify(context),
75
+ context === void 0 ? void 0 : contextIdentity.encode(context),
74
76
  options.authenticate,
75
77
  options.dangerouslyAllowInternalAccess,
76
78
  options.enableRealtime,