diff --git a/backend/openapi.yaml b/backend/openapi.yaml index 3060a05506..f6f3b6db34 100644 --- a/backend/openapi.yaml +++ b/backend/openapi.yaml @@ -3117,8 +3117,15 @@ components: name: type: string typ: - type: string - enum: ["str", "float", "int", "bool", "unknown"] + oneOf: + - type: string + enum: ["str", "float", "int", "bool", "unknown"] + - type: object + properties: + resourcetype: + type: string + required: + - resourcetype has_default: type: boolean default: {} diff --git a/backend/src/parser.rs b/backend/src/parser.rs index ac48a5a443..31af756ae6 100644 --- a/backend/src/parser.rs +++ b/backend/src/parser.rs @@ -36,6 +36,7 @@ pub enum Typ { List, Bytes, Datetime, + ResourceType(String), Unknown, } @@ -119,7 +120,7 @@ use swc_common::sync::Lrc; use swc_common::{FileName, SourceMap}; use swc_ecma_ast::{ AssignPat, BindingIdent, Decl, ExportDecl, FnDecl, Ident, ModuleDecl, ModuleItem, Pat, - TsKeywordTypeKind, TsType, + TsEntityName, TsKeywordTypeKind, TsType, TsTypeRef, }; use swc_ecma_parser::{lexer::Lexer, Parser, StringInput, Syntax, TsConfig}; @@ -239,6 +240,33 @@ fn binding_ident_to_arg( }, // TODO: we can do better here and extract the inner type of array TsType::TsArrayType(_) => Typ::List, + TsType::TsTypeRef(TsTypeRef { + span: _, + type_name: + TsEntityName::Ident(Ident { + span: _, + sym, + optional: _, + }), + type_params, + }) => { + println!("N{sym:?}\nP{type_params:?}"); + match sym.to_string().as_str() { + "ResourceType" => Typ::ResourceType( + type_params + .as_ref() + .and_then(|x| { + x.params.get(0).and_then(|y| { + y.as_ts_lit_type().and_then(|z| { + z.lit.as_str().map(|a| a.to_owned().value.to_string()) + }) + }) + }) + .unwrap_or_else(|| "unknown".to_string()), + ), + _ => Typ::Unknown, + } + } _ => Typ::Unknown, }) .unwrap_or(Typ::Unknown), @@ -724,7 +752,8 @@ def main(): fn test_parse_deno_sig() -> anyhow::Result<()> { let code = " -export function main(test1: string, test2: string = \"burkina\") { +export function main(test1: string, test2: string = \"burkina\", + test3: ResourceType<'rt'>, email: email_string) { console.log(42) } diff --git a/deno-client/index.ts b/deno-client/index.ts index 1bdfdcd890..8124bf1467 100644 --- a/deno-client/index.ts +++ b/deno-client/index.ts @@ -7,6 +7,11 @@ export { UserApi, WorkspaceApi } from './windmill-api/index.ts' +export type string_regex = String +export type string_email = String + +export type ResourceType = {} + /** * Create a client configuration from env variables * @returns client configuration diff --git a/frontend/src/infer.ts b/frontend/src/infer.ts index 91bb59da98..a60025f6f0 100644 --- a/frontend/src/infer.ts +++ b/frontend/src/infer.ts @@ -31,7 +31,7 @@ export async function inferArgs( } else { schema.properties[arg.name] = oldProperties[arg.name] } - pythonToJsonSchemaType(arg.typ, schema.properties[arg.name]) + argSigToJsonSchemaType(arg.typ, schema.properties[arg.name]) schema.properties[arg.name].default = arg.default if (!arg.has_default) { @@ -44,7 +44,7 @@ export async function inferArgs( } } -function pythonToJsonSchemaType(t: string, s: SchemaProperty): void { +function argSigToJsonSchemaType(t: string | { resourcetype: string }, s: SchemaProperty): void { if (t === 'int') { s.type = 'integer' } else if (t === 'float') { @@ -63,6 +63,9 @@ function pythonToJsonSchemaType(t: string, s: SchemaProperty): void { } else if (t === 'datetime') { s.type = 'string' s.format = 'date-time' + } else if (typeof t !== 'string' && t.resourcetype != undefined) { + s.type = 'object' + s.format = `resource-${t.resourcetype}` } else { s.type = undefined }