From b0a67e55b5f2dc2128c6b1d63cc525b0bb98a690 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Thu, 24 Feb 2022 11:11:46 +0100 Subject: [PATCH] Factor out a type definition MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- package-lock.json | 134 +++++++++--------- package.json | 6 +- .../ocpp/OCPPRequestService.ts | 10 +- src/types/ocpp/Requests.ts | 2 + 4 files changed, 77 insertions(+), 75 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0d3f08ae..986d797e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -36,7 +36,7 @@ "@types/proper-lockfile": "^4.1.2", "@types/tar": "^6.1.1", "@types/uuid": "^8.3.4", - "@types/ws": "^8.2.3", + "@types/ws": "^8.5.0", "@typescript-eslint/eslint-plugin": "^5.12.1", "@typescript-eslint/parser": "^5.12.1", "auto-changelog": "^2.4.0", @@ -51,9 +51,9 @@ "mochawesome": "^7.0.1", "npm-check": "^5.9.2", "nyc": "^15.1.0", - "release-it": "^14.12.4", + "release-it": "^14.12.5", "robohydra": "^0.6.9", - "rollup": "^2.67.3", + "rollup": "^2.68.0", "rollup-plugin-analyzer": "^4.0.0", "rollup-plugin-copy": "^3.4.0", "rollup-plugin-delete": "^2.0.0", @@ -269,9 +269,9 @@ } }, "node_modules/@babel/helper-module-transforms": { - "version": "7.16.7", - "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.16.7.tgz", - "integrity": "sha512-gaqtLDxJEFCeQbYp9aLAefjhkKdjKcdh6DB7jniIGU3Pz52WAmP268zK0VgPz9hUNkMSYeH976K2/Y6yPadpng==", + "version": "7.17.6", + "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.17.6.tgz", + "integrity": "sha512-2ULmRdqoOMpdvkbT8jONrZML/XALfzxlb052bldftkicAUy8AxSCkD5trDPQcwHNmolcl7wP6ehNqMlyUw6AaA==", "dev": true, "dependencies": { "@babel/helper-environment-visitor": "^7.16.7", @@ -280,8 +280,8 @@ "@babel/helper-split-export-declaration": "^7.16.7", "@babel/helper-validator-identifier": "^7.16.7", "@babel/template": "^7.16.7", - "@babel/traverse": "^7.16.7", - "@babel/types": "^7.16.7" + "@babel/traverse": "^7.17.3", + "@babel/types": "^7.17.0" }, "engines": { "node": ">=6.9.0" @@ -767,9 +767,9 @@ "dev": true }, "node_modules/@humanwhocodes/config-array": { - "version": "0.9.3", - "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.9.3.tgz", - "integrity": "sha512-3xSMlXHh03hCcCmFc0rbKp3Ivt2PFEJnQUJDDMTJQ2wkECZWdq4GePs2ctc5H8zV+cHPaq8k2vU8mrQjA6iHdQ==", + "version": "0.9.5", + "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.9.5.tgz", + "integrity": "sha512-ObyMyWxZiCu/yTisA7uzx81s40xR2fD5Cg/2Kq7G02ajkNubJf6BopgDTmDyc3U7sXpNKM8cYOw7s7Tyr+DnCw==", "dev": true, "dependencies": { "@humanwhocodes/object-schema": "^1.2.1", @@ -984,9 +984,9 @@ } }, "node_modules/@mdn/browser-compat-data": { - "version": "4.1.8", - "resolved": "https://registry.npmjs.org/@mdn/browser-compat-data/-/browser-compat-data-4.1.8.tgz", - "integrity": "sha512-iY8qGU+yJvscccvWLyWPKfF9BSLmSFth5HBNjSNtIfoyUrQV3lTZml+zyKWRymMYCgvos6LiSqMj1RDEj3TehA==", + "version": "4.1.9", + "resolved": "https://registry.npmjs.org/@mdn/browser-compat-data/-/browser-compat-data-4.1.9.tgz", + "integrity": "sha512-MGIACLLfhkuJ4rV5JPIOFNLJN+JWgYmV83NMBfx8EvRma+kcEAFivVgHHuEPJtdCba5zRpMx/cIGrXfVyGN56g==", "dev": true }, "node_modules/@mikro-orm/cli": { @@ -1845,9 +1845,9 @@ } }, "node_modules/@types/ws": { - "version": "8.2.3", - "resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.2.3.tgz", - "integrity": "sha512-ahRJZquUYCdOZf/rCsWg88S0/+cb9wazUBHv6HZEe3XdYaBe2zr/slM8J28X07Hn88Pnm4ezo7N8/ofnOgrPVQ==", + "version": "8.5.0", + "resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.0.tgz", + "integrity": "sha512-mTClfhq5cuGyW4jthaFuig6Q8OVfB3IRyZfN/9SCyJtiM5H0SubwM89cHoT9UngO6HyUFic88HvT1zSNLNyxWA==", "dev": true, "dependencies": { "@types/node": "*" @@ -2638,9 +2638,9 @@ } }, "node_modules/autocannon": { - "version": "7.6.0", - "resolved": "https://registry.npmjs.org/autocannon/-/autocannon-7.6.0.tgz", - "integrity": "sha512-p/E4/a1vLxMWOCeiIj6/WEQ2C6nseaCDcVIa3lXdjJ5xtfF/TNWl+UVvpXcwzXGXt/lOq8v1NGnkslqCwgf4Hw==", + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/autocannon/-/autocannon-7.7.0.tgz", + "integrity": "sha512-mcIoiROal9V9QN7Av932+dcDtV/uvdePpd/oa04g178D/u+E6np+s5nvubglbSjq9fZtMyg/DJPMqcMXSdZTnw==", "dev": true, "dependencies": { "chalk": "^4.1.0", @@ -5459,9 +5459,9 @@ } }, "node_modules/electron-to-chromium": { - "version": "1.4.71", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.71.tgz", - "integrity": "sha512-Hk61vXXKRb2cd3znPE9F+2pLWdIOmP7GjiTj45y6L3W/lO+hSnUSUhq+6lEaERWBdZOHbk2s3YV5c9xVl3boVw==", + "version": "1.4.72", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.72.tgz", + "integrity": "sha512-9LkRQwjW6/wnSfevR21a3k8sOJ+XWSH7kkzs9/EUenKmuDkndP3W9y1yCZpOxufwGbX3JV8glZZSDb4o95zwXQ==", "dev": true }, "node_modules/elliptic": { @@ -11080,9 +11080,9 @@ } }, "node_modules/mochawesome-report-generator/node_modules/fs-extra": { - "version": "10.0.0", - "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.0.0.tgz", - "integrity": "sha512-C5owb14u9eJwizKGdchcDUQeFtlSHHthBk8pbX9Vc1PFZrLombudjDnNns88aYslCyF6IY5SUw3Roz6xShcEIQ==", + "version": "10.0.1", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.0.1.tgz", + "integrity": "sha512-NbdoVMZso2Lsrn/QwLXOy6rm0ufY2zEOKCDzJR/0kBsb0E6qed0P3iYK+Ath3BfvXEeu4JhEtXLgILx5psUfag==", "dev": true, "dependencies": { "graceful-fs": "^4.2.0", @@ -11210,9 +11210,9 @@ } }, "node_modules/mongodb-connection-string-url": { - "version": "2.4.2", - "resolved": "https://registry.npmjs.org/mongodb-connection-string-url/-/mongodb-connection-string-url-2.4.2.tgz", - "integrity": "sha512-mZUXF6nUzRWk5J3h41MsPv13ukWlH4jOMSk6astVeoZ1EbdTJyF5I3wxKkvqBAOoVtzLgyEYUvDjrGdcPlKjAw==", + "version": "2.5.1", + "resolved": "https://registry.npmjs.org/mongodb-connection-string-url/-/mongodb-connection-string-url-2.5.1.tgz", + "integrity": "sha512-0GAJKc1LBXzlWPhtj9uGawIlYSkTXkgpW9wZ97b4ySEuKbE5j9a0OdLGM31AWMhRS2ut49Z0kufSYsamGEIb8Q==", "dependencies": { "@types/whatwg-url": "^8.2.1", "whatwg-url": "^11.0.0" @@ -14461,9 +14461,9 @@ "dev": true }, "node_modules/release-it": { - "version": "14.12.4", - "resolved": "https://registry.npmjs.org/release-it/-/release-it-14.12.4.tgz", - "integrity": "sha512-lqf9PMsj7ycCqFHGag8Uv7cE1hNsKa+yKUMe+Fkh9fdOfxu2F01On+YUefRCP0DuQthmr/WyLCYdrjThMEkWFQ==", + "version": "14.12.5", + "resolved": "https://registry.npmjs.org/release-it/-/release-it-14.12.5.tgz", + "integrity": "sha512-mGFbbX8eEKMOhfjq5mZAgGppT8CME1T+vj6xA5tAPYSCuPpcNEDjqiG1tJfPy/XImZI4uS3U6pNP5KyDpy9etg==", "dev": true, "dependencies": { "@iarna/toml": "2.2.5", @@ -15319,9 +15319,9 @@ } }, "node_modules/rollup": { - "version": "2.67.3", - "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.67.3.tgz", - "integrity": "sha512-G/x1vUwbGtP6O5ZM8/sWr8+p7YfZhI18pPqMRtMYMWSbHjKZ/ajHGiM+GWNTlWyOR0EHIdT8LHU+Z4ciIZ1oBw==", + "version": "2.68.0", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.68.0.tgz", + "integrity": "sha512-XrMKOYK7oQcTio4wyTz466mucnd8LzkiZLozZ4Rz0zQD+HeX4nUK4B8GrTX/2EvN2/vBF/i2WnaXboPxo0JylA==", "dev": true, "bin": { "rollup": "dist/bin/rollup" @@ -19237,9 +19237,9 @@ } }, "@babel/helper-module-transforms": { - "version": "7.16.7", - "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.16.7.tgz", - "integrity": "sha512-gaqtLDxJEFCeQbYp9aLAefjhkKdjKcdh6DB7jniIGU3Pz52WAmP268zK0VgPz9hUNkMSYeH976K2/Y6yPadpng==", + "version": "7.17.6", + "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.17.6.tgz", + "integrity": "sha512-2ULmRdqoOMpdvkbT8jONrZML/XALfzxlb052bldftkicAUy8AxSCkD5trDPQcwHNmolcl7wP6ehNqMlyUw6AaA==", "dev": true, "requires": { "@babel/helper-environment-visitor": "^7.16.7", @@ -19248,8 +19248,8 @@ "@babel/helper-split-export-declaration": "^7.16.7", "@babel/helper-validator-identifier": "^7.16.7", "@babel/template": "^7.16.7", - "@babel/traverse": "^7.16.7", - "@babel/types": "^7.16.7" + "@babel/traverse": "^7.17.3", + "@babel/types": "^7.17.0" } }, "@babel/helper-simple-access": { @@ -19647,9 +19647,9 @@ } }, "@humanwhocodes/config-array": { - "version": "0.9.3", - "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.9.3.tgz", - "integrity": "sha512-3xSMlXHh03hCcCmFc0rbKp3Ivt2PFEJnQUJDDMTJQ2wkECZWdq4GePs2ctc5H8zV+cHPaq8k2vU8mrQjA6iHdQ==", + "version": "0.9.5", + "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.9.5.tgz", + "integrity": "sha512-ObyMyWxZiCu/yTisA7uzx81s40xR2fD5Cg/2Kq7G02ajkNubJf6BopgDTmDyc3U7sXpNKM8cYOw7s7Tyr+DnCw==", "dev": true, "requires": { "@humanwhocodes/object-schema": "^1.2.1", @@ -19815,9 +19815,9 @@ } }, "@mdn/browser-compat-data": { - "version": "4.1.8", - "resolved": "https://registry.npmjs.org/@mdn/browser-compat-data/-/browser-compat-data-4.1.8.tgz", - "integrity": "sha512-iY8qGU+yJvscccvWLyWPKfF9BSLmSFth5HBNjSNtIfoyUrQV3lTZml+zyKWRymMYCgvos6LiSqMj1RDEj3TehA==", + "version": "4.1.9", + "resolved": "https://registry.npmjs.org/@mdn/browser-compat-data/-/browser-compat-data-4.1.9.tgz", + "integrity": "sha512-MGIACLLfhkuJ4rV5JPIOFNLJN+JWgYmV83NMBfx8EvRma+kcEAFivVgHHuEPJtdCba5zRpMx/cIGrXfVyGN56g==", "dev": true }, "@mikro-orm/cli": { @@ -20486,9 +20486,9 @@ } }, "@types/ws": { - "version": "8.2.3", - "resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.2.3.tgz", - "integrity": "sha512-ahRJZquUYCdOZf/rCsWg88S0/+cb9wazUBHv6HZEe3XdYaBe2zr/slM8J28X07Hn88Pnm4ezo7N8/ofnOgrPVQ==", + "version": "8.5.0", + "resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.0.tgz", + "integrity": "sha512-mTClfhq5cuGyW4jthaFuig6Q8OVfB3IRyZfN/9SCyJtiM5H0SubwM89cHoT9UngO6HyUFic88HvT1zSNLNyxWA==", "dev": true, "requires": { "@types/node": "*" @@ -21067,9 +21067,9 @@ } }, "autocannon": { - "version": "7.6.0", - "resolved": "https://registry.npmjs.org/autocannon/-/autocannon-7.6.0.tgz", - "integrity": "sha512-p/E4/a1vLxMWOCeiIj6/WEQ2C6nseaCDcVIa3lXdjJ5xtfF/TNWl+UVvpXcwzXGXt/lOq8v1NGnkslqCwgf4Hw==", + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/autocannon/-/autocannon-7.7.0.tgz", + "integrity": "sha512-mcIoiROal9V9QN7Av932+dcDtV/uvdePpd/oa04g178D/u+E6np+s5nvubglbSjq9fZtMyg/DJPMqcMXSdZTnw==", "dev": true, "requires": { "chalk": "^4.1.0", @@ -23384,9 +23384,9 @@ } }, "electron-to-chromium": { - "version": "1.4.71", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.71.tgz", - "integrity": "sha512-Hk61vXXKRb2cd3znPE9F+2pLWdIOmP7GjiTj45y6L3W/lO+hSnUSUhq+6lEaERWBdZOHbk2s3YV5c9xVl3boVw==", + "version": "1.4.72", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.72.tgz", + "integrity": "sha512-9LkRQwjW6/wnSfevR21a3k8sOJ+XWSH7kkzs9/EUenKmuDkndP3W9y1yCZpOxufwGbX3JV8glZZSDb4o95zwXQ==", "dev": true }, "elliptic": { @@ -27827,9 +27827,9 @@ } }, "fs-extra": { - "version": "10.0.0", - "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.0.0.tgz", - "integrity": "sha512-C5owb14u9eJwizKGdchcDUQeFtlSHHthBk8pbX9Vc1PFZrLombudjDnNns88aYslCyF6IY5SUw3Roz6xShcEIQ==", + "version": "10.0.1", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.0.1.tgz", + "integrity": "sha512-NbdoVMZso2Lsrn/QwLXOy6rm0ufY2zEOKCDzJR/0kBsb0E6qed0P3iYK+Ath3BfvXEeu4JhEtXLgILx5psUfag==", "dev": true, "requires": { "graceful-fs": "^4.2.0", @@ -27936,9 +27936,9 @@ } }, "mongodb-connection-string-url": { - "version": "2.4.2", - "resolved": "https://registry.npmjs.org/mongodb-connection-string-url/-/mongodb-connection-string-url-2.4.2.tgz", - "integrity": "sha512-mZUXF6nUzRWk5J3h41MsPv13ukWlH4jOMSk6astVeoZ1EbdTJyF5I3wxKkvqBAOoVtzLgyEYUvDjrGdcPlKjAw==", + "version": "2.5.1", + "resolved": "https://registry.npmjs.org/mongodb-connection-string-url/-/mongodb-connection-string-url-2.5.1.tgz", + "integrity": "sha512-0GAJKc1LBXzlWPhtj9uGawIlYSkTXkgpW9wZ97b4ySEuKbE5j9a0OdLGM31AWMhRS2ut49Z0kufSYsamGEIb8Q==", "requires": { "@types/whatwg-url": "^8.2.1", "whatwg-url": "^11.0.0" @@ -30536,9 +30536,9 @@ "dev": true }, "release-it": { - "version": "14.12.4", - "resolved": "https://registry.npmjs.org/release-it/-/release-it-14.12.4.tgz", - "integrity": "sha512-lqf9PMsj7ycCqFHGag8Uv7cE1hNsKa+yKUMe+Fkh9fdOfxu2F01On+YUefRCP0DuQthmr/WyLCYdrjThMEkWFQ==", + "version": "14.12.5", + "resolved": "https://registry.npmjs.org/release-it/-/release-it-14.12.5.tgz", + "integrity": "sha512-mGFbbX8eEKMOhfjq5mZAgGppT8CME1T+vj6xA5tAPYSCuPpcNEDjqiG1tJfPy/XImZI4uS3U6pNP5KyDpy9etg==", "dev": true, "requires": { "@iarna/toml": "2.2.5", @@ -31178,9 +31178,9 @@ } }, "rollup": { - "version": "2.67.3", - "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.67.3.tgz", - "integrity": "sha512-G/x1vUwbGtP6O5ZM8/sWr8+p7YfZhI18pPqMRtMYMWSbHjKZ/ajHGiM+GWNTlWyOR0EHIdT8LHU+Z4ciIZ1oBw==", + "version": "2.68.0", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.68.0.tgz", + "integrity": "sha512-XrMKOYK7oQcTio4wyTz466mucnd8LzkiZLozZ4Rz0zQD+HeX4nUK4B8GrTX/2EvN2/vBF/i2WnaXboPxo0JylA==", "dev": true, "requires": { "fsevents": "~2.3.2" diff --git a/package.json b/package.json index 420b8bb9..261eede6 100644 --- a/package.json +++ b/package.json @@ -98,7 +98,7 @@ "@types/proper-lockfile": "^4.1.2", "@types/tar": "^6.1.1", "@types/uuid": "^8.3.4", - "@types/ws": "^8.2.3", + "@types/ws": "^8.5.0", "@typescript-eslint/eslint-plugin": "^5.12.1", "@typescript-eslint/parser": "^5.12.1", "auto-changelog": "^2.4.0", @@ -113,9 +113,9 @@ "mochawesome": "^7.0.1", "npm-check": "^5.9.2", "nyc": "^15.1.0", - "release-it": "^14.12.4", + "release-it": "^14.12.5", "robohydra": "^0.6.9", - "rollup": "^2.67.3", + "rollup": "^2.68.0", "rollup-plugin-analyzer": "^4.0.0", "rollup-plugin-copy": "^3.4.0", "rollup-plugin-delete": "^2.0.0", diff --git a/src/charging-station/ocpp/OCPPRequestService.ts b/src/charging-station/ocpp/OCPPRequestService.ts index 15ad6e8a..000d8c0a 100644 --- a/src/charging-station/ocpp/OCPPRequestService.ts +++ b/src/charging-station/ocpp/OCPPRequestService.ts @@ -1,5 +1,5 @@ import { AuthorizeResponse, StartTransactionResponse, StopTransactionReason, StopTransactionResponse } from '../../types/ocpp/Transaction'; -import { DiagnosticsStatus, IncomingRequestCommand, RequestCommand, SendParams } from '../../types/ocpp/Requests'; +import { DiagnosticsStatus, IncomingRequestCommand, RequestCommand, ResponseType, SendParams } from '../../types/ocpp/Requests'; import { BootNotificationResponse } from '../../types/ocpp/Responses'; import { ChargePointErrorCode } from '../../types/ocpp/ChargePointErrorCode'; @@ -33,7 +33,7 @@ export default abstract class OCPPRequestService { return OCPPRequestService.instances.get(chargingStation.id) as T; } - public async sendResult(messageId: string, messagePayload: JsonType, commandName: IncomingRequestCommand): Promise { + public async sendResult(messageId: string, messagePayload: JsonType, commandName: IncomingRequestCommand): Promise { try { // Send result message return await this.internalSendMessage(messageId, messagePayload, MessageType.CALL_RESULT_MESSAGE, commandName); @@ -42,7 +42,7 @@ export default abstract class OCPPRequestService { } } - public async sendError(messageId: string, ocppError: OCPPError, commandName: IncomingRequestCommand): Promise { + public async sendError(messageId: string, ocppError: OCPPError, commandName: IncomingRequestCommand): Promise { try { // Send error message return await this.internalSendMessage(messageId, ocppError, MessageType.CALL_ERROR_MESSAGE, commandName); @@ -54,7 +54,7 @@ export default abstract class OCPPRequestService { protected async sendMessage(messageId: string, messagePayload: JsonType, commandName: RequestCommand, params: SendParams = { skipBufferingOnError: false, triggerMessage: false - }): Promise { + }): Promise { try { return await this.internalSendMessage(messageId, messagePayload, MessageType.CALL_MESSAGE, commandName, params); } catch (error) { @@ -66,7 +66,7 @@ export default abstract class OCPPRequestService { params: SendParams = { skipBufferingOnError: false, triggerMessage: false - }): Promise { + }): Promise { if ((this.chargingStation.isInUnknownState() && commandName === RequestCommand.BOOT_NOTIFICATION) || (!this.chargingStation.getOcppStrictCompliance() && this.chargingStation.isInUnknownState()) || this.chargingStation.isInAcceptedState() || (this.chargingStation.isInPendingState() && params.triggerMessage)) { diff --git a/src/types/ocpp/Requests.ts b/src/types/ocpp/Requests.ts index fcd39a01..1a0d0ffb 100644 --- a/src/types/ocpp/Requests.ts +++ b/src/types/ocpp/Requests.ts @@ -12,6 +12,8 @@ export interface SendParams { export type IncomingRequestHandler = (commandPayload: JsonType) => JsonType | Promise; +export type ResponseType = JsonType | OCPPError | string; + export type BootNotificationRequest = OCPP16BootNotificationRequest; export type AvailabilityType = OCPP16AvailabilityType; -- 2.34.1