@livestore/livestore 0.3.0-dev.33 → 0.3.0-dev.34
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/live-queries/base-class.d.ts +2 -0
- package/dist/live-queries/base-class.d.ts.map +1 -1
- package/dist/live-queries/base-class.js.map +1 -1
- package/dist/live-queries/computed.d.ts +3 -1
- package/dist/live-queries/computed.d.ts.map +1 -1
- package/dist/live-queries/computed.js +6 -2
- package/dist/live-queries/computed.js.map +1 -1
- package/dist/live-queries/db-query.d.ts +3 -1
- package/dist/live-queries/db-query.d.ts.map +1 -1
- package/dist/live-queries/db-query.js +6 -2
- package/dist/live-queries/db-query.js.map +1 -1
- package/dist/live-queries/db-query.test.js +1 -1
- package/dist/live-queries/db-query.test.js.map +1 -1
- package/dist/store/devtools.d.ts.map +1 -1
- package/dist/store/devtools.js +1 -0
- package/dist/store/devtools.js.map +1 -1
- package/dist/store/store.d.ts.map +1 -1
- package/dist/store/store.js +7 -10
- package/dist/store/store.js.map +1 -1
- package/dist/utils/tests/fixture.d.ts +4 -4
- package/package.json +10 -4
- package/src/live-queries/base-class.ts +3 -0
- package/src/live-queries/computed.ts +8 -1
- package/src/live-queries/db-query.test.ts +1 -1
- package/src/live-queries/db-query.ts +8 -1
- package/src/store/devtools.ts +1 -0
- package/src/store/store.ts +7 -20
- package/tmp/pack.tgz +0 -0
- package/tsconfig.json +0 -17
- package/vitest.config.js +0 -9
@@ -19,7 +19,7 @@ export const computed = <TResult>(
|
|
19
19
|
throw new Error(`On Expo/React Native, computed queries must provide a \`deps\` option`)
|
20
20
|
}
|
21
21
|
|
22
|
-
|
22
|
+
const def: LiveQueryDef.Any = {
|
23
23
|
_tag: 'def',
|
24
24
|
make: withRCMap(hash, (ctx, _otelContext) => {
|
25
25
|
// TODO onDestroy
|
@@ -27,6 +27,7 @@ export const computed = <TResult>(
|
|
27
27
|
fn,
|
28
28
|
label: options?.label ?? fn.toString(),
|
29
29
|
reactivityGraph: ctx.reactivityGraph.deref()!,
|
30
|
+
def,
|
30
31
|
})
|
31
32
|
}),
|
32
33
|
label: options?.label ?? fn.toString(),
|
@@ -35,6 +36,8 @@ export const computed = <TResult>(
|
|
35
36
|
// NOTE `fn.toString()` doesn't work in Expo as it always produces `[native code]`
|
36
37
|
hash,
|
37
38
|
}
|
39
|
+
|
40
|
+
return def
|
38
41
|
}
|
39
42
|
|
40
43
|
export class LiveStoreComputedQuery<TResult> extends LiveStoreQueryBase<TResult> {
|
@@ -46,20 +49,24 @@ export class LiveStoreComputedQuery<TResult> extends LiveStoreQueryBase<TResult>
|
|
46
49
|
label: string
|
47
50
|
|
48
51
|
reactivityGraph: ReactivityGraph
|
52
|
+
def: LiveQueryDef<TResult>
|
49
53
|
|
50
54
|
constructor({
|
51
55
|
fn,
|
52
56
|
label,
|
53
57
|
reactivityGraph,
|
58
|
+
def,
|
54
59
|
}: {
|
55
60
|
label: string
|
56
61
|
fn: (get: GetAtomResult) => TResult
|
57
62
|
reactivityGraph: ReactivityGraph
|
63
|
+
def: LiveQueryDef<TResult>
|
58
64
|
}) {
|
59
65
|
super()
|
60
66
|
|
61
67
|
this.label = label
|
62
68
|
this.reactivityGraph = reactivityGraph
|
69
|
+
this.def = def
|
63
70
|
|
64
71
|
const queryLabel = `${label}:results`
|
65
72
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { sql } from '@livestore/common'
|
2
2
|
import { rawSqlEvent } from '@livestore/common/schema'
|
3
3
|
import { Effect, ReadonlyRecord, Schema } from '@livestore/utils/effect'
|
4
|
-
import { Vitest } from '@livestore/utils/node-vitest'
|
4
|
+
import { Vitest } from '@livestore/utils-dev/node-vitest'
|
5
5
|
import * as otel from '@opentelemetry/api'
|
6
6
|
import { BasicTracerProvider, InMemorySpanExporter, SimpleSpanProcessor } from '@opentelemetry/sdk-trace-base'
|
7
7
|
import { expect } from 'vitest'
|
@@ -85,7 +85,7 @@ export const queryDb: {
|
|
85
85
|
|
86
86
|
const label = options?.label ?? queryString
|
87
87
|
|
88
|
-
|
88
|
+
const def: LiveQueryDef.Any = {
|
89
89
|
_tag: 'def',
|
90
90
|
make: withRCMap(hash, (ctx, otelContext) => {
|
91
91
|
// TODO onDestroy
|
@@ -95,11 +95,14 @@ export const queryDb: {
|
|
95
95
|
label,
|
96
96
|
map: options?.map,
|
97
97
|
otelContext,
|
98
|
+
def,
|
98
99
|
})
|
99
100
|
}),
|
100
101
|
label,
|
101
102
|
hash,
|
102
103
|
}
|
104
|
+
|
105
|
+
return def
|
103
106
|
}
|
104
107
|
|
105
108
|
const bindValuesToDepKey = (bindValues: Bindable | undefined): DepKey => {
|
@@ -146,6 +149,7 @@ export class LiveStoreDbQuery<TResultSchema, TResult = TResultSchema> extends Li
|
|
146
149
|
readonly reactivityGraph
|
147
150
|
|
148
151
|
private mapResult: (rows: TResultSchema) => TResult
|
152
|
+
def: LiveQueryDef<TResult>
|
149
153
|
|
150
154
|
constructor({
|
151
155
|
queryInput,
|
@@ -153,6 +157,7 @@ export class LiveStoreDbQuery<TResultSchema, TResult = TResultSchema> extends Li
|
|
153
157
|
reactivityGraph,
|
154
158
|
map,
|
155
159
|
otelContext,
|
160
|
+
def,
|
156
161
|
}: {
|
157
162
|
label?: string
|
158
163
|
queryInput:
|
@@ -162,11 +167,13 @@ export class LiveStoreDbQuery<TResultSchema, TResult = TResultSchema> extends Li
|
|
162
167
|
map?: (rows: TResultSchema) => TResult
|
163
168
|
/** Only used for the initial query execution */
|
164
169
|
otelContext?: otel.Context
|
170
|
+
def: LiveQueryDef<TResult>
|
165
171
|
}) {
|
166
172
|
super()
|
167
173
|
|
168
174
|
let label = inputLabel ?? 'db(unknown)'
|
169
175
|
this.reactivityGraph = reactivityGraph
|
176
|
+
this.def = def
|
170
177
|
|
171
178
|
this.mapResult = map === undefined ? (rows: any) => rows as TResult : map
|
172
179
|
|
package/src/store/devtools.ts
CHANGED
package/src/store/store.ts
CHANGED
@@ -20,14 +20,7 @@ import {
|
|
20
20
|
replaceSessionIdSymbol,
|
21
21
|
} from '@livestore/common'
|
22
22
|
import type { LiveStoreSchema } from '@livestore/common/schema'
|
23
|
-
import {
|
24
|
-
getEventDef,
|
25
|
-
LEADER_MERGE_COUNTER_TABLE,
|
26
|
-
LiveStoreEvent,
|
27
|
-
SCHEMA_EVENT_DEFS_META_TABLE,
|
28
|
-
SCHEMA_META_TABLE,
|
29
|
-
SESSION_CHANGESET_META_TABLE,
|
30
|
-
} from '@livestore/common/schema'
|
23
|
+
import { getEventDef, LiveStoreEvent, SystemTables } from '@livestore/common/schema'
|
31
24
|
import { assertNever, isDevEnv } from '@livestore/utils'
|
32
25
|
import type { Scope } from '@livestore/utils/effect'
|
33
26
|
import { Cause, Effect, Inspectable, OtelTracer, Runtime, Schema, Stream } from '@livestore/utils/effect'
|
@@ -114,7 +107,7 @@ export class Store<TSchema extends LiveStoreSchema = LiveStoreSchema, TContext =
|
|
114
107
|
schema,
|
115
108
|
clientSession,
|
116
109
|
runtime: effectContext.runtime,
|
117
|
-
|
110
|
+
materializeEvent: (eventDecoded, { otelContext, withChangeset }) => {
|
118
111
|
const eventDef = getEventDef(schema, eventDecoded.name)
|
119
112
|
|
120
113
|
const execArgsArr = getExecArgsFromEvent({
|
@@ -201,14 +194,8 @@ export class Store<TSchema extends LiveStoreSchema = LiveStoreSchema, TContext =
|
|
201
194
|
// NOTE we're excluding the LiveStore schema and events tables as they are not user-facing
|
202
195
|
// unless LiveStore is running in the devtools
|
203
196
|
__runningInDevtools
|
204
|
-
? this.schema.tables.keys()
|
205
|
-
: Array.from(this.schema.tables.keys()).filter(
|
206
|
-
(_) =>
|
207
|
-
_ !== SCHEMA_META_TABLE &&
|
208
|
-
_ !== SCHEMA_EVENT_DEFS_META_TABLE &&
|
209
|
-
_ !== SESSION_CHANGESET_META_TABLE &&
|
210
|
-
_ !== LEADER_MERGE_COUNTER_TABLE,
|
211
|
-
),
|
197
|
+
? this.schema.state.sqlite.tables.keys()
|
198
|
+
: Array.from(this.schema.state.sqlite.tables.keys()).filter((_) => !SystemTables.isStateSystemTable(_)),
|
212
199
|
)
|
213
200
|
const existingTableRefs = new Map(
|
214
201
|
Array.from(this.reactivityGraph.atoms.values())
|
@@ -540,13 +527,13 @@ export class Store<TSchema extends LiveStoreSchema = LiveStoreSchema, TContext =
|
|
540
527
|
try {
|
541
528
|
const { writeTables } = (() => {
|
542
529
|
try {
|
543
|
-
const
|
530
|
+
const materializeEvents = () => this.syncProcessor.push(events, { otelContext })
|
544
531
|
|
545
532
|
if (events.length > 1) {
|
546
533
|
// TODO: what to do about leader transaction here?
|
547
|
-
return this.sqliteDbWrapper.txn(
|
534
|
+
return this.sqliteDbWrapper.txn(materializeEvents)
|
548
535
|
} else {
|
549
|
-
return
|
536
|
+
return materializeEvents()
|
550
537
|
}
|
551
538
|
} catch (e: any) {
|
552
539
|
console.error(e)
|
package/tmp/pack.tgz
DELETED
Binary file
|
package/tsconfig.json
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"extends": "../../../tsconfig.base.json",
|
3
|
-
"compilerOptions": {
|
4
|
-
"outDir": "./dist",
|
5
|
-
"rootDir": "./src",
|
6
|
-
"skipLibCheck": true,
|
7
|
-
"resolveJsonModule": true,
|
8
|
-
// "jsx": "preserve",
|
9
|
-
"tsBuildInfoFile": "./dist/.tsbuildinfo"
|
10
|
-
},
|
11
|
-
"include": ["./src"],
|
12
|
-
"references": [
|
13
|
-
{ "path": "../common" },
|
14
|
-
{ "path": "../adapter-web" },
|
15
|
-
{ "path": "../utils" }
|
16
|
-
]
|
17
|
-
}
|