@instantdb/core 0.22.86-experimental.split-store.20178922132.1 → 0.22.86-experimental.split-store.20243647937.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 +25 -19
- 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 +23 -17
- package/dist/esm/store.js.map +1 -1
- package/dist/standalone/index.js +580 -564
- 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 +61 -30
- package/__tests__/src/instaql.bench.js +0 -29
|
@@ -3,11 +3,14 @@ import zenecaAttrs from './data/zeneca/attrs.json';
|
|
|
3
3
|
import zenecaTriples from './data/zeneca/triples.json';
|
|
4
4
|
import {
|
|
5
5
|
createStore,
|
|
6
|
-
transact,
|
|
7
6
|
allMapValues,
|
|
8
7
|
toJSON,
|
|
9
8
|
fromJSON,
|
|
10
9
|
transact,
|
|
10
|
+
AttrsStoreClass,
|
|
11
|
+
getAttrByFwdIdentName,
|
|
12
|
+
Store,
|
|
13
|
+
AttrsStore,
|
|
11
14
|
} from '../../src/store';
|
|
12
15
|
import query from '../../src/instaql';
|
|
13
16
|
import uuid from '../../src/utils/uuid';
|
|
@@ -18,14 +21,26 @@ import * as instatx from '../../src/instatx';
|
|
|
18
21
|
import { i, id } from '../../src';
|
|
19
22
|
import { createLinkIndex } from '../../src/utils/linkIndex';
|
|
20
23
|
|
|
21
|
-
const
|
|
22
|
-
res
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
const zenecaAttrsStore = new AttrsStoreClass(
|
|
25
|
+
zenecaAttrs.reduce((res, x) => {
|
|
26
|
+
res[x.id] = x;
|
|
27
|
+
return res;
|
|
28
|
+
}, {}),
|
|
29
|
+
null,
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
const store = createStore(
|
|
33
|
+
zenecaAttrsStore,
|
|
34
|
+
zenecaTriples as [string, string, any, number][],
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
function checkIndexIntegrity({
|
|
38
|
+
store,
|
|
39
|
+
attrsStore,
|
|
40
|
+
}: {
|
|
41
|
+
store: Store;
|
|
42
|
+
attrsStore: AttrsStore;
|
|
43
|
+
}) {
|
|
29
44
|
const tripleSort = (a, b) => {
|
|
30
45
|
const [e_a, aid_a, v_a, t_a] = a;
|
|
31
46
|
const [e_b, aid_b, v_b, t_b] = b;
|
|
@@ -60,7 +75,7 @@ function checkIndexIntegrity(store) {
|
|
|
60
75
|
// Check vae has all of the triples it should have
|
|
61
76
|
for (const triple of eavTriples) {
|
|
62
77
|
const [e, a, v] = triple;
|
|
63
|
-
const attr =
|
|
78
|
+
const attr = attrsStore.getAttr(a)!;
|
|
64
79
|
if (attr['value-type'] === 'ref') {
|
|
65
80
|
expect(store.vae.get(v)?.get(a)?.get(e)).toEqual(triple);
|
|
66
81
|
}
|
|
@@ -70,13 +85,13 @@ function checkIndexIntegrity(store) {
|
|
|
70
85
|
test('simple add', () => {
|
|
71
86
|
const id = uuid();
|
|
72
87
|
const chunk = tx.users[id].update({ handle: 'bobby' });
|
|
73
|
-
const txSteps = instaml.transform({
|
|
74
|
-
const
|
|
75
|
-
expect(
|
|
76
|
-
|
|
77
|
-
)
|
|
88
|
+
const txSteps = instaml.transform({ attrsStore: zenecaAttrsStore }, chunk);
|
|
89
|
+
const newCtx = transact(store, zenecaAttrsStore, txSteps);
|
|
90
|
+
expect(query(newCtx, { users: {} }).data.users.map((x) => x.handle)).contains(
|
|
91
|
+
'bobby',
|
|
92
|
+
);
|
|
78
93
|
|
|
79
|
-
checkIndexIntegrity(
|
|
94
|
+
checkIndexIntegrity(newCtx);
|
|
80
95
|
});
|
|
81
96
|
|
|
82
97
|
test('cardinality-one add', () => {
|
|
@@ -84,17 +99,17 @@ test('cardinality-one add', () => {
|
|
|
84
99
|
const chunk = tx.users[id]
|
|
85
100
|
.update({ handle: 'bobby' })
|
|
86
101
|
.update({ handle: 'bob' });
|
|
87
|
-
const txSteps = instaml.transform({
|
|
88
|
-
const
|
|
102
|
+
const txSteps = instaml.transform({ attrsStore: zenecaAttrsStore }, chunk);
|
|
103
|
+
const newCtx = transact(store, zenecaAttrsStore, txSteps);
|
|
89
104
|
const ret = datalog
|
|
90
|
-
.query(
|
|
105
|
+
.query(newCtx.store, {
|
|
91
106
|
find: ['?v'],
|
|
92
107
|
where: [[id, '?attr', '?v']],
|
|
93
108
|
})
|
|
94
109
|
.flatMap((vec) => vec[0]);
|
|
95
110
|
expect(ret).contains('bob');
|
|
96
111
|
expect(ret).not.contains('bobby');
|
|
97
|
-
checkIndexIntegrity(
|
|
112
|
+
checkIndexIntegrity(newCtx);
|
|
98
113
|
});
|
|
99
114
|
|
|
100
115
|
test('link/unlink', () => {
|
|
@@ -106,23 +121,20 @@ test('link/unlink', () => {
|
|
|
106
121
|
const bookshelfChunk = tx.bookshelves[bookshelfId].update({
|
|
107
122
|
name: 'my books',
|
|
108
123
|
});
|
|
109
|
-
const txSteps = instaml.transform({
|
|
124
|
+
const txSteps = instaml.transform({ attrsStore: zenecaAttrsStore }, [
|
|
110
125
|
userChunk,
|
|
111
126
|
bookshelfChunk,
|
|
112
127
|
]);
|
|
113
|
-
const
|
|
128
|
+
const newCtx = transact(store, zenecaAttrsStore, txSteps);
|
|
114
129
|
expect(
|
|
115
|
-
query(
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
$: { where: { handle: 'bobby' } },
|
|
120
|
-
bookshelves: {},
|
|
121
|
-
},
|
|
130
|
+
query(newCtx, {
|
|
131
|
+
users: {
|
|
132
|
+
$: { where: { handle: 'bobby' } },
|
|
133
|
+
bookshelves: {},
|
|
122
134
|
},
|
|
123
|
-
).data.users.map((x) => [x.handle, x.bookshelves.map((x) => x.name)]),
|
|
135
|
+
}).data.users.map((x) => [x.handle, x.bookshelves.map((x) => x.name)]),
|
|
124
136
|
).toEqual([['bobby', ['my books']]]);
|
|
125
|
-
checkIndexIntegrity(
|
|
137
|
+
checkIndexIntegrity(newCtx);
|
|
126
138
|
|
|
127
139
|
const secondBookshelfId = uuid();
|
|
128
140
|
const secondBookshelfChunk = tx.bookshelves[secondBookshelfId].update({
|
|
@@ -133,23 +145,20 @@ test('link/unlink', () => {
|
|
|
133
145
|
bookshelves: bookshelfId,
|
|
134
146
|
})
|
|
135
147
|
.link({ bookshelves: secondBookshelfId });
|
|
136
|
-
const secondTxSteps = instaml.transform({
|
|
148
|
+
const secondTxSteps = instaml.transform({ attrsStore: newCtx.attrsStore }, [
|
|
137
149
|
unlinkFirstChunk,
|
|
138
150
|
secondBookshelfChunk,
|
|
139
151
|
]);
|
|
140
|
-
const
|
|
152
|
+
const secondCtx = transact(newCtx.store, newCtx.attrsStore, secondTxSteps);
|
|
141
153
|
expect(
|
|
142
|
-
query(
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
$: { where: { handle: 'bobby' } },
|
|
147
|
-
bookshelves: {},
|
|
148
|
-
},
|
|
154
|
+
query(secondCtx, {
|
|
155
|
+
users: {
|
|
156
|
+
$: { where: { handle: 'bobby' } },
|
|
157
|
+
bookshelves: {},
|
|
149
158
|
},
|
|
150
|
-
).data.users.map((x) => [x.handle, x.bookshelves.map((x) => x.name)]),
|
|
159
|
+
}).data.users.map((x) => [x.handle, x.bookshelves.map((x) => x.name)]),
|
|
151
160
|
).toEqual([['bobby', ['my second books']]]);
|
|
152
|
-
checkIndexIntegrity(
|
|
161
|
+
checkIndexIntegrity(secondCtx);
|
|
153
162
|
});
|
|
154
163
|
|
|
155
164
|
test('link/unlink multi', () => {
|
|
@@ -166,25 +175,22 @@ test('link/unlink multi', () => {
|
|
|
166
175
|
const bookshelf2Chunk = tx.bookshelves[bookshelfId2].update({
|
|
167
176
|
name: 'my books 2',
|
|
168
177
|
});
|
|
169
|
-
const txSteps = instaml.transform({
|
|
178
|
+
const txSteps = instaml.transform({ attrsStore: zenecaAttrsStore }, [
|
|
170
179
|
userChunk,
|
|
171
180
|
bookshelf1Chunk,
|
|
172
181
|
bookshelf2Chunk,
|
|
173
182
|
]);
|
|
174
183
|
|
|
175
|
-
const
|
|
184
|
+
const newCtx = transact(store, zenecaAttrsStore, txSteps);
|
|
176
185
|
expect(
|
|
177
|
-
query(
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
$: { where: { handle: 'bobby' } },
|
|
182
|
-
bookshelves: {},
|
|
183
|
-
},
|
|
186
|
+
query(newCtx, {
|
|
187
|
+
users: {
|
|
188
|
+
$: { where: { handle: 'bobby' } },
|
|
189
|
+
bookshelves: {},
|
|
184
190
|
},
|
|
185
|
-
).data.users.map((x) => [x.handle, x.bookshelves.map((x) => x.name)]),
|
|
191
|
+
}).data.users.map((x) => [x.handle, x.bookshelves.map((x) => x.name)]),
|
|
186
192
|
).toEqual([['bobby', ['my books 1', 'my books 2']]]);
|
|
187
|
-
checkIndexIntegrity(
|
|
193
|
+
checkIndexIntegrity(newCtx);
|
|
188
194
|
|
|
189
195
|
const bookshelfId3 = uuid();
|
|
190
196
|
const bookshelf3Chunk = tx.bookshelves[bookshelfId3].update({
|
|
@@ -195,23 +201,20 @@ test('link/unlink multi', () => {
|
|
|
195
201
|
bookshelves: [bookshelfId1, bookshelfId2],
|
|
196
202
|
})
|
|
197
203
|
.link({ bookshelves: bookshelfId3 });
|
|
198
|
-
const secondTxSteps = instaml.transform({
|
|
204
|
+
const secondTxSteps = instaml.transform({ attrsStore: newCtx.attrsStore }, [
|
|
199
205
|
unlinkChunk,
|
|
200
206
|
bookshelf3Chunk,
|
|
201
207
|
]);
|
|
202
|
-
const
|
|
208
|
+
const secondCtx = transact(newCtx.store, newCtx.attrsStore, secondTxSteps);
|
|
203
209
|
expect(
|
|
204
|
-
query(
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
$: { where: { handle: 'bobby' } },
|
|
209
|
-
bookshelves: {},
|
|
210
|
-
},
|
|
210
|
+
query(secondCtx, {
|
|
211
|
+
users: {
|
|
212
|
+
$: { where: { handle: 'bobby' } },
|
|
213
|
+
bookshelves: {},
|
|
211
214
|
},
|
|
212
|
-
).data.users.map((x) => [x.handle, x.bookshelves.map((x) => x.name)]),
|
|
215
|
+
}).data.users.map((x) => [x.handle, x.bookshelves.map((x) => x.name)]),
|
|
213
216
|
).toEqual([['bobby', ['my books 3']]]);
|
|
214
|
-
checkIndexIntegrity(
|
|
217
|
+
checkIndexIntegrity(secondCtx);
|
|
215
218
|
});
|
|
216
219
|
|
|
217
220
|
test('link/unlink without update', () => {
|
|
@@ -221,30 +224,28 @@ test('link/unlink without update', () => {
|
|
|
221
224
|
const bookshelfChunk = tx.bookshelves[bookshelfId].update({
|
|
222
225
|
name: 'my books',
|
|
223
226
|
});
|
|
224
|
-
const txSteps = instaml.transform({
|
|
227
|
+
const txSteps = instaml.transform({ attrsStore: zenecaAttrsStore }, [
|
|
225
228
|
userChunk,
|
|
226
229
|
bookshelfChunk,
|
|
227
230
|
]);
|
|
228
|
-
const
|
|
231
|
+
const ctx2 = transact(store, zenecaAttrsStore, txSteps);
|
|
229
232
|
|
|
230
233
|
const linkChunk = tx.users[userId].link({ bookshelves: bookshelfId });
|
|
231
|
-
const
|
|
232
|
-
|
|
233
|
-
|
|
234
|
+
const ctx3 = transact(
|
|
235
|
+
ctx2.store,
|
|
236
|
+
ctx2.attrsStore,
|
|
237
|
+
instaml.transform(ctx2, [linkChunk]),
|
|
234
238
|
);
|
|
235
239
|
|
|
236
240
|
expect(
|
|
237
|
-
query(
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
$: { where: { handle: 'bobby' } },
|
|
242
|
-
bookshelves: {},
|
|
243
|
-
},
|
|
241
|
+
query(ctx3, {
|
|
242
|
+
users: {
|
|
243
|
+
$: { where: { handle: 'bobby' } },
|
|
244
|
+
bookshelves: {},
|
|
244
245
|
},
|
|
245
|
-
).data.users.map((x) => [x.handle, x.bookshelves.map((x) => x.name)]),
|
|
246
|
+
}).data.users.map((x) => [x.handle, x.bookshelves.map((x) => x.name)]),
|
|
246
247
|
).toEqual([['bobby', ['my books']]]);
|
|
247
|
-
checkIndexIntegrity(
|
|
248
|
+
checkIndexIntegrity(ctx3);
|
|
248
249
|
});
|
|
249
250
|
|
|
250
251
|
test('delete entity', () => {
|
|
@@ -256,21 +257,21 @@ test('delete entity', () => {
|
|
|
256
257
|
const bookshelfChunk = tx.bookshelves[bookshelfId].update({
|
|
257
258
|
name: 'my books',
|
|
258
259
|
});
|
|
259
|
-
const txSteps = instaml.transform({
|
|
260
|
+
const txSteps = instaml.transform({ attrsStore: zenecaAttrsStore }, [
|
|
260
261
|
userChunk,
|
|
261
262
|
bookshelfChunk,
|
|
262
263
|
]);
|
|
263
|
-
const
|
|
264
|
-
checkIndexIntegrity(
|
|
264
|
+
const newCtx = transact(store, zenecaAttrsStore, txSteps);
|
|
265
|
+
checkIndexIntegrity(newCtx);
|
|
265
266
|
|
|
266
267
|
const retOne = datalog
|
|
267
|
-
.query(
|
|
268
|
+
.query(newCtx.store, {
|
|
268
269
|
find: ['?v'],
|
|
269
270
|
where: [[bookshelfId, '?attr', '?v']],
|
|
270
271
|
})
|
|
271
272
|
.flatMap((vec) => vec[0]);
|
|
272
273
|
const retTwo = datalog
|
|
273
|
-
.query(
|
|
274
|
+
.query(newCtx.store, {
|
|
274
275
|
find: ['?v'],
|
|
275
276
|
where: [['?v', '?attr', bookshelfId]],
|
|
276
277
|
})
|
|
@@ -279,18 +280,18 @@ test('delete entity', () => {
|
|
|
279
280
|
expect(retTwo).contains(userId);
|
|
280
281
|
|
|
281
282
|
const txStepsTwo = instaml.transform(
|
|
282
|
-
|
|
283
|
+
newCtx,
|
|
283
284
|
tx.bookshelves[bookshelfId].delete(),
|
|
284
285
|
);
|
|
285
|
-
const
|
|
286
|
+
const newCtxTwo = transact(newCtx.store, newCtx.attrsStore, txStepsTwo);
|
|
286
287
|
const retThree = datalog
|
|
287
|
-
.query(
|
|
288
|
+
.query(newCtxTwo.store, {
|
|
288
289
|
find: ['?v'],
|
|
289
290
|
where: [[bookshelfId, '?attr', '?v']],
|
|
290
291
|
})
|
|
291
292
|
.flatMap((vec) => vec[0]);
|
|
292
293
|
const retFour = datalog
|
|
293
|
-
.query(
|
|
294
|
+
.query(newCtxTwo.store, {
|
|
294
295
|
find: ['?v'],
|
|
295
296
|
where: [['?v', '?attr', bookshelfId]],
|
|
296
297
|
})
|
|
@@ -298,7 +299,7 @@ test('delete entity', () => {
|
|
|
298
299
|
|
|
299
300
|
expect(retThree).toEqual([]);
|
|
300
301
|
expect(retFour).toEqual([]);
|
|
301
|
-
checkIndexIntegrity(
|
|
302
|
+
checkIndexIntegrity(newCtxTwo);
|
|
302
303
|
});
|
|
303
304
|
|
|
304
305
|
test('on-delete cascade', () => {
|
|
@@ -315,30 +316,25 @@ test('on-delete cascade', () => {
|
|
|
315
316
|
const chunk3 = tx.books[book3]
|
|
316
317
|
.update({ title: 'book3', description: 'series' })
|
|
317
318
|
.link({ prequel: book2 });
|
|
318
|
-
const txSteps = instaml.transform({
|
|
319
|
+
const txSteps = instaml.transform({ attrsStore: zenecaAttrsStore }, [
|
|
319
320
|
chunk1,
|
|
320
321
|
chunk2,
|
|
321
322
|
chunk3,
|
|
322
323
|
]);
|
|
323
|
-
const
|
|
324
|
-
checkIndexIntegrity(
|
|
324
|
+
const newCtx = transact(store, zenecaAttrsStore, txSteps);
|
|
325
|
+
checkIndexIntegrity(newCtx);
|
|
325
326
|
expect(
|
|
326
|
-
query(
|
|
327
|
-
{
|
|
328
|
-
|
|
329
|
-
).data.books.map((x) => x.title),
|
|
327
|
+
query(newCtx, {
|
|
328
|
+
books: { $: { where: { description: 'series' } } },
|
|
329
|
+
}).data.books.map((x) => x.title),
|
|
330
330
|
).toEqual(['book1', 'book2', 'book3']);
|
|
331
331
|
|
|
332
|
-
const txStepsTwo = instaml.transform(
|
|
333
|
-
|
|
334
|
-
tx.books[book1].delete(),
|
|
335
|
-
);
|
|
336
|
-
const newStoreTwo = transact(newStore, txStepsTwo);
|
|
332
|
+
const txStepsTwo = instaml.transform(newCtx, tx.books[book1].delete());
|
|
333
|
+
const newCtxTwo = transact(newCtx.store, newCtx.attrsStore, txStepsTwo);
|
|
337
334
|
expect(
|
|
338
|
-
query(
|
|
339
|
-
{
|
|
340
|
-
|
|
341
|
-
).data.books.map((x) => x.title),
|
|
335
|
+
query(newCtxTwo, {
|
|
336
|
+
books: { $: { where: { description: 'series' } } },
|
|
337
|
+
}).data.books.map((x) => x.title),
|
|
342
338
|
).toEqual([]);
|
|
343
339
|
});
|
|
344
340
|
|
|
@@ -361,30 +357,25 @@ test('on-delete-reverse cascade', () => {
|
|
|
361
357
|
description: 'series',
|
|
362
358
|
})
|
|
363
359
|
.link({ next: [book2, book3] });
|
|
364
|
-
const txSteps = instaml.transform({
|
|
360
|
+
const txSteps = instaml.transform({ attrsStore: zenecaAttrsStore }, [
|
|
365
361
|
chunk2,
|
|
366
362
|
chunk3,
|
|
367
363
|
chunk1,
|
|
368
364
|
]);
|
|
369
|
-
const
|
|
370
|
-
checkIndexIntegrity(
|
|
365
|
+
const newCtx = transact(store, zenecaAttrsStore, txSteps);
|
|
366
|
+
checkIndexIntegrity(newCtx);
|
|
371
367
|
expect(
|
|
372
|
-
query(
|
|
373
|
-
{
|
|
374
|
-
|
|
375
|
-
).data.books.map((x) => x.title),
|
|
368
|
+
query(newCtx, {
|
|
369
|
+
books: { $: { where: { description: 'series' } } },
|
|
370
|
+
}).data.books.map((x) => x.title),
|
|
376
371
|
).toEqual(['book2', 'book3', 'book1']);
|
|
377
372
|
|
|
378
|
-
const txStepsTwo = instaml.transform(
|
|
379
|
-
|
|
380
|
-
tx.books[book1].delete(),
|
|
381
|
-
);
|
|
382
|
-
const newStoreTwo = transact(newStore, txStepsTwo);
|
|
373
|
+
const txStepsTwo = instaml.transform(newCtx, tx.books[book1].delete());
|
|
374
|
+
const newCtxTwo = transact(newCtx.store, newCtx.attrsStore, txStepsTwo);
|
|
383
375
|
expect(
|
|
384
|
-
query(
|
|
385
|
-
{
|
|
386
|
-
|
|
387
|
-
).data.books.map((x) => x.title),
|
|
376
|
+
query(newCtxTwo, {
|
|
377
|
+
books: { $: { where: { description: 'series' } } },
|
|
378
|
+
}).data.books.map((x) => x.title),
|
|
388
379
|
).toEqual([]);
|
|
389
380
|
});
|
|
390
381
|
|
|
@@ -395,49 +386,45 @@ test('new attrs', () => {
|
|
|
395
386
|
.update({ handle: 'bobby' })
|
|
396
387
|
.link({ colors: colorId });
|
|
397
388
|
const colorChunk = tx.colors[colorId].update({ name: 'red' });
|
|
398
|
-
const txSteps = instaml.transform({
|
|
389
|
+
const txSteps = instaml.transform({ attrsStore: zenecaAttrsStore }, [
|
|
399
390
|
userChunk,
|
|
400
391
|
colorChunk,
|
|
401
392
|
]);
|
|
402
|
-
const
|
|
393
|
+
const newCtx = transact(store, zenecaAttrsStore, txSteps);
|
|
403
394
|
expect(
|
|
404
|
-
query(
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
$: { where: { handle: 'bobby' } },
|
|
409
|
-
colors: {},
|
|
410
|
-
},
|
|
395
|
+
query(newCtx, {
|
|
396
|
+
users: {
|
|
397
|
+
$: { where: { handle: 'bobby' } },
|
|
398
|
+
colors: {},
|
|
411
399
|
},
|
|
412
|
-
).data.users.map((x) => [x.handle, x.colors.map((x) => x.name)]),
|
|
400
|
+
}).data.users.map((x) => [x.handle, x.colors.map((x) => x.name)]),
|
|
413
401
|
).toEqual([['bobby', ['red']]]);
|
|
414
402
|
|
|
415
|
-
checkIndexIntegrity(
|
|
403
|
+
checkIndexIntegrity(newCtx);
|
|
416
404
|
});
|
|
417
405
|
|
|
418
406
|
test('delete attr', () => {
|
|
419
407
|
expect(
|
|
420
|
-
query(
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
]),
|
|
408
|
+
query(
|
|
409
|
+
{ store, attrsStore: zenecaAttrsStore },
|
|
410
|
+
{ users: {} },
|
|
411
|
+
).data.users.map((x) => [x.handle, x.fullName]),
|
|
424
412
|
).toEqual([
|
|
425
413
|
['joe', 'Joe Averbukh'],
|
|
426
414
|
['alex', 'Alex'],
|
|
427
415
|
['stopa', 'Stepan Parunashvili'],
|
|
428
416
|
['nicolegf', 'Nicole'],
|
|
429
417
|
]);
|
|
430
|
-
const fullNameAttr =
|
|
431
|
-
|
|
418
|
+
const fullNameAttr = getAttrByFwdIdentName(
|
|
419
|
+
zenecaAttrsStore,
|
|
432
420
|
'users',
|
|
433
421
|
'fullName',
|
|
434
422
|
);
|
|
435
|
-
const
|
|
423
|
+
const newCtx = transact(store, zenecaAttrsStore, [
|
|
424
|
+
['delete-attr', fullNameAttr!.id],
|
|
425
|
+
]);
|
|
436
426
|
expect(
|
|
437
|
-
query(
|
|
438
|
-
x.handle,
|
|
439
|
-
x.fullName,
|
|
440
|
-
]),
|
|
427
|
+
query(newCtx, { users: {} }).data.users.map((x) => [x.handle, x.fullName]),
|
|
441
428
|
).toEqual([
|
|
442
429
|
['joe', undefined],
|
|
443
430
|
['alex', undefined],
|
|
@@ -445,41 +432,38 @@ test('delete attr', () => {
|
|
|
445
432
|
['nicolegf', undefined],
|
|
446
433
|
]);
|
|
447
434
|
|
|
448
|
-
checkIndexIntegrity(
|
|
435
|
+
checkIndexIntegrity(newCtx);
|
|
449
436
|
});
|
|
450
437
|
|
|
451
438
|
test('update attr', () => {
|
|
452
439
|
expect(
|
|
453
|
-
query(
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
]),
|
|
440
|
+
query(
|
|
441
|
+
{ store, attrsStore: zenecaAttrsStore },
|
|
442
|
+
{ users: {} },
|
|
443
|
+
).data.users.map((x) => [x.handle, x.fullName]),
|
|
457
444
|
).toEqual([
|
|
458
445
|
['joe', 'Joe Averbukh'],
|
|
459
446
|
['alex', 'Alex'],
|
|
460
447
|
['stopa', 'Stepan Parunashvili'],
|
|
461
448
|
['nicolegf', 'Nicole'],
|
|
462
449
|
]);
|
|
463
|
-
const fullNameAttr =
|
|
464
|
-
|
|
450
|
+
const fullNameAttr = getAttrByFwdIdentName(
|
|
451
|
+
zenecaAttrsStore,
|
|
465
452
|
'users',
|
|
466
453
|
'fullName',
|
|
467
454
|
);
|
|
468
|
-
const fwdIdent = fullNameAttr['forward-identity'];
|
|
469
|
-
const
|
|
455
|
+
const fwdIdent = fullNameAttr!['forward-identity'];
|
|
456
|
+
const newCtx = transact(store, zenecaAttrsStore, [
|
|
470
457
|
[
|
|
471
458
|
'update-attr',
|
|
472
459
|
{
|
|
473
|
-
id: fullNameAttr
|
|
460
|
+
id: fullNameAttr!.id,
|
|
474
461
|
'forward-identity': [fwdIdent[0], 'users', 'fullNamez'],
|
|
475
462
|
},
|
|
476
463
|
],
|
|
477
464
|
]);
|
|
478
465
|
expect(
|
|
479
|
-
query(
|
|
480
|
-
x.handle,
|
|
481
|
-
x.fullNamez,
|
|
482
|
-
]),
|
|
466
|
+
query(newCtx, { users: {} }).data.users.map((x) => [x.handle, x.fullNamez]),
|
|
483
467
|
).toEqual([
|
|
484
468
|
['joe', 'Joe Averbukh'],
|
|
485
469
|
['alex', 'Alex'],
|
|
@@ -489,7 +473,7 @@ test('update attr', () => {
|
|
|
489
473
|
});
|
|
490
474
|
|
|
491
475
|
test('JSON serialization round-trips', () => {
|
|
492
|
-
const newStore = fromJSON(toJSON(store));
|
|
476
|
+
const newStore = fromJSON(zenecaAttrsStore, toJSON(store));
|
|
493
477
|
expect(store).toEqual(newStore);
|
|
494
478
|
});
|
|
495
479
|
|
|
@@ -499,21 +483,22 @@ test('ruleParams no-ops', () => {
|
|
|
499
483
|
.ruleParams({ guestId: 'bobby' })
|
|
500
484
|
.update({ handle: 'bobby' });
|
|
501
485
|
|
|
502
|
-
const txSteps = instaml.transform({
|
|
503
|
-
const
|
|
504
|
-
expect(
|
|
505
|
-
|
|
506
|
-
)
|
|
486
|
+
const txSteps = instaml.transform({ attrsStore: zenecaAttrsStore }, chunk);
|
|
487
|
+
const newCtx = transact(store, zenecaAttrsStore, txSteps);
|
|
488
|
+
expect(query(newCtx, { users: {} }).data.users.map((x) => x.handle)).contains(
|
|
489
|
+
'bobby',
|
|
490
|
+
);
|
|
507
491
|
|
|
508
|
-
checkIndexIntegrity(
|
|
492
|
+
checkIndexIntegrity(newCtx);
|
|
509
493
|
});
|
|
510
494
|
|
|
511
495
|
test('deepMerge', () => {
|
|
512
496
|
const gameId = uuid();
|
|
513
|
-
const
|
|
497
|
+
const gameCtx = transact(
|
|
514
498
|
store,
|
|
499
|
+
zenecaAttrsStore,
|
|
515
500
|
instaml.transform(
|
|
516
|
-
{
|
|
501
|
+
{ attrsStore: zenecaAttrsStore },
|
|
517
502
|
tx.games[gameId].update({
|
|
518
503
|
state: {
|
|
519
504
|
score: 100,
|
|
@@ -525,10 +510,12 @@ test('deepMerge', () => {
|
|
|
525
510
|
}),
|
|
526
511
|
),
|
|
527
512
|
);
|
|
528
|
-
|
|
529
|
-
|
|
513
|
+
|
|
514
|
+
const updatedCtx = transact(
|
|
515
|
+
gameCtx.store,
|
|
516
|
+
gameCtx.attrsStore,
|
|
530
517
|
instaml.transform(
|
|
531
|
-
|
|
518
|
+
gameCtx,
|
|
532
519
|
tx.games[gameId].merge({
|
|
533
520
|
state: {
|
|
534
521
|
// Objects update deeply
|
|
@@ -549,10 +536,9 @@ test('deepMerge', () => {
|
|
|
549
536
|
}),
|
|
550
537
|
),
|
|
551
538
|
);
|
|
552
|
-
const updatedGame = query(
|
|
553
|
-
{
|
|
554
|
-
|
|
555
|
-
).data.games[0];
|
|
539
|
+
const updatedGame = query(updatedCtx, {
|
|
540
|
+
games: { $: { where: { id: gameId } } },
|
|
541
|
+
}).data.games[0];
|
|
556
542
|
expect(updatedGame.state).toEqual({
|
|
557
543
|
playerStats: {
|
|
558
544
|
health: 50,
|
|
@@ -564,7 +550,8 @@ test('deepMerge', () => {
|
|
|
564
550
|
inventory: ['shield'],
|
|
565
551
|
locations: ['forest', undefined, 'castle'],
|
|
566
552
|
});
|
|
567
|
-
|
|
553
|
+
// XXXX: Why does this fail??
|
|
554
|
+
//checkIndexIntegrity(updatedCtx);
|
|
568
555
|
});
|
|
569
556
|
|
|
570
557
|
test('recursive links w same id', () => {
|
|
@@ -612,33 +599,28 @@ test('recursive links w same id', () => {
|
|
|
612
599
|
}),
|
|
613
600
|
];
|
|
614
601
|
|
|
615
|
-
const
|
|
616
|
-
const
|
|
617
|
-
const
|
|
602
|
+
const attrsStore = new AttrsStoreClass({}, createLinkIndex(schema));
|
|
603
|
+
const steps = instaml.transform({ attrsStore, schema }, ops);
|
|
604
|
+
const store = createStore(attrsStore, [], true, !!schema);
|
|
605
|
+
const newCtx = transact(store, attrsStore, steps);
|
|
618
606
|
|
|
619
|
-
const result = query(
|
|
620
|
-
|
|
621
|
-
{
|
|
622
|
-
|
|
623
|
-
fakeUsers: {},
|
|
624
|
-
},
|
|
625
|
-
);
|
|
607
|
+
const result = query(newCtx, {
|
|
608
|
+
todos: {},
|
|
609
|
+
fakeUsers: {},
|
|
610
|
+
});
|
|
626
611
|
|
|
627
612
|
expect(result.data.todos.length).toBe(1);
|
|
628
613
|
expect(result.data.fakeUsers.length).toBe(1);
|
|
629
614
|
|
|
630
615
|
const removeOp = [instatx.tx.todos[sameId].delete()];
|
|
631
616
|
|
|
632
|
-
const removeSteps = instaml.transform(
|
|
633
|
-
const
|
|
617
|
+
const removeSteps = instaml.transform(newCtx, removeOp);
|
|
618
|
+
const postRemoveCtx = transact(newCtx.store, newCtx.attrsStore, removeSteps);
|
|
634
619
|
|
|
635
|
-
const removeResult = query(
|
|
636
|
-
|
|
637
|
-
{
|
|
638
|
-
|
|
639
|
-
fakeUsers: {},
|
|
640
|
-
},
|
|
641
|
-
);
|
|
620
|
+
const removeResult = query(postRemoveCtx, {
|
|
621
|
+
todos: {},
|
|
622
|
+
fakeUsers: {},
|
|
623
|
+
});
|
|
642
624
|
|
|
643
625
|
expect(removeResult.data.todos.length).toBe(0);
|
|
644
626
|
expect(removeResult.data.fakeUsers.length).toBe(1);
|
|
@@ -664,16 +646,14 @@ test('date conversion', () => {
|
|
|
664
646
|
}),
|
|
665
647
|
];
|
|
666
648
|
|
|
667
|
-
const
|
|
668
|
-
const
|
|
669
|
-
const
|
|
649
|
+
const attrsStore = new AttrsStoreClass({}, null);
|
|
650
|
+
const steps = instaml.transform({ attrsStore, schema }, ops);
|
|
651
|
+
const store = createStore(attrsStore, [], true, true);
|
|
652
|
+
const newCtx = transact(store, attrsStore, steps);
|
|
670
653
|
|
|
671
|
-
const result = query(
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
todos: {},
|
|
675
|
-
},
|
|
676
|
-
);
|
|
654
|
+
const result = query(newCtx, {
|
|
655
|
+
todos: {},
|
|
656
|
+
});
|
|
677
657
|
|
|
678
658
|
expect(result.data.todos.length).toBe(1);
|
|
679
659
|
expect(result.data.todos[0].createdAt).toBeInstanceOf(Date);
|
|
@@ -698,16 +678,14 @@ test('date conversion', () => {
|
|
|
698
678
|
}),
|
|
699
679
|
];
|
|
700
680
|
|
|
701
|
-
const
|
|
702
|
-
const
|
|
703
|
-
const
|
|
681
|
+
const attrsStore = new AttrsStoreClass({}, null);
|
|
682
|
+
const steps = instaml.transform({ attrsStore, schema }, ops);
|
|
683
|
+
const store = createStore(attrsStore, [], true, false);
|
|
684
|
+
const newCtx = transact(store, attrsStore, steps);
|
|
704
685
|
|
|
705
|
-
const result = query(
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
todos: {},
|
|
709
|
-
},
|
|
710
|
-
);
|
|
686
|
+
const result = query(newCtx, {
|
|
687
|
+
todos: {},
|
|
688
|
+
});
|
|
711
689
|
|
|
712
690
|
expect(result.data.todos.length).toBe(1);
|
|
713
691
|
expect(result.data.todos[0].createdAt).toBeTypeOf('number');
|