0

Update Resource

by
Published today

Update a resource's value, description or path. Fields left empty keep their current value; the value is replaced as a whole, not merged.

Script windmill Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 4 hours ago
1
//native
2

3
import * as wmill from "windmill-client"
4

5
// windmill-client errors only carry the status text: throw the response body, which says why
6
wmill.OpenAPI.interceptors.response.use(async (response) => {
7
  if (!response.ok) {
8
    throw new Error(`${response.status} ${await response.text()}`)
9
  }
10
  return response
11
})
12

13
export type DynSelect_path = string
14

15
export async function path() {
16
  const resources = await wmill.ResourceService.listResource({
17
    workspace: wmill.getWorkspace(),
18
    perPage: 1000,
19
  })
20
  return resources.map((r) => ({
21
    value: r.path,
22
    label: `${r.path} (${r.resource_type})`,
23
  }))
24
}
25

26
/**
27
 * Update Resource
28
 * Update a resource's value, description or path. Fields left empty keep their current value; the value is replaced as a whole, not merged.
29
 */
30
export async function main(
31
  path: DynSelect_path,
32
  value: { [key: string]: any } | undefined,
33
  description: string | undefined,
34
  new_path: string | undefined
35
) {
36
  return await wmill.ResourceService.updateResource({
37
    workspace: wmill.getWorkspace(),
38
    path,
39
    requestBody: {
40
      value: value ?? undefined,
41
      description: description || undefined,
42
      path: new_path || undefined,
43
    },
44
  })
45
}
46