@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.
- 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 +38 -207
- 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 +38 -71
- package/SKILL.md +0 -507
- 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 -833
- package/dist/engine-wasm/wasm/lix_engine.wasm +0 -0
- package/dist/engine-wasm/wasm/lix_engine.wasm.d.ts +0 -27
- 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 -359
- package/dist-engine-src/README.md +0 -18
- package/dist-engine-src/src/backend/capabilities.rs +0 -67
- package/dist-engine-src/src/backend/conformance/baseline.rs +0 -1127
- package/dist-engine-src/src/backend/conformance/factory.rs +0 -93
- package/dist-engine-src/src/backend/conformance/failure_tests.rs +0 -608
- package/dist-engine-src/src/backend/conformance/fixtures.rs +0 -26
- package/dist-engine-src/src/backend/conformance/mod.rs +0 -75
- package/dist-engine-src/src/backend/conformance/model.rs +0 -28
- package/dist-engine-src/src/backend/conformance/model_based.rs +0 -257
- package/dist-engine-src/src/backend/conformance/persistence.rs +0 -204
- package/dist-engine-src/src/backend/conformance/projection.rs +0 -21
- package/dist-engine-src/src/backend/conformance/pushdown.rs +0 -24
- package/dist-engine-src/src/backend/conformance/runner.rs +0 -90
- package/dist-engine-src/src/backend/conformance/scan.rs +0 -24
- package/dist-engine-src/src/backend/conformance/write.rs +0 -16
- package/dist-engine-src/src/backend/error.rs +0 -94
- package/dist-engine-src/src/backend/in_memory.rs +0 -670
- package/dist-engine-src/src/backend/mod.rs +0 -39
- package/dist-engine-src/src/backend/predicate.rs +0 -80
- package/dist-engine-src/src/backend/traits.rs +0 -260
- package/dist-engine-src/src/backend/types.rs +0 -239
- 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 -1038
- 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/branch/context.rs +0 -40
- package/dist-engine-src/src/branch/lifecycle.rs +0 -221
- package/dist-engine-src/src/branch/mod.rs +0 -13
- package/dist-engine-src/src/branch/refs.rs +0 -321
- package/dist-engine-src/src/branch/stage_rows.rs +0 -67
- package/dist-engine-src/src/branch/types.rs +0 -21
- 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/changelog/bench_support.rs +0 -785
- package/dist-engine-src/src/changelog/change.rs +0 -1
- package/dist-engine-src/src/changelog/codec.rs +0 -497
- package/dist-engine-src/src/changelog/commit.rs +0 -1
- package/dist-engine-src/src/changelog/context.rs +0 -1614
- package/dist-engine-src/src/changelog/mod.rs +0 -29
- package/dist-engine-src/src/changelog/store.rs +0 -163
- package/dist-engine-src/src/changelog/test_support.rs +0 -54
- package/dist-engine-src/src/changelog/types.rs +0 -213
- package/dist-engine-src/src/commit_graph/context.rs +0 -944
- package/dist-engine-src/src/commit_graph/mod.rs +0 -9
- package/dist-engine-src/src/commit_graph/types.rs +0 -89
- package/dist-engine-src/src/commit_graph/walker.rs +0 -786
- package/dist-engine-src/src/common/error.rs +0 -347
- 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 -320
- package/dist-engine-src/src/engine.rs +0 -203
- package/dist-engine-src/src/entity_pk.rs +0 -402
- package/dist-engine-src/src/functions/context.rs +0 -296
- 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 -335
- package/dist-engine-src/src/functions/types.rs +0 -37
- package/dist-engine-src/src/init.rs +0 -692
- package/dist-engine-src/src/json_store/compression.rs +0 -77
- package/dist-engine-src/src/json_store/context.rs +0 -172
- package/dist-engine-src/src/json_store/encoded.rs +0 -15
- package/dist-engine-src/src/json_store/mod.rs +0 -38
- package/dist-engine-src/src/json_store/store.rs +0 -494
- package/dist-engine-src/src/json_store/types.rs +0 -212
- package/dist-engine-src/src/lib.rs +0 -92
- package/dist-engine-src/src/live_state/context.rs +0 -1883
- package/dist-engine-src/src/live_state/mod.rs +0 -21
- 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 -231
- package/dist-engine-src/src/live_state/visibility.rs +0 -666
- 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 -202
- package/dist-engine-src/src/plugin/mod.rs +0 -33
- package/dist-engine-src/src/plugin/plugin_manifest.json +0 -119
- 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_branch_descriptor.json +0 -34
- package/dist-engine-src/src/schema/builtin/lix_branch_ref.json +0 -48
- 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/mod.rs +0 -220
- 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 -1059
- package/dist-engine-src/src/session/create_branch.rs +0 -94
- package/dist-engine-src/src/session/execute.rs +0 -681
- package/dist-engine-src/src/session/merge/analysis.rs +0 -108
- package/dist-engine-src/src/session/merge/branch.rs +0 -417
- package/dist-engine-src/src/session/merge/conflicts.rs +0 -63
- package/dist-engine-src/src/session/merge/mod.rs +0 -10
- package/dist-engine-src/src/session/merge/stats.rs +0 -61
- package/dist-engine-src/src/session/mod.rs +0 -30
- package/dist-engine-src/src/session/switch_branch.rs +0 -113
- package/dist-engine-src/src/session/transaction.rs +0 -557
- package/dist-engine-src/src/sql2/bind/classify.rs +0 -102
- package/dist-engine-src/src/sql2/bind/error.rs +0 -5
- package/dist-engine-src/src/sql2/bind/expr.rs +0 -29
- package/dist-engine-src/src/sql2/bind/mod.rs +0 -12
- package/dist-engine-src/src/sql2/bind/public_udf.rs +0 -306
- package/dist-engine-src/src/sql2/bind/read.rs +0 -65
- package/dist-engine-src/src/sql2/bind/statement.rs +0 -2236
- package/dist-engine-src/src/sql2/bind/table.rs +0 -273
- package/dist-engine-src/src/sql2/bind/write.rs +0 -86
- package/dist-engine-src/src/sql2/branch_scope.rs +0 -436
- package/dist-engine-src/src/sql2/catalog/capability.rs +0 -20
- package/dist-engine-src/src/sql2/catalog/entity_surface.rs +0 -296
- package/dist-engine-src/src/sql2/catalog/mod.rs +0 -15
- package/dist-engine-src/src/sql2/catalog/registry.rs +0 -556
- package/dist-engine-src/src/sql2/catalog/schema.rs +0 -88
- package/dist-engine-src/src/sql2/catalog/surface.rs +0 -41
- package/dist-engine-src/src/sql2/change_materialization.rs +0 -122
- package/dist-engine-src/src/sql2/context.rs +0 -317
- package/dist-engine-src/src/sql2/dml.rs +0 -148
- package/dist-engine-src/src/sql2/error.rs +0 -215
- package/dist-engine-src/src/sql2/exec/bound_public_write.rs +0 -1593
- package/dist-engine-src/src/sql2/exec/datafusion.rs +0 -5266
- package/dist-engine-src/src/sql2/exec/fast_write.rs +0 -82
- package/dist-engine-src/src/sql2/exec/mod.rs +0 -24
- package/dist-engine-src/src/sql2/exec/write.rs +0 -661
- package/dist-engine-src/src/sql2/filesystem_planner.rs +0 -1485
- 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_route.rs +0 -661
- package/dist-engine-src/src/sql2/mod.rs +0 -52
- package/dist-engine-src/src/sql2/optimize/datafusion.rs +0 -1
- package/dist-engine-src/src/sql2/optimize/mod.rs +0 -2
- package/dist-engine-src/src/sql2/optimize/simple_write.rs +0 -116
- package/dist-engine-src/src/sql2/parse/mod.rs +0 -69
- package/dist-engine-src/src/sql2/parse/normalize.rs +0 -1
- package/dist-engine-src/src/sql2/plan/branch_scope.rs +0 -24
- package/dist-engine-src/src/sql2/plan/mod.rs +0 -5
- package/dist-engine-src/src/sql2/plan/predicate.rs +0 -22
- package/dist-engine-src/src/sql2/plan/write.rs +0 -147
- package/dist-engine-src/src/sql2/predicate_typecheck.rs +0 -504
- package/dist-engine-src/src/sql2/providers/branch.rs +0 -1206
- package/dist-engine-src/src/sql2/providers/change.rs +0 -445
- package/dist-engine-src/src/sql2/providers/directory.rs +0 -2422
- package/dist-engine-src/src/sql2/providers/directory_history.rs +0 -645
- package/dist-engine-src/src/sql2/providers/entity.rs +0 -1484
- package/dist-engine-src/src/sql2/providers/entity_history.rs +0 -452
- package/dist-engine-src/src/sql2/providers/file.rs +0 -3686
- package/dist-engine-src/src/sql2/providers/file_history.rs +0 -924
- package/dist-engine-src/src/sql2/providers/history.rs +0 -426
- package/dist-engine-src/src/sql2/providers/lix_state.rs +0 -2542
- package/dist-engine-src/src/sql2/providers/mod.rs +0 -508
- 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 -83
- package/dist-engine-src/src/sql2/storage/constraints.rs +0 -1
- package/dist-engine-src/src/sql2/storage/mod.rs +0 -1
- package/dist-engine-src/src/sql2/test_support/differential.rs +0 -712
- package/dist-engine-src/src/sql2/test_support/generators.rs +0 -354
- package/dist-engine-src/src/sql2/test_support/mod.rs +0 -2
- package/dist-engine-src/src/sql2/udfs/common.rs +0 -295
- package/dist-engine-src/src/sql2/udfs/lix_active_branch_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 -86
- package/dist-engine-src/src/sql2/write_normalization.rs +0 -368
- package/dist-engine-src/src/storage/conformance.rs +0 -399
- package/dist-engine-src/src/storage/context.rs +0 -620
- package/dist-engine-src/src/storage/mod.rs +0 -52
- package/dist-engine-src/src/storage/point.rs +0 -440
- package/dist-engine-src/src/storage/read_scope.rs +0 -67
- package/dist-engine-src/src/storage/reader.rs +0 -867
- package/dist-engine-src/src/storage/scan.rs +0 -784
- package/dist-engine-src/src/storage/spaces.rs +0 -236
- package/dist-engine-src/src/storage/stats.rs +0 -80
- package/dist-engine-src/src/storage/write_set.rs +0 -962
- package/dist-engine-src/src/storage_bench.rs +0 -171
- package/dist-engine-src/src/test_support.rs +0 -450
- package/dist-engine-src/src/tracked_state/bench_support.rs +0 -394
- package/dist-engine-src/src/tracked_state/codec.rs +0 -1183
- package/dist-engine-src/src/tracked_state/commit_root_rebuild.rs +0 -358
- package/dist-engine-src/src/tracked_state/context.rs +0 -2801
- package/dist-engine-src/src/tracked_state/diff.rs +0 -2140
- package/dist-engine-src/src/tracked_state/merge.rs +0 -478
- package/dist-engine-src/src/tracked_state/mod.rs +0 -35
- package/dist-engine-src/src/tracked_state/row_materialization.rs +0 -275
- package/dist-engine-src/src/tracked_state/storage.rs +0 -427
- package/dist-engine-src/src/tracked_state/tree.rs +0 -3063
- package/dist-engine-src/src/tracked_state/types.rs +0 -238
- package/dist-engine-src/src/transaction/bench_support.rs +0 -407
- package/dist-engine-src/src/transaction/commit.rs +0 -1592
- package/dist-engine-src/src/transaction/context.rs +0 -1653
- package/dist-engine-src/src/transaction/mod.rs +0 -24
- package/dist-engine-src/src/transaction/normalization.rs +0 -877
- package/dist-engine-src/src/transaction/prep.rs +0 -37
- package/dist-engine-src/src/transaction/schema_resolver.rs +0 -163
- package/dist-engine-src/src/transaction/staging.rs +0 -1525
- package/dist-engine-src/src/transaction/types.rs +0 -403
- package/dist-engine-src/src/transaction/validation.rs +0 -5766
- package/dist-engine-src/src/untracked_state/codec.rs +0 -615
- 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 -898
- package/dist-engine-src/src/untracked_state/types.rs +0 -146
- package/dist-engine-src/src/wasm/mod.rs +0 -60
|
@@ -1,516 +0,0 @@
|
|
|
1
|
-
use std::sync::OnceLock;
|
|
2
|
-
|
|
3
|
-
use globset::{Glob, GlobBuilder};
|
|
4
|
-
use jsonschema::{Draft, JSONSchema};
|
|
5
|
-
use serde::{Deserialize, Serialize};
|
|
6
|
-
use serde_json::Value as JsonValue;
|
|
7
|
-
|
|
8
|
-
use crate::LixError;
|
|
9
|
-
|
|
10
|
-
static PLUGIN_MANIFEST_SCHEMA: OnceLock<JsonValue> = OnceLock::new();
|
|
11
|
-
static PLUGIN_MANIFEST_VALIDATOR: OnceLock<Result<JSONSchema, LixError>> = OnceLock::new();
|
|
12
|
-
|
|
13
|
-
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
|
14
|
-
#[serde(rename_all = "kebab-case")]
|
|
15
|
-
pub enum PluginRuntime {
|
|
16
|
-
WasmComponentV1,
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
#[allow(dead_code)]
|
|
20
|
-
impl PluginRuntime {
|
|
21
|
-
pub fn as_str(self) -> &'static str {
|
|
22
|
-
match self {
|
|
23
|
-
Self::WasmComponentV1 => "wasm-component-v1",
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
pub fn from_str(value: &str) -> Option<Self> {
|
|
28
|
-
match value {
|
|
29
|
-
"wasm-component-v1" => Some(Self::WasmComponentV1),
|
|
30
|
-
_ => None,
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
|
36
|
-
pub struct PluginManifest {
|
|
37
|
-
pub key: String,
|
|
38
|
-
pub runtime: PluginRuntime,
|
|
39
|
-
pub api_version: String,
|
|
40
|
-
#[serde(rename = "match")]
|
|
41
|
-
pub file_match: PluginMatch,
|
|
42
|
-
#[serde(default)]
|
|
43
|
-
pub detect_changes: Option<DetectChangesConfig>,
|
|
44
|
-
pub entry: String,
|
|
45
|
-
pub schemas: Vec<String>,
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
|
49
|
-
pub struct PluginMatch {
|
|
50
|
-
pub path_glob: String,
|
|
51
|
-
#[serde(default)]
|
|
52
|
-
pub content_type: Option<PluginContentType>,
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
|
56
|
-
#[serde(rename_all = "snake_case")]
|
|
57
|
-
pub enum PluginContentType {
|
|
58
|
-
Text,
|
|
59
|
-
Binary,
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
63
|
-
pub struct ValidatedPluginManifest {
|
|
64
|
-
pub manifest: PluginManifest,
|
|
65
|
-
pub normalized_json: String,
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
|
69
|
-
pub struct DetectChangesConfig {
|
|
70
|
-
#[serde(default)]
|
|
71
|
-
pub state_context: Option<DetectStateContextConfig>,
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
|
75
|
-
pub struct DetectStateContextConfig {
|
|
76
|
-
#[serde(default)]
|
|
77
|
-
pub include_active_state: Option<bool>,
|
|
78
|
-
#[serde(default)]
|
|
79
|
-
pub columns: Option<Vec<StateContextColumn>>,
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
#[allow(dead_code)]
|
|
83
|
-
impl DetectStateContextConfig {
|
|
84
|
-
pub fn includes_active_state(&self) -> bool {
|
|
85
|
-
self.include_active_state.unwrap_or(false)
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
pub fn resolved_columns_or_default(&self) -> Option<Vec<StateContextColumn>> {
|
|
89
|
-
if !self.includes_active_state() {
|
|
90
|
-
return None;
|
|
91
|
-
}
|
|
92
|
-
Some(
|
|
93
|
-
self.columns
|
|
94
|
-
.clone()
|
|
95
|
-
.unwrap_or_else(|| StateContextColumn::default_active_state_columns().to_vec()),
|
|
96
|
-
)
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
|
101
|
-
#[serde(rename_all = "snake_case")]
|
|
102
|
-
pub enum StateContextColumn {
|
|
103
|
-
EntityPk,
|
|
104
|
-
SchemaKey,
|
|
105
|
-
SchemaVersion,
|
|
106
|
-
SnapshotContent,
|
|
107
|
-
FileId,
|
|
108
|
-
PluginKey,
|
|
109
|
-
BranchId,
|
|
110
|
-
ChangeId,
|
|
111
|
-
Metadata,
|
|
112
|
-
CreatedAt,
|
|
113
|
-
UpdatedAt,
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
#[allow(dead_code)]
|
|
117
|
-
impl StateContextColumn {
|
|
118
|
-
pub const fn default_active_state_columns() -> &'static [StateContextColumn] {
|
|
119
|
-
&[
|
|
120
|
-
StateContextColumn::EntityPk,
|
|
121
|
-
StateContextColumn::SchemaKey,
|
|
122
|
-
StateContextColumn::SchemaVersion,
|
|
123
|
-
StateContextColumn::SnapshotContent,
|
|
124
|
-
]
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
pub fn parse_plugin_manifest_json(raw: &str) -> Result<ValidatedPluginManifest, LixError> {
|
|
129
|
-
let manifest_json: JsonValue = serde_json::from_str(raw).map_err(|error| LixError {
|
|
130
|
-
code: "LIX_ERROR_UNKNOWN".to_string(),
|
|
131
|
-
message: format!("Plugin manifest must be valid JSON: {error}"),
|
|
132
|
-
hint: None,
|
|
133
|
-
details: None,
|
|
134
|
-
})?;
|
|
135
|
-
|
|
136
|
-
validate_plugin_manifest_json(&manifest_json)?;
|
|
137
|
-
|
|
138
|
-
let manifest: PluginManifest =
|
|
139
|
-
serde_json::from_value(manifest_json.clone()).map_err(|error| LixError {
|
|
140
|
-
code: "LIX_ERROR_UNKNOWN".to_string(),
|
|
141
|
-
message: format!("Plugin manifest does not match expected shape: {error}"),
|
|
142
|
-
hint: None,
|
|
143
|
-
details: None,
|
|
144
|
-
})?;
|
|
145
|
-
validate_path_glob(&manifest.file_match.path_glob)?;
|
|
146
|
-
|
|
147
|
-
let normalized_json = serde_json::to_string(&manifest_json).map_err(|error| LixError {
|
|
148
|
-
code: "LIX_ERROR_UNKNOWN".to_string(),
|
|
149
|
-
message: format!("Failed to normalize plugin manifest JSON: {error}"),
|
|
150
|
-
hint: None,
|
|
151
|
-
details: None,
|
|
152
|
-
})?;
|
|
153
|
-
|
|
154
|
-
Ok(ValidatedPluginManifest {
|
|
155
|
-
manifest,
|
|
156
|
-
normalized_json,
|
|
157
|
-
})
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
pub fn select_best_glob_match<'a, T, C: Copy + PartialEq>(
|
|
161
|
-
path: &str,
|
|
162
|
-
file_content_type: Option<C>,
|
|
163
|
-
candidates: &'a [T],
|
|
164
|
-
glob: impl Fn(&T) -> &str,
|
|
165
|
-
required_content_type: impl Fn(&T) -> Option<C>,
|
|
166
|
-
) -> Option<&'a T> {
|
|
167
|
-
let mut selected: Option<&T> = None;
|
|
168
|
-
let mut selected_rank: Option<(u8, i32)> = None;
|
|
169
|
-
|
|
170
|
-
for candidate in candidates {
|
|
171
|
-
let pattern = glob(candidate);
|
|
172
|
-
if !glob_matches_path(pattern, path) {
|
|
173
|
-
continue;
|
|
174
|
-
}
|
|
175
|
-
if let (Some(actual_type), Some(required_type)) =
|
|
176
|
-
(file_content_type, required_content_type(candidate))
|
|
177
|
-
{
|
|
178
|
-
if actual_type != required_type {
|
|
179
|
-
continue;
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
let rank = glob_specificity_rank(pattern);
|
|
184
|
-
match selected_rank {
|
|
185
|
-
None => {
|
|
186
|
-
selected = Some(candidate);
|
|
187
|
-
selected_rank = Some(rank);
|
|
188
|
-
}
|
|
189
|
-
Some(existing_rank) if rank > existing_rank => {
|
|
190
|
-
selected = Some(candidate);
|
|
191
|
-
selected_rank = Some(rank);
|
|
192
|
-
}
|
|
193
|
-
_ => {}
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
selected
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
pub fn glob_matches_path(glob: &str, path: &str) -> bool {
|
|
201
|
-
let normalized_glob = glob.trim();
|
|
202
|
-
let normalized_path = path.trim();
|
|
203
|
-
if normalized_glob.is_empty() || normalized_path.is_empty() {
|
|
204
|
-
return false;
|
|
205
|
-
}
|
|
206
|
-
if is_catch_all_glob(normalized_glob) {
|
|
207
|
-
return true;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
GlobBuilder::new(normalized_glob)
|
|
211
|
-
.literal_separator(false)
|
|
212
|
-
.case_insensitive(true)
|
|
213
|
-
.build()
|
|
214
|
-
.map(|compiled| compiled.compile_matcher().is_match(normalized_path))
|
|
215
|
-
.unwrap_or(false)
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
fn validate_path_glob(glob: &str) -> Result<(), LixError> {
|
|
219
|
-
Glob::new(glob).map_err(|error| LixError {
|
|
220
|
-
code: "LIX_ERROR_UNKNOWN".to_string(),
|
|
221
|
-
message: format!("Invalid plugin manifest: match.path_glob is invalid: {error}"),
|
|
222
|
-
hint: None,
|
|
223
|
-
details: None,
|
|
224
|
-
})?;
|
|
225
|
-
Ok(())
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
fn validate_plugin_manifest_json(manifest: &JsonValue) -> Result<(), LixError> {
|
|
229
|
-
let validator = plugin_manifest_validator()?;
|
|
230
|
-
if let Err(errors) = validator.validate(manifest) {
|
|
231
|
-
let details = format_validation_errors(errors);
|
|
232
|
-
return Err(LixError {
|
|
233
|
-
code: "LIX_ERROR_UNKNOWN".to_string(),
|
|
234
|
-
message: format!("Invalid plugin manifest: {details}"),
|
|
235
|
-
hint: None,
|
|
236
|
-
details: None,
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
Ok(())
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
fn glob_specificity_rank(glob: &str) -> (u8, i32) {
|
|
243
|
-
let normalized = glob.trim();
|
|
244
|
-
if is_catch_all_glob(normalized) {
|
|
245
|
-
return (0, i32::MIN);
|
|
246
|
-
}
|
|
247
|
-
(1, glob_specificity_score(normalized))
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
fn glob_specificity_score(glob: &str) -> i32 {
|
|
251
|
-
let mut literal_chars = 0i32;
|
|
252
|
-
let mut wildcard_chars = 0i32;
|
|
253
|
-
for ch in glob.chars() {
|
|
254
|
-
match ch {
|
|
255
|
-
'*' | '?' | '[' | ']' | '{' | '}' => wildcard_chars += 1,
|
|
256
|
-
_ => literal_chars += 1,
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
literal_chars - wildcard_chars
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
fn is_catch_all_glob(glob: &str) -> bool {
|
|
263
|
-
glob == "*" || glob == "**/*" || glob == "**"
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
fn plugin_manifest_validator() -> Result<&'static JSONSchema, LixError> {
|
|
267
|
-
let result = PLUGIN_MANIFEST_VALIDATOR.get_or_init(|| {
|
|
268
|
-
let mut options = JSONSchema::options();
|
|
269
|
-
options.with_meta_schemas();
|
|
270
|
-
if plugin_manifest_schema()
|
|
271
|
-
.get("$schema")
|
|
272
|
-
.and_then(JsonValue::as_str)
|
|
273
|
-
.is_some_and(|url| url == "https://json-schema.org/draft/2020-12/schema")
|
|
274
|
-
{
|
|
275
|
-
options.with_draft(Draft::Draft202012);
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
options
|
|
279
|
-
.compile(plugin_manifest_schema())
|
|
280
|
-
.map_err(|error| LixError {
|
|
281
|
-
code: "LIX_ERROR_UNKNOWN".to_string(),
|
|
282
|
-
message: format!("Failed to compile plugin manifest schema: {error}"),
|
|
283
|
-
hint: None,
|
|
284
|
-
details: None,
|
|
285
|
-
})
|
|
286
|
-
});
|
|
287
|
-
|
|
288
|
-
match result {
|
|
289
|
-
Ok(schema) => Ok(schema),
|
|
290
|
-
Err(error) => Err(LixError {
|
|
291
|
-
code: "LIX_ERROR_UNKNOWN".to_string(),
|
|
292
|
-
message: error.message.clone(),
|
|
293
|
-
hint: None,
|
|
294
|
-
details: None,
|
|
295
|
-
}),
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
fn plugin_manifest_schema() -> &'static JsonValue {
|
|
300
|
-
PLUGIN_MANIFEST_SCHEMA.get_or_init(|| {
|
|
301
|
-
let raw = include_str!("./plugin_manifest.schema.json");
|
|
302
|
-
serde_json::from_str(raw).expect("plugin_manifest.schema.json must be valid JSON")
|
|
303
|
-
})
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
fn format_validation_errors<'a>(
|
|
307
|
-
errors: impl Iterator<Item = jsonschema::ValidationError<'a>>,
|
|
308
|
-
) -> String {
|
|
309
|
-
let mut parts = Vec::new();
|
|
310
|
-
for error in errors {
|
|
311
|
-
let path = error.instance_path.to_string();
|
|
312
|
-
let message = error.to_string();
|
|
313
|
-
if path.is_empty() {
|
|
314
|
-
parts.push(message);
|
|
315
|
-
} else {
|
|
316
|
-
parts.push(format!("{path} {message}"));
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
if parts.is_empty() {
|
|
320
|
-
"Unknown validation error".to_string()
|
|
321
|
-
} else {
|
|
322
|
-
parts.join("; ")
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
#[cfg(test)]
|
|
327
|
-
mod tests {
|
|
328
|
-
use super::{
|
|
329
|
-
parse_plugin_manifest_json, DetectStateContextConfig, PluginContentType, StateContextColumn,
|
|
330
|
-
};
|
|
331
|
-
|
|
332
|
-
#[test]
|
|
333
|
-
fn resolved_columns_returns_none_when_active_state_is_not_enabled() {
|
|
334
|
-
let config = DetectStateContextConfig {
|
|
335
|
-
include_active_state: None,
|
|
336
|
-
columns: None,
|
|
337
|
-
};
|
|
338
|
-
|
|
339
|
-
assert_eq!(config.resolved_columns_or_default(), None);
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
#[test]
|
|
343
|
-
fn resolved_columns_uses_defaults_when_columns_are_omitted() {
|
|
344
|
-
let config = DetectStateContextConfig {
|
|
345
|
-
include_active_state: Some(true),
|
|
346
|
-
columns: None,
|
|
347
|
-
};
|
|
348
|
-
|
|
349
|
-
assert_eq!(
|
|
350
|
-
config.resolved_columns_or_default(),
|
|
351
|
-
Some(StateContextColumn::default_active_state_columns().to_vec())
|
|
352
|
-
);
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
#[test]
|
|
356
|
-
fn resolved_columns_uses_explicit_column_selection() {
|
|
357
|
-
let config = DetectStateContextConfig {
|
|
358
|
-
include_active_state: Some(true),
|
|
359
|
-
columns: Some(vec![
|
|
360
|
-
StateContextColumn::EntityPk,
|
|
361
|
-
StateContextColumn::SchemaKey,
|
|
362
|
-
]),
|
|
363
|
-
};
|
|
364
|
-
|
|
365
|
-
assert_eq!(
|
|
366
|
-
config.resolved_columns_or_default(),
|
|
367
|
-
Some(vec![
|
|
368
|
-
StateContextColumn::EntityPk,
|
|
369
|
-
StateContextColumn::SchemaKey
|
|
370
|
-
])
|
|
371
|
-
);
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
#[test]
|
|
375
|
-
fn parses_valid_manifest() {
|
|
376
|
-
let validated = parse_plugin_manifest_json(
|
|
377
|
-
r#"{
|
|
378
|
-
"key":"plugin_json",
|
|
379
|
-
"runtime":"wasm-component-v1",
|
|
380
|
-
"api_version":"0.1.0",
|
|
381
|
-
"match":{"path_glob":"*.json"},
|
|
382
|
-
"entry":"plugin.wasm",
|
|
383
|
-
"schemas":["schema/default.json"]
|
|
384
|
-
}"#,
|
|
385
|
-
)
|
|
386
|
-
.expect("manifest should parse");
|
|
387
|
-
|
|
388
|
-
assert_eq!(validated.manifest.key, "plugin_json");
|
|
389
|
-
assert_eq!(validated.manifest.runtime.as_str(), "wasm-component-v1");
|
|
390
|
-
assert_eq!(validated.manifest.entry, "plugin.wasm");
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
#[test]
|
|
394
|
-
fn rejects_invalid_manifest() {
|
|
395
|
-
let err = parse_plugin_manifest_json(
|
|
396
|
-
r#"{
|
|
397
|
-
"runtime":"wasm-component-v1",
|
|
398
|
-
"api_version":"0.1.0",
|
|
399
|
-
"match":{"path_glob":"*.json"},
|
|
400
|
-
"entry":"plugin.wasm",
|
|
401
|
-
"schemas":["schema/default.json"]
|
|
402
|
-
}"#,
|
|
403
|
-
)
|
|
404
|
-
.expect_err("manifest should be invalid");
|
|
405
|
-
|
|
406
|
-
assert!(err.message.contains("Invalid plugin manifest"));
|
|
407
|
-
assert!(err.message.contains("key"));
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
#[test]
|
|
411
|
-
fn rejects_invalid_path_glob() {
|
|
412
|
-
let err = parse_plugin_manifest_json(
|
|
413
|
-
r#"{
|
|
414
|
-
"key":"plugin_markdown",
|
|
415
|
-
"runtime":"wasm-component-v1",
|
|
416
|
-
"api_version":"0.1.0",
|
|
417
|
-
"match":{"path_glob":"*.{md,mdx"},
|
|
418
|
-
"entry":"plugin.wasm",
|
|
419
|
-
"schemas":["schema/default.json"]
|
|
420
|
-
}"#,
|
|
421
|
-
)
|
|
422
|
-
.expect_err("invalid glob should fail");
|
|
423
|
-
|
|
424
|
-
assert!(err.message.contains("match.path_glob"));
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
#[test]
|
|
428
|
-
fn parses_manifest_with_content_type_match_filter() {
|
|
429
|
-
let validated = parse_plugin_manifest_json(
|
|
430
|
-
r#"{
|
|
431
|
-
"key":"plugin_text",
|
|
432
|
-
"runtime":"wasm-component-v1",
|
|
433
|
-
"api_version":"0.1.0",
|
|
434
|
-
"match":{"path_glob":"**/*", "content_type":"text"},
|
|
435
|
-
"entry":"plugin.wasm",
|
|
436
|
-
"schemas":["schema/default.json"]
|
|
437
|
-
}"#,
|
|
438
|
-
)
|
|
439
|
-
.expect("manifest should parse");
|
|
440
|
-
|
|
441
|
-
assert_eq!(
|
|
442
|
-
validated.manifest.file_match.content_type,
|
|
443
|
-
Some(PluginContentType::Text)
|
|
444
|
-
);
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
#[test]
|
|
448
|
-
fn parses_manifest_with_active_state_columns() {
|
|
449
|
-
let validated = parse_plugin_manifest_json(
|
|
450
|
-
r#"{
|
|
451
|
-
"key":"plugin_markdown",
|
|
452
|
-
"runtime":"wasm-component-v1",
|
|
453
|
-
"api_version":"0.1.0",
|
|
454
|
-
"match":{"path_glob":"*.{md,mdx}"},
|
|
455
|
-
"entry":"plugin.wasm",
|
|
456
|
-
"schemas":["schema/default.json"],
|
|
457
|
-
"detect_changes": {
|
|
458
|
-
"state_context": {
|
|
459
|
-
"include_active_state": true,
|
|
460
|
-
"columns": ["entity_pk", "schema_key", "snapshot_content"]
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
}"#,
|
|
464
|
-
)
|
|
465
|
-
.expect("manifest should parse");
|
|
466
|
-
|
|
467
|
-
let state_context = validated
|
|
468
|
-
.manifest
|
|
469
|
-
.detect_changes
|
|
470
|
-
.expect("detect_changes should be present")
|
|
471
|
-
.state_context
|
|
472
|
-
.expect("state_context should be present");
|
|
473
|
-
|
|
474
|
-
assert_eq!(state_context.include_active_state, Some(true));
|
|
475
|
-
assert_eq!(
|
|
476
|
-
state_context.columns,
|
|
477
|
-
Some(vec![
|
|
478
|
-
StateContextColumn::EntityPk,
|
|
479
|
-
StateContextColumn::SchemaKey,
|
|
480
|
-
StateContextColumn::SnapshotContent
|
|
481
|
-
])
|
|
482
|
-
);
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
#[test]
|
|
486
|
-
fn parses_manifest_with_active_state_and_default_columns() {
|
|
487
|
-
let validated = parse_plugin_manifest_json(
|
|
488
|
-
r#"{
|
|
489
|
-
"key":"plugin_markdown",
|
|
490
|
-
"runtime":"wasm-component-v1",
|
|
491
|
-
"api_version":"0.1.0",
|
|
492
|
-
"match":{"path_glob":"*.md"},
|
|
493
|
-
"entry":"plugin.wasm",
|
|
494
|
-
"schemas":["schema/default.json"],
|
|
495
|
-
"detect_changes": {
|
|
496
|
-
"state_context": {
|
|
497
|
-
"include_active_state": true
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
}"#,
|
|
501
|
-
)
|
|
502
|
-
.expect("manifest should parse");
|
|
503
|
-
|
|
504
|
-
let state_context = validated
|
|
505
|
-
.manifest
|
|
506
|
-
.detect_changes
|
|
507
|
-
.expect("detect_changes should be present")
|
|
508
|
-
.state_context
|
|
509
|
-
.expect("state_context should be present");
|
|
510
|
-
|
|
511
|
-
assert_eq!(
|
|
512
|
-
state_context.resolved_columns_or_default(),
|
|
513
|
-
Some(StateContextColumn::default_active_state_columns().to_vec())
|
|
514
|
-
);
|
|
515
|
-
}
|
|
516
|
-
}
|
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
use std::collections::BTreeSet;
|
|
2
|
-
use std::sync::{Arc, RwLock};
|
|
3
|
-
|
|
4
|
-
use async_trait::async_trait;
|
|
5
|
-
|
|
6
|
-
use crate::common::LixError;
|
|
7
|
-
use crate::live_state::{list_installed_plugin_archive_refs, PluginArchiveRef};
|
|
8
|
-
use crate::Backend;
|
|
9
|
-
|
|
10
|
-
use super::component::{apply_changes_with_plugin, PluginComponentHost};
|
|
11
|
-
use super::{
|
|
12
|
-
load_installed_plugin_from_archive_bytes, plugin_key_from_archive_path, PluginContentType,
|
|
13
|
-
PluginRuntime,
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
17
|
-
pub struct InstalledPlugin {
|
|
18
|
-
pub key: String,
|
|
19
|
-
pub runtime: PluginRuntime,
|
|
20
|
-
pub api_version: String,
|
|
21
|
-
pub path_glob: String,
|
|
22
|
-
pub content_type: Option<PluginContentType>,
|
|
23
|
-
pub entry: String,
|
|
24
|
-
pub manifest_json: String,
|
|
25
|
-
pub wasm: Vec<u8>,
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
#[async_trait(?Send)]
|
|
29
|
-
pub trait FilesystemPluginMaterializer {
|
|
30
|
-
async fn load_installed_plugins(&self) -> Result<Vec<InstalledPlugin>, LixError>;
|
|
31
|
-
|
|
32
|
-
async fn apply_plugin_changes(
|
|
33
|
-
&self,
|
|
34
|
-
plugin: &InstalledPlugin,
|
|
35
|
-
payload: &[u8],
|
|
36
|
-
) -> Result<Vec<u8>, LixError>;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
pub(crate) trait PluginMaterializationHost: PluginComponentHost {
|
|
40
|
-
fn plugin_backend(&self) -> &Arc<dyn Backend + Send + Sync>;
|
|
41
|
-
|
|
42
|
-
fn installed_plugins_cache(&self) -> &RwLock<Option<Vec<InstalledPlugin>>>;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
pub(crate) async fn load_installed_plugins_with_runtime_cache(
|
|
46
|
-
host: &impl PluginMaterializationHost,
|
|
47
|
-
) -> Result<Vec<InstalledPlugin>, LixError> {
|
|
48
|
-
if let Some(cached) = host
|
|
49
|
-
.installed_plugins_cache()
|
|
50
|
-
.read()
|
|
51
|
-
.map_err(|_| LixError {
|
|
52
|
-
code: "LIX_ERROR_UNKNOWN".to_string(),
|
|
53
|
-
message: "installed plugin cache lock poisoned".to_string(),
|
|
54
|
-
hint: None,
|
|
55
|
-
details: None,
|
|
56
|
-
})?
|
|
57
|
-
.clone()
|
|
58
|
-
{
|
|
59
|
-
return Ok(cached);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
let plugins = load_installed_plugins_from_backend(host).await?;
|
|
63
|
-
let mut guard = host
|
|
64
|
-
.installed_plugins_cache()
|
|
65
|
-
.write()
|
|
66
|
-
.map_err(|_| LixError {
|
|
67
|
-
code: "LIX_ERROR_UNKNOWN".to_string(),
|
|
68
|
-
message: "installed plugin cache lock poisoned".to_string(),
|
|
69
|
-
hint: None,
|
|
70
|
-
details: None,
|
|
71
|
-
})?;
|
|
72
|
-
*guard = Some(plugins.clone());
|
|
73
|
-
Ok(plugins)
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
pub(crate) async fn load_installed_plugins_from_backend(
|
|
77
|
-
host: &impl PluginMaterializationHost,
|
|
78
|
-
) -> Result<Vec<InstalledPlugin>, LixError> {
|
|
79
|
-
load_installed_plugins_from_backend_state(host.plugin_backend().as_ref()).await
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
pub(crate) async fn load_installed_plugins_from_backend_state(
|
|
83
|
-
backend: &dyn Backend,
|
|
84
|
-
) -> Result<Vec<InstalledPlugin>, LixError> {
|
|
85
|
-
let archive_refs = list_installed_plugin_archive_refs(backend).await?;
|
|
86
|
-
let mut plugins = Vec::with_capacity(archive_refs.len());
|
|
87
|
-
for archive_ref in archive_refs {
|
|
88
|
-
plugins.push(
|
|
89
|
-
load_installed_plugin_from_archive_ref_with_backend(backend, &archive_ref).await?,
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
Ok(plugins)
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
pub(crate) async fn load_installed_plugin_from_archive_ref_with_backend(
|
|
96
|
-
backend: &dyn Backend,
|
|
97
|
-
archive_ref: &PluginArchiveRef,
|
|
98
|
-
) -> Result<InstalledPlugin, LixError> {
|
|
99
|
-
let Some(plugin_key) = plugin_key_from_archive_path(&archive_ref.path) else {
|
|
100
|
-
return Err(LixError {
|
|
101
|
-
code: "LIX_ERROR_UNKNOWN".to_string(),
|
|
102
|
-
message: format!(
|
|
103
|
-
"plugin materialization: unsupported plugin archive path '{}'",
|
|
104
|
-
archive_ref.path
|
|
105
|
-
),
|
|
106
|
-
hint: None,
|
|
107
|
-
details: None,
|
|
108
|
-
});
|
|
109
|
-
};
|
|
110
|
-
let binary_cas = crate::binary_cas::BinaryCasContext::new();
|
|
111
|
-
let mut reader = binary_cas.reader(backend);
|
|
112
|
-
let archive_hash = crate::binary_cas::BlobHash::from_hex(&archive_ref.blob_hash)?;
|
|
113
|
-
let archive_bytes = reader
|
|
114
|
-
.load_bytes_many(&[archive_hash])
|
|
115
|
-
.await?
|
|
116
|
-
.into_vec()
|
|
117
|
-
.into_iter()
|
|
118
|
-
.next()
|
|
119
|
-
.flatten()
|
|
120
|
-
.ok_or_else(|| LixError {
|
|
121
|
-
code: "LIX_ERROR_UNKNOWN".to_string(),
|
|
122
|
-
message: format!(
|
|
123
|
-
"plugin materialization: missing plugin archive blob '{}' for file '{}' ({})",
|
|
124
|
-
archive_ref.blob_hash, archive_ref.path, archive_ref.file_id
|
|
125
|
-
),
|
|
126
|
-
hint: None,
|
|
127
|
-
details: None,
|
|
128
|
-
})?;
|
|
129
|
-
if archive_bytes.is_empty() {
|
|
130
|
-
return Err(LixError {
|
|
131
|
-
code: "LIX_ERROR_UNKNOWN".to_string(),
|
|
132
|
-
message: format!(
|
|
133
|
-
"plugin materialization: archive '{}' is empty",
|
|
134
|
-
archive_ref.path
|
|
135
|
-
),
|
|
136
|
-
hint: None,
|
|
137
|
-
details: None,
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
load_installed_plugin_from_archive_bytes(&plugin_key, &archive_ref.path, &archive_bytes)
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
pub(crate) async fn list_installed_plugin_manifest_keys(
|
|
144
|
-
backend: &dyn Backend,
|
|
145
|
-
) -> Result<BTreeSet<String>, LixError> {
|
|
146
|
-
Ok(load_installed_plugins_from_backend_state(backend)
|
|
147
|
-
.await?
|
|
148
|
-
.into_iter()
|
|
149
|
-
.map(|plugin| plugin.key)
|
|
150
|
-
.collect())
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
#[allow(dead_code)]
|
|
154
|
-
pub(crate) async fn installed_plugin_manifest_key_exists(
|
|
155
|
-
backend: &dyn Backend,
|
|
156
|
-
plugin_key: &str,
|
|
157
|
-
) -> Result<bool, LixError> {
|
|
158
|
-
Ok(list_installed_plugin_manifest_keys(backend)
|
|
159
|
-
.await?
|
|
160
|
-
.contains(plugin_key))
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
pub(crate) fn invalidate_installed_plugins_cache(
|
|
164
|
-
host: &impl PluginMaterializationHost,
|
|
165
|
-
) -> Result<(), LixError> {
|
|
166
|
-
let mut guard = host
|
|
167
|
-
.installed_plugins_cache()
|
|
168
|
-
.write()
|
|
169
|
-
.map_err(|_| LixError {
|
|
170
|
-
code: "LIX_ERROR_UNKNOWN".to_string(),
|
|
171
|
-
message: "installed plugin cache lock poisoned".to_string(),
|
|
172
|
-
hint: None,
|
|
173
|
-
details: None,
|
|
174
|
-
})?;
|
|
175
|
-
*guard = None;
|
|
176
|
-
let mut component_guard = host.plugin_component_cache().lock().map_err(|_| LixError {
|
|
177
|
-
code: "LIX_ERROR_UNKNOWN".to_string(),
|
|
178
|
-
message: "plugin component cache lock poisoned".to_string(),
|
|
179
|
-
hint: None,
|
|
180
|
-
details: None,
|
|
181
|
-
})?;
|
|
182
|
-
component_guard.clear();
|
|
183
|
-
Ok(())
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
#[async_trait(?Send)]
|
|
187
|
-
impl<T> FilesystemPluginMaterializer for T
|
|
188
|
-
where
|
|
189
|
-
T: PluginMaterializationHost,
|
|
190
|
-
{
|
|
191
|
-
async fn load_installed_plugins(&self) -> Result<Vec<InstalledPlugin>, LixError> {
|
|
192
|
-
load_installed_plugins_with_runtime_cache(self).await
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
async fn apply_plugin_changes(
|
|
196
|
-
&self,
|
|
197
|
-
plugin: &InstalledPlugin,
|
|
198
|
-
payload: &[u8],
|
|
199
|
-
) -> Result<Vec<u8>, LixError> {
|
|
200
|
-
apply_changes_with_plugin(self, plugin, payload).await
|
|
201
|
-
}
|
|
202
|
-
}
|