@graphty/graphty-element / extend / GraphImporter
Interface: GraphImporter<Opts> ​
Defined in: graph-io/dist/src/types.d.ts:209
A format's reader. It reads the input once, from start to end, and adds each node, edge and attribute to a graph builder (GraphSink, which GraphBuilder from @graphty/graph-format implements); importGraph() then builds the snapshot. Register one with registry.registerImporter() to teach graph-io a new format. Opts is the type of the format's own options.
Type Parameters ​
Opts ​
Opts = unknown
Properties ​
extensions ​
readonlyextensions: readonlystring[]
Defined in: graph-io/dist/src/types.d.ts:213
File extensions with the leading dot, most common first; used to detect the format from a file name.
format ​
readonlyformat:string
Defined in: graph-io/dist/src/types.d.ts:211
The name callers pass as format, such as "graphml" or "csv"; lowercase, unique in a registry.
mimeTypes ​
readonlymimeTypes: readonlystring[]
Defined in: graph-io/dist/src/types.d.ts:215
MIME types the format is served as, most specific first; used to detect the format from a Content-Type.
options? ​
readonlyoptionaloptions?: readonlystring[]
Defined in: graph-io/dist/src/types.d.ts:221
The names of this format's own options (["separator"]), when you want misspelled options reported. While every registered importer lists its options, a load warns W_UNKNOWN_OPTION for a name that no format and no load function takes. Leave it out to report nothing.
Methods ​
import() ​
import(
input,sink,options?):Promise<ImporterReport>
Defined in: graph-io/dist/src/types.d.ts:239
Read input into sink. Record each problem in an ImportReportBuilder and skip the element; the builder throws ImportError once there are more errors than errorLimit.
Parameters ​
input ​
the text, bytes or stream to read
sink ​
the graph builder to add nodes, edges and attributes to
options? ​
Opts & CommonImportOptions
the format's own options and the options every importer takes
Returns ​
Promise<ImporterReport>
the import report (report.finish())
importAll()? ​
optionalimportAll(input,sinkFor,options?):Promise<ImporterReport[]>
Defined in: graph-io/dist/src/types.d.ts:250
Optional, for a format whose files can hold several graphs: read every graph, each into its own sink. importAllGraphs() calls it; with it, importGraph() also honors graphIndex and graphName by reading every graph and returning the chosen one. import() should read the first graph and warn W_MULTIPLE_GRAPHS with the number skipped.
Parameters ​
input ​
the text, bytes or stream to read
sinkFor ​
(index) => GraphSink
called once per graph, in document order, before that graph's first push
options? ​
Opts & CommonImportOptions
format-specific and common options
Returns ​
Promise<ImporterReport[]>
one report per graph, in document order
listGraphs()? ​
optionallistGraphs(input,options?):Promise<readonlyGraphListing[]>
Defined in: graph-io/dist/src/types.d.ts:260
Optional: list the graphs of a file without importing them, so a caller can offer a choice. listGraphs() calls it. An importer that has it must also honor graphIndex and graphName in import() itself (chooseGraph() resolves them); one without it lists nothing and the registry makes the choice through importAll().
Parameters ​
input ​
the text, bytes or stream to read
options? ​
Opts & CommonImportOptions
format-specific and common options
Returns ​
Promise<readonly GraphListing[]>
one listing per graph, in document order
sniff()? ​
optionalsniff(head):number
Defined in: graph-io/dist/src/types.d.ts:230
How sure you are that head, the first bytes of a file (up to SNIFF_HEAD_BYTES), is this format: 0 for no, up to 1 for certain. Below 0.5 counts as a weak guess, which loses to a file extension another format claims. Without this method the format is detected only by file name and MIME type.
Parameters ​
head ​
Uint8Array
the first bytes of the input
Returns ​
number
a confidence in 0..1