@livestore/livestore 0.2.0 → 0.3.0-dev.11
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/SqliteDbWrapper.js +212 -0
- package/dist/SqliteDbWrapper.js.map +1 -0
- package/dist/SynchronousDatabaseWrapper.d.ts +20 -6
- package/dist/SynchronousDatabaseWrapper.d.ts.map +1 -1
- package/dist/SynchronousDatabaseWrapper.js +38 -6
- package/dist/SynchronousDatabaseWrapper.js.map +1 -1
- package/dist/__tests__/fixture.d.ts +252 -0
- package/dist/__tests__/fixture.d.ts.map +1 -0
- package/dist/__tests__/fixture.js +18 -0
- package/dist/__tests__/fixture.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 +64 -21
- package/dist/live-queries/base-class.d.ts.map +1 -1
- package/dist/live-queries/base-class.js +56 -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 +35 -11
- package/dist/live-queries/computed.js.map +1 -1
- package/dist/live-queries/{sql.d.ts → db-query.d.ts} +19 -14
- package/dist/live-queries/db-query.d.ts.map +1 -0
- package/dist/live-queries/db-query.js +244 -0
- 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 +123 -0
- package/dist/live-queries/db-query.test.js.map +1 -0
- package/dist/live-queries/db.d.ts +12 -15
- package/dist/live-queries/db.d.ts.map +1 -1
- package/dist/live-queries/db.js +72 -48
- package/dist/live-queries/db.js.map +1 -1
- package/dist/live-queries/db.test.js +18 -15
- package/dist/live-queries/db.test.js.map +1 -1
- 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 +35 -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 +15 -13
- package/dist/reactive.d.ts.map +1 -1
- package/dist/reactive.js +15 -9
- package/dist/reactive.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 +225 -188
- package/dist/store/store.js.map +1 -1
- package/dist/store/store.test.d.ts +2 -0
- package/dist/store/store.test.d.ts.map +1 -0
- package/dist/store/store.test.js +27 -0
- package/dist/store/store.test.js.map +1 -0
- 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/expo.d.ts +2 -0
- package/dist/utils/expo.d.ts.map +1 -0
- package/dist/utils/expo.js +8 -0
- package/dist/utils/expo.js.map +1 -0
- 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 -13
- 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 -69
- package/src/live-queries/base-class.ts +160 -40
- package/src/live-queries/computed.ts +45 -19
- package/src/live-queries/{db.test.ts → db-query.test.ts} +23 -12
- package/src/live-queries/{db.ts → db-query.ts} +124 -61
- package/src/live-queries/graphql.ts +47 -21
- package/src/live-queries/make-ref.ts +47 -0
- package/src/reactive.ts +52 -27
- 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 +361 -290
- 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/live-queries/sql.d.ts.map +0 -1
- package/dist/live-queries/sql.js +0 -175
- package/dist/live-queries/sql.js.map +0 -1
- package/dist/live-queries/sql.test.d.ts +0 -2
- package/dist/live-queries/sql.test.d.ts.map +0 -1
- package/dist/live-queries/sql.test.js +0 -285
- package/dist/live-queries/sql.test.js.map +0 -1
- package/dist/reactiveQueries/base-class.d.ts +0 -64
- package/dist/reactiveQueries/base-class.d.ts.map +0 -1
- package/dist/reactiveQueries/base-class.js +0 -31
- package/dist/reactiveQueries/base-class.js.map +0 -1
- package/dist/reactiveQueries/computed.d.ts +0 -26
- package/dist/reactiveQueries/computed.d.ts.map +0 -1
- package/dist/reactiveQueries/computed.js +0 -38
- package/dist/reactiveQueries/computed.js.map +0 -1
- package/dist/reactiveQueries/graphql.d.ts +0 -49
- package/dist/reactiveQueries/graphql.d.ts.map +0 -1
- package/dist/reactiveQueries/graphql.js +0 -122
- package/dist/reactiveQueries/graphql.js.map +0 -1
- package/dist/reactiveQueries/sql.d.ts +0 -62
- package/dist/reactiveQueries/sql.d.ts.map +0 -1
- package/dist/reactiveQueries/sql.js +0 -175
- package/dist/reactiveQueries/sql.js.map +0 -1
- package/dist/reactiveQueries/sql.test.d.ts +0 -2
- package/dist/reactiveQueries/sql.test.d.ts.map +0 -1
- package/dist/reactiveQueries/sql.test.js +0 -285
- package/dist/reactiveQueries/sql.test.js.map +0 -1
- package/dist/row-query.d.ts +0 -16
- package/dist/row-query.d.ts.map +0 -1
- package/dist/row-query.js +0 -30
- package/dist/row-query.js.map +0 -1
- package/src/global-state.ts +0 -20
|
@@ -1,285 +0,0 @@
|
|
|
1
|
-
import { Effect, Schema } from '@livestore/utils/effect';
|
|
2
|
-
import * as otel from '@opentelemetry/api';
|
|
3
|
-
import { BasicTracerProvider, InMemorySpanExporter, SimpleSpanProcessor } from '@opentelemetry/sdk-trace-base';
|
|
4
|
-
import { describe, expect, it } from 'vitest';
|
|
5
|
-
import { computed, queryDb, rawSqlMutation, sql } from '../index.js';
|
|
6
|
-
import { makeTodoMvc, tables } from '../utils/tests/fixture.js';
|
|
7
|
-
import { getSimplifiedRootSpan } from '../utils/tests/otel.js';
|
|
8
|
-
/*
|
|
9
|
-
TODO write tests for:
|
|
10
|
-
|
|
11
|
-
- sql queries without and with `map` (incl. callback and schemas)
|
|
12
|
-
- optional and explicit `queriedTables` argument
|
|
13
|
-
*/
|
|
14
|
-
describe('otel', () => {
|
|
15
|
-
let cachedProvider;
|
|
16
|
-
const makeQuery = Effect.gen(function* () {
|
|
17
|
-
const exporter = new InMemorySpanExporter();
|
|
18
|
-
const provider = cachedProvider ?? new BasicTracerProvider();
|
|
19
|
-
cachedProvider = provider;
|
|
20
|
-
provider.addSpanProcessor(new SimpleSpanProcessor(exporter));
|
|
21
|
-
provider.register();
|
|
22
|
-
const otelTracer = otel.trace.getTracer('test');
|
|
23
|
-
const span = otelTracer.startSpan('test');
|
|
24
|
-
const otelContext = otel.trace.setSpan(otel.context.active(), span);
|
|
25
|
-
const { store } = yield* makeTodoMvc({ otelTracer, otelContext });
|
|
26
|
-
return {
|
|
27
|
-
store,
|
|
28
|
-
otelTracer,
|
|
29
|
-
exporter,
|
|
30
|
-
span,
|
|
31
|
-
provider,
|
|
32
|
-
};
|
|
33
|
-
});
|
|
34
|
-
it('otel', async () => {
|
|
35
|
-
const { exporter } = await Effect.gen(function* () {
|
|
36
|
-
const { store, exporter, span } = yield* makeQuery;
|
|
37
|
-
const query$ = queryDb({
|
|
38
|
-
query: `select * from todos`,
|
|
39
|
-
schema: Schema.Array(tables.todos.schema),
|
|
40
|
-
queriedTables: new Set(['todos']),
|
|
41
|
-
});
|
|
42
|
-
expect(query$.run()).toMatchInlineSnapshot('[]');
|
|
43
|
-
store.mutate(rawSqlMutation({ sql: sql `INSERT INTO todos (id, text, completed) VALUES ('t1', 'buy milk', 0)` }));
|
|
44
|
-
expect(query$.run()).toMatchInlineSnapshot(`
|
|
45
|
-
[
|
|
46
|
-
{
|
|
47
|
-
"completed": false,
|
|
48
|
-
"id": "t1",
|
|
49
|
-
"text": "buy milk",
|
|
50
|
-
},
|
|
51
|
-
]
|
|
52
|
-
`);
|
|
53
|
-
query$.destroy();
|
|
54
|
-
span.end();
|
|
55
|
-
return { exporter };
|
|
56
|
-
}).pipe(Effect.scoped, Effect.tapCauseLogPretty, Effect.runPromise);
|
|
57
|
-
expect(getSimplifiedRootSpan(exporter)).toMatchInlineSnapshot(`
|
|
58
|
-
{
|
|
59
|
-
"_name": "test",
|
|
60
|
-
"children": [
|
|
61
|
-
{
|
|
62
|
-
"_name": "livestore.in-memory-db:execute",
|
|
63
|
-
"attributes": {
|
|
64
|
-
"sql.query": "
|
|
65
|
-
PRAGMA page_size=32768;
|
|
66
|
-
PRAGMA cache_size=10000;
|
|
67
|
-
PRAGMA journal_mode='MEMORY'; -- we don't flush to disk before committing a write
|
|
68
|
-
PRAGMA synchronous='OFF';
|
|
69
|
-
PRAGMA temp_store='MEMORY';
|
|
70
|
-
PRAGMA foreign_keys='ON'; -- we want foreign key constraints to be enforced
|
|
71
|
-
",
|
|
72
|
-
},
|
|
73
|
-
},
|
|
74
|
-
{
|
|
75
|
-
"_name": "LiveStore:mutations",
|
|
76
|
-
"children": [
|
|
77
|
-
{
|
|
78
|
-
"_name": "LiveStore:mutate",
|
|
79
|
-
"attributes": {
|
|
80
|
-
"livestore.mutateLabel": "mutate",
|
|
81
|
-
},
|
|
82
|
-
"children": [
|
|
83
|
-
{
|
|
84
|
-
"_name": "LiveStore:processWrites",
|
|
85
|
-
"attributes": {
|
|
86
|
-
"livestore.mutateLabel": "mutate",
|
|
87
|
-
},
|
|
88
|
-
"children": [
|
|
89
|
-
{
|
|
90
|
-
"_name": "LiveStore:mutateWithoutRefresh",
|
|
91
|
-
"attributes": {
|
|
92
|
-
"livestore.args": "{
|
|
93
|
-
"sql": "INSERT INTO todos (id, text, completed) VALUES ('t1', 'buy milk', 0)"
|
|
94
|
-
}",
|
|
95
|
-
"livestore.mutation": "livestore.RawSql",
|
|
96
|
-
},
|
|
97
|
-
"children": [
|
|
98
|
-
{
|
|
99
|
-
"_name": "livestore.in-memory-db:execute",
|
|
100
|
-
"attributes": {
|
|
101
|
-
"sql.query": "INSERT INTO todos (id, text, completed) VALUES ('t1', 'buy milk', 0)",
|
|
102
|
-
},
|
|
103
|
-
},
|
|
104
|
-
],
|
|
105
|
-
},
|
|
106
|
-
],
|
|
107
|
-
},
|
|
108
|
-
],
|
|
109
|
-
},
|
|
110
|
-
],
|
|
111
|
-
},
|
|
112
|
-
{
|
|
113
|
-
"_name": "LiveStore:queries",
|
|
114
|
-
"children": [
|
|
115
|
-
{
|
|
116
|
-
"_name": "sql:select * from todos",
|
|
117
|
-
"attributes": {
|
|
118
|
-
"sql.query": "select * from todos",
|
|
119
|
-
"sql.rowsCount": 0,
|
|
120
|
-
},
|
|
121
|
-
"children": [
|
|
122
|
-
{
|
|
123
|
-
"_name": "sql-in-memory-select",
|
|
124
|
-
"attributes": {
|
|
125
|
-
"sql.cached": false,
|
|
126
|
-
"sql.query": "select * from todos",
|
|
127
|
-
"sql.rowsCount": 0,
|
|
128
|
-
},
|
|
129
|
-
},
|
|
130
|
-
],
|
|
131
|
-
},
|
|
132
|
-
{
|
|
133
|
-
"_name": "sql:select * from todos",
|
|
134
|
-
"attributes": {
|
|
135
|
-
"sql.query": "select * from todos",
|
|
136
|
-
"sql.rowsCount": 1,
|
|
137
|
-
},
|
|
138
|
-
"children": [
|
|
139
|
-
{
|
|
140
|
-
"_name": "sql-in-memory-select",
|
|
141
|
-
"attributes": {
|
|
142
|
-
"sql.cached": false,
|
|
143
|
-
"sql.query": "select * from todos",
|
|
144
|
-
"sql.rowsCount": 1,
|
|
145
|
-
},
|
|
146
|
-
},
|
|
147
|
-
],
|
|
148
|
-
},
|
|
149
|
-
],
|
|
150
|
-
},
|
|
151
|
-
],
|
|
152
|
-
}
|
|
153
|
-
`);
|
|
154
|
-
});
|
|
155
|
-
it('with thunks', async () => {
|
|
156
|
-
const { exporter } = await Effect.gen(function* () {
|
|
157
|
-
const { store, exporter, span } = yield* makeQuery;
|
|
158
|
-
const defaultTodo = { id: '', text: '', completed: false };
|
|
159
|
-
const filter = computed(() => `where completed = 0`, { label: 'where-filter' });
|
|
160
|
-
const query$ = queryDb((get) => ({
|
|
161
|
-
query: `select * from todos ${get(filter)}`,
|
|
162
|
-
schema: Schema.Array(tables.todos.schema).pipe(Schema.headOrElse(() => defaultTodo)),
|
|
163
|
-
}), { label: 'all todos' });
|
|
164
|
-
expect(query$.run()).toMatchInlineSnapshot(`
|
|
165
|
-
{
|
|
166
|
-
"completed": false,
|
|
167
|
-
"id": "",
|
|
168
|
-
"text": "",
|
|
169
|
-
}
|
|
170
|
-
`);
|
|
171
|
-
store.mutate(rawSqlMutation({ sql: sql `INSERT INTO todos (id, text, completed) VALUES ('t1', 'buy milk', 0)` }));
|
|
172
|
-
expect(query$.run()).toMatchInlineSnapshot(`
|
|
173
|
-
{
|
|
174
|
-
"completed": false,
|
|
175
|
-
"id": "t1",
|
|
176
|
-
"text": "buy milk",
|
|
177
|
-
}
|
|
178
|
-
`);
|
|
179
|
-
query$.destroy();
|
|
180
|
-
span.end();
|
|
181
|
-
return { exporter };
|
|
182
|
-
}).pipe(Effect.scoped, Effect.tapCauseLogPretty, Effect.runPromise);
|
|
183
|
-
expect(getSimplifiedRootSpan(exporter)).toMatchInlineSnapshot(`
|
|
184
|
-
{
|
|
185
|
-
"_name": "test",
|
|
186
|
-
"children": [
|
|
187
|
-
{
|
|
188
|
-
"_name": "livestore.in-memory-db:execute",
|
|
189
|
-
"attributes": {
|
|
190
|
-
"sql.query": "
|
|
191
|
-
PRAGMA page_size=32768;
|
|
192
|
-
PRAGMA cache_size=10000;
|
|
193
|
-
PRAGMA journal_mode='MEMORY'; -- we don't flush to disk before committing a write
|
|
194
|
-
PRAGMA synchronous='OFF';
|
|
195
|
-
PRAGMA temp_store='MEMORY';
|
|
196
|
-
PRAGMA foreign_keys='ON'; -- we want foreign key constraints to be enforced
|
|
197
|
-
",
|
|
198
|
-
},
|
|
199
|
-
},
|
|
200
|
-
{
|
|
201
|
-
"_name": "LiveStore:mutations",
|
|
202
|
-
"children": [
|
|
203
|
-
{
|
|
204
|
-
"_name": "LiveStore:mutate",
|
|
205
|
-
"attributes": {
|
|
206
|
-
"livestore.mutateLabel": "mutate",
|
|
207
|
-
},
|
|
208
|
-
"children": [
|
|
209
|
-
{
|
|
210
|
-
"_name": "LiveStore:processWrites",
|
|
211
|
-
"attributes": {
|
|
212
|
-
"livestore.mutateLabel": "mutate",
|
|
213
|
-
},
|
|
214
|
-
"children": [
|
|
215
|
-
{
|
|
216
|
-
"_name": "LiveStore:mutateWithoutRefresh",
|
|
217
|
-
"attributes": {
|
|
218
|
-
"livestore.args": "{
|
|
219
|
-
"sql": "INSERT INTO todos (id, text, completed) VALUES ('t1', 'buy milk', 0)"
|
|
220
|
-
}",
|
|
221
|
-
"livestore.mutation": "livestore.RawSql",
|
|
222
|
-
},
|
|
223
|
-
"children": [
|
|
224
|
-
{
|
|
225
|
-
"_name": "livestore.in-memory-db:execute",
|
|
226
|
-
"attributes": {
|
|
227
|
-
"sql.query": "INSERT INTO todos (id, text, completed) VALUES ('t1', 'buy milk', 0)",
|
|
228
|
-
},
|
|
229
|
-
},
|
|
230
|
-
],
|
|
231
|
-
},
|
|
232
|
-
],
|
|
233
|
-
},
|
|
234
|
-
],
|
|
235
|
-
},
|
|
236
|
-
],
|
|
237
|
-
},
|
|
238
|
-
{
|
|
239
|
-
"_name": "LiveStore:queries",
|
|
240
|
-
"children": [
|
|
241
|
-
{
|
|
242
|
-
"_name": "sql:select * from todos where completed = 0",
|
|
243
|
-
"attributes": {
|
|
244
|
-
"sql.query": "select * from todos where completed = 0",
|
|
245
|
-
"sql.rowsCount": 0,
|
|
246
|
-
},
|
|
247
|
-
"children": [
|
|
248
|
-
{
|
|
249
|
-
"_name": "js:where-filter",
|
|
250
|
-
},
|
|
251
|
-
{
|
|
252
|
-
"_name": "sql-in-memory-select",
|
|
253
|
-
"attributes": {
|
|
254
|
-
"sql.cached": false,
|
|
255
|
-
"sql.query": "select * from todos where completed = 0",
|
|
256
|
-
"sql.rowsCount": 0,
|
|
257
|
-
},
|
|
258
|
-
},
|
|
259
|
-
],
|
|
260
|
-
},
|
|
261
|
-
{
|
|
262
|
-
"_name": "sql:select * from todos where completed = 0",
|
|
263
|
-
"attributes": {
|
|
264
|
-
"sql.query": "select * from todos where completed = 0",
|
|
265
|
-
"sql.rowsCount": 1,
|
|
266
|
-
},
|
|
267
|
-
"children": [
|
|
268
|
-
{
|
|
269
|
-
"_name": "sql-in-memory-select",
|
|
270
|
-
"attributes": {
|
|
271
|
-
"sql.cached": false,
|
|
272
|
-
"sql.query": "select * from todos where completed = 0",
|
|
273
|
-
"sql.rowsCount": 1,
|
|
274
|
-
},
|
|
275
|
-
},
|
|
276
|
-
],
|
|
277
|
-
},
|
|
278
|
-
],
|
|
279
|
-
},
|
|
280
|
-
],
|
|
281
|
-
}
|
|
282
|
-
`);
|
|
283
|
-
});
|
|
284
|
-
});
|
|
285
|
-
//# sourceMappingURL=sql.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sql.test.js","sourceRoot":"","sources":["../../src/live-queries/sql.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,KAAK,IAAI,MAAM,oBAAoB,CAAA;AAC1C,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAA;AAC9G,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAE7C,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,EAAE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;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAmG7D,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import type { QueryInfo } from '@livestore/common';
|
|
2
|
-
import type * as otel from '@opentelemetry/api';
|
|
3
|
-
import { type Atom, type GetAtom, ReactiveGraph, type Thunk } from '../reactive.js';
|
|
4
|
-
import type { Store } from '../store/store.js';
|
|
5
|
-
import type { QueryDebugInfo, RefreshReason } from '../store/store-types.js';
|
|
6
|
-
import type { StackInfo } from '../utils/stack-info.js';
|
|
7
|
-
export type ReactivityGraph = ReactiveGraph<RefreshReason, QueryDebugInfo, QueryContext>;
|
|
8
|
-
export declare const makeReactivityGraph: () => ReactivityGraph;
|
|
9
|
-
export type QueryContext = {
|
|
10
|
-
store: Store;
|
|
11
|
-
otelTracer: otel.Tracer;
|
|
12
|
-
rootOtelContext: otel.Context;
|
|
13
|
-
effectsWrapper: (run: () => void) => void;
|
|
14
|
-
};
|
|
15
|
-
export type UnsubscribeQuery = () => void;
|
|
16
|
-
export type GetResult<TQuery extends LiveQueryAny> = TQuery extends LiveQuery<infer TResult, infer _1> ? TResult : unknown;
|
|
17
|
-
export type LiveQueryAny = LiveQuery<any, QueryInfo>;
|
|
18
|
-
export declare const TypeId: unique symbol;
|
|
19
|
-
export type TypeId = typeof TypeId;
|
|
20
|
-
export interface LiveQuery<TResult, TQueryInfo extends QueryInfo = QueryInfo.None> {
|
|
21
|
-
id: number;
|
|
22
|
-
_tag: 'computed' | 'sql' | 'graphql';
|
|
23
|
-
[TypeId]: TypeId;
|
|
24
|
-
/** This should only be used on a type-level and doesn't hold any value during runtime */
|
|
25
|
-
'__result!': TResult;
|
|
26
|
-
/** A reactive thunk representing the query results */
|
|
27
|
-
results$: Thunk<TResult, QueryContext, RefreshReason>;
|
|
28
|
-
label: string;
|
|
29
|
-
run: (otelContext?: otel.Context, debugRefreshReason?: RefreshReason) => TResult;
|
|
30
|
-
runAndDestroy: (otelContext?: otel.Context, debugRefreshReason?: RefreshReason) => TResult;
|
|
31
|
-
destroy(): void;
|
|
32
|
-
subscribe(onNewValue: (value: TResult) => void, onUnsubsubscribe?: () => void, options?: {
|
|
33
|
-
label?: string;
|
|
34
|
-
otelContext?: otel.Context;
|
|
35
|
-
}): () => void;
|
|
36
|
-
activeSubscriptions: Set<StackInfo>;
|
|
37
|
-
queryInfo: TQueryInfo;
|
|
38
|
-
runs: number;
|
|
39
|
-
executionTimes: number[];
|
|
40
|
-
}
|
|
41
|
-
export declare abstract class LiveStoreQueryBase<TResult, TQueryInfo extends QueryInfo> implements LiveQuery<TResult, TQueryInfo> {
|
|
42
|
-
'__result!': TResult;
|
|
43
|
-
id: number;
|
|
44
|
-
[TypeId]: TypeId;
|
|
45
|
-
abstract _tag: 'computed' | 'sql' | 'graphql';
|
|
46
|
-
/** Human-readable label for the query for debugging */
|
|
47
|
-
abstract label: string;
|
|
48
|
-
abstract results$: Thunk<TResult, QueryContext, RefreshReason>;
|
|
49
|
-
activeSubscriptions: Set<StackInfo>;
|
|
50
|
-
protected abstract reactivityGraph: ReactivityGraph;
|
|
51
|
-
abstract queryInfo: TQueryInfo;
|
|
52
|
-
get runs(): number;
|
|
53
|
-
executionTimes: number[];
|
|
54
|
-
abstract destroy: () => void;
|
|
55
|
-
run: (otelContext?: otel.Context, debugRefreshReason?: RefreshReason) => TResult;
|
|
56
|
-
runAndDestroy: (otelContext?: otel.Context, debugRefreshReason?: RefreshReason) => TResult;
|
|
57
|
-
subscribe: (onNewValue: (value: TResult) => void, onUnsubsubscribe?: () => void, options?: {
|
|
58
|
-
label?: string;
|
|
59
|
-
otelContext?: otel.Context;
|
|
60
|
-
} | undefined) => (() => void);
|
|
61
|
-
}
|
|
62
|
-
export type GetAtomResult = <T>(atom: Atom<T, any, RefreshReason> | LiveQuery<T, any>) => T;
|
|
63
|
-
export declare const makeGetAtomResult: (get: GetAtom, otelContext: otel.Context) => Get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=> new ReactiveGraph();
|
|
3
|
-
let queryIdCounter = 0;
|
|
4
|
-
export const TypeId = Symbol.for('LiveQuery');
|
|
5
|
-
export class LiveStoreQueryBase {
|
|
6
|
-
'__result!';
|
|
7
|
-
id = queryIdCounter++;
|
|
8
|
-
[TypeId] = TypeId;
|
|
9
|
-
activeSubscriptions = new Set();
|
|
10
|
-
get runs() {
|
|
11
|
-
return this.results$.recomputations;
|
|
12
|
-
}
|
|
13
|
-
executionTimes = [];
|
|
14
|
-
run = (otelContext, debugRefreshReason) => this.results$.computeResult(otelContext, debugRefreshReason);
|
|
15
|
-
runAndDestroy = (otelContext, debugRefreshReason) => {
|
|
16
|
-
const result = this.run(otelContext, debugRefreshReason);
|
|
17
|
-
this.destroy();
|
|
18
|
-
return result;
|
|
19
|
-
};
|
|
20
|
-
subscribe = (onNewValue, onUnsubsubscribe, options) => this.reactivityGraph.context?.store.subscribe(this, onNewValue, onUnsubsubscribe, options) ??
|
|
21
|
-
throwContextNotSetError(this.reactivityGraph);
|
|
22
|
-
}
|
|
23
|
-
export const makeGetAtomResult = (get, otelContext) => {
|
|
24
|
-
const getAtom = (atom) => {
|
|
25
|
-
if (atom._tag === 'thunk' || atom._tag === 'ref')
|
|
26
|
-
return get(atom, otelContext);
|
|
27
|
-
return get(atom.results$, otelContext);
|
|
28
|
-
};
|
|
29
|
-
return getAtom;
|
|
30
|
-
};
|
|
31
|
-
//# sourceMappingURL=base-class.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"base-class.js","sourceRoot":"","sources":["../../src/reactiveQueries/base-class.ts"],"names":[],"mappings":"AAGA,OAAO,EAA2B,aAAa,EAAE,uBAAuB,EAAc,MAAM,gBAAgB,CAAA;AAO5G,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAoB,EAAE,CACvD,IAAI,aAAa,EAA+C,CAAA;AAclE,IAAI,cAAc,GAAG,CAAC,CAAA;AAItB,MAAM,CAAC,MAAM,MAAM,GAAG,MAAM,C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,CAAA;IACxC,CAAC,CAAA;IAED,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA"}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { QueryInfo } from '@livestore/common';
|
|
2
|
-
import type { Thunk } from '../reactive.js';
|
|
3
|
-
import type { RefreshReason } from '../store/store-types.js';
|
|
4
|
-
import type { GetAtomResult, LiveQuery, QueryContext, ReactivityGraph } from './base-class.js';
|
|
5
|
-
import { LiveStoreQueryBase } from './base-class.js';
|
|
6
|
-
export declare const computed: <TResult, TQueryInfo extends QueryInfo = QueryInfo.None>(fn: (get: GetAtomResult) => TResult, options?: {
|
|
7
|
-
label: string;
|
|
8
|
-
reactivityGraph?: ReactivityGraph;
|
|
9
|
-
queryInfo?: TQueryInfo;
|
|
10
|
-
}) => LiveQuery<TResult, TQueryInfo>;
|
|
11
|
-
export declare class LiveStoreJSQuery<TResult, TQueryInfo extends QueryInfo = QueryInfo.None> extends LiveStoreQueryBase<TResult, TQueryInfo> {
|
|
12
|
-
_tag: 'computed';
|
|
13
|
-
/** A reactive thunk representing the query results */
|
|
14
|
-
results$: Thunk<TResult, QueryContext, RefreshReason>;
|
|
15
|
-
label: string;
|
|
16
|
-
protected reactivityGraph: ReactivityGraph;
|
|
17
|
-
queryInfo: TQueryInfo;
|
|
18
|
-
constructor({ fn, label, reactivityGraph, queryInfo, }: {
|
|
19
|
-
label: string;
|
|
20
|
-
fn: (get: GetAtomResult) => TResult;
|
|
21
|
-
reactivityGraph?: ReactivityGraph;
|
|
22
|
-
queryInfo?: TQueryInfo;
|
|
23
|
-
});
|
|
24
|
-
destroy: () => void;
|
|
25
|
-
}
|
|
26
|
-
//# sourceMappingURL=computed.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"computed.d.ts","sourceRoot":"","sources":["../../src/reactiveQueries/computed.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAIlD,OA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3
|
-
import { getDurationMsFromSpan } from '../utils/otel.js';
|
|
4
|
-
import { LiveStoreQueryBase, makeGetAtomResult } from './base-class.js';
|
|
5
|
-
export const computed = (fn, options) => new LiveStoreJSQuery({
|
|
6
|
-
fn,
|
|
7
|
-
label: options?.label ?? fn.toString(),
|
|
8
|
-
reactivityGraph: options?.reactivityGraph,
|
|
9
|
-
queryInfo: options?.queryInfo,
|
|
10
|
-
});
|
|
11
|
-
export class LiveStoreJSQuery extends LiveStoreQueryBase {
|
|
12
|
-
_tag = 'computed';
|
|
13
|
-
/** A reactive thunk representing the query results */
|
|
14
|
-
results$;
|
|
15
|
-
label;
|
|
16
|
-
reactivityGraph;
|
|
17
|
-
queryInfo;
|
|
18
|
-
constructor({ fn, label, reactivityGraph, queryInfo, }) {
|
|
19
|
-
super();
|
|
20
|
-
this.label = label;
|
|
21
|
-
this.reactivityGraph = reactivityGraph ?? globalReactivityGraph;
|
|
22
|
-
this.queryInfo = queryInfo ?? { _tag: 'None' };
|
|
23
|
-
const queryLabel = `${label}:results`;
|
|
24
|
-
this.results$ = this.reactivityGraph.makeThunk((get, setDebugInfo, { otelTracer, rootOtelContext }, otelContext) => otelTracer.startActiveSpan(`js:${label}`, {}, otelContext ?? rootOtelContext, (span) => {
|
|
25
|
-
const otelContext = otel.trace.setSpan(otel.context.active(), span);
|
|
26
|
-
const res = fn(makeGetAtomResult(get, otelContext));
|
|
27
|
-
span.end();
|
|
28
|
-
const durationMs = getDurationMsFromSpan(span);
|
|
29
|
-
this.executionTimes.push(durationMs);
|
|
30
|
-
setDebugInfo({ _tag: 'computed', label, query: fn.toString(), durationMs });
|
|
31
|
-
return res;
|
|
32
|
-
}), { label: queryLabel, meta: { liveStoreThunkType: 'computedResults' } });
|
|
33
|
-
}
|
|
34
|
-
destroy = () => {
|
|
35
|
-
this.reactivityGraph.destroyNode(this.results$);
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
//# sourceMappingURL=computed.js.map
|
|
@@ -1 +0,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,eAAe,CAAC,MAAM,KAAK,EAAE,EAAE,EAAE,EAAE,WAAW,IAAI,eAAe,EAAE,CAAC,IAAI,EAAE,EAAE;YACrF,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,IAAI,CAAC,CAAA;YACnE,MAAM,GAAG,GAAG,EAAE,CAAC,iBAAiB,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC,CAAA;YAEnD,IAAI,CAAC,GAAG,EAAE,CAAA;YAEV,MAAM,UAAU,GAAG,qBAAqB,CAAC,IAAI,CAAC,CAAA;YAE9C,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;YAEpC,YAAY,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,QAAQ,EAAE,EAAE,UAAU,EAAE,CAAC,CAAA;YAE3E,OAAO,GAAG,CAAA;QACZ,CAAC,CAAC,EACJ,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,EAAE,CACvE,CAAA;IACH,CAAC;IAED,OAAO,GAAG,GAAG,EAAE;QACb,IAAI,CAAC,eAAe,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;IACjD,CAAC,CAAA;CACF"}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import type { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core';
|
|
2
|
-
import type { QueryInfo } from '@livestore/common';
|
|
3
|
-
import { Schema } from '@livestore/utils/effect';
|
|
4
|
-
import * as otel from '@opentelemetry/api';
|
|
5
|
-
import * as graphql from 'graphql';
|
|
6
|
-
import { type Thunk } from '../reactive.js';
|
|
7
|
-
import type { Store } from '../store/store.js';
|
|
8
|
-
import type { BaseGraphQLContext, RefreshReason } from '../store/store-types.js';
|
|
9
|
-
import type { GetAtomResult, LiveQuery, QueryContext, ReactivityGraph } from './base-class.js';
|
|
10
|
-
import { LiveStoreQueryBase } from './base-class.js';
|
|
11
|
-
export type MapResult<To, From> = ((res: From, get: GetAtomResult) => To) | Schema.Schema<To, From>;
|
|
12
|
-
export declare const queryGraphQL: <TResult extends Record<string, any>, TVariableValues extends Record<string, any>, TResultMapped extends Record<string, any> = TResult>(document: DocumentNode<TResult, TVariableValues>, genVariableValues: TVariableValues | ((get: GetAtomResult) => TVariableValues), { label, reactivityGraph, map, }?: {
|
|
13
|
-
label?: string;
|
|
14
|
-
reactivityGraph?: ReactivityGraph;
|
|
15
|
-
map?: MapResult<TResultMapped, TResult>;
|
|
16
|
-
}) => LiveQuery<TResultMapped, QueryInfo.None>;
|
|
17
|
-
export declare class LiveStoreGraphQLQuery<TResult extends Record<string, any>, TVariableValues extends Record<string, any>, TContext extends BaseGraphQLContext, TResultMapped extends Record<string, any> = TResult> extends LiveStoreQueryBase<TResultMapped, QueryInfo.None> {
|
|
18
|
-
_tag: 'graphql';
|
|
19
|
-
/** The abstract GraphQL query */
|
|
20
|
-
document: DocumentNode<TResult, TVariableValues>;
|
|
21
|
-
/** A reactive thunk representing the query results */
|
|
22
|
-
results$: Thunk<TResultMapped, QueryContext, RefreshReason>;
|
|
23
|
-
variableValues$: Thunk<TVariableValues, QueryContext, RefreshReason> | undefined;
|
|
24
|
-
label: string;
|
|
25
|
-
protected reactivityGraph: ReactivityGraph;
|
|
26
|
-
queryInfo: QueryInfo.None;
|
|
27
|
-
private mapResult;
|
|
28
|
-
constructor({ document, label, genVariableValues, reactivityGraph, map, }: {
|
|
29
|
-
document: DocumentNode<TResult, TVariableValues>;
|
|
30
|
-
genVariableValues: TVariableValues | ((get: GetAtomResult) => TVariableValues);
|
|
31
|
-
label?: string;
|
|
32
|
-
reactivityGraph?: ReactivityGraph;
|
|
33
|
-
map?: MapResult<TResultMapped, TResult>;
|
|
34
|
-
});
|
|
35
|
-
queryOnce: ({ document, otelContext, otelTracer, variableValues, store, get, }: {
|
|
36
|
-
document: graphql.DocumentNode;
|
|
37
|
-
otelContext: otel.Context;
|
|
38
|
-
otelTracer: otel.Tracer;
|
|
39
|
-
variableValues: TVariableValues;
|
|
40
|
-
store: Store<TContext>;
|
|
41
|
-
get: GetAtomResult;
|
|
42
|
-
}) => {
|
|
43
|
-
result: TResultMapped;
|
|
44
|
-
queriedTables: string[];
|
|
45
|
-
durationMs: number;
|
|
46
|
-
};
|
|
47
|
-
destroy: () => void;
|
|
48
|
-
}
|
|
49
|
-
//# sourceMappingURL=graphql.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"graphql.d.ts","sourceRoot":"","sources":["../../src/reactiveQueries/graphql.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,IAAI,YAAY,EAAE,MAAM,mCAAmC,CAAA;AAC1F,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAElD,OAAO,EAAE,MAAM,EAAiB,MAAM,yBAAyB,CAAA;AAC/D,OAAO,KAAK,IAAI,MAAM,oBAAoB,CAAA;AAC1C,OAAO,KAAK,OAAO,MAAM,SAAS,CAAA;AAGlC,OAAO,EAAW,KAAK,KAAK,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAC9C,OAAO,KAAK,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AAEhF,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAC9F,OAAO,EAAE,kBAAkB,EAAqB,MAAM,iBAAiB,CAAA;AAEvE,MAAM,MAAM,SAAS,CAAC,EAAE,EAAE,IAAI,IAAI,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,aAAa,KAAK,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,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,OAAO,CAAC,SAAS,CAAA;gBAEL,EACV,QAAQ,EACR,KAAK,EACL,iBAAiB,EACjB,eAAe,EACf,GAAG,GACJ,EAAE;QACD,QAAQ,EAAE,YAAY,CAAC,OAAO,EAAE,eAAe,CAAC,CAAA;QAChD,iBAAiB,EAAE,eAAe,GAAG,CAAC,CAAC,GAAG,EAAE,aAAa,KAAK,eAAe,CAAC,CAAA;QAC9E,KAAK,CAAC,EAAE,MAAM,CAAA;QACd,eAAe,CAAC,EAAE,eAAe,CAAA;QACjC,GAAG,CAAC,EAAE,SAAS,CAAC,aAAa,EAAE,OAAO,CAAC,CAAA;KACxC;IAwED,SAAS,uEAON;QACD,QAAQ,EAAE,OAAO,CAAC,YAAY,CAAA;QAC9B,WAAW,EAAE,IAAI,CAAC,OAAO,CAAA;QACzB,UAAU,EAAE,IAAI,CAAC,MAAM,CAAA;QACvB,cAAc,EAAE,eAAe,CAAA;QAC/B,KAAK,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAA;QACtB,GAAG,EAAE,aAAa,CAAA;KACnB;;;;MAmDA;IAED,OAAO,aAMN;CACF"}
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import { shouldNeverHappen } from '@livestore/utils';
|
|
2
|
-
import { Schema, TreeFormatter } from '@livestore/utils/effect';
|
|
3
|
-
import * as otel from '@opentelemetry/api';
|
|
4
|
-
import * as graphql from 'graphql';
|
|
5
|
-
import { globalReactivityGraph } from '../global-state.js';
|
|
6
|
-
import { isThunk } from '../reactive.js';
|
|
7
|
-
import { getDurationMsFromSpan } from '../utils/otel.js';
|
|
8
|
-
import { LiveStoreQueryBase, makeGetAtomResult } from './base-class.js';
|
|
9
|
-
export const queryGraphQL = (document, genVariableValues, { label, reactivityGraph, map, } = {}) => new LiveStoreGraphQLQuery({ document, genVariableValues, label, reactivityGraph, map });
|
|
10
|
-
export class LiveStoreGraphQLQuery extends LiveStoreQueryBase {
|
|
11
|
-
_tag = 'graphql';
|
|
12
|
-
/** The abstract GraphQL query */
|
|
13
|
-
document;
|
|
14
|
-
/** A reactive thunk representing the query results */
|
|
15
|
-
results$;
|
|
16
|
-
variableValues$;
|
|
17
|
-
label;
|
|
18
|
-
reactivityGraph;
|
|
19
|
-
queryInfo = { _tag: 'None' };
|
|
20
|
-
mapResult;
|
|
21
|
-
constructor({ document, label, genVariableValues, reactivityGraph, map, }) {
|
|
22
|
-
super();
|
|
23
|
-
const labelWithDefault = label ?? graphql.getOperationAST(document)?.name?.value ?? 'graphql';
|
|
24
|
-
this.label = labelWithDefault;
|
|
25
|
-
this.document = document;
|
|
26
|
-
this.reactivityGraph = reactivityGraph ?? globalReactivityGraph;
|
|
27
|
-
this.mapResult =
|
|
28
|
-
map === undefined
|
|
29
|
-
? (res) => res
|
|
30
|
-
: Schema.isSchema(map)
|
|
31
|
-
? (res) => {
|
|
32
|
-
const parseResult = Schema.decodeEither(map)(res);
|
|
33
|
-
if (parseResult._tag === 'Left') {
|
|
34
|
-
console.error(`Error parsing GraphQL query result: ${TreeFormatter.formatErrorSync(parseResult.left)}`);
|
|
35
|
-
return shouldNeverHappen(`Error parsing SQL query result: ${parseResult.left}`);
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
return parseResult.right;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
: typeof map === 'function'
|
|
42
|
-
? map
|
|
43
|
-
: shouldNeverHappen(`Invalid map function ${map}`);
|
|
44
|
-
// TODO don't even create a thunk if variables are static
|
|
45
|
-
let variableValues$OrvariableValues;
|
|
46
|
-
if (typeof genVariableValues === 'function') {
|
|
47
|
-
variableValues$OrvariableValues = this.reactivityGraph.makeThunk((get, _setDebugInfo, { rootOtelContext }, otelContext) => {
|
|
48
|
-
return genVariableValues(makeGetAtomResult(get, otelContext ?? rootOtelContext));
|
|
49
|
-
}, { label: `${labelWithDefault}:variableValues`, meta: { liveStoreThunkType: 'graphqlQuery' } });
|
|
50
|
-
this.variableValues$ = variableValues$OrvariableValues;
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
variableValues$OrvariableValues = genVariableValues;
|
|
54
|
-
}
|
|
55
|
-
const resultsLabel = `${labelWithDefault}:results`;
|
|
56
|
-
this.results$ = this.reactivityGraph.makeThunk((get, setDebugInfo, { store, otelTracer, rootOtelContext }, otelContext) => {
|
|
57
|
-
const variableValues = isThunk(variableValues$OrvariableValues)
|
|
58
|
-
? get(variableValues$OrvariableValues)
|
|
59
|
-
: variableValues$OrvariableValues;
|
|
60
|
-
const { result, queriedTables, durationMs } = this.queryOnce({
|
|
61
|
-
document,
|
|
62
|
-
variableValues,
|
|
63
|
-
otelContext: otelContext ?? rootOtelContext,
|
|
64
|
-
otelTracer,
|
|
65
|
-
store: store,
|
|
66
|
-
get: makeGetAtomResult(get, otelContext ?? rootOtelContext),
|
|
67
|
-
});
|
|
68
|
-
// Add dependencies on any tables that were used
|
|
69
|
-
for (const tableName of queriedTables) {
|
|
70
|
-
const tableRef = store.tableRefs[tableName] ?? shouldNeverHappen(`No table ref found for ${tableName}`);
|
|
71
|
-
get(tableRef);
|
|
72
|
-
}
|
|
73
|
-
setDebugInfo({ _tag: 'graphql', label: resultsLabel, query: graphql.print(document), durationMs });
|
|
74
|
-
return result;
|
|
75
|
-
}, { label: resultsLabel, meta: { liveStoreThunkType: 'graphqlResults' } });
|
|
76
|
-
}
|
|
77
|
-
queryOnce = ({ document, otelContext, otelTracer, variableValues, store, get, }) => {
|
|
78
|
-
const schema = store.graphQLSchema ?? shouldNeverHappen("Can't run a GraphQL query on a store without GraphQL schema");
|
|
79
|
-
const context = store.graphQLContext ?? shouldNeverHappen("Can't run a GraphQL query on a store without GraphQL context");
|
|
80
|
-
const operationName = graphql.getOperationAST(document)?.name?.value;
|
|
81
|
-
return otelTracer.startActiveSpan(`executeGraphQLQuery: ${operationName}`, {}, otelContext, (span) => {
|
|
82
|
-
span.setAttribute('graphql.variables', JSON.stringify(variableValues));
|
|
83
|
-
span.setAttribute('graphql.query', graphql.print(document));
|
|
84
|
-
context.queriedTables.clear();
|
|
85
|
-
context.otelContext = otel.trace.setSpan(otel.context.active(), span);
|
|
86
|
-
const res = graphql.executeSync({
|
|
87
|
-
document,
|
|
88
|
-
contextValue: context,
|
|
89
|
-
schema: schema,
|
|
90
|
-
variableValues,
|
|
91
|
-
});
|
|
92
|
-
// TODO track number of nested SQL queries via Otel + debug info
|
|
93
|
-
if (res.errors) {
|
|
94
|
-
span.setStatus({ code: otel.SpanStatusCode.ERROR, message: 'GraphQL error' });
|
|
95
|
-
span.setAttribute('graphql.error', res.errors.join('\n'));
|
|
96
|
-
span.setAttribute('graphql.error-detail', JSON.stringify(res.errors));
|
|
97
|
-
console.error(`graphql error (${operationName}) - ${res.errors.length} errors`);
|
|
98
|
-
for (const error of res.errors) {
|
|
99
|
-
console.error(error);
|
|
100
|
-
}
|
|
101
|
-
debugger;
|
|
102
|
-
shouldNeverHappen(`GraphQL error: ${res.errors.join('\n')}`);
|
|
103
|
-
}
|
|
104
|
-
span.end();
|
|
105
|
-
const result = this.mapResult(res.data, get);
|
|
106
|
-
const durationMs = getDurationMsFromSpan(span);
|
|
107
|
-
this.executionTimes.push(durationMs);
|
|
108
|
-
return {
|
|
109
|
-
result,
|
|
110
|
-
queriedTables: Array.from(context.queriedTables.values()),
|
|
111
|
-
durationMs,
|
|
112
|
-
};
|
|
113
|
-
});
|
|
114
|
-
};
|
|
115
|
-
destroy = () => {
|
|
116
|
-
if (this.variableValues$ !== undefined) {
|
|
117
|
-
this.reactivityGraph.destroyNode(this.variableValues$);
|
|
118
|
-
}
|
|
119
|
-
this.reactivityGraph.destroyNode(this.results$);
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
//# sourceMappingURL=graphql.js.map
|