@livestore/livestore 0.0.23 → 0.0.25
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/QueryCache.d.ts +2 -2
- package/dist/QueryCache.d.ts.map +1 -1
- package/dist/QueryCache.js.map +1 -1
- package/dist/__tests__/react/fixture.d.ts +2 -2
- package/dist/__tests__/react/fixture.d.ts.map +1 -1
- package/dist/__tests__/react/fixture.js +2 -2
- package/dist/__tests__/react/fixture.js.map +1 -1
- package/dist/__tests__/react/useComponentState.test.js +78 -10
- package/dist/__tests__/react/useComponentState.test.js.map +1 -1
- package/dist/__tests__/react/useQuery.test.js +35 -10
- package/dist/__tests__/react/useQuery.test.js.map +1 -1
- package/dist/__tests__/reactive.test.js +51 -0
- package/dist/__tests__/reactive.test.js.map +1 -1
- package/dist/__tests__/reactiveQueries/sql.test.js +2 -9
- package/dist/__tests__/reactiveQueries/sql.test.js.map +1 -1
- package/dist/effect/LiveStore.js +1 -1
- package/dist/effect/LiveStore.js.map +1 -1
- package/dist/inMemoryDatabase.d.ts +3 -3
- package/dist/inMemoryDatabase.d.ts.map +1 -1
- package/dist/inMemoryDatabase.js +3 -3
- package/dist/inMemoryDatabase.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/migrations.d.ts.map +1 -1
- package/dist/migrations.js +7 -2
- package/dist/migrations.js.map +1 -1
- package/dist/react/useComponentState.d.ts +3 -3
- package/dist/react/useComponentState.d.ts.map +1 -1
- package/dist/react/useComponentState.js +43 -57
- package/dist/react/useComponentState.js.map +1 -1
- package/dist/react/useQuery.js +2 -2
- package/dist/react/useQuery.js.map +1 -1
- package/dist/react/utils/stack-info.d.ts.map +1 -1
- package/dist/react/utils/stack-info.js +0 -1
- package/dist/react/utils/stack-info.js.map +1 -1
- package/dist/reactive.d.ts +37 -28
- package/dist/reactive.d.ts.map +1 -1
- package/dist/reactive.js +44 -19
- package/dist/reactive.js.map +1 -1
- package/dist/reactiveQueries/base-class.d.ts +4 -4
- package/dist/reactiveQueries/base-class.d.ts.map +1 -1
- package/dist/reactiveQueries/base-class.js +2 -1
- package/dist/reactiveQueries/base-class.js.map +1 -1
- package/dist/reactiveQueries/js.d.ts +6 -1
- package/dist/reactiveQueries/js.d.ts.map +1 -1
- package/dist/reactiveQueries/js.js.map +1 -1
- package/dist/reactiveQueries/sql.d.ts +2 -2
- package/dist/reactiveQueries/sql.d.ts.map +1 -1
- package/dist/reactiveQueries/sql.js +1 -1
- package/dist/reactiveQueries/sql.js.map +1 -1
- package/dist/store.d.ts +2 -11
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +6 -11
- package/dist/store.js.map +1 -1
- package/package.json +16 -13
- package/src/QueryCache.ts +2 -2
- package/src/__tests__/react/fixture.tsx +3 -3
- package/src/__tests__/react/useComponentState.test.tsx +116 -10
- package/src/__tests__/react/useQuery.test.tsx +54 -12
- package/src/__tests__/reactive.test.ts +71 -0
- package/src/__tests__/reactiveQueries/sql.test.ts +2 -9
- package/src/effect/LiveStore.ts +1 -1
- package/src/inMemoryDatabase.ts +8 -8
- package/src/index.ts +4 -12
- package/src/migrations.ts +13 -7
- package/src/react/useComponentState.ts +53 -72
- package/src/react/useQuery.ts +2 -2
- package/src/react/utils/stack-info.ts +0 -1
- package/src/reactive.ts +80 -64
- package/src/reactiveQueries/base-class.ts +6 -8
- package/src/reactiveQueries/js.ts +6 -1
- package/src/reactiveQueries/sql.ts +3 -3
- package/src/store.ts +12 -24
- package/dist/__tests__/react/useLQuery.test.d.ts +0 -2
- package/dist/__tests__/react/useLQuery.test.d.ts.map +0 -1
- package/dist/__tests__/react/useLQuery.test.js +0 -38
- package/dist/__tests__/react/useLQuery.test.js.map +0 -1
- package/dist/__tests__/react/useLiveStoreComponent.test.d.ts +0 -2
- package/dist/__tests__/react/useLiveStoreComponent.test.d.ts.map +0 -1
- package/dist/__tests__/react/useLiveStoreComponent.test.js +0 -73
- package/dist/__tests__/react/useLiveStoreComponent.test.js.map +0 -1
- package/dist/__tests__/react/utils/extractStackInfoFromStackTrace.test.d.ts +0 -2
- package/dist/__tests__/react/utils/extractStackInfoFromStackTrace.test.d.ts.map +0 -1
- package/dist/__tests__/react/utils/extractStackInfoFromStackTrace.test.js +0 -38
- package/dist/__tests__/react/utils/extractStackInfoFromStackTrace.test.js.map +0 -1
- package/dist/react/useGlobalQuery.d.ts +0 -3
- package/dist/react/useGlobalQuery.d.ts.map +0 -1
- package/dist/react/useGlobalQuery.js +0 -26
- package/dist/react/useGlobalQuery.js.map +0 -1
- package/dist/react/useGraphQL.d.ts +0 -13
- package/dist/react/useGraphQL.d.ts.map +0 -1
- package/dist/react/useGraphQL.js +0 -87
- package/dist/react/useGraphQL.js.map +0 -1
- package/dist/react/useLiveStoreComponent.d.ts +0 -75
- package/dist/react/useLiveStoreComponent.d.ts.map +0 -1
- package/dist/react/useLiveStoreComponent.js +0 -361
- package/dist/react/useLiveStoreComponent.js.map +0 -1
- package/dist/react/utils/extractNamesFromStackTrace.d.ts +0 -3
- package/dist/react/utils/extractNamesFromStackTrace.d.ts.map +0 -1
- package/dist/react/utils/extractNamesFromStackTrace.js +0 -40
- package/dist/react/utils/extractNamesFromStackTrace.js.map +0 -1
- package/dist/react/utils/extractStackInfoFromStackTrace.d.ts +0 -7
- package/dist/react/utils/extractStackInfoFromStackTrace.d.ts.map +0 -1
- package/dist/react/utils/extractStackInfoFromStackTrace.js +0 -40
- package/dist/react/utils/extractStackInfoFromStackTrace.js.map +0 -1
|
@@ -1,361 +0,0 @@
|
|
|
1
|
-
import { omit, shouldNeverHappen } from '@livestore/utils';
|
|
2
|
-
import { Schema } from '@livestore/utils/effect';
|
|
3
|
-
import * as otel from '@opentelemetry/api';
|
|
4
|
-
import { SqliteAst, SqliteDsl } from 'effect-db-schema';
|
|
5
|
-
import { isEqual, mapValues } from 'lodash-es';
|
|
6
|
-
import React from 'react';
|
|
7
|
-
import { v4 as uuid } from 'uuid';
|
|
8
|
-
import { labelForKey, tableNameForComponentKey } from '../componentKey.js';
|
|
9
|
-
import { migrateTable } from '../migrations.js';
|
|
10
|
-
import { queryGraphQL } from '../reactiveQueries/graphql.js';
|
|
11
|
-
import { LiveStoreJSQuery } from '../reactiveQueries/js.js';
|
|
12
|
-
import { LiveStoreSQLQuery } from '../reactiveQueries/sql.js';
|
|
13
|
-
import { SCHEMA_META_TABLE } from '../schema.js';
|
|
14
|
-
import { sql } from '../util.js';
|
|
15
|
-
import { useStore } from './LiveStoreContext.js';
|
|
16
|
-
import { useStateRefWithReactiveInput } from './utils/useStateRefWithReactiveInput.js';
|
|
17
|
-
// type ComponentState = {
|
|
18
|
-
// /** Equivalent to `componentKey.key` */
|
|
19
|
-
// id: string
|
|
20
|
-
// [key: string]: string | number | boolean | null
|
|
21
|
-
// }
|
|
22
|
-
/**
|
|
23
|
-
* This is needed because the `React.useMemo` call below, can sometimes be called multiple times 🤷,
|
|
24
|
-
* so we need to "cache" the fact that we've already started a span for this component.
|
|
25
|
-
* The map entry is being removed again in the `React.useEffect` call below.
|
|
26
|
-
*/
|
|
27
|
-
const spanAlreadyStartedCache = new Map();
|
|
28
|
-
/**
|
|
29
|
-
* Create reactive queries within a component.
|
|
30
|
-
* @param config.queries A function that returns a map of named reactive queries.
|
|
31
|
-
* @param config.componentKey A function that returns a unique key for this component.
|
|
32
|
-
* @param config.reactDeps A list of React-level dependencies that will refresh the queries.
|
|
33
|
-
*/
|
|
34
|
-
export const useLiveStoreComponent = ({ stateSchema: stateSchema_, queries: queriesDef = () => ({}), componentKey: componentKeyConfig, reactDeps = [], }) => {
|
|
35
|
-
// TODO validate schema to make sure each column has a default value
|
|
36
|
-
// TODO we should clean up the state schema handling to remove this special handling for the `id` column
|
|
37
|
-
const stateSchema = React.useMemo(() => (stateSchema_ ? { ...stateSchema_, columns: omit(stateSchema_.columns, 'id') } : undefined), [stateSchema_]);
|
|
38
|
-
// performance.mark('useLiveStoreComponent:start')
|
|
39
|
-
const componentKey = useComponentKey(componentKeyConfig, reactDeps);
|
|
40
|
-
const { store } = useStore();
|
|
41
|
-
const componentKeyLabel = React.useMemo(() => labelForKey(componentKey), [componentKey]);
|
|
42
|
-
// The following `React.useMemo` and `React.useEffect` calls are used to start and end a span for the lifetime of this component.
|
|
43
|
-
const { span, otelContext } = React.useMemo(() => {
|
|
44
|
-
const existingSpan = spanAlreadyStartedCache.get(componentKeyLabel);
|
|
45
|
-
if (existingSpan !== undefined)
|
|
46
|
-
return existingSpan;
|
|
47
|
-
const span = store.otel.tracer.startSpan(`LiveStore:useLiveStoreComponent:${componentKeyLabel}`, {}, store.otel.queriesSpanContext);
|
|
48
|
-
const otelContext = otel.trace.setSpan(otel.context.active(), span);
|
|
49
|
-
spanAlreadyStartedCache.set(componentKeyLabel, { span, otelContext });
|
|
50
|
-
return { span, otelContext };
|
|
51
|
-
}, [componentKeyLabel, store.otel.queriesSpanContext, store.otel.tracer]);
|
|
52
|
-
React.useEffect(() => () => {
|
|
53
|
-
spanAlreadyStartedCache.delete(componentKeyLabel);
|
|
54
|
-
span.end();
|
|
55
|
-
}, [componentKeyLabel, span]);
|
|
56
|
-
const generateQueries = React.useCallback(({ state$, registerSubscription, isTemporaryQuery, }) => queriesDef({
|
|
57
|
-
rxSQL: (genQuery, queriedTables, bindValues) => new LiveStoreSQLQuery({
|
|
58
|
-
label: 'todo',
|
|
59
|
-
genQueryString: genQuery,
|
|
60
|
-
bindValues,
|
|
61
|
-
queriedTables,
|
|
62
|
-
}),
|
|
63
|
-
rxGraphQL: (query, genVariableValues, label) => queryGraphQL(query, genVariableValues, { label }),
|
|
64
|
-
// rxJS: <T>(genQuery: (get: GetAtomResult) => T) => store.queryJS(genQuery, { componentKey, otelContext }),
|
|
65
|
-
state$,
|
|
66
|
-
subscribe: registerSubscription,
|
|
67
|
-
isTemporaryQuery,
|
|
68
|
-
}),
|
|
69
|
-
// NOTE: we don't include the queries function passed in by the user here;
|
|
70
|
-
// the reason is that we don't want to force them to memoize that function.
|
|
71
|
-
// Instead, we just assume that the function always has the same contents.
|
|
72
|
-
// This makes sense for LiveStore because the component config should be static.
|
|
73
|
-
// TODO: document this and consider whether it's the right API surface.
|
|
74
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
75
|
-
[store, componentKey]);
|
|
76
|
-
const defaultComponentState = React.useMemo(() => {
|
|
77
|
-
const defaultState = (stateSchema === undefined ? {} : mapValues(stateSchema.columns, (c) => c.default));
|
|
78
|
-
// @ts-expect-error TODO fix typing
|
|
79
|
-
defaultState.id = componentKeyConfig.id;
|
|
80
|
-
return defaultState;
|
|
81
|
-
}, [componentKeyConfig.id, stateSchema]);
|
|
82
|
-
const componentStateEffectSchema = React.useMemo(() => (stateSchema ? SqliteDsl.structSchemaForTable(stateSchema) : Schema.any), [stateSchema]);
|
|
83
|
-
const state$ = React.useMemo(() => {
|
|
84
|
-
// create state query
|
|
85
|
-
if (stateSchema === undefined) {
|
|
86
|
-
// TODO don't set up a query if there's no state schema (keeps the graph more clean)
|
|
87
|
-
return new LiveStoreJSQuery({
|
|
88
|
-
fn: () => ({}),
|
|
89
|
-
label: 'empty-component-state',
|
|
90
|
-
// otelContext,
|
|
91
|
-
// otelTracer: store.otel.tracer,
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
const componentTableName = tableNameForComponentKey(componentKey);
|
|
96
|
-
const whereClause = componentKey._tag === 'singleton' ? '' : `where id = '${componentKey.id}'`;
|
|
97
|
-
// TODO find a better solution for this
|
|
98
|
-
if (store.tableRefs[componentTableName] === undefined) {
|
|
99
|
-
const schemaHash = SqliteAst.hash(stateSchema.ast);
|
|
100
|
-
const res = store.inMemoryDB.select(sql `SELECT schemaHash FROM ${SCHEMA_META_TABLE} WHERE tableName = '${componentTableName}'`);
|
|
101
|
-
if (res.length === 0 || res[0].schemaHash !== schemaHash) {
|
|
102
|
-
migrateTable({ db: store._proxyDb, tableDef: stateSchema.ast, otelContext, schemaHash });
|
|
103
|
-
}
|
|
104
|
-
store.tableRefs[componentTableName] = store.graph.makeRef(null, {
|
|
105
|
-
equal: () => false,
|
|
106
|
-
label: componentTableName,
|
|
107
|
-
meta: { liveStoreRefType: 'table' },
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
// state$ = store
|
|
111
|
-
// .querySQL(() => sql`select * from ${componentTableName} ${whereClause} limit 1`, {
|
|
112
|
-
// queriedTables: [componentTableName],
|
|
113
|
-
// componentKey,
|
|
114
|
-
// label: `localState:query:${componentKeyLabel}`,
|
|
115
|
-
// otelContext,
|
|
116
|
-
// })
|
|
117
|
-
return (new LiveStoreSQLQuery({
|
|
118
|
-
label: `localState:query:${componentKeyLabel}`,
|
|
119
|
-
// otelContext,
|
|
120
|
-
// otelTracer: store.otel.tracer,
|
|
121
|
-
genQueryString: () => sql `select * from ${componentTableName} ${whereClause} limit 1`,
|
|
122
|
-
queriedTables: [componentTableName],
|
|
123
|
-
})
|
|
124
|
-
// TODO consider to instead of just returning the default value, to write the default component state to the DB
|
|
125
|
-
.pipe((results) => results.length === 1 ? Schema.parseSync(componentStateEffectSchema)(results[0]) : defaultComponentState));
|
|
126
|
-
}
|
|
127
|
-
}, [
|
|
128
|
-
componentKey,
|
|
129
|
-
componentKeyLabel,
|
|
130
|
-
componentStateEffectSchema,
|
|
131
|
-
defaultComponentState,
|
|
132
|
-
otelContext,
|
|
133
|
-
stateSchema,
|
|
134
|
-
store._proxyDb,
|
|
135
|
-
store.graph,
|
|
136
|
-
store.inMemoryDB,
|
|
137
|
-
store.tableRefs,
|
|
138
|
-
]);
|
|
139
|
-
const queries = React.useMemo(() => generateQueries({ state$, registerSubscription: () => { }, isTemporaryQuery: false }), [generateQueries, state$]);
|
|
140
|
-
// Step 1:
|
|
141
|
-
// Synchronously create state and queries for initial render pass.
|
|
142
|
-
// We do this in a temporary query context which cleans up after itself, making it idempotent
|
|
143
|
-
// TODO get rid of the temporary query workaround
|
|
144
|
-
const { initialComponentState, initialQueryResults } = React.useMemo(() => {
|
|
145
|
-
// return store.otel.tracer.startActiveSpan('LiveStore:useLiveStoreComponent:initial', {}, otelContext, (span) => {
|
|
146
|
-
// const otelContext = otel.trace.setSpan(otel.context.active(), span)
|
|
147
|
-
// NOTE `inTempQueryContext` automatically destroys the queries once the callback is done
|
|
148
|
-
// return store.inTempQueryContext(() => {
|
|
149
|
-
// try {
|
|
150
|
-
// store.graph.refresh({}, otelContext)
|
|
151
|
-
const initialComponentState = state$.run(otelContext);
|
|
152
|
-
// const queries = generateQueries({
|
|
153
|
-
// state$: state$,
|
|
154
|
-
// otelContext,
|
|
155
|
-
// registerSubscription: () => {},
|
|
156
|
-
// isTemporaryQuery: true,
|
|
157
|
-
// })
|
|
158
|
-
for (const [name, query] of Object.entries(queries)) {
|
|
159
|
-
query.label = name;
|
|
160
|
-
}
|
|
161
|
-
// store.graph.refresh({}, otelContext)
|
|
162
|
-
// TODO improve typing
|
|
163
|
-
const initialQueryResults = mapValues(queries, (query) => query.run(otelContext));
|
|
164
|
-
return { initialComponentState, initialQueryResults };
|
|
165
|
-
// } finally {
|
|
166
|
-
// span.end()
|
|
167
|
-
// }
|
|
168
|
-
// })
|
|
169
|
-
// })
|
|
170
|
-
}, [otelContext, queries, state$]);
|
|
171
|
-
// Now that we've computed the initial state synchronously,
|
|
172
|
-
// we can set up our useState calls w/ a default value populated...
|
|
173
|
-
const [componentStateRef, setComponentState_] = useStateRefWithReactiveInput(initialComponentState);
|
|
174
|
-
const [queryResultsRef, setQueryResults_] = useStateRefWithReactiveInput(initialQueryResults);
|
|
175
|
-
const setState = (stateSchema === undefined
|
|
176
|
-
? {}
|
|
177
|
-
: // TODO: do we have a better type for the values that can go in SQLite?
|
|
178
|
-
mapValues(stateSchema.columns, (column, columnName) => (value) => {
|
|
179
|
-
// Don't update the state if it's the same as the value already seen in the component
|
|
180
|
-
// @ts-expect-error TODO fix typing
|
|
181
|
-
if (componentStateRef.current[columnName] === value)
|
|
182
|
-
return;
|
|
183
|
-
const encodedValue = Schema.encodeSync(column.type.codec)(value);
|
|
184
|
-
if (['componentKey', 'columnNames'].includes(columnName)) {
|
|
185
|
-
shouldNeverHappen(`Can't use reserved column name ${columnName}`);
|
|
186
|
-
}
|
|
187
|
-
return store.applyEvent('updateComponentState', {
|
|
188
|
-
componentKey,
|
|
189
|
-
columnNames: [columnName],
|
|
190
|
-
[columnName]: encodedValue,
|
|
191
|
-
});
|
|
192
|
-
}));
|
|
193
|
-
setState.setMany = (columnValues) => {
|
|
194
|
-
// TODO use hashing instead
|
|
195
|
-
// Don't update the state if it's the same as the value already seen in the component
|
|
196
|
-
// @ts-expect-error TODO fix typing
|
|
197
|
-
if (Object.entries(columnValues).every(([columnName, value]) => componentStateRef.current[columnName] === value)) {
|
|
198
|
-
return;
|
|
199
|
-
}
|
|
200
|
-
const columnNames = Object.keys(columnValues);
|
|
201
|
-
return store.applyEvent('updateComponentState', { componentKey, columnNames, ...columnValues });
|
|
202
|
-
};
|
|
203
|
-
// OK, now all the synchronous work is done;
|
|
204
|
-
// time to set up our long-running queries in an effect
|
|
205
|
-
React.useEffect(() => {
|
|
206
|
-
return store.otel.tracer.startActiveSpan('LiveStore:useLiveStoreComponent:long-running', { attributes: {} }, otelContext, (span) => {
|
|
207
|
-
const otelContext = otel.trace.setSpan(otel.context.active(), span);
|
|
208
|
-
const unsubs = [];
|
|
209
|
-
if (stateSchema !== undefined) {
|
|
210
|
-
insertRowForComponentInstance({ store, componentKey, stateSchema });
|
|
211
|
-
}
|
|
212
|
-
// // create state query
|
|
213
|
-
// let state$: LiveStoreJSQuery<TComponentState>
|
|
214
|
-
// if (stateSchema === undefined) {
|
|
215
|
-
// // TODO remove this query
|
|
216
|
-
// // state$ = store.queryJS(() => ({}) as TComponentState, {
|
|
217
|
-
// // componentKey,
|
|
218
|
-
// // otelContext,
|
|
219
|
-
// // label: 'empty-component-state',
|
|
220
|
-
// // })
|
|
221
|
-
// state$ = new LiveStoreJSQuery({
|
|
222
|
-
// fn: () => ({}) as TComponentState,
|
|
223
|
-
// label: 'empty-component-state',
|
|
224
|
-
// otelContext,
|
|
225
|
-
// otelTracer: store.otel.tracer,
|
|
226
|
-
// })
|
|
227
|
-
// } else {
|
|
228
|
-
// const componentTableName = tableNameForComponentKey(componentKey)
|
|
229
|
-
// insertRowForComponentInstance({ store, componentKey, stateSchema })
|
|
230
|
-
// const whereClause = componentKey._tag === 'singleton' ? '' : `where id = '${componentKey.id}'`
|
|
231
|
-
// // state$ = store
|
|
232
|
-
// // .querySQL<TComponentState>(() => sql`select * from ${componentTableName} ${whereClause} limit 1`, {
|
|
233
|
-
// // queriedTables: [componentTableName],
|
|
234
|
-
// // componentKey,
|
|
235
|
-
// // label: `localState:query:${componentKeyLabel}`,
|
|
236
|
-
// // otelContext,
|
|
237
|
-
// // })
|
|
238
|
-
// state$ = new LiveStoreSQLQuery({
|
|
239
|
-
// label: `localState:query:${componentKeyLabel}`,
|
|
240
|
-
// otelContext,
|
|
241
|
-
// otelTracer: store.otel.tracer,
|
|
242
|
-
// payload: {
|
|
243
|
-
// genQueryString: () => sql`select * from ${componentTableName} ${whereClause} limit 1`,
|
|
244
|
-
// queriedTables: [componentTableName],
|
|
245
|
-
// },
|
|
246
|
-
// })
|
|
247
|
-
// // TODO consider to instead of just returning the default value, to write the default component state to the DB
|
|
248
|
-
// .pipe<TComponentState>((results) =>
|
|
249
|
-
// results.length === 1 ? Schema.parseSync(componentStateEffectSchema)(results[0]!) : defaultComponentState,
|
|
250
|
-
// )
|
|
251
|
-
// }
|
|
252
|
-
unsubs.push(store.subscribe(state$, (results) => {
|
|
253
|
-
if (isEqual(results, componentStateRef.current) === false) {
|
|
254
|
-
setComponentState_(results);
|
|
255
|
-
}
|
|
256
|
-
}, undefined, { label: `useLiveStoreComponent:localState:subscribe:${state$.label}` }));
|
|
257
|
-
// TODO re-enable
|
|
258
|
-
const registerSubscription = (query$, callback, onUnsubscribe) => {
|
|
259
|
-
unsubs.push(store.subscribe(query$, (results) => {
|
|
260
|
-
callback(results);
|
|
261
|
-
}, onUnsubscribe, { label: `useLiveStoreComponent:query:manual-subscribe:${query$.label}` }));
|
|
262
|
-
};
|
|
263
|
-
for (const [key, query] of Object.entries(queries)) {
|
|
264
|
-
// Use the field name given to this query in the useQueries hook as its label
|
|
265
|
-
query.label = key;
|
|
266
|
-
unsubs.push(store.subscribe(query, (results) => {
|
|
267
|
-
const newQueryResults = { ...queryResultsRef.current, [key]: results };
|
|
268
|
-
if (isEqual(newQueryResults, queryResultsRef.current) === false) {
|
|
269
|
-
setQueryResults_(newQueryResults);
|
|
270
|
-
}
|
|
271
|
-
}, undefined, { label: `useLiveStoreComponent:query:subscribe:${query.label}` }));
|
|
272
|
-
}
|
|
273
|
-
return () => {
|
|
274
|
-
for (const unsub of unsubs) {
|
|
275
|
-
unsub();
|
|
276
|
-
}
|
|
277
|
-
span.end();
|
|
278
|
-
};
|
|
279
|
-
});
|
|
280
|
-
// NOTE excluding `setComponentState_` and `setQueryResults_` from the deps array as it seems to cause an infinite loop
|
|
281
|
-
// This should probably be improved
|
|
282
|
-
// TODO is this still true?
|
|
283
|
-
// // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
284
|
-
}, [
|
|
285
|
-
store,
|
|
286
|
-
componentKey,
|
|
287
|
-
stateSchema,
|
|
288
|
-
defaultComponentState,
|
|
289
|
-
generateQueries,
|
|
290
|
-
otelContext,
|
|
291
|
-
componentStateRef,
|
|
292
|
-
state$,
|
|
293
|
-
queries,
|
|
294
|
-
queryResultsRef,
|
|
295
|
-
setComponentState_,
|
|
296
|
-
setQueryResults_,
|
|
297
|
-
]);
|
|
298
|
-
// Very important: remove any queries / other resources associated w/ this component
|
|
299
|
-
React.useEffect(() => () => store.unmountComponent(componentKey), [store, componentKey]);
|
|
300
|
-
// performance.mark('useLiveStoreComponent:end')
|
|
301
|
-
// performance.measure(`useLiveStoreComponent:${componentKey.type}`, 'useLiveStoreComponent:start', 'useLiveStoreComponent:end')
|
|
302
|
-
const state = componentStateRef.current;
|
|
303
|
-
const useLiveStoreJsonState = (jsonStringKey, parse = (_) => _) => {
|
|
304
|
-
const value = React.useMemo(() => {
|
|
305
|
-
return parse(JSON.parse(state[jsonStringKey]));
|
|
306
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
307
|
-
}, [state[jsonStringKey], parse]);
|
|
308
|
-
const setValue = React.useCallback((newValOrFn) => {
|
|
309
|
-
const newVal = typeof newValOrFn === 'function'
|
|
310
|
-
? // NOTE we're using the ref instead of the value because we want to be sure
|
|
311
|
-
// we're using the latest value when the setter is called
|
|
312
|
-
newValOrFn(parse(JSON.parse(componentStateRef.current[jsonStringKey])))
|
|
313
|
-
: newValOrFn;
|
|
314
|
-
setState[jsonStringKey](JSON.stringify(newVal));
|
|
315
|
-
}, [parse, jsonStringKey]);
|
|
316
|
-
return [value, setValue];
|
|
317
|
-
};
|
|
318
|
-
return {
|
|
319
|
-
queryResults: queryResultsRef.current,
|
|
320
|
-
state,
|
|
321
|
-
setState,
|
|
322
|
-
useLiveStoreJsonState,
|
|
323
|
-
};
|
|
324
|
-
};
|
|
325
|
-
export const useComponentKey = ({ name, id }, deps = []) => React.useMemo(() => {
|
|
326
|
-
switch (id) {
|
|
327
|
-
case 'singleton': {
|
|
328
|
-
return { _tag: 'singleton', componentName: name, id: 'singleton' };
|
|
329
|
-
}
|
|
330
|
-
case '__ephemeral__': {
|
|
331
|
-
return { _tag: 'ephemeral', componentName: name, id: uuid() };
|
|
332
|
-
}
|
|
333
|
-
default: {
|
|
334
|
-
return { _tag: 'custom', componentName: name, id };
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
338
|
-
}, [...deps, id, name]);
|
|
339
|
-
/**
|
|
340
|
-
* Create a row storing the state for a component instance, if none exists yet.
|
|
341
|
-
* Initialized with default values, and keyed on the component key.
|
|
342
|
-
*/
|
|
343
|
-
const insertRowForComponentInstance = ({ store, componentKey, stateSchema, }) => {
|
|
344
|
-
const columnNames = ['id', ...Object.keys(stateSchema.columns)];
|
|
345
|
-
const columnValues = columnNames.map((name) => `$${name}`).join(', ');
|
|
346
|
-
const tableName = tableNameForComponentKey(componentKey);
|
|
347
|
-
const insertQuery = sql `insert into ${tableName} (${columnNames.join(', ')}) select ${columnValues} where not exists(select 1 from ${tableName} where id = '${componentKey.id}')`;
|
|
348
|
-
void store.execute(insertQuery, {
|
|
349
|
-
...mapValues(stateSchema.columns, (column) => prepareValueForSql(column.default ?? null)),
|
|
350
|
-
id: componentKey.id,
|
|
351
|
-
}, [tableName]);
|
|
352
|
-
};
|
|
353
|
-
const prepareValueForSql = (value) => {
|
|
354
|
-
if (typeof value === 'string' || typeof value === 'number' || value === null) {
|
|
355
|
-
return value;
|
|
356
|
-
}
|
|
357
|
-
else {
|
|
358
|
-
return value ? 1 : 0;
|
|
359
|
-
}
|
|
360
|
-
};
|
|
361
|
-
//# sourceMappingURL=useLiveStoreComponent.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useLiveStoreComponent.js","sourceRoot":"","sources":["../../src/react/useLiveStoreComponent.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAChD,OAAO,KAAK,IAAI,MAAM,oBAAoB,CAAA;AAC1C,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AACvD,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAE9C,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAA;AAGjC,OAAO,EAAE,WAAW,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAA;AAC1E,OAAO,E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,YAAY,CAAC,EAAE;KACpB,EACD,CAAC,SAAS,CAAC,CACZ,CAAA;AACH,CAAC,CAAA;AAED,MAAM,kBAAkB,GAAG,CAAC,KAAuC,EAAE,EAAE;IACrE,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE;QAC5E,OAAO,KAAK,CAAA;KACb;SAAM;QACL,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;KACrB;AACH,CAAC,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"extractNamesFromStackTrace.d.ts","sourceRoot":"","sources":["../../../src/react/utils/extractNamesFromStackTrace.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kBAAkB,QAAwB,CAAA;AAqBvD,eAAO,MAAM,0BAA0B,eAAgB,MAAM,KAAG,MAAM,EAoBrE,CAAA"}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
export const originalStackLimit = Error.stackTraceLimit;
|
|
2
|
-
/*
|
|
3
|
-
Example stack trace:
|
|
4
|
-
|
|
5
|
-
Error
|
|
6
|
-
at https://localhost:8081/@fs/Users/schickling/Code/overtone/submodules/livestore/packages/@livestore/livestore/dist/react/useQuery.js?t=1699550216884:18:23
|
|
7
|
-
at mountMemo (https://localhost:8081/node_modules/.vite-web/deps/chunk-M23HUTQV.js?v=3eb66ed6:12817:27)
|
|
8
|
-
at Object.useMemo (https://localhost:8081/node_modules/.vite-web/deps/chunk-M23HUTQV.js?v=3eb66ed6:13141:24)
|
|
9
|
-
at Object.useMemo (https://localhost:8081/node_modules/.vite-web/deps/chunk-4WADDZ2G.js?v=3eb66ed6:1094:29)
|
|
10
|
-
at useQuery (https://localhost:8081/@fs/Users/schickling/Code/overtone/submodules/livestore/packages/@livestore/livestore/dist/react/useQuery.js?t=1699550216884:13:33)
|
|
11
|
-
at useAppState (https://localhost:8081/src/db/AppState.ts?t=1699550216884:17:34)
|
|
12
|
-
at useRoute (https://localhost:8081/src/db/AppState.ts?t=1699550216884:74:22)
|
|
13
|
-
at RouteLink (https://localhost:8081/src/components/Link.tsx?t=1699550216884:36:7)
|
|
14
|
-
at renderWithHooks (https://localhost:8081/node_modules/.vite-web/deps/chunk-M23HUTQV.js?v=3eb66ed6:12171:26)
|
|
15
|
-
at mountIndeterminateComponent (https://localhost:8081/node_modules/.vite-web/deps/chunk-M23HUTQV.js?v=3eb66ed6:14921:21)
|
|
16
|
-
|
|
17
|
-
Approach:
|
|
18
|
-
- Start filtering at `at useQuery` (including)
|
|
19
|
-
- Stop filtering at `at renderWithHooks` (excluding)
|
|
20
|
-
*/
|
|
21
|
-
export const extractNamesFromStackTrace = (stackTrace) => {
|
|
22
|
-
const namePattern = / at (\w+)/g;
|
|
23
|
-
let match;
|
|
24
|
-
const names = [];
|
|
25
|
-
let hasReachedStart = false;
|
|
26
|
-
while ((match = namePattern.exec(stackTrace)) !== null) {
|
|
27
|
-
if (match[1]?.startsWith('use')) {
|
|
28
|
-
hasReachedStart = true;
|
|
29
|
-
// match[1] contains the captured group, which is the name we want to extract
|
|
30
|
-
names.unshift(match[1]);
|
|
31
|
-
}
|
|
32
|
-
else if (hasReachedStart) {
|
|
33
|
-
// We've reached the end of the `use*` functions, so we're adding the component name and stop
|
|
34
|
-
names.unshift(match[1]);
|
|
35
|
-
break;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return names;
|
|
39
|
-
};
|
|
40
|
-
//# sourceMappingURL=extractNamesFromStackTrace.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"extractNamesFromStackTrace.js","sourceRoot":"","sources":["../../../src/react/utils/extractNamesFromStackTrace.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,CAAC,eAAe,CAAA;AAEvD;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,UAAkB,EAAY,EAAE;IACzE,MAAM,WAAW,GAAG,YAAY,CAAA;IAChC,IAAI,KAA6B,CAAA;IACjC,MAAM,KAAK,GAAa,EAAE,CAAA;IAC1B,IAAI,eAAe,GAAG,KAAK,CAAA;IAE3B,OAAO,CAAC,KAAK,GAAG,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,KAAK,IAAI,EAAE;QACtD,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,KAAK,CAAC,EAAE;YAC/B,eAAe,GAAG,IAAI,CAAA;YAEtB,6EAA6E;YAC7E,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;SACxB;aAAM,IAAI,eAAe,EAAE;YAC1B,6FAA6F;YAC7F,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAE,CAAC,CAAA;YACxB,MAAK;SACN;KACF;IAED,OAAO,KAAK,CAAA;AACd,CAAC,CAAA"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export declare const originalStackLimit: number;
|
|
2
|
-
export type StackInfo = {
|
|
3
|
-
name: string;
|
|
4
|
-
filePath: string;
|
|
5
|
-
};
|
|
6
|
-
export declare const extractStackInfoFromStackTrace: (stackTrace: string) => StackInfo[];
|
|
7
|
-
//# sourceMappingURL=extractStackInfoFromStackTrace.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"extractStackInfoFromStackTrace.d.ts","sourceRoot":"","sources":["../../../src/react/utils/extractStackInfoFromStackTrace.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kBAAkB,QAAwB,CAAA;AAEvD,MAAM,MAAM,SAAS,GAAG;IACtB,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAqBD,eAAO,MAAM,8BAA8B,eAAgB,MAAM,KAAG,SAAS,EAoB5E,CAAA"}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
export const originalStackLimit = Error.stackTraceLimit;
|
|
2
|
-
/*
|
|
3
|
-
Example stack trace:
|
|
4
|
-
|
|
5
|
-
Error
|
|
6
|
-
at https://localhost:8081/@fs/Users/schickling/Code/overtone/submodules/livestore/packages/@livestore/livestore/dist/react/useQuery.js?t=1699550216884:18:23
|
|
7
|
-
at mountMemo (https://localhost:8081/node_modules/.vite-web/deps/chunk-M23HUTQV.js?v=3eb66ed6:12817:27)
|
|
8
|
-
at Object.useMemo (https://localhost:8081/node_modules/.vite-web/deps/chunk-M23HUTQV.js?v=3eb66ed6:13141:24)
|
|
9
|
-
at Object.useMemo (https://localhost:8081/node_modules/.vite-web/deps/chunk-4WADDZ2G.js?v=3eb66ed6:1094:29)
|
|
10
|
-
at useQuery (https://localhost:8081/@fs/Users/schickling/Code/overtone/submodules/livestore/packages/@livestore/livestore/dist/react/useQuery.js?t=1699550216884:13:33)
|
|
11
|
-
at useAppState (https://localhost:8081/src/db/AppState.ts?t=1699550216884:17:34)
|
|
12
|
-
at useRoute (https://localhost:8081/src/db/AppState.ts?t=1699550216884:74:22)
|
|
13
|
-
at RouteLink (https://localhost:8081/src/components/Link.tsx?t=1699550216884:36:7)
|
|
14
|
-
at renderWithHooks (https://localhost:8081/node_modules/.vite-web/deps/chunk-M23HUTQV.js?v=3eb66ed6:12171:26)
|
|
15
|
-
at mountIndeterminateComponent (https://localhost:8081/node_modules/.vite-web/deps/chunk-M23HUTQV.js?v=3eb66ed6:14921:21)
|
|
16
|
-
|
|
17
|
-
Approach:
|
|
18
|
-
- Start filtering at `at useQuery` (including)
|
|
19
|
-
- Stop filtering at `at renderWithHooks` (excluding)
|
|
20
|
-
*/
|
|
21
|
-
export const extractStackInfoFromStackTrace = (stackTrace) => {
|
|
22
|
-
const namePattern = /at (\S+) \((.+)\)/g;
|
|
23
|
-
let match;
|
|
24
|
-
const stackInfoArr = [];
|
|
25
|
-
let hasReachedStart = false;
|
|
26
|
-
while ((match = namePattern.exec(stackTrace)) !== null) {
|
|
27
|
-
const [, name, filePath] = match;
|
|
28
|
-
if (name.startsWith('use')) {
|
|
29
|
-
hasReachedStart = true;
|
|
30
|
-
stackInfoArr.unshift({ name, filePath });
|
|
31
|
-
}
|
|
32
|
-
else if (hasReachedStart) {
|
|
33
|
-
// We've reached the end of the `use*` functions, so we're adding the component name and stop
|
|
34
|
-
stackInfoArr.unshift({ name, filePath });
|
|
35
|
-
break;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return stackInfoArr;
|
|
39
|
-
};
|
|
40
|
-
//# sourceMappingURL=extractStackInfoFromStackTrace.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"extractStackInfoFromStackTrace.js","sourceRoot":"","sources":["../../../src/react/utils/extractStackInfoFromStackTrace.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,CAAC,eAAe,CAAA;AAOvD;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAAC,UAAkB,EAAe,EAAE;IAChF,MAAM,WAAW,GAAG,oBAAoB,CAAA;IACxC,IAAI,KAA6B,CAAA;IACjC,MAAM,YAAY,GAAgB,EAAE,CAAA;IACpC,IAAI,eAAe,GAAG,KAAK,CAAA;IAE3B,OAAO,CAAC,KAAK,GAAG,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,KAAK,IAAI,EAAE;QACtD,MAAM,CAAC,EAAE,IAAI,EAAE,QAAQ,CAAC,GAAG,KAAwC,CAAA;QACnE,IAAI,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE;YAC1B,eAAe,GAAG,IAAI,CAAA;YAEtB,YAAY,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAA;SACzC;aAAM,IAAI,eAAe,EAAE;YAC1B,6FAA6F;YAC7F,YAAY,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAA;YACxC,MAAK;SACN;KACF;IAED,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA"}
|