move inferArgs to be loaded JIT

This commit is contained in:
Ruben Fiszel
2023-07-31 10:17:36 +02:00
parent 754b966904
commit 5839373348
4 changed files with 43 additions and 45 deletions
@@ -24,8 +24,7 @@
import { createEventDispatcher } from 'svelte'
import { deepEqual } from 'fast-equals'
import { computeFields } from './utils'
import { loadSchema } from '../../utils'
import { inferArgs } from '$lib/infer'
import { inferArgs, loadSchema } from '$lib/infer'
import RunButton from './RunButton.svelte'
import { getScriptByPath } from '$lib/scripts'
import { sendUserToast } from '$lib/toast'
@@ -10,8 +10,9 @@
import type { AppViewerContext } from '$lib/components/apps/types'
import { createEventDispatcher, getContext } from 'svelte'
import type { Schema } from '$lib/common'
import { getAllScriptNames, loadSchema, schemaToInputsSpec } from '$lib/components/apps/utils'
import { getAllScriptNames, schemaToInputsSpec } from '$lib/components/apps/utils'
import { defaultIfEmptyString, emptySchema } from '$lib/utils'
import { loadSchema } from '$lib/infer'
type Tab = 'hubscripts' | 'workspacescripts' | 'workspaceflows' | 'inlinescripts'
+2 -40
View File
@@ -1,7 +1,5 @@
import type { Schema, SupportedLanguage } from '$lib/common'
import { FlowService, ScriptService } from '$lib/gen'
import { inferArgs } from '$lib/infer'
import { emptySchema } from '$lib/utils'
import type { Schema } from '$lib/common'
import { twMerge } from 'tailwind-merge'
import type { AppComponent } from './editor/component'
import type { AppInput, InputType, ResultAppInput, StaticAppInput } from './inputType'
@@ -39,42 +37,6 @@ export function allItems(
return [...grid, ...Object.values(subgrids).flat()]
}
export async function loadSchema(
workspace: string,
path: string,
runType: 'script' | 'flow' | 'hubscript'
): Promise<{ schema: Schema; summary: string | undefined }> {
if (runType === 'script') {
const script = await ScriptService.getScriptByPath({
workspace,
path
})
return { schema: script.schema as any, summary: script.summary }
} else if (runType === 'flow') {
const flow = await FlowService.getFlowByPath({
workspace,
path
})
return { schema: flow.schema as any, summary: flow.summary }
} else {
const script = await ScriptService.getHubScriptByPath({
path
})
if (
script.schema == undefined ||
Object.keys(script.schema).length == 0 ||
typeof script.schema != 'object'
) {
script.schema = emptySchema()
}
await inferArgs(script.language as SupportedLanguage, script.content, script.schema)
return { schema: script.schema, summary: script.summary }
}
}
export function schemaToInputsSpec(
schema: Schema,
defaultUserInput: boolean
+38 -2
View File
@@ -1,7 +1,7 @@
import type { MainArgSignature } from '$lib/gen'
import { ScriptService, type MainArgSignature, FlowService } from '$lib/gen'
import { get, writable } from 'svelte/store'
import type { Schema, SchemaProperty, SupportedLanguage } from './common.js'
import { sortObject } from './utils.js'
import { emptySchema, sortObject } from './utils.js'
import { tick } from 'svelte'
import init, {
parse_deno,
@@ -183,3 +183,39 @@ function argSigToJsonSchemaType(
oldS.format = undefined
}
}
export async function loadSchema(
workspace: string,
path: string,
runType: 'script' | 'flow' | 'hubscript'
): Promise<{ schema: Schema; summary: string | undefined }> {
if (runType === 'script') {
const script = await ScriptService.getScriptByPath({
workspace,
path
})
return { schema: script.schema as any, summary: script.summary }
} else if (runType === 'flow') {
const flow = await FlowService.getFlowByPath({
workspace,
path
})
return { schema: flow.schema as any, summary: flow.summary }
} else {
const script = await ScriptService.getHubScriptByPath({
path
})
if (
script.schema == undefined ||
Object.keys(script.schema).length == 0 ||
typeof script.schema != 'object'
) {
script.schema = emptySchema()
}
await inferArgs(script.language as SupportedLanguage, script.content, script.schema)
return { schema: script.schema, summary: script.summary }
}
}