@livestore/livestore 0.0.58-dev.8 → 0.1.0-dev.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -117
- package/dist/.tsbuildinfo +1 -1
- package/dist/effect/LiveStore.d.ts +6 -6
- package/dist/effect/LiveStore.d.ts.map +1 -1
- package/dist/effect/LiveStore.js +1 -1
- package/dist/effect/LiveStore.js.map +1 -1
- package/dist/global-state.d.ts.map +1 -1
- package/dist/global-state.js +2 -1
- package/dist/global-state.js.map +1 -1
- package/dist/index.d.ts +11 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -4
- package/dist/index.js.map +1 -1
- package/dist/reactiveQueries/base-class.d.ts +5 -4
- package/dist/reactiveQueries/base-class.d.ts.map +1 -1
- package/dist/reactiveQueries/base-class.js.map +1 -1
- package/dist/reactiveQueries/computed.d.ts +35 -0
- package/dist/reactiveQueries/computed.d.ts.map +1 -0
- package/dist/reactiveQueries/computed.js +57 -0
- package/dist/reactiveQueries/computed.js.map +1 -0
- package/dist/reactiveQueries/graphql.d.ts +2 -1
- package/dist/reactiveQueries/graphql.d.ts.map +1 -1
- package/dist/reactiveQueries/graphql.js.map +1 -1
- package/dist/reactiveQueries/sql.d.ts +2 -2
- package/dist/reactiveQueries/sql.d.ts.map +1 -1
- package/dist/reactiveQueries/sql.js +3 -3
- package/dist/reactiveQueries/sql.js.map +1 -1
- package/dist/reactiveQueries/sql.test.js +2 -2
- package/dist/reactiveQueries/sql.test.js.map +1 -1
- package/dist/row-query.d.ts +3 -2
- package/dist/row-query.d.ts.map +1 -1
- package/dist/row-query.js +14 -10
- package/dist/row-query.js.map +1 -1
- package/dist/store/create-store.d.ts +28 -0
- package/dist/store/create-store.d.ts.map +1 -0
- package/dist/store/create-store.js +85 -0
- package/dist/store/create-store.js.map +1 -0
- package/dist/store/devtools.d.ts +19 -0
- package/dist/store/devtools.d.ts.map +1 -0
- package/dist/store/devtools.js +141 -0
- package/dist/store/devtools.js.map +1 -0
- package/dist/store/store-context.d.ts +26 -0
- package/dist/store/store-context.d.ts.map +1 -0
- package/dist/store/store-context.js +6 -0
- package/dist/store/store-context.js.map +1 -0
- package/dist/store/store-types.d.ts +98 -0
- package/dist/store/store-types.d.ts.map +1 -0
- package/dist/store/store-types.js +6 -0
- package/dist/store/store-types.js.map +1 -0
- package/dist/store/store.d.ts +88 -0
- package/dist/store/store.d.ts.map +1 -0
- package/dist/store/store.js +367 -0
- package/dist/store/store.js.map +1 -0
- package/dist/store-devtools.d.ts +2 -2
- package/dist/store-devtools.d.ts.map +1 -1
- package/dist/store-devtools.js +2 -2
- package/dist/store-devtools.js.map +1 -1
- package/dist/store.d.ts +8 -8
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +54 -54
- package/dist/store.js.map +1 -1
- package/dist/utils/dev.d.ts +1 -0
- package/dist/utils/dev.d.ts.map +1 -1
- package/dist/utils/dev.js +5 -0
- package/dist/utils/dev.js.map +1 -1
- package/dist/{react/utils → utils}/stack-info.d.ts +1 -2
- package/dist/utils/stack-info.d.ts.map +1 -0
- package/dist/{react/utils → utils}/stack-info.js +1 -9
- package/dist/utils/stack-info.js.map +1 -0
- package/dist/utils/stack-info.test.d.ts.map +1 -0
- package/dist/{__tests__/react/utils → utils}/stack-info.test.js +1 -1
- package/dist/utils/stack-info.test.js.map +1 -0
- package/dist/utils/tests/fixture.d.ts +259 -0
- package/dist/utils/tests/fixture.d.ts.map +1 -0
- package/dist/utils/tests/fixture.js +32 -0
- package/dist/utils/tests/fixture.js.map +1 -0
- package/dist/utils/tests/mod.d.ts +3 -0
- package/dist/utils/tests/mod.d.ts.map +1 -0
- package/dist/utils/tests/mod.js +3 -0
- package/dist/utils/tests/mod.js.map +1 -0
- package/dist/utils/tests/otel.d.ts.map +1 -0
- package/dist/{__tests__/react/utils → utils/tests}/otel.js +3 -3
- package/dist/utils/tests/otel.js.map +1 -0
- package/package.json +13 -20
- package/src/ambient.d.ts +3 -1
- package/src/effect/LiveStore.ts +7 -7
- package/src/global-state.ts +5 -1
- package/src/index.ts +19 -7
- package/src/reactiveQueries/base-class.ts +5 -4
- package/src/reactiveQueries/{js.ts → computed.ts} +3 -3
- package/src/reactiveQueries/graphql.ts +2 -1
- package/src/reactiveQueries/sql.test.ts +2 -2
- package/src/reactiveQueries/sql.ts +5 -5
- package/src/row-query.ts +33 -17
- package/src/store/create-store.ts +214 -0
- package/src/{store-devtools.ts → store/devtools.ts} +9 -9
- package/src/store/store-types.ts +110 -0
- package/src/{store.ts → store/store.ts} +56 -415
- package/src/utils/dev.ts +6 -0
- package/src/{__tests__/react/utils → utils}/stack-info.test.ts +1 -1
- package/src/{react/utils → utils}/stack-info.ts +2 -12
- package/src/utils/tests/fixture.ts +73 -0
- package/src/utils/tests/mod.ts +2 -0
- package/src/{__tests__/react/utils → utils/tests}/otel.ts +4 -4
- package/tsconfig.json +1 -2
- package/vitest.config.js +0 -8
- package/dist/__tests__/react/fixture.d.ts +0 -461
- package/dist/__tests__/react/fixture.d.ts.map +0 -1
- package/dist/__tests__/react/fixture.js +0 -68
- package/dist/__tests__/react/fixture.js.map +0 -1
- package/dist/__tests__/react/utils/otel.d.ts.map +0 -1
- package/dist/__tests__/react/utils/otel.js.map +0 -1
- package/dist/__tests__/react/utils/stack-info.test.d.ts.map +0 -1
- package/dist/__tests__/react/utils/stack-info.test.js.map +0 -1
- package/dist/react/LiveStoreContext.d.ts +0 -7
- package/dist/react/LiveStoreContext.d.ts.map +0 -1
- package/dist/react/LiveStoreContext.js +0 -13
- package/dist/react/LiveStoreContext.js.map +0 -1
- package/dist/react/LiveStoreProvider.d.ts +0 -49
- package/dist/react/LiveStoreProvider.d.ts.map +0 -1
- package/dist/react/LiveStoreProvider.js +0 -169
- package/dist/react/LiveStoreProvider.js.map +0 -1
- package/dist/react/LiveStoreProvider.test.d.ts +0 -2
- package/dist/react/LiveStoreProvider.test.d.ts.map +0 -1
- package/dist/react/LiveStoreProvider.test.js +0 -62
- package/dist/react/LiveStoreProvider.test.js.map +0 -1
- package/dist/react/components/LiveList.d.ts +0 -21
- package/dist/react/components/LiveList.d.ts.map +0 -1
- package/dist/react/components/LiveList.js +0 -31
- package/dist/react/components/LiveList.js.map +0 -1
- package/dist/react/index.d.ts +0 -11
- package/dist/react/index.d.ts.map +0 -1
- package/dist/react/index.js +0 -10
- package/dist/react/index.js.map +0 -1
- package/dist/react/useAtom.d.ts +0 -10
- package/dist/react/useAtom.d.ts.map +0 -1
- package/dist/react/useAtom.js +0 -37
- package/dist/react/useAtom.js.map +0 -1
- package/dist/react/useLocalId.d.ts +0 -10
- package/dist/react/useLocalId.d.ts.map +0 -1
- package/dist/react/useLocalId.js +0 -22
- package/dist/react/useLocalId.js.map +0 -1
- package/dist/react/useQuery.d.ts +0 -9
- package/dist/react/useQuery.d.ts.map +0 -1
- package/dist/react/useQuery.js +0 -70
- package/dist/react/useQuery.js.map +0 -1
- package/dist/react/useQuery.test.d.ts +0 -2
- package/dist/react/useQuery.test.d.ts.map +0 -1
- package/dist/react/useQuery.test.js +0 -51
- package/dist/react/useQuery.test.js.map +0 -1
- package/dist/react/useRow.d.ts +0 -46
- package/dist/react/useRow.d.ts.map +0 -1
- package/dist/react/useRow.js +0 -94
- package/dist/react/useRow.js.map +0 -1
- package/dist/react/useRow.test.d.ts +0 -2
- package/dist/react/useRow.test.d.ts.map +0 -1
- package/dist/react/useRow.test.js +0 -208
- package/dist/react/useRow.test.js.map +0 -1
- package/dist/react/useTemporaryQuery.d.ts +0 -22
- package/dist/react/useTemporaryQuery.d.ts.map +0 -1
- package/dist/react/useTemporaryQuery.js +0 -75
- package/dist/react/useTemporaryQuery.js.map +0 -1
- package/dist/react/useTemporaryQuery.test.d.ts +0 -2
- package/dist/react/useTemporaryQuery.test.d.ts.map +0 -1
- package/dist/react/useTemporaryQuery.test.js +0 -59
- package/dist/react/useTemporaryQuery.test.js.map +0 -1
- package/dist/react/utils/stack-info.d.ts.map +0 -1
- package/dist/react/utils/stack-info.js.map +0 -1
- package/dist/react/utils/useStateRefWithReactiveInput.d.ts +0 -13
- package/dist/react/utils/useStateRefWithReactiveInput.d.ts.map +0 -1
- package/dist/react/utils/useStateRefWithReactiveInput.js +0 -38
- package/dist/react/utils/useStateRefWithReactiveInput.js.map +0 -1
- package/src/__tests__/react/fixture.tsx +0 -126
- package/src/react/LiveStoreContext.ts +0 -20
- package/src/react/LiveStoreProvider.test.tsx +0 -109
- package/src/react/LiveStoreProvider.tsx +0 -291
- package/src/react/__snapshots__/useRow.test.tsx.snap +0 -359
- package/src/react/components/LiveList.tsx +0 -84
- package/src/react/index.ts +0 -19
- package/src/react/useAtom.ts +0 -55
- package/src/react/useLocalId.ts +0 -34
- package/src/react/useQuery.test.tsx +0 -82
- package/src/react/useQuery.ts +0 -106
- package/src/react/useRow.test.tsx +0 -345
- package/src/react/useRow.ts +0 -180
- package/src/react/useTemporaryQuery.test.tsx +0 -98
- package/src/react/useTemporaryQuery.ts +0 -131
- package/src/react/utils/useStateRefWithReactiveInput.ts +0 -51
- package/src/store-context.ts +0 -23
- /package/dist/{__tests__/react/utils → utils}/stack-info.test.d.ts +0 -0
- /package/dist/{__tests__/react/utils → utils/tests}/otel.d.ts +0 -0
|
@@ -1,291 +0,0 @@
|
|
|
1
|
-
import type { BootDb, BootStatus, IntentionalShutdownCause, StoreAdapterFactory } from '@livestore/common'
|
|
2
|
-
import { UnexpectedError } from '@livestore/common'
|
|
3
|
-
import type { LiveStoreSchema } from '@livestore/common/schema'
|
|
4
|
-
import { errorToString } from '@livestore/utils'
|
|
5
|
-
import { Effect, FiberSet, Logger, LogLevel, Schema } from '@livestore/utils/effect'
|
|
6
|
-
import type * as otel from '@opentelemetry/api'
|
|
7
|
-
import type { ReactElement, ReactNode } from 'react'
|
|
8
|
-
import React from 'react'
|
|
9
|
-
|
|
10
|
-
import type { BaseGraphQLContext, CreateStoreOptions, GraphQLOptions, OtelOptions } from '../store.js'
|
|
11
|
-
import { createStore } from '../store.js'
|
|
12
|
-
import type { LiveStoreContext as StoreContext_ } from '../store-context.js'
|
|
13
|
-
import { StoreAbort, StoreInterrupted } from '../store-context.js'
|
|
14
|
-
import { LiveStoreContext } from './LiveStoreContext.js'
|
|
15
|
-
|
|
16
|
-
interface LiveStoreProviderProps<GraphQLContext> {
|
|
17
|
-
schema: LiveStoreSchema
|
|
18
|
-
/**
|
|
19
|
-
* The `storeId` can be used to isolate multiple stores from each other.
|
|
20
|
-
* So it can be useful for multi-tenancy scenarios.
|
|
21
|
-
*
|
|
22
|
-
* The `storeId` is also used for persistence.
|
|
23
|
-
*
|
|
24
|
-
* Make sure to also provide `storeId` to `mountDevtools` in `_devtools.html`.
|
|
25
|
-
*
|
|
26
|
-
* @default 'default'
|
|
27
|
-
*/
|
|
28
|
-
storeId?: string
|
|
29
|
-
boot?: (db: BootDb, parentSpan: otel.Span) => void | Promise<void> | Effect.Effect<void, unknown, otel.Tracer>
|
|
30
|
-
graphQLOptions?: GraphQLOptions<GraphQLContext>
|
|
31
|
-
otelOptions?: OtelOptions
|
|
32
|
-
renderLoading: (status: BootStatus) => ReactElement
|
|
33
|
-
renderError?: (error: UnexpectedError | unknown) => ReactElement
|
|
34
|
-
renderShutdown?: (cause: IntentionalShutdownCause | StoreAbort) => ReactElement
|
|
35
|
-
adapter: StoreAdapterFactory
|
|
36
|
-
/**
|
|
37
|
-
* In order for LiveStore to apply multiple mutations in a single render,
|
|
38
|
-
* you need to pass the `batchUpdates` function from either `react-dom` or `react-native`.
|
|
39
|
-
*
|
|
40
|
-
* ```ts
|
|
41
|
-
* // With React DOM
|
|
42
|
-
* import { unstable_batchedUpdates as batchUpdates } from 'react-dom'
|
|
43
|
-
*
|
|
44
|
-
* // With React Native
|
|
45
|
-
* import { unstable_batchedUpdates as batchUpdates } from 'react-native'
|
|
46
|
-
* ```
|
|
47
|
-
*/
|
|
48
|
-
batchUpdates: (run: () => void) => void
|
|
49
|
-
disableDevtools?: boolean
|
|
50
|
-
signal?: AbortSignal
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const defaultRenderError = (error: UnexpectedError | unknown) => (
|
|
54
|
-
<>{Schema.is(UnexpectedError)(error) ? error.toString() : errorToString(error)}</>
|
|
55
|
-
)
|
|
56
|
-
const defaultRenderShutdown = (cause: IntentionalShutdownCause | StoreAbort) => {
|
|
57
|
-
const reason =
|
|
58
|
-
cause._tag === 'LiveStore.StoreAbort'
|
|
59
|
-
? 'abort signal'
|
|
60
|
-
: cause.reason === 'devtools-import'
|
|
61
|
-
? 'devtools import'
|
|
62
|
-
: cause.reason === 'devtools-reset'
|
|
63
|
-
? 'devtools reset'
|
|
64
|
-
: 'unknown reason'
|
|
65
|
-
|
|
66
|
-
return <>LiveStore Shutdown due to {reason}</>
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export const LiveStoreProvider = <GraphQLContext extends BaseGraphQLContext>({
|
|
70
|
-
renderLoading,
|
|
71
|
-
renderError = defaultRenderError,
|
|
72
|
-
renderShutdown = defaultRenderShutdown,
|
|
73
|
-
graphQLOptions,
|
|
74
|
-
otelOptions,
|
|
75
|
-
children,
|
|
76
|
-
schema,
|
|
77
|
-
storeId = 'default',
|
|
78
|
-
boot,
|
|
79
|
-
adapter,
|
|
80
|
-
batchUpdates,
|
|
81
|
-
disableDevtools,
|
|
82
|
-
signal,
|
|
83
|
-
}: LiveStoreProviderProps<GraphQLContext> & { children?: ReactNode }): JSX.Element => {
|
|
84
|
-
const storeCtx = useCreateStore({
|
|
85
|
-
storeId,
|
|
86
|
-
schema,
|
|
87
|
-
graphQLOptions,
|
|
88
|
-
otelOptions,
|
|
89
|
-
boot,
|
|
90
|
-
adapter,
|
|
91
|
-
batchUpdates,
|
|
92
|
-
disableDevtools,
|
|
93
|
-
signal,
|
|
94
|
-
})
|
|
95
|
-
|
|
96
|
-
if (storeCtx.stage === 'error') {
|
|
97
|
-
return renderError(storeCtx.error)
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (storeCtx.stage === 'shutdown') {
|
|
101
|
-
return renderShutdown(storeCtx.cause)
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if (storeCtx.stage !== 'running') {
|
|
105
|
-
return renderLoading(storeCtx)
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
globalThis.__debugLiveStore ??= {}
|
|
109
|
-
globalThis.__debugLiveStore[storeId] = storeCtx.store
|
|
110
|
-
|
|
111
|
-
return <LiveStoreContext.Provider value={storeCtx}>{children}</LiveStoreContext.Provider>
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
type SchemaKey = string
|
|
115
|
-
const semaphoreMap = new Map<SchemaKey, Effect.Semaphore>()
|
|
116
|
-
|
|
117
|
-
const withSemaphore = (storeId: SchemaKey) => {
|
|
118
|
-
let semaphore = semaphoreMap.get(storeId)
|
|
119
|
-
if (!semaphore) {
|
|
120
|
-
semaphore = Effect.makeSemaphore(1).pipe(Effect.runSync)
|
|
121
|
-
semaphoreMap.set(storeId, semaphore)
|
|
122
|
-
}
|
|
123
|
-
return semaphore.withPermits(1)
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
const useCreateStore = <GraphQLContext extends BaseGraphQLContext>({
|
|
127
|
-
schema,
|
|
128
|
-
storeId,
|
|
129
|
-
graphQLOptions,
|
|
130
|
-
otelOptions,
|
|
131
|
-
boot,
|
|
132
|
-
adapter,
|
|
133
|
-
batchUpdates,
|
|
134
|
-
disableDevtools,
|
|
135
|
-
reactivityGraph,
|
|
136
|
-
signal,
|
|
137
|
-
}: CreateStoreOptions<GraphQLContext, LiveStoreSchema> & { signal?: AbortSignal }) => {
|
|
138
|
-
const [_, rerender] = React.useState(0)
|
|
139
|
-
const ctxValueRef = React.useRef<{
|
|
140
|
-
value: StoreContext_ | BootStatus
|
|
141
|
-
fiberSet: FiberSet.FiberSet | undefined
|
|
142
|
-
counter: number
|
|
143
|
-
}>({
|
|
144
|
-
value: { stage: 'loading' },
|
|
145
|
-
fiberSet: undefined,
|
|
146
|
-
counter: 0,
|
|
147
|
-
})
|
|
148
|
-
|
|
149
|
-
// console.debug(`useCreateStore (${ctxValueRef.current.counter})`, ctxValueRef.current.value.stage)
|
|
150
|
-
|
|
151
|
-
const inputPropsCacheRef = React.useRef({
|
|
152
|
-
schema,
|
|
153
|
-
graphQLOptions,
|
|
154
|
-
otelOptions,
|
|
155
|
-
boot,
|
|
156
|
-
adapter,
|
|
157
|
-
batchUpdates,
|
|
158
|
-
disableDevtools,
|
|
159
|
-
reactivityGraph,
|
|
160
|
-
signal,
|
|
161
|
-
})
|
|
162
|
-
|
|
163
|
-
const interrupt = (fiberSet: FiberSet.FiberSet, error: StoreAbort | StoreInterrupted) =>
|
|
164
|
-
Effect.gen(function* () {
|
|
165
|
-
yield* FiberSet.clear(fiberSet)
|
|
166
|
-
yield* FiberSet.run(fiberSet, Effect.fail(error))
|
|
167
|
-
}).pipe(
|
|
168
|
-
Effect.tapErrorCause((cause) => Effect.logDebug(`[@livestore/livestore/react] interupting`, cause)),
|
|
169
|
-
Effect.runFork,
|
|
170
|
-
)
|
|
171
|
-
|
|
172
|
-
if (
|
|
173
|
-
inputPropsCacheRef.current.schema !== schema ||
|
|
174
|
-
inputPropsCacheRef.current.graphQLOptions !== graphQLOptions ||
|
|
175
|
-
inputPropsCacheRef.current.otelOptions !== otelOptions ||
|
|
176
|
-
inputPropsCacheRef.current.boot !== boot ||
|
|
177
|
-
inputPropsCacheRef.current.adapter !== adapter ||
|
|
178
|
-
inputPropsCacheRef.current.batchUpdates !== batchUpdates ||
|
|
179
|
-
inputPropsCacheRef.current.disableDevtools !== disableDevtools ||
|
|
180
|
-
inputPropsCacheRef.current.reactivityGraph !== reactivityGraph ||
|
|
181
|
-
inputPropsCacheRef.current.signal !== signal
|
|
182
|
-
) {
|
|
183
|
-
inputPropsCacheRef.current = {
|
|
184
|
-
schema,
|
|
185
|
-
graphQLOptions,
|
|
186
|
-
otelOptions,
|
|
187
|
-
boot,
|
|
188
|
-
adapter,
|
|
189
|
-
batchUpdates,
|
|
190
|
-
disableDevtools,
|
|
191
|
-
reactivityGraph,
|
|
192
|
-
signal,
|
|
193
|
-
}
|
|
194
|
-
if (ctxValueRef.current.fiberSet !== undefined) {
|
|
195
|
-
interrupt(ctxValueRef.current.fiberSet, new StoreInterrupted())
|
|
196
|
-
ctxValueRef.current.fiberSet = undefined
|
|
197
|
-
}
|
|
198
|
-
ctxValueRef.current = { value: { stage: 'loading' }, fiberSet: undefined, counter: ctxValueRef.current.counter + 1 }
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
React.useEffect(() => {
|
|
202
|
-
const counter = ctxValueRef.current.counter
|
|
203
|
-
|
|
204
|
-
const setContextValue = (value: StoreContext_ | BootStatus) => {
|
|
205
|
-
if (ctxValueRef.current.counter !== counter) return
|
|
206
|
-
ctxValueRef.current.value = value
|
|
207
|
-
rerender((c) => c + 1)
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
signal?.addEventListener('abort', () => {
|
|
211
|
-
if (ctxValueRef.current.fiberSet !== undefined && ctxValueRef.current.counter === counter) {
|
|
212
|
-
interrupt(ctxValueRef.current.fiberSet, new StoreAbort())
|
|
213
|
-
ctxValueRef.current.fiberSet = undefined
|
|
214
|
-
}
|
|
215
|
-
})
|
|
216
|
-
|
|
217
|
-
Effect.gen(function* () {
|
|
218
|
-
const fiberSet = yield* FiberSet.make<
|
|
219
|
-
unknown,
|
|
220
|
-
UnexpectedError | IntentionalShutdownCause | StoreAbort | StoreInterrupted
|
|
221
|
-
>()
|
|
222
|
-
|
|
223
|
-
ctxValueRef.current.fiberSet = fiberSet
|
|
224
|
-
|
|
225
|
-
yield* Effect.gen(function* () {
|
|
226
|
-
const store = yield* createStore({
|
|
227
|
-
fiberSet,
|
|
228
|
-
schema,
|
|
229
|
-
storeId,
|
|
230
|
-
graphQLOptions,
|
|
231
|
-
otelOptions,
|
|
232
|
-
boot,
|
|
233
|
-
adapter,
|
|
234
|
-
reactivityGraph,
|
|
235
|
-
batchUpdates,
|
|
236
|
-
disableDevtools,
|
|
237
|
-
onBootStatus: (status) => {
|
|
238
|
-
if (ctxValueRef.current.value.stage === 'running' || ctxValueRef.current.value.stage === 'error') return
|
|
239
|
-
setContextValue(status)
|
|
240
|
-
},
|
|
241
|
-
})
|
|
242
|
-
|
|
243
|
-
setContextValue({ stage: 'running', store })
|
|
244
|
-
|
|
245
|
-
yield* Effect.never
|
|
246
|
-
}).pipe(Effect.scoped, FiberSet.run(fiberSet))
|
|
247
|
-
|
|
248
|
-
const shutdownContext = (cause: IntentionalShutdownCause | StoreAbort) =>
|
|
249
|
-
Effect.sync(() => setContextValue({ stage: 'shutdown', cause }))
|
|
250
|
-
|
|
251
|
-
yield* FiberSet.join(fiberSet).pipe(
|
|
252
|
-
Effect.catchTag('LiveStore.IntentionalShutdownCause', (cause) => shutdownContext(cause)),
|
|
253
|
-
Effect.catchTag('LiveStore.StoreAbort', (cause) => shutdownContext(cause)),
|
|
254
|
-
Effect.tapError((error) => Effect.sync(() => setContextValue({ stage: 'error', error }))),
|
|
255
|
-
Effect.tapDefect((defect) => Effect.sync(() => setContextValue({ stage: 'error', error: defect }))),
|
|
256
|
-
Effect.exit,
|
|
257
|
-
)
|
|
258
|
-
}).pipe(
|
|
259
|
-
Effect.scoped,
|
|
260
|
-
// NOTE we're running the code above in a semaphore to make sure a previous store is always fully
|
|
261
|
-
// shutdown before a new one is created - especially when shutdown logic is async. You can't trust `React.useEffect`.
|
|
262
|
-
// Thank you to Mattia Manzati for this idea.
|
|
263
|
-
withSemaphore(storeId),
|
|
264
|
-
Effect.tapCauseLogPretty,
|
|
265
|
-
Effect.annotateLogs({ thread: 'window' }),
|
|
266
|
-
Effect.provide(Logger.pretty),
|
|
267
|
-
Logger.withMinimumLogLevel(LogLevel.Debug),
|
|
268
|
-
Effect.runFork,
|
|
269
|
-
)
|
|
270
|
-
|
|
271
|
-
return () => {
|
|
272
|
-
if (ctxValueRef.current.fiberSet !== undefined) {
|
|
273
|
-
interrupt(ctxValueRef.current.fiberSet, new StoreInterrupted())
|
|
274
|
-
ctxValueRef.current.fiberSet = undefined
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
}, [
|
|
278
|
-
schema,
|
|
279
|
-
graphQLOptions,
|
|
280
|
-
otelOptions,
|
|
281
|
-
boot,
|
|
282
|
-
adapter,
|
|
283
|
-
batchUpdates,
|
|
284
|
-
disableDevtools,
|
|
285
|
-
signal,
|
|
286
|
-
reactivityGraph,
|
|
287
|
-
storeId,
|
|
288
|
-
])
|
|
289
|
-
|
|
290
|
-
return ctxValueRef.current.value
|
|
291
|
-
}
|
|
@@ -1,359 +0,0 @@
|
|
|
1
|
-
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
-
|
|
3
|
-
exports[`useRow > otel > should update the data based on component key > strictMode=false 1`] = `
|
|
4
|
-
{
|
|
5
|
-
"_name": "test",
|
|
6
|
-
"children": [
|
|
7
|
-
{
|
|
8
|
-
"_name": "livestore.in-memory-db:execute",
|
|
9
|
-
"attributes": {
|
|
10
|
-
"sql.query": "
|
|
11
|
-
PRAGMA page_size=32768;
|
|
12
|
-
PRAGMA cache_size=10000;
|
|
13
|
-
PRAGMA journal_mode='MEMORY'; -- we don't flush to disk before committing a write
|
|
14
|
-
PRAGMA synchronous='OFF';
|
|
15
|
-
PRAGMA temp_store='MEMORY';
|
|
16
|
-
PRAGMA foreign_keys='ON'; -- we want foreign key constraints to be enforced
|
|
17
|
-
",
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
"_name": "sql-in-memory-select",
|
|
22
|
-
"attributes": {
|
|
23
|
-
"sql.cached": false,
|
|
24
|
-
"sql.query": "select 1 from UserInfo where id = 'u1'",
|
|
25
|
-
"sql.rowsCount": 0,
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
"_name": "sql-in-memory-select",
|
|
30
|
-
"attributes": {
|
|
31
|
-
"sql.cached": false,
|
|
32
|
-
"sql.query": "select 1 from UserInfo where id = 'u2'",
|
|
33
|
-
"sql.rowsCount": 1,
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
"_name": "LiveStore:mutations",
|
|
38
|
-
"children": [
|
|
39
|
-
{
|
|
40
|
-
"_name": "LiveStore:mutate",
|
|
41
|
-
"attributes": {
|
|
42
|
-
"livestore.mutateLabel": "mutate",
|
|
43
|
-
},
|
|
44
|
-
"children": [
|
|
45
|
-
{
|
|
46
|
-
"_name": "LiveStore:processWrites",
|
|
47
|
-
"attributes": {
|
|
48
|
-
"livestore.mutateLabel": "mutate",
|
|
49
|
-
},
|
|
50
|
-
"children": [
|
|
51
|
-
{
|
|
52
|
-
"_name": "LiveStore:mutateWithoutRefresh",
|
|
53
|
-
"attributes": {
|
|
54
|
-
"livestore.args": "{
|
|
55
|
-
"sql": "INSERT INTO UserInfo (id, username) VALUES ('u2', 'username_u2')"
|
|
56
|
-
}",
|
|
57
|
-
"livestore.mutation": "livestore.RawSql",
|
|
58
|
-
},
|
|
59
|
-
"children": [
|
|
60
|
-
{
|
|
61
|
-
"_name": "livestore.in-memory-db:execute",
|
|
62
|
-
"attributes": {
|
|
63
|
-
"sql.query": "INSERT INTO UserInfo (id, username) VALUES ('u2', 'username_u2')",
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
-
],
|
|
67
|
-
},
|
|
68
|
-
],
|
|
69
|
-
},
|
|
70
|
-
],
|
|
71
|
-
},
|
|
72
|
-
],
|
|
73
|
-
},
|
|
74
|
-
{
|
|
75
|
-
"_name": "LiveStore:queries",
|
|
76
|
-
"children": [
|
|
77
|
-
{
|
|
78
|
-
"_name": "sql:select * from UserInfo where id = 'u1' limit 1",
|
|
79
|
-
"attributes": {
|
|
80
|
-
"sql.query": "select * from UserInfo where id = 'u1' limit 1",
|
|
81
|
-
"sql.rowsCount": 1,
|
|
82
|
-
},
|
|
83
|
-
"children": [
|
|
84
|
-
{
|
|
85
|
-
"_name": "sql-in-memory-select",
|
|
86
|
-
"attributes": {
|
|
87
|
-
"sql.cached": false,
|
|
88
|
-
"sql.query": "select * from UserInfo where id = 'u1' limit 1",
|
|
89
|
-
"sql.rowsCount": 1,
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
],
|
|
93
|
-
},
|
|
94
|
-
{
|
|
95
|
-
"_name": "LiveStore:useRow:UserInfo:u1",
|
|
96
|
-
"attributes": {
|
|
97
|
-
"id": "u1",
|
|
98
|
-
},
|
|
99
|
-
"children": [
|
|
100
|
-
{
|
|
101
|
-
"_name": "LiveStore:mutateWithoutRefresh",
|
|
102
|
-
"attributes": {
|
|
103
|
-
"livestore.args": "{
|
|
104
|
-
"id": "u1"
|
|
105
|
-
}",
|
|
106
|
-
"livestore.mutation": "_Derived_Create_UserInfo",
|
|
107
|
-
},
|
|
108
|
-
"children": [
|
|
109
|
-
{
|
|
110
|
-
"_name": "livestore.in-memory-db:execute",
|
|
111
|
-
"attributes": {
|
|
112
|
-
"sql.query": "INSERT INTO UserInfo (username, text, id) VALUES ($username, $text, $id)",
|
|
113
|
-
},
|
|
114
|
-
},
|
|
115
|
-
],
|
|
116
|
-
},
|
|
117
|
-
{
|
|
118
|
-
"_name": "LiveStore:useQuery:sql(rowQuery:query:UserInfo:u1)",
|
|
119
|
-
"attributes": {
|
|
120
|
-
"label": "sql(rowQuery:query:UserInfo:u1)",
|
|
121
|
-
"stackInfo": "{"frames":[{"name":"renderHook.wrapper","filePath":"__REPLACED_FOR_SNAPSHOT__"},{"name":"useRow","filePath":"__REPLACED_FOR_SNAPSHOT__"}]}",
|
|
122
|
-
},
|
|
123
|
-
"children": [
|
|
124
|
-
{
|
|
125
|
-
"_name": "sql:select * from UserInfo where id = 'u1' limit 1",
|
|
126
|
-
"attributes": {
|
|
127
|
-
"sql.query": "select * from UserInfo where id = 'u1' limit 1",
|
|
128
|
-
"sql.rowsCount": 1,
|
|
129
|
-
},
|
|
130
|
-
"children": [
|
|
131
|
-
{
|
|
132
|
-
"_name": "sql-in-memory-select",
|
|
133
|
-
"attributes": {
|
|
134
|
-
"sql.cached": false,
|
|
135
|
-
"sql.query": "select * from UserInfo where id = 'u1' limit 1",
|
|
136
|
-
"sql.rowsCount": 1,
|
|
137
|
-
},
|
|
138
|
-
},
|
|
139
|
-
],
|
|
140
|
-
},
|
|
141
|
-
{
|
|
142
|
-
"_name": "LiveStore.subscribe",
|
|
143
|
-
"attributes": {
|
|
144
|
-
"label": "sql(rowQuery:query:UserInfo:u1)",
|
|
145
|
-
"queryLabel": "sql(rowQuery:query:UserInfo:u1)",
|
|
146
|
-
},
|
|
147
|
-
},
|
|
148
|
-
],
|
|
149
|
-
},
|
|
150
|
-
],
|
|
151
|
-
},
|
|
152
|
-
{
|
|
153
|
-
"_name": "LiveStore:useRow:UserInfo:u2",
|
|
154
|
-
"attributes": {
|
|
155
|
-
"id": "u2",
|
|
156
|
-
},
|
|
157
|
-
"children": [
|
|
158
|
-
{
|
|
159
|
-
"_name": "LiveStore:useQuery:sql(rowQuery:query:UserInfo:u2)",
|
|
160
|
-
"attributes": {
|
|
161
|
-
"label": "sql(rowQuery:query:UserInfo:u2)",
|
|
162
|
-
"stackInfo": "{"frames":[{"name":"renderHook.wrapper","filePath":"__REPLACED_FOR_SNAPSHOT__"},{"name":"useRow","filePath":"__REPLACED_FOR_SNAPSHOT__"}]}",
|
|
163
|
-
},
|
|
164
|
-
"children": [
|
|
165
|
-
{
|
|
166
|
-
"_name": "sql:select * from UserInfo where id = 'u2' limit 1",
|
|
167
|
-
"attributes": {
|
|
168
|
-
"sql.query": "select * from UserInfo where id = 'u2' limit 1",
|
|
169
|
-
"sql.rowsCount": 1,
|
|
170
|
-
},
|
|
171
|
-
"children": [
|
|
172
|
-
{
|
|
173
|
-
"_name": "sql-in-memory-select",
|
|
174
|
-
"attributes": {
|
|
175
|
-
"sql.cached": false,
|
|
176
|
-
"sql.query": "select * from UserInfo where id = 'u2' limit 1",
|
|
177
|
-
"sql.rowsCount": 1,
|
|
178
|
-
},
|
|
179
|
-
},
|
|
180
|
-
],
|
|
181
|
-
},
|
|
182
|
-
{
|
|
183
|
-
"_name": "LiveStore.subscribe",
|
|
184
|
-
"attributes": {
|
|
185
|
-
"label": "sql(rowQuery:query:UserInfo:u2)",
|
|
186
|
-
"queryLabel": "sql(rowQuery:query:UserInfo:u2)",
|
|
187
|
-
},
|
|
188
|
-
},
|
|
189
|
-
],
|
|
190
|
-
},
|
|
191
|
-
],
|
|
192
|
-
},
|
|
193
|
-
],
|
|
194
|
-
},
|
|
195
|
-
],
|
|
196
|
-
}
|
|
197
|
-
`;
|
|
198
|
-
|
|
199
|
-
exports[`useRow > otel > should update the data based on component key > strictMode=true 1`] = `
|
|
200
|
-
{
|
|
201
|
-
"_name": "test",
|
|
202
|
-
"children": [
|
|
203
|
-
{
|
|
204
|
-
"_name": "livestore.in-memory-db:execute",
|
|
205
|
-
"attributes": {
|
|
206
|
-
"sql.query": "
|
|
207
|
-
PRAGMA page_size=32768;
|
|
208
|
-
PRAGMA cache_size=10000;
|
|
209
|
-
PRAGMA journal_mode='MEMORY'; -- we don't flush to disk before committing a write
|
|
210
|
-
PRAGMA synchronous='OFF';
|
|
211
|
-
PRAGMA temp_store='MEMORY';
|
|
212
|
-
PRAGMA foreign_keys='ON'; -- we want foreign key constraints to be enforced
|
|
213
|
-
",
|
|
214
|
-
},
|
|
215
|
-
},
|
|
216
|
-
{
|
|
217
|
-
"_name": "sql-in-memory-select",
|
|
218
|
-
"attributes": {
|
|
219
|
-
"sql.cached": false,
|
|
220
|
-
"sql.query": "select 1 from UserInfo where id = 'u1'",
|
|
221
|
-
"sql.rowsCount": 0,
|
|
222
|
-
},
|
|
223
|
-
},
|
|
224
|
-
{
|
|
225
|
-
"_name": "sql-in-memory-select",
|
|
226
|
-
"attributes": {
|
|
227
|
-
"sql.cached": false,
|
|
228
|
-
"sql.query": "select 1 from UserInfo where id = 'u2'",
|
|
229
|
-
"sql.rowsCount": 1,
|
|
230
|
-
},
|
|
231
|
-
},
|
|
232
|
-
{
|
|
233
|
-
"_name": "LiveStore:mutations",
|
|
234
|
-
"children": [
|
|
235
|
-
{
|
|
236
|
-
"_name": "LiveStore:mutate",
|
|
237
|
-
"attributes": {
|
|
238
|
-
"livestore.mutateLabel": "mutate",
|
|
239
|
-
},
|
|
240
|
-
"children": [
|
|
241
|
-
{
|
|
242
|
-
"_name": "LiveStore:processWrites",
|
|
243
|
-
"attributes": {
|
|
244
|
-
"livestore.mutateLabel": "mutate",
|
|
245
|
-
},
|
|
246
|
-
"children": [
|
|
247
|
-
{
|
|
248
|
-
"_name": "LiveStore:mutateWithoutRefresh",
|
|
249
|
-
"attributes": {
|
|
250
|
-
"livestore.args": "{
|
|
251
|
-
"sql": "INSERT INTO UserInfo (id, username) VALUES ('u2', 'username_u2')"
|
|
252
|
-
}",
|
|
253
|
-
"livestore.mutation": "livestore.RawSql",
|
|
254
|
-
},
|
|
255
|
-
"children": [
|
|
256
|
-
{
|
|
257
|
-
"_name": "livestore.in-memory-db:execute",
|
|
258
|
-
"attributes": {
|
|
259
|
-
"sql.query": "INSERT INTO UserInfo (id, username) VALUES ('u2', 'username_u2')",
|
|
260
|
-
},
|
|
261
|
-
},
|
|
262
|
-
],
|
|
263
|
-
},
|
|
264
|
-
],
|
|
265
|
-
},
|
|
266
|
-
],
|
|
267
|
-
},
|
|
268
|
-
],
|
|
269
|
-
},
|
|
270
|
-
{
|
|
271
|
-
"_name": "LiveStore:queries",
|
|
272
|
-
"children": [
|
|
273
|
-
{
|
|
274
|
-
"_name": "sql:select * from UserInfo where id = 'u1' limit 1",
|
|
275
|
-
"attributes": {
|
|
276
|
-
"sql.query": "select * from UserInfo where id = 'u1' limit 1",
|
|
277
|
-
"sql.rowsCount": 1,
|
|
278
|
-
},
|
|
279
|
-
"children": [
|
|
280
|
-
{
|
|
281
|
-
"_name": "sql-in-memory-select",
|
|
282
|
-
"attributes": {
|
|
283
|
-
"sql.cached": false,
|
|
284
|
-
"sql.query": "select * from UserInfo where id = 'u1' limit 1",
|
|
285
|
-
"sql.rowsCount": 1,
|
|
286
|
-
},
|
|
287
|
-
},
|
|
288
|
-
],
|
|
289
|
-
},
|
|
290
|
-
{
|
|
291
|
-
"_name": "LiveStore:useRow:UserInfo:u1",
|
|
292
|
-
"attributes": {
|
|
293
|
-
"id": "u1",
|
|
294
|
-
},
|
|
295
|
-
"children": [
|
|
296
|
-
{
|
|
297
|
-
"_name": "LiveStore:mutateWithoutRefresh",
|
|
298
|
-
"attributes": {
|
|
299
|
-
"livestore.args": "{
|
|
300
|
-
"id": "u1"
|
|
301
|
-
}",
|
|
302
|
-
"livestore.mutation": "_Derived_Create_UserInfo",
|
|
303
|
-
},
|
|
304
|
-
"children": [
|
|
305
|
-
{
|
|
306
|
-
"_name": "livestore.in-memory-db:execute",
|
|
307
|
-
"attributes": {
|
|
308
|
-
"sql.query": "INSERT INTO UserInfo (username, text, id) VALUES ($username, $text, $id)",
|
|
309
|
-
},
|
|
310
|
-
},
|
|
311
|
-
],
|
|
312
|
-
},
|
|
313
|
-
{
|
|
314
|
-
"_name": "LiveStore:useQuery:sql(rowQuery:query:UserInfo:u1)",
|
|
315
|
-
"attributes": {
|
|
316
|
-
"label": "sql(rowQuery:query:UserInfo:u1)",
|
|
317
|
-
"stackInfo": "{"frames":[{"name":"renderHook.wrapper","filePath":"__REPLACED_FOR_SNAPSHOT__"},{"name":"useRow","filePath":"__REPLACED_FOR_SNAPSHOT__"}]}",
|
|
318
|
-
},
|
|
319
|
-
"children": [
|
|
320
|
-
{
|
|
321
|
-
"_name": "sql:select * from UserInfo where id = 'u1' limit 1",
|
|
322
|
-
"attributes": {
|
|
323
|
-
"sql.query": "select * from UserInfo where id = 'u1' limit 1",
|
|
324
|
-
"sql.rowsCount": 1,
|
|
325
|
-
},
|
|
326
|
-
"children": [
|
|
327
|
-
{
|
|
328
|
-
"_name": "sql-in-memory-select",
|
|
329
|
-
"attributes": {
|
|
330
|
-
"sql.cached": false,
|
|
331
|
-
"sql.query": "select * from UserInfo where id = 'u1' limit 1",
|
|
332
|
-
"sql.rowsCount": 1,
|
|
333
|
-
},
|
|
334
|
-
},
|
|
335
|
-
],
|
|
336
|
-
},
|
|
337
|
-
{
|
|
338
|
-
"_name": "LiveStore.subscribe",
|
|
339
|
-
"attributes": {
|
|
340
|
-
"label": "sql(rowQuery:query:UserInfo:u1)",
|
|
341
|
-
"queryLabel": "sql(rowQuery:query:UserInfo:u1)",
|
|
342
|
-
},
|
|
343
|
-
},
|
|
344
|
-
{
|
|
345
|
-
"_name": "LiveStore.subscribe",
|
|
346
|
-
"attributes": {
|
|
347
|
-
"label": "sql(rowQuery:query:UserInfo:u1)",
|
|
348
|
-
"queryLabel": "sql(rowQuery:query:UserInfo:u1)",
|
|
349
|
-
},
|
|
350
|
-
},
|
|
351
|
-
],
|
|
352
|
-
},
|
|
353
|
-
],
|
|
354
|
-
},
|
|
355
|
-
],
|
|
356
|
-
},
|
|
357
|
-
],
|
|
358
|
-
}
|
|
359
|
-
`;
|