From 9657fbafb1cf30b23b4da5237e553fe7a82bddee Mon Sep 17 00:00:00 2001 From: Joachim Van Herwegen Date: Thu, 17 Sep 2020 10:18:37 +0200 Subject: [PATCH] refactor: Update eslint related dependencies --- .eslintrc.js | 12 +- package-lock.json | 665 ++++++++++++------ package.json | 28 +- src/authentication/CredentialsExtractor.ts | 4 +- src/authentication/UnsecureWebIdExtractor.ts | 4 +- src/authorization/AclManager.ts | 2 +- src/authorization/Authorizer.ts | 6 +- src/authorization/UrlBasedAclManager.ts | 4 +- src/authorization/WebAclAuthorizer.ts | 22 +- src/init/CliRunner.ts | 9 +- src/init/Setup.ts | 6 +- src/ldp/AuthenticatedLdpHandler.ts | 32 +- src/ldp/http/AcceptPreferenceParser.ts | 10 +- src/ldp/http/BasicRequestParser.ts | 10 +- src/ldp/http/BasicResponseWriter.ts | 4 +- src/ldp/http/BasicTargetExtractor.ts | 6 +- src/ldp/http/BodyParser.ts | 4 +- src/ldp/http/Patch.ts | 2 +- src/ldp/http/PreferenceParser.ts | 4 +- src/ldp/http/RawBodyParser.ts | 4 +- src/ldp/http/RequestParser.ts | 4 +- src/ldp/http/ResponseWriter.ts | 4 +- src/ldp/http/SparqlUpdateBodyParser.ts | 11 +- src/ldp/http/SparqlUpdatePatch.ts | 4 +- src/ldp/http/TargetExtractor.ts | 4 +- src/ldp/operations/DeleteOperationHandler.ts | 6 +- src/ldp/operations/GetOperationHandler.ts | 6 +- src/ldp/operations/Operation.ts | 6 +- src/ldp/operations/OperationHandler.ts | 4 +- src/ldp/operations/PatchOperationHandler.ts | 8 +- src/ldp/operations/PostOperationHandler.ts | 6 +- src/ldp/operations/PutOperationHandler.ts | 6 +- src/ldp/operations/ResponseDescription.ts | 4 +- .../permissions/MethodPermissionsExtractor.ts | 4 +- src/ldp/permissions/PermissionsExtractor.ts | 4 +- .../SparqlPatchPermissionsExtractor.ts | 8 +- src/ldp/representation/Representation.ts | 4 +- .../RepresentationPreferences.ts | 2 +- src/server/ExpressHttpServer.ts | 11 +- src/server/HttpHandler.ts | 4 +- src/server/HttpRequest.ts | 2 +- src/server/HttpResponse.ts | 2 +- src/storage/AtomicResourceStore.ts | 2 +- src/storage/Conditions.ts | 2 +- src/storage/ContainerManager.ts | 2 +- src/storage/ExtensionBasedMapper.ts | 4 +- src/storage/FileIdentifierMapper.ts | 2 +- src/storage/FileResourceStore.ts | 43 +- src/storage/InMemoryResourceStore.ts | 9 +- src/storage/LockingResourceStore.ts | 18 +- src/storage/PassthroughStore.ts | 12 +- src/storage/PatchingStore.ts | 12 +- src/storage/RepresentationConvertingStore.ts | 12 +- src/storage/ResourceLocker.ts | 4 +- src/storage/ResourceStore.ts | 10 +- src/storage/SingleThreadedResourceLocker.ts | 6 +- src/storage/UrlContainerManager.ts | 4 +- src/storage/conversion/ChainedConverter.ts | 6 +- src/storage/conversion/ConversionUtil.ts | 6 +- src/storage/conversion/QuadToRdfConverter.ts | 8 +- .../conversion/QuadToTurtleConverter.ts | 5 +- src/storage/conversion/RdfToQuadConverter.ts | 4 +- .../conversion/RepresentationConverter.ts | 6 +- .../conversion/TurtleToQuadConverter.ts | 5 +- src/storage/patch/PatchHandler.ts | 4 +- src/storage/patch/SparqlUpdatePatchHandler.ts | 12 +- src/util/AcceptParser.ts | 6 +- src/util/AsyncHandler.ts | 4 +- src/util/CompositeAsyncHandler.ts | 12 +- src/util/MetadataController.ts | 4 +- src/util/UriConstants.ts | 2 +- src/util/Util.ts | 2 +- test/.eslintrc.js | 8 + .../AuthenticatedFileResourceStoreConfig.ts | 6 +- test/configs/BasicConfig.ts | 6 +- test/configs/BasicHandlersConfig.ts | 6 +- test/configs/BasicHandlersWithAclConfig.ts | 6 +- test/configs/FileResourceStoreConfig.ts | 6 +- test/configs/ServerConfig.ts | 4 +- test/configs/Util.ts | 14 +- .../AuthenticatedFileResourceStore.test.ts | 2 +- .../AuthenticatedLdpHandler.test.ts | 2 +- test/integration/Authorization.test.ts | 2 +- test/integration/FileResourceStore.test.ts | 2 +- .../RepresentationConverter.test.ts | 2 +- test/integration/RequestParser.test.ts | 2 +- .../authentication/UnsecureWebIdExtractor.ts | 2 +- .../authorization/WebAclAuthorizer.test.ts | 14 +- test/unit/init/Setup.test.ts | 2 +- test/unit/ldp/AuthenticatedLdpHandler.test.ts | 30 +- .../ldp/http/AcceptPreferenceParser.test.ts | 2 +- test/unit/ldp/http/BasicRequestParser.test.ts | 6 +- .../unit/ldp/http/BasicResponseWriter.test.ts | 5 +- test/unit/ldp/http/RawBodyParser.test.ts | 2 +- .../ldp/http/SparqlUpdateBodyParser.test.ts | 13 +- .../operations/DeleteOperationHandler.test.ts | 4 +- .../operations/GetOperationHandler.test.ts | 6 +- .../operations/PatchOperationHandler.test.ts | 4 +- .../operations/PostOperationHandler.test.ts | 6 +- .../operations/PutOperationHandler.test.ts | 4 +- .../BasePermissionsExtractor.test.ts | 2 +- .../SparqlPatchPermissionsExtractor.test.ts | 4 +- test/unit/server/ExpressHttpServer.test.ts | 30 +- test/unit/storage/FileResourceStore.test.ts | 23 +- .../storage/InMemoryResourceStore.test.ts | 4 +- .../unit/storage/LockingResourceStore.test.ts | 12 +- test/unit/storage/PassthroughStore.test.ts | 6 +- test/unit/storage/PatchingStore.test.ts | 6 +- .../RepresentationConvertingStore.test.ts | 4 +- .../conversion/ChainedConverter.test.ts | 6 +- .../storage/conversion/ConversionUtil.test.ts | 6 +- .../conversion/QuadToRdfConverter.test.ts | 6 +- .../conversion/QuadToTurtleConverter.test.ts | 6 +- .../conversion/RdfToQuadConverter.test.ts | 6 +- .../conversion/TurtleToQuadConverter.test.ts | 6 +- .../patch/SparqlUpdatePatchHandler.test.ts | 10 +- test/unit/util/AsyncHandler.test.ts | 2 +- test/unit/util/CompositeAsyncHandler.test.ts | 11 +- test/util/TestHelpers.ts | 14 +- test/util/Util.ts | 9 +- 120 files changed, 916 insertions(+), 605 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 394e2ef49..7737cfd29 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -24,9 +24,13 @@ module.exports = { } }, rules: { + '@typescript-eslint/lines-between-class-members': [ 'error', { exceptAfterSingleLine: true }], + '@typescript-eslint/naming-convention': 'off', '@typescript-eslint/no-empty-interface': 'off', + '@typescript-eslint/no-invalid-void-type': 'off', // breaks with default void in Asynchandler 2nd generic '@typescript-eslint/no-unnecessary-condition': 'off', // problems with optional parameters '@typescript-eslint/space-before-function-paren': [ 'error', 'never' ], + '@typescript-eslint/unbound-method': 'off', '@typescript-eslint/unified-signatures': 'off', 'class-methods-use-this': 'off', // conflicts with functions from interfaces that sometimes don't require `this` 'comma-dangle': ['error', 'always-multiline'], @@ -39,7 +43,10 @@ module.exports = { 'padding-line-between-statements': 'off', 'prefer-named-capture-group': 'off', 'tsdoc/syntax': 'error', + 'unicorn/catch-error-name': 'off', + 'unicorn/import-index': 'off', 'unicorn/no-fn-reference-in-iterator': 'off', // this prevents some functional programming paradigms + 'unicorn/no-object-as-default-parameter': 'off', // Import 'sort-imports': 'off', // Disabled in favor of eslint-plugin-import @@ -49,8 +56,9 @@ module.exports = { caseInsensitive: true } }], - 'unused-imports/no-unused-imports-ts': 'error', + 'import/no-duplicates': 'error', 'import/no-extraneous-dependencies': 'error', - 'unicorn/import-index': 'off' + 'no-duplicate-imports': 'off', // doesn't work with type imports + 'unused-imports/no-unused-imports-ts': 'error' }, }; diff --git a/package-lock.json b/package-lock.json index 0b86aef75..bf5be7ee3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -453,6 +453,16 @@ "requires": { "@types/rdf-js": "^3.0.0", "htmlparser2": "^4.0.0" + }, + "dependencies": { + "@types/rdf-js": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/@types/rdf-js/-/rdf-js-3.0.3.tgz", + "integrity": "sha512-1dvodNHh/YpLovHA/b046Nu+xERVt0KcYJFQH1A8S4ZcMj+stYtx4ypXw0X2/oatbREUo4JW+cjoBll3CVtwSQ==", + "requires": { + "@types/node": "*" + } + } } }, "@comunica/actor-rdf-parse-html-rdfa": { @@ -470,6 +480,16 @@ "requires": { "@types/rdf-js": "^3.0.0", "relative-to-absolute-iri": "^1.0.5" + }, + "dependencies": { + "@types/rdf-js": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/@types/rdf-js/-/rdf-js-3.0.3.tgz", + "integrity": "sha512-1dvodNHh/YpLovHA/b046Nu+xERVt0KcYJFQH1A8S4ZcMj+stYtx4ypXw0X2/oatbREUo4JW+cjoBll3CVtwSQ==", + "requires": { + "@types/node": "*" + } + } } }, "@comunica/actor-rdf-parse-jsonld": { @@ -480,6 +500,16 @@ "@types/rdf-js": "^3.0.0", "jsonld-streaming-parser": "^2.0.2", "stream-to-string": "^1.2.0" + }, + "dependencies": { + "@types/rdf-js": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/@types/rdf-js/-/rdf-js-3.0.3.tgz", + "integrity": "sha512-1dvodNHh/YpLovHA/b046Nu+xERVt0KcYJFQH1A8S4ZcMj+stYtx4ypXw0X2/oatbREUo4JW+cjoBll3CVtwSQ==", + "requires": { + "@types/node": "*" + } + } } }, "@comunica/actor-rdf-parse-n3": { @@ -524,6 +554,16 @@ "@types/rdf-js": "^3.0.0", "n3": "^1.0.0", "rdf-string": "^1.4.2" + }, + "dependencies": { + "@types/rdf-js": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/@types/rdf-js/-/rdf-js-3.0.3.tgz", + "integrity": "sha512-1dvodNHh/YpLovHA/b046Nu+xERVt0KcYJFQH1A8S4ZcMj+stYtx4ypXw0X2/oatbREUo4JW+cjoBll3CVtwSQ==", + "requires": { + "@types/node": "*" + } + } } }, "@comunica/bus-http": { @@ -554,6 +594,16 @@ "requires": { "@comunica/actor-abstract-mediatyped": "^1.15.0", "@types/rdf-js": "^3.0.0" + }, + "dependencies": { + "@types/rdf-js": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/@types/rdf-js/-/rdf-js-3.0.3.tgz", + "integrity": "sha512-1dvodNHh/YpLovHA/b046Nu+xERVt0KcYJFQH1A8S4ZcMj+stYtx4ypXw0X2/oatbREUo4JW+cjoBll3CVtwSQ==", + "requires": { + "@types/node": "*" + } + } } }, "@comunica/bus-rdf-parse-html": { @@ -562,6 +612,16 @@ "integrity": "sha512-7F/kDrNf9X//IrO/CK4LpwM5f+mFHLa/wsPc2RubyhiFN3P3KWU6NWxjDJRT9yP85EmW4KknXWwF8AOTvbKF1A==", "requires": { "@types/rdf-js": "^3.0.0" + }, + "dependencies": { + "@types/rdf-js": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/@types/rdf-js/-/rdf-js-3.0.3.tgz", + "integrity": "sha512-1dvodNHh/YpLovHA/b046Nu+xERVt0KcYJFQH1A8S4ZcMj+stYtx4ypXw0X2/oatbREUo4JW+cjoBll3CVtwSQ==", + "requires": { + "@types/node": "*" + } + } } }, "@comunica/bus-rdf-serialize": { @@ -571,6 +631,16 @@ "requires": { "@comunica/actor-abstract-mediatyped": "^1.15.0", "@types/rdf-js": "^3.0.0" + }, + "dependencies": { + "@types/rdf-js": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/@types/rdf-js/-/rdf-js-3.0.3.tgz", + "integrity": "sha512-1dvodNHh/YpLovHA/b046Nu+xERVt0KcYJFQH1A8S4ZcMj+stYtx4ypXw0X2/oatbREUo4JW+cjoBll3CVtwSQ==", + "requires": { + "@types/node": "*" + } + } } }, "@comunica/core": { @@ -596,6 +666,35 @@ "resolved": "https://registry.npmjs.org/@comunica/mediator-race/-/mediator-race-1.15.0.tgz", "integrity": "sha512-MVESJnkgSoPaCkNNN8RDm0B06d0JNL4QOvRZFuFETY4/D+OwIpcEf0EGButQsDUlelAk5n/sFssLMqo2tw65SA==" }, + "@eslint/eslintrc": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-0.1.3.tgz", + "integrity": "sha512-4YVwPkANLeNtRjMekzux1ci8hIaH5eGKktGqR0d3LWsKNn5B2X/1Z6Trxy7jQXl9EBGE6Yj02O+t09FMeRllaA==", + "dev": true, + "requires": { + "ajv": "^6.12.4", + "debug": "^4.1.1", + "espree": "^7.3.0", + "globals": "^12.1.0", + "ignore": "^4.0.6", + "import-fresh": "^3.2.1", + "js-yaml": "^3.13.1", + "lodash": "^4.17.19", + "minimatch": "^3.0.4", + "strip-json-comments": "^3.1.1" + }, + "dependencies": { + "debug": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", + "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", + "dev": true, + "requires": { + "ms": "^2.1.1" + } + } + } + }, "@hutson/parse-repository-url": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/@hutson/parse-repository-url/-/parse-repository-url-3.0.2.tgz", @@ -1102,9 +1201,9 @@ } }, "@microsoft/tsdoc": { - "version": "0.12.20", - "resolved": "https://registry.npmjs.org/@microsoft/tsdoc/-/tsdoc-0.12.20.tgz", - "integrity": "sha512-/b13m37QZYPV6nCOiqkFyvlQjlTNvAcQpgFZ6ZKIqtStJxNdqVo/frULubxMUMWi6p9Uo5f4BRlguv5ViFcL0A==", + "version": "0.12.21", + "resolved": "https://registry.npmjs.org/@microsoft/tsdoc/-/tsdoc-0.12.21.tgz", + "integrity": "sha512-j+9OJ0A0buZZaUn6NxeHUVpoa05tY2PgVs7kXJhJQiKRB0G1zQqbJxer3T7jWtzpqQWP89OBDluyIeyTsMk8Sg==", "dev": true }, "@microsoft/tsdoc-config": { @@ -1163,21 +1262,11 @@ } }, "@rdfjs/data-model": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/@rdfjs/data-model/-/data-model-1.1.2.tgz", - "integrity": "sha512-pk/G/JLYGaXesoBLvEmoC/ic0H3B79fTyS0Ujjh5YQB2DZW+mn05ZowFFv88rjB9jf7c1XE5XSmf8jzn6U0HHA==", + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@rdfjs/data-model/-/data-model-1.2.0.tgz", + "integrity": "sha512-6ITWcu2sr9zJqXUPDm1XJ8DRpea7PotWBIkTzuO1MCSruLOWH2ICoQOAtlJy30cT+GqH9oAQKPR+CHXejsdizA==", "requires": { - "@types/rdf-js": "^2.0.1" - }, - "dependencies": { - "@types/rdf-js": { - "version": "2.0.12", - "resolved": "https://registry.npmjs.org/@types/rdf-js/-/rdf-js-2.0.12.tgz", - "integrity": "sha512-NBzHFHp2vHOJkPlSqzsOrkEsD9grKn+PdFjZieIw59pc0FlRG6WEQAjQZvHzFxJlYzC6ZDCFyTA1wBvUnnzUQw==", - "requires": { - "@types/node": "*" - } - } + "@types/rdf-js": "*" } }, "@sindresorhus/is": { @@ -1303,12 +1392,6 @@ "@types/express": "*" } }, - "@types/eslint-visitor-keys": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/@types/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz", - "integrity": "sha512-OCutwjDZ4aFS6PB1UZ988C4YgwlBHJd6wCeQqaLdmadZ/7e+w79+hbMUFC1QXDNCmdyoRfAFdm0RypzwR+Qpag==", - "dev": true - }, "@types/express": { "version": "4.17.7", "resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.7.tgz", @@ -1385,9 +1468,9 @@ } }, "@types/jest": { - "version": "26.0.12", - "resolved": "https://registry.npmjs.org/@types/jest/-/jest-26.0.12.tgz", - "integrity": "sha512-vZOFjm562IPb1EmaKxMjdcouxVb1l3NqoUH4XC4tDQ2R/AWde+0HXBUhyfc6L+7vc3mJ393U+5vr3nH2CLSVVg==", + "version": "26.0.14", + "resolved": "https://registry.npmjs.org/@types/jest/-/jest-26.0.14.tgz", + "integrity": "sha512-Hz5q8Vu0D288x3iWXePSn53W7hAjP0H7EQ6QvDO9c7t46mR0lNOLlfuwQ+JkVxuhygHzlzPX+0jKdA3ZgSh+Vg==", "dev": true, "requires": { "jest-diff": "^25.2.1", @@ -1439,18 +1522,18 @@ "integrity": "sha1-aaI6OtKcrwCX8G7aWbNh7i8GOfY=" }, "@types/n3": { - "version": "1.4.3", - "resolved": "https://registry.npmjs.org/@types/n3/-/n3-1.4.3.tgz", - "integrity": "sha512-NJ6GKZDE/6Q9iF9Zg+c89WHLK6VXIyVPfvPw6Z8/17ssk1Vx944XcAn0ZmPlRnvUXlGCg63NmMGzB20X46cs4A==", + "version": "1.4.4", + "resolved": "https://registry.npmjs.org/@types/n3/-/n3-1.4.4.tgz", + "integrity": "sha512-xsWfwyDh0uAH0CXvwqe9vb2UEDafMjRez/pB7yZwbWpd9Olw2wdxaL32FtdHjmmFE6b9i+j249JfRyZnvWkoqg==", "requires": { "@types/node": "*", "@types/rdf-js": "*" } }, "@types/node": { - "version": "14.6.0", - "resolved": "https://registry.npmjs.org/@types/node/-/node-14.6.0.tgz", - "integrity": "sha512-mikldZQitV94akrc4sCcSjtJfsTKt4p+e/s0AGscVA6XArQ9kFclP+ZiYUMnq987rc6QlYxXv/EivqlfSLxpKA==" + "version": "14.10.3", + "resolved": "https://registry.npmjs.org/@types/node/-/node-14.10.3.tgz", + "integrity": "sha512-zdN0hor7TLkjAdKTnYW+Y22oIhUUpil5ZD1V1OFq0CR0CLKw+NdR6dkziTfkWRLo6sKzisayoj/GNpNbe4LY9Q==" }, "@types/normalize-package-data": { "version": "2.4.0", @@ -1486,9 +1569,9 @@ "integrity": "sha512-ewFXqrQHlFsgc09MK5jP5iR7vumV/BYayNC6PgJO2LPe8vrnNFyjQjSppfEngITi0qvfKtzFvgKymGheFM9UOA==" }, "@types/rdf-js": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/@types/rdf-js/-/rdf-js-3.0.3.tgz", - "integrity": "sha512-1dvodNHh/YpLovHA/b046Nu+xERVt0KcYJFQH1A8S4ZcMj+stYtx4ypXw0X2/oatbREUo4JW+cjoBll3CVtwSQ==", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/@types/rdf-js/-/rdf-js-4.0.0.tgz", + "integrity": "sha512-2uaR7ks0380MqzUWGOPOOk9yZIr/6MOaCcaj3ntKgd2PqNocgi8j5kSHIJTDe+5ABtTHqKMSE0v0UqrsT8ibgQ==", "requires": { "@types/node": "*" } @@ -1564,58 +1647,16 @@ "integrity": "sha512-FA/BWv8t8ZWJ+gEOnLLd8ygxH/2UFbAvgEonyfN6yWGLKc7zVjbpl2Y4CTjid9h2RfgPP6SEt6uHwEOply00yw==" }, "@typescript-eslint/eslint-plugin": { - "version": "2.34.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-2.34.0.tgz", - "integrity": "sha512-4zY3Z88rEE99+CNvTbXSyovv2z9PNOVffTWD2W8QF5s2prBQtwN2zadqERcrHpcR7O/+KMI3fcTAmUUhK/iQcQ==", + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-4.1.1.tgz", + "integrity": "sha512-Hoxyt99EA9LMmqo/5PuWWPeWeB3mKyvibfJ1Hy5SfiUpjE8Nqp+5QNd9fOkzL66+fqvIWSIE+Ett16LGMzCGnQ==", "dev": true, "requires": { - "@typescript-eslint/experimental-utils": "2.34.0", + "@typescript-eslint/experimental-utils": "4.1.1", + "@typescript-eslint/scope-manager": "4.1.1", + "debug": "^4.1.1", "functional-red-black-tree": "^1.0.1", "regexpp": "^3.0.0", - "tsutils": "^3.17.1" - } - }, - "@typescript-eslint/experimental-utils": { - "version": "2.34.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-2.34.0.tgz", - "integrity": "sha512-eS6FTkq+wuMJ+sgtuNTtcqavWXqsflWcfBnlYhg/nS4aZ1leewkXGbvBhaapn1q6qf4M71bsR1tez5JTRMuqwA==", - "dev": true, - "requires": { - "@types/json-schema": "^7.0.3", - "@typescript-eslint/typescript-estree": "2.34.0", - "eslint-scope": "^5.0.0", - "eslint-utils": "^2.0.0" - } - }, - "@typescript-eslint/parser": { - "version": "2.34.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-2.34.0.tgz", - "integrity": "sha512-03ilO0ucSD0EPTw2X4PntSIRFtDPWjrVq7C3/Z3VQHRC7+13YB55rcJI3Jt+YgeHbjUdJPcPa7b23rXCBokuyA==", - "dev": true, - "requires": { - "@types/eslint-visitor-keys": "^1.0.0", - "@typescript-eslint/experimental-utils": "2.34.0", - "@typescript-eslint/typescript-estree": "2.34.0", - "eslint-visitor-keys": "^1.1.0" - } - }, - "@typescript-eslint/types": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-4.0.1.tgz", - "integrity": "sha512-S+gD3fgbkZYW2rnbjugNMqibm9HpEjqZBZkTiI3PwbbNGWmAcxolWIUwZ0SKeG4Dy2ktpKKaI/6+HGYVH8Qrlg==", - "dev": true - }, - "@typescript-eslint/typescript-estree": { - "version": "2.34.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-2.34.0.tgz", - "integrity": "sha512-OMAr+nJWKdlVM9LOqCqh3pQQPwxHAN7Du8DR6dmwCrAmxtiXQnhHJ6tBNtf+cggqfo51SG/FCwnKhXCIM7hnVg==", - "dev": true, - "requires": { - "debug": "^4.1.1", - "eslint-visitor-keys": "^1.1.0", - "glob": "^7.1.6", - "is-glob": "^4.0.1", - "lodash": "^4.17.15", "semver": "^7.3.2", "tsutils": "^3.17.1" }, @@ -1631,6 +1672,146 @@ } } }, + "@typescript-eslint/experimental-utils": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-4.1.1.tgz", + "integrity": "sha512-jzYsNciHoa4Z3c1URtmeT/bamYm8Dwfw6vuN3WHIE/BXb1iC4KveAnXDErTAZtPVxTYBaYn3n2gbt6F6D2rm1A==", + "dev": true, + "requires": { + "@types/json-schema": "^7.0.3", + "@typescript-eslint/scope-manager": "4.1.1", + "@typescript-eslint/types": "4.1.1", + "@typescript-eslint/typescript-estree": "4.1.1", + "eslint-scope": "^5.0.0", + "eslint-utils": "^2.0.0" + }, + "dependencies": { + "@typescript-eslint/types": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-4.1.1.tgz", + "integrity": "sha512-zrBiqOKYerMTllKcn+BP+i1b7LW/EbMMYytroXMxUTvFPn1smkCu0D7lSAx29fTUO4jnwV0ljSvYQtn2vNrNxA==", + "dev": true + } + } + }, + "@typescript-eslint/parser": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-4.1.1.tgz", + "integrity": "sha512-NLIhmicpKGfJbdXyQBz9j48PA6hq6e+SDOoXy7Ak6bq1ebGqbgG+fR1UIDAuay6OjQdot69c/URu2uLlsP8GQQ==", + "dev": true, + "requires": { + "@typescript-eslint/scope-manager": "4.1.1", + "@typescript-eslint/types": "4.1.1", + "@typescript-eslint/typescript-estree": "4.1.1", + "debug": "^4.1.1" + }, + "dependencies": { + "@typescript-eslint/types": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-4.1.1.tgz", + "integrity": "sha512-zrBiqOKYerMTllKcn+BP+i1b7LW/EbMMYytroXMxUTvFPn1smkCu0D7lSAx29fTUO4jnwV0ljSvYQtn2vNrNxA==", + "dev": true + }, + "debug": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", + "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", + "dev": true, + "requires": { + "ms": "^2.1.1" + } + } + } + }, + "@typescript-eslint/scope-manager": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-4.1.1.tgz", + "integrity": "sha512-0W8TTobCvIIQ2FsrYTffyZGAAFUyIbEHq5EYJb1m7Rpd005jrnOvKOo8ywCLhs/Bm17C+KsrUboBvBAARQVvyA==", + "dev": true, + "requires": { + "@typescript-eslint/types": "4.1.1", + "@typescript-eslint/visitor-keys": "4.1.1" + }, + "dependencies": { + "@typescript-eslint/types": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-4.1.1.tgz", + "integrity": "sha512-zrBiqOKYerMTllKcn+BP+i1b7LW/EbMMYytroXMxUTvFPn1smkCu0D7lSAx29fTUO4jnwV0ljSvYQtn2vNrNxA==", + "dev": true + }, + "@typescript-eslint/visitor-keys": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-4.1.1.tgz", + "integrity": "sha512-/EOOXbA2ferGLG6RmCHEQ0lTTLkOlXYDgblCmQk3tIU7mTPLm4gKhFMeeUSe+bcchTUsKeCk8xcpbop5Zr/8Rw==", + "dev": true, + "requires": { + "@typescript-eslint/types": "4.1.1", + "eslint-visitor-keys": "^2.0.0" + } + }, + "eslint-visitor-keys": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-2.0.0.tgz", + "integrity": "sha512-QudtT6av5WXels9WjIM7qz1XD1cWGvX4gGXvp/zBn9nXG02D0utdU3Em2m/QjTnrsk6bBjmCygl3rmj118msQQ==", + "dev": true + } + } + }, + "@typescript-eslint/types": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-4.0.1.tgz", + "integrity": "sha512-S+gD3fgbkZYW2rnbjugNMqibm9HpEjqZBZkTiI3PwbbNGWmAcxolWIUwZ0SKeG4Dy2ktpKKaI/6+HGYVH8Qrlg==", + "dev": true + }, + "@typescript-eslint/typescript-estree": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-4.1.1.tgz", + "integrity": "sha512-2AUg5v0liVBsqbGxBphbJ0QbGqSRVaF5qPoTPWcxop+66vMdU1h4CCvHxTC47+Qb+Pr4l2RhXDd41JNpwcQEKw==", + "dev": true, + "requires": { + "@typescript-eslint/types": "4.1.1", + "@typescript-eslint/visitor-keys": "4.1.1", + "debug": "^4.1.1", + "globby": "^11.0.1", + "is-glob": "^4.0.1", + "lodash": "^4.17.15", + "semver": "^7.3.2", + "tsutils": "^3.17.1" + }, + "dependencies": { + "@typescript-eslint/types": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-4.1.1.tgz", + "integrity": "sha512-zrBiqOKYerMTllKcn+BP+i1b7LW/EbMMYytroXMxUTvFPn1smkCu0D7lSAx29fTUO4jnwV0ljSvYQtn2vNrNxA==", + "dev": true + }, + "@typescript-eslint/visitor-keys": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-4.1.1.tgz", + "integrity": "sha512-/EOOXbA2ferGLG6RmCHEQ0lTTLkOlXYDgblCmQk3tIU7mTPLm4gKhFMeeUSe+bcchTUsKeCk8xcpbop5Zr/8Rw==", + "dev": true, + "requires": { + "@typescript-eslint/types": "4.1.1", + "eslint-visitor-keys": "^2.0.0" + } + }, + "debug": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", + "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", + "dev": true, + "requires": { + "ms": "^2.1.1" + } + }, + "eslint-visitor-keys": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-2.0.0.tgz", + "integrity": "sha512-QudtT6av5WXels9WjIM7qz1XD1cWGvX4gGXvp/zBn9nXG02D0utdU3Em2m/QjTnrsk6bBjmCygl3rmj118msQQ==", + "dev": true + } + } + }, "@typescript-eslint/visitor-keys": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-4.0.1.tgz", @@ -1943,6 +2124,20 @@ "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.10.1.tgz", "integrity": "sha512-zg7Hz2k5lI8kb7U32998pRRFin7zJlkfezGJjUc2heaD4Pw2wObakCDVzkKztTm/Ln7eiVvYsjqak0Ed4LkMDA==" }, + "babel-eslint": { + "version": "10.1.0", + "resolved": "https://registry.npmjs.org/babel-eslint/-/babel-eslint-10.1.0.tgz", + "integrity": "sha512-ifWaTHQ0ce+448CYop8AdrQiBsGrnC+bMgfyKFdi6EsPLTAWG+QfyDeM6OH+FmWnKvEq5NnBMLvlBUPKQZoDSg==", + "dev": true, + "requires": { + "@babel/code-frame": "^7.0.0", + "@babel/parser": "^7.7.0", + "@babel/traverse": "^7.7.0", + "@babel/types": "^7.7.0", + "eslint-visitor-keys": "^1.0.0", + "resolve": "^1.12.0" + } + }, "babel-jest": { "version": "26.3.0", "resolved": "https://registry.npmjs.org/babel-jest/-/babel-jest-26.3.0.tgz", @@ -3216,12 +3411,13 @@ } }, "eslint": { - "version": "7.7.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-7.7.0.tgz", - "integrity": "sha512-1KUxLzos0ZVsyL81PnRN335nDtQ8/vZUD6uMtWbF+5zDtjKcsklIi78XoE0MVL93QvWTu+E5y44VyyCsOMBrIg==", + "version": "7.9.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-7.9.0.tgz", + "integrity": "sha512-V6QyhX21+uXp4T+3nrNfI3hQNBDa/P8ga7LoQOenwrlEFXrEnUEE+ok1dMtaS3b6rmLXhT1TkTIsG75HMLbknA==", "dev": true, "requires": { "@babel/code-frame": "^7.0.0", + "@eslint/eslintrc": "^0.1.3", "ajv": "^6.10.0", "chalk": "^4.0.0", "cross-spawn": "^7.0.2", @@ -3231,7 +3427,7 @@ "eslint-scope": "^5.1.0", "eslint-utils": "^2.1.0", "eslint-visitor-keys": "^1.3.0", - "espree": "^7.2.0", + "espree": "^7.3.0", "esquery": "^1.2.0", "esutils": "^2.0.2", "file-entry-cache": "^5.0.1", @@ -3291,73 +3487,17 @@ } }, "eslint-config-es": { - "version": "3.19.67", - "resolved": "https://registry.npmjs.org/eslint-config-es/-/eslint-config-es-3.19.67.tgz", - "integrity": "sha512-9GTZGyRKT1L/hCBLKz0VC0YWYrlbPdMPSxnwIZiX08X4Gk6cIyK6gd8cKB2reLviAX0kLUR0WGj/oKx7nlSYTw==", + "version": "3.20.3", + "resolved": "https://registry.npmjs.org/eslint-config-es/-/eslint-config-es-3.20.3.tgz", + "integrity": "sha512-Qd2u5+S+FC3L5+qcW6i6hZO1GAjYqaSa+DE5MQcrGi+ZWU3f0gsMfAZa6PYlZiSOlNc6Dp5dA8ZyY8SVBzLXsA==", "dev": true, "requires": { - "@typescript-eslint/eslint-plugin": "2.26.0", - "@typescript-eslint/parser": "2.34.0", + "@typescript-eslint/eslint-plugin": "4.1.1", + "@typescript-eslint/parser": "4.1.1", "eslint-plugin-extended": "0.2.0", - "eslint-plugin-mocha": "6.3.0", + "eslint-plugin-mocha": "8.0.0", "eslint-plugin-react": "7.20.6", - "eslint-plugin-unicorn": "17.2.0" - }, - "dependencies": { - "@typescript-eslint/eslint-plugin": { - "version": "2.26.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-2.26.0.tgz", - "integrity": "sha512-4yUnLv40bzfzsXcTAtZyTjbiGUXMrcIJcIMioI22tSOyAxpdXiZ4r7YQUU8Jj6XXrLz9d5aMHPQf5JFR7h27Nw==", - "dev": true, - "requires": { - "@typescript-eslint/experimental-utils": "2.26.0", - "functional-red-black-tree": "^1.0.1", - "regexpp": "^3.0.0", - "tsutils": "^3.17.1" - } - }, - "@typescript-eslint/experimental-utils": { - "version": "2.26.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-2.26.0.tgz", - "integrity": "sha512-RELVoH5EYd+JlGprEyojUv9HeKcZqF7nZUGSblyAw1FwOGNnmQIU8kxJ69fttQvEwCsX5D6ECJT8GTozxrDKVQ==", - "dev": true, - "requires": { - "@types/json-schema": "^7.0.3", - "@typescript-eslint/typescript-estree": "2.26.0", - "eslint-scope": "^5.0.0", - "eslint-utils": "^2.0.0" - } - }, - "@typescript-eslint/typescript-estree": { - "version": "2.26.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-2.26.0.tgz", - "integrity": "sha512-3x4SyZCLB4zsKsjuhxDLeVJN6W29VwBnYpCsZ7vIdPel9ZqLfIZJgJXO47MNUkurGpQuIBALdPQKtsSnWpE1Yg==", - "dev": true, - "requires": { - "debug": "^4.1.1", - "eslint-visitor-keys": "^1.1.0", - "glob": "^7.1.6", - "is-glob": "^4.0.1", - "lodash": "^4.17.15", - "semver": "^6.3.0", - "tsutils": "^3.17.1" - } - }, - "debug": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", - "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", - "dev": true, - "requires": { - "ms": "^2.1.1" - } - }, - "semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", - "dev": true - } + "eslint-plugin-unicorn": "21.0.0" } }, "eslint-import-resolver-node": { @@ -3371,9 +3511,9 @@ } }, "eslint-import-resolver-typescript": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/eslint-import-resolver-typescript/-/eslint-import-resolver-typescript-2.2.1.tgz", - "integrity": "sha512-wxlVdwuWY6R5+CoesIy6n8EZX4k9lEeZGWTVBoX9g//8Xma8JMtL/p3AGnG43rRyXmIrX+/0IN8lpOPzrw1fSw==", + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/eslint-import-resolver-typescript/-/eslint-import-resolver-typescript-2.3.0.tgz", + "integrity": "sha512-MHSXvmj5e0SGOOBhBbt7C+fWj1bJbtSYFAD85Xeg8nvUtuooTod2HQb8bfhE9f5QyyNxEfgzqOYFCvmdDIcCuw==", "dev": true, "requires": { "debug": "^4.1.1", @@ -3517,13 +3657,13 @@ } }, "eslint-plugin-mocha": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/eslint-plugin-mocha/-/eslint-plugin-mocha-6.3.0.tgz", - "integrity": "sha512-Cd2roo8caAyG21oKaaNTj7cqeYRWW1I2B5SfpKRp0Ip1gkfwoR1Ow0IGlPWnNjzywdF4n+kHL8/9vM6zCJUxdg==", + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-mocha/-/eslint-plugin-mocha-8.0.0.tgz", + "integrity": "sha512-n67etbWDz6NQM+HnTwZHyBwz/bLlYPOxUbw7bPuCyFujv7ZpaT/Vn6KTAbT02gf7nRljtYIjWcTxK/n8a57rQQ==", "dev": true, "requires": { - "eslint-utils": "^2.0.0", - "ramda": "^0.27.0" + "eslint-utils": "^2.1.0", + "ramda": "^0.27.1" } }, "eslint-plugin-react": { @@ -3557,55 +3697,34 @@ } }, "eslint-plugin-tsdoc": { - "version": "0.2.6", - "resolved": "https://registry.npmjs.org/eslint-plugin-tsdoc/-/eslint-plugin-tsdoc-0.2.6.tgz", - "integrity": "sha512-pU6/VVEOlC85BrUjsqZGGSRy41N+PHfWXokqjpQRWT1LSpBsAEbRpsueNYSFS+93Sx9CFD0511kjLKVySRbLbg==", + "version": "0.2.7", + "resolved": "https://registry.npmjs.org/eslint-plugin-tsdoc/-/eslint-plugin-tsdoc-0.2.7.tgz", + "integrity": "sha512-GAbNpwNfwnolagP6mCQT8wY4usifnAE/iuCz15L3BcEca0xAidctU61h7w40mOuNiSp78DYPUl5gwN89nJ8+8Q==", "dev": true, "requires": { - "@microsoft/tsdoc": "0.12.20", - "@microsoft/tsdoc-config": "0.13.5" - }, - "dependencies": { - "@microsoft/tsdoc-config": { - "version": "0.13.5", - "resolved": "https://registry.npmjs.org/@microsoft/tsdoc-config/-/tsdoc-config-0.13.5.tgz", - "integrity": "sha512-KlnIdTRnPSsU9Coz9wzDAkT8JCLopP3ec1sgsgo7trwE6QLMKRpM4hZi2uzVX897SW49Q4f439auGBcQLnZQfA==", - "dev": true, - "requires": { - "@microsoft/tsdoc": "0.12.20", - "ajv": "~6.12.3", - "jju": "~1.4.0", - "resolve": "~1.12.0" - } - }, - "resolve": { - "version": "1.12.3", - "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.12.3.tgz", - "integrity": "sha512-hF6+hAPlxjqHWrw4p1rF3Wztbgxd4AjA5VlUzY5zcTb4J8D3JK4/1RjU48pHz2PJWzGVsLB1VWZkvJzhK2CCOA==", - "dev": true, - "requires": { - "path-parse": "^1.0.6" - } - } + "@microsoft/tsdoc": "0.12.21", + "@microsoft/tsdoc-config": "0.13.6" } }, "eslint-plugin-unicorn": { - "version": "17.2.0", - "resolved": "https://registry.npmjs.org/eslint-plugin-unicorn/-/eslint-plugin-unicorn-17.2.0.tgz", - "integrity": "sha512-0kYjrywf0kQxevFz571KrDfYMIRZ5Kq6dDgPU1EEBFeC181r+fAaPatBScWX+/hisKJ4+eCRFebxTeVylsSYmw==", + "version": "21.0.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-unicorn/-/eslint-plugin-unicorn-21.0.0.tgz", + "integrity": "sha512-S8v7+v4gZTQPj4pKKvexhgSUaLQSyItvxW2SVZDaX9Iu5IjlAmF2eni+L6w8a2aqshxgU8Lle4FIAVDtuejSKQ==", "dev": true, "requires": { "ci-info": "^2.0.0", "clean-regexp": "^1.0.0", "eslint-ast-utils": "^1.1.0", - "eslint-template-visitor": "^1.1.0", + "eslint-template-visitor": "^2.0.0", + "eslint-utils": "^2.1.0", "import-modules": "^2.0.0", "lodash": "^4.17.15", + "pluralize": "^8.0.0", "read-pkg-up": "^7.0.1", - "regexp-tree": "^0.1.20", + "regexp-tree": "^0.1.21", "reserved-words": "^0.1.2", "safe-regex": "^2.1.1", - "semver": "^7.1.2" + "semver": "^7.3.2" } }, "eslint-plugin-unused-imports": { @@ -3621,6 +3740,72 @@ "typescript": "^3.6.3" }, "dependencies": { + "@typescript-eslint/eslint-plugin": { + "version": "2.34.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-2.34.0.tgz", + "integrity": "sha512-4zY3Z88rEE99+CNvTbXSyovv2z9PNOVffTWD2W8QF5s2prBQtwN2zadqERcrHpcR7O/+KMI3fcTAmUUhK/iQcQ==", + "dev": true, + "requires": { + "@typescript-eslint/experimental-utils": "2.34.0", + "functional-red-black-tree": "^1.0.1", + "regexpp": "^3.0.0", + "tsutils": "^3.17.1" + }, + "dependencies": { + "regexpp": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-3.1.0.tgz", + "integrity": "sha512-ZOIzd8yVsQQA7j8GCSlPGXwg5PfmA1mrq0JP4nGhh54LaKN3xdai/vHUDu74pKwV8OxseMS65u2NImosQcSD0Q==", + "dev": true + } + } + }, + "@typescript-eslint/experimental-utils": { + "version": "2.34.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-2.34.0.tgz", + "integrity": "sha512-eS6FTkq+wuMJ+sgtuNTtcqavWXqsflWcfBnlYhg/nS4aZ1leewkXGbvBhaapn1q6qf4M71bsR1tez5JTRMuqwA==", + "dev": true, + "requires": { + "@types/json-schema": "^7.0.3", + "@typescript-eslint/typescript-estree": "2.34.0", + "eslint-scope": "^5.0.0", + "eslint-utils": "^2.0.0" + }, + "dependencies": { + "eslint-utils": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-2.1.0.tgz", + "integrity": "sha512-w94dQYoauyvlDc43XnGB8lU3Zt713vNChgt4EWwhXAP2XkBvndfxF0AgIqKOOasjPIPzj9JqgwkwbCYD0/V3Zg==", + "dev": true, + "requires": { + "eslint-visitor-keys": "^1.1.0" + } + } + } + }, + "@typescript-eslint/typescript-estree": { + "version": "2.34.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-2.34.0.tgz", + "integrity": "sha512-OMAr+nJWKdlVM9LOqCqh3pQQPwxHAN7Du8DR6dmwCrAmxtiXQnhHJ6tBNtf+cggqfo51SG/FCwnKhXCIM7hnVg==", + "dev": true, + "requires": { + "debug": "^4.1.1", + "eslint-visitor-keys": "^1.1.0", + "glob": "^7.1.6", + "is-glob": "^4.0.1", + "lodash": "^4.17.15", + "semver": "^7.3.2", + "tsutils": "^3.17.1" + }, + "dependencies": { + "semver": { + "version": "7.3.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.2.tgz", + "integrity": "sha512-OrOb32TeeambH6UrhtShmF7CRDqhL6/5XpPNp2DuRH6+9QLw/orhp72j87v8Qa1ScDkvrrBNpZcDejAirJmfXQ==", + "dev": true + } + } + }, "ansi-regex": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.0.tgz", @@ -3852,6 +4037,12 @@ "requires": { "prelude-ls": "~1.1.2" } + }, + "typescript": { + "version": "3.9.7", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.9.7.tgz", + "integrity": "sha512-BLbiRkiBzAwsjut4x/dsibSTB6yWpwT5qWmC2OfuCg3GgVQCSgMs4vEctYPhsaGtd0AeuuHMkjZ2h2WG8MSzRw==", + "dev": true } } }, @@ -3872,27 +4063,15 @@ } }, "eslint-template-visitor": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/eslint-template-visitor/-/eslint-template-visitor-1.1.0.tgz", - "integrity": "sha512-Lmy6QVlmFiIGl5fPi+8ACnov3sare+0Ouf7deJAGGhmUfeWJ5fVarELUxZRpsZ9sHejiJUq8626d0dn9uvcZTw==", + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/eslint-template-visitor/-/eslint-template-visitor-2.2.1.tgz", + "integrity": "sha512-q3SxoBXz0XjPGkUpwGVAwIwIPIxzCAJX1uwfVc8tW3v7u/zS7WXNH3I2Mu2MDz2NgSITAyKLRaQFPHu/iyKxDQ==", "dev": true, "requires": { - "eslint-visitor-keys": "^1.1.0", - "espree": "^6.1.1", - "multimap": "^1.0.2" - }, - "dependencies": { - "espree": { - "version": "6.2.1", - "resolved": "https://registry.npmjs.org/espree/-/espree-6.2.1.tgz", - "integrity": "sha512-ysCxRQY3WaXJz9tdbWOwuWr5Y/XrPTGX9Kiz3yoUXwW0VZ4w30HTkQLaGx/+ttFjF8i+ACbArnB4ce68a9m5hw==", - "dev": true, - "requires": { - "acorn": "^7.1.1", - "acorn-jsx": "^5.2.0", - "eslint-visitor-keys": "^1.1.0" - } - } + "babel-eslint": "^10.1.0", + "eslint-visitor-keys": "^1.3.0", + "esquery": "^1.3.1", + "multimap": "^1.1.0" } }, "eslint-utils": { @@ -7247,6 +7426,16 @@ "http-link-header": "^1.0.2", "jsonld-context-parser": "^2.0.1", "jsonparse": "^1.3.1" + }, + "dependencies": { + "@types/rdf-js": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/@types/rdf-js/-/rdf-js-3.0.3.tgz", + "integrity": "sha512-1dvodNHh/YpLovHA/b046Nu+xERVt0KcYJFQH1A8S4ZcMj+stYtx4ypXw0X2/oatbREUo4JW+cjoBll3CVtwSQ==", + "requires": { + "@types/node": "*" + } + } } }, "jsonld-streaming-serializer": { @@ -7256,6 +7445,16 @@ "requires": { "@types/rdf-js": "^3.0.0", "jsonld-context-parser": "^2.0.0" + }, + "dependencies": { + "@types/rdf-js": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/@types/rdf-js/-/rdf-js-3.0.3.tgz", + "integrity": "sha512-1dvodNHh/YpLovHA/b046Nu+xERVt0KcYJFQH1A8S4ZcMj+stYtx4ypXw0X2/oatbREUo4JW+cjoBll3CVtwSQ==", + "requires": { + "@types/node": "*" + } + } } }, "jsonparse": { @@ -7713,9 +7912,9 @@ "dev": true }, "n3": { - "version": "1.6.2", - "resolved": "https://registry.npmjs.org/n3/-/n3-1.6.2.tgz", - "integrity": "sha512-9R45WRNxNPblKLbXGwR9IvtaVvdr80vRxME79fhWnqBzHb2GcP6lS77Mvf8Fx6Wpfn8PpBTdggceWsSMDGY/SA==", + "version": "1.6.3", + "resolved": "https://registry.npmjs.org/n3/-/n3-1.6.3.tgz", + "integrity": "sha512-dN+8pLw2h1H1WQTW9VR3T16tHPDYdQP+YKXzbcpBCMCb9ZkksUyoVRRdtFGl3vosdET+NIB5eiIgth+4Vit6Yw==", "requires": { "queue-microtask": "^1.1.2", "readable-stream": "^3.6.0" @@ -8357,6 +8556,12 @@ "semver-compare": "^1.0.0" } }, + "pluralize": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/pluralize/-/pluralize-8.0.0.tgz", + "integrity": "sha512-Nc3IT5yHzflTfbjgqWcCPpo7DaKy4FnpB0l/zCAW0Tc7jxAiuqSxHasntB3D7887LSrA93kDJ9IXovxJYxyLCA==", + "dev": true + }, "posix-character-classes": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/posix-character-classes/-/posix-character-classes-0.1.1.tgz", @@ -8558,6 +8763,16 @@ "@comunica/mediator-race": "~1.15.0", "@types/rdf-js": "^3.0.0", "stream-to-string": "^1.2.0" + }, + "dependencies": { + "@types/rdf-js": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/@types/rdf-js/-/rdf-js-3.0.3.tgz", + "integrity": "sha512-1dvodNHh/YpLovHA/b046Nu+xERVt0KcYJFQH1A8S4ZcMj+stYtx4ypXw0X2/oatbREUo4JW+cjoBll3CVtwSQ==", + "requires": { + "@types/node": "*" + } + } } }, "rdf-serialize": { @@ -8603,6 +8818,16 @@ "@types/rdf-js": "^3.0.0", "htmlparser2": "^4.0.0", "relative-to-absolute-iri": "^1.0.2" + }, + "dependencies": { + "@types/rdf-js": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/@types/rdf-js/-/rdf-js-3.0.3.tgz", + "integrity": "sha512-1dvodNHh/YpLovHA/b046Nu+xERVt0KcYJFQH1A8S4ZcMj+stYtx4ypXw0X2/oatbREUo4JW+cjoBll3CVtwSQ==", + "requires": { + "@types/node": "*" + } + } } }, "rdfxml-streaming-parser": { @@ -10133,9 +10358,9 @@ "dev": true }, "ts-jest": { - "version": "26.2.0", - "resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-26.2.0.tgz", - "integrity": "sha512-9+y2qwzXdAImgLSYLXAb/Rhq9+K4rbt0417b8ai987V60g2uoNWBBmMkYgutI7D8Zhu+IbCSHbBtrHxB9d7xyA==", + "version": "26.3.0", + "resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-26.3.0.tgz", + "integrity": "sha512-Jq2uKfx6bPd9+JDpZNMBJMdMQUC3sJ08acISj8NXlVgR2d5OqslEHOR2KHMgwymu8h50+lKIm0m0xj/ioYdW2Q==", "dev": true, "requires": { "@types/jest": "26.x", @@ -10248,9 +10473,9 @@ } }, "typescript": { - "version": "3.9.7", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.9.7.tgz", - "integrity": "sha512-BLbiRkiBzAwsjut4x/dsibSTB6yWpwT5qWmC2OfuCg3GgVQCSgMs4vEctYPhsaGtd0AeuuHMkjZ2h2WG8MSzRw==", + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.0.2.tgz", + "integrity": "sha512-e4ERvRV2wb+rRZ/IQeb3jm2VxBsirQLpQhdxplZ2MEzGvDkkMmPglecnNDfSUBivMjP93vRbngYYDQqQ/78bcQ==", "dev": true }, "undefsafe": { diff --git a/package.json b/package.json index 17cfa6fa0..f3d683733 100644 --- a/package.json +++ b/package.json @@ -62,15 +62,15 @@ "config/**/*.json" ], "dependencies": { - "@rdfjs/data-model": "^1.1.2", + "@rdfjs/data-model": "^1.2.0", "@types/arrayify-stream": "^1.0.0", "@types/async-lock": "^1.1.2", "@types/cors": "^2.8.6", "@types/express": "^4.17.6", "@types/mime-types": "^2.1.0", - "@types/n3": "^1.4.0", - "@types/node": "^14.0.1", - "@types/rdf-js": "^3.0.0", + "@types/n3": "^1.4.4", + "@types/node": "^14.10.2", + "@types/rdf-js": "^4.0.0", "@types/streamify-array": "^1.0.0", "@types/uuid": "^8.3.0", "@types/yargs": "^15.0.5", @@ -80,7 +80,7 @@ "cors": "^2.8.5", "express": "^4.17.1", "mime-types": "^2.1.27", - "n3": "^1.4.0", + "n3": "^1.6.3", "rdf-parse": "^1.5.0", "rdf-serialize": "^1.0.0", "rdf-terms": "^1.5.1", @@ -91,18 +91,18 @@ }, "devDependencies": { "@microsoft/tsdoc-config": "^0.13.6", - "@types/jest": "^26.0.0", + "@types/jest": "^26.0.13", "@types/rimraf": "^3.0.0", "@types/supertest": "^2.0.10", - "@typescript-eslint/eslint-plugin": "^2.33.0", - "@typescript-eslint/parser": "^2.33.0", + "@typescript-eslint/eslint-plugin": "^4.1.1", + "@typescript-eslint/parser": "^4.1.1", "componentjs-generator": "^1.1.0", "coveralls": "^3.1.0", - "eslint": "^7.0.0", - "eslint-config-es": "^3.19.61", - "eslint-import-resolver-typescript": "^2.2.1", + "eslint": "^7.9.0", + "eslint-config-es": "^3.20.3", + "eslint-import-resolver-typescript": "^2.3.0", "eslint-plugin-import": "^2.22.0", - "eslint-plugin-tsdoc": "^0.2.4", + "eslint-plugin-tsdoc": "^0.2.7", "eslint-plugin-unused-imports": "^0.1.3", "husky": "^4.2.5", "jest": "^26.0.1", @@ -113,7 +113,7 @@ "rimraf": "^3.0.2", "stream-to-string": "^1.1.0", "supertest": "^4.0.2", - "ts-jest": "^26.0.0", - "typescript": "^3.9.2" + "ts-jest": "^26.3.0", + "typescript": "^4.0.2" } } diff --git a/src/authentication/CredentialsExtractor.ts b/src/authentication/CredentialsExtractor.ts index 08d4d7c2f..e7598413c 100644 --- a/src/authentication/CredentialsExtractor.ts +++ b/src/authentication/CredentialsExtractor.ts @@ -1,6 +1,6 @@ -import { HttpRequest } from '../server/HttpRequest'; +import type { HttpRequest } from '../server/HttpRequest'; import { AsyncHandler } from '../util/AsyncHandler'; -import { Credentials } from './Credentials'; +import type { Credentials } from './Credentials'; /** * Responsible for extracting credentials from an incoming request. diff --git a/src/authentication/UnsecureWebIdExtractor.ts b/src/authentication/UnsecureWebIdExtractor.ts index 415956a0d..3a596e9b6 100644 --- a/src/authentication/UnsecureWebIdExtractor.ts +++ b/src/authentication/UnsecureWebIdExtractor.ts @@ -1,5 +1,5 @@ -import { HttpRequest } from '../server/HttpRequest'; -import { Credentials } from './Credentials'; +import type { HttpRequest } from '../server/HttpRequest'; +import type { Credentials } from './Credentials'; import { CredentialsExtractor } from './CredentialsExtractor'; /** diff --git a/src/authorization/AclManager.ts b/src/authorization/AclManager.ts index b26a71506..1bf7b679d 100644 --- a/src/authorization/AclManager.ts +++ b/src/authorization/AclManager.ts @@ -1,4 +1,4 @@ -import { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier'; +import type { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier'; /** * Handles where acl files are stored. diff --git a/src/authorization/Authorizer.ts b/src/authorization/Authorizer.ts index 7e24dd43d..02f603dcd 100644 --- a/src/authorization/Authorizer.ts +++ b/src/authorization/Authorizer.ts @@ -1,6 +1,6 @@ -import { Credentials } from '../authentication/Credentials'; -import { PermissionSet } from '../ldp/permissions/PermissionSet'; -import { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier'; +import type { Credentials } from '../authentication/Credentials'; +import type { PermissionSet } from '../ldp/permissions/PermissionSet'; +import type { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier'; import { AsyncHandler } from '../util/AsyncHandler'; /** diff --git a/src/authorization/UrlBasedAclManager.ts b/src/authorization/UrlBasedAclManager.ts index a5f5849a6..d7b2c1f92 100644 --- a/src/authorization/UrlBasedAclManager.ts +++ b/src/authorization/UrlBasedAclManager.ts @@ -1,5 +1,5 @@ -import { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier'; -import { AclManager } from './AclManager'; +import type { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier'; +import type { AclManager } from './AclManager'; /** * Generates acl URIs by adding an .acl file extension. diff --git a/src/authorization/WebAclAuthorizer.ts b/src/authorization/WebAclAuthorizer.ts index bc5958614..bec9e6abd 100644 --- a/src/authorization/WebAclAuthorizer.ts +++ b/src/authorization/WebAclAuthorizer.ts @@ -1,17 +1,19 @@ -import { Quad, Store, Term } from 'n3'; -import { Credentials } from '../authentication/Credentials'; -import { PermissionSet } from '../ldp/permissions/PermissionSet'; -import { Representation } from '../ldp/representation/Representation'; -import { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier'; -import { ContainerManager } from '../storage/ContainerManager'; -import { ResourceStore } from '../storage/ResourceStore'; +import type { Quad, Term } from 'n3'; +import { Store } from 'n3'; +import type { Credentials } from '../authentication/Credentials'; +import type { PermissionSet } from '../ldp/permissions/PermissionSet'; +import type { Representation } from '../ldp/representation/Representation'; +import type { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier'; +import type { ContainerManager } from '../storage/ContainerManager'; +import type { ResourceStore } from '../storage/ResourceStore'; import { INTERNAL_QUADS } from '../util/ContentTypes'; import { ForbiddenHttpError } from '../util/errors/ForbiddenHttpError'; import { NotFoundHttpError } from '../util/errors/NotFoundHttpError'; import { UnauthorizedHttpError } from '../util/errors/UnauthorizedHttpError'; import { ACL, FOAF } from '../util/UriConstants'; -import { AclManager } from './AclManager'; -import { Authorizer, AuthorizerArgs } from './Authorizer'; +import type { AclManager } from './AclManager'; +import type { AuthorizerArgs } from './Authorizer'; +import { Authorizer } from './Authorizer'; /** * Handles most web access control predicates such as @@ -113,7 +115,7 @@ export class WebAclAuthorizer extends Authorizer { const acl = await this.aclManager.getAcl(id); const data = await this.resourceStore.getRepresentation(acl, { type: [{ value: INTERNAL_QUADS, weight: 1 }]}); return this.filterData(data, recurse ? ACL.default : ACL.accessTo, id.path); - } catch (error) { + } catch (error: unknown) { if (!(error instanceof NotFoundHttpError)) { throw error; } diff --git a/src/init/CliRunner.ts b/src/init/CliRunner.ts index f068cafbf..2d2910dfd 100644 --- a/src/init/CliRunner.ts +++ b/src/init/CliRunner.ts @@ -1,8 +1,9 @@ import * as Path from 'path'; -import { ReadStream, WriteStream } from 'tty'; -import { Loader, LoaderProperties } from 'componentsjs'; +import type { ReadStream, WriteStream } from 'tty'; +import type { LoaderProperties } from 'componentsjs'; +import { Loader } from 'componentsjs'; import yargs from 'yargs'; -import { Setup } from './Setup'; +import type { Setup } from './Setup'; /** * Generic run function for starting the server from a given config @@ -43,7 +44,7 @@ export const runCustom = function( 'urn:solid-server:default:variable:base': `http://localhost:${argv.port}/`, 'urn:solid-server:default:variable:rootFilePath': process.cwd(), }, - }); + }) as Setup; return await setup.setup(); })().then((base: string): void => { stdout.write(`Running at ${base}\n`); diff --git a/src/init/Setup.ts b/src/init/Setup.ts index 4a98b2901..f234a99a8 100644 --- a/src/init/Setup.ts +++ b/src/init/Setup.ts @@ -1,8 +1,8 @@ import streamifyArray from 'streamify-array'; -import { AclManager } from '../authorization/AclManager'; +import type { AclManager } from '../authorization/AclManager'; import { RepresentationMetadata } from '../ldp/representation/RepresentationMetadata'; -import { ExpressHttpServer } from '../server/ExpressHttpServer'; -import { ResourceStore } from '../storage/ResourceStore'; +import type { ExpressHttpServer } from '../server/ExpressHttpServer'; +import type { ResourceStore } from '../storage/ResourceStore'; import { TEXT_TURTLE } from '../util/ContentTypes'; import { CONTENT_TYPE } from '../util/UriConstants'; diff --git a/src/ldp/AuthenticatedLdpHandler.ts b/src/ldp/AuthenticatedLdpHandler.ts index fc2b0156b..a3adb9f65 100644 --- a/src/ldp/AuthenticatedLdpHandler.ts +++ b/src/ldp/AuthenticatedLdpHandler.ts @@ -1,16 +1,16 @@ -import { Credentials } from '../authentication/Credentials'; -import { CredentialsExtractor } from '../authentication/CredentialsExtractor'; -import { Authorizer } from '../authorization/Authorizer'; +import type { Credentials } from '../authentication/Credentials'; +import type { CredentialsExtractor } from '../authentication/CredentialsExtractor'; +import type { Authorizer } from '../authorization/Authorizer'; import { HttpHandler } from '../server/HttpHandler'; -import { HttpRequest } from '../server/HttpRequest'; -import { HttpResponse } from '../server/HttpResponse'; -import { RequestParser } from './http/RequestParser'; -import { ResponseWriter } from './http/ResponseWriter'; -import { Operation } from './operations/Operation'; -import { OperationHandler } from './operations/OperationHandler'; -import { ResponseDescription } from './operations/ResponseDescription'; -import { PermissionSet } from './permissions/PermissionSet'; -import { PermissionsExtractor } from './permissions/PermissionsExtractor'; +import type { HttpRequest } from '../server/HttpRequest'; +import type { HttpResponse } from '../server/HttpResponse'; +import type { RequestParser } from './http/RequestParser'; +import type { ResponseWriter } from './http/ResponseWriter'; +import type { Operation } from './operations/Operation'; +import type { OperationHandler } from './operations/OperationHandler'; +import type { ResponseDescription } from './operations/ResponseDescription'; +import type { PermissionSet } from './permissions/PermissionSet'; +import type { PermissionsExtractor } from './permissions/PermissionsExtractor'; /** * Collection of handlers needed for {@link AuthenticatedLdpHandler} to function. @@ -91,8 +91,12 @@ export class AuthenticatedLdpHandler extends HttpHandler { try { writeData = { response: input.response, result: await this.runHandlers(input.request) }; - } catch (error) { - writeData = { response: input.response, result: error }; + } catch (error: unknown) { + if (error instanceof Error) { + writeData = { response: input.response, result: error }; + } else { + throw error; + } } await this.responseWriter.handleSafe(writeData); diff --git a/src/ldp/http/AcceptPreferenceParser.ts b/src/ldp/http/AcceptPreferenceParser.ts index 2e269a072..469968b90 100644 --- a/src/ldp/http/AcceptPreferenceParser.ts +++ b/src/ldp/http/AcceptPreferenceParser.ts @@ -1,13 +1,13 @@ -import { HttpRequest } from '../../server/HttpRequest'; +import type { HttpRequest } from '../../server/HttpRequest'; +import type { AcceptHeader } from '../../util/AcceptParser'; import { - AcceptHeader, parseAccept, parseAcceptCharset, parseAcceptEncoding, parseAcceptLanguage, } from '../../util/AcceptParser'; -import { RepresentationPreference } from '../representation/RepresentationPreference'; -import { RepresentationPreferences } from '../representation/RepresentationPreferences'; +import type { RepresentationPreference } from '../representation/RepresentationPreference'; +import type { RepresentationPreferences } from '../representation/RepresentationPreferences'; import { PreferenceParser } from './PreferenceParser'; /** @@ -26,7 +26,7 @@ export class AcceptPreferenceParser extends PreferenceParser { public async handle(input: HttpRequest): Promise { const result: RepresentationPreferences = {}; const headers: - { [T in keyof RepresentationPreferences]: { val?: string; func: (input: string) => AcceptHeader[] }} = { + { [T in keyof RepresentationPreferences]: { val?: string; func: (inp: string) => AcceptHeader[] }} = { type: { val: input.headers.accept, func: parseAccept }, charset: { val: input.headers['accept-charset'] as string, func: parseAcceptCharset }, encoding: { val: input.headers['accept-encoding'] as string, func: parseAcceptEncoding }, diff --git a/src/ldp/http/BasicRequestParser.ts b/src/ldp/http/BasicRequestParser.ts index d7df9ffce..6a2b4a3e3 100644 --- a/src/ldp/http/BasicRequestParser.ts +++ b/src/ldp/http/BasicRequestParser.ts @@ -1,9 +1,9 @@ -import { HttpRequest } from '../../server/HttpRequest'; -import { Operation } from '../operations/Operation'; -import { BodyParser } from './BodyParser'; -import { PreferenceParser } from './PreferenceParser'; +import type { HttpRequest } from '../../server/HttpRequest'; +import type { Operation } from '../operations/Operation'; +import type { BodyParser } from './BodyParser'; +import type { PreferenceParser } from './PreferenceParser'; import { RequestParser } from './RequestParser'; -import { TargetExtractor } from './TargetExtractor'; +import type { TargetExtractor } from './TargetExtractor'; /** * Input parsers required for a {@link BasicRequestParser}. diff --git a/src/ldp/http/BasicResponseWriter.ts b/src/ldp/http/BasicResponseWriter.ts index 855cd6240..00919fdef 100644 --- a/src/ldp/http/BasicResponseWriter.ts +++ b/src/ldp/http/BasicResponseWriter.ts @@ -1,7 +1,7 @@ -import { HttpResponse } from '../../server/HttpResponse'; +import type { HttpResponse } from '../../server/HttpResponse'; import { HttpError } from '../../util/errors/HttpError'; import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError'; -import { ResponseDescription } from '../operations/ResponseDescription'; +import type { ResponseDescription } from '../operations/ResponseDescription'; import { ResponseWriter } from './ResponseWriter'; /** diff --git a/src/ldp/http/BasicTargetExtractor.ts b/src/ldp/http/BasicTargetExtractor.ts index 499bc09ab..5d94727c4 100644 --- a/src/ldp/http/BasicTargetExtractor.ts +++ b/src/ldp/http/BasicTargetExtractor.ts @@ -1,7 +1,7 @@ -import { TLSSocket } from 'tls'; +import type { TLSSocket } from 'tls'; import { format } from 'url'; -import { HttpRequest } from '../../server/HttpRequest'; -import { ResourceIdentifier } from '../representation/ResourceIdentifier'; +import type { HttpRequest } from '../../server/HttpRequest'; +import type { ResourceIdentifier } from '../representation/ResourceIdentifier'; import { TargetExtractor } from './TargetExtractor'; /** diff --git a/src/ldp/http/BodyParser.ts b/src/ldp/http/BodyParser.ts index db4149e4b..f69e1705d 100644 --- a/src/ldp/http/BodyParser.ts +++ b/src/ldp/http/BodyParser.ts @@ -1,6 +1,6 @@ -import { HttpRequest } from '../../server/HttpRequest'; +import type { HttpRequest } from '../../server/HttpRequest'; import { AsyncHandler } from '../../util/AsyncHandler'; -import { Representation } from '../representation/Representation'; +import type { Representation } from '../representation/Representation'; /** * Parses the body of an incoming {@link HttpRequest} and converts it to a {@link Representation}. diff --git a/src/ldp/http/Patch.ts b/src/ldp/http/Patch.ts index 1df19e0be..4f2013502 100644 --- a/src/ldp/http/Patch.ts +++ b/src/ldp/http/Patch.ts @@ -1,4 +1,4 @@ -import { Representation } from '../representation/Representation'; +import type { Representation } from '../representation/Representation'; /** * Represents the changes needed for a PATCH request. diff --git a/src/ldp/http/PreferenceParser.ts b/src/ldp/http/PreferenceParser.ts index 6e244fb7c..73beaa7ba 100644 --- a/src/ldp/http/PreferenceParser.ts +++ b/src/ldp/http/PreferenceParser.ts @@ -1,6 +1,6 @@ -import { HttpRequest } from '../../server/HttpRequest'; +import type { HttpRequest } from '../../server/HttpRequest'; import { AsyncHandler } from '../../util/AsyncHandler'; -import { RepresentationPreferences } from '../representation/RepresentationPreferences'; +import type { RepresentationPreferences } from '../representation/RepresentationPreferences'; /** * Creates {@link RepresentationPreferences} based on the incoming HTTP headers in a {@link HttpRequest}. diff --git a/src/ldp/http/RawBodyParser.ts b/src/ldp/http/RawBodyParser.ts index 7636f3fdb..8e8402a45 100644 --- a/src/ldp/http/RawBodyParser.ts +++ b/src/ldp/http/RawBodyParser.ts @@ -1,7 +1,7 @@ -import { HttpRequest } from '../../server/HttpRequest'; +import type { HttpRequest } from '../../server/HttpRequest'; import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError'; import { CONTENT_TYPE, HTTP, RDF } from '../../util/UriConstants'; -import { Representation } from '../representation/Representation'; +import type { Representation } from '../representation/Representation'; import { RepresentationMetadata } from '../representation/RepresentationMetadata'; import { BodyParser } from './BodyParser'; diff --git a/src/ldp/http/RequestParser.ts b/src/ldp/http/RequestParser.ts index e1cbb5140..d0dd1dfe6 100644 --- a/src/ldp/http/RequestParser.ts +++ b/src/ldp/http/RequestParser.ts @@ -1,6 +1,6 @@ -import { HttpRequest } from '../../server/HttpRequest'; +import type { HttpRequest } from '../../server/HttpRequest'; import { AsyncHandler } from '../../util/AsyncHandler'; -import { Operation } from '../operations/Operation'; +import type { Operation } from '../operations/Operation'; /** * Converts an incoming HttpRequest to an Operation. diff --git a/src/ldp/http/ResponseWriter.ts b/src/ldp/http/ResponseWriter.ts index b4c50b42f..c0fd33496 100644 --- a/src/ldp/http/ResponseWriter.ts +++ b/src/ldp/http/ResponseWriter.ts @@ -1,6 +1,6 @@ -import { HttpResponse } from '../../server/HttpResponse'; +import type { HttpResponse } from '../../server/HttpResponse'; import { AsyncHandler } from '../../util/AsyncHandler'; -import { ResponseDescription } from '../operations/ResponseDescription'; +import type { ResponseDescription } from '../operations/ResponseDescription'; /** * Writes to the HttpResponse. diff --git a/src/ldp/http/SparqlUpdateBodyParser.ts b/src/ldp/http/SparqlUpdateBodyParser.ts index 5d66a32b8..873a0a533 100644 --- a/src/ldp/http/SparqlUpdateBodyParser.ts +++ b/src/ldp/http/SparqlUpdateBodyParser.ts @@ -1,13 +1,13 @@ import { PassThrough } from 'stream'; import { translate } from 'sparqlalgebrajs'; -import { HttpRequest } from '../../server/HttpRequest'; +import type { HttpRequest } from '../../server/HttpRequest'; import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError'; import { UnsupportedMediaTypeHttpError } from '../../util/errors/UnsupportedMediaTypeHttpError'; import { CONTENT_TYPE } from '../../util/UriConstants'; import { readableToString } from '../../util/Util'; import { RepresentationMetadata } from '../representation/RepresentationMetadata'; import { BodyParser } from './BodyParser'; -import { SparqlUpdatePatch } from './SparqlUpdatePatch'; +import type { SparqlUpdatePatch } from './SparqlUpdatePatch'; /** * {@link BodyParser} that supports `application/sparql-update` content. @@ -44,8 +44,11 @@ export class SparqlUpdateBodyParser extends BodyParser { data: dataCopy, metadata, }; - } catch (error) { - throw new UnsupportedHttpError(error); + } catch (error: unknown) { + if (error instanceof Error) { + throw new UnsupportedHttpError(error.message); + } + throw new UnsupportedHttpError(); } } } diff --git a/src/ldp/http/SparqlUpdatePatch.ts b/src/ldp/http/SparqlUpdatePatch.ts index c3e50f4a5..c52f65926 100644 --- a/src/ldp/http/SparqlUpdatePatch.ts +++ b/src/ldp/http/SparqlUpdatePatch.ts @@ -1,5 +1,5 @@ -import { Algebra } from 'sparqlalgebrajs'; -import { Patch } from './Patch'; +import type { Algebra } from 'sparqlalgebrajs'; +import type { Patch } from './Patch'; /** * A specific type of {@link Patch} corresponding to a SPARQL update. diff --git a/src/ldp/http/TargetExtractor.ts b/src/ldp/http/TargetExtractor.ts index 0c8cf167c..8af184257 100644 --- a/src/ldp/http/TargetExtractor.ts +++ b/src/ldp/http/TargetExtractor.ts @@ -1,6 +1,6 @@ -import { HttpRequest } from '../../server/HttpRequest'; +import type { HttpRequest } from '../../server/HttpRequest'; import { AsyncHandler } from '../../util/AsyncHandler'; -import { ResourceIdentifier } from '../representation/ResourceIdentifier'; +import type { ResourceIdentifier } from '../representation/ResourceIdentifier'; /** * Extracts a {@link ResourceIdentifier} from an incoming {@link HttpRequest}. diff --git a/src/ldp/operations/DeleteOperationHandler.ts b/src/ldp/operations/DeleteOperationHandler.ts index 17bac170e..25d90263b 100644 --- a/src/ldp/operations/DeleteOperationHandler.ts +++ b/src/ldp/operations/DeleteOperationHandler.ts @@ -1,8 +1,8 @@ -import { ResourceStore } from '../../storage/ResourceStore'; +import type { ResourceStore } from '../../storage/ResourceStore'; import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError'; -import { Operation } from './Operation'; +import type { Operation } from './Operation'; import { OperationHandler } from './OperationHandler'; -import { ResponseDescription } from './ResponseDescription'; +import type { ResponseDescription } from './ResponseDescription'; /** * Handles DELETE {@link Operation}s. diff --git a/src/ldp/operations/GetOperationHandler.ts b/src/ldp/operations/GetOperationHandler.ts index 4c96c1a9b..a618aeb83 100644 --- a/src/ldp/operations/GetOperationHandler.ts +++ b/src/ldp/operations/GetOperationHandler.ts @@ -1,8 +1,8 @@ -import { ResourceStore } from '../../storage/ResourceStore'; +import type { ResourceStore } from '../../storage/ResourceStore'; import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError'; -import { Operation } from './Operation'; +import type { Operation } from './Operation'; import { OperationHandler } from './OperationHandler'; -import { ResponseDescription } from './ResponseDescription'; +import type { ResponseDescription } from './ResponseDescription'; /** * Handles GET {@link Operation}s. diff --git a/src/ldp/operations/Operation.ts b/src/ldp/operations/Operation.ts index 29f3875f8..18b0484bf 100644 --- a/src/ldp/operations/Operation.ts +++ b/src/ldp/operations/Operation.ts @@ -1,6 +1,6 @@ -import { Representation } from '../representation/Representation'; -import { RepresentationPreferences } from '../representation/RepresentationPreferences'; -import { ResourceIdentifier } from '../representation/ResourceIdentifier'; +import type { Representation } from '../representation/Representation'; +import type { RepresentationPreferences } from '../representation/RepresentationPreferences'; +import type { ResourceIdentifier } from '../representation/ResourceIdentifier'; /** * A single REST operation. diff --git a/src/ldp/operations/OperationHandler.ts b/src/ldp/operations/OperationHandler.ts index b58ddf3a2..bd183216d 100644 --- a/src/ldp/operations/OperationHandler.ts +++ b/src/ldp/operations/OperationHandler.ts @@ -1,6 +1,6 @@ import { AsyncHandler } from '../../util/AsyncHandler'; -import { Operation } from './Operation'; -import { ResponseDescription } from './ResponseDescription'; +import type { Operation } from './Operation'; +import type { ResponseDescription } from './ResponseDescription'; /** * Handler for a specific operation type. diff --git a/src/ldp/operations/PatchOperationHandler.ts b/src/ldp/operations/PatchOperationHandler.ts index e510f31ba..fa1f93e14 100644 --- a/src/ldp/operations/PatchOperationHandler.ts +++ b/src/ldp/operations/PatchOperationHandler.ts @@ -1,9 +1,9 @@ -import { ResourceStore } from '../../storage/ResourceStore'; +import type { ResourceStore } from '../../storage/ResourceStore'; import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError'; -import { Patch } from '../http/Patch'; -import { Operation } from './Operation'; +import type { Patch } from '../http/Patch'; +import type { Operation } from './Operation'; import { OperationHandler } from './OperationHandler'; -import { ResponseDescription } from './ResponseDescription'; +import type { ResponseDescription } from './ResponseDescription'; export class PatchOperationHandler extends OperationHandler { private readonly store: ResourceStore; diff --git a/src/ldp/operations/PostOperationHandler.ts b/src/ldp/operations/PostOperationHandler.ts index dc71415e6..f70ac892b 100644 --- a/src/ldp/operations/PostOperationHandler.ts +++ b/src/ldp/operations/PostOperationHandler.ts @@ -1,8 +1,8 @@ -import { ResourceStore } from '../../storage/ResourceStore'; +import type { ResourceStore } from '../../storage/ResourceStore'; import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError'; -import { Operation } from './Operation'; +import type { Operation } from './Operation'; import { OperationHandler } from './OperationHandler'; -import { ResponseDescription } from './ResponseDescription'; +import type { ResponseDescription } from './ResponseDescription'; /** * Handles POST {@link Operation}s. diff --git a/src/ldp/operations/PutOperationHandler.ts b/src/ldp/operations/PutOperationHandler.ts index 7aceacc1e..d3058f53e 100644 --- a/src/ldp/operations/PutOperationHandler.ts +++ b/src/ldp/operations/PutOperationHandler.ts @@ -1,8 +1,8 @@ -import { ResourceStore } from '../../storage/ResourceStore'; +import type { ResourceStore } from '../../storage/ResourceStore'; import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError'; -import { Operation } from './Operation'; +import type { Operation } from './Operation'; import { OperationHandler } from './OperationHandler'; -import { ResponseDescription } from './ResponseDescription'; +import type { ResponseDescription } from './ResponseDescription'; /** * Handles PUT {@link Operation}s. diff --git a/src/ldp/operations/ResponseDescription.ts b/src/ldp/operations/ResponseDescription.ts index 3958fdc2c..dad5cbe2b 100644 --- a/src/ldp/operations/ResponseDescription.ts +++ b/src/ldp/operations/ResponseDescription.ts @@ -1,5 +1,5 @@ -import { Representation } from '../representation/Representation'; -import { ResourceIdentifier } from '../representation/ResourceIdentifier'; +import type { Representation } from '../representation/Representation'; +import type { ResourceIdentifier } from '../representation/ResourceIdentifier'; /** * The result of executing an operation. diff --git a/src/ldp/permissions/MethodPermissionsExtractor.ts b/src/ldp/permissions/MethodPermissionsExtractor.ts index 8a1954e98..a9b0bf05d 100644 --- a/src/ldp/permissions/MethodPermissionsExtractor.ts +++ b/src/ldp/permissions/MethodPermissionsExtractor.ts @@ -1,6 +1,6 @@ import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError'; -import { Operation } from '../operations/Operation'; -import { PermissionSet } from './PermissionSet'; +import type { Operation } from '../operations/Operation'; +import type { PermissionSet } from './PermissionSet'; import { PermissionsExtractor } from './PermissionsExtractor'; const READ_METHODS = new Set([ 'GET', 'HEAD' ]); diff --git a/src/ldp/permissions/PermissionsExtractor.ts b/src/ldp/permissions/PermissionsExtractor.ts index 76df3d2a2..ea562b107 100644 --- a/src/ldp/permissions/PermissionsExtractor.ts +++ b/src/ldp/permissions/PermissionsExtractor.ts @@ -1,6 +1,6 @@ import { AsyncHandler } from '../../util/AsyncHandler'; -import { Operation } from '../operations/Operation'; -import { PermissionSet } from './PermissionSet'; +import type { Operation } from '../operations/Operation'; +import type { PermissionSet } from './PermissionSet'; /** * Verifies which permissions are requested on a given {@link Operation}. diff --git a/src/ldp/permissions/SparqlPatchPermissionsExtractor.ts b/src/ldp/permissions/SparqlPatchPermissionsExtractor.ts index 92f2bc169..22b3f3904 100644 --- a/src/ldp/permissions/SparqlPatchPermissionsExtractor.ts +++ b/src/ldp/permissions/SparqlPatchPermissionsExtractor.ts @@ -1,9 +1,9 @@ import { Algebra } from 'sparqlalgebrajs'; import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError'; -import { SparqlUpdatePatch } from '../http/SparqlUpdatePatch'; -import { Operation } from '../operations/Operation'; -import { Representation } from '../representation/Representation'; -import { PermissionSet } from './PermissionSet'; +import type { SparqlUpdatePatch } from '../http/SparqlUpdatePatch'; +import type { Operation } from '../operations/Operation'; +import type { Representation } from '../representation/Representation'; +import type { PermissionSet } from './PermissionSet'; import { PermissionsExtractor } from './PermissionsExtractor'; /** diff --git a/src/ldp/representation/Representation.ts b/src/ldp/representation/Representation.ts index 69c181c16..36c4b92da 100644 --- a/src/ldp/representation/Representation.ts +++ b/src/ldp/representation/Representation.ts @@ -1,5 +1,5 @@ -import { Readable } from 'stream'; -import { RepresentationMetadata } from './RepresentationMetadata'; +import type { Readable } from 'stream'; +import type { RepresentationMetadata } from './RepresentationMetadata'; /** * A representation of a resource. diff --git a/src/ldp/representation/RepresentationPreferences.ts b/src/ldp/representation/RepresentationPreferences.ts index 249ac6ff1..83aec3109 100644 --- a/src/ldp/representation/RepresentationPreferences.ts +++ b/src/ldp/representation/RepresentationPreferences.ts @@ -1,4 +1,4 @@ -import { RepresentationPreference } from './RepresentationPreference'; +import type { RepresentationPreference } from './RepresentationPreference'; /** * Contains the preferences of which kind of representation is requested. diff --git a/src/server/ExpressHttpServer.ts b/src/server/ExpressHttpServer.ts index e2f64b346..d5c1ca3e1 100644 --- a/src/server/ExpressHttpServer.ts +++ b/src/server/ExpressHttpServer.ts @@ -1,7 +1,8 @@ -import { Server } from 'http'; +import type { Server } from 'http'; import cors from 'cors'; -import express, { Express } from 'express'; -import { HttpHandler } from './HttpHandler'; +import type { Express } from 'express'; +import express from 'express'; +import type { HttpHandler } from './HttpHandler'; export class ExpressHttpServer { private readonly handler: HttpHandler; @@ -35,8 +36,8 @@ export class ExpressHttpServer { app.use(async(request, response, done): Promise => { try { await this.handler.handleSafe({ request, response }); - } catch (error) { - const errMsg = `${error.name}: ${error.message}\n${error.stack}`; + } catch (error: unknown) { + const errMsg = error instanceof Error ? `${error.name}: ${error.message}\n${error.stack}` : 'Unknown error.'; process.stderr.write(errMsg); response.status(500).contentType('text/plain').send(errMsg); } finally { diff --git a/src/server/HttpHandler.ts b/src/server/HttpHandler.ts index 36acef1f5..c0441ce2b 100644 --- a/src/server/HttpHandler.ts +++ b/src/server/HttpHandler.ts @@ -1,6 +1,6 @@ import { AsyncHandler } from '../util/AsyncHandler'; -import { HttpRequest } from './HttpRequest'; -import { HttpResponse } from './HttpResponse'; +import type { HttpRequest } from './HttpRequest'; +import type { HttpResponse } from './HttpResponse'; /** * An HTTP request handler. diff --git a/src/server/HttpRequest.ts b/src/server/HttpRequest.ts index 7bb00fb7e..5c1a1c1c7 100644 --- a/src/server/HttpRequest.ts +++ b/src/server/HttpRequest.ts @@ -1,4 +1,4 @@ -import { IncomingMessage } from 'http'; +import type { IncomingMessage } from 'http'; /** * An incoming HTTP request; diff --git a/src/server/HttpResponse.ts b/src/server/HttpResponse.ts index ab6829c5f..476485d0e 100644 --- a/src/server/HttpResponse.ts +++ b/src/server/HttpResponse.ts @@ -1,4 +1,4 @@ -import { ServerResponse } from 'http'; +import type { ServerResponse } from 'http'; /** * An outgoing HTTP response; diff --git a/src/storage/AtomicResourceStore.ts b/src/storage/AtomicResourceStore.ts index cac075b9a..9926778d5 100644 --- a/src/storage/AtomicResourceStore.ts +++ b/src/storage/AtomicResourceStore.ts @@ -1,4 +1,4 @@ -import { ResourceStore } from './ResourceStore'; +import type { ResourceStore } from './ResourceStore'; /** * A {@link ResourceStore} of which all operations are atomic. diff --git a/src/storage/Conditions.ts b/src/storage/Conditions.ts index 73d840db4..c5eef7a49 100644 --- a/src/storage/Conditions.ts +++ b/src/storage/Conditions.ts @@ -1,4 +1,4 @@ -import { RepresentationMetadata } from '../ldp/representation/RepresentationMetadata'; +import type { RepresentationMetadata } from '../ldp/representation/RepresentationMetadata'; /** * The conditions of an HTTP conditional request. diff --git a/src/storage/ContainerManager.ts b/src/storage/ContainerManager.ts index b2d5ea26d..02bd9a719 100644 --- a/src/storage/ContainerManager.ts +++ b/src/storage/ContainerManager.ts @@ -1,4 +1,4 @@ -import { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier'; +import type { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier'; /** * Handles the identification of containers in which a resource is contained. diff --git a/src/storage/ExtensionBasedMapper.ts b/src/storage/ExtensionBasedMapper.ts index 427673a2c..ba79533e7 100644 --- a/src/storage/ExtensionBasedMapper.ts +++ b/src/storage/ExtensionBasedMapper.ts @@ -1,11 +1,11 @@ import { posix } from 'path'; import { types } from 'mime-types'; -import { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier'; +import type { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier'; import { APPLICATION_OCTET_STREAM, TEXT_TURTLE } from '../util/ContentTypes'; import { ConflictHttpError } from '../util/errors/ConflictHttpError'; import { NotFoundHttpError } from '../util/errors/NotFoundHttpError'; import { trimTrailingSlashes } from '../util/Util'; -import { FileIdentifierMapper } from './FileIdentifierMapper'; +import type { FileIdentifierMapper } from './FileIdentifierMapper'; const { join: joinPath, normalize: normalizePath } = posix; diff --git a/src/storage/FileIdentifierMapper.ts b/src/storage/FileIdentifierMapper.ts index d4d2ad9ca..17484932f 100644 --- a/src/storage/FileIdentifierMapper.ts +++ b/src/storage/FileIdentifierMapper.ts @@ -1,4 +1,4 @@ -import { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier'; +import type { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier'; /** * Supports mapping a file to an URL and back. diff --git a/src/storage/FileResourceStore.ts b/src/storage/FileResourceStore.ts index aaafc156d..89907a075 100644 --- a/src/storage/FileResourceStore.ts +++ b/src/storage/FileResourceStore.ts @@ -1,24 +1,25 @@ -import { createReadStream, createWriteStream, promises as fsPromises, Stats } from 'fs'; +import type { Stats } from 'fs'; +import { createReadStream, createWriteStream, promises as fsPromises } from 'fs'; import { posix } from 'path'; -import { Readable } from 'stream'; +import type { Readable } from 'stream'; import { DataFactory } from 'n3'; import type { Quad } from 'rdf-js'; import streamifyArray from 'streamify-array'; -import { Representation } from '../ldp/representation/Representation'; +import type { Representation } from '../ldp/representation/Representation'; import { RepresentationMetadata } from '../ldp/representation/RepresentationMetadata'; -import { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier'; +import type { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier'; import { INTERNAL_QUADS } from '../util/ContentTypes'; import { ConflictHttpError } from '../util/errors/ConflictHttpError'; import { MethodNotAllowedHttpError } from '../util/errors/MethodNotAllowedHttpError'; import { NotFoundHttpError } from '../util/errors/NotFoundHttpError'; import { UnsupportedMediaTypeHttpError } from '../util/errors/UnsupportedMediaTypeHttpError'; -import { InteractionController } from '../util/InteractionController'; -import { MetadataController } from '../util/MetadataController'; +import type { InteractionController } from '../util/InteractionController'; +import type { MetadataController } from '../util/MetadataController'; import { CONTENT_TYPE, DCTERMS, HTTP, POSIX, RDF, XSD } from '../util/UriConstants'; import { getTypedLiteral } from '../util/UriUtil'; import { ensureTrailingSlash } from '../util/Util'; -import { ExtensionBasedMapper } from './ExtensionBasedMapper'; -import { ResourceStore } from './ResourceStore'; +import type { ExtensionBasedMapper } from './ExtensionBasedMapper'; +import type { ResourceStore } from './ResourceStore'; const { join: joinPath } = posix; @@ -91,7 +92,7 @@ export class FileResourceStore implements ResourceStore { let stats; try { stats = await fsPromises.lstat(path); - } catch (error) { + } catch { throw new NotFoundHttpError(); } @@ -118,7 +119,7 @@ export class FileResourceStore implements ResourceStore { let stats; try { stats = await fsPromises.lstat(path); - } catch (error) { + } catch { throw new NotFoundHttpError(); } @@ -179,7 +180,7 @@ export class FileResourceStore implements ResourceStore { // Only delete the metadata file as auxiliary resource because this is the only file created by this store. try { await fsPromises.unlink(`${path}.metadata`); - } catch (_) { + } catch { // It's ok if there was no metadata file. } } @@ -198,7 +199,7 @@ export class FileResourceStore implements ResourceStore { // Only delete the metadata file as auxiliary resource because this is the only file created by this store. try { await fsPromises.unlink(joinPath(path, '.metadata')); - } catch (_) { + } catch { // It's ok if there was no metadata file. } @@ -220,7 +221,7 @@ export class FileResourceStore implements ResourceStore { try { const readMetadataStream = createReadStream(`${path}.metadata`); rawMetadata = await this.metadataController.parseQuads(readMetadataStream); - } catch (_) { + } catch { // Metadata file doesn't exist so lets keep `rawMetaData` an empty array. } const metadata = new RepresentationMetadata(this.resourceMapper.mapFilePathToUrl(path)).addQuads(rawMetadata) @@ -253,7 +254,7 @@ export class FileResourceStore implements ResourceStore { try { const readMetadataStream = createReadStream(joinPath(path, '.metadata')); rawMetadata = await this.metadataController.parseQuads(readMetadataStream); - } catch (_) { + } catch { // Metadata file doesn't exist so lets keep `rawMetaData` an empty array. } @@ -289,7 +290,7 @@ export class FileResourceStore implements ResourceStore { quads.push(...this.metadataController.generateResourceQuads(childURI, childStats)); childURIs.push(childURI); - } catch (_) { + } catch { // Skip the child if there is an error. } } @@ -314,7 +315,7 @@ export class FileResourceStore implements ResourceStore { stats = await fsPromises.lstat( this.resourceMapper.getAbsolutePath(path, newIdentifier), ); - } catch (error) { + } catch { await this.createFile(path, newIdentifier, data, true, metadata); return; } @@ -338,7 +339,7 @@ export class FileResourceStore implements ResourceStore { this.resourceMapper.getAbsolutePath(path, newIdentifier), ); throw new ConflictHttpError('Resource with that identifier already exists.'); - } catch (error) { + } catch (error: unknown) { if (error instanceof ConflictHttpError) { throw error; } @@ -369,7 +370,7 @@ export class FileResourceStore implements ResourceStore { let stats; try { stats = await fsPromises.lstat(this.resourceMapper.getAbsolutePath(path)); - } catch (error) { + } catch { throw new MethodNotAllowedHttpError(); } @@ -387,7 +388,7 @@ export class FileResourceStore implements ResourceStore { const fullPath = this.resourceMapper.getAbsolutePath(path, resourceName); await this.createDataFile(fullPath, data); return { path: this.resourceMapper.mapFilePathToUrl(fullPath) }; - } catch (error) { + } catch (error: unknown) { // Normal file has not been created so we don't want the metadata file to remain. await fsPromises.unlink(this.resourceMapper.getAbsolutePath(path, `${resourceName}.metadata`)); throw error; @@ -417,7 +418,7 @@ export class FileResourceStore implements ResourceStore { } } await fsPromises.mkdir(fullPath, { recursive: allowRecursiveCreation }); - } catch (error) { + } catch (error: unknown) { if (error instanceof MethodNotAllowedHttpError) { throw error; } @@ -429,7 +430,7 @@ export class FileResourceStore implements ResourceStore { if (metadata) { try { await this.createDataFile(joinPath(fullPath, '.metadata'), metadata); - } catch (error) { + } catch (error: unknown) { // Failed to create the metadata file so remove the created directory. await fsPromises.rmdir(fullPath); throw error; diff --git a/src/storage/InMemoryResourceStore.ts b/src/storage/InMemoryResourceStore.ts index 1d67f9752..654c0856a 100644 --- a/src/storage/InMemoryResourceStore.ts +++ b/src/storage/InMemoryResourceStore.ts @@ -1,14 +1,14 @@ import { PassThrough } from 'stream'; import arrayifyStream from 'arrayify-stream'; import streamifyArray from 'streamify-array'; -import { Representation } from '../ldp/representation/Representation'; +import type { Representation } from '../ldp/representation/Representation'; import { RepresentationMetadata } from '../ldp/representation/RepresentationMetadata'; -import { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier'; +import type { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier'; import { TEXT_TURTLE } from '../util/ContentTypes'; import { NotFoundHttpError } from '../util/errors/NotFoundHttpError'; import { CONTENT_TYPE } from '../util/UriConstants'; import { ensureTrailingSlash } from '../util/Util'; -import { ResourceStore } from './ResourceStore'; +import type { ResourceStore } from './ResourceStore'; /** * Resource store storing its data in an in-memory map. @@ -133,10 +133,9 @@ export class InMemoryResourceStore implements ResourceStore { * @param source - Incoming Representation. */ private async copyRepresentation(source: Representation): Promise { - const arr = await arrayifyStream(source.data); return { binary: source.binary, - data: streamifyArray([ ...arr ]), + data: streamifyArray(await arrayifyStream(source.data)), metadata: source.metadata, }; } diff --git a/src/storage/LockingResourceStore.ts b/src/storage/LockingResourceStore.ts index 30d414bb3..652d23405 100644 --- a/src/storage/LockingResourceStore.ts +++ b/src/storage/LockingResourceStore.ts @@ -1,12 +1,12 @@ -import { Readable } from 'stream'; -import { Patch } from '../ldp/http/Patch'; -import { Representation } from '../ldp/representation/Representation'; -import { RepresentationPreferences } from '../ldp/representation/RepresentationPreferences'; -import { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier'; -import { AtomicResourceStore } from './AtomicResourceStore'; -import { Conditions } from './Conditions'; -import { ResourceLocker } from './ResourceLocker'; -import { ResourceStore } from './ResourceStore'; +import type { Readable } from 'stream'; +import type { Patch } from '../ldp/http/Patch'; +import type { Representation } from '../ldp/representation/Representation'; +import type { RepresentationPreferences } from '../ldp/representation/RepresentationPreferences'; +import type { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier'; +import type { AtomicResourceStore } from './AtomicResourceStore'; +import type { Conditions } from './Conditions'; +import type { ResourceLocker } from './ResourceLocker'; +import type { ResourceStore } from './ResourceStore'; /** Time in ms after which reading a representation times out, causing the lock to be released. */ const READ_TIMEOUT = 1000; diff --git a/src/storage/PassthroughStore.ts b/src/storage/PassthroughStore.ts index 6bef3a45a..a24637770 100644 --- a/src/storage/PassthroughStore.ts +++ b/src/storage/PassthroughStore.ts @@ -1,9 +1,9 @@ -import { Patch } from '../ldp/http/Patch'; -import { Representation } from '../ldp/representation/Representation'; -import { RepresentationPreferences } from '../ldp/representation/RepresentationPreferences'; -import { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier'; -import { Conditions } from './Conditions'; -import { ResourceStore } from './ResourceStore'; +import type { Patch } from '../ldp/http/Patch'; +import type { Representation } from '../ldp/representation/Representation'; +import type { RepresentationPreferences } from '../ldp/representation/RepresentationPreferences'; +import type { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier'; +import type { Conditions } from './Conditions'; +import type { ResourceStore } from './ResourceStore'; /** * Store that calls the corresponding functions of the source Store. diff --git a/src/storage/PatchingStore.ts b/src/storage/PatchingStore.ts index a2987b64a..727d40216 100644 --- a/src/storage/PatchingStore.ts +++ b/src/storage/PatchingStore.ts @@ -1,9 +1,9 @@ -import { Patch } from '../ldp/http/Patch'; -import { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier'; -import { Conditions } from './Conditions'; +import type { Patch } from '../ldp/http/Patch'; +import type { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier'; +import type { Conditions } from './Conditions'; import { PassthroughStore } from './PassthroughStore'; -import { PatchHandler } from './patch/PatchHandler'; -import { ResourceStore } from './ResourceStore'; +import type { PatchHandler } from './patch/PatchHandler'; +import type { ResourceStore } from './ResourceStore'; /** * {@link ResourceStore} using decorator pattern for the `modifyResource` function. @@ -21,7 +21,7 @@ export class PatchingStore extends Pass public async modifyResource(identifier: ResourceIdentifier, patch: Patch, conditions?: Conditions): Promise { try { return await this.source.modifyResource(identifier, patch, conditions); - } catch (error) { + } catch { return this.patcher.handleSafe({ identifier, patch }); } } diff --git a/src/storage/RepresentationConvertingStore.ts b/src/storage/RepresentationConvertingStore.ts index 65ab2b583..eb32b2315 100644 --- a/src/storage/RepresentationConvertingStore.ts +++ b/src/storage/RepresentationConvertingStore.ts @@ -1,11 +1,11 @@ -import { Representation } from '../ldp/representation/Representation'; -import { RepresentationPreferences } from '../ldp/representation/RepresentationPreferences'; -import { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier'; +import type { Representation } from '../ldp/representation/Representation'; +import type { RepresentationPreferences } from '../ldp/representation/RepresentationPreferences'; +import type { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier'; import { matchingMediaType } from '../util/Util'; -import { Conditions } from './Conditions'; -import { RepresentationConverter } from './conversion/RepresentationConverter'; +import type { Conditions } from './Conditions'; +import type { RepresentationConverter } from './conversion/RepresentationConverter'; import { PassthroughStore } from './PassthroughStore'; -import { ResourceStore } from './ResourceStore'; +import type { ResourceStore } from './ResourceStore'; /** * Store that overrides the `getRepresentation` function. diff --git a/src/storage/ResourceLocker.ts b/src/storage/ResourceLocker.ts index 2b25adb9b..93e1a5960 100644 --- a/src/storage/ResourceLocker.ts +++ b/src/storage/ResourceLocker.ts @@ -1,5 +1,5 @@ -import { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier'; -import { Lock } from './Lock'; +import type { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier'; +import type { Lock } from './Lock'; /** * Allows the locking of resources which is needed for non-atomic {@link ResourceStore}s. diff --git a/src/storage/ResourceStore.ts b/src/storage/ResourceStore.ts index 353ec7932..a9e1d657d 100644 --- a/src/storage/ResourceStore.ts +++ b/src/storage/ResourceStore.ts @@ -1,8 +1,8 @@ -import { Patch } from '../ldp/http/Patch'; -import { Representation } from '../ldp/representation/Representation'; -import { RepresentationPreferences } from '../ldp/representation/RepresentationPreferences'; -import { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier'; -import { Conditions } from './Conditions'; +import type { Patch } from '../ldp/http/Patch'; +import type { Representation } from '../ldp/representation/Representation'; +import type { RepresentationPreferences } from '../ldp/representation/RepresentationPreferences'; +import type { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier'; +import type { Conditions } from './Conditions'; /** * A ResourceStore represents a collection of resources. diff --git a/src/storage/SingleThreadedResourceLocker.ts b/src/storage/SingleThreadedResourceLocker.ts index da800b373..23ccbc974 100644 --- a/src/storage/SingleThreadedResourceLocker.ts +++ b/src/storage/SingleThreadedResourceLocker.ts @@ -1,7 +1,7 @@ import AsyncLock from 'async-lock'; -import { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier'; -import { Lock } from './Lock'; -import { ResourceLocker } from './ResourceLocker'; +import type { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier'; +import type { Lock } from './Lock'; +import type { ResourceLocker } from './ResourceLocker'; /** * A resource locker making use of the `async-lock` library. diff --git a/src/storage/UrlContainerManager.ts b/src/storage/UrlContainerManager.ts index ca74c384d..79d9012a0 100644 --- a/src/storage/UrlContainerManager.ts +++ b/src/storage/UrlContainerManager.ts @@ -1,6 +1,6 @@ -import { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier'; +import type { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier'; import { ensureTrailingSlash } from '../util/Util'; -import { ContainerManager } from './ContainerManager'; +import type { ContainerManager } from './ContainerManager'; /** * Determines containers based on URL decomposition. diff --git a/src/storage/conversion/ChainedConverter.ts b/src/storage/conversion/ChainedConverter.ts index 21538d081..5e6c9babc 100644 --- a/src/storage/conversion/ChainedConverter.ts +++ b/src/storage/conversion/ChainedConverter.ts @@ -1,9 +1,9 @@ -import { Representation } from '../../ldp/representation/Representation'; +import type { Representation } from '../../ldp/representation/Representation'; import { RepresentationMetadata } from '../../ldp/representation/RepresentationMetadata'; -import { RepresentationPreferences } from '../../ldp/representation/RepresentationPreferences'; +import type { RepresentationPreferences } from '../../ldp/representation/RepresentationPreferences'; import { CONTENT_TYPE } from '../../util/UriConstants'; import { matchingMediaType } from '../../util/Util'; -import { RepresentationConverterArgs } from './RepresentationConverter'; +import type { RepresentationConverterArgs } from './RepresentationConverter'; import { TypedRepresentationConverter } from './TypedRepresentationConverter'; /** diff --git a/src/storage/conversion/ConversionUtil.ts b/src/storage/conversion/ConversionUtil.ts index 0d2921f6b..72a5ec8c6 100644 --- a/src/storage/conversion/ConversionUtil.ts +++ b/src/storage/conversion/ConversionUtil.ts @@ -1,8 +1,8 @@ -import { RepresentationPreference } from '../../ldp/representation/RepresentationPreference'; -import { RepresentationPreferences } from '../../ldp/representation/RepresentationPreferences'; +import type { RepresentationPreference } from '../../ldp/representation/RepresentationPreference'; +import type { RepresentationPreferences } from '../../ldp/representation/RepresentationPreferences'; import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError'; import { matchingMediaType } from '../../util/Util'; -import { RepresentationConverterArgs } from './RepresentationConverter'; +import type { RepresentationConverterArgs } from './RepresentationConverter'; /** * Filters out the media types from the preferred types that correspond to one of the supported types. diff --git a/src/storage/conversion/QuadToRdfConverter.ts b/src/storage/conversion/QuadToRdfConverter.ts index b6cbcc29a..91cf257d9 100644 --- a/src/storage/conversion/QuadToRdfConverter.ts +++ b/src/storage/conversion/QuadToRdfConverter.ts @@ -1,12 +1,12 @@ -import { Readable } from 'stream'; +import type { Readable } from 'stream'; import rdfSerializer from 'rdf-serialize'; -import { Representation } from '../../ldp/representation/Representation'; +import type { Representation } from '../../ldp/representation/Representation'; import { RepresentationMetadata } from '../../ldp/representation/RepresentationMetadata'; -import { RepresentationPreferences } from '../../ldp/representation/RepresentationPreferences'; +import type { RepresentationPreferences } from '../../ldp/representation/RepresentationPreferences'; import { INTERNAL_QUADS } from '../../util/ContentTypes'; import { CONTENT_TYPE } from '../../util/UriConstants'; import { checkRequest, matchingTypes } from './ConversionUtil'; -import { RepresentationConverterArgs } from './RepresentationConverter'; +import type { RepresentationConverterArgs } from './RepresentationConverter'; import { TypedRepresentationConverter } from './TypedRepresentationConverter'; /** diff --git a/src/storage/conversion/QuadToTurtleConverter.ts b/src/storage/conversion/QuadToTurtleConverter.ts index d99524123..e17fb8bbf 100644 --- a/src/storage/conversion/QuadToTurtleConverter.ts +++ b/src/storage/conversion/QuadToTurtleConverter.ts @@ -1,10 +1,11 @@ import { StreamWriter } from 'n3'; -import { Representation } from '../../ldp/representation/Representation'; +import type { Representation } from '../../ldp/representation/Representation'; import { RepresentationMetadata } from '../../ldp/representation/RepresentationMetadata'; import { INTERNAL_QUADS, TEXT_TURTLE } from '../../util/ContentTypes'; import { CONTENT_TYPE } from '../../util/UriConstants'; import { checkRequest } from './ConversionUtil'; -import { RepresentationConverter, RepresentationConverterArgs } from './RepresentationConverter'; +import type { RepresentationConverterArgs } from './RepresentationConverter'; +import { RepresentationConverter } from './RepresentationConverter'; /** * Converts `internal/quads` to `text/turtle`. diff --git a/src/storage/conversion/RdfToQuadConverter.ts b/src/storage/conversion/RdfToQuadConverter.ts index bf7db1eb5..040416183 100644 --- a/src/storage/conversion/RdfToQuadConverter.ts +++ b/src/storage/conversion/RdfToQuadConverter.ts @@ -1,12 +1,12 @@ import { PassThrough } from 'stream'; import rdfParser from 'rdf-parse'; -import { Representation } from '../../ldp/representation/Representation'; +import type { Representation } from '../../ldp/representation/Representation'; import { RepresentationMetadata } from '../../ldp/representation/RepresentationMetadata'; import { INTERNAL_QUADS } from '../../util/ContentTypes'; import { CONTENT_TYPE } from '../../util/UriConstants'; import { pipeStreamsAndErrors } from '../../util/Util'; import { checkRequest } from './ConversionUtil'; -import { RepresentationConverterArgs } from './RepresentationConverter'; +import type { RepresentationConverterArgs } from './RepresentationConverter'; import { TypedRepresentationConverter } from './TypedRepresentationConverter'; /** diff --git a/src/storage/conversion/RepresentationConverter.ts b/src/storage/conversion/RepresentationConverter.ts index fd3336501..9197ce173 100644 --- a/src/storage/conversion/RepresentationConverter.ts +++ b/src/storage/conversion/RepresentationConverter.ts @@ -1,6 +1,6 @@ -import { Representation } from '../../ldp/representation/Representation'; -import { RepresentationPreferences } from '../../ldp/representation/RepresentationPreferences'; -import { ResourceIdentifier } from '../../ldp/representation/ResourceIdentifier'; +import type { Representation } from '../../ldp/representation/Representation'; +import type { RepresentationPreferences } from '../../ldp/representation/RepresentationPreferences'; +import type { ResourceIdentifier } from '../../ldp/representation/ResourceIdentifier'; import { AsyncHandler } from '../../util/AsyncHandler'; export interface RepresentationConverterArgs { diff --git a/src/storage/conversion/TurtleToQuadConverter.ts b/src/storage/conversion/TurtleToQuadConverter.ts index 983c61020..a78488ea0 100644 --- a/src/storage/conversion/TurtleToQuadConverter.ts +++ b/src/storage/conversion/TurtleToQuadConverter.ts @@ -1,12 +1,13 @@ import { PassThrough } from 'stream'; import { StreamParser } from 'n3'; -import { Representation } from '../../ldp/representation/Representation'; +import type { Representation } from '../../ldp/representation/Representation'; import { RepresentationMetadata } from '../../ldp/representation/RepresentationMetadata'; import { TEXT_TURTLE, INTERNAL_QUADS } from '../../util/ContentTypes'; import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError'; import { CONTENT_TYPE } from '../../util/UriConstants'; import { checkRequest } from './ConversionUtil'; -import { RepresentationConverter, RepresentationConverterArgs } from './RepresentationConverter'; +import type { RepresentationConverterArgs } from './RepresentationConverter'; +import { RepresentationConverter } from './RepresentationConverter'; /** * Converts `text/turtle` to `internal/quads`. diff --git a/src/storage/patch/PatchHandler.ts b/src/storage/patch/PatchHandler.ts index fdb7ba492..e03ec21f1 100644 --- a/src/storage/patch/PatchHandler.ts +++ b/src/storage/patch/PatchHandler.ts @@ -1,5 +1,5 @@ -import { Patch } from '../../ldp/http/Patch'; -import { ResourceIdentifier } from '../../ldp/representation/ResourceIdentifier'; +import type { Patch } from '../../ldp/http/Patch'; +import type { ResourceIdentifier } from '../../ldp/representation/ResourceIdentifier'; import { AsyncHandler } from '../../util/AsyncHandler'; export abstract class PatchHandler extends AsyncHandler<{identifier: ResourceIdentifier; patch: Patch}> {} diff --git a/src/storage/patch/SparqlUpdatePatchHandler.ts b/src/storage/patch/SparqlUpdatePatchHandler.ts index f458aadd7..d83b169b0 100644 --- a/src/storage/patch/SparqlUpdatePatchHandler.ts +++ b/src/storage/patch/SparqlUpdatePatchHandler.ts @@ -1,18 +1,18 @@ -import { Readable } from 'stream'; +import type { Readable } from 'stream'; import { defaultGraph } from '@rdfjs/data-model'; import { Store } from 'n3'; import type { BaseQuad } from 'rdf-js'; import { someTerms } from 'rdf-terms'; import { Algebra } from 'sparqlalgebrajs'; -import { SparqlUpdatePatch } from '../../ldp/http/SparqlUpdatePatch'; -import { Representation } from '../../ldp/representation/Representation'; +import type { SparqlUpdatePatch } from '../../ldp/http/SparqlUpdatePatch'; +import type { Representation } from '../../ldp/representation/Representation'; import { RepresentationMetadata } from '../../ldp/representation/RepresentationMetadata'; -import { ResourceIdentifier } from '../../ldp/representation/ResourceIdentifier'; +import type { ResourceIdentifier } from '../../ldp/representation/ResourceIdentifier'; import { INTERNAL_QUADS } from '../../util/ContentTypes'; import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError'; import { CONTENT_TYPE } from '../../util/UriConstants'; -import { ResourceLocker } from '../ResourceLocker'; -import { ResourceStore } from '../ResourceStore'; +import type { ResourceLocker } from '../ResourceLocker'; +import type { ResourceStore } from '../ResourceStore'; import { PatchHandler } from './PatchHandler'; /** diff --git a/src/util/AcceptParser.ts b/src/util/AcceptParser.ts index b442854b4..8febdb1ac 100644 --- a/src/util/AcceptParser.ts +++ b/src/util/AcceptParser.ts @@ -104,7 +104,7 @@ const transformQuotedStrings = (input: string): { result: string; replacements: const replacements: { [id: string]: string } = {}; const result = input.replace(/"(?:[^"\\]|\\.)*"/gu, (match): string => { // Not all characters allowed in quoted strings, see BNF above - if (!/^"(?:[\t !\u0023-\u005b\u005d-\u007e\u0080-\u00ff]|(?:\\[\t\u0020-\u007e\u0080-\u00ff]))*"$/u.test(match)) { + if (!/^"(?:[\t !\u0023-\u005B\u005D-\u007E\u0080-\u00FF]|(?:\\[\t\u0020-\u007E\u0080-\u00FF]))*"$/u.test(match)) { throw new UnsupportedHttpError( `Invalid quoted string in Accept header: ${match}. Check which characters are allowed`, ); @@ -179,7 +179,7 @@ const parseAcceptPart = (part: string, replacements: { [id: string]: string }): // Extension parameters appear after the q value map = extensionParams; testQValue(param); - weight = parseFloat(value); + weight = Number.parseFloat(value); } else { // Test replaced string for easier check // parameter = token "=" ( token / quoted-string ) @@ -229,7 +229,7 @@ const parseNoParameters = (input: string): { range: string; weight: number }[] = const result = { range, weight: 1 }; if (qvalue) { testQValue(qvalue); - result.weight = parseFloat(qvalue.split('=')[1]); + result.weight = Number.parseFloat(qvalue.split('=')[1]); } return result; }).sort((left, right): number => right.weight - left.weight); diff --git a/src/util/AsyncHandler.ts b/src/util/AsyncHandler.ts index 9731c8f79..27ce2a134 100644 --- a/src/util/AsyncHandler.ts +++ b/src/util/AsyncHandler.ts @@ -9,7 +9,7 @@ export abstract class AsyncHandler { * * @returns A promise resolving if this input can be handled, rejecting with an Error if not. */ - public abstract canHandle (input: TInput): Promise; + public abstract canHandle(input: TInput): Promise; /** * Handles the given input. This should only be done if the {@link canHandle} function returned `true`. @@ -17,7 +17,7 @@ export abstract class AsyncHandler { * * @returns A promise resolving when the handling is finished. Return value depends on the given type. */ - public abstract handle (input: TInput): Promise; + public abstract handle(input: TInput): Promise; /** * Helper function that first runs the canHandle function followed by the handle function. diff --git a/src/util/CompositeAsyncHandler.ts b/src/util/CompositeAsyncHandler.ts index d024c3a85..b1fbe887c 100644 --- a/src/util/CompositeAsyncHandler.ts +++ b/src/util/CompositeAsyncHandler.ts @@ -1,4 +1,4 @@ -import { AsyncHandler } from './AsyncHandler'; +import type { AsyncHandler } from './AsyncHandler'; import { UnsupportedHttpError } from './errors/UnsupportedHttpError'; /** @@ -40,7 +40,7 @@ export class CompositeAsyncHandler implements AsyncHandler try { handler = await this.findHandler(input); - } catch (error) { + } catch { throw new Error('All handlers failed. This might be the consequence of calling handle before canHandle.'); } @@ -77,8 +77,12 @@ export class CompositeAsyncHandler implements AsyncHandler await handler.canHandle(input); return handler; - } catch (error) { - errors.push(error); + } catch (error: unknown) { + if (error instanceof Error) { + errors.push(error); + } else { + errors.push(new Error('Unknown error.')); + } } } diff --git a/src/util/MetadataController.ts b/src/util/MetadataController.ts index 89c76223d..f960048b0 100644 --- a/src/util/MetadataController.ts +++ b/src/util/MetadataController.ts @@ -1,5 +1,5 @@ -import { Stats } from 'fs'; -import { Readable } from 'stream'; +import type { Stats } from 'fs'; +import type { Readable } from 'stream'; import arrayifyStream from 'arrayify-stream'; import { DataFactory, StreamParser, StreamWriter } from 'n3'; import type { Quad } from 'rdf-js'; diff --git a/src/util/UriConstants.ts b/src/util/UriConstants.ts index fe9653fe2..eaa45ef41 100644 --- a/src/util/UriConstants.ts +++ b/src/util/UriConstants.ts @@ -1,4 +1,4 @@ -const createSuffixFn = (prefix: string): any => (suffix: string): string => `${prefix}${suffix}`; +const createSuffixFn = (prefix: string): ((suf: string) => string) => (suffix: string): string => `${prefix}${suffix}`; const ACL_PREFIX = createSuffixFn('http://www.w3.org/ns/auth/acl#'); export const ACL = { diff --git a/src/util/Util.ts b/src/util/Util.ts index 40ff5d670..080f08178 100644 --- a/src/util/Util.ts +++ b/src/util/Util.ts @@ -1,4 +1,4 @@ -import { Readable, Writable } from 'stream'; +import type { Readable, Writable } from 'stream'; import arrayifyStream from 'arrayify-stream'; import { UnsupportedHttpError } from './errors/UnsupportedHttpError'; diff --git a/test/.eslintrc.js b/test/.eslintrc.js index 360045186..64c1468db 100644 --- a/test/.eslintrc.js +++ b/test/.eslintrc.js @@ -1,5 +1,13 @@ module.exports = { env: { jest: true + }, + rules: { + '@typescript-eslint/no-unsafe-assignment': 'off', + 'unicorn/no-useless-undefined': 'off', + + // Need these 2 to run tests for throwing non-Error objects + '@typescript-eslint/no-throw-literal': 'off', + 'no-throw-literal': 'off', } }; diff --git a/test/configs/AuthenticatedFileResourceStoreConfig.ts b/test/configs/AuthenticatedFileResourceStoreConfig.ts index ce0f3c087..fd0da7233 100644 --- a/test/configs/AuthenticatedFileResourceStoreConfig.ts +++ b/test/configs/AuthenticatedFileResourceStoreConfig.ts @@ -1,15 +1,15 @@ +import type { HttpHandler, + ResourceStore } from '../../index'; import { AuthenticatedLdpHandler, BasicResponseWriter, CompositeAsyncHandler, - HttpHandler, MethodPermissionsExtractor, RdfToQuadConverter, - ResourceStore, UnsecureWebIdExtractor, QuadToRdfConverter, } from '../../index'; -import { ServerConfig } from './ServerConfig'; +import type { ServerConfig } from './ServerConfig'; import { getFileResourceStore, getConvertingStore, diff --git a/test/configs/BasicConfig.ts b/test/configs/BasicConfig.ts index 4140efe01..ec22b9b1f 100644 --- a/test/configs/BasicConfig.ts +++ b/test/configs/BasicConfig.ts @@ -1,13 +1,13 @@ +import type { HttpHandler, + ResourceStore } from '../../index'; import { AllowEverythingAuthorizer, AuthenticatedLdpHandler, BasicResponseWriter, - HttpHandler, MethodPermissionsExtractor, - ResourceStore, UnsecureWebIdExtractor, } from '../../index'; -import { ServerConfig } from './ServerConfig'; +import type { ServerConfig } from './ServerConfig'; import { getOperationHandler, getInMemoryResourceStore, getBasicRequestParser } from './Util'; /** diff --git a/test/configs/BasicHandlersConfig.ts b/test/configs/BasicHandlersConfig.ts index 3f7894ed1..a6d88d025 100644 --- a/test/configs/BasicHandlersConfig.ts +++ b/test/configs/BasicHandlersConfig.ts @@ -1,20 +1,20 @@ +import type { HttpHandler, + ResourceStore } from '../../index'; import { AllowEverythingAuthorizer, AuthenticatedLdpHandler, BasicResponseWriter, CompositeAsyncHandler, - HttpHandler, MethodPermissionsExtractor, QuadToRdfConverter, RawBodyParser, RdfToQuadConverter, - ResourceStore, SparqlUpdateBodyParser, SparqlPatchPermissionsExtractor, UnsecureWebIdExtractor, } from '../../index'; -import { ServerConfig } from './ServerConfig'; +import type { ServerConfig } from './ServerConfig'; import { getInMemoryResourceStore, getOperationHandler, getConvertingStore, diff --git a/test/configs/BasicHandlersWithAclConfig.ts b/test/configs/BasicHandlersWithAclConfig.ts index a291898dd..49b280e1c 100644 --- a/test/configs/BasicHandlersWithAclConfig.ts +++ b/test/configs/BasicHandlersWithAclConfig.ts @@ -1,15 +1,15 @@ +import type { HttpHandler, + ResourceStore } from '../../index'; import { AuthenticatedLdpHandler, BasicResponseWriter, CompositeAsyncHandler, - HttpHandler, MethodPermissionsExtractor, RdfToQuadConverter, - ResourceStore, UnsecureWebIdExtractor, QuadToRdfConverter, } from '../../index'; -import { ServerConfig } from './ServerConfig'; +import type { ServerConfig } from './ServerConfig'; import { getInMemoryResourceStore, getConvertingStore, diff --git a/test/configs/FileResourceStoreConfig.ts b/test/configs/FileResourceStoreConfig.ts index a00dca829..5b091dd76 100644 --- a/test/configs/FileResourceStoreConfig.ts +++ b/test/configs/FileResourceStoreConfig.ts @@ -1,17 +1,17 @@ +import type { HttpHandler, + ResourceStore } from '../../index'; import { AllowEverythingAuthorizer, AuthenticatedLdpHandler, BasicResponseWriter, CompositeAsyncHandler, - HttpHandler, MethodPermissionsExtractor, QuadToRdfConverter, RawBodyParser, RdfToQuadConverter, - ResourceStore, UnsecureWebIdExtractor, } from '../../index'; -import { ServerConfig } from './ServerConfig'; +import type { ServerConfig } from './ServerConfig'; import { getFileResourceStore, getOperationHandler, getConvertingStore, getBasicRequestParser } from './Util'; /** diff --git a/test/configs/ServerConfig.ts b/test/configs/ServerConfig.ts index b29bdce18..f9dc5c3b1 100644 --- a/test/configs/ServerConfig.ts +++ b/test/configs/ServerConfig.ts @@ -1,5 +1,5 @@ -import { HttpHandler } from '../../src/server/HttpHandler'; +import type { HttpHandler } from '../../src/server/HttpHandler'; export interface ServerConfig { - getHttpHandler(): HttpHandler; + getHttpHandler: () => HttpHandler; } diff --git a/test/configs/Util.ts b/test/configs/Util.ts index bc716b67a..e98e7178a 100644 --- a/test/configs/Util.ts +++ b/test/configs/Util.ts @@ -1,28 +1,28 @@ import { join } from 'path'; +import type { BodyParser, + HttpRequest, + Operation, + Representation, + RepresentationConverter, + ResourceStore, + ResponseDescription } from '../../index'; import { AcceptPreferenceParser, BasicRequestParser, BasicTargetExtractor, - BodyParser, CompositeAsyncHandler, DeleteOperationHandler, FileResourceStore, GetOperationHandler, - HttpRequest, InMemoryResourceStore, InteractionController, MetadataController, - Operation, PatchingStore, PatchOperationHandler, PostOperationHandler, PutOperationHandler, RawBodyParser, - Representation, - RepresentationConverter, RepresentationConvertingStore, - ResourceStore, - ResponseDescription, SingleThreadedResourceLocker, SparqlUpdatePatchHandler, UrlBasedAclManager, diff --git a/test/integration/AuthenticatedFileResourceStore.test.ts b/test/integration/AuthenticatedFileResourceStore.test.ts index 1b0f2db42..d1584d67f 100644 --- a/test/integration/AuthenticatedFileResourceStore.test.ts +++ b/test/integration/AuthenticatedFileResourceStore.test.ts @@ -1,7 +1,7 @@ import { copyFileSync, mkdirSync } from 'fs'; import { join } from 'path'; import * as rimraf from 'rimraf'; -import { HttpHandler, ResourceStore } from '../../index'; +import type { HttpHandler, ResourceStore } from '../../index'; import { ensureTrailingSlash } from '../../src/util/Util'; import { AuthenticatedFileResourceStoreConfig } from '../configs/AuthenticatedFileResourceStoreConfig'; import { BASE, getRootFilePath } from '../configs/Util'; diff --git a/test/integration/AuthenticatedLdpHandler.test.ts b/test/integration/AuthenticatedLdpHandler.test.ts index 41c200c04..9f8b02148 100644 --- a/test/integration/AuthenticatedLdpHandler.test.ts +++ b/test/integration/AuthenticatedLdpHandler.test.ts @@ -1,7 +1,7 @@ import * as url from 'url'; import { namedNode, quad } from '@rdfjs/data-model'; import { Parser } from 'n3'; -import { MockResponse } from 'node-mocks-http'; +import type { MockResponse } from 'node-mocks-http'; import { BasicConfig } from '../configs/BasicConfig'; import { BasicHandlersConfig } from '../configs/BasicHandlersConfig'; import { call } from '../util/Util'; diff --git a/test/integration/Authorization.test.ts b/test/integration/Authorization.test.ts index 31a43d24e..fca7a4c2f 100644 --- a/test/integration/Authorization.test.ts +++ b/test/integration/Authorization.test.ts @@ -1,4 +1,4 @@ -import { MockResponse } from 'node-mocks-http'; +import type { MockResponse } from 'node-mocks-http'; import { BasicHandlersWithAclConfig } from '../configs/BasicHandlersWithAclConfig'; import { AclTestHelper } from '../util/TestHelpers'; import { call } from '../util/Util'; diff --git a/test/integration/FileResourceStore.test.ts b/test/integration/FileResourceStore.test.ts index f7e8452ca..8d7256ce5 100644 --- a/test/integration/FileResourceStore.test.ts +++ b/test/integration/FileResourceStore.test.ts @@ -1,5 +1,5 @@ import * as rimraf from 'rimraf'; -import { HttpHandler } from '../../src/server/HttpHandler'; +import type { HttpHandler } from '../../src/server/HttpHandler'; import { FileResourceStoreConfig } from '../configs/FileResourceStoreConfig'; import { BASE, getRootFilePath } from '../configs/Util'; import { FileTestHelper } from '../util/TestHelpers'; diff --git a/test/integration/RepresentationConverter.test.ts b/test/integration/RepresentationConverter.test.ts index 620332b7f..c659f5227 100644 --- a/test/integration/RepresentationConverter.test.ts +++ b/test/integration/RepresentationConverter.test.ts @@ -1,5 +1,5 @@ import streamifyArray from 'streamify-array'; -import { Representation } from '../../src/ldp/representation/Representation'; +import type { Representation } from '../../src/ldp/representation/Representation'; import { RepresentationMetadata } from '../../src/ldp/representation/RepresentationMetadata'; import { ChainedConverter } from '../../src/storage/conversion/ChainedConverter'; import { QuadToRdfConverter } from '../../src/storage/conversion/QuadToRdfConverter'; diff --git a/test/integration/RequestParser.test.ts b/test/integration/RequestParser.test.ts index 4598698e0..d5abb0f47 100644 --- a/test/integration/RequestParser.test.ts +++ b/test/integration/RequestParser.test.ts @@ -6,7 +6,7 @@ import { BasicRequestParser } from '../../src/ldp/http/BasicRequestParser'; import { BasicTargetExtractor } from '../../src/ldp/http/BasicTargetExtractor'; import { RawBodyParser } from '../../src/ldp/http/RawBodyParser'; import { RepresentationMetadata } from '../../src/ldp/representation/RepresentationMetadata'; -import { HttpRequest } from '../../src/server/HttpRequest'; +import type { HttpRequest } from '../../src/server/HttpRequest'; describe('A BasicRequestParser with simple input parsers', (): void => { const targetExtractor = new BasicTargetExtractor(); diff --git a/test/unit/authentication/UnsecureWebIdExtractor.ts b/test/unit/authentication/UnsecureWebIdExtractor.ts index 9461f71b9..2b6416b2c 100644 --- a/test/unit/authentication/UnsecureWebIdExtractor.ts +++ b/test/unit/authentication/UnsecureWebIdExtractor.ts @@ -1,5 +1,5 @@ import { UnsecureWebIdExtractor } from '../../../src/authentication/UnsecureWebIdExtractor'; -import { HttpRequest } from '../../../src/server/HttpRequest'; +import type { HttpRequest } from '../../../src/server/HttpRequest'; describe('An UnsecureWebIdExtractor', (): void => { const extractor = new UnsecureWebIdExtractor(); diff --git a/test/unit/authorization/WebAclAuthorizer.test.ts b/test/unit/authorization/WebAclAuthorizer.test.ts index dbe2b2386..0790768b7 100644 --- a/test/unit/authorization/WebAclAuthorizer.test.ts +++ b/test/unit/authorization/WebAclAuthorizer.test.ts @@ -1,13 +1,13 @@ import { namedNode, quad } from '@rdfjs/data-model'; import streamifyArray from 'streamify-array'; -import { Credentials } from '../../../src/authentication/Credentials'; -import { AclManager } from '../../../src/authorization/AclManager'; +import type { Credentials } from '../../../src/authentication/Credentials'; +import type { AclManager } from '../../../src/authorization/AclManager'; import { WebAclAuthorizer } from '../../../src/authorization/WebAclAuthorizer'; -import { PermissionSet } from '../../../src/ldp/permissions/PermissionSet'; -import { Representation } from '../../../src/ldp/representation/Representation'; -import { ResourceIdentifier } from '../../../src/ldp/representation/ResourceIdentifier'; -import { ContainerManager } from '../../../src/storage/ContainerManager'; -import { ResourceStore } from '../../../src/storage/ResourceStore'; +import type { PermissionSet } from '../../../src/ldp/permissions/PermissionSet'; +import type { Representation } from '../../../src/ldp/representation/Representation'; +import type { ResourceIdentifier } from '../../../src/ldp/representation/ResourceIdentifier'; +import type { ContainerManager } from '../../../src/storage/ContainerManager'; +import type { ResourceStore } from '../../../src/storage/ResourceStore'; import { ForbiddenHttpError } from '../../../src/util/errors/ForbiddenHttpError'; import { NotFoundHttpError } from '../../../src/util/errors/NotFoundHttpError'; import { UnauthorizedHttpError } from '../../../src/util/errors/UnauthorizedHttpError'; diff --git a/test/unit/init/Setup.test.ts b/test/unit/init/Setup.test.ts index 041ca0a21..6b84f4650 100644 --- a/test/unit/init/Setup.test.ts +++ b/test/unit/init/Setup.test.ts @@ -1,5 +1,5 @@ import { Setup } from '../../../src/init/Setup'; -import { ResourceIdentifier } from '../../../src/ldp/representation/ResourceIdentifier'; +import type { ResourceIdentifier } from '../../../src/ldp/representation/ResourceIdentifier'; describe('Setup', (): void => { let httpServer: any; diff --git a/test/unit/ldp/AuthenticatedLdpHandler.test.ts b/test/unit/ldp/AuthenticatedLdpHandler.test.ts index 12e95be0d..690499cda 100644 --- a/test/unit/ldp/AuthenticatedLdpHandler.test.ts +++ b/test/unit/ldp/AuthenticatedLdpHandler.test.ts @@ -1,13 +1,14 @@ -import { CredentialsExtractor } from '../../../src/authentication/CredentialsExtractor'; -import { Authorizer } from '../../../src/authorization/Authorizer'; -import { AuthenticatedLdpHandler, AuthenticatedLdpHandlerArgs } from '../../../src/ldp/AuthenticatedLdpHandler'; -import { RequestParser } from '../../../src/ldp/http/RequestParser'; -import { ResponseWriter } from '../../../src/ldp/http/ResponseWriter'; -import { Operation } from '../../../src/ldp/operations/Operation'; -import { OperationHandler } from '../../../src/ldp/operations/OperationHandler'; -import { PermissionsExtractor } from '../../../src/ldp/permissions/PermissionsExtractor'; -import { HttpRequest } from '../../../src/server/HttpRequest'; -import { HttpResponse } from '../../../src/server/HttpResponse'; +import type { CredentialsExtractor } from '../../../src/authentication/CredentialsExtractor'; +import type { Authorizer } from '../../../src/authorization/Authorizer'; +import type { AuthenticatedLdpHandlerArgs } from '../../../src/ldp/AuthenticatedLdpHandler'; +import { AuthenticatedLdpHandler } from '../../../src/ldp/AuthenticatedLdpHandler'; +import type { RequestParser } from '../../../src/ldp/http/RequestParser'; +import type { ResponseWriter } from '../../../src/ldp/http/ResponseWriter'; +import type { Operation } from '../../../src/ldp/operations/Operation'; +import type { OperationHandler } from '../../../src/ldp/operations/OperationHandler'; +import type { PermissionsExtractor } from '../../../src/ldp/permissions/PermissionsExtractor'; +import type { HttpRequest } from '../../../src/server/HttpRequest'; +import type { HttpResponse } from '../../../src/server/HttpResponse'; import { StaticAsyncHandler } from '../../util/StaticAsyncHandler'; describe('An AuthenticatedLdpHandler', (): void => { @@ -67,4 +68,13 @@ describe('An AuthenticatedLdpHandler', (): void => { await expect(handler.handle({ request: 'request' as any, response: {} as HttpResponse })).rejects.toThrow(Error); }); + + it('errors an invalid object was thrown by a handler.', async(): Promise< void> => { + args.authorizer.handle = async(): Promise => { + throw 'apple'; + }; + const handler = new AuthenticatedLdpHandler(args); + + await expect(handler.handle({ request: 'request' as any, response: {} as HttpResponse })).rejects.toEqual('apple'); + }); }); diff --git a/test/unit/ldp/http/AcceptPreferenceParser.test.ts b/test/unit/ldp/http/AcceptPreferenceParser.test.ts index b3362751d..62118fb20 100644 --- a/test/unit/ldp/http/AcceptPreferenceParser.test.ts +++ b/test/unit/ldp/http/AcceptPreferenceParser.test.ts @@ -1,5 +1,5 @@ import { AcceptPreferenceParser } from '../../../../src/ldp/http/AcceptPreferenceParser'; -import { HttpRequest } from '../../../../src/server/HttpRequest'; +import type { HttpRequest } from '../../../../src/server/HttpRequest'; describe('An AcceptPreferenceParser', (): void => { const preferenceParser = new AcceptPreferenceParser(); diff --git a/test/unit/ldp/http/BasicRequestParser.test.ts b/test/unit/ldp/http/BasicRequestParser.test.ts index 49678640a..5c298f1f6 100644 --- a/test/unit/ldp/http/BasicRequestParser.test.ts +++ b/test/unit/ldp/http/BasicRequestParser.test.ts @@ -1,7 +1,7 @@ import { BasicRequestParser } from '../../../../src/ldp/http/BasicRequestParser'; -import { BodyParser } from '../../../../src/ldp/http/BodyParser'; -import { PreferenceParser } from '../../../../src/ldp/http/PreferenceParser'; -import { TargetExtractor } from '../../../../src/ldp/http/TargetExtractor'; +import type { BodyParser } from '../../../../src/ldp/http/BodyParser'; +import type { PreferenceParser } from '../../../../src/ldp/http/PreferenceParser'; +import type { TargetExtractor } from '../../../../src/ldp/http/TargetExtractor'; import { StaticAsyncHandler } from '../../../util/StaticAsyncHandler'; describe('A BasicRequestParser', (): void => { diff --git a/test/unit/ldp/http/BasicResponseWriter.test.ts b/test/unit/ldp/http/BasicResponseWriter.test.ts index 693c7d7a8..16a58d4f0 100644 --- a/test/unit/ldp/http/BasicResponseWriter.test.ts +++ b/test/unit/ldp/http/BasicResponseWriter.test.ts @@ -1,8 +1,9 @@ import { EventEmitter } from 'events'; -import { createResponse, MockResponse } from 'node-mocks-http'; +import type { MockResponse } from 'node-mocks-http'; +import { createResponse } from 'node-mocks-http'; import streamifyArray from 'streamify-array'; import { BasicResponseWriter } from '../../../../src/ldp/http/BasicResponseWriter'; -import { ResponseDescription } from '../../../../src/ldp/operations/ResponseDescription'; +import type { ResponseDescription } from '../../../../src/ldp/operations/ResponseDescription'; import { RepresentationMetadata } from '../../../../src/ldp/representation/RepresentationMetadata'; import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError'; import { CONTENT_TYPE } from '../../../../src/util/UriConstants'; diff --git a/test/unit/ldp/http/RawBodyParser.test.ts b/test/unit/ldp/http/RawBodyParser.test.ts index 9ed9ef30a..539a0ea7b 100644 --- a/test/unit/ldp/http/RawBodyParser.test.ts +++ b/test/unit/ldp/http/RawBodyParser.test.ts @@ -2,7 +2,7 @@ import arrayifyStream from 'arrayify-stream'; import streamifyArray from 'streamify-array'; import { RawBodyParser } from '../../../../src/ldp/http/RawBodyParser'; import { RepresentationMetadata } from '../../../../src/ldp/representation/RepresentationMetadata'; -import { HttpRequest } from '../../../../src/server/HttpRequest'; +import type { HttpRequest } from '../../../../src/server/HttpRequest'; import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError'; import 'jest-rdf'; import { HTTP, RDF } from '../../../../src/util/UriConstants'; diff --git a/test/unit/ldp/http/SparqlUpdateBodyParser.test.ts b/test/unit/ldp/http/SparqlUpdateBodyParser.test.ts index d325011ae..bb1307e18 100644 --- a/test/unit/ldp/http/SparqlUpdateBodyParser.test.ts +++ b/test/unit/ldp/http/SparqlUpdateBodyParser.test.ts @@ -1,9 +1,10 @@ import { namedNode, quad } from '@rdfjs/data-model'; import arrayifyStream from 'arrayify-stream'; import { Algebra } from 'sparqlalgebrajs'; +import * as algebra from 'sparqlalgebrajs'; import streamifyArray from 'streamify-array'; import { SparqlUpdateBodyParser } from '../../../../src/ldp/http/SparqlUpdateBodyParser'; -import { HttpRequest } from '../../../../src/server/HttpRequest'; +import type { HttpRequest } from '../../../../src/server/HttpRequest'; import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError'; import { UnsupportedMediaTypeHttpError } from '../../../../src/util/errors/UnsupportedMediaTypeHttpError'; @@ -23,6 +24,16 @@ describe('A SparqlUpdateBodyParser', (): void => { .rejects.toThrow(UnsupportedHttpError); }); + it('errors when receiving an unexpected error.', async(): Promise => { + const mock = jest.spyOn(algebra, 'translate').mockImplementationOnce((): any => { + throw 'apple'; + }); + await expect(bodyParser.handle(streamifyArray( + [ 'DELETE DATA { }' ], + ) as HttpRequest)).rejects.toThrow(UnsupportedHttpError); + mock.mockRestore(); + }); + it('converts SPARQL updates to algebra.', async(): Promise => { const result = await bodyParser.handle(streamifyArray( [ 'DELETE DATA { }' ], diff --git a/test/unit/ldp/operations/DeleteOperationHandler.test.ts b/test/unit/ldp/operations/DeleteOperationHandler.test.ts index 3dc3a7359..7499c2712 100644 --- a/test/unit/ldp/operations/DeleteOperationHandler.test.ts +++ b/test/unit/ldp/operations/DeleteOperationHandler.test.ts @@ -1,6 +1,6 @@ import { DeleteOperationHandler } from '../../../../src/ldp/operations/DeleteOperationHandler'; -import { Operation } from '../../../../src/ldp/operations/Operation'; -import { ResourceStore } from '../../../../src/storage/ResourceStore'; +import type { Operation } from '../../../../src/ldp/operations/Operation'; +import type { ResourceStore } from '../../../../src/storage/ResourceStore'; import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError'; describe('A DeleteOperationHandler', (): void => { diff --git a/test/unit/ldp/operations/GetOperationHandler.test.ts b/test/unit/ldp/operations/GetOperationHandler.test.ts index 7c61af141..efc8d3cf1 100644 --- a/test/unit/ldp/operations/GetOperationHandler.test.ts +++ b/test/unit/ldp/operations/GetOperationHandler.test.ts @@ -1,7 +1,7 @@ import { GetOperationHandler } from '../../../../src/ldp/operations/GetOperationHandler'; -import { Operation } from '../../../../src/ldp/operations/Operation'; -import { Representation } from '../../../../src/ldp/representation/Representation'; -import { ResourceStore } from '../../../../src/storage/ResourceStore'; +import type { Operation } from '../../../../src/ldp/operations/Operation'; +import type { Representation } from '../../../../src/ldp/representation/Representation'; +import type { ResourceStore } from '../../../../src/storage/ResourceStore'; import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError'; describe('A GetOperationHandler', (): void => { diff --git a/test/unit/ldp/operations/PatchOperationHandler.test.ts b/test/unit/ldp/operations/PatchOperationHandler.test.ts index f28a87688..5099a24c1 100644 --- a/test/unit/ldp/operations/PatchOperationHandler.test.ts +++ b/test/unit/ldp/operations/PatchOperationHandler.test.ts @@ -1,6 +1,6 @@ -import { Operation } from '../../../../src/ldp/operations/Operation'; +import type { Operation } from '../../../../src/ldp/operations/Operation'; import { PatchOperationHandler } from '../../../../src/ldp/operations/PatchOperationHandler'; -import { ResourceStore } from '../../../../src/storage/ResourceStore'; +import type { ResourceStore } from '../../../../src/storage/ResourceStore'; import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError'; describe('A PatchOperationHandler', (): void => { diff --git a/test/unit/ldp/operations/PostOperationHandler.test.ts b/test/unit/ldp/operations/PostOperationHandler.test.ts index 58b0912b0..f1e70a2fc 100644 --- a/test/unit/ldp/operations/PostOperationHandler.test.ts +++ b/test/unit/ldp/operations/PostOperationHandler.test.ts @@ -1,7 +1,7 @@ -import { Operation } from '../../../../src/ldp/operations/Operation'; +import type { Operation } from '../../../../src/ldp/operations/Operation'; import { PostOperationHandler } from '../../../../src/ldp/operations/PostOperationHandler'; -import { ResourceIdentifier } from '../../../../src/ldp/representation/ResourceIdentifier'; -import { ResourceStore } from '../../../../src/storage/ResourceStore'; +import type { ResourceIdentifier } from '../../../../src/ldp/representation/ResourceIdentifier'; +import type { ResourceStore } from '../../../../src/storage/ResourceStore'; import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError'; describe('A PostOperationHandler', (): void => { diff --git a/test/unit/ldp/operations/PutOperationHandler.test.ts b/test/unit/ldp/operations/PutOperationHandler.test.ts index b594e93cf..a905d3af8 100644 --- a/test/unit/ldp/operations/PutOperationHandler.test.ts +++ b/test/unit/ldp/operations/PutOperationHandler.test.ts @@ -1,6 +1,6 @@ -import { Operation } from '../../../../src/ldp/operations/Operation'; +import type { Operation } from '../../../../src/ldp/operations/Operation'; import { PutOperationHandler } from '../../../../src/ldp/operations/PutOperationHandler'; -import { ResourceStore } from '../../../../src/storage/ResourceStore'; +import type { ResourceStore } from '../../../../src/storage/ResourceStore'; import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError'; describe('A PutOperationHandler', (): void => { diff --git a/test/unit/ldp/permissions/BasePermissionsExtractor.test.ts b/test/unit/ldp/permissions/BasePermissionsExtractor.test.ts index 3c49d8e7e..7f4839f14 100644 --- a/test/unit/ldp/permissions/BasePermissionsExtractor.test.ts +++ b/test/unit/ldp/permissions/BasePermissionsExtractor.test.ts @@ -1,4 +1,4 @@ -import { Operation } from '../../../../src/ldp/operations/Operation'; +import type { Operation } from '../../../../src/ldp/operations/Operation'; import { MethodPermissionsExtractor } from '../../../../src/ldp/permissions/MethodPermissionsExtractor'; import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError'; diff --git a/test/unit/ldp/permissions/SparqlPatchPermissionsExtractor.test.ts b/test/unit/ldp/permissions/SparqlPatchPermissionsExtractor.test.ts index 5bf2badc8..4b677d7f9 100644 --- a/test/unit/ldp/permissions/SparqlPatchPermissionsExtractor.test.ts +++ b/test/unit/ldp/permissions/SparqlPatchPermissionsExtractor.test.ts @@ -1,6 +1,6 @@ import { Factory } from 'sparqlalgebrajs'; -import { SparqlUpdatePatch } from '../../../../src/ldp/http/SparqlUpdatePatch'; -import { Operation } from '../../../../src/ldp/operations/Operation'; +import type { SparqlUpdatePatch } from '../../../../src/ldp/http/SparqlUpdatePatch'; +import type { Operation } from '../../../../src/ldp/operations/Operation'; import { SparqlPatchPermissionsExtractor } from '../../../../src/ldp/permissions/SparqlPatchPermissionsExtractor'; import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError'; diff --git a/test/unit/server/ExpressHttpServer.test.ts b/test/unit/server/ExpressHttpServer.test.ts index a33a50a95..a301d06ee 100644 --- a/test/unit/server/ExpressHttpServer.test.ts +++ b/test/unit/server/ExpressHttpServer.test.ts @@ -1,9 +1,10 @@ -import { Server } from 'http'; +import type { Server } from 'http'; import request from 'supertest'; import { ExpressHttpServer } from '../../../src/server/ExpressHttpServer'; import { HttpHandler } from '../../../src/server/HttpHandler'; -import { HttpRequest } from '../../../src/server/HttpRequest'; -import { HttpResponse } from '../../../src/server/HttpResponse'; +import type { HttpRequest } from '../../../src/server/HttpRequest'; +import type { HttpResponse } from '../../../src/server/HttpResponse'; +import SpyInstance = jest.SpyInstance; const handle = async(input: { request: HttpRequest; response: HttpResponse }): Promise => { input.response.writeHead(200); @@ -25,6 +26,13 @@ describe('ExpressHttpServer', (): void => { let canHandleJest: jest.Mock, []>; let handleJest: jest.Mock, [any]>; let handler: SimpleHttpHandler; + let mock: SpyInstance; + + beforeAll(async(): Promise => { + // Prevent test from writing to stderr + mock = jest.spyOn(process.stderr, 'write').mockImplementation((): boolean => true); + }); + beforeEach(async(): Promise => { handler = new SimpleHttpHandler(); canHandleJest = jest.fn(async(): Promise => undefined); @@ -42,6 +50,10 @@ describe('ExpressHttpServer', (): void => { server.close(); }); + afterAll(async(): Promise => { + mock.mockReset(); + }); + it('sends server identification in the X-Powered-By header.', async(): Promise => { const res = await request(server).get('/'); expect(res.header).toEqual(expect.objectContaining({ @@ -96,10 +108,16 @@ describe('ExpressHttpServer', (): void => { throw new Error('dummyError'); }; - // Prevent test from writing to stderr - jest.spyOn(process.stderr, 'write').mockImplementation((): boolean => true); - const res = await request(server).get('/').expect(500); expect(res.text).toContain('dummyError'); }); + + it('throws unknown errors if its handler throw non-Error objects.', async(): Promise => { + handler.handle = async(): Promise => { + throw 'apple'; + }; + + const res = await request(server).get('/').expect(500); + expect(res.text).toContain('Unknown error.'); + }); }); diff --git a/test/unit/storage/FileResourceStore.test.ts b/test/unit/storage/FileResourceStore.test.ts index 4e02add46..4181fe23f 100644 --- a/test/unit/storage/FileResourceStore.test.ts +++ b/test/unit/storage/FileResourceStore.test.ts @@ -1,11 +1,12 @@ -import fs, { promises as fsPromises, Stats, WriteStream } from 'fs'; +import type { Stats, WriteStream } from 'fs'; +import fs, { promises as fsPromises } from 'fs'; import { posix } from 'path'; import { Readable } from 'stream'; import { literal, namedNode, quad as quadRDF } from '@rdfjs/data-model'; import arrayifyStream from 'arrayify-stream'; import { DataFactory } from 'n3'; import streamifyArray from 'streamify-array'; -import { Representation } from '../../../src/ldp/representation/Representation'; +import type { Representation } from '../../../src/ldp/representation/Representation'; import { RepresentationMetadata } from '../../../src/ldp/representation/RepresentationMetadata'; import { ExtensionBasedMapper } from '../../../src/storage/ExtensionBasedMapper'; import { FileResourceStore } from '../../../src/storage/FileResourceStore'; @@ -60,8 +61,8 @@ describe('A FileResourceStore', (): void => { }; stats = { - isDirectory: jest.fn((): any => false) as Function, - isFile: jest.fn((): any => false) as Function, + isDirectory: jest.fn((): any => false) as any, + isFile: jest.fn((): any => false) as any, mtime: new Date(), size: 5, } as jest.Mocked; @@ -72,11 +73,11 @@ describe('A FileResourceStore', (): void => { func(); } return writeStream; - }) as Function, - once: jest.fn((): any => writeStream) as Function, - emit: jest.fn((): any => true) as Function, - write: jest.fn((): any => true) as Function, - end: jest.fn() as Function, + }) as any, + once: jest.fn((): any => writeStream) as any, + emit: jest.fn((): any => true) as any, + write: jest.fn((): any => true) as any, + end: jest.fn() as any, } as jest.Mocked; (fs.createWriteStream as jest.Mock).mockReturnValue(writeStream); @@ -86,8 +87,8 @@ describe('A FileResourceStore', (): void => { func(); } return readableMock; - }) as Function, - pipe: jest.fn((): any => readableMock) as Function, + }) as any, + pipe: jest.fn((): any => readableMock) as any, } as jest.Mocked; }); diff --git a/test/unit/storage/InMemoryResourceStore.test.ts b/test/unit/storage/InMemoryResourceStore.test.ts index 66583ed27..103764204 100644 --- a/test/unit/storage/InMemoryResourceStore.test.ts +++ b/test/unit/storage/InMemoryResourceStore.test.ts @@ -1,7 +1,7 @@ import { Readable } from 'stream'; import streamifyArray from 'streamify-array'; -import { Representation } from '../../../src/ldp/representation/Representation'; -import { RepresentationMetadata } from '../../../src/ldp/representation/RepresentationMetadata'; +import type { Representation } from '../../../src/ldp/representation/Representation'; +import type { RepresentationMetadata } from '../../../src/ldp/representation/RepresentationMetadata'; import { InMemoryResourceStore } from '../../../src/storage/InMemoryResourceStore'; import { NotFoundHttpError } from '../../../src/util/errors/NotFoundHttpError'; import { readableToString } from '../../../src/util/Util'; diff --git a/test/unit/storage/LockingResourceStore.test.ts b/test/unit/storage/LockingResourceStore.test.ts index bde1af7e8..f0519754a 100644 --- a/test/unit/storage/LockingResourceStore.test.ts +++ b/test/unit/storage/LockingResourceStore.test.ts @@ -1,11 +1,11 @@ -import { EventEmitter } from 'events'; +import type { EventEmitter } from 'events'; import streamifyArray from 'streamify-array'; -import { Patch } from '../../../src/ldp/http/Patch'; -import { Representation } from '../../../src/ldp/representation/Representation'; -import { Lock } from '../../../src/storage/Lock'; +import type { Patch } from '../../../src/ldp/http/Patch'; +import type { Representation } from '../../../src/ldp/representation/Representation'; +import type { Lock } from '../../../src/storage/Lock'; import { LockingResourceStore } from '../../../src/storage/LockingResourceStore'; -import { ResourceLocker } from '../../../src/storage/ResourceLocker'; -import { ResourceStore } from '../../../src/storage/ResourceStore'; +import type { ResourceLocker } from '../../../src/storage/ResourceLocker'; +import type { ResourceStore } from '../../../src/storage/ResourceStore'; describe('A LockingResourceStore', (): void => { let store: LockingResourceStore; diff --git a/test/unit/storage/PassthroughStore.test.ts b/test/unit/storage/PassthroughStore.test.ts index 6e3aee666..c83afbfa2 100644 --- a/test/unit/storage/PassthroughStore.test.ts +++ b/test/unit/storage/PassthroughStore.test.ts @@ -1,7 +1,7 @@ -import { Patch } from '../../../src/ldp/http/Patch'; -import { Representation } from '../../../src/ldp/representation/Representation'; +import type { Patch } from '../../../src/ldp/http/Patch'; +import type { Representation } from '../../../src/ldp/representation/Representation'; import { PassthroughStore } from '../../../src/storage/PassthroughStore'; -import { ResourceStore } from '../../../src/storage/ResourceStore'; +import type { ResourceStore } from '../../../src/storage/ResourceStore'; describe('A PassthroughStore', (): void => { let store: PassthroughStore; diff --git a/test/unit/storage/PatchingStore.test.ts b/test/unit/storage/PatchingStore.test.ts index 1e81a5a77..613a3bfee 100644 --- a/test/unit/storage/PatchingStore.test.ts +++ b/test/unit/storage/PatchingStore.test.ts @@ -1,7 +1,7 @@ -import { Patch } from '../../../src/ldp/http/Patch'; -import { PatchHandler } from '../../../src/storage/patch/PatchHandler'; +import type { Patch } from '../../../src/ldp/http/Patch'; +import type { PatchHandler } from '../../../src/storage/patch/PatchHandler'; import { PatchingStore } from '../../../src/storage/PatchingStore'; -import { ResourceStore } from '../../../src/storage/ResourceStore'; +import type { ResourceStore } from '../../../src/storage/ResourceStore'; describe('A PatchingStore', (): void => { let store: PatchingStore; diff --git a/test/unit/storage/RepresentationConvertingStore.test.ts b/test/unit/storage/RepresentationConvertingStore.test.ts index 0e395222f..b44fde42e 100644 --- a/test/unit/storage/RepresentationConvertingStore.test.ts +++ b/test/unit/storage/RepresentationConvertingStore.test.ts @@ -1,7 +1,7 @@ import { RepresentationMetadata } from '../../../src/ldp/representation/RepresentationMetadata'; -import { RepresentationConverter } from '../../../src/storage/conversion/RepresentationConverter'; +import type { RepresentationConverter } from '../../../src/storage/conversion/RepresentationConverter'; import { RepresentationConvertingStore } from '../../../src/storage/RepresentationConvertingStore'; -import { ResourceStore } from '../../../src/storage/ResourceStore'; +import type { ResourceStore } from '../../../src/storage/ResourceStore'; import { CONTENT_TYPE } from '../../../src/util/UriConstants'; describe('A RepresentationConvertingStore', (): void => { diff --git a/test/unit/storage/conversion/ChainedConverter.test.ts b/test/unit/storage/conversion/ChainedConverter.test.ts index ffd100ba2..75b08ab35 100644 --- a/test/unit/storage/conversion/ChainedConverter.test.ts +++ b/test/unit/storage/conversion/ChainedConverter.test.ts @@ -1,9 +1,9 @@ -import { Representation } from '../../../../src/ldp/representation/Representation'; +import type { Representation } from '../../../../src/ldp/representation/Representation'; import { RepresentationMetadata } from '../../../../src/ldp/representation/RepresentationMetadata'; -import { RepresentationPreferences } from '../../../../src/ldp/representation/RepresentationPreferences'; +import type { RepresentationPreferences } from '../../../../src/ldp/representation/RepresentationPreferences'; import { ChainedConverter } from '../../../../src/storage/conversion/ChainedConverter'; import { checkRequest } from '../../../../src/storage/conversion/ConversionUtil'; -import { RepresentationConverterArgs } from '../../../../src/storage/conversion/RepresentationConverter'; +import type { RepresentationConverterArgs } from '../../../../src/storage/conversion/RepresentationConverter'; import { TypedRepresentationConverter } from '../../../../src/storage/conversion/TypedRepresentationConverter'; import { CONTENT_TYPE } from '../../../../src/util/UriConstants'; diff --git a/test/unit/storage/conversion/ConversionUtil.test.ts b/test/unit/storage/conversion/ConversionUtil.test.ts index c46ba2af3..f9ca0aaef 100644 --- a/test/unit/storage/conversion/ConversionUtil.test.ts +++ b/test/unit/storage/conversion/ConversionUtil.test.ts @@ -1,7 +1,7 @@ -import { Representation } from '../../../../src/ldp/representation/Representation'; +import type { Representation } from '../../../../src/ldp/representation/Representation'; import { RepresentationMetadata } from '../../../../src/ldp/representation/RepresentationMetadata'; -import { RepresentationPreferences } from '../../../../src/ldp/representation/RepresentationPreferences'; -import { ResourceIdentifier } from '../../../../src/ldp/representation/ResourceIdentifier'; +import type { RepresentationPreferences } from '../../../../src/ldp/representation/RepresentationPreferences'; +import type { ResourceIdentifier } from '../../../../src/ldp/representation/ResourceIdentifier'; import { checkRequest, matchingTypes } from '../../../../src/storage/conversion/ConversionUtil'; describe('A ConversionUtil', (): void => { diff --git a/test/unit/storage/conversion/QuadToRdfConverter.test.ts b/test/unit/storage/conversion/QuadToRdfConverter.test.ts index 518746c62..78b3b4b59 100644 --- a/test/unit/storage/conversion/QuadToRdfConverter.test.ts +++ b/test/unit/storage/conversion/QuadToRdfConverter.test.ts @@ -2,10 +2,10 @@ import { namedNode, triple } from '@rdfjs/data-model'; import rdfSerializer from 'rdf-serialize'; import stringifyStream from 'stream-to-string'; import streamifyArray from 'streamify-array'; -import { Representation } from '../../../../src/ldp/representation/Representation'; +import type { Representation } from '../../../../src/ldp/representation/Representation'; import { RepresentationMetadata } from '../../../../src/ldp/representation/RepresentationMetadata'; -import { RepresentationPreferences } from '../../../../src/ldp/representation/RepresentationPreferences'; -import { ResourceIdentifier } from '../../../../src/ldp/representation/ResourceIdentifier'; +import type { RepresentationPreferences } from '../../../../src/ldp/representation/RepresentationPreferences'; +import type { ResourceIdentifier } from '../../../../src/ldp/representation/ResourceIdentifier'; import { QuadToRdfConverter } from '../../../../src/storage/conversion/QuadToRdfConverter'; import { INTERNAL_QUADS } from '../../../../src/util/ContentTypes'; import { CONTENT_TYPE } from '../../../../src/util/UriConstants'; diff --git a/test/unit/storage/conversion/QuadToTurtleConverter.test.ts b/test/unit/storage/conversion/QuadToTurtleConverter.test.ts index 1e2281d31..f84868de7 100644 --- a/test/unit/storage/conversion/QuadToTurtleConverter.test.ts +++ b/test/unit/storage/conversion/QuadToTurtleConverter.test.ts @@ -1,10 +1,10 @@ import { namedNode, triple } from '@rdfjs/data-model'; import arrayifyStream from 'arrayify-stream'; import streamifyArray from 'streamify-array'; -import { Representation } from '../../../../src/ldp/representation/Representation'; +import type { Representation } from '../../../../src/ldp/representation/Representation'; import { RepresentationMetadata } from '../../../../src/ldp/representation/RepresentationMetadata'; -import { RepresentationPreferences } from '../../../../src/ldp/representation/RepresentationPreferences'; -import { ResourceIdentifier } from '../../../../src/ldp/representation/ResourceIdentifier'; +import type { RepresentationPreferences } from '../../../../src/ldp/representation/RepresentationPreferences'; +import type { ResourceIdentifier } from '../../../../src/ldp/representation/ResourceIdentifier'; import { QuadToTurtleConverter } from '../../../../src/storage/conversion/QuadToTurtleConverter'; import { INTERNAL_QUADS } from '../../../../src/util/ContentTypes'; import { CONTENT_TYPE } from '../../../../src/util/UriConstants'; diff --git a/test/unit/storage/conversion/RdfToQuadConverter.test.ts b/test/unit/storage/conversion/RdfToQuadConverter.test.ts index 66b64762f..6cd26befa 100644 --- a/test/unit/storage/conversion/RdfToQuadConverter.test.ts +++ b/test/unit/storage/conversion/RdfToQuadConverter.test.ts @@ -3,10 +3,10 @@ import { namedNode, triple } from '@rdfjs/data-model'; import arrayifyStream from 'arrayify-stream'; import rdfParser from 'rdf-parse'; import streamifyArray from 'streamify-array'; -import { Representation } from '../../../../src/ldp/representation/Representation'; +import type { Representation } from '../../../../src/ldp/representation/Representation'; import { RepresentationMetadata } from '../../../../src/ldp/representation/RepresentationMetadata'; -import { RepresentationPreferences } from '../../../../src/ldp/representation/RepresentationPreferences'; -import { ResourceIdentifier } from '../../../../src/ldp/representation/ResourceIdentifier'; +import type { RepresentationPreferences } from '../../../../src/ldp/representation/RepresentationPreferences'; +import type { ResourceIdentifier } from '../../../../src/ldp/representation/ResourceIdentifier'; import { RdfToQuadConverter } from '../../../../src/storage/conversion/RdfToQuadConverter'; import { INTERNAL_QUADS } from '../../../../src/util/ContentTypes'; import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError'; diff --git a/test/unit/storage/conversion/TurtleToQuadConverter.test.ts b/test/unit/storage/conversion/TurtleToQuadConverter.test.ts index 86c532ea1..3192aa9b7 100644 --- a/test/unit/storage/conversion/TurtleToQuadConverter.test.ts +++ b/test/unit/storage/conversion/TurtleToQuadConverter.test.ts @@ -2,10 +2,10 @@ import { Readable } from 'stream'; import { namedNode, triple } from '@rdfjs/data-model'; import arrayifyStream from 'arrayify-stream'; import streamifyArray from 'streamify-array'; -import { Representation } from '../../../../src/ldp/representation/Representation'; +import type { Representation } from '../../../../src/ldp/representation/Representation'; import { RepresentationMetadata } from '../../../../src/ldp/representation/RepresentationMetadata'; -import { RepresentationPreferences } from '../../../../src/ldp/representation/RepresentationPreferences'; -import { ResourceIdentifier } from '../../../../src/ldp/representation/ResourceIdentifier'; +import type { RepresentationPreferences } from '../../../../src/ldp/representation/RepresentationPreferences'; +import type { ResourceIdentifier } from '../../../../src/ldp/representation/ResourceIdentifier'; import { TurtleToQuadConverter } from '../../../../src/storage/conversion/TurtleToQuadConverter'; import { INTERNAL_QUADS } from '../../../../src/util/ContentTypes'; import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError'; diff --git a/test/unit/storage/patch/SparqlUpdatePatchHandler.test.ts b/test/unit/storage/patch/SparqlUpdatePatchHandler.test.ts index 8d3d96e24..df4ab51f1 100644 --- a/test/unit/storage/patch/SparqlUpdatePatchHandler.test.ts +++ b/test/unit/storage/patch/SparqlUpdatePatchHandler.test.ts @@ -3,12 +3,12 @@ import arrayifyStream from 'arrayify-stream'; import type { Quad } from 'rdf-js'; import { translate } from 'sparqlalgebrajs'; import streamifyArray from 'streamify-array'; -import { SparqlUpdatePatch } from '../../../../src/ldp/http/SparqlUpdatePatch'; +import type { SparqlUpdatePatch } from '../../../../src/ldp/http/SparqlUpdatePatch'; import { RepresentationMetadata } from '../../../../src/ldp/representation/RepresentationMetadata'; -import { Lock } from '../../../../src/storage/Lock'; +import type { Lock } from '../../../../src/storage/Lock'; import { SparqlUpdatePatchHandler } from '../../../../src/storage/patch/SparqlUpdatePatchHandler'; -import { ResourceLocker } from '../../../../src/storage/ResourceLocker'; -import { ResourceStore } from '../../../../src/storage/ResourceStore'; +import type { ResourceLocker } from '../../../../src/storage/ResourceLocker'; +import type { ResourceStore } from '../../../../src/storage/ResourceStore'; import { INTERNAL_QUADS } from '../../../../src/util/ContentTypes'; import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError'; @@ -84,7 +84,7 @@ describe('A SparqlUpdatePatchHandler', (): void => { const input = { identifier: { path: 'path' }, patch: { algebra: {}} as SparqlUpdatePatch }; await expect(handler.canHandle(input)).resolves.toBeUndefined(); - delete input.patch.algebra; + delete (input.patch as any).algebra; await expect(handler.canHandle(input)).rejects.toThrow(UnsupportedHttpError); }); diff --git a/test/unit/util/AsyncHandler.test.ts b/test/unit/util/AsyncHandler.test.ts index 669b52205..75de47759 100644 --- a/test/unit/util/AsyncHandler.test.ts +++ b/test/unit/util/AsyncHandler.test.ts @@ -1,4 +1,4 @@ -import { AsyncHandler } from '../../../src/util/AsyncHandler'; +import type { AsyncHandler } from '../../../src/util/AsyncHandler'; import { StaticAsyncHandler } from '../../util/StaticAsyncHandler'; describe('An AsyncHandler', (): void => { diff --git a/test/unit/util/CompositeAsyncHandler.test.ts b/test/unit/util/CompositeAsyncHandler.test.ts index 547fe65e4..6dcaf73cf 100644 --- a/test/unit/util/CompositeAsyncHandler.test.ts +++ b/test/unit/util/CompositeAsyncHandler.test.ts @@ -1,4 +1,4 @@ -import { AsyncHandler } from '../../../src/util/AsyncHandler'; +import type { AsyncHandler } from '../../../src/util/AsyncHandler'; import { CompositeAsyncHandler } from '../../../src/util/CompositeAsyncHandler'; import { StaticAsyncHandler } from '../../util/StaticAsyncHandler'; @@ -45,6 +45,15 @@ describe('A CompositeAsyncHandler', (): void => { await expect(handler.canHandle(null)).rejects.toThrow('[Not supported., Not supported.]'); }); + it('throws unknown errors if no Error objects are thrown.', async(): Promise => { + handlerFalse.canHandle = async(): Promise => { + throw 'apple'; + }; + const handler = new CompositeAsyncHandler([ handlerFalse, handlerFalse ]); + + await expect(handler.canHandle(null)).rejects.toThrow('[Unknown error., Unknown error.]'); + }); + it('handles data if a handler supports it.', async(): Promise => { const handler = new CompositeAsyncHandler([ handlerFalse, handlerTrue ]); diff --git a/test/util/TestHelpers.ts b/test/util/TestHelpers.ts index c6b88217f..1cf93d978 100644 --- a/test/util/TestHelpers.ts +++ b/test/util/TestHelpers.ts @@ -1,14 +1,16 @@ import { EventEmitter } from 'events'; import { promises as fs } from 'fs'; -import { IncomingHttpHeaders } from 'http'; +import type { IncomingHttpHeaders } from 'http'; import { join } from 'path'; import * as url from 'url'; -import { createResponse, MockResponse } from 'node-mocks-http'; +import type { MockResponse } from 'node-mocks-http'; +import { createResponse } from 'node-mocks-http'; import streamifyArray from 'streamify-array'; -import { RepresentationMetadata, ResourceStore } from '../../index'; -import { PermissionSet } from '../../src/ldp/permissions/PermissionSet'; -import { HttpHandler } from '../../src/server/HttpHandler'; -import { HttpRequest } from '../../src/server/HttpRequest'; +import type { ResourceStore } from '../../index'; +import { RepresentationMetadata } from '../../index'; +import type { PermissionSet } from '../../src/ldp/permissions/PermissionSet'; +import type { HttpHandler } from '../../src/server/HttpHandler'; +import type { HttpRequest } from '../../src/server/HttpRequest'; import { CONTENT_TYPE } from '../../src/util/UriConstants'; import { call } from './Util'; diff --git a/test/util/Util.ts b/test/util/Util.ts index d6ed16355..c80d2f37a 100644 --- a/test/util/Util.ts +++ b/test/util/Util.ts @@ -1,9 +1,10 @@ import { EventEmitter } from 'events'; -import { IncomingHttpHeaders } from 'http'; -import { createResponse, MockResponse } from 'node-mocks-http'; +import type { IncomingHttpHeaders } from 'http'; +import type { MockResponse } from 'node-mocks-http'; +import { createResponse } from 'node-mocks-http'; import streamifyArray from 'streamify-array'; -import { HttpHandler } from '../../src/server/HttpHandler'; -import { HttpRequest } from '../../src/server/HttpRequest'; +import type { HttpHandler } from '../../src/server/HttpHandler'; +import type { HttpRequest } from '../../src/server/HttpRequest'; export const call = async( handler: HttpHandler,