diff --git a/packages/xlsx-import/package-lock.json b/packages/xlsx-import/package-lock.json index 0d0e7cf..610ff86 100644 --- a/packages/xlsx-import/package-lock.json +++ b/packages/xlsx-import/package-lock.json @@ -5,6 +5,7 @@ "requires": true, "packages": { "": { + "name": "xlsx-import", "version": "2.4.4", "license": "MIT", "dependencies": { @@ -13,6 +14,7 @@ "devDependencies": { "@types/chai": "^4.2.14", "@types/mocha": "^5.2.7", + "@types/node": "^20.8.2", "chai": "^4.2.0", "markdownlint-cli": "^0.31.0", "mocha": "^9.2.0", @@ -418,6 +420,11 @@ "lodash.isnil": "^4.0.0" } }, + "node_modules/@fast-csv/format/node_modules/@types/node": { + "version": "14.18.63", + "resolved": "https://registry.npmjs.org/@types/node/-/node-14.18.63.tgz", + "integrity": "sha512-fAtCfv4jJg+ExtXhvCkCqUKZ+4ok/JQk01qDKhL5BDDoS3AxKXhV5/MAVUZyQnSEd2GT92fkgZl0pz0Q0AzcIQ==" + }, "node_modules/@fast-csv/parse": { "version": "4.3.6", "resolved": "https://registry.npmjs.org/@fast-csv/parse/-/parse-4.3.6.tgz", @@ -432,6 +439,11 @@ "lodash.uniq": "^4.5.0" } }, + "node_modules/@fast-csv/parse/node_modules/@types/node": { + "version": "14.18.63", + "resolved": "https://registry.npmjs.org/@types/node/-/node-14.18.63.tgz", + "integrity": "sha512-fAtCfv4jJg+ExtXhvCkCqUKZ+4ok/JQk01qDKhL5BDDoS3AxKXhV5/MAVUZyQnSEd2GT92fkgZl0pz0Q0AzcIQ==" + }, "node_modules/@istanbuljs/load-nyc-config": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@istanbuljs/load-nyc-config/-/load-nyc-config-1.1.0.tgz", @@ -569,9 +581,10 @@ "dev": true }, "node_modules/@types/node": { - "version": "14.18.10", - "resolved": "https://registry.npmjs.org/@types/node/-/node-14.18.10.tgz", - "integrity": "sha512-6iihJ/Pp5fsFJ/aEDGyvT4pHGmCpq7ToQ/yf4bl5SbVAvwpspYJ+v3jO7n8UyjhQVHTy+KNszOozDdv+O6sovQ==" + "version": "20.8.2", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.8.2.tgz", + "integrity": "sha512-Vvycsc9FQdwhxE3y3DzeIxuEJbWGDsnrxvMADzTDF/lcdR9/K+AQIeAghTQsHtotg/q0j3WEOYS/jQgSdWue3w==", + "dev": true }, "node_modules/@ungap/promise-all-settled": { "version": "1.1.2", @@ -4060,6 +4073,13 @@ "lodash.isequal": "^4.5.0", "lodash.isfunction": "^3.0.9", "lodash.isnil": "^4.0.0" + }, + "dependencies": { + "@types/node": { + "version": "14.18.63", + "resolved": "https://registry.npmjs.org/@types/node/-/node-14.18.63.tgz", + "integrity": "sha512-fAtCfv4jJg+ExtXhvCkCqUKZ+4ok/JQk01qDKhL5BDDoS3AxKXhV5/MAVUZyQnSEd2GT92fkgZl0pz0Q0AzcIQ==" + } } }, "@fast-csv/parse": { @@ -4074,6 +4094,13 @@ "lodash.isnil": "^4.0.0", "lodash.isundefined": "^3.0.1", "lodash.uniq": "^4.5.0" + }, + "dependencies": { + "@types/node": { + "version": "14.18.63", + "resolved": "https://registry.npmjs.org/@types/node/-/node-14.18.63.tgz", + "integrity": "sha512-fAtCfv4jJg+ExtXhvCkCqUKZ+4ok/JQk01qDKhL5BDDoS3AxKXhV5/MAVUZyQnSEd2GT92fkgZl0pz0Q0AzcIQ==" + } } }, "@istanbuljs/load-nyc-config": { @@ -4188,9 +4215,10 @@ "dev": true }, "@types/node": { - "version": "14.18.10", - "resolved": "https://registry.npmjs.org/@types/node/-/node-14.18.10.tgz", - "integrity": "sha512-6iihJ/Pp5fsFJ/aEDGyvT4pHGmCpq7ToQ/yf4bl5SbVAvwpspYJ+v3jO7n8UyjhQVHTy+KNszOozDdv+O6sovQ==" + "version": "20.8.2", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.8.2.tgz", + "integrity": "sha512-Vvycsc9FQdwhxE3y3DzeIxuEJbWGDsnrxvMADzTDF/lcdR9/K+AQIeAghTQsHtotg/q0j3WEOYS/jQgSdWue3w==", + "dev": true }, "@ungap/promise-all-settled": { "version": "1.1.2", diff --git a/packages/xlsx-import/package.json b/packages/xlsx-import/package.json index 87d75ae..587733e 100644 --- a/packages/xlsx-import/package.json +++ b/packages/xlsx-import/package.json @@ -44,6 +44,7 @@ "devDependencies": { "@types/chai": "^4.2.14", "@types/mocha": "^5.2.7", + "@types/node": "^20.8.2", "chai": "^4.2.0", "markdownlint-cli": "^0.31.0", "mocha": "^9.2.0", diff --git a/packages/xlsx-import/src/Importer.ts b/packages/xlsx-import/src/Importer.ts index ed1f296..b759f93 100644 --- a/packages/xlsx-import/src/Importer.ts +++ b/packages/xlsx-import/src/Importer.ts @@ -12,7 +12,9 @@ export class Importer implements IImporter { const { worksheet } = config; const type = (config.type as ImportType) || IMPORT_TYPE_DEFAULT; const ws = this.wb.getWorksheet(worksheet); - + if (!ws) { + throw new Error(`Worksheet "${worksheet}" not found in workbook.`); + } return getStrategyByType(type)(config, ws); } diff --git a/packages/xlsx-import/tests/integration/vertical-lists.test.ts b/packages/xlsx-import/tests/integration/vertical-lists.test.ts index f1d5aa1..d39ac96 100644 --- a/packages/xlsx-import/tests/integration/vertical-lists.test.ts +++ b/packages/xlsx-import/tests/integration/vertical-lists.test.ts @@ -26,6 +26,9 @@ describe('testing vertical list - on file "marsjanie-db"', () => { ], rowOffset: 1, }, + not_existing_wroksheet: { + worksheet: 'dummy' + } }; it('worksheet "szit1"', async () => { @@ -180,4 +183,11 @@ describe('testing vertical list - on file "marsjanie-db"', () => { chai.expect(result).eql(expected); }); + + it(`should return a meaningful error when the worksheet is not found`, async() => { + const factory = new ImporterFactory(); + const importer = await factory.from('tests/data/marsjanie-db.xlsx'); + const result = () => importer.getAllItems(configs.not_existing_wroksheet); + chai.expect(result).to.throw('Worksheet "dummy" not found in workbook.'); + }); }); diff --git a/packages/xlsx-import/tsconfig.json b/packages/xlsx-import/tsconfig.json index c53df98..4bc2de5 100644 --- a/packages/xlsx-import/tsconfig.json +++ b/packages/xlsx-import/tsconfig.json @@ -6,7 +6,8 @@ "outDir": "./lib", "strict": true, "esModuleInterop": true, - "sourceMap": true + "sourceMap": true, + "lib": ["ES2015", "DOM", "ES2017", "ES2017.Object", "ESNext", "DOM.Iterable"] }, "include": ["src"], "exclude": [