From 26d7b234ec68370e6ad6baa766667f63dac504c5 Mon Sep 17 00:00:00 2001 From: Jeongho Nam Date: Tue, 17 Dec 2024 10:16:00 +0900 Subject: [PATCH] Fix missed LLM type checking cases: tuple type --- package.json | 2 +- packages/core/package.json | 4 +- .../src/programmers/TypedBodyProgrammer.ts | 3 +- .../programmers/TypedQueryBodyProgrammer.ts | 66 ++++++++++--------- .../src/programmers/TypedQueryProgrammer.ts | 64 ++++++++++-------- .../programmers/TypedQueryRouteProgrammer.ts | 64 ++++++++++-------- .../src/programmers/TypedRouteProgrammer.ts | 3 +- .../internal/LlmValidatePredicator.ts | 16 ----- packages/fetcher/package.json | 2 +- packages/sdk/package.json | 6 +- 10 files changed, 115 insertions(+), 115 deletions(-) delete mode 100644 packages/core/src/programmers/internal/LlmValidatePredicator.ts diff --git a/package.json b/package.json index f3f1295ee..df6c12930 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "private": true, "name": "@nestia/station", - "version": "4.4.1", + "version": "4.4.2", "description": "Nestia station", "scripts": { "build": "node deploy build", diff --git a/packages/core/package.json b/packages/core/package.json index 919c59a51..1edade749 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@nestia/core", - "version": "4.4.1-dev.20241216", + "version": "4.4.2-dev.20241217", "description": "Super-fast validation decorators of NestJS", "main": "lib/index.js", "typings": "lib/index.d.ts", @@ -52,7 +52,7 @@ "ws": "^7.5.3" }, "peerDependencies": { - "@nestia/fetcher": ">=4.4.1-dev.20241216", + "@nestia/fetcher": ">=4.4.2-dev.20241217", "@nestjs/common": ">=7.0.1", "@nestjs/core": ">=7.0.1", "reflect-metadata": ">=0.1.12", diff --git a/packages/core/src/programmers/TypedBodyProgrammer.ts b/packages/core/src/programmers/TypedBodyProgrammer.ts index 8968bdae8..1137791b8 100644 --- a/packages/core/src/programmers/TypedBodyProgrammer.ts +++ b/packages/core/src/programmers/TypedBodyProgrammer.ts @@ -12,7 +12,6 @@ import { ITypiaContext } from "typia/lib/transformers/ITypiaContext"; import { INestiaTransformContext } from "../options/INestiaTransformProject"; import { IRequestBodyValidator } from "../options/IRequestBodyValidator"; -import { LlmValidatePredicator } from "./internal/LlmValidatePredicator"; export namespace TypedBodyProgrammer { export const generate = (props: { @@ -26,7 +25,7 @@ export namespace TypedBodyProgrammer { checker: props.context.checker, transformer: props.context.transformer, type: props.type, - validate: LlmValidatePredicator.is(props.context.options.llm) + validate: props.context.options.llm ? LlmSchemaProgrammer.validate({ model: props.context.options.llm.model, config: { diff --git a/packages/core/src/programmers/TypedQueryBodyProgrammer.ts b/packages/core/src/programmers/TypedQueryBodyProgrammer.ts index 421fa48ef..5d1d4f1de 100644 --- a/packages/core/src/programmers/TypedQueryBodyProgrammer.ts +++ b/packages/core/src/programmers/TypedQueryBodyProgrammer.ts @@ -1,3 +1,4 @@ +import { ILlmSchema } from "@samchon/openapi"; import ts from "typescript"; import { MetadataCollection } from "typia/lib/factories/MetadataCollection"; import { MetadataFactory } from "typia/lib/factories/MetadataFactory"; @@ -6,12 +7,14 @@ import { HttpIsQueryProgrammer } from "typia/lib/programmers/http/HttpIsQueryPro import { HttpQueryProgrammer } from "typia/lib/programmers/http/HttpQueryProgrammer"; import { HttpValidateQueryProgrammer } from "typia/lib/programmers/http/HttpValidateQueryProgrammer"; import { LlmSchemaProgrammer } from "typia/lib/programmers/llm/LlmSchemaProgrammer"; +import { Metadata } from "typia/lib/schemas/metadata/Metadata"; import { ITypiaContext } from "typia/lib/transformers/ITypiaContext"; import { TransformerError } from "typia/lib/transformers/TransformerError"; +import { ValidationPipe } from "typia/lib/typings/ValidationPipe"; +import { INestiaTransformOptions } from "../options/INestiaTransformOptions"; import { INestiaTransformContext } from "../options/INestiaTransformProject"; import { IRequestQueryValidator } from "../options/IRequestQueryValidator"; -import { LlmValidatePredicator } from "./internal/LlmValidatePredicator"; export namespace TypedQueryBodyProgrammer { export const generate = (props: { @@ -20,38 +23,41 @@ export namespace TypedQueryBodyProgrammer { type: ts.Type; }): ts.ObjectLiteralExpression => { // VALIDATE TYPE - if (LlmValidatePredicator.is(props.context.options.llm)) { - const result = MetadataFactory.analyze({ - checker: props.context.checker, - transformer: props.context.transformer, - options: { - escape: false, - constant: true, - absorb: true, - validate: (meta, explore) => { - const errors: string[] = HttpQueryProgrammer.validate( - meta, - explore, - true, - ); - errors.push( - ...LlmSchemaProgrammer.validate({ - model: props.context.options.llm!.model, - config: { - strict: props.context.options.llm!.strict, - recursive: props.context.options.llm!.recursive, - }, - })(meta), - ); - return errors; + if (props.context.options.llm) { + const llm: INestiaTransformOptions.ILlm = + props.context.options.llm; + const result: ValidationPipe = + MetadataFactory.analyze({ + checker: props.context.checker, + transformer: props.context.transformer, + options: { + escape: false, + constant: true, + absorb: true, + validate: (meta, explore) => { + const errors: string[] = HttpQueryProgrammer.validate( + meta, + explore, + true, + ); + errors.push( + ...LlmSchemaProgrammer.validate({ + model: llm.model, + config: { + strict: llm.strict, + recursive: llm.recursive, + }, + })(meta), + ); + return errors; + }, }, - }, - collection: new MetadataCollection(), - type: props.type, - }); + collection: new MetadataCollection(), + type: props.type, + }); if (result.success === false) throw TransformerError.from({ - code: "@nestia.core.TypedQuery.Body", + code: props.modulo.getText(), errors: result.errors, }); } diff --git a/packages/core/src/programmers/TypedQueryProgrammer.ts b/packages/core/src/programmers/TypedQueryProgrammer.ts index 5ccd80b3b..2abfc61a4 100644 --- a/packages/core/src/programmers/TypedQueryProgrammer.ts +++ b/packages/core/src/programmers/TypedQueryProgrammer.ts @@ -1,3 +1,4 @@ +import { ILlmSchema } from "@samchon/openapi"; import ts from "typescript"; import { MetadataCollection } from "typia/lib/factories/MetadataCollection"; import { MetadataFactory } from "typia/lib/factories/MetadataFactory"; @@ -6,12 +7,14 @@ import { HttpIsQueryProgrammer } from "typia/lib/programmers/http/HttpIsQueryPro import { HttpQueryProgrammer } from "typia/lib/programmers/http/HttpQueryProgrammer"; import { HttpValidateQueryProgrammer } from "typia/lib/programmers/http/HttpValidateQueryProgrammer"; import { LlmSchemaProgrammer } from "typia/lib/programmers/llm/LlmSchemaProgrammer"; +import { Metadata } from "typia/lib/schemas/metadata/Metadata"; import { ITypiaContext } from "typia/lib/transformers/ITypiaContext"; import { TransformerError } from "typia/lib/transformers/TransformerError"; +import { ValidationPipe } from "typia/lib/typings/ValidationPipe"; +import { INestiaTransformOptions } from "../options/INestiaTransformOptions"; import { INestiaTransformContext } from "../options/INestiaTransformProject"; import { IRequestQueryValidator } from "../options/IRequestQueryValidator"; -import { LlmValidatePredicator } from "./internal/LlmValidatePredicator"; export namespace TypedQueryProgrammer { export const generate = (props: { @@ -20,35 +23,38 @@ export namespace TypedQueryProgrammer { type: ts.Type; }): ts.Expression => { // VALIDATE TYPE - if (LlmValidatePredicator.is(props.context.options.llm)) { - const result = MetadataFactory.analyze({ - checker: props.context.checker, - transformer: props.context.transformer, - options: { - escape: false, - constant: true, - absorb: true, - validate: (meta, explore) => { - const errors: string[] = HttpQueryProgrammer.validate( - meta, - explore, - true, - ); - errors.push( - ...LlmSchemaProgrammer.validate({ - model: props.context.options.llm!.model, - config: { - strict: props.context.options.llm!.strict, - recursive: props.context.options.llm!.recursive, - }, - })(meta), - ); - return errors; + if (props.context.options.llm) { + const llm: INestiaTransformOptions.ILlm = + props.context.options.llm; + const result: ValidationPipe = + MetadataFactory.analyze({ + checker: props.context.checker, + transformer: props.context.transformer, + options: { + escape: false, + constant: true, + absorb: true, + validate: (meta, explore) => { + const errors: string[] = HttpQueryProgrammer.validate( + meta, + explore, + true, + ); + errors.push( + ...LlmSchemaProgrammer.validate({ + model: llm.model, + config: { + strict: llm.strict, + recursive: llm.recursive, + }, + })(meta), + ); + return errors; + }, }, - }, - collection: new MetadataCollection(), - type: props.type, - }); + collection: new MetadataCollection(), + type: props.type, + }); if (result.success === false) throw TransformerError.from({ code: "@nestia.core.TypedQuery", diff --git a/packages/core/src/programmers/TypedQueryRouteProgrammer.ts b/packages/core/src/programmers/TypedQueryRouteProgrammer.ts index 44d786b7d..ae8624352 100644 --- a/packages/core/src/programmers/TypedQueryRouteProgrammer.ts +++ b/packages/core/src/programmers/TypedQueryRouteProgrammer.ts @@ -1,17 +1,20 @@ +import { ILlmSchema } from "@samchon/openapi"; import ts from "typescript"; import { MetadataCollection } from "typia/lib/factories/MetadataCollection"; import { MetadataFactory } from "typia/lib/factories/MetadataFactory"; import { HttpQueryProgrammer } from "typia/lib/programmers/http/HttpQueryProgrammer"; import { LlmSchemaProgrammer } from "typia/lib/programmers/llm/LlmSchemaProgrammer"; +import { Metadata } from "typia/lib/schemas/metadata/Metadata"; import { ITypiaContext } from "typia/lib/transformers/ITypiaContext"; import { TransformerError } from "typia/lib/transformers/TransformerError"; +import { ValidationPipe } from "typia/lib/typings/ValidationPipe"; +import { INestiaTransformOptions } from "../options/INestiaTransformOptions"; import { INestiaTransformContext } from "../options/INestiaTransformProject"; import { HttpAssertQuerifyProgrammer } from "./http/HttpAssertQuerifyProgrammer"; import { HttpIsQuerifyProgrammer } from "./http/HttpIsQuerifyProgrammer"; import { HttpQuerifyProgrammer } from "./http/HttpQuerifyProgrammer"; import { HttpValidateQuerifyProgrammer } from "./http/HttpValidateQuerifyProgrammer"; -import { LlmValidatePredicator } from "./internal/LlmValidatePredicator"; export namespace TypedQueryRouteProgrammer { export const generate = (props: { @@ -20,35 +23,38 @@ export namespace TypedQueryRouteProgrammer { type: ts.Type; }): ts.Expression => { // VALIDATE TYPE - if (LlmValidatePredicator.is(props.context.options.llm)) { - const result = MetadataFactory.analyze({ - checker: props.context.checker, - transformer: props.context.transformer, - options: { - escape: false, - constant: true, - absorb: true, - validate: (meta, explore) => { - const errors: string[] = HttpQueryProgrammer.validate( - meta, - explore, - true, - ); - errors.push( - ...LlmSchemaProgrammer.validate({ - model: props.context.options.llm!.model, - config: { - strict: props.context.options.llm!.strict, - recursive: props.context.options.llm!.recursive, - }, - })(meta), - ); - return errors; + if (props.context.options.llm) { + const llm: INestiaTransformOptions.ILlm = + props.context.options.llm; + const result: ValidationPipe = + MetadataFactory.analyze({ + checker: props.context.checker, + transformer: props.context.transformer, + options: { + escape: false, + constant: true, + absorb: true, + validate: (meta, explore) => { + const errors: string[] = HttpQueryProgrammer.validate( + meta, + explore, + true, + ); + errors.push( + ...LlmSchemaProgrammer.validate({ + model: llm.model, + config: { + strict: llm.strict, + recursive: llm.recursive, + }, + })(meta), + ); + return errors; + }, }, - }, - collection: new MetadataCollection(), - type: props.type, - }); + collection: new MetadataCollection(), + type: props.type, + }); if (result.success === false) throw TransformerError.from({ code: props.modulo.getText(), diff --git a/packages/core/src/programmers/TypedRouteProgrammer.ts b/packages/core/src/programmers/TypedRouteProgrammer.ts index e10ac43fc..81b70124b 100644 --- a/packages/core/src/programmers/TypedRouteProgrammer.ts +++ b/packages/core/src/programmers/TypedRouteProgrammer.ts @@ -8,7 +8,6 @@ import { LlmSchemaProgrammer } from "typia/lib/programmers/llm/LlmSchemaProgramm import { IProgrammerProps } from "typia/lib/transformers/IProgrammerProps"; import { INestiaTransformContext } from "../options/INestiaTransformProject"; -import { LlmValidatePredicator } from "./internal/LlmValidatePredicator"; export namespace TypedRouteProgrammer { export const generate = (props: { @@ -17,7 +16,7 @@ export namespace TypedRouteProgrammer { type: ts.Type; }): ts.Expression => { // VALIDATE TYPE - if (LlmValidatePredicator.is(props.context.options.llm)) + if (props.context.options.llm) JsonMetadataFactory.analyze({ method: "@nestia.core.TypedBody", checker: props.context.checker, diff --git a/packages/core/src/programmers/internal/LlmValidatePredicator.ts b/packages/core/src/programmers/internal/LlmValidatePredicator.ts deleted file mode 100644 index b396d2dcf..000000000 --- a/packages/core/src/programmers/internal/LlmValidatePredicator.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { ILlmSchema } from "@samchon/openapi"; - -import { INestiaTransformOptions } from "../../options/INestiaTransformOptions"; - -export namespace LlmValidatePredicator { - export const is = ( - llm: INestiaTransformOptions.ILlm | undefined, - ): llm is INestiaTransformOptions.ILlm => { - if (llm?.model === undefined) return false; - else if (llm.model === "chatgpt") return llm.strict === true; - else if (llm.model === "gemini") return true; - else if (llm.model === "3.0") - return llm.recursive === false || llm.recursive === 0; - return false; - }; -} diff --git a/packages/fetcher/package.json b/packages/fetcher/package.json index a5f3a275a..7228b5ca2 100644 --- a/packages/fetcher/package.json +++ b/packages/fetcher/package.json @@ -1,6 +1,6 @@ { "name": "@nestia/fetcher", - "version": "4.4.1-dev.20241216", + "version": "4.4.2-dev.20241217", "description": "Fetcher library of Nestia SDK", "main": "lib/index.js", "typings": "lib/index.d.ts", diff --git a/packages/sdk/package.json b/packages/sdk/package.json index b0e6a2e8b..2da8161dc 100644 --- a/packages/sdk/package.json +++ b/packages/sdk/package.json @@ -1,6 +1,6 @@ { "name": "@nestia/sdk", - "version": "4.4.1-dev.20241216", + "version": "4.4.2-dev.20241217", "description": "Nestia SDK and Swagger generator", "main": "lib/index.js", "typings": "lib/index.d.ts", @@ -47,8 +47,8 @@ "typia": "^7.4.1" }, "peerDependencies": { - "@nestia/core": ">=4.4.1-dev.20241216", - "@nestia/fetcher": ">=4.4.1-dev.20241216", + "@nestia/core": ">=4.4.2-dev.20241217", + "@nestia/fetcher": ">=4.4.2-dev.20241217", "@nestjs/common": ">=7.0.1", "@nestjs/core": ">=7.0.1", "reflect-metadata": ">=0.1.12",