@livestore/livestore 0.4.0 → 0.5.0-dev.1
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 +1 -1
- package/dist/SqliteDbWrapper.d.ts.map +1 -1
- package/dist/SqliteDbWrapper.js +9 -7
- package/dist/SqliteDbWrapper.js.map +1 -1
- package/dist/SqliteDbWrapper.test.js +22 -5
- package/dist/SqliteDbWrapper.test.js.map +1 -1
- package/dist/effect/LiveStore.d.ts +68 -16
- package/dist/effect/LiveStore.d.ts.map +1 -1
- package/dist/effect/LiveStore.js +22 -20
- package/dist/effect/LiveStore.js.map +1 -1
- package/dist/effect/LiveStore.test.js +7 -8
- package/dist/effect/LiveStore.test.js.map +1 -1
- package/dist/effect/mod.js +2 -2
- package/dist/internal/mod.js +2 -2
- package/dist/live-queries/base-class.d.ts +20 -3
- package/dist/live-queries/base-class.d.ts.map +1 -1
- package/dist/live-queries/base-class.js +30 -4
- package/dist/live-queries/base-class.js.map +1 -1
- package/dist/live-queries/client-document-get-query.d.ts.map +1 -1
- package/dist/live-queries/client-document-get-query.js +1 -1
- package/dist/live-queries/computed.d.ts +1 -1
- package/dist/live-queries/computed.d.ts.map +1 -1
- package/dist/live-queries/computed.js +5 -5
- package/dist/live-queries/computed.js.map +1 -1
- package/dist/live-queries/db-query.d.ts +3 -3
- package/dist/live-queries/db-query.d.ts.map +1 -1
- package/dist/live-queries/db-query.js +30 -21
- package/dist/live-queries/db-query.js.map +1 -1
- package/dist/live-queries/db-query.test.js +15 -15
- package/dist/live-queries/db-query.test.js.map +1 -1
- package/dist/live-queries/mod.js +4 -4
- package/dist/live-queries/signal.d.ts +1 -1
- package/dist/live-queries/signal.d.ts.map +1 -1
- package/dist/live-queries/signal.js +2 -2
- package/dist/live-queries/signal.js.map +1 -1
- package/dist/live-queries/signal.test.js +5 -5
- package/dist/live-queries/signal.test.js.map +1 -1
- package/dist/mod.js +8 -8
- package/dist/reactive.d.ts +1 -1
- package/dist/reactive.d.ts.map +1 -1
- package/dist/reactive.js +20 -1
- package/dist/reactive.js.map +1 -1
- package/dist/reactive.test.js +1 -1
- package/dist/store/StoreRegistry.d.ts +12 -12
- package/dist/store/StoreRegistry.d.ts.map +1 -1
- package/dist/store/StoreRegistry.js +25 -25
- package/dist/store/StoreRegistry.js.map +1 -1
- package/dist/store/StoreRegistry.test.js +65 -62
- package/dist/store/StoreRegistry.test.js.map +1 -1
- package/dist/store/create-store.d.ts +27 -16
- package/dist/store/create-store.d.ts.map +1 -1
- package/dist/store/create-store.js +55 -27
- package/dist/store/create-store.js.map +1 -1
- package/dist/store/create-store.test.d.ts +2 -0
- package/dist/store/create-store.test.d.ts.map +1 -0
- package/dist/store/create-store.test.js +28 -0
- package/dist/store/create-store.test.js.map +1 -0
- package/dist/store/devtools.d.ts +1 -2
- package/dist/store/devtools.d.ts.map +1 -1
- package/dist/store/devtools.js +6 -5
- package/dist/store/devtools.js.map +1 -1
- package/dist/store/store-commit.test.d.ts +2 -0
- package/dist/store/store-commit.test.d.ts.map +1 -0
- package/dist/store/store-commit.test.js +85 -0
- package/dist/store/store-commit.test.js.map +1 -0
- package/dist/store/store-eventstream.test.js +6 -6
- package/dist/store/store-eventstream.test.js.map +1 -1
- package/dist/store/store-types.d.ts +10 -28
- package/dist/store/store-types.d.ts.map +1 -1
- package/dist/store/store-types.js +2 -38
- package/dist/store/store-types.js.map +1 -1
- package/dist/store/store-types.test.js +4 -4
- package/dist/store/store.d.ts +15 -16
- package/dist/store/store.d.ts.map +1 -1
- package/dist/store/store.js +149 -91
- 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/dev.js +1 -1
- package/dist/utils/dev.js.map +1 -1
- package/dist/utils/function-string.d.ts +3 -3
- package/dist/utils/function-string.d.ts.map +1 -1
- package/dist/utils/stack-info.d.ts.map +1 -1
- package/dist/utils/stack-info.js +2 -1
- package/dist/utils/stack-info.js.map +1 -1
- package/dist/utils/stack-info.test.js +1 -1
- package/dist/utils/tests/fixture.d.ts +26 -34
- package/dist/utils/tests/fixture.d.ts.map +1 -1
- package/dist/utils/tests/fixture.js.map +1 -1
- package/dist/utils/tests/mod.js +3 -3
- package/dist/utils/tests/otel.d.ts +6 -6
- package/dist/utils/tests/otel.d.ts.map +1 -1
- package/package.json +40 -50
- package/src/SqliteDbWrapper.test.ts +25 -3
- package/src/SqliteDbWrapper.ts +13 -10
- package/src/effect/LiveStore.test.ts +16 -16
- package/src/effect/LiveStore.ts +83 -51
- package/src/live-queries/__snapshots__/db-query.test.ts.snap +303 -97
- package/src/live-queries/base-class.ts +39 -7
- package/src/live-queries/computed.ts +5 -5
- package/src/live-queries/db-query.test.ts +9 -9
- package/src/live-queries/db-query.ts +42 -30
- package/src/live-queries/signal.test.ts +2 -2
- package/src/live-queries/signal.ts +3 -3
- package/src/reactive.ts +45 -35
- package/src/store/StoreRegistry.test.ts +62 -59
- package/src/store/StoreRegistry.ts +49 -38
- package/src/store/create-store.test.ts +35 -0
- package/src/store/create-store.ts +110 -55
- package/src/store/devtools.ts +283 -283
- package/src/store/store-commit.test.ts +137 -0
- package/src/store/store-eventstream.test.ts +16 -7
- package/src/store/store-types.test.ts +1 -1
- package/src/store/store-types.ts +10 -56
- package/src/store/store.ts +184 -110
- package/src/utils/dev.ts +1 -1
- package/src/utils/stack-info.ts +4 -1
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { expect } from 'vitest'
|
|
2
|
+
|
|
3
|
+
import { Vitest } from '@livestore/utils-dev/node-vitest'
|
|
4
|
+
import { Effect } from '@livestore/utils/effect'
|
|
5
|
+
|
|
6
|
+
import { events, makeTodoMvc, tables } from '../utils/tests/fixture.ts'
|
|
7
|
+
|
|
8
|
+
Vitest.describe('Store commit API', () => {
|
|
9
|
+
Vitest.live('should materialize events returned by the commit callback', () =>
|
|
10
|
+
Effect.gen(function* () {
|
|
11
|
+
const store = yield* makeTodoMvc()
|
|
12
|
+
const firstTodo = { id: '1', text: 'Make coffee', completed: false }
|
|
13
|
+
const secondTodo = { id: '2', text: 'Buy groceries', completed: false }
|
|
14
|
+
|
|
15
|
+
// Regression for https://github.com/livestorejs/livestore/issues/1611.
|
|
16
|
+
store.commit(() => {
|
|
17
|
+
expect(store.query(tables.todos)).toEqual([])
|
|
18
|
+
return [events.todoCreated(firstTodo), events.todoCreated(secondTodo)]
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
expect(store.query(tables.todos.orderBy('id', 'asc'))).toEqual([firstTodo, secondTodo])
|
|
22
|
+
}).pipe(Effect.scoped),
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
Vitest.live('should materialize a single callback event', () =>
|
|
26
|
+
Effect.gen(function* () {
|
|
27
|
+
const store = yield* makeTodoMvc()
|
|
28
|
+
const todo = { id: '1', text: 'Make coffee', completed: false }
|
|
29
|
+
const batch = [events.todoCreated(todo)] as const
|
|
30
|
+
|
|
31
|
+
store.commit(() => batch)
|
|
32
|
+
|
|
33
|
+
expect(store.query(tables.todos)).toEqual([todo])
|
|
34
|
+
}).pipe(Effect.scoped),
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
Vitest.live('should accept an empty callback', () =>
|
|
38
|
+
Effect.gen(function* () {
|
|
39
|
+
const store = yield* makeTodoMvc()
|
|
40
|
+
|
|
41
|
+
store.commit(() => [])
|
|
42
|
+
|
|
43
|
+
expect(store.query(tables.todos)).toEqual([])
|
|
44
|
+
}).pipe(Effect.scoped),
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
Vitest.live('should apply no events when the callback throws', () =>
|
|
48
|
+
Effect.gen(function* () {
|
|
49
|
+
const store = yield* makeTodoMvc()
|
|
50
|
+
const todo = { id: '1', text: 'Make coffee', completed: false }
|
|
51
|
+
const error = new Error('Callback failed')
|
|
52
|
+
|
|
53
|
+
expect(() =>
|
|
54
|
+
store.commit(() => {
|
|
55
|
+
throw error
|
|
56
|
+
}),
|
|
57
|
+
).toThrow(error)
|
|
58
|
+
|
|
59
|
+
expect(store.query(tables.todos)).toEqual([])
|
|
60
|
+
store.commit(events.todoCreated(todo))
|
|
61
|
+
expect(store.query(tables.todos)).toEqual([todo])
|
|
62
|
+
}).pipe(Effect.scoped),
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
Vitest.live('should commit multiple returned event types in order', () =>
|
|
66
|
+
Effect.gen(function* () {
|
|
67
|
+
const store = yield* makeTodoMvc()
|
|
68
|
+
const todo = { id: '1', text: 'Make coffee', completed: false }
|
|
69
|
+
|
|
70
|
+
store.commit(() => [events.todoCreated(todo), events.todoCompleted({ id: todo.id })])
|
|
71
|
+
|
|
72
|
+
expect(store.query(tables.todos)).toEqual([{ ...todo, completed: true }])
|
|
73
|
+
}).pipe(Effect.scoped),
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
for (const options of [{}, { label: 'Create todo' }]) {
|
|
77
|
+
Vitest.live(`should accept callback options ${JSON.stringify(options)}`, () =>
|
|
78
|
+
Effect.gen(function* () {
|
|
79
|
+
const store = yield* makeTodoMvc()
|
|
80
|
+
const todo = { id: '1', text: 'Make coffee', completed: false }
|
|
81
|
+
|
|
82
|
+
store.commit(options, () => [events.todoCreated(todo)])
|
|
83
|
+
|
|
84
|
+
expect(store.query(tables.todos)).toEqual([todo])
|
|
85
|
+
}).pipe(Effect.scoped),
|
|
86
|
+
)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
Vitest.live('should reject callback values that are not event arrays', () =>
|
|
90
|
+
Effect.gen(function* () {
|
|
91
|
+
const store = yield* makeTodoMvc()
|
|
92
|
+
|
|
93
|
+
expect(() => Reflect.apply(store.commit, store, [() => undefined])).toThrow(
|
|
94
|
+
'store.commit callback must synchronously return an array of events',
|
|
95
|
+
)
|
|
96
|
+
expect(() => Reflect.apply(store.commit, store, [() => Promise.resolve([])])).toThrow(
|
|
97
|
+
'store.commit callback must synchronously return an array of events',
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
expect(store.query(tables.todos)).toEqual([])
|
|
101
|
+
}).pipe(Effect.scoped),
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
Vitest.live('should reject non-array and asynchronous callbacks at the type level', () =>
|
|
105
|
+
Effect.gen(function* () {
|
|
106
|
+
const store = yield* makeTodoMvc()
|
|
107
|
+
|
|
108
|
+
// Keep invalid calls uninvoked so TypeScript checks the public overloads without executing them.
|
|
109
|
+
const assertRejectedCallbackTypes = () => {
|
|
110
|
+
// @ts-expect-error Commit callbacks must return an event array.
|
|
111
|
+
store.commit(() => {})
|
|
112
|
+
// @ts-expect-error Commit callbacks do not receive an event emitter.
|
|
113
|
+
store.commit((emit: () => void) => {
|
|
114
|
+
emit()
|
|
115
|
+
return []
|
|
116
|
+
})
|
|
117
|
+
// @ts-expect-error Commit callbacks must be synchronous.
|
|
118
|
+
store.commit(async () => [])
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
expect(assertRejectedCallbackTypes).toBeTypeOf('function')
|
|
122
|
+
}).pipe(Effect.scoped),
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
Vitest.live('should still accept direct events with options and no events', () =>
|
|
126
|
+
Effect.gen(function* () {
|
|
127
|
+
const store = yield* makeTodoMvc()
|
|
128
|
+
const todo = { id: '1', text: 'Make coffee', completed: false }
|
|
129
|
+
|
|
130
|
+
store.commit()
|
|
131
|
+
store.commit({ label: 'Empty commit' })
|
|
132
|
+
store.commit({ label: 'Create and complete' }, events.todoCreated(todo), events.todoCompleted({ id: todo.id }))
|
|
133
|
+
|
|
134
|
+
expect(store.query(tables.todos)).toEqual([{ ...todo, completed: true }])
|
|
135
|
+
}).pipe(Effect.scoped),
|
|
136
|
+
)
|
|
137
|
+
})
|
|
@@ -9,8 +9,17 @@ import type { ShutdownDeferred, Store } from '@livestore/livestore'
|
|
|
9
9
|
import { createStore, makeShutdownDeferred } from '@livestore/livestore'
|
|
10
10
|
import { omitUndefineds } from '@livestore/utils'
|
|
11
11
|
import { Vitest } from '@livestore/utils-dev/node-vitest'
|
|
12
|
-
import
|
|
13
|
-
|
|
12
|
+
import {
|
|
13
|
+
type OtelTracer,
|
|
14
|
+
type Scope,
|
|
15
|
+
Context,
|
|
16
|
+
Effect,
|
|
17
|
+
FetchHttpClient,
|
|
18
|
+
Layer,
|
|
19
|
+
Queue,
|
|
20
|
+
References,
|
|
21
|
+
Stream,
|
|
22
|
+
} from '@livestore/utils/effect'
|
|
14
23
|
import { nanoid } from '@livestore/utils/nanoid'
|
|
15
24
|
import { PlatformNode } from '@livestore/utils/node'
|
|
16
25
|
|
|
@@ -22,7 +31,7 @@ const withTestCtx = Vitest.makeWithTestCtx({
|
|
|
22
31
|
TestContextLive,
|
|
23
32
|
PlatformNode.NodeFileSystem.layer,
|
|
24
33
|
FetchHttpClient.layer,
|
|
25
|
-
|
|
34
|
+
Layer.succeed(References.MinimumLogLevel, 'Debug'),
|
|
26
35
|
),
|
|
27
36
|
})
|
|
28
37
|
|
|
@@ -32,7 +41,7 @@ const withTestCtx = Vitest.makeWithTestCtx({
|
|
|
32
41
|
* tests/package-common/src/leader-thread/stream-events.test.ts
|
|
33
42
|
*/
|
|
34
43
|
Vitest.describe('Store events API', () => {
|
|
35
|
-
Vitest.
|
|
44
|
+
Vitest.live('should resume when reconnected to sync backend', (test) =>
|
|
36
45
|
Effect.gen(function* () {
|
|
37
46
|
const { makeStore, mockSyncBackend } = yield* TestContext
|
|
38
47
|
const store = yield* makeStore()
|
|
@@ -69,7 +78,7 @@ Vitest.describe('Store events API', () => {
|
|
|
69
78
|
)
|
|
70
79
|
})
|
|
71
80
|
|
|
72
|
-
class TestContext extends Context.
|
|
81
|
+
class TestContext extends Context.Service<
|
|
73
82
|
TestContext,
|
|
74
83
|
{
|
|
75
84
|
makeStore: (args?: {
|
|
@@ -87,9 +96,9 @@ class TestContext extends Context.Tag('TestContext')<
|
|
|
87
96
|
mockSyncBackend: MockSyncBackend
|
|
88
97
|
shutdownDeferred: ShutdownDeferred
|
|
89
98
|
}
|
|
90
|
-
>() {}
|
|
99
|
+
>()('TestContext') {}
|
|
91
100
|
|
|
92
|
-
const TestContextLive = Layer.
|
|
101
|
+
const TestContextLive = Layer.effect(
|
|
93
102
|
TestContext,
|
|
94
103
|
Effect.gen(function* () {
|
|
95
104
|
const mockSyncBackend = yield* makeMockSyncBackend()
|
|
@@ -20,7 +20,7 @@ describe('isQueryable', () => {
|
|
|
20
20
|
it('identifies live query definitions', () => {
|
|
21
21
|
const def = queryDb({
|
|
22
22
|
query: 'select 1 as value',
|
|
23
|
-
schema: Schema.Array(Schema.Struct({ value: Schema.
|
|
23
|
+
schema: Schema.Array(Schema.Struct({ value: Schema.Finite })),
|
|
24
24
|
})
|
|
25
25
|
|
|
26
26
|
expect(isQueryable(def)).toBe(true)
|
package/src/store/store-types.ts
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
import type * as otel from '@opentelemetry/api'
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
|
+
type BackendIdMismatchError,
|
|
4
5
|
type ClientSession,
|
|
5
6
|
type ClientSessionSyncProcessor,
|
|
6
|
-
type ClientSessionSyncProcessorSimulationParams,
|
|
7
7
|
type IntentionalShutdownCause,
|
|
8
8
|
isQueryBuilder,
|
|
9
9
|
type MaterializeError,
|
|
10
10
|
type QueryBuilder,
|
|
11
11
|
type StoreInterrupted,
|
|
12
|
-
type BackendIdMismatchError,
|
|
13
12
|
type UnknownError,
|
|
14
13
|
} from '@livestore/common'
|
|
15
14
|
import type { StreamEventsOptions } from '@livestore/common/leader-thread'
|
|
16
15
|
import type { LiveStoreEvent, LiveStoreSchema } from '@livestore/common/schema'
|
|
17
|
-
import type
|
|
18
|
-
import { Deferred, Predicate } from '@livestore/utils/effect'
|
|
16
|
+
import { type Context, Deferred, type Effect, Predicate, type Schema, type Scope } from '@livestore/utils/effect'
|
|
19
17
|
|
|
20
18
|
import type {
|
|
21
19
|
LiveQuery,
|
|
@@ -24,7 +22,7 @@ import type {
|
|
|
24
22
|
ReactivityGraphContext,
|
|
25
23
|
SignalDef,
|
|
26
24
|
} from '../live-queries/base-class.ts'
|
|
27
|
-
import { TypeId } from '../live-queries/base-class.ts'
|
|
25
|
+
import { isLiveQueryDef, TypeId } from '../live-queries/base-class.ts'
|
|
28
26
|
import type { DebugRefreshReasonBase, Ref } from '../reactive.ts'
|
|
29
27
|
import type { SqliteDbWrapper } from '../SqliteDbWrapper.ts'
|
|
30
28
|
import type { ReferenceCountedSet } from '../utils/data-structures.ts'
|
|
@@ -98,7 +96,7 @@ export type StoreInternals = {
|
|
|
98
96
|
* Exposed primarily for Devtools (e.g. databrowser) to validate ad‑hoc
|
|
99
97
|
* event payloads. Application code should not depend on it directly.
|
|
100
98
|
*/
|
|
101
|
-
readonly eventSchema: Schema.
|
|
99
|
+
readonly eventSchema: Schema.Codec<LiveStoreEvent.Client.Decoded, LiveStoreEvent.Client.Encoded>
|
|
102
100
|
|
|
103
101
|
/**
|
|
104
102
|
* The active client session backing this Store. Provides access to the
|
|
@@ -115,14 +113,14 @@ export type StoreInternals = {
|
|
|
115
113
|
readonly sqliteDbWrapper: SqliteDbWrapper
|
|
116
114
|
|
|
117
115
|
/**
|
|
118
|
-
* Effect
|
|
116
|
+
* Effect context and scope used to fork background fibers for the Store.
|
|
119
117
|
*
|
|
120
|
-
* - `
|
|
118
|
+
* - `services` provides services when executing effects from imperative Store APIs.
|
|
121
119
|
* - `lifetimeScope` owns forked fibers; closed during Store shutdown.
|
|
122
120
|
*/
|
|
123
121
|
readonly effectContext: {
|
|
124
|
-
/** Effect
|
|
125
|
-
readonly
|
|
122
|
+
/** Effect context used to run Store effects with proper services. */
|
|
123
|
+
readonly services: Context.Context<Scope.Scope>
|
|
126
124
|
/** Scope that owns all long‑lived fibers spawned by the Store. */
|
|
127
125
|
readonly lifetimeScope: Scope.Scope
|
|
128
126
|
}
|
|
@@ -189,7 +187,7 @@ export type StoreConstructorParams<TSchema extends LiveStoreSchema = LiveStoreSc
|
|
|
189
187
|
context: TContext
|
|
190
188
|
otelOptions: OtelOptions
|
|
191
189
|
effectContext: {
|
|
192
|
-
|
|
190
|
+
services: Context.Context<Scope.Scope>
|
|
193
191
|
lifetimeScope: Scope.Scope
|
|
194
192
|
}
|
|
195
193
|
confirmUnsavedChanges: boolean
|
|
@@ -197,9 +195,6 @@ export type StoreConstructorParams<TSchema extends LiveStoreSchema = LiveStoreSc
|
|
|
197
195
|
params: {
|
|
198
196
|
leaderPushBatchSize: number
|
|
199
197
|
eventQueryBatchSize?: number
|
|
200
|
-
simulation?: {
|
|
201
|
-
clientSessionSyncProcessor: typeof ClientSessionSyncProcessorSimulationParams.Type
|
|
202
|
-
}
|
|
203
198
|
}
|
|
204
199
|
__runningInDevtools: boolean
|
|
205
200
|
}
|
|
@@ -335,48 +330,7 @@ export namespace Queryable {
|
|
|
335
330
|
export type Result<TQueryable extends Queryable<any>> = TQueryable extends Queryable<infer TResult> ? TResult : never
|
|
336
331
|
}
|
|
337
332
|
|
|
338
|
-
|
|
339
|
-
* Type guard that checks if a value is a query or signal definition.
|
|
340
|
-
*
|
|
341
|
-
* Use this to distinguish between definitions (blueprints) and instances (live queries).
|
|
342
|
-
* Definitions are created by `queryDb()`, `computed()`, and `signal()`.
|
|
343
|
-
*
|
|
344
|
-
* @example
|
|
345
|
-
* ```ts
|
|
346
|
-
* const todos$ = queryDb(tables.todos.all())
|
|
347
|
-
*
|
|
348
|
-
* if (isLiveQueryDef(todos$)) {
|
|
349
|
-
* console.log('This is a definition:', todos$.label)
|
|
350
|
-
* }
|
|
351
|
-
* ```
|
|
352
|
-
*/
|
|
353
|
-
export const isLiveQueryDef = (value: unknown): value is LiveQueryDef<any> | SignalDef<any> => {
|
|
354
|
-
if (typeof value !== 'object' || value === null) {
|
|
355
|
-
return false
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
if (!('_tag' in value)) {
|
|
359
|
-
return false
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
const tag = (value as LiveQueryDef<any> | SignalDef<any>)._tag
|
|
363
|
-
if (tag !== 'def' && tag !== 'signal-def') {
|
|
364
|
-
return false
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
const candidate = value as LiveQueryDef<any>
|
|
368
|
-
if (typeof candidate.make !== 'function') {
|
|
369
|
-
// The store calls make() to turn the definition into a live query instance.
|
|
370
|
-
return false
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
if (typeof candidate.hash !== 'string' || typeof candidate.label !== 'string') {
|
|
374
|
-
// Both identifiers must be present so the store can cache and log the query.
|
|
375
|
-
return false
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
return true
|
|
379
|
-
}
|
|
333
|
+
export { isLiveQueryDef }
|
|
380
334
|
|
|
381
335
|
/**
|
|
382
336
|
* Type guard that checks if a value is a live query instance.
|