@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,475 @@
1
+ /**
2
+ * Model is the base class for the sync engine's domain models. A model is a
3
+ * plain domain object: it holds data and business logic, tracks its own
4
+ * property changes, and validates itself, and it returns the changes to apply
5
+ * rather than applying them. It does not reach into stores or singletons and
6
+ * does not perform side effects such as saving or sending notifications;
7
+ * persistence and sync are driven by the store that owns the model.
8
+ */
9
+ /** Store interface — methods that Model subclasses can call on the store */
10
+ interface SyncStoreRef {
11
+ getByForeignKey<T extends Model>(modelName: string, foreignKey: string, id: string): T[];
12
+ retrieve<T extends Model>(modelClass: abstract new (...args: never[]) => T, id: string): T | undefined;
13
+ /** Lookup a model by ID alone. Returns the pool entry regardless of type. */
14
+ getById(id: string): Model | undefined;
15
+ /** Persist a model (upsert). */
16
+ save(model: Model): Promise<void>;
17
+ /** Delete a model. */
18
+ delete(model: Model): Promise<void>;
19
+ /** Archive a model (soft delete). */
20
+ archive(model: Model): Promise<void>;
21
+ /** Unarchive a previously archived model. */
22
+ unarchive(model: Model): Promise<void>;
23
+ }
24
+ /**
25
+ * Internal wire-hydration hint. Symbol-keyed and non-enumerable at the call
26
+ * site, so it can never enter persistence, JSON, a mutation payload, or a
27
+ * consumer's model fields.
28
+ */
29
+ export declare const DEFER_MODEL_OBSERVABILITY: unique symbol;
30
+ /** Model data type - allows any object with string keys.
31
+ * Mirrors `ModelData` exported from BaseSyncedStore — kept local to
32
+ * break the import cycle between Model and BaseSyncedStore. */
33
+ type ModelData = Record<string, unknown>;
34
+ /** Represents a property value change with old and new values */
35
+ export interface PropertyChange {
36
+ old: unknown;
37
+ new: unknown;
38
+ }
39
+ /** Validation rule function that returns error string or null if valid */
40
+ type ValidationRule = (value: unknown) => string | null;
41
+ /** Interface for objects that can be disposed */
42
+ interface Disposable {
43
+ dispose(): void;
44
+ }
45
+ /** Field change information for activity tracking */
46
+ interface FieldChange {
47
+ field: string;
48
+ oldValue: unknown;
49
+ newValue: unknown;
50
+ fieldType: string;
51
+ }
52
+ /**
53
+ * Validation error for model validation failures
54
+ */
55
+ export declare class ValidationError extends Error {
56
+ errors: string[];
57
+ constructor(errors: string[]);
58
+ }
59
+ /**
60
+ * Model changes for external processing
61
+ */
62
+ export interface ModelChanges {
63
+ type: 'create' | 'update' | 'delete' | 'archive' | 'unarchive';
64
+ modelName: string;
65
+ modelId: string;
66
+ changes?: Map<string, PropertyChange>;
67
+ timestamp: Date;
68
+ }
69
+ /**
70
+ * The abstract base class every domain model extends. It holds the model's id
71
+ * and timestamps, tracks in-place property changes for change detection and
72
+ * undo, and serializes itself, while leaving persistence and sync to the store
73
+ * that owns it.
74
+ */
75
+ export declare abstract class Model {
76
+ /** Static reference to active SyncedStore for reactive queries */
77
+ private static store;
78
+ /** Unique identifier - always permanent UUID */
79
+ id: string;
80
+ /** Client ID - always equals id, kept for compatibility */
81
+ clientId: string;
82
+ /** MobX observable properties storage */
83
+ _mobxProperties: ModelData;
84
+ /** Referenced models cache */
85
+ _referencedModels: Record<string, Model | null>;
86
+ /** Track property changes */
87
+ modifiedProperties: Map<string, PropertyChange>;
88
+ /** Track if this is a new model */
89
+ private _isNew;
90
+ /** Original data snapshot */
91
+ private _originalData?;
92
+ /** Sync status */
93
+ syncStatus: 'pending' | 'syncing' | 'synced';
94
+ /** Timestamps */
95
+ createdAt?: Date;
96
+ updatedAt?: Date;
97
+ archivedAt?: Date | null;
98
+ /** Validation rules */
99
+ protected validationRules: Record<string, ValidationRule[]>;
100
+ /** Lifecycle state */
101
+ private isDisposed;
102
+ private disposers;
103
+ /**
104
+ * Whether MobX field instrumentation has been installed. Wire hydration can
105
+ * deliberately defer this work until the cache hands the model to a
106
+ * consumer; optimistic/local models still install it in their constructor.
107
+ */
108
+ private _observabilityReady;
109
+ private _observabilityDeferred;
110
+ /**
111
+ * Track observed LazyReferenceCollections for GC prevention
112
+ * When any collection is being observed by React, the model should not be GC'd
113
+ * Following MobX best practice: https://mobx.js.org/lazy-observables.html
114
+ */
115
+ private _observedCollections;
116
+ constructor(data?: Partial<Model>);
117
+ /**
118
+ * Generate unique ID
119
+ */
120
+ static generateId(): string;
121
+ /**
122
+ * Set the active SyncedStore reference for reactive queries.
123
+ * Called once at engine initialization.
124
+ */
125
+ static setStore(store: SyncStoreRef): void;
126
+ /**
127
+ * Get the active SyncedStore reference for reactive queries.
128
+ *
129
+ * Returns `null` if no store has been registered yet (e.g. during
130
+ * bootstrap before the engine is ready). Subclasses should use this
131
+ * instead of reaching into the private static field via bracket
132
+ * notation — the generic parameter lets app-side Model subclasses
133
+ * narrow the return to their concrete store type.
134
+ *
135
+ * @example
136
+ * // In a Section model getter
137
+ * const store = Section.getStore();
138
+ * if (!store) return [];
139
+ * return store.getByForeignKey<Block>('Block', 'sectionId', this.id);
140
+ */
141
+ static getStore<T extends SyncStoreRef = SyncStoreRef>(): T | null;
142
+ /**
143
+ * Initialize MobX observability
144
+ */
145
+ makeObservable(): void;
146
+ /** Mark a schema model as intentionally cold until cache exposure. */
147
+ protected deferObservability(): void;
148
+ /**
149
+ * Activate a cold wire-hydrated model before it crosses a consumer-visible
150
+ * cache boundary. Idempotent, so ordinary eagerly observable models pay only
151
+ * the boolean check.
152
+ */
153
+ ensureObservable(): void;
154
+ /**
155
+ * Track property changes
156
+ */
157
+ propertyChanged(propertyName: string, oldValue: unknown, newValue: unknown): void;
158
+ /**
159
+ * Get changes as object
160
+ */
161
+ getChanges(): ModelData;
162
+ /**
163
+ * Check if model has changes
164
+ */
165
+ get hasChanges(): boolean;
166
+ /**
167
+ * Mark model as persisted (not new)
168
+ */
169
+ markAsPersisted(): void;
170
+ /**
171
+ * Check if this is a new model
172
+ */
173
+ isNew(): boolean;
174
+ /**
175
+ * Return a read-only view of the snapshot taken at {@link markAsPersisted}
176
+ * or at load time. The undo machinery uses it to recover a field's pre-edit
177
+ * value when the field was written without first being tracked in
178
+ * `modifiedProperties`. The returned object is the live snapshot, so callers
179
+ * must not mutate it.
180
+ *
181
+ * This per-instance baseline is needed because application code can edit a
182
+ * model in two ways that coexist: a direct property write
183
+ * (`section.title = 'foo'`) and a recorded mutation. A design in which every
184
+ * write went through a single recorded path would not need it, since the
185
+ * last acknowledged state would already be the authoritative baseline.
186
+ */
187
+ getOriginalSnapshot(): Readonly<ModelData> | undefined;
188
+ /**
189
+ * Clear tracked changes
190
+ */
191
+ clearChanges(): void;
192
+ /**
193
+ * Capture a before-image for `keys` — the single source of truth for the
194
+ * "previous value" that undo inverses are built from. Both undo paths call
195
+ * this so they can never drift: the stream path
196
+ * (`MutationQueue.extractPreviousData`) and the manual-record path
197
+ * (`RecordingMutation.snapshotFields`).
198
+ *
199
+ * Resolution order per key:
200
+ * 1. `modifiedProperties.get(key).old` — first-old-wins pre-session
201
+ * baseline, set whenever the field was mutated in place before commit.
202
+ * 2. `getOriginalSnapshot()[key]` — the last loaded/acked row, the correct
203
+ * before-image for a key written without a prior in-place mutation
204
+ * (e.g. a `precomputedChanges` write).
205
+ * 3. `fallbackToLive` only — the current live value. The manual-record path
206
+ * wants this last resort; the stream path deliberately omits unresolved
207
+ * keys so `buildUndoOps` drops an un-revertible inverse rather than
208
+ * inventing one. The flag is the one intentional difference between the
209
+ * two callers — do not collapse it.
210
+ *
211
+ * `id` is always skipped. Values are read out per-key, so the
212
+ * `getOriginalSnapshot()` "callers must not mutate" contract is preserved.
213
+ *
214
+ * Invariant this relies on: a given undo scope is either stream-recorded
215
+ * (`recordFromStream: true`) or manual (`useMutators({ undoScope })`), never
216
+ * both — otherwise a write would be captured twice. No surface sets both.
217
+ */
218
+ capturePreviousValues(keys: Iterable<string>, opts?: {
219
+ fallbackToLive?: boolean;
220
+ }): ModelData;
221
+ /**
222
+ * Drop the `modifiedProperties` entries for `keys` — re-baselines a field
223
+ * after its `.old` has been frozen into a committed transaction, so the next
224
+ * write to the same field starts from this commit's result rather than the
225
+ * stale pre-session `.old` that {@link propertyChanged}'s first-old-wins
226
+ * policy preserves. Safe because the committed transaction owns its own
227
+ * frozen `data`/`previousData`; neither re-reads `modifiedProperties`. `id`
228
+ * is never consumed. With no `keys`, consumes every tracked field.
229
+ */
230
+ consumeModifiedFields(keys?: Iterable<string>): void;
231
+ /**
232
+ * Validate model
233
+ */
234
+ validate(): string[];
235
+ /**
236
+ * Override for custom validation
237
+ */
238
+ protected customValidate(): string[];
239
+ /**
240
+ * Add validation rule
241
+ */
242
+ protected addValidationRule(propName: string, rule: ValidationRule): void;
243
+ /**
244
+ * Prepare save operation
245
+ * Returns the changes to be saved without side effects
246
+ */
247
+ prepareSave(): ModelChanges | null;
248
+ /**
249
+ * Prepare delete operation
250
+ */
251
+ prepareDelete(): ModelChanges;
252
+ /**
253
+ * Prepare archive operation
254
+ */
255
+ prepareArchive(): ModelChanges;
256
+ /**
257
+ * Prepare unarchive operation
258
+ */
259
+ prepareUnarchive(): ModelChanges;
260
+ /**
261
+ * Safely assign each field of `data` onto this instance, skipping `id`,
262
+ * unknown keys, MobX computed accessors, and getter-only (read-only)
263
+ * properties, and coercing date fields. Shared by `updateFromData`
264
+ * (hydration) and `applyChanges` (local user update).
265
+ *
266
+ * Change tracking is explicit: for every field actually
267
+ * written, `onWrite(key, oldValue, newValue)` is invoked with the value
268
+ * captured immediately before assignment. `applyChanges` passes a hook
269
+ * that records the change in `modifiedProperties`; `updateFromData`
270
+ * passes none (hydration must not generate outbound mutations).
271
+ *
272
+ * This is not the ONLY tracking path. `mobxSetup`'s `observe()` bridge is
273
+ * live and forwards a DIRECT assignment (`layer.position = next`) to
274
+ * `propertyChanged` as well — product code writes model fields directly in
275
+ * plenty of places (keyboard nudge, formatting, AI tools), and those writes
276
+ * have to reach the server and the undo stream too. The two paths compose:
277
+ * a direct write establishes the first-old-wins baseline, and a later
278
+ * `applyChanges` carrying the value the model already holds is a no-op that
279
+ * leaves that baseline intact.
280
+ */
281
+ private assignFieldsFromData;
282
+ /**
283
+ * Update from raw data (hydration)
284
+ *
285
+ * Used for inbound server deltas and pool upserts. Change tracking is
286
+ * deliberately suppressed: hydration writes must not land in
287
+ * `modifiedProperties`, otherwise applying a server delta would queue a
288
+ * brand-new outbound mutation and the record would echo forever. For a
289
+ * local user edit, use `applyChanges` instead.
290
+ *
291
+ * Suppression takes two forms and BOTH are load-bearing: we pass no
292
+ * `onWrite` hook, and we clear/restore `modifiedProperties` around the
293
+ * assignment. The second is what catches `mobxSetup`'s `observe()` bridge,
294
+ * which fires on the assignment itself and would otherwise record an
295
+ * inbound delta as a local edit — queueing an outbound mutation that echoes
296
+ * forever, and putting a collaborator's change on your undo stack. Do not
297
+ * remove it while that bridge exists (`mobxSetup.M1`).
298
+ */
299
+ updateFromData(data: ModelData): void;
300
+ /**
301
+ * Apply a local, user-initiated update from a data object — the write
302
+ * path for `proxy.update({ id, data })`, which is the one and only way
303
+ * application code mutates synced fields.
304
+ *
305
+ * Unlike `updateFromData` (hydration, untracked), this records every
306
+ * written field in `modifiedProperties` via `propertyChanged`, so
307
+ * `getChanges()` and the transaction queue send the edited fields to the
308
+ * server and the undo system gets a correct pre-write baseline. Recording
309
+ * is explicit here, through the `onWrite` hook, and does not rely on any
310
+ * MobX `observe()` side channel.
311
+ *
312
+ * `_originalData` is intentionally not reset here: it stays as the
313
+ * last-persisted baseline until `clearChanges()` runs on sync-ack.
314
+ */
315
+ applyChanges(data: ModelData): void;
316
+ /**
317
+ * Serialize to JSON
318
+ * This method should not trigger MobX reactions since it's used for serialization
319
+ * Returns Record<string, any> to allow subclass specialization with more specific return types
320
+ */
321
+ toJSON(): Record<string, any>;
322
+ /**
323
+ * Clone this model
324
+ */
325
+ clone(): this;
326
+ getModelName(): string;
327
+ /**
328
+ * Read a field value by name. Runtime-safe dynamic field access —
329
+ * schema-generated models store all declared fields as instance properties.
330
+ * Use this for generic code (sort comparators, filter predicates that work
331
+ * across model types) that reads fields by name string.
332
+ */
333
+ getField(name: string): unknown;
334
+ /**
335
+ * Check equality
336
+ */
337
+ equals(other: Model): boolean;
338
+ /**
339
+ * String representation
340
+ */
341
+ toString(): string;
342
+ /**
343
+ * Register a LazyReferenceCollection as being observed
344
+ * Called by LazyReferenceCollection when onBecomeObserved fires
345
+ */
346
+ _registerObservedCollection(collection: Disposable): void;
347
+ /**
348
+ * Unregister a LazyReferenceCollection that's no longer observed
349
+ * Called by LazyReferenceCollection when onBecomeUnobserved fires
350
+ */
351
+ _unregisterObservedCollection(collection: Disposable): void;
352
+ /**
353
+ * Check if any collection on this model is currently being observed by React
354
+ * Used by InstanceCache GC to prevent disposing models in active use
355
+ */
356
+ hasObservedCollections(): boolean;
357
+ /**
358
+ * Get count of observed collections (for debugging)
359
+ */
360
+ get observedCollectionCount(): number;
361
+ /**
362
+ * Dispose model
363
+ */
364
+ dispose(): void;
365
+ /**
366
+ * Check if disposed
367
+ */
368
+ get disposed(): boolean;
369
+ /**
370
+ * Lifecycle hooks - override in subclasses
371
+ */
372
+ protected didUpdate(): void;
373
+ protected willDelete(): void;
374
+ /**
375
+ * Capture snapshot for change detection
376
+ */
377
+ protected captureSnapshot(): ModelData;
378
+ /**
379
+ * A fresh, plain row snapshot that READS every declared field through its
380
+ * MobX observable getter. This is the reactive read surface for
381
+ * `useReactive`/`useAblo`, and it relies on two MobX facts:
382
+ *
383
+ * 1. MobX tracks property *access*, not values — so reading each field here,
384
+ * inside the caller's tracked function, SUBSCRIBES the reaction to that
385
+ * field. A bare `return model` (the previous `modelAsRow`) dereferences
386
+ * nothing, so an in-place delta update fires no reaction and the UI never
387
+ * re-renders. (https://mobx.js.org/understanding-reactivity.html)
388
+ * 2. The returned object is a NEW identity each call, so the hook's equality
389
+ * check detects the change — the same mutated instance would compare equal
390
+ * and suppress the re-render even after tracking fired.
391
+ *
392
+ * Unlike `toJSON()`, values keep their runtime types (a `Date` stays a `Date`,
393
+ * a json field stays its parsed object) and wire-noise keys
394
+ * (`__class`/`clientId`/`syncStatus`) are omitted — this is exactly the row
395
+ * the schema's `T` describes. Computed relations (`referenceModel`/
396
+ * `referenceCollection`) and ephemeral fields are skipped, matching `toJSON`'s
397
+ * row projection; they're lazy/recursive and not part of the row's data.
398
+ *
399
+ * Schema-derived getters (`computed:` entries and `${field}Json` getters) ARE
400
+ * materialized, as non-enumerable own values. The schema's inferred row type
401
+ * includes them, so omitting them would make every snapshot read of a computed
402
+ * silently `undefined` — a type-level lie. They're evaluated here, inside the
403
+ * caller's tracked function, so the reaction subscribes to whatever fields the
404
+ * getter reads. Non-enumerable keeps write-path parity with model instances:
405
+ * an instance's getters sit on the prototype and never enter `{...model}`
406
+ * spreads or `JSON.stringify`, and materialized values must not either — a
407
+ * spread-into-update would otherwise send computed keys to the server.
408
+ */
409
+ toReactiveSnapshot<T = ModelData>(): T;
410
+ /**
411
+ * Names of schema-derived getters — `computed:` entries and `${field}Json`
412
+ * getters — that {@link toReactiveSnapshot} materializes onto snapshots.
413
+ * The dynamic model class built by `registerModelsFromSchema` overrides this;
414
+ * hand-written Model subclasses default to none.
415
+ */
416
+ getDerivedGetterNames(): readonly string[];
417
+ /**
418
+ * Get field changes for activity tracking
419
+ */
420
+ getFieldChanges(): FieldChange[];
421
+ private getFieldType;
422
+ /**
423
+ * Create model from JSON
424
+ */
425
+ static fromJSON(data: ModelData & {
426
+ __typename?: string;
427
+ __class?: string;
428
+ modelName?: string;
429
+ }): Model;
430
+ /**
431
+ * Get sync status
432
+ */
433
+ getSyncStatus(): 'pending' | 'syncing' | 'synced';
434
+ /**
435
+ * Mark model as synced
436
+ */
437
+ markAsSynced(): void;
438
+ /**
439
+ * Mark model as pending sync
440
+ */
441
+ markAsPending(): void;
442
+ }
443
+ /**
444
+ * Project a dynamic-class `Model` instance to the schema row shape `T`.
445
+ *
446
+ * The runtime invariant: `createDynamicModelClass(...)` attaches every
447
+ * field of `T` directly onto the Model prototype/instance via
448
+ * `Object.defineProperty` and the M1 observable bridge, so a Model
449
+ * instance structurally satisfies `T` at runtime. The static type
450
+ * system can't see this because `T` is a free generic — there's no
451
+ * common ancestor between `Model` (base class) and the schema row
452
+ * interface produced by `defineSchema`.
453
+ *
454
+ * This is a typed boundary, not a bypass: every call site is the
455
+ * dynamic-class duality where Model-with-extras-and-T-fields is being
456
+ * returned to a consumer that only sees `T`. Concentrating the cast
457
+ * here means there's one place to look when the boundary changes.
458
+ */
459
+ export declare function modelAsRow<T>(model: Model): T;
460
+ /**
461
+ * Inverse of `modelAsRow`: accept a row-shaped value (schema-derived
462
+ * `T` with at minimum an `id`) and surface it as a `Model`. Used by
463
+ * `BaseSyncedStore.save / delete / archive / unarchive` so consumers
464
+ * can pass either a typed schema row or a Model instance and the
465
+ * SDK's persistence path sees a uniform Model surface.
466
+ *
467
+ * Same runtime invariant as `modelAsRow`: dynamic-class instances
468
+ * carry both the row fields and the Model methods on the same object
469
+ * — one structural identity, two static views. The helper does no
470
+ * runtime conversion (no allocation, no copy) — it's a pure type cast.
471
+ */
472
+ export declare function rowAsModel<T extends {
473
+ id: string;
474
+ }>(entity: T): Model;
475
+ export {};