@@ -70,7 +70,7 @@ exports.SessionSetFile = (sid, filename) => {
7070///
7171
7272exports . SessionSetAttributes = ( sid , attrDefs ) => {
73- sessionStore . apply ( sid , ( s ) => { s . attribudeDefs = attrDefs } )
73+ sessionStore . apply ( sid , ( s ) => { s . attributeDefs = attrDefs } )
7474}
7575
7676exports . SessionSetHeaderRange = ( sid , range ) => {
@@ -124,25 +124,57 @@ exports.SessionSetFormatChoices = (sid, choices) => {
124124// have the required information.
125125exports . SessionGetColumnsNeedingFormats = ( sid ) => {
126126 const session = sessionStore . get ( sid ) ;
127- const attributes = session . attribudeDefs ;
127+ const attributes = session . attributeDefs ;
128128 const mappings = session . mappingRules ;
129129 const supportedTypes = attributeTypes . supportedTypes ;
130130
131131 let columnsNeedingFormats = new Array ( ) ;
132132
133133 Object . entries ( mappings ) . forEach ( ( entry ) => {
134134 const [ colIdx , columnAttribute ] = entry ;
135- const columnDef = attributes . find ( ( attr ) => attr . name == columnAttribute ) ;
136- const columnTypeName = columnDef . type ;
137- const columnType = supportedTypes . get ( columnTypeName ) ;
138- if ( columnType . formats ) {
139- columnsNeedingFormats . push ( colIdx ) ;
135+ if ( columnAttribute != "" ) {
136+ const columnDef = attributes . find ( ( attr ) => attr . name == columnAttribute ) ;
137+ const columnTypeName = columnDef . type ;
138+ const columnType = supportedTypes . get ( columnTypeName ) ;
139+ if ( columnType . formats ) {
140+ columnsNeedingFormats . push ( colIdx ) ;
141+ }
140142 }
141143 } ) ;
142144
143145 return columnsNeedingFormats ;
144146} ;
145147
148+ // Given guesses as returned by SessionGuessTypes and a list of domain-model
149+ // fields (with name and type fields), returns the type guesses with each column
150+ // augmented with a `fields` field - a Map mapping likely field names for this
151+ // column to an array of possible formats for that field.
152+
153+ exports . SessionSuggestFields = ( sid , typeGuesses , domainModelFields ) => {
154+ let result = [ ] ;
155+
156+ typeGuesses . forEach ( ( colTypeGuess ) => {
157+ let fieldFormats = new Map ( ) ; // Map from field names to likely formats
158+ // Examine every field, and check if they have a type that this column might
159+ // contain
160+ domainModelFields . forEach ( ( field ) => {
161+ if ( colTypeGuess . types . has ( field . type ) ) {
162+ // Add this field to the possibilities for the column, using the guessed
163+ // formats
164+ fieldFormats . set ( field . name , colTypeGuess . types . get ( field . type ) ) ;
165+ }
166+ } ) ;
167+
168+ // Extend the column type guess with the "fields" field
169+ let typeGuessesAndFields = Object . assign ( { } , colTypeGuess ) ;
170+ typeGuessesAndFields . fields = fieldFormats ;
171+ result . push ( typeGuessesAndFields ) ;
172+ } ) ;
173+
174+ return result ;
175+ } ;
176+
177+
146178///
147179/// Information about the loaded input file
148180///
@@ -514,7 +546,7 @@ exports.SessionGuessTypes = (sid, range) => {
514546 }
515547
516548 // How many columns do we have?
517- const columns = range . end . column - range . start . column ;
549+ const columns = ( range . end . column - range . start . column ) + 1 ;
518550
519551 let guesses = new Array ( columns ) ;
520552 if ( range . end . row < range . start . row ) {
@@ -535,7 +567,7 @@ exports.SessionGuessTypes = (sid, range) => {
535567 const merges = sheet [ "!merges" ] ;
536568
537569 // Examine each row in turn, looking at the columns in parallel
538- for ( let row = range . start . row ; row < range . end . row ; row ++ ) {
570+ for ( let row = range . start . row ; row <= range . end . row ; row ++ ) {
539571 let rowData = extractColsFromRow ( getMergedRow ( data , merges , row ) ,
540572 range . start . column , range . end . column + 1 ) ;
541573 for ( let col = 0 ; col < columns ; col ++ ) {
@@ -590,34 +622,6 @@ exports.SessionGetSupportedTypes = (sid) => {
590622 return attributeTypes . supportedTypes ;
591623} ;
592624
593- // Given guesses as returned by SessionGuessTypes and a list of domain-model
594- // fields (with name and type fields), returns the type guesses with each column
595- // augmented with a `fields` field - a Map mapping likely field names for this
596- // column to an array of possible formats for that field.
597-
598- exports . SessionSuggestFields = ( sid , typeGuesses , domainModelFields ) => {
599- let result = [ ] ;
600-
601- typeGuesses . forEach ( ( colTypeGuess ) => {
602- let fieldFormats = new Map ( ) ; // Map from field names to likely formats
603- // Examine every field, and check if they have a type that this column might
604- // contain
605- domainModelFields . forEach ( ( field ) => {
606- if ( colTypeGuess . types . has ( field . type ) ) {
607- // Add this field to the possibilities for the column, using the guessed
608- // formats
609- fieldFormats . set ( field . name , colTypeGuess . types . get ( field . type ) ) ;
610- }
611- } ) ;
612-
613- // Extend the column type guess with the "fields" field
614- let typeGuessesAndFields = Object . assign ( { } , colTypeGuess ) ;
615- typeGuessesAndFields . fields = fieldFormats ;
616- result . push ( typeGuessesAndFields ) ;
617- } ) ;
618-
619- return result ;
620- } ;
621625
622626// Return the unique values in each column in the range. Return no more than
623627// maxValues values for any given column. Return format is an array, one entry
0 commit comments