@instantdb/core 0.22.86-experimental.split-store.20178922132.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 +4 -1
- package/dist/commonjs/Reactor.d.ts.map +1 -1
- package/dist/commonjs/Reactor.js +22 -12
- package/dist/commonjs/Reactor.js.map +1 -1
- package/dist/commonjs/instaml.d.ts +3 -3
- package/dist/commonjs/instaml.d.ts.map +1 -1
- package/dist/commonjs/instaml.js +2 -2
- package/dist/commonjs/instaml.js.map +1 -1
- package/dist/commonjs/instaql.d.ts +2 -2
- package/dist/commonjs/instaql.d.ts.map +1 -1
- package/dist/commonjs/instaql.js.map +1 -1
- package/dist/commonjs/store.d.ts +28 -9
- package/dist/commonjs/store.d.ts.map +1 -1
- package/dist/commonjs/store.js +13 -8
- package/dist/commonjs/store.js.map +1 -1
- package/dist/esm/Reactor.d.ts +4 -1
- package/dist/esm/Reactor.d.ts.map +1 -1
- package/dist/esm/Reactor.js +22 -12
- package/dist/esm/Reactor.js.map +1 -1
- package/dist/esm/instaml.d.ts +3 -3
- package/dist/esm/instaml.d.ts.map +1 -1
- package/dist/esm/instaml.js +3 -3
- package/dist/esm/instaml.js.map +1 -1
- package/dist/esm/instaql.d.ts +2 -2
- package/dist/esm/instaql.d.ts.map +1 -1
- package/dist/esm/instaql.js.map +1 -1
- package/dist/esm/store.d.ts +28 -9
- package/dist/esm/store.d.ts.map +1 -1
- package/dist/esm/store.js +11 -6
- package/dist/esm/store.js.map +1 -1
- package/dist/standalone/index.js +549 -533
- package/dist/standalone/index.umd.cjs +2 -2
- package/package.json +2 -2
- package/src/Reactor.js +44 -35
- package/src/instaml.ts +8 -7
- package/src/instaql.ts +2 -2
- package/src/store.ts +47 -19
- package/__tests__/src/instaql.bench.js +0 -29
|
@@ -13,11 +13,15 @@ import zenecaAttrs from './data/zeneca/attrs.json';
|
|
|
13
13
|
import zenecaTriples from './data/zeneca/triples.json';
|
|
14
14
|
import uuid from '../../src/utils/uuid';
|
|
15
15
|
import { weakHash } from '../../src';
|
|
16
|
+
import { AttrsStoreClass } from '../../src/store';
|
|
16
17
|
|
|
17
|
-
const
|
|
18
|
-
res
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
const zenecaAttrsStore = new AttrsStoreClass(
|
|
19
|
+
zenecaAttrs.reduce((res, x) => {
|
|
20
|
+
res[x.id] = x;
|
|
21
|
+
return res;
|
|
22
|
+
}, {}),
|
|
23
|
+
null,
|
|
24
|
+
);
|
|
21
25
|
|
|
22
26
|
async function waitForLoaded(reactor) {
|
|
23
27
|
await reactor.querySubs.waitForMetaToLoad();
|
|
@@ -123,12 +127,15 @@ test('rewrite mutations', () => {
|
|
|
123
127
|
];
|
|
124
128
|
|
|
125
129
|
// create transactions without any attributes
|
|
126
|
-
const optimisticSteps = instaml.transform(
|
|
130
|
+
const optimisticSteps = instaml.transform(
|
|
131
|
+
{ attrsStore: new AttrsStoreClass({}, null) },
|
|
132
|
+
ops,
|
|
133
|
+
);
|
|
127
134
|
|
|
128
135
|
const mutations = new Map([['k', { 'tx-steps': optimisticSteps }]]);
|
|
129
136
|
|
|
130
137
|
const rewrittenWithoutAttrs = reactor
|
|
131
|
-
._rewriteMutations({}, mutations)
|
|
138
|
+
._rewriteMutations(new AttrsStoreClass({}, null), mutations)
|
|
132
139
|
.get('k')['tx-steps'];
|
|
133
140
|
|
|
134
141
|
// Check that we didn't clobber anything in our rewrite
|
|
@@ -136,10 +143,10 @@ test('rewrite mutations', () => {
|
|
|
136
143
|
|
|
137
144
|
// rewrite them with the new server attributes
|
|
138
145
|
const rewrittenSteps = reactor
|
|
139
|
-
._rewriteMutations(
|
|
146
|
+
._rewriteMutations(zenecaAttrsStore, mutations)
|
|
140
147
|
.get('k')['tx-steps'];
|
|
141
148
|
|
|
142
|
-
const serverSteps = instaml.transform({
|
|
149
|
+
const serverSteps = instaml.transform({ attrsStore: zenecaAttrsStore }, ops);
|
|
143
150
|
expect(rewrittenSteps).toEqual(serverSteps);
|
|
144
151
|
});
|
|
145
152
|
|
|
@@ -170,7 +177,7 @@ test('rewrite mutations works with multiple transactions', () => {
|
|
|
170
177
|
|
|
171
178
|
for (const k of keys) {
|
|
172
179
|
const attrs = reactor.optimisticAttrs();
|
|
173
|
-
const steps = instaml.transform({ attrs }, ops);
|
|
180
|
+
const steps = instaml.transform({ attrsStore: attrs }, ops);
|
|
174
181
|
const mut = {
|
|
175
182
|
op: 'transact',
|
|
176
183
|
'tx-steps': steps,
|
|
@@ -183,11 +190,11 @@ test('rewrite mutations works with multiple transactions', () => {
|
|
|
183
190
|
|
|
184
191
|
// rewrite them with the new server attributes
|
|
185
192
|
const rewrittenMutations = reactor._rewriteMutations(
|
|
186
|
-
|
|
193
|
+
zenecaAttrsStore,
|
|
187
194
|
reactor._pendingMutations(),
|
|
188
195
|
);
|
|
189
196
|
|
|
190
|
-
const serverSteps = instaml.transform({
|
|
197
|
+
const serverSteps = instaml.transform({ attrsStore: zenecaAttrsStore }, ops);
|
|
191
198
|
for (const k of keys) {
|
|
192
199
|
expect(rewrittenMutations.get(k)['tx-steps']).toEqual(serverSteps);
|
|
193
200
|
}
|
|
@@ -7,10 +7,22 @@ import {
|
|
|
7
7
|
querySingle,
|
|
8
8
|
queryWhere,
|
|
9
9
|
} from '../../src/datalog';
|
|
10
|
-
import {
|
|
11
|
-
|
|
10
|
+
import {
|
|
11
|
+
AttrsStoreClass,
|
|
12
|
+
createStore,
|
|
13
|
+
getAttrByFwdIdentName,
|
|
14
|
+
} from '../../src/store';
|
|
15
|
+
import { InstantDBAttr } from '../../src';
|
|
16
|
+
|
|
17
|
+
const movieAttrsStore = new AttrsStoreClass(
|
|
18
|
+
movieAttrs as unknown as Record<string, InstantDBAttr>,
|
|
19
|
+
null,
|
|
20
|
+
);
|
|
12
21
|
|
|
13
|
-
const store = createStore(
|
|
22
|
+
const store = createStore(
|
|
23
|
+
movieAttrsStore,
|
|
24
|
+
movieTriples as [string, string, any, number][],
|
|
25
|
+
);
|
|
14
26
|
|
|
15
27
|
test('matchPattern', () => {
|
|
16
28
|
expect(
|
|
@@ -31,8 +43,8 @@ test('matchPattern', () => {
|
|
|
31
43
|
|
|
32
44
|
function aid(friendlyName) {
|
|
33
45
|
const [etype, label] = friendlyName.split('/');
|
|
34
|
-
const attr = getAttrByFwdIdentName(
|
|
35
|
-
return attr
|
|
46
|
+
const attr = getAttrByFwdIdentName(movieAttrsStore, etype, label);
|
|
47
|
+
return attr?.id;
|
|
36
48
|
}
|
|
37
49
|
|
|
38
50
|
function mid(movieName) {
|
|
@@ -3,27 +3,33 @@ import * as instaml from '../../src/instaml';
|
|
|
3
3
|
import * as instatx from '../../src/instatx';
|
|
4
4
|
import zenecaAttrs from './data/zeneca/attrs.json';
|
|
5
5
|
import zenecaTriples from './data/zeneca/triples.json';
|
|
6
|
-
import { createStore, transact } from '../../src/store';
|
|
6
|
+
import { createStore, transact, AttrsStoreClass } from '../../src/store';
|
|
7
7
|
import uuid from '../../src/utils/uuid';
|
|
8
|
-
import { i } from '../../src/index';
|
|
8
|
+
import { i, InstantDBAttr } from '../../src/index';
|
|
9
9
|
|
|
10
10
|
const zenecaAttrToId = zenecaAttrs.reduce((res, x) => {
|
|
11
11
|
res[`${x['forward-identity'][1]}/${x['forward-identity'][2]}`] = x.id;
|
|
12
12
|
return res;
|
|
13
13
|
}, {});
|
|
14
14
|
|
|
15
|
-
const
|
|
16
|
-
res
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
const zenecaAttrsStore = new AttrsStoreClass(
|
|
16
|
+
zenecaAttrs.reduce((res, x) => {
|
|
17
|
+
res[x.id] = x;
|
|
18
|
+
return res;
|
|
19
|
+
}, {}),
|
|
20
|
+
null,
|
|
21
|
+
);
|
|
19
22
|
|
|
20
|
-
const store = createStore(
|
|
23
|
+
const store = createStore(
|
|
24
|
+
zenecaAttrsStore,
|
|
25
|
+
zenecaTriples as [string, string, any, number][],
|
|
26
|
+
);
|
|
21
27
|
|
|
22
28
|
test('simple update transform', () => {
|
|
23
29
|
const testId = uuid();
|
|
24
30
|
|
|
25
31
|
const ops = instatx.tx.books[testId].update({ title: 'New Title' });
|
|
26
|
-
const result = instaml.transform({
|
|
32
|
+
const result = instaml.transform({ attrsStore: zenecaAttrsStore }, ops);
|
|
27
33
|
|
|
28
34
|
const expected = [
|
|
29
35
|
['add-triple', testId, zenecaAttrToId['books/title'], 'New Title'],
|
|
@@ -43,7 +49,7 @@ test('undefined is ignored in update', () => {
|
|
|
43
49
|
handle: 'bobby',
|
|
44
50
|
fullName: undefined,
|
|
45
51
|
});
|
|
46
|
-
const result = instaml.transform({
|
|
52
|
+
const result = instaml.transform({ attrsStore: zenecaAttrsStore }, ops);
|
|
47
53
|
|
|
48
54
|
const expected = [
|
|
49
55
|
['add-triple', testId, zenecaAttrToId['users/id'], testId],
|
|
@@ -63,7 +69,7 @@ test('ignores id attrs', () => {
|
|
|
63
69
|
title: 'New Title',
|
|
64
70
|
id: 'ploop',
|
|
65
71
|
});
|
|
66
|
-
const result = instaml.transform({
|
|
72
|
+
const result = instaml.transform({ attrsStore: zenecaAttrsStore }, ops);
|
|
67
73
|
|
|
68
74
|
const expected = [
|
|
69
75
|
['add-triple', testId, zenecaAttrToId['books/title'], 'New Title'],
|
|
@@ -80,7 +86,7 @@ test("optimistically adds attrs if they don't exist", () => {
|
|
|
80
86
|
|
|
81
87
|
const ops = instatx.tx.books[testId].update({ newAttr: 'New Title' });
|
|
82
88
|
|
|
83
|
-
const result = instaml.transform({
|
|
89
|
+
const result = instaml.transform({ attrsStore: zenecaAttrsStore }, ops);
|
|
84
90
|
|
|
85
91
|
const expected = [
|
|
86
92
|
[
|
|
@@ -114,7 +120,7 @@ test('lookup resolves attr ids', () => {
|
|
|
114
120
|
|
|
115
121
|
const stopaLookup = [zenecaAttrToId['users/email'], 'stopa@instantdb.com'];
|
|
116
122
|
|
|
117
|
-
const result = instaml.transform({
|
|
123
|
+
const result = instaml.transform({ attrsStore: zenecaAttrsStore }, ops);
|
|
118
124
|
|
|
119
125
|
const expected = [
|
|
120
126
|
['add-triple', stopaLookup, zenecaAttrToId['users/handle'], 'stopa'],
|
|
@@ -140,7 +146,7 @@ test('lookup creates unique attrs for custom lookups', () => {
|
|
|
140
146
|
'newAttrValue',
|
|
141
147
|
];
|
|
142
148
|
|
|
143
|
-
const result = instaml.transform({
|
|
149
|
+
const result = instaml.transform({ attrsStore: zenecaAttrsStore }, ops);
|
|
144
150
|
const expected = [
|
|
145
151
|
[
|
|
146
152
|
'add-attr',
|
|
@@ -170,7 +176,10 @@ test('lookup creates unique attrs for lookups in link values', () => {
|
|
|
170
176
|
.update({})
|
|
171
177
|
.link({ posts: instatx.lookup('slug', 'life-is-good') });
|
|
172
178
|
|
|
173
|
-
const result = instaml.transform(
|
|
179
|
+
const result = instaml.transform(
|
|
180
|
+
{ attrsStore: new AttrsStoreClass({}, null) },
|
|
181
|
+
ops,
|
|
182
|
+
);
|
|
174
183
|
|
|
175
184
|
expect(result).toEqual([
|
|
176
185
|
[
|
|
@@ -229,7 +238,10 @@ test('lookup creates unique attrs for lookups in link values with arrays', () =>
|
|
|
229
238
|
],
|
|
230
239
|
});
|
|
231
240
|
|
|
232
|
-
const result = instaml.transform(
|
|
241
|
+
const result = instaml.transform(
|
|
242
|
+
{ attrsStore: new AttrsStoreClass({}, null) },
|
|
243
|
+
ops,
|
|
244
|
+
);
|
|
233
245
|
|
|
234
246
|
const expected = [
|
|
235
247
|
[
|
|
@@ -305,10 +317,10 @@ test('lookup creates unique attrs for lookups in link values when fwd-ident exis
|
|
|
305
317
|
cardinality: 'one',
|
|
306
318
|
'unique?': true,
|
|
307
319
|
'index?': true,
|
|
308
|
-
};
|
|
320
|
+
} as unknown as InstantDBAttr;
|
|
309
321
|
|
|
310
322
|
const result = instaml.transform(
|
|
311
|
-
{
|
|
323
|
+
{ attrsStore: new AttrsStoreClass({ [attrId]: existingRefAttr }, null) },
|
|
312
324
|
ops,
|
|
313
325
|
);
|
|
314
326
|
|
|
@@ -362,10 +374,10 @@ test('lookup creates unique attrs for lookups in link values when rev-ident exis
|
|
|
362
374
|
cardinality: 'one',
|
|
363
375
|
'unique?': true,
|
|
364
376
|
'index?': true,
|
|
365
|
-
};
|
|
377
|
+
} as unknown as InstantDBAttr;
|
|
366
378
|
|
|
367
379
|
const result = instaml.transform(
|
|
368
|
-
{
|
|
380
|
+
{ attrsStore: new AttrsStoreClass({ [attrId]: existingRefAttr }, null) },
|
|
369
381
|
ops,
|
|
370
382
|
);
|
|
371
383
|
|
|
@@ -414,35 +426,38 @@ test("lookup doesn't override attrs for lookups in link values", () => {
|
|
|
414
426
|
const userIdAttrId = uuid();
|
|
415
427
|
const postsSlugAttrId = uuid();
|
|
416
428
|
|
|
417
|
-
const
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
429
|
+
const attrsStore = new AttrsStoreClass(
|
|
430
|
+
{
|
|
431
|
+
[refAttrId]: {
|
|
432
|
+
id: refAttrId,
|
|
433
|
+
'forward-identity': [uuid(), 'users', 'posts'],
|
|
434
|
+
'reverse-identity': [uuid(), 'posts', 'users'],
|
|
435
|
+
'value-type': 'ref',
|
|
436
|
+
cardinality: 'one',
|
|
437
|
+
'unique?': true,
|
|
438
|
+
'index?': true,
|
|
439
|
+
} as unknown as InstantDBAttr,
|
|
440
|
+
[userIdAttrId]: {
|
|
441
|
+
id: userIdAttrId,
|
|
442
|
+
'forward-identity': [uuid(), 'users', 'id'],
|
|
443
|
+
'value-type': 'blob',
|
|
444
|
+
cardinality: 'one',
|
|
445
|
+
'unique?': true,
|
|
446
|
+
'index?': false,
|
|
447
|
+
} as unknown as InstantDBAttr,
|
|
448
|
+
[postsSlugAttrId]: {
|
|
449
|
+
id: postsSlugAttrId,
|
|
450
|
+
'forward-identity': [uuid(), 'posts', 'slug'],
|
|
451
|
+
'value-type': 'blob',
|
|
452
|
+
cardinality: 'one',
|
|
453
|
+
'unique?': true,
|
|
454
|
+
'index?': true,
|
|
455
|
+
} as unknown as InstantDBAttr,
|
|
442
456
|
},
|
|
443
|
-
|
|
457
|
+
null,
|
|
458
|
+
);
|
|
444
459
|
|
|
445
|
-
const result = instaml.transform({
|
|
460
|
+
const result = instaml.transform({ attrsStore }, ops);
|
|
446
461
|
|
|
447
462
|
expect(result).toEqual([
|
|
448
463
|
['add-triple', uid, userIdAttrId, uid],
|
|
@@ -455,39 +470,42 @@ test("lookup doesn't override attrs for lookups in self links", () => {
|
|
|
455
470
|
const postIdAttrId = uuid();
|
|
456
471
|
const postsSlugAttrId = uuid();
|
|
457
472
|
|
|
458
|
-
const
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
473
|
+
const attrsStore = new AttrsStoreClass(
|
|
474
|
+
{
|
|
475
|
+
[postIdAttrId]: {
|
|
476
|
+
id: postIdAttrId,
|
|
477
|
+
'forward-identity': [uuid(), 'posts', 'id'],
|
|
478
|
+
'value-type': 'blob',
|
|
479
|
+
cardinality: 'one',
|
|
480
|
+
'unique?': true,
|
|
481
|
+
'index?': false,
|
|
482
|
+
} as unknown as InstantDBAttr,
|
|
483
|
+
[postsSlugAttrId]: {
|
|
484
|
+
id: postsSlugAttrId,
|
|
485
|
+
'forward-identity': [uuid(), 'posts', 'slug'],
|
|
486
|
+
'value-type': 'blob',
|
|
487
|
+
cardinality: 'one',
|
|
488
|
+
'unique?': true,
|
|
489
|
+
'index?': true,
|
|
490
|
+
} as unknown as InstantDBAttr,
|
|
491
|
+
[refAttrId]: {
|
|
492
|
+
id: refAttrId,
|
|
493
|
+
'forward-identity': [uuid(), 'posts', 'parent'],
|
|
494
|
+
'reverse-identity': [uuid(), 'posts', 'child'],
|
|
495
|
+
'value-type': 'ref',
|
|
496
|
+
cardinality: 'one',
|
|
497
|
+
'unique?': true,
|
|
498
|
+
'index?': true,
|
|
499
|
+
} as unknown as InstantDBAttr,
|
|
483
500
|
},
|
|
484
|
-
|
|
501
|
+
null,
|
|
502
|
+
);
|
|
485
503
|
|
|
486
504
|
const ops1 = instatx.tx.posts[instatx.lookup('slug', 'life-is-good')]
|
|
487
505
|
.update({})
|
|
488
506
|
.link({ parent: instatx.lookup('slug', 'life-is-good') });
|
|
489
507
|
|
|
490
|
-
const result1 = instaml.transform({
|
|
508
|
+
const result1 = instaml.transform({ attrsStore }, ops1);
|
|
491
509
|
|
|
492
510
|
expect(result1.filter((x) => x[0] !== 'add-triple')).toEqual([]);
|
|
493
511
|
|
|
@@ -495,7 +513,7 @@ test("lookup doesn't override attrs for lookups in self links", () => {
|
|
|
495
513
|
.update({})
|
|
496
514
|
.link({ child: instatx.lookup('slug', 'life-is-good') });
|
|
497
515
|
|
|
498
|
-
const result2 = instaml.transform({
|
|
516
|
+
const result2 = instaml.transform({ attrsStore }, ops2);
|
|
499
517
|
|
|
500
518
|
expect(result2.filter((x) => x[0] !== 'add-triple')).toEqual([]);
|
|
501
519
|
});
|
|
@@ -513,7 +531,10 @@ test('lookup creates unique ref attrs for ref lookup', () => {
|
|
|
513
531
|
uid,
|
|
514
532
|
];
|
|
515
533
|
|
|
516
|
-
const result = instaml.transform(
|
|
534
|
+
const result = instaml.transform(
|
|
535
|
+
{ attrsStore: new AttrsStoreClass({}, null) },
|
|
536
|
+
ops,
|
|
537
|
+
);
|
|
517
538
|
const expected = [
|
|
518
539
|
[
|
|
519
540
|
'add-attr',
|
|
@@ -576,7 +597,10 @@ test('lookup creates unique ref attrs for ref lookup in link value', () => {
|
|
|
576
597
|
uid,
|
|
577
598
|
];
|
|
578
599
|
|
|
579
|
-
const result = instaml.transform(
|
|
600
|
+
const result = instaml.transform(
|
|
601
|
+
{ attrsStore: new AttrsStoreClass({}, null) },
|
|
602
|
+
ops,
|
|
603
|
+
);
|
|
580
604
|
|
|
581
605
|
const expected = [
|
|
582
606
|
[
|
|
@@ -621,7 +645,7 @@ test('lookups create entities from links', () => {
|
|
|
621
645
|
bookshelves: bookshelfId,
|
|
622
646
|
});
|
|
623
647
|
|
|
624
|
-
const result = instaml.transform({
|
|
648
|
+
const result = instaml.transform({ attrsStore: zenecaAttrsStore }, ops);
|
|
625
649
|
const expectedLookup = [zenecaAttrToId['users/handle'], 'bobby_newuser'];
|
|
626
650
|
const expected = [
|
|
627
651
|
['add-triple', expectedLookup, zenecaAttrToId['users/id'], expectedLookup],
|
|
@@ -648,7 +672,7 @@ test('lookups create entities from unlinks', () => {
|
|
|
648
672
|
bookshelves: bookshelfId,
|
|
649
673
|
});
|
|
650
674
|
|
|
651
|
-
const result = instaml.transform({
|
|
675
|
+
const result = instaml.transform({ attrsStore: zenecaAttrsStore }, ops);
|
|
652
676
|
const expectedLookup = [zenecaAttrToId['users/handle'], 'bobby_newuser'];
|
|
653
677
|
const expected = [
|
|
654
678
|
['add-triple', expectedLookup, zenecaAttrToId['users/id'], expectedLookup],
|
|
@@ -670,7 +694,10 @@ test('mode: update', () => {
|
|
|
670
694
|
// create
|
|
671
695
|
var id = uuid();
|
|
672
696
|
var ops = instatx.tx.users[id].update({ handle: 'test' });
|
|
673
|
-
var result = instaml.transform(
|
|
697
|
+
var result = instaml.transform(
|
|
698
|
+
{ attrsStore: zenecaAttrsStore, stores: [store] },
|
|
699
|
+
ops,
|
|
700
|
+
);
|
|
674
701
|
for (const txStep of result) {
|
|
675
702
|
expect(txStep[4]).toEqual(undefined);
|
|
676
703
|
}
|
|
@@ -679,7 +706,10 @@ test('mode: update', () => {
|
|
|
679
706
|
ops = instatx.tx.users['ce942051-2d74-404a-9c7d-4aa3f2d54ae4'].update({
|
|
680
707
|
handle: 'joe2',
|
|
681
708
|
});
|
|
682
|
-
result = instaml.transform(
|
|
709
|
+
result = instaml.transform(
|
|
710
|
+
{ attrsStore: zenecaAttrsStore, stores: [store] },
|
|
711
|
+
ops,
|
|
712
|
+
);
|
|
683
713
|
for (const txStep of result) {
|
|
684
714
|
expect(txStep[4]).toEqual({ mode: 'update' });
|
|
685
715
|
}
|
|
@@ -688,14 +718,20 @@ test('mode: update', () => {
|
|
|
688
718
|
ops = instatx.tx.users[instatx.lookup('email', 'stopa@instantdb.com')].update(
|
|
689
719
|
{ handle: 'stopa2' },
|
|
690
720
|
);
|
|
691
|
-
result = instaml.transform(
|
|
721
|
+
result = instaml.transform(
|
|
722
|
+
{ attrsStore: zenecaAttrsStore, stores: [store] },
|
|
723
|
+
ops,
|
|
724
|
+
);
|
|
692
725
|
for (const txStep of result) {
|
|
693
726
|
expect(txStep[4]).toEqual({ mode: 'update' });
|
|
694
727
|
}
|
|
695
728
|
|
|
696
729
|
// forced mode
|
|
697
730
|
var ops = instatx.tx.users[id].update({ handle: 'test' }, { upsert: false });
|
|
698
|
-
var result = instaml.transform(
|
|
731
|
+
var result = instaml.transform(
|
|
732
|
+
{ attrsStore: zenecaAttrsStore, stores: [store] },
|
|
733
|
+
ops,
|
|
734
|
+
);
|
|
699
735
|
for (const txStep of result) {
|
|
700
736
|
expect(txStep[4]).toEqual({ mode: 'update' });
|
|
701
737
|
}
|
|
@@ -704,7 +740,10 @@ test('mode: update', () => {
|
|
|
704
740
|
{ handle: 'test' },
|
|
705
741
|
{ upsert: true },
|
|
706
742
|
);
|
|
707
|
-
var result = instaml.transform(
|
|
743
|
+
var result = instaml.transform(
|
|
744
|
+
{ attrsStore: zenecaAttrsStore, stores: [store] },
|
|
745
|
+
ops,
|
|
746
|
+
);
|
|
708
747
|
for (const txStep of result) {
|
|
709
748
|
expect(txStep[4]).toEqual(undefined);
|
|
710
749
|
}
|
|
@@ -713,7 +752,7 @@ test('mode: update', () => {
|
|
|
713
752
|
test('it throws if you use an invalid link attr', () => {
|
|
714
753
|
expect(() =>
|
|
715
754
|
instaml.transform(
|
|
716
|
-
{
|
|
755
|
+
{ attrsStore: new AttrsStoreClass({}, null) },
|
|
717
756
|
instatx.tx.users[
|
|
718
757
|
instatx.lookup('user_pref.email', 'test@example.com')
|
|
719
758
|
].update({
|
|
@@ -727,36 +766,39 @@ test("it doesn't throw if you have a period in your attr", () => {
|
|
|
727
766
|
const aid = uuid();
|
|
728
767
|
const iid = uuid();
|
|
729
768
|
const pid = uuid();
|
|
730
|
-
const
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
769
|
+
const attrsStore = new AttrsStoreClass(
|
|
770
|
+
{
|
|
771
|
+
[aid]: {
|
|
772
|
+
id: aid,
|
|
773
|
+
cardinality: 'one',
|
|
774
|
+
'forward-identity': [uuid(), 'users', 'attr.with.dot'],
|
|
775
|
+
'index?': true,
|
|
776
|
+
'unique?': true,
|
|
777
|
+
'value-type': 'blob',
|
|
778
|
+
} as unknown as InstantDBAttr,
|
|
779
|
+
[iid]: {
|
|
780
|
+
id: iid,
|
|
781
|
+
cardinality: 'one',
|
|
782
|
+
'forward-identity': [uuid(), 'users', 'id'],
|
|
783
|
+
'index?': true,
|
|
784
|
+
'unique?': false,
|
|
785
|
+
'value-type': 'blob',
|
|
786
|
+
} as unknown as InstantDBAttr,
|
|
787
|
+
[pid]: {
|
|
788
|
+
id: pid,
|
|
789
|
+
cardinality: 'one',
|
|
790
|
+
'forward-identity': [uuid(), 'users', 'a'],
|
|
791
|
+
'index?': false,
|
|
792
|
+
'unique?': false,
|
|
793
|
+
'value-type': 'blob',
|
|
794
|
+
} as unknown as InstantDBAttr,
|
|
754
795
|
},
|
|
755
|
-
|
|
796
|
+
null,
|
|
797
|
+
);
|
|
756
798
|
|
|
757
799
|
expect(
|
|
758
800
|
instaml.transform(
|
|
759
|
-
{
|
|
801
|
+
{ attrsStore },
|
|
760
802
|
instatx.tx.users[instatx.lookup('attr.with.dot', 'value')].update({
|
|
761
803
|
a: 1,
|
|
762
804
|
}),
|
|
@@ -775,7 +817,10 @@ test("it doesn't create duplicate ref attrs", () => {
|
|
|
775
817
|
instatx.tx.nsB[bid].update({}).link({ nsA: aid }),
|
|
776
818
|
];
|
|
777
819
|
|
|
778
|
-
const result = instaml.transform(
|
|
820
|
+
const result = instaml.transform(
|
|
821
|
+
{ attrsStore: new AttrsStoreClass({}, null) },
|
|
822
|
+
ops,
|
|
823
|
+
);
|
|
779
824
|
|
|
780
825
|
const expected = [
|
|
781
826
|
[
|
|
@@ -863,7 +908,7 @@ test('Schema: uses info in `attrs` and `links`', () => {
|
|
|
863
908
|
|
|
864
909
|
const result = instaml.transform(
|
|
865
910
|
{
|
|
866
|
-
|
|
911
|
+
attrsStore: zenecaAttrsStore,
|
|
867
912
|
schema: schema,
|
|
868
913
|
},
|
|
869
914
|
ops,
|
|
@@ -947,7 +992,10 @@ test("Schema: doesn't create duplicate ref attrs", () => {
|
|
|
947
992
|
instatx.tx.books[bookId].update({}).link({ comments: commentId }),
|
|
948
993
|
];
|
|
949
994
|
|
|
950
|
-
const result = instaml.transform(
|
|
995
|
+
const result = instaml.transform(
|
|
996
|
+
{ attrsStore: zenecaAttrsStore, schema },
|
|
997
|
+
ops,
|
|
998
|
+
);
|
|
951
999
|
|
|
952
1000
|
const expected = [
|
|
953
1001
|
[
|
|
@@ -1007,7 +1055,10 @@ test('Schema: lookup creates unique attrs for custom lookups', () => {
|
|
|
1007
1055
|
'stopanator',
|
|
1008
1056
|
];
|
|
1009
1057
|
|
|
1010
|
-
const result = instaml.transform(
|
|
1058
|
+
const result = instaml.transform(
|
|
1059
|
+
{ attrsStore: zenecaAttrsStore, schema },
|
|
1060
|
+
ops,
|
|
1061
|
+
);
|
|
1011
1062
|
const expected = [
|
|
1012
1063
|
[
|
|
1013
1064
|
'add-attr',
|
|
@@ -1061,7 +1112,10 @@ test('Schema: lookup creates unique attrs for lookups in link values', () => {
|
|
|
1061
1112
|
.update({})
|
|
1062
1113
|
.link({ authoredPosts: instatx.lookup('slug', 'life-is-good') });
|
|
1063
1114
|
|
|
1064
|
-
const result = instaml.transform(
|
|
1115
|
+
const result = instaml.transform(
|
|
1116
|
+
{ attrsStore: new AttrsStoreClass({}, null), schema },
|
|
1117
|
+
ops,
|
|
1118
|
+
);
|
|
1065
1119
|
|
|
1066
1120
|
expect(result).toEqual([
|
|
1067
1121
|
[
|
|
@@ -1145,7 +1199,10 @@ test('Schema: lookup creates unique attrs for lookups in link values with arrays
|
|
|
1145
1199
|
],
|
|
1146
1200
|
});
|
|
1147
1201
|
|
|
1148
|
-
const result = instaml.transform(
|
|
1202
|
+
const result = instaml.transform(
|
|
1203
|
+
{ attrsStore: new AttrsStoreClass({}, null), schema },
|
|
1204
|
+
ops,
|
|
1205
|
+
);
|
|
1149
1206
|
|
|
1150
1207
|
const expected = [
|
|
1151
1208
|
[
|
|
@@ -1241,7 +1298,10 @@ test('Schema: lookup creates unique ref attrs for ref lookup', () => {
|
|
|
1241
1298
|
uid,
|
|
1242
1299
|
];
|
|
1243
1300
|
|
|
1244
|
-
const result = instaml.transform(
|
|
1301
|
+
const result = instaml.transform(
|
|
1302
|
+
{ attrsStore: new AttrsStoreClass({}, null), schema },
|
|
1303
|
+
ops,
|
|
1304
|
+
);
|
|
1245
1305
|
const expected = [
|
|
1246
1306
|
[
|
|
1247
1307
|
'add-attr',
|
|
@@ -1324,7 +1384,10 @@ test('Schema: lookup creates unique ref attrs for ref lookup in link value', ()
|
|
|
1324
1384
|
uid,
|
|
1325
1385
|
];
|
|
1326
1386
|
|
|
1327
|
-
const result = instaml.transform(
|
|
1387
|
+
const result = instaml.transform(
|
|
1388
|
+
{ attrsStore: new AttrsStoreClass({}, null), schema },
|
|
1389
|
+
ops,
|
|
1390
|
+
);
|
|
1328
1391
|
|
|
1329
1392
|
const expected = [
|
|
1330
1393
|
[
|
|
@@ -1388,7 +1451,7 @@ test('Schema: populates checked-data-type', () => {
|
|
|
1388
1451
|
|
|
1389
1452
|
const result = instaml.transform(
|
|
1390
1453
|
{
|
|
1391
|
-
|
|
1454
|
+
attrsStore: zenecaAttrsStore,
|
|
1392
1455
|
schema: schema,
|
|
1393
1456
|
},
|
|
1394
1457
|
ops,
|
|
@@ -1501,6 +1564,7 @@ test('Schema: populates checked-data-type', () => {
|
|
|
1501
1564
|
test('instatx should not be too permissive', () => {
|
|
1502
1565
|
const ops = instatx.tx.books[uuid()].update({
|
|
1503
1566
|
title: 'New Title',
|
|
1567
|
+
// @ts-expect-error: testing invalid states
|
|
1504
1568
|
}).this_is_an_unknown_op;
|
|
1505
1569
|
expect(ops).toBeUndefined();
|
|
1506
1570
|
});
|