From 9e4e7d9567599ab13eb3bc00c72077d4a0efd6bb Mon Sep 17 00:00:00 2001 From: Walaff Fernandes Date: Mon, 10 Jun 2024 17:24:27 -0300 Subject: [PATCH] feat: optimize rawQuery object validation in api.ts --- packages/adonis/package.json | 2 +- packages/client/package.json | 2 +- packages/core/src/utils/api.ts | 14 +++++--------- packages/nest/package.json | 2 +- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/packages/adonis/package.json b/packages/adonis/package.json index 6e97ba5..0c41082 100644 --- a/packages/adonis/package.json +++ b/packages/adonis/package.json @@ -92,7 +92,7 @@ "@release-it/bumper": { "out": { "file": "package.json", - "prefix": "^", + "versionPrefix": "^", "path": [ "peerDependencies.@cel_cash/core" ] diff --git a/packages/client/package.json b/packages/client/package.json index 31c8e5f..c2019a8 100644 --- a/packages/client/package.json +++ b/packages/client/package.json @@ -56,7 +56,7 @@ "@release-it/bumper": { "out": { "file": "package.json", - "prefix": "^", + "versionPrefix": "^", "path": [ "peerDependencies.@cel_cash/core" ] diff --git a/packages/core/src/utils/api.ts b/packages/core/src/utils/api.ts index ee15a84..a00b6af 100644 --- a/packages/core/src/utils/api.ts +++ b/packages/core/src/utils/api.ts @@ -48,16 +48,12 @@ export const api = async ( (!!args.route.query && args.route.query instanceof ZodObject) || (!!args.route.query && args.route.query instanceof ZodEffects) ) { + const entries = Object.entries(args.rawQuery || {}).filter( + ([_, v]) => !['', null, undefined].includes(v), + ) + const validation = args.route.query.safeParse( - Object.fromEntries( - Object.entries(args.rawQuery || {}).filter(([_, v]) => - typeof v === 'string' - ? v.length > 0 - : typeof v === 'undefined' - ? false - : true, - ), - ), + Object.fromEntries(entries), ) if (validation.success) { diff --git a/packages/nest/package.json b/packages/nest/package.json index cdf680f..c3fad8a 100644 --- a/packages/nest/package.json +++ b/packages/nest/package.json @@ -59,7 +59,7 @@ "@release-it/bumper": { "out": { "file": "package.json", - "prefix": "^", + "versionPrefix": "^", "path": [ "peerDependencies.@cel_cash/core" ]