@abloatai/ablo 0.3.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 (278) hide show
  1. package/CHANGELOG.md +208 -0
  2. package/LICENSE +201 -0
  3. package/NOTICE +12 -0
  4. package/README.md +230 -0
  5. package/dist/BaseSyncedStore.d.ts +709 -0
  6. package/dist/BaseSyncedStore.js +1843 -0
  7. package/dist/Database.d.ts +344 -0
  8. package/dist/Database.js +1259 -0
  9. package/dist/LazyReferenceCollection.d.ts +181 -0
  10. package/dist/LazyReferenceCollection.js +460 -0
  11. package/dist/Model.d.ts +339 -0
  12. package/dist/Model.js +715 -0
  13. package/dist/ModelRegistry.d.ts +200 -0
  14. package/dist/ModelRegistry.js +535 -0
  15. package/dist/NetworkMonitor.d.ts +27 -0
  16. package/dist/NetworkMonitor.js +73 -0
  17. package/dist/ObjectPool.d.ts +202 -0
  18. package/dist/ObjectPool.js +1106 -0
  19. package/dist/SyncClient.d.ts +489 -0
  20. package/dist/SyncClient.js +1555 -0
  21. package/dist/SyncEngineContext.d.ts +46 -0
  22. package/dist/SyncEngineContext.js +74 -0
  23. package/dist/adapters/alwaysOnline.d.ts +16 -0
  24. package/dist/adapters/alwaysOnline.js +19 -0
  25. package/dist/adapters/inMemoryStorage.d.ts +30 -0
  26. package/dist/adapters/inMemoryStorage.js +94 -0
  27. package/dist/agent/Agent.d.ts +358 -0
  28. package/dist/agent/Agent.js +500 -0
  29. package/dist/agent/index.d.ts +115 -0
  30. package/dist/agent/index.js +128 -0
  31. package/dist/agent/session.d.ts +90 -0
  32. package/dist/agent/session.js +156 -0
  33. package/dist/agent/types.d.ts +73 -0
  34. package/dist/agent/types.js +10 -0
  35. package/dist/ai-sdk/coordination-context.d.ts +51 -0
  36. package/dist/ai-sdk/coordination-context.js +107 -0
  37. package/dist/ai-sdk/index.d.ts +68 -0
  38. package/dist/ai-sdk/index.js +68 -0
  39. package/dist/ai-sdk/intent-broadcast.d.ts +77 -0
  40. package/dist/ai-sdk/intent-broadcast.js +72 -0
  41. package/dist/ai-sdk/wrap.d.ts +67 -0
  42. package/dist/ai-sdk/wrap.js +45 -0
  43. package/dist/api/index.d.ts +10 -0
  44. package/dist/api/index.js +9 -0
  45. package/dist/auth/index.d.ts +137 -0
  46. package/dist/auth/index.js +246 -0
  47. package/dist/client/Ablo.d.ts +835 -0
  48. package/dist/client/Ablo.js +1440 -0
  49. package/dist/client/ApiClient.d.ts +200 -0
  50. package/dist/client/ApiClient.js +659 -0
  51. package/dist/client/auth.d.ts +79 -0
  52. package/dist/client/auth.js +81 -0
  53. package/dist/client/createInternalComponents.d.ts +44 -0
  54. package/dist/client/createInternalComponents.js +88 -0
  55. package/dist/client/createModelProxy.d.ts +152 -0
  56. package/dist/client/createModelProxy.js +199 -0
  57. package/dist/client/identity.d.ts +63 -0
  58. package/dist/client/identity.js +156 -0
  59. package/dist/client/index.d.ts +36 -0
  60. package/dist/client/index.js +33 -0
  61. package/dist/client/persistence.d.ts +7 -0
  62. package/dist/client/persistence.js +11 -0
  63. package/dist/client/validateAbloOptions.d.ts +42 -0
  64. package/dist/client/validateAbloOptions.js +43 -0
  65. package/dist/config/index.d.ts +10 -0
  66. package/dist/config/index.js +12 -0
  67. package/dist/context.d.ts +27 -0
  68. package/dist/context.js +58 -0
  69. package/dist/core/DatabaseManager.d.ts +108 -0
  70. package/dist/core/DatabaseManager.js +361 -0
  71. package/dist/core/QueryProcessor.d.ts +77 -0
  72. package/dist/core/QueryProcessor.js +262 -0
  73. package/dist/core/QueryView.d.ts +64 -0
  74. package/dist/core/QueryView.js +219 -0
  75. package/dist/core/StoreManager.d.ts +131 -0
  76. package/dist/core/StoreManager.js +334 -0
  77. package/dist/core/ViewRegistry.d.ts +20 -0
  78. package/dist/core/ViewRegistry.js +55 -0
  79. package/dist/core/index.d.ts +34 -0
  80. package/dist/core/index.js +59 -0
  81. package/dist/core/openIDBWithTimeout.d.ts +27 -0
  82. package/dist/core/openIDBWithTimeout.js +63 -0
  83. package/dist/core/query-utils.d.ts +37 -0
  84. package/dist/core/query-utils.js +60 -0
  85. package/dist/errors.d.ts +235 -0
  86. package/dist/errors.js +243 -0
  87. package/dist/index.d.ts +41 -0
  88. package/dist/index.js +82 -0
  89. package/dist/interfaces/headless.d.ts +95 -0
  90. package/dist/interfaces/headless.js +41 -0
  91. package/dist/interfaces/index.d.ts +321 -0
  92. package/dist/interfaces/index.js +8 -0
  93. package/dist/mutators/RecordingTransaction.d.ts +36 -0
  94. package/dist/mutators/RecordingTransaction.js +216 -0
  95. package/dist/mutators/Transaction.d.ts +48 -0
  96. package/dist/mutators/Transaction.js +64 -0
  97. package/dist/mutators/UndoManager.d.ts +114 -0
  98. package/dist/mutators/UndoManager.js +143 -0
  99. package/dist/mutators/defineMutators.d.ts +55 -0
  100. package/dist/mutators/defineMutators.js +28 -0
  101. package/dist/policy/index.d.ts +19 -0
  102. package/dist/policy/index.js +18 -0
  103. package/dist/policy/types.d.ts +74 -0
  104. package/dist/policy/types.js +17 -0
  105. package/dist/principal.d.ts +44 -0
  106. package/dist/principal.js +49 -0
  107. package/dist/query/client.d.ts +43 -0
  108. package/dist/query/client.js +84 -0
  109. package/dist/query/index.d.ts +6 -0
  110. package/dist/query/index.js +5 -0
  111. package/dist/query/types.d.ts +143 -0
  112. package/dist/query/types.js +36 -0
  113. package/dist/react/AbloProvider.d.ts +205 -0
  114. package/dist/react/AbloProvider.js +398 -0
  115. package/dist/react/ClientSideSuspense.d.ts +36 -0
  116. package/dist/react/ClientSideSuspense.js +17 -0
  117. package/dist/react/DefaultFallback.d.ts +24 -0
  118. package/dist/react/DefaultFallback.js +43 -0
  119. package/dist/react/SyncGroupProvider.d.ts +19 -0
  120. package/dist/react/SyncGroupProvider.js +44 -0
  121. package/dist/react/context.d.ts +161 -0
  122. package/dist/react/context.js +35 -0
  123. package/dist/react/index.d.ts +64 -0
  124. package/dist/react/index.js +73 -0
  125. package/dist/react/internalContext.d.ts +35 -0
  126. package/dist/react/internalContext.js +3 -0
  127. package/dist/react/useAblo.d.ts +72 -0
  128. package/dist/react/useAblo.js +63 -0
  129. package/dist/react/useCurrentUserId.d.ts +21 -0
  130. package/dist/react/useCurrentUserId.js +33 -0
  131. package/dist/react/useErrorListener.d.ts +20 -0
  132. package/dist/react/useErrorListener.js +39 -0
  133. package/dist/react/useIntent.d.ts +29 -0
  134. package/dist/react/useIntent.js +42 -0
  135. package/dist/react/useMutate.d.ts +83 -0
  136. package/dist/react/useMutate.js +122 -0
  137. package/dist/react/useMutationFailureListener.d.ts +26 -0
  138. package/dist/react/useMutationFailureListener.js +38 -0
  139. package/dist/react/useMutators.d.ts +56 -0
  140. package/dist/react/useMutators.js +66 -0
  141. package/dist/react/usePresence.d.ts +32 -0
  142. package/dist/react/usePresence.js +41 -0
  143. package/dist/react/useQuery.d.ts +123 -0
  144. package/dist/react/useQuery.js +145 -0
  145. package/dist/react/useReactive.d.ts +35 -0
  146. package/dist/react/useReactive.js +111 -0
  147. package/dist/react/useReader.d.ts +69 -0
  148. package/dist/react/useReader.js +73 -0
  149. package/dist/react/useSyncStatus.d.ts +61 -0
  150. package/dist/react/useSyncStatus.js +76 -0
  151. package/dist/react/useUndoScope.d.ts +36 -0
  152. package/dist/react/useUndoScope.js +73 -0
  153. package/dist/realtime/index.d.ts +10 -0
  154. package/dist/realtime/index.js +9 -0
  155. package/dist/schema/field.d.ts +134 -0
  156. package/dist/schema/field.js +264 -0
  157. package/dist/schema/index.d.ts +29 -0
  158. package/dist/schema/index.js +38 -0
  159. package/dist/schema/model.d.ts +326 -0
  160. package/dist/schema/model.js +89 -0
  161. package/dist/schema/queries.d.ts +203 -0
  162. package/dist/schema/queries.js +145 -0
  163. package/dist/schema/relation.d.ts +172 -0
  164. package/dist/schema/relation.js +104 -0
  165. package/dist/schema/schema.d.ts +259 -0
  166. package/dist/schema/schema.js +188 -0
  167. package/dist/schema/sugar.d.ts +129 -0
  168. package/dist/schema/sugar.js +94 -0
  169. package/dist/source/index.d.ts +423 -0
  170. package/dist/source/index.js +320 -0
  171. package/dist/source/pushQueue.d.ts +112 -0
  172. package/dist/source/pushQueue.js +249 -0
  173. package/dist/stores/ObjectStore.d.ts +103 -0
  174. package/dist/stores/ObjectStore.js +371 -0
  175. package/dist/stores/ObjectStoreContract.d.ts +39 -0
  176. package/dist/stores/ObjectStoreContract.js +1 -0
  177. package/dist/stores/SyncActionStore.d.ts +101 -0
  178. package/dist/stores/SyncActionStore.js +481 -0
  179. package/dist/sync/BootstrapHelper.d.ts +127 -0
  180. package/dist/sync/BootstrapHelper.js +434 -0
  181. package/dist/sync/ConnectionManager.d.ts +136 -0
  182. package/dist/sync/ConnectionManager.js +465 -0
  183. package/dist/sync/HydrationCoordinator.d.ts +137 -0
  184. package/dist/sync/HydrationCoordinator.js +468 -0
  185. package/dist/sync/NetworkProbe.d.ts +43 -0
  186. package/dist/sync/NetworkProbe.js +113 -0
  187. package/dist/sync/OfflineFlush.d.ts +9 -0
  188. package/dist/sync/OfflineFlush.js +22 -0
  189. package/dist/sync/OfflineTransactionStore.d.ts +37 -0
  190. package/dist/sync/OfflineTransactionStore.js +263 -0
  191. package/dist/sync/SyncWebSocket.d.ts +663 -0
  192. package/dist/sync/SyncWebSocket.js +1336 -0
  193. package/dist/sync/createIntentStream.d.ts +33 -0
  194. package/dist/sync/createIntentStream.js +243 -0
  195. package/dist/sync/createPresenceStream.d.ts +46 -0
  196. package/dist/sync/createPresenceStream.js +192 -0
  197. package/dist/sync/createSnapshot.d.ts +33 -0
  198. package/dist/sync/createSnapshot.js +124 -0
  199. package/dist/sync/participants.d.ts +114 -0
  200. package/dist/sync/participants.js +336 -0
  201. package/dist/sync/schemas.d.ts +79 -0
  202. package/dist/sync/schemas.js +78 -0
  203. package/dist/testing/fixtures/bootstrap.d.ts +45 -0
  204. package/dist/testing/fixtures/bootstrap.js +53 -0
  205. package/dist/testing/fixtures/deltas.d.ts +86 -0
  206. package/dist/testing/fixtures/deltas.js +139 -0
  207. package/dist/testing/fixtures/models.d.ts +82 -0
  208. package/dist/testing/fixtures/models.js +270 -0
  209. package/dist/testing/helpers/react-wrapper.d.ts +66 -0
  210. package/dist/testing/helpers/react-wrapper.js +64 -0
  211. package/dist/testing/helpers/sync-engine-harness.d.ts +55 -0
  212. package/dist/testing/helpers/sync-engine-harness.js +70 -0
  213. package/dist/testing/helpers/wait.d.ts +25 -0
  214. package/dist/testing/helpers/wait.js +44 -0
  215. package/dist/testing/index.d.ts +21 -0
  216. package/dist/testing/index.js +32 -0
  217. package/dist/testing/mocks/MockMutationExecutor.d.ts +65 -0
  218. package/dist/testing/mocks/MockMutationExecutor.js +139 -0
  219. package/dist/testing/mocks/MockNetworkMonitor.d.ts +20 -0
  220. package/dist/testing/mocks/MockNetworkMonitor.js +46 -0
  221. package/dist/testing/mocks/MockSyncContext.d.ts +64 -0
  222. package/dist/testing/mocks/MockSyncContext.js +100 -0
  223. package/dist/testing/mocks/MockSyncStore.d.ts +88 -0
  224. package/dist/testing/mocks/MockSyncStore.js +171 -0
  225. package/dist/testing/mocks/MockWebSocket.d.ts +66 -0
  226. package/dist/testing/mocks/MockWebSocket.js +117 -0
  227. package/dist/transactions/OptimisticEchoTracker.d.ts +82 -0
  228. package/dist/transactions/OptimisticEchoTracker.js +104 -0
  229. package/dist/transactions/TransactionQueue.d.ts +499 -0
  230. package/dist/transactions/TransactionQueue.js +1895 -0
  231. package/dist/transactions/index.d.ts +16 -0
  232. package/dist/transactions/index.js +7 -0
  233. package/dist/transactions/mutation-error-handler.d.ts +5 -0
  234. package/dist/transactions/mutation-error-handler.js +39 -0
  235. package/dist/types/global.d.ts +107 -0
  236. package/dist/types/global.js +38 -0
  237. package/dist/types/index.d.ts +241 -0
  238. package/dist/types/index.js +70 -0
  239. package/dist/types/streams.d.ts +495 -0
  240. package/dist/types/streams.js +11 -0
  241. package/dist/utils/asyncIterator.d.ts +41 -0
  242. package/dist/utils/asyncIterator.js +142 -0
  243. package/dist/utils/duration.d.ts +28 -0
  244. package/dist/utils/duration.js +47 -0
  245. package/dist/utils/mobx-setup.d.ts +42 -0
  246. package/dist/utils/mobx-setup.js +381 -0
  247. package/docs/api-keys.md +24 -0
  248. package/docs/api.md +230 -0
  249. package/docs/audit.md +81 -0
  250. package/docs/capabilities.md +163 -0
  251. package/docs/client-behavior.md +202 -0
  252. package/docs/data-sources.md +214 -0
  253. package/docs/examples/agent-human.md +84 -0
  254. package/docs/examples/ai-sdk-tool.md +92 -0
  255. package/docs/examples/existing-python-backend.md +249 -0
  256. package/docs/examples/nextjs.md +88 -0
  257. package/docs/examples/server-agent.md +86 -0
  258. package/docs/guarantees.md +148 -0
  259. package/docs/index.md +97 -0
  260. package/docs/integration-guide.md +493 -0
  261. package/docs/interaction-model.md +140 -0
  262. package/docs/mcp/claude-code.md +43 -0
  263. package/docs/mcp/cursor.md +53 -0
  264. package/docs/mcp/windsurf.md +46 -0
  265. package/docs/mcp.md +59 -0
  266. package/docs/quickstart.md +152 -0
  267. package/docs/react.md +115 -0
  268. package/docs/roadmap.md +45 -0
  269. package/examples/README.md +54 -0
  270. package/examples/data-source/README.md +102 -0
  271. package/examples/data-source/ablo-driver.ts +89 -0
  272. package/examples/data-source/customer-server.ts +208 -0
  273. package/examples/data-source/run.ts +101 -0
  274. package/examples/data-source/schema.ts +25 -0
  275. package/examples/quickstart.ts +54 -0
  276. package/examples/tsconfig.json +16 -0
  277. package/llms.txt +143 -0
  278. package/package.json +147 -0
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Transaction types and exports (MVP)
3
+ *
4
+ * Simplified for MVP: only TransactionQueue exports
5
+ * Individual transaction classes removed in favor of simple transaction objects
6
+ */
7
+ export { TransactionQueue } from './TransactionQueue.js';
8
+ export type TransactionType = 'create' | 'update' | 'delete';
9
+ export interface Transaction {
10
+ id: string;
11
+ type: TransactionType;
12
+ modelName: string;
13
+ modelId: string;
14
+ data?: any;
15
+ createdAt: number;
16
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Transaction types and exports (MVP)
3
+ *
4
+ * Simplified for MVP: only TransactionQueue exports
5
+ * Individual transaction classes removed in favor of simple transaction objects
6
+ */
7
+ export { TransactionQueue } from './TransactionQueue.js';
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Shared error handler for mutation execution.
3
+ * Logs to SyncObservability (unless offline + network error), then re-throws.
4
+ */
5
+ export declare function handleMutationError(error: unknown, context: string, schemaName: string, modelId: string): never;
@@ -0,0 +1,39 @@
1
+ import { getContext } from "../context.js";
2
+ /**
3
+ * Shared error handler for mutation execution.
4
+ * Logs to SyncObservability (unless offline + network error), then re-throws.
5
+ */
6
+ export function handleMutationError(error, context, schemaName, modelId) {
7
+ const errorInfo = { schemaName, modelId, rawError: error };
8
+ if (error instanceof Error) {
9
+ errorInfo.message = error.message;
10
+ errorInfo.name = error.name;
11
+ errorInfo.stack =
12
+ typeof error.stack === 'string' ? error.stack.split('\n').slice(0, 5) : undefined;
13
+ }
14
+ else if (error && typeof error === 'object') {
15
+ errorInfo.message =
16
+ error.message ??
17
+ error.error ??
18
+ 'Unknown error';
19
+ errorInfo.code = error.code;
20
+ errorInfo.extensions = error.extensions;
21
+ }
22
+ else {
23
+ errorInfo.message = String(error);
24
+ }
25
+ const isOffline = !getContext().onlineStatus.isOnline();
26
+ const msg = errorInfo.message;
27
+ const isNetworkError = msg?.includes('Failed to fetch') ||
28
+ msg?.includes('Network request failed') ||
29
+ msg?.includes('NetworkError');
30
+ if (!isOffline || !isNetworkError) {
31
+ getContext().observability.captureTransactionFailure({
32
+ context,
33
+ error: error instanceof Error ? error : String(errorInfo.message ?? error),
34
+ modelName: schemaName,
35
+ modelId,
36
+ });
37
+ }
38
+ throw error;
39
+ }
@@ -0,0 +1,107 @@
1
+ /**
2
+ * Typed-global augmentation point for SDK consumers.
3
+ *
4
+ * Consumers declare their Schema, Presence, Intents, and UserMeta ONCE in a
5
+ * `.d.ts` file and every SDK hook — `useQuery`, `useOne`, `useMutate`,
6
+ * `usePresence`, `useIntent` — reads its types from the resolved global.
7
+ * No generics at call sites. No `schema` runtime arg passed per hook call.
8
+ *
9
+ * This is the same canonical TypeScript declaration-merging pattern that
10
+ * Next.js uses for `process.env` / `NodeJS.ProcessEnv`, that CSS Modules
11
+ * use for `declare module '*.module.css'`, and that Liveblocks uses for
12
+ * `interface Liveblocks`. It's a language feature, not a library trick —
13
+ * any file in the compilation can augment the global `AbloSync` interface
14
+ * and every consumer of the resolved types below picks up the augmentation
15
+ * automatically.
16
+ *
17
+ * Consumer example:
18
+ *
19
+ * ```ts
20
+ * // apps/your-app/src/ablo-sync.d.ts
21
+ * import type { schema } from './your-schema';
22
+ *
23
+ * declare global {
24
+ * interface AbloSync {
25
+ * Schema: typeof schema;
26
+ * Presence: { cursor: { x: number; y: number } | null };
27
+ * Intents: { editLayer: { layerId: string } };
28
+ * UserMeta: { id: string; email: string };
29
+ * }
30
+ * }
31
+ * export {};
32
+ * ```
33
+ *
34
+ * If `AbloSync` is never declared, every resolver falls back to the
35
+ * `DefaultSyncShape` — a loose `Record<string, unknown>` shape that keeps
36
+ * SDK consumers compiling without typed benefits until they opt in.
37
+ */
38
+ /**
39
+ * Default fallback shapes used when the consumer hasn't declared
40
+ * `interface AbloSync`. `DefaultSyncShape.Schema` is intentionally
41
+ * structural — it carries `{ models: Record<string, unknown> }` so hooks
42
+ * can still validate the model key argument against *something*, just
43
+ * without producing a typed entity shape. Once the consumer augments the
44
+ * global, every resolver below picks up the augmented types automatically.
45
+ */
46
+ export interface DefaultSyncShape {
47
+ readonly Schema: {
48
+ readonly models: Record<string, unknown>;
49
+ };
50
+ readonly Presence: Record<string, unknown>;
51
+ readonly Intents: Record<string, unknown>;
52
+ readonly UserMeta: {
53
+ readonly id: string;
54
+ };
55
+ }
56
+ declare global {
57
+ /**
58
+ * Global augmentation target. Consumers augment this via
59
+ * `declare global { interface AbloSync { Schema: ...; Presence: ...; ... } }`.
60
+ * Empty by default — every SDK resolver falls back to {@link DefaultSyncShape}
61
+ * when an expected key is absent.
62
+ */
63
+ interface AbloSync {
64
+ }
65
+ }
66
+ /**
67
+ * The consumer's schema, or the default shape if undeclared. Hooks use
68
+ * this to type their model-key argument and to infer the entity type
69
+ * returned from queries/mutations.
70
+ */
71
+ export type ResolveSchema = AbloSync extends {
72
+ Schema: infer S;
73
+ } ? S extends {
74
+ models: Record<string, unknown>;
75
+ } ? S : DefaultSyncShape['Schema'] : DefaultSyncShape['Schema'];
76
+ /**
77
+ * The consumer's presence shape, or the default shape if undeclared.
78
+ * Used by `usePresence`. The shape is free-form — any serializable JSON
79
+ * the consumer wants to broadcast per session.
80
+ */
81
+ export type ResolvePresence = AbloSync extends {
82
+ Presence: infer P;
83
+ } ? P : DefaultSyncShape['Presence'];
84
+ /**
85
+ * The consumer's intent vocabulary, or the default if undeclared. Keys
86
+ * are intent names; values are the claim payload for each intent. Used
87
+ * by `useIntent(intentName)`.
88
+ */
89
+ export type ResolveIntents = AbloSync extends {
90
+ Intents: infer I;
91
+ } ? I : DefaultSyncShape['Intents'];
92
+ /**
93
+ * The consumer's user-metadata shape, or the default if undeclared.
94
+ * Carries identity info the consumer trusts from their auth layer —
95
+ * the SDK doesn't validate this.
96
+ */
97
+ export type ResolveUserMeta = AbloSync extends {
98
+ UserMeta: infer U;
99
+ } ? U : DefaultSyncShape['UserMeta'];
100
+ /**
101
+ * The keys of the consumer's schema models. `useQuery(modelKey)` narrows
102
+ * its first argument to this union, so unknown key literals fail at
103
+ * compile time.
104
+ */
105
+ export type ResolveModelKey = ResolveSchema extends {
106
+ models: infer M;
107
+ } ? keyof M & string : string;
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Typed-global augmentation point for SDK consumers.
3
+ *
4
+ * Consumers declare their Schema, Presence, Intents, and UserMeta ONCE in a
5
+ * `.d.ts` file and every SDK hook — `useQuery`, `useOne`, `useMutate`,
6
+ * `usePresence`, `useIntent` — reads its types from the resolved global.
7
+ * No generics at call sites. No `schema` runtime arg passed per hook call.
8
+ *
9
+ * This is the same canonical TypeScript declaration-merging pattern that
10
+ * Next.js uses for `process.env` / `NodeJS.ProcessEnv`, that CSS Modules
11
+ * use for `declare module '*.module.css'`, and that Liveblocks uses for
12
+ * `interface Liveblocks`. It's a language feature, not a library trick —
13
+ * any file in the compilation can augment the global `AbloSync` interface
14
+ * and every consumer of the resolved types below picks up the augmentation
15
+ * automatically.
16
+ *
17
+ * Consumer example:
18
+ *
19
+ * ```ts
20
+ * // apps/your-app/src/ablo-sync.d.ts
21
+ * import type { schema } from './your-schema';
22
+ *
23
+ * declare global {
24
+ * interface AbloSync {
25
+ * Schema: typeof schema;
26
+ * Presence: { cursor: { x: number; y: number } | null };
27
+ * Intents: { editLayer: { layerId: string } };
28
+ * UserMeta: { id: string; email: string };
29
+ * }
30
+ * }
31
+ * export {};
32
+ * ```
33
+ *
34
+ * If `AbloSync` is never declared, every resolver falls back to the
35
+ * `DefaultSyncShape` — a loose `Record<string, unknown>` shape that keeps
36
+ * SDK consumers compiling without typed benefits until they opt in.
37
+ */
38
+ export {};
@@ -0,0 +1,241 @@
1
+ /**
2
+ * Linear Sync Engine - Core Types
3
+ *
4
+ * Foundational type definitions for the model-driven sync architecture.
5
+ * These types define how properties are tracked, loaded, and synchronized.
6
+ */
7
+ /**
8
+ * Model Scope - lifecycle filter for queries.
9
+ * Controls whether live, archived, or all entities are returned.
10
+ */
11
+ export declare enum ModelScope {
12
+ live = "live",
13
+ archived = "archived",
14
+ all = "all"
15
+ }
16
+ /**
17
+ * Property Types - EXACTLY 7 types as per Linear Sync Engine
18
+ * These define how model properties behave in the sync system
19
+ */
20
+ export declare enum PropertyType {
21
+ /** Standard observable property - owned by model, persisted and synced */
22
+ property = "property",
23
+ /** Property that doesn't persist or sync - runtime only */
24
+ ephemeralProperty = "ephemeralProperty",
25
+ /** Foreign key reference - stores ID only */
26
+ reference = "reference",
27
+ /** Lazy-loaded model reference - getter/setter for model based on ID */
28
+ referenceModel = "referenceModel",
29
+ /** Collection of related models - one-to-many relationship */
30
+ referenceCollection = "referenceCollection",
31
+ /** Back-reference computed property - inverse relationship */
32
+ backReference = "backReference",
33
+ /** Array of foreign key references - many-to-many relationship */
34
+ referenceArray = "referenceArray"
35
+ }
36
+ /**
37
+ * Load Strategies - EXACTLY 5 strategies as per Linear Sync Engine
38
+ * Controls when and how model data is loaded from the server
39
+ */
40
+ export declare enum LoadStrategy {
41
+ /** Load immediately into ObjectPool during bootstrap - for critical models */
42
+ instant = "instant",
43
+ /** Load all at once when first needed - for secondary models */
44
+ lazy = "lazy",
45
+ /** Load on demand in subsets - for large collections */
46
+ partial = "partial",
47
+ /** Only load when explicitly requested - for optional data */
48
+ explicitlyRequested = "explicitlyRequested",
49
+ /** Never sync with server, local only - for client-side state */
50
+ local = "local"
51
+ }
52
+ /**
53
+ * Property Metadata - Configuration for decorated properties
54
+ */
55
+ export interface PropertyMetadata {
56
+ type: PropertyType;
57
+ indexed?: boolean;
58
+ optional?: boolean;
59
+ nullable?: boolean;
60
+ defaultValue?: unknown;
61
+ loadStrategy?: LoadStrategy;
62
+ /**
63
+ * MobX observability annotation for this property. Controls how deeply
64
+ * MobX wraps the value when `M1` registers the model.
65
+ *
66
+ * - `'deep'` (default): full recursive observability. Every nested
67
+ * object/array becomes its own atom. Correct for scalar fields and
68
+ * small structured values where consumers subscribe to inner
69
+ * properties.
70
+ * - `'shallow'`: track the reference and array/map/set operations, but
71
+ * do NOT recurse into element internals. Right for collections whose
72
+ * elements are replaced wholesale.
73
+ * - `'ref'`: track ONLY reassignment. Right for opaque JSON blobs
74
+ * (chart specs, ProseMirror docs, style maps) that are treated as
75
+ * immutable values — consumers always read the whole blob and pass
76
+ * it to a renderer. Deep enhancement on these produces a microtask
77
+ * storm with no benefit.
78
+ *
79
+ * Schema-driven registration auto-sets this to `'ref'` for fields with
80
+ * wire type `'json'`, which is the right default for the blob pattern.
81
+ */
82
+ observability?: 'deep' | 'shallow' | 'ref';
83
+ }
84
+ /** Model constructor type for reference metadata */
85
+ type ModelConstructor = abstract new (...args: never[]) => unknown;
86
+ /**
87
+ * Reference Metadata - Configuration for reference properties
88
+ */
89
+ export interface ReferenceMetadata {
90
+ referencedModel: () => ModelConstructor;
91
+ backReference?: string;
92
+ indexed?: boolean;
93
+ nullable?: boolean;
94
+ }
95
+ /**
96
+ * Model Metadata - Configuration for model classes
97
+ */
98
+ export interface ModelMetadata {
99
+ loadStrategy: LoadStrategy;
100
+ syncGroup?: string;
101
+ tableName?: string;
102
+ partialLoadMode?: 'full' | 'regular' | 'lowPriority';
103
+ usedForPartialIndexes?: boolean;
104
+ schemaVersion?: number;
105
+ /**
106
+ * Schema-declared fields for this model, keyed by field name. Drives
107
+ * commit payload projection (filter to declared fields + stringify
108
+ * JSON-typed values) inside the transaction queue.
109
+ *
110
+ * Populated by `registerModelsFromSchema`. Each entry carries the
111
+ * sync-engine type tag (`'string' | 'number' | 'boolean' | 'date' |
112
+ * 'enum' | 'json'`), which tells the wire serializer how to handle
113
+ * the value. Missing → projection becomes identity pass-through
114
+ * (back-compat for models registered outside the schema path).
115
+ */
116
+ fields?: Readonly<Record<string, {
117
+ type: 'string' | 'number' | 'boolean' | 'date' | 'enum' | 'json';
118
+ }>>;
119
+ /**
120
+ * Fields to back-fill from the sync client identity when missing
121
+ * during IndexedDB self-healing. Populated from
122
+ * `ModelOptions.autoFill` in the schema. Each entry maps a field on
123
+ * this model to one of the identity values held by `SyncClient`
124
+ * (`organizationId` or `userId`).
125
+ *
126
+ * Used by `SyncClient.healModelRecord` to keep the engine
127
+ * product-neutral: the engine no longer hardcodes which models carry
128
+ * `organizationId` / `createdBy` — the consumer's schema declares it.
129
+ */
130
+ autoFill?: ReadonlyArray<{
131
+ field: string;
132
+ from: 'organizationId' | 'userId';
133
+ }>;
134
+ /**
135
+ * Fields whose absence makes a stored row orphaned. When healing
136
+ * encounters a record missing any of these fields, it returns `null`
137
+ * to signal the caller to skip the row. Populated from
138
+ * `ModelOptions.requiredFields` in the schema.
139
+ */
140
+ requiredFields?: readonly string[];
141
+ }
142
+ /**
143
+ * Model Options - Options for @ClientModel decorator
144
+ */
145
+ export interface ModelOptions {
146
+ loadStrategy: LoadStrategy;
147
+ syncGroup?: string;
148
+ tableName?: string;
149
+ }
150
+ /**
151
+ * Property Options - Options for @Property decorator
152
+ */
153
+ export interface PropertyOptions {
154
+ indexed?: boolean;
155
+ optional?: boolean;
156
+ defaultValue?: unknown;
157
+ ephemeral?: boolean;
158
+ }
159
+ /**
160
+ * Reference Options - Options for @Reference decorator
161
+ */
162
+ export interface ReferenceOptions {
163
+ indexed?: boolean;
164
+ nullable?: boolean;
165
+ }
166
+ /**
167
+ * GraphQL Mutation Interface
168
+ */
169
+ export interface GraphQLMutation {
170
+ mutationText: string;
171
+ variables: Record<string, unknown>;
172
+ }
173
+ /**
174
+ * Load Request Interface
175
+ */
176
+ export interface LoadRequest {
177
+ modelName: string;
178
+ indexedKey: string;
179
+ keyValue: string;
180
+ resolve?: (value: unknown[]) => void;
181
+ }
182
+ /**
183
+ * Sync Action Types - Complete Linear specification
184
+ */
185
+ export type SyncActionType = 'I' | 'U' | 'A' | 'D' | 'C' | 'G' | 'S' | 'V';
186
+ /**
187
+ * Sync Action Interface - Linear format
188
+ */
189
+ export interface SyncAction {
190
+ id: number;
191
+ modelName: string;
192
+ modelId: string;
193
+ action: SyncActionType;
194
+ data: unknown;
195
+ __class: 'SyncAction';
196
+ }
197
+ /**
198
+ * Delta Packet - Array of sync actions
199
+ */
200
+ export type DeltaPacket = SyncAction[];
201
+ /**
202
+ * Bootstrap Types
203
+ */
204
+ export type BootstrapType = 'full' | 'partial' | 'local';
205
+ /**
206
+ * Bootstrap Metadata
207
+ */
208
+ export interface BootstrapMetadata {
209
+ lastSyncId: number;
210
+ subscribedSyncGroups: string[];
211
+ }
212
+ /**
213
+ * Database Metadata - Sync engine state tracking
214
+ */
215
+ export interface DatabaseMetadata {
216
+ lastSyncId: number;
217
+ firstSyncId: number;
218
+ backendDatabaseVersion: number;
219
+ subscribedSyncGroups: string[];
220
+ updatedAt: Date;
221
+ }
222
+ /**
223
+ * Mutation operation types for batch mutations.
224
+ */
225
+ export declare enum MutationOperationType {
226
+ ARCHIVE = "ARCHIVE",
227
+ CREATE = "CREATE",
228
+ DELETE = "DELETE",
229
+ UNARCHIVE = "UNARCHIVE",
230
+ UPDATE = "UPDATE"
231
+ }
232
+ /**
233
+ * Partial Index Information - For complex querying
234
+ */
235
+ export interface PartialIndexInfo {
236
+ modelName: string;
237
+ indexKey: string;
238
+ depth: number;
239
+ path: string[];
240
+ }
241
+ export * from "./streams.js";
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Linear Sync Engine - Core Types
3
+ *
4
+ * Foundational type definitions for the model-driven sync architecture.
5
+ * These types define how properties are tracked, loaded, and synchronized.
6
+ */
7
+ /**
8
+ * Model Scope - lifecycle filter for queries.
9
+ * Controls whether live, archived, or all entities are returned.
10
+ */
11
+ export var ModelScope;
12
+ (function (ModelScope) {
13
+ ModelScope["live"] = "live";
14
+ ModelScope["archived"] = "archived";
15
+ ModelScope["all"] = "all";
16
+ })(ModelScope || (ModelScope = {}));
17
+ /**
18
+ * Property Types - EXACTLY 7 types as per Linear Sync Engine
19
+ * These define how model properties behave in the sync system
20
+ */
21
+ export var PropertyType;
22
+ (function (PropertyType) {
23
+ /** Standard observable property - owned by model, persisted and synced */
24
+ PropertyType["property"] = "property";
25
+ /** Property that doesn't persist or sync - runtime only */
26
+ PropertyType["ephemeralProperty"] = "ephemeralProperty";
27
+ /** Foreign key reference - stores ID only */
28
+ PropertyType["reference"] = "reference";
29
+ /** Lazy-loaded model reference - getter/setter for model based on ID */
30
+ PropertyType["referenceModel"] = "referenceModel";
31
+ /** Collection of related models - one-to-many relationship */
32
+ PropertyType["referenceCollection"] = "referenceCollection";
33
+ /** Back-reference computed property - inverse relationship */
34
+ PropertyType["backReference"] = "backReference";
35
+ /** Array of foreign key references - many-to-many relationship */
36
+ PropertyType["referenceArray"] = "referenceArray";
37
+ })(PropertyType || (PropertyType = {}));
38
+ /**
39
+ * Load Strategies - EXACTLY 5 strategies as per Linear Sync Engine
40
+ * Controls when and how model data is loaded from the server
41
+ */
42
+ export var LoadStrategy;
43
+ (function (LoadStrategy) {
44
+ /** Load immediately into ObjectPool during bootstrap - for critical models */
45
+ LoadStrategy["instant"] = "instant";
46
+ /** Load all at once when first needed - for secondary models */
47
+ LoadStrategy["lazy"] = "lazy";
48
+ /** Load on demand in subsets - for large collections */
49
+ LoadStrategy["partial"] = "partial";
50
+ /** Only load when explicitly requested - for optional data */
51
+ LoadStrategy["explicitlyRequested"] = "explicitlyRequested";
52
+ /** Never sync with server, local only - for client-side state */
53
+ LoadStrategy["local"] = "local";
54
+ })(LoadStrategy || (LoadStrategy = {}));
55
+ /**
56
+ * Mutation operation types for batch mutations.
57
+ */
58
+ export var MutationOperationType;
59
+ (function (MutationOperationType) {
60
+ MutationOperationType["ARCHIVE"] = "ARCHIVE";
61
+ MutationOperationType["CREATE"] = "CREATE";
62
+ MutationOperationType["DELETE"] = "DELETE";
63
+ MutationOperationType["UNARCHIVE"] = "UNARCHIVE";
64
+ MutationOperationType["UPDATE"] = "UPDATE";
65
+ })(MutationOperationType || (MutationOperationType = {}));
66
+ // Re-export stream + snapshot + principal types for the engine surface
67
+ // (PresenceStream,
68
+ // IntentStream, Snapshot, etc.) consumed by `Ablo({...}).presence`,
69
+ // `.intents`, `.snapshot()`.
70
+ export * from "./streams.js";