From add18c82c981c424494f0a7c66d5e171767d118b Mon Sep 17 00:00:00 2001 From: Yongseok Date: Thu, 21 Mar 2024 20:14:28 +0900 Subject: [PATCH] [#182] Support gRPC stream flowable [#177] Update minimum NodeJS version to Node@16 --- .github/workflows/main.yml | 2 +- lib/client/bounded-buffer-readable-stream.js | 53 +++++++++++++++++++ package-lock.json | 36 ++++++------- package.json | 6 +-- test/agent.test.js | 2 +- .../bounded-buffer-readable-stream.test.js | 8 +++ 6 files changed, 84 insertions(+), 23 deletions(-) create mode 100644 lib/client/bounded-buffer-readable-stream.js create mode 100644 test/client/bounded-buffer-readable-stream.test.js diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index bc45c4e3..8b2dc6a9 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -14,9 +14,9 @@ jobs: strategy: matrix: node_version: - - 14 - 16 - 18 + - 20 name: Node ${{ matrix.node_version }} on ubuntu-latest steps: diff --git a/lib/client/bounded-buffer-readable-stream.js b/lib/client/bounded-buffer-readable-stream.js new file mode 100644 index 00000000..60dcc624 --- /dev/null +++ b/lib/client/bounded-buffer-readable-stream.js @@ -0,0 +1,53 @@ +/** + * Pinpoint Node.js Agent + * Copyright 2021-present NAVER Corp. + * Apache License v2.0 + */ + +'use strict' + +const { Readable } = require('node:stream') + +class BoundedBufferReadableStream { + constructor(constructorOptions) { + this.buffer = [] + this.stopped = false + + const options = constructorOptions || {} + this.readable = new Readable(Object.assign({ + read() { + this.stopped = false + this.readStart() + } + }, options)) + } + + push(data) { + if (!data) { + return + } + + this.buffer.push(data) + this.readStart() + } + + end() { + this.readable.end() + } + + readStart() { + if (this.stopped) { + return + } + + const length = this.buffer.length + for (let index = 0; index < length; index++) { + if (this.readable.push(this.buffer.shift())) { + this.stopped = true + return + } + } + } +} + +module.exports = BoundedBufferReadableStream \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 4feebe50..7b33ce3c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "pinpoint-node-agent", - "version": "0.9.0-next.4", + "version": "1.0.0-next.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "pinpoint-node-agent", - "version": "0.9.0-next.4", + "version": "1.0.0-next.1", "license": "Apache-2.0", "dependencies": { "@grpc/grpc-js": "^1.2.3", @@ -22,7 +22,7 @@ "devDependencies": { "@types/semver": "^7.3.13", "@types/shimmer": "^1.0.2", - "axios": "^1.6.2", + "axios": "^1.6.8", "eslint": "^8.43.0", "eslint-config-prettier": "^3.6.0", "eslint-plugin-import": "^2.25.2", @@ -47,7 +47,7 @@ "typescript": "^4.8.3" }, "engines": { - "node": ">=14.0" + "node": ">=16.0" } }, "node_modules/@aashutoshrathi/word-wrap": { @@ -1171,12 +1171,12 @@ } }, "node_modules/axios": { - "version": "1.6.2", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.2.tgz", - "integrity": "sha512-7i24Ri4pmDRfJTR7LDBhsOTtcm+9kjX5WiY1X3wIisx6G9So3pfMkEiU7emUBe46oceVImccTEM3k6C5dbVW8A==", + "version": "1.6.8", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.8.tgz", + "integrity": "sha512-v/ZHtJDU39mDpyBoFVkETcd/uNdxrWRrg3bKpOKzXFA6Bvqopts6ALSMU3y6ijYxbw2B+wPrIv46egTzJXCLGQ==", "dev": true, "dependencies": { - "follow-redirects": "^1.15.0", + "follow-redirects": "^1.15.6", "form-data": "^4.0.0", "proxy-from-env": "^1.1.0" } @@ -3297,9 +3297,9 @@ } }, "node_modules/follow-redirects": { - "version": "1.15.5", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.5.tgz", - "integrity": "sha512-vSFWUON1B+yAw1VN4xMfxgn5fTUiaOzAJCKBwIIgT/+7CuGy9+r+5gITvP62j3RmaD5Ph65UaERdOSRGUzZtgw==", + "version": "1.15.6", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz", + "integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==", "dev": true, "funding": [ { @@ -8806,12 +8806,12 @@ "dev": true }, "axios": { - "version": "1.6.2", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.2.tgz", - "integrity": "sha512-7i24Ri4pmDRfJTR7LDBhsOTtcm+9kjX5WiY1X3wIisx6G9So3pfMkEiU7emUBe46oceVImccTEM3k6C5dbVW8A==", + "version": "1.6.8", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.8.tgz", + "integrity": "sha512-v/ZHtJDU39mDpyBoFVkETcd/uNdxrWRrg3bKpOKzXFA6Bvqopts6ALSMU3y6ijYxbw2B+wPrIv46egTzJXCLGQ==", "dev": true, "requires": { - "follow-redirects": "^1.15.0", + "follow-redirects": "^1.15.6", "form-data": "^4.0.0", "proxy-from-env": "^1.1.0" } @@ -10440,9 +10440,9 @@ "integrity": "sha512-PIaqOGvVH5P+R92Ywy5PumsNEHvondVQh42SGOmkA9A0ZTFbfguzZpjZ/Gy3WVRUqT9Ia8k5tWlJeiZQzRHA7g==" }, "follow-redirects": { - "version": "1.15.5", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.5.tgz", - "integrity": "sha512-vSFWUON1B+yAw1VN4xMfxgn5fTUiaOzAJCKBwIIgT/+7CuGy9+r+5gITvP62j3RmaD5Ph65UaERdOSRGUzZtgw==", + "version": "1.15.6", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz", + "integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==", "dev": true }, "for-each": { diff --git a/package.json b/package.json index 7185cfd4..066b46af 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pinpoint-node-agent", - "version": "0.9.0-next.4", + "version": "1.0.0-next.1", "main": "index.js", "types": "index.d.ts", "type": "commonjs", @@ -23,7 +23,7 @@ }, "homepage": "https://github.com/pinpoint-apm/pinpoint-node-agent", "engines": { - "node": ">=14.0" + "node": ">=16.0" }, "keywords": [ "pinpoint", @@ -64,7 +64,7 @@ "devDependencies": { "@types/semver": "^7.3.13", "@types/shimmer": "^1.0.2", - "axios": "^1.6.2", + "axios": "^1.6.8", "eslint": "^8.43.0", "eslint-config-prettier": "^3.6.0", "eslint-plugin-import": "^2.25.2", diff --git a/test/agent.test.js b/test/agent.test.js index 21f66879..92bce2a0 100644 --- a/test/agent.test.js +++ b/test/agent.test.js @@ -14,5 +14,5 @@ test('Should initialize agent', function (t) { const agent = require('./support/agent-singleton-mock') t.ok(agent) - t.equal(agent.pinpointClient.agentInfo.agentVersion, '0.9.0-next.4', 'agent version from package.json') + t.equal(agent.pinpointClient.agentInfo.agentVersion, '1.0.0-next.1', 'agent version from package.json') }) \ No newline at end of file diff --git a/test/client/bounded-buffer-readable-stream.test.js b/test/client/bounded-buffer-readable-stream.test.js new file mode 100644 index 00000000..0f9eccda --- /dev/null +++ b/test/client/bounded-buffer-readable-stream.test.js @@ -0,0 +1,8 @@ +/** + * Pinpoint Node.js Agent + * Copyright 2020-present NAVER Corp. + * Apache License v2.0 + */ + +const test = require('tape') +