@instantdb/core 0.22.96-experimental.add-posthog-frontend.20386914944.1 → 0.22.96

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.
Files changed (63) hide show
  1. package/__tests__/src/serializeSchema.test.ts +123 -0
  2. package/dist/commonjs/Reactor.d.ts +13 -1
  3. package/dist/commonjs/Reactor.d.ts.map +1 -1
  4. package/dist/commonjs/Reactor.js +72 -5
  5. package/dist/commonjs/Reactor.js.map +1 -1
  6. package/dist/commonjs/SyncTable.d.ts.map +1 -1
  7. package/dist/commonjs/SyncTable.js +7 -6
  8. package/dist/commonjs/SyncTable.js.map +1 -1
  9. package/dist/commonjs/createRouteHandler.d.ts +8 -0
  10. package/dist/commonjs/createRouteHandler.d.ts.map +1 -0
  11. package/dist/commonjs/createRouteHandler.js +66 -0
  12. package/dist/commonjs/createRouteHandler.js.map +1 -0
  13. package/dist/commonjs/framework.d.ts +77 -0
  14. package/dist/commonjs/framework.d.ts.map +1 -0
  15. package/dist/commonjs/framework.js +228 -0
  16. package/dist/commonjs/framework.js.map +1 -0
  17. package/dist/commonjs/index.d.ts +5 -1
  18. package/dist/commonjs/index.d.ts.map +1 -1
  19. package/dist/commonjs/index.js +7 -1
  20. package/dist/commonjs/index.js.map +1 -1
  21. package/dist/commonjs/parseSchemaFromJSON.d.ts +3 -0
  22. package/dist/commonjs/parseSchemaFromJSON.d.ts.map +1 -0
  23. package/dist/commonjs/parseSchemaFromJSON.js +148 -0
  24. package/dist/commonjs/parseSchemaFromJSON.js.map +1 -0
  25. package/dist/commonjs/reactorTypes.d.ts +5 -4
  26. package/dist/commonjs/reactorTypes.d.ts.map +1 -1
  27. package/dist/commonjs/reactorTypes.js.map +1 -1
  28. package/dist/esm/Reactor.d.ts +13 -1
  29. package/dist/esm/Reactor.d.ts.map +1 -1
  30. package/dist/esm/Reactor.js +72 -5
  31. package/dist/esm/Reactor.js.map +1 -1
  32. package/dist/esm/SyncTable.d.ts.map +1 -1
  33. package/dist/esm/SyncTable.js +7 -6
  34. package/dist/esm/SyncTable.js.map +1 -1
  35. package/dist/esm/createRouteHandler.d.ts +8 -0
  36. package/dist/esm/createRouteHandler.d.ts.map +1 -0
  37. package/dist/esm/createRouteHandler.js +62 -0
  38. package/dist/esm/createRouteHandler.js.map +1 -0
  39. package/dist/esm/framework.d.ts +77 -0
  40. package/dist/esm/framework.d.ts.map +1 -0
  41. package/dist/esm/framework.js +188 -0
  42. package/dist/esm/framework.js.map +1 -0
  43. package/dist/esm/index.d.ts +5 -1
  44. package/dist/esm/index.d.ts.map +1 -1
  45. package/dist/esm/index.js +5 -2
  46. package/dist/esm/index.js.map +1 -1
  47. package/dist/esm/parseSchemaFromJSON.d.ts +3 -0
  48. package/dist/esm/parseSchemaFromJSON.d.ts.map +1 -0
  49. package/dist/esm/parseSchemaFromJSON.js +144 -0
  50. package/dist/esm/parseSchemaFromJSON.js.map +1 -0
  51. package/dist/esm/reactorTypes.d.ts +5 -4
  52. package/dist/esm/reactorTypes.d.ts.map +1 -1
  53. package/dist/esm/reactorTypes.js.map +1 -1
  54. package/dist/standalone/index.js +2735 -2400
  55. package/dist/standalone/index.umd.cjs +3 -3
  56. package/package.json +2 -2
  57. package/src/Reactor.js +83 -6
  58. package/src/SyncTable.ts +18 -14
  59. package/src/createRouteHandler.ts +63 -0
  60. package/src/framework.ts +318 -0
  61. package/src/index.ts +9 -0
  62. package/src/parseSchemaFromJSON.ts +176 -0
  63. package/src/reactorTypes.ts +5 -4
@@ -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
+ };
@@ -6,12 +6,13 @@ export type QuerySubResult = {
6
6
  attrsStore: AttrsStore;
7
7
  pageInfo?: PageInfoResponse<any> | null | undefined;
8
8
  aggregate?: any;
9
- processedTxId: number;
9
+ processedTxId?: number;
10
+ isExternal?: boolean;
10
11
  };
11
12
 
12
13
  export type QuerySub = {
13
14
  q: Object;
14
- eventId: string;
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: number;
25
+ processedTxId?: number;
25
26
  };
26
27
 
27
28
  export type QuerySubInStorage = {
28
29
  q: Object;
29
- eventId: string;
30
+ eventId?: string;
30
31
  lastAccessed?: number | null | undefined;
31
32
  result?: QuerySubResultInStorage;
32
33
  };