@livestore/livestore 0.0.0-snapshot-a39a3b63b870a2878f22f82ce2979a6989076053 → 0.0.0-snapshot-97ca7eac46b6a583b22d40189126d06a377ec1b0
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/dist/.tsbuildinfo +1 -1
- package/dist/QueryCache.d.ts.map +1 -1
- package/dist/SqliteDbWrapper.d.ts.map +1 -1
- package/dist/SqliteDbWrapper.js +1 -2
- package/dist/SqliteDbWrapper.js.map +1 -1
- package/dist/effect/LiveStore.d.ts +6 -38
- package/dist/effect/LiveStore.d.ts.map +1 -1
- package/dist/effect/LiveStore.js +6 -18
- package/dist/effect/LiveStore.js.map +1 -1
- package/dist/effect/mod.d.ts +3 -0
- package/dist/effect/mod.d.ts.map +1 -0
- package/dist/effect/mod.js +3 -0
- package/dist/effect/mod.js.map +1 -0
- package/dist/internal/mod.d.ts +3 -0
- package/dist/internal/mod.d.ts.map +1 -0
- package/dist/internal/mod.js +3 -0
- package/dist/internal/mod.js.map +1 -0
- package/dist/live-queries/base-class.d.ts +10 -6
- package/dist/live-queries/base-class.d.ts.map +1 -1
- package/dist/live-queries/base-class.js.map +1 -1
- package/dist/live-queries/computed.d.ts.map +1 -1
- package/dist/live-queries/computed.js +1 -1
- package/dist/live-queries/computed.js.map +1 -1
- package/dist/live-queries/db-query.d.ts.map +1 -1
- package/dist/live-queries/db-query.js +1 -2
- package/dist/live-queries/db-query.js.map +1 -1
- package/dist/live-queries/db-query.test.js +4 -1
- package/dist/live-queries/db-query.test.js.map +1 -1
- package/dist/live-queries/make-ref.d.ts.map +1 -1
- package/dist/live-queries/mod.d.ts +5 -0
- package/dist/live-queries/mod.d.ts.map +1 -0
- package/dist/live-queries/mod.js +5 -0
- package/dist/live-queries/mod.js.map +1 -0
- package/dist/mod.d.ts +14 -0
- package/dist/mod.d.ts.map +1 -0
- package/dist/mod.js +11 -0
- package/dist/mod.js.map +1 -0
- package/dist/reactive.d.ts.map +1 -1
- package/dist/row-query-utils.d.ts.map +1 -1
- package/dist/store/create-store.d.ts +35 -9
- package/dist/store/create-store.d.ts.map +1 -1
- package/dist/store/create-store.js +12 -4
- package/dist/store/create-store.js.map +1 -1
- package/dist/store/devtools.d.ts.map +1 -1
- package/dist/store/store-types.d.ts +6 -29
- package/dist/store/store-types.d.ts.map +1 -1
- package/dist/store/store-types.js +1 -5
- package/dist/store/store-types.js.map +1 -1
- package/dist/store/store.d.ts +4 -6
- package/dist/store/store.d.ts.map +1 -1
- package/dist/store/store.js +6 -11
- package/dist/store/store.js.map +1 -1
- package/dist/utils/data-structures.d.ts.map +1 -1
- package/dist/utils/dev.d.ts.map +1 -1
- package/dist/utils/function-string.d.ts.map +1 -1
- package/dist/utils/stack-info.d.ts.map +1 -1
- package/dist/utils/tests/fixture.d.ts +1 -1
- package/dist/utils/tests/fixture.d.ts.map +1 -1
- package/dist/utils/tests/fixture.js.map +1 -1
- package/dist/utils/tests/otel.d.ts.map +1 -1
- package/package.json +20 -22
- package/src/SqliteDbWrapper.ts +8 -2
- package/src/effect/LiveStore.ts +22 -70
- package/src/effect/{index.ts → mod.ts} +2 -3
- package/src/internal/mod.ts +2 -0
- package/src/live-queries/base-class.ts +12 -7
- package/src/live-queries/computed.ts +1 -1
- package/src/live-queries/db-query.test.ts +4 -1
- package/src/live-queries/db-query.ts +1 -1
- package/src/live-queries/mod.ts +4 -0
- package/src/mod.ts +37 -0
- package/src/store/create-store.ts +56 -20
- package/src/store/store-types.ts +6 -30
- package/src/store/store.ts +11 -25
- package/src/utils/tests/fixture.ts +1 -1
- package/dist/effect/index.d.ts +0 -2
- package/dist/effect/index.d.ts.map +0 -1
- package/dist/effect/index.js +0 -2
- package/dist/effect/index.js.map +0 -1
- package/dist/index.d.ts +0 -19
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -16
- package/dist/index.js.map +0 -1
- package/dist/live-queries/graphql.d.ts +0 -49
- package/dist/live-queries/graphql.d.ts.map +0 -1
- package/dist/live-queries/graphql.js +0 -147
- package/dist/live-queries/graphql.js.map +0 -1
- package/dist/utils/otel.d.ts +0 -4
- package/dist/utils/otel.d.ts.map +0 -1
- package/dist/utils/otel.js +0 -6
- package/dist/utils/otel.js.map +0 -1
- package/src/index.ts +0 -72
- package/src/live-queries/graphql.ts +0 -244
- package/src/utils/otel.ts +0 -9
package/package.json
CHANGED
|
@@ -1,54 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@livestore/livestore",
|
|
3
|
-
"version": "0.0.0-snapshot-
|
|
3
|
+
"version": "0.0.0-snapshot-97ca7eac46b6a583b22d40189126d06a377ec1b0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
8
|
-
"types": "./dist/
|
|
9
|
-
"default": "./dist/
|
|
8
|
+
"types": "./dist/mod.d.ts",
|
|
9
|
+
"default": "./dist/mod.js"
|
|
10
|
+
},
|
|
11
|
+
"./internal": {
|
|
12
|
+
"types": "./dist/internal/mod.d.ts",
|
|
13
|
+
"default": "./dist/internal/mod.js"
|
|
10
14
|
},
|
|
11
15
|
"./internal/testing-utils": {
|
|
12
16
|
"types": "./dist/utils/tests/mod.d.ts",
|
|
13
17
|
"default": "./dist/utils/tests/mod.js"
|
|
14
18
|
},
|
|
15
19
|
"./effect": {
|
|
16
|
-
"types": "./dist/effect/
|
|
17
|
-
"default": "./dist/effect/
|
|
20
|
+
"types": "./dist/effect/mod.d.ts",
|
|
21
|
+
"default": "./dist/effect/mod.js"
|
|
18
22
|
}
|
|
19
23
|
},
|
|
20
|
-
"types": "./dist/
|
|
24
|
+
"types": "./dist/mod.d.ts",
|
|
21
25
|
"typesVersions": {
|
|
22
26
|
"*": {
|
|
27
|
+
"internal": [
|
|
28
|
+
"./dist/internal/mod.d.ts"
|
|
29
|
+
],
|
|
23
30
|
"testing-utils": [
|
|
24
31
|
"./dist/utils/tests/mod.d.ts"
|
|
25
32
|
],
|
|
26
33
|
"effect": [
|
|
27
|
-
"./dist/effect/
|
|
34
|
+
"./dist/effect/mod.d.ts"
|
|
28
35
|
]
|
|
29
36
|
}
|
|
30
37
|
},
|
|
31
38
|
"dependencies": {
|
|
32
|
-
"@graphql-typed-document-node/core": "3.2.0",
|
|
33
39
|
"@opentelemetry/api": "1.9.0",
|
|
34
|
-
"@livestore/common": "0.0.0-snapshot-
|
|
35
|
-
"@livestore/utils": "0.0.0-snapshot-
|
|
40
|
+
"@livestore/common": "0.0.0-snapshot-97ca7eac46b6a583b22d40189126d06a377ec1b0",
|
|
41
|
+
"@livestore/utils": "0.0.0-snapshot-97ca7eac46b6a583b22d40189126d06a377ec1b0"
|
|
36
42
|
},
|
|
37
43
|
"devDependencies": {
|
|
38
44
|
"@opentelemetry/sdk-trace-base": "^1.30.1",
|
|
39
45
|
"jsdom": "^26.0.0",
|
|
40
|
-
"typescript": "^5.
|
|
41
|
-
"vite": "^6.1
|
|
42
|
-
"vitest": "^
|
|
43
|
-
"@livestore/adapter-web": "0.0.0-snapshot-
|
|
44
|
-
},
|
|
45
|
-
"peerDependencies": {
|
|
46
|
-
"graphql": "~16.0"
|
|
47
|
-
},
|
|
48
|
-
"peerDependenciesMeta": {
|
|
49
|
-
"graphql": {
|
|
50
|
-
"optional": true
|
|
51
|
-
}
|
|
46
|
+
"typescript": "^5.8.2",
|
|
47
|
+
"vite": "^6.2.1",
|
|
48
|
+
"vitest": "^3.0.8",
|
|
49
|
+
"@livestore/adapter-web": "0.0.0-snapshot-97ca7eac46b6a583b22d40189126d06a377ec1b0"
|
|
52
50
|
},
|
|
53
51
|
"publishConfig": {
|
|
54
52
|
"access": "public"
|
package/src/SqliteDbWrapper.ts
CHANGED
|
@@ -9,12 +9,18 @@ import type {
|
|
|
9
9
|
SqliteDbChangeset,
|
|
10
10
|
SqliteDbSession,
|
|
11
11
|
} from '@livestore/common'
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
BoundArray,
|
|
14
|
+
BoundMap,
|
|
15
|
+
getDurationMsFromSpan,
|
|
16
|
+
getStartTimeHighResFromSpan,
|
|
17
|
+
sql,
|
|
18
|
+
SqliteError,
|
|
19
|
+
} from '@livestore/common'
|
|
13
20
|
import { isDevEnv } from '@livestore/utils'
|
|
14
21
|
import type * as otel from '@opentelemetry/api'
|
|
15
22
|
|
|
16
23
|
import QueryCache from './QueryCache.js'
|
|
17
|
-
import { getDurationMsFromSpan, getStartTimeHighResFromSpan } from './utils/otel.js'
|
|
18
24
|
|
|
19
25
|
export const emptyDebugInfo = (): DebugInfo => ({
|
|
20
26
|
slowQueries: new BoundArray(200),
|
package/src/effect/LiveStore.ts
CHANGED
|
@@ -1,92 +1,31 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { UnexpectedError } from '@livestore/common'
|
|
2
2
|
import type { LiveStoreSchema } from '@livestore/common/schema'
|
|
3
3
|
import type { Cause, OtelTracer, Scope } from '@livestore/utils/effect'
|
|
4
|
-
import {
|
|
5
|
-
import type * as otel from '@opentelemetry/api'
|
|
6
|
-
import type { GraphQLSchema } from 'graphql'
|
|
4
|
+
import { Deferred, Duration, Effect, Layer, pipe } from '@livestore/utils/effect'
|
|
7
5
|
|
|
8
|
-
import type {
|
|
9
|
-
import { createStore } from '../store/create-store.js'
|
|
10
|
-
import type { Store } from '../store/store.js'
|
|
11
|
-
import type { BaseGraphQLContext, LiveStoreContextRunning as LiveStoreContextRunning_ } from '../store/store-types.js'
|
|
6
|
+
import type { LiveStoreContextProps } from '../store/create-store.js'
|
|
7
|
+
import { createStore, DeferredStoreContext, LiveStoreContextRunning } from '../store/create-store.js'
|
|
12
8
|
|
|
13
|
-
export
|
|
14
|
-
LiveStoreContextRunning,
|
|
15
|
-
LiveStoreContextRunning_
|
|
16
|
-
>() {
|
|
17
|
-
static fromDeferred = Effect.gen(function* () {
|
|
18
|
-
const deferred = yield* DeferredStoreContext
|
|
19
|
-
const ctx = yield* deferred
|
|
20
|
-
return Layer.succeed(LiveStoreContextRunning, ctx)
|
|
21
|
-
}).pipe(Layer.unwrapScoped)
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export class DeferredStoreContext extends Context.Tag('@livestore/livestore/effect/DeferredStoreContext')<
|
|
25
|
-
DeferredStoreContext,
|
|
26
|
-
Deferred.Deferred<LiveStoreContextRunning['Type'], UnexpectedError>
|
|
27
|
-
>() {}
|
|
28
|
-
|
|
29
|
-
export type LiveStoreContextProps<GraphQLContext extends BaseGraphQLContext> = {
|
|
30
|
-
schema: LiveStoreSchema
|
|
31
|
-
/**
|
|
32
|
-
* The `storeId` can be used to isolate multiple stores from each other.
|
|
33
|
-
* So it can be useful for multi-tenancy scenarios.
|
|
34
|
-
*
|
|
35
|
-
* The `storeId` is also used for persistence.
|
|
36
|
-
*
|
|
37
|
-
* @default 'default'
|
|
38
|
-
*/
|
|
39
|
-
storeId?: string
|
|
40
|
-
graphQLOptions?: {
|
|
41
|
-
schema: Effect.Effect<GraphQLSchema, never, OtelTracer.OtelTracer>
|
|
42
|
-
makeContext: (db: SqliteDbWrapper, tracer: otel.Tracer, sessionId: string) => GraphQLContext
|
|
43
|
-
}
|
|
44
|
-
boot?: (
|
|
45
|
-
store: Store<GraphQLContext, LiveStoreSchema>,
|
|
46
|
-
) => Effect.Effect<void, unknown, OtelTracer.OtelTracer | LiveStoreContextRunning>
|
|
47
|
-
adapter: Adapter
|
|
48
|
-
disableDevtools?: boolean
|
|
49
|
-
onBootStatus?: (status: BootStatus) => void
|
|
50
|
-
batchUpdates: (run: () => void) => void
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export const LiveStoreContextLayer = <GraphQLContext extends BaseGraphQLContext>(
|
|
54
|
-
props: LiveStoreContextProps<GraphQLContext>,
|
|
55
|
-
): Layer.Layer<LiveStoreContextRunning, UnexpectedError | Cause.TimeoutException, OtelTracer.OtelTracer> =>
|
|
56
|
-
Layer.scoped(LiveStoreContextRunning, makeLiveStoreContext(props)).pipe(
|
|
57
|
-
Layer.withSpan('LiveStore'),
|
|
58
|
-
Layer.provide(LiveStoreContextDeferred),
|
|
59
|
-
)
|
|
60
|
-
|
|
61
|
-
export const LiveStoreContextDeferred = Layer.effect(
|
|
62
|
-
DeferredStoreContext,
|
|
63
|
-
Deferred.make<LiveStoreContextRunning['Type'], UnexpectedError>(),
|
|
64
|
-
)
|
|
65
|
-
|
|
66
|
-
export const makeLiveStoreContext = <GraphQLContext extends BaseGraphQLContext>({
|
|
9
|
+
export const makeLiveStoreContext = <TSchema extends LiveStoreSchema, TContext = {}>({
|
|
67
10
|
schema,
|
|
68
11
|
storeId = 'default',
|
|
69
|
-
|
|
12
|
+
context,
|
|
70
13
|
boot,
|
|
71
14
|
adapter,
|
|
72
15
|
disableDevtools,
|
|
73
16
|
onBootStatus,
|
|
74
17
|
batchUpdates,
|
|
75
|
-
}: LiveStoreContextProps<
|
|
18
|
+
}: LiveStoreContextProps<TSchema, TContext>): Effect.Effect<
|
|
76
19
|
LiveStoreContextRunning['Type'],
|
|
77
20
|
UnexpectedError | Cause.TimeoutException,
|
|
78
21
|
DeferredStoreContext | Scope.Scope | OtelTracer.OtelTracer
|
|
79
22
|
> =>
|
|
80
23
|
pipe(
|
|
81
24
|
Effect.gen(function* () {
|
|
82
|
-
const graphQLOptions = yield* graphQLOptions_
|
|
83
|
-
? Effect.all({ schema: graphQLOptions_.schema, makeContext: Effect.succeed(graphQLOptions_.makeContext) })
|
|
84
|
-
: Effect.succeed(undefined)
|
|
85
|
-
|
|
86
25
|
const store = yield* createStore({
|
|
87
26
|
schema,
|
|
88
27
|
storeId,
|
|
89
|
-
|
|
28
|
+
context,
|
|
90
29
|
boot,
|
|
91
30
|
adapter,
|
|
92
31
|
disableDevtools,
|
|
@@ -100,7 +39,7 @@ export const makeLiveStoreContext = <GraphQLContext extends BaseGraphQLContext>(
|
|
|
100
39
|
}
|
|
101
40
|
globalThis.__debugLiveStore[storeId] = store
|
|
102
41
|
|
|
103
|
-
return { stage: 'running', store }
|
|
42
|
+
return { stage: 'running', store } as any as LiveStoreContextRunning['Type']
|
|
104
43
|
}),
|
|
105
44
|
Effect.tapErrorCause((cause) => Effect.flatMap(DeferredStoreContext, (def) => Deferred.failCause(def, cause))),
|
|
106
45
|
Effect.tap((storeCtx) => Effect.flatMap(DeferredStoreContext, (def) => Deferred.succeed(def, storeCtx))),
|
|
@@ -109,3 +48,16 @@ export const makeLiveStoreContext = <GraphQLContext extends BaseGraphQLContext>(
|
|
|
109
48
|
Effect.timeout(Duration.minutes(5)),
|
|
110
49
|
Effect.withSpan('@livestore/livestore/effect:makeLiveStoreContext'),
|
|
111
50
|
)
|
|
51
|
+
|
|
52
|
+
export const LiveStoreContextLayer = <TSchema extends LiveStoreSchema, TContext = {}>(
|
|
53
|
+
props: LiveStoreContextProps<TSchema, TContext>,
|
|
54
|
+
): Layer.Layer<LiveStoreContextRunning, UnexpectedError | Cause.TimeoutException, OtelTracer.OtelTracer> =>
|
|
55
|
+
Layer.scoped(LiveStoreContextRunning, makeLiveStoreContext(props)).pipe(
|
|
56
|
+
Layer.withSpan('LiveStore'),
|
|
57
|
+
Layer.provide(LiveStoreContextDeferred),
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
export const LiveStoreContextDeferred = Layer.effect(
|
|
61
|
+
DeferredStoreContext,
|
|
62
|
+
Deferred.make<LiveStoreContextRunning['Type'], UnexpectedError>(),
|
|
63
|
+
)
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
+
export { LiveStoreContextLayer, LiveStoreContextDeferred } from './LiveStore.js'
|
|
1
2
|
export {
|
|
2
|
-
LiveStoreContextLayer,
|
|
3
3
|
LiveStoreContextRunning as LiveStoreContext,
|
|
4
4
|
LiveStoreContextRunning,
|
|
5
|
-
LiveStoreContextDeferred,
|
|
6
5
|
DeferredStoreContext,
|
|
7
6
|
type LiveStoreContextProps,
|
|
8
|
-
} from '
|
|
7
|
+
} from '../store/create-store.js'
|
|
@@ -15,7 +15,7 @@ export const makeReactivityGraph = (): ReactivityGraph =>
|
|
|
15
15
|
export type ReactivityGraphContext = {
|
|
16
16
|
store: Store
|
|
17
17
|
/** Maps from the hash of the query definition to the RcRef of the query */
|
|
18
|
-
defRcMap: Map<string, RcRef<
|
|
18
|
+
defRcMap: Map<string, RcRef<LiveQuery.Any | ILiveQueryRef<any>>>
|
|
19
19
|
/** Back-reference to the reactivity graph for convenience */
|
|
20
20
|
reactivityGraph: WeakRef<ReactivityGraph>
|
|
21
21
|
otelTracer: otel.Tracer
|
|
@@ -23,7 +23,7 @@ export type ReactivityGraphContext = {
|
|
|
23
23
|
effectsWrapper: (run: () => void) => void
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
export type GetResult<TQuery extends
|
|
26
|
+
export type GetResult<TQuery extends LiveQueryDef.Any | LiveQuery.Any> =
|
|
27
27
|
TQuery extends LiveQuery<infer TResult, infer _1>
|
|
28
28
|
? TResult
|
|
29
29
|
: TQuery extends LiveQueryDef<infer TResult, infer _1>
|
|
@@ -32,9 +32,6 @@ export type GetResult<TQuery extends LiveQueryDefAny | LiveQueryAny> =
|
|
|
32
32
|
|
|
33
33
|
let queryIdCounter = 0
|
|
34
34
|
|
|
35
|
-
export type LiveQueryAny = LiveQuery<any, QueryInfo>
|
|
36
|
-
export type LiveQueryDefAny = LiveQueryDef<any, any>
|
|
37
|
-
|
|
38
35
|
export interface ILiveQueryRefDef<T> {
|
|
39
36
|
_tag: 'live-ref-def'
|
|
40
37
|
defaultValue: T
|
|
@@ -77,6 +74,10 @@ export interface LiveQueryDef<TResult, TQueryInfo extends QueryInfo = QueryInfo.
|
|
|
77
74
|
queryInfo: TQueryInfo
|
|
78
75
|
}
|
|
79
76
|
|
|
77
|
+
export namespace LiveQueryDef {
|
|
78
|
+
export type Any = LiveQueryDef<any, any>
|
|
79
|
+
}
|
|
80
|
+
|
|
80
81
|
/**
|
|
81
82
|
* A LiveQuery is stateful
|
|
82
83
|
*/
|
|
@@ -115,6 +116,10 @@ export interface LiveQuery<TResult, TQueryInfo extends QueryInfo = QueryInfo.Non
|
|
|
115
116
|
executionTimes: number[]
|
|
116
117
|
}
|
|
117
118
|
|
|
119
|
+
export namespace LiveQuery {
|
|
120
|
+
export type Any = LiveQuery<any, any>
|
|
121
|
+
}
|
|
122
|
+
|
|
118
123
|
export abstract class LiveStoreQueryBase<TResult, TQueryInfo extends QueryInfo>
|
|
119
124
|
implements LiveQuery<TResult, TQueryInfo>
|
|
120
125
|
{
|
|
@@ -170,7 +175,7 @@ export type GetAtomResult = <T>(
|
|
|
170
175
|
debugRefreshReason?: RefreshReason | undefined,
|
|
171
176
|
) => T
|
|
172
177
|
|
|
173
|
-
export type DependencyQueriesRef = Set<RcRef<
|
|
178
|
+
export type DependencyQueriesRef = Set<RcRef<LiveQuery.Any | ILiveQueryRef<any>>>
|
|
174
179
|
|
|
175
180
|
export const makeGetAtomResult = (
|
|
176
181
|
get: RG.GetAtom,
|
|
@@ -201,7 +206,7 @@ export const makeGetAtomResult = (
|
|
|
201
206
|
return getAtom
|
|
202
207
|
}
|
|
203
208
|
|
|
204
|
-
export const withRCMap = <T extends
|
|
209
|
+
export const withRCMap = <T extends LiveQuery.Any | ILiveQueryRef<any>>(
|
|
205
210
|
id: string,
|
|
206
211
|
make: (ctx: ReactivityGraphContext, otelContext?: otel.Context) => T,
|
|
207
212
|
): ((ctx: ReactivityGraphContext, otelContext?: otel.Context) => RcRef<T>) => {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { QueryInfo } from '@livestore/common'
|
|
2
|
+
import { getDurationMsFromSpan } from '@livestore/common'
|
|
2
3
|
import * as otel from '@opentelemetry/api'
|
|
3
4
|
|
|
4
5
|
import type { Thunk } from '../reactive.js'
|
|
5
6
|
import type { RefreshReason } from '../store/store-types.js'
|
|
6
7
|
import { isValidFunctionString } from '../utils/function-string.js'
|
|
7
|
-
import { getDurationMsFromSpan } from '../utils/otel.js'
|
|
8
8
|
import type { DepKey, GetAtomResult, LiveQueryDef, ReactivityGraph, ReactivityGraphContext } from './base-class.js'
|
|
9
9
|
import { depsToString, LiveStoreQueryBase, makeGetAtomResult, withRCMap } from './base-class.js'
|
|
10
10
|
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
+
import { sql } from '@livestore/common'
|
|
2
|
+
import { rawSqlMutation } from '@livestore/common/schema'
|
|
1
3
|
import { Effect, ReadonlyRecord, Schema } from '@livestore/utils/effect'
|
|
2
4
|
import { Vitest } from '@livestore/utils/node-vitest'
|
|
3
5
|
import * as otel from '@opentelemetry/api'
|
|
4
6
|
import { BasicTracerProvider, InMemorySpanExporter, SimpleSpanProcessor } from '@opentelemetry/sdk-trace-base'
|
|
5
7
|
import { expect } from 'vitest'
|
|
6
8
|
|
|
7
|
-
import { computed, queryDb, rawSqlMutation, sql } from '../index.js'
|
|
8
9
|
import * as RG from '../reactive.js'
|
|
9
10
|
import { makeTodoMvc, tables } from '../utils/tests/fixture.js'
|
|
10
11
|
import { getSimplifiedRootSpan } from '../utils/tests/otel.js'
|
|
12
|
+
import { computed } from './computed.js'
|
|
13
|
+
import { queryDb } from './db-query.js'
|
|
11
14
|
|
|
12
15
|
/*
|
|
13
16
|
TODO write tests for:
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Bindable, QueryBuilder, QueryInfo } from '@livestore/common'
|
|
2
2
|
import {
|
|
3
|
+
getDurationMsFromSpan,
|
|
3
4
|
getResultSchema,
|
|
4
5
|
isQueryBuilder,
|
|
5
6
|
prepareBindValues,
|
|
@@ -16,7 +17,6 @@ import { isThunk, NOT_REFRESHED_YET } from '../reactive.js'
|
|
|
16
17
|
import { makeExecBeforeFirstRun, rowQueryLabel } from '../row-query-utils.js'
|
|
17
18
|
import type { RefreshReason } from '../store/store-types.js'
|
|
18
19
|
import { isValidFunctionString } from '../utils/function-string.js'
|
|
19
|
-
import { getDurationMsFromSpan } from '../utils/otel.js'
|
|
20
20
|
import type { DepKey, GetAtomResult, LiveQueryDef, ReactivityGraph, ReactivityGraphContext } from './base-class.js'
|
|
21
21
|
import { depsToString, LiveStoreQueryBase, makeGetAtomResult, withRCMap } from './base-class.js'
|
|
22
22
|
|
package/src/mod.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export { Store } from './store/store.js'
|
|
2
|
+
export { createStore, createStorePromise, type CreateStoreOptions } from './store/create-store.js'
|
|
3
|
+
export type { QueryDebugInfo, RefreshReason, OtelOptions } from './store/store-types.js'
|
|
4
|
+
|
|
5
|
+
export { type LiveStoreContext, type ShutdownDeferred, type LiveStoreContextRunning } from './store/store-types.js'
|
|
6
|
+
|
|
7
|
+
export { SqliteDbWrapper, emptyDebugInfo } from './SqliteDbWrapper.js'
|
|
8
|
+
|
|
9
|
+
export { deriveColQuery } from './row-query-utils.js'
|
|
10
|
+
|
|
11
|
+
export { queryDb, computed, makeRef, type LiveQuery, type LiveQueryDef } from './live-queries/mod.js'
|
|
12
|
+
|
|
13
|
+
export * from '@livestore/common/schema'
|
|
14
|
+
export {
|
|
15
|
+
sql,
|
|
16
|
+
SessionIdSymbol,
|
|
17
|
+
type BootStatus,
|
|
18
|
+
type SqliteDb,
|
|
19
|
+
type DebugInfo,
|
|
20
|
+
type MutableDebugInfo,
|
|
21
|
+
prepareBindValues,
|
|
22
|
+
type Bindable,
|
|
23
|
+
type PreparedBindValues,
|
|
24
|
+
type QueryBuilderAst,
|
|
25
|
+
type QueryBuilder,
|
|
26
|
+
type RowQuery,
|
|
27
|
+
StoreInterrupted,
|
|
28
|
+
IntentionalShutdownCause,
|
|
29
|
+
provideOtel,
|
|
30
|
+
} from '@livestore/common'
|
|
31
|
+
|
|
32
|
+
export { deepEqual } from '@livestore/utils'
|
|
33
|
+
export { nanoid } from '@livestore/utils/nanoid'
|
|
34
|
+
|
|
35
|
+
export * from './utils/stack-info.js'
|
|
36
|
+
|
|
37
|
+
export type { ClientSession, Adapter, PreparedStatement } from '@livestore/common'
|
|
@@ -11,6 +11,7 @@ import type { EventId, LiveStoreSchema, MutationEvent } from '@livestore/common/
|
|
|
11
11
|
import { LS_DEV } from '@livestore/utils'
|
|
12
12
|
import type { Cause } from '@livestore/utils/effect'
|
|
13
13
|
import {
|
|
14
|
+
Context,
|
|
14
15
|
Deferred,
|
|
15
16
|
Effect,
|
|
16
17
|
Exit,
|
|
@@ -28,22 +29,63 @@ import {
|
|
|
28
29
|
import { nanoid } from '@livestore/utils/nanoid'
|
|
29
30
|
import * as otel from '@opentelemetry/api'
|
|
30
31
|
|
|
31
|
-
import { LiveStoreContextRunning } from '../effect/index.js'
|
|
32
32
|
import { connectDevtoolsToStore } from './devtools.js'
|
|
33
33
|
import { Store } from './store.js'
|
|
34
|
-
import type {
|
|
34
|
+
import type {
|
|
35
|
+
LiveStoreContextRunning as LiveStoreContextRunning_,
|
|
36
|
+
OtelOptions,
|
|
37
|
+
ShutdownDeferred,
|
|
38
|
+
} from './store-types.js'
|
|
35
39
|
|
|
36
40
|
export const DEFAULT_PARAMS = {
|
|
37
41
|
leaderPushBatchSize: 1,
|
|
38
42
|
}
|
|
39
43
|
|
|
40
|
-
export
|
|
44
|
+
export class LiveStoreContextRunning extends Context.Tag('@livestore/livestore/effect/LiveStoreContextRunning')<
|
|
45
|
+
LiveStoreContextRunning,
|
|
46
|
+
LiveStoreContextRunning_
|
|
47
|
+
>() {
|
|
48
|
+
static fromDeferred = Effect.gen(function* () {
|
|
49
|
+
const deferred = yield* DeferredStoreContext
|
|
50
|
+
const ctx = yield* deferred
|
|
51
|
+
return Layer.succeed(LiveStoreContextRunning, ctx)
|
|
52
|
+
}).pipe(Layer.unwrapScoped)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export class DeferredStoreContext extends Context.Tag('@livestore/livestore/effect/DeferredStoreContext')<
|
|
56
|
+
DeferredStoreContext,
|
|
57
|
+
Deferred.Deferred<LiveStoreContextRunning['Type'], UnexpectedError>
|
|
58
|
+
>() {}
|
|
59
|
+
|
|
60
|
+
export type LiveStoreContextProps<TSchema extends LiveStoreSchema, TContext = {}> = {
|
|
61
|
+
schema: TSchema
|
|
62
|
+
/**
|
|
63
|
+
* The `storeId` can be used to isolate multiple stores from each other.
|
|
64
|
+
* So it can be useful for multi-tenancy scenarios.
|
|
65
|
+
*
|
|
66
|
+
* The `storeId` is also used for persistence.
|
|
67
|
+
*
|
|
68
|
+
* @default 'default'
|
|
69
|
+
*/
|
|
70
|
+
storeId?: string
|
|
71
|
+
/** Can be useful for custom live query implementations (e.g. see `@livestore/graphql`) */
|
|
72
|
+
context?: TContext
|
|
73
|
+
boot?: (
|
|
74
|
+
store: Store<TSchema, TContext>,
|
|
75
|
+
) => Effect.Effect<void, unknown, OtelTracer.OtelTracer | LiveStoreContextRunning>
|
|
76
|
+
adapter: Adapter
|
|
77
|
+
disableDevtools?: boolean
|
|
78
|
+
onBootStatus?: (status: BootStatus) => void
|
|
79
|
+
batchUpdates: (run: () => void) => void
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export interface CreateStoreOptions<TSchema extends LiveStoreSchema, TContext = {}> {
|
|
41
83
|
schema: TSchema
|
|
42
84
|
adapter: Adapter
|
|
43
85
|
storeId: string
|
|
44
|
-
|
|
86
|
+
context?: TContext
|
|
45
87
|
boot?: (
|
|
46
|
-
store: Store<
|
|
88
|
+
store: Store<TSchema, TContext>,
|
|
47
89
|
ctx: {
|
|
48
90
|
migrationsReport: MigrationsReport
|
|
49
91
|
parentSpan: otel.Span
|
|
@@ -62,17 +104,14 @@ export interface CreateStoreOptions<TGraphQLContext extends BaseGraphQLContext,
|
|
|
62
104
|
}
|
|
63
105
|
|
|
64
106
|
/** Create a new LiveStore Store */
|
|
65
|
-
export const createStorePromise = async <
|
|
66
|
-
TGraphQLContext extends BaseGraphQLContext,
|
|
67
|
-
TSchema extends LiveStoreSchema = LiveStoreSchema,
|
|
68
|
-
>({
|
|
107
|
+
export const createStorePromise = async <TSchema extends LiveStoreSchema = LiveStoreSchema, TContext = {}>({
|
|
69
108
|
signal,
|
|
70
109
|
otelOptions,
|
|
71
110
|
...options
|
|
72
|
-
}: CreateStoreOptions<
|
|
111
|
+
}: CreateStoreOptions<TSchema, TContext> & {
|
|
73
112
|
signal?: AbortSignal
|
|
74
113
|
otelOptions?: Partial<OtelOptions>
|
|
75
|
-
}): Promise<Store<
|
|
114
|
+
}): Promise<Store<TSchema, TContext>> =>
|
|
76
115
|
Effect.gen(function* () {
|
|
77
116
|
const scope = yield* Scope.make()
|
|
78
117
|
const runtime = yield* Effect.runtime()
|
|
@@ -96,14 +135,11 @@ export const createStorePromise = async <
|
|
|
96
135
|
Effect.runPromise,
|
|
97
136
|
)
|
|
98
137
|
|
|
99
|
-
export const createStore = <
|
|
100
|
-
TGraphQLContext extends BaseGraphQLContext,
|
|
101
|
-
TSchema extends LiveStoreSchema = LiveStoreSchema,
|
|
102
|
-
>({
|
|
138
|
+
export const createStore = <TSchema extends LiveStoreSchema = LiveStoreSchema, TContext = {}>({
|
|
103
139
|
schema,
|
|
104
140
|
adapter,
|
|
105
141
|
storeId,
|
|
106
|
-
|
|
142
|
+
context = {} as TContext,
|
|
107
143
|
boot,
|
|
108
144
|
batchUpdates,
|
|
109
145
|
disableDevtools,
|
|
@@ -111,8 +147,8 @@ export const createStore = <
|
|
|
111
147
|
shutdownDeferred,
|
|
112
148
|
params,
|
|
113
149
|
debug,
|
|
114
|
-
}: CreateStoreOptions<
|
|
115
|
-
Store<
|
|
150
|
+
}: CreateStoreOptions<TSchema, TContext>): Effect.Effect<
|
|
151
|
+
Store<TSchema, TContext>,
|
|
116
152
|
UnexpectedError,
|
|
117
153
|
Scope.Scope | OtelTracer.OtelTracer
|
|
118
154
|
> =>
|
|
@@ -199,10 +235,10 @@ export const createStore = <
|
|
|
199
235
|
// TODO fill up with unsynced mutation events from the client session
|
|
200
236
|
const unsyncedMutationEvents = MutableHashMap.empty<EventId.EventId, MutationEvent.ForSchema<TSchema>>()
|
|
201
237
|
|
|
202
|
-
const store = new Store<
|
|
238
|
+
const store = new Store<TSchema, TContext>({
|
|
203
239
|
clientSession,
|
|
204
240
|
schema,
|
|
205
|
-
|
|
241
|
+
context,
|
|
206
242
|
otelOptions: { tracer: otelTracer, rootSpanContext: otelRootSpanContext },
|
|
207
243
|
disableDevtools,
|
|
208
244
|
unsyncedMutationEvents,
|
package/src/store/store-types.ts
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import type { ClientSession, IntentionalShutdownCause, UnexpectedError } from '@livestore/common'
|
|
1
|
+
import type { ClientSession, IntentionalShutdownCause, StoreInterrupted, UnexpectedError } from '@livestore/common'
|
|
2
2
|
import type { EventId, LiveStoreSchema, MutationEvent } from '@livestore/common/schema'
|
|
3
3
|
import type { Deferred, MutableHashMap, Runtime, Scope } from '@livestore/utils/effect'
|
|
4
|
-
import { Schema } from '@livestore/utils/effect'
|
|
5
4
|
import type * as otel from '@opentelemetry/api'
|
|
6
|
-
import type { GraphQLSchema } from 'graphql'
|
|
7
5
|
|
|
8
6
|
import type { DebugRefreshReasonBase } from '../reactive.js'
|
|
9
|
-
import type { SqliteDbWrapper } from '../SqliteDbWrapper.js'
|
|
10
7
|
import type { StackInfo } from '../utils/stack-info.js'
|
|
11
8
|
import type { Store } from './store.js'
|
|
12
9
|
|
|
@@ -18,47 +15,26 @@ export type LiveStoreContext =
|
|
|
18
15
|
}
|
|
19
16
|
| {
|
|
20
17
|
stage: 'shutdown'
|
|
21
|
-
cause: IntentionalShutdownCause |
|
|
18
|
+
cause: IntentionalShutdownCause | StoreInterrupted
|
|
22
19
|
}
|
|
23
20
|
|
|
24
|
-
export
|
|
25
|
-
export class StoreInterrupted extends Schema.TaggedError<StoreInterrupted>()('LiveStore.StoreInterrupted', {}) {}
|
|
26
|
-
|
|
27
|
-
export type ShutdownDeferred = Deferred.Deferred<
|
|
28
|
-
void,
|
|
29
|
-
UnexpectedError | IntentionalShutdownCause | StoreInterrupted | StoreAbort
|
|
30
|
-
>
|
|
21
|
+
export type ShutdownDeferred = Deferred.Deferred<void, UnexpectedError | IntentionalShutdownCause | StoreInterrupted>
|
|
31
22
|
|
|
32
23
|
export type LiveStoreContextRunning = {
|
|
33
24
|
stage: 'running'
|
|
34
25
|
store: Store
|
|
35
26
|
}
|
|
36
27
|
|
|
37
|
-
export type BaseGraphQLContext = {
|
|
38
|
-
queriedTables: Set<string>
|
|
39
|
-
/** Needed by Pothos Otel plugin for resolver tracing to work */
|
|
40
|
-
otelContext?: otel.Context
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export type GraphQLOptions<TContext> = {
|
|
44
|
-
schema: GraphQLSchema
|
|
45
|
-
makeContext: (db: SqliteDbWrapper, tracer: otel.Tracer, sessionId: string) => TContext
|
|
46
|
-
}
|
|
47
|
-
|
|
48
28
|
export type OtelOptions = {
|
|
49
29
|
tracer: otel.Tracer
|
|
50
30
|
rootSpanContext: otel.Context
|
|
51
31
|
}
|
|
52
32
|
|
|
53
|
-
export type StoreOptions<
|
|
54
|
-
TGraphQLContext extends BaseGraphQLContext,
|
|
55
|
-
TSchema extends LiveStoreSchema = LiveStoreSchema,
|
|
56
|
-
> = {
|
|
33
|
+
export type StoreOptions<TSchema extends LiveStoreSchema = LiveStoreSchema, TContext = {}> = {
|
|
57
34
|
clientSession: ClientSession
|
|
58
35
|
schema: TSchema
|
|
59
36
|
storeId: string
|
|
60
|
-
|
|
61
|
-
graphQLOptions?: GraphQLOptions<TGraphQLContext>
|
|
37
|
+
context: TContext
|
|
62
38
|
otelOptions: OtelOptions
|
|
63
39
|
disableDevtools?: boolean
|
|
64
40
|
lifetimeScope: Scope.Scope
|
|
@@ -93,7 +69,7 @@ export type RefreshReason =
|
|
|
93
69
|
| { _tag: 'manual'; label?: string }
|
|
94
70
|
|
|
95
71
|
export type QueryDebugInfo = {
|
|
96
|
-
_tag:
|
|
72
|
+
_tag: string
|
|
97
73
|
label: string
|
|
98
74
|
query: string
|
|
99
75
|
durationMs: number
|