feat: add script bootstrap and script generate-metadata CLI commands (#3007)

* feat: add script bootstrap and script generate-metadata CLI commands

* Address PR comments on code
This commit is contained in:
Guillaume Bouvignies
2024-01-16 18:25:51 +01:00
committed by GitHub
parent 602afbe457
commit 33788f6361
17 changed files with 1726 additions and 117 deletions

24
cli/bootstrap/common.ts Normal file
View File

@@ -0,0 +1,24 @@
export interface SchemaProperty {
type: string | undefined
description?: string
pattern?: string
default?: any
enum?: string[]
contentEncoding?: 'base64' | 'binary'
format?: string
items?: {
type?: 'string' | 'number' | 'bytes' | 'object'
contentEncoding?: 'base64'
enum?: string[]
}
min?: number
max?: number
currency?: string
currencyLocale?: string
multiselect?: boolean
customErrorMessage?: string
properties?: { [name: string]: SchemaProperty }
required?: string[]
showExpr?: string
}

View File

@@ -0,0 +1,35 @@
import { SchemaProperty } from "./common.ts";
export interface FlowDefinition {
summary: string,
description: string,
value: {
modules: any[]
},
schema: {
$schema: string,
type: string,
order: string[],
properties: { [name: string]: SchemaProperty},
required: string[]
}
ws_error_handler_muted: false
}
export function defaultFlowDefinition(): FlowDefinition {
return {
summary: '',
description: '',
value: {
modules: []
},
schema: {
$schema: 'https://json-schema.org/draft/2020-12/schema',
type: 'object',
order: [],
properties: {},
required: []
},
ws_error_handler_muted: false,
}
}

View File

@@ -0,0 +1,83 @@
import { SchemaProperty } from "./common.ts";
export interface ScriptMetadata {
summary: string,
description: string,
lock: string[],
is_template: boolean,
kind: string,
schema: {
$schema: string,
type: string,
properties: { [name: string]: SchemaProperty},
required: string[]
}
}
export function defaultScriptMetadata(): ScriptMetadata {
return {
summary: '',
description: '',
lock: [],
is_template: false,
kind: 'script',
schema: {
$schema: 'https://json-schema.org/draft/2020-12/schema',
type: 'object',
properties: {},
required: []
}
}
}
export const scriptBootstrapCode = {
python3: `def main():
return "Hello world"
`,
nativets: `export async function main() {
return "Hello world";
}
`,
bun: `export async function main() {
return "Hello world";
}
`,
deno: `export async function main() {
return "Hello world";
}
`,
go: `package inner
func main() (interface{}, error) {
return "Hello world", nil
}
`,
mysql: `SELECT 'Hello world' AS message
`,
bigquery: `SELECT 'Hello world' AS message
`,
snowflake: `SELECT 'Hello world' AS message
`,
mssql: `SELECT 'Hello world' AS message
`,
graphql: `query() {
demo() {}
}`,
postgresql: `SELECT 'Hello world' AS message
`,
bash: `echo "Hello world"
`,
powershell: `Write-Output "Hello world"`,
}