@lix-js/sdk 0.0.1 → 0.2.0

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 (359) hide show
  1. package/LICENSE +21 -0
  2. package/dist/account/database-schema.d.ts.map +1 -1
  3. package/dist/account/database-schema.js +2 -6
  4. package/dist/account/database-schema.js.map +1 -1
  5. package/dist/account/database-schema.test.js +4 -8
  6. package/dist/account/database-schema.test.js.map +1 -1
  7. package/dist/change/apply-changes.js +9 -9
  8. package/dist/change/apply-changes.js.map +1 -1
  9. package/dist/change/apply-changes.test.js +5 -5
  10. package/dist/change/apply-changes.test.js.map +1 -1
  11. package/dist/database/apply-schema.d.ts.map +1 -1
  12. package/dist/database/apply-schema.js +20 -72
  13. package/dist/database/apply-schema.js.map +1 -1
  14. package/dist/database/execute-sync.test.js +3 -3
  15. package/dist/database/execute-sync.test.js.map +1 -1
  16. package/dist/database/init-db.d.ts.map +1 -1
  17. package/dist/database/init-db.js +18 -3
  18. package/dist/database/init-db.js.map +1 -1
  19. package/dist/database/init-db.test.js +128 -17
  20. package/dist/database/init-db.test.js.map +1 -1
  21. package/dist/database/kysely-plugin/parse-jsonb-plugin-v1.d.ts.map +1 -1
  22. package/dist/database/kysely-plugin/parse-jsonb-plugin-v1.js +5 -2
  23. package/dist/database/kysely-plugin/parse-jsonb-plugin-v1.js.map +1 -1
  24. package/dist/database/mutation-log/database-schema.d.ts.map +1 -1
  25. package/dist/database/mutation-log/database-schema.js +1 -3
  26. package/dist/database/mutation-log/database-schema.js.map +1 -1
  27. package/dist/database/nano-id.d.ts +21 -0
  28. package/dist/database/nano-id.d.ts.map +1 -0
  29. package/dist/database/nano-id.js +58 -0
  30. package/dist/database/nano-id.js.map +1 -0
  31. package/dist/database/nano-id.test.d.ts +2 -0
  32. package/dist/database/nano-id.test.d.ts.map +1 -0
  33. package/dist/database/nano-id.test.js +13 -0
  34. package/dist/database/nano-id.test.js.map +1 -0
  35. package/dist/database/schema.d.ts +15 -23
  36. package/dist/database/schema.d.ts.map +1 -1
  37. package/dist/discussion/create-comment.d.ts +0 -2
  38. package/dist/discussion/create-comment.d.ts.map +1 -1
  39. package/dist/discussion/create-comment.js +0 -1
  40. package/dist/discussion/create-comment.js.map +1 -1
  41. package/dist/discussion/create-discussion.d.ts +3 -5
  42. package/dist/discussion/create-discussion.d.ts.map +1 -1
  43. package/dist/discussion/create-discussion.js +4 -5
  44. package/dist/discussion/create-discussion.js.map +1 -1
  45. package/dist/discussion/create-discussion.test.js +8 -34
  46. package/dist/discussion/create-discussion.test.js.map +1 -1
  47. package/dist/file-queue/file-handlers.d.ts +24 -0
  48. package/dist/file-queue/file-handlers.d.ts.map +1 -0
  49. package/dist/file-queue/file-handlers.js +209 -0
  50. package/dist/file-queue/file-handlers.js.map +1 -0
  51. package/dist/file-queue/file-queue-process.d.ts +5 -0
  52. package/dist/file-queue/file-queue-process.d.ts.map +1 -0
  53. package/dist/file-queue/file-queue-process.js +88 -0
  54. package/dist/file-queue/file-queue-process.js.map +1 -0
  55. package/dist/file-queue/file-queue-process.test.d.ts +2 -0
  56. package/dist/file-queue/file-queue-process.test.d.ts.map +1 -0
  57. package/dist/file-queue/file-queue-process.test.js +372 -0
  58. package/dist/file-queue/file-queue-process.test.js.map +1 -0
  59. package/dist/file-queue/file-queue-settled.d.ts +13 -0
  60. package/dist/file-queue/file-queue-settled.d.ts.map +1 -0
  61. package/dist/file-queue/file-queue-settled.js +25 -0
  62. package/dist/file-queue/file-queue-settled.js.map +1 -0
  63. package/dist/file-queue/file-queue-settled.test.d.ts +2 -0
  64. package/dist/file-queue/file-queue-settled.test.d.ts.map +1 -0
  65. package/dist/file-queue/file-queue-settled.test.js +47 -0
  66. package/dist/file-queue/file-queue-settled.test.js.map +1 -0
  67. package/dist/file-queue/index.d.ts +2 -0
  68. package/dist/file-queue/index.d.ts.map +1 -0
  69. package/dist/file-queue/index.js +2 -0
  70. package/dist/file-queue/index.js.map +1 -0
  71. package/dist/file-queue/with-skip-file-queue.d.ts +3 -0
  72. package/dist/file-queue/with-skip-file-queue.d.ts.map +1 -0
  73. package/dist/file-queue/with-skip-file-queue.js +26 -0
  74. package/dist/file-queue/with-skip-file-queue.js.map +1 -0
  75. package/dist/file-queue/with-skip-file-queue.test.d.ts +2 -0
  76. package/dist/file-queue/with-skip-file-queue.test.d.ts.map +1 -0
  77. package/dist/file-queue/with-skip-file-queue.test.js +138 -0
  78. package/dist/file-queue/with-skip-file-queue.test.js.map +1 -0
  79. package/dist/index.d.ts +2 -2
  80. package/dist/index.d.ts.map +1 -1
  81. package/dist/index.js +2 -2
  82. package/dist/index.js.map +1 -1
  83. package/dist/key-value/database-schema.d.ts +11 -2
  84. package/dist/key-value/database-schema.d.ts.map +1 -1
  85. package/dist/key-value/database-schema.js +7 -4
  86. package/dist/key-value/database-schema.js.map +1 -1
  87. package/dist/key-value/database-schema.test.js +21 -5
  88. package/dist/key-value/database-schema.test.js.map +1 -1
  89. package/dist/lix/close-lix.d.ts +8 -0
  90. package/dist/lix/close-lix.d.ts.map +1 -0
  91. package/dist/lix/close-lix.js +7 -0
  92. package/dist/lix/close-lix.js.map +1 -0
  93. package/dist/lix/index.d.ts +1 -0
  94. package/dist/lix/index.d.ts.map +1 -1
  95. package/dist/lix/index.js +1 -0
  96. package/dist/lix/index.js.map +1 -1
  97. package/dist/lix/merge.js +3 -3
  98. package/dist/lix/merge.js.map +1 -1
  99. package/dist/lix/merge.test.js +7 -18
  100. package/dist/lix/merge.test.js.map +1 -1
  101. package/dist/lix/new-lix.d.ts.map +1 -1
  102. package/dist/lix/new-lix.js +2 -3
  103. package/dist/lix/new-lix.js.map +1 -1
  104. package/dist/lix/open-lix-in-memory.test.js +2 -1
  105. package/dist/lix/open-lix-in-memory.test.js.map +1 -1
  106. package/dist/lix/open-lix.d.ts +19 -6
  107. package/dist/lix/open-lix.d.ts.map +1 -1
  108. package/dist/lix/open-lix.js +80 -18
  109. package/dist/lix/open-lix.js.map +1 -1
  110. package/dist/lix/open-lix.test.js +70 -7
  111. package/dist/lix/open-lix.test.js.map +1 -1
  112. package/dist/lix/to-blob.d.ts +11 -0
  113. package/dist/lix/to-blob.d.ts.map +1 -0
  114. package/dist/lix/to-blob.js +11 -0
  115. package/dist/lix/to-blob.js.map +1 -0
  116. package/dist/own-change-control/apply-own-change.d.ts +10 -0
  117. package/dist/own-change-control/apply-own-change.d.ts.map +1 -0
  118. package/dist/own-change-control/apply-own-change.js +69 -0
  119. package/dist/own-change-control/apply-own-change.js.map +1 -0
  120. package/dist/own-change-control/apply-own-change.test.d.ts +2 -0
  121. package/dist/own-change-control/apply-own-change.test.d.ts.map +1 -0
  122. package/dist/own-change-control/apply-own-change.test.js +297 -0
  123. package/dist/own-change-control/apply-own-change.test.js.map +1 -0
  124. package/dist/own-change-control/change-controlled-tables.d.ts +60 -0
  125. package/dist/own-change-control/change-controlled-tables.d.ts.map +1 -0
  126. package/dist/own-change-control/change-controlled-tables.js +70 -0
  127. package/dist/own-change-control/change-controlled-tables.js.map +1 -0
  128. package/dist/own-change-control/change-controlled-tables.test.d.ts +2 -0
  129. package/dist/own-change-control/change-controlled-tables.test.d.ts.map +1 -0
  130. package/dist/own-change-control/change-controlled-tables.test.js +48 -0
  131. package/dist/own-change-control/change-controlled-tables.test.js.map +1 -0
  132. package/dist/own-change-control/database-triggers.d.ts +5 -0
  133. package/dist/own-change-control/database-triggers.d.ts.map +1 -0
  134. package/dist/own-change-control/database-triggers.js +135 -0
  135. package/dist/own-change-control/database-triggers.js.map +1 -0
  136. package/dist/own-change-control/database-triggers.test.d.ts +2 -0
  137. package/dist/own-change-control/database-triggers.test.d.ts.map +1 -0
  138. package/dist/own-change-control/database-triggers.test.js +214 -0
  139. package/dist/own-change-control/database-triggers.test.js.map +1 -0
  140. package/dist/own-change-control/index.d.ts +2 -0
  141. package/dist/own-change-control/index.d.ts.map +1 -0
  142. package/dist/own-change-control/index.js +2 -0
  143. package/dist/own-change-control/index.js.map +1 -0
  144. package/dist/own-change-control/with-skip-own-change-control.d.ts +3 -0
  145. package/dist/own-change-control/with-skip-own-change-control.d.ts.map +1 -0
  146. package/dist/own-change-control/with-skip-own-change-control.js +28 -0
  147. package/dist/own-change-control/with-skip-own-change-control.js.map +1 -0
  148. package/dist/own-change-control/with-skip-own-change-control.test.d.ts +2 -0
  149. package/dist/own-change-control/with-skip-own-change-control.test.d.ts.map +1 -0
  150. package/dist/own-change-control/with-skip-own-change-control.test.js +49 -0
  151. package/dist/own-change-control/with-skip-own-change-control.test.js.map +1 -0
  152. package/dist/own-entity-change-control/apply-own-entity-change.js +2 -2
  153. package/dist/own-entity-change-control/apply-own-entity-change.js.map +1 -1
  154. package/dist/own-entity-change-control/apply-own-entity-change.test.js +9 -9
  155. package/dist/own-entity-change-control/apply-own-entity-change.test.js.map +1 -1
  156. package/dist/own-entity-change-control/database-triggers.js +6 -6
  157. package/dist/own-entity-change-control/database-triggers.js.map +1 -1
  158. package/dist/own-entity-change-control/database-triggers.test.js +1 -1
  159. package/dist/own-entity-change-control/database-triggers.test.js.map +1 -1
  160. package/dist/query-filter/version-change-in-difference.test.js +37 -29
  161. package/dist/query-filter/version-change-in-difference.test.js.map +1 -1
  162. package/dist/query-filter/version-change-in-symmetric-difference.test.js +37 -39
  163. package/dist/query-filter/version-change-in-symmetric-difference.test.js.map +1 -1
  164. package/dist/server-api-handler/environment/create-in-memory-environment.d.ts.map +1 -1
  165. package/dist/server-api-handler/environment/create-in-memory-environment.js +7 -3
  166. package/dist/server-api-handler/environment/create-in-memory-environment.js.map +1 -1
  167. package/dist/server-api-handler/environment/create-in-memory-environment.test.js +8 -7
  168. package/dist/server-api-handler/environment/create-in-memory-environment.test.js.map +1 -1
  169. package/dist/server-api-handler/routes/get-v1.d.ts.map +1 -1
  170. package/dist/server-api-handler/routes/get-v1.js +1 -2
  171. package/dist/server-api-handler/routes/get-v1.js.map +1 -1
  172. package/dist/server-api-handler/routes/get-v1.test.js +6 -5
  173. package/dist/server-api-handler/routes/get-v1.test.js.map +1 -1
  174. package/dist/server-api-handler/routes/new-v1.d.ts.map +1 -1
  175. package/dist/server-api-handler/routes/new-v1.js +3 -1
  176. package/dist/server-api-handler/routes/new-v1.js.map +1 -1
  177. package/dist/server-api-handler/routes/new-v1.test.js +2 -1
  178. package/dist/server-api-handler/routes/new-v1.test.js.map +1 -1
  179. package/dist/server-api-handler/routes/pull-v1.test.js +4 -3
  180. package/dist/server-api-handler/routes/pull-v1.test.js.map +1 -1
  181. package/dist/server-api-handler/routes/push-v1.test.js +5 -4
  182. package/dist/server-api-handler/routes/push-v1.test.js.map +1 -1
  183. package/dist/services/env-variables/index.d.ts +5 -0
  184. package/dist/services/env-variables/index.d.ts.map +1 -0
  185. package/dist/services/env-variables/index.js +5 -0
  186. package/dist/services/env-variables/index.js.map +1 -0
  187. package/dist/services/telemetry/capture.d.ts +30 -0
  188. package/dist/services/telemetry/capture.d.ts.map +1 -0
  189. package/dist/services/telemetry/capture.js +71 -0
  190. package/dist/services/telemetry/capture.js.map +1 -0
  191. package/dist/services/telemetry/capture.test.d.ts +2 -0
  192. package/dist/services/telemetry/capture.test.d.ts.map +1 -0
  193. package/dist/services/telemetry/capture.test.js +37 -0
  194. package/dist/services/telemetry/capture.test.js.map +1 -0
  195. package/dist/sync/pull-from-server.d.ts.map +1 -1
  196. package/dist/sync/pull-from-server.js +0 -2
  197. package/dist/sync/pull-from-server.js.map +1 -1
  198. package/dist/sync/pull-from-server.test.js +29 -14
  199. package/dist/sync/pull-from-server.test.js.map +1 -1
  200. package/dist/sync/push-to-server.test.js +17 -13
  201. package/dist/sync/push-to-server.test.js.map +1 -1
  202. package/dist/sync/sync-process.d.ts +2 -4
  203. package/dist/sync/sync-process.d.ts.map +1 -1
  204. package/dist/sync/sync-process.js +14 -13
  205. package/dist/sync/sync-process.js.map +1 -1
  206. package/dist/sync/sync-process.test.js +26 -38
  207. package/dist/sync/sync-process.test.js.map +1 -1
  208. package/dist/version/create-version.d.ts +5 -5
  209. package/dist/version/create-version.d.ts.map +1 -1
  210. package/dist/version/create-version.js +23 -11
  211. package/dist/version/create-version.js.map +1 -1
  212. package/dist/version/create-version.test.js +2 -2
  213. package/dist/version/create-version.test.js.map +1 -1
  214. package/dist/version/merge-version.d.ts.map +1 -1
  215. package/dist/version/merge-version.js +16 -26
  216. package/dist/version/merge-version.js.map +1 -1
  217. package/dist/version/switch-version.js +3 -3
  218. package/dist/version/switch-version.js.map +1 -1
  219. package/dist/version/switch-version.test.js +12 -15
  220. package/dist/version/switch-version.test.js.map +1 -1
  221. package/dist/version/update-changes-in-version.d.ts.map +1 -1
  222. package/dist/version/update-changes-in-version.js +11 -31
  223. package/dist/version/update-changes-in-version.js.map +1 -1
  224. package/package.json +7 -9
  225. package/src/account/database-schema.test.ts +6 -9
  226. package/src/account/database-schema.ts +2 -6
  227. package/src/change/apply-changes.test.ts +7 -7
  228. package/src/change/apply-changes.ts +9 -9
  229. package/src/database/apply-schema.ts +20 -73
  230. package/src/database/execute-sync.test.ts +3 -3
  231. package/src/database/init-db.test.ts +163 -19
  232. package/src/database/init-db.ts +20 -3
  233. package/src/database/kysely-plugin/parse-jsonb-plugin-v1.ts +9 -2
  234. package/src/database/mutation-log/database-schema.ts +1 -3
  235. package/src/database/nano-id.test.ts +15 -0
  236. package/src/database/nano-id.ts +72 -0
  237. package/src/database/schema.ts +15 -24
  238. package/src/discussion/create-comment.ts +0 -3
  239. package/src/discussion/create-discussion.test.ts +8 -39
  240. package/src/discussion/create-discussion.ts +6 -9
  241. package/src/{change-queue → file-queue}/file-handlers.ts +27 -27
  242. package/src/{change-queue/init-change-queue.test.ts → file-queue/file-queue-process.test.ts} +28 -29
  243. package/src/{change-queue/init-change-queue.ts → file-queue/file-queue-process.ts} +21 -16
  244. package/src/{change-queue/change-queue-settled.test.ts → file-queue/file-queue-settled.test.ts} +12 -12
  245. package/src/{change-queue/change-queue-settled.ts → file-queue/file-queue-settled.ts} +4 -4
  246. package/src/file-queue/index.ts +1 -0
  247. package/src/{change-queue/with-skip-change-queue.test.ts → file-queue/with-skip-file-queue.test.ts} +9 -9
  248. package/src/{change-queue/with-skip-change-queue.ts → file-queue/with-skip-file-queue.ts} +3 -3
  249. package/src/index.ts +2 -2
  250. package/src/key-value/database-schema.test.ts +26 -5
  251. package/src/key-value/database-schema.ts +18 -6
  252. package/src/lix/close-lix.ts +8 -0
  253. package/src/lix/index.ts +1 -0
  254. package/src/lix/merge.test.ts +7 -19
  255. package/src/lix/merge.ts +4 -4
  256. package/src/lix/new-lix.ts +2 -3
  257. package/src/lix/open-lix-in-memory.test.ts +5 -1
  258. package/src/lix/open-lix.test.ts +82 -7
  259. package/src/lix/open-lix.ts +104 -24
  260. package/src/lix/to-blob.ts +14 -0
  261. package/src/{own-entity-change-control/apply-own-entity-change.test.ts → own-change-control/apply-own-change.test.ts} +27 -31
  262. package/src/{own-entity-change-control/apply-own-entity-change.ts → own-change-control/apply-own-change.ts} +3 -3
  263. package/src/{own-entity-change-control → own-change-control}/change-controlled-tables.ts +0 -1
  264. package/src/{own-entity-change-control → own-change-control}/database-triggers.test.ts +7 -7
  265. package/src/{own-entity-change-control → own-change-control}/database-triggers.ts +11 -11
  266. package/src/{own-entity-change-control → own-change-control}/with-skip-own-change-control.ts +6 -2
  267. package/src/query-filter/version-change-in-difference.test.ts +41 -32
  268. package/src/query-filter/version-change-in-symmetric-difference.test.ts +41 -42
  269. package/src/server-api-handler/environment/create-in-memory-environment.test.ts +8 -7
  270. package/src/server-api-handler/environment/create-in-memory-environment.ts +7 -3
  271. package/src/server-api-handler/routes/get-v1.test.ts +6 -5
  272. package/src/server-api-handler/routes/get-v1.ts +1 -3
  273. package/src/server-api-handler/routes/new-v1.test.ts +2 -1
  274. package/src/server-api-handler/routes/new-v1.ts +3 -1
  275. package/src/server-api-handler/routes/pull-v1.test.ts +4 -3
  276. package/src/server-api-handler/routes/push-v1.test.ts +5 -4
  277. package/src/services/env-variables/create-index-file.js +35 -0
  278. package/src/services/env-variables/index.d.ts +15 -0
  279. package/src/services/telemetry/capture.test.ts +44 -0
  280. package/src/services/telemetry/capture.ts +99 -0
  281. package/src/sync/pull-from-server.test.ts +29 -14
  282. package/src/sync/pull-from-server.ts +0 -2
  283. package/src/sync/push-to-server.test.ts +19 -15
  284. package/src/sync/sync-process.test.ts +37 -43
  285. package/src/sync/sync-process.ts +16 -23
  286. package/src/version/create-version.test.ts +2 -2
  287. package/src/version/create-version.ts +24 -12
  288. package/src/version/merge-version.ts +18 -26
  289. package/src/version/switch-version.test.ts +12 -15
  290. package/src/version/switch-version.ts +3 -3
  291. package/src/version/update-changes-in-version.ts +11 -30
  292. package/node_modules/@lix-js/server-api-schema/.prettierrc.json +0 -3
  293. package/node_modules/@lix-js/server-api-schema/.vscode/extensions.json +0 -3
  294. package/node_modules/@lix-js/server-api-schema/dist/schema.d.ts +0 -384
  295. package/node_modules/@lix-js/server-api-schema/package.json +0 -21
  296. package/node_modules/@lix-js/server-api-schema/src/schema.yaml +0 -290
  297. package/node_modules/@lix-js/server-api-schema/tsconfig.json +0 -20
  298. package/node_modules/sqlite-wasm-kysely/README.md +0 -11
  299. package/node_modules/sqlite-wasm-kysely/dist/dialect.d.ts +0 -11
  300. package/node_modules/sqlite-wasm-kysely/dist/dialect.js +0 -13
  301. package/node_modules/sqlite-wasm-kysely/dist/dialect.js.map +0 -1
  302. package/node_modules/sqlite-wasm-kysely/dist/index.d.ts +0 -2
  303. package/node_modules/sqlite-wasm-kysely/dist/index.js +0 -3
  304. package/node_modules/sqlite-wasm-kysely/dist/index.js.map +0 -1
  305. package/node_modules/sqlite-wasm-kysely/dist/kysely/ConnectionMutex.d.ts +0 -5
  306. package/node_modules/sqlite-wasm-kysely/dist/kysely/ConnectionMutex.js +0 -34
  307. package/node_modules/sqlite-wasm-kysely/dist/kysely/ConnectionMutex.js.map +0 -1
  308. package/node_modules/sqlite-wasm-kysely/dist/kysely/SqliteWasmConnection.d.ts +0 -8
  309. package/node_modules/sqlite-wasm-kysely/dist/kysely/SqliteWasmConnection.js +0 -57
  310. package/node_modules/sqlite-wasm-kysely/dist/kysely/SqliteWasmConnection.js.map +0 -1
  311. package/node_modules/sqlite-wasm-kysely/dist/kysely/SqliteWasmDialectConfig.d.ts +0 -18
  312. package/node_modules/sqlite-wasm-kysely/dist/kysely/SqliteWasmDialectConfig.js +0 -2
  313. package/node_modules/sqlite-wasm-kysely/dist/kysely/SqliteWasmDialectConfig.js.map +0 -1
  314. package/node_modules/sqlite-wasm-kysely/dist/kysely/SqliteWasmDriver.d.ts +0 -13
  315. package/node_modules/sqlite-wasm-kysely/dist/kysely/SqliteWasmDriver.js +0 -57
  316. package/node_modules/sqlite-wasm-kysely/dist/kysely/SqliteWasmDriver.js.map +0 -1
  317. package/node_modules/sqlite-wasm-kysely/dist/kysely/index.d.ts +0 -4
  318. package/node_modules/sqlite-wasm-kysely/dist/kysely/index.js +0 -4
  319. package/node_modules/sqlite-wasm-kysely/dist/kysely/index.js.map +0 -1
  320. package/node_modules/sqlite-wasm-kysely/dist/kysely/sqliteModule.d.ts +0 -3
  321. package/node_modules/sqlite-wasm-kysely/dist/kysely/sqliteModule.js +0 -5
  322. package/node_modules/sqlite-wasm-kysely/dist/kysely/sqliteModule.js.map +0 -1
  323. package/node_modules/sqlite-wasm-kysely/dist/util/contentFromDatabase.d.ts +0 -9
  324. package/node_modules/sqlite-wasm-kysely/dist/util/contentFromDatabase.js +0 -12
  325. package/node_modules/sqlite-wasm-kysely/dist/util/contentFromDatabase.js.map +0 -1
  326. package/node_modules/sqlite-wasm-kysely/dist/util/createInMemoryDatabase.d.ts +0 -3
  327. package/node_modules/sqlite-wasm-kysely/dist/util/createInMemoryDatabase.js +0 -22
  328. package/node_modules/sqlite-wasm-kysely/dist/util/createInMemoryDatabase.js.map +0 -1
  329. package/node_modules/sqlite-wasm-kysely/dist/util/importDatabase.d.ts +0 -7
  330. package/node_modules/sqlite-wasm-kysely/dist/util/importDatabase.js +0 -15
  331. package/node_modules/sqlite-wasm-kysely/dist/util/importDatabase.js.map +0 -1
  332. package/node_modules/sqlite-wasm-kysely/dist/util/index.d.ts +0 -5
  333. package/node_modules/sqlite-wasm-kysely/dist/util/index.js +0 -5
  334. package/node_modules/sqlite-wasm-kysely/dist/util/index.js.map +0 -1
  335. package/node_modules/sqlite-wasm-kysely/dist/util/loadDatabaseInMemory.d.ts +0 -1
  336. package/node_modules/sqlite-wasm-kysely/dist/util/loadDatabaseInMemory.js +0 -13
  337. package/node_modules/sqlite-wasm-kysely/dist/util/loadDatabaseInMemory.js.map +0 -1
  338. package/node_modules/sqlite-wasm-kysely/dist/util/sqliteWasmBinary.d.ts +0 -7
  339. package/node_modules/sqlite-wasm-kysely/dist/util/sqliteWasmBinary.js +0 -17
  340. package/node_modules/sqlite-wasm-kysely/dist/util/sqliteWasmBinary.js.map +0 -1
  341. package/node_modules/sqlite-wasm-kysely/package.json +0 -34
  342. package/node_modules/sqlite-wasm-kysely/src/dialect.ts +0 -15
  343. package/node_modules/sqlite-wasm-kysely/src/index.ts +0 -2
  344. package/node_modules/sqlite-wasm-kysely/src/kysely/ConnectionMutex.ts +0 -23
  345. package/node_modules/sqlite-wasm-kysely/src/kysely/SqliteWasmConnection.ts +0 -57
  346. package/node_modules/sqlite-wasm-kysely/src/kysely/SqliteWasmDialectConfig.ts +0 -19
  347. package/node_modules/sqlite-wasm-kysely/src/kysely/SqliteWasmDriver.ts +0 -58
  348. package/node_modules/sqlite-wasm-kysely/src/kysely/index.ts +0 -4
  349. package/node_modules/sqlite-wasm-kysely/src/kysely/sqliteModule.ts +0 -7
  350. package/node_modules/sqlite-wasm-kysely/src/util/contentFromDatabase.ts +0 -13
  351. package/node_modules/sqlite-wasm-kysely/src/util/createInMemoryDatabase.ts +0 -30
  352. package/node_modules/sqlite-wasm-kysely/src/util/importDatabase.ts +0 -34
  353. package/node_modules/sqlite-wasm-kysely/src/util/index.ts +0 -5
  354. package/node_modules/sqlite-wasm-kysely/src/util/loadDatabaseInMemory.ts +0 -13
  355. package/node_modules/sqlite-wasm-kysely/src/util/sqliteWasmBinary.ts +0 -20
  356. package/src/change-queue/index.ts +0 -1
  357. /package/src/{own-entity-change-control → own-change-control}/change-controlled-tables.test.ts +0 -0
  358. /package/src/{own-entity-change-control → own-change-control}/index.ts +0 -0
  359. /package/src/{own-entity-change-control → own-change-control}/with-skip-own-change-control.test.ts +0 -0
@@ -0,0 +1,99 @@
1
+ import { ENV_VARIABLES } from "../env-variables/index.js";
2
+
3
+ /**
4
+ * List of telemetry events for typesafety.
5
+ *
6
+ * - prefix with `SDK` to avoid collisions with other apps
7
+ * - use past tense to indicate that the event is completed
8
+ */
9
+ type TelemetryEvent = "LIX-SDK lix opened";
10
+
11
+ /**
12
+ * Capture an event.
13
+ *
14
+ * - manually calling the PostHog API because the SDKs were not platform angostic (and generally bloated)
15
+ */
16
+ export const capture = async (
17
+ event: TelemetryEvent,
18
+ args: {
19
+ lixId: string;
20
+ accountId: string;
21
+ /**
22
+ * The value of the telemetry key-value pair.
23
+ *
24
+ * @example
25
+ * const telemetryKeyValue = await lix.db.selectFrom("key_value").select("value").where("key", "=", "lix_telemetry").executeTakeFirstOrThrow();
26
+ * await capture("LIX-SDK opened lix", { lixId: "test", accountId: "test", telemetryKeyValue: telemetryKeyValue.value, properties: {} });
27
+ */
28
+ telemetryKeyValue: string;
29
+ /**
30
+ * Please use snake_case for property names.
31
+ */
32
+ properties: Record<string, any>;
33
+ }
34
+ ): Promise<void> => {
35
+ if (ENV_VARIABLES.LIX_SDK_POSTHOG_TOKEN === undefined) {
36
+ return;
37
+ } else if (args.telemetryKeyValue === "off") {
38
+ return;
39
+ }
40
+ try {
41
+ await fetch("https://eu.posthog.com/capture/", {
42
+ method: "POST",
43
+ body: JSON.stringify({
44
+ api_key: ENV_VARIABLES.LIX_SDK_POSTHOG_TOKEN,
45
+ event,
46
+ distinct_id: args.accountId,
47
+ properties: {
48
+ $groups: { lix_id: args.lixId },
49
+ ...args.properties,
50
+ },
51
+ }),
52
+ });
53
+ await identifyLix({
54
+ lixId: args.lixId,
55
+ accountId: args.accountId,
56
+ // using the id for now as a name but can be changed in the future
57
+ // we need at least one property to make a project visible in the dashboard
58
+ properties: { name: args.lixId },
59
+ });
60
+ } catch {
61
+ //
62
+ }
63
+ };
64
+
65
+ /**
66
+ * Identifying a project is needed.
67
+ *
68
+ * Otherwise, the project will not be visible in the PostHog dashboard.
69
+ */
70
+ const identifyLix = async (args: {
71
+ lixId: string;
72
+ accountId: string;
73
+ properties: Record<string, string>;
74
+ }) => {
75
+ // do not send events if the token is not set
76
+ // (assuming this eases testing)
77
+ if (ENV_VARIABLES.LIX_SDK_POSTHOG_TOKEN === undefined) {
78
+ return;
79
+ }
80
+ try {
81
+ await fetch("https://eu.posthog.com/capture/", {
82
+ method: "POST",
83
+ body: JSON.stringify({
84
+ api_key: ENV_VARIABLES.LIX_SDK_POSTHOG_TOKEN,
85
+ event: "$groupidentify",
86
+ distinct_id: args.accountId,
87
+ properties: {
88
+ $group_type: "lix",
89
+ $group_key: args.lixId,
90
+ $group_set: {
91
+ ...args.properties,
92
+ },
93
+ },
94
+ }),
95
+ });
96
+ } catch {
97
+ //
98
+ }
99
+ };
@@ -4,11 +4,14 @@ import { openLixInMemory } from "../lix/open-lix-in-memory.js";
4
4
  import { pullFromServer } from "./pull-from-server.js";
5
5
  import { mockJsonSnapshot } from "../snapshot/mock-json-snapshot.js";
6
6
  import { createLsaInMemoryEnvironment } from "../server-api-handler/environment/create-in-memory-environment.js";
7
+ import { toBlob } from "../lix/to-blob.js";
7
8
 
8
9
  test("pull rows of multiple tables from server successfully and applies them", async () => {
9
10
  const lixOnServer = await openLixInMemory({});
10
11
 
11
- const lix = await openLixInMemory({ blob: await lixOnServer.toBlob() });
12
+ const lix = await openLixInMemory({
13
+ blob: await toBlob({ lix: lixOnServer }),
14
+ });
12
15
 
13
16
  const { value: id } = await lixOnServer.db
14
17
  .selectFrom("key_value")
@@ -38,7 +41,7 @@ test("pull rows of multiple tables from server successfully and applies them", a
38
41
  await lsaHandler(
39
42
  new Request("http://localhost:3000/lsa/new-v1", {
40
43
  method: "POST",
41
- body: await lixOnServer.toBlob(),
44
+ body: await toBlob({ lix: lixOnServer }),
42
45
  headers: {
43
46
  "Content-Type": "application/json",
44
47
  },
@@ -66,13 +69,15 @@ test("pull rows of multiple tables from server successfully and applies them", a
66
69
  .executeTakeFirstOrThrow();
67
70
 
68
71
  expect(account).toEqual({ id: "account0", name: "test account" });
69
- expect(mockKey).toEqual({ key: "mock-key", value: "mock-value" });
72
+ expect(mockKey).toMatchObject({ key: "mock-key", value: "mock-value" });
70
73
  });
71
74
 
72
75
  test("it handles snapshot.content being json binary", async () => {
73
76
  const lixOnServer = await openLixInMemory({});
74
77
 
75
- const lix = await openLixInMemory({ blob: await lixOnServer.toBlob() });
78
+ const lix = await openLixInMemory({
79
+ blob: await toBlob({ lix: lixOnServer }),
80
+ });
76
81
 
77
82
  const { value: id } = await lixOnServer.db
78
83
  .selectFrom("key_value")
@@ -101,7 +106,7 @@ test("it handles snapshot.content being json binary", async () => {
101
106
  await lsaHandler(
102
107
  new Request("http://localhost:3000/lsa/new-v1", {
103
108
  method: "POST",
104
- body: await lixOnServer.toBlob(),
109
+ body: await toBlob({ lix: lixOnServer }),
105
110
  headers: {
106
111
  "Content-Type": "application/json",
107
112
  },
@@ -141,7 +146,9 @@ test("rows changed on the client more recently should not be updated", async ()
141
146
  })
142
147
  .executeTakeFirstOrThrow();
143
148
 
144
- const lix = await openLixInMemory({ blob: await lixOnServer.toBlob() });
149
+ const lix = await openLixInMemory({
150
+ blob: await toBlob({ lix: lixOnServer }),
151
+ });
145
152
 
146
153
  const environment = createLsaInMemoryEnvironment();
147
154
  const lsaHandler = await createServerApiHandler({ environment });
@@ -152,7 +159,7 @@ test("rows changed on the client more recently should not be updated", async ()
152
159
  await lsaHandler(
153
160
  new Request("http://localhost:3000/lsa/new-v1", {
154
161
  method: "POST",
155
- body: await lixOnServer.toBlob(),
162
+ body: await toBlob({ lix: lixOnServer }),
156
163
  headers: {
157
164
  "Content-Type": "application/json",
158
165
  },
@@ -179,7 +186,10 @@ test("rows changed on the client more recently should not be updated", async ()
179
186
  .selectAll()
180
187
  .executeTakeFirstOrThrow();
181
188
 
182
- expect(mockKey).toEqual({ key: "mock-key", value: "mock-value-updated" });
189
+ expect(mockKey).toMatchObject({
190
+ key: "mock-key",
191
+ value: "mock-value-updated",
192
+ });
183
193
  });
184
194
 
185
195
  // the change table now models "change control". no more last edit wins needed
@@ -192,7 +202,9 @@ test.skip("rows changed on the server more recently should be updated on the cli
192
202
 
193
203
  // create a lix and clone it for the client - so they share the same lix id
194
204
  const remoteLix = await openLixInMemory({});
195
- const localLix = await openLixInMemory({ blob: await remoteLix.toBlob() });
205
+ const localLix = await openLixInMemory({
206
+ blob: await toBlob({ lix: remoteLix }),
207
+ });
196
208
 
197
209
  // insert mock data into server lix
198
210
  await remoteLix.db
@@ -234,7 +246,7 @@ test.skip("rows changed on the server more recently should be updated on the cli
234
246
  await lsaHandler(
235
247
  new Request("http://localhost:3000/lsa/new-v1", {
236
248
  method: "POST",
237
- body: await remoteLix.toBlob(),
249
+ body: await toBlob({ lix: remoteLix }),
238
250
  headers: {
239
251
  "Content-Type": "application/json",
240
252
  },
@@ -347,7 +359,7 @@ test("non-conflicting changes from the server should for the same version should
347
359
 
348
360
  global.fetch = vi.fn((request) => lsaHandler(request));
349
361
 
350
- const lixOnServer = await openLixInMemory({ blob: await lix.toBlob() });
362
+ const lixOnServer = await openLixInMemory({ blob: await toBlob({ lix }) });
351
363
 
352
364
  // insert data on the server that the client does not have yet
353
365
  await lixOnServer.db
@@ -369,7 +381,10 @@ test("non-conflicting changes from the server should for the same version should
369
381
  expect.arrayContaining([
370
382
  expect.objectContaining({
371
383
  version_id: currentVersion.id,
372
- content: { key: "mock-key", value: "mock-value" },
384
+ content: expect.objectContaining({
385
+ key: "mock-key",
386
+ value: "mock-value",
387
+ }),
373
388
  }),
374
389
  ])
375
390
  );
@@ -377,7 +392,7 @@ test("non-conflicting changes from the server should for the same version should
377
392
  await lsaHandler(
378
393
  new Request("http://localhost:3000/lsa/new-v1", {
379
394
  method: "POST",
380
- body: await lixOnServer.toBlob(),
395
+ body: await toBlob({ lix: lixOnServer }),
381
396
  headers: {
382
397
  "Content-Type": "application/json",
383
398
  },
@@ -405,6 +420,6 @@ test("non-conflicting changes from the server should for the same version should
405
420
  .select("snapshot.content as content")
406
421
  .execute();
407
422
 
408
- expect(mockKey).toEqual({ key: "mock-key", value: "mock-value" });
423
+ expect(mockKey).toMatchObject({ key: "mock-key", value: "mock-value" });
409
424
  expect(versionChanges).toEqual(expect.arrayContaining(serverVersionChanges));
410
425
  });
@@ -133,8 +133,6 @@ export async function pullFromServer(args: {
133
133
  });
134
134
 
135
135
  if (changesToApply.length > 0) {
136
- // the changes already exists hence prevent own change control
137
- // from creating new changes for the applied changes
138
136
  await applyChanges({
139
137
  lix: { ...args.lix, db: trx },
140
138
  changes: changesToApply,
@@ -5,10 +5,11 @@ import { pushToServer } from "./push-to-server.js";
5
5
  import type { LixFile } from "../database/schema.js";
6
6
  import type { Account } from "../account/database-schema.js";
7
7
  import { newLixFile } from "../lix/new-lix.js";
8
- import type { KeyValue } from "../key-value/database-schema.js";
8
+ import type { NewKeyValue } from "../key-value/database-schema.js";
9
9
  import { mockJsonSnapshot } from "../snapshot/mock-json-snapshot.js";
10
10
  import { pullFromServer } from "./pull-from-server.js";
11
11
  import { createLsaInMemoryEnvironment } from "../server-api-handler/environment/create-in-memory-environment.js";
12
+ import { toBlob } from "../lix/to-blob.js";
12
13
 
13
14
  test("push rows of multiple tables to server successfully", async () => {
14
15
  const lixBlob = await newLixFile();
@@ -30,7 +31,7 @@ test("push rows of multiple tables to server successfully", async () => {
30
31
  await lsaHandler(
31
32
  new Request("http://localhost:3000/lsa/new-v1", {
32
33
  method: "POST",
33
- body: await lix.toBlob(),
34
+ body: await toBlob({ lix }),
34
35
  })
35
36
  );
36
37
 
@@ -83,11 +84,11 @@ test("push rows of multiple tables to server successfully", async () => {
83
84
  { id: "account0", name: "some account" } satisfies Account,
84
85
  ]);
85
86
  expect(keyValueChangesOnServer.map((c) => c.content)).toEqual([
86
- {
87
+ expect.objectContaining({
87
88
  key: "mock-key",
88
89
  value: "mock-value",
89
- },
90
- ] satisfies KeyValue[]);
90
+ }),
91
+ ] satisfies NewKeyValue[]);
91
92
  });
92
93
 
93
94
  test("push-pull-push with two clients", async () => {
@@ -111,7 +112,7 @@ test("push-pull-push with two clients", async () => {
111
112
  await lsaHandler(
112
113
  new Request("http://localhost:3000/lsa/new-v1", {
113
114
  method: "POST",
114
- body: await client1.toBlob(),
115
+ body: await toBlob({ lix: client1 }),
115
116
  })
116
117
  );
117
118
 
@@ -165,10 +166,10 @@ test("push-pull-push with two clients", async () => {
165
166
 
166
167
  expect(client2KeyValueAfterPull).toEqual(
167
168
  expect.arrayContaining([
168
- {
169
+ expect.objectContaining({
169
170
  key: "mock-key",
170
171
  value: "mock-value from client 1",
171
- } satisfies KeyValue,
172
+ } satisfies NewKeyValue),
172
173
  ])
173
174
  );
174
175
 
@@ -260,15 +261,18 @@ test("push-pull-push with two clients", async () => {
260
261
 
261
262
  expect(keyValueChangesOnServer.map((c) => c.content)).toEqual(
262
263
  expect.arrayContaining([
263
- {
264
+ expect.objectContaining({
264
265
  key: "mock-key",
265
266
  value: "mock-value from client 1",
266
- },
267
- {
267
+ }),
268
+ expect.objectContaining({
268
269
  key: "mock-key",
269
270
  value: "mock-value from client 1 - updated by client 2",
270
- },
271
- { key: "mock-key-2", value: "mock-value from client 2" },
271
+ }),
272
+ expect.objectContaining({
273
+ key: "mock-key-2",
274
+ value: "mock-value from client 2",
275
+ }),
272
276
  ])
273
277
  );
274
278
  });
@@ -291,7 +295,7 @@ test("it should handle snapshots.content json binaries", async () => {
291
295
  await lsaHandler(
292
296
  new Request("http://localhost:3000/lsa/new-v1", {
293
297
  method: "POST",
294
- body: await lix.toBlob(),
298
+ body: await toBlob({ lix }),
295
299
  })
296
300
  );
297
301
 
@@ -345,7 +349,7 @@ test.todo("it should handle binary values", async () => {
345
349
  await lsaHandler(
346
350
  new Request("http://localhost:3000/lsa/new", {
347
351
  method: "POST",
348
- body: await lix.toBlob(),
352
+ body: await toBlob({ lix }),
349
353
  })
350
354
  );
351
355
 
@@ -8,6 +8,7 @@ import { createVersion } from "../version/create-version.js";
8
8
  import { switchVersion } from "../version/switch-version.js";
9
9
  import type { Version } from "../database/schema.js";
10
10
  import { executeSync } from "../database/execute-sync.js";
11
+ import { toBlob } from "../lix/to-blob.js";
11
12
 
12
13
  test("versions should be synced", async () => {
13
14
  const environment = createLsaInMemoryEnvironment();
@@ -16,7 +17,7 @@ test("versions should be synced", async () => {
16
17
  global.fetch = vi.fn((request) => lsaHandler(request));
17
18
 
18
19
  const lix0 = await openLixInMemory({
19
- keyValues: [{ key: "#lix_sync", value: "true" }],
20
+ keyValues: [{ key: "lix_server_url", value: "http://mock.com" }],
20
21
  });
21
22
 
22
23
  // @ts-expect-error - eases debugging
@@ -32,32 +33,26 @@ test("versions should be synced", async () => {
32
33
  await lsaHandler(
33
34
  new Request("http://mock.com/lsa/new-v1", {
34
35
  method: "POST",
35
- body: await lix0.toBlob(),
36
+ body: await toBlob({ lix: lix0 }),
36
37
  })
37
38
  );
38
39
 
39
40
  // create a second client
40
41
  const lix1 = await openLixInMemory({
41
- blob: await lix0.toBlob(),
42
- keyValues: [{ key: "#lix_sync", value: "true" }],
42
+ blob: await toBlob({ lix: lix0 }),
43
+ keyValues: [{ key: "lix_sync", value: "true" }],
43
44
  });
44
45
 
45
46
  // start syncing
46
- await lix0.db
47
- .insertInto("key_value")
48
- .values({
49
- key: "lix_server_url",
50
- value: "http://mock.com",
51
- })
52
- .execute();
53
-
54
- await lix1.db
55
- .insertInto("key_value")
56
- .values({
57
- key: "lix_server_url",
58
- value: "http://mock.com",
59
- })
60
- .execute();
47
+ await Promise.all(
48
+ [lix0, lix1].map((lix) =>
49
+ lix.db
50
+ .updateTable("key_value")
51
+ .where("key", "=", "lix_sync")
52
+ .set({ value: "true" })
53
+ .execute()
54
+ )
55
+ );
61
56
 
62
57
  // @ts-expect-error - eases debugging
63
58
  lix1.db.__name = "lix1";
@@ -74,7 +69,7 @@ test("versions should be synced", async () => {
74
69
  .executeTakeFirstOrThrow();
75
70
  version0 = await createVersion({
76
71
  lix: { ...lix0, db: trx },
77
- parent: currentVersion,
72
+ from: currentVersion,
78
73
  name: "version0",
79
74
  });
80
75
  await switchVersion({ lix: { ...lix0, db: trx }, to: version0 });
@@ -113,17 +108,16 @@ test("versions should be synced", async () => {
113
108
  expect(lix0Versions).toEqual(lix1Versions);
114
109
 
115
110
  // expecting both lix0 and lix1 to have the same version changes
116
- const lix0VersionChanges = await lix0.db
117
- .selectFrom("version_change")
118
- .orderBy("change_id", "desc")
119
- .selectAll()
120
- .execute();
121
-
122
- const lix1VersionChanges = await lix1.db
123
- .selectFrom("version_change")
124
- .orderBy("change_id", "desc")
125
- .selectAll()
126
- .execute();
111
+ const [lix0VersionChanges, lix1VersionChanges] = await Promise.all(
112
+ [lix0, lix1].map((lix) =>
113
+ lix.db
114
+ .selectFrom("version_change")
115
+ .orderBy("change_id", "desc")
116
+ .orderBy("version_id", "desc")
117
+ .selectAll()
118
+ .execute()
119
+ )
120
+ );
127
121
 
128
122
  expect(lix0VersionChanges).toEqual(lix1VersionChanges);
129
123
  });
@@ -137,7 +131,7 @@ test("switching synced versions should work", async () => {
137
131
  global.executeSync = executeSync;
138
132
 
139
133
  const lix0 = await openLixInMemory({
140
- keyValues: [{ key: "#lix_sync", value: "true" }],
134
+ keyValues: [{ key: "lix_sync", value: "true" }],
141
135
  });
142
136
  // @ts-expect-error - eases debugging
143
137
  lix0.db.__name = "lix0";
@@ -154,7 +148,7 @@ test("switching synced versions should work", async () => {
154
148
  await lsaHandler(
155
149
  new Request("http://mock.com/lsa/new-v1", {
156
150
  method: "POST",
157
- body: await lix0.toBlob(),
151
+ body: await toBlob({ lix: lix0 }),
158
152
  })
159
153
  );
160
154
 
@@ -169,8 +163,8 @@ test("switching synced versions should work", async () => {
169
163
 
170
164
  // create a second client
171
165
  const lix1 = await openLixInMemory({
172
- blob: await lix0.toBlob(),
173
- keyValues: [{ key: "#lix_sync", value: "true" }],
166
+ blob: await toBlob({ lix: lix0 }),
167
+ keyValues: [{ key: "lix_sync", value: "true" }],
174
168
  });
175
169
 
176
170
  // @ts-expect-error - eases debugging
@@ -187,7 +181,7 @@ test("switching synced versions should work", async () => {
187
181
  const version0 = await createVersion({
188
182
  lix: lix0,
189
183
  name: "version0",
190
- parent: currentVersion,
184
+ from: currentVersion,
191
185
  });
192
186
 
193
187
  await switchVersion({ lix: lix0, to: version0 });
@@ -239,13 +233,13 @@ test("switching synced versions should work", async () => {
239
233
  .selectAll()
240
234
  .executeTakeFirst();
241
235
 
242
- expect(keyValue).toEqual({
236
+ expect(keyValue).toMatchObject({
243
237
  key: "mock-key",
244
238
  value: "mock",
245
239
  });
246
240
  });
247
241
 
248
- test("doesnt sync if #lix_sync is not true", async () => {
242
+ test("doesnt sync if lix_sync is not true", async () => {
249
243
  const environment = createLsaInMemoryEnvironment();
250
244
  const lsaHandler = await createServerApiHandler({ environment });
251
245
  global.fetch = vi.fn((request) => lsaHandler(request));
@@ -262,14 +256,14 @@ test("doesnt sync if #lix_sync is not true", async () => {
262
256
  await lsaHandler(
263
257
  new Request("http://mock.com/lsa/new-v1", {
264
258
  method: "POST",
265
- body: await lix.toBlob(),
259
+ body: await toBlob({ lix }),
266
260
  })
267
261
  );
268
262
 
269
263
  await lix.db
270
264
  .updateTable("key_value")
271
265
  .set({ value: "false" })
272
- .where("key", "=", "#lix_sync")
266
+ .where("key", "=", "lix_sync")
273
267
  .execute();
274
268
 
275
269
  await lix.db
@@ -301,7 +295,7 @@ test("doesnt sync if #lix_sync is not true", async () => {
301
295
  await lix.db
302
296
  .updateTable("key_value")
303
297
  .set({ value: "true" })
304
- .where("key", "=", "#lix_sync")
298
+ .where("key", "=", "lix_sync")
305
299
  .execute();
306
300
 
307
301
  await new Promise((resolve) => setTimeout(resolve, 1010));
@@ -317,10 +311,10 @@ test("doesnt sync if #lix_sync is not true", async () => {
317
311
  expect(keyValueChangesOnServerAfterSync).toEqual(
318
312
  expect.arrayContaining([
319
313
  expect.objectContaining({
320
- content: {
314
+ content: expect.objectContaining({
321
315
  key: "foo",
322
316
  value: "bar",
323
- },
317
+ }),
324
318
  }),
325
319
  ])
326
320
  );
@@ -1,27 +1,21 @@
1
1
  import type { Lix } from "../lix/open-lix.js";
2
2
  import { pushToServer } from "./push-to-server.js";
3
3
  import { pullFromServer } from "./pull-from-server.js";
4
+ import { toBlob } from "../lix/to-blob.js";
4
5
 
5
6
  export async function initSyncProcess(args: {
6
- lix: Pick<Lix, "db" | "plugin" | "toBlob">;
7
- }): Promise<
8
- | {
9
- stop: () => void;
10
- }
11
- | undefined
12
- > {
7
+ lix: Pick<Lix, "db" | "plugin" | "sqlite">;
8
+ }): Promise<void> {
13
9
  const lixId = await args.lix.db
14
10
  .selectFrom("key_value")
15
11
  .where("key", "=", "lix_id")
16
12
  .select("value")
17
13
  .executeTakeFirstOrThrow();
18
14
 
19
- let stoped = false;
20
-
21
15
  const pullAndPush = async () => {
22
16
  const shouldSync = await args.lix.db
23
17
  .selectFrom("key_value")
24
- .where("key", "=", "#lix_sync")
18
+ .where("key", "=", "lix_sync")
25
19
  .select("value")
26
20
  .executeTakeFirst();
27
21
 
@@ -40,7 +34,6 @@ export async function initSyncProcess(args: {
40
34
  if (!url) {
41
35
  return;
42
36
  }
43
-
44
37
  try {
45
38
  // console.log("----------- PULL FROM SERVER -------------");
46
39
  const serverState = await pullFromServer({
@@ -64,7 +57,7 @@ export async function initSyncProcess(args: {
64
57
  const response = await fetch(
65
58
  new Request(url.value + "/lsa/new-v1", {
66
59
  method: "POST",
67
- body: await args.lix.toBlob(),
60
+ body: await toBlob({ lix: args.lix }),
68
61
  })
69
62
  );
70
63
  if (!response.ok && response.status !== 409) {
@@ -77,21 +70,21 @@ export async function initSyncProcess(args: {
77
70
  // naive implementation that syncs every second
78
71
 
79
72
  function schedulePullAndPush() {
80
- if (!stoped) {
81
- pullAndPush().catch((e) => {
82
- console.error("Error in sync process", e);
83
- });
73
+ if (args.lix.sqlite.isOpen() === false) {
74
+ return;
84
75
  }
76
+ pullAndPush().catch((e) => {
77
+ if (e instanceof Error && e.message.includes("DB has been closed.")) {
78
+ // stop the syncing process, the database has been closed.
79
+ return;
80
+ }
81
+ console.error("Error in sync process", e);
82
+ });
83
+ // schedule next sync
85
84
  setTimeout(() => {
86
85
  schedulePullAndPush();
87
- }, 1000);
86
+ }, 750);
88
87
  }
89
88
 
90
89
  schedulePullAndPush();
91
-
92
- return {
93
- stop: () => {
94
- stoped = true;
95
- },
96
- };
97
90
  }
@@ -42,7 +42,7 @@ test("it should copy the changes from the parent version", async () => {
42
42
 
43
43
  const version1 = await createVersion({
44
44
  lix,
45
- parent: version0,
45
+ from: version0,
46
46
  });
47
47
 
48
48
  const changesInversion0 = await lix.db
@@ -132,7 +132,7 @@ test("it should copy change conflict pointers from the parent version", async ()
132
132
 
133
133
  const version1 = await createVersion({
134
134
  lix,
135
- parent: version0,
135
+ from: version0,
136
136
  name: "version1",
137
137
  });
138
138