@smthrs/sync 1.0.0-rc.7 → 1.0.0-rc.8
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/README.md +3 -1
- package/dist/cjs/SyncClient.d.ts.map +1 -1
- package/dist/cjs/SyncClient.js +10 -1
- package/dist/cjs/SyncClient.js.map +2 -2
- package/dist/cjs/SyncServer.d.ts.map +1 -1
- package/dist/cjs/SyncServer.js +3 -1
- package/dist/cjs/SyncServer.js.map +2 -2
- package/dist/esm/SyncClient.d.ts.map +1 -1
- package/dist/esm/SyncClient.js +9 -1
- package/dist/esm/SyncClient.js.map +1 -1
- package/dist/esm/SyncServer.d.ts.map +1 -1
- package/dist/esm/SyncServer.js +8 -1
- package/dist/esm/SyncServer.js.map +1 -1
- package/docs/README.md +3 -1
- package/docs/installation.md +5 -1
- package/docs/protocol.md +7 -3
- package/docs/quickstart.md +1 -1
- package/docs/troubleshooting.md +1 -1
- package/package.json +5 -5
- package/src/SyncClient.ts +14 -1
- package/src/SyncServer.ts +6 -1
package/README.md
CHANGED
|
@@ -20,7 +20,9 @@ commands to a branch's journal run after verifying a write-scoped
|
|
|
20
20
|
|
|
21
21
|
## Install
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
```bash
|
|
24
|
+
npm install @smthrs/sync@next effect
|
|
25
|
+
```
|
|
24
26
|
|
|
25
27
|
`effect` is a peer dependency in the range `^4.0.4`. Two copies of `effect`
|
|
26
28
|
in one program are two sets of service tags, so a client built against one copy
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SyncClient.d.ts","sourceRoot":"","sources":["../../src/SyncClient.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,KAAK,YAAY,MAAM,8BAA8B,CAAA;AAEjE,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,MAAM,cAA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AAA;CAAE,KAAG,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,SAAS,CAYxE,CAAA;AA+XH;;;;;GAKG;AACH,eAAO,MAAM,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,UAAU,EAAE,KAAK,EAAE,SAAS,CAAC,QAAQ,CAGpE,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS,GAAI,SAAS,OAAO,KAAG,KAAK,CAAC,KAAK,CAAC,UAAU,EAAE,SAAS,EAAE,SAAS,CAAC,QAAQ,CACgB,CAAA"}
|
package/dist/cjs/SyncClient.js
CHANGED
|
@@ -299,7 +299,16 @@ const service = (client, { bootstrapLimit, maxFrameBytes }) => Effect.sync(() =>
|
|
|
299
299
|
}
|
|
300
300
|
if (frame.toSeq <= afterSeq) return Stream.empty;
|
|
301
301
|
const entries = frame.entries.filter((entry) => entry.seq > afterSeq);
|
|
302
|
-
|
|
302
|
+
const carried = Stream.flatMap(
|
|
303
|
+
Stream.fromIterable(entries),
|
|
304
|
+
(entry) => deliver(frame.runId, entry, generation)
|
|
305
|
+
);
|
|
306
|
+
const lastCarried = entries.length === 0 ? afterSeq : entries[entries.length - 1].seq;
|
|
307
|
+
if (frame.toSeq <= lastCarried) return carried;
|
|
308
|
+
return Stream.concat(
|
|
309
|
+
carried,
|
|
310
|
+
Stream.drain(Stream.fromEffect(commit(frame.runId, frame.toSeq, generation, applyEntry !== void 0)))
|
|
311
|
+
);
|
|
303
312
|
};
|
|
304
313
|
const livePage = (onFrame) => Stream.unwrap(
|
|
305
314
|
Effect.sync(
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/SyncClient.ts"],
|
|
4
|
-
"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 RpcClient from \"effect/rpc/RpcClient\"\nimport * as RpcClientError from \"effect/rpc/RpcClientError\"\nimport type * as RpcGroup from \"effect/rpc/RpcGroup\"\nimport * as Schedule from \"effect/Schedule\"\nimport * as Schema from \"effect/Schema\"\nimport * as Stream from \"effect/Stream\"\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 \u2014 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 \u2014 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 \u2014 when the caller supplies `SubscribeOptions.apply` \u2014 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` \u2014 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"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,YAAuB;AACvB,cAAyB;AACzB,aAAwB;AACxB,YAAuB;AACvB,UAAqB;AACrB,gBAA2B;AAC3B,qBAAgC;AAEhC,eAA0B;AAC1B,aAAwB;AACxB,aAAwB;AAExB,gBAA2B;AAC3B,uBAAkD;AAClD,2BAAwC;AACxC,uBAAkC;AAClC,uBAAwC;AACxC,0BAmBO;AACP,sBAAyB;AAkBlB,MAAM,gBAAgB;AAatB,MAAM,wBAAwB;AAgCrC,MAAM,WAAqB;AAAA,EACzB,eAAe;AAAA,EACf,gBAAgB;AAClB;AA0FO,MAAM,mBAAmB,QAAQ,QAA6B,EAAE,yBAAyB,EAAE;AAAC;AAS5F,MAAM,OAAO;AAiBb,MAAM,WAAW,CAAC,YAA8B,CAAC,MACtD,WAAW,GAAG;AAAA,EACZ,UAAU,MAAM,OAAO,KAAK,IAAI,2BAAU,EAAE,MAAM,UAAU,SAAS,wBAAwB,CAAC,CAAC;AAAA,EAC/F,WAAW,MAAM,OAAO,KAAK,IAAI,2BAAU,EAAE,MAAM,UAAU,SAAS,wBAAwB,CAAC,CAAC;AAAA,EAChG,UAAU,OAAO,QAAQ,EAAE,WAAW,CAAC,GAAG,SAAS,CAAC,EAAE,CAAC;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AO,OAAO,OAAO,KAAK,eAAe,CAAC;AAAA,UAC5C;AACA,gBAAMC,WAAU;AAChB,cAAIA,SAAQ,eAAe,QAAW;AACpC,mBAAO,OAAO,OAAO;AAAA,cACnB,IAAI,2BAAU;AAAA,gBACZ,MAAM;AAAA,gBACN,SAAS;AAAA,cACX,CAAC;AAAA,YACH;AAAA,UACF;AACA,iBAAO,OAAOA,SAAQ,OAAOA,SAAQ,UAAUA,SAAQ,YAAY,IAAI;AACvE,iBAAO,SAAS;AAAA,QAClB,CAAC;AAAA,MACH,CAAC;AAAA,IACH,CAAC;AAEH,WAAO,SAAS;AAAA,EAClB,CAAC,CAAC;AAEJ,SAAO,WAAW,GAAG,EAAE,UAAU,WAAW,SAAS,CAAC;AACxD,CAAC;AAQI,MAAM,QAA4D,MAAM;AAAA,EAC7E;AAAA,EACA,OAAO,QAAQ,UAAU,KAAK,wBAAQ,GAAG,CAAC,WAAW,KAAK,EAAE,OAAO,CAAC,CAAC;AACvE;AAUO,MAAM,YAAY,CAAC,YACxB,MAAM,OAAO,YAAY,OAAO,QAAQ,UAAU,KAAK,wBAAQ,GAAG,CAAC,WAAW,SAAS,EAAE,GAAG,SAAS,OAAO,CAAC,CAAC,CAAC;",
|
|
4
|
+
"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 RpcClient from \"effect/rpc/RpcClient\"\nimport * as RpcClientError from \"effect/rpc/RpcClientError\"\nimport type * as RpcGroup from \"effect/rpc/RpcGroup\"\nimport * as Schedule from \"effect/Schedule\"\nimport * as Schema from \"effect/Schema\"\nimport * as Stream from \"effect/Stream\"\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 \u2014 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 \u2014 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 \u2014 when the caller supplies `SubscribeOptions.apply` \u2014 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 const carried = Stream.flatMap(\n Stream.fromIterable(entries),\n (entry) => deliver(frame.runId, entry, generation)\n )\n // The frame covered through `toSeq`, and admission may have dropped\n // its LAST sequences, not only inner ones. Committing only the last\n // carried entry left the cursor short, so the next contiguous frame\n // began beyond it and was refused as a gap.\n const lastCarried = entries.length === 0 ? afterSeq : entries[entries.length - 1]!.seq\n if (frame.toSeq <= lastCarried) return carried\n return Stream.concat(\n carried,\n Stream.drain(Stream.fromEffect(commit(frame.runId, frame.toSeq, generation, applyEntry !== undefined)))\n )\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` \u2014 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"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,YAAuB;AACvB,cAAyB;AACzB,aAAwB;AACxB,YAAuB;AACvB,UAAqB;AACrB,gBAA2B;AAC3B,qBAAgC;AAEhC,eAA0B;AAC1B,aAAwB;AACxB,aAAwB;AAExB,gBAA2B;AAC3B,uBAAkD;AAClD,2BAAwC;AACxC,uBAAkC;AAClC,uBAAwC;AACxC,0BAmBO;AACP,sBAAyB;AAkBlB,MAAM,gBAAgB;AAatB,MAAM,wBAAwB;AAgCrC,MAAM,WAAqB;AAAA,EACzB,eAAe;AAAA,EACf,gBAAgB;AAClB;AA0FO,MAAM,mBAAmB,QAAQ,QAA6B,EAAE,yBAAyB,EAAE;AAAC;AAS5F,MAAM,OAAO;AAiBb,MAAM,WAAW,CAAC,YAA8B,CAAC,MACtD,WAAW,GAAG;AAAA,EACZ,UAAU,MAAM,OAAO,KAAK,IAAI,2BAAU,EAAE,MAAM,UAAU,SAAS,wBAAwB,CAAC,CAAC;AAAA,EAC/F,WAAW,MAAM,OAAO,KAAK,IAAI,2BAAU,EAAE,MAAM,UAAU,SAAS,wBAAwB,CAAC,CAAC;AAAA,EAChG,UAAU,OAAO,QAAQ,EAAE,WAAW,CAAC,GAAG,SAAS,CAAC,EAAE,CAAC;AAAA,EACvD,GAAG;AACL,CAAC;AAQI,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CAAA;CAC7C;AAg1BD;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,OAAO,GAAG,UAAU,CAAC,UAAU,CAAsB,CAAA;AAElH;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,YAAY,GACvB,UAAS,OAAY,KACpB,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,SAAS,EAAE,OAAO,CAAC,OAAO,GAAG,UAAU,CAAC,UAAU,CAYzE,CAAA;AAEH;;;;;GAKG;AACH,eAAO,MAAM,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,UAAU,EAAE,KAAK,EAAE,OAAO,CAAC,OAAO,GAAG,UAAU,CAAC,UAAU,CAGzF,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,GACpB,SAAS,OAAO,KACf,KAAK,CAAC,KAAK,CAAC,UAAU,EAAE,SAAS,EAAE,OAAO,CAAC,OAAO,GAAG,UAAU,CAAC,UAAU,CAC5B,CAAA;AAEjD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,KAAK,CACrC,GAAG,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,QAAQ,CAAC,CAAC,EAC7C,KAAK,EACL,UAAU,CAUX,CAAA"}
|
package/dist/cjs/SyncServer.js
CHANGED
|
@@ -242,7 +242,8 @@ const makeWith = ({ concurrency, maxFrameBytes, tailIntervalMs }) => Effect.gen(
|
|
|
242
242
|
yield* (0, import_ProtocolVersion.requireVersion)(request.protocolVersion);
|
|
243
243
|
yield* requireUniqueCursors(request.cursors);
|
|
244
244
|
const limit = yield* (0, import_PolicyOptions.requestCount)("A read's limit", request.limit, SyncProtocol.maxReadLimit);
|
|
245
|
-
const { runIds } = yield* runIdsFor(request.scope, request.capability);
|
|
245
|
+
const { expiresAtMs, runIds } = yield* runIdsFor(request.scope, request.capability);
|
|
246
|
+
if (expiresAtMs <= (yield* Clock.currentTimeMillis)) return yield* Effect.fail(expired);
|
|
246
247
|
const entries = [];
|
|
247
248
|
const cursors = new Map(request.cursors.map((cursor) => [cursor.runId, cursor.afterSeq]));
|
|
248
249
|
const generations = new Map(request.cursors.map((cursor) => [cursor.runId, cursor.generation ?? 0]));
|
|
@@ -276,6 +277,7 @@ const makeWith = ({ concurrency, maxFrameBytes, tailIntervalMs }) => Effect.gen(
|
|
|
276
277
|
const shares = yield* pass(pending, () => Math.min(share2, limit - entries.length), behind);
|
|
277
278
|
const stop = shares ?? (yield* pass(behind, () => limit - entries.length, []));
|
|
278
279
|
if (stop?._tag === "oversized") return yield* frameTooLarge(stop.bytes);
|
|
280
|
+
if (expiresAtMs <= (yield* Clock.currentTimeMillis)) return yield* Effect.fail(expired);
|
|
279
281
|
return {
|
|
280
282
|
entries,
|
|
281
283
|
cursors: Array.from(cursors, ([runId, afterSeq]) => ({
|