@powerhousedao/reactor 4.1.0-dev.12 → 4.1.0-dev.121

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 (366) hide show
  1. package/dist/src/cache/buffer/ring-buffer.d.ts +37 -0
  2. package/dist/src/cache/buffer/ring-buffer.d.ts.map +1 -0
  3. package/dist/src/cache/buffer/ring-buffer.js +69 -0
  4. package/dist/src/cache/buffer/ring-buffer.js.map +1 -0
  5. package/dist/src/cache/index.d.ts +3 -0
  6. package/dist/src/cache/index.d.ts.map +1 -0
  7. package/dist/src/cache/index.js +2 -0
  8. package/dist/src/cache/index.js.map +1 -0
  9. package/dist/src/cache/kysely-operation-index.d.ts +13 -0
  10. package/dist/src/cache/kysely-operation-index.d.ts.map +1 -0
  11. package/dist/src/cache/kysely-operation-index.js +207 -0
  12. package/dist/src/cache/kysely-operation-index.js.map +1 -0
  13. package/dist/src/cache/kysely-write-cache.d.ts +134 -0
  14. package/dist/src/cache/kysely-write-cache.d.ts.map +1 -0
  15. package/dist/src/cache/kysely-write-cache.js +375 -0
  16. package/dist/src/cache/kysely-write-cache.js.map +1 -0
  17. package/dist/src/cache/lru/lru-tracker.d.ts +15 -0
  18. package/dist/src/cache/lru/lru-tracker.d.ts.map +1 -0
  19. package/dist/src/cache/lru/lru-tracker.js +96 -0
  20. package/dist/src/cache/lru/lru-tracker.js.map +1 -0
  21. package/dist/src/cache/operation-index-types.d.ts +49 -0
  22. package/dist/src/cache/operation-index-types.d.ts.map +1 -0
  23. package/dist/src/cache/operation-index-types.js +4 -0
  24. package/dist/src/cache/operation-index-types.js.map +1 -0
  25. package/dist/src/cache/write/interfaces.d.ts +83 -0
  26. package/dist/src/cache/write/interfaces.d.ts.map +1 -0
  27. package/dist/src/cache/write/interfaces.js +2 -0
  28. package/dist/src/cache/write/interfaces.js.map +1 -0
  29. package/dist/src/cache/write-cache-types.d.ts +42 -0
  30. package/dist/src/cache/write-cache-types.d.ts.map +1 -0
  31. package/dist/src/cache/write-cache-types.js +2 -0
  32. package/dist/src/cache/write-cache-types.js.map +1 -0
  33. package/dist/src/client/reactor-client.d.ts +103 -0
  34. package/dist/src/client/reactor-client.d.ts.map +1 -0
  35. package/dist/src/client/reactor-client.js +184 -0
  36. package/dist/src/client/reactor-client.js.map +1 -0
  37. package/dist/src/client/types.d.ts +213 -0
  38. package/dist/src/client/types.d.ts.map +1 -0
  39. package/dist/src/client/types.js +14 -0
  40. package/dist/src/client/types.js.map +1 -0
  41. package/dist/src/core/builder.d.ts +20 -0
  42. package/dist/src/core/builder.d.ts.map +1 -0
  43. package/dist/src/core/builder.js +47 -0
  44. package/dist/src/core/builder.js.map +1 -0
  45. package/dist/src/core/reactor-builder.d.ts +37 -0
  46. package/dist/src/core/reactor-builder.d.ts.map +1 -0
  47. package/dist/src/core/reactor-builder.js +138 -0
  48. package/dist/src/core/reactor-builder.js.map +1 -0
  49. package/dist/src/core/reactor.d.ts +111 -0
  50. package/dist/src/core/reactor.d.ts.map +1 -0
  51. package/dist/src/core/reactor.js +952 -0
  52. package/dist/src/core/reactor.js.map +1 -0
  53. package/dist/src/core/types.d.ts +183 -0
  54. package/dist/src/core/types.d.ts.map +1 -0
  55. package/dist/src/core/types.js +2 -0
  56. package/dist/src/core/types.js.map +1 -0
  57. package/dist/src/core/utils.d.ts +51 -0
  58. package/dist/src/core/utils.d.ts.map +1 -0
  59. package/dist/src/core/utils.js +141 -0
  60. package/dist/src/core/utils.js.map +1 -0
  61. package/dist/src/events/event-bus.d.ts +3 -3
  62. package/dist/src/events/event-bus.d.ts.map +1 -1
  63. package/dist/src/events/event-bus.js.map +1 -1
  64. package/dist/src/events/interfaces.d.ts +1 -1
  65. package/dist/src/events/interfaces.d.ts.map +1 -1
  66. package/dist/src/events/types.d.ts +31 -1
  67. package/dist/src/events/types.d.ts.map +1 -1
  68. package/dist/src/events/types.js +7 -0
  69. package/dist/src/events/types.js.map +1 -1
  70. package/dist/src/executor/interfaces.d.ts +31 -54
  71. package/dist/src/executor/interfaces.d.ts.map +1 -1
  72. package/dist/src/executor/simple-job-executor-manager.d.ts +32 -0
  73. package/dist/src/executor/simple-job-executor-manager.d.ts.map +1 -0
  74. package/dist/src/executor/simple-job-executor-manager.js +214 -0
  75. package/dist/src/executor/simple-job-executor-manager.js.map +1 -0
  76. package/dist/src/executor/simple-job-executor.d.ts +62 -0
  77. package/dist/src/executor/simple-job-executor.d.ts.map +1 -0
  78. package/dist/src/executor/simple-job-executor.js +705 -0
  79. package/dist/src/executor/simple-job-executor.js.map +1 -0
  80. package/dist/src/executor/types.d.ts +32 -8
  81. package/dist/src/executor/types.d.ts.map +1 -1
  82. package/dist/src/executor/types.js.map +1 -1
  83. package/dist/src/executor/util.d.ts +65 -0
  84. package/dist/src/executor/util.d.ts.map +1 -0
  85. package/dist/src/executor/util.js +154 -0
  86. package/dist/src/executor/util.js.map +1 -0
  87. package/dist/src/index.d.ts +35 -3
  88. package/dist/src/index.d.ts.map +1 -1
  89. package/dist/src/index.js +43 -2
  90. package/dist/src/index.js.map +1 -1
  91. package/dist/src/job-tracker/in-memory-job-tracker.d.ts +16 -0
  92. package/dist/src/job-tracker/in-memory-job-tracker.d.ts.map +1 -0
  93. package/dist/src/job-tracker/in-memory-job-tracker.js +84 -0
  94. package/dist/src/job-tracker/in-memory-job-tracker.js.map +1 -0
  95. package/dist/src/job-tracker/index.d.ts +3 -0
  96. package/dist/src/job-tracker/index.d.ts.map +1 -0
  97. package/dist/src/job-tracker/index.js +2 -0
  98. package/dist/src/job-tracker/index.js.map +1 -0
  99. package/dist/src/job-tracker/interfaces.d.ts +42 -0
  100. package/dist/src/job-tracker/interfaces.d.ts.map +1 -0
  101. package/dist/src/job-tracker/interfaces.js +2 -0
  102. package/dist/src/job-tracker/interfaces.js.map +1 -0
  103. package/dist/src/queue/interfaces.d.ts +46 -5
  104. package/dist/src/queue/interfaces.d.ts.map +1 -1
  105. package/dist/src/queue/job-execution-handle.d.ts +25 -0
  106. package/dist/src/queue/job-execution-handle.d.ts.map +1 -0
  107. package/dist/src/queue/job-execution-handle.js +62 -0
  108. package/dist/src/queue/job-execution-handle.js.map +1 -0
  109. package/dist/src/queue/queue.d.ts +56 -5
  110. package/dist/src/queue/queue.d.ts.map +1 -1
  111. package/dist/src/queue/queue.js +284 -36
  112. package/dist/src/queue/queue.js.map +1 -1
  113. package/dist/src/queue/types.d.ts +38 -5
  114. package/dist/src/queue/types.d.ts.map +1 -1
  115. package/dist/src/queue/types.js +12 -0
  116. package/dist/src/queue/types.js.map +1 -1
  117. package/dist/src/read-models/coordinator.d.ts +38 -0
  118. package/dist/src/read-models/coordinator.d.ts.map +1 -0
  119. package/dist/src/read-models/coordinator.js +72 -0
  120. package/dist/src/read-models/coordinator.js.map +1 -0
  121. package/dist/src/read-models/document-view.d.ts +24 -0
  122. package/dist/src/read-models/document-view.d.ts.map +1 -0
  123. package/dist/src/read-models/document-view.js +368 -0
  124. package/dist/src/read-models/document-view.js.map +1 -0
  125. package/dist/src/read-models/interfaces.d.ts +29 -0
  126. package/dist/src/read-models/interfaces.d.ts.map +1 -0
  127. package/dist/src/read-models/interfaces.js +2 -0
  128. package/dist/src/read-models/interfaces.js.map +1 -0
  129. package/dist/src/read-models/types.d.ts +46 -0
  130. package/dist/src/read-models/types.d.ts.map +1 -0
  131. package/dist/src/read-models/types.js +2 -0
  132. package/dist/src/read-models/types.js.map +1 -0
  133. package/dist/src/registry/implementation.d.ts +62 -0
  134. package/dist/src/registry/implementation.d.ts.map +1 -0
  135. package/dist/src/registry/implementation.js +96 -0
  136. package/dist/src/registry/implementation.js.map +1 -0
  137. package/dist/src/registry/index.d.ts +3 -0
  138. package/dist/src/registry/index.d.ts.map +1 -0
  139. package/dist/src/registry/index.js +2 -0
  140. package/dist/src/registry/index.js.map +1 -0
  141. package/dist/src/registry/interfaces.d.ts +39 -0
  142. package/dist/src/registry/interfaces.d.ts.map +1 -0
  143. package/dist/src/registry/interfaces.js +2 -0
  144. package/dist/src/registry/interfaces.js.map +1 -0
  145. package/dist/src/shared/awaiter.d.ts +32 -0
  146. package/dist/src/shared/awaiter.d.ts.map +1 -0
  147. package/dist/src/shared/awaiter.js +132 -0
  148. package/dist/src/shared/awaiter.js.map +1 -0
  149. package/dist/src/shared/consistency-tracker.d.ts +48 -0
  150. package/dist/src/shared/consistency-tracker.d.ts.map +1 -0
  151. package/dist/src/shared/consistency-tracker.js +123 -0
  152. package/dist/src/shared/consistency-tracker.js.map +1 -0
  153. package/dist/src/shared/errors.d.ts +17 -0
  154. package/dist/src/shared/errors.d.ts.map +1 -0
  155. package/dist/src/shared/errors.js +33 -0
  156. package/dist/src/shared/errors.js.map +1 -0
  157. package/dist/src/shared/factories.d.ts +16 -0
  158. package/dist/src/shared/factories.d.ts.map +1 -0
  159. package/dist/src/shared/factories.js +33 -0
  160. package/dist/src/shared/factories.js.map +1 -0
  161. package/dist/src/shared/types.d.ts +126 -20
  162. package/dist/src/shared/types.d.ts.map +1 -1
  163. package/dist/src/shared/types.js +35 -1
  164. package/dist/src/shared/types.js.map +1 -1
  165. package/dist/src/shared/utils.d.ts +3 -0
  166. package/dist/src/shared/utils.d.ts.map +1 -0
  167. package/dist/src/shared/utils.js +8 -0
  168. package/dist/src/shared/utils.js.map +1 -0
  169. package/dist/src/signer/passthrough-signer.d.ts +6 -0
  170. package/dist/src/signer/passthrough-signer.d.ts.map +1 -0
  171. package/dist/src/signer/passthrough-signer.js +6 -0
  172. package/dist/src/signer/passthrough-signer.js.map +1 -0
  173. package/dist/src/signer/types.d.ts +15 -0
  174. package/dist/src/signer/types.d.ts.map +1 -0
  175. package/dist/src/signer/types.js +2 -0
  176. package/dist/src/signer/types.js.map +1 -0
  177. package/dist/src/storage/index.d.ts +4 -0
  178. package/dist/src/storage/index.d.ts.map +1 -0
  179. package/dist/src/storage/index.js +3 -0
  180. package/dist/src/storage/index.js.map +1 -0
  181. package/dist/src/storage/interfaces.d.ts +335 -0
  182. package/dist/src/storage/interfaces.d.ts.map +1 -0
  183. package/dist/src/storage/interfaces.js +19 -0
  184. package/dist/src/storage/interfaces.js.map +1 -0
  185. package/dist/src/storage/kysely/document-indexer.d.ts +28 -0
  186. package/dist/src/storage/kysely/document-indexer.d.ts.map +1 -0
  187. package/dist/src/storage/kysely/document-indexer.js +350 -0
  188. package/dist/src/storage/kysely/document-indexer.js.map +1 -0
  189. package/dist/src/storage/kysely/keyframe-store.d.ts +15 -0
  190. package/dist/src/storage/kysely/keyframe-store.d.ts.map +1 -0
  191. package/dist/src/storage/kysely/keyframe-store.js +64 -0
  192. package/dist/src/storage/kysely/keyframe-store.js.map +1 -0
  193. package/dist/src/storage/kysely/store.d.ts +15 -0
  194. package/dist/src/storage/kysely/store.d.ts.map +1 -0
  195. package/dist/src/storage/kysely/store.js +196 -0
  196. package/dist/src/storage/kysely/store.js.map +1 -0
  197. package/dist/src/storage/kysely/sync-cursor-storage.d.ts +13 -0
  198. package/dist/src/storage/kysely/sync-cursor-storage.d.ts.map +1 -0
  199. package/dist/src/storage/kysely/sync-cursor-storage.js +93 -0
  200. package/dist/src/storage/kysely/sync-cursor-storage.js.map +1 -0
  201. package/dist/src/storage/kysely/sync-remote-storage.d.ts +13 -0
  202. package/dist/src/storage/kysely/sync-remote-storage.d.ts.map +1 -0
  203. package/dist/src/storage/kysely/sync-remote-storage.js +134 -0
  204. package/dist/src/storage/kysely/sync-remote-storage.js.map +1 -0
  205. package/dist/src/storage/kysely/types.d.ts +135 -0
  206. package/dist/src/storage/kysely/types.d.ts.map +1 -0
  207. package/dist/src/storage/kysely/types.js +2 -0
  208. package/dist/src/storage/kysely/types.js.map +1 -0
  209. package/dist/src/storage/migrations/001_create_operation_table.d.ts +3 -0
  210. package/dist/src/storage/migrations/001_create_operation_table.d.ts.map +1 -0
  211. package/dist/src/storage/migrations/001_create_operation_table.js +40 -0
  212. package/dist/src/storage/migrations/001_create_operation_table.js.map +1 -0
  213. package/dist/src/storage/migrations/002_create_keyframe_table.d.ts +3 -0
  214. package/dist/src/storage/migrations/002_create_keyframe_table.d.ts.map +1 -0
  215. package/dist/src/storage/migrations/002_create_keyframe_table.js +27 -0
  216. package/dist/src/storage/migrations/002_create_keyframe_table.js.map +1 -0
  217. package/dist/src/storage/migrations/003_create_document_table.d.ts +3 -0
  218. package/dist/src/storage/migrations/003_create_document_table.d.ts.map +1 -0
  219. package/dist/src/storage/migrations/003_create_document_table.js +10 -0
  220. package/dist/src/storage/migrations/003_create_document_table.js.map +1 -0
  221. package/dist/src/storage/migrations/004_create_document_relationship_table.d.ts +3 -0
  222. package/dist/src/storage/migrations/004_create_document_relationship_table.d.ts.map +1 -0
  223. package/dist/src/storage/migrations/004_create_document_relationship_table.js +35 -0
  224. package/dist/src/storage/migrations/004_create_document_relationship_table.js.map +1 -0
  225. package/dist/src/storage/migrations/005_create_indexer_state_table.d.ts +3 -0
  226. package/dist/src/storage/migrations/005_create_indexer_state_table.d.ts.map +1 -0
  227. package/dist/src/storage/migrations/005_create_indexer_state_table.js +10 -0
  228. package/dist/src/storage/migrations/005_create_indexer_state_table.js.map +1 -0
  229. package/dist/src/storage/migrations/006_create_document_snapshot_table.d.ts +3 -0
  230. package/dist/src/storage/migrations/006_create_document_snapshot_table.d.ts.map +1 -0
  231. package/dist/src/storage/migrations/006_create_document_snapshot_table.js +49 -0
  232. package/dist/src/storage/migrations/006_create_document_snapshot_table.js.map +1 -0
  233. package/dist/src/storage/migrations/007_create_slug_mapping_table.d.ts +3 -0
  234. package/dist/src/storage/migrations/007_create_slug_mapping_table.d.ts.map +1 -0
  235. package/dist/src/storage/migrations/007_create_slug_mapping_table.js +24 -0
  236. package/dist/src/storage/migrations/007_create_slug_mapping_table.js.map +1 -0
  237. package/dist/src/storage/migrations/008_create_view_state_table.d.ts +3 -0
  238. package/dist/src/storage/migrations/008_create_view_state_table.d.ts.map +1 -0
  239. package/dist/src/storage/migrations/008_create_view_state_table.js +9 -0
  240. package/dist/src/storage/migrations/008_create_view_state_table.js.map +1 -0
  241. package/dist/src/storage/migrations/009_create_operation_index_tables.d.ts +3 -0
  242. package/dist/src/storage/migrations/009_create_operation_index_tables.d.ts.map +1 -0
  243. package/dist/src/storage/migrations/009_create_operation_index_tables.js +50 -0
  244. package/dist/src/storage/migrations/009_create_operation_index_tables.js.map +1 -0
  245. package/dist/src/storage/migrations/010_create_sync_tables.d.ts +3 -0
  246. package/dist/src/storage/migrations/010_create_sync_tables.d.ts.map +1 -0
  247. package/dist/src/storage/migrations/010_create_sync_tables.js +43 -0
  248. package/dist/src/storage/migrations/010_create_sync_tables.js.map +1 -0
  249. package/dist/src/storage/migrations/index.d.ts +3 -0
  250. package/dist/src/storage/migrations/index.d.ts.map +1 -0
  251. package/dist/src/storage/migrations/index.js +3 -0
  252. package/dist/src/storage/migrations/index.js.map +1 -0
  253. package/dist/src/storage/migrations/migrator.d.ts +5 -0
  254. package/dist/src/storage/migrations/migrator.d.ts.map +1 -0
  255. package/dist/src/storage/migrations/migrator.js +55 -0
  256. package/dist/src/storage/migrations/migrator.js.map +1 -0
  257. package/dist/src/storage/migrations/run-migrations.d.ts +2 -0
  258. package/dist/src/storage/migrations/run-migrations.d.ts.map +1 -0
  259. package/dist/src/storage/migrations/run-migrations.js +58 -0
  260. package/dist/src/storage/migrations/run-migrations.js.map +1 -0
  261. package/dist/src/storage/migrations/types.d.ts +9 -0
  262. package/dist/src/storage/migrations/types.d.ts.map +1 -0
  263. package/dist/src/storage/migrations/types.js +2 -0
  264. package/dist/src/storage/migrations/types.js.map +1 -0
  265. package/dist/src/storage/txn.d.ts +15 -0
  266. package/dist/src/storage/txn.d.ts.map +1 -0
  267. package/dist/src/storage/txn.js +43 -0
  268. package/dist/src/storage/txn.js.map +1 -0
  269. package/dist/src/subs/default-error-handler.d.ts +13 -0
  270. package/dist/src/subs/default-error-handler.d.ts.map +1 -0
  271. package/dist/src/subs/default-error-handler.js +27 -0
  272. package/dist/src/subs/default-error-handler.js.map +1 -0
  273. package/dist/src/subs/react-subscription-manager.d.ts +45 -0
  274. package/dist/src/subs/react-subscription-manager.d.ts.map +1 -0
  275. package/dist/src/subs/react-subscription-manager.js +185 -0
  276. package/dist/src/subs/react-subscription-manager.js.map +1 -0
  277. package/dist/src/subs/types.d.ts +64 -0
  278. package/dist/src/subs/types.d.ts.map +1 -0
  279. package/dist/src/subs/types.js +2 -0
  280. package/dist/src/subs/types.js.map +1 -0
  281. package/dist/src/sync/channels/index.d.ts +3 -0
  282. package/dist/src/sync/channels/index.d.ts.map +1 -0
  283. package/dist/src/sync/channels/index.js +3 -0
  284. package/dist/src/sync/channels/index.js.map +1 -0
  285. package/dist/src/sync/channels/internal-channel.d.ts +57 -0
  286. package/dist/src/sync/channels/internal-channel.d.ts.map +1 -0
  287. package/dist/src/sync/channels/internal-channel.js +106 -0
  288. package/dist/src/sync/channels/internal-channel.js.map +1 -0
  289. package/dist/src/sync/channels/utils.d.ts +15 -0
  290. package/dist/src/sync/channels/utils.d.ts.map +1 -0
  291. package/dist/src/sync/channels/utils.js +26 -0
  292. package/dist/src/sync/channels/utils.js.map +1 -0
  293. package/dist/src/sync/errors.d.ts +10 -0
  294. package/dist/src/sync/errors.d.ts.map +1 -0
  295. package/dist/src/sync/errors.js +17 -0
  296. package/dist/src/sync/errors.js.map +1 -0
  297. package/dist/src/sync/index.d.ts +12 -0
  298. package/dist/src/sync/index.d.ts.map +1 -0
  299. package/dist/src/sync/index.js +9 -0
  300. package/dist/src/sync/index.js.map +1 -0
  301. package/dist/src/sync/interfaces.d.ts +150 -0
  302. package/dist/src/sync/interfaces.d.ts.map +1 -0
  303. package/dist/src/sync/interfaces.js +2 -0
  304. package/dist/src/sync/interfaces.js.map +1 -0
  305. package/dist/src/sync/mailbox.d.ts +21 -0
  306. package/dist/src/sync/mailbox.d.ts.map +1 -0
  307. package/dist/src/sync/mailbox.js +59 -0
  308. package/dist/src/sync/mailbox.js.map +1 -0
  309. package/dist/src/sync/sync-builder.d.ts +17 -0
  310. package/dist/src/sync/sync-builder.d.ts.map +1 -0
  311. package/dist/src/sync/sync-builder.js +29 -0
  312. package/dist/src/sync/sync-builder.js.map +1 -0
  313. package/dist/src/sync/sync-manager.d.ts +33 -0
  314. package/dist/src/sync/sync-manager.d.ts.map +1 -0
  315. package/dist/src/sync/sync-manager.js +196 -0
  316. package/dist/src/sync/sync-manager.js.map +1 -0
  317. package/dist/src/sync/sync-operation.d.ts +28 -0
  318. package/dist/src/sync/sync-operation.d.ts.map +1 -0
  319. package/dist/src/sync/sync-operation.js +63 -0
  320. package/dist/src/sync/sync-operation.js.map +1 -0
  321. package/dist/src/sync/types.d.ts +61 -0
  322. package/dist/src/sync/types.d.ts.map +1 -0
  323. package/dist/src/sync/types.js +16 -0
  324. package/dist/src/sync/types.js.map +1 -0
  325. package/dist/src/sync/utils.d.ts +17 -0
  326. package/dist/src/sync/utils.d.ts.map +1 -0
  327. package/dist/src/sync/utils.js +34 -0
  328. package/dist/src/sync/utils.js.map +1 -0
  329. package/dist/src/utils/reshuffle.d.ts +30 -0
  330. package/dist/src/utils/reshuffle.d.ts.map +1 -0
  331. package/dist/src/utils/reshuffle.js +47 -0
  332. package/dist/src/utils/reshuffle.js.map +1 -0
  333. package/package.json +23 -7
  334. package/dist/bench/end-to-end-flow.bench.d.ts +0 -2
  335. package/dist/bench/end-to-end-flow.bench.d.ts.map +0 -1
  336. package/dist/bench/end-to-end-flow.bench.js +0 -256
  337. package/dist/bench/end-to-end-flow.bench.js.map +0 -1
  338. package/dist/bench/event-bus.bench.d.ts +0 -2
  339. package/dist/bench/event-bus.bench.d.ts.map +0 -1
  340. package/dist/bench/event-bus.bench.js +0 -238
  341. package/dist/bench/event-bus.bench.js.map +0 -1
  342. package/dist/bench/queue-only.bench.d.ts +0 -2
  343. package/dist/bench/queue-only.bench.d.ts.map +0 -1
  344. package/dist/bench/queue-only.bench.js +0 -40
  345. package/dist/bench/queue-only.bench.js.map +0 -1
  346. package/dist/bench/reactor-throughput.bench.d.ts +0 -2
  347. package/dist/bench/reactor-throughput.bench.d.ts.map +0 -1
  348. package/dist/bench/reactor-throughput.bench.js +0 -137
  349. package/dist/bench/reactor-throughput.bench.js.map +0 -1
  350. package/dist/src/executor/job-executor.d.ts +0 -62
  351. package/dist/src/executor/job-executor.d.ts.map +0 -1
  352. package/dist/src/executor/job-executor.js +0 -325
  353. package/dist/src/executor/job-executor.js.map +0 -1
  354. package/dist/test/event-bus.test.d.ts +0 -2
  355. package/dist/test/event-bus.test.d.ts.map +0 -1
  356. package/dist/test/event-bus.test.js +0 -532
  357. package/dist/test/event-bus.test.js.map +0 -1
  358. package/dist/test/job-executor.test.d.ts +0 -2
  359. package/dist/test/job-executor.test.d.ts.map +0 -1
  360. package/dist/test/job-executor.test.js +0 -581
  361. package/dist/test/job-executor.test.js.map +0 -1
  362. package/dist/test/queue.test.d.ts +0 -2
  363. package/dist/test/queue.test.d.ts.map +0 -1
  364. package/dist/test/queue.test.js +0 -396
  365. package/dist/test/queue.test.js.map +0 -1
  366. package/dist/tsconfig.tsbuildinfo +0 -1
@@ -0,0 +1,196 @@
1
+ import { OperationEventTypes, } from "../events/types.js";
2
+ import { JobStatus, } from "../shared/types.js";
3
+ import { JobAwaiter } from "../shared/awaiter.js";
4
+ import { ChannelError } from "./errors.js";
5
+ import { SyncOperation } from "./sync-operation.js";
6
+ import { ChannelErrorSource, SyncOperationStatus } from "./types.js";
7
+ import { createIdleHealth, filterOperations } from "./utils.js";
8
+ export class SyncManager {
9
+ remoteStorage;
10
+ cursorStorage;
11
+ channelFactory;
12
+ _operationIndex;
13
+ reactor;
14
+ eventBus;
15
+ remotes;
16
+ awaiter;
17
+ isShutdown;
18
+ eventUnsubscribe;
19
+ loadJobs = new Map();
20
+ constructor(remoteStorage, cursorStorage, channelFactory, operationIndex, reactor, eventBus) {
21
+ this.remoteStorage = remoteStorage;
22
+ this.cursorStorage = cursorStorage;
23
+ this.channelFactory = channelFactory;
24
+ this._operationIndex = operationIndex;
25
+ this.reactor = reactor;
26
+ this.eventBus = eventBus;
27
+ this.remotes = new Map();
28
+ this.awaiter = new JobAwaiter((jobId, signal) => reactor.getJobStatus(jobId, signal));
29
+ this.isShutdown = false;
30
+ }
31
+ async startup() {
32
+ if (this.isShutdown) {
33
+ throw new Error("SyncManager is already shutdown and cannot be started");
34
+ }
35
+ const remoteRecords = await this.remoteStorage.list();
36
+ for (const record of remoteRecords) {
37
+ const channel = this.channelFactory.instance(record.channelConfig, this.cursorStorage);
38
+ const remote = {
39
+ name: record.name,
40
+ collectionId: record.collectionId,
41
+ filter: record.filter,
42
+ options: record.options,
43
+ channel,
44
+ };
45
+ this.remotes.set(record.name, remote);
46
+ this.wireChannelCallbacks(remote);
47
+ }
48
+ this.eventUnsubscribe = this.eventBus.subscribe(OperationEventTypes.OPERATION_WRITTEN, (_type, event) => this.handleOperationWritten(event));
49
+ }
50
+ shutdown() {
51
+ this.isShutdown = true;
52
+ if (this.eventUnsubscribe) {
53
+ this.eventUnsubscribe();
54
+ this.eventUnsubscribe = undefined;
55
+ }
56
+ for (const remote of this.remotes.values()) {
57
+ try {
58
+ remote.channel.shutdown();
59
+ }
60
+ catch (error) {
61
+ console.error(`Error shutting down channel for remote ${remote.name}: ${error instanceof Error ? error.message : String(error)}`);
62
+ }
63
+ }
64
+ this.remotes.clear();
65
+ return {
66
+ isShutdown: true,
67
+ };
68
+ }
69
+ get(name) {
70
+ const remote = this.remotes.get(name);
71
+ if (!remote) {
72
+ throw new Error(`Remote with name '${name}' does not exist`);
73
+ }
74
+ return remote;
75
+ }
76
+ async add(name, collectionId, channelConfig, filter = { documentId: [], scope: [], branch: "" }, options = {}) {
77
+ if (this.isShutdown) {
78
+ throw new Error("SyncManager is shutdown and cannot add remotes");
79
+ }
80
+ if (this.remotes.has(name)) {
81
+ throw new Error(`Remote with name '${name}' already exists`);
82
+ }
83
+ const status = {
84
+ push: createIdleHealth(),
85
+ pull: createIdleHealth(),
86
+ };
87
+ const remoteRecord = {
88
+ name,
89
+ collectionId,
90
+ channelConfig,
91
+ filter,
92
+ options,
93
+ status,
94
+ };
95
+ await this.remoteStorage.upsert(remoteRecord);
96
+ const channel = this.channelFactory.instance(channelConfig, this.cursorStorage);
97
+ const remote = {
98
+ name,
99
+ collectionId,
100
+ filter,
101
+ options,
102
+ channel,
103
+ };
104
+ this.remotes.set(name, remote);
105
+ this.wireChannelCallbacks(remote);
106
+ return remote;
107
+ }
108
+ async remove(name) {
109
+ const remote = this.remotes.get(name);
110
+ if (!remote) {
111
+ throw new Error(`Remote with name '${name}' does not exist`);
112
+ }
113
+ await this.remoteStorage.remove(name);
114
+ remote.channel.shutdown();
115
+ this.remotes.delete(name);
116
+ }
117
+ list() {
118
+ return Array.from(this.remotes.values());
119
+ }
120
+ wireChannelCallbacks(remote) {
121
+ remote.channel.inbox.onAdded((syncOp) => {
122
+ this.handleInboxJob(remote, syncOp);
123
+ });
124
+ remote.channel.outbox.onAdded((syncOp) => {
125
+ this.handleOutboxJob(remote, syncOp);
126
+ });
127
+ }
128
+ handleOperationWritten(event) {
129
+ if (this.isShutdown) {
130
+ return;
131
+ }
132
+ for (const remote of this.remotes.values()) {
133
+ const filteredOps = filterOperations(event.operations, remote.filter);
134
+ if (filteredOps.length === 0) {
135
+ continue;
136
+ }
137
+ const syncOp = new SyncOperation(crypto.randomUUID(), remote.name, filteredOps[0].context.documentId, [...new Set(filteredOps.map((op) => op.context.scope))], filteredOps[0].context.branch, filteredOps);
138
+ remote.channel.outbox.add(syncOp);
139
+ }
140
+ }
141
+ handleInboxJob(remote, syncOp) {
142
+ if (this.isShutdown) {
143
+ return;
144
+ }
145
+ void this.applyInboxJob(remote, syncOp);
146
+ }
147
+ handleOutboxJob(remote, syncOp) {
148
+ syncOp.on((syncOp, _prev, next) => {
149
+ if (next === SyncOperationStatus.Applied) {
150
+ remote.channel.outbox.remove(syncOp);
151
+ }
152
+ else if (next === SyncOperationStatus.Error) {
153
+ remote.channel.outbox.remove(syncOp);
154
+ }
155
+ });
156
+ }
157
+ async applyInboxJob(remote, syncOp) {
158
+ const operations = syncOp.operations.map((op) => op.operation);
159
+ let jobInfo;
160
+ try {
161
+ jobInfo = await this.reactor.load(syncOp.documentId, syncOp.branch, operations);
162
+ }
163
+ catch (error) {
164
+ const err = error instanceof Error ? error : new Error(String(error));
165
+ const channelError = new ChannelError(ChannelErrorSource.Inbox, err);
166
+ syncOp.failed(channelError);
167
+ remote.channel.deadLetter.add(syncOp);
168
+ remote.channel.inbox.remove(syncOp);
169
+ return;
170
+ }
171
+ let completedJobInfo;
172
+ try {
173
+ completedJobInfo = await this.awaiter.waitForJob(jobInfo.id);
174
+ }
175
+ catch (error) {
176
+ const err = error instanceof Error ? error : new Error(String(error));
177
+ const channelError = new ChannelError(ChannelErrorSource.Inbox, err);
178
+ syncOp.failed(channelError);
179
+ remote.channel.deadLetter.add(syncOp);
180
+ remote.channel.inbox.remove(syncOp);
181
+ return;
182
+ }
183
+ const jobKey = `${syncOp.documentId}:${syncOp.branch}`;
184
+ this.loadJobs.set(jobKey, completedJobInfo);
185
+ if (completedJobInfo.status === JobStatus.FAILED) {
186
+ const error = new ChannelError(ChannelErrorSource.Inbox, new Error(`Failed to apply operations: ${completedJobInfo.error?.message || "Unknown error"}`));
187
+ syncOp.failed(error);
188
+ remote.channel.deadLetter.add(syncOp);
189
+ }
190
+ else {
191
+ syncOp.executed();
192
+ }
193
+ remote.channel.inbox.remove(syncOp);
194
+ }
195
+ }
196
+ //# sourceMappingURL=sync-manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync-manager.js","sourceRoot":"","sources":["../../../src/sync/sync-manager.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,mBAAmB,GAEpB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,SAAS,GAGV,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAKlD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AA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C,KAAK,EAAE,GAAG,CAAC,CAAC;YACrE,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;YAC5B,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YACtC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YACpC,OAAO;QACT,CAAC;QAED,MAAM,MAAM,GAAG,GAAG,MAAM,CAAC,UAAU,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;QACvD,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;QAE5C,IAAI,gBAAgB,CAAC,MAAM,KAAK,SAAS,CAAC,MAAM,EAAE,CAAC;YACjD,MAAM,KAAK,GAAG,IAAI,YAAY,CAC5B,kBAAkB,CAAC,KAAK,EACxB,IAAI,KAAK,CACP,+BAA+B,gBAAgB,CAAC,KAAK,EAAE,OAAO,IAAI,eAAe,EAAE,CACpF,CACF,CAAC;YACF,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACrB,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACxC,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,QAAQ,EAAE,CAAC;QACpB,CAAC;QAED,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACtC,CAAC;CACF"}
@@ -0,0 +1,28 @@
1
+ import type { OperationWithContext } from "../storage/interfaces.js";
2
+ import type { ChannelError } from "./errors.js";
3
+ import { SyncOperationStatus } from "./types.js";
4
+ type SyncOperationStatusCallback = (syncOp: SyncOperation, prev: SyncOperationStatus, next: SyncOperationStatus) => void;
5
+ export declare class SyncOperationAggregateError extends Error {
6
+ errors: Error[];
7
+ constructor(errors: Error[]);
8
+ }
9
+ export declare class SyncOperation {
10
+ readonly id: string;
11
+ readonly remoteName: string;
12
+ readonly documentId: string;
13
+ readonly scopes: string[];
14
+ readonly branch: string;
15
+ readonly operations: OperationWithContext[];
16
+ status: SyncOperationStatus;
17
+ error?: ChannelError;
18
+ private callbacks;
19
+ constructor(id: string, remoteName: string, documentId: string, scopes: string[], branch: string, operations: OperationWithContext[]);
20
+ on(callback: SyncOperationStatusCallback): void;
21
+ started(): void;
22
+ transported(): void;
23
+ executed(): void;
24
+ failed(error: ChannelError): void;
25
+ private transition;
26
+ }
27
+ export {};
28
+ //# sourceMappingURL=sync-operation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync-operation.d.ts","sourceRoot":"","sources":["../../../src/sync/sync-operation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEjD,KAAK,2BAA2B,GAAG,CACjC,MAAM,EAAE,aAAa,EACrB,IAAI,EAAE,mBAAmB,EACzB,IAAI,EAAE,mBAAmB,KACtB,IAAI,CAAC;AAEV,qBAAa,2BAA4B,SAAQ,KAAK;IACpD,MAAM,EAAE,KAAK,EAAE,CAAC;gBAEJ,MAAM,EAAE,KAAK,EAAE;CAQ5B;AAED,qBAAa,aAAa;IACxB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,UAAU,EAAE,oBAAoB,EAAE,CAAC;IAC5C,MAAM,EAAE,mBAAmB,CAAC;IAC5B,KAAK,CAAC,EAAE,YAAY,CAAC;IAErB,OAAO,CAAC,SAAS,CAAqC;gBAGpD,EAAE,EAAE,MAAM,EACV,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,EAAE,EAChB,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,oBAAoB,EAAE;IAWpC,EAAE,CAAC,QAAQ,EAAE,2BAA2B,GAAG,IAAI;IAI/C,OAAO,IAAI,IAAI;IAIf,WAAW,IAAI,IAAI;IAInB,QAAQ,IAAI,IAAI;IAIhB,MAAM,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI;IAKjC,OAAO,CAAC,UAAU;CAenB"}
@@ -0,0 +1,63 @@
1
+ import { SyncOperationStatus } from "./types.js";
2
+ export class SyncOperationAggregateError extends Error {
3
+ errors;
4
+ constructor(errors) {
5
+ const messages = errors.map((e) => e.message).join("; ");
6
+ super(`SyncOperation callback failed with ${errors.length} error(s): ${messages}`);
7
+ this.name = "SyncOperationAggregateError";
8
+ this.errors = errors;
9
+ }
10
+ }
11
+ export class SyncOperation {
12
+ id;
13
+ remoteName;
14
+ documentId;
15
+ scopes;
16
+ branch;
17
+ operations;
18
+ status;
19
+ error;
20
+ callbacks = [];
21
+ constructor(id, remoteName, documentId, scopes, branch, operations) {
22
+ this.id = id;
23
+ this.remoteName = remoteName;
24
+ this.documentId = documentId;
25
+ this.scopes = scopes;
26
+ this.branch = branch;
27
+ this.operations = operations;
28
+ this.status = SyncOperationStatus.Unknown;
29
+ }
30
+ on(callback) {
31
+ this.callbacks.push(callback);
32
+ }
33
+ started() {
34
+ this.transition(SyncOperationStatus.TransportPending);
35
+ }
36
+ transported() {
37
+ this.transition(SyncOperationStatus.ExecutionPending);
38
+ }
39
+ executed() {
40
+ this.transition(SyncOperationStatus.Applied);
41
+ }
42
+ failed(error) {
43
+ this.error = error;
44
+ this.transition(SyncOperationStatus.Error);
45
+ }
46
+ transition(next) {
47
+ const prev = this.status;
48
+ this.status = next;
49
+ const errors = [];
50
+ for (const callback of this.callbacks) {
51
+ try {
52
+ callback(this, prev, next);
53
+ }
54
+ catch (error) {
55
+ errors.push(error instanceof Error ? error : new Error(String(error)));
56
+ }
57
+ }
58
+ if (errors.length > 0) {
59
+ throw new SyncOperationAggregateError(errors);
60
+ }
61
+ }
62
+ }
63
+ //# sourceMappingURL=sync-operation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync-operation.js","sourceRoot":"","sources":["../../../src/sync/sync-operation.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAQjD,MAAM,OAAO,2BAA4B,SAAQ,KAAK;IACpD,MAAM,CAAU;IAEhB,YAAY,MAAe;QACzB,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACzD,KAAK,CACH,sCAAsC,MAAM,CAAC,MAAM,cAAc,QAAQ,EAAE,CAC5E,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,6BAA6B,CAAC;QAC1C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF;AAED,MAAM,OAAO,aAAa;IACf,EAAE,CAAS;IACX,UAAU,CAAS;IACnB,UAAU,CAAS;IACnB,MAAM,CAAW;IACjB,MAAM,CAAS;IACf,UAAU,CAAyB;IAC5C,MAAM,CAAsB;IAC5B,KAAK,CAAgB;IAEb,SAAS,GAAkC,EAAE,CAAC;IAEtD,YACE,EAAU,EACV,UAAkB,EAClB,UAAkB,EAClB,MAAgB,EAChB,MAAc,EACd,UAAkC;QAElC,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,UAAU,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
@@ -0,0 +1,61 @@
1
+ import type { OperationWithContext } from "../storage/interfaces.js";
2
+ export type RemoteOptions = {};
3
+ export type RemoteFilter = {
4
+ documentId: string[];
5
+ scope: string[];
6
+ branch: string;
7
+ };
8
+ export type RemoteCursor = {
9
+ remoteName: string;
10
+ cursorOrdinal: number;
11
+ lastSyncedAtUtcMs?: number;
12
+ };
13
+ export type ChannelMeta = {
14
+ id: string;
15
+ };
16
+ export type SyncEnvelopeType = "operations" | "ack";
17
+ export type SyncEnvelope = {
18
+ type: SyncEnvelopeType;
19
+ channelMeta: ChannelMeta;
20
+ operations?: OperationWithContext[];
21
+ cursor?: RemoteCursor;
22
+ };
23
+ export declare enum SyncOperationStatus {
24
+ Unknown = -1,
25
+ TransportPending = 0,
26
+ ExecutionPending = 1,
27
+ Applied = 2,
28
+ Error = 3
29
+ }
30
+ export declare enum ChannelErrorSource {
31
+ None = "none",
32
+ Channel = "channel",
33
+ Inbox = "inbox",
34
+ Outbox = "outbox"
35
+ }
36
+ export type SyncOperationErrorType = "SIGNATURE_INVALID" | "HASH_MISMATCH" | "LIBRARY_ERROR" | "MISSING_OPERATIONS" | "EXCESSIVE_SHUFFLE" | "GRACEFUL_ABORT";
37
+ export type ChannelHealth = {
38
+ state: "idle" | "running" | "error";
39
+ lastSuccessUtcMs?: number;
40
+ lastFailureUtcMs?: number;
41
+ failureCount: number;
42
+ };
43
+ export type RemoteStatus = {
44
+ push: ChannelHealth;
45
+ pull: ChannelHealth;
46
+ };
47
+ export type ChannelConfig = {
48
+ type: string;
49
+ channelId: string;
50
+ remoteName: string;
51
+ parameters: Record<string, unknown>;
52
+ };
53
+ export type RemoteRecord = {
54
+ name: string;
55
+ collectionId: string;
56
+ channelConfig: ChannelConfig;
57
+ filter: RemoteFilter;
58
+ options: RemoteOptions;
59
+ status: RemoteStatus;
60
+ };
61
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src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YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,aAAa,CAAC;IACpB,IAAI,EAAE,aAAa,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACrC,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,aAAa,CAAC;IAC7B,MAAM,EAAE,YAAY,CAAC;IACrB,OAAO,EAAE,aAAa,CAAC;IACvB,MAAM,EAAE,YAAY,CAAC;CACtB,CAAC"}
@@ -0,0 +1,16 @@
1
+ export var SyncOperationStatus;
2
+ (function (SyncOperationStatus) {
3
+ SyncOperationStatus[SyncOperationStatus["Unknown"] = -1] = "Unknown";
4
+ SyncOperationStatus[SyncOperationStatus["TransportPending"] = 0] = "TransportPending";
5
+ SyncOperationStatus[SyncOperationStatus["ExecutionPending"] = 1] = "ExecutionPending";
6
+ SyncOperationStatus[SyncOperationStatus["Applied"] = 2] = "Applied";
7
+ SyncOperationStatus[SyncOperationStatus["Error"] = 3] = "Error";
8
+ })(SyncOperationStatus || (SyncOperationStatus = {}));
9
+ export var ChannelErrorSource;
10
+ (function (ChannelErrorSource) {
11
+ ChannelErrorSource["None"] = "none";
12
+ ChannelErrorSource["Channel"] = "channel";
13
+ ChannelErrorSource["Inbox"] = "inbox";
14
+ ChannelErrorSource["Outbox"] = "outbox";
15
+ })(ChannelErrorSource || (ChannelErrorSource = {}));
16
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/sync/types.ts"],"names":[],"mappings":"AAgCA,MAAM,CAAN,IAAY,mBAMX;AAND,WAAY,mBAAmB;IAC7B,oEAAY,CAAA;IACZ,qFAAoB,CAAA;IACpB,qFAAoB,CAAA;IACpB,mEAAW,CAAA;IACX,+DAAS,CAAA;AACX,CAAC,EANW,mBAAmB,KAAnB,mBAAmB,QAM9B;AAED,MAAM,CAAN,IAAY,kBAKX;AALD,WAAY,kBAAkB;IAC5B,mCAAa,CAAA;IACb,yCAAmB,CAAA;IACnB,qCAAe,CAAA;IACf,uCAAiB,CAAA;AACnB,CAAC,EALW,kBAAkB,KAAlB,kBAAkB,QAK7B"}
@@ -0,0 +1,17 @@
1
+ import type { OperationWithContext } from "../storage/interfaces.js";
2
+ import type { ChannelHealth, RemoteFilter } from "./types.js";
3
+ /**
4
+ * Filters operations based on a remote's filter criteria.
5
+ *
6
+ * @param operations - The operations to filter
7
+ * @param filter - The filter criteria to apply
8
+ * @returns The filtered operations that match the criteria
9
+ */
10
+ export declare function filterOperations(operations: OperationWithContext[], filter: RemoteFilter): OperationWithContext[];
11
+ /**
12
+ * Creates an idle channel health status.
13
+ *
14
+ * @returns A new idle channel health object
15
+ */
16
+ export declare function createIdleHealth(): ChannelHealth;
17
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/sync/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE9D;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,UAAU,EAAE,oBAAoB,EAAE,EAClC,MAAM,EAAE,YAAY,GACnB,oBAAoB,EAAE,CAmBxB;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,IAAI,aAAa,CAKhD"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Filters operations based on a remote's filter criteria.
3
+ *
4
+ * @param operations - The operations to filter
5
+ * @param filter - The filter criteria to apply
6
+ * @returns The filtered operations that match the criteria
7
+ */
8
+ export function filterOperations(operations, filter) {
9
+ return operations.filter((op) => {
10
+ if (filter.branch && op.context.branch !== filter.branch) {
11
+ return false;
12
+ }
13
+ if (filter.documentId.length > 0 &&
14
+ !filter.documentId.includes(op.context.documentId)) {
15
+ return false;
16
+ }
17
+ if (filter.scope.length > 0 && !filter.scope.includes(op.context.scope)) {
18
+ return false;
19
+ }
20
+ return true;
21
+ });
22
+ }
23
+ /**
24
+ * Creates an idle channel health status.
25
+ *
26
+ * @returns A new idle channel health object
27
+ */
28
+ export function createIdleHealth() {
29
+ return {
30
+ state: "idle",
31
+ failureCount: 0,
32
+ };
33
+ }
34
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/sync/utils.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAC9B,UAAkC,EAClC,MAAoB;IAEpB,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE;QAC9B,IAAI,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC,OAAO,CAAC,MAAM,KAAK,MAAM,CAAC,MAAM,EAAE,CAAC;YACzD,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IACE,MAAM,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC;YAC5B,CAAC,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC,OAAO,CAAC,UAAU,CAAC,EAClD,CAAC;YACD,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IAAI,MAAM,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACxE,OAAO,KAAK,CAAC;QACf,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,gBAAgB;IAC9B,OAAO;QACL,KAAK,EAAE,MAAM;QACb,YAAY,EAAE,CAAC;KAChB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,30 @@
1
+ type OperationIndex = {
2
+ index: number;
3
+ skip: number;
4
+ id?: string;
5
+ timestampUtcMs?: string;
6
+ };
7
+ /**
8
+ * Sorts operations by index and skip number.
9
+ * [0:0 2:0 1:0 3:3 3:1] => [0:0 1:0 2:0 3:1 3:3]
10
+ */
11
+ export declare function sortOperations<TOpIndex extends OperationIndex>(operations: TOpIndex[]): TOpIndex[];
12
+ /**
13
+ * Reshuffles operations by timestamp only, ignoring their original index values.
14
+ * Used for merging concurrent operations from different branches.
15
+ *
16
+ * Example:
17
+ * [0:0, 1:0, 2:0, A3:0, A4:0, A5:0] + [0:0, 1:0, 2:0, B3:0, B4:2, B5:0]
18
+ * GC => [0:0, 1:0, 2:0, A3:0, A4:0, A5:0] + [0:0, 1:0, B4:2, B5:0]
19
+ * Split => [0:0, 1:0] + [2:0, A3:0, A4:0, A5:0] + [B4:2, B5:0]
20
+ * Reshuffle(6:4) => [6:4, 7:0, 8:0, 9:0, 10:0, 11:0]
21
+ * merge => [0:0, 1:0, 6:4, 7:0, 8:0, 9:0, 10:0, 11:0]
22
+ */
23
+ export declare function reshuffleByTimestamp<TOp extends OperationIndex>(startIndex: OperationIndex, opsA: TOp[], opsB: TOp[]): TOp[];
24
+ /**
25
+ * Reshuffles operations by timestamp first, then by original index value.
26
+ * Used for merging concurrent operations while preserving index ordering for operations with same timestamp.
27
+ */
28
+ export declare function reshuffleByTimestampAndIndex<TOp extends OperationIndex>(startIndex: OperationIndex, opsA: TOp[], opsB: TOp[]): TOp[];
29
+ export {};
30
+ //# sourceMappingURL=reshuffle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reshuffle.d.ts","sourceRoot":"","sources":["../../../src/utils/reshuffle.ts"],"names":[],"mappings":"AAAA,KAAK,cAAc,GAAG;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF;;;GAGG;AACH,wBAAgB,cAAc,CAAC,QAAQ,SAAS,cAAc,EAC5D,UAAU,EAAE,QAAQ,EAAE,GACrB,QAAQ,EAAE,CAKZ;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,SAAS,cAAc,EAC7D,UAAU,EAAE,cAAc,EAC1B,IAAI,EAAE,GAAG,EAAE,EACX,IAAI,EAAE,GAAG,EAAE,GACV,GAAG,EAAE,CAYP;AAED;;;GAGG;AACH,wBAAgB,4BAA4B,CAAC,GAAG,SAAS,cAAc,EACrE,UAAU,EAAE,cAAc,EAC1B,IAAI,EAAE,GAAG,EAAE,EACX,IAAI,EAAE,GAAG,EAAE,GACV,GAAG,EAAE,CAaP"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Sorts operations by index and skip number.
3
+ * [0:0 2:0 1:0 3:3 3:1] => [0:0 1:0 2:0 3:1 3:3]
4
+ */
5
+ export function sortOperations(operations) {
6
+ return operations
7
+ .slice()
8
+ .sort((a, b) => a.skip - b.skip)
9
+ .sort((a, b) => a.index - b.index);
10
+ }
11
+ /**
12
+ * Reshuffles operations by timestamp only, ignoring their original index values.
13
+ * Used for merging concurrent operations from different branches.
14
+ *
15
+ * Example:
16
+ * [0:0, 1:0, 2:0, A3:0, A4:0, A5:0] + [0:0, 1:0, 2:0, B3:0, B4:2, B5:0]
17
+ * GC => [0:0, 1:0, 2:0, A3:0, A4:0, A5:0] + [0:0, 1:0, B4:2, B5:0]
18
+ * Split => [0:0, 1:0] + [2:0, A3:0, A4:0, A5:0] + [B4:2, B5:0]
19
+ * Reshuffle(6:4) => [6:4, 7:0, 8:0, 9:0, 10:0, 11:0]
20
+ * merge => [0:0, 1:0, 6:4, 7:0, 8:0, 9:0, 10:0, 11:0]
21
+ */
22
+ export function reshuffleByTimestamp(startIndex, opsA, opsB) {
23
+ return [...opsA, ...opsB]
24
+ .sort((a, b) => new Date(a.timestampUtcMs || "").getTime() -
25
+ new Date(b.timestampUtcMs || "").getTime())
26
+ .map((op, i) => ({
27
+ ...op,
28
+ index: startIndex.index + i,
29
+ skip: i === 0 ? startIndex.skip : 0,
30
+ }));
31
+ }
32
+ /**
33
+ * Reshuffles operations by timestamp first, then by original index value.
34
+ * Used for merging concurrent operations while preserving index ordering for operations with same timestamp.
35
+ */
36
+ export function reshuffleByTimestampAndIndex(startIndex, opsA, opsB) {
37
+ return [...opsA, ...opsB]
38
+ .sort((a, b) => new Date(a.timestampUtcMs || "").getTime() -
39
+ new Date(b.timestampUtcMs || "").getTime())
40
+ .sort((a, b) => a.index - b.index)
41
+ .map((op, i) => ({
42
+ ...op,
43
+ index: startIndex.index + i,
44
+ skip: i === 0 ? startIndex.skip : 0,
45
+ }));
46
+ }
47
+ //# sourceMappingURL=reshuffle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reshuffle.js","sourceRoot":"","sources":["../../../src/utils/reshuffle.ts"],"names":[],"mappings":"AAOA;;;GAGG;AACH,MAAM,UAAU,cAAc,CAC5B,UAAsB;IAEtB,OAAO,UAAU;SACd,KAAK,EAAE;SACP,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC;SAC/B,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;AACvC,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,oBAAoB,CAClC,UAA0B,EAC1B,IAAW,EACX,IAAW;IAEX,OAAO,CAAC,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC;SAC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  {
2
2
  "name": "@powerhousedao/reactor",
3
- "version": "4.1.0-dev.12",
3
+ "version": "4.1.0-dev.121",
4
4
  "description": "",
5
5
  "repository": {
6
6
  "url": "https://github.com/powerhouse-inc/powerhouse",
7
7
  "directory": "packages/reactor"
8
8
  },
9
9
  "type": "module",
10
- "types": "./dist/index.d.ts",
10
+ "types": "./dist/src/index.d.ts",
11
11
  "exports": {
12
- ".": "./dist/index.js"
12
+ ".": "./dist/src/index.js"
13
13
  },
14
14
  "imports": {
15
15
  "#*": "./dist/src/*"
16
16
  },
17
17
  "files": [
18
- "./dist"
18
+ "./dist/src"
19
19
  ],
20
20
  "publishConfig": {
21
21
  "access": "public"
@@ -23,18 +23,34 @@
23
23
  "keywords": [],
24
24
  "author": "",
25
25
  "license": "AGPL-3.0-only",
26
+ "dependencies": {
27
+ "@electric-sql/pglite": "0.2.17",
28
+ "kysely": "^0.28.2",
29
+ "kysely-pglite": "^0.6.1",
30
+ "uuid": "^11.0.5",
31
+ "document-drive": "4.1.0-dev.121",
32
+ "document-model": "4.1.0-dev.121"
33
+ },
26
34
  "devDependencies": {
35
+ "@vitest/coverage-v8": "^3.2.4",
36
+ "tinybench": "^2.9.0",
37
+ "tsx": "^4.19.2",
27
38
  "typescript": "^5.7.3",
28
- "vitest": "^3.1.2"
39
+ "vitest": "^3.2.4"
29
40
  },
30
41
  "scripts": {
31
42
  "build": "pnpm run build:tsc",
32
43
  "build:tsc": "tsc --build",
33
44
  "prebuild": "pnpm run clean",
34
- "test": "vitest run",
45
+ "test": "vitest run --coverage --printConsoleTrace=true --silent=false",
46
+ "test:watch": "vitest --coverage",
35
47
  "lint": "eslint",
36
48
  "bench": "vitest bench --run",
49
+ "bench:sync": "node --import tsx bench/two-reactor-sync.bench.ts",
37
50
  "clean": "rimraf dist",
38
- "clean:node_modules": "rimraf node_modules"
51
+ "clean:node_modules": "rimraf node_modules",
52
+ "claude": "pnpm build && pnpm test && npx prettier --write \"**/*.ts\" && pnpm lint",
53
+ "migrate": "tsx src/storage/migrations/run-migrations.ts",
54
+ "migrate:status": "tsx src/storage/migrations/run-migrations.ts status"
39
55
  }
40
56
  }
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=end-to-end-flow.bench.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"end-to-end-flow.bench.d.ts","sourceRoot":"","sources":["../../bench/end-to-end-flow.bench.ts"],"names":[],"mappings":""}