@instantdb/core 0.22.86-experimental.split-store.20178922132.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 +4 -1
- package/dist/commonjs/Reactor.d.ts.map +1 -1
- package/dist/commonjs/Reactor.js +22 -12
- package/dist/commonjs/Reactor.js.map +1 -1
- package/dist/commonjs/instaml.d.ts +3 -3
- package/dist/commonjs/instaml.d.ts.map +1 -1
- package/dist/commonjs/instaml.js +2 -2
- package/dist/commonjs/instaml.js.map +1 -1
- package/dist/commonjs/instaql.d.ts +2 -2
- package/dist/commonjs/instaql.d.ts.map +1 -1
- package/dist/commonjs/instaql.js.map +1 -1
- package/dist/commonjs/store.d.ts +28 -9
- package/dist/commonjs/store.d.ts.map +1 -1
- package/dist/commonjs/store.js +13 -8
- package/dist/commonjs/store.js.map +1 -1
- package/dist/esm/Reactor.d.ts +4 -1
- package/dist/esm/Reactor.d.ts.map +1 -1
- package/dist/esm/Reactor.js +22 -12
- package/dist/esm/Reactor.js.map +1 -1
- package/dist/esm/instaml.d.ts +3 -3
- package/dist/esm/instaml.d.ts.map +1 -1
- package/dist/esm/instaml.js +3 -3
- package/dist/esm/instaml.js.map +1 -1
- package/dist/esm/instaql.d.ts +2 -2
- package/dist/esm/instaql.d.ts.map +1 -1
- package/dist/esm/instaql.js.map +1 -1
- package/dist/esm/store.d.ts +28 -9
- package/dist/esm/store.d.ts.map +1 -1
- package/dist/esm/store.js +11 -6
- package/dist/esm/store.js.map +1 -1
- package/dist/standalone/index.js +549 -533
- package/dist/standalone/index.umd.cjs +2 -2
- package/package.json +2 -2
- package/src/Reactor.js +44 -35
- package/src/instaml.ts +8 -7
- package/src/instaql.ts +2 -2
- package/src/store.ts +47 -19
- package/__tests__/src/instaql.bench.js +0 -29
package/dist/commonjs/store.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.AttrsStoreClass = void 0;
|
|
4
4
|
exports.isBlob = isBlob;
|
|
5
5
|
exports.getInMap = getInMap;
|
|
6
6
|
exports.toJSON = toJSON;
|
|
@@ -22,13 +22,12 @@ exports.transact = transact;
|
|
|
22
22
|
const mutative_1 = require("mutative");
|
|
23
23
|
const object_js_1 = require("./utils/object.js");
|
|
24
24
|
const dates_ts_1 = require("./utils/dates.js");
|
|
25
|
-
class
|
|
25
|
+
class AttrsStoreClass {
|
|
26
26
|
constructor(attrs, linkIndex) {
|
|
27
27
|
this._blobAttrs = null;
|
|
28
28
|
this._primaryKeys = null;
|
|
29
29
|
this._forwardIdents = null;
|
|
30
30
|
this._revIdents = null;
|
|
31
|
-
console.log('attrs init', new Error('trace'));
|
|
32
31
|
this.attrs = attrs;
|
|
33
32
|
this.linkIndex = linkIndex;
|
|
34
33
|
}
|
|
@@ -118,7 +117,7 @@ class AttrsStore {
|
|
|
118
117
|
return { attrs: this.attrs, linkIndex: this.linkIndex };
|
|
119
118
|
}
|
|
120
119
|
}
|
|
121
|
-
exports.
|
|
120
|
+
exports.AttrsStoreClass = AttrsStoreClass;
|
|
122
121
|
function hasEA(attr) {
|
|
123
122
|
return attr['cardinality'] === 'one';
|
|
124
123
|
}
|
|
@@ -223,10 +222,10 @@ function fromJSON(attrsStore, storeJSON) {
|
|
|
223
222
|
}
|
|
224
223
|
function attrsStoreFromJSON(attrsStoreJSON, storeJSON) {
|
|
225
224
|
if (attrsStoreJSON) {
|
|
226
|
-
return new
|
|
225
|
+
return new AttrsStoreClass(attrsStoreJSON.attrs, attrsStoreJSON.linkIndex);
|
|
227
226
|
}
|
|
228
227
|
if (storeJSON && '__type' in storeJSON) {
|
|
229
|
-
return new
|
|
228
|
+
return new AttrsStoreClass(storeJSON.attrs, storeJSON.linkIndex);
|
|
230
229
|
}
|
|
231
230
|
}
|
|
232
231
|
function hasTriple(store, [e, a, v]) {
|
|
@@ -744,10 +743,16 @@ function transact(store, attrsStore, txSteps) {
|
|
|
744
743
|
}
|
|
745
744
|
return true;
|
|
746
745
|
});
|
|
747
|
-
return (0, mutative_1.create)(store, (draft) => {
|
|
746
|
+
return (0, mutative_1.create)({ store, attrsStore }, (draft) => {
|
|
748
747
|
txStepsFiltered.forEach((txStep) => {
|
|
749
|
-
applyTxStep(draft, attrsStore, txStep);
|
|
748
|
+
applyTxStep(draft.store, draft.attrsStore, txStep);
|
|
750
749
|
});
|
|
750
|
+
}, {
|
|
751
|
+
mark: (target) => {
|
|
752
|
+
if (target instanceof AttrsStoreClass) {
|
|
753
|
+
return 'immutable';
|
|
754
|
+
}
|
|
755
|
+
},
|
|
751
756
|
});
|
|
752
757
|
}
|
|
753
758
|
//# sourceMappingURL=store.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/store.ts"],"names":[],"mappings":";;;AAsKA,wBAEC;AAMD,4BAEC;AAyFD,wBAOC;AAED,4BAOC;AAED,gDAUC;AAED,8BAEC;AAED,8BAEC;AAED,kCAcC;AA2DD,sCAoBC;AAwCD,8BAyCC;AAqLD,oCAkBC;AAsED,gCAyDC;AAED,kCAoBC;AAED,sDAMC;AAED,8DAMC;AAED,oCAEC;AAED,8CAMC;AAyBD,4BA4CC;AA15BD,uCAAkC;AAClC,iDAAuD;AACvD,+CAAgD;AA6ChD,MAAa,UAAU;IAOrB,YAAY,KAAY,EAAE,SAA2B;QAJ7C,eAAU,GAAmD,IAAI,CAAC;QA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":["import { create } from 'mutative';\nimport { immutableDeepMerge } from './utils/object.js';\nimport { coerceToDate } from './utils/dates.ts';\nimport { InstantDBAttr } from './attrTypes.ts';\nimport { LinkIndex } from './utils/linkIndex.ts';\n\ntype Triple = [string, string, any, number];\ntype Attrs = Record<string, InstantDBAttr>;\n\ninterface AttrIndexes {\n blobAttrs: Map<string, Map<string, InstantDBAttr>>;\n primaryKeys: Map<string, InstantDBAttr>;\n forwardIdents: Map<string, Map<string, InstantDBAttr>>;\n revIdents: Map<string, Map<string, InstantDBAttr>>;\n}\n\nexport type Store = {\n eav: Map<string, Map<string, Map<any, Triple>>>;\n aev: Map<string, Map<string, Map<any, Triple>>>;\n vae: Map<any, Map<string, Map<string, Triple>>>;\n useDateObjects: boolean | null;\n cardinalityInference: boolean | null;\n};\n\ntype StoreJsonVersion0 = {\n __type: 'store';\n attrs: Attrs;\n triples: Triple[];\n cardinalityInference: boolean | null;\n linkIndex: LinkIndex | null;\n useDateObjects: boolean | null;\n};\n\ntype StoreJsonVersion1 = {\n triples: Triple[];\n cardinalityInference: boolean | null;\n useDateObjects: boolean | null;\n version: 1;\n};\n\nexport type StoreJson = StoreJsonVersion0 | StoreJsonVersion1;\n\nexport type AttrsStoreJson = {\n attrs: Attrs;\n linkIndex: LinkIndex | null;\n};\n\nexport class AttrsStore {\n public attrs: Attrs;\n public linkIndex: LinkIndex | null;\n private _blobAttrs: Map<string, Map<string, InstantDBAttr>> | null = null;\n private _primaryKeys: Map<string, InstantDBAttr> | null = null;\n private _forwardIdents: Map<string, Map<string, InstantDBAttr>> | null = null;\n private _revIdents: Map<string, Map<string, InstantDBAttr>> | null = null;\n constructor(attrs: Attrs, linkIndex: LinkIndex | null) {\n console.log('attrs init', new Error('trace'));\n this.attrs = attrs;\n this.linkIndex = linkIndex;\n }\n\n public resetAttrIndexes() {\n this._blobAttrs = null;\n this._primaryKeys = null;\n this._forwardIdents = null;\n this._revIdents = null;\n }\n\n public addAttr(attr: InstantDBAttr) {\n this.attrs[attr.id] = attr;\n this.resetAttrIndexes();\n }\n\n public deleteAttr(attrId: string) {\n delete this.attrs[attrId];\n this.resetAttrIndexes();\n }\n\n public updateAttr(partialAttr: Partial<InstantDBAttr> & { id: string }) {\n const attr = this.attrs[partialAttr.id];\n if (!attr) return;\n this.attrs[partialAttr.id] = { ...attr, ...partialAttr };\n this.resetAttrIndexes();\n }\n\n public getAttr(id: string): InstantDBAttr | undefined {\n return this.attrs[id];\n }\n\n // XXX: Might be better to create all of the indexes at once as soon as someone\n // requests one index\n get blobAttrs(): Map<string, Map<string, InstantDBAttr>> {\n if (this._blobAttrs) {\n return this._blobAttrs;\n }\n console.log('blobAttrs');\n this._blobAttrs = new Map();\n for (const attr of Object.values(this.attrs)) {\n if (isBlob(attr)) {\n const [_, fwdEtype, fwdLabel] = attr['forward-identity'];\n setInMap(this.blobAttrs, [fwdEtype, fwdLabel], attr);\n }\n }\n return this._blobAttrs;\n }\n\n get primaryKeys(): Map<string, InstantDBAttr> {\n if (this._primaryKeys) {\n return this._primaryKeys;\n }\n console.log('primayKeys');\n this._primaryKeys = new Map();\n\n for (const attr of Object.values(this.attrs)) {\n if (attr['primary?']) {\n const [_, fwdEtype] = attr['forward-identity'];\n setInMap(this._primaryKeys, [fwdEtype], attr);\n }\n }\n return this._primaryKeys;\n }\n\n get forwardIdents(): Map<string, Map<string, InstantDBAttr>> {\n if (this._forwardIdents) {\n return this._forwardIdents;\n }\n console.log('fwdIdents');\n this._forwardIdents = new Map();\n\n for (const attr of Object.values(this.attrs)) {\n const fwdIdent = attr['forward-identity'];\n const [_, fwdEtype, fwdLabel] = fwdIdent;\n setInMap(this._forwardIdents, [fwdEtype, fwdLabel], attr);\n }\n return this._forwardIdents;\n }\n\n get revIdents(): Map<string, Map<string, InstantDBAttr>> {\n if (this._revIdents) {\n return this._revIdents;\n }\n console.log('revIdents');\n this._revIdents = new Map();\n\n for (const attr of Object.values(this.attrs)) {\n const revIdent = attr['reverse-identity'];\n if (revIdent) {\n const [_, revEtype, revLabel] = revIdent;\n setInMap(this._revIdents, [revEtype, revLabel], attr);\n }\n }\n return this._revIdents;\n }\n\n public toJSON(): AttrsStoreJson {\n return { attrs: this.attrs, linkIndex: this.linkIndex };\n }\n}\n\nfunction hasEA(attr: InstantDBAttr) {\n return attr['cardinality'] === 'one';\n}\n\nfunction isRef(attr: InstantDBAttr) {\n return attr['value-type'] === 'ref';\n}\n\nexport function isBlob(attr: InstantDBAttr) {\n return attr['value-type'] === 'blob';\n}\n\nfunction getAttr(attrs: Attrs, attrId: string): InstantDBAttr | undefined {\n return attrs[attrId];\n}\n\nexport function getInMap(obj, path) {\n return path.reduce((acc, key) => acc && acc.get(key), obj);\n}\n\nfunction deleteInMap(m, path) {\n if (path.length === 0) throw new Error('path must have at least one element');\n if (path.length === 1) {\n m.delete(path[0]);\n return;\n }\n const [head, ...tail] = path;\n if (!m.has(head)) return;\n deleteInMap(m.get(head), tail);\n}\n\nfunction setInMap(m, path, value) {\n if (path.length === 0) throw new Error('path must have at least one element');\n if (path.length === 1) {\n m.set(path[0], value);\n return;\n }\n const [head, ...tail] = path;\n let nextM = m.get(head);\n if (!nextM) {\n nextM = new Map();\n m.set(head, nextM);\n }\n setInMap(nextM, tail, value);\n}\n\nfunction isDateAttr(attr: InstantDBAttr) {\n return attr['checked-data-type'] === 'date';\n}\n\nfunction createTripleIndexes(\n attrsStore: AttrsStore,\n triples: Triple[],\n useDateObjects: boolean | null,\n): Pick<Store, 'eav' | 'aev' | 'vae'> {\n const eav = new Map();\n const aev = new Map();\n const vae = new Map();\n for (const triple of triples) {\n let [eid, aid, v] = triple;\n const attr = attrsStore.getAttr(aid);\n if (!attr) {\n console.warn('no such attr', aid, eid);\n continue;\n }\n\n if (attr['checked-data-type'] === 'date' && useDateObjects) {\n v = coerceToDate(v);\n triple[2] = v;\n }\n\n if (isRef(attr)) {\n setInMap(vae, [v, aid, eid], triple);\n }\n\n setInMap(eav, [eid, aid, v], triple);\n setInMap(aev, [aid, eid, v], triple);\n }\n return { eav, aev, vae };\n}\n\nfunction createAttrIndexes(attrs: Record<string, InstantDBAttr>): AttrIndexes {\n const blobAttrs = new Map();\n const primaryKeys = new Map();\n const forwardIdents = new Map();\n const revIdents = new Map();\n for (const attr of Object.values(attrs)) {\n const fwdIdent = attr['forward-identity'];\n const [_, fwdEtype, fwdLabel] = fwdIdent;\n const revIdent = attr['reverse-identity'];\n\n setInMap(forwardIdents, [fwdEtype, fwdLabel], attr);\n if (isBlob(attr)) {\n setInMap(blobAttrs, [fwdEtype, fwdLabel], attr);\n }\n if (attr['primary?']) {\n setInMap(primaryKeys, [fwdEtype], attr);\n }\n if (revIdent) {\n const [_, revEtype, revLabel] = revIdent;\n setInMap(revIdents, [revEtype, revLabel], attr);\n }\n }\n\n return { blobAttrs, primaryKeys, forwardIdents, revIdents };\n}\n\nexport function toJSON(store: Store): StoreJsonVersion1 {\n return {\n triples: allMapValues(store.eav, 3),\n cardinalityInference: store.cardinalityInference,\n useDateObjects: store.useDateObjects,\n version: 1,\n };\n}\n\nexport function fromJSON(attrsStore: AttrsStore, storeJSON: StoreJson): Store {\n return createStore(\n attrsStore,\n storeJSON.triples,\n storeJSON.cardinalityInference,\n storeJSON.useDateObjects,\n );\n}\n\nexport function attrsStoreFromJSON(\n attrsStoreJSON: AttrsStoreJson | null,\n storeJSON: StoreJson | null,\n): AttrsStore | undefined {\n if (attrsStoreJSON) {\n return new AttrsStore(attrsStoreJSON.attrs, attrsStoreJSON.linkIndex);\n }\n if (storeJSON && '__type' in storeJSON) {\n return new AttrsStore(storeJSON.attrs, storeJSON.linkIndex);\n }\n}\n\nexport function hasTriple(store: Store, [e, a, v]: [string, string, any]) {\n return getInMap(store.eav, [e, a, v]) !== undefined;\n}\n\nexport function hasEntity(store: Store, e: string) {\n return getInMap(store.eav, [e]) !== undefined;\n}\n\nexport function createStore(\n attrsStore: AttrsStore,\n triples: Triple[],\n enableCardinalityInference: boolean | null,\n useDateObjects: boolean | null,\n): Store {\n const store = createTripleIndexes(\n attrsStore,\n triples,\n useDateObjects,\n ) as unknown as Store;\n store.cardinalityInference = enableCardinalityInference;\n store.useDateObjects = useDateObjects;\n return store;\n}\n\n// We may have local triples with lookup refs in them,\n// we need to convert those lookup refs to eids to insert them\n// into the store. If we can't find the lookup ref locally,\n// then we drop the triple and have to wait for the server response\n// to see the optimistic updates.\nfunction resolveLookupRefs(store: Store, triple: Triple): Triple | null {\n let eid;\n\n // Check if `e` is a lookup ref\n if (Array.isArray(triple[0])) {\n const [a, v] = triple[0];\n const eMaps = store.aev.get(a);\n if (!eMaps) {\n // We don't have the attr, so don't try to add the\n // triple to the store\n return null;\n }\n // This would be a lot more efficient with a ave index\n const triples = allMapValues(eMaps, 2);\n eid = triples.find((x) => x[2] === v)?.[0];\n } else {\n eid = triple[0];\n }\n\n if (!eid) {\n // We don't know the eid that the ref refers to, so\n // we can't add the triple to the store.\n return null;\n }\n\n // Check if v is a lookup ref\n const lookupV = triple[2];\n if (\n Array.isArray(lookupV) &&\n lookupV.length === 2 &&\n store.aev.get(lookupV[0])\n ) {\n const [a, v] = lookupV;\n const eMaps = store.aev.get(a);\n if (!eMaps) {\n // We don't have the attr, so don't try to add the\n // triple to the store\n return null;\n }\n const triples = allMapValues(eMaps, 2);\n const value = triples.find((x) => x[2] === v)?.[0];\n if (!value) {\n return null;\n }\n const [_e, aid, _v, ...rest] = triple;\n return [eid, aid, value, ...rest];\n } else {\n const [_, ...rest] = triple;\n return [eid, ...rest];\n }\n}\n\nexport function retractTriple(\n store: Store,\n attrsStore: AttrsStore,\n rawTriple: Triple,\n): void {\n const triple = resolveLookupRefs(store, rawTriple);\n if (!triple) {\n return;\n }\n const [eid, aid, v] = triple;\n const attr = attrsStore.getAttr(aid);\n if (!attr) {\n return;\n }\n\n deleteInMap(store.eav, [eid, aid, v]);\n deleteInMap(store.aev, [aid, eid, v]);\n if (isRef(attr)) {\n deleteInMap(store.vae, [v, aid, eid]);\n }\n}\n\nlet _seed = 0;\nfunction getCreatedAt(\n store: Store,\n attr: InstantDBAttr,\n triple: Triple,\n): Number {\n const [eid, aid, v] = triple;\n let createdAt;\n\n const t = getInMap(store.eav, [eid, aid, v]);\n if (t) {\n createdAt = t[3];\n }\n\n /**\n * (XXX)\n * Two hacks here, for generating a `createdAt`\n *\n * 1. We multiply Date.now() by 10, to make sure that\n * `createdAt` is always greater than anything the server\n * could return\n *\n * We do this because right now we know we _only_ insert\n * triples as optimistic updates.\n *\n * 2. We increment by `_seed`, to make sure there are no\n * two triples with the same `createdAt`. This is\n * done to make tests more predictable.\n *\n * We may need to rethink this. Because we * 10, we can't\n * use this value as an _actual_ `createdAt` timestamp.\n * Eventually we may want too though; For example, we could\n * use `createdAt` for each triple, to infer a `createdAt` and\n * `updatedAt` value for each object.\n */\n return createdAt || Date.now() * 10 + _seed++;\n}\n\nexport function addTriple(\n store: Store,\n attrsStore: AttrsStore,\n rawTriple: Triple,\n) {\n const triple = resolveLookupRefs(store, rawTriple);\n if (!triple) {\n return;\n }\n let [eid, aid, v] = triple;\n const attr = attrsStore.getAttr(aid);\n if (!attr) {\n // (XXX): Due to the way we're handling attrs, it's\n // possible to enter a state where we receive a triple without an attr.\n // See: https://github.com/jsventures/instant-local/pull/132 for details.\n // For now, if we receive a command without an attr, we no-op.\n return;\n }\n\n if (attr['checked-data-type'] === 'date' && store.useDateObjects) {\n v = coerceToDate(v);\n }\n\n const existingTriple = getInMap(store.eav, [eid, aid, v]);\n // Reuse the created_at for a triple if it's already in the store.\n // Prevents updates from temporarily pushing an entity to the top\n // while waiting for the server response.\n const t = existingTriple?.[3] ?? getCreatedAt(store, attr, triple);\n const enhancedTriple = [eid, aid, v, t];\n\n if (hasEA(attr)) {\n setInMap(store.eav, [eid, aid], new Map([[v, enhancedTriple]]));\n setInMap(store.aev, [aid, eid], new Map([[v, enhancedTriple]]));\n } else {\n setInMap(store.eav, [eid, aid, v], enhancedTriple);\n setInMap(store.aev, [aid, eid, v], enhancedTriple);\n }\n\n if (isRef(attr)) {\n setInMap(store.vae, [v, aid, eid], enhancedTriple);\n }\n}\n\nfunction mergeTriple(store: Store, attrsStore: AttrsStore, rawTriple: Triple) {\n const triple = resolveLookupRefs(store, rawTriple);\n if (!triple) {\n return;\n }\n\n const [eid, aid, update] = triple;\n const attr = attrsStore.getAttr(aid);\n\n if (!attr) return;\n\n if (!isBlob(attr))\n throw new Error('merge operation is not supported for links');\n\n const eavValuesMap = getInMap(store.eav, [eid, aid]);\n if (!eavValuesMap) return;\n\n const currentTriple = eavValuesMap.values().next()?.value;\n if (!currentTriple) return;\n\n const currentValue = currentTriple[2];\n\n const updatedValue = immutableDeepMerge(currentValue, update);\n const enhancedTriple = [\n eid,\n aid,\n updatedValue,\n getCreatedAt(store, attr, currentTriple),\n ];\n\n setInMap(store.eav, [eid, aid], new Map([[updatedValue, enhancedTriple]]));\n}\n\nfunction deleteEntity(store: Store, attrsStore: AttrsStore, args: any[]) {\n const [lookup, etype] = args;\n const triple = resolveLookupRefs(store, [lookup] as unknown as Triple);\n\n if (!triple) {\n return;\n }\n const [id] = triple;\n\n // delete forward links and attributes + cardinality one links\n const eMap = store.eav.get(id);\n if (eMap) {\n for (const a of eMap.keys()) {\n const attr = attrsStore.getAttr(a);\n\n // delete cascade refs\n if (attr && attr['on-delete-reverse'] === 'cascade') {\n allMapValues(eMap.get(a), 1).forEach(\n ([e, a, v]: [string, string, any]) =>\n deleteEntity(store, attrsStore, [v, attr['reverse-identity']?.[1]]),\n );\n }\n\n if (\n // Fall back to deleting everything if we've rehydrated tx-steps from\n // the store that didn't set `etype` in deleteEntity\n !etype ||\n // If we don't know about the attr, let's just get rid of it\n !attr ||\n // Make sure it matches the etype\n attr['forward-identity']?.[1] === etype\n ) {\n deleteInMap(store.aev, [a, id]);\n deleteInMap(store.eav, [id, a]);\n }\n }\n // Clear out the eav index for `id` if we deleted all of the attributes\n if (eMap.size === 0) {\n deleteInMap(store.eav, [id]);\n }\n }\n\n // delete reverse links\n const vaeTriples = store.vae.get(id) && allMapValues(store.vae.get(id), 2);\n\n if (vaeTriples) {\n vaeTriples.forEach((triple: Triple) => {\n const [e, a, v] = triple;\n const attr = attrsStore.getAttr(a);\n if (!etype || !attr || attr['reverse-identity']?.[1] === etype) {\n deleteInMap(store.eav, [e, a, v]);\n deleteInMap(store.aev, [a, e, v]);\n deleteInMap(store.vae, [v, a, e]);\n }\n if (\n attr &&\n attr['on-delete'] === 'cascade' &&\n attr['reverse-identity']?.[1] === etype\n ) {\n deleteEntity(store, attrsStore, [e, attr['forward-identity']?.[1]]);\n }\n });\n }\n // Clear out vae index for `id` if we deleted all the reverse attributes\n if (store.vae.get(id)?.size === 0) {\n deleteInMap(store.vae, [id]);\n }\n}\n\n// (XXX): Whenever we change/delete attrs,\n// We indiscriminately reset the index map.\n// There are lots of opportunities for optimization:\n// * We _only_ need to run this indexes change. We could detect that\n// * We could batch this reset at the end\n// * We could add an ave index for all triples, so removing the\n// right triples is easy and fast.\nfunction resetIndexMap(store: Store, attrsStore, newTriples: Triple[]) {\n const newIndexMap = createTripleIndexes(\n attrsStore,\n newTriples,\n store.useDateObjects,\n );\n Object.keys(newIndexMap).forEach((key) => {\n store[key] = newIndexMap[key];\n });\n}\n\nfunction addAttr(attrsStore: AttrsStore, [attr]: [InstantDBAttr]) {\n attrsStore.addAttr(attr);\n}\n\nfunction getAllTriples(store: Store): Triple[] {\n return allMapValues(store.eav, 3);\n}\n\nfunction deleteAttr(store: Store, attrsStore: AttrsStore, [id]: [string]) {\n if (!attrsStore.getAttr(id)) return;\n const newTriples = getAllTriples(store).filter(([_, aid]) => aid !== id);\n attrsStore.deleteAttr(id);\n resetIndexMap(store, attrsStore, newTriples);\n}\n\nfunction updateAttr(\n store: Store,\n attrsStore: AttrsStore,\n [partialAttr]: [Partial<InstantDBAttr> & { id: string }],\n) {\n const attr = attrsStore.getAttr(partialAttr.id);\n if (!attr) return;\n attrsStore.updateAttr(partialAttr);\n resetIndexMap(store, attrsStore, getAllTriples(store));\n}\n\nfunction applyTxStep(store: Store, attrsStore: AttrsStore, txStep) {\n const [action, ...args] = txStep;\n switch (action) {\n case 'add-triple':\n addTriple(store, attrsStore, args);\n break;\n case 'deep-merge-triple':\n mergeTriple(store, attrsStore, args);\n break;\n case 'retract-triple':\n retractTriple(store, attrsStore, args);\n break;\n case 'delete-entity':\n deleteEntity(store, attrsStore, args);\n break;\n case 'add-attr':\n addAttr(attrsStore, args);\n break;\n case 'delete-attr':\n deleteAttr(store, attrsStore, args);\n break;\n case 'update-attr':\n updateAttr(store, attrsStore, args);\n break;\n case 'restore-attr':\n break;\n case 'rule-params':\n break;\n default:\n throw new Error(`unhandled transaction action: ${action}`);\n }\n}\n\nexport function allMapValues(m, level, res: any[] = []) {\n if (!m) {\n return res;\n }\n if (level === 0) {\n return res;\n }\n if (level === 1) {\n for (const v of m.values()) {\n res.push(v);\n }\n return res;\n }\n for (const v of m.values()) {\n allMapValues(v, level - 1, res);\n }\n\n return res;\n}\n\nfunction triplesByValue(store: Store, m: Map<any, Triple>, v: any) {\n const res: Triple[] = [];\n if (v?.hasOwnProperty('$not')) {\n for (const candidate of m.keys()) {\n if (v.$not !== candidate) {\n res.push(m.get(candidate) as Triple);\n }\n }\n return res;\n }\n\n if (v?.hasOwnProperty('$isNull')) {\n const { attrId, isNull, reverse } = v.$isNull;\n\n if (reverse) {\n for (const candidate of m.keys()) {\n const vMap = store.vae.get(candidate);\n const isValNull = !vMap || !vMap.get(attrId);\n if (isNull ? isValNull : !isValNull) {\n res.push(m.get(candidate) as Triple);\n }\n }\n } else {\n const aMap = store.aev.get(attrId);\n for (const candidate of m.keys()) {\n const isValNull =\n !aMap || aMap.get(candidate)?.get(null) || !aMap.get(candidate);\n if (isNull ? isValNull : !isValNull) {\n res.push(m.get(candidate) as Triple);\n }\n }\n }\n return res;\n }\n\n if (v?.$comparator) {\n // TODO: A sorted index would be nice here\n return allMapValues(m, 1).filter(v.$op);\n }\n\n const values = v.in || v.$in || [v];\n\n for (const value of values) {\n const triple = m.get(value);\n if (triple) {\n res.push(triple);\n }\n }\n\n return res;\n}\n\n// A poor man's pattern matching\n// Returns either eav, ea, ev, av, v, or ''\nfunction whichIdx(e, a, v): 'eav' | 'ea' | 'ev' | 'av' | 'e' | 'a' | 'v' | '' {\n let res = '';\n if (e !== undefined) {\n res += 'e';\n }\n if (a !== undefined) {\n res += 'a';\n }\n if (v !== undefined) {\n res += 'v';\n }\n return res as 'eav' | 'ea' | 'ev' | 'av' | 'e' | 'a' | 'v' | '';\n}\n\nexport function getTriples(store, [e, a, v]) {\n const idx = whichIdx(e, a, v);\n switch (idx) {\n case 'e': {\n const eMap = store.eav.get(e);\n return allMapValues(eMap, 2);\n }\n case 'ea': {\n const aMap = store.eav.get(e)?.get(a);\n return allMapValues(aMap, 1);\n }\n case 'eav': {\n const aMap = store.eav.get(e)?.get(a);\n if (!aMap) {\n return [];\n }\n return triplesByValue(store, aMap, v);\n }\n case 'ev': {\n const eMap = store.eav.get(e);\n if (!eMap) {\n return [];\n }\n const res: Triple[] = [];\n for (const aMap of eMap.values()) {\n res.push(...triplesByValue(store, aMap, v));\n }\n return res;\n }\n case 'a': {\n const aMap = store.aev.get(a);\n return allMapValues(aMap, 2);\n }\n case 'av': {\n const aMap = store.aev.get(a);\n if (!aMap) {\n return [];\n }\n const res: Triple[] = [];\n for (const eMap of aMap.values()) {\n res.push(...triplesByValue(store, eMap, v));\n }\n return res;\n }\n case 'v': {\n const res: Triple[] = [];\n for (const eMap of store.eav.values()) {\n for (const aMap of eMap.values()) {\n res.push(...triplesByValue(store, aMap, v));\n }\n }\n return res;\n }\n default: {\n return allMapValues(store.eav, 3);\n }\n }\n}\n\nexport function getAsObject(\n store: Store,\n attrs: Map<string, InstantDBAttr> | undefined,\n e: string,\n) {\n const obj = {};\n\n if (!attrs) {\n return obj;\n }\n\n for (const [label, attr] of attrs.entries()) {\n const aMap = store.eav.get(e)?.get(attr.id);\n const triples = allMapValues(aMap, 1);\n for (const triple of triples) {\n obj[label] = triple[2];\n }\n }\n\n return obj;\n}\n\nexport function getAttrByFwdIdentName(\n attrsStore: AttrsStore,\n inputEtype: string,\n inputLabel: string,\n) {\n return attrsStore.forwardIdents.get(inputEtype)?.get(inputLabel);\n}\n\nexport function getAttrByReverseIdentName(\n attrsStore: AttrsStore,\n inputEtype: string,\n inputLabel: string,\n) {\n return attrsStore.revIdents.get(inputEtype)?.get(inputLabel);\n}\n\nexport function getBlobAttrs(attrsStore: AttrsStore, etype: string) {\n return attrsStore.blobAttrs.get(etype);\n}\n\nexport function getPrimaryKeyAttr(attrsStore: AttrsStore, etype: string) {\n const fromPrimary = attrsStore.primaryKeys.get(etype);\n if (fromPrimary) {\n return fromPrimary;\n }\n return attrsStore.forwardIdents.get(etype)?.get('id');\n}\n\nfunction findTriple(\n store: Store,\n attrsStore: AttrsStore,\n rawTriple: [string, string, any] | Triple,\n): Triple | undefined {\n const triple = resolveLookupRefs(store, rawTriple as Triple);\n if (!triple) {\n return;\n }\n\n const [eid, aid, v] = triple;\n const attr = attrsStore.getAttr(aid);\n if (!attr) {\n // (XXX): Due to the way we're handling attrs, it's\n // possible to enter a state where we receive a triple without an attr.\n // See: https://github.com/jsventures/instant-local/pull/132 for details.\n // For now, if we receive a command without an attr, we no-op.\n return;\n }\n\n return getInMap(store.eav, [eid, aid]);\n}\n\nexport function transact(store: Store, attrsStore: AttrsStore, txSteps) {\n const txStepsFiltered = txSteps.filter(\n ([action, eid, attrId, value, opts]) => {\n if (action !== 'add-triple' && action !== 'deep-merge-triple') {\n return true;\n }\n\n const mode = opts?.mode;\n if (mode !== 'create' && mode !== 'update') {\n return true;\n }\n\n let exists = false;\n\n const attr = attrsStore.getAttr(attrId);\n if (attr) {\n const idAttr = getPrimaryKeyAttr(\n attrsStore,\n attr['forward-identity'][1],\n );\n exists = !!findTriple(store, attrsStore, [\n eid as string,\n idAttr?.id as string,\n eid,\n ]);\n }\n\n if (mode === 'create' && exists) {\n return false;\n }\n\n if (mode === 'update' && !exists) {\n return false;\n }\n\n return true;\n },\n );\n\n return create(store, (draft) => {\n txStepsFiltered.forEach((txStep) => {\n applyTxStep(draft, attrsStore, txStep);\n });\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/store.ts"],"names":[],"mappings":";;;AAoLA,wBAEC;AAMD,4BAEC;AAyFD,wBAOC;AAED,4BAOC;AAED,gDAUC;AAED,8BAEC;AAED,8BAEC;AAED,kCAcC;AA2DD,sCAoBC;AAwCD,8BAyCC;AAqLD,oCAkBC;AAsED,gCAyDC;AAED,kCAoBC;AAED,sDAMC;AAED,8DAMC;AAED,oCAEC;AAED,8CAMC;AAyBD,4BA0DC;AAt7BD,uCAAkC;AAClC,iDAAuD;AACvD,+CAAgD;AA4DhD,MAAa,eAAe;IAO1B,YAAY,KAAY,EAAE,SAA2B;QAJ7C,eAAU,GAAmD,IAAI,CAAC;QAClE,iBAAY,GAAsC,IAAI,CAAC;QACvD,mBAAc,GAAmD,IAAI,CAAC;QACtE,eAAU,GAAmD,IAAI,CAAC;QAExE,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;IAEM,gBAAgB;QACrB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;QACvB,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;QACzB,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;QAC3B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;IACzB,CAAC;IAEM,OAAO,CAAC,IAAmB;QAChC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC;QAC3B,IAAI,CAAC,gBAAgB,EAAE,CAAC;IAC1B,CAAC;IAEM,UAAU,CAAC,MAAc;QAC9B,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAC1B,IAAI,CAAC,gBAAgB,EAAE,CAAC;IAC1B,CAAC;IAEM,UAAU,CAA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,KAAK,QAAQ,IAAI,MAAM,EAAE,CAAC;YAChC,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IAAI,IAAI,KAAK,QAAQ,IAAI,CAAC,MAAM,EAAE,CAAC;YACjC,OAAO,KAAK,CAAC;QACf,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC,CACF,CAAC;IAEF,OAAO,IAAA,iBAAM,EACX,EAAE,KAAK,EAAE,UAAU,EAAE,EACrB,CAAC,KAAK,EAAE,EAAE;QACR,eAAe,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;YACjC,WAAW,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;QACrD,CAAC,CAAC,CAAC;IACL,CAAC,EACD;QACE,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE;YACf,IAAI,MAAM,YAAY,eAAe,EAAE,CAAC;gBACtC,OAAO,WAAW,CAAC;YACrB,CAAC;QACH,CAAC;KACF,CACF,CAAC;AACJ,CAAC","sourcesContent":["import { create } from 'mutative';\nimport { immutableDeepMerge } from './utils/object.js';\nimport { coerceToDate } from './utils/dates.ts';\nimport { InstantDBAttr } from './attrTypes.ts';\nimport { LinkIndex } from './utils/linkIndex.ts';\n\ntype Triple = [string, string, any, number];\ntype Attrs = Record<string, InstantDBAttr>;\n\ninterface AttrIndexes {\n blobAttrs: Map<string, Map<string, InstantDBAttr>>;\n primaryKeys: Map<string, InstantDBAttr>;\n forwardIdents: Map<string, Map<string, InstantDBAttr>>;\n revIdents: Map<string, Map<string, InstantDBAttr>>;\n}\n\nexport type Store = {\n eav: Map<string, Map<string, Map<any, Triple>>>;\n aev: Map<string, Map<string, Map<any, Triple>>>;\n vae: Map<any, Map<string, Map<string, Triple>>>;\n useDateObjects: boolean | null | undefined;\n cardinalityInference: boolean | null | undefined;\n};\n\ntype StoreJsonVersion0 = {\n __type: 'store';\n attrs: Attrs;\n triples: Triple[];\n cardinalityInference: boolean | null | undefined;\n linkIndex: LinkIndex | null;\n useDateObjects: boolean | null | undefined;\n};\n\ntype StoreJsonVersion1 = {\n triples: Triple[];\n cardinalityInference: boolean | null | undefined;\n useDateObjects: boolean | null | undefined;\n version: 1;\n};\n\nexport type StoreJson = StoreJsonVersion0 | StoreJsonVersion1;\n\nexport type AttrsStoreJson = {\n attrs: Attrs;\n linkIndex: LinkIndex | null;\n};\n\nexport interface AttrsStore {\n attrs: Attrs;\n linkIndex: LinkIndex | null;\n resetAttrIndexes(): void;\n addAttr(attr: InstantDBAttr): void;\n deleteAttr(attrId: string): void;\n updateAttr(partialAttr: Partial<InstantDBAttr> & { id: string }): void;\n getAttr(id: string): InstantDBAttr | undefined;\n blobAttrs: Map<string, Map<string, InstantDBAttr>>;\n primaryKeys: Map<string, InstantDBAttr>;\n forwardIdents: Map<string, Map<string, InstantDBAttr>>;\n revIdents: Map<string, Map<string, InstantDBAttr>>;\n toJSON(): AttrsStoreJson;\n}\n\nexport class AttrsStoreClass implements AttrsStore {\n public attrs: Attrs;\n public linkIndex: LinkIndex | null;\n private _blobAttrs: Map<string, Map<string, InstantDBAttr>> | null = null;\n private _primaryKeys: Map<string, InstantDBAttr> | null = null;\n private _forwardIdents: Map<string, Map<string, InstantDBAttr>> | null = null;\n private _revIdents: Map<string, Map<string, InstantDBAttr>> | null = null;\n constructor(attrs: Attrs, linkIndex: LinkIndex | null) {\n this.attrs = attrs;\n this.linkIndex = linkIndex;\n }\n\n public resetAttrIndexes() {\n this._blobAttrs = null;\n this._primaryKeys = null;\n this._forwardIdents = null;\n this._revIdents = null;\n }\n\n public addAttr(attr: InstantDBAttr) {\n this.attrs[attr.id] = attr;\n this.resetAttrIndexes();\n }\n\n public deleteAttr(attrId: string) {\n delete this.attrs[attrId];\n this.resetAttrIndexes();\n }\n\n public updateAttr(partialAttr: Partial<InstantDBAttr> & { id: string }) {\n const attr = this.attrs[partialAttr.id];\n if (!attr) return;\n this.attrs[partialAttr.id] = { ...attr, ...partialAttr };\n this.resetAttrIndexes();\n }\n\n public getAttr(id: string): InstantDBAttr | undefined {\n return this.attrs[id];\n }\n\n // XXX: Might be better to create all of the indexes at once as soon as someone\n // requests one index\n get blobAttrs(): Map<string, Map<string, InstantDBAttr>> {\n if (this._blobAttrs) {\n return this._blobAttrs;\n }\n console.log('blobAttrs');\n this._blobAttrs = new Map();\n for (const attr of Object.values(this.attrs)) {\n if (isBlob(attr)) {\n const [_, fwdEtype, fwdLabel] = attr['forward-identity'];\n setInMap(this.blobAttrs, [fwdEtype, fwdLabel], attr);\n }\n }\n return this._blobAttrs;\n }\n\n get primaryKeys(): Map<string, InstantDBAttr> {\n if (this._primaryKeys) {\n return this._primaryKeys;\n }\n console.log('primayKeys');\n this._primaryKeys = new Map();\n\n for (const attr of Object.values(this.attrs)) {\n if (attr['primary?']) {\n const [_, fwdEtype] = attr['forward-identity'];\n setInMap(this._primaryKeys, [fwdEtype], attr);\n }\n }\n return this._primaryKeys;\n }\n\n get forwardIdents(): Map<string, Map<string, InstantDBAttr>> {\n if (this._forwardIdents) {\n return this._forwardIdents;\n }\n console.log('fwdIdents');\n this._forwardIdents = new Map();\n\n for (const attr of Object.values(this.attrs)) {\n const fwdIdent = attr['forward-identity'];\n const [_, fwdEtype, fwdLabel] = fwdIdent;\n setInMap(this._forwardIdents, [fwdEtype, fwdLabel], attr);\n }\n return this._forwardIdents;\n }\n\n get revIdents(): Map<string, Map<string, InstantDBAttr>> {\n if (this._revIdents) {\n return this._revIdents;\n }\n console.log('revIdents');\n this._revIdents = new Map();\n\n for (const attr of Object.values(this.attrs)) {\n const revIdent = attr['reverse-identity'];\n if (revIdent) {\n const [_, revEtype, revLabel] = revIdent;\n setInMap(this._revIdents, [revEtype, revLabel], attr);\n }\n }\n return this._revIdents;\n }\n\n public toJSON(): AttrsStoreJson {\n return { attrs: this.attrs, linkIndex: this.linkIndex };\n }\n}\n\nfunction hasEA(attr: InstantDBAttr) {\n return attr['cardinality'] === 'one';\n}\n\nfunction isRef(attr: InstantDBAttr) {\n return attr['value-type'] === 'ref';\n}\n\nexport function isBlob(attr: InstantDBAttr) {\n return attr['value-type'] === 'blob';\n}\n\nfunction getAttr(attrs: Attrs, attrId: string): InstantDBAttr | undefined {\n return attrs[attrId];\n}\n\nexport function getInMap(obj, path) {\n return path.reduce((acc, key) => acc && acc.get(key), obj);\n}\n\nfunction deleteInMap(m, path) {\n if (path.length === 0) throw new Error('path must have at least one element');\n if (path.length === 1) {\n m.delete(path[0]);\n return;\n }\n const [head, ...tail] = path;\n if (!m.has(head)) return;\n deleteInMap(m.get(head), tail);\n}\n\nfunction setInMap(m, path, value) {\n if (path.length === 0) throw new Error('path must have at least one element');\n if (path.length === 1) {\n m.set(path[0], value);\n return;\n }\n const [head, ...tail] = path;\n let nextM = m.get(head);\n if (!nextM) {\n nextM = new Map();\n m.set(head, nextM);\n }\n setInMap(nextM, tail, value);\n}\n\nfunction isDateAttr(attr: InstantDBAttr) {\n return attr['checked-data-type'] === 'date';\n}\n\nfunction createTripleIndexes(\n attrsStore: AttrsStore,\n triples: Triple[],\n useDateObjects: boolean | null | undefined,\n): Pick<Store, 'eav' | 'aev' | 'vae'> {\n const eav = new Map();\n const aev = new Map();\n const vae = new Map();\n for (const triple of triples) {\n let [eid, aid, v] = triple;\n const attr = attrsStore.getAttr(aid);\n if (!attr) {\n console.warn('no such attr', aid, eid);\n continue;\n }\n\n if (attr['checked-data-type'] === 'date' && useDateObjects) {\n v = coerceToDate(v);\n triple[2] = v;\n }\n\n if (isRef(attr)) {\n setInMap(vae, [v, aid, eid], triple);\n }\n\n setInMap(eav, [eid, aid, v], triple);\n setInMap(aev, [aid, eid, v], triple);\n }\n return { eav, aev, vae };\n}\n\nfunction createAttrIndexes(attrs: Record<string, InstantDBAttr>): AttrIndexes {\n const blobAttrs = new Map();\n const primaryKeys = new Map();\n const forwardIdents = new Map();\n const revIdents = new Map();\n for (const attr of Object.values(attrs)) {\n const fwdIdent = attr['forward-identity'];\n const [_, fwdEtype, fwdLabel] = fwdIdent;\n const revIdent = attr['reverse-identity'];\n\n setInMap(forwardIdents, [fwdEtype, fwdLabel], attr);\n if (isBlob(attr)) {\n setInMap(blobAttrs, [fwdEtype, fwdLabel], attr);\n }\n if (attr['primary?']) {\n setInMap(primaryKeys, [fwdEtype], attr);\n }\n if (revIdent) {\n const [_, revEtype, revLabel] = revIdent;\n setInMap(revIdents, [revEtype, revLabel], attr);\n }\n }\n\n return { blobAttrs, primaryKeys, forwardIdents, revIdents };\n}\n\nexport function toJSON(store: Store): StoreJsonVersion1 {\n return {\n triples: allMapValues(store.eav, 3),\n cardinalityInference: store.cardinalityInference,\n useDateObjects: store.useDateObjects,\n version: 1,\n };\n}\n\nexport function fromJSON(attrsStore: AttrsStore, storeJSON: StoreJson): Store {\n return createStore(\n attrsStore,\n storeJSON.triples,\n storeJSON.cardinalityInference,\n storeJSON.useDateObjects,\n );\n}\n\nexport function attrsStoreFromJSON(\n attrsStoreJSON: AttrsStoreJson | null,\n storeJSON: StoreJson | null,\n): AttrsStore | undefined {\n if (attrsStoreJSON) {\n return new AttrsStoreClass(attrsStoreJSON.attrs, attrsStoreJSON.linkIndex);\n }\n if (storeJSON && '__type' in storeJSON) {\n return new AttrsStoreClass(storeJSON.attrs, storeJSON.linkIndex);\n }\n}\n\nexport function hasTriple(store: Store, [e, a, v]: [string, string, any]) {\n return getInMap(store.eav, [e, a, v]) !== undefined;\n}\n\nexport function hasEntity(store: Store, e: string) {\n return getInMap(store.eav, [e]) !== undefined;\n}\n\nexport function createStore(\n attrsStore: AttrsStore,\n triples: Triple[],\n enableCardinalityInference?: boolean | null,\n useDateObjects?: boolean | null,\n): Store {\n const store = createTripleIndexes(\n attrsStore,\n triples,\n useDateObjects,\n ) as unknown as Store;\n store.cardinalityInference = enableCardinalityInference;\n store.useDateObjects = useDateObjects;\n return store;\n}\n\n// We may have local triples with lookup refs in them,\n// we need to convert those lookup refs to eids to insert them\n// into the store. If we can't find the lookup ref locally,\n// then we drop the triple and have to wait for the server response\n// to see the optimistic updates.\nfunction resolveLookupRefs(store: Store, triple: Triple): Triple | null {\n let eid;\n\n // Check if `e` is a lookup ref\n if (Array.isArray(triple[0])) {\n const [a, v] = triple[0];\n const eMaps = store.aev.get(a);\n if (!eMaps) {\n // We don't have the attr, so don't try to add the\n // triple to the store\n return null;\n }\n // This would be a lot more efficient with a ave index\n const triples = allMapValues(eMaps, 2);\n eid = triples.find((x) => x[2] === v)?.[0];\n } else {\n eid = triple[0];\n }\n\n if (!eid) {\n // We don't know the eid that the ref refers to, so\n // we can't add the triple to the store.\n return null;\n }\n\n // Check if v is a lookup ref\n const lookupV = triple[2];\n if (\n Array.isArray(lookupV) &&\n lookupV.length === 2 &&\n store.aev.get(lookupV[0])\n ) {\n const [a, v] = lookupV;\n const eMaps = store.aev.get(a);\n if (!eMaps) {\n // We don't have the attr, so don't try to add the\n // triple to the store\n return null;\n }\n const triples = allMapValues(eMaps, 2);\n const value = triples.find((x) => x[2] === v)?.[0];\n if (!value) {\n return null;\n }\n const [_e, aid, _v, ...rest] = triple;\n return [eid, aid, value, ...rest];\n } else {\n const [_, ...rest] = triple;\n return [eid, ...rest];\n }\n}\n\nexport function retractTriple(\n store: Store,\n attrsStore: AttrsStore,\n rawTriple: Triple,\n): void {\n const triple = resolveLookupRefs(store, rawTriple);\n if (!triple) {\n return;\n }\n const [eid, aid, v] = triple;\n const attr = attrsStore.getAttr(aid);\n if (!attr) {\n return;\n }\n\n deleteInMap(store.eav, [eid, aid, v]);\n deleteInMap(store.aev, [aid, eid, v]);\n if (isRef(attr)) {\n deleteInMap(store.vae, [v, aid, eid]);\n }\n}\n\nlet _seed = 0;\nfunction getCreatedAt(\n store: Store,\n attr: InstantDBAttr,\n triple: Triple,\n): Number {\n const [eid, aid, v] = triple;\n let createdAt;\n\n const t = getInMap(store.eav, [eid, aid, v]);\n if (t) {\n createdAt = t[3];\n }\n\n /**\n * (XXX)\n * Two hacks here, for generating a `createdAt`\n *\n * 1. We multiply Date.now() by 10, to make sure that\n * `createdAt` is always greater than anything the server\n * could return\n *\n * We do this because right now we know we _only_ insert\n * triples as optimistic updates.\n *\n * 2. We increment by `_seed`, to make sure there are no\n * two triples with the same `createdAt`. This is\n * done to make tests more predictable.\n *\n * We may need to rethink this. Because we * 10, we can't\n * use this value as an _actual_ `createdAt` timestamp.\n * Eventually we may want too though; For example, we could\n * use `createdAt` for each triple, to infer a `createdAt` and\n * `updatedAt` value for each object.\n */\n return createdAt || Date.now() * 10 + _seed++;\n}\n\nexport function addTriple(\n store: Store,\n attrsStore: AttrsStore,\n rawTriple: Triple,\n) {\n const triple = resolveLookupRefs(store, rawTriple);\n if (!triple) {\n return;\n }\n let [eid, aid, v] = triple;\n const attr = attrsStore.getAttr(aid);\n if (!attr) {\n // (XXX): Due to the way we're handling attrs, it's\n // possible to enter a state where we receive a triple without an attr.\n // See: https://github.com/jsventures/instant-local/pull/132 for details.\n // For now, if we receive a command without an attr, we no-op.\n return;\n }\n\n if (attr['checked-data-type'] === 'date' && store.useDateObjects) {\n v = coerceToDate(v);\n }\n\n const existingTriple = getInMap(store.eav, [eid, aid, v]);\n // Reuse the created_at for a triple if it's already in the store.\n // Prevents updates from temporarily pushing an entity to the top\n // while waiting for the server response.\n const t = existingTriple?.[3] ?? getCreatedAt(store, attr, triple);\n const enhancedTriple = [eid, aid, v, t];\n\n if (hasEA(attr)) {\n setInMap(store.eav, [eid, aid], new Map([[v, enhancedTriple]]));\n setInMap(store.aev, [aid, eid], new Map([[v, enhancedTriple]]));\n } else {\n setInMap(store.eav, [eid, aid, v], enhancedTriple);\n setInMap(store.aev, [aid, eid, v], enhancedTriple);\n }\n\n if (isRef(attr)) {\n setInMap(store.vae, [v, aid, eid], enhancedTriple);\n }\n}\n\nfunction mergeTriple(store: Store, attrsStore: AttrsStore, rawTriple: Triple) {\n const triple = resolveLookupRefs(store, rawTriple);\n if (!triple) {\n return;\n }\n\n const [eid, aid, update] = triple;\n const attr = attrsStore.getAttr(aid);\n\n if (!attr) return;\n\n if (!isBlob(attr))\n throw new Error('merge operation is not supported for links');\n\n const eavValuesMap = getInMap(store.eav, [eid, aid]);\n if (!eavValuesMap) return;\n\n const currentTriple = eavValuesMap.values().next()?.value;\n if (!currentTriple) return;\n\n const currentValue = currentTriple[2];\n\n const updatedValue = immutableDeepMerge(currentValue, update);\n const enhancedTriple = [\n eid,\n aid,\n updatedValue,\n getCreatedAt(store, attr, currentTriple),\n ];\n\n setInMap(store.eav, [eid, aid], new Map([[updatedValue, enhancedTriple]]));\n}\n\nfunction deleteEntity(store: Store, attrsStore: AttrsStore, args: any[]) {\n const [lookup, etype] = args;\n const triple = resolveLookupRefs(store, [lookup] as unknown as Triple);\n\n if (!triple) {\n return;\n }\n const [id] = triple;\n\n // delete forward links and attributes + cardinality one links\n const eMap = store.eav.get(id);\n if (eMap) {\n for (const a of eMap.keys()) {\n const attr = attrsStore.getAttr(a);\n\n // delete cascade refs\n if (attr && attr['on-delete-reverse'] === 'cascade') {\n allMapValues(eMap.get(a), 1).forEach(\n ([e, a, v]: [string, string, any]) =>\n deleteEntity(store, attrsStore, [v, attr['reverse-identity']?.[1]]),\n );\n }\n\n if (\n // Fall back to deleting everything if we've rehydrated tx-steps from\n // the store that didn't set `etype` in deleteEntity\n !etype ||\n // If we don't know about the attr, let's just get rid of it\n !attr ||\n // Make sure it matches the etype\n attr['forward-identity']?.[1] === etype\n ) {\n deleteInMap(store.aev, [a, id]);\n deleteInMap(store.eav, [id, a]);\n }\n }\n // Clear out the eav index for `id` if we deleted all of the attributes\n if (eMap.size === 0) {\n deleteInMap(store.eav, [id]);\n }\n }\n\n // delete reverse links\n const vaeTriples = store.vae.get(id) && allMapValues(store.vae.get(id), 2);\n\n if (vaeTriples) {\n vaeTriples.forEach((triple: Triple) => {\n const [e, a, v] = triple;\n const attr = attrsStore.getAttr(a);\n if (!etype || !attr || attr['reverse-identity']?.[1] === etype) {\n deleteInMap(store.eav, [e, a, v]);\n deleteInMap(store.aev, [a, e, v]);\n deleteInMap(store.vae, [v, a, e]);\n }\n if (\n attr &&\n attr['on-delete'] === 'cascade' &&\n attr['reverse-identity']?.[1] === etype\n ) {\n deleteEntity(store, attrsStore, [e, attr['forward-identity']?.[1]]);\n }\n });\n }\n // Clear out vae index for `id` if we deleted all the reverse attributes\n if (store.vae.get(id)?.size === 0) {\n deleteInMap(store.vae, [id]);\n }\n}\n\n// (XXX): Whenever we change/delete attrs,\n// We indiscriminately reset the index map.\n// There are lots of opportunities for optimization:\n// * We _only_ need to run this indexes change. We could detect that\n// * We could batch this reset at the end\n// * We could add an ave index for all triples, so removing the\n// right triples is easy and fast.\nfunction resetIndexMap(store: Store, attrsStore, newTriples: Triple[]) {\n const newIndexMap = createTripleIndexes(\n attrsStore,\n newTriples,\n store.useDateObjects,\n );\n Object.keys(newIndexMap).forEach((key) => {\n store[key] = newIndexMap[key];\n });\n}\n\nfunction addAttr(attrsStore: AttrsStore, [attr]: [InstantDBAttr]) {\n attrsStore.addAttr(attr);\n}\n\nfunction getAllTriples(store: Store): Triple[] {\n return allMapValues(store.eav, 3);\n}\n\nfunction deleteAttr(store: Store, attrsStore: AttrsStore, [id]: [string]) {\n if (!attrsStore.getAttr(id)) return;\n const newTriples = getAllTriples(store).filter(([_, aid]) => aid !== id);\n attrsStore.deleteAttr(id);\n resetIndexMap(store, attrsStore, newTriples);\n}\n\nfunction updateAttr(\n store: Store,\n attrsStore: AttrsStore,\n [partialAttr]: [Partial<InstantDBAttr> & { id: string }],\n) {\n const attr = attrsStore.getAttr(partialAttr.id);\n if (!attr) return;\n attrsStore.updateAttr(partialAttr);\n resetIndexMap(store, attrsStore, getAllTriples(store));\n}\n\nfunction applyTxStep(store: Store, attrsStore: AttrsStore, txStep) {\n const [action, ...args] = txStep;\n switch (action) {\n case 'add-triple':\n addTriple(store, attrsStore, args);\n break;\n case 'deep-merge-triple':\n mergeTriple(store, attrsStore, args);\n break;\n case 'retract-triple':\n retractTriple(store, attrsStore, args);\n break;\n case 'delete-entity':\n deleteEntity(store, attrsStore, args);\n break;\n case 'add-attr':\n addAttr(attrsStore, args);\n break;\n case 'delete-attr':\n deleteAttr(store, attrsStore, args);\n break;\n case 'update-attr':\n updateAttr(store, attrsStore, args);\n break;\n case 'restore-attr':\n break;\n case 'rule-params':\n break;\n default:\n throw new Error(`unhandled transaction action: ${action}`);\n }\n}\n\nexport function allMapValues(m, level, res: any[] = []) {\n if (!m) {\n return res;\n }\n if (level === 0) {\n return res;\n }\n if (level === 1) {\n for (const v of m.values()) {\n res.push(v);\n }\n return res;\n }\n for (const v of m.values()) {\n allMapValues(v, level - 1, res);\n }\n\n return res;\n}\n\nfunction triplesByValue(store: Store, m: Map<any, Triple>, v: any) {\n const res: Triple[] = [];\n if (v?.hasOwnProperty('$not')) {\n for (const candidate of m.keys()) {\n if (v.$not !== candidate) {\n res.push(m.get(candidate) as Triple);\n }\n }\n return res;\n }\n\n if (v?.hasOwnProperty('$isNull')) {\n const { attrId, isNull, reverse } = v.$isNull;\n\n if (reverse) {\n for (const candidate of m.keys()) {\n const vMap = store.vae.get(candidate);\n const isValNull = !vMap || !vMap.get(attrId);\n if (isNull ? isValNull : !isValNull) {\n res.push(m.get(candidate) as Triple);\n }\n }\n } else {\n const aMap = store.aev.get(attrId);\n for (const candidate of m.keys()) {\n const isValNull =\n !aMap || aMap.get(candidate)?.get(null) || !aMap.get(candidate);\n if (isNull ? isValNull : !isValNull) {\n res.push(m.get(candidate) as Triple);\n }\n }\n }\n return res;\n }\n\n if (v?.$comparator) {\n // TODO: A sorted index would be nice here\n return allMapValues(m, 1).filter(v.$op);\n }\n\n const values = v.in || v.$in || [v];\n\n for (const value of values) {\n const triple = m.get(value);\n if (triple) {\n res.push(triple);\n }\n }\n\n return res;\n}\n\n// A poor man's pattern matching\n// Returns either eav, ea, ev, av, v, or ''\nfunction whichIdx(e, a, v): 'eav' | 'ea' | 'ev' | 'av' | 'e' | 'a' | 'v' | '' {\n let res = '';\n if (e !== undefined) {\n res += 'e';\n }\n if (a !== undefined) {\n res += 'a';\n }\n if (v !== undefined) {\n res += 'v';\n }\n return res as 'eav' | 'ea' | 'ev' | 'av' | 'e' | 'a' | 'v' | '';\n}\n\nexport function getTriples(store, [e, a, v]) {\n const idx = whichIdx(e, a, v);\n switch (idx) {\n case 'e': {\n const eMap = store.eav.get(e);\n return allMapValues(eMap, 2);\n }\n case 'ea': {\n const aMap = store.eav.get(e)?.get(a);\n return allMapValues(aMap, 1);\n }\n case 'eav': {\n const aMap = store.eav.get(e)?.get(a);\n if (!aMap) {\n return [];\n }\n return triplesByValue(store, aMap, v);\n }\n case 'ev': {\n const eMap = store.eav.get(e);\n if (!eMap) {\n return [];\n }\n const res: Triple[] = [];\n for (const aMap of eMap.values()) {\n res.push(...triplesByValue(store, aMap, v));\n }\n return res;\n }\n case 'a': {\n const aMap = store.aev.get(a);\n return allMapValues(aMap, 2);\n }\n case 'av': {\n const aMap = store.aev.get(a);\n if (!aMap) {\n return [];\n }\n const res: Triple[] = [];\n for (const eMap of aMap.values()) {\n res.push(...triplesByValue(store, eMap, v));\n }\n return res;\n }\n case 'v': {\n const res: Triple[] = [];\n for (const eMap of store.eav.values()) {\n for (const aMap of eMap.values()) {\n res.push(...triplesByValue(store, aMap, v));\n }\n }\n return res;\n }\n default: {\n return allMapValues(store.eav, 3);\n }\n }\n}\n\nexport function getAsObject(\n store: Store,\n attrs: Map<string, InstantDBAttr> | undefined,\n e: string,\n) {\n const obj = {};\n\n if (!attrs) {\n return obj;\n }\n\n for (const [label, attr] of attrs.entries()) {\n const aMap = store.eav.get(e)?.get(attr.id);\n const triples = allMapValues(aMap, 1);\n for (const triple of triples) {\n obj[label] = triple[2];\n }\n }\n\n return obj;\n}\n\nexport function getAttrByFwdIdentName(\n attrsStore: AttrsStore,\n inputEtype: string,\n inputLabel: string,\n) {\n return attrsStore.forwardIdents.get(inputEtype)?.get(inputLabel);\n}\n\nexport function getAttrByReverseIdentName(\n attrsStore: AttrsStore,\n inputEtype: string,\n inputLabel: string,\n) {\n return attrsStore.revIdents.get(inputEtype)?.get(inputLabel);\n}\n\nexport function getBlobAttrs(attrsStore: AttrsStore, etype: string) {\n return attrsStore.blobAttrs.get(etype);\n}\n\nexport function getPrimaryKeyAttr(attrsStore: AttrsStore, etype: string) {\n const fromPrimary = attrsStore.primaryKeys.get(etype);\n if (fromPrimary) {\n return fromPrimary;\n }\n return attrsStore.forwardIdents.get(etype)?.get('id');\n}\n\nfunction findTriple(\n store: Store,\n attrsStore: AttrsStore,\n rawTriple: [string, string, any] | Triple,\n): Triple | undefined {\n const triple = resolveLookupRefs(store, rawTriple as Triple);\n if (!triple) {\n return;\n }\n\n const [eid, aid, v] = triple;\n const attr = attrsStore.getAttr(aid);\n if (!attr) {\n // (XXX): Due to the way we're handling attrs, it's\n // possible to enter a state where we receive a triple without an attr.\n // See: https://github.com/jsventures/instant-local/pull/132 for details.\n // For now, if we receive a command without an attr, we no-op.\n return;\n }\n\n return getInMap(store.eav, [eid, aid]);\n}\n\nexport function transact(\n store: Store,\n attrsStore: AttrsStore,\n txSteps,\n): { store: Store; attrsStore: AttrsStore } {\n const txStepsFiltered = txSteps.filter(\n ([action, eid, attrId, value, opts]) => {\n if (action !== 'add-triple' && action !== 'deep-merge-triple') {\n return true;\n }\n\n const mode = opts?.mode;\n if (mode !== 'create' && mode !== 'update') {\n return true;\n }\n\n let exists = false;\n\n const attr = attrsStore.getAttr(attrId);\n if (attr) {\n const idAttr = getPrimaryKeyAttr(\n attrsStore,\n attr['forward-identity'][1],\n );\n exists = !!findTriple(store, attrsStore, [\n eid as string,\n idAttr?.id as string,\n eid,\n ]);\n }\n\n if (mode === 'create' && exists) {\n return false;\n }\n\n if (mode === 'update' && !exists) {\n return false;\n }\n\n return true;\n },\n );\n\n return create(\n { store, attrsStore },\n (draft) => {\n txStepsFiltered.forEach((txStep) => {\n applyTxStep(draft.store, draft.attrsStore, txStep);\n });\n },\n {\n mark: (target) => {\n if (target instanceof AttrsStoreClass) {\n return 'immutable';\n }\n },\n },\n );\n}\n"]}
|
package/dist/esm/Reactor.d.ts
CHANGED
|
@@ -155,7 +155,10 @@ export default class Reactor<RoomSchema extends import("./presence.ts").RoomSche
|
|
|
155
155
|
optimisticAttrs(): sts.AttrsStore;
|
|
156
156
|
/** Runs instaql on a query and a store */
|
|
157
157
|
dataForQuery(hash: any): any;
|
|
158
|
-
_applyOptimisticUpdates(store: any, attrsStore: any, mutations: any, processedTxId: any):
|
|
158
|
+
_applyOptimisticUpdates(store: any, attrsStore: any, mutations: any, processedTxId: any): {
|
|
159
|
+
store: any;
|
|
160
|
+
attrsStore: any;
|
|
161
|
+
};
|
|
159
162
|
/** Re-run instaql and call all callbacks with new data */
|
|
160
163
|
notifyOne: (hash: any) => void;
|
|
161
164
|
notifyOneQueryOnce: (hash: any) => void;
|
|
@@ -1 +1 @@
|
|
|
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,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IAED,4DAWC;IAKD,oFAWC;IAED,8DAWC;IAKD,+CAaC;IAED,wCAWC;CACF;qBA93Ea,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/esm/Reactor.js
CHANGED
|
@@ -698,13 +698,21 @@ export default class Reactor {
|
|
|
698
698
|
const result = x['instaql-result'];
|
|
699
699
|
const hash = weakHash(q);
|
|
700
700
|
const triples = extractTriples(result);
|
|
701
|
-
const
|
|
702
|
-
const
|
|
701
|
+
const attrsStore = this.ensureAttrs();
|
|
702
|
+
const store = sts.createStore(attrsStore, triples, enableCardinalityInference, this.config.useDateObjects);
|
|
703
|
+
const { store: newStore, attrsStore: newAttrsStore } = this._applyOptimisticUpdates(store, attrsStore, mutations, processedTxId);
|
|
703
704
|
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'];
|
|
704
705
|
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'];
|
|
705
|
-
return {
|
|
706
|
+
return {
|
|
707
|
+
q,
|
|
708
|
+
hash,
|
|
709
|
+
store: newStore,
|
|
710
|
+
attrsStore: newAttrsStore,
|
|
711
|
+
pageInfo,
|
|
712
|
+
aggregate,
|
|
713
|
+
};
|
|
706
714
|
});
|
|
707
|
-
updates.forEach(({ hash, q, store, pageInfo, aggregate }) => {
|
|
715
|
+
updates.forEach(({ hash, q, store, attrsStore, pageInfo, aggregate }) => {
|
|
708
716
|
this.querySubs.updateInPlace((prev) => {
|
|
709
717
|
if (!prev[hash]) {
|
|
710
718
|
this._log.error('Missing value in querySubs', { hash, q });
|
|
@@ -712,7 +720,7 @@ export default class Reactor {
|
|
|
712
720
|
}
|
|
713
721
|
prev[hash].result = {
|
|
714
722
|
store,
|
|
715
|
-
attrsStore
|
|
723
|
+
attrsStore,
|
|
716
724
|
pageInfo,
|
|
717
725
|
aggregate,
|
|
718
726
|
processedTxId,
|
|
@@ -909,7 +917,7 @@ export default class Reactor {
|
|
|
909
917
|
this._completeQueryOnce(q, hash, r.dfd);
|
|
910
918
|
}
|
|
911
919
|
_setAttrs(attrs) {
|
|
912
|
-
this.attrs = new sts.
|
|
920
|
+
this.attrs = new sts.AttrsStoreClass(attrs.reduce((acc, attr) => {
|
|
913
921
|
acc[attr.id] = attr;
|
|
914
922
|
return acc;
|
|
915
923
|
}, {}), this._linkIndex);
|
|
@@ -1122,7 +1130,7 @@ export default class Reactor {
|
|
|
1122
1130
|
}
|
|
1123
1131
|
}
|
|
1124
1132
|
if (!deletedAttrIds.size && !pendingAttrs.length) {
|
|
1125
|
-
return this.attrs || new sts.
|
|
1133
|
+
return this.attrs || new sts.AttrsStoreClass({}, this._linkIndex);
|
|
1126
1134
|
}
|
|
1127
1135
|
const attrs = Object.assign({}, (((_b = this.attrs) === null || _b === void 0 ? void 0 : _b.attrs) || {}));
|
|
1128
1136
|
for (const attr of pendingAttrs) {
|
|
@@ -1131,7 +1139,7 @@ export default class Reactor {
|
|
|
1131
1139
|
for (const id of deletedAttrIds) {
|
|
1132
1140
|
delete attrs[id];
|
|
1133
1141
|
}
|
|
1134
|
-
return new sts.
|
|
1142
|
+
return new sts.AttrsStoreClass(attrs, this._linkIndex);
|
|
1135
1143
|
}
|
|
1136
1144
|
/** Runs instaql on a query and a store */
|
|
1137
1145
|
dataForQuery(hash) {
|
|
@@ -1158,17 +1166,19 @@ export default class Reactor {
|
|
|
1158
1166
|
}
|
|
1159
1167
|
const { store, attrsStore, pageInfo, aggregate, processedTxId } = result;
|
|
1160
1168
|
const mutations = this._rewriteMutationsSorted(attrsStore, pendingMutations);
|
|
1161
|
-
const newStore = this._applyOptimisticUpdates(store, attrsStore, mutations, processedTxId);
|
|
1162
|
-
const resp = instaql({ store: newStore, attrsStore, pageInfo, aggregate }, q);
|
|
1169
|
+
const { store: newStore, attrsStore: newAttrsStore } = this._applyOptimisticUpdates(store, attrsStore, mutations, processedTxId);
|
|
1170
|
+
const resp = instaql({ store: newStore, attrsStore: newAttrsStore, pageInfo, aggregate }, q);
|
|
1163
1171
|
return { data: resp, querySubVersion, pendingMutationsVersion };
|
|
1164
1172
|
}
|
|
1165
1173
|
_applyOptimisticUpdates(store, attrsStore, mutations, processedTxId) {
|
|
1166
1174
|
for (const [_, mut] of mutations) {
|
|
1167
1175
|
if (!mut['tx-id'] || (processedTxId && mut['tx-id'] > processedTxId)) {
|
|
1168
|
-
|
|
1176
|
+
const result = sts.transact(store, attrsStore, mut['tx-steps']);
|
|
1177
|
+
store = result.store;
|
|
1178
|
+
attrsStore = result.attrsStore;
|
|
1169
1179
|
}
|
|
1170
1180
|
}
|
|
1171
|
-
return store;
|
|
1181
|
+
return { store, attrsStore };
|
|
1172
1182
|
}
|
|
1173
1183
|
/** Re-compute all subscriptions */
|
|
1174
1184
|
notifyAll() {
|