| 227 | }) |
| 228 | |
| 229 | const createFormatterTransform = ( |
| 230 | format: 'jsonl' | 'json', |
| 231 | onExported: () => void, |
| 232 | ): Transform => { |
| 233 | if (format === 'jsonl') { |
| 234 | return new Transform({ |
| 235 | objectMode: true, |
| 236 | transform(row: EventRow, _encoding, callback) { |
| 237 | onExported() |
| 238 | callback(null, JSON.stringify(toEvent(row)) + '\n') |
| 239 | }, |
| 240 | }) |
| 241 | } |
| 242 | |
| 243 | let hasRows = false |
| 244 | return new Transform({ |
| 245 | objectMode: true, |
| 246 | transform(row: EventRow, _encoding, callback) { |
| 247 | const prefix = hasRows ? ',\n' : '[\n' |
| 248 | hasRows = true |
| 249 | onExported() |
| 250 | callback(null, prefix + JSON.stringify(toEvent(row))) |
| 251 | }, |
| 252 | flush(callback) { |
| 253 | callback(null, hasRows ? '\n]\n' : '[]\n') |
| 254 | }, |
| 255 | }) |
| 256 | } |
| 257 | |
| 258 | export async function runExportEvents(args: string[] = process.argv.slice(2), options: ExportOptions = {}): Promise<number> { |
| 259 | const useStructuredFormat = Boolean(options.format) |