Summary
In packages/validation/api.ts, three threshold fields use a .refine() that
checks v === undefined, but this branch is unreachable, and a .transform(Number)
that is a no-op.
Affected fields:
SearchRequestSchema.chunkThreshold
SearchRequestSchema.documentThreshold
Searchv4RequestSchema.threshold
Why the code is dead
Each field is defined as:
z.number().optional().default(0).refine((v) => v === undefined || (v >= 0 && v <= 1), {...}).transform(Number)
Zod applies .default() before downstream processing. When the field is omitted,
the parsed input is undefined, .default(0) replaces it with 0, and only then
does .refine() run. So v is always a number, never undefined, the
v === undefined || branch can never execute.
Additionally, .transform(Number) runs on a value that is already z.number(),
so it is a no-op.
Question before I open a PR
Happy to submit a PR removing the dead v === undefined checks and the redundant
.transform(Number) across all three fields. Before I do:
Is the .default(0) intentional? If "unset" is meant to be distinguishable from
an explicit 0, that may be worth addressing separately, otherwise I'll keep the
cleanup purely to the dead code and leave the defaults as-is.
Summary
In
packages/validation/api.ts, three threshold fields use a.refine()thatchecks
v === undefined, but this branch is unreachable, and a.transform(Number)that is a no-op.
Affected fields:
SearchRequestSchema.chunkThresholdSearchRequestSchema.documentThresholdSearchv4RequestSchema.thresholdWhy the code is dead
Each field is defined as:
Zod applies
.default()before downstream processing. When the field is omitted,the parsed input is
undefined,.default(0)replaces it with0, and only thendoes
.refine()run. Sovis always a number, neverundefined, thev === undefined ||branch can never execute.Additionally,
.transform(Number)runs on a value that is alreadyz.number(),so it is a no-op.
Question before I open a PR
Happy to submit a PR removing the dead
v === undefinedchecks and the redundant.transform(Number)across all three fields. Before I do:Is the
.default(0)intentional? If "unset" is meant to be distinguishable froman explicit
0, that may be worth addressing separately, otherwise I'll keep thecleanup purely to the dead code and leave the defaults as-is.