@livestore/livestore 0.0.9 → 0.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (152) hide show
  1. package/package.json +7 -7
  2. package/src/__tests__/react/fixture.tsx +1 -13
  3. package/src/__tests__/reactive.test.ts +39 -0
  4. package/src/inMemoryDatabase.ts +5 -5
  5. package/src/react/useGraphQL.ts +6 -7
  6. package/src/react/useLiveStoreComponent.ts +38 -48
  7. package/src/reactive.ts +12 -11
  8. package/src/reactiveQueries/graphql.ts +5 -3
  9. package/src/reactiveQueries/js.ts +1 -3
  10. package/src/reactiveQueries/sql.ts +6 -6
  11. package/src/store.ts +45 -31
  12. package/dist/.tsbuildinfo +0 -1
  13. package/dist/QueryCache.d.ts +0 -20
  14. package/dist/QueryCache.d.ts.map +0 -1
  15. package/dist/QueryCache.js +0 -71
  16. package/dist/QueryCache.js.map +0 -1
  17. package/dist/__tests__/react/fixture.d.ts +0 -141
  18. package/dist/__tests__/react/fixture.d.ts.map +0 -1
  19. package/dist/__tests__/react/fixture.js +0 -72
  20. package/dist/__tests__/react/fixture.js.map +0 -1
  21. package/dist/__tests__/react/useLiveStoreComponent.test.d.ts +0 -2
  22. package/dist/__tests__/react/useLiveStoreComponent.test.d.ts.map +0 -1
  23. package/dist/__tests__/react/useLiveStoreComponent.test.js +0 -78
  24. package/dist/__tests__/react/useLiveStoreComponent.test.js.map +0 -1
  25. package/dist/__tests__/reactive.test.d.ts +0 -2
  26. package/dist/__tests__/reactive.test.d.ts.map +0 -1
  27. package/dist/__tests__/reactive.test.js +0 -167
  28. package/dist/__tests__/reactive.test.js.map +0 -1
  29. package/dist/backends/base.d.ts +0 -13
  30. package/dist/backends/base.d.ts.map +0 -1
  31. package/dist/backends/base.js +0 -53
  32. package/dist/backends/base.js.map +0 -1
  33. package/dist/backends/index.d.ts +0 -45
  34. package/dist/backends/index.d.ts.map +0 -1
  35. package/dist/backends/index.js +0 -38
  36. package/dist/backends/index.js.map +0 -1
  37. package/dist/backends/noop.d.ts +0 -18
  38. package/dist/backends/noop.d.ts.map +0 -1
  39. package/dist/backends/noop.js +0 -21
  40. package/dist/backends/noop.js.map +0 -1
  41. package/dist/backends/tauri.d.ts +0 -22
  42. package/dist/backends/tauri.d.ts.map +0 -1
  43. package/dist/backends/tauri.js +0 -48
  44. package/dist/backends/tauri.js.map +0 -1
  45. package/dist/backends/utils/idb.d.ts +0 -10
  46. package/dist/backends/utils/idb.d.ts.map +0 -1
  47. package/dist/backends/utils/idb.js +0 -58
  48. package/dist/backends/utils/idb.js.map +0 -1
  49. package/dist/backends/web-in-memory.d.ts +0 -22
  50. package/dist/backends/web-in-memory.d.ts.map +0 -1
  51. package/dist/backends/web-in-memory.js +0 -45
  52. package/dist/backends/web-in-memory.js.map +0 -1
  53. package/dist/backends/web-worker.d.ts +0 -17
  54. package/dist/backends/web-worker.d.ts.map +0 -1
  55. package/dist/backends/web-worker.js +0 -139
  56. package/dist/backends/web-worker.js.map +0 -1
  57. package/dist/backends/web.d.ts +0 -27
  58. package/dist/backends/web.d.ts.map +0 -1
  59. package/dist/backends/web.js +0 -63
  60. package/dist/backends/web.js.map +0 -1
  61. package/dist/bounded-collections.d.ts +0 -34
  62. package/dist/bounded-collections.d.ts.map +0 -1
  63. package/dist/bounded-collections.js +0 -103
  64. package/dist/bounded-collections.js.map +0 -1
  65. package/dist/componentKey.d.ts +0 -20
  66. package/dist/componentKey.d.ts.map +0 -1
  67. package/dist/componentKey.js +0 -3
  68. package/dist/componentKey.js.map +0 -1
  69. package/dist/effect/LiveStore.d.ts +0 -42
  70. package/dist/effect/LiveStore.d.ts.map +0 -1
  71. package/dist/effect/LiveStore.js +0 -40
  72. package/dist/effect/LiveStore.js.map +0 -1
  73. package/dist/effect/index.d.ts +0 -2
  74. package/dist/effect/index.d.ts.map +0 -1
  75. package/dist/effect/index.js +0 -2
  76. package/dist/effect/index.js.map +0 -1
  77. package/dist/events.d.ts +0 -7
  78. package/dist/events.d.ts.map +0 -1
  79. package/dist/events.js +0 -2
  80. package/dist/events.js.map +0 -1
  81. package/dist/inMemoryDatabase.d.ts +0 -65
  82. package/dist/inMemoryDatabase.d.ts.map +0 -1
  83. package/dist/inMemoryDatabase.js +0 -241
  84. package/dist/inMemoryDatabase.js.map +0 -1
  85. package/dist/index.d.ts +0 -20
  86. package/dist/index.d.ts.map +0 -1
  87. package/dist/index.js +0 -10
  88. package/dist/index.js.map +0 -1
  89. package/dist/otel.d.ts +0 -5
  90. package/dist/otel.d.ts.map +0 -1
  91. package/dist/otel.js +0 -17
  92. package/dist/otel.js.map +0 -1
  93. package/dist/react/LiveStoreContext.d.ts +0 -11
  94. package/dist/react/LiveStoreContext.d.ts.map +0 -1
  95. package/dist/react/LiveStoreContext.js +0 -10
  96. package/dist/react/LiveStoreContext.js.map +0 -1
  97. package/dist/react/LiveStoreProvider.d.ts +0 -21
  98. package/dist/react/LiveStoreProvider.d.ts.map +0 -1
  99. package/dist/react/LiveStoreProvider.js +0 -48
  100. package/dist/react/LiveStoreProvider.js.map +0 -1
  101. package/dist/react/index.d.ts +0 -7
  102. package/dist/react/index.d.ts.map +0 -1
  103. package/dist/react/index.js +0 -6
  104. package/dist/react/index.js.map +0 -1
  105. package/dist/react/useGlobalQuery.d.ts +0 -3
  106. package/dist/react/useGlobalQuery.d.ts.map +0 -1
  107. package/dist/react/useGlobalQuery.js +0 -25
  108. package/dist/react/useGlobalQuery.js.map +0 -1
  109. package/dist/react/useGraphQL.d.ts +0 -11
  110. package/dist/react/useGraphQL.d.ts.map +0 -1
  111. package/dist/react/useGraphQL.js +0 -68
  112. package/dist/react/useGraphQL.js.map +0 -1
  113. package/dist/react/useLiveStoreComponent.d.ts +0 -70
  114. package/dist/react/useLiveStoreComponent.d.ts.map +0 -1
  115. package/dist/react/useLiveStoreComponent.js +0 -261
  116. package/dist/react/useLiveStoreComponent.js.map +0 -1
  117. package/dist/react/utils/useStateRefWithReactiveInput.d.ts +0 -13
  118. package/dist/react/utils/useStateRefWithReactiveInput.d.ts.map +0 -1
  119. package/dist/react/utils/useStateRefWithReactiveInput.js +0 -38
  120. package/dist/react/utils/useStateRefWithReactiveInput.js.map +0 -1
  121. package/dist/reactive.d.ts +0 -140
  122. package/dist/reactive.d.ts.map +0 -1
  123. package/dist/reactive.js +0 -301
  124. package/dist/reactive.js.map +0 -1
  125. package/dist/reactiveQueries/base-class.d.ts +0 -24
  126. package/dist/reactiveQueries/base-class.d.ts.map +0 -1
  127. package/dist/reactiveQueries/base-class.js +0 -22
  128. package/dist/reactiveQueries/base-class.js.map +0 -1
  129. package/dist/reactiveQueries/graphql.d.ts +0 -25
  130. package/dist/reactiveQueries/graphql.d.ts.map +0 -1
  131. package/dist/reactiveQueries/graphql.js +0 -14
  132. package/dist/reactiveQueries/graphql.js.map +0 -1
  133. package/dist/reactiveQueries/js.d.ts +0 -19
  134. package/dist/reactiveQueries/js.d.ts.map +0 -1
  135. package/dist/reactiveQueries/js.js +0 -13
  136. package/dist/reactiveQueries/js.js.map +0 -1
  137. package/dist/reactiveQueries/sql.d.ts +0 -31
  138. package/dist/reactiveQueries/sql.d.ts.map +0 -1
  139. package/dist/reactiveQueries/sql.js +0 -28
  140. package/dist/reactiveQueries/sql.js.map +0 -1
  141. package/dist/schema.d.ts +0 -163
  142. package/dist/schema.d.ts.map +0 -1
  143. package/dist/schema.js +0 -92
  144. package/dist/schema.js.map +0 -1
  145. package/dist/store.d.ts +0 -175
  146. package/dist/store.d.ts.map +0 -1
  147. package/dist/store.js +0 -549
  148. package/dist/store.js.map +0 -1
  149. package/dist/util.d.ts +0 -24
  150. package/dist/util.d.ts.map +0 -1
  151. package/dist/util.js +0 -51
  152. package/dist/util.js.map +0 -1
@@ -1,70 +0,0 @@
1
- import type { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core';
2
- import { type LiteralUnion } from '@livestore/utils';
3
- import type { DependencyList } from 'react';
4
- import React from 'react';
5
- import type { ComponentKey } from '../componentKey.js';
6
- import type { GetAtom } from '../reactive.js';
7
- import type { LiveStoreGraphQLQuery } from '../reactiveQueries/graphql.js';
8
- import type { LiveStoreJSQuery } from '../reactiveQueries/js.js';
9
- import type { LiveStoreSQLQuery } from '../reactiveQueries/sql.js';
10
- import type { ComponentStateSchema } from '../schema.js';
11
- import type { BaseGraphQLContext, LiveStoreQuery, QueryResult } from '../store.js';
12
- export interface QueryDefinitions {
13
- [queryName: string]: LiveStoreQuery;
14
- }
15
- export type QueryResults<TQuery> = {
16
- [queryName in keyof TQuery]: QueryResult<TQuery[queryName]>;
17
- };
18
- export type ReactiveSQL = <TResult>(genQuery: (get: GetAtom) => string, queriedTables: string[]) => LiveStoreSQLQuery<TResult>;
19
- export type ReactiveGraphQL = <TResult extends Record<string, any>, TVariables extends Record<string, any>, TContext extends BaseGraphQLContext>(query: DocumentNode<TResult, TVariables>, genVariableValues: (get: GetAtom) => TVariables, label?: string) => LiveStoreGraphQLQuery<TResult, TVariables, TContext>;
20
- type RegisterSubscription = <TQuery extends LiveStoreQuery>(query: TQuery, onNewValue: (value: QueryResult<TQuery>) => void, onUnsubscribe?: () => void) => void;
21
- type GenQueries<TQueries, TStateResult> = (args: {
22
- rxSQL: ReactiveSQL;
23
- rxGraphQL: ReactiveGraphQL;
24
- globalQueries: QueryDefinitions;
25
- state$: LiveStoreJSQuery<TStateResult>;
26
- /** Registers a subscription */
27
- subscribe: RegisterSubscription;
28
- isTemporaryQuery: boolean;
29
- }) => TQueries;
30
- export type UseLiveStoreComponentProps<TQueries, TComponentState> = {
31
- stateSchema?: ComponentStateSchema<TComponentState>;
32
- queries?: GenQueries<TQueries, TComponentState>;
33
- reactDeps?: React.DependencyList;
34
- componentKey: ComponentKeyConfig;
35
- };
36
- export type ComponentKeyConfig = {
37
- /**
38
- * Name of the Component
39
- *
40
- * TODO we should eventually derive this info automatically from the component (TBD how though...)
41
- */
42
- name: string;
43
- id: LiteralUnion<'singleton' | '__ephemeral__', string>;
44
- };
45
- type ComponentState = {
46
- /** Equivalent to `componentKey.key` */
47
- id: string;
48
- [key: string]: string | number | boolean | null;
49
- };
50
- type UseLiveStoreJsonState<TState> = <TResult>(jsonStringKey: keyof TState, parse?: (_: unknown) => TResult) => [value: TResult, setValue: (newVal: TResult | ((prevVal: TResult) => TResult)) => void];
51
- /**
52
- * Create reactive queries within a component.
53
- * @param config.queries A function that returns a map of named reactive queries.
54
- * @param config.componentKey A function that returns a unique key for this component.
55
- * @param config.reactDeps A list of React-level dependencies that will refresh the queries.
56
- */
57
- export declare const useLiveStoreComponent: <TComponentState extends ComponentState, TQueries extends QueryDefinitions>({ stateSchema: stateSchema_, queries, componentKey: componentKeyConfig, reactDeps, }: UseLiveStoreComponentProps<TQueries, TComponentState>) => {
58
- queryResults: QueryResults<TQueries>;
59
- state: TComponentState;
60
- setState: Setters<TComponentState>;
61
- useLiveStoreJsonState: UseLiveStoreJsonState<TComponentState>;
62
- };
63
- export type Setters<TComponentState> = {
64
- [k in keyof TComponentState]: (newValue: TComponentState[k]) => void;
65
- } & {
66
- setMany: (newValues: Partial<TComponentState>) => void;
67
- };
68
- export declare const useComponentKey: ({ name, id }: ComponentKeyConfig, deps?: DependencyList) => ComponentKey;
69
- export {};
70
- //# sourceMappingURL=useLiveStoreComponent.d.ts.map
@@ -1 +0,0 @@
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,EAAE,KAAK,YAAY,EAA2B,MAAM,kBAAkB,CAAA;AAG7E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,OAAO,CAAA;AAC3C,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAEtD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAC7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IAAI,CAAC,CAAA;AAE5F;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB;;;;;CA+UjC,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"}
@@ -1,261 +0,0 @@
1
- import { omit, shouldNeverHappen } from '@livestore/utils';
2
- import * as otel from '@opentelemetry/api';
3
- import { isEqual, mapValues } from 'lodash-es';
4
- import React from 'react';
5
- import { v4 as uuid } from 'uuid';
6
- import { labelForKey, tableNameForComponentKey } from '../componentKey.js';
7
- import { sql } from '../util.js';
8
- import { useStore } from './LiveStoreContext.js';
9
- import { useStateRefWithReactiveInput } from './utils/useStateRefWithReactiveInput.js';
10
- /**
11
- * This is needed because the `React.useMemo` call below, can sometimes be called multiple times 🤷,
12
- * so we need to "cache" the fact that we've already started a span for this component.
13
- * The map entry is being removed again in the `React.useEffect` call below.
14
- */
15
- const spanAlreadyStartedCache = new Map();
16
- /**
17
- * Create reactive queries within a component.
18
- * @param config.queries A function that returns a map of named reactive queries.
19
- * @param config.componentKey A function that returns a unique key for this component.
20
- * @param config.reactDeps A list of React-level dependencies that will refresh the queries.
21
- */
22
- export const useLiveStoreComponent = ({ stateSchema: stateSchema_, queries = () => ({}), componentKey: componentKeyConfig, reactDeps = [], }) => {
23
- // TODO we should clean up the state schema handling to remove this special handling for the `id` column
24
- const stateSchema = React.useMemo(() => (stateSchema_ ? { ...stateSchema_, columns: omit(stateSchema_.columns, 'id') } : undefined), [stateSchema_]);
25
- // performance.mark('useLiveStoreComponent:start')
26
- const componentKey = useComponentKey(componentKeyConfig, reactDeps);
27
- const { store, globalQueries } = useStore();
28
- const componentKeyLabel = React.useMemo(() => labelForKey(componentKey), [componentKey]);
29
- // The following `React.useMemo` and `React.useEffect` calls are used to start and end a span for the lifetime of this component.
30
- const { span, otelCtx } = React.useMemo(() => {
31
- const existingSpan = spanAlreadyStartedCache.get(componentKeyLabel);
32
- if (existingSpan !== undefined)
33
- return existingSpan;
34
- const span = store.otel.tracer.startSpan(`LiveStore:useLiveStoreComponent:${componentKeyLabel}`, {}, store.otel.queriesSpanContext);
35
- const otelCtx = otel.trace.setSpan(otel.context.active(), span);
36
- spanAlreadyStartedCache.set(componentKeyLabel, { span, otelCtx });
37
- return { span, otelCtx };
38
- }, [componentKeyLabel, store.otel.queriesSpanContext, store.otel.tracer]);
39
- React.useEffect(() => () => {
40
- spanAlreadyStartedCache.delete(componentKeyLabel);
41
- span.end();
42
- }, [componentKeyLabel, span]);
43
- const generateQueries = React.useCallback(({ state$, otelCtx, registerSubscription, isTemporaryQuery, }) => queries({
44
- rxSQL: (genQuery, queriedTables) => store.querySQL(genQuery, queriedTables, undefined, componentKey, undefined, otelCtx),
45
- rxGraphQL: (query, genVariableValues, label) => store.queryGraphQL(query, genVariableValues, { componentKey, label }, otelCtx),
46
- globalQueries,
47
- state$,
48
- subscribe: registerSubscription,
49
- isTemporaryQuery,
50
- }),
51
- // NOTE: we don't include the queries function passed in by the user here;
52
- // the reason is that we don't want to force them to memoize that function.
53
- // Instead, we just assume that the function always has the same contents.
54
- // This makes sense for LiveStore because the component config should be static.
55
- // TODO: document this and consider whether it's the right API surface.
56
- // eslint-disable-next-line react-hooks/exhaustive-deps
57
- [store, componentKey, globalQueries]);
58
- const defaultComponentState = React.useMemo(() => {
59
- const defaultState = (stateSchema === undefined ? {} : mapValues(stateSchema.columns, (c) => c.default));
60
- defaultState.id = componentKeyConfig.id;
61
- return defaultState;
62
- }, [componentKeyConfig.id, stateSchema]);
63
- // Step 1:
64
- // Synchronously create state and queries for initial render pass.
65
- // We do this in a temporary query context which cleans up after itself, making it idempotent
66
- // TODO get rid of the temporary query workaround
67
- const { initialComponentState, initialQueryResults } = React.useMemo(() => {
68
- return store.otel.tracer.startActiveSpan('LiveStore:useLiveStoreComponent:initial', {}, otelCtx, (span) => {
69
- const otelCtx = otel.trace.setSpan(otel.context.active(), span);
70
- return store.inTempQueryContext(() => {
71
- try {
72
- // create state query
73
- let stateQuery;
74
- if (stateSchema === undefined) {
75
- // TODO don't set up a query if there's no state schema (keeps the graph more clean)
76
- stateQuery = store.queryJS(() => ({}), componentKey, undefined, otelCtx);
77
- }
78
- else {
79
- const componentTableName = tableNameForComponentKey(componentKey);
80
- const whereClause = componentKey._tag === 'singleton' ? '' : `where id = '${componentKey.id}'`;
81
- stateQuery = store
82
- .querySQL(() => sql `select * from ${componentTableName} ${whereClause} limit 1`, [componentTableName], undefined, componentKey, `localState:query:${componentKeyLabel}`, otelCtx)
83
- .getFirstRow({ defaultValue: defaultComponentState });
84
- }
85
- const initialComponentState = stateQuery.results$.result;
86
- const queries = generateQueries({
87
- state$: stateQuery,
88
- otelCtx,
89
- registerSubscription: () => { },
90
- isTemporaryQuery: true,
91
- });
92
- for (const [name, query] of Object.entries(queries)) {
93
- query.label = name;
94
- }
95
- const initialQueryResults = mapValues(queries, (query) => query.results$.result);
96
- return { initialComponentState, initialQueryResults };
97
- }
98
- finally {
99
- span.end();
100
- }
101
- });
102
- });
103
- }, [store, otelCtx, stateSchema, generateQueries, componentKey, componentKeyLabel, defaultComponentState]);
104
- // Now that we've computed the initial state synchronously,
105
- // we can set up our useState calls w/ a default value populated...
106
- const [componentStateRef, setComponentState_] = useStateRefWithReactiveInput(initialComponentState);
107
- const [queryResultsRef, setQueryResults_] = useStateRefWithReactiveInput(initialQueryResults);
108
- const setState = (stateSchema === undefined
109
- ? {}
110
- : // TODO: do we have a better type for the values that can go in SQLite?
111
- mapValues(stateSchema.columns, (_, columnName) => (value) => {
112
- // Don't update the state if it's the same as the value already seen in the component
113
- if (componentStateRef.current[columnName] === value)
114
- return;
115
- if (['componentKey', 'columnNames'].includes(columnName)) {
116
- shouldNeverHappen(`Can't use reserved column name ${columnName}`);
117
- }
118
- return store.applyEvent('updateComponentState', {
119
- componentKey,
120
- columnNames: [columnName],
121
- [columnName]: value,
122
- });
123
- }));
124
- setState.setMany = (columnValues) => {
125
- // TODO use hashing instead
126
- // Don't update the state if it's the same as the value already seen in the component
127
- if (Object.entries(columnValues).every(([columnName, value]) => componentStateRef.current[columnName] === value)) {
128
- return;
129
- }
130
- const columnNames = Object.keys(columnValues);
131
- return store.applyEvent('updateComponentState', { componentKey, columnNames, ...columnValues });
132
- };
133
- // OK, now all the synchronous work is done;
134
- // time to set up our long-running queries in an effect
135
- React.useEffect(() => {
136
- return store.otel.tracer.startActiveSpan('LiveStore:useLiveStoreComponent:long-running', { attributes: {} }, otelCtx, (span) => {
137
- const otelCtx = otel.trace.setSpan(otel.context.active(), span);
138
- const unsubs = [];
139
- // create state query
140
- let stateQuery;
141
- if (stateSchema === undefined) {
142
- stateQuery = store.queryJS(() => ({}), componentKey, undefined, otelCtx);
143
- }
144
- else {
145
- const componentTableName = tableNameForComponentKey(componentKey);
146
- insertRowForComponentInstance({ store, componentKey, stateSchema });
147
- const whereClause = componentKey._tag === 'singleton' ? '' : `where id = '${componentKey.id}'`;
148
- stateQuery = store
149
- .querySQL(() => sql `select * from ${componentTableName} ${whereClause} limit 1`, [componentTableName], undefined, componentKey,
150
- // TODO introduce a refresh "grouping" concept to associate related refreshes in the debugger UI
151
- `localState:query:${componentKeyLabel}`, otelCtx)
152
- .getFirstRow({ defaultValue: defaultComponentState });
153
- }
154
- unsubs.push(store.subscribe(stateQuery, (results) => {
155
- if (isEqual(results, componentStateRef.current) === false) {
156
- setComponentState_(results);
157
- }
158
- }, undefined, { label: `useLiveStoreComponent:localState:subscribe:${stateQuery.label}` }));
159
- const registerSubscription = (query, callback, onUnsubscribe) => {
160
- unsubs.push(store.subscribe(query, (results) => {
161
- callback(results);
162
- }, onUnsubscribe, { label: `useLiveStoreComponent:query:manual-subscribe:${query.label}` }));
163
- };
164
- const queries = generateQueries({ state$: stateQuery, otelCtx, registerSubscription, isTemporaryQuery: false });
165
- // Use the name given to this query in the useQueries hook as its label
166
- for (const [name, query] of Object.entries(queries)) {
167
- query.label = name;
168
- }
169
- for (const [key, query] of Object.entries(queries)) {
170
- unsubs.push(store.subscribe(query, (results) => {
171
- const newQueryResults = { ...queryResultsRef.current, [key]: results };
172
- if (isEqual(newQueryResults, queryResultsRef.current) === false) {
173
- setQueryResults_(newQueryResults);
174
- }
175
- }, undefined, { label: `useLiveStoreComponent:query:subscribe:${query.label}` }));
176
- }
177
- return () => {
178
- for (const unsub of unsubs) {
179
- unsub();
180
- }
181
- span.end();
182
- };
183
- });
184
- // NOTE excluding `setComponentState_` and `setQueryResults_` from the deps array as it seems to cause an infinite loop
185
- // This should probably be improved
186
- // eslint-disable-next-line react-hooks/exhaustive-deps
187
- }, [
188
- store,
189
- componentKey,
190
- stateSchema,
191
- defaultComponentState,
192
- generateQueries,
193
- otelCtx,
194
- componentStateRef,
195
- // setComponentState_,
196
- // setQueryResults_,
197
- ]);
198
- // Very important: remove any queries / other resources associated w/ this component
199
- React.useEffect(() => () => store.unmountComponent(componentKey), [store, componentKey]);
200
- // performance.mark('useLiveStoreComponent:end')
201
- // performance.measure(`useLiveStoreComponent:${componentKey.type}`, 'useLiveStoreComponent:start', 'useLiveStoreComponent:end')
202
- const state = componentStateRef.current;
203
- const useLiveStoreJsonState = (jsonStringKey, parse = (_) => _) => {
204
- const value = React.useMemo(() => {
205
- return parse(JSON.parse(state[jsonStringKey]));
206
- // eslint-disable-next-line react-hooks/exhaustive-deps
207
- }, [state[jsonStringKey], parse]);
208
- const setValue = React.useCallback((newValOrFn) => {
209
- const newVal = typeof newValOrFn === 'function'
210
- ? // NOTE we're using the ref instead of the value because we want to be sure
211
- // we're using the latest value when the setter is called
212
- newValOrFn(parse(JSON.parse(componentStateRef.current[jsonStringKey])))
213
- : newValOrFn;
214
- setState[jsonStringKey](JSON.stringify(newVal));
215
- }, [parse, jsonStringKey]);
216
- return [value, setValue];
217
- };
218
- return {
219
- queryResults: queryResultsRef.current,
220
- state,
221
- setState,
222
- useLiveStoreJsonState,
223
- };
224
- };
225
- export const useComponentKey = ({ name, id }, deps = []) => React.useMemo(() => {
226
- switch (id) {
227
- case 'singleton': {
228
- return { _tag: 'singleton', componentName: name, id: 'singleton' };
229
- }
230
- case '__ephemeral__': {
231
- return { _tag: 'ephemeral', componentName: name, id: uuid() };
232
- }
233
- default: {
234
- return { _tag: 'custom', componentName: name, id };
235
- }
236
- }
237
- // eslint-disable-next-line react-hooks/exhaustive-deps
238
- }, [...deps, id, name]);
239
- /**
240
- * Create a row storing the state for a component instance, if none exists yet.
241
- * Initialized with default values, and keyed on the component key.
242
- */
243
- const insertRowForComponentInstance = ({ store, componentKey, stateSchema, }) => {
244
- const columnNames = ['id', ...Object.keys(stateSchema.columns)];
245
- const columnValues = columnNames.map((name) => `$${name}`).join(', ');
246
- const tableName = tableNameForComponentKey(componentKey);
247
- const insertQuery = sql `insert into ${tableName} (${columnNames.join(', ')}) select ${columnValues} where not exists(select 1 from ${tableName} where id = '${componentKey.id}')`;
248
- void store.execute(insertQuery, {
249
- id: componentKey.id,
250
- ...mapValues(stateSchema.columns, (column) => prepareValueForSql(column.default ?? null)),
251
- }, [tableName]);
252
- };
253
- const prepareValueForSql = (value) => {
254
- if (typeof value === 'string' || typeof value === 'number' || value === null) {
255
- return value;
256
- }
257
- else {
258
- return value ? 1 : 0;
259
- }
260
- };
261
- //# sourceMappingURL=useLiveStoreComponent.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useLiveStoreComponent.js","sourceRoot":"","sources":["../../src/react/useLiveStoreComponent.ts"],"names":[],"mappings":"AACA,OAAO,EAAqB,IAAI,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAC7E,OAAO,KAAK,IAAI,MAAM,oBAAoB,CAAA;AAC1C,OAAO,EAAE,OAAO,EAAE,SA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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,13 +0,0 @@
1
- import React from 'react';
2
- /**
3
- * A variant of `React.useState` which allows the `inputState` to change over time as well.
4
- * Important: This hook is synchronous / single-render-pass (i.e. doesn't use `useEffect` or `setState` directly).
5
- *
6
- * Notes:
7
- * - The output state is always reset to the input state in case the input state changes (i.e. the previous "external" `setStateAndRerender` call is forgotten)
8
- * - This hook might not work properly with React Suspense
9
- * - Also see this Tweet for more potential problems: https://twitter.com/schickling/status/1677317711104278528
10
- *
11
- */
12
- export declare const useStateRefWithReactiveInput: <T>(inputState: T) => [React.MutableRefObject<T>, (newState: T | ((prev: T) => T)) => void];
13
- //# sourceMappingURL=useStateRefWithReactiveInput.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useStateRefWithReactiveInput.d.ts","sourceRoot":"","sources":["../../../src/react/utils/useStateRefWithReactiveInput.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB;;;;;;;;;GASG;AACH,eAAO,MAAM,4BAA4B,wFAE0B,IAAI,CAwBtE,CAAA"}
@@ -1,38 +0,0 @@
1
- import React from 'react';
2
- /**
3
- * A variant of `React.useState` which allows the `inputState` to change over time as well.
4
- * Important: This hook is synchronous / single-render-pass (i.e. doesn't use `useEffect` or `setState` directly).
5
- *
6
- * Notes:
7
- * - The output state is always reset to the input state in case the input state changes (i.e. the previous "external" `setStateAndRerender` call is forgotten)
8
- * - This hook might not work properly with React Suspense
9
- * - Also see this Tweet for more potential problems: https://twitter.com/schickling/status/1677317711104278528
10
- *
11
- */
12
- export const useStateRefWithReactiveInput = (inputState) => {
13
- const [_, rerender] = React.useState(0);
14
- const lastKnownInputStateRef = React.useRef(inputState);
15
- const stateRef = React.useRef(inputState);
16
- if (lastKnownInputStateRef.current !== inputState) {
17
- lastKnownInputStateRef.current = inputState;
18
- // NOTE we don't need to re-render here, because the component is already re-rendering due to the `inputState` change
19
- stateRef.current = inputState;
20
- }
21
- const setStateAndRerender = React.useCallback((newState) => {
22
- // @ts-expect-error https://github.com/microsoft/TypeScript/issues/37663
23
- const val = typeof newState === 'function' ? newState(stateRef.current) : newState;
24
- stateRef.current = val;
25
- rerender((c) => c + 1);
26
- }, [rerender]);
27
- return [stateRef, setStateAndRerender];
28
- };
29
- // Down-side of this implementation: Double render pass due to `setState` call (which forces a re-render)
30
- // Keeping around for now in case `useStateRefWithReactiveInput` doesn't work out
31
- // const _useStateWithReactiveInput = <T>(inputState: T): [T, (newState: T | ((prev: T) => T)) => void] => {
32
- // const [externalState, setExternalState] = React.useState(inputState)
33
- // if (externalState !== inputState) {
34
- // setExternalState(inputState)
35
- // }
36
- // return [externalState, setExternalState]
37
- // }
38
- //# sourceMappingURL=useStateRefWithReactiveInput.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useStateRefWithReactiveInput.js","sourceRoot":"","sources":["../../../src/react/utils/useStateRefWithReactiveInput.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAC1C,UAAa,EAC0D,EAAE;IACzE,MAAM,CAAC,CAAC,EAAE,QAAQ,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAA;IAEvC,MAAM,sBAAsB,GAAG,KAAK,CAAC,MAAM,CAAI,UAAU,CAAC,CAAA;IAC1D,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAI,UAAU,CAAC,CAAA;IAE5C,IAAI,sBAAsB,CAAC,OAAO,KAAK,UAAU,EAAE;QACjD,sBAAsB,CAAC,OAAO,GAAG,UAAU,CAAA;QAE3C,qHAAqH;QACrH,QAAQ,CAAC,OAAO,GAAG,UAAU,CAAA;KAC9B;IAED,MAAM,mBAAmB,GAAG,KAAK,CAAC,WAAW,CAC3C,CAAC,QAA8B,EAAE,EAAE;QACjC,wEAAwE;QACxE,MAAM,GAAG,GAAG,OAAO,QAAQ,KAAK,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAA;QAClF,QAAQ,CAAC,OAAO,GAAG,GAAG,CAAA;QACtB,QAAQ,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA;IACxB,CAAC,EACD,CAAC,QAAQ,CAAC,CACX,CAAA;IAED,OAAO,CAAC,QAAQ,EAAE,mBAAmB,CAAC,CAAA;AACxC,CAAC,CAAA;AAED,yGAAyG;AACzG,iFAAiF;AACjF,4GAA4G;AAC5G,yEAAyE;AAEzE,wCAAwC;AACxC,mCAAmC;AACnC,MAAM;AAEN,6CAA6C;AAC7C,IAAI"}
@@ -1,140 +0,0 @@
1
- import type { PrettifyFlat } from '@livestore/utils';
2
- import type * as otel from '@opentelemetry/api';
3
- import { BoundArray } from './bounded-collections.js';
4
- export type GetAtom = <T>(atom: Atom<T>) => T;
5
- export type Ref<T> = {
6
- _tag: 'ref';
7
- id: string;
8
- result: T;
9
- height: 0;
10
- getResult: () => T;
11
- sub: Set<Atom<any>>;
12
- super: Set<Atom<any> | Effect>;
13
- label?: string;
14
- /** Container for meta information (e.g. the LiveStore Store) */
15
- meta?: any;
16
- equal: (a: T, b: T) => boolean;
17
- };
18
- type BaseThunk<T> = {
19
- _tag: 'thunk';
20
- id: string;
21
- height: number;
22
- getResult: (get: GetAtom, addDebugInfo: (debugInfo: any) => void) => T;
23
- sub: Set<Atom<any>>;
24
- super: Set<Atom<any> | Effect>;
25
- label?: string;
26
- /** Container for meta information (e.g. the LiveStore Store) */
27
- meta?: any;
28
- equal: (a: T, b: T) => boolean;
29
- };
30
- export type Thunk<T> = BaseThunk<T> & {
31
- result: T;
32
- };
33
- export type Atom<T> = Ref<T> | Thunk<T>;
34
- export type Effect = {
35
- _tag: 'effect';
36
- id: string;
37
- doEffect: (get: GetAtom) => void;
38
- sub: Set<Atom<any>>;
39
- };
40
- export type Taggable<T extends string = string> = {
41
- _tag: T;
42
- };
43
- export type ReactiveGraphOptions = {
44
- effectsWrapper?: (runEffects: () => void) => void;
45
- otelTracer: otel.Tracer;
46
- };
47
- export type AtomDebugInfo<TDebugThunkInfo extends Taggable> = {
48
- atom: SerializedAtom;
49
- resultChanged: boolean;
50
- durationMs: number;
51
- debugInfo: TDebugThunkInfo;
52
- };
53
- export type RefreshDebugInfo<TDebugRefreshReason extends Taggable, TDebugThunkInfo extends Taggable> = {
54
- /** Currently only used for easier handling in React (e.g. as key) */
55
- id: string;
56
- reason: TDebugRefreshReason;
57
- refreshedAtoms: AtomDebugInfo<TDebugThunkInfo>[];
58
- skippedRefresh: boolean;
59
- durationMs: number;
60
- /** Note we're using a regular `Date.now()` timestamp here as it's faster to produce and we don't need the fine accuracy */
61
- completedTimestamp: number;
62
- graphSnapshot: ReactiveGraphSnapshot;
63
- };
64
- export type RefreshReasonWithGenericReasons<T extends Taggable> = T | {
65
- _tag: 'makeThunk';
66
- label?: string;
67
- } | {
68
- _tag: 'makeEffect';
69
- label?: string;
70
- } | {
71
- _tag: 'unknown';
72
- };
73
- export declare const unknownRefreshReason: () => {
74
- _tag: "unknown";
75
- };
76
- export type SerializedAtom = Readonly<PrettifyFlat<Pick<Atom<unknown>, '_tag' | 'height' | 'id' | 'label' | 'meta' | 'result'> & {
77
- sub: string[];
78
- super: string[];
79
- }>>;
80
- export type SerializedEffect = Readonly<PrettifyFlat<Pick<Effect, '_tag' | 'id'>>>;
81
- type ReactiveGraphSnapshot = {
82
- readonly atoms: SerializedAtom[];
83
- readonly effects: SerializedEffect[];
84
- /** IDs of atoms and effects that are dirty */
85
- readonly dirtyNodes: string[];
86
- };
87
- export declare class ReactiveGraph<TDebugRefreshReason extends Taggable, TDebugThunkInfo extends Taggable> {
88
- private atoms;
89
- private effects;
90
- private otelTracer;
91
- readonly dirtyNodes: Set<Atom<any> | Effect>;
92
- effectsWrapper: (runEffects: () => void) => void;
93
- debugRefreshInfos: BoundArray<RefreshDebugInfo<RefreshReasonWithGenericReasons<TDebugRefreshReason>, TDebugThunkInfo>>;
94
- constructor(options: ReactiveGraphOptions);
95
- makeRef<T>(val: T, options?: {
96
- label?: string;
97
- meta?: unknown;
98
- equal?: (a: T, b: T) => boolean;
99
- }): Ref<T>;
100
- makeThunk<T>(getResult: (get: GetAtom, addDebugInfo: (debugInfo: TDebugThunkInfo) => void) => T, options: {
101
- label?: string;
102
- meta?: any;
103
- equal?: (a: T, b: T) => boolean;
104
- /** Debug info for initializing the thunk (i.e. running it the first time) */
105
- debugRefreshReason?: RefreshReasonWithGenericReasons<TDebugRefreshReason>;
106
- } | undefined, parentSpanContext: otel.Context): Thunk<T>;
107
- destroy(node: Atom<any> | Effect): void;
108
- makeEffect(doEffect: (get: GetAtom) => void, options: {
109
- label?: string;
110
- } | undefined, parentSpanContext: otel.Context): Effect;
111
- setRef<T>(ref: Ref<T>, val: T, options: {
112
- otelHint?: string;
113
- skipRefresh?: boolean;
114
- debugRefreshReason?: TDebugRefreshReason;
115
- } | undefined, parentSpanContext: otel.Context): void;
116
- setRefs<T>(refs: [Ref<T>, T][], options: {
117
- otelHint?: string;
118
- skipRefresh?: boolean;
119
- debugRefreshReason?: TDebugRefreshReason;
120
- } | undefined, parentSpanContext: otel.Context): void;
121
- get<T>(atom: Atom<T>, context: Atom<any> | Effect): T;
122
- /**
123
- * Update the graph to be consistent with the current values of the root atoms.
124
- * Generally we run this after a ref is updated.
125
- * At the end of the refresh, we run any effects that were scheduled.
126
- *
127
- * @param roots Root atoms to start the refresh from
128
- */
129
- refresh(options: {
130
- otelHint?: string;
131
- debugRefreshReason?: RefreshReasonWithGenericReasons<TDebugRefreshReason>;
132
- } | undefined, parentSpanContext: otel.Context): void;
133
- label(atom: Atom<any> | Effect): string;
134
- addEdge(superComp: Atom<any> | Effect, subComp: Atom<any>): void;
135
- removeEdge(superComp: Atom<any> | Effect, subComp: Atom<any>): void;
136
- updateAtomHeight(atom: Atom<any> | Effect): void;
137
- private getSnapshot;
138
- }
139
- export {};
140
- //# sourceMappingURL=reactive.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"reactive.d.ts","sourceRoot":"","sources":["../src/reactive.ts"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAEpD,OAAO,KAAK,KAAK,IAAI,MAAM,oBAAoB,CAAA;AAG/C,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAErD,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAA;AAE7C,MAAM,MAAM,GAAG,CAAC,CAAC,IAAI;IACnB,IAAI,EAAE,KAAK,CAAA;IACX,EAAE,EAAE,MAAM,CAAA;IACV,MAAM,EAAE,CAAC,CAAA;IACT,MAAM,EAAE,CAAC,CAAA;IACT,SAAS,EAAE,MAAM,CAAC,CAAA;IAClB,GAAG,EAAE,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAA;IACnB,KAAK,EAAE,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,CAAA;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,gEAAgE;IAChE,IAAI,CAAC,EAAE,GAAG,CAAA;IACV,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,OAAO,CAAA;CAC/B,CAAA;AAED,KAAK,SAAS,CAAC,CAAC,IAAI;IAClB,IAAI,EAAE,OAAO,CAAA;IACb,EAAE,EAAE,MAAM,CAAA;IACV,MAAM,EAAE,MAAM,CAAA;IACd,SAAS,EAAE,CAAC,GAAG,E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