@dvina/sdk 3.3.124
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/LICENSE +21 -0
- package/README.md +449 -0
- package/dist/_generated_documents-DF34ZUJ3.js +4 -0
- package/dist/_generated_documents-DF34ZUJ3.js.map +1 -0
- package/dist/_generated_documents-W4RHWJ4B.cjs +2041 -0
- package/dist/_generated_documents-W4RHWJ4B.cjs.map +1 -0
- package/dist/adapters/angular/index.cjs +163 -0
- package/dist/adapters/angular/index.cjs.map +1 -0
- package/dist/adapters/angular/index.d.cts +254 -0
- package/dist/adapters/angular/index.d.ts +254 -0
- package/dist/adapters/angular/index.js +159 -0
- package/dist/adapters/angular/index.js.map +1 -0
- package/dist/adapters/react/index.cjs +51 -0
- package/dist/adapters/react/index.cjs.map +1 -0
- package/dist/adapters/react/index.d.cts +62 -0
- package/dist/adapters/react/index.d.ts +62 -0
- package/dist/adapters/react/index.js +49 -0
- package/dist/adapters/react/index.js.map +1 -0
- package/dist/billing/index.cjs +26 -0
- package/dist/billing/index.cjs.map +1 -0
- package/dist/billing/index.d.cts +338 -0
- package/dist/billing/index.d.ts +338 -0
- package/dist/billing/index.js +5 -0
- package/dist/billing/index.js.map +1 -0
- package/dist/chunk-4QKWHQT2.cjs +104 -0
- package/dist/chunk-4QKWHQT2.cjs.map +1 -0
- package/dist/chunk-5WRI5ZAA.js +29 -0
- package/dist/chunk-5WRI5ZAA.js.map +1 -0
- package/dist/chunk-7JUBGIQ2.js +1008 -0
- package/dist/chunk-7JUBGIQ2.js.map +1 -0
- package/dist/chunk-7XBJ77RJ.js +103 -0
- package/dist/chunk-7XBJ77RJ.js.map +1 -0
- package/dist/chunk-DHUFVGJR.cjs +20389 -0
- package/dist/chunk-DHUFVGJR.cjs.map +1 -0
- package/dist/chunk-DZUJEN5N.cjs +32 -0
- package/dist/chunk-DZUJEN5N.cjs.map +1 -0
- package/dist/chunk-GDK2HJTF.cjs +1346 -0
- package/dist/chunk-GDK2HJTF.cjs.map +1 -0
- package/dist/chunk-KG3GNTYI.js +1339 -0
- package/dist/chunk-KG3GNTYI.js.map +1 -0
- package/dist/chunk-KV5SP7RP.cjs +114 -0
- package/dist/chunk-KV5SP7RP.cjs.map +1 -0
- package/dist/chunk-NPIKZKLU.cjs +27 -0
- package/dist/chunk-NPIKZKLU.cjs.map +1 -0
- package/dist/chunk-OAAZZUYL.cjs +1517 -0
- package/dist/chunk-OAAZZUYL.cjs.map +1 -0
- package/dist/chunk-P4BYTXZ7.js +98 -0
- package/dist/chunk-P4BYTXZ7.js.map +1 -0
- package/dist/chunk-PDM2KR7T.js +392 -0
- package/dist/chunk-PDM2KR7T.js.map +1 -0
- package/dist/chunk-QOZI2HY5.js +24 -0
- package/dist/chunk-QOZI2HY5.js.map +1 -0
- package/dist/chunk-RFBLNKW6.js +20035 -0
- package/dist/chunk-RFBLNKW6.js.map +1 -0
- package/dist/chunk-UELAE75E.cjs +408 -0
- package/dist/chunk-UELAE75E.cjs.map +1 -0
- package/dist/client-9Rwj21T9.d.cts +77 -0
- package/dist/client-Bskq7sc_.d.ts +77 -0
- package/dist/client-CLhQragb.d.cts +446 -0
- package/dist/client-CLhQragb.d.ts +446 -0
- package/dist/error-CsVoUTY8.d.cts +95 -0
- package/dist/error-CsVoUTY8.d.ts +95 -0
- package/dist/index-BrGSfyXq.d.cts +79 -0
- package/dist/index-zPcVLagO.d.ts +79 -0
- package/dist/index.cjs +1675 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +9943 -0
- package/dist/index.d.ts +9943 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/inference/index.cjs +70 -0
- package/dist/inference/index.cjs.map +1 -0
- package/dist/inference/index.d.cts +80 -0
- package/dist/inference/index.d.ts +80 -0
- package/dist/inference/index.js +5 -0
- package/dist/inference/index.js.map +1 -0
- package/dist/pagination/index.cjs +34 -0
- package/dist/pagination/index.cjs.map +1 -0
- package/dist/pagination/index.d.cts +6 -0
- package/dist/pagination/index.d.ts +6 -0
- package/dist/pagination/index.js +5 -0
- package/dist/pagination/index.js.map +1 -0
- package/dist/sync-engine-DVKQO-1-.d.cts +423 -0
- package/dist/sync-engine-cLwTqdjv.d.ts +423 -0
- package/dist/types-2RotD0Ab.d.cts +102 -0
- package/dist/types-2RotD0Ab.d.ts +102 -0
- package/package.json +143 -0
|
@@ -0,0 +1,423 @@
|
|
|
1
|
+
import { DocumentNode } from 'graphql';
|
|
2
|
+
import * as dexie from 'dexie';
|
|
3
|
+
import { Dexie, Table } from 'dexie';
|
|
4
|
+
import { D as DvinaError } from './error-CsVoUTY8.cjs';
|
|
5
|
+
import { D as DvinaQueryRef } from './types-2RotD0Ab.cjs';
|
|
6
|
+
|
|
7
|
+
/** Cached result metadata for a specific query + variables combination */
|
|
8
|
+
interface QueryResultEntry {
|
|
9
|
+
/** Hash of document name + serialized variables */
|
|
10
|
+
key: string;
|
|
11
|
+
/** The entity table these IDs refer to (e.g. 'chats', 'reports') */
|
|
12
|
+
entityType: string;
|
|
13
|
+
/** Ordered list of entity IDs returned by this query */
|
|
14
|
+
entityIds: string[];
|
|
15
|
+
/** Relay PageInfo for cursor-based pagination */
|
|
16
|
+
pageInfo?: {
|
|
17
|
+
hasNextPage: boolean;
|
|
18
|
+
hasPreviousPage: boolean;
|
|
19
|
+
startCursor?: string | null;
|
|
20
|
+
endCursor?: string | null;
|
|
21
|
+
};
|
|
22
|
+
/** Total count if the server returned it */
|
|
23
|
+
totalCount?: number;
|
|
24
|
+
/** Timestamp of the last server fetch */
|
|
25
|
+
fetchedAt: number;
|
|
26
|
+
}
|
|
27
|
+
interface PendingMutationEntry {
|
|
28
|
+
/** Auto-incremented ID */
|
|
29
|
+
id?: number;
|
|
30
|
+
/** Mutation operation name */
|
|
31
|
+
operationName: string;
|
|
32
|
+
/** Serialized DocumentNode name (to re-resolve at replay time) */
|
|
33
|
+
documentName: string;
|
|
34
|
+
/** Serialized variables */
|
|
35
|
+
variables: Record<string, unknown>;
|
|
36
|
+
/** Timestamp when the mutation was queued */
|
|
37
|
+
queuedAt: number;
|
|
38
|
+
/** Number of retry attempts so far */
|
|
39
|
+
retries: number;
|
|
40
|
+
}
|
|
41
|
+
interface SyncMetadataEntry {
|
|
42
|
+
/** Metadata key (e.g. 'lastSyncTimestamp', 'schemaVersion') */
|
|
43
|
+
key: string;
|
|
44
|
+
/** Arbitrary value */
|
|
45
|
+
value: unknown;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Base entity record stored in Dexie.
|
|
49
|
+
*
|
|
50
|
+
* Most entities use `id` as primary key, but some use alternative keys:
|
|
51
|
+
* - `DataSourceTypeDetails` uses `type` (enum string)
|
|
52
|
+
* - `ReportMember` uses compound key `[reportId, insightId]`
|
|
53
|
+
*
|
|
54
|
+
* Use `getPrimaryKeyField()` / `resolvePrimaryKey()` for PK-safe access.
|
|
55
|
+
*/
|
|
56
|
+
interface EntityRecord {
|
|
57
|
+
__typename?: string;
|
|
58
|
+
[key: string]: unknown;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The Dvina IndexedDB database.
|
|
62
|
+
*
|
|
63
|
+
* One database per workspace+user, lazily created on first access.
|
|
64
|
+
* Entity tables are auto-generated from the GraphQL schema (via `_generated_store.ts`).
|
|
65
|
+
* Meta tables (`_queryResults`, `_pendingMutations`, `_sync`) support
|
|
66
|
+
* the SyncEngine's caching and offline mutation queue.
|
|
67
|
+
*
|
|
68
|
+
* Uses Dexie v4 — we create an instance with `new Dexie(name)` and define
|
|
69
|
+
* the schema via `.version().stores()`.
|
|
70
|
+
*/
|
|
71
|
+
declare class DvinaDatabase {
|
|
72
|
+
readonly db: Dexie;
|
|
73
|
+
private readonly _dbName;
|
|
74
|
+
/**
|
|
75
|
+
* Resolves when the schema-hash check is complete.
|
|
76
|
+
* Consumers that depend on a consistent schema should await this before
|
|
77
|
+
* performing reads/writes. The factory function `getOrCreateDatabase`
|
|
78
|
+
* handles this automatically.
|
|
79
|
+
*/
|
|
80
|
+
readonly ready: Promise<void>;
|
|
81
|
+
constructor(workspaceId: string, userId: string);
|
|
82
|
+
/**
|
|
83
|
+
* Verify that the stored schema hash matches the current codegen hash.
|
|
84
|
+
* If the hashes differ the database is deleted and recreated so that
|
|
85
|
+
* stale indexes / missing tables never cause silent data corruption.
|
|
86
|
+
*
|
|
87
|
+
* On a fresh database (no stored hash) the current hash is persisted.
|
|
88
|
+
*/
|
|
89
|
+
private _ensureSchemaCompatibility;
|
|
90
|
+
get _queryResults(): Table<QueryResultEntry, string, QueryResultEntry>;
|
|
91
|
+
get _pendingMutations(): Table<PendingMutationEntry, number, PendingMutationEntry>;
|
|
92
|
+
get _sync(): Table<SyncMetadataEntry, string, SyncMetadataEntry>;
|
|
93
|
+
/** Get a table by name (generic accessor for all entity tables) */
|
|
94
|
+
table<T = unknown, TKey = unknown>(tableName: string): Table<T, TKey>;
|
|
95
|
+
/** Access all tables */
|
|
96
|
+
get allTables(): Table[];
|
|
97
|
+
/** Run a read-write transaction across specified tables */
|
|
98
|
+
transaction<U>(mode: 'rw' | 'r', tables: Table[], scope: () => PromiseLike<U> | U): dexie.PromiseExtended<U>;
|
|
99
|
+
/** Close the database connection and evict from the module-level cache. */
|
|
100
|
+
close(): void;
|
|
101
|
+
/** Get the last processed sync event ID, or '0' if none. */
|
|
102
|
+
getLastSyncId(): Promise<string>;
|
|
103
|
+
/** Persist the last processed sync event ID. */
|
|
104
|
+
setLastSyncId(syncId: string): Promise<void>;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Get or create a DvinaDatabase instance.
|
|
108
|
+
*
|
|
109
|
+
* Databases are cached by name to avoid opening multiple connections
|
|
110
|
+
* to the same IndexedDB database. The returned promise resolves once
|
|
111
|
+
* the schema-hash compatibility check is complete; after that the
|
|
112
|
+
* database is guaranteed to match the current codegen schema.
|
|
113
|
+
*
|
|
114
|
+
* @param token - A valid JWT from which workspaceId and userId are extracted
|
|
115
|
+
* @returns The DvinaDatabase instance after schema compatibility is ensured
|
|
116
|
+
*/
|
|
117
|
+
declare function getOrCreateDatabase(token: string): Promise<DvinaDatabase>;
|
|
118
|
+
/**
|
|
119
|
+
* Close and remove a cached database instance.
|
|
120
|
+
* Useful for logout / workspace switching.
|
|
121
|
+
*/
|
|
122
|
+
declare function closeDatabase(token: string): void;
|
|
123
|
+
/**
|
|
124
|
+
* Delete the IndexedDB database entirely.
|
|
125
|
+
* Use with caution — this wipes all cached data for the workspace+user.
|
|
126
|
+
*/
|
|
127
|
+
declare function deleteDatabase(token: string): Promise<void>;
|
|
128
|
+
|
|
129
|
+
interface HttpTransportOptions {
|
|
130
|
+
/** Full GraphQL HTTP endpoint URL (e.g. 'https://api.dvina.ai/graphql') */
|
|
131
|
+
url: string;
|
|
132
|
+
/**
|
|
133
|
+
* Returns an auth token.
|
|
134
|
+
* When called with `{ forceRefresh: true }`, the callback must bypass any
|
|
135
|
+
* cache and obtain a brand-new token (e.g. via Auth0's silent refresh).
|
|
136
|
+
*/
|
|
137
|
+
getToken: (options?: {
|
|
138
|
+
forceRefresh?: boolean;
|
|
139
|
+
}) => Promise<string>;
|
|
140
|
+
/** Returns the preferred language, or undefined */
|
|
141
|
+
getLanguage: () => string | undefined;
|
|
142
|
+
/**
|
|
143
|
+
* Optional global error callback. Called with the final error right before
|
|
144
|
+
* it is thrown to the caller. Useful for centralized error reporting / UI alerts.
|
|
145
|
+
*
|
|
146
|
+
* **Not** called for transient errors that are retried internally (e.g.
|
|
147
|
+
* intermediate 401s that trigger a token refresh, or network retries).
|
|
148
|
+
* Only invoked for the terminal error that will actually propagate.
|
|
149
|
+
*/
|
|
150
|
+
onError?: (error: DvinaError) => void;
|
|
151
|
+
}
|
|
152
|
+
interface HttpTransport {
|
|
153
|
+
/** Execute a GraphQL query or mutation */
|
|
154
|
+
request: <T>(document: DocumentNode, variables?: Record<string, unknown>) => Promise<T>;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Create a fetch-based GraphQL HTTP transport with:
|
|
158
|
+
* - Auth header injection (Bearer token)
|
|
159
|
+
* - Language header injection
|
|
160
|
+
* - Retry on network errors (status 0, up to 4 attempts with linear backoff)
|
|
161
|
+
* - Auth error handling (401/UNAUTHENTICATED → token refresh → retry, with request queuing)
|
|
162
|
+
*/
|
|
163
|
+
declare function createHttpTransport(options: HttpTransportOptions): HttpTransport;
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* SSE transport for delta sync.
|
|
167
|
+
*
|
|
168
|
+
* Connects to the backend SSE endpoint and emits sync events.
|
|
169
|
+
* Uses EventSource in browser environments and a fetch-based
|
|
170
|
+
* fallback for environments without native EventSource.
|
|
171
|
+
*
|
|
172
|
+
* Features:
|
|
173
|
+
* - Fetch-based SSE with Authorization header (no query parameter token exposure)
|
|
174
|
+
* - Automatic reconnection with exponential backoff
|
|
175
|
+
* - Auth failure detection with short-delay retry for token refresh
|
|
176
|
+
* - Event listener pattern for processing sync events
|
|
177
|
+
*/
|
|
178
|
+
interface SseSyncEvent {
|
|
179
|
+
id: string;
|
|
180
|
+
type: 'upsert' | 'delete';
|
|
181
|
+
modelName: string;
|
|
182
|
+
entityId: string;
|
|
183
|
+
payload: Record<string, unknown> | null;
|
|
184
|
+
}
|
|
185
|
+
interface SseQueryEvent {
|
|
186
|
+
type: 'add' | 'remove';
|
|
187
|
+
subscriptionId: string;
|
|
188
|
+
entityId: string;
|
|
189
|
+
entityType: string;
|
|
190
|
+
}
|
|
191
|
+
interface SubscriptionDescriptor {
|
|
192
|
+
id: string;
|
|
193
|
+
entityType: string;
|
|
194
|
+
operationName: string;
|
|
195
|
+
modelName: string;
|
|
196
|
+
filter?: Record<string, unknown>;
|
|
197
|
+
}
|
|
198
|
+
interface SseTransportOptions {
|
|
199
|
+
/** Full SSE endpoint URL (e.g. 'https://api.dvina.ai/api/sync/stream') */
|
|
200
|
+
url: string;
|
|
201
|
+
/**
|
|
202
|
+
* Returns an auth token.
|
|
203
|
+
* When called with `{ forceRefresh: true }`, the callback must bypass any
|
|
204
|
+
* cache and obtain a brand-new token (e.g. via Auth0's silent refresh).
|
|
205
|
+
*/
|
|
206
|
+
getToken: (options?: {
|
|
207
|
+
forceRefresh?: boolean;
|
|
208
|
+
}) => Promise<string>;
|
|
209
|
+
/** Called when a sync event is received */
|
|
210
|
+
onEvent: (event: SseSyncEvent) => void;
|
|
211
|
+
/** Called when a query event is received (server-driven subscription update) */
|
|
212
|
+
onQueryEvent?: (event: SseQueryEvent) => void;
|
|
213
|
+
/** Called when the initial cursor is received (fresh connection) */
|
|
214
|
+
onCursor?: (syncId: string) => void;
|
|
215
|
+
/** Called when the server signals that the sync gap is unrecoverable and a full resync is needed */
|
|
216
|
+
onFullResync?: () => void;
|
|
217
|
+
/** Called on connection state changes */
|
|
218
|
+
onStateChange?: (state: 'connecting' | 'connected' | 'disconnected') => void;
|
|
219
|
+
}
|
|
220
|
+
interface SseTransport {
|
|
221
|
+
/** Start the SSE connection */
|
|
222
|
+
connect(lastSyncId?: string): Promise<void>;
|
|
223
|
+
/** Close the SSE connection */
|
|
224
|
+
disconnect(): void;
|
|
225
|
+
/** Whether the transport is currently connected */
|
|
226
|
+
readonly connected: boolean;
|
|
227
|
+
/** Register a query subscription (fire-and-forget POST) */
|
|
228
|
+
subscribe(descriptor: SubscriptionDescriptor): void;
|
|
229
|
+
/** Unregister a query subscription (fire-and-forget POST) */
|
|
230
|
+
unsubscribe(subscriptionId: string): void;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Create an SSE transport for delta sync.
|
|
234
|
+
*
|
|
235
|
+
* Uses a fetch-based SSE implementation instead of the native EventSource API
|
|
236
|
+
* so that we can send the auth token via the `Authorization` header. This
|
|
237
|
+
* avoids exposing tokens in URL query parameters (which end up in server
|
|
238
|
+
* logs, browser history, and referrer headers).
|
|
239
|
+
*/
|
|
240
|
+
declare function createSseTransport(options: SseTransportOptions): SseTransport;
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Convention-based cache rules generated by codegen.
|
|
244
|
+
* These tell the SyncEngine how to update the local store after a mutation.
|
|
245
|
+
*/
|
|
246
|
+
interface CacheRuleCreate {
|
|
247
|
+
type: 'create';
|
|
248
|
+
/** Dexie table name for the created entity (e.g. 'chats') */
|
|
249
|
+
entityType: string;
|
|
250
|
+
/** Query result keys to prepend the new entity to (e.g. ['chats']) */
|
|
251
|
+
connectionFields: string[];
|
|
252
|
+
}
|
|
253
|
+
interface CacheRuleUpdate {
|
|
254
|
+
type: 'update';
|
|
255
|
+
/** Dexie table name for the updated entity */
|
|
256
|
+
entityType: string;
|
|
257
|
+
}
|
|
258
|
+
interface CacheRuleDelete {
|
|
259
|
+
type: 'delete';
|
|
260
|
+
/** Dexie table name for the deleted entity */
|
|
261
|
+
entityType: string;
|
|
262
|
+
/** Query result keys to remove the entity from */
|
|
263
|
+
connectionFields: string[];
|
|
264
|
+
/** Related entity types to cascade-delete (e.g. Resource for a DataSource delete) */
|
|
265
|
+
cascadeDelete?: string[];
|
|
266
|
+
}
|
|
267
|
+
type CacheRule = CacheRuleCreate | CacheRuleUpdate | CacheRuleDelete;
|
|
268
|
+
interface SyncEngineOptions {
|
|
269
|
+
/** The Dexie database instance */
|
|
270
|
+
db: DvinaDatabase;
|
|
271
|
+
/** HTTP transport for queries and mutations */
|
|
272
|
+
httpTransport: HttpTransport;
|
|
273
|
+
/** Optional SSE transport for delta sync (browser-only) */
|
|
274
|
+
sseTransport?: SseTransport;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* The SyncEngine is the central orchestrator for all data operations in the SDK.
|
|
278
|
+
*
|
|
279
|
+
* It sits between the generated SDK classes and the transport/store layers:
|
|
280
|
+
*
|
|
281
|
+
* ```
|
|
282
|
+
* SDK classes → SyncEngine → HTTP Transport (server)
|
|
283
|
+
* → Dexie (local store)
|
|
284
|
+
* → liveQuery (reactivity)
|
|
285
|
+
* ```
|
|
286
|
+
*
|
|
287
|
+
* Responsibilities:
|
|
288
|
+
* 1. **query()** — Fetch from server → normalize → write to Dexie → return data
|
|
289
|
+
* 2. **watch()** — Create a Dexie liveQuery, fetch from server on cold start,
|
|
290
|
+
* auto-update on any store change
|
|
291
|
+
* 3. **mutate()** — Optimistic write → server call → commit/rollback
|
|
292
|
+
* 4. **Cache rules** — Convention-based auto cache updates for CRUD mutations
|
|
293
|
+
*/
|
|
294
|
+
declare class SyncEngine {
|
|
295
|
+
private _db;
|
|
296
|
+
private _sse?;
|
|
297
|
+
private _cache;
|
|
298
|
+
private _queryExecutor;
|
|
299
|
+
private _mutationExecutor;
|
|
300
|
+
/**
|
|
301
|
+
* Maps subscriptionId → queryKey for routing server-driven query events
|
|
302
|
+
* to the correct cache entry. Populated by watch() when a subscription
|
|
303
|
+
* descriptor is provided, cleaned up on dispose().
|
|
304
|
+
*/
|
|
305
|
+
private _subscriptionToQueryKey;
|
|
306
|
+
/** Active subscription metadata used for targeted revalidation fallback. */
|
|
307
|
+
private _subscriptionToQuery;
|
|
308
|
+
/** Last per-query revalidation timestamp to avoid refetch storms. */
|
|
309
|
+
private _lastRevalidatedAt;
|
|
310
|
+
/**
|
|
311
|
+
* Last mutation/sync touch timestamp by entity type.
|
|
312
|
+
* Used to detect stale cached query results on watch re-entry.
|
|
313
|
+
*/
|
|
314
|
+
private _entityTypeTouchedAt;
|
|
315
|
+
constructor(options: SyncEngineOptions);
|
|
316
|
+
/**
|
|
317
|
+
* Start the SSE delta sync connection.
|
|
318
|
+
* Reads the last sync cursor from Dexie and connects to the SSE endpoint.
|
|
319
|
+
* Incoming events are automatically written to Dexie, triggering liveQuery updates.
|
|
320
|
+
*/
|
|
321
|
+
startSync(): Promise<void>;
|
|
322
|
+
/**
|
|
323
|
+
* Stop the SSE delta sync connection.
|
|
324
|
+
*/
|
|
325
|
+
stopSync(): void;
|
|
326
|
+
/**
|
|
327
|
+
* Handle a full-resync signal from the server.
|
|
328
|
+
*
|
|
329
|
+
* Clears all cached entities and query results, resets the sync cursor,
|
|
330
|
+
* then restarts the SSE connection so the client gets a fresh cursor.
|
|
331
|
+
* Active `liveQuery` watchers will re-emit once data is refetched.
|
|
332
|
+
*/
|
|
333
|
+
handleFullResync(): Promise<void>;
|
|
334
|
+
/**
|
|
335
|
+
* Process an incoming SSE sync event.
|
|
336
|
+
* Writes the entity to Dexie and updates the sync cursor atomically.
|
|
337
|
+
*/
|
|
338
|
+
processSyncEvent(event: SseSyncEvent): Promise<void>;
|
|
339
|
+
/**
|
|
340
|
+
* Execute a query: fetch from server → normalize → write to Dexie → return raw data.
|
|
341
|
+
*
|
|
342
|
+
* For connection queries, also writes the ordered entity IDs to `_queryResults`
|
|
343
|
+
* so that `watch()` can reconstruct the same ordered list from the store.
|
|
344
|
+
*/
|
|
345
|
+
query<T>(document: DocumentNode, variables?: Record<string, unknown>, operationName?: string): Promise<T>;
|
|
346
|
+
/**
|
|
347
|
+
* Create a reactive query that auto-updates when the underlying store changes.
|
|
348
|
+
*
|
|
349
|
+
* **Cold start**: The first emission waits for the server fetch to complete.
|
|
350
|
+
* After that, Dexie's `liveQuery` handles reactivity — any write to a table
|
|
351
|
+
* accessed by the query factory triggers a re-emission.
|
|
352
|
+
*
|
|
353
|
+
* When a `subscriptionDescriptor` is provided, the watch registers a
|
|
354
|
+
* server-driven subscription via the SSE transport. The server evaluates
|
|
355
|
+
* Prisma filters on create/update/upsert events and sends targeted
|
|
356
|
+
* `query-add` / `query-remove`
|
|
357
|
+
* events back, which this engine routes to the correct cache entry.
|
|
358
|
+
*
|
|
359
|
+
* @param document - The GraphQL query document
|
|
360
|
+
* @param variables - Query variables
|
|
361
|
+
* @param operationName - The operation name (used as the query result cache key)
|
|
362
|
+
* @param buildResult - A function that reads from Dexie and returns the raw response shape.
|
|
363
|
+
* @param subscriptionDescriptor - Optional server-driven subscription metadata for filtered queries.
|
|
364
|
+
*/
|
|
365
|
+
watch<T>(document: DocumentNode, variables: Record<string, unknown> | undefined, operationName: string, buildResult: (db: DvinaDatabase) => Promise<T> | T, subscriptionDescriptor?: SubscriptionDescriptor): DvinaQueryRef<T>;
|
|
366
|
+
/**
|
|
367
|
+
* Execute a mutation with optional optimistic update and automatic cache rule.
|
|
368
|
+
*
|
|
369
|
+
* Flow:
|
|
370
|
+
* 1. **Optimistic write** (if cache rule is create/update/delete) — immediately
|
|
371
|
+
* update Dexie so all watchers see the change
|
|
372
|
+
* 2. **Server call** — send the mutation to the server
|
|
373
|
+
* 3. **Commit** — normalize server response and write to Dexie (replacing optimistic data)
|
|
374
|
+
* 4. **Rollback** (on error) — restore the original state in Dexie
|
|
375
|
+
*/
|
|
376
|
+
mutate<T>(document: DocumentNode, variables?: Record<string, unknown>, cacheRule?: CacheRule, optimisticData?: Record<string, unknown>): Promise<T>;
|
|
377
|
+
/** Direct access to the Dexie database (for advanced use cases) */
|
|
378
|
+
get db(): DvinaDatabase;
|
|
379
|
+
/**
|
|
380
|
+
* Read a single entity from the store by table name and primary key.
|
|
381
|
+
*
|
|
382
|
+
* @param tableName - Dexie table name (e.g. 'chats', 'reportMembers')
|
|
383
|
+
* @param pk - Primary key value. String for simple keys, string[] for compound keys.
|
|
384
|
+
*/
|
|
385
|
+
getEntity(tableName: string, pk: string | string[]): Promise<EntityRecord | undefined>;
|
|
386
|
+
/**
|
|
387
|
+
* Read query result metadata from the store.
|
|
388
|
+
*/
|
|
389
|
+
getQueryResult(operationName: string, variables?: Record<string, unknown>): Promise<QueryResultEntry | undefined>;
|
|
390
|
+
/**
|
|
391
|
+
* Invalidate (delete) a query result, forcing the next watch() to refetch.
|
|
392
|
+
*/
|
|
393
|
+
invalidateQuery(operationName: string, variables?: Record<string, unknown>): Promise<void>;
|
|
394
|
+
/**
|
|
395
|
+
* Clear all data from the store (but keep the database structure).
|
|
396
|
+
* Useful for logout scenarios.
|
|
397
|
+
*/
|
|
398
|
+
clearAll(): Promise<void>;
|
|
399
|
+
/**
|
|
400
|
+
* Process a server-driven query event (query-add / query-remove).
|
|
401
|
+
*
|
|
402
|
+
* The server evaluates Prisma filters on create/update/upsert events and sends targeted
|
|
403
|
+
* events to subscriptions that match. This method routes the event to the
|
|
404
|
+
* correct query result cache entry using the subscriptionId → queryKey map.
|
|
405
|
+
*/
|
|
406
|
+
processQueryEvent(event: SseQueryEvent): Promise<void>;
|
|
407
|
+
/**
|
|
408
|
+
* Handle an upsert sync event: normalize the payload and write to Dexie.
|
|
409
|
+
*
|
|
410
|
+
* The updated entity type is marked as touched so cached query results can
|
|
411
|
+
* be revalidated lazily when those queries become active again.
|
|
412
|
+
*/
|
|
413
|
+
private _processSyncUpsert;
|
|
414
|
+
private _markEntityTypeTouched;
|
|
415
|
+
private _revalidateSubscriptionIfStale;
|
|
416
|
+
private _revalidateSubscriptionsForEntityType;
|
|
417
|
+
/**
|
|
418
|
+
* Handle a delete sync event: remove entity from Dexie and query results.
|
|
419
|
+
*/
|
|
420
|
+
private _processSyncDelete;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
export { type CacheRule as C, DvinaDatabase as D, SyncEngine as S, type CacheRuleCreate as a, type CacheRuleDelete as b, createHttpTransport as c, type CacheRuleUpdate as d, type SseQueryEvent as e, type SseSyncEvent as f, type SseTransport as g, type SseTransportOptions as h, type SubscriptionDescriptor as i, closeDatabase as j, createSseTransport as k, deleteDatabase as l, getOrCreateDatabase as m };
|