@instantdb/core 0.22.86-experimental.split-store.20249702529.1 → 0.22.86-experimental.split-store.20250097559.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 +8 -8
- package/dist/commonjs/Reactor.d.ts.map +1 -1
- package/dist/commonjs/Reactor.js +15 -16
- package/dist/commonjs/Reactor.js.map +1 -1
- package/dist/esm/Reactor.d.ts +8 -8
- package/dist/esm/Reactor.d.ts.map +1 -1
- package/dist/esm/Reactor.js +15 -16
- package/dist/esm/Reactor.js.map +1 -1
- package/dist/standalone/index.js +5 -5
- package/dist/standalone/index.umd.cjs +1 -1
- package/package.json +2 -2
- package/src/Reactor.js +16 -17
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instantdb/core",
|
|
3
|
-
"version": "0.22.86-experimental.split-store.
|
|
3
|
+
"version": "0.22.86-experimental.split-store.20250097559.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.split-store.
|
|
56
|
+
"@instantdb/version": "0.22.86-experimental.split-store.20250097559.1"
|
|
57
57
|
},
|
|
58
58
|
"scripts": {
|
|
59
59
|
"test": "vitest",
|
package/src/Reactor.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import weakHash from './utils/weakHash.ts';
|
|
3
3
|
import instaql from './instaql.ts';
|
|
4
4
|
import * as instaml from './instaml.ts';
|
|
5
|
-
import * as
|
|
5
|
+
import * as s 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';
|
|
@@ -118,13 +118,13 @@ function querySubFromStorage(x, useDateObjects) {
|
|
|
118
118
|
const v = typeof x === 'string' ? JSON.parse(x) : x;
|
|
119
119
|
|
|
120
120
|
if (v?.result?.store) {
|
|
121
|
-
const attrsStore =
|
|
121
|
+
const attrsStore = s.attrsStoreFromJSON(
|
|
122
122
|
v.result.attrsStore,
|
|
123
123
|
v.result.store,
|
|
124
124
|
);
|
|
125
125
|
if (attrsStore) {
|
|
126
126
|
const storeJSON = v.result.store;
|
|
127
|
-
v.result.store =
|
|
127
|
+
v.result.store = s.fromJSON(attrsStore, {
|
|
128
128
|
...storeJSON,
|
|
129
129
|
useDateObjects: useDateObjects,
|
|
130
130
|
});
|
|
@@ -150,7 +150,7 @@ function querySubToStorage(_key, sub) {
|
|
|
150
150
|
/** @type {import('./reactorTypes.ts').QuerySubResultInStorage} */
|
|
151
151
|
const jsonResult = {
|
|
152
152
|
...result,
|
|
153
|
-
store:
|
|
153
|
+
store: s.toJSON(result.store),
|
|
154
154
|
attrsStore: result.attrsStore.toJSON(),
|
|
155
155
|
};
|
|
156
156
|
|
|
@@ -203,7 +203,7 @@ function sortedMutationEntries(entries) {
|
|
|
203
203
|
* @template {import('./presence.ts').RoomSchemaShape} [RoomSchema = {}]
|
|
204
204
|
*/
|
|
205
205
|
export default class Reactor {
|
|
206
|
-
/** @type {
|
|
206
|
+
/** @type {s.AttrsStore | undefined} */
|
|
207
207
|
attrs;
|
|
208
208
|
_isOnline = true;
|
|
209
209
|
_isShutdown = false;
|
|
@@ -335,7 +335,7 @@ export default class Reactor {
|
|
|
335
335
|
},
|
|
336
336
|
this._log,
|
|
337
337
|
(triples) => {
|
|
338
|
-
return
|
|
338
|
+
return s.createStore(
|
|
339
339
|
this.ensureAttrs(),
|
|
340
340
|
triples,
|
|
341
341
|
this.config.enableCardinalityInference,
|
|
@@ -589,7 +589,7 @@ export default class Reactor {
|
|
|
589
589
|
const aggregate = result?.[0]?.data?.['aggregate'];
|
|
590
590
|
const triples = extractTriples(result);
|
|
591
591
|
const attrsStore = this.ensureAttrs();
|
|
592
|
-
const store =
|
|
592
|
+
const store = s.createStore(
|
|
593
593
|
attrsStore,
|
|
594
594
|
triples,
|
|
595
595
|
enableCardinalityInference,
|
|
@@ -663,7 +663,7 @@ export default class Reactor {
|
|
|
663
663
|
const hash = weakHash(q);
|
|
664
664
|
const triples = extractTriples(result);
|
|
665
665
|
const attrsStore = this.ensureAttrs();
|
|
666
|
-
const store =
|
|
666
|
+
const store = s.createStore(
|
|
667
667
|
attrsStore,
|
|
668
668
|
triples,
|
|
669
669
|
enableCardinalityInference,
|
|
@@ -746,7 +746,6 @@ export default class Reactor {
|
|
|
746
746
|
if (newAttrs.length) {
|
|
747
747
|
const existingAttrs = Object.values(this.ensureAttrs().attrs);
|
|
748
748
|
this._setAttrs([...existingAttrs, ...newAttrs]);
|
|
749
|
-
this._setAttrs(newAttrs);
|
|
750
749
|
}
|
|
751
750
|
|
|
752
751
|
this._finishTransaction('synced', eventId);
|
|
@@ -931,7 +930,7 @@ export default class Reactor {
|
|
|
931
930
|
}
|
|
932
931
|
|
|
933
932
|
_setAttrs(attrs) {
|
|
934
|
-
this.attrs = new
|
|
933
|
+
this.attrs = new s.AttrsStoreClass(
|
|
935
934
|
attrs.reduce((acc, attr) => {
|
|
936
935
|
acc[attr.id] = attr;
|
|
937
936
|
return acc;
|
|
@@ -1088,7 +1087,7 @@ export default class Reactor {
|
|
|
1088
1087
|
// server attr-ids.
|
|
1089
1088
|
/**
|
|
1090
1089
|
*
|
|
1091
|
-
* @param {
|
|
1090
|
+
* @param {s.AttrsStore} attrs
|
|
1092
1091
|
* @param {any} muts
|
|
1093
1092
|
* @param {number} [processedTxId]
|
|
1094
1093
|
*/
|
|
@@ -1097,12 +1096,12 @@ export default class Reactor {
|
|
|
1097
1096
|
if (!muts) return new Map();
|
|
1098
1097
|
const findExistingAttr = (attr) => {
|
|
1099
1098
|
const [_, etype, label] = attr['forward-identity'];
|
|
1100
|
-
const existing =
|
|
1099
|
+
const existing = s.getAttrByFwdIdentName(attrs, etype, label);
|
|
1101
1100
|
return existing;
|
|
1102
1101
|
};
|
|
1103
1102
|
const findReverseAttr = (attr) => {
|
|
1104
1103
|
const [_, etype, label] = attr['forward-identity'];
|
|
1105
|
-
const revAttr =
|
|
1104
|
+
const revAttr = s.getAttrByReverseIdentName(attrs, etype, label);
|
|
1106
1105
|
return revAttr;
|
|
1107
1106
|
};
|
|
1108
1107
|
const mapping = { attrIdMap: {}, refSwapAttrIds: new Set() };
|
|
@@ -1180,7 +1179,7 @@ export default class Reactor {
|
|
|
1180
1179
|
// Transact
|
|
1181
1180
|
|
|
1182
1181
|
/**
|
|
1183
|
-
* @returns {
|
|
1182
|
+
* @returns {s.AttrsStore}
|
|
1184
1183
|
*/
|
|
1185
1184
|
optimisticAttrs() {
|
|
1186
1185
|
const pendingMutationSteps = [...this._pendingMutations().values()] // hack due to Map()
|
|
@@ -1207,7 +1206,7 @@ export default class Reactor {
|
|
|
1207
1206
|
}
|
|
1208
1207
|
|
|
1209
1208
|
if (!deletedAttrIds.size && !pendingAttrs.length) {
|
|
1210
|
-
return this.attrs || new
|
|
1209
|
+
return this.attrs || new s.AttrsStoreClass({}, this._linkIndex);
|
|
1211
1210
|
}
|
|
1212
1211
|
|
|
1213
1212
|
const attrs = { ...(this.attrs?.attrs || {}) };
|
|
@@ -1218,7 +1217,7 @@ export default class Reactor {
|
|
|
1218
1217
|
delete attrs[id];
|
|
1219
1218
|
}
|
|
1220
1219
|
|
|
1221
|
-
return new
|
|
1220
|
+
return new s.AttrsStoreClass(attrs, this._linkIndex);
|
|
1222
1221
|
}
|
|
1223
1222
|
|
|
1224
1223
|
/** Runs instaql on a query and a store */
|
|
@@ -1264,7 +1263,7 @@ export default class Reactor {
|
|
|
1264
1263
|
_applyOptimisticUpdates(store, attrsStore, mutations, processedTxId) {
|
|
1265
1264
|
for (const [_, mut] of mutations) {
|
|
1266
1265
|
if (!mut['tx-id'] || (processedTxId && mut['tx-id'] > processedTxId)) {
|
|
1267
|
-
const result =
|
|
1266
|
+
const result = s.transact(store, attrsStore, mut['tx-steps']);
|
|
1268
1267
|
store = result.store;
|
|
1269
1268
|
attrsStore = result.attrsStore;
|
|
1270
1269
|
}
|