@livestore/common 0.3.0-dev.31 → 0.3.0-dev.32
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/derived-mutations.d.ts +77 -0
- package/dist/derived-mutations.d.ts.map +1 -0
- package/dist/derived-mutations.js +54 -0
- package/dist/derived-mutations.js.map +1 -0
- package/dist/derived-mutations.test.d.ts +2 -0
- package/dist/derived-mutations.test.d.ts.map +1 -0
- package/dist/derived-mutations.test.js +93 -0
- package/dist/derived-mutations.test.js.map +1 -0
- package/dist/devtools/devtools-bridge.d.ts +12 -0
- package/dist/devtools/devtools-bridge.d.ts.map +1 -0
- package/dist/devtools/devtools-bridge.js +2 -0
- package/dist/devtools/devtools-bridge.js.map +1 -0
- package/dist/devtools/devtools-messages-client-session.d.ts +21 -21
- package/dist/devtools/devtools-messages-common.d.ts +6 -6
- package/dist/devtools/devtools-messages-leader.d.ts +24 -24
- package/dist/devtools/index.d.ts +42 -0
- package/dist/devtools/index.d.ts.map +1 -0
- package/dist/devtools/index.js +49 -0
- package/dist/devtools/index.js.map +1 -0
- package/dist/init-singleton-tables.d.ts +4 -0
- package/dist/init-singleton-tables.d.ts.map +1 -0
- package/dist/init-singleton-tables.js +16 -0
- package/dist/init-singleton-tables.js.map +1 -0
- package/dist/mutation.d.ts +14 -0
- package/dist/mutation.d.ts.map +1 -0
- package/dist/mutation.js +71 -0
- package/dist/mutation.js.map +1 -0
- package/dist/query-info.d.ts +38 -0
- package/dist/query-info.d.ts.map +1 -0
- package/dist/query-info.js +7 -0
- package/dist/query-info.js.map +1 -0
- package/dist/rehydrate-from-mutationlog.d.ts +14 -0
- package/dist/rehydrate-from-mutationlog.d.ts.map +1 -0
- package/dist/rehydrate-from-mutationlog.js +72 -0
- package/dist/rehydrate-from-mutationlog.js.map +1 -0
- package/dist/schema/index.d.ts +62 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +67 -0
- package/dist/schema/index.js.map +1 -0
- package/dist/schema/mutations.d.ts +227 -0
- package/dist/schema/mutations.d.ts.map +1 -0
- package/dist/schema/mutations.js +68 -0
- package/dist/schema/mutations.js.map +1 -0
- package/dist/schema-management/migrations.js +2 -0
- package/dist/schema-management/migrations.js.map +1 -1
- package/dist/sync/next/test/mutation-fixtures.d.ts +73 -0
- package/dist/sync/next/test/mutation-fixtures.d.ts.map +1 -0
- package/dist/sync/next/test/mutation-fixtures.js +161 -0
- package/dist/sync/next/test/mutation-fixtures.js.map +1 -0
- package/dist/sync/next-mutation-event-id-pair.d.ts +14 -0
- package/dist/sync/next-mutation-event-id-pair.d.ts.map +1 -0
- package/dist/sync/next-mutation-event-id-pair.js +13 -0
- package/dist/sync/next-mutation-event-id-pair.js.map +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -2
- package/src/schema-management/migrations.ts +1 -0
- package/src/version.ts +1 -1
@@ -3,7 +3,7 @@ import * as SyncState from '../sync/syncstate.js';
|
|
3
3
|
declare const ResetAllDataReq_base: Schema.Struct<{
|
4
4
|
_tag: Schema.tag<"LSD.Leader.ResetAllDataReq">;
|
5
5
|
} & {
|
6
|
-
liveStoreVersion: Schema.Literal<["0.3.0-dev.
|
6
|
+
liveStoreVersion: Schema.Literal<["0.3.0-dev.32"]>;
|
7
7
|
} & {
|
8
8
|
clientId: typeof Schema.String;
|
9
9
|
} & {
|
@@ -16,7 +16,7 @@ export declare class ResetAllDataReq extends ResetAllDataReq_base {
|
|
16
16
|
declare const DatabaseFileInfoReq_base: Schema.Struct<{
|
17
17
|
_tag: Schema.tag<"LSD.Leader.DatabaseFileInfoReq">;
|
18
18
|
} & {
|
19
|
-
liveStoreVersion: Schema.Literal<["0.3.0-dev.
|
19
|
+
liveStoreVersion: Schema.Literal<["0.3.0-dev.32"]>;
|
20
20
|
} & {
|
21
21
|
clientId: typeof Schema.String;
|
22
22
|
} & {
|
@@ -38,7 +38,7 @@ export declare class DatabaseFileInfo extends DatabaseFileInfo_base {
|
|
38
38
|
declare const DatabaseFileInfoRes_base: Schema.Struct<{
|
39
39
|
_tag: Schema.tag<"LSD.Leader.DatabaseFileInfoRes">;
|
40
40
|
} & {
|
41
|
-
liveStoreVersion: Schema.Literal<["0.3.0-dev.
|
41
|
+
liveStoreVersion: Schema.Literal<["0.3.0-dev.32"]>;
|
42
42
|
} & {
|
43
43
|
clientId: typeof Schema.String;
|
44
44
|
} & {
|
@@ -52,7 +52,7 @@ export declare class DatabaseFileInfoRes extends DatabaseFileInfoRes_base {
|
|
52
52
|
declare const NetworkStatusSubscribe_base: Schema.Struct<{
|
53
53
|
_tag: Schema.tag<"LSD.Leader.NetworkStatusSubscribe">;
|
54
54
|
} & {
|
55
|
-
liveStoreVersion: Schema.Literal<["0.3.0-dev.
|
55
|
+
liveStoreVersion: Schema.Literal<["0.3.0-dev.32"]>;
|
56
56
|
} & {
|
57
57
|
clientId: typeof Schema.String;
|
58
58
|
} & {
|
@@ -65,7 +65,7 @@ export declare class NetworkStatusSubscribe extends NetworkStatusSubscribe_base
|
|
65
65
|
declare const NetworkStatusUnsubscribe_base: Schema.Struct<{
|
66
66
|
_tag: Schema.tag<"LSD.Leader.NetworkStatusUnsubscribe">;
|
67
67
|
} & {
|
68
|
-
liveStoreVersion: Schema.Literal<["0.3.0-dev.
|
68
|
+
liveStoreVersion: Schema.Literal<["0.3.0-dev.32"]>;
|
69
69
|
} & {
|
70
70
|
clientId: typeof Schema.String;
|
71
71
|
} & {
|
@@ -78,7 +78,7 @@ export declare class NetworkStatusUnsubscribe extends NetworkStatusUnsubscribe_b
|
|
78
78
|
declare const NetworkStatusRes_base: Schema.Struct<{
|
79
79
|
_tag: Schema.tag<"LSD.Leader.NetworkStatusRes">;
|
80
80
|
} & {
|
81
|
-
liveStoreVersion: Schema.Literal<["0.3.0-dev.
|
81
|
+
liveStoreVersion: Schema.Literal<["0.3.0-dev.32"]>;
|
82
82
|
} & {
|
83
83
|
clientId: typeof Schema.String;
|
84
84
|
} & {
|
@@ -96,7 +96,7 @@ export declare class NetworkStatusRes extends NetworkStatusRes_base {
|
|
96
96
|
declare const SyncingInfoReq_base: Schema.Struct<{
|
97
97
|
_tag: Schema.tag<"LSD.Leader.SyncingInfoReq">;
|
98
98
|
} & {
|
99
|
-
liveStoreVersion: Schema.Literal<["0.3.0-dev.
|
99
|
+
liveStoreVersion: Schema.Literal<["0.3.0-dev.32"]>;
|
100
100
|
} & {
|
101
101
|
clientId: typeof Schema.String;
|
102
102
|
} & {
|
@@ -113,7 +113,7 @@ export declare class SyncingInfo extends SyncingInfo_base {
|
|
113
113
|
declare const SyncingInfoRes_base: Schema.Struct<{
|
114
114
|
_tag: Schema.tag<"LSD.Leader.SyncingInfoRes">;
|
115
115
|
} & {
|
116
|
-
liveStoreVersion: Schema.Literal<["0.3.0-dev.
|
116
|
+
liveStoreVersion: Schema.Literal<["0.3.0-dev.32"]>;
|
117
117
|
} & {
|
118
118
|
clientId: typeof Schema.String;
|
119
119
|
} & {
|
@@ -126,7 +126,7 @@ export declare class SyncingInfoRes extends SyncingInfoRes_base {
|
|
126
126
|
declare const SyncHistorySubscribe_base: Schema.Struct<{
|
127
127
|
_tag: Schema.tag<"LSD.Leader.SyncHistorySubscribe">;
|
128
128
|
} & {
|
129
|
-
liveStoreVersion: Schema.Literal<["0.3.0-dev.
|
129
|
+
liveStoreVersion: Schema.Literal<["0.3.0-dev.32"]>;
|
130
130
|
} & {
|
131
131
|
clientId: typeof Schema.String;
|
132
132
|
} & {
|
@@ -139,7 +139,7 @@ export declare class SyncHistorySubscribe extends SyncHistorySubscribe_base {
|
|
139
139
|
declare const SyncHistoryUnsubscribe_base: Schema.Struct<{
|
140
140
|
_tag: Schema.tag<"LSD.Leader.SyncHistoryUnsubscribe">;
|
141
141
|
} & {
|
142
|
-
liveStoreVersion: Schema.Literal<["0.3.0-dev.
|
142
|
+
liveStoreVersion: Schema.Literal<["0.3.0-dev.32"]>;
|
143
143
|
} & {
|
144
144
|
clientId: typeof Schema.String;
|
145
145
|
} & {
|
@@ -152,7 +152,7 @@ export declare class SyncHistoryUnsubscribe extends SyncHistoryUnsubscribe_base
|
|
152
152
|
declare const SyncHistoryRes_base: Schema.Struct<{
|
153
153
|
_tag: Schema.tag<"LSD.Leader.SyncHistoryRes">;
|
154
154
|
} & {
|
155
|
-
liveStoreVersion: Schema.Literal<["0.3.0-dev.
|
155
|
+
liveStoreVersion: Schema.Literal<["0.3.0-dev.32"]>;
|
156
156
|
} & {
|
157
157
|
clientId: typeof Schema.String;
|
158
158
|
} & {
|
@@ -174,7 +174,7 @@ export declare class SyncHistoryRes extends SyncHistoryRes_base {
|
|
174
174
|
declare const SyncHeadSubscribe_base: Schema.Struct<{
|
175
175
|
_tag: Schema.tag<"LSD.Leader.SyncHeadSubscribe">;
|
176
176
|
} & {
|
177
|
-
liveStoreVersion: Schema.Literal<["0.3.0-dev.
|
177
|
+
liveStoreVersion: Schema.Literal<["0.3.0-dev.32"]>;
|
178
178
|
} & {
|
179
179
|
clientId: typeof Schema.String;
|
180
180
|
} & {
|
@@ -187,7 +187,7 @@ export declare class SyncHeadSubscribe extends SyncHeadSubscribe_base {
|
|
187
187
|
declare const SyncHeadUnsubscribe_base: Schema.Struct<{
|
188
188
|
_tag: Schema.tag<"LSD.Leader.SyncHeadUnsubscribe">;
|
189
189
|
} & {
|
190
|
-
liveStoreVersion: Schema.Literal<["0.3.0-dev.
|
190
|
+
liveStoreVersion: Schema.Literal<["0.3.0-dev.32"]>;
|
191
191
|
} & {
|
192
192
|
clientId: typeof Schema.String;
|
193
193
|
} & {
|
@@ -200,7 +200,7 @@ export declare class SyncHeadUnsubscribe extends SyncHeadUnsubscribe_base {
|
|
200
200
|
declare const SyncHeadRes_base: Schema.Struct<{
|
201
201
|
_tag: Schema.tag<"LSD.Leader.SyncHeadRes">;
|
202
202
|
} & {
|
203
|
-
liveStoreVersion: Schema.Literal<["0.3.0-dev.
|
203
|
+
liveStoreVersion: Schema.Literal<["0.3.0-dev.32"]>;
|
204
204
|
} & {
|
205
205
|
clientId: typeof Schema.String;
|
206
206
|
} & {
|
@@ -221,7 +221,7 @@ export declare class SyncHeadRes extends SyncHeadRes_base {
|
|
221
221
|
declare const SnapshotReq_base: Schema.Struct<{
|
222
222
|
_tag: Schema.tag<"LSD.Leader.SnapshotReq">;
|
223
223
|
} & {
|
224
|
-
liveStoreVersion: Schema.Literal<["0.3.0-dev.
|
224
|
+
liveStoreVersion: Schema.Literal<["0.3.0-dev.32"]>;
|
225
225
|
} & {
|
226
226
|
clientId: typeof Schema.String;
|
227
227
|
} & {
|
@@ -232,7 +232,7 @@ export declare class SnapshotReq extends SnapshotReq_base {
|
|
232
232
|
declare const SnapshotRes_base: Schema.Struct<{
|
233
233
|
_tag: Schema.tag<"LSD.Leader.SnapshotRes">;
|
234
234
|
} & {
|
235
|
-
liveStoreVersion: Schema.Literal<["0.3.0-dev.
|
235
|
+
liveStoreVersion: Schema.Literal<["0.3.0-dev.32"]>;
|
236
236
|
} & {
|
237
237
|
clientId: typeof Schema.String;
|
238
238
|
} & {
|
@@ -252,7 +252,7 @@ export declare const LoadDatabaseFile: import("./devtools-messages-common.js").L
|
|
252
252
|
declare const SyncPull_base: Schema.Struct<{
|
253
253
|
_tag: Schema.tag<"LSD.Leader.SyncPull">;
|
254
254
|
} & {
|
255
|
-
liveStoreVersion: Schema.Literal<["0.3.0-dev.
|
255
|
+
liveStoreVersion: Schema.Literal<["0.3.0-dev.32"]>;
|
256
256
|
} & {
|
257
257
|
payload: typeof SyncState.PayloadUpstream;
|
258
258
|
}>;
|
@@ -261,7 +261,7 @@ export declare class SyncPull extends SyncPull_base {
|
|
261
261
|
declare const CommitEventReq_base: Schema.Struct<{
|
262
262
|
_tag: Schema.tag<"LSD.Leader.CommitEventReq">;
|
263
263
|
} & {
|
264
|
-
liveStoreVersion: Schema.Literal<["0.3.0-dev.
|
264
|
+
liveStoreVersion: Schema.Literal<["0.3.0-dev.32"]>;
|
265
265
|
} & {
|
266
266
|
clientId: typeof Schema.String;
|
267
267
|
} & {
|
@@ -277,7 +277,7 @@ export declare class CommitEventReq extends CommitEventReq_base {
|
|
277
277
|
declare const CommitEventRes_base: Schema.Struct<{
|
278
278
|
_tag: Schema.tag<"LSD.Leader.CommitEventRes">;
|
279
279
|
} & {
|
280
|
-
liveStoreVersion: Schema.Literal<["0.3.0-dev.
|
280
|
+
liveStoreVersion: Schema.Literal<["0.3.0-dev.32"]>;
|
281
281
|
} & {
|
282
282
|
clientId: typeof Schema.String;
|
283
283
|
} & {
|
@@ -288,7 +288,7 @@ export declare class CommitEventRes extends CommitEventRes_base {
|
|
288
288
|
declare const EventlogReq_base: Schema.Struct<{
|
289
289
|
_tag: Schema.tag<"LSD.Leader.EventlogReq">;
|
290
290
|
} & {
|
291
|
-
liveStoreVersion: Schema.Literal<["0.3.0-dev.
|
291
|
+
liveStoreVersion: Schema.Literal<["0.3.0-dev.32"]>;
|
292
292
|
} & {
|
293
293
|
clientId: typeof Schema.String;
|
294
294
|
} & {
|
@@ -299,7 +299,7 @@ export declare class EventlogReq extends EventlogReq_base {
|
|
299
299
|
declare const EventlogRes_base: Schema.Struct<{
|
300
300
|
_tag: Schema.tag<"LSD.Leader.EventlogRes">;
|
301
301
|
} & {
|
302
|
-
liveStoreVersion: Schema.Literal<["0.3.0-dev.
|
302
|
+
liveStoreVersion: Schema.Literal<["0.3.0-dev.32"]>;
|
303
303
|
} & {
|
304
304
|
clientId: typeof Schema.String;
|
305
305
|
} & {
|
@@ -312,7 +312,7 @@ export declare class EventlogRes extends EventlogRes_base {
|
|
312
312
|
declare const Ping_base: Schema.Struct<{
|
313
313
|
_tag: Schema.tag<"LSD.Leader.Ping">;
|
314
314
|
} & {
|
315
|
-
liveStoreVersion: Schema.Literal<["0.3.0-dev.
|
315
|
+
liveStoreVersion: Schema.Literal<["0.3.0-dev.32"]>;
|
316
316
|
} & {
|
317
317
|
clientId: typeof Schema.String;
|
318
318
|
} & {
|
@@ -323,7 +323,7 @@ export declare class Ping extends Ping_base {
|
|
323
323
|
declare const Pong_base: Schema.Struct<{
|
324
324
|
_tag: Schema.tag<"LSD.Leader.Pong">;
|
325
325
|
} & {
|
326
|
-
liveStoreVersion: Schema.Literal<["0.3.0-dev.
|
326
|
+
liveStoreVersion: Schema.Literal<["0.3.0-dev.32"]>;
|
327
327
|
} & {
|
328
328
|
clientId: typeof Schema.String;
|
329
329
|
} & {
|
@@ -334,7 +334,7 @@ export declare class Pong extends Pong_base {
|
|
334
334
|
declare const Disconnect_base: Schema.Struct<{
|
335
335
|
_tag: Schema.tag<"LSD.Leader.Disconnect">;
|
336
336
|
} & {
|
337
|
-
liveStoreVersion: Schema.Literal<["0.3.0-dev.
|
337
|
+
liveStoreVersion: Schema.Literal<["0.3.0-dev.32"]>;
|
338
338
|
} & {
|
339
339
|
clientId: typeof Schema.String;
|
340
340
|
} & {
|
@@ -0,0 +1,42 @@
|
|
1
|
+
import type { Effect, Scope } from '@livestore/utils/effect';
|
2
|
+
import { Schema, WebChannel } from '@livestore/utils/effect';
|
3
|
+
export * from './devtools-messages.js';
|
4
|
+
export * from './devtools-window-message.js';
|
5
|
+
export * from './devtools-bridge.js';
|
6
|
+
export declare namespace WebBridge {
|
7
|
+
const AppHostReady_base: Schema.TaggedStruct<"LSD.WebBridge.AppHostReady", {
|
8
|
+
appHostId: typeof Schema.String;
|
9
|
+
isLeader: typeof Schema.Boolean;
|
10
|
+
}>;
|
11
|
+
export class AppHostReady extends AppHostReady_base {
|
12
|
+
}
|
13
|
+
const DevtoolsReady_base: Schema.TaggedStruct<"LSD.WebBridge.DevtoolsReady", {
|
14
|
+
devtoolsId: typeof Schema.String;
|
15
|
+
}>;
|
16
|
+
export class DevtoolsReady extends DevtoolsReady_base {
|
17
|
+
}
|
18
|
+
const ConnectToDevtools_base: Schema.TaggedStruct<"LSD.WebBridge.ConnectToDevtools", {
|
19
|
+
devtoolsId: typeof Schema.String;
|
20
|
+
appHostId: typeof Schema.String;
|
21
|
+
/**
|
22
|
+
* Given the m:n relationship between devtools and app hosts and the fact that appHostIds are usually
|
23
|
+
* sticky, we generate a new unique id for the lifetime of the web bridge.
|
24
|
+
*/
|
25
|
+
webBridgeId: typeof Schema.String;
|
26
|
+
isLeader: typeof Schema.Boolean;
|
27
|
+
storeId: typeof Schema.String;
|
28
|
+
}>;
|
29
|
+
export class ConnectToDevtools extends ConnectToDevtools_base {
|
30
|
+
}
|
31
|
+
const AppHostWillDisconnect_base: Schema.TaggedStruct<"LSD.WebBridge.AppHostWillDisconnect", {
|
32
|
+
appHostId: typeof Schema.String;
|
33
|
+
}>;
|
34
|
+
export class AppHostWillDisconnect extends AppHostWillDisconnect_base {
|
35
|
+
}
|
36
|
+
const All_base: Schema.Union<[typeof AppHostReady, typeof DevtoolsReady, typeof ConnectToDevtools, typeof AppHostWillDisconnect]>;
|
37
|
+
export class All extends All_base {
|
38
|
+
}
|
39
|
+
export const makeBroadcastChannel: (key?: string) => Effect.Effect<WebChannel.WebChannel<typeof All.Type, typeof All.Type>, never, Scope.Scope>;
|
40
|
+
export {};
|
41
|
+
}
|
42
|
+
//# sourceMappingURL=index.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/devtools/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AAC5D,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAE5D,cAAc,wBAAwB,CAAA;AACtC,cAAc,8BAA8B,CAAA;AAC5C,cAAc,sBAAsB,CAAA;AAEpC,yBAAiB,SAAS,CAAC;;;;;IACzB,MAAM,OAAO,YAAa,SAAQ,iBAIhC;KAAG;;;;IAEL,MAAM,OAAO,aAAc,SAAQ,kBAEjC;KAAG;;;;QAKH;;;WAGG;;;;;IANL,MAAM,OAAO,iBAAkB,SAAQ,sBAUrC;KAAG;;;;IAEL,MAAM,OAAO,qBAAsB,SAAQ,0BAEzC;KAAG;;IAML,MAAM,OAAO,GAAI,SAAQ,QAAmF;KAAG;IAE/G,MAAM,CAAC,MAAM,oBAAoB,GAC/B,MAAM,MAAM,KACX,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,UAAU,CAAC,OAAO,GAAG,CAAC,IAAI,EAAE,OAAO,GAAG,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,CAKxF,CAAA;;CACL"}
|
@@ -0,0 +1,49 @@
|
|
1
|
+
import { Schema, WebChannel } from '@livestore/utils/effect';
|
2
|
+
export * from './devtools-messages.js';
|
3
|
+
export * from './devtools-window-message.js';
|
4
|
+
export * from './devtools-bridge.js';
|
5
|
+
export var WebBridge;
|
6
|
+
(function (WebBridge) {
|
7
|
+
class AppHostReady extends Schema.TaggedStruct('LSD.WebBridge.AppHostReady', {
|
8
|
+
appHostId: Schema.String,
|
9
|
+
// storeId: Schema.String,
|
10
|
+
isLeader: Schema.Boolean,
|
11
|
+
}) {
|
12
|
+
}
|
13
|
+
WebBridge.AppHostReady = AppHostReady;
|
14
|
+
class DevtoolsReady extends Schema.TaggedStruct('LSD.WebBridge.DevtoolsReady', {
|
15
|
+
devtoolsId: Schema.String,
|
16
|
+
}) {
|
17
|
+
}
|
18
|
+
WebBridge.DevtoolsReady = DevtoolsReady;
|
19
|
+
class ConnectToDevtools extends Schema.TaggedStruct('LSD.WebBridge.ConnectToDevtools', {
|
20
|
+
devtoolsId: Schema.String,
|
21
|
+
appHostId: Schema.String,
|
22
|
+
/**
|
23
|
+
* Given the m:n relationship between devtools and app hosts and the fact that appHostIds are usually
|
24
|
+
* sticky, we generate a new unique id for the lifetime of the web bridge.
|
25
|
+
*/
|
26
|
+
webBridgeId: Schema.String,
|
27
|
+
isLeader: Schema.Boolean,
|
28
|
+
storeId: Schema.String,
|
29
|
+
}) {
|
30
|
+
}
|
31
|
+
WebBridge.ConnectToDevtools = ConnectToDevtools;
|
32
|
+
class AppHostWillDisconnect extends Schema.TaggedStruct('LSD.WebBridge.AppHostWillDisconnect', {
|
33
|
+
appHostId: Schema.String,
|
34
|
+
}) {
|
35
|
+
}
|
36
|
+
WebBridge.AppHostWillDisconnect = AppHostWillDisconnect;
|
37
|
+
// export class DevtoolsWillDisconnect extends Schema.TaggedStruct('LSD.WebBridge.DevtoolsWillDisconnect', {
|
38
|
+
// appHostId: Schema.String,
|
39
|
+
// }) {}
|
40
|
+
class All extends Schema.Union(AppHostReady, DevtoolsReady, ConnectToDevtools, AppHostWillDisconnect) {
|
41
|
+
}
|
42
|
+
WebBridge.All = All;
|
43
|
+
WebBridge.makeBroadcastChannel = (key) => WebChannel.broadcastChannel({
|
44
|
+
channelName: `livestore-web-bridge-devtools${key ? `-${key}` : ''}`,
|
45
|
+
listenSchema: All,
|
46
|
+
sendSchema: All,
|
47
|
+
});
|
48
|
+
})(WebBridge || (WebBridge = {}));
|
49
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/devtools/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAE5D,cAAc,wBAAwB,CAAA;AACtC,cAAc,8BAA8B,CAAA;AAC5C,cAAc,sBAAsB,CAAA;AAEpC,MAAM,KAAW,SAAS,CAyCzB;AAzCD,WAAiB,SAAS;IACxB,MAAa,YAAa,SAAQ,MAAM,CAAC,YAAY,CAAC,4BAA4B,EAAE;QAClF,SAAS,EAAE,MAAM,CAAC,MAAM;QACxB,0BAA0B;QAC1B,QAAQ,EAAE,MAAM,CAAC,OAAO;KACzB,CAAC;KAAG;IAJQ,sBAAY,eAIpB,CAAA;IAEL,MAAa,aAAc,SAAQ,MAAM,CAAC,YAAY,CAAC,6BAA6B,EAAE;QACpF,UAAU,EAAE,MAAM,CAAC,MAAM;KAC1B,CAAC;KAAG;IAFQ,uBAAa,gBAErB,CAAA;IAEL,MAAa,iBAAkB,SAAQ,MAAM,CAAC,YAAY,CAAC,iCAAiC,EAAE;QAC5F,UAAU,EAAE,MAAM,CAAC,MAAM;QACzB,SAAS,EAAE,MAAM,CAAC,MAAM;QACxB;;;WAGG;QACH,WAAW,EAAE,MAAM,CAAC,MAAM;QAC1B,QAAQ,EAAE,MAAM,CAAC,OAAO;QACxB,OAAO,EAAE,MAAM,CAAC,MAAM;KACvB,CAAC;KAAG;IAVQ,2BAAiB,oBAUzB,CAAA;IAEL,MAAa,qBAAsB,SAAQ,MAAM,CAAC,YAAY,CAAC,qCAAqC,EAAE;QACpG,SAAS,EAAE,MAAM,CAAC,MAAM;KACzB,CAAC;KAAG;IAFQ,+BAAqB,wBAE7B,CAAA;IAEL,4GAA4G;IAC5G,8BAA8B;IAC9B,QAAQ;IAER,MAAa,GAAI,SAAQ,MAAM,CAAC,KAAK,CAAC,YAAY,EAAE,aAAa,EAAE,iBAAiB,EAAE,qBAAqB,CAAC;KAAG;IAAlG,aAAG,MAA+F,CAAA;IAElG,8BAAoB,GAAG,CAClC,GAAY,EACgF,EAAE,CAC9F,UAAU,CAAC,gBAAgB,CAAC;QAC1B,WAAW,EAAE,gCAAgC,GAAG,CAAC,CAAC,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE;QACnE,YAAY,EAAE,GAAG;QACjB,UAAU,EAAE,GAAG;KAChB,CAAC,CAAA;AACN,CAAC,EAzCgB,SAAS,KAAT,SAAS,QAyCzB"}
|
@@ -0,0 +1,4 @@
|
|
1
|
+
import type { SynchronousDatabase } from './adapter-types.js';
|
2
|
+
import type { LiveStoreSchema } from './schema/index.js';
|
3
|
+
export declare const initializeSingletonTables: (schema: LiveStoreSchema, db: SynchronousDatabase) => void;
|
4
|
+
//# sourceMappingURL=init-singleton-tables.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"init-singleton-tables.d.ts","sourceRoot":"","sources":["../src/init-singleton-tables.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AAC7D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAIxD,eAAO,MAAM,yBAAyB,GAAI,QAAQ,eAAe,EAAE,IAAI,mBAAmB,SAkBzF,CAAA"}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import { getDefaultValuesEncoded } from './schema/schema-helpers.js';
|
2
|
+
import { prepareBindValues, sql } from './util.js';
|
3
|
+
export const initializeSingletonTables = (schema, db) => {
|
4
|
+
for (const [, tableDef] of schema.tables) {
|
5
|
+
if (tableDef.options.isSingleton) {
|
6
|
+
const defaultValues = getDefaultValuesEncoded(tableDef, undefined);
|
7
|
+
const defaultColumnNames = [...Object.keys(defaultValues), 'id'];
|
8
|
+
const columnValues = defaultColumnNames.map((name) => `$${name}`).join(', ');
|
9
|
+
const tableName = tableDef.sqliteDef.name;
|
10
|
+
const insertQuery = sql `insert into ${tableName} (${defaultColumnNames.join(', ')}) select ${columnValues} where not exists(select 1 from ${tableName} where id = 'singleton')`;
|
11
|
+
const bindValues = prepareBindValues({ ...defaultValues, id: 'singleton' }, insertQuery);
|
12
|
+
db.execute(insertQuery, bindValues);
|
13
|
+
}
|
14
|
+
}
|
15
|
+
};
|
16
|
+
//# sourceMappingURL=init-singleton-tables.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"init-singleton-tables.js","sourceRoot":"","sources":["../src/init-singleton-tables.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAA;AACpE,OAAO,EAAE,iBAAiB,EAAE,GAAG,EAAE,MAAM,WAAW,CAAA;AAElD,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,MAAuB,EAAE,EAAuB,EAAE,EAAE;IAC5F,KAAK,MAAM,CAAC,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;QACzC,IAAI,QAAQ,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC;YACjC,MAAM,aAAa,GAAG,uBAAuB,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAA;YAElE,MAAM,kBAAkB,GAAG,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,EAAE,IAAI,CAAC,CAAA;YAChE,MAAM,YAAY,GAAG,kBAAkB,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;YAE5E,MAAM,SAAS,GAAG,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAA;YACzC,MAAM,WAAW,GAAG,GAAG,CAAA,eAAe,SAAS,KAAK,kBAAkB,CAAC,IAAI,CACzE,IAAI,CACL,YAAY,YAAY,mCAAmC,SAAS,0BAA0B,CAAA;YAE/F,MAAM,UAAU,GAAG,iBAAiB,CAAC,EAAE,GAAG,aAAa,EAAE,EAAE,EAAE,WAAW,EAAE,EAAE,WAAW,CAAC,CAAA;YAExF,EAAE,CAAC,OAAO,CAAC,WAAW,EAAE,UAAU,CAAC,CAAA;QACrC,CAAC;IACH,CAAC;AACH,CAAC,CAAA"}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import type { LiveStoreSchema } from './schema/index.js';
|
2
|
+
import type { MutationDef, MutationEvent } from './schema/mutations.js';
|
3
|
+
import type { PreparedBindValues } from './util.js';
|
4
|
+
export declare const getExecArgsFromMutation: ({ mutationDef, mutationEventDecoded, }: {
|
5
|
+
mutationDef: MutationDef.Any;
|
6
|
+
mutationEventDecoded: MutationEvent.Any;
|
7
|
+
}) => ReadonlyArray<{
|
8
|
+
statementSql: string;
|
9
|
+
bindValues: PreparedBindValues;
|
10
|
+
writeTables: ReadonlySet<string> | undefined;
|
11
|
+
}>;
|
12
|
+
export declare const makeShouldExcludeMutationFromLog: (schema: LiveStoreSchema) => (mutationName: string, mutationEventDecoded: MutationEvent.Any) => boolean;
|
13
|
+
export declare const replaceSessionIdSymbol: (bindValues: Record<string, unknown> | ReadonlyArray<unknown>, sessionId: string) => void;
|
14
|
+
//# sourceMappingURL=mutation.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"mutation.d.ts","sourceRoot":"","sources":["../src/mutation.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACxD,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AACvE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAA;AAGnD,eAAO,MAAM,uBAAuB,GAAI,wCAGrC;IACD,WAAW,EAAE,WAAW,CAAC,GAAG,CAAA;IAC5B,oBAAoB,EAAE,aAAa,CAAC,GAAG,CAAA;CACxC,KAAG,aAAa,CAAC;IAChB,YAAY,EAAE,MAAM,CAAA;IACpB,UAAU,EAAE,kBAAkB,CAAA;IAC9B,WAAW,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,SAAS,CAAA;CAC7C,CAiCA,CAAA;AAED,eAAO,MAAM,gCAAgC,WAAyB,eAAe,oBAO7D,MAAM,wBAAwB,aAAa,CAAC,GAAG,KAAG,OAQxE,CAAA;AAIF,eAAO,MAAM,sBAAsB,GACjC,YAAY,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,aAAa,CAAC,OAAO,CAAC,EAC5D,WAAW,MAAM,SAGlB,CAAA"}
|
package/dist/mutation.js
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
import { memoizeByRef, shouldNeverHappen } from '@livestore/utils';
|
2
|
+
import { Schema } from '@livestore/utils/effect';
|
3
|
+
import { SessionIdSymbol } from './adapter-types.js';
|
4
|
+
import { prepareBindValues } from './util.js';
|
5
|
+
export const getExecArgsFromMutation = ({ mutationDef, mutationEventDecoded, }) => {
|
6
|
+
let statementRes;
|
7
|
+
switch (typeof mutationDef.sql) {
|
8
|
+
case 'function': {
|
9
|
+
const res = mutationDef.sql(mutationEventDecoded.args);
|
10
|
+
statementRes = Array.isArray(res) ? res : [res];
|
11
|
+
break;
|
12
|
+
}
|
13
|
+
case 'string': {
|
14
|
+
statementRes = [mutationDef.sql];
|
15
|
+
break;
|
16
|
+
}
|
17
|
+
default: {
|
18
|
+
statementRes = mutationDef.sql;
|
19
|
+
break;
|
20
|
+
}
|
21
|
+
}
|
22
|
+
return statementRes.map((statementRes) => {
|
23
|
+
const statementSql = typeof statementRes === 'string' ? statementRes : statementRes.sql;
|
24
|
+
const bindValues = typeof statementRes === 'string'
|
25
|
+
? Schema.encodeUnknownSync(mutationDef.schema)(mutationEventDecoded.args)
|
26
|
+
: statementRes.bindValues;
|
27
|
+
const writeTables = typeof statementRes === 'string' ? undefined : statementRes.writeTables;
|
28
|
+
return { statementSql, bindValues: prepareBindValues(bindValues ?? {}, statementSql), writeTables };
|
29
|
+
});
|
30
|
+
};
|
31
|
+
export const makeShouldExcludeMutationFromLog = memoizeByRef((schema) => {
|
32
|
+
const migrationOptions = schema.migrationOptions;
|
33
|
+
const mutationLogExclude = migrationOptions.strategy === 'from-mutation-log'
|
34
|
+
? (migrationOptions.excludeMutations ?? new Set(['livestore.RawSql']))
|
35
|
+
: new Set(['livestore.RawSql']);
|
36
|
+
return (mutationName, mutationEventDecoded) => {
|
37
|
+
if (mutationLogExclude.has(mutationName))
|
38
|
+
return true;
|
39
|
+
const mutationDef = schema.mutations.get(mutationName) ?? shouldNeverHappen(`Unknown mutation: ${mutationName}`);
|
40
|
+
const execArgsArr = getExecArgsFromMutation({ mutationDef, mutationEventDecoded });
|
41
|
+
return execArgsArr.some((_) => _.statementSql.includes('__livestore'));
|
42
|
+
};
|
43
|
+
});
|
44
|
+
// NOTE we should explore whether there is a more elegant solution
|
45
|
+
// e.g. by leveraging the schema to replace the sessionIdSymbol
|
46
|
+
export const replaceSessionIdSymbol = (bindValues, sessionId) => {
|
47
|
+
deepReplaceValue(bindValues, SessionIdSymbol, sessionId);
|
48
|
+
};
|
49
|
+
const deepReplaceValue = (input, searchValue, replaceValue) => {
|
50
|
+
if (Array.isArray(input)) {
|
51
|
+
for (const i in input) {
|
52
|
+
if (input[i] === searchValue) {
|
53
|
+
input[i] = replaceValue;
|
54
|
+
}
|
55
|
+
else {
|
56
|
+
deepReplaceValue(input[i], searchValue, replaceValue);
|
57
|
+
}
|
58
|
+
}
|
59
|
+
}
|
60
|
+
else if (typeof input === 'object' && input !== null) {
|
61
|
+
for (const key in input) {
|
62
|
+
if (input[key] === searchValue) {
|
63
|
+
input[key] = replaceValue;
|
64
|
+
}
|
65
|
+
else {
|
66
|
+
deepReplaceValue(input[key], searchValue, replaceValue);
|
67
|
+
}
|
68
|
+
}
|
69
|
+
}
|
70
|
+
};
|
71
|
+
//# sourceMappingURL=mutation.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"mutation.js","sourceRoot":"","sources":["../src/mutation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAClE,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAEhD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAIpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAE7C,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,EACtC,WAAW,EACX,oBAAoB,GAIrB,EAIE,EAAE;IACH,IAAI,YAEH,CAAA;IAED,QAAQ,OAAO,WAAW,CAAC,GAAG,EAAE,CAAC;QAC/B,KAAK,UAAU,CAAC,CAAC,CAAC;YAChB,MAAM,GAAG,GAAG,WAAW,CAAC,GAAG,CAAC,oBAAoB,CAAC,IAAI,CAAC,CAAA;YACtD,YAAY,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC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AI,EAAE,CAAC;QACvD,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE,CAAC;YACxB,IAAI,KAAK,CAAC,GAAG,CAAC,KAAK,WAAW,EAAE,CAAC;gBAC/B,KAAK,CAAC,GAAG,CAAC,GAAG,YAAY,CAAA;YAC3B,CAAC;iBAAM,CAAC;gBACN,gBAAgB,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,WAAW,EAAE,YAAY,CAAC,CAAA;YACzD,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC,CAAA"}
|
@@ -0,0 +1,38 @@
|
|
1
|
+
import type { SessionIdSymbol } from './adapter-types.js';
|
2
|
+
import type { DbSchema } from './schema/index.js';
|
3
|
+
/**
|
4
|
+
* Semantic information about a query with supported cases being:
|
5
|
+
* - a whole row
|
6
|
+
* - a single column value
|
7
|
+
* - a sub value in a JSON column
|
8
|
+
*
|
9
|
+
* This information is currently only used for derived mutations.
|
10
|
+
*/
|
11
|
+
export type QueryInfo = QueryInfo.None | QueryInfo.Row | QueryInfo.Col | QueryInfo.ColJsonValue;
|
12
|
+
export declare namespace QueryInfo {
|
13
|
+
type None = {
|
14
|
+
_tag: 'None';
|
15
|
+
};
|
16
|
+
type Row = {
|
17
|
+
_tag: 'Row';
|
18
|
+
table: DbSchema.TableDefBase;
|
19
|
+
id: string | SessionIdSymbol;
|
20
|
+
};
|
21
|
+
type Col = {
|
22
|
+
_tag: 'Col';
|
23
|
+
table: DbSchema.TableDefBase;
|
24
|
+
id: string | SessionIdSymbol;
|
25
|
+
column: string;
|
26
|
+
};
|
27
|
+
type ColJsonValue = {
|
28
|
+
_tag: 'ColJsonValue';
|
29
|
+
table: DbSchema.TableDefBase;
|
30
|
+
id: string | SessionIdSymbol;
|
31
|
+
column: string;
|
32
|
+
/**
|
33
|
+
* example: `$.tabs[3].items[2]` (`$` referring to the column value)
|
34
|
+
*/
|
35
|
+
jsonPath: string;
|
36
|
+
};
|
37
|
+
}
|
38
|
+
//# sourceMappingURL=query-info.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"query-info.d.ts","sourceRoot":"","sources":["../src/query-info.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACzD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAEjD;;;;;;;GAOG;AACH,MAAM,MAAM,SAAS,GAAG,SAAS,CAAC,IAAI,GAAG,SAAS,CAAC,GAAG,GAAG,SAAS,CAAC,GAAG,GAAG,SAAS,CAAC,YAAY,CAAA;AAO/F,yBAAiB,SAAS,CAAC;IACzB,KAAY,IAAI,GAAG;QACjB,IAAI,EAAE,MAAM,CAAA;KACb,CAAA;IAED,KAAY,GAAG,GAAG;QAChB,IAAI,EAAE,KAAK,CAAA;QACX,KAAK,EAAE,QAAQ,CAAC,YAAY,CAAA;QAC5B,EAAE,EAAE,MAAM,GAAG,eAAe,CAAA;KAC7B,CAAA;IAED,KAAY,GAAG,GAAG;QAChB,IAAI,EAAE,KAAK,CAAA;QACX,KAAK,EAAE,QAAQ,CAAC,YAAY,CAAA;QAC5B,EAAE,EAAE,MAAM,GAAG,eAAe,CAAA;QAC5B,MAAM,EAAE,MAAM,CAAA;KACf,CAAA;IAED,KAAY,YAAY,GAAG;QACzB,IAAI,EAAE,cAAc,CAAA;QACpB,KAAK,EAAE,QAAQ,CAAC,YAAY,CAAA;QAC5B,EAAE,EAAE,MAAM,GAAG,eAAe,CAAA;QAC5B,MAAM,EAAE,MAAM,CAAA;QACd;;WAEG;QACH,QAAQ,EAAE,MAAM,CAAA;KACjB,CAAA;CA0BF"}
|
@@ -0,0 +1,7 @@
|
|
1
|
+
export {};
|
2
|
+
// type GetJsonColumn<TTableDef extends DbSchema.TableDefBase> = keyof {
|
3
|
+
// [ColName in keyof TTableDef['sqliteDef']['columns'] as TTableDef['sqliteDef']['columns'][ColName]['columnType'] extends 'text'
|
4
|
+
// ? ColName
|
5
|
+
// : never]: {}
|
6
|
+
// }
|
7
|
+
//# sourceMappingURL=query-info.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"query-info.js","sourceRoot":"","sources":["../src/query-info.ts"],"names":[],"mappings":";AAyEA,wEAAwE;AACxE,mIAAmI;AACnI,gBAAgB;AAChB,mBAAmB;AACnB,IAAI"}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import { Effect } from '@livestore/utils/effect';
|
2
|
+
import { type MigrationOptionsFromMutationLog, type SynchronousDatabase, UnexpectedError } from './adapter-types.js';
|
3
|
+
import type { LiveStoreSchema } from './schema/index.js';
|
4
|
+
export declare const rehydrateFromMutationLog: ({ logDb, db, schema, migrationOptions, onProgress, }: {
|
5
|
+
logDb: SynchronousDatabase;
|
6
|
+
db: SynchronousDatabase;
|
7
|
+
schema: LiveStoreSchema;
|
8
|
+
migrationOptions: MigrationOptionsFromMutationLog;
|
9
|
+
onProgress: (_: {
|
10
|
+
done: number;
|
11
|
+
total: number;
|
12
|
+
}) => Effect.Effect<void>;
|
13
|
+
}) => Effect.Effect<void, UnexpectedError, never>;
|
14
|
+
//# sourceMappingURL=rehydrate-from-mutationlog.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"rehydrate-from-mutationlog.d.ts","sourceRoot":"","sources":["../src/rehydrate-from-mutationlog.ts"],"names":[],"mappings":"AACA,OAAO,EAAS,MAAM,EAA0B,MAAM,yBAAyB,CAAA;AAE/E,OAAO,EAAE,KAAK,+BAA+B,EAAE,KAAK,mBAAmB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAEpH,OAAO,KAAK,EAAE,eAAe,EAAkD,MAAM,mBAAmB,CAAA;AAKxG,eAAO,MAAM,wBAAwB,GAAI,sDAMtC;IACD,KAAK,EAAE,mBAAmB,CAAA;IAC1B,EAAE,EAAE,mBAAmB,CAAA;IACvB,MAAM,EAAE,eAAe,CAAA;IACvB,gBAAgB,EAAE,+BAA+B,CAAA;IACjD,UAAU,EAAE,CAAC,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;CACxE,gDA4GE,CAAA"}
|
@@ -0,0 +1,72 @@
|
|
1
|
+
import { memoizeByRef, shouldNeverHappen } from '@livestore/utils';
|
2
|
+
import { Chunk, Effect, Option, Schema, Stream } from '@livestore/utils/effect';
|
3
|
+
import { UnexpectedError } from './adapter-types.js';
|
4
|
+
import { getExecArgsFromMutation } from './mutation.js';
|
5
|
+
import { MUTATION_LOG_META_TABLE } from './schema/index.js';
|
6
|
+
import { sql } from './util.js';
|
7
|
+
export const rehydrateFromMutationLog = ({ logDb, db, schema, migrationOptions, onProgress, }) => Effect.gen(function* () {
|
8
|
+
const mutationsCount = logDb.select(`SELECT COUNT(*) AS count FROM ${MUTATION_LOG_META_TABLE}`)[0].count;
|
9
|
+
const hashMutation = memoizeByRef((mutation) => Schema.hash(mutation.schema));
|
10
|
+
const processMutation = (row) => Effect.gen(function* () {
|
11
|
+
const mutationDef = schema.mutations.get(row.mutation) ?? shouldNeverHappen(`Unknown mutation ${row.mutation}`);
|
12
|
+
if (migrationOptions.excludeMutations?.has(row.mutation) === true)
|
13
|
+
return;
|
14
|
+
if (hashMutation(mutationDef) !== row.schemaHash) {
|
15
|
+
yield* Effect.logWarning(`Schema hash mismatch for mutation ${row.mutation}. Trying to apply mutation anyway.`);
|
16
|
+
}
|
17
|
+
const argsDecoded = yield* Schema.decodeUnknown(Schema.parseJson(mutationDef.schema))(row.argsJson).pipe(Effect.mapError((cause) => UnexpectedError.make({
|
18
|
+
cause,
|
19
|
+
note: `\
|
20
|
+
There was an error during rehydrating from the mutation log while decoding
|
21
|
+
the persisted mutation event args for mutation "${row.mutation}".
|
22
|
+
This likely means the schema has changed in an incompatible way.
|
23
|
+
`,
|
24
|
+
})));
|
25
|
+
const mutationEventDecoded = {
|
26
|
+
id: { global: row.idGlobal, local: row.idLocal },
|
27
|
+
parentId: { global: row.parentIdGlobal, local: row.parentIdLocal },
|
28
|
+
mutation: row.mutation,
|
29
|
+
args: argsDecoded,
|
30
|
+
};
|
31
|
+
const execArgsArr = getExecArgsFromMutation({ mutationDef, mutationEventDecoded });
|
32
|
+
const makeExecuteOptions = (statementSql, bindValues) => ({
|
33
|
+
onRowsChanged: (rowsChanged) => {
|
34
|
+
if (rowsChanged === 0 && migrationOptions.logging?.excludeAffectedRows?.(statementSql) !== true) {
|
35
|
+
console.warn(`Mutation "${mutationDef.name}" did not affect any rows:`, statementSql, bindValues);
|
36
|
+
}
|
37
|
+
},
|
38
|
+
});
|
39
|
+
for (const { statementSql, bindValues } of execArgsArr) {
|
40
|
+
// TODO cache prepared statements for mutations
|
41
|
+
db.execute(statementSql, bindValues, import.meta.env.DEV ? makeExecuteOptions(statementSql, bindValues) : undefined);
|
42
|
+
// console.log(`Re-executed mutation ${mutationSql}`, bindValues)
|
43
|
+
}
|
44
|
+
}).pipe(Effect.withSpan(`@livestore/common:rehydrateFromMutationLog:processMutation`));
|
45
|
+
const CHUNK_SIZE = 100;
|
46
|
+
const stmt = logDb.prepare(sql `\
|
47
|
+
SELECT * FROM ${MUTATION_LOG_META_TABLE}
|
48
|
+
WHERE idGlobal > COALESCE($idGlobal, '') AND idLocal > COALESCE($idLocal, '')
|
49
|
+
ORDER BY idGlobal ASC, idLocal ASC
|
50
|
+
LIMIT ${CHUNK_SIZE}
|
51
|
+
`);
|
52
|
+
let processedMutations = 0;
|
53
|
+
yield* Stream.unfoldChunk({ _tag: 'Initial ' }, (item) => {
|
54
|
+
// End stream if no more rows
|
55
|
+
if (Chunk.isChunk(item) && item.length === 0)
|
56
|
+
return Option.none();
|
57
|
+
const lastId = Chunk.isChunk(item)
|
58
|
+
? Chunk.last(item).pipe(Option.map((_) => ({ global: _.idGlobal, local: _.idLocal })), Option.getOrUndefined)
|
59
|
+
: undefined;
|
60
|
+
const nextItem = Chunk.fromIterable(stmt.select({
|
61
|
+
$idGlobal: lastId?.global,
|
62
|
+
$idLocal: lastId?.local,
|
63
|
+
}));
|
64
|
+
const prevItem = Chunk.isChunk(item) ? item : Chunk.empty();
|
65
|
+
return Option.some([prevItem, nextItem]);
|
66
|
+
}).pipe(Stream.bufferChunks({ capacity: 2 }), Stream.tap((row) => Effect.gen(function* () {
|
67
|
+
yield* processMutation(row);
|
68
|
+
processedMutations++;
|
69
|
+
yield* onProgress({ done: processedMutations, total: mutationsCount });
|
70
|
+
})), Stream.runDrain);
|
71
|
+
}).pipe(Effect.withPerformanceMeasure('@livestore/common:rehydrateFromMutationLog'), Effect.withSpan('@livestore/common:rehydrateFromMutationLog'));
|
72
|
+
//# sourceMappingURL=rehydrate-from-mutationlog.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"rehydrate-from-mutationlog.js","sourceRoot":"","sources":["../src/rehydrate-from-mutationlog.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAClE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAE/E,OAAO,EAAkE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACpH,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAA;AAEvD,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAA;AAE3D,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAA;AAE/B,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,EACvC,KAAK,EACL,EAAE,EACF,MAAM,EACN,gBAAgB,EAChB,UAAU,GAOX,EAAE,EAAE,CACH,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAClB,MAAM,cAAc,GAAG,KAAK,CAAC,MAAM,CACjC,iCAAiC,uBAAuB,EAAE,CAC3D,CAAC,CAAC,CAAE,CAA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