feat: add resource and variable picker for rest scripts (#3628)

* feat: add resource and variable picker for rest scripts

* feat: add reserved variables to rest scripts
This commit is contained in:
HugoCasa
2024-04-29 12:13:21 +02:00
committed by GitHub
parent b5297846fe
commit 3956d012ad
2 changed files with 48 additions and 9 deletions
+11 -4
View File
@@ -89,8 +89,8 @@ use crate::{
bash_executor::{handle_bash_job, handle_powershell_job, ANSI_ESCAPE_RE},
bun_executor::{gen_lockfile, get_trusted_deps, handle_bun_job},
common::{
build_args_map, get_cached_resource_value_if_valid, hash_args, read_result, save_in_cache,
write_file, NO_LOGS_AT_ALL, SLOW_LOGS,
build_args_map, get_cached_resource_value_if_valid, get_reserved_variables, hash_args,
read_result, save_in_cache, write_file, NO_LOGS_AT_ALL, SLOW_LOGS,
},
deno_executor::{generate_deno_lock, handle_deno_job},
go_executor::{handle_go_job, install_go_dependencies},
@@ -3203,9 +3203,16 @@ async fn handle_code_execution_job(
db,
)
.await;
let reserved_variables = get_reserved_variables(job, &client.get_token().await, db).await?;
let code = format!(
"const BASE_URL = '{base_internal_url}';\nconst WM_TOKEN = '{}';\n{}",
&client.get_token().await,
"const BASE_URL = '{base_internal_url}';\nconst BASE_INTERNAL_URL = '{base_internal_url}';\n{}\n{}",
reserved_variables
.iter()
.map(|(k, v)| format!("const {} = '{}';\n", k, v))
.collect::<Vec<String>>()
.join("\n"),
inner_content
);
let (result, ts_logs) =
+37 -5
View File
@@ -79,13 +79,27 @@
let showResourcePicker = false
let showResourceTypePicker = false
$: showContextVarPicker = ['python3', 'bash', 'powershell', 'go', 'deno', 'bun'].includes(
lang ?? ''
)
$: showVarPicker = ['python3', 'bash', 'powershell', 'go', 'deno', 'bun'].includes(lang ?? '')
$: showResourcePicker = ['python3', 'bash', 'powershell', 'go', 'deno', 'bun'].includes(
$: showContextVarPicker = [
'python3',
'bash',
'powershell',
'go',
'deno',
'bun',
'nativets'
].includes(lang ?? '')
$: showVarPicker = ['python3', 'bash', 'powershell', 'go', 'deno', 'bun', 'nativets'].includes(
lang ?? ''
)
$: showResourcePicker = [
'python3',
'bash',
'powershell',
'go',
'deno',
'bun',
'nativets'
].includes(lang ?? '')
$: showResourceTypePicker =
['typescript', 'javascript'].includes(scriptLangToEditorLang(lang)) || lang === 'python3'
@@ -271,6 +285,8 @@
editor.insertAtCursor(`$${name}`)
} else if (lang == 'powershell') {
editor.insertAtCursor(`$Env:${name}`)
} else if (lang == 'nativets') {
editor.insertAtCursor(name)
}
sendUserToast(`${name} inserted at cursor`)
}}
@@ -316,6 +332,14 @@
editor.insertAtCursor(
`\nInvoke-RestMethod -Headers $Headers -Uri "$Env:BASE_INTERNAL_URL/api/w/$Env:WM_WORKSPACE/variables/get_value/${path}"`
)
} else if (lang == 'nativets') {
editor.insertAtCursor(
'await fetch(`${BASE_INTERNAL_URL}/api/w/${WM_WORKSPACE}/variables/get_value/' +
path +
'`, {\nheaders: { Authorization: `Bearer ${WM_TOKEN}` }'
)
editor.arrowDown()
editor.insertAtCursor('.then(res => res.json())')
}
sendUserToast(`${name} inserted at cursor`)
}}
@@ -375,6 +399,14 @@
editor.insertAtCursor(
`\nInvoke-RestMethod -Headers $Headers -Uri "$Env:BASE_INTERNAL_URL/api/w/$Env:WM_WORKSPACE/resources/get_value_interpolated/${path}"`
)
} else if (lang == 'nativets') {
editor.insertAtCursor(
'await fetch(`${BASE_INTERNAL_URL}/api/w/${WM_WORKSPACE}/resources/get_value_interpolated/' +
path +
'`, {\nheaders: { Authorization: `Bearer ${WM_TOKEN}` }'
)
editor.arrowDown()
editor.insertAtCursor('.then(res => res.json())')
}
sendUserToast(`${path} inserted at cursor`)
}}