@smthrs/sync 1.0.0-rc.5 → 1.0.0-rc.6

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.
Files changed (74) hide show
  1. package/README.md +6 -6
  2. package/dist/cjs/BranchRpcs.d.ts +2 -2
  3. package/dist/cjs/BranchRpcs.d.ts.map +1 -1
  4. package/dist/cjs/BranchRpcs.js +1 -1
  5. package/dist/cjs/BranchRpcs.js.map +2 -2
  6. package/dist/cjs/BranchServer.d.ts +2 -2
  7. package/dist/cjs/BranchServer.d.ts.map +1 -1
  8. package/dist/cjs/BranchServer.js.map +2 -2
  9. package/dist/cjs/SyncAuth.d.ts +1 -1
  10. package/dist/cjs/SyncAuth.d.ts.map +1 -1
  11. package/dist/cjs/SyncAuth.js +5 -5
  12. package/dist/cjs/SyncAuth.js.map +2 -2
  13. package/dist/cjs/SyncClient.d.ts +3 -3
  14. package/dist/cjs/SyncClient.d.ts.map +1 -1
  15. package/dist/cjs/SyncClient.js +2 -2
  16. package/dist/cjs/SyncClient.js.map +2 -2
  17. package/dist/cjs/SyncRpcs.d.ts +2 -2
  18. package/dist/cjs/SyncRpcs.d.ts.map +1 -1
  19. package/dist/cjs/SyncRpcs.js +1 -1
  20. package/dist/cjs/SyncRpcs.js.map +1 -1
  21. package/dist/cjs/SyncServer.d.ts +2 -2
  22. package/dist/cjs/SyncServer.d.ts.map +1 -1
  23. package/dist/cjs/SyncServer.js.map +2 -2
  24. package/dist/cjs/test/TestSocket.d.ts +1 -1
  25. package/dist/cjs/test/TestSocket.d.ts.map +1 -1
  26. package/dist/cjs/test/TestSocket.js +1 -1
  27. package/dist/cjs/test/TestSocket.js.map +1 -1
  28. package/dist/cjs/test/TestSync.d.ts +1 -1
  29. package/dist/cjs/test/TestSync.d.ts.map +1 -1
  30. package/dist/cjs/test/TestSync.js +6 -6
  31. package/dist/cjs/test/TestSync.js.map +1 -1
  32. package/dist/esm/BranchRpcs.d.ts +2 -2
  33. package/dist/esm/BranchRpcs.d.ts.map +1 -1
  34. package/dist/esm/BranchRpcs.js +1 -1
  35. package/dist/esm/BranchRpcs.js.map +1 -1
  36. package/dist/esm/BranchServer.d.ts +2 -2
  37. package/dist/esm/BranchServer.d.ts.map +1 -1
  38. package/dist/esm/BranchServer.js.map +1 -1
  39. package/dist/esm/SyncAuth.d.ts +1 -1
  40. package/dist/esm/SyncAuth.d.ts.map +1 -1
  41. package/dist/esm/SyncAuth.js +5 -5
  42. package/dist/esm/SyncAuth.js.map +1 -1
  43. package/dist/esm/SyncClient.d.ts +3 -3
  44. package/dist/esm/SyncClient.d.ts.map +1 -1
  45. package/dist/esm/SyncClient.js +2 -2
  46. package/dist/esm/SyncClient.js.map +1 -1
  47. package/dist/esm/SyncRpcs.d.ts +2 -2
  48. package/dist/esm/SyncRpcs.d.ts.map +1 -1
  49. package/dist/esm/SyncRpcs.js +1 -1
  50. package/dist/esm/SyncRpcs.js.map +1 -1
  51. package/dist/esm/SyncServer.d.ts +2 -2
  52. package/dist/esm/SyncServer.d.ts.map +1 -1
  53. package/dist/esm/SyncServer.js.map +1 -1
  54. package/dist/esm/test/TestSocket.d.ts +1 -1
  55. package/dist/esm/test/TestSocket.d.ts.map +1 -1
  56. package/dist/esm/test/TestSocket.js +1 -1
  57. package/dist/esm/test/TestSocket.js.map +1 -1
  58. package/dist/esm/test/TestSync.d.ts +1 -1
  59. package/dist/esm/test/TestSync.d.ts.map +1 -1
  60. package/dist/esm/test/TestSync.js +6 -6
  61. package/dist/esm/test/TestSync.js.map +1 -1
  62. package/docs/README.md +2 -2
  63. package/docs/guides/follow-a-run.md +4 -4
  64. package/docs/guides/serve-the-read-path.md +1 -1
  65. package/docs/installation.md +3 -3
  66. package/package.json +9 -9
  67. package/src/BranchRpcs.ts +1 -1
  68. package/src/BranchServer.ts +2 -2
  69. package/src/SyncAuth.ts +5 -5
  70. package/src/SyncClient.ts +3 -3
  71. package/src/SyncRpcs.ts +1 -1
  72. package/src/SyncServer.ts +2 -2
  73. package/src/test/TestSocket.ts +1 -1
  74. package/src/test/TestSync.ts +6 -6
@@ -1 +1 @@
1
- {"version":3,"file":"BranchServer.js","sourceRoot":"","sources":["../../src/BranchServer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAGvC,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAA;AACrD,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAA;AAC3C,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAA;AACrD,OAAO,EAAE,QAAQ,EAAoB,MAAM,qBAAqB,CAAA;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAA;AAC/C,OAAO,KAAK,SAAS,MAAM,yBAAyB,CAAA;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAA;AAEnD;;;;;;;;;;;;;;GAcG;AACH,MAAM,SAAS,GAAG,CAAC,YAAwC,EAAU,EAAE,CACrE,IAAI,CAAC,SAAS,CACZ,YAAY,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC;IAChC,WAAW,CAAC,aAAa;IACzB,WAAW,CAAC,WAAW;IACvB,WAAW,CAAC,SAAS;IACrB,WAAW,CAAC,IAAI;IAChB,WAAW,CAAC,KAAK;IACjB,WAAW,CAAC,QAAQ;IACpB,WAAW,CAAC,UAAU;IACtB,WAAW,CAAC,gBAAgB;IAC5B,WAAW,CAAC,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,CAA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AI,CAAC,OAAO,CAAC,CAAC;QAC9C,iEAAiE;QACjE,mEAAmE;QACnE,oEAAoE;QACpE,gDAAgD;QAChD,MAAM,CAAC,WAAW,CAAC,UAAU,CAAC,EAC9B,MAAM,CAAC,GAAG,CAAC,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,CAAC,CACjD;KACJ,CAAC,CAAA;AACJ,CAAC,CAAC,CACH,CAAA","sourcesContent":["/**\n * The server-side handlers of {@link BranchRpcs}: a thin projection of the\n * branch services onto the wire.\n *\n * Five procedures forward to the service that owns their boundary and add\n * nothing: `Branch.Submit` to {@link BranchCommands}, and `Branch.Announce`,\n * `Branch.Leave`, `Branch.Roster`, and `Branch.WatchRoster` to\n * {@link BranchPresence}. Two enforce policy here, on top of what\n * {@link BranchShare} checks: `Branch.CreateBranch` refuses any principal that\n * is not an authenticated workspace, and `Branch.MintShare` verifies write\n * access, refuses an expired parent, and caps the child at the parent's\n * expiry. `BranchShare.mint` performs none of those checks, so an in-process\n * host that mints through the service directly must gate the principal and\n * the parent capability itself.\n *\n * @since 0.1.0\n */\n\nimport * as Clock from \"effect/Clock\"\nimport * as Effect from \"effect/Effect\"\nimport type * as Layer from \"effect/Layer\"\nimport * as Stream from \"effect/Stream\"\nimport type * as Rpc from \"effect/unstable/rpc/Rpc\"\nimport type * as RpcGroup from \"effect/unstable/rpc/RpcGroup\"\nimport * as BranchCommands from \"./BranchCommands.ts\"\nimport * as BranchIds from \"./BranchIds.ts\"\nimport * as BranchPresence from \"./BranchPresence.ts\"\nimport { BranchId, type Participant } from \"./BranchProtocol.ts\"\nimport { BranchRpcs } from \"./BranchRpcs.ts\"\nimport * as BranchShare from \"./BranchShare.ts\"\nimport * as Admission from \"./internal/Admission.ts\"\nimport { SyncError } from \"./SyncError.ts\"\nimport * as SyncPrincipal from \"./SyncPrincipal.ts\"\n\n/**\n * Whether two roster emissions say the same thing.\n *\n * `list` returns participants sorted by id, so the comparison is positional.\n * The lease itself is part of the key: a heartbeat that only extends a lease\n * IS a change the watcher wants, because it is the evidence the participant is\n * still there.\n *\n * The rendering is JSON rather than delimiter-joined fields. Participant ids\n * and display names are `NonEmptyString` with no charset constraint, so every\n * separator is a character they may carry, including the control bytes this\n * used to join on. Two rosters differing only in where a field boundary falls\n * then rendered identically and a watcher never observed the change. JSON\n * quotes and escapes each field, so distinct rosters render distinctly.\n */\nconst rosterKey = (participants: ReadonlyArray<Participant>): string =>\n JSON.stringify(\n participants.map((participant) => [\n participant.participantId,\n participant.displayName,\n participant.sessionId,\n participant.kind,\n participant.where,\n participant.watching,\n participant.for_member,\n participant.leaseExpiresAtMs,\n participant.cursor === null ? null : [participant.cursor.cardId, participant.cursor.offset]\n ])\n )\n\nconst sameRoster = (\n left: ReadonlyArray<Participant>,\n right: ReadonlyArray<Participant>\n): boolean => rosterKey(left) === rosterKey(right)\n\n/**\n * Provides the branch RPC handlers over the branch services.\n *\n * With {@link BranchPresence.layerNoop}, roster reads and watches fail with\n * `unsupported`: unavailable presence cannot establish an empty roster.\n *\n * A roster watch emits the roster as of subscription, then re-lists on every\n * presence change for the branch AND at least once per second, emitting\n * only when the roster it read differs from the one it last sent.\n *\n * All three of those are triggers into ONE sequential reader. The roster is\n * mutable state behind an effect, so concurrent readers can complete out of\n * order, and a watcher that receives an older roster after a newer one keeps\n * the older one: `changesWith` compares against the previous emission, not\n * against the freshest state. Serializing the reads is what makes the last\n * value a watcher holds the most recent one that was read.\n *\n * The periodic re-list is what makes expiry observable. A lapsed lease\n * publishes nothing — the roster drops it the next time somebody lists — so a\n * watch driven by change events alone never saw the LAST participant leave,\n * and a burst of announcements on unrelated branches could slide the one\n * notification this watch needed out of the shared feed. Both are bounded by\n * one second: a departure is visible within 1 s of lease expiry,\n * whether or not a survivor reports it.\n *\n * @category layers\n * @since 0.1.0\n */\nexport const layerHandlers: Layer.Layer<\n Rpc.ToHandler<RpcGroup.Rpcs<typeof BranchRpcs>>,\n never,\n | BranchShare.BranchShare\n | BranchPresence.BranchPresence\n | BranchCommands.BranchCommands\n | BranchIds.BranchIds\n> = BranchRpcs.toLayer(\n Effect.gen(function*() {\n const share = yield* BranchShare.BranchShare\n const presence = yield* BranchPresence.BranchPresence\n const commands = yield* BranchCommands.BranchCommands\n const ids = yield* BranchIds.BranchIds\n\n return BranchRpcs.of({\n \"Branch.CreateBranch\": ({ ttlMs }) =>\n Effect.gen(function*() {\n const principal = yield* SyncPrincipal.SyncPrincipal\n if (!SyncPrincipal.isWorkspace(principal)) {\n return yield* new SyncError({\n code: \"unauthorized\",\n message: \"Creating a branch requires an authenticated workspace principal\"\n })\n }\n // Decoded, not branded: `BranchIds` is a host port whose `fresh` is\n // typed `Effect<string>`, so a host id source yielding \"\" turned an\n // asserted `BranchId` into a schema defect inside `mint` rather than\n // the `SyncError` this handler declares.\n const branchId = yield* Admission.decode(BranchId, yield* ids.fresh, \"invalid_request\")\n const capability = yield* share.mint({\n branchId,\n capabilityId: yield* ids.fresh,\n access: \"write\",\n ttlMs\n })\n return { branchId: capability.claims.branchId, capability }\n }),\n \"Branch.MintShare\": ({ capability, access, ttlMs }) =>\n Effect.gen(function*() {\n const claims = yield* share.verify(capability, {\n branchId: capability.claims.branchId,\n access: \"write\"\n })\n const capabilityId = yield* ids.fresh\n const nowMs = yield* Clock.currentTimeMillis\n // ID generation may outlast the parent. Refuse before minting, and\n // pass the absolute ceiling so the signing clock cannot extend it.\n if (nowMs >= claims.expiresAtMs) {\n return yield* new SyncError({\n code: \"unauthorized\",\n message: \"The share capability has expired\"\n })\n }\n // A link never outlives the capability it was minted from.\n return yield* share.mint({\n branchId: claims.branchId,\n capabilityId,\n access,\n ttlMs,\n maxExpiresAtMs: claims.expiresAtMs\n })\n }),\n \"Branch.Submit\": (payload) => commands.submit(payload),\n \"Branch.Announce\": (payload) => presence.announce(payload),\n \"Branch.Leave\": (payload) => Effect.as(presence.leave(payload), null),\n \"Branch.Roster\": (payload) => presence.list(payload),\n \"Branch.PresenceOn\": (payload) => presence.presenceOn(payload),\n \"Branch.WatchRoster\": (payload) =>\n Stream.merge(\n // The subscription's own snapshot is a TRIGGER like the other two,\n // not a fourth reader. Reading it here concurrently with them let\n // the roster a change produced overtake it: `presence.list` is an\n // effect against mutable state, three of them ran at once, and the\n // slowest one won the merge. `changesWith` compares an emission only\n // against the one before it, so the older roster passed the filter\n // and the watcher's LAST value said a participant who had already\n // left was still present, until the next change or lease tick.\n Stream.succeed(undefined),\n Stream.merge(\n presence.changes.pipe(\n Stream.filter((branchId) => branchId === payload.branchId),\n Stream.map(() => undefined)\n ),\n // A lapsed lease publishes nothing, so a watch driven only by\n // change events never observes the LAST participant leaving, and\n // an unrelated branch's burst can slide the one notification this\n // watch needed out of the shared feed. Re-listing at least once per second\n // bounds both: a departure is visible within 1 s of expiry, whether or not anyone reports it.\n Stream.fromEffectRepeat(Effect.sleep(Math.min(presence.leaseMs, 1_000))).pipe(Stream.map(() => undefined))\n )\n ).pipe(\n // ONE reader, sequential by default, so a roster is read in the\n // order its trigger arrived and every emission is at least as fresh\n // as the one before it.\n Stream.mapEffect(() => presence.list(payload)),\n // Deduplicated over the WHOLE stream, initial emission included.\n // Applied to the change half alone, its first value always passed,\n // so a change that left the roster identical still sent the watcher\n // a second copy of what it had just been given.\n Stream.changesWith(sameRoster),\n Stream.map((participants) => ({ participants }))\n )\n })\n })\n)\n"]}
1
+ {"version":3,"file":"BranchServer.js","sourceRoot":"","sources":["../../src/BranchServer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAIvC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAA;AACrD,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAA;AAC3C,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAA;AACrD,OAAO,EAAE,Q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QAClE,kEAAkE;QAClE,mEAAmE;QACnE,qEAAqE;QACrE,mEAAmE;QACnE,kEAAkE;QAClE,+DAA+D;QAC/D,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,EACzB,MAAM,CAAC,KAAK,CACV,QAAQ,CAAC,OAAO,CAAC,IAAI,CACnB,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,KAAK,OAAO,CAAC,QAAQ,CAAC,EAC1D,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAC5B;QACD,8DAA8D;QAC9D,iEAAiE;QACjE,kEAAkE;QAClE,2EAA2E;QAC3E,8FAA8F;QAC9F,MAAM,CAAC,gBAAgB,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC,CAC3G,CACF,CAAC,IAAI;QACJ,gEAAgE;QAChE,oEAAoE;QACpE,wBAAwB;QACxB,MAAM,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC9C,iEAAiE;QACjE,mEAAmE;QACnE,oEAAoE;QACpE,gDAAgD;QAChD,MAAM,CAAC,WAAW,CAAC,UAAU,CAAC,EAC9B,MAAM,CAAC,GAAG,CAAC,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,CAAC,CACjD;KACJ,CAAC,CAAA;AACJ,CAAC,CAAC,CACH,CAAA","sourcesContent":["/**\n * The server-side handlers of {@link BranchRpcs}: a thin projection of the\n * branch services onto the wire.\n *\n * Five procedures forward to the service that owns their boundary and add\n * nothing: `Branch.Submit` to {@link BranchCommands}, and `Branch.Announce`,\n * `Branch.Leave`, `Branch.Roster`, and `Branch.WatchRoster` to\n * {@link BranchPresence}. Two enforce policy here, on top of what\n * {@link BranchShare} checks: `Branch.CreateBranch` refuses any principal that\n * is not an authenticated workspace, and `Branch.MintShare` verifies write\n * access, refuses an expired parent, and caps the child at the parent's\n * expiry. `BranchShare.mint` performs none of those checks, so an in-process\n * host that mints through the service directly must gate the principal and\n * the parent capability itself.\n *\n * @since 0.1.0\n */\n\nimport * as Clock from \"effect/Clock\"\nimport * as Effect from \"effect/Effect\"\nimport type * as Layer from \"effect/Layer\"\nimport type * as Rpc from \"effect/rpc/Rpc\"\nimport type * as RpcGroup from \"effect/rpc/RpcGroup\"\nimport * as Stream from \"effect/Stream\"\nimport * as BranchCommands from \"./BranchCommands.ts\"\nimport * as BranchIds from \"./BranchIds.ts\"\nimport * as BranchPresence from \"./BranchPresence.ts\"\nimport { BranchId, type Participant } from \"./BranchProtocol.ts\"\nimport { BranchRpcs } from \"./BranchRpcs.ts\"\nimport * as BranchShare from \"./BranchShare.ts\"\nimport * as Admission from \"./internal/Admission.ts\"\nimport { SyncError } from \"./SyncError.ts\"\nimport * as SyncPrincipal from \"./SyncPrincipal.ts\"\n\n/**\n * Whether two roster emissions say the same thing.\n *\n * `list` returns participants sorted by id, so the comparison is positional.\n * The lease itself is part of the key: a heartbeat that only extends a lease\n * IS a change the watcher wants, because it is the evidence the participant is\n * still there.\n *\n * The rendering is JSON rather than delimiter-joined fields. Participant ids\n * and display names are `NonEmptyString` with no charset constraint, so every\n * separator is a character they may carry, including the control bytes this\n * used to join on. Two rosters differing only in where a field boundary falls\n * then rendered identically and a watcher never observed the change. JSON\n * quotes and escapes each field, so distinct rosters render distinctly.\n */\nconst rosterKey = (participants: ReadonlyArray<Participant>): string =>\n JSON.stringify(\n participants.map((participant) => [\n participant.participantId,\n participant.displayName,\n participant.sessionId,\n participant.kind,\n participant.where,\n participant.watching,\n participant.for_member,\n participant.leaseExpiresAtMs,\n participant.cursor === null ? null : [participant.cursor.cardId, participant.cursor.offset]\n ])\n )\n\nconst sameRoster = (\n left: ReadonlyArray<Participant>,\n right: ReadonlyArray<Participant>\n): boolean => rosterKey(left) === rosterKey(right)\n\n/**\n * Provides the branch RPC handlers over the branch services.\n *\n * With {@link BranchPresence.layerNoop}, roster reads and watches fail with\n * `unsupported`: unavailable presence cannot establish an empty roster.\n *\n * A roster watch emits the roster as of subscription, then re-lists on every\n * presence change for the branch AND at least once per second, emitting\n * only when the roster it read differs from the one it last sent.\n *\n * All three of those are triggers into ONE sequential reader. The roster is\n * mutable state behind an effect, so concurrent readers can complete out of\n * order, and a watcher that receives an older roster after a newer one keeps\n * the older one: `changesWith` compares against the previous emission, not\n * against the freshest state. Serializing the reads is what makes the last\n * value a watcher holds the most recent one that was read.\n *\n * The periodic re-list is what makes expiry observable. A lapsed lease\n * publishes nothing — the roster drops it the next time somebody lists — so a\n * watch driven by change events alone never saw the LAST participant leave,\n * and a burst of announcements on unrelated branches could slide the one\n * notification this watch needed out of the shared feed. Both are bounded by\n * one second: a departure is visible within 1 s of lease expiry,\n * whether or not a survivor reports it.\n *\n * @category layers\n * @since 0.1.0\n */\nexport const layerHandlers: Layer.Layer<\n Rpc.ToHandler<RpcGroup.Rpcs<typeof BranchRpcs>>,\n never,\n | BranchShare.BranchShare\n | BranchPresence.BranchPresence\n | BranchCommands.BranchCommands\n | BranchIds.BranchIds\n> = BranchRpcs.toLayer(\n Effect.gen(function*() {\n const share = yield* BranchShare.BranchShare\n const presence = yield* BranchPresence.BranchPresence\n const commands = yield* BranchCommands.BranchCommands\n const ids = yield* BranchIds.BranchIds\n\n return BranchRpcs.of({\n \"Branch.CreateBranch\": ({ ttlMs }) =>\n Effect.gen(function*() {\n const principal = yield* SyncPrincipal.SyncPrincipal\n if (!SyncPrincipal.isWorkspace(principal)) {\n return yield* new SyncError({\n code: \"unauthorized\",\n message: \"Creating a branch requires an authenticated workspace principal\"\n })\n }\n // Decoded, not branded: `BranchIds` is a host port whose `fresh` is\n // typed `Effect<string>`, so a host id source yielding \"\" turned an\n // asserted `BranchId` into a schema defect inside `mint` rather than\n // the `SyncError` this handler declares.\n const branchId = yield* Admission.decode(BranchId, yield* ids.fresh, \"invalid_request\")\n const capability = yield* share.mint({\n branchId,\n capabilityId: yield* ids.fresh,\n access: \"write\",\n ttlMs\n })\n return { branchId: capability.claims.branchId, capability }\n }),\n \"Branch.MintShare\": ({ capability, access, ttlMs }) =>\n Effect.gen(function*() {\n const claims = yield* share.verify(capability, {\n branchId: capability.claims.branchId,\n access: \"write\"\n })\n const capabilityId = yield* ids.fresh\n const nowMs = yield* Clock.currentTimeMillis\n // ID generation may outlast the parent. Refuse before minting, and\n // pass the absolute ceiling so the signing clock cannot extend it.\n if (nowMs >= claims.expiresAtMs) {\n return yield* new SyncError({\n code: \"unauthorized\",\n message: \"The share capability has expired\"\n })\n }\n // A link never outlives the capability it was minted from.\n return yield* share.mint({\n branchId: claims.branchId,\n capabilityId,\n access,\n ttlMs,\n maxExpiresAtMs: claims.expiresAtMs\n })\n }),\n \"Branch.Submit\": (payload) => commands.submit(payload),\n \"Branch.Announce\": (payload) => presence.announce(payload),\n \"Branch.Leave\": (payload) => Effect.as(presence.leave(payload), null),\n \"Branch.Roster\": (payload) => presence.list(payload),\n \"Branch.PresenceOn\": (payload) => presence.presenceOn(payload),\n \"Branch.WatchRoster\": (payload) =>\n Stream.merge(\n // The subscription's own snapshot is a TRIGGER like the other two,\n // not a fourth reader. Reading it here concurrently with them let\n // the roster a change produced overtake it: `presence.list` is an\n // effect against mutable state, three of them ran at once, and the\n // slowest one won the merge. `changesWith` compares an emission only\n // against the one before it, so the older roster passed the filter\n // and the watcher's LAST value said a participant who had already\n // left was still present, until the next change or lease tick.\n Stream.succeed(undefined),\n Stream.merge(\n presence.changes.pipe(\n Stream.filter((branchId) => branchId === payload.branchId),\n Stream.map(() => undefined)\n ),\n // A lapsed lease publishes nothing, so a watch driven only by\n // change events never observes the LAST participant leaving, and\n // an unrelated branch's burst can slide the one notification this\n // watch needed out of the shared feed. Re-listing at least once per second\n // bounds both: a departure is visible within 1 s of expiry, whether or not anyone reports it.\n Stream.fromEffectRepeat(Effect.sleep(Math.min(presence.leaseMs, 1_000))).pipe(Stream.map(() => undefined))\n )\n ).pipe(\n // ONE reader, sequential by default, so a roster is read in the\n // order its trigger arrived and every emission is at least as fresh\n // as the one before it.\n Stream.mapEffect(() => presence.list(payload)),\n // Deduplicated over the WHOLE stream, initial emission included.\n // Applied to the change half alone, its first value always passed,\n // so a change that left the roster identical still sent the watcher\n // a second copy of what it had just been given.\n Stream.changesWith(sameRoster),\n Stream.map((participants) => ({ participants }))\n )\n })\n })\n)\n"]}
@@ -21,7 +21,7 @@
21
21
  */
22
22
  import * as Effect from "effect/Effect";
23
23
  import * as Layer from "effect/Layer";
24
- import * as RpcMiddleware from "effect/unstable/rpc/RpcMiddleware";
24
+ import * as RpcMiddleware from "effect/rpc/RpcMiddleware";
25
25
  import { SyncError } from "./SyncError.ts";
26
26
  import { SyncAuth } from "./SyncRpcs.ts";
27
27
  import * as WorkspaceShare from "./WorkspaceShare.ts";
@@ -1 +1 @@
1
- {"version":3,"file":"SyncAuth.d.ts","sourceRoot":"","sources":["../../src/SyncAuth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAIrC,OAAO,KAAK,aAAa,MAAM,mCAAmC,CAAA;AAGlE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE1C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAA;AAErD;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,yBAAyB,CAAA;AAItD;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,GAC3B,YAAY,cAAc,CAAC,mBAAmB,KAC7C,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,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K,CAAC,QAAQ,EAAE,KAAK,EAAE,cAAc,CAAC,cAAc,CAyB7E,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,GACtB,YAAY,cAAc,CAAC,mBAAmB,KAC7C,KAAK,CAAC,KAAK,CAAC,aAAa,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,SAAS,CAKxD,CAAA"}
@@ -20,12 +20,12 @@
20
20
  * @since 0.1.0
21
21
  */
22
22
  import * as Effect from "effect/Effect";
23
- import * as Encoding from "effect/Encoding";
23
+ import * as Base64Url from "effect/encoding/Base64Url";
24
+ import * as Headers from "effect/http/Headers";
24
25
  import * as Layer from "effect/Layer";
25
26
  import * as Result from "effect/Result";
27
+ import * as RpcMiddleware from "effect/rpc/RpcMiddleware";
26
28
  import * as Schema from "effect/Schema";
27
- import * as Headers from "effect/unstable/http/Headers";
28
- import * as RpcMiddleware from "effect/unstable/rpc/RpcMiddleware";
29
29
  import { causeText } from "./internal/CauseText.js";
30
30
  import * as shareSigner from "./internal/ShareSigner.js";
31
31
  import { SyncError } from "./SyncError.js";
@@ -57,7 +57,7 @@ export const encodeCapability = (capability) => {
57
57
  // carries the value it rejected, and the value here is a credential.
58
58
  cause: causeText(encoded.failure)
59
59
  }))
60
- : Effect.succeed(Encoding.encodeBase64Url(JSON.stringify(encoded.success)));
60
+ : Effect.succeed(Base64Url.encode(JSON.stringify(encoded.success)));
61
61
  };
62
62
  /**
63
63
  * Decodes a capability header value. Every malformation folds to the same
@@ -67,7 +67,7 @@ export const encodeCapability = (capability) => {
67
67
  * @since 0.1.0
68
68
  */
69
69
  export const decodeCapability = (value) => {
70
- const text = Encoding.decodeBase64UrlString(value);
70
+ const text = Base64Url.decodeString(value);
71
71
  if (Result.isFailure(text)) {
72
72
  return Effect.fail(denied("The workspace capability header is not a capability"));
73
73
  }
@@ -1 +1 @@
1
- {"version":3,"file":"SyncAuth.js","sourceRoot":"","sources":["../../src/SyncAuth.ts"],"names":[],"mappings":"AAAA;;;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` RPC middleware.\n *\n * A connection presents a {@link WorkspaceShare.WorkspaceCapability} in the\n * {@link capabilityHeader} request header. {@link layer} verifies it against\n * the workspace's {@link WorkspaceShare.WorkspaceShare} authority and runs\n * the handler as the workspace principal. A request with no header runs as\n * the anonymous principal — branch share capabilities carried in request\n * payloads still authorize branch reads — and the server refuses anonymous\n * access to every non-branch run. A request whose header is present but\n * malformed, forged, expired, or signed by an unknown key is refused\n * outright: presence of a credential is a claim, and a false claim is never\n * downgraded to anonymity.\n *\n * There is deliberately no trusted pass-through implementation here: the only\n * sanctioned bypass is an in-process caller providing `SyncPrincipal` itself,\n * never a transport.\n *\n * @since 0.1.0\n */\n\nimport * as Effect from \"effect/Effect\"\nimport * as Encoding from \"effect/Encoding\"\nimport * as Layer from \"effect/Layer\"\nimport * as Result from \"effect/Result\"\nimport * as Schema from \"effect/Schema\"\nimport * as Headers from \"effect/unstable/http/Headers\"\nimport * as RpcMiddleware from \"effect/unstable/rpc/RpcMiddleware\"\nimport { causeText } from \"./internal/CauseText.ts\"\nimport * as shareSigner from \"./internal/ShareSigner.ts\"\nimport { SyncError } from \"./SyncError.ts\"\nimport * as SyncPrincipal from \"./SyncPrincipal.ts\"\nimport { SyncAuth } from \"./SyncRpcs.ts\"\nimport * as WorkspaceShare from \"./WorkspaceShare.ts\"\n\n/**\n * The request header a connection presents its workspace capability in.\n *\n * @category constants\n * @since 0.1.0\n */\nexport const capabilityHeader = \"flows-sync-workspace\"\n\nconst denied = shareSigner.unauthorized\n\n/**\n * Renders a workspace capability as its header value: unpadded base64url of\n * the schema-encoded capability JSON.\n *\n * @category encoding\n * @since 0.1.0\n */\nexport const encodeCapability = (\n capability: WorkspaceShare.WorkspaceCapability\n): Effect.Effect<string, SyncError> => {\n const encoded = Schema.encodeUnknownResult(WorkspaceShare.WorkspaceCapability)(capability)\n return Result.isFailure(encoded)\n ? Effect.fail(\n new SyncError({\n code: \"invalid_request\",\n message: \"The workspace capability does not encode\",\n // The rendering, never the parse failure itself: a schema issue\n // carries the value it rejected, and the value here is a credential.\n cause: causeText(encoded.failure)\n })\n )\n : Effect.succeed(Encoding.encodeBase64Url(JSON.stringify(encoded.success)))\n}\n\n/**\n * Decodes a capability header value. Every malformation folds to the same\n * `unauthorized` refusal so the header is not a parsing oracle.\n *\n * @category encoding\n * @since 0.1.0\n */\nexport const decodeCapability = (value: string): Effect.Effect<WorkspaceShare.WorkspaceCapability, SyncError> => {\n const text = Encoding.decodeBase64UrlString(value)\n if (Result.isFailure(text)) {\n return Effect.fail(denied(\"The workspace capability header is not a capability\"))\n }\n let parsed: unknown\n try {\n parsed = JSON.parse(text.success)\n } catch {\n return Effect.fail(denied(\"The workspace capability header is not a capability\"))\n }\n const decoded = Schema.decodeUnknownResult(WorkspaceShare.WorkspaceCapability)(parsed)\n return Result.isFailure(decoded)\n ? Effect.fail(denied(\"The workspace capability header is not a capability\"))\n : Effect.succeed(decoded.success)\n}\n\n/**\n * Provides the workspace-capability authentication middleware: no header\n * runs the handler as anonymous, a verified header runs it as the workspace\n * principal, and anything else refuses the request. Verification faults\n * (Web Crypto failing) propagate as their own error rather than as a\n * refusal.\n *\n * @category layers\n * @since 0.1.0\n */\nexport const layer: Layer.Layer<SyncAuth, never, WorkspaceShare.WorkspaceShare> = Layer.effect(\n SyncAuth,\n Effect.gen(function*() {\n const share = yield* WorkspaceShare.WorkspaceShare\n const middleware: RpcMiddleware.RpcMiddleware<never, SyncError, never> = (effect, options) => {\n const header = Headers.get(options.headers, capabilityHeader)\n if (header._tag === \"None\") {\n return Effect.provideService(effect, SyncPrincipal.SyncPrincipal, SyncPrincipal.anonymous)\n }\n return decodeCapability(header.value).pipe(\n Effect.flatMap((capability) => share.verify(capability, { access: \"read\" })),\n Effect.flatMap((claims) =>\n Effect.provideService(\n effect,\n SyncPrincipal.SyncPrincipal,\n // The signed expiry travels WITH the identity. A handler that\n // opens a stream authorizes once; reducing the verified claims to\n // a capability id here left the stream with nothing to expire on.\n SyncPrincipal.workspace(claims.capabilityId, claims.expiresAtMs)\n )\n )\n )\n }\n return middleware\n })\n)\n\n/**\n * Stamps every outgoing request from a generated RPC client with the given\n * workspace capability.\n *\n * @category layers\n * @since 0.1.0\n */\nexport const layerClient = (\n capability: WorkspaceShare.WorkspaceCapability\n): Layer.Layer<RpcMiddleware.ForClient<SyncAuth>, SyncError> =>\n RpcMiddleware.layerClient(\n SyncAuth,\n Effect.map(encodeCapability(capability), (header) => ({ next, request }) =>\n next({ ...request, headers: Headers.set(request.headers, capabilityHeader, header) }))\n )\n"]}
1
+ {"version":3,"file":"SyncAuth.js","sourceRoot":"","sources":["../../src/SyncAuth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,SAAS,MAAM,2BAA2B,CAAA;AACtD,OAAO,KAAK,OAAO,MAAM,qBAAqB,CAAA;AAC9C,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,aAAa,MAAM,0BAA0B,CAAA;AACzD,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACnD,OAAO,KAAK,WAAW,MAAM,2BAA2B,CAAA;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAA;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAA;AAErD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,sBAAsB,CAAA;AAEtD,MAAM,MAAM,GAAG,WAAW,CAAC,YAAY,CAAA;AAEvC;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,UAA8C,EACZ,EAAE;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8C,EACa,EAAE,CAC7D,aAAa,CAAC,WAAW,CACvB,QAAQ,EACR,MAAM,CAAC,GAAG,CAAC,gBAAgB,CAAC,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,CACzE,IAAI,CAAC,EAAE,GAAG,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,EAAE,gBAAgB,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC,CACzF,CAAA","sourcesContent":["/**\n * The sync read path's connection authentication: implementations of the\n * `SyncRpcs.SyncAuth` RPC middleware.\n *\n * A connection presents a {@link WorkspaceShare.WorkspaceCapability} in the\n * {@link capabilityHeader} request header. {@link layer} verifies it against\n * the workspace's {@link WorkspaceShare.WorkspaceShare} authority and runs\n * the handler as the workspace principal. A request with no header runs as\n * the anonymous principal — branch share capabilities carried in request\n * payloads still authorize branch reads — and the server refuses anonymous\n * access to every non-branch run. A request whose header is present but\n * malformed, forged, expired, or signed by an unknown key is refused\n * outright: presence of a credential is a claim, and a false claim is never\n * downgraded to anonymity.\n *\n * There is deliberately no trusted pass-through implementation here: the only\n * sanctioned bypass is an in-process caller providing `SyncPrincipal` itself,\n * never a transport.\n *\n * @since 0.1.0\n */\n\nimport * as Effect from \"effect/Effect\"\nimport * as Base64Url from \"effect/encoding/Base64Url\"\nimport * as Headers from \"effect/http/Headers\"\nimport * as Layer from \"effect/Layer\"\nimport * as Result from \"effect/Result\"\nimport * as RpcMiddleware from \"effect/rpc/RpcMiddleware\"\nimport * as Schema from \"effect/Schema\"\nimport { causeText } from \"./internal/CauseText.ts\"\nimport * as shareSigner from \"./internal/ShareSigner.ts\"\nimport { SyncError } from \"./SyncError.ts\"\nimport * as SyncPrincipal from \"./SyncPrincipal.ts\"\nimport { SyncAuth } from \"./SyncRpcs.ts\"\nimport * as WorkspaceShare from \"./WorkspaceShare.ts\"\n\n/**\n * The request header a connection presents its workspace capability in.\n *\n * @category constants\n * @since 0.1.0\n */\nexport const capabilityHeader = \"flows-sync-workspace\"\n\nconst denied = shareSigner.unauthorized\n\n/**\n * Renders a workspace capability as its header value: unpadded base64url of\n * the schema-encoded capability JSON.\n *\n * @category encoding\n * @since 0.1.0\n */\nexport const encodeCapability = (\n capability: WorkspaceShare.WorkspaceCapability\n): Effect.Effect<string, SyncError> => {\n const encoded = Schema.encodeUnknownResult(WorkspaceShare.WorkspaceCapability)(capability)\n return Result.isFailure(encoded)\n ? Effect.fail(\n new SyncError({\n code: \"invalid_request\",\n message: \"The workspace capability does not encode\",\n // The rendering, never the parse failure itself: a schema issue\n // carries the value it rejected, and the value here is a credential.\n cause: causeText(encoded.failure)\n })\n )\n : Effect.succeed(Base64Url.encode(JSON.stringify(encoded.success)))\n}\n\n/**\n * Decodes a capability header value. Every malformation folds to the same\n * `unauthorized` refusal so the header is not a parsing oracle.\n *\n * @category encoding\n * @since 0.1.0\n */\nexport const decodeCapability = (value: string): Effect.Effect<WorkspaceShare.WorkspaceCapability, SyncError> => {\n const text = Base64Url.decodeString(value)\n if (Result.isFailure(text)) {\n return Effect.fail(denied(\"The workspace capability header is not a capability\"))\n }\n let parsed: unknown\n try {\n parsed = JSON.parse(text.success)\n } catch {\n return Effect.fail(denied(\"The workspace capability header is not a capability\"))\n }\n const decoded = Schema.decodeUnknownResult(WorkspaceShare.WorkspaceCapability)(parsed)\n return Result.isFailure(decoded)\n ? Effect.fail(denied(\"The workspace capability header is not a capability\"))\n : Effect.succeed(decoded.success)\n}\n\n/**\n * Provides the workspace-capability authentication middleware: no header\n * runs the handler as anonymous, a verified header runs it as the workspace\n * principal, and anything else refuses the request. Verification faults\n * (Web Crypto failing) propagate as their own error rather than as a\n * refusal.\n *\n * @category layers\n * @since 0.1.0\n */\nexport const layer: Layer.Layer<SyncAuth, never, WorkspaceShare.WorkspaceShare> = Layer.effect(\n SyncAuth,\n Effect.gen(function*() {\n const share = yield* WorkspaceShare.WorkspaceShare\n const middleware: RpcMiddleware.RpcMiddleware<never, SyncError, never> = (effect, options) => {\n const header = Headers.get(options.headers, capabilityHeader)\n if (header._tag === \"None\") {\n return Effect.provideService(effect, SyncPrincipal.SyncPrincipal, SyncPrincipal.anonymous)\n }\n return decodeCapability(header.value).pipe(\n Effect.flatMap((capability) => share.verify(capability, { access: \"read\" })),\n Effect.flatMap((claims) =>\n Effect.provideService(\n effect,\n SyncPrincipal.SyncPrincipal,\n // The signed expiry travels WITH the identity. A handler that\n // opens a stream authorizes once; reducing the verified claims to\n // a capability id here left the stream with nothing to expire on.\n SyncPrincipal.workspace(claims.capabilityId, claims.expiresAtMs)\n )\n )\n )\n }\n return middleware\n })\n)\n\n/**\n * Stamps every outgoing request from a generated RPC client with the given\n * workspace capability.\n *\n * @category layers\n * @since 0.1.0\n */\nexport const layerClient = (\n capability: WorkspaceShare.WorkspaceCapability\n): Layer.Layer<RpcMiddleware.ForClient<SyncAuth>, SyncError> =>\n RpcMiddleware.layerClient(\n SyncAuth,\n Effect.map(encodeCapability(capability), (header) => ({ next, request }) =>\n next({ ...request, headers: Headers.set(request.headers, capabilityHeader, header) }))\n )\n"]}
@@ -7,10 +7,10 @@ import type * as JournalEvent from "@smthrs/journal/JournalEvent";
7
7
  import * as Context from "effect/Context";
8
8
  import * as Effect from "effect/Effect";
9
9
  import * as Layer from "effect/Layer";
10
+ import * as RpcClient from "effect/rpc/RpcClient";
11
+ import * as RpcClientError from "effect/rpc/RpcClientError";
12
+ import type * as RpcGroup from "effect/rpc/RpcGroup";
10
13
  import * as Stream from "effect/Stream";
11
- import * as RpcClient from "effect/unstable/rpc/RpcClient";
12
- import * as RpcClientError from "effect/unstable/rpc/RpcClientError";
13
- import type * as RpcGroup from "effect/unstable/rpc/RpcGroup";
14
14
  import type { ShareCapability } from "./BranchProtocol.ts";
15
15
  import { SyncError, SyncGapError } from "./SyncError.ts";
16
16
  import { type Progress, type Resync, RunCursor, type Scope, type Snapshot, type SnapshotRequest,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AAEJ;;;;;GAKG;AACH,eAAO,MAAM,SAAS,GAAI,YAAW,OAAO,CAAC,OAAO,CAAM,KAAG,KAAK,CAAC,KAAK,CAAC,UAAU,CACnC,CAAA;AAEhD,KAAK,MAAM,GAAG,SAAS,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,QAAQ,CAAC,EAAE,cAAc,CAAC,cAAc,CAAC,CAAA;AA2LhG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,eAAO,MAAM,IAAI,GAAI,YAAY;IAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,KAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAA8B,CAAA;AAElH;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,QAAQ,GAAI,2CAItB,OAAO,GAAG;IAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,KAAG,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,SAAS,CAYxE,CAAA;AAkXH;;;;;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"}
@@ -8,11 +8,11 @@ import * as Context from "effect/Context";
8
8
  import * as Effect from "effect/Effect";
9
9
  import * as Layer from "effect/Layer";
10
10
  import * as Ref from "effect/Ref";
11
+ import * as RpcClient from "effect/rpc/RpcClient";
12
+ import * as RpcClientError from "effect/rpc/RpcClientError";
11
13
  import * as Schedule from "effect/Schedule";
12
14
  import * as Schema from "effect/Schema";
13
15
  import * as Stream from "effect/Stream";
14
- import * as RpcClient from "effect/unstable/rpc/RpcClient";
15
- import * as RpcClientError from "effect/unstable/rpc/RpcClientError";
16
16
  import * as Admission from "./internal/Admission.js";
17
17
  import { boundedText, causeCode, causeText } from "./internal/CauseText.js";
18
18
  import { boundedInt, positiveInt } from "./internal/PolicyOptions.js";
@@ -1 +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,MAAM,YAAY,CAAA;AACjC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAC3C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,SAAS,MAAM,+BAA+B,CAAA;AAC1D,OAAO,KAAK,cAAc,MAAM,oCAAoC,CAAA;AAGpE,OAAO,KAAK,SAAS,MAAM,yBAAyB,CAAA;AACpD,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAC3E,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AACrE,OAAO,KAAK,gBAAgB,MAAM,gCAAgC,CAAA;AAClE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AACxD,OAAO,EACL,MAAM,EACN,oBAAoB,EACpB,oBAAoB,EACpB,iBAAiB,EAEjB,KAAK,EACL,YAAY,EACZ,kBAAkB,EAElB,eAAe,EACf,YAAY,EACZ,eAAe,EAEf,SAAS,EAKV,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAExC;;;;;;;;;;;;;;;GAeG;AACH,M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 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"]}
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,MAAM,YAAY,CAAA;AACjC,OAAO,KAAK,SAAS,MAAM,sBAAsB,CAAA;AACjD,OAAO,KAAK,cAAc,MAAM,2BAA2B,CAAA;AAE3D,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAC3C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,SAAS,MAAM,yBAAyB,CAAA;AACpD,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAC3E,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AACrE,OAAO,KAAK,gBAAgB,MAAM,gCAAgC,CAAA;AAClE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM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AgB,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 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 — 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"]}
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * @since 0.1.0
5
5
  */
6
- import { Rpc, RpcGroup, RpcMiddleware } from "effect/unstable/rpc";
6
+ import { Rpc, RpcGroup, RpcMiddleware } from "effect/rpc";
7
7
  import { SyncError } from "./SyncError.ts";
8
8
  declare const SyncAuth_base: RpcMiddleware.ServiceClass<SyncAuth, "@smthrs/sync/SyncAuth", never, typeof SyncError, never, never, false>;
9
9
  /**
@@ -79,7 +79,7 @@ export declare const SyncRpcs: RpcGroup.RpcGroup<Rpc.Rpc<"Sync.Snapshot", import
79
79
  }>>;
80
80
  readonly credit: import("effect/Schema").Int;
81
81
  readonly capability: import("effect/Schema").optional<typeof import("./BranchProtocol.ts").ShareCapability>;
82
- }>, import("effect/unstable/rpc/RpcSchema").Stream<import("effect/Schema").Union<readonly [import("effect/Schema").TaggedStruct<"Entries", {
82
+ }>, import("effect/rpc/RpcSchema").Stream<import("effect/Schema").Union<readonly [import("effect/Schema").TaggedStruct<"Entries", {
83
83
  readonly runId: import("effect/Schema").brand<import("effect/Schema").String, "@smthrs/journal/JournalEvent/RunId">;
84
84
  readonly generation: import("effect/Schema").optional<import("effect/Schema").Int>;
85
85
  readonly fromSeq: import("effect/Schema").brand<import("effect/Schema").Int, "@smthrs/journal/JournalEvent/Seq">;
@@ -1 +1 @@
1
- {"version":3,"file":"SyncRpcs.d.ts","sourceRoot":"","sources":["../../src/SyncRpcs.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAClE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;;AAG1C;;;;;;;;;;;;GAYG;AACH,qBAAa,QAAS,SAAQ,aAAgF;CAAG;AAEjH;;;;;;;;;GASG;AACH,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gFAIC,CAAA"}
1
+ {"version":3,"file":"SyncRpcs.d.ts","sourceRoot":"","sources":["../../src/SyncRpcs.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;;AAG1C;;;;;;;;;;;;GAYG;AACH,qBAAa,QAAS,SAAQ,aAAgF;CAAG;AAEjH;;;;;;;;;GASG;AACH,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gFAIC,CAAA"}
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * @since 0.1.0
5
5
  */
6
- import { Rpc, RpcGroup, RpcMiddleware } from "effect/unstable/rpc";
6
+ import { Rpc, RpcGroup, RpcMiddleware } from "effect/rpc";
7
7
  import { SyncError } from "./SyncError.js";
8
8
  import { Frame, ReadRequest, ReadResponse, Snapshot, SnapshotRequest, SubscribeRequest } from "./SyncProtocol.js";
9
9
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"SyncRpcs.js","sourceRoot":"","sources":["../../src/SyncRpcs.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAClE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAEjH;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,QAAS,SAAQ,aAAa,CAAC,OAAO,EAAY,CAAC,uBAAuB,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;CAAG;AAEjH;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,QAAQ,CAAC,IAAI,CACnC,GAAG,CAAC,IAAI,CAAC,eAAe,EAAE,EAAE,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,EAC5F,GAAG,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,EACxF,GAAG,CAAC,IAAI,CAAC,gBAAgB,EAAE,EAAE,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAC1G,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAA","sourcesContent":["/**\n * Schema-backed RPC projection of the sync read path.\n *\n * @since 0.1.0\n */\n\nimport { Rpc, RpcGroup, RpcMiddleware } from \"effect/unstable/rpc\"\nimport { SyncError } from \"./SyncError.ts\"\nimport { Frame, ReadRequest, ReadResponse, Snapshot, SnapshotRequest, SubscribeRequest } from \"./SyncProtocol.ts\"\n\n/**\n * Authentication boundary for the sync RPC group.\n *\n * The middleware authenticates each request to a `SyncPrincipal` before the\n * handler runs. The production implementation is `SyncAuth.layer`, which\n * verifies the workspace capability presented in the request headers and\n * installs the resulting principal; a request without a credential runs as\n * the anonymous principal, which the server refuses for every non-branch\n * read.\n *\n * @category middleware\n * @since 0.1.0\n */\nexport class SyncAuth extends RpcMiddleware.Service<SyncAuth>()(\"@smthrs/sync/SyncAuth\", { error: SyncError }) {}\n\n/**\n * The remote procedures of the sync read path.\n *\n * A subscription's `credit` is a hard frame limit. Clients reconnect with\n * their materialized cursor to replenish it; there is no separate\n * acknowledgement channel.\n *\n * @category groups\n * @since 0.1.0\n */\nexport const SyncRpcs = RpcGroup.make(\n Rpc.make(\"Sync.Snapshot\", { payload: SnapshotRequest, success: Snapshot, error: SyncError }),\n Rpc.make(\"Sync.Read\", { payload: ReadRequest, success: ReadResponse, error: SyncError }),\n Rpc.make(\"Sync.Subscribe\", { payload: SubscribeRequest, success: Frame, error: SyncError, stream: true })\n).middleware(SyncAuth)\n"]}
1
+ {"version":3,"file":"SyncRpcs.js","sourceRoot":"","sources":["../../src/SyncRpcs.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAEjH;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,QAAS,SAAQ,aAAa,CAAC,OAAO,EAAY,CAAC,uBAAuB,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;CAAG;AAEjH;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,QAAQ,CAAC,IAAI,CACnC,GAAG,CAAC,IAAI,CAAC,eAAe,EAAE,EAAE,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,EAC5F,GAAG,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,EACxF,GAAG,CAAC,IAAI,CAAC,gBAAgB,EAAE,EAAE,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAC1G,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAA","sourcesContent":["/**\n * Schema-backed RPC projection of the sync read path.\n *\n * @since 0.1.0\n */\n\nimport { Rpc, RpcGroup, RpcMiddleware } from \"effect/rpc\"\nimport { SyncError } from \"./SyncError.ts\"\nimport { Frame, ReadRequest, ReadResponse, Snapshot, SnapshotRequest, SubscribeRequest } from \"./SyncProtocol.ts\"\n\n/**\n * Authentication boundary for the sync RPC group.\n *\n * The middleware authenticates each request to a `SyncPrincipal` before the\n * handler runs. The production implementation is `SyncAuth.layer`, which\n * verifies the workspace capability presented in the request headers and\n * installs the resulting principal; a request without a credential runs as\n * the anonymous principal, which the server refuses for every non-branch\n * read.\n *\n * @category middleware\n * @since 0.1.0\n */\nexport class SyncAuth extends RpcMiddleware.Service<SyncAuth>()(\"@smthrs/sync/SyncAuth\", { error: SyncError }) {}\n\n/**\n * The remote procedures of the sync read path.\n *\n * A subscription's `credit` is a hard frame limit. Clients reconnect with\n * their materialized cursor to replenish it; there is no separate\n * acknowledgement channel.\n *\n * @category groups\n * @since 0.1.0\n */\nexport const SyncRpcs = RpcGroup.make(\n Rpc.make(\"Sync.Snapshot\", { payload: SnapshotRequest, success: Snapshot, error: SyncError }),\n Rpc.make(\"Sync.Read\", { payload: ReadRequest, success: ReadResponse, error: SyncError }),\n Rpc.make(\"Sync.Subscribe\", { payload: SubscribeRequest, success: Frame, error: SyncError, stream: true })\n).middleware(SyncAuth)\n"]}
@@ -7,9 +7,9 @@ import { Journal } from "@smthrs/journal";
7
7
  import * as Context from "effect/Context";
8
8
  import * as Effect from "effect/Effect";
9
9
  import * as Layer from "effect/Layer";
10
+ import type * as Rpc from "effect/rpc/Rpc";
11
+ import type * as RpcGroup from "effect/rpc/RpcGroup";
10
12
  import * as Stream from "effect/Stream";
11
- import type * as Rpc from "effect/unstable/rpc/Rpc";
12
- import type * as RpcGroup from "effect/unstable/rpc/RpcGroup";
13
13
  import * as RunCatalog from "./RunCatalog.ts";
14
14
  import { SyncError } from "./SyncError.ts";
15
15
  import * as SyncProtocol from "./SyncProtocol.ts";
@@ -1 +1 @@
1
- {"version":3,"file":"SyncServer.d.ts","sourceRoot":"","sources":["../../src/SyncServer.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AAIzC,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAGrC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,GAAG,MAAM,yBAAyB,CAAA;AACnD,OAAO,KAAK,KAAK,QAAQ,MAAM,8BAA8B,CAAA;AAS7D,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAA;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE1C,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAExC;;;;;GAKG;AACH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