@lix-js/sdk 0.6.0-preview.4 → 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 (223) 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 +39 -201
  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 +20 -50
  16. package/SKILL.md +0 -506
  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 -821
  23. package/dist/engine-wasm/wasm/lix_engine.wasm +0 -0
  24. package/dist/engine-wasm/wasm/lix_engine.wasm.d.ts +0 -26
  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 -303
  29. package/dist-engine-src/README.md +0 -18
  30. package/dist-engine-src/src/backend/kv.rs +0 -358
  31. package/dist-engine-src/src/backend/mod.rs +0 -12
  32. package/dist-engine-src/src/backend/testing.rs +0 -658
  33. package/dist-engine-src/src/backend/types.rs +0 -96
  34. package/dist-engine-src/src/binary_cas/chunking.rs +0 -31
  35. package/dist-engine-src/src/binary_cas/codec.rs +0 -346
  36. package/dist-engine-src/src/binary_cas/context.rs +0 -139
  37. package/dist-engine-src/src/binary_cas/kv.rs +0 -1063
  38. package/dist-engine-src/src/binary_cas/mod.rs +0 -11
  39. package/dist-engine-src/src/binary_cas/types.rs +0 -121
  40. package/dist-engine-src/src/catalog/context.rs +0 -412
  41. package/dist-engine-src/src/catalog/mod.rs +0 -10
  42. package/dist-engine-src/src/catalog/schema.rs +0 -4
  43. package/dist-engine-src/src/catalog/snapshot.rs +0 -1114
  44. package/dist-engine-src/src/cel/context.rs +0 -86
  45. package/dist-engine-src/src/cel/error.rs +0 -19
  46. package/dist-engine-src/src/cel/mod.rs +0 -8
  47. package/dist-engine-src/src/cel/provider.rs +0 -9
  48. package/dist-engine-src/src/cel/runtime.rs +0 -167
  49. package/dist-engine-src/src/cel/value.rs +0 -50
  50. package/dist-engine-src/src/commit_graph/context.rs +0 -901
  51. package/dist-engine-src/src/commit_graph/mod.rs +0 -11
  52. package/dist-engine-src/src/commit_graph/types.rs +0 -109
  53. package/dist-engine-src/src/commit_graph/walker.rs +0 -756
  54. package/dist-engine-src/src/commit_store/codec.rs +0 -887
  55. package/dist-engine-src/src/commit_store/context.rs +0 -944
  56. package/dist-engine-src/src/commit_store/materialization.rs +0 -84
  57. package/dist-engine-src/src/commit_store/mod.rs +0 -16
  58. package/dist-engine-src/src/commit_store/storage.rs +0 -600
  59. package/dist-engine-src/src/commit_store/types.rs +0 -215
  60. package/dist-engine-src/src/common/error.rs +0 -313
  61. package/dist-engine-src/src/common/fingerprint.rs +0 -3
  62. package/dist-engine-src/src/common/fs_path.rs +0 -1336
  63. package/dist-engine-src/src/common/identity.rs +0 -145
  64. package/dist-engine-src/src/common/json_pointer.rs +0 -67
  65. package/dist-engine-src/src/common/metadata.rs +0 -40
  66. package/dist-engine-src/src/common/mod.rs +0 -23
  67. package/dist-engine-src/src/common/types.rs +0 -105
  68. package/dist-engine-src/src/common/wire.rs +0 -222
  69. package/dist-engine-src/src/domain.rs +0 -324
  70. package/dist-engine-src/src/engine.rs +0 -225
  71. package/dist-engine-src/src/entity_identity.rs +0 -405
  72. package/dist-engine-src/src/functions/context.rs +0 -292
  73. package/dist-engine-src/src/functions/deterministic.rs +0 -113
  74. package/dist-engine-src/src/functions/mod.rs +0 -18
  75. package/dist-engine-src/src/functions/provider.rs +0 -130
  76. package/dist-engine-src/src/functions/state.rs +0 -336
  77. package/dist-engine-src/src/functions/types.rs +0 -37
  78. package/dist-engine-src/src/init.rs +0 -558
  79. package/dist-engine-src/src/json_store/compression.rs +0 -77
  80. package/dist-engine-src/src/json_store/context.rs +0 -423
  81. package/dist-engine-src/src/json_store/encoded.rs +0 -15
  82. package/dist-engine-src/src/json_store/mod.rs +0 -12
  83. package/dist-engine-src/src/json_store/store.rs +0 -1109
  84. package/dist-engine-src/src/json_store/types.rs +0 -217
  85. package/dist-engine-src/src/lib.rs +0 -62
  86. package/dist-engine-src/src/live_state/context.rs +0 -2019
  87. package/dist-engine-src/src/live_state/mod.rs +0 -15
  88. package/dist-engine-src/src/live_state/overlay.rs +0 -75
  89. package/dist-engine-src/src/live_state/reader.rs +0 -23
  90. package/dist-engine-src/src/live_state/types.rs +0 -222
  91. package/dist-engine-src/src/live_state/visibility.rs +0 -223
  92. package/dist-engine-src/src/plugin/archive.rs +0 -438
  93. package/dist-engine-src/src/plugin/component.rs +0 -183
  94. package/dist-engine-src/src/plugin/install.rs +0 -619
  95. package/dist-engine-src/src/plugin/manifest.rs +0 -516
  96. package/dist-engine-src/src/plugin/materializer.rs +0 -477
  97. package/dist-engine-src/src/plugin/mod.rs +0 -33
  98. package/dist-engine-src/src/plugin/plugin_manifest.json +0 -118
  99. package/dist-engine-src/src/plugin/storage.rs +0 -74
  100. package/dist-engine-src/src/schema/annotations/defaults.rs +0 -275
  101. package/dist-engine-src/src/schema/annotations/mod.rs +0 -1
  102. package/dist-engine-src/src/schema/builtin/lix_account.json +0 -21
  103. package/dist-engine-src/src/schema/builtin/lix_active_account.json +0 -29
  104. package/dist-engine-src/src/schema/builtin/lix_binary_blob_ref.json +0 -29
  105. package/dist-engine-src/src/schema/builtin/lix_change.json +0 -63
  106. package/dist-engine-src/src/schema/builtin/lix_change_author.json +0 -45
  107. package/dist-engine-src/src/schema/builtin/lix_commit.json +0 -24
  108. package/dist-engine-src/src/schema/builtin/lix_commit_edge.json +0 -53
  109. package/dist-engine-src/src/schema/builtin/lix_directory_descriptor.json +0 -52
  110. package/dist-engine-src/src/schema/builtin/lix_file_descriptor.json +0 -52
  111. package/dist-engine-src/src/schema/builtin/lix_key_value.json +0 -40
  112. package/dist-engine-src/src/schema/builtin/lix_label.json +0 -29
  113. package/dist-engine-src/src/schema/builtin/lix_label_assignment.json +0 -74
  114. package/dist-engine-src/src/schema/builtin/lix_registered_schema.json +0 -25
  115. package/dist-engine-src/src/schema/builtin/lix_version_descriptor.json +0 -34
  116. package/dist-engine-src/src/schema/builtin/lix_version_ref.json +0 -48
  117. package/dist-engine-src/src/schema/builtin/mod.rs +0 -222
  118. package/dist-engine-src/src/schema/compatibility.rs +0 -787
  119. package/dist-engine-src/src/schema/definition.json +0 -187
  120. package/dist-engine-src/src/schema/definition.rs +0 -742
  121. package/dist-engine-src/src/schema/key.rs +0 -138
  122. package/dist-engine-src/src/schema/mod.rs +0 -20
  123. package/dist-engine-src/src/schema/seed.rs +0 -14
  124. package/dist-engine-src/src/schema/tests.rs +0 -780
  125. package/dist-engine-src/src/session/context.rs +0 -404
  126. package/dist-engine-src/src/session/create_version.rs +0 -88
  127. package/dist-engine-src/src/session/execute.rs +0 -541
  128. package/dist-engine-src/src/session/merge/analysis.rs +0 -102
  129. package/dist-engine-src/src/session/merge/apply.rs +0 -23
  130. package/dist-engine-src/src/session/merge/conflicts.rs +0 -63
  131. package/dist-engine-src/src/session/merge/mod.rs +0 -11
  132. package/dist-engine-src/src/session/merge/stats.rs +0 -65
  133. package/dist-engine-src/src/session/merge/version.rs +0 -427
  134. package/dist-engine-src/src/session/mod.rs +0 -27
  135. package/dist-engine-src/src/session/optimization9_sql2_bench.rs +0 -100
  136. package/dist-engine-src/src/session/switch_version.rs +0 -110
  137. package/dist-engine-src/src/session/transaction.rs +0 -76
  138. package/dist-engine-src/src/sql2/change_provider.rs +0 -331
  139. package/dist-engine-src/src/sql2/classify.rs +0 -174
  140. package/dist-engine-src/src/sql2/context.rs +0 -311
  141. package/dist-engine-src/src/sql2/directory_history_provider.rs +0 -631
  142. package/dist-engine-src/src/sql2/directory_provider.rs +0 -2453
  143. package/dist-engine-src/src/sql2/dml.rs +0 -148
  144. package/dist-engine-src/src/sql2/entity_history_provider.rs +0 -440
  145. package/dist-engine-src/src/sql2/entity_provider.rs +0 -3211
  146. package/dist-engine-src/src/sql2/error.rs +0 -215
  147. package/dist-engine-src/src/sql2/execute.rs +0 -3533
  148. package/dist-engine-src/src/sql2/file_history_provider.rs +0 -910
  149. package/dist-engine-src/src/sql2/file_provider.rs +0 -3679
  150. package/dist-engine-src/src/sql2/filesystem_planner.rs +0 -1490
  151. package/dist-engine-src/src/sql2/filesystem_predicates.rs +0 -159
  152. package/dist-engine-src/src/sql2/filesystem_visibility.rs +0 -383
  153. package/dist-engine-src/src/sql2/history_projection.rs +0 -56
  154. package/dist-engine-src/src/sql2/history_provider.rs +0 -412
  155. package/dist-engine-src/src/sql2/history_route.rs +0 -657
  156. package/dist-engine-src/src/sql2/lix_state_provider.rs +0 -2512
  157. package/dist-engine-src/src/sql2/mod.rs +0 -47
  158. package/dist-engine-src/src/sql2/predicate_typecheck.rs +0 -246
  159. package/dist-engine-src/src/sql2/public_bind/assignment.rs +0 -46
  160. package/dist-engine-src/src/sql2/public_bind/capability.rs +0 -41
  161. package/dist-engine-src/src/sql2/public_bind/dml.rs +0 -172
  162. package/dist-engine-src/src/sql2/public_bind/mod.rs +0 -26
  163. package/dist-engine-src/src/sql2/public_bind/table.rs +0 -168
  164. package/dist-engine-src/src/sql2/read_only.rs +0 -63
  165. package/dist-engine-src/src/sql2/record_batch.rs +0 -17
  166. package/dist-engine-src/src/sql2/result_metadata.rs +0 -29
  167. package/dist-engine-src/src/sql2/runtime.rs +0 -60
  168. package/dist-engine-src/src/sql2/session.rs +0 -132
  169. package/dist-engine-src/src/sql2/udfs/common.rs +0 -295
  170. package/dist-engine-src/src/sql2/udfs/lix_active_version_commit_id.rs +0 -53
  171. package/dist-engine-src/src/sql2/udfs/lix_empty_blob.rs +0 -47
  172. package/dist-engine-src/src/sql2/udfs/lix_json.rs +0 -100
  173. package/dist-engine-src/src/sql2/udfs/lix_json_get.rs +0 -99
  174. package/dist-engine-src/src/sql2/udfs/lix_json_get_text.rs +0 -99
  175. package/dist-engine-src/src/sql2/udfs/lix_text_decode.rs +0 -82
  176. package/dist-engine-src/src/sql2/udfs/lix_text_encode.rs +0 -85
  177. package/dist-engine-src/src/sql2/udfs/lix_timestamp.rs +0 -76
  178. package/dist-engine-src/src/sql2/udfs/lix_uuid_v7.rs +0 -76
  179. package/dist-engine-src/src/sql2/udfs/mod.rs +0 -89
  180. package/dist-engine-src/src/sql2/udfs/public_call.rs +0 -238
  181. package/dist-engine-src/src/sql2/version_provider.rs +0 -1202
  182. package/dist-engine-src/src/sql2/version_scope.rs +0 -394
  183. package/dist-engine-src/src/sql2/write_normalization.rs +0 -345
  184. package/dist-engine-src/src/storage/context.rs +0 -356
  185. package/dist-engine-src/src/storage/mod.rs +0 -14
  186. package/dist-engine-src/src/storage/read_scope.rs +0 -88
  187. package/dist-engine-src/src/storage/types.rs +0 -501
  188. package/dist-engine-src/src/storage_bench.rs +0 -4863
  189. package/dist-engine-src/src/test_support.rs +0 -228
  190. package/dist-engine-src/src/tracked_state/by_file_index.rs +0 -98
  191. package/dist-engine-src/src/tracked_state/codec.rs +0 -2085
  192. package/dist-engine-src/src/tracked_state/context.rs +0 -1867
  193. package/dist-engine-src/src/tracked_state/diff.rs +0 -686
  194. package/dist-engine-src/src/tracked_state/materialization.rs +0 -403
  195. package/dist-engine-src/src/tracked_state/materializer.rs +0 -488
  196. package/dist-engine-src/src/tracked_state/merge.rs +0 -492
  197. package/dist-engine-src/src/tracked_state/mod.rs +0 -32
  198. package/dist-engine-src/src/tracked_state/storage.rs +0 -375
  199. package/dist-engine-src/src/tracked_state/tree.rs +0 -3187
  200. package/dist-engine-src/src/tracked_state/types.rs +0 -231
  201. package/dist-engine-src/src/transaction/commit.rs +0 -1484
  202. package/dist-engine-src/src/transaction/context.rs +0 -1548
  203. package/dist-engine-src/src/transaction/live_state_overlay.rs +0 -35
  204. package/dist-engine-src/src/transaction/mod.rs +0 -13
  205. package/dist-engine-src/src/transaction/normalization.rs +0 -890
  206. package/dist-engine-src/src/transaction/prep.rs +0 -37
  207. package/dist-engine-src/src/transaction/schema_resolver.rs +0 -149
  208. package/dist-engine-src/src/transaction/staging.rs +0 -1731
  209. package/dist-engine-src/src/transaction/types.rs +0 -460
  210. package/dist-engine-src/src/transaction/validation.rs +0 -5830
  211. package/dist-engine-src/src/untracked_state/codec.rs +0 -307
  212. package/dist-engine-src/src/untracked_state/context.rs +0 -98
  213. package/dist-engine-src/src/untracked_state/materialization.rs +0 -63
  214. package/dist-engine-src/src/untracked_state/mod.rs +0 -15
  215. package/dist-engine-src/src/untracked_state/storage.rs +0 -396
  216. package/dist-engine-src/src/untracked_state/types.rs +0 -146
  217. package/dist-engine-src/src/version/context.rs +0 -40
  218. package/dist-engine-src/src/version/lifecycle.rs +0 -221
  219. package/dist-engine-src/src/version/mod.rs +0 -13
  220. package/dist-engine-src/src/version/refs.rs +0 -330
  221. package/dist-engine-src/src/version/stage_rows.rs +0 -67
  222. package/dist-engine-src/src/version/types.rs +0 -21
  223. 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, version 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,207 +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 BackendKvPut = {
82
- key: Uint8Array;
83
- value: Uint8Array;
84
- };
85
- export type BackendKvWriteBatch = {
86
- groups: BackendKvWriteGroup[];
87
- };
88
- export type BackendKvWriteGroup = {
89
- namespace: string;
90
- puts: BackendKvPut[];
91
- deletes: Uint8Array[];
92
- };
93
- export type BackendKvWriteStats = {
94
- puts: number;
95
- deletes: number;
96
- bytesWritten: number;
97
- };
98
- export type LixBackendReadTransaction = {
99
- getValues(request: BackendKvGetRequest): BackendKvValueBatch;
100
- existsMany(request: BackendKvGetRequest): BackendKvExistsBatch;
101
- scanKeys(request: BackendKvScanRequest): BackendKvKeyPage;
102
- scanValues(request: BackendKvScanRequest): BackendKvValuePage;
103
- scanEntries(request: BackendKvScanRequest): BackendKvEntryPage;
104
- rollback(): void;
105
- };
106
- export type LixBackendWriteTransaction = LixBackendReadTransaction & {
107
- 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;
108
18
  commit(): void;
19
+ rollback(): void;
109
20
  };
110
- export type LixBackend = {
111
- beginReadTransaction(): LixBackendReadTransaction;
112
- beginWriteTransaction(): LixBackendWriteTransaction;
113
- close?(): void;
114
- };
115
- export type OpenLixOptions = {
116
- backend?: LixBackend;
117
- };
118
- export type CreateVersionOptions = {
119
- id?: string;
120
- name: string;
121
- fromCommitId?: string;
122
- };
123
- export type CreateVersionResult = {
124
- id: string;
125
- name: string;
126
- hidden: boolean;
127
- commitId: string;
128
- };
129
- export type SwitchVersionOptions = {
130
- versionId: string;
131
- };
132
- export type SwitchVersionResult = {
133
- versionId: string;
134
- };
135
- export type MergeVersionOptions = {
136
- sourceVersionId: string;
137
- };
138
- export type MergeVersionOutcome = "alreadyUpToDate" | "fastForward" | "mergeCommitted";
139
- export type MergeVersionResult = {
140
- /**
141
- * How the merge was applied. `fastForward` advances the target ref without
142
- * creating a merge commit, but can still make source changes visible.
143
- */
144
- outcome: MergeVersionOutcome;
145
- targetVersionId: string;
146
- sourceVersionId: string;
147
- baseCommitId: string;
148
- targetHeadBeforeCommitId: string;
149
- sourceHeadBeforeCommitId: string;
150
- targetHeadAfterCommitId: string;
151
- createdMergeCommitId: string | null;
152
- changeStats: MergeChangeStats;
153
- };
154
- export type MergeVersionPreviewResult = {
155
- outcome: MergeVersionOutcome;
156
- targetVersionId: string;
157
- sourceVersionId: string;
158
- baseCommitId: string;
159
- targetHeadCommitId: string;
160
- sourceHeadCommitId: string;
161
- changeStats: MergeChangeStats;
162
- conflicts: MergeConflict[];
163
- };
164
- export type MergeChangeStats = {
165
- total: number;
166
- added: number;
167
- modified: number;
168
- removed: number;
169
- };
170
- export type MergeConflict = {
171
- kind: "sameEntityChanged";
172
- schemaKey: string;
173
- entityId: string[];
174
- fileId: string | null;
175
- target: MergeConflictSide;
176
- source: MergeConflictSide;
177
- };
178
- export type MergeConflictSide = {
179
- kind: "added" | "modified" | "removed";
180
- beforeChangeId: string | null;
181
- afterChangeId: string | null;
182
- };
183
- export type Lix = {
184
- /**
185
- * Executes one DataFusion SQL statement against this Lix session.
186
- *
187
- * This is not SQLite SQL. Use the DataFusion SQL dialect; positional
188
- * placeholders are `?` or `$1`, `$2`, and so on. SQLite-specific catalog tables and
189
- * transaction statements such as `sqlite_master`, `BEGIN`, and `COMMIT` are
190
- * not available. Use `information_schema` for catalog inspection. While a
191
- * transaction is active, call `execute()` on the transaction handle instead.
192
- */
193
- 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>;
194
30
  beginTransaction(): Promise<LixTransaction>;
195
- activeVersionId(): Promise<string>;
196
- createVersion(options: CreateVersionOptions): Promise<CreateVersionResult>;
197
- switchVersion(options: SwitchVersionOptions): Promise<SwitchVersionResult>;
198
- mergeVersionPreview(options: MergeVersionOptions): Promise<MergeVersionPreviewResult>;
199
- mergeVersion(options: MergeVersionOptions): Promise<MergeVersionResult>;
31
+ activeBranchId(): Promise<string>;
32
+ createBranch(options: CreateBranchOptions): Promise<CreateBranchReceipt>;
33
+ switchBranch(options: SwitchBranchOptions): Promise<SwitchBranchReceipt>;
34
+ mergeBranchPreview(options: MergeBranchOptions): Promise<MergeBranchPreview>;
35
+ mergeBranch(options: MergeBranchOptions): Promise<MergeBranchReceipt>;
200
36
  close(): Promise<void>;
201
- };
202
- export type LixTransaction = {
203
- 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>;
204
42
  commit(): Promise<void>;
205
43
  rollback(): Promise<void>;
206
- };
207
- export declare function openLix(options?: OpenLixOptions): Promise<Lix>;
44
+ }
45
+ export {};