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