//native
import * as wmill from "windmill-client"
// windmill-client errors only carry the status text: throw the response body, which says why
wmill.OpenAPI.interceptors.response.use(async (response) => {
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
return response
})
export type DynSelect_resource_type = string
export async function resource_type() {
const names = await wmill.ResourceService.listResourceTypeNames({
workspace: wmill.getWorkspace(),
})
return names.map((n) => ({ value: n, label: n }))
}
/**
* Create Resource
* Create a resource of a given resource type, or overwrite it when update_if_exists is set. Windmill resolves `$var:`/`$res:` strings in job arguments before the script runs, so the stored value holds what they point to, not the reference.
*/
export async function main(
path: string,
resource_type: DynSelect_resource_type,
value: { [key: string]: any },
description: string | undefined,
update_if_exists: boolean | undefined
) {
return await wmill.ResourceService.createResource({
workspace: wmill.getWorkspace(),
updateIfExists: update_if_exists || undefined,
requestBody: {
path,
resource_type,
value: value ?? {},
description: description || undefined,
},
})
}
Submitted by hugo989 5 hours ago