prostgles-client 4.0.357 → 4.0.358
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/SyncedTable/SyncedTable.d.ts +3 -35
- package/dist/SyncedTable/SyncedTable.d.ts.map +1 -1
- package/dist/SyncedTable/SyncedTable.js +43 -211
- package/dist/getDbHandler.js +3 -3
- package/dist/getSyncHandler.d.ts +2 -2
- package/dist/getSyncHandler.d.ts.map +1 -1
- package/dist/getSyncHandler.js +26 -17
- package/dist/index.js +1 -1
- package/dist/index.no-sync.js +1 -1
- package/dist/prostgles.d.ts +8 -2
- package/dist/prostgles.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AnyObject, EqualityFilter, FieldFilter, NormalizedRow, SyncBatchParams, TableHandler } from "prostgles-types";
|
|
2
2
|
import { WAL } from "prostgles-types";
|
|
3
3
|
import type { DBHandlerClient, SyncDebugEvent } from "../prostgles";
|
|
4
|
-
export declare const debug: any;
|
|
5
4
|
type OmittedSyncProps = "onDebug" | "name" | "filter" | "db" | "onError";
|
|
6
5
|
export type SyncOptions = Partial<Omit<SyncedTableOptions, OmittedSyncProps>> & {
|
|
7
6
|
select?: FieldFilter;
|
|
@@ -86,15 +85,10 @@ export type SubscriptionMulti<T extends AnyObject = AnyObject> = {
|
|
|
86
85
|
handlesOnData?: boolean;
|
|
87
86
|
handles?: MultiSyncHandles<T>;
|
|
88
87
|
};
|
|
89
|
-
declare const STORAGE_TYPES: {
|
|
90
|
-
readonly map: "map";
|
|
91
|
-
readonly localStorage: "localStorage";
|
|
92
|
-
};
|
|
93
88
|
export type MultiChangeListener<T extends AnyObject = AnyObject> = (items: NormalizedRow<T>[], delta: DeepPartial<T>[]) => any;
|
|
94
89
|
export type SingleChangeListener<T extends AnyObject = AnyObject, Full extends boolean | undefined = false> = (item: SyncDataItem<T, {
|
|
95
90
|
handlesOnData: Full;
|
|
96
91
|
}>, delta?: DeepPartial<T>) => any;
|
|
97
|
-
type StorageType = keyof typeof STORAGE_TYPES;
|
|
98
92
|
export type SyncedTableOptions = {
|
|
99
93
|
/**
|
|
100
94
|
* Table name
|
|
@@ -111,22 +105,7 @@ export type SyncedTableOptions = {
|
|
|
111
105
|
onChange?: MultiChangeListener;
|
|
112
106
|
onError?: OnErrorHandler;
|
|
113
107
|
db: DBHandlerClient | Partial<DBHandlerClient>;
|
|
114
|
-
/**
|
|
115
|
-
* If true then the first onChange trigger is skipped
|
|
116
|
-
*/
|
|
117
|
-
skipFirstTrigger?: boolean;
|
|
118
108
|
select?: "*" | AnyObject;
|
|
119
|
-
/**
|
|
120
|
-
* Default is "object".
|
|
121
|
-
* "localStorage" will persist the data
|
|
122
|
-
*/
|
|
123
|
-
storageType?: StorageType;
|
|
124
|
-
/**
|
|
125
|
-
* If true then only the delta of the text field is sent to server.
|
|
126
|
-
* Full text is sent if an error occurs
|
|
127
|
-
*/
|
|
128
|
-
patchText?: boolean;
|
|
129
|
-
patchJSON?: boolean;
|
|
130
109
|
onReady: () => void;
|
|
131
110
|
onDebug?: (event: SyncDebugEvent, tbl: SyncedTable) => Promise<void> | void;
|
|
132
111
|
};
|
|
@@ -138,13 +117,11 @@ export declare class SyncedTable {
|
|
|
138
117
|
db: DBHandlerClient | Partial<DBHandlerClient>;
|
|
139
118
|
name: string;
|
|
140
119
|
select?: "*" | AnyObject;
|
|
141
|
-
filter?: AnyObject
|
|
142
|
-
onChange?: MultiChangeListener;
|
|
120
|
+
filter?: EqualityFilter<AnyObject>;
|
|
143
121
|
id_fields: string[];
|
|
144
122
|
synced_field: string;
|
|
145
123
|
throttle: number;
|
|
146
124
|
batch_size: number;
|
|
147
|
-
skipFirstTrigger: boolean;
|
|
148
125
|
columns: {
|
|
149
126
|
name: string;
|
|
150
127
|
data_type: string;
|
|
@@ -161,20 +138,11 @@ export declare class SyncedTable {
|
|
|
161
138
|
set singleSubscriptions(sSubs: SubscriptionSingle[]);
|
|
162
139
|
get singleSubscriptions(): SubscriptionSingle[];
|
|
163
140
|
dbSync?: DbTableSync;
|
|
164
|
-
storageType?: StorageType;
|
|
165
141
|
itemsMap: Map<string, AnyObject>;
|
|
166
|
-
patchText: boolean;
|
|
167
|
-
patchJSON: boolean;
|
|
168
142
|
isSynced: boolean;
|
|
169
143
|
onError: SyncedTableOptions["onError"];
|
|
170
144
|
onDebug?: (evt: Omit<SyncDebugEvent, "type" | "tableName" | "channelName" | "syncedTable">) => Promise<void> | void;
|
|
171
|
-
constructor({ name, filter,
|
|
172
|
-
/**
|
|
173
|
-
* Will update text/json fields through patching method
|
|
174
|
-
* This will send less data to server
|
|
175
|
-
* @param walData
|
|
176
|
-
*/
|
|
177
|
-
updatePatches: (walData: WALItem[]) => Promise<any[]>;
|
|
145
|
+
constructor({ name, filter, onReady, onDebug, db, select, onError, }: SyncedTableOptions);
|
|
178
146
|
static create(opts: Omit<SyncedTableOptions, "onReady">): Promise<SyncedTable>;
|
|
179
147
|
/**
|
|
180
148
|
* Returns a sync handler to all records within the SyncedTable instance
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SyncedTable.d.ts","sourceRoot":"","sources":["../../lib/SyncedTable/SyncedTable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,
|
|
1
|
+
{"version":3,"file":"SyncedTable.d.ts","sourceRoot":"","sources":["../../lib/SyncedTable/SyncedTable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,SAAS,EAGT,cAAc,EACd,WAAW,EACX,aAAa,EACb,eAAe,EACf,YAAY,EAEb,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAOL,GAAG,EACJ,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAKpE,KAAK,gBAAgB,GAAG,SAAS,GAAG,MAAM,GAAG,QAAQ,GAAG,IAAI,GAAG,SAAS,CAA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GAAU,OAAO,UAAU,EAAE,EAAE,qBAAmB,KAAG,OAAO,CAAC,IAAI,CAAC,CA6HtE;IAGF,OAAO,CAAC,CAAC,GAAG,SAAS,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,SAAS;IAMxD;;;;;;OAMG;IACH,OAAO,CAAC,KAAK,EAAE,SAAS,EAAE,UAAU,UAAQ,EAAE,UAAU,UAAQ;IAYhE;;OAEG;IACH,QAAQ,GAAI,QAAQ,SAAS,EAAE,KAAG,IAAI,CASpC;IAEF;;OAEG;IACH,QAAQ,GAAI,CAAC,SAAS,SAAS,GAAG,SAAS,OAAK,CAAC,EAAE,CAsBjD;IAEF;;OAEG;IACH,QAAQ,GACN,4CAA2C,eAAiD;;QAe5F;CACH;AAED,eAAO,MAAM,SAAS,GACpB,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,EAC5C,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS;;CAkB7C,CAAC;AAEF,eAAO,MAAM,UAAU,GAAI,CAAC,EAAE,KAAK,CAAC,KAAG,CAetC,CAAC"}
|
|
@@ -1,103 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.quickClone = exports.mergeDeep = exports.SyncedTable =
|
|
3
|
+
exports.quickClone = exports.mergeDeep = exports.SyncedTable = void 0;
|
|
4
4
|
const prostgles_types_1 = require("prostgles-types");
|
|
5
5
|
const getMultiSyncSubscription_1 = require("./getMultiSyncSubscription");
|
|
6
|
-
const DEBUG_KEY = "DEBUG_SYNCEDTABLE";
|
|
7
6
|
const hasWnd = typeof window !== "undefined";
|
|
8
|
-
const debug = function (...args) {
|
|
9
|
-
if (hasWnd && window[DEBUG_KEY]) {
|
|
10
|
-
window[DEBUG_KEY](...args);
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
exports.debug = debug;
|
|
14
|
-
const STORAGE_TYPES = {
|
|
15
|
-
map: "map",
|
|
16
|
-
localStorage: "localStorage",
|
|
17
|
-
// object: "object",
|
|
18
|
-
};
|
|
19
7
|
class SyncedTable {
|
|
20
8
|
/**
|
|
21
9
|
* add debug mode to fix sudden no data and sync listeners bug
|
|
22
10
|
*/
|
|
23
11
|
set multiSubscriptions(mSubs) {
|
|
24
|
-
(0, exports.debug)(mSubs, this._multiSubscriptions);
|
|
25
12
|
this._multiSubscriptions = mSubs.slice(0);
|
|
26
13
|
}
|
|
27
14
|
get multiSubscriptions() {
|
|
28
15
|
return this._multiSubscriptions;
|
|
29
16
|
}
|
|
30
17
|
set singleSubscriptions(sSubs) {
|
|
31
|
-
(0, exports.debug)(sSubs, this._singleSubscriptions);
|
|
32
18
|
this._singleSubscriptions = sSubs.slice(0);
|
|
33
19
|
}
|
|
34
20
|
get singleSubscriptions() {
|
|
35
21
|
return this._singleSubscriptions;
|
|
36
22
|
}
|
|
37
|
-
constructor({ name, filter
|
|
23
|
+
constructor({ name, filter = {}, onReady, onDebug, db, select = "*", onError, }) {
|
|
38
24
|
this.throttle = 100;
|
|
39
25
|
this.batch_size = 50;
|
|
40
|
-
this.skipFirstTrigger = false;
|
|
41
26
|
this.columns = [];
|
|
42
27
|
this._multiSubscriptions = [];
|
|
43
28
|
this._singleSubscriptions = [];
|
|
44
29
|
this.itemsMap = new Map();
|
|
45
30
|
this.isSynced = false;
|
|
46
|
-
/**
|
|
47
|
-
* Will update text/json fields through patching method
|
|
48
|
-
* This will send less data to server
|
|
49
|
-
* @param walData
|
|
50
|
-
*/
|
|
51
|
-
this.updatePatches = async (walData) => {
|
|
52
|
-
var _a, _b;
|
|
53
|
-
let remaining = walData.map((d) => d.current);
|
|
54
|
-
const patched = [], patchedItems = [];
|
|
55
|
-
if (this.columns.length &&
|
|
56
|
-
((_a = this.tableHandler) === null || _a === void 0 ? void 0 : _a.updateBatch) &&
|
|
57
|
-
(this.patchText || this.patchJSON)) {
|
|
58
|
-
// const jCols = this.columns.filter(c => c.data_type === "json")
|
|
59
|
-
const txtCols = this.columns.filter((c) => c.data_type === "text");
|
|
60
|
-
if (this.patchText && txtCols.length) {
|
|
61
|
-
remaining = [];
|
|
62
|
-
const id_keys = [this.synced_field, ...this.id_fields];
|
|
63
|
-
await Promise.all(walData.slice(0).map(async (d, i) => {
|
|
64
|
-
const { current, initial } = { ...d };
|
|
65
|
-
let patchedDelta;
|
|
66
|
-
if (initial) {
|
|
67
|
-
txtCols.map((c) => {
|
|
68
|
-
if (!id_keys.includes(c.name) && c.name in current) {
|
|
69
|
-
patchedDelta !== null && patchedDelta !== void 0 ? patchedDelta : (patchedDelta = { ...current });
|
|
70
|
-
patchedDelta[c.name] = (0, prostgles_types_1.getTextPatch)(initial[c.name], current[c.name]);
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
if (patchedDelta && this.wal) {
|
|
74
|
-
patchedItems.push(patchedDelta);
|
|
75
|
-
patched.push([this.wal.getIdObj(patchedDelta), this.wal.getDeltaObj(patchedDelta)]);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
// console.log("json-stable-stringify ???")
|
|
79
|
-
if (!patchedDelta) {
|
|
80
|
-
remaining.push(current);
|
|
81
|
-
}
|
|
82
|
-
}));
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* There is a decent chance the patch update will fail.
|
|
87
|
-
* As such, to prevent sync batch update failures, the patched updates are updated separately.
|
|
88
|
-
* If patch update fails then sync batch normally without patch.
|
|
89
|
-
*/
|
|
90
|
-
if (patched.length) {
|
|
91
|
-
try {
|
|
92
|
-
await ((_b = this.tableHandler) === null || _b === void 0 ? void 0 : _b.updateBatch(patched));
|
|
93
|
-
}
|
|
94
|
-
catch (e) {
|
|
95
|
-
console.log("failed to patch update", e);
|
|
96
|
-
remaining = remaining.concat(patchedItems);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
return remaining.filter((d) => d);
|
|
100
|
-
};
|
|
101
31
|
/**
|
|
102
32
|
* Notifies multi subs with ALL data + deltas. Attaches handles on data if required
|
|
103
33
|
* @param newData -> updates. Must include id_fields + updates
|
|
@@ -132,22 +62,13 @@ class SyncedTable {
|
|
|
132
62
|
ids.push(idObj);
|
|
133
63
|
}
|
|
134
64
|
});
|
|
135
|
-
if (this.
|
|
65
|
+
if (this.multiSubscriptions.length) {
|
|
136
66
|
const allItems = [], allDeltas = [];
|
|
137
67
|
this.getItems().map((d) => {
|
|
138
68
|
allItems.push({ ...d });
|
|
139
69
|
const dIdx = items.findIndex((_d) => this.matchesIdObj(d, _d));
|
|
140
70
|
allDeltas.push(deltas[dIdx]);
|
|
141
71
|
});
|
|
142
|
-
/* Notify main subscription */
|
|
143
|
-
if (this.onChange) {
|
|
144
|
-
try {
|
|
145
|
-
this.onChange(allItems, allDeltas);
|
|
146
|
-
}
|
|
147
|
-
catch (e) {
|
|
148
|
-
console.error("SyncedTable failed to notify onChange: ", e);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
72
|
/* Multisubs must not forget about the original filter */
|
|
152
73
|
this.multiSubscriptions.map(async (s) => {
|
|
153
74
|
try {
|
|
@@ -162,7 +83,6 @@ class SyncedTable {
|
|
|
162
83
|
this.unsubscribe = (onChange) => {
|
|
163
84
|
this.singleSubscriptions = this.singleSubscriptions.filter((s) => s._onChange !== onChange);
|
|
164
85
|
this.multiSubscriptions = this.multiSubscriptions.filter((s) => s._onChange !== onChange);
|
|
165
|
-
(0, exports.debug)("unsubscribe", this);
|
|
166
86
|
return "ok";
|
|
167
87
|
};
|
|
168
88
|
this.unsync = () => {
|
|
@@ -174,7 +94,6 @@ class SyncedTable {
|
|
|
174
94
|
this.multiSubscriptions = [];
|
|
175
95
|
this.singleSubscriptions = [];
|
|
176
96
|
this.itemsMap.clear();
|
|
177
|
-
this.onChange = undefined;
|
|
178
97
|
};
|
|
179
98
|
this.delete = async (item, from_server = false) => {
|
|
180
99
|
var _a;
|
|
@@ -318,53 +237,27 @@ class SyncedTable {
|
|
|
318
237
|
*/
|
|
319
238
|
this.setItems = (_items) => {
|
|
320
239
|
const items = (0, exports.quickClone)(_items);
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
}
|
|
326
|
-
else if (this.storageType === STORAGE_TYPES.map) {
|
|
327
|
-
this.itemsMap = new Map(items.map((item) => {
|
|
328
|
-
const id = this.getIdStr(item);
|
|
329
|
-
return [id, { ...item }];
|
|
330
|
-
}));
|
|
331
|
-
}
|
|
240
|
+
this.itemsMap = new Map(items.map((item) => {
|
|
241
|
+
const id = this.getIdStr(item);
|
|
242
|
+
return [id, { ...item }];
|
|
243
|
+
}));
|
|
332
244
|
};
|
|
333
245
|
/**
|
|
334
246
|
* Returns the current data ordered by synced_field ASC and matching the main filter;
|
|
335
247
|
*/
|
|
336
248
|
this.getItems = () => {
|
|
337
249
|
let items = [];
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
else if (this.storageType === STORAGE_TYPES.map) {
|
|
352
|
-
items = Array.from(this.itemsMap.values()).map((d) => ({ ...d }));
|
|
353
|
-
}
|
|
354
|
-
if (this.id_fields.length && this.synced_field) {
|
|
355
|
-
const s_fields = [this.synced_field, ...this.id_fields.sort()];
|
|
356
|
-
items = items
|
|
357
|
-
.filter((d) => {
|
|
358
|
-
return !this.filter || !(0, prostgles_types_1.getKeys)(this.filter).find((key) => d[key] !== this.filter[key]);
|
|
359
|
-
})
|
|
360
|
-
.sort((a, b) => s_fields
|
|
361
|
-
.map((key) => (a[key] < b[key] ? -1
|
|
362
|
-
: a[key] > b[key] ? 1
|
|
363
|
-
: 0))
|
|
364
|
-
.find((v) => v));
|
|
365
|
-
}
|
|
366
|
-
else
|
|
367
|
-
throw "id_fields AND/OR synced_field missing";
|
|
250
|
+
items = Array.from(this.itemsMap.values()).map((d) => ({ ...d }));
|
|
251
|
+
const syncFields = [this.synced_field, ...this.id_fields.sort()];
|
|
252
|
+
items = items
|
|
253
|
+
.filter((d) => {
|
|
254
|
+
return !this.filter || !(0, prostgles_types_1.getKeys)(this.filter).find((key) => d[key] !== this.filter[key]);
|
|
255
|
+
})
|
|
256
|
+
.sort((a, b) => syncFields
|
|
257
|
+
.map((key) => (a[key] < b[key] ? -1
|
|
258
|
+
: a[key] > b[key] ? 1
|
|
259
|
+
: 0))
|
|
260
|
+
.find((v) => v));
|
|
368
261
|
return (0, exports.quickClone)(items);
|
|
369
262
|
};
|
|
370
263
|
/**
|
|
@@ -376,27 +269,24 @@ class SyncedTable {
|
|
|
376
269
|
.map((c) => ({ ...c }))
|
|
377
270
|
.filter((c) => (!Number.isFinite(from_synced) || +c[this.synced_field] >= +from_synced) &&
|
|
378
271
|
(!Number.isFinite(to_synced) || +c[this.synced_field] <= +to_synced));
|
|
379
|
-
if (offset || limit)
|
|
272
|
+
if (offset || limit) {
|
|
380
273
|
res = res.splice(offset !== null && offset !== void 0 ? offset : 0, limit || res.length);
|
|
274
|
+
}
|
|
381
275
|
return res;
|
|
382
276
|
};
|
|
383
277
|
this.name = name;
|
|
384
278
|
this.filter = filter;
|
|
385
279
|
this.select = select;
|
|
386
|
-
this.onChange = onChange;
|
|
387
280
|
if (onDebug) {
|
|
388
|
-
this.onDebug = (evt) => onDebug({
|
|
281
|
+
this.onDebug = (evt) => onDebug({
|
|
282
|
+
...evt,
|
|
283
|
+
type: "sync",
|
|
284
|
+
tableName: name,
|
|
285
|
+
channelName: (0, prostgles_types_1.getSyncChannelName)({ filter, select, tableName: name }),
|
|
286
|
+
syncedTable: this,
|
|
287
|
+
}, this);
|
|
288
|
+
this.onDebug({ command: "create", data: { name, filter, select } });
|
|
389
289
|
}
|
|
390
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
391
|
-
if (!STORAGE_TYPES[storageType])
|
|
392
|
-
throw "Invalid storage type. Expecting one of: " + Object.keys(STORAGE_TYPES).join(", ");
|
|
393
|
-
if (!hasWnd && storageType === STORAGE_TYPES.localStorage) {
|
|
394
|
-
console.warn("Could not set storageType to localStorage: window object missing\nStorage changed to map");
|
|
395
|
-
storageType = "map";
|
|
396
|
-
}
|
|
397
|
-
this.storageType = storageType;
|
|
398
|
-
this.patchText = patchText;
|
|
399
|
-
this.patchJSON = patchJSON;
|
|
400
290
|
const tableHandler = db[name];
|
|
401
291
|
if (!tableHandler)
|
|
402
292
|
throw `${name} table not found in db`;
|
|
@@ -411,7 +301,6 @@ class SyncedTable {
|
|
|
411
301
|
this.synced_field = synced_field;
|
|
412
302
|
this.batch_size = batch_size;
|
|
413
303
|
this.throttle = throttle;
|
|
414
|
-
this.skipFirstTrigger = skipFirstTrigger;
|
|
415
304
|
this.multiSubscriptions = [];
|
|
416
305
|
this.singleSubscriptions = [];
|
|
417
306
|
this.onError =
|
|
@@ -492,18 +381,7 @@ class SyncedTable {
|
|
|
492
381
|
window.onbeforeunload = confirmExit;
|
|
493
382
|
},
|
|
494
383
|
onSend: async (data, walData) => {
|
|
495
|
-
|
|
496
|
-
// const textCols = this.columns.filter(c => c.data_type.toLowerCase().startsWith("text"));
|
|
497
|
-
// data = await Promise.all(data.map(d => {
|
|
498
|
-
// const dataTextCols = Object.keys(d).filter(k => textCols.find(tc => tc.name === k));
|
|
499
|
-
// if(dataTextCols.length){
|
|
500
|
-
// /* Create text patches and update separately */
|
|
501
|
-
// dada
|
|
502
|
-
// }
|
|
503
|
-
// return d;
|
|
504
|
-
// }))
|
|
505
|
-
// }
|
|
506
|
-
const _data = await this.updatePatches(walData);
|
|
384
|
+
const _data = walData.map((d) => d.current);
|
|
507
385
|
if (!_data.length)
|
|
508
386
|
return [];
|
|
509
387
|
return this.dbSync.syncData(data);
|
|
@@ -535,10 +413,6 @@ class SyncedTable {
|
|
|
535
413
|
this.columns = cols;
|
|
536
414
|
});
|
|
537
415
|
}
|
|
538
|
-
if (this.onChange && !this.skipFirstTrigger) {
|
|
539
|
-
setTimeout(this.onChange, 0);
|
|
540
|
-
}
|
|
541
|
-
(0, exports.debug)(this);
|
|
542
416
|
}
|
|
543
417
|
static create(opts) {
|
|
544
418
|
return new Promise((resolve, reject) => {
|
|
@@ -550,6 +424,10 @@ class SyncedTable {
|
|
|
550
424
|
resolve(res);
|
|
551
425
|
}, 0);
|
|
552
426
|
},
|
|
427
|
+
onError: (err) => {
|
|
428
|
+
console.error("Sync internal error: ", err);
|
|
429
|
+
reject(err);
|
|
430
|
+
},
|
|
553
431
|
});
|
|
554
432
|
}
|
|
555
433
|
catch (err) {
|
|
@@ -568,18 +446,13 @@ class SyncedTable {
|
|
|
568
446
|
handlesOnData,
|
|
569
447
|
});
|
|
570
448
|
this.multiSubscriptions.push(sub);
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
}, 0);
|
|
576
|
-
}
|
|
449
|
+
setTimeout(() => {
|
|
450
|
+
const items = this.getItems();
|
|
451
|
+
sub.notify(items, items);
|
|
452
|
+
}, 0);
|
|
577
453
|
return Object.freeze({ ...handles });
|
|
578
454
|
}
|
|
579
455
|
makeSingleSyncHandles(idObj, onChange) {
|
|
580
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
581
|
-
if (!idObj || !onChange)
|
|
582
|
-
throw `syncOne(idObj, onChange) -> MISSING idObj or onChange`;
|
|
583
456
|
const handles = {
|
|
584
457
|
$get: () => this.getItem(idObj),
|
|
585
458
|
$find: (idObject) => this.getItem(idObject),
|
|
@@ -593,7 +466,6 @@ class SyncedTable {
|
|
|
593
466
|
/* DROPPED SYNC BUG */
|
|
594
467
|
if (!this.singleSubscriptions.length && !this.multiSubscriptions.length) {
|
|
595
468
|
console.warn("No sync listeners");
|
|
596
|
-
(0, exports.debug)("nosync", this._singleSubscriptions, this._multiSubscriptions);
|
|
597
469
|
}
|
|
598
470
|
return this.upsert([{ idObj, delta: newData, opts }]);
|
|
599
471
|
},
|
|
@@ -730,14 +602,7 @@ class SyncedTable {
|
|
|
730
602
|
}
|
|
731
603
|
/* Returns an item by idObj from the local store */
|
|
732
604
|
getItem(idObj) {
|
|
733
|
-
|
|
734
|
-
if (this.storageType === STORAGE_TYPES.localStorage) {
|
|
735
|
-
const items = this.getItems();
|
|
736
|
-
d = items.find((d) => this.matchesIdObj(d, idObj));
|
|
737
|
-
}
|
|
738
|
-
else {
|
|
739
|
-
d = this.itemsMap.get(this.getIdStr(idObj));
|
|
740
|
-
}
|
|
605
|
+
const d = this.itemsMap.get(this.getIdStr(idObj));
|
|
741
606
|
return (0, exports.quickClone)(d);
|
|
742
607
|
}
|
|
743
608
|
/**
|
|
@@ -750,37 +615,13 @@ class SyncedTable {
|
|
|
750
615
|
setItem(_item, isFullData = false, deleteItem = false) {
|
|
751
616
|
var _a;
|
|
752
617
|
const item = (0, exports.quickClone)(_item);
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
items = items.filter((d) => !this.matchesIdObj(d, item));
|
|
757
|
-
}
|
|
758
|
-
else {
|
|
759
|
-
let exists = false;
|
|
760
|
-
items = items.map((d) => {
|
|
761
|
-
if (this.matchesIdObj(d, item)) {
|
|
762
|
-
exists = true;
|
|
763
|
-
return isFullData ? { ...item } : { ...d, ...item };
|
|
764
|
-
}
|
|
765
|
-
return d;
|
|
766
|
-
});
|
|
767
|
-
if (!exists) {
|
|
768
|
-
items.push(item);
|
|
769
|
-
}
|
|
770
|
-
}
|
|
771
|
-
if (hasWnd) {
|
|
772
|
-
window.localStorage.setItem(this.name, JSON.stringify(items));
|
|
773
|
-
}
|
|
618
|
+
const id = this.getIdStr(item);
|
|
619
|
+
if (deleteItem) {
|
|
620
|
+
this.itemsMap.delete(id);
|
|
774
621
|
}
|
|
775
622
|
else {
|
|
776
|
-
const
|
|
777
|
-
|
|
778
|
-
this.itemsMap.delete(id);
|
|
779
|
-
}
|
|
780
|
-
else {
|
|
781
|
-
const existing = (_a = this.itemsMap.get(id)) !== null && _a !== void 0 ? _a : {};
|
|
782
|
-
this.itemsMap.set(id, isFullData ? { ...item } : { ...existing, ...item });
|
|
783
|
-
}
|
|
623
|
+
const existing = (_a = this.itemsMap.get(id)) !== null && _a !== void 0 ? _a : {};
|
|
624
|
+
this.itemsMap.set(id, isFullData ? { ...item } : { ...existing, ...item });
|
|
784
625
|
}
|
|
785
626
|
}
|
|
786
627
|
}
|
|
@@ -821,12 +662,3 @@ const quickClone = (obj) => {
|
|
|
821
662
|
return obj;
|
|
822
663
|
};
|
|
823
664
|
exports.quickClone = quickClone;
|
|
824
|
-
/**
|
|
825
|
-
* Type tests
|
|
826
|
-
*/
|
|
827
|
-
const typeTest = async () => {
|
|
828
|
-
const s = 1;
|
|
829
|
-
const sh = s({ a: 1 }, {}, (d) => { });
|
|
830
|
-
const syncTyped = 1;
|
|
831
|
-
// const sUntyped: Sync<AnyObject, any> = syncTyped;
|
|
832
|
-
};
|
package/dist/getDbHandler.js
CHANGED
|
@@ -96,14 +96,14 @@ const getDB = ({ tableSchema, onDebug, syncedTable, syncHandler, subscriptionHan
|
|
|
96
96
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
97
97
|
(0, useSync_1.useSync)(syncOne, basicFilter, options, hookOptions);
|
|
98
98
|
}
|
|
99
|
-
dboTable._sync = async function (
|
|
99
|
+
dboTable._sync = async function (filter, select, syncHandles) {
|
|
100
100
|
await (onDebug === null || onDebug === void 0 ? void 0 : onDebug({
|
|
101
101
|
type: "table",
|
|
102
102
|
command: "_sync",
|
|
103
103
|
tableName,
|
|
104
|
-
data: {
|
|
104
|
+
data: { filter, select, syncHandles },
|
|
105
105
|
}));
|
|
106
|
-
return syncHandler.addSync({ tableName, command,
|
|
106
|
+
return syncHandler.addSync({ tableName, command, filter, select }, syncHandles);
|
|
107
107
|
};
|
|
108
108
|
}
|
|
109
109
|
else if (subscribeCommands.includes(command)) {
|
package/dist/getSyncHandler.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { type ClientSyncHandles } from "prostgles-types";
|
|
2
|
-
import type {
|
|
2
|
+
import type { InitOptions, SyncParams } from "./prostgles";
|
|
3
3
|
import type { SyncedTable } from "./SyncedTable/SyncedTable";
|
|
4
4
|
export declare const getSyncHandler: ({ socket, onDebug }: Pick<InitOptions, "socket" | "onDebug">) => {
|
|
5
5
|
destroySyncs: () => Promise<void>;
|
|
6
6
|
syncedTables: Map<string, Promise<SyncedTable>>;
|
|
7
|
-
addSync: (params:
|
|
7
|
+
addSync: (params: SyncParams, triggers: ClientSyncHandles) => Promise<any>;
|
|
8
8
|
reAttachAll: () => Promise<void>;
|
|
9
9
|
};
|
|
10
10
|
//# sourceMappingURL=getSyncHandler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getSyncHandler.d.ts","sourceRoot":"","sources":["../lib/getSyncHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,KAAK,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAElF,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"getSyncHandler.d.ts","sourceRoot":"","sources":["../lib/getSyncHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,KAAK,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAElF,OAAO,KAAK,EAA2B,WAAW,EAAY,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9F,OAAO,KAAK,EAAe,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAQ1E,eAAO,MAAM,cAAc,GAAI,qBAAqB,IAAI,CAAC,WAAW,EAAE,QAAQ,GAAG,SAAS,CAAC;;;sBAoE1D,UAAU,YAAY,iBAAiB,KAAG,OAAO,CAAC,GAAG,CAAC;;CAiJtF,CAAC"}
|
package/dist/getSyncHandler.js
CHANGED
|
@@ -36,9 +36,15 @@ const getSyncHandler = ({ socket, onDebug }) => {
|
|
|
36
36
|
}
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
|
-
function addServerSync({ tableName, command,
|
|
39
|
+
function addServerSync({ tableName, command, filter, select }, onSyncRequest) {
|
|
40
40
|
return new Promise((resolve, reject) => {
|
|
41
|
-
socket.emit(prostgles_types_1.CHANNEL_PREFIX, { tableName, command, param1, param2 }, (err, syncInfo) => {
|
|
41
|
+
socket.emit(prostgles_types_1.CHANNEL_PREFIX, { tableName, command, param1: filter, param2: select }, (err, syncInfo) => {
|
|
42
|
+
onDebug === null || onDebug === void 0 ? void 0 : onDebug({
|
|
43
|
+
type: "table",
|
|
44
|
+
command: "getSync",
|
|
45
|
+
tableName,
|
|
46
|
+
data: { filter, select },
|
|
47
|
+
});
|
|
42
48
|
if (err) {
|
|
43
49
|
console.error(err);
|
|
44
50
|
reject(err);
|
|
@@ -57,7 +63,7 @@ const getSyncHandler = ({ socket, onDebug }) => {
|
|
|
57
63
|
async function addSync(params, triggers) {
|
|
58
64
|
return addSyncQueuer.run([params, triggers]);
|
|
59
65
|
}
|
|
60
|
-
async function _addSync({ tableName, command,
|
|
66
|
+
async function _addSync({ tableName, command, filter, select }, clientSyncHandlers) {
|
|
61
67
|
const { onSyncRequest } = clientSyncHandlers;
|
|
62
68
|
function makeHandler(channelName) {
|
|
63
69
|
const unsync = function () {
|
|
@@ -79,8 +85,8 @@ const getSyncHandler = ({ socket, onDebug }) => {
|
|
|
79
85
|
const matchingSync = Array.from(syncs.entries()).find(([ch, s]) => {
|
|
80
86
|
return (s.tableName === tableName &&
|
|
81
87
|
s.command === command &&
|
|
82
|
-
(0, prostgles_types_1.isEqual)(s.
|
|
83
|
-
(0, prostgles_types_1.isEqual)(s.
|
|
88
|
+
(0, prostgles_types_1.isEqual)(s.filter, filter) &&
|
|
89
|
+
(0, prostgles_types_1.isEqual)(s.select, select));
|
|
84
90
|
});
|
|
85
91
|
if (matchingSync) {
|
|
86
92
|
const [existingChannel, existingSync] = matchingSync;
|
|
@@ -88,7 +94,7 @@ const getSyncHandler = ({ socket, onDebug }) => {
|
|
|
88
94
|
return makeHandler(existingChannel);
|
|
89
95
|
}
|
|
90
96
|
else {
|
|
91
|
-
const sync_info = await addServerSync({ tableName, command,
|
|
97
|
+
const sync_info = await addServerSync({ tableName, command, filter, select }, onSyncRequest);
|
|
92
98
|
const { channelName } = sync_info;
|
|
93
99
|
const onCall = function (data, cb) {
|
|
94
100
|
/*
|
|
@@ -104,15 +110,18 @@ const getSyncHandler = ({ socket, onDebug }) => {
|
|
|
104
110
|
if (!matchingSync)
|
|
105
111
|
return;
|
|
106
112
|
matchingSync.clientSyncHandles.map(({ onUpdates, onSyncRequest, onPullRequest }) => {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
:
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
113
|
+
var _a;
|
|
114
|
+
(_a = syncedTables.get(channelName)) === null || _a === void 0 ? void 0 : _a.then((syncedTable) => {
|
|
115
|
+
onDebug === null || onDebug === void 0 ? void 0 : onDebug({
|
|
116
|
+
type: "sync",
|
|
117
|
+
command: data.data ? "onUpdates"
|
|
118
|
+
: data.onSyncRequest ? "onSyncRequest"
|
|
119
|
+
: "onPullRequest",
|
|
120
|
+
tableName,
|
|
121
|
+
channelName,
|
|
122
|
+
data,
|
|
123
|
+
syncedTable,
|
|
124
|
+
});
|
|
116
125
|
});
|
|
117
126
|
if (data.data) {
|
|
118
127
|
Promise.resolve(onUpdates(data))
|
|
@@ -147,8 +156,8 @@ const getSyncHandler = ({ socket, onDebug }) => {
|
|
|
147
156
|
syncs.set(channelName, {
|
|
148
157
|
tableName,
|
|
149
158
|
command,
|
|
150
|
-
|
|
151
|
-
|
|
159
|
+
filter,
|
|
160
|
+
select,
|
|
152
161
|
clientSyncHandles: [clientSyncHandlers],
|
|
153
162
|
syncInfo: sync_info,
|
|
154
163
|
onCall,
|