@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.
Files changed (57) hide show
  1. package/dist/commonjs/Reactor.d.ts +6 -20
  2. package/dist/commonjs/Reactor.d.ts.map +1 -1
  3. package/dist/commonjs/Reactor.js +42 -97
  4. package/dist/commonjs/Reactor.js.map +1 -1
  5. package/dist/commonjs/SyncTable.d.ts +1 -4
  6. package/dist/commonjs/SyncTable.d.ts.map +1 -1
  7. package/dist/commonjs/SyncTable.js +37 -35
  8. package/dist/commonjs/SyncTable.js.map +1 -1
  9. package/dist/commonjs/instaml.d.ts +4 -17
  10. package/dist/commonjs/instaml.d.ts.map +1 -1
  11. package/dist/commonjs/instaml.js +76 -105
  12. package/dist/commonjs/instaml.js.map +1 -1
  13. package/dist/commonjs/instaql.d.ts +1 -2
  14. package/dist/commonjs/instaql.d.ts.map +1 -1
  15. package/dist/commonjs/instaql.js +63 -65
  16. package/dist/commonjs/instaql.js.map +1 -1
  17. package/dist/commonjs/store.d.ts +21 -44
  18. package/dist/commonjs/store.d.ts.map +1 -1
  19. package/dist/commonjs/store.js +69 -164
  20. package/dist/commonjs/store.js.map +1 -1
  21. package/dist/esm/Reactor.d.ts +6 -20
  22. package/dist/esm/Reactor.d.ts.map +1 -1
  23. package/dist/esm/Reactor.js +43 -98
  24. package/dist/esm/Reactor.js.map +1 -1
  25. package/dist/esm/SyncTable.d.ts +1 -4
  26. package/dist/esm/SyncTable.d.ts.map +1 -1
  27. package/dist/esm/SyncTable.js +37 -35
  28. package/dist/esm/SyncTable.js.map +1 -1
  29. package/dist/esm/instaml.d.ts +4 -17
  30. package/dist/esm/instaml.d.ts.map +1 -1
  31. package/dist/esm/instaml.js +71 -102
  32. package/dist/esm/instaml.js.map +1 -1
  33. package/dist/esm/instaql.d.ts +1 -2
  34. package/dist/esm/instaql.d.ts.map +1 -1
  35. package/dist/esm/instaql.js +63 -65
  36. package/dist/esm/instaql.js.map +1 -1
  37. package/dist/esm/store.d.ts +21 -44
  38. package/dist/esm/store.d.ts.map +1 -1
  39. package/dist/esm/store.js +69 -161
  40. package/dist/esm/store.js.map +1 -1
  41. package/dist/standalone/index.js +1364 -1536
  42. package/dist/standalone/index.umd.cjs +3 -3
  43. package/package.json +2 -2
  44. package/src/Reactor.js +58 -126
  45. package/src/SyncTable.ts +45 -85
  46. package/src/{instaml.ts → instaml.js} +95 -195
  47. package/src/instaql.ts +60 -86
  48. package/src/store.ts +79 -209
  49. package/dist/commonjs/reactorTypes.d.ts +0 -29
  50. package/dist/commonjs/reactorTypes.d.ts.map +0 -1
  51. package/dist/commonjs/reactorTypes.js +0 -3
  52. package/dist/commonjs/reactorTypes.js.map +0 -1
  53. package/dist/esm/reactorTypes.d.ts +0 -29
  54. package/dist/esm/reactorTypes.d.ts.map +0 -1
  55. package/dist/esm/reactorTypes.js +0 -2
  56. package/dist/esm/reactorTypes.js.map +0 -1
  57. package/src/reactorTypes.ts +0 -32
@@ -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;QAClE,iBAAY,GAAsC,IAAI,CAAC;QACvD,mBAAc,GAAmD,IAAI,CAAC;QACtE,eAAU,GAAmD,IAAI,CAAC;QAExE,OAAO,CA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K,mBAAmB,EAAE,CAAC;YAC9D,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,IAAI,GAAG,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,IAAI,CAAC;QACxB,IAAI,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC3C,OAAO,IAAI,CAAC;QACd,CAAC;QAED,IAAI,MAAM,GAAG,KAAK,CAAC;QAEnB,MAAM,IAAI,GAAG,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACxC,IAAI,IAAI,EAAE,CAAC;YACT,MAAM,MAAM,GAAG,iBAAiB,CAC9B,UAAU,EACV,IAAI,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAC5B,CAAC;YACF,MAAM,GAAG,CAAC,CAAC,UAAU,CAAC,KAAK,EAAE,UAAU,EAAE;gBACvC,GAAa;gBACb,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,EAAY;gBACpB,GAAG;aACJ,CAAC,CAAC;QACL,CAAC;QAED,IAAI,IAAI,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,EAAC,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE;QAC7B,eAAe,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;YACjC,WAAW,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC;QACzC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,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;\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":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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,EAAC,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE;QAC7B,eAAe,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;YACjC,WAAW,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAC7B,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,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\ntype 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 attrs: Attrs;\n attrIndexes: AttrIndexes;\n cardinalityInference: boolean | null;\n linkIndex: LinkIndex | null;\n __type: 'store';\n};\n\nexport type StoreJson = {\n __type: 'store';\n attrs: Attrs;\n triples: Triple[];\n cardinalityInference: boolean | null;\n linkIndex: LinkIndex | null;\n useDateObjects: boolean | null;\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 attrs: Record<string, InstantDBAttr>,\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, t] = triple;\n const attr = getAttr(attrs, aid);\n if (!attr) {\n console.warn('no such attr', eid, attrs);\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): StoreJson {\n return {\n __type: store.__type,\n attrs: store.attrs,\n triples: allMapValues(store.eav, 3),\n cardinalityInference: store.cardinalityInference,\n linkIndex: store.linkIndex,\n useDateObjects: store.useDateObjects,\n };\n}\n\nexport function fromJSON(storeJSON: StoreJson): Store {\n return createStore(\n storeJSON.attrs,\n storeJSON.triples,\n storeJSON.cardinalityInference,\n storeJSON.linkIndex,\n storeJSON.useDateObjects,\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\nfunction resetAttrIndexes(store: Store) {\n store.attrIndexes = createAttrIndexes(store.attrs);\n}\n\nexport function createStore(\n attrs: Record<string, InstantDBAttr>,\n triples: Triple[],\n enableCardinalityInference: boolean | null,\n linkIndex: LinkIndex | null,\n useDateObjects: boolean | null,\n): Store {\n const store = createTripleIndexes(\n attrs,\n triples,\n useDateObjects,\n ) as unknown as Store;\n store.useDateObjects = useDateObjects;\n store.attrs = attrs;\n store.attrIndexes = createAttrIndexes(attrs);\n store.cardinalityInference = enableCardinalityInference;\n store.linkIndex = linkIndex;\n store.__type = 'store';\n\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(store: Store, rawTriple: Triple): void {\n const triple = resolveLookupRefs(store, rawTriple);\n if (!triple) {\n return;\n }\n const [eid, aid, v] = triple;\n const attr = getAttr(store.attrs, 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(store: Store, rawTriple: Triple) {\n const triple = resolveLookupRefs(store, rawTriple);\n if (!triple) {\n return;\n }\n let [eid, aid, v] = triple;\n const attr = getAttr(store.attrs, 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, rawTriple: Triple) {\n const triple = resolveLookupRefs(store, rawTriple);\n if (!triple) {\n return;\n }\n\n const [eid, aid, update] = triple;\n const attr = getAttr(store.attrs, 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, 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 = store.attrs[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, [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 = store.attrs[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, [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, newTriples: Triple[]) {\n const newIndexMap = createTripleIndexes(\n store.attrs,\n newTriples,\n store.useDateObjects,\n );\n Object.keys(newIndexMap).forEach((key) => {\n store[key] = newIndexMap[key];\n });\n}\n\nfunction addAttr(store: Store, [attr]: [InstantDBAttr]) {\n store.attrs[attr.id] = attr;\n resetAttrIndexes(store);\n}\n\nfunction getAllTriples(store: Store): Triple[] {\n return allMapValues(store.eav, 3);\n}\n\nfunction deleteAttr(store: Store, [id]: [string]) {\n if (!store.attrs[id]) return;\n const newTriples = getAllTriples(store).filter(([_, aid]) => aid !== id);\n delete store.attrs[id];\n resetAttrIndexes(store);\n resetIndexMap(store, newTriples);\n}\n\nfunction updateAttr(\n store: Store,\n [partialAttr]: [Partial<InstantDBAttr> & { id: string }],\n) {\n const attr = store.attrs[partialAttr.id];\n if (!attr) return;\n store.attrs[partialAttr.id] = { ...attr, ...partialAttr };\n resetAttrIndexes(store);\n resetIndexMap(store, getAllTriples(store));\n}\n\nfunction applyTxStep(store: Store, txStep) {\n const [action, ...args] = txStep;\n switch (action) {\n case 'add-triple':\n addTriple(store, args);\n break;\n case 'deep-merge-triple':\n mergeTriple(store, args);\n break;\n case 'retract-triple':\n retractTriple(store, args);\n break;\n case 'delete-entity':\n deleteEntity(store, args);\n break;\n case 'add-attr':\n addAttr(store, args);\n break;\n case 'delete-attr':\n deleteAttr(store, args);\n break;\n case 'update-attr':\n updateAttr(store, 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 store: Store,\n inputEtype: string,\n inputLabel: string,\n) {\n return store.attrIndexes.forwardIdents.get(inputEtype)?.get(inputLabel);\n}\n\nexport function getAttrByReverseIdentName(\n store: Store,\n inputEtype: string,\n inputLabel: string,\n) {\n return store.attrIndexes.revIdents.get(inputEtype)?.get(inputLabel);\n}\n\nexport function getBlobAttrs(store: Store, etype: string) {\n return store.attrIndexes.blobAttrs.get(etype);\n}\n\nexport function getPrimaryKeyAttr(store: Store, etype: string) {\n const fromPrimary = store.attrIndexes.primaryKeys.get(etype);\n if (fromPrimary) {\n return fromPrimary;\n }\n return store.attrIndexes.forwardIdents.get(etype)?.get('id');\n}\n\nfunction findTriple(\n store: Store,\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 = getAttr(store.attrs, 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, 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 = getAttr(store.attrs, attrId);\n if (attr) {\n const idAttr = getPrimaryKeyAttr(store, attr['forward-identity'][1]);\n exists = !!findTriple(store, [\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, txStep);\n });\n });\n}\n"]}
@@ -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
- /** @type {sts.AttrsStore | undefined} */
7
- attrs: sts.AttrsStore | undefined;
6
+ attrs: any;
8
7
  _isOnline: boolean;
9
8
  _isShutdown: boolean;
10
9
  status: string;
11
- /** @type {PersistedObject<string, QuerySub, QuerySubInStorage>} */
12
- querySubs: PersistedObject<string, QuerySub, QuerySubInStorage>;
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, attrsStore: any, mutations: any, processedTxId: any): 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":"AAyMA;;GAEG;AACH,6BAFwD,UAAU,SAArD,OAAQ,eAAe,EAAE,eAAgB;IAmEpD,8KAiHC;IAjLD,yCAAyC;IACzC,OADW,GAAG,CAAC,UAAU,GAAG,SAAS,CAC/B;IACN,mBAAiB;IACjB,qBAAoB;IACpB,eAA2B;IAE3B,mEAAmE;IACnE,WADW,eAAe,CAAC,MAAM,EAAE,QAAQ,EAAE,iBAAiB,CAAC,CACrD;IAEV,8BAA8B;IAC9B,mCAAG;IAEH,wBAAwB;IACxB,YADW,SAAS,CACT;IAEX,wEAAwE;IACxE,UADW,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC;QAAE,CAAC,EAAE,GAAG,CAAC;QAAC,EAAE,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,GAAG,CAAA;KAAE,CAAC,CAAC,CACtD;IACd,gFAAgF;IAChF,eADW,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC;QAAE,CAAC,EAAE,GAAG,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,QAAQ,CAAA;KAAE,CAAC,CAAC,CACzD;IACnB,eAAa;IACb,gBAAc;IACd,wBAAsB;IACtB,2BAAyB;IACzB,YAAO;IACP,qCAAkC;IAClC,0BAA2B;IAC3B,4BAAwB;IACxB,yBAAyB;IACzB,YADW,UAAU,CACV;IACX,4BAA4B;IAC5B,gBADW,aAAa,CACF;IAEtB,qCAAqC;IACrC,cADW,sBAAsB,CACpB;IACb,6BAA6B;IAC7B,OADW,OAAO,GAAG,IAAI,CACZ;IACb,qBAAsB;IACtB,oBAAqB;IACrB,gEAAgE;IAChE,wBADW,OAAO,CAAC,IAAI,GAAG;QAAC,KAAK,EAAE;YAAC,OAAO,EAAE,MA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AS;MA4lD5E;IAED,gCAGC;IAED;;qBAnnD4C,MAAM;;;;;;;;;;;;OAyoDjD;IAED,oCAGC;IAED,+CAiBC;IAED,+BAaC;IAED;;+CAMC;IAED;;;wCAYC;IAED,uEAQC;IAED,iDAOC;IAED,8DAoBC;IAED,kCAIC;IAED;;;;;;;OAOG;IACH,oDAJG;QAAuB,UAAU,EAAzB,MAAM;QACS,WAAW,EAA1B,MAAM;KACd,GAAU,MAAM,CAKlB;IAED;;;;OAIG;IACH,6CAHG;QAAuB,IAAI,EAAnB,MAAM;QACU,YAAY;KACtC,mCAaA;IAED,oBAGC;IAED;;;;;OAKG;IACH,kDAJG;QAAuB,UAAU,EAAzB,MAAM;QACS,OAAO,EAAtB,MAAM;QAC6B,KAAK,GAAxC,MAAM,GAAG,IAAI,GAAG,SAAS;KACnC,mCAeA;IAKD;;;;OAIG;IACH,iBAJW,MAAM,oBACN,GAAG,GAAG,IAAI,GAAG,SAAS,cA4BhC;IAED,gCAiBC;IAMD;;;;;;;;;;;aAUC;IAGD,oEAsBC;IAED,8CAMC;IAED,2CAGC;IAED,iCAEC;IAED,0DAKC;IAGD,8EAuBC;IAED,uCAIC;IAED,oDAaC;IAED,mDAyBC;IAED,gDAWC;IAKD;;;;;aAeC;IAED,uEAQC;IAED,6DAoBC;IAED,4DAWC;IAKD,oFAWC;IAED,8DAWC;IAKD,+CAaC;IAED,wCAWC;CACF;qBAjzEa,OAAO,gBAAgB,EAAE,MAAM;;4BAE/B,OAAO,iBAAiB,EAAE,aAAa;qCACvC,OAAO,iBAAiB,EAAE,sBAAsB;gCAxB9B,4BAA4B;0BAmBlC,gBAAgB;yBApBjB,qBAAqB;yBAJrB,cAAc;4BACX,iBAAiB;6BAHhB,uBAAuB;kCAClB,4BAA4B"}
@@ -21,8 +21,8 @@ var __rest = (this && this.__rest) || function (s, e) {
21
21
  // @ts-check
22
22
  import weakHash from "./utils/weakHash.js";
23
23
  import instaql from "./instaql.js";
24
- import * as instaml from "./instaml.js";
25
- import * as sts from "./store.js";
24
+ import * as instaml from './instaml.js';
25
+ import * as s from "./store.js";
26
26
  import uuid from "./utils/uuid.js";
27
27
  import IndexedDBStorage from "./IndexedDBStorage.js";
28
28
  import WindowNetworkListener from './WindowNetworkListener.js';
@@ -49,8 +49,6 @@ import { SyncTable } from "./SyncTable.js";
49
49
  /** @typedef {import('./Connection.ts').Connection} Connection */
50
50
  /** @typedef {import('./Connection.ts').TransportType} TransportType */
51
51
  /** @typedef {import('./Connection.ts').EventSourceConstructor} EventSourceConstructor */
52
- /** @typedef {import('./reactorTypes.ts').QuerySub} QuerySub */
53
- /** @typedef {import('./reactorTypes.ts').QuerySubInStorage} QuerySubInStorage */
54
52
  const STATUS = {
55
53
  CONNECTING: 'connecting',
56
54
  OPENED: 'opened',
@@ -103,37 +101,20 @@ const ignoreLogging = {
103
101
  'refresh-presence': true,
104
102
  'patch-presence': true,
105
103
  };
106
- /**
107
- * @param {QuerySubInStorage} x
108
- * @param {boolean | null} useDateObjects
109
- * @returns {QuerySub}
110
- */
111
104
  function querySubFromStorage(x, useDateObjects) {
112
105
  var _a;
113
106
  const v = typeof x === 'string' ? JSON.parse(x) : x;
114
107
  if ((_a = v === null || v === void 0 ? void 0 : v.result) === null || _a === void 0 ? void 0 : _a.store) {
115
- const attrsStore = sts.attrsStoreFromJSON(v.result.attrsStore, v.result.store);
116
- if (attrsStore) {
117
- const storeJSON = v.result.store;
118
- v.result.store = sts.fromJSON(attrsStore, Object.assign(Object.assign({}, storeJSON), { useDateObjects: useDateObjects }));
119
- v.result.attrsStore = attrsStore;
120
- }
108
+ const storeJSON = v.result.store;
109
+ v.result.store = s.fromJSON(Object.assign(Object.assign({}, storeJSON), { useDateObjects: useDateObjects }));
121
110
  }
122
111
  return v;
123
112
  }
124
- /**
125
- *
126
- * @param {string} _key
127
- * @param {QuerySub} sub
128
- * @returns QuerySubInStorage
129
- */
130
113
  function querySubToStorage(_key, sub) {
131
- const { result } = sub, rest = __rest(sub, ["result"]);
132
- const jsonSub = /** @type {import('./reactorTypes.ts').QuerySubInStorage} */ (rest);
133
- if (result) {
134
- /** @type {import('./reactorTypes.ts').QuerySubResultInStorage} */
135
- const jsonResult = Object.assign(Object.assign({}, result), { store: sts.toJSON(result.store), attrsStore: result.attrsStore.toJSON() });
136
- jsonSub.result = jsonResult;
114
+ var _a;
115
+ const jsonSub = Object.assign({}, sub);
116
+ if ((_a = sub.result) === null || _a === void 0 ? void 0 : _a.store) {
117
+ jsonSub.result = Object.assign(Object.assign({}, sub.result), { store: s.toJSON(sub.result.store) });
137
118
  }
138
119
  return jsonSub;
139
120
  }
@@ -278,7 +259,7 @@ export default class Reactor {
278
259
  }
279
260
  try {
280
261
  const txSteps = instaml.transform({
281
- attrsStore: this.optimisticAttrs(),
262
+ attrs: this.optimisticAttrs(),
282
263
  schema: this.config.schema,
283
264
  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; }),
284
265
  useDateObjects: this.config.useDateObjects,
@@ -444,9 +425,7 @@ export default class Reactor {
444
425
  this._initStorage(Storage);
445
426
  this._syncTable = new SyncTable(this._trySendAuthed.bind(this), new Storage(this.config.appId, 'syncSubs'), {
446
427
  useDateObjects: this.config.useDateObjects,
447
- }, this._log, (triples) => {
448
- return sts.createStore(this.ensureAttrs(), triples, this.config.enableCardinalityInference, this.config.useDateObjects);
449
- }, () => this.ensureAttrs());
428
+ }, this._log, (triples) => s.createStore(this.attrs, triples, this.config.enableCardinalityInference, this._linkIndex, this.config.useDateObjects));
450
429
  this._oauthCallbackResponse = this._oauthLoginInit();
451
430
  // kick off a request to cache it
452
431
  this.getCurrentUser();
@@ -476,12 +455,6 @@ export default class Reactor {
476
455
  addEventListener('beforeunload', this._beforeUnload);
477
456
  }
478
457
  }
479
- ensureAttrs() {
480
- if (!this.attrs) {
481
- throw new Error('attrs have not loaded.');
482
- }
483
- return this.attrs;
484
- }
485
458
  updateSchema(schema) {
486
459
  this.config = Object.assign(Object.assign({}, this.config), { schema: schema, cardinalityInference: Boolean(schema) });
487
460
  this._linkIndex = schema ? createLinkIndex(this.config.schema) : null;
@@ -505,7 +478,7 @@ export default class Reactor {
505
478
  serialize: querySubToStorage,
506
479
  parse: (_key, x) => querySubFromStorage(x, this.config.useDateObjects),
507
480
  // objectSize
508
- objectSize: (x) => { var _a, _b, _c, _d; return (_d = (_c = (_b = (_a = x === null || x === void 0 ? void 0 : x.result) === null || _a === void 0 ? void 0 : _a.store) === null || _b === void 0 ? void 0 : _b.triples) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0; },
481
+ 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; },
509
482
  logger: this._log,
510
483
  preloadEntryCount: 10,
511
484
  gc: {
@@ -639,7 +612,7 @@ export default class Reactor {
639
612
  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'];
640
613
  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'];
641
614
  const triples = extractTriples(result);
642
- const store = sts.createStore(this.ensureAttrs(), triples, enableCardinalityInference, this.config.useDateObjects);
615
+ const store = s.createStore(this.attrs, triples, enableCardinalityInference, this._linkIndex, this.config.useDateObjects);
643
616
  this.querySubs.updateInPlace((prev) => {
644
617
  if (!prev[hash]) {
645
618
  this._log.info('Missing value in querySubs', { hash, q });
@@ -647,7 +620,6 @@ export default class Reactor {
647
620
  }
648
621
  prev[hash].result = {
649
622
  store,
650
- attrsStore: this.ensureAttrs(),
651
623
  pageInfo,
652
624
  aggregate,
653
625
  processedTxId: msg['processed-tx-id'],
@@ -682,7 +654,7 @@ export default class Reactor {
682
654
  this._setAttrs(attrs);
683
655
  }
684
656
  this._cleanupPendingMutationsTimeout();
685
- const rewrittenMutations = this._rewriteMutations(this.ensureAttrs(), this._pendingMutations(), processedTxId);
657
+ const rewrittenMutations = this._rewriteMutations(this.attrs, this._pendingMutations(), processedTxId);
686
658
  if (rewrittenMutations !== this._pendingMutations()) {
687
659
  // We know we've changed the mutations to fix the attr ids and removed
688
660
  // processed attrs, so we'll persist those changes to prevent optimisticAttrs
@@ -698,8 +670,8 @@ export default class Reactor {
698
670
  const result = x['instaql-result'];
699
671
  const hash = weakHash(q);
700
672
  const triples = extractTriples(result);
701
- const store = sts.createStore(this.ensureAttrs(), triples, enableCardinalityInference, this.config.useDateObjects);
702
- const newStore = this._applyOptimisticUpdates(store, this.ensureAttrs(), mutations, processedTxId);
673
+ const store = s.createStore(this.attrs, triples, enableCardinalityInference, this._linkIndex, this.config.useDateObjects);
674
+ const newStore = this._applyOptimisticUpdates(store, mutations, processedTxId);
703
675
  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
676
  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
677
  return { q, hash, store: newStore, pageInfo, aggregate };
@@ -710,13 +682,7 @@ export default class Reactor {
710
682
  this._log.error('Missing value in querySubs', { hash, q });
711
683
  return;
712
684
  }
713
- prev[hash].result = {
714
- store,
715
- attrsStore: this.ensureAttrs(),
716
- pageInfo,
717
- aggregate,
718
- processedTxId,
719
- };
685
+ prev[hash].result = { store, pageInfo, aggregate, processedTxId };
720
686
  });
721
687
  });
722
688
  this._cleanupPendingMutationsQueries();
@@ -728,7 +694,7 @@ export default class Reactor {
728
694
  case 'transact-ok': {
729
695
  const { 'client-event-id': eventId, 'tx-id': txId } = msg;
730
696
  this._inFlightMutationEventIds.delete(eventId);
731
- const muts = this._rewriteMutations(this.ensureAttrs(), this._pendingMutations());
697
+ const muts = this._rewriteMutations(this.attrs, this._pendingMutations());
732
698
  const prevMutation = muts.get(eventId);
733
699
  if (!prevMutation) {
734
700
  break;
@@ -737,18 +703,11 @@ export default class Reactor {
737
703
  this._updatePendingMutations((prev) => {
738
704
  prev.set(eventId, Object.assign(Object.assign({}, prev.get(eventId)), { 'tx-id': txId, confirmed: Date.now() }));
739
705
  });
740
- const newAttrs = [];
741
- for (const step of prevMutation['tx-steps']) {
742
- if (step[0] === 'add-attr') {
743
- const attr = step[1];
744
- newAttrs.push(attr);
745
- }
746
- }
747
- if (newAttrs.length) {
748
- const existingAttrs = Object.values(this.ensureAttrs());
749
- this._setAttrs([...existingAttrs, ...newAttrs]);
750
- this._setAttrs(newAttrs);
751
- }
706
+ const newAttrs = prevMutation['tx-steps']
707
+ .filter(([action, ..._args]) => action === 'add-attr')
708
+ .map(([_action, attr]) => attr)
709
+ .concat(Object.values(this.attrs));
710
+ this._setAttrs(newAttrs);
752
711
  this._finishTransaction('synced', eventId);
753
712
  this._cleanupPendingMutationsTimeout();
754
713
  break;
@@ -909,10 +868,10 @@ export default class Reactor {
909
868
  this._completeQueryOnce(q, hash, r.dfd);
910
869
  }
911
870
  _setAttrs(attrs) {
912
- this.attrs = new sts.AttrsStore(attrs.reduce((acc, attr) => {
871
+ this.attrs = attrs.reduce((acc, attr) => {
913
872
  acc[attr.id] = attr;
914
873
  return acc;
915
- }, {}), this._linkIndex);
874
+ }, {});
916
875
  this.notifyAttrsSubs();
917
876
  }
918
877
  _startQuerySub(q, hash) {
@@ -1018,12 +977,6 @@ export default class Reactor {
1018
977
  // We remove `add-attr` commands for attrs that already exist.
1019
978
  // We update `add-triple` and `retract-triple` commands to use the
1020
979
  // server attr-ids.
1021
- /**
1022
- *
1023
- * @param {sts.AttrsStore} attrs
1024
- * @param {any} muts
1025
- * @param {number} [processedTxId]
1026
- */
1027
980
  _rewriteMutations(attrs, muts, processedTxId) {
1028
981
  if (!attrs)
1029
982
  return muts;
@@ -1031,12 +984,12 @@ export default class Reactor {
1031
984
  return new Map();
1032
985
  const findExistingAttr = (attr) => {
1033
986
  const [_, etype, label] = attr['forward-identity'];
1034
- const existing = sts.getAttrByFwdIdentName(attrs, etype, label);
987
+ const existing = instaml.getAttrByFwdIdentName(attrs, etype, label);
1035
988
  return existing;
1036
989
  };
1037
990
  const findReverseAttr = (attr) => {
1038
991
  const [_, etype, label] = attr['forward-identity'];
1039
- const revAttr = sts.getAttrByReverseIdentName(attrs, etype, label);
992
+ const revAttr = instaml.getAttrByReverseIdentName(attrs, etype, label);
1040
993
  return revAttr;
1041
994
  };
1042
995
  const mapping = { attrIdMap: {}, refSwapAttrIds: new Set() };
@@ -1099,11 +1052,8 @@ export default class Reactor {
1099
1052
  }
1100
1053
  // ---------------------------
1101
1054
  // Transact
1102
- /**
1103
- * @returns {sts.AttrsStore}
1104
- */
1105
1055
  optimisticAttrs() {
1106
- var _a, _b;
1056
+ var _a;
1107
1057
  const pendingMutationSteps = [...this._pendingMutations().values()] // hack due to Map()
1108
1058
  .flatMap((x) => x['tx-steps']);
1109
1059
  const deletedAttrIds = new Set(pendingMutationSteps
@@ -1116,22 +1066,17 @@ export default class Reactor {
1116
1066
  }
1117
1067
  else if (_action === 'update-attr' &&
1118
1068
  attr.id &&
1119
- ((_a = this.attrs) === null || _a === void 0 ? void 0 : _a.getAttr(attr.id))) {
1120
- const fullAttr = Object.assign(Object.assign({}, this.attrs.getAttr(attr.id)), attr);
1069
+ ((_a = this.attrs) === null || _a === void 0 ? void 0 : _a[attr.id])) {
1070
+ const fullAttr = Object.assign(Object.assign({}, this.attrs[attr.id]), attr);
1121
1071
  pendingAttrs.push(fullAttr);
1122
1072
  }
1123
1073
  }
1124
- if (!deletedAttrIds.size && !pendingAttrs.length) {
1125
- return this.attrs || new sts.AttrsStore({}, this._linkIndex);
1126
- }
1127
- const attrs = Object.assign({}, (((_b = this.attrs) === null || _b === void 0 ? void 0 : _b.attrs) || {}));
1128
- for (const attr of pendingAttrs) {
1129
- attrs[attr.id] = attr;
1130
- }
1131
- for (const id of deletedAttrIds) {
1132
- delete attrs[id];
1133
- }
1134
- return new sts.AttrsStore(attrs, this._linkIndex);
1074
+ const attrsWithoutDeleted = [
1075
+ ...Object.values(this.attrs || {}),
1076
+ ...pendingAttrs,
1077
+ ].filter((a) => !deletedAttrIds.has(a.id));
1078
+ const attrsRecord = Object.fromEntries(attrsWithoutDeleted.map((a) => [a.id, a]));
1079
+ return attrsRecord;
1135
1080
  }
1136
1081
  /** Runs instaql on a query and a store */
1137
1082
  dataForQuery(hash) {
@@ -1156,16 +1101,16 @@ export default class Reactor {
1156
1101
  pendingMutationsVersion === cached.pendingMutationsVersion) {
1157
1102
  return cached;
1158
1103
  }
1159
- const { store, attrsStore, pageInfo, aggregate, processedTxId } = result;
1160
- 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);
1104
+ const { store, pageInfo, aggregate, processedTxId } = result;
1105
+ const mutations = this._rewriteMutationsSorted(store.attrs, pendingMutations);
1106
+ const newStore = this._applyOptimisticUpdates(store, mutations, processedTxId);
1107
+ const resp = instaql({ store: newStore, pageInfo, aggregate }, q);
1163
1108
  return { data: resp, querySubVersion, pendingMutationsVersion };
1164
1109
  }
1165
- _applyOptimisticUpdates(store, attrsStore, mutations, processedTxId) {
1110
+ _applyOptimisticUpdates(store, mutations, processedTxId) {
1166
1111
  for (const [_, mut] of mutations) {
1167
1112
  if (!mut['tx-id'] || (processedTxId && mut['tx-id'] > processedTxId)) {
1168
- store = sts.transact(store, attrsStore, mut['tx-steps']);
1113
+ store = s.transact(store, mut['tx-steps']);
1169
1114
  }
1170
1115
  }
1171
1116
  return store;
@@ -1248,7 +1193,7 @@ export default class Reactor {
1248
1193
  .forEach(({ eventId, q }) => {
1249
1194
  this._trySendAuthed(eventId, { op: 'add-query', q });
1250
1195
  });
1251
- const muts = this._rewriteMutationsSorted(this.ensureAttrs(), this._pendingMutations());
1196
+ const muts = this._rewriteMutationsSorted(this.attrs, this._pendingMutations());
1252
1197
  muts.forEach(([eventId, mut]) => {
1253
1198
  if (!mut['tx-id']) {
1254
1199
  this._sendMutation(eventId, mut);
@@ -1535,7 +1480,7 @@ export default class Reactor {
1535
1480
  subscribeAttrs(cb) {
1536
1481
  this.attrsCbs.push(cb);
1537
1482
  if (this.attrs) {
1538
- cb(this.attrs.attrs);
1483
+ cb(this.attrs);
1539
1484
  }
1540
1485
  return () => {
1541
1486
  this.attrsCbs = this.attrsCbs.filter((x) => x !== cb);