Skip to content

Commit

Permalink
feat: optimize rawQuery object validation in api.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
lncitador committed Jun 10, 2024
1 parent f4fccb2 commit 9e4e7d9
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/adonis/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
"@release-it/bumper": {
"out": {
"file": "package.json",
"prefix": "^",
"versionPrefix": "^",
"path": [
"peerDependencies.@cel_cash/core"
]
Expand Down
2 changes: 1 addition & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"@release-it/bumper": {
"out": {
"file": "package.json",
"prefix": "^",
"versionPrefix": "^",
"path": [
"peerDependencies.@cel_cash/core"
]
Expand Down
14 changes: 5 additions & 9 deletions packages/core/src/utils/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion packages/nest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"@release-it/bumper": {
"out": {
"file": "package.json",
"prefix": "^",
"versionPrefix": "^",
"path": [
"peerDependencies.@cel_cash/core"
]
Expand Down

0 comments on commit 9e4e7d9

Please sign in to comment.