@abloatai/ablo 0.24.0 → 0.26.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 (246) hide show
  1. package/AGENTS.md +5 -3
  2. package/CHANGELOG.md +33 -0
  3. package/README.md +45 -36
  4. package/dist/BaseSyncedStore.d.ts +72 -195
  5. package/dist/BaseSyncedStore.js +240 -625
  6. package/dist/Database.d.ts +8 -9
  7. package/dist/Database.js +9 -14
  8. package/dist/LazyReferenceCollection.js +5 -0
  9. package/dist/Model.js +6 -8
  10. package/dist/ModelRegistry.d.ts +25 -6
  11. package/dist/ModelRegistry.js +12 -6
  12. package/dist/NetworkMonitor.js +1 -1
  13. package/dist/ObjectPool.js +9 -3
  14. package/dist/SyncClient.d.ts +15 -5
  15. package/dist/SyncClient.js +152 -66
  16. package/dist/SyncEngineContext.d.ts +1 -3
  17. package/dist/SyncEngineContext.js +1 -2
  18. package/dist/agent/Agent.d.ts +21 -8
  19. package/dist/agent/Agent.js +26 -13
  20. package/dist/ai-sdk/coordination-context.js +9 -3
  21. package/dist/ai-sdk/wrap.d.ts +1 -1
  22. package/dist/ai-sdk/wrap.js +1 -1
  23. package/dist/auth/credentialPolicy.d.ts +10 -2
  24. package/dist/auth/credentialSource.d.ts +1 -13
  25. package/dist/auth/credentialSource.js +6 -13
  26. package/dist/auth/index.js +3 -3
  27. package/dist/cli.cjs +583 -287
  28. package/dist/client/Ablo.d.ts +35 -764
  29. package/dist/client/Ablo.js +64 -688
  30. package/dist/client/ApiClient.d.ts +14 -1
  31. package/dist/client/ApiClient.js +63 -9
  32. package/dist/client/auth.d.ts +8 -17
  33. package/dist/client/auth.js +42 -6
  34. package/dist/client/consoleLogger.d.ts +36 -0
  35. package/dist/client/consoleLogger.js +45 -0
  36. package/dist/client/createInternalComponents.js +1 -1
  37. package/dist/client/createModelProxy.js +10 -6
  38. package/dist/client/credentialEndpoint.d.ts +63 -0
  39. package/dist/client/credentialEndpoint.js +87 -0
  40. package/dist/client/hostedEndpoints.d.ts +24 -0
  41. package/dist/client/hostedEndpoints.js +24 -0
  42. package/dist/client/httpClient.d.ts +1 -1
  43. package/dist/client/identity.js +2 -1
  44. package/dist/client/modelRegistration.d.ts +14 -0
  45. package/dist/client/modelRegistration.js +321 -0
  46. package/dist/client/options.d.ts +396 -0
  47. package/dist/client/options.js +10 -0
  48. package/dist/client/resourceTypes.d.ts +344 -0
  49. package/dist/client/resourceTypes.js +13 -0
  50. package/dist/client/schemaConfig.d.ts +56 -0
  51. package/dist/client/schemaConfig.js +188 -0
  52. package/dist/client/sessionMint.d.ts +1 -1
  53. package/dist/client/validateAbloOptions.js +1 -1
  54. package/dist/client/wsMutationExecutor.d.ts +33 -0
  55. package/dist/client/wsMutationExecutor.js +77 -0
  56. package/dist/context.js +0 -3
  57. package/dist/coordination/index.d.ts +8 -1
  58. package/dist/coordination/index.js +24 -1
  59. package/dist/coordination/trace.d.ts +0 -1
  60. package/dist/coordination/trace.js +0 -1
  61. package/dist/core/DatabaseManager.d.ts +0 -1
  62. package/dist/core/DatabaseManager.js +26 -24
  63. package/dist/core/QueryProcessor.js +7 -8
  64. package/dist/core/QueryView.d.ts +14 -2
  65. package/dist/core/QueryView.js +4 -5
  66. package/dist/core/StoreManager.d.ts +2 -2
  67. package/dist/core/StoreManager.js +5 -1
  68. package/dist/core/index.d.ts +1 -1
  69. package/dist/core/openIDBWithTimeout.js +15 -11
  70. package/dist/core/query-utils.js +1 -1
  71. package/dist/core/storeContract.d.ts +143 -0
  72. package/dist/core/storeContract.js +16 -0
  73. package/dist/errorCodes.d.ts +11 -2
  74. package/dist/errorCodes.js +155 -137
  75. package/dist/errors.d.ts +18 -7
  76. package/dist/errors.js +14 -1
  77. package/dist/index.js +5 -0
  78. package/dist/interfaces/index.d.ts +6 -20
  79. package/dist/keys/index.js +18 -9
  80. package/dist/mutators/UndoManager.js +6 -1
  81. package/dist/mutators/defineMutators.d.ts +1 -3
  82. package/dist/policy/types.d.ts +1 -1
  83. package/dist/query/client.d.ts +11 -0
  84. package/dist/query/client.js +81 -52
  85. package/dist/react/AbloProvider.d.ts +6 -10
  86. package/dist/react/AbloProvider.js +22 -15
  87. package/dist/react/context.d.ts +2 -118
  88. package/dist/react/useAblo.js +1 -1
  89. package/dist/react/useErrorListener.js +1 -1
  90. package/dist/react/useMutationFailureListener.js +1 -1
  91. package/dist/react/useMutators.js +7 -1
  92. package/dist/react/useReactive.js +0 -1
  93. package/dist/react/useUndoScope.js +2 -2
  94. package/dist/schema/ddlLock.d.ts +39 -0
  95. package/dist/schema/ddlLock.js +51 -0
  96. package/dist/schema/field.js +1 -1
  97. package/dist/schema/index.d.ts +4 -3
  98. package/dist/schema/index.js +15 -5
  99. package/dist/schema/model.d.ts +3 -3
  100. package/dist/schema/model.js +2 -2
  101. package/dist/schema/openapi.js +5 -1
  102. package/dist/schema/queries.d.ts +1 -1
  103. package/dist/schema/queries.js +1 -0
  104. package/dist/schema/residency.d.ts +35 -0
  105. package/dist/schema/residency.js +27 -0
  106. package/dist/schema/roles.d.ts +25 -0
  107. package/dist/schema/roles.js +37 -0
  108. package/dist/schema/schema.d.ts +3 -3
  109. package/dist/schema/schema.js +11 -7
  110. package/dist/schema/serialize.d.ts +8 -8
  111. package/dist/schema/sync-delta-row.d.ts +2 -2
  112. package/dist/schema/sync-delta-row.js +2 -2
  113. package/dist/server/storage-mode.d.ts +8 -1
  114. package/dist/server/storage-mode.js +14 -4
  115. package/dist/source/adapter.d.ts +1 -1
  116. package/dist/source/adapters/drizzle.js +4 -3
  117. package/dist/source/adapters/kysely.js +4 -3
  118. package/dist/source/adapters/memory.js +1 -1
  119. package/dist/source/adapters/prisma.js +5 -4
  120. package/dist/source/conformance.js +10 -8
  121. package/dist/source/connector.js +4 -2
  122. package/dist/source/factory.d.ts +106 -0
  123. package/dist/source/factory.js +273 -0
  124. package/dist/source/index.d.ts +11 -461
  125. package/dist/source/index.js +14 -416
  126. package/dist/source/next.d.ts +1 -1
  127. package/dist/source/next.js +1 -1
  128. package/dist/source/pushQueue.d.ts +1 -1
  129. package/dist/source/pushQueue.js +6 -3
  130. package/dist/source/signing.d.ts +59 -0
  131. package/dist/source/signing.js +142 -0
  132. package/dist/source/types.d.ts +334 -0
  133. package/dist/source/types.js +44 -0
  134. package/dist/stores/ObjectStore.d.ts +1 -1
  135. package/dist/stores/ObjectStore.js +23 -23
  136. package/dist/stores/SyncActionStore.d.ts +1 -1
  137. package/dist/stores/SyncActionStore.js +70 -35
  138. package/dist/surface.d.ts +1 -1
  139. package/dist/surface.js +1 -0
  140. package/dist/sync/AreaOfInterestManager.d.ts +2 -2
  141. package/dist/sync/AreaOfInterestManager.js +1 -1
  142. package/dist/sync/BootstrapHelper.d.ts +1 -3
  143. package/dist/sync/BootstrapHelper.js +29 -8
  144. package/dist/sync/ConnectionManager.d.ts +8 -0
  145. package/dist/sync/ConnectionManager.js +19 -4
  146. package/dist/sync/HydrationCoordinator.d.ts +12 -0
  147. package/dist/sync/HydrationCoordinator.js +25 -5
  148. package/dist/sync/NetworkProbe.d.ts +3 -2
  149. package/dist/sync/NetworkProbe.js +7 -6
  150. package/dist/sync/SyncWebSocket.d.ts +71 -120
  151. package/dist/sync/SyncWebSocket.js +324 -630
  152. package/dist/sync/awaitClaimGrant.js +27 -19
  153. package/dist/sync/bootstrapApply.d.ts +60 -0
  154. package/dist/sync/bootstrapApply.js +65 -0
  155. package/dist/sync/commitFrames.d.ts +43 -0
  156. package/dist/sync/commitFrames.js +94 -0
  157. package/dist/sync/createClaimStream.js +3 -2
  158. package/dist/sync/createSnapshot.d.ts +1 -3
  159. package/dist/sync/credentialLifecycle.d.ts +175 -0
  160. package/dist/sync/credentialLifecycle.js +329 -0
  161. package/dist/sync/deltaPipeline.d.ts +111 -0
  162. package/dist/sync/deltaPipeline.js +262 -0
  163. package/dist/sync/groupChange.d.ts +111 -0
  164. package/dist/sync/groupChange.js +246 -0
  165. package/dist/sync/heartbeat.d.ts +62 -0
  166. package/dist/sync/heartbeat.js +91 -0
  167. package/dist/sync/participants.d.ts +8 -8
  168. package/dist/sync/syncCursor.d.ts +44 -0
  169. package/dist/sync/syncCursor.js +59 -0
  170. package/dist/sync/syncPlan.d.ts +62 -0
  171. package/dist/sync/syncPlan.js +51 -0
  172. package/dist/sync/wsFrameHandlers.d.ts +117 -0
  173. package/dist/sync/wsFrameHandlers.js +378 -0
  174. package/dist/testing/fixtures/bootstrap.d.ts +9 -11
  175. package/dist/testing/fixtures/deltas.d.ts +1 -1
  176. package/dist/testing/fixtures/models.js +1 -0
  177. package/dist/testing/helpers/sync-engine-harness.d.ts +0 -3
  178. package/dist/testing/helpers/sync-engine-harness.js +2 -1
  179. package/dist/testing/index.d.ts +1 -1
  180. package/dist/testing/index.js +1 -1
  181. package/dist/testing/mocks/MockSyncContext.d.ts +1 -17
  182. package/dist/testing/mocks/MockSyncContext.js +1 -32
  183. package/dist/testing/mocks/MockSyncStore.d.ts +4 -4
  184. package/dist/testing/mocks/MockWebSocket.d.ts +2 -2
  185. package/dist/transactions/TransactionQueue.d.ts +20 -56
  186. package/dist/transactions/TransactionQueue.js +101 -487
  187. package/dist/transactions/TransactionStore.d.ts +18 -0
  188. package/dist/transactions/TransactionStore.js +51 -0
  189. package/dist/transactions/coalesceRules.d.ts +34 -0
  190. package/dist/transactions/coalesceRules.js +117 -0
  191. package/dist/transactions/commitPayload.d.ts +134 -0
  192. package/dist/transactions/commitPayload.js +152 -0
  193. package/dist/transactions/deltaConfirmation.d.ts +60 -0
  194. package/dist/transactions/deltaConfirmation.js +223 -0
  195. package/dist/transactions/optimistic.d.ts +24 -0
  196. package/dist/transactions/optimistic.js +45 -0
  197. package/dist/transactions/persistedReplay.d.ts +93 -0
  198. package/dist/transactions/persistedReplay.js +105 -0
  199. package/dist/types/index.d.ts +3 -3
  200. package/dist/types/index.js +0 -5
  201. package/dist/types/modelData.d.ts +12 -0
  202. package/dist/types/modelData.js +11 -0
  203. package/dist/types/participant.d.ts +21 -0
  204. package/dist/types/participant.js +12 -0
  205. package/dist/types/streams.d.ts +8 -14
  206. package/dist/utils/mobx-setup.d.ts +1 -1
  207. package/dist/utils/mobx-setup.js +2 -2
  208. package/dist/wire/errorEnvelope.d.ts +11 -2
  209. package/dist/wire/errorEnvelope.js +14 -2
  210. package/dist/wire/frames.d.ts +90 -0
  211. package/dist/wire/frames.js +55 -1
  212. package/dist/wire/index.d.ts +4 -1
  213. package/dist/wire/index.js +20 -1
  214. package/dist/wire/protocol.d.ts +45 -0
  215. package/dist/wire/protocol.js +45 -0
  216. package/dist/wire/protocolVersion.d.ts +56 -0
  217. package/dist/wire/protocolVersion.js +63 -0
  218. package/docs/api-keys.md +4 -3
  219. package/docs/data-sources.md +12 -5
  220. package/docs/examples/existing-python-backend.md +3 -3
  221. package/docs/identity.md +4 -4
  222. package/docs/integration-guide.md +1 -1
  223. package/docs/react.md +1 -1
  224. package/docs/sessions.md +5 -7
  225. package/llms.txt +4 -2
  226. package/package.json +15 -13
  227. package/dist/client/index.d.ts +0 -36
  228. package/dist/client/index.js +0 -33
  229. package/dist/config/index.d.ts +0 -10
  230. package/dist/config/index.js +0 -12
  231. package/dist/interfaces/headless.d.ts +0 -95
  232. package/dist/interfaces/headless.js +0 -41
  233. package/dist/query/index.d.ts +0 -6
  234. package/dist/query/index.js +0 -5
  235. package/dist/realtime/index.d.ts +0 -10
  236. package/dist/realtime/index.js +0 -9
  237. package/dist/schema/plane.d.ts +0 -23
  238. package/dist/schema/plane.js +0 -19
  239. package/dist/server/next.d.ts +0 -51
  240. package/dist/server/next.js +0 -47
  241. package/dist/sync/OfflineFlush.d.ts +0 -9
  242. package/dist/sync/OfflineFlush.js +0 -22
  243. package/dist/sync/OfflineTransactionStore.d.ts +0 -37
  244. package/dist/sync/OfflineTransactionStore.js +0 -263
  245. package/dist/transactions/index.d.ts +0 -16
  246. package/dist/transactions/index.js +0 -7
@@ -13,50 +13,13 @@ import { Model } from '../Model.js';
13
13
  import { SyncPosition } from '../sync/syncPosition.js';
14
14
  import type { WriteOptions } from '../interfaces/index.js';
15
15
  import type { StaleNotification, ReadDependency } from '../coordination/schema.js';
16
- export interface UserContext {
17
- userId: string;
18
- organizationId: string;
19
- role?: string;
20
- teamIds?: string[];
21
- }
22
- /** Wire-format mutation payload (post-projection). */
23
- type MutationInput = Record<string, unknown>;
24
- export interface Transaction {
25
- id: string;
26
- type: 'create' | 'update' | 'delete' | 'archive' | 'unarchive';
27
- modelName: string;
28
- modelId: string;
29
- modelKey: string;
30
- data?: MutationInput;
31
- previousData?: MutationInput | null;
32
- context: UserContext;
33
- status: 'pending' | 'executing' | 'awaiting_delta' | 'completed' | 'failed' | 'rolled_back';
34
- createdAt: number;
35
- attempts: number;
36
- priority: 'normal' | 'high';
37
- priorityScore: number;
38
- writeOptions?: WriteOptions;
39
- batchId?: string;
40
- /** Completed locally without a server operation; no sync echo will arrive. */
41
- localOnly?: boolean;
42
- /** LINEAR PATTERN: syncId threshold - transaction confirms when delta.id >= this value */
43
- syncIdNeededForCompletion?: number;
44
- /**
45
- * Resolves when the server has confirmed this transaction (delta arrived
46
- * or HTTP ack). Rejects with the originating error if the transaction is
47
- * permanently rolled back. Name matches the queue's existing `'confirmed'`
48
- * status vocabulary (`commits.create({wait:'confirmed'})`,
49
- * `waitForConfirmation`) — gives call sites a single `await` point for
50
- * "did my write land?", so failures surface at the source instead of
51
- * leaking via silent pool rollback. The rejection error is the same
52
- * `AbloError` recorded on the queue's `transaction:failed` event.
53
- */
54
- confirmation?: Promise<void>;
55
- }
16
+ import { type MutationInput, type Transaction, type UserContext } from './commitPayload.js';
17
+ export type { Transaction, UserContext } from './commitPayload.js';
56
18
  /**
57
19
  * A raw multi-op commit transaction queued via `ablo.commits.create()`.
58
20
  *
59
- * Distinct from the per-model `Transaction` above: operations are
21
+ * Distinct from the per-model `Transaction` (see `./commitPayload.js`):
22
+ * operations are
60
23
  * pre-built by the caller and the envelope is atomic — no coalescing,
61
24
  * no FK reordering, no optimistic local apply. The lane shares the
62
25
  * same `mutationExecutor.commit()` underneath as the model-proxy
@@ -65,7 +28,7 @@ export interface Transaction {
65
28
  interface CommitTransaction {
66
29
  id: string;
67
30
  kind: 'commit';
68
- operations: Array<{
31
+ operations: {
69
32
  type: string;
70
33
  model: string;
71
34
  id: string;
@@ -73,7 +36,7 @@ interface CommitTransaction {
73
36
  transactionId?: string;
74
37
  readAt?: number | null;
75
38
  onStale?: 'reject' | 'overwrite' | 'notify' | null;
76
- }>;
39
+ }[];
77
40
  causedByTaskId?: string | null;
78
41
  /** Batch-level read dependencies (STORM read-set), forwarded to the executor. */
79
42
  reads?: ReadDependency[] | null;
@@ -143,7 +106,6 @@ export declare class TransactionQueue extends EventEmitter {
143
106
  private computePriorityScore;
144
107
  private ensureDerivedFields;
145
108
  private entityKey;
146
- private isTransactionForModel;
147
109
  private resolveConfirmation;
148
110
  private takeUnsentCreateForModel;
149
111
  private cancelUnsentCreateForDelete;
@@ -151,13 +113,11 @@ export declare class TransactionQueue extends EventEmitter {
151
113
  private completeLocalDelete;
152
114
  private deferDeleteUntilCreateSettles;
153
115
  private releaseDeferredDeletesForCreate;
154
- private mergeUpdateData;
155
116
  private config;
156
117
  private executingCount;
157
118
  private optimisticUpdates;
158
119
  private commitNotifications;
159
- private deltaConfirmationTimeouts;
160
- private deltaConfirmationRetries;
120
+ private readonly deltaConfirmation;
161
121
  private isConnectedFn;
162
122
  private commitOfflineGraceTimer;
163
123
  /**
@@ -171,9 +131,6 @@ export declare class TransactionQueue extends EventEmitter {
171
131
  /** Applied-cursor alias, kept so the many internal read sites stay legible. */
172
132
  private get lastSeenSyncId();
173
133
  private noteAck;
174
- private static readonly DELTA_MAX_RETRIES;
175
- private static readonly DELTA_INITIAL_TIMEOUT_MS;
176
- private static readonly DELTA_MAX_TIMEOUT_MS;
177
134
  private batchIndex;
178
135
  /**
179
136
  * Resolvers for per-transaction `confirmation` promises. Populated in
@@ -288,13 +245,13 @@ export declare class TransactionQueue extends EventEmitter {
288
245
  /**
289
246
  * Batch upload attachments — delegates to MutationExecutor
290
247
  */
291
- batchUploadAttachments(_files: File[], items: Array<{
248
+ batchUploadAttachments(_files: File[], items: {
292
249
  id: string;
293
250
  [key: string]: unknown;
294
- }>, _context: UserContext): Promise<Array<{
251
+ }[], _context: UserContext): Promise<{
295
252
  id: string;
296
253
  url: string;
297
- }>>;
254
+ }[]>;
298
255
  /**
299
256
  * Archive operation
300
257
  */
@@ -321,11 +278,11 @@ export declare class TransactionQueue extends EventEmitter {
321
278
  /**
322
279
  * LINEAR PATTERN: Confirm all awaiting transactions when delta with syncId >= threshold arrives.
323
280
  * This replaces clientMutationId echoing - transactions are confirmed by sync ID threshold.
281
+ * Policy + timeout maps live in the `./deltaConfirmation.js` leaf.
324
282
  * @param syncId - The sync ID of the received delta
325
283
  */
326
284
  onDeltaReceived(syncId: number): void;
327
285
  private scheduleDeltaConfirmationTimeout;
328
- private cancelDeltaConfirmationTimeout;
329
286
  /**
330
287
  * Wait for a transaction to be confirmed via delta echo (Linear pattern)
331
288
  * Reuses existing timeout mechanism from scheduleDeltaConfirmationTimeout
@@ -388,7 +345,8 @@ export declare class TransactionQueue extends EventEmitter {
388
345
  */
389
346
  handleConflict(transaction: Transaction, serverData: MutationInput): Promise<void>;
390
347
  /**
391
- * Optimistic updates
348
+ * Optimistic updates — apply/rollback rules live in `./optimistic.js`;
349
+ * these delegates bind the host-owned ledger + event emitter.
392
350
  */
393
351
  private applyOptimisticCreate;
394
352
  private applyOptimisticUpdate;
@@ -402,6 +360,13 @@ export declare class TransactionQueue extends EventEmitter {
402
360
  * Persistence
403
361
  */
404
362
  loadPersistedTransactions(database: Database): Promise<void>;
363
+ /**
364
+ * Validate + rehydrate one persisted row (the T1.8 IDB replay boundary).
365
+ * Rows written by other subsystems into the same store (`'queue'`,
366
+ * `'awaiting_delta'`) are skipped silently; rows that fail the
367
+ * persisted-transaction schema (older SDK versions, corruption) are
368
+ * DROPPED with an observability capture instead of replayed as commits.
369
+ */
405
370
  private deserializeTransaction;
406
371
  /**
407
372
  * Cancel transactions for a specific model
@@ -529,4 +494,3 @@ export declare class TransactionQueue extends EventEmitter {
529
494
  */
530
495
  dispose(): void;
531
496
  }
532
- export {};