fix: clean exported deno-client api

This commit is contained in:
Ruben Fiszel
2022-05-18 10:09:41 +02:00
parent c8af16fa23
commit b69ca7a822
2 changed files with 20 additions and 2 deletions
BIN
View File
Binary file not shown.
+20 -2
View File
@@ -1,8 +1,16 @@
import { ResourceApi, VariableApi, ServerConfiguration } from './windmill-api/index.ts'
import { createConfiguration, type Configuration as Configuration } from './windmill-api/configuration.ts'
export * from './windmill-api/index.ts'
export {
AdminApi, AuditApi, FlowApi, GranularAclApi, GroupApi,
JobApi, ResourceApi, VariableApi, ScriptApi, ScheduleApi, SettingsApi,
UserApi, WorkspaceApi
} from './windmill-api/index.ts'
/**
* Create a client configuration from env variables
* @returns client configuration
*/
export function createConf(): Configuration & { workspace_id: string } {
const token = Deno.env.get("WM_TOKEN") ?? 'no_token'
const base_url = Deno.env.get("BASE_URL") ?? 'http://localhost:8000'
@@ -14,19 +22,29 @@ export function createConf(): Configuration & { workspace_id: string } {
}
}
/**
* Get a resource value by path
* @param path path of the resource
* @returns resource value
*/
export async function getResource(path: string): Promise<any> {
const conf = createConf()
const resource = await new ResourceApi(conf).getResource(conf.workspace_id, path)
return await transformLeaves(resource.value)
}
/**
* Get a variable by path
* @param path path of the variable
* @returns variable value
*/
export async function getVariable(path: string): Promise<string | undefined> {
const conf = createConf()
const variable = await new VariableApi(conf).getVariable(conf.workspace_id, path)
return variable.value
}
export async function transformLeaves(d: { [key: string]: any }): Promise<{ [key: string]: any }> {
async function transformLeaves(d: { [key: string]: any }): Promise<{ [key: string]: any }> {
for (const k in d) {
d[k] = await _transformLeaf(d[k])
}