diff --git a/package-lock.json b/package-lock.json index ff145889..53ee3dff 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4173,6 +4173,15 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/aws-ssl-profiles": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/aws-ssl-profiles/-/aws-ssl-profiles-1.1.2.tgz", + "integrity": "sha512-NZKeq9AfyQvEeNlN0zSYAaWrmBffJh3IELMZfRpJVWgrpEbtEpnjvzqBPf+mxoI287JohRDoa+/nsfqqiZmF6g==", + "license": "MIT", + "engines": { + "node": ">= 6.0.0" + } + }, "node_modules/axios": { "version": "0.26.0", "resolved": "https://registry.npmjs.org/axios/-/axios-0.26.0.tgz", @@ -4437,15 +4446,6 @@ "node": "*" } }, - "node_modules/bignumber.js": { - "version": "9.0.0", - "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.0.0.tgz", - "integrity": "sha512-t/OYhhJ2SD+YGBQcjY8GzzDHEk9f3nerxjtfa6tlMXfe7frs/WozhvCNoGvpM0P3bNf3Gq5ZRMlGr5f3r4/N8A==", - "license": "MIT", - "engines": { - "node": "*" - } - }, "node_modules/bindings": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz", @@ -5753,6 +5753,15 @@ "integrity": "sha512-bd2L678uiWATM6m5Z1VzNCErI3jiGzt6HGY8OVICs40JQq/HALfbyNJmp0UDakEY4pMMaN0Ly5om/B1VI/+xfQ==", "optional": true }, + "node_modules/denque": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/denque/-/denque-2.1.0.tgz", + "integrity": "sha512-HVQE3AAb/pxF8fQAoiqpvg9i3evqug3hoiwakOyZAwJm+6vZehbkYXZ0l4JxS+I3QxM97v5aaRNhj8v5oBhekw==", + "license": "Apache-2.0", + "engines": { + "node": ">=0.10" + } + }, "node_modules/depd": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", @@ -6592,6 +6601,15 @@ "node": "^12.13.0 || ^14.15.0 || >=16.0.0" } }, + "node_modules/generate-function": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/generate-function/-/generate-function-2.3.1.tgz", + "integrity": "sha512-eeB5GfMNeevm/GRYq20ShmsaGcmI81kIX2K9XQx5miC8KdHaC6Jm0qQ8ZNeGOi7wYB8OsdxKs+Y2oVuTFuVwKQ==", + "license": "MIT", + "dependencies": { + "is-property": "^1.0.2" + } + }, "node_modules/gensync": { "version": "1.0.0-beta.2", "resolved": "https://registry.npmjs.org/gensync/-/gensync-1.0.0-beta.2.tgz", @@ -7263,6 +7281,12 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/is-property": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/is-property/-/is-property-1.0.2.tgz", + "integrity": "sha512-Ks/IoX00TtClbGQr4TWXemAnktAQvYB7HzcCxDGqEZU6oCmb2INHuOoKxbtR+HFkmYWBKv/dOZtGRiAjDhj92g==", + "license": "MIT" + }, "node_modules/is-regex": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.1.4.tgz", @@ -9219,6 +9243,12 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/long": { + "version": "5.2.3", + "resolved": "https://registry.npmjs.org/long/-/long-5.2.3.tgz", + "integrity": "sha512-lcHwpNoggQTObv5apGNCTdJrO69eHOZMi4BNC+rTLER8iHAqGrUVeLh/irVIM7zTw2bOXA8T6uNPeujwOLg/2Q==", + "license": "Apache-2.0" + }, "node_modules/loose-envify": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz", @@ -9247,6 +9277,21 @@ "yallist": "^3.0.2" } }, + "node_modules/lru.min": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/lru.min/-/lru.min-1.1.1.tgz", + "integrity": "sha512-FbAj6lXil6t8z4z3j0E5mfRlPzxkySotzUHwRXjlpRh10vc6AI6WN62ehZj82VG7M20rqogJ0GLwar2Xa05a8Q==", + "license": "MIT", + "engines": { + "bun": ">=1.0.0", + "deno": ">=1.30.0", + "node": ">=8.0.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wellwelwel" + } + }, "node_modules/luxon": { "version": "3.5.0", "resolved": "https://registry.npmjs.org/luxon/-/luxon-3.5.0.tgz", @@ -10236,34 +10281,66 @@ "node": ">= 6.0.0" } }, - "node_modules/mysql": { - "version": "2.18.1", - "resolved": "https://registry.npmjs.org/mysql/-/mysql-2.18.1.tgz", - "integrity": "sha512-Bca+gk2YWmqp2Uf6k5NFEurwY/0td0cpebAucFpY/3jhrwrVGuxU2uQFCHjU19SJfje0yQvi+rVWdq78hR5lig==", + "node_modules/mysql2": { + "version": "3.11.3", + "resolved": "https://registry.npmjs.org/mysql2/-/mysql2-3.11.3.tgz", + "integrity": "sha512-Qpu2ADfbKzyLdwC/5d4W7+5Yz7yBzCU05YWt5npWzACST37wJsB23wgOSo00qi043urkiRwXtEvJc9UnuLX/MQ==", "license": "MIT", "dependencies": { - "bignumber.js": "9.0.0", - "readable-stream": "2.3.7", - "safe-buffer": "5.1.2", - "sqlstring": "2.3.1" + "aws-ssl-profiles": "^1.1.1", + "denque": "^2.1.0", + "generate-function": "^2.3.1", + "iconv-lite": "^0.6.3", + "long": "^5.2.1", + "lru.min": "^1.0.0", + "named-placeholders": "^1.1.3", + "seq-queue": "^0.0.5", + "sqlstring": "^2.3.2" + }, + "engines": { + "node": ">= 8.0" + } + }, + "node_modules/mysql2/node_modules/iconv-lite": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", + "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==", + "license": "MIT", + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3.0.0" }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/mysql2/node_modules/sqlstring": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/sqlstring/-/sqlstring-2.3.3.tgz", + "integrity": "sha512-qC9iz2FlN7DQl3+wjwn3802RTyjCx7sDvfQEXchwa6CWOx07/WVfh91gBmQ9fahw8snwGEWU3xGzOt4tFyHLxg==", + "license": "MIT", "engines": { "node": ">= 0.6" } }, - "node_modules/mysql/node_modules/readable-stream": { - "version": "2.3.7", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", - "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", + "node_modules/named-placeholders": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/named-placeholders/-/named-placeholders-1.1.3.tgz", + "integrity": "sha512-eLoBxg6wE/rZkJPhU/xRX1WTpkFEwDJEN96oxFrTsqBdbT5ec295Q+CoHrL9IT0DipqKhmGcaZmwOt8OON5x1w==", "license": "MIT", "dependencies": { - "core-util-is": "~1.0.0", - "inherits": "~2.0.3", - "isarray": "~1.0.0", - "process-nextick-args": "~2.0.0", - "safe-buffer": "~5.1.1", - "string_decoder": "~1.1.1", - "util-deprecate": "~1.0.1" + "lru-cache": "^7.14.1" + }, + "engines": { + "node": ">=12.0.0" + } + }, + "node_modules/named-placeholders/node_modules/lru-cache": { + "version": "7.18.3", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-7.18.3.tgz", + "integrity": "sha512-jumlc0BIUrS3qJGgIkWZsyfAM7NCWiBcCDhnd+3NNM5KbBmLTgHVfWBcg6W+rLUsIpzpERPsvwUP7CckAQSOoA==", + "license": "ISC", + "engines": { + "node": ">=12" } }, "node_modules/nan": { @@ -11921,6 +11998,11 @@ "node": ">= 0.8" } }, + "node_modules/seq-queue": { + "version": "0.0.5", + "resolved": "https://registry.npmjs.org/seq-queue/-/seq-queue-0.0.5.tgz", + "integrity": "sha512-hr3Wtp/GZIc/6DAGPDcV4/9WoZhjrkXsi5B/07QgX8tsdc6ilr7BFM6PM6rbdAX1kFSDYeZGLipIZZKyQP0O5Q==" + }, "node_modules/serve-static": { "version": "1.16.2", "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.16.2.tgz", @@ -12289,15 +12371,6 @@ } } }, - "node_modules/sqlstring": { - "version": "2.3.1", - "resolved": "https://registry.npmjs.org/sqlstring/-/sqlstring-2.3.1.tgz", - "integrity": "sha512-ooAzh/7dxIG5+uDik1z/Rd1vli0+38izZhGzSa34FwR7IbelPWCCKSNIl8jlL/F7ERvy8CB2jNeM1E9i9mXMAQ==", - "license": "MIT", - "engines": { - "node": ">= 0.6" - } - }, "node_modules/ssri": { "version": "8.0.1", "resolved": "https://registry.npmjs.org/ssri/-/ssri-8.0.1.tgz", @@ -14307,7 +14380,7 @@ "version": "0.7.0", "dependencies": { "knex": "3.1.0", - "mysql": "^2.18.1" + "mysql2": "3.11.3" }, "devDependencies": { "@types/mysql": "2.15.26" diff --git a/plugins/mysql/package.json b/plugins/mysql/package.json index 6ce32454..07982b49 100644 --- a/plugins/mysql/package.json +++ b/plugins/mysql/package.json @@ -17,7 +17,7 @@ }, "dependencies": { "knex": "3.1.0", - "mysql": "^2.18.1" + "mysql2": "3.11.3" }, "devDependencies": { "@types/mysql": "2.15.26" diff --git a/plugins/mysql/src/Database/index.ts b/plugins/mysql/src/Database/index.ts index 5d5c0e9d..5ad85544 100644 --- a/plugins/mysql/src/Database/index.ts +++ b/plugins/mysql/src/Database/index.ts @@ -20,7 +20,7 @@ const deviceDB = {} as IDatabaseConnection; const migrationConfig: Knex.MigratorConfig = { tableName: "migrations", - directory: path.join(dirname__, "Migrations"), + directory: path.join(dirname__, "..", "Migrations"), // ! FIX Error: The migration directory is corrupt, the following files are missing: disableMigrationsListValidation: true, }; @@ -34,7 +34,7 @@ function createConnection( options?: IConnectionOptions, ): Knex { return knex({ - client: "mysql", + client: "mysql2", connection: { charset: "utf8", timezone: "utc", diff --git a/plugins/mysql/src/Helpers/DeviceDatabase.ts b/plugins/mysql/src/Helpers/DeviceDatabase.ts index cbe5aa79..20349920 100644 --- a/plugins/mysql/src/Helpers/DeviceDatabase.ts +++ b/plugins/mysql/src/Helpers/DeviceDatabase.ts @@ -32,6 +32,7 @@ export async function getDeviceConnection(id: TGenericID, type: TDeviceType) { table.index(["time"]); table.index(["group"]); table.index(["created_at"]); + table.string("serie", 100); }); } diff --git a/plugins/mysql/src/Providers/Action/getActionInfo.ts b/plugins/mysql/src/Providers/Action/getActionInfo.ts index fe80a31c..487f8ec4 100644 --- a/plugins/mysql/src/Providers/Action/getActionInfo.ts +++ b/plugins/mysql/src/Providers/Action/getActionInfo.ts @@ -16,7 +16,7 @@ async function getActionInfo(actionID: TGenericID): Promise { response.active = Boolean(response.active); response.lock = Boolean(response.lock); response.created_at = new Date(response.created_at); - response.tags = JSON.parse(response.tags); + response.tags = JSON.parse(JSON.stringify(response.tags)); if (response.action) { response.action = JSON.parse(response.action); diff --git a/plugins/mysql/src/Providers/Action/getActionList.ts b/plugins/mysql/src/Providers/Action/getActionList.ts index ad2315f6..169d5736 100644 --- a/plugins/mysql/src/Providers/Action/getActionList.ts +++ b/plugins/mysql/src/Providers/Action/getActionList.ts @@ -52,7 +52,7 @@ async function getActionList( item.lock = Boolean(item.lock); } if (item.tags) { - item.tags = JSON.parse(item.tags); + item.tags = JSON.parse(JSON.stringify(item.tags)); } if (item.action) { item.action = JSON.parse(item.action); diff --git a/plugins/mysql/src/Providers/Analysis/getAnalysisInfo.ts b/plugins/mysql/src/Providers/Analysis/getAnalysisInfo.ts index 0dfbeb8c..d4e9d870 100644 --- a/plugins/mysql/src/Providers/Analysis/getAnalysisInfo.ts +++ b/plugins/mysql/src/Providers/Analysis/getAnalysisInfo.ts @@ -17,7 +17,7 @@ async function getAnalysisInfo( if (response) { response.active = Boolean(response.active); response.created_at = new Date(response.created_at); - response.tags = JSON.parse(response.tags); + response.tags = JSON.parse(JSON.stringify(response.tags)); if (response.variables) { response.variables = JSON.parse(response.variables); diff --git a/plugins/mysql/src/Providers/Analysis/getAnalysisList.ts b/plugins/mysql/src/Providers/Analysis/getAnalysisList.ts index 4a9c9b70..c22b20a3 100644 --- a/plugins/mysql/src/Providers/Analysis/getAnalysisList.ts +++ b/plugins/mysql/src/Providers/Analysis/getAnalysisList.ts @@ -59,7 +59,7 @@ async function getAnalysisList( item.active = Boolean(item.active); } if (item.tags) { - item.tags = JSON.parse(item.tags); + item.tags = JSON.parse(JSON.stringify(item.tags)); } if (item.variables) { item.variables = JSON.parse(item.variables); diff --git a/plugins/mysql/src/Providers/Device/getDeviceInfo.ts b/plugins/mysql/src/Providers/Device/getDeviceInfo.ts index 4c674158..4af319d2 100644 --- a/plugins/mysql/src/Providers/Device/getDeviceInfo.ts +++ b/plugins/mysql/src/Providers/Device/getDeviceInfo.ts @@ -15,7 +15,7 @@ async function getDeviceInfo(deviceID: TGenericID): Promise { if (response) { response.active = Boolean(response.active); response.created_at = new Date(response.created_at); - response.tags = JSON.parse(response.tags); + response.tags = JSON.parse(JSON.stringify(response.tags)); if (response.last_input) { response.last_input = new Date(response.last_input); diff --git a/plugins/mysql/src/Providers/Device/getDeviceList.ts b/plugins/mysql/src/Providers/Device/getDeviceList.ts index 49874ffe..3d74a9cc 100644 --- a/plugins/mysql/src/Providers/Device/getDeviceList.ts +++ b/plugins/mysql/src/Providers/Device/getDeviceList.ts @@ -58,7 +58,7 @@ async function getDeviceList( item.active = Boolean(item.active); } if (item.tags) { - item.tags = JSON.parse(item.tags); + item.tags = JSON.parse(JSON.stringify(item.tags)); } if (item.encoder_stack) { item.encoder_stack = JSON.parse(item.encoder_stack); diff --git a/plugins/mysql/src/Providers/Tag/getTagKeys.ts b/plugins/mysql/src/Providers/Tag/getTagKeys.ts index 75fd7c00..97261d13 100644 --- a/plugins/mysql/src/Providers/Tag/getTagKeys.ts +++ b/plugins/mysql/src/Providers/Tag/getTagKeys.ts @@ -9,7 +9,7 @@ async function getTagKeys(type: TDatabaseGetTagKeysType): Promise { const keys: string[] = []; for (const item of response) { - const tags = JSON.parse(item.tags) as ITag[]; + const tags = JSON.parse(JSON.stringify(item.tags)) as ITag[]; for (const tag of tags) { if (!keys.includes(tag.key)) { keys.push(tag.key);