@livestore/common 0.3.0-dev.33 → 0.3.0-dev.34
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/adapter-types.d.ts +5 -9
- 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 +30 -29
- package/dist/devtools/devtools-messages-client-session.d.ts.map +1 -1
- package/dist/devtools/devtools-messages-client-session.js +1 -0
- 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 +25 -25
- package/dist/devtools/devtools-messages-leader.js +1 -1
- package/dist/devtools/devtools-messages-leader.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/leader-thread/LeaderSyncProcessor.d.ts +4 -4
- package/dist/leader-thread/LeaderSyncProcessor.d.ts.map +1 -1
- package/dist/leader-thread/LeaderSyncProcessor.js +21 -17
- package/dist/leader-thread/LeaderSyncProcessor.js.map +1 -1
- package/dist/leader-thread/apply-event.d.ts +4 -4
- package/dist/leader-thread/apply-event.d.ts.map +1 -1
- package/dist/leader-thread/apply-event.js +9 -9
- package/dist/leader-thread/apply-event.js.map +1 -1
- package/dist/leader-thread/eventlog.d.ts.map +1 -1
- package/dist/leader-thread/eventlog.js +11 -15
- 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 +13 -12
- 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 +11 -18
- package/dist/leader-thread/make-leader-thread-layer.js.map +1 -1
- package/dist/leader-thread/materialize-event.d.ts +16 -0
- package/dist/leader-thread/materialize-event.d.ts.map +1 -0
- package/dist/leader-thread/materialize-event.js +103 -0
- package/dist/leader-thread/materialize-event.js.map +1 -0
- package/dist/leader-thread/recreate-db.d.ts.map +1 -1
- package/dist/leader-thread/recreate-db.js +9 -17
- package/dist/leader-thread/recreate-db.js.map +1 -1
- package/dist/leader-thread/types.d.ts +5 -5
- package/dist/leader-thread/types.d.ts.map +1 -1
- package/dist/materializer-helper.d.ts.map +1 -1
- package/dist/materializer-helper.js +1 -1
- package/dist/materializer-helper.js.map +1 -1
- package/dist/query-builder/api.d.ts +4 -4
- package/dist/query-builder/api.d.ts.map +1 -1
- package/dist/query-builder/impl.d.ts +2 -2
- package/dist/query-builder/impl.test.d.ts +5 -5
- package/dist/query-builder/mod.d.ts +2 -2
- package/dist/rehydrate-from-eventlog.d.ts +1 -1
- package/dist/rehydrate-from-eventlog.d.ts.map +1 -1
- package/dist/rehydrate-from-eventlog.js +6 -7
- package/dist/rehydrate-from-eventlog.js.map +1 -1
- package/dist/rematerialize-from-eventlog.d.ts +14 -0
- package/dist/rematerialize-from-eventlog.d.ts.map +1 -0
- package/dist/rematerialize-from-eventlog.js +64 -0
- package/dist/rematerialize-from-eventlog.js.map +1 -0
- package/dist/schema/EventDef.d.ts +3 -3
- package/dist/schema/EventDef.d.ts.map +1 -1
- package/dist/schema/EventId.test.js +1 -1
- package/dist/schema/EventId.test.js.map +1 -1
- package/dist/schema/client-document-def.d.ts +2 -2
- package/dist/schema/db-schema/dsl/mod.d.ts +3 -3
- package/dist/schema/db-schema/mod.d.ts +2 -2
- package/dist/schema/mod.d.ts +4 -4
- package/dist/schema/mod.d.ts.map +1 -1
- package/dist/schema/mod.js +4 -4
- package/dist/schema/mod.js.map +1 -1
- package/dist/schema/schema-helpers.d.ts +1 -1
- package/dist/schema/schema.d.ts +12 -14
- package/dist/schema/schema.d.ts.map +1 -1
- package/dist/schema/schema.js +5 -28
- package/dist/schema/schema.js.map +1 -1
- package/dist/schema/state/mod.d.ts +3 -0
- package/dist/schema/state/mod.d.ts.map +1 -0
- package/dist/schema/state/mod.js +3 -0
- package/dist/schema/state/mod.js.map +1 -0
- package/dist/schema/state/sqlite/client-document-def.d.ts +223 -0
- package/dist/schema/state/sqlite/client-document-def.d.ts.map +1 -0
- package/dist/schema/state/sqlite/client-document-def.js +170 -0
- package/dist/schema/state/sqlite/client-document-def.js.map +1 -0
- package/dist/schema/state/sqlite/client-document-def.test.d.ts +2 -0
- package/dist/schema/state/sqlite/client-document-def.test.d.ts.map +1 -0
- package/dist/schema/state/sqlite/client-document-def.test.js +201 -0
- package/dist/schema/state/sqlite/client-document-def.test.js.map +1 -0
- package/dist/schema/state/sqlite/db-schema/ast/sqlite.d.ts +69 -0
- package/dist/schema/state/sqlite/db-schema/ast/sqlite.d.ts.map +1 -0
- package/dist/schema/state/sqlite/db-schema/ast/sqlite.js +71 -0
- package/dist/schema/state/sqlite/db-schema/ast/sqlite.js.map +1 -0
- package/dist/schema/state/sqlite/db-schema/ast/validate.d.ts +3 -0
- package/dist/schema/state/sqlite/db-schema/ast/validate.d.ts.map +1 -0
- package/dist/schema/state/sqlite/db-schema/ast/validate.js +12 -0
- package/dist/schema/state/sqlite/db-schema/ast/validate.js.map +1 -0
- package/dist/schema/state/sqlite/db-schema/dsl/field-defs.d.ts +90 -0
- package/dist/schema/state/sqlite/db-schema/dsl/field-defs.d.ts.map +1 -0
- package/dist/schema/state/sqlite/db-schema/dsl/field-defs.js +87 -0
- package/dist/schema/state/sqlite/db-schema/dsl/field-defs.js.map +1 -0
- package/dist/schema/state/sqlite/db-schema/dsl/field-defs.test.d.ts +2 -0
- package/dist/schema/state/sqlite/db-schema/dsl/field-defs.test.d.ts.map +1 -0
- package/dist/schema/state/sqlite/db-schema/dsl/field-defs.test.js +29 -0
- package/dist/schema/state/sqlite/db-schema/dsl/field-defs.test.js.map +1 -0
- package/dist/schema/state/sqlite/db-schema/dsl/mod.d.ts +90 -0
- package/dist/schema/state/sqlite/db-schema/dsl/mod.d.ts.map +1 -0
- package/dist/schema/state/sqlite/db-schema/dsl/mod.js +41 -0
- package/dist/schema/state/sqlite/db-schema/dsl/mod.js.map +1 -0
- package/dist/schema/state/sqlite/db-schema/hash.d.ts +2 -0
- package/dist/schema/state/sqlite/db-schema/hash.d.ts.map +1 -0
- package/dist/schema/state/sqlite/db-schema/hash.js +14 -0
- package/dist/schema/state/sqlite/db-schema/hash.js.map +1 -0
- package/dist/schema/state/sqlite/db-schema/mod.d.ts +3 -0
- package/dist/schema/state/sqlite/db-schema/mod.d.ts.map +1 -0
- package/dist/schema/state/sqlite/db-schema/mod.js +3 -0
- package/dist/schema/state/sqlite/db-schema/mod.js.map +1 -0
- package/dist/schema/state/sqlite/mod.d.ts +17 -0
- package/dist/schema/state/sqlite/mod.d.ts.map +1 -0
- package/dist/schema/state/sqlite/mod.js +41 -0
- package/dist/schema/state/sqlite/mod.js.map +1 -0
- package/dist/schema/state/sqlite/query-builder/api.d.ts +293 -0
- package/dist/schema/state/sqlite/query-builder/api.d.ts.map +1 -0
- package/dist/schema/state/sqlite/query-builder/api.js +6 -0
- package/dist/schema/state/sqlite/query-builder/api.js.map +1 -0
- package/dist/schema/state/sqlite/query-builder/astToSql.d.ts +7 -0
- package/dist/schema/state/sqlite/query-builder/astToSql.d.ts.map +1 -0
- package/dist/schema/state/sqlite/query-builder/astToSql.js +190 -0
- package/dist/schema/state/sqlite/query-builder/astToSql.js.map +1 -0
- package/dist/schema/state/sqlite/query-builder/impl.d.ts +7 -0
- package/dist/schema/state/sqlite/query-builder/impl.d.ts.map +1 -0
- package/dist/schema/state/sqlite/query-builder/impl.js +286 -0
- package/dist/schema/state/sqlite/query-builder/impl.js.map +1 -0
- package/dist/schema/state/sqlite/query-builder/impl.test.d.ts +87 -0
- package/dist/schema/state/sqlite/query-builder/impl.test.d.ts.map +1 -0
- package/dist/schema/state/sqlite/query-builder/impl.test.js +554 -0
- package/dist/schema/state/sqlite/query-builder/impl.test.js.map +1 -0
- package/dist/schema/state/sqlite/query-builder/mod.d.ts +17 -0
- package/dist/schema/state/sqlite/query-builder/mod.d.ts.map +1 -0
- package/dist/schema/state/sqlite/query-builder/mod.js +17 -0
- package/dist/schema/state/sqlite/query-builder/mod.js.map +1 -0
- package/dist/schema/state/sqlite/schema-helpers.d.ts +4 -0
- package/dist/schema/state/sqlite/schema-helpers.d.ts.map +1 -0
- package/dist/schema/state/sqlite/schema-helpers.js +30 -0
- package/dist/schema/state/sqlite/schema-helpers.js.map +1 -0
- package/dist/schema/state/sqlite/sqlite-state.d.ts +12 -0
- package/dist/schema/state/sqlite/sqlite-state.d.ts.map +1 -0
- package/dist/schema/state/sqlite/sqlite-state.js +36 -0
- package/dist/schema/state/sqlite/sqlite-state.js.map +1 -0
- package/dist/schema/state/sqlite/system-tables.d.ts +574 -0
- package/dist/schema/state/sqlite/system-tables.d.ts.map +1 -0
- package/dist/schema/state/sqlite/system-tables.js +87 -0
- package/dist/schema/state/sqlite/system-tables.js.map +1 -0
- package/dist/schema/state/sqlite/table-def.d.ts +84 -0
- package/dist/schema/state/sqlite/table-def.d.ts.map +1 -0
- package/dist/schema/state/sqlite/table-def.js +36 -0
- package/dist/schema/state/sqlite/table-def.js.map +1 -0
- package/dist/schema/state/state.d.ts +3 -0
- package/dist/schema/state/state.d.ts.map +1 -0
- package/dist/schema/state/state.js +3 -0
- package/dist/schema/state/state.js.map +1 -0
- package/dist/schema/state.d.ts +3 -0
- package/dist/schema/state.d.ts.map +1 -0
- package/dist/schema/state.js +3 -0
- package/dist/schema/state.js.map +1 -0
- package/dist/schema/system-tables.d.ts +7 -433
- package/dist/schema/system-tables.d.ts.map +1 -1
- package/dist/schema/system-tables.js +1 -1
- package/dist/schema/system-tables.js.map +1 -1
- package/dist/schema/table-def.d.ts +2 -2
- package/dist/schema-management/migrations.d.ts +1 -1
- package/dist/schema-management/migrations.d.ts.map +1 -1
- package/dist/schema-management/migrations.js +14 -12
- package/dist/schema-management/migrations.js.map +1 -1
- package/dist/schema-management/validate-schema.d.ts +8 -0
- package/dist/schema-management/validate-schema.d.ts.map +1 -0
- package/dist/schema-management/validate-schema.js +39 -0
- package/dist/schema-management/validate-schema.js.map +1 -0
- package/dist/sql-queries/sql-queries.d.ts +1 -1
- package/dist/sql-queries/sql-queries.d.ts.map +1 -1
- package/dist/sql-queries/sql-query-builder.d.ts +1 -1
- package/dist/sql-queries/sql-query-builder.d.ts.map +1 -1
- package/dist/sql-queries/types.d.ts +1 -1
- package/dist/sql-queries/types.d.ts.map +1 -1
- package/dist/sync/ClientSessionSyncProcessor.d.ts +3 -3
- package/dist/sync/ClientSessionSyncProcessor.d.ts.map +1 -1
- package/dist/sync/ClientSessionSyncProcessor.js +6 -6
- package/dist/sync/ClientSessionSyncProcessor.js.map +1 -1
- package/dist/sync/next/test/event-fixtures.d.ts +7 -7
- package/dist/sync/syncstate.d.ts +4 -4
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +9 -3
- package/src/adapter-types.ts +4 -10
- package/src/devtools/devtools-messages-client-session.ts +1 -0
- package/src/devtools/devtools-messages-leader.ts +1 -1
- package/src/index.ts +3 -3
- package/src/leader-thread/LeaderSyncProcessor.ts +28 -30
- package/src/leader-thread/eventlog.ts +12 -17
- package/src/leader-thread/leader-worker-devtools.ts +15 -12
- package/src/leader-thread/make-leader-thread-layer.ts +15 -21
- package/src/leader-thread/{apply-event.ts → materialize-event.ts} +22 -28
- package/src/leader-thread/recreate-db.ts +9 -21
- package/src/leader-thread/types.ts +5 -5
- package/src/materializer-helper.ts +1 -1
- package/src/{rehydrate-from-eventlog.ts → rematerialize-from-eventlog.ts} +41 -38
- package/src/schema/EventDef.ts +1 -1
- package/src/schema/EventId.test.ts +1 -1
- package/src/schema/mod.ts +4 -4
- package/src/schema/schema.ts +18 -52
- package/src/schema/state/mod.ts +2 -0
- package/src/schema/{client-document-def.test.ts → state/sqlite/client-document-def.test.ts} +2 -2
- package/src/schema/{client-document-def.ts → state/sqlite/client-document-def.ts} +6 -6
- package/src/schema/{sqlite-state.ts → state/sqlite/mod.ts} +17 -6
- package/src/{query-builder → schema/state/sqlite/query-builder}/api.ts +21 -22
- package/src/{query-builder → schema/state/sqlite/query-builder}/astToSql.ts +3 -3
- package/src/{query-builder → schema/state/sqlite/query-builder}/impl.test.ts +1 -1
- package/src/{query-builder → schema/state/sqlite/query-builder}/impl.ts +3 -4
- package/src/schema/{schema-helpers.ts → state/sqlite/schema-helpers.ts} +1 -1
- package/src/schema/{system-tables.ts → state/sqlite/system-tables.ts} +6 -5
- package/src/schema/{table-def.ts → state/sqlite/table-def.ts} +2 -2
- package/src/schema-management/migrations.ts +17 -15
- package/src/sql-queries/sql-queries.ts +1 -1
- package/src/sql-queries/sql-query-builder.ts +1 -1
- package/src/sql-queries/types.ts +1 -1
- package/src/sync/ClientSessionSyncProcessor.ts +7 -7
- package/src/version.ts +1 -1
- package/src/schema/view.ts +0 -2
- package/tmp/pack.tgz +0 -0
- package/tsconfig.json +0 -12
- /package/src/schema/{db-schema → state/sqlite/db-schema}/ast/sqlite.ts +0 -0
- /package/src/schema/{db-schema → state/sqlite/db-schema}/ast/validate.ts +0 -0
- /package/src/schema/{db-schema → state/sqlite/db-schema}/dsl/__snapshots__/field-defs.test.ts.snap +0 -0
- /package/src/schema/{db-schema → state/sqlite/db-schema}/dsl/field-defs.test.ts +0 -0
- /package/src/schema/{db-schema → state/sqlite/db-schema}/dsl/field-defs.ts +0 -0
- /package/src/schema/{db-schema → state/sqlite/db-schema}/dsl/mod.ts +0 -0
- /package/src/schema/{db-schema → state/sqlite/db-schema}/hash.ts +0 -0
- /package/src/schema/{db-schema → state/sqlite/db-schema}/mod.ts +0 -0
- /package/src/{query-builder → schema/state/sqlite/query-builder}/mod.ts +0 -0
- /package/src/schema-management/{validate-mutation-defs.ts → validate-schema.ts} +0 -0
package/src/schema/schema.ts
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
import { isReadonlyArray, shouldNeverHappen } from '@livestore/utils'
|
2
2
|
|
3
3
|
import type { MigrationOptions } from '../adapter-types.js'
|
4
|
-
import { tableIsClientDocumentTable } from './client-document-def.js'
|
5
|
-
import type { SqliteDsl } from './db-schema/mod.js'
|
6
|
-
import { SqliteAst } from './db-schema/mod.js'
|
7
4
|
import type { EventDef, EventDefRecord, Materializer, RawSqlEvent } from './EventDef.js'
|
8
5
|
import { rawSqlEvent } from './EventDef.js'
|
9
|
-
import {
|
10
|
-
import type {
|
6
|
+
import { tableIsClientDocumentTable } from './state/sqlite/client-document-def.js'
|
7
|
+
import type { SqliteDsl } from './state/sqlite/db-schema/mod.js'
|
8
|
+
import { stateSystemTables } from './state/sqlite/system-tables.js'
|
9
|
+
import type { TableDef } from './state/sqlite/table-def.js'
|
11
10
|
|
12
11
|
export const LiveStoreSchemaSymbol = Symbol.for('livestore.LiveStoreSchema')
|
13
12
|
export type LiveStoreSchemaSymbol = typeof LiveStoreSchemaSymbol
|
@@ -16,27 +15,24 @@ export type LiveStoreSchema<
|
|
16
15
|
TDbSchema extends SqliteDsl.DbSchema = SqliteDsl.DbSchema,
|
17
16
|
TEventsDefRecord extends EventDefRecord = EventDefRecord,
|
18
17
|
> = {
|
19
|
-
readonly
|
18
|
+
readonly LiveStoreSchemaSymbol: LiveStoreSchemaSymbol
|
20
19
|
/** Only used on type-level */
|
21
20
|
readonly _DbSchemaType: TDbSchema
|
22
21
|
/** Only used on type-level */
|
23
22
|
readonly _EventDefMapType: TEventsDefRecord
|
24
23
|
|
25
|
-
// TODO remove in favour of `state`
|
26
|
-
readonly tables: Map<string, TableDef>
|
27
|
-
/** Compound hash of all table defs etc */
|
28
|
-
readonly hash: number
|
29
24
|
readonly state: State
|
30
|
-
|
31
25
|
readonly eventsDefsMap: Map<string, EventDef.AnyWithoutFn>
|
32
|
-
|
33
|
-
// readonly materializers: Map<string, Materializer>
|
34
|
-
|
35
|
-
migrationOptions: MigrationOptions
|
36
26
|
}
|
37
27
|
|
28
|
+
// TODO abstract this further away from sqlite/tables
|
38
29
|
export type State = {
|
39
|
-
readonly
|
30
|
+
readonly sqlite: {
|
31
|
+
readonly tables: Map<string, TableDef.Any>
|
32
|
+
readonly migrations: MigrationOptions
|
33
|
+
/** Compound hash of all table defs etc */
|
34
|
+
readonly hash: number
|
35
|
+
}
|
40
36
|
readonly materializers: Map<string, Materializer>
|
41
37
|
}
|
42
38
|
|
@@ -47,32 +43,12 @@ export type InputSchema = {
|
|
47
43
|
|
48
44
|
export const makeSchema = <TInputSchema extends InputSchema>(
|
49
45
|
/** Note when using the object-notation for tables/events, the object keys are ignored and not used as table/mutation names */
|
50
|
-
inputSchema: TInputSchema
|
51
|
-
/** "hard-reset" is currently the default strategy */
|
52
|
-
migrations?: MigrationOptions
|
53
|
-
},
|
46
|
+
inputSchema: TInputSchema,
|
54
47
|
): FromInputSchema.DeriveSchema<TInputSchema> => {
|
55
|
-
// const inputTables: ReadonlyArray<TableDef> = Array.isArray(inputSchema.tables)
|
56
|
-
// ? inputSchema.tables
|
57
|
-
// : Object.values(inputSchema.tables)
|
58
|
-
|
59
|
-
// const inputTables = []
|
60
|
-
|
61
|
-
// const tables = new Map<string, TableDef>()
|
62
|
-
|
63
|
-
// for (const tableDef of inputTables) {
|
64
|
-
// // TODO validate tables (e.g. index names are unique)
|
65
|
-
// if (tables.has(tableDef.sqliteDef.ast.name)) {
|
66
|
-
// shouldNeverHappen(`Duplicate table name: ${tableDef.sqliteDef.ast.name}. Please use unique names for tables.`)
|
67
|
-
// }
|
68
|
-
// tables.set(tableDef.sqliteDef.ast.name, tableDef)
|
69
|
-
// }
|
70
|
-
|
71
48
|
const state = inputSchema.state
|
72
|
-
const tables = inputSchema.state.tables
|
49
|
+
const tables = inputSchema.state.sqlite.tables
|
73
50
|
|
74
|
-
for (const tableDef of
|
75
|
-
// // @ts-expect-error TODO fix type level issue
|
51
|
+
for (const tableDef of stateSystemTables) {
|
76
52
|
tables.set(tableDef.sqliteDef.name, tableDef)
|
77
53
|
}
|
78
54
|
|
@@ -99,22 +75,12 @@ export const makeSchema = <TInputSchema extends InputSchema>(
|
|
99
75
|
}
|
100
76
|
}
|
101
77
|
|
102
|
-
const hash = SqliteAst.hash({
|
103
|
-
_tag: 'dbSchema',
|
104
|
-
tables: [...tables.values()].map((_) => _.sqliteDef.ast),
|
105
|
-
})
|
106
|
-
|
107
78
|
return {
|
108
|
-
|
79
|
+
LiveStoreSchemaSymbol,
|
109
80
|
_DbSchemaType: Symbol.for('livestore.DbSchemaType') as any,
|
110
81
|
_EventDefMapType: Symbol.for('livestore.EventDefMapType') as any,
|
111
|
-
// tables,
|
112
|
-
// events,
|
113
82
|
state,
|
114
|
-
tables: state.tables,
|
115
83
|
eventsDefsMap,
|
116
|
-
migrationOptions: inputSchema.migrations ?? { strategy: 'from-eventlog' },
|
117
|
-
hash,
|
118
84
|
} satisfies LiveStoreSchema
|
119
85
|
}
|
120
86
|
|
@@ -138,7 +104,7 @@ export const getEventDef = <TSchema extends LiveStoreSchema>(
|
|
138
104
|
|
139
105
|
export namespace FromInputSchema {
|
140
106
|
export type DeriveSchema<TInputSchema extends InputSchema> = LiveStoreSchema<
|
141
|
-
DbSchemaFromInputSchemaTables<TInputSchema['state']['tables']>,
|
107
|
+
DbSchemaFromInputSchemaTables<TInputSchema['state']['sqlite']['tables']>,
|
142
108
|
EventDefRecordFromInputSchemaEvents<TInputSchema['events']>
|
143
109
|
>
|
144
110
|
|
@@ -147,7 +113,7 @@ export namespace FromInputSchema {
|
|
147
113
|
* - array: we use the table name of each array item (= table definition) as the object key
|
148
114
|
* - object: we discard the keys of the input object and use the table name of each object value (= table definition) as the new object key
|
149
115
|
*/
|
150
|
-
type DbSchemaFromInputSchemaTables<TTables extends InputSchema['state']['tables']> =
|
116
|
+
type DbSchemaFromInputSchemaTables<TTables extends InputSchema['state']['sqlite']['tables']> =
|
151
117
|
TTables extends ReadonlyArray<TableDef>
|
152
118
|
? { [K in TTables[number] as K['sqliteDef']['name']]: K['sqliteDef'] }
|
153
119
|
: TTables extends Record<string, TableDef>
|
@@ -1,9 +1,9 @@
|
|
1
1
|
import { Schema } from '@livestore/utils/effect'
|
2
2
|
import { describe, expect, test } from 'vitest'
|
3
3
|
|
4
|
-
import { tables } from '
|
4
|
+
import { tables } from '../../../__tests__/fixture.js'
|
5
|
+
import type * as LiveStoreEvent from '../../LiveStoreEvent.js'
|
5
6
|
import { clientDocument, ClientDocumentTableDefSymbol } from './client-document-def.js'
|
6
|
-
import type * as LiveStoreEvent from './LiveStoreEvent.js'
|
7
7
|
|
8
8
|
const materializerContext = {
|
9
9
|
currentFacts: new Map(),
|
@@ -2,13 +2,13 @@ import { shouldNeverHappen } from '@livestore/utils'
|
|
2
2
|
import type { Option, Types } from '@livestore/utils/effect'
|
3
3
|
import { Schema, SchemaAST } from '@livestore/utils/effect'
|
4
4
|
|
5
|
-
import { SessionIdSymbol } from '
|
6
|
-
import
|
7
|
-
import {
|
8
|
-
import {
|
5
|
+
import { SessionIdSymbol } from '../../../adapter-types.js'
|
6
|
+
import { sql } from '../../../util.js'
|
7
|
+
import type { EventDef, Materializer } from '../../EventDef.js'
|
8
|
+
import { defineEvent, defineMaterializer } from '../../EventDef.js'
|
9
9
|
import { SqliteDsl } from './db-schema/mod.js'
|
10
|
-
import type {
|
11
|
-
import {
|
10
|
+
import type { QueryBuilder, QueryBuilderAst } from './query-builder/mod.js'
|
11
|
+
import { QueryBuilderAstSymbol, QueryBuilderTypeId } from './query-builder/mod.js'
|
12
12
|
import type { TableDef, TableDefBase } from './table-def.js'
|
13
13
|
import { table } from './table-def.js'
|
14
14
|
|
@@ -1,9 +1,11 @@
|
|
1
1
|
import { shouldNeverHappen } from '@livestore/utils'
|
2
2
|
|
3
|
+
import type { MigrationOptions } from '../../../adapter-types.js'
|
4
|
+
import { type Materializer, rawSqlEvent, rawSqlMaterializer } from '../../EventDef.js'
|
5
|
+
import type { State } from '../../schema.js'
|
3
6
|
import { ClientDocumentTableDefSymbol, tableIsClientDocumentTable } from './client-document-def.js'
|
4
|
-
import {
|
5
|
-
import
|
6
|
-
import { systemTables } from './system-tables.js'
|
7
|
+
import { SqliteAst } from './db-schema/mod.js'
|
8
|
+
import { stateSystemTables } from './system-tables.js'
|
7
9
|
import { type TableDef, type TableDefBase } from './table-def.js'
|
8
10
|
|
9
11
|
export * from './table-def.js'
|
@@ -14,7 +16,7 @@ export {
|
|
14
16
|
type ClientDocumentTableDef,
|
15
17
|
type ClientDocumentTableOptions,
|
16
18
|
} from './client-document-def.js'
|
17
|
-
export * from '
|
19
|
+
export * from '../../EventDef.js'
|
18
20
|
|
19
21
|
export const makeState = <TStateInput extends InputState>(inputSchema: TStateInput): State => {
|
20
22
|
const inputTables: ReadonlyArray<TableDef> = Array.isArray(inputSchema.tables)
|
@@ -32,7 +34,7 @@ export const makeState = <TStateInput extends InputState>(inputSchema: TStateInp
|
|
32
34
|
tables.set(sqliteDef.ast.name, tableDef)
|
33
35
|
}
|
34
36
|
|
35
|
-
for (const tableDef of
|
37
|
+
for (const tableDef of stateSystemTables) {
|
36
38
|
tables.set(tableDef.sqliteDef.name, tableDef)
|
37
39
|
}
|
38
40
|
|
@@ -53,10 +55,19 @@ export const makeState = <TStateInput extends InputState>(inputSchema: TStateInp
|
|
53
55
|
}
|
54
56
|
}
|
55
57
|
|
56
|
-
|
58
|
+
const hash = SqliteAst.hash({
|
59
|
+
_tag: 'dbSchema',
|
60
|
+
tables: [...tables.values()].map((_) => _.sqliteDef.ast),
|
61
|
+
})
|
62
|
+
|
63
|
+
return { sqlite: { tables, migrations: inputSchema.migrations ?? { strategy: 'auto' }, hash }, materializers }
|
57
64
|
}
|
58
65
|
|
59
66
|
export type InputState = {
|
60
67
|
readonly tables: Record<string, TableDefBase> | ReadonlyArray<TableDefBase>
|
61
68
|
readonly materializers: Record<string, Materializer<any>>
|
69
|
+
/**
|
70
|
+
* @default { strategy: 'auto' }
|
71
|
+
*/
|
72
|
+
readonly migrations?: MigrationOptions
|
62
73
|
}
|
@@ -1,11 +1,11 @@
|
|
1
1
|
import type { GetValForKey, SingleOrReadonlyArray } from '@livestore/utils'
|
2
2
|
import { type Option, Predicate, type Schema } from '@livestore/utils/effect'
|
3
3
|
|
4
|
-
import type { SessionIdSymbol } from '
|
5
|
-
import type {
|
6
|
-
import type {
|
7
|
-
import type {
|
8
|
-
import type {
|
4
|
+
import type { SessionIdSymbol } from '../../../../adapter-types.js'
|
5
|
+
import type { SqlValue } from '../../../../util.js'
|
6
|
+
import type { ClientDocumentTableDef } from '../client-document-def.js'
|
7
|
+
import type { SqliteDsl } from '../db-schema/mod.js'
|
8
|
+
import type { TableDefBase } from '../table-def.js'
|
9
9
|
|
10
10
|
export type QueryBuilderAst =
|
11
11
|
| QueryBuilderAst.SelectQuery
|
@@ -26,28 +26,28 @@ export namespace QueryBuilderAst {
|
|
26
26
|
readonly orderBy: ReadonlyArray<OrderBy>
|
27
27
|
readonly offset: Option.Option<number>
|
28
28
|
readonly limit: Option.Option<number>
|
29
|
-
readonly tableDef:
|
29
|
+
readonly tableDef: TableDefBase
|
30
30
|
readonly where: ReadonlyArray<QueryBuilderAst.Where>
|
31
31
|
readonly resultSchemaSingle: Schema.Schema<any>
|
32
32
|
}
|
33
33
|
|
34
34
|
export interface CountQuery {
|
35
35
|
readonly _tag: 'CountQuery'
|
36
|
-
readonly tableDef:
|
36
|
+
readonly tableDef: TableDefBase
|
37
37
|
readonly where: ReadonlyArray<QueryBuilderAst.Where>
|
38
38
|
readonly resultSchema: Schema.Schema<number, ReadonlyArray<{ count: number }>>
|
39
39
|
}
|
40
40
|
|
41
41
|
export interface RowQuery {
|
42
42
|
readonly _tag: 'RowQuery'
|
43
|
-
readonly tableDef:
|
43
|
+
readonly tableDef: ClientDocumentTableDef.Any
|
44
44
|
readonly id: string | SessionIdSymbol
|
45
45
|
readonly explicitDefaultValues: Record<string, unknown>
|
46
46
|
}
|
47
47
|
|
48
48
|
export interface InsertQuery {
|
49
49
|
readonly _tag: 'InsertQuery'
|
50
|
-
readonly tableDef:
|
50
|
+
readonly tableDef: TableDefBase
|
51
51
|
readonly values: Record<string, unknown>
|
52
52
|
readonly onConflict: OnConflict | undefined
|
53
53
|
readonly returning: string[] | undefined
|
@@ -68,7 +68,7 @@ export namespace QueryBuilderAst {
|
|
68
68
|
|
69
69
|
export interface UpdateQuery {
|
70
70
|
readonly _tag: 'UpdateQuery'
|
71
|
-
readonly tableDef:
|
71
|
+
readonly tableDef: TableDefBase
|
72
72
|
readonly values: Record<string, unknown>
|
73
73
|
readonly where: ReadonlyArray<QueryBuilderAst.Where>
|
74
74
|
readonly returning: string[] | undefined
|
@@ -77,7 +77,7 @@ export namespace QueryBuilderAst {
|
|
77
77
|
|
78
78
|
export interface DeleteQuery {
|
79
79
|
readonly _tag: 'DeleteQuery'
|
80
|
-
readonly tableDef:
|
80
|
+
readonly tableDef: TableDefBase
|
81
81
|
readonly where: ReadonlyArray<QueryBuilderAst.Where>
|
82
82
|
readonly returning: string[] | undefined
|
83
83
|
readonly resultSchema: Schema.Schema<any>
|
@@ -111,7 +111,7 @@ export const isQueryBuilder = (value: unknown): value is QueryBuilder<any, any,
|
|
111
111
|
|
112
112
|
export type QueryBuilder<
|
113
113
|
TResult,
|
114
|
-
TTableDef extends
|
114
|
+
TTableDef extends TableDefBase,
|
115
115
|
/** Used to gradually remove features from the API based on the query context */
|
116
116
|
TWithout extends QueryBuilder.ApiFeature = never,
|
117
117
|
> = {
|
@@ -151,7 +151,7 @@ export namespace QueryBuilder {
|
|
151
151
|
| 'returning'
|
152
152
|
| 'onConflict'
|
153
153
|
|
154
|
-
export type WhereParams<TTableDef extends
|
154
|
+
export type WhereParams<TTableDef extends TableDefBase> = Partial<{
|
155
155
|
[K in keyof TTableDef['sqliteDef']['columns']]:
|
156
156
|
| TTableDef['sqliteDef']['columns'][K]['schema']['Type']
|
157
157
|
| { op: QueryBuilder.WhereOps.SingleValue; value: TTableDef['sqliteDef']['columns'][K]['schema']['Type'] }
|
@@ -162,12 +162,12 @@ export namespace QueryBuilder {
|
|
162
162
|
| undefined
|
163
163
|
}>
|
164
164
|
|
165
|
-
export type OrderByParams<TTableDef extends
|
165
|
+
export type OrderByParams<TTableDef extends TableDefBase> = ReadonlyArray<{
|
166
166
|
col: keyof TTableDef['sqliteDef']['columns'] & string
|
167
167
|
direction: 'asc' | 'desc'
|
168
168
|
}>
|
169
169
|
|
170
|
-
export type ApiFull<TResult, TTableDef extends
|
170
|
+
export type ApiFull<TResult, TTableDef extends TableDefBase, TWithout extends ApiFeature> = {
|
171
171
|
/**
|
172
172
|
* `SELECT *` is the default
|
173
173
|
*
|
@@ -409,7 +409,7 @@ export namespace RowQuery {
|
|
409
409
|
}
|
410
410
|
|
411
411
|
// TODO get rid of this
|
412
|
-
export type RequiredColumnsOptions<TTableDef extends
|
412
|
+
export type RequiredColumnsOptions<TTableDef extends TableDefBase> = {
|
413
413
|
/**
|
414
414
|
* Values to be inserted into the row if it doesn't exist yet
|
415
415
|
*/
|
@@ -419,7 +419,7 @@ export namespace RowQuery {
|
|
419
419
|
>
|
420
420
|
}
|
421
421
|
|
422
|
-
export type Result<TTableDef extends
|
422
|
+
export type Result<TTableDef extends TableDefBase> = SqliteDsl.FromColumns.RowDecoded<
|
423
423
|
TTableDef['sqliteDef']['columns']
|
424
424
|
>
|
425
425
|
|
@@ -428,12 +428,11 @@ export namespace RowQuery {
|
|
428
428
|
'value'
|
429
429
|
>
|
430
430
|
|
431
|
-
export type ResultEncoded<TTableDef extends
|
432
|
-
TTableDef['
|
433
|
-
|
434
|
-
: SqliteDsl.FromColumns.RowEncoded<TTableDef['sqliteDef']['columns']>
|
431
|
+
export type ResultEncoded<TTableDef extends TableDefBase> = TTableDef['options']['isClientDocumentTable'] extends true
|
432
|
+
? GetValForKey<SqliteDsl.FromColumns.RowEncoded<TTableDef['sqliteDef']['columns']>, 'value'>
|
433
|
+
: SqliteDsl.FromColumns.RowEncoded<TTableDef['sqliteDef']['columns']>
|
435
434
|
|
436
|
-
export type GetIdColumnType<TTableDef extends
|
435
|
+
export type GetIdColumnType<TTableDef extends TableDefBase> =
|
437
436
|
TTableDef['sqliteDef']['columns']['id']['schema']['Type']
|
438
437
|
}
|
439
438
|
|
@@ -1,9 +1,9 @@
|
|
1
1
|
import { shouldNeverHappen } from '@livestore/utils'
|
2
2
|
import { Schema } from '@livestore/utils/effect'
|
3
3
|
|
4
|
-
import { SessionIdSymbol } from '
|
5
|
-
import type {
|
6
|
-
import type {
|
4
|
+
import { SessionIdSymbol } from '../../../../adapter-types.js'
|
5
|
+
import type { SqlValue } from '../../../../util.js'
|
6
|
+
import type { State } from '../../../mod.js'
|
7
7
|
import type { QueryBuilderAst } from './api.js'
|
8
8
|
|
9
9
|
// Helper functions for SQL generation
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { Schema } from '@livestore/utils/effect'
|
2
2
|
import { describe, expect, it } from 'vitest'
|
3
3
|
|
4
|
-
import { State } from '
|
4
|
+
import { State } from '../../../mod.js'
|
5
5
|
import type { QueryBuilder } from './api.js'
|
6
6
|
import { getResultSchema } from './impl.js'
|
7
7
|
|
@@ -1,12 +1,11 @@
|
|
1
1
|
import { casesHandled, shouldNeverHappen } from '@livestore/utils'
|
2
2
|
import { Match, Option, Predicate, Schema } from '@livestore/utils/effect'
|
3
3
|
|
4
|
-
import type {
|
4
|
+
import type { TableDefBase } from '../table-def.js'
|
5
5
|
import type { QueryBuilder, QueryBuilderAst } from './api.js'
|
6
6
|
import { QueryBuilderAstSymbol, QueryBuilderTypeId } from './api.js'
|
7
7
|
import { astToSql } from './astToSql.js'
|
8
|
-
|
9
|
-
export const makeQueryBuilder = <TResult, TTableDef extends State.SQLite.TableDefBase>(
|
8
|
+
export const makeQueryBuilder = <TResult, TTableDef extends TableDefBase>(
|
10
9
|
tableDef: TTableDef,
|
11
10
|
ast: QueryBuilderAst = emptyAst(tableDef),
|
12
11
|
): QueryBuilder<TResult, TTableDef, never> => {
|
@@ -262,7 +261,7 @@ export const makeQueryBuilder = <TResult, TTableDef extends State.SQLite.TableDe
|
|
262
261
|
} satisfies QueryBuilder<TResult, TTableDef>
|
263
262
|
}
|
264
263
|
|
265
|
-
const emptyAst = (tableDef:
|
264
|
+
const emptyAst = (tableDef: TableDefBase): QueryBuilderAst.SelectQuery => ({
|
266
265
|
_tag: 'SelectQuery',
|
267
266
|
columns: [],
|
268
267
|
pickFirst: false,
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { shouldNeverHappen } from '@livestore/utils'
|
2
2
|
import { pipe, ReadonlyRecord, Schema } from '@livestore/utils/effect'
|
3
3
|
|
4
|
-
import { SqliteDsl } from '
|
4
|
+
import { SqliteDsl } from './db-schema/mod.js'
|
5
5
|
import type { TableDef, TableDefBase } from './table-def.js'
|
6
6
|
|
7
7
|
export const getDefaultValuesEncoded = <TTableDef extends TableDef>(
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { Schema } from '@livestore/utils/effect'
|
2
2
|
|
3
|
+
import * as EventId from '../../EventId.js'
|
3
4
|
import { SqliteDsl } from './db-schema/mod.js'
|
4
|
-
import * as EventId from './EventId.js'
|
5
5
|
import { table } from './table-def.js'
|
6
6
|
|
7
7
|
/// Read model DB
|
@@ -66,17 +66,16 @@ export const leaderMergeCounterTable = table({
|
|
66
66
|
|
67
67
|
export type LeaderMergeCounterRow = typeof leaderMergeCounterTable.Type
|
68
68
|
|
69
|
-
export const
|
69
|
+
export const stateSystemTables = [
|
70
70
|
schemaMetaTable,
|
71
71
|
schemaEventDefsMetaTable,
|
72
72
|
sessionChangesetMetaTable,
|
73
73
|
leaderMergeCounterTable,
|
74
74
|
]
|
75
75
|
|
76
|
-
|
76
|
+
export const isStateSystemTable = (tableName: string) => stateSystemTables.some((_) => _.sqliteDef.name === tableName)
|
77
77
|
|
78
|
-
|
79
|
-
export type SyncStatus = typeof SyncStatus.Type
|
78
|
+
/// Eventlog DB
|
80
79
|
|
81
80
|
export const EVENTLOG_META_TABLE = 'eventlog'
|
82
81
|
|
@@ -113,3 +112,5 @@ export const syncStatusTable = table({
|
|
113
112
|
})
|
114
113
|
|
115
114
|
export type SyncStatusRow = typeof syncStatusTable.Type
|
115
|
+
|
116
|
+
export const eventlogSystemTables = [eventlogMetaTable, syncStatusTable]
|
@@ -1,9 +1,9 @@
|
|
1
1
|
import { type Nullable } from '@livestore/utils'
|
2
2
|
import type { Schema, Types } from '@livestore/utils/effect'
|
3
3
|
|
4
|
-
import type { QueryBuilder } from '../query-builder/mod.js'
|
5
|
-
import { makeQueryBuilder, QueryBuilderAstSymbol, QueryBuilderTypeId } from '../query-builder/mod.js'
|
6
4
|
import { SqliteDsl } from './db-schema/mod.js'
|
5
|
+
import type { QueryBuilder } from './query-builder/mod.js'
|
6
|
+
import { makeQueryBuilder, QueryBuilderAstSymbol, QueryBuilderTypeId } from './query-builder/mod.js'
|
7
7
|
|
8
8
|
export const { blob, boolean, column, datetime, integer, isColumnDefinition, json, real, text } = SqliteDsl
|
9
9
|
|
@@ -2,20 +2,20 @@ import { memoizeByStringifyArgs } from '@livestore/utils'
|
|
2
2
|
import { Effect, Schema as EffectSchema } from '@livestore/utils/effect'
|
3
3
|
|
4
4
|
import type { MigrationsReport, MigrationsReportEntry, SqliteDb, UnexpectedError } from '../adapter-types.js'
|
5
|
-
import { SqliteAst, SqliteDsl } from '../schema/db-schema/mod.js'
|
6
5
|
import type { LiveStoreSchema } from '../schema/mod.js'
|
7
|
-
import
|
6
|
+
import { SqliteAst, SqliteDsl } from '../schema/state/sqlite/db-schema/mod.js'
|
7
|
+
import type { SchemaEventDefsMetaRow, SchemaMetaRow } from '../schema/state/sqlite/system-tables.js'
|
8
8
|
import {
|
9
|
+
isStateSystemTable,
|
9
10
|
SCHEMA_EVENT_DEFS_META_TABLE,
|
10
11
|
SCHEMA_META_TABLE,
|
11
12
|
schemaEventDefsMetaTable,
|
12
|
-
|
13
|
-
|
14
|
-
} from '../schema/system-tables.js'
|
13
|
+
stateSystemTables,
|
14
|
+
} from '../schema/state/sqlite/system-tables.js'
|
15
15
|
import { sql } from '../util.js'
|
16
16
|
import type { SchemaManager } from './common.js'
|
17
17
|
import { dbExecute, dbSelect } from './common.js'
|
18
|
-
import { validateSchema } from './validate-
|
18
|
+
import { validateSchema } from './validate-schema.js'
|
19
19
|
|
20
20
|
const getMemoizedTimestamp = memoizeByStringifyArgs(() => new Date().toISOString())
|
21
21
|
|
@@ -55,11 +55,13 @@ export const migrateDb = ({
|
|
55
55
|
onProgress?: (opts: { done: number; total: number }) => Effect.Effect<void>
|
56
56
|
}): Effect.Effect<MigrationsReport, UnexpectedError> =>
|
57
57
|
Effect.gen(function* () {
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
58
|
+
for (const tableDef of stateSystemTables) {
|
59
|
+
yield* migrateTable({
|
60
|
+
db,
|
61
|
+
tableAst: tableDef.sqliteDef.ast,
|
62
|
+
behaviour: 'create-if-not-exists',
|
63
|
+
})
|
64
|
+
}
|
63
65
|
|
64
66
|
// TODO enforce that migrating tables isn't allowed once the store is running
|
65
67
|
|
@@ -72,11 +74,11 @@ export const migrateDb = ({
|
|
72
74
|
schemaMetaRows.map(({ tableName, schemaHash }) => [tableName, schemaHash]),
|
73
75
|
)
|
74
76
|
|
75
|
-
const tableDefs =
|
77
|
+
const tableDefs = [
|
76
78
|
// NOTE it's important the `SCHEMA_META_TABLE` comes first since we're writing to it below
|
77
|
-
...
|
78
|
-
...Array.from(schema.tables.values()).filter((_) => _.sqliteDef.name
|
79
|
-
]
|
79
|
+
...stateSystemTables,
|
80
|
+
...Array.from(schema.state.sqlite.tables.values()).filter((_) => !isStateSystemTable(_.sqliteDef.name)),
|
81
|
+
]
|
80
82
|
|
81
83
|
const tablesToMigrate = new Set<{ tableAst: SqliteAst.Table; schemaHash: number }>()
|
82
84
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { shouldNeverHappen } from '@livestore/utils'
|
2
2
|
import { pipe, ReadonlyArray, Schema, TreeFormatter } from '@livestore/utils/effect'
|
3
3
|
|
4
|
-
import type { SqliteDsl } from '../schema/db-schema/mod.js'
|
4
|
+
import type { SqliteDsl } from '../schema/state/sqlite/db-schema/mod.js'
|
5
5
|
import { sql } from '../util.js'
|
6
6
|
import { objectEntries } from './misc.js'
|
7
7
|
import * as ClientTypes from './types.js'
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import type { SqliteDsl } from '../schema/db-schema/mod.js'
|
1
|
+
import type { SqliteDsl } from '../schema/state/sqlite/db-schema/mod.js'
|
2
2
|
import type { BindValues } from './sql-queries.js'
|
3
3
|
import * as SqlQueries from './sql-queries.js'
|
4
4
|
import type * as ClientTypes from './types.js'
|
package/src/sql-queries/types.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import type { Prettify } from '@livestore/utils'
|
2
2
|
import type { Schema } from '@livestore/utils/effect'
|
3
3
|
|
4
|
-
import type { SqliteDsl } from '../schema/db-schema/mod.js'
|
4
|
+
import type { SqliteDsl } from '../schema/state/sqlite/db-schema/mod.js'
|
5
5
|
|
6
6
|
export type DecodedValuesForTableAll<TSchema extends SqliteDsl.DbSchema, TTableName extends keyof TSchema> = {
|
7
7
|
[K in keyof GetColumns<TSchema, TTableName>]: Schema.Schema.Type<GetColumn<TSchema, TTableName, K>['schema']>
|
@@ -7,7 +7,7 @@ import * as otel from '@opentelemetry/api'
|
|
7
7
|
import type { ClientSession, UnexpectedError } from '../adapter-types.js'
|
8
8
|
import * as EventId from '../schema/EventId.js'
|
9
9
|
import * as LiveStoreEvent from '../schema/LiveStoreEvent.js'
|
10
|
-
import { getEventDef,
|
10
|
+
import { getEventDef, type LiveStoreSchema, SystemTables } from '../schema/mod.js'
|
11
11
|
import { sql } from '../util.js'
|
12
12
|
import * as SyncState from './syncstate.js'
|
13
13
|
|
@@ -17,7 +17,7 @@ import * as SyncState from './syncstate.js'
|
|
17
17
|
* - If there was a race condition (i.e. the leader and client session have both advacned),
|
18
18
|
* we'll need to rebase the local pending events on top of the leader's head.
|
19
19
|
* - The goal is to never block the UI, so we'll interrupt rebasing if a new events is pushed by the client session.
|
20
|
-
* - We also want to avoid "backwards-jumping" in the UI, so we'll transactionally apply
|
20
|
+
* - We also want to avoid "backwards-jumping" in the UI, so we'll transactionally apply state changes during a rebase.
|
21
21
|
* - We might need to make the rebase behaviour configurable e.g. to let users manually trigger a rebase
|
22
22
|
*
|
23
23
|
* Longer term we should evalutate whether we can unify the ClientSessionSyncProcessor with the LeaderSyncProcessor.
|
@@ -26,7 +26,7 @@ export const makeClientSessionSyncProcessor = ({
|
|
26
26
|
schema,
|
27
27
|
clientSession,
|
28
28
|
runtime,
|
29
|
-
|
29
|
+
materializeEvent,
|
30
30
|
rollback,
|
31
31
|
refreshTables,
|
32
32
|
span,
|
@@ -36,7 +36,7 @@ export const makeClientSessionSyncProcessor = ({
|
|
36
36
|
schema: LiveStoreSchema
|
37
37
|
clientSession: ClientSession
|
38
38
|
runtime: Runtime.Runtime<Scope.Scope>
|
39
|
-
|
39
|
+
materializeEvent: (
|
40
40
|
eventDecoded: LiveStoreEvent.PartialAnyDecoded,
|
41
41
|
options: { otelContext: otel.Context; withChangeset: boolean },
|
42
42
|
) => {
|
@@ -120,7 +120,7 @@ export const makeClientSessionSyncProcessor = ({
|
|
120
120
|
for (const event of mergeResult.newEvents) {
|
121
121
|
// TODO avoid encoding and decoding here again
|
122
122
|
const decodedEventDef = Schema.decodeSync(eventSchema)(event)
|
123
|
-
const res =
|
123
|
+
const res = materializeEvent(decodedEventDef, { otelContext, withChangeset: true })
|
124
124
|
for (const table of res.writeTables) {
|
125
125
|
writeTables.add(table)
|
126
126
|
}
|
@@ -173,7 +173,7 @@ export const makeClientSessionSyncProcessor = ({
|
|
173
173
|
|
174
174
|
const getMergeCounter = () =>
|
175
175
|
clientSession.sqliteDb.select<{ mergeCounter: number }>(
|
176
|
-
sql`SELECT mergeCounter FROM ${LEADER_MERGE_COUNTER_TABLE} WHERE id = 0`,
|
176
|
+
sql`SELECT mergeCounter FROM ${SystemTables.LEADER_MERGE_COUNTER_TABLE} WHERE id = 0`,
|
177
177
|
)[0]?.mergeCounter ?? 0
|
178
178
|
|
179
179
|
// NOTE We need to lazily call `.pull` as we want the cursor to be updated
|
@@ -261,7 +261,7 @@ export const makeClientSessionSyncProcessor = ({
|
|
261
261
|
for (const event of mergeResult.newEvents) {
|
262
262
|
// TODO apply changeset if available (will require tracking of write tables as well)
|
263
263
|
const decodedEventDef = Schema.decodeSync(eventSchema)(event)
|
264
|
-
const res =
|
264
|
+
const res = materializeEvent(decodedEventDef, { otelContext, withChangeset: true })
|
265
265
|
for (const table of res.writeTables) {
|
266
266
|
writeTables.add(table)
|
267
267
|
}
|
package/src/version.ts
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
// import packageJson from '../package.json' with { type: 'json' }
|
3
3
|
// export const liveStoreVersion = packageJson.version
|
4
4
|
|
5
|
-
export const liveStoreVersion = '0.3.0-dev.
|
5
|
+
export const liveStoreVersion = '0.3.0-dev.34' as const
|
6
6
|
|
7
7
|
/**
|
8
8
|
* This version number is incremented whenever the internal storage format changes in a breaking way.
|
package/src/schema/view.ts
DELETED
package/tmp/pack.tgz
DELETED
Binary file
|
package/tsconfig.json
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"extends": "../../../tsconfig.base.json",
|
3
|
-
"compilerOptions": {
|
4
|
-
"lib": ["ES2023"], // Needed for `Array.toSorted`
|
5
|
-
"outDir": "./dist",
|
6
|
-
"rootDir": "./src",
|
7
|
-
"resolveJsonModule": true,
|
8
|
-
"tsBuildInfoFile": "./dist/.tsbuildinfo"
|
9
|
-
},
|
10
|
-
"include": ["./src"],
|
11
|
-
"references": [{ "path": "../utils" }]
|
12
|
-
}
|
File without changes
|
File without changes
|