@instantdb/core 0.22.88 → 0.22.89-experimental.drewh-fix-export.20277749804.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/__tests__/src/Reactor.test.js +18 -11
- package/__tests__/src/{datalog.test.js → datalog.test.ts} +17 -5
- package/__tests__/src/{instaml.test.js → instaml.test.ts} +183 -119
- package/__tests__/src/instaql.bench.ts +34 -0
- package/__tests__/src/{instaql.test.js → instaql.test.ts} +342 -455
- package/__tests__/src/instaqlInference.test.js +13 -9
- package/__tests__/src/{store.test.js → store.test.ts} +215 -212
- package/dist/commonjs/Reactor.d.ts +23 -6
- package/dist/commonjs/Reactor.d.ts.map +1 -1
- package/dist/commonjs/Reactor.js +110 -45
- package/dist/commonjs/Reactor.js.map +1 -1
- package/dist/commonjs/SyncTable.d.ts +4 -1
- package/dist/commonjs/SyncTable.d.ts.map +1 -1
- package/dist/commonjs/SyncTable.js +35 -37
- package/dist/commonjs/SyncTable.js.map +1 -1
- package/dist/commonjs/instaml.d.ts +17 -4
- package/dist/commonjs/instaml.d.ts.map +1 -1
- package/dist/commonjs/instaml.js +115 -82
- package/dist/commonjs/instaml.js.map +1 -1
- package/dist/commonjs/instaql.d.ts +4 -3
- package/dist/commonjs/instaql.d.ts.map +1 -1
- package/dist/commonjs/instaql.js +65 -63
- package/dist/commonjs/instaql.js.map +1 -1
- package/dist/commonjs/reactorTypes.d.ts +29 -0
- package/dist/commonjs/reactorTypes.d.ts.map +1 -0
- package/dist/commonjs/reactorTypes.js +3 -0
- package/dist/commonjs/reactorTypes.js.map +1 -0
- package/dist/commonjs/store.d.ts +67 -25
- package/dist/commonjs/store.d.ts.map +1 -1
- package/dist/commonjs/store.js +177 -81
- package/dist/commonjs/store.js.map +1 -1
- package/dist/esm/Reactor.d.ts +23 -6
- package/dist/esm/Reactor.d.ts.map +1 -1
- package/dist/esm/Reactor.js +111 -46
- package/dist/esm/Reactor.js.map +1 -1
- package/dist/esm/SyncTable.d.ts +4 -1
- package/dist/esm/SyncTable.d.ts.map +1 -1
- package/dist/esm/SyncTable.js +35 -37
- package/dist/esm/SyncTable.js.map +1 -1
- package/dist/esm/instaml.d.ts +17 -4
- package/dist/esm/instaml.d.ts.map +1 -1
- package/dist/esm/instaml.js +112 -77
- package/dist/esm/instaml.js.map +1 -1
- package/dist/esm/instaql.d.ts +4 -3
- package/dist/esm/instaql.d.ts.map +1 -1
- package/dist/esm/instaql.js +65 -63
- package/dist/esm/instaql.js.map +1 -1
- package/dist/esm/reactorTypes.d.ts +29 -0
- package/dist/esm/reactorTypes.d.ts.map +1 -0
- package/dist/esm/reactorTypes.js +2 -0
- package/dist/esm/reactorTypes.js.map +1 -0
- package/dist/esm/store.d.ts +67 -25
- package/dist/esm/store.d.ts.map +1 -1
- package/dist/esm/store.js +174 -81
- package/dist/esm/store.js.map +1 -1
- package/dist/standalone/index.js +1605 -1415
- package/dist/standalone/index.umd.cjs +3 -3
- package/package.json +2 -2
- package/src/Reactor.js +152 -75
- package/src/SyncTable.ts +85 -45
- package/src/{instaml.js → instaml.ts} +201 -96
- package/src/instaql.ts +88 -62
- package/src/reactorTypes.ts +32 -0
- package/src/store.ts +257 -101
- package/__tests__/src/instaql.bench.js +0 -29
package/dist/esm/store.d.ts
CHANGED
|
@@ -2,47 +2,89 @@ import { InstantDBAttr } from './attrTypes.ts';
|
|
|
2
2
|
import { LinkIndex } from './utils/linkIndex.ts';
|
|
3
3
|
type Triple = [string, string, any, number];
|
|
4
4
|
type Attrs = Record<string, InstantDBAttr>;
|
|
5
|
-
type AttrIndexes = {
|
|
6
|
-
blobAttrs: Map<string, Map<string, InstantDBAttr>>;
|
|
7
|
-
primaryKeys: Map<string, InstantDBAttr>;
|
|
8
|
-
forwardIdents: Map<string, Map<string, InstantDBAttr>>;
|
|
9
|
-
revIdents: Map<string, Map<string, InstantDBAttr>>;
|
|
10
|
-
};
|
|
11
5
|
export type Store = {
|
|
12
6
|
eav: Map<string, Map<string, Map<any, Triple>>>;
|
|
13
7
|
aev: Map<string, Map<string, Map<any, Triple>>>;
|
|
14
8
|
vae: Map<any, Map<string, Map<string, Triple>>>;
|
|
15
|
-
useDateObjects: boolean | null;
|
|
16
|
-
|
|
17
|
-
attrIndexes: AttrIndexes;
|
|
18
|
-
cardinalityInference: boolean | null;
|
|
19
|
-
linkIndex: LinkIndex | null;
|
|
20
|
-
__type: 'store';
|
|
9
|
+
useDateObjects: boolean | null | undefined;
|
|
10
|
+
cardinalityInference: boolean | null | undefined;
|
|
21
11
|
};
|
|
22
|
-
|
|
12
|
+
type StoreJsonVersion0 = {
|
|
23
13
|
__type: 'store';
|
|
24
14
|
attrs: Attrs;
|
|
25
15
|
triples: Triple[];
|
|
26
|
-
cardinalityInference: boolean | null;
|
|
16
|
+
cardinalityInference: boolean | null | undefined;
|
|
17
|
+
linkIndex: LinkIndex | null;
|
|
18
|
+
useDateObjects: boolean | null | undefined;
|
|
19
|
+
};
|
|
20
|
+
type StoreJsonVersion1 = {
|
|
21
|
+
triples: Triple[];
|
|
22
|
+
cardinalityInference: boolean | null | undefined;
|
|
23
|
+
useDateObjects: boolean | null | undefined;
|
|
24
|
+
version: 1;
|
|
25
|
+
};
|
|
26
|
+
export type StoreJson = StoreJsonVersion0 | StoreJsonVersion1;
|
|
27
|
+
export type AttrsStoreJson = {
|
|
28
|
+
attrs: Attrs;
|
|
27
29
|
linkIndex: LinkIndex | null;
|
|
28
|
-
useDateObjects: boolean | null;
|
|
29
30
|
};
|
|
31
|
+
export interface AttrsStore {
|
|
32
|
+
attrs: Attrs;
|
|
33
|
+
linkIndex: LinkIndex | null;
|
|
34
|
+
resetAttrIndexes(): void;
|
|
35
|
+
addAttr(attr: InstantDBAttr): void;
|
|
36
|
+
deleteAttr(attrId: string): void;
|
|
37
|
+
updateAttr(partialAttr: Partial<InstantDBAttr> & {
|
|
38
|
+
id: string;
|
|
39
|
+
}): void;
|
|
40
|
+
getAttr(id: string): InstantDBAttr | undefined;
|
|
41
|
+
blobAttrs: Map<string, Map<string, InstantDBAttr>>;
|
|
42
|
+
primaryKeys: Map<string, InstantDBAttr>;
|
|
43
|
+
forwardIdents: Map<string, Map<string, InstantDBAttr>>;
|
|
44
|
+
revIdents: Map<string, Map<string, InstantDBAttr>>;
|
|
45
|
+
toJSON(): AttrsStoreJson;
|
|
46
|
+
}
|
|
47
|
+
export declare class AttrsStoreClass implements AttrsStore {
|
|
48
|
+
attrs: Attrs;
|
|
49
|
+
linkIndex: LinkIndex | null;
|
|
50
|
+
private _blobAttrs;
|
|
51
|
+
private _primaryKeys;
|
|
52
|
+
private _forwardIdents;
|
|
53
|
+
private _revIdents;
|
|
54
|
+
constructor(attrs: Attrs, linkIndex: LinkIndex | null);
|
|
55
|
+
resetAttrIndexes(): void;
|
|
56
|
+
addAttr(attr: InstantDBAttr): void;
|
|
57
|
+
deleteAttr(attrId: string): void;
|
|
58
|
+
updateAttr(partialAttr: Partial<InstantDBAttr> & {
|
|
59
|
+
id: string;
|
|
60
|
+
}): void;
|
|
61
|
+
getAttr(id: string): InstantDBAttr | undefined;
|
|
62
|
+
get blobAttrs(): Map<string, Map<string, InstantDBAttr>>;
|
|
63
|
+
get primaryKeys(): Map<string, InstantDBAttr>;
|
|
64
|
+
get forwardIdents(): Map<string, Map<string, InstantDBAttr>>;
|
|
65
|
+
get revIdents(): Map<string, Map<string, InstantDBAttr>>;
|
|
66
|
+
toJSON(): AttrsStoreJson;
|
|
67
|
+
}
|
|
30
68
|
export declare function isBlob(attr: InstantDBAttr): boolean;
|
|
31
69
|
export declare function getInMap(obj: any, path: any): any;
|
|
32
|
-
export declare function toJSON(store: Store):
|
|
33
|
-
export declare function fromJSON(storeJSON: StoreJson): Store;
|
|
70
|
+
export declare function toJSON(store: Store): StoreJsonVersion1;
|
|
71
|
+
export declare function fromJSON(attrsStore: AttrsStore, storeJSON: StoreJson): Store;
|
|
72
|
+
export declare function attrsStoreFromJSON(attrsStoreJSON: AttrsStoreJson | null, storeJSON: StoreJson | null): AttrsStore | undefined;
|
|
34
73
|
export declare function hasTriple(store: Store, [e, a, v]: [string, string, any]): boolean;
|
|
35
74
|
export declare function hasEntity(store: Store, e: string): boolean;
|
|
36
|
-
export declare function createStore(
|
|
37
|
-
export declare function retractTriple(store: Store, rawTriple: Triple): void;
|
|
38
|
-
export declare function addTriple(store: Store, rawTriple: Triple): void;
|
|
75
|
+
export declare function createStore(attrsStore: AttrsStore, triples: Triple[], enableCardinalityInference?: boolean | null, useDateObjects?: boolean | null): Store;
|
|
76
|
+
export declare function retractTriple(store: Store, attrsStore: AttrsStore, rawTriple: Triple): void;
|
|
77
|
+
export declare function addTriple(store: Store, attrsStore: AttrsStore, rawTriple: Triple): void;
|
|
39
78
|
export declare function allMapValues(m: any, level: any, res?: any[]): any[];
|
|
40
79
|
export declare function getTriples(store: any, [e, a, v]: [any, any, any]): any[];
|
|
41
80
|
export declare function getAsObject(store: Store, attrs: Map<string, InstantDBAttr> | undefined, e: string): {};
|
|
42
|
-
export declare function getAttrByFwdIdentName(
|
|
43
|
-
export declare function getAttrByReverseIdentName(
|
|
44
|
-
export declare function getBlobAttrs(
|
|
45
|
-
export declare function getPrimaryKeyAttr(
|
|
46
|
-
export declare function transact(store: Store, txSteps: any):
|
|
81
|
+
export declare function getAttrByFwdIdentName(attrsStore: AttrsStore, inputEtype: string, inputLabel: string): InstantDBAttr | undefined;
|
|
82
|
+
export declare function getAttrByReverseIdentName(attrsStore: AttrsStore, inputEtype: string, inputLabel: string): InstantDBAttr | undefined;
|
|
83
|
+
export declare function getBlobAttrs(attrsStore: AttrsStore, etype: string): Map<string, InstantDBAttr> | undefined;
|
|
84
|
+
export declare function getPrimaryKeyAttr(attrsStore: AttrsStore, etype: string): InstantDBAttr | undefined;
|
|
85
|
+
export declare function transact(store: Store, attrsStore: AttrsStore, txSteps: any): {
|
|
86
|
+
store: Store;
|
|
87
|
+
attrsStore: AttrsStore;
|
|
88
|
+
};
|
|
47
89
|
export {};
|
|
48
90
|
//# sourceMappingURL=store.d.ts.map
|
package/dist/esm/store.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/store.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD,KAAK,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;AAC5C,KAAK,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/store.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD,KAAK,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;AAC5C,KAAK,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;AAS3C,MAAM,MAAM,KAAK,GAAG;IAClB,GAAG,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;IAChD,GAAG,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;IAChD,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;IAChD,cAAc,EAAE,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC;IAC3C,oBAAoB,EAAE,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC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C,MAAM,EAAE,aAAa,CAAC,GAAG,SAAS,EAC7C,CAAC,EAAE,MAAM,MAiBV;AAED,wBAAgB,qBAAqB,CACnC,UAAU,EAAE,UAAU,EACtB,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,6BAGnB;AAED,wBAAgB,yBAAyB,CACvC,UAAU,EAAE,UAAU,EACtB,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,6BAGnB;AAED,wBAAgB,YAAY,CAAC,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,0CAEjE;AAED,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,6BAMtE;AAyBD,wBAAgB,QAAQ,CACtB,KAAK,EAAE,KAAK,EACZ,UAAU,EAAE,UAAU,EACtB,OAAO,KAAA,GACN;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,UAAU,EAAE,UAAU,CAAA;CAAE,CAsD1C"}
|
package/dist/esm/store.js
CHANGED
|
@@ -1,6 +1,95 @@
|
|
|
1
1
|
import { create } from 'mutative';
|
|
2
2
|
import { immutableDeepMerge } from './utils/object.js';
|
|
3
3
|
import { coerceToDate } from "./utils/dates.js";
|
|
4
|
+
export class AttrsStoreClass {
|
|
5
|
+
constructor(attrs, linkIndex) {
|
|
6
|
+
this._blobAttrs = null;
|
|
7
|
+
this._primaryKeys = null;
|
|
8
|
+
this._forwardIdents = null;
|
|
9
|
+
this._revIdents = null;
|
|
10
|
+
this.attrs = attrs;
|
|
11
|
+
this.linkIndex = linkIndex;
|
|
12
|
+
}
|
|
13
|
+
resetAttrIndexes() {
|
|
14
|
+
this._blobAttrs = null;
|
|
15
|
+
this._primaryKeys = null;
|
|
16
|
+
this._forwardIdents = null;
|
|
17
|
+
this._revIdents = null;
|
|
18
|
+
}
|
|
19
|
+
addAttr(attr) {
|
|
20
|
+
this.attrs[attr.id] = attr;
|
|
21
|
+
this.resetAttrIndexes();
|
|
22
|
+
}
|
|
23
|
+
deleteAttr(attrId) {
|
|
24
|
+
delete this.attrs[attrId];
|
|
25
|
+
this.resetAttrIndexes();
|
|
26
|
+
}
|
|
27
|
+
updateAttr(partialAttr) {
|
|
28
|
+
const attr = this.attrs[partialAttr.id];
|
|
29
|
+
if (!attr)
|
|
30
|
+
return;
|
|
31
|
+
this.attrs[partialAttr.id] = Object.assign(Object.assign({}, attr), partialAttr);
|
|
32
|
+
this.resetAttrIndexes();
|
|
33
|
+
}
|
|
34
|
+
getAttr(id) {
|
|
35
|
+
return this.attrs[id];
|
|
36
|
+
}
|
|
37
|
+
get blobAttrs() {
|
|
38
|
+
if (this._blobAttrs) {
|
|
39
|
+
return this._blobAttrs;
|
|
40
|
+
}
|
|
41
|
+
this._blobAttrs = new Map();
|
|
42
|
+
for (const attr of Object.values(this.attrs)) {
|
|
43
|
+
if (isBlob(attr)) {
|
|
44
|
+
const [_, fwdEtype, fwdLabel] = attr['forward-identity'];
|
|
45
|
+
setInMap(this.blobAttrs, [fwdEtype, fwdLabel], attr);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return this._blobAttrs;
|
|
49
|
+
}
|
|
50
|
+
get primaryKeys() {
|
|
51
|
+
if (this._primaryKeys) {
|
|
52
|
+
return this._primaryKeys;
|
|
53
|
+
}
|
|
54
|
+
this._primaryKeys = new Map();
|
|
55
|
+
for (const attr of Object.values(this.attrs)) {
|
|
56
|
+
if (attr['primary?']) {
|
|
57
|
+
const [_, fwdEtype] = attr['forward-identity'];
|
|
58
|
+
setInMap(this._primaryKeys, [fwdEtype], attr);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return this._primaryKeys;
|
|
62
|
+
}
|
|
63
|
+
get forwardIdents() {
|
|
64
|
+
if (this._forwardIdents) {
|
|
65
|
+
return this._forwardIdents;
|
|
66
|
+
}
|
|
67
|
+
this._forwardIdents = new Map();
|
|
68
|
+
for (const attr of Object.values(this.attrs)) {
|
|
69
|
+
const fwdIdent = attr['forward-identity'];
|
|
70
|
+
const [_, fwdEtype, fwdLabel] = fwdIdent;
|
|
71
|
+
setInMap(this._forwardIdents, [fwdEtype, fwdLabel], attr);
|
|
72
|
+
}
|
|
73
|
+
return this._forwardIdents;
|
|
74
|
+
}
|
|
75
|
+
get revIdents() {
|
|
76
|
+
if (this._revIdents) {
|
|
77
|
+
return this._revIdents;
|
|
78
|
+
}
|
|
79
|
+
this._revIdents = new Map();
|
|
80
|
+
for (const attr of Object.values(this.attrs)) {
|
|
81
|
+
const revIdent = attr['reverse-identity'];
|
|
82
|
+
if (revIdent) {
|
|
83
|
+
const [_, revEtype, revLabel] = revIdent;
|
|
84
|
+
setInMap(this._revIdents, [revEtype, revLabel], attr);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return this._revIdents;
|
|
88
|
+
}
|
|
89
|
+
toJSON() {
|
|
90
|
+
return { attrs: this.attrs, linkIndex: this.linkIndex };
|
|
91
|
+
}
|
|
92
|
+
}
|
|
4
93
|
function hasEA(attr) {
|
|
5
94
|
return attr['cardinality'] === 'one';
|
|
6
95
|
}
|
|
@@ -29,32 +118,33 @@ function deleteInMap(m, path) {
|
|
|
29
118
|
deleteInMap(m.get(head), tail);
|
|
30
119
|
}
|
|
31
120
|
function setInMap(m, path, value) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
121
|
+
let current = m;
|
|
122
|
+
const lastI = path.length - 1;
|
|
123
|
+
for (let i = 0; i < lastI; i++) {
|
|
124
|
+
const part = path[i];
|
|
125
|
+
let nextMap = current.get(part);
|
|
126
|
+
if (nextMap === undefined) {
|
|
127
|
+
nextMap = new Map();
|
|
128
|
+
current.set(part, nextMap);
|
|
129
|
+
}
|
|
130
|
+
current = nextMap;
|
|
37
131
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (!nextM) {
|
|
41
|
-
nextM = new Map();
|
|
42
|
-
m.set(head, nextM);
|
|
132
|
+
if (lastI > -1) {
|
|
133
|
+
current.set(path[lastI], value);
|
|
43
134
|
}
|
|
44
|
-
setInMap(nextM, tail, value);
|
|
45
135
|
}
|
|
46
136
|
function isDateAttr(attr) {
|
|
47
137
|
return attr['checked-data-type'] === 'date';
|
|
48
138
|
}
|
|
49
|
-
function createTripleIndexes(
|
|
139
|
+
function createTripleIndexes(attrsStore, triples, useDateObjects) {
|
|
50
140
|
const eav = new Map();
|
|
51
141
|
const aev = new Map();
|
|
52
142
|
const vae = new Map();
|
|
53
143
|
for (const triple of triples) {
|
|
54
|
-
let [eid, aid, v
|
|
55
|
-
const attr = getAttr(
|
|
144
|
+
let [eid, aid, v] = triple;
|
|
145
|
+
const attr = attrsStore.getAttr(aid);
|
|
56
146
|
if (!attr) {
|
|
57
|
-
console.warn('no such attr',
|
|
147
|
+
console.warn('no such attr', aid, eid);
|
|
58
148
|
continue;
|
|
59
149
|
}
|
|
60
150
|
if (attr['checked-data-type'] === 'date' && useDateObjects) {
|
|
@@ -94,16 +184,22 @@ function createAttrIndexes(attrs) {
|
|
|
94
184
|
}
|
|
95
185
|
export function toJSON(store) {
|
|
96
186
|
return {
|
|
97
|
-
__type: store.__type,
|
|
98
|
-
attrs: store.attrs,
|
|
99
187
|
triples: allMapValues(store.eav, 3),
|
|
100
188
|
cardinalityInference: store.cardinalityInference,
|
|
101
|
-
linkIndex: store.linkIndex,
|
|
102
189
|
useDateObjects: store.useDateObjects,
|
|
190
|
+
version: 1,
|
|
103
191
|
};
|
|
104
192
|
}
|
|
105
|
-
export function fromJSON(storeJSON) {
|
|
106
|
-
return createStore(
|
|
193
|
+
export function fromJSON(attrsStore, storeJSON) {
|
|
194
|
+
return createStore(attrsStore, storeJSON.triples, storeJSON.cardinalityInference, storeJSON.useDateObjects);
|
|
195
|
+
}
|
|
196
|
+
export function attrsStoreFromJSON(attrsStoreJSON, storeJSON) {
|
|
197
|
+
if (attrsStoreJSON) {
|
|
198
|
+
return new AttrsStoreClass(attrsStoreJSON.attrs, attrsStoreJSON.linkIndex);
|
|
199
|
+
}
|
|
200
|
+
if (storeJSON && '__type' in storeJSON) {
|
|
201
|
+
return new AttrsStoreClass(storeJSON.attrs, storeJSON.linkIndex);
|
|
202
|
+
}
|
|
107
203
|
}
|
|
108
204
|
export function hasTriple(store, [e, a, v]) {
|
|
109
205
|
return getInMap(store.eav, [e, a, v]) !== undefined;
|
|
@@ -111,17 +207,10 @@ export function hasTriple(store, [e, a, v]) {
|
|
|
111
207
|
export function hasEntity(store, e) {
|
|
112
208
|
return getInMap(store.eav, [e]) !== undefined;
|
|
113
209
|
}
|
|
114
|
-
function
|
|
115
|
-
store
|
|
116
|
-
}
|
|
117
|
-
export function createStore(attrs, triples, enableCardinalityInference, linkIndex, useDateObjects) {
|
|
118
|
-
const store = createTripleIndexes(attrs, triples, useDateObjects);
|
|
119
|
-
store.useDateObjects = useDateObjects;
|
|
120
|
-
store.attrs = attrs;
|
|
121
|
-
store.attrIndexes = createAttrIndexes(attrs);
|
|
210
|
+
export function createStore(attrsStore, triples, enableCardinalityInference, useDateObjects) {
|
|
211
|
+
const store = createTripleIndexes(attrsStore, triples, useDateObjects);
|
|
122
212
|
store.cardinalityInference = enableCardinalityInference;
|
|
123
|
-
store.
|
|
124
|
-
store.__type = 'store';
|
|
213
|
+
store.useDateObjects = useDateObjects;
|
|
125
214
|
return store;
|
|
126
215
|
}
|
|
127
216
|
// We may have local triples with lookup refs in them,
|
|
@@ -178,13 +267,13 @@ function resolveLookupRefs(store, triple) {
|
|
|
178
267
|
return [eid, ...rest];
|
|
179
268
|
}
|
|
180
269
|
}
|
|
181
|
-
export function retractTriple(store, rawTriple) {
|
|
270
|
+
export function retractTriple(store, attrsStore, rawTriple) {
|
|
182
271
|
const triple = resolveLookupRefs(store, rawTriple);
|
|
183
272
|
if (!triple) {
|
|
184
273
|
return;
|
|
185
274
|
}
|
|
186
275
|
const [eid, aid, v] = triple;
|
|
187
|
-
const attr = getAttr(
|
|
276
|
+
const attr = attrsStore.getAttr(aid);
|
|
188
277
|
if (!attr) {
|
|
189
278
|
return;
|
|
190
279
|
}
|
|
@@ -225,14 +314,14 @@ function getCreatedAt(store, attr, triple) {
|
|
|
225
314
|
*/
|
|
226
315
|
return createdAt || Date.now() * 10 + _seed++;
|
|
227
316
|
}
|
|
228
|
-
export function addTriple(store, rawTriple) {
|
|
317
|
+
export function addTriple(store, attrsStore, rawTriple) {
|
|
229
318
|
var _a;
|
|
230
319
|
const triple = resolveLookupRefs(store, rawTriple);
|
|
231
320
|
if (!triple) {
|
|
232
321
|
return;
|
|
233
322
|
}
|
|
234
323
|
let [eid, aid, v] = triple;
|
|
235
|
-
const attr = getAttr(
|
|
324
|
+
const attr = attrsStore.getAttr(aid);
|
|
236
325
|
if (!attr) {
|
|
237
326
|
// (XXX): Due to the way we're handling attrs, it's
|
|
238
327
|
// possible to enter a state where we receive a triple without an attr.
|
|
@@ -261,14 +350,14 @@ export function addTriple(store, rawTriple) {
|
|
|
261
350
|
setInMap(store.vae, [v, aid, eid], enhancedTriple);
|
|
262
351
|
}
|
|
263
352
|
}
|
|
264
|
-
function mergeTriple(store, rawTriple) {
|
|
353
|
+
function mergeTriple(store, attrsStore, rawTriple) {
|
|
265
354
|
var _a;
|
|
266
355
|
const triple = resolveLookupRefs(store, rawTriple);
|
|
267
356
|
if (!triple) {
|
|
268
357
|
return;
|
|
269
358
|
}
|
|
270
359
|
const [eid, aid, update] = triple;
|
|
271
|
-
const attr = getAttr(
|
|
360
|
+
const attr = attrsStore.getAttr(aid);
|
|
272
361
|
if (!attr)
|
|
273
362
|
return;
|
|
274
363
|
if (!isBlob(attr))
|
|
@@ -288,8 +377,9 @@ function mergeTriple(store, rawTriple) {
|
|
|
288
377
|
getCreatedAt(store, attr, currentTriple),
|
|
289
378
|
];
|
|
290
379
|
setInMap(store.eav, [eid, aid], new Map([[updatedValue, enhancedTriple]]));
|
|
380
|
+
setInMap(store.aev, [aid, eid], new Map([[updatedValue, enhancedTriple]]));
|
|
291
381
|
}
|
|
292
|
-
function deleteEntity(store, args) {
|
|
382
|
+
function deleteEntity(store, attrsStore, args) {
|
|
293
383
|
var _a, _b;
|
|
294
384
|
const [lookup, etype] = args;
|
|
295
385
|
const triple = resolveLookupRefs(store, [lookup]);
|
|
@@ -301,10 +391,10 @@ function deleteEntity(store, args) {
|
|
|
301
391
|
const eMap = store.eav.get(id);
|
|
302
392
|
if (eMap) {
|
|
303
393
|
for (const a of eMap.keys()) {
|
|
304
|
-
const attr =
|
|
394
|
+
const attr = attrsStore.getAttr(a);
|
|
305
395
|
// delete cascade refs
|
|
306
396
|
if (attr && attr['on-delete-reverse'] === 'cascade') {
|
|
307
|
-
allMapValues(eMap.get(a), 1).forEach(([e, a, v]) => { var _a; return deleteEntity(store, [v, (_a = attr['reverse-identity']) === null || _a === void 0 ? void 0 : _a[1]]); });
|
|
397
|
+
allMapValues(eMap.get(a), 1).forEach(([e, a, v]) => { var _a; return deleteEntity(store, attrsStore, [v, (_a = attr['reverse-identity']) === null || _a === void 0 ? void 0 : _a[1]]); });
|
|
308
398
|
}
|
|
309
399
|
if (
|
|
310
400
|
// Fall back to deleting everything if we've rehydrated tx-steps from
|
|
@@ -329,7 +419,7 @@ function deleteEntity(store, args) {
|
|
|
329
419
|
vaeTriples.forEach((triple) => {
|
|
330
420
|
var _a, _b, _c;
|
|
331
421
|
const [e, a, v] = triple;
|
|
332
|
-
const attr =
|
|
422
|
+
const attr = attrsStore.getAttr(a);
|
|
333
423
|
if (!etype || !attr || ((_a = attr['reverse-identity']) === null || _a === void 0 ? void 0 : _a[1]) === etype) {
|
|
334
424
|
deleteInMap(store.eav, [e, a, v]);
|
|
335
425
|
deleteInMap(store.aev, [a, e, v]);
|
|
@@ -338,7 +428,7 @@ function deleteEntity(store, args) {
|
|
|
338
428
|
if (attr &&
|
|
339
429
|
attr['on-delete'] === 'cascade' &&
|
|
340
430
|
((_b = attr['reverse-identity']) === null || _b === void 0 ? void 0 : _b[1]) === etype) {
|
|
341
|
-
deleteEntity(store, [e, (_c = attr['forward-identity']) === null || _c === void 0 ? void 0 : _c[1]]);
|
|
431
|
+
deleteEntity(store, attrsStore, [e, (_c = attr['forward-identity']) === null || _c === void 0 ? void 0 : _c[1]]);
|
|
342
432
|
}
|
|
343
433
|
});
|
|
344
434
|
}
|
|
@@ -354,58 +444,55 @@ function deleteEntity(store, args) {
|
|
|
354
444
|
// * We could batch this reset at the end
|
|
355
445
|
// * We could add an ave index for all triples, so removing the
|
|
356
446
|
// right triples is easy and fast.
|
|
357
|
-
function resetIndexMap(store, newTriples) {
|
|
358
|
-
const newIndexMap = createTripleIndexes(
|
|
447
|
+
function resetIndexMap(store, attrsStore, newTriples) {
|
|
448
|
+
const newIndexMap = createTripleIndexes(attrsStore, newTriples, store.useDateObjects);
|
|
359
449
|
Object.keys(newIndexMap).forEach((key) => {
|
|
360
450
|
store[key] = newIndexMap[key];
|
|
361
451
|
});
|
|
362
452
|
}
|
|
363
|
-
function addAttr(
|
|
364
|
-
|
|
365
|
-
resetAttrIndexes(store);
|
|
453
|
+
function addAttr(attrsStore, [attr]) {
|
|
454
|
+
attrsStore.addAttr(attr);
|
|
366
455
|
}
|
|
367
456
|
function getAllTriples(store) {
|
|
368
457
|
return allMapValues(store.eav, 3);
|
|
369
458
|
}
|
|
370
|
-
function deleteAttr(store, [id]) {
|
|
371
|
-
if (!
|
|
459
|
+
function deleteAttr(store, attrsStore, [id]) {
|
|
460
|
+
if (!attrsStore.getAttr(id))
|
|
372
461
|
return;
|
|
373
462
|
const newTriples = getAllTriples(store).filter(([_, aid]) => aid !== id);
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
resetIndexMap(store, newTriples);
|
|
463
|
+
attrsStore.deleteAttr(id);
|
|
464
|
+
resetIndexMap(store, attrsStore, newTriples);
|
|
377
465
|
}
|
|
378
|
-
function updateAttr(store, [partialAttr]) {
|
|
379
|
-
const attr =
|
|
466
|
+
function updateAttr(store, attrsStore, [partialAttr]) {
|
|
467
|
+
const attr = attrsStore.getAttr(partialAttr.id);
|
|
380
468
|
if (!attr)
|
|
381
469
|
return;
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
resetIndexMap(store, getAllTriples(store));
|
|
470
|
+
attrsStore.updateAttr(partialAttr);
|
|
471
|
+
resetIndexMap(store, attrsStore, getAllTriples(store));
|
|
385
472
|
}
|
|
386
|
-
function applyTxStep(store, txStep) {
|
|
473
|
+
function applyTxStep(store, attrsStore, txStep) {
|
|
387
474
|
const [action, ...args] = txStep;
|
|
388
475
|
switch (action) {
|
|
389
476
|
case 'add-triple':
|
|
390
|
-
addTriple(store, args);
|
|
477
|
+
addTriple(store, attrsStore, args);
|
|
391
478
|
break;
|
|
392
479
|
case 'deep-merge-triple':
|
|
393
|
-
mergeTriple(store, args);
|
|
480
|
+
mergeTriple(store, attrsStore, args);
|
|
394
481
|
break;
|
|
395
482
|
case 'retract-triple':
|
|
396
|
-
retractTriple(store, args);
|
|
483
|
+
retractTriple(store, attrsStore, args);
|
|
397
484
|
break;
|
|
398
485
|
case 'delete-entity':
|
|
399
|
-
deleteEntity(store, args);
|
|
486
|
+
deleteEntity(store, attrsStore, args);
|
|
400
487
|
break;
|
|
401
488
|
case 'add-attr':
|
|
402
|
-
addAttr(
|
|
489
|
+
addAttr(attrsStore, args);
|
|
403
490
|
break;
|
|
404
491
|
case 'delete-attr':
|
|
405
|
-
deleteAttr(store, args);
|
|
492
|
+
deleteAttr(store, attrsStore, args);
|
|
406
493
|
break;
|
|
407
494
|
case 'update-attr':
|
|
408
|
-
updateAttr(store, args);
|
|
495
|
+
updateAttr(store, attrsStore, args);
|
|
409
496
|
break;
|
|
410
497
|
case 'restore-attr':
|
|
411
498
|
break;
|
|
@@ -568,32 +655,32 @@ export function getAsObject(store, attrs, e) {
|
|
|
568
655
|
}
|
|
569
656
|
return obj;
|
|
570
657
|
}
|
|
571
|
-
export function getAttrByFwdIdentName(
|
|
658
|
+
export function getAttrByFwdIdentName(attrsStore, inputEtype, inputLabel) {
|
|
572
659
|
var _a;
|
|
573
|
-
return (_a =
|
|
660
|
+
return (_a = attrsStore.forwardIdents.get(inputEtype)) === null || _a === void 0 ? void 0 : _a.get(inputLabel);
|
|
574
661
|
}
|
|
575
|
-
export function getAttrByReverseIdentName(
|
|
662
|
+
export function getAttrByReverseIdentName(attrsStore, inputEtype, inputLabel) {
|
|
576
663
|
var _a;
|
|
577
|
-
return (_a =
|
|
664
|
+
return (_a = attrsStore.revIdents.get(inputEtype)) === null || _a === void 0 ? void 0 : _a.get(inputLabel);
|
|
578
665
|
}
|
|
579
|
-
export function getBlobAttrs(
|
|
580
|
-
return
|
|
666
|
+
export function getBlobAttrs(attrsStore, etype) {
|
|
667
|
+
return attrsStore.blobAttrs.get(etype);
|
|
581
668
|
}
|
|
582
|
-
export function getPrimaryKeyAttr(
|
|
669
|
+
export function getPrimaryKeyAttr(attrsStore, etype) {
|
|
583
670
|
var _a;
|
|
584
|
-
const fromPrimary =
|
|
671
|
+
const fromPrimary = attrsStore.primaryKeys.get(etype);
|
|
585
672
|
if (fromPrimary) {
|
|
586
673
|
return fromPrimary;
|
|
587
674
|
}
|
|
588
|
-
return (_a =
|
|
675
|
+
return (_a = attrsStore.forwardIdents.get(etype)) === null || _a === void 0 ? void 0 : _a.get('id');
|
|
589
676
|
}
|
|
590
|
-
function findTriple(store, rawTriple) {
|
|
677
|
+
function findTriple(store, attrsStore, rawTriple) {
|
|
591
678
|
const triple = resolveLookupRefs(store, rawTriple);
|
|
592
679
|
if (!triple) {
|
|
593
680
|
return;
|
|
594
681
|
}
|
|
595
682
|
const [eid, aid, v] = triple;
|
|
596
|
-
const attr = getAttr(
|
|
683
|
+
const attr = attrsStore.getAttr(aid);
|
|
597
684
|
if (!attr) {
|
|
598
685
|
// (XXX): Due to the way we're handling attrs, it's
|
|
599
686
|
// possible to enter a state where we receive a triple without an attr.
|
|
@@ -603,7 +690,7 @@ function findTriple(store, rawTriple) {
|
|
|
603
690
|
}
|
|
604
691
|
return getInMap(store.eav, [eid, aid]);
|
|
605
692
|
}
|
|
606
|
-
export function transact(store, txSteps) {
|
|
693
|
+
export function transact(store, attrsStore, txSteps) {
|
|
607
694
|
const txStepsFiltered = txSteps.filter(([action, eid, attrId, value, opts]) => {
|
|
608
695
|
if (action !== 'add-triple' && action !== 'deep-merge-triple') {
|
|
609
696
|
return true;
|
|
@@ -613,10 +700,10 @@ export function transact(store, txSteps) {
|
|
|
613
700
|
return true;
|
|
614
701
|
}
|
|
615
702
|
let exists = false;
|
|
616
|
-
const attr = getAttr(
|
|
703
|
+
const attr = attrsStore.getAttr(attrId);
|
|
617
704
|
if (attr) {
|
|
618
|
-
const idAttr = getPrimaryKeyAttr(
|
|
619
|
-
exists = !!findTriple(store, [
|
|
705
|
+
const idAttr = getPrimaryKeyAttr(attrsStore, attr['forward-identity'][1]);
|
|
706
|
+
exists = !!findTriple(store, attrsStore, [
|
|
620
707
|
eid,
|
|
621
708
|
idAttr === null || idAttr === void 0 ? void 0 : idAttr.id,
|
|
622
709
|
eid,
|
|
@@ -630,10 +717,16 @@ export function transact(store, txSteps) {
|
|
|
630
717
|
}
|
|
631
718
|
return true;
|
|
632
719
|
});
|
|
633
|
-
return create(store, (draft) => {
|
|
720
|
+
return create({ store, attrsStore }, (draft) => {
|
|
634
721
|
txStepsFiltered.forEach((txStep) => {
|
|
635
|
-
applyTxStep(draft, txStep);
|
|
722
|
+
applyTxStep(draft.store, draft.attrsStore, txStep);
|
|
636
723
|
});
|
|
724
|
+
}, {
|
|
725
|
+
mark: (target) => {
|
|
726
|
+
if (target instanceof AttrsStoreClass) {
|
|
727
|
+
return 'immutable';
|
|
728
|
+
}
|
|
729
|
+
},
|
|
637
730
|
});
|
|
638
731
|
}
|
|
639
732
|
//# sourceMappingURL=store.js.map
|