@instantdb/core 0.22.89 → 0.22.90-experimental.drewh-ssr.20286580593.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 +1 -1
- package/__tests__/src/instaml.test.ts +1 -1
- package/__tests__/src/serializeSchema.test.ts +123 -0
- package/__tests__/src/store.test.ts +1 -1
- package/__tests__/src/transactionValidation.test.ts +1 -1
- package/dist/commonjs/Reactor.d.ts +13 -1
- package/dist/commonjs/Reactor.d.ts.map +1 -1
- package/dist/commonjs/Reactor.js +79 -15
- package/dist/commonjs/Reactor.js.map +1 -1
- package/dist/commonjs/SyncTable.js +3 -3
- 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 +6 -2
- package/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/index.js +9 -3
- package/dist/commonjs/index.js.map +1 -1
- package/dist/commonjs/instaml.js +8 -8
- package/dist/commonjs/instaml.js.map +1 -1
- package/dist/commonjs/instaql.js +2 -2
- 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 +5 -4
- package/dist/commonjs/reactorTypes.d.ts.map +1 -1
- package/dist/commonjs/reactorTypes.js.map +1 -1
- package/dist/commonjs/utils/{uuid.d.ts → id.d.ts} +1 -1
- package/dist/commonjs/utils/id.d.ts.map +1 -0
- package/dist/commonjs/utils/{uuid.js → id.js} +1 -1
- package/dist/commonjs/utils/id.js.map +1 -0
- package/dist/esm/Reactor.d.ts +13 -1
- package/dist/esm/Reactor.d.ts.map +1 -1
- package/dist/esm/Reactor.js +70 -6
- package/dist/esm/Reactor.js.map +1 -1
- package/dist/esm/SyncTable.js +1 -1
- 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 +6 -2
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +6 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/instaml.js +1 -1
- package/dist/esm/instaml.js.map +1 -1
- package/dist/esm/instaql.js +1 -1
- 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 +5 -4
- package/dist/esm/reactorTypes.d.ts.map +1 -1
- package/dist/esm/reactorTypes.js.map +1 -1
- package/dist/esm/utils/{uuid.d.ts → id.d.ts} +1 -1
- package/dist/esm/utils/id.d.ts.map +1 -0
- package/dist/esm/utils/{uuid.js → id.js} +1 -1
- package/dist/esm/utils/id.js.map +1 -0
- package/dist/standalone/index.js +2697 -2377
- package/dist/standalone/index.umd.cjs +3 -3
- package/package.json +2 -2
- package/src/Reactor.js +85 -7
- package/src/SyncTable.ts +1 -1
- package/src/createRouteHandler.ts +44 -0
- package/src/framework.ts +294 -0
- package/src/index.ts +10 -1
- package/src/instaml.ts +1 -1
- package/src/instaql.ts +1 -1
- package/src/parseSchemaFromJSON.ts +176 -0
- package/src/reactorTypes.ts +5 -4
- package/dist/commonjs/utils/uuid.d.ts.map +0 -1
- package/dist/commonjs/utils/uuid.js.map +0 -1
- package/dist/esm/utils/uuid.d.ts.map +0 -1
- package/dist/esm/utils/uuid.js.map +0 -1
- /package/src/utils/{uuid.ts → id.ts} +0 -0
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { i } from './schema.ts';
|
|
2
|
+
import { DataAttrDef, InstantSchemaDef } from './schemaTypes.ts';
|
|
3
|
+
|
|
4
|
+
export const parseSchemaFromJSON = (
|
|
5
|
+
s: any,
|
|
6
|
+
): InstantSchemaDef<any, any, any> => {
|
|
7
|
+
// Parse entities
|
|
8
|
+
const entities: Record<string, any> = {};
|
|
9
|
+
|
|
10
|
+
for (const [entityName, entityInfo] of Object.entries(s.entities)) {
|
|
11
|
+
const entityDef = entityInfo as any;
|
|
12
|
+
const attrs: Record<string, any> = {};
|
|
13
|
+
|
|
14
|
+
// Parse attributes
|
|
15
|
+
for (const [attrName, attrInfo] of Object.entries(entityDef.attrs)) {
|
|
16
|
+
const attrDef = attrInfo as any;
|
|
17
|
+
let attr: DataAttrDef<any, any, any>;
|
|
18
|
+
|
|
19
|
+
// Create the appropriate attribute type
|
|
20
|
+
switch (attrDef.valueType) {
|
|
21
|
+
case 'string':
|
|
22
|
+
attr = i.string();
|
|
23
|
+
break;
|
|
24
|
+
case 'number':
|
|
25
|
+
attr = i.number();
|
|
26
|
+
break;
|
|
27
|
+
case 'boolean':
|
|
28
|
+
attr = i.boolean();
|
|
29
|
+
break;
|
|
30
|
+
case 'date':
|
|
31
|
+
attr = i.date();
|
|
32
|
+
break;
|
|
33
|
+
case 'json':
|
|
34
|
+
attr = i.json();
|
|
35
|
+
break;
|
|
36
|
+
default:
|
|
37
|
+
attr = i.json();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Apply modifiers
|
|
41
|
+
if (!attrDef.required) {
|
|
42
|
+
attr = attr.optional();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (attrDef.config?.indexed) {
|
|
46
|
+
attr = attr.indexed();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (attrDef.config?.unique) {
|
|
50
|
+
attr = attr.unique();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
attrs[attrName] = attr;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
entities[entityName] = i.entity(attrs);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Parse links
|
|
60
|
+
const links: Record<string, any> = s.links || {};
|
|
61
|
+
|
|
62
|
+
// Parse rooms
|
|
63
|
+
const rooms: Record<string, any> = {};
|
|
64
|
+
|
|
65
|
+
if (s.rooms) {
|
|
66
|
+
for (const [roomName, roomInfo] of Object.entries(s.rooms)) {
|
|
67
|
+
const roomDef = roomInfo as any;
|
|
68
|
+
|
|
69
|
+
// Parse presence
|
|
70
|
+
const presenceAttrs: Record<string, any> = {};
|
|
71
|
+
for (const [attrName, attrInfo] of Object.entries(
|
|
72
|
+
roomDef.presence.attrs,
|
|
73
|
+
)) {
|
|
74
|
+
const attrDef = attrInfo as any;
|
|
75
|
+
let attr: DataAttrDef<any, any, any>;
|
|
76
|
+
|
|
77
|
+
switch (attrDef.valueType) {
|
|
78
|
+
case 'string':
|
|
79
|
+
attr = i.string();
|
|
80
|
+
break;
|
|
81
|
+
case 'number':
|
|
82
|
+
attr = i.number();
|
|
83
|
+
break;
|
|
84
|
+
case 'boolean':
|
|
85
|
+
attr = i.boolean();
|
|
86
|
+
break;
|
|
87
|
+
case 'date':
|
|
88
|
+
attr = i.date();
|
|
89
|
+
break;
|
|
90
|
+
case 'json':
|
|
91
|
+
attr = i.json();
|
|
92
|
+
break;
|
|
93
|
+
default:
|
|
94
|
+
attr = i.json();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (!attrDef.required) {
|
|
98
|
+
attr = attr.optional();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (attrDef.config?.indexed) {
|
|
102
|
+
attr = attr.indexed();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (attrDef.config?.unique) {
|
|
106
|
+
attr = attr.unique();
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
presenceAttrs[attrName] = attr;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Parse topics
|
|
113
|
+
const topics: Record<string, any> = {};
|
|
114
|
+
if (roomDef.topics) {
|
|
115
|
+
for (const [topicName, topicInfo] of Object.entries(roomDef.topics)) {
|
|
116
|
+
const topicDef = topicInfo as any;
|
|
117
|
+
const topicAttrs: Record<string, any> = {};
|
|
118
|
+
|
|
119
|
+
for (const [attrName, attrInfo] of Object.entries(topicDef.attrs)) {
|
|
120
|
+
const attrDef = attrInfo as any;
|
|
121
|
+
let attr: DataAttrDef<any, any, any>;
|
|
122
|
+
|
|
123
|
+
switch (attrDef.valueType) {
|
|
124
|
+
case 'string':
|
|
125
|
+
attr = i.string();
|
|
126
|
+
break;
|
|
127
|
+
case 'number':
|
|
128
|
+
attr = i.number();
|
|
129
|
+
break;
|
|
130
|
+
case 'boolean':
|
|
131
|
+
attr = i.boolean();
|
|
132
|
+
break;
|
|
133
|
+
case 'date':
|
|
134
|
+
attr = i.date();
|
|
135
|
+
break;
|
|
136
|
+
case 'json':
|
|
137
|
+
attr = i.json();
|
|
138
|
+
break;
|
|
139
|
+
default:
|
|
140
|
+
attr = i.json();
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (!attrDef.required) {
|
|
144
|
+
attr = attr.optional();
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (attrDef.config?.indexed) {
|
|
148
|
+
attr = attr.indexed();
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (attrDef.config?.unique) {
|
|
152
|
+
attr = attr.unique();
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
topicAttrs[attrName] = attr;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
topics[topicName] = i.entity(topicAttrs);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
rooms[roomName] = {
|
|
163
|
+
presence: i.entity(presenceAttrs),
|
|
164
|
+
topics,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const resultingSchema = i.schema({
|
|
170
|
+
entities,
|
|
171
|
+
links,
|
|
172
|
+
rooms,
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
return resultingSchema;
|
|
176
|
+
};
|
package/src/reactorTypes.ts
CHANGED
|
@@ -6,12 +6,13 @@ export type QuerySubResult = {
|
|
|
6
6
|
attrsStore: AttrsStore;
|
|
7
7
|
pageInfo?: PageInfoResponse<any> | null | undefined;
|
|
8
8
|
aggregate?: any;
|
|
9
|
-
processedTxId
|
|
9
|
+
processedTxId?: number;
|
|
10
|
+
isExternal?: boolean;
|
|
10
11
|
};
|
|
11
12
|
|
|
12
13
|
export type QuerySub = {
|
|
13
14
|
q: Object;
|
|
14
|
-
eventId
|
|
15
|
+
eventId?: string;
|
|
15
16
|
lastAccessed?: number | null | undefined;
|
|
16
17
|
result?: QuerySubResult;
|
|
17
18
|
};
|
|
@@ -21,12 +22,12 @@ export type QuerySubResultInStorage = {
|
|
|
21
22
|
attrsStore: AttrsStoreJson;
|
|
22
23
|
pageInfo?: PageInfoResponse<any> | null | undefined;
|
|
23
24
|
aggregate?: any;
|
|
24
|
-
processedTxId
|
|
25
|
+
processedTxId?: number;
|
|
25
26
|
};
|
|
26
27
|
|
|
27
28
|
export type QuerySubInStorage = {
|
|
28
29
|
q: Object;
|
|
29
|
-
eventId
|
|
30
|
+
eventId?: string;
|
|
30
31
|
lastAccessed?: number | null | undefined;
|
|
31
32
|
result?: QuerySubResultInStorage;
|
|
32
33
|
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"uuid.d.ts","sourceRoot":"","sources":["../../../src/utils/uuid.ts"],"names":[],"mappings":"AAmBA,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAEzD;AAED,iBAAS,EAAE,IAAI,MAAM,CAEpB;AAED,eAAe,EAAE,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"uuid.js","sourceRoot":"","sources":["../../../src/utils/uuid.ts"],"names":[],"mappings":";;AAmBA,kCAEC;AArBD,+BAA0B;AAE1B,SAAS,eAAe,CAAC,IAAY;IACnC,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IACnC,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QACvC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;IACpD,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,iBAAiB,CAAC,CAAC,EAAE,CAAC;IAC7B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAClC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YAAE,OAAO,CAAC,CAAC,CAAC;QAC3B,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YAAE,OAAO,CAAC,CAAC;IAC5B,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC;AAED,SAAgB,WAAW,CAAC,MAAc,EAAE,MAAc;IACxD,OAAO,iBAAiB,CAAC,eAAe,CAAC,MAAM,CAAC,EAAE,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC;AAC7E,CAAC;AAED,SAAS,EAAE;IACT,OAAO,IAAA,SAAE,GAAE,CAAC;AACd,CAAC;AAED,kBAAe,EAAE,CAAC","sourcesContent":["import { v4 } from 'uuid';\n\nfunction uuidToByteArray(uuid: string) {\n const hex = uuid.replace(/-/g, '');\n const bytes: number[] = [];\n for (let i = 0; i < hex.length; i += 2) {\n bytes.push(parseInt(hex.substring(i, i + 2), 16));\n }\n return bytes;\n}\n\nfunction compareByteArrays(a, b) {\n for (let i = 0; i < a.length; i++) {\n if (a[i] < b[i]) return -1;\n if (a[i] > b[i]) return 1;\n }\n return 0;\n}\n\nexport function uuidCompare(uuid_a: string, uuid_b: string) {\n return compareByteArrays(uuidToByteArray(uuid_a), uuidToByteArray(uuid_b));\n}\n\nfunction id(): string {\n return v4();\n}\n\nexport default id;\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"uuid.d.ts","sourceRoot":"","sources":["../../../src/utils/uuid.ts"],"names":[],"mappings":"AAmBA,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAEzD;AAED,iBAAS,EAAE,IAAI,MAAM,CAEpB;AAED,eAAe,EAAE,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"uuid.js","sourceRoot":"","sources":["../../../src/utils/uuid.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,MAAM,CAAC;AAE1B,SAAS,eAAe,CAAC,IAAY;IACnC,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IACnC,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QACvC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;IACpD,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,iBAAiB,CAAC,CAAC,EAAE,CAAC;IAC7B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAClC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YAAE,OAAO,CAAC,CAAC,CAAC;QAC3B,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YAAE,OAAO,CAAC,CAAC;IAC5B,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,MAAc,EAAE,MAAc;IACxD,OAAO,iBAAiB,CAAC,eAAe,CAAC,MAAM,CAAC,EAAE,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC;AAC7E,CAAC;AAED,SAAS,EAAE;IACT,OAAO,EAAE,EAAE,CAAC;AACd,CAAC;AAED,eAAe,EAAE,CAAC","sourcesContent":["import { v4 } from 'uuid';\n\nfunction uuidToByteArray(uuid: string) {\n const hex = uuid.replace(/-/g, '');\n const bytes: number[] = [];\n for (let i = 0; i < hex.length; i += 2) {\n bytes.push(parseInt(hex.substring(i, i + 2), 16));\n }\n return bytes;\n}\n\nfunction compareByteArrays(a, b) {\n for (let i = 0; i < a.length; i++) {\n if (a[i] < b[i]) return -1;\n if (a[i] > b[i]) return 1;\n }\n return 0;\n}\n\nexport function uuidCompare(uuid_a: string, uuid_b: string) {\n return compareByteArrays(uuidToByteArray(uuid_a), uuidToByteArray(uuid_b));\n}\n\nfunction id(): string {\n return v4();\n}\n\nexport default id;\n"]}
|
|
File without changes
|