@powerhousedao/reactor 5.1.0 → 5.2.0-dev.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (225) hide show
  1. package/dist/src/actions/index.d.ts +24 -0
  2. package/dist/src/actions/index.d.ts.map +1 -0
  3. package/dist/src/actions/index.js +76 -0
  4. package/dist/src/actions/index.js.map +1 -0
  5. package/dist/src/cache/document-meta-cache-types.d.ts +114 -0
  6. package/dist/src/cache/document-meta-cache-types.d.ts.map +1 -0
  7. package/dist/src/cache/document-meta-cache-types.js +2 -0
  8. package/dist/src/cache/document-meta-cache-types.js.map +1 -0
  9. package/dist/src/cache/document-meta-cache.d.ts +30 -0
  10. package/dist/src/cache/document-meta-cache.d.ts.map +1 -0
  11. package/dist/src/cache/document-meta-cache.js +128 -0
  12. package/dist/src/cache/document-meta-cache.js.map +1 -0
  13. package/dist/src/cache/kysely-operation-index.d.ts +4 -2
  14. package/dist/src/cache/kysely-operation-index.d.ts.map +1 -1
  15. package/dist/src/cache/kysely-operation-index.js +67 -24
  16. package/dist/src/cache/kysely-operation-index.js.map +1 -1
  17. package/dist/src/cache/kysely-write-cache.d.ts.map +1 -1
  18. package/dist/src/cache/kysely-write-cache.js +3 -2
  19. package/dist/src/cache/kysely-write-cache.js.map +1 -1
  20. package/dist/src/cache/operation-index-types.d.ts +4 -3
  21. package/dist/src/cache/operation-index-types.d.ts.map +1 -1
  22. package/dist/src/cache/operation-index-types.js.map +1 -1
  23. package/dist/src/client/reactor-client.d.ts +22 -10
  24. package/dist/src/client/reactor-client.d.ts.map +1 -1
  25. package/dist/src/client/reactor-client.js +145 -48
  26. package/dist/src/client/reactor-client.js.map +1 -1
  27. package/dist/src/client/types.d.ts +32 -13
  28. package/dist/src/client/types.d.ts.map +1 -1
  29. package/dist/src/core/reactor-builder.d.ts +19 -12
  30. package/dist/src/core/reactor-builder.d.ts.map +1 -1
  31. package/dist/src/core/reactor-builder.js +127 -37
  32. package/dist/src/core/reactor-builder.js.map +1 -1
  33. package/dist/src/core/{builder.d.ts → reactor-client-builder.d.ts} +20 -4
  34. package/dist/src/core/reactor-client-builder.d.ts.map +1 -0
  35. package/dist/src/core/reactor-client-builder.js +123 -0
  36. package/dist/src/core/reactor-client-builder.js.map +1 -0
  37. package/dist/src/core/reactor.d.ts +14 -16
  38. package/dist/src/core/reactor.d.ts.map +1 -1
  39. package/dist/src/core/reactor.js +101 -110
  40. package/dist/src/core/reactor.js.map +1 -1
  41. package/dist/src/core/types.d.ts +101 -22
  42. package/dist/src/core/types.d.ts.map +1 -1
  43. package/dist/src/core/utils.d.ts +9 -1
  44. package/dist/src/core/utils.d.ts.map +1 -1
  45. package/dist/src/core/utils.js +30 -0
  46. package/dist/src/core/utils.js.map +1 -1
  47. package/dist/src/events/types.d.ts +1 -0
  48. package/dist/src/events/types.d.ts.map +1 -1
  49. package/dist/src/executor/simple-job-executor-manager.d.ts +3 -1
  50. package/dist/src/executor/simple-job-executor-manager.d.ts.map +1 -1
  51. package/dist/src/executor/simple-job-executor-manager.js +10 -7
  52. package/dist/src/executor/simple-job-executor-manager.js.map +1 -1
  53. package/dist/src/executor/simple-job-executor.d.ts +20 -2
  54. package/dist/src/executor/simple-job-executor.d.ts.map +1 -1
  55. package/dist/src/executor/simple-job-executor.js +400 -219
  56. package/dist/src/executor/simple-job-executor.js.map +1 -1
  57. package/dist/src/executor/types.d.ts +2 -0
  58. package/dist/src/executor/types.d.ts.map +1 -1
  59. package/dist/src/executor/types.js.map +1 -1
  60. package/dist/src/executor/util.d.ts +14 -5
  61. package/dist/src/executor/util.d.ts.map +1 -1
  62. package/dist/src/executor/util.js +36 -9
  63. package/dist/src/executor/util.js.map +1 -1
  64. package/dist/src/index.d.ts +17 -6
  65. package/dist/src/index.d.ts.map +1 -1
  66. package/dist/src/index.js +15 -3
  67. package/dist/src/index.js.map +1 -1
  68. package/dist/src/logging/console.d.ts +23 -0
  69. package/dist/src/logging/console.d.ts.map +1 -0
  70. package/dist/src/logging/console.js +108 -0
  71. package/dist/src/logging/console.js.map +1 -0
  72. package/dist/src/logging/types.d.ts +12 -0
  73. package/dist/src/logging/types.d.ts.map +1 -0
  74. package/dist/src/logging/types.js +2 -0
  75. package/dist/src/logging/types.js.map +1 -0
  76. package/dist/src/processors/index.d.ts +3 -0
  77. package/dist/src/processors/index.d.ts.map +1 -0
  78. package/dist/src/processors/index.js +2 -0
  79. package/dist/src/processors/index.js.map +1 -0
  80. package/dist/src/processors/processor-manager.d.ts +38 -0
  81. package/dist/src/processors/processor-manager.d.ts.map +1 -0
  82. package/dist/src/processors/processor-manager.js +165 -0
  83. package/dist/src/processors/processor-manager.js.map +1 -0
  84. package/dist/src/processors/types.d.ts +63 -0
  85. package/dist/src/processors/types.d.ts.map +1 -0
  86. package/dist/src/processors/types.js +2 -0
  87. package/dist/src/processors/types.js.map +1 -0
  88. package/dist/src/processors/utils.d.ts +10 -0
  89. package/dist/src/processors/utils.d.ts.map +1 -0
  90. package/dist/src/processors/utils.js +58 -0
  91. package/dist/src/processors/utils.js.map +1 -0
  92. package/dist/src/queue/types.d.ts +2 -0
  93. package/dist/src/queue/types.d.ts.map +1 -1
  94. package/dist/src/queue/types.js.map +1 -1
  95. package/dist/src/read-models/base-read-model.d.ts +60 -0
  96. package/dist/src/read-models/base-read-model.d.ts.map +1 -0
  97. package/dist/src/read-models/base-read-model.js +143 -0
  98. package/dist/src/read-models/base-read-model.js.map +1 -0
  99. package/dist/src/read-models/coordinator.d.ts +3 -2
  100. package/dist/src/read-models/coordinator.d.ts.map +1 -1
  101. package/dist/src/read-models/coordinator.js +12 -13
  102. package/dist/src/read-models/coordinator.js.map +1 -1
  103. package/dist/src/read-models/document-view.d.ts +6 -7
  104. package/dist/src/read-models/document-view.d.ts.map +1 -1
  105. package/dist/src/read-models/document-view.js +18 -81
  106. package/dist/src/read-models/document-view.js.map +1 -1
  107. package/dist/src/read-models/types.d.ts +2 -1
  108. package/dist/src/read-models/types.d.ts.map +1 -1
  109. package/dist/src/registry/implementation.d.ts +42 -34
  110. package/dist/src/registry/implementation.d.ts.map +1 -1
  111. package/dist/src/registry/implementation.js +168 -48
  112. package/dist/src/registry/implementation.js.map +1 -1
  113. package/dist/src/registry/interfaces.d.ts +69 -8
  114. package/dist/src/registry/interfaces.d.ts.map +1 -1
  115. package/dist/src/shared/errors.d.ts +24 -0
  116. package/dist/src/shared/errors.d.ts.map +1 -1
  117. package/dist/src/shared/errors.js +42 -0
  118. package/dist/src/shared/errors.js.map +1 -1
  119. package/dist/src/shared/types.d.ts +4 -0
  120. package/dist/src/shared/types.d.ts.map +1 -1
  121. package/dist/src/shared/types.js.map +1 -1
  122. package/dist/src/signer/passthrough-signer.d.ts +9 -3
  123. package/dist/src/signer/passthrough-signer.d.ts.map +1 -1
  124. package/dist/src/signer/passthrough-signer.js +13 -0
  125. package/dist/src/signer/passthrough-signer.js.map +1 -1
  126. package/dist/src/signer/types.d.ts +12 -10
  127. package/dist/src/signer/types.d.ts.map +1 -1
  128. package/dist/src/storage/consistency-aware-legacy-storage.d.ts +33 -0
  129. package/dist/src/storage/consistency-aware-legacy-storage.d.ts.map +1 -0
  130. package/dist/src/storage/consistency-aware-legacy-storage.js +65 -0
  131. package/dist/src/storage/consistency-aware-legacy-storage.js.map +1 -0
  132. package/dist/src/storage/interfaces.d.ts +94 -1
  133. package/dist/src/storage/interfaces.d.ts.map +1 -1
  134. package/dist/src/storage/interfaces.js +2 -2
  135. package/dist/src/storage/interfaces.js.map +1 -1
  136. package/dist/src/storage/kysely/store.d.ts +1 -0
  137. package/dist/src/storage/kysely/store.d.ts.map +1 -1
  138. package/dist/src/storage/kysely/store.js +41 -4
  139. package/dist/src/storage/kysely/store.js.map +1 -1
  140. package/dist/src/storage/kysely/sync-cursor-storage.js +2 -2
  141. package/dist/src/storage/kysely/sync-cursor-storage.js.map +1 -1
  142. package/dist/src/storage/kysely/sync-remote-storage.d.ts.map +1 -1
  143. package/dist/src/storage/kysely/sync-remote-storage.js +11 -12
  144. package/dist/src/storage/kysely/sync-remote-storage.js.map +1 -1
  145. package/dist/src/storage/kysely/types.d.ts +6 -6
  146. package/dist/src/storage/migrations/001_create_operation_table.d.ts.map +1 -1
  147. package/dist/src/storage/migrations/001_create_operation_table.js +2 -1
  148. package/dist/src/storage/migrations/001_create_operation_table.js.map +1 -1
  149. package/dist/src/storage/migrations/008_create_view_state_table.d.ts +1 -1
  150. package/dist/src/storage/migrations/008_create_view_state_table.d.ts.map +1 -1
  151. package/dist/src/storage/migrations/008_create_view_state_table.js +2 -1
  152. package/dist/src/storage/migrations/008_create_view_state_table.js.map +1 -1
  153. package/dist/src/storage/migrations/009_create_operation_index_tables.js +1 -1
  154. package/dist/src/storage/migrations/009_create_operation_index_tables.js.map +1 -1
  155. package/dist/src/storage/migrations/010_create_sync_tables.js +5 -5
  156. package/dist/src/storage/migrations/010_create_sync_tables.js.map +1 -1
  157. package/dist/src/storage/migrations/migrator.d.ts +3 -2
  158. package/dist/src/storage/migrations/migrator.d.ts.map +1 -1
  159. package/dist/src/storage/migrations/migrator.js +29 -6
  160. package/dist/src/storage/migrations/migrator.js.map +1 -1
  161. package/dist/src/storage/migrations/run-migrations.js +3 -3
  162. package/dist/src/storage/migrations/run-migrations.js.map +1 -1
  163. package/dist/src/storage/txn.d.ts.map +1 -1
  164. package/dist/src/storage/txn.js +2 -3
  165. package/dist/src/storage/txn.js.map +1 -1
  166. package/dist/src/subs/subscription-notification-read-model.d.ts +17 -0
  167. package/dist/src/subs/subscription-notification-read-model.d.ts.map +1 -0
  168. package/dist/src/subs/subscription-notification-read-model.js +62 -0
  169. package/dist/src/subs/subscription-notification-read-model.js.map +1 -0
  170. package/dist/src/sync/channels/composite-channel-factory.d.ts +30 -0
  171. package/dist/src/sync/channels/composite-channel-factory.d.ts.map +1 -0
  172. package/dist/src/sync/channels/composite-channel-factory.js +87 -0
  173. package/dist/src/sync/channels/composite-channel-factory.js.map +1 -0
  174. package/dist/src/sync/channels/gql-channel-factory.d.ts +25 -0
  175. package/dist/src/sync/channels/gql-channel-factory.d.ts.map +1 -0
  176. package/dist/src/sync/channels/gql-channel-factory.js +76 -0
  177. package/dist/src/sync/channels/gql-channel-factory.js.map +1 -0
  178. package/dist/src/sync/channels/gql-channel.d.ts +118 -0
  179. package/dist/src/sync/channels/gql-channel.d.ts.map +1 -0
  180. package/dist/src/sync/channels/gql-channel.js +423 -0
  181. package/dist/src/sync/channels/gql-channel.js.map +1 -0
  182. package/dist/src/sync/channels/index.d.ts +4 -1
  183. package/dist/src/sync/channels/index.d.ts.map +1 -1
  184. package/dist/src/sync/channels/index.js +4 -1
  185. package/dist/src/sync/channels/index.js.map +1 -1
  186. package/dist/src/sync/channels/polling-channel.d.ts +39 -0
  187. package/dist/src/sync/channels/polling-channel.d.ts.map +1 -0
  188. package/dist/src/sync/channels/polling-channel.js +72 -0
  189. package/dist/src/sync/channels/polling-channel.js.map +1 -0
  190. package/dist/src/sync/channels/utils.d.ts +17 -2
  191. package/dist/src/sync/channels/utils.d.ts.map +1 -1
  192. package/dist/src/sync/channels/utils.js +76 -6
  193. package/dist/src/sync/channels/utils.js.map +1 -1
  194. package/dist/src/sync/errors.d.ts +1 -1
  195. package/dist/src/sync/errors.d.ts.map +1 -1
  196. package/dist/src/sync/errors.js +2 -2
  197. package/dist/src/sync/errors.js.map +1 -1
  198. package/dist/src/sync/index.d.ts +2 -2
  199. package/dist/src/sync/index.d.ts.map +1 -1
  200. package/dist/src/sync/index.js +2 -2
  201. package/dist/src/sync/index.js.map +1 -1
  202. package/dist/src/sync/interfaces.d.ts +33 -3
  203. package/dist/src/sync/interfaces.d.ts.map +1 -1
  204. package/dist/src/sync/sync-builder.d.ts +4 -2
  205. package/dist/src/sync/sync-builder.d.ts.map +1 -1
  206. package/dist/src/sync/sync-builder.js +12 -2
  207. package/dist/src/sync/sync-builder.js.map +1 -1
  208. package/dist/src/sync/sync-manager.d.ts +7 -3
  209. package/dist/src/sync/sync-manager.d.ts.map +1 -1
  210. package/dist/src/sync/sync-manager.js +79 -10
  211. package/dist/src/sync/sync-manager.js.map +1 -1
  212. package/dist/src/sync/types.d.ts +1 -2
  213. package/dist/src/sync/types.d.ts.map +1 -1
  214. package/dist/src/sync/utils.d.ts +19 -0
  215. package/dist/src/sync/utils.d.ts.map +1 -1
  216. package/dist/src/sync/utils.js +44 -0
  217. package/dist/src/sync/utils.js.map +1 -1
  218. package/package.json +6 -5
  219. package/dist/src/core/builder.d.ts.map +0 -1
  220. package/dist/src/core/builder.js +0 -88
  221. package/dist/src/core/builder.js.map +0 -1
  222. package/dist/src/sync/channels/internal-channel.d.ts +0 -57
  223. package/dist/src/sync/channels/internal-channel.d.ts.map +0 -1
  224. package/dist/src/sync/channels/internal-channel.js +0 -106
  225. package/dist/src/sync/channels/internal-channel.js.map +0 -1
@@ -0,0 +1,72 @@
1
+ import { PollingChannelError } from "../errors.js";
2
+ import { Mailbox } from "../mailbox.js";
3
+ import { envelopesToSyncOperations } from "./utils.js";
4
+ /**
5
+ * Channel for cursor-based polling by external clients.
6
+ *
7
+ * PollingChannel does NOT auto-remove operations from the outbox.
8
+ * Operations remain until explicitly acknowledged via cursor
9
+ * advancement through updateCursor().
10
+ */
11
+ export class PollingChannel {
12
+ inbox;
13
+ outbox;
14
+ deadLetter;
15
+ channelId;
16
+ remoteName;
17
+ cursorStorage;
18
+ isShutdown;
19
+ constructor(channelId, remoteName, cursorStorage) {
20
+ this.channelId = channelId;
21
+ this.remoteName = remoteName;
22
+ this.cursorStorage = cursorStorage;
23
+ this.isShutdown = false;
24
+ this.inbox = new Mailbox();
25
+ this.outbox = new Mailbox();
26
+ this.deadLetter = new Mailbox();
27
+ }
28
+ shutdown() {
29
+ this.isShutdown = true;
30
+ }
31
+ async init() { }
32
+ /**
33
+ * Receives a sync envelope from a peer channel.
34
+ *
35
+ * @param envelope - The sync envelope to receive
36
+ * @throws {PollingChannelError} If channel is shutdown
37
+ */
38
+ receive(envelope) {
39
+ if (this.isShutdown) {
40
+ throw new PollingChannelError(`Channel ${this.channelId} is shutdown and cannot receive envelopes`);
41
+ }
42
+ if (envelope.type === "operations" && envelope.operations) {
43
+ const syncOps = envelopesToSyncOperations(envelope, this.remoteName);
44
+ for (const syncOp of syncOps) {
45
+ syncOp.transported();
46
+ this.inbox.add(syncOp);
47
+ }
48
+ }
49
+ }
50
+ /**
51
+ * Advances the cursor and removes acknowledged operations from outbox.
52
+ * Operations with ordinal <= cursorOrdinal are considered acknowledged.
53
+ *
54
+ * @param cursorOrdinal - The last processed ordinal (exclusive)
55
+ */
56
+ async updateCursor(cursorOrdinal) {
57
+ const cursor = {
58
+ remoteName: this.remoteName,
59
+ cursorOrdinal,
60
+ lastSyncedAtUtcMs: Date.now(),
61
+ };
62
+ await this.cursorStorage.upsert(cursor);
63
+ for (const op of this.outbox.items) {
64
+ const maxOrdinal = Math.max(...op.operations.map((o) => o.context.ordinal));
65
+ if (maxOrdinal <= cursorOrdinal) {
66
+ op.executed();
67
+ this.outbox.remove(op);
68
+ }
69
+ }
70
+ }
71
+ }
72
+ //# sourceMappingURL=polling-channel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"polling-channel.js","sourceRoot":"","sources":["../../../../src/sync/channels/polling-channel.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAGnD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC,OAAO,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAEvD;;;;;;GAMG;AACH,MAAM,OAAO,cAAc;IAChB,KAAK,CAAyB;IAC9B,MAAM,CAAyB;IAC/B,UAAU,CAAyB;IAE3B,SAAS,CAAS;IAClB,UAAU,CAAS;IACnB,aAAa,CAAqB;IAC3C,UAAU,CAAU;IAE5B,YACE,SAAiB,EACjB,UAAkB,EAClB,aAAiC;QAEjC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;Q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IAAI,CAAC,GAAG,CACzB,GAAG,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAC/C,CAAC;YACF,IAAI,UAAU,IAAI,aAAa,EAAE,CAAC;gBAChC,EAAE,CAAC,QAAQ,EAAE,CAAC;gBACd,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;YACzB,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
@@ -4,12 +4,27 @@ import type { SyncEnvelope } from "../types.js";
4
4
  * Converts a SyncEnvelope containing operations into a SyncOperation.
5
5
  *
6
6
  * Extracts the necessary metadata from the envelope's operations to create
7
- * a sync operation that can be processed by the receiving channel.
7
+ * a sync operation that can be processed by the receiving channel. Also
8
+ * deserializes any signatures from comma-separated strings back to tuples,
9
+ * as GraphQL transport serializes Signature tuples for compatibility.
8
10
  *
9
11
  * @param envelope - The sync envelope containing operations
10
12
  * @param remoteName - The name of the remote this sync operation is associated with
11
- * @returns A new SyncOperation containing the envelope's operations
13
+ * @returns A new SyncOperation containing the envelope's operations with deserialized signatures
12
14
  * @throws Error if envelope has no operations or operations array is empty
13
15
  */
14
16
  export declare function envelopeToSyncOperation(envelope: SyncEnvelope, remoteName: string): SyncOperation;
17
+ /**
18
+ * Converts a SyncEnvelope containing operations into multiple SyncOperations.
19
+ *
20
+ * This function batches operations by documentId, preserving cross-document ordering.
21
+ * For operations [a1, a2, a3, b1, b2, a4], it returns:
22
+ * - SyncOperation 1: [a1, a2, a3] for doc-a
23
+ * - SyncOperation 2: [b1, b2] for doc-b
24
+ * - SyncOperation 3: [a4] for doc-a
25
+ *
26
+ * This ensures operations are grouped for efficient processing while maintaining
27
+ * causality across documents.
28
+ */
29
+ export declare function envelopesToSyncOperations(envelope: SyncEnvelope, remoteName: string): SyncOperation[];
15
30
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/sync/channels/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAIhD;;;;;;;;;;GAUG;AACH,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,YAAY,EACtB,UAAU,EAAE,MAAM,GACjB,aAAa,CAuBf"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/sync/channels/utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAsDhD;;;;;;;;;;;;GAYG;AACH,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,YAAY,EACtB,UAAU,EAAE,MAAM,GACjB,aAAa,CA2Bf;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,YAAY,EACtB,UAAU,EAAE,MAAM,GACjB,aAAa,EAAE,CAqBjB"}
@@ -1,26 +1,96 @@
1
1
  import { SyncOperation } from "../sync-operation.js";
2
+ import { batchOperationsByDocument } from "../utils.js";
2
3
  let syncOpCounter = 0;
4
+ /**
5
+ * Deserializes a signature from a comma-separated string back to a tuple.
6
+ *
7
+ * GraphQL serializes Signature tuples as comma-separated strings for transport.
8
+ * This function converts them back to the expected [string, string, string, string, string] format.
9
+ */
10
+ function deserializeSignature(sig) {
11
+ if (Array.isArray(sig)) {
12
+ return sig;
13
+ }
14
+ return sig.split(", ");
15
+ }
16
+ /**
17
+ * Deserializes signatures in an operation's signer context from strings back to tuples.
18
+ *
19
+ * When operations are transported via GraphQL, signatures are serialized as comma-separated
20
+ * strings. This function restores them to the Signature tuple format required for verification.
21
+ */
22
+ function deserializeOperationSignatures(opWithContext) {
23
+ const signer = opWithContext.operation.action.context?.signer;
24
+ if (!signer?.signatures || signer.signatures.length === 0) {
25
+ return opWithContext;
26
+ }
27
+ const deserializedSignatures = signer.signatures.map(deserializeSignature);
28
+ const deserializedOperation = {
29
+ ...opWithContext.operation,
30
+ action: {
31
+ ...opWithContext.operation.action,
32
+ context: {
33
+ ...opWithContext.operation.action.context,
34
+ signer: {
35
+ ...signer,
36
+ signatures: deserializedSignatures,
37
+ },
38
+ },
39
+ },
40
+ };
41
+ return {
42
+ ...opWithContext,
43
+ operation: deserializedOperation,
44
+ };
45
+ }
3
46
  /**
4
47
  * Converts a SyncEnvelope containing operations into a SyncOperation.
5
48
  *
6
49
  * Extracts the necessary metadata from the envelope's operations to create
7
- * a sync operation that can be processed by the receiving channel.
50
+ * a sync operation that can be processed by the receiving channel. Also
51
+ * deserializes any signatures from comma-separated strings back to tuples,
52
+ * as GraphQL transport serializes Signature tuples for compatibility.
8
53
  *
9
54
  * @param envelope - The sync envelope containing operations
10
55
  * @param remoteName - The name of the remote this sync operation is associated with
11
- * @returns A new SyncOperation containing the envelope's operations
56
+ * @returns A new SyncOperation containing the envelope's operations with deserialized signatures
12
57
  * @throws Error if envelope has no operations or operations array is empty
13
58
  */
14
59
  export function envelopeToSyncOperation(envelope, remoteName) {
15
60
  if (!envelope.operations || envelope.operations.length === 0) {
16
61
  throw new Error("Cannot create SyncOperation from envelope without operations");
17
62
  }
18
- const operations = envelope.operations;
19
- const firstOp = operations[0];
63
+ const deserializedOperations = envelope.operations.map(deserializeOperationSignatures);
64
+ const firstOp = deserializedOperations[0];
20
65
  const documentId = firstOp.context.documentId;
21
66
  const branch = firstOp.context.branch;
22
- const scopes = [...new Set(operations.map((op) => op.context.scope))];
67
+ const scopes = [
68
+ ...new Set(deserializedOperations.map((op) => op.context.scope)),
69
+ ];
23
70
  const syncOpId = `syncop-${envelope.channelMeta.id}-${Date.now()}-${syncOpCounter++}`;
24
- return new SyncOperation(syncOpId, remoteName, documentId, scopes, branch, operations);
71
+ return new SyncOperation(syncOpId, remoteName, documentId, scopes, branch, deserializedOperations);
72
+ }
73
+ /**
74
+ * Converts a SyncEnvelope containing operations into multiple SyncOperations.
75
+ *
76
+ * This function batches operations by documentId, preserving cross-document ordering.
77
+ * For operations [a1, a2, a3, b1, b2, a4], it returns:
78
+ * - SyncOperation 1: [a1, a2, a3] for doc-a
79
+ * - SyncOperation 2: [b1, b2] for doc-b
80
+ * - SyncOperation 3: [a4] for doc-a
81
+ *
82
+ * This ensures operations are grouped for efficient processing while maintaining
83
+ * causality across documents.
84
+ */
85
+ export function envelopesToSyncOperations(envelope, remoteName) {
86
+ if (!envelope.operations || envelope.operations.length === 0) {
87
+ return [];
88
+ }
89
+ const deserializedOps = envelope.operations.map(deserializeOperationSignatures);
90
+ const batches = batchOperationsByDocument(deserializedOps);
91
+ return batches.map((batch) => {
92
+ const syncOpId = `syncop-${envelope.channelMeta.id}-${Date.now()}-${syncOpCounter++}`;
93
+ return new SyncOperation(syncOpId, remoteName, batch.documentId, [batch.scope], batch.branch, batch.operations);
94
+ });
25
95
  }
26
96
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/sync/channels/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAGrD,IAAI,aAAa,GAAG,CAAC,CAAC;AAEtB;;;;;;;;;;GAUG;AACH,MAAM,UAAU,uBAAuB,CACrC,QAAsB,EACtB,UAAkB;IAElB,IAAI,CAAC,QAAQ,CAAC,UAAU,IAAI,QAAQ,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC7D,MAAM,IAAI,KAAK,CACb,8DAA8D,CAC/D,CAAC;IACJ,CAAC;IAED,MAAM,UAAU,GAAG,QAAQ,CAAC,UAAU,CAAC;IACvC,MAAM,OAAO,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;IAC9B,MAAM,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC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AAM,EACN,sBAAsB,CACvB,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,yBAAyB,CACvC,QAAsB,EACtB,UAAkB;IAElB,IAAI,CAAC,QAAQ,CAAC,UAAU,IAAI,QAAQ,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC7D,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,eAAe,GAAG,QAAQ,CAAC,UAAU,CAAC,GAAG,CAC7C,8BAA8B,CAC/B,CAAC;IACF,MAAM,OAAO,GAAG,yBAAyB,CAAC,eAAe,CAAC,CAAC;IAE3D,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;QAC3B,MAAM,QAAQ,GAAG,UAAU,QAAQ,CAAC,WAAW,CAAC,EAAE,IAAI,IAAI,CAAC,GAAG,EAAE,IAAI,aAAa,EAAE,EAAE,CAAC;QACtF,OAAO,IAAI,aAAa,CACtB,QAAQ,EACR,UAAU,EACV,KAAK,CAAC,UAAU,EAChB,CAAC,KAAK,CAAC,KAAK,CAAC,EACb,KAAK,CAAC,MAAM,EACZ,KAAK,CAAC,UAAU,CACjB,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import type { ChannelErrorSource } from "./types.js";
2
- export declare class InternalChannelError extends Error {
2
+ export declare class PollingChannelError extends Error {
3
3
  constructor(message: string);
4
4
  }
5
5
  export declare class ChannelError extends Error {
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/sync/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAErD,qBAAa,oBAAqB,SAAQ,KAAK;gBACjC,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,YAAa,SAAQ,KAAK;IACrC,MAAM,EAAE,kBAAkB,CAAC;IAC3B,KAAK,EAAE,KAAK,CAAC;gBAED,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,KAAK;CAMrD"}
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/sync/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAErD,qBAAa,mBAAoB,SAAQ,KAAK;gBAChC,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,YAAa,SAAQ,KAAK;IACrC,MAAM,EAAE,kBAAkB,CAAC;IAC3B,KAAK,EAAE,KAAK,CAAC;gBAED,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,KAAK;CAMrD"}
@@ -1,7 +1,7 @@
1
- export class InternalChannelError extends Error {
1
+ export class PollingChannelError extends Error {
2
2
  constructor(message) {
3
3
  super(message);
4
- this.name = "InternalChannelError";
4
+ this.name = "PollingChannelError";
5
5
  }
6
6
  }
7
7
  export class ChannelError extends Error {
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/sync/errors.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IAC7C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;IACrC,CAAC;CACF;AAED,MAAM,OAAO,YAAa,SAAQ,KAAK;IACrC,MAAM,CAAqB;IAC3B,KAAK,CAAQ;IAEb,YAAY,MAA0B,EAAE,KAAY;QAClD,KAAK,CAAC,gBAAgB,MAAM,MAAM,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QACnD,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF"}
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/sync/errors.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAC5C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;CACF;AAED,MAAM,OAAO,YAAa,SAAQ,KAAK;IACrC,MAAM,CAAqB;IAC3B,KAAK,CAAQ;IAEb,YAAY,MAA0B,EAAE,KAAY;QAClD,KAAK,CAAC,gBAAgB,MAAM,MAAM,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QACnD,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF"}
@@ -4,8 +4,8 @@ export type { ChannelConfig, ChannelHealth, SyncOperationErrorType, RemoteFilter
4
4
  export { ChannelErrorSource, SyncOperationStatus } from "./types.js";
5
5
  export { SyncOperation, SyncOperationAggregateError, } from "./sync-operation.js";
6
6
  export { Mailbox, type MailboxItem } from "./mailbox.js";
7
- export { ChannelError, InternalChannelError } from "./errors.js";
8
- export { InternalChannel } from "./channels/index.js";
7
+ export { ChannelError, PollingChannelError } from "./errors.js";
8
+ export { PollingChannel, GqlChannelFactory, CompositeChannelFactory, } from "./channels/index.js";
9
9
  export { SyncManager } from "./sync-manager.js";
10
10
  export { SyncBuilder } from "./sync-builder.js";
11
11
  export { createIdleHealth, filterOperations } from "./utils.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/sync/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,QAAQ,EACR,eAAe,EACf,YAAY,EACZ,MAAM,GACP,MAAM,iBAAiB,CAAC;AAEzB,YAAY,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEzD,YAAY,EACV,aAAa,EACb,aAAa,EACb,sBAAsB,EACtB,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,YAAY,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EACjB,uBAAuB,GACxB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC"}
@@ -1,8 +1,8 @@
1
1
  export { ChannelErrorSource, SyncOperationStatus } from "./types.js";
2
2
  export { SyncOperation, SyncOperationAggregateError, } from "./sync-operation.js";
3
3
  export { Mailbox } from "./mailbox.js";
4
- export { ChannelError, InternalChannelError } from "./errors.js";
5
- export { InternalChannel } from "./channels/index.js";
4
+ export { ChannelError, PollingChannelError } from "./errors.js";
5
+ export { PollingChannel, GqlChannelFactory, CompositeChannelFactory, } from "./channels/index.js";
6
6
  export { SyncManager } from "./sync-manager.js";
7
7
  export { SyncBuilder } from "./sync-builder.js";
8
8
  export { createIdleHealth, filterOperations } from "./utils.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/sync/index.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAErE,OAAO,EACL,aAAa,EACb,2BAA2B,GAC5B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,OAAO,EAAoB,MAAM,cAAc,CAAC;AAEzD,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEjE,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/sync/index.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAErE,OAAO,EACL,aAAa,EACb,2BAA2B,GAC5B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,OAAO,EAAoB,MAAM,cAAc,CAAC;AAEzD,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAEhE,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,uBAAuB,GACxB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC"}
@@ -33,10 +33,23 @@ export interface IChannel {
33
33
  * These sync operations require manual intervention or should be logged for debugging.
34
34
  */
35
35
  deadLetter: Mailbox<SyncOperation>;
36
+ /**
37
+ * Initializes the channel asynchronously.
38
+ * For remote channels, this typically involves registering the channel on the remote server.
39
+ * Must be called after construction before the channel is used.
40
+ */
41
+ init(): Promise<void>;
36
42
  /**
37
43
  * Shuts down the channel and prevents further operations.
38
44
  */
39
45
  shutdown(): void;
46
+ /**
47
+ * Updates the synchronization cursor for this channel.
48
+ * For polling channels, this also removes acknowledged operations from the outbox.
49
+ *
50
+ * @param cursorOrdinal - The last processed ordinal
51
+ */
52
+ updateCursor(cursorOrdinal: number): Promise<void>;
40
53
  }
41
54
  /**
42
55
  * Factory for creating channel instances.
@@ -48,11 +61,15 @@ export interface IChannelFactory {
48
61
  /**
49
62
  * Creates a new channel instance with the given configuration.
50
63
  *
64
+ * @param remoteId - Unique identifier for the remote
65
+ * @param remoteName - Name of the remote
51
66
  * @param config - Channel configuration including type and parameters
52
67
  * @param cursorStorage - Storage for persisting synchronization cursors
68
+ * @param collectionId - Collection ID to synchronize
69
+ * @param filter - Filter to apply to operations
53
70
  * @returns A new channel instance
54
71
  */
55
- instance(config: ChannelConfig, cursorStorage: ISyncCursorStorage): IChannel;
72
+ instance(remoteId: string, remoteName: string, config: ChannelConfig, cursorStorage: ISyncCursorStorage, collectionId: string, filter: RemoteFilter): IChannel;
56
73
  }
57
74
  /**
58
75
  * Represents a configured remote with an active channel.
@@ -61,6 +78,10 @@ export interface IChannelFactory {
61
78
  * The remote name is used as a unique identifier across the system.
62
79
  */
63
80
  export type Remote = {
81
+ /**
82
+ * Unique identifier for this remote.
83
+ */
84
+ id: string;
64
85
  /**
65
86
  * Unique name for this remote.
66
87
  */
@@ -113,7 +134,15 @@ export interface ISyncManager {
113
134
  * @returns The remote
114
135
  * @throws Error if the remote does not exist
115
136
  */
116
- get(name: string): Remote;
137
+ getByName(name: string): Remote;
138
+ /**
139
+ * Gets a remote by ID.
140
+ *
141
+ * @param id - The ID of the remote
142
+ * @returns The remote
143
+ * @throws Error if the remote does not exist
144
+ */
145
+ getById(id: string): Remote;
117
146
  /**
118
147
  * Adds a new remote and starts its channel.
119
148
  *
@@ -125,10 +154,11 @@ export interface ISyncManager {
125
154
  * @param channelConfig - Configuration for the channel type and parameters
126
155
  * @param filter - Optional filter for operations (defaults to no filtering)
127
156
  * @param options - Optional remote configuration options
157
+ * @param id - Optional ID for the remote (generated if not provided)
128
158
  * @returns Promise that resolves with the created remote
129
159
  * @throws Error if a remote with this name already exists
130
160
  */
131
- add(name: string, collectionId: string, channelConfig: ChannelConfig, filter?: RemoteFilter, options?: RemoteOptions): Promise<Remote>;
161
+ add(name: string, collectionId: string, channelConfig: ChannelConfig, filter?: RemoteFilter, options?: RemoteOptions, id?: string): Promise<Remote>;
132
162
  /**
133
163
  * Removes a remote and stops its channel.
134
164
  *
@@ -1 +1 @@
1
- {"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../../src/sync/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0B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Aa,EACrB,aAAa,EAAE,kBAAkB,EACjC,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,YAAY,GACnB,QAAQ,CAAC;CACb;AAED;;;;;GAKG;AACH,MAAM,MAAM,MAAM,GAAG;IACnB;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IAEX;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;;OAGG;IACH,MAAM,EAAE,YAAY,CAAC;IAErB;;OAEG;IACH,OAAO,EAAE,aAAa,CAAC;IAEvB;;OAEG;IACH,OAAO,EAAE,QAAQ,CAAC;CACnB,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B;;;;;;;OAOG;IACH,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzB;;;;;;;OAOG;IACH,QAAQ,IAAI,cAAc,CAAC;IAE3B;;;;;;OAMG;IACH,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IAEhC;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IAE5B;;;;;;;;;;;;;;OAcG;IACH,GAAG,CACD,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,MAAM,EACpB,aAAa,EAAE,aAAa,EAC5B,MAAM,CAAC,EAAE,YAAY,EACrB,OAAO,CAAC,EAAE,aAAa,EACvB,EAAE,CAAC,EAAE,MAAM,GACV,OAAO,CAAC,MAAM,CAAC,CAAC;IAEnB;;;;;;;;;OASG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEpC;;;;OAIG;IACH,IAAI,IAAI,MAAM,EAAE,CAAC;CAClB"}
@@ -1,7 +1,8 @@
1
1
  import type { Kysely } from "kysely";
2
2
  import type { IOperationIndex } from "../cache/operation-index-types.js";
3
- import type { IReactor } from "../core/types.js";
3
+ import type { IReactor, SyncModule } from "../core/types.js";
4
4
  import type { IEventBus } from "../events/interfaces.js";
5
+ import type { ILogger } from "../logging/types.js";
5
6
  import type { ISyncCursorStorage, ISyncRemoteStorage } from "../storage/interfaces.js";
6
7
  import type { Database } from "../storage/kysely/types.js";
7
8
  import type { IChannelFactory, ISyncManager } from "./interfaces.js";
@@ -12,6 +13,7 @@ export declare class SyncBuilder {
12
13
  withChannelFactory(factory: IChannelFactory): this;
13
14
  withRemoteStorage(storage: ISyncRemoteStorage): this;
14
15
  withCursorStorage(storage: ISyncCursorStorage): this;
15
- build(reactor: IReactor, operationIndex: IOperationIndex, eventBus: IEventBus, db: Kysely<Database>): ISyncManager;
16
+ build(reactor: IReactor, logger: ILogger, operationIndex: IOperationIndex, eventBus: IEventBus, db: Kysely<Database>): ISyncManager;
17
+ buildModule(reactor: IReactor, logger: ILogger, operationIndex: IOperationIndex, eventBus: IEventBus, db: Kysely<Database>): SyncModule;
16
18
  }
17
19
  //# sourceMappingURL=sync-builder.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sync-builder.d.ts","sourceRoot":"","sources":["../../../src/sync/sync-builder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,KAAK,EACV,kBAAkB,EAClB,kBAAkB,EACnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAG3D,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAGrE,qBAAa,WAAW;IACtB,OAAO,CAAC,cAAc,CAAC,CAAkB;IACzC,OAAO,CAAC,aAAa,CAAC,CAAqB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KAAK,CACH,OAAO,EAAE,QAAQ,EACjB,MAAM,EAAE,OAAO,EACf,cAAc,EAAE,eAAe,EAC/B,QAAQ,EAAE,SAAS,EACnB,EAAE,EAAE,MAAM,CAAC,QAAQ,CAAC,GACnB,YAAY;IAWf,WAAW,CACT,OAAO,EAAE,QAAQ,EACjB,MAAM,EAAE,OAAO,EACf,cAAc,EAAE,eAAe,EAC/B,QAAQ,EAAE,SAAS,EACnB,EAAE,EAAE,MAAM,CAAC,QAAQ,CAAC,GACnB,UAAU;CAyBd"}
@@ -17,13 +17,23 @@ export class SyncBuilder {
17
17
  this.cursorStorage = storage;
18
18
  return this;
19
19
  }
20
- build(reactor, operationIndex, eventBus, db) {
20
+ build(reactor, logger, operationIndex, eventBus, db) {
21
+ const module = this.buildModule(reactor, logger, operationIndex, eventBus, db);
22
+ return module.syncManager;
23
+ }
24
+ buildModule(reactor, logger, operationIndex, eventBus, db) {
21
25
  if (!this.channelFactory) {
22
26
  throw new Error("Channel factory is required");
23
27
  }
24
28
  const remoteStorage = this.remoteStorage ?? new KyselySyncRemoteStorage(db);
25
29
  const cursorStorage = this.cursorStorage ?? new KyselySyncCursorStorage(db);
26
- return new SyncManager(remoteStorage, cursorStorage, this.channelFactory, operationIndex, reactor, eventBus);
30
+ const syncManager = new SyncManager(logger, remoteStorage, cursorStorage, this.channelFactory, operationIndex, reactor, eventBus);
31
+ return {
32
+ remoteStorage,
33
+ cursorStorage,
34
+ channelFactory: this.channelFactory,
35
+ syncManager,
36
+ };
27
37
  }
28
38
  }
29
39
  //# sourceMappingURL=sync-builder.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"sync-builder.js","sourceRoot":"","sources":["../../../src/sync/sync-builder.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,uBAAuB,EAAE,MAAM,0CAA0C,CAAC;AACnF,OAAO,EAAE,uBAAuB,EAAE,MAAM,0CAA0C,CAAC;AAEnF,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAE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IAAI,CAAC,cAAc,GAAG,OAAO,CAAC;QAC9B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,iBAAiB,CAAC,OAA2B;QAC3C,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC;QAC7B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,iBAAiB,CAAC,OAA2B;QAC3C,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC;QAC7B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK,CACH,OAAiB,EACjB,MAAe,EACf,cAA+B,EAC/B,QAAmB,EACnB,EAAoB;QAEpB,MAAM,MAAM,GAAG,IAAI,CAAC,WAAW,CAC7B,OAAO,EACP,MAAM,EACN,cAAc,EACd,QAAQ,EACR,EAAE,CACH,CAAC;QACF,OAAO,MAAM,CAAC,WAAW,CAAC;IAC5B,CAAC;IAED,WAAW,CACT,OAAiB,EACjB,MAAe,EACf,cAA+B,EAC/B,QAAmB,EACnB,EAAoB;QAEpB,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC;YACzB,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;QACjD,CAAC;QAED,MAAM,aAAa,GAAG,IAAI,CAAC,aAAa,IAAI,IAAI,uBAAuB,CAAC,EAAE,CAAC,CAAC;QAC5E,MAAM,aAAa,GAAG,IAAI,CAAC,aAAa,IAAI,IAAI,uBAAuB,CAAC,EAAE,CAAC,CAAC;QAE5E,MAAM,WAAW,GAAG,IAAI,WAAW,CACjC,MAAM,EACN,aAAa,EACb,aAAa,EACb,IAAI,CAAC,cAAc,EACnB,cAAc,EACd,OAAO,EACP,QAAQ,CACT,CAAC;QAEF,OAAO;YACL,aAAa;YACb,aAAa;YACb,cAAc,EAAE,IAAI,CAAC,cAAc;YACnC,WAAW;SACZ,CAAC;IACJ,CAAC;CACF"}
@@ -1,11 +1,13 @@
1
1
  import type { IOperationIndex } from "../cache/operation-index-types.js";
2
2
  import type { IReactor } from "../core/types.js";
3
3
  import type { IEventBus } from "../events/interfaces.js";
4
+ import type { ILogger } from "../logging/types.js";
4
5
  import { type JobInfo, type ShutdownStatus } from "../shared/types.js";
5
6
  import type { ISyncCursorStorage, ISyncRemoteStorage } from "../storage/interfaces.js";
6
7
  import type { IChannelFactory, ISyncManager, Remote } from "./interfaces.js";
7
8
  import type { ChannelConfig, RemoteFilter, RemoteOptions } from "./types.js";
8
9
  export declare class SyncManager implements ISyncManager {
10
+ private readonly logger;
9
11
  private readonly remoteStorage;
10
12
  private readonly cursorStorage;
11
13
  private readonly channelFactory;
@@ -17,11 +19,13 @@ export declare class SyncManager implements ISyncManager {
17
19
  private isShutdown;
18
20
  private eventUnsubscribe?;
19
21
  loadJobs: Map<string, JobInfo>;
20
- constructor(remoteStorage: ISyncRemoteStorage, cursorStorage: ISyncCursorStorage, channelFactory: IChannelFactory, operationIndex: IOperationIndex, reactor: IReactor, eventBus: IEventBus);
22
+ constructor(logger: ILogger, remoteStorage: ISyncRemoteStorage, cursorStorage: ISyncCursorStorage, channelFactory: IChannelFactory, operationIndex: IOperationIndex, reactor: IReactor, eventBus: IEventBus);
21
23
  startup(): Promise<void>;
22
24
  shutdown(): ShutdownStatus;
23
- get(name: string): Remote;
24
- add(name: string, collectionId: string, channelConfig: ChannelConfig, filter?: RemoteFilter, options?: RemoteOptions): Promise<Remote>;
25
+ getByName(name: string): Remote;
26
+ getById(id: string): Remote;
27
+ add(name: string, collectionId: string, channelConfig: ChannelConfig, filter?: RemoteFilter, options?: RemoteOptions, id?: string): Promise<Remote>;
28
+ private backfillOutbox;
25
29
  remove(name: string): Promise<void>;
26
30
  list(): Remote[];
27
31
  private wireChannelCallbacks;
@@ -1 +1 @@
1
- {"version":3,"file":"sync-manager.d.ts","sourceRoot":"","sources":["../../../src/sync/sync-manager.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACjD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