MCPcopy Index your code
hub / github.com/cameri/nostream / createFormatterTransform

Function createFormatterTransform

src/scripts/export-events.ts:229–256  ·  view source on GitHub ↗
(
  format: 'jsonl' | 'json',
  onExported: () => void,
)

Source from the content-addressed store, hash-verified

227})
228
229const 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
258export async function runExportEvents(args: string[] = process.argv.slice(2), options: ExportOptions = {}): Promise<number> {
259 const useStructuredFormat = Boolean(options.format)

Callers 1

runExportEventsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected