@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
|
@@ -1,477 +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
|
-
}
|
|
203
|
-
|
|
204
|
-
#[cfg(test)]
|
|
205
|
-
mod tests {
|
|
206
|
-
use super::*;
|
|
207
|
-
use crate::binary_cas::codec::{
|
|
208
|
-
binary_blob_hash_bytes, encode_binary_cas_chunk, encode_binary_cas_manifest,
|
|
209
|
-
encode_binary_cas_manifest_chunk, BinaryCasManifest, BinaryChunkCodec,
|
|
210
|
-
};
|
|
211
|
-
use crate::binary_cas::kv::{
|
|
212
|
-
BINARY_CAS_CHUNK_NAMESPACE, BINARY_CAS_MANIFEST_CHUNK_NAMESPACE,
|
|
213
|
-
BINARY_CAS_MANIFEST_NAMESPACE,
|
|
214
|
-
};
|
|
215
|
-
use crate::{
|
|
216
|
-
BackendKvEntryPage, BackendKvExistsBatch, BackendKvExistsGroup,
|
|
217
|
-
BackendKvGetRequest, BackendKvKeyPage, BackendKvScanRange, BackendKvScanRequest,
|
|
218
|
-
BackendKvValueBatch, BackendKvValueGroup, BackendKvValuePage, BackendKvWriteBatch,
|
|
219
|
-
BackendKvWriteStats, BackendReadTransaction, BackendWriteTransaction, BytePageBuilder,
|
|
220
|
-
};
|
|
221
|
-
use async_trait::async_trait;
|
|
222
|
-
use std::io::{Cursor, Write};
|
|
223
|
-
use zip::write::SimpleFileOptions;
|
|
224
|
-
use zip::{CompressionMethod, ZipWriter};
|
|
225
|
-
|
|
226
|
-
struct InstalledPluginLookupBackend {
|
|
227
|
-
archive_bytes: Vec<u8>,
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
struct PluginLookupTransaction {
|
|
231
|
-
archive_bytes: Vec<u8>,
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
#[async_trait]
|
|
235
|
-
impl Backend for InstalledPluginLookupBackend {
|
|
236
|
-
async fn begin_read_transaction(
|
|
237
|
-
&self,
|
|
238
|
-
) -> Result<Box<dyn BackendReadTransaction + Send + Sync + 'static>, LixError> {
|
|
239
|
-
Ok(Box::new(PluginLookupTransaction {
|
|
240
|
-
archive_bytes: self.archive_bytes.clone(),
|
|
241
|
-
}))
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
async fn begin_write_transaction(
|
|
245
|
-
&self,
|
|
246
|
-
) -> Result<Box<dyn BackendWriteTransaction + Send + Sync + 'static>, LixError> {
|
|
247
|
-
Ok(Box::new(PluginLookupTransaction {
|
|
248
|
-
archive_bytes: self.archive_bytes.clone(),
|
|
249
|
-
}))
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
#[async_trait]
|
|
254
|
-
impl BackendReadTransaction for PluginLookupTransaction {
|
|
255
|
-
async fn get_values(
|
|
256
|
-
&mut self,
|
|
257
|
-
request: BackendKvGetRequest,
|
|
258
|
-
) -> Result<BackendKvValueBatch, LixError> {
|
|
259
|
-
let mut groups = Vec::with_capacity(request.groups.len());
|
|
260
|
-
for group in request.groups {
|
|
261
|
-
let namespace = group.namespace.clone();
|
|
262
|
-
let mut values = BytePageBuilder::with_capacity(group.keys.len(), 0);
|
|
263
|
-
let mut present = Vec::with_capacity(group.keys.len());
|
|
264
|
-
for key in group.keys {
|
|
265
|
-
if let Some(value) = test_kv_get(&self.archive_bytes, &group.namespace, &key)? {
|
|
266
|
-
values.push(value);
|
|
267
|
-
present.push(true);
|
|
268
|
-
} else {
|
|
269
|
-
values.push([]);
|
|
270
|
-
present.push(false);
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
groups.push(BackendKvValueGroup::new(namespace, values.finish(), present));
|
|
274
|
-
}
|
|
275
|
-
Ok(BackendKvValueBatch { groups })
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
async fn exists_many(
|
|
279
|
-
&mut self,
|
|
280
|
-
request: BackendKvGetRequest,
|
|
281
|
-
) -> Result<BackendKvExistsBatch, LixError> {
|
|
282
|
-
let mut groups = Vec::with_capacity(request.groups.len());
|
|
283
|
-
for group in request.groups {
|
|
284
|
-
let namespace = group.namespace.clone();
|
|
285
|
-
let exists = group
|
|
286
|
-
.keys
|
|
287
|
-
.iter()
|
|
288
|
-
.map(|key| test_kv_get(&self.archive_bytes, &group.namespace, key))
|
|
289
|
-
.collect::<Result<Vec<_>, LixError>>()?
|
|
290
|
-
.into_iter()
|
|
291
|
-
.map(|value| value.is_some())
|
|
292
|
-
.collect();
|
|
293
|
-
groups.push(BackendKvExistsGroup {
|
|
294
|
-
namespace,
|
|
295
|
-
exists,
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
|
-
Ok(BackendKvExistsBatch { groups })
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
async fn scan_keys(
|
|
302
|
-
&mut self,
|
|
303
|
-
request: BackendKvScanRequest,
|
|
304
|
-
) -> Result<BackendKvKeyPage, LixError> {
|
|
305
|
-
let entries = test_kv_scan(&self.archive_bytes, request)?;
|
|
306
|
-
Ok(BackendKvKeyPage {
|
|
307
|
-
keys: entries.keys,
|
|
308
|
-
resume_after: entries.resume_after,
|
|
309
|
-
})
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
async fn scan_values(
|
|
313
|
-
&mut self,
|
|
314
|
-
request: BackendKvScanRequest,
|
|
315
|
-
) -> Result<BackendKvValuePage, LixError> {
|
|
316
|
-
let entries = test_kv_scan(&self.archive_bytes, request)?;
|
|
317
|
-
Ok(BackendKvValuePage {
|
|
318
|
-
values: entries.values,
|
|
319
|
-
resume_after: entries.resume_after,
|
|
320
|
-
})
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
async fn scan_entries(
|
|
324
|
-
&mut self,
|
|
325
|
-
request: BackendKvScanRequest,
|
|
326
|
-
) -> Result<BackendKvEntryPage, LixError> {
|
|
327
|
-
test_kv_scan(&self.archive_bytes, request)
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
async fn rollback(self: Box<Self>) -> Result<(), LixError> {
|
|
331
|
-
Ok(())
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
#[async_trait]
|
|
336
|
-
impl BackendWriteTransaction for PluginLookupTransaction {
|
|
337
|
-
async fn write_kv_batch(&mut self, _batch: BackendKvWriteBatch) -> Result<BackendKvWriteStats, LixError> {
|
|
338
|
-
Err(LixError::new(
|
|
339
|
-
"LIX_ERROR_UNKNOWN",
|
|
340
|
-
"plugin lookup test backend is read-only",
|
|
341
|
-
))
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
async fn commit(self: Box<Self>) -> Result<(), LixError> {
|
|
345
|
-
Ok(())
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
fn test_kv_get(
|
|
350
|
-
archive_bytes: &[u8],
|
|
351
|
-
namespace: &str,
|
|
352
|
-
key: &[u8],
|
|
353
|
-
) -> Result<Option<Vec<u8>>, LixError> {
|
|
354
|
-
match (namespace, key) {
|
|
355
|
-
(BINARY_CAS_MANIFEST_NAMESPACE, key)
|
|
356
|
-
if key == binary_blob_hash_bytes(archive_bytes).as_slice() =>
|
|
357
|
-
{
|
|
358
|
-
Ok(Some(encode_binary_cas_manifest(
|
|
359
|
-
&BinaryCasManifest::Chunked {
|
|
360
|
-
size_bytes: archive_bytes.len() as u64,
|
|
361
|
-
chunk_count: 1,
|
|
362
|
-
},
|
|
363
|
-
)))
|
|
364
|
-
}
|
|
365
|
-
(BINARY_CAS_CHUNK_NAMESPACE, key)
|
|
366
|
-
if key == binary_blob_hash_bytes(archive_bytes).as_slice() =>
|
|
367
|
-
{
|
|
368
|
-
Ok(Some(encode_binary_cas_chunk(
|
|
369
|
-
BinaryChunkCodec::Raw,
|
|
370
|
-
archive_bytes.len() as u64,
|
|
371
|
-
archive_bytes,
|
|
372
|
-
)))
|
|
373
|
-
}
|
|
374
|
-
_ => Ok(None),
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
fn test_kv_scan(
|
|
379
|
-
archive_bytes: &[u8],
|
|
380
|
-
request: BackendKvScanRequest,
|
|
381
|
-
) -> Result<BackendKvEntryPage, LixError> {
|
|
382
|
-
if request.namespace != BINARY_CAS_MANIFEST_CHUNK_NAMESPACE {
|
|
383
|
-
return Ok(BackendKvEntryPage {
|
|
384
|
-
keys: BytePageBuilder::new().finish(),
|
|
385
|
-
values: BytePageBuilder::new().finish(),
|
|
386
|
-
resume_after: None,
|
|
387
|
-
});
|
|
388
|
-
}
|
|
389
|
-
let blob_hash = binary_blob_hash_bytes(archive_bytes);
|
|
390
|
-
let chunk_hash = binary_blob_hash_bytes(archive_bytes);
|
|
391
|
-
let mut key = blob_hash.to_vec();
|
|
392
|
-
key.extend_from_slice(&0u64.to_be_bytes());
|
|
393
|
-
let include = match request.range {
|
|
394
|
-
BackendKvScanRange::Prefix(prefix) => key.starts_with(&prefix),
|
|
395
|
-
BackendKvScanRange::Range { start, end } => key >= start && key < end,
|
|
396
|
-
};
|
|
397
|
-
if !include || request.after.as_deref().is_some_and(|after| key.as_slice() <= after) {
|
|
398
|
-
return Ok(BackendKvEntryPage {
|
|
399
|
-
keys: BytePageBuilder::new().finish(),
|
|
400
|
-
values: BytePageBuilder::new().finish(),
|
|
401
|
-
resume_after: None,
|
|
402
|
-
});
|
|
403
|
-
}
|
|
404
|
-
let value = encode_binary_cas_manifest_chunk(&chunk_hash, archive_bytes.len() as u64);
|
|
405
|
-
let mut keys = BytePageBuilder::with_capacity(1, key.len());
|
|
406
|
-
let mut values = BytePageBuilder::with_capacity(1, value.len());
|
|
407
|
-
let mut resume_after = None;
|
|
408
|
-
if request.limit > 0 {
|
|
409
|
-
resume_after = Some(key.clone());
|
|
410
|
-
keys.push(&key);
|
|
411
|
-
values.push(&value);
|
|
412
|
-
}
|
|
413
|
-
let resume_after = (request.limit == 0).then_some(resume_after).flatten();
|
|
414
|
-
Ok(BackendKvEntryPage {
|
|
415
|
-
keys: keys.finish(),
|
|
416
|
-
values: values.finish(),
|
|
417
|
-
resume_after,
|
|
418
|
-
})
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
fn build_archive(entries: &[(&str, &[u8])]) -> Vec<u8> {
|
|
422
|
-
let options = SimpleFileOptions::default().compression_method(CompressionMethod::Stored);
|
|
423
|
-
let cursor = Cursor::new(Vec::new());
|
|
424
|
-
let mut writer = ZipWriter::new(cursor);
|
|
425
|
-
for (path, bytes) in entries {
|
|
426
|
-
writer
|
|
427
|
-
.start_file(*path, options)
|
|
428
|
-
.expect("archive entry start should succeed");
|
|
429
|
-
writer
|
|
430
|
-
.write_all(bytes)
|
|
431
|
-
.expect("archive entry write should succeed");
|
|
432
|
-
}
|
|
433
|
-
writer
|
|
434
|
-
.finish()
|
|
435
|
-
.expect("archive finish should succeed")
|
|
436
|
-
.into_inner()
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
fn build_plugin_archive(manifest_json: &str) -> Vec<u8> {
|
|
440
|
-
let wasm = [0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00];
|
|
441
|
-
build_archive(&[
|
|
442
|
-
("manifest.json", manifest_json.as_bytes()),
|
|
443
|
-
("plugin.wasm", &wasm),
|
|
444
|
-
])
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
fn plugin_manifest_json(key: &str) -> String {
|
|
448
|
-
format!(
|
|
449
|
-
r#"{{
|
|
450
|
-
"key":"{key}",
|
|
451
|
-
"runtime":"wasm-component-v1",
|
|
452
|
-
"api_version":"0.1.0",
|
|
453
|
-
"match":{{"path_glob":"*.json"}},
|
|
454
|
-
"entry":"plugin.wasm",
|
|
455
|
-
"schemas":["schema/plugin_json_schema.json"]
|
|
456
|
-
}}"#
|
|
457
|
-
)
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
#[tokio::test]
|
|
461
|
-
async fn installed_plugin_manifest_key_exists_reads_installed_manifest_keys() {
|
|
462
|
-
let backend = InstalledPluginLookupBackend {
|
|
463
|
-
archive_bytes: build_plugin_archive(&plugin_manifest_json("plugin_json")),
|
|
464
|
-
};
|
|
465
|
-
|
|
466
|
-
assert!(
|
|
467
|
-
installed_plugin_manifest_key_exists(&backend, "plugin_json")
|
|
468
|
-
.await
|
|
469
|
-
.expect("installed manifest key lookup should succeed")
|
|
470
|
-
);
|
|
471
|
-
assert!(
|
|
472
|
-
!installed_plugin_manifest_key_exists(&backend, "missing_plugin")
|
|
473
|
-
.await
|
|
474
|
-
.expect("missing manifest key lookup should succeed")
|
|
475
|
-
);
|
|
476
|
-
}
|
|
477
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
//! Plugin subsystem root.
|
|
2
|
-
//!
|
|
3
|
-
//! Phase 1 establishes `crate::plugin::*` as the owner path for plugin-domain
|
|
4
|
-
//! code under concrete plugin-owned modules instead of legacy ownership-neutral
|
|
5
|
-
//! buckets.
|
|
6
|
-
|
|
7
|
-
mod archive;
|
|
8
|
-
pub(crate) mod component;
|
|
9
|
-
mod manifest;
|
|
10
|
-
mod materializer;
|
|
11
|
-
mod storage;
|
|
12
|
-
|
|
13
|
-
pub(crate) use archive::{
|
|
14
|
-
load_installed_plugin_from_archive_bytes, parse_plugin_archive_for_install, ParsedPluginArchive,
|
|
15
|
-
};
|
|
16
|
-
#[allow(unused_imports)]
|
|
17
|
-
pub(crate) use manifest::{
|
|
18
|
-
glob_matches_path, parse_plugin_manifest_json, select_best_glob_match, DetectChangesConfig,
|
|
19
|
-
DetectStateContextConfig, PluginContentType, PluginManifest, PluginMatch, PluginRuntime,
|
|
20
|
-
StateContextColumn, ValidatedPluginManifest,
|
|
21
|
-
};
|
|
22
|
-
#[allow(unused_imports)]
|
|
23
|
-
pub(crate) use materializer::{
|
|
24
|
-
installed_plugin_manifest_key_exists, invalidate_installed_plugins_cache,
|
|
25
|
-
list_installed_plugin_manifest_keys, load_installed_plugins_from_backend_state,
|
|
26
|
-
load_installed_plugins_with_runtime_cache, FilesystemPluginMaterializer, InstalledPlugin,
|
|
27
|
-
PluginMaterializationHost,
|
|
28
|
-
};
|
|
29
|
-
#[allow(unused_imports)]
|
|
30
|
-
pub(crate) use storage::{
|
|
31
|
-
plugin_key_from_archive_path, plugin_storage_archive_file_id, plugin_storage_archive_path,
|
|
32
|
-
PLUGIN_ARCHIVE_FILE_EXTENSION, PLUGIN_STORAGE_ROOT_DIRECTORY_PATH,
|
|
33
|
-
};
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
-
"type": "object",
|
|
4
|
-
"additionalProperties": false,
|
|
5
|
-
"required": [
|
|
6
|
-
"key",
|
|
7
|
-
"runtime",
|
|
8
|
-
"api_version",
|
|
9
|
-
"match",
|
|
10
|
-
"entry",
|
|
11
|
-
"schemas"
|
|
12
|
-
],
|
|
13
|
-
"properties": {
|
|
14
|
-
"key": {
|
|
15
|
-
"type": "string",
|
|
16
|
-
"minLength": 1,
|
|
17
|
-
"maxLength": 128,
|
|
18
|
-
"pattern": "^[a-z][a-z0-9_-]*$"
|
|
19
|
-
},
|
|
20
|
-
"runtime": {
|
|
21
|
-
"type": "string",
|
|
22
|
-
"enum": [
|
|
23
|
-
"wasm-component-v1"
|
|
24
|
-
]
|
|
25
|
-
},
|
|
26
|
-
"api_version": {
|
|
27
|
-
"type": "string",
|
|
28
|
-
"pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$"
|
|
29
|
-
},
|
|
30
|
-
"match": {
|
|
31
|
-
"type": "object",
|
|
32
|
-
"additionalProperties": false,
|
|
33
|
-
"required": ["path_glob"],
|
|
34
|
-
"properties": {
|
|
35
|
-
"path_glob": {
|
|
36
|
-
"type": "string",
|
|
37
|
-
"minLength": 1
|
|
38
|
-
},
|
|
39
|
-
"content_type": {
|
|
40
|
-
"type": "string",
|
|
41
|
-
"enum": ["text", "binary"]
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
"detect_changes": {
|
|
46
|
-
"type": "object",
|
|
47
|
-
"additionalProperties": false,
|
|
48
|
-
"properties": {
|
|
49
|
-
"state_context": {
|
|
50
|
-
"type": "object",
|
|
51
|
-
"additionalProperties": false,
|
|
52
|
-
"properties": {
|
|
53
|
-
"include_active_state": {
|
|
54
|
-
"type": "boolean"
|
|
55
|
-
},
|
|
56
|
-
"columns": {
|
|
57
|
-
"type": "array",
|
|
58
|
-
"minItems": 1,
|
|
59
|
-
"uniqueItems": true,
|
|
60
|
-
"items": {
|
|
61
|
-
"type": "string",
|
|
62
|
-
"enum": [
|
|
63
|
-
"entity_id",
|
|
64
|
-
"schema_key",
|
|
65
|
-
"snapshot_content",
|
|
66
|
-
"file_id",
|
|
67
|
-
"plugin_key",
|
|
68
|
-
"version_id",
|
|
69
|
-
"change_id",
|
|
70
|
-
"metadata",
|
|
71
|
-
"created_at",
|
|
72
|
-
"updated_at"
|
|
73
|
-
]
|
|
74
|
-
},
|
|
75
|
-
"contains": {
|
|
76
|
-
"const": "entity_id"
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
},
|
|
80
|
-
"allOf": [
|
|
81
|
-
{
|
|
82
|
-
"if": {
|
|
83
|
-
"properties": {
|
|
84
|
-
"include_active_state": {
|
|
85
|
-
"const": true
|
|
86
|
-
}
|
|
87
|
-
},
|
|
88
|
-
"required": [
|
|
89
|
-
"include_active_state"
|
|
90
|
-
]
|
|
91
|
-
},
|
|
92
|
-
"then": {},
|
|
93
|
-
"else": {
|
|
94
|
-
"not": {
|
|
95
|
-
"required": [
|
|
96
|
-
"columns"
|
|
97
|
-
]
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
]
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
},
|
|
105
|
-
"entry": {
|
|
106
|
-
"type": "string",
|
|
107
|
-
"minLength": 1
|
|
108
|
-
},
|
|
109
|
-
"schemas": {
|
|
110
|
-
"type": "array",
|
|
111
|
-
"minItems": 1,
|
|
112
|
-
"items": {
|
|
113
|
-
"type": "string",
|
|
114
|
-
"minLength": 1
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
use crate::LixError;
|
|
2
|
-
|
|
3
|
-
pub const PLUGIN_STORAGE_ROOT_DIRECTORY_PATH: &str = "/.lix/plugins/";
|
|
4
|
-
pub const PLUGIN_ARCHIVE_FILE_EXTENSION: &str = ".lixplugin";
|
|
5
|
-
|
|
6
|
-
pub fn plugin_storage_archive_file_id(plugin_key: &str) -> String {
|
|
7
|
-
format!("lix_plugin_archive::{plugin_key}")
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
pub fn plugin_storage_archive_path(plugin_key: &str) -> Result<String, LixError> {
|
|
11
|
-
validate_plugin_key_segment(plugin_key)?;
|
|
12
|
-
Ok(format!(
|
|
13
|
-
"{PLUGIN_STORAGE_ROOT_DIRECTORY_PATH}{plugin_key}{PLUGIN_ARCHIVE_FILE_EXTENSION}"
|
|
14
|
-
))
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
pub fn plugin_key_from_archive_path(path: &str) -> Option<String> {
|
|
18
|
-
let file_name = path.strip_prefix(PLUGIN_STORAGE_ROOT_DIRECTORY_PATH)?;
|
|
19
|
-
let plugin_key = file_name.strip_suffix(PLUGIN_ARCHIVE_FILE_EXTENSION)?;
|
|
20
|
-
if plugin_key.is_empty()
|
|
21
|
-
|| plugin_key == "."
|
|
22
|
-
|| plugin_key == ".."
|
|
23
|
-
|| plugin_key.contains('/')
|
|
24
|
-
|| plugin_key.contains('\\')
|
|
25
|
-
{
|
|
26
|
-
return None;
|
|
27
|
-
}
|
|
28
|
-
Some(plugin_key.to_string())
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
fn validate_plugin_key_segment(plugin_key: &str) -> Result<(), LixError> {
|
|
32
|
-
if plugin_key.is_empty()
|
|
33
|
-
|| plugin_key == "."
|
|
34
|
-
|| plugin_key == ".."
|
|
35
|
-
|| plugin_key.contains('/')
|
|
36
|
-
|| plugin_key.contains('\\')
|
|
37
|
-
{
|
|
38
|
-
return Err(LixError {
|
|
39
|
-
code: "LIX_ERROR_UNKNOWN".to_string(),
|
|
40
|
-
message: format!(
|
|
41
|
-
"plugin key '{}' must be a single relative path segment",
|
|
42
|
-
plugin_key
|
|
43
|
-
),
|
|
44
|
-
hint: None,
|
|
45
|
-
details: None,
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
Ok(())
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
#[cfg(test)]
|
|
52
|
-
mod tests {
|
|
53
|
-
use super::{plugin_key_from_archive_path, plugin_storage_archive_path};
|
|
54
|
-
|
|
55
|
-
#[test]
|
|
56
|
-
fn computes_storage_archive_paths() {
|
|
57
|
-
assert_eq!(
|
|
58
|
-
plugin_storage_archive_path("plugin_json").expect("path should build"),
|
|
59
|
-
"/.lix/plugins/plugin_json.lixplugin"
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
#[test]
|
|
64
|
-
fn extracts_plugin_key_from_storage_path() {
|
|
65
|
-
assert_eq!(
|
|
66
|
-
plugin_key_from_archive_path("/.lix/plugins/plugin_json.lixplugin"),
|
|
67
|
-
Some("plugin_json".to_string())
|
|
68
|
-
);
|
|
69
|
-
assert_eq!(
|
|
70
|
-
plugin_key_from_archive_path("/.lix/plugins/nested/plugin.lixplugin"),
|
|
71
|
-
None
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
}
|