@livestore/livestore 0.0.0-snapshot-d9d66b354a9f4cfae987725d38971992ff14e4ad → 0.0.0-snapshot-1d99fea7d2ce2c7a5d9ed0a3752f8a7bda6bc3db
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/dist/.tsbuildinfo +1 -1
- package/dist/SqliteDbWrapper.d.ts +54 -0
- package/dist/SqliteDbWrapper.d.ts.map +1 -0
- package/dist/{SynchronousDatabaseWrapper.js → SqliteDbWrapper.js} +44 -9
- package/dist/SqliteDbWrapper.js.map +1 -0
- package/dist/effect/LiveStore.d.ts +16 -12
- package/dist/effect/LiveStore.d.ts.map +1 -1
- package/dist/effect/LiveStore.js +14 -14
- package/dist/effect/LiveStore.js.map +1 -1
- package/dist/index.d.ts +6 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/live-queries/base-class.d.ts +57 -21
- package/dist/live-queries/base-class.d.ts.map +1 -1
- package/dist/live-queries/base-class.js +54 -13
- package/dist/live-queries/base-class.js.map +1 -1
- package/dist/live-queries/computed.d.ts +7 -7
- package/dist/live-queries/computed.d.ts.map +1 -1
- package/dist/live-queries/computed.js +34 -11
- package/dist/live-queries/computed.js.map +1 -1
- package/dist/live-queries/{db.d.ts → db-query.d.ts} +15 -14
- package/dist/live-queries/db-query.d.ts.map +1 -0
- package/dist/live-queries/{db.js → db-query.js} +87 -43
- package/dist/live-queries/db-query.js.map +1 -0
- package/dist/live-queries/db-query.test.d.ts +2 -0
- package/dist/live-queries/db-query.test.d.ts.map +1 -0
- package/dist/live-queries/db-query.test.js +113 -0
- package/dist/live-queries/db-query.test.js.map +1 -0
- package/dist/live-queries/graphql.d.ts +8 -8
- package/dist/live-queries/graphql.d.ts.map +1 -1
- package/dist/live-queries/graphql.js +34 -9
- package/dist/live-queries/graphql.js.map +1 -1
- package/dist/live-queries/make-ref.d.ts +20 -0
- package/dist/live-queries/make-ref.d.ts.map +1 -0
- package/dist/live-queries/make-ref.js +33 -0
- package/dist/live-queries/make-ref.js.map +1 -0
- package/dist/reactive.d.ts +19 -13
- package/dist/reactive.d.ts.map +1 -1
- package/dist/reactive.js +22 -18
- package/dist/reactive.js.map +1 -1
- package/dist/reactive.test.js +1 -1
- package/dist/reactive.test.js.map +1 -1
- package/dist/row-query-utils.d.ts +4 -4
- package/dist/row-query-utils.d.ts.map +1 -1
- package/dist/row-query-utils.js +14 -10
- package/dist/row-query-utils.js.map +1 -1
- package/dist/store/create-store.d.ts +13 -12
- package/dist/store/create-store.d.ts.map +1 -1
- package/dist/store/create-store.js +27 -33
- package/dist/store/create-store.js.map +1 -1
- package/dist/store/devtools.d.ts +3 -3
- package/dist/store/devtools.d.ts.map +1 -1
- package/dist/store/devtools.js +56 -34
- package/dist/store/devtools.js.map +1 -1
- package/dist/store/store-types.d.ts +18 -18
- package/dist/store/store-types.d.ts.map +1 -1
- package/dist/store/store-types.js.map +1 -1
- package/dist/store/store.d.ts +57 -38
- package/dist/store/store.d.ts.map +1 -1
- package/dist/store/store.js +226 -188
- package/dist/store/store.js.map +1 -1
- package/dist/utils/dev.d.ts.map +1 -1
- package/dist/utils/dev.js +3 -2
- package/dist/utils/dev.js.map +1 -1
- package/dist/utils/function-string.d.ts +7 -0
- package/dist/utils/function-string.d.ts.map +1 -0
- package/dist/utils/function-string.js +9 -0
- package/dist/utils/function-string.js.map +1 -0
- package/dist/utils/stack-info.d.ts.map +1 -1
- package/dist/utils/stack-info.js +6 -1
- package/dist/utils/stack-info.js.map +1 -1
- package/dist/utils/stack-info.test.js +54 -1
- package/dist/utils/stack-info.test.js.map +1 -1
- package/dist/utils/tests/fixture.d.ts +2 -6
- package/dist/utils/tests/fixture.d.ts.map +1 -1
- package/dist/utils/tests/fixture.js +7 -13
- package/dist/utils/tests/fixture.js.map +1 -1
- package/dist/utils/tests/mod.d.ts +1 -0
- package/dist/utils/tests/mod.d.ts.map +1 -1
- package/dist/utils/tests/mod.js +1 -0
- package/dist/utils/tests/mod.js.map +1 -1
- package/dist/utils/tests/otel.d.ts +60 -1
- package/dist/utils/tests/otel.d.ts.map +1 -1
- package/dist/utils/tests/otel.js +65 -4
- package/dist/utils/tests/otel.js.map +1 -1
- package/package.json +12 -12
- package/src/{SynchronousDatabaseWrapper.ts → SqliteDbWrapper.ts} +59 -14
- package/src/ambient.d.ts +1 -1
- package/src/effect/LiveStore.ts +32 -33
- package/src/index.ts +14 -7
- package/src/live-queries/__snapshots__/{db.test.ts.snap → db-query.test.ts.snap} +220 -72
- package/src/live-queries/base-class.ts +151 -40
- package/src/live-queries/computed.ts +44 -19
- package/src/live-queries/{db.test.ts → db-query.test.ts} +46 -33
- package/src/live-queries/{db.ts → db-query.ts} +123 -61
- package/src/live-queries/graphql.ts +46 -21
- package/src/live-queries/make-ref.ts +47 -0
- package/src/reactive.test.ts +1 -1
- package/src/reactive.ts +60 -37
- package/src/row-query-utils.ts +29 -18
- package/src/store/create-store.ts +106 -113
- package/src/store/devtools.ts +65 -39
- package/src/store/store-types.ts +20 -18
- package/src/store/store.ts +362 -289
- package/src/utils/dev.ts +4 -2
- package/src/utils/function-string.ts +12 -0
- package/src/utils/stack-info.test.ts +58 -1
- package/src/utils/stack-info.ts +6 -1
- package/src/utils/tests/fixture.ts +6 -16
- package/src/utils/tests/mod.ts +1 -0
- package/src/utils/tests/otel.ts +71 -5
- package/dist/SynchronousDatabaseWrapper.d.ts +0 -36
- package/dist/SynchronousDatabaseWrapper.d.ts.map +0 -1
- package/dist/SynchronousDatabaseWrapper.js.map +0 -1
- package/dist/global-state.d.ts +0 -14
- package/dist/global-state.d.ts.map +0 -1
- package/dist/global-state.js +0 -16
- package/dist/global-state.js.map +0 -1
- package/dist/live-queries/db.d.ts.map +0 -1
- package/dist/live-queries/db.js.map +0 -1
- package/dist/live-queries/db.test.d.ts +0 -2
- package/dist/live-queries/db.test.d.ts.map +0 -1
- package/dist/live-queries/db.test.js +0 -117
- package/dist/live-queries/db.test.js.map +0 -1
- package/src/global-state.ts +0 -20
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
exports[`otel > otel 3`] = `
|
|
4
4
|
{
|
|
5
|
-
"_name": "
|
|
5
|
+
"_name": "createStore",
|
|
6
|
+
"attributes": {
|
|
7
|
+
"debugInstanceId": "test",
|
|
8
|
+
"storeId": "default",
|
|
9
|
+
},
|
|
6
10
|
"children": [
|
|
7
11
|
{
|
|
8
12
|
"_name": "livestore.in-memory-db:execute",
|
|
@@ -10,46 +14,32 @@ exports[`otel > otel 3`] = `
|
|
|
10
14
|
"sql.query": "
|
|
11
15
|
PRAGMA page_size=32768;
|
|
12
16
|
PRAGMA cache_size=10000;
|
|
13
|
-
PRAGMA journal_mode='MEMORY'; -- we don't flush to disk before committing a write
|
|
14
17
|
PRAGMA synchronous='OFF';
|
|
15
18
|
PRAGMA temp_store='MEMORY';
|
|
16
19
|
PRAGMA foreign_keys='ON'; -- we want foreign key constraints to be enforced
|
|
17
20
|
",
|
|
18
21
|
},
|
|
19
22
|
},
|
|
23
|
+
{
|
|
24
|
+
"_name": "LiveStore:sync",
|
|
25
|
+
},
|
|
20
26
|
{
|
|
21
27
|
"_name": "LiveStore:mutations",
|
|
22
28
|
"children": [
|
|
23
29
|
{
|
|
24
30
|
"_name": "LiveStore:mutate",
|
|
25
31
|
"attributes": {
|
|
26
|
-
"livestore.
|
|
32
|
+
"livestore.mutationEventTags": [
|
|
33
|
+
"livestore.RawSql",
|
|
34
|
+
],
|
|
35
|
+
"livestore.mutationEventsCount": 1,
|
|
27
36
|
},
|
|
28
37
|
"children": [
|
|
29
38
|
{
|
|
30
|
-
"_name": "
|
|
39
|
+
"_name": "livestore.in-memory-db:execute",
|
|
31
40
|
"attributes": {
|
|
32
|
-
"
|
|
41
|
+
"sql.query": "INSERT INTO todos (id, text, completed) VALUES ('t1', 'buy milk', 0)",
|
|
33
42
|
},
|
|
34
|
-
"children": [
|
|
35
|
-
{
|
|
36
|
-
"_name": "LiveStore:mutateWithoutRefresh",
|
|
37
|
-
"attributes": {
|
|
38
|
-
"livestore.args": "{
|
|
39
|
-
"sql": "INSERT INTO todos (id, text, completed) VALUES ('t1', 'buy milk', 0)"
|
|
40
|
-
}",
|
|
41
|
-
"livestore.mutation": "livestore.RawSql",
|
|
42
|
-
},
|
|
43
|
-
"children": [
|
|
44
|
-
{
|
|
45
|
-
"_name": "livestore.in-memory-db:execute",
|
|
46
|
-
"attributes": {
|
|
47
|
-
"sql.query": "INSERT INTO todos (id, text, completed) VALUES ('t1', 'buy milk', 0)",
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
],
|
|
51
|
-
},
|
|
52
|
-
],
|
|
53
43
|
},
|
|
54
44
|
],
|
|
55
45
|
},
|
|
@@ -98,9 +88,185 @@ exports[`otel > otel 3`] = `
|
|
|
98
88
|
}
|
|
99
89
|
`;
|
|
100
90
|
|
|
91
|
+
exports[`otel > with thunks 1`] = `
|
|
92
|
+
{
|
|
93
|
+
"atoms": [
|
|
94
|
+
{
|
|
95
|
+
"_tag": "ref",
|
|
96
|
+
"id": "node-1",
|
|
97
|
+
"isDestroyed": false,
|
|
98
|
+
"isDirty": false,
|
|
99
|
+
"label": "tableRef:todos",
|
|
100
|
+
"meta": {
|
|
101
|
+
"liveStoreRefType": "table",
|
|
102
|
+
},
|
|
103
|
+
"previousResult": {
|
|
104
|
+
"_tag": "Some",
|
|
105
|
+
"value": "null",
|
|
106
|
+
},
|
|
107
|
+
"refreshes": 0,
|
|
108
|
+
"sub": [],
|
|
109
|
+
"super": [],
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
"_tag": "ref",
|
|
113
|
+
"id": "node-2",
|
|
114
|
+
"isDestroyed": false,
|
|
115
|
+
"isDirty": false,
|
|
116
|
+
"label": "tableRef:app",
|
|
117
|
+
"meta": {
|
|
118
|
+
"liveStoreRefType": "table",
|
|
119
|
+
},
|
|
120
|
+
"previousResult": {
|
|
121
|
+
"_tag": "Some",
|
|
122
|
+
"value": "null",
|
|
123
|
+
},
|
|
124
|
+
"refreshes": 0,
|
|
125
|
+
"sub": [],
|
|
126
|
+
"super": [],
|
|
127
|
+
},
|
|
128
|
+
],
|
|
129
|
+
"deferredEffects": [],
|
|
130
|
+
"effects": [],
|
|
131
|
+
}
|
|
132
|
+
`;
|
|
133
|
+
|
|
101
134
|
exports[`otel > with thunks 3`] = `
|
|
102
135
|
{
|
|
103
|
-
"
|
|
136
|
+
"atoms": [
|
|
137
|
+
{
|
|
138
|
+
"_tag": "ref",
|
|
139
|
+
"id": "node-1",
|
|
140
|
+
"isDestroyed": false,
|
|
141
|
+
"isDirty": false,
|
|
142
|
+
"label": "tableRef:todos",
|
|
143
|
+
"meta": {
|
|
144
|
+
"liveStoreRefType": "table",
|
|
145
|
+
},
|
|
146
|
+
"previousResult": {
|
|
147
|
+
"_tag": "Some",
|
|
148
|
+
"value": "null",
|
|
149
|
+
},
|
|
150
|
+
"refreshes": 0,
|
|
151
|
+
"sub": [],
|
|
152
|
+
"super": [],
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
"_tag": "ref",
|
|
156
|
+
"id": "node-2",
|
|
157
|
+
"isDestroyed": false,
|
|
158
|
+
"isDirty": false,
|
|
159
|
+
"label": "tableRef:app",
|
|
160
|
+
"meta": {
|
|
161
|
+
"liveStoreRefType": "table",
|
|
162
|
+
},
|
|
163
|
+
"previousResult": {
|
|
164
|
+
"_tag": "Some",
|
|
165
|
+
"value": "null",
|
|
166
|
+
},
|
|
167
|
+
"refreshes": 0,
|
|
168
|
+
"sub": [],
|
|
169
|
+
"super": [],
|
|
170
|
+
},
|
|
171
|
+
],
|
|
172
|
+
"deferredEffects": [],
|
|
173
|
+
"effects": [],
|
|
174
|
+
}
|
|
175
|
+
`;
|
|
176
|
+
|
|
177
|
+
exports[`otel > with thunks 4`] = `
|
|
178
|
+
{
|
|
179
|
+
"atoms": [
|
|
180
|
+
{
|
|
181
|
+
"_tag": "ref",
|
|
182
|
+
"id": "node-1",
|
|
183
|
+
"isDestroyed": false,
|
|
184
|
+
"isDirty": false,
|
|
185
|
+
"label": "tableRef:todos",
|
|
186
|
+
"meta": {
|
|
187
|
+
"liveStoreRefType": "table",
|
|
188
|
+
},
|
|
189
|
+
"previousResult": {
|
|
190
|
+
"_tag": "Some",
|
|
191
|
+
"value": "null",
|
|
192
|
+
},
|
|
193
|
+
"refreshes": 1,
|
|
194
|
+
"sub": [],
|
|
195
|
+
"super": [],
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
"_tag": "ref",
|
|
199
|
+
"id": "node-2",
|
|
200
|
+
"isDestroyed": false,
|
|
201
|
+
"isDirty": false,
|
|
202
|
+
"label": "tableRef:app",
|
|
203
|
+
"meta": {
|
|
204
|
+
"liveStoreRefType": "table",
|
|
205
|
+
},
|
|
206
|
+
"previousResult": {
|
|
207
|
+
"_tag": "Some",
|
|
208
|
+
"value": "null",
|
|
209
|
+
},
|
|
210
|
+
"refreshes": 0,
|
|
211
|
+
"sub": [],
|
|
212
|
+
"super": [],
|
|
213
|
+
},
|
|
214
|
+
],
|
|
215
|
+
"deferredEffects": [],
|
|
216
|
+
"effects": [],
|
|
217
|
+
}
|
|
218
|
+
`;
|
|
219
|
+
|
|
220
|
+
exports[`otel > with thunks 6`] = `
|
|
221
|
+
{
|
|
222
|
+
"atoms": [
|
|
223
|
+
{
|
|
224
|
+
"_tag": "ref",
|
|
225
|
+
"id": "node-1",
|
|
226
|
+
"isDestroyed": false,
|
|
227
|
+
"isDirty": false,
|
|
228
|
+
"label": "tableRef:todos",
|
|
229
|
+
"meta": {
|
|
230
|
+
"liveStoreRefType": "table",
|
|
231
|
+
},
|
|
232
|
+
"previousResult": {
|
|
233
|
+
"_tag": "Some",
|
|
234
|
+
"value": "null",
|
|
235
|
+
},
|
|
236
|
+
"refreshes": 1,
|
|
237
|
+
"sub": [],
|
|
238
|
+
"super": [],
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
"_tag": "ref",
|
|
242
|
+
"id": "node-2",
|
|
243
|
+
"isDestroyed": false,
|
|
244
|
+
"isDirty": false,
|
|
245
|
+
"label": "tableRef:app",
|
|
246
|
+
"meta": {
|
|
247
|
+
"liveStoreRefType": "table",
|
|
248
|
+
},
|
|
249
|
+
"previousResult": {
|
|
250
|
+
"_tag": "Some",
|
|
251
|
+
"value": "null",
|
|
252
|
+
},
|
|
253
|
+
"refreshes": 0,
|
|
254
|
+
"sub": [],
|
|
255
|
+
"super": [],
|
|
256
|
+
},
|
|
257
|
+
],
|
|
258
|
+
"deferredEffects": [],
|
|
259
|
+
"effects": [],
|
|
260
|
+
}
|
|
261
|
+
`;
|
|
262
|
+
|
|
263
|
+
exports[`otel > with thunks 7`] = `
|
|
264
|
+
{
|
|
265
|
+
"_name": "createStore",
|
|
266
|
+
"attributes": {
|
|
267
|
+
"debugInstanceId": "test",
|
|
268
|
+
"storeId": "default",
|
|
269
|
+
},
|
|
104
270
|
"children": [
|
|
105
271
|
{
|
|
106
272
|
"_name": "livestore.in-memory-db:execute",
|
|
@@ -108,46 +274,32 @@ exports[`otel > with thunks 3`] = `
|
|
|
108
274
|
"sql.query": "
|
|
109
275
|
PRAGMA page_size=32768;
|
|
110
276
|
PRAGMA cache_size=10000;
|
|
111
|
-
PRAGMA journal_mode='MEMORY'; -- we don't flush to disk before committing a write
|
|
112
277
|
PRAGMA synchronous='OFF';
|
|
113
278
|
PRAGMA temp_store='MEMORY';
|
|
114
279
|
PRAGMA foreign_keys='ON'; -- we want foreign key constraints to be enforced
|
|
115
280
|
",
|
|
116
281
|
},
|
|
117
282
|
},
|
|
283
|
+
{
|
|
284
|
+
"_name": "LiveStore:sync",
|
|
285
|
+
},
|
|
118
286
|
{
|
|
119
287
|
"_name": "LiveStore:mutations",
|
|
120
288
|
"children": [
|
|
121
289
|
{
|
|
122
290
|
"_name": "LiveStore:mutate",
|
|
123
291
|
"attributes": {
|
|
124
|
-
"livestore.
|
|
292
|
+
"livestore.mutationEventTags": [
|
|
293
|
+
"livestore.RawSql",
|
|
294
|
+
],
|
|
295
|
+
"livestore.mutationEventsCount": 1,
|
|
125
296
|
},
|
|
126
297
|
"children": [
|
|
127
298
|
{
|
|
128
|
-
"_name": "
|
|
299
|
+
"_name": "livestore.in-memory-db:execute",
|
|
129
300
|
"attributes": {
|
|
130
|
-
"
|
|
301
|
+
"sql.query": "INSERT INTO todos (id, text, completed) VALUES ('t1', 'buy milk', 0)",
|
|
131
302
|
},
|
|
132
|
-
"children": [
|
|
133
|
-
{
|
|
134
|
-
"_name": "LiveStore:mutateWithoutRefresh",
|
|
135
|
-
"attributes": {
|
|
136
|
-
"livestore.args": "{
|
|
137
|
-
"sql": "INSERT INTO todos (id, text, completed) VALUES ('t1', 'buy milk', 0)"
|
|
138
|
-
}",
|
|
139
|
-
"livestore.mutation": "livestore.RawSql",
|
|
140
|
-
},
|
|
141
|
-
"children": [
|
|
142
|
-
{
|
|
143
|
-
"_name": "livestore.in-memory-db:execute",
|
|
144
|
-
"attributes": {
|
|
145
|
-
"sql.query": "INSERT INTO todos (id, text, completed) VALUES ('t1', 'buy milk', 0)",
|
|
146
|
-
},
|
|
147
|
-
},
|
|
148
|
-
],
|
|
149
|
-
},
|
|
150
|
-
],
|
|
151
303
|
},
|
|
152
304
|
],
|
|
153
305
|
},
|
|
@@ -183,6 +335,9 @@ exports[`otel > with thunks 3`] = `
|
|
|
183
335
|
"sql.rowsCount": 1,
|
|
184
336
|
},
|
|
185
337
|
"children": [
|
|
338
|
+
{
|
|
339
|
+
"_name": "js:where-filter",
|
|
340
|
+
},
|
|
186
341
|
{
|
|
187
342
|
"_name": "sql-in-memory-select",
|
|
188
343
|
"attributes": {
|
|
@@ -201,7 +356,11 @@ exports[`otel > with thunks 3`] = `
|
|
|
201
356
|
|
|
202
357
|
exports[`otel > with thunks with query builder and without labels 3`] = `
|
|
203
358
|
{
|
|
204
|
-
"_name": "
|
|
359
|
+
"_name": "createStore",
|
|
360
|
+
"attributes": {
|
|
361
|
+
"debugInstanceId": "test",
|
|
362
|
+
"storeId": "default",
|
|
363
|
+
},
|
|
205
364
|
"children": [
|
|
206
365
|
{
|
|
207
366
|
"_name": "livestore.in-memory-db:execute",
|
|
@@ -209,46 +368,32 @@ exports[`otel > with thunks with query builder and without labels 3`] = `
|
|
|
209
368
|
"sql.query": "
|
|
210
369
|
PRAGMA page_size=32768;
|
|
211
370
|
PRAGMA cache_size=10000;
|
|
212
|
-
PRAGMA journal_mode='MEMORY'; -- we don't flush to disk before committing a write
|
|
213
371
|
PRAGMA synchronous='OFF';
|
|
214
372
|
PRAGMA temp_store='MEMORY';
|
|
215
373
|
PRAGMA foreign_keys='ON'; -- we want foreign key constraints to be enforced
|
|
216
374
|
",
|
|
217
375
|
},
|
|
218
376
|
},
|
|
377
|
+
{
|
|
378
|
+
"_name": "LiveStore:sync",
|
|
379
|
+
},
|
|
219
380
|
{
|
|
220
381
|
"_name": "LiveStore:mutations",
|
|
221
382
|
"children": [
|
|
222
383
|
{
|
|
223
384
|
"_name": "LiveStore:mutate",
|
|
224
385
|
"attributes": {
|
|
225
|
-
"livestore.
|
|
386
|
+
"livestore.mutationEventTags": [
|
|
387
|
+
"livestore.RawSql",
|
|
388
|
+
],
|
|
389
|
+
"livestore.mutationEventsCount": 1,
|
|
226
390
|
},
|
|
227
391
|
"children": [
|
|
228
392
|
{
|
|
229
|
-
"_name": "
|
|
393
|
+
"_name": "livestore.in-memory-db:execute",
|
|
230
394
|
"attributes": {
|
|
231
|
-
"
|
|
395
|
+
"sql.query": "INSERT INTO todos (id, text, completed) VALUES ('t1', 'buy milk', 0)",
|
|
232
396
|
},
|
|
233
|
-
"children": [
|
|
234
|
-
{
|
|
235
|
-
"_name": "LiveStore:mutateWithoutRefresh",
|
|
236
|
-
"attributes": {
|
|
237
|
-
"livestore.args": "{
|
|
238
|
-
"sql": "INSERT INTO todos (id, text, completed) VALUES ('t1', 'buy milk', 0)"
|
|
239
|
-
}",
|
|
240
|
-
"livestore.mutation": "livestore.RawSql",
|
|
241
|
-
},
|
|
242
|
-
"children": [
|
|
243
|
-
{
|
|
244
|
-
"_name": "livestore.in-memory-db:execute",
|
|
245
|
-
"attributes": {
|
|
246
|
-
"sql.query": "INSERT INTO todos (id, text, completed) VALUES ('t1', 'buy milk', 0)",
|
|
247
|
-
},
|
|
248
|
-
},
|
|
249
|
-
],
|
|
250
|
-
},
|
|
251
|
-
],
|
|
252
397
|
},
|
|
253
398
|
],
|
|
254
399
|
},
|
|
@@ -284,6 +429,9 @@ exports[`otel > with thunks with query builder and without labels 3`] = `
|
|
|
284
429
|
"sql.rowsCount": 1,
|
|
285
430
|
},
|
|
286
431
|
"children": [
|
|
432
|
+
{
|
|
433
|
+
"_name": "js:() => ({ completed: false })",
|
|
434
|
+
},
|
|
287
435
|
{
|
|
288
436
|
"_name": "sql-in-memory-select",
|
|
289
437
|
"attributes": {
|
|
@@ -1,59 +1,110 @@
|
|
|
1
1
|
import type { QueryInfo } from '@livestore/common'
|
|
2
|
+
import { isNotNil } from '@livestore/utils'
|
|
2
3
|
import type * as otel from '@opentelemetry/api'
|
|
3
4
|
|
|
4
|
-
import
|
|
5
|
+
import * as RG from '../reactive.js'
|
|
5
6
|
import type { Store } from '../store/store.js'
|
|
6
7
|
import type { QueryDebugInfo, RefreshReason } from '../store/store-types.js'
|
|
7
8
|
import type { StackInfo } from '../utils/stack-info.js'
|
|
8
9
|
|
|
9
|
-
export type ReactivityGraph = ReactiveGraph<RefreshReason, QueryDebugInfo,
|
|
10
|
+
export type ReactivityGraph = RG.ReactiveGraph<RefreshReason, QueryDebugInfo, ReactivityGraphContext>
|
|
10
11
|
|
|
11
12
|
export const makeReactivityGraph = (): ReactivityGraph =>
|
|
12
|
-
new ReactiveGraph<RefreshReason, QueryDebugInfo,
|
|
13
|
+
new RG.ReactiveGraph<RefreshReason, QueryDebugInfo, ReactivityGraphContext>()
|
|
13
14
|
|
|
14
|
-
export type
|
|
15
|
+
export type ReactivityGraphContext = {
|
|
15
16
|
store: Store
|
|
17
|
+
/** Maps from the hash of the query definition to the RcRef of the query */
|
|
18
|
+
defRcMap: Map<string, RcRef<LiveQueryAny | ILiveQueryRef<any>>>
|
|
19
|
+
/** Back-reference to the reactivity graph for convenience */
|
|
20
|
+
reactivityGraph: WeakRef<ReactivityGraph>
|
|
16
21
|
otelTracer: otel.Tracer
|
|
17
22
|
rootOtelContext: otel.Context
|
|
18
23
|
effectsWrapper: (run: () => void) => void
|
|
19
24
|
}
|
|
20
25
|
|
|
21
|
-
export type
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
26
|
+
export type GetResult<TQuery extends LiveQueryDefAny | LiveQueryAny> =
|
|
27
|
+
TQuery extends LiveQuery<infer TResult, infer _1>
|
|
28
|
+
? TResult
|
|
29
|
+
: TQuery extends LiveQueryDef<infer TResult, infer _1>
|
|
30
|
+
? TResult
|
|
31
|
+
: unknown
|
|
25
32
|
|
|
26
33
|
let queryIdCounter = 0
|
|
27
34
|
|
|
28
35
|
export type LiveQueryAny = LiveQuery<any, QueryInfo>
|
|
36
|
+
export type LiveQueryDefAny = LiveQueryDef<any, any>
|
|
37
|
+
|
|
38
|
+
export interface ILiveQueryRefDef<T> {
|
|
39
|
+
_tag: 'live-ref-def'
|
|
40
|
+
defaultValue: T
|
|
41
|
+
make: (ctx: ReactivityGraphContext) => RcRef<ILiveQueryRef<T>>
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface ILiveQueryRef<T> {
|
|
45
|
+
_tag: 'live-ref'
|
|
46
|
+
reactivityGraph: ReactivityGraph
|
|
47
|
+
ref: RG.Ref<T, ReactivityGraphContext, RefreshReason>
|
|
48
|
+
set: (value: T) => void
|
|
49
|
+
get: () => T
|
|
50
|
+
destroy: () => void
|
|
51
|
+
}
|
|
29
52
|
|
|
30
53
|
export const TypeId = Symbol.for('LiveQuery')
|
|
31
54
|
export type TypeId = typeof TypeId
|
|
32
55
|
|
|
56
|
+
export interface RcRef<T> {
|
|
57
|
+
rc: number
|
|
58
|
+
value: T
|
|
59
|
+
deref: () => void
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export type DepKey = string | number | ReadonlyArray<string | number | undefined | null>
|
|
63
|
+
|
|
64
|
+
export const depsToString = (deps: DepKey): string => {
|
|
65
|
+
if (typeof deps === 'string' || typeof deps === 'number') {
|
|
66
|
+
return deps.toString()
|
|
67
|
+
}
|
|
68
|
+
return deps.filter(isNotNil).join(',')
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface LiveQueryDef<TResult, TQueryInfo extends QueryInfo = QueryInfo.None> {
|
|
72
|
+
_tag: 'def'
|
|
73
|
+
/** Creates a new LiveQuery instance bound to a specific store/reactivityGraph */
|
|
74
|
+
make: (ctx: ReactivityGraphContext, otelContext?: otel.Context) => RcRef<LiveQuery<TResult, TQueryInfo>>
|
|
75
|
+
label: string
|
|
76
|
+
hash: string
|
|
77
|
+
queryInfo: TQueryInfo
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* A LiveQuery is stateful
|
|
82
|
+
*/
|
|
33
83
|
export interface LiveQuery<TResult, TQueryInfo extends QueryInfo = QueryInfo.None> {
|
|
34
84
|
id: number
|
|
35
85
|
_tag: 'computed' | 'db' | 'graphql'
|
|
36
86
|
[TypeId]: TypeId
|
|
37
87
|
|
|
88
|
+
// reactivityGraph: ReactivityGraph
|
|
89
|
+
|
|
38
90
|
/** This should only be used on a type-level and doesn't hold any value during runtime */
|
|
39
91
|
'__result!': TResult
|
|
40
92
|
|
|
41
93
|
/** A reactive thunk representing the query results */
|
|
42
|
-
results$: Thunk<TResult,
|
|
94
|
+
results$: RG.Thunk<TResult, ReactivityGraphContext, RefreshReason>
|
|
43
95
|
|
|
44
96
|
label: string
|
|
45
97
|
|
|
46
|
-
run: (otelContext?: otel.Context
|
|
47
|
-
|
|
48
|
-
runAndDestroy: (otelContext?: otel.Context, debugRefreshReason?: RefreshReason) => TResult
|
|
98
|
+
run: (args: { otelContext?: otel.Context; debugRefreshReason?: RefreshReason }) => TResult
|
|
49
99
|
|
|
50
|
-
destroy()
|
|
100
|
+
destroy: () => void
|
|
101
|
+
isDestroyed: boolean
|
|
51
102
|
|
|
52
|
-
subscribe(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
): () => void
|
|
103
|
+
// subscribe(
|
|
104
|
+
// onNewValue: (value: TResult) => void,
|
|
105
|
+
// onUnsubsubscribe?: () => void,
|
|
106
|
+
// options?: { label?: string; otelContext?: otel.Context },
|
|
107
|
+
// ): () => void
|
|
57
108
|
|
|
58
109
|
activeSubscriptions: Set<StackInfo>
|
|
59
110
|
|
|
@@ -75,11 +126,11 @@ export abstract class LiveStoreQueryBase<TResult, TQueryInfo extends QueryInfo>
|
|
|
75
126
|
/** Human-readable label for the query for debugging */
|
|
76
127
|
abstract label: string
|
|
77
128
|
|
|
78
|
-
abstract results$: Thunk<TResult,
|
|
129
|
+
abstract results$: RG.Thunk<TResult, ReactivityGraphContext, RefreshReason>
|
|
79
130
|
|
|
80
131
|
activeSubscriptions: Set<StackInfo> = new Set()
|
|
81
132
|
|
|
82
|
-
|
|
133
|
+
abstract readonly reactivityGraph: ReactivityGraph
|
|
83
134
|
|
|
84
135
|
abstract queryInfo: TQueryInfo
|
|
85
136
|
|
|
@@ -89,33 +140,93 @@ export abstract class LiveStoreQueryBase<TResult, TQueryInfo extends QueryInfo>
|
|
|
89
140
|
|
|
90
141
|
executionTimes: number[] = []
|
|
91
142
|
|
|
143
|
+
// TODO double check if this is needed
|
|
144
|
+
isDestroyed = false
|
|
92
145
|
abstract destroy: () => void
|
|
93
146
|
|
|
94
|
-
run = (otelContext?: otel.Context
|
|
95
|
-
this.results$.computeResult(otelContext, debugRefreshReason)
|
|
96
|
-
|
|
97
|
-
runAndDestroy = (otelContext?: otel.Context, debugRefreshReason?: RefreshReason): TResult => {
|
|
98
|
-
const result = this.run(otelContext, debugRefreshReason)
|
|
99
|
-
this.destroy()
|
|
100
|
-
return result
|
|
147
|
+
run = (args: { otelContext?: otel.Context; debugRefreshReason?: RefreshReason }): TResult => {
|
|
148
|
+
return this.results$.computeResult(args.otelContext, args.debugRefreshReason)
|
|
101
149
|
}
|
|
102
150
|
|
|
103
|
-
|
|
104
|
-
onNewValue: (value: TResult) => void,
|
|
105
|
-
onUnsubsubscribe?: () => void,
|
|
106
|
-
options?: { label?: string; otelContext?: otel.Context } | undefined,
|
|
107
|
-
): (() => void) =>
|
|
108
|
-
this.reactivityGraph.context?.store.subscribe(this, onNewValue, onUnsubsubscribe, options) ??
|
|
109
|
-
throwContextNotSetError(this.reactivityGraph)
|
|
110
|
-
}
|
|
151
|
+
protected dependencyQueriesRef: DependencyQueriesRef = new Set()
|
|
111
152
|
|
|
112
|
-
|
|
153
|
+
// subscribe = (
|
|
154
|
+
// onNewValue: (value: TResult) => void,
|
|
155
|
+
// onUnsubsubscribe?: () => void,
|
|
156
|
+
// options?: { label?: string; otelContext?: otel.Context } | undefined,
|
|
157
|
+
// ): (() => void) =>
|
|
158
|
+
// this.reactivityGraph.context?.store.subscribe(this, onNewValue, onUnsubsubscribe, options) ??
|
|
159
|
+
// RG.throwContextNotSetError(this.reactivityGraph)
|
|
160
|
+
}
|
|
113
161
|
|
|
114
|
-
export
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
162
|
+
export type GetAtomResult = <T>(
|
|
163
|
+
atom:
|
|
164
|
+
| RG.Atom<T, any, RefreshReason>
|
|
165
|
+
| LiveQueryDef<T, any>
|
|
166
|
+
| LiveQuery<T, any>
|
|
167
|
+
| ILiveQueryRef<T>
|
|
168
|
+
| ILiveQueryRefDef<T>,
|
|
169
|
+
otelContext?: otel.Context | undefined,
|
|
170
|
+
debugRefreshReason?: RefreshReason | undefined,
|
|
171
|
+
) => T
|
|
172
|
+
|
|
173
|
+
export type DependencyQueriesRef = Set<RcRef<LiveQueryAny | ILiveQueryRef<any>>>
|
|
174
|
+
|
|
175
|
+
export const makeGetAtomResult = (
|
|
176
|
+
get: RG.GetAtom,
|
|
177
|
+
ctx: ReactivityGraphContext,
|
|
178
|
+
otelContext: otel.Context,
|
|
179
|
+
dependencyQueriesRef: DependencyQueriesRef,
|
|
180
|
+
) => {
|
|
181
|
+
// NOTE we're using the `otelContext` from `makeGetAtomResult` here, not the `otelContext` from `getAtom`
|
|
182
|
+
const getAtom: GetAtomResult = (atom, _otelContext, debugRefreshReason) => {
|
|
183
|
+
// ReactivityGraph atoms case
|
|
184
|
+
if (atom._tag === 'thunk' || atom._tag === 'ref') return get(atom, otelContext, debugRefreshReason)
|
|
185
|
+
|
|
186
|
+
// LiveQueryDef case
|
|
187
|
+
if (atom._tag === 'def' || atom._tag === 'live-ref-def') {
|
|
188
|
+
const query = atom.make(ctx)
|
|
189
|
+
dependencyQueriesRef.add(query)
|
|
190
|
+
// TODO deref the query on destroy
|
|
191
|
+
return getAtom(query.value, _otelContext, debugRefreshReason)
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// LiveQueryRef case
|
|
195
|
+
if (atom._tag === 'live-ref') return get(atom.ref, otelContext, debugRefreshReason)
|
|
196
|
+
|
|
197
|
+
// LiveQuery case
|
|
198
|
+
return get(atom.results$, otelContext, debugRefreshReason)
|
|
118
199
|
}
|
|
119
200
|
|
|
120
201
|
return getAtom
|
|
121
202
|
}
|
|
203
|
+
|
|
204
|
+
export const withRCMap = <T extends LiveQueryAny | ILiveQueryRef<any>>(
|
|
205
|
+
id: string,
|
|
206
|
+
make: (ctx: ReactivityGraphContext, otelContext?: otel.Context) => T,
|
|
207
|
+
): ((ctx: ReactivityGraphContext, otelContext?: otel.Context) => RcRef<T>) => {
|
|
208
|
+
return (ctx, otelContext) => {
|
|
209
|
+
let item = ctx.defRcMap.get(id)
|
|
210
|
+
if (item) {
|
|
211
|
+
item.rc++
|
|
212
|
+
return item as RcRef<T>
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const query$ = make(ctx, otelContext)
|
|
216
|
+
|
|
217
|
+
item = {
|
|
218
|
+
rc: 1,
|
|
219
|
+
value: query$,
|
|
220
|
+
deref: () => {
|
|
221
|
+
item!.rc--
|
|
222
|
+
if (item!.rc === 0) {
|
|
223
|
+
item!.value.destroy()
|
|
224
|
+
}
|
|
225
|
+
ctx.defRcMap.delete(id)
|
|
226
|
+
},
|
|
227
|
+
}
|
|
228
|
+
ctx.defRcMap.set(id, item)
|
|
229
|
+
|
|
230
|
+
return item as RcRef<T>
|
|
231
|
+
}
|
|
232
|
+
}
|