@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,118 @@
1
+ import type { ILogger } from "../../logging/types.js";
2
+ import type { ISyncCursorStorage } from "../../storage/interfaces.js";
3
+ import type { IChannel } from "../interfaces.js";
4
+ import { Mailbox } from "../mailbox.js";
5
+ import type { SyncOperation } from "../sync-operation.js";
6
+ import type { RemoteFilter } from "../types.js";
7
+ /**
8
+ * Configuration parameters for GqlChannel
9
+ */
10
+ export type GqlChannelConfig = {
11
+ /** The GraphQL endpoint URL */
12
+ url: string;
13
+ /** Authentication token for the remote */
14
+ authToken?: string;
15
+ /** Polling interval in milliseconds (default: 5000) */
16
+ pollIntervalMs?: number;
17
+ /** Base delay for exponential backoff retries in milliseconds (default: 1000) */
18
+ retryBaseDelayMs?: number;
19
+ /** Maximum delay for exponential backoff retries in milliseconds (default: 300000) */
20
+ retryMaxDelayMs?: number;
21
+ /** Maximum number of consecutive failures before marking as error (default: 5) */
22
+ maxFailures?: number;
23
+ /** Custom fetch function for testing (default: global fetch) */
24
+ fetchFn?: typeof fetch;
25
+ /** Collection ID to synchronize */
26
+ collectionId: string;
27
+ /** Filter to apply to operations */
28
+ filter: RemoteFilter;
29
+ };
30
+ /**
31
+ * GraphQL-based synchronization channel for network communication between reactors.
32
+ */
33
+ export declare class GqlChannel implements IChannel {
34
+ private readonly logger;
35
+ readonly inbox: Mailbox<SyncOperation>;
36
+ readonly outbox: Mailbox<SyncOperation>;
37
+ readonly deadLetter: Mailbox<SyncOperation>;
38
+ private readonly channelId;
39
+ private readonly remoteName;
40
+ private readonly cursorStorage;
41
+ private readonly config;
42
+ private isShutdown;
43
+ private pollTimer?;
44
+ private failureCount;
45
+ private lastSuccessUtcMs?;
46
+ private lastFailureUtcMs?;
47
+ constructor(logger: ILogger, channelId: string, remoteName: string, cursorStorage: ISyncCursorStorage, config: GqlChannelConfig);
48
+ /**
49
+ * Shuts down the channel and prevents further operations.
50
+ */
51
+ shutdown(): void;
52
+ /**
53
+ * Initializes the channel by registering it on the remote server and starting polling.
54
+ */
55
+ init(): Promise<void>;
56
+ /**
57
+ * Starts the polling loop to fetch operations from the remote.
58
+ */
59
+ private startPolling;
60
+ /**
61
+ * Polls the remote for new sync envelopes.
62
+ */
63
+ private poll;
64
+ /**
65
+ * Handles polling errors with exponential backoff.
66
+ */
67
+ private handlePollError;
68
+ /**
69
+ * Recovers from a "Channel not found" error by re-registering and restarting polling.
70
+ */
71
+ private recoverFromChannelNotFound;
72
+ /**
73
+ * Queries the remote GraphQL endpoint for sync envelopes.
74
+ */
75
+ private pollSyncEnvelopes;
76
+ /**
77
+ * Registers or updates this channel on the remote server via GraphQL mutation.
78
+ */
79
+ private touchRemoteChannel;
80
+ /**
81
+ * Handles sync operations added to the outbox by sending them to the remote.
82
+ */
83
+ private handleOutboxAdded;
84
+ /**
85
+ * Pushes a sync operation to the remote via GraphQL mutation.
86
+ */
87
+ private pushSyncOperation;
88
+ /**
89
+ * Serializes a SyncEnvelope for GraphQL transport.
90
+ *
91
+ * Signatures are serialized as comma-separated strings since GraphQL schema
92
+ * defines them as [String!]!. Extra context fields (resultingState, ordinal)
93
+ * are stripped since they are not defined in OperationContextInput.
94
+ */
95
+ private serializeEnvelope;
96
+ /**
97
+ * Serializes an action for GraphQL transport, converting signature tuples to strings.
98
+ */
99
+ private serializeAction;
100
+ /**
101
+ * Executes a GraphQL query or mutation against the remote endpoint.
102
+ */
103
+ private executeGraphQL;
104
+ /**
105
+ * Updates the synchronization cursor for this channel's remote.
106
+ */
107
+ updateCursor(cursorOrdinal: number): Promise<void>;
108
+ /**
109
+ * Gets the current health status of the channel.
110
+ */
111
+ getHealth(): {
112
+ state: "idle" | "running" | "error";
113
+ lastSuccessUtcMs?: number;
114
+ lastFailureUtcMs?: number;
115
+ failureCount: number;
116
+ };
117
+ }
118
+ //# sourceMappingURL=gql-channel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gql-channel.d.ts","sourceRoot":"","sources":["../../../../src/sync/channels/gql-channel.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAEtE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EAAgB,YAAY,EAAgB,MAAM,aAAa,CAAC;AAI5E;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,+BAA+B;IAC/B,GAAG,EAAE,MAAM,CAAC;IACZ,0CAA0C;IAC1C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,uDAAuD;IACvD,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,iFAAiF;IACjF,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,sFAAsF;IACtF,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,kFAAkF;IAClF,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gEAAgE;IAChE,OAAO,CAAC,EAAE,OAAO,KAAK,CAAC;IACv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H,OAAO,CAAC,iBAAiB;IAyBzB;;OAEG;IACH,OAAO,CAAC,eAAe;IAoBvB;;OAEG;YACW,cAAc;IA4D5B;;OAEG;IACG,YAAY,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAUxD;;OAEG;IACH,SAAS,IAAI;QACX,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC;QACpC,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAC1B,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAC1B,YAAY,EAAE,MAAM,CAAC;KACtB;CAaF"}
@@ -0,0 +1,423 @@
1
+ import { ChannelError } from "../errors.js";
2
+ import { Mailbox } from "../mailbox.js";
3
+ import { ChannelErrorSource } from "../types.js";
4
+ import { envelopesToSyncOperations } from "./utils.js";
5
+ /**
6
+ * GraphQL-based synchronization channel for network communication between reactors.
7
+ */
8
+ export class GqlChannel {
9
+ logger;
10
+ inbox;
11
+ outbox;
12
+ deadLetter;
13
+ channelId;
14
+ remoteName;
15
+ cursorStorage;
16
+ config;
17
+ isShutdown;
18
+ pollTimer;
19
+ failureCount;
20
+ lastSuccessUtcMs;
21
+ lastFailureUtcMs;
22
+ constructor(logger, channelId, remoteName, cursorStorage, config) {
23
+ this.logger = logger;
24
+ this.channelId = channelId;
25
+ this.remoteName = remoteName;
26
+ this.cursorStorage = cursorStorage;
27
+ this.config = {
28
+ url: config.url,
29
+ authToken: config.authToken,
30
+ pollIntervalMs: config.pollIntervalMs ?? 10000,
31
+ retryBaseDelayMs: config.retryBaseDelayMs ?? 1000,
32
+ retryMaxDelayMs: config.retryMaxDelayMs ?? 300000,
33
+ maxFailures: config.maxFailures ?? 5,
34
+ fetchFn: config.fetchFn,
35
+ collectionId: config.collectionId,
36
+ filter: config.filter,
37
+ };
38
+ this.isShutdown = false;
39
+ this.failureCount = 0;
40
+ this.inbox = new Mailbox();
41
+ this.outbox = new Mailbox();
42
+ this.deadLetter = new Mailbox();
43
+ this.outbox.onAdded((syncOp) => {
44
+ this.handleOutboxAdded(syncOp);
45
+ });
46
+ }
47
+ /**
48
+ * Shuts down the channel and prevents further operations.
49
+ */
50
+ shutdown() {
51
+ this.isShutdown = true;
52
+ if (this.pollTimer) {
53
+ clearTimeout(this.pollTimer);
54
+ this.pollTimer = undefined;
55
+ }
56
+ }
57
+ /**
58
+ * Initializes the channel by registering it on the remote server and starting polling.
59
+ */
60
+ async init() {
61
+ await this.touchRemoteChannel();
62
+ this.startPolling();
63
+ }
64
+ /**
65
+ * Starts the polling loop to fetch operations from the remote.
66
+ */
67
+ startPolling() {
68
+ if (this.isShutdown) {
69
+ return;
70
+ }
71
+ void this.poll().then(() => {
72
+ this.pollTimer = setTimeout(() => {
73
+ this.startPolling(); // Schedule next poll
74
+ }, this.config.pollIntervalMs);
75
+ });
76
+ }
77
+ /**
78
+ * Polls the remote for new sync envelopes.
79
+ */
80
+ async poll() {
81
+ if (this.isShutdown) {
82
+ return;
83
+ }
84
+ if (this.failureCount >= this.config.maxFailures) {
85
+ return;
86
+ }
87
+ let cursor;
88
+ try {
89
+ cursor = await this.cursorStorage.get(this.remoteName);
90
+ }
91
+ catch (error) {
92
+ this.handlePollError(error);
93
+ return;
94
+ }
95
+ const cursorOrdinal = cursor.cursorOrdinal;
96
+ let envelopes;
97
+ try {
98
+ envelopes = await this.pollSyncEnvelopes(cursorOrdinal);
99
+ }
100
+ catch (error) {
101
+ this.handlePollError(error);
102
+ return;
103
+ }
104
+ let maxCursorOrdinal = cursorOrdinal;
105
+ for (const envelope of envelopes) {
106
+ if (envelope.type.toLowerCase() === "operations" && envelope.operations) {
107
+ const syncOps = envelopesToSyncOperations(envelope, this.remoteName);
108
+ for (const syncOp of syncOps) {
109
+ syncOp.transported();
110
+ this.inbox.add(syncOp);
111
+ }
112
+ }
113
+ if (envelope.cursor && envelope.cursor.cursorOrdinal > maxCursorOrdinal) {
114
+ maxCursorOrdinal = envelope.cursor.cursorOrdinal;
115
+ }
116
+ }
117
+ if (maxCursorOrdinal > cursorOrdinal) {
118
+ try {
119
+ await this.updateCursor(maxCursorOrdinal);
120
+ }
121
+ catch (error) {
122
+ this.handlePollError(error);
123
+ return;
124
+ }
125
+ }
126
+ this.lastSuccessUtcMs = Date.now();
127
+ this.failureCount = 0;
128
+ }
129
+ /**
130
+ * Handles polling errors with exponential backoff.
131
+ */
132
+ handlePollError(error) {
133
+ const err = error instanceof Error ? error : new Error(String(error));
134
+ if (err.message.includes("Channel not found")) {
135
+ this.recoverFromChannelNotFound();
136
+ return;
137
+ }
138
+ this.failureCount++;
139
+ this.lastFailureUtcMs = Date.now();
140
+ const channelError = new ChannelError(ChannelErrorSource.Inbox, err);
141
+ this.logger.error("GqlChannel poll error (@FailureCount/@MaxFailures): @Error", this.failureCount, this.config.maxFailures, channelError);
142
+ if (this.failureCount >= this.config.maxFailures) {
143
+ this.logger.error("GqlChannel @ChannelId exceeded failure threshold, stopping polls", this.channelId);
144
+ }
145
+ }
146
+ /**
147
+ * Recovers from a "Channel not found" error by re-registering and restarting polling.
148
+ */
149
+ recoverFromChannelNotFound() {
150
+ this.logger.info("GqlChannel @ChannelId not found on remote, re-registering...", this.channelId);
151
+ if (this.pollTimer) {
152
+ clearTimeout(this.pollTimer);
153
+ this.pollTimer = undefined;
154
+ }
155
+ void this.touchRemoteChannel()
156
+ .then(() => {
157
+ this.logger.info("GqlChannel @ChannelId re-registered successfully", this.channelId);
158
+ this.failureCount = 0;
159
+ this.startPolling();
160
+ })
161
+ .catch((recoveryError) => {
162
+ this.logger.error("GqlChannel @ChannelId failed to re-register: @Error", this.channelId, recoveryError);
163
+ this.failureCount++;
164
+ this.lastFailureUtcMs = Date.now();
165
+ this.pollTimer = setTimeout(() => {
166
+ this.startPolling();
167
+ }, this.config.pollIntervalMs);
168
+ });
169
+ }
170
+ /**
171
+ * Queries the remote GraphQL endpoint for sync envelopes.
172
+ */
173
+ async pollSyncEnvelopes(cursorOrdinal) {
174
+ const query = `
175
+ query PollSyncEnvelopes($channelId: String!, $cursorOrdinal: Int!) {
176
+ pollSyncEnvelopes(channelId: $channelId, cursorOrdinal: $cursorOrdinal) {
177
+ type
178
+ channelMeta {
179
+ id
180
+ }
181
+ operations {
182
+ operation {
183
+ index
184
+ timestampUtcMs
185
+ hash
186
+ skip
187
+ error
188
+ id
189
+ action {
190
+ id
191
+ type
192
+ timestampUtcMs
193
+ input
194
+ scope
195
+ attachments {
196
+ data
197
+ mimeType
198
+ hash
199
+ extension
200
+ fileName
201
+ }
202
+ context {
203
+ signer {
204
+ user {
205
+ address
206
+ networkId
207
+ chainId
208
+ }
209
+ app {
210
+ name
211
+ key
212
+ }
213
+ signatures
214
+ }
215
+ }
216
+ }
217
+ }
218
+ context {
219
+ documentId
220
+ documentType
221
+ scope
222
+ branch
223
+ }
224
+ }
225
+ cursor {
226
+ remoteName
227
+ cursorOrdinal
228
+ lastSyncedAtUtcMs
229
+ }
230
+ }
231
+ }
232
+ `;
233
+ const variables = {
234
+ channelId: this.channelId,
235
+ cursorOrdinal,
236
+ };
237
+ const response = await this.executeGraphQL(query, variables);
238
+ return response.pollSyncEnvelopes;
239
+ }
240
+ /**
241
+ * Registers or updates this channel on the remote server via GraphQL mutation.
242
+ */
243
+ async touchRemoteChannel() {
244
+ const mutation = `
245
+ mutation TouchChannel($input: TouchChannelInput!) {
246
+ touchChannel(input: $input)
247
+ }
248
+ `;
249
+ const variables = {
250
+ input: {
251
+ id: this.channelId,
252
+ name: this.channelId,
253
+ collectionId: this.config.collectionId,
254
+ filter: {
255
+ documentId: this.config.filter.documentId,
256
+ scope: this.config.filter.scope,
257
+ branch: this.config.filter.branch,
258
+ },
259
+ },
260
+ };
261
+ await this.executeGraphQL(mutation, variables);
262
+ }
263
+ /**
264
+ * Handles sync operations added to the outbox by sending them to the remote.
265
+ */
266
+ handleOutboxAdded(syncOp) {
267
+ if (this.isShutdown) {
268
+ return;
269
+ }
270
+ // Execute async but don't await (fire and forget with error handling)
271
+ this.pushSyncOperation(syncOp).catch((error) => {
272
+ const err = error instanceof Error ? error : new Error(String(error));
273
+ const channelError = new ChannelError(ChannelErrorSource.Outbox, err);
274
+ syncOp.failed(channelError);
275
+ this.deadLetter.add(syncOp);
276
+ this.outbox.remove(syncOp);
277
+ });
278
+ }
279
+ /**
280
+ * Pushes a sync operation to the remote via GraphQL mutation.
281
+ */
282
+ async pushSyncOperation(syncOp) {
283
+ syncOp.started();
284
+ this.logger.debug("[PUSH]: @Operations", syncOp.operations.map((op) => `(${op.context.documentId}, ${op.context.branch}, ${op.context.scope}, ${op.operation.index})`));
285
+ const envelope = {
286
+ type: "operations",
287
+ channelMeta: { id: this.channelId },
288
+ operations: syncOp.operations,
289
+ };
290
+ const mutation = `
291
+ mutation PushSyncEnvelope($envelope: SyncEnvelopeInput!) {
292
+ pushSyncEnvelope(envelope: $envelope)
293
+ }
294
+ `;
295
+ const variables = {
296
+ envelope: this.serializeEnvelope(envelope),
297
+ };
298
+ await this.executeGraphQL(mutation, variables);
299
+ // Successfully sent - the outbox will be cleared when we receive ACK
300
+ // For now, we optimistically remove from outbox
301
+ this.outbox.remove(syncOp);
302
+ }
303
+ /**
304
+ * Serializes a SyncEnvelope for GraphQL transport.
305
+ *
306
+ * Signatures are serialized as comma-separated strings since GraphQL schema
307
+ * defines them as [String!]!. Extra context fields (resultingState, ordinal)
308
+ * are stripped since they are not defined in OperationContextInput.
309
+ */
310
+ serializeEnvelope(envelope) {
311
+ return {
312
+ type: envelope.type.toUpperCase(),
313
+ channelMeta: envelope.channelMeta,
314
+ operations: envelope.operations?.map((opWithContext) => ({
315
+ operation: {
316
+ index: opWithContext.operation.index,
317
+ timestampUtcMs: opWithContext.operation.timestampUtcMs,
318
+ hash: opWithContext.operation.hash,
319
+ skip: opWithContext.operation.skip,
320
+ error: opWithContext.operation.error,
321
+ id: opWithContext.operation.id,
322
+ action: this.serializeAction(opWithContext.operation.action),
323
+ },
324
+ context: {
325
+ documentId: opWithContext.context.documentId,
326
+ documentType: opWithContext.context.documentType,
327
+ scope: opWithContext.context.scope,
328
+ branch: opWithContext.context.branch,
329
+ },
330
+ })),
331
+ cursor: envelope.cursor,
332
+ };
333
+ }
334
+ /**
335
+ * Serializes an action for GraphQL transport, converting signature tuples to strings.
336
+ */
337
+ serializeAction(action) {
338
+ const signer = action.context?.signer;
339
+ if (!signer?.signatures) {
340
+ return action;
341
+ }
342
+ return {
343
+ ...action,
344
+ context: {
345
+ ...action.context,
346
+ signer: {
347
+ ...signer,
348
+ signatures: signer.signatures.map((sig) => Array.isArray(sig) ? sig.join(", ") : sig),
349
+ },
350
+ },
351
+ };
352
+ }
353
+ /**
354
+ * Executes a GraphQL query or mutation against the remote endpoint.
355
+ */
356
+ async executeGraphQL(query, variables) {
357
+ const headers = {
358
+ "Content-Type": "application/json",
359
+ };
360
+ if (this.config.authToken) {
361
+ headers["Authorization"] = `Bearer ${this.config.authToken}`;
362
+ }
363
+ const fetchFn = this.config.fetchFn ?? fetch;
364
+ let response;
365
+ try {
366
+ response = await fetchFn(this.config.url, {
367
+ method: "POST",
368
+ headers,
369
+ body: JSON.stringify({
370
+ query,
371
+ variables,
372
+ }),
373
+ });
374
+ }
375
+ catch (error) {
376
+ throw new Error(`GraphQL request failed: ${error instanceof Error ? error.message : String(error)}`);
377
+ }
378
+ if (!response.ok) {
379
+ throw new Error(`GraphQL request failed: ${response.status} ${response.statusText}`);
380
+ }
381
+ let result;
382
+ try {
383
+ result = (await response.json());
384
+ }
385
+ catch (error) {
386
+ throw new Error(`Failed to parse GraphQL response: ${error instanceof Error ? error.message : String(error)}`);
387
+ }
388
+ if (result.errors) {
389
+ throw new Error(`GraphQL errors: ${JSON.stringify(result.errors, null, 2)}`);
390
+ }
391
+ if (!result.data) {
392
+ throw new Error("GraphQL response missing data field");
393
+ }
394
+ return result.data;
395
+ }
396
+ /**
397
+ * Updates the synchronization cursor for this channel's remote.
398
+ */
399
+ async updateCursor(cursorOrdinal) {
400
+ const cursor = {
401
+ remoteName: this.remoteName,
402
+ cursorOrdinal,
403
+ lastSyncedAtUtcMs: Date.now(),
404
+ };
405
+ await this.cursorStorage.upsert(cursor);
406
+ }
407
+ /**
408
+ * Gets the current health status of the channel.
409
+ */
410
+ getHealth() {
411
+ return {
412
+ state: this.failureCount >= this.config.maxFailures
413
+ ? "error"
414
+ : this.failureCount > 0
415
+ ? "running"
416
+ : "idle",
417
+ lastSuccessUtcMs: this.lastSuccessUtcMs,
418
+ lastFailureUtcMs: this.lastFailureUtcMs,
419
+ failureCount: this.failureCount,
420
+ };
421
+ }
422
+ }
423
+ //# sourceMappingURL=gql-channel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gql-channel.js","sourceRoot":"","sources":["../../../../src/sync/channels/gql-channel.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAGxC,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AA0BvD;;GAEG;AACH,MAAM,OAAO,UAAU;IAgBF;IAfV,KAAK,CAAyB;IAC9B,MAAM,CAAyB;IAC/B,UAAU,CAAyB;IAE3B,SAAS,CAAS;IAClB,UAAU,CAAS;IACnB,aAAa,CAAqB;IAClC,MAAM,CAAmB;IAClC,UAAU,CAAU;IACpB,SAAS,CAAkB;IAC3B,YAAY,CAAS;IACrB,gBAAgB,CAAU;IAC1B,gBAAgB,CAAU;IAElC,YACmB,MAAe,EAChC,SAAiB,EACjB,UAAkB,EAClB,aAAiC,EACjC,MAAwB;QAJP,WAAM,GAAN,MAAM,CAAS;QAMhC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,MAAM,GAAG;YACZ,GAAG,EAAE,MAAM,CA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.js";
1
+ export { PollingChannel } from "./polling-channel.js";
2
+ export { GqlChannel, type GqlChannelConfig } from "./gql-channel.js";
3
+ export { GqlChannelFactory } from "./gql-channel-factory.js";
4
+ export { CompositeChannelFactory } from "./composite-channel-factory.js";
2
5
  export { envelopeToSyncOperation } from "./utils.js";
3
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/sync/channels/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/sync/channels/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,KAAK,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AACzE,OAAO,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC"}
@@ -1,3 +1,6 @@
1
- export { InternalChannel } from "./internal-channel.js";
1
+ export { PollingChannel } from "./polling-channel.js";
2
+ export { GqlChannel } from "./gql-channel.js";
3
+ export { GqlChannelFactory } from "./gql-channel-factory.js";
4
+ export { CompositeChannelFactory } from "./composite-channel-factory.js";
2
5
  export { envelopeToSyncOperation } from "./utils.js";
3
6
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/sync/channels/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/sync/channels/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAyB,MAAM,kBAAkB,CAAC;AACrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AACzE,OAAO,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,39 @@
1
+ import type { ISyncCursorStorage } from "../../storage/interfaces.js";
2
+ import type { IChannel } from "../interfaces.js";
3
+ import type { SyncOperation } from "../sync-operation.js";
4
+ import { Mailbox } from "../mailbox.js";
5
+ import type { SyncEnvelope } from "../types.js";
6
+ /**
7
+ * Channel for cursor-based polling by external clients.
8
+ *
9
+ * PollingChannel does NOT auto-remove operations from the outbox.
10
+ * Operations remain until explicitly acknowledged via cursor
11
+ * advancement through updateCursor().
12
+ */
13
+ export declare class PollingChannel implements IChannel {
14
+ readonly inbox: Mailbox<SyncOperation>;
15
+ readonly outbox: Mailbox<SyncOperation>;
16
+ readonly deadLetter: Mailbox<SyncOperation>;
17
+ private readonly channelId;
18
+ private readonly remoteName;
19
+ private readonly cursorStorage;
20
+ private isShutdown;
21
+ constructor(channelId: string, remoteName: string, cursorStorage: ISyncCursorStorage);
22
+ shutdown(): void;
23
+ init(): Promise<void>;
24
+ /**
25
+ * Receives a sync envelope from a peer channel.
26
+ *
27
+ * @param envelope - The sync envelope to receive
28
+ * @throws {PollingChannelError} If channel is shutdown
29
+ */
30
+ receive(envelope: SyncEnvelope): void;
31
+ /**
32
+ * Advances the cursor and removes acknowledged operations from outbox.
33
+ * Operations with ordinal <= cursorOrdinal are considered acknowledged.
34
+ *
35
+ * @param cursorOrdinal - The last processed ordinal (exclusive)
36
+ */
37
+ updateCursor(cursorOrdinal: number): Promise<void>;
38
+ }
39
+ //# sourceMappingURL=polling-channel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"polling-channel.d.ts","sourceRoot":"","sources":["../../../../src/sync/channels/polling-channel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAEtE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,EAAgB,YAAY,EAAE,MAAM,aAAa,CAAC;AAG9D;;;;;;GAMG;AACH,qBAAa,cAAe,YAAW,QAAQ;IAC7C,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;IACvC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;IACxC,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;IAE5C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAqB;IACnD,OAAO,CAAC,UAAU,CAAU;gBAG1B,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,aAAa,EAAE,kBAAkB;IAYnC,QAAQ,IAAI,IAAI;IAIV,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAE3B;;;;;OAKG;IACH,OAAO,CAAC,QAAQ,EAAE,YAAY,GAAG,IAAI;IAgBrC;;;;;OAKG;IACG,YAAY,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAmBzD"}