Avena Webapp API - v0.0.1
    Preparing search index...

    Interface ExportRunOptions

    interface ExportRunOptions {
        download?: (
            nats: NatsService,
            requestSubject: string,
            payload: ExportRequestPayload,
            options?: ExportStreamOptions,
        ) => Promise<ExportStreamResult>;
        onChunk?: (data: Uint8Array) => void | Promise<void>;
        onProgress?: (received: number) => void;
        onSummary?: (missingChannels: number[]) => void;
        openConnection: () => Promise<NatsService | null>;
        payload: ExportRequestPayload;
        signal: AbortSignal;
        subject: string;
    }
    Index

    Properties

    download?: (
        nats: NatsService,
        requestSubject: string,
        payload: ExportRequestPayload,
        options?: ExportStreamOptions,
    ) => Promise<ExportStreamResult>

    The download function; downloadExportViaNats unless a test replaces it.

    Type Declaration

      • (
            nats: NatsService,
            requestSubject: string,
            payload: ExportRequestPayload,
            options?: ExportStreamOptions,
        ): Promise<ExportStreamResult>
      • Requests a CSV export from an edge box's exporter and collects the streamed reply.

        Steps, in order:

        1. Creates a reply inbox and an ack inbox, and subscribes to the reply inbox.
        2. Publishes payload as JSON to requestSubject, with format: "csv" and ack_subject set to the ack inbox, and flushes.
        3. Reads reply messages. A NATS status message with code 503 means no exporter is subscribed to requestSubject (the box is offline or its exporter is not running), and the call rejects at once instead of waiting for the idle timeout. Otherwise the Avena-Export-Frame header names each frame; a message without the header counts as a chunk. Each chunk is copied and stored (or passed to options.onChunk, which is awaited), and then acknowledged by publishing an empty message to the ack inbox. meta and summary frames are parsed as JSON and kept. Frames with another name, or whose type field does not match the header, are ignored.
        4. On the complete frame, joins the stored parts into one Blob (an empty one when options.onChunk took the chunks) and resolves.

        If the call ends any other way after the request was sent (cancelled through options.signal, idle timeout, a bad frame, the subscription ending, or options.onChunk failing), it publishes a cancel message on the ack subject, with the header Avena-Export-Frame: cancel and the body {"type":"cancel"}, so the exporter stops instead of waiting for acks. No cancel is sent after an error frame or a NATS status reply, since the exporter has already stopped or never started.

        Chunks are folded into a Blob part every 8 MiB, so at most that much CSV sits in JavaScript memory at a time; the rest is held in the browser's Blob storage until the caller saves the result. With options.onChunk nothing is kept at all.

        Parameters

        Returns Promise<ExportStreamResult>

        Resolves to the assembled CSV, its file name, size and missing channels.

        If publishing fails, no exporter is listening on requestSubject, the server returns another error status, a non-chunk frame is not valid JSON, the exporter sends an error frame, no message arrives within the idle timeout, the reply subscription ends before a complete frame, options.onChunk throws (that error), or options.signal is aborted (an error named AbortError).

        const subject = archiveExportRequestSubject(config);
        const result = await downloadExportViaNats(nats, subject, {
        asset: 1001,
        channels: [8, 9],
        start: "2026-09-22T12:00:00Z",
        end: "2026-09-22T12:30:00Z",
        }, { onProgress: (bytes) => console.log(bytes) });
    onChunk?: (data: Uint8Array) => void | Promise<void>

    Takes each chunk as it arrives, before it is acknowledged, instead of the chunks being collected into the result's Blob (see ExportStreamOptions.onChunk).

    onProgress?: (received: number) => void

    Progress, summary and chunk callbacks, passed on to downloadExportViaNats.

    onSummary?: (missingChannels: number[]) => void
    openConnection: () => Promise<NatsService | null>

    Opens the export's connection; resolves to null when that fails.

    Request fields.

    signal: AbortSignal

    Cancels the export, including while the connection is being opened.

    subject: string

    Export request subject (archiveExportRequestSubject).