Edits history of script submission #23602 for ' Update Resource (windmill)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //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_path = string
    
    export async function path() {
      const resources = await wmill.ResourceService.listResource({
        workspace: wmill.getWorkspace(),
        perPage: 1000,
      })
      return resources.map((r) => ({
        value: r.path,
        label: `${r.path} (${r.resource_type})`,
      }))
    }
    
    /**
     * Update Resource
     * Update a resource's value, description or path. Fields left empty keep their current value; the value is replaced as a whole, not merged.
     */
    export async function main(
      path: DynSelect_path,
      value: { [key: string]: any } | undefined,
      description: string | undefined,
      new_path: string | undefined
    ) {
      return await wmill.ResourceService.updateResource({
        workspace: wmill.getWorkspace(),
        path,
        requestBody: {
          value: value ?? undefined,
          description: description || undefined,
          path: new_path || undefined,
        },
      })
    }
    

    Submitted by hugo989 5 hours ago