@livestore/common 0.4.0 → 0.5.0-dev.1

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 (501) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/ClientSessionLeaderThreadProxy.d.ts +1 -1
  3. package/dist/ClientSessionLeaderThreadProxy.d.ts.map +1 -1
  4. package/dist/MaterializationJournal.d.ts +44 -0
  5. package/dist/MaterializationJournal.d.ts.map +1 -0
  6. package/dist/MaterializationJournal.js +112 -0
  7. package/dist/MaterializationJournal.js.map +1 -0
  8. package/dist/StateHead.d.ts +26 -0
  9. package/dist/StateHead.d.ts.map +1 -0
  10. package/dist/StateHead.js +50 -0
  11. package/dist/StateHead.js.map +1 -0
  12. package/dist/WorkerTransportError.d.ts +3 -3
  13. package/dist/WorkerTransportError.d.ts.map +1 -1
  14. package/dist/WorkerTransportError.js +3 -3
  15. package/dist/WorkerTransportError.js.map +1 -1
  16. package/dist/__tests__/fixture.d.ts +8 -8
  17. package/dist/__tests__/fixture.d.ts.map +1 -1
  18. package/dist/__tests__/fixture.js +4 -4
  19. package/dist/__tests__/fixture.js.map +1 -1
  20. package/dist/adapter-types.d.ts +33 -57
  21. package/dist/adapter-types.d.ts.map +1 -1
  22. package/dist/adapter-types.js +24 -41
  23. package/dist/adapter-types.js.map +1 -1
  24. package/dist/bounded-collections.d.ts.map +1 -1
  25. package/dist/bounded-collections.js.map +1 -1
  26. package/dist/debug-info.d.ts +56 -56
  27. package/dist/debug-info.d.ts.map +1 -1
  28. package/dist/debug-info.js +32 -44
  29. package/dist/debug-info.js.map +1 -1
  30. package/dist/defs.d.ts +9 -9
  31. package/dist/defs.js +2 -2
  32. package/dist/devtools/devtools-compatibility.test.js +2 -1
  33. package/dist/devtools/devtools-compatibility.test.js.map +1 -1
  34. package/dist/devtools/devtools-messages-client-session.d.ts +522 -334
  35. package/dist/devtools/devtools-messages-client-session.d.ts.map +1 -1
  36. package/dist/devtools/devtools-messages-client-session.js +80 -78
  37. package/dist/devtools/devtools-messages-client-session.js.map +1 -1
  38. package/dist/devtools/devtools-messages-common.d.ts +27 -27
  39. package/dist/devtools/devtools-messages-common.d.ts.map +1 -1
  40. package/dist/devtools/devtools-messages-common.js +6 -6
  41. package/dist/devtools/devtools-messages-common.js.map +1 -1
  42. package/dist/devtools/devtools-messages-leader.d.ts +410 -348
  43. package/dist/devtools/devtools-messages-leader.d.ts.map +1 -1
  44. package/dist/devtools/devtools-messages-leader.js +105 -93
  45. package/dist/devtools/devtools-messages-leader.js.map +1 -1
  46. package/dist/devtools/devtools-messages.js +3 -3
  47. package/dist/devtools/devtools-sessioninfo.d.ts +18 -19
  48. package/dist/devtools/devtools-sessioninfo.d.ts.map +1 -1
  49. package/dist/devtools/devtools-sessioninfo.js +8 -5
  50. package/dist/devtools/devtools-sessioninfo.js.map +1 -1
  51. package/dist/devtools/mod.d.ts +4 -5
  52. package/dist/devtools/mod.d.ts.map +1 -1
  53. package/dist/devtools/mod.js +12 -8
  54. package/dist/devtools/mod.js.map +1 -1
  55. package/dist/errors.d.ts +45 -69
  56. package/dist/errors.d.ts.map +1 -1
  57. package/dist/errors.js +19 -17
  58. package/dist/errors.js.map +1 -1
  59. package/dist/index.d.ts +4 -1
  60. package/dist/index.d.ts.map +1 -1
  61. package/dist/index.js +22 -19
  62. package/dist/index.js.map +1 -1
  63. package/dist/leader-thread/LeaderSyncProcessor.d.ts +87 -18
  64. package/dist/leader-thread/LeaderSyncProcessor.d.ts.map +1 -1
  65. package/dist/leader-thread/LeaderSyncProcessor.js +548 -480
  66. package/dist/leader-thread/LeaderSyncProcessor.js.map +1 -1
  67. package/dist/leader-thread/RejectedPushError.d.ts +72 -41
  68. package/dist/leader-thread/RejectedPushError.d.ts.map +1 -1
  69. package/dist/leader-thread/RejectedPushError.js +25 -6
  70. package/dist/leader-thread/RejectedPushError.js.map +1 -1
  71. package/dist/leader-thread/connection.d.ts +1 -0
  72. package/dist/leader-thread/connection.d.ts.map +1 -1
  73. package/dist/leader-thread/connection.js +11 -10
  74. package/dist/leader-thread/connection.js.map +1 -1
  75. package/dist/leader-thread/eventlog.d.ts +15 -5
  76. package/dist/leader-thread/eventlog.d.ts.map +1 -1
  77. package/dist/leader-thread/eventlog.js +19 -19
  78. package/dist/leader-thread/eventlog.js.map +1 -1
  79. package/dist/leader-thread/leader-worker-devtools.d.ts +1 -1
  80. package/dist/leader-thread/leader-worker-devtools.d.ts.map +1 -1
  81. package/dist/leader-thread/leader-worker-devtools.js +36 -20
  82. package/dist/leader-thread/leader-worker-devtools.js.map +1 -1
  83. package/dist/leader-thread/make-leader-thread-layer.d.ts +15 -5
  84. package/dist/leader-thread/make-leader-thread-layer.d.ts.map +1 -1
  85. package/dist/leader-thread/make-leader-thread-layer.js +62 -58
  86. package/dist/leader-thread/make-leader-thread-layer.js.map +1 -1
  87. package/dist/leader-thread/make-leader-thread-layer.test.js +9 -9
  88. package/dist/leader-thread/make-leader-thread-layer.test.js.map +1 -1
  89. package/dist/leader-thread/materialize-event.d.ts +2 -1
  90. package/dist/leader-thread/materialize-event.d.ts.map +1 -1
  91. package/dist/leader-thread/materialize-event.js +12 -8
  92. package/dist/leader-thread/materialize-event.js.map +1 -1
  93. package/dist/leader-thread/mod.js +9 -9
  94. package/dist/leader-thread/recreate-db.d.ts +5 -1
  95. package/dist/leader-thread/recreate-db.d.ts.map +1 -1
  96. package/dist/leader-thread/recreate-db.js +34 -59
  97. package/dist/leader-thread/recreate-db.js.map +1 -1
  98. package/dist/leader-thread/shutdown-channel.d.ts +2 -6
  99. package/dist/leader-thread/shutdown-channel.d.ts.map +1 -1
  100. package/dist/leader-thread/shutdown-channel.js +2 -3
  101. package/dist/leader-thread/shutdown-channel.js.map +1 -1
  102. package/dist/leader-thread/stream-events.d.ts +4 -7
  103. package/dist/leader-thread/stream-events.d.ts.map +1 -1
  104. package/dist/leader-thread/stream-events.js +16 -21
  105. package/dist/leader-thread/stream-events.js.map +1 -1
  106. package/dist/leader-thread/types.d.ts +38 -73
  107. package/dist/leader-thread/types.d.ts.map +1 -1
  108. package/dist/leader-thread/types.js +10 -6
  109. package/dist/leader-thread/types.js.map +1 -1
  110. package/dist/logging.d.ts +5 -30
  111. package/dist/logging.d.ts.map +1 -1
  112. package/dist/logging.js +1 -32
  113. package/dist/logging.js.map +1 -1
  114. package/dist/make-client-session.d.ts +2 -3
  115. package/dist/make-client-session.d.ts.map +1 -1
  116. package/dist/make-client-session.js +5 -5
  117. package/dist/make-client-session.js.map +1 -1
  118. package/dist/materializer-helper.d.ts +0 -1
  119. package/dist/materializer-helper.d.ts.map +1 -1
  120. package/dist/materializer-helper.js +9 -37
  121. package/dist/materializer-helper.js.map +1 -1
  122. package/dist/otel.d.ts +2 -3
  123. package/dist/otel.d.ts.map +1 -1
  124. package/dist/otel.js +2 -7
  125. package/dist/otel.js.map +1 -1
  126. package/dist/rematerialize-from-eventlog.d.ts +3 -1
  127. package/dist/rematerialize-from-eventlog.d.ts.map +1 -1
  128. package/dist/rematerialize-from-eventlog.js +42 -33
  129. package/dist/rematerialize-from-eventlog.js.map +1 -1
  130. package/dist/schema/EventDef/define.d.ts +6 -6
  131. package/dist/schema/EventDef/define.d.ts.map +1 -1
  132. package/dist/schema/EventDef/define.js +5 -5
  133. package/dist/schema/EventDef/define.js.map +1 -1
  134. package/dist/schema/EventDef/define.test.d.ts +2 -0
  135. package/dist/schema/EventDef/define.test.d.ts.map +1 -0
  136. package/dist/schema/EventDef/define.test.js +23 -0
  137. package/dist/schema/EventDef/define.test.js.map +1 -0
  138. package/dist/schema/EventDef/deprecated.d.ts +8 -13
  139. package/dist/schema/EventDef/deprecated.d.ts.map +1 -1
  140. package/dist/schema/EventDef/deprecated.js +12 -13
  141. package/dist/schema/EventDef/deprecated.js.map +1 -1
  142. package/dist/schema/EventDef/deprecated.test.js +3 -3
  143. package/dist/schema/EventDef/deprecated.test.js.map +1 -1
  144. package/dist/schema/EventDef/event-def.d.ts +1 -1
  145. package/dist/schema/EventDef/event-def.d.ts.map +1 -1
  146. package/dist/schema/EventDef/facts.d.ts.map +1 -1
  147. package/dist/schema/EventDef/materializer.d.ts +2 -2
  148. package/dist/schema/EventDef/materializer.d.ts.map +1 -1
  149. package/dist/schema/EventDef/mod.js +5 -5
  150. package/dist/schema/EventSequenceNumber/client.d.ts +12 -17
  151. package/dist/schema/EventSequenceNumber/client.d.ts.map +1 -1
  152. package/dist/schema/EventSequenceNumber/client.js +20 -24
  153. package/dist/schema/EventSequenceNumber/client.js.map +1 -1
  154. package/dist/schema/EventSequenceNumber/global.d.ts +2 -2
  155. package/dist/schema/EventSequenceNumber/global.d.ts.map +1 -1
  156. package/dist/schema/EventSequenceNumber/global.js +1 -1
  157. package/dist/schema/EventSequenceNumber/global.js.map +1 -1
  158. package/dist/schema/EventSequenceNumber/mod.js +2 -2
  159. package/dist/schema/EventSequenceNumber.test.js +6 -6
  160. package/dist/schema/EventSequenceNumber.test.js.map +1 -1
  161. package/dist/schema/LiveStoreEvent/client.d.ts +58 -187
  162. package/dist/schema/LiveStoreEvent/client.d.ts.map +1 -1
  163. package/dist/schema/LiveStoreEvent/client.js +33 -30
  164. package/dist/schema/LiveStoreEvent/client.js.map +1 -1
  165. package/dist/schema/LiveStoreEvent/client.test.js +13 -4
  166. package/dist/schema/LiveStoreEvent/client.test.js.map +1 -1
  167. package/dist/schema/LiveStoreEvent/for-event-def.d.ts +7 -7
  168. package/dist/schema/LiveStoreEvent/for-event-def.d.ts.map +1 -1
  169. package/dist/schema/LiveStoreEvent/global.d.ts +6 -6
  170. package/dist/schema/LiveStoreEvent/global.d.ts.map +1 -1
  171. package/dist/schema/LiveStoreEvent/global.js +2 -2
  172. package/dist/schema/LiveStoreEvent/global.js.map +1 -1
  173. package/dist/schema/LiveStoreEvent/input.d.ts +6 -6
  174. package/dist/schema/LiveStoreEvent/input.d.ts.map +1 -1
  175. package/dist/schema/LiveStoreEvent/input.js +3 -3
  176. package/dist/schema/LiveStoreEvent/input.js.map +1 -1
  177. package/dist/schema/LiveStoreEvent/mod.js +4 -4
  178. package/dist/schema/events.js +1 -1
  179. package/dist/schema/mod.d.ts +1 -0
  180. package/dist/schema/mod.d.ts.map +1 -1
  181. package/dist/schema/mod.js +11 -10
  182. package/dist/schema/mod.js.map +1 -1
  183. package/dist/schema/schema.d.ts +1 -1
  184. package/dist/schema/schema.d.ts.map +1 -1
  185. package/dist/schema/schema.js +6 -5
  186. package/dist/schema/schema.js.map +1 -1
  187. package/dist/schema/state/mod.js +2 -2
  188. package/dist/schema/state/sqlite/client-document-def.d.ts +13 -18
  189. package/dist/schema/state/sqlite/client-document-def.d.ts.map +1 -1
  190. package/dist/schema/state/sqlite/client-document-def.js +30 -27
  191. package/dist/schema/state/sqlite/client-document-def.js.map +1 -1
  192. package/dist/schema/state/sqlite/client-document-def.test.js +53 -18
  193. package/dist/schema/state/sqlite/client-document-def.test.js.map +1 -1
  194. package/dist/schema/state/sqlite/column-annotations.d.ts +13 -13
  195. package/dist/schema/state/sqlite/column-annotations.d.ts.map +1 -1
  196. package/dist/schema/state/sqlite/column-annotations.js +13 -15
  197. package/dist/schema/state/sqlite/column-annotations.js.map +1 -1
  198. package/dist/schema/state/sqlite/column-annotations.test.js +19 -43
  199. package/dist/schema/state/sqlite/column-annotations.test.js.map +1 -1
  200. package/dist/schema/state/sqlite/column-def.d.ts +1 -1
  201. package/dist/schema/state/sqlite/column-def.d.ts.map +1 -1
  202. package/dist/schema/state/sqlite/column-def.js +73 -33
  203. package/dist/schema/state/sqlite/column-def.js.map +1 -1
  204. package/dist/schema/state/sqlite/column-def.test.js +176 -75
  205. package/dist/schema/state/sqlite/column-def.test.js.map +1 -1
  206. package/dist/schema/state/sqlite/column-spec.d.ts.map +1 -1
  207. package/dist/schema/state/sqlite/column-spec.js +1 -1
  208. package/dist/schema/state/sqlite/column-spec.js.map +1 -1
  209. package/dist/schema/state/sqlite/column-spec.test.js +4 -4
  210. package/dist/schema/state/sqlite/column-spec.test.js.map +1 -1
  211. package/dist/schema/state/sqlite/db-schema/ast/fingerprint-digest.d.ts +3 -0
  212. package/dist/schema/state/sqlite/db-schema/ast/fingerprint-digest.d.ts.map +1 -0
  213. package/dist/schema/state/sqlite/db-schema/ast/fingerprint-digest.js +5 -0
  214. package/dist/schema/state/sqlite/db-schema/ast/fingerprint-digest.js.map +1 -0
  215. package/dist/schema/state/sqlite/db-schema/ast/fingerprint.d.ts +5 -0
  216. package/dist/schema/state/sqlite/db-schema/ast/fingerprint.d.ts.map +1 -0
  217. package/dist/schema/state/sqlite/db-schema/ast/fingerprint.js +183 -0
  218. package/dist/schema/state/sqlite/db-schema/ast/fingerprint.js.map +1 -0
  219. package/dist/schema/state/sqlite/db-schema/ast/fingerprint.test.d.ts +2 -0
  220. package/dist/schema/state/sqlite/db-schema/ast/fingerprint.test.d.ts.map +1 -0
  221. package/dist/schema/state/sqlite/db-schema/ast/fingerprint.test.js +142 -0
  222. package/dist/schema/state/sqlite/db-schema/ast/fingerprint.test.js.map +1 -0
  223. package/dist/schema/state/sqlite/db-schema/ast/sqlite.d.ts +3 -8
  224. package/dist/schema/state/sqlite/db-schema/ast/sqlite.d.ts.map +1 -1
  225. package/dist/schema/state/sqlite/db-schema/ast/sqlite.js +1 -73
  226. package/dist/schema/state/sqlite/db-schema/ast/sqlite.js.map +1 -1
  227. package/dist/schema/state/sqlite/db-schema/ast/validate.d.ts.map +1 -1
  228. package/dist/schema/state/sqlite/db-schema/dsl/field-defs.d.ts +9 -9
  229. package/dist/schema/state/sqlite/db-schema/dsl/field-defs.d.ts.map +1 -1
  230. package/dist/schema/state/sqlite/db-schema/dsl/field-defs.js +9 -13
  231. package/dist/schema/state/sqlite/db-schema/dsl/field-defs.js.map +1 -1
  232. package/dist/schema/state/sqlite/db-schema/dsl/field-defs.test.js +28 -17
  233. package/dist/schema/state/sqlite/db-schema/dsl/field-defs.test.js.map +1 -1
  234. package/dist/schema/state/sqlite/db-schema/dsl/mod.d.ts +13 -11
  235. package/dist/schema/state/sqlite/db-schema/dsl/mod.d.ts.map +1 -1
  236. package/dist/schema/state/sqlite/db-schema/dsl/mod.js +6 -4
  237. package/dist/schema/state/sqlite/db-schema/dsl/mod.js.map +1 -1
  238. package/dist/schema/state/sqlite/db-schema/has-json-string-encoding.d.ts +3 -0
  239. package/dist/schema/state/sqlite/db-schema/has-json-string-encoding.d.ts.map +1 -0
  240. package/dist/schema/state/sqlite/db-schema/has-json-string-encoding.js +6 -0
  241. package/dist/schema/state/sqlite/db-schema/has-json-string-encoding.js.map +1 -0
  242. package/dist/schema/state/sqlite/db-schema/mod.js +2 -2
  243. package/dist/schema/state/sqlite/mod.d.ts +1 -3
  244. package/dist/schema/state/sqlite/mod.d.ts.map +1 -1
  245. package/dist/schema/state/sqlite/mod.js +11 -10
  246. package/dist/schema/state/sqlite/mod.js.map +1 -1
  247. package/dist/schema/state/sqlite/persistence.d.ts +11 -0
  248. package/dist/schema/state/sqlite/persistence.d.ts.map +1 -0
  249. package/dist/schema/state/sqlite/persistence.js +10 -0
  250. package/dist/schema/state/sqlite/persistence.js.map +1 -0
  251. package/dist/schema/state/sqlite/query-builder/api.d.ts +7 -7
  252. package/dist/schema/state/sqlite/query-builder/api.d.ts.map +1 -1
  253. package/dist/schema/state/sqlite/query-builder/astToSql.d.ts.map +1 -1
  254. package/dist/schema/state/sqlite/query-builder/astToSql.js +22 -23
  255. package/dist/schema/state/sqlite/query-builder/astToSql.js.map +1 -1
  256. package/dist/schema/state/sqlite/query-builder/impl.d.ts +1 -1
  257. package/dist/schema/state/sqlite/query-builder/impl.d.ts.map +1 -1
  258. package/dist/schema/state/sqlite/query-builder/impl.js +18 -16
  259. package/dist/schema/state/sqlite/query-builder/impl.js.map +1 -1
  260. package/dist/schema/state/sqlite/query-builder/impl.test.js +364 -598
  261. package/dist/schema/state/sqlite/query-builder/impl.test.js.map +1 -1
  262. package/dist/schema/state/sqlite/query-builder/mod.js +2 -2
  263. package/dist/schema/state/sqlite/schema-helpers.d.ts.map +1 -1
  264. package/dist/schema/state/sqlite/schema-helpers.js +2 -2
  265. package/dist/schema/state/sqlite/schema-helpers.js.map +1 -1
  266. package/dist/schema/state/sqlite/schema-helpers.test.js +2 -2
  267. package/dist/schema/state/sqlite/system-tables/eventlog-tables.d.ts +102 -134
  268. package/dist/schema/state/sqlite/system-tables/eventlog-tables.d.ts.map +1 -1
  269. package/dist/schema/state/sqlite/system-tables/eventlog-tables.js +5 -5
  270. package/dist/schema/state/sqlite/system-tables/eventlog-tables.js.map +1 -1
  271. package/dist/schema/state/sqlite/system-tables/mod.js +2 -2
  272. package/dist/schema/state/sqlite/system-tables/state-tables.d.ts +380 -115
  273. package/dist/schema/state/sqlite/system-tables/state-tables.d.ts.map +1 -1
  274. package/dist/schema/state/sqlite/system-tables/state-tables.js +47 -6
  275. package/dist/schema/state/sqlite/system-tables/state-tables.js.map +1 -1
  276. package/dist/schema/state/sqlite/table-def.d.ts +17 -20
  277. package/dist/schema/state/sqlite/table-def.d.ts.map +1 -1
  278. package/dist/schema/state/sqlite/table-def.js +72 -6
  279. package/dist/schema/state/sqlite/table-def.js.map +1 -1
  280. package/dist/schema/state/sqlite/table-def.test.js +207 -37
  281. package/dist/schema/state/sqlite/table-def.test.js.map +1 -1
  282. package/dist/schema/unknown-events.d.ts.map +1 -1
  283. package/dist/schema/unknown-events.js +3 -2
  284. package/dist/schema/unknown-events.js.map +1 -1
  285. package/dist/schema-management/__tests__/migrations-autoincrement-quoting.test.js +28 -6
  286. package/dist/schema-management/__tests__/migrations-autoincrement-quoting.test.js.map +1 -1
  287. package/dist/schema-management/common.d.ts.map +1 -1
  288. package/dist/schema-management/common.js +2 -2
  289. package/dist/schema-management/migrations.d.ts +4 -4
  290. package/dist/schema-management/migrations.d.ts.map +1 -1
  291. package/dist/schema-management/migrations.js +9 -9
  292. package/dist/schema-management/migrations.js.map +1 -1
  293. package/dist/schema-management/validate-schema.d.ts.map +1 -1
  294. package/dist/schema-management/validate-schema.js +1 -1
  295. package/dist/session-id-symbol.d.ts +29 -0
  296. package/dist/session-id-symbol.d.ts.map +1 -0
  297. package/dist/session-id-symbol.js +44 -0
  298. package/dist/session-id-symbol.js.map +1 -0
  299. package/dist/sql-queries/index.js +3 -3
  300. package/dist/sql-queries/sql-queries.d.ts.map +1 -1
  301. package/dist/sql-queries/sql-queries.js +11 -13
  302. package/dist/sql-queries/sql-queries.js.map +1 -1
  303. package/dist/sql-queries/sql-query-builder.d.ts.map +1 -1
  304. package/dist/sql-queries/sql-query-builder.js +1 -1
  305. package/dist/sql-queries/types.d.ts +6 -7
  306. package/dist/sql-queries/types.d.ts.map +1 -1
  307. package/dist/sql-queries/types.js.map +1 -1
  308. package/dist/sqlite-db-helper.d.ts +23 -3
  309. package/dist/sqlite-db-helper.d.ts.map +1 -1
  310. package/dist/sqlite-db-helper.js +39 -4
  311. package/dist/sqlite-db-helper.js.map +1 -1
  312. package/dist/sqlite-types.d.ts +3 -6
  313. package/dist/sqlite-types.d.ts.map +1 -1
  314. package/dist/sqlite-types.js +3 -3
  315. package/dist/sqlite-types.js.map +1 -1
  316. package/dist/sync/ClientSessionSyncProcessor.d.ts +41 -19
  317. package/dist/sync/ClientSessionSyncProcessor.d.ts.map +1 -1
  318. package/dist/sync/ClientSessionSyncProcessor.js +200 -70
  319. package/dist/sync/ClientSessionSyncProcessor.js.map +1 -1
  320. package/dist/sync/errors.d.ts +12 -18
  321. package/dist/sync/errors.d.ts.map +1 -1
  322. package/dist/sync/errors.js +3 -3
  323. package/dist/sync/errors.js.map +1 -1
  324. package/dist/sync/index.js +6 -6
  325. package/dist/sync/mock-sync-backend.d.ts +2 -3
  326. package/dist/sync/mock-sync-backend.d.ts.map +1 -1
  327. package/dist/sync/mock-sync-backend.js +58 -37
  328. package/dist/sync/mock-sync-backend.js.map +1 -1
  329. package/dist/sync/mock-sync-backend.test.d.ts +2 -0
  330. package/dist/sync/mock-sync-backend.test.d.ts.map +1 -0
  331. package/dist/sync/mock-sync-backend.test.js +49 -0
  332. package/dist/sync/mock-sync-backend.test.js.map +1 -0
  333. package/dist/sync/next/compact-events.d.ts.map +1 -1
  334. package/dist/sync/next/compact-events.js +3 -3
  335. package/dist/sync/next/facts.d.ts.map +1 -1
  336. package/dist/sync/next/facts.js +1 -1
  337. package/dist/sync/next/history-dag-common.d.ts +5 -1
  338. package/dist/sync/next/history-dag-common.d.ts.map +1 -1
  339. package/dist/sync/next/history-dag-common.js +53 -32
  340. package/dist/sync/next/history-dag-common.js.map +1 -1
  341. package/dist/sync/next/history-dag.d.ts.map +1 -1
  342. package/dist/sync/next/history-dag.js +5 -4
  343. package/dist/sync/next/history-dag.js.map +1 -1
  344. package/dist/sync/next/mod.js +5 -5
  345. package/dist/sync/next/rebase-events.d.ts.map +1 -1
  346. package/dist/sync/next/rebase-events.js +2 -2
  347. package/dist/sync/next/test/compact-events.calculator.test.js +6 -6
  348. package/dist/sync/next/test/compact-events.test.js +4 -4
  349. package/dist/sync/next/test/event-fixtures.d.ts +8 -8
  350. package/dist/sync/next/test/event-fixtures.d.ts.map +1 -1
  351. package/dist/sync/next/test/event-fixtures.js +6 -6
  352. package/dist/sync/next/test/event-fixtures.js.map +1 -1
  353. package/dist/sync/next/test/history-dag-common.test.d.ts +2 -0
  354. package/dist/sync/next/test/history-dag-common.test.d.ts.map +1 -0
  355. package/dist/sync/next/test/history-dag-common.test.js +73 -0
  356. package/dist/sync/next/test/history-dag-common.test.js.map +1 -0
  357. package/dist/sync/next/test/mod.js +1 -1
  358. package/dist/sync/sync-backend-kv.d.ts.map +1 -1
  359. package/dist/sync/sync-backend-kv.js +5 -3
  360. package/dist/sync/sync-backend-kv.js.map +1 -1
  361. package/dist/sync/sync-backend.d.ts +15 -15
  362. package/dist/sync/sync-backend.d.ts.map +1 -1
  363. package/dist/sync/sync-backend.js +10 -6
  364. package/dist/sync/sync-backend.js.map +1 -1
  365. package/dist/sync/sync.d.ts +1 -1
  366. package/dist/sync/sync.d.ts.map +1 -1
  367. package/dist/sync/sync.js +2 -2
  368. package/dist/sync/syncstate.d.ts +100 -176
  369. package/dist/sync/syncstate.d.ts.map +1 -1
  370. package/dist/sync/syncstate.js +36 -39
  371. package/dist/sync/syncstate.js.map +1 -1
  372. package/dist/sync/syncstate.test.js +103 -64
  373. package/dist/sync/syncstate.test.js.map +1 -1
  374. package/dist/sync/transport-chunking.d.ts +15 -16
  375. package/dist/sync/transport-chunking.d.ts.map +1 -1
  376. package/dist/sync/transport-chunking.js +23 -32
  377. package/dist/sync/transport-chunking.js.map +1 -1
  378. package/dist/sync/validate-push-payload.d.ts.map +1 -1
  379. package/dist/sync/validate-push-payload.js +2 -2
  380. package/dist/testing/event-factory.d.ts.map +1 -1
  381. package/dist/testing/event-factory.js +2 -2
  382. package/dist/testing/event-factory.js.map +1 -1
  383. package/dist/testing/mod.js +1 -1
  384. package/dist/util.d.ts +11 -4
  385. package/dist/util.d.ts.map +1 -1
  386. package/dist/util.js +20 -2
  387. package/dist/util.js.map +1 -1
  388. package/dist/version.d.ts.map +1 -1
  389. package/dist/version.js.map +1 -1
  390. package/package.json +40 -57
  391. package/src/ClientSessionLeaderThreadProxy.ts +1 -1
  392. package/src/MaterializationJournal.ts +184 -0
  393. package/src/StateHead.ts +80 -0
  394. package/src/WorkerTransportError.ts +4 -4
  395. package/src/__tests__/fixture.ts +3 -3
  396. package/src/adapter-types.ts +28 -61
  397. package/src/debug-info.ts +53 -70
  398. package/src/defs.ts +2 -2
  399. package/src/devtools/devtools-compatibility.test.ts +1 -0
  400. package/src/devtools/devtools-messages-client-session.ts +56 -65
  401. package/src/devtools/devtools-messages-common.ts +12 -11
  402. package/src/devtools/devtools-messages-leader.ts +71 -69
  403. package/src/devtools/devtools-sessioninfo.ts +13 -11
  404. package/src/devtools/mod.ts +4 -5
  405. package/src/errors.ts +46 -34
  406. package/src/index.ts +8 -1
  407. package/src/leader-thread/LeaderSyncProcessor.ts +777 -650
  408. package/src/leader-thread/RejectedPushError.ts +40 -27
  409. package/src/leader-thread/connection.ts +12 -8
  410. package/src/leader-thread/eventlog.ts +20 -12
  411. package/src/leader-thread/leader-worker-devtools.ts +38 -20
  412. package/src/leader-thread/make-leader-thread-layer.test.ts +7 -7
  413. package/src/leader-thread/make-leader-thread-layer.ts +100 -71
  414. package/src/leader-thread/materialize-event.ts +13 -8
  415. package/src/leader-thread/recreate-db.ts +41 -75
  416. package/src/leader-thread/shutdown-channel.ts +3 -14
  417. package/src/leader-thread/stream-events.ts +102 -101
  418. package/src/leader-thread/types.ts +29 -62
  419. package/src/logging.ts +5 -52
  420. package/src/make-client-session.ts +6 -6
  421. package/src/materializer-helper.ts +7 -36
  422. package/src/otel.ts +5 -14
  423. package/src/rematerialize-from-eventlog.ts +116 -98
  424. package/src/schema/EventDef/define.test.ts +28 -0
  425. package/src/schema/EventDef/define.ts +20 -19
  426. package/src/schema/EventDef/deprecated.test.ts +1 -8
  427. package/src/schema/EventDef/deprecated.ts +17 -20
  428. package/src/schema/EventDef/event-def.ts +2 -4
  429. package/src/schema/EventSequenceNumber/client.ts +20 -24
  430. package/src/schema/EventSequenceNumber/global.ts +1 -1
  431. package/src/schema/EventSequenceNumber.test.ts +5 -5
  432. package/src/schema/LiveStoreEvent/client.test.ts +17 -4
  433. package/src/schema/LiveStoreEvent/client.ts +36 -35
  434. package/src/schema/LiveStoreEvent/for-event-def.ts +7 -7
  435. package/src/schema/LiveStoreEvent/global.ts +1 -1
  436. package/src/schema/LiveStoreEvent/input.ts +6 -6
  437. package/src/schema/mod.ts +1 -0
  438. package/src/schema/schema.ts +4 -3
  439. package/src/schema/state/sqlite/client-document-def.test.ts +55 -20
  440. package/src/schema/state/sqlite/client-document-def.ts +95 -80
  441. package/src/schema/state/sqlite/column-annotations.test.ts +26 -45
  442. package/src/schema/state/sqlite/column-annotations.ts +26 -30
  443. package/src/schema/state/sqlite/column-def.test.ts +213 -77
  444. package/src/schema/state/sqlite/column-def.ts +87 -37
  445. package/src/schema/state/sqlite/column-spec.test.ts +2 -2
  446. package/src/schema/state/sqlite/column-spec.ts +3 -2
  447. package/src/schema/state/sqlite/db-schema/ast/fingerprint-digest.ts +6 -0
  448. package/src/schema/state/sqlite/db-schema/ast/fingerprint.test.ts +209 -0
  449. package/src/schema/state/sqlite/db-schema/ast/fingerprint.ts +225 -0
  450. package/src/schema/state/sqlite/db-schema/ast/sqlite.ts +2 -81
  451. package/src/schema/state/sqlite/db-schema/dsl/__snapshots__/field-defs.test.ts.snap +123 -63
  452. package/src/schema/state/sqlite/db-schema/dsl/field-defs.test.ts +35 -16
  453. package/src/schema/state/sqlite/db-schema/dsl/field-defs.ts +26 -31
  454. package/src/schema/state/sqlite/db-schema/dsl/mod.ts +35 -21
  455. package/src/schema/state/sqlite/db-schema/has-json-string-encoding.ts +9 -0
  456. package/src/schema/state/sqlite/mod.ts +4 -5
  457. package/src/schema/state/sqlite/persistence.ts +11 -0
  458. package/src/schema/state/sqlite/query-builder/api.ts +9 -9
  459. package/src/schema/state/sqlite/query-builder/astToSql.ts +24 -26
  460. package/src/schema/state/sqlite/query-builder/impl.test.ts +433 -669
  461. package/src/schema/state/sqlite/query-builder/impl.ts +19 -15
  462. package/src/schema/state/sqlite/schema-helpers.ts +1 -1
  463. package/src/schema/state/sqlite/system-tables/eventlog-tables.ts +2 -2
  464. package/src/schema/state/sqlite/system-tables/state-tables.ts +54 -3
  465. package/src/schema/state/sqlite/table-def.test.ts +270 -66
  466. package/src/schema/state/sqlite/table-def.ts +112 -45
  467. package/src/schema/unknown-events.ts +3 -2
  468. package/src/schema-management/__tests__/migrations-autoincrement-quoting.test.ts +35 -4
  469. package/src/schema-management/migrations.ts +7 -6
  470. package/src/session-id-symbol.ts +59 -0
  471. package/src/sql-queries/sql-queries.ts +9 -13
  472. package/src/sql-queries/types.ts +6 -7
  473. package/src/sqlite-db-helper.ts +64 -2
  474. package/src/sqlite-types.ts +5 -8
  475. package/src/sync/ClientSessionSyncProcessor.ts +303 -119
  476. package/src/sync/errors.ts +14 -12
  477. package/src/sync/mock-sync-backend.test.ts +78 -0
  478. package/src/sync/mock-sync-backend.ts +93 -47
  479. package/src/sync/next/history-dag-common.ts +60 -34
  480. package/src/sync/next/history-dag.ts +4 -1
  481. package/src/sync/next/test/compact-events.calculator.test.ts +2 -2
  482. package/src/sync/next/test/event-fixtures.ts +1 -1
  483. package/src/sync/next/test/history-dag-common.test.ts +87 -0
  484. package/src/sync/sync-backend-kv.ts +4 -2
  485. package/src/sync/sync-backend.ts +15 -15
  486. package/src/sync/sync.ts +1 -1
  487. package/src/sync/syncstate.test.ts +191 -140
  488. package/src/sync/syncstate.ts +63 -53
  489. package/src/sync/transport-chunking.ts +34 -39
  490. package/src/util.ts +19 -9
  491. package/src/version.ts +1 -2
  492. package/dist/schema/state/sqlite/db-schema/hash.d.ts +0 -2
  493. package/dist/schema/state/sqlite/db-schema/hash.d.ts.map +0 -1
  494. package/dist/schema/state/sqlite/db-schema/hash.js +0 -15
  495. package/dist/schema/state/sqlite/db-schema/hash.js.map +0 -1
  496. package/dist/sql-queries/misc.d.ts +0 -2
  497. package/dist/sql-queries/misc.d.ts.map +0 -1
  498. package/dist/sql-queries/misc.js +0 -2
  499. package/dist/sql-queries/misc.js.map +0 -1
  500. package/src/schema/state/sqlite/db-schema/hash.ts +0 -13
  501. package/src/sql-queries/misc.ts +0 -2
@@ -0,0 +1,225 @@
1
+ import { casesHandled, textEncodeToArrayBuffer } from '@livestore/utils'
2
+ import { Schema, SchemaAST, SchemaRepresentation } from '@livestore/utils/effect'
3
+
4
+ import { isDefaultThunk, isSqlDefaultValue } from '../dsl/field-defs.ts'
5
+ import { hasJsonStringEncoding } from '../has-json-string-encoding.ts'
6
+ import { digestToFingerprint } from './fingerprint-digest.ts'
7
+ import type { Column, ColumnType, DbSchema, Index, Table } from './sqlite.ts'
8
+
9
+ type FingerprintInput = Table | DbSchema
10
+
11
+ export const fingerprint = (input: FingerprintInput): string => digestToFingerprint(toCanonicalBytes(input))
12
+
13
+ type CanonicalValue = Schema.Json
14
+
15
+ type SchemaDescriptorCache = WeakMap<Schema.Top, CanonicalValue>
16
+
17
+ const domain = 'livestore/state-storage-fingerprint'
18
+
19
+ const toCanonicalBytes = (input: FingerprintInput): Uint8Array<ArrayBuffer> =>
20
+ textEncodeToArrayBuffer(JSON.stringify(toRootDescriptor(input)))
21
+
22
+ const toRootDescriptor = (input: FingerprintInput): CanonicalValue => {
23
+ // Limit schema memoization to one fingerprint operation so descriptors remain collectible.
24
+ const cache: SchemaDescriptorCache = new WeakMap()
25
+ return [domain, toDescriptor(input, cache)]
26
+ }
27
+
28
+ const toDescriptor = (input: FingerprintInput, cache: SchemaDescriptorCache): CanonicalValue => {
29
+ switch (input._tag) {
30
+ case 'table':
31
+ return tableDescriptor(input, cache)
32
+ case 'dbSchema':
33
+ return dbSchemaDescriptor(input, cache)
34
+ default:
35
+ return casesHandled(input)
36
+ }
37
+ }
38
+
39
+ const columnDescriptor = (column: Column, cache: SchemaDescriptorCache): CanonicalValue => {
40
+ const {
41
+ _tag: _tagIgnored,
42
+ name,
43
+ type,
44
+ primaryKey,
45
+ nullable,
46
+ autoIncrement,
47
+ default: defaultValue,
48
+ schema,
49
+ ...unhandled
50
+ } = column
51
+ assertNoUnhandledKeys(unhandled)
52
+
53
+ return [
54
+ 'column',
55
+ name,
56
+ columnTypeDescriptor(type),
57
+ primaryKey,
58
+ nullable,
59
+ autoIncrement,
60
+ defaultDescriptor(defaultValue, schema),
61
+ hasJsonStringEncoding(schema.ast) === true ? schemaDescriptor(schema, cache) : null,
62
+ ]
63
+ }
64
+
65
+ const columnTypeDescriptor = (type: ColumnType.ColumnType): string => {
66
+ const { _tag, ...unhandled } = type
67
+ assertNoUnhandledKeys(unhandled)
68
+ switch (_tag) {
69
+ case 'text':
70
+ case 'null':
71
+ case 'real':
72
+ case 'integer':
73
+ case 'blob':
74
+ return _tag
75
+ default:
76
+ return casesHandled(_tag)
77
+ }
78
+ }
79
+
80
+ const indexDescriptor = (index: Index): CanonicalValue => {
81
+ const { _tag: _tagIgnored, name, unique, primaryKey, columns, ...unhandled } = index
82
+ assertNoUnhandledKeys(unhandled)
83
+ return ['index', name ?? null, unique ?? false, primaryKey ?? false, columns]
84
+ }
85
+
86
+ const tableDescriptor = (table: Table, cache: SchemaDescriptorCache): CanonicalValue => {
87
+ const { _tag: _tagIgnored, name, columns, indexes, ...unhandled } = table
88
+ assertNoUnhandledKeys(unhandled)
89
+ return [
90
+ 'table',
91
+ name,
92
+ columns.map((column) => columnDescriptor(column, cache)),
93
+ sortCanonicalValues(indexes.map(indexDescriptor)),
94
+ ]
95
+ }
96
+
97
+ const dbSchemaDescriptor = (dbSchema: DbSchema, cache: SchemaDescriptorCache): CanonicalValue => {
98
+ const { _tag: _tagIgnored, tables, ...unhandled } = dbSchema
99
+ assertNoUnhandledKeys(unhandled)
100
+ return ['database', sortByCanonicalKey(tables, (table) => table.name).map((table) => tableDescriptor(table, cache))]
101
+ }
102
+
103
+ const defaultDescriptor = (value: Column['default'], schema: Column['schema']): CanonicalValue => {
104
+ if (value._tag === 'None') return ['none']
105
+ if (isDefaultThunk(value.value) === true) return ['runtime-default']
106
+ if (value.value === null) return ['value', null]
107
+ if (isSqlDefaultValue(value.value) === true) return ['sql', value.value.sql]
108
+
109
+ return ['value', canonicalValue(Schema.encodeSync(schema)(value.value))]
110
+ }
111
+
112
+ const schemaDescriptor = (schema: Schema.Top, cache: SchemaDescriptorCache): CanonicalValue => {
113
+ const cached = cache.get(schema)
114
+ if (cached !== undefined) return cached
115
+
116
+ // Both ends matter: the encoded side describes stored JSON while the type side
117
+ // distinguishes codecs such as DateFromString from an unconstrained string.
118
+ const document = SchemaRepresentation.toRepresentations([schema.ast, SchemaAST.toType(schema.ast)], {
119
+ referencePolicy: () => undefined,
120
+ })
121
+ const descriptor: CanonicalValue = ['schema', schemaRepresentationDescriptor(document)]
122
+ cache.set(schema, descriptor)
123
+ return descriptor
124
+ }
125
+
126
+ const schemaRepresentationDescriptor = (value: unknown, parentKey?: string): CanonicalValue => {
127
+ // Representation payloads are application-owned JSON. Keys such as `annotations`
128
+ // inside them are data, not Effect metadata.
129
+ if (parentKey === 'payload') return canonicalValue(value)
130
+
131
+ if (Array.isArray(value) === true) return value.map((item) => schemaRepresentationDescriptor(item))
132
+
133
+ if (value !== null && typeof value === 'object' && value instanceof Uint8Array === false) {
134
+ const sourceEntries = Object.entries(value).map(([key, entryValue]): [string, unknown] =>
135
+ parentKey === 'representation' && key === 'id' && typeof entryValue === 'string'
136
+ ? [key, renamedEffectCheckIds.get(entryValue) ?? entryValue]
137
+ : [key, entryValue],
138
+ )
139
+ const isUnion = sourceEntries.some(([key, entryValue]) => key === '_tag' && entryValue === 'Union')
140
+ // Effect rc.113 removed this representation field because unions only support `anyOf`.
141
+ // Restore the old default so dependency upgrades preserve existing state fingerprints.
142
+ if (isUnion === true && sourceEntries.some(([key]) => key === 'mode') === false) {
143
+ sourceEntries.push(['mode', 'anyOf'])
144
+ }
145
+ const entries = sortByCanonicalKey(
146
+ sourceEntries.filter(([key]) => effectIgnoredFields.has(key) === false),
147
+ ([key]) => key,
148
+ ).map(([key, entryValue]) => [key, schemaRepresentationDescriptor(entryValue, key)] as const)
149
+ return Object.fromEntries(entries)
150
+ }
151
+
152
+ return canonicalValue(value)
153
+ }
154
+
155
+ const effectIgnoredFields = new Set(['annotations', 'isMutable'])
156
+
157
+ /** Maps renamed Effect check ids to the ids existing fingerprints were computed from, so the rename does not rebuild state. */
158
+ const renamedEffectCheckIds = new Map([
159
+ ['effect/schema/isBetweenLength', 'effect/schema/isLengthBetween'],
160
+ ['effect/schema/isStartingWith', 'effect/schema/isStartsWith'],
161
+ ['effect/schema/isEndingWith', 'effect/schema/isEndsWith'],
162
+ ['effect/schema/isIncluding', 'effect/schema/isIncludes'],
163
+ ['effect/schema/isBetweenSize', 'effect/schema/isSizeBetween'],
164
+ ['effect/schema/isBetweenProperties', 'effect/schema/isPropertiesLengthBetween'],
165
+ ])
166
+
167
+ const canonicalValue = (value: unknown): CanonicalValue => {
168
+ if (Array.isArray(value) === true) return value.map(canonicalValue)
169
+
170
+ if (value !== null && typeof value === 'object' && value instanceof Uint8Array === false) {
171
+ const entries = sortByCanonicalKey(Object.entries(value), ([key]) => key).map(
172
+ ([key, entryValue]) => [key, canonicalValue(entryValue)] as const,
173
+ )
174
+ return Object.fromEntries(entries)
175
+ }
176
+
177
+ if (value === null || typeof value === 'string' || typeof value === 'boolean') return value
178
+
179
+ if (typeof value === 'number') {
180
+ if (Number.isNaN(value) === true) return specialValue('number', 'NaN')
181
+ if (value === Number.POSITIVE_INFINITY) return specialValue('number', 'Infinity')
182
+ if (value === Number.NEGATIVE_INFINITY) return specialValue('number', '-Infinity')
183
+ if (Object.is(value, -0) === true) return specialValue('number', '-0')
184
+ return value
185
+ }
186
+
187
+ if (typeof value === 'bigint') return specialValue('bigint', value.toString(10))
188
+ if (value === undefined) return specialValue('undefined')
189
+
190
+ if (typeof value === 'symbol') {
191
+ const symbolKey = Symbol.keyFor(value)
192
+ if (symbolKey === undefined) throw new Error('Local symbols cannot be represented in a persistent fingerprint')
193
+ return specialValue('symbol', symbolKey)
194
+ }
195
+
196
+ if (typeof value === 'function') throw new Error('Functions cannot be represented in a persistent fingerprint')
197
+ if (value instanceof Uint8Array) return specialValue('bytes', bytesToHex(value))
198
+
199
+ throw new Error('Unsupported canonical value')
200
+ }
201
+
202
+ const specialValue = (type: string, value?: string): CanonicalValue => ({
203
+ $livestore$type: value === undefined ? [type] : [type, value],
204
+ })
205
+
206
+ const bytesToHex = (bytes: Uint8Array): string => {
207
+ let output = ''
208
+ for (const byte of bytes) output += byte.toString(16).padStart(2, '0')
209
+ return output
210
+ }
211
+
212
+ /** Avoid repeatedly serializing deep descriptors from inside an O(n log n) sort comparator. */
213
+ const sortCanonicalValues = (values: ReadonlyArray<CanonicalValue>): ReadonlyArray<CanonicalValue> =>
214
+ values
215
+ .map((value) => ({ value, key: JSON.stringify(value) }))
216
+ .toSorted((left, right) => (left.key < right.key ? -1 : left.key > right.key ? 1 : 0))
217
+ .map(({ value }) => value)
218
+
219
+ const sortByCanonicalKey = <A>(values: ReadonlyArray<A>, key: (value: A) => CanonicalValue): ReadonlyArray<A> =>
220
+ values
221
+ .map((value) => ({ value, key: JSON.stringify(key(value)) }))
222
+ .toSorted((left, right) => (left.key < right.key ? -1 : left.key > right.key ? 1 : 0))
223
+ .map(({ value }) => value)
224
+
225
+ const assertNoUnhandledKeys = (_unhandled: Record<PropertyKey, never>): void => {}
@@ -1,7 +1,5 @@
1
1
  import { omitUndefineds } from '@livestore/utils'
2
- import { type Option, Schema, SchemaAST } from '@livestore/utils/effect'
3
-
4
- import { hashCode } from '../hash.ts'
2
+ import { type Option, Schema } from '@livestore/utils/effect'
5
3
 
6
4
  export namespace ColumnType {
7
5
  export type ColumnType = Text | Null | Real | Integer | Blob
@@ -25,7 +23,7 @@ export type Column = {
25
23
  nullable: boolean
26
24
  autoIncrement: boolean
27
25
  default: Option.Option<any>
28
- schema: Schema.Schema<any>
26
+ schema: Schema.Codec<any, any>
29
27
  }
30
28
 
31
29
  export const column = (props: Omit<Column, '_tag'>): Column => ({ _tag: 'column', ...props })
@@ -83,82 +81,5 @@ export type DbSchema = {
83
81
 
84
82
  export const dbSchema = (tables: Table[]): DbSchema => ({ _tag: 'dbSchema', tables })
85
83
 
86
- /**
87
- * Helper to detect if a column is a JSON column (has parseJson transformation)
88
- */
89
- const isJsonColumn = (column: Column): boolean => {
90
- if (column.type._tag !== 'text') return false
91
-
92
- // Check if the schema AST is a parseJson transformation
93
- const ast = column.schema.ast
94
- return ast._tag === 'Transformation' && ast.annotations.schemaId === SchemaAST.ParseJsonSchemaId
95
- }
96
-
97
- /**
98
- * NOTE we're now including JSON schema information for JSON columns
99
- * to detect client document schema changes
100
- */
101
- export const hash = (obj: Table | Column | Index | ForeignKey | DbSchema): number =>
102
- hashCode(JSON.stringify(trimInfoForHasing(obj)))
103
-
104
- const trimInfoForHasing = (obj: Table | Column | Index | ForeignKey | DbSchema): Record<string, any> => {
105
- switch (obj._tag) {
106
- case 'table': {
107
- return {
108
- _tag: 'table',
109
- name: obj.name,
110
- columns: obj.columns.map((column) => trimInfoForHasing(column)),
111
- indexes: obj.indexes.map((index) => trimInfoForHasing(index)),
112
- }
113
- }
114
- case 'column': {
115
- const baseInfo: Record<string, any> = {
116
- _tag: 'column',
117
- name: obj.name,
118
- type: obj.type._tag,
119
- primaryKey: obj.primaryKey,
120
- nullable: obj.nullable,
121
- autoIncrement: obj.autoIncrement,
122
- default: obj.default,
123
- }
124
-
125
- // NEW: Include schema hash for JSON columns
126
- // This ensures that changes to the JSON schema are detected
127
- if (isJsonColumn(obj) === true && obj.schema !== undefined) {
128
- // Use Effect's Schema.hash for consistent hashing
129
- baseInfo.jsonSchemaHash = Schema.hash(obj.schema)
130
- }
131
-
132
- return baseInfo
133
- }
134
- case 'index': {
135
- return {
136
- _tag: 'index',
137
- columns: obj.columns,
138
- name: obj.name,
139
- unique: obj.unique,
140
- primaryKey: obj.primaryKey,
141
- }
142
- }
143
- case 'foreignKey': {
144
- return {
145
- _tag: 'foreignKey',
146
- references: obj.references,
147
- key: obj.key,
148
- columns: obj.columns,
149
- }
150
- }
151
- case 'dbSchema': {
152
- return {
153
- _tag: 'dbSchema',
154
- tables: obj.tables.map(trimInfoForHasing),
155
- }
156
- }
157
- default: {
158
- throw new Error(`Unreachable: ${String(obj)}`)
159
- }
160
- }
161
- }
162
-
163
84
  export const structSchemaForTable = (tableDef: Table) =>
164
85
  Schema.Struct(Object.fromEntries(tableDef.columns.map((column) => [column.name, column.schema])))
@@ -3,77 +3,77 @@
3
3
  exports[`FieldDefs > boolean 1`] = `
4
4
  {
5
5
  "autoIncrement": false,
6
- "columnType": "text",
6
+ "columnType": "integer",
7
7
  "default": {
8
8
  "_id": "Option",
9
9
  "_tag": "None",
10
10
  },
11
11
  "nullable": false,
12
12
  "primaryKey": false,
13
- "schema": [Function],
13
+ "schema": {
14
+ "ast": "Boolean",
15
+ "decodedAst": "Boolean",
16
+ "encodedAst": "Union",
17
+ },
14
18
  }
15
19
  `;
16
20
 
17
21
  exports[`FieldDefs > boolean 2`] = `
18
22
  {
19
23
  "autoIncrement": false,
20
- "columnType": "text",
24
+ "columnType": "integer",
21
25
  "default": {
22
26
  "_id": "Option",
23
27
  "_tag": "None",
24
28
  },
25
29
  "nullable": false,
26
30
  "primaryKey": false,
27
- "schema": [Function],
31
+ "schema": {
32
+ "ast": "Boolean",
33
+ "decodedAst": "Boolean",
34
+ "encodedAst": "Union",
35
+ },
28
36
  }
29
37
  `;
30
38
 
31
39
  exports[`FieldDefs > boolean 3`] = `
32
40
  {
33
41
  "autoIncrement": false,
34
- "columnType": "text",
42
+ "columnType": "integer",
35
43
  "default": {
36
44
  "_id": "Option",
37
45
  "_tag": "Some",
38
- "value": null,
46
+ "value": false,
39
47
  },
40
- "nullable": true,
48
+ "nullable": false,
41
49
  "primaryKey": false,
42
- "schema": [Function],
43
- }
44
- `;
45
-
46
- exports[`FieldDefs > boolean 4`] = `
47
- {
48
- "autoIncrement": false,
49
- "columnType": "text",
50
- "default": {
51
- "_id": "Option",
52
- "_tag": "Some",
53
- "value": "foo",
50
+ "schema": {
51
+ "ast": "Boolean",
52
+ "decodedAst": "Boolean",
53
+ "encodedAst": "Union",
54
54
  },
55
- "nullable": true,
56
- "primaryKey": false,
57
- "schema": [Function],
58
55
  }
59
56
  `;
60
57
 
61
- exports[`FieldDefs > boolean 5`] = `
58
+ exports[`FieldDefs > datetime 1`] = `
62
59
  {
63
60
  "autoIncrement": false,
64
61
  "columnType": "text",
65
62
  "default": {
66
63
  "_id": "Option",
67
- "_tag": "Some",
68
- "value": "foo",
64
+ "_tag": "None",
69
65
  },
70
- "nullable": true,
66
+ "nullable": false,
71
67
  "primaryKey": false,
72
- "schema": [Function],
68
+ "schema": {
69
+ "ast": "Declaration",
70
+ "decodedAst": "Declaration",
71
+ "encodedAst": "String",
72
+ },
73
73
  }
74
74
  `;
75
75
 
76
- exports[`FieldDefs > boolean 6`] = `
76
+ exports[`FieldDefs > datetime 2`] = `
77
77
  {
78
78
  "autoIncrement": false,
79
79
  "columnType": "text",
@@ -83,11 +83,15 @@ exports[`FieldDefs > boolean 6`] = `
83
83
  },
84
84
  "nullable": false,
85
85
  "primaryKey": false,
86
- "schema": [Function],
86
+ "schema": {
87
+ "ast": "Declaration",
88
+ "decodedAst": "Declaration",
89
+ "encodedAst": "String",
90
+ },
87
91
  }
88
92
  `;
89
93
 
90
- exports[`FieldDefs > boolean 7`] = `
94
+ exports[`FieldDefs > datetime 3`] = `
91
95
  {
92
96
  "autoIncrement": false,
93
97
  "columnType": "text",
@@ -98,28 +102,34 @@ exports[`FieldDefs > boolean 7`] = `
98
102
  },
99
103
  "nullable": true,
100
104
  "primaryKey": false,
101
- "schema": [Function],
105
+ "schema": {
106
+ "ast": "Union",
107
+ "decodedAst": "Union",
108
+ "encodedAst": "Union",
109
+ },
102
110
  }
103
111
  `;
104
112
 
105
- exports[`FieldDefs > boolean 8`] = `
113
+ exports[`FieldDefs > datetime 4`] = `
106
114
  {
107
115
  "autoIncrement": false,
108
116
  "columnType": "text",
109
117
  "default": {
110
118
  "_id": "Option",
111
119
  "_tag": "Some",
112
- "value": {
113
- "name": "Bob",
114
- },
120
+ "value": 2022-02-02T00:00:00.000Z,
115
121
  },
116
- "nullable": true,
122
+ "nullable": false,
117
123
  "primaryKey": false,
118
- "schema": [Function],
124
+ "schema": {
125
+ "ast": "Declaration",
126
+ "decodedAst": "Declaration",
127
+ "encodedAst": "String",
128
+ },
119
129
  }
120
130
  `;
121
131
 
122
- exports[`FieldDefs > boolean 9`] = `
132
+ exports[`FieldDefs > json 1`] = `
123
133
  {
124
134
  "autoIncrement": false,
125
135
  "columnType": "text",
@@ -129,93 +139,143 @@ exports[`FieldDefs > boolean 9`] = `
129
139
  },
130
140
  "nullable": false,
131
141
  "primaryKey": false,
132
- "schema": [Function],
142
+ "schema": {
143
+ "ast": "Any",
144
+ "decodedAst": "Any",
145
+ "encodedAst": "String",
146
+ },
133
147
  }
134
148
  `;
135
149
 
136
- exports[`FieldDefs > boolean 10`] = `
150
+ exports[`FieldDefs > json 2`] = `
137
151
  {
138
152
  "autoIncrement": false,
139
153
  "columnType": "text",
140
154
  "default": {
141
155
  "_id": "Option",
142
- "_tag": "None",
156
+ "_tag": "Some",
157
+ "value": null,
143
158
  },
144
- "nullable": false,
159
+ "nullable": true,
145
160
  "primaryKey": false,
146
- "schema": [Function],
161
+ "schema": {
162
+ "ast": "Union",
163
+ "decodedAst": "Union",
164
+ "encodedAst": "Union",
165
+ },
147
166
  }
148
167
  `;
149
168
 
150
- exports[`FieldDefs > boolean 11`] = `
169
+ exports[`FieldDefs > json 3`] = `
151
170
  {
152
171
  "autoIncrement": false,
153
172
  "columnType": "text",
154
173
  "default": {
155
174
  "_id": "Option",
156
175
  "_tag": "Some",
157
- "value": null,
176
+ "value": {
177
+ "name": "Bob",
178
+ },
158
179
  },
159
180
  "nullable": true,
160
181
  "primaryKey": false,
161
- "schema": [Function],
182
+ "schema": {
183
+ "ast": "Union",
184
+ "decodedAst": "Union",
185
+ "encodedAst": "Union",
186
+ },
162
187
  }
163
188
  `;
164
189
 
165
- exports[`FieldDefs > boolean 12`] = `
190
+ exports[`FieldDefs > text 1`] = `
166
191
  {
167
192
  "autoIncrement": false,
168
193
  "columnType": "text",
169
194
  "default": {
170
195
  "_id": "Option",
171
- "_tag": "Some",
172
- "value": 2022-02-02T00:00:00.000Z,
196
+ "_tag": "None",
173
197
  },
174
198
  "nullable": false,
175
199
  "primaryKey": false,
176
- "schema": [Function],
200
+ "schema": {
201
+ "ast": "String",
202
+ "decodedAst": "String",
203
+ "encodedAst": "String",
204
+ },
177
205
  }
178
206
  `;
179
207
 
180
- exports[`FieldDefs > boolean 13`] = `
208
+ exports[`FieldDefs > text 2`] = `
181
209
  {
182
210
  "autoIncrement": false,
183
- "columnType": "integer",
211
+ "columnType": "text",
184
212
  "default": {
185
213
  "_id": "Option",
186
214
  "_tag": "None",
187
215
  },
188
216
  "nullable": false,
189
217
  "primaryKey": false,
190
- "schema": [Function],
218
+ "schema": {
219
+ "ast": "String",
220
+ "decodedAst": "String",
221
+ "encodedAst": "String",
222
+ },
191
223
  }
192
224
  `;
193
225
 
194
- exports[`FieldDefs > boolean 14`] = `
226
+ exports[`FieldDefs > text 3`] = `
195
227
  {
196
228
  "autoIncrement": false,
197
- "columnType": "integer",
229
+ "columnType": "text",
198
230
  "default": {
199
231
  "_id": "Option",
200
- "_tag": "None",
232
+ "_tag": "Some",
233
+ "value": null,
201
234
  },
202
- "nullable": false,
235
+ "nullable": true,
203
236
  "primaryKey": false,
204
- "schema": [Function],
237
+ "schema": {
238
+ "ast": "Union",
239
+ "decodedAst": "Union",
240
+ "encodedAst": "Union",
241
+ },
205
242
  }
206
243
  `;
207
244
 
208
- exports[`FieldDefs > boolean 15`] = `
245
+ exports[`FieldDefs > text 4`] = `
209
246
  {
210
247
  "autoIncrement": false,
211
- "columnType": "integer",
248
+ "columnType": "text",
212
249
  "default": {
213
250
  "_id": "Option",
214
251
  "_tag": "Some",
215
- "value": false,
252
+ "value": "foo",
216
253
  },
217
- "nullable": false,
254
+ "nullable": true,
218
255
  "primaryKey": false,
219
- "schema": [Function],
256
+ "schema": {
257
+ "ast": "Union",
258
+ "decodedAst": "Union",
259
+ "encodedAst": "Union",
260
+ },
261
+ }
262
+ `;
263
+
264
+ exports[`FieldDefs > text 5`] = `
265
+ {
266
+ "autoIncrement": false,
267
+ "columnType": "text",
268
+ "default": {
269
+ "_id": "Option",
270
+ "_tag": "Some",
271
+ "value": "foo",
272
+ },
273
+ "nullable": true,
274
+ "primaryKey": false,
275
+ "schema": {
276
+ "ast": "Union",
277
+ "decodedAst": "Union",
278
+ "encodedAst": "Union",
279
+ },
220
280
  }
221
281
  `;