@abloatai/ablo 0.34.1 → 0.35.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 (483) hide show
  1. package/AGENTS.md +2 -1
  2. package/CHANGELOG.md +674 -5
  3. package/README.md +39 -22
  4. package/dist/BaseSyncedStore.d.ts +152 -44
  5. package/dist/BaseSyncedStore.js +300 -184
  6. package/dist/Database.d.ts +9 -24
  7. package/dist/Database.js +37 -22
  8. package/dist/InstanceCache.d.ts +25 -4
  9. package/dist/InstanceCache.js +48 -15
  10. package/dist/LazyReferenceCollection.d.ts +3 -3
  11. package/dist/LazyReferenceCollection.js +4 -4
  12. package/dist/Model.d.ts +6 -6
  13. package/dist/Model.js +10 -10
  14. package/dist/ModelRegistry.d.ts +4 -4
  15. package/dist/ModelRegistry.js +3 -3
  16. package/dist/{SyncEngineContext.d.ts → RuntimeContext.d.ts} +20 -13
  17. package/dist/{SyncEngineContext.js → RuntimeContext.js} +11 -12
  18. package/dist/SyncClient.d.ts +42 -32
  19. package/dist/SyncClient.js +166 -110
  20. package/dist/ai-sdk/coordinatedTool.d.ts +2 -2
  21. package/dist/ai-sdk/coordinatedTool.js +1 -1
  22. package/dist/ai-sdk/coordinationContext.d.ts +2 -2
  23. package/dist/ai-sdk/coordinationContext.js +1 -1
  24. package/dist/ai-sdk/wrap.d.ts +3 -3
  25. package/dist/ai-sdk/wrap.js +2 -2
  26. package/dist/auth/index.d.ts +1 -156
  27. package/dist/auth/index.js +8 -301
  28. package/dist/cli.cjs +3344 -1073
  29. package/dist/client/Ablo.d.ts +42 -287
  30. package/dist/client/Ablo.js +118 -963
  31. package/dist/client/abloClient.d.ts +309 -0
  32. package/dist/client/abloClient.js +13 -0
  33. package/dist/client/clientPrelude.d.ts +52 -0
  34. package/dist/client/clientPrelude.js +60 -0
  35. package/dist/client/consoleLogger.d.ts +2 -2
  36. package/dist/client/coreClient.d.ts +60 -0
  37. package/dist/client/coreClient.js +118 -0
  38. package/dist/client/createInternalComponents.d.ts +4 -4
  39. package/dist/client/createInternalComponents.js +9 -8
  40. package/dist/client/createModelProxy.d.ts +78 -373
  41. package/dist/client/createModelProxy.js +114 -86
  42. package/dist/client/humans.d.ts +48 -0
  43. package/dist/client/humans.js +52 -0
  44. package/dist/client/modelRegistration.d.ts +1 -1
  45. package/dist/client/modelRegistration.js +9 -9
  46. package/dist/client/options.d.ts +73 -17
  47. package/dist/client/reactiveEngine.d.ts +48 -0
  48. package/dist/client/reactiveEngine.js +910 -0
  49. package/dist/client/resourceTypes.d.ts +9 -250
  50. package/dist/client/resourceTypes.js +8 -5
  51. package/dist/client/schemaConfig.d.ts +4 -4
  52. package/dist/client/schemaConfig.js +6 -2
  53. package/dist/client/validateAbloOptions.d.ts +3 -2
  54. package/dist/client/validateAbloOptions.js +1 -1
  55. package/dist/client/wsMutationExecutor.d.ts +3 -3
  56. package/dist/client/wsMutationExecutor.js +3 -3
  57. package/dist/context.d.ts +9 -9
  58. package/dist/context.js +10 -9
  59. package/dist/coordination/ClaimLog.d.ts +26 -0
  60. package/dist/coordination/ClaimLog.js +32 -0
  61. package/dist/coordination/index.d.ts +1 -15
  62. package/dist/coordination/index.js +8 -31
  63. package/dist/core/DatabaseManager.js +1 -1
  64. package/dist/core/QueryView.d.ts +1 -1
  65. package/dist/core/QueryView.js +1 -1
  66. package/dist/core/StoreManager.d.ts +4 -23
  67. package/dist/core/StoreManager.js +5 -55
  68. package/dist/core/index.d.ts +2 -2
  69. package/dist/core/index.js +2 -2
  70. package/dist/core/storeContract.d.ts +2 -2
  71. package/dist/docs/catalog.d.ts +72 -0
  72. package/dist/docs/catalog.js +227 -0
  73. package/dist/docs/index.d.ts +10 -0
  74. package/dist/docs/index.js +10 -0
  75. package/dist/environment.d.ts +1 -40
  76. package/dist/environment.js +8 -37
  77. package/dist/index.d.ts +40 -34
  78. package/dist/index.js +26 -20
  79. package/dist/interfaces/index.d.ts +44 -134
  80. package/dist/keys/index.d.ts +1 -77
  81. package/dist/keys/index.js +8 -190
  82. package/dist/mutators/{RecordingTransaction.d.ts → RecordingMutation.d.ts} +4 -4
  83. package/dist/mutators/{RecordingTransaction.js → RecordingMutation.js} +2 -2
  84. package/dist/mutators/Transaction.d.ts +1 -1
  85. package/dist/mutators/Transaction.js +1 -1
  86. package/dist/mutators/UndoManager.d.ts +6 -6
  87. package/dist/mutators/UndoManager.js +5 -5
  88. package/dist/mutators/defineMutators.d.ts +3 -3
  89. package/dist/mutators/defineMutators.js +1 -1
  90. package/dist/mutators/inverseOp.js +2 -2
  91. package/dist/mutators/mutateActions.d.ts +3 -3
  92. package/dist/mutators/mutateActions.js +1 -1
  93. package/dist/mutators/readerActions.d.ts +1 -1
  94. package/dist/mutators/undoApply.d.ts +1 -1
  95. package/dist/mutators/undoApply.js +1 -1
  96. package/dist/policy/index.d.ts +2 -2
  97. package/dist/policy/index.js +1 -1
  98. package/dist/query/client.d.ts +2 -2
  99. package/dist/query/client.js +4 -4
  100. package/dist/query/types.d.ts +6 -41
  101. package/dist/query/types.js +2 -2
  102. package/dist/react/AbloProvider.d.ts +6 -8
  103. package/dist/react/AbloProvider.js +5 -7
  104. package/dist/react/context.d.ts +1 -1
  105. package/dist/react/context.js +1 -1
  106. package/dist/react/index.d.ts +5 -5
  107. package/dist/react/index.js +3 -3
  108. package/dist/react/internalContext.d.ts +1 -1
  109. package/dist/react/useAblo.d.ts +3 -3
  110. package/dist/react/useAblo.js +1 -1
  111. package/dist/react/useCurrentUserId.js +1 -1
  112. package/dist/react/useErrorListener.js +1 -1
  113. package/dist/react/useMutationFailureListener.d.ts +2 -2
  114. package/dist/react/useMutationFailureListener.js +1 -1
  115. package/dist/react/useMutators.d.ts +3 -3
  116. package/dist/react/useMutators.js +3 -3
  117. package/dist/react/useUndoScope.d.ts +5 -5
  118. package/dist/react/useUndoScope.js +1 -1
  119. package/dist/schema/coordination.d.ts +69 -10
  120. package/dist/schema/coordination.js +86 -9
  121. package/dist/schema/ddl.js +2 -2
  122. package/dist/schema/diff.d.ts +1 -1
  123. package/dist/schema/generate.js +1 -1
  124. package/dist/schema/index.d.ts +10 -10
  125. package/dist/schema/index.js +18 -18
  126. package/dist/schema/queries.d.ts +27 -27
  127. package/dist/schema/queries.js +23 -23
  128. package/dist/schema/select.d.ts +3 -3
  129. package/dist/schema/select.js +3 -3
  130. package/dist/schema/serialize.d.ts +15 -6
  131. package/dist/schema/serialize.js +17 -3
  132. package/dist/schema/sugar.d.ts +6 -7
  133. package/dist/schema/sugar.js +9 -12
  134. package/dist/schema/syncDeltaRow.d.ts +4 -152
  135. package/dist/schema/syncDeltaRow.js +4 -105
  136. package/dist/server/adapter.d.ts +18 -1
  137. package/dist/server/commit.d.ts +10 -16
  138. package/dist/server/index.d.ts +1 -1
  139. package/dist/server/index.js +1 -1
  140. package/dist/server/readConfig.d.ts +1 -1
  141. package/dist/source/adapters/drizzle.d.ts +1 -1
  142. package/dist/source/adapters/drizzle.js +2 -2
  143. package/dist/source/adapters/kysely.d.ts +1 -1
  144. package/dist/source/adapters/kysely.js +1 -1
  145. package/dist/source/adapters/kyselyMutationCore.d.ts +1 -1
  146. package/dist/source/adapters/kyselyMutationCore.js +2 -2
  147. package/dist/source/adapters/memory.js +1 -1
  148. package/dist/source/adapters/prisma.d.ts +8 -3
  149. package/dist/source/adapters/prisma.js +1 -1
  150. package/dist/source/connector.js +1 -1
  151. package/dist/source/connectorProtocol.d.ts +2 -8
  152. package/dist/source/connectorProtocol.js +3 -2
  153. package/dist/source/contract.d.ts +29 -17
  154. package/dist/source/contract.js +27 -22
  155. package/dist/source/factory.d.ts +1 -1
  156. package/dist/source/footprint.d.ts +111 -0
  157. package/dist/source/footprint.js +0 -0
  158. package/dist/source/idempotency.js +2 -2
  159. package/dist/source/index.d.ts +1 -0
  160. package/dist/source/index.js +3 -0
  161. package/dist/source/next.d.ts +1 -1
  162. package/dist/source/signing.d.ts +9 -2
  163. package/dist/source/signing.js +4 -1
  164. package/dist/source/types.d.ts +6 -4
  165. package/dist/source/types.js +1 -1
  166. package/dist/stores/ObjectStore.d.ts +1 -1
  167. package/dist/stores/SyncActionStore.d.ts +1 -1
  168. package/dist/stores/SyncActionStore.js +2 -10
  169. package/dist/stores/syncAction.d.ts +26 -0
  170. package/dist/stores/syncAction.js +16 -0
  171. package/dist/surface.d.ts +3 -3
  172. package/dist/surface.js +6 -4
  173. package/dist/sync/BootstrapFetcher.d.ts +123 -6
  174. package/dist/sync/BootstrapFetcher.js +492 -66
  175. package/dist/sync/ConnectionManager.d.ts +6 -198
  176. package/dist/sync/ConnectionManager.js +6 -677
  177. package/dist/sync/OnDemandLoader.d.ts +2 -2
  178. package/dist/sync/OnDemandLoader.js +60 -21
  179. package/dist/sync/SubscriptionManager.d.ts +13 -2
  180. package/dist/sync/SubscriptionManager.js +23 -5
  181. package/dist/sync/SyncWebSocket.d.ts +27 -510
  182. package/dist/sync/SyncWebSocket.js +76 -954
  183. package/dist/sync/awaitClaimGrant.d.ts +4 -44
  184. package/dist/sync/awaitClaimGrant.js +4 -109
  185. package/dist/sync/commitFrames.d.ts +6 -40
  186. package/dist/sync/commitFrames.js +6 -97
  187. package/dist/sync/contextPorts.d.ts +18 -0
  188. package/dist/sync/contextPorts.js +31 -0
  189. package/dist/sync/createClaimStream.d.ts +5 -49
  190. package/dist/sync/createClaimStream.js +5 -469
  191. package/dist/sync/createPresenceStream.d.ts +26 -4
  192. package/dist/sync/createPresenceStream.js +28 -20
  193. package/dist/sync/createSnapshot.d.ts +2 -2
  194. package/dist/sync/createSnapshot.js +1 -1
  195. package/dist/sync/credentialLifecycle.d.ts +5 -173
  196. package/dist/sync/credentialLifecycle.js +5 -320
  197. package/dist/sync/deltaPipeline.d.ts +1 -1
  198. package/dist/sync/participants.d.ts +5 -4
  199. package/dist/sync/participants.js +29 -22
  200. package/dist/sync/schemaDrift.d.ts +55 -0
  201. package/dist/sync/schemaDrift.js +53 -0
  202. package/dist/sync/schemas.d.ts +21 -32
  203. package/dist/sync/schemas.js +26 -17
  204. package/dist/sync/syncPlan.d.ts +3 -3
  205. package/dist/sync/wsFrameHandlers.d.ts +6 -114
  206. package/dist/sync/wsFrameHandlers.js +6 -392
  207. package/dist/testing/fixtures/bootstrap.d.ts +1 -1
  208. package/dist/testing/fixtures/deltas.d.ts +1 -1
  209. package/dist/testing/fixtures/httpResponses.d.ts +70 -0
  210. package/dist/testing/fixtures/httpResponses.js +90 -0
  211. package/dist/testing/fixtures/models.js +1 -1
  212. package/dist/testing/helpers/wait.js +1 -1
  213. package/dist/testing/mocks/MockMutationExecutor.d.ts +2 -2
  214. package/dist/testing/mocks/MockMutationExecutor.js +8 -14
  215. package/dist/testing/mocks/MockSyncContext.d.ts +11 -11
  216. package/dist/testing/mocks/MockSyncContext.js +10 -9
  217. package/dist/testing/mocks/MockSyncStore.js +1 -1
  218. package/dist/testing/mocks/MockWebSocket.d.ts +2 -2
  219. package/dist/transaction/ablo.d.ts +88 -0
  220. package/dist/transaction/ablo.js +33 -0
  221. package/dist/{client/auth.d.ts → transaction/auth/apiKey.d.ts} +43 -8
  222. package/dist/{client/auth.js → transaction/auth/apiKey.js} +19 -0
  223. package/dist/transaction/auth/bootstrapScope.d.ts +15 -0
  224. package/dist/transaction/auth/bootstrapScope.js +1 -0
  225. package/dist/transaction/auth/capability.d.ts +177 -0
  226. package/dist/transaction/auth/capability.js +199 -0
  227. package/dist/{auth → transaction/auth}/credentialSource.d.ts +8 -1
  228. package/dist/{client → transaction/auth}/identity.d.ts +8 -7
  229. package/dist/{client → transaction/auth}/identity.js +1 -1
  230. package/dist/transaction/auth/index.d.ts +162 -0
  231. package/dist/transaction/auth/index.js +304 -0
  232. package/dist/{auth → transaction/auth}/schemas.d.ts +1 -1
  233. package/dist/{auth → transaction/auth}/schemas.js +13 -13
  234. package/dist/{client → transaction/auth}/sessionMint.d.ts +8 -8
  235. package/dist/{client → transaction/auth}/sessionMint.js +4 -7
  236. package/dist/transaction/coordination/awaitClaimGrant.d.ts +49 -0
  237. package/dist/transaction/coordination/awaitClaimGrant.js +112 -0
  238. package/dist/transaction/coordination/claimMeta.d.ts +49 -0
  239. package/dist/transaction/coordination/claimMeta.js +52 -0
  240. package/dist/transaction/coordination/createClaimStream.d.ts +64 -0
  241. package/dist/transaction/coordination/createClaimStream.js +475 -0
  242. package/dist/transaction/coordination/events.d.ts +74 -0
  243. package/dist/transaction/coordination/events.js +7 -0
  244. package/dist/transaction/coordination/index.d.ts +19 -0
  245. package/dist/transaction/coordination/index.js +44 -0
  246. package/dist/transaction/coordination/locator.d.ts +83 -0
  247. package/dist/transaction/coordination/locator.js +82 -0
  248. package/dist/transaction/coordination/schema.d.ts +1473 -0
  249. package/dist/{coordination → transaction/coordination}/schema.js +490 -55
  250. package/dist/transaction/coordination/targetConflict.d.ts +2 -0
  251. package/dist/transaction/coordination/targetConflict.js +103 -0
  252. package/dist/{coordination → transaction/coordination}/trace.d.ts +7 -18
  253. package/dist/{coordination → transaction/coordination}/trace.js +18 -25
  254. package/dist/transaction/durableWrites.d.ts +62 -0
  255. package/dist/{client → transaction}/durableWrites.js +28 -3
  256. package/dist/transaction/environment.d.ts +105 -0
  257. package/dist/transaction/environment.js +108 -0
  258. package/dist/{errorCodes.d.ts → transaction/errorCodes.d.ts} +11 -11
  259. package/dist/{errorCodes.js → transaction/errorCodes.js} +35 -12
  260. package/dist/{errors.d.ts → transaction/errors.d.ts} +37 -13
  261. package/dist/{errors.js → transaction/errors.js} +85 -16
  262. package/dist/transaction/index.d.ts +20 -0
  263. package/dist/transaction/index.js +20 -0
  264. package/dist/transaction/keys/index.d.ts +87 -0
  265. package/dist/transaction/keys/index.js +207 -0
  266. package/dist/transaction/log/syncDeltaRow.d.ts +158 -0
  267. package/dist/transaction/log/syncDeltaRow.js +95 -0
  268. package/dist/{sync/syncPosition.d.ts → transaction/logPosition.d.ts} +22 -8
  269. package/dist/{sync/syncPosition.js → transaction/logPosition.js} +15 -6
  270. package/dist/transaction/logger.d.ts +16 -0
  271. package/dist/transaction/logger.js +7 -0
  272. package/dist/transaction/observability.d.ts +53 -0
  273. package/dist/transaction/observability.js +19 -0
  274. package/dist/transaction/plugin.d.ts +192 -0
  275. package/dist/transaction/plugin.js +87 -0
  276. package/dist/{policy → transaction/policy}/types.d.ts +3 -3
  277. package/dist/{policy → transaction/policy}/types.js +2 -0
  278. package/dist/transaction/resources/httpResources.d.ts +266 -0
  279. package/dist/transaction/resources/httpResources.js +7 -0
  280. package/dist/transaction/resources/modelOperations.d.ts +319 -0
  281. package/dist/transaction/resources/modelOperations.js +12 -0
  282. package/dist/transaction/resources/mutationOptions.d.ts +66 -0
  283. package/dist/transaction/resources/mutationOptions.js +9 -0
  284. package/dist/transaction/resources/where.d.ts +85 -0
  285. package/dist/transaction/resources/where.js +70 -0
  286. package/dist/{client → transaction/resources}/writeOptionsSchema.d.ts +2 -6
  287. package/dist/{client → transaction/resources}/writeOptionsSchema.js +9 -5
  288. package/dist/{schema → transaction/schema}/field.d.ts +5 -5
  289. package/dist/{schema → transaction/schema}/field.js +5 -5
  290. package/dist/transaction/schema/loadStrategy.d.ts +45 -0
  291. package/dist/transaction/schema/loadStrategy.js +46 -0
  292. package/dist/{schema → transaction/schema}/model.d.ts +50 -35
  293. package/dist/{schema → transaction/schema}/model.js +30 -20
  294. package/dist/transaction/schema/openapi.d.ts +57 -0
  295. package/dist/transaction/schema/openapi.js +340 -0
  296. package/dist/{schema → transaction/schema}/relation.d.ts +14 -14
  297. package/dist/{schema → transaction/schema}/relation.js +7 -7
  298. package/dist/{schema → transaction/schema}/residency.d.ts +0 -9
  299. package/dist/{schema → transaction/schema}/residency.js +0 -5
  300. package/dist/{schema → transaction/schema}/roles.d.ts +5 -5
  301. package/dist/{schema → transaction/schema}/roles.js +5 -5
  302. package/dist/{schema → transaction/schema}/schema.d.ts +12 -10
  303. package/dist/{schema → transaction/schema}/schema.js +4 -3
  304. package/dist/{schema → transaction/schema}/tenancy.d.ts +1 -1
  305. package/dist/{schema → transaction/schema}/tenancy.js +7 -4
  306. package/dist/transaction/transactionLayer.d.ts +82 -0
  307. package/dist/transaction/transactionLayer.js +24 -0
  308. package/dist/{transactions → transaction/transactions/settlement}/commitEnvelope.d.ts +4 -5
  309. package/dist/{transactions → transaction/transactions/settlement}/commitEnvelope.js +9 -13
  310. package/dist/{transactions → transaction/transactions/settlement}/httpCommitEnvelope.d.ts +9 -2
  311. package/dist/{transactions → transaction/transactions/settlement}/httpCommitEnvelope.js +5 -9
  312. package/dist/{transactions/durableWriteStore.d.ts → transaction/transactions/settlement/pendingWrite.d.ts} +10 -36
  313. package/dist/transaction/transactions/settlement/pendingWrite.js +20 -0
  314. package/dist/transaction/transport/commitFrames.d.ts +90 -0
  315. package/dist/transaction/transport/commitFrames.js +134 -0
  316. package/dist/transaction/transport/connectionManager.d.ts +215 -0
  317. package/dist/transaction/transport/connectionManager.js +673 -0
  318. package/dist/transaction/transport/credentialLifecycle.d.ts +177 -0
  319. package/dist/transaction/transport/credentialLifecycle.js +324 -0
  320. package/dist/{sync → transaction/transport}/heartbeat.d.ts +3 -1
  321. package/dist/{sync → transaction/transport}/heartbeat.js +6 -4
  322. package/dist/{client → transaction/transport}/httpClient.d.ts +59 -16
  323. package/dist/{client → transaction/transport}/httpClient.js +5 -5
  324. package/dist/transaction/transport/httpOptions.d.ts +33 -0
  325. package/dist/transaction/transport/httpOptions.js +12 -0
  326. package/dist/{client → transaction/transport}/httpTransport.js +171 -85
  327. package/dist/{sync/NetworkProbe.d.ts → transaction/transport/networkProbe.d.ts} +7 -4
  328. package/dist/{sync/NetworkProbe.js → transaction/transport/networkProbe.js} +14 -13
  329. package/dist/transaction/transport/wsFrameHandlers.d.ts +128 -0
  330. package/dist/transaction/transport/wsFrameHandlers.js +429 -0
  331. package/dist/transaction/transport/wsTransport.d.ts +576 -0
  332. package/dist/transaction/transport/wsTransport.js +1017 -0
  333. package/dist/transaction/types/assertExact.d.ts +17 -0
  334. package/dist/transaction/types/assertExact.js +1 -0
  335. package/dist/{types → transaction/types}/global.d.ts +17 -2
  336. package/dist/{types → transaction/types}/global.js +2 -1
  337. package/dist/{types → transaction/types}/index.d.ts +14 -46
  338. package/dist/{types → transaction/types}/index.js +7 -16
  339. package/dist/{types → transaction/types}/streams.d.ts +63 -45
  340. package/dist/{utils → transaction/utils}/json.d.ts +18 -0
  341. package/dist/transaction/utils/json.js +276 -0
  342. package/dist/transaction/wire/accountResponses.d.ts +351 -0
  343. package/dist/transaction/wire/accountResponses.js +255 -0
  344. package/dist/transaction/wire/auth.d.ts +49 -0
  345. package/dist/transaction/wire/auth.js +57 -0
  346. package/dist/transaction/wire/claimEvent.d.ts +76 -0
  347. package/dist/transaction/wire/claimEvent.js +73 -0
  348. package/dist/transaction/wire/claims.d.ts +463 -0
  349. package/dist/transaction/wire/claims.js +229 -0
  350. package/dist/{wire → transaction/wire}/commit.d.ts +125 -193
  351. package/dist/{wire → transaction/wire}/commit.js +68 -47
  352. package/dist/{wire → transaction/wire}/delta.d.ts +66 -17
  353. package/dist/{wire → transaction/wire}/delta.js +37 -13
  354. package/dist/transaction/wire/errorEnvelope.d.ts +72 -0
  355. package/dist/{wire → transaction/wire}/errorEnvelope.js +36 -5
  356. package/dist/transaction/wire/feedCursor.d.ts +60 -0
  357. package/dist/transaction/wire/feedCursor.js +82 -0
  358. package/dist/transaction/wire/feedEvent.d.ts +177 -0
  359. package/dist/transaction/wire/feedEvent.js +39 -0
  360. package/dist/transaction/wire/frames.d.ts +194 -0
  361. package/dist/transaction/wire/frames.js +50 -0
  362. package/dist/transaction/wire/inboundFrames.d.ts +552 -0
  363. package/dist/transaction/wire/inboundFrames.js +116 -0
  364. package/dist/transaction/wire/index.d.ts +50 -0
  365. package/dist/transaction/wire/index.js +74 -0
  366. package/dist/{wire → transaction/wire}/listEnvelope.d.ts +13 -14
  367. package/dist/transaction/wire/listEnvelope.js +42 -0
  368. package/dist/transaction/wire/modelResponses.d.ts +85 -0
  369. package/dist/transaction/wire/modelResponses.js +43 -0
  370. package/dist/transactions/{TransactionQueue.d.ts → mutations/MutationQueue.d.ts} +79 -38
  371. package/dist/transactions/{TransactionQueue.js → mutations/MutationQueue.js} +110 -59
  372. package/dist/transactions/{TransactionStore.d.ts → mutations/MutationStore.d.ts} +8 -8
  373. package/dist/transactions/{TransactionStore.js → mutations/MutationStore.js} +2 -2
  374. package/dist/transactions/{coalesceRules.d.ts → mutations/coalesceRules.d.ts} +10 -10
  375. package/dist/transactions/{coalesceRules.js → mutations/coalesceRules.js} +1 -1
  376. package/dist/transactions/mutations/commitLatency.d.ts +52 -0
  377. package/dist/transactions/mutations/commitLatency.js +130 -0
  378. package/dist/transactions/{commitOutboxStore.d.ts → mutations/commitOutboxStore.d.ts} +1 -5
  379. package/dist/transactions/{commitOutboxStore.js → mutations/commitOutboxStore.js} +1 -1
  380. package/dist/transactions/{commitPayload.d.ts → mutations/commitPayload.d.ts} +16 -15
  381. package/dist/transactions/{commitPayload.js → mutations/commitPayload.js} +12 -12
  382. package/dist/transactions/{deltaConfirmation.d.ts → mutations/deltaConfirmation.d.ts} +11 -11
  383. package/dist/transactions/{deltaConfirmation.js → mutations/deltaConfirmation.js} +7 -7
  384. package/dist/transactions/mutations/durableWriteStore.d.ts +14 -0
  385. package/dist/transactions/mutations/durableWriteStore.js +12 -0
  386. package/dist/transactions/{optimisticApply.d.ts → mutations/optimisticApply.d.ts} +7 -7
  387. package/dist/transactions/{replayValidation.d.ts → mutations/replayValidation.d.ts} +3 -3
  388. package/dist/transactions/{replayValidation.js → mutations/replayValidation.js} +4 -3
  389. package/dist/utils/mobxSetup.d.ts +1 -1
  390. package/dist/utils/mobxSetup.js +5 -2
  391. package/dist/webhooks/events.d.ts +2 -2
  392. package/dist/wire/index.d.ts +1 -34
  393. package/dist/wire/index.js +8 -49
  394. package/docs/agent-messaging.md +3 -3
  395. package/docs/agents.md +19 -12
  396. package/docs/api-keys.md +8 -4
  397. package/docs/api.md +22 -18
  398. package/docs/audit.md +2 -0
  399. package/docs/cli.md +31 -3
  400. package/docs/client-behavior.md +8 -6
  401. package/docs/concurrency-convention.md +30 -24
  402. package/docs/coordination.md +48 -38
  403. package/docs/data-sources.md +3 -1
  404. package/docs/debugging.md +5 -3
  405. package/docs/deployment.md +267 -0
  406. package/docs/examples/agent-human.md +49 -42
  407. package/docs/examples/ai-sdk-tool.md +69 -44
  408. package/docs/examples/existing-python-backend.md +8 -6
  409. package/docs/examples/nextjs.md +129 -47
  410. package/docs/examples/scoped-agent.md +45 -44
  411. package/docs/examples/server-agent.md +46 -26
  412. package/docs/groups.md +32 -29
  413. package/docs/guarantees.md +4 -2
  414. package/docs/how-it-works.md +9 -7
  415. package/docs/idempotency.md +126 -0
  416. package/docs/identity.md +58 -54
  417. package/docs/index.md +172 -86
  418. package/docs/integration-guide.md +17 -16
  419. package/docs/interaction-model.md +6 -4
  420. package/docs/mcp.md +41 -16
  421. package/docs/migration.md +63 -5
  422. package/docs/operating-on-your-database.md +3 -1
  423. package/docs/projects.md +2 -0
  424. package/docs/quickstart.md +22 -5
  425. package/docs/react.md +12 -10
  426. package/docs/schema-contract.md +5 -3
  427. package/docs/session-settings.md +108 -0
  428. package/docs/sessions.md +3 -1
  429. package/docs/webhooks.md +3 -1
  430. package/llms.txt +47 -17
  431. package/package.json +10 -8
  432. package/dist/agent/Agent.d.ts +0 -366
  433. package/dist/agent/Agent.js +0 -514
  434. package/dist/agent/index.d.ts +0 -115
  435. package/dist/agent/index.js +0 -128
  436. package/dist/agent/session.d.ts +0 -93
  437. package/dist/agent/session.js +0 -149
  438. package/dist/agent/types.d.ts +0 -68
  439. package/dist/agent/types.js +0 -9
  440. package/dist/client/durableWrites.d.ts +0 -21
  441. package/dist/coordination/schema.d.ts +0 -722
  442. package/dist/schema/openapi.d.ts +0 -29
  443. package/dist/schema/openapi.js +0 -124
  444. package/dist/transactions/durableWriteStore.js +0 -30
  445. package/dist/utils/json.js +0 -88
  446. package/dist/wire/errorEnvelope.d.ts +0 -55
  447. package/dist/wire/frames.d.ts +0 -197
  448. package/dist/wire/frames.js +0 -49
  449. package/dist/wire/listEnvelope.js +0 -18
  450. /package/dist/{client → transaction/auth}/credentialEndpoint.d.ts +0 -0
  451. /package/dist/{client → transaction/auth}/credentialEndpoint.js +0 -0
  452. /package/dist/{auth → transaction/auth}/credentialPolicy.d.ts +0 -0
  453. /package/dist/{auth → transaction/auth}/credentialPolicy.js +0 -0
  454. /package/dist/{auth → transaction/auth}/credentialSource.js +0 -0
  455. /package/dist/{client → transaction/auth}/hostedEndpoints.d.ts +0 -0
  456. /package/dist/{client → transaction/auth}/hostedEndpoints.js +0 -0
  457. /package/dist/{client → transaction/coordination}/claimHeartbeatLoop.d.ts +0 -0
  458. /package/dist/{client → transaction/coordination}/claimHeartbeatLoop.js +0 -0
  459. /package/dist/{client → transaction}/persistence.d.ts +0 -0
  460. /package/dist/{client → transaction}/persistence.js +0 -0
  461. /package/dist/{client → transaction/resources}/functionalUpdate.d.ts +0 -0
  462. /package/dist/{client → transaction/resources}/functionalUpdate.js +0 -0
  463. /package/dist/{transactions → transaction/transactions/settlement}/idempotencyKey.d.ts +0 -0
  464. /package/dist/{transactions → transaction/transactions/settlement}/idempotencyKey.js +0 -0
  465. /package/dist/{client → transaction/transport}/httpTransport.d.ts +0 -0
  466. /package/dist/{types → transaction/types}/modelData.d.ts +0 -0
  467. /package/dist/{types → transaction/types}/modelData.js +0 -0
  468. /package/dist/{types → transaction/types}/participant.d.ts +0 -0
  469. /package/dist/{types → transaction/types}/participant.js +0 -0
  470. /package/dist/{types → transaction/types}/streams.js +0 -0
  471. /package/dist/{utils → transaction/utils}/asyncIterator.d.ts +0 -0
  472. /package/dist/{utils → transaction/utils}/asyncIterator.js +0 -0
  473. /package/dist/{utils → transaction/utils}/duration.d.ts +0 -0
  474. /package/dist/{utils → transaction/utils}/duration.js +0 -0
  475. /package/dist/{wire → transaction/wire}/bootstrapReason.d.ts +0 -0
  476. /package/dist/{wire → transaction/wire}/bootstrapReason.js +0 -0
  477. /package/dist/{wire → transaction/wire}/protocol.d.ts +0 -0
  478. /package/dist/{wire → transaction/wire}/protocol.js +0 -0
  479. /package/dist/{wire → transaction/wire}/protocolVersion.d.ts +0 -0
  480. /package/dist/{wire → transaction/wire}/protocolVersion.js +0 -0
  481. /package/dist/transactions/{UnconfirmedWrites.d.ts → mutations/UnconfirmedWrites.d.ts} +0 -0
  482. /package/dist/transactions/{UnconfirmedWrites.js → mutations/UnconfirmedWrites.js} +0 -0
  483. /package/dist/transactions/{optimisticApply.js → mutations/optimisticApply.js} +0 -0
@@ -18,7 +18,6 @@
18
18
  */
19
19
  import { z } from 'zod';
20
20
  import type { ErrorCode } from '../errorCodes.js';
21
- import type { RequiredCapability } from '../errors.js';
22
21
  /** Matches the permanent source/idempotency-key ceiling. */
23
22
  export declare const COMMIT_CORRELATION_ID_MAX_LENGTH = 255;
24
23
  /** Opaque server-authored identity shared by a queued receipt and its authoritative source delta. */
@@ -29,6 +28,24 @@ export declare const commitStatusSchema: z.ZodEnum<{
29
28
  confirmed: "confirmed";
30
29
  }>;
31
30
  export type CommitStatus = z.infer<typeof commitStatusSchema>;
31
+ /**
32
+ * The settlement states a write may block on — extracted from the reported
33
+ * vocabulary above, never restated beside it. `commitStatusSchema` is every
34
+ * state a server can report; this is the subset a caller can usefully wait for,
35
+ * and the two are not the same question: one describes an outcome, the other a
36
+ * request.
37
+ *
38
+ * `.extract` keeps the relationship mechanical in both directions. Renaming a
39
+ * settlement state breaks this line at build time, and adding one that nobody
40
+ * can block on — a commit parked for a human, say — does not become a legal
41
+ * `wait` merely by being added above. Both the `wait` option's runtime
42
+ * validator and its interface derive from here, so they cannot disagree.
43
+ */
44
+ export declare const commitWaitSchema: z.ZodEnum<{
45
+ queued: "queued";
46
+ confirmed: "confirmed";
47
+ }>;
48
+ export type CommitWait = z.infer<typeof commitWaitSchema>;
32
49
  /** The one settlement discriminant shared by every commit boundary. */
33
50
  export declare const commitSettlementSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
34
51
  status: z.ZodLiteral<"queued">;
@@ -104,72 +121,6 @@ export declare const commitReceiptSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
104
121
  missingIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
105
122
  }, z.core.$strip>], "status">;
106
123
  export type CommitReceiptWire = z.infer<typeof commitReceiptSchema>;
107
- /**
108
- * Compatibility decoder for pre-contract WebSocket acknowledgements. It
109
- * supplies fields old servers omitted and normalizes their string sync ids,
110
- * then hands the result to the exact same canonical receipt schema. It never
111
- * invents a source correlation: an old/malformed queued receipt still fails
112
- * closed.
113
- */
114
- export declare const legacyCompatibleCommitReceiptSchema: z.ZodPreprocess<z.ZodDiscriminatedUnion<[z.ZodObject<{
115
- status: z.ZodLiteral<"queued">;
116
- correlationId: z.ZodString;
117
- object: z.ZodLiteral<"commit_receipt">;
118
- id: z.ZodOptional<z.ZodString>;
119
- clientTxId: z.ZodString;
120
- serverTxId: z.ZodString;
121
- success: z.ZodLiteral<true>;
122
- lastSyncId: z.ZodNumber;
123
- ops: z.ZodNumber;
124
- notifications: z.ZodOptional<z.ZodArray<z.ZodObject<{
125
- object: z.ZodOptional<z.ZodLiteral<"stale_notification">>;
126
- model: z.ZodString;
127
- id: z.ZodString;
128
- readAt: z.ZodNumber;
129
- observedSyncId: z.ZodNumber;
130
- conflictingFields: z.ZodArray<z.ZodString>;
131
- currentValues: z.ZodRecord<z.ZodString, z.ZodUnknown>;
132
- writtenBy: z.ZodObject<{
133
- kind: z.ZodEnum<{
134
- user: "user";
135
- agent: "agent";
136
- system: "system";
137
- }>;
138
- id: z.ZodString;
139
- }, z.core.$strip>;
140
- group: z.ZodOptional<z.ZodString>;
141
- }, z.core.$strip>>>;
142
- missingIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
143
- }, z.core.$strip>, z.ZodObject<{
144
- status: z.ZodLiteral<"confirmed">;
145
- correlationId: z.ZodOptional<z.ZodString>;
146
- object: z.ZodLiteral<"commit_receipt">;
147
- id: z.ZodOptional<z.ZodString>;
148
- clientTxId: z.ZodString;
149
- serverTxId: z.ZodString;
150
- success: z.ZodLiteral<true>;
151
- lastSyncId: z.ZodNumber;
152
- ops: z.ZodNumber;
153
- notifications: z.ZodOptional<z.ZodArray<z.ZodObject<{
154
- object: z.ZodOptional<z.ZodLiteral<"stale_notification">>;
155
- model: z.ZodString;
156
- id: z.ZodString;
157
- readAt: z.ZodNumber;
158
- observedSyncId: z.ZodNumber;
159
- conflictingFields: z.ZodArray<z.ZodString>;
160
- currentValues: z.ZodRecord<z.ZodString, z.ZodUnknown>;
161
- writtenBy: z.ZodObject<{
162
- kind: z.ZodEnum<{
163
- user: "user";
164
- agent: "agent";
165
- system: "system";
166
- }>;
167
- id: z.ZodString;
168
- }, z.core.$strip>;
169
- group: z.ZodOptional<z.ZodString>;
170
- }, z.core.$strip>>>;
171
- missingIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
172
- }, z.core.$strip>], "status">>;
173
124
  /** The failure arm is separate: queued/confirmed always imply `success:true`. */
174
125
  export declare const rejectedCommitReceiptSchema: z.ZodObject<{
175
126
  object: z.ZodLiteral<"commit_receipt">;
@@ -183,7 +134,13 @@ export declare const rejectedCommitReceiptSchema: z.ZodObject<{
183
134
  code: z.ZodCustom<ErrorCode, ErrorCode>;
184
135
  message: z.ZodString;
185
136
  field: z.ZodOptional<z.ZodString>;
186
- requiredCapability: z.ZodOptional<z.ZodCustom<RequiredCapability, RequiredCapability>>;
137
+ requiredCapability: z.ZodOptional<z.ZodObject<{
138
+ scope: z.ZodString;
139
+ constraints: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodArray<z.ZodString>, z.ZodString]>>>;
140
+ issuer: z.ZodPreprocess<z.ZodOptional<z.ZodString>>;
141
+ ttlSeconds: z.ZodPreprocess<z.ZodOptional<z.ZodNumber>>;
142
+ nonce: z.ZodPreprocess<z.ZodOptional<z.ZodString>>;
143
+ }, z.core.$loose>>;
187
144
  }, z.core.$strip>;
188
145
  }, z.core.$strip>;
189
146
  export type RejectedCommitReceiptWire = z.infer<typeof rejectedCommitReceiptSchema>;
@@ -257,7 +214,13 @@ export declare const mutationResultPayloadSchema: z.ZodUnion<readonly [z.ZodDisc
257
214
  code: z.ZodCustom<ErrorCode, ErrorCode>;
258
215
  message: z.ZodString;
259
216
  field: z.ZodOptional<z.ZodString>;
260
- requiredCapability: z.ZodOptional<z.ZodCustom<RequiredCapability, RequiredCapability>>;
217
+ requiredCapability: z.ZodOptional<z.ZodObject<{
218
+ scope: z.ZodString;
219
+ constraints: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodArray<z.ZodString>, z.ZodString]>>>;
220
+ issuer: z.ZodPreprocess<z.ZodOptional<z.ZodString>>;
221
+ ttlSeconds: z.ZodPreprocess<z.ZodOptional<z.ZodNumber>>;
222
+ nonce: z.ZodPreprocess<z.ZodOptional<z.ZodString>>;
223
+ }, z.core.$loose>>;
261
224
  }, z.core.$strip>;
262
225
  }, z.core.$strip>]>;
263
226
  export type MutationResultPayload = z.infer<typeof mutationResultPayloadSchema>;
@@ -333,7 +296,13 @@ export declare const mutationResultMessageSchema: z.ZodObject<{
333
296
  code: z.ZodCustom<ErrorCode, ErrorCode>;
334
297
  message: z.ZodString;
335
298
  field: z.ZodOptional<z.ZodString>;
336
- requiredCapability: z.ZodOptional<z.ZodCustom<RequiredCapability, RequiredCapability>>;
299
+ requiredCapability: z.ZodOptional<z.ZodObject<{
300
+ scope: z.ZodString;
301
+ constraints: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodArray<z.ZodString>, z.ZodString]>>>;
302
+ issuer: z.ZodPreprocess<z.ZodOptional<z.ZodString>>;
303
+ ttlSeconds: z.ZodPreprocess<z.ZodOptional<z.ZodNumber>>;
304
+ nonce: z.ZodPreprocess<z.ZodOptional<z.ZodString>>;
305
+ }, z.core.$loose>>;
337
306
  }, z.core.$strip>;
338
307
  }, z.core.$strip>]>;
339
308
  }, z.core.$strip>;
@@ -461,11 +430,12 @@ export declare const commitAckSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
461
430
  }, z.core.$strict>], "status">;
462
431
  export type CommitAck = z.infer<typeof commitAckSchema>;
463
432
  /**
464
- * Compatibility boundary for injected/older mutation executors. New
465
- * transports return `commitAckSchema`; a legacy `{lastSyncId}` is normalized
466
- * to explicit confirmed settlement before queue code branches on it.
433
+ * The boundary an injected mutation executor returns through. It is the
434
+ * acknowledgement schema itself: settlement is declared, never inferred from
435
+ * an omission, so a transport cannot report a write as landed by staying
436
+ * silent about how it landed.
467
437
  */
468
- export declare const mutationCommitResultSchema: z.ZodPipe<z.ZodUnion<readonly [z.ZodDiscriminatedUnion<[z.ZodObject<{
438
+ export declare const mutationCommitResultSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
469
439
  status: z.ZodLiteral<"queued">;
470
440
  correlationId: z.ZodString;
471
441
  lastSyncId: z.ZodNumber;
@@ -511,125 +481,7 @@ export declare const mutationCommitResultSchema: z.ZodPipe<z.ZodUnion<readonly [
511
481
  group: z.ZodOptional<z.ZodString>;
512
482
  }, z.core.$strip>>>;
513
483
  missingIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
514
- }, z.core.$strict>], "status">, z.ZodObject<{
515
- status: z.ZodOptional<z.ZodUndefined>;
516
- correlationId: z.ZodOptional<z.ZodUndefined>;
517
- lastSyncId: z.ZodNumber;
518
- notifications: z.ZodOptional<z.ZodArray<z.ZodObject<{
519
- object: z.ZodOptional<z.ZodLiteral<"stale_notification">>;
520
- model: z.ZodString;
521
- id: z.ZodString;
522
- readAt: z.ZodNumber;
523
- observedSyncId: z.ZodNumber;
524
- conflictingFields: z.ZodArray<z.ZodString>;
525
- currentValues: z.ZodRecord<z.ZodString, z.ZodUnknown>;
526
- writtenBy: z.ZodObject<{
527
- kind: z.ZodEnum<{
528
- user: "user";
529
- agent: "agent";
530
- system: "system";
531
- }>;
532
- id: z.ZodString;
533
- }, z.core.$strip>;
534
- group: z.ZodOptional<z.ZodString>;
535
- }, z.core.$strip>>>;
536
- missingIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
537
- }, z.core.$strict>]>, z.ZodTransform<{
538
- status: "queued";
539
- correlationId: string;
540
- lastSyncId: number;
541
- notifications?: {
542
- model: string;
543
- id: string;
544
- readAt: number;
545
- observedSyncId: number;
546
- conflictingFields: string[];
547
- currentValues: Record<string, unknown>;
548
- writtenBy: {
549
- kind: "user" | "agent" | "system";
550
- id: string;
551
- };
552
- object?: "stale_notification" | undefined;
553
- group?: string | undefined;
554
- }[] | undefined;
555
- missingIds?: string[] | undefined;
556
- } | {
557
- status: "confirmed";
558
- lastSyncId: number;
559
- correlationId?: string | undefined;
560
- notifications?: {
561
- model: string;
562
- id: string;
563
- readAt: number;
564
- observedSyncId: number;
565
- conflictingFields: string[];
566
- currentValues: Record<string, unknown>;
567
- writtenBy: {
568
- kind: "user" | "agent" | "system";
569
- id: string;
570
- };
571
- object?: "stale_notification" | undefined;
572
- group?: string | undefined;
573
- }[] | undefined;
574
- missingIds?: string[] | undefined;
575
- }, {
576
- status: "queued";
577
- correlationId: string;
578
- lastSyncId: number;
579
- notifications?: {
580
- model: string;
581
- id: string;
582
- readAt: number;
583
- observedSyncId: number;
584
- conflictingFields: string[];
585
- currentValues: Record<string, unknown>;
586
- writtenBy: {
587
- kind: "user" | "agent" | "system";
588
- id: string;
589
- };
590
- object?: "stale_notification" | undefined;
591
- group?: string | undefined;
592
- }[] | undefined;
593
- missingIds?: string[] | undefined;
594
- } | {
595
- status: "confirmed";
596
- lastSyncId: number;
597
- correlationId?: string | undefined;
598
- notifications?: {
599
- model: string;
600
- id: string;
601
- readAt: number;
602
- observedSyncId: number;
603
- conflictingFields: string[];
604
- currentValues: Record<string, unknown>;
605
- writtenBy: {
606
- kind: "user" | "agent" | "system";
607
- id: string;
608
- };
609
- object?: "stale_notification" | undefined;
610
- group?: string | undefined;
611
- }[] | undefined;
612
- missingIds?: string[] | undefined;
613
- } | {
614
- lastSyncId: number;
615
- status?: undefined;
616
- correlationId?: undefined;
617
- notifications?: {
618
- model: string;
619
- id: string;
620
- readAt: number;
621
- observedSyncId: number;
622
- conflictingFields: string[];
623
- currentValues: Record<string, unknown>;
624
- writtenBy: {
625
- kind: "user" | "agent" | "system";
626
- id: string;
627
- };
628
- object?: "stale_notification" | undefined;
629
- group?: string | undefined;
630
- }[] | undefined;
631
- missingIds?: string[] | undefined;
632
- }>>;
484
+ }, z.core.$strict>], "status">;
633
485
  export type MutationCommitResultInput = z.input<typeof mutationCommitResultSchema>;
634
486
  export type MutationCommitResult = z.infer<typeof mutationCommitResultSchema>;
635
487
  /**
@@ -669,3 +521,83 @@ export declare const clientCommitReceiptSchema: z.ZodObject<{
669
521
  missingIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
670
522
  }, z.core.$strict>;
671
523
  export type ClientCommitReceipt = z.infer<typeof clientCommitReceiptSchema>;
524
+ /** Control fields any operation in a commit may carry. */
525
+ export declare const commitOperationControlShape: {
526
+ id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
527
+ transactionId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
528
+ readAt: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
529
+ onStale: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
530
+ reject: "reject";
531
+ overwrite: "overwrite";
532
+ notify: "notify";
533
+ }>>>;
534
+ fenceToken: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
535
+ };
536
+ /** One write inside a commit, in the canonical spelling. */
537
+ export declare const commitOperationBodySchema: z.ZodObject<{
538
+ action: z.ZodString;
539
+ model: z.ZodString;
540
+ data: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
541
+ id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
542
+ transactionId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
543
+ readAt: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
544
+ onStale: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
545
+ reject: "reject";
546
+ overwrite: "overwrite";
547
+ notify: "notify";
548
+ }>>>;
549
+ fenceToken: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
550
+ }, z.core.$strip>;
551
+ export type CommitOperationBody = z.infer<typeof commitOperationBodySchema>;
552
+ /**
553
+ * The `POST /v1/commits` request body.
554
+ *
555
+ * `operations` carries the writes; `track` registers durable premises.
556
+ * Neither is required on its own, because a body with `track` and no
557
+ * `operations` is how a caller starts watching a row without writing to it.
558
+ * Request identity travels in the `Idempotency-Key` header.
559
+ */
560
+ export declare const commitRequestSchema: z.ZodObject<{
561
+ operations: z.ZodOptional<z.ZodArray<z.ZodObject<{
562
+ action: z.ZodString;
563
+ model: z.ZodString;
564
+ data: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
565
+ id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
566
+ transactionId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
567
+ readAt: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
568
+ onStale: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
569
+ reject: "reject";
570
+ overwrite: "overwrite";
571
+ notify: "notify";
572
+ }>>>;
573
+ fenceToken: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
574
+ }, z.core.$strip>>>;
575
+ reads: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
576
+ model: z.ZodString;
577
+ id: z.ZodString;
578
+ readAt: z.ZodNumber;
579
+ fields: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
580
+ onStale: z.ZodOptional<z.ZodEnum<{
581
+ reject: "reject";
582
+ overwrite: "overwrite";
583
+ notify: "notify";
584
+ }>>;
585
+ }, z.core.$strip>, z.ZodObject<{
586
+ group: z.ZodString;
587
+ readAt: z.ZodNumber;
588
+ onStale: z.ZodOptional<z.ZodEnum<{
589
+ reject: "reject";
590
+ overwrite: "overwrite";
591
+ notify: "notify";
592
+ }>>;
593
+ }, z.core.$strip>]>>>>;
594
+ track: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
595
+ model: z.ZodString;
596
+ id: z.ZodString;
597
+ readAt: z.ZodOptional<z.ZodNumber>;
598
+ }, z.core.$strip>, z.ZodObject<{
599
+ group: z.ZodString;
600
+ readAt: z.ZodOptional<z.ZodNumber>;
601
+ }, z.core.$strip>]>>>>;
602
+ }, z.core.$strip>;
603
+ export type CommitRequest = z.infer<typeof commitRequestSchema>;
@@ -17,12 +17,27 @@
17
17
  * one giant object.
18
18
  */
19
19
  import { z } from 'zod';
20
- import { staleNotificationSchema } from '../coordination/schema.js';
20
+ import { onStaleModeSchema, readDependencySchema, staleNotificationSchema, trackDependencySchema, } from '../coordination/schema.js';
21
+ import { requiredCapabilityWireSchema } from '../errors.js';
21
22
  /** Matches the permanent source/idempotency-key ceiling. */
22
23
  export const COMMIT_CORRELATION_ID_MAX_LENGTH = 255;
23
24
  /** Opaque server-authored identity shared by a queued receipt and its authoritative source delta. */
24
25
  export const correlationIdSchema = z.string().min(1).max(COMMIT_CORRELATION_ID_MAX_LENGTH);
25
26
  export const commitStatusSchema = z.enum(['queued', 'confirmed']);
27
+ /**
28
+ * The settlement states a write may block on — extracted from the reported
29
+ * vocabulary above, never restated beside it. `commitStatusSchema` is every
30
+ * state a server can report; this is the subset a caller can usefully wait for,
31
+ * and the two are not the same question: one describes an outcome, the other a
32
+ * request.
33
+ *
34
+ * `.extract` keeps the relationship mechanical in both directions. Renaming a
35
+ * settlement state breaks this line at build time, and adding one that nobody
36
+ * can block on — a commit parked for a human, say — does not become a legal
37
+ * `wait` merely by being added above. Both the `wait` option's runtime
38
+ * validator and its interface derive from here, so they cannot disagree.
39
+ */
40
+ export const commitWaitSchema = commitStatusSchema.extract(['queued', 'confirmed']);
26
41
  const queuedSettlementShape = {
27
42
  status: z.literal('queued'),
28
43
  correlationId: correlationIdSchema,
@@ -91,41 +106,13 @@ export const commitReceiptSchema = z.discriminatedUnion('status', [
91
106
  confirmedCommitReceiptSchema,
92
107
  ]);
93
108
  /**
94
- * Compatibility decoder for pre-contract WebSocket acknowledgements. It
95
- * supplies fields old servers omitted and normalizes their string sync ids,
96
- * then hands the result to the exact same canonical receipt schema. It never
97
- * invents a source correlation: an old/malformed queued receipt still fails
98
- * closed.
109
+ * The rejection code is deliberately not narrowed to the {@link ErrorCode}
110
+ * registry. A newer server may reject a commit with a code this build predates,
111
+ * and failing the whole receipt over an unrecognized string would turn a
112
+ * readable rejection into an opaque parse error. `errorCodes.ts` sanctions this
113
+ * single boundary cast; every code *producer* is constrained at the
114
+ * `AbloError` constructor instead.
99
115
  */
100
- export const legacyCompatibleCommitReceiptSchema = z.preprocess((value) => {
101
- if (typeof value !== 'object' || value === null)
102
- return value;
103
- const receipt = value;
104
- if (receipt.success !== true)
105
- return value;
106
- const rawLastSyncId = receipt.lastSyncId;
107
- const numericLastSyncId = typeof rawLastSyncId === 'string' && rawLastSyncId.trim().length > 0
108
- ? Number(rawLastSyncId)
109
- : rawLastSyncId;
110
- const normalizedLastSyncId = typeof numericLastSyncId === 'number' &&
111
- Number.isSafeInteger(numericLastSyncId) &&
112
- numericLastSyncId >= 0
113
- ? numericLastSyncId
114
- : undefined;
115
- return {
116
- ...receipt,
117
- object: receipt.object ?? 'commit_receipt',
118
- status: receipt.status ?? 'confirmed',
119
- serverTxId: typeof receipt.serverTxId === 'string'
120
- ? receipt.serverTxId
121
- : String(normalizedLastSyncId ?? 0),
122
- ops: typeof receipt.ops === 'number' && Number.isSafeInteger(receipt.ops) ? receipt.ops : 0,
123
- lastSyncId: normalizedLastSyncId ?? 0,
124
- };
125
- }, commitReceiptSchema);
126
- const requiredCapabilitySchema = z.custom((value) => typeof value === 'object' &&
127
- value !== null &&
128
- typeof value.scope === 'string', { message: 'requiredCapability must contain a scope' });
129
116
  const errorCodeSchema = z.custom((value) => typeof value === 'string' && value.length > 0, { message: 'commit rejection code must be a non-empty string' });
130
117
  /** The failure arm is separate: queued/confirmed always imply `success:true`. */
131
118
  export const rejectedCommitReceiptSchema = z.object({
@@ -140,7 +127,7 @@ export const rejectedCommitReceiptSchema = z.object({
140
127
  code: errorCodeSchema,
141
128
  message: z.string(),
142
129
  field: z.string().optional(),
143
- requiredCapability: requiredCapabilitySchema.optional(),
130
+ requiredCapability: requiredCapabilityWireSchema.optional(),
144
131
  }),
145
132
  });
146
133
  export const mutationResultPayloadSchema = z.union([
@@ -269,19 +256,13 @@ export const commitAckSchema = z.discriminatedUnion('status', [
269
256
  message: 'A source-confirmed acknowledgement requires a sync watermark',
270
257
  }),
271
258
  ]);
272
- const legacyMutationCommitResultSchema = z.strictObject({
273
- ...ackCommonShape,
274
- status: z.undefined().optional(),
275
- correlationId: z.undefined().optional(),
276
- });
277
259
  /**
278
- * Compatibility boundary for injected/older mutation executors. New
279
- * transports return `commitAckSchema`; a legacy `{lastSyncId}` is normalized
280
- * to explicit confirmed settlement before queue code branches on it.
260
+ * The boundary an injected mutation executor returns through. It is the
261
+ * acknowledgement schema itself: settlement is declared, never inferred from
262
+ * an omission, so a transport cannot report a write as landed by staying
263
+ * silent about how it landed.
281
264
  */
282
- export const mutationCommitResultSchema = z
283
- .union([commitAckSchema, legacyMutationCommitResultSchema])
284
- .transform((result) => (result.status ? result : { ...result, status: 'confirmed' }));
265
+ export const mutationCommitResultSchema = commitAckSchema;
285
266
  /**
286
267
  * Public SDK projection returned by `ablo.commits` and model mutations.
287
268
  *
@@ -298,3 +279,43 @@ export const clientCommitReceiptSchema = z.strictObject({
298
279
  notifications: notificationsSchema.optional(),
299
280
  missingIds: missingIdsSchema.optional(),
300
281
  });
282
+ // ─────────────────────────────────────────────────────────────────────────
283
+ // The request side of the commit boundary
284
+ // ─────────────────────────────────────────────────────────────────────────
285
+ //
286
+ // `POST /v1/commits` is the chokepoint every write passes through, so its
287
+ // request shape is a boundary contract and belongs here beside the receipt it
288
+ // answers with — not in a route handler. The published OpenAPI reference is
289
+ // derived from these schemas rather than describing them separately, so the
290
+ // documented surface cannot drift from the validated one.
291
+ //
292
+ // The server layers its own decoder-only compatibility spellings on top for
293
+ // already-shipped clients; those are a rollout concern, not the contract.
294
+ /** Control fields any operation in a commit may carry. */
295
+ export const commitOperationControlShape = {
296
+ id: z.string().nullish(),
297
+ transactionId: z.string().nullish(),
298
+ readAt: z.number().nullish(),
299
+ onStale: onStaleModeSchema.nullish(),
300
+ fenceToken: z.number().nullish(),
301
+ };
302
+ /** One write inside a commit, in the canonical spelling. */
303
+ export const commitOperationBodySchema = z.object({
304
+ ...commitOperationControlShape,
305
+ action: z.string(),
306
+ model: z.string(),
307
+ data: z.record(z.string(), z.unknown()).nullish(),
308
+ });
309
+ /**
310
+ * The `POST /v1/commits` request body.
311
+ *
312
+ * `operations` carries the writes; `track` registers durable premises.
313
+ * Neither is required on its own, because a body with `track` and no
314
+ * `operations` is how a caller starts watching a row without writing to it.
315
+ * Request identity travels in the `Idempotency-Key` header.
316
+ */
317
+ export const commitRequestSchema = z.object({
318
+ operations: z.array(commitOperationBodySchema).min(1).optional(),
319
+ reads: z.array(readDependencySchema).nullish(),
320
+ track: z.array(trackDependencySchema).nullish(),
321
+ });
@@ -5,9 +5,9 @@
5
5
  * one definition and cannot drift apart. This is the delta's home in the wire
6
6
  * layer, alongside the other protocol shapes in `wire/`.
7
7
  *
8
- * The wire delta is a projection of the stored `sync_deltas` row (see
9
- * {@link import('../schema/syncDeltaRow.js').syncDeltaRowSchema}) and differs from
10
- * it in three ways: it omits `organizationId` (the tenant-isolation predicate is
8
+ * The wire delta is a projection of the stored `sync_deltas` row (the
9
+ * `syncDeltaRowSchema` in `../log/syncDeltaRow.ts`) and differs from it
10
+ * in three ways: it omits `organizationId` (the tenant-isolation predicate is
11
11
  * never broadcast), it uses the full action vocabulary (see
12
12
  * {@link syncDeltaActionSchema}) rather than plain create, update, and delete, and
13
13
  * it carries attribution as nested {@link ParticipantRef}s instead of flat columns.
@@ -18,19 +18,18 @@
18
18
  * - {@link serverSyncDeltaSchema} — the core plus the audit attribution the server
19
19
  * adds to each broadcast, which the client ignores.
20
20
  *
21
- * The two participant enums below (`participantKind`, `confirmationState`) are the
22
- * shared vocabulary of the protocol. They live here, at the wire layer, so the
23
- * stored-row schema can import them downward rather than the wire delta reaching
24
- * up into the schema DSL for them.
21
+ * The participant vocabulary the delta carries is declared once elsewhere and
22
+ * re-served here: the actor union lives in `types/participant.ts` and its
23
+ * runtime validator in `coordination/schema.ts`. Only `confirmationState` has
24
+ * its home in this module, since the approval stage of a committed change is
25
+ * delta attribution and nothing else. All three mirror Postgres enums.
25
26
  */
26
27
  import { z } from 'zod';
27
- /** `participant_kind` — who a delta is attributed to. */
28
- export declare const participantKindSchema: z.ZodEnum<{
29
- user: "user";
30
- agent: "agent";
31
- system: "system";
32
- }>;
33
- export type ParticipantKind = z.infer<typeof participantKindSchema>;
28
+ /** `participant_kind` — who a delta is attributed to. Declared in
29
+ * `coordination/schema.ts`; re-exported so the wire subpath serves the
30
+ * vocabulary its delta shapes carry. */
31
+ export { participantKindSchema } from '../coordination/schema.js';
32
+ export type { ParticipantKind } from '../types/participant.js';
34
33
  /** `confirmation_state` — the approval stage a committed change was in. */
35
34
  export declare const confirmationStateSchema: z.ZodEnum<{
36
35
  auto: "auto";
@@ -69,7 +68,9 @@ export type WireDeltaData = z.infer<typeof wireDeltaDataSchema>;
69
68
  /**
70
69
  * A participant reference as carried on a broadcast delta. The server expands the
71
70
  * flat `actor_id` and `actor_kind` stored columns into this nested `{ kind, id }`
72
- * shape.
71
+ * shape. The type is the canonical {@link ParticipantRef} from
72
+ * `types/participant.ts`; the pin below fails to compile if this schema and the
73
+ * canonical shape ever drift.
73
74
  */
74
75
  export declare const participantRefSchema: z.ZodObject<{
75
76
  kind: z.ZodEnum<{
@@ -79,7 +80,7 @@ export declare const participantRefSchema: z.ZodObject<{
79
80
  }>;
80
81
  id: z.ZodString;
81
82
  }, z.core.$strip>;
82
- export type ParticipantRef = z.infer<typeof participantRefSchema>;
83
+ export type { ParticipantRef } from '../types/participant.js';
83
84
  /**
84
85
  * The fields the server and client agree on for a broadcast delta — the shared core
85
86
  * both projections extend. `transactionId` is typed as the client sees it (an
@@ -196,6 +197,54 @@ export declare const serverSyncDeltaSchema: z.ZodObject<{
196
197
  required_human_approval: "required_human_approval";
197
198
  auto_historical: "auto_historical";
198
199
  }>>;
199
- causedByTaskId: z.ZodNullable<z.ZodString>;
200
200
  }, z.core.$strip>;
201
201
  export type ServerSyncDelta = z.infer<typeof serverSyncDeltaSchema>;
202
+ /**
203
+ * The transaction-layer seam's transport-neutral projection of a broadcast
204
+ * delta. It removes delivery plumbing (`syncGroups`, `transactionId`, and
205
+ * `correlationId`) while retaining the row change and optional audit
206
+ * attribution. `TransactionLayer.observe()` yields this shape.
207
+ */
208
+ export declare const deltaSchema: z.ZodObject<{
209
+ id: z.ZodNumber;
210
+ data: z.ZodNullable<z.ZodUnion<readonly [z.ZodRecord<z.ZodString, z.ZodUnknown>, z.ZodString]>>;
211
+ actionType: z.ZodEnum<{
212
+ I: "I";
213
+ U: "U";
214
+ D: "D";
215
+ A: "A";
216
+ V: "V";
217
+ C: "C";
218
+ G: "G";
219
+ S: "S";
220
+ }>;
221
+ modelName: z.ZodString;
222
+ modelId: z.ZodString;
223
+ previousData: z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodRecord<z.ZodString, z.ZodUnknown>, z.ZodString]>>>;
224
+ createdAt: z.ZodString;
225
+ actor: z.ZodOptional<z.ZodNullable<z.ZodObject<{
226
+ kind: z.ZodEnum<{
227
+ user: "user";
228
+ agent: "agent";
229
+ system: "system";
230
+ }>;
231
+ id: z.ZodString;
232
+ }, z.core.$strip>>>;
233
+ onBehalfOf: z.ZodOptional<z.ZodNullable<z.ZodObject<{
234
+ kind: z.ZodEnum<{
235
+ user: "user";
236
+ agent: "agent";
237
+ system: "system";
238
+ }>;
239
+ id: z.ZodString;
240
+ }, z.core.$strip>>>;
241
+ capabilityId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
242
+ confirmationState: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
243
+ auto: "auto";
244
+ previewed: "previewed";
245
+ approved: "approved";
246
+ required_human_approval: "required_human_approval";
247
+ auto_historical: "auto_historical";
248
+ }>>>;
249
+ }, z.core.$strip>;
250
+ export type Delta = z.infer<typeof deltaSchema>;