@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.
- package/CHANGELOG.md +208 -0
- package/LICENSE +201 -0
- package/NOTICE +12 -0
- package/README.md +230 -0
- package/dist/BaseSyncedStore.d.ts +709 -0
- package/dist/BaseSyncedStore.js +1843 -0
- package/dist/Database.d.ts +344 -0
- package/dist/Database.js +1259 -0
- package/dist/LazyReferenceCollection.d.ts +181 -0
- package/dist/LazyReferenceCollection.js +460 -0
- package/dist/Model.d.ts +339 -0
- package/dist/Model.js +715 -0
- package/dist/ModelRegistry.d.ts +200 -0
- package/dist/ModelRegistry.js +535 -0
- package/dist/NetworkMonitor.d.ts +27 -0
- package/dist/NetworkMonitor.js +73 -0
- package/dist/ObjectPool.d.ts +202 -0
- package/dist/ObjectPool.js +1106 -0
- package/dist/SyncClient.d.ts +489 -0
- package/dist/SyncClient.js +1555 -0
- package/dist/SyncEngineContext.d.ts +46 -0
- package/dist/SyncEngineContext.js +74 -0
- package/dist/adapters/alwaysOnline.d.ts +16 -0
- package/dist/adapters/alwaysOnline.js +19 -0
- package/dist/adapters/inMemoryStorage.d.ts +30 -0
- package/dist/adapters/inMemoryStorage.js +94 -0
- package/dist/agent/Agent.d.ts +358 -0
- package/dist/agent/Agent.js +500 -0
- package/dist/agent/index.d.ts +115 -0
- package/dist/agent/index.js +128 -0
- package/dist/agent/session.d.ts +90 -0
- package/dist/agent/session.js +156 -0
- package/dist/agent/types.d.ts +73 -0
- package/dist/agent/types.js +10 -0
- package/dist/ai-sdk/coordination-context.d.ts +51 -0
- package/dist/ai-sdk/coordination-context.js +107 -0
- package/dist/ai-sdk/index.d.ts +68 -0
- package/dist/ai-sdk/index.js +68 -0
- package/dist/ai-sdk/intent-broadcast.d.ts +77 -0
- package/dist/ai-sdk/intent-broadcast.js +72 -0
- package/dist/ai-sdk/wrap.d.ts +67 -0
- package/dist/ai-sdk/wrap.js +45 -0
- package/dist/api/index.d.ts +10 -0
- package/dist/api/index.js +9 -0
- package/dist/auth/index.d.ts +137 -0
- package/dist/auth/index.js +246 -0
- package/dist/client/Ablo.d.ts +835 -0
- package/dist/client/Ablo.js +1440 -0
- package/dist/client/ApiClient.d.ts +200 -0
- package/dist/client/ApiClient.js +659 -0
- package/dist/client/auth.d.ts +79 -0
- package/dist/client/auth.js +81 -0
- package/dist/client/createInternalComponents.d.ts +44 -0
- package/dist/client/createInternalComponents.js +88 -0
- package/dist/client/createModelProxy.d.ts +152 -0
- package/dist/client/createModelProxy.js +199 -0
- package/dist/client/identity.d.ts +63 -0
- package/dist/client/identity.js +156 -0
- package/dist/client/index.d.ts +36 -0
- package/dist/client/index.js +33 -0
- package/dist/client/persistence.d.ts +7 -0
- package/dist/client/persistence.js +11 -0
- package/dist/client/validateAbloOptions.d.ts +42 -0
- package/dist/client/validateAbloOptions.js +43 -0
- package/dist/config/index.d.ts +10 -0
- package/dist/config/index.js +12 -0
- package/dist/context.d.ts +27 -0
- package/dist/context.js +58 -0
- package/dist/core/DatabaseManager.d.ts +108 -0
- package/dist/core/DatabaseManager.js +361 -0
- package/dist/core/QueryProcessor.d.ts +77 -0
- package/dist/core/QueryProcessor.js +262 -0
- package/dist/core/QueryView.d.ts +64 -0
- package/dist/core/QueryView.js +219 -0
- package/dist/core/StoreManager.d.ts +131 -0
- package/dist/core/StoreManager.js +334 -0
- package/dist/core/ViewRegistry.d.ts +20 -0
- package/dist/core/ViewRegistry.js +55 -0
- package/dist/core/index.d.ts +34 -0
- package/dist/core/index.js +59 -0
- package/dist/core/openIDBWithTimeout.d.ts +27 -0
- package/dist/core/openIDBWithTimeout.js +63 -0
- package/dist/core/query-utils.d.ts +37 -0
- package/dist/core/query-utils.js +60 -0
- package/dist/errors.d.ts +235 -0
- package/dist/errors.js +243 -0
- package/dist/index.d.ts +41 -0
- package/dist/index.js +82 -0
- package/dist/interfaces/headless.d.ts +95 -0
- package/dist/interfaces/headless.js +41 -0
- package/dist/interfaces/index.d.ts +321 -0
- package/dist/interfaces/index.js +8 -0
- package/dist/mutators/RecordingTransaction.d.ts +36 -0
- package/dist/mutators/RecordingTransaction.js +216 -0
- package/dist/mutators/Transaction.d.ts +48 -0
- package/dist/mutators/Transaction.js +64 -0
- package/dist/mutators/UndoManager.d.ts +114 -0
- package/dist/mutators/UndoManager.js +143 -0
- package/dist/mutators/defineMutators.d.ts +55 -0
- package/dist/mutators/defineMutators.js +28 -0
- package/dist/policy/index.d.ts +19 -0
- package/dist/policy/index.js +18 -0
- package/dist/policy/types.d.ts +74 -0
- package/dist/policy/types.js +17 -0
- package/dist/principal.d.ts +44 -0
- package/dist/principal.js +49 -0
- package/dist/query/client.d.ts +43 -0
- package/dist/query/client.js +84 -0
- package/dist/query/index.d.ts +6 -0
- package/dist/query/index.js +5 -0
- package/dist/query/types.d.ts +143 -0
- package/dist/query/types.js +36 -0
- package/dist/react/AbloProvider.d.ts +205 -0
- package/dist/react/AbloProvider.js +398 -0
- package/dist/react/ClientSideSuspense.d.ts +36 -0
- package/dist/react/ClientSideSuspense.js +17 -0
- package/dist/react/DefaultFallback.d.ts +24 -0
- package/dist/react/DefaultFallback.js +43 -0
- package/dist/react/SyncGroupProvider.d.ts +19 -0
- package/dist/react/SyncGroupProvider.js +44 -0
- package/dist/react/context.d.ts +161 -0
- package/dist/react/context.js +35 -0
- package/dist/react/index.d.ts +64 -0
- package/dist/react/index.js +73 -0
- package/dist/react/internalContext.d.ts +35 -0
- package/dist/react/internalContext.js +3 -0
- package/dist/react/useAblo.d.ts +72 -0
- package/dist/react/useAblo.js +63 -0
- package/dist/react/useCurrentUserId.d.ts +21 -0
- package/dist/react/useCurrentUserId.js +33 -0
- package/dist/react/useErrorListener.d.ts +20 -0
- package/dist/react/useErrorListener.js +39 -0
- package/dist/react/useIntent.d.ts +29 -0
- package/dist/react/useIntent.js +42 -0
- package/dist/react/useMutate.d.ts +83 -0
- package/dist/react/useMutate.js +122 -0
- package/dist/react/useMutationFailureListener.d.ts +26 -0
- package/dist/react/useMutationFailureListener.js +38 -0
- package/dist/react/useMutators.d.ts +56 -0
- package/dist/react/useMutators.js +66 -0
- package/dist/react/usePresence.d.ts +32 -0
- package/dist/react/usePresence.js +41 -0
- package/dist/react/useQuery.d.ts +123 -0
- package/dist/react/useQuery.js +145 -0
- package/dist/react/useReactive.d.ts +35 -0
- package/dist/react/useReactive.js +111 -0
- package/dist/react/useReader.d.ts +69 -0
- package/dist/react/useReader.js +73 -0
- package/dist/react/useSyncStatus.d.ts +61 -0
- package/dist/react/useSyncStatus.js +76 -0
- package/dist/react/useUndoScope.d.ts +36 -0
- package/dist/react/useUndoScope.js +73 -0
- package/dist/realtime/index.d.ts +10 -0
- package/dist/realtime/index.js +9 -0
- package/dist/schema/field.d.ts +134 -0
- package/dist/schema/field.js +264 -0
- package/dist/schema/index.d.ts +29 -0
- package/dist/schema/index.js +38 -0
- package/dist/schema/model.d.ts +326 -0
- package/dist/schema/model.js +89 -0
- package/dist/schema/queries.d.ts +203 -0
- package/dist/schema/queries.js +145 -0
- package/dist/schema/relation.d.ts +172 -0
- package/dist/schema/relation.js +104 -0
- package/dist/schema/schema.d.ts +259 -0
- package/dist/schema/schema.js +188 -0
- package/dist/schema/sugar.d.ts +129 -0
- package/dist/schema/sugar.js +94 -0
- package/dist/source/index.d.ts +423 -0
- package/dist/source/index.js +320 -0
- package/dist/source/pushQueue.d.ts +112 -0
- package/dist/source/pushQueue.js +249 -0
- package/dist/stores/ObjectStore.d.ts +103 -0
- package/dist/stores/ObjectStore.js +371 -0
- package/dist/stores/ObjectStoreContract.d.ts +39 -0
- package/dist/stores/ObjectStoreContract.js +1 -0
- package/dist/stores/SyncActionStore.d.ts +101 -0
- package/dist/stores/SyncActionStore.js +481 -0
- package/dist/sync/BootstrapHelper.d.ts +127 -0
- package/dist/sync/BootstrapHelper.js +434 -0
- package/dist/sync/ConnectionManager.d.ts +136 -0
- package/dist/sync/ConnectionManager.js +465 -0
- package/dist/sync/HydrationCoordinator.d.ts +137 -0
- package/dist/sync/HydrationCoordinator.js +468 -0
- package/dist/sync/NetworkProbe.d.ts +43 -0
- package/dist/sync/NetworkProbe.js +113 -0
- package/dist/sync/OfflineFlush.d.ts +9 -0
- package/dist/sync/OfflineFlush.js +22 -0
- package/dist/sync/OfflineTransactionStore.d.ts +37 -0
- package/dist/sync/OfflineTransactionStore.js +263 -0
- package/dist/sync/SyncWebSocket.d.ts +663 -0
- package/dist/sync/SyncWebSocket.js +1336 -0
- package/dist/sync/createIntentStream.d.ts +33 -0
- package/dist/sync/createIntentStream.js +243 -0
- package/dist/sync/createPresenceStream.d.ts +46 -0
- package/dist/sync/createPresenceStream.js +192 -0
- package/dist/sync/createSnapshot.d.ts +33 -0
- package/dist/sync/createSnapshot.js +124 -0
- package/dist/sync/participants.d.ts +114 -0
- package/dist/sync/participants.js +336 -0
- package/dist/sync/schemas.d.ts +79 -0
- package/dist/sync/schemas.js +78 -0
- package/dist/testing/fixtures/bootstrap.d.ts +45 -0
- package/dist/testing/fixtures/bootstrap.js +53 -0
- package/dist/testing/fixtures/deltas.d.ts +86 -0
- package/dist/testing/fixtures/deltas.js +139 -0
- package/dist/testing/fixtures/models.d.ts +82 -0
- package/dist/testing/fixtures/models.js +270 -0
- package/dist/testing/helpers/react-wrapper.d.ts +66 -0
- package/dist/testing/helpers/react-wrapper.js +64 -0
- package/dist/testing/helpers/sync-engine-harness.d.ts +55 -0
- package/dist/testing/helpers/sync-engine-harness.js +70 -0
- package/dist/testing/helpers/wait.d.ts +25 -0
- package/dist/testing/helpers/wait.js +44 -0
- package/dist/testing/index.d.ts +21 -0
- package/dist/testing/index.js +32 -0
- package/dist/testing/mocks/MockMutationExecutor.d.ts +65 -0
- package/dist/testing/mocks/MockMutationExecutor.js +139 -0
- package/dist/testing/mocks/MockNetworkMonitor.d.ts +20 -0
- package/dist/testing/mocks/MockNetworkMonitor.js +46 -0
- package/dist/testing/mocks/MockSyncContext.d.ts +64 -0
- package/dist/testing/mocks/MockSyncContext.js +100 -0
- package/dist/testing/mocks/MockSyncStore.d.ts +88 -0
- package/dist/testing/mocks/MockSyncStore.js +171 -0
- package/dist/testing/mocks/MockWebSocket.d.ts +66 -0
- package/dist/testing/mocks/MockWebSocket.js +117 -0
- package/dist/transactions/OptimisticEchoTracker.d.ts +82 -0
- package/dist/transactions/OptimisticEchoTracker.js +104 -0
- package/dist/transactions/TransactionQueue.d.ts +499 -0
- package/dist/transactions/TransactionQueue.js +1895 -0
- package/dist/transactions/index.d.ts +16 -0
- package/dist/transactions/index.js +7 -0
- package/dist/transactions/mutation-error-handler.d.ts +5 -0
- package/dist/transactions/mutation-error-handler.js +39 -0
- package/dist/types/global.d.ts +107 -0
- package/dist/types/global.js +38 -0
- package/dist/types/index.d.ts +241 -0
- package/dist/types/index.js +70 -0
- package/dist/types/streams.d.ts +495 -0
- package/dist/types/streams.js +11 -0
- package/dist/utils/asyncIterator.d.ts +41 -0
- package/dist/utils/asyncIterator.js +142 -0
- package/dist/utils/duration.d.ts +28 -0
- package/dist/utils/duration.js +47 -0
- package/dist/utils/mobx-setup.d.ts +42 -0
- package/dist/utils/mobx-setup.js +381 -0
- package/docs/api-keys.md +24 -0
- package/docs/api.md +230 -0
- package/docs/audit.md +81 -0
- package/docs/capabilities.md +163 -0
- package/docs/client-behavior.md +202 -0
- package/docs/data-sources.md +214 -0
- package/docs/examples/agent-human.md +84 -0
- package/docs/examples/ai-sdk-tool.md +92 -0
- package/docs/examples/existing-python-backend.md +249 -0
- package/docs/examples/nextjs.md +88 -0
- package/docs/examples/server-agent.md +86 -0
- package/docs/guarantees.md +148 -0
- package/docs/index.md +97 -0
- package/docs/integration-guide.md +493 -0
- package/docs/interaction-model.md +140 -0
- package/docs/mcp/claude-code.md +43 -0
- package/docs/mcp/cursor.md +53 -0
- package/docs/mcp/windsurf.md +46 -0
- package/docs/mcp.md +59 -0
- package/docs/quickstart.md +152 -0
- package/docs/react.md +115 -0
- package/docs/roadmap.md +45 -0
- package/examples/README.md +54 -0
- package/examples/data-source/README.md +102 -0
- package/examples/data-source/ablo-driver.ts +89 -0
- package/examples/data-source/customer-server.ts +208 -0
- package/examples/data-source/run.ts +101 -0
- package/examples/data-source/schema.ts +25 -0
- package/examples/quickstart.ts +54 -0
- package/examples/tsconfig.json +16 -0
- package/llms.txt +143 -0
- package/package.json +147 -0
package/dist/Model.d.ts
ADDED
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model - Clean base class for domain models
|
|
3
|
+
*
|
|
4
|
+
* Models are pure domain objects that:
|
|
5
|
+
* - Hold data and business logic
|
|
6
|
+
* - Track their own changes
|
|
7
|
+
* - Validate themselves
|
|
8
|
+
* - Return updates/changes (not perform them)
|
|
9
|
+
*
|
|
10
|
+
* Models do NOT:
|
|
11
|
+
* - Access stores or singletons
|
|
12
|
+
* - Perform side effects (saving, notifications)
|
|
13
|
+
* - Know about sync infrastructure
|
|
14
|
+
*/
|
|
15
|
+
/** Store interface — methods that Model subclasses can call on the store */
|
|
16
|
+
interface SyncStoreRef {
|
|
17
|
+
getByForeignKey<T extends Model>(modelName: string, foreignKey: string, id: string): T[];
|
|
18
|
+
retrieve<T extends Model>(modelClass: abstract new (...args: never[]) => T, id: string): T | undefined;
|
|
19
|
+
/** Lookup a model by ID alone. Returns the pool entry regardless of type. */
|
|
20
|
+
getById(id: string): Model | undefined;
|
|
21
|
+
/** Persist a model (upsert). */
|
|
22
|
+
save(model: Model): Promise<void>;
|
|
23
|
+
/** Delete a model. */
|
|
24
|
+
delete(model: Model): Promise<void>;
|
|
25
|
+
/** Archive a model (soft delete). */
|
|
26
|
+
archive(model: Model): Promise<void>;
|
|
27
|
+
/** Unarchive a previously archived model. */
|
|
28
|
+
unarchive(model: Model): Promise<void>;
|
|
29
|
+
}
|
|
30
|
+
/** Model data type - allows any object with string keys.
|
|
31
|
+
* Mirrors `ModelData` exported from BaseSyncedStore — kept local to
|
|
32
|
+
* break the import cycle between Model and BaseSyncedStore. */
|
|
33
|
+
type ModelData = Record<string, unknown>;
|
|
34
|
+
/** Represents a property value change with old and new values */
|
|
35
|
+
export interface PropertyChange {
|
|
36
|
+
old: unknown;
|
|
37
|
+
new: unknown;
|
|
38
|
+
}
|
|
39
|
+
/** Validation rule function that returns error string or null if valid */
|
|
40
|
+
type ValidationRule = (value: unknown) => string | null;
|
|
41
|
+
/** Interface for objects that can be disposed */
|
|
42
|
+
interface Disposable {
|
|
43
|
+
dispose(): void;
|
|
44
|
+
}
|
|
45
|
+
/** Field change information for activity tracking */
|
|
46
|
+
interface FieldChange {
|
|
47
|
+
field: string;
|
|
48
|
+
oldValue: unknown;
|
|
49
|
+
newValue: unknown;
|
|
50
|
+
fieldType: string;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Validation error for model validation failures
|
|
54
|
+
*/
|
|
55
|
+
export declare class ValidationError extends Error {
|
|
56
|
+
errors: string[];
|
|
57
|
+
constructor(errors: string[]);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Model changes for external processing
|
|
61
|
+
*/
|
|
62
|
+
export interface ModelChanges {
|
|
63
|
+
type: 'create' | 'update' | 'delete' | 'archive' | 'unarchive';
|
|
64
|
+
modelName: string;
|
|
65
|
+
modelId: string;
|
|
66
|
+
changes?: Map<string, PropertyChange>;
|
|
67
|
+
timestamp: Date;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Abstract Model - Base class for all domain models
|
|
71
|
+
*
|
|
72
|
+
* Pure domain object with no external dependencies
|
|
73
|
+
*/
|
|
74
|
+
export declare abstract class Model {
|
|
75
|
+
/** Static reference to active SyncedStore for reactive queries */
|
|
76
|
+
private static store;
|
|
77
|
+
/** Unique identifier - always permanent UUID */
|
|
78
|
+
id: string;
|
|
79
|
+
/** Client ID - always equals id, kept for compatibility */
|
|
80
|
+
clientId: string;
|
|
81
|
+
/** MobX observable properties storage */
|
|
82
|
+
_mobxProperties: ModelData;
|
|
83
|
+
/** Referenced models cache */
|
|
84
|
+
_referencedModels: Record<string, Model | null>;
|
|
85
|
+
/** Track property changes */
|
|
86
|
+
modifiedProperties: Map<string, PropertyChange>;
|
|
87
|
+
/** Track if this is a new model */
|
|
88
|
+
private _isNew;
|
|
89
|
+
/** Original data snapshot */
|
|
90
|
+
private _originalData?;
|
|
91
|
+
/** Sync status */
|
|
92
|
+
syncStatus: 'pending' | 'syncing' | 'synced';
|
|
93
|
+
/** Timestamps */
|
|
94
|
+
createdAt?: Date;
|
|
95
|
+
updatedAt?: Date;
|
|
96
|
+
archivedAt?: Date | null;
|
|
97
|
+
/** Validation rules */
|
|
98
|
+
protected validationRules: Record<string, ValidationRule[]>;
|
|
99
|
+
/** Lifecycle state */
|
|
100
|
+
private isDisposed;
|
|
101
|
+
private disposers;
|
|
102
|
+
/**
|
|
103
|
+
* Track observed LazyReferenceCollections for GC prevention
|
|
104
|
+
* When any collection is being observed by React, the model should not be GC'd
|
|
105
|
+
* Following MobX best practice: https://mobx.js.org/lazy-observables.html
|
|
106
|
+
*/
|
|
107
|
+
private _observedCollections;
|
|
108
|
+
constructor(data?: Partial<Model>);
|
|
109
|
+
/**
|
|
110
|
+
* Generate unique ID
|
|
111
|
+
*/
|
|
112
|
+
static generateId(): string;
|
|
113
|
+
/**
|
|
114
|
+
* Set the active SyncedStore reference for reactive queries.
|
|
115
|
+
* Called once at engine initialization.
|
|
116
|
+
*/
|
|
117
|
+
static setStore(store: SyncStoreRef): void;
|
|
118
|
+
/**
|
|
119
|
+
* Get the active SyncedStore reference for reactive queries.
|
|
120
|
+
*
|
|
121
|
+
* Returns `null` if no store has been registered yet (e.g. during
|
|
122
|
+
* bootstrap before the engine is ready). Subclasses should use this
|
|
123
|
+
* instead of reaching into the private static field via bracket
|
|
124
|
+
* notation — the generic parameter lets app-side Model subclasses
|
|
125
|
+
* narrow the return to their concrete store type.
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* // In a Slide model getter
|
|
129
|
+
* const store = Slide.getStore();
|
|
130
|
+
* if (!store) return [];
|
|
131
|
+
* return store.getByForeignKey<SlideLayer>('SlideLayer', 'slideId', this.id);
|
|
132
|
+
*/
|
|
133
|
+
static getStore<T extends SyncStoreRef = SyncStoreRef>(): T | null;
|
|
134
|
+
/**
|
|
135
|
+
* Initialize MobX observability
|
|
136
|
+
*/
|
|
137
|
+
makeObservable(): void;
|
|
138
|
+
/**
|
|
139
|
+
* Track property changes
|
|
140
|
+
*/
|
|
141
|
+
propertyChanged(propertyName: string, oldValue: unknown, newValue: unknown): void;
|
|
142
|
+
/**
|
|
143
|
+
* Get changes as object
|
|
144
|
+
*/
|
|
145
|
+
getChanges(): ModelData;
|
|
146
|
+
/**
|
|
147
|
+
* Check if model has changes
|
|
148
|
+
*/
|
|
149
|
+
get hasChanges(): boolean;
|
|
150
|
+
/**
|
|
151
|
+
* Mark model as persisted (not new)
|
|
152
|
+
*/
|
|
153
|
+
markAsPersisted(): void;
|
|
154
|
+
/**
|
|
155
|
+
* Check if this is a new model
|
|
156
|
+
*/
|
|
157
|
+
isNew(): boolean;
|
|
158
|
+
/**
|
|
159
|
+
* Read-only view of the snapshot taken at `markAsPersisted()` /
|
|
160
|
+
* load. Used by recording-transaction undo to derive a pre-session
|
|
161
|
+
* baseline for fields that weren't yet pre-mutated (so
|
|
162
|
+
* `modifiedProperties` has no entry for them). Returns the same
|
|
163
|
+
* underlying object — callers must not mutate it.
|
|
164
|
+
*
|
|
165
|
+
* Architectural note: this method exists because we allow direct
|
|
166
|
+
* property writes (`slide.title = 'foo'`) AND mutator-recorded
|
|
167
|
+
* writes to coexist. Zero / Replicache structurally avoids this:
|
|
168
|
+
* every mutation MUST go through a registered mutator function,
|
|
169
|
+
* mutator args are serialized, and on server pull all unacked
|
|
170
|
+
* mutations are dropped and the mutator functions are replayed on
|
|
171
|
+
* the new basis (rebase). That makes per-instance baselines
|
|
172
|
+
* unnecessary because the b-tree at the new basis IS the
|
|
173
|
+
* authoritative pre-session state.
|
|
174
|
+
*
|
|
175
|
+
* If we ever migrate to "mutators are the only write path," this
|
|
176
|
+
* snapshot field, `_originalData`, and most of
|
|
177
|
+
* `RecordingTransaction.snapshotFields` become dead code. See
|
|
178
|
+
* `packages/replicache/src/db/rebase.ts` (rocicorp/mono) for the
|
|
179
|
+
* pattern.
|
|
180
|
+
*/
|
|
181
|
+
getOriginalSnapshot(): Readonly<ModelData> | undefined;
|
|
182
|
+
/**
|
|
183
|
+
* Clear tracked changes
|
|
184
|
+
*/
|
|
185
|
+
clearChanges(): void;
|
|
186
|
+
/**
|
|
187
|
+
* Validate model
|
|
188
|
+
*/
|
|
189
|
+
validate(): string[];
|
|
190
|
+
/**
|
|
191
|
+
* Override for custom validation
|
|
192
|
+
*/
|
|
193
|
+
protected customValidate(): string[];
|
|
194
|
+
/**
|
|
195
|
+
* Add validation rule
|
|
196
|
+
*/
|
|
197
|
+
protected addValidationRule(propName: string, rule: ValidationRule): void;
|
|
198
|
+
/**
|
|
199
|
+
* Prepare save operation
|
|
200
|
+
* Returns the changes to be saved without side effects
|
|
201
|
+
*/
|
|
202
|
+
prepareSave(): ModelChanges | null;
|
|
203
|
+
/**
|
|
204
|
+
* Prepare delete operation
|
|
205
|
+
*/
|
|
206
|
+
prepareDelete(): ModelChanges;
|
|
207
|
+
/**
|
|
208
|
+
* Prepare archive operation
|
|
209
|
+
*/
|
|
210
|
+
prepareArchive(): ModelChanges;
|
|
211
|
+
/**
|
|
212
|
+
* Prepare unarchive operation
|
|
213
|
+
*/
|
|
214
|
+
prepareUnarchive(): ModelChanges;
|
|
215
|
+
/**
|
|
216
|
+
* Update from raw data (hydration)
|
|
217
|
+
*/
|
|
218
|
+
updateFromData(data: ModelData): void;
|
|
219
|
+
/**
|
|
220
|
+
* Serialize to JSON
|
|
221
|
+
* This method should not trigger MobX reactions since it's used for serialization
|
|
222
|
+
* Returns Record<string, any> to allow subclass specialization with more specific return types
|
|
223
|
+
*/
|
|
224
|
+
toJSON(): Record<string, any>;
|
|
225
|
+
/**
|
|
226
|
+
* Clone this model
|
|
227
|
+
*/
|
|
228
|
+
clone(): this;
|
|
229
|
+
getModelName(): string;
|
|
230
|
+
/**
|
|
231
|
+
* Read a field value by name. Runtime-safe dynamic field access —
|
|
232
|
+
* schema-generated models store all declared fields as instance properties.
|
|
233
|
+
* Use this for generic code (sort comparators, filter predicates that work
|
|
234
|
+
* across model types) that reads fields by name string.
|
|
235
|
+
*/
|
|
236
|
+
getField(name: string): unknown;
|
|
237
|
+
/**
|
|
238
|
+
* Check equality
|
|
239
|
+
*/
|
|
240
|
+
equals(other: Model): boolean;
|
|
241
|
+
/**
|
|
242
|
+
* String representation
|
|
243
|
+
*/
|
|
244
|
+
toString(): string;
|
|
245
|
+
/**
|
|
246
|
+
* Register a LazyReferenceCollection as being observed
|
|
247
|
+
* Called by LazyReferenceCollection when onBecomeObserved fires
|
|
248
|
+
*/
|
|
249
|
+
_registerObservedCollection(collection: Disposable): void;
|
|
250
|
+
/**
|
|
251
|
+
* Unregister a LazyReferenceCollection that's no longer observed
|
|
252
|
+
* Called by LazyReferenceCollection when onBecomeUnobserved fires
|
|
253
|
+
*/
|
|
254
|
+
_unregisterObservedCollection(collection: Disposable): void;
|
|
255
|
+
/**
|
|
256
|
+
* Check if any collection on this model is currently being observed by React
|
|
257
|
+
* Used by ObjectPool GC to prevent disposing models in active use
|
|
258
|
+
*/
|
|
259
|
+
hasObservedCollections(): boolean;
|
|
260
|
+
/**
|
|
261
|
+
* Get count of observed collections (for debugging)
|
|
262
|
+
*/
|
|
263
|
+
get observedCollectionCount(): number;
|
|
264
|
+
/**
|
|
265
|
+
* Dispose model
|
|
266
|
+
*/
|
|
267
|
+
dispose(): void;
|
|
268
|
+
/**
|
|
269
|
+
* Check if disposed
|
|
270
|
+
*/
|
|
271
|
+
get disposed(): boolean;
|
|
272
|
+
/**
|
|
273
|
+
* Lifecycle hooks - override in subclasses
|
|
274
|
+
*/
|
|
275
|
+
protected didUpdate(): void;
|
|
276
|
+
protected willDelete(): void;
|
|
277
|
+
/**
|
|
278
|
+
* Capture snapshot for change detection
|
|
279
|
+
*/
|
|
280
|
+
protected captureSnapshot(): ModelData;
|
|
281
|
+
/**
|
|
282
|
+
* Get field changes for activity tracking
|
|
283
|
+
*/
|
|
284
|
+
getFieldChanges(): FieldChange[];
|
|
285
|
+
private getFieldType;
|
|
286
|
+
/**
|
|
287
|
+
* Create model from JSON
|
|
288
|
+
*/
|
|
289
|
+
static fromJSON(data: ModelData & {
|
|
290
|
+
__typename?: string;
|
|
291
|
+
__class?: string;
|
|
292
|
+
modelName?: string;
|
|
293
|
+
}): Model;
|
|
294
|
+
/**
|
|
295
|
+
* Get sync status
|
|
296
|
+
*/
|
|
297
|
+
getSyncStatus(): 'pending' | 'syncing' | 'synced';
|
|
298
|
+
/**
|
|
299
|
+
* Mark model as synced
|
|
300
|
+
*/
|
|
301
|
+
markAsSynced(): void;
|
|
302
|
+
/**
|
|
303
|
+
* Mark model as pending sync
|
|
304
|
+
*/
|
|
305
|
+
markAsPending(): void;
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Project a dynamic-class `Model` instance to the schema row shape `T`.
|
|
309
|
+
*
|
|
310
|
+
* The runtime invariant: `createDynamicModelClass(...)` attaches every
|
|
311
|
+
* field of `T` directly onto the Model prototype/instance via
|
|
312
|
+
* `Object.defineProperty` and the M1 observable bridge, so a Model
|
|
313
|
+
* instance structurally satisfies `T` at runtime. The static type
|
|
314
|
+
* system can't see this because `T` is a free generic — there's no
|
|
315
|
+
* common ancestor between `Model` (base class) and the schema row
|
|
316
|
+
* interface produced by `defineSchema`.
|
|
317
|
+
*
|
|
318
|
+
* This is a typed boundary, not a bypass: every call site is the
|
|
319
|
+
* dynamic-class duality where Model-with-extras-and-T-fields is being
|
|
320
|
+
* returned to a consumer that only sees `T`. Concentrating the cast
|
|
321
|
+
* here means there's one place to look when the boundary changes.
|
|
322
|
+
*/
|
|
323
|
+
export declare function modelAsRow<T>(model: Model): T;
|
|
324
|
+
/**
|
|
325
|
+
* Inverse of `modelAsRow`: accept a row-shaped value (schema-derived
|
|
326
|
+
* `T` with at minimum an `id`) and surface it as a `Model`. Used by
|
|
327
|
+
* `BaseSyncedStore.save / delete / archive / unarchive` so consumers
|
|
328
|
+
* can pass either a typed schema row or a Model instance and the
|
|
329
|
+
* SDK's persistence path sees a uniform Model surface.
|
|
330
|
+
*
|
|
331
|
+
* Same runtime invariant as `modelAsRow`: dynamic-class instances
|
|
332
|
+
* carry both the row fields and the Model methods on the same object
|
|
333
|
+
* — one structural identity, two static views. The helper does no
|
|
334
|
+
* runtime conversion (no allocation, no copy) — it's a pure type cast.
|
|
335
|
+
*/
|
|
336
|
+
export declare function rowAsModel<T extends {
|
|
337
|
+
id: string;
|
|
338
|
+
}>(entity: T): Model;
|
|
339
|
+
export {};
|