@@ -62,10 +62,6 @@ type AnyZodTypeDef = z.ZodTypeDef & { typeName: ZodTypeName };
6262
6363type AnyZodArrayDef = z . ZodArrayDef & { type : z . AnyZodObject } ;
6464
65- function isZodObject ( value : unknown ) : value is z . AnyZodObject {
66- return isPlainObject ( value ) ;
67- }
68-
6965function isZodTypeDef ( value : unknown ) : value is AnyZodTypeDef {
7066 return isPlainObject ( value ) && ZOD_TYPE_NAMES . includes ( value . typeName as ZodTypeName ) ;
7167}
@@ -431,20 +427,16 @@ function generateSampleData({
431427export function createUploadTemplateCSV ( instrument : AnyUnilingualFormInstrument ) {
432428 // TODO - type validationSchema as object
433429 try {
434- //This needs to be tested!!!
435- if ( ! isZodObject ( instrument . validationSchema ) ) {
436- throw new Error ( 'Error in validation schema type' ) ;
437- }
438- const instrumentSchema = instrument . validationSchema ;
430+ const instrumentSchema = instrument . validationSchema as z . AnyZodObject ;
439431
440432 const instrumentSchemaDef : unknown = instrument . validationSchema . _def ;
441433
442434 let shape : { [ key : string ] : z . ZodTypeAny } = { } ;
443435
444436 if ( isZodTypeDef ( instrumentSchemaDef ) && isZodEffectsDef ( instrumentSchemaDef ) ) {
445- const innerSchema : unknown = instrumentSchemaDef . schema . _def ;
446- if ( isZodTypeDef ( innerSchema ) && isZodObjectDef ( innerSchema ) ) {
447- shape = innerSchema . shape ( ) as { [ key : string ] : z . ZodTypeAny } ;
437+ const innerSchemaDef : unknown = instrumentSchemaDef . schema . _def ;
438+ if ( isZodTypeDef ( innerSchemaDef ) && isZodObjectDef ( innerSchemaDef ) ) {
439+ shape = innerSchemaDef . shape ( ) as { [ key : string ] : z . ZodTypeAny } ;
448440 }
449441 } else {
450442 shape = instrumentSchema . shape as { [ key : string ] : z . ZodTypeAny } ;
@@ -473,6 +465,9 @@ export function createUploadTemplateCSV(instrument: AnyUnilingualFormInstrument)
473465 if ( e instanceof Error && e . message === 'Unsuccessful input data transfer or undefined data' ) {
474466 throw e ;
475467 }
468+ if ( e instanceof Error && e . message === 'Error in validation schema type' ) {
469+ throw e ;
470+ }
476471 throw new Error ( 'Error generating Sample CSV template' ) ;
477472 }
478473}
0 commit comments