@livestore/livestore 0.0.12 → 0.0.14
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/README.md +25 -28
- package/dist/.tsbuildinfo +1 -0
- package/dist/QueryCache.d.ts +20 -0
- package/dist/QueryCache.d.ts.map +1 -0
- package/dist/QueryCache.js +71 -0
- package/dist/QueryCache.js.map +1 -0
- package/dist/__tests__/react/fixture.d.ts +26 -0
- package/dist/__tests__/react/fixture.d.ts.map +1 -0
- package/dist/__tests__/react/fixture.js +60 -0
- package/dist/__tests__/react/fixture.js.map +1 -0
- package/dist/__tests__/react/useComponentState.test.d.ts +2 -0
- package/dist/__tests__/react/useComponentState.test.d.ts.map +1 -0
- package/dist/__tests__/react/useComponentState.test.js +68 -0
- package/dist/__tests__/react/useComponentState.test.js.map +1 -0
- package/dist/__tests__/react/useLQuery.test.d.ts +2 -0
- package/dist/__tests__/react/useLQuery.test.d.ts.map +1 -0
- package/dist/__tests__/react/useLQuery.test.js +38 -0
- package/dist/__tests__/react/useLQuery.test.js.map +1 -0
- package/dist/__tests__/react/useLiveStoreComponent.test.d.ts +2 -0
- package/dist/__tests__/react/useLiveStoreComponent.test.d.ts.map +1 -0
- package/dist/__tests__/react/useLiveStoreComponent.test.js +73 -0
- package/dist/__tests__/react/useLiveStoreComponent.test.js.map +1 -0
- package/dist/__tests__/react/useQuery.test.d.ts +2 -0
- package/dist/__tests__/react/useQuery.test.d.ts.map +1 -0
- package/dist/__tests__/react/useQuery.test.js +33 -0
- package/dist/__tests__/react/useQuery.test.js.map +1 -0
- package/dist/__tests__/react/utils/extractStackInfoFromStackTrace.test.d.ts +2 -0
- package/dist/__tests__/react/utils/extractStackInfoFromStackTrace.test.d.ts.map +1 -0
- package/dist/__tests__/react/utils/extractStackInfoFromStackTrace.test.js +38 -0
- package/dist/__tests__/react/utils/extractStackInfoFromStackTrace.test.js.map +1 -0
- package/dist/__tests__/reactive.test.d.ts +2 -0
- package/dist/__tests__/reactive.test.d.ts.map +1 -0
- package/dist/__tests__/reactive.test.js +271 -0
- package/dist/__tests__/reactive.test.js.map +1 -0
- package/dist/__tests__/reactiveQueries/sql.test.d.ts +2 -0
- package/dist/__tests__/reactiveQueries/sql.test.d.ts.map +1 -0
- package/dist/__tests__/reactiveQueries/sql.test.js +337 -0
- package/dist/__tests__/reactiveQueries/sql.test.js.map +1 -0
- package/dist/bounded-collections.d.ts +34 -0
- package/dist/bounded-collections.d.ts.map +1 -0
- package/dist/bounded-collections.js +103 -0
- package/dist/bounded-collections.js.map +1 -0
- package/dist/componentKey.d.ts +20 -0
- package/dist/componentKey.d.ts.map +1 -0
- package/dist/componentKey.js +3 -0
- package/dist/componentKey.js.map +1 -0
- package/dist/effect/LiveStore.d.ts +36 -0
- package/dist/effect/LiveStore.d.ts.map +1 -0
- package/dist/effect/LiveStore.js +41 -0
- package/dist/effect/LiveStore.js.map +1 -0
- package/dist/effect/index.d.ts +2 -0
- package/dist/effect/index.d.ts.map +1 -0
- package/dist/effect/index.js +2 -0
- package/dist/effect/index.js.map +1 -0
- package/dist/events.d.ts +7 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +2 -0
- package/dist/events.js.map +1 -0
- package/dist/inMemoryDatabase.d.ts +56 -0
- package/dist/inMemoryDatabase.d.ts.map +1 -0
- package/dist/inMemoryDatabase.js +223 -0
- package/dist/inMemoryDatabase.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/migrations.d.ts +16 -0
- package/dist/migrations.d.ts.map +1 -0
- package/dist/migrations.js +67 -0
- package/dist/migrations.js.map +1 -0
- package/dist/otel.d.ts +4 -0
- package/dist/otel.d.ts.map +1 -0
- package/dist/otel.js +6 -0
- package/dist/otel.js.map +1 -0
- package/dist/react/LiveStoreContext.d.ts +11 -0
- package/dist/react/LiveStoreContext.d.ts.map +1 -0
- package/dist/react/LiveStoreContext.js +10 -0
- package/dist/react/LiveStoreContext.js.map +1 -0
- package/dist/react/LiveStoreProvider.d.ts +20 -0
- package/dist/react/LiveStoreProvider.d.ts.map +1 -0
- package/dist/react/LiveStoreProvider.js +52 -0
- package/dist/react/LiveStoreProvider.js.map +1 -0
- package/dist/react/index.d.ts +8 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +6 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/useComponentState.d.ts +50 -0
- package/dist/react/useComponentState.d.ts.map +1 -0
- package/dist/react/useComponentState.js +248 -0
- package/dist/react/useComponentState.js.map +1 -0
- package/dist/react/useGlobalQuery.d.ts +3 -0
- package/dist/react/useGlobalQuery.d.ts.map +1 -0
- package/dist/react/useGlobalQuery.js +26 -0
- package/dist/react/useGlobalQuery.js.map +1 -0
- package/dist/react/useGraphQL.d.ts +13 -0
- package/dist/react/useGraphQL.d.ts.map +1 -0
- package/dist/react/useGraphQL.js +87 -0
- package/dist/react/useGraphQL.js.map +1 -0
- package/dist/react/useLiveStoreComponent.d.ts +75 -0
- package/dist/react/useLiveStoreComponent.d.ts.map +1 -0
- package/dist/react/useLiveStoreComponent.js +361 -0
- package/dist/react/useLiveStoreComponent.js.map +1 -0
- package/dist/react/useQuery.d.ts +3 -0
- package/dist/react/useQuery.d.ts.map +1 -0
- package/dist/react/useQuery.js +42 -0
- package/dist/react/useQuery.js.map +1 -0
- package/dist/react/useTemporaryQuery.d.ts +8 -0
- package/dist/react/useTemporaryQuery.d.ts.map +1 -0
- package/dist/react/useTemporaryQuery.js +17 -0
- package/dist/react/useTemporaryQuery.js.map +1 -0
- package/dist/react/utils/extractNamesFromStackTrace.d.ts +3 -0
- package/dist/react/utils/extractNamesFromStackTrace.d.ts.map +1 -0
- package/dist/react/utils/extractNamesFromStackTrace.js +40 -0
- package/dist/react/utils/extractNamesFromStackTrace.js.map +1 -0
- package/dist/react/utils/extractStackInfoFromStackTrace.d.ts +7 -0
- package/dist/react/utils/extractStackInfoFromStackTrace.d.ts.map +1 -0
- package/dist/react/utils/extractStackInfoFromStackTrace.js +40 -0
- package/dist/react/utils/extractStackInfoFromStackTrace.js.map +1 -0
- package/dist/react/utils/useStateRefWithReactiveInput.d.ts +13 -0
- package/dist/react/utils/useStateRefWithReactiveInput.d.ts.map +1 -0
- package/dist/react/utils/useStateRefWithReactiveInput.js +38 -0
- package/dist/react/utils/useStateRefWithReactiveInput.js.map +1 -0
- package/dist/reactive.d.ts +134 -0
- package/dist/reactive.d.ts.map +1 -0
- package/dist/reactive.js +409 -0
- package/dist/reactive.js.map +1 -0
- package/dist/reactiveQueries/base-class.d.ts +32 -0
- package/dist/reactiveQueries/base-class.d.ts.map +1 -0
- package/dist/reactiveQueries/base-class.js +30 -0
- package/dist/reactiveQueries/base-class.js.map +1 -0
- package/dist/reactiveQueries/graph.d.ts +10 -0
- package/dist/reactiveQueries/graph.d.ts.map +1 -0
- package/dist/reactiveQueries/graph.js +6 -0
- package/dist/reactiveQueries/graph.js.map +1 -0
- package/dist/reactiveQueries/graphql.d.ts +42 -0
- package/dist/reactiveQueries/graphql.d.ts.map +1 -0
- package/dist/reactiveQueries/graphql.js +99 -0
- package/dist/reactiveQueries/graphql.js.map +1 -0
- package/dist/reactiveQueries/js.d.ts +23 -0
- package/dist/reactiveQueries/js.d.ts.map +1 -0
- package/dist/reactiveQueries/js.js +36 -0
- package/dist/reactiveQueries/js.js.map +1 -0
- package/dist/reactiveQueries/sql.d.ts +35 -0
- package/dist/reactiveQueries/sql.d.ts.map +1 -0
- package/dist/reactiveQueries/sql.js +97 -0
- package/dist/reactiveQueries/sql.js.map +1 -0
- package/dist/schema.d.ts +81 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +46 -0
- package/dist/schema.js.map +1 -0
- package/dist/storage/in-memory/index.d.ts +15 -0
- package/dist/storage/in-memory/index.d.ts.map +1 -0
- package/dist/storage/in-memory/index.js +14 -0
- package/dist/storage/in-memory/index.js.map +1 -0
- package/dist/storage/index.d.ts +14 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +9 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/tauri/index.d.ts +19 -0
- package/dist/storage/tauri/index.d.ts.map +1 -0
- package/dist/storage/tauri/index.js +38 -0
- package/dist/storage/tauri/index.js.map +1 -0
- package/dist/storage/utils/idb.d.ts +10 -0
- package/dist/storage/utils/idb.d.ts.map +1 -0
- package/dist/storage/utils/idb.js +58 -0
- package/dist/storage/utils/idb.js.map +1 -0
- package/dist/storage/web-worker/index.d.ts +27 -0
- package/dist/storage/web-worker/index.d.ts.map +1 -0
- package/dist/storage/web-worker/index.js +74 -0
- package/dist/storage/web-worker/index.js.map +1 -0
- package/dist/storage/web-worker/worker.d.ts +13 -0
- package/dist/storage/web-worker/worker.d.ts.map +1 -0
- package/dist/storage/web-worker/worker.js +110 -0
- package/dist/storage/web-worker/worker.js.map +1 -0
- package/dist/store.d.ts +159 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +626 -0
- package/dist/store.js.map +1 -0
- package/dist/util.d.ts +28 -0
- package/dist/util.d.ts.map +1 -0
- package/dist/util.js +55 -0
- package/dist/util.js.map +1 -0
- package/package.json +47 -19
- package/src/QueryCache.ts +1 -1
- package/src/__tests__/react/fixture.tsx +35 -39
- package/src/__tests__/react/{useLiveStoreComponent.test.tsx → useComponentState.test.tsx} +9 -20
- package/src/__tests__/react/useQuery.test.tsx +48 -0
- package/src/__tests__/react/utils/extractStackInfoFromStackTrace.test.ts +40 -0
- package/src/__tests__/reactive.test.ts +194 -142
- package/src/__tests__/reactiveQueries/sql.test.ts +372 -0
- package/src/effect/LiveStore.ts +22 -31
- package/src/events.ts +1 -1
- package/src/inMemoryDatabase.ts +117 -142
- package/src/index.ts +18 -22
- package/src/migrations.ts +119 -0
- package/src/otel.ts +0 -11
- package/src/react/LiveStoreProvider.tsx +24 -23
- package/src/react/index.ts +12 -7
- package/src/react/useComponentState.ts +409 -0
- package/src/react/useQuery.ts +58 -0
- package/src/react/useTemporaryQuery.ts +21 -0
- package/src/react/utils/extractStackInfoFromStackTrace.ts +47 -0
- package/src/reactive.ts +386 -267
- package/src/reactiveQueries/base-class.ts +61 -39
- package/src/reactiveQueries/graph.ts +15 -0
- package/src/reactiveQueries/graphql.ts +147 -31
- package/src/reactiveQueries/js.ts +54 -21
- package/src/reactiveQueries/sql.ts +128 -37
- package/src/schema.ts +69 -145
- package/src/storage/in-memory/index.ts +21 -0
- package/src/storage/index.ts +27 -0
- package/src/{backends/tauri.ts → storage/tauri/index.ts} +14 -28
- package/src/storage/web-worker/index.ts +116 -0
- package/src/{backends/web-worker.ts → storage/web-worker/worker.ts} +17 -52
- package/src/store.ts +466 -457
- package/src/util.ts +13 -3
- package/tsconfig.json +1 -3
- package/src/backends/base.ts +0 -67
- package/src/backends/index.ts +0 -98
- package/src/backends/noop.ts +0 -32
- package/src/backends/web-in-memory.ts +0 -65
- package/src/backends/web.ts +0 -97
- package/src/react/useGlobalQuery.ts +0 -40
- package/src/react/useGraphQL.ts +0 -112
- package/src/react/useLiveStoreComponent.ts +0 -483
- /package/src/{backends → storage}/utils/idb.ts +0 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React, { useEffect, useState } from 'react';
|
|
2
|
+
import { labelForKey } from '../componentKey.js';
|
|
3
|
+
import { useStore } from './LiveStoreContext.js';
|
|
4
|
+
export const useGlobalQuery = (queryDef) => {
|
|
5
|
+
const { store } = useStore();
|
|
6
|
+
const query = React.useMemo(() => queryDef(store), [store, queryDef]);
|
|
7
|
+
// We know the query has a result by the time we use it; so we can synchronously populate a default state
|
|
8
|
+
const [value, setValue] = useState(query.results$.result);
|
|
9
|
+
// Subscribe to future updates for this query
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
return query.store.otel.tracer.startActiveSpan(`LiveStore:useGlobalQuery:${labelForKey(query.componentKey)}:${query.label}`, {}, query.store.otel.queriesSpanContext, (span) => {
|
|
12
|
+
const cancel = query.store.subscribe(query, (v) => {
|
|
13
|
+
// NOTE: we return a reference to the result object within LiveStore;
|
|
14
|
+
// this implies that app code must not mutate the results, or else
|
|
15
|
+
// there may be weird reactivity bugs.
|
|
16
|
+
return setValue(v);
|
|
17
|
+
}, undefined, { label: query.label });
|
|
18
|
+
return () => {
|
|
19
|
+
cancel();
|
|
20
|
+
span.end();
|
|
21
|
+
};
|
|
22
|
+
});
|
|
23
|
+
}, [query]);
|
|
24
|
+
return value;
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=useGlobalQuery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useGlobalQuery.js","sourceRoot":"","sources":["../../src/react/useGlobalQuery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAElD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAEhD,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAEhD,MAAM,CAAC,MAAM,cAAc,GAAG,CAA2B,QAAkC,EAAkB,EAAE;IAC7G,MAAM,EAAE,KAAK,EAAE,GAAG,QAAQ,EAAE,CAAA;IAC5B,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAA;IACrE,yGAAyG;IACzG,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAiB,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;IAEzE,6CAA6C;IAC7C,SAAS,CAAC,GAAG,EAAE;QACb,OAAO,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,eAAe,CAC5C,4BAA4B,WAAW,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,KAAK,CAAC,KAAK,EAAE,EAC5E,EAAE,EACF,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,kBAAkB,EACnC,CAAC,IAAI,EAAE,EAAE;YACP,MAAM,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,SAAS,CAClC,KAAK,EACL,CAAC,CAAC,EAAE,EAAE;gBACJ,qEAAqE;gBACrE,kEAAkE;gBAClE,sCAAsC;gBACtC,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAA;YACpB,CAAC,EACD,SAAS,EACT,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CACvB,CAAA;YACD,OAAO,GAAG,EAAE;gBACV,MAAM,EAAE,CAAA;gBACR,IAAI,CAAC,GAAG,EAAE,CAAA;YACZ,CAAC,CAAA;QACH,CAAC,CACF,CAAA;IACH,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAA;IAEX,OAAO,KAAK,CAAA;AACd,CAAC,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { type ComponentKeyConfig } from './useComponentState.js';
|
|
4
|
+
export type UseComponentStateProps<TResult extends Record<string, any>, TVariables extends Record<string, any>> = {
|
|
5
|
+
query: DocumentNode<TResult, TVariables>;
|
|
6
|
+
variables: TVariables;
|
|
7
|
+
componentKey: ComponentKeyConfig;
|
|
8
|
+
reactDeps?: React.DependencyList;
|
|
9
|
+
};
|
|
10
|
+
type Variables = Record<string, any>;
|
|
11
|
+
export declare const useGraphQL: <TResult extends Record<string, any>, TVariables extends Variables = {}>({ query: document, variables, componentKey: componentKeyConfig, reactDeps, }: UseComponentStateProps<TResult, TVariables>) => Readonly<TResult>;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=useGraphQL.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useGraphQL.d.ts","sourceRoot":"","sources":["../../src/react/useGraphQL.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,IAAI,YAAY,EAAE,MAAM,mCAAmC,CAAA;AAG1F,OAAO,KAAK,MAAM,OAAO,CAAA;AAKzB,OAAO,EAAE,KAAK,kBAAkB,EAAmB,MAAM,wBAAwB,CAAA;AAGjF,MAAM,MAAM,sBAAsB,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,UAAU,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI;IAChH,KAAK,EAAE,YAAY,CAAC,OAAO,EAAE,UAAU,CAAC,CAAA;IACxC,SAAS,EAAE,UAAU,CAAA;IACrB,YAAY,EAAE,kBAAkB,CAAA;IAChC,SAAS,CAAC,EAAE,KAAK,CAAC,cAAc,CAAA;CACjC,CAAA;AAED,KAAK,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;AAepC,eAAO,MAAM,UAAU,0NAuGtB,CAAA"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import * as otel from '@opentelemetry/api';
|
|
2
|
+
import { isEqual } from 'lodash-es';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { labelForKey } from '../componentKey.js';
|
|
5
|
+
import { queryGraphQL } from '../reactiveQueries/graphql.js';
|
|
6
|
+
import { useStore } from './LiveStoreContext.js';
|
|
7
|
+
import { useComponentKey } from './useComponentState.js';
|
|
8
|
+
import { useStateRefWithReactiveInput } from './utils/useStateRefWithReactiveInput.js';
|
|
9
|
+
// TODO get rid of the query cache in favour of the new side-effect-free query definition approach https://www.notion.so/schickling/New-query-definition-approach-1097a78ef0e9495bac25f90417374756?pvs=4
|
|
10
|
+
// NOTE we're using a nested map here since we need to resolve 2 levels of object identities (query + variables)
|
|
11
|
+
// const queryCache = new Map<DocumentNode<any, any>, Map<Variables, LiveStoreGraphQLQuery<any, any, any>>>()
|
|
12
|
+
/**
|
|
13
|
+
* This is needed because the `React.useMemo` call below, can sometimes be called multiple times 🤷,
|
|
14
|
+
* so we need to "cache" the fact that we've already started a span for this component.
|
|
15
|
+
* The map entry is being removed again in the `React.useEffect` call below.
|
|
16
|
+
*/
|
|
17
|
+
const spanAlreadyStartedCache = new Map();
|
|
18
|
+
// TODO 1) figure out a way to make `variables` optional if the query doesn't have any variables (probably requires positional args)
|
|
19
|
+
// TODO 2) allow `.pipe` on the resulting query (possibly as a separate optional prop)
|
|
20
|
+
export const useGraphQL = ({ query: document, variables, componentKey: componentKeyConfig, reactDeps = [], }) => {
|
|
21
|
+
const componentKey = useComponentKey(componentKeyConfig, reactDeps);
|
|
22
|
+
const { store } = useStore();
|
|
23
|
+
const componentKeyLabel = React.useMemo(() => labelForKey(componentKey), [componentKey]);
|
|
24
|
+
// The following `React.useMemo` and `React.useEffect` calls are used to start and end a span for the lifetime of this component.
|
|
25
|
+
const { span, otelContext } = React.useMemo(() => {
|
|
26
|
+
const existingSpan = spanAlreadyStartedCache.get(componentKeyLabel);
|
|
27
|
+
if (existingSpan !== undefined)
|
|
28
|
+
return existingSpan;
|
|
29
|
+
const span = store.otel.tracer.startSpan(`LiveStore:useGraphQL:${componentKeyLabel}`, {}, store.otel.queriesSpanContext);
|
|
30
|
+
const otelContext = otel.trace.setSpan(otel.context.active(), span);
|
|
31
|
+
spanAlreadyStartedCache.set(componentKeyLabel, { span, otelContext });
|
|
32
|
+
return { span, otelContext };
|
|
33
|
+
}, [componentKeyLabel, store.otel.queriesSpanContext, store.otel.tracer]);
|
|
34
|
+
React.useEffect(() => () => {
|
|
35
|
+
spanAlreadyStartedCache.delete(componentKeyLabel);
|
|
36
|
+
span.end();
|
|
37
|
+
}, [componentKeyLabel, span]);
|
|
38
|
+
const liveStoreQuery = React.useMemo(() => {
|
|
39
|
+
return queryGraphQL(document, () => variables ?? {}, {
|
|
40
|
+
/* componentKey, */
|
|
41
|
+
});
|
|
42
|
+
// NOTE I had to disable the caching below as still led to many problems
|
|
43
|
+
// We should just implement the new query definition approach instead
|
|
44
|
+
// const queryCacheForQuery = queryCache.get(query)
|
|
45
|
+
// if (queryCacheForQuery && queryCacheForQuery.has(variables)) {
|
|
46
|
+
// return queryCacheForQuery.get(variables)!
|
|
47
|
+
// }
|
|
48
|
+
// const newQuery = store.queryGraphQL(query, () => variables ?? ({} as TVariables), { componentKey, otelContext })
|
|
49
|
+
// if (queryCacheForQuery) {
|
|
50
|
+
// queryCacheForQuery.set(variables, newQuery)
|
|
51
|
+
// } else {
|
|
52
|
+
// queryCache.set(query, new Map([[variables, newQuery]]))
|
|
53
|
+
// }
|
|
54
|
+
// return newQuery
|
|
55
|
+
},
|
|
56
|
+
// NOTE: we don't include the queries function passed in by the user here;
|
|
57
|
+
// the reason is that we don't want to force them to memoize that function.
|
|
58
|
+
// Instead, we just assume that the function always has the same contents.
|
|
59
|
+
// This makes sense for LiveStore because the component config should be static.
|
|
60
|
+
// TODO: document this and consider whether it's the right API surface.
|
|
61
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
62
|
+
[componentKey, store]);
|
|
63
|
+
// TODO get rid of the temporary query workaround
|
|
64
|
+
const initialQueryResults = React.useMemo(() => liveStoreQuery.run(), [liveStoreQuery]);
|
|
65
|
+
const [queryResultsRef, setQueryResults_] = useStateRefWithReactiveInput(initialQueryResults);
|
|
66
|
+
React.useEffect(() => {
|
|
67
|
+
const unsubscribe = store.subscribe(liveStoreQuery, (results) => {
|
|
68
|
+
if (isEqual(results, queryResultsRef.current) === false) {
|
|
69
|
+
setQueryResults_(results);
|
|
70
|
+
}
|
|
71
|
+
}, undefined, { label: `useGraphQL:query:subscribe:${liveStoreQuery.label}` });
|
|
72
|
+
return () => {
|
|
73
|
+
unsubscribe();
|
|
74
|
+
};
|
|
75
|
+
// NOTE `setQueryResults_` from the deps array as it seems to cause an infinite loop
|
|
76
|
+
// This should probably be improved
|
|
77
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
78
|
+
}, [
|
|
79
|
+
liveStoreQuery,
|
|
80
|
+
// setQueryResults_,
|
|
81
|
+
store,
|
|
82
|
+
]);
|
|
83
|
+
// Very important: remove any queries / other resources associated w/ this component
|
|
84
|
+
React.useEffect(() => () => liveStoreQuery.destroy(), [liveStoreQuery]);
|
|
85
|
+
return queryResultsRef.current;
|
|
86
|
+
};
|
|
87
|
+
//# sourceMappingURL=useGraphQL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useGraphQL.js","sourceRoot":"","sources":["../../src/react/useGraphQL.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,IAAI,MAAM,oBAAoB,CAAA;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAA;AAC5D,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAChD,OAAO,EAA2B,eAAe,EAAE,MAAM,wBAAwB,CAAA;AACjF,OAAO,EAAE,4BAA4B,EAAE,MAAM,yCAAyC,CAAA;AAWtF,wMAAwM;AACxM,gHAAgH;AAChH,6GAA6G;AAE7G;;;;GAIG;AACH,MAAM,uBAAuB,GAAG,IAAI,GAAG,EAA0D,CAAA;AAEjG,oIAAoI;AACpI,sFAAsF;AACtF,MAAM,CAAC,MAAM,UAAU,GAAG,CAAyE,EACjG,KAAK,EAAE,QAAQ,EACf,SAAS,EACT,YAAY,EAAE,kBAAkB,EAChC,SAAS,GAAG,EAAE,GAC8B,EAAqB,EAAE;IACnE,MAAM,YAAY,GAAG,eAAe,CAAC,kBAAkB,EAAE,SAAS,CAAC,CAAA;IACnE,MAAM,EAAE,KAAK,EAAE,GAAG,QAAQ,EAAE,CAAA;IAE5B,MAAM,iBAAiB,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,WAAW,CAAC,YAAY,CAAC,EAAE,CAAC,YAAY,CAAC,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75 @@
|
|
|
1
|
+
import type { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core';
|
|
2
|
+
import type { LiteralUnion, PrettifyFlat } from '@livestore/utils';
|
|
3
|
+
import { SqliteDsl } from 'effect-db-schema';
|
|
4
|
+
import type { DependencyList } from 'react';
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import type { ComponentKey } from '../componentKey.js';
|
|
7
|
+
import type { GetAtomResult } from '../reactiveQueries/base-class.js';
|
|
8
|
+
import { type LiveStoreGraphQLQuery } from '../reactiveQueries/graphql.js';
|
|
9
|
+
import { LiveStoreJSQuery } from '../reactiveQueries/js.js';
|
|
10
|
+
import { LiveStoreSQLQuery } from '../reactiveQueries/sql.js';
|
|
11
|
+
import type { BaseGraphQLContext, LiveStoreQuery, QueryResult } from '../store.js';
|
|
12
|
+
import type { Bindable } from '../util.js';
|
|
13
|
+
export interface QueryDefinitions {
|
|
14
|
+
[queryName: string]: LiveStoreQuery;
|
|
15
|
+
}
|
|
16
|
+
export type QueryResults<TQuery> = {
|
|
17
|
+
[queryName in keyof TQuery]: PrettifyFlat<QueryResult<TQuery[queryName]>>;
|
|
18
|
+
};
|
|
19
|
+
export type ReactiveSQL = <TResult>(query: string | ((get: GetAtomResult) => string), queriedTables: string[], bindValues?: Bindable | undefined) => LiveStoreSQLQuery<TResult>;
|
|
20
|
+
export type ReactiveJS = <TResult>(query: (get: GetAtomResult) => TResult) => LiveStoreJSQuery<TResult>;
|
|
21
|
+
export type ReactiveGraphQL = <TResult extends Record<string, any>, TVariables extends Record<string, any>, TContext extends BaseGraphQLContext>(query: DocumentNode<TResult, TVariables>, variableValues: TVariables | ((get: GetAtomResult) => TVariables), label?: string) => LiveStoreGraphQLQuery<TResult, TVariables, TContext>;
|
|
22
|
+
type RegisterSubscription = <TQuery extends LiveStoreQuery>(query: TQuery, onNewValue: (value: QueryResult<TQuery>) => void, onUnsubscribe?: () => void) => void;
|
|
23
|
+
type GenQueries<TQueries, TStateResult> = (args: {
|
|
24
|
+
rxSQL: ReactiveSQL;
|
|
25
|
+
rxGraphQL: ReactiveGraphQL;
|
|
26
|
+
state$: LiveStoreJSQuery<TStateResult>;
|
|
27
|
+
/**
|
|
28
|
+
* Registers a subscription.
|
|
29
|
+
*
|
|
30
|
+
* Passed down for some manual subscribing. Use carefully.
|
|
31
|
+
*/
|
|
32
|
+
subscribe: RegisterSubscription;
|
|
33
|
+
isTemporaryQuery: boolean;
|
|
34
|
+
}) => TQueries;
|
|
35
|
+
export type UseLiveStoreComponentProps<TQueries, TStateColumns extends ComponentColumns> = {
|
|
36
|
+
stateSchema?: SqliteDsl.TableDefinition<string, TStateColumns>;
|
|
37
|
+
queries?: GenQueries<TQueries, SqliteDsl.FromColumns.RowDecoded<TStateColumns>>;
|
|
38
|
+
reactDeps?: React.DependencyList;
|
|
39
|
+
componentKey: ComponentKeyConfig;
|
|
40
|
+
};
|
|
41
|
+
export type ComponentKeyConfig = {
|
|
42
|
+
/**
|
|
43
|
+
* Name of the Component
|
|
44
|
+
*
|
|
45
|
+
* TODO we should eventually derive this info automatically from the component (TBD how though...)
|
|
46
|
+
*/
|
|
47
|
+
name: string;
|
|
48
|
+
id: LiteralUnion<'singleton' | '__ephemeral__', string>;
|
|
49
|
+
};
|
|
50
|
+
export interface ComponentColumns extends SqliteDsl.Columns {
|
|
51
|
+
id: SqliteDsl.ColumnDefinition<SqliteDsl.FieldType.FieldTypeText<string, string>, false>;
|
|
52
|
+
}
|
|
53
|
+
type UseLiveStoreJsonState<TState> = <TResult>(jsonStringKey: keyof TState, parse?: (_: unknown) => TResult) => [value: TResult, setValue: (newVal: TResult | ((prevVal: TResult) => TResult)) => void];
|
|
54
|
+
export type GetStateType<TTableDef extends SqliteDsl.TableDefinition<any, any>> = SqliteDsl.FromColumns.RowDecoded<TTableDef['columns']>;
|
|
55
|
+
export type GetStateTypeEncoded<TTableDef extends SqliteDsl.TableDefinition<any, any>> = SqliteDsl.FromColumns.RowEncoded<TTableDef['columns']>;
|
|
56
|
+
/**
|
|
57
|
+
* Create reactive queries within a component.
|
|
58
|
+
* @param config.queries A function that returns a map of named reactive queries.
|
|
59
|
+
* @param config.componentKey A function that returns a unique key for this component.
|
|
60
|
+
* @param config.reactDeps A list of React-level dependencies that will refresh the queries.
|
|
61
|
+
*/
|
|
62
|
+
export declare const useLiveStoreComponent: <TStateColumns extends ComponentColumns, TQueries extends QueryDefinitions>({ stateSchema: stateSchema_, queries: queriesDef, componentKey: componentKeyConfig, reactDeps, }: UseLiveStoreComponentProps<TQueries, TStateColumns>) => {
|
|
63
|
+
queryResults: QueryResults<TQueries>;
|
|
64
|
+
state: import("effect-db-schema").PrettifyFlat<import("effect-db-schema").Nullable<Pick<SqliteDsl.FromColumns.RowDecodedAll<TStateColumns>, keyof { [K in keyof TStateColumns as TStateColumns[K] extends SqliteDsl.ColumnDefinition<any, true> ? K : never]: {}; }>> & Omit<SqliteDsl.FromColumns.RowDecodedAll<TStateColumns>, keyof { [K in keyof TStateColumns as TStateColumns[K] extends SqliteDsl.ColumnDefinition<any, true> ? K : never]: {}; }>>;
|
|
65
|
+
setState: Setters<import("effect-db-schema").PrettifyFlat<import("effect-db-schema").Nullable<Pick<SqliteDsl.FromColumns.RowDecodedAll<TStateColumns>, keyof { [K in keyof TStateColumns as TStateColumns[K] extends SqliteDsl.ColumnDefinition<any, true> ? K : never]: {}; }>> & Omit<SqliteDsl.FromColumns.RowDecodedAll<TStateColumns>, keyof { [K in keyof TStateColumns as TStateColumns[K] extends SqliteDsl.ColumnDefinition<any, true> ? K : never]: {}; }>>>;
|
|
66
|
+
useLiveStoreJsonState: UseLiveStoreJsonState<import("effect-db-schema").PrettifyFlat<import("effect-db-schema").Nullable<Pick<SqliteDsl.FromColumns.RowDecodedAll<TStateColumns>, keyof { [K in keyof TStateColumns as TStateColumns[K] extends SqliteDsl.ColumnDefinition<any, true> ? K : never]: {}; }>> & Omit<SqliteDsl.FromColumns.RowDecodedAll<TStateColumns>, keyof { [K in keyof TStateColumns as TStateColumns[K] extends SqliteDsl.ColumnDefinition<any, true> ? K : never]: {}; }>>>;
|
|
67
|
+
};
|
|
68
|
+
export type Setters<TComponentState> = {
|
|
69
|
+
[k in keyof TComponentState]: (newValue: TComponentState[k]) => void;
|
|
70
|
+
} & {
|
|
71
|
+
setMany: (newValues: Partial<TComponentState>) => void;
|
|
72
|
+
};
|
|
73
|
+
export declare const useComponentKey: ({ name, id }: ComponentKeyConfig, deps?: DependencyList) => ComponentKey;
|
|
74
|
+
export {};
|
|
75
|
+
//# sourceMappingURL=useLiveStoreComponent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useLiveStoreComponent.d.ts","sourceRoot":"","sources":["../../src/react/useLiveStoreComponent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,IAAI,YAAY,EAAE,MAAM,mCAAmC,CAAA;AAC1F,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAIlE,OAAO,EAAa,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAEvD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,OAAO,CAAA;AAC3C,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAGtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAA;AACrE,OAAO,EAAE,KAAK,qBAAqB,EAAgB,MAAM,+BAA+B,CAAA;AACxF,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAA;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAE7D,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,WAAW,EAAS,MAAM,aAAa,CAAA;AACzF,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAK1C,MAAM,WAAW,gBAAgB;IAC/B,CAAC,SAAS,EA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,SAAS,SAAS,SAAS,CAAC,eAAe,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,SAAS,CAAC,WAAW,CAAC,UAAU,CAChH,SAAS,CAAC,SAAS,CAAC,CACrB,CAAA;AAED,MAAM,MAAM,mBAAmB,CAAC,SAAS,SAAS,SAAS,CAAC,eAAe,CAAC,GAAG,EAAE,GAAG,CAAC,IACnF,SAAS,CAAC,WAAW,CAAC,UAAU,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAA;AAExD;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB;;;;;CA8ajC,CAAA;AAED,MAAM,MAAM,OAAO,CAAC,eAAe,IAAI;KACpC,CAAC,IAAI,MAAM,eAAe,GAAG,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC,CAAC,KAAK,IAAI;CACrE,GAAG;IACF,OAAO,EAAE,CAAC,SAAS,EAAE,OAAO,CAAC,eAAe,CAAC,KAAK,IAAI,CAAA;CACvD,CAAA;AAED,eAAO,MAAM,eAAe,iBAAkB,kBAAkB,wCAcvC,CAAA"}
|
|
@@ -0,0 +1,361 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAE/C,OAAO,EAA8B,YAAY,EAAE,MAAM,+BAA+B,CAAA;AACxF,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAA;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAGhD,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAA;AAChC,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,C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