@smthrs/sync 0.0.0-stage → 1.0.0-rc.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (266) hide show
  1. package/CHANGELOG.md +208 -0
  2. package/LICENSE +21 -0
  3. package/README.md +208 -2
  4. package/dist/cjs/BranchCommands.d.ts +228 -0
  5. package/dist/cjs/BranchCommands.d.ts.map +1 -0
  6. package/dist/cjs/BranchCommands.js +316 -0
  7. package/dist/cjs/BranchCommands.js.map +7 -0
  8. package/dist/cjs/BranchIds.d.ts +65 -0
  9. package/dist/cjs/BranchIds.d.ts.map +1 -0
  10. package/dist/cjs/BranchIds.js +53 -0
  11. package/dist/cjs/BranchIds.js.map +7 -0
  12. package/dist/cjs/BranchPresence.d.ts +195 -0
  13. package/dist/cjs/BranchPresence.d.ts.map +1 -0
  14. package/dist/cjs/BranchPresence.js +276 -0
  15. package/dist/cjs/BranchPresence.js.map +7 -0
  16. package/dist/cjs/BranchProjection.d.ts +179 -0
  17. package/dist/cjs/BranchProjection.d.ts.map +1 -0
  18. package/dist/cjs/BranchProjection.js +197 -0
  19. package/dist/cjs/BranchProjection.js.map +7 -0
  20. package/dist/cjs/BranchProtocol.d.ts +415 -0
  21. package/dist/cjs/BranchProtocol.d.ts.map +1 -0
  22. package/dist/cjs/BranchProtocol.js +172 -0
  23. package/dist/cjs/BranchProtocol.js.map +7 -0
  24. package/dist/cjs/BranchRpcs.d.ts +177 -0
  25. package/dist/cjs/BranchRpcs.d.ts.map +1 -0
  26. package/dist/cjs/BranchRpcs.js +85 -0
  27. package/dist/cjs/BranchRpcs.js.map +7 -0
  28. package/dist/cjs/BranchServer.d.ts +55 -0
  29. package/dist/cjs/BranchServer.d.ts.map +1 -0
  30. package/dist/cjs/BranchServer.js +147 -0
  31. package/dist/cjs/BranchServer.js.map +7 -0
  32. package/dist/cjs/BranchShare.d.ts +159 -0
  33. package/dist/cjs/BranchShare.d.ts.map +1 -0
  34. package/dist/cjs/BranchShare.js +147 -0
  35. package/dist/cjs/BranchShare.js.map +7 -0
  36. package/dist/cjs/RunCatalog.d.ts +207 -0
  37. package/dist/cjs/RunCatalog.d.ts.map +1 -0
  38. package/dist/cjs/RunCatalog.js +122 -0
  39. package/dist/cjs/RunCatalog.js.map +7 -0
  40. package/dist/cjs/SyncAuth.d.ts +70 -0
  41. package/dist/cjs/SyncAuth.d.ts.map +1 -0
  42. package/dist/cjs/SyncAuth.js +109 -0
  43. package/dist/cjs/SyncAuth.js.map +7 -0
  44. package/dist/cjs/SyncClient.d.ts +274 -0
  45. package/dist/cjs/SyncClient.d.ts.map +1 -0
  46. package/dist/cjs/SyncClient.js +474 -0
  47. package/dist/cjs/SyncClient.js.map +7 -0
  48. package/dist/cjs/SyncError.d.ts +107 -0
  49. package/dist/cjs/SyncError.d.ts.map +1 -0
  50. package/dist/cjs/SyncError.js +110 -0
  51. package/dist/cjs/SyncError.js.map +7 -0
  52. package/dist/cjs/SyncPrincipal.d.ts +100 -0
  53. package/dist/cjs/SyncPrincipal.d.ts.map +1 -0
  54. package/dist/cjs/SyncPrincipal.js +48 -0
  55. package/dist/cjs/SyncPrincipal.js.map +7 -0
  56. package/dist/cjs/SyncProtocol.d.ts +592 -0
  57. package/dist/cjs/SyncProtocol.d.ts.map +1 -0
  58. package/dist/cjs/SyncProtocol.js +165 -0
  59. package/dist/cjs/SyncProtocol.js.map +7 -0
  60. package/dist/cjs/SyncRpcs.d.ts +92 -0
  61. package/dist/cjs/SyncRpcs.d.ts.map +1 -0
  62. package/dist/cjs/SyncRpcs.js +35 -0
  63. package/dist/cjs/SyncRpcs.js.map +7 -0
  64. package/dist/cjs/SyncServer.d.ts +184 -0
  65. package/dist/cjs/SyncServer.d.ts.map +1 -0
  66. package/dist/cjs/SyncServer.js +513 -0
  67. package/dist/cjs/SyncServer.js.map +7 -0
  68. package/dist/cjs/WorkspaceShare.d.ts +174 -0
  69. package/dist/cjs/WorkspaceShare.d.ts.map +1 -0
  70. package/dist/cjs/WorkspaceShare.js +149 -0
  71. package/dist/cjs/WorkspaceShare.js.map +7 -0
  72. package/dist/cjs/index.d.ts +91 -0
  73. package/dist/cjs/index.d.ts.map +1 -0
  74. package/dist/cjs/index.js +67 -0
  75. package/dist/cjs/index.js.map +7 -0
  76. package/dist/cjs/internal/Admission.d.ts +43 -0
  77. package/dist/cjs/internal/Admission.d.ts.map +1 -0
  78. package/dist/cjs/internal/Admission.js +90 -0
  79. package/dist/cjs/internal/Admission.js.map +7 -0
  80. package/dist/cjs/internal/CauseText.d.ts +55 -0
  81. package/dist/cjs/internal/CauseText.d.ts.map +1 -0
  82. package/dist/cjs/internal/CauseText.js +38 -0
  83. package/dist/cjs/internal/CauseText.js.map +7 -0
  84. package/dist/cjs/internal/JournalErrorCode.d.ts +23 -0
  85. package/dist/cjs/internal/JournalErrorCode.d.ts.map +1 -0
  86. package/dist/cjs/internal/JournalErrorCode.js +34 -0
  87. package/dist/cjs/internal/JournalErrorCode.js.map +7 -0
  88. package/dist/cjs/internal/PolicyOptions.d.ts +57 -0
  89. package/dist/cjs/internal/PolicyOptions.d.ts.map +1 -0
  90. package/dist/cjs/internal/PolicyOptions.js +62 -0
  91. package/dist/cjs/internal/PolicyOptions.js.map +7 -0
  92. package/dist/cjs/internal/ProtocolVersion.d.ts +17 -0
  93. package/dist/cjs/internal/ProtocolVersion.d.ts.map +1 -0
  94. package/dist/cjs/internal/ProtocolVersion.js +44 -0
  95. package/dist/cjs/internal/ProtocolVersion.js.map +7 -0
  96. package/dist/cjs/internal/ShareSigner.d.ts +173 -0
  97. package/dist/cjs/internal/ShareSigner.d.ts.map +1 -0
  98. package/dist/cjs/internal/ShareSigner.js +150 -0
  99. package/dist/cjs/internal/ShareSigner.js.map +7 -0
  100. package/dist/cjs/internal/SnapshotBoundary.d.ts +17 -0
  101. package/dist/cjs/internal/SnapshotBoundary.d.ts.map +1 -0
  102. package/dist/cjs/internal/SnapshotBoundary.js +97 -0
  103. package/dist/cjs/internal/SnapshotBoundary.js.map +7 -0
  104. package/dist/cjs/package.json +1 -0
  105. package/dist/cjs/test/TestSocket.d.ts +55 -0
  106. package/dist/cjs/test/TestSocket.d.ts.map +1 -0
  107. package/dist/cjs/test/TestSocket.js +145 -0
  108. package/dist/cjs/test/TestSocket.js.map +7 -0
  109. package/dist/cjs/test/TestSync.d.ts +54 -0
  110. package/dist/cjs/test/TestSync.d.ts.map +1 -0
  111. package/dist/cjs/test/TestSync.js +96 -0
  112. package/dist/cjs/test/TestSync.js.map +7 -0
  113. package/dist/esm/BranchCommands.d.ts +228 -0
  114. package/dist/esm/BranchCommands.d.ts.map +1 -0
  115. package/dist/esm/BranchCommands.js +496 -0
  116. package/dist/esm/BranchCommands.js.map +1 -0
  117. package/dist/esm/BranchIds.d.ts +65 -0
  118. package/dist/esm/BranchIds.d.ts.map +1 -0
  119. package/dist/esm/BranchIds.js +61 -0
  120. package/dist/esm/BranchIds.js.map +1 -0
  121. package/dist/esm/BranchPresence.d.ts +195 -0
  122. package/dist/esm/BranchPresence.d.ts.map +1 -0
  123. package/dist/esm/BranchPresence.js +361 -0
  124. package/dist/esm/BranchPresence.js.map +1 -0
  125. package/dist/esm/BranchProjection.d.ts +179 -0
  126. package/dist/esm/BranchProjection.d.ts.map +1 -0
  127. package/dist/esm/BranchProjection.js +269 -0
  128. package/dist/esm/BranchProjection.js.map +1 -0
  129. package/dist/esm/BranchProtocol.d.ts +415 -0
  130. package/dist/esm/BranchProtocol.d.ts.map +1 -0
  131. package/dist/esm/BranchProtocol.js +323 -0
  132. package/dist/esm/BranchProtocol.js.map +1 -0
  133. package/dist/esm/BranchRpcs.d.ts +177 -0
  134. package/dist/esm/BranchRpcs.d.ts.map +1 -0
  135. package/dist/esm/BranchRpcs.js +103 -0
  136. package/dist/esm/BranchRpcs.js.map +1 -0
  137. package/dist/esm/BranchServer.d.ts +55 -0
  138. package/dist/esm/BranchServer.d.ts.map +1 -0
  139. package/dist/esm/BranchServer.js +168 -0
  140. package/dist/esm/BranchServer.js.map +1 -0
  141. package/dist/esm/BranchShare.d.ts +159 -0
  142. package/dist/esm/BranchShare.d.ts.map +1 -0
  143. package/dist/esm/BranchShare.js +213 -0
  144. package/dist/esm/BranchShare.js.map +1 -0
  145. package/dist/esm/RunCatalog.d.ts +207 -0
  146. package/dist/esm/RunCatalog.d.ts.map +1 -0
  147. package/dist/esm/RunCatalog.js +196 -0
  148. package/dist/esm/RunCatalog.js.map +1 -0
  149. package/dist/esm/SyncAuth.d.ts +70 -0
  150. package/dist/esm/SyncAuth.d.ts.map +1 -0
  151. package/dist/esm/SyncAuth.js +119 -0
  152. package/dist/esm/SyncAuth.js.map +1 -0
  153. package/dist/esm/SyncClient.d.ts +274 -0
  154. package/dist/esm/SyncClient.d.ts.map +1 -0
  155. package/dist/esm/SyncClient.js +586 -0
  156. package/dist/esm/SyncClient.js.map +1 -0
  157. package/dist/esm/SyncError.d.ts +107 -0
  158. package/dist/esm/SyncError.d.ts.map +1 -0
  159. package/dist/esm/SyncError.js +133 -0
  160. package/dist/esm/SyncError.js.map +1 -0
  161. package/dist/esm/SyncPrincipal.d.ts +100 -0
  162. package/dist/esm/SyncPrincipal.d.ts.map +1 -0
  163. package/dist/esm/SyncPrincipal.js +58 -0
  164. package/dist/esm/SyncPrincipal.js.map +1 -0
  165. package/dist/esm/SyncProtocol.d.ts +592 -0
  166. package/dist/esm/SyncProtocol.d.ts.map +1 -0
  167. package/dist/esm/SyncProtocol.js +434 -0
  168. package/dist/esm/SyncProtocol.js.map +1 -0
  169. package/dist/esm/SyncRpcs.d.ts +92 -0
  170. package/dist/esm/SyncRpcs.d.ts.map +1 -0
  171. package/dist/esm/SyncRpcs.js +35 -0
  172. package/dist/esm/SyncRpcs.js.map +1 -0
  173. package/dist/esm/SyncServer.d.ts +184 -0
  174. package/dist/esm/SyncServer.d.ts.map +1 -0
  175. package/dist/esm/SyncServer.js +897 -0
  176. package/dist/esm/SyncServer.js.map +1 -0
  177. package/dist/esm/WorkspaceShare.d.ts +174 -0
  178. package/dist/esm/WorkspaceShare.d.ts.map +1 -0
  179. package/dist/esm/WorkspaceShare.js +208 -0
  180. package/dist/esm/WorkspaceShare.js.map +1 -0
  181. package/dist/esm/index.d.ts +91 -0
  182. package/dist/esm/index.d.ts.map +1 -0
  183. package/dist/esm/index.js +91 -0
  184. package/dist/esm/index.js.map +1 -0
  185. package/dist/esm/internal/Admission.d.ts +43 -0
  186. package/dist/esm/internal/Admission.d.ts.map +1 -0
  187. package/dist/esm/internal/Admission.js +80 -0
  188. package/dist/esm/internal/Admission.js.map +1 -0
  189. package/dist/esm/internal/CauseText.d.ts +55 -0
  190. package/dist/esm/internal/CauseText.d.ts.map +1 -0
  191. package/dist/esm/internal/CauseText.js +67 -0
  192. package/dist/esm/internal/CauseText.js.map +1 -0
  193. package/dist/esm/internal/JournalErrorCode.d.ts +23 -0
  194. package/dist/esm/internal/JournalErrorCode.d.ts.map +1 -0
  195. package/dist/esm/internal/JournalErrorCode.js +44 -0
  196. package/dist/esm/internal/JournalErrorCode.js.map +1 -0
  197. package/dist/esm/internal/PolicyOptions.d.ts +57 -0
  198. package/dist/esm/internal/PolicyOptions.d.ts.map +1 -0
  199. package/dist/esm/internal/PolicyOptions.js +70 -0
  200. package/dist/esm/internal/PolicyOptions.js.map +1 -0
  201. package/dist/esm/internal/ProtocolVersion.d.ts +17 -0
  202. package/dist/esm/internal/ProtocolVersion.d.ts.map +1 -0
  203. package/dist/esm/internal/ProtocolVersion.js +24 -0
  204. package/dist/esm/internal/ProtocolVersion.js.map +1 -0
  205. package/dist/esm/internal/ShareSigner.d.ts +173 -0
  206. package/dist/esm/internal/ShareSigner.d.ts.map +1 -0
  207. package/dist/esm/internal/ShareSigner.js +219 -0
  208. package/dist/esm/internal/ShareSigner.js.map +1 -0
  209. package/dist/esm/internal/SnapshotBoundary.d.ts +17 -0
  210. package/dist/esm/internal/SnapshotBoundary.d.ts.map +1 -0
  211. package/dist/esm/internal/SnapshotBoundary.js +68 -0
  212. package/dist/esm/internal/SnapshotBoundary.js.map +1 -0
  213. package/dist/esm/test/TestSocket.d.ts +55 -0
  214. package/dist/esm/test/TestSocket.d.ts.map +1 -0
  215. package/dist/esm/test/TestSocket.js +128 -0
  216. package/dist/esm/test/TestSocket.js.map +1 -0
  217. package/dist/esm/test/TestSync.d.ts +54 -0
  218. package/dist/esm/test/TestSync.d.ts.map +1 -0
  219. package/dist/esm/test/TestSync.js +76 -0
  220. package/dist/esm/test/TestSync.js.map +1 -0
  221. package/docs/README.md +156 -0
  222. package/docs/api.md +328 -0
  223. package/docs/concepts/authorization.md +117 -0
  224. package/docs/concepts/branches.md +195 -0
  225. package/docs/concepts/compaction.md +144 -0
  226. package/docs/concepts/replay-then-follow.md +129 -0
  227. package/docs/concepts/scopes-and-cursors.md +135 -0
  228. package/docs/guides/authorize-a-connection.md +174 -0
  229. package/docs/guides/follow-a-run.md +174 -0
  230. package/docs/guides/handle-a-compacted-run.md +158 -0
  231. package/docs/guides/list-workspace-runs.md +120 -0
  232. package/docs/guides/run-a-long-soak.md +80 -0
  233. package/docs/guides/serve-the-read-path.md +146 -0
  234. package/docs/guides/test-a-follower.md +273 -0
  235. package/docs/installation.md +92 -0
  236. package/docs/protocol.md +183 -0
  237. package/docs/quickstart.md +159 -0
  238. package/docs/troubleshooting.md +234 -0
  239. package/package.json +304 -3
  240. package/src/BranchCommands.ts +684 -0
  241. package/src/BranchIds.ts +76 -0
  242. package/src/BranchPresence.ts +512 -0
  243. package/src/BranchProjection.ts +308 -0
  244. package/src/BranchProtocol.ts +411 -0
  245. package/src/BranchRpcs.ts +163 -0
  246. package/src/BranchServer.ts +202 -0
  247. package/src/BranchShare.ts +297 -0
  248. package/src/RunCatalog.ts +308 -0
  249. package/src/SyncAuth.ts +146 -0
  250. package/src/SyncClient.ts +902 -0
  251. package/src/SyncError.ts +147 -0
  252. package/src/SyncPrincipal.ts +115 -0
  253. package/src/SyncProtocol.ts +594 -0
  254. package/src/SyncRpcs.ts +40 -0
  255. package/src/SyncServer.ts +1184 -0
  256. package/src/WorkspaceShare.ts +292 -0
  257. package/src/index.ts +107 -0
  258. package/src/internal/Admission.ts +119 -0
  259. package/src/internal/CauseText.ts +74 -0
  260. package/src/internal/JournalErrorCode.ts +46 -0
  261. package/src/internal/PolicyOptions.ts +97 -0
  262. package/src/internal/ProtocolVersion.ts +28 -0
  263. package/src/internal/ShareSigner.ts +300 -0
  264. package/src/internal/SnapshotBoundary.ts +91 -0
  265. package/src/test/TestSocket.ts +192 -0
  266. package/src/test/TestSync.ts +113 -0
@@ -0,0 +1,474 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var SyncClient_exports = {};
30
+ __export(SyncClient_exports, {
31
+ Sync: () => Sync,
32
+ SyncClient: () => SyncClient,
33
+ defaultBootstrapLimit: () => defaultBootstrapLimit,
34
+ defaultCredit: () => defaultCredit,
35
+ layer: () => layer,
36
+ layerNoop: () => layerNoop,
37
+ layerWith: () => layerWith,
38
+ make: () => make,
39
+ makeNoop: () => makeNoop,
40
+ makeWith: () => makeWith
41
+ });
42
+ module.exports = __toCommonJS(SyncClient_exports);
43
+ var Cause = __toESM(require("effect/Cause"), 1);
44
+ var Context = __toESM(require("effect/Context"), 1);
45
+ var Effect = __toESM(require("effect/Effect"), 1);
46
+ var Layer = __toESM(require("effect/Layer"), 1);
47
+ var Ref = __toESM(require("effect/Ref"), 1);
48
+ var Schedule = __toESM(require("effect/Schedule"), 1);
49
+ var Schema = __toESM(require("effect/Schema"), 1);
50
+ var Stream = __toESM(require("effect/Stream"), 1);
51
+ var RpcClient = __toESM(require("effect/unstable/rpc/RpcClient"), 1);
52
+ var RpcClientError = __toESM(require("effect/unstable/rpc/RpcClientError"), 1);
53
+ var Admission = __toESM(require("./internal/Admission.js"), 1);
54
+ var import_CauseText = require("./internal/CauseText.js");
55
+ var import_PolicyOptions = require("./internal/PolicyOptions.js");
56
+ var SnapshotBoundary = __toESM(require("./internal/SnapshotBoundary.js"), 1);
57
+ var import_SyncError = require("./SyncError.js");
58
+ var import_SyncProtocol = require("./SyncProtocol.js");
59
+ var import_SyncRpcs = require("./SyncRpcs.js");
60
+ const defaultCredit = 256;
61
+ const defaultBootstrapLimit = 256;
62
+ const defaults = {
63
+ maxFrameBytes: import_SyncProtocol.defaultMaxFrameBytes,
64
+ bootstrapLimit: defaultBootstrapLimit
65
+ };
66
+ class SyncClient extends Context.Service()("@smthrs/sync/SyncClient") {
67
+ }
68
+ const Sync = SyncClient;
69
+ const makeNoop = (overrides = {}) => SyncClient.of({
70
+ snapshot: () => Effect.fail(new import_SyncError.SyncError({ code: "closed", message: "Sync client is closed" })),
71
+ subscribe: () => Stream.fail(new import_SyncError.SyncError({ code: "closed", message: "Sync client is closed" })),
72
+ progress: Effect.succeed({ delivered: [], applied: [] }),
73
+ ...overrides
74
+ });
75
+ const layerNoop = (overrides = {}) => Layer.succeed(SyncClient, makeNoop(overrides));
76
+ const transportError = (cause) => cause instanceof import_SyncError.SyncError ? cause : cause instanceof RpcClientError.RpcClientError && cause.reason._tag === "RpcClientDefect" ? new import_SyncError.SyncError({ code: "protocol_violation", message: "Sync RPC protocol failed", cause: (0, import_CauseText.causeCode)(cause.reason) }) : new import_SyncError.SyncError({
77
+ code: "transport_failed",
78
+ // Bounded like `cause`. `message` is `Schema.String` and it is the
79
+ // declared error schema of every RPC, so a host's own sentence must not
80
+ // be able to be the largest thing this error carries.
81
+ message: cause instanceof Error ? (0, import_CauseText.boundedText)(cause.message) : "Sync RPC transport failed",
82
+ cause: (0, import_CauseText.causeText)(cause)
83
+ });
84
+ const rpcCause = (cause) => Cause.fromReasons(
85
+ Cause.map(cause, transportError).reasons.map(
86
+ (reason) => Cause.isDieReason(reason) && Schema.isSchemaError(reason.defect) ? Cause.makeFailReason(
87
+ new import_SyncError.SyncError({ code: "decode_failed", message: "Invalid sync RPC response", cause: "SchemaError" })
88
+ ).annotate(Context.makeUnsafe(reason.annotations)) : reason
89
+ )
90
+ );
91
+ const cursorMap = (cursors) => new Map(cursors.map((cursor) => [cursor.runId, { ...cursor }]));
92
+ const canonicalCursors = (cursors) => Array.from(cursors.values(), (cursor) => ({ ...cursor })).sort(
93
+ (left, right) => (
94
+ // A Map has one value per key, so this comparator never receives equal
95
+ // run IDs. `cursorMap` and the acknowledged cursor state both establish
96
+ // that invariant before reaching this boundary.
97
+ left.runId > right.runId ? 1 : -1
98
+ )
99
+ );
100
+ const advance = (cursors, runId, throughSeq, generation) => {
101
+ const current = cursors.get(runId);
102
+ if (current !== void 0 && current.afterSeq >= throughSeq) return cursors;
103
+ const next = new Map(cursors);
104
+ next.set(runId, { runId, afterSeq: throughSeq, generation });
105
+ return next;
106
+ };
107
+ const reconnectPolicy = Schedule.min([
108
+ Schedule.exponential(500, 1.5),
109
+ Schedule.spaced(5e3)
110
+ ]).pipe(
111
+ Schedule.while(({ input }) => isTransportCause(input))
112
+ );
113
+ const isTransportCause = (cause) => {
114
+ const reason = cause.reasons[0];
115
+ return cause.reasons.length === 1 && Cause.isFailReason(reason) && import_SyncError.SyncError.is(reason.error) && reason.error.code === "transport_failed";
116
+ };
117
+ const lineageChanged = (runId) => new import_SyncError.SyncError({
118
+ code: "lineage_changed",
119
+ message: `Run ${runId} was rewound; rebuild from its archive boundary with a fresh sync client`
120
+ });
121
+ const entriesByteLength = (entries) => entries.reduce((bytes, entry) => bytes + (0, import_SyncProtocol.encodedByteLength)(entry), 0);
122
+ const oversized = (bytes, maxFrameBytes) => new import_SyncError.SyncError({
123
+ code: "frame_too_large",
124
+ message: `Encoded entries of ${bytes} bytes exceed the ${maxFrameBytes}-byte frame ceiling`
125
+ });
126
+ const frameViolation = (frame) => {
127
+ let previous = -1;
128
+ for (const entry of frame.entries) {
129
+ if (entry.runId !== frame.runId) {
130
+ return new import_SyncError.SyncError({
131
+ code: "protocol_violation",
132
+ cause: "foreign_run",
133
+ message: `Frame for run ${frame.runId} carried an entry for run ${entry.runId}`
134
+ });
135
+ }
136
+ if (entry.seq <= previous) {
137
+ return new import_SyncError.SyncError({
138
+ code: "protocol_violation",
139
+ cause: "non_monotonic_sequence",
140
+ message: `Frame entries must ascend strictly: sequence ${entry.seq} arrived after ${previous}`
141
+ });
142
+ }
143
+ if (entry.seq < frame.fromSeq || frame.toSeq < entry.seq) {
144
+ return new import_SyncError.SyncError({
145
+ code: "protocol_violation",
146
+ cause: "invalid_frame_interval",
147
+ message: `Entry ${entry.seq} lies outside the frame's covered interval ${frame.fromSeq}..${frame.toSeq}`
148
+ });
149
+ }
150
+ previous = entry.seq;
151
+ }
152
+ return void 0;
153
+ };
154
+ const pageViolation = (scope, requested, response) => {
155
+ const violation = (message) => new import_SyncError.SyncError({ code: "protocol_violation", message, cause: "invalid_read_page" });
156
+ const generations = /* @__PURE__ */ new Set();
157
+ for (const cursor of response.cursors) {
158
+ generations.add(cursor.runId);
159
+ if (cursor.generation === void 0) return violation("Read response lacks a generation");
160
+ const previous = requested.get(cursor.runId);
161
+ if (previous !== void 0 && (previous.generation ?? 0) !== cursor.generation) {
162
+ return lineageChanged(cursor.runId);
163
+ }
164
+ }
165
+ const highest = /* @__PURE__ */ new Map();
166
+ for (const entry of response.entries) {
167
+ if (!(0, import_SyncProtocol.covers)(scope, entry.runId)) {
168
+ return violation(`Read page carried an entry for run ${entry.runId}, which the request's scope excludes`);
169
+ }
170
+ const floor = requested.get(entry.runId)?.afterSeq;
171
+ if (floor !== void 0 && entry.seq <= floor) {
172
+ return violation(
173
+ `Read page carried sequence ${entry.seq} for run ${entry.runId}, at or below the requested cursor ${floor}`
174
+ );
175
+ }
176
+ const previous = highest.get(entry.runId);
177
+ if (previous !== void 0 && entry.seq <= previous) {
178
+ return violation(
179
+ `Read page entries for run ${entry.runId} must ascend strictly: sequence ${entry.seq} arrived after ${previous}`
180
+ );
181
+ }
182
+ highest.set(entry.runId, entry.seq);
183
+ }
184
+ for (const runId of highest.keys()) {
185
+ if (!generations.has(runId)) return violation(`Read page lacks a generation cursor for run ${runId}`);
186
+ }
187
+ const duplicate = (0, import_SyncProtocol.duplicateCursorRunId)(response.cursors);
188
+ return duplicate === void 0 ? void 0 : violation(`Read page echoed run ${duplicate} more than once`);
189
+ };
190
+ const make = ({ client }) => service(client, defaults);
191
+ const makeWith = ({
192
+ bootstrapLimit,
193
+ client,
194
+ maxFrameBytes
195
+ }) => Effect.flatMap(
196
+ Effect.all({
197
+ maxFrameBytes: (0, import_PolicyOptions.positiveInt)("SyncClient.Options.maxFrameBytes", maxFrameBytes, defaults.maxFrameBytes),
198
+ bootstrapLimit: (0, import_PolicyOptions.boundedInt)(
199
+ "SyncClient.Options.bootstrapLimit",
200
+ bootstrapLimit,
201
+ defaults.bootstrapLimit,
202
+ import_SyncProtocol.maxReadLimit
203
+ )
204
+ }),
205
+ (policy) => service(client, policy)
206
+ );
207
+ const service = (client, { bootstrapLimit, maxFrameBytes }) => Effect.sync(() => {
208
+ const delivered = Ref.makeUnsafe(/* @__PURE__ */ new Map());
209
+ const applied = Ref.makeUnsafe(/* @__PURE__ */ new Map());
210
+ const progress = Effect.gen(function* () {
211
+ return {
212
+ delivered: canonicalCursors(yield* Ref.get(delivered)),
213
+ applied: canonicalCursors(yield* Ref.get(applied))
214
+ };
215
+ });
216
+ const snapshot = (input) => Effect.gen(function* () {
217
+ const request = yield* SnapshotBoundary.request(input);
218
+ const supplied = yield* client["Sync.Snapshot"]({ ...request }).pipe(
219
+ Effect.catchCause((cause) => Effect.failCause(rpcCause(cause)))
220
+ );
221
+ return yield* SnapshotBoundary.response(request, supplied, maxFrameBytes);
222
+ });
223
+ const subscribe = (input) => Stream.unwrap(Effect.gen(function* () {
224
+ const options = {
225
+ ...input,
226
+ ...yield* Admission.decode(import_SyncProtocol.RequestEnvelope, input, "invalid_request")
227
+ };
228
+ const credit = yield* (0, import_PolicyOptions.boundedInt)(
229
+ "SyncClient.SubscribeOptions.credit",
230
+ options.credit,
231
+ defaultCredit,
232
+ import_SyncProtocol.maxSubscribeCredit
233
+ );
234
+ const cursor = cursorMap(options.cursors);
235
+ for (const [runId, position] of yield* Ref.get(options.apply === void 0 ? delivered : applied)) {
236
+ const supplied = cursor.get(runId);
237
+ if (supplied !== void 0 && (supplied.generation ?? 0) !== position.generation) {
238
+ return yield* Effect.fail(lineageChanged(runId));
239
+ }
240
+ if (supplied === void 0 || supplied.afterSeq < position.afterSeq) cursor.set(runId, position);
241
+ }
242
+ const snapshot2 = () => canonicalCursors(cursor);
243
+ const commit = (runId, throughSeq, generation, wasApplied) => Effect.gen(function* () {
244
+ for (const view of wasApplied ? [delivered, applied] : [delivered]) {
245
+ const previous = (yield* Ref.get(view)).get(runId);
246
+ if (previous !== void 0 && previous.generation !== generation) {
247
+ return yield* Effect.fail(lineageChanged(runId));
248
+ }
249
+ }
250
+ yield* Ref.update(delivered, (shared) => advance(shared, runId, throughSeq, generation));
251
+ if (wasApplied) yield* Ref.update(applied, (shared) => advance(shared, runId, throughSeq, generation));
252
+ cursor.set(runId, { runId, afterSeq: throughSeq, generation });
253
+ }).pipe(Effect.uninterruptible);
254
+ const applyEntry = options.apply;
255
+ const deliver = (runId, entry, generation) => {
256
+ const through = entry.seq;
257
+ return Stream.concat(
258
+ Stream.drain(Stream.fromEffect(
259
+ applyEntry === void 0 ? commit(runId, through, generation, false) : Effect.uninterruptibleMask(
260
+ (restore) => Effect.andThen(restore(applyEntry(entry)), commit(runId, through, generation, true))
261
+ )
262
+ )),
263
+ Stream.succeed(entry)
264
+ );
265
+ };
266
+ const batch = (frame) => {
267
+ if (frame.generation === void 0) {
268
+ return Stream.fail(
269
+ new import_SyncError.SyncError({ code: "protocol_violation", message: "Entries frame lacks a generation" })
270
+ );
271
+ }
272
+ if (!(0, import_SyncProtocol.covers)(options.scope, frame.runId)) {
273
+ return Stream.fail(
274
+ new import_SyncError.SyncError({
275
+ code: "protocol_violation",
276
+ message: "Live frame is outside the subscription scope",
277
+ cause: "foreign_run"
278
+ })
279
+ );
280
+ }
281
+ const frameBytes = entriesByteLength(frame.entries);
282
+ if (frameBytes > maxFrameBytes) return Stream.fail(oversized(frameBytes, maxFrameBytes));
283
+ const violation = frameViolation(frame);
284
+ if (violation !== void 0) return Stream.fail(violation);
285
+ const position = cursor.get(frame.runId);
286
+ const generation = frame.generation;
287
+ if (position !== void 0 && (position.generation ?? 0) !== generation) {
288
+ return Stream.fail(lineageChanged(frame.runId));
289
+ }
290
+ const afterSeq = position?.afterSeq ?? -1;
291
+ if (frame.fromSeq > afterSeq + 1) {
292
+ return Stream.fail(
293
+ new import_SyncError.SyncGapError({
294
+ runId: frame.runId,
295
+ expectedFrom: afterSeq + 1,
296
+ receivedFrom: frame.fromSeq
297
+ })
298
+ );
299
+ }
300
+ if (frame.toSeq <= afterSeq) return Stream.empty;
301
+ const entries = frame.entries.filter((entry) => entry.seq > afterSeq);
302
+ return Stream.flatMap(Stream.fromIterable(entries), (entry) => deliver(frame.runId, entry, generation));
303
+ };
304
+ const livePage = (onFrame) => Stream.unwrap(
305
+ Effect.sync(
306
+ () => client["Sync.Subscribe"]({
307
+ protocolVersion: import_SyncProtocol.protocolVersion,
308
+ scope: options.scope,
309
+ cursors: snapshot2(),
310
+ credit,
311
+ ...options.capability === void 0 ? {} : { capability: options.capability }
312
+ })
313
+ )
314
+ ).pipe(
315
+ Stream.catchCause((cause) => Stream.failCause(rpcCause(cause))),
316
+ Stream.mapEffect((frame) => Admission.decode(import_SyncProtocol.Frame, frame)),
317
+ Stream.mapEffect(
318
+ (frame) => frame._tag === "Entries" ? Effect.map(Admission.records(frame.entries), (entries) => ({ ...frame, entries })) : Effect.succeed(frame)
319
+ ),
320
+ Stream.flatMap((frame) => {
321
+ onFrame();
322
+ switch (frame._tag) {
323
+ case "Entries":
324
+ return batch(frame);
325
+ case "Closed":
326
+ return Stream.fail(new import_SyncError.SyncError({ code: "closed", message: "Sync subscription closed" }));
327
+ default:
328
+ return Stream.empty;
329
+ }
330
+ })
331
+ );
332
+ const live = () => Stream.unwrap(Effect.sync(() => {
333
+ let receivedFrame = false;
334
+ return Stream.concat(
335
+ livePage(() => {
336
+ receivedFrame = true;
337
+ }),
338
+ Stream.unwrap(Effect.sync(
339
+ () => receivedFrame ? live() : Stream.fail(
340
+ new import_SyncError.SyncError({
341
+ code: "protocol_violation",
342
+ message: "Subscription window closed without frames"
343
+ })
344
+ )
345
+ ))
346
+ );
347
+ }));
348
+ const follow = () => live().pipe(
349
+ Stream.tapCause(
350
+ (cause) => isTransportCause(cause) ? Effect.logWarning("sync live follow transport failed; reconnecting with backoff", cause) : Effect.void
351
+ ),
352
+ // Schedule the complete cause so retry refusal cannot discard an
353
+ // accompanying defect, interruption, or tracing annotation.
354
+ Stream.catchCause((cause) => Stream.fail(cause)),
355
+ Stream.retry(reconnectPolicy),
356
+ Stream.catch((cause) => Stream.failCause(cause))
357
+ );
358
+ const bootstrap = () => Stream.unwrap(
359
+ // SUSPENDED, exactly as `livePage` is. Building the payload where
360
+ // the recursive call is written snapshotted the cursors as page N
361
+ // was mapped, before a single one of its entries had reached
362
+ // `commit` — so read N+1 carried read N's request cursors and the
363
+ // server correctly re-served the page it had just served. Every
364
+ // catch-up page past the first arrived twice.
365
+ Effect.suspend(() => {
366
+ const requested = snapshot2();
367
+ return client["Sync.Read"]({
368
+ protocolVersion: import_SyncProtocol.protocolVersion,
369
+ scope: options.scope,
370
+ cursors: requested,
371
+ limit: bootstrapLimit,
372
+ ...options.capability === void 0 ? {} : { capability: options.capability }
373
+ }).pipe(
374
+ Effect.catchCause((cause) => Effect.failCause(rpcCause(cause))),
375
+ Effect.flatMap((response) => Admission.decode(import_SyncProtocol.ReadResponse, response)),
376
+ Effect.flatMap(
377
+ (response) => Effect.map(Admission.records(response.entries), (entries) => ({ ...response, entries }))
378
+ ),
379
+ Effect.map((response) => {
380
+ const pageBytes = entriesByteLength(response.entries);
381
+ if (pageBytes > maxFrameBytes) return Stream.fail(oversized(pageBytes, maxFrameBytes));
382
+ const violation = pageViolation(options.scope, cursorMap(requested), response);
383
+ if (violation !== void 0) return Stream.fail(violation);
384
+ const generations = new Map(response.cursors.map((cursor2) => [cursor2.runId, cursor2.generation]));
385
+ const page = Stream.flatMap(
386
+ Stream.fromIterable(response.entries),
387
+ (entry) => deliver(
388
+ entry.runId,
389
+ entry,
390
+ generations.get(entry.runId)
391
+ )
392
+ );
393
+ if (response.done) return Stream.concat(page, follow());
394
+ if (response.entries.length === 0) {
395
+ return Stream.fail(
396
+ new import_SyncError.SyncError({
397
+ code: "protocol_violation",
398
+ message: "Bootstrap read reported more durable entries but returned an empty page"
399
+ })
400
+ );
401
+ }
402
+ return Stream.concat(page, bootstrap());
403
+ })
404
+ );
405
+ })
406
+ );
407
+ const resyncTarget = (failure) => {
408
+ if (!import_SyncError.SyncError.is(failure) || failure.code !== "compacted" || failure.resync === void 0) {
409
+ return void 0;
410
+ }
411
+ const covered = cursor.get(failure.resync.runId)?.afterSeq ?? -1;
412
+ return covered >= failure.resync.checkpointSeq ? void 0 : failure.resync;
413
+ };
414
+ const onResync = options.onResync;
415
+ const resynced = () => Stream.catchCause(bootstrap(), (cause) => {
416
+ const reason = cause.reasons[0];
417
+ if (cause.reasons.length !== 1 || !Cause.isFailReason(reason)) return Stream.failCause(cause);
418
+ const failure = reason.error;
419
+ const resync = resyncTarget(failure);
420
+ if (resync === void 0) return Stream.failCause(cause);
421
+ if (!(0, import_SyncProtocol.covers)(options.scope, resync.runId)) {
422
+ return Stream.fail(
423
+ new import_SyncError.SyncError({
424
+ code: "protocol_violation",
425
+ message: "Compaction target is outside the subscription scope"
426
+ })
427
+ );
428
+ }
429
+ if (onResync === void 0) return Stream.failCause(cause);
430
+ const runId = resync.runId;
431
+ const checkpointSeq = resync.checkpointSeq;
432
+ const refusedGeneration = resync.generation;
433
+ return Stream.unwrap(Effect.uninterruptibleMask(
434
+ (restore) => Effect.gen(function* () {
435
+ const receipt = yield* restore(onResync(resync));
436
+ const restoredCursor = () => new import_SyncError.SyncError({
437
+ code: "invalid_request",
438
+ message: "Recovery must return the restored run cursor at or above its compaction floor"
439
+ });
440
+ const captured = yield* Effect.try({
441
+ try: () => ({
442
+ runId: receipt.runId,
443
+ afterSeq: receipt.afterSeq,
444
+ generation: receipt.generation ?? refusedGeneration
445
+ }),
446
+ catch: restoredCursor
447
+ });
448
+ if (!Schema.is(import_SyncProtocol.RunCursor)(captured) || captured.runId !== runId || captured.afterSeq < checkpointSeq) {
449
+ return yield* Effect.fail(restoredCursor());
450
+ }
451
+ const applied2 = captured;
452
+ if (applied2.generation === void 0) {
453
+ return yield* Effect.fail(
454
+ new import_SyncError.SyncError({
455
+ code: "protocol_violation",
456
+ message: "Compaction refusal names no generation for a receipt that omits one"
457
+ })
458
+ );
459
+ }
460
+ yield* commit(applied2.runId, applied2.afterSeq, applied2.generation, true);
461
+ return resynced();
462
+ })
463
+ ));
464
+ });
465
+ return resynced();
466
+ }));
467
+ return SyncClient.of({ snapshot, subscribe, progress });
468
+ });
469
+ const layer = Layer.effect(
470
+ SyncClient,
471
+ Effect.flatMap(RpcClient.make(import_SyncRpcs.SyncRpcs), (client) => make({ client }))
472
+ );
473
+ const layerWith = (options) => Layer.effect(SyncClient, Effect.flatMap(RpcClient.make(import_SyncRpcs.SyncRpcs), (client) => makeWith({ ...options, client })));
474
+ //# sourceMappingURL=SyncClient.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/SyncClient.ts"],
4
+ "sourcesContent": ["/**\n * Browser-safe client for replaying and following journal entries.\n *\n * @since 0.1.0\n */\n\nimport type * as JournalEvent from \"@smthrs/journal/JournalEvent\"\nimport * as Cause from \"effect/Cause\"\nimport * as Context from \"effect/Context\"\nimport * as Effect from \"effect/Effect\"\nimport * as Layer from \"effect/Layer\"\nimport * as Ref from \"effect/Ref\"\nimport * as 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 \u2014 an unbounded window would hand the server one\n * never-closing subscription per follower.\n *\n * @category constants\n * @since 0.1.0\n */\nexport const defaultCredit = 256\n\n/**\n * Entries one catch-up page asks for.\n *\n * Bootstrap is the replay half of replay-then-follow, so the page size is the\n * memory one catch-up costs and the granularity at which its cursor advances.\n * It matches {@link defaultCredit} and stays under\n * `SyncProtocol.maxReadLimit`, which is the ceiling the server enforces.\n *\n * @category constants\n * @since 1.0.0-rc.0\n */\nexport const defaultBootstrapLimit = 256\n\n/**\n * The policy one sync client runs every operation under.\n *\n * Both fields are validated by {@link makeWith} and {@link layerWith}, so a\n * value that is not a positive safe integer fails the constructor rather than\n * disabling the bound it configures.\n *\n * @category models\n * @since 1.0.0-rc.0\n */\nexport interface Options {\n /**\n * Largest summed encoded-entry size one frame or bootstrap page may carry,\n * in bytes. Defaults to {@link defaultMaxFrameBytes}.\n */\n readonly maxFrameBytes?: number | undefined\n /**\n * Entries one catch-up page asks for. Defaults to\n * {@link defaultBootstrapLimit}, and may not exceed\n * `SyncProtocol.maxReadLimit`.\n */\n readonly bootstrapLimit?: number | undefined\n}\n\n/** The resolved, already-validated client policy. */\ninterface Resolved {\n readonly maxFrameBytes: number\n readonly bootstrapLimit: number\n}\n\nconst defaults: Resolved = {\n maxFrameBytes: defaultMaxFrameBytes,\n bootstrapLimit: defaultBootstrapLimit\n}\n\n/**\n * Input accepted by a sync subscription.\n *\n * `capability` authorizes branch reads: following a shared branch's run\n * requires a capability that verifies for that branch on the server.\n *\n * `EApply` and `EResync` are the consumer's own failure types for `apply` and\n * `onResync`. The subscription fails with them unchanged, so an application\n * failure is never dressed as a transport or protocol {@link SyncError}.\n *\n * @category models\n * @since 0.1.0\n */\nexport interface SubscribeOptions<EApply = never, EResync = never> {\n readonly scope: Scope\n /**\n * Where this subscription starts, per run. The effective position is the\n * LATER of this and the client's matching progress map (applied when an\n * apply callback is present, delivered otherwise), so a caller\n * ahead of the shared view keeps its place and a caller behind it is\n * fast-forwarded. Rebuild from an earlier position with a fresh client.\n */\n readonly cursors: WorkspaceCursor\n readonly capability?: ShareCapability\n /**\n * Frames one subscription round may carry before the follow replenishes the\n * window. Defaults to {@link defaultCredit}, and must be a positive integer\n * no greater than `SyncProtocol.maxSubscribeCredit`.\n */\n readonly credit?: number | undefined\n /**\n * Applies one entry, and DEFINES what this subscription's cursor means.\n *\n * Without it the cursor advances as each entry is handed to the consumer,\n * so a consumer whose own application then fails has a cursor naming an\n * entry it never materialized. With it the cursor advances only after this\n * effect succeeds, and records it in `Progress.applied`. A failure here\n * fails the subscription with the entry unacknowledged, so the\n * next applying subscription delivers it again; the effect must\n * therefore be idempotent, because a redelivery is exactly what a retry is.\n */\n readonly apply?: ((entry: JournalEvent.Entry) => Effect.Effect<void, EApply>) | undefined\n /**\n * Restores state when the server refuses a cursor below a compaction floor.\n * Return the exact run and sequence actually restored, after applying it.\n *\n * The entries under the floor are deleted. Fetch an explicitly public\n * projection through `snapshot` or an authorized local source; a\n * projection has a real hole to fill. The returned sequence must cover the\n * requested floor; a newer snapshot resumes at its own sequence, not the\n * older floor. Missing handlers, failures, interruption, and invalid receipts\n * leave the cursor unmoved. There is no implicit skip of deleted history.\n *\n * Durable consumers must commit their restored state and durable cursor in\n * their own transaction and seed a fresh client from that cursor on restart.\n * This client's cursor is in memory, not an atomic cross-store transaction.\n * Recovery must be idempotent, including when a newer compaction requires\n * another restoration before the suffix can be read.\n */\n readonly onResync?: ((resync: Resync) => Effect.Effect<RunCursor, EResync>) | undefined\n}\n\n/**\n * Replicated journal subscription operations.\n *\n * @category models\n * @since 0.1.0\n */\nexport interface Service {\n /** Fetches a public snapshot without applying state or advancing a cursor. */\n readonly snapshot: (request: SnapshotRequest) => Effect.Effect<Snapshot, SyncError>\n /** Replays then follows `options.scope`, also failing with the callbacks' own errors. */\n readonly subscribe: <EApply = never, EResync = never>(\n options: SubscribeOptions<EApply, EResync>\n ) => Stream.Stream<JournalEvent.Entry, SyncError | SyncGapError | EApply | EResync>\n /**\n * Delivery and application positions. `delivered` is a transport bookmark\n * only; `applied` is what the `apply` and `onResync` callbacks acknowledged.\n */\n readonly progress: Effect.Effect<Progress>\n}\n\n/**\n * The browser-safe journal replication client.\n *\n * @category services\n * @since 1.0.0-rc.0\n */\nexport class SyncClient extends Context.Service<SyncClient, Service>()(\"@smthrs/sync/SyncClient\") {}\n\n/**\n * The client tag's former name, kept for one release.\n *\n * @deprecated Use {@link SyncClient}.\n * @category services\n * @since 0.1.0\n */\nexport const Sync = SyncClient\n\n/**\n * The client tag's former name, kept for one release.\n *\n * @deprecated Use {@link SyncClient}.\n * @category services\n * @since 0.1.0\n */\nexport type Sync = SyncClient\n\n/**\n * Constructs a closed sync stub, optionally overriding individual operations.\n *\n * @category constructors\n * @since 0.1.0\n */\nexport const makeNoop = (overrides: Partial<Service> = {}): Service =>\n SyncClient.of({\n snapshot: () => Effect.fail(new SyncError({ code: \"closed\", message: \"Sync client is closed\" })),\n subscribe: () => Stream.fail(new SyncError({ code: \"closed\", message: \"Sync client is closed\" })),\n progress: Effect.succeed({ delivered: [], applied: [] }),\n ...overrides\n })\n\n/**\n * Provides a closed sync stub.\n *\n * @category layers\n * @since 0.1.0\n */\nexport const layerNoop = (overrides: Partial<Service> = {}): Layer.Layer<SyncClient> =>\n Layer.succeed(SyncClient, makeNoop(overrides))\n\ntype Client = RpcClient.RpcClient<RpcGroup.Rpcs<typeof SyncRpcs>, RpcClientError.RpcClientError>\n\nconst transportError = (cause: unknown): SyncError =>\n cause instanceof SyncError\n ? cause\n : cause instanceof RpcClientError.RpcClientError && cause.reason._tag === \"RpcClientDefect\"\n ? new SyncError({ code: \"protocol_violation\", message: \"Sync RPC protocol failed\", cause: causeCode(cause.reason) })\n : new SyncError({\n code: \"transport_failed\",\n // Bounded like `cause`. `message` is `Schema.String` and it is the\n // declared error schema of every RPC, so a host's own sentence must not\n // be able to be the largest thing this error carries.\n message: cause instanceof Error ? boundedText(cause.message) : \"Sync RPC transport failed\",\n cause: causeText(cause)\n })\n\n/** Effect RPC decodes malformed peer values with orDie. Restore the sync\n * boundary's typed refusal without swallowing unrelated defects or interruption.\n */\nconst rpcCause = (cause: Cause.Cause<unknown>): Cause.Cause<SyncError> =>\n Cause.fromReasons(\n Cause.map(cause, transportError).reasons.map((reason) =>\n Cause.isDieReason(reason) && Schema.isSchemaError(reason.defect)\n ? Cause.makeFailReason(\n new SyncError({ code: \"decode_failed\", message: \"Invalid sync RPC response\", cause: \"SchemaError\" })\n )\n .annotate(Context.makeUnsafe(reason.annotations))\n : reason\n )\n )\n\ntype Cursors = Map<JournalEvent.RunId, RunCursor>\n\nconst cursorMap = (cursors: WorkspaceCursor): Cursors => new Map(cursors.map((cursor) => [cursor.runId, { ...cursor }]))\n\nconst canonicalCursors = (cursors: ReadonlyMap<JournalEvent.RunId, RunCursor>): WorkspaceCursor =>\n Array.from(cursors.values(), (cursor) => ({ ...cursor })).sort((left, right) =>\n // A Map has one value per key, so this comparator never receives equal\n // run IDs. `cursorMap` and the acknowledged cursor state both establish\n // that invariant before reaching this boundary.\n left.runId > right.runId ? 1 : -1\n )\n\n/**\n * Advances the shared acknowledged view monotonically. A lagging subscription\n * commits what it just consumed, but it must never move the shared cursor\n * backward past another subscription's progress.\n */\nconst advance = (\n cursors: ReadonlyMap<JournalEvent.RunId, RunCursor>,\n runId: JournalEvent.RunId,\n throughSeq: JournalEvent.Seq,\n generation: number\n): ReadonlyMap<JournalEvent.RunId, RunCursor> => {\n const current = cursors.get(runId)\n if (current !== undefined && current.afterSeq >= throughSeq) return cursors\n const next = new Map(cursors)\n next.set(runId, { runId, afterSeq: throughSeq, generation })\n return next\n}\n\n/**\n * Live-follow reconnect policy: exponential backoff capped at five seconds,\n * the same shape as `RpcClient`'s own transport retry policy, and only for\n * transport failures \u2014 gaps, authorization refusals, server closes, and the\n * consumer's own callback failures propagate to the consumer.\n */\nconst reconnectPolicy = Schedule.min([\n Schedule.exponential(500, 1.5),\n Schedule.spaced(5000)\n]).pipe(\n Schedule.while(({ input }: { readonly input: Cause.Cause<unknown> }) => isTransportCause(input))\n)\n\nconst isTransportCause = (cause: Cause.Cause<unknown>): boolean => {\n const reason = cause.reasons[0]!\n return cause.reasons.length === 1 && Cause.isFailReason(reason) &&\n SyncError.is(reason.error) && reason.error.code === \"transport_failed\"\n}\n\nconst lineageChanged = (runId: JournalEvent.RunId): SyncError =>\n new SyncError({\n code: \"lineage_changed\",\n message: `Run ${runId} was rewound; rebuild from its archive boundary with a fresh sync client`\n })\n\nconst entriesByteLength = (entries: ReadonlyArray<JournalEvent.Entry>): number =>\n entries.reduce((bytes, entry) => bytes + encodedByteLength(entry), 0)\n\nconst oversized = (bytes: number, maxFrameBytes: number): SyncError =>\n new SyncError({\n code: \"frame_too_large\",\n message: `Encoded entries of ${bytes} bytes exceed the ${maxFrameBytes}-byte frame ceiling`\n })\n\n/**\n * The first internal inconsistency of a server frame, or `undefined` for a\n * consistent one.\n *\n * A schema-valid frame can still contradict itself: carry another run's\n * entry, repeat or reorder sequences, or carry an entry outside its own\n * declared covered interval. Applying one would corrupt the client's cursor\n * bookkeeping, so an inconsistent frame is refused as a protocol violation\n * before any entry is admitted or any cursor moves.\n */\nconst frameViolation = (frame: EntriesFrame): SyncError | undefined => {\n let previous = -1\n for (const entry of frame.entries) {\n if (entry.runId !== frame.runId) {\n return new SyncError({\n code: \"protocol_violation\",\n cause: \"foreign_run\",\n message: `Frame for run ${frame.runId} carried an entry for run ${entry.runId}`\n })\n }\n if (entry.seq <= previous) {\n return new SyncError({\n code: \"protocol_violation\",\n cause: \"non_monotonic_sequence\",\n message: `Frame entries must ascend strictly: sequence ${entry.seq} arrived after ${previous}`\n })\n }\n if (entry.seq < frame.fromSeq || frame.toSeq < entry.seq) {\n return new SyncError({\n code: \"protocol_violation\",\n cause: \"invalid_frame_interval\",\n message: `Entry ${entry.seq} lies outside the frame's covered interval ${frame.fromSeq}..${frame.toSeq}`\n })\n }\n previous = entry.seq\n }\n return undefined\n}\n\n/**\n * The first semantic inconsistency of a catch-up page, or `undefined` for a\n * consistent one.\n *\n * Every entry must belong to the requested scope, ascend strictly within its\n * run, and lie above the requested cursor. Every entry-bearing run must have\n * exactly one response cursor with an explicit generation matching the request.\n *\n * Strictly-above-the-cursor is also what makes an incomplete page CONVERGE: a\n * page that carries entries but moves no cursor would be re-read forever.\n */\nconst pageViolation = (\n scope: Scope,\n requested: ReadonlyMap<JournalEvent.RunId, RunCursor>,\n response: ReadResponse\n): SyncError | undefined => {\n const violation = (message: string): SyncError =>\n new SyncError({ code: \"protocol_violation\", message, cause: \"invalid_read_page\" })\n const generations = new Set<JournalEvent.RunId>()\n for (const cursor of response.cursors) {\n generations.add(cursor.runId)\n if (cursor.generation === undefined) return violation(\"Read response lacks a generation\")\n const previous = requested.get(cursor.runId)\n if (previous !== undefined && (previous.generation ?? 0) !== cursor.generation) {\n return lineageChanged(cursor.runId)\n }\n }\n const highest = new Map<JournalEvent.RunId, JournalEvent.Seq>()\n for (const entry of response.entries) {\n if (!covers(scope, entry.runId)) {\n return violation(`Read page carried an entry for run ${entry.runId}, which the request's scope excludes`)\n }\n const floor = requested.get(entry.runId)?.afterSeq\n if (floor !== undefined && entry.seq <= floor) {\n return violation(\n `Read page carried sequence ${entry.seq} for run ${entry.runId}, at or below the requested cursor ${floor}`\n )\n }\n const previous = highest.get(entry.runId)\n if (previous !== undefined && entry.seq <= previous) {\n return violation(\n `Read page entries for run ${entry.runId} must ascend strictly: sequence ${entry.seq} arrived after ${previous}`\n )\n }\n highest.set(entry.runId, entry.seq)\n }\n for (const runId of highest.keys()) {\n if (!generations.has(runId)) return violation(`Read page lacks a generation cursor for run ${runId}`)\n }\n const duplicate = duplicateCursorRunId(response.cursors)\n return duplicate === undefined ? undefined : violation(`Read page echoed run ${duplicate} more than once`)\n}\n\n/**\n * Projects a Sync RPC client into the local replication service.\n *\n * Delivered and applied cursors are separate per-service `Ref` maps: concurrent\n * subscriptions for one materialization share them, and each commit advances\n * its matching map monotonically. A\n * cursor advances in the same stream pull that admits each entry to the\n * consumer, or \u2014 when the caller supplies `SubscribeOptions.apply` \u2014 only\n * after that callback has applied the entry. Interrupted partial pages\n * therefore retain the last admitted entry rather than incorrectly\n * acknowledging the server's whole page.\n *\n * A frame or bootstrap page whose encoded entries exceed `maxFrameBytes` is\n * refused with `frame_too_large`. Out-of-scope entries, repeated or reordered\n * sequences, and missing response generations fail with `protocol_violation`\n * before delivery. Each entry-bearing run in a Read page must have exactly one\n * explicit generation cursor, and every entry must be above the requested\n * cursor. Live frames instead drop already-covered entries and deliver only\n * the suffix above the cursor. An incomplete bootstrap page with no entries\n * or a completed subscription window with no frames fails with\n * `protocol_violation` instead of reopening immediately.\n *\n * A live follow that loses its transport reconnects under\n * {@link reconnectPolicy}, resuming from the acknowledged cursors; the failure\n * cause is logged before the retry folds it. The follow spends a credit window\n * of {@link defaultCredit} frames per subscription round and replenishes it by\n * resubscribing from the cursors it has acknowledged. Already-covered entries\n * are not delivered again; the round-trip cost scales with credit windows.\n *\n * A `compacted` refusal fails closed unless `SubscribeOptions.onResync`\n * restores the missing prefix and returns its exact cursor. Snapshot fetching\n * never applies state or advances cursors. Only a validated receipt for the requested run at or\n * above its compaction floor advances the cursor before reading the suffix.\n *\n * A subscription's effective cursor per run is the LATER of the caller's and\n * the matching progress map: a caller that restored its own progress is never\n * regressed, and a caller asking for history this client already acknowledged\n * is fast-forwarded. Rebuild a projection from an earlier position with a\n * fresh client, whose acknowledged map is empty.\n *\n * This constructor carries the default policy, which is valid by\n * construction and so cannot fail. {@link makeWith} takes an explicit\n * {@link Options} and validates it.\n *\n * @category constructors\n * @since 0.1.0\n */\nexport const make = ({ client }: { readonly client: Client }): Effect.Effect<Service> => service(client, defaults)\n\n/**\n * Constructs the sync client under an explicit policy.\n *\n * Every option is validated here, once, so a client either exists under a\n * policy it can serve or never exists at all. Validating on each `subscribe`\n * and each `snapshot` instead accepted a `maxFrameBytes` of `NaN` at\n * construction and then refused every operation under it, which reported a\n * composition's mistake as a run-time failure of the follow. This mirrors\n * `SyncServer.makeLiveWith` and `BranchCommands.makeLiveWith`.\n *\n * `SubscribeOptions.credit` is a REQUEST count rather than a client policy, so\n * it is still checked where the request is built.\n *\n * @category constructors\n * @since 1.0.0-rc.0\n */\nexport const makeWith = ({\n bootstrapLimit,\n client,\n maxFrameBytes\n}: Options & { readonly client: Client }): Effect.Effect<Service, SyncError> =>\n Effect.flatMap(\n Effect.all({\n maxFrameBytes: positiveInt(\"SyncClient.Options.maxFrameBytes\", maxFrameBytes, defaults.maxFrameBytes),\n bootstrapLimit: boundedInt(\n \"SyncClient.Options.bootstrapLimit\",\n bootstrapLimit,\n defaults.bootstrapLimit,\n maxReadLimit\n )\n }),\n (policy) => service(client, policy)\n )\n\nconst service = (client: Client, { bootstrapLimit, maxFrameBytes }: Resolved): Effect.Effect<Service> =>\n Effect.sync(() => {\n const delivered = Ref.makeUnsafe<ReadonlyMap<JournalEvent.RunId, RunCursor>>(new Map())\n const applied = Ref.makeUnsafe<ReadonlyMap<JournalEvent.RunId, RunCursor>>(new Map())\n\n const progress: Effect.Effect<Progress> = Effect.gen(function*() {\n return {\n delivered: canonicalCursors(yield* Ref.get(delivered)),\n applied: canonicalCursors(yield* Ref.get(applied))\n }\n })\n\n const snapshot = (input: SnapshotRequest): Effect.Effect<Snapshot, SyncError> =>\n Effect.gen(function*() {\n const request = yield* SnapshotBoundary.request(input)\n const supplied = yield* client[\"Sync.Snapshot\"]({ ...request }).pipe(\n Effect.catchCause((cause) => Effect.failCause(rpcCause(cause)))\n )\n return yield* SnapshotBoundary.response(request, supplied, maxFrameBytes)\n })\n\n const subscribe = <EApply = never, EResync = never>(\n input: SubscribeOptions<EApply, EResync>\n ): Stream.Stream<JournalEvent.Entry, SyncError | SyncGapError | EApply | EResync> =>\n Stream.unwrap(Effect.gen(function*() {\n /** Every way this subscription fails: the wire's refusals and the consumer's own callback errors. */\n type Failure = SyncError | SyncGapError | EApply | EResync\n\n const options = {\n ...input,\n ...yield* Admission.decode(RequestEnvelope, input, \"invalid_request\")\n }\n // The client's own policy was checked once, by the constructor. What\n // is left is the count this REQUEST carries: the declared type says\n // `number`, and `NaN` disabled each comparison it appears in rather\n // than tightening it.\n const credit = yield* boundedInt(\n \"SyncClient.SubscribeOptions.credit\",\n options.credit,\n defaultCredit,\n maxSubscribeCredit\n )\n const cursor = cursorMap(options.cursors)\n // A previous delivery-only subscriber cannot skip work for an applying subscriber.\n // Rebuilding an independent projection requires a fresh client.\n for (const [runId, position] of yield* Ref.get(options.apply === undefined ? delivered : applied)) {\n const supplied = cursor.get(runId)\n if (supplied !== undefined && (supplied.generation ?? 0) !== position.generation) {\n return yield* Effect.fail(lineageChanged(runId))\n }\n if (supplied === undefined || supplied.afterSeq < position.afterSeq) cursor.set(runId, position)\n }\n\n const snapshot = (): WorkspaceCursor => canonicalCursors(cursor)\n\n const commit = (\n runId: JournalEvent.RunId,\n throughSeq: JournalEvent.Seq,\n generation: number,\n wasApplied: boolean\n ) =>\n Effect.gen(function*() {\n // Delivery and application have distinct cursors, but both are bound\n // to the same journal generation and advance without an interrupt gap.\n for (const view of wasApplied ? [delivered, applied] : [delivered]) {\n const previous = (yield* Ref.get(view)).get(runId)\n if (previous !== undefined && previous.generation !== generation) {\n return yield* Effect.fail(lineageChanged(runId))\n }\n }\n yield* Ref.update(delivered, (shared) => advance(shared, runId, throughSeq, generation))\n if (wasApplied) yield* Ref.update(applied, (shared) => advance(shared, runId, throughSeq, generation))\n cursor.set(runId, { runId, afterSeq: throughSeq, generation })\n }).pipe(Effect.uninterruptible)\n\n const applyEntry = options.apply\n\n /**\n * Hands one entry to the consumer and moves its cursor.\n *\n * With an `apply` callback the cursor moves only after the callback\n * succeeds, so a cursor names what the consumer materialized. Without\n * one it moves as the entry is admitted, which is the weaker promise\n * this client has always made and the one `RunCursor`'s JSDoc now\n * states.\n *\n * The position committed is SNAPSHOTTED before the callback runs.\n * `Entry` is a `Schema.Class`, and instances are not frozen, so\n * reading `entry.seq` again afterwards let the consumer's own callback\n * choose the cursor it was being handed an entry for.\n */\n const deliver = (\n runId: JournalEvent.RunId,\n entry: JournalEvent.Entry,\n generation: number\n ): Stream.Stream<JournalEvent.Entry, Failure> => {\n const through = entry.seq\n return Stream.concat(\n Stream.drain(Stream.fromEffect(\n applyEntry === undefined\n ? commit(runId, through, generation, false)\n : Effect.uninterruptibleMask((restore) =>\n Effect.andThen(restore(applyEntry(entry)), commit(runId, through, generation, true))\n )\n )),\n Stream.succeed(entry)\n )\n }\n\n const batch = (frame: EntriesFrame): Stream.Stream<JournalEvent.Entry, Failure> => {\n if (frame.generation === undefined) {\n return Stream.fail(\n new SyncError({ code: \"protocol_violation\", message: \"Entries frame lacks a generation\" })\n )\n }\n if (!covers(options.scope, frame.runId)) {\n return Stream.fail(\n new SyncError({\n code: \"protocol_violation\",\n message: \"Live frame is outside the subscription scope\",\n cause: \"foreign_run\"\n })\n )\n }\n const frameBytes = entriesByteLength(frame.entries)\n if (frameBytes > maxFrameBytes) return Stream.fail(oversized(frameBytes, maxFrameBytes))\n const violation = frameViolation(frame)\n if (violation !== undefined) return Stream.fail(violation)\n const position = cursor.get(frame.runId)\n const generation = frame.generation\n if (position !== undefined && (position.generation ?? 0) !== generation) {\n return Stream.fail(lineageChanged(frame.runId))\n }\n const afterSeq: number = position?.afterSeq ?? -1\n // `fromSeq` is the start of the server-declared covered interval. It is\n // intentionally compared to the cursor, not to the first entry's seq:\n // dropped journal admissions legitimately leave holes inside that range.\n if (frame.fromSeq > afterSeq + 1) {\n return Stream.fail(\n new SyncGapError({\n runId: frame.runId,\n expectedFrom: (afterSeq + 1) as JournalEvent.Seq,\n receivedFrom: frame.fromSeq\n })\n )\n }\n if (frame.toSeq <= afterSeq) return Stream.empty\n\n const entries = frame.entries.filter((entry) => entry.seq > afterSeq)\n return Stream.flatMap(Stream.fromIterable(entries), (entry) => deliver(frame.runId, entry, generation))\n }\n\n const livePage = (onFrame: () => void): Stream.Stream<JournalEvent.Entry, Failure> =>\n Stream.unwrap(\n Effect.sync(() =>\n client[\"Sync.Subscribe\"]({\n protocolVersion,\n scope: options.scope,\n cursors: snapshot(),\n credit,\n ...(options.capability === undefined ? {} : { capability: options.capability })\n })\n )\n ).pipe(\n Stream.catchCause((cause) => Stream.failCause(rpcCause(cause))),\n Stream.mapEffect((frame) => Admission.decode(Frame, frame)),\n Stream.mapEffect((frame): Effect.Effect<Frame, SyncError> =>\n frame._tag === \"Entries\"\n ? Effect.map(Admission.records(frame.entries), (entries) => ({ ...frame, entries }))\n : Effect.succeed(frame)\n ),\n Stream.flatMap((frame) => {\n onFrame()\n switch (frame._tag) {\n case \"Entries\":\n return batch(frame)\n case \"Closed\":\n return Stream.fail(new SyncError({ code: \"closed\", message: \"Sync subscription closed\" }))\n default:\n return Stream.empty\n }\n })\n )\n\n const live = (): Stream.Stream<JournalEvent.Entry, Failure> =>\n Stream.unwrap(Effect.sync(() => {\n let receivedFrame = false\n return Stream.concat(\n livePage(() => {\n receivedFrame = true\n }),\n Stream.unwrap(Effect.sync(() =>\n receivedFrame ? live() : Stream.fail(\n new SyncError({\n code: \"protocol_violation\",\n message: \"Subscription window closed without frames\"\n })\n )\n ))\n )\n }))\n\n // The retry re-runs the whole follow from the acknowledged cursors,\n // and its schedule resets once entries flow again, so a long-lived\n // subscription pays the backoff only across consecutive failures.\n const follow = (): Stream.Stream<JournalEvent.Entry, Failure> =>\n live().pipe(\n Stream.tapCause((cause) =>\n isTransportCause(cause)\n ? Effect.logWarning(\"sync live follow transport failed; reconnecting with backoff\", cause)\n : Effect.void\n ),\n // Schedule the complete cause so retry refusal cannot discard an\n // accompanying defect, interruption, or tracing annotation.\n Stream.catchCause((cause) => Stream.fail(cause)),\n Stream.retry(reconnectPolicy),\n Stream.catch((cause) => Stream.failCause(cause))\n )\n\n const bootstrap = (): Stream.Stream<JournalEvent.Entry, Failure> =>\n Stream.unwrap(\n // SUSPENDED, exactly as `livePage` is. Building the payload where\n // the recursive call is written snapshotted the cursors as page N\n // was mapped, before a single one of its entries had reached\n // `commit` \u2014 so read N+1 carried read N's request cursors and the\n // server correctly re-served the page it had just served. Every\n // catch-up page past the first arrived twice.\n Effect.suspend(() => {\n const requested = snapshot()\n return client[\"Sync.Read\"]({\n protocolVersion,\n scope: options.scope,\n cursors: requested,\n limit: bootstrapLimit,\n ...(options.capability === undefined ? {} : { capability: options.capability })\n }).pipe(\n Effect.catchCause((cause) => Effect.failCause(rpcCause(cause))),\n Effect.flatMap((response) => Admission.decode(ReadResponse, response)),\n Effect.flatMap((response) =>\n Effect.map(Admission.records(response.entries), (entries) => ({ ...response, entries }))\n ),\n Effect.map((response) => {\n const pageBytes = entriesByteLength(response.entries)\n if (pageBytes > maxFrameBytes) return Stream.fail(oversized(pageBytes, maxFrameBytes))\n const violation = pageViolation(options.scope, cursorMap(requested), response)\n if (violation !== undefined) return Stream.fail(violation)\n const generations = new Map(response.cursors.map((cursor) => [cursor.runId, cursor.generation!]))\n const page = Stream.flatMap(\n Stream.fromIterable(response.entries),\n (entry) =>\n deliver(\n entry.runId,\n entry,\n generations.get(entry.runId)!\n )\n )\n if (response.done) return Stream.concat(page, follow())\n if (response.entries.length === 0) {\n // An incomplete page with no entries can never converge:\n // the next read would carry the same cursors and receive\n // the same page. Fail typed instead of spinning.\n return Stream.fail(\n new SyncError({\n code: \"protocol_violation\",\n message: \"Bootstrap read reported more durable entries but returned an empty page\"\n })\n )\n }\n return Stream.concat(page, bootstrap())\n })\n )\n })\n )\n\n /**\n * The checkpoint one failure says to resume from, or `undefined` when\n * the failure is not a recoverable compaction.\n *\n * A compaction whose checkpoint is at or below what this subscription\n * already covers cannot move it forward, so retrying would re-read the\n * same refusal forever. That is the same non-convergence rule the\n * empty incomplete bootstrap page is refused under, and it is why a\n * `compacted` failure carrying no {@link Resync} stays a failure\n * rather than becoming a silent stall.\n */\n const resyncTarget = (failure: Failure): Resync | undefined => {\n if (!SyncError.is(failure) || failure.code !== \"compacted\" || failure.resync === undefined) {\n return undefined\n }\n const covered: number = cursor.get(failure.resync.runId)?.afterSeq ?? -1\n return covered >= failure.resync.checkpointSeq ? undefined : failure.resync\n }\n\n const onResync = options.onResync\n\n const resynced = (): Stream.Stream<JournalEvent.Entry, Failure> =>\n Stream.catchCause(bootstrap(), (cause) => {\n const reason = cause.reasons[0]!\n if (cause.reasons.length !== 1 || !Cause.isFailReason(reason)) return Stream.failCause(cause)\n const failure = reason.error\n const resync = resyncTarget(failure)\n if (resync === undefined) return Stream.failCause(cause)\n if (!covers(options.scope, resync.runId)) {\n return Stream.fail(\n new SyncError({\n code: \"protocol_violation\",\n message: \"Compaction target is outside the subscription scope\"\n })\n )\n }\n if (onResync === undefined) return Stream.failCause(cause)\n // Snapshotted before the hook runs, for the reason `deliver`\n // snapshots: the hook is handed the value the commit is read from,\n // and re-reading it afterwards let a consumer move its own cursor\n // arbitrarily far forward from inside the callback.\n const runId = resync.runId\n const checkpointSeq = resync.checkpointSeq\n const refusedGeneration = resync.generation\n return Stream.unwrap(Effect.uninterruptibleMask((restore) =>\n Effect.gen(function*() {\n // Application remains interruptible. Once it returns success,\n // validation and the in-memory commit finish without an async\n // cancellation gap. Durable state/cursor atomicity belongs to\n // the consumer's own transaction, not to this mask.\n const receipt = yield* restore(onResync(resync))\n const restoredCursor = () =>\n new SyncError({\n code: \"invalid_request\",\n message: \"Recovery must return the restored run cursor at or above its compaction floor\"\n })\n // A receipt that omits its generation restored the floor's\n // history, which the refusal names. The previous cursor's\n // generation is no substitute: a fresh client has none,\n // and a rewind since then has replaced it.\n const captured = yield* Effect.try({\n try: () => ({\n runId: receipt.runId,\n afterSeq: receipt.afterSeq,\n generation: receipt.generation ?? refusedGeneration\n }),\n catch: restoredCursor\n })\n if (\n !Schema.is(RunCursor)(captured) || captured.runId !== runId || captured.afterSeq < checkpointSeq\n ) {\n return yield* Effect.fail(restoredCursor())\n }\n const applied = captured\n if (applied.generation === undefined) {\n return yield* Effect.fail(\n new SyncError({\n code: \"protocol_violation\",\n message: \"Compaction refusal names no generation for a receipt that omits one\"\n })\n )\n }\n yield* commit(applied.runId, applied.afterSeq, applied.generation, true)\n return resynced()\n })\n ))\n })\n\n return resynced()\n }))\n\n return SyncClient.of({ snapshot, subscribe, progress })\n })\n\n/**\n * Provides the sync client from the active RPC protocol.\n *\n * @category layers\n * @since 0.1.0\n */\nexport const layer: Layer.Layer<SyncClient, never, RpcClient.Protocol> = Layer.effect(\n SyncClient,\n Effect.flatMap(RpcClient.make(SyncRpcs), (client) => make({ client }))\n)\n\n/**\n * Provides the sync client under an explicit policy. Fails with\n * `invalid_request` when an option is not a positive safe integer, so a bad\n * policy fails the composition rather than every operation under it.\n *\n * @category layers\n * @since 1.0.0-rc.0\n */\nexport const layerWith = (options: Options): Layer.Layer<SyncClient, SyncError, RpcClient.Protocol> =>\n Layer.effect(SyncClient, Effect.flatMap(RpcClient.make(SyncRpcs), (client) => makeWith({ ...options, client })))\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,YAAuB;AACvB,cAAyB;AACzB,aAAwB;AACxB,YAAuB;AACvB,UAAqB;AACrB,eAA0B;AAC1B,aAAwB;AACxB,aAAwB;AACxB,gBAA2B;AAC3B,qBAAgC;AAGhC,gBAA2B;AAC3B,uBAAkD;AAClD,2BAAwC;AACxC,uBAAkC;AAClC,uBA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