Connected service from "nats.svelte"!connect.
Export request subject, e.g. from
subjects!archiveExportRequestSubject:
avenars.<site>.<box>.<source>.export.request.
Request fields. format is overwritten with csv.
Progress callbacks, chunk consumer, idle timeout and abort signal.
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).
Requests a CSV export from an edge box's exporter and collects the streamed reply.
Steps, in order:
payloadas JSON torequestSubject, withformat: "csv"andack_subjectset to the ack inbox, and flushes.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 theAvena-Export-Frameheader names each frame; a message without the header counts as achunk. Each chunk is copied and stored (or passed tooptions.onChunk, which is awaited), and then acknowledged by publishing an empty message to the ack inbox.metaandsummaryframes are parsed as JSON and kept. Frames with another name, or whosetypefield does not match the header, are ignored.completeframe, joins the stored parts into one Blob (an empty one whenoptions.onChunktook 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, oroptions.onChunkfailing), it publishes acancelmessage on the ack subject, with the headerAvena-Export-Frame: canceland the body{"type":"cancel"}, so the exporter stops instead of waiting for acks. No cancel is sent after anerrorframe 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.onChunknothing is kept at all.