Upgrade sqlite3 in SQLite agent, upgrade deps with security flaws, remove Sequelize dep

[GDC-812]: https://hasurahq.atlassian.net/browse/GDC-812?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/8120
GitOrigin-RevId: c15d5aaf0c9e71fcfcaa8d580d6d1423efcc416f
This commit is contained in:
Daniel Chambers 2023-02-28 01:00:51 +11:00 committed by hasura-bot
parent aaf20b971f
commit bbe756dbcc
13 changed files with 2628 additions and 2742 deletions

File diff suppressed because it is too large Load Diff

View File

@ -9,9 +9,9 @@
"version": "0.1.0",
"license": "Apache-2.0",
"dependencies": {
"@fastify/cors": "^7.0.0",
"@fastify/cors": "^8.1.0",
"@hasura/dc-api-types": "0.25.0",
"fastify": "^3.29.0",
"fastify": "^4.13.0",
"mathjs": "^11.0.0",
"pino-pretty": "^8.0.0",
"xml2js": "github:Leonidas-from-XIV/node-xml2js"
@ -25,24 +25,32 @@
}
},
"node_modules/@fastify/cors": {
"version": "7.0.0",
"license": "MIT",
"version": "8.1.0",
"resolved": "https://registry.npmjs.org/@fastify/cors/-/cors-8.1.0.tgz",
"integrity": "sha512-1OmjwyxQZ8GePxa5t1Rpsn2qS56+1ouKMvZufpgJWhXtoCeM/ffA+PsNW8pyslPr4W0E27gVoFqtvHwhXW1U2w==",
"dependencies": {
"fastify-plugin": "^3.0.0",
"vary": "^1.1.2"
"fastify-plugin": "^4.0.0",
"mnemonist": "0.39.2"
}
},
"node_modules/fastify-plugin": {
"version": "3.0.1",
"license": "MIT"
"version": "4.5.0",
"resolved": "https://registry.npmjs.org/fastify-plugin/-/fastify-plugin-4.5.0.tgz",
"integrity": "sha512-79ak0JxddO0utAXAQ5ccKhvs6vX2MGyHHMMsmZkBANrq3hXc1CHzvNPHOcvTsVMEPl5I+NT+RO4YKMGehOfSIg=="
},
"node_modules/vary": {
"version": "1.1.2",
"license": "MIT",
"engines": {
"node": ">= 0.8"
"node_modules/mnemonist": {
"version": "0.39.2",
"resolved": "https://registry.npmjs.org/mnemonist/-/mnemonist-0.39.2.tgz",
"integrity": "sha512-n3ZCEosuMH03DVivZ9N0fcXPWiZrBLEdfSlEJ+S/mJxmk3zuo1ur0dj9URDczFyP1VS3wfiyKzqLLDXoPJ6rPA==",
"dependencies": {
"obliterator": "^2.0.1"
}
},
"node_modules/obliterator": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/obliterator/-/obliterator-2.0.4.tgz",
"integrity": "sha512-lgHwxlxV1qIg1Eap7LgIeoBWIMFibOjbrYPIPJZcI1mmGAI2m3lNYpK12Y+GBdPQ0U1hRwSord7GIaawz962qQ=="
},
"node_modules/@hasura/dc-api-types": {
"version": "0.25.0",
"license": "Apache-2.0",
@ -61,7 +69,8 @@
"node_modules/@types/node": {
"version": "16.11.49",
"resolved": "https://registry.npmjs.org/@types/node/-/node-16.11.49.tgz",
"integrity": "sha512-Abq9fBviLV93OiXMu+f6r0elxCzRwc0RC5f99cU892uBITL44pTvgvEqlRlPRi8EGcO1z7Cp8A4d0s/p3J/+Nw=="
"integrity": "sha512-Abq9fBviLV93OiXMu+f6r0elxCzRwc0RC5f99cU892uBITL44pTvgvEqlRlPRi8EGcO1z7Cp8A4d0s/p3J/+Nw==",
"dev": true
},
"node_modules/typescript": {
"version": "4.7.4",
@ -77,40 +86,45 @@
}
},
"node_modules/fastify": {
"version": "3.29.0",
"license": "MIT",
"version": "4.13.0",
"resolved": "https://registry.npmjs.org/fastify/-/fastify-4.13.0.tgz",
"integrity": "sha512-p9ibdFWH3pZ7KPgmfHPKGUy2W4EWU2TEpwlcu58w4CwGyU3ARFfh2kwq6zpZ5W2ZGVbufi4tZbqHIHAlX/9Z/A==",
"dependencies": {
"@fastify/ajv-compiler": "^1.0.0",
"@fastify/error": "^2.0.0",
"abstract-logging": "^2.0.0",
"avvio": "^7.1.2",
"fast-json-stringify": "^2.5.2",
"find-my-way": "^4.5.0",
"flatstr": "^1.0.12",
"light-my-request": "^4.2.0",
"pino": "^6.13.0",
"process-warning": "^1.0.0",
"@fastify/ajv-compiler": "^3.3.1",
"@fastify/error": "^3.0.0",
"@fastify/fast-json-stringify-compiler": "^4.1.0",
"abstract-logging": "^2.0.1",
"avvio": "^8.2.0",
"fast-content-type-parse": "^1.0.0",
"find-my-way": "^7.3.0",
"light-my-request": "^5.6.1",
"pino": "^8.5.0",
"process-warning": "^2.0.0",
"proxy-addr": "^2.0.7",
"rfdc": "^1.1.4",
"secure-json-parse": "^2.0.0",
"semver": "^7.3.2",
"tiny-lru": "^8.0.1"
"rfdc": "^1.3.0",
"secure-json-parse": "^2.5.0",
"semver": "^7.3.7",
"tiny-lru": "^10.0.0"
}
},
"node_modules/@fastify/ajv-compiler": {
"version": "1.1.0",
"license": "MIT",
"version": "3.4.0",
"resolved": "https://registry.npmjs.org/@fastify/ajv-compiler/-/ajv-compiler-3.4.0.tgz",
"integrity": "sha512-69JnK7Cot+ktn7LD5TikP3b7psBPX55tYpQa8WSumt8r117PCa2zwHnImfBtRWYExreJlI48hr0WZaVrTBGj7w==",
"dependencies": {
"ajv": "^6.12.6"
"ajv": "^8.11.0",
"ajv-formats": "^2.1.1",
"fast-uri": "^2.0.0"
}
},
"node_modules/ajv": {
"version": "6.12.6",
"license": "MIT",
"version": "8.11.2",
"resolved": "https://registry.npmjs.org/ajv/-/ajv-8.11.2.tgz",
"integrity": "sha512-E4bfmKAhGiSTvMfL1Myyycaub+cUEU2/IvpylXkUu7CHBkBj1f/ikdzbD7YQ6FKUbixDxeYvB/xY4fvyroDlQg==",
"dependencies": {
"fast-deep-equal": "^3.1.1",
"fast-json-stable-stringify": "^2.0.0",
"json-schema-traverse": "^0.4.1",
"json-schema-traverse": "^1.0.0",
"require-from-string": "^2.0.2",
"uri-js": "^4.2.2"
},
"funding": {
@ -123,13 +137,18 @@
"resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz",
"integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q=="
},
"node_modules/fast-json-stable-stringify": {
"version": "2.1.0",
"license": "MIT"
},
"node_modules/json-schema-traverse": {
"version": "0.4.1",
"license": "MIT"
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz",
"integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug=="
},
"node_modules/require-from-string": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz",
"integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/uri-js": {
"version": "4.4.1",
@ -147,9 +166,62 @@
"node": ">=6"
}
},
"node_modules/ajv-formats": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.1.tgz",
"integrity": "sha512-Wx0Kx52hxE7C18hkMEggYlEifqWZtYaRgouJor+WMdPnQyEK13vgEWyVNup7SoeeoLMsr4kf5h6dOW11I15MUA==",
"dependencies": {
"ajv": "^8.0.0"
},
"peerDependencies": {
"ajv": "^8.0.0"
},
"peerDependenciesMeta": {
"ajv": {
"optional": true
}
}
},
"node_modules/fast-uri": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-2.1.0.tgz",
"integrity": "sha512-qKRta6N7BWEFVlyonVY/V+BMLgFqktCUV0QjT259ekAIlbVrMaFnFLxJ4s/JPl4tou56S1BzPufI60bLe29fHA=="
},
"node_modules/@fastify/error": {
"version": "2.0.0",
"license": "MIT"
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/@fastify/error/-/error-3.0.0.tgz",
"integrity": "sha512-dPRyT40GiHRzSCll3/Jn2nPe25+E1VXc9tDwRAIKwFCxd5Np5wzgz1tmooWG3sV0qKgrBibihVoCna2ru4SEFg=="
},
"node_modules/@fastify/fast-json-stringify-compiler": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/@fastify/fast-json-stringify-compiler/-/fast-json-stringify-compiler-4.1.0.tgz",
"integrity": "sha512-cTKBV2J9+u6VaKDhX7HepSfPSzw+F+TSd+k0wzifj4rG+4E5PjSFJCk19P8R6tr/72cuzgGd+mbB3jFT6lvAgw==",
"dependencies": {
"fast-json-stringify": "^5.0.0"
}
},
"node_modules/fast-json-stringify": {
"version": "5.4.1",
"resolved": "https://registry.npmjs.org/fast-json-stringify/-/fast-json-stringify-5.4.1.tgz",
"integrity": "sha512-P7S9WXEnMqu6seBnzAFmgZ+T3KCD+Do+pNIJsmk/6OlDHZVjl6KzsQB3TFHKQb2Q8N7C9l31WS7/LZGF5hT1FA==",
"dependencies": {
"@fastify/deepmerge": "^1.0.0",
"ajv": "^8.10.0",
"ajv-formats": "^2.1.1",
"fast-deep-equal": "^3.1.3",
"fast-uri": "^2.1.0",
"rfdc": "^1.2.0"
}
},
"node_modules/@fastify/deepmerge": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/@fastify/deepmerge/-/deepmerge-1.1.0.tgz",
"integrity": "sha512-E8Hfdvs1bG6u0N4vN5Nty6JONUfTdOciyD5rn8KnEsLKIenvOVcr210BQR9t34PRkNyjqnMLGk3e0BsaxRdL+g=="
},
"node_modules/rfdc": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/rfdc/-/rfdc-1.3.0.tgz",
"integrity": "sha512-V2hovdzFbOi77/WajaSMXk2OLm+xNIeQdMMuB7icj7bk6zi2F8GGAxigcnDFpJHbNyNcgyJDiP+8nOrY5cZGrA=="
},
"node_modules/abstract-logging": {
"version": "2.0.1",
@ -157,13 +229,13 @@
"integrity": "sha512-2BjRTZxTPvheOvGbBslFSYOUkr+SjPtOnrLP33f+VIWLzezQpZcqVg7ja3L4dBXmzzgwT+a029jRx5PCi3JuiA=="
},
"node_modules/avvio": {
"version": "7.2.5",
"license": "MIT",
"version": "8.2.0",
"resolved": "https://registry.npmjs.org/avvio/-/avvio-8.2.0.tgz",
"integrity": "sha512-bbCQdg7bpEv6kGH41RO/3B2/GMMmJSo2iBK+X8AWN9mujtfUipMDfIjsgHCfpnKqoGEQrrmCDKSa5OQ19+fDmg==",
"dependencies": {
"archy": "^1.0.0",
"debug": "^4.0.0",
"fastq": "^1.6.1",
"queue-microtask": "^1.1.2"
"fastq": "^1.6.1"
}
},
"node_modules/archy": {
@ -209,64 +281,30 @@
"node": ">=0.10.0"
}
},
"node_modules/queue-microtask": {
"version": "1.2.3",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/feross"
},
{
"type": "patreon",
"url": "https://www.patreon.com/feross"
},
{
"type": "consulting",
"url": "https://feross.org/support"
}
],
"license": "MIT"
},
"node_modules/fast-json-stringify": {
"version": "2.7.13",
"license": "MIT",
"dependencies": {
"ajv": "^6.11.0",
"deepmerge": "^4.2.2",
"rfdc": "^1.2.0",
"string-similarity": "^4.0.1"
},
"engines": {
"node": ">= 10.0.0"
}
},
"node_modules/deepmerge": {
"version": "4.2.2",
"license": "MIT",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/rfdc": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/rfdc/-/rfdc-1.3.0.tgz",
"integrity": "sha512-V2hovdzFbOi77/WajaSMXk2OLm+xNIeQdMMuB7icj7bk6zi2F8GGAxigcnDFpJHbNyNcgyJDiP+8nOrY5cZGrA=="
},
"node_modules/string-similarity": {
"version": "4.0.4",
"license": "ISC"
"node_modules/fast-content-type-parse": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/fast-content-type-parse/-/fast-content-type-parse-1.0.0.tgz",
"integrity": "sha512-Xbc4XcysUXcsP5aHUU7Nq3OwvHq97C+WnbkeIefpeYLX+ryzFJlU6OStFJhs6Ol0LkUGpcK+wL0JwfM+FCU5IA=="
},
"node_modules/find-my-way": {
"version": "4.5.1",
"license": "MIT",
"version": "7.3.1",
"resolved": "https://registry.npmjs.org/find-my-way/-/find-my-way-7.3.1.tgz",
"integrity": "sha512-kGvM08SOkqvheLcuQ8GW9t/H901Qb9rZEbcNWbXopzy4jDRoaJpJoObPSKf4MnQLZ20ZTp7rL5MpF6rf+pqmyg==",
"dependencies": {
"fast-decode-uri-component": "^1.0.1",
"fast-deep-equal": "^3.1.3",
"safe-regex2": "^2.0.0",
"semver-store": "^0.3.0"
"fast-querystring": "^1.0.0",
"safe-regex2": "^2.0.0"
},
"engines": {
"node": ">=10"
"node": ">=14"
}
},
"node_modules/fast-querystring": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/fast-querystring/-/fast-querystring-1.0.0.tgz",
"integrity": "sha512-3LQi62IhQoDlmt4ULCYmh17vRO2EtS7hTSsG4WwoKWgV7GLMKBOecEh+aiavASnLx8I2y89OD33AGLo0ccRhzA==",
"dependencies": {
"fast-decode-uri-component": "^1.0.1"
}
},
"node_modules/fast-decode-uri-component": {
@ -290,60 +328,28 @@
"node": ">=4"
}
},
"node_modules/semver-store": {
"version": "0.3.0",
"license": "MIT"
},
"node_modules/flatstr": {
"version": "1.0.12",
"license": "MIT"
},
"node_modules/light-my-request": {
"version": "4.8.0",
"license": "BSD-3-Clause",
"version": "5.6.1",
"resolved": "https://registry.npmjs.org/light-my-request/-/light-my-request-5.6.1.tgz",
"integrity": "sha512-sbJnC1UBRivi9L1kICr3CESb82pNiPNB3TvtdIrZZqW0Qh8uDXvoywMmWKZlihDcmw952CMICCzM+54LDf+E+g==",
"dependencies": {
"ajv": "^8.1.0",
"cookie": "^0.4.0",
"process-warning": "^1.0.0",
"cookie": "^0.5.0",
"process-warning": "^2.0.0",
"set-cookie-parser": "^2.4.1"
}
},
"node_modules/light-my-request/node_modules/ajv": {
"version": "8.10.0",
"license": "MIT",
"dependencies": {
"fast-deep-equal": "^3.1.1",
"json-schema-traverse": "^1.0.0",
"require-from-string": "^2.0.2",
"uri-js": "^4.2.2"
},
"funding": {
"type": "github",
"url": "https://github.com/sponsors/epoberezkin"
}
},
"node_modules/light-my-request/node_modules/json-schema-traverse": {
"version": "1.0.0",
"license": "MIT"
},
"node_modules/require-from-string": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz",
"integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/cookie": {
"version": "0.4.2",
"license": "MIT",
"version": "0.5.0",
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.5.0.tgz",
"integrity": "sha512-YZ3GUyn/o8gfKJlnlX7g7xq4gyO6OSuhGPKaaGssGB2qgDUS0gPgtTvoyZLTt9Ab6dC4hfc9dV5arkvc/OCmrw==",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/process-warning": {
"version": "1.0.0",
"license": "MIT"
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/process-warning/-/process-warning-2.0.0.tgz",
"integrity": "sha512-+MmoAXoUX+VTHAlwns0h+kFUWFs/3FZy+ZuchkgjyOu3oioLAo2LB5aCfKPh2+P9O18i3m43tUEv3YqttSy0Ww=="
},
"node_modules/set-cookie-parser": {
"version": "2.5.1",
@ -351,21 +357,34 @@
"integrity": "sha512-1jeBGaKNGdEq4FgIrORu/N570dwoPYio8lSoYLWmX7sQ//0JY08Xh9o5pBcgmHQ/MbsYp/aZnOe1s1lIsbLprQ=="
},
"node_modules/pino": {
"version": "6.14.0",
"license": "MIT",
"version": "8.7.0",
"resolved": "https://registry.npmjs.org/pino/-/pino-8.7.0.tgz",
"integrity": "sha512-l9sA5uPxmZzwydhMWUcm1gI0YxNnYl8MfSr2h8cwLvOAzQLBLewzF247h/vqHe3/tt6fgtXeG9wdjjoetdI/vA==",
"dependencies": {
"fast-redact": "^3.0.0",
"fast-safe-stringify": "^2.0.8",
"flatstr": "^1.0.12",
"pino-std-serializers": "^3.1.0",
"process-warning": "^1.0.0",
"atomic-sleep": "^1.0.0",
"fast-redact": "^3.1.1",
"on-exit-leak-free": "^2.1.0",
"pino-abstract-transport": "v1.0.0",
"pino-std-serializers": "^6.0.0",
"process-warning": "^2.0.0",
"quick-format-unescaped": "^4.0.3",
"sonic-boom": "^1.0.2"
"real-require": "^0.2.0",
"safe-stable-stringify": "^2.3.1",
"sonic-boom": "^3.1.0",
"thread-stream": "^2.0.0"
},
"bin": {
"pino": "bin.js"
}
},
"node_modules/atomic-sleep": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/atomic-sleep/-/atomic-sleep-1.0.0.tgz",
"integrity": "sha512-kNOjDqAh7px0XWNI+4QbzoiR/nTkHAWNud2uvnJquD1/x5a7EQZMJT0AczqK0Qn67oY/TTQ1LbUKajZpp3I9tQ==",
"engines": {
"node": ">=8.0.0"
}
},
"node_modules/fast-redact": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/fast-redact/-/fast-redact-3.1.2.tgz",
@ -374,33 +393,178 @@
"node": ">=6"
}
},
"node_modules/fast-safe-stringify": {
"version": "2.1.1",
"license": "MIT"
"node_modules/on-exit-leak-free": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/on-exit-leak-free/-/on-exit-leak-free-2.1.0.tgz",
"integrity": "sha512-VuCaZZAjReZ3vUwgOB8LxAosIurDiAW0s13rI1YwmaP++jvcxP77AWoQvenZebpCA2m8WC1/EosPYPMjnRAp/w=="
},
"node_modules/pino-abstract-transport": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/pino-abstract-transport/-/pino-abstract-transport-1.0.0.tgz",
"integrity": "sha512-c7vo5OpW4wIS42hUVcT5REsL8ZljsUfBjqV/e2sFxmFEFZiq1XLUp5EYLtuDH6PEHq9W1egWqRbnLUP5FuZmOA==",
"dependencies": {
"readable-stream": "^4.0.0",
"split2": "^4.0.0"
}
},
"node_modules/readable-stream": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-4.2.0.tgz",
"integrity": "sha512-gJrBHsaI3lgBoGMW/jHZsQ/o/TIWiu5ENCJG1BB7fuCKzpFM8GaS2UoBVt9NO+oI+3FcrBNbUkl3ilDe09aY4A==",
"dependencies": {
"abort-controller": "^3.0.0",
"buffer": "^6.0.3",
"events": "^3.3.0",
"process": "^0.11.10"
},
"engines": {
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
}
},
"node_modules/abort-controller": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz",
"integrity": "sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==",
"dependencies": {
"event-target-shim": "^5.0.0"
},
"engines": {
"node": ">=6.5"
}
},
"node_modules/event-target-shim": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz",
"integrity": "sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==",
"engines": {
"node": ">=6"
}
},
"node_modules/buffer": {
"version": "6.0.3",
"resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz",
"integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/feross"
},
{
"type": "patreon",
"url": "https://www.patreon.com/feross"
},
{
"type": "consulting",
"url": "https://feross.org/support"
}
],
"dependencies": {
"base64-js": "^1.3.1",
"ieee754": "^1.2.1"
}
},
"node_modules/base64-js": {
"version": "1.5.1",
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz",
"integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/feross"
},
{
"type": "patreon",
"url": "https://www.patreon.com/feross"
},
{
"type": "consulting",
"url": "https://feross.org/support"
}
]
},
"node_modules/ieee754": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz",
"integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/feross"
},
{
"type": "patreon",
"url": "https://www.patreon.com/feross"
},
{
"type": "consulting",
"url": "https://feross.org/support"
}
]
},
"node_modules/events": {
"version": "3.3.0",
"resolved": "https://registry.npmjs.org/events/-/events-3.3.0.tgz",
"integrity": "sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q==",
"engines": {
"node": ">=0.8.x"
}
},
"node_modules/process": {
"version": "0.11.10",
"resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz",
"integrity": "sha512-cdGef/drWFoydD1JsMzuFf8100nZl+GT+yacc2bEced5f9Rjk4z+WtFUTBu9PhOi9j/jfmBPu0mMEY4wIdAF8A==",
"engines": {
"node": ">= 0.6.0"
}
},
"node_modules/split2": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/split2/-/split2-4.1.0.tgz",
"integrity": "sha512-VBiJxFkxiXRlUIeyMQi8s4hgvKCSjtknJv/LVYbrgALPwf5zSKmEwV9Lst25AkvMDnvxODugjdl6KZgwKM1WYQ==",
"engines": {
"node": ">= 10.x"
}
},
"node_modules/pino-std-serializers": {
"version": "3.2.0",
"license": "MIT"
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/pino-std-serializers/-/pino-std-serializers-6.0.0.tgz",
"integrity": "sha512-mMMOwSKrmyl+Y12Ri2xhH1lbzQxwwpuru9VjyJpgFIH4asSj88F2csdMwN6+M5g1Ll4rmsYghHLQJw81tgZ7LQ=="
},
"node_modules/quick-format-unescaped": {
"version": "4.0.4",
"resolved": "https://registry.npmjs.org/quick-format-unescaped/-/quick-format-unescaped-4.0.4.tgz",
"integrity": "sha512-tYC1Q1hgyRuHgloV/YXs2w15unPVh8qfu/qCTfhTYamaw7fyhumKa2yGpdSo87vY32rIclj+4fWYQXUMs9EHvg=="
},
"node_modules/sonic-boom": {
"version": "1.4.1",
"license": "MIT",
"dependencies": {
"atomic-sleep": "^1.0.0",
"flatstr": "^1.0.12"
"node_modules/real-require": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/real-require/-/real-require-0.2.0.tgz",
"integrity": "sha512-57frrGM/OCTLqLOAh0mhVA9VBMHd+9U7Zb2THMGdBUoZVOtGbJzjxsYGDJ3A9AYYCP4hn6y1TVbaOfzWtm5GFg==",
"engines": {
"node": ">= 12.13.0"
}
},
"node_modules/atomic-sleep": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/atomic-sleep/-/atomic-sleep-1.0.0.tgz",
"integrity": "sha512-kNOjDqAh7px0XWNI+4QbzoiR/nTkHAWNud2uvnJquD1/x5a7EQZMJT0AczqK0Qn67oY/TTQ1LbUKajZpp3I9tQ==",
"node_modules/safe-stable-stringify": {
"version": "2.4.1",
"resolved": "https://registry.npmjs.org/safe-stable-stringify/-/safe-stable-stringify-2.4.1.tgz",
"integrity": "sha512-dVHE6bMtS/bnL2mwualjc6IxEv1F+OCUpA46pKUj6F8uDbUM0jCCulPqRNPSnWwGNKx5etqMjZYdXtrm5KJZGA==",
"engines": {
"node": ">=8.0.0"
"node": ">=10"
}
},
"node_modules/sonic-boom": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/sonic-boom/-/sonic-boom-3.2.0.tgz",
"integrity": "sha512-SbbZ+Kqj/XIunvIAgUZRlqd6CGQYq71tRRbXR92Za8J/R3Yh4Av+TWENiSiEgnlwckYLyP0YZQWVfyNC0dzLaA==",
"dependencies": {
"atomic-sleep": "^1.0.0"
}
},
"node_modules/thread-stream": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/thread-stream/-/thread-stream-2.2.0.tgz",
"integrity": "sha512-rUkv4/fnb4rqy/gGy7VuqK6wE1+1DOCOWy4RMeaV69ZHMP11tQKZvZSip1yTgrKCMZzEMcCL/bKfHvSfDHx+iQ==",
"dependencies": {
"real-require": "^0.2.0"
}
},
"node_modules/proxy-addr": {
@ -467,8 +631,9 @@
"integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A=="
},
"node_modules/tiny-lru": {
"version": "8.0.2",
"license": "BSD-3-Clause",
"version": "10.0.1",
"resolved": "https://registry.npmjs.org/tiny-lru/-/tiny-lru-10.0.1.tgz",
"integrity": "sha512-Vst+6kEsWvb17Zpz14sRJV/f8bUWKhqm6Dc+v08iShmIJ/WxqWytHzCTd6m88pS33rE2zpX34TRmOpAJPloNCA==",
"engines": {
"node": ">=6"
}
@ -684,6 +849,10 @@
"version": "2.1.3",
"license": "MIT"
},
"node_modules/fast-safe-stringify": {
"version": "2.1.1",
"license": "MIT"
},
"node_modules/joycon": {
"version": "3.1.1",
"license": "MIT",
@ -691,11 +860,11 @@
"node": ">=10"
}
},
"node_modules/on-exit-leak-free": {
"node_modules/pino-pretty/node_modules/on-exit-leak-free": {
"version": "0.2.0",
"license": "MIT"
},
"node_modules/pino-abstract-transport": {
"node_modules/pino-pretty/node_modules/pino-abstract-transport": {
"version": "0.5.0",
"license": "MIT",
"dependencies": {
@ -722,20 +891,23 @@
},
"node_modules/once": {
"version": "1.4.0",
"license": "ISC",
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
"integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==",
"dependencies": {
"wrappy": "1"
}
},
"node_modules/wrappy": {
"version": "1.0.2",
"license": "ISC"
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
"integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ=="
},
"node_modules/inherits": {
"version": "2.0.4",
"license": "ISC"
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
},
"node_modules/readable-stream": {
"node_modules/duplexify/node_modules/readable-stream": {
"version": "3.6.0",
"license": "MIT",
"dependencies": {
@ -749,13 +921,16 @@
},
"node_modules/string_decoder": {
"version": "1.3.0",
"license": "MIT",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz",
"integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==",
"dependencies": {
"safe-buffer": "~5.2.0"
}
},
"node_modules/safe-buffer": {
"version": "5.2.1",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",
"integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==",
"funding": [
{
"type": "github",
@ -769,25 +944,17 @@
"type": "consulting",
"url": "https://feross.org/support"
}
],
"license": "MIT"
]
},
"node_modules/util-deprecate": {
"version": "1.0.2",
"license": "MIT"
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
"integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw=="
},
"node_modules/stream-shift": {
"version": "1.0.1",
"license": "MIT"
},
"node_modules/split2": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/split2/-/split2-4.1.0.tgz",
"integrity": "sha512-VBiJxFkxiXRlUIeyMQi8s4hgvKCSjtknJv/LVYbrgALPwf5zSKmEwV9Lst25AkvMDnvxODugjdl6KZgwKM1WYQ==",
"engines": {
"node": ">= 10.x"
}
},
"node_modules/pump": {
"version": "3.0.0",
"license": "MIT",
@ -796,6 +963,18 @@
"once": "^1.3.1"
}
},
"node_modules/pino-pretty/node_modules/readable-stream": {
"version": "3.6.0",
"license": "MIT",
"dependencies": {
"inherits": "^2.0.3",
"string_decoder": "^1.1.1",
"util-deprecate": "^1.0.1"
},
"engines": {
"node": ">= 6"
}
},
"node_modules/pino-pretty/node_modules/sonic-boom": {
"version": "2.6.0",
"license": "MIT",

View File

@ -21,9 +21,9 @@
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"@fastify/cors": "^7.0.0",
"@fastify/cors": "^8.1.0",
"@hasura/dc-api-types": "0.25.0",
"fastify": "^3.29.0",
"fastify": "^4.13.0",
"mathjs": "^11.0.0",
"pino-pretty": "^8.0.0",
"xml2js": "github:Leonidas-from-XIV/node-xml2js"

View File

@ -8,7 +8,7 @@ import { CapabilitiesResponse, SchemaResponse, QueryRequest, QueryResponse, Data
import { cloneDataset, defaultDbStoreName, deleteDataset, getDataset, getDbStoreName } from './datasets';
const port = Number(process.env.PORT) || 8100;
const server = Fastify({ logger: { prettyPrint: true } });
const server = Fastify({ logger: { transport: { target: 'pino-pretty' } }});
let staticData : Record<string, StaticData> = {};
server.register(FastifyCors, {
@ -85,7 +85,7 @@ process.on('SIGINT', () => {
const start = async () => {
try {
staticData = {[defaultDbStoreName]: await loadStaticData("Chinook.xml.gz")};
await server.listen(port, "0.0.0.0");
await server.listen({port: port, host: "0.0.0.0"});
}
catch (err) {
server.log.fatal(err);

File diff suppressed because it is too large Load Diff

View File

@ -24,13 +24,12 @@
"@fastify/cors": "^8.1.0",
"@hasura/dc-api-types": "0.25.0",
"fastify-metrics": "^9.2.1",
"fastify": "^4.4.0",
"fastify": "^4.13.0",
"nanoid": "^3.3.4",
"openapi3-ts": "^2.0.2",
"pino-pretty": "^8.1.0",
"sequelize": "^6.21.2",
"sqlite-parser": "^1.0.1",
"sqlite3": "^5.0.8",
"sqlite3": "^5.1.4",
"sqlstring-sqlite": "^0.1.1"
},
"devDependencies": {

View File

@ -1,4 +1,4 @@
import { connect, createDbMode, SqlLogger, withConnection } from './db';
import { createDbMode, defaultMode, SqlLogger, withConnection } from './db';
import { DatasetDeleteCloneResponse, DatasetGetTemplateResponse, DatasetCreateCloneRequest, DatasetCreateCloneResponse, } from '@hasura/dc-api-types';
import { access, constants, promises, existsSync } from 'fs';
import { DATASET_CLONES, DATASET_DELETE, DATASET_TEMPLATES } from "./environment";
@ -20,12 +20,13 @@ export async function cloneDataset(logger: SqlLogger, clone_name: string, body:
}
if (await fileIsReadable(templatePaths.dbFileTemplatePath)) {
const db = connect({ db: templatePaths.dbFileTemplatePath, explicit_main_schema: false, tables: [], meta: false }, logger);
if (db) {
db.close();
} else {
try {
await withConnection({ db: templatePaths.dbFileTemplatePath, explicit_main_schema: false, tables: [], meta: false }, defaultMode, logger, async db => {});
}
catch {
throw new Error("Dataset template is not a valid SQLite database!");
}
await promises.cp(templatePaths.dbFileTemplatePath, toPath);
return { config: { db: toPath } };

View File

@ -1,5 +1,4 @@
import { Config } from "./config";
import { Sequelize } from 'sequelize';
import { DB_ALLOW_LIST, DB_CREATE, DB_PRIVATECACHE, DB_READONLY } from "./environment";
import SQLite from 'sqlite3';
@ -14,23 +13,6 @@ const cacheMode = DB_PRIVATECACHE ? SQLite.OPEN_PRIVATECACHE : SQLite.OPEN_SHAR
export const defaultMode = readMode | createMode | cacheMode;
export const createDbMode = SQLite.OPEN_CREATE | readMode | cacheMode;
export function connect(config: Config, sqlLogger: SqlLogger): Sequelize {
if(DB_ALLOW_LIST != null) {
if(DB_ALLOW_LIST.includes(config.db)) {
throw new Error(`Database ${config.db} is not present in DB_ALLOW_LIST 😭`);
}
}
const db = new Sequelize({
dialect: 'sqlite',
storage: config.db,
dialectOptions: { mode: defaultMode },
logging: sqlLogger
});
return db;
};
export type Connection = {
query: (query: string, params?: Record<string, unknown>) => Promise<Array<any>>,
exec: (sql: string) => Promise<void>;

View File

@ -5,7 +5,7 @@ import { explain, queryData } from './query';
import { getConfig, tryGetConfig } from './config';
import { capabilitiesResponse } from './capabilities';
import { QueryResponse, SchemaResponse, QueryRequest, CapabilitiesResponse, ExplainResponse, RawRequest, RawResponse, ErrorResponse, MutationRequest, MutationResponse, DatasetTemplateName, DatasetGetTemplateResponse, DatasetCreateCloneRequest, DatasetCreateCloneResponse, DatasetDeleteCloneResponse } from '@hasura/dc-api-types';
import { connect } from './db';
import { defaultMode, withConnection } from './db';
import metrics from 'fastify-metrics';
import prometheus from 'prom-client';
import { runRawOperation } from './raw';
@ -170,14 +170,15 @@ server.get("/health", async (request, response) => {
response.statusCode = 204;
} else {
server.log.info({ headers: request.headers, query: request.body, }, "health.db.request");
const db = connect(config, sqlLogger);
const [r, m] = await db.query('select 1 where 1 = 1');
if(r && JSON.stringify(r) == '[{"1":1}]') {
response.statusCode = 204;
} else {
response.statusCode = 500;
return { "error": "problem executing query", "query_result": r };
}
return await withConnection(config, defaultMode, sqlLogger, async db => {
const r = await db.query('select 1 where 1 = 1');
if (r && JSON.stringify(r) == '[{"1":1}]') {
response.statusCode = 204;
} else {
response.statusCode = 500;
return { "error": "problem executing query", "query_result": r };
}
});
}
});

View File

@ -1,7 +1,7 @@
import { ArrayRelationInsertFieldValue, ColumnInsertFieldValue, DeleteMutationOperation, Expression, Field, InsertFieldSchema, InsertMutationOperation, MutationOperation, MutationOperationResults, MutationRequest, MutationResponse, ObjectRelationInsertFieldValue, QueryRequest, RowObject, RowUpdate, TableInsertSchema, TableName, TableRelationships, UpdateMutationOperation } from "@hasura/dc-api-types";
import { ArrayRelationInsertFieldValue, ColumnFieldValue, ColumnInsertFieldValue, DeleteMutationOperation, Expression, Field, InsertFieldSchema, InsertMutationOperation, MutationOperation, MutationOperationResults, MutationRequest, MutationResponse, NullColumnFieldValue, ObjectRelationInsertFieldValue, QueryRequest, QueryResponse, RowObject, RowUpdate, TableInsertSchema, TableName, TableRelationships, UpdateMutationOperation } from "@hasura/dc-api-types";
import { Config } from "./config";
import { Connection, defaultMode, SqlLogger, withConnection } from "./db";
import { escapeIdentifier, escapeTableName, escapeTableNameSansSchema, json_object, where_clause, } from "./query";
import { escapeIdentifier, escapeTableName, escapeTableNameSansSchema, json_object, parseRowFields, where_clause, } from "./query";
import { asyncSequenceFromInputs, ErrorWithStatusCode, mapObjectToArray, tableNameEquals, unreachable, zip } from "./util";
// Types
@ -256,11 +256,11 @@ async function mutationOperation(db: Connection, relationships: Array<TableRelat
const insertResultsSet = await asyncSequenceFromInputs(infos, (info) => insertRow(db, relationships, op, info));
const insertResults = ([] as Array<Row>).concat(...insertResultsSet);
let insertFailed: Array<Row> = [];
const mappedInsertResults = insertResults.map((e: Row) => {
if(! e.ok) {
insertFailed.push(e);
const mappedInsertResults = insertResults.map((row: Row) => {
if (!row.ok) {
insertFailed.push(row);
}
return JSON.parse(e.row);
return parseMutationResultRow(row, op.returning_fields ?? {});
});
if(insertFailed.length > 0) {
await db.query('ROLLBACK', {});
@ -279,11 +279,11 @@ async function mutationOperation(db: Connection, relationships: Array<TableRelat
const resultSet = await updateRow(db, relationships, op, updateInfo);
const updateResults = ([] as Array<Row>).concat(...resultSet);
let updateFailed: Array<Row> = [];
const mappedUpdateResults = updateResults.map((e: Row) => {
if(! e.ok) {
updateFailed.push(e);
const mappedUpdateResults = updateResults.map((row: Row) => {
if (!row.ok) {
updateFailed.push(row);
}
return JSON.parse(e.row);
return parseMutationResultRow(row, op.returning_fields ?? {});
});
if(updateFailed.length > 0) {
await db.query('ROLLBACK', {});
@ -299,7 +299,7 @@ async function mutationOperation(db: Connection, relationships: Array<TableRelat
case 'delete':
await db.query('BEGIN',{});
const deleteResults = await deleteRows(db, relationships, op);
const mappedDeleteResults = deleteResults.map((r: Row) => JSON.parse(r.row));
const mappedDeleteResults = deleteResults.map(row => parseMutationResultRow(row, op.returning_fields ?? {}));
await db.query('COMMIT',{});
return {
affected_rows: mappedDeleteResults.length,
@ -311,6 +311,11 @@ async function mutationOperation(db: Connection, relationships: Array<TableRelat
}
}
function parseMutationResultRow(e: Row, returningFields: Record<string, Field>): Record<string, (ColumnFieldValue | QueryResponse | NullColumnFieldValue)> {
const parsedRow = JSON.parse(e.row);
return parseRowFields(parsedRow, returningFields);
}
/**
* @param config
* @param sqlLogger

View File

@ -1,6 +1,6 @@
import { Config } from "./config";
import { connect, SqlLogger } from "./db";
import { coerceUndefinedToNull, coerceUndefinedOrNullToEmptyRecord, isEmptyObject, tableNameEquals, unreachable, stringArrayEquals, ErrorWithStatusCode } from "./util";
import { defaultMode, SqlLogger, withConnection } from "./db";
import { coerceUndefinedToNull, coerceUndefinedOrNullToEmptyRecord, isEmptyObject, tableNameEquals, unreachable, stringArrayEquals, ErrorWithStatusCode, mapObject } from "./util";
import {
Expression,
BinaryComparisonOperator,
@ -20,10 +20,12 @@ import {
UnaryComparisonOperator,
ExplainResponse,
ExistsExpression,
ErrorResponse,
OrderByRelation,
OrderByElement,
OrderByTarget,
Query,
ColumnFieldValue,
NullColumnFieldValue,
} from "@hasura/dc-api-types";
import { customAlphabet } from "nanoid";
import { DEBUGGING_TAGS, QUERY_LENGTH_LIMIT } from "./environment";
@ -665,8 +667,53 @@ function query(request: QueryRequest): string {
*
* Note: There should always be one result since 0 rows still generates an empty JSON array.
*/
function output(rows: any): QueryResponse {
return JSON.parse(rows[0].data);
function parseDbResult(rows: any, request: QueryRequest): QueryResponse {
const rawResponse = JSON.parse(rows[0].data);
return parseRawQueryResponse(request.query, rawResponse);
}
type RawQueryResponse = {
rows?: string[] | null,
aggregates?: Record<string, any> | null,
}
function parseRawQueryResponse(query: Query, rawQueryResponse: RawQueryResponse): QueryResponse {
const rows = query.fields
? (rawQueryResponse.rows ?? []).map(rowJson => {
const row: Record<string, (ColumnFieldValue | RawQueryResponse | NullColumnFieldValue)> = JSON.parse(rowJson);
return parseRowFields(row, query.fields ?? {});
})
: null;
return {
aggregates: rawQueryResponse.aggregates,
... (rows ? { rows } : {}),
}
}
// It seems that since SQLite 3.39.0, the JSON_GROUP_ARRAY function that is used to create the arrays
// for object/array relationships now string-encodes any JSON inside the array. This function works
// around the problem by decoding the stringified-JSON back into JSON.
// The issue has been raised here: https://sqlite.org/forum/forumpost/e3b101fb32
export function parseRowFields(row: Record<string, (ColumnFieldValue | RawQueryResponse | NullColumnFieldValue)>, fields: Record<string, Field>): Record<string, (ColumnFieldValue | QueryResponse | NullColumnFieldValue)> {
return mapObject(row, ([fieldName, fieldValue]) => {
const queryField = fields[fieldName];
if (queryField === undefined)
throw new Error(`Unable to find response field ${fieldName} on amongst original query fields`);
switch (queryField.type) {
case "column":
return [fieldName, fieldValue];
case "relationship":
if (fieldValue === null || (!("rows" in fieldValue) && !("aggregates" in fieldValue)))
throw new Error(`Did not find a query response in field ${fieldName} where one was expected`);
return [fieldName, parseRawQueryResponse(queryField.query, fieldValue)];
default:
return unreachable(queryField["type"]);
}
});
}
/** Function to add SQL comments to the generated SQL to tag which procedures generated what text.
@ -728,20 +775,21 @@ function tag(t: string, s: string): string {
*
*/
export async function queryData(config: Config, sqlLogger: SqlLogger, queryRequest: QueryRequest): Promise<QueryResponse> {
const db = connect(config, sqlLogger); // TODO: Should this be cached?
const q = query(queryRequest);
return await withConnection(config, defaultMode, sqlLogger, async db => {
const q = query(queryRequest);
if(q.length > QUERY_LENGTH_LIMIT) {
const error = new ErrorWithStatusCode(
`Generated SQL Query was too long (${q.length} > ${QUERY_LENGTH_LIMIT})`,
500,
{ "query.length": q.length, "limit": QUERY_LENGTH_LIMIT }
);
throw error;
}
if(q.length > QUERY_LENGTH_LIMIT) {
const error = new ErrorWithStatusCode(
`Generated SQL Query was too long (${q.length} > ${QUERY_LENGTH_LIMIT})`,
500,
{ "query.length": q.length, "limit": QUERY_LENGTH_LIMIT }
);
throw error;
}
const [result, metadata] = await db.query(q);
return output(result);
const results = await db.query(q);
return parseDbResult(results, queryRequest);
});
}
/**
@ -758,13 +806,14 @@ export async function queryData(config: Config, sqlLogger: SqlLogger, queryReque
* @returns
*/
export async function explain(config: Config, sqlLogger: SqlLogger, queryRequest: QueryRequest): Promise<ExplainResponse> {
const db = connect(config, sqlLogger);
const q = query(queryRequest);
const [result, metadata] = await db.query(`EXPLAIN QUERY PLAN ${q}`);
return {
query: q,
lines: [ "", ...formatExplainLines(result as AnalysisEntry[])]
}
return await withConnection(config, defaultMode, sqlLogger, async db => {
const q = query(queryRequest);
const result = await db.query(`EXPLAIN QUERY PLAN ${q}`);
return {
query: q,
lines: [ "", ...formatExplainLines(result as AnalysisEntry[])]
};
});
}
function formatExplainLines(items: AnalysisEntry[]): string[] {

View File

@ -1,12 +1,13 @@
import { Config } from "./config";
import { connect, SqlLogger } from './db';
import { withConnection, SqlLogger, defaultMode } from './db';
import { RawRequest, RawResponse } from '@hasura/dc-api-types';
export async function runRawOperation(config: Config, sqlLogger: SqlLogger, query: RawRequest): Promise<RawResponse> {
const db = connect(config, sqlLogger);
const [results, metadata] = await db.query(query.query);
return await withConnection(config, defaultMode, sqlLogger, async db => {
const results = await db.query(query.query);
return {
rows: (results || []) as Record<string, any>[]
};
return {
rows: (results || []) as Record<string, any>[]
};
});
};

View File

@ -1,7 +1,7 @@
import { SchemaResponse, ScalarType, ColumnInfo, TableInfo, Constraint } from "@hasura/dc-api-types"
import { SchemaResponse, ColumnInfo, TableInfo, Constraint } from "@hasura/dc-api-types"
import { ScalarTypeKey } from "./capabilities";
import { Config } from "./config";
import { connect, SqlLogger } from './db';
import { defaultMode, SqlLogger, withConnection } from './db';
import { MUTATIONS } from "./environment";
var sqliteParser = require('sqlite-parser');
@ -227,13 +227,14 @@ function getPrimaryKeyNames(ddl: any): string[] {
}
export async function getSchema(config: Config, sqlLogger: SqlLogger): Promise<SchemaResponse> {
const db = connect(config, sqlLogger);
const [results, metadata] = await db.query("SELECT * from sqlite_schema");
const resultsT: TableInfoInternal[] = results as TableInfoInternal[];
const filtered: TableInfoInternal[] = resultsT.filter(table => includeTable(config,table));
const result: TableInfo[] = filtered.map(formatTableInfo(config));
return await withConnection(config, defaultMode, sqlLogger, async db => {
const results = await db.query("SELECT * from sqlite_schema");
const resultsT: TableInfoInternal[] = results as TableInfoInternal[];
const filtered: TableInfoInternal[] = resultsT.filter(table => includeTable(config,table));
const result: TableInfo[] = filtered.map(formatTableInfo(config));
return {
tables: result
};
return {
tables: result
};
});
};