Skip to content

Commit

Permalink
Remove copying mechanism which falsely suggests immutability
Browse files Browse the repository at this point in the history
In fact it's just a second reference to the same thing after the code
changes in the previous commit. So it would be better to avoid
suggesting that changes are safe.
  • Loading branch information
amcaplan committed Dec 10, 2024
1 parent fef9338 commit ae73505
Showing 1 changed file with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,18 @@ export async function writeAppConfigurationFile(configuration: CurrentAppConfigu
}

export const rewriteConfiguration = <T extends zod.ZodTypeAny>(schema: T, config: unknown): unknown => {
const configCopy = config

if (schema === null || schema === undefined) return null
if (schema instanceof zod.ZodNullable || schema instanceof zod.ZodOptional)
return rewriteConfiguration(schema.unwrap(), configCopy)
return rewriteConfiguration(schema.unwrap(), config)
if (schema instanceof zod.ZodArray) {
return (configCopy as unknown[]).map((item) => rewriteConfiguration(schema.element, item))
return (config as unknown[]).map((item) => rewriteConfiguration(schema.element, item))
}
if (schema instanceof zod.ZodEffects) {
return rewriteConfiguration(schema._def.schema, configCopy)
return rewriteConfiguration(schema._def.schema, config)
}
if (schema instanceof zod.ZodObject) {
const entries = Object.entries(schema.shape)
const confObj = configCopy as {[key: string]: unknown}
const confObj = config as {[key: string]: unknown}
let result: {[key: string]: unknown} = {}
entries.forEach(([key, subSchema]) => {
if (confObj !== undefined && confObj[key] !== undefined) {
Expand Down

0 comments on commit ae73505

Please sign in to comment.