@livestore/livestore 0.3.2-dev.1 → 0.3.2-dev.11
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 +5 -0
- 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/computed.d.ts.map +1 -1
- package/dist/live-queries/computed.js +7 -0
- package/dist/live-queries/computed.js.map +1 -1
- package/dist/live-queries/db-query.d.ts.map +1 -1
- package/dist/live-queries/db-query.js +12 -2
- package/dist/live-queries/db-query.js.map +1 -1
- package/dist/live-queries/db-query.test.js +8 -10
- package/dist/live-queries/db-query.test.js.map +1 -1
- package/dist/live-queries/signal.d.ts.map +1 -1
- package/dist/live-queries/signal.js +7 -0
- package/dist/live-queries/signal.js.map +1 -1
- package/dist/mod.d.ts +2 -1
- package/dist/mod.d.ts.map +1 -1
- package/dist/mod.js +1 -0
- package/dist/mod.js.map +1 -1
- package/dist/reactive.d.ts.map +1 -1
- package/dist/reactive.js +2 -0
- package/dist/reactive.js.map +1 -1
- package/dist/store/create-store.d.ts +5 -7
- package/dist/store/create-store.d.ts.map +1 -1
- package/dist/store/create-store.js +4 -4
- package/dist/store/create-store.js.map +1 -1
- package/dist/store/store-shutdown.test.d.ts +2 -0
- package/dist/store/store-shutdown.test.d.ts.map +1 -0
- package/dist/store/store-shutdown.test.js +103 -0
- package/dist/store/store-shutdown.test.js.map +1 -0
- package/dist/store/store-types.d.ts +4 -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 -2
- package/dist/store/store.d.ts.map +1 -1
- package/dist/store/store.js +76 -43
- package/dist/store/store.js.map +1 -1
- package/dist/utils/dev.d.ts.map +1 -1
- package/dist/utils/dev.js +14 -8
- package/dist/utils/dev.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/package.json +12 -38
- package/src/live-queries/__snapshots__/db-query.test.ts.snap +14 -14
- package/src/live-queries/base-class.ts +5 -1
- package/src/live-queries/computed.ts +7 -0
- package/src/live-queries/db-query.test.ts +8 -10
- package/src/live-queries/db-query.ts +12 -3
- package/src/live-queries/signal.ts +7 -0
- package/src/mod.ts +2 -1
- package/src/reactive.ts +2 -0
- package/src/store/create-store.ts +18 -16
- package/src/store/store-types.ts +9 -5
- package/src/store/store.ts +67 -8
- package/src/utils/dev.ts +14 -7
- package/src/utils/tests/fixture.ts +18 -3
package/dist/utils/dev.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"dev.js","sourceRoot":"","sources":["../../src/utils/dev.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"dev.js","sourceRoot":"","sources":["../../src/utils/dev.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAEhD,MAAM,CAAC,MAAM,YAAY,GAAG,CAC1B,IAAgC,EAChC,QAAgB,EAChB,QAAQ,GAAG,0BAA0B,EACrC,EAAE;IACF,MAAM,IAAI,GAAG,IAAI,YAAY,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAA;IAE/E,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC,IAAI,CAAC,CAAA;IAE5C,WAAW,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAA;IAE1B,UAAU,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC,GAAG,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F,CAAA;AACH,CAAC,CAAA"}
|
@@ -113,16 +113,47 @@ export declare const tables: {
|
|
113
113
|
};
|
114
114
|
}>;
|
115
115
|
};
|
116
|
+
export declare const events: {
|
117
|
+
todoCreated: State.SQLite.EventDef<"todo.created", {
|
118
|
+
readonly id: string;
|
119
|
+
readonly text: string;
|
120
|
+
readonly completed: boolean;
|
121
|
+
}, {
|
122
|
+
readonly id: string;
|
123
|
+
readonly text: string;
|
124
|
+
readonly completed: boolean;
|
125
|
+
}, false>;
|
126
|
+
};
|
116
127
|
export declare const state: import("@livestore/livestore").InternalState;
|
117
128
|
export declare const schema: import("@livestore/livestore").FromInputSchema.DeriveSchema<{
|
118
129
|
state: import("@livestore/livestore").InternalState;
|
119
|
-
events: {
|
130
|
+
events: {
|
131
|
+
todoCreated: State.SQLite.EventDef<"todo.created", {
|
132
|
+
readonly id: string;
|
133
|
+
readonly text: string;
|
134
|
+
readonly completed: boolean;
|
135
|
+
}, {
|
136
|
+
readonly id: string;
|
137
|
+
readonly text: string;
|
138
|
+
readonly completed: boolean;
|
139
|
+
}, false>;
|
140
|
+
};
|
120
141
|
}>;
|
121
142
|
export declare const makeTodoMvc: ({ otelTracer, otelContext, }?: {
|
122
143
|
otelTracer?: otel.Tracer;
|
123
144
|
otelContext?: otel.Context;
|
124
145
|
}) => Effect.Effect<import("@livestore/livestore").Store<import("@livestore/livestore").FromInputSchema.DeriveSchema<{
|
125
146
|
state: import("@livestore/livestore").InternalState;
|
126
|
-
events: {
|
147
|
+
events: {
|
148
|
+
todoCreated: State.SQLite.EventDef<"todo.created", {
|
149
|
+
readonly id: string;
|
150
|
+
readonly text: string;
|
151
|
+
readonly completed: boolean;
|
152
|
+
}, {
|
153
|
+
readonly id: string;
|
154
|
+
readonly text: string;
|
155
|
+
readonly completed: boolean;
|
156
|
+
}, false>;
|
157
|
+
};
|
127
158
|
}>, {}>, import("@livestore/common").UnexpectedError, import("effect/Scope").Scope>;
|
128
159
|
//# sourceMappingURL=fixture.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"fixture.d.ts","sourceRoot":"","sources":["../../../src/utils/tests/fixture.ts"],"names":[],"mappings":"AAEA,OAAO,
|
1
|
+
{"version":3,"file":"fixture.d.ts","sourceRoot":"","sources":["../../../src/utils/tests/fixture.ts"],"names":[],"mappings":"AAEA,OAAO,EAAmC,KAAK,EAAE,MAAM,sBAAsB,CAAA;AAC7E,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,KAAK,KAAK,IAAI,MAAM,oBAAoB,CAAA;AAE/C,MAAM,MAAM,IAAI,GAAG;IACjB,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,OAAO,CAAA;CACnB,CAAA;AAED,MAAM,MAAM,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,WAAW,CAAA;AAEnD,MAAM,MAAM,QAAQ,GAAG;IACrB,WAAW,EAAE,MAAM,CAAA;IACnB,MAAM,EAAE,MAAM,CAAA;CACf,CAAA;AAED,eAAO,MAAM,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAOhB,CAAA;AAEF,eAAO,MAAM,GAAG;;;;;;;;;;;;;;;EAOd,CAAA;AAEF,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAAiB,CAAA;AAEpC,eAAO,MAAM,MAAM;;;;;;;;;;CASlB,CAAA;AAMD,eAAO,MAAM,KAAK,8CAAoD,CAAA;AACtE,eAAO,MAAM,MAAM;;;;;;;;;;;;;EAAgC,CAAA;AAEnD,eAAO,MAAM,WAAW,GAAI,+BAGzB;IACD,UAAU,CAAC,EAAE,IAAI,CAAC,MAAM,CAAA;IACxB,WAAW,CAAC,EAAE,IAAI,CAAC,OAAO,CAAA;CACtB;;;;;;;;;;;;;mFAU4E,CAAA"}
|
@@ -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
|
export const todos = State.SQLite.table({
|
6
6
|
name: 'todos',
|
@@ -19,8 +19,21 @@ export const app = State.SQLite.clientDocument({
|
|
19
19
|
default: { value: { newTodoText: '', filter: 'all' } },
|
20
20
|
});
|
21
21
|
export const tables = { todos, app };
|
22
|
-
export const
|
23
|
-
|
22
|
+
export const events = {
|
23
|
+
todoCreated: Events.synced({
|
24
|
+
name: 'todo.created',
|
25
|
+
schema: Schema.Struct({
|
26
|
+
id: Schema.String,
|
27
|
+
text: Schema.String,
|
28
|
+
completed: Schema.Boolean,
|
29
|
+
}),
|
30
|
+
}),
|
31
|
+
};
|
32
|
+
const materializers = State.SQLite.materializers(events, {
|
33
|
+
'todo.created': ({ id, text, completed }) => tables.todos.insert({ id, text, completed }),
|
34
|
+
});
|
35
|
+
export const state = State.SQLite.makeState({ tables, materializers });
|
36
|
+
export const schema = makeSchema({ state, events });
|
24
37
|
export const makeTodoMvc = ({ otelTracer, otelContext, } = {}) => Effect.gen(function* () {
|
25
38
|
const store = yield* createStore({
|
26
39
|
schema,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"fixture.js","sourceRoot":"","sources":["../../../src/utils/tests/fixture.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAA;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAA;
|
1
|
+
{"version":3,"file":"fixture.js","sourceRoot":"","sources":["../../../src/utils/tests/fixture.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,m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
4
4
|
"type": "module",
|
5
5
|
"sideEffects": false,
|
6
6
|
"exports": {
|
7
|
-
".":
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
"./internal": {
|
12
|
-
"types": "./dist/internal/mod.d.ts",
|
13
|
-
"default": "./dist/internal/mod.js"
|
14
|
-
},
|
15
|
-
"./internal/testing-utils": {
|
16
|
-
"types": "./dist/utils/tests/mod.d.ts",
|
17
|
-
"default": "./dist/utils/tests/mod.js"
|
18
|
-
},
|
19
|
-
"./effect": {
|
20
|
-
"types": "./dist/effect/mod.d.ts",
|
21
|
-
"default": "./dist/effect/mod.js"
|
22
|
-
}
|
23
|
-
},
|
24
|
-
"types": "./dist/mod.d.ts",
|
25
|
-
"typesVersions": {
|
26
|
-
"*": {
|
27
|
-
"internal": [
|
28
|
-
"./dist/internal/mod.d.ts"
|
29
|
-
],
|
30
|
-
"testing-utils": [
|
31
|
-
"./dist/utils/tests/mod.d.ts"
|
32
|
-
],
|
33
|
-
"effect": [
|
34
|
-
"./dist/effect/mod.d.ts"
|
35
|
-
]
|
36
|
-
}
|
7
|
+
".": "./dist/mod.js",
|
8
|
+
"./internal": "./dist/internal/mod.js",
|
9
|
+
"./internal/testing-utils": "./dist/utils/tests/mod.js",
|
10
|
+
"./effect": "./dist/effect/mod.js"
|
37
11
|
},
|
38
12
|
"dependencies": {
|
39
13
|
"@opentelemetry/api": "1.9.0",
|
40
|
-
"@livestore/
|
41
|
-
"@livestore/
|
14
|
+
"@livestore/common": "0.3.2-dev.11",
|
15
|
+
"@livestore/utils": "0.3.2-dev.11"
|
42
16
|
},
|
43
17
|
"devDependencies": {
|
44
|
-
"@opentelemetry/sdk-trace-base": "^2.0.
|
45
|
-
"jsdom": "^26.
|
18
|
+
"@opentelemetry/sdk-trace-base": "^2.0.1",
|
19
|
+
"jsdom": "^26.1.0",
|
46
20
|
"typescript": "^5.8.3",
|
47
|
-
"vite": "^7.0.
|
21
|
+
"vite": "^7.0.6",
|
48
22
|
"vitest": "3.2.4",
|
49
|
-
"@livestore/adapter-web": "0.3.2-dev.
|
50
|
-
"@livestore/utils-dev": "0.3.2-dev.
|
23
|
+
"@livestore/adapter-web": "0.3.2-dev.11",
|
24
|
+
"@livestore/utils-dev": "0.3.2-dev.11"
|
51
25
|
},
|
52
26
|
"files": [
|
53
27
|
"package.json",
|
@@ -45,7 +45,7 @@ exports[`otel > QueryBuilder subscription - basic functionality 1`] = `
|
|
45
45
|
"_name": "LiveStore:commit",
|
46
46
|
"attributes": {
|
47
47
|
"livestore.eventTags": [
|
48
|
-
"
|
48
|
+
"todo.created",
|
49
49
|
],
|
50
50
|
"livestore.eventsCount": 1,
|
51
51
|
},
|
@@ -53,7 +53,7 @@ exports[`otel > QueryBuilder subscription - basic functionality 1`] = `
|
|
53
53
|
{
|
54
54
|
"_name": "livestore.in-memory-db:execute",
|
55
55
|
"attributes": {
|
56
|
-
"sql.query": "INSERT INTO todos (id, text, completed) VALUES (
|
56
|
+
"sql.query": "INSERT INTO 'todos' (id, text, completed) VALUES (?, ?, ?)",
|
57
57
|
},
|
58
58
|
},
|
59
59
|
],
|
@@ -158,7 +158,7 @@ exports[`otel > QueryBuilder subscription - direct table subscription 1`] = `
|
|
158
158
|
"_name": "LiveStore:commit",
|
159
159
|
"attributes": {
|
160
160
|
"livestore.eventTags": [
|
161
|
-
"
|
161
|
+
"todo.created",
|
162
162
|
],
|
163
163
|
"livestore.eventsCount": 1,
|
164
164
|
},
|
@@ -166,7 +166,7 @@ exports[`otel > QueryBuilder subscription - direct table subscription 1`] = `
|
|
166
166
|
{
|
167
167
|
"_name": "livestore.in-memory-db:execute",
|
168
168
|
"attributes": {
|
169
|
-
"sql.query": "INSERT INTO todos (id, text, completed) VALUES (
|
169
|
+
"sql.query": "INSERT INTO 'todos' (id, text, completed) VALUES (?, ?, ?)",
|
170
170
|
},
|
171
171
|
},
|
172
172
|
],
|
@@ -278,7 +278,7 @@ exports[`otel > QueryBuilder subscription - unsubscribe functionality 1`] = `
|
|
278
278
|
"_name": "LiveStore:commit",
|
279
279
|
"attributes": {
|
280
280
|
"livestore.eventTags": [
|
281
|
-
"
|
281
|
+
"todo.created",
|
282
282
|
],
|
283
283
|
"livestore.eventsCount": 1,
|
284
284
|
},
|
@@ -286,7 +286,7 @@ exports[`otel > QueryBuilder subscription - unsubscribe functionality 1`] = `
|
|
286
286
|
{
|
287
287
|
"_name": "livestore.in-memory-db:execute",
|
288
288
|
"attributes": {
|
289
|
-
"sql.query": "INSERT INTO todos (id, text, completed) VALUES (
|
289
|
+
"sql.query": "INSERT INTO 'todos' (id, text, completed) VALUES (?, ?, ?)",
|
290
290
|
},
|
291
291
|
},
|
292
292
|
],
|
@@ -295,7 +295,7 @@ exports[`otel > QueryBuilder subscription - unsubscribe functionality 1`] = `
|
|
295
295
|
"_name": "LiveStore:commit",
|
296
296
|
"attributes": {
|
297
297
|
"livestore.eventTags": [
|
298
|
-
"
|
298
|
+
"todo.created",
|
299
299
|
],
|
300
300
|
"livestore.eventsCount": 1,
|
301
301
|
},
|
@@ -303,7 +303,7 @@ exports[`otel > QueryBuilder subscription - unsubscribe functionality 1`] = `
|
|
303
303
|
{
|
304
304
|
"_name": "livestore.in-memory-db:execute",
|
305
305
|
"attributes": {
|
306
|
-
"sql.query": "INSERT INTO todos (id, text, completed) VALUES (
|
306
|
+
"sql.query": "INSERT INTO 'todos' (id, text, completed) VALUES (?, ?, ?)",
|
307
307
|
},
|
308
308
|
},
|
309
309
|
],
|
@@ -434,7 +434,7 @@ exports[`otel > otel 3`] = `
|
|
434
434
|
"_name": "LiveStore:commit",
|
435
435
|
"attributes": {
|
436
436
|
"livestore.eventTags": [
|
437
|
-
"
|
437
|
+
"todo.created",
|
438
438
|
],
|
439
439
|
"livestore.eventsCount": 1,
|
440
440
|
},
|
@@ -442,7 +442,7 @@ exports[`otel > otel 3`] = `
|
|
442
442
|
{
|
443
443
|
"_name": "livestore.in-memory-db:execute",
|
444
444
|
"attributes": {
|
445
|
-
"sql.query": "INSERT INTO todos (id, text, completed) VALUES (
|
445
|
+
"sql.query": "INSERT INTO 'todos' (id, text, completed) VALUES (?, ?, ?)",
|
446
446
|
},
|
447
447
|
},
|
448
448
|
],
|
@@ -709,7 +709,7 @@ exports[`otel > with thunks 7`] = `
|
|
709
709
|
"_name": "LiveStore:commit",
|
710
710
|
"attributes": {
|
711
711
|
"livestore.eventTags": [
|
712
|
-
"
|
712
|
+
"todo.created",
|
713
713
|
],
|
714
714
|
"livestore.eventsCount": 1,
|
715
715
|
},
|
@@ -717,7 +717,7 @@ exports[`otel > with thunks 7`] = `
|
|
717
717
|
{
|
718
718
|
"_name": "livestore.in-memory-db:execute",
|
719
719
|
"attributes": {
|
720
|
-
"sql.query": "INSERT INTO todos (id, text, completed) VALUES (
|
720
|
+
"sql.query": "INSERT INTO 'todos' (id, text, completed) VALUES (?, ?, ?)",
|
721
721
|
},
|
722
722
|
},
|
723
723
|
],
|
@@ -818,7 +818,7 @@ exports[`otel > with thunks with query builder and without labels 3`] = `
|
|
818
818
|
"_name": "LiveStore:commit",
|
819
819
|
"attributes": {
|
820
820
|
"livestore.eventTags": [
|
821
|
-
"
|
821
|
+
"todo.created",
|
822
822
|
],
|
823
823
|
"livestore.eventsCount": 1,
|
824
824
|
},
|
@@ -826,7 +826,7 @@ exports[`otel > with thunks with query builder and without labels 3`] = `
|
|
826
826
|
{
|
827
827
|
"_name": "livestore.in-memory-db:execute",
|
828
828
|
"attributes": {
|
829
|
-
"sql.query": "INSERT INTO todos (id, text, completed) VALUES (
|
829
|
+
"sql.query": "INSERT INTO 'todos' (id, text, completed) VALUES (?, ?, ?)",
|
830
830
|
},
|
831
831
|
},
|
832
832
|
],
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { isNotNil } from '@livestore/utils'
|
2
|
-
import { Predicate } from '@livestore/utils/effect'
|
2
|
+
import { Equal, Hash, Predicate } from '@livestore/utils/effect'
|
3
3
|
import type * as otel from '@opentelemetry/api'
|
4
4
|
|
5
5
|
import * as RG from '../reactive.ts'
|
@@ -41,6 +41,8 @@ export interface SignalDef<T> extends LiveQueryDef<T, 'signal-def'> {
|
|
41
41
|
hash: string
|
42
42
|
label: string
|
43
43
|
make: (ctx: ReactivityGraphContext) => RcRef<ISignal<T>>
|
44
|
+
[Equal.symbol](that: SignalDef<T>): boolean
|
45
|
+
[Hash.symbol](): number
|
44
46
|
}
|
45
47
|
|
46
48
|
export interface ISignal<T> extends LiveQuery<T> {
|
@@ -77,6 +79,8 @@ export interface LiveQueryDef<TResult, TTag extends string = 'def'> {
|
|
77
79
|
make: (ctx: ReactivityGraphContext, otelContext?: otel.Context) => RcRef<LiveQuery<TResult> | ISignal<TResult>>
|
78
80
|
label: string
|
79
81
|
hash: string
|
82
|
+
[Equal.symbol](that: LiveQueryDef<TResult, TTag>): boolean
|
83
|
+
[Hash.symbol](): number
|
80
84
|
}
|
81
85
|
|
82
86
|
export namespace LiveQueryDef {
|
@@ -1,4 +1,5 @@
|
|
1
1
|
import { getDurationMsFromSpan } from '@livestore/common'
|
2
|
+
import { Equal, Hash } from '@livestore/utils/effect'
|
2
3
|
import * as otel from '@opentelemetry/api'
|
3
4
|
|
4
5
|
import type { Thunk } from '../reactive.ts'
|
@@ -35,6 +36,12 @@ export const computed = <TResult>(
|
|
35
36
|
// TODO we should figure out whether this could cause some problems and/or if there's a better way to do this
|
36
37
|
// NOTE `fn.toString()` doesn't work in Expo as it always produces `[native code]`
|
37
38
|
hash,
|
39
|
+
[Equal.symbol](that: LiveQueryDef<any>): boolean {
|
40
|
+
return this.hash === that.hash
|
41
|
+
},
|
42
|
+
[Hash.symbol](): number {
|
43
|
+
return Hash.string(this.hash)
|
44
|
+
},
|
38
45
|
}
|
39
46
|
|
40
47
|
return def
|
@@ -1,5 +1,3 @@
|
|
1
|
-
import { sql } from '@livestore/common'
|
2
|
-
import { rawSqlEvent } from '@livestore/common/schema'
|
3
1
|
import { Effect, ReadonlyRecord, Schema } from '@livestore/utils/effect'
|
4
2
|
import { Vitest } from '@livestore/utils-dev/node-vitest'
|
5
3
|
import * as otel from '@opentelemetry/api'
|
@@ -7,7 +5,7 @@ import { BasicTracerProvider, InMemorySpanExporter, SimpleSpanProcessor } from '
|
|
7
5
|
import { expect } from 'vitest'
|
8
6
|
|
9
7
|
import * as RG from '../reactive.ts'
|
10
|
-
import { makeTodoMvc, tables } from '../utils/tests/fixture.ts'
|
8
|
+
import { events, makeTodoMvc, tables } from '../utils/tests/fixture.ts'
|
11
9
|
import { getSimplifiedRootSpan } from '../utils/tests/otel.ts'
|
12
10
|
import { computed } from './computed.ts'
|
13
11
|
import { queryDb } from './db-query.ts'
|
@@ -65,7 +63,7 @@ Vitest.describe('otel', () => {
|
|
65
63
|
})
|
66
64
|
expect(store.query(query$)).toMatchInlineSnapshot('[]')
|
67
65
|
|
68
|
-
store.commit(
|
66
|
+
store.commit(events.todoCreated({ id: 't1', text: 'buy milk', completed: false }))
|
69
67
|
|
70
68
|
expect(store.query(query$)).toMatchInlineSnapshot(`
|
71
69
|
[
|
@@ -119,7 +117,7 @@ Vitest.describe('otel', () => {
|
|
119
117
|
|
120
118
|
expect(store.reactivityGraph.getSnapshot({ includeResults: true })).toMatchSnapshot()
|
121
119
|
|
122
|
-
store.commit(
|
120
|
+
store.commit(events.todoCreated({ id: 't1', text: 'buy milk', completed: false }))
|
123
121
|
|
124
122
|
expect(store.reactivityGraph.getSnapshot({ includeResults: true })).toMatchSnapshot()
|
125
123
|
|
@@ -167,7 +165,7 @@ Vitest.describe('otel', () => {
|
|
167
165
|
}
|
168
166
|
`)
|
169
167
|
|
170
|
-
store.commit(
|
168
|
+
store.commit(events.todoCreated({ id: 't1', text: 'buy milk', completed: false }))
|
171
169
|
|
172
170
|
expect(store.query(query$)).toMatchInlineSnapshot(`
|
173
171
|
{
|
@@ -212,7 +210,7 @@ Vitest.describe('otel', () => {
|
|
212
210
|
expect(callbackResults).toHaveLength(1)
|
213
211
|
expect(callbackResults[0]).toMatchObject(defaultTodo)
|
214
212
|
|
215
|
-
store.commit(
|
213
|
+
store.commit(events.todoCreated({ id: 't1', text: 'buy milk', completed: false }))
|
216
214
|
|
217
215
|
expect(callbackResults).toHaveLength(2)
|
218
216
|
expect(callbackResults[1]).toMatchObject({
|
@@ -264,14 +262,14 @@ Vitest.describe('otel', () => {
|
|
264
262
|
expect(callbackResults1).toHaveLength(1)
|
265
263
|
expect(callbackResults2).toHaveLength(1)
|
266
264
|
|
267
|
-
store.commit(
|
265
|
+
store.commit(events.todoCreated({ id: 't3', text: 'read book', completed: false }))
|
268
266
|
|
269
267
|
expect(callbackResults1).toHaveLength(2)
|
270
268
|
expect(callbackResults2).toHaveLength(2)
|
271
269
|
|
272
270
|
unsubscribe1()
|
273
271
|
|
274
|
-
store.commit(
|
272
|
+
store.commit(events.todoCreated({ id: 't4', text: 'cook dinner', completed: false }))
|
275
273
|
|
276
274
|
expect(callbackResults1).toHaveLength(2)
|
277
275
|
expect(callbackResults2).toHaveLength(3)
|
@@ -307,7 +305,7 @@ Vitest.describe('otel', () => {
|
|
307
305
|
expect(callbackResults).toHaveLength(1)
|
308
306
|
expect(callbackResults[0]).toEqual([])
|
309
307
|
|
310
|
-
store.commit(
|
308
|
+
store.commit(events.todoCreated({ id: 't5', text: 'clean house', completed: true }))
|
311
309
|
|
312
310
|
expect(callbackResults).toHaveLength(2)
|
313
311
|
expect(callbackResults[1]).toHaveLength(1)
|
@@ -10,7 +10,7 @@ import {
|
|
10
10
|
UnexpectedError,
|
11
11
|
} from '@livestore/common'
|
12
12
|
import { deepEqual, shouldNeverHappen } from '@livestore/utils'
|
13
|
-
import { Predicate, Schema, TreeFormatter } from '@livestore/utils/effect'
|
13
|
+
import { Equal, Hash, Predicate, Schema, TreeFormatter } from '@livestore/utils/effect'
|
14
14
|
import * as otel from '@opentelemetry/api'
|
15
15
|
|
16
16
|
import type { Thunk } from '../reactive.ts'
|
@@ -131,6 +131,12 @@ export const queryDb: {
|
|
131
131
|
}),
|
132
132
|
label,
|
133
133
|
hash,
|
134
|
+
[Equal.symbol](that: LiveQueryDef<any>): boolean {
|
135
|
+
return this.hash === that.hash
|
136
|
+
},
|
137
|
+
[Hash.symbol](): number {
|
138
|
+
return Hash.string(this.hash)
|
139
|
+
},
|
134
140
|
}
|
135
141
|
|
136
142
|
return def
|
@@ -314,8 +320,11 @@ export class LiveStoreDbQuery<TResultSchema, TResult = TResultSchema> extends Li
|
|
314
320
|
|
315
321
|
const queriedTablesRef: { current: Set<string> | undefined } = { current: undefined }
|
316
322
|
|
317
|
-
const makeResultsEqual = (resultSchema: Schema.Schema<any, any>) =>
|
318
|
-
|
323
|
+
const makeResultsEqual = (resultSchema: Schema.Schema<any, any>) => {
|
324
|
+
// Creating the equivalence function eagerly in outer scope as it might be expensive
|
325
|
+
const eq = Schema.equivalence(resultSchema)
|
326
|
+
return (a: TResult, b: TResult) => a === NOT_REFRESHED_YET || b === NOT_REFRESHED_YET ? false : eq(a, b)
|
327
|
+
}
|
319
328
|
|
320
329
|
// NOTE we try to create the equality function eagerly as it might be expensive
|
321
330
|
// TODO also support derived equality for `map` (probably will depend on having an easy way to transform a schema without an `encode` step)
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import { Equal, Hash } from '@livestore/utils/effect'
|
1
2
|
import { nanoid } from '@livestore/utils/nanoid'
|
2
3
|
|
3
4
|
import type * as RG from '../reactive.ts'
|
@@ -27,6 +28,12 @@ export const signal = <T>(
|
|
27
28
|
def,
|
28
29
|
}),
|
29
30
|
),
|
31
|
+
[Equal.symbol](that: SignalDef<T>): boolean {
|
32
|
+
return this.hash === that.hash
|
33
|
+
},
|
34
|
+
[Hash.symbol](): number {
|
35
|
+
return Hash.string(this.hash)
|
36
|
+
},
|
30
37
|
}
|
31
38
|
|
32
39
|
return def
|
package/src/mod.ts
CHANGED
@@ -35,11 +35,12 @@ export {
|
|
35
35
|
export { emptyDebugInfo, SqliteDbWrapper } from './SqliteDbWrapper.ts'
|
36
36
|
export { type CreateStoreOptions, createStore, createStorePromise } from './store/create-store.ts'
|
37
37
|
export { Store } from './store/store.ts'
|
38
|
-
export type { OtelOptions, QueryDebugInfo, RefreshReason } from './store/store-types.ts'
|
38
|
+
export type { OtelOptions, QueryDebugInfo, RefreshReason, Unsubscribe } from './store/store-types.ts'
|
39
39
|
export {
|
40
40
|
type LiveStoreContext,
|
41
41
|
type LiveStoreContextRunning,
|
42
42
|
makeShutdownDeferred,
|
43
43
|
type ShutdownDeferred,
|
44
44
|
} from './store/store-types.ts'
|
45
|
+
export { exposeDebugUtils } from './utils/dev.ts'
|
45
46
|
export * from './utils/stack-info.ts'
|
package/src/reactive.ts
CHANGED
@@ -211,8 +211,10 @@ export class ReactiveGraph<
|
|
211
211
|
|
212
212
|
private refreshCallbacks: Set<() => void> = new Set()
|
213
213
|
|
214
|
+
// biome-ignore lint/correctness/noUnusedPrivateClassMembers: for debugging
|
214
215
|
private nodeIdCounter = 0
|
215
216
|
private uniqueNodeId = () => `node-${++this.nodeIdCounter}`
|
217
|
+
// biome-ignore lint/correctness/noUnusedPrivateClassMembers: for debugging
|
216
218
|
private refreshInfoIdCounter = 0
|
217
219
|
private uniqueRefreshInfoId = () => `refresh-info-${++this.refreshInfoIdCounter}`
|
218
220
|
|
@@ -1,16 +1,17 @@
|
|
1
|
-
import
|
2
|
-
Adapter,
|
3
|
-
BootStatus,
|
4
|
-
ClientSession,
|
5
|
-
ClientSessionDevtoolsChannel,
|
6
|
-
ClientSessionSyncProcessorSimulationParams,
|
7
|
-
IntentionalShutdownCause,
|
8
|
-
MigrationsReport,
|
1
|
+
import {
|
2
|
+
type Adapter,
|
3
|
+
type BootStatus,
|
4
|
+
type ClientSession,
|
5
|
+
type ClientSessionDevtoolsChannel,
|
6
|
+
type ClientSessionSyncProcessorSimulationParams,
|
7
|
+
type IntentionalShutdownCause,
|
8
|
+
type MigrationsReport,
|
9
|
+
provideOtel,
|
10
|
+
type SyncError,
|
11
|
+
UnexpectedError,
|
9
12
|
} from '@livestore/common'
|
10
|
-
import { provideOtel, UnexpectedError } from '@livestore/common'
|
11
13
|
import type { LiveStoreSchema } from '@livestore/common/schema'
|
12
14
|
import { isDevEnv, LS_DEV } from '@livestore/utils'
|
13
|
-
import type { Cause, Schema } from '@livestore/utils/effect'
|
14
15
|
import {
|
15
16
|
Context,
|
16
17
|
Deferred,
|
@@ -24,6 +25,7 @@ import {
|
|
24
25
|
OtelTracer,
|
25
26
|
Queue,
|
26
27
|
Runtime,
|
28
|
+
type Schema,
|
27
29
|
Scope,
|
28
30
|
TaskTracing,
|
29
31
|
} from '@livestore/utils/effect'
|
@@ -96,7 +98,7 @@ export interface CreateStoreOptions<TSchema extends LiveStoreSchema, TContext =
|
|
96
98
|
migrationsReport: MigrationsReport
|
97
99
|
parentSpan: otel.Span
|
98
100
|
},
|
99
|
-
) =>
|
101
|
+
) => Effect.SyncOrPromiseOrEffect<void, unknown, OtelTracer.OtelTracer | LiveStoreContextRunning>
|
100
102
|
batchUpdates?: (run: () => void) => void
|
101
103
|
/**
|
102
104
|
* Whether to disable devtools.
|
@@ -131,7 +133,7 @@ export interface CreateStoreOptions<TSchema extends LiveStoreSchema, TContext =
|
|
131
133
|
}
|
132
134
|
|
133
135
|
/** Create a new LiveStore Store */
|
134
|
-
export const createStorePromise = async <TSchema extends LiveStoreSchema = LiveStoreSchema, TContext = {}>({
|
136
|
+
export const createStorePromise = async <TSchema extends LiveStoreSchema = LiveStoreSchema.Any, TContext = {}>({
|
135
137
|
signal,
|
136
138
|
otelOptions,
|
137
139
|
...options
|
@@ -162,7 +164,7 @@ export const createStorePromise = async <TSchema extends LiveStoreSchema = LiveS
|
|
162
164
|
Effect.runPromise,
|
163
165
|
)
|
164
166
|
|
165
|
-
export const createStore = <TSchema extends LiveStoreSchema = LiveStoreSchema, TContext = {}>({
|
167
|
+
export const createStore = <TSchema extends LiveStoreSchema = LiveStoreSchema.Any, TContext = {}>({
|
166
168
|
schema,
|
167
169
|
adapter,
|
168
170
|
storeId,
|
@@ -215,9 +217,9 @@ export const createStore = <TSchema extends LiveStoreSchema = LiveStoreSchema, T
|
|
215
217
|
|
216
218
|
const runtime = yield* Effect.runtime<Scope.Scope>()
|
217
219
|
|
218
|
-
const shutdown = (
|
220
|
+
const shutdown = (exit: Exit.Exit<IntentionalShutdownCause, UnexpectedError | SyncError>) =>
|
219
221
|
Effect.gen(function* () {
|
220
|
-
yield* Scope.close(lifetimeScope,
|
222
|
+
yield* Scope.close(lifetimeScope, exit).pipe(
|
221
223
|
Effect.logWarnIfTakesLongerThan({ label: '@livestore/livestore:shutdown', duration: 500 }),
|
222
224
|
Effect.timeout(1000),
|
223
225
|
Effect.catchTag('TimeoutException', () =>
|
@@ -226,7 +228,7 @@ export const createStore = <TSchema extends LiveStoreSchema = LiveStoreSchema, T
|
|
226
228
|
)
|
227
229
|
|
228
230
|
if (shutdownDeferred) {
|
229
|
-
yield* Deferred.
|
231
|
+
yield* Deferred.done(shutdownDeferred, exit)
|
230
232
|
}
|
231
233
|
|
232
234
|
yield* Effect.logDebug('LiveStore shutdown complete')
|
package/src/store/store-types.ts
CHANGED
@@ -3,6 +3,7 @@ import type {
|
|
3
3
|
ClientSessionSyncProcessorSimulationParams,
|
4
4
|
IntentionalShutdownCause,
|
5
5
|
StoreInterrupted,
|
6
|
+
SyncError,
|
6
7
|
UnexpectedError,
|
7
8
|
} from '@livestore/common'
|
8
9
|
import type { EventSequenceNumber, LiveStoreEvent, LiveStoreSchema } from '@livestore/common/schema'
|
@@ -22,13 +23,16 @@ export type LiveStoreContext =
|
|
22
23
|
}
|
23
24
|
| {
|
24
25
|
stage: 'shutdown'
|
25
|
-
cause: IntentionalShutdownCause | StoreInterrupted
|
26
|
+
cause: IntentionalShutdownCause | StoreInterrupted | SyncError
|
26
27
|
}
|
27
28
|
|
28
|
-
export type ShutdownDeferred = Deferred.Deferred<
|
29
|
+
export type ShutdownDeferred = Deferred.Deferred<
|
30
|
+
IntentionalShutdownCause,
|
31
|
+
UnexpectedError | SyncError | StoreInterrupted
|
32
|
+
>
|
29
33
|
export const makeShutdownDeferred: Effect.Effect<ShutdownDeferred> = Deferred.make<
|
30
|
-
|
31
|
-
UnexpectedError |
|
34
|
+
IntentionalShutdownCause,
|
35
|
+
UnexpectedError | SyncError | StoreInterrupted
|
32
36
|
>()
|
33
37
|
|
34
38
|
export type LiveStoreContextRunning = {
|
@@ -41,7 +45,7 @@ export type OtelOptions = {
|
|
41
45
|
rootSpanContext: otel.Context
|
42
46
|
}
|
43
47
|
|
44
|
-
export type StoreOptions<TSchema extends LiveStoreSchema = LiveStoreSchema, TContext = {}> = {
|
48
|
+
export type StoreOptions<TSchema extends LiveStoreSchema = LiveStoreSchema.Any, TContext = {}> = {
|
45
49
|
clientSession: ClientSession
|
46
50
|
schema: TSchema
|
47
51
|
storeId: string
|