@@ -22,17 +22,6 @@ function ensureNum(obj: any, argName: string): number {
2222 throw new Error ( `'${ argName } ' spec key is not a number.` ) ;
2323}
2424
25- /*
26- * Ensures that the field IDs match what's actually found in the template.
27- * Throws human-readable exceptions if errors are found.
28- */
29- function validateOutputPartialSpec ( o : OutputPartialSpec ) : void {
30- const fields : Set < string > = new Set ( Object . keys ( o . fields ) ) ;
31- console . assert ( fields . size === Object . keys ( o . fields ) . length ) ;
32-
33- // TODO: Length of fields?
34- }
35-
3625function inputTransform ( obj : any ) {
3726 // TODO: Simplify this later.
3827 const title : string = ensureStr ( obj . title , "input[].title" ) ;
@@ -48,6 +37,9 @@ function inputTransform(obj: any) {
4837
4938/********************************************************************/
5039
40+ interface OutputFieldSpec {
41+ label : string ;
42+ }
5143
5244interface InputPartialSpec {
5345 title : string ;
@@ -57,9 +49,7 @@ interface InputPartialSpec {
5749
5850interface OutputPartialSpec {
5951 title : string ;
60- fields : { [ key : string ] : {
61- title : string ;
62- } } ;
52+ fields : OutputFieldSpec [ ] ;
6353}
6454
6555export interface SpecValues {
@@ -107,24 +97,16 @@ export function getSpecValues(specPath: string): SpecValues {
10797
10898 output : objectValueMap ( output , ( obj : any ) => {
10999 const title : string = ensureStr ( obj . title , "output[].title" ) ;
110- const fields : any = obj . fields ;
111- if ( typeof fields !== "object" ) {
112- throw new Error ( `Output ${ obj . title } must provide a fields specification object .` ) ;
100+ const fieldLabels : any = obj . fieldLabels ;
101+ if ( ! Array . isArray ( fieldLabels ) ) {
102+ throw new Error ( `Output ${ obj . title } must provide a fields specification array .` ) ;
113103 }
114104
115- const newFieldsEntries = Object . fromEntries ( Object . entries ( fields ) . map (
116- ( [ k , v ] ) => {
117- const fieldKey : string = ensureStr ( k , `output[].fields.${ title } key` ) ;
118- const fieldTitle : string = ensureStr ( v , `output[].fields.${ title } value` ) ;
119- return [ fieldKey , { title : fieldTitle } ] ;
120- }
121- ) ) ;
122-
123- const outputObj = {
124- title,
125- fields : newFieldsEntries ,
126- } ;
127- validateOutputPartialSpec ( outputObj ) ;
105+ const fields : OutputFieldSpec [ ] = fieldLabels . map (
106+ x => ( { label : ensureStr ( x , `output[].fields[].label` ) } )
107+ ) ;
108+
109+ const outputObj = { title, fields} ;
128110 return outputObj ;
129111 } ) ,
130112 } ;
0 commit comments