@livestore/common 0.4.0-dev.1 → 0.4.0-dev.10
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/ClientSessionLeaderThreadProxy.d.ts +7 -2
- package/dist/ClientSessionLeaderThreadProxy.d.ts.map +1 -1
- package/dist/ClientSessionLeaderThreadProxy.js.map +1 -1
- package/dist/adapter-types.d.ts +9 -3
- package/dist/adapter-types.d.ts.map +1 -1
- package/dist/adapter-types.js.map +1 -1
- package/dist/devtools/devtools-messages-client-session.d.ts +21 -21
- package/dist/devtools/devtools-messages-common.d.ts +7 -14
- package/dist/devtools/devtools-messages-common.d.ts.map +1 -1
- package/dist/devtools/devtools-messages-common.js +1 -6
- package/dist/devtools/devtools-messages-common.js.map +1 -1
- package/dist/devtools/devtools-messages-leader.d.ts +27 -25
- package/dist/devtools/devtools-messages-leader.d.ts.map +1 -1
- package/dist/errors.d.ts +47 -5
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +22 -3
- package/dist/errors.js.map +1 -1
- package/dist/leader-thread/LeaderSyncProcessor.d.ts +7 -3
- package/dist/leader-thread/LeaderSyncProcessor.d.ts.map +1 -1
- package/dist/leader-thread/LeaderSyncProcessor.js +122 -49
- package/dist/leader-thread/LeaderSyncProcessor.js.map +1 -1
- package/dist/leader-thread/eventlog.d.ts +4 -10
- package/dist/leader-thread/eventlog.d.ts.map +1 -1
- package/dist/leader-thread/eventlog.js +4 -6
- package/dist/leader-thread/eventlog.js.map +1 -1
- package/dist/leader-thread/leader-worker-devtools.d.ts +1 -1
- package/dist/leader-thread/leader-worker-devtools.js +6 -2
- package/dist/leader-thread/leader-worker-devtools.js.map +1 -1
- package/dist/leader-thread/make-leader-thread-layer.d.ts +1 -2
- package/dist/leader-thread/make-leader-thread-layer.d.ts.map +1 -1
- package/dist/leader-thread/make-leader-thread-layer.js +68 -19
- package/dist/leader-thread/make-leader-thread-layer.js.map +1 -1
- package/dist/leader-thread/make-leader-thread-layer.test.d.ts +2 -0
- package/dist/leader-thread/make-leader-thread-layer.test.d.ts.map +1 -0
- package/dist/leader-thread/make-leader-thread-layer.test.js +32 -0
- package/dist/leader-thread/make-leader-thread-layer.test.js.map +1 -0
- package/dist/leader-thread/materialize-event.d.ts +2 -2
- package/dist/leader-thread/materialize-event.d.ts.map +1 -1
- package/dist/leader-thread/materialize-event.js +23 -9
- package/dist/leader-thread/materialize-event.js.map +1 -1
- package/dist/leader-thread/recreate-db.d.ts +2 -3
- package/dist/leader-thread/recreate-db.d.ts.map +1 -1
- package/dist/leader-thread/recreate-db.js +1 -1
- package/dist/leader-thread/recreate-db.js.map +1 -1
- package/dist/leader-thread/shutdown-channel.d.ts +2 -2
- package/dist/leader-thread/shutdown-channel.d.ts.map +1 -1
- package/dist/leader-thread/shutdown-channel.js +2 -2
- package/dist/leader-thread/shutdown-channel.js.map +1 -1
- package/dist/leader-thread/types.d.ts +7 -5
- package/dist/leader-thread/types.d.ts.map +1 -1
- package/dist/leader-thread/types.js.map +1 -1
- package/dist/materializer-helper.d.ts +1 -1
- package/dist/materializer-helper.d.ts.map +1 -1
- package/dist/materializer-helper.js +20 -4
- package/dist/materializer-helper.js.map +1 -1
- package/dist/rematerialize-from-eventlog.d.ts +1 -1
- package/dist/rematerialize-from-eventlog.d.ts.map +1 -1
- package/dist/rematerialize-from-eventlog.js +25 -16
- package/dist/rematerialize-from-eventlog.js.map +1 -1
- package/dist/schema/EventDef.d.ts +3 -0
- package/dist/schema/EventDef.d.ts.map +1 -1
- package/dist/schema/EventDef.js.map +1 -1
- package/dist/schema/LiveStoreEvent.d.ts +1 -1
- package/dist/schema/LiveStoreEvent.d.ts.map +1 -1
- package/dist/schema/LiveStoreEvent.js +1 -2
- package/dist/schema/LiveStoreEvent.js.map +1 -1
- package/dist/schema/mod.d.ts +2 -0
- package/dist/schema/mod.d.ts.map +1 -1
- package/dist/schema/mod.js +1 -0
- package/dist/schema/mod.js.map +1 -1
- package/dist/schema/schema.d.ts +15 -0
- package/dist/schema/schema.d.ts.map +1 -1
- package/dist/schema/schema.js +26 -1
- package/dist/schema/schema.js.map +1 -1
- package/dist/schema/state/sqlite/client-document-def.d.ts +35 -5
- package/dist/schema/state/sqlite/client-document-def.d.ts.map +1 -1
- package/dist/schema/state/sqlite/client-document-def.js +95 -4
- package/dist/schema/state/sqlite/client-document-def.js.map +1 -1
- package/dist/schema/state/sqlite/client-document-def.test.js +16 -0
- package/dist/schema/state/sqlite/client-document-def.test.js.map +1 -1
- package/dist/schema/state/sqlite/column-annotations.d.ts.map +1 -1
- package/dist/schema/state/sqlite/column-annotations.js +14 -6
- package/dist/schema/state/sqlite/column-annotations.js.map +1 -1
- package/dist/schema/state/sqlite/column-def.d.ts +6 -2
- package/dist/schema/state/sqlite/column-def.d.ts.map +1 -1
- package/dist/schema/state/sqlite/column-def.js +122 -185
- package/dist/schema/state/sqlite/column-def.js.map +1 -1
- package/dist/schema/state/sqlite/column-def.test.js +116 -73
- package/dist/schema/state/sqlite/column-def.test.js.map +1 -1
- package/dist/schema/state/sqlite/db-schema/ast/sqlite.d.ts +2 -1
- package/dist/schema/state/sqlite/db-schema/ast/sqlite.d.ts.map +1 -1
- package/dist/schema/state/sqlite/db-schema/ast/sqlite.js +23 -6
- package/dist/schema/state/sqlite/db-schema/ast/sqlite.js.map +1 -1
- package/dist/schema/state/sqlite/db-schema/dsl/mod.d.ts.map +1 -1
- package/dist/schema/state/sqlite/db-schema/dsl/mod.js +2 -1
- package/dist/schema/state/sqlite/db-schema/dsl/mod.js.map +1 -1
- package/dist/schema/state/sqlite/mod.d.ts +1 -1
- package/dist/schema/state/sqlite/mod.d.ts.map +1 -1
- package/dist/schema/state/sqlite/mod.js +1 -1
- package/dist/schema/state/sqlite/mod.js.map +1 -1
- package/dist/schema/state/sqlite/query-builder/api.d.ts +5 -2
- package/dist/schema/state/sqlite/query-builder/api.d.ts.map +1 -1
- package/dist/schema/state/sqlite/query-builder/impl.d.ts.map +1 -1
- package/dist/schema/state/sqlite/query-builder/impl.js +6 -2
- package/dist/schema/state/sqlite/query-builder/impl.js.map +1 -1
- package/dist/schema/state/sqlite/query-builder/impl.test.js +137 -2
- package/dist/schema/state/sqlite/query-builder/impl.test.js.map +1 -1
- package/dist/schema/state/sqlite/system-tables.d.ts +42 -6
- package/dist/schema/state/sqlite/system-tables.d.ts.map +1 -1
- package/dist/schema/state/sqlite/system-tables.js +2 -0
- package/dist/schema/state/sqlite/system-tables.js.map +1 -1
- package/dist/schema/state/sqlite/table-def.d.ts +4 -4
- package/dist/schema/state/sqlite/table-def.d.ts.map +1 -1
- package/dist/schema/state/sqlite/table-def.js +2 -2
- package/dist/schema/state/sqlite/table-def.js.map +1 -1
- package/dist/schema/state/sqlite/table-def.test.js +51 -2
- package/dist/schema/state/sqlite/table-def.test.js.map +1 -1
- package/dist/schema/unknown-events.d.ts +47 -0
- package/dist/schema/unknown-events.d.ts.map +1 -0
- package/dist/schema/unknown-events.js +69 -0
- package/dist/schema/unknown-events.js.map +1 -0
- package/dist/sql-queries/sql-query-builder.d.ts.map +1 -1
- package/dist/sql-queries/sql-query-builder.js +2 -1
- package/dist/sql-queries/sql-query-builder.js.map +1 -1
- package/dist/sync/ClientSessionSyncProcessor.d.ts +9 -11
- package/dist/sync/ClientSessionSyncProcessor.d.ts.map +1 -1
- package/dist/sync/ClientSessionSyncProcessor.js +35 -33
- package/dist/sync/ClientSessionSyncProcessor.js.map +1 -1
- package/dist/sync/errors.d.ts +61 -0
- package/dist/sync/errors.d.ts.map +1 -0
- package/dist/sync/errors.js +36 -0
- package/dist/sync/errors.js.map +1 -0
- package/dist/sync/index.d.ts +3 -0
- package/dist/sync/index.d.ts.map +1 -1
- package/dist/sync/index.js +3 -0
- package/dist/sync/index.js.map +1 -1
- package/dist/sync/mock-sync-backend.d.ts +23 -0
- package/dist/sync/mock-sync-backend.d.ts.map +1 -0
- package/dist/sync/mock-sync-backend.js +114 -0
- package/dist/sync/mock-sync-backend.js.map +1 -0
- package/dist/sync/next/compact-events.d.ts.map +1 -1
- package/dist/sync/next/compact-events.js +4 -5
- package/dist/sync/next/compact-events.js.map +1 -1
- package/dist/sync/next/facts.d.ts.map +1 -1
- package/dist/sync/next/facts.js +1 -2
- package/dist/sync/next/facts.js.map +1 -1
- package/dist/sync/next/history-dag-common.d.ts +50 -11
- package/dist/sync/next/history-dag-common.d.ts.map +1 -1
- package/dist/sync/next/history-dag-common.js +193 -4
- package/dist/sync/next/history-dag-common.js.map +1 -1
- package/dist/sync/next/history-dag.d.ts.map +1 -1
- package/dist/sync/next/history-dag.js +3 -1
- package/dist/sync/next/history-dag.js.map +1 -1
- package/dist/sync/sync-backend-kv.d.ts +7 -0
- package/dist/sync/sync-backend-kv.d.ts.map +1 -0
- package/dist/sync/sync-backend-kv.js +18 -0
- package/dist/sync/sync-backend-kv.js.map +1 -0
- package/dist/sync/sync-backend.d.ts +105 -0
- package/dist/sync/sync-backend.d.ts.map +1 -0
- package/dist/sync/sync-backend.js +61 -0
- package/dist/sync/sync-backend.js.map +1 -0
- package/dist/sync/sync.d.ts +6 -84
- package/dist/sync/sync.d.ts.map +1 -1
- package/dist/sync/sync.js +2 -27
- package/dist/sync/sync.js.map +1 -1
- package/dist/sync/transport-chunking.d.ts +36 -0
- package/dist/sync/transport-chunking.d.ts.map +1 -0
- package/dist/sync/transport-chunking.js +56 -0
- package/dist/sync/transport-chunking.js.map +1 -0
- package/dist/sync/validate-push-payload.d.ts +1 -1
- package/dist/sync/validate-push-payload.d.ts.map +1 -1
- package/dist/sync/validate-push-payload.js +6 -6
- package/dist/sync/validate-push-payload.js.map +1 -1
- package/dist/testing/event-factory.d.ts +68 -0
- package/dist/testing/event-factory.d.ts.map +1 -0
- package/dist/testing/event-factory.js +80 -0
- package/dist/testing/event-factory.js.map +1 -0
- package/dist/testing/mod.d.ts +2 -0
- package/dist/testing/mod.d.ts.map +1 -0
- package/dist/testing/mod.js +2 -0
- package/dist/testing/mod.js.map +1 -0
- package/dist/version.d.ts +2 -2
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +2 -2
- package/dist/version.js.map +1 -1
- package/package.json +7 -8
- package/src/ClientSessionLeaderThreadProxy.ts +7 -2
- package/src/adapter-types.ts +13 -3
- package/src/devtools/devtools-messages-common.ts +1 -8
- package/src/errors.ts +33 -4
- package/src/leader-thread/LeaderSyncProcessor.ts +179 -57
- package/src/leader-thread/eventlog.ts +10 -6
- package/src/leader-thread/leader-worker-devtools.ts +6 -2
- package/src/leader-thread/make-leader-thread-layer.test.ts +44 -0
- package/src/leader-thread/make-leader-thread-layer.ts +137 -26
- package/src/leader-thread/materialize-event.ts +34 -9
- package/src/leader-thread/recreate-db.ts +11 -3
- package/src/leader-thread/shutdown-channel.ts +16 -2
- package/src/leader-thread/types.ts +7 -5
- package/src/materializer-helper.ts +22 -5
- package/src/rematerialize-from-eventlog.ts +33 -23
- package/src/schema/EventDef.ts +3 -0
- package/src/schema/LiveStoreEvent.ts +1 -2
- package/src/schema/mod.ts +2 -0
- package/src/schema/schema.ts +37 -1
- package/src/schema/state/sqlite/client-document-def.test.ts +17 -0
- package/src/schema/state/sqlite/client-document-def.ts +117 -5
- package/src/schema/state/sqlite/column-annotations.ts +16 -6
- package/src/schema/state/sqlite/column-def.test.ts +150 -93
- package/src/schema/state/sqlite/column-def.ts +128 -203
- package/src/schema/state/sqlite/db-schema/ast/sqlite.ts +26 -6
- package/src/schema/state/sqlite/db-schema/dsl/mod.ts +2 -1
- package/src/schema/state/sqlite/mod.ts +1 -0
- package/src/schema/state/sqlite/query-builder/api.ts +7 -2
- package/src/schema/state/sqlite/query-builder/impl.test.ts +187 -6
- package/src/schema/state/sqlite/query-builder/impl.ts +8 -2
- package/src/schema/state/sqlite/system-tables.ts +2 -0
- package/src/schema/state/sqlite/table-def.test.ts +64 -2
- package/src/schema/state/sqlite/table-def.ts +9 -8
- package/src/schema/unknown-events.ts +131 -0
- package/src/sql-queries/sql-query-builder.ts +2 -1
- package/src/sync/ClientSessionSyncProcessor.ts +55 -49
- package/src/sync/errors.ts +38 -0
- package/src/sync/index.ts +3 -0
- package/src/sync/mock-sync-backend.ts +184 -0
- package/src/sync/next/compact-events.ts +4 -5
- package/src/sync/next/facts.ts +1 -3
- package/src/sync/next/history-dag-common.ts +272 -21
- package/src/sync/next/history-dag.ts +3 -1
- package/src/sync/sync-backend-kv.ts +22 -0
- package/src/sync/sync-backend.ts +185 -0
- package/src/sync/sync.ts +6 -89
- package/src/sync/transport-chunking.ts +90 -0
- package/src/sync/validate-push-payload.ts +6 -7
- package/src/testing/event-factory.ts +133 -0
- package/src/testing/mod.ts +1 -0
- package/src/version.ts +2 -2
- package/dist/schema-management/migrations.test.d.ts +0 -2
- package/dist/schema-management/migrations.test.d.ts.map +0 -1
- package/dist/schema-management/migrations.test.js +0 -52
- package/dist/schema-management/migrations.test.js.map +0 -1
- package/dist/sync/next/graphology.d.ts +0 -8
- package/dist/sync/next/graphology.d.ts.map +0 -1
- package/dist/sync/next/graphology.js +0 -30
- package/dist/sync/next/graphology.js.map +0 -1
- package/dist/sync/next/graphology_.d.ts +0 -3
- package/dist/sync/next/graphology_.d.ts.map +0 -1
- package/dist/sync/next/graphology_.js +0 -3
- package/dist/sync/next/graphology_.js.map +0 -1
- package/src/sync/next/ambient.d.ts +0 -3
- package/src/sync/next/graphology.ts +0 -41
- package/src/sync/next/graphology_.ts +0 -2
@@ -0,0 +1,80 @@
|
|
1
|
+
/**
|
2
|
+
* Helpers for synthesizing LiveStore events in tests while keeping track of
|
3
|
+
* sequence numbers, parent pointers, and authoring client identity. Inspired
|
4
|
+
* by the effect-based schema utilities, the factory exposes a namespaced API
|
5
|
+
* where each event definition maps to a helper with `next`, `advanceTo`, and
|
6
|
+
* `setParent` functions that share a single sequence stream.
|
7
|
+
*
|
8
|
+
* @example
|
9
|
+
* ```ts
|
10
|
+
* import { EventFactory } from '@livestore/common/testing'
|
11
|
+
* import { events } from './schema'
|
12
|
+
*
|
13
|
+
* const eventFactory = EventFactory.makeFactory(events)({
|
14
|
+
* client: EventFactory.clientIdentity('test-client'),
|
15
|
+
* startSeq: 1,
|
16
|
+
* initialParent: 'root',
|
17
|
+
* })
|
18
|
+
*
|
19
|
+
* const bootstrap = eventFactory.todoCreated.next({
|
20
|
+
* id: 'todo-1',
|
21
|
+
* text: 'write tests',
|
22
|
+
* completed: false,
|
23
|
+
* })
|
24
|
+
*
|
25
|
+
* eventFactory.todoCreated.advanceTo(42)
|
26
|
+
* const branched = eventFactory.todoUpdated.next({
|
27
|
+
* id: 'todo-1',
|
28
|
+
* text: 'ship feature',
|
29
|
+
* completed: true,
|
30
|
+
* })
|
31
|
+
* ```
|
32
|
+
*/
|
33
|
+
import { Schema } from '@livestore/utils/effect';
|
34
|
+
import * as EventSequenceNumber from "../schema/EventSequenceNumber.js";
|
35
|
+
import * as LiveStoreEvent from "../schema/LiveStoreEvent.js";
|
36
|
+
export const clientIdentity = (label, session = `${label}-session`) => ({
|
37
|
+
clientId: label,
|
38
|
+
sessionId: session,
|
39
|
+
});
|
40
|
+
export const makeFactory = (eventDefs) => ({ client, startSeq = 1, initialParent = 'root', }) => {
|
41
|
+
let nextSeq = startSeq;
|
42
|
+
let parentRef = initialParent;
|
43
|
+
const advanceTo = (seq, parent = 'root') => {
|
44
|
+
nextSeq = seq;
|
45
|
+
parentRef = parent;
|
46
|
+
};
|
47
|
+
const setParent = (parent) => {
|
48
|
+
parentRef = parent;
|
49
|
+
};
|
50
|
+
const current = () => ({ seq: nextSeq, parent: parentRef });
|
51
|
+
const factories = {};
|
52
|
+
for (const [name, eventDef] of Object.entries(eventDefs)) {
|
53
|
+
const next = (args) => {
|
54
|
+
const decoded = eventDef(args);
|
55
|
+
const encodedArgs = Schema.encodeSync(eventDef.schema)(decoded.args);
|
56
|
+
const encoded = eventDef.encoded(encodedArgs);
|
57
|
+
const event = LiveStoreEvent.AnyEncodedGlobal.make({
|
58
|
+
name: encoded.name,
|
59
|
+
args: encoded.args,
|
60
|
+
seqNum: EventSequenceNumber.globalEventSequenceNumber(nextSeq),
|
61
|
+
parentSeqNum: parentRef === 'root'
|
62
|
+
? EventSequenceNumber.ROOT.global
|
63
|
+
: EventSequenceNumber.globalEventSequenceNumber(parentRef),
|
64
|
+
clientId: client.clientId,
|
65
|
+
sessionId: client.sessionId,
|
66
|
+
});
|
67
|
+
parentRef = nextSeq;
|
68
|
+
nextSeq = nextSeq + 1;
|
69
|
+
return event;
|
70
|
+
};
|
71
|
+
factories[name] = {
|
72
|
+
next,
|
73
|
+
advanceTo,
|
74
|
+
setParent,
|
75
|
+
current,
|
76
|
+
};
|
77
|
+
}
|
78
|
+
return factories;
|
79
|
+
};
|
80
|
+
//# sourceMappingURL=event-factory.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"event-factory.js","sourceRoot":"","sources":["../../src/testing/event-factory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAGhD,OAAO,KAAK,mBAAmB,MAAM,kCAAkC,CAAA;AACvE,OAAO,KAAK,cAAc,MAAM,6BAA6B,CAAA;AAO7D,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,KAAa,EAAE,OAAO,GAAG,GAAG,KAAK,UAAU,EAAkB,EAAE,CAAC,CAAC;IAC9F,QAAQ,EAAE,KAAK;IACf,SAAS,EAAE,OAAO;CACnB,CAAC,CAAA;AA6BF,MAAM,CAAC,MAAM,WAAW,GACtB,CAA6C,SAAgB,EAAE,EAAE,CACjE,CAAC,EACC,MAAM,EACN,QAAQ,GAAG,CAAC,EACZ,aAAa,GAAG,MAAM,GACD,EAA0D,EAAE;IACjF,IAAI,OAAO,GAAG,QAAQ,CAAA;IACtB,IAAI,SAAS,GAAkB,aAAa,CAAA;IAE5C,MAAM,SAAS,GAAG,CAAC,GAAW,EAAE,SAAwB,MAAM,EAAE,EAAE;QAChE,OAAO,GAAG,GAAG,CAAA;QACb,SAAS,GAAG,MAAM,CAAA;IACpB,CAAC,CAAA;IAED,MAAM,SAAS,GAAG,CAAC,MAAqB,EAAE,EAAE;QAC1C,SAAS,GAAG,MAAM,CAAA;IACpB,CAAC,CAAA;IAED,MAAM,OAAO,GAAG,GAAG,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAA;IAE3D,MAAM,SAAS,GAAoE,EAAE,CAAA;IAErF,KAAK,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,SAAS,CAAwC,EAAE,CAAC;QAChG,MAAM,IAAI,GAAG,CAAC,IAA4C,EAAE,EAAE;YAC5D,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAA;YAC9B,MAAM,WAAW,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;YACpE,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC,WAAW,CAAC,CAAA;YAE7C,MAAM,KAAK,GAAG,cAAc,CAAC,gBAAgB,CAAC,IAAI,CAAC;gBACjD,IAAI,EAAE,OAAO,CAAC,IAAI;gBAClB,IAAI,EAAE,OAAO,CAAC,IAAI;gBAClB,MAAM,EAAE,mBAAmB,CAAC,yBAAyB,CAAC,OAAO,CAAC;gBAC9D,YAAY,EACV,SAAS,KAAK,MAAM;oBAClB,CAAC,CAAC,mBAAmB,CAAC,IAAI,CAAC,MAAM;oBACjC,CAAC,CAAC,mBAAmB,CAAC,yBAAyB,CAAC,SAAS,CAAC;gBAC9D,QAAQ,EAAE,MAAM,CAAC,QAAQ;gBACzB,SAAS,EAAE,MAAM,CAAC,SAAS;aAC5B,CAAC,CAAA;YAEF,SAAS,GAAG,OAAO,CAAA;YACnB,OAAO,GAAG,OAAO,GAAG,CAAC,CAAA;YAErB,OAAO,KAAK,CAAA;QACd,CAAC,CAAA;QAED,SAAS,CAAC,IAAI,CAAC,GAAG;YAChB,IAAI;YACJ,SAAS;YACT,SAAS;YACT,OAAO;SAC+D,CAAA;IAC1E,CAAC;IAED,OAAO,SAAmE,CAAA;AAC5E,CAAC,CAAA"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/testing/mod.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,YAAY,MAAM,oBAAoB,CAAA"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../../src/testing/mod.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,YAAY,MAAM,oBAAoB,CAAA"}
|
package/dist/version.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
export declare const liveStoreVersion: "0.4.0-dev.
|
1
|
+
export declare const liveStoreVersion: "0.4.0-dev.10";
|
2
2
|
/**
|
3
3
|
* This version number is incremented whenever the internal storage format changes in a breaking way.
|
4
4
|
* Whenever this version changes, LiveStore will start with fresh database files. Old database files are not deleted.
|
@@ -6,5 +6,5 @@ export declare const liveStoreVersion: "0.4.0-dev.1";
|
|
6
6
|
* While LiveStore is in beta, this might happen more frequently.
|
7
7
|
* In the future, LiveStore will provide a migration path for older database files to avoid the impression of data loss.
|
8
8
|
*/
|
9
|
-
export declare const liveStoreStorageFormatVersion =
|
9
|
+
export declare const liveStoreStorageFormatVersion = 6;
|
10
10
|
//# sourceMappingURL=version.d.ts.map
|
package/dist/version.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,gBAAgB,EAAG,
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,gBAAgB,EAAG,cAAuB,CAAA;AAEvD;;;;;;GAMG;AACH,eAAO,MAAM,6BAA6B,IAAI,CAAA"}
|
package/dist/version.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
// TODO bring back when Expo and Playwright supports `with` imports
|
2
2
|
// import packageJson from '../package.json' with { type: 'json' }
|
3
3
|
// export const liveStoreVersion = packageJson.version
|
4
|
-
export const liveStoreVersion = '0.4.0-dev.
|
4
|
+
export const liveStoreVersion = '0.4.0-dev.10';
|
5
5
|
/**
|
6
6
|
* This version number is incremented whenever the internal storage format changes in a breaking way.
|
7
7
|
* Whenever this version changes, LiveStore will start with fresh database files. Old database files are not deleted.
|
@@ -9,5 +9,5 @@ export const liveStoreVersion = '0.4.0-dev.1';
|
|
9
9
|
* While LiveStore is in beta, this might happen more frequently.
|
10
10
|
* In the future, LiveStore will provide a migration path for older database files to avoid the impression of data loss.
|
11
11
|
*/
|
12
|
-
export const liveStoreStorageFormatVersion =
|
12
|
+
export const liveStoreStorageFormatVersion = 6;
|
13
13
|
//# sourceMappingURL=version.js.map
|
package/dist/version.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,kEAAkE;AAClE,sDAAsD;AAEtD,MAAM,CAAC,MAAM,gBAAgB,GAAG,
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,kEAAkE;AAClE,sDAAsD;AAEtD,MAAM,CAAC,MAAM,gBAAgB,GAAG,cAAuB,CAAA;AAEvD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAAC,CAAA"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@livestore/common",
|
3
|
-
"version": "0.4.0-dev.
|
3
|
+
"version": "0.4.0-dev.10",
|
4
4
|
"type": "module",
|
5
5
|
"sideEffects": false,
|
6
6
|
"exports": {
|
@@ -8,20 +8,19 @@
|
|
8
8
|
"./sql-queries": "./dist/sql-queries/index.js",
|
9
9
|
"./leader-thread": "./dist/leader-thread/mod.js",
|
10
10
|
"./schema": "./dist/schema/mod.js",
|
11
|
+
"./sync": "./dist/sync/index.js",
|
11
12
|
"./sync/next": "./dist/sync/next/mod.js",
|
12
|
-
"./sync/next/test": "./dist/sync/next/test/mod.js"
|
13
|
+
"./sync/next/test": "./dist/sync/next/test/mod.js",
|
14
|
+
"./testing": "./dist/testing/mod.js"
|
13
15
|
},
|
14
16
|
"dependencies": {
|
15
17
|
"@opentelemetry/api": "1.9.0",
|
16
|
-
"
|
17
|
-
"
|
18
|
-
"graphology-types": "0.24.8",
|
19
|
-
"@livestore/webmesh": "0.4.0-dev.1",
|
20
|
-
"@livestore/utils": "0.4.0-dev.1"
|
18
|
+
"@livestore/utils": "0.4.0-dev.10",
|
19
|
+
"@livestore/webmesh": "0.4.0-dev.10"
|
21
20
|
},
|
22
21
|
"devDependencies": {
|
23
22
|
"vitest": "3.2.4",
|
24
|
-
"@livestore/utils-dev": "0.4.0-dev.
|
23
|
+
"@livestore/utils-dev": "0.4.0-dev.10"
|
25
24
|
},
|
26
25
|
"files": [
|
27
26
|
"package.json",
|
@@ -1,11 +1,11 @@
|
|
1
|
-
import type { Effect, Stream } from '@livestore/utils/effect'
|
1
|
+
import type { Effect, Stream, Subscribable } from '@livestore/utils/effect'
|
2
2
|
|
3
3
|
import type { MigrationsReport } from './defs.ts'
|
4
4
|
import type * as Devtools from './devtools/mod.ts'
|
5
5
|
import type { UnexpectedError } from './errors.ts'
|
6
6
|
import type * as EventSequenceNumber from './schema/EventSequenceNumber.ts'
|
7
7
|
import type { LiveStoreEvent } from './schema/mod.ts'
|
8
|
-
import type { LeaderAheadError } from './sync/sync.ts'
|
8
|
+
import type { LeaderAheadError, SyncBackend } from './sync/sync.ts'
|
9
9
|
import type { PayloadUpstream, SyncState } from './sync/syncstate.ts'
|
10
10
|
|
11
11
|
export interface ClientSessionLeaderThreadProxy {
|
@@ -28,6 +28,11 @@ export interface ClientSessionLeaderThreadProxy {
|
|
28
28
|
getSyncState: Effect.Effect<SyncState, UnexpectedError>
|
29
29
|
/** For debugging purposes it can be useful to manually trigger devtools messages (e.g. to reset the database) */
|
30
30
|
sendDevtoolsMessage: (message: Devtools.Leader.MessageToApp) => Effect.Effect<void, UnexpectedError>
|
31
|
+
/**
|
32
|
+
* Reactive stream describing the connectivity between the leader and its upstream sync backend.
|
33
|
+
* Includes raw connection state, last transition timestamp, and devtools overrides (latch state).
|
34
|
+
*/
|
35
|
+
networkStatus: Subscribable.Subscribable<SyncBackend.NetworkStatus>
|
31
36
|
}
|
32
37
|
|
33
38
|
export const of = (
|
package/src/adapter-types.ts
CHANGED
@@ -10,15 +10,21 @@ import {
|
|
10
10
|
|
11
11
|
import type { ClientSessionLeaderThreadProxy } from './ClientSessionLeaderThreadProxy.ts'
|
12
12
|
import type * as Devtools from './devtools/mod.ts'
|
13
|
-
import type { IntentionalShutdownCause,
|
13
|
+
import type { IntentionalShutdownCause, MaterializeError, UnexpectedError } from './errors.ts'
|
14
14
|
import type { LiveStoreSchema } from './schema/mod.ts'
|
15
15
|
import type { SqliteDb } from './sqlite-types.ts'
|
16
|
+
import type { IsOfflineError, SyncError } from './sync/index.js'
|
16
17
|
|
17
18
|
export * as ClientSessionLeaderThreadProxy from './ClientSessionLeaderThreadProxy.ts'
|
18
19
|
export * from './defs.ts'
|
19
20
|
export * from './errors.ts'
|
20
21
|
export * from './sqlite-types.ts'
|
21
22
|
|
23
|
+
/**
|
24
|
+
* Runtime handle to an active LiveStore client session within the current process.
|
25
|
+
* Provides direct access to the embedded SQLite database, leader thread bridge,
|
26
|
+
* and lifecycle controls useful for application-level coordination.
|
27
|
+
*/
|
22
28
|
export interface ClientSession {
|
23
29
|
/** SQLite database with synchronous API running in the same thread (usually in-memory) */
|
24
30
|
sqliteDb: SqliteDb
|
@@ -27,7 +33,9 @@ export interface ClientSession {
|
|
27
33
|
sessionId: string
|
28
34
|
/** Status info whether current session is leader or not */
|
29
35
|
lockStatus: SubscriptionRef.SubscriptionRef<LockStatus>
|
30
|
-
shutdown: (
|
36
|
+
shutdown: (
|
37
|
+
cause: Exit.Exit<IntentionalShutdownCause, UnexpectedError | SyncError | MaterializeError>,
|
38
|
+
) => Effect.Effect<void>
|
31
39
|
/** A proxy API to communicate with the leader thread */
|
32
40
|
leaderThread: ClientSessionLeaderThreadProxy
|
33
41
|
/** A unique identifier for the current instance of the client session. Used for debugging purposes. */
|
@@ -121,7 +129,9 @@ export interface AdapterArgs {
|
|
121
129
|
devtoolsEnabled: boolean
|
122
130
|
debugInstanceId: string
|
123
131
|
bootStatusQueue: Queue.Queue<BootStatus>
|
124
|
-
shutdown: (
|
132
|
+
shutdown: (
|
133
|
+
exit: Exit.Exit<IntentionalShutdownCause, UnexpectedError | SyncError | MaterializeError | IsOfflineError>,
|
134
|
+
) => Effect.Effect<void>
|
125
135
|
connectDevtoolsToStore: ConnectDevtoolsToStore
|
126
136
|
/**
|
127
137
|
* Payload that will be passed to the sync backend when connecting
|
@@ -2,14 +2,7 @@ import { Schema } from '@livestore/utils/effect'
|
|
2
2
|
|
3
3
|
import { liveStoreVersion as pkgVersion } from '../version.ts'
|
4
4
|
|
5
|
-
export
|
6
|
-
isConnected: Schema.Boolean,
|
7
|
-
timestampMs: Schema.Number,
|
8
|
-
/** Whether the network status devtools latch is closed. Used to simulate network disconnection. */
|
9
|
-
latchClosed: Schema.Boolean,
|
10
|
-
})
|
11
|
-
|
12
|
-
export type NetworkStatus = typeof NetworkStatus.Type
|
5
|
+
export { NetworkStatus } from '../sync/sync-backend.ts'
|
13
6
|
|
14
7
|
export const requestId = Schema.String
|
15
8
|
export const clientId = Schema.String
|
package/src/errors.ts
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
import { Effect, Schema, Stream } from '@livestore/utils/effect'
|
1
|
+
import { Cause, Effect, Layer, Schema, Stream } from '@livestore/utils/effect'
|
2
|
+
|
3
|
+
import * as LiveStoreEvent from './schema/LiveStoreEvent.ts'
|
2
4
|
|
3
5
|
export class UnexpectedError extends Schema.TaggedError<UnexpectedError>()('LiveStore.UnexpectedError', {
|
4
6
|
cause: Schema.Defect,
|
@@ -11,15 +13,30 @@ export class UnexpectedError extends Schema.TaggedError<UnexpectedError>()('Live
|
|
11
13
|
Effect.catchAllDefect((cause) => new UnexpectedError({ cause })),
|
12
14
|
)
|
13
15
|
|
16
|
+
static mapToUnexpectedErrorLayer = <A, E, R>(layer: Layer.Layer<A, E, R>) =>
|
17
|
+
layer.pipe(
|
18
|
+
Layer.catchAllCause((cause) =>
|
19
|
+
Cause.isFailType(cause) && Schema.is(UnexpectedError)(cause.error)
|
20
|
+
? Layer.fail(cause.error)
|
21
|
+
: Layer.fail(new UnexpectedError({ cause: cause })),
|
22
|
+
),
|
23
|
+
)
|
24
|
+
|
14
25
|
static mapToUnexpectedErrorStream = <A, E, R>(stream: Stream.Stream<A, E, R>) =>
|
15
26
|
stream.pipe(
|
16
27
|
Stream.mapError((cause) => (Schema.is(UnexpectedError)(cause) ? cause : new UnexpectedError({ cause }))),
|
17
28
|
)
|
18
29
|
}
|
19
30
|
|
20
|
-
export class
|
21
|
-
|
22
|
-
|
31
|
+
export class MaterializerHashMismatchError extends Schema.TaggedError<MaterializerHashMismatchError>()(
|
32
|
+
'LiveStore.MaterializerHashMismatchError',
|
33
|
+
{
|
34
|
+
eventName: Schema.String,
|
35
|
+
note: Schema.optionalWith(Schema.String, {
|
36
|
+
default: () => 'Please make sure your event materializer is a pure function without side effects.',
|
37
|
+
}),
|
38
|
+
},
|
39
|
+
) {}
|
23
40
|
|
24
41
|
export class IntentionalShutdownCause extends Schema.TaggedError<IntentionalShutdownCause>()(
|
25
42
|
'LiveStore.IntentionalShutdownCause',
|
@@ -47,3 +64,15 @@ export class SqliteError extends Schema.TaggedError<SqliteError>()('LiveStore.Sq
|
|
47
64
|
cause: Schema.Defect,
|
48
65
|
note: Schema.optional(Schema.String),
|
49
66
|
}) {}
|
67
|
+
|
68
|
+
export class UnknownEventError extends Schema.TaggedError<UnknownEventError>()('LiveStore.UnknownEventError', {
|
69
|
+
event: LiveStoreEvent.AnyEncoded.pipe(Schema.pick('name', 'args', 'seqNum', 'clientId', 'sessionId')),
|
70
|
+
reason: Schema.Literal('event-definition-missing', 'materializer-missing'),
|
71
|
+
operation: Schema.String,
|
72
|
+
note: Schema.optional(Schema.String),
|
73
|
+
}) {}
|
74
|
+
|
75
|
+
export class MaterializeError extends Schema.TaggedError<MaterializeError>()('LiveStore.MaterializeError', {
|
76
|
+
cause: Schema.Union(MaterializerHashMismatchError, SqliteError, UnknownEventError),
|
77
|
+
note: Schema.optional(Schema.String),
|
78
|
+
}) {}
|