@livestore/common 0.3.0-dev.27 → 0.3.0-dev.29
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/__tests__/fixture.d.ts +83 -221
- package/dist/__tests__/fixture.d.ts.map +1 -1
- package/dist/__tests__/fixture.js +33 -11
- package/dist/__tests__/fixture.js.map +1 -1
- package/dist/adapter-types.d.ts +22 -15
- package/dist/adapter-types.d.ts.map +1 -1
- package/dist/adapter-types.js +15 -2
- package/dist/adapter-types.js.map +1 -1
- package/dist/bounded-collections.d.ts +1 -1
- package/dist/bounded-collections.d.ts.map +1 -1
- package/dist/debug-info.d.ts.map +1 -1
- package/dist/debug-info.js +1 -0
- package/dist/debug-info.js.map +1 -1
- 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 +45 -45
- package/dist/devtools/devtools-messages-leader.d.ts.map +1 -1
- package/dist/devtools/devtools-messages-leader.js +11 -11
- package/dist/devtools/devtools-messages-leader.js.map +1 -1
- package/dist/index.d.ts +2 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -5
- package/dist/index.js.map +1 -1
- package/dist/leader-thread/LeaderSyncProcessor.d.ts +25 -12
- package/dist/leader-thread/LeaderSyncProcessor.d.ts.map +1 -1
- package/dist/leader-thread/LeaderSyncProcessor.js +125 -89
- package/dist/leader-thread/LeaderSyncProcessor.js.map +1 -1
- package/dist/leader-thread/{apply-mutation.d.ts → apply-event.d.ts} +7 -7
- package/dist/leader-thread/apply-event.d.ts.map +1 -0
- package/dist/leader-thread/apply-event.js +103 -0
- package/dist/leader-thread/apply-event.js.map +1 -0
- package/dist/leader-thread/eventlog.d.ts +27 -0
- package/dist/leader-thread/eventlog.d.ts.map +1 -0
- package/dist/leader-thread/eventlog.js +123 -0
- package/dist/leader-thread/eventlog.js.map +1 -0
- package/dist/leader-thread/leader-worker-devtools.js +18 -18
- package/dist/leader-thread/leader-worker-devtools.js.map +1 -1
- package/dist/leader-thread/make-leader-thread-layer.d.ts +16 -4
- package/dist/leader-thread/make-leader-thread-layer.d.ts.map +1 -1
- package/dist/leader-thread/make-leader-thread-layer.js +23 -16
- package/dist/leader-thread/make-leader-thread-layer.js.map +1 -1
- package/dist/leader-thread/mod.d.ts +1 -1
- package/dist/leader-thread/mod.d.ts.map +1 -1
- package/dist/leader-thread/mod.js +1 -1
- package/dist/leader-thread/mod.js.map +1 -1
- package/dist/leader-thread/recreate-db.d.ts.map +1 -1
- package/dist/leader-thread/recreate-db.js +6 -8
- package/dist/leader-thread/recreate-db.js.map +1 -1
- package/dist/leader-thread/types.d.ts +11 -11
- package/dist/leader-thread/types.d.ts.map +1 -1
- package/dist/materializer-helper.d.ts +23 -0
- package/dist/materializer-helper.d.ts.map +1 -0
- package/dist/materializer-helper.js +70 -0
- package/dist/materializer-helper.js.map +1 -0
- package/dist/query-builder/api.d.ts +58 -53
- package/dist/query-builder/api.d.ts.map +1 -1
- package/dist/query-builder/api.js +3 -5
- package/dist/query-builder/api.js.map +1 -1
- package/dist/query-builder/astToSql.d.ts.map +1 -1
- package/dist/query-builder/astToSql.js +59 -37
- package/dist/query-builder/astToSql.js.map +1 -1
- package/dist/query-builder/impl.d.ts +2 -3
- package/dist/query-builder/impl.d.ts.map +1 -1
- package/dist/query-builder/impl.js +48 -46
- package/dist/query-builder/impl.js.map +1 -1
- package/dist/query-builder/impl.test.d.ts +86 -1
- package/dist/query-builder/impl.test.d.ts.map +1 -1
- package/dist/query-builder/impl.test.js +244 -36
- package/dist/query-builder/impl.test.js.map +1 -1
- package/dist/rehydrate-from-eventlog.d.ts +14 -0
- package/dist/rehydrate-from-eventlog.d.ts.map +1 -0
- package/dist/{rehydrate-from-mutationlog.js → rehydrate-from-eventlog.js} +25 -26
- package/dist/rehydrate-from-eventlog.js.map +1 -0
- package/dist/schema/EventDef.d.ts +136 -0
- package/dist/schema/EventDef.d.ts.map +1 -0
- package/dist/schema/EventDef.js +58 -0
- package/dist/schema/EventDef.js.map +1 -0
- package/dist/schema/EventId.d.ts +2 -2
- package/dist/schema/EventId.d.ts.map +1 -1
- package/dist/schema/EventId.js +8 -2
- package/dist/schema/EventId.js.map +1 -1
- package/dist/schema/{MutationEvent.d.ts → LiveStoreEvent.d.ts} +56 -56
- package/dist/schema/LiveStoreEvent.d.ts.map +1 -0
- package/dist/schema/{MutationEvent.js → LiveStoreEvent.js} +25 -25
- package/dist/schema/LiveStoreEvent.js.map +1 -0
- package/dist/schema/client-document-def.d.ts +223 -0
- package/dist/schema/client-document-def.d.ts.map +1 -0
- package/dist/schema/client-document-def.js +170 -0
- package/dist/schema/client-document-def.js.map +1 -0
- package/dist/schema/client-document-def.test.d.ts +2 -0
- package/dist/schema/client-document-def.test.d.ts.map +1 -0
- package/dist/schema/client-document-def.test.js +201 -0
- package/dist/schema/client-document-def.test.js.map +1 -0
- package/dist/schema/db-schema/dsl/mod.d.ts.map +1 -1
- package/dist/schema/events.d.ts +2 -0
- package/dist/schema/events.d.ts.map +1 -0
- package/dist/schema/events.js +2 -0
- package/dist/schema/events.js.map +1 -0
- package/dist/schema/mod.d.ts +4 -3
- package/dist/schema/mod.d.ts.map +1 -1
- package/dist/schema/mod.js +4 -3
- package/dist/schema/mod.js.map +1 -1
- package/dist/schema/schema.d.ts +27 -23
- package/dist/schema/schema.d.ts.map +1 -1
- package/dist/schema/schema.js +45 -43
- package/dist/schema/schema.js.map +1 -1
- package/dist/schema/sqlite-state.d.ts +12 -0
- package/dist/schema/sqlite-state.d.ts.map +1 -0
- package/dist/schema/sqlite-state.js +36 -0
- package/dist/schema/sqlite-state.js.map +1 -0
- package/dist/schema/system-tables.d.ts +67 -98
- package/dist/schema/system-tables.d.ts.map +1 -1
- package/dist/schema/system-tables.js +62 -48
- package/dist/schema/system-tables.js.map +1 -1
- package/dist/schema/table-def.d.ts +26 -96
- package/dist/schema/table-def.d.ts.map +1 -1
- package/dist/schema/table-def.js +16 -64
- package/dist/schema/table-def.js.map +1 -1
- package/dist/schema/view.d.ts +3 -0
- package/dist/schema/view.d.ts.map +1 -0
- package/dist/schema/view.js +3 -0
- package/dist/schema/view.js.map +1 -0
- package/dist/schema-management/common.d.ts +4 -4
- package/dist/schema-management/common.d.ts.map +1 -1
- package/dist/schema-management/migrations.d.ts.map +1 -1
- package/dist/schema-management/migrations.js +6 -6
- package/dist/schema-management/migrations.js.map +1 -1
- package/dist/schema-management/validate-mutation-defs.d.ts +3 -3
- package/dist/schema-management/validate-mutation-defs.d.ts.map +1 -1
- package/dist/schema-management/validate-mutation-defs.js +17 -17
- package/dist/schema-management/validate-mutation-defs.js.map +1 -1
- package/dist/sync/ClientSessionSyncProcessor.d.ts +7 -7
- package/dist/sync/ClientSessionSyncProcessor.d.ts.map +1 -1
- package/dist/sync/ClientSessionSyncProcessor.js +31 -30
- package/dist/sync/ClientSessionSyncProcessor.js.map +1 -1
- package/dist/sync/next/facts.d.ts +19 -19
- package/dist/sync/next/facts.d.ts.map +1 -1
- package/dist/sync/next/facts.js +2 -2
- package/dist/sync/next/facts.js.map +1 -1
- package/dist/sync/next/history-dag-common.d.ts +3 -3
- package/dist/sync/next/history-dag-common.d.ts.map +1 -1
- package/dist/sync/next/history-dag-common.js +1 -1
- package/dist/sync/next/history-dag-common.js.map +1 -1
- package/dist/sync/next/history-dag.js +1 -1
- package/dist/sync/next/history-dag.js.map +1 -1
- package/dist/sync/next/rebase-events.d.ts +7 -7
- 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/compact-events.calculator.test.js +38 -33
- package/dist/sync/next/test/compact-events.calculator.test.js.map +1 -1
- package/dist/sync/next/test/compact-events.test.js +71 -71
- package/dist/sync/next/test/compact-events.test.js.map +1 -1
- package/dist/sync/next/test/{mutation-fixtures.d.ts → event-fixtures.d.ts} +29 -29
- package/dist/sync/next/test/event-fixtures.d.ts.map +1 -0
- package/dist/sync/next/test/{mutation-fixtures.js → event-fixtures.js} +60 -25
- package/dist/sync/next/test/event-fixtures.js.map +1 -0
- package/dist/sync/next/test/mod.d.ts +1 -1
- package/dist/sync/next/test/mod.d.ts.map +1 -1
- package/dist/sync/next/test/mod.js +1 -1
- package/dist/sync/next/test/mod.js.map +1 -1
- package/dist/sync/sync.d.ts +3 -3
- package/dist/sync/sync.d.ts.map +1 -1
- package/dist/sync/syncstate.d.ts +32 -32
- package/dist/sync/syncstate.d.ts.map +1 -1
- package/dist/sync/syncstate.js +31 -25
- package/dist/sync/syncstate.js.map +1 -1
- package/dist/sync/syncstate.test.js +165 -175
- package/dist/sync/syncstate.test.js.map +1 -1
- package/dist/sync/validate-push-payload.d.ts +2 -2
- package/dist/sync/validate-push-payload.d.ts.map +1 -1
- package/dist/sync/validate-push-payload.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +3 -3
- package/src/__tests__/fixture.ts +36 -15
- package/src/adapter-types.ts +23 -16
- package/src/debug-info.ts +1 -0
- package/src/devtools/devtools-messages-leader.ts +13 -13
- package/src/index.ts +2 -5
- package/src/leader-thread/LeaderSyncProcessor.ts +183 -122
- package/src/leader-thread/{apply-mutation.ts → apply-event.ts} +50 -74
- package/src/leader-thread/eventlog.ts +199 -0
- package/src/leader-thread/leader-worker-devtools.ts +18 -18
- package/src/leader-thread/make-leader-thread-layer.ts +51 -29
- package/src/leader-thread/mod.ts +1 -1
- package/src/leader-thread/recreate-db.ts +6 -9
- package/src/leader-thread/types.ts +12 -12
- package/src/materializer-helper.ts +110 -0
- package/src/query-builder/api.ts +79 -105
- package/src/query-builder/astToSql.ts +68 -39
- package/src/query-builder/impl.test.ts +264 -42
- package/src/query-builder/impl.ts +72 -56
- package/src/{rehydrate-from-mutationlog.ts → rehydrate-from-eventlog.ts} +33 -40
- package/src/schema/EventDef.ts +216 -0
- package/src/schema/EventId.ts +11 -3
- package/src/schema/{MutationEvent.ts → LiveStoreEvent.ts} +68 -69
- package/src/schema/client-document-def.test.ts +239 -0
- package/src/schema/client-document-def.ts +444 -0
- package/src/schema/db-schema/dsl/mod.ts +0 -1
- package/src/schema/events.ts +1 -0
- package/src/schema/mod.ts +4 -3
- package/src/schema/schema.ts +79 -69
- package/src/schema/sqlite-state.ts +62 -0
- package/src/schema/system-tables.ts +42 -53
- package/src/schema/table-def.ts +53 -209
- package/src/schema/view.ts +2 -0
- package/src/schema-management/common.ts +4 -4
- package/src/schema-management/migrations.ts +8 -9
- package/src/schema-management/validate-mutation-defs.ts +22 -24
- package/src/sync/ClientSessionSyncProcessor.ts +37 -36
- package/src/sync/next/facts.ts +31 -32
- package/src/sync/next/history-dag-common.ts +4 -4
- package/src/sync/next/history-dag.ts +1 -1
- package/src/sync/next/rebase-events.ts +13 -13
- package/src/sync/next/test/compact-events.calculator.test.ts +45 -45
- package/src/sync/next/test/compact-events.test.ts +73 -73
- package/src/sync/next/test/event-fixtures.ts +219 -0
- package/src/sync/next/test/mod.ts +1 -1
- package/src/sync/sync.ts +3 -3
- package/src/sync/syncstate.test.ts +168 -179
- package/src/sync/syncstate.ts +48 -38
- package/src/sync/validate-push-payload.ts +2 -2
- package/src/version.ts +1 -1
- package/tmp/pack.tgz +0 -0
- package/tsconfig.json +1 -0
- package/dist/derived-mutations.d.ts +0 -109
- package/dist/derived-mutations.d.ts.map +0 -1
- package/dist/derived-mutations.js +0 -54
- package/dist/derived-mutations.js.map +0 -1
- package/dist/derived-mutations.test.d.ts +0 -2
- package/dist/derived-mutations.test.d.ts.map +0 -1
- package/dist/derived-mutations.test.js +0 -93
- package/dist/derived-mutations.test.js.map +0 -1
- package/dist/init-singleton-tables.d.ts +0 -4
- package/dist/init-singleton-tables.d.ts.map +0 -1
- package/dist/init-singleton-tables.js +0 -16
- package/dist/init-singleton-tables.js.map +0 -1
- package/dist/leader-thread/apply-mutation.d.ts.map +0 -1
- package/dist/leader-thread/apply-mutation.js +0 -122
- package/dist/leader-thread/apply-mutation.js.map +0 -1
- package/dist/leader-thread/mutationlog.d.ts +0 -27
- package/dist/leader-thread/mutationlog.d.ts.map +0 -1
- package/dist/leader-thread/mutationlog.js +0 -124
- package/dist/leader-thread/mutationlog.js.map +0 -1
- package/dist/leader-thread/pull-queue-set.d.ts +0 -7
- package/dist/leader-thread/pull-queue-set.d.ts.map +0 -1
- package/dist/leader-thread/pull-queue-set.js +0 -38
- package/dist/leader-thread/pull-queue-set.js.map +0 -1
- package/dist/mutation.d.ts +0 -20
- package/dist/mutation.d.ts.map +0 -1
- package/dist/mutation.js +0 -68
- package/dist/mutation.js.map +0 -1
- package/dist/query-info.d.ts +0 -41
- package/dist/query-info.d.ts.map +0 -1
- package/dist/query-info.js +0 -7
- package/dist/query-info.js.map +0 -1
- package/dist/rehydrate-from-mutationlog.d.ts +0 -15
- package/dist/rehydrate-from-mutationlog.d.ts.map +0 -1
- package/dist/rehydrate-from-mutationlog.js.map +0 -1
- package/dist/schema/MutationEvent.d.ts.map +0 -1
- package/dist/schema/MutationEvent.js.map +0 -1
- package/dist/schema/mutations.d.ts +0 -115
- package/dist/schema/mutations.d.ts.map +0 -1
- package/dist/schema/mutations.js +0 -42
- package/dist/schema/mutations.js.map +0 -1
- package/dist/sync/next/test/mutation-fixtures.d.ts.map +0 -1
- package/dist/sync/next/test/mutation-fixtures.js.map +0 -1
- package/src/derived-mutations.test.ts +0 -101
- package/src/derived-mutations.ts +0 -170
- package/src/init-singleton-tables.ts +0 -24
- package/src/leader-thread/mutationlog.ts +0 -202
- package/src/mutation.ts +0 -108
- package/src/query-info.ts +0 -83
- package/src/schema/mutations.ts +0 -193
- package/src/sync/next/test/mutation-fixtures.ts +0 -228
@@ -1,88 +1,81 @@
|
|
1
1
|
import { memoizeByRef } from '@livestore/utils'
|
2
2
|
import { Chunk, Effect, Option, Schema, Stream } from '@livestore/utils/effect'
|
3
3
|
|
4
|
-
import { type
|
5
|
-
import type {
|
6
|
-
import type {
|
7
|
-
import { EventId,
|
4
|
+
import { type SqliteDb, UnexpectedError } from './adapter-types.js'
|
5
|
+
import type { ApplyEvent } from './leader-thread/mod.js'
|
6
|
+
import type { EventDef, EventlogMetaRow, LiveStoreSchema } from './schema/mod.js'
|
7
|
+
import { EventId, EVENTLOG_META_TABLE, getEventDef, LiveStoreEvent } from './schema/mod.js'
|
8
8
|
import type { PreparedBindValues } from './util.js'
|
9
9
|
import { sql } from './util.js'
|
10
10
|
|
11
|
-
export const
|
12
|
-
|
11
|
+
export const rehydrateFromEventlog = ({
|
12
|
+
dbEventlog,
|
13
13
|
// TODO re-use this db when bringing back the boot in-memory db implementation
|
14
14
|
// db,
|
15
15
|
schema,
|
16
|
-
migrationOptions,
|
17
16
|
onProgress,
|
18
|
-
|
17
|
+
applyEvent,
|
19
18
|
}: {
|
20
|
-
|
19
|
+
dbEventlog: SqliteDb
|
21
20
|
// db: SqliteDb
|
22
21
|
schema: LiveStoreSchema
|
23
|
-
migrationOptions: MigrationOptionsFromMutationLog
|
24
22
|
onProgress: (_: { done: number; total: number }) => Effect.Effect<void>
|
25
|
-
|
23
|
+
applyEvent: ApplyEvent
|
26
24
|
}) =>
|
27
25
|
Effect.gen(function* () {
|
28
|
-
const
|
29
|
-
|
30
|
-
)[0]!.count
|
26
|
+
const eventsCount = dbEventlog.select<{ count: number }>(`SELECT COUNT(*) AS count FROM ${EVENTLOG_META_TABLE}`)[0]!
|
27
|
+
.count
|
31
28
|
|
32
|
-
const
|
29
|
+
const hashEvent = memoizeByRef((event: EventDef.AnyWithoutFn) => Schema.hash(event.schema))
|
33
30
|
|
34
|
-
const
|
31
|
+
const processEvent = (row: EventlogMetaRow) =>
|
35
32
|
Effect.gen(function* () {
|
36
|
-
const
|
33
|
+
const eventDef = getEventDef(schema, row.name)
|
37
34
|
|
38
|
-
if (
|
39
|
-
|
40
|
-
if (hashMutation(mutationDef) !== row.schemaHash) {
|
41
|
-
yield* Effect.logWarning(
|
42
|
-
`Schema hash mismatch for mutation ${row.mutation}. Trying to apply mutation anyway.`,
|
43
|
-
)
|
35
|
+
if (hashEvent(eventDef.eventDef) !== row.schemaHash) {
|
36
|
+
yield* Effect.logWarning(`Schema hash mismatch for mutation ${row.name}. Trying to apply mutation anyway.`)
|
44
37
|
}
|
45
38
|
|
46
39
|
const args = JSON.parse(row.argsJson)
|
47
40
|
|
48
41
|
// Checking whether the schema has changed in an incompatible way
|
49
|
-
yield* Schema.decodeUnknown(
|
42
|
+
yield* Schema.decodeUnknown(eventDef.eventDef.schema)(args).pipe(
|
50
43
|
Effect.mapError((cause) =>
|
51
44
|
UnexpectedError.make({
|
52
45
|
cause,
|
53
46
|
note: `\
|
54
|
-
There was an error during rehydrating from the
|
55
|
-
the persisted mutation event args for mutation "${row.
|
47
|
+
There was an error during rehydrating from the eventlog while decoding
|
48
|
+
the persisted mutation event args for mutation "${row.name}".
|
56
49
|
This likely means the schema has changed in an incompatible way.
|
57
50
|
`,
|
58
51
|
}),
|
59
52
|
),
|
60
53
|
)
|
61
54
|
|
62
|
-
const
|
55
|
+
const eventEncoded = LiveStoreEvent.EncodedWithMeta.make({
|
63
56
|
id: { global: row.idGlobal, client: row.idClient },
|
64
57
|
parentId: { global: row.parentIdGlobal, client: row.parentIdClient },
|
65
|
-
|
58
|
+
name: row.name,
|
66
59
|
args,
|
67
60
|
clientId: row.clientId,
|
68
61
|
sessionId: row.sessionId,
|
69
62
|
})
|
70
63
|
|
71
|
-
yield*
|
72
|
-
}).pipe(Effect.withSpan(`@livestore/common:
|
64
|
+
yield* applyEvent(eventEncoded, { skipEventlog: true })
|
65
|
+
}).pipe(Effect.withSpan(`@livestore/common:rehydrateFromEventlog:processEvent`))
|
73
66
|
|
74
67
|
const CHUNK_SIZE = 100
|
75
68
|
|
76
|
-
const stmt =
|
77
|
-
SELECT * FROM ${
|
69
|
+
const stmt = dbEventlog.prepare(sql`\
|
70
|
+
SELECT * FROM ${EVENTLOG_META_TABLE}
|
78
71
|
WHERE idGlobal > $idGlobal OR (idGlobal = $idGlobal AND idClient > $idClient)
|
79
72
|
ORDER BY idGlobal ASC, idClient ASC
|
80
73
|
LIMIT ${CHUNK_SIZE}
|
81
74
|
`)
|
82
75
|
|
83
|
-
let
|
76
|
+
let processedEvents = 0
|
84
77
|
|
85
|
-
yield* Stream.unfoldChunk<Chunk.Chunk<
|
78
|
+
yield* Stream.unfoldChunk<Chunk.Chunk<EventlogMetaRow> | { _tag: 'Initial ' }, EventlogMetaRow>(
|
86
79
|
{ _tag: 'Initial ' },
|
87
80
|
(item) => {
|
88
81
|
// End stream if no more rows
|
@@ -95,7 +88,7 @@ LIMIT ${CHUNK_SIZE}
|
|
95
88
|
)
|
96
89
|
: EventId.ROOT
|
97
90
|
const nextItem = Chunk.fromIterable(
|
98
|
-
stmt.select<
|
91
|
+
stmt.select<EventlogMetaRow>({
|
99
92
|
$idGlobal: lastId?.global,
|
100
93
|
$idClient: lastId?.client,
|
101
94
|
} as any as PreparedBindValues),
|
@@ -107,15 +100,15 @@ LIMIT ${CHUNK_SIZE}
|
|
107
100
|
Stream.bufferChunks({ capacity: 2 }),
|
108
101
|
Stream.tap((row) =>
|
109
102
|
Effect.gen(function* () {
|
110
|
-
yield*
|
103
|
+
yield* processEvent(row)
|
111
104
|
|
112
|
-
|
113
|
-
yield* onProgress({ done:
|
105
|
+
processedEvents++
|
106
|
+
yield* onProgress({ done: processedEvents, total: eventsCount })
|
114
107
|
}),
|
115
108
|
),
|
116
109
|
Stream.runDrain,
|
117
110
|
)
|
118
111
|
}).pipe(
|
119
|
-
Effect.withPerformanceMeasure('@livestore/common:
|
120
|
-
Effect.withSpan('@livestore/common:
|
112
|
+
Effect.withPerformanceMeasure('@livestore/common:rehydrateFromEventlog'),
|
113
|
+
Effect.withSpan('@livestore/common:rehydrateFromEventlog'),
|
121
114
|
)
|
@@ -0,0 +1,216 @@
|
|
1
|
+
import type { SingleOrReadonlyArray } from '@livestore/utils'
|
2
|
+
import { shouldNeverHappen } from '@livestore/utils'
|
3
|
+
import { Schema } from '@livestore/utils/effect'
|
4
|
+
|
5
|
+
import type { QueryBuilder } from '../query-builder/mod.js'
|
6
|
+
import type { BindValues } from '../sql-queries/sql-queries.js'
|
7
|
+
|
8
|
+
export type EventDefMap = {
|
9
|
+
map: Map<string | 'livestore.RawSql', EventDef.Any>
|
10
|
+
}
|
11
|
+
export type EventDefRecord = {
|
12
|
+
'livestore.RawSql': RawSqlEvent
|
13
|
+
[name: string]: EventDef.Any
|
14
|
+
}
|
15
|
+
|
16
|
+
export type EventDef<TName extends string, TType, TEncoded = TType, TDerived extends boolean = false> = {
|
17
|
+
name: TName
|
18
|
+
schema: Schema.Schema<TType, TEncoded>
|
19
|
+
options: {
|
20
|
+
/**
|
21
|
+
* When set to true, the mutation won't be synced across clients but
|
22
|
+
*/
|
23
|
+
clientOnly: boolean
|
24
|
+
/** Warning: This feature is not fully implemented yet */
|
25
|
+
facts: FactsCallback<TType> | undefined
|
26
|
+
derived: TDerived
|
27
|
+
}
|
28
|
+
|
29
|
+
/** Helper function to construct a partial mutation event */
|
30
|
+
(args: TType): {
|
31
|
+
name: TName
|
32
|
+
args: TType
|
33
|
+
}
|
34
|
+
|
35
|
+
readonly Event: {
|
36
|
+
name: TName
|
37
|
+
args: TType
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
export type FactsCallback<TTo> = (
|
42
|
+
args: TTo,
|
43
|
+
currentFacts: EventDefFacts,
|
44
|
+
) => {
|
45
|
+
modify: {
|
46
|
+
set: Iterable<EventDefFactInput>
|
47
|
+
unset: Iterable<EventDefFactInput>
|
48
|
+
}
|
49
|
+
require: Iterable<EventDefFactInput>
|
50
|
+
}
|
51
|
+
|
52
|
+
export namespace EventDef {
|
53
|
+
export type Any = EventDef<string, any, any, boolean>
|
54
|
+
|
55
|
+
export type AnyWithoutFn = Pick<Any, 'name' | 'schema' | 'options'>
|
56
|
+
}
|
57
|
+
|
58
|
+
export type EventDefKey = string
|
59
|
+
export type EventDefFact = string
|
60
|
+
export type EventDefFacts = ReadonlyMap<string, any>
|
61
|
+
|
62
|
+
export type EventDefFactsGroup = {
|
63
|
+
modifySet: EventDefFacts
|
64
|
+
modifyUnset: EventDefFacts
|
65
|
+
|
66
|
+
/**
|
67
|
+
* Events on independent "dependency" branches are commutative which can facilitate more prioritized syncing
|
68
|
+
*/
|
69
|
+
depRequire: EventDefFacts
|
70
|
+
depRead: EventDefFacts
|
71
|
+
}
|
72
|
+
|
73
|
+
export type EventDefFactsSnapshot = Map<string, any>
|
74
|
+
|
75
|
+
export type EventDefFactInput = string | readonly [string, any]
|
76
|
+
|
77
|
+
export const defineFacts = <
|
78
|
+
TRecord extends Record<string, EventDefFactInput | ((...args: any[]) => EventDefFactInput)>,
|
79
|
+
>(
|
80
|
+
record: TRecord,
|
81
|
+
): TRecord => record
|
82
|
+
|
83
|
+
export type DefineEventOptions<TTo, TDerived extends boolean = false> = {
|
84
|
+
// TODO actually implement this
|
85
|
+
// onError?: (error: any) => void
|
86
|
+
/** Warning: This feature is not fully implemented yet */
|
87
|
+
facts?: (
|
88
|
+
args: TTo,
|
89
|
+
currentFacts: EventDefFacts,
|
90
|
+
) => {
|
91
|
+
modify?: {
|
92
|
+
set?: Iterable<EventDefFactInput>
|
93
|
+
unset?: Iterable<EventDefFactInput>
|
94
|
+
}
|
95
|
+
/**
|
96
|
+
* Two purposes: constrain history and constrain compaction
|
97
|
+
*/
|
98
|
+
require?: Iterable<EventDefFactInput>
|
99
|
+
}
|
100
|
+
/**
|
101
|
+
* When set to true, the event won't be synced over the network
|
102
|
+
*/
|
103
|
+
clientOnly?: boolean
|
104
|
+
derived?: TDerived
|
105
|
+
}
|
106
|
+
|
107
|
+
export const defineEvent = <TName extends string, TType, TEncoded = TType, TDerived extends boolean = false>(
|
108
|
+
args: {
|
109
|
+
name: TName
|
110
|
+
schema: Schema.Schema<TType, TEncoded>
|
111
|
+
} & DefineEventOptions<TType, TDerived>,
|
112
|
+
): EventDef<TName, TType, TEncoded, TDerived> => {
|
113
|
+
const { name, schema, ...options } = args
|
114
|
+
|
115
|
+
const makePartialEvent = (args: TType) => {
|
116
|
+
const res = Schema.validateEither(schema)(args)
|
117
|
+
if (res._tag === 'Left') {
|
118
|
+
shouldNeverHappen(`Invalid event args for event '${name}':`, res.left.message, '\n')
|
119
|
+
}
|
120
|
+
return { name: name, args }
|
121
|
+
}
|
122
|
+
|
123
|
+
Object.defineProperty(makePartialEvent, 'name', { value: name })
|
124
|
+
Object.defineProperty(makePartialEvent, 'schema', { value: schema })
|
125
|
+
Object.defineProperty(makePartialEvent, 'options', {
|
126
|
+
value: {
|
127
|
+
clientOnly: options?.clientOnly ?? false,
|
128
|
+
facts: options?.facts
|
129
|
+
? (args, currentFacts) => {
|
130
|
+
const res = options.facts!(args, currentFacts)
|
131
|
+
return {
|
132
|
+
modify: {
|
133
|
+
set: res.modify?.set ? new Set(res.modify.set) : new Set(),
|
134
|
+
unset: res.modify?.unset ? new Set(res.modify.unset) : new Set(),
|
135
|
+
},
|
136
|
+
require: res.require ? new Set(res.require) : new Set(),
|
137
|
+
}
|
138
|
+
}
|
139
|
+
: undefined,
|
140
|
+
derived: options?.derived ?? false,
|
141
|
+
} satisfies EventDef.Any['options'],
|
142
|
+
})
|
143
|
+
|
144
|
+
return makePartialEvent as EventDef<TName, TType, TEncoded, TDerived>
|
145
|
+
}
|
146
|
+
|
147
|
+
export const synced = <TName extends string, TType, TEncoded = TType>(
|
148
|
+
args: {
|
149
|
+
name: TName
|
150
|
+
schema: Schema.Schema<TType, TEncoded>
|
151
|
+
} & Omit<DefineEventOptions<TType, false>, 'derived' | 'clientOnly'>,
|
152
|
+
): EventDef<TName, TType, TEncoded> => defineEvent({ ...args, clientOnly: false })
|
153
|
+
|
154
|
+
export const clientOnly = <TName extends string, TType, TEncoded = TType>(
|
155
|
+
args: {
|
156
|
+
name: TName
|
157
|
+
schema: Schema.Schema<TType, TEncoded>
|
158
|
+
} & Omit<DefineEventOptions<TType, false>, 'derived' | 'clientOnly'>,
|
159
|
+
): EventDef<TName, TType, TEncoded> => defineEvent({ ...args, clientOnly: true })
|
160
|
+
|
161
|
+
export type MaterializerResult =
|
162
|
+
| {
|
163
|
+
sql: string
|
164
|
+
bindValues: BindValues
|
165
|
+
writeTables?: ReadonlySet<string>
|
166
|
+
}
|
167
|
+
| QueryBuilder.Any
|
168
|
+
| string
|
169
|
+
|
170
|
+
export type Materializer<TEventDef extends EventDef.AnyWithoutFn = EventDef.AnyWithoutFn> = (
|
171
|
+
event: TEventDef['schema']['Type'],
|
172
|
+
context: { currentFacts: EventDefFacts; clientOnly: boolean },
|
173
|
+
) => SingleOrReadonlyArray<MaterializerResult>
|
174
|
+
|
175
|
+
export const defineMaterializer = <TEventDef extends EventDef.AnyWithoutFn>(
|
176
|
+
eventDef: TEventDef,
|
177
|
+
materializer: Materializer<TEventDef>,
|
178
|
+
): Materializer<TEventDef> => {
|
179
|
+
return materializer
|
180
|
+
}
|
181
|
+
|
182
|
+
export const materializers = <TInputRecord extends Record<string, EventDef.AnyWithoutFn>>(
|
183
|
+
eventDefRecord: TInputRecord,
|
184
|
+
handlers: {
|
185
|
+
[TEventName in TInputRecord[keyof TInputRecord]['name'] as Extract<
|
186
|
+
TInputRecord[keyof TInputRecord],
|
187
|
+
{ name: TEventName }
|
188
|
+
>['options']['derived'] extends true
|
189
|
+
? never
|
190
|
+
: TEventName]: Materializer<Extract<TInputRecord[keyof TInputRecord], { name: TEventName }>>
|
191
|
+
// [K in TInputRecord[keyof TInputRecord]['name']]: Materializer<
|
192
|
+
// Extract<TInputRecord[keyof TInputRecord], { name: K }>
|
193
|
+
// >
|
194
|
+
},
|
195
|
+
) => {
|
196
|
+
return handlers
|
197
|
+
}
|
198
|
+
|
199
|
+
export const rawSqlEvent = defineEvent({
|
200
|
+
name: 'livestore.RawSql',
|
201
|
+
schema: Schema.Struct({
|
202
|
+
sql: Schema.String,
|
203
|
+
bindValues: Schema.optional(Schema.Record({ key: Schema.String, value: Schema.Any })),
|
204
|
+
writeTables: Schema.optional(Schema.ReadonlySet(Schema.String)),
|
205
|
+
}),
|
206
|
+
clientOnly: true,
|
207
|
+
derived: true,
|
208
|
+
})
|
209
|
+
|
210
|
+
export const rawSqlMaterializer = defineMaterializer(rawSqlEvent, ({ sql, bindValues, writeTables }) => ({
|
211
|
+
sql,
|
212
|
+
bindValues: bindValues ?? {},
|
213
|
+
writeTables,
|
214
|
+
}))
|
215
|
+
|
216
|
+
export type RawSqlEvent = typeof rawSqlEvent
|
package/src/schema/EventId.ts
CHANGED
@@ -14,20 +14,28 @@ export const clientDefault = 0 as any as ClientEventId
|
|
14
14
|
* LiveStore event id value consisting of a globally unique event sequence number
|
15
15
|
* and a client sequence number.
|
16
16
|
*
|
17
|
-
* The client sequence number is only used for clientOnly
|
17
|
+
* The client sequence number is only used for clientOnly events and starts from 0 for each global sequence number.
|
18
18
|
*/
|
19
19
|
export type EventId = { global: GlobalEventId; client: ClientEventId }
|
20
20
|
|
21
21
|
// export const EventSequenceNumber = Schema.Struct({})
|
22
22
|
// export const EventNumber = Schema.Struct({})
|
23
|
+
// export const ClientEventNumber = Schema.Struct({})
|
24
|
+
// export const GlobalEventNumber = Schema.Struct({})
|
23
25
|
|
24
26
|
/**
|
25
27
|
* NOTE: Client mutation events with a non-0 client id, won't be synced to the sync backend.
|
26
28
|
*/
|
27
29
|
export const EventId = Schema.Struct({
|
28
30
|
global: GlobalEventId,
|
29
|
-
/** Only increments for clientOnly
|
31
|
+
/** Only increments for clientOnly events */
|
30
32
|
client: ClientEventId,
|
33
|
+
|
34
|
+
// TODO also provide a way to see "confirmation level" of event (e.g. confirmed by leader/sync backend)
|
35
|
+
|
36
|
+
// TODO: actually add this field
|
37
|
+
// Client only
|
38
|
+
// generation: Schema.Number.pipe(Schema.optional),
|
31
39
|
}).annotations({ title: 'LiveStore.EventId' })
|
32
40
|
|
33
41
|
/**
|
@@ -92,7 +100,7 @@ export const nextPair = (id: EventId, isLocal: boolean): EventIdPair => {
|
|
92
100
|
|
93
101
|
return {
|
94
102
|
id: { global: (id.global + 1) as any as GlobalEventId, client: clientDefault },
|
95
|
-
// NOTE we always point to `client: 0` for non-clientOnly
|
103
|
+
// NOTE we always point to `client: 0` for non-clientOnly events
|
96
104
|
parentId: { global: id.global, client: clientDefault },
|
97
105
|
}
|
98
106
|
}
|
@@ -1,133 +1,132 @@
|
|
1
1
|
import { memoizeByRef } from '@livestore/utils'
|
2
2
|
import { Option, Schema } from '@livestore/utils/effect'
|
3
3
|
|
4
|
+
import type { EventDef, EventDefRecord } from './EventDef.js'
|
4
5
|
import * as EventId from './EventId.js'
|
5
|
-
import type { MutationDef, MutationDefRecord } from './mutations.js'
|
6
6
|
import type { LiveStoreSchema } from './schema.js'
|
7
7
|
|
8
|
-
export type
|
9
|
-
|
10
|
-
args: Schema.Schema.Type<
|
8
|
+
export type EventDefPartial<TEventDef extends EventDef.Any> = {
|
9
|
+
name: TEventDef['name']
|
10
|
+
args: Schema.Schema.Type<TEventDef['schema']>
|
11
11
|
}
|
12
12
|
|
13
|
-
export type PartialEncoded<
|
14
|
-
|
15
|
-
args: Schema.Schema.Encoded<
|
13
|
+
export type PartialEncoded<TEventDef extends EventDef.Any> = {
|
14
|
+
name: TEventDef['name']
|
15
|
+
args: Schema.Schema.Encoded<TEventDef['schema']>
|
16
16
|
}
|
17
17
|
|
18
|
-
export type
|
19
|
-
|
20
|
-
args: Schema.Schema.Type<
|
18
|
+
export type ForEventDef<TEventDef extends EventDef.Any> = {
|
19
|
+
name: TEventDef['name']
|
20
|
+
args: Schema.Schema.Type<TEventDef['schema']>
|
21
21
|
id: EventId.EventId
|
22
22
|
parentId: EventId.EventId
|
23
23
|
clientId: string
|
24
24
|
sessionId: string
|
25
25
|
}
|
26
26
|
|
27
|
-
export type
|
28
|
-
|
29
|
-
args: Schema.Schema.Encoded<
|
27
|
+
export type EventDefEncoded<TEventDef extends EventDef.Any> = {
|
28
|
+
name: TEventDef['name']
|
29
|
+
args: Schema.Schema.Encoded<TEventDef['schema']>
|
30
30
|
id: EventId.EventId
|
31
31
|
parentId: EventId.EventId
|
32
32
|
clientId: string
|
33
33
|
sessionId: string
|
34
34
|
}
|
35
35
|
|
36
|
-
export type AnyDecoded =
|
36
|
+
export type AnyDecoded = ForEventDef<EventDef.Any>
|
37
37
|
export const AnyDecoded = Schema.Struct({
|
38
|
-
|
38
|
+
name: Schema.String,
|
39
39
|
args: Schema.Any,
|
40
40
|
id: EventId.EventId,
|
41
41
|
parentId: EventId.EventId,
|
42
42
|
clientId: Schema.String,
|
43
43
|
sessionId: Schema.String,
|
44
|
-
}).annotations({ title: '
|
44
|
+
}).annotations({ title: 'LiveStoreEvent.AnyDecoded' })
|
45
45
|
|
46
|
-
export type AnyEncoded =
|
46
|
+
export type AnyEncoded = EventDefEncoded<EventDef.Any>
|
47
47
|
export const AnyEncoded = Schema.Struct({
|
48
|
-
|
48
|
+
name: Schema.String,
|
49
49
|
args: Schema.Any,
|
50
50
|
id: EventId.EventId,
|
51
51
|
parentId: EventId.EventId,
|
52
52
|
clientId: Schema.String,
|
53
53
|
sessionId: Schema.String,
|
54
|
-
}).annotations({ title: '
|
54
|
+
}).annotations({ title: 'LiveStoreEvent.AnyEncoded' })
|
55
55
|
|
56
56
|
export const AnyEncodedGlobal = Schema.Struct({
|
57
|
-
|
57
|
+
name: Schema.String,
|
58
58
|
args: Schema.Any,
|
59
59
|
id: EventId.GlobalEventId,
|
60
60
|
parentId: EventId.GlobalEventId,
|
61
61
|
clientId: Schema.String,
|
62
62
|
sessionId: Schema.String,
|
63
|
-
}).annotations({ title: '
|
63
|
+
}).annotations({ title: 'LiveStoreEvent.AnyEncodedGlobal' })
|
64
64
|
export type AnyEncodedGlobal = typeof AnyEncodedGlobal.Type
|
65
65
|
|
66
|
-
export type PartialAnyDecoded =
|
67
|
-
export type PartialAnyEncoded = PartialEncoded<
|
66
|
+
export type PartialAnyDecoded = EventDefPartial<EventDef.Any>
|
67
|
+
export type PartialAnyEncoded = PartialEncoded<EventDef.Any>
|
68
68
|
|
69
69
|
export const PartialAnyEncoded = Schema.Struct({
|
70
|
-
|
70
|
+
name: Schema.String,
|
71
71
|
args: Schema.Any,
|
72
72
|
})
|
73
73
|
|
74
74
|
export type PartialForSchema<TSchema extends LiveStoreSchema> = {
|
75
|
-
[K in keyof TSchema['
|
76
|
-
}[keyof TSchema['
|
75
|
+
[K in keyof TSchema['_EventDefMapType']]: EventDefPartial<TSchema['_EventDefMapType'][K]>
|
76
|
+
}[keyof TSchema['_EventDefMapType']]
|
77
77
|
|
78
78
|
export type ForSchema<TSchema extends LiveStoreSchema> = {
|
79
|
-
[K in keyof TSchema['
|
80
|
-
}[keyof TSchema['
|
79
|
+
[K in keyof TSchema['_EventDefMapType']]: ForEventDef<TSchema['_EventDefMapType'][K]>
|
80
|
+
}[keyof TSchema['_EventDefMapType']]
|
81
81
|
|
82
|
-
export const
|
83
|
-
|
84
|
-
): mutationEvent is PartialAnyDecoded => 'id' in mutationEvent === false && 'parentId' in mutationEvent === false
|
82
|
+
export const isPartialEventDef = (event: AnyDecoded | PartialAnyDecoded): event is PartialAnyDecoded =>
|
83
|
+
'id' in event === false && 'parentId' in event === false
|
85
84
|
|
86
|
-
export type
|
85
|
+
export type ForEventDefRecord<TEventDefRecord extends EventDefRecord> = Schema.Schema<
|
87
86
|
{
|
88
|
-
[K in keyof
|
89
|
-
|
90
|
-
args: Schema.Schema.Type<
|
87
|
+
[K in keyof TEventDefRecord]: {
|
88
|
+
name: K
|
89
|
+
args: Schema.Schema.Type<TEventDefRecord[K]['schema']>
|
91
90
|
id: EventId.EventId
|
92
91
|
parentId: EventId.EventId
|
93
92
|
clientId: string
|
94
93
|
sessionId: string
|
95
94
|
}
|
96
|
-
}[keyof
|
95
|
+
}[keyof TEventDefRecord],
|
97
96
|
{
|
98
|
-
[K in keyof
|
99
|
-
|
100
|
-
args: Schema.Schema.Encoded<
|
97
|
+
[K in keyof TEventDefRecord]: {
|
98
|
+
name: K
|
99
|
+
args: Schema.Schema.Encoded<TEventDefRecord[K]['schema']>
|
101
100
|
id: EventId.EventId
|
102
101
|
parentId: EventId.EventId
|
103
102
|
clientId: string
|
104
103
|
sessionId: string
|
105
104
|
}
|
106
|
-
}[keyof
|
105
|
+
}[keyof TEventDefRecord]
|
107
106
|
>
|
108
107
|
|
109
|
-
export type
|
108
|
+
export type EventDefPartialSchema<TEventDefRecord extends EventDefRecord> = Schema.Schema<
|
110
109
|
{
|
111
|
-
[K in keyof
|
112
|
-
|
113
|
-
args: Schema.Schema.Type<
|
110
|
+
[K in keyof TEventDefRecord]: {
|
111
|
+
name: K
|
112
|
+
args: Schema.Schema.Type<TEventDefRecord[K]['schema']>
|
114
113
|
}
|
115
|
-
}[keyof
|
114
|
+
}[keyof TEventDefRecord],
|
116
115
|
{
|
117
|
-
[K in keyof
|
118
|
-
|
119
|
-
args: Schema.Schema.Encoded<
|
116
|
+
[K in keyof TEventDefRecord]: {
|
117
|
+
name: K
|
118
|
+
args: Schema.Schema.Encoded<TEventDefRecord[K]['schema']>
|
120
119
|
}
|
121
|
-
}[keyof
|
120
|
+
}[keyof TEventDefRecord]
|
122
121
|
>
|
123
122
|
|
124
|
-
export const
|
123
|
+
export const makeEventDefSchema = <TSchema extends LiveStoreSchema>(
|
125
124
|
schema: TSchema,
|
126
|
-
):
|
125
|
+
): ForEventDefRecord<TSchema['_EventDefMapType']> =>
|
127
126
|
Schema.Union(
|
128
|
-
...[...schema.
|
127
|
+
...[...schema.eventsDefsMap.values()].map((def) =>
|
129
128
|
Schema.Struct({
|
130
|
-
|
129
|
+
name: Schema.Literal(def.name),
|
131
130
|
args: def.schema,
|
132
131
|
id: EventId.EventId,
|
133
132
|
parentId: EventId.EventId,
|
@@ -135,25 +134,25 @@ export const makeMutationEventSchema = <TSchema extends LiveStoreSchema>(
|
|
135
134
|
sessionId: Schema.String,
|
136
135
|
}),
|
137
136
|
),
|
138
|
-
).annotations({ title: '
|
137
|
+
).annotations({ title: 'EventDef' }) as any
|
139
138
|
|
140
|
-
export const
|
139
|
+
export const makeEventDefPartialSchema = <TSchema extends LiveStoreSchema>(
|
141
140
|
schema: TSchema,
|
142
|
-
):
|
141
|
+
): EventDefPartialSchema<TSchema['_EventDefMapType']> =>
|
143
142
|
Schema.Union(
|
144
|
-
...[...schema.
|
143
|
+
...[...schema.eventsDefsMap.values()].map((def) =>
|
145
144
|
Schema.Struct({
|
146
|
-
|
145
|
+
name: Schema.Literal(def.name),
|
147
146
|
args: def.schema,
|
148
147
|
}),
|
149
148
|
),
|
150
|
-
).annotations({ title: '
|
149
|
+
).annotations({ title: 'EventDefPartial' }) as any
|
151
150
|
|
152
|
-
export const
|
151
|
+
export const makeEventDefSchemaMemo = memoizeByRef(makeEventDefSchema)
|
153
152
|
|
154
153
|
/** Equivalent to AnyEncoded but with a meta field and some convenience methods */
|
155
|
-
export class EncodedWithMeta extends Schema.Class<EncodedWithMeta>('
|
156
|
-
|
154
|
+
export class EncodedWithMeta extends Schema.Class<EncodedWithMeta>('LiveStoreEvent.EncodedWithMeta')({
|
155
|
+
name: Schema.String,
|
157
156
|
args: Schema.Any,
|
158
157
|
// TODO rename to `.num` / `.parentNum`
|
159
158
|
id: EventId.EventId,
|
@@ -185,8 +184,8 @@ export class EncodedWithMeta extends Schema.Class<EncodedWithMeta>('MutationEven
|
|
185
184
|
// - More readable way to print the id + parentId
|
186
185
|
// - not including `meta`, `clientId`, `sessionId`
|
187
186
|
return {
|
188
|
-
id: `${EventId.toString(this.id)} → ${EventId.toString(this.parentId)}`,
|
189
|
-
|
187
|
+
id: `${EventId.toString(this.id)} → ${EventId.toString(this.parentId)} (${this.clientId}, ${this.sessionId})`,
|
188
|
+
name: this.name,
|
190
189
|
args: this.args,
|
191
190
|
}
|
192
191
|
}
|
@@ -214,11 +213,11 @@ export class EncodedWithMeta extends Schema.Class<EncodedWithMeta>('MutationEven
|
|
214
213
|
...EventId.nextPair(parentId, isClient),
|
215
214
|
})
|
216
215
|
|
217
|
-
static fromGlobal = (
|
216
|
+
static fromGlobal = (event: AnyEncodedGlobal, syncMetadata: Option.Option<Schema.JsonValue>) =>
|
218
217
|
new EncodedWithMeta({
|
219
|
-
...
|
220
|
-
id: { global:
|
221
|
-
parentId: { global:
|
218
|
+
...event,
|
219
|
+
id: { global: event.id, client: EventId.clientDefault },
|
220
|
+
parentId: { global: event.parentId, client: EventId.clientDefault },
|
222
221
|
meta: { sessionChangeset: { _tag: 'unset' as const }, syncMetadata },
|
223
222
|
})
|
224
223
|
|
@@ -233,7 +232,7 @@ export class EncodedWithMeta extends Schema.Class<EncodedWithMeta>('MutationEven
|
|
233
232
|
export const isEqualEncoded = (a: AnyEncoded, b: AnyEncoded) =>
|
234
233
|
a.id.global === b.id.global &&
|
235
234
|
a.id.client === b.id.client &&
|
236
|
-
a.
|
235
|
+
a.name === b.name &&
|
237
236
|
a.clientId === b.clientId &&
|
238
237
|
a.sessionId === b.sessionId &&
|
239
238
|
// TODO use schema equality here
|