@smthrs/sync 0.0.0-stage → 1.0.0-rc.4
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/CHANGELOG.md +208 -0
- package/LICENSE +21 -0
- package/README.md +208 -2
- package/dist/cjs/BranchCommands.d.ts +228 -0
- package/dist/cjs/BranchCommands.d.ts.map +1 -0
- package/dist/cjs/BranchCommands.js +316 -0
- package/dist/cjs/BranchCommands.js.map +7 -0
- package/dist/cjs/BranchIds.d.ts +65 -0
- package/dist/cjs/BranchIds.d.ts.map +1 -0
- package/dist/cjs/BranchIds.js +53 -0
- package/dist/cjs/BranchIds.js.map +7 -0
- package/dist/cjs/BranchPresence.d.ts +195 -0
- package/dist/cjs/BranchPresence.d.ts.map +1 -0
- package/dist/cjs/BranchPresence.js +276 -0
- package/dist/cjs/BranchPresence.js.map +7 -0
- package/dist/cjs/BranchProjection.d.ts +179 -0
- package/dist/cjs/BranchProjection.d.ts.map +1 -0
- package/dist/cjs/BranchProjection.js +197 -0
- package/dist/cjs/BranchProjection.js.map +7 -0
- package/dist/cjs/BranchProtocol.d.ts +415 -0
- package/dist/cjs/BranchProtocol.d.ts.map +1 -0
- package/dist/cjs/BranchProtocol.js +172 -0
- package/dist/cjs/BranchProtocol.js.map +7 -0
- package/dist/cjs/BranchRpcs.d.ts +177 -0
- package/dist/cjs/BranchRpcs.d.ts.map +1 -0
- package/dist/cjs/BranchRpcs.js +85 -0
- package/dist/cjs/BranchRpcs.js.map +7 -0
- package/dist/cjs/BranchServer.d.ts +55 -0
- package/dist/cjs/BranchServer.d.ts.map +1 -0
- package/dist/cjs/BranchServer.js +147 -0
- package/dist/cjs/BranchServer.js.map +7 -0
- package/dist/cjs/BranchShare.d.ts +159 -0
- package/dist/cjs/BranchShare.d.ts.map +1 -0
- package/dist/cjs/BranchShare.js +147 -0
- package/dist/cjs/BranchShare.js.map +7 -0
- package/dist/cjs/RunCatalog.d.ts +207 -0
- package/dist/cjs/RunCatalog.d.ts.map +1 -0
- package/dist/cjs/RunCatalog.js +122 -0
- package/dist/cjs/RunCatalog.js.map +7 -0
- package/dist/cjs/SyncAuth.d.ts +70 -0
- package/dist/cjs/SyncAuth.d.ts.map +1 -0
- package/dist/cjs/SyncAuth.js +109 -0
- package/dist/cjs/SyncAuth.js.map +7 -0
- package/dist/cjs/SyncClient.d.ts +274 -0
- package/dist/cjs/SyncClient.d.ts.map +1 -0
- package/dist/cjs/SyncClient.js +474 -0
- package/dist/cjs/SyncClient.js.map +7 -0
- package/dist/cjs/SyncError.d.ts +107 -0
- package/dist/cjs/SyncError.d.ts.map +1 -0
- package/dist/cjs/SyncError.js +110 -0
- package/dist/cjs/SyncError.js.map +7 -0
- package/dist/cjs/SyncPrincipal.d.ts +100 -0
- package/dist/cjs/SyncPrincipal.d.ts.map +1 -0
- package/dist/cjs/SyncPrincipal.js +48 -0
- package/dist/cjs/SyncPrincipal.js.map +7 -0
- package/dist/cjs/SyncProtocol.d.ts +592 -0
- package/dist/cjs/SyncProtocol.d.ts.map +1 -0
- package/dist/cjs/SyncProtocol.js +165 -0
- package/dist/cjs/SyncProtocol.js.map +7 -0
- package/dist/cjs/SyncRpcs.d.ts +92 -0
- package/dist/cjs/SyncRpcs.d.ts.map +1 -0
- package/dist/cjs/SyncRpcs.js +35 -0
- package/dist/cjs/SyncRpcs.js.map +7 -0
- package/dist/cjs/SyncServer.d.ts +184 -0
- package/dist/cjs/SyncServer.d.ts.map +1 -0
- package/dist/cjs/SyncServer.js +513 -0
- package/dist/cjs/SyncServer.js.map +7 -0
- package/dist/cjs/WorkspaceShare.d.ts +174 -0
- package/dist/cjs/WorkspaceShare.d.ts.map +1 -0
- package/dist/cjs/WorkspaceShare.js +149 -0
- package/dist/cjs/WorkspaceShare.js.map +7 -0
- package/dist/cjs/index.d.ts +91 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +67 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/internal/Admission.d.ts +43 -0
- package/dist/cjs/internal/Admission.d.ts.map +1 -0
- package/dist/cjs/internal/Admission.js +90 -0
- package/dist/cjs/internal/Admission.js.map +7 -0
- package/dist/cjs/internal/CauseText.d.ts +55 -0
- package/dist/cjs/internal/CauseText.d.ts.map +1 -0
- package/dist/cjs/internal/CauseText.js +38 -0
- package/dist/cjs/internal/CauseText.js.map +7 -0
- package/dist/cjs/internal/JournalErrorCode.d.ts +23 -0
- package/dist/cjs/internal/JournalErrorCode.d.ts.map +1 -0
- package/dist/cjs/internal/JournalErrorCode.js +34 -0
- package/dist/cjs/internal/JournalErrorCode.js.map +7 -0
- package/dist/cjs/internal/PolicyOptions.d.ts +57 -0
- package/dist/cjs/internal/PolicyOptions.d.ts.map +1 -0
- package/dist/cjs/internal/PolicyOptions.js +62 -0
- package/dist/cjs/internal/PolicyOptions.js.map +7 -0
- package/dist/cjs/internal/ProtocolVersion.d.ts +17 -0
- package/dist/cjs/internal/ProtocolVersion.d.ts.map +1 -0
- package/dist/cjs/internal/ProtocolVersion.js +44 -0
- package/dist/cjs/internal/ProtocolVersion.js.map +7 -0
- package/dist/cjs/internal/ShareSigner.d.ts +173 -0
- package/dist/cjs/internal/ShareSigner.d.ts.map +1 -0
- package/dist/cjs/internal/ShareSigner.js +150 -0
- package/dist/cjs/internal/ShareSigner.js.map +7 -0
- package/dist/cjs/internal/SnapshotBoundary.d.ts +17 -0
- package/dist/cjs/internal/SnapshotBoundary.d.ts.map +1 -0
- package/dist/cjs/internal/SnapshotBoundary.js +97 -0
- package/dist/cjs/internal/SnapshotBoundary.js.map +7 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/test/TestSocket.d.ts +55 -0
- package/dist/cjs/test/TestSocket.d.ts.map +1 -0
- package/dist/cjs/test/TestSocket.js +145 -0
- package/dist/cjs/test/TestSocket.js.map +7 -0
- package/dist/cjs/test/TestSync.d.ts +54 -0
- package/dist/cjs/test/TestSync.d.ts.map +1 -0
- package/dist/cjs/test/TestSync.js +96 -0
- package/dist/cjs/test/TestSync.js.map +7 -0
- package/dist/esm/BranchCommands.d.ts +228 -0
- package/dist/esm/BranchCommands.d.ts.map +1 -0
- package/dist/esm/BranchCommands.js +496 -0
- package/dist/esm/BranchCommands.js.map +1 -0
- package/dist/esm/BranchIds.d.ts +65 -0
- package/dist/esm/BranchIds.d.ts.map +1 -0
- package/dist/esm/BranchIds.js +61 -0
- package/dist/esm/BranchIds.js.map +1 -0
- package/dist/esm/BranchPresence.d.ts +195 -0
- package/dist/esm/BranchPresence.d.ts.map +1 -0
- package/dist/esm/BranchPresence.js +361 -0
- package/dist/esm/BranchPresence.js.map +1 -0
- package/dist/esm/BranchProjection.d.ts +179 -0
- package/dist/esm/BranchProjection.d.ts.map +1 -0
- package/dist/esm/BranchProjection.js +269 -0
- package/dist/esm/BranchProjection.js.map +1 -0
- package/dist/esm/BranchProtocol.d.ts +415 -0
- package/dist/esm/BranchProtocol.d.ts.map +1 -0
- package/dist/esm/BranchProtocol.js +323 -0
- package/dist/esm/BranchProtocol.js.map +1 -0
- package/dist/esm/BranchRpcs.d.ts +177 -0
- package/dist/esm/BranchRpcs.d.ts.map +1 -0
- package/dist/esm/BranchRpcs.js +103 -0
- package/dist/esm/BranchRpcs.js.map +1 -0
- package/dist/esm/BranchServer.d.ts +55 -0
- package/dist/esm/BranchServer.d.ts.map +1 -0
- package/dist/esm/BranchServer.js +168 -0
- package/dist/esm/BranchServer.js.map +1 -0
- package/dist/esm/BranchShare.d.ts +159 -0
- package/dist/esm/BranchShare.d.ts.map +1 -0
- package/dist/esm/BranchShare.js +213 -0
- package/dist/esm/BranchShare.js.map +1 -0
- package/dist/esm/RunCatalog.d.ts +207 -0
- package/dist/esm/RunCatalog.d.ts.map +1 -0
- package/dist/esm/RunCatalog.js +196 -0
- package/dist/esm/RunCatalog.js.map +1 -0
- package/dist/esm/SyncAuth.d.ts +70 -0
- package/dist/esm/SyncAuth.d.ts.map +1 -0
- package/dist/esm/SyncAuth.js +119 -0
- package/dist/esm/SyncAuth.js.map +1 -0
- package/dist/esm/SyncClient.d.ts +274 -0
- package/dist/esm/SyncClient.d.ts.map +1 -0
- package/dist/esm/SyncClient.js +586 -0
- package/dist/esm/SyncClient.js.map +1 -0
- package/dist/esm/SyncError.d.ts +107 -0
- package/dist/esm/SyncError.d.ts.map +1 -0
- package/dist/esm/SyncError.js +133 -0
- package/dist/esm/SyncError.js.map +1 -0
- package/dist/esm/SyncPrincipal.d.ts +100 -0
- package/dist/esm/SyncPrincipal.d.ts.map +1 -0
- package/dist/esm/SyncPrincipal.js +58 -0
- package/dist/esm/SyncPrincipal.js.map +1 -0
- package/dist/esm/SyncProtocol.d.ts +592 -0
- package/dist/esm/SyncProtocol.d.ts.map +1 -0
- package/dist/esm/SyncProtocol.js +434 -0
- package/dist/esm/SyncProtocol.js.map +1 -0
- package/dist/esm/SyncRpcs.d.ts +92 -0
- package/dist/esm/SyncRpcs.d.ts.map +1 -0
- package/dist/esm/SyncRpcs.js +35 -0
- package/dist/esm/SyncRpcs.js.map +1 -0
- package/dist/esm/SyncServer.d.ts +184 -0
- package/dist/esm/SyncServer.d.ts.map +1 -0
- package/dist/esm/SyncServer.js +897 -0
- package/dist/esm/SyncServer.js.map +1 -0
- package/dist/esm/WorkspaceShare.d.ts +174 -0
- package/dist/esm/WorkspaceShare.d.ts.map +1 -0
- package/dist/esm/WorkspaceShare.js +208 -0
- package/dist/esm/WorkspaceShare.js.map +1 -0
- package/dist/esm/index.d.ts +91 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +91 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/internal/Admission.d.ts +43 -0
- package/dist/esm/internal/Admission.d.ts.map +1 -0
- package/dist/esm/internal/Admission.js +80 -0
- package/dist/esm/internal/Admission.js.map +1 -0
- package/dist/esm/internal/CauseText.d.ts +55 -0
- package/dist/esm/internal/CauseText.d.ts.map +1 -0
- package/dist/esm/internal/CauseText.js +67 -0
- package/dist/esm/internal/CauseText.js.map +1 -0
- package/dist/esm/internal/JournalErrorCode.d.ts +23 -0
- package/dist/esm/internal/JournalErrorCode.d.ts.map +1 -0
- package/dist/esm/internal/JournalErrorCode.js +44 -0
- package/dist/esm/internal/JournalErrorCode.js.map +1 -0
- package/dist/esm/internal/PolicyOptions.d.ts +57 -0
- package/dist/esm/internal/PolicyOptions.d.ts.map +1 -0
- package/dist/esm/internal/PolicyOptions.js +70 -0
- package/dist/esm/internal/PolicyOptions.js.map +1 -0
- package/dist/esm/internal/ProtocolVersion.d.ts +17 -0
- package/dist/esm/internal/ProtocolVersion.d.ts.map +1 -0
- package/dist/esm/internal/ProtocolVersion.js +24 -0
- package/dist/esm/internal/ProtocolVersion.js.map +1 -0
- package/dist/esm/internal/ShareSigner.d.ts +173 -0
- package/dist/esm/internal/ShareSigner.d.ts.map +1 -0
- package/dist/esm/internal/ShareSigner.js +219 -0
- package/dist/esm/internal/ShareSigner.js.map +1 -0
- package/dist/esm/internal/SnapshotBoundary.d.ts +17 -0
- package/dist/esm/internal/SnapshotBoundary.d.ts.map +1 -0
- package/dist/esm/internal/SnapshotBoundary.js +68 -0
- package/dist/esm/internal/SnapshotBoundary.js.map +1 -0
- package/dist/esm/test/TestSocket.d.ts +55 -0
- package/dist/esm/test/TestSocket.d.ts.map +1 -0
- package/dist/esm/test/TestSocket.js +128 -0
- package/dist/esm/test/TestSocket.js.map +1 -0
- package/dist/esm/test/TestSync.d.ts +54 -0
- package/dist/esm/test/TestSync.d.ts.map +1 -0
- package/dist/esm/test/TestSync.js +76 -0
- package/dist/esm/test/TestSync.js.map +1 -0
- package/docs/README.md +156 -0
- package/docs/api.md +328 -0
- package/docs/concepts/authorization.md +117 -0
- package/docs/concepts/branches.md +195 -0
- package/docs/concepts/compaction.md +144 -0
- package/docs/concepts/replay-then-follow.md +129 -0
- package/docs/concepts/scopes-and-cursors.md +135 -0
- package/docs/guides/authorize-a-connection.md +174 -0
- package/docs/guides/follow-a-run.md +174 -0
- package/docs/guides/handle-a-compacted-run.md +158 -0
- package/docs/guides/list-workspace-runs.md +120 -0
- package/docs/guides/run-a-long-soak.md +80 -0
- package/docs/guides/serve-the-read-path.md +146 -0
- package/docs/guides/test-a-follower.md +273 -0
- package/docs/installation.md +92 -0
- package/docs/protocol.md +183 -0
- package/docs/quickstart.md +159 -0
- package/docs/troubleshooting.md +234 -0
- package/package.json +304 -3
- package/src/BranchCommands.ts +684 -0
- package/src/BranchIds.ts +76 -0
- package/src/BranchPresence.ts +512 -0
- package/src/BranchProjection.ts +308 -0
- package/src/BranchProtocol.ts +411 -0
- package/src/BranchRpcs.ts +163 -0
- package/src/BranchServer.ts +202 -0
- package/src/BranchShare.ts +297 -0
- package/src/RunCatalog.ts +308 -0
- package/src/SyncAuth.ts +146 -0
- package/src/SyncClient.ts +902 -0
- package/src/SyncError.ts +147 -0
- package/src/SyncPrincipal.ts +115 -0
- package/src/SyncProtocol.ts +594 -0
- package/src/SyncRpcs.ts +40 -0
- package/src/SyncServer.ts +1184 -0
- package/src/WorkspaceShare.ts +292 -0
- package/src/index.ts +107 -0
- package/src/internal/Admission.ts +119 -0
- package/src/internal/CauseText.ts +74 -0
- package/src/internal/JournalErrorCode.ts +46 -0
- package/src/internal/PolicyOptions.ts +97 -0
- package/src/internal/ProtocolVersion.ts +28 -0
- package/src/internal/ShareSigner.ts +300 -0
- package/src/internal/SnapshotBoundary.ts +91 -0
- package/src/test/TestSocket.ts +192 -0
- package/src/test/TestSync.ts +113 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SyncClient.js","sourceRoot":"","sources":["../../src/SyncClient.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,GAAG,M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AAC,CAAA;QACJ,CAAC,CAAC,CAAA;QAEJ,OAAO,QAAQ,EAAE,CAAA;IACnB,CAAC,CAAC,CAAC,CAAA;IAEL,OAAO,UAAU,CAAC,EAAE,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,CAAA;AACzD,CAAC,CAAC,CAAA;AAEJ;;;;;GAKG;AACH,MAAM,CAAC,MAAM,KAAK,GAAuD,KAAK,CAAC,MAAM,CACnF,UAAU,EACV,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CACvE,CAAA;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,OAAgB,EAA0D,EAAE,CACpG,KAAK,CAAC,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,QAAQ,CAAC,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,CAAA","sourcesContent":["/**\n * Browser-safe client for replaying and following journal entries.\n *\n * @since 0.1.0\n */\n\nimport type * as JournalEvent from \"@smthrs/journal/JournalEvent\"\nimport * as Cause from \"effect/Cause\"\nimport * as Context from \"effect/Context\"\nimport * as Effect from \"effect/Effect\"\nimport * as Layer from \"effect/Layer\"\nimport * as Ref from \"effect/Ref\"\nimport * as Schedule from \"effect/Schedule\"\nimport * as Schema from \"effect/Schema\"\nimport * as Stream from \"effect/Stream\"\nimport * as RpcClient from \"effect/unstable/rpc/RpcClient\"\nimport * as RpcClientError from \"effect/unstable/rpc/RpcClientError\"\nimport type * as RpcGroup from \"effect/unstable/rpc/RpcGroup\"\nimport type { ShareCapability } from \"./BranchProtocol.ts\"\nimport * as Admission from \"./internal/Admission.ts\"\nimport { boundedText, causeCode, causeText } from \"./internal/CauseText.ts\"\nimport { boundedInt, positiveInt } from \"./internal/PolicyOptions.ts\"\nimport * as SnapshotBoundary from \"./internal/SnapshotBoundary.ts\"\nimport { SyncError, SyncGapError } from \"./SyncError.ts\"\nimport {\n covers,\n defaultMaxFrameBytes,\n duplicateCursorRunId,\n encodedByteLength,\n type EntriesFrame,\n Frame,\n maxReadLimit,\n maxSubscribeCredit,\n type Progress,\n protocolVersion,\n ReadResponse,\n RequestEnvelope,\n type Resync,\n RunCursor,\n type Scope,\n type Snapshot,\n type SnapshotRequest,\n type WorkspaceCursor\n} from \"./SyncProtocol.ts\"\nimport { SyncRpcs } from \"./SyncRpcs.ts\"\n\n/**\n * Frames one subscription round may carry before the follow replenishes it.\n *\n * A subscription's `credit` is a hard frame limit the server enforces with\n * `Stream.take`, so the number the client sends is the size of its window, not\n * a hint. At `credit: 1` the window closed after every single entry and the\n * follow resubscribed: following a run that emits a hundred entries cost a\n * hundred subscribe round trips, each of them a fresh cursor snapshot and a\n * fresh server-side fan-out. Replenishing 256 frames at a time makes the\n * round-trip cost proportional to the window rather than to the traffic, and\n * keeps it bounded — an unbounded window would hand the server one\n * never-closing subscription per follower.\n *\n * @category constants\n * @since 0.1.0\n */\nexport const defaultCredit = 256\n\n/**\n * Entries one catch-up page asks for.\n *\n * Bootstrap is the replay half of replay-then-follow, so the page size is the\n * memory one catch-up costs and the granularity at which its cursor advances.\n * It matches {@link defaultCredit} and stays under\n * `SyncProtocol.maxReadLimit`, which is the ceiling the server enforces.\n *\n * @category constants\n * @since 1.0.0-rc.0\n */\nexport const defaultBootstrapLimit = 256\n\n/**\n * The policy one sync client runs every operation under.\n *\n * Both fields are validated by {@link makeWith} and {@link layerWith}, so a\n * value that is not a positive safe integer fails the constructor rather than\n * disabling the bound it configures.\n *\n * @category models\n * @since 1.0.0-rc.0\n */\nexport interface Options {\n /**\n * Largest summed encoded-entry size one frame or bootstrap page may carry,\n * in bytes. Defaults to {@link defaultMaxFrameBytes}.\n */\n readonly maxFrameBytes?: number | undefined\n /**\n * Entries one catch-up page asks for. Defaults to\n * {@link defaultBootstrapLimit}, and may not exceed\n * `SyncProtocol.maxReadLimit`.\n */\n readonly bootstrapLimit?: number | undefined\n}\n\n/** The resolved, already-validated client policy. */\ninterface Resolved {\n readonly maxFrameBytes: number\n readonly bootstrapLimit: number\n}\n\nconst defaults: Resolved = {\n maxFrameBytes: defaultMaxFrameBytes,\n bootstrapLimit: defaultBootstrapLimit\n}\n\n/**\n * Input accepted by a sync subscription.\n *\n * `capability` authorizes branch reads: following a shared branch's run\n * requires a capability that verifies for that branch on the server.\n *\n * `EApply` and `EResync` are the consumer's own failure types for `apply` and\n * `onResync`. The subscription fails with them unchanged, so an application\n * failure is never dressed as a transport or protocol {@link SyncError}.\n *\n * @category models\n * @since 0.1.0\n */\nexport interface SubscribeOptions<EApply = never, EResync = never> {\n readonly scope: Scope\n /**\n * Where this subscription starts, per run. The effective position is the\n * LATER of this and the client's matching progress map (applied when an\n * apply callback is present, delivered otherwise), so a caller\n * ahead of the shared view keeps its place and a caller behind it is\n * fast-forwarded. Rebuild from an earlier position with a fresh client.\n */\n readonly cursors: WorkspaceCursor\n readonly capability?: ShareCapability\n /**\n * Frames one subscription round may carry before the follow replenishes the\n * window. Defaults to {@link defaultCredit}, and must be a positive integer\n * no greater than `SyncProtocol.maxSubscribeCredit`.\n */\n readonly credit?: number | undefined\n /**\n * Applies one entry, and DEFINES what this subscription's cursor means.\n *\n * Without it the cursor advances as each entry is handed to the consumer,\n * so a consumer whose own application then fails has a cursor naming an\n * entry it never materialized. With it the cursor advances only after this\n * effect succeeds, and records it in `Progress.applied`. A failure here\n * fails the subscription with the entry unacknowledged, so the\n * next applying subscription delivers it again; the effect must\n * therefore be idempotent, because a redelivery is exactly what a retry is.\n */\n readonly apply?: ((entry: JournalEvent.Entry) => Effect.Effect<void, EApply>) | undefined\n /**\n * Restores state when the server refuses a cursor below a compaction floor.\n * Return the exact run and sequence actually restored, after applying it.\n *\n * The entries under the floor are deleted. Fetch an explicitly public\n * projection through `snapshot` or an authorized local source; a\n * projection has a real hole to fill. The returned sequence must cover the\n * requested floor; a newer snapshot resumes at its own sequence, not the\n * older floor. Missing handlers, failures, interruption, and invalid receipts\n * leave the cursor unmoved. There is no implicit skip of deleted history.\n *\n * Durable consumers must commit their restored state and durable cursor in\n * their own transaction and seed a fresh client from that cursor on restart.\n * This client's cursor is in memory, not an atomic cross-store transaction.\n * Recovery must be idempotent, including when a newer compaction requires\n * another restoration before the suffix can be read.\n */\n readonly onResync?: ((resync: Resync) => Effect.Effect<RunCursor, EResync>) | undefined\n}\n\n/**\n * Replicated journal subscription operations.\n *\n * @category models\n * @since 0.1.0\n */\nexport interface Service {\n /** Fetches a public snapshot without applying state or advancing a cursor. */\n readonly snapshot: (request: SnapshotRequest) => Effect.Effect<Snapshot, SyncError>\n /** Replays then follows `options.scope`, also failing with the callbacks' own errors. */\n readonly subscribe: <EApply = never, EResync = never>(\n options: SubscribeOptions<EApply, EResync>\n ) => Stream.Stream<JournalEvent.Entry, SyncError | SyncGapError | EApply | EResync>\n /**\n * Delivery and application positions. `delivered` is a transport bookmark\n * only; `applied` is what the `apply` and `onResync` callbacks acknowledged.\n */\n readonly progress: Effect.Effect<Progress>\n}\n\n/**\n * The browser-safe journal replication client.\n *\n * @category services\n * @since 1.0.0-rc.0\n */\nexport class SyncClient extends Context.Service<SyncClient, Service>()(\"@smthrs/sync/SyncClient\") {}\n\n/**\n * The client tag's former name, kept for one release.\n *\n * @deprecated Use {@link SyncClient}.\n * @category services\n * @since 0.1.0\n */\nexport const Sync = SyncClient\n\n/**\n * The client tag's former name, kept for one release.\n *\n * @deprecated Use {@link SyncClient}.\n * @category services\n * @since 0.1.0\n */\nexport type Sync = SyncClient\n\n/**\n * Constructs a closed sync stub, optionally overriding individual operations.\n *\n * @category constructors\n * @since 0.1.0\n */\nexport const makeNoop = (overrides: Partial<Service> = {}): Service =>\n SyncClient.of({\n snapshot: () => Effect.fail(new SyncError({ code: \"closed\", message: \"Sync client is closed\" })),\n subscribe: () => Stream.fail(new SyncError({ code: \"closed\", message: \"Sync client is closed\" })),\n progress: Effect.succeed({ delivered: [], applied: [] }),\n ...overrides\n })\n\n/**\n * Provides a closed sync stub.\n *\n * @category layers\n * @since 0.1.0\n */\nexport const layerNoop = (overrides: Partial<Service> = {}): Layer.Layer<SyncClient> =>\n Layer.succeed(SyncClient, makeNoop(overrides))\n\ntype Client = RpcClient.RpcClient<RpcGroup.Rpcs<typeof SyncRpcs>, RpcClientError.RpcClientError>\n\nconst transportError = (cause: unknown): SyncError =>\n cause instanceof SyncError\n ? cause\n : cause instanceof RpcClientError.RpcClientError && cause.reason._tag === \"RpcClientDefect\"\n ? new SyncError({ code: \"protocol_violation\", message: \"Sync RPC protocol failed\", cause: causeCode(cause.reason) })\n : new SyncError({\n code: \"transport_failed\",\n // Bounded like `cause`. `message` is `Schema.String` and it is the\n // declared error schema of every RPC, so a host's own sentence must not\n // be able to be the largest thing this error carries.\n message: cause instanceof Error ? boundedText(cause.message) : \"Sync RPC transport failed\",\n cause: causeText(cause)\n })\n\n/** Effect RPC decodes malformed peer values with orDie. Restore the sync\n * boundary's typed refusal without swallowing unrelated defects or interruption.\n */\nconst rpcCause = (cause: Cause.Cause<unknown>): Cause.Cause<SyncError> =>\n Cause.fromReasons(\n Cause.map(cause, transportError).reasons.map((reason) =>\n Cause.isDieReason(reason) && Schema.isSchemaError(reason.defect)\n ? Cause.makeFailReason(\n new SyncError({ code: \"decode_failed\", message: \"Invalid sync RPC response\", cause: \"SchemaError\" })\n )\n .annotate(Context.makeUnsafe(reason.annotations))\n : reason\n )\n )\n\ntype Cursors = Map<JournalEvent.RunId, RunCursor>\n\nconst cursorMap = (cursors: WorkspaceCursor): Cursors => new Map(cursors.map((cursor) => [cursor.runId, { ...cursor }]))\n\nconst canonicalCursors = (cursors: ReadonlyMap<JournalEvent.RunId, RunCursor>): WorkspaceCursor =>\n Array.from(cursors.values(), (cursor) => ({ ...cursor })).sort((left, right) =>\n // A Map has one value per key, so this comparator never receives equal\n // run IDs. `cursorMap` and the acknowledged cursor state both establish\n // that invariant before reaching this boundary.\n left.runId > right.runId ? 1 : -1\n )\n\n/**\n * Advances the shared acknowledged view monotonically. A lagging subscription\n * commits what it just consumed, but it must never move the shared cursor\n * backward past another subscription's progress.\n */\nconst advance = (\n cursors: ReadonlyMap<JournalEvent.RunId, RunCursor>,\n runId: JournalEvent.RunId,\n throughSeq: JournalEvent.Seq,\n generation: number\n): ReadonlyMap<JournalEvent.RunId, RunCursor> => {\n const current = cursors.get(runId)\n if (current !== undefined && current.afterSeq >= throughSeq) return cursors\n const next = new Map(cursors)\n next.set(runId, { runId, afterSeq: throughSeq, generation })\n return next\n}\n\n/**\n * Live-follow reconnect policy: exponential backoff capped at five seconds,\n * the same shape as `RpcClient`'s own transport retry policy, and only for\n * transport failures — gaps, authorization refusals, server closes, and the\n * consumer's own callback failures propagate to the consumer.\n */\nconst reconnectPolicy = Schedule.min([\n Schedule.exponential(500, 1.5),\n Schedule.spaced(5000)\n]).pipe(\n Schedule.while(({ input }: { readonly input: Cause.Cause<unknown> }) => isTransportCause(input))\n)\n\nconst isTransportCause = (cause: Cause.Cause<unknown>): boolean => {\n const reason = cause.reasons[0]!\n return cause.reasons.length === 1 && Cause.isFailReason(reason) &&\n SyncError.is(reason.error) && reason.error.code === \"transport_failed\"\n}\n\nconst lineageChanged = (runId: JournalEvent.RunId): SyncError =>\n new SyncError({\n code: \"lineage_changed\",\n message: `Run ${runId} was rewound; rebuild from its archive boundary with a fresh sync client`\n })\n\nconst entriesByteLength = (entries: ReadonlyArray<JournalEvent.Entry>): number =>\n entries.reduce((bytes, entry) => bytes + encodedByteLength(entry), 0)\n\nconst oversized = (bytes: number, maxFrameBytes: number): SyncError =>\n new SyncError({\n code: \"frame_too_large\",\n message: `Encoded entries of ${bytes} bytes exceed the ${maxFrameBytes}-byte frame ceiling`\n })\n\n/**\n * The first internal inconsistency of a server frame, or `undefined` for a\n * consistent one.\n *\n * A schema-valid frame can still contradict itself: carry another run's\n * entry, repeat or reorder sequences, or carry an entry outside its own\n * declared covered interval. Applying one would corrupt the client's cursor\n * bookkeeping, so an inconsistent frame is refused as a protocol violation\n * before any entry is admitted or any cursor moves.\n */\nconst frameViolation = (frame: EntriesFrame): SyncError | undefined => {\n let previous = -1\n for (const entry of frame.entries) {\n if (entry.runId !== frame.runId) {\n return new SyncError({\n code: \"protocol_violation\",\n cause: \"foreign_run\",\n message: `Frame for run ${frame.runId} carried an entry for run ${entry.runId}`\n })\n }\n if (entry.seq <= previous) {\n return new SyncError({\n code: \"protocol_violation\",\n cause: \"non_monotonic_sequence\",\n message: `Frame entries must ascend strictly: sequence ${entry.seq} arrived after ${previous}`\n })\n }\n if (entry.seq < frame.fromSeq || frame.toSeq < entry.seq) {\n return new SyncError({\n code: \"protocol_violation\",\n cause: \"invalid_frame_interval\",\n message: `Entry ${entry.seq} lies outside the frame's covered interval ${frame.fromSeq}..${frame.toSeq}`\n })\n }\n previous = entry.seq\n }\n return undefined\n}\n\n/**\n * The first semantic inconsistency of a catch-up page, or `undefined` for a\n * consistent one.\n *\n * Every entry must belong to the requested scope, ascend strictly within its\n * run, and lie above the requested cursor. Every entry-bearing run must have\n * exactly one response cursor with an explicit generation matching the request.\n *\n * Strictly-above-the-cursor is also what makes an incomplete page CONVERGE: a\n * page that carries entries but moves no cursor would be re-read forever.\n */\nconst pageViolation = (\n scope: Scope,\n requested: ReadonlyMap<JournalEvent.RunId, RunCursor>,\n response: ReadResponse\n): SyncError | undefined => {\n const violation = (message: string): SyncError =>\n new SyncError({ code: \"protocol_violation\", message, cause: \"invalid_read_page\" })\n const generations = new Set<JournalEvent.RunId>()\n for (const cursor of response.cursors) {\n generations.add(cursor.runId)\n if (cursor.generation === undefined) return violation(\"Read response lacks a generation\")\n const previous = requested.get(cursor.runId)\n if (previous !== undefined && (previous.generation ?? 0) !== cursor.generation) {\n return lineageChanged(cursor.runId)\n }\n }\n const highest = new Map<JournalEvent.RunId, JournalEvent.Seq>()\n for (const entry of response.entries) {\n if (!covers(scope, entry.runId)) {\n return violation(`Read page carried an entry for run ${entry.runId}, which the request's scope excludes`)\n }\n const floor = requested.get(entry.runId)?.afterSeq\n if (floor !== undefined && entry.seq <= floor) {\n return violation(\n `Read page carried sequence ${entry.seq} for run ${entry.runId}, at or below the requested cursor ${floor}`\n )\n }\n const previous = highest.get(entry.runId)\n if (previous !== undefined && entry.seq <= previous) {\n return violation(\n `Read page entries for run ${entry.runId} must ascend strictly: sequence ${entry.seq} arrived after ${previous}`\n )\n }\n highest.set(entry.runId, entry.seq)\n }\n for (const runId of highest.keys()) {\n if (!generations.has(runId)) return violation(`Read page lacks a generation cursor for run ${runId}`)\n }\n const duplicate = duplicateCursorRunId(response.cursors)\n return duplicate === undefined ? undefined : violation(`Read page echoed run ${duplicate} more than once`)\n}\n\n/**\n * Projects a Sync RPC client into the local replication service.\n *\n * Delivered and applied cursors are separate per-service `Ref` maps: concurrent\n * subscriptions for one materialization share them, and each commit advances\n * its matching map monotonically. A\n * cursor advances in the same stream pull that admits each entry to the\n * consumer, or — when the caller supplies `SubscribeOptions.apply` — only\n * after that callback has applied the entry. Interrupted partial pages\n * therefore retain the last admitted entry rather than incorrectly\n * acknowledging the server's whole page.\n *\n * A frame or bootstrap page whose encoded entries exceed `maxFrameBytes` is\n * refused with `frame_too_large`. Out-of-scope entries, repeated or reordered\n * sequences, and missing response generations fail with `protocol_violation`\n * before delivery. Each entry-bearing run in a Read page must have exactly one\n * explicit generation cursor, and every entry must be above the requested\n * cursor. Live frames instead drop already-covered entries and deliver only\n * the suffix above the cursor. An incomplete bootstrap page with no entries\n * or a completed subscription window with no frames fails with\n * `protocol_violation` instead of reopening immediately.\n *\n * A live follow that loses its transport reconnects under\n * {@link reconnectPolicy}, resuming from the acknowledged cursors; the failure\n * cause is logged before the retry folds it. The follow spends a credit window\n * of {@link defaultCredit} frames per subscription round and replenishes it by\n * resubscribing from the cursors it has acknowledged. Already-covered entries\n * are not delivered again; the round-trip cost scales with credit windows.\n *\n * A `compacted` refusal fails closed unless `SubscribeOptions.onResync`\n * restores the missing prefix and returns its exact cursor. Snapshot fetching\n * never applies state or advances cursors. Only a validated receipt for the requested run at or\n * above its compaction floor advances the cursor before reading the suffix.\n *\n * A subscription's effective cursor per run is the LATER of the caller's and\n * the matching progress map: a caller that restored its own progress is never\n * regressed, and a caller asking for history this client already acknowledged\n * is fast-forwarded. Rebuild a projection from an earlier position with a\n * fresh client, whose acknowledged map is empty.\n *\n * This constructor carries the default policy, which is valid by\n * construction and so cannot fail. {@link makeWith} takes an explicit\n * {@link Options} and validates it.\n *\n * @category constructors\n * @since 0.1.0\n */\nexport const make = ({ client }: { readonly client: Client }): Effect.Effect<Service> => service(client, defaults)\n\n/**\n * Constructs the sync client under an explicit policy.\n *\n * Every option is validated here, once, so a client either exists under a\n * policy it can serve or never exists at all. Validating on each `subscribe`\n * and each `snapshot` instead accepted a `maxFrameBytes` of `NaN` at\n * construction and then refused every operation under it, which reported a\n * composition's mistake as a run-time failure of the follow. This mirrors\n * `SyncServer.makeLiveWith` and `BranchCommands.makeLiveWith`.\n *\n * `SubscribeOptions.credit` is a REQUEST count rather than a client policy, so\n * it is still checked where the request is built.\n *\n * @category constructors\n * @since 1.0.0-rc.0\n */\nexport const makeWith = ({\n bootstrapLimit,\n client,\n maxFrameBytes\n}: Options & { readonly client: Client }): Effect.Effect<Service, SyncError> =>\n Effect.flatMap(\n Effect.all({\n maxFrameBytes: positiveInt(\"SyncClient.Options.maxFrameBytes\", maxFrameBytes, defaults.maxFrameBytes),\n bootstrapLimit: boundedInt(\n \"SyncClient.Options.bootstrapLimit\",\n bootstrapLimit,\n defaults.bootstrapLimit,\n maxReadLimit\n )\n }),\n (policy) => service(client, policy)\n )\n\nconst service = (client: Client, { bootstrapLimit, maxFrameBytes }: Resolved): Effect.Effect<Service> =>\n Effect.sync(() => {\n const delivered = Ref.makeUnsafe<ReadonlyMap<JournalEvent.RunId, RunCursor>>(new Map())\n const applied = Ref.makeUnsafe<ReadonlyMap<JournalEvent.RunId, RunCursor>>(new Map())\n\n const progress: Effect.Effect<Progress> = Effect.gen(function*() {\n return {\n delivered: canonicalCursors(yield* Ref.get(delivered)),\n applied: canonicalCursors(yield* Ref.get(applied))\n }\n })\n\n const snapshot = (input: SnapshotRequest): Effect.Effect<Snapshot, SyncError> =>\n Effect.gen(function*() {\n const request = yield* SnapshotBoundary.request(input)\n const supplied = yield* client[\"Sync.Snapshot\"]({ ...request }).pipe(\n Effect.catchCause((cause) => Effect.failCause(rpcCause(cause)))\n )\n return yield* SnapshotBoundary.response(request, supplied, maxFrameBytes)\n })\n\n const subscribe = <EApply = never, EResync = never>(\n input: SubscribeOptions<EApply, EResync>\n ): Stream.Stream<JournalEvent.Entry, SyncError | SyncGapError | EApply | EResync> =>\n Stream.unwrap(Effect.gen(function*() {\n /** Every way this subscription fails: the wire's refusals and the consumer's own callback errors. */\n type Failure = SyncError | SyncGapError | EApply | EResync\n\n const options = {\n ...input,\n ...yield* Admission.decode(RequestEnvelope, input, \"invalid_request\")\n }\n // The client's own policy was checked once, by the constructor. What\n // is left is the count this REQUEST carries: the declared type says\n // `number`, and `NaN` disabled each comparison it appears in rather\n // than tightening it.\n const credit = yield* boundedInt(\n \"SyncClient.SubscribeOptions.credit\",\n options.credit,\n defaultCredit,\n maxSubscribeCredit\n )\n const cursor = cursorMap(options.cursors)\n // A previous delivery-only subscriber cannot skip work for an applying subscriber.\n // Rebuilding an independent projection requires a fresh client.\n for (const [runId, position] of yield* Ref.get(options.apply === undefined ? delivered : applied)) {\n const supplied = cursor.get(runId)\n if (supplied !== undefined && (supplied.generation ?? 0) !== position.generation) {\n return yield* Effect.fail(lineageChanged(runId))\n }\n if (supplied === undefined || supplied.afterSeq < position.afterSeq) cursor.set(runId, position)\n }\n\n const snapshot = (): WorkspaceCursor => canonicalCursors(cursor)\n\n const commit = (\n runId: JournalEvent.RunId,\n throughSeq: JournalEvent.Seq,\n generation: number,\n wasApplied: boolean\n ) =>\n Effect.gen(function*() {\n // Delivery and application have distinct cursors, but both are bound\n // to the same journal generation and advance without an interrupt gap.\n for (const view of wasApplied ? [delivered, applied] : [delivered]) {\n const previous = (yield* Ref.get(view)).get(runId)\n if (previous !== undefined && previous.generation !== generation) {\n return yield* Effect.fail(lineageChanged(runId))\n }\n }\n yield* Ref.update(delivered, (shared) => advance(shared, runId, throughSeq, generation))\n if (wasApplied) yield* Ref.update(applied, (shared) => advance(shared, runId, throughSeq, generation))\n cursor.set(runId, { runId, afterSeq: throughSeq, generation })\n }).pipe(Effect.uninterruptible)\n\n const applyEntry = options.apply\n\n /**\n * Hands one entry to the consumer and moves its cursor.\n *\n * With an `apply` callback the cursor moves only after the callback\n * succeeds, so a cursor names what the consumer materialized. Without\n * one it moves as the entry is admitted, which is the weaker promise\n * this client has always made and the one `RunCursor`'s JSDoc now\n * states.\n *\n * The position committed is SNAPSHOTTED before the callback runs.\n * `Entry` is a `Schema.Class`, and instances are not frozen, so\n * reading `entry.seq` again afterwards let the consumer's own callback\n * choose the cursor it was being handed an entry for.\n */\n const deliver = (\n runId: JournalEvent.RunId,\n entry: JournalEvent.Entry,\n generation: number\n ): Stream.Stream<JournalEvent.Entry, Failure> => {\n const through = entry.seq\n return Stream.concat(\n Stream.drain(Stream.fromEffect(\n applyEntry === undefined\n ? commit(runId, through, generation, false)\n : Effect.uninterruptibleMask((restore) =>\n Effect.andThen(restore(applyEntry(entry)), commit(runId, through, generation, true))\n )\n )),\n Stream.succeed(entry)\n )\n }\n\n const batch = (frame: EntriesFrame): Stream.Stream<JournalEvent.Entry, Failure> => {\n if (frame.generation === undefined) {\n return Stream.fail(\n new SyncError({ code: \"protocol_violation\", message: \"Entries frame lacks a generation\" })\n )\n }\n if (!covers(options.scope, frame.runId)) {\n return Stream.fail(\n new SyncError({\n code: \"protocol_violation\",\n message: \"Live frame is outside the subscription scope\",\n cause: \"foreign_run\"\n })\n )\n }\n const frameBytes = entriesByteLength(frame.entries)\n if (frameBytes > maxFrameBytes) return Stream.fail(oversized(frameBytes, maxFrameBytes))\n const violation = frameViolation(frame)\n if (violation !== undefined) return Stream.fail(violation)\n const position = cursor.get(frame.runId)\n const generation = frame.generation\n if (position !== undefined && (position.generation ?? 0) !== generation) {\n return Stream.fail(lineageChanged(frame.runId))\n }\n const afterSeq: number = position?.afterSeq ?? -1\n // `fromSeq` is the start of the server-declared covered interval. It is\n // intentionally compared to the cursor, not to the first entry's seq:\n // dropped journal admissions legitimately leave holes inside that range.\n if (frame.fromSeq > afterSeq + 1) {\n return Stream.fail(\n new SyncGapError({\n runId: frame.runId,\n expectedFrom: (afterSeq + 1) as JournalEvent.Seq,\n receivedFrom: frame.fromSeq\n })\n )\n }\n if (frame.toSeq <= afterSeq) return Stream.empty\n\n const entries = frame.entries.filter((entry) => entry.seq > afterSeq)\n return Stream.flatMap(Stream.fromIterable(entries), (entry) => deliver(frame.runId, entry, generation))\n }\n\n const livePage = (onFrame: () => void): Stream.Stream<JournalEvent.Entry, Failure> =>\n Stream.unwrap(\n Effect.sync(() =>\n client[\"Sync.Subscribe\"]({\n protocolVersion,\n scope: options.scope,\n cursors: snapshot(),\n credit,\n ...(options.capability === undefined ? {} : { capability: options.capability })\n })\n )\n ).pipe(\n Stream.catchCause((cause) => Stream.failCause(rpcCause(cause))),\n Stream.mapEffect((frame) => Admission.decode(Frame, frame)),\n Stream.mapEffect((frame): Effect.Effect<Frame, SyncError> =>\n frame._tag === \"Entries\"\n ? Effect.map(Admission.records(frame.entries), (entries) => ({ ...frame, entries }))\n : Effect.succeed(frame)\n ),\n Stream.flatMap((frame) => {\n onFrame()\n switch (frame._tag) {\n case \"Entries\":\n return batch(frame)\n case \"Closed\":\n return Stream.fail(new SyncError({ code: \"closed\", message: \"Sync subscription closed\" }))\n default:\n return Stream.empty\n }\n })\n )\n\n const live = (): Stream.Stream<JournalEvent.Entry, Failure> =>\n Stream.unwrap(Effect.sync(() => {\n let receivedFrame = false\n return Stream.concat(\n livePage(() => {\n receivedFrame = true\n }),\n Stream.unwrap(Effect.sync(() =>\n receivedFrame ? live() : Stream.fail(\n new SyncError({\n code: \"protocol_violation\",\n message: \"Subscription window closed without frames\"\n })\n )\n ))\n )\n }))\n\n // The retry re-runs the whole follow from the acknowledged cursors,\n // and its schedule resets once entries flow again, so a long-lived\n // subscription pays the backoff only across consecutive failures.\n const follow = (): Stream.Stream<JournalEvent.Entry, Failure> =>\n live().pipe(\n Stream.tapCause((cause) =>\n isTransportCause(cause)\n ? Effect.logWarning(\"sync live follow transport failed; reconnecting with backoff\", cause)\n : Effect.void\n ),\n // Schedule the complete cause so retry refusal cannot discard an\n // accompanying defect, interruption, or tracing annotation.\n Stream.catchCause((cause) => Stream.fail(cause)),\n Stream.retry(reconnectPolicy),\n Stream.catch((cause) => Stream.failCause(cause))\n )\n\n const bootstrap = (): Stream.Stream<JournalEvent.Entry, Failure> =>\n Stream.unwrap(\n // SUSPENDED, exactly as `livePage` is. Building the payload where\n // the recursive call is written snapshotted the cursors as page N\n // was mapped, before a single one of its entries had reached\n // `commit` — so read N+1 carried read N's request cursors and the\n // server correctly re-served the page it had just served. Every\n // catch-up page past the first arrived twice.\n Effect.suspend(() => {\n const requested = snapshot()\n return client[\"Sync.Read\"]({\n protocolVersion,\n scope: options.scope,\n cursors: requested,\n limit: bootstrapLimit,\n ...(options.capability === undefined ? {} : { capability: options.capability })\n }).pipe(\n Effect.catchCause((cause) => Effect.failCause(rpcCause(cause))),\n Effect.flatMap((response) => Admission.decode(ReadResponse, response)),\n Effect.flatMap((response) =>\n Effect.map(Admission.records(response.entries), (entries) => ({ ...response, entries }))\n ),\n Effect.map((response) => {\n const pageBytes = entriesByteLength(response.entries)\n if (pageBytes > maxFrameBytes) return Stream.fail(oversized(pageBytes, maxFrameBytes))\n const violation = pageViolation(options.scope, cursorMap(requested), response)\n if (violation !== undefined) return Stream.fail(violation)\n const generations = new Map(response.cursors.map((cursor) => [cursor.runId, cursor.generation!]))\n const page = Stream.flatMap(\n Stream.fromIterable(response.entries),\n (entry) =>\n deliver(\n entry.runId,\n entry,\n generations.get(entry.runId)!\n )\n )\n if (response.done) return Stream.concat(page, follow())\n if (response.entries.length === 0) {\n // An incomplete page with no entries can never converge:\n // the next read would carry the same cursors and receive\n // the same page. Fail typed instead of spinning.\n return Stream.fail(\n new SyncError({\n code: \"protocol_violation\",\n message: \"Bootstrap read reported more durable entries but returned an empty page\"\n })\n )\n }\n return Stream.concat(page, bootstrap())\n })\n )\n })\n )\n\n /**\n * The checkpoint one failure says to resume from, or `undefined` when\n * the failure is not a recoverable compaction.\n *\n * A compaction whose checkpoint is at or below what this subscription\n * already covers cannot move it forward, so retrying would re-read the\n * same refusal forever. That is the same non-convergence rule the\n * empty incomplete bootstrap page is refused under, and it is why a\n * `compacted` failure carrying no {@link Resync} stays a failure\n * rather than becoming a silent stall.\n */\n const resyncTarget = (failure: Failure): Resync | undefined => {\n if (!SyncError.is(failure) || failure.code !== \"compacted\" || failure.resync === undefined) {\n return undefined\n }\n const covered: number = cursor.get(failure.resync.runId)?.afterSeq ?? -1\n return covered >= failure.resync.checkpointSeq ? undefined : failure.resync\n }\n\n const onResync = options.onResync\n\n const resynced = (): Stream.Stream<JournalEvent.Entry, Failure> =>\n Stream.catchCause(bootstrap(), (cause) => {\n const reason = cause.reasons[0]!\n if (cause.reasons.length !== 1 || !Cause.isFailReason(reason)) return Stream.failCause(cause)\n const failure = reason.error\n const resync = resyncTarget(failure)\n if (resync === undefined) return Stream.failCause(cause)\n if (!covers(options.scope, resync.runId)) {\n return Stream.fail(\n new SyncError({\n code: \"protocol_violation\",\n message: \"Compaction target is outside the subscription scope\"\n })\n )\n }\n if (onResync === undefined) return Stream.failCause(cause)\n // Snapshotted before the hook runs, for the reason `deliver`\n // snapshots: the hook is handed the value the commit is read from,\n // and re-reading it afterwards let a consumer move its own cursor\n // arbitrarily far forward from inside the callback.\n const runId = resync.runId\n const checkpointSeq = resync.checkpointSeq\n const refusedGeneration = resync.generation\n return Stream.unwrap(Effect.uninterruptibleMask((restore) =>\n Effect.gen(function*() {\n // Application remains interruptible. Once it returns success,\n // validation and the in-memory commit finish without an async\n // cancellation gap. Durable state/cursor atomicity belongs to\n // the consumer's own transaction, not to this mask.\n const receipt = yield* restore(onResync(resync))\n const restoredCursor = () =>\n new SyncError({\n code: \"invalid_request\",\n message: \"Recovery must return the restored run cursor at or above its compaction floor\"\n })\n // A receipt that omits its generation restored the floor's\n // history, which the refusal names. The previous cursor's\n // generation is no substitute: a fresh client has none,\n // and a rewind since then has replaced it.\n const captured = yield* Effect.try({\n try: () => ({\n runId: receipt.runId,\n afterSeq: receipt.afterSeq,\n generation: receipt.generation ?? refusedGeneration\n }),\n catch: restoredCursor\n })\n if (\n !Schema.is(RunCursor)(captured) || captured.runId !== runId || captured.afterSeq < checkpointSeq\n ) {\n return yield* Effect.fail(restoredCursor())\n }\n const applied = captured\n if (applied.generation === undefined) {\n return yield* Effect.fail(\n new SyncError({\n code: \"protocol_violation\",\n message: \"Compaction refusal names no generation for a receipt that omits one\"\n })\n )\n }\n yield* commit(applied.runId, applied.afterSeq, applied.generation, true)\n return resynced()\n })\n ))\n })\n\n return resynced()\n }))\n\n return SyncClient.of({ snapshot, subscribe, progress })\n })\n\n/**\n * Provides the sync client from the active RPC protocol.\n *\n * @category layers\n * @since 0.1.0\n */\nexport const layer: Layer.Layer<SyncClient, never, RpcClient.Protocol> = Layer.effect(\n SyncClient,\n Effect.flatMap(RpcClient.make(SyncRpcs), (client) => make({ client }))\n)\n\n/**\n * Provides the sync client under an explicit policy. Fails with\n * `invalid_request` when an option is not a positive safe integer, so a bad\n * policy fails the composition rather than every operation under it.\n *\n * @category layers\n * @since 1.0.0-rc.0\n */\nexport const layerWith = (options: Options): Layer.Layer<SyncClient, SyncError, RpcClient.Protocol> =>\n Layer.effect(SyncClient, Effect.flatMap(RpcClient.make(SyncRpcs), (client) => makeWith({ ...options, client })))\n"]}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stable, schema-backed failures for the sync boundary.
|
|
3
|
+
*
|
|
4
|
+
* @since 0.1.0
|
|
5
|
+
*/
|
|
6
|
+
import * as Schema from "effect/Schema";
|
|
7
|
+
/**
|
|
8
|
+
* Stable error codes returned by sync operations.
|
|
9
|
+
*
|
|
10
|
+
* `unsupported` reports an unavailable host operation or presence transport
|
|
11
|
+
* (since 1.0.0). It never implies an empty roster.
|
|
12
|
+
*
|
|
13
|
+
* `compacted` reports that the request's cursor for one run starts below that
|
|
14
|
+
* run's compaction floor, so the entries it asks for have been deleted. It is
|
|
15
|
+
* its own code rather than an `unknown` because it is RECOVERABLE and nothing
|
|
16
|
+
* else here is: the accompanying {@link SyncError.resync} names the checkpoint
|
|
17
|
+
* to resume from, and a follower that applies it converges. Folding it into
|
|
18
|
+
* `unknown` cost the checkpoint, and with it every path back.
|
|
19
|
+
*
|
|
20
|
+
* @category models
|
|
21
|
+
* @since 0.1.0
|
|
22
|
+
*/
|
|
23
|
+
export declare const ErrorCode: Schema.Literals<readonly ["invalid_request", "unsupported", "unauthorized", "not_found", "backpressure", "frame_too_large", "decode_failed", "transport_failed", "protocol_violation", "lineage_changed", "compacted", "closed", "unknown"]>;
|
|
24
|
+
/**
|
|
25
|
+
* Stable error code returned by a sync operation.
|
|
26
|
+
*
|
|
27
|
+
* @category models
|
|
28
|
+
* @since 0.1.0
|
|
29
|
+
*/
|
|
30
|
+
export type ErrorCode = typeof ErrorCode.Type;
|
|
31
|
+
declare const SyncError_base: Schema.Class<SyncError, Schema.TaggedStruct<"@smthrs/sync/SyncError", {
|
|
32
|
+
readonly code: Schema.Literals<readonly ["invalid_request", "unsupported", "unauthorized", "not_found", "backpressure", "frame_too_large", "decode_failed", "transport_failed", "protocol_violation", "lineage_changed", "compacted", "closed", "unknown"]>;
|
|
33
|
+
readonly message: Schema.String;
|
|
34
|
+
readonly cause: Schema.optional<Schema.String>;
|
|
35
|
+
readonly resync: Schema.optional<Schema.Struct<{
|
|
36
|
+
readonly runId: Schema.brand<Schema.String, "@smthrs/journal/JournalEvent/RunId">;
|
|
37
|
+
readonly checkpointSeq: Schema.brand<Schema.Int, "@smthrs/journal/JournalEvent/Seq">;
|
|
38
|
+
readonly generation: Schema.optional<Schema.Int>;
|
|
39
|
+
}>>;
|
|
40
|
+
readonly rewind: Schema.optional<Schema.Struct<{
|
|
41
|
+
readonly runId: Schema.brand<Schema.String, "@smthrs/journal/JournalEvent/RunId">;
|
|
42
|
+
readonly generation: Schema.Int;
|
|
43
|
+
readonly afterSeq: Schema.Int;
|
|
44
|
+
}>>;
|
|
45
|
+
}>, import("effect/Cause").YieldableError>;
|
|
46
|
+
/**
|
|
47
|
+
* Error raised by sync validation, transport, framing, or subscription work.
|
|
48
|
+
*
|
|
49
|
+
* `resync` is set only on `compacted`, and names the run and the checkpoint
|
|
50
|
+
* sequence a follower resumes from. It is optional so every other code keeps
|
|
51
|
+
* the shape it already had on the wire.
|
|
52
|
+
*
|
|
53
|
+
* `rewind` is set on server-side `lineage_changed` refusals and names the
|
|
54
|
+
* current generation and archive boundary. The caller rebuilds its projection
|
|
55
|
+
* from retained history and creates a fresh client; the client never retries this failure.
|
|
56
|
+
*
|
|
57
|
+
* `cause` is a bounded STRING, not the host object that failed. This error is
|
|
58
|
+
* the declared error schema of every RPC in both groups, so whatever it
|
|
59
|
+
* carries reaches a remote follower that may hold nothing but a branch share
|
|
60
|
+
* link. A `Schema.Unknown` cause published the host's own failure verbatim —
|
|
61
|
+
* a driver message with SQL text, a rejected credential — counted against no
|
|
62
|
+
* size ceiling, and had no defined wire form for a class instance or a cyclic
|
|
63
|
+
* value. `internal/CauseText` is the one renderer that fills it.
|
|
64
|
+
*
|
|
65
|
+
* @category errors
|
|
66
|
+
* @since 0.1.0
|
|
67
|
+
*/
|
|
68
|
+
export declare class SyncError extends SyncError_base {
|
|
69
|
+
/**
|
|
70
|
+
* Returns `true` when a value carries this error's shape: the tag, a `code`
|
|
71
|
+
* this package declares, a string `message`, and a `resync` only alongside
|
|
72
|
+
* `compacted`.
|
|
73
|
+
*
|
|
74
|
+
* It is a STRUCTURAL check, not a class check, deliberately. Everything that
|
|
75
|
+
* reaches it on a shipped path has crossed a boundary that rebuilds the
|
|
76
|
+
* value — the RPC client's schema-decoded error channel, or a browser
|
|
77
|
+
* `postMessage` that keeps the fields and drops the prototype — and a check
|
|
78
|
+
* that demanded the prototype would refuse an error the package itself sent.
|
|
79
|
+
* What it does not verify is that the value was produced by this package: a
|
|
80
|
+
* value constructed in-process with the right fields passes.
|
|
81
|
+
*
|
|
82
|
+
* It is TOTAL. The value is `unknown`, so ANY property read on it may be a
|
|
83
|
+
* throwing getter — the tag included, which is the first one read and was
|
|
84
|
+
* the one read outside the protection — and this guard decides whether a
|
|
85
|
+
* follow reconnects and whether a cursor moves past a compaction floor: a
|
|
86
|
+
* question about a value's shape must answer, never raise.
|
|
87
|
+
*
|
|
88
|
+
* @since 0.1.0
|
|
89
|
+
*/
|
|
90
|
+
static readonly is: (value: unknown) => value is SyncError;
|
|
91
|
+
}
|
|
92
|
+
declare const SyncGapError_base: Schema.Class<SyncGapError, Schema.TaggedStruct<"@smthrs/sync/SyncGapError", {
|
|
93
|
+
readonly runId: Schema.brand<Schema.String, "@smthrs/journal/JournalEvent/RunId">;
|
|
94
|
+
readonly expectedFrom: Schema.brand<Schema.Int, "@smthrs/journal/JournalEvent/Seq">;
|
|
95
|
+
readonly receivedFrom: Schema.brand<Schema.Int, "@smthrs/journal/JournalEvent/Seq">;
|
|
96
|
+
}>, import("effect/Cause").YieldableError>;
|
|
97
|
+
/**
|
|
98
|
+
* Terminal error raised when a server frame starts beyond the client's
|
|
99
|
+
* covered cursor.
|
|
100
|
+
*
|
|
101
|
+
* @category errors
|
|
102
|
+
* @since 0.1.0
|
|
103
|
+
*/
|
|
104
|
+
export declare class SyncGapError extends SyncGapError_base {
|
|
105
|
+
}
|
|
106
|
+
export {};
|
|
107
|
+
//# sourceMappingURL=SyncError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SyncError.d.ts","sourceRoot":"","sources":["../../src/SyncError.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAoBvC;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,SAAS,8OAAiF,CAAA;AAIvG;;;;;GAKG;AACH,MAAM,MAAM,SAAS,GAAG,OAAO,SAAS,CAAC,IAAI,CAAA;;;;;;;;;;;;;;;;AAQ7C;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,SAAU,SAAQ,cAM7B;IACA;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,MAAM,CAAC,QAAQ,CAAC,EAAE,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,SAAS,CAoBxD;CACF;;;;;;AAED;;;;;;GAMG;AACH,qBAAa,YAAa,SAAQ,iBAIhC;CAAG"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stable, schema-backed failures for the sync boundary.
|
|
3
|
+
*
|
|
4
|
+
* @since 0.1.0
|
|
5
|
+
*/
|
|
6
|
+
import * as JournalEvent from "@smthrs/journal/JournalEvent";
|
|
7
|
+
import * as Predicate from "effect/Predicate";
|
|
8
|
+
import * as Schema from "effect/Schema";
|
|
9
|
+
import { Resync } from "./SyncProtocol.js";
|
|
10
|
+
/** The literals behind {@link ErrorCode}, also read by {@link SyncError.is}. */
|
|
11
|
+
const errorCodes = [
|
|
12
|
+
"invalid_request",
|
|
13
|
+
"unsupported",
|
|
14
|
+
"unauthorized",
|
|
15
|
+
"not_found",
|
|
16
|
+
"backpressure",
|
|
17
|
+
"frame_too_large",
|
|
18
|
+
"decode_failed",
|
|
19
|
+
"transport_failed",
|
|
20
|
+
"protocol_violation",
|
|
21
|
+
"lineage_changed",
|
|
22
|
+
"compacted",
|
|
23
|
+
"closed",
|
|
24
|
+
"unknown"
|
|
25
|
+
];
|
|
26
|
+
/**
|
|
27
|
+
* Stable error codes returned by sync operations.
|
|
28
|
+
*
|
|
29
|
+
* `unsupported` reports an unavailable host operation or presence transport
|
|
30
|
+
* (since 1.0.0). It never implies an empty roster.
|
|
31
|
+
*
|
|
32
|
+
* `compacted` reports that the request's cursor for one run starts below that
|
|
33
|
+
* run's compaction floor, so the entries it asks for have been deleted. It is
|
|
34
|
+
* its own code rather than an `unknown` because it is RECOVERABLE and nothing
|
|
35
|
+
* else here is: the accompanying {@link SyncError.resync} names the checkpoint
|
|
36
|
+
* to resume from, and a follower that applies it converges. Folding it into
|
|
37
|
+
* `unknown` cost the checkpoint, and with it every path back.
|
|
38
|
+
*
|
|
39
|
+
* @category models
|
|
40
|
+
* @since 0.1.0
|
|
41
|
+
*/
|
|
42
|
+
export const ErrorCode = Schema.Literals(errorCodes).annotate({ identifier: "@smthrs/sync/ErrorCode" });
|
|
43
|
+
const codes = new Set(errorCodes);
|
|
44
|
+
const Rewind = Schema.Struct({
|
|
45
|
+
runId: JournalEvent.RunId,
|
|
46
|
+
generation: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
|
|
47
|
+
afterSeq: Schema.Int.check(Schema.isGreaterThanOrEqualTo(-1))
|
|
48
|
+
});
|
|
49
|
+
/**
|
|
50
|
+
* Error raised by sync validation, transport, framing, or subscription work.
|
|
51
|
+
*
|
|
52
|
+
* `resync` is set only on `compacted`, and names the run and the checkpoint
|
|
53
|
+
* sequence a follower resumes from. It is optional so every other code keeps
|
|
54
|
+
* the shape it already had on the wire.
|
|
55
|
+
*
|
|
56
|
+
* `rewind` is set on server-side `lineage_changed` refusals and names the
|
|
57
|
+
* current generation and archive boundary. The caller rebuilds its projection
|
|
58
|
+
* from retained history and creates a fresh client; the client never retries this failure.
|
|
59
|
+
*
|
|
60
|
+
* `cause` is a bounded STRING, not the host object that failed. This error is
|
|
61
|
+
* the declared error schema of every RPC in both groups, so whatever it
|
|
62
|
+
* carries reaches a remote follower that may hold nothing but a branch share
|
|
63
|
+
* link. A `Schema.Unknown` cause published the host's own failure verbatim —
|
|
64
|
+
* a driver message with SQL text, a rejected credential — counted against no
|
|
65
|
+
* size ceiling, and had no defined wire form for a class instance or a cyclic
|
|
66
|
+
* value. `internal/CauseText` is the one renderer that fills it.
|
|
67
|
+
*
|
|
68
|
+
* @category errors
|
|
69
|
+
* @since 0.1.0
|
|
70
|
+
*/
|
|
71
|
+
export class SyncError extends Schema.TaggedError()("@smthrs/sync/SyncError", {
|
|
72
|
+
code: ErrorCode,
|
|
73
|
+
message: Schema.String,
|
|
74
|
+
cause: Schema.optional(Schema.String),
|
|
75
|
+
resync: Schema.optional(Resync),
|
|
76
|
+
rewind: Schema.optional(Rewind)
|
|
77
|
+
}) {
|
|
78
|
+
/**
|
|
79
|
+
* Returns `true` when a value carries this error's shape: the tag, a `code`
|
|
80
|
+
* this package declares, a string `message`, and a `resync` only alongside
|
|
81
|
+
* `compacted`.
|
|
82
|
+
*
|
|
83
|
+
* It is a STRUCTURAL check, not a class check, deliberately. Everything that
|
|
84
|
+
* reaches it on a shipped path has crossed a boundary that rebuilds the
|
|
85
|
+
* value — the RPC client's schema-decoded error channel, or a browser
|
|
86
|
+
* `postMessage` that keeps the fields and drops the prototype — and a check
|
|
87
|
+
* that demanded the prototype would refuse an error the package itself sent.
|
|
88
|
+
* What it does not verify is that the value was produced by this package: a
|
|
89
|
+
* value constructed in-process with the right fields passes.
|
|
90
|
+
*
|
|
91
|
+
* It is TOTAL. The value is `unknown`, so ANY property read on it may be a
|
|
92
|
+
* throwing getter — the tag included, which is the first one read and was
|
|
93
|
+
* the one read outside the protection — and this guard decides whether a
|
|
94
|
+
* follow reconnects and whether a cursor moves past a compaction floor: a
|
|
95
|
+
* question about a value's shape must answer, never raise.
|
|
96
|
+
*
|
|
97
|
+
* @since 0.1.0
|
|
98
|
+
*/
|
|
99
|
+
static is = (value) => {
|
|
100
|
+
try {
|
|
101
|
+
if (!Predicate.isTagged(value, "@smthrs/sync/SyncError"))
|
|
102
|
+
return false;
|
|
103
|
+
const candidate = value;
|
|
104
|
+
if (typeof candidate.message !== "string")
|
|
105
|
+
return false;
|
|
106
|
+
if (typeof candidate.code !== "string" || !codes.has(candidate.code))
|
|
107
|
+
return false;
|
|
108
|
+
if (candidate.rewind !== undefined &&
|
|
109
|
+
(candidate.code !== "lineage_changed" || !Schema.is(Rewind)(candidate.rewind)))
|
|
110
|
+
return false;
|
|
111
|
+
if (candidate.resync === undefined)
|
|
112
|
+
return true;
|
|
113
|
+
return candidate.code === "compacted" && Schema.is(Resync)(candidate.resync);
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Terminal error raised when a server frame starts beyond the client's
|
|
122
|
+
* covered cursor.
|
|
123
|
+
*
|
|
124
|
+
* @category errors
|
|
125
|
+
* @since 0.1.0
|
|
126
|
+
*/
|
|
127
|
+
export class SyncGapError extends Schema.TaggedError()("@smthrs/sync/SyncGapError", {
|
|
128
|
+
runId: JournalEvent.RunId,
|
|
129
|
+
expectedFrom: JournalEvent.Seq,
|
|
130
|
+
receivedFrom: JournalEvent.Seq
|
|
131
|
+
}) {
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=SyncError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SyncError.js","sourceRoot":"","sources":["../../src/SyncError.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,YAAY,MAAM,8BAA8B,CAAA;AAC5D,OAAO,KAAK,SAAS,MAAM,kBAAkB,CAAA;AAC7C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAE1C,gFAAgF;AAChF,MAAM,UAAU,GAAG;IACjB,iBAAiB;IACjB,aAAa;IACb,cAAc;IACd,W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YACtE,MAAM,SAAS,GAAG,KAKjB,CAAA;YACD,IAAI,OAAO,SAAS,CAAC,OAAO,KAAK,QAAQ;gBAAE,OAAO,KAAK,CAAA;YACvD,IAAI,OAAO,SAAS,CAAC,IAAI,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC;gBAAE,OAAO,KAAK,CAAA;YAClF,IACE,SAAS,CAAC,MAAM,KAAK,SAAS;gBAC9B,CAAC,SAAS,CAAC,IAAI,KAAK,iBAAiB,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;gBAC9E,OAAO,KAAK,CAAA;YACd,IAAI,SAAS,CAAC,MAAM,KAAK,SAAS;gBAAE,OAAO,IAAI,CAAA;YAC/C,OAAO,SAAS,CAAC,IAAI,KAAK,WAAW,IAAI,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;QAC9E,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,KAAK,CAAA;QACd,CAAC;IACH,CAAC,CAAA;;AAGH;;;;;;GAMG;AACH,MAAM,OAAO,YAAa,SAAQ,MAAM,CAAC,WAAW,EAAgB,CAAC,2BAA2B,EAAE;IAChG,KAAK,EAAE,YAAY,CAAC,KAAK;IACzB,YAAY,EAAE,YAAY,CAAC,GAAG;IAC9B,YAAY,EAAE,YAAY,CAAC,GAAG;CAC/B,CAAC;CAAG","sourcesContent":["/**\n * Stable, schema-backed failures for the sync boundary.\n *\n * @since 0.1.0\n */\n\nimport * as JournalEvent from \"@smthrs/journal/JournalEvent\"\nimport * as Predicate from \"effect/Predicate\"\nimport * as Schema from \"effect/Schema\"\nimport { Resync } from \"./SyncProtocol.ts\"\n\n/** The literals behind {@link ErrorCode}, also read by {@link SyncError.is}. */\nconst errorCodes = [\n \"invalid_request\",\n \"unsupported\",\n \"unauthorized\",\n \"not_found\",\n \"backpressure\",\n \"frame_too_large\",\n \"decode_failed\",\n \"transport_failed\",\n \"protocol_violation\",\n \"lineage_changed\",\n \"compacted\",\n \"closed\",\n \"unknown\"\n] as const\n\n/**\n * Stable error codes returned by sync operations.\n *\n * `unsupported` reports an unavailable host operation or presence transport\n * (since 1.0.0). It never implies an empty roster.\n *\n * `compacted` reports that the request's cursor for one run starts below that\n * run's compaction floor, so the entries it asks for have been deleted. It is\n * its own code rather than an `unknown` because it is RECOVERABLE and nothing\n * else here is: the accompanying {@link SyncError.resync} names the checkpoint\n * to resume from, and a follower that applies it converges. Folding it into\n * `unknown` cost the checkpoint, and with it every path back.\n *\n * @category models\n * @since 0.1.0\n */\nexport const ErrorCode = Schema.Literals(errorCodes).annotate({ identifier: \"@smthrs/sync/ErrorCode\" })\n\nconst codes: ReadonlySet<string> = new Set(errorCodes)\n\n/**\n * Stable error code returned by a sync operation.\n *\n * @category models\n * @since 0.1.0\n */\nexport type ErrorCode = typeof ErrorCode.Type\n\nconst Rewind = Schema.Struct({\n runId: JournalEvent.RunId,\n generation: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),\n afterSeq: Schema.Int.check(Schema.isGreaterThanOrEqualTo(-1))\n})\n\n/**\n * Error raised by sync validation, transport, framing, or subscription work.\n *\n * `resync` is set only on `compacted`, and names the run and the checkpoint\n * sequence a follower resumes from. It is optional so every other code keeps\n * the shape it already had on the wire.\n *\n * `rewind` is set on server-side `lineage_changed` refusals and names the\n * current generation and archive boundary. The caller rebuilds its projection\n * from retained history and creates a fresh client; the client never retries this failure.\n *\n * `cause` is a bounded STRING, not the host object that failed. This error is\n * the declared error schema of every RPC in both groups, so whatever it\n * carries reaches a remote follower that may hold nothing but a branch share\n * link. A `Schema.Unknown` cause published the host's own failure verbatim —\n * a driver message with SQL text, a rejected credential — counted against no\n * size ceiling, and had no defined wire form for a class instance or a cyclic\n * value. `internal/CauseText` is the one renderer that fills it.\n *\n * @category errors\n * @since 0.1.0\n */\nexport class SyncError extends Schema.TaggedError<SyncError>()(\"@smthrs/sync/SyncError\", {\n code: ErrorCode,\n message: Schema.String,\n cause: Schema.optional(Schema.String),\n resync: Schema.optional(Resync),\n rewind: Schema.optional(Rewind)\n}) {\n /**\n * Returns `true` when a value carries this error's shape: the tag, a `code`\n * this package declares, a string `message`, and a `resync` only alongside\n * `compacted`.\n *\n * It is a STRUCTURAL check, not a class check, deliberately. Everything that\n * reaches it on a shipped path has crossed a boundary that rebuilds the\n * value — the RPC client's schema-decoded error channel, or a browser\n * `postMessage` that keeps the fields and drops the prototype — and a check\n * that demanded the prototype would refuse an error the package itself sent.\n * What it does not verify is that the value was produced by this package: a\n * value constructed in-process with the right fields passes.\n *\n * It is TOTAL. The value is `unknown`, so ANY property read on it may be a\n * throwing getter — the tag included, which is the first one read and was\n * the one read outside the protection — and this guard decides whether a\n * follow reconnects and whether a cursor moves past a compaction floor: a\n * question about a value's shape must answer, never raise.\n *\n * @since 0.1.0\n */\n static readonly is = (value: unknown): value is SyncError => {\n try {\n if (!Predicate.isTagged(value, \"@smthrs/sync/SyncError\")) return false\n const candidate = value as {\n readonly code?: unknown\n readonly message?: unknown\n readonly resync?: unknown\n readonly rewind?: unknown\n }\n if (typeof candidate.message !== \"string\") return false\n if (typeof candidate.code !== \"string\" || !codes.has(candidate.code)) return false\n if (\n candidate.rewind !== undefined &&\n (candidate.code !== \"lineage_changed\" || !Schema.is(Rewind)(candidate.rewind))\n ) return false\n if (candidate.resync === undefined) return true\n return candidate.code === \"compacted\" && Schema.is(Resync)(candidate.resync)\n } catch {\n return false\n }\n }\n}\n\n/**\n * Terminal error raised when a server frame starts beyond the client's\n * covered cursor.\n *\n * @category errors\n * @since 0.1.0\n */\nexport class SyncGapError extends Schema.TaggedError<SyncGapError>()(\"@smthrs/sync/SyncGapError\", {\n runId: JournalEvent.RunId,\n expectedFrom: JournalEvent.Seq,\n receivedFrom: JournalEvent.Seq\n}) {}\n"]}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The authenticated identity of one sync request.
|
|
3
|
+
*
|
|
4
|
+
* The principal is a `Context.Reference` whose default is
|
|
5
|
+
* {@link anonymous}, which is what makes the read path fail closed: code
|
|
6
|
+
* that never authenticates runs as anonymous, and the server refuses
|
|
7
|
+
* anonymous access to every non-branch run. The only ways to become the
|
|
8
|
+
* workspace principal are a workspace capability verified by
|
|
9
|
+
* `SyncAuth.layer` at the RPC boundary, or an in-process caller that
|
|
10
|
+
* provides the reference itself — which is the sanctioned path for code
|
|
11
|
+
* already holding the journal, and never for a transport.
|
|
12
|
+
*
|
|
13
|
+
* @since 0.1.0
|
|
14
|
+
*/
|
|
15
|
+
import * as Context from "effect/Context";
|
|
16
|
+
import * as Layer from "effect/Layer";
|
|
17
|
+
/**
|
|
18
|
+
* A request that presented no credential. It may still read branch runs
|
|
19
|
+
* through per-request branch share capabilities.
|
|
20
|
+
*
|
|
21
|
+
* @category models
|
|
22
|
+
* @since 0.1.0
|
|
23
|
+
*/
|
|
24
|
+
export interface Anonymous {
|
|
25
|
+
readonly _tag: "Anonymous";
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* A request authenticated for the workspace's non-branch runs.
|
|
29
|
+
* `capabilityId` names the credential for auditing; in-process callers name
|
|
30
|
+
* themselves.
|
|
31
|
+
*
|
|
32
|
+
* @category models
|
|
33
|
+
* @since 0.1.0
|
|
34
|
+
*/
|
|
35
|
+
export interface Workspace {
|
|
36
|
+
readonly _tag: "Workspace";
|
|
37
|
+
readonly capabilityId: string;
|
|
38
|
+
/**
|
|
39
|
+
* When the credential that established this principal stops authorizing,
|
|
40
|
+
* in epoch milliseconds, or `Infinity` for an in-process owner that
|
|
41
|
+
* presented no credential at all.
|
|
42
|
+
*
|
|
43
|
+
* A signed expiry is this package's ONLY revocation mechanism, and an open
|
|
44
|
+
* subscription is not a sequence of requests: it is authorized once, at
|
|
45
|
+
* open, and then streams. Without the expiry on the identity itself,
|
|
46
|
+
* nothing downstream could tell a live subscription to stop, so a holder of
|
|
47
|
+
* an expired capability kept reading for as long as it declined to
|
|
48
|
+
* disconnect.
|
|
49
|
+
*/
|
|
50
|
+
readonly expiresAtMs: number;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Any authenticated identity a sync request can carry.
|
|
54
|
+
*
|
|
55
|
+
* @category models
|
|
56
|
+
* @since 0.1.0
|
|
57
|
+
*/
|
|
58
|
+
export type Principal = Anonymous | Workspace;
|
|
59
|
+
/**
|
|
60
|
+
* The unauthenticated principal.
|
|
61
|
+
*
|
|
62
|
+
* @category constructors
|
|
63
|
+
* @since 0.1.0
|
|
64
|
+
*/
|
|
65
|
+
export declare const anonymous: Principal;
|
|
66
|
+
/**
|
|
67
|
+
* Constructs the workspace principal for a named credential.
|
|
68
|
+
*
|
|
69
|
+
* `expiresAtMs` defaults to `Infinity`, which is the honest answer for an
|
|
70
|
+
* in-process owner that already holds the journal: it presented no credential,
|
|
71
|
+
* so no credential can expire under it.
|
|
72
|
+
*
|
|
73
|
+
* @category constructors
|
|
74
|
+
* @since 0.1.0
|
|
75
|
+
*/
|
|
76
|
+
export declare const workspace: (capabilityId: string, expiresAtMs?: number) => Principal;
|
|
77
|
+
/**
|
|
78
|
+
* Returns `true` when a principal may read non-branch runs.
|
|
79
|
+
*
|
|
80
|
+
* @category predicates
|
|
81
|
+
* @since 0.1.0
|
|
82
|
+
*/
|
|
83
|
+
export declare const isWorkspace: (principal: Principal) => principal is Workspace;
|
|
84
|
+
/**
|
|
85
|
+
* The current request's principal, defaulting to {@link anonymous}.
|
|
86
|
+
*
|
|
87
|
+
* @category references
|
|
88
|
+
* @since 0.1.0
|
|
89
|
+
*/
|
|
90
|
+
export declare const SyncPrincipal: Context.Reference<Principal>;
|
|
91
|
+
/**
|
|
92
|
+
* Provides the workspace principal directly, bypassing credential
|
|
93
|
+
* verification. For in-process callers that already own the journal — a
|
|
94
|
+
* transport boundary must authenticate through `SyncAuth.layer` instead.
|
|
95
|
+
*
|
|
96
|
+
* @category layers
|
|
97
|
+
* @since 0.1.0
|
|
98
|
+
*/
|
|
99
|
+
export declare const layerWorkspace: (capabilityId: string) => Layer.Layer<never>;
|
|
100
|
+
//# sourceMappingURL=SyncPrincipal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SyncPrincipal.d.ts","sourceRoot":"","sources":["../../src/SyncPrincipal.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAErC;;;;;;GAMG;AACH,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAA;CAC3B;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAA;IAC1B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;IAC7B;;;;;;;;;;;OAWG;IACH,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;CAC7B;AAED;;;;;GAKG;AACH,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,SAAS,CAAA;AAE7C;;;;;GAKG;AACH,eAAO,MAAM,SAAS,EAAE,SAAiC,CAAA;AAEzD;;;;;;;;;GASG;AACH,eAAO,MAAM,SAAS,GACpB,cAAc,MAAM,EACpB,cAAa,MAAiC,KAC7C,SAA+D,CAAA;AAElE;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GAAI,WAAW,SAAS,KAAG,SAAS,IAAI,SAA2C,CAAA;AAE3G;;;;;GAKG;AACH,eAAO,MAAM,aAAa,EAAE,OAAO,CAAC,SAAS,CAAC,SAAS,CAGtD,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,GAAI,cAAc,MAAM,KAAG,KAAK,CAAC,KAAK,CAAC,KAAK,CAChB,CAAA"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The authenticated identity of one sync request.
|
|
3
|
+
*
|
|
4
|
+
* The principal is a `Context.Reference` whose default is
|
|
5
|
+
* {@link anonymous}, which is what makes the read path fail closed: code
|
|
6
|
+
* that never authenticates runs as anonymous, and the server refuses
|
|
7
|
+
* anonymous access to every non-branch run. The only ways to become the
|
|
8
|
+
* workspace principal are a workspace capability verified by
|
|
9
|
+
* `SyncAuth.layer` at the RPC boundary, or an in-process caller that
|
|
10
|
+
* provides the reference itself — which is the sanctioned path for code
|
|
11
|
+
* already holding the journal, and never for a transport.
|
|
12
|
+
*
|
|
13
|
+
* @since 0.1.0
|
|
14
|
+
*/
|
|
15
|
+
import * as Context from "effect/Context";
|
|
16
|
+
import * as Layer from "effect/Layer";
|
|
17
|
+
/**
|
|
18
|
+
* The unauthenticated principal.
|
|
19
|
+
*
|
|
20
|
+
* @category constructors
|
|
21
|
+
* @since 0.1.0
|
|
22
|
+
*/
|
|
23
|
+
export const anonymous = { _tag: "Anonymous" };
|
|
24
|
+
/**
|
|
25
|
+
* Constructs the workspace principal for a named credential.
|
|
26
|
+
*
|
|
27
|
+
* `expiresAtMs` defaults to `Infinity`, which is the honest answer for an
|
|
28
|
+
* in-process owner that already holds the journal: it presented no credential,
|
|
29
|
+
* so no credential can expire under it.
|
|
30
|
+
*
|
|
31
|
+
* @category constructors
|
|
32
|
+
* @since 0.1.0
|
|
33
|
+
*/
|
|
34
|
+
export const workspace = (capabilityId, expiresAtMs = Number.POSITIVE_INFINITY) => ({ _tag: "Workspace", capabilityId, expiresAtMs });
|
|
35
|
+
/**
|
|
36
|
+
* Returns `true` when a principal may read non-branch runs.
|
|
37
|
+
*
|
|
38
|
+
* @category predicates
|
|
39
|
+
* @since 0.1.0
|
|
40
|
+
*/
|
|
41
|
+
export const isWorkspace = (principal) => principal._tag === "Workspace";
|
|
42
|
+
/**
|
|
43
|
+
* The current request's principal, defaulting to {@link anonymous}.
|
|
44
|
+
*
|
|
45
|
+
* @category references
|
|
46
|
+
* @since 0.1.0
|
|
47
|
+
*/
|
|
48
|
+
export const SyncPrincipal = Context.Reference("@smthrs/sync/SyncPrincipal", { defaultValue: () => anonymous });
|
|
49
|
+
/**
|
|
50
|
+
* Provides the workspace principal directly, bypassing credential
|
|
51
|
+
* verification. For in-process callers that already own the journal — a
|
|
52
|
+
* transport boundary must authenticate through `SyncAuth.layer` instead.
|
|
53
|
+
*
|
|
54
|
+
* @category layers
|
|
55
|
+
* @since 0.1.0
|
|
56
|
+
*/
|
|
57
|
+
export const layerWorkspace = (capabilityId) => Layer.succeed(SyncPrincipal, workspace(capabilityId));
|
|
58
|
+
//# sourceMappingURL=SyncPrincipal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SyncPrincipal.js","sourceRoot":"","sources":["../../src/SyncPrincipal.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AA+CrC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,SAAS,GAAc,EAAE,IAAI,EAAE,WAAW,EAAE,CAAA;AAEzD;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CACvB,YAAoB,EACpB,cAAsB,MAAM,CAAC,iBAAiB,EACnC,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,CAAC,CAAA;AAElE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,SAAoB,EAA0B,EAAE,CAAC,SAAS,CAAC,IAAI,KAAK,WAAW,CAAA;AAE3G;;;;;GAKG;AACH,MAAM,CAAC,MAAM,aAAa,GAAiC,OAAO,CAAC,SAAS,CAC1E,4BAA4B,EAC5B,EAAE,YAAY,EAAE,GAAG,EAAE,CAAC,SAAS,EAAE,CAClC,CAAA;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,YAAoB,EAAsB,EAAE,CACzE,KAAK,CAAC,OAAO,CAAC,aAAa,EAAE,SAAS,CAAC,YAAY,CAAC,CAAC,CAAA","sourcesContent":["/**\n * The authenticated identity of one sync request.\n *\n * The principal is a `Context.Reference` whose default is\n * {@link anonymous}, which is what makes the read path fail closed: code\n * that never authenticates runs as anonymous, and the server refuses\n * anonymous access to every non-branch run. The only ways to become the\n * workspace principal are a workspace capability verified by\n * `SyncAuth.layer` at the RPC boundary, or an in-process caller that\n * provides the reference itself — which is the sanctioned path for code\n * already holding the journal, and never for a transport.\n *\n * @since 0.1.0\n */\n\nimport * as Context from \"effect/Context\"\nimport * as Layer from \"effect/Layer\"\n\n/**\n * A request that presented no credential. It may still read branch runs\n * through per-request branch share capabilities.\n *\n * @category models\n * @since 0.1.0\n */\nexport interface Anonymous {\n readonly _tag: \"Anonymous\"\n}\n\n/**\n * A request authenticated for the workspace's non-branch runs.\n * `capabilityId` names the credential for auditing; in-process callers name\n * themselves.\n *\n * @category models\n * @since 0.1.0\n */\nexport interface Workspace {\n readonly _tag: \"Workspace\"\n readonly capabilityId: string\n /**\n * When the credential that established this principal stops authorizing,\n * in epoch milliseconds, or `Infinity` for an in-process owner that\n * presented no credential at all.\n *\n * A signed expiry is this package's ONLY revocation mechanism, and an open\n * subscription is not a sequence of requests: it is authorized once, at\n * open, and then streams. Without the expiry on the identity itself,\n * nothing downstream could tell a live subscription to stop, so a holder of\n * an expired capability kept reading for as long as it declined to\n * disconnect.\n */\n readonly expiresAtMs: number\n}\n\n/**\n * Any authenticated identity a sync request can carry.\n *\n * @category models\n * @since 0.1.0\n */\nexport type Principal = Anonymous | Workspace\n\n/**\n * The unauthenticated principal.\n *\n * @category constructors\n * @since 0.1.0\n */\nexport const anonymous: Principal = { _tag: \"Anonymous\" }\n\n/**\n * Constructs the workspace principal for a named credential.\n *\n * `expiresAtMs` defaults to `Infinity`, which is the honest answer for an\n * in-process owner that already holds the journal: it presented no credential,\n * so no credential can expire under it.\n *\n * @category constructors\n * @since 0.1.0\n */\nexport const workspace = (\n capabilityId: string,\n expiresAtMs: number = Number.POSITIVE_INFINITY\n): Principal => ({ _tag: \"Workspace\", capabilityId, expiresAtMs })\n\n/**\n * Returns `true` when a principal may read non-branch runs.\n *\n * @category predicates\n * @since 0.1.0\n */\nexport const isWorkspace = (principal: Principal): principal is Workspace => principal._tag === \"Workspace\"\n\n/**\n * The current request's principal, defaulting to {@link anonymous}.\n *\n * @category references\n * @since 0.1.0\n */\nexport const SyncPrincipal: Context.Reference<Principal> = Context.Reference<Principal>(\n \"@smthrs/sync/SyncPrincipal\",\n { defaultValue: () => anonymous }\n)\n\n/**\n * Provides the workspace principal directly, bypassing credential\n * verification. For in-process callers that already own the journal — a\n * transport boundary must authenticate through `SyncAuth.layer` instead.\n *\n * @category layers\n * @since 0.1.0\n */\nexport const layerWorkspace = (capabilityId: string): Layer.Layer<never> =>\n Layer.succeed(SyncPrincipal, workspace(capabilityId))\n"]}
|