Skip to content

Commit

Permalink
function -> const
Browse files Browse the repository at this point in the history
  • Loading branch information
mxsdev committed Aug 11, 2023
1 parent 6beafc5 commit e9b6976
Showing 1 changed file with 25 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,31 @@ const getZodDefFromZodSchemaHelpers = (schema: z.ZodTypeAny) => {
return schema._def
}

const tryGetZodSchemaAsObject = (
schema: z.ZodTypeAny
): z.ZodObject<any> | undefined => {
const isZodEffect = schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects
const safe_schema = getZodObjectSchemaFromZodEffectSchema(isZodEffect, schema)
const isZodObject =
safe_schema._def.typeName === ZodFirstPartyTypeKind.ZodObject

if (!isZodObject) {
return undefined
}

return safe_schema as z.ZodObject<any>
}

const isZodSchemaArray = (schema: z.ZodTypeAny) => {
const def = getZodDefFromZodSchemaHelpers(schema)
return def.typeName === ZodFirstPartyTypeKind.ZodArray
}

const isZodSchemaBoolean = (schema: z.ZodTypeAny) => {
const def = getZodDefFromZodSchemaHelpers(schema)
return def.typeName === ZodFirstPartyTypeKind.ZodBoolean
}

const parseQueryParams = (
schema: z.ZodTypeAny,
input: Record<string, unknown>,
Expand Down Expand Up @@ -106,31 +131,6 @@ const parseQueryParams = (
return schema.parse(parsed_input)
}

function tryGetZodSchemaAsObject(
schema: z.ZodTypeAny
): z.ZodObject<any> | undefined {
const isZodEffect = schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects
const safe_schema = getZodObjectSchemaFromZodEffectSchema(isZodEffect, schema)
const isZodObject =
safe_schema._def.typeName === ZodFirstPartyTypeKind.ZodObject

if (!isZodObject) {
return undefined
}

return safe_schema as z.ZodObject<any>
}

function isZodSchemaArray(schema: z.ZodTypeAny) {
const def = getZodDefFromZodSchemaHelpers(schema)
return def.typeName === ZodFirstPartyTypeKind.ZodArray
}

function isZodSchemaBoolean(schema: z.ZodTypeAny) {
const def = getZodDefFromZodSchemaHelpers(schema)
return def.typeName === ZodFirstPartyTypeKind.ZodBoolean
}

const validateQueryParams = (
inputUrl: string,
schema: z.ZodTypeAny,
Expand Down

0 comments on commit e9b6976

Please sign in to comment.