@livestore/livestore 0.4.0-dev.9 → 0.5.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.
Files changed (132) hide show
  1. package/README.md +0 -1
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/QueryCache.js +1 -1
  4. package/dist/QueryCache.js.map +1 -1
  5. package/dist/SqliteDbWrapper.d.ts +5 -5
  6. package/dist/SqliteDbWrapper.d.ts.map +1 -1
  7. package/dist/SqliteDbWrapper.js +15 -13
  8. package/dist/SqliteDbWrapper.js.map +1 -1
  9. package/dist/SqliteDbWrapper.test.js +24 -6
  10. package/dist/SqliteDbWrapper.test.js.map +1 -1
  11. package/dist/effect/LiveStore.d.ts +134 -6
  12. package/dist/effect/LiveStore.d.ts.map +1 -1
  13. package/dist/effect/LiveStore.js +190 -11
  14. package/dist/effect/LiveStore.js.map +1 -1
  15. package/dist/effect/LiveStore.test.d.ts +2 -0
  16. package/dist/effect/LiveStore.test.d.ts.map +1 -0
  17. package/dist/effect/LiveStore.test.js +41 -0
  18. package/dist/effect/LiveStore.test.js.map +1 -0
  19. package/dist/effect/mod.d.ts +1 -1
  20. package/dist/effect/mod.d.ts.map +1 -1
  21. package/dist/effect/mod.js +3 -1
  22. package/dist/effect/mod.js.map +1 -1
  23. package/dist/live-queries/base-class.d.ts +129 -9
  24. package/dist/live-queries/base-class.d.ts.map +1 -1
  25. package/dist/live-queries/base-class.js +30 -4
  26. package/dist/live-queries/base-class.js.map +1 -1
  27. package/dist/live-queries/client-document-get-query.d.ts +1 -1
  28. package/dist/live-queries/client-document-get-query.d.ts.map +1 -1
  29. package/dist/live-queries/client-document-get-query.js +4 -3
  30. package/dist/live-queries/client-document-get-query.js.map +1 -1
  31. package/dist/live-queries/computed.d.ts +56 -0
  32. package/dist/live-queries/computed.d.ts.map +1 -1
  33. package/dist/live-queries/computed.js +62 -6
  34. package/dist/live-queries/computed.js.map +1 -1
  35. package/dist/live-queries/db-query.d.ts +2 -2
  36. package/dist/live-queries/db-query.d.ts.map +1 -1
  37. package/dist/live-queries/db-query.js +41 -30
  38. package/dist/live-queries/db-query.js.map +1 -1
  39. package/dist/live-queries/db-query.test.js +112 -29
  40. package/dist/live-queries/db-query.test.js.map +1 -1
  41. package/dist/live-queries/signal.d.ts +49 -0
  42. package/dist/live-queries/signal.d.ts.map +1 -1
  43. package/dist/live-queries/signal.js +51 -2
  44. package/dist/live-queries/signal.js.map +1 -1
  45. package/dist/live-queries/signal.test.js +4 -4
  46. package/dist/live-queries/signal.test.js.map +1 -1
  47. package/dist/mod.d.ts +3 -3
  48. package/dist/mod.d.ts.map +1 -1
  49. package/dist/mod.js +3 -2
  50. package/dist/mod.js.map +1 -1
  51. package/dist/reactive.d.ts +10 -10
  52. package/dist/reactive.d.ts.map +1 -1
  53. package/dist/reactive.js +29 -27
  54. package/dist/reactive.js.map +1 -1
  55. package/dist/reactive.test.js +2 -2
  56. package/dist/reactive.test.js.map +1 -1
  57. package/dist/store/StoreRegistry.d.ts +215 -0
  58. package/dist/store/StoreRegistry.d.ts.map +1 -0
  59. package/dist/store/StoreRegistry.js +267 -0
  60. package/dist/store/StoreRegistry.js.map +1 -0
  61. package/dist/store/StoreRegistry.test.d.ts +2 -0
  62. package/dist/store/StoreRegistry.test.d.ts.map +1 -0
  63. package/dist/store/StoreRegistry.test.js +384 -0
  64. package/dist/store/StoreRegistry.test.js.map +1 -0
  65. package/dist/store/create-store.d.ts +99 -22
  66. package/dist/store/create-store.d.ts.map +1 -1
  67. package/dist/store/create-store.js +85 -37
  68. package/dist/store/create-store.js.map +1 -1
  69. package/dist/store/devtools.d.ts +6 -18
  70. package/dist/store/devtools.d.ts.map +1 -1
  71. package/dist/store/devtools.js +61 -19
  72. package/dist/store/devtools.js.map +1 -1
  73. package/dist/store/store-eventstream.test.d.ts +2 -0
  74. package/dist/store/store-eventstream.test.d.ts.map +1 -0
  75. package/dist/store/store-eventstream.test.js +65 -0
  76. package/dist/store/store-eventstream.test.js.map +1 -0
  77. package/dist/store/store-types.d.ts +271 -31
  78. package/dist/store/store-types.d.ts.map +1 -1
  79. package/dist/store/store-types.js +41 -1
  80. package/dist/store/store-types.js.map +1 -1
  81. package/dist/store/store-types.test.d.ts +2 -0
  82. package/dist/store/store-types.test.d.ts.map +1 -0
  83. package/dist/store/store-types.test.js +39 -0
  84. package/dist/store/store-types.test.js.map +1 -0
  85. package/dist/store/store.d.ts +255 -68
  86. package/dist/store/store.d.ts.map +1 -1
  87. package/dist/store/store.js +533 -186
  88. package/dist/store/store.js.map +1 -1
  89. package/dist/utils/dev.d.ts.map +1 -1
  90. package/dist/utils/dev.js +1 -1
  91. package/dist/utils/dev.js.map +1 -1
  92. package/dist/utils/stack-info.d.ts.map +1 -1
  93. package/dist/utils/stack-info.js +3 -2
  94. package/dist/utils/stack-info.js.map +1 -1
  95. package/dist/utils/tests/fixture.d.ts +46 -39
  96. package/dist/utils/tests/fixture.d.ts.map +1 -1
  97. package/dist/utils/tests/fixture.js +7 -0
  98. package/dist/utils/tests/fixture.js.map +1 -1
  99. package/dist/utils/tests/otel.d.ts.map +1 -1
  100. package/dist/utils/tests/otel.js +5 -5
  101. package/dist/utils/tests/otel.js.map +1 -1
  102. package/package.json +50 -18
  103. package/src/QueryCache.ts +1 -1
  104. package/src/SqliteDbWrapper.test.ts +30 -6
  105. package/src/SqliteDbWrapper.ts +21 -17
  106. package/src/ambient.d.ts +0 -7
  107. package/src/effect/LiveStore.test.ts +61 -0
  108. package/src/effect/LiveStore.ts +426 -22
  109. package/src/effect/mod.ts +13 -1
  110. package/src/live-queries/__snapshots__/db-query.test.ts.snap +814 -178
  111. package/src/live-queries/base-class.ts +162 -32
  112. package/src/live-queries/client-document-get-query.ts +6 -4
  113. package/src/live-queries/computed.ts +65 -8
  114. package/src/live-queries/db-query.test.ts +168 -30
  115. package/src/live-queries/db-query.ts +58 -43
  116. package/src/live-queries/signal.test.ts +5 -4
  117. package/src/live-queries/signal.ts +52 -3
  118. package/src/mod.ts +19 -2
  119. package/src/reactive.test.ts +3 -2
  120. package/src/reactive.ts +58 -49
  121. package/src/store/StoreRegistry.test.ts +543 -0
  122. package/src/store/StoreRegistry.ts +429 -0
  123. package/src/store/create-store.ts +227 -74
  124. package/src/store/devtools.ts +305 -261
  125. package/src/store/store-eventstream.test.ts +123 -0
  126. package/src/store/store-types.test.ts +52 -0
  127. package/src/store/store-types.ts +318 -44
  128. package/src/store/store.ts +695 -283
  129. package/src/utils/dev.ts +3 -4
  130. package/src/utils/stack-info.ts +5 -2
  131. package/src/utils/tests/fixture.ts +9 -1
  132. package/src/utils/tests/otel.ts +8 -7
@@ -1,52 +1,169 @@
1
- import type { ClientSession, ClientSessionSyncProcessorSimulationParams, IntentionalShutdownCause, InvalidPullError, IsOfflineError, MaterializeError, StoreInterrupted, SyncError, UnexpectedError } from '@livestore/common';
2
- import type { EventSequenceNumber, LiveStoreEvent, LiveStoreSchema } from '@livestore/common/schema';
3
- import type { Effect, Runtime, Scope } from '@livestore/utils/effect';
4
- import { Deferred } from '@livestore/utils/effect';
5
1
  import type * as otel from '@opentelemetry/api';
6
- import type { DebugRefreshReasonBase } from '../reactive.ts';
2
+ import { type BackendIdMismatchError, type ClientSession, type ClientSessionSyncProcessor, type IntentionalShutdownCause, type MaterializeError, type QueryBuilder, type StoreInterrupted, type UnknownError } from '@livestore/common';
3
+ import type { StreamEventsOptions } from '@livestore/common/leader-thread';
4
+ import type { LiveStoreEvent, LiveStoreSchema } from '@livestore/common/schema';
5
+ import { type Context, Deferred, type Effect, type Schema, type Scope } from '@livestore/utils/effect';
6
+ import type { LiveQuery, LiveQueryDef, ReactivityGraph, ReactivityGraphContext, SignalDef } from '../live-queries/base-class.ts';
7
+ import { isLiveQueryDef } from '../live-queries/base-class.ts';
8
+ import type { DebugRefreshReasonBase, Ref } from '../reactive.ts';
9
+ import type { SqliteDbWrapper } from '../SqliteDbWrapper.ts';
10
+ import type { ReferenceCountedSet } from '../utils/data-structures.ts';
7
11
  import type { StackInfo } from '../utils/stack-info.ts';
8
12
  import type { Store } from './store.ts';
9
- export type LiveStoreContext = LiveStoreContextRunning | {
13
+ /**
14
+ * Union type representing the possible states of a LiveStore context.
15
+ *
16
+ * Used by framework integrations (React, Solid, etc.) to track Store lifecycle:
17
+ * - `running`: Store is active and ready for queries/commits
18
+ * - `error`: Store failed during boot or operation
19
+ * - `shutdown`: Store was intentionally shut down or interrupted
20
+ *
21
+ * @typeParam TSchema - The LiveStore schema type. Defaults to `LiveStoreSchema.Any`.
22
+ */
23
+ export type LiveStoreContext<TSchema extends LiveStoreSchema = LiveStoreSchema.Any> = LiveStoreContextRunning<TSchema> | {
10
24
  stage: 'error';
11
- error: UnexpectedError | unknown;
25
+ error: unknown;
12
26
  } | {
13
27
  stage: 'shutdown';
14
- cause: IntentionalShutdownCause | StoreInterrupted | SyncError;
28
+ cause: IntentionalShutdownCause | StoreInterrupted | UnknownError;
15
29
  };
16
- export type ShutdownDeferred = Deferred.Deferred<IntentionalShutdownCause, UnexpectedError | SyncError | StoreInterrupted | MaterializeError | InvalidPullError | IsOfflineError>;
30
+ export type ShutdownDeferred = Deferred.Deferred<IntentionalShutdownCause, UnknownError | StoreInterrupted | MaterializeError | BackendIdMismatchError>;
17
31
  export declare const makeShutdownDeferred: Effect.Effect<ShutdownDeferred>;
18
- export type LiveStoreContextRunning = {
32
+ /**
33
+ * Context state when the Store is active and ready for use.
34
+ *
35
+ * This is the normal operating state where you can query data, commit events,
36
+ * and subscribe to changes.
37
+ *
38
+ * @typeParam TSchema - The LiveStore schema type. Defaults to `LiveStoreSchema.Any`
39
+ * for backwards compatibility, but prefer providing the concrete schema type
40
+ * for full type safety.
41
+ */
42
+ export type LiveStoreContextRunning<TSchema extends LiveStoreSchema = LiveStoreSchema.Any> = {
19
43
  stage: 'running';
20
- store: Store;
44
+ store: Store<TSchema>;
21
45
  };
22
46
  export type OtelOptions = {
23
47
  tracer: otel.Tracer;
24
48
  rootSpanContext: otel.Context;
25
49
  };
26
- export type StoreOptions<TSchema extends LiveStoreSchema = LiveStoreSchema.Any, TContext = {}> = {
50
+ export declare const StoreInternalsSymbol: unique symbol;
51
+ export type StoreInternalsSymbol = typeof StoreInternalsSymbol;
52
+ /**
53
+ * Opaque bag containing the Store's implementation details.
54
+ *
55
+ * Not part of the public API — shapes and semantics may change without notice.
56
+ * Access only from within the @livestore/livestore package (and Devtools) via
57
+ * `StoreInternalsSymbol` to avoid accidental coupling in application code.
58
+ */
59
+ export type StoreInternals = {
60
+ /**
61
+ * Runtime event schema used for encoding/decoding events.
62
+ *
63
+ * Exposed primarily for Devtools (e.g. databrowser) to validate ad‑hoc
64
+ * event payloads. Application code should not depend on it directly.
65
+ */
66
+ readonly eventSchema: Schema.Codec<LiveStoreEvent.Client.Decoded, LiveStoreEvent.Client.Encoded>;
67
+ /**
68
+ * The active client session backing this Store. Provides access to the
69
+ * leader thread, network status, and shutdown signaling.
70
+ *
71
+ * Do not close or mutate directly — use `store.shutdown(...)`.
72
+ */
73
+ readonly clientSession: ClientSession;
74
+ /**
75
+ * Wrapper around the local SQLite state database. Centralizes query
76
+ * planning, caching, and change tracking used by reads and materializers.
77
+ */
78
+ readonly sqliteDbWrapper: SqliteDbWrapper;
79
+ /**
80
+ * Effect context and scope used to fork background fibers for the Store.
81
+ *
82
+ * - `services` provides services when executing effects from imperative Store APIs.
83
+ * - `lifetimeScope` owns forked fibers; closed during Store shutdown.
84
+ */
85
+ readonly effectContext: {
86
+ /** Effect context used to run Store effects with proper services. */
87
+ readonly services: Context.Context<Scope.Scope>;
88
+ /** Scope that owns all long‑lived fibers spawned by the Store. */
89
+ readonly lifetimeScope: Scope.Scope;
90
+ };
91
+ /**
92
+ * OpenTelemetry primitives used for instrumentation of commits, queries,
93
+ * and Store boot lifecycle.
94
+ */
95
+ readonly otel: StoreOtel;
96
+ /**
97
+ * The Store's reactive graph instance used to model dependencies and
98
+ * propagate updates. Provides APIs to create refs/thunks/effects and to
99
+ * subscribe to refresh cycles.
100
+ */
101
+ readonly reactivityGraph: ReactivityGraph;
102
+ /**
103
+ * Per‑table reactive refs used to broadcast invalidations when materializers
104
+ * write to tables. Values are always `null`; equality is intentionally
105
+ * `false` to force recomputation.
106
+ *
107
+ * Keys are SQLite table names (user tables; some system tables may be
108
+ * intentionally excluded from refresh).
109
+ */
110
+ readonly tableRefs: Readonly<Record<string, Ref<null, ReactivityGraphContext, RefreshReason>>>;
111
+ /**
112
+ * Set of currently subscribed LiveQuery instances (reference‑counted).
113
+ * Used for Devtools and diagnostics.
114
+ */
115
+ readonly activeQueries: ReferenceCountedSet<LiveQuery<any>>;
116
+ /**
117
+ * Client‑session sync processor orchestrating push/pull and materialization
118
+ * of events into local state.
119
+ */
120
+ readonly syncProcessor: ClientSessionSyncProcessor;
121
+ /**
122
+ * Starts background fibers for sync and observation. Must be run exactly
123
+ * once per Store instance. Scoped; installs finalizers to end spans and
124
+ * detach reactive refs.
125
+ */
126
+ readonly boot: Effect.Effect<void, UnknownError, Scope.Scope>;
127
+ /**
128
+ * Tracks whether the Store has been shut down. When true, mutating APIs
129
+ * should reject via `checkShutdown`.
130
+ */
131
+ isShutdown: boolean;
132
+ };
133
+ /**
134
+ * Parameters for constructing a Store instance.
135
+ *
136
+ * @internal This type is used by the Store constructor and is not part of the public API.
137
+ * For creating stores, use `createStore()` or `StoreRegistry` instead.
138
+ */
139
+ export type StoreConstructorParams<TSchema extends LiveStoreSchema = LiveStoreSchema.Any, TContext = {}> = {
27
140
  clientSession: ClientSession;
28
141
  schema: TSchema;
29
142
  storeId: string;
30
143
  context: TContext;
31
144
  otelOptions: OtelOptions;
32
145
  effectContext: {
33
- runtime: Runtime.Runtime<Scope.Scope>;
146
+ services: Context.Context<Scope.Scope>;
34
147
  lifetimeScope: Scope.Scope;
35
148
  };
36
149
  confirmUnsavedChanges: boolean;
37
150
  batchUpdates: (runUpdates: () => void) => void;
38
151
  params: {
39
152
  leaderPushBatchSize: number;
40
- simulation?: {
41
- clientSessionSyncProcessor: typeof ClientSessionSyncProcessorSimulationParams.Type;
42
- };
153
+ eventQueryBatchSize?: number;
43
154
  };
44
155
  __runningInDevtools: boolean;
45
156
  };
157
+ /**
158
+ * Tagged union describing why a reactive refresh occurred.
159
+ *
160
+ * Used internally for debugging and devtools to trace the cause of query re-evaluations.
161
+ * Each variant includes context about what triggered the refresh.
162
+ */
46
163
  export type RefreshReason = DebugRefreshReasonBase | {
47
164
  _tag: 'commit';
48
165
  /** The events that were applied */
49
- events: ReadonlyArray<LiveStoreEvent.AnyDecoded | LiveStoreEvent.PartialAnyDecoded>;
166
+ events: ReadonlyArray<LiveStoreEvent.Client.Decoded | LiveStoreEvent.Input.Decoded>;
50
167
  /** The tables that were written to by the event */
51
168
  writeTables: ReadonlyArray<string>;
52
169
  } | {
@@ -64,10 +181,19 @@ export type RefreshReason = DebugRefreshReasonBase | {
64
181
  _tag: 'manual';
65
182
  label?: string;
66
183
  };
184
+ /**
185
+ * Debug information captured for each query execution.
186
+ *
187
+ * Used by devtools and performance monitoring to track query behavior.
188
+ */
67
189
  export type QueryDebugInfo = {
190
+ /** Query type discriminator ('db', 'computed', etc.) */
68
191
  _tag: string;
192
+ /** Human-readable query label */
69
193
  label: string;
194
+ /** SQL query string or computed function representation */
70
195
  query: string;
196
+ /** Execution time in milliseconds */
71
197
  durationMs: number;
72
198
  };
73
199
  export type StoreOtel = {
@@ -82,27 +208,141 @@ export type StoreCommitOptions = {
82
208
  spanLinks?: otel.Link[];
83
209
  otelContext?: otel.Context;
84
210
  };
85
- export type StoreEventsOptions<TSchema extends LiveStoreSchema> = {
86
- /**
87
- * By default only new events are returned.
88
- * Use this to get all events from a specific point in time.
89
- */
90
- cursor?: EventSequenceNumber.EventSequenceNumber;
211
+ /**
212
+ * filter: Narrowed to the store's event types
213
+ * includeClientOnly: Omitted from public API until supported
214
+ */
215
+ export type StoreEventsOptions<TSchema extends LiveStoreSchema> = Omit<StreamEventsOptions, 'filter' | 'includeClientOnly'> & {
91
216
  /**
92
- * Only include events of the given names
217
+ * Only include events of the given names.
93
218
  * @default undefined (include all)
94
219
  */
95
220
  filter?: ReadonlyArray<keyof TSchema['_EventDefMapType']>;
221
+ };
222
+ /**
223
+ * Function returned by `store.subscribe()` to stop receiving updates.
224
+ *
225
+ * Call this to unsubscribe from a query and release the associated resources.
226
+ *
227
+ * @example
228
+ * ```ts
229
+ * const unsubscribe = store.subscribe(todos$, (todos) => console.log(todos))
230
+ * // Later...
231
+ * unsubscribe()
232
+ * ```
233
+ */
234
+ export type Unsubscribe = () => void;
235
+ /**
236
+ * Options for `store.subscribe()`.
237
+ *
238
+ * @typeParam TResult - The result type of the subscribed query
239
+ */
240
+ export type SubscribeOptions<TResult> = {
241
+ /** Callback invoked when the subscription is established (receives the live query instance) */
242
+ onSubscribe?: (query$: LiveQuery<TResult>) => void;
243
+ /** Callback invoked when the subscription is terminated */
244
+ onUnsubsubscribe?: () => void;
245
+ /** Label for debugging and devtools */
246
+ label?: string;
247
+ /** If true, skips invoking the callback for the initial value */
248
+ skipInitialRun?: boolean;
249
+ /** OpenTelemetry context for tracing */
250
+ otelContext?: otel.Context;
251
+ /** Stack trace info for debugging subscription origins */
252
+ stackInfo?: StackInfo;
253
+ };
254
+ /** All query definitions or instances the store can execute or subscribe to. */
255
+ export type Queryable<TResult> = LiveQueryDef<TResult> | SignalDef<TResult> | LiveQuery<TResult> | QueryBuilder<TResult, any, any>;
256
+ /**
257
+ * Helper types for `Queryable`.
258
+ *
259
+ * Provides type-level utilities to work with `Queryable` values.
260
+ */
261
+ export declare namespace Queryable {
96
262
  /**
97
- * Whether to include client-only events or only return synced events
98
- * @default true
263
+ * Extracts the result type from a `Queryable`.
264
+ *
265
+ * Example:
266
+ * - `Queryable.Result<LiveQueryDef<number>>` → `number`
267
+ * - `Queryable.Result<SignalDef<string>>` → `string`
268
+ * - `Queryable.Result<LiveQuery<{ id: string }>>` → `{ id: string }`
269
+ * - `Queryable.Result<LiveQueryDef<A> | SignalDef<B>>` → `A | B`
99
270
  */
100
- includeClientOnly?: boolean;
271
+ type Result<TQueryable extends Queryable<any>> = TQueryable extends Queryable<infer TResult> ? TResult : never;
272
+ }
273
+ export { isLiveQueryDef };
274
+ /**
275
+ * Type guard that checks if a value is a live query instance.
276
+ *
277
+ * Live query instances are stateful objects bound to a Store's reactivity graph.
278
+ * They're created internally when you use a definition with `store.query()` or `store.subscribe()`.
279
+ *
280
+ * @example
281
+ * ```ts
282
+ * const [, , , query$] = useClientDocument(tables.uiState)
283
+ *
284
+ * if (isLiveQueryInstance(query$)) {
285
+ * console.log('Execution count:', query$.runs)
286
+ * }
287
+ * ```
288
+ */
289
+ export declare const isLiveQueryInstance: (value: unknown) => value is LiveQuery<any>;
290
+ /**
291
+ * Type guard that checks if a value can be used with `store.query()` or `store.subscribe()`.
292
+ *
293
+ * Queryable values include:
294
+ * - Query definitions (`LiveQueryDef` from `queryDb()`, `computed()`)
295
+ * - Signal definitions (`SignalDef` from `signal()`)
296
+ * - Live query instances (`LiveQuery`)
297
+ * - Query builders (e.g., `tables.todos.where(...)`)
298
+ *
299
+ * @example
300
+ * ```ts
301
+ * const handleQuery = (input: unknown) => {
302
+ * if (isQueryable(input)) {
303
+ * return store.query(input)
304
+ * }
305
+ * throw new Error('Not a valid query')
306
+ * }
307
+ * ```
308
+ */
309
+ export declare const isQueryable: (value: unknown) => value is Queryable<unknown>;
310
+ /**
311
+ * Represents the current synchronization status of the store.
312
+ *
313
+ * This provides visibility into the sync state between the client session
314
+ * and the leader thread, allowing applications to show sync indicators
315
+ * or determine backend health.
316
+ *
317
+ * @example
318
+ * ```ts
319
+ * const status = store.syncStatus()
320
+ * if (status.isSynced) {
321
+ * console.log('All changes synced')
322
+ * } else {
323
+ * console.log(`${status.pendingCount} events pending sync`)
324
+ * }
325
+ * ```
326
+ */
327
+ export type SyncStatus = {
101
328
  /**
102
- * Exclude own events that have not been pushed to the sync backend yet
103
- * @default false
329
+ * The local head sequence number (most recent event in the client session).
330
+ * Represented as a string in the format "e{global}.{client}" (e.g., "e5.2").
104
331
  */
105
- excludeUnpushed?: boolean;
332
+ localHead: string;
333
+ /**
334
+ * The upstream head sequence number (what the leader thread has confirmed).
335
+ * Represented as a string in the format "e{global}" (e.g., "e3").
336
+ */
337
+ upstreamHead: string;
338
+ /**
339
+ * Number of events pending synchronization to the leader thread.
340
+ */
341
+ pendingCount: number;
342
+ /**
343
+ * Whether the client session is fully synced with the leader thread.
344
+ * True when there are no pending events (pendingCount === 0).
345
+ */
346
+ isSynced: boolean;
106
347
  };
107
- export type Unsubscribe = () => void;
108
348
  //# sourceMappingURL=store-types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"store-types.d.ts","sourceRoot":"","sources":["../../src/store/store-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,0CAA0C,EAC1C,wBAAwB,EACxB,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,SAAS,EACT,eAAe,EAChB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,KAAK,EAAE,mBAAmB,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AACpG,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AACrE,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AAClD,OAAO,KAAK,KAAK,IAAI,MAAM,oBAAoB,CAAA;AAE/C,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAA;AAC5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AACvD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAEvC,MAAM,MAAM,gBAAgB,GACxB,uBAAuB,GACvB;IACE,KAAK,EAAE,OAAO,CAAA;IACd,KAAK,EAAE,eAAe,GAAG,OAAO,CAAA;CACjC,GACD;IACE,KAAK,EAAE,UAAU,CAAA;IACjB,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O,CAAA;IAC1B,0DAA0D;IAC1D,SAAS,CAAC,EAAE,SAAS,CAAA;CACtB,CAAA;AAED,gFAAgF;AAChF,MAAM,MAAM,SAAS,CAAC,OAAO,IACzB,YAAY,CAAC,OAAO,CAAC,GACrB,SAAS,CAAC,OAAO,CAAC,GAClB,SAAS,CAAC,OAAO,CAAC,GAClB,YAAY,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA;AAEnC;;;;GAIG;AACH,yBAAiB,SAAS,CAAC;IACzB;;;;;;;;OAQG;IACH,KAAY,MAAM,CAAC,UAAU,SAAS,SAAS,CAAC,GAAG,CAAC,IAAI,UAAU,SAAS,SAAS,CAAC,MAAM,OAAO,CAAC,GAAG,OAAO,GAAG,KAAK,CAAA;CACtH;AAED,OAAO,EAAE,cAAc,EAAE,CAAA;AAEzB;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,mBAAmB,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,SAAS,CAAC,GAAG,CAAyC,CAAA;AAEpH;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,WAAW,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,SAAS,CAAC,OAAO,CACO,CAAA;AAE9E;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB;;;OAGG;IACH,SAAS,EAAE,MAAM,CAAA;IACjB;;;OAGG;IACH,YAAY,EAAE,MAAM,CAAA;IACpB;;OAEG;IACH,YAAY,EAAE,MAAM,CAAA;IACpB;;;OAGG;IACH,QAAQ,EAAE,OAAO,CAAA;CAClB,CAAA"}
@@ -1,3 +1,43 @@
1
- import { Deferred } from '@livestore/utils/effect';
1
+ import { isQueryBuilder, } from '@livestore/common';
2
+ import { Deferred, Predicate } from '@livestore/utils/effect';
3
+ import { isLiveQueryDef, TypeId } from "../live-queries/base-class.js";
2
4
  export const makeShutdownDeferred = Deferred.make();
5
+ export const StoreInternalsSymbol = Symbol.for('livestore.StoreInternals');
6
+ export { isLiveQueryDef };
7
+ /**
8
+ * Type guard that checks if a value is a live query instance.
9
+ *
10
+ * Live query instances are stateful objects bound to a Store's reactivity graph.
11
+ * They're created internally when you use a definition with `store.query()` or `store.subscribe()`.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * const [, , , query$] = useClientDocument(tables.uiState)
16
+ *
17
+ * if (isLiveQueryInstance(query$)) {
18
+ * console.log('Execution count:', query$.runs)
19
+ * }
20
+ * ```
21
+ */
22
+ export const isLiveQueryInstance = (value) => Predicate.hasProperty(value, TypeId);
23
+ /**
24
+ * Type guard that checks if a value can be used with `store.query()` or `store.subscribe()`.
25
+ *
26
+ * Queryable values include:
27
+ * - Query definitions (`LiveQueryDef` from `queryDb()`, `computed()`)
28
+ * - Signal definitions (`SignalDef` from `signal()`)
29
+ * - Live query instances (`LiveQuery`)
30
+ * - Query builders (e.g., `tables.todos.where(...)`)
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * const handleQuery = (input: unknown) => {
35
+ * if (isQueryable(input)) {
36
+ * return store.query(input)
37
+ * }
38
+ * throw new Error('Not a valid query')
39
+ * }
40
+ * ```
41
+ */
42
+ export const isQueryable = (value) => isQueryBuilder(value) || isLiveQueryInstance(value) || isLiveQueryDef(value);
3
43
  //# sourceMappingURL=store-types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"store-types.js","sourceRoot":"","sources":["../../src/store/store-types.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AAsBlD,MAAM,CAAC,MAAM,oBAAoB,GAAoC,QAAQ,CAAC,IAAI,EAG/E,CAAA"}
1
+ {"version":3,"file":"store-types.js","sourceRoot":"","sources":["../../src/store/store-types.ts"],"names":[],"mappings":"AAEA,OAAO,EAKL,cAAc,GAKf,MAAM,mBAAmB,CAAA;AAG1B,OAAO,EAAgB,QAAQ,EAAe,SAAS,EAA2B,MAAM,yBAAyB,CAAA;AASjH,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAA;AAgCtE,MAAM,CAAC,MAAM,oBAAoB,GAAoC,QAAQ,CAAC,IAAI,EAG/E,CAAA;AAsBH,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAA;AA2P1E,OAAO,EAAE,cAAc,EAAE,CAAA;AAEzB;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,KAAc,EAA2B,EAAE,CAAC,SAAS,CAAC,WAAW,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;AAEpH;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,KAAc,EAA+B,EAAE,CACzE,cAAc,CAAC,KAAK,CAAC,IAAI,mBAAmB,CAAC,KAAK,CAAC,IAAI,cAAc,CAAC,KAAK,CAAC,CAAA"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=store-types.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store-types.test.d.ts","sourceRoot":"","sources":["../../src/store/store-types.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,39 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { QueryBuilderTypeId } from '@livestore/common';
3
+ import { Schema } from '@livestore/utils/effect';
4
+ import { TypeId } from "../live-queries/base-class.js";
5
+ import { queryDb, signal } from "../live-queries/mod.js";
6
+ import { isQueryable } from "./store-types.js";
7
+ const makeQueryBuilder = () => ({
8
+ [QueryBuilderTypeId]: QueryBuilderTypeId,
9
+ ResultType: null,
10
+ asSql: () => ({ query: 'select 1', bindValues: [], usedTables: new Set() }),
11
+ toString: () => 'select 1',
12
+ });
13
+ describe('isQueryable', () => {
14
+ it('identifies live query definitions', () => {
15
+ const def = queryDb({
16
+ query: 'select 1 as value',
17
+ schema: Schema.Array(Schema.Struct({ value: Schema.Finite })),
18
+ });
19
+ expect(isQueryable(def)).toBe(true);
20
+ });
21
+ it('identifies signal definitions', () => {
22
+ const sig = signal(0, { label: 'count' });
23
+ expect(isQueryable(sig)).toBe(true);
24
+ });
25
+ it('identifies live query instances', () => {
26
+ const liveQueryLike = { [TypeId]: TypeId };
27
+ expect(isQueryable(liveQueryLike)).toBe(true);
28
+ });
29
+ it('identifies query builders', () => {
30
+ const qb = makeQueryBuilder();
31
+ expect(isQueryable(qb)).toBe(true);
32
+ });
33
+ it('rejects unrelated values', () => {
34
+ expect(isQueryable(null)).toBe(false);
35
+ expect(isQueryable(undefined)).toBe(false);
36
+ expect(isQueryable({})).toBe(false);
37
+ });
38
+ });
39
+ //# sourceMappingURL=store-types.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store-types.test.js","sourceRoot":"","sources":["../../src/store/store-types.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAG7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAEhD,OAAO,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAA;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAE9C,MAAM,gBAAgB,GAAG,GAAgC,EAAE,CACzD,CAAC;IACC,CAAC,kBAAkB,CAAC,EAAE,kBAAkB;IACxC,UAAU,EAAE,IAAI;IAChB,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,EAAE,EAAE,UAAU,EAAE,IAAI,GAAG,EAAU,EAAE,CAAC;IACnF,QAAQ,EAAE,GAAG,EAAE,CAAC,UAAU;CAC3B,CAA2C,CAAA;AAE9C,QAAQ,CAAC,aAAa,EAAE,GAA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