@livestore/livestore 0.0.0-snapshot-8fd59846e2580d37bdd37ae607e9db2a458a8b63 → 0.0.0-snapshot-9d9745f6fc391ab1a695b44e8fad6c460c7b3b77

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 (105) 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 +3 -4
  5. package/dist/QueryCache.js.map +1 -1
  6. package/dist/SqliteDbWrapper.d.ts +3 -2
  7. package/dist/SqliteDbWrapper.d.ts.map +1 -1
  8. package/dist/SqliteDbWrapper.js +9 -6
  9. package/dist/SqliteDbWrapper.js.map +1 -1
  10. package/dist/SqliteDbWrapper.test.js +1 -1
  11. package/dist/effect/LiveStore.d.ts +2 -2
  12. package/dist/effect/LiveStore.js +2 -2
  13. package/dist/effect/LiveStore.js.map +1 -1
  14. package/dist/effect/mod.d.ts +2 -2
  15. package/dist/effect/mod.d.ts.map +1 -1
  16. package/dist/effect/mod.js +2 -2
  17. package/dist/effect/mod.js.map +1 -1
  18. package/dist/internal/mod.d.ts +2 -2
  19. package/dist/internal/mod.js +2 -2
  20. package/dist/live-queries/base-class.d.ts +4 -4
  21. package/dist/live-queries/base-class.d.ts.map +1 -1
  22. package/dist/live-queries/base-class.js +1 -1
  23. package/dist/live-queries/base-class.js.map +1 -1
  24. package/dist/live-queries/client-document-get-query.d.ts +1 -1
  25. package/dist/live-queries/computed.d.ts +4 -4
  26. package/dist/live-queries/computed.js +2 -2
  27. package/dist/live-queries/db-query.d.ts +4 -4
  28. package/dist/live-queries/db-query.js +4 -4
  29. package/dist/live-queries/db-query.test.js +19 -17
  30. package/dist/live-queries/db-query.test.js.map +1 -1
  31. package/dist/live-queries/mod.d.ts +4 -4
  32. package/dist/live-queries/mod.js +4 -4
  33. package/dist/live-queries/signal.d.ts +4 -4
  34. package/dist/live-queries/signal.js +1 -1
  35. package/dist/live-queries/signal.test.js +3 -3
  36. package/dist/mod.d.ts +10 -10
  37. package/dist/mod.d.ts.map +1 -1
  38. package/dist/mod.js +9 -9
  39. package/dist/mod.js.map +1 -1
  40. package/dist/reactive.d.ts.map +1 -1
  41. package/dist/reactive.js +2 -3
  42. package/dist/reactive.js.map +1 -1
  43. package/dist/reactive.test.js +1 -1
  44. package/dist/store/create-store.d.ts +6 -3
  45. package/dist/store/create-store.d.ts.map +1 -1
  46. package/dist/store/create-store.js +3 -2
  47. package/dist/store/create-store.js.map +1 -1
  48. package/dist/store/devtools.d.ts +3 -3
  49. package/dist/store/devtools.js +2 -2
  50. package/dist/store/store-types.d.ts +7 -4
  51. package/dist/store/store-types.d.ts.map +1 -1
  52. package/dist/store/store-types.js.map +1 -1
  53. package/dist/store/store.d.ts +11 -10
  54. package/dist/store/store.d.ts.map +1 -1
  55. package/dist/store/store.js +18 -9
  56. package/dist/store/store.js.map +1 -1
  57. package/dist/utils/dev.d.ts.map +1 -1
  58. package/dist/utils/dev.js +0 -1
  59. package/dist/utils/dev.js.map +1 -1
  60. package/dist/utils/stack-info.d.ts.map +1 -1
  61. package/dist/utils/stack-info.js +5 -1
  62. package/dist/utils/stack-info.js.map +1 -1
  63. package/dist/utils/stack-info.test.js +7 -3
  64. package/dist/utils/stack-info.test.js.map +1 -1
  65. package/dist/utils/tests/fixture.d.ts +33 -2
  66. package/dist/utils/tests/fixture.d.ts.map +1 -1
  67. package/dist/utils/tests/fixture.js +16 -3
  68. package/dist/utils/tests/fixture.js.map +1 -1
  69. package/dist/utils/tests/mod.d.ts +3 -3
  70. package/dist/utils/tests/mod.d.ts.map +1 -1
  71. package/dist/utils/tests/mod.js +3 -3
  72. package/dist/utils/tests/mod.js.map +1 -1
  73. package/dist/utils/tests/otel.d.ts.map +1 -1
  74. package/dist/utils/tests/otel.js +1 -1
  75. package/dist/utils/tests/otel.js.map +1 -1
  76. package/package.json +12 -38
  77. package/src/QueryCache.ts +6 -8
  78. package/src/SqliteDbWrapper.test.ts +1 -1
  79. package/src/SqliteDbWrapper.ts +13 -12
  80. package/src/ambient.d.ts +0 -2
  81. package/src/effect/LiveStore.ts +3 -3
  82. package/src/effect/mod.ts +4 -4
  83. package/src/internal/mod.ts +2 -2
  84. package/src/live-queries/__snapshots__/db-query.test.ts.snap +14 -14
  85. package/src/live-queries/base-class.ts +11 -10
  86. package/src/live-queries/client-document-get-query.ts +1 -1
  87. package/src/live-queries/computed.ts +5 -5
  88. package/src/live-queries/db-query.test.ts +21 -17
  89. package/src/live-queries/db-query.ts +7 -7
  90. package/src/live-queries/mod.ts +4 -4
  91. package/src/live-queries/signal.test.ts +3 -3
  92. package/src/live-queries/signal.ts +4 -4
  93. package/src/mod.ts +33 -39
  94. package/src/reactive.test.ts +1 -1
  95. package/src/reactive.ts +2 -4
  96. package/src/store/create-store.ts +8 -3
  97. package/src/store/devtools.ts +5 -5
  98. package/src/store/store-types.ts +13 -4
  99. package/src/store/store.ts +29 -18
  100. package/src/utils/dev.ts +0 -1
  101. package/src/utils/stack-info.test.ts +7 -3
  102. package/src/utils/stack-info.ts +5 -1
  103. package/src/utils/tests/fixture.ts +18 -3
  104. package/src/utils/tests/mod.ts +3 -3
  105. package/src/utils/tests/otel.ts +2 -1
@@ -1,12 +1,7 @@
1
1
  import {
2
+ type Bindable,
2
3
  type ClientSession,
3
4
  type ClientSessionSyncProcessor,
4
- type ParamsObject,
5
- type PreparedBindValues,
6
- type QueryBuilder,
7
- UnexpectedError,
8
- } from '@livestore/common'
9
- import {
10
5
  Devtools,
11
6
  getDurationMsFromSpan,
12
7
  getExecStatementsFromMaterializer,
@@ -16,9 +11,12 @@ import {
16
11
  isQueryBuilder,
17
12
  liveStoreVersion,
18
13
  makeClientSessionSyncProcessor,
14
+ type PreparedBindValues,
19
15
  prepareBindValues,
16
+ type QueryBuilder,
20
17
  QueryBuilderAstSymbol,
21
18
  replaceSessionIdSymbol,
19
+ UnexpectedError,
22
20
  } from '@livestore/common'
23
21
  import type { LiveStoreSchema } from '@livestore/common/schema'
24
22
  import { getEventDef, LiveStoreEvent, SystemTables } from '@livestore/common/schema'
@@ -34,15 +32,15 @@ import type {
34
32
  ReactivityGraph,
35
33
  ReactivityGraphContext,
36
34
  SignalDef,
37
- } from '../live-queries/base-class.js'
38
- import { makeReactivityGraph } from '../live-queries/base-class.js'
39
- import { makeExecBeforeFirstRun } from '../live-queries/client-document-get-query.js'
40
- import { queryDb } from '../live-queries/db-query.js'
41
- import type { Ref } from '../reactive.js'
42
- import { SqliteDbWrapper } from '../SqliteDbWrapper.js'
43
- import { ReferenceCountedSet } from '../utils/data-structures.js'
44
- import { downloadBlob, exposeDebugUtils } from '../utils/dev.js'
45
- 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'
46
44
  import type {
47
45
  RefreshReason,
48
46
  StoreCommitOptions,
@@ -50,7 +48,7 @@ import type {
50
48
  StoreOptions,
51
49
  StoreOtel,
52
50
  Unsubscribe,
53
- } from './store-types.js'
51
+ } from './store-types.ts'
54
52
 
55
53
  if (isDevEnv()) {
56
54
  exposeDebugUtils()
@@ -164,6 +162,8 @@ export class Store<TSchema extends LiveStoreSchema = LiveStoreSchema, TContext =
164
162
  for (const table of writeTables) {
165
163
  writeTablesForEvent.add(table)
166
164
  }
165
+
166
+ this.sqliteDbWrapper.debug.head = eventDecoded.seqNum
167
167
  }
168
168
  }
169
169
 
@@ -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
  })
@@ -413,13 +414,17 @@ export class Store<TSchema extends LiveStoreSchema = LiveStoreSchema, TContext =
413
414
  | LiveQuery<TResult>
414
415
  | LiveQueryDef<TResult>
415
416
  | SignalDef<TResult>
416
- | { query: string; bindValues: ParamsObject },
417
+ | { query: string; bindValues: Bindable; schema?: Schema.Schema<TResult> },
417
418
  options?: { otelContext?: otel.Context; debugRefreshReason?: RefreshReason },
418
419
  ): TResult => {
419
420
  if (typeof query === 'object' && 'query' in query && 'bindValues' in query) {
420
- return this.sqliteDbWrapper.cachedSelect(query.query, prepareBindValues(query.bindValues, query.query), {
421
+ const res = this.sqliteDbWrapper.cachedSelect(query.query, prepareBindValues(query.bindValues, query.query), {
421
422
  otelContext: options?.otelContext,
422
423
  }) as any
424
+ if (query.schema) {
425
+ return Schema.decodeSync(query.schema)(res)
426
+ }
427
+ return res
423
428
  } else if (isQueryBuilder(query)) {
424
429
  const ast = query[QueryBuilderAstSymbol]
425
430
  if (ast._tag === 'RowQuery') {
@@ -433,6 +438,12 @@ export class Store<TSchema extends LiveStoreSchema = LiveStoreSchema, TContext =
433
438
 
434
439
  const sqlRes = query.asSql()
435
440
  const schema = getResultSchema(query)
441
+
442
+ // Replace SessionIdSymbol in bind values before executing the query
443
+ if (sqlRes.bindValues) {
444
+ replaceSessionIdSymbol(sqlRes.bindValues, this.clientSession.sessionId)
445
+ }
446
+
436
447
  const rawRes = this.sqliteDbWrapper.cachedSelect(sqlRes.query, sqlRes.bindValues as any as PreparedBindValues, {
437
448
  otelContext: options?.otelContext,
438
449
  queriedTables: new Set([query[QueryBuilderAstSymbol].tableDef.sqliteDef.name]),
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 = `\
@@ -19,7 +19,9 @@ Error
19
19
 
20
20
  const stackInfo = extractStackInfoFromStackTrace(stackTrace)
21
21
  // Replacing file paths for snapshot testing as they are not stable
22
- stackInfo.frames.forEach((_) => (_.filePath = '__REPLACED_FOR_SNAPSHOT__'))
22
+ stackInfo.frames.forEach((_) => {
23
+ _.filePath = '__REPLACED_FOR_SNAPSHOT__'
24
+ })
23
25
  expect(stackInfo).toMatchInlineSnapshot(`
24
26
  {
25
27
  "frames": [
@@ -61,7 +63,9 @@ Error
61
63
 
62
64
  const stackInfo = extractStackInfoFromStackTrace(stackTrace)
63
65
  // Replacing file paths for snapshot testing as they are not stable
64
- stackInfo.frames.forEach((_) => (_.filePath = '__REPLACED_FOR_SNAPSHOT__'))
66
+ stackInfo.frames.forEach((_) => {
67
+ _.filePath = '__REPLACED_FOR_SNAPSHOT__'
68
+ })
65
69
  expect(stackInfo).toMatchInlineSnapshot(`
66
70
  {
67
71
  "frames": [
@@ -32,7 +32,11 @@ export const extractStackInfoFromStackTrace = (stackTrace: string): StackInfo =>
32
32
  const frames: StackFrame[] = []
33
33
  let hasReachedStart = false
34
34
 
35
- while ((match = namePattern.exec(stackTrace)) !== null) {
35
+ while (true) {
36
+ match = namePattern.exec(stackTrace)
37
+ if (match === null) {
38
+ break
39
+ }
36
40
  const [, name, filePath] = match as any as [string, string, string]
37
41
  // console.debug(name, filePath)
38
42
 
@@ -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 = (
@@ -24,7 +25,7 @@ export const getSimplifiedRootSpan = (
24
25
  const createStoreSpanData = spans.find((_) => _.name === 'createStore')
25
26
  if (createStoreSpanData === undefined) {
26
27
  throw new Error(
27
- "Could not find the root span named 'createStore'. Available spans: " + spans.map((s) => s.name).join(', '),
28
+ `Could not find the root span named 'createStore'. Available spans: ${spans.map((s) => s.name).join(', ')}`,
28
29
  )
29
30
  }
30
31
  const rootSpan = spansMap.get(createStoreSpanData.spanContext().spanId)!