groq-cli
groq-cli copied to clipboard
`TypeError` when using `-n` CLI flag
When using -n
CLI flag, the following error is thrown: TypeError: ndjson is not a function
This regression likely happened after upgrading ndjson
package from version 1.x.x
to version 2.x.x
, where the API of the package changed. The error takes place in the following two places:
https://github.com/sanity-io/groq-cli/blob/c726590f441214092ee37c3ec1adb2f256cb36a6/src/cli.js#L132
https://github.com/sanity-io/groq-cli/blob/c726590f441214092ee37c3ec1adb2f256cb36a6/src/cli.js#L108
In order to fix this issue, update inputNDJSON
and outputNDJSON
functions. Consider using the following implementations:
function inputNDJSON() {
const dataset = new S2A(process.stdin.pipe(ndjson.parse()))
return {dataset}
}
async function* outputNDJSON(result) {
const value = await result.get()
if (Array.isArray(value)) {
for await (const row of value) {
yield JSON.stringify(row)
yield '\n'
}
} else {
yield JSON.stringify(value)
yield '\n'
}
}
+1 We are experiencing this issue.
Thanks for reporting! Just published [email protected]
which should handle ndjson correctly