@livestore/common 0.3.0-dev.33 → 0.3.0-dev.36

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.
Files changed (243) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/adapter-types.d.ts +5 -9
  3. package/dist/adapter-types.d.ts.map +1 -1
  4. package/dist/adapter-types.js.map +1 -1
  5. package/dist/devtools/devtools-messages-client-session.d.ts +30 -29
  6. package/dist/devtools/devtools-messages-client-session.d.ts.map +1 -1
  7. package/dist/devtools/devtools-messages-client-session.js +1 -0
  8. package/dist/devtools/devtools-messages-client-session.js.map +1 -1
  9. package/dist/devtools/devtools-messages-common.d.ts +6 -6
  10. package/dist/devtools/devtools-messages-leader.d.ts +25 -25
  11. package/dist/devtools/devtools-messages-leader.js +1 -1
  12. package/dist/devtools/devtools-messages-leader.js.map +1 -1
  13. package/dist/devtools/devtools-sessioninfo.d.ts +2 -0
  14. package/dist/devtools/devtools-sessioninfo.d.ts.map +1 -1
  15. package/dist/devtools/devtools-sessioninfo.js +1 -0
  16. package/dist/devtools/devtools-sessioninfo.js.map +1 -1
  17. package/dist/index.d.ts +3 -3
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +3 -3
  20. package/dist/index.js.map +1 -1
  21. package/dist/leader-thread/LeaderSyncProcessor.d.ts +4 -4
  22. package/dist/leader-thread/LeaderSyncProcessor.d.ts.map +1 -1
  23. package/dist/leader-thread/LeaderSyncProcessor.js +21 -17
  24. package/dist/leader-thread/LeaderSyncProcessor.js.map +1 -1
  25. package/dist/leader-thread/apply-event.d.ts +4 -4
  26. package/dist/leader-thread/apply-event.d.ts.map +1 -1
  27. package/dist/leader-thread/apply-event.js +9 -9
  28. package/dist/leader-thread/apply-event.js.map +1 -1
  29. package/dist/leader-thread/eventlog.d.ts.map +1 -1
  30. package/dist/leader-thread/eventlog.js +11 -15
  31. package/dist/leader-thread/eventlog.js.map +1 -1
  32. package/dist/leader-thread/leader-worker-devtools.d.ts +1 -1
  33. package/dist/leader-thread/leader-worker-devtools.js +13 -12
  34. package/dist/leader-thread/leader-worker-devtools.js.map +1 -1
  35. package/dist/leader-thread/make-leader-thread-layer.d.ts +2 -2
  36. package/dist/leader-thread/make-leader-thread-layer.d.ts.map +1 -1
  37. package/dist/leader-thread/make-leader-thread-layer.js +11 -18
  38. package/dist/leader-thread/make-leader-thread-layer.js.map +1 -1
  39. package/dist/leader-thread/materialize-event.d.ts +16 -0
  40. package/dist/leader-thread/materialize-event.d.ts.map +1 -0
  41. package/dist/leader-thread/materialize-event.js +103 -0
  42. package/dist/leader-thread/materialize-event.js.map +1 -0
  43. package/dist/leader-thread/recreate-db.d.ts.map +1 -1
  44. package/dist/leader-thread/recreate-db.js +9 -17
  45. package/dist/leader-thread/recreate-db.js.map +1 -1
  46. package/dist/leader-thread/types.d.ts +5 -5
  47. package/dist/leader-thread/types.d.ts.map +1 -1
  48. package/dist/materializer-helper.d.ts.map +1 -1
  49. package/dist/materializer-helper.js +1 -1
  50. package/dist/materializer-helper.js.map +1 -1
  51. package/dist/query-builder/api.d.ts +4 -4
  52. package/dist/query-builder/api.d.ts.map +1 -1
  53. package/dist/query-builder/impl.d.ts +2 -2
  54. package/dist/query-builder/impl.test.d.ts +5 -5
  55. package/dist/query-builder/mod.d.ts +2 -2
  56. package/dist/rehydrate-from-eventlog.d.ts +1 -1
  57. package/dist/rehydrate-from-eventlog.d.ts.map +1 -1
  58. package/dist/rehydrate-from-eventlog.js +6 -7
  59. package/dist/rehydrate-from-eventlog.js.map +1 -1
  60. package/dist/rematerialize-from-eventlog.d.ts +14 -0
  61. package/dist/rematerialize-from-eventlog.d.ts.map +1 -0
  62. package/dist/rematerialize-from-eventlog.js +64 -0
  63. package/dist/rematerialize-from-eventlog.js.map +1 -0
  64. package/dist/schema/EventDef.d.ts +3 -3
  65. package/dist/schema/EventDef.d.ts.map +1 -1
  66. package/dist/schema/EventId.test.js +1 -1
  67. package/dist/schema/EventId.test.js.map +1 -1
  68. package/dist/schema/client-document-def.d.ts +2 -2
  69. package/dist/schema/db-schema/dsl/mod.d.ts +3 -3
  70. package/dist/schema/db-schema/mod.d.ts +2 -2
  71. package/dist/schema/mod.d.ts +4 -4
  72. package/dist/schema/mod.d.ts.map +1 -1
  73. package/dist/schema/mod.js +4 -4
  74. package/dist/schema/mod.js.map +1 -1
  75. package/dist/schema/schema-helpers.d.ts +1 -1
  76. package/dist/schema/schema.d.ts +25 -14
  77. package/dist/schema/schema.d.ts.map +1 -1
  78. package/dist/schema/schema.js +8 -28
  79. package/dist/schema/schema.js.map +1 -1
  80. package/dist/schema/state/mod.d.ts +3 -0
  81. package/dist/schema/state/mod.d.ts.map +1 -0
  82. package/dist/schema/state/mod.js +3 -0
  83. package/dist/schema/state/mod.js.map +1 -0
  84. package/dist/schema/state/sqlite/client-document-def.d.ts +223 -0
  85. package/dist/schema/state/sqlite/client-document-def.d.ts.map +1 -0
  86. package/dist/schema/state/sqlite/client-document-def.js +170 -0
  87. package/dist/schema/state/sqlite/client-document-def.js.map +1 -0
  88. package/dist/schema/state/sqlite/client-document-def.test.d.ts +2 -0
  89. package/dist/schema/state/sqlite/client-document-def.test.d.ts.map +1 -0
  90. package/dist/schema/state/sqlite/client-document-def.test.js +201 -0
  91. package/dist/schema/state/sqlite/client-document-def.test.js.map +1 -0
  92. package/dist/schema/state/sqlite/db-schema/ast/sqlite.d.ts +69 -0
  93. package/dist/schema/state/sqlite/db-schema/ast/sqlite.d.ts.map +1 -0
  94. package/dist/schema/state/sqlite/db-schema/ast/sqlite.js +71 -0
  95. package/dist/schema/state/sqlite/db-schema/ast/sqlite.js.map +1 -0
  96. package/dist/schema/state/sqlite/db-schema/ast/validate.d.ts +3 -0
  97. package/dist/schema/state/sqlite/db-schema/ast/validate.d.ts.map +1 -0
  98. package/dist/schema/state/sqlite/db-schema/ast/validate.js +12 -0
  99. package/dist/schema/state/sqlite/db-schema/ast/validate.js.map +1 -0
  100. package/dist/schema/state/sqlite/db-schema/dsl/field-defs.d.ts +90 -0
  101. package/dist/schema/state/sqlite/db-schema/dsl/field-defs.d.ts.map +1 -0
  102. package/dist/schema/state/sqlite/db-schema/dsl/field-defs.js +87 -0
  103. package/dist/schema/state/sqlite/db-schema/dsl/field-defs.js.map +1 -0
  104. package/dist/schema/state/sqlite/db-schema/dsl/field-defs.test.d.ts +2 -0
  105. package/dist/schema/state/sqlite/db-schema/dsl/field-defs.test.d.ts.map +1 -0
  106. package/dist/schema/state/sqlite/db-schema/dsl/field-defs.test.js +29 -0
  107. package/dist/schema/state/sqlite/db-schema/dsl/field-defs.test.js.map +1 -0
  108. package/dist/schema/state/sqlite/db-schema/dsl/mod.d.ts +90 -0
  109. package/dist/schema/state/sqlite/db-schema/dsl/mod.d.ts.map +1 -0
  110. package/dist/schema/state/sqlite/db-schema/dsl/mod.js +41 -0
  111. package/dist/schema/state/sqlite/db-schema/dsl/mod.js.map +1 -0
  112. package/dist/schema/state/sqlite/db-schema/hash.d.ts +2 -0
  113. package/dist/schema/state/sqlite/db-schema/hash.d.ts.map +1 -0
  114. package/dist/schema/state/sqlite/db-schema/hash.js +14 -0
  115. package/dist/schema/state/sqlite/db-schema/hash.js.map +1 -0
  116. package/dist/schema/state/sqlite/db-schema/mod.d.ts +3 -0
  117. package/dist/schema/state/sqlite/db-schema/mod.d.ts.map +1 -0
  118. package/dist/schema/state/sqlite/db-schema/mod.js +3 -0
  119. package/dist/schema/state/sqlite/db-schema/mod.js.map +1 -0
  120. package/dist/schema/state/sqlite/mod.d.ts +17 -0
  121. package/dist/schema/state/sqlite/mod.d.ts.map +1 -0
  122. package/dist/schema/state/sqlite/mod.js +41 -0
  123. package/dist/schema/state/sqlite/mod.js.map +1 -0
  124. package/dist/schema/state/sqlite/query-builder/api.d.ts +293 -0
  125. package/dist/schema/state/sqlite/query-builder/api.d.ts.map +1 -0
  126. package/dist/schema/state/sqlite/query-builder/api.js +6 -0
  127. package/dist/schema/state/sqlite/query-builder/api.js.map +1 -0
  128. package/dist/schema/state/sqlite/query-builder/astToSql.d.ts +7 -0
  129. package/dist/schema/state/sqlite/query-builder/astToSql.d.ts.map +1 -0
  130. package/dist/schema/state/sqlite/query-builder/astToSql.js +190 -0
  131. package/dist/schema/state/sqlite/query-builder/astToSql.js.map +1 -0
  132. package/dist/schema/state/sqlite/query-builder/impl.d.ts +7 -0
  133. package/dist/schema/state/sqlite/query-builder/impl.d.ts.map +1 -0
  134. package/dist/schema/state/sqlite/query-builder/impl.js +286 -0
  135. package/dist/schema/state/sqlite/query-builder/impl.js.map +1 -0
  136. package/dist/schema/state/sqlite/query-builder/impl.test.d.ts +87 -0
  137. package/dist/schema/state/sqlite/query-builder/impl.test.d.ts.map +1 -0
  138. package/dist/schema/state/sqlite/query-builder/impl.test.js +554 -0
  139. package/dist/schema/state/sqlite/query-builder/impl.test.js.map +1 -0
  140. package/dist/schema/state/sqlite/query-builder/mod.d.ts +17 -0
  141. package/dist/schema/state/sqlite/query-builder/mod.d.ts.map +1 -0
  142. package/dist/schema/state/sqlite/query-builder/mod.js +17 -0
  143. package/dist/schema/state/sqlite/query-builder/mod.js.map +1 -0
  144. package/dist/schema/state/sqlite/schema-helpers.d.ts +4 -0
  145. package/dist/schema/state/sqlite/schema-helpers.d.ts.map +1 -0
  146. package/dist/schema/state/sqlite/schema-helpers.js +30 -0
  147. package/dist/schema/state/sqlite/schema-helpers.js.map +1 -0
  148. package/dist/schema/state/sqlite/sqlite-state.d.ts +12 -0
  149. package/dist/schema/state/sqlite/sqlite-state.d.ts.map +1 -0
  150. package/dist/schema/state/sqlite/sqlite-state.js +36 -0
  151. package/dist/schema/state/sqlite/sqlite-state.js.map +1 -0
  152. package/dist/schema/state/sqlite/system-tables.d.ts +574 -0
  153. package/dist/schema/state/sqlite/system-tables.d.ts.map +1 -0
  154. package/dist/schema/state/sqlite/system-tables.js +87 -0
  155. package/dist/schema/state/sqlite/system-tables.js.map +1 -0
  156. package/dist/schema/state/sqlite/table-def.d.ts +84 -0
  157. package/dist/schema/state/sqlite/table-def.d.ts.map +1 -0
  158. package/dist/schema/state/sqlite/table-def.js +36 -0
  159. package/dist/schema/state/sqlite/table-def.js.map +1 -0
  160. package/dist/schema/state/state.d.ts +3 -0
  161. package/dist/schema/state/state.d.ts.map +1 -0
  162. package/dist/schema/state/state.js +3 -0
  163. package/dist/schema/state/state.js.map +1 -0
  164. package/dist/schema/state.d.ts +3 -0
  165. package/dist/schema/state.d.ts.map +1 -0
  166. package/dist/schema/state.js +3 -0
  167. package/dist/schema/state.js.map +1 -0
  168. package/dist/schema/system-tables.d.ts +7 -433
  169. package/dist/schema/system-tables.d.ts.map +1 -1
  170. package/dist/schema/system-tables.js +1 -1
  171. package/dist/schema/system-tables.js.map +1 -1
  172. package/dist/schema/table-def.d.ts +2 -2
  173. package/dist/schema-management/migrations.d.ts +1 -1
  174. package/dist/schema-management/migrations.d.ts.map +1 -1
  175. package/dist/schema-management/migrations.js +14 -12
  176. package/dist/schema-management/migrations.js.map +1 -1
  177. package/dist/schema-management/validate-schema.d.ts +8 -0
  178. package/dist/schema-management/validate-schema.d.ts.map +1 -0
  179. package/dist/schema-management/validate-schema.js +39 -0
  180. package/dist/schema-management/validate-schema.js.map +1 -0
  181. package/dist/sql-queries/sql-queries.d.ts +1 -1
  182. package/dist/sql-queries/sql-queries.d.ts.map +1 -1
  183. package/dist/sql-queries/sql-query-builder.d.ts +1 -1
  184. package/dist/sql-queries/sql-query-builder.d.ts.map +1 -1
  185. package/dist/sql-queries/types.d.ts +1 -1
  186. package/dist/sql-queries/types.d.ts.map +1 -1
  187. package/dist/sync/ClientSessionSyncProcessor.d.ts +3 -3
  188. package/dist/sync/ClientSessionSyncProcessor.d.ts.map +1 -1
  189. package/dist/sync/ClientSessionSyncProcessor.js +6 -6
  190. package/dist/sync/ClientSessionSyncProcessor.js.map +1 -1
  191. package/dist/sync/next/test/event-fixtures.d.ts +7 -7
  192. package/dist/sync/syncstate.d.ts +4 -4
  193. package/dist/version.d.ts +1 -1
  194. package/dist/version.js +1 -1
  195. package/package.json +9 -3
  196. package/src/adapter-types.ts +4 -10
  197. package/src/devtools/devtools-messages-client-session.ts +1 -0
  198. package/src/devtools/devtools-messages-leader.ts +1 -1
  199. package/src/devtools/devtools-sessioninfo.ts +1 -0
  200. package/src/index.ts +3 -3
  201. package/src/leader-thread/LeaderSyncProcessor.ts +28 -30
  202. package/src/leader-thread/eventlog.ts +12 -17
  203. package/src/leader-thread/leader-worker-devtools.ts +15 -12
  204. package/src/leader-thread/make-leader-thread-layer.ts +15 -21
  205. package/src/leader-thread/{apply-event.ts → materialize-event.ts} +22 -28
  206. package/src/leader-thread/recreate-db.ts +9 -21
  207. package/src/leader-thread/types.ts +5 -5
  208. package/src/materializer-helper.ts +1 -1
  209. package/src/{rehydrate-from-eventlog.ts → rematerialize-from-eventlog.ts} +41 -38
  210. package/src/schema/EventDef.ts +1 -1
  211. package/src/schema/EventId.test.ts +1 -1
  212. package/src/schema/mod.ts +4 -4
  213. package/src/schema/schema.ts +34 -52
  214. package/src/schema/state/mod.ts +2 -0
  215. package/src/schema/{client-document-def.test.ts → state/sqlite/client-document-def.test.ts} +2 -2
  216. package/src/schema/{client-document-def.ts → state/sqlite/client-document-def.ts} +6 -6
  217. package/src/schema/{sqlite-state.ts → state/sqlite/mod.ts} +17 -6
  218. package/src/{query-builder → schema/state/sqlite/query-builder}/api.ts +21 -22
  219. package/src/{query-builder → schema/state/sqlite/query-builder}/astToSql.ts +3 -3
  220. package/src/{query-builder → schema/state/sqlite/query-builder}/impl.test.ts +1 -1
  221. package/src/{query-builder → schema/state/sqlite/query-builder}/impl.ts +3 -4
  222. package/src/schema/{schema-helpers.ts → state/sqlite/schema-helpers.ts} +1 -1
  223. package/src/schema/{system-tables.ts → state/sqlite/system-tables.ts} +6 -5
  224. package/src/schema/{table-def.ts → state/sqlite/table-def.ts} +2 -2
  225. package/src/schema-management/migrations.ts +17 -15
  226. package/src/sql-queries/sql-queries.ts +1 -1
  227. package/src/sql-queries/sql-query-builder.ts +1 -1
  228. package/src/sql-queries/types.ts +1 -1
  229. package/src/sync/ClientSessionSyncProcessor.ts +7 -7
  230. package/src/version.ts +1 -1
  231. package/src/schema/view.ts +0 -2
  232. package/tmp/pack.tgz +0 -0
  233. package/tsconfig.json +0 -12
  234. /package/src/schema/{db-schema → state/sqlite/db-schema}/ast/sqlite.ts +0 -0
  235. /package/src/schema/{db-schema → state/sqlite/db-schema}/ast/validate.ts +0 -0
  236. /package/src/schema/{db-schema → state/sqlite/db-schema}/dsl/__snapshots__/field-defs.test.ts.snap +0 -0
  237. /package/src/schema/{db-schema → state/sqlite/db-schema}/dsl/field-defs.test.ts +0 -0
  238. /package/src/schema/{db-schema → state/sqlite/db-schema}/dsl/field-defs.ts +0 -0
  239. /package/src/schema/{db-schema → state/sqlite/db-schema}/dsl/mod.ts +0 -0
  240. /package/src/schema/{db-schema → state/sqlite/db-schema}/hash.ts +0 -0
  241. /package/src/schema/{db-schema → state/sqlite/db-schema}/mod.ts +0 -0
  242. /package/src/{query-builder → schema/state/sqlite/query-builder}/mod.ts +0 -0
  243. /package/src/schema-management/{validate-mutation-defs.ts → validate-schema.ts} +0 -0
@@ -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 { systemTables } from './system-tables.js'
10
- import type { TableDef } from './table-def.js'
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,63 +15,53 @@ export type LiveStoreSchema<
16
15
  TDbSchema extends SqliteDsl.DbSchema = SqliteDsl.DbSchema,
17
16
  TEventsDefRecord extends EventDefRecord = EventDefRecord,
18
17
  > = {
19
- readonly _Type: LiveStoreSchemaSymbol
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
26
+ readonly devtools: {
27
+ /** @default 'default' */
28
+ readonly alias: string
29
+ }
36
30
  }
37
31
 
32
+ // TODO abstract this further away from sqlite/tables
38
33
  export type State = {
39
- readonly tables: Map<string, TableDef.Any>
34
+ readonly sqlite: {
35
+ readonly tables: Map<string, TableDef.Any>
36
+ readonly migrations: MigrationOptions
37
+ /** Compound hash of all table defs etc */
38
+ readonly hash: number
39
+ }
40
40
  readonly materializers: Map<string, Materializer>
41
41
  }
42
42
 
43
43
  export type InputSchema = {
44
44
  readonly events: ReadonlyArray<EventDef.AnyWithoutFn> | Record<string, EventDef.AnyWithoutFn>
45
45
  readonly state: State
46
+ readonly devtools?: {
47
+ /**
48
+ * This alias value is used to disambiguate between multiple schemas in the devtools.
49
+ * Only needed when an app uses multiple schemas.
50
+ *
51
+ * @default 'default'
52
+ */
53
+ readonly alias?: string
54
+ }
46
55
  }
47
56
 
48
57
  export const makeSchema = <TInputSchema extends InputSchema>(
49
58
  /** 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
- },
59
+ inputSchema: TInputSchema,
54
60
  ): 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
61
  const state = inputSchema.state
72
- const tables = inputSchema.state.tables
62
+ const tables = inputSchema.state.sqlite.tables
73
63
 
74
- for (const tableDef of systemTables) {
75
- // // @ts-expect-error TODO fix type level issue
64
+ for (const tableDef of stateSystemTables) {
76
65
  tables.set(tableDef.sqliteDef.name, tableDef)
77
66
  }
78
67
 
@@ -99,22 +88,15 @@ export const makeSchema = <TInputSchema extends InputSchema>(
99
88
  }
100
89
  }
101
90
 
102
- const hash = SqliteAst.hash({
103
- _tag: 'dbSchema',
104
- tables: [...tables.values()].map((_) => _.sqliteDef.ast),
105
- })
106
-
107
91
  return {
108
- _Type: LiveStoreSchemaSymbol,
92
+ LiveStoreSchemaSymbol,
109
93
  _DbSchemaType: Symbol.for('livestore.DbSchemaType') as any,
110
94
  _EventDefMapType: Symbol.for('livestore.EventDefMapType') as any,
111
- // tables,
112
- // events,
113
95
  state,
114
- tables: state.tables,
115
96
  eventsDefsMap,
116
- migrationOptions: inputSchema.migrations ?? { strategy: 'from-eventlog' },
117
- hash,
97
+ devtools: {
98
+ alias: inputSchema.devtools?.alias ?? 'default',
99
+ },
118
100
  } satisfies LiveStoreSchema
119
101
  }
120
102
 
@@ -138,7 +120,7 @@ export const getEventDef = <TSchema extends LiveStoreSchema>(
138
120
 
139
121
  export namespace FromInputSchema {
140
122
  export type DeriveSchema<TInputSchema extends InputSchema> = LiveStoreSchema<
141
- DbSchemaFromInputSchemaTables<TInputSchema['state']['tables']>,
123
+ DbSchemaFromInputSchemaTables<TInputSchema['state']['sqlite']['tables']>,
142
124
  EventDefRecordFromInputSchemaEvents<TInputSchema['events']>
143
125
  >
144
126
 
@@ -147,7 +129,7 @@ export namespace FromInputSchema {
147
129
  * - array: we use the table name of each array item (= table definition) as the object key
148
130
  * - 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
131
  */
150
- type DbSchemaFromInputSchemaTables<TTables extends InputSchema['state']['tables']> =
132
+ type DbSchemaFromInputSchemaTables<TTables extends InputSchema['state']['sqlite']['tables']> =
151
133
  TTables extends ReadonlyArray<TableDef>
152
134
  ? { [K in TTables[number] as K['sqliteDef']['name']]: K['sqliteDef'] }
153
135
  : TTables extends Record<string, TableDef>
@@ -0,0 +1,2 @@
1
+ export * as SQLite from './sqlite/mod.js'
2
+ export { QueryBuilderAstSymbol, QueryBuilderTypeId } from './sqlite/query-builder/mod.js'
@@ -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 '../__tests__/fixture.js'
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 '../adapter-types.js'
6
- import type { QueryBuilder, QueryBuilderAst } from '../query-builder/mod.js'
7
- import { QueryBuilderAstSymbol, QueryBuilderTypeId } from '../query-builder/mod.js'
8
- import { sql } from '../util.js'
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 { EventDef, Materializer } from './EventDef.js'
11
- import { defineEvent, defineMaterializer } from './EventDef.js'
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 { type Materializer, rawSqlEvent, rawSqlMaterializer } from './EventDef.js'
5
- import type { State } from './schema.js'
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 './EventDef.js'
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 systemTables) {
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
- return { tables, materializers }
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 '../adapter-types.js'
5
- import type { ClientDocumentTableDef } from '../schema/client-document-def.js'
6
- import type { SqliteDsl } from '../schema/db-schema/mod.js'
7
- import type { State } from '../schema/mod.js'
8
- import type { SqlValue } from '../util.js'
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: State.SQLite.TableDefBase
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: State.SQLite.TableDefBase
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: State.SQLite.ClientDocumentTableDef.Any
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: State.SQLite.TableDefBase
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: State.SQLite.TableDefBase
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: State.SQLite.TableDefBase
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 State.SQLite.TableDefBase,
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 State.SQLite.TableDefBase> = Partial<{
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 State.SQLite.TableDefBase> = ReadonlyArray<{
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 State.SQLite.TableDefBase, TWithout extends ApiFeature> = {
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 State.SQLite.TableDefBase> = {
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 State.SQLite.TableDefBase> = SqliteDsl.FromColumns.RowDecoded<
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 State.SQLite.TableDefBase> =
432
- TTableDef['options']['isClientDocumentTable'] extends true
433
- ? GetValForKey<SqliteDsl.FromColumns.RowEncoded<TTableDef['sqliteDef']['columns']>, 'value'>
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 State.SQLite.TableDefBase> =
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 '../adapter-types.js'
5
- import type { State } from '../schema/mod.js'
6
- import type { SqlValue } from '../util.js'
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 '../schema/mod.js'
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 { State } from '../schema/mod.js'
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: State.SQLite.TableDefBase): QueryBuilderAst.SelectQuery => ({
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 '../schema/db-schema/mod.js'
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 systemTables = [
69
+ export const stateSystemTables = [
70
70
  schemaMetaTable,
71
71
  schemaEventDefsMetaTable,
72
72
  sessionChangesetMetaTable,
73
73
  leaderMergeCounterTable,
74
74
  ]
75
75
 
76
- /// Eventlog DB
76
+ export const isStateSystemTable = (tableName: string) => stateSystemTables.some((_) => _.sqliteDef.name === tableName)
77
77
 
78
- export const SyncStatus = Schema.Literal('synced', 'pending', 'error', 'clientOnly')
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 type { SchemaEventDefsMetaRow, SchemaMetaRow } from '../schema/system-tables.js'
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
- schemaMetaTable,
13
- systemTables,
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-mutation-defs.js'
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
- yield* migrateTable({
59
- db,
60
- tableAst: schemaMetaTable.sqliteDef.ast,
61
- behaviour: 'create-if-not-exists',
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 = new Set([
77
+ const tableDefs = [
76
78
  // NOTE it's important the `SCHEMA_META_TABLE` comes first since we're writing to it below
77
- ...systemTables,
78
- ...Array.from(schema.tables.values()).filter((_) => _.sqliteDef.name !== SCHEMA_META_TABLE),
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'
@@ -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, LEADER_MERGE_COUNTER_TABLE, type LiveStoreSchema } from '../schema/mod.js'
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 a read model changes during a rebase.
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
- applyEvent,
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
- applyEvent: (
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 = applyEvent(decodedEventDef, { otelContext, withChangeset: true })
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 = applyEvent(decodedEventDef, { otelContext, withChangeset: true })
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.33' as const
5
+ export const liveStoreVersion = '0.3.0-dev.36' as const
6
6
 
7
7
  /**
8
8
  * This version number is incremented whenever the internal storage format changes in a breaking way.
@@ -1,2 +0,0 @@
1
- export * as SQLite from './sqlite-state.js'
2
- export { QueryBuilderAstSymbol, QueryBuilderTypeId } from '../query-builder/mod.js'
package/tmp/pack.tgz DELETED
Binary file