@powerhousedao/reactor 6.0.0-dev.7 → 6.0.0-dev.78

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 (376) hide show
  1. package/dist/src/cache/collection-membership-cache.d.ts +13 -0
  2. package/dist/src/cache/collection-membership-cache.d.ts.map +1 -0
  3. package/dist/src/cache/document-meta-cache.d.ts.map +1 -1
  4. package/dist/src/cache/kysely-operation-index.d.ts +6 -1
  5. package/dist/src/cache/kysely-operation-index.d.ts.map +1 -1
  6. package/dist/src/cache/kysely-write-cache.d.ts +9 -2
  7. package/dist/src/cache/kysely-write-cache.d.ts.map +1 -1
  8. package/dist/src/cache/operation-index-types.d.ts +16 -2
  9. package/dist/src/cache/operation-index-types.d.ts.map +1 -1
  10. package/dist/src/cache/write/interfaces.d.ts +7 -2
  11. package/dist/src/cache/write/interfaces.d.ts.map +1 -1
  12. package/dist/src/client/reactor-client.d.ts +13 -10
  13. package/dist/src/client/reactor-client.d.ts.map +1 -1
  14. package/dist/src/client/types.d.ts +25 -6
  15. package/dist/src/client/types.d.ts.map +1 -1
  16. package/dist/src/core/reactor-builder.d.ts +23 -10
  17. package/dist/src/core/reactor-builder.d.ts.map +1 -1
  18. package/dist/src/core/reactor-client-builder.d.ts +5 -4
  19. package/dist/src/core/reactor-client-builder.d.ts.map +1 -1
  20. package/dist/src/core/reactor.d.ts +20 -80
  21. package/dist/src/core/reactor.d.ts.map +1 -1
  22. package/dist/src/core/types.d.ts +64 -28
  23. package/dist/src/core/types.d.ts.map +1 -1
  24. package/dist/src/core/utils.d.ts +39 -3
  25. package/dist/src/core/utils.d.ts.map +1 -1
  26. package/dist/src/events/types.d.ts +35 -10
  27. package/dist/src/events/types.d.ts.map +1 -1
  28. package/dist/src/executor/document-action-handler.d.ts +37 -0
  29. package/dist/src/executor/document-action-handler.d.ts.map +1 -0
  30. package/dist/src/executor/signature-verifier.d.ts +9 -0
  31. package/dist/src/executor/signature-verifier.d.ts.map +1 -0
  32. package/dist/src/executor/simple-job-executor-manager.d.ts +6 -1
  33. package/dist/src/executor/simple-job-executor-manager.d.ts.map +1 -1
  34. package/dist/src/executor/simple-job-executor.d.ts +6 -46
  35. package/dist/src/executor/simple-job-executor.d.ts.map +1 -1
  36. package/dist/src/executor/types.d.ts +1 -3
  37. package/dist/src/executor/types.d.ts.map +1 -1
  38. package/dist/src/executor/util.d.ts +12 -2
  39. package/dist/src/executor/util.d.ts.map +1 -1
  40. package/dist/src/index.d.ts +11 -9
  41. package/dist/src/index.d.ts.map +1 -1
  42. package/dist/src/index.js +20208 -61
  43. package/dist/src/job-tracker/in-memory-job-tracker.d.ts +4 -3
  44. package/dist/src/job-tracker/in-memory-job-tracker.d.ts.map +1 -1
  45. package/dist/src/job-tracker/interfaces.d.ts +3 -1
  46. package/dist/src/job-tracker/interfaces.d.ts.map +1 -1
  47. package/dist/src/logging/console.d.ts +1 -22
  48. package/dist/src/logging/console.d.ts.map +1 -1
  49. package/dist/src/logging/types.d.ts +1 -11
  50. package/dist/src/logging/types.d.ts.map +1 -1
  51. package/dist/src/processors/index.d.ts +1 -1
  52. package/dist/src/processors/index.d.ts.map +1 -1
  53. package/dist/src/processors/processor-manager.d.ts +19 -6
  54. package/dist/src/processors/processor-manager.d.ts.map +1 -1
  55. package/dist/src/processors/relational/types.d.ts +2 -0
  56. package/dist/src/processors/relational/types.d.ts.map +1 -0
  57. package/dist/src/processors/relational/utils.d.ts +2 -0
  58. package/dist/src/processors/relational/utils.d.ts.map +1 -0
  59. package/dist/src/processors/utils.d.ts +3 -2
  60. package/dist/src/processors/utils.d.ts.map +1 -1
  61. package/dist/src/queue/job-execution-handle.d.ts +3 -0
  62. package/dist/src/queue/job-execution-handle.d.ts.map +1 -1
  63. package/dist/src/queue/queue.d.ts +30 -1
  64. package/dist/src/queue/queue.d.ts.map +1 -1
  65. package/dist/src/queue/types.d.ts +4 -3
  66. package/dist/src/queue/types.d.ts.map +1 -1
  67. package/dist/src/read-models/base-read-model.d.ts +11 -9
  68. package/dist/src/read-models/base-read-model.d.ts.map +1 -1
  69. package/dist/src/read-models/coordinator.d.ts +2 -2
  70. package/dist/src/read-models/coordinator.d.ts.map +1 -1
  71. package/dist/src/read-models/document-view.d.ts +7 -4
  72. package/dist/src/read-models/document-view.d.ts.map +1 -1
  73. package/dist/src/read-models/interfaces.d.ts +1 -1
  74. package/dist/src/read-models/interfaces.d.ts.map +1 -1
  75. package/dist/src/read-models/types.d.ts +16 -0
  76. package/dist/src/read-models/types.d.ts.map +1 -1
  77. package/dist/src/registry/document-model-resolver.d.ts +29 -0
  78. package/dist/src/registry/document-model-resolver.d.ts.map +1 -0
  79. package/dist/src/registry/implementation.d.ts +4 -0
  80. package/dist/src/registry/implementation.d.ts.map +1 -1
  81. package/dist/src/registry/index.d.ts +3 -1
  82. package/dist/src/registry/index.d.ts.map +1 -1
  83. package/dist/src/registry/interfaces.d.ts +8 -0
  84. package/dist/src/registry/interfaces.d.ts.map +1 -1
  85. package/dist/src/shared/awaiter.d.ts +2 -2
  86. package/dist/src/shared/awaiter.d.ts.map +1 -1
  87. package/dist/src/shared/collect-all-pages.d.ts +7 -0
  88. package/dist/src/shared/collect-all-pages.d.ts.map +1 -0
  89. package/dist/src/shared/drive-url.d.ts +15 -0
  90. package/dist/src/shared/drive-url.d.ts.map +1 -0
  91. package/dist/src/shared/errors.d.ts +9 -0
  92. package/dist/src/shared/errors.d.ts.map +1 -1
  93. package/dist/src/shared/factories.d.ts +6 -2
  94. package/dist/src/shared/factories.d.ts.map +1 -1
  95. package/dist/src/shared/types.d.ts +32 -6
  96. package/dist/src/shared/types.d.ts.map +1 -1
  97. package/dist/src/signer/passthrough-signer.d.ts +1 -1
  98. package/dist/src/signer/passthrough-signer.d.ts.map +1 -1
  99. package/dist/src/storage/interfaces.d.ts +238 -124
  100. package/dist/src/storage/interfaces.d.ts.map +1 -1
  101. package/dist/src/storage/kysely/document-indexer.d.ts +17 -18
  102. package/dist/src/storage/kysely/document-indexer.d.ts.map +1 -1
  103. package/dist/src/storage/kysely/store.d.ts +5 -4
  104. package/dist/src/storage/kysely/store.d.ts.map +1 -1
  105. package/dist/src/storage/kysely/sync-cursor-storage.d.ts +1 -1
  106. package/dist/src/storage/kysely/sync-cursor-storage.d.ts.map +1 -1
  107. package/dist/src/storage/kysely/sync-dead-letter-storage.d.ts +17 -0
  108. package/dist/src/storage/kysely/sync-dead-letter-storage.d.ts.map +1 -0
  109. package/dist/src/storage/kysely/types.d.ts +22 -0
  110. package/dist/src/storage/kysely/types.d.ts.map +1 -1
  111. package/dist/src/storage/migrations/011_add_cursor_type_column.d.ts +3 -0
  112. package/dist/src/storage/migrations/011_add_cursor_type_column.d.ts.map +1 -0
  113. package/dist/src/storage/migrations/012_add_source_remote_column.d.ts +3 -0
  114. package/dist/src/storage/migrations/012_add_source_remote_column.d.ts.map +1 -0
  115. package/dist/src/storage/migrations/013_create_sync_dead_letters_table.d.ts +3 -0
  116. package/dist/src/storage/migrations/013_create_sync_dead_letters_table.d.ts.map +1 -0
  117. package/dist/src/storage/migrations/014_create_processor_cursor_table.d.ts +3 -0
  118. package/dist/src/storage/migrations/014_create_processor_cursor_table.d.ts.map +1 -0
  119. package/dist/src/storage/migrations/migrator.d.ts.map +1 -1
  120. package/dist/src/subs/default-error-handler.d.ts.map +1 -1
  121. package/dist/src/subs/subscription-notification-read-model.d.ts +3 -2
  122. package/dist/src/subs/subscription-notification-read-model.d.ts.map +1 -1
  123. package/dist/src/sync/batch-aggregator.d.ts +25 -0
  124. package/dist/src/sync/batch-aggregator.d.ts.map +1 -0
  125. package/dist/src/sync/buffered-mailbox.d.ts +36 -0
  126. package/dist/src/sync/buffered-mailbox.d.ts.map +1 -0
  127. package/dist/src/sync/channels/gql-req-channel.d.ts +121 -0
  128. package/dist/src/sync/channels/gql-req-channel.d.ts.map +1 -0
  129. package/dist/src/sync/channels/gql-request-channel-factory.d.ts +32 -0
  130. package/dist/src/sync/channels/gql-request-channel-factory.d.ts.map +1 -0
  131. package/dist/src/sync/channels/gql-res-channel.d.ts +31 -0
  132. package/dist/src/sync/channels/gql-res-channel.d.ts.map +1 -0
  133. package/dist/src/sync/channels/gql-response-channel-factory.d.ts +13 -0
  134. package/dist/src/sync/channels/gql-response-channel-factory.d.ts.map +1 -0
  135. package/dist/src/sync/channels/index.d.ts +6 -4
  136. package/dist/src/sync/channels/index.d.ts.map +1 -1
  137. package/dist/src/sync/channels/interval-poll-timer.d.ts +40 -0
  138. package/dist/src/sync/channels/interval-poll-timer.d.ts.map +1 -0
  139. package/dist/src/sync/channels/poll-timer.d.ts +14 -0
  140. package/dist/src/sync/channels/poll-timer.d.ts.map +1 -0
  141. package/dist/src/sync/channels/utils.d.ts +15 -1
  142. package/dist/src/sync/channels/utils.d.ts.map +1 -1
  143. package/dist/src/sync/index.d.ts +11 -7
  144. package/dist/src/sync/index.d.ts.map +1 -1
  145. package/dist/src/sync/interfaces.d.ts +42 -19
  146. package/dist/src/sync/interfaces.d.ts.map +1 -1
  147. package/dist/src/sync/mailbox.d.ts +51 -12
  148. package/dist/src/sync/mailbox.d.ts.map +1 -1
  149. package/dist/src/sync/sync-awaiter.d.ts +34 -0
  150. package/dist/src/sync/sync-awaiter.d.ts.map +1 -0
  151. package/dist/src/sync/sync-builder.d.ts +5 -1
  152. package/dist/src/sync/sync-builder.d.ts.map +1 -1
  153. package/dist/src/sync/sync-manager.d.ts +22 -8
  154. package/dist/src/sync/sync-manager.d.ts.map +1 -1
  155. package/dist/src/sync/sync-operation.d.ts +4 -2
  156. package/dist/src/sync/sync-operation.d.ts.map +1 -1
  157. package/dist/src/sync/sync-status-tracker.d.ts +31 -0
  158. package/dist/src/sync/sync-status-tracker.d.ts.map +1 -0
  159. package/dist/src/sync/types.d.ts +107 -2
  160. package/dist/src/sync/types.d.ts.map +1 -1
  161. package/dist/src/sync/utils.d.ts +37 -2
  162. package/dist/src/sync/utils.d.ts.map +1 -1
  163. package/dist/src/utils/reshuffle.d.ts +22 -5
  164. package/dist/src/utils/reshuffle.d.ts.map +1 -1
  165. package/package.json +24 -20
  166. package/dist/src/actions/index.js +0 -76
  167. package/dist/src/actions/index.js.map +0 -1
  168. package/dist/src/cache/buffer/ring-buffer.js +0 -69
  169. package/dist/src/cache/buffer/ring-buffer.js.map +0 -1
  170. package/dist/src/cache/document-meta-cache-types.js +0 -2
  171. package/dist/src/cache/document-meta-cache-types.js.map +0 -1
  172. package/dist/src/cache/document-meta-cache.js +0 -128
  173. package/dist/src/cache/document-meta-cache.js.map +0 -1
  174. package/dist/src/cache/index.js +0 -2
  175. package/dist/src/cache/index.js.map +0 -1
  176. package/dist/src/cache/kysely-operation-index.js +0 -250
  177. package/dist/src/cache/kysely-operation-index.js.map +0 -1
  178. package/dist/src/cache/kysely-write-cache.js +0 -388
  179. package/dist/src/cache/kysely-write-cache.js.map +0 -1
  180. package/dist/src/cache/lru/lru-tracker.js +0 -96
  181. package/dist/src/cache/lru/lru-tracker.js.map +0 -1
  182. package/dist/src/cache/operation-index-types.js +0 -4
  183. package/dist/src/cache/operation-index-types.js.map +0 -1
  184. package/dist/src/cache/write/interfaces.js +0 -2
  185. package/dist/src/cache/write/interfaces.js.map +0 -1
  186. package/dist/src/cache/write-cache-types.js +0 -2
  187. package/dist/src/cache/write-cache-types.js.map +0 -1
  188. package/dist/src/client/reactor-client.js +0 -406
  189. package/dist/src/client/reactor-client.js.map +0 -1
  190. package/dist/src/client/types.js +0 -14
  191. package/dist/src/client/types.js.map +0 -1
  192. package/dist/src/core/reactor-builder.js +0 -231
  193. package/dist/src/core/reactor-builder.js.map +0 -1
  194. package/dist/src/core/reactor-client-builder.js +0 -123
  195. package/dist/src/core/reactor-client-builder.js.map +0 -1
  196. package/dist/src/core/reactor.js +0 -981
  197. package/dist/src/core/reactor.js.map +0 -1
  198. package/dist/src/core/types.js +0 -2
  199. package/dist/src/core/types.js.map +0 -1
  200. package/dist/src/core/utils.js +0 -171
  201. package/dist/src/core/utils.js.map +0 -1
  202. package/dist/src/events/event-bus.js +0 -53
  203. package/dist/src/events/event-bus.js.map +0 -1
  204. package/dist/src/events/interfaces.js +0 -2
  205. package/dist/src/events/interfaces.js.map +0 -1
  206. package/dist/src/events/types.js +0 -28
  207. package/dist/src/events/types.js.map +0 -1
  208. package/dist/src/executor/interfaces.js +0 -2
  209. package/dist/src/executor/interfaces.js.map +0 -1
  210. package/dist/src/executor/simple-job-executor-manager.js +0 -233
  211. package/dist/src/executor/simple-job-executor-manager.js.map +0 -1
  212. package/dist/src/executor/simple-job-executor.js +0 -898
  213. package/dist/src/executor/simple-job-executor.js.map +0 -1
  214. package/dist/src/executor/types.js +0 -11
  215. package/dist/src/executor/types.js.map +0 -1
  216. package/dist/src/executor/util.js +0 -184
  217. package/dist/src/executor/util.js.map +0 -1
  218. package/dist/src/index.js.map +0 -1
  219. package/dist/src/job-tracker/in-memory-job-tracker.js +0 -112
  220. package/dist/src/job-tracker/in-memory-job-tracker.js.map +0 -1
  221. package/dist/src/job-tracker/index.js +0 -2
  222. package/dist/src/job-tracker/index.js.map +0 -1
  223. package/dist/src/job-tracker/interfaces.js +0 -2
  224. package/dist/src/job-tracker/interfaces.js.map +0 -1
  225. package/dist/src/logging/console.js +0 -108
  226. package/dist/src/logging/console.js.map +0 -1
  227. package/dist/src/logging/types.js +0 -2
  228. package/dist/src/logging/types.js.map +0 -1
  229. package/dist/src/processors/index.js +0 -2
  230. package/dist/src/processors/index.js.map +0 -1
  231. package/dist/src/processors/processor-manager.js +0 -165
  232. package/dist/src/processors/processor-manager.js.map +0 -1
  233. package/dist/src/processors/types.d.ts +0 -63
  234. package/dist/src/processors/types.d.ts.map +0 -1
  235. package/dist/src/processors/types.js +0 -2
  236. package/dist/src/processors/types.js.map +0 -1
  237. package/dist/src/processors/utils.js +0 -58
  238. package/dist/src/processors/utils.js.map +0 -1
  239. package/dist/src/queue/interfaces.js +0 -2
  240. package/dist/src/queue/interfaces.js.map +0 -1
  241. package/dist/src/queue/job-execution-handle.js +0 -62
  242. package/dist/src/queue/job-execution-handle.js.map +0 -1
  243. package/dist/src/queue/queue.js +0 -384
  244. package/dist/src/queue/queue.js.map +0 -1
  245. package/dist/src/queue/types.js +0 -19
  246. package/dist/src/queue/types.js.map +0 -1
  247. package/dist/src/read-models/base-read-model.js +0 -143
  248. package/dist/src/read-models/base-read-model.js.map +0 -1
  249. package/dist/src/read-models/coordinator.js +0 -72
  250. package/dist/src/read-models/coordinator.js.map +0 -1
  251. package/dist/src/read-models/document-view.js +0 -375
  252. package/dist/src/read-models/document-view.js.map +0 -1
  253. package/dist/src/read-models/interfaces.js +0 -2
  254. package/dist/src/read-models/interfaces.js.map +0 -1
  255. package/dist/src/read-models/types.js +0 -2
  256. package/dist/src/read-models/types.js.map +0 -1
  257. package/dist/src/registry/implementation.js +0 -216
  258. package/dist/src/registry/implementation.js.map +0 -1
  259. package/dist/src/registry/index.js +0 -2
  260. package/dist/src/registry/index.js.map +0 -1
  261. package/dist/src/registry/interfaces.js +0 -2
  262. package/dist/src/registry/interfaces.js.map +0 -1
  263. package/dist/src/shared/awaiter.js +0 -123
  264. package/dist/src/shared/awaiter.js.map +0 -1
  265. package/dist/src/shared/consistency-tracker.js +0 -123
  266. package/dist/src/shared/consistency-tracker.js.map +0 -1
  267. package/dist/src/shared/errors.js +0 -75
  268. package/dist/src/shared/errors.js.map +0 -1
  269. package/dist/src/shared/factories.js +0 -33
  270. package/dist/src/shared/factories.js.map +0 -1
  271. package/dist/src/shared/types.js +0 -38
  272. package/dist/src/shared/types.js.map +0 -1
  273. package/dist/src/shared/utils.js +0 -8
  274. package/dist/src/shared/utils.js.map +0 -1
  275. package/dist/src/signer/passthrough-signer.js +0 -19
  276. package/dist/src/signer/passthrough-signer.js.map +0 -1
  277. package/dist/src/signer/types.js +0 -2
  278. package/dist/src/signer/types.js.map +0 -1
  279. package/dist/src/storage/consistency-aware-legacy-storage.d.ts +0 -33
  280. package/dist/src/storage/consistency-aware-legacy-storage.d.ts.map +0 -1
  281. package/dist/src/storage/consistency-aware-legacy-storage.js +0 -65
  282. package/dist/src/storage/consistency-aware-legacy-storage.js.map +0 -1
  283. package/dist/src/storage/index.js +0 -3
  284. package/dist/src/storage/index.js.map +0 -1
  285. package/dist/src/storage/interfaces.js +0 -19
  286. package/dist/src/storage/interfaces.js.map +0 -1
  287. package/dist/src/storage/kysely/document-indexer.js +0 -350
  288. package/dist/src/storage/kysely/document-indexer.js.map +0 -1
  289. package/dist/src/storage/kysely/keyframe-store.js +0 -64
  290. package/dist/src/storage/kysely/keyframe-store.js.map +0 -1
  291. package/dist/src/storage/kysely/store.js +0 -233
  292. package/dist/src/storage/kysely/store.js.map +0 -1
  293. package/dist/src/storage/kysely/sync-cursor-storage.js +0 -93
  294. package/dist/src/storage/kysely/sync-cursor-storage.js.map +0 -1
  295. package/dist/src/storage/kysely/sync-remote-storage.js +0 -133
  296. package/dist/src/storage/kysely/sync-remote-storage.js.map +0 -1
  297. package/dist/src/storage/kysely/types.js +0 -2
  298. package/dist/src/storage/kysely/types.js.map +0 -1
  299. package/dist/src/storage/migrations/001_create_operation_table.js +0 -41
  300. package/dist/src/storage/migrations/001_create_operation_table.js.map +0 -1
  301. package/dist/src/storage/migrations/002_create_keyframe_table.js +0 -27
  302. package/dist/src/storage/migrations/002_create_keyframe_table.js.map +0 -1
  303. package/dist/src/storage/migrations/003_create_document_table.js +0 -10
  304. package/dist/src/storage/migrations/003_create_document_table.js.map +0 -1
  305. package/dist/src/storage/migrations/004_create_document_relationship_table.js +0 -35
  306. package/dist/src/storage/migrations/004_create_document_relationship_table.js.map +0 -1
  307. package/dist/src/storage/migrations/005_create_indexer_state_table.js +0 -10
  308. package/dist/src/storage/migrations/005_create_indexer_state_table.js.map +0 -1
  309. package/dist/src/storage/migrations/006_create_document_snapshot_table.js +0 -49
  310. package/dist/src/storage/migrations/006_create_document_snapshot_table.js.map +0 -1
  311. package/dist/src/storage/migrations/007_create_slug_mapping_table.js +0 -24
  312. package/dist/src/storage/migrations/007_create_slug_mapping_table.js.map +0 -1
  313. package/dist/src/storage/migrations/008_create_view_state_table.js +0 -10
  314. package/dist/src/storage/migrations/008_create_view_state_table.js.map +0 -1
  315. package/dist/src/storage/migrations/009_create_operation_index_tables.js +0 -50
  316. package/dist/src/storage/migrations/009_create_operation_index_tables.js.map +0 -1
  317. package/dist/src/storage/migrations/010_create_sync_tables.js +0 -43
  318. package/dist/src/storage/migrations/010_create_sync_tables.js.map +0 -1
  319. package/dist/src/storage/migrations/index.js +0 -3
  320. package/dist/src/storage/migrations/index.js.map +0 -1
  321. package/dist/src/storage/migrations/migrator.js +0 -78
  322. package/dist/src/storage/migrations/migrator.js.map +0 -1
  323. package/dist/src/storage/migrations/run-migrations.js +0 -58
  324. package/dist/src/storage/migrations/run-migrations.js.map +0 -1
  325. package/dist/src/storage/migrations/types.js +0 -2
  326. package/dist/src/storage/migrations/types.js.map +0 -1
  327. package/dist/src/storage/txn.js +0 -42
  328. package/dist/src/storage/txn.js.map +0 -1
  329. package/dist/src/subs/default-error-handler.js +0 -27
  330. package/dist/src/subs/default-error-handler.js.map +0 -1
  331. package/dist/src/subs/react-subscription-manager.js +0 -185
  332. package/dist/src/subs/react-subscription-manager.js.map +0 -1
  333. package/dist/src/subs/subscription-notification-read-model.js +0 -62
  334. package/dist/src/subs/subscription-notification-read-model.js.map +0 -1
  335. package/dist/src/subs/types.js +0 -2
  336. package/dist/src/subs/types.js.map +0 -1
  337. package/dist/src/sync/channels/composite-channel-factory.d.ts +0 -30
  338. package/dist/src/sync/channels/composite-channel-factory.d.ts.map +0 -1
  339. package/dist/src/sync/channels/composite-channel-factory.js +0 -87
  340. package/dist/src/sync/channels/composite-channel-factory.js.map +0 -1
  341. package/dist/src/sync/channels/gql-channel-factory.d.ts +0 -25
  342. package/dist/src/sync/channels/gql-channel-factory.d.ts.map +0 -1
  343. package/dist/src/sync/channels/gql-channel-factory.js +0 -76
  344. package/dist/src/sync/channels/gql-channel-factory.js.map +0 -1
  345. package/dist/src/sync/channels/gql-channel.d.ts +0 -118
  346. package/dist/src/sync/channels/gql-channel.d.ts.map +0 -1
  347. package/dist/src/sync/channels/gql-channel.js +0 -423
  348. package/dist/src/sync/channels/gql-channel.js.map +0 -1
  349. package/dist/src/sync/channels/index.js +0 -6
  350. package/dist/src/sync/channels/index.js.map +0 -1
  351. package/dist/src/sync/channels/polling-channel.d.ts +0 -39
  352. package/dist/src/sync/channels/polling-channel.d.ts.map +0 -1
  353. package/dist/src/sync/channels/polling-channel.js +0 -72
  354. package/dist/src/sync/channels/polling-channel.js.map +0 -1
  355. package/dist/src/sync/channels/utils.js +0 -96
  356. package/dist/src/sync/channels/utils.js.map +0 -1
  357. package/dist/src/sync/errors.js +0 -17
  358. package/dist/src/sync/errors.js.map +0 -1
  359. package/dist/src/sync/index.js +0 -9
  360. package/dist/src/sync/index.js.map +0 -1
  361. package/dist/src/sync/interfaces.js +0 -2
  362. package/dist/src/sync/interfaces.js.map +0 -1
  363. package/dist/src/sync/mailbox.js +0 -59
  364. package/dist/src/sync/mailbox.js.map +0 -1
  365. package/dist/src/sync/sync-builder.js +0 -39
  366. package/dist/src/sync/sync-builder.js.map +0 -1
  367. package/dist/src/sync/sync-manager.js +0 -266
  368. package/dist/src/sync/sync-manager.js.map +0 -1
  369. package/dist/src/sync/sync-operation.js +0 -63
  370. package/dist/src/sync/sync-operation.js.map +0 -1
  371. package/dist/src/sync/types.js +0 -16
  372. package/dist/src/sync/types.js.map +0 -1
  373. package/dist/src/sync/utils.js +0 -78
  374. package/dist/src/sync/utils.js.map +0 -1
  375. package/dist/src/utils/reshuffle.js +0 -47
  376. package/dist/src/utils/reshuffle.js.map +0 -1
@@ -1,423 +0,0 @@
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 ?? 2000,
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
@@ -1 +0,0 @@
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,CA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I,CAAC,gBAAgB;YACvC,YAAY,EAAE,IAAI,CAAC,YAAY;SAChC,CAAC;IACJ,CAAC;CACF"}
@@ -1,6 +0,0 @@
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";
5
- export { envelopeToSyncOperation } from "./utils.js";
6
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
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"}
@@ -1,39 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,72 +0,0 @@
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
@@ -1 +0,0 @@
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;QAC7B,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;QAExB,IAAI,CAAC,KAAK,GAAG,IAAI,OAAO,EAAiB,CAAC;QAC1C,IAAI,CAAC,MAAM,GAAG,IAAI,OAAO,EAAiB,CAAC;QAC3C,IAAI,CAAC,UAAU,GAAG,IAAI,OAAO,EAAiB,CAAC;IACjD,CAAC;IAED,QAAQ;QACN,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,IAAI,KAAmB,CAAC;IAE9B;;;;;OAKG;IACH,OAAO,CAAC,QAAsB;QAC5B,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACpB,MAAM,IAAI,mBAAmB,CAC3B,WAAW,IAAI,CAAC,SAAS,2CAA2C,CACrE,CAAC;QACJ,CAAC;QAED,IAAI,QAAQ,CAAC,IAAI,KAAK,YAAY,IAAI,QAAQ,CAAC,UAAU,EAAE,CAAC;YAC1D,MAAM,OAAO,GAAG,yBAAyB,CAAC,QAAQ,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;YACrE,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;gBAC7B,MAAM,CAAC,WAAW,EAAE,CAAC;gBACrB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YACzB,CAAC;QACH,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,YAAY,CAAC,aAAqB;QACtC,MAAM,MAAM,GAAiB;YAC3B,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,aAAa;YACb,iBAAiB,EAAE,IAAI,CAAC,GAAG,EAAE;SAC9B,CAAC;QAEF,MAAM,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAExC,KAAK,MAAM,EAAE,IAAI,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;YACnC,MAAM,UAAU,GAAG,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"}
@@ -1,96 +0,0 @@
1
- import { SyncOperation } from "../sync-operation.js";
2
- import { batchOperationsByDocument } from "../utils.js";
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
- }
46
- /**
47
- * Converts a SyncEnvelope containing operations into a SyncOperation.
48
- *
49
- * Extracts the necessary metadata from the envelope's operations to create
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.
53
- *
54
- * @param envelope - The sync envelope containing operations
55
- * @param remoteName - The name of the remote this sync operation is associated with
56
- * @returns A new SyncOperation containing the envelope's operations with deserialized signatures
57
- * @throws Error if envelope has no operations or operations array is empty
58
- */
59
- export function envelopeToSyncOperation(envelope, remoteName) {
60
- if (!envelope.operations || envelope.operations.length === 0) {
61
- throw new Error("Cannot create SyncOperation from envelope without operations");
62
- }
63
- const deserializedOperations = envelope.operations.map(deserializeOperationSignatures);
64
- const firstOp = deserializedOperations[0];
65
- const documentId = firstOp.context.documentId;
66
- const branch = firstOp.context.branch;
67
- const scopes = [
68
- ...new Set(deserializedOperations.map((op) => op.context.scope)),
69
- ];
70
- const syncOpId = `syncop-${envelope.channelMeta.id}-${Date.now()}-${syncOpCounter++}`;
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
- });
95
- }
96
- //# sourceMappingURL=utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/sync/channels/utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAExD,IAAI,aAAa,GAAG,CAAC,CAAC;AAEtB;;;;;GAKG;AACH,SAAS,oBAAoB,CAAC,GAAuB;IACnD,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QACvB,OAAO,GAAG,CAAC;IACb,CAAC;IACD,OAAO,GAAG,CAAC,KAAK,CAAC,IAAI,CAAc,CAAC;AACtC,CAAC;AAED;;;;;GAKG;AACH,SAAS,8BAA8B,CACrC,aAAmC;IAEnC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