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