@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.
- package/README.md +76 -4
- package/dist/errors.d.ts +7 -0
- package/dist/errors.js +19 -0
- package/dist/index.d.ts +4 -5
- package/dist/index.js +3 -3
- package/dist/native.d.ts +1 -0
- package/dist/native.js +47 -0
- package/dist/open-lix.d.ts +39 -201
- package/dist/open-lix.js +59 -284
- package/dist/result.d.ts +18 -0
- package/dist/result.js +48 -0
- package/dist/types.d.ts +114 -1
- package/dist/value.d.ts +28 -0
- package/dist/value.js +245 -0
- package/package.json +20 -50
- package/SKILL.md +0 -506
- package/dist/builtin-schemas.d.ts +0 -1
- package/dist/builtin-schemas.js +0 -1
- package/dist/engine-wasm/index.d.ts +0 -87
- package/dist/engine-wasm/index.js +0 -339
- package/dist/engine-wasm/wasm/lix_engine.d.ts +0 -79
- package/dist/engine-wasm/wasm/lix_engine.js +0 -821
- package/dist/engine-wasm/wasm/lix_engine.wasm +0 -0
- package/dist/engine-wasm/wasm/lix_engine.wasm.d.ts +0 -26
- package/dist/generated/builtin-schemas.d.ts +0 -427
- package/dist/generated/builtin-schemas.js +0 -643
- package/dist/sqlite/index.d.ts +0 -12
- package/dist/sqlite/index.js +0 -303
- package/dist-engine-src/README.md +0 -18
- package/dist-engine-src/src/backend/kv.rs +0 -358
- package/dist-engine-src/src/backend/mod.rs +0 -12
- package/dist-engine-src/src/backend/testing.rs +0 -658
- package/dist-engine-src/src/backend/types.rs +0 -96
- package/dist-engine-src/src/binary_cas/chunking.rs +0 -31
- package/dist-engine-src/src/binary_cas/codec.rs +0 -346
- package/dist-engine-src/src/binary_cas/context.rs +0 -139
- package/dist-engine-src/src/binary_cas/kv.rs +0 -1063
- package/dist-engine-src/src/binary_cas/mod.rs +0 -11
- package/dist-engine-src/src/binary_cas/types.rs +0 -121
- package/dist-engine-src/src/catalog/context.rs +0 -412
- package/dist-engine-src/src/catalog/mod.rs +0 -10
- package/dist-engine-src/src/catalog/schema.rs +0 -4
- package/dist-engine-src/src/catalog/snapshot.rs +0 -1114
- package/dist-engine-src/src/cel/context.rs +0 -86
- package/dist-engine-src/src/cel/error.rs +0 -19
- package/dist-engine-src/src/cel/mod.rs +0 -8
- package/dist-engine-src/src/cel/provider.rs +0 -9
- package/dist-engine-src/src/cel/runtime.rs +0 -167
- package/dist-engine-src/src/cel/value.rs +0 -50
- package/dist-engine-src/src/commit_graph/context.rs +0 -901
- package/dist-engine-src/src/commit_graph/mod.rs +0 -11
- package/dist-engine-src/src/commit_graph/types.rs +0 -109
- package/dist-engine-src/src/commit_graph/walker.rs +0 -756
- package/dist-engine-src/src/commit_store/codec.rs +0 -887
- package/dist-engine-src/src/commit_store/context.rs +0 -944
- package/dist-engine-src/src/commit_store/materialization.rs +0 -84
- package/dist-engine-src/src/commit_store/mod.rs +0 -16
- package/dist-engine-src/src/commit_store/storage.rs +0 -600
- package/dist-engine-src/src/commit_store/types.rs +0 -215
- package/dist-engine-src/src/common/error.rs +0 -313
- package/dist-engine-src/src/common/fingerprint.rs +0 -3
- package/dist-engine-src/src/common/fs_path.rs +0 -1336
- package/dist-engine-src/src/common/identity.rs +0 -145
- package/dist-engine-src/src/common/json_pointer.rs +0 -67
- package/dist-engine-src/src/common/metadata.rs +0 -40
- package/dist-engine-src/src/common/mod.rs +0 -23
- package/dist-engine-src/src/common/types.rs +0 -105
- package/dist-engine-src/src/common/wire.rs +0 -222
- package/dist-engine-src/src/domain.rs +0 -324
- package/dist-engine-src/src/engine.rs +0 -225
- package/dist-engine-src/src/entity_identity.rs +0 -405
- package/dist-engine-src/src/functions/context.rs +0 -292
- package/dist-engine-src/src/functions/deterministic.rs +0 -113
- package/dist-engine-src/src/functions/mod.rs +0 -18
- package/dist-engine-src/src/functions/provider.rs +0 -130
- package/dist-engine-src/src/functions/state.rs +0 -336
- package/dist-engine-src/src/functions/types.rs +0 -37
- package/dist-engine-src/src/init.rs +0 -558
- package/dist-engine-src/src/json_store/compression.rs +0 -77
- package/dist-engine-src/src/json_store/context.rs +0 -423
- package/dist-engine-src/src/json_store/encoded.rs +0 -15
- package/dist-engine-src/src/json_store/mod.rs +0 -12
- package/dist-engine-src/src/json_store/store.rs +0 -1109
- package/dist-engine-src/src/json_store/types.rs +0 -217
- package/dist-engine-src/src/lib.rs +0 -62
- package/dist-engine-src/src/live_state/context.rs +0 -2019
- package/dist-engine-src/src/live_state/mod.rs +0 -15
- package/dist-engine-src/src/live_state/overlay.rs +0 -75
- package/dist-engine-src/src/live_state/reader.rs +0 -23
- package/dist-engine-src/src/live_state/types.rs +0 -222
- package/dist-engine-src/src/live_state/visibility.rs +0 -223
- package/dist-engine-src/src/plugin/archive.rs +0 -438
- package/dist-engine-src/src/plugin/component.rs +0 -183
- package/dist-engine-src/src/plugin/install.rs +0 -619
- package/dist-engine-src/src/plugin/manifest.rs +0 -516
- package/dist-engine-src/src/plugin/materializer.rs +0 -477
- package/dist-engine-src/src/plugin/mod.rs +0 -33
- package/dist-engine-src/src/plugin/plugin_manifest.json +0 -118
- package/dist-engine-src/src/plugin/storage.rs +0 -74
- package/dist-engine-src/src/schema/annotations/defaults.rs +0 -275
- package/dist-engine-src/src/schema/annotations/mod.rs +0 -1
- package/dist-engine-src/src/schema/builtin/lix_account.json +0 -21
- package/dist-engine-src/src/schema/builtin/lix_active_account.json +0 -29
- package/dist-engine-src/src/schema/builtin/lix_binary_blob_ref.json +0 -29
- package/dist-engine-src/src/schema/builtin/lix_change.json +0 -63
- package/dist-engine-src/src/schema/builtin/lix_change_author.json +0 -45
- package/dist-engine-src/src/schema/builtin/lix_commit.json +0 -24
- package/dist-engine-src/src/schema/builtin/lix_commit_edge.json +0 -53
- package/dist-engine-src/src/schema/builtin/lix_directory_descriptor.json +0 -52
- package/dist-engine-src/src/schema/builtin/lix_file_descriptor.json +0 -52
- package/dist-engine-src/src/schema/builtin/lix_key_value.json +0 -40
- package/dist-engine-src/src/schema/builtin/lix_label.json +0 -29
- package/dist-engine-src/src/schema/builtin/lix_label_assignment.json +0 -74
- package/dist-engine-src/src/schema/builtin/lix_registered_schema.json +0 -25
- package/dist-engine-src/src/schema/builtin/lix_version_descriptor.json +0 -34
- package/dist-engine-src/src/schema/builtin/lix_version_ref.json +0 -48
- package/dist-engine-src/src/schema/builtin/mod.rs +0 -222
- package/dist-engine-src/src/schema/compatibility.rs +0 -787
- package/dist-engine-src/src/schema/definition.json +0 -187
- package/dist-engine-src/src/schema/definition.rs +0 -742
- package/dist-engine-src/src/schema/key.rs +0 -138
- package/dist-engine-src/src/schema/mod.rs +0 -20
- package/dist-engine-src/src/schema/seed.rs +0 -14
- package/dist-engine-src/src/schema/tests.rs +0 -780
- package/dist-engine-src/src/session/context.rs +0 -404
- package/dist-engine-src/src/session/create_version.rs +0 -88
- package/dist-engine-src/src/session/execute.rs +0 -541
- package/dist-engine-src/src/session/merge/analysis.rs +0 -102
- package/dist-engine-src/src/session/merge/apply.rs +0 -23
- package/dist-engine-src/src/session/merge/conflicts.rs +0 -63
- package/dist-engine-src/src/session/merge/mod.rs +0 -11
- package/dist-engine-src/src/session/merge/stats.rs +0 -65
- package/dist-engine-src/src/session/merge/version.rs +0 -427
- package/dist-engine-src/src/session/mod.rs +0 -27
- package/dist-engine-src/src/session/optimization9_sql2_bench.rs +0 -100
- package/dist-engine-src/src/session/switch_version.rs +0 -110
- package/dist-engine-src/src/session/transaction.rs +0 -76
- package/dist-engine-src/src/sql2/change_provider.rs +0 -331
- package/dist-engine-src/src/sql2/classify.rs +0 -174
- package/dist-engine-src/src/sql2/context.rs +0 -311
- package/dist-engine-src/src/sql2/directory_history_provider.rs +0 -631
- package/dist-engine-src/src/sql2/directory_provider.rs +0 -2453
- package/dist-engine-src/src/sql2/dml.rs +0 -148
- package/dist-engine-src/src/sql2/entity_history_provider.rs +0 -440
- package/dist-engine-src/src/sql2/entity_provider.rs +0 -3211
- package/dist-engine-src/src/sql2/error.rs +0 -215
- package/dist-engine-src/src/sql2/execute.rs +0 -3533
- package/dist-engine-src/src/sql2/file_history_provider.rs +0 -910
- package/dist-engine-src/src/sql2/file_provider.rs +0 -3679
- package/dist-engine-src/src/sql2/filesystem_planner.rs +0 -1490
- package/dist-engine-src/src/sql2/filesystem_predicates.rs +0 -159
- package/dist-engine-src/src/sql2/filesystem_visibility.rs +0 -383
- package/dist-engine-src/src/sql2/history_projection.rs +0 -56
- package/dist-engine-src/src/sql2/history_provider.rs +0 -412
- package/dist-engine-src/src/sql2/history_route.rs +0 -657
- package/dist-engine-src/src/sql2/lix_state_provider.rs +0 -2512
- package/dist-engine-src/src/sql2/mod.rs +0 -47
- package/dist-engine-src/src/sql2/predicate_typecheck.rs +0 -246
- package/dist-engine-src/src/sql2/public_bind/assignment.rs +0 -46
- package/dist-engine-src/src/sql2/public_bind/capability.rs +0 -41
- package/dist-engine-src/src/sql2/public_bind/dml.rs +0 -172
- package/dist-engine-src/src/sql2/public_bind/mod.rs +0 -26
- package/dist-engine-src/src/sql2/public_bind/table.rs +0 -168
- package/dist-engine-src/src/sql2/read_only.rs +0 -63
- package/dist-engine-src/src/sql2/record_batch.rs +0 -17
- package/dist-engine-src/src/sql2/result_metadata.rs +0 -29
- package/dist-engine-src/src/sql2/runtime.rs +0 -60
- package/dist-engine-src/src/sql2/session.rs +0 -132
- package/dist-engine-src/src/sql2/udfs/common.rs +0 -295
- package/dist-engine-src/src/sql2/udfs/lix_active_version_commit_id.rs +0 -53
- package/dist-engine-src/src/sql2/udfs/lix_empty_blob.rs +0 -47
- package/dist-engine-src/src/sql2/udfs/lix_json.rs +0 -100
- package/dist-engine-src/src/sql2/udfs/lix_json_get.rs +0 -99
- package/dist-engine-src/src/sql2/udfs/lix_json_get_text.rs +0 -99
- package/dist-engine-src/src/sql2/udfs/lix_text_decode.rs +0 -82
- package/dist-engine-src/src/sql2/udfs/lix_text_encode.rs +0 -85
- package/dist-engine-src/src/sql2/udfs/lix_timestamp.rs +0 -76
- package/dist-engine-src/src/sql2/udfs/lix_uuid_v7.rs +0 -76
- package/dist-engine-src/src/sql2/udfs/mod.rs +0 -89
- package/dist-engine-src/src/sql2/udfs/public_call.rs +0 -238
- package/dist-engine-src/src/sql2/version_provider.rs +0 -1202
- package/dist-engine-src/src/sql2/version_scope.rs +0 -394
- package/dist-engine-src/src/sql2/write_normalization.rs +0 -345
- package/dist-engine-src/src/storage/context.rs +0 -356
- package/dist-engine-src/src/storage/mod.rs +0 -14
- package/dist-engine-src/src/storage/read_scope.rs +0 -88
- package/dist-engine-src/src/storage/types.rs +0 -501
- package/dist-engine-src/src/storage_bench.rs +0 -4863
- package/dist-engine-src/src/test_support.rs +0 -228
- package/dist-engine-src/src/tracked_state/by_file_index.rs +0 -98
- package/dist-engine-src/src/tracked_state/codec.rs +0 -2085
- package/dist-engine-src/src/tracked_state/context.rs +0 -1867
- package/dist-engine-src/src/tracked_state/diff.rs +0 -686
- package/dist-engine-src/src/tracked_state/materialization.rs +0 -403
- package/dist-engine-src/src/tracked_state/materializer.rs +0 -488
- package/dist-engine-src/src/tracked_state/merge.rs +0 -492
- package/dist-engine-src/src/tracked_state/mod.rs +0 -32
- package/dist-engine-src/src/tracked_state/storage.rs +0 -375
- package/dist-engine-src/src/tracked_state/tree.rs +0 -3187
- package/dist-engine-src/src/tracked_state/types.rs +0 -231
- package/dist-engine-src/src/transaction/commit.rs +0 -1484
- package/dist-engine-src/src/transaction/context.rs +0 -1548
- package/dist-engine-src/src/transaction/live_state_overlay.rs +0 -35
- package/dist-engine-src/src/transaction/mod.rs +0 -13
- package/dist-engine-src/src/transaction/normalization.rs +0 -890
- package/dist-engine-src/src/transaction/prep.rs +0 -37
- package/dist-engine-src/src/transaction/schema_resolver.rs +0 -149
- package/dist-engine-src/src/transaction/staging.rs +0 -1731
- package/dist-engine-src/src/transaction/types.rs +0 -460
- package/dist-engine-src/src/transaction/validation.rs +0 -5830
- package/dist-engine-src/src/untracked_state/codec.rs +0 -307
- package/dist-engine-src/src/untracked_state/context.rs +0 -98
- package/dist-engine-src/src/untracked_state/materialization.rs +0 -63
- package/dist-engine-src/src/untracked_state/mod.rs +0 -15
- package/dist-engine-src/src/untracked_state/storage.rs +0 -396
- package/dist-engine-src/src/untracked_state/types.rs +0 -146
- package/dist-engine-src/src/version/context.rs +0 -40
- package/dist-engine-src/src/version/lifecycle.rs +0 -221
- package/dist-engine-src/src/version/mod.rs +0 -13
- package/dist-engine-src/src/version/refs.rs +0 -330
- package/dist-engine-src/src/version/stage_rows.rs +0 -67
- package/dist-engine-src/src/version/types.rs +0 -21
- package/dist-engine-src/src/wasm/mod.rs +0 -60
package/dist/open-lix.js
CHANGED
|
@@ -1,307 +1,82 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
get(columnName) {
|
|
11
|
-
return valueToNative(this.value(columnName));
|
|
12
|
-
}
|
|
13
|
-
tryGet(columnName) {
|
|
14
|
-
const value = this.tryValue(columnName);
|
|
15
|
-
return value === undefined ? undefined : valueToNative(value);
|
|
16
|
-
}
|
|
17
|
-
value(columnName) {
|
|
18
|
-
const index = this.columns.indexOf(columnName);
|
|
19
|
-
if (index === -1) {
|
|
20
|
-
throw createLixError("LIX_COLUMN_NOT_FOUND", `Column "${columnName}" does not exist. Available columns: ${this.availableColumns()}`);
|
|
1
|
+
import { invalidArgument } from "./errors.js";
|
|
2
|
+
import { addon } from "./native.js";
|
|
3
|
+
import { normalizeOptionals, wrapExecuteResult } from "./result.js";
|
|
4
|
+
import { normalizeParam, toNativeValue } from "./value.js";
|
|
5
|
+
export class SqliteBackend {
|
|
6
|
+
path;
|
|
7
|
+
constructor(options) {
|
|
8
|
+
if (!options || typeof options.path !== "string" || options.path.length === 0) {
|
|
9
|
+
throw new TypeError("SqliteBackend requires a non-empty path");
|
|
21
10
|
}
|
|
22
|
-
|
|
23
|
-
if (value === undefined) {
|
|
24
|
-
throw createLixError("LIX_COLUMN_NOT_FOUND", `Column "${columnName}" is outside row width ${this.valuesByIndex.length}.`);
|
|
25
|
-
}
|
|
26
|
-
return value;
|
|
11
|
+
this.path = options.path;
|
|
27
12
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
13
|
+
}
|
|
14
|
+
export async function openLix(options = {}) {
|
|
15
|
+
if (!options || typeof options !== "object") {
|
|
16
|
+
throw new TypeError("openLix() options must be an object");
|
|
31
17
|
}
|
|
32
|
-
|
|
33
|
-
return
|
|
18
|
+
if (options.backend === undefined) {
|
|
19
|
+
return new Lix(addon.Lix.openMemory());
|
|
34
20
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (value === undefined) {
|
|
38
|
-
throw createLixError("LIX_COLUMN_NOT_FOUND", `Column index ${index} is outside row width ${this.valuesByIndex.length}.`);
|
|
39
|
-
}
|
|
40
|
-
return value;
|
|
21
|
+
if (!(options.backend instanceof SqliteBackend)) {
|
|
22
|
+
throw new TypeError("openLix() requires { backend: new SqliteBackend({ path }) }");
|
|
41
23
|
}
|
|
42
|
-
|
|
43
|
-
|
|
24
|
+
return new Lix(addon.Lix.openSqlite(options.backend.path));
|
|
25
|
+
}
|
|
26
|
+
export class Lix {
|
|
27
|
+
native;
|
|
28
|
+
constructor(native) {
|
|
29
|
+
this.native = native;
|
|
44
30
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
valueToNative(this.valueAt(index)),
|
|
49
|
-
]));
|
|
31
|
+
async execute(sql, params = []) {
|
|
32
|
+
assertExecuteArgs("lix", sql, params);
|
|
33
|
+
return wrapExecuteResult(this.native.execute(sql, params.map((param, index) => toNativeValue(normalizeParam(param, index)))));
|
|
50
34
|
}
|
|
51
|
-
|
|
52
|
-
return
|
|
35
|
+
async beginTransaction() {
|
|
36
|
+
return new LixTransaction(this.native.beginTransaction());
|
|
53
37
|
}
|
|
54
|
-
|
|
55
|
-
return this.
|
|
38
|
+
async activeBranchId() {
|
|
39
|
+
return this.native.activeBranchId();
|
|
56
40
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
switch (value.kind) {
|
|
60
|
-
case "null":
|
|
61
|
-
return null;
|
|
62
|
-
case "boolean":
|
|
63
|
-
case "integer":
|
|
64
|
-
case "real":
|
|
65
|
-
case "text":
|
|
66
|
-
case "json":
|
|
67
|
-
return value.value;
|
|
68
|
-
case "blob":
|
|
69
|
-
return value.asBlob() ?? new Uint8Array();
|
|
41
|
+
async createBranch(options) {
|
|
42
|
+
return this.native.createBranch(options);
|
|
70
43
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
async function ensureWasmReady() {
|
|
74
|
-
if (!wasmReady) {
|
|
75
|
-
wasmReady = resolveEngineWasmModuleOrPath()
|
|
76
|
-
.then((module_or_path) => init({ module_or_path }))
|
|
77
|
-
.then(() => undefined);
|
|
44
|
+
async switchBranch(options) {
|
|
45
|
+
return this.native.switchBranch(options);
|
|
78
46
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
export async function openLix(options = {}) {
|
|
82
|
-
await ensureWasmReady();
|
|
83
|
-
try {
|
|
84
|
-
const wasmLix = (await wasmModule.openLix(options));
|
|
85
|
-
return createLixHandle(wasmLix);
|
|
47
|
+
async mergeBranchPreview(options) {
|
|
48
|
+
return normalizeOptionals(this.native.mergeBranchPreview(options));
|
|
86
49
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
catch {
|
|
92
|
-
// Preserve the original open failure.
|
|
93
|
-
}
|
|
94
|
-
throw normalizeThrownError(error);
|
|
50
|
+
async mergeBranch(options) {
|
|
51
|
+
const receipt = normalizeOptionals(this.native.mergeBranch(options));
|
|
52
|
+
receipt.createdMergeCommitId ??= null;
|
|
53
|
+
return receipt;
|
|
95
54
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
let operationQueue = Promise.resolve();
|
|
99
|
-
const acquireOperationSlot = async () => {
|
|
100
|
-
const previous = operationQueue;
|
|
101
|
-
let releaseCurrent;
|
|
102
|
-
const current = new Promise((resolve) => {
|
|
103
|
-
releaseCurrent = resolve;
|
|
104
|
-
});
|
|
105
|
-
operationQueue = previous.then(() => current);
|
|
106
|
-
await previous;
|
|
107
|
-
return () => releaseCurrent?.();
|
|
108
|
-
};
|
|
109
|
-
const runQueued = async (operation) => {
|
|
110
|
-
const release = await acquireOperationSlot();
|
|
111
|
-
try {
|
|
112
|
-
return await operation();
|
|
113
|
-
}
|
|
114
|
-
catch (error) {
|
|
115
|
-
throw normalizeThrownError(error);
|
|
116
|
-
}
|
|
117
|
-
finally {
|
|
118
|
-
release();
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
return {
|
|
122
|
-
async execute(sql, params = []) {
|
|
123
|
-
validateExecuteArguments(sql, params);
|
|
124
|
-
const values = params.map((param, index) => valueFromExecuteParam(param, index));
|
|
125
|
-
const result = await runQueued(() => wasmLix.execute(sql, values));
|
|
126
|
-
return normalizeExecuteResult(result);
|
|
127
|
-
},
|
|
128
|
-
async beginTransaction() {
|
|
129
|
-
const wasmTransaction = await runQueued(() => wasmLix.beginTransaction());
|
|
130
|
-
return createLixTransactionHandle(wasmTransaction, runQueued);
|
|
131
|
-
},
|
|
132
|
-
async activeVersionId() {
|
|
133
|
-
return await runQueued(() => wasmLix.activeVersionId());
|
|
134
|
-
},
|
|
135
|
-
async createVersion(options) {
|
|
136
|
-
return await runQueued(() => wasmLix.createVersion(options));
|
|
137
|
-
},
|
|
138
|
-
async switchVersion(options) {
|
|
139
|
-
return await runQueued(() => wasmLix.switchVersion(options));
|
|
140
|
-
},
|
|
141
|
-
async mergeVersionPreview(options) {
|
|
142
|
-
return await runQueued(() => wasmLix.mergeVersionPreview(options));
|
|
143
|
-
},
|
|
144
|
-
async mergeVersion(options) {
|
|
145
|
-
return await runQueued(() => wasmLix.mergeVersion(options));
|
|
146
|
-
},
|
|
147
|
-
async close() {
|
|
148
|
-
await runQueued(() => wasmLix.close());
|
|
149
|
-
},
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
function createLixTransactionHandle(wasmTransaction, runQueued) {
|
|
153
|
-
let closed = false;
|
|
154
|
-
const ensureOpen = () => {
|
|
155
|
-
if (closed) {
|
|
156
|
-
throw createLixError("LIX_INVALID_TRANSACTION_STATE", "Lix transaction is closed");
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
return {
|
|
160
|
-
async execute(sql, params = []) {
|
|
161
|
-
ensureOpen();
|
|
162
|
-
validateExecuteArguments(sql, params);
|
|
163
|
-
const values = params.map((param, index) => valueFromExecuteParam(param, index));
|
|
164
|
-
const result = await runQueued(() => wasmTransaction.execute(sql, values));
|
|
165
|
-
return normalizeExecuteResult(result);
|
|
166
|
-
},
|
|
167
|
-
async commit() {
|
|
168
|
-
ensureOpen();
|
|
169
|
-
try {
|
|
170
|
-
await runQueued(() => wasmTransaction.commit());
|
|
171
|
-
}
|
|
172
|
-
finally {
|
|
173
|
-
closed = true;
|
|
174
|
-
}
|
|
175
|
-
},
|
|
176
|
-
async rollback() {
|
|
177
|
-
ensureOpen();
|
|
178
|
-
try {
|
|
179
|
-
await runQueued(() => wasmTransaction.rollback());
|
|
180
|
-
}
|
|
181
|
-
finally {
|
|
182
|
-
closed = true;
|
|
183
|
-
}
|
|
184
|
-
},
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
function validateExecuteArguments(sql, params) {
|
|
188
|
-
if (typeof sql !== "string") {
|
|
189
|
-
throw invalidArgumentError("execute", "sql", "string", sql);
|
|
190
|
-
}
|
|
191
|
-
if (!Array.isArray(params)) {
|
|
192
|
-
throw invalidArgumentError("execute", "params", "array", params);
|
|
55
|
+
async close() {
|
|
56
|
+
return this.native.close();
|
|
193
57
|
}
|
|
194
58
|
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
argument,
|
|
200
|
-
expected,
|
|
201
|
-
actual: runtimeTypeName(actualValue),
|
|
202
|
-
},
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
function valueFromExecuteParam(param, index) {
|
|
206
|
-
try {
|
|
207
|
-
return Value.from(param);
|
|
208
|
-
}
|
|
209
|
-
catch (error) {
|
|
210
|
-
throw invalidParamError(index, param, error);
|
|
59
|
+
export class LixTransaction {
|
|
60
|
+
native;
|
|
61
|
+
constructor(native) {
|
|
62
|
+
this.native = native;
|
|
211
63
|
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
? cause.message
|
|
216
|
-
: "parameter is not a valid Lix SQL value";
|
|
217
|
-
return createLixError("LIX_INVALID_PARAM", `lix.execute() invalid parameter $${index + 1}: ${message}`, {
|
|
218
|
-
details: {
|
|
219
|
-
operation: "execute",
|
|
220
|
-
parameter_index: index + 1,
|
|
221
|
-
argument: `params[${index}]`,
|
|
222
|
-
actual: runtimeTypeName(actualValue),
|
|
223
|
-
},
|
|
224
|
-
cause,
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
function expectedArticle(expected) {
|
|
228
|
-
return /^[aeiou]/i.test(expected) ? "an" : "a";
|
|
229
|
-
}
|
|
230
|
-
function runtimeTypeName(value) {
|
|
231
|
-
if (value === null)
|
|
232
|
-
return "null";
|
|
233
|
-
if (Array.isArray(value))
|
|
234
|
-
return "array";
|
|
235
|
-
if (value instanceof Date)
|
|
236
|
-
return "Date";
|
|
237
|
-
if (value instanceof ArrayBuffer)
|
|
238
|
-
return "ArrayBuffer";
|
|
239
|
-
if (ArrayBuffer.isView(value))
|
|
240
|
-
return value.constructor.name;
|
|
241
|
-
return typeof value;
|
|
242
|
-
}
|
|
243
|
-
function normalizeExecuteResult(result) {
|
|
244
|
-
const columns = [...result.columns];
|
|
245
|
-
return {
|
|
246
|
-
columns,
|
|
247
|
-
rows: result.rows.map((row) => new Row(columns, row.map((value) => Value.from(value)))),
|
|
248
|
-
rowsAffected: result.rowsAffected,
|
|
249
|
-
notices: result.notices ?? [],
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
|
-
function createLixError(code, message, options = {}) {
|
|
253
|
-
const error = new Error(message);
|
|
254
|
-
error.name = "LixError";
|
|
255
|
-
error.code = code;
|
|
256
|
-
if (options.hint !== undefined) {
|
|
257
|
-
error.hint = options.hint;
|
|
64
|
+
async execute(sql, params = []) {
|
|
65
|
+
assertExecuteArgs("lixTransaction", sql, params);
|
|
66
|
+
return wrapExecuteResult(this.native.execute(sql, params.map((param, index) => toNativeValue(normalizeParam(param, index)))));
|
|
258
67
|
}
|
|
259
|
-
|
|
260
|
-
|
|
68
|
+
async commit() {
|
|
69
|
+
return this.native.commit();
|
|
261
70
|
}
|
|
262
|
-
|
|
263
|
-
|
|
71
|
+
async rollback() {
|
|
72
|
+
return this.native.rollback();
|
|
264
73
|
}
|
|
265
|
-
return error;
|
|
266
74
|
}
|
|
267
|
-
function
|
|
268
|
-
if (
|
|
269
|
-
|
|
270
|
-
? error.hint
|
|
271
|
-
: extractHintFromMessage(error.message);
|
|
272
|
-
const details = "details" in error ? error.details : undefined;
|
|
273
|
-
if (error instanceof Error) {
|
|
274
|
-
if (hint !== undefined && error.hint === undefined) {
|
|
275
|
-
error.hint = hint;
|
|
276
|
-
}
|
|
277
|
-
if (details !== undefined && error.details === undefined) {
|
|
278
|
-
error.details = details;
|
|
279
|
-
}
|
|
280
|
-
return error;
|
|
281
|
-
}
|
|
282
|
-
const message = typeof error.message === "string" ? error.message : error.code;
|
|
283
|
-
return createLixError(error.code, message, { hint, details });
|
|
284
|
-
}
|
|
285
|
-
if (error instanceof WebAssembly.RuntimeError) {
|
|
286
|
-
return createLixError("LIX_WASM_RUNTIME_ERROR", error.message, {
|
|
287
|
-
hint: "The Lix engine encountered a WebAssembly runtime trap. Please report this as an engine bug with the SQL statement or API call that triggered it.",
|
|
288
|
-
cause: error,
|
|
289
|
-
});
|
|
75
|
+
function assertExecuteArgs(receiver, sql, params) {
|
|
76
|
+
if (typeof sql !== "string") {
|
|
77
|
+
throw invalidArgument("execute", "sql", "string", typeof sql, receiver);
|
|
290
78
|
}
|
|
291
|
-
if (
|
|
292
|
-
|
|
79
|
+
if (!Array.isArray(params)) {
|
|
80
|
+
throw invalidArgument("execute", "params", "array", typeof params, receiver);
|
|
293
81
|
}
|
|
294
|
-
return createLixError("LIX_ERROR_UNKNOWN", String(error));
|
|
295
|
-
}
|
|
296
|
-
function extractHintFromMessage(message) {
|
|
297
|
-
if (typeof message !== "string")
|
|
298
|
-
return undefined;
|
|
299
|
-
const match = message.match(/(?:^|\n)hint:\s*(.+)$/s);
|
|
300
|
-
return match?.[1]?.trim();
|
|
301
|
-
}
|
|
302
|
-
function isLixErrorLike(error) {
|
|
303
|
-
return (typeof error === "object" &&
|
|
304
|
-
error !== null &&
|
|
305
|
-
typeof error.code === "string" &&
|
|
306
|
-
error.code.startsWith("LIX_"));
|
|
307
82
|
}
|
package/dist/result.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type NativeLixValue, Value } from "./value.js";
|
|
2
|
+
import type { ExecuteResult, LixValue } from "./types.js";
|
|
3
|
+
export declare class Row {
|
|
4
|
+
private readonly columns;
|
|
5
|
+
private readonly values;
|
|
6
|
+
constructor(columns: string[], values: Value[]);
|
|
7
|
+
static fromRaw(columns: string[], values: LixValue[]): Row;
|
|
8
|
+
get(column: string): unknown;
|
|
9
|
+
value(column: string): Value;
|
|
10
|
+
toObject(): Record<string, unknown>;
|
|
11
|
+
toValueMap(): Record<string, Value>;
|
|
12
|
+
}
|
|
13
|
+
type NativeExecuteResult = Omit<ExecuteResult, "rows"> & {
|
|
14
|
+
rows: NativeLixValue[][];
|
|
15
|
+
};
|
|
16
|
+
export declare function wrapExecuteResult(result: NativeExecuteResult): ExecuteResult;
|
|
17
|
+
export declare function normalizeOptionals<T>(value: T): T;
|
|
18
|
+
export {};
|
package/dist/result.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { fromNativeValue, Value } from "./value.js";
|
|
2
|
+
export class Row {
|
|
3
|
+
columns;
|
|
4
|
+
values;
|
|
5
|
+
constructor(columns, values) {
|
|
6
|
+
this.columns = columns;
|
|
7
|
+
this.values = values;
|
|
8
|
+
}
|
|
9
|
+
static fromRaw(columns, values) {
|
|
10
|
+
return new Row(columns, values.map((value) => Value._fromNative(value)));
|
|
11
|
+
}
|
|
12
|
+
get(column) {
|
|
13
|
+
return this.value(column).toJS();
|
|
14
|
+
}
|
|
15
|
+
value(column) {
|
|
16
|
+
const index = this.columns.indexOf(column);
|
|
17
|
+
if (index === -1) {
|
|
18
|
+
throw new Error(`Unknown column "${column}". Available columns: ${this.columns.join(", ")}`);
|
|
19
|
+
}
|
|
20
|
+
const value = this.values[index];
|
|
21
|
+
if (!value) {
|
|
22
|
+
throw new Error(`Column "${column}" is missing a value`);
|
|
23
|
+
}
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
toObject() {
|
|
27
|
+
return Object.fromEntries(this.columns.map((column, index) => [column, this.values[index]?.toJS()]));
|
|
28
|
+
}
|
|
29
|
+
toValueMap() {
|
|
30
|
+
return Object.fromEntries(this.columns.map((column, index) => [column, this.values[index]]));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export function wrapExecuteResult(result) {
|
|
34
|
+
return {
|
|
35
|
+
...result,
|
|
36
|
+
rows: result.rows.map((row) => Row.fromRaw(result.columns, row.map(fromNativeValue))),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export function normalizeOptionals(value) {
|
|
40
|
+
if (Array.isArray(value))
|
|
41
|
+
return value.map(normalizeOptionals);
|
|
42
|
+
if (!value || typeof value !== "object")
|
|
43
|
+
return value;
|
|
44
|
+
return Object.fromEntries(Object.entries(value).map(([key, entry]) => [
|
|
45
|
+
key,
|
|
46
|
+
entry === undefined ? null : normalizeOptionals(entry),
|
|
47
|
+
]));
|
|
48
|
+
}
|
package/dist/types.d.ts
CHANGED
|
@@ -1 +1,114 @@
|
|
|
1
|
-
export type
|
|
1
|
+
export type SqliteBackendOptions = {
|
|
2
|
+
path: string;
|
|
3
|
+
};
|
|
4
|
+
export type OpenLixOptions = {
|
|
5
|
+
backend?: import("./open-lix.js").SqliteBackend;
|
|
6
|
+
};
|
|
7
|
+
export type LixValue = {
|
|
8
|
+
kind: "null";
|
|
9
|
+
value: null;
|
|
10
|
+
} | {
|
|
11
|
+
kind: "boolean";
|
|
12
|
+
value: boolean;
|
|
13
|
+
} | {
|
|
14
|
+
kind: "integer";
|
|
15
|
+
value: number;
|
|
16
|
+
} | {
|
|
17
|
+
kind: "real";
|
|
18
|
+
value: number;
|
|
19
|
+
} | {
|
|
20
|
+
kind: "text";
|
|
21
|
+
value: string;
|
|
22
|
+
} | {
|
|
23
|
+
kind: "json";
|
|
24
|
+
value: JsonValue;
|
|
25
|
+
} | {
|
|
26
|
+
kind: "blob";
|
|
27
|
+
value: Uint8Array;
|
|
28
|
+
};
|
|
29
|
+
export type JsonValue = null | boolean | number | string | readonly JsonValue[] | {
|
|
30
|
+
readonly [key: string]: JsonValue;
|
|
31
|
+
};
|
|
32
|
+
export type SqlParam = JsonValue | Uint8Array | import("./value.js").Value;
|
|
33
|
+
export type ExecuteResult = {
|
|
34
|
+
columns: string[];
|
|
35
|
+
rows: RowLike[];
|
|
36
|
+
rowsAffected: number;
|
|
37
|
+
notices: Array<{
|
|
38
|
+
code: string;
|
|
39
|
+
message: string;
|
|
40
|
+
hint?: string;
|
|
41
|
+
}>;
|
|
42
|
+
};
|
|
43
|
+
export type RowLike = {
|
|
44
|
+
get(column: string): unknown;
|
|
45
|
+
value(column: string): ValueLike;
|
|
46
|
+
toObject(): Record<string, unknown>;
|
|
47
|
+
toValueMap(): Record<string, ValueLike>;
|
|
48
|
+
};
|
|
49
|
+
export type ValueLike = {
|
|
50
|
+
readonly kind: LixValue["kind"];
|
|
51
|
+
toJS(): unknown;
|
|
52
|
+
asBytes(): Uint8Array | undefined;
|
|
53
|
+
};
|
|
54
|
+
export type CreateBranchOptions = {
|
|
55
|
+
id?: string;
|
|
56
|
+
name: string;
|
|
57
|
+
fromCommitId?: string;
|
|
58
|
+
};
|
|
59
|
+
export type CreateBranchReceipt = {
|
|
60
|
+
id: string;
|
|
61
|
+
name: string;
|
|
62
|
+
hidden: boolean;
|
|
63
|
+
commitId: string;
|
|
64
|
+
};
|
|
65
|
+
export type SwitchBranchOptions = {
|
|
66
|
+
branchId: string;
|
|
67
|
+
};
|
|
68
|
+
export type SwitchBranchReceipt = {
|
|
69
|
+
branchId: string;
|
|
70
|
+
};
|
|
71
|
+
export type MergeBranchOptions = {
|
|
72
|
+
sourceBranchId: string;
|
|
73
|
+
};
|
|
74
|
+
export type MergeBranchOutcome = "alreadyUpToDate" | "fastForward" | "mergeCommitted";
|
|
75
|
+
export type MergeBranchReceipt = {
|
|
76
|
+
outcome: MergeBranchOutcome;
|
|
77
|
+
targetBranchId: string;
|
|
78
|
+
sourceBranchId: string;
|
|
79
|
+
baseCommitId: string;
|
|
80
|
+
targetHeadBeforeCommitId: string;
|
|
81
|
+
sourceHeadBeforeCommitId: string;
|
|
82
|
+
targetHeadAfterCommitId: string;
|
|
83
|
+
createdMergeCommitId: string | null;
|
|
84
|
+
changeStats: MergeChangeStats;
|
|
85
|
+
};
|
|
86
|
+
export type MergeBranchPreview = {
|
|
87
|
+
outcome: MergeBranchOutcome;
|
|
88
|
+
targetBranchId: string;
|
|
89
|
+
sourceBranchId: string;
|
|
90
|
+
baseCommitId: string;
|
|
91
|
+
targetHeadCommitId: string;
|
|
92
|
+
sourceHeadCommitId: string;
|
|
93
|
+
changeStats: MergeChangeStats;
|
|
94
|
+
conflicts: MergeConflict[];
|
|
95
|
+
};
|
|
96
|
+
export type MergeChangeStats = {
|
|
97
|
+
total: number;
|
|
98
|
+
added: number;
|
|
99
|
+
modified: number;
|
|
100
|
+
removed: number;
|
|
101
|
+
};
|
|
102
|
+
export type MergeConflict = {
|
|
103
|
+
kind: "sameEntityChanged";
|
|
104
|
+
schemaKey: string;
|
|
105
|
+
entityPk: unknown;
|
|
106
|
+
fileId: string | null;
|
|
107
|
+
target: MergeConflictSide;
|
|
108
|
+
source: MergeConflictSide;
|
|
109
|
+
};
|
|
110
|
+
export type MergeConflictSide = {
|
|
111
|
+
kind: "added" | "modified" | "removed";
|
|
112
|
+
beforeChangeId: string | null;
|
|
113
|
+
afterChangeId: string | null;
|
|
114
|
+
};
|
package/dist/value.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { JsonValue, LixValue, SqlParam } from "./types.js";
|
|
2
|
+
export declare class Value {
|
|
3
|
+
#private;
|
|
4
|
+
readonly kind: LixValue["kind"];
|
|
5
|
+
private constructor();
|
|
6
|
+
static null(): Value;
|
|
7
|
+
static boolean(value: boolean): Value;
|
|
8
|
+
static integer(value: number): Value;
|
|
9
|
+
static real(value: number): Value;
|
|
10
|
+
static text(value: string): Value;
|
|
11
|
+
static json(value: JsonValue): Value;
|
|
12
|
+
static blob(value: Uint8Array): Value;
|
|
13
|
+
static from(value: SqlParam): Value;
|
|
14
|
+
static _fromNative(value: LixValue): Value;
|
|
15
|
+
_toNative(): NativeLixValue;
|
|
16
|
+
toJS(): unknown;
|
|
17
|
+
asBytes(): Uint8Array<ArrayBuffer> | undefined;
|
|
18
|
+
}
|
|
19
|
+
export type NativeLixValue = Exclude<LixValue, {
|
|
20
|
+
kind: "blob";
|
|
21
|
+
}> | {
|
|
22
|
+
kind: "blob";
|
|
23
|
+
value?: null;
|
|
24
|
+
blob: Uint8Array;
|
|
25
|
+
};
|
|
26
|
+
export declare function toNativeValue(value: LixValue): NativeLixValue;
|
|
27
|
+
export declare function fromNativeValue(value: NativeLixValue): LixValue;
|
|
28
|
+
export declare function normalizeParam(value: SqlParam, index?: number, seen?: WeakSet<object>): LixValue;
|