groq-cli icon indicating copy to clipboard operation
groq-cli copied to clipboard

`TypeError` when using `-n` CLI flag

Open azaxarov opened this issue 10 months ago • 1 comments

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'
  }
}

azaxarov avatar Apr 12 '24 11:04 azaxarov

+1 We are experiencing this issue.

tabuchid avatar Apr 12 '24 13:04 tabuchid

Thanks for reporting! Just published [email protected] which should handle ndjson correctly

sgulseth avatar May 14 '24 12:05 sgulseth