From 8fbf1312616fae077fc37d90edaf13e25a278dae Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Thu, 26 Aug 2021 18:09:31 -0500 Subject: [PATCH] perf: stream bundled OpenAPI file instead of sending it wholesale (#361) * perf: stream bundled OpenAPI file instead of sending it wholesale * chore: update default host URL --- config/default.js | 2 +- package-lock.json | 46 ++++++++++++++++++++++++++++++++++++++++----- package.json | 3 ++- src/cmds/openapi.js | 9 ++++++++- 4 files changed, 52 insertions(+), 8 deletions(-) diff --git a/config/default.js b/config/default.js index 8a2e85652..56410c1ff 100644 --- a/config/default.js +++ b/config/default.js @@ -1,6 +1,6 @@ module.exports = { // eslint-disable-next-line global-require cli: require('../package.json').name, - host: 'https://dash.readme.io', + host: 'https://dash.readme.com', hub: 'https://{project}.readme.io', }; diff --git a/package-lock.json b/package-lock.json index 6d5ff5095..38fa59f5e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { "name": "rdme", - "version": "5.0.0", + "version": "5.1.1", "lockfileVersion": 2, "requires": true, "packages": { "": { - "version": "5.0.0", + "version": "5.1.1", "license": "MIT", "dependencies": { "cli-table": "^0.3.1", @@ -26,7 +26,8 @@ "parse-link-header": "^1.0.1", "read": "^1.0.7", "semver": "^7.0.0", - "table-layout": "^1.0.0" + "table-layout": "^1.0.0", + "tmp-promise": "^3.0.2" }, "bin": { "rdme": "bin/rdme" @@ -12133,7 +12134,6 @@ "version": "3.0.2", "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", - "dev": true, "dependencies": { "glob": "^7.1.3" }, @@ -12957,6 +12957,25 @@ "node": ">=0.6.0" } }, + "node_modules/tmp-promise": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/tmp-promise/-/tmp-promise-3.0.2.tgz", + "integrity": "sha512-OyCLAKU1HzBjL6Ev3gxUeraJNlbNingmi8IrHHEsYH8LTmEuhvYfqvhn2F/je+mjf4N58UmZ96OMEy1JanSCpA==", + "dependencies": { + "tmp": "^0.2.0" + } + }, + "node_modules/tmp-promise/node_modules/tmp": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.2.1.tgz", + "integrity": "sha512-76SUhtfqR2Ijn+xllcI5P1oyannHNHByD80W1q447gU3mp9G9PSpGdWmjUOHRDPiHYacIk66W7ubDTuPF3BEtQ==", + "dependencies": { + "rimraf": "^3.0.0" + }, + "engines": { + "node": ">=8.17.0" + } + }, "node_modules/tmpl": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/tmpl/-/tmpl-1.0.4.tgz", @@ -22761,7 +22780,6 @@ "version": "3.0.2", "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", - "dev": true, "requires": { "glob": "^7.1.3" } @@ -23448,6 +23466,24 @@ "os-tmpdir": "~1.0.2" } }, + "tmp-promise": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/tmp-promise/-/tmp-promise-3.0.2.tgz", + "integrity": "sha512-OyCLAKU1HzBjL6Ev3gxUeraJNlbNingmi8IrHHEsYH8LTmEuhvYfqvhn2F/je+mjf4N58UmZ96OMEy1JanSCpA==", + "requires": { + "tmp": "^0.2.0" + }, + "dependencies": { + "tmp": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.2.1.tgz", + "integrity": "sha512-76SUhtfqR2Ijn+xllcI5P1oyannHNHByD80W1q447gU3mp9G9PSpGdWmjUOHRDPiHYacIk66W7ubDTuPF3BEtQ==", + "requires": { + "rimraf": "^3.0.0" + } + } + } + }, "tmpl": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/tmpl/-/tmpl-1.0.4.tgz", diff --git a/package.json b/package.json index 424545870..abb0e2636 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,8 @@ "parse-link-header": "^1.0.1", "read": "^1.0.7", "semver": "^7.0.0", - "table-layout": "^1.0.0" + "table-layout": "^1.0.0", + "tmp-promise": "^3.0.2" }, "devDependencies": { "@readme/eslint-config": "^6.0.0", diff --git a/src/cmds/openapi.js b/src/cmds/openapi.js index 982811061..fc37043c1 100644 --- a/src/cmds/openapi.js +++ b/src/cmds/openapi.js @@ -10,6 +10,7 @@ const { getProjectVersion } = require('../lib/versionSelect'); const fetch = require('node-fetch'); const FormData = require('form-data'); const parse = require('parse-link-header'); +const { file: tmpFile } = require('tmp-promise'); exports.command = 'openapi'; exports.usage = 'openapi [file] [options]'; @@ -117,8 +118,14 @@ exports.run = async function (opts) { return Promise.reject(err); }); + // Create a temporary file to write the bundled spec to, + // which we will then stream into the form data body + const { path } = await tmpFile({ prefix: 'rdme-openapi-', postfix: '.json' }); + await fs.writeFileSync(path, bundledSpec); + const stream = fs.createReadStream(path); + const formData = new FormData(); - formData.append('spec', bundledSpec); + formData.append('spec', stream); const options = { headers: cleanHeaders(key, {