Skip to content

@graphty/graphty-element / extend / GraphExporter

Interface: GraphExporter<Opts> ​

Defined in: graph-io/dist/src/types.d.ts:382

A format's writer. Register one with registry.registerExporter() to make a format writable by every save function. Opts is the type of the format's own options.

Type Parameters ​

Opts ​

Opts = unknown

Properties ​

capabilities ​

readonly capabilities: ExportCapabilities

Defined in: graph-io/dist/src/types.d.ts:386

What the format can store exactly; build it with capabilities().


extensions? ​

readonly optional extensions?: readonly string[]

Defined in: graph-io/dist/src/types.d.ts:391

File extensions with the leading dot, most common first. Optional; listFormats() uses them when no importer is registered for the format (an export-only format).


format ​

readonly format: string

Defined in: graph-io/dist/src/types.d.ts:384

The name callers pass as format; the same as the importer's when the format has both.


mimeTypes? ​

readonly optional mimeTypes?: readonly string[]

Defined in: graph-io/dist/src/types.d.ts:393

MIME types, most specific first. Optional; used the same way as extensions.


options? ​

readonly optional options?: readonly string[]

Defined in: graph-io/dist/src/types.d.ts:399

The names of this format's own save options, when you want misspelled options reported. While every registered exporter lists its options, checkExport() returns a W_UNKNOWN_OPTION note for a name that no format and no save function takes. Leave it out to report nothing.

Methods ​

check() ​

check(snapshot, options?): readonly LossNote[]

Defined in: graph-io/dist/src/types.d.ts:409

What a save would lose, without writing anything; checkExport(snapshot, format, options) calls it. Start from checkCapabilities(snapshot, capabilities, resolveExportOptions(options)) and add a note for anything else your format changes. Every difference a re-import would show needs a note.

Parameters ​

snapshot ​

GraphSnapshot

the graph to check

options? ​

Opts & CommonExportOptions

the format's own options and the options every exporter takes

Returns ​

readonly LossNote[]

the loss notes, empty when the save is exact


export() ​

export(snapshot, options?): AsyncIterable<Uint8Array<ArrayBufferLike>>

Defined in: graph-io/dist/src/types.d.ts:418

Write the graph as byte chunks: UTF-8 text for a text format (encodeChunks() turns string parts into them), the raw bytes for a binary one. Throw a GraphFormatError before writing for every "E_" note check() returns.

Parameters ​

snapshot ​

GraphSnapshot

the graph to write

options? ​

Opts & CommonExportOptions

the format's own options and the options every exporter takes

Returns ​

AsyncIterable<Uint8Array<ArrayBufferLike>>

the file's bytes, chunk by chunk


exportToString() ​

exportToString(snapshot, options?): Promise<string>

Defined in: graph-io/dist/src/types.d.ts:426

Write the graph as one string (joinText() joins string parts). A binary format rejects with a GraphFormatError E_UNSUPPORTED (details.reason "binary") instead.

Parameters ​

snapshot ​

GraphSnapshot

the graph to write

options? ​

Opts & CommonExportOptions

the format's own options and the options every exporter takes

Returns ​

Promise<string>

the whole file