Skip to content

Commit

Permalink
fix(cli): update CLI schema parsers to latest
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenfiszel committed Sep 16, 2024
1 parent 692c1dc commit b8152b2
Show file tree
Hide file tree
Showing 9 changed files with 154 additions and 103 deletions.
52 changes: 20 additions & 32 deletions backend/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ rsmq_async = { version = "5.1.5" }
gosyn = "0.2.6"
bytes = "1.4.0"
gethostname = "0.4.3"
wasm-bindgen = "0.2.92"
wasm-bindgen = "=0.2.92"
serde-wasm-bindgen = "0.6.5"
wasm-bindgen-test = "0.3.42"
convert_case = "0.6.0"
Expand Down
4 changes: 3 additions & 1 deletion cli/bootstrap/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ export interface SchemaProperty {
contentEncoding?: "base64" | "binary";
format?: string;
items?: {
type?: "string" | "number" | "bytes" | "object";
type?: "string" | "number" | "bytes" | "object" | "resource";
contentEncoding?: "base64";
enum?: string[];
resourceType?: string;
properties?: { [name: string]: SchemaProperty };
};
min?: number;
max?: number;
Expand Down
37 changes: 35 additions & 2 deletions cli/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -530,17 +530,19 @@ function sortObject(obj: any): any {
);
}

//copied straight fron frontend /src/utils/inferArgs.ts
export function argSigToJsonSchemaType(
t:
| string
| { resource: string | null }
| {
list:
| string
| (string | { object: { key: string; typ: any }[] })
| { str: any }
| { object: { key: string; typ: any }[] }
| null;
}
| { dynselect: string }
| { str: string[] | null }
| { object: { key: string; typ: any }[] }
| {
Expand All @@ -553,7 +555,7 @@ export function argSigToJsonSchemaType(
},
oldS: SchemaProperty
): void {
let newS: SchemaProperty = { type: "" };
const newS: SchemaProperty = { type: "" };
if (t === "int") {
newS.type = "integer";
} else if (t === "float") {
Expand Down Expand Up @@ -618,13 +620,19 @@ export function argSigToJsonSchemaType(
if (t.str) {
newS.originalType = "enum";
newS.enum = t.str;
} else if (oldS.originalType == "string" && oldS.enum) {
newS.originalType = "string";
newS.enum = oldS.enum;
} else {
newS.originalType = "string";
newS.enum = undefined;
}
} else if (typeof t !== "string" && `resource` in t) {
newS.type = "object";
newS.format = `resource-${t.resource}`;
} else if (typeof t !== "string" && `dynselect` in t) {
newS.type = "object";
newS.format = `dynselect-${t.dynselect}`;
} else if (typeof t !== "string" && `list` in t) {
newS.type = "array";
if (t.list === "int" || t.list === "float") {
Expand All @@ -635,6 +643,31 @@ export function argSigToJsonSchemaType(
newS.items = { type: "string" };
} else if (t.list && typeof t.list == "object" && "str" in t.list) {
newS.items = { type: "string", enum: t.list.str };
} else if (
t.list &&
typeof t.list == "object" &&
"resource" in t.list &&
t.list.resource
) {
newS.items = {
type: "resource",
resourceType: t.list.resource as string,
};
} else if (
t.list &&
typeof t.list == "object" &&
"object" in t.list &&
t.list.object &&
t.list.object.length > 0
) {
const properties: Record<string, any> = {};
for (const prop of t.list.object) {
properties[prop.key] = { description: "", type: "" };

argSigToJsonSchemaType(prop.typ, properties[prop.key]);
}

newS.items = { type: "object", properties: properties };
} else {
newS.items = { type: "object" };
}
Expand Down
8 changes: 7 additions & 1 deletion cli/wasm/windmill_parser_wasm.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export interface InstantiateResult {
parse_mssql: typeof parse_mssql;
parse_db_resource: typeof parse_db_resource;
parse_graphql: typeof parse_graphql;
parse_php: typeof parse_php
parse_php: typeof parse_php;
parse_rust: typeof parse_rust
};
}

Expand Down Expand Up @@ -118,3 +119,8 @@ export function parse_graphql(code: string): string;
* @returns {string}
*/
export function parse_php(code: string): string;
/**
* @param {string} code
* @returns {string}
*/
export function parse_rust(code: string): string;
Loading

0 comments on commit b8152b2

Please sign in to comment.