@livestore/livestore 0.3.2-dev.0 → 0.3.2-dev.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/QueryCache.d.ts +4 -6
  3. package/dist/QueryCache.d.ts.map +1 -1
  4. package/dist/QueryCache.js +2 -3
  5. package/dist/QueryCache.js.map +1 -1
  6. package/dist/SqliteDbWrapper.d.ts.map +1 -1
  7. package/dist/SqliteDbWrapper.js +1 -2
  8. package/dist/SqliteDbWrapper.js.map +1 -1
  9. package/dist/SqliteDbWrapper.test.js +1 -1
  10. package/dist/effect/LiveStore.d.ts +2 -2
  11. package/dist/effect/LiveStore.js +1 -1
  12. package/dist/effect/mod.d.ts +2 -2
  13. package/dist/effect/mod.d.ts.map +1 -1
  14. package/dist/effect/mod.js +2 -2
  15. package/dist/effect/mod.js.map +1 -1
  16. package/dist/internal/mod.d.ts +2 -2
  17. package/dist/internal/mod.js +2 -2
  18. package/dist/live-queries/base-class.d.ts +4 -4
  19. package/dist/live-queries/base-class.d.ts.map +1 -1
  20. package/dist/live-queries/base-class.js +1 -1
  21. package/dist/live-queries/base-class.js.map +1 -1
  22. package/dist/live-queries/client-document-get-query.d.ts +1 -1
  23. package/dist/live-queries/computed.d.ts +4 -4
  24. package/dist/live-queries/computed.js +2 -2
  25. package/dist/live-queries/db-query.d.ts +4 -4
  26. package/dist/live-queries/db-query.js +4 -4
  27. package/dist/live-queries/db-query.test.js +12 -14
  28. package/dist/live-queries/db-query.test.js.map +1 -1
  29. package/dist/live-queries/mod.d.ts +4 -4
  30. package/dist/live-queries/mod.js +4 -4
  31. package/dist/live-queries/signal.d.ts +4 -4
  32. package/dist/live-queries/signal.js +1 -1
  33. package/dist/live-queries/signal.test.js +3 -3
  34. package/dist/mod.d.ts +10 -10
  35. package/dist/mod.d.ts.map +1 -1
  36. package/dist/mod.js +9 -9
  37. package/dist/mod.js.map +1 -1
  38. package/dist/reactive.d.ts.map +1 -1
  39. package/dist/reactive.js +1 -2
  40. package/dist/reactive.js.map +1 -1
  41. package/dist/reactive.test.js +1 -1
  42. package/dist/store/create-store.d.ts +6 -3
  43. package/dist/store/create-store.d.ts.map +1 -1
  44. package/dist/store/create-store.js +3 -2
  45. package/dist/store/create-store.js.map +1 -1
  46. package/dist/store/devtools.d.ts +3 -3
  47. package/dist/store/devtools.js +2 -2
  48. package/dist/store/store-types.d.ts +7 -4
  49. package/dist/store/store-types.d.ts.map +1 -1
  50. package/dist/store/store-types.js.map +1 -1
  51. package/dist/store/store.d.ts +7 -7
  52. package/dist/store/store.d.ts.map +1 -1
  53. package/dist/store/store.js +7 -6
  54. package/dist/store/store.js.map +1 -1
  55. package/dist/utils/dev.d.ts.map +1 -1
  56. package/dist/utils/dev.js +0 -1
  57. package/dist/utils/dev.js.map +1 -1
  58. package/dist/utils/stack-info.test.js +1 -1
  59. package/dist/utils/tests/fixture.d.ts +33 -2
  60. package/dist/utils/tests/fixture.d.ts.map +1 -1
  61. package/dist/utils/tests/fixture.js +16 -3
  62. package/dist/utils/tests/fixture.js.map +1 -1
  63. package/dist/utils/tests/mod.d.ts +3 -3
  64. package/dist/utils/tests/mod.d.ts.map +1 -1
  65. package/dist/utils/tests/mod.js +3 -3
  66. package/dist/utils/tests/mod.js.map +1 -1
  67. package/dist/utils/tests/otel.d.ts.map +1 -1
  68. package/dist/utils/tests/otel.js.map +1 -1
  69. package/package.json +5 -5
  70. package/src/QueryCache.ts +5 -7
  71. package/src/SqliteDbWrapper.test.ts +1 -1
  72. package/src/SqliteDbWrapper.ts +1 -3
  73. package/src/ambient.d.ts +0 -2
  74. package/src/effect/LiveStore.ts +2 -2
  75. package/src/effect/mod.ts +4 -4
  76. package/src/internal/mod.ts +2 -2
  77. package/src/live-queries/__snapshots__/db-query.test.ts.snap +14 -14
  78. package/src/live-queries/base-class.ts +11 -10
  79. package/src/live-queries/client-document-get-query.ts +1 -1
  80. package/src/live-queries/computed.ts +5 -5
  81. package/src/live-queries/db-query.test.ts +12 -14
  82. package/src/live-queries/db-query.ts +7 -7
  83. package/src/live-queries/mod.ts +4 -4
  84. package/src/live-queries/signal.test.ts +3 -3
  85. package/src/live-queries/signal.ts +4 -4
  86. package/src/mod.ts +33 -39
  87. package/src/reactive.test.ts +1 -1
  88. package/src/reactive.ts +2 -4
  89. package/src/store/create-store.ts +8 -3
  90. package/src/store/devtools.ts +5 -5
  91. package/src/store/store-types.ts +13 -4
  92. package/src/store/store.ts +11 -10
  93. package/src/utils/dev.ts +0 -1
  94. package/src/utils/stack-info.test.ts +1 -1
  95. package/src/utils/tests/fixture.ts +18 -3
  96. package/src/utils/tests/mod.ts +3 -3
  97. package/src/utils/tests/otel.ts +1 -0
package/src/reactive.ts CHANGED
@@ -21,13 +21,11 @@
21
21
  // is maintained eagerly as edges are added and removed.)
22
22
  // - At every thunk we check value equality with the previous value and cutoff propagation if possible.
23
23
 
24
- /* eslint-disable prefer-arrow/prefer-arrow-functions */
25
-
26
24
  import { BoundArray } from '@livestore/common'
27
25
  import { deepEqual, shouldNeverHappen } from '@livestore/utils'
28
26
  import type { Types } from '@livestore/utils/effect'
29
27
  import type * as otel from '@opentelemetry/api'
30
- // import { getDurationMsFromSpan } from './otel.js'
28
+ // import { getDurationMsFromSpan } from './otel.ts'
31
29
 
32
30
  export const NOT_REFRESHED_YET = Symbol.for('NOT_REFRESHED_YET')
33
31
  export type NOT_REFRESHED_YET = typeof NOT_REFRESHED_YET
@@ -279,7 +277,7 @@ export class ReactiveGraph<
279
277
  return compute(atom, otelContext, debugRefreshReason)
280
278
  }
281
279
 
282
- let debugInfo: TDebugThunkInfo | undefined
280
+ let debugInfo: TDebugThunkInfo | undefined
283
281
  const setDebugInfo = (debugInfo_: TDebugThunkInfo) => {
284
282
  debugInfo = debugInfo_
285
283
  }
@@ -3,6 +3,7 @@ import type {
3
3
  BootStatus,
4
4
  ClientSession,
5
5
  ClientSessionDevtoolsChannel,
6
+ ClientSessionSyncProcessorSimulationParams,
6
7
  IntentionalShutdownCause,
7
8
  MigrationsReport,
8
9
  } from '@livestore/common'
@@ -29,13 +30,13 @@ import {
29
30
  import { nanoid } from '@livestore/utils/nanoid'
30
31
  import * as otel from '@opentelemetry/api'
31
32
 
32
- import { connectDevtoolsToStore } from './devtools.js'
33
- import { Store } from './store.js'
33
+ import { connectDevtoolsToStore } from './devtools.ts'
34
+ import { Store } from './store.ts'
34
35
  import type {
35
36
  LiveStoreContextRunning as LiveStoreContextRunning_,
36
37
  OtelOptions,
37
38
  ShutdownDeferred,
38
- } from './store-types.js'
39
+ } from './store-types.ts'
39
40
 
40
41
  export const DEFAULT_PARAMS = {
41
42
  leaderPushBatchSize: 100,
@@ -120,6 +121,9 @@ export interface CreateStoreOptions<TSchema extends LiveStoreSchema, TContext =
120
121
  syncPayload?: Schema.JsonValue
121
122
  params?: {
122
123
  leaderPushBatchSize?: number
124
+ simulation?: {
125
+ clientSessionSyncProcessor: typeof ClientSessionSyncProcessorSimulationParams.Type
126
+ }
123
127
  }
124
128
  debug?: {
125
129
  instanceId?: string
@@ -274,6 +278,7 @@ export const createStore = <TSchema extends LiveStoreSchema = LiveStoreSchema, T
274
278
  storeId,
275
279
  params: {
276
280
  leaderPushBatchSize: params?.leaderPushBatchSize ?? DEFAULT_PARAMS.leaderPushBatchSize,
281
+ simulation: params?.simulation,
277
282
  },
278
283
  })
279
284
 
@@ -5,11 +5,11 @@ import type { WebChannel } from '@livestore/utils/effect'
5
5
  import { Effect, Stream } from '@livestore/utils/effect'
6
6
  import { nanoid } from '@livestore/utils/nanoid'
7
7
 
8
- import type { LiveQuery, ReactivityGraph } from '../live-queries/base-class.js'
9
- import { NOT_REFRESHED_YET } from '../reactive.js'
10
- import type { SqliteDbWrapper } from '../SqliteDbWrapper.js'
11
- import { emptyDebugInfo as makeEmptyDebugInfo } from '../SqliteDbWrapper.js'
12
- import type { ReferenceCountedSet } from '../utils/data-structures.js'
8
+ import type { LiveQuery, ReactivityGraph } from '../live-queries/base-class.ts'
9
+ import { NOT_REFRESHED_YET } from '../reactive.ts'
10
+ import type { SqliteDbWrapper } from '../SqliteDbWrapper.ts'
11
+ import { emptyDebugInfo as makeEmptyDebugInfo } from '../SqliteDbWrapper.ts'
12
+ import type { ReferenceCountedSet } from '../utils/data-structures.ts'
13
13
 
14
14
  type IStore = {
15
15
  clientSession: ClientSession
@@ -1,12 +1,18 @@
1
- import type { ClientSession, IntentionalShutdownCause, StoreInterrupted, UnexpectedError } from '@livestore/common'
1
+ import type {
2
+ ClientSession,
3
+ ClientSessionSyncProcessorSimulationParams,
4
+ IntentionalShutdownCause,
5
+ StoreInterrupted,
6
+ UnexpectedError,
7
+ } from '@livestore/common'
2
8
  import type { EventSequenceNumber, LiveStoreEvent, LiveStoreSchema } from '@livestore/common/schema'
3
9
  import type { Effect, Runtime, Scope } from '@livestore/utils/effect'
4
10
  import { Deferred } from '@livestore/utils/effect'
5
11
  import type * as otel from '@opentelemetry/api'
6
12
 
7
- import type { DebugRefreshReasonBase } from '../reactive.js'
8
- import type { StackInfo } from '../utils/stack-info.js'
9
- import type { Store } from './store.js'
13
+ import type { DebugRefreshReasonBase } from '../reactive.ts'
14
+ import type { StackInfo } from '../utils/stack-info.ts'
15
+ import type { Store } from './store.ts'
10
16
 
11
17
  export type LiveStoreContext =
12
18
  | LiveStoreContextRunning
@@ -49,6 +55,9 @@ export type StoreOptions<TSchema extends LiveStoreSchema = LiveStoreSchema, TCon
49
55
  batchUpdates: (runUpdates: () => void) => void
50
56
  params: {
51
57
  leaderPushBatchSize: number
58
+ simulation?: {
59
+ clientSessionSyncProcessor: typeof ClientSessionSyncProcessorSimulationParams.Type
60
+ }
52
61
  }
53
62
  __runningInDevtools: boolean
54
63
  }
@@ -32,15 +32,15 @@ import type {
32
32
  ReactivityGraph,
33
33
  ReactivityGraphContext,
34
34
  SignalDef,
35
- } from '../live-queries/base-class.js'
36
- import { makeReactivityGraph } from '../live-queries/base-class.js'
37
- import { makeExecBeforeFirstRun } from '../live-queries/client-document-get-query.js'
38
- import { queryDb } from '../live-queries/db-query.js'
39
- import type { Ref } from '../reactive.js'
40
- import { SqliteDbWrapper } from '../SqliteDbWrapper.js'
41
- import { ReferenceCountedSet } from '../utils/data-structures.js'
42
- import { downloadBlob, exposeDebugUtils } from '../utils/dev.js'
43
- import type { StackInfo } from '../utils/stack-info.js'
35
+ } from '../live-queries/base-class.ts'
36
+ import { makeReactivityGraph } from '../live-queries/base-class.ts'
37
+ import { makeExecBeforeFirstRun } from '../live-queries/client-document-get-query.ts'
38
+ import { queryDb } from '../live-queries/db-query.ts'
39
+ import type { Ref } from '../reactive.ts'
40
+ import { SqliteDbWrapper } from '../SqliteDbWrapper.ts'
41
+ import { ReferenceCountedSet } from '../utils/data-structures.ts'
42
+ import { downloadBlob, exposeDebugUtils } from '../utils/dev.ts'
43
+ import type { StackInfo } from '../utils/stack-info.ts'
44
44
  import type {
45
45
  RefreshReason,
46
46
  StoreCommitOptions,
@@ -48,7 +48,7 @@ import type {
48
48
  StoreOptions,
49
49
  StoreOtel,
50
50
  Unsubscribe,
51
- } from './store-types.js'
51
+ } from './store-types.ts'
52
52
 
53
53
  if (isDevEnv()) {
54
54
  exposeDebugUtils()
@@ -195,6 +195,7 @@ export class Store<TSchema extends LiveStoreSchema = LiveStoreSchema, TContext =
195
195
  span: syncSpan,
196
196
  params: {
197
197
  leaderPushBatchSize: params.leaderPushBatchSize,
198
+ simulation: params.simulation?.clientSessionSyncProcessor,
198
199
  },
199
200
  confirmUnsavedChanges,
200
201
  })
package/src/utils/dev.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import { isDevEnv } from '@livestore/utils'
2
2
  import { Effect } from '@livestore/utils/effect'
3
3
 
4
- /* eslint-disable unicorn/prefer-global-this */
5
4
  export const downloadBlob = (
6
5
  data: Uint8Array | Blob | string,
7
6
  fileName: string,
@@ -1,6 +1,6 @@
1
1
  import { expect, it } from 'vitest'
2
2
 
3
- import { extractStackInfoFromStackTrace } from './stack-info.js'
3
+ import { extractStackInfoFromStackTrace } from './stack-info.ts'
4
4
 
5
5
  it('RouteLink stacktrace', async () => {
6
6
  const stackTrace = `\
@@ -1,6 +1,6 @@
1
1
  import { makeInMemoryAdapter } from '@livestore/adapter-web'
2
2
  import { provideOtel } from '@livestore/common'
3
- import { createStore, makeSchema, State } from '@livestore/livestore'
3
+ import { createStore, Events, makeSchema, State } from '@livestore/livestore'
4
4
  import { Effect, Schema } from '@livestore/utils/effect'
5
5
  import type * as otel from '@opentelemetry/api'
6
6
 
@@ -37,8 +37,23 @@ export const app = State.SQLite.clientDocument({
37
37
 
38
38
  export const tables = { todos, app }
39
39
 
40
- export const state = State.SQLite.makeState({ tables, materializers: {} })
41
- export const schema = makeSchema({ state, events: {} })
40
+ export const events = {
41
+ todoCreated: Events.synced({
42
+ name: 'todo.created',
43
+ schema: Schema.Struct({
44
+ id: Schema.String,
45
+ text: Schema.String,
46
+ completed: Schema.Boolean,
47
+ }),
48
+ }),
49
+ }
50
+
51
+ const materializers = State.SQLite.materializers(events, {
52
+ 'todo.created': ({ id, text, completed }) => tables.todos.insert({ id, text, completed }),
53
+ })
54
+
55
+ export const state = State.SQLite.makeState({ tables, materializers })
56
+ export const schema = makeSchema({ state, events })
42
57
 
43
58
  export const makeTodoMvc = ({
44
59
  otelTracer,
@@ -1,3 +1,3 @@
1
- export * from './fixture.js'
2
- export * from './otel.js'
3
- export * as RG from '../../reactive.js'
1
+ export * as RG from '../../reactive.ts'
2
+ export * from './fixture.ts'
3
+ export * from './otel.ts'
@@ -1,6 +1,7 @@
1
1
  import { identity } from '@livestore/utils/effect'
2
2
  import type { Attributes } from '@opentelemetry/api'
3
3
  import type { InMemorySpanExporter, ReadableSpan } from '@opentelemetry/sdk-trace-base'
4
+
4
5
  type SimplifiedNestedSpan = { _name: string; attributes: any; children: SimplifiedNestedSpan[] }
5
6
 
6
7
  export const getSimplifiedRootSpan = (