@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
@@ -4,6 +4,7 @@ import type { VersionChange } from "../database/schema.js";
4
4
  import { mockChange } from "../change/mock-change.js";
5
5
  import { createVersion } from "../version/create-version.js";
6
6
  import { versionChangeInDifference } from "./version-change-in-difference.js";
7
+ import { updateChangesInVersion } from "../version/update-changes-in-version.js";
7
8
 
8
9
  test("should return the difference between two versions", async () => {
9
10
  const lix = await openLixInMemory({});
@@ -11,42 +12,42 @@ test("should return the difference between two versions", async () => {
11
12
  const versionA = await createVersion({ lix });
12
13
  const versionB = await createVersion({ lix });
13
14
 
15
+ const mockChanges = [
16
+ mockChange({ id: "change0", entity_id: "entity0" }),
17
+ mockChange({ id: "change1", entity_id: "entity1" }),
18
+ mockChange({ id: "change2", entity_id: "entity2" }),
19
+ mockChange({ id: "change3", entity_id: "entity3" }),
20
+ ] as const;
21
+
14
22
  await lix.db
15
23
  .insertInto("change")
16
- .values([
17
- mockChange({ id: "change1" }),
18
- mockChange({ id: "change2" }),
19
- mockChange({ id: "change3" }),
20
- mockChange({ id: "change4" }),
21
- ])
24
+ .values(mockChanges)
22
25
  .returningAll()
23
26
  .execute();
24
27
 
25
- const changesA: VersionChange[] = [
26
- { version_id: versionA.id, change_id: "change1" },
27
- { version_id: versionA.id, change_id: "change2" },
28
- ];
29
-
30
- const changesB: VersionChange[] = [
31
- { version_id: versionB.id, change_id: "change2" },
32
- { version_id: versionB.id, change_id: "change3" },
33
- ];
28
+ await updateChangesInVersion({
29
+ lix,
30
+ version: versionA,
31
+ changes: [mockChanges[0], mockChanges[1]],
32
+ });
34
33
 
35
- await lix.db
36
- .insertInto("version_change")
37
- .values([...changesA, ...changesB])
38
- .execute();
34
+ await updateChangesInVersion({
35
+ lix,
36
+ version: versionB,
37
+ changes: [mockChanges[1], mockChanges[2]],
38
+ });
39
39
 
40
40
  const result = await lix.db
41
41
  .selectFrom("version_change")
42
42
  .where(versionChangeInDifference(versionA, versionB))
43
- .selectAll()
43
+ .select("version_id")
44
+ .select("change_id")
44
45
  .execute();
45
46
 
46
47
  expect(result).toEqual([
47
- // change1 is in A but not in B
48
- { version_id: versionA.id, change_id: "change1" },
49
- ] satisfies VersionChange[]);
48
+ // change0 is in A but not in B
49
+ expect.objectContaining({ version_id: versionA.id, change_id: "change0" }),
50
+ ] satisfies Partial<VersionChange>[]);
50
51
  });
51
52
 
52
53
  test("should return an empty array if there are no differences", async () => {
@@ -55,20 +56,28 @@ test("should return an empty array if there are no differences", async () => {
55
56
  const versionA = await createVersion({ lix });
56
57
  const versionB = await createVersion({ lix });
57
58
 
59
+ const mockChanges = [
60
+ mockChange({ id: "change0" }),
61
+ mockChange({ id: "change1" }),
62
+ ];
63
+
58
64
  await lix.db
59
65
  .insertInto("change")
60
- .values([mockChange({ id: "change1" }), mockChange({ id: "change2" })])
66
+ .values(mockChanges)
61
67
  .returningAll()
62
68
  .execute();
63
69
 
64
- const changes: VersionChange[] = [
65
- { version_id: versionA.id, change_id: "change1" },
66
- { version_id: versionA.id, change_id: "change2" },
67
- { version_id: versionB.id, change_id: "change1" },
68
- { version_id: versionB.id, change_id: "change2" },
69
- ];
70
-
71
- await lix.db.insertInto("version_change").values(changes).execute();
70
+ await updateChangesInVersion({
71
+ lix,
72
+ version: versionA,
73
+ changes: mockChanges,
74
+ });
75
+
76
+ await updateChangesInVersion({
77
+ lix,
78
+ version: versionB,
79
+ changes: mockChanges,
80
+ });
72
81
 
73
82
  const result = await lix.db
74
83
  .selectFrom("version_change")
@@ -4,6 +4,7 @@ import type { VersionChange } from "../database/schema.js";
4
4
  import { mockChange } from "../change/mock-change.js";
5
5
  import { createVersion } from "../version/create-version.js";
6
6
  import { versionChangeInSymmetricDifference } from "./version-change-in-symmetric-difference.js";
7
+ import { updateChangesInVersion } from "../version/update-changes-in-version.js";
7
8
 
8
9
  test("should return the symmetric difference between two versions", async () => {
9
10
  const lix = await openLixInMemory({});
@@ -11,31 +12,26 @@ test("should return the symmetric difference between two versions", async () =>
11
12
  const versionA = await createVersion({ lix });
12
13
  const versionB = await createVersion({ lix });
13
14
 
14
- await lix.db
15
- .insertInto("change")
16
- .values([
17
- mockChange({ id: "change1" }),
18
- mockChange({ id: "change2" }),
19
- mockChange({ id: "change3" }),
20
- mockChange({ id: "change4" }),
21
- ])
22
- .returningAll()
23
- .execute();
15
+ const mockChanges = [
16
+ mockChange({ id: "change0", entity_id: "entity0" }),
17
+ mockChange({ id: "change1", entity_id: "entity1" }),
18
+ mockChange({ id: "change2", entity_id: "entity2" }),
19
+ mockChange({ id: "change3", entity_id: "entity3" }),
20
+ ] as const;
24
21
 
25
- const changesA: VersionChange[] = [
26
- { version_id: versionA.id, change_id: "change1" },
27
- { version_id: versionA.id, change_id: "change2" },
28
- ];
22
+ await lix.db.insertInto("change").values(mockChanges).execute();
29
23
 
30
- const changesB: VersionChange[] = [
31
- { version_id: versionB.id, change_id: "change2" },
32
- { version_id: versionB.id, change_id: "change3" },
33
- ];
24
+ await updateChangesInVersion({
25
+ lix,
26
+ version: versionA,
27
+ changes: [mockChanges[0], mockChanges[1]],
28
+ });
34
29
 
35
- await lix.db
36
- .insertInto("version_change")
37
- .values([...changesA, ...changesB])
38
- .execute();
30
+ await updateChangesInVersion({
31
+ lix,
32
+ version: versionB,
33
+ changes: [mockChanges[1], mockChanges[2]],
34
+ });
39
35
 
40
36
  const result = await lix.db
41
37
  .selectFrom("version_change")
@@ -44,13 +40,13 @@ test("should return the symmetric difference between two versions", async () =>
44
40
  .execute();
45
41
 
46
42
  expect(result).toEqual([
47
- // change 1 is in A but not in B
48
- { version_id: versionA.id, change_id: "change1" },
49
- // change 3 is in B but not in A
50
- { version_id: versionB.id, change_id: "change3" },
51
- // change 4 is in neither A nor B
43
+ // change 0 is in A but not in B
44
+ expect.objectContaining({ version_id: versionA.id, change_id: "change0" }),
45
+ // change 2 is in B but not in A
46
+ expect.objectContaining({ version_id: versionB.id, change_id: "change2" }),
47
+ // change 3 is in neither A nor B
52
48
  // hence not in the symmetric difference
53
- ] satisfies VersionChange[]);
49
+ ] satisfies Partial<VersionChange>[]);
54
50
  });
55
51
 
56
52
  test("should return an empty array if there are no differences", async () => {
@@ -59,25 +55,28 @@ test("should return an empty array if there are no differences", async () => {
59
55
  const versionA = await createVersion({ lix });
60
56
  const versionB = await createVersion({ lix });
61
57
 
58
+ const mockChanges = [
59
+ mockChange({ id: "change0", entity_id: "entity0" }),
60
+ mockChange({ id: "change1", entity_id: "entity1" }),
61
+ ] as const;
62
+
62
63
  await lix.db
63
64
  .insertInto("change")
64
- .values([
65
- mockChange({ id: "change1" }),
66
- mockChange({ id: "change2" }),
67
- mockChange({ id: "change3" }),
68
- mockChange({ id: "change4" }),
69
- ])
65
+ .values(mockChanges)
70
66
  .returningAll()
71
67
  .execute();
72
68
 
73
- const changes: VersionChange[] = [
74
- { version_id: versionA.id, change_id: "change1" },
75
- { version_id: versionA.id, change_id: "change2" },
76
- { version_id: versionB.id, change_id: "change1" },
77
- { version_id: versionB.id, change_id: "change2" },
78
- ];
79
-
80
- await lix.db.insertInto("version_change").values(changes).execute();
69
+ await updateChangesInVersion({
70
+ lix,
71
+ version: versionA,
72
+ changes: [mockChanges[0], mockChanges[1]],
73
+ });
74
+
75
+ await updateChangesInVersion({
76
+ lix,
77
+ version: versionB,
78
+ changes: [mockChanges[0], mockChanges[1]],
79
+ });
81
80
 
82
81
  const result = await lix.db
83
82
  .selectFrom("version_change")
@@ -1,6 +1,7 @@
1
1
  import { test, expect } from "vitest";
2
2
  import { createLsaInMemoryEnvironment } from "./create-in-memory-environment.js";
3
3
  import { openLixInMemory } from "../../lix/open-lix-in-memory.js";
4
+ import { toBlob } from "../../lix/to-blob.js";
4
5
 
5
6
  test("opening a lix works", async () => {
6
7
  const environment = createLsaInMemoryEnvironment();
@@ -14,7 +15,7 @@ test("opening a lix works", async () => {
14
15
  .executeTakeFirstOrThrow();
15
16
 
16
17
  // initialize the env with the lix file
17
- environment.setLix({ id: lixId, blob: await mockLix.toBlob() });
18
+ environment.setLix({ id: lixId, blob: await toBlob({ lix: mockLix }) });
18
19
 
19
20
  const open0 = await environment.openLix({ id: lixId });
20
21
 
@@ -24,7 +25,7 @@ test("opening a lix works", async () => {
24
25
  .returningAll()
25
26
  .executeTakeFirstOrThrow();
26
27
 
27
- expect(mockInsert).toEqual({
28
+ expect(mockInsert).toMatchObject({
28
29
  key: "foo",
29
30
  value: "bar",
30
31
  });
@@ -44,7 +45,7 @@ test("opening a lix works", async () => {
44
45
  .selectAll()
45
46
  .executeTakeFirstOrThrow();
46
47
 
47
- expect(mockSelect).toEqual({ key: "foo", value: "bar" });
48
+ expect(mockSelect).toMatchObject({ key: "foo", value: "bar" });
48
49
 
49
50
  await environment.closeLix({ id: lixId, connectionId: open1.connectionId });
50
51
  });
@@ -61,7 +62,7 @@ test("it handles concurrent connections", async () => {
61
62
  .executeTakeFirstOrThrow();
62
63
 
63
64
  // initialize the env with the lix file
64
- environment.setLix({ id: lixId, blob: await mockLix.toBlob() });
65
+ environment.setLix({ id: lixId, blob: await toBlob({ lix: mockLix }) });
65
66
 
66
67
  const open0 = await environment.openLix({ id: lixId });
67
68
  const open1 = await environment.openLix({ id: lixId });
@@ -72,7 +73,7 @@ test("it handles concurrent connections", async () => {
72
73
  .returningAll()
73
74
  .executeTakeFirstOrThrow();
74
75
 
75
- expect(mockInsert).toEqual({
76
+ expect(mockInsert).toMatchObject({
76
77
  key: "foo",
77
78
  value: "bar",
78
79
  });
@@ -83,7 +84,7 @@ test("it handles concurrent connections", async () => {
83
84
  .selectAll()
84
85
  .executeTakeFirstOrThrow();
85
86
 
86
- expect(mockSelect).toEqual({ key: "foo", value: "bar" });
87
+ expect(mockSelect).toMatchObject({ key: "foo", value: "bar" });
87
88
 
88
89
  // test both writing at the same time
89
90
 
@@ -124,7 +125,7 @@ test("it handles concurrent connections", async () => {
124
125
  .selectAll()
125
126
  .executeTakeFirstOrThrow();
126
127
 
127
- expect(mockSelect2).toEqual({ key: "foo", value: "bar3" });
128
+ expect(mockSelect2).toMatchObject({ key: "foo", value: "bar3" });
128
129
 
129
130
  await environment.closeLix({ id: lixId, connectionId: open2.connectionId });
130
131
  });
@@ -1,5 +1,8 @@
1
+ import { fileQueueSettled } from "../../file-queue/file-queue-settled.js";
2
+ import { closeLix } from "../../lix/close-lix.js";
1
3
  import { openLixInMemory } from "../../lix/open-lix-in-memory.js";
2
4
  import type { Lix } from "../../lix/open-lix.js";
5
+ import { toBlob } from "../../lix/to-blob.js";
3
6
  import type { LsaEnvironment } from "./environment.js";
4
7
 
5
8
  /**
@@ -72,7 +75,7 @@ export const createLsaInMemoryEnvironment = (): LsaEnvironment => {
72
75
  lix = await openLixInMemory({
73
76
  blob,
74
77
  // don't sync the server with itself
75
- keyValues: [{ key: "#lix_sync", value: "false" }],
78
+ keyValues: [{ key: "lix_sync", value: "false" }],
76
79
  });
77
80
 
78
81
  lix.sqlite.exec("PRAGMA foreign_keys = OFF;");
@@ -100,8 +103,9 @@ export const createLsaInMemoryEnvironment = (): LsaEnvironment => {
100
103
  if (connections.size === 0) {
101
104
  // TODO no concurrency guarantees
102
105
  const lix = openLixes.get(args.id);
103
- const blob = await lix!.toBlob();
104
- await lix?.close();
106
+ await fileQueueSettled({ lix: lix! });
107
+ const blob = await toBlob({ lix: lix! });
108
+ await closeLix({ lix: lix! });
105
109
  openConnections.delete(args.id);
106
110
  openLixes.delete(args.id);
107
111
  store.set(args.id, blob);
@@ -3,6 +3,7 @@ import { createServerApiHandler } from "../create-server-api-handler.js";
3
3
  import { newLixFile } from "../../lix/new-lix.js";
4
4
  import { openLixInMemory } from "../../lix/open-lix-in-memory.js";
5
5
  import { createLsaInMemoryEnvironment } from "../environment/create-in-memory-environment.js";
6
+ import { toBlob } from "../../lix/to-blob.js";
6
7
 
7
8
  test("it should fetch the lix file from the server", async () => {
8
9
  const lix = await openLixInMemory({
@@ -26,7 +27,7 @@ test("it should fetch the lix file from the server", async () => {
26
27
  await lsaHandler(
27
28
  new Request("http://localhost:3000/lsa/new-v1", {
28
29
  method: "POST",
29
- body: await lix.toBlob(),
30
+ body: await toBlob({ lix }),
30
31
  })
31
32
  );
32
33
 
@@ -103,20 +104,20 @@ test("it should return 400 for a request without lix_id", async () => {
103
104
  expect(responseJson.error).toBe("Missing required field 'lix_id'");
104
105
  });
105
106
 
106
- test("#lix_sync is set to true", async () => {
107
+ test("lix_sync is set to true", async () => {
107
108
  const environment = createLsaInMemoryEnvironment();
108
109
  const lsaHandler = await createServerApiHandler({ environment });
109
110
 
110
111
  const lix = await openLixInMemory({
111
112
  blob: await newLixFile(),
112
- keyValues: [{ key: "#lix_sync", value: "false" }],
113
+ keyValues: [{ key: "lix_sync", value: "false" }],
113
114
  });
114
115
 
115
116
  // Store the lix file
116
117
  const response0 = await lsaHandler(
117
118
  new Request("http://localhost:3000/lsa/new-v1", {
118
119
  method: "POST",
119
- body: await lix.toBlob(),
120
+ body: await toBlob({ lix }),
120
121
  })
121
122
  );
122
123
 
@@ -138,7 +139,7 @@ test("#lix_sync is set to true", async () => {
138
139
 
139
140
  const lixSync = await lixFromServer.db
140
141
  .selectFrom("key_value")
141
- .where("key", "=", "#lix_sync")
142
+ .where("key", "=", "lix_sync")
142
143
  .selectAll()
143
144
  .executeTakeFirstOrThrow();
144
145
 
@@ -47,12 +47,10 @@ export const route: LixServerApiHandlerRoute = async (context) => {
47
47
  content: new Uint8Array(await blob!.arrayBuffer()),
48
48
  });
49
49
 
50
- sqlite.exec("UPDATE key_value SET value = 'true' WHERE key = '#lix_sync'");
50
+ sqlite.exec("UPDATE key_value SET value = 'true' WHERE key = 'lix_sync'");
51
51
 
52
52
  const blob2 = new Blob([contentFromDatabase(sqlite)]);
53
53
 
54
- sqlite.close();
55
-
56
54
  return new Response(blob2, {
57
55
  status: 200,
58
56
  headers: {
@@ -3,6 +3,7 @@ import { createServerApiHandler } from "../create-server-api-handler.js";
3
3
  import { newLixFile } from "../../lix/new-lix.js";
4
4
  import { openLixInMemory } from "../../lix/open-lix-in-memory.js";
5
5
  import { createLsaInMemoryEnvironment } from "../environment/create-in-memory-environment.js";
6
+ import { toBlob } from "../../lix/to-blob.js";
6
7
 
7
8
  test("it should store the lix file", async () => {
8
9
  const initLix = await openLixInMemory({
@@ -22,7 +23,7 @@ test("it should store the lix file", async () => {
22
23
  const response = await lsaHandler(
23
24
  new Request("http://localhost:3000/lsa/new-v1", {
24
25
  method: "POST",
25
- body: await initLix.toBlob(),
26
+ body: await toBlob({ lix: initLix }),
26
27
  })
27
28
  );
28
29
  const json = await response.json();
@@ -11,7 +11,9 @@ export const route: LixServerApiHandlerRoute = async (context) => {
11
11
  lix = await openLixInMemory({
12
12
  blob,
13
13
  // turn off sync for server
14
- keyValues: [{ key: "#lix_sync", value: "false" }],
14
+ keyValues: [
15
+ { key: "lix_sync", value: "false", skip_change_control: true },
16
+ ],
15
17
  });
16
18
  } catch {
17
19
  return new Response(null, {
@@ -5,6 +5,7 @@ import { createServerApiHandler } from "../create-server-api-handler.js";
5
5
  import { mockJsonSnapshot } from "../../snapshot/mock-json-snapshot.js";
6
6
  import { mockChange } from "../../change/mock-change.js";
7
7
  import { createLsaInMemoryEnvironment } from "../environment/create-in-memory-environment.js";
8
+ import { toBlob } from "../../lix/to-blob.js";
8
9
 
9
10
  type RequestBody =
10
11
  LixServerApi.paths["/lsa/pull-v1"]["post"]["requestBody"]["content"]["application/json"];
@@ -27,7 +28,7 @@ test("it should pull rows successfully", async () => {
27
28
 
28
29
  const environment = createLsaInMemoryEnvironment();
29
30
 
30
- await environment.setLix({ id: id.value, blob: await lix.toBlob() });
31
+ await environment.setLix({ id: id.value, blob: await toBlob({ lix }) });
31
32
 
32
33
  const lsaHandler = await createServerApiHandler({ environment });
33
34
 
@@ -79,7 +80,7 @@ test("it should specifically be able to handle snapshots which use json binary a
79
80
  .execute();
80
81
 
81
82
  const environment = createLsaInMemoryEnvironment();
82
- await environment.setLix({ id, blob: await lix.toBlob() });
83
+ await environment.setLix({ id, blob: await toBlob({ lix }) });
83
84
 
84
85
  const lsa = await createServerApiHandler({ environment });
85
86
 
@@ -172,7 +173,7 @@ test("it should handle empty tables gracefully", async () => {
172
173
  .executeTakeFirstOrThrow();
173
174
 
174
175
  const environment = createLsaInMemoryEnvironment();
175
- await environment.setLix({ id, blob: await lix.toBlob() });
176
+ await environment.setLix({ id, blob: await toBlob({ lix }) });
176
177
 
177
178
  const lsa = await createServerApiHandler({ environment });
178
179
 
@@ -9,6 +9,7 @@ import { createVersion } from "../../version/create-version.js";
9
9
  import { switchVersion } from "../../version/switch-version.js";
10
10
  import { pullFromServer } from "../../sync/pull-from-server.js";
11
11
  import { createLsaInMemoryEnvironment } from "../environment/create-in-memory-environment.js";
12
+ import { toBlob } from "../../lix/to-blob.js";
12
13
 
13
14
  test("it should push data successfully", async () => {
14
15
  const lix = await openLixInMemory({});
@@ -19,7 +20,7 @@ test("it should push data successfully", async () => {
19
20
  .executeTakeFirstOrThrow();
20
21
 
21
22
  const environment = createLsaInMemoryEnvironment();
22
- await environment.setLix({ id, blob: await lix.toBlob() });
23
+ await environment.setLix({ id, blob: await toBlob({ lix }) });
23
24
 
24
25
  const lsaHandler = await createServerApiHandler({ environment });
25
26
 
@@ -130,7 +131,7 @@ test("it should return 400 for a failed insert operation", async () => {
130
131
 
131
132
  const environment = createLsaInMemoryEnvironment();
132
133
 
133
- environment.setLix({ id, blob: await lix.toBlob() });
134
+ environment.setLix({ id, blob: await toBlob({ lix }) });
134
135
 
135
136
  const lsa = await createServerApiHandler({ environment });
136
137
 
@@ -169,7 +170,7 @@ test.skip("it should detect conflicts", async () => {
169
170
 
170
171
  // initialize client
171
172
  const lixOnClient = await openLixInMemory({
172
- blob: await lixOnServer.toBlob(),
173
+ blob: await toBlob({ lix: lixOnServer }),
173
174
  });
174
175
 
175
176
  const lixId = await lixOnServer.db
@@ -192,7 +193,7 @@ test.skip("it should detect conflicts", async () => {
192
193
 
193
194
  await environment.setLix({
194
195
  id: lixId.value,
195
- blob: await lixOnServer.toBlob(),
196
+ blob: await toBlob({ lix: lixOnServer }),
196
197
  });
197
198
 
198
199
  // client has/creates value1 for mock_key
@@ -0,0 +1,35 @@
1
+ /* eslint-disable no-undef */
2
+ /**
3
+ * This script writes public environment variables
4
+ * to an importable env file.
5
+ *
6
+ * - The SDK must bundle this file with the rest of the SDK
7
+ * - This scripts avoids the need for a bundler
8
+ * - Must be ran before building the SDK
9
+ */
10
+
11
+ import fs from "node:fs/promises";
12
+ import url from "node:url";
13
+ import path from "node:path";
14
+
15
+ const dirname = path.dirname(url.fileURLToPath(import.meta.url));
16
+
17
+ const packageJson = JSON.parse(
18
+ await fs.readFile(path.resolve(dirname, "../../../package.json"), "utf-8")
19
+ );
20
+
21
+ await fs.writeFile(
22
+ dirname + "/index.ts",
23
+ `
24
+ export const ENV_VARIABLES = {
25
+ LIX_SDK_POSTHOG_TOKEN: ${ifDefined(process.env.LIX_SDK_POSTHOG_TOKEN)},
26
+ LIX_SDK_VERSION: ${ifDefined(packageJson.version)},
27
+ }
28
+ `
29
+ );
30
+
31
+ // console.log("✅ Created env variable index file.");
32
+
33
+ function ifDefined(value) {
34
+ return value ? `"${value}"` : undefined;
35
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Avoiding TypeScript errors before the `createIndexFile` script
3
+ * is invoked by defining the type ahead of time.
4
+ */
5
+
6
+ /**
7
+ * Env variables that are available at runtime.
8
+ */
9
+ export declare const ENV_VARIABLES: {
10
+ LIX_SDK_POSTHOG_TOKEN?: string;
11
+ /**
12
+ * As defined in the package.json
13
+ */
14
+ LIX_SDK_VERSION?: string;
15
+ };
@@ -0,0 +1,44 @@
1
+ import { expect, test, vi } from "vitest";
2
+ import { capture } from "./capture.js";
3
+
4
+ test("it should not capture if telemetry is off", async () => {
5
+ global.fetch = vi.fn(() => Promise.resolve(new Response()));
6
+
7
+ vi.mock("../env-variables/index.js", async () => {
8
+ return {
9
+ ENV_VARIABLES: {
10
+ LIX_SDK_POSTHOG_TOKEN: "mock-defined",
11
+ },
12
+ };
13
+ });
14
+
15
+ await capture("LIX-SDK lix opened", {
16
+ lixId: "test",
17
+ accountId: "test",
18
+ telemetryKeyValue: "off",
19
+ properties: {},
20
+ });
21
+
22
+ expect(global.fetch).not.toHaveBeenCalled();
23
+ });
24
+
25
+ test("it should not capture if telemetry is NOT off", async () => {
26
+ global.fetch = vi.fn(() => Promise.resolve(new Response()));
27
+
28
+ vi.mock("../env-variables/index.js", async () => {
29
+ return {
30
+ ENV_VARIABLES: {
31
+ LIX_SDK_POSTHOG_TOKEN: "mock-defined",
32
+ },
33
+ };
34
+ });
35
+
36
+ await capture("LIX-SDK lix opened", {
37
+ lixId: "test",
38
+ accountId: "test",
39
+ telemetryKeyValue: "on",
40
+ properties: {},
41
+ });
42
+
43
+ expect(global.fetch).toHaveBeenCalled();
44
+ });