@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.
- package/dist/.tsbuildinfo +1 -1
- package/dist/QueryCache.d.ts +4 -6
- package/dist/QueryCache.d.ts.map +1 -1
- package/dist/QueryCache.js +3 -4
- package/dist/QueryCache.js.map +1 -1
- package/dist/SqliteDbWrapper.d.ts +3 -2
- package/dist/SqliteDbWrapper.d.ts.map +1 -1
- package/dist/SqliteDbWrapper.js +9 -6
- package/dist/SqliteDbWrapper.js.map +1 -1
- package/dist/SqliteDbWrapper.test.js +1 -1
- package/dist/effect/LiveStore.d.ts +2 -2
- package/dist/effect/LiveStore.js +2 -2
- package/dist/effect/LiveStore.js.map +1 -1
- package/dist/effect/mod.d.ts +2 -2
- package/dist/effect/mod.d.ts.map +1 -1
- package/dist/effect/mod.js +2 -2
- package/dist/effect/mod.js.map +1 -1
- package/dist/internal/mod.d.ts +2 -2
- package/dist/internal/mod.js +2 -2
- package/dist/live-queries/base-class.d.ts +4 -4
- package/dist/live-queries/base-class.d.ts.map +1 -1
- package/dist/live-queries/base-class.js +1 -1
- package/dist/live-queries/base-class.js.map +1 -1
- package/dist/live-queries/client-document-get-query.d.ts +1 -1
- package/dist/live-queries/computed.d.ts +4 -4
- package/dist/live-queries/computed.js +2 -2
- package/dist/live-queries/db-query.d.ts +4 -4
- package/dist/live-queries/db-query.js +4 -4
- package/dist/live-queries/db-query.test.js +19 -17
- package/dist/live-queries/db-query.test.js.map +1 -1
- package/dist/live-queries/mod.d.ts +4 -4
- package/dist/live-queries/mod.js +4 -4
- package/dist/live-queries/signal.d.ts +4 -4
- package/dist/live-queries/signal.js +1 -1
- package/dist/live-queries/signal.test.js +3 -3
- package/dist/mod.d.ts +10 -10
- package/dist/mod.d.ts.map +1 -1
- package/dist/mod.js +9 -9
- package/dist/mod.js.map +1 -1
- package/dist/reactive.d.ts.map +1 -1
- package/dist/reactive.js +2 -3
- package/dist/reactive.js.map +1 -1
- package/dist/reactive.test.js +1 -1
- package/dist/store/create-store.d.ts +6 -3
- package/dist/store/create-store.d.ts.map +1 -1
- package/dist/store/create-store.js +3 -2
- package/dist/store/create-store.js.map +1 -1
- package/dist/store/devtools.d.ts +3 -3
- package/dist/store/devtools.js +2 -2
- package/dist/store/store-types.d.ts +7 -4
- package/dist/store/store-types.d.ts.map +1 -1
- package/dist/store/store-types.js.map +1 -1
- package/dist/store/store.d.ts +11 -10
- package/dist/store/store.d.ts.map +1 -1
- package/dist/store/store.js +18 -9
- package/dist/store/store.js.map +1 -1
- package/dist/utils/dev.d.ts.map +1 -1
- package/dist/utils/dev.js +0 -1
- package/dist/utils/dev.js.map +1 -1
- package/dist/utils/stack-info.d.ts.map +1 -1
- package/dist/utils/stack-info.js +5 -1
- package/dist/utils/stack-info.js.map +1 -1
- package/dist/utils/stack-info.test.js +7 -3
- package/dist/utils/stack-info.test.js.map +1 -1
- package/dist/utils/tests/fixture.d.ts +33 -2
- package/dist/utils/tests/fixture.d.ts.map +1 -1
- package/dist/utils/tests/fixture.js +16 -3
- package/dist/utils/tests/fixture.js.map +1 -1
- package/dist/utils/tests/mod.d.ts +3 -3
- package/dist/utils/tests/mod.d.ts.map +1 -1
- package/dist/utils/tests/mod.js +3 -3
- package/dist/utils/tests/mod.js.map +1 -1
- package/dist/utils/tests/otel.d.ts.map +1 -1
- package/dist/utils/tests/otel.js +1 -1
- package/dist/utils/tests/otel.js.map +1 -1
- package/package.json +12 -38
- package/src/QueryCache.ts +6 -8
- package/src/SqliteDbWrapper.test.ts +1 -1
- package/src/SqliteDbWrapper.ts +13 -12
- package/src/ambient.d.ts +0 -2
- package/src/effect/LiveStore.ts +3 -3
- package/src/effect/mod.ts +4 -4
- package/src/internal/mod.ts +2 -2
- package/src/live-queries/__snapshots__/db-query.test.ts.snap +14 -14
- package/src/live-queries/base-class.ts +11 -10
- package/src/live-queries/client-document-get-query.ts +1 -1
- package/src/live-queries/computed.ts +5 -5
- package/src/live-queries/db-query.test.ts +21 -17
- package/src/live-queries/db-query.ts +7 -7
- package/src/live-queries/mod.ts +4 -4
- package/src/live-queries/signal.test.ts +3 -3
- package/src/live-queries/signal.ts +4 -4
- package/src/mod.ts +33 -39
- package/src/reactive.test.ts +1 -1
- package/src/reactive.ts +2 -4
- package/src/store/create-store.ts +8 -3
- package/src/store/devtools.ts +5 -5
- package/src/store/store-types.ts +13 -4
- package/src/store/store.ts +29 -18
- package/src/utils/dev.ts +0 -1
- package/src/utils/stack-info.test.ts +7 -3
- package/src/utils/stack-info.ts +5 -1
- package/src/utils/tests/fixture.ts +18 -3
- package/src/utils/tests/mod.ts +3 -3
- package/src/utils/tests/otel.ts +2 -1
package/src/store/store.ts
CHANGED
|
@@ -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.
|
|
38
|
-
import { makeReactivityGraph } from '../live-queries/base-class.
|
|
39
|
-
import { makeExecBeforeFirstRun } from '../live-queries/client-document-get-query.
|
|
40
|
-
import { queryDb } from '../live-queries/db-query.
|
|
41
|
-
import type { Ref } from '../reactive.
|
|
42
|
-
import { SqliteDbWrapper } from '../SqliteDbWrapper.
|
|
43
|
-
import { ReferenceCountedSet } from '../utils/data-structures.
|
|
44
|
-
import { downloadBlob, exposeDebugUtils } from '../utils/dev.
|
|
45
|
-
import type { StackInfo } from '../utils/stack-info.
|
|
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.
|
|
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:
|
|
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
|
-
|
|
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,6 +1,6 @@
|
|
|
1
1
|
import { expect, it } from 'vitest'
|
|
2
2
|
|
|
3
|
-
import { extractStackInfoFromStackTrace } from './stack-info.
|
|
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((_) =>
|
|
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((_) =>
|
|
66
|
+
stackInfo.frames.forEach((_) => {
|
|
67
|
+
_.filePath = '__REPLACED_FOR_SNAPSHOT__'
|
|
68
|
+
})
|
|
65
69
|
expect(stackInfo).toMatchInlineSnapshot(`
|
|
66
70
|
{
|
|
67
71
|
"frames": [
|
package/src/utils/stack-info.ts
CHANGED
|
@@ -32,7 +32,11 @@ export const extractStackInfoFromStackTrace = (stackTrace: string): StackInfo =>
|
|
|
32
32
|
const frames: StackFrame[] = []
|
|
33
33
|
let hasReachedStart = false
|
|
34
34
|
|
|
35
|
-
while (
|
|
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
|
|
41
|
-
|
|
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,
|
package/src/utils/tests/mod.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from '
|
|
2
|
-
export * from './
|
|
3
|
-
export *
|
|
1
|
+
export * as RG from '../../reactive.ts'
|
|
2
|
+
export * from './fixture.ts'
|
|
3
|
+
export * from './otel.ts'
|
package/src/utils/tests/otel.ts
CHANGED
|
@@ -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
|
-
|
|
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)!
|