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

Function runExportEvents

src/scripts/export-events.ts:258–418  ·  view source on GitHub ↗
(args: string[] = process.argv.slice(2), options: ExportOptions = {})

Source from the content-addressed store, hash-verified

256}
257
258export async function runExportEvents(args: string[] = process.argv.slice(2), options: ExportOptions = {}): Promise<number> {
259 const useStructuredFormat = Boolean(options.format)
260 const structuredFormat = resolveExportFormat(options.format)
261 const cliOptions = useStructuredFormat ? undefined : parseCliArgs(args)
262
263 if (!useStructuredFormat && cliOptions?.showHelp) {
264 printUsage()
265 return 0
266 }
267
268 const outputPath = useStructuredFormat
269 ? resolveOutputPath(args[0], structuredFormat)
270 : path.resolve(cliOptions?.outputFilePath ?? DEFAULT_OUTPUT_FILE_PATH)
271
272 const db = getMasterDbClient()
273 const abortController = new AbortController()
274 let interruptedBySignal: NodeJS.Signals | undefined
275
276 const onSignal = (signal: NodeJS.Signals) => {
277 if (abortController.signal.aborted) {
278 return
279 }
280
281 interruptedBySignal = signal
282 process.exitCode = 130
283 console.log(`${signal} received. Stopping export...`)
284 abortController.abort()
285 }
286
287 process.on('SIGINT', onSignal).on('SIGTERM', onSignal)
288
289 try {
290 const firstEvent = await db('events').select('event_id').whereNull('deleted_at').first()
291
292 if (abortController.signal.aborted) {
293 return 130
294 }
295
296 if (!firstEvent) {
297 if (options.json) {
298 console.log(JSON.stringify({ exported: 0, outputPath, empty: true }, null, 2))
299 } else {
300 console.log('No events to export.')
301 }
302 return 0
303 }
304
305 if (useStructuredFormat) {
306 console.log(`Exporting events to ${outputPath}`)
307 } else if (cliOptions?.format) {
308 console.log(`Exporting events to ${outputPath} using ${getCompressionLabel(cliOptions.format)} compression`)
309 } else {
310 console.log(`Exporting events to ${outputPath}`)
311 }
312
313 const startedAt = Date.now()
314 const output = fs.createWriteStream(outputPath)
315

Callers 3

export.spec.tsFile · 0.90
runExportFunction · 0.90
export-events.tsFile · 0.85

Calls 13

getMasterDbClientFunction · 0.90
createCompressionStreamFunction · 0.90
resolveExportFormatFunction · 0.85
resolveOutputPathFunction · 0.85
getCompressionLabelFunction · 0.85
createFormatterTransformFunction · 0.85
formatCompressionDeltaFunction · 0.85
getRatePerSecondFunction · 0.85
formatBytesFunction · 0.85
formatCountFunction · 0.85
streamMethod · 0.80
parseCliArgsFunction · 0.70

Tested by

no test coverage detected