@livestore/livestore 0.3.0-dev.11 → 0.3.0-dev.5

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 (122) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/SynchronousDatabaseWrapper.d.ts +5 -14
  3. package/dist/SynchronousDatabaseWrapper.d.ts.map +1 -1
  4. package/dist/SynchronousDatabaseWrapper.js +4 -24
  5. package/dist/SynchronousDatabaseWrapper.js.map +1 -1
  6. package/dist/effect/LiveStore.d.ts +8 -12
  7. package/dist/effect/LiveStore.d.ts.map +1 -1
  8. package/dist/effect/LiveStore.js +3 -13
  9. package/dist/effect/LiveStore.js.map +1 -1
  10. package/dist/index.d.ts +7 -6
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +4 -4
  13. package/dist/index.js.map +1 -1
  14. package/dist/live-queries/base-class.d.ts +21 -64
  15. package/dist/live-queries/base-class.d.ts.map +1 -1
  16. package/dist/live-queries/base-class.js +13 -56
  17. package/dist/live-queries/base-class.js.map +1 -1
  18. package/dist/live-queries/computed.d.ts +7 -7
  19. package/dist/live-queries/computed.d.ts.map +1 -1
  20. package/dist/live-queries/computed.js +11 -35
  21. package/dist/live-queries/computed.js.map +1 -1
  22. package/dist/live-queries/db.d.ts +15 -12
  23. package/dist/live-queries/db.d.ts.map +1 -1
  24. package/dist/live-queries/db.js +25 -44
  25. package/dist/live-queries/db.js.map +1 -1
  26. package/dist/live-queries/db.test.js +14 -16
  27. package/dist/live-queries/db.test.js.map +1 -1
  28. package/dist/live-queries/graphql.d.ts +8 -8
  29. package/dist/live-queries/graphql.d.ts.map +1 -1
  30. package/dist/live-queries/graphql.js +9 -35
  31. package/dist/live-queries/graphql.js.map +1 -1
  32. package/dist/reactive.d.ts +13 -15
  33. package/dist/reactive.d.ts.map +1 -1
  34. package/dist/reactive.js +9 -15
  35. package/dist/reactive.js.map +1 -1
  36. package/dist/row-query-utils.d.ts +4 -4
  37. package/dist/row-query-utils.d.ts.map +1 -1
  38. package/dist/row-query-utils.js +10 -14
  39. package/dist/row-query-utils.js.map +1 -1
  40. package/dist/store/create-store.d.ts +4 -3
  41. package/dist/store/create-store.d.ts.map +1 -1
  42. package/dist/store/create-store.js +7 -7
  43. package/dist/store/create-store.js.map +1 -1
  44. package/dist/store/devtools.d.ts +2 -2
  45. package/dist/store/devtools.d.ts.map +1 -1
  46. package/dist/store/devtools.js +15 -15
  47. package/dist/store/devtools.js.map +1 -1
  48. package/dist/store/store-types.d.ts +5 -10
  49. package/dist/store/store-types.d.ts.map +1 -1
  50. package/dist/store/store-types.js.map +1 -1
  51. package/dist/store/store.d.ts +16 -34
  52. package/dist/store/store.d.ts.map +1 -1
  53. package/dist/store/store.js +77 -129
  54. package/dist/store/store.js.map +1 -1
  55. package/dist/utils/stack-info.d.ts.map +1 -1
  56. package/dist/utils/stack-info.js +1 -6
  57. package/dist/utils/stack-info.js.map +1 -1
  58. package/dist/utils/stack-info.test.js +1 -54
  59. package/dist/utils/stack-info.test.js.map +1 -1
  60. package/dist/utils/tests/fixture.d.ts +6 -2
  61. package/dist/utils/tests/fixture.d.ts.map +1 -1
  62. package/dist/utils/tests/fixture.js +5 -3
  63. package/dist/utils/tests/fixture.js.map +1 -1
  64. package/dist/utils/tests/mod.d.ts +0 -1
  65. package/dist/utils/tests/mod.d.ts.map +1 -1
  66. package/dist/utils/tests/mod.js +0 -1
  67. package/dist/utils/tests/mod.js.map +1 -1
  68. package/package.json +12 -12
  69. package/src/{SqliteDbWrapper.ts → SynchronousDatabaseWrapper.ts} +11 -41
  70. package/src/effect/LiveStore.ts +15 -26
  71. package/src/global-state.ts +20 -0
  72. package/src/index.ts +7 -14
  73. package/src/live-queries/__snapshots__/{db-query.test.ts.snap → db.test.ts.snap} +42 -196
  74. package/src/live-queries/base-class.ts +40 -160
  75. package/src/live-queries/computed.ts +19 -45
  76. package/src/live-queries/{db-query.test.ts → db.test.ts} +11 -21
  77. package/src/live-queries/{db-query.ts → db.ts} +39 -97
  78. package/src/live-queries/graphql.ts +21 -47
  79. package/src/reactive.ts +27 -52
  80. package/src/row-query-utils.ts +18 -29
  81. package/src/store/create-store.ts +23 -20
  82. package/src/store/devtools.ts +17 -17
  83. package/src/store/store-types.ts +5 -7
  84. package/src/store/store.ts +122 -231
  85. package/src/utils/stack-info.test.ts +1 -58
  86. package/src/utils/stack-info.ts +1 -6
  87. package/src/utils/tests/fixture.ts +7 -2
  88. package/src/utils/tests/mod.ts +0 -1
  89. package/dist/SqliteDbWrapper.d.ts +0 -54
  90. package/dist/SqliteDbWrapper.d.ts.map +0 -1
  91. package/dist/SqliteDbWrapper.js +0 -212
  92. package/dist/SqliteDbWrapper.js.map +0 -1
  93. package/dist/__tests__/fixture.d.ts +0 -252
  94. package/dist/__tests__/fixture.d.ts.map +0 -1
  95. package/dist/__tests__/fixture.js +0 -18
  96. package/dist/__tests__/fixture.js.map +0 -1
  97. package/dist/live-queries/db-query.d.ts +0 -67
  98. package/dist/live-queries/db-query.d.ts.map +0 -1
  99. package/dist/live-queries/db-query.js +0 -244
  100. package/dist/live-queries/db-query.js.map +0 -1
  101. package/dist/live-queries/db-query.test.d.ts +0 -2
  102. package/dist/live-queries/db-query.test.d.ts.map +0 -1
  103. package/dist/live-queries/db-query.test.js +0 -123
  104. package/dist/live-queries/db-query.test.js.map +0 -1
  105. package/dist/live-queries/make-ref.d.ts +0 -20
  106. package/dist/live-queries/make-ref.d.ts.map +0 -1
  107. package/dist/live-queries/make-ref.js +0 -33
  108. package/dist/live-queries/make-ref.js.map +0 -1
  109. package/dist/store/store.test.d.ts +0 -2
  110. package/dist/store/store.test.d.ts.map +0 -1
  111. package/dist/store/store.test.js +0 -27
  112. package/dist/store/store.test.js.map +0 -1
  113. package/dist/utils/expo.d.ts +0 -2
  114. package/dist/utils/expo.d.ts.map +0 -1
  115. package/dist/utils/expo.js +0 -8
  116. package/dist/utils/expo.js.map +0 -1
  117. package/dist/utils/function-string.d.ts +0 -7
  118. package/dist/utils/function-string.d.ts.map +0 -1
  119. package/dist/utils/function-string.js +0 -9
  120. package/dist/utils/function-string.js.map +0 -1
  121. package/src/live-queries/make-ref.ts +0 -47
  122. package/src/utils/function-string.ts +0 -12
@@ -1,119 +1,59 @@
1
1
  import type { QueryInfo } from '@livestore/common'
2
- import { isNotNil } from '@livestore/utils'
3
- import { GlobalValue } from '@livestore/utils/effect'
4
2
  import type * as otel from '@opentelemetry/api'
5
3
 
6
- import * as RG from '../reactive.js'
4
+ import { type Atom, type GetAtom, ReactiveGraph, throwContextNotSetError, type Thunk } from '../reactive.js'
7
5
  import type { Store } from '../store/store.js'
8
6
  import type { QueryDebugInfo, RefreshReason } from '../store/store-types.js'
9
7
  import type { StackInfo } from '../utils/stack-info.js'
10
8
 
11
- export type ReactivityGraph = RG.ReactiveGraph<RefreshReason, QueryDebugInfo, ReactivityGraphContext>
9
+ export type ReactivityGraph = ReactiveGraph<RefreshReason, QueryDebugInfo, QueryContext>
12
10
 
13
11
  export const makeReactivityGraph = (): ReactivityGraph =>
14
- new RG.ReactiveGraph<RefreshReason, QueryDebugInfo, ReactivityGraphContext>()
12
+ new ReactiveGraph<RefreshReason, QueryDebugInfo, QueryContext>()
15
13
 
16
- export const defCounterRef = GlobalValue.globalValue('livestore-def-counter', () => ({ current: 0 }))
17
-
18
- type LiveQueryDefHash = string
19
-
20
- export type LiveQueryRCMap = Map<LiveQueryDefHash, RcRef<LiveQueryAny | ILiveQueryRef<any>>>
21
-
22
- export type ReactivityGraphContext = {
14
+ export type QueryContext = {
23
15
  store: Store
24
- liveQueryRCMap: LiveQueryRCMap
25
- /** Back-reference to the reactivity graph for convenience */
26
- reactivityGraph: WeakRef<ReactivityGraph>
27
16
  otelTracer: otel.Tracer
28
17
  rootOtelContext: otel.Context
29
18
  effectsWrapper: (run: () => void) => void
30
19
  }
31
20
 
32
- export type GetResult<TQuery extends LiveQueryDefAny | LiveQueryAny> =
33
- TQuery extends LiveQuery<infer TResult, infer _1>
34
- ? TResult
35
- : TQuery extends LiveQueryDef<infer TResult, infer _1>
36
- ? TResult
37
- : unknown
21
+ export type UnsubscribeQuery = () => void
22
+
23
+ export type GetResult<TQuery extends LiveQueryAny> =
24
+ TQuery extends LiveQuery<infer TResult, infer _1> ? TResult : unknown
38
25
 
39
26
  let queryIdCounter = 0
40
27
 
41
28
  export type LiveQueryAny = LiveQuery<any, QueryInfo>
42
- export type LiveQueryDefAny = LiveQueryDef<any, any>
43
-
44
- export interface ILiveQueryRefDef<T> {
45
- _tag: 'live-ref-def'
46
- defaultValue: T
47
- make: (ctx: ReactivityGraphContext) => RcRef<ILiveQueryRef<T>>
48
- }
49
-
50
- export interface ILiveQueryRef<T> {
51
- _tag: 'live-ref'
52
- reactivityGraph: ReactivityGraph
53
- ref: RG.Ref<T, ReactivityGraphContext, RefreshReason>
54
- set: (value: T) => void
55
- get: () => T
56
- destroy: () => void
57
- }
58
29
 
59
30
  export const TypeId = Symbol.for('LiveQuery')
60
31
  export type TypeId = typeof TypeId
61
32
 
62
- export interface RcRef<T> {
63
- rc: number
64
- value: T
65
- deref: () => void
66
- }
67
-
68
- export type DepKey = string | number | ReadonlyArray<string | number | undefined | null>
69
-
70
- export const depsToString = (deps: DepKey): string => {
71
- if (typeof deps === 'string' || typeof deps === 'number') {
72
- return deps.toString()
73
- }
74
- return deps.filter(isNotNil).join(',')
75
- }
76
-
77
- export interface LiveQueryDef<TResult, TQueryInfo extends QueryInfo = QueryInfo.None> {
78
- _tag: 'def'
79
- // TODO do we need both id and hash?
80
- /** A unique identifier for the query definition */
81
- id: number
82
- /** Creates a new LiveQuery instance bound to a specific store/reactivityGraph */
83
- make: (ctx: ReactivityGraphContext, otelContext?: otel.Context) => RcRef<LiveQuery<TResult, TQueryInfo>>
84
- label: string
85
- hash: string
86
- queryInfo: TQueryInfo
87
- }
88
-
89
- /**
90
- * A LiveQuery is stateful
91
- */
92
33
  export interface LiveQuery<TResult, TQueryInfo extends QueryInfo = QueryInfo.None> {
93
34
  id: number
94
35
  _tag: 'computed' | 'db' | 'graphql'
95
36
  [TypeId]: TypeId
96
37
 
97
- // reactivityGraph: ReactivityGraph
98
-
99
38
  /** This should only be used on a type-level and doesn't hold any value during runtime */
100
39
  '__result!': TResult
101
40
 
102
41
  /** A reactive thunk representing the query results */
103
- results$: RG.Thunk<TResult, ReactivityGraphContext, RefreshReason>
42
+ results$: Thunk<TResult, QueryContext, RefreshReason>
104
43
 
105
44
  label: string
106
45
 
107
- run: (args: { otelContext?: otel.Context; debugRefreshReason?: RefreshReason }) => TResult
46
+ run: (otelContext?: otel.Context, debugRefreshReason?: RefreshReason) => TResult
47
+
48
+ runAndDestroy: (otelContext?: otel.Context, debugRefreshReason?: RefreshReason) => TResult
108
49
 
109
- destroy: () => void
110
- isDestroyed: boolean
50
+ destroy(): void
111
51
 
112
- // subscribe(
113
- // onNewValue: (value: TResult) => void,
114
- // onUnsubsubscribe?: () => void,
115
- // options?: { label?: string; otelContext?: otel.Context },
116
- // ): () => void
52
+ subscribe(
53
+ onNewValue: (value: TResult) => void,
54
+ onUnsubsubscribe?: () => void,
55
+ options?: { label?: string; otelContext?: otel.Context },
56
+ ): () => void
117
57
 
118
58
  activeSubscriptions: Set<StackInfo>
119
59
 
@@ -135,11 +75,11 @@ export abstract class LiveStoreQueryBase<TResult, TQueryInfo extends QueryInfo>
135
75
  /** Human-readable label for the query for debugging */
136
76
  abstract label: string
137
77
 
138
- abstract results$: RG.Thunk<TResult, ReactivityGraphContext, RefreshReason>
78
+ abstract results$: Thunk<TResult, QueryContext, RefreshReason>
139
79
 
140
80
  activeSubscriptions: Set<StackInfo> = new Set()
141
81
 
142
- abstract readonly reactivityGraph: ReactivityGraph
82
+ protected abstract reactivityGraph: ReactivityGraph
143
83
 
144
84
  abstract queryInfo: TQueryInfo
145
85
 
@@ -149,93 +89,33 @@ export abstract class LiveStoreQueryBase<TResult, TQueryInfo extends QueryInfo>
149
89
 
150
90
  executionTimes: number[] = []
151
91
 
152
- // TODO double check if this is needed
153
- isDestroyed = false
154
92
  abstract destroy: () => void
155
93
 
156
- run = (args: { otelContext?: otel.Context; debugRefreshReason?: RefreshReason }): TResult => {
157
- return this.results$.computeResult(args.otelContext, args.debugRefreshReason)
158
- }
94
+ run = (otelContext?: otel.Context, debugRefreshReason?: RefreshReason): TResult =>
95
+ this.results$.computeResult(otelContext, debugRefreshReason)
159
96
 
160
- protected dependencyQueriesRef: DependencyQueriesRef = new Set()
97
+ runAndDestroy = (otelContext?: otel.Context, debugRefreshReason?: RefreshReason): TResult => {
98
+ const result = this.run(otelContext, debugRefreshReason)
99
+ this.destroy()
100
+ return result
101
+ }
161
102
 
162
- // subscribe = (
163
- // onNewValue: (value: TResult) => void,
164
- // onUnsubsubscribe?: () => void,
165
- // options?: { label?: string; otelContext?: otel.Context } | undefined,
166
- // ): (() => void) =>
167
- // this.reactivityGraph.context?.store.subscribe(this, onNewValue, onUnsubsubscribe, options) ??
168
- // RG.throwContextNotSetError(this.reactivityGraph)
103
+ subscribe = (
104
+ onNewValue: (value: TResult) => void,
105
+ onUnsubsubscribe?: () => void,
106
+ options?: { label?: string; otelContext?: otel.Context } | undefined,
107
+ ): (() => void) =>
108
+ this.reactivityGraph.context?.store.subscribe(this, onNewValue, onUnsubsubscribe, options) ??
109
+ throwContextNotSetError(this.reactivityGraph)
169
110
  }
170
111
 
171
- export type GetAtomResult = <T>(
172
- atom:
173
- | RG.Atom<T, any, RefreshReason>
174
- | LiveQueryDef<T, any>
175
- | LiveQuery<T, any>
176
- | ILiveQueryRef<T>
177
- | ILiveQueryRefDef<T>,
178
- otelContext?: otel.Context | undefined,
179
- debugRefreshReason?: RefreshReason | undefined,
180
- ) => T
181
-
182
- export type DependencyQueriesRef = Set<RcRef<LiveQueryAny | ILiveQueryRef<any>>>
183
-
184
- export const makeGetAtomResult = (
185
- get: RG.GetAtom,
186
- ctx: ReactivityGraphContext,
187
- otelContext: otel.Context,
188
- dependencyQueriesRef: DependencyQueriesRef,
189
- ) => {
190
- // NOTE we're using the `otelContext` from `makeGetAtomResult` here, not the `otelContext` from `getAtom`
191
- const getAtom: GetAtomResult = (atom, _otelContext, debugRefreshReason) => {
192
- // ReactivityGraph atoms case
193
- if (atom._tag === 'thunk' || atom._tag === 'ref') return get(atom, otelContext, debugRefreshReason)
194
-
195
- // LiveQueryDef case
196
- if (atom._tag === 'def' || atom._tag === 'live-ref-def') {
197
- const query = atom.make(ctx)
198
- dependencyQueriesRef.add(query)
199
- // TODO deref the query on destroy
200
- return getAtom(query.value, _otelContext, debugRefreshReason)
201
- }
202
-
203
- // LiveQueryRef case
204
- if (atom._tag === 'live-ref') return get(atom.ref, otelContext, debugRefreshReason)
205
-
206
- // LiveQuery case
207
- return get(atom.results$, otelContext, debugRefreshReason)
112
+ export type GetAtomResult = <T>(atom: Atom<T, any, RefreshReason> | LiveQuery<T, any>) => T
113
+
114
+ export const makeGetAtomResult = (get: GetAtom, otelContext: otel.Context) => {
115
+ const getAtom: GetAtomResult = (atom) => {
116
+ if (atom._tag === 'thunk' || atom._tag === 'ref') return get(atom, otelContext)
117
+ return get(atom.results$, otelContext)
208
118
  }
209
119
 
210
120
  return getAtom
211
121
  }
212
-
213
- export const withRCMap = <T extends LiveQueryAny | ILiveQueryRef<any>>(
214
- id: string,
215
- make: (ctx: ReactivityGraphContext, otelContext?: otel.Context) => T,
216
- ): ((ctx: ReactivityGraphContext, otelContext?: otel.Context) => RcRef<T>) => {
217
- return (ctx, otelContext) => {
218
- let item = ctx.liveQueryRCMap.get(id)
219
- if (item) {
220
- item.rc++
221
- return item as RcRef<T>
222
- }
223
-
224
- const query$ = make(ctx, otelContext)
225
-
226
- item = {
227
- rc: 1,
228
- value: query$,
229
- deref: () => {
230
- item!.rc--
231
- if (item!.rc === 0) {
232
- item!.value.destroy()
233
- }
234
- ctx.liveQueryRCMap.delete(id)
235
- },
236
- }
237
- ctx.liveQueryRCMap.set(id, item)
238
-
239
- return item as RcRef<T>
240
- }
241
- }
@@ -1,48 +1,27 @@
1
1
  import type { QueryInfo } from '@livestore/common'
2
2
  import * as otel from '@opentelemetry/api'
3
3
 
4
+ import { globalReactivityGraph } from '../global-state.js'
4
5
  import type { Thunk } from '../reactive.js'
5
6
  import type { RefreshReason } from '../store/store-types.js'
6
- import { isValidFunctionString } from '../utils/function-string.js'
7
7
  import { getDurationMsFromSpan } from '../utils/otel.js'
8
- import type { DepKey, GetAtomResult, LiveQueryDef, ReactivityGraph, ReactivityGraphContext } from './base-class.js'
9
- import { defCounterRef, depsToString, LiveStoreQueryBase, makeGetAtomResult, withRCMap } from './base-class.js'
8
+ import type { GetAtomResult, LiveQuery, QueryContext, ReactivityGraph } from './base-class.js'
9
+ import { LiveStoreQueryBase, makeGetAtomResult } from './base-class.js'
10
10
 
11
11
  export const computed = <TResult, TQueryInfo extends QueryInfo = QueryInfo.None>(
12
12
  fn: (get: GetAtomResult) => TResult,
13
13
  options?: {
14
- label?: string
14
+ label: string
15
+ reactivityGraph?: ReactivityGraph
15
16
  queryInfo?: TQueryInfo
16
- deps?: DepKey
17
17
  },
18
- ): LiveQueryDef<TResult, TQueryInfo> => {
19
- const hash = options?.deps ? depsToString(options.deps) : fn.toString()
20
- if (isValidFunctionString(hash)._tag === 'invalid') {
21
- throw new Error(`On Expo/React Native, computed queries must provide a \`deps\` option`)
22
- }
23
-
24
- const queryInfo = options?.queryInfo ?? ({ _tag: 'None' } as TQueryInfo)
25
-
26
- return {
27
- _tag: 'def',
28
- id: ++defCounterRef.current,
29
- make: withRCMap(hash, (ctx, _otelContext) => {
30
- // TODO onDestroy
31
- return new LiveStoreComputedQuery<TResult, TQueryInfo>({
32
- fn,
33
- label: options?.label ?? fn.toString(),
34
- queryInfo: options?.queryInfo,
35
- reactivityGraph: ctx.reactivityGraph.deref()!,
36
- })
37
- }),
18
+ ): LiveQuery<TResult, TQueryInfo> =>
19
+ new LiveStoreComputedQuery<TResult, TQueryInfo>({
20
+ fn,
38
21
  label: options?.label ?? fn.toString(),
39
- // NOTE We're using the `makeQuery` function body string to make sure the key is unique across the app
40
- // TODO we should figure out whether this could cause some problems and/or if there's a better way to do this
41
- // NOTE `fn.toString()` doesn't work in Expo as it always produces `[native code]`
42
- hash,
43
- queryInfo,
44
- }
45
- }
22
+ reactivityGraph: options?.reactivityGraph,
23
+ queryInfo: options?.queryInfo,
24
+ })
46
25
 
47
26
  export class LiveStoreComputedQuery<TResult, TQueryInfo extends QueryInfo = QueryInfo.None> extends LiveStoreQueryBase<
48
27
  TResult,
@@ -51,11 +30,11 @@ export class LiveStoreComputedQuery<TResult, TQueryInfo extends QueryInfo = Quer
51
30
  _tag: 'computed' = 'computed'
52
31
 
53
32
  /** A reactive thunk representing the query results */
54
- results$: Thunk<TResult, ReactivityGraphContext, RefreshReason>
33
+ results$: Thunk<TResult, QueryContext, RefreshReason>
55
34
 
56
35
  label: string
57
36
 
58
- reactivityGraph: ReactivityGraph
37
+ protected reactivityGraph: ReactivityGraph
59
38
 
60
39
  queryInfo: TQueryInfo
61
40
 
@@ -67,22 +46,23 @@ export class LiveStoreComputedQuery<TResult, TQueryInfo extends QueryInfo = Quer
67
46
  }: {
68
47
  label: string
69
48
  fn: (get: GetAtomResult) => TResult
70
- reactivityGraph: ReactivityGraph
49
+ reactivityGraph?: ReactivityGraph
71
50
  queryInfo?: TQueryInfo
72
51
  }) {
73
52
  super()
74
53
 
75
54
  this.label = label
76
- this.reactivityGraph = reactivityGraph
55
+
56
+ this.reactivityGraph = reactivityGraph ?? globalReactivityGraph
77
57
  this.queryInfo = queryInfo ?? ({ _tag: 'None' } as TQueryInfo)
78
58
 
79
59
  const queryLabel = `${label}:results`
80
60
 
81
61
  this.results$ = this.reactivityGraph.makeThunk(
82
- (get, setDebugInfo, ctx, otelContext) =>
83
- ctx.otelTracer.startActiveSpan(`js:${label}`, {}, otelContext ?? ctx.rootOtelContext, (span) => {
62
+ (get, setDebugInfo, { otelTracer, rootOtelContext }, otelContext) =>
63
+ otelTracer.startActiveSpan(`js:${label}`, {}, otelContext ?? rootOtelContext, (span) => {
84
64
  const otelContext = otel.trace.setSpan(otel.context.active(), span)
85
- const res = fn(makeGetAtomResult(get, ctx, otelContext, this.dependencyQueriesRef))
65
+ const res = fn(makeGetAtomResult(get, otelContext))
86
66
 
87
67
  span.end()
88
68
 
@@ -99,12 +79,6 @@ export class LiveStoreComputedQuery<TResult, TQueryInfo extends QueryInfo = Quer
99
79
  }
100
80
 
101
81
  destroy = () => {
102
- this.isDestroyed = true
103
-
104
82
  this.reactivityGraph.destroyNode(this.results$)
105
-
106
- for (const query of this.dependencyQueriesRef) {
107
- query.deref()
108
- }
109
83
  }
110
84
  }
@@ -1,10 +1,9 @@
1
1
  import { Effect, Schema } from '@livestore/utils/effect'
2
2
  import * as otel from '@opentelemetry/api'
3
3
  import { BasicTracerProvider, InMemorySpanExporter, SimpleSpanProcessor } from '@opentelemetry/sdk-trace-base'
4
- import { beforeEach, describe, expect, it } from 'vitest'
4
+ import { describe, expect, it } from 'vitest'
5
5
 
6
6
  import { computed, queryDb, rawSqlMutation, sql } from '../index.js'
7
- import * as RG from '../reactive.js'
8
7
  import { makeTodoMvc, tables } from '../utils/tests/fixture.js'
9
8
  import { getSimplifiedRootSpan } from '../utils/tests/otel.js'
10
9
 
@@ -18,10 +17,6 @@ TODO write tests for:
18
17
  describe('otel', () => {
19
18
  let cachedProvider: BasicTracerProvider | undefined
20
19
 
21
- beforeEach(() => {
22
- RG.__resetIds()
23
- })
24
-
25
20
  const makeQuery = Effect.gen(function* () {
26
21
  const exporter = new InMemorySpanExporter()
27
22
 
@@ -36,7 +31,7 @@ describe('otel', () => {
36
31
  const span = otelTracer.startSpan('test-root')
37
32
  const otelContext = otel.trace.setSpan(otel.context.active(), span)
38
33
 
39
- const store = yield* makeTodoMvc({ otelTracer, otelContext })
34
+ const { store } = yield* makeTodoMvc({ otelTracer, otelContext })
40
35
 
41
36
  return {
42
37
  store,
@@ -56,11 +51,11 @@ describe('otel', () => {
56
51
  schema: Schema.Array(tables.todos.schema),
57
52
  queriedTables: new Set(['todos']),
58
53
  })
59
- expect(store.query(query$)).toMatchInlineSnapshot('[]')
54
+ expect(query$.run()).toMatchInlineSnapshot('[]')
60
55
 
61
56
  store.mutate(rawSqlMutation({ sql: sql`INSERT INTO todos (id, text, completed) VALUES ('t1', 'buy milk', 0)` }))
62
57
 
63
- expect(store.query(query$)).toMatchInlineSnapshot(`
58
+ expect(query$.run()).toMatchInlineSnapshot(`
64
59
  [
65
60
  {
66
61
  "completed": false,
@@ -70,6 +65,7 @@ describe('otel', () => {
70
65
  ]
71
66
  `)
72
67
 
68
+ query$.destroy()
73
69
  span.end()
74
70
 
75
71
  return { exporter }
@@ -93,9 +89,7 @@ describe('otel', () => {
93
89
  { label: 'all todos' },
94
90
  )
95
91
 
96
- expect(store.reactivityGraph.getSnapshot({ includeResults: true })).toMatchSnapshot()
97
-
98
- expect(store.query(query$)).toMatchInlineSnapshot(`
92
+ expect(query$.run()).toMatchInlineSnapshot(`
99
93
  {
100
94
  "completed": false,
101
95
  "id": "",
@@ -103,13 +97,9 @@ describe('otel', () => {
103
97
  }
104
98
  `)
105
99
 
106
- expect(store.reactivityGraph.getSnapshot({ includeResults: true })).toMatchSnapshot()
107
-
108
100
  store.mutate(rawSqlMutation({ sql: sql`INSERT INTO todos (id, text, completed) VALUES ('t1', 'buy milk', 0)` }))
109
101
 
110
- expect(store.reactivityGraph.getSnapshot({ includeResults: true })).toMatchSnapshot()
111
-
112
- expect(store.query(query$)).toMatchInlineSnapshot(`
102
+ expect(query$.run()).toMatchInlineSnapshot(`
113
103
  {
114
104
  "completed": false,
115
105
  "id": "t1",
@@ -117,8 +107,7 @@ describe('otel', () => {
117
107
  }
118
108
  `)
119
109
 
120
- expect(store.reactivityGraph.getSnapshot({ includeResults: true })).toMatchSnapshot()
121
-
110
+ query$.destroy()
122
111
  span.end()
123
112
 
124
113
  return { exporter }
@@ -136,7 +125,7 @@ describe('otel', () => {
136
125
  const filter = computed(() => ({ completed: false }))
137
126
  const query$ = queryDb((get) => tables.todos.query.where(get(filter)).first({ fallback: () => defaultTodo }))
138
127
 
139
- expect(store.query(query$)).toMatchInlineSnapshot(`
128
+ expect(query$.run()).toMatchInlineSnapshot(`
140
129
  {
141
130
  "completed": false,
142
131
  "id": "",
@@ -146,7 +135,7 @@ describe('otel', () => {
146
135
 
147
136
  store.mutate(rawSqlMutation({ sql: sql`INSERT INTO todos (id, text, completed) VALUES ('t1', 'buy milk', 0)` }))
148
137
 
149
- expect(store.query(query$)).toMatchInlineSnapshot(`
138
+ expect(query$.run()).toMatchInlineSnapshot(`
150
139
  {
151
140
  "completed": false,
152
141
  "id": "t1",
@@ -154,6 +143,7 @@ describe('otel', () => {
154
143
  }
155
144
  `)
156
145
 
146
+ query$.destroy()
157
147
  span.end()
158
148
 
159
149
  return { exporter }