Skip to content

Commit

Permalink
refactor(#285): Rename DEBUG_WALK_SHAPE to match function name
Browse files Browse the repository at this point in the history
Co-Authored-By: Carol Soliman <17387510+carsoli@users.noreply.github.com>
  • Loading branch information
FlorianWendelborn and carsoli committed Sep 24, 2021
1 parent 1e70461 commit 4e21270
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions packages/kotti-ui/source/make-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { cloneDeep } from 'lodash'
import { z } from 'zod'

const DEBUG_MAKE_PROPS = false as const // enable to print debug log
const DEBUG_WALK_SHAPE = false as const // enable to print debug log
const DEBUG_WALK_SCHEMA_TYPES = false as const // enable to print debug log

/**
* This type is not exported directly by @vue/composition-api
Expand Down Expand Up @@ -60,19 +60,20 @@ const walkSchemaTypes = <SCHEMA extends z.ZodTypeAny>(
/* eslint-disable no-console */
const typeName = schema._def.typeName as z.ZodFirstPartyTypeKind

if (DEBUG_WALK_SHAPE)
if (DEBUG_WALK_SCHEMA_TYPES)
console.log(`walkSchemaTypes: found “ZodFirstPartyTypeKind.${typeName}”`)

switch (typeName) {
case z.ZodFirstPartyTypeKind.ZodUnion: {
const { options } = schema._def as z.ZodUnionDef

if (DEBUG_WALK_SHAPE) console.group('walkSchemaTypes: walking union')
if (DEBUG_WALK_SCHEMA_TYPES)
console.group('walkSchemaTypes: walking union')

// walk every option in the union and merge results
const result = setUnion(...options.map((x) => walkSchemaTypes(x)))

if (DEBUG_WALK_SHAPE) console.groupEnd()
if (DEBUG_WALK_SCHEMA_TYPES) console.groupEnd()

return result
}
Expand All @@ -85,7 +86,7 @@ const walkSchemaTypes = <SCHEMA extends z.ZodTypeAny>(
| z.ZodNullableDef
| z.ZodOptionalDef

if (DEBUG_WALK_SHAPE)
if (DEBUG_WALK_SCHEMA_TYPES)
console.log(
`walkSchemaTypes: walking innerType of “ZodFirstPartyTypeKind.${typeName}”`,
)
Expand All @@ -103,7 +104,7 @@ const walkSchemaTypes = <SCHEMA extends z.ZodTypeAny>(
case z.ZodFirstPartyTypeKind.ZodNumber:
case z.ZodFirstPartyTypeKind.ZodObject:
case z.ZodFirstPartyTypeKind.ZodString: {
if (DEBUG_WALK_SHAPE)
if (DEBUG_WALK_SCHEMA_TYPES)
console.log(
`walkSchemaTypes: adding “ZodFirstPartyTypeKind.${typeName}”`,
)
Expand Down

0 comments on commit 4e21270

Please sign in to comment.