cry-synced-db-client 0.1.75 → 0.1.77
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/dist/index.js +1580 -1135
- package/dist/src/db/SyncedDb.d.ts +36 -0
- package/dist/src/db/types/managers.d.ts +6 -0
- package/dist/src/types/CollectionConfig.d.ts +6 -0
- package/dist/src/types/I_SyncedDb.d.ts +18 -0
- package/package.json +3 -2
|
@@ -27,6 +27,8 @@ export declare class SyncedDb implements I_SyncedDb {
|
|
|
27
27
|
private syncing;
|
|
28
28
|
private syncLock;
|
|
29
29
|
private wsUpdateQueue;
|
|
30
|
+
/** When non-null, only these collections participate in sync/in-mem loading. */
|
|
31
|
+
private syncOnlyCollections;
|
|
30
32
|
private readonly updaterId;
|
|
31
33
|
private readonly syncedDbInstanceId;
|
|
32
34
|
private syncMetaCache;
|
|
@@ -44,6 +46,20 @@ export declare class SyncedDb implements I_SyncedDb {
|
|
|
44
46
|
getInstanceId(): string;
|
|
45
47
|
getCrossTabSyncDebounceMs(): number;
|
|
46
48
|
isLeaderTab(): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Restrict sync to only these collections. When non-empty, only the listed
|
|
51
|
+
* collections load from Dexie→in-mem and download from server. Pass an empty
|
|
52
|
+
* array to sync all collections again.
|
|
53
|
+
*
|
|
54
|
+
* Newly-allowed collections are loaded from Dexie immediately and a sync is
|
|
55
|
+
* triggered if online.
|
|
56
|
+
*/
|
|
57
|
+
setSyncOnlyTheseCollections(collections: string[]): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Get the current syncOnlyTheseCollections filter.
|
|
60
|
+
* Returns null when all collections are synced.
|
|
61
|
+
*/
|
|
62
|
+
getSyncOnlyTheseCollections(): ReadonlySet<string> | null;
|
|
47
63
|
/**
|
|
48
64
|
* Test helper: simulate receiving a cross-tab broadcast from another instance.
|
|
49
65
|
*/
|
|
@@ -114,5 +130,25 @@ export declare class SyncedDb implements I_SyncedDb {
|
|
|
114
130
|
* Per-call values take precedence over global defaults.
|
|
115
131
|
*/
|
|
116
132
|
private resolveOpts;
|
|
133
|
+
/**
|
|
134
|
+
* Whether a collection participates in sync (server download,
|
|
135
|
+
* WS notifications, cross-tab sync, Dexie→in-mem loading).
|
|
136
|
+
* False for writeOnly collections and collections excluded by syncOnlyCollections.
|
|
137
|
+
*/
|
|
138
|
+
private isSyncAllowed;
|
|
139
|
+
/**
|
|
140
|
+
* Load a single collection from Dexie into in-memory cache.
|
|
141
|
+
* Filters out deleted and archived items.
|
|
142
|
+
*/
|
|
143
|
+
private loadCollectionToInMem;
|
|
117
144
|
private assertCollection;
|
|
145
|
+
/**
|
|
146
|
+
* Asserts write-only collection has online connectivity for reads.
|
|
147
|
+
* @throws Error if offline
|
|
148
|
+
*/
|
|
149
|
+
private assertWriteOnlyOnline;
|
|
150
|
+
private writeOnlyFindById;
|
|
151
|
+
private writeOnlyFindByIds;
|
|
152
|
+
private writeOnlyFindOne;
|
|
153
|
+
private writeOnlyFind;
|
|
118
154
|
}
|
|
@@ -50,6 +50,8 @@ export interface CrossTabSyncDeps {
|
|
|
50
50
|
dexieDb: I_DexieDb;
|
|
51
51
|
/** Write to in-mem batch. */
|
|
52
52
|
writeToInMemBatch: <T extends DbEntity>(collection: string, items: T[], operation: "upsert" | "delete") => void;
|
|
53
|
+
/** Whether a collection participates in sync (not writeOnly, not filtered out). */
|
|
54
|
+
isSyncAllowed: (collection: string) => boolean;
|
|
53
55
|
}
|
|
54
56
|
export interface CrossTabSyncConfig {
|
|
55
57
|
tenant: string;
|
|
@@ -225,6 +227,8 @@ export interface SyncEngineDeps {
|
|
|
225
227
|
awaitRestUpload: () => Promise<void>;
|
|
226
228
|
/** Broadcast updated IDs to other tabs */
|
|
227
229
|
broadcastUpdates: (updates: Record<string, string[]>) => void;
|
|
230
|
+
/** Whether a collection participates in sync (not writeOnly, not filtered out). */
|
|
231
|
+
isSyncAllowed: (collection: string) => boolean;
|
|
228
232
|
}
|
|
229
233
|
export interface SyncEngineConfig {
|
|
230
234
|
tenant: string;
|
|
@@ -256,6 +260,8 @@ export interface ServerUpdateHandlerDeps {
|
|
|
256
260
|
getPendingChange: (collection: string, id: Id) => PendingChange | undefined;
|
|
257
261
|
broadcastUpdates: (updates: Record<string, string[]>) => void;
|
|
258
262
|
writeToInMemBatch: <T extends DbEntity>(collection: string, items: T[], operation: "upsert" | "delete") => void;
|
|
263
|
+
/** Whether a collection participates in sync (not writeOnly, not filtered out). */
|
|
264
|
+
isSyncAllowed: (collection: string) => boolean;
|
|
259
265
|
}
|
|
260
266
|
export interface ServerUpdateHandlerConfig {
|
|
261
267
|
tenant: string;
|
|
@@ -20,4 +20,10 @@ export interface CollectionConfig<T = any> {
|
|
|
20
20
|
*/
|
|
21
21
|
syncConfig?: CollectionSyncConfig<T>;
|
|
22
22
|
resolveSyncConflict?(local: T, external: T): T;
|
|
23
|
+
/**
|
|
24
|
+
* Write-only mode: writes are persisted locally (Dexie) and uploaded
|
|
25
|
+
* to the server, but no data is downloaded or kept in the in-memory cache.
|
|
26
|
+
* Read operations throw. Server sync and WS notifications are skipped.
|
|
27
|
+
*/
|
|
28
|
+
writeOnly?: boolean;
|
|
23
29
|
}
|
|
@@ -254,6 +254,12 @@ export interface CollectionConfig<T extends DbEntity = any, M = any> {
|
|
|
254
254
|
syncConfig?: CollectionSyncConfig;
|
|
255
255
|
/** Opcijska funkcija za razreševanje konfliktov */
|
|
256
256
|
resolveSyncConflict?(local: T, external: T): T;
|
|
257
|
+
/**
|
|
258
|
+
* Write-only mode: writes are persisted locally (Dexie) and uploaded
|
|
259
|
+
* to the server, but no data is downloaded or kept in the in-memory cache.
|
|
260
|
+
* Read operations throw. Server sync and WS notifications are skipped.
|
|
261
|
+
*/
|
|
262
|
+
writeOnly?: boolean;
|
|
257
263
|
/** Whether this collection uses in-memory metadata */
|
|
258
264
|
hasMetadata?: boolean;
|
|
259
265
|
/** Callback called when a single object is written to in-mem. Returns metadata to store. */
|
|
@@ -512,6 +518,18 @@ export interface I_SyncedDb {
|
|
|
512
518
|
sync(calledFrom?: string): Promise<void>;
|
|
513
519
|
/** Ali je sinhronizacija v teku */
|
|
514
520
|
isSyncing(): boolean;
|
|
521
|
+
/**
|
|
522
|
+
* Restrict sync to only these collections. When non-empty, only listed
|
|
523
|
+
* collections load Dexie→in-mem and download from server. Pass empty
|
|
524
|
+
* array to sync all collections. Newly-allowed collections are loaded
|
|
525
|
+
* immediately and a sync is triggered if online.
|
|
526
|
+
*/
|
|
527
|
+
setSyncOnlyTheseCollections(collections: string[]): Promise<void>;
|
|
528
|
+
/**
|
|
529
|
+
* Get the current syncOnlyTheseCollections filter.
|
|
530
|
+
* Returns null when all collections are synced.
|
|
531
|
+
*/
|
|
532
|
+
getSyncOnlyTheseCollections(): ReadonlySet<string> | null;
|
|
515
533
|
/**
|
|
516
534
|
* Izvede batch upsert na serverju
|
|
517
535
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cry-synced-db-client",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.77",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"scripts": {
|
|
18
18
|
"clean": "rm -rf dist",
|
|
19
19
|
"build": "bun run clean && bun run build:js && bun run build:types",
|
|
20
|
-
"build:js": "
|
|
20
|
+
"build:js": "esbuild ./src/index.ts --bundle --outdir=./dist --target=es2017 --format=esm --platform=browser --external:dexie --external:bson --external:cry-helpers --external:notepack.io",
|
|
21
21
|
"build:types": "tsc --emitDeclarationOnly --outDir dist",
|
|
22
22
|
"test": "bun test test/*.test.ts test/restProxy/*.test.ts && vitest run",
|
|
23
23
|
"test:bun": "bun test test/*.test.ts test/restProxy/*.test.ts",
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"bson": "^7.2.0",
|
|
30
30
|
"cry-ebus-proxy": "^1.0.3",
|
|
31
31
|
"dexie": "^4.4.1",
|
|
32
|
+
"esbuild": "^0.27.4",
|
|
32
33
|
"fake-indexeddb": "^6.2.5",
|
|
33
34
|
"typescript": "^6",
|
|
34
35
|
"vitest": "^4.1.2"
|