@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/src/store.ts
CHANGED
|
@@ -7,22 +7,26 @@ import { LinkIndex } from './utils/linkIndex.ts';
|
|
|
7
7
|
type Triple = [string, string, any, number];
|
|
8
8
|
type Attrs = Record<string, InstantDBAttr>;
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
type AttrIndexes = {
|
|
11
11
|
blobAttrs: Map<string, Map<string, InstantDBAttr>>;
|
|
12
12
|
primaryKeys: Map<string, InstantDBAttr>;
|
|
13
13
|
forwardIdents: Map<string, Map<string, InstantDBAttr>>;
|
|
14
14
|
revIdents: Map<string, Map<string, InstantDBAttr>>;
|
|
15
|
-
}
|
|
15
|
+
};
|
|
16
16
|
|
|
17
17
|
export type Store = {
|
|
18
18
|
eav: Map<string, Map<string, Map<any, Triple>>>;
|
|
19
19
|
aev: Map<string, Map<string, Map<any, Triple>>>;
|
|
20
20
|
vae: Map<any, Map<string, Map<string, Triple>>>;
|
|
21
21
|
useDateObjects: boolean | null;
|
|
22
|
+
attrs: Attrs;
|
|
23
|
+
attrIndexes: AttrIndexes;
|
|
22
24
|
cardinalityInference: boolean | null;
|
|
25
|
+
linkIndex: LinkIndex | null;
|
|
26
|
+
__type: 'store';
|
|
23
27
|
};
|
|
24
28
|
|
|
25
|
-
type
|
|
29
|
+
export type StoreJson = {
|
|
26
30
|
__type: 'store';
|
|
27
31
|
attrs: Attrs;
|
|
28
32
|
triples: Triple[];
|
|
@@ -31,131 +35,6 @@ type StoreJsonVersion0 = {
|
|
|
31
35
|
useDateObjects: boolean | null;
|
|
32
36
|
};
|
|
33
37
|
|
|
34
|
-
type StoreJsonVersion1 = {
|
|
35
|
-
triples: Triple[];
|
|
36
|
-
cardinalityInference: boolean | null;
|
|
37
|
-
useDateObjects: boolean | null;
|
|
38
|
-
version: 1;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export type StoreJson = StoreJsonVersion0 | StoreJsonVersion1;
|
|
42
|
-
|
|
43
|
-
export type AttrsStoreJson = {
|
|
44
|
-
attrs: Attrs;
|
|
45
|
-
linkIndex: LinkIndex | null;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
export class AttrsStore {
|
|
49
|
-
public attrs: Attrs;
|
|
50
|
-
public linkIndex: LinkIndex | null;
|
|
51
|
-
private _blobAttrs: Map<string, Map<string, InstantDBAttr>> | null = null;
|
|
52
|
-
private _primaryKeys: Map<string, InstantDBAttr> | null = null;
|
|
53
|
-
private _forwardIdents: Map<string, Map<string, InstantDBAttr>> | null = null;
|
|
54
|
-
private _revIdents: Map<string, Map<string, InstantDBAttr>> | null = null;
|
|
55
|
-
constructor(attrs: Attrs, linkIndex: LinkIndex | null) {
|
|
56
|
-
console.log('attrs init', new Error('trace'));
|
|
57
|
-
this.attrs = attrs;
|
|
58
|
-
this.linkIndex = linkIndex;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
public resetAttrIndexes() {
|
|
62
|
-
this._blobAttrs = null;
|
|
63
|
-
this._primaryKeys = null;
|
|
64
|
-
this._forwardIdents = null;
|
|
65
|
-
this._revIdents = null;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
public addAttr(attr: InstantDBAttr) {
|
|
69
|
-
this.attrs[attr.id] = attr;
|
|
70
|
-
this.resetAttrIndexes();
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
public deleteAttr(attrId: string) {
|
|
74
|
-
delete this.attrs[attrId];
|
|
75
|
-
this.resetAttrIndexes();
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
public updateAttr(partialAttr: Partial<InstantDBAttr> & { id: string }) {
|
|
79
|
-
const attr = this.attrs[partialAttr.id];
|
|
80
|
-
if (!attr) return;
|
|
81
|
-
this.attrs[partialAttr.id] = { ...attr, ...partialAttr };
|
|
82
|
-
this.resetAttrIndexes();
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
public getAttr(id: string): InstantDBAttr | undefined {
|
|
86
|
-
return this.attrs[id];
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// XXX: Might be better to create all of the indexes at once as soon as someone
|
|
90
|
-
// requests one index
|
|
91
|
-
get blobAttrs(): Map<string, Map<string, InstantDBAttr>> {
|
|
92
|
-
if (this._blobAttrs) {
|
|
93
|
-
return this._blobAttrs;
|
|
94
|
-
}
|
|
95
|
-
console.log('blobAttrs');
|
|
96
|
-
this._blobAttrs = new Map();
|
|
97
|
-
for (const attr of Object.values(this.attrs)) {
|
|
98
|
-
if (isBlob(attr)) {
|
|
99
|
-
const [_, fwdEtype, fwdLabel] = attr['forward-identity'];
|
|
100
|
-
setInMap(this.blobAttrs, [fwdEtype, fwdLabel], attr);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
return this._blobAttrs;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
get primaryKeys(): Map<string, InstantDBAttr> {
|
|
107
|
-
if (this._primaryKeys) {
|
|
108
|
-
return this._primaryKeys;
|
|
109
|
-
}
|
|
110
|
-
console.log('primayKeys');
|
|
111
|
-
this._primaryKeys = new Map();
|
|
112
|
-
|
|
113
|
-
for (const attr of Object.values(this.attrs)) {
|
|
114
|
-
if (attr['primary?']) {
|
|
115
|
-
const [_, fwdEtype] = attr['forward-identity'];
|
|
116
|
-
setInMap(this._primaryKeys, [fwdEtype], attr);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
return this._primaryKeys;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
get forwardIdents(): Map<string, Map<string, InstantDBAttr>> {
|
|
123
|
-
if (this._forwardIdents) {
|
|
124
|
-
return this._forwardIdents;
|
|
125
|
-
}
|
|
126
|
-
console.log('fwdIdents');
|
|
127
|
-
this._forwardIdents = new Map();
|
|
128
|
-
|
|
129
|
-
for (const attr of Object.values(this.attrs)) {
|
|
130
|
-
const fwdIdent = attr['forward-identity'];
|
|
131
|
-
const [_, fwdEtype, fwdLabel] = fwdIdent;
|
|
132
|
-
setInMap(this._forwardIdents, [fwdEtype, fwdLabel], attr);
|
|
133
|
-
}
|
|
134
|
-
return this._forwardIdents;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
get revIdents(): Map<string, Map<string, InstantDBAttr>> {
|
|
138
|
-
if (this._revIdents) {
|
|
139
|
-
return this._revIdents;
|
|
140
|
-
}
|
|
141
|
-
console.log('revIdents');
|
|
142
|
-
this._revIdents = new Map();
|
|
143
|
-
|
|
144
|
-
for (const attr of Object.values(this.attrs)) {
|
|
145
|
-
const revIdent = attr['reverse-identity'];
|
|
146
|
-
if (revIdent) {
|
|
147
|
-
const [_, revEtype, revLabel] = revIdent;
|
|
148
|
-
setInMap(this._revIdents, [revEtype, revLabel], attr);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
return this._revIdents;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
public toJSON(): AttrsStoreJson {
|
|
155
|
-
return { attrs: this.attrs, linkIndex: this.linkIndex };
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
38
|
function hasEA(attr: InstantDBAttr) {
|
|
160
39
|
return attr['cardinality'] === 'one';
|
|
161
40
|
}
|
|
@@ -207,7 +86,7 @@ function isDateAttr(attr: InstantDBAttr) {
|
|
|
207
86
|
}
|
|
208
87
|
|
|
209
88
|
function createTripleIndexes(
|
|
210
|
-
|
|
89
|
+
attrs: Record<string, InstantDBAttr>,
|
|
211
90
|
triples: Triple[],
|
|
212
91
|
useDateObjects: boolean | null,
|
|
213
92
|
): Pick<Store, 'eav' | 'aev' | 'vae'> {
|
|
@@ -215,10 +94,10 @@ function createTripleIndexes(
|
|
|
215
94
|
const aev = new Map();
|
|
216
95
|
const vae = new Map();
|
|
217
96
|
for (const triple of triples) {
|
|
218
|
-
let [eid, aid, v] = triple;
|
|
219
|
-
const attr =
|
|
97
|
+
let [eid, aid, v, t] = triple;
|
|
98
|
+
const attr = getAttr(attrs, aid);
|
|
220
99
|
if (!attr) {
|
|
221
|
-
console.warn('no such attr',
|
|
100
|
+
console.warn('no such attr', eid, attrs);
|
|
222
101
|
continue;
|
|
223
102
|
}
|
|
224
103
|
|
|
@@ -263,36 +142,27 @@ function createAttrIndexes(attrs: Record<string, InstantDBAttr>): AttrIndexes {
|
|
|
263
142
|
return { blobAttrs, primaryKeys, forwardIdents, revIdents };
|
|
264
143
|
}
|
|
265
144
|
|
|
266
|
-
export function toJSON(store: Store):
|
|
145
|
+
export function toJSON(store: Store): StoreJson {
|
|
267
146
|
return {
|
|
147
|
+
__type: store.__type,
|
|
148
|
+
attrs: store.attrs,
|
|
268
149
|
triples: allMapValues(store.eav, 3),
|
|
269
150
|
cardinalityInference: store.cardinalityInference,
|
|
151
|
+
linkIndex: store.linkIndex,
|
|
270
152
|
useDateObjects: store.useDateObjects,
|
|
271
|
-
version: 1,
|
|
272
153
|
};
|
|
273
154
|
}
|
|
274
155
|
|
|
275
|
-
export function fromJSON(
|
|
156
|
+
export function fromJSON(storeJSON: StoreJson): Store {
|
|
276
157
|
return createStore(
|
|
277
|
-
|
|
158
|
+
storeJSON.attrs,
|
|
278
159
|
storeJSON.triples,
|
|
279
160
|
storeJSON.cardinalityInference,
|
|
161
|
+
storeJSON.linkIndex,
|
|
280
162
|
storeJSON.useDateObjects,
|
|
281
163
|
);
|
|
282
164
|
}
|
|
283
165
|
|
|
284
|
-
export function attrsStoreFromJSON(
|
|
285
|
-
attrsStoreJSON: AttrsStoreJson | null,
|
|
286
|
-
storeJSON: StoreJson | null,
|
|
287
|
-
): AttrsStore | undefined {
|
|
288
|
-
if (attrsStoreJSON) {
|
|
289
|
-
return new AttrsStore(attrsStoreJSON.attrs, attrsStoreJSON.linkIndex);
|
|
290
|
-
}
|
|
291
|
-
if (storeJSON && '__type' in storeJSON) {
|
|
292
|
-
return new AttrsStore(storeJSON.attrs, storeJSON.linkIndex);
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
|
|
296
166
|
export function hasTriple(store: Store, [e, a, v]: [string, string, any]) {
|
|
297
167
|
return getInMap(store.eav, [e, a, v]) !== undefined;
|
|
298
168
|
}
|
|
@@ -301,19 +171,29 @@ export function hasEntity(store: Store, e: string) {
|
|
|
301
171
|
return getInMap(store.eav, [e]) !== undefined;
|
|
302
172
|
}
|
|
303
173
|
|
|
174
|
+
function resetAttrIndexes(store: Store) {
|
|
175
|
+
store.attrIndexes = createAttrIndexes(store.attrs);
|
|
176
|
+
}
|
|
177
|
+
|
|
304
178
|
export function createStore(
|
|
305
|
-
|
|
179
|
+
attrs: Record<string, InstantDBAttr>,
|
|
306
180
|
triples: Triple[],
|
|
307
181
|
enableCardinalityInference: boolean | null,
|
|
182
|
+
linkIndex: LinkIndex | null,
|
|
308
183
|
useDateObjects: boolean | null,
|
|
309
184
|
): Store {
|
|
310
185
|
const store = createTripleIndexes(
|
|
311
|
-
|
|
186
|
+
attrs,
|
|
312
187
|
triples,
|
|
313
188
|
useDateObjects,
|
|
314
189
|
) as unknown as Store;
|
|
315
|
-
store.cardinalityInference = enableCardinalityInference;
|
|
316
190
|
store.useDateObjects = useDateObjects;
|
|
191
|
+
store.attrs = attrs;
|
|
192
|
+
store.attrIndexes = createAttrIndexes(attrs);
|
|
193
|
+
store.cardinalityInference = enableCardinalityInference;
|
|
194
|
+
store.linkIndex = linkIndex;
|
|
195
|
+
store.__type = 'store';
|
|
196
|
+
|
|
317
197
|
return store;
|
|
318
198
|
}
|
|
319
199
|
|
|
@@ -374,17 +254,13 @@ function resolveLookupRefs(store: Store, triple: Triple): Triple | null {
|
|
|
374
254
|
}
|
|
375
255
|
}
|
|
376
256
|
|
|
377
|
-
export function retractTriple(
|
|
378
|
-
store: Store,
|
|
379
|
-
attrsStore: AttrsStore,
|
|
380
|
-
rawTriple: Triple,
|
|
381
|
-
): void {
|
|
257
|
+
export function retractTriple(store: Store, rawTriple: Triple): void {
|
|
382
258
|
const triple = resolveLookupRefs(store, rawTriple);
|
|
383
259
|
if (!triple) {
|
|
384
260
|
return;
|
|
385
261
|
}
|
|
386
262
|
const [eid, aid, v] = triple;
|
|
387
|
-
const attr =
|
|
263
|
+
const attr = getAttr(store.attrs, aid);
|
|
388
264
|
if (!attr) {
|
|
389
265
|
return;
|
|
390
266
|
}
|
|
@@ -434,17 +310,13 @@ function getCreatedAt(
|
|
|
434
310
|
return createdAt || Date.now() * 10 + _seed++;
|
|
435
311
|
}
|
|
436
312
|
|
|
437
|
-
export function addTriple(
|
|
438
|
-
store: Store,
|
|
439
|
-
attrsStore: AttrsStore,
|
|
440
|
-
rawTriple: Triple,
|
|
441
|
-
) {
|
|
313
|
+
export function addTriple(store: Store, rawTriple: Triple) {
|
|
442
314
|
const triple = resolveLookupRefs(store, rawTriple);
|
|
443
315
|
if (!triple) {
|
|
444
316
|
return;
|
|
445
317
|
}
|
|
446
318
|
let [eid, aid, v] = triple;
|
|
447
|
-
const attr =
|
|
319
|
+
const attr = getAttr(store.attrs, aid);
|
|
448
320
|
if (!attr) {
|
|
449
321
|
// (XXX): Due to the way we're handling attrs, it's
|
|
450
322
|
// possible to enter a state where we receive a triple without an attr.
|
|
@@ -477,14 +349,14 @@ export function addTriple(
|
|
|
477
349
|
}
|
|
478
350
|
}
|
|
479
351
|
|
|
480
|
-
function mergeTriple(store: Store,
|
|
352
|
+
function mergeTriple(store: Store, rawTriple: Triple) {
|
|
481
353
|
const triple = resolveLookupRefs(store, rawTriple);
|
|
482
354
|
if (!triple) {
|
|
483
355
|
return;
|
|
484
356
|
}
|
|
485
357
|
|
|
486
358
|
const [eid, aid, update] = triple;
|
|
487
|
-
const attr =
|
|
359
|
+
const attr = getAttr(store.attrs, aid);
|
|
488
360
|
|
|
489
361
|
if (!attr) return;
|
|
490
362
|
|
|
@@ -510,7 +382,7 @@ function mergeTriple(store: Store, attrsStore: AttrsStore, rawTriple: Triple) {
|
|
|
510
382
|
setInMap(store.eav, [eid, aid], new Map([[updatedValue, enhancedTriple]]));
|
|
511
383
|
}
|
|
512
384
|
|
|
513
|
-
function deleteEntity(store: Store,
|
|
385
|
+
function deleteEntity(store: Store, args: any[]) {
|
|
514
386
|
const [lookup, etype] = args;
|
|
515
387
|
const triple = resolveLookupRefs(store, [lookup] as unknown as Triple);
|
|
516
388
|
|
|
@@ -523,13 +395,13 @@ function deleteEntity(store: Store, attrsStore: AttrsStore, args: any[]) {
|
|
|
523
395
|
const eMap = store.eav.get(id);
|
|
524
396
|
if (eMap) {
|
|
525
397
|
for (const a of eMap.keys()) {
|
|
526
|
-
const attr =
|
|
398
|
+
const attr = store.attrs[a];
|
|
527
399
|
|
|
528
400
|
// delete cascade refs
|
|
529
401
|
if (attr && attr['on-delete-reverse'] === 'cascade') {
|
|
530
402
|
allMapValues(eMap.get(a), 1).forEach(
|
|
531
403
|
([e, a, v]: [string, string, any]) =>
|
|
532
|
-
deleteEntity(store,
|
|
404
|
+
deleteEntity(store, [v, attr['reverse-identity']?.[1]]),
|
|
533
405
|
);
|
|
534
406
|
}
|
|
535
407
|
|
|
@@ -558,7 +430,7 @@ function deleteEntity(store: Store, attrsStore: AttrsStore, args: any[]) {
|
|
|
558
430
|
if (vaeTriples) {
|
|
559
431
|
vaeTriples.forEach((triple: Triple) => {
|
|
560
432
|
const [e, a, v] = triple;
|
|
561
|
-
const attr =
|
|
433
|
+
const attr = store.attrs[a];
|
|
562
434
|
if (!etype || !attr || attr['reverse-identity']?.[1] === etype) {
|
|
563
435
|
deleteInMap(store.eav, [e, a, v]);
|
|
564
436
|
deleteInMap(store.aev, [a, e, v]);
|
|
@@ -569,7 +441,7 @@ function deleteEntity(store: Store, attrsStore: AttrsStore, args: any[]) {
|
|
|
569
441
|
attr['on-delete'] === 'cascade' &&
|
|
570
442
|
attr['reverse-identity']?.[1] === etype
|
|
571
443
|
) {
|
|
572
|
-
deleteEntity(store,
|
|
444
|
+
deleteEntity(store, [e, attr['forward-identity']?.[1]]);
|
|
573
445
|
}
|
|
574
446
|
});
|
|
575
447
|
}
|
|
@@ -586,9 +458,9 @@ function deleteEntity(store: Store, attrsStore: AttrsStore, args: any[]) {
|
|
|
586
458
|
// * We could batch this reset at the end
|
|
587
459
|
// * We could add an ave index for all triples, so removing the
|
|
588
460
|
// right triples is easy and fast.
|
|
589
|
-
function resetIndexMap(store: Store,
|
|
461
|
+
function resetIndexMap(store: Store, newTriples: Triple[]) {
|
|
590
462
|
const newIndexMap = createTripleIndexes(
|
|
591
|
-
|
|
463
|
+
store.attrs,
|
|
592
464
|
newTriples,
|
|
593
465
|
store.useDateObjects,
|
|
594
466
|
);
|
|
@@ -597,55 +469,57 @@ function resetIndexMap(store: Store, attrsStore, newTriples: Triple[]) {
|
|
|
597
469
|
});
|
|
598
470
|
}
|
|
599
471
|
|
|
600
|
-
function addAttr(
|
|
601
|
-
|
|
472
|
+
function addAttr(store: Store, [attr]: [InstantDBAttr]) {
|
|
473
|
+
store.attrs[attr.id] = attr;
|
|
474
|
+
resetAttrIndexes(store);
|
|
602
475
|
}
|
|
603
476
|
|
|
604
477
|
function getAllTriples(store: Store): Triple[] {
|
|
605
478
|
return allMapValues(store.eav, 3);
|
|
606
479
|
}
|
|
607
480
|
|
|
608
|
-
function deleteAttr(store: Store,
|
|
609
|
-
if (!
|
|
481
|
+
function deleteAttr(store: Store, [id]: [string]) {
|
|
482
|
+
if (!store.attrs[id]) return;
|
|
610
483
|
const newTriples = getAllTriples(store).filter(([_, aid]) => aid !== id);
|
|
611
|
-
|
|
612
|
-
|
|
484
|
+
delete store.attrs[id];
|
|
485
|
+
resetAttrIndexes(store);
|
|
486
|
+
resetIndexMap(store, newTriples);
|
|
613
487
|
}
|
|
614
488
|
|
|
615
489
|
function updateAttr(
|
|
616
490
|
store: Store,
|
|
617
|
-
attrsStore: AttrsStore,
|
|
618
491
|
[partialAttr]: [Partial<InstantDBAttr> & { id: string }],
|
|
619
492
|
) {
|
|
620
|
-
const attr =
|
|
493
|
+
const attr = store.attrs[partialAttr.id];
|
|
621
494
|
if (!attr) return;
|
|
622
|
-
|
|
623
|
-
|
|
495
|
+
store.attrs[partialAttr.id] = { ...attr, ...partialAttr };
|
|
496
|
+
resetAttrIndexes(store);
|
|
497
|
+
resetIndexMap(store, getAllTriples(store));
|
|
624
498
|
}
|
|
625
499
|
|
|
626
|
-
function applyTxStep(store: Store,
|
|
500
|
+
function applyTxStep(store: Store, txStep) {
|
|
627
501
|
const [action, ...args] = txStep;
|
|
628
502
|
switch (action) {
|
|
629
503
|
case 'add-triple':
|
|
630
|
-
addTriple(store,
|
|
504
|
+
addTriple(store, args);
|
|
631
505
|
break;
|
|
632
506
|
case 'deep-merge-triple':
|
|
633
|
-
mergeTriple(store,
|
|
507
|
+
mergeTriple(store, args);
|
|
634
508
|
break;
|
|
635
509
|
case 'retract-triple':
|
|
636
|
-
retractTriple(store,
|
|
510
|
+
retractTriple(store, args);
|
|
637
511
|
break;
|
|
638
512
|
case 'delete-entity':
|
|
639
|
-
deleteEntity(store,
|
|
513
|
+
deleteEntity(store, args);
|
|
640
514
|
break;
|
|
641
515
|
case 'add-attr':
|
|
642
|
-
addAttr(
|
|
516
|
+
addAttr(store, args);
|
|
643
517
|
break;
|
|
644
518
|
case 'delete-attr':
|
|
645
|
-
deleteAttr(store,
|
|
519
|
+
deleteAttr(store, args);
|
|
646
520
|
break;
|
|
647
521
|
case 'update-attr':
|
|
648
|
-
updateAttr(store,
|
|
522
|
+
updateAttr(store, args);
|
|
649
523
|
break;
|
|
650
524
|
case 'restore-attr':
|
|
651
525
|
break;
|
|
@@ -826,36 +700,35 @@ export function getAsObject(
|
|
|
826
700
|
}
|
|
827
701
|
|
|
828
702
|
export function getAttrByFwdIdentName(
|
|
829
|
-
|
|
703
|
+
store: Store,
|
|
830
704
|
inputEtype: string,
|
|
831
705
|
inputLabel: string,
|
|
832
706
|
) {
|
|
833
|
-
return
|
|
707
|
+
return store.attrIndexes.forwardIdents.get(inputEtype)?.get(inputLabel);
|
|
834
708
|
}
|
|
835
709
|
|
|
836
710
|
export function getAttrByReverseIdentName(
|
|
837
|
-
|
|
711
|
+
store: Store,
|
|
838
712
|
inputEtype: string,
|
|
839
713
|
inputLabel: string,
|
|
840
714
|
) {
|
|
841
|
-
return
|
|
715
|
+
return store.attrIndexes.revIdents.get(inputEtype)?.get(inputLabel);
|
|
842
716
|
}
|
|
843
717
|
|
|
844
|
-
export function getBlobAttrs(
|
|
845
|
-
return
|
|
718
|
+
export function getBlobAttrs(store: Store, etype: string) {
|
|
719
|
+
return store.attrIndexes.blobAttrs.get(etype);
|
|
846
720
|
}
|
|
847
721
|
|
|
848
|
-
export function getPrimaryKeyAttr(
|
|
849
|
-
const fromPrimary =
|
|
722
|
+
export function getPrimaryKeyAttr(store: Store, etype: string) {
|
|
723
|
+
const fromPrimary = store.attrIndexes.primaryKeys.get(etype);
|
|
850
724
|
if (fromPrimary) {
|
|
851
725
|
return fromPrimary;
|
|
852
726
|
}
|
|
853
|
-
return
|
|
727
|
+
return store.attrIndexes.forwardIdents.get(etype)?.get('id');
|
|
854
728
|
}
|
|
855
729
|
|
|
856
730
|
function findTriple(
|
|
857
731
|
store: Store,
|
|
858
|
-
attrsStore: AttrsStore,
|
|
859
732
|
rawTriple: [string, string, any] | Triple,
|
|
860
733
|
): Triple | undefined {
|
|
861
734
|
const triple = resolveLookupRefs(store, rawTriple as Triple);
|
|
@@ -864,7 +737,7 @@ function findTriple(
|
|
|
864
737
|
}
|
|
865
738
|
|
|
866
739
|
const [eid, aid, v] = triple;
|
|
867
|
-
const attr =
|
|
740
|
+
const attr = getAttr(store.attrs, aid);
|
|
868
741
|
if (!attr) {
|
|
869
742
|
// (XXX): Due to the way we're handling attrs, it's
|
|
870
743
|
// possible to enter a state where we receive a triple without an attr.
|
|
@@ -876,7 +749,7 @@ function findTriple(
|
|
|
876
749
|
return getInMap(store.eav, [eid, aid]);
|
|
877
750
|
}
|
|
878
751
|
|
|
879
|
-
export function transact(store: Store,
|
|
752
|
+
export function transact(store: Store, txSteps) {
|
|
880
753
|
const txStepsFiltered = txSteps.filter(
|
|
881
754
|
([action, eid, attrId, value, opts]) => {
|
|
882
755
|
if (action !== 'add-triple' && action !== 'deep-merge-triple') {
|
|
@@ -890,13 +763,10 @@ export function transact(store: Store, attrsStore: AttrsStore, txSteps) {
|
|
|
890
763
|
|
|
891
764
|
let exists = false;
|
|
892
765
|
|
|
893
|
-
const attr =
|
|
766
|
+
const attr = getAttr(store.attrs, attrId);
|
|
894
767
|
if (attr) {
|
|
895
|
-
const idAttr = getPrimaryKeyAttr(
|
|
896
|
-
|
|
897
|
-
attr['forward-identity'][1],
|
|
898
|
-
);
|
|
899
|
-
exists = !!findTriple(store, attrsStore, [
|
|
768
|
+
const idAttr = getPrimaryKeyAttr(store, attr['forward-identity'][1]);
|
|
769
|
+
exists = !!findTriple(store, [
|
|
900
770
|
eid as string,
|
|
901
771
|
idAttr?.id as string,
|
|
902
772
|
eid,
|
|
@@ -917,7 +787,7 @@ export function transact(store: Store, attrsStore: AttrsStore, txSteps) {
|
|
|
917
787
|
|
|
918
788
|
return create(store, (draft) => {
|
|
919
789
|
txStepsFiltered.forEach((txStep) => {
|
|
920
|
-
applyTxStep(draft,
|
|
790
|
+
applyTxStep(draft, txStep);
|
|
921
791
|
});
|
|
922
792
|
});
|
|
923
793
|
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { PageInfoResponse } from './queryTypes.ts';
|
|
2
|
-
import { AttrsStore, AttrsStoreJson, Store, StoreJson } from './store.ts';
|
|
3
|
-
export type QuerySubResult = {
|
|
4
|
-
store: Store;
|
|
5
|
-
attrsStore: AttrsStore;
|
|
6
|
-
pageInfo?: PageInfoResponse<any> | null | undefined;
|
|
7
|
-
aggregate?: any;
|
|
8
|
-
processedTxId: number;
|
|
9
|
-
};
|
|
10
|
-
export type QuerySub = {
|
|
11
|
-
q: Object;
|
|
12
|
-
eventId: string;
|
|
13
|
-
lastAccessed?: number | null | undefined;
|
|
14
|
-
result?: QuerySubResult;
|
|
15
|
-
};
|
|
16
|
-
export type QuerySubResultInStorage = {
|
|
17
|
-
store: StoreJson;
|
|
18
|
-
attrsStore: AttrsStoreJson;
|
|
19
|
-
pageInfo?: PageInfoResponse<any> | null | undefined;
|
|
20
|
-
aggregate?: any;
|
|
21
|
-
processedTxId: number;
|
|
22
|
-
};
|
|
23
|
-
export type QuerySubInStorage = {
|
|
24
|
-
q: Object;
|
|
25
|
-
eventId: string;
|
|
26
|
-
lastAccessed?: number | null | undefined;
|
|
27
|
-
result?: QuerySubResultInStorage;
|
|
28
|
-
};
|
|
29
|
-
//# sourceMappingURL=reactorTypes.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"reactorTypes.d.ts","sourceRoot":"","sources":["../../src/reactorTypes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE1E,MAAM,MAAM,cAAc,GAAG;IAC3B,KAAK,EAAE,KAAK,CAAC;IACb,UAAU,EAAE,UAAU,CAAC;IACvB,QAAQ,CAAC,EAAE,gBAAgB,CAAC,GAAG,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;IACpD,SAAS,CAAC,EAAE,GAAG,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG;IACrB,CAAC,EAAE,MAAM,CAAC;IACV,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACzC,MAAM,CAAC,EAAE,cAAc,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,KAAK,EAAE,SAAS,CAAC;IACjB,UAAU,EAAE,cAAc,CAAC;IAC3B,QAAQ,CAAC,EAAE,gBAAgB,CAAC,GAAG,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;IACpD,SAAS,CAAC,EAAE,GAAG,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,CAAC,EAAE,MAAM,CAAC;IACV,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACzC,MAAM,CAAC,EAAE,uBAAuB,CAAC;CAClC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"reactorTypes.js","sourceRoot":"","sources":["../../src/reactorTypes.ts"],"names":[],"mappings":"","sourcesContent":["import { PageInfoResponse } from './queryTypes.ts';\nimport { AttrsStore, AttrsStoreJson, Store, StoreJson } from './store.ts';\n\nexport type QuerySubResult = {\n store: Store;\n attrsStore: AttrsStore;\n pageInfo?: PageInfoResponse<any> | null | undefined;\n aggregate?: any;\n processedTxId: number;\n};\n\nexport type QuerySub = {\n q: Object;\n eventId: string;\n lastAccessed?: number | null | undefined;\n result?: QuerySubResult;\n};\n\nexport type QuerySubResultInStorage = {\n store: StoreJson;\n attrsStore: AttrsStoreJson;\n pageInfo?: PageInfoResponse<any> | null | undefined;\n aggregate?: any;\n processedTxId: number;\n};\n\nexport type QuerySubInStorage = {\n q: Object;\n eventId: string;\n lastAccessed?: number | null | undefined;\n result?: QuerySubResultInStorage;\n};\n"]}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { PageInfoResponse } from './queryTypes.ts';
|
|
2
|
-
import { AttrsStore, AttrsStoreJson, Store, StoreJson } from './store.ts';
|
|
3
|
-
export type QuerySubResult = {
|
|
4
|
-
store: Store;
|
|
5
|
-
attrsStore: AttrsStore;
|
|
6
|
-
pageInfo?: PageInfoResponse<any> | null | undefined;
|
|
7
|
-
aggregate?: any;
|
|
8
|
-
processedTxId: number;
|
|
9
|
-
};
|
|
10
|
-
export type QuerySub = {
|
|
11
|
-
q: Object;
|
|
12
|
-
eventId: string;
|
|
13
|
-
lastAccessed?: number | null | undefined;
|
|
14
|
-
result?: QuerySubResult;
|
|
15
|
-
};
|
|
16
|
-
export type QuerySubResultInStorage = {
|
|
17
|
-
store: StoreJson;
|
|
18
|
-
attrsStore: AttrsStoreJson;
|
|
19
|
-
pageInfo?: PageInfoResponse<any> | null | undefined;
|
|
20
|
-
aggregate?: any;
|
|
21
|
-
processedTxId: number;
|
|
22
|
-
};
|
|
23
|
-
export type QuerySubInStorage = {
|
|
24
|
-
q: Object;
|
|
25
|
-
eventId: string;
|
|
26
|
-
lastAccessed?: number | null | undefined;
|
|
27
|
-
result?: QuerySubResultInStorage;
|
|
28
|
-
};
|
|
29
|
-
//# sourceMappingURL=reactorTypes.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"reactorTypes.d.ts","sourceRoot":"","sources":["../../src/reactorTypes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE1E,MAAM,MAAM,cAAc,GAAG;IAC3B,KAAK,EAAE,KAAK,CAAC;IACb,UAAU,EAAE,UAAU,CAAC;IACvB,QAAQ,CAAC,EAAE,gBAAgB,CAAC,GAAG,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;IACpD,SAAS,CAAC,EAAE,GAAG,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG;IACrB,CAAC,EAAE,MAAM,CAAC;IACV,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACzC,MAAM,CAAC,EAAE,cAAc,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,KAAK,EAAE,SAAS,CAAC;IACjB,UAAU,EAAE,cAAc,CAAC;IAC3B,QAAQ,CAAC,EAAE,gBAAgB,CAAC,GAAG,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;IACpD,SAAS,CAAC,EAAE,GAAG,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,CAAC,EAAE,MAAM,CAAC;IACV,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACzC,MAAM,CAAC,EAAE,uBAAuB,CAAC;CAClC,CAAC"}
|
package/dist/esm/reactorTypes.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"reactorTypes.js","sourceRoot":"","sources":["../../src/reactorTypes.ts"],"names":[],"mappings":"","sourcesContent":["import { PageInfoResponse } from './queryTypes.ts';\nimport { AttrsStore, AttrsStoreJson, Store, StoreJson } from './store.ts';\n\nexport type QuerySubResult = {\n store: Store;\n attrsStore: AttrsStore;\n pageInfo?: PageInfoResponse<any> | null | undefined;\n aggregate?: any;\n processedTxId: number;\n};\n\nexport type QuerySub = {\n q: Object;\n eventId: string;\n lastAccessed?: number | null | undefined;\n result?: QuerySubResult;\n};\n\nexport type QuerySubResultInStorage = {\n store: StoreJson;\n attrsStore: AttrsStoreJson;\n pageInfo?: PageInfoResponse<any> | null | undefined;\n aggregate?: any;\n processedTxId: number;\n};\n\nexport type QuerySubInStorage = {\n q: Object;\n eventId: string;\n lastAccessed?: number | null | undefined;\n result?: QuerySubResultInStorage;\n};\n"]}
|
package/src/reactorTypes.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { PageInfoResponse } from './queryTypes.ts';
|
|
2
|
-
import { AttrsStore, AttrsStoreJson, Store, StoreJson } from './store.ts';
|
|
3
|
-
|
|
4
|
-
export type QuerySubResult = {
|
|
5
|
-
store: Store;
|
|
6
|
-
attrsStore: AttrsStore;
|
|
7
|
-
pageInfo?: PageInfoResponse<any> | null | undefined;
|
|
8
|
-
aggregate?: any;
|
|
9
|
-
processedTxId: number;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export type QuerySub = {
|
|
13
|
-
q: Object;
|
|
14
|
-
eventId: string;
|
|
15
|
-
lastAccessed?: number | null | undefined;
|
|
16
|
-
result?: QuerySubResult;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export type QuerySubResultInStorage = {
|
|
20
|
-
store: StoreJson;
|
|
21
|
-
attrsStore: AttrsStoreJson;
|
|
22
|
-
pageInfo?: PageInfoResponse<any> | null | undefined;
|
|
23
|
-
aggregate?: any;
|
|
24
|
-
processedTxId: number;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export type QuerySubInStorage = {
|
|
28
|
-
q: Object;
|
|
29
|
-
eventId: string;
|
|
30
|
-
lastAccessed?: number | null | undefined;
|
|
31
|
-
result?: QuerySubResultInStorage;
|
|
32
|
-
};
|