read-excel-file 9.0.9 → 9.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unzipFromStream.test.js","names":["_mocha","require","_chai","_stream","_fflate","_unzipFromStream","_interopRequireDefault","obj","__esModule","_regeneratorRuntime","e","t","r","Object","prototype","n","hasOwnProperty","o","defineProperty","value","i","Symbol","a","iterator","c","asyncIterator","u","toStringTag","define","enumerable","configurable","writable","wrap","Generator","create","Context","makeInvokeMethod","tryCatch","type","arg","call","h","l","f","s","y","GeneratorFunction","GeneratorFunctionPrototype","p","d","getPrototypeOf","v","values","g","defineIteratorMethods","forEach","_invoke","AsyncIterator","invoke","_typeof","resolve","__await","then","callInvokeWithMethodAndArg","Error","done","method","delegate","maybeInvokeDelegate","sent","_sent","dispatchException","abrupt","TypeError","resultName","next","nextLoc","pushTryEntry","tryLoc","catchLoc","finallyLoc","afterLoc","tryEntries","push","resetTryEntry","completion","reset","isNaN","length","displayName","isGeneratorFunction","constructor","name","mark","setPrototypeOf","__proto__","awrap","async","Promise","keys","reverse","pop","prev","charAt","slice","stop","rval","handle","complete","finish","_catch","delegateYield","asyncGeneratorStep","gen","reject","_next","_throw","key","info","error","_asyncToGenerator","fn","self","args","arguments","apply","err","undefined","describe","it","_callee","zip","files","_callee$","_context","createZip","unzipFromStream","createStreamFromBuffer","expect","convertValuesFromBufferToString","to","deep","equal","_callee2","_callee2$","_context2","level","_callee3","_callee3$","_context3","repeat","chunkSize","_callee4","_callee4$","_context4","Buffer","from","zipSync","Uint8Array","strToU8","_callee5","_callee5$","_context5","filter","_ref6","path","endsWith","_callee6","stream","thrown","_callee6$","_context6","Readable","read","process","nextTick","emit","t0","_callee7","garbage","_callee7$","_context7","be","an","_ref9","entries","_i","_Object$keys","buffer","_ref10","_ref10$chunkSize","chunks","subarray","alloc","object","convertedObject","_i2","_Object$keys2","strFromU8"],"sources":["../../source/zip/unzipFromStream.test.js"],"sourcesContent":["// This code was originally submitted by Stian Jensen.\r\n// https://github.com/catamphetamine/read-excel-file/pull/122\r\n\r\nimport { describe, it } from 'mocha'\r\nimport { expect } from 'chai'\r\n\r\nimport { Readable } from 'stream'\r\nimport { zipSync, strToU8, strFromU8 } from 'fflate'\r\n\r\nimport unzipFromStream from './unzipFromStream.js'\r\n\r\ndescribe('unzipFromStream', () => {\r\n\tit('should read DEFLATE-compressed entries from a stream', async () => {\r\n\t\tconst zip = createZip({\r\n\t\t\t'a.xml': '<a>Hello</a>',\r\n\t\t\t'dir/b.xml': '<b>World</b>'\r\n\t\t})\r\n\t\tconst files = await unzipFromStream(createStreamFromBuffer(zip))\r\n\t\texpect(convertValuesFromBufferToString(files)).to.deep.equal({\r\n\t\t\t'a.xml': '<a>Hello</a>',\r\n\t\t\t'dir/b.xml': '<b>World</b>'\r\n\t\t})\r\n\t})\r\n\r\n\tit('should read \"stored\" (uncompressed) entries from a stream', async () => {\r\n\t\tconst zip = createZip({ 'a.xml': '<a>Hello</a>' }, { level: 0 })\r\n\t\tconst files = await unzipFromStream(createStreamFromBuffer(zip))\r\n\t\texpect(convertValuesFromBufferToString(files)).to.deep.equal({ 'a.xml': '<a>Hello</a>' })\r\n\t})\r\n\r\n\tit('should read entries split across small stream chunks', async () => {\r\n\t\tconst zip = createZip({\r\n\t\t\t'a.xml': '<a>'.repeat(500),\r\n\t\t\t'b.xml': '<b>'.repeat(500)\r\n\t\t})\r\n\t\tconst files = await unzipFromStream(createStreamFromBuffer(zip, { chunkSize: 7 }))\r\n\t\texpect(convertValuesFromBufferToString(files)).to.deep.equal({\r\n\t\t\t'a.xml': '<a>'.repeat(500),\r\n\t\t\t'b.xml': '<b>'.repeat(500)\r\n\t\t})\r\n\t})\r\n\r\n\tit('should ignore directory entries', async () => {\r\n\t\tconst zip = Buffer.from(zipSync({\r\n\t\t\t'dir/': new Uint8Array(0),\r\n\t\t\t'dir/a.xml': strToU8('<a/>')\r\n\t\t}))\r\n\t\tconst files = await unzipFromStream(createStreamFromBuffer(zip))\r\n\t\texpect(convertValuesFromBufferToString(files)).to.deep.equal({ 'dir/a.xml': '<a/>' })\r\n\t})\r\n\r\n\tit('should ignore entries rejected by the `filter` option', async () => {\r\n\t\tconst zip = createZip({\r\n\t\t\t'keep.xml': '<keep/>',\r\n\t\t\t'skip.png': 'binary'\r\n\t\t})\r\n\t\tconst files = await unzipFromStream(createStreamFromBuffer(zip), {\r\n\t\t\tfilter: ({ path }) => path.endsWith('.xml')\r\n\t\t})\r\n\t\texpect(convertValuesFromBufferToString(files)).to.deep.equal({ 'keep.xml': '<keep/>' })\r\n\t})\r\n\r\n\tit('should reject when the source stream errors', async () => {\r\n\t\tconst stream = new Readable({ read() {} })\r\n\t\tconst error = new Error('Stream read failure')\r\n\t\tprocess.nextTick(() => stream.emit('error', error))\r\n\r\n\t\tlet thrown\r\n\t\ttry {\r\n\t\t\tawait unzipFromStream(stream)\r\n\t\t} catch (caught) {\r\n\t\t\tthrown = caught\r\n\t\t}\r\n\t\texpect(thrown).to.equal(error)\r\n\t})\r\n\r\n\tit('should reject on invalid (non-zip) data', async () => {\r\n\t\tconst garbage = Buffer.from('this is definitely not a zip archive')\r\n\r\n\t\tlet thrown\r\n\t\ttry {\r\n\t\t\tawait unzipFromStream(createStreamFromBuffer(garbage))\r\n\t\t} catch (caught) {\r\n\t\t\tthrown = caught\r\n\t\t}\r\n\t\texpect(thrown).to.be.an('error')\r\n\t})\r\n})\r\n\r\n\r\n// Builds a `.zip` archive (in memory) from a map of text files.\r\n//\r\n// Accepts `fflate`'s `zipSync()` function options as the optional second argument.\r\n// For example, passing `level: 0` will produce a `.zip` file with no compression.\r\n//\r\n// Returns a `Buffer`.\r\n//\r\nfunction createZip(files, { level } = {}) {\r\n\tconst entries = {}\r\n\tfor (const name of Object.keys(files)) {\r\n\t\tentries[name] = strToU8(files[name])\r\n\t}\r\n\treturn Buffer.from(zipSync(entries, { level }))\r\n}\r\n\r\n// Creates a Node.js Stream from a given `buffer` containing the data.\r\n// The stream will split the data into `chunkSize`-byte chunks.\r\n// (this is used to exercise reading across arbitrary chunk boundaries)\r\nfunction createStreamFromBuffer(buffer, { chunkSize = buffer.length } = {}) {\r\n\tconst chunks = []\r\n\tfor (let i = 0; i < buffer.length; i += chunkSize) {\r\n\t\tchunks.push(buffer.subarray(i, i + chunkSize))\r\n\t}\r\n\treturn Readable.from(chunks.length > 0 ? chunks : [Buffer.alloc(0)])\r\n}\r\n\r\n// Converts the values in the given object from `Buffer` to UTF-8 `string`.\r\nfunction convertValuesFromBufferToString(object) {\r\n\tconst convertedObject = {}\r\n\tfor (const path of Object.keys(object)) {\r\n\t\tconvertedObject[path] = strFromU8(object[path])\r\n\t}\r\n\treturn convertedObject\r\n}"],"mappings":";;;AAGA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAEA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AAEA,IAAAI,gBAAA,GAAAC,sBAAA,CAAAL,OAAA;AAAkD,SAAAK,uBAAAC,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,gBAAAA,GAAA;AAAA,SAAAE,oBAAA,kBARlD,qJAAAA,mBAAA,YAAAA,oBAAA,WAAAC,CAAA,SAAAC,CAAA,EAAAD,CAAA,OAAAE,CAAA,GAAAC,MAAA,CAAAC,SAAA,EAAAC,CAAA,GAAAH,CAAA,CAAAI,cAAA,EAAAC,CAAA,GAAAJ,MAAA,CAAAK,cAAA,cAAAP,CAAA,EAAAD,CAAA,EAAAE,CAAA,IAAAD,CAAA,CAAAD,CAAA,IAAAE,CAAA,CAAAO,KAAA,KAAAC,CAAA,wBAAAC,MAAA,GAAAA,MAAA,OAAAC,CAAA,GAAAF,CAAA,CAAAG,QAAA,kBAAAC,CAAA,GAAAJ,CAAA,CAAAK,aAAA,uBAAAC,CAAA,GAAAN,CAAA,CAAAO,WAA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D;;AAEA;AACA;AACA;AACA,SAAST,sBAAsBA,CAACmD,MAAM,EAAsC;EAAA,IAAAC,MAAA,GAAAjE,SAAA,CAAApC,MAAA,QAAAoC,SAAA,QAAAG,SAAA,GAAAH,SAAA,MAAJ,CAAC,CAAC;IAAAkE,gBAAA,GAAAD,MAAA,CAAhCtC,SAAS;IAATA,SAAS,GAAAuC,gBAAA,cAAGF,MAAM,CAACpG,MAAM,GAAAsG,gBAAA;EAClE,IAAMC,MAAM,GAAG,EAAE;EACjB,KAAK,IAAI3K,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGwK,MAAM,CAACpG,MAAM,EAAEpE,CAAC,IAAImI,SAAS,EAAE;IAClDwC,MAAM,CAAC5G,IAAI,CAACyG,MAAM,CAACI,QAAQ,CAAC5K,CAAC,EAAEA,CAAC,GAAGmI,SAAS,CAAC,CAAC;EAC/C;EACA,OAAOqB,gBAAQ,CAAChB,IAAI,CAACmC,MAAM,CAACvG,MAAM,GAAG,CAAC,GAAGuG,MAAM,GAAG,CAACpC,MAAM,CAACsC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AACrE;;AAEA;AACA,SAAStD,+BAA+BA,CAACuD,MAAM,EAAE;EAChD,IAAMC,eAAe,GAAG,CAAC,CAAC;EAC1B,SAAAC,GAAA,MAAAC,aAAA,GAAmBxL,MAAM,CAACsF,IAAI,CAAC+F,MAAM,CAAC,EAAAE,GAAA,GAAAC,aAAA,CAAA7G,MAAA,EAAA4G,GAAA,IAAE;IAAnC,IAAM/B,IAAI,GAAAgC,aAAA,CAAAD,GAAA;IACdD,eAAe,CAAC9B,IAAI,CAAC,GAAG,IAAAiC,iBAAS,EAACJ,MAAM,CAAC7B,IAAI,CAAC,CAAC;EAChD;EACA,OAAO8B,eAAe;AACvB"}
@@ -389,7 +389,7 @@ export function parseValue(value, schemaEntry, options) {
389
389
  //
390
390
  Array.isArray(schemaEntry.type) ? schemaEntry.type[0] : schemaEntry.type, options);
391
391
  } else {
392
- // If the `type` is not specified for a given schema entry, the default one is `String`.
392
+ // If the `type` is not specified for a given schema entry, the `value` will be returned as is.
393
393
  result = {
394
394
  value: value
395
395
  };
@@ -1 +1 @@
1
- {"version":3,"file":"parseSheetData.js","names":["NumberType","StringType","BooleanType","DateType","parseSheetData","data","schema","optionsCustom","objects","errors","parsedRows","parseSheetDataWithPerRowErrors","parsedRowIndex","_iterator","_createForOfIteratorHelperLoose","_step","done","_step$value","value","object","rowErrors","concat","map","rowError","_objectSpread","row","push","length","validateSchema","options","applyDefaultOptions","_data","_toArray","columns","dataRows","slice","parseDataRow","dataRow","schemaEntry","_parseProperty","parseProperty","undefined","isEmptyValue","children","dummyParentObject","PARSED_OBJECT_TREE_START","isRequired","requiredErrors","runPendingRequiredValidations","transformValue","parseObject","path","isEmptyObject","_i","_Object$keys","Object","keys","key","child","getPropertyPath","columnIndex","column","indexOf","isMissingColumn","_ref","propertyValueWhenColumnIsMissing","parseCellValueWithPossibleErrors","cellValue","_parseCellValue","parseCellValue","errorMessage","error","errorReason","reason","createError","valueType","type","propertyValueWhenCellIsEmpty","Array","isArray","parseArrayValue","parseValue","isEmptyArray","reasons","values","parseSeparatedSubstrings","separatorCharacter","substring","_parseValue","result","parseValueOfType","oneOf","errorAndReason","validateOneOf","validate","message","String","parseValueUsingTypeParser","Number","Date","Boolean","Error","name","parsedValue","getNextSubstring","string","startIndex","i","character","elements","index","_getNextSubstring","_getNextSubstring2","_slicedToArray","trim","isObject","transformEmptyObject","transformEmptyArray","propertyName","parentObjectPath","parentObjectIsRequired","parentObjectValue","parentObjectValueIsEmpty","parentObjectErrors","isPropertyRequired","_iterator2","_step2","requiredErrorsOfChild","required","_ref2","_i2","_Object$keys2","_typeof","validateObjectSchemaRequiredProperty","_i3","_Object$keys3","JSON","stringify","DEFAULT_OPTIONS","objectConstructor","constructor"],"sources":["../../source/parseSheetData/parseSheetData.js"],"sourcesContent":["import NumberType from './types/Number.js'\r\nimport StringType from './types/String.js'\r\nimport BooleanType from './types/Boolean.js'\r\nimport DateType from './types/Date.js'\r\n\r\n/**\r\n * Converts spreadsheet-alike data structure into an array of JSON objects.\r\n *\r\n * Parameters:\r\n *\r\n * * `data` — An array of rows, each row being an array of cells. The first row should be the list of column headers and the rest of the rows should be the data.\r\n * * `schema` — A \"to JSON\" convertion schema (see above).\r\n * * `options` — (optional) Schema conversion parameters of `read-excel-file`:\r\n * * `propertyValueWhenColumnIsMissing` — By default, when some of the `schema` columns are missing in the input `data`, those properties are set to `undefined` in the output objects. Pass `propertyValueWhenColumnIsMissing: null` to set such \"missing column\" properties to `null` in the output objects.\r\n * * `propertyValueWhenCellIsEmpty` — By default, when it encounters a `null` value in a cell in input `data`, it sets it to `undefined` in the output object. Pass `propertyValueWhenCellIsEmpty: null` to make it set such values as `null`s in output objects.\r\n * // * `shouldSkipRequiredValidationWhenColumnIsMissing: (column: string, { object }) => boolean` — By default, it does apply `required` validation to `schema` properties for which columns are missing in the input `data`. One could pass a custom `shouldSkipRequiredValidationWhenColumnIsMissing(column, { object })` to disable `required` validation for missing columns in some or all cases.\r\n * * `transformEmptyObject(object, { path? })` — By default, it returns `null` for \"empty\" objects. One could override that value using `transformEmptyObject(object, { path })` parameter. The value applies to both top-level object and any nested sub-objects in case of a nested schema, hence the additional (optional) `path?: string` parameter.\r\n * * `transformEmptyArray(array, { path })` — By default, it returns `null` for an \"empty\" array value. One could override that value using `transformEmptyArray(array, { path })` parameter.\r\n * * `separatorCharacter` — By default, it splits array-type cell values by a comma character.\r\n *\r\n * When parsing a property value, in case of an error, the value of that property is gonna be `undefined`.\r\n *\r\n * @param {SheetData} data - An array of rows, each row being an array of cells.\r\n * @param {object} schema\r\n * @param {object} [options]\r\n * @param {any} [options.propertyValueWhenColumnIsMissing] — By default, when some of the `schema` columns are missing in the input `data`, those properties are set to `undefined` in the output objects. Pass `propertyValueWhenColumnIsMissing: null` to set such \"missing column\" properties to `null` in the output objects.\r\n * @param {any} [options.propertyValueWhenCellIsEmpty] — By default, when it encounters a `null` value in a cell in input `data`, it leaves the value as is. Pass a custom `propertyValueWhenCellIsEmpty` to make it set such values to that value.\r\n * // @param {boolean} [options.shouldSkipRequiredValidationWhenColumnIsMissing(column: string, { object })] — By default, it does apply `required` validation to `schema` properties for which columns are missing in the input `data`. One could pass a custom `shouldSkipRequiredValidationWhenColumnIsMissing(column, { object })` to disable `required` validation for missing columns in some or all cases.\r\n * @param {function} [options.transformEmptyObject(object, { path })] — By default, it returns `null` for an \"empty\" resulting object. One could override that value using `transformEmptyObject(object, { path })` parameter. The value applies to both top-level object and any nested sub-objects in case of a nested schema, hence the additional `path?: string` parameter.\r\n * @param {function} [options.transformEmptyArray(array, { path })] — By default, it returns `null` for an \"empty\" array value. One could override that value using `transformEmptyArray(array, { path })` parameter.\r\n * @param {string} [options.separatorCharacter] — When specified, string values will be split by this separator to get the array.\r\n * @return {object} — An object of shape `{ objects, errors }`. Either `objects` or `errors` is going to be `undefined`.\r\n */\r\nexport default function parseSheetData(data, schema, optionsCustom) {\r\n const objects = []\r\n let errors = []\r\n\r\n const parsedRows = parseSheetDataWithPerRowErrors(data, schema, optionsCustom)\r\n let parsedRowIndex = 0\r\n for (const { object, errors: rowErrors } of parsedRows) {\r\n if (rowErrors) {\r\n errors = errors.concat(\r\n rowErrors.map(\r\n // Add row number property to each row error.\r\n rowError => ({ ...rowError, row: parsedRowIndex + 1 })\r\n )\r\n )\r\n } else {\r\n objects.push(object)\r\n }\r\n parsedRowIndex++\r\n }\r\n\r\n if (errors.length > 0) {\r\n return { errors }\r\n }\r\n\r\n return { objects }\r\n}\r\n\r\n// This one is only used in tests.\r\nexport function parseSheetDataWithPerRowErrors(data, schema, optionsCustom) {\r\n validateSchema(schema)\r\n\r\n const options = applyDefaultOptions(optionsCustom)\r\n\r\n const [columns, ...dataRows] = data\r\n\r\n return dataRows.map(row => parseDataRow(row, schema, columns, options))\r\n}\r\n\r\nfunction parseDataRow(dataRow, schema, columns, options) {\r\n // Create a `schemaEntry` for the top-level object.\r\n const schemaEntry = {\r\n schema\r\n }\r\n\r\n // Parse the values in the given data row into an object.\r\n const {\r\n value,\r\n isEmptyValue,\r\n errors,\r\n children\r\n } = parseProperty(dataRow, schemaEntry, undefined, columns, options)\r\n\r\n // Simulate a \"dummy\" parent object for the top-level object.\r\n // It will be used when running `required` validations.\r\n const dummyParentObject = {\r\n // The \"dummy\" parent object has a \"dummy\" value.\r\n // This value is irrelevant because it won't be read anywhere.\r\n value: PARSED_OBJECT_TREE_START,\r\n // The \"dummy\" parent object is empty if the parsed row is empty.\r\n isEmptyValue,\r\n // The \"dummy\" object has the same errors as the parsed row.\r\n errors,\r\n // The parsed object by default is not required to have any data\r\n // so the \"dummy\" object is not required.\r\n isRequired: undefined\r\n }\r\n\r\n // Run any `required` validations.\r\n //\r\n // `required` validations should be run after the entire data row has been parsed,\r\n // i.e. when the entire object structure has been parsed.\r\n // The reason is that a `required` validation could be either a simple boolean or a \"complex\" function.\r\n // In the latter case, the result of a `required()` function may depend on any other property of the object,\r\n // hence the actual `required` flag value could only be obtained after the entire data row has been parsed.\r\n //\r\n // For example, consider a top-level object:\r\n //\r\n // {\r\n // firstName: string,\r\n // lastName: string,\r\n // pet?: { name: string }\r\n // }\r\n //\r\n // A corresponding schema would be:\r\n //\r\n // {\r\n // firstName: {\r\n // required: true\r\n // },\r\n // lastName: {\r\n // required: true\r\n // },\r\n // pet: {\r\n // required: false,\r\n // schema: {\r\n // name: {\r\n // required: true\r\n // }\r\n // }\r\n // }\r\n // }\r\n //\r\n // I.e. when a `pet` exists, it must have a `name`.\r\n //\r\n // In such case, the `required: true` check of the `pet`'s `name` property\r\n // should not be performed if the `pet` is not present, because the `pet` nested object\r\n // is marked as `required: false`, meaning that `pet` data is not required to be present.\r\n //\r\n const requiredErrors = runPendingRequiredValidations(\r\n schemaEntry,\r\n value,\r\n isEmptyValue,\r\n errors,\r\n children,\r\n // Simulate a \"dummy\" parent object for the top-level object.\r\n dummyParentObject.isRequired,\r\n dummyParentObject.value,\r\n dummyParentObject.isEmptyValue,\r\n dummyParentObject.errors,\r\n columns\r\n )\r\n\r\n // If there were any errors, whether caused by `required`\r\n // or occured while parsing the values, return those errors.\r\n if (errors || requiredErrors) {\r\n return {\r\n errors: (errors || []).concat(requiredErrors || [])\r\n }\r\n }\r\n\r\n // Return the parsed object.\r\n return {\r\n object: transformValue(value, isEmptyValue, undefined, options)\r\n }\r\n}\r\n\r\nfunction parseObject(row, schema, path, columns, options) {\r\n const object = {}\r\n let isEmptyObject = true\r\n\r\n let errors = []\r\n\r\n const children = []\r\n\r\n // For each property of the object.\r\n for (const key of Object.keys(schema)) {\r\n const child = parseProperty(row, schema[key], getPropertyPath(key, path), columns, options)\r\n\r\n if (child.errors) {\r\n errors = errors.concat(child.errors)\r\n } else {\r\n object[key] = transformValue(child.value, child.isEmptyValue, getPropertyPath(key, path), options)\r\n // Potentially unmark the object as \"empty\".\r\n if (isEmptyObject && !child.isEmptyValue) {\r\n isEmptyObject = false\r\n }\r\n }\r\n\r\n children.push({\r\n ...child,\r\n // `schemaEntry` will be used when running `required` validation of this property (later),\r\n schemaEntry: schema[key]\r\n })\r\n }\r\n\r\n // If there were any errors, return them.\r\n if (errors.length > 0) {\r\n return {\r\n // Return the errors.\r\n errors,\r\n // Return the `children` because `required` validations still have to be run (later).\r\n children\r\n }\r\n }\r\n\r\n return {\r\n value: object,\r\n isEmptyValue: isEmptyObject,\r\n // Return the `children` because `required` validations still have to be run (later).\r\n children\r\n }\r\n}\r\n\r\nfunction parseProperty(row, schemaEntry, path, columns, options) {\r\n const columnIndex = schemaEntry.column ? columns.indexOf(schemaEntry.column) : undefined\r\n const isMissingColumn = schemaEntry.column ? columnIndex < 0 : undefined\r\n\r\n const {\r\n value,\r\n isEmptyValue,\r\n errors,\r\n children\r\n } = schemaEntry.column\r\n ? (\r\n isMissingColumn\r\n ? { value: options.propertyValueWhenColumnIsMissing, isEmptyValue: true }\r\n : parseCellValueWithPossibleErrors(row[columnIndex], schemaEntry, columnIndex, options)\r\n )\r\n : parseObject(\r\n row,\r\n schemaEntry.schema,\r\n path,\r\n columns,\r\n options\r\n )\r\n\r\n // If there were any errors, return them.\r\n if (errors) {\r\n return {\r\n // Return the errors.\r\n errors,\r\n // Return the `children` because `required` validations still have to be run (later).\r\n children\r\n }\r\n }\r\n\r\n return {\r\n value,\r\n isEmptyValue,\r\n // Return the `children` because `required` validations still have to be run (later).\r\n children\r\n }\r\n}\r\n\r\nfunction parseCellValueWithPossibleErrors(cellValue, schemaEntry, columnIndex, options) {\r\n const {\r\n value,\r\n isEmptyValue,\r\n error: errorMessage,\r\n reason: errorReason\r\n } = parseCellValue(cellValue, schemaEntry, options)\r\n\r\n if (errorMessage) {\r\n const error = createError({\r\n error: errorMessage,\r\n reason: errorReason,\r\n column: schemaEntry.column,\r\n columnIndex,\r\n valueType: schemaEntry.type,\r\n value: cellValue\r\n })\r\n return {\r\n errors: [error]\r\n }\r\n }\r\n\r\n return {\r\n value,\r\n isEmptyValue\r\n }\r\n}\r\n\r\n/**\r\n * Converts a cell value value to a javascript typed value.\r\n * @param {any} cellValue\r\n * @param {object} schemaEntry\r\n * @param {string} propertyPath\r\n * @param {object} options\r\n * @return {{ value?: any, isEmptyValue: boolean } | { error: string, reason?: string }}\r\n */\r\nfunction parseCellValue(cellValue, schemaEntry, options) {\r\n if (cellValue === undefined) {\r\n // This isn't supposed to be possible when reading spreadsheet data:\r\n // cell values are always read as `null` when those cells are empty.\r\n // It's currently impossible for `read-excel-file` to return `undefined` cell value.\r\n // Here it uses some \"sensible default\" fallback by treating `undefined` as \"column missing\".\r\n return {\r\n value: options.propertyValueWhenColumnIsMissing,\r\n isEmptyValue: true\r\n }\r\n }\r\n\r\n if (cellValue === null) {\r\n return {\r\n value: options.propertyValueWhenCellIsEmpty,\r\n isEmptyValue: true\r\n }\r\n }\r\n\r\n // Parse comma-separated cell value.\r\n if (Array.isArray(schemaEntry.type)) {\r\n return parseArrayValue(cellValue, schemaEntry, options)\r\n }\r\n\r\n return parseValue(cellValue, schemaEntry, options)\r\n}\r\n\r\n/**\r\n * Converts textual value to a javascript typed array value.\r\n * @param {any} value\r\n * @param {object} schemaEntry\r\n * @param {object} options\r\n * @return {{ value?: any, isEmptyValue: boolean } | { error: string, reason?: string }}\r\n */\r\nfunction parseArrayValue(value, schemaEntry, options) {\r\n // If the cell value is not a string — i.e. a number, a boolean, a Date —\r\n // then throw an error.\r\n if (typeof value !== 'string') {\r\n return {\r\n error: 'not_a_string'\r\n }\r\n }\r\n\r\n let isEmptyArray = true\r\n\r\n const errors = []\r\n const reasons = []\r\n\r\n const values = parseSeparatedSubstrings(value, options.separatorCharacter).map((substring) => {\r\n // If any substring was already detected to be invalid\r\n // don't attempt to parse any other substrings.\r\n if (errors.length > 0) {\r\n return\r\n }\r\n\r\n // If an empty substring was extracted, it means that there was an out-of-place separator.\r\n if (!substring) {\r\n errors.push('invalid')\r\n reasons.push('syntax')\r\n return\r\n }\r\n\r\n const {\r\n value,\r\n isEmptyValue,\r\n error,\r\n reason\r\n } = parseValue(substring, schemaEntry, options)\r\n\r\n if (error) {\r\n errors.push(error)\r\n reasons.push(reason)\r\n return\r\n }\r\n\r\n if (isEmptyArray && !isEmptyValue) {\r\n isEmptyArray = false\r\n }\r\n\r\n return value\r\n })\r\n\r\n if (errors.length > 0) {\r\n return {\r\n error: errors[0],\r\n reason: reasons[0]\r\n }\r\n }\r\n\r\n return {\r\n value: values,\r\n isEmptyValue: isEmptyArray\r\n }\r\n}\r\n\r\n/**\r\n * Converts textual value to a javascript typed value.\r\n * @param {any} value\r\n * @param {object} schemaEntry\r\n * @param {object} options\r\n * @return {{ value?: any, isEmptyValue: boolean } | { error: string }}\r\n */\r\nexport function parseValue(value, schemaEntry, options) {\r\n // `null` values (i.e. empty cells) don't get parsed.\r\n if (value === null) {\r\n return {\r\n value: null,\r\n isEmptyValue: true\r\n }\r\n }\r\n\r\n // Parse the value according to the `type` that is specified in the schema entry.\r\n let result\r\n if (schemaEntry.type) {\r\n result = parseValueOfType(\r\n value,\r\n // Get the type of the value.\r\n //\r\n // Handle the case if it's a comma-separated value.\r\n // Example `type`: String[]\r\n // Example Input Value: 'Barack Obama, \"String, with, colons\", Donald Trump'\r\n // Example Parsed Value: ['Barack Obama', 'String, with, colons', 'Donald Trump']\r\n //\r\n Array.isArray(schemaEntry.type) ? schemaEntry.type[0] : schemaEntry.type,\r\n options\r\n )\r\n } else {\r\n // If the `type` is not specified for a given schema entry, the default one is `String`.\r\n result = { value }\r\n // throw new Error('Invalid schema entry: no `type` specified:\\n\\n' + JSON.stringify(schemaEntry, null, 2))\r\n }\r\n\r\n // If there was an error when parsing the value then return the error.\r\n if (result.error) {\r\n return result\r\n }\r\n\r\n // If the parsed value is empty, return it.\r\n if (value === null) {\r\n return {\r\n value: null,\r\n isEmptyValue: true\r\n }\r\n }\r\n\r\n // Value is not empty.\r\n // Validate it and return.\r\n\r\n // Perform `oneOf` validation.\r\n if (schemaEntry.oneOf) {\r\n const errorAndReason = validateOneOf(result.value, schemaEntry.oneOf)\r\n if (errorAndReason) {\r\n return errorAndReason\r\n }\r\n }\r\n\r\n // Perform `validate()` validation.\r\n if (schemaEntry.validate) {\r\n try {\r\n schemaEntry.validate(result.value)\r\n } catch (error) {\r\n return { error: error.message }\r\n }\r\n }\r\n\r\n // Return the value.\r\n return {\r\n value: result.value,\r\n isEmptyValue: isEmptyValue(result.value)\r\n }\r\n}\r\n\r\nfunction validateOneOf(value, oneOf) {\r\n if (oneOf.indexOf(value) < 0) {\r\n return { error: 'invalid', reason: 'unknown' }\r\n }\r\n}\r\n\r\n/**\r\n * Converts cell value to a javascript typed value.\r\n * @param {(string|number|boolean|Date)} value\r\n * @param {function} type\r\n * @return {object} Either `{ value: (string|number|Date|boolean) }` or `{ error: string, reason?: string }`\r\n */\r\nfunction parseValueOfType(value, type) {\r\n switch (type) {\r\n case String:\r\n return parseValueUsingTypeParser(value, StringType)\r\n\r\n case Number:\r\n return parseValueUsingTypeParser(value, NumberType)\r\n\r\n case Date:\r\n return parseValueUsingTypeParser(value, DateType)\r\n\r\n case Boolean:\r\n return parseValueUsingTypeParser(value, BooleanType)\r\n\r\n default:\r\n // Validate `type`\r\n if (typeof type !== 'function') {\r\n throw new Error(`Unsupported schema \\`type\\`: ${type && type.name || type}`)\r\n }\r\n return parseValueUsingTypeParser(value, type)\r\n }\r\n}\r\n\r\n/**\r\n * Converts textual value to a custom value using supplied `type`.\r\n * @param {any} value\r\n * @param {function} type\r\n * @return {{ value: any, error: string }}\r\n */\r\nfunction parseValueUsingTypeParser(value, type) {\r\n try {\r\n const parsedValue = type(value)\r\n // Returning `undefined` from a `type` parser is treated as returning `null`.\r\n if (parsedValue === undefined) {\r\n return { value: null }\r\n }\r\n return { value: parsedValue }\r\n } catch (error) {\r\n const result = { error: error.message }\r\n // Built-in types such as `Number` or `Date` may also report\r\n // a specific `reason` of the error.\r\n if (error.reason) {\r\n result.reason = error.reason;\r\n }\r\n return result\r\n }\r\n}\r\n\r\n// Extracts a substring from a string.\r\nexport function getNextSubstring(string, separatorCharacter, startIndex) {\r\n let i = 0\r\n let substring = ''\r\n while (startIndex + i < string.length) {\r\n const character = string[startIndex + i]\r\n if (character === separatorCharacter) {\r\n return [substring, i]\r\n }\r\n // Previously, it used to treat `\"` character similar to how it's treated in `.csv` files:\r\n // any commas inside quotes are ignored. But then I thought that it could introduce more\r\n // issues than it was originally intending to fix, and it also didn't provide an \"escape\" mechanism.\r\n // Overall, a decision was made to simplify the whole thing and drop the concept of quotes as special characters.\r\n //\r\n // else if (character === '\"') {\r\n // const quotedSubstring = getNextSubstring(string, '\"', startIndex + i + 1)\r\n // substring += quotedSubstring[0]\r\n // i += '\"'.length + quotedSubstring[1] + '\"'.length\r\n // }\r\n else {\r\n substring += character\r\n i++\r\n }\r\n }\r\n return [substring, i]\r\n}\r\n\r\n/**\r\n * Parses a string of comma-separated substrings into an array of substrings.\r\n * (the `export` is just for tests)\r\n * @param {string} string — A string of comma-separated substrings.\r\n * @return {string[]} An array of substrings.\r\n */\r\nexport function parseSeparatedSubstrings(string, separatorCharacter) {\r\n const elements = []\r\n let index = 0\r\n while (index < string.length) {\r\n const [substring, length] = getNextSubstring(string, separatorCharacter, index)\r\n index += length + separatorCharacter.length\r\n elements.push(substring.trim())\r\n }\r\n return elements\r\n}\r\n\r\nfunction transformValue(value, isEmptyValue, path, options) {\r\n if (isEmptyValue) {\r\n if (isObject(value)) {\r\n return options.transformEmptyObject(value, { path })\r\n } else if (Array.isArray(value)) {\r\n return options.transformEmptyArray(value, { path })\r\n }\r\n }\r\n return value\r\n}\r\n\r\nfunction getPropertyPath(propertyName, parentObjectPath) {\r\n return `${parentObjectPath ? parentObjectPath + '.' : ''}${propertyName}`\r\n}\r\n\r\n// Recursively runs `required` validations for the parsed data row tree.\r\nfunction runPendingRequiredValidations(\r\n schemaEntry,\r\n value,\r\n isEmptyValue,\r\n errors,\r\n children,\r\n parentObjectIsRequired,\r\n parentObjectValue,\r\n parentObjectValueIsEmpty,\r\n parentObjectErrors,\r\n columns\r\n) {\r\n let requiredErrors = []\r\n\r\n // See if this property is required.\r\n const isRequired = isPropertyRequired(\r\n schemaEntry,\r\n parentObjectIsRequired,\r\n parentObjectValue,\r\n parentObjectValueIsEmpty,\r\n parentObjectErrors\r\n )\r\n\r\n // If this property is required and empty, create a \"required\" error.\r\n if (isRequired && isEmptyValue) {\r\n requiredErrors.push(createError({\r\n error: 'required',\r\n column: schemaEntry.column,\r\n columnIndex: columns.indexOf(schemaEntry.column),\r\n valueType: schemaEntry.type,\r\n value\r\n }))\r\n }\r\n\r\n // Run `required` validations of the children.\r\n if (children) {\r\n for (const child of children) {\r\n const requiredErrorsOfChild = runPendingRequiredValidations(\r\n child.schemaEntry,\r\n child.value,\r\n child.isEmptyValue,\r\n child.errors,\r\n child.children,\r\n // The following properties describe the parent object of the `child`,\r\n // i.e. the current (iterated) object.\r\n isRequired,\r\n value,\r\n isEmptyValue,\r\n errors,\r\n columns\r\n )\r\n if (requiredErrorsOfChild) {\r\n requiredErrors = requiredErrors.concat(requiredErrorsOfChild)\r\n }\r\n }\r\n }\r\n if (requiredErrors.length > 0) {\r\n return requiredErrors\r\n }\r\n}\r\n\r\nfunction isPropertyRequired(\r\n schemaEntry,\r\n parentObjectIsRequired,\r\n parentObjectValue,\r\n parentObjectValueIsEmpty,\r\n parentObjectErrors\r\n) {\r\n // If the parent object is marked as `required: false` then it's allowed\r\n // to be absent entirely from the input data. If that's the case,\r\n // i.e. if the parent object is absent entirely from the input data,\r\n // then any descendant properties of such object are allowed to be absent too,\r\n // which means that they should also be considered being `required: false`.\r\n //\r\n // Also, if the parent object couldn't be parsed due to some non-`required` errors,\r\n // it can't be known whether it's actually empty or not. In case of such uncertainty,\r\n // the code shouldn't attempt to be overly smart and do things that might not be necessary,\r\n // so such parent object is just assumed to be empty in order to not falsly trigger\r\n // any `required` validations that otherwise wouldn't have been run.\r\n // In other words, skipping some `required` validations is better than\r\n // running `required` validations that shouldn't have been run.\r\n //\r\n if (parentObjectIsRequired === false && (parentObjectValueIsEmpty || parentObjectErrors)) {\r\n return false\r\n }\r\n\r\n return schemaEntry.required && (\r\n typeof schemaEntry.required === 'boolean'\r\n ? schemaEntry.required\r\n : (\r\n // If there were any non-`required` errors when parsing the parent object,\r\n // the `parentObject` will be `undefined`. In that case, \"complex\" `required()`\r\n // validations — the ones where `required` is a function — can't really be run\r\n // because those validations assume a fully and correctly parsed parent object\r\n // be passed as an argument, and the thing is that the `parentObject` is unknown.\r\n // As a result, only \"basic\" `required` validations could be run,\r\n // i.e. the ones where `required` is just a boolean, and \"complex\" `required`\r\n // validations, i.e. the ones where `required` is a functions, should be skipped,\r\n // because it's better to skip some `required` errors than to trigger falsy ones.\r\n parentObjectErrors ? false : schemaEntry.required(parentObjectValue)\r\n )\r\n )\r\n}\r\n\r\nfunction createError({\r\n column,\r\n columnIndex,\r\n valueType,\r\n value,\r\n error: errorMessage,\r\n reason\r\n}) {\r\n const error = {\r\n error: errorMessage,\r\n column,\r\n columnIndex,\r\n value\r\n }\r\n if (reason) {\r\n error.reason = reason\r\n }\r\n // * Regular values specify a `type?` property, which is included in the `error` object.\r\n // * Nested objects specify a `schema` property, which is not included in the `error` object.\r\n if (valueType) {\r\n error.type = valueType\r\n }\r\n return error\r\n}\r\n\r\nfunction validateSchema(schema) {\r\n for (const key of Object.keys(schema)) {\r\n const schemaEntry = schema[key]\r\n // Validate that the `schema` is not using a deprecated `type: nestedSchema` format.\r\n if (typeof schemaEntry.type === 'object' && !Array.isArray(schemaEntry.type)) {\r\n throw new Error('When defining a nested schema, use a `schema` property instead of a `type` property')\r\n }\r\n // Validate that every property has a source `column` title specified for it.\r\n if (!schemaEntry.schema) {\r\n if (!schemaEntry.column) {\r\n throw new Error(`\"column\" not defined for schema entry \"${key}\".`)\r\n }\r\n }\r\n }\r\n\r\n // A nested object could have a `required` property but the only allowed value is `false`.\r\n // The reason why `true` value is not allowed is because in case of a \"required\" error\r\n // there's no single column title corresponding to such nested object, and column title\r\n // is required to create a \"required\" error.\r\n validateObjectSchemaRequiredProperty(schema, undefined)\r\n}\r\n\r\nfunction validateObjectSchemaRequiredProperty(schema, required) {\r\n if (required !== undefined && required !== false) {\r\n throw new Error(`In a schema, a nested object can have a \\`required\\` property but the only allowed value is \\`undefined\\` or \\`false\\`. Otherwise, a \"required\" error for a nested object would have to include a specific \\`column\\` title and a nested object doesn't have one. You've specified the following \\`required\\`: ${required}`)\r\n }\r\n // For each property of the described object.\r\n for (const key of Object.keys(schema)) {\r\n // If this property is itself an object.\r\n if (isObject(schema[key].schema)) {\r\n // Validate that a `column` property can't coexist with a `schema` property.\r\n if (schema[key].column) {\r\n throw new Error(`In a schema, \\`column\\` property is only allowed when describing a property value rather than a nested object. Key: ${key}. Schema:\\n${JSON.stringify(schema[key], null, 2)}`)\r\n }\r\n // Recurse into the child object.\r\n validateObjectSchemaRequiredProperty(schema[key].schema, schema[key].required)\r\n }\r\n }\r\n}\r\n\r\nfunction isEmptyValue(value) {\r\n return value === undefined || value === null\r\n}\r\n\r\nconst DEFAULT_OPTIONS = {\r\n propertyValueWhenColumnIsMissing: undefined,\r\n propertyValueWhenCellIsEmpty: null,\r\n // shouldSkipRequiredValidationWhenColumnIsMissing: () => false,\r\n // `transformEmptyObject(object, { path })` applies to both the top-level object\r\n // and any of its nested objects.\r\n transformEmptyObject: () => null,\r\n transformEmptyArray: () => null,\r\n separatorCharacter: ','\r\n}\r\n\r\nfunction applyDefaultOptions(options) {\r\n if (options) {\r\n return {\r\n ...DEFAULT_OPTIONS,\r\n ...options\r\n }\r\n } else {\r\n return DEFAULT_OPTIONS\r\n }\r\n}\r\n\r\n// This `value` marks the start of a tree structure that is parsed from a given data row.\r\nconst PARSED_OBJECT_TREE_START = {}\r\n\r\nconst objectConstructor = {}.constructor\r\n\r\nfunction isObject(object) {\r\n return object !== undefined && object !== null && object.constructor === objectConstructor\r\n}"],"mappings":";;;;;;;;;;;;;;;AAAA,OAAOA,UAAU,MAAM,mBAAmB;AAC1C,OAAOC,UAAU,MAAM,mBAAmB;AAC1C,OAAOC,WAAW,MAAM,oBAAoB;AAC5C,OAAOC,QAAQ,MAAM,iBAAiB;;AAEtC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,cAAcA,CAACC,IAAI,EAAEC,MAAM,EAAEC,aAAa,EAAE;EAClE,IAAMC,OAAO,GAAG,EAAE;EAClB,IAAIC,MAAM,GAAG,EAAE;EAEf,IAAMC,UAAU,GAAGC,8BAA8B,CAACN,IAAI,EAAEC,MAAM,EAAEC,aAAa,CAAC;EAC9E,IAAIK,cAAc,GAAG,CAAC;EACtB,SAAAC,SAAA,GAAAC,+BAAA,CAA4CJ,UAAU,GAAAK,KAAA,IAAAA,KAAA,GAAAF,SAAA,IAAAG,IAAA,GAAE;IAAA,IAAAC,WAAA,GAAAF,KAAA,C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C;AAEA,IAAMwH,eAAe,GAAG;EACtBzE,gCAAgC,EAAExB,SAAS;EAC3CoC,4BAA4B,EAAE,IAAI;EAClC;EACA;EACA;EACAuC,oBAAoB,EAAE,SAAAA,qBAAA;IAAA,OAAM,IAAI;EAAA;EAChCC,mBAAmB,EAAE,SAAAA,oBAAA;IAAA,OAAM,IAAI;EAAA;EAC/B/B,kBAAkB,EAAE;AACtB,CAAC;AAED,SAASxD,mBAAmBA,CAACD,OAAO,EAAE;EACpC,IAAIA,OAAO,EAAE;IACX,OAAAL,aAAA,CAAAA,aAAA,KACKkH,eAAe,GACf7G,OAAO;EAEd,CAAC,MAAM;IACL,OAAO6G,eAAe;EACxB;AACF;;AAEA;AACA,IAAM7F,wBAAwB,GAAG,CAAC,CAAC;AAEnC,IAAM8F,iBAAiB,GAAG,CAAC,CAAC,CAACC,WAAW;AAExC,SAASzB,QAAQA,CAAChG,MAAM,EAAE;EACxB,OAAOA,MAAM,KAAKsB,SAAS,IAAItB,MAAM,KAAK,IAAI,IAAIA,MAAM,CAACyH,WAAW,KAAKD,iBAAiB;AAC5F"}
1
+ {"version":3,"file":"parseSheetData.js","names":["NumberType","StringType","BooleanType","DateType","parseSheetData","data","schema","optionsCustom","objects","errors","parsedRows","parseSheetDataWithPerRowErrors","parsedRowIndex","_iterator","_createForOfIteratorHelperLoose","_step","done","_step$value","value","object","rowErrors","concat","map","rowError","_objectSpread","row","push","length","validateSchema","options","applyDefaultOptions","_data","_toArray","columns","dataRows","slice","parseDataRow","dataRow","schemaEntry","_parseProperty","parseProperty","undefined","isEmptyValue","children","dummyParentObject","PARSED_OBJECT_TREE_START","isRequired","requiredErrors","runPendingRequiredValidations","transformValue","parseObject","path","isEmptyObject","_i","_Object$keys","Object","keys","key","child","getPropertyPath","columnIndex","column","indexOf","isMissingColumn","_ref","propertyValueWhenColumnIsMissing","parseCellValueWithPossibleErrors","cellValue","_parseCellValue","parseCellValue","errorMessage","error","errorReason","reason","createError","valueType","type","propertyValueWhenCellIsEmpty","Array","isArray","parseArrayValue","parseValue","isEmptyArray","reasons","values","parseSeparatedSubstrings","separatorCharacter","substring","_parseValue","result","parseValueOfType","oneOf","errorAndReason","validateOneOf","validate","message","String","parseValueUsingTypeParser","Number","Date","Boolean","Error","name","parsedValue","getNextSubstring","string","startIndex","i","character","elements","index","_getNextSubstring","_getNextSubstring2","_slicedToArray","trim","isObject","transformEmptyObject","transformEmptyArray","propertyName","parentObjectPath","parentObjectIsRequired","parentObjectValue","parentObjectValueIsEmpty","parentObjectErrors","isPropertyRequired","_iterator2","_step2","requiredErrorsOfChild","required","_ref2","_i2","_Object$keys2","_typeof","validateObjectSchemaRequiredProperty","_i3","_Object$keys3","JSON","stringify","DEFAULT_OPTIONS","objectConstructor","constructor"],"sources":["../../source/parseSheetData/parseSheetData.js"],"sourcesContent":["import NumberType from './types/Number.js'\r\nimport StringType from './types/String.js'\r\nimport BooleanType from './types/Boolean.js'\r\nimport DateType from './types/Date.js'\r\n\r\n/**\r\n * Converts spreadsheet-alike data structure into an array of JSON objects.\r\n *\r\n * Parameters:\r\n *\r\n * * `data` — An array of rows, each row being an array of cells. The first row should be the list of column headers and the rest of the rows should be the data.\r\n * * `schema` — A \"to JSON\" convertion schema (see above).\r\n * * `options` — (optional) Schema conversion parameters of `read-excel-file`:\r\n * * `propertyValueWhenColumnIsMissing` — By default, when some of the `schema` columns are missing in the input `data`, those properties are set to `undefined` in the output objects. Pass `propertyValueWhenColumnIsMissing: null` to set such \"missing column\" properties to `null` in the output objects.\r\n * * `propertyValueWhenCellIsEmpty` — By default, when it encounters a `null` value in a cell in input `data`, it sets it to `undefined` in the output object. Pass `propertyValueWhenCellIsEmpty: null` to make it set such values as `null`s in output objects.\r\n * // * `shouldSkipRequiredValidationWhenColumnIsMissing: (column: string, { object }) => boolean` — By default, it does apply `required` validation to `schema` properties for which columns are missing in the input `data`. One could pass a custom `shouldSkipRequiredValidationWhenColumnIsMissing(column, { object })` to disable `required` validation for missing columns in some or all cases.\r\n * * `transformEmptyObject(object, { path? })` — By default, it returns `null` for \"empty\" objects. One could override that value using `transformEmptyObject(object, { path })` parameter. The value applies to both top-level object and any nested sub-objects in case of a nested schema, hence the additional (optional) `path?: string` parameter.\r\n * * `transformEmptyArray(array, { path })` — By default, it returns `null` for an \"empty\" array value. One could override that value using `transformEmptyArray(array, { path })` parameter.\r\n * * `separatorCharacter` — By default, it splits array-type cell values by a comma character.\r\n *\r\n * When parsing a property value, in case of an error, the value of that property is gonna be `undefined`.\r\n *\r\n * @param {SheetData} data - An array of rows, each row being an array of cells.\r\n * @param {object} schema\r\n * @param {object} [options]\r\n * @param {any} [options.propertyValueWhenColumnIsMissing] — By default, when some of the `schema` columns are missing in the input `data`, those properties are set to `undefined` in the output objects. Pass `propertyValueWhenColumnIsMissing: null` to set such \"missing column\" properties to `null` in the output objects.\r\n * @param {any} [options.propertyValueWhenCellIsEmpty] — By default, when it encounters a `null` value in a cell in input `data`, it leaves the value as is. Pass a custom `propertyValueWhenCellIsEmpty` to make it set such values to that value.\r\n * // @param {boolean} [options.shouldSkipRequiredValidationWhenColumnIsMissing(column: string, { object })] — By default, it does apply `required` validation to `schema` properties for which columns are missing in the input `data`. One could pass a custom `shouldSkipRequiredValidationWhenColumnIsMissing(column, { object })` to disable `required` validation for missing columns in some or all cases.\r\n * @param {function} [options.transformEmptyObject(object, { path })] — By default, it returns `null` for an \"empty\" resulting object. One could override that value using `transformEmptyObject(object, { path })` parameter. The value applies to both top-level object and any nested sub-objects in case of a nested schema, hence the additional `path?: string` parameter.\r\n * @param {function} [options.transformEmptyArray(array, { path })] — By default, it returns `null` for an \"empty\" array value. One could override that value using `transformEmptyArray(array, { path })` parameter.\r\n * @param {string} [options.separatorCharacter] — When specified, string values will be split by this separator to get the array.\r\n * @return {object} — An object of shape `{ objects, errors }`. Either `objects` or `errors` is going to be `undefined`.\r\n */\r\nexport default function parseSheetData(data, schema, optionsCustom) {\r\n const objects = []\r\n let errors = []\r\n\r\n const parsedRows = parseSheetDataWithPerRowErrors(data, schema, optionsCustom)\r\n let parsedRowIndex = 0\r\n for (const { object, errors: rowErrors } of parsedRows) {\r\n if (rowErrors) {\r\n errors = errors.concat(\r\n rowErrors.map(\r\n // Add row number property to each row error.\r\n rowError => ({ ...rowError, row: parsedRowIndex + 1 })\r\n )\r\n )\r\n } else {\r\n objects.push(object)\r\n }\r\n parsedRowIndex++\r\n }\r\n\r\n if (errors.length > 0) {\r\n return { errors }\r\n }\r\n\r\n return { objects }\r\n}\r\n\r\n// This one is only used in tests.\r\nexport function parseSheetDataWithPerRowErrors(data, schema, optionsCustom) {\r\n validateSchema(schema)\r\n\r\n const options = applyDefaultOptions(optionsCustom)\r\n\r\n const [columns, ...dataRows] = data\r\n\r\n return dataRows.map(row => parseDataRow(row, schema, columns, options))\r\n}\r\n\r\nfunction parseDataRow(dataRow, schema, columns, options) {\r\n // Create a `schemaEntry` for the top-level object.\r\n const schemaEntry = {\r\n schema\r\n }\r\n\r\n // Parse the values in the given data row into an object.\r\n const {\r\n value,\r\n isEmptyValue,\r\n errors,\r\n children\r\n } = parseProperty(dataRow, schemaEntry, undefined, columns, options)\r\n\r\n // Simulate a \"dummy\" parent object for the top-level object.\r\n // It will be used when running `required` validations.\r\n const dummyParentObject = {\r\n // The \"dummy\" parent object has a \"dummy\" value.\r\n // This value is irrelevant because it won't be read anywhere.\r\n value: PARSED_OBJECT_TREE_START,\r\n // The \"dummy\" parent object is empty if the parsed row is empty.\r\n isEmptyValue,\r\n // The \"dummy\" object has the same errors as the parsed row.\r\n errors,\r\n // The parsed object by default is not required to have any data\r\n // so the \"dummy\" object is not required.\r\n isRequired: undefined\r\n }\r\n\r\n // Run any `required` validations.\r\n //\r\n // `required` validations should be run after the entire data row has been parsed,\r\n // i.e. when the entire object structure has been parsed.\r\n // The reason is that a `required` validation could be either a simple boolean or a \"complex\" function.\r\n // In the latter case, the result of a `required()` function may depend on any other property of the object,\r\n // hence the actual `required` flag value could only be obtained after the entire data row has been parsed.\r\n //\r\n // For example, consider a top-level object:\r\n //\r\n // {\r\n // firstName: string,\r\n // lastName: string,\r\n // pet?: { name: string }\r\n // }\r\n //\r\n // A corresponding schema would be:\r\n //\r\n // {\r\n // firstName: {\r\n // required: true\r\n // },\r\n // lastName: {\r\n // required: true\r\n // },\r\n // pet: {\r\n // required: false,\r\n // schema: {\r\n // name: {\r\n // required: true\r\n // }\r\n // }\r\n // }\r\n // }\r\n //\r\n // I.e. when a `pet` exists, it must have a `name`.\r\n //\r\n // In such case, the `required: true` check of the `pet`'s `name` property\r\n // should not be performed if the `pet` is not present, because the `pet` nested object\r\n // is marked as `required: false`, meaning that `pet` data is not required to be present.\r\n //\r\n const requiredErrors = runPendingRequiredValidations(\r\n schemaEntry,\r\n value,\r\n isEmptyValue,\r\n errors,\r\n children,\r\n // Simulate a \"dummy\" parent object for the top-level object.\r\n dummyParentObject.isRequired,\r\n dummyParentObject.value,\r\n dummyParentObject.isEmptyValue,\r\n dummyParentObject.errors,\r\n columns\r\n )\r\n\r\n // If there were any errors, whether caused by `required`\r\n // or occured while parsing the values, return those errors.\r\n if (errors || requiredErrors) {\r\n return {\r\n errors: (errors || []).concat(requiredErrors || [])\r\n }\r\n }\r\n\r\n // Return the parsed object.\r\n return {\r\n object: transformValue(value, isEmptyValue, undefined, options)\r\n }\r\n}\r\n\r\nfunction parseObject(row, schema, path, columns, options) {\r\n const object = {}\r\n let isEmptyObject = true\r\n\r\n let errors = []\r\n\r\n const children = []\r\n\r\n // For each property of the object.\r\n for (const key of Object.keys(schema)) {\r\n const child = parseProperty(row, schema[key], getPropertyPath(key, path), columns, options)\r\n\r\n if (child.errors) {\r\n errors = errors.concat(child.errors)\r\n } else {\r\n object[key] = transformValue(child.value, child.isEmptyValue, getPropertyPath(key, path), options)\r\n // Potentially unmark the object as \"empty\".\r\n if (isEmptyObject && !child.isEmptyValue) {\r\n isEmptyObject = false\r\n }\r\n }\r\n\r\n children.push({\r\n ...child,\r\n // `schemaEntry` will be used when running `required` validation of this property (later),\r\n schemaEntry: schema[key]\r\n })\r\n }\r\n\r\n // If there were any errors, return them.\r\n if (errors.length > 0) {\r\n return {\r\n // Return the errors.\r\n errors,\r\n // Return the `children` because `required` validations still have to be run (later).\r\n children\r\n }\r\n }\r\n\r\n return {\r\n value: object,\r\n isEmptyValue: isEmptyObject,\r\n // Return the `children` because `required` validations still have to be run (later).\r\n children\r\n }\r\n}\r\n\r\nfunction parseProperty(row, schemaEntry, path, columns, options) {\r\n const columnIndex = schemaEntry.column ? columns.indexOf(schemaEntry.column) : undefined\r\n const isMissingColumn = schemaEntry.column ? columnIndex < 0 : undefined\r\n\r\n const {\r\n value,\r\n isEmptyValue,\r\n errors,\r\n children\r\n } = schemaEntry.column\r\n ? (\r\n isMissingColumn\r\n ? { value: options.propertyValueWhenColumnIsMissing, isEmptyValue: true }\r\n : parseCellValueWithPossibleErrors(row[columnIndex], schemaEntry, columnIndex, options)\r\n )\r\n : parseObject(\r\n row,\r\n schemaEntry.schema,\r\n path,\r\n columns,\r\n options\r\n )\r\n\r\n // If there were any errors, return them.\r\n if (errors) {\r\n return {\r\n // Return the errors.\r\n errors,\r\n // Return the `children` because `required` validations still have to be run (later).\r\n children\r\n }\r\n }\r\n\r\n return {\r\n value,\r\n isEmptyValue,\r\n // Return the `children` because `required` validations still have to be run (later).\r\n children\r\n }\r\n}\r\n\r\nfunction parseCellValueWithPossibleErrors(cellValue, schemaEntry, columnIndex, options) {\r\n const {\r\n value,\r\n isEmptyValue,\r\n error: errorMessage,\r\n reason: errorReason\r\n } = parseCellValue(cellValue, schemaEntry, options)\r\n\r\n if (errorMessage) {\r\n const error = createError({\r\n error: errorMessage,\r\n reason: errorReason,\r\n column: schemaEntry.column,\r\n columnIndex,\r\n valueType: schemaEntry.type,\r\n value: cellValue\r\n })\r\n return {\r\n errors: [error]\r\n }\r\n }\r\n\r\n return {\r\n value,\r\n isEmptyValue\r\n }\r\n}\r\n\r\n/**\r\n * Converts a cell value value to a javascript typed value.\r\n * @param {any} cellValue\r\n * @param {object} schemaEntry\r\n * @param {string} propertyPath\r\n * @param {object} options\r\n * @return {{ value?: any, isEmptyValue: boolean } | { error: string, reason?: string }}\r\n */\r\nfunction parseCellValue(cellValue, schemaEntry, options) {\r\n if (cellValue === undefined) {\r\n // This isn't supposed to be possible when reading spreadsheet data:\r\n // cell values are always read as `null` when those cells are empty.\r\n // It's currently impossible for `read-excel-file` to return `undefined` cell value.\r\n // Here it uses some \"sensible default\" fallback by treating `undefined` as \"column missing\".\r\n return {\r\n value: options.propertyValueWhenColumnIsMissing,\r\n isEmptyValue: true\r\n }\r\n }\r\n\r\n if (cellValue === null) {\r\n return {\r\n value: options.propertyValueWhenCellIsEmpty,\r\n isEmptyValue: true\r\n }\r\n }\r\n\r\n // Parse comma-separated cell value.\r\n if (Array.isArray(schemaEntry.type)) {\r\n return parseArrayValue(cellValue, schemaEntry, options)\r\n }\r\n\r\n return parseValue(cellValue, schemaEntry, options)\r\n}\r\n\r\n/**\r\n * Converts textual value to a javascript typed array value.\r\n * @param {any} value\r\n * @param {object} schemaEntry\r\n * @param {object} options\r\n * @return {{ value?: any, isEmptyValue: boolean } | { error: string, reason?: string }}\r\n */\r\nfunction parseArrayValue(value, schemaEntry, options) {\r\n // If the cell value is not a string — i.e. a number, a boolean, a Date —\r\n // then throw an error.\r\n if (typeof value !== 'string') {\r\n return {\r\n error: 'not_a_string'\r\n }\r\n }\r\n\r\n let isEmptyArray = true\r\n\r\n const errors = []\r\n const reasons = []\r\n\r\n const values = parseSeparatedSubstrings(value, options.separatorCharacter).map((substring) => {\r\n // If any substring was already detected to be invalid\r\n // don't attempt to parse any other substrings.\r\n if (errors.length > 0) {\r\n return\r\n }\r\n\r\n // If an empty substring was extracted, it means that there was an out-of-place separator.\r\n if (!substring) {\r\n errors.push('invalid')\r\n reasons.push('syntax')\r\n return\r\n }\r\n\r\n const {\r\n value,\r\n isEmptyValue,\r\n error,\r\n reason\r\n } = parseValue(substring, schemaEntry, options)\r\n\r\n if (error) {\r\n errors.push(error)\r\n reasons.push(reason)\r\n return\r\n }\r\n\r\n if (isEmptyArray && !isEmptyValue) {\r\n isEmptyArray = false\r\n }\r\n\r\n return value\r\n })\r\n\r\n if (errors.length > 0) {\r\n return {\r\n error: errors[0],\r\n reason: reasons[0]\r\n }\r\n }\r\n\r\n return {\r\n value: values,\r\n isEmptyValue: isEmptyArray\r\n }\r\n}\r\n\r\n/**\r\n * Converts textual value to a javascript typed value.\r\n * @param {any} value\r\n * @param {object} schemaEntry\r\n * @param {object} options\r\n * @return {{ value?: any, isEmptyValue: boolean } | { error: string }}\r\n */\r\nexport function parseValue(value, schemaEntry, options) {\r\n // `null` values (i.e. empty cells) don't get parsed.\r\n if (value === null) {\r\n return {\r\n value: null,\r\n isEmptyValue: true\r\n }\r\n }\r\n\r\n // Parse the value according to the `type` that is specified in the schema entry.\r\n let result\r\n if (schemaEntry.type) {\r\n result = parseValueOfType(\r\n value,\r\n // Get the type of the value.\r\n //\r\n // Handle the case if it's a comma-separated value.\r\n // Example `type`: String[]\r\n // Example Input Value: 'Barack Obama, \"String, with, colons\", Donald Trump'\r\n // Example Parsed Value: ['Barack Obama', 'String, with, colons', 'Donald Trump']\r\n //\r\n Array.isArray(schemaEntry.type) ? schemaEntry.type[0] : schemaEntry.type,\r\n options\r\n )\r\n } else {\r\n // If the `type` is not specified for a given schema entry, the `value` will be returned as is.\r\n result = { value }\r\n // throw new Error('Invalid schema entry: no `type` specified:\\n\\n' + JSON.stringify(schemaEntry, null, 2))\r\n }\r\n\r\n // If there was an error when parsing the value then return the error.\r\n if (result.error) {\r\n return result\r\n }\r\n\r\n // If the parsed value is empty, return it.\r\n if (value === null) {\r\n return {\r\n value: null,\r\n isEmptyValue: true\r\n }\r\n }\r\n\r\n // Value is not empty.\r\n // Validate it and return.\r\n\r\n // Perform `oneOf` validation.\r\n if (schemaEntry.oneOf) {\r\n const errorAndReason = validateOneOf(result.value, schemaEntry.oneOf)\r\n if (errorAndReason) {\r\n return errorAndReason\r\n }\r\n }\r\n\r\n // Perform `validate()` validation.\r\n if (schemaEntry.validate) {\r\n try {\r\n schemaEntry.validate(result.value)\r\n } catch (error) {\r\n return { error: error.message }\r\n }\r\n }\r\n\r\n // Return the value.\r\n return {\r\n value: result.value,\r\n isEmptyValue: isEmptyValue(result.value)\r\n }\r\n}\r\n\r\nfunction validateOneOf(value, oneOf) {\r\n if (oneOf.indexOf(value) < 0) {\r\n return { error: 'invalid', reason: 'unknown' }\r\n }\r\n}\r\n\r\n/**\r\n * Converts cell value to a javascript typed value.\r\n * @param {(string|number|boolean|Date)} value\r\n * @param {function} type\r\n * @return {object} Either `{ value: (string|number|Date|boolean) }` or `{ error: string, reason?: string }`\r\n */\r\nfunction parseValueOfType(value, type) {\r\n switch (type) {\r\n case String:\r\n return parseValueUsingTypeParser(value, StringType)\r\n\r\n case Number:\r\n return parseValueUsingTypeParser(value, NumberType)\r\n\r\n case Date:\r\n return parseValueUsingTypeParser(value, DateType)\r\n\r\n case Boolean:\r\n return parseValueUsingTypeParser(value, BooleanType)\r\n\r\n default:\r\n // Validate `type`\r\n if (typeof type !== 'function') {\r\n throw new Error(`Unsupported schema \\`type\\`: ${type && type.name || type}`)\r\n }\r\n return parseValueUsingTypeParser(value, type)\r\n }\r\n}\r\n\r\n/**\r\n * Converts textual value to a custom value using supplied `type`.\r\n * @param {any} value\r\n * @param {function} type\r\n * @return {{ value: any, error: string }}\r\n */\r\nfunction parseValueUsingTypeParser(value, type) {\r\n try {\r\n const parsedValue = type(value)\r\n // Returning `undefined` from a `type` parser is treated as returning `null`.\r\n if (parsedValue === undefined) {\r\n return { value: null }\r\n }\r\n return { value: parsedValue }\r\n } catch (error) {\r\n const result = { error: error.message }\r\n // Built-in types such as `Number` or `Date` may also report\r\n // a specific `reason` of the error.\r\n if (error.reason) {\r\n result.reason = error.reason;\r\n }\r\n return result\r\n }\r\n}\r\n\r\n// Extracts a substring from a string.\r\nexport function getNextSubstring(string, separatorCharacter, startIndex) {\r\n let i = 0\r\n let substring = ''\r\n while (startIndex + i < string.length) {\r\n const character = string[startIndex + i]\r\n if (character === separatorCharacter) {\r\n return [substring, i]\r\n }\r\n // Previously, it used to treat `\"` character similar to how it's treated in `.csv` files:\r\n // any commas inside quotes are ignored. But then I thought that it could introduce more\r\n // issues than it was originally intending to fix, and it also didn't provide an \"escape\" mechanism.\r\n // Overall, a decision was made to simplify the whole thing and drop the concept of quotes as special characters.\r\n //\r\n // else if (character === '\"') {\r\n // const quotedSubstring = getNextSubstring(string, '\"', startIndex + i + 1)\r\n // substring += quotedSubstring[0]\r\n // i += '\"'.length + quotedSubstring[1] + '\"'.length\r\n // }\r\n else {\r\n substring += character\r\n i++\r\n }\r\n }\r\n return [substring, i]\r\n}\r\n\r\n/**\r\n * Parses a string of comma-separated substrings into an array of substrings.\r\n * (the `export` is just for tests)\r\n * @param {string} string — A string of comma-separated substrings.\r\n * @return {string[]} An array of substrings.\r\n */\r\nexport function parseSeparatedSubstrings(string, separatorCharacter) {\r\n const elements = []\r\n let index = 0\r\n while (index < string.length) {\r\n const [substring, length] = getNextSubstring(string, separatorCharacter, index)\r\n index += length + separatorCharacter.length\r\n elements.push(substring.trim())\r\n }\r\n return elements\r\n}\r\n\r\nfunction transformValue(value, isEmptyValue, path, options) {\r\n if (isEmptyValue) {\r\n if (isObject(value)) {\r\n return options.transformEmptyObject(value, { path })\r\n } else if (Array.isArray(value)) {\r\n return options.transformEmptyArray(value, { path })\r\n }\r\n }\r\n return value\r\n}\r\n\r\nfunction getPropertyPath(propertyName, parentObjectPath) {\r\n return `${parentObjectPath ? parentObjectPath + '.' : ''}${propertyName}`\r\n}\r\n\r\n// Recursively runs `required` validations for the parsed data row tree.\r\nfunction runPendingRequiredValidations(\r\n schemaEntry,\r\n value,\r\n isEmptyValue,\r\n errors,\r\n children,\r\n parentObjectIsRequired,\r\n parentObjectValue,\r\n parentObjectValueIsEmpty,\r\n parentObjectErrors,\r\n columns\r\n) {\r\n let requiredErrors = []\r\n\r\n // See if this property is required.\r\n const isRequired = isPropertyRequired(\r\n schemaEntry,\r\n parentObjectIsRequired,\r\n parentObjectValue,\r\n parentObjectValueIsEmpty,\r\n parentObjectErrors\r\n )\r\n\r\n // If this property is required and empty, create a \"required\" error.\r\n if (isRequired && isEmptyValue) {\r\n requiredErrors.push(createError({\r\n error: 'required',\r\n column: schemaEntry.column,\r\n columnIndex: columns.indexOf(schemaEntry.column),\r\n valueType: schemaEntry.type,\r\n value\r\n }))\r\n }\r\n\r\n // Run `required` validations of the children.\r\n if (children) {\r\n for (const child of children) {\r\n const requiredErrorsOfChild = runPendingRequiredValidations(\r\n child.schemaEntry,\r\n child.value,\r\n child.isEmptyValue,\r\n child.errors,\r\n child.children,\r\n // The following properties describe the parent object of the `child`,\r\n // i.e. the current (iterated) object.\r\n isRequired,\r\n value,\r\n isEmptyValue,\r\n errors,\r\n columns\r\n )\r\n if (requiredErrorsOfChild) {\r\n requiredErrors = requiredErrors.concat(requiredErrorsOfChild)\r\n }\r\n }\r\n }\r\n if (requiredErrors.length > 0) {\r\n return requiredErrors\r\n }\r\n}\r\n\r\nfunction isPropertyRequired(\r\n schemaEntry,\r\n parentObjectIsRequired,\r\n parentObjectValue,\r\n parentObjectValueIsEmpty,\r\n parentObjectErrors\r\n) {\r\n // If the parent object is marked as `required: false` then it's allowed\r\n // to be absent entirely from the input data. If that's the case,\r\n // i.e. if the parent object is absent entirely from the input data,\r\n // then any descendant properties of such object are allowed to be absent too,\r\n // which means that they should also be considered being `required: false`.\r\n //\r\n // Also, if the parent object couldn't be parsed due to some non-`required` errors,\r\n // it can't be known whether it's actually empty or not. In case of such uncertainty,\r\n // the code shouldn't attempt to be overly smart and do things that might not be necessary,\r\n // so such parent object is just assumed to be empty in order to not falsly trigger\r\n // any `required` validations that otherwise wouldn't have been run.\r\n // In other words, skipping some `required` validations is better than\r\n // running `required` validations that shouldn't have been run.\r\n //\r\n if (parentObjectIsRequired === false && (parentObjectValueIsEmpty || parentObjectErrors)) {\r\n return false\r\n }\r\n\r\n return schemaEntry.required && (\r\n typeof schemaEntry.required === 'boolean'\r\n ? schemaEntry.required\r\n : (\r\n // If there were any non-`required` errors when parsing the parent object,\r\n // the `parentObject` will be `undefined`. In that case, \"complex\" `required()`\r\n // validations — the ones where `required` is a function — can't really be run\r\n // because those validations assume a fully and correctly parsed parent object\r\n // be passed as an argument, and the thing is that the `parentObject` is unknown.\r\n // As a result, only \"basic\" `required` validations could be run,\r\n // i.e. the ones where `required` is just a boolean, and \"complex\" `required`\r\n // validations, i.e. the ones where `required` is a functions, should be skipped,\r\n // because it's better to skip some `required` errors than to trigger falsy ones.\r\n parentObjectErrors ? false : schemaEntry.required(parentObjectValue)\r\n )\r\n )\r\n}\r\n\r\nfunction createError({\r\n column,\r\n columnIndex,\r\n valueType,\r\n value,\r\n error: errorMessage,\r\n reason\r\n}) {\r\n const error = {\r\n error: errorMessage,\r\n column,\r\n columnIndex,\r\n value\r\n }\r\n if (reason) {\r\n error.reason = reason\r\n }\r\n // * Regular values specify a `type?` property, which is included in the `error` object.\r\n // * Nested objects specify a `schema` property, which is not included in the `error` object.\r\n if (valueType) {\r\n error.type = valueType\r\n }\r\n return error\r\n}\r\n\r\nfunction validateSchema(schema) {\r\n for (const key of Object.keys(schema)) {\r\n const schemaEntry = schema[key]\r\n // Validate that the `schema` is not using a deprecated `type: nestedSchema` format.\r\n if (typeof schemaEntry.type === 'object' && !Array.isArray(schemaEntry.type)) {\r\n throw new Error('When defining a nested schema, use a `schema` property instead of a `type` property')\r\n }\r\n // Validate that every property has a source `column` title specified for it.\r\n if (!schemaEntry.schema) {\r\n if (!schemaEntry.column) {\r\n throw new Error(`\"column\" not defined for schema entry \"${key}\".`)\r\n }\r\n }\r\n }\r\n\r\n // A nested object could have a `required` property but the only allowed value is `false`.\r\n // The reason why `true` value is not allowed is because in case of a \"required\" error\r\n // there's no single column title corresponding to such nested object, and column title\r\n // is required to create a \"required\" error.\r\n validateObjectSchemaRequiredProperty(schema, undefined)\r\n}\r\n\r\nfunction validateObjectSchemaRequiredProperty(schema, required) {\r\n if (required !== undefined && required !== false) {\r\n throw new Error(`In a schema, a nested object can have a \\`required\\` property but the only allowed value is \\`undefined\\` or \\`false\\`. Otherwise, a \"required\" error for a nested object would have to include a specific \\`column\\` title and a nested object doesn't have one. You've specified the following \\`required\\`: ${required}`)\r\n }\r\n // For each property of the described object.\r\n for (const key of Object.keys(schema)) {\r\n // If this property is itself an object.\r\n if (isObject(schema[key].schema)) {\r\n // Validate that a `column` property can't coexist with a `schema` property.\r\n if (schema[key].column) {\r\n throw new Error(`In a schema, \\`column\\` property is only allowed when describing a property value rather than a nested object. Key: ${key}. Schema:\\n${JSON.stringify(schema[key], null, 2)}`)\r\n }\r\n // Recurse into the child object.\r\n validateObjectSchemaRequiredProperty(schema[key].schema, schema[key].required)\r\n }\r\n }\r\n}\r\n\r\nfunction isEmptyValue(value) {\r\n return value === undefined || value === null\r\n}\r\n\r\nconst DEFAULT_OPTIONS = {\r\n propertyValueWhenColumnIsMissing: undefined,\r\n propertyValueWhenCellIsEmpty: null,\r\n // shouldSkipRequiredValidationWhenColumnIsMissing: () => false,\r\n // `transformEmptyObject(object, { path })` applies to both the top-level object\r\n // and any of its nested objects.\r\n transformEmptyObject: () => null,\r\n transformEmptyArray: () => null,\r\n separatorCharacter: ','\r\n}\r\n\r\nfunction applyDefaultOptions(options) {\r\n if (options) {\r\n return {\r\n ...DEFAULT_OPTIONS,\r\n ...options\r\n }\r\n } else {\r\n return DEFAULT_OPTIONS\r\n }\r\n}\r\n\r\n// This `value` marks the start of a tree structure that is parsed from a given data row.\r\nconst PARSED_OBJECT_TREE_START = {}\r\n\r\nconst objectConstructor = {}.constructor\r\n\r\nfunction isObject(object) {\r\n return object !== undefined && object !== null && object.constructor === objectConstructor\r\n}"],"mappings":";;;;;;;;;;;;;;;AAAA,OAAOA,UAAU,MAAM,mBAAmB;AAC1C,OAAOC,UAAU,MAAM,mBAAmB;AAC1C,OAAOC,WAAW,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KAAKD,iBAAiB;AAC5F"}
@@ -1,22 +1,44 @@
1
- import { Buffer } from 'buffer';
1
+ // This code was originally submitted by Stian Jensen.
2
+ // https://github.com/catamphetamine/read-excel-file/pull/122
2
3
 
3
- // `unzipper` has a bug when it doesn't include "@aws-sdk/client-s3" package in the `dependencies`
4
- // which causes some "bundlers" throw an error.
5
- // https://github.com/ZJONSSON/node-unzipper/issues/330
4
+ // A `*.zip` file consists of individual file entries with the "total" summary section
5
+ // placed at the end of the file rather than at the start of it, which was originally done
6
+ // to allow for easy append of data to a given `.zip` file.
7
+ // https://en.wikipedia.org/wiki/ZIP_(file_format)
6
8
  //
7
- // One workaround is to install "@aws-sdk/client-s3" package manually, which would still lead to increased bundle size.
8
- // If the code is bundled for server-side-use only, that is will not be used in a web browser,
9
- // then the increased bundle size would not be an issue.
9
+ // But this also means that reading a `*.zip` file from a stream can't really be done
10
+ // using the "officially recommended" way of first reading the "total" summary section
11
+ // and only then reading the individual file entries specified in that summary section.
10
12
  //
11
- // Another workaround could be to "alias" "@aws-sdk/client-s3" package in a "bundler" configuration file
12
- // with a path to a `*.js` file containing just "export default null". But that kind of a workaround would also
13
- // result in errors when using other packages that `import` anything from "@aws-sdk/client-s3" package,
14
- // so it's not really a workaround but more of a ticking bomb.
13
+ // So in order to be able to read a `*.zip` file from a stream, some corners have to be cut.
14
+ // For example, the "total" summary section is completely ignored and instead the reader
15
+ // should adopt "data recovery" software approach it should proactively "scan" the input stream
16
+ // for individual file entries and handle them one-by-one as they come.
15
17
  //
16
- import unzip from 'unzipper';
17
-
18
- // Althernatively, it could use `fflate` if someone writes an example of handling a Node.js stream.
18
+ // Such approach doesn't seem to contradict with the XLSX specification
19
+ // because an `*.xlsx` files is supposed to be a normal `.zip` archive
20
+ // without any "trickery" such as "deleted" files or "garbage" data
21
+ // hiding under the hood.
22
+ //
23
+ // So when handling `*.xlsx` file, we assume that each such file must start
24
+ // with an individual file entry followed by another individual file entry, etc.
25
+ //
26
+ // When the "summary" section is reached, we assume that the archive has ended.
27
+ //
28
+ // To read a `.zip` archive, the code uses `fflate`'s `Unzip` class
29
+ // with `UnzipInflate` decompression implementation to decompress the data
30
+ // that was previously compressed using `DEFLATE` compressing algorithm,
31
+ // which is what `*.xlsx` files use.
32
+ //
33
+ // The `Unzip` class doesn't speak the Node.js stream interface, and `fflate`'s readme
34
+ // doesn't include a clear "reading a `.zip` file from a Node.js stream" section.
19
35
  // https://github.com/101arrowz/fflate/issues/251
36
+ // Instead, the `Unzip` class has its own `push(chunk)` / `onfile` / `entry.ondata` protocol.
37
+ // This code reads the binary input stream and forwards each chunk of it to `unzip.push()`,
38
+ // and then collects the decompressed file entries.
39
+ //
40
+ import { Unzip, UnzipInflate } from 'fflate';
41
+ import { Buffer } from 'buffer';
20
42
 
21
43
  /**
22
44
  * Reads `*.zip` file contents.
@@ -29,7 +51,6 @@ export default function unzipFromStream(stream) {
29
51
  // The `files` object stores the files and their contents.
30
52
  var files = {};
31
53
  return new Promise(function (resolve, reject) {
32
- var promises = [];
33
54
  var errored = false;
34
55
  var onError = function onError(error) {
35
56
  if (!errored) {
@@ -37,83 +58,137 @@ export default function unzipFromStream(stream) {
37
58
  reject(error);
38
59
  }
39
60
  };
40
- stream
41
- // This first "error" listener catches the original stream errors.
42
- //
43
- // That's because the .pipe() method does not automatically propagate errors
44
- // from a source (input) stream to the destination stream or the end of the pipeline.
45
- // You would need to attach an 'error' event handler to each stream in the chain.
46
- //
47
- // A more convenient alternative would be to use `stream.pipeline()` function:
48
- // `pipeline(stream1, stream2, (error) => { ... })`
49
- //
50
- .on('error', onError)
51
- // Pipe the input stream through the unzipper stream.
52
- .pipe(unzip.Parse())
53
- // This second "error" listener catches the unzipper stream errors.
54
- //
55
- // That's because the .pipe() method does not automatically propagate errors
56
- // from a source (input) stream to the destination stream or the end of the pipeline.
57
- // You would need to attach an 'error' event handler to each stream in the chain.
58
- //
59
- // A more convenient alternative would be to use `stream.pipeline()` function:
60
- // `pipeline(stream1, stream2, (error) => { ... })`
61
- //
62
- .on('error', onError)
63
- // The unzipper stream is closed when all `entries` have been reported.
64
- .on('finish', function () {
65
- if (!errored) {
66
- // Wait for all `entries` to be read.
67
- // The second argument of `.then()` function is not required
68
- // but I didn't remove it just to potentially prevent any potential silly bugs
69
- // in case of some potential changes in some potential future.
70
- Promise.all(promises).then(function () {
71
- resolve(files);
72
- }, onError);
61
+ var _createZipFileValidat = createZipFileValidator(function (isValid) {
62
+ if (!isValid) {
63
+ onError(new Error('Invalid `.zip` archive'));
64
+ }
65
+ }),
66
+ validateChunk = _createZipFileValidat.validateChunk;
67
+
68
+ // `Unzip` discovers each individual file entry in the input data stream
69
+ // and then calls the callback function for each such entry.
70
+ var unzip = new Unzip(function (entry) {
71
+ // If there already was an error while reading this `.zip` file,
72
+ // ignore any follow-up entries.
73
+ if (errored) {
74
+ return;
75
+ }
76
+
77
+ // Skip directory entries (their names end with a slash).
78
+ // Only files are of any interest.
79
+ if (entry.name.endsWith('/')) {
80
+ return;
73
81
  }
74
- }).on('entry', function (entry) {
82
+
75
83
  // See if this file should be ignored.
76
- var ignore = false;
77
- // `entry.type` could be 'Directory' or 'File'.
78
- // Ignore anything except files.
79
- if (entry.type === 'Directory') {
80
- ignore = true;
84
+ // If it should, this entry won't be processed, i.e. `Unzip` will not try
85
+ // to decompress its data, and will just discard it.
86
+ if (filter && !filter({
87
+ path: entry.name
88
+ })) {
89
+ return;
81
90
  }
91
+ var chunks = [];
92
+
93
+ // `entry.ondata` is called with each decompressed chunk of the entry,
94
+ // and a final time with `isLast === true` once the entry is complete.
95
+ entry.ondata = function (error, chunk, isLast) {
96
+ if (error) {
97
+ return onError(error);
98
+ }
99
+ chunks.push(chunk);
100
+ if (isLast) {
101
+ files[entry.name] = Buffer.concat(chunks);
102
+ }
103
+ };
104
+
105
+ // Start decompressing this entry.
106
+ entry.start();
107
+ });
108
+
109
+ // Register the decompressor for the data that was compressed using
110
+ // `DEFLATE` compression algorithm (compression method `8`),
111
+ // which is what `.xlsx` files use.
112
+ unzip.register(UnzipInflate);
113
+ stream
114
+ // Catch errors emitted from the input stream (for example, a file read error).
115
+ .on('error', onError)
116
+ // When another chunk of data is read from the input stream.
117
+ .on('data', function (chunk) {
118
+ // If there already was an error while reading this `.zip` file,
119
+ // ignore any follow-up data chunks.
82
120
  if (errored) {
83
- ignore = true;
121
+ return;
84
122
  }
85
- if (filter) {
86
- if (!filter({
87
- path: entry.path
88
- })) {
89
- ignore = true;
90
- }
123
+ // Validate the `.zip` archive as its data comes through.
124
+ validateChunk(chunk);
125
+ // If the `.zip` archive is found to be invalid, stop any further
126
+ // processing of it.
127
+ if (errored) {
128
+ return;
91
129
  }
92
-
93
- // If this file should be ignored.
94
- if (ignore) {
95
- // Call `entry.autodrain()` when you do not intend to process a specific `entry`'s raw data.
96
- // Otherwise, if an `entry` is not consumed (via .pipe(), .buffer(), or .autodrain()),
97
- // the stream will halt, preventing further file processing.
98
- entry.autodrain().on('error', onError);
130
+ // Push the next data chunk to `fflate`'s `Unzip` class instance.
131
+ // The `.push()` function is synchronous, meaning that by the time it returns,
132
+ // any complete files entries encountered so far have already been decompressed
133
+ // and populated in the `files` object.
134
+ try {
135
+ unzip.push(chunk, false);
136
+ } catch (error) {
137
+ onError(error);
138
+ }
139
+ })
140
+ // When there's no more data in the input stream to consume,
141
+ // finish reading the `.zip` archive.
142
+ .on('end', function () {
143
+ // If there were any errors when reading the `.zip` archive,
144
+ // don't `resolve()` with anything.
145
+ if (errored) {
99
146
  return;
100
147
  }
101
- var chunks = [];
102
- promises.push(new Promise(function (resolve) {
103
- // `entry` seems to be a generic Node.js stream.
104
- // `entry.pipe()` pipes the file contents to a stream.
105
- // `entry.stream()` returns a readable stream.
106
- // `entry.buffer()` returns a promise that resolves to a `Buffer` with the file contents.
107
- entry.on('data', function (data) {
108
- chunks.push(data);
109
- }).on('error', function (error) {
110
- onError(error);
111
- }).on('finish', function () {
112
- files[entry.path] = Buffer.concat(chunks);
113
- resolve();
114
- });
115
- }));
148
+ try {
149
+ // Signal the end of the archive to `fflate`'s `Unzip` class instance.
150
+ // It will flush any remaining state in it.
151
+ unzip.push(new Uint8Array(0), true);
152
+ // Resolve with the unzipped files.
153
+ resolve(files);
154
+ } catch (error) {
155
+ onError(error);
156
+ }
116
157
  });
117
158
  });
118
159
  }
160
+
161
+ // Every section in a `.zip` archive is marked with 4 bytes, the first two of which
162
+ // are `0x50` and `0x4B`, which reads "PK", referencing the initials of the inventor Phil Katz.
163
+ //
164
+ // It looks like `fflate`'s `Unzip` doesn't ever complain about whatever data is thrown at it.
165
+ // Due to how `.zip` file format is defined, "garbage" data could be placed at various
166
+ // places in it and it'd still be a valid `.zip` archive. It's likely that for this reason
167
+ // `fflate` doesn't ever complain and simply emits no entries when fed any kind of invalid data.
168
+ //
169
+ // In order to introduce some basic validation, here we specifically demand
170
+ // that a `.zip` archive must at least start with an individual file entry
171
+ // because an `.xlsx` file creator softwared really shouldn't attempt doing
172
+ // anything "funny" when writing a file, hence this adherence requirement.
173
+ //
174
+ function createZipFileValidator(onValidationResult) {
175
+ var firstBytesCount = 2;
176
+ var firstBytes = [];
177
+ var firstBytesCheckResult;
178
+ return {
179
+ validateChunk: function validateChunk(chunk) {
180
+ if (firstBytes.length < 2) {
181
+ var i = 0;
182
+ while (i < chunk.length && i < firstBytesCount) {
183
+ firstBytes.push(chunk[i]);
184
+ i++;
185
+ }
186
+ if (firstBytes.length === 2) {
187
+ var isValid = firstBytes[0] === 0x50 && firstBytes[1] === 0x4B;
188
+ onValidationResult(isValid);
189
+ }
190
+ }
191
+ }
192
+ };
193
+ }
119
194
  //# sourceMappingURL=unzipFromStream.js.map