@instantdb/core 0.22.86-experimental.separate-attrs.20122276424.1 → 0.22.86-experimental.split-store.20178922132.1
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/commonjs/Reactor.d.ts +20 -6
- package/dist/commonjs/Reactor.d.ts.map +1 -1
- package/dist/commonjs/Reactor.js +97 -42
- package/dist/commonjs/Reactor.js.map +1 -1
- package/dist/commonjs/SyncTable.d.ts +4 -1
- package/dist/commonjs/SyncTable.d.ts.map +1 -1
- package/dist/commonjs/SyncTable.js +35 -37
- package/dist/commonjs/SyncTable.js.map +1 -1
- package/dist/commonjs/instaml.d.ts +17 -4
- package/dist/commonjs/instaml.d.ts.map +1 -1
- package/dist/commonjs/instaml.js +105 -76
- package/dist/commonjs/instaml.js.map +1 -1
- package/dist/commonjs/instaql.d.ts +2 -1
- package/dist/commonjs/instaql.d.ts.map +1 -1
- package/dist/commonjs/instaql.js +65 -63
- package/dist/commonjs/instaql.js.map +1 -1
- package/dist/commonjs/reactorTypes.d.ts +29 -0
- package/dist/commonjs/reactorTypes.d.ts.map +1 -0
- package/dist/commonjs/reactorTypes.js +3 -0
- package/dist/commonjs/reactorTypes.js.map +1 -0
- package/dist/commonjs/store.d.ts +44 -21
- package/dist/commonjs/store.d.ts.map +1 -1
- package/dist/commonjs/store.js +164 -69
- package/dist/commonjs/store.js.map +1 -1
- package/dist/esm/Reactor.d.ts +20 -6
- package/dist/esm/Reactor.d.ts.map +1 -1
- package/dist/esm/Reactor.js +98 -43
- package/dist/esm/Reactor.js.map +1 -1
- package/dist/esm/SyncTable.d.ts +4 -1
- package/dist/esm/SyncTable.d.ts.map +1 -1
- package/dist/esm/SyncTable.js +35 -37
- package/dist/esm/SyncTable.js.map +1 -1
- package/dist/esm/instaml.d.ts +17 -4
- package/dist/esm/instaml.d.ts.map +1 -1
- package/dist/esm/instaml.js +102 -71
- package/dist/esm/instaml.js.map +1 -1
- package/dist/esm/instaql.d.ts +2 -1
- package/dist/esm/instaql.d.ts.map +1 -1
- package/dist/esm/instaql.js +65 -63
- package/dist/esm/instaql.js.map +1 -1
- package/dist/esm/reactorTypes.d.ts +29 -0
- package/dist/esm/reactorTypes.d.ts.map +1 -0
- package/dist/esm/reactorTypes.js +2 -0
- package/dist/esm/reactorTypes.js.map +1 -0
- package/dist/esm/store.d.ts +44 -21
- package/dist/esm/store.d.ts.map +1 -1
- package/dist/esm/store.js +161 -69
- package/dist/esm/store.js.map +1 -1
- package/dist/standalone/index.js +1517 -1345
- package/dist/standalone/index.umd.cjs +3 -3
- package/package.json +2 -2
- package/src/Reactor.js +126 -58
- package/src/SyncTable.ts +85 -45
- package/src/{instaml.js → instaml.ts} +195 -95
- package/src/instaql.ts +86 -60
- package/src/reactorTypes.ts +32 -0
- package/src/store.ts +209 -79
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export default class Reactor<RoomSchema extends import("./presence.ts").RoomSchemaShape = {}> {
|
|
5
5
|
constructor(config: any, Storage: typeof IndexedDBStorage | undefined, NetworkListener: typeof WindowNetworkListener | undefined, versions: any, EventSourceConstructor: any);
|
|
6
|
-
|
|
6
|
+
/** @type {sts.AttrsStore | undefined} */
|
|
7
|
+
attrs: sts.AttrsStore | undefined;
|
|
7
8
|
_isOnline: boolean;
|
|
8
9
|
_isShutdown: boolean;
|
|
9
10
|
status: string;
|
|
10
|
-
/** @type {PersistedObject} */
|
|
11
|
-
querySubs: PersistedObject<
|
|
11
|
+
/** @type {PersistedObject<string, QuerySub, QuerySubInStorage>} */
|
|
12
|
+
querySubs: PersistedObject<string, QuerySub, QuerySubInStorage>;
|
|
12
13
|
/** @type {PersistedObject} */
|
|
13
14
|
kv: PersistedObject<any, any, any>;
|
|
14
15
|
/** @type {SyncTable} */
|
|
@@ -78,6 +79,7 @@ export default class Reactor<RoomSchema extends import("./presence.ts").RoomSche
|
|
|
78
79
|
queryCacheLimit: any;
|
|
79
80
|
versions: any;
|
|
80
81
|
_beforeUnload(): void;
|
|
82
|
+
ensureAttrs(): sts.AttrsStore;
|
|
81
83
|
updateSchema(schema: any): void;
|
|
82
84
|
_reactorStats(): {
|
|
83
85
|
inFlightMutationCount: number;
|
|
@@ -139,12 +141,21 @@ export default class Reactor<RoomSchema extends import("./presence.ts").RoomSche
|
|
|
139
141
|
_unsubQuery(q: any, hash: any, cb: any): void;
|
|
140
142
|
_hasQueryListeners(hash: any): boolean;
|
|
141
143
|
_cleanupQuery(q: any, hash: any): void;
|
|
142
|
-
|
|
144
|
+
/**
|
|
145
|
+
*
|
|
146
|
+
* @param {sts.AttrsStore} attrs
|
|
147
|
+
* @param {any} muts
|
|
148
|
+
* @param {number} [processedTxId]
|
|
149
|
+
*/
|
|
150
|
+
_rewriteMutations(attrs: sts.AttrsStore, muts: any, processedTxId?: number): any;
|
|
143
151
|
_rewriteMutationsSorted(attrs: any, muts: any): any[];
|
|
144
|
-
|
|
152
|
+
/**
|
|
153
|
+
* @returns {sts.AttrsStore}
|
|
154
|
+
*/
|
|
155
|
+
optimisticAttrs(): sts.AttrsStore;
|
|
145
156
|
/** Runs instaql on a query and a store */
|
|
146
157
|
dataForQuery(hash: any): any;
|
|
147
|
-
_applyOptimisticUpdates(store: any, mutations: any, processedTxId: any): any;
|
|
158
|
+
_applyOptimisticUpdates(store: any, attrsStore: any, mutations: any, processedTxId: any): any;
|
|
148
159
|
/** Re-run instaql and call all callbacks with new data */
|
|
149
160
|
notifyOne: (hash: any) => void;
|
|
150
161
|
notifyOneQueryOnce: (hash: any) => void;
|
|
@@ -338,6 +349,9 @@ export type Logger = import("./utils/log.ts").Logger;
|
|
|
338
349
|
export type Connection = import("./Connection.ts").Connection<any>;
|
|
339
350
|
export type TransportType = import("./Connection.ts").TransportType;
|
|
340
351
|
export type EventSourceConstructor = import("./Connection.ts").EventSourceConstructor;
|
|
352
|
+
export type QuerySub = import("./reactorTypes.ts").QuerySub;
|
|
353
|
+
export type QuerySubInStorage = import("./reactorTypes.ts").QuerySubInStorage;
|
|
354
|
+
import * as sts from './store.ts';
|
|
341
355
|
import { PersistedObject } from './utils/PersistedObject.ts';
|
|
342
356
|
import { SyncTable } from './SyncTable.ts';
|
|
343
357
|
import { Deferred } from './utils/Deferred.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Reactor.d.ts","sourceRoot":"","sources":["../../src/Reactor.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Reactor.d.ts","sourceRoot":"","sources":["../../src/Reactor.js"],"names":[],"mappings":"AAyMA;;GAEG;AACH,6BAFwD,UAAU,SAArD,OAAQ,eAAe,EAAE,eAAgB;IAmEpD,8KAiHC;IAjLD,yCAAyC;IACzC,OADW,GAAG,CAAC,UAAU,GAAG,SAAS,CAC/B;IACN,mBAAiB;IACjB,qBAAoB;IACpB,eAA2B;IAE3B,mEAAmE;IACnE,WADW,eAAe,CAAC,MAAM,EAAE,QAAQ,EAAE,iBAAiB,CAAC,CACrD;IAEV,8BAA8B;IAC9B,mCAAG;IAEH,wBAAwB;IACxB,YADW,SAAS,CACT;IAEX,wEAAwE;IACxE,UADW,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC;QAAE,CAAC,EAAE,GAAG,CAAC;QAAC,EAAE,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,GAAG,CAAA;KAAE,CAAC,CAAC,CACtD;IACd,gFAAgF;IAChF,eADW,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC;QAAE,CAAC,EAAE,GAAG,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,QAAQ,CAAA;KAAE,CAAC,CAAC,CACzD;IACnB,eAAa;IACb,gBAAc;IACd,wBAAsB;IACtB,2BAAyB;IACzB,YAAO;IACP,qCAAkC;IAClC,0BAA2B;IAC3B,4BAAwB;IACxB,yBAAyB;IACzB,YADW,UAAU,CACV;IACX,4BAA4B;IAC5B,gBADW,aAAa,CACF;IAEtB,qCAAqC;IACrC,c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;qBAr3Ea,OAAO,gBAAgB,EAAE,MAAM;;4BAE/B,OAAO,iBAAiB,EAAE,aAAa;qCACvC,OAAO,iBAAiB,EAAE,sBAAsB;uBAChD,OAAO,mBAAmB,EAAE,QAAQ;gCACpC,OAAO,mBAAmB,EAAE,iBAAiB;qBAnCtC,YAAY;gCASD,4BAA4B;0BAmBlC,gBAAgB;yBApBjB,qBAAqB;yBAJrB,cAAc;4BACX,iBAAiB;6BAHhB,uBAAuB;kCAClB,4BAA4B"}
|
package/dist/commonjs/Reactor.js
CHANGED
|
@@ -60,7 +60,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
60
60
|
const weakHash_ts_1 = __importDefault(require("./utils/weakHash.js"));
|
|
61
61
|
const instaql_ts_1 = __importDefault(require("./instaql.js"));
|
|
62
62
|
const instaml = __importStar(require("./instaml.js"));
|
|
63
|
-
const
|
|
63
|
+
const sts = __importStar(require("./store.js"));
|
|
64
64
|
const uuid_ts_1 = __importDefault(require("./utils/uuid.js"));
|
|
65
65
|
const IndexedDBStorage_ts_1 = __importDefault(require("./IndexedDBStorage.js"));
|
|
66
66
|
const WindowNetworkListener_js_1 = __importDefault(require("./WindowNetworkListener.js"));
|
|
@@ -87,6 +87,8 @@ const SyncTable_ts_1 = require("./SyncTable.js");
|
|
|
87
87
|
/** @typedef {import('./Connection.ts').Connection} Connection */
|
|
88
88
|
/** @typedef {import('./Connection.ts').TransportType} TransportType */
|
|
89
89
|
/** @typedef {import('./Connection.ts').EventSourceConstructor} EventSourceConstructor */
|
|
90
|
+
/** @typedef {import('./reactorTypes.ts').QuerySub} QuerySub */
|
|
91
|
+
/** @typedef {import('./reactorTypes.ts').QuerySubInStorage} QuerySubInStorage */
|
|
90
92
|
const STATUS = {
|
|
91
93
|
CONNECTING: 'connecting',
|
|
92
94
|
OPENED: 'opened',
|
|
@@ -139,20 +141,37 @@ const ignoreLogging = {
|
|
|
139
141
|
'refresh-presence': true,
|
|
140
142
|
'patch-presence': true,
|
|
141
143
|
};
|
|
144
|
+
/**
|
|
145
|
+
* @param {QuerySubInStorage} x
|
|
146
|
+
* @param {boolean | null} useDateObjects
|
|
147
|
+
* @returns {QuerySub}
|
|
148
|
+
*/
|
|
142
149
|
function querySubFromStorage(x, useDateObjects) {
|
|
143
150
|
var _a;
|
|
144
151
|
const v = typeof x === 'string' ? JSON.parse(x) : x;
|
|
145
152
|
if ((_a = v === null || v === void 0 ? void 0 : v.result) === null || _a === void 0 ? void 0 : _a.store) {
|
|
146
|
-
const
|
|
147
|
-
|
|
153
|
+
const attrsStore = sts.attrsStoreFromJSON(v.result.attrsStore, v.result.store);
|
|
154
|
+
if (attrsStore) {
|
|
155
|
+
const storeJSON = v.result.store;
|
|
156
|
+
v.result.store = sts.fromJSON(attrsStore, Object.assign(Object.assign({}, storeJSON), { useDateObjects: useDateObjects }));
|
|
157
|
+
v.result.attrsStore = attrsStore;
|
|
158
|
+
}
|
|
148
159
|
}
|
|
149
160
|
return v;
|
|
150
161
|
}
|
|
162
|
+
/**
|
|
163
|
+
*
|
|
164
|
+
* @param {string} _key
|
|
165
|
+
* @param {QuerySub} sub
|
|
166
|
+
* @returns QuerySubInStorage
|
|
167
|
+
*/
|
|
151
168
|
function querySubToStorage(_key, sub) {
|
|
152
|
-
|
|
153
|
-
const jsonSub =
|
|
154
|
-
if (
|
|
155
|
-
|
|
169
|
+
const { result } = sub, rest = __rest(sub, ["result"]);
|
|
170
|
+
const jsonSub = /** @type {import('./reactorTypes.ts').QuerySubInStorage} */ (rest);
|
|
171
|
+
if (result) {
|
|
172
|
+
/** @type {import('./reactorTypes.ts').QuerySubResultInStorage} */
|
|
173
|
+
const jsonResult = Object.assign(Object.assign({}, result), { store: sts.toJSON(result.store), attrsStore: result.attrsStore.toJSON() });
|
|
174
|
+
jsonSub.result = jsonResult;
|
|
156
175
|
}
|
|
157
176
|
return jsonSub;
|
|
158
177
|
}
|
|
@@ -297,7 +316,7 @@ class Reactor {
|
|
|
297
316
|
}
|
|
298
317
|
try {
|
|
299
318
|
const txSteps = instaml.transform({
|
|
300
|
-
|
|
319
|
+
attrsStore: this.optimisticAttrs(),
|
|
301
320
|
schema: this.config.schema,
|
|
302
321
|
stores: Object.values(this.querySubs.currentValue).map((sub) => { var _a; return (_a = sub === null || sub === void 0 ? void 0 : sub.result) === null || _a === void 0 ? void 0 : _a.store; }),
|
|
303
322
|
useDateObjects: this.config.useDateObjects,
|
|
@@ -463,7 +482,9 @@ class Reactor {
|
|
|
463
482
|
this._initStorage(Storage);
|
|
464
483
|
this._syncTable = new SyncTable_ts_1.SyncTable(this._trySendAuthed.bind(this), new Storage(this.config.appId, 'syncSubs'), {
|
|
465
484
|
useDateObjects: this.config.useDateObjects,
|
|
466
|
-
}, this._log, (triples) =>
|
|
485
|
+
}, this._log, (triples) => {
|
|
486
|
+
return sts.createStore(this.ensureAttrs(), triples, this.config.enableCardinalityInference, this.config.useDateObjects);
|
|
487
|
+
}, () => this.ensureAttrs());
|
|
467
488
|
this._oauthCallbackResponse = this._oauthLoginInit();
|
|
468
489
|
// kick off a request to cache it
|
|
469
490
|
this.getCurrentUser();
|
|
@@ -493,6 +514,12 @@ class Reactor {
|
|
|
493
514
|
addEventListener('beforeunload', this._beforeUnload);
|
|
494
515
|
}
|
|
495
516
|
}
|
|
517
|
+
ensureAttrs() {
|
|
518
|
+
if (!this.attrs) {
|
|
519
|
+
throw new Error('attrs have not loaded.');
|
|
520
|
+
}
|
|
521
|
+
return this.attrs;
|
|
522
|
+
}
|
|
496
523
|
updateSchema(schema) {
|
|
497
524
|
this.config = Object.assign(Object.assign({}, this.config), { schema: schema, cardinalityInference: Boolean(schema) });
|
|
498
525
|
this._linkIndex = schema ? (0, linkIndex_ts_1.createLinkIndex)(this.config.schema) : null;
|
|
@@ -516,7 +543,7 @@ class Reactor {
|
|
|
516
543
|
serialize: querySubToStorage,
|
|
517
544
|
parse: (_key, x) => querySubFromStorage(x, this.config.useDateObjects),
|
|
518
545
|
// objectSize
|
|
519
|
-
objectSize: (x) => { var _a, _b, _c, _d; return (_d = (_c = (_b = (_a = x.result) === null || _a === void 0 ? void 0 : _a.store) === null || _b === void 0 ? void 0 : _b.triples) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0; },
|
|
546
|
+
objectSize: (x) => { var _a, _b, _c, _d; return (_d = (_c = (_b = (_a = x === null || x === void 0 ? void 0 : x.result) === null || _a === void 0 ? void 0 : _a.store) === null || _b === void 0 ? void 0 : _b.triples) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0; },
|
|
520
547
|
logger: this._log,
|
|
521
548
|
preloadEntryCount: 10,
|
|
522
549
|
gc: {
|
|
@@ -650,7 +677,7 @@ class Reactor {
|
|
|
650
677
|
const pageInfo = (_d = (_c = result === null || result === void 0 ? void 0 : result[0]) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d['page-info'];
|
|
651
678
|
const aggregate = (_f = (_e = result === null || result === void 0 ? void 0 : result[0]) === null || _e === void 0 ? void 0 : _e.data) === null || _f === void 0 ? void 0 : _f['aggregate'];
|
|
652
679
|
const triples = (0, instaqlResult_js_1.extractTriples)(result);
|
|
653
|
-
const store =
|
|
680
|
+
const store = sts.createStore(this.ensureAttrs(), triples, enableCardinalityInference, this.config.useDateObjects);
|
|
654
681
|
this.querySubs.updateInPlace((prev) => {
|
|
655
682
|
if (!prev[hash]) {
|
|
656
683
|
this._log.info('Missing value in querySubs', { hash, q });
|
|
@@ -658,6 +685,7 @@ class Reactor {
|
|
|
658
685
|
}
|
|
659
686
|
prev[hash].result = {
|
|
660
687
|
store,
|
|
688
|
+
attrsStore: this.ensureAttrs(),
|
|
661
689
|
pageInfo,
|
|
662
690
|
aggregate,
|
|
663
691
|
processedTxId: msg['processed-tx-id'],
|
|
@@ -692,7 +720,7 @@ class Reactor {
|
|
|
692
720
|
this._setAttrs(attrs);
|
|
693
721
|
}
|
|
694
722
|
this._cleanupPendingMutationsTimeout();
|
|
695
|
-
const rewrittenMutations = this._rewriteMutations(this.
|
|
723
|
+
const rewrittenMutations = this._rewriteMutations(this.ensureAttrs(), this._pendingMutations(), processedTxId);
|
|
696
724
|
if (rewrittenMutations !== this._pendingMutations()) {
|
|
697
725
|
// We know we've changed the mutations to fix the attr ids and removed
|
|
698
726
|
// processed attrs, so we'll persist those changes to prevent optimisticAttrs
|
|
@@ -708,8 +736,8 @@ class Reactor {
|
|
|
708
736
|
const result = x['instaql-result'];
|
|
709
737
|
const hash = (0, weakHash_ts_1.default)(q);
|
|
710
738
|
const triples = (0, instaqlResult_js_1.extractTriples)(result);
|
|
711
|
-
const store =
|
|
712
|
-
const newStore = this._applyOptimisticUpdates(store, mutations, processedTxId);
|
|
739
|
+
const store = sts.createStore(this.ensureAttrs(), triples, enableCardinalityInference, this.config.useDateObjects);
|
|
740
|
+
const newStore = this._applyOptimisticUpdates(store, this.ensureAttrs(), mutations, processedTxId);
|
|
713
741
|
const pageInfo = (_b = (_a = result === null || result === void 0 ? void 0 : result[0]) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b['page-info'];
|
|
714
742
|
const aggregate = (_d = (_c = result === null || result === void 0 ? void 0 : result[0]) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d['aggregate'];
|
|
715
743
|
return { q, hash, store: newStore, pageInfo, aggregate };
|
|
@@ -720,7 +748,13 @@ class Reactor {
|
|
|
720
748
|
this._log.error('Missing value in querySubs', { hash, q });
|
|
721
749
|
return;
|
|
722
750
|
}
|
|
723
|
-
prev[hash].result = {
|
|
751
|
+
prev[hash].result = {
|
|
752
|
+
store,
|
|
753
|
+
attrsStore: this.ensureAttrs(),
|
|
754
|
+
pageInfo,
|
|
755
|
+
aggregate,
|
|
756
|
+
processedTxId,
|
|
757
|
+
};
|
|
724
758
|
});
|
|
725
759
|
});
|
|
726
760
|
this._cleanupPendingMutationsQueries();
|
|
@@ -732,7 +766,7 @@ class Reactor {
|
|
|
732
766
|
case 'transact-ok': {
|
|
733
767
|
const { 'client-event-id': eventId, 'tx-id': txId } = msg;
|
|
734
768
|
this._inFlightMutationEventIds.delete(eventId);
|
|
735
|
-
const muts = this._rewriteMutations(this.
|
|
769
|
+
const muts = this._rewriteMutations(this.ensureAttrs(), this._pendingMutations());
|
|
736
770
|
const prevMutation = muts.get(eventId);
|
|
737
771
|
if (!prevMutation) {
|
|
738
772
|
break;
|
|
@@ -741,11 +775,18 @@ class Reactor {
|
|
|
741
775
|
this._updatePendingMutations((prev) => {
|
|
742
776
|
prev.set(eventId, Object.assign(Object.assign({}, prev.get(eventId)), { 'tx-id': txId, confirmed: Date.now() }));
|
|
743
777
|
});
|
|
744
|
-
const newAttrs =
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
778
|
+
const newAttrs = [];
|
|
779
|
+
for (const step of prevMutation['tx-steps']) {
|
|
780
|
+
if (step[0] === 'add-attr') {
|
|
781
|
+
const attr = step[1];
|
|
782
|
+
newAttrs.push(attr);
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
if (newAttrs.length) {
|
|
786
|
+
const existingAttrs = Object.values(this.ensureAttrs());
|
|
787
|
+
this._setAttrs([...existingAttrs, ...newAttrs]);
|
|
788
|
+
this._setAttrs(newAttrs);
|
|
789
|
+
}
|
|
749
790
|
this._finishTransaction('synced', eventId);
|
|
750
791
|
this._cleanupPendingMutationsTimeout();
|
|
751
792
|
break;
|
|
@@ -906,10 +947,10 @@ class Reactor {
|
|
|
906
947
|
this._completeQueryOnce(q, hash, r.dfd);
|
|
907
948
|
}
|
|
908
949
|
_setAttrs(attrs) {
|
|
909
|
-
this.attrs = attrs.reduce((acc, attr) => {
|
|
950
|
+
this.attrs = new sts.AttrsStore(attrs.reduce((acc, attr) => {
|
|
910
951
|
acc[attr.id] = attr;
|
|
911
952
|
return acc;
|
|
912
|
-
}, {});
|
|
953
|
+
}, {}), this._linkIndex);
|
|
913
954
|
this.notifyAttrsSubs();
|
|
914
955
|
}
|
|
915
956
|
_startQuerySub(q, hash) {
|
|
@@ -1015,6 +1056,12 @@ class Reactor {
|
|
|
1015
1056
|
// We remove `add-attr` commands for attrs that already exist.
|
|
1016
1057
|
// We update `add-triple` and `retract-triple` commands to use the
|
|
1017
1058
|
// server attr-ids.
|
|
1059
|
+
/**
|
|
1060
|
+
*
|
|
1061
|
+
* @param {sts.AttrsStore} attrs
|
|
1062
|
+
* @param {any} muts
|
|
1063
|
+
* @param {number} [processedTxId]
|
|
1064
|
+
*/
|
|
1018
1065
|
_rewriteMutations(attrs, muts, processedTxId) {
|
|
1019
1066
|
if (!attrs)
|
|
1020
1067
|
return muts;
|
|
@@ -1022,12 +1069,12 @@ class Reactor {
|
|
|
1022
1069
|
return new Map();
|
|
1023
1070
|
const findExistingAttr = (attr) => {
|
|
1024
1071
|
const [_, etype, label] = attr['forward-identity'];
|
|
1025
|
-
const existing =
|
|
1072
|
+
const existing = sts.getAttrByFwdIdentName(attrs, etype, label);
|
|
1026
1073
|
return existing;
|
|
1027
1074
|
};
|
|
1028
1075
|
const findReverseAttr = (attr) => {
|
|
1029
1076
|
const [_, etype, label] = attr['forward-identity'];
|
|
1030
|
-
const revAttr =
|
|
1077
|
+
const revAttr = sts.getAttrByReverseIdentName(attrs, etype, label);
|
|
1031
1078
|
return revAttr;
|
|
1032
1079
|
};
|
|
1033
1080
|
const mapping = { attrIdMap: {}, refSwapAttrIds: new Set() };
|
|
@@ -1090,8 +1137,11 @@ class Reactor {
|
|
|
1090
1137
|
}
|
|
1091
1138
|
// ---------------------------
|
|
1092
1139
|
// Transact
|
|
1140
|
+
/**
|
|
1141
|
+
* @returns {sts.AttrsStore}
|
|
1142
|
+
*/
|
|
1093
1143
|
optimisticAttrs() {
|
|
1094
|
-
var _a;
|
|
1144
|
+
var _a, _b;
|
|
1095
1145
|
const pendingMutationSteps = [...this._pendingMutations().values()] // hack due to Map()
|
|
1096
1146
|
.flatMap((x) => x['tx-steps']);
|
|
1097
1147
|
const deletedAttrIds = new Set(pendingMutationSteps
|
|
@@ -1104,17 +1154,22 @@ class Reactor {
|
|
|
1104
1154
|
}
|
|
1105
1155
|
else if (_action === 'update-attr' &&
|
|
1106
1156
|
attr.id &&
|
|
1107
|
-
((_a = this.attrs) === null || _a === void 0 ? void 0 : _a
|
|
1108
|
-
const fullAttr = Object.assign(Object.assign({}, this.attrs
|
|
1157
|
+
((_a = this.attrs) === null || _a === void 0 ? void 0 : _a.getAttr(attr.id))) {
|
|
1158
|
+
const fullAttr = Object.assign(Object.assign({}, this.attrs.getAttr(attr.id)), attr);
|
|
1109
1159
|
pendingAttrs.push(fullAttr);
|
|
1110
1160
|
}
|
|
1111
1161
|
}
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
const
|
|
1117
|
-
|
|
1162
|
+
if (!deletedAttrIds.size && !pendingAttrs.length) {
|
|
1163
|
+
return this.attrs || new sts.AttrsStore({}, this._linkIndex);
|
|
1164
|
+
}
|
|
1165
|
+
const attrs = Object.assign({}, (((_b = this.attrs) === null || _b === void 0 ? void 0 : _b.attrs) || {}));
|
|
1166
|
+
for (const attr of pendingAttrs) {
|
|
1167
|
+
attrs[attr.id] = attr;
|
|
1168
|
+
}
|
|
1169
|
+
for (const id of deletedAttrIds) {
|
|
1170
|
+
delete attrs[id];
|
|
1171
|
+
}
|
|
1172
|
+
return new sts.AttrsStore(attrs, this._linkIndex);
|
|
1118
1173
|
}
|
|
1119
1174
|
/** Runs instaql on a query and a store */
|
|
1120
1175
|
dataForQuery(hash) {
|
|
@@ -1139,16 +1194,16 @@ class Reactor {
|
|
|
1139
1194
|
pendingMutationsVersion === cached.pendingMutationsVersion) {
|
|
1140
1195
|
return cached;
|
|
1141
1196
|
}
|
|
1142
|
-
const { store, pageInfo, aggregate, processedTxId } = result;
|
|
1143
|
-
const mutations = this._rewriteMutationsSorted(
|
|
1144
|
-
const newStore = this._applyOptimisticUpdates(store, mutations, processedTxId);
|
|
1145
|
-
const resp = (0, instaql_ts_1.default)({ store: newStore, pageInfo, aggregate }, q);
|
|
1197
|
+
const { store, attrsStore, pageInfo, aggregate, processedTxId } = result;
|
|
1198
|
+
const mutations = this._rewriteMutationsSorted(attrsStore, pendingMutations);
|
|
1199
|
+
const newStore = this._applyOptimisticUpdates(store, attrsStore, mutations, processedTxId);
|
|
1200
|
+
const resp = (0, instaql_ts_1.default)({ store: newStore, attrsStore, pageInfo, aggregate }, q);
|
|
1146
1201
|
return { data: resp, querySubVersion, pendingMutationsVersion };
|
|
1147
1202
|
}
|
|
1148
|
-
_applyOptimisticUpdates(store, mutations, processedTxId) {
|
|
1203
|
+
_applyOptimisticUpdates(store, attrsStore, mutations, processedTxId) {
|
|
1149
1204
|
for (const [_, mut] of mutations) {
|
|
1150
1205
|
if (!mut['tx-id'] || (processedTxId && mut['tx-id'] > processedTxId)) {
|
|
1151
|
-
store =
|
|
1206
|
+
store = sts.transact(store, attrsStore, mut['tx-steps']);
|
|
1152
1207
|
}
|
|
1153
1208
|
}
|
|
1154
1209
|
return store;
|
|
@@ -1231,7 +1286,7 @@ class Reactor {
|
|
|
1231
1286
|
.forEach(({ eventId, q }) => {
|
|
1232
1287
|
this._trySendAuthed(eventId, { op: 'add-query', q });
|
|
1233
1288
|
});
|
|
1234
|
-
const muts = this._rewriteMutationsSorted(this.
|
|
1289
|
+
const muts = this._rewriteMutationsSorted(this.ensureAttrs(), this._pendingMutations());
|
|
1235
1290
|
muts.forEach(([eventId, mut]) => {
|
|
1236
1291
|
if (!mut['tx-id']) {
|
|
1237
1292
|
this._sendMutation(eventId, mut);
|
|
@@ -1518,7 +1573,7 @@ class Reactor {
|
|
|
1518
1573
|
subscribeAttrs(cb) {
|
|
1519
1574
|
this.attrsCbs.push(cb);
|
|
1520
1575
|
if (this.attrs) {
|
|
1521
|
-
cb(this.attrs);
|
|
1576
|
+
cb(this.attrs.attrs);
|
|
1522
1577
|
}
|
|
1523
1578
|
return () => {
|
|
1524
1579
|
this.attrsCbs = this.attrsCbs.filter((x) => x !== cb);
|