@instantdb/core 0.22.86-experimental.separate-attrs.20122276424.1 → 0.22.86-experimental.split-store.20178922132.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commonjs/Reactor.d.ts +20 -6
- package/dist/commonjs/Reactor.d.ts.map +1 -1
- package/dist/commonjs/Reactor.js +97 -42
- package/dist/commonjs/Reactor.js.map +1 -1
- package/dist/commonjs/SyncTable.d.ts +4 -1
- package/dist/commonjs/SyncTable.d.ts.map +1 -1
- package/dist/commonjs/SyncTable.js +35 -37
- package/dist/commonjs/SyncTable.js.map +1 -1
- package/dist/commonjs/instaml.d.ts +17 -4
- package/dist/commonjs/instaml.d.ts.map +1 -1
- package/dist/commonjs/instaml.js +105 -76
- package/dist/commonjs/instaml.js.map +1 -1
- package/dist/commonjs/instaql.d.ts +2 -1
- package/dist/commonjs/instaql.d.ts.map +1 -1
- package/dist/commonjs/instaql.js +65 -63
- package/dist/commonjs/instaql.js.map +1 -1
- package/dist/commonjs/reactorTypes.d.ts +29 -0
- package/dist/commonjs/reactorTypes.d.ts.map +1 -0
- package/dist/commonjs/reactorTypes.js +3 -0
- package/dist/commonjs/reactorTypes.js.map +1 -0
- package/dist/commonjs/store.d.ts +44 -21
- package/dist/commonjs/store.d.ts.map +1 -1
- package/dist/commonjs/store.js +164 -69
- package/dist/commonjs/store.js.map +1 -1
- package/dist/esm/Reactor.d.ts +20 -6
- package/dist/esm/Reactor.d.ts.map +1 -1
- package/dist/esm/Reactor.js +98 -43
- package/dist/esm/Reactor.js.map +1 -1
- package/dist/esm/SyncTable.d.ts +4 -1
- package/dist/esm/SyncTable.d.ts.map +1 -1
- package/dist/esm/SyncTable.js +35 -37
- package/dist/esm/SyncTable.js.map +1 -1
- package/dist/esm/instaml.d.ts +17 -4
- package/dist/esm/instaml.d.ts.map +1 -1
- package/dist/esm/instaml.js +102 -71
- package/dist/esm/instaml.js.map +1 -1
- package/dist/esm/instaql.d.ts +2 -1
- package/dist/esm/instaql.d.ts.map +1 -1
- package/dist/esm/instaql.js +65 -63
- package/dist/esm/instaql.js.map +1 -1
- package/dist/esm/reactorTypes.d.ts +29 -0
- package/dist/esm/reactorTypes.d.ts.map +1 -0
- package/dist/esm/reactorTypes.js +2 -0
- package/dist/esm/reactorTypes.js.map +1 -0
- package/dist/esm/store.d.ts +44 -21
- package/dist/esm/store.d.ts.map +1 -1
- package/dist/esm/store.js +161 -69
- package/dist/esm/store.js.map +1 -1
- package/dist/standalone/index.js +1517 -1345
- package/dist/standalone/index.umd.cjs +3 -3
- package/package.json +2 -2
- package/src/Reactor.js +126 -58
- package/src/SyncTable.ts +85 -45
- package/src/{instaml.js → instaml.ts} +195 -95
- package/src/instaql.ts +86 -60
- package/src/reactorTypes.ts +32 -0
- package/src/store.ts +209 -79
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/store.ts"],"names":[],"mappings":";;AA6CA,wBAEC;AAMD,4BAEC;AAyFD,wBASC;AAED,4BAQC;AAED,8BAEC;AAED,8BAEC;AAMD,kCAoBC;AA2DD,sCAgBC;AAwCD,8BAqCC;AAuLD,oCAkBC;AAsED,gCAyDC;AAED,kCAoBC;AAED,sDAMC;AAED,8DAMC;AAED,oCAEC;AAED,8CAMC;AAwBD,4BAyCC;AAxxBD,uCAAkC;AAClC,iDAAuD;AACvD,+CAAgD;AAmChD,SAAS,KAAK,CAAC,IAAmB;IAChC,OAAO,IAAI,CAAC,aAAa,CAAC,KAAK,KAAK,CAAC;AACvC,CAAC;AAED,SAAS,KAAK,CAAC,IAAmB;IAChC,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,KAAK,CAAC;AACtC,CAAC;AAED,SAAgB,MAAM,CAAC,IAAmB;IACxC,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,MAAM,CAAC;AACvC,CAAC;AAED,SAAS,OAAO,CAAC,KAAY,EAAE,MAAc;IAC3C,OAAO,KA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AI,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,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAC1C,IAAI,IAAI,EAAE,CAAC;YACT,MAAM,MAAM,GAAG,iBAAiB,CAAC,KAAK,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACrE,MAAM,GAAG,CAAC,CAAC,UAAU,CAAC,KAAK,EAAE;gBAC3B,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,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"]}
|
|
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,CAAC,GAAG,CAAC,YAAY,EAAE,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;QAC9C,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,CAA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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"]}
|
package/dist/esm/Reactor.d.ts
CHANGED
|
@@ -3,12 +3,13 @@
|
|
|
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
|
-
|
|
6
|
+
/** @type {sts.AttrsStore | undefined} */
|
|
7
|
+
attrs: sts.AttrsStore | undefined;
|
|
7
8
|
_isOnline: boolean;
|
|
8
9
|
_isShutdown: boolean;
|
|
9
10
|
status: string;
|
|
10
|
-
/** @type {PersistedObject} */
|
|
11
|
-
querySubs: PersistedObject<
|
|
11
|
+
/** @type {PersistedObject<string, QuerySub, QuerySubInStorage>} */
|
|
12
|
+
querySubs: PersistedObject<string, QuerySub, QuerySubInStorage>;
|
|
12
13
|
/** @type {PersistedObject} */
|
|
13
14
|
kv: PersistedObject<any, any, any>;
|
|
14
15
|
/** @type {SyncTable} */
|
|
@@ -78,6 +79,7 @@ export default class Reactor<RoomSchema extends import("./presence.ts").RoomSche
|
|
|
78
79
|
queryCacheLimit: any;
|
|
79
80
|
versions: any;
|
|
80
81
|
_beforeUnload(): void;
|
|
82
|
+
ensureAttrs(): sts.AttrsStore;
|
|
81
83
|
updateSchema(schema: any): void;
|
|
82
84
|
_reactorStats(): {
|
|
83
85
|
inFlightMutationCount: number;
|
|
@@ -139,12 +141,21 @@ export default class Reactor<RoomSchema extends import("./presence.ts").RoomSche
|
|
|
139
141
|
_unsubQuery(q: any, hash: any, cb: any): void;
|
|
140
142
|
_hasQueryListeners(hash: any): boolean;
|
|
141
143
|
_cleanupQuery(q: any, hash: any): void;
|
|
142
|
-
|
|
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;
|
|
143
151
|
_rewriteMutationsSorted(attrs: any, muts: any): any[];
|
|
144
|
-
|
|
152
|
+
/**
|
|
153
|
+
* @returns {sts.AttrsStore}
|
|
154
|
+
*/
|
|
155
|
+
optimisticAttrs(): sts.AttrsStore;
|
|
145
156
|
/** Runs instaql on a query and a store */
|
|
146
157
|
dataForQuery(hash: any): any;
|
|
147
|
-
_applyOptimisticUpdates(store: any, mutations: any, processedTxId: any): any;
|
|
158
|
+
_applyOptimisticUpdates(store: any, attrsStore: any, mutations: any, processedTxId: any): any;
|
|
148
159
|
/** Re-run instaql and call all callbacks with new data */
|
|
149
160
|
notifyOne: (hash: any) => void;
|
|
150
161
|
notifyOneQueryOnce: (hash: any) => void;
|
|
@@ -338,6 +349,9 @@ export type Logger = import("./utils/log.ts").Logger;
|
|
|
338
349
|
export type Connection = import("./Connection.ts").Connection<any>;
|
|
339
350
|
export type TransportType = import("./Connection.ts").TransportType;
|
|
340
351
|
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';
|
|
341
355
|
import { PersistedObject } from './utils/PersistedObject.ts';
|
|
342
356
|
import { SyncTable } from './SyncTable.ts';
|
|
343
357
|
import { Deferred } from './utils/Deferred.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Reactor.d.ts","sourceRoot":"","sources":["../../src/Reactor.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Reactor.d.ts","sourceRoot":"","sources":["../../src/Reactor.js"],"names":[],"mappings":"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;IACt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uBC;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;qBAr3Ea,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
|
@@ -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
|
|
25
|
-
import * as
|
|
24
|
+
import * as instaml from "./instaml.js";
|
|
25
|
+
import * as sts 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,6 +49,8 @@ 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 */
|
|
52
54
|
const STATUS = {
|
|
53
55
|
CONNECTING: 'connecting',
|
|
54
56
|
OPENED: 'opened',
|
|
@@ -101,20 +103,37 @@ const ignoreLogging = {
|
|
|
101
103
|
'refresh-presence': true,
|
|
102
104
|
'patch-presence': true,
|
|
103
105
|
};
|
|
106
|
+
/**
|
|
107
|
+
* @param {QuerySubInStorage} x
|
|
108
|
+
* @param {boolean | null} useDateObjects
|
|
109
|
+
* @returns {QuerySub}
|
|
110
|
+
*/
|
|
104
111
|
function querySubFromStorage(x, useDateObjects) {
|
|
105
112
|
var _a;
|
|
106
113
|
const v = typeof x === 'string' ? JSON.parse(x) : x;
|
|
107
114
|
if ((_a = v === null || v === void 0 ? void 0 : v.result) === null || _a === void 0 ? void 0 : _a.store) {
|
|
108
|
-
const
|
|
109
|
-
|
|
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
|
+
}
|
|
110
121
|
}
|
|
111
122
|
return v;
|
|
112
123
|
}
|
|
124
|
+
/**
|
|
125
|
+
*
|
|
126
|
+
* @param {string} _key
|
|
127
|
+
* @param {QuerySub} sub
|
|
128
|
+
* @returns QuerySubInStorage
|
|
129
|
+
*/
|
|
113
130
|
function querySubToStorage(_key, sub) {
|
|
114
|
-
|
|
115
|
-
const jsonSub =
|
|
116
|
-
if (
|
|
117
|
-
|
|
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;
|
|
118
137
|
}
|
|
119
138
|
return jsonSub;
|
|
120
139
|
}
|
|
@@ -259,7 +278,7 @@ export default class Reactor {
|
|
|
259
278
|
}
|
|
260
279
|
try {
|
|
261
280
|
const txSteps = instaml.transform({
|
|
262
|
-
|
|
281
|
+
attrsStore: this.optimisticAttrs(),
|
|
263
282
|
schema: this.config.schema,
|
|
264
283
|
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; }),
|
|
265
284
|
useDateObjects: this.config.useDateObjects,
|
|
@@ -425,7 +444,9 @@ export default class Reactor {
|
|
|
425
444
|
this._initStorage(Storage);
|
|
426
445
|
this._syncTable = new SyncTable(this._trySendAuthed.bind(this), new Storage(this.config.appId, 'syncSubs'), {
|
|
427
446
|
useDateObjects: this.config.useDateObjects,
|
|
428
|
-
}, this._log, (triples) =>
|
|
447
|
+
}, this._log, (triples) => {
|
|
448
|
+
return sts.createStore(this.ensureAttrs(), triples, this.config.enableCardinalityInference, this.config.useDateObjects);
|
|
449
|
+
}, () => this.ensureAttrs());
|
|
429
450
|
this._oauthCallbackResponse = this._oauthLoginInit();
|
|
430
451
|
// kick off a request to cache it
|
|
431
452
|
this.getCurrentUser();
|
|
@@ -455,6 +476,12 @@ export default class Reactor {
|
|
|
455
476
|
addEventListener('beforeunload', this._beforeUnload);
|
|
456
477
|
}
|
|
457
478
|
}
|
|
479
|
+
ensureAttrs() {
|
|
480
|
+
if (!this.attrs) {
|
|
481
|
+
throw new Error('attrs have not loaded.');
|
|
482
|
+
}
|
|
483
|
+
return this.attrs;
|
|
484
|
+
}
|
|
458
485
|
updateSchema(schema) {
|
|
459
486
|
this.config = Object.assign(Object.assign({}, this.config), { schema: schema, cardinalityInference: Boolean(schema) });
|
|
460
487
|
this._linkIndex = schema ? createLinkIndex(this.config.schema) : null;
|
|
@@ -478,7 +505,7 @@ export default class Reactor {
|
|
|
478
505
|
serialize: querySubToStorage,
|
|
479
506
|
parse: (_key, x) => querySubFromStorage(x, this.config.useDateObjects),
|
|
480
507
|
// objectSize
|
|
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; },
|
|
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; },
|
|
482
509
|
logger: this._log,
|
|
483
510
|
preloadEntryCount: 10,
|
|
484
511
|
gc: {
|
|
@@ -612,7 +639,7 @@ export default class Reactor {
|
|
|
612
639
|
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'];
|
|
613
640
|
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'];
|
|
614
641
|
const triples = extractTriples(result);
|
|
615
|
-
const store =
|
|
642
|
+
const store = sts.createStore(this.ensureAttrs(), triples, enableCardinalityInference, this.config.useDateObjects);
|
|
616
643
|
this.querySubs.updateInPlace((prev) => {
|
|
617
644
|
if (!prev[hash]) {
|
|
618
645
|
this._log.info('Missing value in querySubs', { hash, q });
|
|
@@ -620,6 +647,7 @@ export default class Reactor {
|
|
|
620
647
|
}
|
|
621
648
|
prev[hash].result = {
|
|
622
649
|
store,
|
|
650
|
+
attrsStore: this.ensureAttrs(),
|
|
623
651
|
pageInfo,
|
|
624
652
|
aggregate,
|
|
625
653
|
processedTxId: msg['processed-tx-id'],
|
|
@@ -654,7 +682,7 @@ export default class Reactor {
|
|
|
654
682
|
this._setAttrs(attrs);
|
|
655
683
|
}
|
|
656
684
|
this._cleanupPendingMutationsTimeout();
|
|
657
|
-
const rewrittenMutations = this._rewriteMutations(this.
|
|
685
|
+
const rewrittenMutations = this._rewriteMutations(this.ensureAttrs(), this._pendingMutations(), processedTxId);
|
|
658
686
|
if (rewrittenMutations !== this._pendingMutations()) {
|
|
659
687
|
// We know we've changed the mutations to fix the attr ids and removed
|
|
660
688
|
// processed attrs, so we'll persist those changes to prevent optimisticAttrs
|
|
@@ -670,8 +698,8 @@ export default class Reactor {
|
|
|
670
698
|
const result = x['instaql-result'];
|
|
671
699
|
const hash = weakHash(q);
|
|
672
700
|
const triples = extractTriples(result);
|
|
673
|
-
const store =
|
|
674
|
-
const newStore = this._applyOptimisticUpdates(store, mutations, processedTxId);
|
|
701
|
+
const store = sts.createStore(this.ensureAttrs(), triples, enableCardinalityInference, this.config.useDateObjects);
|
|
702
|
+
const newStore = this._applyOptimisticUpdates(store, this.ensureAttrs(), mutations, processedTxId);
|
|
675
703
|
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'];
|
|
676
704
|
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'];
|
|
677
705
|
return { q, hash, store: newStore, pageInfo, aggregate };
|
|
@@ -682,7 +710,13 @@ export default class Reactor {
|
|
|
682
710
|
this._log.error('Missing value in querySubs', { hash, q });
|
|
683
711
|
return;
|
|
684
712
|
}
|
|
685
|
-
prev[hash].result = {
|
|
713
|
+
prev[hash].result = {
|
|
714
|
+
store,
|
|
715
|
+
attrsStore: this.ensureAttrs(),
|
|
716
|
+
pageInfo,
|
|
717
|
+
aggregate,
|
|
718
|
+
processedTxId,
|
|
719
|
+
};
|
|
686
720
|
});
|
|
687
721
|
});
|
|
688
722
|
this._cleanupPendingMutationsQueries();
|
|
@@ -694,7 +728,7 @@ export default class Reactor {
|
|
|
694
728
|
case 'transact-ok': {
|
|
695
729
|
const { 'client-event-id': eventId, 'tx-id': txId } = msg;
|
|
696
730
|
this._inFlightMutationEventIds.delete(eventId);
|
|
697
|
-
const muts = this._rewriteMutations(this.
|
|
731
|
+
const muts = this._rewriteMutations(this.ensureAttrs(), this._pendingMutations());
|
|
698
732
|
const prevMutation = muts.get(eventId);
|
|
699
733
|
if (!prevMutation) {
|
|
700
734
|
break;
|
|
@@ -703,11 +737,18 @@ export default class Reactor {
|
|
|
703
737
|
this._updatePendingMutations((prev) => {
|
|
704
738
|
prev.set(eventId, Object.assign(Object.assign({}, prev.get(eventId)), { 'tx-id': txId, confirmed: Date.now() }));
|
|
705
739
|
});
|
|
706
|
-
const newAttrs =
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
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
|
+
}
|
|
711
752
|
this._finishTransaction('synced', eventId);
|
|
712
753
|
this._cleanupPendingMutationsTimeout();
|
|
713
754
|
break;
|
|
@@ -868,10 +909,10 @@ export default class Reactor {
|
|
|
868
909
|
this._completeQueryOnce(q, hash, r.dfd);
|
|
869
910
|
}
|
|
870
911
|
_setAttrs(attrs) {
|
|
871
|
-
this.attrs = attrs.reduce((acc, attr) => {
|
|
912
|
+
this.attrs = new sts.AttrsStore(attrs.reduce((acc, attr) => {
|
|
872
913
|
acc[attr.id] = attr;
|
|
873
914
|
return acc;
|
|
874
|
-
}, {});
|
|
915
|
+
}, {}), this._linkIndex);
|
|
875
916
|
this.notifyAttrsSubs();
|
|
876
917
|
}
|
|
877
918
|
_startQuerySub(q, hash) {
|
|
@@ -977,6 +1018,12 @@ export default class Reactor {
|
|
|
977
1018
|
// We remove `add-attr` commands for attrs that already exist.
|
|
978
1019
|
// We update `add-triple` and `retract-triple` commands to use the
|
|
979
1020
|
// server attr-ids.
|
|
1021
|
+
/**
|
|
1022
|
+
*
|
|
1023
|
+
* @param {sts.AttrsStore} attrs
|
|
1024
|
+
* @param {any} muts
|
|
1025
|
+
* @param {number} [processedTxId]
|
|
1026
|
+
*/
|
|
980
1027
|
_rewriteMutations(attrs, muts, processedTxId) {
|
|
981
1028
|
if (!attrs)
|
|
982
1029
|
return muts;
|
|
@@ -984,12 +1031,12 @@ export default class Reactor {
|
|
|
984
1031
|
return new Map();
|
|
985
1032
|
const findExistingAttr = (attr) => {
|
|
986
1033
|
const [_, etype, label] = attr['forward-identity'];
|
|
987
|
-
const existing =
|
|
1034
|
+
const existing = sts.getAttrByFwdIdentName(attrs, etype, label);
|
|
988
1035
|
return existing;
|
|
989
1036
|
};
|
|
990
1037
|
const findReverseAttr = (attr) => {
|
|
991
1038
|
const [_, etype, label] = attr['forward-identity'];
|
|
992
|
-
const revAttr =
|
|
1039
|
+
const revAttr = sts.getAttrByReverseIdentName(attrs, etype, label);
|
|
993
1040
|
return revAttr;
|
|
994
1041
|
};
|
|
995
1042
|
const mapping = { attrIdMap: {}, refSwapAttrIds: new Set() };
|
|
@@ -1052,8 +1099,11 @@ export default class Reactor {
|
|
|
1052
1099
|
}
|
|
1053
1100
|
// ---------------------------
|
|
1054
1101
|
// Transact
|
|
1102
|
+
/**
|
|
1103
|
+
* @returns {sts.AttrsStore}
|
|
1104
|
+
*/
|
|
1055
1105
|
optimisticAttrs() {
|
|
1056
|
-
var _a;
|
|
1106
|
+
var _a, _b;
|
|
1057
1107
|
const pendingMutationSteps = [...this._pendingMutations().values()] // hack due to Map()
|
|
1058
1108
|
.flatMap((x) => x['tx-steps']);
|
|
1059
1109
|
const deletedAttrIds = new Set(pendingMutationSteps
|
|
@@ -1066,17 +1116,22 @@ export default class Reactor {
|
|
|
1066
1116
|
}
|
|
1067
1117
|
else if (_action === 'update-attr' &&
|
|
1068
1118
|
attr.id &&
|
|
1069
|
-
((_a = this.attrs) === null || _a === void 0 ? void 0 : _a
|
|
1070
|
-
const fullAttr = Object.assign(Object.assign({}, this.attrs
|
|
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);
|
|
1071
1121
|
pendingAttrs.push(fullAttr);
|
|
1072
1122
|
}
|
|
1073
1123
|
}
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
const
|
|
1079
|
-
|
|
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);
|
|
1080
1135
|
}
|
|
1081
1136
|
/** Runs instaql on a query and a store */
|
|
1082
1137
|
dataForQuery(hash) {
|
|
@@ -1101,16 +1156,16 @@ export default class Reactor {
|
|
|
1101
1156
|
pendingMutationsVersion === cached.pendingMutationsVersion) {
|
|
1102
1157
|
return cached;
|
|
1103
1158
|
}
|
|
1104
|
-
const { store, pageInfo, aggregate, processedTxId } = result;
|
|
1105
|
-
const mutations = this._rewriteMutationsSorted(
|
|
1106
|
-
const newStore = this._applyOptimisticUpdates(store, mutations, processedTxId);
|
|
1107
|
-
const resp = instaql({ store: newStore, pageInfo, aggregate }, q);
|
|
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);
|
|
1108
1163
|
return { data: resp, querySubVersion, pendingMutationsVersion };
|
|
1109
1164
|
}
|
|
1110
|
-
_applyOptimisticUpdates(store, mutations, processedTxId) {
|
|
1165
|
+
_applyOptimisticUpdates(store, attrsStore, mutations, processedTxId) {
|
|
1111
1166
|
for (const [_, mut] of mutations) {
|
|
1112
1167
|
if (!mut['tx-id'] || (processedTxId && mut['tx-id'] > processedTxId)) {
|
|
1113
|
-
store =
|
|
1168
|
+
store = sts.transact(store, attrsStore, mut['tx-steps']);
|
|
1114
1169
|
}
|
|
1115
1170
|
}
|
|
1116
1171
|
return store;
|
|
@@ -1193,7 +1248,7 @@ export default class Reactor {
|
|
|
1193
1248
|
.forEach(({ eventId, q }) => {
|
|
1194
1249
|
this._trySendAuthed(eventId, { op: 'add-query', q });
|
|
1195
1250
|
});
|
|
1196
|
-
const muts = this._rewriteMutationsSorted(this.
|
|
1251
|
+
const muts = this._rewriteMutationsSorted(this.ensureAttrs(), this._pendingMutations());
|
|
1197
1252
|
muts.forEach(([eventId, mut]) => {
|
|
1198
1253
|
if (!mut['tx-id']) {
|
|
1199
1254
|
this._sendMutation(eventId, mut);
|
|
@@ -1480,7 +1535,7 @@ export default class Reactor {
|
|
|
1480
1535
|
subscribeAttrs(cb) {
|
|
1481
1536
|
this.attrsCbs.push(cb);
|
|
1482
1537
|
if (this.attrs) {
|
|
1483
|
-
cb(this.attrs);
|
|
1538
|
+
cb(this.attrs.attrs);
|
|
1484
1539
|
}
|
|
1485
1540
|
return () => {
|
|
1486
1541
|
this.attrsCbs = this.attrsCbs.filter((x) => x !== cb);
|