@instantdb/core 0.22.86-experimental.separate-attrs.20122276424.1 → 0.22.86-experimental.split-store.20183617880.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/__tests__/src/Reactor.test.js +18 -11
- package/__tests__/src/{datalog.test.js → datalog.test.ts} +17 -5
- package/__tests__/src/{instaml.test.js → instaml.test.ts} +183 -119
- package/__tests__/src/instaql.bench.ts +34 -0
- package/__tests__/src/{instaql.test.js → instaql.test.ts} +342 -455
- package/__tests__/src/instaqlInference.test.js +13 -9
- package/__tests__/src/{store.test.js → store.test.ts} +188 -210
- package/dist/commonjs/Reactor.d.ts +23 -6
- package/dist/commonjs/Reactor.d.ts.map +1 -1
- package/dist/commonjs/Reactor.js +110 -45
- 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 +4 -3
- 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 +67 -25
- package/dist/commonjs/store.d.ts.map +1 -1
- package/dist/commonjs/store.js +170 -70
- package/dist/commonjs/store.js.map +1 -1
- package/dist/esm/Reactor.d.ts +23 -6
- package/dist/esm/Reactor.d.ts.map +1 -1
- package/dist/esm/Reactor.js +111 -46
- 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 +4 -3
- 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 +67 -25
- package/dist/esm/store.d.ts.map +1 -1
- package/dist/esm/store.js +167 -70
- package/dist/esm/store.js.map +1 -1
- package/dist/standalone/index.js +1580 -1392
- package/dist/standalone/index.umd.cjs +3 -3
- package/package.json +2 -2
- package/src/Reactor.js +154 -77
- package/src/SyncTable.ts +85 -45
- package/src/{instaml.js → instaml.ts} +196 -95
- package/src/instaql.ts +88 -62
- package/src/reactorTypes.ts +32 -0
- package/src/store.ts +248 -90
- package/__tests__/src/instaql.bench.js +0 -29
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instantdb/core",
|
|
3
|
-
"version": "0.22.86-experimental.
|
|
3
|
+
"version": "0.22.86-experimental.split-store.20183617880.1",
|
|
4
4
|
"description": "Instant's core local abstraction",
|
|
5
5
|
"homepage": "https://github.com/instantdb/instant/tree/main/client/packages/core",
|
|
6
6
|
"repository": {
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"mutative": "^1.0.10",
|
|
55
55
|
"uuid": "^11.1.0",
|
|
56
|
-
"@instantdb/version": "0.22.86-experimental.
|
|
56
|
+
"@instantdb/version": "0.22.86-experimental.split-store.20183617880.1"
|
|
57
57
|
},
|
|
58
58
|
"scripts": {
|
|
59
59
|
"test": "vitest",
|
package/src/Reactor.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
import weakHash from './utils/weakHash.ts';
|
|
3
3
|
import instaql from './instaql.ts';
|
|
4
|
-
import * as instaml from './instaml.
|
|
5
|
-
import * as
|
|
4
|
+
import * as instaml from './instaml.ts';
|
|
5
|
+
import * as sts from './store.ts';
|
|
6
6
|
import uuid from './utils/uuid.ts';
|
|
7
7
|
import IndexedDBStorage from './IndexedDBStorage.ts';
|
|
8
8
|
import WindowNetworkListener from './WindowNetworkListener.js';
|
|
@@ -36,6 +36,8 @@ import { SyncTable } from './SyncTable.ts';
|
|
|
36
36
|
/** @typedef {import('./Connection.ts').Connection} Connection */
|
|
37
37
|
/** @typedef {import('./Connection.ts').TransportType} TransportType */
|
|
38
38
|
/** @typedef {import('./Connection.ts').EventSourceConstructor} EventSourceConstructor */
|
|
39
|
+
/** @typedef {import('./reactorTypes.ts').QuerySub} QuerySub */
|
|
40
|
+
/** @typedef {import('./reactorTypes.ts').QuerySubInStorage} QuerySubInStorage */
|
|
39
41
|
|
|
40
42
|
const STATUS = {
|
|
41
43
|
CONNECTING: 'connecting',
|
|
@@ -107,27 +109,52 @@ const ignoreLogging = {
|
|
|
107
109
|
'patch-presence': true,
|
|
108
110
|
};
|
|
109
111
|
|
|
112
|
+
/**
|
|
113
|
+
* @param {QuerySubInStorage} x
|
|
114
|
+
* @param {boolean | null} useDateObjects
|
|
115
|
+
* @returns {QuerySub}
|
|
116
|
+
*/
|
|
110
117
|
function querySubFromStorage(x, useDateObjects) {
|
|
111
118
|
const v = typeof x === 'string' ? JSON.parse(x) : x;
|
|
112
119
|
|
|
113
120
|
if (v?.result?.store) {
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
121
|
+
const attrsStore = sts.attrsStoreFromJSON(
|
|
122
|
+
v.result.attrsStore,
|
|
123
|
+
v.result.store,
|
|
124
|
+
);
|
|
125
|
+
if (attrsStore) {
|
|
126
|
+
const storeJSON = v.result.store;
|
|
127
|
+
v.result.store = sts.fromJSON(attrsStore, {
|
|
128
|
+
...storeJSON,
|
|
129
|
+
useDateObjects: useDateObjects,
|
|
130
|
+
});
|
|
131
|
+
v.result.attrsStore = attrsStore;
|
|
132
|
+
}
|
|
119
133
|
}
|
|
120
134
|
|
|
121
135
|
return v;
|
|
122
136
|
}
|
|
123
137
|
|
|
138
|
+
/**
|
|
139
|
+
*
|
|
140
|
+
* @param {string} _key
|
|
141
|
+
* @param {QuerySub} sub
|
|
142
|
+
* @returns QuerySubInStorage
|
|
143
|
+
*/
|
|
124
144
|
function querySubToStorage(_key, sub) {
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
145
|
+
const { result, ...rest } = sub;
|
|
146
|
+
const jsonSub = /** @type {import('./reactorTypes.ts').QuerySubInStorage} */ (
|
|
147
|
+
rest
|
|
148
|
+
);
|
|
149
|
+
if (result) {
|
|
150
|
+
/** @type {import('./reactorTypes.ts').QuerySubResultInStorage} */
|
|
151
|
+
const jsonResult = {
|
|
152
|
+
...result,
|
|
153
|
+
store: sts.toJSON(result.store),
|
|
154
|
+
attrsStore: result.attrsStore.toJSON(),
|
|
130
155
|
};
|
|
156
|
+
|
|
157
|
+
jsonSub.result = jsonResult;
|
|
131
158
|
}
|
|
132
159
|
return jsonSub;
|
|
133
160
|
}
|
|
@@ -176,12 +203,13 @@ function sortedMutationEntries(entries) {
|
|
|
176
203
|
* @template {import('./presence.ts').RoomSchemaShape} [RoomSchema = {}]
|
|
177
204
|
*/
|
|
178
205
|
export default class Reactor {
|
|
206
|
+
/** @type {sts.AttrsStore | undefined} */
|
|
179
207
|
attrs;
|
|
180
208
|
_isOnline = true;
|
|
181
209
|
_isShutdown = false;
|
|
182
210
|
status = STATUS.CONNECTING;
|
|
183
211
|
|
|
184
|
-
/** @type {PersistedObject} */
|
|
212
|
+
/** @type {PersistedObject<string, QuerySub, QuerySubInStorage>} */
|
|
185
213
|
querySubs;
|
|
186
214
|
|
|
187
215
|
/** @type {PersistedObject} */
|
|
@@ -306,14 +334,15 @@ export default class Reactor {
|
|
|
306
334
|
useDateObjects: this.config.useDateObjects,
|
|
307
335
|
},
|
|
308
336
|
this._log,
|
|
309
|
-
(triples) =>
|
|
310
|
-
|
|
311
|
-
this.
|
|
337
|
+
(triples) => {
|
|
338
|
+
return sts.createStore(
|
|
339
|
+
this.ensureAttrs(),
|
|
312
340
|
triples,
|
|
313
341
|
this.config.enableCardinalityInference,
|
|
314
|
-
this._linkIndex,
|
|
315
342
|
this.config.useDateObjects,
|
|
316
|
-
)
|
|
343
|
+
);
|
|
344
|
+
},
|
|
345
|
+
() => this.ensureAttrs(),
|
|
317
346
|
);
|
|
318
347
|
|
|
319
348
|
this._oauthCallbackResponse = this._oauthLoginInit();
|
|
@@ -353,6 +382,13 @@ export default class Reactor {
|
|
|
353
382
|
}
|
|
354
383
|
}
|
|
355
384
|
|
|
385
|
+
ensureAttrs() {
|
|
386
|
+
if (!this.attrs) {
|
|
387
|
+
throw new Error('attrs have not loaded.');
|
|
388
|
+
}
|
|
389
|
+
return this.attrs;
|
|
390
|
+
}
|
|
391
|
+
|
|
356
392
|
updateSchema(schema) {
|
|
357
393
|
this.config = {
|
|
358
394
|
...this.config,
|
|
@@ -383,7 +419,7 @@ export default class Reactor {
|
|
|
383
419
|
serialize: querySubToStorage,
|
|
384
420
|
parse: (_key, x) => querySubFromStorage(x, this.config.useDateObjects),
|
|
385
421
|
// objectSize
|
|
386
|
-
objectSize: (x) => x
|
|
422
|
+
objectSize: (x) => x?.result?.store?.triples?.length ?? 0,
|
|
387
423
|
logger: this._log,
|
|
388
424
|
preloadEntryCount: 10,
|
|
389
425
|
gc: {
|
|
@@ -552,13 +588,13 @@ export default class Reactor {
|
|
|
552
588
|
const pageInfo = result?.[0]?.data?.['page-info'];
|
|
553
589
|
const aggregate = result?.[0]?.data?.['aggregate'];
|
|
554
590
|
const triples = extractTriples(result);
|
|
555
|
-
const store =
|
|
556
|
-
this.
|
|
591
|
+
const store = sts.createStore(
|
|
592
|
+
this.ensureAttrs(),
|
|
557
593
|
triples,
|
|
558
594
|
enableCardinalityInference,
|
|
559
|
-
this._linkIndex,
|
|
560
595
|
this.config.useDateObjects,
|
|
561
596
|
);
|
|
597
|
+
|
|
562
598
|
this.querySubs.updateInPlace((prev) => {
|
|
563
599
|
if (!prev[hash]) {
|
|
564
600
|
this._log.info('Missing value in querySubs', { hash, q });
|
|
@@ -566,6 +602,7 @@ export default class Reactor {
|
|
|
566
602
|
}
|
|
567
603
|
prev[hash].result = {
|
|
568
604
|
store,
|
|
605
|
+
attrsStore: this.ensureAttrs(),
|
|
569
606
|
pageInfo,
|
|
570
607
|
aggregate,
|
|
571
608
|
processedTxId: msg['processed-tx-id'],
|
|
@@ -603,7 +640,7 @@ export default class Reactor {
|
|
|
603
640
|
this._cleanupPendingMutationsTimeout();
|
|
604
641
|
|
|
605
642
|
const rewrittenMutations = this._rewriteMutations(
|
|
606
|
-
this.
|
|
643
|
+
this.ensureAttrs(),
|
|
607
644
|
this._pendingMutations(),
|
|
608
645
|
processedTxId,
|
|
609
646
|
);
|
|
@@ -624,32 +661,49 @@ export default class Reactor {
|
|
|
624
661
|
const result = x['instaql-result'];
|
|
625
662
|
const hash = weakHash(q);
|
|
626
663
|
const triples = extractTriples(result);
|
|
627
|
-
const
|
|
628
|
-
|
|
664
|
+
const attrsStore = this.ensureAttrs();
|
|
665
|
+
const store = sts.createStore(
|
|
666
|
+
attrsStore,
|
|
629
667
|
triples,
|
|
630
668
|
enableCardinalityInference,
|
|
631
|
-
this._linkIndex,
|
|
632
669
|
this.config.useDateObjects,
|
|
633
670
|
);
|
|
634
|
-
const newStore =
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
671
|
+
const { store: newStore, attrsStore: newAttrsStore } =
|
|
672
|
+
this._applyOptimisticUpdates(
|
|
673
|
+
store,
|
|
674
|
+
attrsStore,
|
|
675
|
+
mutations,
|
|
676
|
+
processedTxId,
|
|
677
|
+
);
|
|
639
678
|
const pageInfo = result?.[0]?.data?.['page-info'];
|
|
640
679
|
const aggregate = result?.[0]?.data?.['aggregate'];
|
|
641
|
-
return {
|
|
680
|
+
return {
|
|
681
|
+
q,
|
|
682
|
+
hash,
|
|
683
|
+
store: newStore,
|
|
684
|
+
attrsStore: newAttrsStore,
|
|
685
|
+
pageInfo,
|
|
686
|
+
aggregate,
|
|
687
|
+
};
|
|
642
688
|
});
|
|
643
689
|
|
|
644
|
-
updates.forEach(
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
690
|
+
updates.forEach(
|
|
691
|
+
({ hash, q, store, attrsStore, pageInfo, aggregate }) => {
|
|
692
|
+
this.querySubs.updateInPlace((prev) => {
|
|
693
|
+
if (!prev[hash]) {
|
|
694
|
+
this._log.error('Missing value in querySubs', { hash, q });
|
|
695
|
+
return;
|
|
696
|
+
}
|
|
697
|
+
prev[hash].result = {
|
|
698
|
+
store,
|
|
699
|
+
attrsStore,
|
|
700
|
+
pageInfo,
|
|
701
|
+
aggregate,
|
|
702
|
+
processedTxId,
|
|
703
|
+
};
|
|
704
|
+
});
|
|
705
|
+
},
|
|
706
|
+
);
|
|
653
707
|
|
|
654
708
|
this._cleanupPendingMutationsQueries();
|
|
655
709
|
|
|
@@ -664,7 +718,7 @@ export default class Reactor {
|
|
|
664
718
|
this._inFlightMutationEventIds.delete(eventId);
|
|
665
719
|
|
|
666
720
|
const muts = this._rewriteMutations(
|
|
667
|
-
this.
|
|
721
|
+
this.ensureAttrs(),
|
|
668
722
|
this._pendingMutations(),
|
|
669
723
|
);
|
|
670
724
|
const prevMutation = muts.get(eventId);
|
|
@@ -681,12 +735,18 @@ export default class Reactor {
|
|
|
681
735
|
});
|
|
682
736
|
});
|
|
683
737
|
|
|
684
|
-
const newAttrs =
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
738
|
+
const newAttrs = [];
|
|
739
|
+
for (const step of prevMutation['tx-steps']) {
|
|
740
|
+
if (step[0] === 'add-attr') {
|
|
741
|
+
const attr = step[1];
|
|
742
|
+
newAttrs.push(attr);
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
if (newAttrs.length) {
|
|
746
|
+
const existingAttrs = Object.values(this.ensureAttrs());
|
|
747
|
+
this._setAttrs([...existingAttrs, ...newAttrs]);
|
|
748
|
+
this._setAttrs(newAttrs);
|
|
749
|
+
}
|
|
690
750
|
|
|
691
751
|
this._finishTransaction('synced', eventId);
|
|
692
752
|
|
|
@@ -870,10 +930,13 @@ export default class Reactor {
|
|
|
870
930
|
}
|
|
871
931
|
|
|
872
932
|
_setAttrs(attrs) {
|
|
873
|
-
this.attrs =
|
|
874
|
-
acc
|
|
875
|
-
|
|
876
|
-
|
|
933
|
+
this.attrs = new sts.AttrsStoreClass(
|
|
934
|
+
attrs.reduce((acc, attr) => {
|
|
935
|
+
acc[attr.id] = attr;
|
|
936
|
+
return acc;
|
|
937
|
+
}, {}),
|
|
938
|
+
this._linkIndex,
|
|
939
|
+
);
|
|
877
940
|
|
|
878
941
|
this.notifyAttrsSubs();
|
|
879
942
|
}
|
|
@@ -1022,17 +1085,23 @@ export default class Reactor {
|
|
|
1022
1085
|
// We remove `add-attr` commands for attrs that already exist.
|
|
1023
1086
|
// We update `add-triple` and `retract-triple` commands to use the
|
|
1024
1087
|
// server attr-ids.
|
|
1088
|
+
/**
|
|
1089
|
+
*
|
|
1090
|
+
* @param {sts.AttrsStore} attrs
|
|
1091
|
+
* @param {any} muts
|
|
1092
|
+
* @param {number} [processedTxId]
|
|
1093
|
+
*/
|
|
1025
1094
|
_rewriteMutations(attrs, muts, processedTxId) {
|
|
1026
1095
|
if (!attrs) return muts;
|
|
1027
1096
|
if (!muts) return new Map();
|
|
1028
1097
|
const findExistingAttr = (attr) => {
|
|
1029
1098
|
const [_, etype, label] = attr['forward-identity'];
|
|
1030
|
-
const existing =
|
|
1099
|
+
const existing = sts.getAttrByFwdIdentName(attrs, etype, label);
|
|
1031
1100
|
return existing;
|
|
1032
1101
|
};
|
|
1033
1102
|
const findReverseAttr = (attr) => {
|
|
1034
1103
|
const [_, etype, label] = attr['forward-identity'];
|
|
1035
|
-
const revAttr =
|
|
1104
|
+
const revAttr = sts.getAttrByReverseIdentName(attrs, etype, label);
|
|
1036
1105
|
return revAttr;
|
|
1037
1106
|
};
|
|
1038
1107
|
const mapping = { attrIdMap: {}, refSwapAttrIds: new Set() };
|
|
@@ -1109,6 +1178,9 @@ export default class Reactor {
|
|
|
1109
1178
|
// ---------------------------
|
|
1110
1179
|
// Transact
|
|
1111
1180
|
|
|
1181
|
+
/**
|
|
1182
|
+
* @returns {sts.AttrsStore}
|
|
1183
|
+
*/
|
|
1112
1184
|
optimisticAttrs() {
|
|
1113
1185
|
const pendingMutationSteps = [...this._pendingMutations().values()] // hack due to Map()
|
|
1114
1186
|
.flatMap((x) => x['tx-steps']);
|
|
@@ -1126,23 +1198,26 @@ export default class Reactor {
|
|
|
1126
1198
|
} else if (
|
|
1127
1199
|
_action === 'update-attr' &&
|
|
1128
1200
|
attr.id &&
|
|
1129
|
-
this.attrs?.
|
|
1201
|
+
this.attrs?.getAttr(attr.id)
|
|
1130
1202
|
) {
|
|
1131
|
-
const fullAttr = { ...this.attrs
|
|
1203
|
+
const fullAttr = { ...this.attrs.getAttr(attr.id), ...attr };
|
|
1132
1204
|
pendingAttrs.push(fullAttr);
|
|
1133
1205
|
}
|
|
1134
1206
|
}
|
|
1135
1207
|
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
].filter((a) => !deletedAttrIds.has(a.id));
|
|
1208
|
+
if (!deletedAttrIds.size && !pendingAttrs.length) {
|
|
1209
|
+
return this.attrs || new sts.AttrsStoreClass({}, this._linkIndex);
|
|
1210
|
+
}
|
|
1140
1211
|
|
|
1141
|
-
const
|
|
1142
|
-
|
|
1143
|
-
|
|
1212
|
+
const attrs = { ...(this.attrs?.attrs || {}) };
|
|
1213
|
+
for (const attr of pendingAttrs) {
|
|
1214
|
+
attrs[attr.id] = attr;
|
|
1215
|
+
}
|
|
1216
|
+
for (const id of deletedAttrIds) {
|
|
1217
|
+
delete attrs[id];
|
|
1218
|
+
}
|
|
1144
1219
|
|
|
1145
|
-
return
|
|
1220
|
+
return new sts.AttrsStoreClass(attrs, this._linkIndex);
|
|
1146
1221
|
}
|
|
1147
1222
|
|
|
1148
1223
|
/** Runs instaql on a query and a store */
|
|
@@ -1170,28 +1245,30 @@ export default class Reactor {
|
|
|
1170
1245
|
return cached;
|
|
1171
1246
|
}
|
|
1172
1247
|
|
|
1173
|
-
const { store, pageInfo, aggregate, processedTxId } = result;
|
|
1248
|
+
const { store, attrsStore, pageInfo, aggregate, processedTxId } = result;
|
|
1174
1249
|
const mutations = this._rewriteMutationsSorted(
|
|
1175
|
-
|
|
1250
|
+
attrsStore,
|
|
1176
1251
|
pendingMutations,
|
|
1177
1252
|
);
|
|
1178
|
-
const newStore =
|
|
1179
|
-
store,
|
|
1180
|
-
|
|
1181
|
-
|
|
1253
|
+
const { store: newStore, attrsStore: newAttrsStore } =
|
|
1254
|
+
this._applyOptimisticUpdates(store, attrsStore, mutations, processedTxId);
|
|
1255
|
+
const resp = instaql(
|
|
1256
|
+
{ store: newStore, attrsStore: newAttrsStore, pageInfo, aggregate },
|
|
1257
|
+
q,
|
|
1182
1258
|
);
|
|
1183
|
-
const resp = instaql({ store: newStore, pageInfo, aggregate }, q);
|
|
1184
1259
|
|
|
1185
1260
|
return { data: resp, querySubVersion, pendingMutationsVersion };
|
|
1186
1261
|
}
|
|
1187
1262
|
|
|
1188
|
-
_applyOptimisticUpdates(store, mutations, processedTxId) {
|
|
1263
|
+
_applyOptimisticUpdates(store, attrsStore, mutations, processedTxId) {
|
|
1189
1264
|
for (const [_, mut] of mutations) {
|
|
1190
1265
|
if (!mut['tx-id'] || (processedTxId && mut['tx-id'] > processedTxId)) {
|
|
1191
|
-
|
|
1266
|
+
const result = sts.transact(store, attrsStore, mut['tx-steps']);
|
|
1267
|
+
store = result.store;
|
|
1268
|
+
attrsStore = result.attrsStore;
|
|
1192
1269
|
}
|
|
1193
1270
|
}
|
|
1194
|
-
return store;
|
|
1271
|
+
return { store, attrsStore };
|
|
1195
1272
|
}
|
|
1196
1273
|
|
|
1197
1274
|
/** Re-run instaql and call all callbacks with new data */
|
|
@@ -1248,7 +1325,7 @@ export default class Reactor {
|
|
|
1248
1325
|
try {
|
|
1249
1326
|
const txSteps = instaml.transform(
|
|
1250
1327
|
{
|
|
1251
|
-
|
|
1328
|
+
attrsStore: this.optimisticAttrs(),
|
|
1252
1329
|
schema: this.config.schema,
|
|
1253
1330
|
stores: Object.values(this.querySubs.currentValue).map(
|
|
1254
1331
|
(sub) => sub?.result?.store,
|
|
@@ -1366,7 +1443,7 @@ export default class Reactor {
|
|
|
1366
1443
|
});
|
|
1367
1444
|
|
|
1368
1445
|
const muts = this._rewriteMutationsSorted(
|
|
1369
|
-
this.
|
|
1446
|
+
this.ensureAttrs(),
|
|
1370
1447
|
this._pendingMutations(),
|
|
1371
1448
|
);
|
|
1372
1449
|
muts.forEach(([eventId, mut]) => {
|
|
@@ -1822,7 +1899,7 @@ export default class Reactor {
|
|
|
1822
1899
|
this.attrsCbs.push(cb);
|
|
1823
1900
|
|
|
1824
1901
|
if (this.attrs) {
|
|
1825
|
-
cb(this.attrs);
|
|
1902
|
+
cb(this.attrs.attrs);
|
|
1826
1903
|
}
|
|
1827
1904
|
|
|
1828
1905
|
return () => {
|