Skip to content

Commit

Permalink
Merge pull request #198 from samchon/features/json
Browse files Browse the repository at this point in the history
Close #196 - allow `TypedRoute` to use native `JSON.stringify()`
  • Loading branch information
samchon authored Dec 20, 2022
2 parents 38edac4 + b5657fe commit 491e0b0
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 deletions.
4 changes: 2 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nestia/core",
"version": "1.0.0",
"version": "1.0.1",
"description": "Super-fast validation decorators of NestJS",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down Expand Up @@ -58,7 +58,7 @@
"raw-body": "*",
"reflect-metadata": "*",
"rxjs": "*",
"typia": "^3.4.7"
"typia": "^3.4.11"
},
"peerDependencies": {
"ttypescript": ">= 1.5.15",
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/decorators/EncryptedRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ export namespace EncryptedRoute {
function Generator(method: "Get" | "Post" | "Put" | "Patch" | "Delete") {
function route(path?: string | string[]): MethodDecorator;
function route<T>(
stringify?: IResponseBodyStringifier<T>,
stringify?: IResponseBodyStringifier<T> | null,
): MethodDecorator;
function route<T>(
path: string | string[],
stringify?: IResponseBodyStringifier<T>,
stringify?: IResponseBodyStringifier<T> | null,
): MethodDecorator;

function route(...args: any[]): MethodDecorator {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ export const get_path_and_stringify =

const take =
(method: string) =>
<T>(functor?: IResponseBodyStringifier<T>) => {
<T>(functor?: IResponseBodyStringifier<T> | null) => {
if (functor === undefined)
throw new Error(
`Error on nestia.core.${method}(): no stringify function provided.`,
);
else if (functor === null) return JSON.stringify;
else if (functor.type === "stringify") return functor.stringify;
else if (functor.type === "assert") return assert(functor.assert);
else if (functor.type === "is") return is(functor.is);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/options/INestiaTransformOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import { ITransformOptions } from "typia/lib/transformers/ITransformOptions";

export interface INestiaTransformOptions extends ITransformOptions {
validate?: "assert" | "is" | "validate";
stringify?: "stringify" | "assert" | "is" | "validate";
stringify?: "stringify" | "assert" | "is" | "validate" | null;
}
4 changes: 3 additions & 1 deletion packages/core/src/transformers/RouteTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export namespace RouteTransformer {
programmer(project, expression.expression)(type),
),
]);
const stringify: ts.ObjectLiteralExpression = (() => {
const stringify: ts.Expression = (() => {
if (project.options.stringify === "stringify")
return parameter("stringify", StringifyProgrammer.generate);
else if (project.options.stringify === "assert")
Expand All @@ -93,6 +93,8 @@ export namespace RouteTransformer {
"validate",
ValidateStringifyProgrammer.generate,
);
else if (project.options.stringify === null)
return ts.factory.createNull();
return parameter("is", IsStringifyProgrammer.generate);
})();

Expand Down

0 comments on commit 491e0b0

Please sign in to comment.