|
1 | 1 | use bon::Builder; |
2 | 2 | use schemars::JsonSchema; |
3 | | -use serde::Deserialize; |
4 | | -use serde::Serialize; |
| 3 | +use serde::{Deserialize, Serialize}; |
5 | 4 |
|
6 | | -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, Builder)] |
| 5 | +use crate::shared::safe_filepath::SafeFilepath; |
| 6 | + |
| 7 | +/// A KCL project that can be executed. |
| 8 | +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, Default, Builder)] |
7 | 9 | #[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))] |
8 | 10 | #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] |
9 | 11 | #[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))] |
10 | 12 | #[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)] |
11 | | -pub struct ExecKclProjectOk {} |
| 13 | +pub struct KclProject { |
| 14 | + /// All files in the project. |
| 15 | + pub files: Vec<KclFile>, |
| 16 | + /// Which file is the entrypoint? |
| 17 | + /// This is the first KCL file to be executed, |
| 18 | + /// the root of the KCL module tree. |
| 19 | + pub entrypoint: SafeFilePath, |
| 20 | +} |
12 | 21 |
|
13 | | -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, Builder)] |
| 22 | +/// Region-creation algorithm version. |
| 23 | +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, Default, Builder)] |
14 | 24 | #[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))] |
15 | 25 | #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] |
16 | 26 | #[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))] |
17 | 27 | #[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)] |
18 | | -pub struct ExecKclProjectErr {} |
| 28 | +pub struct KclFile { |
| 29 | + /// Where is the file, relative to the project directory? |
| 30 | + pub path: SafeFilepath, |
| 31 | + /// Contents of the file, as UTF-8 encoded bytes. |
| 32 | + #[serde(deserialize_with = "serde_bytes::deserialize")] |
| 33 | + #[serde(serialize_with = "serde_bytes::serialize")] |
| 34 | + pub contents: Vec<u8>, |
| 35 | +} |
| 36 | + |
| 37 | +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, Builder)] |
| 38 | +#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))] |
| 39 | +#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))] |
| 40 | +#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)] |
| 41 | +/// Successful KCL project execution response. |
| 42 | +pub struct ExecKclProjectOk { |
| 43 | + /// Scene graph updates and execution metadata produced by running the KCL project. |
| 44 | + pub scene_graph_delta: |
| 45 | + kcl_api::SceneGraphDelta<kcl_api::SceneGraph<serde_json::Value, serde_json::Value>, serde_json::Value>, |
| 46 | +} |
| 47 | + |
| 48 | +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, Builder)] |
| 49 | +#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))] |
| 50 | +#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))] |
| 51 | +#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)] |
| 52 | +/// Failed KCL project execution response. |
| 53 | +pub struct ExecKclProjectErr { |
| 54 | + /// Error produced while executing the KCL project. |
| 55 | + pub error: kcl_api::Error, |
| 56 | +} |
| 57 | + |
| 58 | +#[cfg(feature = "arbitrary")] |
| 59 | +// TODO: Impl this properly for fuzzing. |
| 60 | +impl<'a> arbitrary::Arbitrary<'a> for ExecKclProjectOk { |
| 61 | + fn arbitrary(_u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> { |
| 62 | + Ok(Self { |
| 63 | + scene_graph_delta: kcl_api::SceneGraphDelta::new( |
| 64 | + kcl_api::SceneGraph::empty(kcl_api::ProjectId(0), kcl_api::FileId(0), kcl_api::Version(0)), |
| 65 | + Vec::new(), |
| 66 | + false, |
| 67 | + serde_json::Value::Null, |
| 68 | + ), |
| 69 | + }) |
| 70 | + } |
| 71 | +} |
| 72 | + |
| 73 | +#[cfg(feature = "arbitrary")] |
| 74 | +// TODO: Impl this properly for fuzzing. |
| 75 | +impl<'a> arbitrary::Arbitrary<'a> for ExecKclProjectErr { |
| 76 | + fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> { |
| 77 | + Ok(Self { |
| 78 | + error: kcl_api::Error { |
| 79 | + msg: <String as arbitrary::Arbitrary>::arbitrary(u)?, |
| 80 | + }, |
| 81 | + }) |
| 82 | + } |
| 83 | +} |
0 commit comments