From 3c198c236001dd3a1032f5ddf76a3f61552a59db Mon Sep 17 00:00:00 2001 From: Reid Miller Date: Thu, 29 Jun 2023 20:06:56 -0400 Subject: [PATCH] Modifies jsonEncodingStream to construct an array Currently, when using a command like: node ./dist/index.js get locations Multiple items are output as: { "foo": "bar1"} { "foo": "bar2"} This is not a syntactically valid array. When piped to jq, as suggested by the README, something as simple as the following throws an error: node ./dist/index.js get locations | jq . This is due to the array syntax error. The output should be: [{ "foo": "bar1"} ,{ "foo": "bar2"}] This commit modifies the jsonEncodingStream to construct a syntactically valid array. --- src/commands/get.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/commands/get.ts b/src/commands/get.ts index 25b2cae..317d27e 100644 --- a/src/commands/get.ts +++ b/src/commands/get.ts @@ -68,10 +68,20 @@ export const get = async (moduleName: string, privacyPass?: string) => { const jsonEncodingStream = new Transform({ writableObjectMode: true, + construct(callback) { + this.push("["); + callback(); + }, transform(chunk, encoding, callback) { + this.emit("append_item"); this.push(JSON.stringify(chunk)); + this.once("append_item", () => { this.push(",") }); callback(); }, + flush(callback) { + this.push("]"); + callback(); + } }); try {