@livestore/livestore 0.0.24 → 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.
Files changed (106) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/QueryCache.d.ts +2 -2
  3. package/dist/QueryCache.d.ts.map +1 -1
  4. package/dist/QueryCache.js.map +1 -1
  5. package/dist/__tests__/react/fixture.d.ts +2 -2
  6. package/dist/__tests__/react/fixture.d.ts.map +1 -1
  7. package/dist/__tests__/react/fixture.js +2 -2
  8. package/dist/__tests__/react/fixture.js.map +1 -1
  9. package/dist/__tests__/react/useComponentState.test.js +78 -10
  10. package/dist/__tests__/react/useComponentState.test.js.map +1 -1
  11. package/dist/__tests__/react/useQuery.test.js +35 -10
  12. package/dist/__tests__/react/useQuery.test.js.map +1 -1
  13. package/dist/__tests__/reactive.test.js +51 -0
  14. package/dist/__tests__/reactive.test.js.map +1 -1
  15. package/dist/__tests__/reactiveQueries/sql.test.js +2 -9
  16. package/dist/__tests__/reactiveQueries/sql.test.js.map +1 -1
  17. package/dist/effect/LiveStore.js +1 -1
  18. package/dist/effect/LiveStore.js.map +1 -1
  19. package/dist/inMemoryDatabase.d.ts +3 -3
  20. package/dist/inMemoryDatabase.d.ts.map +1 -1
  21. package/dist/inMemoryDatabase.js +3 -3
  22. package/dist/inMemoryDatabase.js.map +1 -1
  23. package/dist/index.d.ts +4 -4
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +3 -3
  26. package/dist/index.js.map +1 -1
  27. package/dist/migrations.js.map +1 -1
  28. package/dist/react/useComponentState.d.ts +3 -3
  29. package/dist/react/useComponentState.d.ts.map +1 -1
  30. package/dist/react/useComponentState.js +43 -57
  31. package/dist/react/useComponentState.js.map +1 -1
  32. package/dist/react/useQuery.js +2 -2
  33. package/dist/react/useQuery.js.map +1 -1
  34. package/dist/react/utils/stack-info.d.ts.map +1 -1
  35. package/dist/react/utils/stack-info.js +0 -1
  36. package/dist/react/utils/stack-info.js.map +1 -1
  37. package/dist/reactive.d.ts +37 -28
  38. package/dist/reactive.d.ts.map +1 -1
  39. package/dist/reactive.js +44 -19
  40. package/dist/reactive.js.map +1 -1
  41. package/dist/reactiveQueries/base-class.d.ts +4 -4
  42. package/dist/reactiveQueries/base-class.d.ts.map +1 -1
  43. package/dist/reactiveQueries/base-class.js +2 -1
  44. package/dist/reactiveQueries/base-class.js.map +1 -1
  45. package/dist/reactiveQueries/js.d.ts +6 -1
  46. package/dist/reactiveQueries/js.d.ts.map +1 -1
  47. package/dist/reactiveQueries/js.js.map +1 -1
  48. package/dist/reactiveQueries/sql.d.ts +2 -2
  49. package/dist/reactiveQueries/sql.d.ts.map +1 -1
  50. package/dist/reactiveQueries/sql.js +1 -1
  51. package/dist/reactiveQueries/sql.js.map +1 -1
  52. package/dist/store.d.ts +2 -11
  53. package/dist/store.d.ts.map +1 -1
  54. package/dist/store.js +6 -11
  55. package/dist/store.js.map +1 -1
  56. package/package.json +16 -13
  57. package/src/QueryCache.ts +2 -2
  58. package/src/__tests__/react/fixture.tsx +3 -3
  59. package/src/__tests__/react/useComponentState.test.tsx +116 -10
  60. package/src/__tests__/react/useQuery.test.tsx +54 -12
  61. package/src/__tests__/reactive.test.ts +71 -0
  62. package/src/__tests__/reactiveQueries/sql.test.ts +2 -9
  63. package/src/effect/LiveStore.ts +1 -1
  64. package/src/inMemoryDatabase.ts +8 -8
  65. package/src/index.ts +4 -12
  66. package/src/migrations.ts +2 -2
  67. package/src/react/useComponentState.ts +53 -72
  68. package/src/react/useQuery.ts +2 -2
  69. package/src/react/utils/stack-info.ts +0 -1
  70. package/src/reactive.ts +80 -64
  71. package/src/reactiveQueries/base-class.ts +6 -8
  72. package/src/reactiveQueries/js.ts +6 -1
  73. package/src/reactiveQueries/sql.ts +3 -3
  74. package/src/store.ts +12 -24
  75. package/dist/__tests__/react/useLQuery.test.d.ts +0 -2
  76. package/dist/__tests__/react/useLQuery.test.d.ts.map +0 -1
  77. package/dist/__tests__/react/useLQuery.test.js +0 -38
  78. package/dist/__tests__/react/useLQuery.test.js.map +0 -1
  79. package/dist/__tests__/react/useLiveStoreComponent.test.d.ts +0 -2
  80. package/dist/__tests__/react/useLiveStoreComponent.test.d.ts.map +0 -1
  81. package/dist/__tests__/react/useLiveStoreComponent.test.js +0 -73
  82. package/dist/__tests__/react/useLiveStoreComponent.test.js.map +0 -1
  83. package/dist/__tests__/react/utils/extractStackInfoFromStackTrace.test.d.ts +0 -2
  84. package/dist/__tests__/react/utils/extractStackInfoFromStackTrace.test.d.ts.map +0 -1
  85. package/dist/__tests__/react/utils/extractStackInfoFromStackTrace.test.js +0 -38
  86. package/dist/__tests__/react/utils/extractStackInfoFromStackTrace.test.js.map +0 -1
  87. package/dist/react/useGlobalQuery.d.ts +0 -3
  88. package/dist/react/useGlobalQuery.d.ts.map +0 -1
  89. package/dist/react/useGlobalQuery.js +0 -26
  90. package/dist/react/useGlobalQuery.js.map +0 -1
  91. package/dist/react/useGraphQL.d.ts +0 -13
  92. package/dist/react/useGraphQL.d.ts.map +0 -1
  93. package/dist/react/useGraphQL.js +0 -87
  94. package/dist/react/useGraphQL.js.map +0 -1
  95. package/dist/react/useLiveStoreComponent.d.ts +0 -75
  96. package/dist/react/useLiveStoreComponent.d.ts.map +0 -1
  97. package/dist/react/useLiveStoreComponent.js +0 -361
  98. package/dist/react/useLiveStoreComponent.js.map +0 -1
  99. package/dist/react/utils/extractNamesFromStackTrace.d.ts +0 -3
  100. package/dist/react/utils/extractNamesFromStackTrace.d.ts.map +0 -1
  101. package/dist/react/utils/extractNamesFromStackTrace.js +0 -40
  102. package/dist/react/utils/extractNamesFromStackTrace.js.map +0 -1
  103. package/dist/react/utils/extractStackInfoFromStackTrace.d.ts +0 -7
  104. package/dist/react/utils/extractStackInfoFromStackTrace.d.ts.map +0 -1
  105. package/dist/react/utils/extractStackInfoFromStackTrace.js +0 -40
  106. package/dist/react/utils/extractStackInfoFromStackTrace.js.map +0 -1
package/src/store.ts CHANGED
@@ -12,7 +12,7 @@ import { InMemoryDatabase } from './inMemoryDatabase.js'
12
12
  import { migrateDb } from './migrations.js'
13
13
  import { getDurationMsFromSpan } from './otel.js'
14
14
  import type { StackInfo } from './react/utils/stack-info.js'
15
- import type { ReactiveGraph, Ref } from './reactive.js'
15
+ import type { DebugRefreshReasonBase, ReactiveGraph, Ref } from './reactive.js'
16
16
  import type { ILiveStoreQuery } from './reactiveQueries/base-class.js'
17
17
  import { type DbContext, dbGraph } from './reactiveQueries/graph.js'
18
18
  import type { LiveStoreGraphQLQuery } from './reactiveQueries/graphql.js'
@@ -38,10 +38,10 @@ export type BaseGraphQLContext = {
38
38
  export type QueryResult<TQuery> = TQuery extends LiveStoreSQLQuery<infer R>
39
39
  ? ReadonlyArray<Readonly<R>>
40
40
  : TQuery extends LiveStoreJSQuery<infer S>
41
- ? Readonly<S>
42
- : TQuery extends LiveStoreGraphQLQuery<infer Result, any, any>
43
- ? Readonly<Result>
44
- : never
41
+ ? Readonly<S>
42
+ : TQuery extends LiveStoreGraphQLQuery<infer Result, any, any>
43
+ ? Readonly<Result>
44
+ : never
45
45
 
46
46
  export type GraphQLOptions<TContext> = {
47
47
  schema: GraphQLSchema
@@ -60,6 +60,7 @@ export type StoreOptions<TGraphQLContext extends BaseGraphQLContext> = {
60
60
  }
61
61
 
62
62
  export type RefreshReason =
63
+ | DebugRefreshReasonBase
63
64
  | {
64
65
  _tag: 'applyEvent'
65
66
  /** The event that was applied */
@@ -80,12 +81,6 @@ export type RefreshReason =
80
81
  /** The tables that were written to by the event */
81
82
  writeTables: string[]
82
83
  }
83
- /** Usually in response to some `applyEvent`/`applyEvents` with `skipRefresh: true` */
84
- | { _tag: 'manualRefresh' }
85
- | {
86
- _tag: 'makeThunk'
87
- label?: string
88
- }
89
84
  | {
90
85
  _tag: 'react'
91
86
  api: string
@@ -93,7 +88,6 @@ export type RefreshReason =
93
88
  stackInfo?: StackInfo
94
89
  }
95
90
  | { _tag: 'manual'; label?: string }
96
- | { _tag: 'unknown' }
97
91
 
98
92
  export type QueryDebugInfo = {
99
93
  _tag: 'graphql' | 'sql' | 'js' | 'unknown'
@@ -160,11 +154,11 @@ export class Store<TGraphQLContext extends BaseGraphQLContext = BaseGraphQLConte
160
154
  queriesSpanContext: otelQueriesSpanContext,
161
155
  }
162
156
 
163
- const allTableNames = [
157
+ const allTableNames = new Set([
164
158
  ...Object.keys(this.schema.tables),
165
159
  ...Object.keys(this.schema.materializedViews),
166
160
  ...Object.keys(componentStateTables),
167
- ]
161
+ ])
168
162
  for (const tableName of allTableNames) {
169
163
  this.tableRefs[tableName] = this.graph.makeRef(null, {
170
164
  equal: () => false,
@@ -383,12 +377,7 @@ export class Store<TGraphQLContext extends BaseGraphQLContext = BaseGraphQLConte
383
377
  writeTables: [...writeTables],
384
378
  }
385
379
  // Update all table refs together in a batch, to only trigger one reactive update
386
- this.graph.setRefs(tablesToUpdate, { debugRefreshReason, otelContext })
387
-
388
- if (skipRefresh === false) {
389
- // TODO update the graph
390
- // this.graph.refresh({ debugRefreshReason, otelHint: 'applyEvents' }, otelContext)
391
- }
380
+ this.graph.setRefs(tablesToUpdate, { debugRefreshReason, otelContext, skipRefresh })
392
381
  } catch (e: any) {
393
382
  span.setStatus({ code: otel.SpanStatusCode.ERROR, message: e.toString() })
394
383
  } finally {
@@ -411,9 +400,8 @@ export class Store<TGraphQLContext extends BaseGraphQLContext = BaseGraphQLConte
411
400
  { attributes: { 'livestore.manualRefreshLabel': label } },
412
401
  this.otel.applyEventsSpanContext,
413
402
  (span) => {
414
- // const otelContext = otel.trace.setSpan(otel.context.active(), span)
415
- // TODO update the graph
416
- // this.graph.refresh({ otelHint: 'manualRefresh', debugRefreshReason: { _tag: 'manualRefresh' } }, otelContext)
403
+ const otelContext = otel.trace.setSpan(otel.context.active(), span)
404
+ this.graph.runDeferredEffects({ otelContext })
417
405
  span.end()
418
406
  },
419
407
  )
@@ -465,7 +453,7 @@ export class Store<TGraphQLContext extends BaseGraphQLContext = BaseGraphQLConte
465
453
  writeTables,
466
454
  argsAlreadyBound: false,
467
455
  }),
468
- prepareBindValues: ({ bindValues }) => bindValues,
456
+ prepareBindValues: ({ bindValues }) => bindValues ?? {},
469
457
  },
470
458
  }
471
459
 
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=useLQuery.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useLQuery.test.d.ts","sourceRoot":"","sources":["../../../src/__tests__/react/useLQuery.test.tsx"],"names":[],"mappings":""}
@@ -1,38 +0,0 @@
1
- import { makeNoopTracer } from '@livestore/utils';
2
- import * as otel from '@opentelemetry/api';
3
- import { renderHook } from '@testing-library/react';
4
- import { describe, it } from 'vitest';
5
- import * as LiveStoreReact from '../../react/index.js';
6
- import { LiveStoreSQLQuery } from '../../reactiveQueries/sql.js';
7
- import { makeTodoMvc } from './fixture.js';
8
- describe.only('useQuery', () => {
9
- it('todo', async () => {
10
- let renderCount = 0;
11
- const { wrapper, AppSchema, store } = await makeTodoMvc();
12
- const { result, rerender } = renderHook((userId) => {
13
- renderCount++;
14
- const query = new LiveStoreSQLQuery({
15
- label: 'todo',
16
- otelContext: otel.context.active(),
17
- otelTracer: makeNoopTracer(),
18
- payload: {
19
- genQueryString: `select * from todos`,
20
- queriedTables: ['todos'],
21
- },
22
- });
23
- return LiveStoreReact.useQuery(query);
24
- }, { wrapper, initialProps: 'u1' });
25
- console.log(result.current);
26
- // expect(result.current.state.id).toBe('u1')
27
- // expect(result.current.state.username).toBe('')
28
- // expect(renderCount).toBe(1)
29
- // act(() => {
30
- // void store.execute(sql`INSERT INTO components__UserInfo (id, username) VALUES ('u2', 'username_u2');`)
31
- // })
32
- // rerender('u2')
33
- // expect(result.current.state.id).toBe('u2')
34
- // expect(result.current.state.username).toBe('username_u2')
35
- // expect(renderCount).toBe(2)
36
- });
37
- });
38
- //# sourceMappingURL=useLQuery.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useLQuery.test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AAiD;QACjD,8BAA8B;QAE9B,cAAc;QACd,2GAA2G;QAC3G,KAAK;QAEL,iBAAiB;QAEjB,6CAA6C;QAC7C,4DAA4D;QAC5D,8BAA8B;IAChC,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=useLiveStoreComponent.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useLiveStoreComponent.test.d.ts","sourceRoot":"","sources":["../../../src/__tests__/react/useLiveStoreComponent.test.tsx"],"names":[],"mappings":""}
@@ -1,73 +0,0 @@
1
- import { act, renderHook } from '@testing-library/react';
2
- import { describe, expect, it } from 'vitest';
3
- import { sql } from '../../index.js';
4
- import * as LiveStoreReact from '../../react/index.js';
5
- import { makeTodoMvc } from './fixture.js';
6
- describe('useLiveStoreComponent', () => {
7
- it('should update the data based on component key', async () => {
8
- let renderCount = 0;
9
- const { wrapper, AppSchema, store } = await makeTodoMvc();
10
- const { result, rerender } = renderHook((userId) => {
11
- renderCount++;
12
- return LiveStoreReact.useLiveStoreComponent({
13
- stateSchema: AppSchema,
14
- componentKey: { name: 'UserInfo', id: userId },
15
- queries: () => ({}),
16
- });
17
- }, { wrapper, initialProps: 'u1' });
18
- expect(result.current.state.id).toBe('u1');
19
- expect(result.current.state.username).toBe('');
20
- expect(renderCount).toBe(1);
21
- act(() => {
22
- void store.execute(sql `INSERT INTO components__UserInfo (id, username) VALUES ('u2', 'username_u2');`);
23
- });
24
- rerender('u2');
25
- expect(result.current.state.id).toBe('u2');
26
- expect(result.current.state.username).toBe('username_u2');
27
- expect(renderCount).toBe(2);
28
- });
29
- it('should update the data reactively - via setState', async () => {
30
- let renderCount = 0;
31
- const { wrapper, AppSchema } = await makeTodoMvc();
32
- const { result } = renderHook((userId) => {
33
- renderCount++;
34
- return LiveStoreReact.useLiveStoreComponent({
35
- stateSchema: AppSchema,
36
- componentKey: { name: 'UserInfo', id: userId },
37
- queries: () => ({}),
38
- });
39
- }, { wrapper, initialProps: 'u1' });
40
- expect(result.current.state.id).toBe('u1');
41
- expect(result.current.state.username).toBe('');
42
- expect(renderCount).toBe(1);
43
- act(() => result.current.setState.username('username_u1_hello'));
44
- expect(result.current.state.id).toBe('u1');
45
- expect(result.current.state.username).toBe('username_u1_hello');
46
- expect(renderCount).toBe(2);
47
- });
48
- it('should update the data reactively - via raw store update', async () => {
49
- let renderCount = 0;
50
- const { wrapper, AppSchema, store } = await makeTodoMvc();
51
- const { result } = renderHook((userId) => {
52
- renderCount++;
53
- return LiveStoreReact.useLiveStoreComponent({
54
- stateSchema: AppSchema,
55
- componentKey: { name: 'UserInfo', id: userId },
56
- queries: () => ({}),
57
- });
58
- }, { wrapper, initialProps: 'u1' });
59
- expect(result.current.state.id).toBe('u1');
60
- expect(result.current.state.username).toBe('');
61
- expect(renderCount).toBe(1);
62
- act(() => result.current.setState.username('username_u1_hello'));
63
- act(() => {
64
- void store.execute(sql `UPDATE components__UserInfo SET username = 'username_u1_hello' WHERE id = 'u1';`);
65
- });
66
- expect(result.current.state.id).toBe('u1');
67
- expect(result.current.state.username).toBe('username_u1_hello');
68
- expect(renderCount).toBe(2);
69
- });
70
- });
71
- // TODO add a test case that tests the `queries` callback
72
- // TODO add a test case that tests the `subscribe` in the `queries` callback
73
- //# sourceMappingURL=useLiveStoreComponent.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useLiveStoreComponent.test.js","sourceRoot":"","sources":["../../../src/__tests__/react/useLiveStoreComponent.test.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAE7C,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAA;AACpC,OAAO,KAAK,cAAc,MAAM,sBAAsB,CAAA;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,cAA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AAK,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAC1C,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAA;QAC/D,MAAM,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IAC7B,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA;AAEF,yDAAyD;AACzD,4EAA4E"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=extractStackInfoFromStackTrace.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"extractStackInfoFromStackTrace.test.d.ts","sourceRoot":"","sources":["../../../../src/__tests__/react/utils/extractStackInfoFromStackTrace.test.ts"],"names":[],"mappings":""}
@@ -1,38 +0,0 @@
1
- import { expect, it } from 'vitest';
2
- import { extractStackInfoFromStackTrace } from '../../../react/utils/extractStackInfoFromStackTrace.js';
3
- it('RouteLink stacktrace', async () => {
4
- const stackTrace = `\
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
- expect(extractStackInfoFromStackTrace(stackTrace)).toMatchInlineSnapshot(`
18
- [
19
- {
20
- "filePath": "https://localhost:8081/src/components/Link.tsx?t=1699550216884:36:7",
21
- "name": "RouteLink",
22
- },
23
- {
24
- "filePath": "https://localhost:8081/src/db/AppState.ts?t=1699550216884:74:22",
25
- "name": "useRoute",
26
- },
27
- {
28
- "filePath": "https://localhost:8081/src/db/AppState.ts?t=1699550216884:17:34",
29
- "name": "useAppState",
30
- },
31
- {
32
- "filePath": "https://localhost:8081/@fs/Users/schickling/Code/overtone/submodules/livestore/packages/@livestore/livestore/dist/react/useQuery.js?t=1699550216884:13:33",
33
- "name": "useQuery",
34
- },
35
- ]
36
- `);
37
- });
38
- //# sourceMappingURL=extractStackInfoFromStackTrace.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"extractStackInfoFromStackTrace.test.js","sourceRoot":"","sources":["../../../../src/__tests__/react/utils/extractStackInfoFromStackTrace.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAEnC,OAAO,EAAE,8BAA8B,EAAE,MAAM,wDAAwD,CAAA;AAEvG,EAAE,CAAC,sBAAsB,EAAE,KAAK,IAAI,EAAE;IACpC,MAAM,UAAU,GAAG;;;;;;;;;;;;CAYpB,CAAA;IAEC,MAAM,CAAC,8BAA8B,CAAC,UAAU,CAAC,CAAC,CAAC,qBAAqB,CAAC;;;;;;;;;;;;;;;;;;;GAmBxE,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -1,3 +0,0 @@
1
- import type { LiveStoreQuery, QueryResult, Store } from '../store.js';
2
- export declare const useGlobalQuery: <Q extends LiveStoreQuery>(queryDef: (store: Store<any>) => Q) => QueryResult<Q>;
3
- //# sourceMappingURL=useGlobalQuery.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useGlobalQuery.d.ts","sourceRoot":"","sources":["../../src/react/useGlobalQuery.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAGrE,eAAO,MAAM,cAAc,+CAAgD,MAAM,GAAG,CAAC,yBAiCpF,CAAA"}
@@ -1,26 +0,0 @@
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
@@ -1 +0,0 @@
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,CAA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';
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
@@ -1 +0,0 @@
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"}
@@ -1,87 +0,0 @@
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
@@ -1 +0,0 @@
1
- {"version":3,"file":"useGraphQL.js","sourceRoot":"","sources":["../../src/react/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D,MAAM,mBAAmB,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,cAAc,CAAC,GAAG,EAAE,EAAE,CAAC,cAAc,CAAC,CAAC,CAAA;IAEvF,MAAM,CAAC,eAAe,EAAE,gBAAgB,CAAC,GAAG,4BAA4B,CAAU,mBAAmB,CAAC,CAAA;IAEtG,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,MAAM,WAAW,GAAG,KAAK,CAAC,SAAS,CACjC,cAAc,EACd,CAAC,OAAO,EAAE,EAAE;YACV,IAAI,OAAO,CAAC,OAAO,EAAE,eAAe,CAAC,OAAO,CAAC,KAAK,KAAK,EAAE;gBACvD,gBAAgB,CAAC,OAAO,CAAC,CAAA;aAC1B;QACH,CAAC,EACD,SAAS,EACT,EAAE,KAAK,EAAE,8BAA8B,cAAc,CAAC,KAAK,EAAE,EAAE,CAChE,CAAA;QAED,OAAO,GAAG,EAAE;YACV,WAAW,EAAE,CAAA;QACf,CAAC,CAAA;QACD,oFAAoF;QACpF,mCAAmC;QACnC,uDAAuD;IACzD,CAAC,EAAE;QACD,cAAc;QACd,oBAAoB;QACpB,KAAK;KACN,CAAC,CAAA;IAEF,oFAAoF;IACpF,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,cAAc,CAAC,OAAO,EAAE,EAAE,CAAC,cAAc,CAAC,CAAC,CAAA;IAEvE,OAAO,eAAe,CAAC,OAAO,CAAA;AAChC,CAAC,CAAA"}
@@ -1,75 +0,0 @@
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
@@ -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,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;AAC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