@@ -82,7 +82,10 @@ function extractSetEntry(entry: string) {
8282}
8383
8484function extractRecordArrayEntry ( entry : string ) {
85- return entry . slice ( 13 , - 2 ) ; // 'RECORD_ARRAY(' - why -2?
85+ if ( entry . lastIndexOf ( ';' ) === entry . length - 2 ) {
86+ return entry . slice ( 13 , - 2 ) ;
87+ }
88+ return entry . slice ( 13 , - 1 ) ;
8689}
8790
8891export function reformatInstrumentData ( {
@@ -212,6 +215,7 @@ export function interpretZodValue(
212215 return { success : true , value : parseNumber ( entry ) } ;
213216 }
214217 return { message : `Invalid number type: ${ entry } ` , success : false } ;
218+ //TODO if ZodSet has a enum see if those values can be shown in template data if possible
215219 case 'ZodSet' :
216220 if ( entry . startsWith ( 'SET(' ) ) {
217221 const setData = extractSetEntry ( entry ) ;
@@ -251,11 +255,16 @@ export function interpretZodObjectValue(
251255 const recordArrayObject : { [ key : string ] : any } = { } ;
252256
253257 const record = listData . split ( ',' ) ;
254-
258+ if ( record . some ( ( str ) => str === '' ) ) {
259+ return { message : `One or more of the record array fields was left empty` , success : false } ;
260+ }
261+ if ( ! ( zList . length === zKeys . length && zList . length === record . length ) ) {
262+ return { message : `Incorrect number of entries for record array` , success : false } ;
263+ }
255264 for ( let i = 0 ; i < record . length ; i ++ ) {
256265 // TODO - make sure this is defined
257266 const recordValue = record [ i ] ! . split ( ':' ) [ 1 ] ! ;
258- // TODO - how do we know that `zList` is the same length as record? What if the user forgets to add a element
267+
259268 const zListResult = zList [ i ] ! ;
260269 if ( ! ( zListResult . success && zListResult . typeName !== 'ZodArray' && zListResult . typeName !== 'ZodObject' ) ) {
261270 return { message : `Failed to interpret field '${ i } '` , success : false } ;
@@ -308,6 +317,7 @@ function generateSampleData({
308317 for ( const val of enumValues ! ) {
309318 possibleEnumOutputs += val + '/' ;
310319 }
320+ possibleEnumOutputs = possibleEnumOutputs . slice ( 0 , - 1 ) ;
311321 return formatTypeInfo ( possibleEnumOutputs , isOptional ) ;
312322 } catch {
313323 throw new Error ( 'Invalid Enum error' ) ;
0 commit comments