optimize mainargsignature inference

This commit is contained in:
Ruben Fiszel
2022-10-13 02:41:24 +02:00
parent d1d3403658
commit ff6046c079
3 changed files with 29 additions and 15 deletions
@@ -71,7 +71,9 @@
isDefault.push(k)
}
})
await inferArgs(lang, code, schema)
schema = schema
isDefault
+3 -1
View File
@@ -4,7 +4,7 @@ import { inferArgs } from '$lib/infer'
import { loadSchema } from '$lib/scripts'
import { workspaceStore } from '$lib/stores'
import { emptySchema } from '$lib/utils'
import { get } from 'svelte/store'
import { get, writable } from 'svelte/store'
import type { FlowModuleState, FlowState } from './flowState'
export function cleanInputs(flow: Flow | any): Flow {
@@ -74,11 +74,13 @@ export function selectedIdToModuleState(selectedId: string, flow: FlowState): Fl
}
}
const loadSchemaLastRun = writable<[string | undefined, Schema]>(undefined)
export async function loadSchemaFromModule(module: FlowModule): Promise<{
input_transforms: Record<string, InputTransform>
schema: Schema
}> {
const mod = module.value
if (mod.type == 'rawscript' || mod.type === 'script') {
+24 -14
View File
@@ -1,27 +1,37 @@
import { ScriptService, type MainArgSignature } from '$lib/gen'
import { get, writable } from 'svelte/store'
import type { Schema, SchemaProperty } from './common.js'
const loadSchemaLastRun = writable<[string | undefined, MainArgSignature | undefined]>(undefined)
export async function inferArgs(
language: 'python3' | 'deno' | 'go',
code: string,
schema: Schema
): Promise<void> {
let lastRun = get(loadSchemaLastRun)
let inferedSchema: MainArgSignature
if (code == '') { code = ' ' }
if (language == 'python3') {
inferedSchema = await ScriptService.pythonToJsonschema({
requestBody: code
})
} else if (language == 'deno') {
inferedSchema = await ScriptService.denoToJsonschema({
requestBody: code
})
} else if (language == 'go') {
inferedSchema = await ScriptService.goToJsonschema({
requestBody: code
})
if (code == lastRun[0] && lastRun[1]) {
inferedSchema = lastRun[1]
} else {
return
if (code == '') { code = ' ' }
if (language == 'python3') {
inferedSchema = await ScriptService.pythonToJsonschema({
requestBody: code
})
} else if (language == 'deno') {
inferedSchema = await ScriptService.denoToJsonschema({
requestBody: code
})
} else if (language == 'go') {
inferedSchema = await ScriptService.goToJsonschema({
requestBody: code
})
} else {
return
}
loadSchemaLastRun.set([code, inferedSchema])
}
schema.required = []