Skip to content

Commit 95a6df3

Browse files
committed
refactor(toml): Move params to params.inline
1 parent 2780ff8 commit 95a6df3

4 files changed

Lines changed: 75 additions & 16 deletions

File tree

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
async function fetch_get(params) {
2-
console.info("Fetching " + params[0]);
3-
const resp = await fetch(params[0]);
1+
async function fetch_get(url) {
2+
console.info("Fetching " + url);
3+
const resp = await fetch(url);
44
const text = await resp.text();
55
return text;
66
}

obelisk-testing-sqlite-local.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ backtrace.ignore_component_digest = true
110110
# name = "activity_js_fetch_get"
111111
# location = "${OBELISK_TOML_DIR}/crates/testing/test-programs/js/activity/fetch.js"
112112
# ffqn = "test:pkg/ifc.fetch-get"
113+
# params.inline = ["string"]
113114
# max_retries = 0
114115
# [[activity_js.allowed_host]]
115116
# pattern = "http://localhost:5005" # all https is allowed

src/config/toml.rs

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,9 +1050,9 @@ pub(crate) struct ActivityJsComponentConfigToml {
10501050
pub(crate) ffqn: String,
10511051
/// Custom parameters for the JS function.
10521052
/// Each entry has a `name` and a WIT `type` (e.g. `string`, `u32`, `list<string>`).
1053-
/// If omitted, defaults to a single `params: list<string>` parameter.
1053+
/// If omitted, defaults to a single `(params: list<string>)` parameter.
10541054
#[serde(default)]
1055-
pub(crate) params: Vec<JsParamToml>,
1055+
pub(crate) params: ParamsSpec,
10561056
#[serde(default)]
10571057
pub(crate) exec: ExecConfigToml,
10581058
#[serde(default = "default_max_retries")]
@@ -1070,6 +1070,15 @@ pub(crate) struct ActivityJsComponentConfigToml {
10701070
pub(crate) allowed_host: Vec<AllowedHostToml>,
10711071
}
10721072

1073+
#[derive(Debug, Default, Deserialize, JsonSchema, Clone)]
1074+
#[serde(rename_all = "snake_case")]
1075+
pub(crate) enum ParamsSpec {
1076+
#[default]
1077+
Default, // `(params: list<string>)`
1078+
Inline(Vec<JsParamToml>),
1079+
// TODO: Add a WIT folder location later
1080+
}
1081+
10731082
/// A parameter declaration for a JS activity function.
10741083
#[derive(Debug, Deserialize, JsonSchema, Clone)]
10751084
#[serde(deny_unknown_fields)]
@@ -1113,16 +1122,17 @@ impl ActivityJsComponentConfigToml {
11131122
.map_err(|e| anyhow!("invalid ffqn `{}`: {e}", self.ffqn))?;
11141123

11151124
// Parse custom params or default to `params: list<string>`
1116-
let parsed_params = if self.params.is_empty() {
1117-
vec![concepts::ParameterType {
1118-
type_wrapper: val_json::type_wrapper::TypeWrapper::List(Box::new(
1119-
val_json::type_wrapper::TypeWrapper::String,
1120-
)),
1121-
name: StrVariant::Static("params"),
1122-
wit_type: StrVariant::Static("list<string>"),
1123-
}]
1124-
} else {
1125-
self.params
1125+
let parsed_params = match self.params {
1126+
ParamsSpec::Default => {
1127+
vec![concepts::ParameterType {
1128+
type_wrapper: val_json::type_wrapper::TypeWrapper::List(Box::new(
1129+
val_json::type_wrapper::TypeWrapper::String,
1130+
)),
1131+
name: StrVariant::Static("params"),
1132+
wit_type: StrVariant::Static("list<string>"),
1133+
}]
1134+
}
1135+
ParamsSpec::Inline(params) => params
11261136
.iter()
11271137
.map(|p| {
11281138
let tw = val_json::type_wrapper::parse_wit_type(&p.wit_type)
@@ -1133,7 +1143,7 @@ impl ActivityJsComponentConfigToml {
11331143
wit_type: StrVariant::from(p.wit_type.clone()),
11341144
})
11351145
})
1136-
.collect::<Result<Vec<_>, anyhow::Error>>()?
1146+
.collect::<Result<Vec<_>, anyhow::Error>>()?,
11371147
};
11381148

11391149
let js_source = self

toml/schema.json

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@
220220
"name": {
221221
"$ref": "#/$defs/ConfigName"
222222
},
223+
"params": {
224+
"description": "Custom parameters for the JS function.\nEach entry has a `name` and a WIT `type` (e.g. `string`, `u32`, `list<string>`).\nIf omitted, defaults to a single `(params: list<string>)` parameter.",
225+
"$ref": "#/$defs/ParamsSpec"
226+
},
223227
"retry_exp_backoff": {
224228
"$ref": "#/$defs/DurationConfig"
225229
}
@@ -784,6 +788,25 @@
784788
"description": "Location of a JavaScript source file for JS activities.\nSupports local file paths and `gh://` GitHub release references.\nOCI references are not supported.",
785789
"type": "string"
786790
},
791+
"JsParamToml": {
792+
"description": "A parameter declaration for a JS activity function.",
793+
"type": "object",
794+
"properties": {
795+
"name": {
796+
"description": "Parameter name (used in WIT metadata).",
797+
"type": "string"
798+
},
799+
"type": {
800+
"description": "WIT type string, e.g. `string`, `u32`, `list<string>`, `option<u64>`.",
801+
"type": "string"
802+
}
803+
},
804+
"additionalProperties": false,
805+
"required": [
806+
"name",
807+
"type"
808+
]
809+
},
787810
"LockingStrategy": {
788811
"type": "string",
789812
"enum": [
@@ -852,6 +875,31 @@
852875
"enabled"
853876
]
854877
},
878+
"ParamsSpec": {
879+
"oneOf": [
880+
{
881+
"type": "string",
882+
"enum": [
883+
"default"
884+
]
885+
},
886+
{
887+
"type": "object",
888+
"properties": {
889+
"inline": {
890+
"type": "array",
891+
"items": {
892+
"$ref": "#/$defs/JsParamToml"
893+
}
894+
}
895+
},
896+
"additionalProperties": false,
897+
"required": [
898+
"inline"
899+
]
900+
}
901+
]
902+
},
855903
"PostgresConfigToml": {
856904
"type": "object",
857905
"properties": {

0 commit comments

Comments
 (0)