@instantdb/core 0.22.88 → 0.22.89-experimental.drewh-ssr.20277611943.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/serializeSchema.test.ts +123 -0
- package/__tests__/src/{store.test.js → store.test.ts} +215 -212
- package/dist/commonjs/Reactor.d.ts +36 -7
- package/dist/commonjs/Reactor.d.ts.map +1 -1
- package/dist/commonjs/Reactor.js +176 -47
- package/dist/commonjs/Reactor.js.map +1 -1
- package/dist/commonjs/SyncTable.d.ts +4 -1
- package/dist/commonjs/SyncTable.d.ts.map +1 -1
- package/dist/commonjs/SyncTable.js +35 -37
- package/dist/commonjs/SyncTable.js.map +1 -1
- package/dist/commonjs/createRouteHandler.d.ts +8 -0
- package/dist/commonjs/createRouteHandler.d.ts.map +1 -0
- package/dist/commonjs/createRouteHandler.js +57 -0
- package/dist/commonjs/createRouteHandler.js.map +1 -0
- package/dist/commonjs/framework.d.ts +77 -0
- package/dist/commonjs/framework.d.ts.map +1 -0
- package/dist/commonjs/framework.js +209 -0
- package/dist/commonjs/framework.js.map +1 -0
- package/dist/commonjs/index.d.ts +5 -1
- package/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/index.js +7 -1
- package/dist/commonjs/index.js.map +1 -1
- package/dist/commonjs/instaml.d.ts +17 -4
- package/dist/commonjs/instaml.d.ts.map +1 -1
- package/dist/commonjs/instaml.js +115 -82
- package/dist/commonjs/instaml.js.map +1 -1
- package/dist/commonjs/instaql.d.ts +4 -3
- package/dist/commonjs/instaql.d.ts.map +1 -1
- package/dist/commonjs/instaql.js +65 -63
- package/dist/commonjs/instaql.js.map +1 -1
- package/dist/commonjs/parseSchemaFromJSON.d.ts +3 -0
- package/dist/commonjs/parseSchemaFromJSON.d.ts.map +1 -0
- package/dist/commonjs/parseSchemaFromJSON.js +148 -0
- package/dist/commonjs/parseSchemaFromJSON.js.map +1 -0
- package/dist/commonjs/reactorTypes.d.ts +30 -0
- package/dist/commonjs/reactorTypes.d.ts.map +1 -0
- package/dist/commonjs/reactorTypes.js +3 -0
- package/dist/commonjs/reactorTypes.js.map +1 -0
- package/dist/commonjs/store.d.ts +67 -25
- package/dist/commonjs/store.d.ts.map +1 -1
- package/dist/commonjs/store.js +177 -81
- package/dist/commonjs/store.js.map +1 -1
- package/dist/esm/Reactor.d.ts +36 -7
- package/dist/esm/Reactor.d.ts.map +1 -1
- package/dist/esm/Reactor.js +177 -48
- package/dist/esm/Reactor.js.map +1 -1
- package/dist/esm/SyncTable.d.ts +4 -1
- package/dist/esm/SyncTable.d.ts.map +1 -1
- package/dist/esm/SyncTable.js +35 -37
- package/dist/esm/SyncTable.js.map +1 -1
- package/dist/esm/createRouteHandler.d.ts +8 -0
- package/dist/esm/createRouteHandler.d.ts.map +1 -0
- package/dist/esm/createRouteHandler.js +53 -0
- package/dist/esm/createRouteHandler.js.map +1 -0
- package/dist/esm/framework.d.ts +77 -0
- package/dist/esm/framework.d.ts.map +1 -0
- package/dist/esm/framework.js +169 -0
- package/dist/esm/framework.js.map +1 -0
- package/dist/esm/index.d.ts +5 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +5 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/instaml.d.ts +17 -4
- package/dist/esm/instaml.d.ts.map +1 -1
- package/dist/esm/instaml.js +112 -77
- package/dist/esm/instaml.js.map +1 -1
- package/dist/esm/instaql.d.ts +4 -3
- package/dist/esm/instaql.d.ts.map +1 -1
- package/dist/esm/instaql.js +65 -63
- package/dist/esm/instaql.js.map +1 -1
- package/dist/esm/parseSchemaFromJSON.d.ts +3 -0
- package/dist/esm/parseSchemaFromJSON.d.ts.map +1 -0
- package/dist/esm/parseSchemaFromJSON.js +144 -0
- package/dist/esm/parseSchemaFromJSON.js.map +1 -0
- package/dist/esm/reactorTypes.d.ts +30 -0
- package/dist/esm/reactorTypes.d.ts.map +1 -0
- package/dist/esm/reactorTypes.js +2 -0
- package/dist/esm/reactorTypes.js.map +1 -0
- package/dist/esm/store.d.ts +67 -25
- package/dist/esm/store.d.ts.map +1 -1
- package/dist/esm/store.js +174 -81
- package/dist/esm/store.js.map +1 -1
- package/dist/standalone/index.js +2899 -2389
- package/dist/standalone/index.umd.cjs +3 -3
- package/package.json +2 -2
- package/src/Reactor.js +232 -77
- package/src/SyncTable.ts +85 -45
- package/src/createRouteHandler.ts +44 -0
- package/src/framework.ts +294 -0
- package/src/index.ts +9 -0
- package/src/{instaml.js → instaml.ts} +201 -96
- package/src/instaql.ts +88 -62
- package/src/parseSchemaFromJSON.ts +176 -0
- package/src/reactorTypes.ts +33 -0
- package/src/store.ts +257 -101
- package/__tests__/src/instaql.bench.js +0 -29
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { test, expect } from 'vitest';
|
|
2
|
-
import { createStore } from '../../src/store';
|
|
2
|
+
import { createStore, AttrsStoreClass } from '../../src/store';
|
|
3
3
|
import query from '../../src/instaql';
|
|
4
4
|
import { i, id } from '../../src';
|
|
5
5
|
import { createLinkIndex } from '../../src/utils/linkIndex';
|
|
@@ -221,19 +221,23 @@ test('one-to-one without inference', () => {
|
|
|
221
221
|
expect(result.data.profiles.at(0).user.at(0).id).toBe(ids.user1);
|
|
222
222
|
});
|
|
223
223
|
|
|
224
|
-
function indexAttrs(attrs) {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
224
|
+
function indexAttrs(attrs, schema) {
|
|
225
|
+
const linkIndex = schema ? createLinkIndex(schema) : undefined;
|
|
226
|
+
return new AttrsStoreClass(
|
|
227
|
+
attrs.reduce((acc, attr) => {
|
|
228
|
+
acc[attr.id] = attr;
|
|
229
|
+
return acc;
|
|
230
|
+
}, {}),
|
|
231
|
+
linkIndex,
|
|
232
|
+
);
|
|
229
233
|
}
|
|
230
234
|
|
|
231
235
|
function queryData(config, attrs, triples, q) {
|
|
232
|
-
const
|
|
236
|
+
const attrsStore = indexAttrs(attrs, config.schema);
|
|
237
|
+
const store = createStore(attrsStore, triples);
|
|
233
238
|
store.cardinalityInference = config.cardinalityInference;
|
|
234
|
-
store.linkIndex = config.schema ? createLinkIndex(config.schema) : undefined;
|
|
235
239
|
|
|
236
|
-
const result = query({ store }, q);
|
|
240
|
+
const result = query({ store, attrsStore }, q);
|
|
237
241
|
|
|
238
242
|
return { result, store };
|
|
239
243
|
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { expect, test } from 'vitest';
|
|
2
|
+
import { i } from '../../src/schema';
|
|
3
|
+
import { parseSchemaFromJSON } from '../../src/parseSchemaFromJSON';
|
|
4
|
+
import { InstantSchemaDef } from '../../src/schemaTypes';
|
|
5
|
+
|
|
6
|
+
const schema = i.schema({
|
|
7
|
+
entities: {
|
|
8
|
+
users: i.entity({
|
|
9
|
+
name: i.string(),
|
|
10
|
+
email: i.string().indexed().unique(),
|
|
11
|
+
bio: i.string().optional(),
|
|
12
|
+
// this is a convenient way to typecheck custom JSON fields
|
|
13
|
+
// though we should probably have a backend solution for this
|
|
14
|
+
stuff: i.json<{ custom: string }>(),
|
|
15
|
+
junk: i.any(),
|
|
16
|
+
}),
|
|
17
|
+
posts: i.entity({
|
|
18
|
+
title: i.string().optional(),
|
|
19
|
+
body: i.string(),
|
|
20
|
+
}),
|
|
21
|
+
comments: i.entity({
|
|
22
|
+
body: i.string().indexed(),
|
|
23
|
+
likes: i.number(),
|
|
24
|
+
}),
|
|
25
|
+
|
|
26
|
+
birthdays: i.entity({
|
|
27
|
+
date: i.date(),
|
|
28
|
+
message: i.string(),
|
|
29
|
+
prizes: i.json<string | number>(),
|
|
30
|
+
}),
|
|
31
|
+
},
|
|
32
|
+
links: {
|
|
33
|
+
usersPosts: {
|
|
34
|
+
forward: {
|
|
35
|
+
on: 'users',
|
|
36
|
+
has: 'many',
|
|
37
|
+
label: 'posts',
|
|
38
|
+
},
|
|
39
|
+
reverse: {
|
|
40
|
+
on: 'posts',
|
|
41
|
+
has: 'one',
|
|
42
|
+
label: 'author',
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
postsComments: {
|
|
46
|
+
forward: {
|
|
47
|
+
on: 'posts',
|
|
48
|
+
has: 'many',
|
|
49
|
+
label: 'comments',
|
|
50
|
+
},
|
|
51
|
+
reverse: {
|
|
52
|
+
on: 'comments',
|
|
53
|
+
has: 'one',
|
|
54
|
+
label: 'post',
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
friendships: {
|
|
58
|
+
forward: {
|
|
59
|
+
on: 'users',
|
|
60
|
+
has: 'many',
|
|
61
|
+
label: 'friends',
|
|
62
|
+
},
|
|
63
|
+
reverse: {
|
|
64
|
+
on: 'users',
|
|
65
|
+
has: 'many',
|
|
66
|
+
label: '_friends',
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
referrals: {
|
|
70
|
+
forward: {
|
|
71
|
+
on: 'users',
|
|
72
|
+
has: 'many',
|
|
73
|
+
label: 'referred',
|
|
74
|
+
},
|
|
75
|
+
reverse: {
|
|
76
|
+
on: 'users',
|
|
77
|
+
has: 'one',
|
|
78
|
+
label: 'referrer',
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
rooms: {
|
|
83
|
+
chat: {
|
|
84
|
+
presence: i.entity({
|
|
85
|
+
name: i.string(),
|
|
86
|
+
status: i.string(),
|
|
87
|
+
}),
|
|
88
|
+
topics: {
|
|
89
|
+
sendEmoji: i.entity({
|
|
90
|
+
emoji: i.string(),
|
|
91
|
+
}),
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
type AnySchema = InstantSchemaDef<any, any, any>;
|
|
98
|
+
|
|
99
|
+
// compare schemas by stringifying them with json and comparing the strings
|
|
100
|
+
const compareSchemas = (schema1: AnySchema, schema2: AnySchema) => {
|
|
101
|
+
expect(JSON.stringify(schema1, null, 2)).toBe(
|
|
102
|
+
JSON.stringify(schema2, null, 2),
|
|
103
|
+
);
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
test('ability to parse stringified schema into real schema object', () => {
|
|
107
|
+
const stringified = JSON.stringify(schema, null, 2);
|
|
108
|
+
const parsed = JSON.parse(stringified);
|
|
109
|
+
console.log(stringified);
|
|
110
|
+
|
|
111
|
+
const otherSide = parseSchemaFromJSON(parsed);
|
|
112
|
+
|
|
113
|
+
compareSchemas(schema, otherSide);
|
|
114
|
+
|
|
115
|
+
expect(schema.entities.comments.links).toEqual(
|
|
116
|
+
otherSide.entities.comments.links,
|
|
117
|
+
);
|
|
118
|
+
expect(schema.entities.comments.asType).toEqual(
|
|
119
|
+
otherSide.entities.comments.asType,
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
expect(schema).toStrictEqual(otherSide);
|
|
123
|
+
});
|