@abloatai/humans 0.37.0

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 (404) hide show
  1. package/README.md +52 -0
  2. package/dist/Ablo.d.ts +208 -0
  3. package/dist/Ablo.js +120 -0
  4. package/dist/client.d.ts +317 -0
  5. package/dist/client.js +13 -0
  6. package/dist/core.d.ts +35 -0
  7. package/dist/core.js +48 -0
  8. package/dist/humans.d.ts +28 -0
  9. package/dist/humans.js +34 -0
  10. package/dist/index.d.ts +10 -0
  11. package/dist/index.js +6 -0
  12. package/dist/local/BaseSyncedStore.d.ts +807 -0
  13. package/dist/local/BaseSyncedStore.js +1516 -0
  14. package/dist/local/Database.d.ts +322 -0
  15. package/dist/local/Database.js +1589 -0
  16. package/dist/local/InstanceCache.d.ts +255 -0
  17. package/dist/local/InstanceCache.js +1263 -0
  18. package/dist/local/LazyReferenceCollection.d.ts +177 -0
  19. package/dist/local/LazyReferenceCollection.js +461 -0
  20. package/dist/local/Model.d.ts +475 -0
  21. package/dist/local/Model.js +950 -0
  22. package/dist/local/ModelRegistry.d.ts +225 -0
  23. package/dist/local/ModelRegistry.js +539 -0
  24. package/dist/local/NetworkMonitor.d.ts +28 -0
  25. package/dist/local/NetworkMonitor.js +79 -0
  26. package/dist/local/RuntimeContext.d.ts +52 -0
  27. package/dist/local/RuntimeContext.js +80 -0
  28. package/dist/local/SyncClient.d.ts +516 -0
  29. package/dist/local/SyncClient.js +1754 -0
  30. package/dist/local/adapters/alwaysOnline.d.ts +14 -0
  31. package/dist/local/adapters/alwaysOnline.js +17 -0
  32. package/dist/local/adapters/inMemoryStorage.d.ts +37 -0
  33. package/dist/local/adapters/inMemoryStorage.js +122 -0
  34. package/dist/local/client/clientPrelude.d.ts +52 -0
  35. package/dist/local/client/clientPrelude.js +60 -0
  36. package/dist/local/client/consoleLogger.d.ts +35 -0
  37. package/dist/local/client/consoleLogger.js +44 -0
  38. package/dist/local/client/createInternalComponents.d.ts +50 -0
  39. package/dist/local/client/createInternalComponents.js +98 -0
  40. package/dist/local/client/createModelProxy.d.ts +248 -0
  41. package/dist/local/client/createModelProxy.js +880 -0
  42. package/dist/local/client/modelRegistration.d.ts +10 -0
  43. package/dist/local/client/modelRegistration.js +316 -0
  44. package/dist/local/client/options.d.ts +440 -0
  45. package/dist/local/client/options.js +7 -0
  46. package/dist/local/client/reactiveEngine.d.ts +53 -0
  47. package/dist/local/client/reactiveEngine.js +705 -0
  48. package/dist/local/client/resourceTypes.d.ts +12 -0
  49. package/dist/local/client/resourceTypes.js +10 -0
  50. package/dist/local/client/schemaConfig.d.ts +44 -0
  51. package/dist/local/client/schemaConfig.js +185 -0
  52. package/dist/local/client/storeCluster.d.ts +46 -0
  53. package/dist/local/client/storeCluster.js +133 -0
  54. package/dist/local/client/storeLifecycle.d.ts +61 -0
  55. package/dist/local/client/storeLifecycle.js +236 -0
  56. package/dist/local/client/validateAbloOptions.d.ts +42 -0
  57. package/dist/local/client/validateAbloOptions.js +43 -0
  58. package/dist/local/client/wsMutationExecutor.d.ts +27 -0
  59. package/dist/local/client/wsMutationExecutor.js +72 -0
  60. package/dist/local/context.d.ts +42 -0
  61. package/dist/local/context.js +81 -0
  62. package/dist/local/coordination/ClaimLog.d.ts +26 -0
  63. package/dist/local/coordination/ClaimLog.js +32 -0
  64. package/dist/local/interfaces/index.d.ts +311 -0
  65. package/dist/local/interfaces/index.js +9 -0
  66. package/dist/local/localModelContract.d.ts +14 -0
  67. package/dist/local/localModelContract.js +1 -0
  68. package/dist/local/logPosition.d.ts +31 -0
  69. package/dist/local/logPosition.js +53 -0
  70. package/dist/local/mutationPersistence.d.ts +6 -0
  71. package/dist/local/mutationPersistence.js +1 -0
  72. package/dist/local/mutators/RecordingMutation.d.ts +36 -0
  73. package/dist/local/mutators/RecordingMutation.js +182 -0
  74. package/dist/local/mutators/Transaction.d.ts +40 -0
  75. package/dist/local/mutators/Transaction.js +58 -0
  76. package/dist/local/mutators/UndoManager.d.ts +258 -0
  77. package/dist/local/mutators/UndoManager.js +665 -0
  78. package/dist/local/mutators/defineMutators.d.ts +60 -0
  79. package/dist/local/mutators/defineMutators.js +18 -0
  80. package/dist/local/mutators/inverseOp.d.ts +126 -0
  81. package/dist/local/mutators/inverseOp.js +71 -0
  82. package/dist/local/mutators/mutateActions.d.ts +45 -0
  83. package/dist/local/mutators/mutateActions.js +105 -0
  84. package/dist/local/mutators/readerActions.d.ts +33 -0
  85. package/dist/local/mutators/readerActions.js +57 -0
  86. package/dist/local/mutators/undoApply.d.ts +51 -0
  87. package/dist/local/mutators/undoApply.js +117 -0
  88. package/dist/local/persistence.d.ts +7 -0
  89. package/dist/local/persistence.js +9 -0
  90. package/dist/local/query/QueryProcessor.d.ts +75 -0
  91. package/dist/local/query/QueryProcessor.js +255 -0
  92. package/dist/local/query/client.d.ts +64 -0
  93. package/dist/local/query/client.js +138 -0
  94. package/dist/local/query/types.d.ts +85 -0
  95. package/dist/local/query/types.js +16 -0
  96. package/dist/local/schema/serialize.d.ts +1 -0
  97. package/dist/local/schema/serialize.js +1 -0
  98. package/dist/local/store/queryApi.d.ts +13 -0
  99. package/dist/local/store/queryApi.js +35 -0
  100. package/dist/local/storeContract.d.ts +145 -0
  101. package/dist/local/storeContract.js +12 -0
  102. package/dist/local/stores/DatabaseManager.d.ts +112 -0
  103. package/dist/local/stores/DatabaseManager.js +400 -0
  104. package/dist/local/stores/ObjectStore.d.ts +115 -0
  105. package/dist/local/stores/ObjectStore.js +393 -0
  106. package/dist/local/stores/ObjectStoreContract.d.ts +38 -0
  107. package/dist/local/stores/ObjectStoreContract.js +1 -0
  108. package/dist/local/stores/StoreManager.d.ts +114 -0
  109. package/dist/local/stores/StoreManager.js +304 -0
  110. package/dist/local/stores/SyncActionStore.d.ts +99 -0
  111. package/dist/local/stores/SyncActionStore.js +506 -0
  112. package/dist/local/stores/openIDBWithTimeout.d.ts +65 -0
  113. package/dist/local/stores/openIDBWithTimeout.js +153 -0
  114. package/dist/local/stores/persistenceCleanup.d.ts +7 -0
  115. package/dist/local/stores/persistenceCleanup.js +26 -0
  116. package/dist/local/stores/persistenceIdentity.d.ts +27 -0
  117. package/dist/local/stores/persistenceIdentity.js +38 -0
  118. package/dist/local/stores/syncAction.d.ts +26 -0
  119. package/dist/local/stores/syncAction.js +16 -0
  120. package/dist/local/stores/v1PersistenceDeletion.d.ts +8 -0
  121. package/dist/local/stores/v1PersistenceDeletion.js +16 -0
  122. package/dist/local/sync/BootstrapFetcher.d.ts +284 -0
  123. package/dist/local/sync/BootstrapFetcher.js +964 -0
  124. package/dist/local/sync/ConnectionManager.d.ts +8 -0
  125. package/dist/local/sync/ConnectionManager.js +8 -0
  126. package/dist/local/sync/OnDemandLoader.d.ts +231 -0
  127. package/dist/local/sync/OnDemandLoader.js +743 -0
  128. package/dist/local/sync/SubscriptionManager.d.ts +159 -0
  129. package/dist/local/sync/SubscriptionManager.js +243 -0
  130. package/dist/local/sync/SyncWebSocket.d.ts +173 -0
  131. package/dist/local/sync/SyncWebSocket.js +438 -0
  132. package/dist/local/sync/bootstrapApply.d.ts +73 -0
  133. package/dist/local/sync/bootstrapApply.js +73 -0
  134. package/dist/local/sync/commitFrames.d.ts +8 -0
  135. package/dist/local/sync/commitFrames.js +8 -0
  136. package/dist/local/sync/connectionManagerLifecycle.d.ts +23 -0
  137. package/dist/local/sync/connectionManagerLifecycle.js +126 -0
  138. package/dist/local/sync/contextPorts.d.ts +18 -0
  139. package/dist/local/sync/contextPorts.js +31 -0
  140. package/dist/local/sync/createClaimStream.d.ts +64 -0
  141. package/dist/local/sync/createClaimStream.js +475 -0
  142. package/dist/local/sync/createSnapshot.d.ts +29 -0
  143. package/dist/local/sync/createSnapshot.js +116 -0
  144. package/dist/local/sync/credentialLifecycle.d.ts +7 -0
  145. package/dist/local/sync/credentialLifecycle.js +7 -0
  146. package/dist/local/sync/deltaPipeline.d.ts +116 -0
  147. package/dist/local/sync/deltaPipeline.js +357 -0
  148. package/dist/local/sync/groupChange.d.ts +116 -0
  149. package/dist/local/sync/groupChange.js +244 -0
  150. package/dist/local/sync/initialize.d.ts +27 -0
  151. package/dist/local/sync/initialize.js +137 -0
  152. package/dist/local/sync/participants.d.ts +132 -0
  153. package/dist/local/sync/participants.js +342 -0
  154. package/dist/local/sync/persistedPrefix.d.ts +12 -0
  155. package/dist/local/sync/persistedPrefix.js +22 -0
  156. package/dist/local/sync/reconnect.d.ts +23 -0
  157. package/dist/local/sync/reconnect.js +55 -0
  158. package/dist/local/sync/schemaDrift.d.ts +55 -0
  159. package/dist/local/sync/schemaDrift.js +53 -0
  160. package/dist/local/sync/schemas.d.ts +71 -0
  161. package/dist/local/sync/schemas.js +94 -0
  162. package/dist/local/sync/socketEventWiring.d.ts +31 -0
  163. package/dist/local/sync/socketEventWiring.js +130 -0
  164. package/dist/local/sync/syncCursor.d.ts +40 -0
  165. package/dist/local/sync/syncCursor.js +55 -0
  166. package/dist/local/sync/syncPlan.d.ts +54 -0
  167. package/dist/local/sync/syncPlan.js +50 -0
  168. package/dist/local/sync/terminalSessionLifecycle.d.ts +20 -0
  169. package/dist/local/sync/terminalSessionLifecycle.js +50 -0
  170. package/dist/local/sync/wsFrameHandlers.d.ts +8 -0
  171. package/dist/local/sync/wsFrameHandlers.js +8 -0
  172. package/dist/local/transactions/databaseCommitOutbox.d.ts +15 -0
  173. package/dist/local/transactions/databaseCommitOutbox.js +16 -0
  174. package/dist/local/transactions/localMutation.d.ts +10 -0
  175. package/dist/local/transactions/localMutation.js +37 -0
  176. package/dist/local/transactions/mutations/MutationQueue.d.ts +511 -0
  177. package/dist/local/transactions/mutations/MutationQueue.js +1498 -0
  178. package/dist/local/transactions/mutations/MutationStore.d.ts +20 -0
  179. package/dist/local/transactions/mutations/MutationStore.js +53 -0
  180. package/dist/local/transactions/mutations/UnconfirmedWrites.d.ts +82 -0
  181. package/dist/local/transactions/mutations/UnconfirmedWrites.js +104 -0
  182. package/dist/local/transactions/mutations/batchProcessing.d.ts +64 -0
  183. package/dist/local/transactions/mutations/batchProcessing.js +349 -0
  184. package/dist/local/transactions/mutations/coalesceRules.d.ts +58 -0
  185. package/dist/local/transactions/mutations/coalesceRules.js +140 -0
  186. package/dist/local/transactions/mutations/commitApi.d.ts +19 -0
  187. package/dist/local/transactions/mutations/commitApi.js +74 -0
  188. package/dist/local/transactions/mutations/commitLane.d.ts +70 -0
  189. package/dist/local/transactions/mutations/commitLane.js +140 -0
  190. package/dist/local/transactions/mutations/commitLatency.d.ts +52 -0
  191. package/dist/local/transactions/mutations/commitLatency.js +130 -0
  192. package/dist/local/transactions/mutations/commitPayload.d.ts +165 -0
  193. package/dist/local/transactions/mutations/commitPayload.js +152 -0
  194. package/dist/local/transactions/mutations/commitTransport.d.ts +36 -0
  195. package/dist/local/transactions/mutations/commitTransport.js +104 -0
  196. package/dist/local/transactions/mutations/deltaConfirmation.d.ts +63 -0
  197. package/dist/local/transactions/mutations/deltaConfirmation.js +235 -0
  198. package/dist/local/transactions/mutations/durableCommitRestore.d.ts +17 -0
  199. package/dist/local/transactions/mutations/durableCommitRestore.js +95 -0
  200. package/dist/local/transactions/mutations/durableWriteStore.d.ts +14 -0
  201. package/dist/local/transactions/mutations/durableWriteStore.js +12 -0
  202. package/dist/local/transactions/mutations/executionSelection.d.ts +6 -0
  203. package/dist/local/transactions/mutations/executionSelection.js +42 -0
  204. package/dist/local/transactions/mutations/failureHandling.d.ts +16 -0
  205. package/dist/local/transactions/mutations/failureHandling.js +130 -0
  206. package/dist/local/transactions/mutations/failurePolicy.d.ts +13 -0
  207. package/dist/local/transactions/mutations/failurePolicy.js +48 -0
  208. package/dist/local/transactions/mutations/localMutation.d.ts +58 -0
  209. package/dist/local/transactions/mutations/localMutation.js +75 -0
  210. package/dist/local/transactions/mutations/modelOperations.d.ts +44 -0
  211. package/dist/local/transactions/mutations/modelOperations.js +144 -0
  212. package/dist/local/transactions/mutations/mutationPersistence.d.ts +25 -0
  213. package/dist/local/transactions/mutations/mutationPersistence.js +188 -0
  214. package/dist/local/transactions/mutations/pendingDrain.d.ts +33 -0
  215. package/dist/local/transactions/mutations/pendingDrain.js +112 -0
  216. package/dist/local/transactions/mutations/processingScheduler.d.ts +14 -0
  217. package/dist/local/transactions/mutations/processingScheduler.js +24 -0
  218. package/dist/local/transactions/mutations/queueCoalescing.d.ts +13 -0
  219. package/dist/local/transactions/mutations/queueCoalescing.js +35 -0
  220. package/dist/local/transactions/mutations/replayValidation.d.ts +187 -0
  221. package/dist/local/transactions/mutations/replayValidation.js +164 -0
  222. package/dist/local/transactions/reconnectDrain.d.ts +11 -0
  223. package/dist/local/transactions/reconnectDrain.js +13 -0
  224. package/dist/local/utils/mobxSetup.d.ts +53 -0
  225. package/dist/local/utils/mobxSetup.js +330 -0
  226. package/dist/local/views/QueryView.d.ts +79 -0
  227. package/dist/local/views/QueryView.js +218 -0
  228. package/dist/local/views/ViewRegistry.d.ts +20 -0
  229. package/dist/local/views/ViewRegistry.js +57 -0
  230. package/dist/local/views/incrementalView.d.ts +45 -0
  231. package/dist/local/views/incrementalView.js +69 -0
  232. package/dist/plugin.d.ts +285 -0
  233. package/dist/plugin.js +106 -0
  234. package/dist/presenceStream.d.ts +69 -0
  235. package/dist/presenceStream.js +200 -0
  236. package/dist/react/AbloProvider.d.ts +242 -0
  237. package/dist/react/AbloProvider.js +456 -0
  238. package/dist/react/ClientSideSuspense.d.ts +36 -0
  239. package/dist/react/ClientSideSuspense.js +17 -0
  240. package/dist/react/DefaultFallback.d.ts +24 -0
  241. package/dist/react/DefaultFallback.js +43 -0
  242. package/dist/react/context.d.ts +55 -0
  243. package/dist/react/context.js +29 -0
  244. package/dist/react/createAbloReact.d.ts +50 -0
  245. package/dist/react/createAbloReact.js +48 -0
  246. package/dist/react/internalContext.d.ts +33 -0
  247. package/dist/react/internalContext.js +3 -0
  248. package/dist/react/useAblo.d.ts +96 -0
  249. package/dist/react/useAblo.js +120 -0
  250. package/dist/react/useCurrentUserId.d.ts +2 -0
  251. package/dist/react/useCurrentUserId.js +12 -0
  252. package/dist/react/useErrorListener.d.ts +2 -0
  253. package/dist/react/useErrorListener.js +14 -0
  254. package/dist/react/useMutationFailureListener.d.ts +8 -0
  255. package/dist/react/useMutationFailureListener.js +19 -0
  256. package/dist/react/useMutators.d.ts +56 -0
  257. package/dist/react/useMutators.js +84 -0
  258. package/dist/react/useSyncStatus.d.ts +19 -0
  259. package/dist/react/useSyncStatus.js +37 -0
  260. package/dist/react/useUndoScope.d.ts +34 -0
  261. package/dist/react/useUndoScope.js +73 -0
  262. package/dist/react.d.ts +18 -0
  263. package/dist/react.js +14 -0
  264. package/dist/reactRuntime.d.ts +4 -0
  265. package/dist/reactRuntime.js +2 -0
  266. package/dist/surface.d.ts +36 -0
  267. package/dist/surface.js +77 -0
  268. package/dist/useReactive.d.ts +6 -0
  269. package/dist/useReactive.js +43 -0
  270. package/package.json +119 -0
  271. package/src/Ablo.ts +456 -0
  272. package/src/client.ts +374 -0
  273. package/src/core.ts +104 -0
  274. package/src/humans.ts +61 -0
  275. package/src/index.ts +40 -0
  276. package/src/local/BaseSyncedStore.ts +1991 -0
  277. package/src/local/Database.ts +2052 -0
  278. package/src/local/InstanceCache.ts +1503 -0
  279. package/src/local/LazyReferenceCollection.ts +563 -0
  280. package/src/local/Model.ts +1124 -0
  281. package/src/local/ModelRegistry.ts +762 -0
  282. package/src/local/NetworkMonitor.ts +88 -0
  283. package/src/local/RuntimeContext.ts +141 -0
  284. package/src/local/SyncClient.ts +2131 -0
  285. package/src/local/adapters/alwaysOnline.ts +20 -0
  286. package/src/local/adapters/inMemoryStorage.ts +141 -0
  287. package/src/local/client/clientPrelude.ts +112 -0
  288. package/src/local/client/consoleLogger.ts +60 -0
  289. package/src/local/client/createInternalComponents.ts +163 -0
  290. package/src/local/client/createModelProxy.ts +1390 -0
  291. package/src/local/client/modelRegistration.ts +350 -0
  292. package/src/local/client/options.ts +526 -0
  293. package/src/local/client/reactiveEngine.ts +935 -0
  294. package/src/local/client/resourceTypes.ts +37 -0
  295. package/src/local/client/schemaConfig.ts +194 -0
  296. package/src/local/client/storeCluster.ts +172 -0
  297. package/src/local/client/storeLifecycle.ts +343 -0
  298. package/src/local/client/validateAbloOptions.ts +95 -0
  299. package/src/local/client/wsMutationExecutor.ts +110 -0
  300. package/src/local/context.ts +96 -0
  301. package/src/local/coordination/ClaimLog.ts +39 -0
  302. package/src/local/interfaces/index.ts +468 -0
  303. package/src/local/localModelContract.ts +15 -0
  304. package/src/local/logPosition.ts +84 -0
  305. package/src/local/mutationPersistence.ts +7 -0
  306. package/src/local/mutators/RecordingMutation.ts +222 -0
  307. package/src/local/mutators/Transaction.ts +97 -0
  308. package/src/local/mutators/UndoManager.ts +741 -0
  309. package/src/local/mutators/defineMutators.ts +76 -0
  310. package/src/local/mutators/inverseOp.ts +83 -0
  311. package/src/local/mutators/mutateActions.ts +167 -0
  312. package/src/local/mutators/readerActions.ts +99 -0
  313. package/src/local/mutators/undoApply.ts +141 -0
  314. package/src/local/persistence.ts +16 -0
  315. package/src/local/query/QueryProcessor.ts +347 -0
  316. package/src/local/query/client.ts +197 -0
  317. package/src/local/query/types.ts +102 -0
  318. package/src/local/schema/serialize.ts +1 -0
  319. package/src/local/store/queryApi.ts +56 -0
  320. package/src/local/storeContract.ts +146 -0
  321. package/src/local/stores/DatabaseManager.ts +507 -0
  322. package/src/local/stores/ObjectStore.ts +449 -0
  323. package/src/local/stores/ObjectStoreContract.ts +48 -0
  324. package/src/local/stores/StoreManager.ts +388 -0
  325. package/src/local/stores/SyncActionStore.ts +579 -0
  326. package/src/local/stores/openIDBWithTimeout.ts +195 -0
  327. package/src/local/stores/persistenceCleanup.ts +43 -0
  328. package/src/local/stores/persistenceIdentity.ts +83 -0
  329. package/src/local/stores/syncAction.ts +21 -0
  330. package/src/local/stores/v1PersistenceDeletion.ts +21 -0
  331. package/src/local/sync/BootstrapFetcher.ts +1224 -0
  332. package/src/local/sync/ConnectionManager.ts +15 -0
  333. package/src/local/sync/OnDemandLoader.ts +927 -0
  334. package/src/local/sync/SubscriptionManager.ts +300 -0
  335. package/src/local/sync/SyncWebSocket.ts +584 -0
  336. package/src/local/sync/bootstrapApply.ts +130 -0
  337. package/src/local/sync/commitFrames.ts +16 -0
  338. package/src/local/sync/connectionManagerLifecycle.ts +158 -0
  339. package/src/local/sync/contextPorts.ts +37 -0
  340. package/src/local/sync/createClaimStream.ts +668 -0
  341. package/src/local/sync/createSnapshot.ts +160 -0
  342. package/src/local/sync/credentialLifecycle.ts +18 -0
  343. package/src/local/sync/deltaPipeline.ts +473 -0
  344. package/src/local/sync/groupChange.ts +343 -0
  345. package/src/local/sync/initialize.ts +205 -0
  346. package/src/local/sync/participants.ts +564 -0
  347. package/src/local/sync/persistedPrefix.ts +27 -0
  348. package/src/local/sync/reconnect.ts +88 -0
  349. package/src/local/sync/schemaDrift.ts +86 -0
  350. package/src/local/sync/schemas.ts +118 -0
  351. package/src/local/sync/socketEventWiring.ts +196 -0
  352. package/src/local/sync/syncCursor.ts +62 -0
  353. package/src/local/sync/syncPlan.ts +89 -0
  354. package/src/local/sync/terminalSessionLifecycle.ts +66 -0
  355. package/src/local/sync/wsFrameHandlers.ts +20 -0
  356. package/src/local/transactions/databaseCommitOutbox.ts +33 -0
  357. package/src/local/transactions/localMutation.ts +58 -0
  358. package/src/local/transactions/mutations/MutationQueue.ts +1998 -0
  359. package/src/local/transactions/mutations/MutationStore.ts +65 -0
  360. package/src/local/transactions/mutations/UnconfirmedWrites.ts +133 -0
  361. package/src/local/transactions/mutations/batchProcessing.ts +469 -0
  362. package/src/local/transactions/mutations/coalesceRules.ts +192 -0
  363. package/src/local/transactions/mutations/commitApi.ts +97 -0
  364. package/src/local/transactions/mutations/commitLane.ts +191 -0
  365. package/src/local/transactions/mutations/commitLatency.ts +164 -0
  366. package/src/local/transactions/mutations/commitPayload.ts +281 -0
  367. package/src/local/transactions/mutations/commitTransport.ts +174 -0
  368. package/src/local/transactions/mutations/deltaConfirmation.ts +298 -0
  369. package/src/local/transactions/mutations/durableCommitRestore.ts +128 -0
  370. package/src/local/transactions/mutations/durableWriteStore.ts +21 -0
  371. package/src/local/transactions/mutations/executionSelection.ts +42 -0
  372. package/src/local/transactions/mutations/failureHandling.ts +154 -0
  373. package/src/local/transactions/mutations/failurePolicy.ts +61 -0
  374. package/src/local/transactions/mutations/localMutation.ts +135 -0
  375. package/src/local/transactions/mutations/modelOperations.ts +210 -0
  376. package/src/local/transactions/mutations/mutationPersistence.ts +231 -0
  377. package/src/local/transactions/mutations/pendingDrain.ts +160 -0
  378. package/src/local/transactions/mutations/processingScheduler.ts +35 -0
  379. package/src/local/transactions/mutations/queueCoalescing.ts +45 -0
  380. package/src/local/transactions/mutations/replayValidation.ts +192 -0
  381. package/src/local/transactions/reconnectDrain.ts +24 -0
  382. package/src/local/utils/mobxSetup.ts +388 -0
  383. package/src/local/views/QueryView.ts +311 -0
  384. package/src/local/views/ViewRegistry.ts +61 -0
  385. package/src/local/views/incrementalView.ts +92 -0
  386. package/src/plugin.ts +396 -0
  387. package/src/presenceStream.ts +279 -0
  388. package/src/react/AbloProvider.tsx +744 -0
  389. package/src/react/ClientSideSuspense.tsx +57 -0
  390. package/src/react/DefaultFallback.tsx +60 -0
  391. package/src/react/context.ts +89 -0
  392. package/src/react/createAbloReact.ts +116 -0
  393. package/src/react/internalContext.ts +38 -0
  394. package/src/react/useAblo.ts +280 -0
  395. package/src/react/useCurrentUserId.ts +17 -0
  396. package/src/react/useErrorListener.ts +22 -0
  397. package/src/react/useMutationFailureListener.ts +34 -0
  398. package/src/react/useMutators.ts +184 -0
  399. package/src/react/useSyncStatus.ts +42 -0
  400. package/src/react/useUndoScope.ts +143 -0
  401. package/src/react.ts +69 -0
  402. package/src/reactRuntime.ts +10 -0
  403. package/src/surface.ts +106 -0
  404. package/src/useReactive.ts +51 -0
@@ -0,0 +1,456 @@
1
+ 'use client';
2
+ import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import { useCallback, useContext, useEffect, useMemo, useRef, useState, createContext, } from 'react';
4
+ import { createParticipantClaimId, parseParticipantTtlSeconds, resolveParticipantSyncGroups, } from '../local/sync/participants.js';
5
+ import { SyncContext } from './context.js';
6
+ import { AbloInternalContext } from './internalContext.js';
7
+ import { AbloValidationError } from '@abloatai/transaction/errors';
8
+ import { useSyncStatus } from './useSyncStatus.js';
9
+ import { DefaultFallback } from './DefaultFallback.js';
10
+ // ── Implementation ───────────────────────────────────────────────────
11
+ /**
12
+ * Lightweight event emitter for provider-level errors. Lives on the
13
+ * provider instance (ref-based) so `useErrorListener` subscriptions
14
+ * survive re-renders without thrashing.
15
+ */
16
+ function createErrorEmitter() {
17
+ const listeners = new Set();
18
+ return {
19
+ subscribe(fn) {
20
+ listeners.add(fn);
21
+ return () => { listeners.delete(fn); };
22
+ },
23
+ emit(err) {
24
+ for (const fn of listeners) {
25
+ try {
26
+ fn(err);
27
+ }
28
+ catch { }
29
+ }
30
+ },
31
+ };
32
+ }
33
+ export function AbloProvider(props) {
34
+ const { client, userId, preventUnsavedChanges, onSessionExpired, onError, fallback = _jsx(DefaultFallback, {}), children, } = props;
35
+ // The client IS the engine — synchronous, never null. This provider is a
36
+ // REACTIVE binding over it (context + bootstrap gate + error/session
37
+ // forwarding); it does NOT construct, configure, or own the connection. The
38
+ // client owns auth, the credential lifecycle (first mint, refresh, and
39
+ // wake/online/focus re-mint — see `Ablo({ apiKey })`), transport, and
40
+ // `dispose()`. The CONSUMER built the client, so the consumer owns teardown;
41
+ // the provider never disposes it.
42
+ const engine = client;
43
+ const schema = engine.schema;
44
+ // Account scope isn't a prop — read it from `_store.orgId` once `ready()`
45
+ // resolves the identity from the client's auth.
46
+ const [resolvedAccountScope, setResolvedAccountScope] = useState(null);
47
+ // ── Error emitter (provider-instance scoped) ─────────────────────
48
+ const errorEmitterRef = useRef(null);
49
+ if (!errorEmitterRef.current) {
50
+ errorEmitterRef.current = createErrorEmitter();
51
+ }
52
+ const errorEmitter = errorEmitterRef.current;
53
+ // Stash callbacks in refs so a new identity each render doesn't re-run the
54
+ // start effect (the `useEventCallback` idiom).
55
+ const onErrorRef = useRef(onError);
56
+ onErrorRef.current = onError;
57
+ useEffect(() => {
58
+ return errorEmitter.subscribe((err) => onErrorRef.current?.(err));
59
+ }, [errorEmitter]);
60
+ const onSessionExpiredRef = useRef(onSessionExpired);
61
+ onSessionExpiredRef.current = onSessionExpired;
62
+ // Re-key the bootstrap gate when the client INSTANCE changes — a genuinely new
63
+ // engine is a fresh "first bootstrap". Stable for the common single-client app.
64
+ const clientGenRef = useRef({ client, gen: 0 });
65
+ if (clientGenRef.current.client !== client) {
66
+ clientGenRef.current = { client, gen: clientGenRef.current.gen + 1 };
67
+ }
68
+ const engineKey = String(clientGenRef.current.gen);
69
+ // ── Start + session-error wiring ─────────────────────────────────
70
+ //
71
+ // Two reactive jobs only:
72
+ // 1. Forward the client's completed terminal-session transition to
73
+ // onSessionExpired. Credential cleanup lives in the CLIENT, so direct
74
+ // consumers and React consumers have the same security boundary.
75
+ // 2. Drive `ready()` (idempotent) so bootstrap starts on mount, then read the
76
+ // resolved org scope for SyncContext.
77
+ // It does NOT dispose the client (consumer-owned) and does NOT touch auth.
78
+ useEffect(() => {
79
+ let stale = false;
80
+ const unsubscribeSession = engine.onSessionError((err) => {
81
+ errorEmitter.emit(err);
82
+ void (async () => {
83
+ try {
84
+ await onSessionExpiredRef.current?.();
85
+ }
86
+ catch (hookErr) {
87
+ errorEmitter.emit(hookErr);
88
+ }
89
+ })().catch(() => {
90
+ // Only a throwing errorEmitter subscriber can land here — it was
91
+ // already the error-reporting path, so swallow rather than surface
92
+ // an unhandled rejection loop.
93
+ });
94
+ });
95
+ engine
96
+ .ready()
97
+ .then(() => {
98
+ if (stale)
99
+ return;
100
+ setResolvedAccountScope(engine._store.orgId ?? null);
101
+ })
102
+ .catch((err) => {
103
+ if (stale)
104
+ return;
105
+ errorEmitter.emit(err);
106
+ });
107
+ return () => {
108
+ stale = true;
109
+ unsubscribeSession();
110
+ };
111
+ }, [engine, errorEmitter]);
112
+ // ── beforeunload + preventUnsavedChanges ─────────────────────────
113
+ useEffect(() => {
114
+ if (typeof window === 'undefined')
115
+ return;
116
+ const handler = (event) => {
117
+ // Best-effort IDB flush on TAB CLOSE — the client is going away with the
118
+ // page regardless. This is NOT an unmount teardown: the consumer owns the
119
+ // client's lifecycle and the provider never disposes it on unmount.
120
+ void engine.dispose();
121
+ if (preventUnsavedChanges && engine._store.hasUnsyncedChanges) {
122
+ event.preventDefault();
123
+ event.returnValue = '';
124
+ }
125
+ };
126
+ window.addEventListener('beforeunload', handler);
127
+ return () => { window.removeEventListener('beforeunload', handler); };
128
+ }, [engine, preventUnsavedChanges]);
129
+ // ── SyncContext value (for useQuery/useOne/useMutate hooks) ──────
130
+ //
131
+ // The engine is always present (it's the `client` prop), but its org scope is
132
+ // unknown until `ready()` resolves identity — so `syncValue` is null until
133
+ // then, which drives the initial fallback below.
134
+ const syncValue = useMemo(() => {
135
+ const currentAccountScope = resolvedAccountScope ??
136
+ engine._store.orgId;
137
+ if (!currentAccountScope)
138
+ return null;
139
+ return {
140
+ store: engine._store,
141
+ organizationId: currentAccountScope,
142
+ schema,
143
+ };
144
+ }, [engine, resolvedAccountScope, schema]);
145
+ // ── Internal context (currentUserId + error subscription) ────────
146
+ const internalValue = useMemo(() => ({
147
+ currentUserId: userId ?? null,
148
+ subscribeError: errorEmitter.subscribe,
149
+ emitError: errorEmitter.emit,
150
+ engine: engine,
151
+ }), [userId, errorEmitter, engine]);
152
+ // ── Render ───────────────────────────────────────────────────────
153
+ //
154
+ // Two-phase gate (see `BootstrapGate` below for the latch logic):
155
+ //
156
+ // 1. Engine is null on first render (constructed in the effect
157
+ // above, not in render). We render `fallback` directly — there
158
+ // is no SyncContext to read status from, and by definition the
159
+ // engine hasn't started bootstrapping.
160
+ // 2. Engine exists. Mount SyncContext. `BootstrapGate` then reads
161
+ // `useSyncStatus()` and shows `fallback` only during the very
162
+ // first `connecting` transition; children render on every
163
+ // subsequent state change, including reconnects and auth
164
+ // failures (the app's own UI handles those).
165
+ //
166
+ // `fallback === 'passthrough'` short-circuits both branches — children
167
+ // render immediately without any gate, restoring pre-gate behavior
168
+ // for consumers who need debug helpers / error boundaries / analytics
169
+ // to mount before the engine is ready.
170
+ const passthrough = fallback === 'passthrough';
171
+ const initialFallback = passthrough ? children : fallback;
172
+ if (!syncValue) {
173
+ return (_jsx(AbloInternalContext.Provider, { value: internalValue, children: initialFallback }));
174
+ }
175
+ return (_jsx(AbloInternalContext.Provider, { value: internalValue, children: _jsx(SyncContext.Provider, { value: syncValue, children: passthrough ? (children) : (_jsx(BootstrapGate, { fallback: fallback, children: children }, engineKey)) }) }));
176
+ }
177
+ /**
178
+ * Internal gate that renders `fallback` only during the very first
179
+ * bootstrap pass. Latches open on the first `connected` / `reconnecting`
180
+ * / `disconnected` transition and stays open — subsequent transient
181
+ * `connecting` states (hard reconnect after an offline stretch) do NOT
182
+ * re-show the fallback, because by then the app has already rendered
183
+ * once and its own reconnect UI should take over.
184
+ *
185
+ * Re-keyed on `engineState.key` in the parent so engine rotations
186
+ * (userId/org/url change) reset the latch — a new engine genuinely IS
187
+ * a new "first bootstrap" cycle.
188
+ */
189
+ function BootstrapGate({ fallback, children, }) {
190
+ const status = useSyncStatus();
191
+ const [everConnected, setEverConnected] = useState(false);
192
+ useEffect(() => {
193
+ if (status.name === 'connected' ||
194
+ status.name === 'reconnecting' ||
195
+ status.name === 'disconnected') {
196
+ setEverConnected(true);
197
+ }
198
+ }, [status.name]);
199
+ const showFallback = !everConnected && status.name === 'connecting';
200
+ return _jsx(_Fragment, { children: showFallback ? fallback : children });
201
+ }
202
+ const EMPTY_PRESENCE = Object.freeze([]);
203
+ const EMPTY_INTENTS = Object.freeze([]);
204
+ /**
205
+ * Join multiplayer for a given scope. Returns the participant and its
206
+ * lifecycle status. Auto-cleans up on unmount or when `paused`
207
+ * flips to true.
208
+ *
209
+ * `useJoin` is the React form of `ablo.<model>.join` — scope-level
210
+ * read-interest + presence; returns the reactive participant facade
211
+ * (peers/claims/status).
212
+ *
213
+ * The returned `participant` is an `EngineParticipant` — `.presence`
214
+ * + `.claims` only — backed by the engine's existing socket. For
215
+ * headless-bot patterns (a separate identity in the same browser
216
+ * tab), construct a second `Ablo({ kind: 'agent', ... })` directly.
217
+ */
218
+ export function useJoin(opts) {
219
+ const ctx = useContext(AbloInternalContext);
220
+ const engine = ctx?.engine ?? null;
221
+ const { paused = false } = opts;
222
+ // Resolve the model-form scope ({ reports: id } / refs) THROUGH the schema, so a
223
+ // model's declared `scope` kind is honored (typename `Report` → `report:<id>`,
224
+ // not the `type:id` string fallback). Schema appears once the engine is ready;
225
+ // until then refs resolve by convention, then re-resolve when it arrives.
226
+ const scopeKey = JSON.stringify(resolveParticipantSyncGroups(opts.scope, engine?.schema).sort());
227
+ const scopedSyncGroups = useMemo(() => JSON.parse(scopeKey), [scopeKey]);
228
+ const [claimError, setClaimError] = useState(null);
229
+ const [claimConnected, setClaimConnected] = useState(false);
230
+ // Reference-stable participant facade — same socket as entity sync,
231
+ // so there is no `connect()` / `disconnect()` lifecycle here. The
232
+ // engine manages the connection; the hook is a thin window onto its
233
+ // already-attached presence + claim streams.
234
+ const participant = useMemo(() => {
235
+ if (!engine)
236
+ return null;
237
+ return { presence: engine.presence, claims: engine.claims };
238
+ }, [engine]);
239
+ // Status maps to the engine's sync state. `connecting` while the
240
+ // engine bootstraps; `connected` once `engine.ready()` resolves and
241
+ // any scoped participant claim has acked; `error` if the claim
242
+ // fails; `disconnected` while paused or before the engine exists.
243
+ const syncStatus = useSyncStatus();
244
+ // Only a write-claim participant waits on a claim ack. A pure reader
245
+ // (the default) is `connected` as soon as the engine is — its read
246
+ // interest is fire-and-forget `update_subscription`, not a claim.
247
+ const needsClaim = !!opts.claim && scopedSyncGroups.length > 0;
248
+ const status = paused || !engine
249
+ ? 'disconnected'
250
+ : claimError
251
+ ? 'error'
252
+ : syncStatus.name === 'connected'
253
+ ? needsClaim && !claimConnected
254
+ ? 'connecting'
255
+ : 'connected'
256
+ : syncStatus.name === 'disconnected' || syncStatus.name === 'needs-auth'
257
+ ? 'disconnected'
258
+ : 'connecting';
259
+ const error = claimError;
260
+ // ── Read interest (always) ───────────────────────────────────────
261
+ // Subscribe the connection to the scope's sync groups while mounted +
262
+ // connected — the area-of-interest navigation primitive. No claim, no
263
+ // TTL: a viewer just receives the scope's deltas. Hysteresis (warm TTL)
264
+ // lives in the store's SubscriptionManager, so a quick unmount/remount
265
+ // (tab flip) doesn't re-bootstrap.
266
+ useEffect(() => {
267
+ const scope = opts.scope;
268
+ if (paused || !engine || !scope || scopedSyncGroups.length === 0)
269
+ return;
270
+ if (syncStatus.name !== 'connected')
271
+ return;
272
+ const store = engine._store;
273
+ // `hydrate` backfills the scope's current state after subscribing
274
+ // (store handles subscribe-first ordering + single-flight). leaveScope
275
+ // only moves read interest; the hydrated rows stay in the pool.
276
+ void store.enterScope?.(scope, { hydrate: opts.hydrate });
277
+ return () => {
278
+ void store.leaveScope?.(scope);
279
+ };
280
+ // scopeKey is the stable proxy for the resolved groups; same idiom as
281
+ // the claim effect below.
282
+ }, [engine, paused, scopeKey, syncStatus.name, opts.hydrate]);
283
+ // ── Write claim (opt-in: `claim: true`) ─────────────────────────
284
+ // A claim is the write-claim primitive — distinct from read interest
285
+ // above. Only sent when the caller opts in; it makes peers observe the
286
+ // claim and pins the scope so it never warms while held.
287
+ useEffect(() => {
288
+ setClaimError(null);
289
+ setClaimConnected(false);
290
+ const scope = opts.scope;
291
+ if (paused || !engine || !opts.claim || !scope || scopedSyncGroups.length === 0)
292
+ return;
293
+ if (syncStatus.name !== 'connected')
294
+ return;
295
+ const ws = engine._ws;
296
+ const store = engine._store;
297
+ let cancelled = false;
298
+ const claimId = createParticipantClaimId();
299
+ ws.sendClaim(claimId, scopedSyncGroups, {
300
+ // Reading the retired spelling IS the compatibility path; it goes at 0.37.0.
301
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
302
+ ttlSeconds: parseParticipantTtlSeconds(opts.ttl ?? opts.ttlSeconds),
303
+ })
304
+ .then(() => {
305
+ if (!cancelled)
306
+ setClaimConnected(true);
307
+ })
308
+ .catch((err) => {
309
+ if (!cancelled) {
310
+ setClaimError(err instanceof Error ? err : new Error(String(err)));
311
+ }
312
+ });
313
+ // Prominence: hold the scope subscribed for as long as the claim lives.
314
+ void store.pinScope?.(scope);
315
+ return () => {
316
+ cancelled = true;
317
+ ws.sendRelease(claimId);
318
+ void store.unpinScope?.(scope);
319
+ };
320
+ // eslint-disable-next-line @typescript-eslint/no-deprecated -- same compatibility read as above.
321
+ }, [engine, paused, scopeKey, syncStatus.name, opts.ttl, opts.ttlSeconds, opts.claim]);
322
+ // Bridge the engine's presence + claims streams into React state.
323
+ // Plain useState + useEffect is sufficient — mid-frame tearing on a
324
+ // peer list is harmless (users won't notice one frame of stale
325
+ // presence). Queries and sync status use useSyncExternalStore
326
+ // because transactions CAN tear visibly; presence can't.
327
+ const [peers, setPeers] = useState(EMPTY_PRESENCE);
328
+ const [claims, setClaims] = useState(EMPTY_INTENTS);
329
+ useEffect(() => {
330
+ if (!participant || paused) {
331
+ setPeers(EMPTY_PRESENCE);
332
+ setClaims(EMPTY_INTENTS);
333
+ return;
334
+ }
335
+ setPeers(participant.presence.others);
336
+ setClaims(participant.claims.others);
337
+ const unsubPresence = participant.presence.onChange(() => {
338
+ setPeers(participant.presence.others);
339
+ });
340
+ const unsubClaims = participant.claims.onChange(() => {
341
+ setClaims(participant.claims.others);
342
+ });
343
+ return () => {
344
+ unsubPresence();
345
+ unsubClaims();
346
+ };
347
+ }, [participant, paused]);
348
+ return { participant, peers, claims, status, error };
349
+ }
350
+ /**
351
+ * Read-only presence: the OTHER participants currently visible to this
352
+ * connection, bridged to React. Unlike {@link useJoin}, this does
353
+ * NOT enter/leave a scope (no `update_subscription`, no warm-TTL churn) —
354
+ * it is a pure reader of the engine's already-flowing presence stream.
355
+ *
356
+ * Pass `scope` to narrow to the peers on that scope's sync group(s); omit
357
+ * it to get everyone on the engine's groups. Membership is driven entirely
358
+ * by the presence channel (set server-side on connect, independent of any
359
+ * cursor/collaboration traffic), so reading it never affects what the
360
+ * connection is subscribed to and can't deadlock against a gated channel.
361
+ *
362
+ * Use this to answer "is anyone else here?" — e.g. suppressing live-cursor
363
+ * broadcasts while alone — when some OTHER mount already owns the scope's
364
+ * read interest (scope `leave` is not reference-counted, so a second
365
+ * `useJoin` on the same scope would warm-drop the owner's
366
+ * subscription on unmount).
367
+ *
368
+ * ```ts
369
+ * const peers = usePeers({ reports: reportId });
370
+ * const alone = !peers.some((p) => p.participantKind === 'user');
371
+ * ```
372
+ */
373
+ export function usePeers(scope) {
374
+ const ctx = useContext(AbloInternalContext);
375
+ const engine = ctx?.engine ?? null;
376
+ // Resolve scope → groups through the schema (same idiom as useJoin).
377
+ // The stringified, sorted key is the stable effect dependency.
378
+ const scopeKey = JSON.stringify(resolveParticipantSyncGroups(scope, engine?.schema).sort());
379
+ const groups = useMemo(() => JSON.parse(scopeKey), [scopeKey]);
380
+ const [peers, setPeers] = useState(EMPTY_PRESENCE);
381
+ useEffect(() => {
382
+ if (!engine) {
383
+ setPeers(EMPTY_PRESENCE);
384
+ return;
385
+ }
386
+ const presence = engine.presence;
387
+ const compute = () => groups.length === 0
388
+ ? presence.others
389
+ : presence.others.filter((p) => p.syncGroups.some((g) => groups.includes(g)));
390
+ // Plain useState + onChange — presence changes on join/leave/activity
391
+ // only (never on cursor traffic, a separate channel), so this fires
392
+ // rarely; a frame of stale presence is harmless (same rationale as
393
+ // useJoin's peers bridge).
394
+ setPeers(compute());
395
+ return presence.onChange(() => { setPeers(compute()); });
396
+ }, [engine, scopeKey]);
397
+ return peers;
398
+ }
399
+ // ── Escape-hatches: raw engine/store access ──────────────────────────
400
+ /**
401
+ * Returns the raw `SyncEngine` proxy. Typically you want the typed
402
+ * hooks (`useQuery`, `useOne`, `useMutate`) — this is for rare cases
403
+ * where you need direct access (e.g., `sync.tasks.onChange(cb)`).
404
+ *
405
+ * The generic parameter narrows the return type to your schema's
406
+ * model record so call sites get typed `sync.tasks.findMany()` /
407
+ * `sync.sections.create(...)` without a cast at the call site:
408
+ *
409
+ * ```ts
410
+ * const sync = useSync<(typeof schema)['models']>();
411
+ * ```
412
+ *
413
+ * The runtime value is the exact engine the provider constructed;
414
+ * the generic just widens the compile-time type.
415
+ */
416
+ export function useSync() {
417
+ const ctx = useContext(AbloInternalContext);
418
+ if (!ctx) {
419
+ throw new AbloValidationError('useSync: no <AbloProvider> mounted above this component.', { code: 'no_ablo_provider' });
420
+ }
421
+ if (!ctx.engine) {
422
+ throw new AbloValidationError('useSync: the sync engine has not yet initialized. Wrap your ' +
423
+ 'consumer in <ClientSideSuspense> or guard on useSyncStatus().', { code: 'sync_not_ready' });
424
+ }
425
+ return rebindProviderEngine(ctx.engine);
426
+ }
427
+ function rebindProviderEngine(engine) {
428
+ return engine;
429
+ }
430
+ /**
431
+ * Returns the underlying `SyncStoreContract` (the BaseSyncedStore).
432
+ * Most consumers should prefer the typed hooks (`useQuery` etc.); this
433
+ * is for advanced cases like direct InstanceCache access or custom
434
+ * reactive bridges. Throws if the provider hasn't mounted the store
435
+ * yet — wrap consumers in `<ClientSideSuspense>` to gate correctly.
436
+ *
437
+ * The generic parameter lets consumers widen the return type to a
438
+ * concrete `BaseSyncedStore<...>` subclass if they track one:
439
+ *
440
+ * ```ts
441
+ * type AppStore = BaseSyncedStore<AppEvents, typeof schema>;
442
+ * const store = useSyncStore<AppStore>(); // no cast needed at call site
443
+ * ```
444
+ *
445
+ * The runtime value is always the concrete store the SDK constructed,
446
+ * so widening the type is safe. The bounded generic (`T extends
447
+ * SyncStoreContract`) keeps the widening honest.
448
+ */
449
+ export function useSyncStore() {
450
+ const sync = useContext(SyncContext);
451
+ if (!sync?.store) {
452
+ throw new AbloValidationError('useSyncStore: the sync engine has not yet initialized. Wrap ' +
453
+ 'consumers in <ClientSideSuspense> or guard on useSyncStatus().', { code: 'sync_not_ready' });
454
+ }
455
+ return sync.store;
456
+ }
@@ -0,0 +1,36 @@
1
+ import { type ReactNode } from 'react';
2
+ /**
3
+ * Nested bootstrap gate for a subtree. `<AbloProvider>` already ships
4
+ * its own built-in gate (via its `fallback` prop) that handles the
5
+ * common "wait for first bootstrap" case. Use `ClientSideSuspense`
6
+ * only when you need a SEPARATE gate inside an already-ready provider —
7
+ * for example, rendering app chrome immediately while gating a single
8
+ * heavy product surface on its own query resolving.
9
+ *
10
+ * Like the provider-level gate, this component latches open on the
11
+ * first `connected` / `reconnecting` / `disconnected` transition and
12
+ * stays open. Subsequent transient `connecting` states (hard reconnect
13
+ * after offline) do NOT re-show the fallback — the app has already
14
+ * rendered once and its own reconnect UI should take over.
15
+ *
16
+ * v0.3.x implementation is non-Suspense: reads `useSyncStatus()` and
17
+ * conditionally renders. v0.3.x+ will ship a
18
+ * the React suspense entry point where `useQuery` / `useOne`
19
+ * actually throw Promises; this component becomes a thin wrapper around
20
+ * React's real `<Suspense>` at that point.
21
+ *
22
+ * @example
23
+ * <AbloProvider fallback={<AppSkeleton />}>
24
+ * <AppChrome />
25
+ * <ClientSideSuspense fallback={<CanvasSkeleton />}>
26
+ * <HeavyCanvas />
27
+ * </ClientSideSuspense>
28
+ * </AbloProvider>
29
+ */
30
+ export interface ClientSideSuspenseProps {
31
+ /** What to render while the nested subtree is waiting for first bootstrap. */
32
+ fallback: ReactNode;
33
+ /** What to render once the subtree is cleared to render. */
34
+ children: ReactNode;
35
+ }
36
+ export declare function ClientSideSuspense({ fallback, children }: ClientSideSuspenseProps): import("react").JSX.Element;
@@ -0,0 +1,17 @@
1
+ 'use client';
2
+ import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
3
+ import { useEffect, useState } from 'react';
4
+ import { useSyncStatus } from './useSyncStatus.js';
5
+ export function ClientSideSuspense({ fallback, children }) {
6
+ const status = useSyncStatus();
7
+ const [everConnected, setEverConnected] = useState(false);
8
+ useEffect(() => {
9
+ if (status.name === 'connected' ||
10
+ status.name === 'reconnecting' ||
11
+ status.name === 'disconnected') {
12
+ setEverConnected(true);
13
+ }
14
+ }, [status.name]);
15
+ const showFallback = !everConnected && status.name === 'connecting';
16
+ return _jsx(_Fragment, { children: showFallback ? fallback : children });
17
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Neutral loading placeholder — the default value of `<AbloProvider>`'s
3
+ * `fallback` prop. Rendered during the first bootstrap pass when the
4
+ * consumer hasn't supplied their own skeleton.
5
+ *
6
+ * Design goals:
7
+ * - Zero design-system dependency. Inline styles only; no CSS file,
8
+ * no UI-lib imports, no Tailwind assumptions.
9
+ * - Theme-adaptive. Uses `currentColor` for the ring so the spinner
10
+ * inherits the text color from whichever ancestor defines it —
11
+ * works in light + dark contexts without a prop.
12
+ * - Self-centering. Flex-centered in a full-parent container so the
13
+ * common case (provider at the layout root) renders a spinner in
14
+ * the middle of the viewport. Consumers who need different
15
+ * positioning compose their own fallback and pass it explicitly.
16
+ * - Minimal bundle footprint. The whole component + keyframe is ~50
17
+ * bytes gzipped.
18
+ *
19
+ * Consumers wanting a branded loader should pass `fallback={<YourSkeleton />}`
20
+ * on `<AbloProvider>`. Consumers wanting NO visual during bootstrap
21
+ * pass `fallback={null}`. Consumers who want to skip the gate entirely
22
+ * pass `fallback="passthrough"`.
23
+ */
24
+ export declare function DefaultFallback(): import("react").JSX.Element;
@@ -0,0 +1,43 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ /**
4
+ * Neutral loading placeholder — the default value of `<AbloProvider>`'s
5
+ * `fallback` prop. Rendered during the first bootstrap pass when the
6
+ * consumer hasn't supplied their own skeleton.
7
+ *
8
+ * Design goals:
9
+ * - Zero design-system dependency. Inline styles only; no CSS file,
10
+ * no UI-lib imports, no Tailwind assumptions.
11
+ * - Theme-adaptive. Uses `currentColor` for the ring so the spinner
12
+ * inherits the text color from whichever ancestor defines it —
13
+ * works in light + dark contexts without a prop.
14
+ * - Self-centering. Flex-centered in a full-parent container so the
15
+ * common case (provider at the layout root) renders a spinner in
16
+ * the middle of the viewport. Consumers who need different
17
+ * positioning compose their own fallback and pass it explicitly.
18
+ * - Minimal bundle footprint. The whole component + keyframe is ~50
19
+ * bytes gzipped.
20
+ *
21
+ * Consumers wanting a branded loader should pass `fallback={<YourSkeleton />}`
22
+ * on `<AbloProvider>`. Consumers wanting NO visual during bootstrap
23
+ * pass `fallback={null}`. Consumers who want to skip the gate entirely
24
+ * pass `fallback="passthrough"`.
25
+ */
26
+ export function DefaultFallback() {
27
+ return (_jsxs("div", { role: "status", "aria-live": "polite", "aria-label": "Loading", style: {
28
+ display: 'flex',
29
+ alignItems: 'center',
30
+ justifyContent: 'center',
31
+ width: '100%',
32
+ minHeight: '100vh',
33
+ color: 'currentColor',
34
+ }, children: [_jsx("div", { style: {
35
+ width: 24,
36
+ height: 24,
37
+ border: '2px solid currentColor',
38
+ borderTopColor: 'transparent',
39
+ borderRadius: '50%',
40
+ opacity: 0.6,
41
+ animation: 'ablo-default-fallback-spin 0.8s linear infinite',
42
+ } }), _jsx("style", { children: `@keyframes ablo-default-fallback-spin { to { transform: rotate(360deg); } }` })] }));
43
+ }
@@ -0,0 +1,55 @@
1
+ import { type ReactNode } from 'react';
2
+ import type { Schema } from '@abloatai/transaction/schema/schema';
3
+ import type { SyncStoreContract } from '../local/storeContract.js';
4
+ export type { SyncStoreContract, LocalMutation, } from '../local/storeContract.js';
5
+ export interface SyncReactContext {
6
+ store: SyncStoreContract;
7
+ /** The organization id used as the default scope for reads and writes. */
8
+ organizationId: string;
9
+ /**
10
+ * An optional schema. When provided, hooks that take a model by name (such as
11
+ * `useQuery('tasks')`) read that model's metadata from this schema, so
12
+ * callers don't pass a schema at every call site. When omitted, those hooks
13
+ * require the schema as an argument instead.
14
+ *
15
+ * The field is loosely typed here because a single runtime context value is
16
+ * shared by every hook. Precise per-model types come from your `Register`
17
+ * module augmentation
18
+ * (`declare module '@abloatai/ablo' { interface Register { Schema: typeof schema } }`),
19
+ * not from this reference.
20
+ */
21
+ schema?: Schema;
22
+ }
23
+ export declare const SyncContext: import("react").Context<SyncReactContext | null>;
24
+ /**
25
+ * Reads the sync store context from inside a provider subtree, throwing a clear
26
+ * error when no provider is mounted above. `<AbloProvider>` supplies this
27
+ * context by rendering the internal {@link SyncProvider}; you wire
28
+ * `<AbloProvider client={ablo}>` rather than touching this directly.
29
+ */
30
+ export declare function useSyncContext(): SyncReactContext;
31
+ /**
32
+ * Props for SyncProvider.
33
+ */
34
+ export interface SyncProviderProps {
35
+ /** The sync store, which must implement {@link SyncStoreContract}. */
36
+ store: SyncStoreContract;
37
+ /** The organization id used as the default scope for reads and writes. */
38
+ organizationId: string;
39
+ /**
40
+ * An optional schema. Provide it to enable hooks that take a model by name
41
+ * (such as `useQuery('tasks')`); the model types also narrow through your
42
+ * `Register` augmentation. Omit it to pass the schema to those hooks directly
43
+ * instead.
44
+ */
45
+ schema?: Schema;
46
+ children?: ReactNode;
47
+ }
48
+ /**
49
+ * A low-level provider that places a built sync store on React context so the
50
+ * data hooks can reach it. This is an internal building block: it is not part
51
+ * of the package's public entry point. Reach for `<AbloProvider>` instead,
52
+ * which builds the store from your `Ablo({ schema, apiKey })` client and
53
+ * renders this provider underneath.
54
+ */
55
+ export declare function SyncProvider({ store, organizationId, schema, children, }: SyncProviderProps): import("react").FunctionComponentElement<import("react").ProviderProps<SyncReactContext | null>>;
@@ -0,0 +1,29 @@
1
+ 'use client';
2
+ import { createContext, createElement, useContext } from 'react';
3
+ import { AbloValidationError } from '@abloatai/transaction/errors';
4
+ export const SyncContext = createContext(null);
5
+ /**
6
+ * Reads the sync store context from inside a provider subtree, throwing a clear
7
+ * error when no provider is mounted above. `<AbloProvider>` supplies this
8
+ * context by rendering the internal {@link SyncProvider}; you wire
9
+ * `<AbloProvider client={ablo}>` rather than touching this directly.
10
+ */
11
+ export function useSyncContext() {
12
+ const ctx = useContext(SyncContext);
13
+ if (!ctx) {
14
+ throw new AbloValidationError('Sync hooks must be used within an <AbloProvider>.', {
15
+ code: 'sync_context_missing_provider',
16
+ });
17
+ }
18
+ return ctx;
19
+ }
20
+ /**
21
+ * A low-level provider that places a built sync store on React context so the
22
+ * data hooks can reach it. This is an internal building block: it is not part
23
+ * of the package's public entry point. Reach for `<AbloProvider>` instead,
24
+ * which builds the store from your `Ablo({ schema, apiKey })` client and
25
+ * renders this provider underneath.
26
+ */
27
+ export function SyncProvider({ store, organizationId, schema, children, }) {
28
+ return createElement(SyncContext.Provider, { value: { store, organizationId, schema } }, children);
29
+ }