@livestore/common 0.4.0-dev.17 → 0.4.0-dev.19
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 +10 -10
- package/dist/ClientSessionLeaderThreadProxy.d.ts.map +1 -1
- package/dist/adapter-types.d.ts +5 -5
- package/dist/adapter-types.d.ts.map +1 -1
- package/dist/devtools/devtools-messages-client-session.d.ts +28 -23
- package/dist/devtools/devtools-messages-client-session.d.ts.map +1 -1
- package/dist/devtools/devtools-messages-client-session.js +2 -2
- package/dist/devtools/devtools-messages-client-session.js.map +1 -1
- package/dist/devtools/devtools-messages-common.d.ts +6 -6
- package/dist/devtools/devtools-messages-leader.d.ts +33 -28
- package/dist/devtools/devtools-messages-leader.d.ts.map +1 -1
- package/dist/devtools/devtools-messages-leader.js +8 -8
- package/dist/devtools/devtools-messages-leader.js.map +1 -1
- package/dist/errors.d.ts +6 -6
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +7 -7
- package/dist/errors.js.map +1 -1
- package/dist/leader-thread/LeaderSyncProcessor.d.ts +2 -2
- package/dist/leader-thread/LeaderSyncProcessor.d.ts.map +1 -1
- package/dist/leader-thread/LeaderSyncProcessor.js +28 -28
- package/dist/leader-thread/LeaderSyncProcessor.js.map +1 -1
- package/dist/leader-thread/eventlog.d.ts +13 -13
- package/dist/leader-thread/eventlog.d.ts.map +1 -1
- package/dist/leader-thread/eventlog.js +12 -11
- package/dist/leader-thread/eventlog.js.map +1 -1
- package/dist/leader-thread/leader-worker-devtools.d.ts +2 -2
- package/dist/leader-thread/leader-worker-devtools.d.ts.map +1 -1
- package/dist/leader-thread/leader-worker-devtools.js +3 -3
- package/dist/leader-thread/leader-worker-devtools.js.map +1 -1
- package/dist/leader-thread/make-leader-thread-layer.d.ts +2 -2
- package/dist/leader-thread/make-leader-thread-layer.d.ts.map +1 -1
- package/dist/leader-thread/make-leader-thread-layer.js +10 -8
- package/dist/leader-thread/make-leader-thread-layer.js.map +1 -1
- package/dist/leader-thread/materialize-event.d.ts +1 -1
- package/dist/leader-thread/materialize-event.d.ts.map +1 -1
- package/dist/leader-thread/materialize-event.js +2 -2
- package/dist/leader-thread/materialize-event.js.map +1 -1
- package/dist/leader-thread/recreate-db.d.ts +2 -2
- package/dist/leader-thread/recreate-db.d.ts.map +1 -1
- package/dist/leader-thread/recreate-db.js +5 -5
- 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 +15 -15
- package/dist/leader-thread/types.d.ts.map +1 -1
- package/dist/make-client-session.d.ts +2 -2
- package/dist/make-client-session.d.ts.map +1 -1
- package/dist/materializer-helper.d.ts +5 -5
- package/dist/materializer-helper.d.ts.map +1 -1
- package/dist/materializer-helper.js.map +1 -1
- package/dist/rematerialize-from-eventlog.d.ts +2 -2
- package/dist/rematerialize-from-eventlog.d.ts.map +1 -1
- package/dist/rematerialize-from-eventlog.js +6 -6
- package/dist/rematerialize-from-eventlog.js.map +1 -1
- package/dist/schema/EventDef/define.d.ts +147 -0
- package/dist/schema/EventDef/define.d.ts.map +1 -0
- package/dist/schema/EventDef/define.js +139 -0
- package/dist/schema/EventDef/define.js.map +1 -0
- package/dist/schema/EventDef/event-def.d.ts +106 -0
- package/dist/schema/EventDef/event-def.d.ts.map +1 -0
- package/dist/schema/EventDef/event-def.js +2 -0
- package/dist/schema/EventDef/event-def.js.map +1 -0
- package/dist/schema/EventDef/facts.d.ts +118 -0
- package/dist/schema/EventDef/facts.d.ts.map +1 -0
- package/dist/schema/EventDef/facts.js +53 -0
- package/dist/schema/EventDef/facts.js.map +1 -0
- package/dist/schema/EventDef/materializer.d.ts +155 -0
- package/dist/schema/EventDef/materializer.d.ts.map +1 -0
- package/dist/schema/EventDef/materializer.js +83 -0
- package/dist/schema/EventDef/materializer.js.map +1 -0
- package/dist/schema/EventDef/mod.d.ts +5 -0
- package/dist/schema/EventDef/mod.d.ts.map +1 -0
- package/dist/schema/EventDef/mod.js +5 -0
- package/dist/schema/EventDef/mod.js.map +1 -0
- package/dist/schema/EventSequenceNumber/client.d.ts +136 -0
- package/dist/schema/EventSequenceNumber/client.d.ts.map +1 -0
- package/dist/schema/{EventSequenceNumber.js → EventSequenceNumber/client.js} +86 -39
- package/dist/schema/EventSequenceNumber/client.js.map +1 -0
- package/dist/schema/EventSequenceNumber/global.d.ts +15 -0
- package/dist/schema/EventSequenceNumber/global.d.ts.map +1 -0
- package/dist/schema/EventSequenceNumber/global.js +14 -0
- package/dist/schema/EventSequenceNumber/global.js.map +1 -0
- package/dist/schema/EventSequenceNumber/mod.d.ts +37 -0
- package/dist/schema/EventSequenceNumber/mod.d.ts.map +1 -0
- package/dist/schema/EventSequenceNumber/mod.js +37 -0
- package/dist/schema/EventSequenceNumber/mod.js.map +1 -0
- package/dist/schema/EventSequenceNumber.test.js +41 -41
- package/dist/schema/EventSequenceNumber.test.js.map +1 -1
- package/dist/schema/{LiveStoreEvent.d.ts → LiveStoreEvent/client.d.ts} +84 -101
- package/dist/schema/LiveStoreEvent/client.d.ts.map +1 -0
- package/dist/schema/{LiveStoreEvent.js → LiveStoreEvent/client.js} +69 -52
- package/dist/schema/LiveStoreEvent/client.js.map +1 -0
- package/dist/schema/LiveStoreEvent/for-event-def.d.ts +52 -0
- package/dist/schema/LiveStoreEvent/for-event-def.d.ts.map +1 -0
- package/dist/schema/LiveStoreEvent/for-event-def.js +2 -0
- package/dist/schema/LiveStoreEvent/for-event-def.js.map +1 -0
- package/dist/schema/LiveStoreEvent/global.d.ts +36 -0
- package/dist/schema/LiveStoreEvent/global.d.ts.map +1 -0
- package/dist/schema/LiveStoreEvent/global.js +31 -0
- package/dist/schema/LiveStoreEvent/global.js.map +1 -0
- package/dist/schema/LiveStoreEvent/input.d.ts +46 -0
- package/dist/schema/LiveStoreEvent/input.d.ts.map +1 -0
- package/dist/schema/LiveStoreEvent/input.js +26 -0
- package/dist/schema/LiveStoreEvent/input.js.map +1 -0
- package/dist/schema/LiveStoreEvent/mod.d.ts +5 -0
- package/dist/schema/LiveStoreEvent/mod.d.ts.map +1 -0
- package/dist/schema/LiveStoreEvent/mod.js +5 -0
- package/dist/schema/LiveStoreEvent/mod.js.map +1 -0
- package/dist/schema/events.d.ts +1 -1
- package/dist/schema/events.d.ts.map +1 -1
- package/dist/schema/events.js +1 -1
- package/dist/schema/events.js.map +1 -1
- package/dist/schema/mod.d.ts +3 -3
- package/dist/schema/mod.d.ts.map +1 -1
- package/dist/schema/mod.js +3 -3
- package/dist/schema/mod.js.map +1 -1
- package/dist/schema/schema.d.ts +1 -1
- package/dist/schema/schema.d.ts.map +1 -1
- package/dist/schema/state/sqlite/client-document-def.d.ts +1 -1
- package/dist/schema/state/sqlite/client-document-def.d.ts.map +1 -1
- package/dist/schema/state/sqlite/client-document-def.js +2 -2
- package/dist/schema/state/sqlite/client-document-def.js.map +1 -1
- package/dist/schema/state/sqlite/client-document-def.test.js.map +1 -1
- package/dist/schema/state/sqlite/column-def.js +60 -28
- package/dist/schema/state/sqlite/column-def.js.map +1 -1
- package/dist/schema/state/sqlite/column-def.test.js +12 -1
- package/dist/schema/state/sqlite/column-def.test.js.map +1 -1
- package/dist/schema/state/sqlite/mod.d.ts +2 -2
- 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 +12 -8
- package/dist/schema/state/sqlite/query-builder/api.d.ts.map +1 -1
- package/dist/schema/state/sqlite/query-builder/astToSql.d.ts.map +1 -1
- package/dist/schema/state/sqlite/query-builder/astToSql.js +18 -11
- package/dist/schema/state/sqlite/query-builder/astToSql.js.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 +0 -1
- package/dist/schema/state/sqlite/query-builder/impl.js.map +1 -1
- package/dist/schema/state/sqlite/query-builder/impl.test.js +119 -90
- package/dist/schema/state/sqlite/query-builder/impl.test.js.map +1 -1
- package/dist/schema/state/sqlite/system-tables/eventlog-tables.js +5 -5
- package/dist/schema/state/sqlite/system-tables/eventlog-tables.js.map +1 -1
- package/dist/schema/state/sqlite/system-tables/state-tables.js +3 -3
- package/dist/schema/state/sqlite/system-tables/state-tables.js.map +1 -1
- package/dist/schema/unknown-events.d.ts +3 -3
- package/dist/schema/unknown-events.d.ts.map +1 -1
- package/dist/schema-management/migrations.d.ts +2 -2
- package/dist/schema-management/migrations.d.ts.map +1 -1
- package/dist/schema-management/migrations.js.map +1 -1
- package/dist/schema-management/validate-schema.d.ts +3 -3
- package/dist/schema-management/validate-schema.d.ts.map +1 -1
- package/dist/schema-management/validate-schema.js +2 -2
- package/dist/schema-management/validate-schema.js.map +1 -1
- package/dist/sqlite-types.d.ts +3 -3
- package/dist/sqlite-types.d.ts.map +1 -1
- package/dist/sync/ClientSessionSyncProcessor.d.ts +5 -5
- package/dist/sync/ClientSessionSyncProcessor.d.ts.map +1 -1
- package/dist/sync/ClientSessionSyncProcessor.js +12 -12
- package/dist/sync/ClientSessionSyncProcessor.js.map +1 -1
- package/dist/sync/errors.d.ts +9 -4
- package/dist/sync/errors.d.ts.map +1 -1
- package/dist/sync/errors.js +6 -6
- package/dist/sync/errors.js.map +1 -1
- package/dist/sync/mock-sync-backend.d.ts +6 -6
- package/dist/sync/mock-sync-backend.d.ts.map +1 -1
- package/dist/sync/mock-sync-backend.js +4 -4
- package/dist/sync/mock-sync-backend.js.map +1 -1
- package/dist/sync/next/compact-events.js +2 -2
- package/dist/sync/next/compact-events.js.map +1 -1
- package/dist/sync/next/facts.d.ts +5 -5
- package/dist/sync/next/facts.d.ts.map +1 -1
- package/dist/sync/next/facts.js.map +1 -1
- package/dist/sync/next/history-dag-common.d.ts +5 -5
- package/dist/sync/next/history-dag-common.d.ts.map +1 -1
- package/dist/sync/next/history-dag-common.js +5 -5
- 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 +8 -8
- package/dist/sync/next/history-dag.js.map +1 -1
- package/dist/sync/next/rebase-events.d.ts +5 -5
- package/dist/sync/next/rebase-events.d.ts.map +1 -1
- package/dist/sync/next/rebase-events.js +5 -5
- package/dist/sync/next/rebase-events.js.map +1 -1
- package/dist/sync/next/test/event-fixtures.d.ts +2 -2
- package/dist/sync/next/test/event-fixtures.d.ts.map +1 -1
- package/dist/sync/next/test/event-fixtures.js +9 -9
- package/dist/sync/next/test/event-fixtures.js.map +1 -1
- package/dist/sync/sync-backend-kv.d.ts +3 -3
- package/dist/sync/sync-backend-kv.d.ts.map +1 -1
- package/dist/sync/sync-backend-kv.js +3 -3
- package/dist/sync/sync-backend-kv.js.map +1 -1
- package/dist/sync/sync-backend.d.ts +9 -9
- package/dist/sync/sync-backend.d.ts.map +1 -1
- package/dist/sync/syncstate.d.ts +55 -42
- package/dist/sync/syncstate.d.ts.map +1 -1
- package/dist/sync/syncstate.js +42 -42
- package/dist/sync/syncstate.js.map +1 -1
- package/dist/sync/syncstate.test.js +40 -40
- package/dist/sync/syncstate.test.js.map +1 -1
- 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 +2 -2
- package/dist/sync/validate-push-payload.js.map +1 -1
- package/dist/testing/event-factory.d.ts +3 -3
- package/dist/testing/event-factory.d.ts.map +1 -1
- package/dist/testing/event-factory.js +5 -7
- package/dist/testing/event-factory.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +4 -4
- package/src/ClientSessionLeaderThreadProxy.ts +10 -10
- package/src/adapter-types.ts +5 -5
- package/src/devtools/devtools-messages-client-session.ts +2 -2
- package/src/devtools/devtools-messages-leader.ts +8 -8
- package/src/errors.ts +11 -13
- package/src/leader-thread/LeaderSyncProcessor.ts +54 -56
- package/src/leader-thread/eventlog.ts +21 -26
- package/src/leader-thread/leader-worker-devtools.ts +3 -3
- package/src/leader-thread/make-leader-thread-layer.ts +12 -10
- package/src/leader-thread/materialize-event.ts +3 -3
- package/src/leader-thread/recreate-db.ts +6 -6
- package/src/leader-thread/shutdown-channel.ts +2 -2
- package/src/leader-thread/types.ts +15 -15
- package/src/make-client-session.ts +2 -2
- package/src/materializer-helper.ts +5 -5
- package/src/rematerialize-from-eventlog.ts +6 -6
- package/src/schema/EventDef/define.ts +201 -0
- package/src/schema/EventDef/event-def.ts +120 -0
- package/src/schema/EventDef/facts.ts +135 -0
- package/src/schema/EventDef/materializer.ts +172 -0
- package/src/schema/EventDef/mod.ts +4 -0
- package/src/schema/EventSequenceNumber/client.ts +257 -0
- package/src/schema/EventSequenceNumber/global.ts +19 -0
- package/src/schema/EventSequenceNumber/mod.ts +37 -0
- package/src/schema/EventSequenceNumber.test.ts +68 -50
- package/src/schema/LiveStoreEvent/client.ts +221 -0
- package/src/schema/LiveStoreEvent/for-event-def.ts +60 -0
- package/src/schema/LiveStoreEvent/global.ts +45 -0
- package/src/schema/LiveStoreEvent/input.ts +63 -0
- package/src/schema/LiveStoreEvent/mod.ts +4 -0
- package/src/schema/events.ts +1 -1
- package/src/schema/mod.ts +3 -3
- package/src/schema/schema.ts +1 -1
- package/src/schema/state/sqlite/client-document-def.test.ts +2 -2
- package/src/schema/state/sqlite/client-document-def.ts +3 -3
- package/src/schema/state/sqlite/column-def.test.ts +18 -1
- package/src/schema/state/sqlite/column-def.ts +73 -30
- package/src/schema/state/sqlite/mod.ts +2 -2
- package/src/schema/state/sqlite/query-builder/api.ts +12 -8
- package/src/schema/state/sqlite/query-builder/astToSql.ts +20 -11
- package/src/schema/state/sqlite/query-builder/impl.test.ts +122 -90
- package/src/schema/state/sqlite/query-builder/impl.ts +0 -1
- package/src/schema/state/sqlite/system-tables/eventlog-tables.ts +5 -5
- package/src/schema/state/sqlite/system-tables/state-tables.ts +3 -3
- package/src/schema/unknown-events.ts +3 -3
- package/src/schema-management/migrations.ts +2 -2
- package/src/schema-management/validate-schema.ts +3 -3
- package/src/sqlite-types.ts +3 -3
- package/src/sync/ClientSessionSyncProcessor.ts +17 -17
- package/src/sync/errors.ts +6 -6
- package/src/sync/mock-sync-backend.ts +16 -16
- package/src/sync/next/compact-events.ts +2 -2
- package/src/sync/next/facts.ts +6 -6
- package/src/sync/next/history-dag-common.ts +8 -8
- package/src/sync/next/history-dag.ts +14 -10
- package/src/sync/next/rebase-events.ts +11 -11
- package/src/sync/next/test/event-fixtures.ts +11 -11
- package/src/sync/sync-backend-kv.ts +3 -3
- package/src/sync/sync-backend.ts +9 -9
- package/src/sync/syncstate.test.ts +46 -46
- package/src/sync/syncstate.ts +59 -55
- package/src/sync/validate-push-payload.ts +4 -4
- package/src/testing/event-factory.ts +10 -12
- package/src/version.ts +1 -1
- package/dist/schema/EventDef.d.ts +0 -126
- package/dist/schema/EventDef.d.ts.map +0 -1
- package/dist/schema/EventDef.js +0 -46
- package/dist/schema/EventDef.js.map +0 -1
- package/dist/schema/EventSequenceNumber.d.ts +0 -89
- package/dist/schema/EventSequenceNumber.d.ts.map +0 -1
- package/dist/schema/EventSequenceNumber.js.map +0 -1
- package/dist/schema/LiveStoreEvent.d.ts.map +0 -1
- package/dist/schema/LiveStoreEvent.js.map +0 -1
- package/src/schema/EventDef.ts +0 -222
- package/src/schema/EventSequenceNumber.ts +0 -208
- package/src/schema/LiveStoreEvent.ts +0 -286
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Materializer System
|
|
3
|
+
*
|
|
4
|
+
* Materializers transform events into SQL mutations (INSERT, UPDATE, DELETE).
|
|
5
|
+
* Every non-derived event must have a corresponding materializer that defines
|
|
6
|
+
* how it affects the SQLite database state.
|
|
7
|
+
*
|
|
8
|
+
* Materializers are pure functions that receive the event arguments and return
|
|
9
|
+
* SQL operations. They can also query current state when needed for complex
|
|
10
|
+
* transformations.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { State } from '@livestore/livestore'
|
|
15
|
+
*
|
|
16
|
+
* const materializers = State.SQLite.materializers(events, {
|
|
17
|
+
* 'v1.TodoCreated': ({ id, text }) =>
|
|
18
|
+
* tables.todos.insert({ id, text, completed: false }),
|
|
19
|
+
*
|
|
20
|
+
* 'v1.TodoCompleted': ({ id }) =>
|
|
21
|
+
* tables.todos.update({ completed: true }).where({ id }),
|
|
22
|
+
*
|
|
23
|
+
* 'v1.TodoDeleted': ({ id, deletedAt }) =>
|
|
24
|
+
* tables.todos.update({ deletedAt }).where({ id }),
|
|
25
|
+
* })
|
|
26
|
+
* ```
|
|
27
|
+
* @module
|
|
28
|
+
*/
|
|
29
|
+
/**
|
|
30
|
+
* Type-safe wrapper for defining a single materializer.
|
|
31
|
+
*
|
|
32
|
+
* Useful when defining materializers separately from the `materializers()` builder.
|
|
33
|
+
* The first argument provides type inference for the second.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* const todoCreatedHandler = defineMaterializer(
|
|
38
|
+
* events.todoCreated,
|
|
39
|
+
* ({ id, text }) => tables.todos.insert({ id, text, completed: false })
|
|
40
|
+
* )
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export const defineMaterializer = (_eventDef, materializer) => {
|
|
44
|
+
return materializer;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Builder function for creating a type-safe materializer map.
|
|
48
|
+
*
|
|
49
|
+
* This is the primary way to define materializers in LiveStore. It ensures:
|
|
50
|
+
* - Every non-derived event has a corresponding materializer
|
|
51
|
+
* - Materializer argument types match their event schemas
|
|
52
|
+
* - Derived events are excluded from the required handlers
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* import { State } from '@livestore/livestore'
|
|
57
|
+
*
|
|
58
|
+
* const handlers = State.SQLite.materializers(events, {
|
|
59
|
+
* // Handler for each event - argument types are inferred
|
|
60
|
+
* 'v1.TodoCreated': ({ id, text, completed }) =>
|
|
61
|
+
* tables.todos.insert({ id, text, completed }),
|
|
62
|
+
*
|
|
63
|
+
* 'v1.TodoUpdated': ({ id, text }) =>
|
|
64
|
+
* tables.todos.update({ text }).where({ id }),
|
|
65
|
+
*
|
|
66
|
+
* // Can return multiple operations
|
|
67
|
+
* 'v1.UserCreatedWithDefaults': ({ userId, name }) => [
|
|
68
|
+
* tables.users.insert({ id: userId, name }),
|
|
69
|
+
* tables.settings.insert({ userId, theme: 'light' }),
|
|
70
|
+
* ],
|
|
71
|
+
*
|
|
72
|
+
* // Can query current state
|
|
73
|
+
* 'v1.TodoToggled': ({ id }, { query }) => {
|
|
74
|
+
* const todo = query(tables.todos.select().where({ id }).first())
|
|
75
|
+
* return tables.todos.update({ completed: !todo?.completed }).where({ id })
|
|
76
|
+
* },
|
|
77
|
+
* })
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
export const materializers = (_eventDefRecord, handlers) => {
|
|
81
|
+
return handlers;
|
|
82
|
+
};
|
|
83
|
+
//# sourceMappingURL=materializer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"materializer.js","sourceRoot":"","sources":["../../../src/schema/EventDef/materializer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AA6EH;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,SAAoB,EACpB,YAAqC,EACZ,EAAE;IAC3B,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,eAA6B,EAC7B,QAOC,EACD,EAAE;IACF,OAAO,QAAQ,CAAA;AACjB,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/schema/EventDef/mod.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,YAAY,CAAA;AAC1B,cAAc,mBAAmB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../../../src/schema/EventDef/mod.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,YAAY,CAAA;AAC1B,cAAc,mBAAmB,CAAA"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { Brand, Schema as S } from '@livestore/utils/effect';
|
|
2
|
+
import { type Type as Global } from './global.ts';
|
|
3
|
+
/** Branded integer type for client-local sequence numbers. */
|
|
4
|
+
export type Type = Brand.Branded<number, 'ClientEventSequenceNumber'>;
|
|
5
|
+
/** Effect Schema for encoding/decoding client sequence numbers. */
|
|
6
|
+
export declare const Schema: S.BrandSchema<number & Brand.Brand<"ClientEventSequenceNumber">, number, never>;
|
|
7
|
+
/**
|
|
8
|
+
* Creates a branded client sequence number from a plain number.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const clientSeq = EventSequenceNumber.Client.make(1)
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare const make: Brand.Brand.Constructor<Type>;
|
|
16
|
+
/**
|
|
17
|
+
* Default client sequence number (0). Used for confirmed/synced events.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* const defaultSeq = EventSequenceNumber.Client.DEFAULT // 0
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare const DEFAULT: Type;
|
|
25
|
+
/** Default rebase generation (0). Increments each time the client rebases unconfirmed events. */
|
|
26
|
+
export declare const REBASE_GENERATION_DEFAULT = 0;
|
|
27
|
+
/**
|
|
28
|
+
* Composite event sequence number consisting of global + client + rebaseGeneration.
|
|
29
|
+
* Used for client-side event tracking with support for unconfirmed local events.
|
|
30
|
+
*
|
|
31
|
+
* For event notation documentation, see: contributor-docs/events-notation.md
|
|
32
|
+
*/
|
|
33
|
+
export type Composite = {
|
|
34
|
+
global: Global;
|
|
35
|
+
client: Type;
|
|
36
|
+
/**
|
|
37
|
+
* Generation integer that is incremented whenever the client rebased.
|
|
38
|
+
* Remains constant for all subsequent events until another rebase occurs.
|
|
39
|
+
*/
|
|
40
|
+
rebaseGeneration: number;
|
|
41
|
+
};
|
|
42
|
+
/** Input type for creating a Composite sequence number. Allows omitting rebaseGeneration (defaults to 0). */
|
|
43
|
+
export type CompositeInput = Composite | (Omit<typeof CompositeSchema.Encoded, 'rebaseGeneration'> & {
|
|
44
|
+
rebaseGeneration?: number;
|
|
45
|
+
});
|
|
46
|
+
/** A pair of sequence numbers representing an event and its parent. */
|
|
47
|
+
export type CompositePair = {
|
|
48
|
+
seqNum: Composite;
|
|
49
|
+
parentSeqNum: Composite;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Compare two composite sequence numbers.
|
|
53
|
+
* Comparison hierarchy: global > client > rebaseGeneration
|
|
54
|
+
*/
|
|
55
|
+
export declare const compare: (a: Composite, b: Composite) => number;
|
|
56
|
+
/**
|
|
57
|
+
* Convert a composite sequence number to a string representation.
|
|
58
|
+
*
|
|
59
|
+
* For notation documentation, see: contributor-docs/events-notation.md
|
|
60
|
+
*/
|
|
61
|
+
export declare const toString: (seqNum: Composite) => string;
|
|
62
|
+
/**
|
|
63
|
+
* Convert a string representation of a sequence number to a Composite.
|
|
64
|
+
* Parses strings in the format: e{global}[.{client}][r{rebaseGeneration}]
|
|
65
|
+
* Examples: "e0", "e0r1", "e0.1", "e0.1r1"
|
|
66
|
+
*
|
|
67
|
+
* For full notation documentation, see: contributor-docs/events-notation.md
|
|
68
|
+
*/
|
|
69
|
+
export declare const fromString: (str: string) => Composite;
|
|
70
|
+
/** Creates a Composite sequence number from a global sequence number (client=0, rebaseGeneration=0). */
|
|
71
|
+
export declare const fromGlobal: (seqNum: Global) => Composite;
|
|
72
|
+
/** Returns true if two Composite sequence numbers are structurally equal. */
|
|
73
|
+
export declare const isEqual: (a: Composite, b: Composite) => boolean;
|
|
74
|
+
/** Returns true if `a` is strictly greater than `b` (compares global, then client). */
|
|
75
|
+
export declare const isGreaterThan: (a: Composite, b: Composite) => boolean;
|
|
76
|
+
/** Returns true if `a` is greater than or equal to `b` (compares global, then client). */
|
|
77
|
+
export declare const isGreaterThanOrEqual: (a: Composite, b: Composite) => boolean;
|
|
78
|
+
/** Returns the larger of two Composite sequence numbers. */
|
|
79
|
+
export declare const max: (a: Composite, b: Composite) => Composite;
|
|
80
|
+
/** Returns the difference between two Composite sequence numbers (a - b) for global and client components. */
|
|
81
|
+
export declare const diff: (a: Composite, b: Composite) => {
|
|
82
|
+
global: number;
|
|
83
|
+
client: number;
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Schema for the composite event sequence number.
|
|
87
|
+
* NOTE: Client mutation events with a non-0 client id won't be synced to the sync backend.
|
|
88
|
+
*/
|
|
89
|
+
declare const CompositeSchema: S.Struct<{
|
|
90
|
+
global: S.BrandSchema<number & Brand.Brand<"GlobalEventSequenceNumber">, number, never>;
|
|
91
|
+
/** Only increments for client-local events */
|
|
92
|
+
client: S.BrandSchema<number & Brand.Brand<"ClientEventSequenceNumber">, number, never>;
|
|
93
|
+
rebaseGeneration: typeof S.Int;
|
|
94
|
+
}>;
|
|
95
|
+
/**
|
|
96
|
+
* Effect Schema for the composite event sequence number (global + client + rebaseGeneration).
|
|
97
|
+
* Also includes a `make` helper for creating validated Composite values.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```ts
|
|
101
|
+
* const seqNum: EventSequenceNumber.Client.Composite = {
|
|
102
|
+
* global: EventSequenceNumber.Global.make(5),
|
|
103
|
+
* client: EventSequenceNumber.Client.DEFAULT,
|
|
104
|
+
* rebaseGeneration: 0
|
|
105
|
+
* }
|
|
106
|
+
*
|
|
107
|
+
* const validated = EventSequenceNumber.Client.Composite.make({ global: 5, client: 0, rebaseGeneration: 0 })
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
export declare const Composite: S.Struct<{
|
|
111
|
+
global: S.BrandSchema<number & Brand.Brand<"GlobalEventSequenceNumber">, number, never>;
|
|
112
|
+
/** Only increments for client-local events */
|
|
113
|
+
client: S.BrandSchema<number & Brand.Brand<"ClientEventSequenceNumber">, number, never>;
|
|
114
|
+
rebaseGeneration: typeof S.Int;
|
|
115
|
+
}> & {
|
|
116
|
+
make: (seqNum: CompositeInput) => Composite;
|
|
117
|
+
};
|
|
118
|
+
/** The root sequence number (global=0, client=0, rebaseGeneration=0). Parent of the first event. */
|
|
119
|
+
export declare const ROOT: {
|
|
120
|
+
global: Global;
|
|
121
|
+
client: Type;
|
|
122
|
+
rebaseGeneration: number;
|
|
123
|
+
};
|
|
124
|
+
/**
|
|
125
|
+
* Computes the next sequence number and its parent based on the current position.
|
|
126
|
+
*
|
|
127
|
+
* For client-local events (isClient=true): increments the client component, keeps global.
|
|
128
|
+
* For global events (isClient=false): increments global, resets client to 0.
|
|
129
|
+
*/
|
|
130
|
+
export declare const nextPair: ({ seqNum, isClient, rebaseGeneration, }: {
|
|
131
|
+
seqNum: Composite;
|
|
132
|
+
isClient: boolean;
|
|
133
|
+
rebaseGeneration?: number;
|
|
134
|
+
}) => CompositePair;
|
|
135
|
+
export {};
|
|
136
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/schema/EventSequenceNumber/client.ts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AQ,MAAM,KAAG,SAI1C,CAAA;AAEF,6EAA6E;AAC7E,eAAO,MAAM,OAAO,GAAI,GAAG,SAAS,EAAE,GAAG,SAAS,YAC2C,CAAA;AAE7F,uFAAuF;AACvF,eAAO,MAAM,aAAa,GAAI,GAAG,SAAS,EAAE,GAAG,SAAS,YAEvD,CAAA;AAED,0FAA0F;AAC1F,eAAO,MAAM,oBAAoB,GAAI,GAAG,SAAS,EAAE,GAAG,SAAS,YAE9D,CAAA;AAED,4DAA4D;AAC5D,eAAO,MAAM,GAAG,GAAI,GAAG,SAAS,EAAE,GAAG,SAAS,cAE7C,CAAA;AAED,8GAA8G;AAC9G,eAAO,MAAM,IAAI,GAAI,GAAG,SAAS,EAAE,GAAG,SAAS;;;CAK9C,CAAA;AAED;;;GAGG;AACH,QAAA,MAAM,eAAe;;IAEnB,8CAA8C;;;EAO9C,CAAA;AAeF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,SAAS;;IArCpB,8CAA8C;;;;mBAajB,cAAc,KAAG,SAAS;CAwBuB,CAAA;AAEhF,oGAAoG;AACpG,eAAO,MAAM,IAAI;;;;CAII,CAAA;AAErB;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,GAAI,yCAItB;IACD,MAAM,EAAE,SAAS,CAAA;IACjB,QAAQ,EAAE,OAAO,CAAA;IACjB,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAC1B,KAAG,aAqBH,CAAA"}
|
|
@@ -1,27 +1,30 @@
|
|
|
1
|
-
import { Brand, Schema } from '@livestore/utils/effect';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export const
|
|
6
|
-
export const clientDefault = 0;
|
|
7
|
-
export const rebaseGenerationDefault = 0;
|
|
8
|
-
// TODO adjust name to `ClientEventSequenceNumber`
|
|
1
|
+
import { Brand, Schema as S } from '@livestore/utils/effect';
|
|
2
|
+
import { Schema as GlobalSchema, make as makeGlobal } from "./global.js";
|
|
3
|
+
const ClientBrand = Brand.nominal();
|
|
4
|
+
/** Effect Schema for encoding/decoding client sequence numbers. */
|
|
5
|
+
export const Schema = S.fromBrand(ClientBrand)(S.Int);
|
|
9
6
|
/**
|
|
10
|
-
*
|
|
7
|
+
* Creates a branded client sequence number from a plain number.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const clientSeq = EventSequenceNumber.Client.make(1)
|
|
12
|
+
* ```
|
|
11
13
|
*/
|
|
12
|
-
export const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
14
|
+
export const make = ClientBrand;
|
|
15
|
+
/**
|
|
16
|
+
* Default client sequence number (0). Used for confirmed/synced events.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const defaultSeq = EventSequenceNumber.Client.DEFAULT // 0
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export const DEFAULT = 0;
|
|
24
|
+
/** Default rebase generation (0). Increments each time the client rebases unconfirmed events. */
|
|
25
|
+
export const REBASE_GENERATION_DEFAULT = 0;
|
|
23
26
|
/**
|
|
24
|
-
* Compare two
|
|
27
|
+
* Compare two composite sequence numbers.
|
|
25
28
|
* Comparison hierarchy: global > client > rebaseGeneration
|
|
26
29
|
*/
|
|
27
30
|
export const compare = (a, b) => {
|
|
@@ -34,7 +37,7 @@ export const compare = (a, b) => {
|
|
|
34
37
|
return a.rebaseGeneration - b.rebaseGeneration;
|
|
35
38
|
};
|
|
36
39
|
/**
|
|
37
|
-
* Convert
|
|
40
|
+
* Convert a composite sequence number to a string representation.
|
|
38
41
|
*
|
|
39
42
|
* For notation documentation, see: contributor-docs/events-notation.md
|
|
40
43
|
*/
|
|
@@ -45,7 +48,7 @@ export const toString = (seqNum) => {
|
|
|
45
48
|
: `e${seqNum.global}.${seqNum.client}${rebaseGenerationStr}`;
|
|
46
49
|
};
|
|
47
50
|
/**
|
|
48
|
-
* Convert a string representation of
|
|
51
|
+
* Convert a string representation of a sequence number to a Composite.
|
|
49
52
|
* Parses strings in the format: e{global}[.{client}][r{rebaseGeneration}]
|
|
50
53
|
* Examples: "e0", "e0r1", "e0.1", "e0.1r1"
|
|
51
54
|
*
|
|
@@ -58,7 +61,7 @@ export const fromString = (str) => {
|
|
|
58
61
|
// Remove the 'e' prefix
|
|
59
62
|
const remaining = str.slice(1);
|
|
60
63
|
// Parse rebase generation if present
|
|
61
|
-
let rebaseGeneration =
|
|
64
|
+
let rebaseGeneration = REBASE_GENERATION_DEFAULT;
|
|
62
65
|
let withoutRebase = remaining;
|
|
63
66
|
const rebaseMatch = remaining.match(/r(\d+)$/);
|
|
64
67
|
if (rebaseMatch !== null) {
|
|
@@ -85,42 +88,86 @@ export const fromString = (str) => {
|
|
|
85
88
|
rebaseGeneration,
|
|
86
89
|
};
|
|
87
90
|
};
|
|
91
|
+
/** Creates a Composite sequence number from a global sequence number (client=0, rebaseGeneration=0). */
|
|
88
92
|
export const fromGlobal = (seqNum) => ({
|
|
89
93
|
global: seqNum,
|
|
90
|
-
client:
|
|
91
|
-
rebaseGeneration:
|
|
94
|
+
client: DEFAULT,
|
|
95
|
+
rebaseGeneration: REBASE_GENERATION_DEFAULT,
|
|
92
96
|
});
|
|
97
|
+
/** Returns true if two Composite sequence numbers are structurally equal. */
|
|
93
98
|
export const isEqual = (a, b) => a.global === b.global && a.client === b.client && a.rebaseGeneration === b.rebaseGeneration;
|
|
94
|
-
|
|
95
|
-
global: 0,
|
|
96
|
-
client: clientDefault,
|
|
97
|
-
rebaseGeneration: rebaseGenerationDefault,
|
|
98
|
-
};
|
|
99
|
+
/** Returns true if `a` is strictly greater than `b` (compares global, then client). */
|
|
99
100
|
export const isGreaterThan = (a, b) => {
|
|
100
101
|
return a.global > b.global || (a.global === b.global && a.client > b.client);
|
|
101
102
|
};
|
|
103
|
+
/** Returns true if `a` is greater than or equal to `b` (compares global, then client). */
|
|
102
104
|
export const isGreaterThanOrEqual = (a, b) => {
|
|
103
105
|
return a.global > b.global || (a.global === b.global && a.client >= b.client);
|
|
104
106
|
};
|
|
107
|
+
/** Returns the larger of two Composite sequence numbers. */
|
|
105
108
|
export const max = (a, b) => {
|
|
106
109
|
return a.global > b.global || (a.global === b.global && a.client > b.client) ? a : b;
|
|
107
110
|
};
|
|
111
|
+
/** Returns the difference between two Composite sequence numbers (a - b) for global and client components. */
|
|
108
112
|
export const diff = (a, b) => {
|
|
109
113
|
return {
|
|
110
114
|
global: a.global - b.global,
|
|
111
115
|
client: a.client - b.client,
|
|
112
116
|
};
|
|
113
117
|
};
|
|
114
|
-
|
|
115
|
-
|
|
118
|
+
/**
|
|
119
|
+
* Schema for the composite event sequence number.
|
|
120
|
+
* NOTE: Client mutation events with a non-0 client id won't be synced to the sync backend.
|
|
121
|
+
*/
|
|
122
|
+
const CompositeSchema = S.Struct({
|
|
123
|
+
global: GlobalSchema,
|
|
124
|
+
/** Only increments for client-local events */
|
|
125
|
+
client: Schema,
|
|
126
|
+
// Client only
|
|
127
|
+
rebaseGeneration: S.Int,
|
|
128
|
+
}).annotations({
|
|
129
|
+
title: 'EventSequenceNumber.Composite',
|
|
130
|
+
pretty: () => (seqNum) => toString(seqNum),
|
|
131
|
+
});
|
|
132
|
+
/**
|
|
133
|
+
* Creates a validated Composite sequence number from input.
|
|
134
|
+
* If rebaseGeneration is omitted, defaults to REBASE_GENERATION_DEFAULT (0).
|
|
135
|
+
*/
|
|
136
|
+
const makeComposite = (seqNum) => {
|
|
137
|
+
return S.is(CompositeSchema)(seqNum)
|
|
116
138
|
? seqNum
|
|
117
|
-
:
|
|
139
|
+
: S.decodeSync(CompositeSchema)({
|
|
118
140
|
...seqNum,
|
|
119
|
-
rebaseGeneration: seqNum.rebaseGeneration ??
|
|
141
|
+
rebaseGeneration: seqNum.rebaseGeneration ?? REBASE_GENERATION_DEFAULT,
|
|
120
142
|
});
|
|
121
143
|
};
|
|
122
144
|
/**
|
|
123
|
-
*
|
|
145
|
+
* Effect Schema for the composite event sequence number (global + client + rebaseGeneration).
|
|
146
|
+
* Also includes a `make` helper for creating validated Composite values.
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```ts
|
|
150
|
+
* const seqNum: EventSequenceNumber.Client.Composite = {
|
|
151
|
+
* global: EventSequenceNumber.Global.make(5),
|
|
152
|
+
* client: EventSequenceNumber.Client.DEFAULT,
|
|
153
|
+
* rebaseGeneration: 0
|
|
154
|
+
* }
|
|
155
|
+
*
|
|
156
|
+
* const validated = EventSequenceNumber.Client.Composite.make({ global: 5, client: 0, rebaseGeneration: 0 })
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
export const Composite = Object.assign(CompositeSchema, { make: makeComposite });
|
|
160
|
+
/** The root sequence number (global=0, client=0, rebaseGeneration=0). Parent of the first event. */
|
|
161
|
+
export const ROOT = {
|
|
162
|
+
global: makeGlobal(0),
|
|
163
|
+
client: DEFAULT,
|
|
164
|
+
rebaseGeneration: REBASE_GENERATION_DEFAULT,
|
|
165
|
+
};
|
|
166
|
+
/**
|
|
167
|
+
* Computes the next sequence number and its parent based on the current position.
|
|
168
|
+
*
|
|
169
|
+
* For client-local events (isClient=true): increments the client component, keeps global.
|
|
170
|
+
* For global events (isClient=false): increments global, resets client to 0.
|
|
124
171
|
*/
|
|
125
172
|
export const nextPair = ({ seqNum, isClient, rebaseGeneration, }) => {
|
|
126
173
|
if (isClient) {
|
|
@@ -136,11 +183,11 @@ export const nextPair = ({ seqNum, isClient, rebaseGeneration, }) => {
|
|
|
136
183
|
return {
|
|
137
184
|
seqNum: {
|
|
138
185
|
global: (seqNum.global + 1),
|
|
139
|
-
client:
|
|
186
|
+
client: DEFAULT,
|
|
140
187
|
rebaseGeneration: rebaseGeneration ?? seqNum.rebaseGeneration,
|
|
141
188
|
},
|
|
142
189
|
// NOTE we always point to `client: 0` for non-client-local events
|
|
143
|
-
parentSeqNum: { global: seqNum.global, client:
|
|
190
|
+
parentSeqNum: { global: seqNum.global, client: DEFAULT, rebaseGeneration: seqNum.rebaseGeneration },
|
|
144
191
|
};
|
|
145
192
|
};
|
|
146
|
-
//# sourceMappingURL=
|
|
193
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/schema/EventSequenceNumber/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,IAAI,CAAC,EAAE,MAAM,yBAAyB,CAAA;AAE5D,OAAO,EAAuB,MAAM,IAAI,YAAY,EAAE,IAAI,IAAI,UAAU,EAAE,MAAM,aAAa,CAAA;AAK7F,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,EAAQ,CAAA;AAEzC,mEAAmE;AACnE,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;AAErD;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,WAAW,CAAA;AAE/B;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CAAgB,CAAA;AAEvC,iGAAiG;AACjG,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,CAAA;AA0B1C;;;GAGG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,CAAY,EAAE,CAAY,EAAE,EAAE;IACpD,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC;QAC1B,OAAO,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,CAAA;IAC5B,CAAC;IACD,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC;QAC1B,OAAO,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,CAAA;IAC5B,CAAC;IACD,OAAO,CAAC,CAAC,g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,QAAQ,GAAG,CAAC,EACvB,MAAM,EACN,QAAQ,EACR,gBAAgB,GAKjB,EAAiB,EAAE;IAClB,IAAI,QAAQ,EAAE,CAAC;QACb,OAAO;YACL,MAAM,EAAE;gBACN,MAAM,EAAE,MAAM,CAAC,MAAM;gBACrB,MAAM,EAAE,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAgB;gBAC1C,gBAAgB,EAAE,gBAAgB,IAAI,MAAM,CAAC,gBAAgB;aAC9D;YACD,YAAY,EAAE,MAAM;SACrB,CAAA;IACH,CAAC;IAED,OAAO;QACL,MAAM,EAAE;YACN,MAAM,EAAE,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAkB;YAC5C,MAAM,EAAE,OAAO;YACf,gBAAgB,EAAE,gBAAgB,IAAI,MAAM,CAAC,gBAAgB;SAC9D;QACD,kEAAkE;QAClE,YAAY,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,CAAC,gBAAgB,EAAE;KACpG,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Brand, Schema as S } from '@livestore/utils/effect';
|
|
2
|
+
/** Branded integer type for global sequence numbers assigned by the sync backend. */
|
|
3
|
+
export type Type = Brand.Branded<number, 'GlobalEventSequenceNumber'>;
|
|
4
|
+
/** Effect Schema for encoding/decoding global sequence numbers. */
|
|
5
|
+
export declare const Schema: S.BrandSchema<number & Brand.Brand<"GlobalEventSequenceNumber">, number, never>;
|
|
6
|
+
/**
|
|
7
|
+
* Creates a branded global sequence number from a plain number.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const seqNum = EventSequenceNumber.Global.make(5)
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export declare const make: Brand.Brand.Constructor<Type>;
|
|
15
|
+
//# sourceMappingURL=global.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global.d.ts","sourceRoot":"","sources":["../../../src/schema/EventSequenceNumber/global.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,IAAI,CAAC,EAAE,MAAM,yBAAyB,CAAA;AAE5D,qFAAqF;AACrF,MAAM,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,2BAA2B,CAAC,CAAA;AAIrE,mEAAmE;AACnE,eAAO,MAAM,MAAM,iFAAkC,CAAA;AAErD;;;;;;;GAOG;AACH,eAAO,MAAM,IAAI,+BAAc,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Brand, Schema as S } from '@livestore/utils/effect';
|
|
2
|
+
const GlobalBrand = Brand.nominal();
|
|
3
|
+
/** Effect Schema for encoding/decoding global sequence numbers. */
|
|
4
|
+
export const Schema = S.fromBrand(GlobalBrand)(S.Int);
|
|
5
|
+
/**
|
|
6
|
+
* Creates a branded global sequence number from a plain number.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* const seqNum = EventSequenceNumber.Global.make(5)
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export const make = GlobalBrand;
|
|
14
|
+
//# sourceMappingURL=global.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global.js","sourceRoot":"","sources":["../../../src/schema/EventSequenceNumber/global.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,IAAI,CAAC,EAAE,MAAM,yBAAyB,CAAA;AAK5D,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,EAAQ,CAAA;AAEzC,mEAAmE;AACnE,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;AAErD;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,WAAW,CAAA"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client sequence numbers track events created locally before sync confirmation.
|
|
3
|
+
* Also contains the Composite type combining global and client sequence numbers with a rebase
|
|
4
|
+
* generation to fully identify an event's position in the eventlog.
|
|
5
|
+
*
|
|
6
|
+
* For event notation documentation, see: contributor-docs/events-notation.md
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { EventSequenceNumber } from '@livestore/common'
|
|
11
|
+
*
|
|
12
|
+
* // Client sequence number
|
|
13
|
+
* const clientSeq = EventSequenceNumber.Client.make(1)
|
|
14
|
+
*
|
|
15
|
+
* // Composite sequence number
|
|
16
|
+
* const composite: EventSequenceNumber.Client.Composite = {
|
|
17
|
+
* global: EventSequenceNumber.Global.make(5),
|
|
18
|
+
* client: EventSequenceNumber.Client.DEFAULT,
|
|
19
|
+
* rebaseGeneration: 0,
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export * as Client from './client.ts';
|
|
24
|
+
/**
|
|
25
|
+
* Global sequence numbers are assigned by the sync backend and represent
|
|
26
|
+
* the canonical ordering of events across all clients. They are monotonically
|
|
27
|
+
* increasing integers that establish the authoritative event timeline.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* import { EventSequenceNumber } from '@livestore/common'
|
|
32
|
+
*
|
|
33
|
+
* const globalSeq = EventSequenceNumber.Global.make(5)
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export * as Global from './global.ts';
|
|
37
|
+
//# sourceMappingURL=mod.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/schema/EventSequenceNumber/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAErC;;;;;;;;;;;GAWG;AACH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client sequence numbers track events created locally before sync confirmation.
|
|
3
|
+
* Also contains the Composite type combining global and client sequence numbers with a rebase
|
|
4
|
+
* generation to fully identify an event's position in the eventlog.
|
|
5
|
+
*
|
|
6
|
+
* For event notation documentation, see: contributor-docs/events-notation.md
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { EventSequenceNumber } from '@livestore/common'
|
|
11
|
+
*
|
|
12
|
+
* // Client sequence number
|
|
13
|
+
* const clientSeq = EventSequenceNumber.Client.make(1)
|
|
14
|
+
*
|
|
15
|
+
* // Composite sequence number
|
|
16
|
+
* const composite: EventSequenceNumber.Client.Composite = {
|
|
17
|
+
* global: EventSequenceNumber.Global.make(5),
|
|
18
|
+
* client: EventSequenceNumber.Client.DEFAULT,
|
|
19
|
+
* rebaseGeneration: 0,
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export * as Client from "./client.js";
|
|
24
|
+
/**
|
|
25
|
+
* Global sequence numbers are assigned by the sync backend and represent
|
|
26
|
+
* the canonical ordering of events across all clients. They are monotonically
|
|
27
|
+
* increasing integers that establish the authoritative event timeline.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* import { EventSequenceNumber } from '@livestore/common'
|
|
32
|
+
*
|
|
33
|
+
* const globalSeq = EventSequenceNumber.Global.make(5)
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export * as Global from "./global.js";
|
|
37
|
+
//# sourceMappingURL=mod.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../../../src/schema/EventSequenceNumber/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAErC;;;;;;;;;;;GAWG;AACH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA"}
|