Files
windmill/frontend/src/lib/scripts.ts
T
2022-10-21 19:43:53 +02:00

26 lines
755 B
TypeScript

import { get } from 'svelte/store'
import type { Schema } from './common'
import { ScriptService } from './gen'
import { inferArgs } from './infer'
import { workspaceStore } from './stores'
import { emptySchema } from './utils'
export async function loadSchema(path: string): Promise<Schema> {
if (path.startsWith('hub/')) {
const { content, language, schema } = await ScriptService.getHubScriptByPath({ path })
if (language == 'deno') {
const newSchema = emptySchema()
await inferArgs('deno', content ?? '', newSchema)
return newSchema
} else {
return schema ?? emptySchema()
}
} else {
const script = await ScriptService.getScriptByPath({
workspace: get(workspaceStore)!,
path: path ?? ''
})
return script.schema
}
}