Skip to content

Commit 0326d97

Browse files
committed
chore: reduce nested statement in generateSampleData
1 parent b393e67 commit 0326d97

1 file changed

Lines changed: 16 additions & 11 deletions

File tree

apps/web/src/utils/upload2.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -271,18 +271,21 @@ namespace Zod3 {
271271
case 'ZodObject':
272272
try {
273273
let multiString = 'RECORD_ARRAY( ';
274-
if (multiValues && multiKeys) {
275-
for (let i = 0; i < multiValues.length; i++) {
276-
const inputData = multiValues[i]!;
277-
// eslint-disable-next-line max-depth
278-
if (i === multiValues.length - 1 && multiValues[i] !== undefined) {
279-
multiString += multiKeys[i] + ':' + generateSampleData(inputData);
280-
} else {
281-
multiString += multiKeys[i] + ':' + generateSampleData(inputData) + ',';
282-
}
274+
if (!(multiValues && multiKeys)) {
275+
throw new UploadError({
276+
en: 'Record Array is empty or does not exist',
277+
fr: 'Erreur record array invalide'
278+
});
279+
}
280+
for (let i = 0; i < multiValues.length; i++) {
281+
const inputData = multiValues[i]!;
282+
if (i === multiValues.length - 1 && multiValues[i] !== undefined) {
283+
multiString += multiKeys[i] + ':' + generateSampleData(inputData);
284+
} else {
285+
multiString += multiKeys[i] + ':' + generateSampleData(inputData) + ',';
283286
}
284-
multiString += ';)';
285287
}
288+
multiString += ';)';
286289
return multiString;
287290
} catch (e) {
288291
throw new UploadError({
@@ -836,12 +839,14 @@ namespace Zod4 {
836839
fr: 'Structure de définition Zod v4 invalide'
837840
});
838841
}
842+
839843
if (!isObjectLike(def) || typeof def.type !== 'string') {
840844
throw new UploadError({
841845
en: 'Invalid Zod v4 definition structure',
842846
fr: 'Structure de définition Zod v4 invalide'
843847
});
844848
}
849+
845850
if (def.type === 'optional' && def.innerType) {
846851
return getZodTypeName(def.innerType, true);
847852
} else if (def.type === 'enum') {
@@ -896,7 +901,7 @@ namespace Zod4 {
896901
): Zod3.ZodTypeNameResult {
897902
const listOfZodElements: Zod3.ZodTypeNameResult[] = [];
898903
const listOfZodKeys: string[] = [];
899-
const castedDef = def as z4.core.$ZodAny;
904+
const castedDef = def as z4.core.$ZodObjectDef;
900905
if (!castedDef.element) {
901906
throw new UploadError({
902907
en: 'Failure to interpret Zod Object or Array',

0 commit comments

Comments
 (0)