@lix-js/sdk 0.6.0-preview.5 → 0.6.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 (274) hide show
  1. package/README.md +76 -4
  2. package/dist/errors.d.ts +7 -0
  3. package/dist/errors.js +19 -0
  4. package/dist/index.d.ts +4 -5
  5. package/dist/index.js +3 -3
  6. package/dist/native.d.ts +1 -0
  7. package/dist/native.js +47 -0
  8. package/dist/open-lix.d.ts +38 -207
  9. package/dist/open-lix.js +59 -284
  10. package/dist/result.d.ts +18 -0
  11. package/dist/result.js +48 -0
  12. package/dist/types.d.ts +114 -1
  13. package/dist/value.d.ts +28 -0
  14. package/dist/value.js +245 -0
  15. package/package.json +38 -71
  16. package/SKILL.md +0 -507
  17. package/dist/builtin-schemas.d.ts +0 -1
  18. package/dist/builtin-schemas.js +0 -1
  19. package/dist/engine-wasm/index.d.ts +0 -87
  20. package/dist/engine-wasm/index.js +0 -339
  21. package/dist/engine-wasm/wasm/lix_engine.d.ts +0 -79
  22. package/dist/engine-wasm/wasm/lix_engine.js +0 -833
  23. package/dist/engine-wasm/wasm/lix_engine.wasm +0 -0
  24. package/dist/engine-wasm/wasm/lix_engine.wasm.d.ts +0 -27
  25. package/dist/generated/builtin-schemas.d.ts +0 -427
  26. package/dist/generated/builtin-schemas.js +0 -643
  27. package/dist/sqlite/index.d.ts +0 -12
  28. package/dist/sqlite/index.js +0 -359
  29. package/dist-engine-src/README.md +0 -18
  30. package/dist-engine-src/src/backend/capabilities.rs +0 -67
  31. package/dist-engine-src/src/backend/conformance/baseline.rs +0 -1127
  32. package/dist-engine-src/src/backend/conformance/factory.rs +0 -93
  33. package/dist-engine-src/src/backend/conformance/failure_tests.rs +0 -608
  34. package/dist-engine-src/src/backend/conformance/fixtures.rs +0 -26
  35. package/dist-engine-src/src/backend/conformance/mod.rs +0 -75
  36. package/dist-engine-src/src/backend/conformance/model.rs +0 -28
  37. package/dist-engine-src/src/backend/conformance/model_based.rs +0 -257
  38. package/dist-engine-src/src/backend/conformance/persistence.rs +0 -204
  39. package/dist-engine-src/src/backend/conformance/projection.rs +0 -21
  40. package/dist-engine-src/src/backend/conformance/pushdown.rs +0 -24
  41. package/dist-engine-src/src/backend/conformance/runner.rs +0 -90
  42. package/dist-engine-src/src/backend/conformance/scan.rs +0 -24
  43. package/dist-engine-src/src/backend/conformance/write.rs +0 -16
  44. package/dist-engine-src/src/backend/error.rs +0 -94
  45. package/dist-engine-src/src/backend/in_memory.rs +0 -670
  46. package/dist-engine-src/src/backend/mod.rs +0 -39
  47. package/dist-engine-src/src/backend/predicate.rs +0 -80
  48. package/dist-engine-src/src/backend/traits.rs +0 -260
  49. package/dist-engine-src/src/backend/types.rs +0 -239
  50. package/dist-engine-src/src/binary_cas/chunking.rs +0 -31
  51. package/dist-engine-src/src/binary_cas/codec.rs +0 -346
  52. package/dist-engine-src/src/binary_cas/context.rs +0 -139
  53. package/dist-engine-src/src/binary_cas/kv.rs +0 -1038
  54. package/dist-engine-src/src/binary_cas/mod.rs +0 -11
  55. package/dist-engine-src/src/binary_cas/types.rs +0 -121
  56. package/dist-engine-src/src/branch/context.rs +0 -40
  57. package/dist-engine-src/src/branch/lifecycle.rs +0 -221
  58. package/dist-engine-src/src/branch/mod.rs +0 -13
  59. package/dist-engine-src/src/branch/refs.rs +0 -321
  60. package/dist-engine-src/src/branch/stage_rows.rs +0 -67
  61. package/dist-engine-src/src/branch/types.rs +0 -21
  62. package/dist-engine-src/src/catalog/context.rs +0 -412
  63. package/dist-engine-src/src/catalog/mod.rs +0 -10
  64. package/dist-engine-src/src/catalog/schema.rs +0 -4
  65. package/dist-engine-src/src/catalog/snapshot.rs +0 -1114
  66. package/dist-engine-src/src/cel/context.rs +0 -86
  67. package/dist-engine-src/src/cel/error.rs +0 -19
  68. package/dist-engine-src/src/cel/mod.rs +0 -8
  69. package/dist-engine-src/src/cel/provider.rs +0 -9
  70. package/dist-engine-src/src/cel/runtime.rs +0 -167
  71. package/dist-engine-src/src/cel/value.rs +0 -50
  72. package/dist-engine-src/src/changelog/bench_support.rs +0 -785
  73. package/dist-engine-src/src/changelog/change.rs +0 -1
  74. package/dist-engine-src/src/changelog/codec.rs +0 -497
  75. package/dist-engine-src/src/changelog/commit.rs +0 -1
  76. package/dist-engine-src/src/changelog/context.rs +0 -1614
  77. package/dist-engine-src/src/changelog/mod.rs +0 -29
  78. package/dist-engine-src/src/changelog/store.rs +0 -163
  79. package/dist-engine-src/src/changelog/test_support.rs +0 -54
  80. package/dist-engine-src/src/changelog/types.rs +0 -213
  81. package/dist-engine-src/src/commit_graph/context.rs +0 -944
  82. package/dist-engine-src/src/commit_graph/mod.rs +0 -9
  83. package/dist-engine-src/src/commit_graph/types.rs +0 -89
  84. package/dist-engine-src/src/commit_graph/walker.rs +0 -786
  85. package/dist-engine-src/src/common/error.rs +0 -347
  86. package/dist-engine-src/src/common/fingerprint.rs +0 -3
  87. package/dist-engine-src/src/common/fs_path.rs +0 -1336
  88. package/dist-engine-src/src/common/identity.rs +0 -145
  89. package/dist-engine-src/src/common/json_pointer.rs +0 -67
  90. package/dist-engine-src/src/common/metadata.rs +0 -40
  91. package/dist-engine-src/src/common/mod.rs +0 -23
  92. package/dist-engine-src/src/common/types.rs +0 -105
  93. package/dist-engine-src/src/common/wire.rs +0 -222
  94. package/dist-engine-src/src/domain.rs +0 -320
  95. package/dist-engine-src/src/engine.rs +0 -203
  96. package/dist-engine-src/src/entity_pk.rs +0 -402
  97. package/dist-engine-src/src/functions/context.rs +0 -296
  98. package/dist-engine-src/src/functions/deterministic.rs +0 -113
  99. package/dist-engine-src/src/functions/mod.rs +0 -18
  100. package/dist-engine-src/src/functions/provider.rs +0 -130
  101. package/dist-engine-src/src/functions/state.rs +0 -335
  102. package/dist-engine-src/src/functions/types.rs +0 -37
  103. package/dist-engine-src/src/init.rs +0 -692
  104. package/dist-engine-src/src/json_store/compression.rs +0 -77
  105. package/dist-engine-src/src/json_store/context.rs +0 -172
  106. package/dist-engine-src/src/json_store/encoded.rs +0 -15
  107. package/dist-engine-src/src/json_store/mod.rs +0 -38
  108. package/dist-engine-src/src/json_store/store.rs +0 -494
  109. package/dist-engine-src/src/json_store/types.rs +0 -212
  110. package/dist-engine-src/src/lib.rs +0 -92
  111. package/dist-engine-src/src/live_state/context.rs +0 -1883
  112. package/dist-engine-src/src/live_state/mod.rs +0 -21
  113. package/dist-engine-src/src/live_state/overlay.rs +0 -75
  114. package/dist-engine-src/src/live_state/reader.rs +0 -23
  115. package/dist-engine-src/src/live_state/types.rs +0 -231
  116. package/dist-engine-src/src/live_state/visibility.rs +0 -666
  117. package/dist-engine-src/src/plugin/archive.rs +0 -438
  118. package/dist-engine-src/src/plugin/component.rs +0 -183
  119. package/dist-engine-src/src/plugin/install.rs +0 -619
  120. package/dist-engine-src/src/plugin/manifest.rs +0 -516
  121. package/dist-engine-src/src/plugin/materializer.rs +0 -202
  122. package/dist-engine-src/src/plugin/mod.rs +0 -33
  123. package/dist-engine-src/src/plugin/plugin_manifest.json +0 -119
  124. package/dist-engine-src/src/plugin/storage.rs +0 -74
  125. package/dist-engine-src/src/schema/annotations/defaults.rs +0 -275
  126. package/dist-engine-src/src/schema/annotations/mod.rs +0 -1
  127. package/dist-engine-src/src/schema/builtin/lix_account.json +0 -21
  128. package/dist-engine-src/src/schema/builtin/lix_active_account.json +0 -29
  129. package/dist-engine-src/src/schema/builtin/lix_binary_blob_ref.json +0 -29
  130. package/dist-engine-src/src/schema/builtin/lix_branch_descriptor.json +0 -34
  131. package/dist-engine-src/src/schema/builtin/lix_branch_ref.json +0 -48
  132. package/dist-engine-src/src/schema/builtin/lix_change.json +0 -63
  133. package/dist-engine-src/src/schema/builtin/lix_change_author.json +0 -45
  134. package/dist-engine-src/src/schema/builtin/lix_commit.json +0 -24
  135. package/dist-engine-src/src/schema/builtin/lix_commit_edge.json +0 -53
  136. package/dist-engine-src/src/schema/builtin/lix_directory_descriptor.json +0 -52
  137. package/dist-engine-src/src/schema/builtin/lix_file_descriptor.json +0 -52
  138. package/dist-engine-src/src/schema/builtin/lix_key_value.json +0 -40
  139. package/dist-engine-src/src/schema/builtin/lix_label.json +0 -29
  140. package/dist-engine-src/src/schema/builtin/lix_label_assignment.json +0 -74
  141. package/dist-engine-src/src/schema/builtin/lix_registered_schema.json +0 -25
  142. package/dist-engine-src/src/schema/builtin/mod.rs +0 -220
  143. package/dist-engine-src/src/schema/compatibility.rs +0 -787
  144. package/dist-engine-src/src/schema/definition.json +0 -187
  145. package/dist-engine-src/src/schema/definition.rs +0 -742
  146. package/dist-engine-src/src/schema/key.rs +0 -138
  147. package/dist-engine-src/src/schema/mod.rs +0 -20
  148. package/dist-engine-src/src/schema/seed.rs +0 -14
  149. package/dist-engine-src/src/schema/tests.rs +0 -780
  150. package/dist-engine-src/src/session/context.rs +0 -1059
  151. package/dist-engine-src/src/session/create_branch.rs +0 -94
  152. package/dist-engine-src/src/session/execute.rs +0 -681
  153. package/dist-engine-src/src/session/merge/analysis.rs +0 -108
  154. package/dist-engine-src/src/session/merge/branch.rs +0 -417
  155. package/dist-engine-src/src/session/merge/conflicts.rs +0 -63
  156. package/dist-engine-src/src/session/merge/mod.rs +0 -10
  157. package/dist-engine-src/src/session/merge/stats.rs +0 -61
  158. package/dist-engine-src/src/session/mod.rs +0 -30
  159. package/dist-engine-src/src/session/switch_branch.rs +0 -113
  160. package/dist-engine-src/src/session/transaction.rs +0 -557
  161. package/dist-engine-src/src/sql2/bind/classify.rs +0 -102
  162. package/dist-engine-src/src/sql2/bind/error.rs +0 -5
  163. package/dist-engine-src/src/sql2/bind/expr.rs +0 -29
  164. package/dist-engine-src/src/sql2/bind/mod.rs +0 -12
  165. package/dist-engine-src/src/sql2/bind/public_udf.rs +0 -306
  166. package/dist-engine-src/src/sql2/bind/read.rs +0 -65
  167. package/dist-engine-src/src/sql2/bind/statement.rs +0 -2236
  168. package/dist-engine-src/src/sql2/bind/table.rs +0 -273
  169. package/dist-engine-src/src/sql2/bind/write.rs +0 -86
  170. package/dist-engine-src/src/sql2/branch_scope.rs +0 -436
  171. package/dist-engine-src/src/sql2/catalog/capability.rs +0 -20
  172. package/dist-engine-src/src/sql2/catalog/entity_surface.rs +0 -296
  173. package/dist-engine-src/src/sql2/catalog/mod.rs +0 -15
  174. package/dist-engine-src/src/sql2/catalog/registry.rs +0 -556
  175. package/dist-engine-src/src/sql2/catalog/schema.rs +0 -88
  176. package/dist-engine-src/src/sql2/catalog/surface.rs +0 -41
  177. package/dist-engine-src/src/sql2/change_materialization.rs +0 -122
  178. package/dist-engine-src/src/sql2/context.rs +0 -317
  179. package/dist-engine-src/src/sql2/dml.rs +0 -148
  180. package/dist-engine-src/src/sql2/error.rs +0 -215
  181. package/dist-engine-src/src/sql2/exec/bound_public_write.rs +0 -1593
  182. package/dist-engine-src/src/sql2/exec/datafusion.rs +0 -5266
  183. package/dist-engine-src/src/sql2/exec/fast_write.rs +0 -82
  184. package/dist-engine-src/src/sql2/exec/mod.rs +0 -24
  185. package/dist-engine-src/src/sql2/exec/write.rs +0 -661
  186. package/dist-engine-src/src/sql2/filesystem_planner.rs +0 -1485
  187. package/dist-engine-src/src/sql2/filesystem_predicates.rs +0 -159
  188. package/dist-engine-src/src/sql2/filesystem_visibility.rs +0 -383
  189. package/dist-engine-src/src/sql2/history_projection.rs +0 -56
  190. package/dist-engine-src/src/sql2/history_route.rs +0 -661
  191. package/dist-engine-src/src/sql2/mod.rs +0 -52
  192. package/dist-engine-src/src/sql2/optimize/datafusion.rs +0 -1
  193. package/dist-engine-src/src/sql2/optimize/mod.rs +0 -2
  194. package/dist-engine-src/src/sql2/optimize/simple_write.rs +0 -116
  195. package/dist-engine-src/src/sql2/parse/mod.rs +0 -69
  196. package/dist-engine-src/src/sql2/parse/normalize.rs +0 -1
  197. package/dist-engine-src/src/sql2/plan/branch_scope.rs +0 -24
  198. package/dist-engine-src/src/sql2/plan/mod.rs +0 -5
  199. package/dist-engine-src/src/sql2/plan/predicate.rs +0 -22
  200. package/dist-engine-src/src/sql2/plan/write.rs +0 -147
  201. package/dist-engine-src/src/sql2/predicate_typecheck.rs +0 -504
  202. package/dist-engine-src/src/sql2/providers/branch.rs +0 -1206
  203. package/dist-engine-src/src/sql2/providers/change.rs +0 -445
  204. package/dist-engine-src/src/sql2/providers/directory.rs +0 -2422
  205. package/dist-engine-src/src/sql2/providers/directory_history.rs +0 -645
  206. package/dist-engine-src/src/sql2/providers/entity.rs +0 -1484
  207. package/dist-engine-src/src/sql2/providers/entity_history.rs +0 -452
  208. package/dist-engine-src/src/sql2/providers/file.rs +0 -3686
  209. package/dist-engine-src/src/sql2/providers/file_history.rs +0 -924
  210. package/dist-engine-src/src/sql2/providers/history.rs +0 -426
  211. package/dist-engine-src/src/sql2/providers/lix_state.rs +0 -2542
  212. package/dist-engine-src/src/sql2/providers/mod.rs +0 -508
  213. package/dist-engine-src/src/sql2/read_only.rs +0 -63
  214. package/dist-engine-src/src/sql2/record_batch.rs +0 -17
  215. package/dist-engine-src/src/sql2/result_metadata.rs +0 -29
  216. package/dist-engine-src/src/sql2/runtime.rs +0 -60
  217. package/dist-engine-src/src/sql2/session.rs +0 -83
  218. package/dist-engine-src/src/sql2/storage/constraints.rs +0 -1
  219. package/dist-engine-src/src/sql2/storage/mod.rs +0 -1
  220. package/dist-engine-src/src/sql2/test_support/differential.rs +0 -712
  221. package/dist-engine-src/src/sql2/test_support/generators.rs +0 -354
  222. package/dist-engine-src/src/sql2/test_support/mod.rs +0 -2
  223. package/dist-engine-src/src/sql2/udfs/common.rs +0 -295
  224. package/dist-engine-src/src/sql2/udfs/lix_active_branch_commit_id.rs +0 -53
  225. package/dist-engine-src/src/sql2/udfs/lix_empty_blob.rs +0 -47
  226. package/dist-engine-src/src/sql2/udfs/lix_json.rs +0 -100
  227. package/dist-engine-src/src/sql2/udfs/lix_json_get.rs +0 -99
  228. package/dist-engine-src/src/sql2/udfs/lix_json_get_text.rs +0 -99
  229. package/dist-engine-src/src/sql2/udfs/lix_text_decode.rs +0 -82
  230. package/dist-engine-src/src/sql2/udfs/lix_text_encode.rs +0 -85
  231. package/dist-engine-src/src/sql2/udfs/lix_timestamp.rs +0 -76
  232. package/dist-engine-src/src/sql2/udfs/lix_uuid_v7.rs +0 -76
  233. package/dist-engine-src/src/sql2/udfs/mod.rs +0 -86
  234. package/dist-engine-src/src/sql2/write_normalization.rs +0 -368
  235. package/dist-engine-src/src/storage/conformance.rs +0 -399
  236. package/dist-engine-src/src/storage/context.rs +0 -620
  237. package/dist-engine-src/src/storage/mod.rs +0 -52
  238. package/dist-engine-src/src/storage/point.rs +0 -440
  239. package/dist-engine-src/src/storage/read_scope.rs +0 -67
  240. package/dist-engine-src/src/storage/reader.rs +0 -867
  241. package/dist-engine-src/src/storage/scan.rs +0 -784
  242. package/dist-engine-src/src/storage/spaces.rs +0 -236
  243. package/dist-engine-src/src/storage/stats.rs +0 -80
  244. package/dist-engine-src/src/storage/write_set.rs +0 -962
  245. package/dist-engine-src/src/storage_bench.rs +0 -171
  246. package/dist-engine-src/src/test_support.rs +0 -450
  247. package/dist-engine-src/src/tracked_state/bench_support.rs +0 -394
  248. package/dist-engine-src/src/tracked_state/codec.rs +0 -1183
  249. package/dist-engine-src/src/tracked_state/commit_root_rebuild.rs +0 -358
  250. package/dist-engine-src/src/tracked_state/context.rs +0 -2801
  251. package/dist-engine-src/src/tracked_state/diff.rs +0 -2140
  252. package/dist-engine-src/src/tracked_state/merge.rs +0 -478
  253. package/dist-engine-src/src/tracked_state/mod.rs +0 -35
  254. package/dist-engine-src/src/tracked_state/row_materialization.rs +0 -275
  255. package/dist-engine-src/src/tracked_state/storage.rs +0 -427
  256. package/dist-engine-src/src/tracked_state/tree.rs +0 -3063
  257. package/dist-engine-src/src/tracked_state/types.rs +0 -238
  258. package/dist-engine-src/src/transaction/bench_support.rs +0 -407
  259. package/dist-engine-src/src/transaction/commit.rs +0 -1592
  260. package/dist-engine-src/src/transaction/context.rs +0 -1653
  261. package/dist-engine-src/src/transaction/mod.rs +0 -24
  262. package/dist-engine-src/src/transaction/normalization.rs +0 -877
  263. package/dist-engine-src/src/transaction/prep.rs +0 -37
  264. package/dist-engine-src/src/transaction/schema_resolver.rs +0 -163
  265. package/dist-engine-src/src/transaction/staging.rs +0 -1525
  266. package/dist-engine-src/src/transaction/types.rs +0 -403
  267. package/dist-engine-src/src/transaction/validation.rs +0 -5766
  268. package/dist-engine-src/src/untracked_state/codec.rs +0 -615
  269. package/dist-engine-src/src/untracked_state/context.rs +0 -98
  270. package/dist-engine-src/src/untracked_state/materialization.rs +0 -63
  271. package/dist-engine-src/src/untracked_state/mod.rs +0 -15
  272. package/dist-engine-src/src/untracked_state/storage.rs +0 -898
  273. package/dist-engine-src/src/untracked_state/types.rs +0 -146
  274. package/dist-engine-src/src/wasm/mod.rs +0 -60
package/README.md CHANGED
@@ -1,9 +1,81 @@
1
1
  # @lix-js/sdk
2
2
 
3
- WASM-backed JavaScript SDK for Lix.
3
+ JavaScript SDK for Lix, backed by the native Rust SDK.
4
4
 
5
- ## Agent Guidance
5
+ ## Install
6
6
 
7
- If you are an AI coding agent using this package, read [`SKILL.md`](./SKILL.md) before building examples, demos, tests, or applications with `@lix-js/sdk`.
7
+ ```bash
8
+ npm install @lix-js/sdk
9
+ ```
8
10
 
9
- The skill documents the current preview API, recommended SQLite backend setup, schema registration flow, entity-table writes, branch workflows, merge behavior, and known sharp edges.
11
+ ## Usage
12
+
13
+ ```ts
14
+ import { openLix, SqliteBackend } from "@lix-js/sdk";
15
+
16
+ const lix = await openLix({
17
+ backend: new SqliteBackend({ path: "app.lix" }),
18
+ });
19
+
20
+ await lix.execute(
21
+ "INSERT INTO lix_key_value (key, value) VALUES ($1, $2)",
22
+ ["hello", "world"],
23
+ );
24
+
25
+ const result = await lix.execute(
26
+ "SELECT value FROM lix_key_value WHERE key = $1",
27
+ ["hello"],
28
+ );
29
+
30
+ console.log(result.rows[0]?.get("value"));
31
+
32
+ await lix.close();
33
+ ```
34
+
35
+ ## Branches
36
+
37
+ ```ts
38
+ const main = await lix.activeBranchId();
39
+ const draft = await lix.createBranch({ name: "Draft" });
40
+
41
+ await lix.switchBranch({ branchId: draft.id });
42
+ await lix.execute(
43
+ "INSERT INTO lix_key_value (key, value) VALUES ($1, $2)",
44
+ ["status", "draft"],
45
+ );
46
+
47
+ await lix.switchBranch({ branchId: main });
48
+ const preview = await lix.mergeBranchPreview({ sourceBranchId: draft.id });
49
+ const merge = await lix.mergeBranch({ sourceBranchId: draft.id });
50
+ ```
51
+
52
+ ## Transactions
53
+
54
+ ```ts
55
+ const tx = await lix.beginTransaction();
56
+
57
+ try {
58
+ await tx.execute(
59
+ "INSERT INTO lix_key_value (key, value) VALUES ($1, $2)",
60
+ ["a", "1"],
61
+ );
62
+ await tx.execute(
63
+ "INSERT INTO lix_key_value (key, value) VALUES ($1, $2)",
64
+ ["b", "2"],
65
+ );
66
+ await tx.commit();
67
+ } catch (error) {
68
+ await tx.rollback();
69
+ throw error;
70
+ }
71
+ ```
72
+
73
+ ## Notes
74
+
75
+ - `openLix()` opens a fresh in-memory Lix. Pass `new SqliteBackend({ path })` to persist to disk.
76
+ - The SDK is Node/native only right now; it is not browser-compatible.
77
+ - The package is ESM-only.
78
+ - The native addon is built from Rust and loaded by the TypeScript wrapper.
79
+ - The public API is promise-based, but the current native implementation performs local SQLite work synchronously under the hood.
80
+ - SQL parameters use normal JavaScript values: `string`, finite `number`, `boolean`, `Uint8Array`, `null`, JSON-compatible arrays, and JSON-compatible plain objects.
81
+ - Use `Value.integer(...)`, `Value.real(...)`, `Value.text(...)`, `Value.json(...)`, or `Value.blob(...)` only when you need to pass an explicit native Lix value.
@@ -0,0 +1,7 @@
1
+ export type LixJsError = Error & {
2
+ code?: string;
3
+ details?: unknown;
4
+ hint?: string;
5
+ };
6
+ export declare function invalidArgument(operation: string, argument: string, expected: string, actual: string, receiver?: string): LixJsError;
7
+ export declare function invalidParam(index: number, message: string, actual: string): LixJsError;
package/dist/errors.js ADDED
@@ -0,0 +1,19 @@
1
+ export function invalidArgument(operation, argument, expected, actual, receiver = "lix") {
2
+ const error = new Error(`${receiver}.${operation}() expected ${argument} to be a ${expected}`);
3
+ error.name = "LixError";
4
+ error.code = "LIX_INVALID_ARGUMENT";
5
+ error.details = { operation, argument, expected, actual };
6
+ return error;
7
+ }
8
+ export function invalidParam(index, message, actual) {
9
+ const error = new Error(message);
10
+ error.name = "LixError";
11
+ error.code = "LIX_INVALID_PARAM";
12
+ error.details = {
13
+ operation: "execute",
14
+ parameter_index: index + 1,
15
+ argument: `params[${index}]`,
16
+ actual,
17
+ };
18
+ return error;
19
+ }
package/dist/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- export * from "./open-lix.js";
2
- export * from "./builtin-schemas.js";
3
- export { Value, isLixError } from "./engine-wasm/index.js";
4
- export type { LixError, LixValue } from "./engine-wasm/index.js";
5
- export type { JsonValue, LixRuntimeValue } from "./types.js";
1
+ export { Lix, LixTransaction, openLix, SqliteBackend } from "./open-lix.js";
2
+ export { Row } from "./result.js";
3
+ export { Value } from "./value.js";
4
+ export type { CreateBranchOptions, CreateBranchReceipt, ExecuteResult, JsonValue, LixValue, MergeBranchOptions, MergeBranchOutcome, MergeBranchPreview, MergeBranchReceipt, MergeChangeStats, MergeConflict, MergeConflictSide, OpenLixOptions, SqlParam, SqliteBackendOptions, SwitchBranchOptions, SwitchBranchReceipt, } from "./types.js";
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- export * from "./open-lix.js";
2
- export * from "./builtin-schemas.js";
3
- export { Value, isLixError } from "./engine-wasm/index.js";
1
+ export { Lix, LixTransaction, openLix, SqliteBackend } from "./open-lix.js";
2
+ export { Row } from "./result.js";
3
+ export { Value } from "./value.js";
@@ -0,0 +1 @@
1
+ export declare const addon: Record<string, any>;
package/dist/native.js ADDED
@@ -0,0 +1,47 @@
1
+ import { existsSync } from "node:fs";
2
+ import { createRequire } from "node:module";
3
+ import { fileURLToPath } from "node:url";
4
+ const require = createRequire(import.meta.url);
5
+ const localNativePath = fileURLToPath(new URL("../lix_js_sdk.node", import.meta.url));
6
+ const nativePackages = {
7
+ "linux-x64": "@lix-js/sdk-linux-x64",
8
+ "linux-arm64": "@lix-js/sdk-linux-arm64",
9
+ "darwin-arm64": "@lix-js/sdk-darwin-arm64",
10
+ "win32-x64": "@lix-js/sdk-win32-x64",
11
+ };
12
+ function nativePackageName() {
13
+ const key = `${process.platform}-${process.arch}`;
14
+ return nativePackages[key];
15
+ }
16
+ function resolveNativePath() {
17
+ if (existsSync(localNativePath)) {
18
+ return localNativePath;
19
+ }
20
+ const packageName = nativePackageName();
21
+ let packageResolutionError;
22
+ if (packageName) {
23
+ try {
24
+ return require.resolve(packageName);
25
+ }
26
+ catch (error) {
27
+ packageResolutionError = error;
28
+ }
29
+ }
30
+ if (!packageName) {
31
+ throw new Error(`Unsupported platform ${process.platform}-${process.arch}`);
32
+ }
33
+ throw packageResolutionError;
34
+ }
35
+ const native = { exports: {} };
36
+ try {
37
+ const nativePath = resolveNativePath();
38
+ process.dlopen(native, nativePath);
39
+ }
40
+ catch (cause) {
41
+ const error = new Error(`Failed to load @lix-js/sdk native addon for ${process.platform}-${process.arch}. ` +
42
+ "This package requires the matching optional native binary package. " +
43
+ "Run `npm run build` from packages/js-sdk for local development, or install a release that includes your platform binary.");
44
+ error.cause = cause;
45
+ throw error;
46
+ }
47
+ export const addon = native.exports;
@@ -1,214 +1,45 @@
1
- import { Value } from "./engine-wasm/index.js";
2
- export type JsonValue = null | boolean | number | string | JsonValue[] | {
3
- [key: string]: JsonValue;
4
- };
5
- export type LixRuntimeValue = JsonValue | Uint8Array | ArrayBuffer | Value;
6
- export type LixNativeValue = JsonValue | Uint8Array;
7
- export type ExecuteResult = {
8
- columns: string[];
9
- rows: Row[];
10
- rowsAffected: number;
11
- notices: LixNotice[];
12
- };
13
- export type LixNotice = {
14
- code: string;
15
- message: string;
16
- hint?: string;
17
- };
18
- export declare class Row {
19
- readonly columns: string[];
20
- private readonly valuesByIndex;
21
- constructor(columns: string[], values: Value[]);
22
- get(columnName: string): LixNativeValue;
23
- tryGet(columnName: string): LixNativeValue | undefined;
24
- value(columnName: string): Value;
25
- tryValue(columnName: string): Value | undefined;
26
- getAt(index: number): LixNativeValue;
27
- valueAt(index: number): Value;
28
- values(): Value[];
29
- toObject(): Record<string, LixNativeValue>;
30
- toValueMap(): Record<string, Value>;
31
- private availableColumns;
32
- }
33
- export type BackendKvScanRange = {
34
- kind: "prefix";
35
- prefix: Uint8Array;
36
- } | {
37
- kind: "range";
38
- start: Uint8Array;
39
- end: Uint8Array;
40
- };
41
- export type BackendKvGetRequest = {
42
- groups: BackendKvGetGroup[];
43
- };
44
- export type BackendKvGetGroup = {
45
- namespace: string;
46
- keys: Uint8Array[];
47
- };
48
- export type BackendKvValueBatch = {
49
- groups: BackendKvValueGroup[];
50
- };
51
- export type BackendKvValueGroup = {
52
- namespace: string;
53
- values: Array<Uint8Array | null>;
54
- };
55
- export type BackendKvExistsBatch = {
56
- groups: BackendKvExistsGroup[];
57
- };
58
- export type BackendKvExistsGroup = {
59
- namespace: string;
60
- exists: boolean[];
61
- };
62
- export type BackendKvScanRequest = {
63
- namespace: string;
64
- range: BackendKvScanRange;
65
- after?: Uint8Array | null;
66
- limit: number;
67
- };
68
- export type BackendKvKeyPage = {
69
- keys: Uint8Array[];
70
- resumeAfter?: Uint8Array | null;
71
- };
72
- export type BackendKvValuePage = {
73
- values: Uint8Array[];
74
- resumeAfter?: Uint8Array | null;
75
- };
76
- export type BackendKvEntryPage = {
77
- keys: Uint8Array[];
78
- values: Uint8Array[];
79
- resumeAfter?: Uint8Array | null;
80
- };
81
- export type BackendKvWriteOp = {
82
- kind: "put";
83
- key: Uint8Array;
84
- value: Uint8Array;
85
- } | {
86
- kind: "delete";
87
- key: Uint8Array;
88
- } | {
89
- kind: "deleteRange";
90
- range: BackendKvScanRange;
91
- };
92
- export type BackendKvWriteBatch = {
93
- groups: BackendKvWriteGroup[];
94
- };
95
- export type BackendKvWriteGroup = {
96
- namespace: string;
97
- ops: BackendKvWriteOp[];
98
- };
99
- export type BackendKvWriteStats = {
100
- puts: number;
101
- deletes: number;
102
- deleteRanges: number;
103
- bytesWritten: number;
104
- };
105
- export type LixBackendReadTransaction = {
106
- getValues(request: BackendKvGetRequest): BackendKvValueBatch;
107
- existsMany(request: BackendKvGetRequest): BackendKvExistsBatch;
108
- scanKeys(request: BackendKvScanRequest): BackendKvKeyPage;
109
- scanValues(request: BackendKvScanRequest): BackendKvValuePage;
110
- scanEntries(request: BackendKvScanRequest): BackendKvEntryPage;
111
- rollback(): void;
112
- };
113
- export type LixBackendWriteTransaction = LixBackendReadTransaction & {
114
- writeKvBatch(batch: BackendKvWriteBatch): BackendKvWriteStats;
1
+ import { wrapExecuteResult } from "./result.js";
2
+ import { toNativeValue } from "./value.js";
3
+ import type { CreateBranchOptions, CreateBranchReceipt, ExecuteResult, MergeBranchOptions, MergeBranchPreview, MergeBranchReceipt, OpenLixOptions, SqlParam, SqliteBackendOptions, SwitchBranchOptions, SwitchBranchReceipt } from "./types.js";
4
+ type NativeExecuteResult = Parameters<typeof wrapExecuteResult>[0];
5
+ type NativeParam = ReturnType<typeof toNativeValue>;
6
+ type NativeLix = {
7
+ execute(sql: string, params: NativeParam[]): NativeExecuteResult;
8
+ beginTransaction(): NativeLixTransaction;
9
+ activeBranchId(): string;
10
+ createBranch(options: CreateBranchOptions): CreateBranchReceipt;
11
+ switchBranch(options: SwitchBranchOptions): SwitchBranchReceipt;
12
+ mergeBranchPreview(options: MergeBranchOptions): MergeBranchPreview;
13
+ mergeBranch(options: MergeBranchOptions): MergeBranchReceipt;
14
+ close(): void;
15
+ };
16
+ type NativeLixTransaction = {
17
+ execute(sql: string, params: NativeParam[]): NativeExecuteResult;
115
18
  commit(): void;
19
+ rollback(): void;
116
20
  };
117
- export type LixBackend = {
118
- beginReadTransaction(): LixBackendReadTransaction;
119
- beginWriteTransaction(): LixBackendWriteTransaction;
120
- close?(): void;
121
- };
122
- export type OpenLixOptions = {
123
- backend?: LixBackend;
124
- };
125
- export type CreateBranchOptions = {
126
- id?: string;
127
- name: string;
128
- fromCommitId?: string;
129
- };
130
- export type CreateBranchResult = {
131
- id: string;
132
- name: string;
133
- hidden: boolean;
134
- commitId: string;
135
- };
136
- export type SwitchBranchOptions = {
137
- branchId: string;
138
- };
139
- export type SwitchBranchResult = {
140
- branchId: string;
141
- };
142
- export type MergeBranchOptions = {
143
- sourceBranchId: string;
144
- };
145
- export type MergeBranchOutcome = "alreadyUpToDate" | "fastForward" | "mergeCommitted";
146
- export type MergeBranchResult = {
147
- /**
148
- * How the merge was applied. `fastForward` advances the target ref without
149
- * creating a merge commit, but can still make source changes visible.
150
- */
151
- outcome: MergeBranchOutcome;
152
- targetBranchId: string;
153
- sourceBranchId: string;
154
- baseCommitId: string;
155
- targetHeadBeforeCommitId: string;
156
- sourceHeadBeforeCommitId: string;
157
- targetHeadAfterCommitId: string;
158
- createdMergeCommitId: string | null;
159
- changeStats: MergeChangeStats;
160
- };
161
- export type MergeBranchPreviewResult = {
162
- outcome: MergeBranchOutcome;
163
- targetBranchId: string;
164
- sourceBranchId: string;
165
- baseCommitId: string;
166
- targetHeadCommitId: string;
167
- sourceHeadCommitId: string;
168
- changeStats: MergeChangeStats;
169
- conflicts: MergeConflict[];
170
- };
171
- export type MergeChangeStats = {
172
- total: number;
173
- added: number;
174
- modified: number;
175
- removed: number;
176
- };
177
- export type MergeConflict = {
178
- kind: "sameEntityChanged";
179
- schemaKey: string;
180
- entityPk: string[];
181
- fileId: string | null;
182
- target: MergeConflictSide;
183
- source: MergeConflictSide;
184
- };
185
- export type MergeConflictSide = {
186
- kind: "added" | "modified" | "removed";
187
- beforeChangeId: string | null;
188
- afterChangeId: string | null;
189
- };
190
- export type Lix = {
191
- /**
192
- * Executes one DataFusion SQL statement against this Lix session.
193
- *
194
- * This is not SQLite SQL. Use the DataFusion SQL dialect; positional
195
- * placeholders are `?` or `$1`, `$2`, and so on. SQLite-specific catalog tables and
196
- * transaction statements such as `sqlite_master`, `BEGIN`, and `COMMIT` are
197
- * not available. Use `information_schema` for catalog inspection. While a
198
- * transaction is active, call `execute()` on the transaction handle instead.
199
- */
200
- execute(sql: string, params?: ReadonlyArray<LixRuntimeValue>): Promise<ExecuteResult>;
21
+ export declare class SqliteBackend {
22
+ readonly path: string;
23
+ constructor(options: SqliteBackendOptions);
24
+ }
25
+ export declare function openLix(options?: OpenLixOptions): Promise<Lix>;
26
+ export declare class Lix {
27
+ private readonly native;
28
+ constructor(native: NativeLix);
29
+ execute(sql: string, params?: SqlParam[]): Promise<ExecuteResult>;
201
30
  beginTransaction(): Promise<LixTransaction>;
202
31
  activeBranchId(): Promise<string>;
203
- createBranch(options: CreateBranchOptions): Promise<CreateBranchResult>;
204
- switchBranch(options: SwitchBranchOptions): Promise<SwitchBranchResult>;
205
- mergeBranchPreview(options: MergeBranchOptions): Promise<MergeBranchPreviewResult>;
206
- mergeBranch(options: MergeBranchOptions): Promise<MergeBranchResult>;
32
+ createBranch(options: CreateBranchOptions): Promise<CreateBranchReceipt>;
33
+ switchBranch(options: SwitchBranchOptions): Promise<SwitchBranchReceipt>;
34
+ mergeBranchPreview(options: MergeBranchOptions): Promise<MergeBranchPreview>;
35
+ mergeBranch(options: MergeBranchOptions): Promise<MergeBranchReceipt>;
207
36
  close(): Promise<void>;
208
- };
209
- export type LixTransaction = {
210
- execute(sql: string, params?: ReadonlyArray<LixRuntimeValue>): Promise<ExecuteResult>;
37
+ }
38
+ export declare class LixTransaction {
39
+ private readonly native;
40
+ constructor(native: NativeLixTransaction);
41
+ execute(sql: string, params?: SqlParam[]): Promise<ExecuteResult>;
211
42
  commit(): Promise<void>;
212
43
  rollback(): Promise<void>;
213
- };
214
- export declare function openLix(options?: OpenLixOptions): Promise<Lix>;
44
+ }
45
+ export {};