@party-stack/ontology-backend 0.7.0 → 0.8.1
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.
- package/lib/delivery.d.ts +10 -0
- package/lib/delivery.d.ts.map +1 -1
- package/lib/errors.d.ts +16 -0
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +8 -0
- package/lib/errors.js.map +1 -1
- package/lib/index.d.ts +3 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/protocol.d.ts +16 -6
- package/lib/protocol.d.ts.map +1 -1
- package/lib/protocol.js +3 -1
- package/lib/protocol.js.map +1 -1
- package/package.json +3 -3
package/lib/delivery.d.ts
CHANGED
|
@@ -39,6 +39,7 @@ export declare const DeliveryRecordSchema: Schema.Union<readonly [Schema.Struct<
|
|
|
39
39
|
readonly now: Schema.String;
|
|
40
40
|
readonly seed: Schema.NonEmptyString;
|
|
41
41
|
}>>;
|
|
42
|
+
readonly timeoutMs: Schema.optional<Schema.Finite>;
|
|
42
43
|
}>;
|
|
43
44
|
readonly requestIdentity: Schema.String;
|
|
44
45
|
readonly createdAt: Schema.Finite;
|
|
@@ -46,6 +47,7 @@ export declare const DeliveryRecordSchema: Schema.Union<readonly [Schema.Struct<
|
|
|
46
47
|
readonly state: Schema.Literals<readonly ["queued", "sending", "acknowledged", "blocked"]>;
|
|
47
48
|
readonly optimistic: Schema.Boolean;
|
|
48
49
|
readonly attempts: Schema.Int;
|
|
50
|
+
readonly blockedBy: Schema.optional<Schema.Union<readonly [Schema.NonEmptyString, Schema.Literal<true>]>>;
|
|
49
51
|
readonly retryFromAttempt: Schema.optional<Schema.Int>;
|
|
50
52
|
readonly nextAttemptAt: Schema.optional<Schema.Finite>;
|
|
51
53
|
readonly failureMessage: Schema.optional<Schema.String>;
|
|
@@ -118,6 +120,7 @@ export declare const DeliveryChangeSchema: Schema.Union<readonly [Schema.Struct<
|
|
|
118
120
|
readonly now: Schema.String;
|
|
119
121
|
readonly seed: Schema.NonEmptyString;
|
|
120
122
|
}>>;
|
|
123
|
+
readonly timeoutMs: Schema.optional<Schema.Finite>;
|
|
121
124
|
}>;
|
|
122
125
|
readonly requestIdentity: Schema.String;
|
|
123
126
|
readonly createdAt: Schema.Finite;
|
|
@@ -125,6 +128,7 @@ export declare const DeliveryChangeSchema: Schema.Union<readonly [Schema.Struct<
|
|
|
125
128
|
readonly state: Schema.Literals<readonly ["queued", "sending", "acknowledged", "blocked"]>;
|
|
126
129
|
readonly optimistic: Schema.Boolean;
|
|
127
130
|
readonly attempts: Schema.Int;
|
|
131
|
+
readonly blockedBy: Schema.optional<Schema.Union<readonly [Schema.NonEmptyString, Schema.Literal<true>]>>;
|
|
128
132
|
readonly retryFromAttempt: Schema.optional<Schema.Int>;
|
|
129
133
|
readonly nextAttemptAt: Schema.optional<Schema.Finite>;
|
|
130
134
|
readonly failureMessage: Schema.optional<Schema.String>;
|
|
@@ -252,6 +256,7 @@ export declare const DeliveryFrameSchema: Schema.Struct<{
|
|
|
252
256
|
readonly now: Schema.String;
|
|
253
257
|
readonly seed: Schema.NonEmptyString;
|
|
254
258
|
}>>;
|
|
259
|
+
readonly timeoutMs: Schema.optional<Schema.Finite>;
|
|
255
260
|
}>;
|
|
256
261
|
readonly requestIdentity: Schema.String;
|
|
257
262
|
readonly createdAt: Schema.Finite;
|
|
@@ -259,6 +264,7 @@ export declare const DeliveryFrameSchema: Schema.Struct<{
|
|
|
259
264
|
readonly state: Schema.Literals<readonly ["queued", "sending", "acknowledged", "blocked"]>;
|
|
260
265
|
readonly optimistic: Schema.Boolean;
|
|
261
266
|
readonly attempts: Schema.Int;
|
|
267
|
+
readonly blockedBy: Schema.optional<Schema.Union<readonly [Schema.NonEmptyString, Schema.Literal<true>]>>;
|
|
262
268
|
readonly retryFromAttempt: Schema.optional<Schema.Int>;
|
|
263
269
|
readonly nextAttemptAt: Schema.optional<Schema.Finite>;
|
|
264
270
|
readonly failureMessage: Schema.optional<Schema.String>;
|
|
@@ -388,6 +394,7 @@ export declare const DeliveryFrameCodec: Schema.Codec<{
|
|
|
388
394
|
readonly now: string;
|
|
389
395
|
readonly seed: string;
|
|
390
396
|
} | undefined;
|
|
397
|
+
readonly timeoutMs?: number | undefined;
|
|
391
398
|
};
|
|
392
399
|
readonly requestIdentity: string;
|
|
393
400
|
readonly createdAt: number;
|
|
@@ -395,6 +402,7 @@ export declare const DeliveryFrameCodec: Schema.Codec<{
|
|
|
395
402
|
readonly state: "acknowledged" | "blocked" | "queued" | "sending";
|
|
396
403
|
readonly optimistic: boolean;
|
|
397
404
|
readonly attempts: number;
|
|
405
|
+
readonly blockedBy?: string | true | undefined;
|
|
398
406
|
readonly retryFromAttempt?: number | undefined;
|
|
399
407
|
readonly nextAttemptAt?: number | undefined;
|
|
400
408
|
readonly failureMessage?: string | undefined;
|
|
@@ -627,6 +635,7 @@ export declare const makeDeliveryReceiver: (options: {
|
|
|
627
635
|
readonly now: string;
|
|
628
636
|
readonly seed: string;
|
|
629
637
|
} | undefined;
|
|
638
|
+
readonly timeoutMs?: number | undefined;
|
|
630
639
|
};
|
|
631
640
|
readonly requestIdentity: string;
|
|
632
641
|
readonly createdAt: number;
|
|
@@ -634,6 +643,7 @@ export declare const makeDeliveryReceiver: (options: {
|
|
|
634
643
|
readonly state: "acknowledged" | "blocked" | "queued" | "sending";
|
|
635
644
|
readonly optimistic: boolean;
|
|
636
645
|
readonly attempts: number;
|
|
646
|
+
readonly blockedBy?: string | true | undefined;
|
|
637
647
|
readonly retryFromAttempt?: number | undefined;
|
|
638
648
|
readonly nextAttemptAt?: number | undefined;
|
|
639
649
|
readonly failureMessage?: string | undefined;
|
package/lib/delivery.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delivery.d.ts","names":[],"sources":["../src/delivery.ts"],"mappings":";;;;;;qBAaa,mBAAiB,OAAA,gBAAA,OAAA;;;;;;;;qBAIjB,sBAAoB,OAAA,gBAAA,OAAA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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MA2RjC;MACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsB1C,iWAAA,MAAA"}
|
package/lib/errors.d.ts
CHANGED
|
@@ -46,6 +46,14 @@ declare const Fields: {
|
|
|
46
46
|
readonly source: Schema.optional<Schema.Literals<readonly ["parameter", "submission", "user-facing"]>>;
|
|
47
47
|
readonly messageSource: Schema.optional<Schema.Literals<readonly ["standard", "configured"]>>;
|
|
48
48
|
}>>>;
|
|
49
|
+
/** Set when an action is still pending behind an earlier blocked action: its queue
|
|
50
|
+
* stopped there and sends nothing after it until that action is retried, reconciled
|
|
51
|
+
* or removed. The waiting action keeps its place in the queue. */
|
|
52
|
+
blockedBy: Schema.optional<Schema.Struct<{
|
|
53
|
+
readonly id: Schema.String;
|
|
54
|
+
readonly name: Schema.String;
|
|
55
|
+
readonly failure: Schema.optional<Schema.Literals<readonly ["Unauthenticated", "Forbidden", "NotFound", "ValidationFailed", "InvalidRequest", "InvalidResponse", "InvalidConfiguration", "Conflict", "NotImplemented", "RateLimited", "Unavailable", "Internal", "HistoryExpired", "SessionExpired", "SessionReplaced", "ViewReplaced", "ResultExpired", "SourceMismatch", "SchemaMismatch"]>>;
|
|
56
|
+
}>>;
|
|
49
57
|
cause: Schema.optional<Schema.Defect>;
|
|
50
58
|
};
|
|
51
59
|
declare const BackendError_base: Schema.Class<BackendError<"Conflict" | "Forbidden" | "HistoryExpired" | "Internal" | "InvalidConfiguration" | "InvalidRequest" | "InvalidResponse" | "NotFound" | "NotImplemented" | "RateLimited" | "ResultExpired" | "SchemaMismatch" | "SessionExpired" | "SessionReplaced" | "SourceMismatch" | "Unauthenticated" | "Unavailable" | "ValidationFailed" | "ViewReplaced">, Schema.TaggedStruct<"BackendError", {
|
|
@@ -63,6 +71,14 @@ declare const BackendError_base: Schema.Class<BackendError<"Conflict" | "Forbidd
|
|
|
63
71
|
readonly source: Schema.optional<Schema.Literals<readonly ["parameter", "submission", "user-facing"]>>;
|
|
64
72
|
readonly messageSource: Schema.optional<Schema.Literals<readonly ["standard", "configured"]>>;
|
|
65
73
|
}>>>;
|
|
74
|
+
/** Set when an action is still pending behind an earlier blocked action: its queue
|
|
75
|
+
* stopped there and sends nothing after it until that action is retried, reconciled
|
|
76
|
+
* or removed. The waiting action keeps its place in the queue. */
|
|
77
|
+
blockedBy: Schema.optional<Schema.Struct<{
|
|
78
|
+
readonly id: Schema.String;
|
|
79
|
+
readonly name: Schema.String;
|
|
80
|
+
readonly failure: Schema.optional<Schema.Literals<readonly ["Unauthenticated", "Forbidden", "NotFound", "ValidationFailed", "InvalidRequest", "InvalidResponse", "InvalidConfiguration", "Conflict", "NotImplemented", "RateLimited", "Unavailable", "Internal", "HistoryExpired", "SessionExpired", "SessionReplaced", "ViewReplaced", "ResultExpired", "SourceMismatch", "SchemaMismatch"]>>;
|
|
81
|
+
}>>;
|
|
66
82
|
cause: Schema.optional<Schema.Defect>;
|
|
67
83
|
}>, import("effect/Cause").YieldableError>;
|
|
68
84
|
/** Shared wire schema; hooks narrow the kind without duplicating error classes. */
|
package/lib/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","names":[],"sources":["../src/errors.ts"],"mappings":";;;qBAQa,uBAAqB,OAAA;;;;;;;;qBAQrB,wBAAsB,OAAA,gBAAA,OAAA;;;;;;;;;;;;;;;;;;;YAUvB,0BAA0B,uBAAuB;qBAEhD,wBAAsB,OAAA;YAqBvB,0BAA0B,uBAAuB;cACvD;EACF,WAAS,OAAA;EACT,MAAI,OAAA;EACJ,SAAO,OAAA;EACP,WAAS,OAAA;EACT,eAAa,OAAA,SAAA,OAAA;EACb,cAAY,OAAA,SAAA,OAAA;EACZ,QAAM,OAAA,SAAA,OAAA,OAAA,OAAA
|
|
1
|
+
{"version":3,"file":"errors.d.ts","names":[],"sources":["../src/errors.ts"],"mappings":";;;qBAQa,uBAAqB,OAAA;;;;;;;;qBAQrB,wBAAsB,OAAA,gBAAA,OAAA;;;;;;;;;;;;;;;;;;;YAUvB,0BAA0B,uBAAuB;qBAEhD,wBAAsB,OAAA;YAqBvB,0BAA0B,uBAAuB;cACvD;EACF,WAAS,OAAA;EACT,MAAI,OAAA;EACJ,SAAO,OAAA;EACP,WAAS,OAAA;EACT,eAAa,OAAA,SAAA,OAAA;EACb,cAAY,OAAA,SAAA,OAAA;EACZ,QAAM,OAAA,SAAA,OAAA,OAAA,OAAA;;;;;;;;;;;EAIN,WAAS,OAAA,SAAA,OAAA;;;;;EAOT,OAAK,OAAA,SAAA,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAGI,aACT,UAAU,mBAAmB,0BACvB;WACW,MAAM;EACvB,YAAY,YAAY,KAAK,OAAO,OAAO,YAAY;aAA8B,MAAM;;;;qBAKlF,qBAAkB,OAAW,KAAK;YAsBnC;YAaA,mBAAmB,aAAa;YAChC,sBAAsB,aAAa;YACnC;YAQA,mBAAmB,aAAa;YAChC,kBAAkB,aAC1B,QAAQ;qBAGC,kBAAe,kBAAA,UAAuD,iBAAY;qBASlF,yBAAsB,mBAAqB,SAAS;;qBAIpD,yBAAsB,OAAW;;wBAuB9B,uBAAuB,mBAAmB,iBAAiB;iBA6L1D;;WAEJ;WACA;;WAEA;;YAED,8CAGJ,OAAO,cAAc,SAAS,2BAA2B;wBACjD,uBACZ,OAAO,iBACP,SAAS,yBACV;;;wBA4Ba,oBACZ,OAAO,cACP,SAAQ,iBACR,UAAS,yBACV;YA2CS,uBAAuB;;wBAGnB,uBAAuB,OAAO,OAAO,uBAAuB"}
|
package/lib/errors.js
CHANGED
|
@@ -59,6 +59,14 @@ const Fields = {
|
|
|
59
59
|
actionOutcome: Schema.optional(Schema.Literals(["not-committed", "unknown"])),
|
|
60
60
|
retryAfterMs: Schema.optional(Schema.Finite),
|
|
61
61
|
issues: Schema.optional(Schema.Array(ValidationIssueSchema)),
|
|
62
|
+
/** Set when an action is still pending behind an earlier blocked action: its queue
|
|
63
|
+
* stopped there and sends nothing after it until that action is retried, reconciled
|
|
64
|
+
* or removed. The waiting action keeps its place in the queue. */
|
|
65
|
+
blockedBy: Schema.optional(Schema.Struct({
|
|
66
|
+
id: Schema.String,
|
|
67
|
+
name: Schema.String,
|
|
68
|
+
failure: Schema.optional(BackendErrorKindSchema)
|
|
69
|
+
})),
|
|
62
70
|
cause: Schema.optional(Schema.Defect())
|
|
63
71
|
};
|
|
64
72
|
/** Shared wire schema; hooks narrow the kind without duplicating error classes. */
|
package/lib/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","names":[],"sources":["../src/errors.ts"],"sourcesContent":["import { OntologyStorageError } from \"@party-stack/ontology-storage\";\nimport { BlobStorageError } from \"@party-stack/ontology-storage/blobs\";\nimport { Predicate, Schema, SchemaIssue, Redacted } from \"effect\";\nimport { HttpClientError } from \"effect/http\";\nimport { RpcClientError } from \"effect/rpc\";\nimport type { ValidationIssue } from \"@party-stack/ontology-spec\";\n\nexport type { ValidationIssue };\nexport const ValidationIssueSchema = Schema.Struct({\n message: Schema.String,\n path: Schema.optional(Schema.Array(Schema.Union([Schema.String, Schema.Number]))),\n code: Schema.optional(Schema.String),\n category: Schema.optional(Schema.Literals([\"input\", \"reference\", \"custom\"])),\n source: Schema.optional(Schema.Literals([\"parameter\", \"submission\", \"user-facing\"])),\n messageSource: Schema.optional(Schema.Literals([\"standard\", \"configured\"])),\n});\nexport const ValidationReportSchema = Schema.Union([\n Schema.Struct({ certain: Schema.Literal(false) }),\n Schema.Struct({\n certain: Schema.Literal(true),\n value: Schema.Union([\n Schema.Struct({ kind: Schema.Literal(\"ok\"), value: Schema.Void }),\n Schema.Struct({ kind: Schema.Literal(\"err\"), value: Schema.Array(ValidationIssueSchema) }),\n ]),\n }),\n]);\nexport type ValidationReport = typeof ValidationReportSchema.Type;\n\nexport const BackendErrorKindSchema = Schema.Literals([\n \"Unauthenticated\",\n \"Forbidden\",\n \"NotFound\",\n \"ValidationFailed\",\n \"InvalidRequest\",\n \"InvalidResponse\",\n \"InvalidConfiguration\",\n \"Conflict\",\n \"NotImplemented\",\n \"RateLimited\",\n \"Unavailable\",\n \"Internal\",\n \"HistoryExpired\",\n \"SessionExpired\",\n \"SessionReplaced\",\n \"ViewReplaced\",\n \"ResultExpired\",\n \"SourceMismatch\",\n \"SchemaMismatch\",\n]);\nexport type BackendErrorKind = typeof BackendErrorKindSchema.Type;\nconst Fields = {\n operation: Schema.String,\n kind: BackendErrorKindSchema,\n message: Schema.String,\n retryable: Schema.Boolean,\n actionOutcome: Schema.optional(Schema.Literals([\"not-committed\", \"unknown\"])),\n retryAfterMs: Schema.optional(Schema.Finite),\n issues: Schema.optional(Schema.Array(ValidationIssueSchema)),\n cause: Schema.optional(Schema.Defect()),\n};\n/** Shared wire schema; hooks narrow the kind without duplicating error classes. */\nexport class BackendError<\n K extends BackendErrorKind = BackendErrorKind,\n> extends Schema.TaggedError<BackendError>()(\"BackendError\", Fields) {\n declare readonly kind: K;\n constructor(properties: Omit<Schema.Struct.Type<typeof Fields>, \"kind\"> & { readonly kind: K }) {\n super(properties);\n }\n}\n/** HTTP bindings share these statuses; RPC still carries the typed error schema. */\nexport const backendErrorStatus = (error: Pick<BackendError, \"kind\">): number =>\n ({\n Unauthenticated: 401,\n Forbidden: 403,\n NotFound: 404,\n ValidationFailed: 422,\n InvalidRequest: 400,\n InvalidResponse: 502,\n InvalidConfiguration: 500,\n Conflict: 409,\n NotImplemented: 501,\n RateLimited: 429,\n Unavailable: 503,\n Internal: 500,\n HistoryExpired: 409,\n SessionExpired: 409,\n SessionReplaced: 409,\n ViewReplaced: 409,\n ResultExpired: 409,\n SourceMismatch: 409,\n SchemaMismatch: 409,\n })[error.kind];\nexport type OperationErrorKind =\n | \"Unauthenticated\"\n | \"Forbidden\"\n | \"NotFound\"\n | \"ValidationFailed\"\n | \"InvalidRequest\"\n | \"InvalidResponse\"\n | \"InvalidConfiguration\"\n | \"Conflict\"\n | \"NotImplemented\"\n | \"RateLimited\"\n | \"Unavailable\"\n | \"Internal\";\nexport type ApplyActionError = BackendError<OperationErrorKind>;\nexport type ValidateActionError = BackendError<OperationErrorKind>;\nexport type ReplicationErrorKind =\n | \"HistoryExpired\"\n | \"SessionExpired\"\n | \"SessionReplaced\"\n | \"ViewReplaced\"\n | \"ResultExpired\"\n | \"SourceMismatch\"\n | \"SchemaMismatch\";\nexport type ReplicationError = BackendError<ReplicationErrorKind>;\nexport type LoadSubsetError = BackendError<\n Exclude<OperationErrorKind, \"ValidationFailed\"> | \"HistoryExpired\"\n>;\n\nexport const unauthenticated = (message = \"Authentication is required.\", options?: ErrorOptions) =>\n new BackendError({\n operation: \"authentication\",\n kind: \"Unauthenticated\",\n message,\n retryable: false,\n actionOutcome: \"not-committed\",\n cause: options?.cause,\n });\nexport const isUnauthenticatedError = (error: unknown): error is BackendError<\"Unauthenticated\"> =>\n error instanceof BackendError && error.kind === \"Unauthenticated\";\n\n/** Unknown outcomes apply to dispatch/execution failures, never ordinary rejections. */\nexport const isUnknownActionOutcome = (error: BackendError) =>\n error.actionOutcome === \"unknown\" ||\n (error.actionOutcome === undefined &&\n (error.kind === \"Unavailable\" || error.kind === \"Internal\" || error.kind === \"InvalidResponse\"));\n\nconst ProviderFailure = Schema.Struct({\n reason: Schema.optional(Schema.Unknown),\n cause: Schema.optional(Schema.Unknown),\n response: Schema.optional(\n Schema.Struct({\n status: Schema.Number,\n headers: Schema.optional(Schema.Record(Schema.String, Schema.String)),\n })\n ),\n retryAfterMs: Schema.optional(Schema.Finite),\n status: Schema.optional(Schema.Number),\n statusCode: Schema.optional(Schema.Number),\n errorCode: Schema.optional(Schema.String),\n errorName: Schema.optional(Schema.String),\n code: Schema.optional(Schema.String),\n parameters: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),\n});\n/** Normalize SDK failures. No provider message/body is made public by this classifier. */\nexport function classifyBackendFailure(operation: string, cause: unknown): BackendError {\n if (cause instanceof BackendError) return cause;\n // Effect RPC currently puts HTTP EOF in RpcClientDefect alongside decoding\n // failures. Only its two explicit EOF cases mean transport loss; malformed\n // frames must remain terminal InvalidResponse failures. Replace this narrow\n // normalization when upstream exposes a structured interrupted-response reason.\n if (\n cause instanceof RpcClientError.RpcClientError &&\n cause.reason._tag === \"RpcClientDefect\" &&\n (cause.reason.message === \"HTTP response ended before RPC request completed\" ||\n cause.reason.message === \"Received empty HTTP response from RPC server\")\n )\n return new BackendError({\n operation,\n kind: \"Unavailable\",\n message: \"The RPC connection was interrupted.\",\n retryable: true,\n actionOutcome: \"unknown\",\n cause: Redacted.make(cause),\n });\n if (\n (cause instanceof RpcClientError.RpcClientError && cause.reason._tag === \"RpcClientDefect\") ||\n (cause instanceof HttpClientError.HttpClientError && cause.reason._tag === \"DecodeError\")\n )\n return new BackendError({\n operation,\n kind: \"InvalidResponse\",\n message: \"The source returned an invalid response.\",\n retryable: false,\n actionOutcome: \"unknown\",\n cause: Redacted.make(cause),\n });\n if (\n cause instanceof HttpClientError.HttpClientError &&\n (cause.reason._tag === \"EncodeError\" || cause.reason._tag === \"InvalidUrlError\")\n )\n return new BackendError({\n operation,\n kind: cause.reason._tag === \"EncodeError\" ? \"InvalidRequest\" : \"InvalidConfiguration\",\n message: \"The request could not be constructed.\",\n retryable: false,\n actionOutcome: \"not-committed\",\n cause: Redacted.make(cause),\n });\n const blob =\n cause instanceof BlobStorageError\n ? cause\n : cause instanceof OntologyStorageError && cause.reason._tag === \"BlobStorageError\"\n ? cause.reason\n : undefined;\n if (blob) {\n return new BackendError({\n operation,\n kind:\n blob.kind === \"NotFound\"\n ? \"NotFound\"\n : blob.kind === \"InvalidValue\"\n ? \"InvalidRequest\"\n : blob.kind === \"Busy\" || blob.kind === \"Conflict\"\n ? \"Conflict\"\n : \"Unavailable\",\n message:\n blob.kind === \"NotFound\"\n ? \"Attachment is unavailable.\"\n : blob.kind === \"Busy\"\n ? \"Attachment upload is still in progress.\"\n : blob.kind === \"Conflict\"\n ? \"Attachment state conflicts with this operation.\"\n : blob.kind === \"InvalidValue\"\n ? \"Invalid attachment value.\"\n : \"Attachment storage is unavailable.\",\n retryable: blob.kind === \"Busy\" || blob.kind === \"Bytes\",\n cause: Redacted.make(cause),\n });\n }\n if (cause instanceof OntologyStorageError) {\n const reason = cause.reason;\n const kind: BackendErrorKind =\n reason._tag === \"QueryError\"\n ? \"InvalidRequest\"\n : reason._tag === \"ConfigurationError\" || reason._tag === \"IndexError\"\n ? \"InvalidConfiguration\"\n : reason._tag === \"DefinitionMismatch\" || reason._tag === \"SchemaMismatch\"\n ? \"SchemaMismatch\"\n : reason._tag === \"UniqueConstraint\"\n ? \"Conflict\"\n : reason._tag === \"StorageError\" ||\n (reason._tag === \"TransactionError\" && reason.kind === \"Backend\")\n ? \"Unavailable\"\n : \"Internal\";\n return new BackendError({\n operation,\n kind,\n message:\n kind === \"InvalidRequest\"\n ? \"Invalid storage query.\"\n : kind === \"SchemaMismatch\"\n ? \"Storage schema changed; migrate or reset explicitly.\"\n : \"Storage operation failed.\",\n retryable: cause.isRetryable,\n cause: Redacted.make(cause),\n });\n }\n let candidate = cause;\n let value: typeof ProviderFailure.Type | undefined;\n for (let depth = 0; depth < 5; depth++) {\n if (candidate instanceof BackendError) return candidate;\n const decoded = Schema.decodeUnknownOption(ProviderFailure)(candidate);\n if (decoded._tag === \"None\") break;\n value = decoded.value;\n if (value.cause instanceof BackendError) return value.cause;\n if (\n value.status !== undefined ||\n value.statusCode !== undefined ||\n value.errorCode !== undefined ||\n value.code !== undefined ||\n value.errorName !== undefined ||\n value.response\n )\n break;\n candidate = value.reason ?? value.cause;\n }\n const status = value?.status ?? value?.statusCode ?? value?.response?.status;\n const code = value?.errorCode ?? value?.code;\n const name = value?.errorName?.split(\":\").at(-1);\n const kind: OperationErrorKind =\n status === 501\n ? \"NotImplemented\"\n : status === 401 || code === \"UNAUTHORIZED\" || code === \"INVALID_SESSION_ID\"\n ? \"Unauthenticated\"\n : status === 429 || code === \"REQUEST_LIMIT_EXCEEDED\" || name === \"RateLimitReached\"\n ? \"RateLimited\"\n : status === 403 || code === \"PERMISSION_DENIED\" || code === \"INSUFFICIENT_ACCESS_OR_READONLY\"\n ? \"Forbidden\"\n : status === 404 || code === \"NOT_FOUND\"\n ? \"NotFound\"\n : name === \"FunctionEncounteredUserFacingError\" ||\n name === \"QueryEncounteredUserFacingError\"\n ? \"ValidationFailed\"\n : code === \"FIELD_CUSTOM_VALIDATION_EXCEPTION\" || code === \"REQUIRED_FIELD_MISSING\"\n ? \"ValidationFailed\"\n : status === 400 || code === \"INVALID_ARGUMENT\"\n ? \"InvalidRequest\"\n : status === 409\n ? \"Conflict\"\n : \"Unavailable\";\n const authored =\n name === \"FunctionEncounteredUserFacingError\" || name === \"QueryEncounteredUserFacingError\";\n const issues: readonly ValidationIssue[] | undefined =\n authored && Predicate.isString(value?.parameters?.message)\n ? [\n {\n message: value.parameters.message,\n code: \"custom\",\n category: \"custom\",\n source: \"user-facing\",\n messageSource: \"configured\",\n },\n ]\n : undefined;\n const seconds = value?.response?.headers?.[\"retry-after\"];\n const retryAfterMs =\n value?.retryAfterMs ??\n (seconds !== undefined && /^\\d+(?:\\.\\d+)?$/.test(seconds) ? Number(seconds) * 1_000 : undefined);\n return new BackendError({\n operation,\n kind,\n retryAfterMs,\n message: {\n Unauthenticated: \"Authentication is required.\",\n Forbidden: \"This operation is not permitted.\",\n NotFound: \"Resource not found.\",\n ValidationFailed: \"Submission failed validation.\",\n InvalidRequest: \"The request is invalid.\",\n InvalidResponse: \"The source returned an invalid response.\",\n InvalidConfiguration: \"The service is configured incorrectly.\",\n Conflict: \"The operation conflicts with current state.\",\n NotImplemented: \"This operation is not implemented.\",\n RateLimited: \"Too many requests. Try again later.\",\n Unavailable: \"The service is unavailable. Try again later.\",\n Internal: \"The operation could not be completed.\",\n }[kind],\n retryable: kind === \"Unavailable\" || kind === \"RateLimited\",\n actionOutcome: kind === \"Unavailable\" ? \"unknown\" : \"not-committed\",\n issues,\n cause: Redacted.make(cause),\n });\n}\n\nexport interface ErrorProjectionContext {\n /** Visible action parameter paths. Hidden/fixed parameters must not appear in public issues. */\n readonly parameters?: readonly string[];\n readonly objectReferenceParameters?: readonly string[];\n /** An upstream connection failure cannot request downstream sign-in. */\n readonly upstream?: boolean;\n}\nexport type ErrorProjection =\n | \"forward\"\n | \"projected\"\n | ((error: BackendError, context: ErrorProjectionContext) => BackendError);\nexport function projectValidationIssue(\n issue: ValidationIssue,\n context: ErrorProjectionContext\n): ValidationIssue | undefined {\n const parameter = issue.path?.[0];\n if (!Predicate.isString(parameter) || !context.parameters?.includes(parameter)) return undefined;\n if (issue.category === \"input\") {\n const standard: Readonly<Record<string, string>> = {\n required: \"A value is required.\",\n type: \"Enter a valid value.\",\n range: \"Enter a value in the allowed range.\",\n arraySize: \"Choose an allowed number of items.\",\n stringLength: \"Enter a value of the allowed length.\",\n regex: \"Enter a value in the required format.\",\n };\n const message = issue.messageSource === \"standard\" ? issue.message : standard[issue.code ?? \"\"];\n if (message)\n return {\n message,\n path: issue.path,\n code: issue.code,\n category: \"input\",\n messageSource: \"standard\",\n };\n }\n if (issue.code === \"InvalidObjectReference\")\n return { message: \"Choose a valid value.\", path: issue.path, code: \"InvalidObjectReference\" };\n return undefined;\n}\n/** Forwarding preserves the original error. Projection removes raw causes and\n * cannot change execution/retry facts. */\nexport function projectBackendError(\n error: BackendError,\n policy: ErrorProjection = \"projected\",\n context: ErrorProjectionContext = {}\n): BackendError {\n if (policy === \"forward\") return error;\n const shown = typeof policy === \"function\" ? policy(error, context) : error;\n const kind = error.kind === \"Unauthenticated\" && context.upstream ? \"Unavailable\" : shown.kind;\n const issues =\n shown.kind !== \"ValidationFailed\"\n ? undefined\n : policy === \"projected\"\n ? error.issues?.flatMap((issue) => {\n const visible = projectValidationIssue(issue, context);\n return visible ? [visible] : [];\n })\n : shown.issues;\n const message =\n policy !== \"projected\"\n ? shown.message\n : kind === \"ValidationFailed\"\n ? \"Submission failed validation.\"\n : kind === \"InvalidRequest\"\n ? \"The request is invalid.\"\n : kind === \"InvalidResponse\"\n ? \"The source returned an invalid response.\"\n : kind === \"Unauthenticated\"\n ? \"Authentication is required.\"\n : kind === \"Forbidden\"\n ? \"This operation is not permitted.\"\n : kind === \"NotFound\"\n ? \"Resource not found.\"\n : kind === \"RateLimited\"\n ? \"Too many requests. Try again later.\"\n : kind === \"NotImplemented\"\n ? \"This operation is not implemented.\"\n : \"The operation could not be completed.\";\n return new BackendError({\n operation: error.operation,\n kind,\n message,\n issues: issues?.length ? issues : undefined,\n retryable: error.retryable,\n actionOutcome: error.actionOutcome,\n retryAfterMs: error.retryAfterMs,\n });\n}\nexport type UnauthenticatedError = BackendError<\"Unauthenticated\">;\n\n/** Schema diagnostics retain paths without echoing input values or internal schemas. */\nexport function schemaValidationIssues(error: Schema.SchemaError): readonly ValidationIssue[] {\n return SchemaIssue.makeFormatterStandardSchemaV1({\n leafHook: (issue) => (issue._tag === \"MissingKey\" ? \"A value is required.\" : \"Enter a valid value.\"),\n checkHook: () => \"Enter a valid value.\",\n })(error.issue).issues.map((issue) => ({\n message: issue.message,\n path: issue.path?.flatMap((part) =>\n typeof part === \"string\" || typeof part === \"number\" ? [part] : []\n ),\n category: \"input\",\n code: issue.message === \"A value is required.\" ? \"required\" : \"type\",\n source: \"parameter\",\n messageSource: \"standard\",\n }));\n}\n"],"mappings":";;;;;;AAQA,MAAa,wBAAwB,OAAO,OAAO;CAC/C,SAAS,OAAO;CAChB,MAAM,OAAO,SAAS,OAAO,MAAM,OAAO,MAAM,CAAC,OAAO,QAAQ,OAAO,MAAM,CAAC,CAAC,CAAC;CAChF,MAAM,OAAO,SAAS,OAAO,MAAM;CACnC,UAAU,OAAO,SAAS,OAAO,SAAS;EAAC;EAAS;EAAa;CAAQ,CAAC,CAAC;CAC3E,QAAQ,OAAO,SAA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AAS,UAAU;EAC7B,MAAM,UAAU,uBAAuB,OAAO,OAAO;EACrD,OAAO,UAAU,CAAC,OAAO,IAAI,CAAC;CAClC,CAAC,IACD,MAAM;CAClB,MAAM,UACF,WAAW,cACL,MAAM,UACN,SAAS,qBACP,kCACA,SAAS,mBACP,4BACA,SAAS,oBACP,6CACA,SAAS,oBACP,gCACA,SAAS,cACP,qCACA,SAAS,aACP,wBACA,SAAS,gBACP,wCACA,SAAS,mBACP,uCACA;CAC1B,OAAO,IAAI,aAAa;EACpB,WAAW,MAAM;EACjB;EACA;EACA,QAAQ,QAAQ,SAAS,SAAS,KAAA;EAClC,WAAW,MAAM;EACjB,eAAe,MAAM;EACrB,cAAc,MAAM;CACxB,CAAC;AACL;;AAIA,SAAgB,uBAAuB,OAAuD;CAC1F,OAAO,YAAY,8BAA8B;EAC7C,WAAW,UAAW,MAAM,SAAS,eAAe,yBAAyB;EAC7E,iBAAiB;CACrB,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,OAAO,KAAK,WAAW;EACnC,SAAS,MAAM;EACf,MAAM,MAAM,MAAM,SAAS,SACvB,OAAO,SAAS,YAAY,OAAO,SAAS,WAAW,CAAC,IAAI,IAAI,CAAC,CACrE;EACA,UAAU;EACV,MAAM,MAAM,YAAY,yBAAyB,aAAa;EAC9D,QAAQ;EACR,eAAe;CACnB,EAAE;AACN"}
|
|
1
|
+
{"version":3,"file":"errors.js","names":[],"sources":["../src/errors.ts"],"sourcesContent":["import { OntologyStorageError } from \"@party-stack/ontology-storage\";\nimport { BlobStorageError } from \"@party-stack/ontology-storage/blobs\";\nimport { Predicate, Schema, SchemaIssue, Redacted } from \"effect\";\nimport { HttpClientError } from \"effect/http\";\nimport { RpcClientError } from \"effect/rpc\";\nimport type { ValidationIssue } from \"@party-stack/ontology-spec\";\n\nexport type { ValidationIssue };\nexport const ValidationIssueSchema = Schema.Struct({\n message: Schema.String,\n path: Schema.optional(Schema.Array(Schema.Union([Schema.String, Schema.Number]))),\n code: Schema.optional(Schema.String),\n category: Schema.optional(Schema.Literals([\"input\", \"reference\", \"custom\"])),\n source: Schema.optional(Schema.Literals([\"parameter\", \"submission\", \"user-facing\"])),\n messageSource: Schema.optional(Schema.Literals([\"standard\", \"configured\"])),\n});\nexport const ValidationReportSchema = Schema.Union([\n Schema.Struct({ certain: Schema.Literal(false) }),\n Schema.Struct({\n certain: Schema.Literal(true),\n value: Schema.Union([\n Schema.Struct({ kind: Schema.Literal(\"ok\"), value: Schema.Void }),\n Schema.Struct({ kind: Schema.Literal(\"err\"), value: Schema.Array(ValidationIssueSchema) }),\n ]),\n }),\n]);\nexport type ValidationReport = typeof ValidationReportSchema.Type;\n\nexport const BackendErrorKindSchema = Schema.Literals([\n \"Unauthenticated\",\n \"Forbidden\",\n \"NotFound\",\n \"ValidationFailed\",\n \"InvalidRequest\",\n \"InvalidResponse\",\n \"InvalidConfiguration\",\n \"Conflict\",\n \"NotImplemented\",\n \"RateLimited\",\n \"Unavailable\",\n \"Internal\",\n \"HistoryExpired\",\n \"SessionExpired\",\n \"SessionReplaced\",\n \"ViewReplaced\",\n \"ResultExpired\",\n \"SourceMismatch\",\n \"SchemaMismatch\",\n]);\nexport type BackendErrorKind = typeof BackendErrorKindSchema.Type;\nconst Fields = {\n operation: Schema.String,\n kind: BackendErrorKindSchema,\n message: Schema.String,\n retryable: Schema.Boolean,\n actionOutcome: Schema.optional(Schema.Literals([\"not-committed\", \"unknown\"])),\n retryAfterMs: Schema.optional(Schema.Finite),\n issues: Schema.optional(Schema.Array(ValidationIssueSchema)),\n /** Set when an action is still pending behind an earlier blocked action: its queue\n * stopped there and sends nothing after it until that action is retried, reconciled\n * or removed. The waiting action keeps its place in the queue. */\n blockedBy: Schema.optional(\n Schema.Struct({\n id: Schema.String,\n name: Schema.String,\n failure: Schema.optional(BackendErrorKindSchema),\n })\n ),\n cause: Schema.optional(Schema.Defect()),\n};\n/** Shared wire schema; hooks narrow the kind without duplicating error classes. */\nexport class BackendError<\n K extends BackendErrorKind = BackendErrorKind,\n> extends Schema.TaggedError<BackendError>()(\"BackendError\", Fields) {\n declare readonly kind: K;\n constructor(properties: Omit<Schema.Struct.Type<typeof Fields>, \"kind\"> & { readonly kind: K }) {\n super(properties);\n }\n}\n/** HTTP bindings share these statuses; RPC still carries the typed error schema. */\nexport const backendErrorStatus = (error: Pick<BackendError, \"kind\">): number =>\n ({\n Unauthenticated: 401,\n Forbidden: 403,\n NotFound: 404,\n ValidationFailed: 422,\n InvalidRequest: 400,\n InvalidResponse: 502,\n InvalidConfiguration: 500,\n Conflict: 409,\n NotImplemented: 501,\n RateLimited: 429,\n Unavailable: 503,\n Internal: 500,\n HistoryExpired: 409,\n SessionExpired: 409,\n SessionReplaced: 409,\n ViewReplaced: 409,\n ResultExpired: 409,\n SourceMismatch: 409,\n SchemaMismatch: 409,\n })[error.kind];\nexport type OperationErrorKind =\n | \"Unauthenticated\"\n | \"Forbidden\"\n | \"NotFound\"\n | \"ValidationFailed\"\n | \"InvalidRequest\"\n | \"InvalidResponse\"\n | \"InvalidConfiguration\"\n | \"Conflict\"\n | \"NotImplemented\"\n | \"RateLimited\"\n | \"Unavailable\"\n | \"Internal\";\nexport type ApplyActionError = BackendError<OperationErrorKind>;\nexport type ValidateActionError = BackendError<OperationErrorKind>;\nexport type ReplicationErrorKind =\n | \"HistoryExpired\"\n | \"SessionExpired\"\n | \"SessionReplaced\"\n | \"ViewReplaced\"\n | \"ResultExpired\"\n | \"SourceMismatch\"\n | \"SchemaMismatch\";\nexport type ReplicationError = BackendError<ReplicationErrorKind>;\nexport type LoadSubsetError = BackendError<\n Exclude<OperationErrorKind, \"ValidationFailed\"> | \"HistoryExpired\"\n>;\n\nexport const unauthenticated = (message = \"Authentication is required.\", options?: ErrorOptions) =>\n new BackendError({\n operation: \"authentication\",\n kind: \"Unauthenticated\",\n message,\n retryable: false,\n actionOutcome: \"not-committed\",\n cause: options?.cause,\n });\nexport const isUnauthenticatedError = (error: unknown): error is BackendError<\"Unauthenticated\"> =>\n error instanceof BackendError && error.kind === \"Unauthenticated\";\n\n/** Unknown outcomes apply to dispatch/execution failures, never ordinary rejections. */\nexport const isUnknownActionOutcome = (error: BackendError) =>\n error.actionOutcome === \"unknown\" ||\n (error.actionOutcome === undefined &&\n (error.kind === \"Unavailable\" || error.kind === \"Internal\" || error.kind === \"InvalidResponse\"));\n\nconst ProviderFailure = Schema.Struct({\n reason: Schema.optional(Schema.Unknown),\n cause: Schema.optional(Schema.Unknown),\n response: Schema.optional(\n Schema.Struct({\n status: Schema.Number,\n headers: Schema.optional(Schema.Record(Schema.String, Schema.String)),\n })\n ),\n retryAfterMs: Schema.optional(Schema.Finite),\n status: Schema.optional(Schema.Number),\n statusCode: Schema.optional(Schema.Number),\n errorCode: Schema.optional(Schema.String),\n errorName: Schema.optional(Schema.String),\n code: Schema.optional(Schema.String),\n parameters: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),\n});\n/** Normalize SDK failures. No provider message/body is made public by this classifier. */\nexport function classifyBackendFailure(operation: string, cause: unknown): BackendError {\n if (cause instanceof BackendError) return cause;\n // Effect RPC currently puts HTTP EOF in RpcClientDefect alongside decoding\n // failures. Only its two explicit EOF cases mean transport loss; malformed\n // frames must remain terminal InvalidResponse failures. Replace this narrow\n // normalization when upstream exposes a structured interrupted-response reason.\n if (\n cause instanceof RpcClientError.RpcClientError &&\n cause.reason._tag === \"RpcClientDefect\" &&\n (cause.reason.message === \"HTTP response ended before RPC request completed\" ||\n cause.reason.message === \"Received empty HTTP response from RPC server\")\n )\n return new BackendError({\n operation,\n kind: \"Unavailable\",\n message: \"The RPC connection was interrupted.\",\n retryable: true,\n actionOutcome: \"unknown\",\n cause: Redacted.make(cause),\n });\n if (\n (cause instanceof RpcClientError.RpcClientError && cause.reason._tag === \"RpcClientDefect\") ||\n (cause instanceof HttpClientError.HttpClientError && cause.reason._tag === \"DecodeError\")\n )\n return new BackendError({\n operation,\n kind: \"InvalidResponse\",\n message: \"The source returned an invalid response.\",\n retryable: false,\n actionOutcome: \"unknown\",\n cause: Redacted.make(cause),\n });\n if (\n cause instanceof HttpClientError.HttpClientError &&\n (cause.reason._tag === \"EncodeError\" || cause.reason._tag === \"InvalidUrlError\")\n )\n return new BackendError({\n operation,\n kind: cause.reason._tag === \"EncodeError\" ? \"InvalidRequest\" : \"InvalidConfiguration\",\n message: \"The request could not be constructed.\",\n retryable: false,\n actionOutcome: \"not-committed\",\n cause: Redacted.make(cause),\n });\n const blob =\n cause instanceof BlobStorageError\n ? cause\n : cause instanceof OntologyStorageError && cause.reason._tag === \"BlobStorageError\"\n ? cause.reason\n : undefined;\n if (blob) {\n return new BackendError({\n operation,\n kind:\n blob.kind === \"NotFound\"\n ? \"NotFound\"\n : blob.kind === \"InvalidValue\"\n ? \"InvalidRequest\"\n : blob.kind === \"Busy\" || blob.kind === \"Conflict\"\n ? \"Conflict\"\n : \"Unavailable\",\n message:\n blob.kind === \"NotFound\"\n ? \"Attachment is unavailable.\"\n : blob.kind === \"Busy\"\n ? \"Attachment upload is still in progress.\"\n : blob.kind === \"Conflict\"\n ? \"Attachment state conflicts with this operation.\"\n : blob.kind === \"InvalidValue\"\n ? \"Invalid attachment value.\"\n : \"Attachment storage is unavailable.\",\n retryable: blob.kind === \"Busy\" || blob.kind === \"Bytes\",\n cause: Redacted.make(cause),\n });\n }\n if (cause instanceof OntologyStorageError) {\n const reason = cause.reason;\n const kind: BackendErrorKind =\n reason._tag === \"QueryError\"\n ? \"InvalidRequest\"\n : reason._tag === \"ConfigurationError\" || reason._tag === \"IndexError\"\n ? \"InvalidConfiguration\"\n : reason._tag === \"DefinitionMismatch\" || reason._tag === \"SchemaMismatch\"\n ? \"SchemaMismatch\"\n : reason._tag === \"UniqueConstraint\"\n ? \"Conflict\"\n : reason._tag === \"StorageError\" ||\n (reason._tag === \"TransactionError\" && reason.kind === \"Backend\")\n ? \"Unavailable\"\n : \"Internal\";\n return new BackendError({\n operation,\n kind,\n message:\n kind === \"InvalidRequest\"\n ? \"Invalid storage query.\"\n : kind === \"SchemaMismatch\"\n ? \"Storage schema changed; migrate or reset explicitly.\"\n : \"Storage operation failed.\",\n retryable: cause.isRetryable,\n cause: Redacted.make(cause),\n });\n }\n let candidate = cause;\n let value: typeof ProviderFailure.Type | undefined;\n for (let depth = 0; depth < 5; depth++) {\n if (candidate instanceof BackendError) return candidate;\n const decoded = Schema.decodeUnknownOption(ProviderFailure)(candidate);\n if (decoded._tag === \"None\") break;\n value = decoded.value;\n if (value.cause instanceof BackendError) return value.cause;\n if (\n value.status !== undefined ||\n value.statusCode !== undefined ||\n value.errorCode !== undefined ||\n value.code !== undefined ||\n value.errorName !== undefined ||\n value.response\n )\n break;\n candidate = value.reason ?? value.cause;\n }\n const status = value?.status ?? value?.statusCode ?? value?.response?.status;\n const code = value?.errorCode ?? value?.code;\n const name = value?.errorName?.split(\":\").at(-1);\n const kind: OperationErrorKind =\n status === 501\n ? \"NotImplemented\"\n : status === 401 || code === \"UNAUTHORIZED\" || code === \"INVALID_SESSION_ID\"\n ? \"Unauthenticated\"\n : status === 429 || code === \"REQUEST_LIMIT_EXCEEDED\" || name === \"RateLimitReached\"\n ? \"RateLimited\"\n : status === 403 || code === \"PERMISSION_DENIED\" || code === \"INSUFFICIENT_ACCESS_OR_READONLY\"\n ? \"Forbidden\"\n : status === 404 || code === \"NOT_FOUND\"\n ? \"NotFound\"\n : name === \"FunctionEncounteredUserFacingError\" ||\n name === \"QueryEncounteredUserFacingError\"\n ? \"ValidationFailed\"\n : code === \"FIELD_CUSTOM_VALIDATION_EXCEPTION\" || code === \"REQUIRED_FIELD_MISSING\"\n ? \"ValidationFailed\"\n : status === 400 || code === \"INVALID_ARGUMENT\"\n ? \"InvalidRequest\"\n : status === 409\n ? \"Conflict\"\n : \"Unavailable\";\n const authored =\n name === \"FunctionEncounteredUserFacingError\" || name === \"QueryEncounteredUserFacingError\";\n const issues: readonly ValidationIssue[] | undefined =\n authored && Predicate.isString(value?.parameters?.message)\n ? [\n {\n message: value.parameters.message,\n code: \"custom\",\n category: \"custom\",\n source: \"user-facing\",\n messageSource: \"configured\",\n },\n ]\n : undefined;\n const seconds = value?.response?.headers?.[\"retry-after\"];\n const retryAfterMs =\n value?.retryAfterMs ??\n (seconds !== undefined && /^\\d+(?:\\.\\d+)?$/.test(seconds) ? Number(seconds) * 1_000 : undefined);\n return new BackendError({\n operation,\n kind,\n retryAfterMs,\n message: {\n Unauthenticated: \"Authentication is required.\",\n Forbidden: \"This operation is not permitted.\",\n NotFound: \"Resource not found.\",\n ValidationFailed: \"Submission failed validation.\",\n InvalidRequest: \"The request is invalid.\",\n InvalidResponse: \"The source returned an invalid response.\",\n InvalidConfiguration: \"The service is configured incorrectly.\",\n Conflict: \"The operation conflicts with current state.\",\n NotImplemented: \"This operation is not implemented.\",\n RateLimited: \"Too many requests. Try again later.\",\n Unavailable: \"The service is unavailable. Try again later.\",\n Internal: \"The operation could not be completed.\",\n }[kind],\n retryable: kind === \"Unavailable\" || kind === \"RateLimited\",\n actionOutcome: kind === \"Unavailable\" ? \"unknown\" : \"not-committed\",\n issues,\n cause: Redacted.make(cause),\n });\n}\n\nexport interface ErrorProjectionContext {\n /** Visible action parameter paths. Hidden/fixed parameters must not appear in public issues. */\n readonly parameters?: readonly string[];\n readonly objectReferenceParameters?: readonly string[];\n /** An upstream connection failure cannot request downstream sign-in. */\n readonly upstream?: boolean;\n}\nexport type ErrorProjection =\n | \"forward\"\n | \"projected\"\n | ((error: BackendError, context: ErrorProjectionContext) => BackendError);\nexport function projectValidationIssue(\n issue: ValidationIssue,\n context: ErrorProjectionContext\n): ValidationIssue | undefined {\n const parameter = issue.path?.[0];\n if (!Predicate.isString(parameter) || !context.parameters?.includes(parameter)) return undefined;\n if (issue.category === \"input\") {\n const standard: Readonly<Record<string, string>> = {\n required: \"A value is required.\",\n type: \"Enter a valid value.\",\n range: \"Enter a value in the allowed range.\",\n arraySize: \"Choose an allowed number of items.\",\n stringLength: \"Enter a value of the allowed length.\",\n regex: \"Enter a value in the required format.\",\n };\n const message = issue.messageSource === \"standard\" ? issue.message : standard[issue.code ?? \"\"];\n if (message)\n return {\n message,\n path: issue.path,\n code: issue.code,\n category: \"input\",\n messageSource: \"standard\",\n };\n }\n if (issue.code === \"InvalidObjectReference\")\n return { message: \"Choose a valid value.\", path: issue.path, code: \"InvalidObjectReference\" };\n return undefined;\n}\n/** Forwarding preserves the original error. Projection removes raw causes and\n * cannot change execution/retry facts. */\nexport function projectBackendError(\n error: BackendError,\n policy: ErrorProjection = \"projected\",\n context: ErrorProjectionContext = {}\n): BackendError {\n if (policy === \"forward\") return error;\n const shown = typeof policy === \"function\" ? policy(error, context) : error;\n const kind = error.kind === \"Unauthenticated\" && context.upstream ? \"Unavailable\" : shown.kind;\n const issues =\n shown.kind !== \"ValidationFailed\"\n ? undefined\n : policy === \"projected\"\n ? error.issues?.flatMap((issue) => {\n const visible = projectValidationIssue(issue, context);\n return visible ? [visible] : [];\n })\n : shown.issues;\n const message =\n policy !== \"projected\"\n ? shown.message\n : kind === \"ValidationFailed\"\n ? \"Submission failed validation.\"\n : kind === \"InvalidRequest\"\n ? \"The request is invalid.\"\n : kind === \"InvalidResponse\"\n ? \"The source returned an invalid response.\"\n : kind === \"Unauthenticated\"\n ? \"Authentication is required.\"\n : kind === \"Forbidden\"\n ? \"This operation is not permitted.\"\n : kind === \"NotFound\"\n ? \"Resource not found.\"\n : kind === \"RateLimited\"\n ? \"Too many requests. Try again later.\"\n : kind === \"NotImplemented\"\n ? \"This operation is not implemented.\"\n : \"The operation could not be completed.\";\n return new BackendError({\n operation: error.operation,\n kind,\n message,\n issues: issues?.length ? issues : undefined,\n retryable: error.retryable,\n actionOutcome: error.actionOutcome,\n retryAfterMs: error.retryAfterMs,\n });\n}\nexport type UnauthenticatedError = BackendError<\"Unauthenticated\">;\n\n/** Schema diagnostics retain paths without echoing input values or internal schemas. */\nexport function schemaValidationIssues(error: Schema.SchemaError): readonly ValidationIssue[] {\n return SchemaIssue.makeFormatterStandardSchemaV1({\n leafHook: (issue) => (issue._tag === \"MissingKey\" ? \"A value is required.\" : \"Enter a valid value.\"),\n checkHook: () => \"Enter a valid value.\",\n })(error.issue).issues.map((issue) => ({\n message: issue.message,\n path: issue.path?.flatMap((part) =>\n typeof part === \"string\" || typeof part === \"number\" ? [part] : []\n ),\n category: \"input\",\n code: issue.message === \"A value is required.\" ? \"required\" : \"type\",\n source: \"parameter\",\n messageSource: \"standard\",\n }));\n}\n"],"mappings":";;;;;;AAQA,MAAa,wBAAwB,OAAO,OAAO;CAC/C,SAAS,OAAO;CAChB,MAAM,OAAO,SAAS,OAAO,MAAM,OAAO,MAAM,CAAC,OAAO,QAAQ,OAAO,MAAM,CAAC,CAAC,CAAC;CAChF,MAAM,OAAO,SAAS,OAAO,MAAM;CACnC,UAAU,OAAO,SAAS,OAAO,SAAS;EAAC;EAAS;EAAa;CAAQ,CAAC,CAAC;CAC3E,QAAQ,OAAO,SAAS,OAAO,SAAS;EAAC;EAAa;EAAc;CAAa,CAAC,CAAC;CACnF,eAAe,OAAO,SAAS,OAAO,SAAS,CAAC,YAAY,YAAY,CAAC,CAAC;AAC9E,CAAC;AACD,MAAa,yBAAyB,OAAO,MAAM,CAC/C,OAAO,OAAO,EAAE,SAAS,OAAO,QAAQ,KAAK,EAAE,CAAC,GAChD,OAAO,OAAO;CACV,SAAS,OAAO,QAAQ,IAAI;CAC5B,OAAO,OAAO,MAAM,CAChB,OAAO,OAAO;EAAE,MAAM,OAAO,QAAQ,IAAI;EAAG,OAAO,OAAO;CAAK,CAAC,GAChE,OAAO,OAAO;EAAE,MAAM,OAAO,QAAQ,KAAK;EAAG,OAAO,OAAO,MAAM,qBAAqB;CAAE,CAAC,CAC7F,CAAC;AACL,CAAC,CACL,CAAC;AAGD,MAAa,yBAAyB,OAAO,SAAS;CAClD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACJ,CAAC;AAED,MA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AAW,MAAM,SAAS,eAAe,yBAAyB;EAC7E,iBAAiB;CACrB,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,OAAO,KAAK,WAAW;EACnC,SAAS,MAAM;EACf,MAAM,MAAM,MAAM,SAAS,SACvB,OAAO,SAAS,YAAY,OAAO,SAAS,WAAW,CAAC,IAAI,IAAI,CAAC,CACrE;EACA,UAAU;EACV,MAAM,MAAM,YAAY,yBAAyB,aAAa;EAC9D,QAAQ;EACR,eAAe;CACnB,EAAE;AACN"}
|
package/lib/index.d.ts
CHANGED
|
@@ -85,6 +85,9 @@ export interface ActionRequest {
|
|
|
85
85
|
readonly now: string;
|
|
86
86
|
readonly seed: string;
|
|
87
87
|
};
|
|
88
|
+
/** How long one attempt to send this action may take, in milliseconds, overriding the
|
|
89
|
+
* outbox's `timeoutMs`. For actions known to take long, such as large uploads. */
|
|
90
|
+
readonly timeoutMs?: number;
|
|
88
91
|
}
|
|
89
92
|
export interface ActionReceipt {
|
|
90
93
|
/** The submitted ActionRequest.id, also supplied as the application's idempotencyKey. */
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":["_$__encrypted_js0.DecryptedValue","_$__delivery_js0.DeliveryPolicy","_$__delivery_js0.DeliveryPosition","_$__delivery_js0.DeliverySubscription","_$__errors_js0.ValidationReport"],"sources":["../src/index.ts"],"mappings":";;;;;;;;;;;iBAuCiB;WACJ,kBAAkB;;iBAEd;;;;;;;WAOJ,kBAAkB;WAClB,eAAe,IAAI;;WAEnB;;;;WAIA;;WAEA,WAAW;;WAEX;;qBAEA,uBAAqB,OAAA;;;;;;;;;;;;;;;;YAetB,kBAAkB,OAAO,OAAO,YAAY;YAC5C;WAEO;WACA;WACA,KAAK;WACL,OAAO;;WAET;WAAyB;WAA6B,KAAK;;iBAC3D;WACJ;WACA,kBAAkB;WAClB;;iBAEI;WACJ,kBAAkB;WAClB;WACA;;iBAEI;WACJ,YAAY;WACZ,MAAM;WACN,SAAS;;iBAEL;;WAEJ;WACA;WACA,YAAY;WACZ,6BAA6B;;WAE7B;aAAoB;aAAsB
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["_$__encrypted_js0.DecryptedValue","_$__delivery_js0.DeliveryPolicy","_$__delivery_js0.DeliveryPosition","_$__delivery_js0.DeliverySubscription","_$__errors_js0.ValidationReport"],"sources":["../src/index.ts"],"mappings":";;;;;;;;;;;iBAuCiB;WACJ,kBAAkB;;iBAEd;;;;;;;WAOJ,kBAAkB;WAClB,eAAe,IAAI;;WAEnB;;;;WAIA;;WAEA,WAAW;;WAEX;;qBAEA,uBAAqB,OAAA;;;;;;;;;;;;;;;;YAetB,kBAAkB,OAAO,OAAO,YAAY;YAC5C;WAEO;WACA;WACA,KAAK;WACL,OAAO;;WAET;WAAyB;WAA6B,KAAK;;iBAC3D;WACJ;WACA,kBAAkB;WAClB;;iBAEI;WACJ,kBAAkB;WAClB;WACA;;iBAEI;WACJ,YAAY;WACZ,MAAM;WACN,SAAS;;iBAEL;;WAEJ;WACA;WACA,YAAY;WACZ,6BAA6B;;WAE7B;aAAoB;aAAsB;;;;WAG1C;;iBAEI;;WAEJ;;WAEA;;WAEA;WACA;;WAEA;;;;;;WAMA;aACI;aACA,gBAAgB;;;;;WAKpB;WACA;aAA2C;aAA0B;;;qBAGrE,oBAAkB,OAAA,gBAAA,OAAA;;;;;;;;;;qBASlB,qBAAmB,OAAA;;;;;;;;;;;;;;;;qBAgBnB,qBAAmB,OAAA;;;;;;;;;;;;;;qBAKnB,uBAAqB,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;;qBAUrB,yBAAuB,OAAA;;;;;;;;;;;;;;;;;;iBAMnB;;WAEJ,SACL,OAAO,YACP,OAAO,WACP;aAAqB,SAAS;QAC7B,OAAO,OAAO,YAAY;;WAEtB,OACL,OAAO,YACP;aAAqB;aAA0B;QAC9C,OAAO,OAAO,WAAW,cAAc,MAAM;WACzC,WACL,OAAO,YACP;aAAqB;QACpB,OAAO;aAEK;aACA;aACA;aACA;eAAwB;eAAwB;;KAE7D;;iBAWS;;WAEJ,UACL,OAAO,uBACN,OAAO,OADDA,gBACiD;;;;;;;;YAQpD;WACK;WAAsB,KAAK;WAAc,OAAO;;WAChD;WAAuB,KAAK;;WAC5B;WAAyB,KAAK;;;;;;;;YAOnC;WAA+C,kBAAkB;;iBAE5D;WACJ;;WAEA;;;;;;WAMA;;;;;;;WAOA;;WAEA,cAAc,OAAO,aAAa;;;;WAIlC,aAAa,QAAQ,iBAAiB,OAAO,OAAO,iBAAiB;;;;;WAKrE,QACL,UAAU,eACV;aAAqB,SAAS;QAC7B,OAAO,OAAO,yBAAyB;;WAEnC,sBACL,WAAW,iBACX,SADWC,gBAEX,SADiCC,qBAEhC,OAAO,OADyBC,sBAC4B,cAAc,MAAM;WAC5E,uBACL,UAFQD,qBAGP,OAAO,aAAa;;WAEhB,2BACL,cACA,YAAY,4BACX,OAAO,OAAO,yBAAyB;;;;;;;;;WASnC,eACL,QAAQ,iBACP,OAAO,OAAO,OAAO,OAAO,kBAAkB,eAAe,cAAc,MAAM;;;WAG7E,WAAW,QAAQ;aAET;aACA;;WAGV,kBACL,cACA,YAAY,yBACZ;aAAqB;QACpB,OAAO,OAFIE,kBAE2C;WAClD,cAAc,YAAY,kBAAkB,OAAO,OAAO,eAAe;WACzE,gBACL,cACA,YAAY,4BACX,OAAO,gBAAgB;WACnB;aACI,OAAO;eACH;eACA;UACP,OAAO,OAAO,mBAAmB;;;;aAI9B,QAAQ,OAAO,OAAO,OAAO,aAAa,eAAe,cAAc,MAAM;;WAEjF,cAAc;WACd,YAAY;;;;qBAIZ,wBAAwB"}
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { Context, Schema } from \"effect\";\nimport { ObjectSubsetSchema } from \"./subsetSchema.js\";\nimport type { AttachmentTypeDef, QueryDocument } from \"@party-stack/ontology-spec\";\nimport type { ObjectSubset } from \"@party-stack/ontology-spec/query\";\nimport type { attachment, Encrypted } from \"@party-stack/ontology-spec/values\";\nimport type { Key, Row } from \"@party-stack/ontology-storage\";\nimport type { ByteInput } from \"@party-stack/ontology-storage/blobs\";\nimport type { Scope, Effect, Stream } from \"effect\";\n\nexport {\n schemaValidationIssues,\n BackendError,\n BackendErrorKindSchema,\n backendErrorStatus,\n ValidationIssueSchema,\n ValidationReportSchema,\n unauthenticated,\n isUnauthenticatedError,\n classifyBackendFailure,\n projectBackendError,\n projectValidationIssue,\n isUnknownActionOutcome,\n} from \"./errors.js\";\nexport type {\n BackendErrorKind,\n ReplicationErrorKind,\n ReplicationError,\n ErrorProjection,\n ErrorProjectionContext,\n ValidationReport,\n ValidationIssue,\n UnauthenticatedError,\n ApplyActionError,\n ValidateActionError,\n LoadSubsetError,\n} from \"./errors.js\";\nimport { BackendError } from \"./errors.js\";\nexport { makeOntologyBackend } from \"./query.js\";\n\nexport interface ObjectSelection {\n readonly subsets: readonly ObjectSubset[];\n}\nexport interface BackendSnapshot {\n /** Region represented by these rows, including any window already applied.\n * Omitted means the requested subset. A broader unwindowed region lets the\n * engine finish filtering/ordering/windowing and optionally cache extra objects.\n * Rows may include residual candidates outside this region; consumers discard\n * them before installing its objects or recording complete coverage.\n */\n readonly fulfilledSubset?: ObjectSubset;\n readonly rows: readonly Row<Record<string, unknown>>[];\n /** Complete for fulfilledSubset (or the request when omitted), including its window. */\n readonly complete: boolean;\n /** Rows fetched from the provider, before adapter-side filtering/windowing.\n * Diagnostic only; omitted when the adapter cannot report it. Not a DB scan count.\n */\n readonly fetchedRows?: number;\n /** Diagnostic provider filter, not a query-capability or coverage contract. */\n readonly pushdown?: SourceQueryPlan;\n /** Position coordinated with this snapshot, when the backend exposes a durable change stream. */\n readonly cursor?: string;\n}\nexport const SourceQueryPlanSchema = Schema.Struct({\n source: Schema.String,\n /** Paths into the request's portable where tree: AND/OR child indices, NOT child 0, [] for the root. */\n predicates: Schema.Array(\n Schema.Struct({\n path: Schema.Array(Schema.Int),\n execution: Schema.Literals([\"source\", \"candidate\", \"adapter\", \"engine\"]),\n })\n ),\n sorting: Schema.Literals([\"source\", \"adapter\", \"engine\", \"none\"]),\n pagination: Schema.Literals([\"source\", \"adapter\", \"engine\", \"none\"]),\n rechecksFilter: Schema.Boolean,\n /** Optional native syntax for raw inspection. Consumers must not parse it to infer execution. */\n native: Schema.optional(Schema.Struct({ language: Schema.String, text: Schema.String })),\n});\nexport type SourceQueryPlan = Schema.Schema.Type<typeof SourceQueryPlanSchema>;\nexport type ObjectChange =\n | {\n readonly kind: \"put\";\n readonly objectType: string;\n readonly key: Key;\n readonly value: Record<string, unknown>;\n }\n | { readonly kind: \"delete\"; readonly objectType: string; readonly key: Key };\nexport interface BackendCommit {\n readonly cursor: string;\n readonly changes: readonly ObjectChange[];\n readonly operationId?: string;\n}\nexport interface BackendChangePage {\n readonly commits: readonly BackendCommit[];\n readonly cursor: string;\n readonly hasMore: boolean;\n}\nexport interface AttachmentUpload {\n readonly attachment: attachment;\n readonly blob: ByteInput;\n readonly target?: AttachmentTypeDef;\n}\nexport interface ActionRequest {\n /** Stable across retries. The source must separately guarantee keyed idempotency. */\n readonly id: string;\n readonly name: string;\n readonly parameters: Record<string, unknown>;\n readonly attachmentUploads?: readonly AttachmentUpload[];\n /** Portable replay inputs, preserved across rebases, forwarding and authoritative execution. */\n readonly replay?: { readonly now: string; readonly seed: string };\n}\nexport interface ActionReceipt {\n /** The submitted ActionRequest.id, also supplied as the application's idempotencyKey. */\n readonly operationId: string;\n /** Provider commitment is recorded before local read-back/reconciliation. Parent acceptance is separate. */\n readonly outcome: \"committed\";\n /** Encoded authoritative return value, interpreted using the action returnType. Never a journal payload. */\n readonly result?: unknown;\n readonly cursor?: string;\n /** Optional upstream execution ID. Never substitutes for our stable retry identity. */\n readonly providerOperationId?: string;\n /** Read-back targets for a committed non-journal action. Missing keys\n * means the whole type; an empty list means no modeled object changes.\n * Omission conservatively refreshes every modeled type.\n * Targets are complete unless affectedComplete is explicitly false.\n */\n readonly affected?: readonly {\n readonly objectType: string;\n readonly keys?: readonly Key[];\n }[];\n /** False when these are known targets but automation may have changed other\n * modeled records. Confirmation must not use them as an exhaustive edit list.\n */\n readonly affectedComplete?: boolean;\n readonly attachmentIdMappings?: readonly { readonly localId: string; readonly remoteId: string }[];\n}\nconst KeySchema = Schema.Union([Schema.String, Schema.Finite]);\nexport const ObjectChangeSchema = Schema.Union([\n Schema.Struct({\n kind: Schema.Literal(\"put\"),\n objectType: Schema.String,\n key: KeySchema,\n value: Schema.Record(Schema.String, Schema.Unknown),\n }),\n Schema.Struct({ kind: Schema.Literal(\"delete\"), objectType: Schema.String, key: KeySchema }),\n]);\nexport const ActionReceiptSchema = Schema.Struct({\n operationId: Schema.String,\n outcome: Schema.Literal(\"committed\"),\n result: Schema.optional(Schema.Unknown),\n cursor: Schema.optional(Schema.String),\n providerOperationId: Schema.optional(Schema.String),\n affected: Schema.optional(\n Schema.Array(\n Schema.Struct({ objectType: Schema.String, keys: Schema.optional(Schema.Array(KeySchema)) })\n )\n ),\n affectedComplete: Schema.optional(Schema.Boolean),\n attachmentIdMappings: Schema.optional(\n Schema.Array(Schema.Struct({ localId: Schema.String, remoteId: Schema.String }))\n ),\n});\nexport const BackendCommitSchema = Schema.Struct({\n cursor: Schema.String,\n changes: Schema.Array(ObjectChangeSchema),\n operationId: Schema.optional(Schema.String),\n});\nexport const BackendSnapshotSchema = Schema.Struct({\n fulfilledSubset: Schema.optional(ObjectSubsetSchema),\n fetchedRows: Schema.optional(Schema.Number),\n pushdown: Schema.optional(SourceQueryPlanSchema),\n rows: Schema.Array(\n Schema.Struct({ key: KeySchema, value: Schema.Record(Schema.String, Schema.Unknown) })\n ),\n complete: Schema.Boolean,\n cursor: Schema.optional(Schema.String),\n});\nexport const BackendChangePageSchema = Schema.Struct({\n commits: Schema.Array(BackendCommitSchema),\n cursor: Schema.String,\n hasMore: Schema.Boolean,\n});\n\nexport interface BackendAttachments {\n /** Optional authoritative staging before a subsequent action references the handle. */\n readonly stage?: (\n value: attachment,\n bytes: ByteInput,\n options?: { readonly target?: AttachmentTypeDef }\n ) => Effect.Effect<attachment, BackendError>;\n /** Keep the caller Scope open through consumption; closing it cancels an unconsumed download too. */\n readonly read: (\n value: attachment,\n options?: { readonly offset?: number; readonly length?: number }\n ) => Effect.Effect<ByteInput, BackendError, Scope.Scope>;\n readonly metadata: (\n value: attachment,\n options?: { readonly select?: readonly (\"size\" | \"type\" | \"name\" | \"dimensions\")[] }\n ) => Effect.Effect<\n {\n readonly size?: number;\n readonly type?: string;\n readonly name?: string;\n readonly dimensions?: { readonly width: number; readonly height: number };\n },\n BackendError\n >;\n}\nexport {\n EncryptedValueSchema,\n DecryptedValueSchema,\n encryptedPropertyCodec,\n makePropertyDecryption,\n} from \"./encrypted.js\";\nexport type { DecryptedValue } from \"./encrypted.js\";\n\nexport interface BackendEncryptedValues {\n /** Explicit operation. Ordinary record loads return handles and never decrypt them. */\n readonly decrypt: (\n value: Encrypted<unknown>\n ) => Effect.Effect<import(\"./encrypted.js\").DecryptedValue, BackendError>;\n}\n/** One object a watch reports, in the watched subset's object type.\n * - `put`: the object is now in the subset with this complete value.\n * - `exit`: the object left the subset. It may have changed or been deleted; the\n * replica reads it back by primary key to tell which.\n * - `delete`: the object no longer exists anywhere.\n */\nexport type SubsetWatchChange =\n | { readonly kind: \"put\"; readonly key: Key; readonly value: Record<string, unknown> }\n | { readonly kind: \"exit\"; readonly key: Key }\n | { readonly kind: \"delete\"; readonly key: Key };\n/** A reset requests repair after starting/restarting a watch; it does not\n * assert that data changed. Ordinary void hints always invalidate coverage.\n * `changes` describes exactly what changed, so the replica can apply it without\n * reloading the subset. Report only what is certain: a `put` must carry every\n * property; anything less precise must be an invalidation hint instead.\n */\nexport type SubsetWatchEvent = void | \"reset\" | { readonly changes: readonly SubsetWatchChange[] };\n\nexport interface OntologyBackendService {\n readonly name: string;\n /** Stable identity for the source whose cursors and receipts this binding returns. */\n readonly sourceId: string;\n /** Durable keyed idempotency within the configured receipt-retention window:\n * repeated IDs return the recorded result, with\n * conflicting payloads rejected. The guarantee must survive source restart.\n * Merely receiving an ID, or an action being naturally idempotent, is insufficient.\n */\n readonly supportsIdempotency: boolean;\n /**\n * The networks this source is on, such as `\"internet\"`: its replica syncs while a device link\n * reaching one of them is available (the runtime's `links`). Omitted means the internet. A\n * source on the same device (in the same process, a worker or a message port) is on none, so\n * its replicas sync whatever the device's links report.\n */\n readonly networks?: readonly string[];\n /** Indexed bounded local maintenance; the backend owner schedules it. */\n readonly maintenance?: Effect.Effect<void, BackendError>;\n /** Return the request or explicitly describe the region actually fulfilled.\n * Consumers use the shared subset normalizer before applying requested windows.\n */\n readonly loadSubset: (subset: ObjectSubset) => Effect.Effect<BackendSnapshot, BackendError>;\n /** Finite Query IR execution using this binding's trusted context and read path.\n * Provider adapters may evaluate through subset loads; owned storage uses one\n * read transaction. Callers supply query inputs, never authentication context.\n */\n readonly query: (\n document: QueryDocument,\n options?: { readonly inputs?: Record<string, unknown> }\n ) => Effect.Effect<Record<string, unknown>, BackendError>;\n /** Optional selected committed rows. Closing the Scope releases demand; delivery state expires by policy. */\n readonly subscribeSelection?: (\n selection: ObjectSelection,\n policy?: import(\"./delivery.js\").DeliveryPolicy,\n resume?: import(\"./delivery.js\").DeliveryPosition\n ) => Effect.Effect<import(\"./delivery.js\").DeliverySubscription, BackendError, Scope.Scope>;\n readonly acknowledgeDelivery?: (\n position: import(\"./delivery.js\").DeliveryPosition\n ) => Effect.Effect<void, BackendError>;\n /** Read-only defaults and edit prefills; never invokes the action. */\n readonly resolveActionParameters?: (\n name: string,\n parameters: Record<string, unknown>\n ) => Effect.Effect<Record<string, unknown>, BackendError>;\n /** Acquire a demand-scoped watch before reading its snapshot. Completion proves\n * registration and buffering are active, even before the returned stream is pulled.\n * The acquiring Scope owns registration and release. Undefined means polling.\n * Reconnect within the same stream must fail or emit reset/invalidation;\n * reacquisition establishes a new readiness boundary for a fresh read.\n * Must cover every change relevant to the requested subset; broader watches\n * may emit extra hints. It does not maintain broader fulfilledSubset coverage.\n */\n readonly watchSubset?: (\n subset: ObjectSubset\n ) => Effect.Effect<Stream.Stream<SubsetWatchEvent, BackendError>, BackendError, Scope.Scope> | undefined;\n /** Recommended demand refresh defaults. Caller configuration wins; healthy\n * watches/journals keep coverage current independently of snapshot age. */\n readonly refresh?: (subset: ObjectSubset) =>\n | {\n readonly pollIntervalMs?: number | false;\n readonly maxCoverageAgeMs?: number;\n }\n | undefined;\n readonly validateAction?: (\n name: string,\n parameters: Record<string, unknown>,\n options?: { readonly knownParameters?: readonly string[] }\n ) => Effect.Effect<import(\"./errors.js\").ValidationReport, BackendError>;\n readonly applyAction: (invocation: ActionRequest) => Effect.Effect<ActionReceipt, BackendError>;\n readonly queryFunction: (\n name: string,\n parameters: Record<string, unknown>\n ) => Effect.Effect<unknown, BackendError>;\n readonly changes?: {\n readonly pull: (options: {\n readonly cursor?: string;\n readonly limit?: number;\n }) => Effect.Effect<BackendChangePage, BackendError>;\n /** Acquire registered, buffered wake-up hints in the caller's Scope before\n * pulling durable changes. Stream consumption does not initiate registration.\n * Call pull to recover changes after reconnect or restart. */\n readonly watch?: Effect.Effect<Stream.Stream<void, BackendError>, BackendError, Scope.Scope>;\n };\n readonly attachments?: BackendAttachments;\n readonly encrypted?: BackendEncryptedValues;\n}\n\n/** Backend protocol independent of TanStack collections and client lifecycle management. */\nexport class OntologyBackend extends Context.Service<OntologyBackend, OntologyBackendService>()(\n \"@party-stack/ontology-backend/OntologyBackend\"\n) {}\n"],"mappings":";;;;;;AA8DA,MAAa,wBAAwB,OAAO,OAAO;CAC/C,QAAQ,OAAO;;CAEf,YAAY,OAAO,MACf,OAAO,OAAO;EACV,MAAM,OAAO,MAAM,OAAO,GAAG;EAC7B,WAAW,OAAO,SAAS;GAAC;GAAU;GAAa;GAAW;EAAQ,CAAC;CAC3E,CAAC,CACL;CACA,SAAS,O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AAO,OAAO;CAC/C,iBAAiB,OAAO,SAAS,kBAAkB;CACnD,aAAa,OAAO,SAAS,OAAO,MAAM;CAC1C,UAAU,OAAO,SAAS,qBAAqB;CAC/C,MAAM,OAAO,MACT,OAAO,OAAO;EAAE,KAAK;EAAW,OAAO,OAAO,OAAO,OAAO,QAAQ,OAAO,OAAO;CAAE,CAAC,CACzF;CACA,UAAU,OAAO;CACjB,QAAQ,OAAO,SAAS,OAAO,MAAM;AACzC,CAAC;AACD,MAAa,0BAA0B,OAAO,OAAO;CACjD,SAAS,OAAO,MAAM,mBAAmB;CACzC,QAAQ,OAAO;CACf,SAAS,OAAO;AACpB,CAAC;;AAoJD,IAAa,kBAAb,cAAqC,QAAQ,QAAiD,CAAC,CAC3F,+CACJ,CAAC,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { Context, Schema } from \"effect\";\nimport { ObjectSubsetSchema } from \"./subsetSchema.js\";\nimport type { AttachmentTypeDef, QueryDocument } from \"@party-stack/ontology-spec\";\nimport type { ObjectSubset } from \"@party-stack/ontology-spec/query\";\nimport type { attachment, Encrypted } from \"@party-stack/ontology-spec/values\";\nimport type { Key, Row } from \"@party-stack/ontology-storage\";\nimport type { ByteInput } from \"@party-stack/ontology-storage/blobs\";\nimport type { Scope, Effect, Stream } from \"effect\";\n\nexport {\n schemaValidationIssues,\n BackendError,\n BackendErrorKindSchema,\n backendErrorStatus,\n ValidationIssueSchema,\n ValidationReportSchema,\n unauthenticated,\n isUnauthenticatedError,\n classifyBackendFailure,\n projectBackendError,\n projectValidationIssue,\n isUnknownActionOutcome,\n} from \"./errors.js\";\nexport type {\n BackendErrorKind,\n ReplicationErrorKind,\n ReplicationError,\n ErrorProjection,\n ErrorProjectionContext,\n ValidationReport,\n ValidationIssue,\n UnauthenticatedError,\n ApplyActionError,\n ValidateActionError,\n LoadSubsetError,\n} from \"./errors.js\";\nimport { BackendError } from \"./errors.js\";\nexport { makeOntologyBackend } from \"./query.js\";\n\nexport interface ObjectSelection {\n readonly subsets: readonly ObjectSubset[];\n}\nexport interface BackendSnapshot {\n /** Region represented by these rows, including any window already applied.\n * Omitted means the requested subset. A broader unwindowed region lets the\n * engine finish filtering/ordering/windowing and optionally cache extra objects.\n * Rows may include residual candidates outside this region; consumers discard\n * them before installing its objects or recording complete coverage.\n */\n readonly fulfilledSubset?: ObjectSubset;\n readonly rows: readonly Row<Record<string, unknown>>[];\n /** Complete for fulfilledSubset (or the request when omitted), including its window. */\n readonly complete: boolean;\n /** Rows fetched from the provider, before adapter-side filtering/windowing.\n * Diagnostic only; omitted when the adapter cannot report it. Not a DB scan count.\n */\n readonly fetchedRows?: number;\n /** Diagnostic provider filter, not a query-capability or coverage contract. */\n readonly pushdown?: SourceQueryPlan;\n /** Position coordinated with this snapshot, when the backend exposes a durable change stream. */\n readonly cursor?: string;\n}\nexport const SourceQueryPlanSchema = Schema.Struct({\n source: Schema.String,\n /** Paths into the request's portable where tree: AND/OR child indices, NOT child 0, [] for the root. */\n predicates: Schema.Array(\n Schema.Struct({\n path: Schema.Array(Schema.Int),\n execution: Schema.Literals([\"source\", \"candidate\", \"adapter\", \"engine\"]),\n })\n ),\n sorting: Schema.Literals([\"source\", \"adapter\", \"engine\", \"none\"]),\n pagination: Schema.Literals([\"source\", \"adapter\", \"engine\", \"none\"]),\n rechecksFilter: Schema.Boolean,\n /** Optional native syntax for raw inspection. Consumers must not parse it to infer execution. */\n native: Schema.optional(Schema.Struct({ language: Schema.String, text: Schema.String })),\n});\nexport type SourceQueryPlan = Schema.Schema.Type<typeof SourceQueryPlanSchema>;\nexport type ObjectChange =\n | {\n readonly kind: \"put\";\n readonly objectType: string;\n readonly key: Key;\n readonly value: Record<string, unknown>;\n }\n | { readonly kind: \"delete\"; readonly objectType: string; readonly key: Key };\nexport interface BackendCommit {\n readonly cursor: string;\n readonly changes: readonly ObjectChange[];\n readonly operationId?: string;\n}\nexport interface BackendChangePage {\n readonly commits: readonly BackendCommit[];\n readonly cursor: string;\n readonly hasMore: boolean;\n}\nexport interface AttachmentUpload {\n readonly attachment: attachment;\n readonly blob: ByteInput;\n readonly target?: AttachmentTypeDef;\n}\nexport interface ActionRequest {\n /** Stable across retries. The source must separately guarantee keyed idempotency. */\n readonly id: string;\n readonly name: string;\n readonly parameters: Record<string, unknown>;\n readonly attachmentUploads?: readonly AttachmentUpload[];\n /** Portable replay inputs, preserved across rebases, forwarding and authoritative execution. */\n readonly replay?: { readonly now: string; readonly seed: string };\n /** How long one attempt to send this action may take, in milliseconds, overriding the\n * outbox's `timeoutMs`. For actions known to take long, such as large uploads. */\n readonly timeoutMs?: number;\n}\nexport interface ActionReceipt {\n /** The submitted ActionRequest.id, also supplied as the application's idempotencyKey. */\n readonly operationId: string;\n /** Provider commitment is recorded before local read-back/reconciliation. Parent acceptance is separate. */\n readonly outcome: \"committed\";\n /** Encoded authoritative return value, interpreted using the action returnType. Never a journal payload. */\n readonly result?: unknown;\n readonly cursor?: string;\n /** Optional upstream execution ID. Never substitutes for our stable retry identity. */\n readonly providerOperationId?: string;\n /** Read-back targets for a committed non-journal action. Missing keys\n * means the whole type; an empty list means no modeled object changes.\n * Omission conservatively refreshes every modeled type.\n * Targets are complete unless affectedComplete is explicitly false.\n */\n readonly affected?: readonly {\n readonly objectType: string;\n readonly keys?: readonly Key[];\n }[];\n /** False when these are known targets but automation may have changed other\n * modeled records. Confirmation must not use them as an exhaustive edit list.\n */\n readonly affectedComplete?: boolean;\n readonly attachmentIdMappings?: readonly { readonly localId: string; readonly remoteId: string }[];\n}\nconst KeySchema = Schema.Union([Schema.String, Schema.Finite]);\nexport const ObjectChangeSchema = Schema.Union([\n Schema.Struct({\n kind: Schema.Literal(\"put\"),\n objectType: Schema.String,\n key: KeySchema,\n value: Schema.Record(Schema.String, Schema.Unknown),\n }),\n Schema.Struct({ kind: Schema.Literal(\"delete\"), objectType: Schema.String, key: KeySchema }),\n]);\nexport const ActionReceiptSchema = Schema.Struct({\n operationId: Schema.String,\n outcome: Schema.Literal(\"committed\"),\n result: Schema.optional(Schema.Unknown),\n cursor: Schema.optional(Schema.String),\n providerOperationId: Schema.optional(Schema.String),\n affected: Schema.optional(\n Schema.Array(\n Schema.Struct({ objectType: Schema.String, keys: Schema.optional(Schema.Array(KeySchema)) })\n )\n ),\n affectedComplete: Schema.optional(Schema.Boolean),\n attachmentIdMappings: Schema.optional(\n Schema.Array(Schema.Struct({ localId: Schema.String, remoteId: Schema.String }))\n ),\n});\nexport const BackendCommitSchema = Schema.Struct({\n cursor: Schema.String,\n changes: Schema.Array(ObjectChangeSchema),\n operationId: Schema.optional(Schema.String),\n});\nexport const BackendSnapshotSchema = Schema.Struct({\n fulfilledSubset: Schema.optional(ObjectSubsetSchema),\n fetchedRows: Schema.optional(Schema.Number),\n pushdown: Schema.optional(SourceQueryPlanSchema),\n rows: Schema.Array(\n Schema.Struct({ key: KeySchema, value: Schema.Record(Schema.String, Schema.Unknown) })\n ),\n complete: Schema.Boolean,\n cursor: Schema.optional(Schema.String),\n});\nexport const BackendChangePageSchema = Schema.Struct({\n commits: Schema.Array(BackendCommitSchema),\n cursor: Schema.String,\n hasMore: Schema.Boolean,\n});\n\nexport interface BackendAttachments {\n /** Optional authoritative staging before a subsequent action references the handle. */\n readonly stage?: (\n value: attachment,\n bytes: ByteInput,\n options?: { readonly target?: AttachmentTypeDef }\n ) => Effect.Effect<attachment, BackendError>;\n /** Keep the caller Scope open through consumption; closing it cancels an unconsumed download too. */\n readonly read: (\n value: attachment,\n options?: { readonly offset?: number; readonly length?: number }\n ) => Effect.Effect<ByteInput, BackendError, Scope.Scope>;\n readonly metadata: (\n value: attachment,\n options?: { readonly select?: readonly (\"size\" | \"type\" | \"name\" | \"dimensions\")[] }\n ) => Effect.Effect<\n {\n readonly size?: number;\n readonly type?: string;\n readonly name?: string;\n readonly dimensions?: { readonly width: number; readonly height: number };\n },\n BackendError\n >;\n}\nexport {\n EncryptedValueSchema,\n DecryptedValueSchema,\n encryptedPropertyCodec,\n makePropertyDecryption,\n} from \"./encrypted.js\";\nexport type { DecryptedValue } from \"./encrypted.js\";\n\nexport interface BackendEncryptedValues {\n /** Explicit operation. Ordinary record loads return handles and never decrypt them. */\n readonly decrypt: (\n value: Encrypted<unknown>\n ) => Effect.Effect<import(\"./encrypted.js\").DecryptedValue, BackendError>;\n}\n/** One object a watch reports, in the watched subset's object type.\n * - `put`: the object is now in the subset with this complete value.\n * - `exit`: the object left the subset. It may have changed or been deleted; the\n * replica reads it back by primary key to tell which.\n * - `delete`: the object no longer exists anywhere.\n */\nexport type SubsetWatchChange =\n | { readonly kind: \"put\"; readonly key: Key; readonly value: Record<string, unknown> }\n | { readonly kind: \"exit\"; readonly key: Key }\n | { readonly kind: \"delete\"; readonly key: Key };\n/** A reset requests repair after starting/restarting a watch; it does not\n * assert that data changed. Ordinary void hints always invalidate coverage.\n * `changes` describes exactly what changed, so the replica can apply it without\n * reloading the subset. Report only what is certain: a `put` must carry every\n * property; anything less precise must be an invalidation hint instead.\n */\nexport type SubsetWatchEvent = void | \"reset\" | { readonly changes: readonly SubsetWatchChange[] };\n\nexport interface OntologyBackendService {\n readonly name: string;\n /** Stable identity for the source whose cursors and receipts this binding returns. */\n readonly sourceId: string;\n /** Durable keyed idempotency within the configured receipt-retention window:\n * repeated IDs return the recorded result, with\n * conflicting payloads rejected. The guarantee must survive source restart.\n * Merely receiving an ID, or an action being naturally idempotent, is insufficient.\n */\n readonly supportsIdempotency: boolean;\n /**\n * The networks this source is on, such as `\"internet\"`: its replica syncs while a device link\n * reaching one of them is available (the runtime's `links`). Omitted means the internet. A\n * source on the same device (in the same process, a worker or a message port) is on none, so\n * its replicas sync whatever the device's links report.\n */\n readonly networks?: readonly string[];\n /** Indexed bounded local maintenance; the backend owner schedules it. */\n readonly maintenance?: Effect.Effect<void, BackendError>;\n /** Return the request or explicitly describe the region actually fulfilled.\n * Consumers use the shared subset normalizer before applying requested windows.\n */\n readonly loadSubset: (subset: ObjectSubset) => Effect.Effect<BackendSnapshot, BackendError>;\n /** Finite Query IR execution using this binding's trusted context and read path.\n * Provider adapters may evaluate through subset loads; owned storage uses one\n * read transaction. Callers supply query inputs, never authentication context.\n */\n readonly query: (\n document: QueryDocument,\n options?: { readonly inputs?: Record<string, unknown> }\n ) => Effect.Effect<Record<string, unknown>, BackendError>;\n /** Optional selected committed rows. Closing the Scope releases demand; delivery state expires by policy. */\n readonly subscribeSelection?: (\n selection: ObjectSelection,\n policy?: import(\"./delivery.js\").DeliveryPolicy,\n resume?: import(\"./delivery.js\").DeliveryPosition\n ) => Effect.Effect<import(\"./delivery.js\").DeliverySubscription, BackendError, Scope.Scope>;\n readonly acknowledgeDelivery?: (\n position: import(\"./delivery.js\").DeliveryPosition\n ) => Effect.Effect<void, BackendError>;\n /** Read-only defaults and edit prefills; never invokes the action. */\n readonly resolveActionParameters?: (\n name: string,\n parameters: Record<string, unknown>\n ) => Effect.Effect<Record<string, unknown>, BackendError>;\n /** Acquire a demand-scoped watch before reading its snapshot. Completion proves\n * registration and buffering are active, even before the returned stream is pulled.\n * The acquiring Scope owns registration and release. Undefined means polling.\n * Reconnect within the same stream must fail or emit reset/invalidation;\n * reacquisition establishes a new readiness boundary for a fresh read.\n * Must cover every change relevant to the requested subset; broader watches\n * may emit extra hints. It does not maintain broader fulfilledSubset coverage.\n */\n readonly watchSubset?: (\n subset: ObjectSubset\n ) => Effect.Effect<Stream.Stream<SubsetWatchEvent, BackendError>, BackendError, Scope.Scope> | undefined;\n /** Recommended demand refresh defaults. Caller configuration wins; healthy\n * watches/journals keep coverage current independently of snapshot age. */\n readonly refresh?: (subset: ObjectSubset) =>\n | {\n readonly pollIntervalMs?: number | false;\n readonly maxCoverageAgeMs?: number;\n }\n | undefined;\n readonly validateAction?: (\n name: string,\n parameters: Record<string, unknown>,\n options?: { readonly knownParameters?: readonly string[] }\n ) => Effect.Effect<import(\"./errors.js\").ValidationReport, BackendError>;\n readonly applyAction: (invocation: ActionRequest) => Effect.Effect<ActionReceipt, BackendError>;\n readonly queryFunction: (\n name: string,\n parameters: Record<string, unknown>\n ) => Effect.Effect<unknown, BackendError>;\n readonly changes?: {\n readonly pull: (options: {\n readonly cursor?: string;\n readonly limit?: number;\n }) => Effect.Effect<BackendChangePage, BackendError>;\n /** Acquire registered, buffered wake-up hints in the caller's Scope before\n * pulling durable changes. Stream consumption does not initiate registration.\n * Call pull to recover changes after reconnect or restart. */\n readonly watch?: Effect.Effect<Stream.Stream<void, BackendError>, BackendError, Scope.Scope>;\n };\n readonly attachments?: BackendAttachments;\n readonly encrypted?: BackendEncryptedValues;\n}\n\n/** Backend protocol independent of TanStack collections and client lifecycle management. */\nexport class OntologyBackend extends Context.Service<OntologyBackend, OntologyBackendService>()(\n \"@party-stack/ontology-backend/OntologyBackend\"\n) {}\n"],"mappings":";;;;;;AA8DA,MAAa,wBAAwB,OAAO,OAAO;CAC/C,QAAQ,OAAO;;CAEf,YAAY,OAAO,MACf,OAAO,OAAO;EACV,MAAM,OAAO,MAAM,OAAO,GAAG;EAC7B,WAAW,OAAO,SAAS;GAAC;GAAU;GAAa;GAAW;EAAQ,CAAC;CAC3E,CAAC,CACL;CACA,SAAS,OAAO,SAAS;EAAC;EAAU;EAAW;EAAU;CAAM,CAAC;CAChE,YAAY,OAAO,SAAS;EAAC;EAAU;EAAW;EAAU;CAAM,CAAC;CACnE,gBAAgB,OAAO;;CAEvB,QAAQ,OAAO,SAAS,OAAO,OAAO;EAAE,UAAU,OAAO;EAAQ,MAAM,OAAO;CAAO,CAAC,CAAC;AAC3F,CAAC;AA8DD,MAAM,YAAY,OAAO,MAAM,CAAC,OAAO,QAAQ,OAAO,MAAM,CAAC;AAC7D,MAAa,qBAAqB,OAAO,MAAM,CAC3C,OAAO,OAAO;CACV,MAAM,OAAO,QAAQ,KAAK;CAC1B,YAAY,OAAO;CACnB,KAAK;CACL,OAAO,OAAO,OAAO,OAAO,QAAQ,OAAO,OAAO;AACtD,CAAC,GACD,OAAO,OAAO;C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package/lib/protocol.d.ts
CHANGED
|
@@ -16,6 +16,8 @@ export interface PendingAction {
|
|
|
16
16
|
readonly state: "queued" | "sending" | "acknowledged" | "blocked";
|
|
17
17
|
readonly optimistic: boolean;
|
|
18
18
|
readonly attempts: number;
|
|
19
|
+
/** Earlier action stopping this queue. A selected view carries true when it omits that action. */
|
|
20
|
+
readonly blockedBy?: string | true;
|
|
19
21
|
/** Total attempts at the last explicit retry; automatic retry budgets start here. */
|
|
20
22
|
readonly retryFromAttempt?: number;
|
|
21
23
|
readonly nextAttemptAt?: number;
|
|
@@ -99,12 +101,8 @@ export interface ClientSubmission {
|
|
|
99
101
|
export interface OntologySource {
|
|
100
102
|
readonly sourceId: string;
|
|
101
103
|
readonly outbox?: {
|
|
102
|
-
readonly remove: (id: string,
|
|
103
|
-
|
|
104
|
-
}) => Effect.Effect<void, BackendError>;
|
|
105
|
-
readonly retry: (id: string, options?: {
|
|
106
|
-
readonly allowUnknownOutcome?: boolean;
|
|
107
|
-
}) => Effect.Effect<void, BackendError>;
|
|
104
|
+
readonly remove: (id: string) => Effect.Effect<void, BackendError>;
|
|
105
|
+
readonly retry: (id: string) => Effect.Effect<void, BackendError>;
|
|
108
106
|
readonly edit: (id: string, request: ActionRequest) => Effect.Effect<void, BackendError>;
|
|
109
107
|
};
|
|
110
108
|
readonly supportsIdempotency: boolean;
|
|
@@ -138,6 +136,7 @@ export declare const ActionRequestSchema: Schema.Struct<{
|
|
|
138
136
|
readonly now: Schema.String;
|
|
139
137
|
readonly seed: Schema.NonEmptyString;
|
|
140
138
|
}>>;
|
|
139
|
+
readonly timeoutMs: Schema.optional<Schema.Finite>;
|
|
141
140
|
}>;
|
|
142
141
|
export declare const PendingActionSchema: Schema.Struct<{
|
|
143
142
|
readonly invocation: Schema.Struct<{
|
|
@@ -148,6 +147,7 @@ export declare const PendingActionSchema: Schema.Struct<{
|
|
|
148
147
|
readonly now: Schema.String;
|
|
149
148
|
readonly seed: Schema.NonEmptyString;
|
|
150
149
|
}>>;
|
|
150
|
+
readonly timeoutMs: Schema.optional<Schema.Finite>;
|
|
151
151
|
}>;
|
|
152
152
|
readonly requestIdentity: Schema.String;
|
|
153
153
|
readonly createdAt: Schema.Finite;
|
|
@@ -155,6 +155,7 @@ export declare const PendingActionSchema: Schema.Struct<{
|
|
|
155
155
|
readonly state: Schema.Literals<readonly ["queued", "sending", "acknowledged", "blocked"]>;
|
|
156
156
|
readonly optimistic: Schema.Boolean;
|
|
157
157
|
readonly attempts: Schema.Int;
|
|
158
|
+
readonly blockedBy: Schema.optional<Schema.Union<readonly [Schema.NonEmptyString, Schema.Literal<true>]>>;
|
|
158
159
|
readonly retryFromAttempt: Schema.optional<Schema.Int>;
|
|
159
160
|
readonly nextAttemptAt: Schema.optional<Schema.Finite>;
|
|
160
161
|
readonly failureMessage: Schema.optional<Schema.String>;
|
|
@@ -250,6 +251,7 @@ export declare const ReplicaStateSnapshotSchema: Schema.Struct<{
|
|
|
250
251
|
readonly now: Schema.String;
|
|
251
252
|
readonly seed: Schema.NonEmptyString;
|
|
252
253
|
}>>;
|
|
254
|
+
readonly timeoutMs: Schema.optional<Schema.Finite>;
|
|
253
255
|
}>;
|
|
254
256
|
readonly requestIdentity: Schema.String;
|
|
255
257
|
readonly createdAt: Schema.Finite;
|
|
@@ -257,6 +259,7 @@ export declare const ReplicaStateSnapshotSchema: Schema.Struct<{
|
|
|
257
259
|
readonly state: Schema.Literals<readonly ["queued", "sending", "acknowledged", "blocked"]>;
|
|
258
260
|
readonly optimistic: Schema.Boolean;
|
|
259
261
|
readonly attempts: Schema.Int;
|
|
262
|
+
readonly blockedBy: Schema.optional<Schema.Union<readonly [Schema.NonEmptyString, Schema.Literal<true>]>>;
|
|
260
263
|
readonly retryFromAttempt: Schema.optional<Schema.Int>;
|
|
261
264
|
readonly nextAttemptAt: Schema.optional<Schema.Finite>;
|
|
262
265
|
readonly failureMessage: Schema.optional<Schema.String>;
|
|
@@ -306,6 +309,7 @@ export declare const ReplicaStateSnapshotSchema: Schema.Struct<{
|
|
|
306
309
|
readonly now: Schema.String;
|
|
307
310
|
readonly seed: Schema.NonEmptyString;
|
|
308
311
|
}>>;
|
|
312
|
+
readonly timeoutMs: Schema.optional<Schema.Finite>;
|
|
309
313
|
}>;
|
|
310
314
|
readonly requestIdentity: Schema.String;
|
|
311
315
|
readonly createdAt: Schema.Finite;
|
|
@@ -313,6 +317,7 @@ export declare const ReplicaStateSnapshotSchema: Schema.Struct<{
|
|
|
313
317
|
readonly state: Schema.Literals<readonly ["queued", "sending", "acknowledged", "blocked"]>;
|
|
314
318
|
readonly optimistic: Schema.Boolean;
|
|
315
319
|
readonly attempts: Schema.Int;
|
|
320
|
+
readonly blockedBy: Schema.optional<Schema.Union<readonly [Schema.NonEmptyString, Schema.Literal<true>]>>;
|
|
316
321
|
readonly retryFromAttempt: Schema.optional<Schema.Int>;
|
|
317
322
|
readonly nextAttemptAt: Schema.optional<Schema.Finite>;
|
|
318
323
|
readonly failureMessage: Schema.optional<Schema.String>;
|
|
@@ -394,6 +399,7 @@ export declare const ClientStateCodec: Schema.Codec<{
|
|
|
394
399
|
readonly now: string;
|
|
395
400
|
readonly seed: string;
|
|
396
401
|
} | undefined;
|
|
402
|
+
readonly timeoutMs?: number | undefined;
|
|
397
403
|
};
|
|
398
404
|
readonly requestIdentity: string;
|
|
399
405
|
readonly createdAt: number;
|
|
@@ -401,6 +407,7 @@ export declare const ClientStateCodec: Schema.Codec<{
|
|
|
401
407
|
readonly state: "acknowledged" | "blocked" | "queued" | "sending";
|
|
402
408
|
readonly optimistic: boolean;
|
|
403
409
|
readonly attempts: number;
|
|
410
|
+
readonly blockedBy?: string | true | undefined;
|
|
404
411
|
readonly retryFromAttempt?: number | undefined;
|
|
405
412
|
readonly nextAttemptAt?: number | undefined;
|
|
406
413
|
readonly failureMessage?: string | undefined;
|
|
@@ -452,6 +459,7 @@ export declare const ClientStateCodec: Schema.Codec<{
|
|
|
452
459
|
readonly now: string;
|
|
453
460
|
readonly seed: string;
|
|
454
461
|
} | undefined;
|
|
462
|
+
readonly timeoutMs?: number | undefined;
|
|
455
463
|
};
|
|
456
464
|
readonly requestIdentity: string;
|
|
457
465
|
readonly createdAt: number;
|
|
@@ -459,6 +467,7 @@ export declare const ClientStateCodec: Schema.Codec<{
|
|
|
459
467
|
readonly state: "acknowledged" | "blocked" | "queued" | "sending";
|
|
460
468
|
readonly optimistic: boolean;
|
|
461
469
|
readonly attempts: number;
|
|
470
|
+
readonly blockedBy?: string | true | undefined;
|
|
462
471
|
readonly retryFromAttempt?: number | undefined;
|
|
463
472
|
readonly nextAttemptAt?: number | undefined;
|
|
464
473
|
readonly failureMessage?: string | undefined;
|
|
@@ -546,6 +555,7 @@ export declare const ClientSubmissionCodec: Schema.Codec<{
|
|
|
546
555
|
readonly now: string;
|
|
547
556
|
readonly seed: string;
|
|
548
557
|
} | undefined;
|
|
558
|
+
readonly timeoutMs?: number | undefined;
|
|
549
559
|
};
|
|
550
560
|
readonly optimistic: boolean;
|
|
551
561
|
readonly stagedAttachments?: readonly string[] | undefined;
|
package/lib/protocol.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.d.ts","names":["_$__errors_js0.ValidationIssue","_$__delivery_js0.DeliveryPolicy","_$__delivery_js0.DeliveryPosition","_$__delivery_js0.DeliverySubscription"],"sources":["../src/protocol.ts"],"mappings":";;;;;;;;;;iBAciB;WACJ,YAAY;WACZ;WACA;WACA;WACA;WACA;WACA;;WAEA;WACA;WACA;WACA,
|
|
1
|
+
{"version":3,"file":"protocol.d.ts","names":["_$__errors_js0.ValidationIssue","_$__delivery_js0.DeliveryPolicy","_$__delivery_js0.DeliveryPosition","_$__delivery_js0.DeliverySubscription"],"sources":["../src/protocol.ts"],"mappings":";;;;;;;;;;iBAciB;WACJ,YAAY;WACZ;WACA;WACA;WACA;WACA;WACA;;WAEA;;WAEA;WACA;WACA;WACA,yBAbYA;WAcZ;;WAEA;WACA;WACA;WACA,UAAU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pB,sBAAoB,OAAA;;;;;;;;qBAKpB,kBAAgB,OAAA;;;;;;;;;;;qBAIhB,4BAA0B,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAgD1B,qBAAsB,GAAC,QAAU,OAAO,MAAM,OAAK,OAAO,MAAM;qBAoBhE,kBAAgB,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAChB,uBAAqB,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBACrB,iBAAe,OAAA;;;;;;;;;;;qBACf,qBAAmB,OAAA;;;;qBAEnB,qBAAmB,OAAA;;;;;;;;qBAEnB,mBAAiB,OAAA,iDAAA;qBACjB,sBAAoB,OAAA"}
|
package/lib/protocol.js
CHANGED
|
@@ -37,7 +37,8 @@ const ActionRequestSchema = Schema.Struct({
|
|
|
37
37
|
replay: Schema.optional(Schema.Struct({
|
|
38
38
|
now: Schema.String,
|
|
39
39
|
seed: Schema.NonEmptyString
|
|
40
|
-
}))
|
|
40
|
+
})),
|
|
41
|
+
timeoutMs: Schema.optional(Schema.Finite.check(Schema.isGreaterThan(0)))
|
|
41
42
|
});
|
|
42
43
|
const PendingActionSchema = Schema.Struct({
|
|
43
44
|
invocation: ActionRequestSchema,
|
|
@@ -52,6 +53,7 @@ const PendingActionSchema = Schema.Struct({
|
|
|
52
53
|
]),
|
|
53
54
|
optimistic: Schema.Boolean,
|
|
54
55
|
attempts: Counter,
|
|
56
|
+
blockedBy: Schema.optional(Schema.Union([Schema.NonEmptyString, Schema.Literal(true)])),
|
|
55
57
|
retryFromAttempt: Schema.optional(Counter),
|
|
56
58
|
nextAttemptAt: Schema.optional(Schema.Finite),
|
|
57
59
|
failureMessage: Schema.optional(Schema.String),
|
package/lib/protocol.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.js","names":[],"sources":["../src/protocol.ts"],"sourcesContent":["import { QuerySchema } from \"@party-stack/ontology-storage\";\nimport { Table } from \"@party-stack/ontology-storage/tables\";\nimport { Effect, Schema, SchemaGetter, SchemaIssue } from \"effect\";\nimport { ClientLeaseSchema, ClientSessionSchema } from \"./clients.js\";\nimport { ObjectSubsetSchema, ObjectSelectionSchema } from \"./subset.js\";\nimport { ActionReceiptSchema, BackendErrorKindSchema, ValidationIssueSchema } from \"./index.js\";\nimport type { ClientLease, ClientSession, ClientToken } from \"./clients.js\";\nimport type { ActionRequest, ActionReceipt, BackendError } from \"./index.js\";\nimport type { CompiledSubset } from \"./subset.js\";\nimport type { Row } from \"@party-stack/ontology-storage\";\nimport type { Override } from \"@party-stack/ontology-storage/overlay\";\nimport type { Scope, Stream } from \"effect\";\n\n/** Logical action state shared by owned sources, intermediate replicas and clients. */\nexport interface PendingAction {\n readonly invocation: ActionRequest;\n readonly requestIdentity: string;\n readonly createdAt: number;\n readonly sequence: number;\n readonly state: \"queued\" | \"sending\" | \"acknowledged\" | \"blocked\";\n readonly optimistic: boolean;\n readonly attempts: number;\n /** Total attempts at the last explicit retry; automatic retry budgets start here. */\n readonly retryFromAttempt?: number;\n readonly nextAttemptAt?: number;\n readonly failureMessage?: string;\n readonly failureIssues?: readonly import(\"./errors.js\").ValidationIssue[];\n readonly completedAt?: number;\n /** The upstream cannot safely deduplicate another attempt; caller acknowledgment is required. */\n readonly retryRequiresAcknowledgement?: boolean;\n readonly failureOutcome?: \"not-committed\" | \"unknown\";\n readonly failureRetryable?: boolean;\n readonly receipt?: ActionReceipt;\n readonly failure?: BackendError[\"kind\"];\n readonly submission?: { readonly clientId: string; readonly sequence: number };\n /** Whether the local prediction is reflected in visible state. `dropped` means it is\n * not reflected locally: its last replay failed (`predictionFailure` says why), or\n * the queue is stopped at a blocked action (this one or an earlier one).\n * `none` means it was never predicted here (confirmed visibility or a source prediction).\n * Absent on entries stored before this field existed; treat as `optimistic ? \"applied\" : \"none\"`. */\n readonly prediction?: \"applied\" | \"dropped\" | \"none\";\n readonly predictionFailure?: BackendError[\"kind\"];\n readonly predictionMessage?: string;\n}\n\n/** Consistent logical state. Selected views limit membership, while authorization\n * and property/action projection remain the server's responsibility.\n */\nexport interface ReplicaStateSnapshot {\n readonly sourceId: string;\n readonly revision: number;\n readonly definition: string;\n readonly view?: { readonly generation: number };\n readonly objects: readonly {\n readonly objectType: string;\n readonly base: readonly Row<Record<string, unknown>>[];\n readonly overrides: readonly Row<Override<Record<string, unknown>>>[];\n }[];\n readonly pending: readonly PendingAction[];\n readonly completed: readonly PendingAction[];\n}\n\n/** Membership is evaluated against the source's composed visible state. Action\n * inspection is privileged and must be authorized independently of row access.\n */\nexport interface StateSelection {\n readonly subsets: readonly CompiledSubset[];\n readonly actionIds: readonly string[];\n /** Include the pending queue. Outcomes are selected by actionIds, including\n * pending actions already observed by the child, not the parent's full history. */\n readonly inspectActions?: boolean;\n}\nexport interface ClientView {\n readonly generation: number;\n readonly selection: StateSelection;\n}\n\nexport interface ClientState {\n readonly coverage?: readonly {\n readonly subset: CompiledSubset;\n readonly complete: boolean;\n /** Previously confirmed resident coverage; it may need background refresh. */\n readonly cached?: boolean;\n }[];\n readonly state: ReplicaStateSnapshot;\n readonly client: ClientLease;\n}\nexport interface ClientSubmission {\n readonly session: ClientSession;\n readonly sequence: number;\n readonly invocation: ActionRequest;\n readonly optimistic: boolean;\n /** Newly staged child copies required before first acceptance; duplicates need no transfer. */\n readonly stagedAttachments?: readonly string[];\n readonly view?: ClientView;\n}\n\n/** A protocol source need not contain a Replica or an upstream outbox. Ordered\n * submission idempotency is scoped to a valid resumable client lease. A transport\n * must bind authorization and decode data before exposing this interface.\n */\nexport interface OntologySource {\n readonly sourceId: string;\n readonly outbox?: {\n readonly remove: (\n id: string,\n options?: { readonly allowUnknownOutcome?: boolean }\n ) => Effect.Effect<void, BackendError>;\n readonly retry: (\n id: string,\n options?: { readonly allowUnknownOutcome?: boolean }\n ) => Effect.Effect<void, BackendError>;\n readonly edit: (id: string, request: ActionRequest) => Effect.Effect<void, BackendError>;\n };\n readonly supportsIdempotency: boolean;\n readonly openClient: (resume?: ClientToken) => Effect.Effect<ClientLease, BackendError>;\n readonly read: (session: ClientSession, view?: ClientView) => Effect.Effect<ClientState, BackendError>;\n readonly subscribe?: (\n session: ClientSession,\n view: ClientView,\n policy?: import(\"./delivery.js\").DeliveryPolicy,\n resume?: import(\"./delivery.js\").DeliveryPosition\n ) => Effect.Effect<import(\"./delivery.js\").DeliverySubscription, BackendError, Scope.Scope>;\n readonly acknowledgeDelivery?: (\n position: import(\"./delivery.js\").DeliveryPosition\n ) => Effect.Effect<void, BackendError>;\n /** Change the view of this client's open state subscription in place. The source\n * acquires the added subsets before releasing removed ones and delivers the change\n * on the same stream. A source that cannot fails `ViewReplaced`, and the client\n * subscribes again with the new view. */\n readonly updateView?: (session: ClientSession, view: ClientView) => Effect.Effect<void, BackendError>;\n /** Acceptance only; selected delivery carries the resulting state. */\n readonly accept?: (request: ClientSubmission) => Effect.Effect<void, BackendError>;\n /** Snapshot-mode interest lease. The first element confirms acquisition;\n * failures/EOF remain observable, and closing the stream releases interest.\n * Replica supervision owns retries, not the transport.\n */\n readonly demand: (subset: CompiledSubset) => Stream.Stream<void, BackendError>;\n readonly subscribeChanges: Effect.Effect<Stream.Stream<void, BackendError>, BackendError, Scope.Scope>;\n readonly submit: (request: ClientSubmission) => Effect.Effect<ClientState, BackendError>;\n readonly acknowledge: (\n session: ClientSession,\n revision: number,\n through: number,\n viewGeneration?: number\n ) => Effect.Effect<void, BackendError>;\n}\n\n/** Row/action arrays represent keyed records, not their transport ordering. */\nexport const stateIdentity = (snapshot: ReplicaStateSnapshot): string => {\n const compare = (a: string, b: string) => (a < b ? -1 : a > b ? 1 : 0);\n const rows = <A>(values: readonly Row<A>[]) =>\n [...values].sort((a, b) => compare(JSON.stringify(a.key), JSON.stringify(b.key)));\n const actions = (values: readonly PendingAction[]) =>\n [...values].sort((a, b) => compare(a.invocation.id, b.invocation.id));\n return Table.make({ name: \"state-identity\" }).encode({\n ...snapshot,\n objects: [...snapshot.objects]\n .sort((a, b) => compare(a.objectType, b.objectType))\n .map((object) => ({\n ...object,\n base: rows(object.base),\n overrides: rows(object.overrides),\n })),\n pending: actions(snapshot.pending),\n completed: actions(snapshot.completed),\n });\n};\n\nconst Counter = Schema.Int.check(Schema.isBetween({ minimum: 0, maximum: Number.MAX_SAFE_INTEGER }));\nconst PositiveCounter = Counter.check(Schema.isGreaterThan(0));\nconst KeySchema = Schema.Union([Schema.String, Schema.Finite]);\nconst ValueSchema = Schema.Record(Schema.String, Schema.Unknown);\nexport const ActionRequestSchema = Schema.Struct({\n id: Schema.NonEmptyString,\n name: Schema.NonEmptyString,\n parameters: ValueSchema,\n replay: Schema.optional(Schema.Struct({ now: Schema.String, seed: Schema.NonEmptyString })),\n});\nexport const PendingActionSchema = Schema.Struct({\n invocation: ActionRequestSchema,\n requestIdentity: Schema.String,\n createdAt: Schema.Finite,\n sequence: PositiveCounter,\n state: Schema.Literals([\"queued\", \"sending\", \"acknowledged\", \"blocked\"]),\n optimistic: Schema.Boolean,\n attempts: Counter,\n retryFromAttempt: Schema.optional(Counter),\n nextAttemptAt: Schema.optional(Schema.Finite),\n failureMessage: Schema.optional(Schema.String),\n failureIssues: Schema.optional(Schema.Array(ValidationIssueSchema)),\n completedAt: Schema.optional(Schema.Finite),\n retryRequiresAcknowledgement: Schema.optional(Schema.Boolean),\n failureOutcome: Schema.optional(Schema.Literals([\"not-committed\", \"unknown\"])),\n failureRetryable: Schema.optional(Schema.Boolean),\n receipt: Schema.optional(ActionReceiptSchema),\n failure: Schema.optional(BackendErrorKindSchema),\n submission: Schema.optional(\n Schema.Struct({ clientId: Schema.NonEmptyString, sequence: PositiveCounter })\n ),\n prediction: Schema.optional(Schema.Literals([\"applied\", \"dropped\", \"none\"])),\n predictionFailure: Schema.optional(BackendErrorKindSchema),\n predictionMessage: Schema.optional(Schema.String),\n});\nexport const CompiledSubsetSchema = Schema.Struct({\n objectType: Schema.NonEmptyString,\n query: Schema.optional(QuerySchema),\n});\nexport const StateSelectionSchema = Schema.Struct({\n subsets: Schema.Array(CompiledSubsetSchema),\n actionIds: Schema.Array(Schema.NonEmptyString),\n inspectActions: Schema.optional(Schema.Boolean),\n});\nexport const ClientViewSchema = Schema.Struct({\n generation: PositiveCounter,\n selection: StateSelectionSchema,\n});\nexport const ReplicaStateSnapshotSchema = Schema.Struct({\n sourceId: Schema.NonEmptyString,\n revision: PositiveCounter,\n definition: Schema.NonEmptyString,\n view: Schema.optional(Schema.Struct({ generation: PositiveCounter })),\n objects: Schema.Array(\n Schema.Struct({\n objectType: Schema.NonEmptyString,\n base: Schema.Array(Schema.Struct({ key: KeySchema, value: ValueSchema })),\n overrides: Schema.Array(\n Schema.Struct({\n key: KeySchema,\n value: Schema.Union([\n Schema.Struct({ deleted: Schema.Literal(true) }),\n Schema.Struct({ deleted: Schema.Literal(false), value: ValueSchema }),\n ]),\n })\n ),\n })\n ),\n pending: Schema.Array(PendingActionSchema),\n completed: Schema.Array(PendingActionSchema),\n});\nconst ClientStateSchema = Schema.Struct({\n state: ReplicaStateSnapshotSchema,\n client: ClientLeaseSchema,\n coverage: Schema.optional(\n Schema.Array(\n Schema.Struct({\n subset: CompiledSubsetSchema,\n complete: Schema.Boolean,\n cached: Schema.optional(Schema.Boolean),\n })\n )\n ),\n});\nconst ClientSubmissionSchema = Schema.Struct({\n session: ClientSessionSchema,\n sequence: PositiveCounter,\n invocation: ActionRequestSchema,\n optimistic: Schema.Boolean,\n stagedAttachments: Schema.optional(Schema.Array(Schema.NonEmptyString)),\n view: Schema.optional(ClientViewSchema),\n});\n\n// Reuse the storage value codec for bigint/Temporal/nested values rather than\n// letting JSON or structured clone silently change the domain representation.\nconst values = Table.make<unknown>({ name: \"ontology-protocol-value\" });\nexport const protocolValueCodec = <A>(schema: Schema.Codec<A>): Schema.Codec<A, string> =>\n Schema.String.pipe(\n Schema.decodeTo(Schema.Unknown, {\n decode: SchemaGetter.transformEffect((input: string) =>\n Effect.try({\n try: () => values.decode(input),\n catch: () =>\n new SchemaIssue.InvalidValue({ message: \"Invalid ontology protocol encoding.\" }),\n })\n ),\n encode: SchemaGetter.transformEffect((input: unknown) =>\n Effect.try({\n try: () => values.encode(input),\n catch: () =>\n new SchemaIssue.InvalidValue({ message: \"Unsupported ontology protocol value.\" }),\n })\n ),\n }),\n Schema.decodeTo(Schema.toType(schema))\n );\nexport const ClientStateCodec = protocolValueCodec(ClientStateSchema);\nexport const ClientSubmissionCodec = protocolValueCodec(ClientSubmissionSchema);\nexport const ClientViewCodec = protocolValueCodec(ClientViewSchema);\nexport const CompiledSubsetCodec = protocolValueCodec(CompiledSubsetSchema);\n\nexport const StateSelectionCodec = protocolValueCodec(StateSelectionSchema);\n\nexport const ObjectSubsetCodec = protocolValueCodec(ObjectSubsetSchema);\nexport const ObjectSelectionCodec = protocolValueCodec(ObjectSelectionSchema);\n"],"mappings":";;;;;;;;;;AAqJA,MAAa,iBAAiB,aAA2C;CACrE,MAAM,WAAW,GAAW,MAAe,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI;CACpE,MAAM,QAAW,WACb,CAAC,GAAG,MAAM,CAAC,CAAC,MAAM,GAAG,MAAM,QAAQ,KAAK,UAAU,EAAE,GAAG,GAAG,KAAK,UAAU,EAAE,GAAG,CAAC,CAAC;CACpF,MAAM,WAAW,WACb,CAAC,GAAG,MAAM,CAAC,CAAC,MAAM,GAAG,MAAM,QAAQ,EAAE,WAAW,IAAI,EAAE,WAAW,EAAE,CAAC;CACxE,OAAO,MAAM,KAAK,EAAE,MA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|
1
|
+
{"version":3,"file":"protocol.js","names":[],"sources":["../src/protocol.ts"],"sourcesContent":["import { QuerySchema } from \"@party-stack/ontology-storage\";\nimport { Table } from \"@party-stack/ontology-storage/tables\";\nimport { Effect, Schema, SchemaGetter, SchemaIssue } from \"effect\";\nimport { ClientLeaseSchema, ClientSessionSchema } from \"./clients.js\";\nimport { ObjectSubsetSchema, ObjectSelectionSchema } from \"./subset.js\";\nimport { ActionReceiptSchema, BackendErrorKindSchema, ValidationIssueSchema } from \"./index.js\";\nimport type { ClientLease, ClientSession, ClientToken } from \"./clients.js\";\nimport type { ActionRequest, ActionReceipt, BackendError } from \"./index.js\";\nimport type { CompiledSubset } from \"./subset.js\";\nimport type { Row } from \"@party-stack/ontology-storage\";\nimport type { Override } from \"@party-stack/ontology-storage/overlay\";\nimport type { Scope, Stream } from \"effect\";\n\n/** Logical action state shared by owned sources, intermediate replicas and clients. */\nexport interface PendingAction {\n readonly invocation: ActionRequest;\n readonly requestIdentity: string;\n readonly createdAt: number;\n readonly sequence: number;\n readonly state: \"queued\" | \"sending\" | \"acknowledged\" | \"blocked\";\n readonly optimistic: boolean;\n readonly attempts: number;\n /** Earlier action stopping this queue. A selected view carries true when it omits that action. */\n readonly blockedBy?: string | true;\n /** Total attempts at the last explicit retry; automatic retry budgets start here. */\n readonly retryFromAttempt?: number;\n readonly nextAttemptAt?: number;\n readonly failureMessage?: string;\n readonly failureIssues?: readonly import(\"./errors.js\").ValidationIssue[];\n readonly completedAt?: number;\n /** The upstream cannot safely deduplicate another attempt; caller acknowledgment is required. */\n readonly retryRequiresAcknowledgement?: boolean;\n readonly failureOutcome?: \"not-committed\" | \"unknown\";\n readonly failureRetryable?: boolean;\n readonly receipt?: ActionReceipt;\n readonly failure?: BackendError[\"kind\"];\n readonly submission?: { readonly clientId: string; readonly sequence: number };\n /** Whether the local prediction is reflected in visible state. `dropped` means it is\n * not reflected locally: its last replay failed (`predictionFailure` says why), or\n * the queue is stopped at a blocked action (this one or an earlier one).\n * `none` means it was never predicted here (confirmed visibility or a source prediction).\n * Absent on entries stored before this field existed; treat as `optimistic ? \"applied\" : \"none\"`. */\n readonly prediction?: \"applied\" | \"dropped\" | \"none\";\n readonly predictionFailure?: BackendError[\"kind\"];\n readonly predictionMessage?: string;\n}\n\n/** Consistent logical state. Selected views limit membership, while authorization\n * and property/action projection remain the server's responsibility.\n */\nexport interface ReplicaStateSnapshot {\n readonly sourceId: string;\n readonly revision: number;\n readonly definition: string;\n readonly view?: { readonly generation: number };\n readonly objects: readonly {\n readonly objectType: string;\n readonly base: readonly Row<Record<string, unknown>>[];\n readonly overrides: readonly Row<Override<Record<string, unknown>>>[];\n }[];\n readonly pending: readonly PendingAction[];\n readonly completed: readonly PendingAction[];\n}\n\n/** Membership is evaluated against the source's composed visible state. Action\n * inspection is privileged and must be authorized independently of row access.\n */\nexport interface StateSelection {\n readonly subsets: readonly CompiledSubset[];\n readonly actionIds: readonly string[];\n /** Include the pending queue. Outcomes are selected by actionIds, including\n * pending actions already observed by the child, not the parent's full history. */\n readonly inspectActions?: boolean;\n}\nexport interface ClientView {\n readonly generation: number;\n readonly selection: StateSelection;\n}\n\nexport interface ClientState {\n readonly coverage?: readonly {\n readonly subset: CompiledSubset;\n readonly complete: boolean;\n /** Previously confirmed resident coverage; it may need background refresh. */\n readonly cached?: boolean;\n }[];\n readonly state: ReplicaStateSnapshot;\n readonly client: ClientLease;\n}\nexport interface ClientSubmission {\n readonly session: ClientSession;\n readonly sequence: number;\n readonly invocation: ActionRequest;\n readonly optimistic: boolean;\n /** Newly staged child copies required before first acceptance; duplicates need no transfer. */\n readonly stagedAttachments?: readonly string[];\n readonly view?: ClientView;\n}\n\n/** A protocol source need not contain a Replica or an upstream outbox. Ordered\n * submission idempotency is scoped to a valid resumable client lease. A transport\n * must bind authorization and decode data before exposing this interface.\n */\nexport interface OntologySource {\n readonly sourceId: string;\n readonly outbox?: {\n readonly remove: (id: string) => Effect.Effect<void, BackendError>;\n readonly retry: (id: string) => Effect.Effect<void, BackendError>;\n readonly edit: (id: string, request: ActionRequest) => Effect.Effect<void, BackendError>;\n };\n readonly supportsIdempotency: boolean;\n readonly openClient: (resume?: ClientToken) => Effect.Effect<ClientLease, BackendError>;\n readonly read: (session: ClientSession, view?: ClientView) => Effect.Effect<ClientState, BackendError>;\n readonly subscribe?: (\n session: ClientSession,\n view: ClientView,\n policy?: import(\"./delivery.js\").DeliveryPolicy,\n resume?: import(\"./delivery.js\").DeliveryPosition\n ) => Effect.Effect<import(\"./delivery.js\").DeliverySubscription, BackendError, Scope.Scope>;\n readonly acknowledgeDelivery?: (\n position: import(\"./delivery.js\").DeliveryPosition\n ) => Effect.Effect<void, BackendError>;\n /** Change the view of this client's open state subscription in place. The source\n * acquires the added subsets before releasing removed ones and delivers the change\n * on the same stream. A source that cannot fails `ViewReplaced`, and the client\n * subscribes again with the new view. */\n readonly updateView?: (session: ClientSession, view: ClientView) => Effect.Effect<void, BackendError>;\n /** Acceptance only; selected delivery carries the resulting state. */\n readonly accept?: (request: ClientSubmission) => Effect.Effect<void, BackendError>;\n /** Snapshot-mode interest lease. The first element confirms acquisition;\n * failures/EOF remain observable, and closing the stream releases interest.\n * Replica supervision owns retries, not the transport.\n */\n readonly demand: (subset: CompiledSubset) => Stream.Stream<void, BackendError>;\n readonly subscribeChanges: Effect.Effect<Stream.Stream<void, BackendError>, BackendError, Scope.Scope>;\n readonly submit: (request: ClientSubmission) => Effect.Effect<ClientState, BackendError>;\n readonly acknowledge: (\n session: ClientSession,\n revision: number,\n through: number,\n viewGeneration?: number\n ) => Effect.Effect<void, BackendError>;\n}\n\n/** Row/action arrays represent keyed records, not their transport ordering. */\nexport const stateIdentity = (snapshot: ReplicaStateSnapshot): string => {\n const compare = (a: string, b: string) => (a < b ? -1 : a > b ? 1 : 0);\n const rows = <A>(values: readonly Row<A>[]) =>\n [...values].sort((a, b) => compare(JSON.stringify(a.key), JSON.stringify(b.key)));\n const actions = (values: readonly PendingAction[]) =>\n [...values].sort((a, b) => compare(a.invocation.id, b.invocation.id));\n return Table.make({ name: \"state-identity\" }).encode({\n ...snapshot,\n objects: [...snapshot.objects]\n .sort((a, b) => compare(a.objectType, b.objectType))\n .map((object) => ({\n ...object,\n base: rows(object.base),\n overrides: rows(object.overrides),\n })),\n pending: actions(snapshot.pending),\n completed: actions(snapshot.completed),\n });\n};\n\nconst Counter = Schema.Int.check(Schema.isBetween({ minimum: 0, maximum: Number.MAX_SAFE_INTEGER }));\nconst PositiveCounter = Counter.check(Schema.isGreaterThan(0));\nconst KeySchema = Schema.Union([Schema.String, Schema.Finite]);\nconst ValueSchema = Schema.Record(Schema.String, Schema.Unknown);\nexport const ActionRequestSchema = Schema.Struct({\n id: Schema.NonEmptyString,\n name: Schema.NonEmptyString,\n parameters: ValueSchema,\n replay: Schema.optional(Schema.Struct({ now: Schema.String, seed: Schema.NonEmptyString })),\n timeoutMs: Schema.optional(Schema.Finite.check(Schema.isGreaterThan(0))),\n});\nexport const PendingActionSchema = Schema.Struct({\n invocation: ActionRequestSchema,\n requestIdentity: Schema.String,\n createdAt: Schema.Finite,\n sequence: PositiveCounter,\n state: Schema.Literals([\"queued\", \"sending\", \"acknowledged\", \"blocked\"]),\n optimistic: Schema.Boolean,\n attempts: Counter,\n blockedBy: Schema.optional(Schema.Union([Schema.NonEmptyString, Schema.Literal(true)])),\n retryFromAttempt: Schema.optional(Counter),\n nextAttemptAt: Schema.optional(Schema.Finite),\n failureMessage: Schema.optional(Schema.String),\n failureIssues: Schema.optional(Schema.Array(ValidationIssueSchema)),\n completedAt: Schema.optional(Schema.Finite),\n retryRequiresAcknowledgement: Schema.optional(Schema.Boolean),\n failureOutcome: Schema.optional(Schema.Literals([\"not-committed\", \"unknown\"])),\n failureRetryable: Schema.optional(Schema.Boolean),\n receipt: Schema.optional(ActionReceiptSchema),\n failure: Schema.optional(BackendErrorKindSchema),\n submission: Schema.optional(\n Schema.Struct({ clientId: Schema.NonEmptyString, sequence: PositiveCounter })\n ),\n prediction: Schema.optional(Schema.Literals([\"applied\", \"dropped\", \"none\"])),\n predictionFailure: Schema.optional(BackendErrorKindSchema),\n predictionMessage: Schema.optional(Schema.String),\n});\nexport const CompiledSubsetSchema = Schema.Struct({\n objectType: Schema.NonEmptyString,\n query: Schema.optional(QuerySchema),\n});\nexport const StateSelectionSchema = Schema.Struct({\n subsets: Schema.Array(CompiledSubsetSchema),\n actionIds: Schema.Array(Schema.NonEmptyString),\n inspectActions: Schema.optional(Schema.Boolean),\n});\nexport const ClientViewSchema = Schema.Struct({\n generation: PositiveCounter,\n selection: StateSelectionSchema,\n});\nexport const ReplicaStateSnapshotSchema = Schema.Struct({\n sourceId: Schema.NonEmptyString,\n revision: PositiveCounter,\n definition: Schema.NonEmptyString,\n view: Schema.optional(Schema.Struct({ generation: PositiveCounter })),\n objects: Schema.Array(\n Schema.Struct({\n objectType: Schema.NonEmptyString,\n base: Schema.Array(Schema.Struct({ key: KeySchema, value: ValueSchema })),\n overrides: Schema.Array(\n Schema.Struct({\n key: KeySchema,\n value: Schema.Union([\n Schema.Struct({ deleted: Schema.Literal(true) }),\n Schema.Struct({ deleted: Schema.Literal(false), value: ValueSchema }),\n ]),\n })\n ),\n })\n ),\n pending: Schema.Array(PendingActionSchema),\n completed: Schema.Array(PendingActionSchema),\n});\nconst ClientStateSchema = Schema.Struct({\n state: ReplicaStateSnapshotSchema,\n client: ClientLeaseSchema,\n coverage: Schema.optional(\n Schema.Array(\n Schema.Struct({\n subset: CompiledSubsetSchema,\n complete: Schema.Boolean,\n cached: Schema.optional(Schema.Boolean),\n })\n )\n ),\n});\nconst ClientSubmissionSchema = Schema.Struct({\n session: ClientSessionSchema,\n sequence: PositiveCounter,\n invocation: ActionRequestSchema,\n optimistic: Schema.Boolean,\n stagedAttachments: Schema.optional(Schema.Array(Schema.NonEmptyString)),\n view: Schema.optional(ClientViewSchema),\n});\n\n// Reuse the storage value codec for bigint/Temporal/nested values rather than\n// letting JSON or structured clone silently change the domain representation.\nconst values = Table.make<unknown>({ name: \"ontology-protocol-value\" });\nexport const protocolValueCodec = <A>(schema: Schema.Codec<A>): Schema.Codec<A, string> =>\n Schema.String.pipe(\n Schema.decodeTo(Schema.Unknown, {\n decode: SchemaGetter.transformEffect((input: string) =>\n Effect.try({\n try: () => values.decode(input),\n catch: () =>\n new SchemaIssue.InvalidValue({ message: \"Invalid ontology protocol encoding.\" }),\n })\n ),\n encode: SchemaGetter.transformEffect((input: unknown) =>\n Effect.try({\n try: () => values.encode(input),\n catch: () =>\n new SchemaIssue.InvalidValue({ message: \"Unsupported ontology protocol value.\" }),\n })\n ),\n }),\n Schema.decodeTo(Schema.toType(schema))\n );\nexport const ClientStateCodec = protocolValueCodec(ClientStateSchema);\nexport const ClientSubmissionCodec = protocolValueCodec(ClientSubmissionSchema);\nexport const ClientViewCodec = protocolValueCodec(ClientViewSchema);\nexport const CompiledSubsetCodec = protocolValueCodec(CompiledSubsetSchema);\n\nexport const StateSelectionCodec = protocolValueCodec(StateSelectionSchema);\n\nexport const ObjectSubsetCodec = protocolValueCodec(ObjectSubsetSchema);\nexport const ObjectSelectionCodec = protocolValueCodec(ObjectSelectionSchema);\n"],"mappings":";;;;;;;;;;AAiJA,MAAa,iBAAiB,aAA2C;CACrE,MAAM,WAAW,GAAW,MAAe,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI;CACpE,MAAM,QAAW,WACb,CAAC,GAAG,MAAM,CAAC,CAAC,MAAM,GAAG,MAAM,QAAQ,KAAK,UAAU,EAAE,GAAG,GAAG,KAAK,UAAU,EAAE,GAAG,CAAC,CAAC;CACpF,MAAM,WAAW,WACb,CAAC,GAAG,MAAM,CAAC,CAAC,MAAM,GAAG,MAAM,QAAQ,EAAE,WAAW,IAAI,EAAE,WAAW,EAAE,CAAC;CACxE,OAAO,MAAM,KAAK,EAAE,MAAM,iBAAiB,CAAC,CAAC,CAAC,OAAO;EACjD,GAAG;EACH,SAAS,CAAC,GAAG,SAAS,OAAO,CAAC,CACzB,MAAM,GAAG,M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mBAAmB,kBAAkB;AACtE,MAAa,uBAAuB,mBAAmB,qBAAqB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@party-stack/ontology-backend",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"files": [
|
|
5
5
|
"lib"
|
|
6
6
|
],
|
|
@@ -57,8 +57,8 @@
|
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
59
|
"temporal-polyfill": "^0.3.0",
|
|
60
|
-
"@party-stack/ontology-spec": "0.5.
|
|
61
|
-
"@party-stack/ontology-storage": "0.4.
|
|
60
|
+
"@party-stack/ontology-spec": "0.5.2",
|
|
61
|
+
"@party-stack/ontology-storage": "0.4.2"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
64
|
"@effect/vitest": "^4.0.5",
|