@instantdb/core 0.22.86-experimental.separate-attrs.20122276424.1 → 0.22.86-experimental.split-store.20183617880.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/__tests__/src/Reactor.test.js +18 -11
- package/__tests__/src/{datalog.test.js → datalog.test.ts} +17 -5
- package/__tests__/src/{instaml.test.js → instaml.test.ts} +183 -119
- package/__tests__/src/instaql.bench.ts +34 -0
- package/__tests__/src/{instaql.test.js → instaql.test.ts} +342 -455
- package/__tests__/src/instaqlInference.test.js +13 -9
- package/__tests__/src/{store.test.js → store.test.ts} +188 -210
- package/dist/commonjs/Reactor.d.ts +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 +105 -76
- 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 +170 -70
- 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 +102 -71
- 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 +167 -70
- package/dist/esm/store.js.map +1 -1
- package/dist/standalone/index.js +1580 -1392
- package/dist/standalone/index.umd.cjs +3 -3
- package/package.json +2 -2
- package/src/Reactor.js +154 -77
- package/src/SyncTable.ts +85 -45
- package/src/{instaml.js → instaml.ts} +196 -95
- package/src/instaql.ts +88 -62
- package/src/reactorTypes.ts +32 -0
- package/src/store.ts +248 -90
- 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,G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AE,GAAG,CAAC,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,101 @@
|
|
|
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
|
+
// XXX: Might be better to create all of the indexes at once as soon as someone
|
|
38
|
+
// requests one index
|
|
39
|
+
get blobAttrs() {
|
|
40
|
+
if (this._blobAttrs) {
|
|
41
|
+
return this._blobAttrs;
|
|
42
|
+
}
|
|
43
|
+
console.log('blobAttrs');
|
|
44
|
+
this._blobAttrs = new Map();
|
|
45
|
+
for (const attr of Object.values(this.attrs)) {
|
|
46
|
+
if (isBlob(attr)) {
|
|
47
|
+
const [_, fwdEtype, fwdLabel] = attr['forward-identity'];
|
|
48
|
+
setInMap(this.blobAttrs, [fwdEtype, fwdLabel], attr);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return this._blobAttrs;
|
|
52
|
+
}
|
|
53
|
+
get primaryKeys() {
|
|
54
|
+
if (this._primaryKeys) {
|
|
55
|
+
return this._primaryKeys;
|
|
56
|
+
}
|
|
57
|
+
console.log('primayKeys');
|
|
58
|
+
this._primaryKeys = new Map();
|
|
59
|
+
for (const attr of Object.values(this.attrs)) {
|
|
60
|
+
if (attr['primary?']) {
|
|
61
|
+
const [_, fwdEtype] = attr['forward-identity'];
|
|
62
|
+
setInMap(this._primaryKeys, [fwdEtype], attr);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return this._primaryKeys;
|
|
66
|
+
}
|
|
67
|
+
get forwardIdents() {
|
|
68
|
+
if (this._forwardIdents) {
|
|
69
|
+
return this._forwardIdents;
|
|
70
|
+
}
|
|
71
|
+
console.log('fwdIdents');
|
|
72
|
+
this._forwardIdents = new Map();
|
|
73
|
+
for (const attr of Object.values(this.attrs)) {
|
|
74
|
+
const fwdIdent = attr['forward-identity'];
|
|
75
|
+
const [_, fwdEtype, fwdLabel] = fwdIdent;
|
|
76
|
+
setInMap(this._forwardIdents, [fwdEtype, fwdLabel], attr);
|
|
77
|
+
}
|
|
78
|
+
return this._forwardIdents;
|
|
79
|
+
}
|
|
80
|
+
get revIdents() {
|
|
81
|
+
if (this._revIdents) {
|
|
82
|
+
return this._revIdents;
|
|
83
|
+
}
|
|
84
|
+
console.log('revIdents');
|
|
85
|
+
this._revIdents = new Map();
|
|
86
|
+
for (const attr of Object.values(this.attrs)) {
|
|
87
|
+
const revIdent = attr['reverse-identity'];
|
|
88
|
+
if (revIdent) {
|
|
89
|
+
const [_, revEtype, revLabel] = revIdent;
|
|
90
|
+
setInMap(this._revIdents, [revEtype, revLabel], attr);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return this._revIdents;
|
|
94
|
+
}
|
|
95
|
+
toJSON() {
|
|
96
|
+
return { attrs: this.attrs, linkIndex: this.linkIndex };
|
|
97
|
+
}
|
|
98
|
+
}
|
|
4
99
|
function hasEA(attr) {
|
|
5
100
|
return attr['cardinality'] === 'one';
|
|
6
101
|
}
|
|
@@ -46,15 +141,15 @@ function setInMap(m, path, value) {
|
|
|
46
141
|
function isDateAttr(attr) {
|
|
47
142
|
return attr['checked-data-type'] === 'date';
|
|
48
143
|
}
|
|
49
|
-
function createTripleIndexes(
|
|
144
|
+
function createTripleIndexes(attrsStore, triples, useDateObjects) {
|
|
50
145
|
const eav = new Map();
|
|
51
146
|
const aev = new Map();
|
|
52
147
|
const vae = new Map();
|
|
53
148
|
for (const triple of triples) {
|
|
54
|
-
let [eid, aid, v
|
|
55
|
-
const attr = getAttr(
|
|
149
|
+
let [eid, aid, v] = triple;
|
|
150
|
+
const attr = attrsStore.getAttr(aid);
|
|
56
151
|
if (!attr) {
|
|
57
|
-
console.warn('no such attr',
|
|
152
|
+
console.warn('no such attr', aid, eid);
|
|
58
153
|
continue;
|
|
59
154
|
}
|
|
60
155
|
if (attr['checked-data-type'] === 'date' && useDateObjects) {
|
|
@@ -94,16 +189,22 @@ function createAttrIndexes(attrs) {
|
|
|
94
189
|
}
|
|
95
190
|
export function toJSON(store) {
|
|
96
191
|
return {
|
|
97
|
-
__type: store.__type,
|
|
98
|
-
attrs: store.attrs,
|
|
99
192
|
triples: allMapValues(store.eav, 3),
|
|
100
193
|
cardinalityInference: store.cardinalityInference,
|
|
101
|
-
linkIndex: store.linkIndex,
|
|
102
194
|
useDateObjects: store.useDateObjects,
|
|
195
|
+
version: 1,
|
|
103
196
|
};
|
|
104
197
|
}
|
|
105
|
-
export function fromJSON(storeJSON) {
|
|
106
|
-
return createStore(
|
|
198
|
+
export function fromJSON(attrsStore, storeJSON) {
|
|
199
|
+
return createStore(attrsStore, storeJSON.triples, storeJSON.cardinalityInference, storeJSON.useDateObjects);
|
|
200
|
+
}
|
|
201
|
+
export function attrsStoreFromJSON(attrsStoreJSON, storeJSON) {
|
|
202
|
+
if (attrsStoreJSON) {
|
|
203
|
+
return new AttrsStoreClass(attrsStoreJSON.attrs, attrsStoreJSON.linkIndex);
|
|
204
|
+
}
|
|
205
|
+
if (storeJSON && '__type' in storeJSON) {
|
|
206
|
+
return new AttrsStoreClass(storeJSON.attrs, storeJSON.linkIndex);
|
|
207
|
+
}
|
|
107
208
|
}
|
|
108
209
|
export function hasTriple(store, [e, a, v]) {
|
|
109
210
|
return getInMap(store.eav, [e, a, v]) !== undefined;
|
|
@@ -111,17 +212,10 @@ export function hasTriple(store, [e, a, v]) {
|
|
|
111
212
|
export function hasEntity(store, e) {
|
|
112
213
|
return getInMap(store.eav, [e]) !== undefined;
|
|
113
214
|
}
|
|
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);
|
|
215
|
+
export function createStore(attrsStore, triples, enableCardinalityInference, useDateObjects) {
|
|
216
|
+
const store = createTripleIndexes(attrsStore, triples, useDateObjects);
|
|
122
217
|
store.cardinalityInference = enableCardinalityInference;
|
|
123
|
-
store.
|
|
124
|
-
store.__type = 'store';
|
|
218
|
+
store.useDateObjects = useDateObjects;
|
|
125
219
|
return store;
|
|
126
220
|
}
|
|
127
221
|
// We may have local triples with lookup refs in them,
|
|
@@ -178,13 +272,13 @@ function resolveLookupRefs(store, triple) {
|
|
|
178
272
|
return [eid, ...rest];
|
|
179
273
|
}
|
|
180
274
|
}
|
|
181
|
-
export function retractTriple(store, rawTriple) {
|
|
275
|
+
export function retractTriple(store, attrsStore, rawTriple) {
|
|
182
276
|
const triple = resolveLookupRefs(store, rawTriple);
|
|
183
277
|
if (!triple) {
|
|
184
278
|
return;
|
|
185
279
|
}
|
|
186
280
|
const [eid, aid, v] = triple;
|
|
187
|
-
const attr = getAttr(
|
|
281
|
+
const attr = attrsStore.getAttr(aid);
|
|
188
282
|
if (!attr) {
|
|
189
283
|
return;
|
|
190
284
|
}
|
|
@@ -225,14 +319,14 @@ function getCreatedAt(store, attr, triple) {
|
|
|
225
319
|
*/
|
|
226
320
|
return createdAt || Date.now() * 10 + _seed++;
|
|
227
321
|
}
|
|
228
|
-
export function addTriple(store, rawTriple) {
|
|
322
|
+
export function addTriple(store, attrsStore, rawTriple) {
|
|
229
323
|
var _a;
|
|
230
324
|
const triple = resolveLookupRefs(store, rawTriple);
|
|
231
325
|
if (!triple) {
|
|
232
326
|
return;
|
|
233
327
|
}
|
|
234
328
|
let [eid, aid, v] = triple;
|
|
235
|
-
const attr = getAttr(
|
|
329
|
+
const attr = attrsStore.getAttr(aid);
|
|
236
330
|
if (!attr) {
|
|
237
331
|
// (XXX): Due to the way we're handling attrs, it's
|
|
238
332
|
// possible to enter a state where we receive a triple without an attr.
|
|
@@ -261,14 +355,14 @@ export function addTriple(store, rawTriple) {
|
|
|
261
355
|
setInMap(store.vae, [v, aid, eid], enhancedTriple);
|
|
262
356
|
}
|
|
263
357
|
}
|
|
264
|
-
function mergeTriple(store, rawTriple) {
|
|
358
|
+
function mergeTriple(store, attrsStore, rawTriple) {
|
|
265
359
|
var _a;
|
|
266
360
|
const triple = resolveLookupRefs(store, rawTriple);
|
|
267
361
|
if (!triple) {
|
|
268
362
|
return;
|
|
269
363
|
}
|
|
270
364
|
const [eid, aid, update] = triple;
|
|
271
|
-
const attr = getAttr(
|
|
365
|
+
const attr = attrsStore.getAttr(aid);
|
|
272
366
|
if (!attr)
|
|
273
367
|
return;
|
|
274
368
|
if (!isBlob(attr))
|
|
@@ -289,7 +383,7 @@ function mergeTriple(store, rawTriple) {
|
|
|
289
383
|
];
|
|
290
384
|
setInMap(store.eav, [eid, aid], new Map([[updatedValue, enhancedTriple]]));
|
|
291
385
|
}
|
|
292
|
-
function deleteEntity(store, args) {
|
|
386
|
+
function deleteEntity(store, attrsStore, args) {
|
|
293
387
|
var _a, _b;
|
|
294
388
|
const [lookup, etype] = args;
|
|
295
389
|
const triple = resolveLookupRefs(store, [lookup]);
|
|
@@ -301,10 +395,10 @@ function deleteEntity(store, args) {
|
|
|
301
395
|
const eMap = store.eav.get(id);
|
|
302
396
|
if (eMap) {
|
|
303
397
|
for (const a of eMap.keys()) {
|
|
304
|
-
const attr =
|
|
398
|
+
const attr = attrsStore.getAttr(a);
|
|
305
399
|
// delete cascade refs
|
|
306
400
|
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]]); });
|
|
401
|
+
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
402
|
}
|
|
309
403
|
if (
|
|
310
404
|
// Fall back to deleting everything if we've rehydrated tx-steps from
|
|
@@ -329,7 +423,7 @@ function deleteEntity(store, args) {
|
|
|
329
423
|
vaeTriples.forEach((triple) => {
|
|
330
424
|
var _a, _b, _c;
|
|
331
425
|
const [e, a, v] = triple;
|
|
332
|
-
const attr =
|
|
426
|
+
const attr = attrsStore.getAttr(a);
|
|
333
427
|
if (!etype || !attr || ((_a = attr['reverse-identity']) === null || _a === void 0 ? void 0 : _a[1]) === etype) {
|
|
334
428
|
deleteInMap(store.eav, [e, a, v]);
|
|
335
429
|
deleteInMap(store.aev, [a, e, v]);
|
|
@@ -338,7 +432,7 @@ function deleteEntity(store, args) {
|
|
|
338
432
|
if (attr &&
|
|
339
433
|
attr['on-delete'] === 'cascade' &&
|
|
340
434
|
((_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]]);
|
|
435
|
+
deleteEntity(store, attrsStore, [e, (_c = attr['forward-identity']) === null || _c === void 0 ? void 0 : _c[1]]);
|
|
342
436
|
}
|
|
343
437
|
});
|
|
344
438
|
}
|
|
@@ -354,58 +448,55 @@ function deleteEntity(store, args) {
|
|
|
354
448
|
// * We could batch this reset at the end
|
|
355
449
|
// * We could add an ave index for all triples, so removing the
|
|
356
450
|
// right triples is easy and fast.
|
|
357
|
-
function resetIndexMap(store, newTriples) {
|
|
358
|
-
const newIndexMap = createTripleIndexes(
|
|
451
|
+
function resetIndexMap(store, attrsStore, newTriples) {
|
|
452
|
+
const newIndexMap = createTripleIndexes(attrsStore, newTriples, store.useDateObjects);
|
|
359
453
|
Object.keys(newIndexMap).forEach((key) => {
|
|
360
454
|
store[key] = newIndexMap[key];
|
|
361
455
|
});
|
|
362
456
|
}
|
|
363
|
-
function addAttr(
|
|
364
|
-
|
|
365
|
-
resetAttrIndexes(store);
|
|
457
|
+
function addAttr(attrsStore, [attr]) {
|
|
458
|
+
attrsStore.addAttr(attr);
|
|
366
459
|
}
|
|
367
460
|
function getAllTriples(store) {
|
|
368
461
|
return allMapValues(store.eav, 3);
|
|
369
462
|
}
|
|
370
|
-
function deleteAttr(store, [id]) {
|
|
371
|
-
if (!
|
|
463
|
+
function deleteAttr(store, attrsStore, [id]) {
|
|
464
|
+
if (!attrsStore.getAttr(id))
|
|
372
465
|
return;
|
|
373
466
|
const newTriples = getAllTriples(store).filter(([_, aid]) => aid !== id);
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
resetIndexMap(store, newTriples);
|
|
467
|
+
attrsStore.deleteAttr(id);
|
|
468
|
+
resetIndexMap(store, attrsStore, newTriples);
|
|
377
469
|
}
|
|
378
|
-
function updateAttr(store, [partialAttr]) {
|
|
379
|
-
const attr =
|
|
470
|
+
function updateAttr(store, attrsStore, [partialAttr]) {
|
|
471
|
+
const attr = attrsStore.getAttr(partialAttr.id);
|
|
380
472
|
if (!attr)
|
|
381
473
|
return;
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
resetIndexMap(store, getAllTriples(store));
|
|
474
|
+
attrsStore.updateAttr(partialAttr);
|
|
475
|
+
resetIndexMap(store, attrsStore, getAllTriples(store));
|
|
385
476
|
}
|
|
386
|
-
function applyTxStep(store, txStep) {
|
|
477
|
+
function applyTxStep(store, attrsStore, txStep) {
|
|
387
478
|
const [action, ...args] = txStep;
|
|
388
479
|
switch (action) {
|
|
389
480
|
case 'add-triple':
|
|
390
|
-
addTriple(store, args);
|
|
481
|
+
addTriple(store, attrsStore, args);
|
|
391
482
|
break;
|
|
392
483
|
case 'deep-merge-triple':
|
|
393
|
-
mergeTriple(store, args);
|
|
484
|
+
mergeTriple(store, attrsStore, args);
|
|
394
485
|
break;
|
|
395
486
|
case 'retract-triple':
|
|
396
|
-
retractTriple(store, args);
|
|
487
|
+
retractTriple(store, attrsStore, args);
|
|
397
488
|
break;
|
|
398
489
|
case 'delete-entity':
|
|
399
|
-
deleteEntity(store, args);
|
|
490
|
+
deleteEntity(store, attrsStore, args);
|
|
400
491
|
break;
|
|
401
492
|
case 'add-attr':
|
|
402
|
-
addAttr(
|
|
493
|
+
addAttr(attrsStore, args);
|
|
403
494
|
break;
|
|
404
495
|
case 'delete-attr':
|
|
405
|
-
deleteAttr(store, args);
|
|
496
|
+
deleteAttr(store, attrsStore, args);
|
|
406
497
|
break;
|
|
407
498
|
case 'update-attr':
|
|
408
|
-
updateAttr(store, args);
|
|
499
|
+
updateAttr(store, attrsStore, args);
|
|
409
500
|
break;
|
|
410
501
|
case 'restore-attr':
|
|
411
502
|
break;
|
|
@@ -568,32 +659,32 @@ export function getAsObject(store, attrs, e) {
|
|
|
568
659
|
}
|
|
569
660
|
return obj;
|
|
570
661
|
}
|
|
571
|
-
export function getAttrByFwdIdentName(
|
|
662
|
+
export function getAttrByFwdIdentName(attrsStore, inputEtype, inputLabel) {
|
|
572
663
|
var _a;
|
|
573
|
-
return (_a =
|
|
664
|
+
return (_a = attrsStore.forwardIdents.get(inputEtype)) === null || _a === void 0 ? void 0 : _a.get(inputLabel);
|
|
574
665
|
}
|
|
575
|
-
export function getAttrByReverseIdentName(
|
|
666
|
+
export function getAttrByReverseIdentName(attrsStore, inputEtype, inputLabel) {
|
|
576
667
|
var _a;
|
|
577
|
-
return (_a =
|
|
668
|
+
return (_a = attrsStore.revIdents.get(inputEtype)) === null || _a === void 0 ? void 0 : _a.get(inputLabel);
|
|
578
669
|
}
|
|
579
|
-
export function getBlobAttrs(
|
|
580
|
-
return
|
|
670
|
+
export function getBlobAttrs(attrsStore, etype) {
|
|
671
|
+
return attrsStore.blobAttrs.get(etype);
|
|
581
672
|
}
|
|
582
|
-
export function getPrimaryKeyAttr(
|
|
673
|
+
export function getPrimaryKeyAttr(attrsStore, etype) {
|
|
583
674
|
var _a;
|
|
584
|
-
const fromPrimary =
|
|
675
|
+
const fromPrimary = attrsStore.primaryKeys.get(etype);
|
|
585
676
|
if (fromPrimary) {
|
|
586
677
|
return fromPrimary;
|
|
587
678
|
}
|
|
588
|
-
return (_a =
|
|
679
|
+
return (_a = attrsStore.forwardIdents.get(etype)) === null || _a === void 0 ? void 0 : _a.get('id');
|
|
589
680
|
}
|
|
590
|
-
function findTriple(store, rawTriple) {
|
|
681
|
+
function findTriple(store, attrsStore, rawTriple) {
|
|
591
682
|
const triple = resolveLookupRefs(store, rawTriple);
|
|
592
683
|
if (!triple) {
|
|
593
684
|
return;
|
|
594
685
|
}
|
|
595
686
|
const [eid, aid, v] = triple;
|
|
596
|
-
const attr = getAttr(
|
|
687
|
+
const attr = attrsStore.getAttr(aid);
|
|
597
688
|
if (!attr) {
|
|
598
689
|
// (XXX): Due to the way we're handling attrs, it's
|
|
599
690
|
// possible to enter a state where we receive a triple without an attr.
|
|
@@ -603,7 +694,7 @@ function findTriple(store, rawTriple) {
|
|
|
603
694
|
}
|
|
604
695
|
return getInMap(store.eav, [eid, aid]);
|
|
605
696
|
}
|
|
606
|
-
export function transact(store, txSteps) {
|
|
697
|
+
export function transact(store, attrsStore, txSteps) {
|
|
607
698
|
const txStepsFiltered = txSteps.filter(([action, eid, attrId, value, opts]) => {
|
|
608
699
|
if (action !== 'add-triple' && action !== 'deep-merge-triple') {
|
|
609
700
|
return true;
|
|
@@ -613,10 +704,10 @@ export function transact(store, txSteps) {
|
|
|
613
704
|
return true;
|
|
614
705
|
}
|
|
615
706
|
let exists = false;
|
|
616
|
-
const attr = getAttr(
|
|
707
|
+
const attr = attrsStore.getAttr(attrId);
|
|
617
708
|
if (attr) {
|
|
618
|
-
const idAttr = getPrimaryKeyAttr(
|
|
619
|
-
exists = !!findTriple(store, [
|
|
709
|
+
const idAttr = getPrimaryKeyAttr(attrsStore, attr['forward-identity'][1]);
|
|
710
|
+
exists = !!findTriple(store, attrsStore, [
|
|
620
711
|
eid,
|
|
621
712
|
idAttr === null || idAttr === void 0 ? void 0 : idAttr.id,
|
|
622
713
|
eid,
|
|
@@ -630,10 +721,16 @@ export function transact(store, txSteps) {
|
|
|
630
721
|
}
|
|
631
722
|
return true;
|
|
632
723
|
});
|
|
633
|
-
return create(store, (draft) => {
|
|
724
|
+
return create({ store, attrsStore }, (draft) => {
|
|
634
725
|
txStepsFiltered.forEach((txStep) => {
|
|
635
|
-
applyTxStep(draft, txStep);
|
|
726
|
+
applyTxStep(draft.store, draft.attrsStore, txStep);
|
|
636
727
|
});
|
|
728
|
+
}, {
|
|
729
|
+
mark: (target) => {
|
|
730
|
+
if (target instanceof AttrsStoreClass) {
|
|
731
|
+
return 'immutable';
|
|
732
|
+
}
|
|
733
|
+
},
|
|
637
734
|
});
|
|
638
735
|
}
|
|
639
736
|
//# sourceMappingURL=store.js.map
|