From 7ce8298dc64d315b5ac92839b7ce401482bca2c3 Mon Sep 17 00:00:00 2001 From: Matt Fulp <8397318+fulpm@users.noreply.github.com> Date: Thu, 3 Oct 2024 13:52:43 -0400 Subject: [PATCH] correct isSchema type guard for type lists --- codegen/engine.ts | 2 +- codegen/filters/types.ts | 32 ++++++++++++++++++--------- src/types/schemas/BuiltInFeatures.ts | 2 +- src/types/schemas/CopySubtrainee.ts | 2 +- src/types/schemas/CreateSubtrainee.ts | 2 +- src/types/schemas/DeleteSubtrainee.ts | 2 +- src/types/schemas/LoadSubtrainee.ts | 2 +- src/types/schemas/SaveSubtrainee.ts | 2 +- src/types/schemas/SetMetadata.ts | 2 +- 9 files changed, 29 insertions(+), 19 deletions(-) diff --git a/codegen/engine.ts b/codegen/engine.ts index 1d24a11..22d4628 100644 --- a/codegen/engine.ts +++ b/codegen/engine.ts @@ -106,7 +106,7 @@ export function isSchema(value: SchemaType | Schema | Ref | null | undefined): v if (value == null || Array.isArray(value) || typeof value === "string") { return false; } - return !isRef(value) && "type" in value && typeof value.type === "string"; + return !isRef(value) && "type" in value && (typeof value.type === "string" || Array.isArray(value.type)); } export function isSchemaOrRef(value: SchemaType | Schema | Ref | boolean | null | undefined): value is Schema | Ref { diff --git a/codegen/filters/types.ts b/codegen/filters/types.ts index 235a75a..4a3ef1a 100644 --- a/codegen/filters/types.ts +++ b/codegen/filters/types.ts @@ -8,24 +8,34 @@ export function isArray(value: any) { return Array.isArray(value); } -export function convertType(value: SchemaType) { - switch (value) { +export function convertType(schema: SchemaType) { + let value: string; + switch (schema) { case "assoc": - return "object"; + value = "Record"; + break; case "list": - return "any[]"; + value = "any[]"; + break; case "string": - return "string"; + value = "string"; + break; case "boolean": - return "boolean"; + value = "boolean"; + break; case "number": - return "number"; + value = "number"; + break; case "null": - return "null"; + value = "null"; + break; case "any": - return "any"; + value = "any"; + break; default: - console.warn(`Unexpected type received: ${value}`); - return "any"; + console.warn(`Unexpected type received: ${schema}`); + value = "any"; } + + return this.env.filters.safe(value); } diff --git a/src/types/schemas/BuiltInFeatures.ts b/src/types/schemas/BuiltInFeatures.ts index cdb5088..f665d69 100644 --- a/src/types/schemas/BuiltInFeatures.ts +++ b/src/types/schemas/BuiltInFeatures.ts @@ -17,7 +17,7 @@ export type BuiltInFeatures = { /** * The list of features that have been imputed for the case. */ - ".imputed"?: any[] | null; + ".imputed"?: string[] | null; /** * The normalized influence of a case on a prediction. */ diff --git a/src/types/schemas/CopySubtrainee.ts b/src/types/schemas/CopySubtrainee.ts index 2fa0107..4d1736f 100644 --- a/src/types/schemas/CopySubtrainee.ts +++ b/src/types/schemas/CopySubtrainee.ts @@ -32,5 +32,5 @@ export type CopySubtraineeRequest = { /** * Name of new copied trainee */ - target_trainee: string | any[]; + target_trainee: string | string[]; }; diff --git a/src/types/schemas/CreateSubtrainee.ts b/src/types/schemas/CreateSubtrainee.ts index efa21d5..e3a9c23 100644 --- a/src/types/schemas/CreateSubtrainee.ts +++ b/src/types/schemas/CreateSubtrainee.ts @@ -16,7 +16,7 @@ export type CreateSubtraineeRequest = { * Name of trainee to create * @default "" */ - trainee?: string | any[]; + trainee?: string | string[]; /** * Unique id for trainee diff --git a/src/types/schemas/DeleteSubtrainee.ts b/src/types/schemas/DeleteSubtrainee.ts index 3e16e09..12cac82 100644 --- a/src/types/schemas/DeleteSubtrainee.ts +++ b/src/types/schemas/DeleteSubtrainee.ts @@ -10,5 +10,5 @@ export type DeleteSubtraineeRequest = { /** * Name path of trainee */ - trainee: string | any[]; + trainee: string | string[]; }; diff --git a/src/types/schemas/LoadSubtrainee.ts b/src/types/schemas/LoadSubtrainee.ts index 84c921e..c9d80f8 100644 --- a/src/types/schemas/LoadSubtrainee.ts +++ b/src/types/schemas/LoadSubtrainee.ts @@ -33,5 +33,5 @@ export type LoadSubtraineeRequest = { * Name path of trainee to load * @default "" */ - trainee?: string | any[]; + trainee?: string | string[]; }; diff --git a/src/types/schemas/SaveSubtrainee.ts b/src/types/schemas/SaveSubtrainee.ts index 77d977b..10c5632 100644 --- a/src/types/schemas/SaveSubtrainee.ts +++ b/src/types/schemas/SaveSubtrainee.ts @@ -29,7 +29,7 @@ export type SaveSubtraineeRequest = { * Trainee instance name path to store * @default "" */ - trainee?: string | any[]; + trainee?: string | string[]; /** * Unique id for trainee. must be provided if trainee does not have one already specified. diff --git a/src/types/schemas/SetMetadata.ts b/src/types/schemas/SetMetadata.ts index 627c0ec..5c4f974 100644 --- a/src/types/schemas/SetMetadata.ts +++ b/src/types/schemas/SetMetadata.ts @@ -10,5 +10,5 @@ export type SetMetadataRequest = { /** * Arbitary map of metadata to store in a trainee */ - metadata: object | null; + metadata: Record | null; };