@livestore/common 0.3.2-dev.0 → 0.3.2-dev.5

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 (260) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/ClientSessionLeaderThreadProxy.d.ts +7 -7
  3. package/dist/__tests__/fixture.d.ts +4 -4
  4. package/dist/__tests__/fixture.js +2 -2
  5. package/dist/adapter-types.d.ts +9 -9
  6. package/dist/adapter-types.d.ts.map +1 -1
  7. package/dist/adapter-types.js +4 -4
  8. package/dist/adapter-types.js.map +1 -1
  9. package/dist/debug-info.d.ts +2 -2
  10. package/dist/debug-info.js +2 -2
  11. package/dist/devtools/devtools-messages-client-session.d.ts +27 -27
  12. package/dist/devtools/devtools-messages-client-session.js +4 -4
  13. package/dist/devtools/devtools-messages-common.d.ts +6 -6
  14. package/dist/devtools/devtools-messages-common.js +1 -1
  15. package/dist/devtools/devtools-messages-leader.d.ts +35 -35
  16. package/dist/devtools/devtools-messages-leader.js +4 -4
  17. package/dist/devtools/devtools-messages.d.ts +3 -3
  18. package/dist/devtools/devtools-messages.d.ts.map +1 -1
  19. package/dist/devtools/devtools-messages.js +3 -3
  20. package/dist/devtools/devtools-messages.js.map +1 -1
  21. package/dist/devtools/mod.d.ts +3 -3
  22. package/dist/devtools/mod.js +3 -3
  23. package/dist/index.d.ts +16 -16
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +16 -16
  26. package/dist/index.js.map +1 -1
  27. package/dist/leader-thread/LeaderSyncProcessor.d.ts +5 -5
  28. package/dist/leader-thread/LeaderSyncProcessor.js +11 -11
  29. package/dist/leader-thread/LeaderSyncProcessor.js.map +1 -1
  30. package/dist/leader-thread/connection.d.ts +4 -4
  31. package/dist/leader-thread/connection.js +2 -2
  32. package/dist/leader-thread/eventlog.d.ts +7 -7
  33. package/dist/leader-thread/eventlog.js +8 -8
  34. package/dist/leader-thread/eventlog.js.map +1 -1
  35. package/dist/leader-thread/leader-worker-devtools.d.ts +3 -3
  36. package/dist/leader-thread/leader-worker-devtools.js +3 -3
  37. package/dist/leader-thread/make-leader-thread-layer.d.ts +7 -7
  38. package/dist/leader-thread/make-leader-thread-layer.js +10 -10
  39. package/dist/leader-thread/materialize-event.d.ts +4 -4
  40. package/dist/leader-thread/materialize-event.js +7 -7
  41. package/dist/leader-thread/mod.d.ts +8 -8
  42. package/dist/leader-thread/mod.d.ts.map +1 -1
  43. package/dist/leader-thread/mod.js +8 -8
  44. package/dist/leader-thread/mod.js.map +1 -1
  45. package/dist/leader-thread/recreate-db.d.ts +5 -5
  46. package/dist/leader-thread/recreate-db.js +2 -2
  47. package/dist/leader-thread/shutdown-channel.d.ts +1 -1
  48. package/dist/leader-thread/shutdown-channel.js +1 -1
  49. package/dist/leader-thread/types.d.ts +6 -6
  50. package/dist/make-client-session.d.ts +2 -2
  51. package/dist/make-client-session.d.ts.map +1 -1
  52. package/dist/make-client-session.js +2 -2
  53. package/dist/make-client-session.js.map +1 -1
  54. package/dist/materializer-helper.d.ts +5 -5
  55. package/dist/materializer-helper.js +5 -5
  56. package/dist/rematerialize-from-eventlog.d.ts +4 -4
  57. package/dist/rematerialize-from-eventlog.js +3 -3
  58. package/dist/schema/EventDef.d.ts +4 -32
  59. package/dist/schema/EventDef.d.ts.map +1 -1
  60. package/dist/schema/EventDef.js +0 -15
  61. package/dist/schema/EventDef.js.map +1 -1
  62. package/dist/schema/EventSequenceNumber.test.js +1 -1
  63. package/dist/schema/LiveStoreEvent.d.ts +5 -5
  64. package/dist/schema/LiveStoreEvent.js +1 -1
  65. package/dist/schema/events.d.ts +1 -1
  66. package/dist/schema/events.d.ts.map +1 -1
  67. package/dist/schema/events.js +1 -1
  68. package/dist/schema/events.js.map +1 -1
  69. package/dist/schema/mod.d.ts +9 -9
  70. package/dist/schema/mod.d.ts.map +1 -1
  71. package/dist/schema/mod.js +9 -9
  72. package/dist/schema/mod.js.map +1 -1
  73. package/dist/schema/schema.d.ts +4 -8
  74. package/dist/schema/schema.d.ts.map +1 -1
  75. package/dist/schema/schema.js +2 -4
  76. package/dist/schema/schema.js.map +1 -1
  77. package/dist/schema/state/mod.d.ts +2 -2
  78. package/dist/schema/state/mod.js +2 -2
  79. package/dist/schema/state/sqlite/client-document-def.d.ts +17 -5
  80. package/dist/schema/state/sqlite/client-document-def.d.ts.map +1 -1
  81. package/dist/schema/state/sqlite/client-document-def.js +18 -6
  82. package/dist/schema/state/sqlite/client-document-def.js.map +1 -1
  83. package/dist/schema/state/sqlite/client-document-def.test.js +4 -6
  84. package/dist/schema/state/sqlite/client-document-def.test.js.map +1 -1
  85. package/dist/schema/state/sqlite/db-schema/ast/sqlite.js +1 -1
  86. package/dist/schema/state/sqlite/db-schema/ast/validate.d.ts +1 -1
  87. package/dist/schema/state/sqlite/db-schema/dsl/field-defs.test.js +1 -1
  88. package/dist/schema/state/sqlite/db-schema/dsl/mod.d.ts +3 -3
  89. package/dist/schema/state/sqlite/db-schema/dsl/mod.d.ts.map +1 -1
  90. package/dist/schema/state/sqlite/db-schema/dsl/mod.js +1 -1
  91. package/dist/schema/state/sqlite/db-schema/dsl/mod.js.map +1 -1
  92. package/dist/schema/state/sqlite/db-schema/hash.d.ts.map +1 -1
  93. package/dist/schema/state/sqlite/db-schema/hash.js +0 -1
  94. package/dist/schema/state/sqlite/db-schema/hash.js.map +1 -1
  95. package/dist/schema/state/sqlite/db-schema/mod.d.ts +2 -2
  96. package/dist/schema/state/sqlite/db-schema/mod.d.ts.map +1 -1
  97. package/dist/schema/state/sqlite/db-schema/mod.js +2 -2
  98. package/dist/schema/state/sqlite/db-schema/mod.js.map +1 -1
  99. package/dist/schema/state/sqlite/mod.d.ts +7 -7
  100. package/dist/schema/state/sqlite/mod.d.ts.map +1 -1
  101. package/dist/schema/state/sqlite/mod.js +6 -8
  102. package/dist/schema/state/sqlite/mod.js.map +1 -1
  103. package/dist/schema/state/sqlite/query-builder/api.d.ts +5 -5
  104. package/dist/schema/state/sqlite/query-builder/astToSql.d.ts +2 -2
  105. package/dist/schema/state/sqlite/query-builder/astToSql.js +1 -1
  106. package/dist/schema/state/sqlite/query-builder/impl.d.ts +2 -2
  107. package/dist/schema/state/sqlite/query-builder/impl.d.ts.map +1 -1
  108. package/dist/schema/state/sqlite/query-builder/impl.js +4 -14
  109. package/dist/schema/state/sqlite/query-builder/impl.js.map +1 -1
  110. package/dist/schema/state/sqlite/query-builder/impl.test.js +3 -3
  111. package/dist/schema/state/sqlite/query-builder/mod.d.ts +2 -2
  112. package/dist/schema/state/sqlite/query-builder/mod.js +2 -2
  113. package/dist/schema/state/sqlite/schema-helpers.d.ts +1 -1
  114. package/dist/schema/state/sqlite/schema-helpers.js +1 -1
  115. package/dist/schema/state/sqlite/system-tables.d.ts +10 -10
  116. package/dist/schema/state/sqlite/system-tables.js +3 -3
  117. package/dist/schema/state/sqlite/table-def.d.ts +2 -2
  118. package/dist/schema/state/sqlite/table-def.js +2 -2
  119. package/dist/schema-management/common.d.ts +2 -2
  120. package/dist/schema-management/common.js +1 -1
  121. package/dist/schema-management/migrations.d.ts +6 -6
  122. package/dist/schema-management/migrations.js +5 -5
  123. package/dist/schema-management/validate-schema.d.ts +4 -4
  124. package/dist/schema-management/validate-schema.js +1 -1
  125. package/dist/sql-queries/index.d.ts +3 -3
  126. package/dist/sql-queries/index.js +3 -3
  127. package/dist/sql-queries/sql-queries.d.ts +2 -2
  128. package/dist/sql-queries/sql-queries.js +3 -3
  129. package/dist/sql-queries/sql-query-builder.d.ts +3 -3
  130. package/dist/sql-queries/sql-query-builder.js +1 -1
  131. package/dist/sql-queries/types.d.ts +1 -1
  132. package/dist/sqlite-db-helper.d.ts +2 -2
  133. package/dist/sqlite-db-helper.js +1 -1
  134. package/dist/sqlite-types.d.ts +4 -4
  135. package/dist/sync/ClientSessionSyncProcessor.d.ts +17 -6
  136. package/dist/sync/ClientSessionSyncProcessor.d.ts.map +1 -1
  137. package/dist/sync/ClientSessionSyncProcessor.js +30 -11
  138. package/dist/sync/ClientSessionSyncProcessor.js.map +1 -1
  139. package/dist/sync/index.d.ts +3 -3
  140. package/dist/sync/index.d.ts.map +1 -1
  141. package/dist/sync/index.js +3 -3
  142. package/dist/sync/index.js.map +1 -1
  143. package/dist/sync/next/compact-events.d.ts +1 -1
  144. package/dist/sync/next/compact-events.js +4 -4
  145. package/dist/sync/next/facts.d.ts +3 -3
  146. package/dist/sync/next/facts.js +2 -2
  147. package/dist/sync/next/graphology.d.ts.map +1 -1
  148. package/dist/sync/next/graphology.js.map +1 -1
  149. package/dist/sync/next/graphology_.d.ts +1 -1
  150. package/dist/sync/next/graphology_.d.ts.map +1 -1
  151. package/dist/sync/next/graphology_.js +1 -1
  152. package/dist/sync/next/graphology_.js.map +1 -1
  153. package/dist/sync/next/history-dag-common.d.ts +3 -3
  154. package/dist/sync/next/history-dag-common.js +2 -2
  155. package/dist/sync/next/history-dag.d.ts +2 -2
  156. package/dist/sync/next/history-dag.js +3 -3
  157. package/dist/sync/next/mod.d.ts +5 -5
  158. package/dist/sync/next/mod.d.ts.map +1 -1
  159. package/dist/sync/next/mod.js +5 -5
  160. package/dist/sync/next/mod.js.map +1 -1
  161. package/dist/sync/next/rebase-events.d.ts +4 -4
  162. package/dist/sync/next/rebase-events.d.ts.map +1 -1
  163. package/dist/sync/next/rebase-events.js +2 -2
  164. package/dist/sync/next/rebase-events.js.map +1 -1
  165. package/dist/sync/next/test/compact-events.calculator.test.js +4 -4
  166. package/dist/sync/next/test/compact-events.test.js +4 -4
  167. package/dist/sync/next/test/event-fixtures.d.ts +3 -3
  168. package/dist/sync/next/test/event-fixtures.js +5 -5
  169. package/dist/sync/next/test/mod.d.ts +1 -1
  170. package/dist/sync/next/test/mod.js +1 -1
  171. package/dist/sync/sync.d.ts +4 -4
  172. package/dist/sync/sync.js +1 -1
  173. package/dist/sync/syncstate.d.ts +1 -1
  174. package/dist/sync/syncstate.js +2 -2
  175. package/dist/sync/syncstate.test.js +3 -4
  176. package/dist/sync/syncstate.test.js.map +1 -1
  177. package/dist/sync/validate-push-payload.d.ts +2 -2
  178. package/dist/sync/validate-push-payload.js +1 -1
  179. package/dist/util.d.ts.map +1 -1
  180. package/dist/util.js +0 -1
  181. package/dist/util.js.map +1 -1
  182. package/dist/version.d.ts +1 -1
  183. package/dist/version.js +1 -1
  184. package/package.json +6 -6
  185. package/src/ClientSessionLeaderThreadProxy.ts +7 -7
  186. package/src/__tests__/fixture.ts +2 -2
  187. package/src/adapter-types.ts +10 -9
  188. package/src/debug-info.ts +2 -2
  189. package/src/devtools/devtools-messages-client-session.ts +4 -4
  190. package/src/devtools/devtools-messages-common.ts +1 -1
  191. package/src/devtools/devtools-messages-leader.ts +4 -4
  192. package/src/devtools/devtools-messages.ts +3 -3
  193. package/src/devtools/mod.ts +3 -3
  194. package/src/index.ts +16 -16
  195. package/src/leader-thread/LeaderSyncProcessor.ts +14 -14
  196. package/src/leader-thread/connection.ts +5 -5
  197. package/src/leader-thread/eventlog.ts +12 -12
  198. package/src/leader-thread/leader-worker-devtools.ts +4 -4
  199. package/src/leader-thread/make-leader-thread-layer.ts +16 -16
  200. package/src/leader-thread/materialize-event.ts +9 -9
  201. package/src/leader-thread/mod.ts +8 -8
  202. package/src/leader-thread/recreate-db.ts +6 -6
  203. package/src/leader-thread/shutdown-channel.ts +1 -1
  204. package/src/leader-thread/types.ts +6 -6
  205. package/src/make-client-session.ts +3 -4
  206. package/src/materializer-helper.ts +11 -11
  207. package/src/rematerialize-from-eventlog.ts +6 -6
  208. package/src/schema/EventDef.ts +4 -24
  209. package/src/schema/EventSequenceNumber.test.ts +1 -1
  210. package/src/schema/LiveStoreEvent.ts +3 -3
  211. package/src/schema/events.ts +1 -1
  212. package/src/schema/mod.ts +9 -9
  213. package/src/schema/schema.ts +8 -11
  214. package/src/schema/state/mod.ts +2 -2
  215. package/src/schema/state/sqlite/client-document-def.test.ts +9 -7
  216. package/src/schema/state/sqlite/client-document-def.ts +57 -33
  217. package/src/schema/state/sqlite/db-schema/ast/sqlite.ts +1 -1
  218. package/src/schema/state/sqlite/db-schema/ast/validate.ts +1 -1
  219. package/src/schema/state/sqlite/db-schema/dsl/field-defs.test.ts +1 -1
  220. package/src/schema/state/sqlite/db-schema/dsl/mod.ts +19 -13
  221. package/src/schema/state/sqlite/db-schema/hash.ts +0 -1
  222. package/src/schema/state/sqlite/db-schema/mod.ts +2 -2
  223. package/src/schema/state/sqlite/mod.ts +13 -15
  224. package/src/schema/state/sqlite/query-builder/api.ts +5 -5
  225. package/src/schema/state/sqlite/query-builder/astToSql.ts +4 -4
  226. package/src/schema/state/sqlite/query-builder/impl.test.ts +4 -4
  227. package/src/schema/state/sqlite/query-builder/impl.ts +8 -16
  228. package/src/schema/state/sqlite/query-builder/mod.ts +2 -2
  229. package/src/schema/state/sqlite/schema-helpers.ts +2 -2
  230. package/src/schema/state/sqlite/system-tables.ts +3 -3
  231. package/src/schema/state/sqlite/table-def.ts +3 -3
  232. package/src/schema-management/common.ts +3 -3
  233. package/src/schema-management/migrations.ts +11 -11
  234. package/src/schema-management/validate-schema.ts +4 -4
  235. package/src/sql-queries/index.ts +3 -3
  236. package/src/sql-queries/sql-queries.ts +4 -4
  237. package/src/sql-queries/sql-query-builder.ts +4 -4
  238. package/src/sql-queries/types.ts +1 -1
  239. package/src/sqlite-db-helper.ts +3 -3
  240. package/src/sqlite-types.ts +4 -4
  241. package/src/sync/ClientSessionSyncProcessor.ts +50 -12
  242. package/src/sync/index.ts +3 -3
  243. package/src/sync/next/compact-events.ts +5 -5
  244. package/src/sync/next/facts.ts +4 -4
  245. package/src/sync/next/graphology.ts +2 -4
  246. package/src/sync/next/graphology_.ts +1 -1
  247. package/src/sync/next/history-dag-common.ts +3 -3
  248. package/src/sync/next/history-dag.ts +3 -3
  249. package/src/sync/next/mod.ts +5 -5
  250. package/src/sync/next/rebase-events.ts +6 -6
  251. package/src/sync/next/test/compact-events.calculator.test.ts +4 -4
  252. package/src/sync/next/test/compact-events.test.ts +5 -5
  253. package/src/sync/next/test/event-fixtures.ts +7 -7
  254. package/src/sync/next/test/mod.ts +1 -1
  255. package/src/sync/sync.ts +4 -4
  256. package/src/sync/syncstate.test.ts +9 -6
  257. package/src/sync/syncstate.ts +2 -2
  258. package/src/sync/validate-push-payload.ts +2 -2
  259. package/src/util.ts +0 -1
  260. package/src/version.ts +1 -1
@@ -12,8 +12,8 @@ import type {
12
12
  import { Context, Schema } from '@livestore/utils/effect'
13
13
  import type { MeshNode } from '@livestore/webmesh'
14
14
 
15
- import type { MigrationsReport } from '../defs.js'
16
- import type { SqliteError } from '../errors.js'
15
+ import type { MigrationsReport } from '../defs.ts'
16
+ import type { SqliteError } from '../errors.ts'
17
17
  import type {
18
18
  BootStatus,
19
19
  Devtools,
@@ -23,10 +23,10 @@ import type {
23
23
  SqliteDb,
24
24
  SyncBackend,
25
25
  UnexpectedError,
26
- } from '../index.js'
27
- import type { EventSequenceNumber, LiveStoreEvent, LiveStoreSchema } from '../schema/mod.js'
28
- import type * as SyncState from '../sync/syncstate.js'
29
- import type { ShutdownChannel } from './shutdown-channel.js'
26
+ } from '../index.ts'
27
+ import type { EventSequenceNumber, LiveStoreEvent, LiveStoreSchema } from '../schema/mod.ts'
28
+ import type * as SyncState from '../sync/syncstate.ts'
29
+ import type { ShutdownChannel } from './shutdown-channel.ts'
30
30
 
31
31
  export type ShutdownState = 'running' | 'shutting-down'
32
32
 
@@ -9,12 +9,11 @@ import type {
9
9
  LockStatus,
10
10
  SqliteDb,
11
11
  UnexpectedError,
12
- } from './adapter-types.js'
13
- import * as Devtools from './devtools/mod.js'
14
- import { liveStoreVersion } from './version.js'
12
+ } from './adapter-types.ts'
13
+ import * as Devtools from './devtools/mod.ts'
14
+ import { liveStoreVersion } from './version.ts'
15
15
 
16
16
  declare global {
17
- // eslint-disable-next-line no-var
18
17
  var __debugWebmeshNode: any
19
18
  }
20
19
 
@@ -1,17 +1,17 @@
1
1
  import { isDevEnv, isNil, isReadonlyArray } from '@livestore/utils'
2
2
  import { Hash, Option, Schema } from '@livestore/utils/effect'
3
3
 
4
- import type { SqliteDb } from './adapter-types.js'
5
- import { SessionIdSymbol } from './adapter-types.js'
6
- import type { EventDef, Materializer, MaterializerContextQuery, MaterializerResult } from './schema/EventDef.js'
7
- import type * as LiveStoreEvent from './schema/LiveStoreEvent.js'
8
- import { getEventDef, type LiveStoreSchema } from './schema/schema.js'
9
- import type { QueryBuilder } from './schema/state/sqlite/query-builder/api.js'
10
- import { isQueryBuilder } from './schema/state/sqlite/query-builder/api.js'
11
- import { getResultSchema } from './schema/state/sqlite/query-builder/impl.js'
12
- import type { BindValues } from './sql-queries/sql-queries.js'
13
- import type { ParamsObject, PreparedBindValues } from './util.js'
14
- import { prepareBindValues } from './util.js'
4
+ import type { SqliteDb } from './adapter-types.ts'
5
+ import { SessionIdSymbol } from './adapter-types.ts'
6
+ import type { EventDef, Materializer, MaterializerContextQuery, MaterializerResult } from './schema/EventDef.ts'
7
+ import type * as LiveStoreEvent from './schema/LiveStoreEvent.ts'
8
+ import { getEventDef, type LiveStoreSchema } from './schema/schema.ts'
9
+ import type { QueryBuilder } from './schema/state/sqlite/query-builder/api.ts'
10
+ import { isQueryBuilder } from './schema/state/sqlite/query-builder/api.ts'
11
+ import { getResultSchema } from './schema/state/sqlite/query-builder/impl.ts'
12
+ import type { BindValues } from './sql-queries/sql-queries.ts'
13
+ import type { ParamsObject, PreparedBindValues } from './util.ts'
14
+ import { prepareBindValues } from './util.ts'
15
15
 
16
16
  export const getExecStatementsFromMaterializer = ({
17
17
  eventDef,
@@ -1,12 +1,12 @@
1
1
  import { memoizeByRef } from '@livestore/utils'
2
2
  import { Chunk, Effect, Option, Schema, Stream } from '@livestore/utils/effect'
3
3
 
4
- import { type SqliteDb, UnexpectedError } from './adapter-types.js'
5
- import type { MaterializeEvent } from './leader-thread/mod.js'
6
- import type { EventDef, LiveStoreSchema } from './schema/mod.js'
7
- import { EventSequenceNumber, getEventDef, LiveStoreEvent, SystemTables } from './schema/mod.js'
8
- import type { PreparedBindValues } from './util.js'
9
- import { sql } from './util.js'
4
+ import { type SqliteDb, UnexpectedError } from './adapter-types.ts'
5
+ import type { MaterializeEvent } from './leader-thread/mod.ts'
6
+ import type { EventDef, LiveStoreSchema } from './schema/mod.ts'
7
+ import { EventSequenceNumber, getEventDef, LiveStoreEvent, SystemTables } from './schema/mod.ts'
8
+ import type { PreparedBindValues } from './util.ts'
9
+ import { sql } from './util.ts'
10
10
 
11
11
  export const rematerializeFromEventlog = ({
12
12
  dbEventlog,
@@ -2,15 +2,14 @@ import type { SingleOrReadonlyArray } from '@livestore/utils'
2
2
  import { shouldNeverHappen } from '@livestore/utils'
3
3
  import { Schema } from '@livestore/utils/effect'
4
4
 
5
- import type { BindValues } from '../sql-queries/sql-queries.js'
6
- import type { ParamsObject } from '../util.js'
7
- import type { QueryBuilder } from './state/sqlite/query-builder/mod.js'
5
+ import type { BindValues } from '../sql-queries/sql-queries.ts'
6
+ import type { ParamsObject } from '../util.ts'
7
+ import type { QueryBuilder } from './state/sqlite/query-builder/mod.ts'
8
8
 
9
9
  export type EventDefMap = {
10
- map: Map<string | 'livestore.RawSql', EventDef.Any>
10
+ map: Map<string, EventDef.Any>
11
11
  }
12
12
  export type EventDefRecord = {
13
- 'livestore.RawSql': RawSqlEvent
14
13
  [name: string]: EventDef.Any
15
14
  }
16
15
 
@@ -218,22 +217,3 @@ export const materializers = <TInputRecord extends Record<string, EventDef.AnyWi
218
217
  ) => {
219
218
  return handlers
220
219
  }
221
-
222
- export const rawSqlEvent = defineEvent({
223
- name: 'livestore.RawSql',
224
- schema: Schema.Struct({
225
- sql: Schema.String,
226
- bindValues: Schema.optional(Schema.Record({ key: Schema.String, value: Schema.Any })),
227
- writeTables: Schema.optional(Schema.ReadonlySet(Schema.String)),
228
- }),
229
- clientOnly: true,
230
- derived: true,
231
- })
232
-
233
- export const rawSqlMaterializer = defineMaterializer(rawSqlEvent, ({ sql, bindValues, writeTables }) => ({
234
- sql,
235
- bindValues: bindValues ?? {},
236
- writeTables,
237
- }))
238
-
239
- export type RawSqlEvent = typeof rawSqlEvent
@@ -1,7 +1,7 @@
1
1
  import { Vitest } from '@livestore/utils-dev/node-vitest'
2
2
  import { expect } from 'vitest'
3
3
 
4
- import { EventSequenceNumber } from './mod.js'
4
+ import { EventSequenceNumber } from './mod.ts'
5
5
 
6
6
  Vitest.describe('EventSequenceNumber', () => {
7
7
  Vitest.test('nextPair (no rebase)', () => {
@@ -1,9 +1,9 @@
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'
5
- import * as EventSequenceNumber from './EventSequenceNumber.js'
6
- import type { LiveStoreSchema } from './schema.js'
4
+ import type { EventDef, EventDefRecord } from './EventDef.ts'
5
+ import * as EventSequenceNumber from './EventSequenceNumber.ts'
6
+ import type { LiveStoreSchema } from './schema.ts'
7
7
 
8
8
  export namespace ForEventDef {
9
9
  export type PartialDecoded<TEventDef extends EventDef.Any> = {
@@ -1 +1 @@
1
- export { defineEvent, synced, clientOnly } from './EventDef.js'
1
+ export { clientOnly, defineEvent, synced } from './EventDef.ts'
package/src/schema/mod.ts CHANGED
@@ -1,9 +1,9 @@
1
- export * as SystemTables from './state/sqlite/system-tables.js'
2
- export { SqliteAst, SqliteDsl } from './state/sqlite/db-schema/mod.js'
3
- export * from './EventDef.js'
4
- export * from './state/sqlite/schema-helpers.js'
5
- export * from './schema.js'
6
- export * as State from './state/mod.js'
7
- export * as LiveStoreEvent from './LiveStoreEvent.js'
8
- export * as EventSequenceNumber from './EventSequenceNumber.js'
9
- export * as Events from './events.js'
1
+ export * from './EventDef.ts'
2
+ export * as EventSequenceNumber from './EventSequenceNumber.ts'
3
+ export * as Events from './events.ts'
4
+ export * as LiveStoreEvent from './LiveStoreEvent.ts'
5
+ export * from './schema.ts'
6
+ export * as State from './state/mod.ts'
7
+ export { SqliteAst, SqliteDsl } from './state/sqlite/db-schema/mod.ts'
8
+ export * from './state/sqlite/schema-helpers.ts'
9
+ export * as SystemTables from './state/sqlite/system-tables.ts'
@@ -1,12 +1,11 @@
1
1
  import { isReadonlyArray, shouldNeverHappen } from '@livestore/utils'
2
2
 
3
- import type { MigrationOptions } from '../adapter-types.js'
4
- import type { EventDef, EventDefRecord, Materializer, RawSqlEvent } from './EventDef.js'
5
- import { rawSqlEvent } from './EventDef.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'
3
+ import type { MigrationOptions } from '../adapter-types.ts'
4
+ import type { EventDef, EventDefRecord, Materializer } from './EventDef.ts'
5
+ import { tableIsClientDocumentTable } from './state/sqlite/client-document-def.ts'
6
+ import type { SqliteDsl } from './state/sqlite/db-schema/mod.ts'
7
+ import { stateSystemTables } from './state/sqlite/system-tables.ts'
8
+ import type { TableDef } from './state/sqlite/table-def.ts'
10
9
 
11
10
  export const LiveStoreSchemaSymbol = Symbol.for('livestore.LiveStoreSchema')
12
11
  export type LiveStoreSchemaSymbol = typeof LiveStoreSchemaSymbol
@@ -80,8 +79,6 @@ export const makeSchema = <TInputSchema extends InputSchema>(
80
79
  }
81
80
  }
82
81
 
83
- eventsDefsMap.set(rawSqlEvent.name, rawSqlEvent)
84
-
85
82
  for (const tableDef of tables.values()) {
86
83
  if (tableIsClientDocumentTable(tableDef) && eventsDefsMap.has(tableDef.set.name) === false) {
87
84
  eventsDefsMap.set(tableDef.set.name, tableDef.set)
@@ -138,8 +135,8 @@ export namespace FromInputSchema {
138
135
 
139
136
  type EventDefRecordFromInputSchemaEvents<TEvents extends InputSchema['events']> =
140
137
  TEvents extends ReadonlyArray<EventDef.Any>
141
- ? { [K in TEvents[number] as K['name']]: K } & { 'livestore.RawSql': RawSqlEvent }
138
+ ? { [K in TEvents[number] as K['name']]: K }
142
139
  : TEvents extends { [name: string]: EventDef.Any }
143
- ? { [K in keyof TEvents as TEvents[K]['name']]: TEvents[K] } & { 'livestore.RawSql': RawSqlEvent }
140
+ ? { [K in keyof TEvents as TEvents[K]['name']]: TEvents[K] }
144
141
  : never
145
142
  }
@@ -1,2 +1,2 @@
1
- export * as SQLite from './sqlite/mod.js'
2
- export { QueryBuilderAstSymbol, QueryBuilderTypeId } from './sqlite/query-builder/mod.js'
1
+ export * as SQLite from './sqlite/mod.ts'
2
+ export { QueryBuilderAstSymbol, QueryBuilderTypeId } from './sqlite/query-builder/mod.ts'
@@ -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'
5
- import type * as LiveStoreEvent from '../../LiveStoreEvent.js'
6
- import { clientDocument, ClientDocumentTableDefSymbol } from './client-document-def.js'
4
+ import { tables } from '../../../__tests__/fixture.ts'
5
+ import type * as LiveStoreEvent from '../../LiveStoreEvent.ts'
6
+ import { ClientDocumentTableDefSymbol, clientDocument } from './client-document-def.ts'
7
7
 
8
8
  describe('client document table', () => {
9
9
  test('set event', () => {
@@ -70,8 +70,9 @@ describe('client document table', () => {
70
70
  })
71
71
 
72
72
  test('struct value (partial set=true)', () => {
73
- expect(forSchema(Schema.Struct({ a: Schema.String }), { a: 'hello' }, 'id1', { partialSet: true }))
74
- .toMatchInlineSnapshot(`
73
+ expect(
74
+ forSchema(Schema.Struct({ a: Schema.String }), { a: 'hello' }, 'id1', { partialSet: true }),
75
+ ).toMatchInlineSnapshot(`
75
76
  {
76
77
  "bindValues": [
77
78
  "id1",
@@ -92,8 +93,9 @@ describe('client document table', () => {
92
93
  })
93
94
 
94
95
  test('struct value (partial set=false)', () => {
95
- expect(forSchema(Schema.Struct({ a: Schema.String }), { a: 'hello' }, 'id1', { partialSet: false }))
96
- .toMatchInlineSnapshot(`
96
+ expect(
97
+ forSchema(Schema.Struct({ a: Schema.String }), { a: 'hello' }, 'id1', { partialSet: false }),
98
+ ).toMatchInlineSnapshot(`
97
99
  {
98
100
  "bindValues": [
99
101
  "id1",
@@ -2,15 +2,15 @@ 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 { sql } from '../../../util.js'
7
- import type { EventDef, Materializer } from '../../EventDef.js'
8
- import { defineEvent, defineMaterializer } from '../../EventDef.js'
9
- import { SqliteDsl } from './db-schema/mod.js'
10
- import type { QueryBuilder, QueryBuilderAst } from './query-builder/mod.js'
11
- import { QueryBuilderAstSymbol, QueryBuilderTypeId } from './query-builder/mod.js'
12
- import type { TableDef, TableDefBase } from './table-def.js'
13
- import { table } from './table-def.js'
5
+ import { SessionIdSymbol } from '../../../adapter-types.ts'
6
+ import { sql } from '../../../util.ts'
7
+ import type { EventDef, Materializer } from '../../EventDef.ts'
8
+ import { defineEvent, defineMaterializer } from '../../EventDef.ts'
9
+ import { SqliteDsl } from './db-schema/mod.ts'
10
+ import type { QueryBuilder, QueryBuilderAst } from './query-builder/mod.ts'
11
+ import { QueryBuilderAstSymbol, QueryBuilderTypeId } from './query-builder/mod.ts'
12
+ import type { TableDef, TableDefBase } from './table-def.ts'
13
+ import { table } from './table-def.ts'
14
14
 
15
15
  /**
16
16
  * Special:
@@ -23,6 +23,18 @@ import { table } from './table-def.js'
23
23
  * Careful:
24
24
  * - When changing the table definitions in a non-backwards compatible way, the state might be lost without
25
25
  * explicit reducers to handle the old auto-generated events
26
+ *
27
+ * Usage:
28
+ *
29
+ * ```ts
30
+ * // Querying data
31
+ * // `'some-id'` can be ommited for SessionIdSymbol
32
+ * store.queryDb(clientDocumentTable.get('some-id'))
33
+ *
34
+ * // Setting data
35
+ * // Again, `'some-id'` can be ommited for SessionIdSymbol
36
+ * store.commit(clientDocumentTable.set({ someField: 'some-value' }, 'some-id'))
37
+ * ```
26
38
  */
27
39
  export const clientDocument = <
28
40
  TName extends string,
@@ -386,37 +398,49 @@ export namespace ClientDocumentTableDef {
386
398
  }
387
399
  }
388
400
 
389
- export type GetOptions<TTableDef extends TraitAny> =
390
- TTableDef extends ClientDocumentTableDef.Trait<any, any, any, infer TOptions> ? TOptions : never
401
+ export type GetOptions<TTableDef extends TraitAny> = TTableDef extends ClientDocumentTableDef.Trait<
402
+ any,
403
+ any,
404
+ any,
405
+ infer TOptions
406
+ >
407
+ ? TOptions
408
+ : never
391
409
 
392
410
  export type TraitAny = Trait<any, any, any, any>
393
411
 
394
- export type DefaultIdType<TTableDef extends TraitAny> =
395
- TTableDef extends ClientDocumentTableDef.Trait<any, any, any, infer TOptions>
396
- ? TOptions['default']['id'] extends SessionIdSymbol | string
397
- ? TOptions['default']['id']
398
- : never
412
+ export type DefaultIdType<TTableDef extends TraitAny> = TTableDef extends ClientDocumentTableDef.Trait<
413
+ any,
414
+ any,
415
+ any,
416
+ infer TOptions
417
+ >
418
+ ? TOptions['default']['id'] extends SessionIdSymbol | string
419
+ ? TOptions['default']['id']
399
420
  : never
421
+ : never
400
422
 
401
- export type SetEventDefLike<TName extends string, TType, TOptions extends ClientDocumentTableOptions<TType>> =
402
- // Helper to create partial event
403
- (TOptions['default']['id'] extends undefined
404
- ? (
405
- args: TOptions['partialSet'] extends false ? TType : Partial<TType>,
406
- id: string | SessionIdSymbol,
407
- ) => { name: `${TName}Set`; args: { id: string; value: TType } }
408
- : (
409
- args: TOptions['partialSet'] extends false ? TType : Partial<TType>,
410
- id?: string | SessionIdSymbol,
411
- ) => { name: `${TName}Set`; args: { id: string; value: TType } }) & {
423
+ export type SetEventDefLike<
424
+ TName extends string,
425
+ TType,
426
+ TOptions extends ClientDocumentTableOptions<TType>,
427
+ > = (TOptions['default']['id'] extends undefined // Helper to create partial event
428
+ ? (
429
+ args: TOptions['partialSet'] extends false ? TType : Partial<TType>,
430
+ id: string | SessionIdSymbol,
431
+ ) => { name: `${TName}Set`; args: { id: string; value: TType } }
432
+ : (
433
+ args: TOptions['partialSet'] extends false ? TType : Partial<TType>,
434
+ id?: string | SessionIdSymbol,
435
+ ) => { name: `${TName}Set`; args: { id: string; value: TType } }) & {
436
+ readonly name: `${TName}Set`
437
+ readonly schema: Schema.Schema<any>
438
+ readonly Event: {
412
439
  readonly name: `${TName}Set`
413
- readonly schema: Schema.Schema<any>
414
- readonly Event: {
415
- readonly name: `${TName}Set`
416
- readonly args: { id: string; value: TType }
417
- }
418
- readonly options: { derived: true; clientOnly: true; facts: undefined }
440
+ readonly args: { id: string; value: TType }
419
441
  }
442
+ readonly options: { derived: true; clientOnly: true; facts: undefined }
443
+ }
420
444
 
421
445
  export type SetEventDef<TName extends string, TType, TOptions extends ClientDocumentTableOptions<TType>> = EventDef<
422
446
  TName,
@@ -1,6 +1,6 @@
1
1
  import { type Option, Schema } from '@livestore/utils/effect'
2
2
 
3
- import { hashCode } from '../hash.js'
3
+ import { hashCode } from '../hash.ts'
4
4
 
5
5
  export namespace ColumnType {
6
6
  export type ColumnType = Text | Null | Real | Integer | Blob
@@ -1,4 +1,4 @@
1
- import type { DbSchema } from './sqlite.js'
1
+ import type { DbSchema } from './sqlite.ts'
2
2
 
3
3
  // TODO
4
4
  export const validate = (_dbSchema: DbSchema) => {
@@ -1,7 +1,7 @@
1
1
  import { Schema } from '@livestore/utils/effect'
2
2
  import { describe, expect, test } from 'vitest'
3
3
 
4
- import * as F from './field-defs.js'
4
+ import * as F from './field-defs.ts'
5
5
 
6
6
  describe.concurrent('FieldDefs', () => {
7
7
  test('text', () => {
@@ -2,10 +2,10 @@ import type { Nullable } from '@livestore/utils'
2
2
  import type { Option, Types } from '@livestore/utils/effect'
3
3
  import { Schema } from '@livestore/utils/effect'
4
4
 
5
- import type * as SqliteAst from '../ast/sqlite.js'
6
- import type { ColumnDefinition } from './field-defs.js'
5
+ import type * as SqliteAst from '../ast/sqlite.ts'
6
+ import type { ColumnDefinition } from './field-defs.ts'
7
7
 
8
- export * from './field-defs.js'
8
+ export * from './field-defs.ts'
9
9
 
10
10
  export type DbSchema = {
11
11
  [key: string]: TableDefinition<string, Columns>
@@ -19,12 +19,13 @@ export type DbSchemaInput = Record<string, TableDefinition<any, any>> | Readonly
19
19
  * - array: we use the table name of each array item (= table definition) as the object key
20
20
  * - 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
21
21
  */
22
- export type DbSchemaFromInputSchema<TSchemaInput extends DbSchemaInput> =
23
- TSchemaInput extends ReadonlyArray<TableDefinition<any, any>>
24
- ? { [K in TSchemaInput[number] as K['name']]: K }
25
- : TSchemaInput extends Record<string, TableDefinition<any, any>>
26
- ? { [K in keyof TSchemaInput as TSchemaInput[K]['name']]: TSchemaInput[K] }
27
- : never
22
+ export type DbSchemaFromInputSchema<TSchemaInput extends DbSchemaInput> = TSchemaInput extends ReadonlyArray<
23
+ TableDefinition<any, any>
24
+ >
25
+ ? { [K in TSchemaInput[number] as K['name']]: K }
26
+ : TSchemaInput extends Record<string, TableDefinition<any, any>>
27
+ ? { [K in keyof TSchemaInput as TSchemaInput[K]['name']]: TSchemaInput[K] }
28
+ : never
28
29
 
29
30
  // TODO ensure via runtime check (possibly even via type-level check) that all index names are unique
30
31
  export const makeDbSchema = <TDbSchemaInput extends DbSchemaInput>(
@@ -113,8 +114,12 @@ export type TableDefinition<TName extends string, TColumns extends Columns> = {
113
114
 
114
115
  export type Columns = Record<string, ColumnDefinition<any, any>>
115
116
 
116
- export type IsSingleColumn<TColumns extends Columns | ColumnDefinition<any, any>> =
117
- TColumns extends ColumnDefinition<any, any> ? true : false
117
+ export type IsSingleColumn<TColumns extends Columns | ColumnDefinition<any, any>> = TColumns extends ColumnDefinition<
118
+ any,
119
+ any
120
+ >
121
+ ? true
122
+ : false
118
123
 
119
124
  /**
120
125
  * NOTE this is only needed to avoid a TS limitation where `StructSchemaForColumns` in the default case
@@ -207,8 +212,9 @@ export namespace FromColumns {
207
212
 
208
213
  export type RequiredInsertColumnNames<TColumns extends Columns> = keyof RequiredInsertColumns<TColumns>
209
214
 
210
- export type RequiresInsertValues<TColumns extends Columns> =
211
- RequiredInsertColumnNames<TColumns> extends never ? false : true
215
+ export type RequiresInsertValues<TColumns extends Columns> = RequiredInsertColumnNames<TColumns> extends never
216
+ ? false
217
+ : true
212
218
 
213
219
  export type InsertRowDecoded<TColumns extends Columns> = Types.Simplify<
214
220
  Pick<RowDecodedAll<TColumns>, RequiredInsertColumnNames<TColumns>> &
@@ -5,7 +5,6 @@ export const hashCode = (str: string) => {
5
5
  let chr: number
6
6
  if (str.length === 0) return hash
7
7
  for (i = 0; i < str.length; i++) {
8
- // eslint-disable-next-line unicorn/prefer-code-point
9
8
  chr = str.charCodeAt(i)
10
9
  hash = (hash << 5) - hash + chr
11
10
  hash = Math.trunc(hash) // Convert to 32bit integer
@@ -1,2 +1,2 @@
1
- export * as SqliteDsl from './dsl/mod.js'
2
- export * as SqliteAst from './ast/sqlite.js'
1
+ export * as SqliteAst from './ast/sqlite.ts'
2
+ export * as SqliteDsl from './dsl/mod.ts'
@@ -1,22 +1,22 @@
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 { InternalState } from '../../schema.js'
6
- import { ClientDocumentTableDefSymbol, tableIsClientDocumentTable } from './client-document-def.js'
7
- import { SqliteAst } from './db-schema/mod.js'
8
- import { stateSystemTables } from './system-tables.js'
9
- import type { TableDef, TableDefBase } from './table-def.js'
3
+ import type { MigrationOptions } from '../../../adapter-types.ts'
4
+ import type { Materializer } from '../../EventDef.ts'
5
+ import type { InternalState } from '../../schema.ts'
6
+ import { ClientDocumentTableDefSymbol, tableIsClientDocumentTable } from './client-document-def.ts'
7
+ import { SqliteAst } from './db-schema/mod.ts'
8
+ import { stateSystemTables } from './system-tables.ts'
9
+ import type { TableDef, TableDefBase } from './table-def.ts'
10
10
 
11
- export * from './table-def.js'
11
+ export * from '../../EventDef.ts'
12
12
  export {
13
- ClientDocumentTableDefSymbol,
14
- tableIsClientDocumentTable,
15
- clientDocument,
16
13
  type ClientDocumentTableDef,
14
+ ClientDocumentTableDefSymbol,
17
15
  type ClientDocumentTableOptions,
18
- } from './client-document-def.js'
19
- export * from '../../EventDef.js'
16
+ clientDocument,
17
+ tableIsClientDocumentTable,
18
+ } from './client-document-def.ts'
19
+ export * from './table-def.ts'
20
20
 
21
21
  export const makeState = <TStateInput extends InputState>(inputSchema: TStateInput): InternalState => {
22
22
  const inputTables: ReadonlyArray<TableDef> = Array.isArray(inputSchema.tables)
@@ -44,8 +44,6 @@ export const makeState = <TStateInput extends InputState>(inputSchema: TStateInp
44
44
  materializers.set(name, materializer)
45
45
  }
46
46
 
47
- materializers.set(rawSqlEvent.name, rawSqlMaterializer)
48
-
49
47
  for (const tableDef of inputTables) {
50
48
  if (tableIsClientDocumentTable(tableDef)) {
51
49
  materializers.set(
@@ -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 { 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'
4
+ import type { SessionIdSymbol } from '../../../../adapter-types.ts'
5
+ import type { SqlValue } from '../../../../util.ts'
6
+ import type { ClientDocumentTableDef } from '../client-document-def.ts'
7
+ import type { SqliteDsl } from '../db-schema/mod.ts'
8
+ import type { TableDefBase } from '../table-def.ts'
9
9
 
10
10
  export type QueryBuilderAst =
11
11
  | QueryBuilderAst.SelectQuery
@@ -1,10 +1,10 @@
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 { SqlValue } from '../../../../util.js'
6
- import type { State } from '../../../mod.js'
7
- import type { QueryBuilderAst } from './api.js'
4
+ import { SessionIdSymbol } from '../../../../adapter-types.ts'
5
+ import type { SqlValue } from '../../../../util.ts'
6
+ import type { State } from '../../../mod.ts'
7
+ import type { QueryBuilderAst } from './api.ts'
8
8
 
9
9
  // Helper functions for SQL generation
10
10
  const formatWhereClause = (
@@ -1,9 +1,9 @@
1
1
  import { Schema } from '@livestore/utils/effect'
2
2
  import { describe, expect, it } from 'vitest'
3
3
 
4
- import { State } from '../../../mod.js'
5
- import type { QueryBuilder } from './api.js'
6
- import { getResultSchema } from './impl.js'
4
+ import { State } from '../../../mod.ts'
5
+ import type { QueryBuilder } from './api.ts'
6
+ import { getResultSchema } from './impl.ts'
7
7
 
8
8
  const todos = State.SQLite.table({
9
9
  name: 'todos',
@@ -116,7 +116,7 @@ describe('query builder', () => {
116
116
  1,
117
117
  ],
118
118
  "query": "SELECT id, text FROM 'todos' LIMIT ?",
119
- "schema": "(ReadonlyArray<{ readonly id: string; readonly text: string }> <-> { readonly id: string; readonly text: string })",
119
+ "schema": "(ReadonlyArray<{ readonly id: string; readonly text: string } | undefined> <-> { readonly id: string; readonly text: string } | undefined)",
120
120
  }
121
121
  `)
122
122