@graphty/graph-io 0.3.18 → 0.3.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -2
- package/dist/chunks/{escape-D-gZWO26.js → escape-CWExcecC.js} +3 -3
- package/dist/chunks/{escape-D-gZWO26.js.map → escape-CWExcecC.js.map} +1 -1
- package/dist/chunks/exporter-CbMZyVt-.js +735 -0
- package/dist/chunks/exporter-CbMZyVt-.js.map +1 -0
- package/dist/chunks/importer-BAP4PrxR.js +2194 -0
- package/dist/chunks/importer-BAP4PrxR.js.map +1 -0
- package/dist/chunks/{importer-Br_QeAeE.js → importer-BNFuV1-K.js} +5 -4
- package/dist/chunks/{importer-Br_QeAeE.js.map → importer-BNFuV1-K.js.map} +1 -1
- package/dist/chunks/{importer-d0uQxFp6.js → importer-BVGtU1NA.js} +5 -4
- package/dist/chunks/{importer-d0uQxFp6.js.map → importer-BVGtU1NA.js.map} +1 -1
- package/dist/chunks/{importer-DHagxvDD.js → importer-BW-Ft2ps.js} +5 -4
- package/dist/chunks/{importer-DHagxvDD.js.map → importer-BW-Ft2ps.js.map} +1 -1
- package/dist/chunks/{importer-Du5crN9l.js → importer-Bm1_5vPS.js} +275 -82
- package/dist/chunks/importer-Bm1_5vPS.js.map +1 -0
- package/dist/chunks/{importer-aNJfe0qu.js → importer-ByPGO-09.js} +2 -2
- package/dist/chunks/{importer-aNJfe0qu.js.map → importer-ByPGO-09.js.map} +1 -1
- package/dist/chunks/importer-DOepkgnG.js +1713 -0
- package/dist/chunks/importer-DOepkgnG.js.map +1 -0
- package/dist/chunks/json-elements-CZY1wiZh.js +779 -0
- package/dist/chunks/json-elements-CZY1wiZh.js.map +1 -0
- package/dist/chunks/{records-Bk9jgodz.js → records-BzNicMsf.js} +2 -2
- package/dist/chunks/{records-Bk9jgodz.js.map → records-BzNicMsf.js.map} +1 -1
- package/dist/chunks/{report-BOk0p5y8.js → report-BcWboivV.js} +95 -95
- package/dist/chunks/{report-BOk0p5y8.js.map → report-BcWboivV.js.map} +1 -1
- package/dist/chunks/weights-CwISIpCP.js +176 -0
- package/dist/chunks/weights-CwISIpCP.js.map +1 -0
- package/dist/chunks/{writer-GAdltGmC.js → writer-DQiKgQJc.js} +8 -179
- package/dist/chunks/writer-DQiKgQJc.js.map +1 -0
- package/dist/csv.js +5 -4
- package/dist/csv.js.map +1 -1
- package/dist/cx.d.ts +1 -0
- package/dist/cx.js +6 -0
- package/dist/cx.js.map +1 -0
- package/dist/cx2.d.ts +1 -0
- package/dist/cx2.js +10 -0
- package/dist/cx2.js.map +1 -0
- package/dist/dot.js +1 -1
- package/dist/gexf.js +15 -4
- package/dist/gexf.js.map +1 -1
- package/dist/gml.js +5 -4
- package/dist/gml.js.map +1 -1
- package/dist/graph-io.js +145 -389
- package/dist/graph-io.js.map +1 -1
- package/dist/graphml.js +1 -1
- package/dist/json.js +1 -1
- package/dist/neo4j.js +5 -4
- package/dist/neo4j.js.map +1 -1
- package/dist/obo.js +1 -1
- package/dist/pajek.js +1 -1
- package/dist/src/common/json-elements.d.ts +286 -0
- package/dist/src/common/json-elements.d.ts.map +1 -0
- package/dist/src/common/json-elements.js +926 -0
- package/dist/src/common/json-elements.js.map +1 -0
- package/dist/src/formats/cx/importer.d.ts +133 -0
- package/dist/src/formats/cx/importer.d.ts.map +1 -0
- package/dist/src/formats/cx/importer.js +2220 -0
- package/dist/src/formats/cx/importer.js.map +1 -0
- package/dist/src/formats/cx/index.d.ts +7 -0
- package/dist/src/formats/cx/index.d.ts.map +1 -0
- package/dist/src/formats/cx/index.js +7 -0
- package/dist/src/formats/cx/index.js.map +1 -0
- package/dist/src/formats/cx2/exporter.d.ts +59 -0
- package/dist/src/formats/cx2/exporter.d.ts.map +1 -0
- package/dist/src/formats/cx2/exporter.js +864 -0
- package/dist/src/formats/cx2/exporter.js.map +1 -0
- package/dist/src/formats/cx2/importer.d.ts +169 -0
- package/dist/src/formats/cx2/importer.d.ts.map +1 -0
- package/dist/src/formats/cx2/importer.js +1652 -0
- package/dist/src/formats/cx2/importer.js.map +1 -0
- package/dist/src/formats/cx2/index.d.ts +7 -0
- package/dist/src/formats/cx2/index.d.ts.map +1 -0
- package/dist/src/formats/cx2/index.js +7 -0
- package/dist/src/formats/cx2/index.js.map +1 -0
- package/dist/src/formats/gexf/exporter.d.ts +2 -0
- package/dist/src/formats/gexf/exporter.d.ts.map +1 -1
- package/dist/src/formats/gexf/exporter.js +6 -0
- package/dist/src/formats/gexf/exporter.js.map +1 -1
- package/dist/src/formats/gexf/importer.d.ts +2 -4
- package/dist/src/formats/gexf/importer.d.ts.map +1 -1
- package/dist/src/formats/gexf/importer.js +2 -4
- package/dist/src/formats/gexf/importer.js.map +1 -1
- package/dist/src/formats/gexf/index.d.ts +1 -1
- package/dist/src/formats/gexf/index.js +2 -2
- package/dist/src/formats/gexf/index.js.map +1 -1
- package/dist/src/formats/gml/exporter.js +1 -1
- package/dist/src/formats/gml/exporter.js.map +1 -1
- package/dist/src/formats/json/importer.d.ts.map +1 -1
- package/dist/src/formats/json/importer.js +6 -104
- package/dist/src/formats/json/importer.js.map +1 -1
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/registry.d.ts.map +1 -1
- package/dist/src/registry.js +5 -0
- package/dist/src/registry.js.map +1 -1
- package/dist/src/sniff.d.ts +1 -1
- package/dist/src/sniff.d.ts.map +1 -1
- package/dist/src/sniff.js +2 -0
- package/dist/src/sniff.js.map +1 -1
- package/package.json +11 -1
- package/src/common/json-elements.ts +1147 -0
- package/src/formats/cx/importer.ts +2733 -0
- package/src/formats/cx/index.ts +7 -0
- package/src/formats/cx2/exporter.ts +1036 -0
- package/src/formats/cx2/importer.ts +2187 -0
- package/src/formats/cx2/index.ts +7 -0
- package/src/formats/gexf/exporter.ts +11 -0
- package/src/formats/gexf/importer.ts +2 -2
- package/src/formats/gexf/index.ts +1 -1
- package/src/formats/gml/exporter.ts +1 -1
- package/src/formats/json/importer.ts +6 -105
- package/src/index.ts +10 -0
- package/src/registry.ts +5 -0
- package/src/sniff.ts +14 -1
- package/dist/chunks/importer-Du5crN9l.js.map +0 -1
- package/dist/chunks/writer-GAdltGmC.js.map +0 -1
package/dist/graph-io.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graph-io.js","sources":["../src/sniff.ts","../src/registry.ts"],"sourcesContent":["/**\n * Format detection (design sections 8.2 and 13.1: the registry's `sniff()`, the successor of\n * graphty-element's `format-detection.ts`): which of the registered importers a file is for, from\n * any combination of a filename (its extension), a MIME type and the first bytes of the content.\n *\n * Every importer declares `extensions`, `mimeTypes` and a `sniff(head)` content confidence in\n * 0..1 (design section 8.4); this module combines them into one ranked answer so that content\n * always beats a hint: a `.csv` whose first line is a neo4j-admin header is Neo4j, a `.xml` is\n * GEXF or GraphML by its root element, a `.txt` holding `graph [` is GML. The confidence of a\n * candidate is\n *\n * - `0.5 + 0.35 * content + 0.1 * [extension matches] + 0.05 * [MIME type matches]` when the\n * importer recognises the content (`content > 0`), so a content match always scores at least\n * 0.5 and at most 1;\n * - `0.3 * [extension matches] + 0.1 * [MIME type matches]` when the content is absent or the\n * importer rejects it, so a hint alone never reaches 0.5;\n * - nothing (the format is not a candidate) otherwise.\n *\n * Ties are broken by the order the importers were registered in, which is why the default\n * registry lists the common formats first. The JSON dialect is sniffed from the head as a hint\n * (the importer's detection on the parsed document is authoritative, design section 8.2).\n */\n\nimport { type JsonImportDialect, sniffJsonDialect } from \"./formats/json/dialect.js\";\nimport { type GraphImporter } from \"./types.js\";\n\n/** The format names of the eight built-in importers and exporters. */\nexport type GraphFormatName = \"gexf\" | \"graphml\" | \"gml\" | \"dot\" | \"pajek\" | \"csv\" | \"json\" | \"neo4j\" | \"obo\";\n\n/**\n * The built-in format names in the default registry's order, which is also the tie-break order of\n * sniffing: the more common format wins an extension two formats claim (`.xml` GraphML before GEXF,\n * `.csv` CSV before Neo4j) when the content does not decide.\n */\nexport const GRAPH_FORMATS: readonly GraphFormatName[] = Object.freeze([\n \"json\",\n \"graphml\",\n \"gexf\",\n \"csv\",\n \"gml\",\n \"dot\",\n \"pajek\",\n \"neo4j\",\n \"obo\",\n]);\n\n/** How many bytes of the input the sniffers look at; the registry reads no more than this before deciding. */\nexport const SNIFF_HEAD_BYTES = 8192;\n\n/** What is known about an input before it is read. */\nexport interface SniffHints {\n /** A file name or path; only its extension is used. */\n readonly filename?: string | null | undefined;\n /** A MIME type, with or without parameters (`text/csv; charset=utf-8`). */\n readonly mimeType?: string | null | undefined;\n /** The first bytes (or characters) of the content. */\n readonly head?: Uint8Array | string | null | undefined;\n}\n\n/** One ranked candidate of a sniff. */\nexport interface SniffResult {\n /** The importer's format name. */\n readonly format: string;\n /** The combined confidence in 0..1 (at least 0.5 when the content was recognised). */\n readonly confidence: number;\n /** The importer's own content confidence, 0 when no head was given or it rejected the head. */\n readonly content: number;\n /** Whether the filename's extension is one the importer claims. */\n readonly extension: boolean;\n /** Whether the MIME type is one the importer claims. */\n readonly mimeType: boolean;\n /** For the JSON format: the dialect the head suggests, or null when unknown; always null for other formats. */\n readonly dialect: JsonImportDialect | null;\n}\n\n/**\n * The lower-cased extension of a file name or path, with its dot.\n * @param filename - the name or path\n * @returns the extension (`.gexf`), or null when the name has none\n */\nexport function extensionOf(filename: string): string | null {\n const base = filename.slice(Math.max(filename.lastIndexOf(\"/\"), filename.lastIndexOf(\"\\\\\")) + 1);\n const dot = base.lastIndexOf(\".\");\n if (dot <= 0 || dot === base.length - 1) {\n return null;\n }\n return base.slice(dot).toLowerCase();\n}\n\n/**\n * A MIME type without parameters, lower-cased, for comparison with an importer's list.\n * @param mimeType - the type as received (`Text/CSV; charset=utf-8`)\n * @returns the bare type (`text/csv`)\n */\nexport function normalizeMimeType(mimeType: string): string {\n const semicolon = mimeType.indexOf(\";\");\n return (semicolon < 0 ? mimeType : mimeType.slice(0, semicolon)).trim().toLowerCase();\n}\n\n/**\n * The head as bytes for the importers' sniff functions: at most SNIFF_HEAD_BYTES, a string\n * encoded as UTF-8, a UTF-16 head with a byte order mark transcoded to UTF-8.\n * @param head - the head as given\n * @returns the bytes\n */\nexport function headBytes(head: Uint8Array | string): Uint8Array {\n if (typeof head === \"string\") {\n return new TextEncoder().encode(head.slice(0, SNIFF_HEAD_BYTES)).subarray(0, SNIFF_HEAD_BYTES);\n }\n if (head.byteLength >= 2 && ((head[0] === 0xff && head[1] === 0xfe) || (head[0] === 0xfe && head[1] === 0xff))) {\n // UTF-16 with a BOM (Excel's \"Unicode text\"): the sniffers read UTF-8, so transcode the head\n const encoding = head[0] === 0xff ? \"utf-16le\" : \"utf-16be\";\n return headBytes(new TextDecoder(encoding).decode(head.subarray(0, SNIFF_HEAD_BYTES)));\n }\n return head.byteLength > SNIFF_HEAD_BYTES ? head.subarray(0, SNIFF_HEAD_BYTES) : head;\n}\n\n/**\n * Rank the registered importers for an input by the rule of the module comment: every importer\n * whose content confidence is positive or whose extension / MIME type matches is a candidate,\n * ordered by confidence (ties in registration order).\n * @param hints - what is known about the input\n * @param importers - the registered importers, in registration order\n * @returns the candidates, best first; empty when nothing matches\n */\nexport function rankFormats(hints: SniffHints, importers: Iterable<GraphImporter>): readonly SniffResult[] {\n const extension = typeof hints.filename === \"string\" ? extensionOf(hints.filename) : null;\n const mime = typeof hints.mimeType === \"string\" ? normalizeMimeType(hints.mimeType) : null;\n const head = hints.head === undefined || hints.head === null ? null : headBytes(hints.head);\n const candidates: { readonly result: SniffResult; readonly rank: number }[] = [];\n let rank = 0;\n for (const importer of importers) {\n const extensionMatch = extension !== null && importer.extensions.some((e) => e.toLowerCase() === extension);\n const mimeMatch = mime !== null && importer.mimeTypes.some((m) => m.toLowerCase() === mime);\n let content = 0;\n if (head !== null && head.byteLength > 0 && typeof importer.sniff === \"function\") {\n content = clamp(importer.sniff(head));\n }\n let confidence: number;\n if (content > 0) {\n confidence = 0.5 + 0.35 * content + (extensionMatch ? 0.1 : 0) + (mimeMatch ? 0.05 : 0);\n } else if (extensionMatch || mimeMatch) {\n confidence = (extensionMatch ? 0.3 : 0) + (mimeMatch ? 0.1 : 0);\n } else {\n continue;\n }\n const dialect = importer.format === \"json\" && head !== null ? sniffJsonDialectHead(head) : null;\n const result: SniffResult = Object.freeze({\n format: importer.format,\n confidence: Math.min(1, confidence),\n content,\n extension: extensionMatch,\n mimeType: mimeMatch,\n dialect,\n });\n candidates.push({ result, rank: rank++ });\n }\n candidates.sort((a, b) => b.result.confidence - a.result.confidence || a.rank - b.rank);\n return candidates.map((c) => c.result);\n}\n\n/**\n * The best candidate of rankFormats(), or null when no importer matches.\n * @param hints - what is known about the input\n * @param importers - the registered importers, in registration order\n * @returns the best candidate, or null\n */\nexport function sniffFormat(hints: SniffHints, importers: Iterable<GraphImporter>): SniffResult | null {\n const ranked = rankFormats(hints, importers);\n return ranked.length > 0 ? ranked[0] : null;\n}\n\n/**\n * The JSON dialect a head suggests. A head that parses as a whole document is classified exactly\n * (sniffJsonDialect); a truncated head is scanned for its top-level keys, the keys of `graph` and\n * `options`, and the keys of the first object under `nodes` / `edges` / `links`, and the same\n * rule is applied to that skeleton. The result is a hint: the importer decides on the parsed\n * document.\n * @param head - the first bytes or characters of the document\n * @returns the dialect, or null when the head is not a JSON graph document\n */\nexport function sniffJsonDialectHead(head: Uint8Array | string): JsonImportDialect | null {\n const text = typeof head === \"string\" ? head : new TextDecoder(\"utf-8\", { fatal: false }).decode(head);\n const body = text.charCodeAt(0) === 0xfeff ? text.slice(1) : text;\n const trimmed = body.trimStart();\n if (!trimmed.startsWith(\"{\") && !trimmed.startsWith(\"[\")) {\n return null;\n }\n let root: unknown;\n try {\n root = JSON.parse(trimmed);\n } catch {\n root = skeletonOf(trimmed);\n }\n return sniffJsonDialect(root);\n}\n\n/** Where a key was seen while scanning a truncated head. */\ntype KeyPath =\n | \"\"\n | \"graph\"\n | \"options\"\n | \"nodes[0]\"\n | \"edges[0]\"\n | \"links[0]\"\n | \"graphs[0].nodes[]\"\n | \"graphs[0].edges[]\";\n\n/**\n * A partial document rebuilt from the keys a truncated head reveals: every key gets a placeholder\n * value of the shape the dialect rule tests for (an object for `graph`, `options`, `attributes`\n * and `data`, an array holding the first element's skeleton for `nodes` / `edges` / `links` /\n * `graphs`, `true` otherwise), so sniffJsonDialect() can classify it.\n * @param text - the head, starting with `{` or `[`\n * @returns the skeleton, or null when the scan finds no key at all\n */\nfunction skeletonOf(text: string): unknown {\n const keys = scanKeys(text);\n if (text.startsWith(\"[\")) {\n // a cut array whose first element has not been seen tells nothing (a whole `[]` is Cytoscape)\n const first = keys.get(\"nodes[0]\");\n return first === undefined ? null : [objectOf(first)];\n }\n const rootKeys = keys.get(\"\");\n if (rootKeys === undefined) {\n return null;\n }\n const root: Record<string, unknown> = {};\n for (const key of rootKeys) {\n switch (key) {\n case \"graph\":\n case \"options\":\n root[key] = objectOf(keys.get(key));\n break;\n case \"graphs\": {\n // the keys of any node or edge of the first graph: OBO Graphs or JGF (design 1.6)\n const nodes = keys.get(\"graphs[0].nodes[]\");\n const edges = keys.get(\"graphs[0].edges[]\");\n const graph: Record<string, unknown> = {};\n if (nodes !== undefined) {\n graph.nodes = [objectOf(nodes)];\n }\n if (edges !== undefined) {\n graph.edges = [objectOf(edges)];\n }\n root[key] = nodes === undefined && edges === undefined ? [] : [graph];\n break;\n }\n case \"nodes\":\n case \"edges\":\n case \"links\": {\n const first = keys.get(`${key}[0]`);\n root[key] = first === undefined ? [] : [objectOf(first)];\n break;\n }\n default:\n root[key] = true;\n break;\n }\n }\n return root;\n}\n\n/**\n * An object holding placeholder values for a key set: `{}` for the keys the rule tests with\n * isJsonObject (`attributes`, `data`), `true` otherwise.\n * @param names - the keys, possibly undefined\n * @returns the object\n */\nfunction objectOf(names: ReadonlySet<string> | undefined): Record<string, unknown> {\n const out: Record<string, unknown> = {};\n if (names !== undefined) {\n for (const name of names) {\n out[name] = name === \"attributes\" || name === \"data\" ? {} : true;\n }\n }\n return out;\n}\n\n/**\n * Scan a (possibly truncated) JSON text for the keys at the paths the dialect rule reads. The\n * scanner tracks a container stack (the key each object sits under, the index of each array\n * element) and records a key when it is at one of the watched paths; a head cut inside a string\n * or a number simply ends the scan. For a top-level array the first element's keys are recorded\n * under `nodes[0]`; the keys of every node and edge of `graphs[0]` under `graphs[0].nodes[]` and\n * `graphs[0].edges[]`.\n * @param text - the head, starting with `{` or `[`\n * @returns key sets by path\n */\nfunction scanKeys(text: string): Map<KeyPath, Set<string>> {\n const found = new Map<KeyPath, Set<string>>();\n // one frame per open container: its kind, the key or index it sits under, and the element index\n const kinds: (\"object\" | \"array\")[] = [];\n const labels: string[] = [];\n const counts: number[] = [];\n let pendingKey: string | null = null;\n let expectingKey = false;\n const pathOf = (): KeyPath | null => {\n const depth = kinds.length;\n if (depth === 1) {\n return kinds[0] === \"object\" ? \"\" : null;\n }\n if (depth === 2 && kinds[0] === \"array\" && kinds[1] === \"object\" && labels[1] === \"0\") {\n return \"nodes[0]\";\n }\n if (depth === 2 && kinds[0] === \"object\" && kinds[1] === \"object\") {\n return labels[1] === \"graph\" || labels[1] === \"options\" ? labels[1] : null;\n }\n if (\n depth === 5 &&\n kinds.join() === \"object,array,object,array,object\" &&\n labels[1] === \"graphs\" &&\n labels[2] === \"0\" &&\n (labels[3] === \"nodes\" || labels[3] === \"edges\")\n ) {\n return labels[3] === \"nodes\" ? \"graphs[0].nodes[]\" : \"graphs[0].edges[]\";\n }\n if (depth === 3 && kinds[0] === \"object\" && kinds[1] === \"array\" && kinds[2] === \"object\") {\n const section = labels[1];\n if ((section === \"nodes\" || section === \"edges\" || section === \"links\") && labels[2] === \"0\") {\n return `${section}[0]`;\n }\n }\n return null;\n };\n let i = 0;\n const n = text.length;\n while (i < n) {\n const ch = text[i];\n if (ch === '\"') {\n const end = scanString(text, i + 1);\n if (end < 0) {\n break;\n }\n const literal = text.slice(i + 1, end);\n i = end + 1;\n if (expectingKey) {\n pendingKey = decodeKey(literal);\n expectingKey = false;\n }\n continue;\n }\n if (ch === \"{\" || ch === \"[\") {\n let label = \"\";\n if (kinds.length > 0) {\n label = kinds[kinds.length - 1] === \"object\" ? (pendingKey ?? \"\") : String(counts[counts.length - 1]);\n }\n kinds.push(ch === \"{\" ? \"object\" : \"array\");\n labels.push(label);\n counts.push(0);\n expectingKey = ch === \"{\";\n pendingKey = null;\n } else if (ch === \"}\" || ch === \"]\") {\n kinds.pop();\n labels.pop();\n counts.pop();\n expectingKey = false;\n pendingKey = null;\n } else if (ch === \":\") {\n if (pendingKey !== null) {\n const path = pathOf();\n if (path !== null) {\n let set = found.get(path);\n if (set === undefined) {\n set = new Set();\n found.set(path, set);\n }\n set.add(pendingKey);\n }\n }\n } else if (ch === \",\") {\n const top = kinds.length - 1;\n if (top >= 0) {\n counts[top]++;\n expectingKey = kinds[top] === \"object\";\n }\n pendingKey = null;\n }\n i++;\n }\n return found;\n}\n\n/**\n * The index of the closing quote of a JSON string starting after its opening quote.\n * @param text - the text\n * @param from - the index after the opening quote\n * @returns the index of the closing quote, or -1 when the text ends first\n */\nfunction scanString(text: string, from: number): number {\n let i = from;\n while (i < text.length) {\n const ch = text[i];\n if (ch === \"\\\\\") {\n i += 2;\n continue;\n }\n if (ch === '\"') {\n return i;\n }\n i++;\n }\n return -1;\n}\n\n/**\n * A key literal decoded when it holds escapes, kept as written otherwise.\n * @param literal - the text between the quotes\n * @returns the key\n */\nfunction decodeKey(literal: string): string {\n if (!literal.includes(\"\\\\\")) {\n return literal;\n }\n try {\n return JSON.parse(`\"${literal}\"`) as string;\n } catch {\n return literal;\n }\n}\n\n/**\n * Coerce a sniff confidence into 0..1 (NaN counts as 0).\n * @param value - the importer's answer\n * @returns the clamped value\n */\nfunction clamp(value: number): number {\n if (!(value > 0)) {\n return 0;\n }\n return value > 1 ? 1 : value;\n}\n","/**\n * The importer / exporter registry (design sections 8.2 and 8.4): the eight built-in formats\n * registered by name, `sniff()` over them, and the two conveniences for callers who do not own a\n * sink: `importGraph()` sniffs the format, creates a builder seeded from the common options\n * (`directed: true` as a placeholder; the importer sets the real value), imports and freezes;\n * `exportGraph()` looks the exporter up by name. A caller who owns a builder uses the importer\n * objects directly (the subpath exports) and this module never touches their sink.\n */\n\nimport {\n type FreezeOptions,\n type FreezeReport,\n GraphBuilder,\n type GraphBuilderOptions,\n GraphFormatError,\n type GraphSnapshot,\n} from \"@graphty/graph-format\";\n\nimport { throwIfAborted } from \"./common/input.js\";\nimport { ImportReportBuilder } from \"./common/report.js\";\nimport { csvExporter, csvImporter } from \"./formats/csv/index.js\";\nimport { dotExporter, dotImporter } from \"./formats/dot/index.js\";\nimport { gexfExporter, gexfImporter } from \"./formats/gexf/index.js\";\nimport { gmlExporter, gmlImporter } from \"./formats/gml/index.js\";\nimport { graphmlExporter, graphmlImporter } from \"./formats/graphml/index.js\";\nimport { jsonExporter, jsonImporter } from \"./formats/json/index.js\";\nimport { neo4jExporter, neo4jImporter } from \"./formats/neo4j/index.js\";\nimport { oboImporter } from \"./formats/obo/index.js\";\nimport { pajekExporter, pajekImporter } from \"./formats/pajek/index.js\";\nimport { rankFormats, SNIFF_HEAD_BYTES, type SniffHints, type SniffResult } from \"./sniff.js\";\nimport {\n type CommonExportOptions,\n type CommonImportOptions,\n type GraphChoiceOptions,\n type GraphExporter,\n type GraphImporter,\n type GraphListing,\n type ImportInput,\n type ImportReport,\n type LossNote,\n} from \"./types.js\";\n\n/** The issue code of an input whose format no registered importer recognises. */\nexport const UNKNOWN_FORMAT_CODE = \"E_UNKNOWN_FORMAT\";\n\n/** The builder options importGraph() accepts beyond the ones the common import options seed. */\nexport type BuilderSeed = Omit<\n GraphBuilderOptions,\n \"directed\" | \"addMissingNodes\" | \"duplicateEdges\" | \"selfLoops\" | \"weightDtype\"\n>;\n\n/**\n * The options of importGraph(): the common import options (which also seed the registry's\n * builder, design section 8.4), the format choice and the hints sniffing uses, the builder and\n * freeze options, and any format-specific option (`delimiter`, `dialect`, ...) passed through to\n * the importer unchanged. `graphIndex` / `graphName` choose one graph of an input that holds\n * several, for the formats that list their graphs.\n */\nexport interface ImportGraphOptions extends CommonImportOptions, GraphChoiceOptions {\n /** The format name, or \"auto\" (default) to sniff it from the filename, MIME type and content. */\n readonly format?: string | undefined;\n /** The file name or path the input came from, a hint for sniffing. */\n readonly filename?: string | null | undefined;\n /** The MIME type the input was served as, a hint for sniffing. */\n readonly mimeType?: string | null | undefined;\n /** Builder options the common options do not cover (`weighted`, `expectedNodes`, ...). */\n readonly builder?: BuilderSeed | undefined;\n /** Options of the freeze that follows the import. */\n readonly freeze?: FreezeOptions | undefined;\n /** Format-specific options, passed to the importer as they are. */\n readonly [formatOption: string]: unknown;\n}\n\n/** What importGraph() returns (design section 8.4). */\nexport interface ImportGraphResult {\n /** The format the input was read as. */\n readonly format: string;\n /** The sniff that chose the importer, or null when the caller named the format. */\n readonly sniff: SniffResult | null;\n /** The frozen snapshot. */\n readonly snapshot: GraphSnapshot;\n /** The importer's report. */\n readonly report: ImportReport;\n /** The freeze report (design section 6.6). */\n readonly freeze: FreezeReport;\n}\n\n/** The options of exportGraph(): the common export options plus any format-specific option, passed through. */\nexport interface ExportGraphOptions extends CommonExportOptions {\n /** Format-specific options, passed to the exporter as they are. */\n readonly [formatOption: string]: unknown;\n}\n\n/** The keys of ImportGraphOptions that belong to the registry, never to an importer. */\nconst REGISTRY_KEYS: ReadonlySet<string> = new Set([\"format\", \"filename\", \"mimeType\", \"builder\", \"freeze\"]);\n\n/**\n * A registry of importers and exporters by format name. Registration order is the tie-break\n * order of sniffing (design section 8.2); the default registry lists the built-in formats in the\n * order of GRAPH_FORMATS.\n */\nexport class FormatRegistry {\n private readonly importerMap = new Map<string, GraphImporter>();\n\n private readonly exporterMap = new Map<string, GraphExporter>();\n\n /**\n * Register an importer under its format name, replacing one of the same name in place (the\n * original registration order is kept).\n * @param importer - the importer\n * @returns this registry, for chaining\n */\n registerImporter(importer: GraphImporter): this {\n this.importerMap.set(importer.format, importer);\n return this;\n }\n\n /**\n * Register an exporter under its format name, replacing one of the same name.\n * @param exporter - the exporter\n * @returns this registry, for chaining\n */\n registerExporter(exporter: GraphExporter): this {\n this.exporterMap.set(exporter.format, exporter);\n return this;\n }\n\n /**\n * The importer of a format.\n * @param format - the format name\n * @returns the importer; E_UNSUPPORTED when none is registered\n */\n importer(format: string): GraphImporter {\n const importer = this.importerMap.get(format);\n if (importer === undefined) {\n throw unknownFormat(\"importer\", format, this.importerMap.keys());\n }\n return importer;\n }\n\n /**\n * The exporter of a format.\n * @param format - the format name\n * @returns the exporter; E_UNSUPPORTED when none is registered\n */\n exporter(format: string): GraphExporter {\n const exporter = this.exporterMap.get(format);\n if (exporter === undefined) {\n throw unknownFormat(\"exporter\", format, this.exporterMap.keys());\n }\n return exporter;\n }\n\n /**\n * Whether an importer is registered for a format.\n * @param format - the format name\n * @returns true when importer(format) would succeed\n */\n hasImporter(format: string): boolean {\n return this.importerMap.has(format);\n }\n\n /**\n * Whether an exporter is registered for a format.\n * @param format - the format name\n * @returns true when exporter(format) would succeed\n */\n hasExporter(format: string): boolean {\n return this.exporterMap.has(format);\n }\n\n /**\n * Every registered importer, in registration order.\n * @returns the importers\n */\n importers(): readonly GraphImporter[] {\n return [...this.importerMap.values()];\n }\n\n /**\n * Every registered exporter, in registration order.\n * @returns the exporters\n */\n exporters(): readonly GraphExporter[] {\n return [...this.exporterMap.values()];\n }\n\n /**\n * The names of every format with an importer or an exporter, importers' order first.\n * @returns the format names, each once\n */\n formats(): readonly string[] {\n return [...new Set([...this.importerMap.keys(), ...this.exporterMap.keys()])];\n }\n\n /**\n * Rank the registered importers for an input (design section 8.2; the successor of\n * graphty-element's detectFormat()).\n * @param hints - the filename, MIME type and / or head of the input\n * @returns the candidates, best first; empty when nothing matches\n */\n sniffAll(hints: SniffHints): readonly SniffResult[] {\n return rankFormats(hints, this.importerMap.values());\n }\n\n /**\n * The best importer for an input, or null when no registered importer claims it.\n * @param hints - the filename, MIME type and / or head of the input\n * @returns the best candidate, or null\n */\n sniff(hints: SniffHints): SniffResult | null {\n const ranked = this.sniffAll(hints);\n return ranked.length > 0 ? ranked[0] : null;\n }\n\n /**\n * Read an input into a fresh builder and freeze it (design section 8.4: for callers who do not\n * own a sink). The format is the one named in the options, else sniffed from the filename,\n * the MIME type and the first bytes of the content; the builder is seeded from the common\n * options with `directed: true` as a placeholder that the importer overrides from the file.\n * An input holding several graphs yields the first, with a warning naming how many were\n * skipped; importAllGraphs() returns every one.\n * @param input - the text, bytes, stream or chunks to read\n * @param options - the format, hints, common and format-specific import options\n * @returns the snapshot, the import report and the freeze report\n */\n async importGraph(input: ImportInput, options: ImportGraphOptions = {}): Promise<ImportGraphResult> {\n const chosen = await this.choose(input, options);\n const builder = seededBuilder(options);\n let report: ImportReport;\n try {\n report = await chosen.importer.import(chosen.source, builder, importerOptions(options));\n } catch (err) {\n await chosen.peeked?.close();\n throw err;\n }\n return result(chosen, builder, report, options);\n }\n\n /**\n * Read every graph of an input (a DOT file with several graphs, a Pajek project with several\n * networks, a JGF document with a `graphs` array), each into its own fresh builder, frozen.\n * A format whose importer has no importAll() holds one graph per input, so the result has one\n * entry. Options, sniffing and the builder seed are those of importGraph().\n * @param input - the text, bytes, stream or chunks to read\n * @param options - the format, hints, common and format-specific import options\n * @returns one result per graph, in document order\n */\n async importAllGraphs(input: ImportInput, options: ImportGraphOptions = {}): Promise<ImportGraphResult[]> {\n const chosen = await this.choose(input, options);\n const { importer } = chosen;\n const builders: GraphBuilder[] = [];\n let reports: ImportReport[];\n try {\n if (importer.importAll === undefined) {\n builders.push(seededBuilder(options));\n reports = [await importer.import(chosen.source, builders[0], importerOptions(options))];\n } else {\n reports = await importer.importAll(\n chosen.source,\n () => {\n const builder = seededBuilder(options);\n builders.push(builder);\n return builder;\n },\n importerOptions(options),\n );\n }\n } catch (err) {\n await chosen.peeked?.close();\n throw err;\n }\n return reports.map((report, i) => result(chosen, builders[i], report, options));\n }\n\n /**\n * The graphs of an input that can hold several, without importing them (a Cytoscape session's\n * networks, a JGF `graphs` array), so a caller can offer a choice and then pass `graphIndex`\n * or `graphName` to importGraph(). The format is named or sniffed as by importGraph().\n * @param input - the text, bytes, stream or chunks to read\n * @param options - the format, hints, common and format-specific import options\n * @returns one listing per graph, in document order; null when the format's importer does not\n * list its graphs (importGraph() then reads the first)\n */\n async listGraphs(input: ImportInput, options: ImportGraphOptions = {}): Promise<readonly GraphListing[] | null> {\n const chosen = await this.choose(input, options);\n try {\n return chosen.importer.listGraphs === undefined\n ? null\n : await chosen.importer.listGraphs(chosen.source, importerOptions(options));\n } finally {\n await chosen.peeked?.close();\n }\n }\n\n /**\n * The importer for an input: the named format, or the sniffed one.\n * @param input - the input\n * @param options - the importGraph options\n * @returns the importer, the sniff, and the input to read (replayed for a stream)\n */\n private async choose(input: ImportInput, options: ImportGraphOptions): Promise<ChosenImporter> {\n const requested = options.format ?? \"auto\";\n if (requested !== \"auto\") {\n return { importer: this.importer(requested), sniff: null, source: input, peeked: null };\n }\n const peeked = await peekHead(input, SNIFF_HEAD_BYTES, options.signal ?? null);\n const sniff = this.sniff({ filename: options.filename, mimeType: options.mimeType, head: peeked.head });\n if (sniff === null) {\n const report = new ImportReportBuilder(\"unknown\", 0);\n return report.fail(\n UNKNOWN_FORMAT_CODE,\n `no registered importer recognises the input${describeHints(options)}; pass the format explicitly`,\n undefined,\n { formats: this.formats() },\n );\n }\n return { importer: this.importer(sniff.format), sniff, source: peeked.input, peeked };\n }\n\n /**\n * Write a snapshot in a format, as UTF-8 chunks (design section 8.5).\n * @param snapshot - the snapshot\n * @param format - the format name\n * @param options - the exporter's common and format-specific options\n * @returns the encoded chunks\n */\n exportGraph(snapshot: GraphSnapshot, format: string, options?: ExportGraphOptions): AsyncIterable<Uint8Array> {\n return this.exporter(format).export(snapshot, options);\n }\n\n /**\n * Write a snapshot in a format, as one string.\n * @param snapshot - the snapshot\n * @param format - the format name\n * @param options - the exporter's common and format-specific options\n * @returns the whole document\n */\n async exportGraphToString(snapshot: GraphSnapshot, format: string, options?: ExportGraphOptions): Promise<string> {\n return this.exporter(format).exportToString(snapshot, options);\n }\n\n /**\n * What exporting a snapshot in a format would lose, without writing anything.\n * @param snapshot - the snapshot\n * @param format - the format name\n * @param options - the exporter's common and format-specific options\n * @returns the loss notes, empty when the export is exact\n */\n checkExport(snapshot: GraphSnapshot, format: string, options?: ExportGraphOptions): readonly LossNote[] {\n return this.exporter(format).check(snapshot, options);\n }\n}\n\n/**\n * A registry holding the eight built-in importers and exporters in the order of GRAPH_FORMATS.\n * @returns a new registry\n */\nexport function createRegistry(): FormatRegistry {\n return new FormatRegistry()\n .registerImporter(jsonImporter)\n .registerExporter(jsonExporter)\n .registerImporter(graphmlImporter)\n .registerExporter(graphmlExporter)\n .registerImporter(gexfImporter)\n .registerExporter(gexfExporter)\n .registerImporter(csvImporter)\n .registerExporter(csvExporter)\n .registerImporter(gmlImporter)\n .registerExporter(gmlExporter)\n .registerImporter(dotImporter)\n .registerExporter(dotExporter)\n .registerImporter(pajekImporter)\n .registerExporter(pajekExporter)\n .registerImporter(neo4jImporter)\n .registerExporter(neo4jExporter)\n .registerImporter(oboImporter);\n}\n\n/** The default registry: every built-in format. */\nexport const registry: FormatRegistry = createRegistry();\n\n/**\n * Read an input into a fresh builder and freeze it, through the default registry (design section\n * 8.4: `importGraph(input, { format?, ...options })`).\n * @param input - the text, bytes, stream or chunks to read\n * @param options - the format, hints, common and format-specific import options\n * @returns the snapshot, the import report and the freeze report\n */\nexport function importGraph(input: ImportInput, options?: ImportGraphOptions): Promise<ImportGraphResult> {\n return registry.importGraph(input, options);\n}\n\n/**\n * Read every graph of an input, each into its own frozen snapshot, through the default registry.\n * @param input - the text, bytes, stream or chunks to read\n * @param options - the format, hints, common and format-specific import options\n * @returns one result per graph, in document order\n */\nexport function importAllGraphs(input: ImportInput, options?: ImportGraphOptions): Promise<ImportGraphResult[]> {\n return registry.importAllGraphs(input, options);\n}\n\n/**\n * The graphs of an input that can hold several, through the default registry.\n * @param input - the text, bytes, stream or chunks to read\n * @param options - the format, hints, common and format-specific import options\n * @returns one listing per graph, in document order; null when the format does not list its graphs\n */\nexport function listGraphs(input: ImportInput, options?: ImportGraphOptions): Promise<readonly GraphListing[] | null> {\n return registry.listGraphs(input, options);\n}\n\n/**\n * Write a snapshot in a format through the default registry, as UTF-8 chunks.\n * @param snapshot - the snapshot\n * @param format - the format name\n * @param options - the exporter's common and format-specific options\n * @returns the encoded chunks\n */\nexport function exportGraph(\n snapshot: GraphSnapshot,\n format: string,\n options?: ExportGraphOptions,\n): AsyncIterable<Uint8Array> {\n return registry.exportGraph(snapshot, format, options);\n}\n\n/**\n * Write a snapshot in a format through the default registry, as one string.\n * @param snapshot - the snapshot\n * @param format - the format name\n * @param options - the exporter's common and format-specific options\n * @returns the whole document\n */\nexport async function exportGraphToString(\n snapshot: GraphSnapshot,\n format: string,\n options?: ExportGraphOptions,\n): Promise<string> {\n return registry.exportGraphToString(snapshot, format, options);\n}\n\n/**\n * What exporting a snapshot in a format would lose, through the default registry.\n * @param snapshot - the snapshot\n * @param format - the format name\n * @param options - the exporter's common and format-specific options\n * @returns the loss notes, empty when the export is exact\n */\nexport function checkExport(\n snapshot: GraphSnapshot,\n format: string,\n options?: ExportGraphOptions,\n): readonly LossNote[] {\n return registry.checkExport(snapshot, format, options);\n}\n\n/**\n * Sniff an input's format through the default registry.\n * @param hints - the filename, MIME type and / or head of the input\n * @returns the best candidate, or null when no built-in importer claims it\n */\nexport function sniff(hints: SniffHints): SniffResult | null {\n return registry.sniff(hints);\n}\n\n/**\n * The options handed to the importer: everything but the registry's own keys.\n * @param options - the importGraph options\n * @returns the importer's options\n */\nfunction importerOptions(options: ImportGraphOptions): CommonImportOptions {\n const out: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(options)) {\n if (!REGISTRY_KEYS.has(key)) {\n out[key] = value;\n }\n }\n return out;\n}\n\n/** The importer chosen for an input, and the input to hand it. */\ninterface ChosenImporter {\n /** The importer. */\n readonly importer: GraphImporter;\n /** The sniff that chose it, or null when the caller named the format. */\n readonly sniff: SniffResult | null;\n /** The input to read: the original, or a replaying iterable for a peeked stream. */\n readonly source: ImportInput;\n /** The peeked head of a sniffed input, or null. */\n readonly peeked: PeekedInput | null;\n}\n\n/**\n * A fresh builder seeded from the common options, `directed: true` as a placeholder the importer\n * overrides from the file.\n * @param options - the importGraph options\n * @returns the builder\n */\nfunction seededBuilder(options: ImportGraphOptions): GraphBuilder {\n return new GraphBuilder({\n weightDtype: options.weightDtype ?? \"f64\",\n ...options.builder,\n directed: true,\n addMissingNodes: options.addMissingNodes ?? true,\n duplicateEdges: options.duplicateEdges ?? \"keep\",\n selfLoops: options.selfLoops ?? \"keep\",\n });\n}\n\n/**\n * Freeze an imported builder into an importGraph result.\n * @param chosen - the importer and its sniff\n * @param builder - the filled builder\n * @param report - the importer's report\n * @param options - the importGraph options\n * @returns the frozen result\n */\nfunction result(\n chosen: ChosenImporter,\n builder: GraphBuilder,\n report: ImportReport,\n options: ImportGraphOptions,\n): ImportGraphResult {\n const frozen = builder.freezeWithReport(options.freeze);\n return Object.freeze({\n format: chosen.importer.format,\n sniff: chosen.sniff,\n snapshot: frozen.snapshot,\n report,\n freeze: frozen.report,\n });\n}\n\n/**\n * The E_UNSUPPORTED error of a format name nothing is registered under.\n * @param kind - importer or exporter\n * @param format - the requested name\n * @param known - the registered names\n * @returns the error\n */\nfunction unknownFormat(kind: \"importer\" | \"exporter\", format: string, known: Iterable<string>): GraphFormatError {\n const supported = [...known];\n return new GraphFormatError(\n \"E_UNSUPPORTED\",\n `no ${kind} is registered for format ${JSON.stringify(format)}; known: ${supported.join(\", \")}`,\n { option: \"format\", found: format, supported },\n );\n}\n\n/**\n * The hints of an import, for the unknown-format message.\n * @param options - the importGraph options\n * @returns \" (filename ..., MIME type ...)\" or an empty string\n */\nfunction describeHints(options: ImportGraphOptions): string {\n const parts: string[] = [];\n if (typeof options.filename === \"string\" && options.filename.length > 0) {\n parts.push(`filename ${JSON.stringify(options.filename)}`);\n }\n if (typeof options.mimeType === \"string\" && options.mimeType.length > 0) {\n parts.push(`MIME type ${JSON.stringify(options.mimeType)}`);\n }\n return parts.length === 0 ? \"\" : ` (${parts.join(\", \")})`;\n}\n\n/** A head read from an input, and the input to hand the importer (the same bytes, replayed for a stream). */\ninterface PeekedInput {\n /** The first bytes (or, for a text input, characters) of the content. */\n readonly head: Uint8Array | string;\n /** The input to read: the original for in-memory input, a replaying iterable for a stream. */\n readonly input: ImportInput;\n /**\n * Close the source when the importer never iterated the replaying input (it threw first, an\n * abort for instance): a stream's reader is cancelled and released, an async generator finalised.\n * @returns when the source is closed\n */\n close(): Promise<void>;\n}\n\n/**\n * The first `bytes` of an input without consuming it: in-memory input is sliced; a stream or an\n * async iterable is read until enough is buffered and then replayed (the buffered chunks first,\n * the rest as it arrives) through a new async iterable that cancels the source when the importer\n * stops early.\n * @param input - the input\n * @param bytes - how much to peek\n * @param signal - the cancellation signal, or null\n * @returns the head and the input to read\n */\nasync function peekHead(input: ImportInput, bytes: number, signal: AbortSignal | null): Promise<PeekedInput> {\n if (typeof input === \"string\") {\n return { head: input.slice(0, bytes), input, close: (): Promise<void> => Promise.resolve() };\n }\n if (input instanceof Uint8Array) {\n return { head: input.subarray(0, bytes), input, close: (): Promise<void> => Promise.resolve() };\n }\n throwIfAborted(signal);\n const source: AsyncIterator<string | Uint8Array> =\n typeof (input as { getReader?: unknown }).getReader === \"function\"\n ? readerIterator(input as ReadableStream<Uint8Array>)\n : (input as AsyncIterable<string | Uint8Array>)[Symbol.asyncIterator]();\n const buffered: (string | Uint8Array)[] = [];\n let size = 0;\n let finished = false;\n while (size < bytes) {\n if (signal !== null && signal.aborted) {\n await source.return?.();\n throwIfAborted(signal);\n }\n const next = await source.next();\n if (next.done === true) {\n finished = true;\n break;\n }\n buffered.push(next.value);\n size += typeof next.value === \"string\" ? next.value.length : next.value.byteLength;\n }\n if (!finished && signal !== null && signal.aborted) {\n // an abort that landed on the read completing the head: close the source before rethrowing\n await source.return?.();\n throwIfAborted(signal);\n }\n const replayed = replay(buffered, source, finished);\n return { head: joinHead(buffered, bytes), input: replayed, close: (): Promise<void> => replayed.close() };\n}\n\n/**\n * The head text or bytes of the buffered chunks: bytes when every chunk is bytes, text otherwise\n * (byte chunks decoded leniently; the importer decodes the real input strictly).\n * @param chunks - the buffered chunks\n * @param bytes - the head size\n * @returns the head\n */\nfunction joinHead(chunks: readonly (string | Uint8Array)[], bytes: number): Uint8Array | string {\n if (chunks.every((c) => c instanceof Uint8Array)) {\n const total = Math.min(\n bytes,\n chunks.reduce((sum, c) => sum + c.byteLength, 0),\n );\n const head = new Uint8Array(total);\n let offset = 0;\n for (const chunk of chunks) {\n if (offset >= total) {\n break;\n }\n const part = chunk.subarray(0, Math.min(chunk.byteLength, total - offset));\n head.set(part, offset);\n offset += part.byteLength;\n }\n return head;\n }\n const decoder = new TextDecoder(\"utf-8\", { fatal: false });\n let text = \"\";\n for (const chunk of chunks) {\n text += typeof chunk === \"string\" ? chunk : decoder.decode(chunk, { stream: true });\n if (text.length >= bytes) {\n break;\n }\n }\n return text.slice(0, bytes);\n}\n\n/**\n * An async iterable that yields the buffered chunks, then the rest of the source; the source is\n * closed when the consumer stops early.\n * @param buffered - the chunks already read\n * @param source - the iterator positioned after them\n * @param finished - whether the source is already exhausted\n * @returns the replaying iterable\n */\nfunction replay(\n buffered: readonly (string | Uint8Array)[],\n source: AsyncIterator<string | Uint8Array>,\n finished: boolean,\n): AsyncIterable<string | Uint8Array> & { close(): Promise<void> } {\n let exhausted = finished;\n const close = async (): Promise<void> => {\n if (!exhausted) {\n exhausted = true;\n await source.return?.();\n }\n };\n return {\n close,\n [Symbol.asyncIterator](): AsyncIterator<string | Uint8Array> {\n let position = 0;\n return {\n async next(): Promise<IteratorResult<string | Uint8Array>> {\n if (position < buffered.length) {\n return { done: false, value: buffered[position++] };\n }\n if (exhausted) {\n return { done: true, value: undefined };\n }\n const next = await source.next();\n if (next.done === true) {\n exhausted = true;\n return { done: true, value: undefined };\n }\n return next;\n },\n async return(): Promise<IteratorResult<string | Uint8Array>> {\n await close();\n return { done: true, value: undefined };\n },\n };\n },\n };\n}\n\n/**\n * An async iterator over a ReadableStream's chunks that cancels the stream when closed early.\n * @param stream - the stream\n * @returns the iterator\n */\nfunction readerIterator(stream: ReadableStream<Uint8Array>): AsyncIterator<Uint8Array> {\n const reader = stream.getReader();\n let done = false;\n return {\n async next(): Promise<IteratorResult<Uint8Array>> {\n if (done) {\n return { done: true, value: undefined };\n }\n const result = await reader.read();\n if (result.done) {\n done = true;\n reader.releaseLock();\n return { done: true, value: undefined };\n }\n return { done: false, value: result.value };\n },\n async return(): Promise<IteratorResult<Uint8Array>> {\n if (!done) {\n done = true;\n await reader.cancel().catch(() => undefined);\n reader.releaseLock();\n }\n return { done: true, value: undefined };\n },\n };\n}\n"],"names":["e","m","result","a","b","c","i","n","sniff"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAkCO,MAAM,gBAA4C,OAAO,OAAO;AAAA,EACnE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACJ,CAAC;AAGM,MAAM,mBAAmB;AAiCzB,SAAS,YAAY,UAAiC;AACzD,QAAM,OAAO,SAAS,MAAM,KAAK,IAAI,SAAS,YAAY,GAAG,GAAG,SAAS,YAAY,IAAI,CAAC,IAAI,CAAC;AAC/F,QAAM,MAAM,KAAK,YAAY,GAAG;AAChC,MAAI,OAAO,KAAK,QAAQ,KAAK,SAAS,GAAG;AACrC,WAAO;AAAA,EACX;AACA,SAAO,KAAK,MAAM,GAAG,EAAE,YAAA;AAC3B;AAOO,SAAS,kBAAkB,UAA0B;AACxD,QAAM,YAAY,SAAS,QAAQ,GAAG;AACtC,UAAQ,YAAY,IAAI,WAAW,SAAS,MAAM,GAAG,SAAS,GAAG,KAAA,EAAO,YAAA;AAC5E;AAQO,SAAS,UAAU,MAAuC;AAC7D,MAAI,OAAO,SA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M,MAAM,OAAO,OAAA;AAAA,MAChC;AACA,YAAMH,UAAS,MAAM,OAAO,KAAA;AAC5B,UAAIA,QAAO,MAAM;AACb,eAAO;AACP,eAAO,YAAA;AACP,eAAO,EAAE,MAAM,MAAM,OAAO,OAAA;AAAA,MAChC;AACA,aAAO,EAAE,MAAM,OAAO,OAAOA,QAAO,MAAA;AAAA,IACxC;AAAA,IACA,MAAM,SAA8C;AAChD,UAAI,CAAC,MAAM;AACP,eAAO;AACP,cAAM,OAAO,OAAA,EAAS,MAAM,MAAM,MAAS;AAC3C,eAAO,YAAA;AAAA,MACX;AACA,aAAO,EAAE,MAAM,MAAM,OAAO,OAAA;AAAA,IAChC;AAAA,EAAA;AAER;"}
|
|
1
|
+
{"version":3,"file":"graph-io.js","sources":["../src/registry.ts"],"sourcesContent":["/**\n * The importer / exporter registry (design sections 8.2 and 8.4): the eight built-in formats\n * registered by name, `sniff()` over them, and the two conveniences for callers who do not own a\n * sink: `importGraph()` sniffs the format, creates a builder seeded from the common options\n * (`directed: true` as a placeholder; the importer sets the real value), imports and freezes;\n * `exportGraph()` looks the exporter up by name. A caller who owns a builder uses the importer\n * objects directly (the subpath exports) and this module never touches their sink.\n */\n\nimport {\n type FreezeOptions,\n type FreezeReport,\n GraphBuilder,\n type GraphBuilderOptions,\n GraphFormatError,\n type GraphSnapshot,\n} from \"@graphty/graph-format\";\n\nimport { throwIfAborted } from \"./common/input.js\";\nimport { ImportReportBuilder } from \"./common/report.js\";\nimport { csvExporter, csvImporter } from \"./formats/csv/index.js\";\nimport { cxImporter } from \"./formats/cx/index.js\";\nimport { cx2Exporter, cx2Importer } from \"./formats/cx2/index.js\";\nimport { dotExporter, dotImporter } from \"./formats/dot/index.js\";\nimport { gexfExporter, gexfImporter } from \"./formats/gexf/index.js\";\nimport { gmlExporter, gmlImporter } from \"./formats/gml/index.js\";\nimport { graphmlExporter, graphmlImporter } from \"./formats/graphml/index.js\";\nimport { jsonExporter, jsonImporter } from \"./formats/json/index.js\";\nimport { neo4jExporter, neo4jImporter } from \"./formats/neo4j/index.js\";\nimport { oboImporter } from \"./formats/obo/index.js\";\nimport { pajekExporter, pajekImporter } from \"./formats/pajek/index.js\";\nimport { rankFormats, SNIFF_HEAD_BYTES, type SniffHints, type SniffResult } from \"./sniff.js\";\nimport {\n type CommonExportOptions,\n type CommonImportOptions,\n type GraphChoiceOptions,\n type GraphExporter,\n type GraphImporter,\n type GraphListing,\n type ImportInput,\n type ImportReport,\n type LossNote,\n} from \"./types.js\";\n\n/** The issue code of an input whose format no registered importer recognises. */\nexport const UNKNOWN_FORMAT_CODE = \"E_UNKNOWN_FORMAT\";\n\n/** The builder options importGraph() accepts beyond the ones the common import options seed. */\nexport type BuilderSeed = Omit<\n GraphBuilderOptions,\n \"directed\" | \"addMissingNodes\" | \"duplicateEdges\" | \"selfLoops\" | \"weightDtype\"\n>;\n\n/**\n * The options of importGraph(): the common import options (which also seed the registry's\n * builder, design section 8.4), the format choice and the hints sniffing uses, the builder and\n * freeze options, and any format-specific option (`delimiter`, `dialect`, ...) passed through to\n * the importer unchanged. `graphIndex` / `graphName` choose one graph of an input that holds\n * several, for the formats that list their graphs.\n */\nexport interface ImportGraphOptions extends CommonImportOptions, GraphChoiceOptions {\n /** The format name, or \"auto\" (default) to sniff it from the filename, MIME type and content. */\n readonly format?: string | undefined;\n /** The file name or path the input came from, a hint for sniffing. */\n readonly filename?: string | null | undefined;\n /** The MIME type the input was served as, a hint for sniffing. */\n readonly mimeType?: string | null | undefined;\n /** Builder options the common options do not cover (`weighted`, `expectedNodes`, ...). */\n readonly builder?: BuilderSeed | undefined;\n /** Options of the freeze that follows the import. */\n readonly freeze?: FreezeOptions | undefined;\n /** Format-specific options, passed to the importer as they are. */\n readonly [formatOption: string]: unknown;\n}\n\n/** What importGraph() returns (design section 8.4). */\nexport interface ImportGraphResult {\n /** The format the input was read as. */\n readonly format: string;\n /** The sniff that chose the importer, or null when the caller named the format. */\n readonly sniff: SniffResult | null;\n /** The frozen snapshot. */\n readonly snapshot: GraphSnapshot;\n /** The importer's report. */\n readonly report: ImportReport;\n /** The freeze report (design section 6.6). */\n readonly freeze: FreezeReport;\n}\n\n/** The options of exportGraph(): the common export options plus any format-specific option, passed through. */\nexport interface ExportGraphOptions extends CommonExportOptions {\n /** Format-specific options, passed to the exporter as they are. */\n readonly [formatOption: string]: unknown;\n}\n\n/** The keys of ImportGraphOptions that belong to the registry, never to an importer. */\nconst REGISTRY_KEYS: ReadonlySet<string> = new Set([\"format\", \"filename\", \"mimeType\", \"builder\", \"freeze\"]);\n\n/**\n * A registry of importers and exporters by format name. Registration order is the tie-break\n * order of sniffing (design section 8.2); the default registry lists the built-in formats in the\n * order of GRAPH_FORMATS.\n */\nexport class FormatRegistry {\n private readonly importerMap = new Map<string, GraphImporter>();\n\n private readonly exporterMap = new Map<string, GraphExporter>();\n\n /**\n * Register an importer under its format name, replacing one of the same name in place (the\n * original registration order is kept).\n * @param importer - the importer\n * @returns this registry, for chaining\n */\n registerImporter(importer: GraphImporter): this {\n this.importerMap.set(importer.format, importer);\n return this;\n }\n\n /**\n * Register an exporter under its format name, replacing one of the same name.\n * @param exporter - the exporter\n * @returns this registry, for chaining\n */\n registerExporter(exporter: GraphExporter): this {\n this.exporterMap.set(exporter.format, exporter);\n return this;\n }\n\n /**\n * The importer of a format.\n * @param format - the format name\n * @returns the importer; E_UNSUPPORTED when none is registered\n */\n importer(format: string): GraphImporter {\n const importer = this.importerMap.get(format);\n if (importer === undefined) {\n throw unknownFormat(\"importer\", format, this.importerMap.keys());\n }\n return importer;\n }\n\n /**\n * The exporter of a format.\n * @param format - the format name\n * @returns the exporter; E_UNSUPPORTED when none is registered\n */\n exporter(format: string): GraphExporter {\n const exporter = this.exporterMap.get(format);\n if (exporter === undefined) {\n throw unknownFormat(\"exporter\", format, this.exporterMap.keys());\n }\n return exporter;\n }\n\n /**\n * Whether an importer is registered for a format.\n * @param format - the format name\n * @returns true when importer(format) would succeed\n */\n hasImporter(format: string): boolean {\n return this.importerMap.has(format);\n }\n\n /**\n * Whether an exporter is registered for a format.\n * @param format - the format name\n * @returns true when exporter(format) would succeed\n */\n hasExporter(format: string): boolean {\n return this.exporterMap.has(format);\n }\n\n /**\n * Every registered importer, in registration order.\n * @returns the importers\n */\n importers(): readonly GraphImporter[] {\n return [...this.importerMap.values()];\n }\n\n /**\n * Every registered exporter, in registration order.\n * @returns the exporters\n */\n exporters(): readonly GraphExporter[] {\n return [...this.exporterMap.values()];\n }\n\n /**\n * The names of every format with an importer or an exporter, importers' order first.\n * @returns the format names, each once\n */\n formats(): readonly string[] {\n return [...new Set([...this.importerMap.keys(), ...this.exporterMap.keys()])];\n }\n\n /**\n * Rank the registered importers for an input (design section 8.2; the successor of\n * graphty-element's detectFormat()).\n * @param hints - the filename, MIME type and / or head of the input\n * @returns the candidates, best first; empty when nothing matches\n */\n sniffAll(hints: SniffHints): readonly SniffResult[] {\n return rankFormats(hints, this.importerMap.values());\n }\n\n /**\n * The best importer for an input, or null when no registered importer claims it.\n * @param hints - the filename, MIME type and / or head of the input\n * @returns the best candidate, or null\n */\n sniff(hints: SniffHints): SniffResult | null {\n const ranked = this.sniffAll(hints);\n return ranked.length > 0 ? ranked[0] : null;\n }\n\n /**\n * Read an input into a fresh builder and freeze it (design section 8.4: for callers who do not\n * own a sink). The format is the one named in the options, else sniffed from the filename,\n * the MIME type and the first bytes of the content; the builder is seeded from the common\n * options with `directed: true` as a placeholder that the importer overrides from the file.\n * An input holding several graphs yields the first, with a warning naming how many were\n * skipped; importAllGraphs() returns every one.\n * @param input - the text, bytes, stream or chunks to read\n * @param options - the format, hints, common and format-specific import options\n * @returns the snapshot, the import report and the freeze report\n */\n async importGraph(input: ImportInput, options: ImportGraphOptions = {}): Promise<ImportGraphResult> {\n const chosen = await this.choose(input, options);\n const builder = seededBuilder(options);\n let report: ImportReport;\n try {\n report = await chosen.importer.import(chosen.source, builder, importerOptions(options));\n } catch (err) {\n await chosen.peeked?.close();\n throw err;\n }\n return result(chosen, builder, report, options);\n }\n\n /**\n * Read every graph of an input (a DOT file with several graphs, a Pajek project with several\n * networks, a JGF document with a `graphs` array), each into its own fresh builder, frozen.\n * A format whose importer has no importAll() holds one graph per input, so the result has one\n * entry. Options, sniffing and the builder seed are those of importGraph().\n * @param input - the text, bytes, stream or chunks to read\n * @param options - the format, hints, common and format-specific import options\n * @returns one result per graph, in document order\n */\n async importAllGraphs(input: ImportInput, options: ImportGraphOptions = {}): Promise<ImportGraphResult[]> {\n const chosen = await this.choose(input, options);\n const { importer } = chosen;\n const builders: GraphBuilder[] = [];\n let reports: ImportReport[];\n try {\n if (importer.importAll === undefined) {\n builders.push(seededBuilder(options));\n reports = [await importer.import(chosen.source, builders[0], importerOptions(options))];\n } else {\n reports = await importer.importAll(\n chosen.source,\n () => {\n const builder = seededBuilder(options);\n builders.push(builder);\n return builder;\n },\n importerOptions(options),\n );\n }\n } catch (err) {\n await chosen.peeked?.close();\n throw err;\n }\n return reports.map((report, i) => result(chosen, builders[i], report, options));\n }\n\n /**\n * The graphs of an input that can hold several, without importing them (a Cytoscape session's\n * networks, a JGF `graphs` array), so a caller can offer a choice and then pass `graphIndex`\n * or `graphName` to importGraph(). The format is named or sniffed as by importGraph().\n * @param input - the text, bytes, stream or chunks to read\n * @param options - the format, hints, common and format-specific import options\n * @returns one listing per graph, in document order; null when the format's importer does not\n * list its graphs (importGraph() then reads the first)\n */\n async listGraphs(input: ImportInput, options: ImportGraphOptions = {}): Promise<readonly GraphListing[] | null> {\n const chosen = await this.choose(input, options);\n try {\n return chosen.importer.listGraphs === undefined\n ? null\n : await chosen.importer.listGraphs(chosen.source, importerOptions(options));\n } finally {\n await chosen.peeked?.close();\n }\n }\n\n /**\n * The importer for an input: the named format, or the sniffed one.\n * @param input - the input\n * @param options - the importGraph options\n * @returns the importer, the sniff, and the input to read (replayed for a stream)\n */\n private async choose(input: ImportInput, options: ImportGraphOptions): Promise<ChosenImporter> {\n const requested = options.format ?? \"auto\";\n if (requested !== \"auto\") {\n return { importer: this.importer(requested), sniff: null, source: input, peeked: null };\n }\n const peeked = await peekHead(input, SNIFF_HEAD_BYTES, options.signal ?? null);\n const sniff = this.sniff({ filename: options.filename, mimeType: options.mimeType, head: peeked.head });\n if (sniff === null) {\n const report = new ImportReportBuilder(\"unknown\", 0);\n return report.fail(\n UNKNOWN_FORMAT_CODE,\n `no registered importer recognises the input${describeHints(options)}; pass the format explicitly`,\n undefined,\n { formats: this.formats() },\n );\n }\n return { importer: this.importer(sniff.format), sniff, source: peeked.input, peeked };\n }\n\n /**\n * Write a snapshot in a format, as UTF-8 chunks (design section 8.5).\n * @param snapshot - the snapshot\n * @param format - the format name\n * @param options - the exporter's common and format-specific options\n * @returns the encoded chunks\n */\n exportGraph(snapshot: GraphSnapshot, format: string, options?: ExportGraphOptions): AsyncIterable<Uint8Array> {\n return this.exporter(format).export(snapshot, options);\n }\n\n /**\n * Write a snapshot in a format, as one string.\n * @param snapshot - the snapshot\n * @param format - the format name\n * @param options - the exporter's common and format-specific options\n * @returns the whole document\n */\n async exportGraphToString(snapshot: GraphSnapshot, format: string, options?: ExportGraphOptions): Promise<string> {\n return this.exporter(format).exportToString(snapshot, options);\n }\n\n /**\n * What exporting a snapshot in a format would lose, without writing anything.\n * @param snapshot - the snapshot\n * @param format - the format name\n * @param options - the exporter's common and format-specific options\n * @returns the loss notes, empty when the export is exact\n */\n checkExport(snapshot: GraphSnapshot, format: string, options?: ExportGraphOptions): readonly LossNote[] {\n return this.exporter(format).check(snapshot, options);\n }\n}\n\n/**\n * A registry holding the eight built-in importers and exporters in the order of GRAPH_FORMATS.\n * @returns a new registry\n */\nexport function createRegistry(): FormatRegistry {\n return new FormatRegistry()\n .registerImporter(jsonImporter)\n .registerExporter(jsonExporter)\n .registerImporter(graphmlImporter)\n .registerExporter(graphmlExporter)\n .registerImporter(gexfImporter)\n .registerExporter(gexfExporter)\n .registerImporter(csvImporter)\n .registerExporter(csvExporter)\n .registerImporter(gmlImporter)\n .registerExporter(gmlExporter)\n .registerImporter(dotImporter)\n .registerExporter(dotExporter)\n .registerImporter(pajekImporter)\n .registerExporter(pajekExporter)\n .registerImporter(neo4jImporter)\n .registerExporter(neo4jExporter)\n .registerImporter(cx2Importer)\n .registerExporter(cx2Exporter)\n .registerImporter(cxImporter)\n .registerImporter(oboImporter);\n}\n\n/** The default registry: every built-in format. */\nexport const registry: FormatRegistry = createRegistry();\n\n/**\n * Read an input into a fresh builder and freeze it, through the default registry (design section\n * 8.4: `importGraph(input, { format?, ...options })`).\n * @param input - the text, bytes, stream or chunks to read\n * @param options - the format, hints, common and format-specific import options\n * @returns the snapshot, the import report and the freeze report\n */\nexport function importGraph(input: ImportInput, options?: ImportGraphOptions): Promise<ImportGraphResult> {\n return registry.importGraph(input, options);\n}\n\n/**\n * Read every graph of an input, each into its own frozen snapshot, through the default registry.\n * @param input - the text, bytes, stream or chunks to read\n * @param options - the format, hints, common and format-specific import options\n * @returns one result per graph, in document order\n */\nexport function importAllGraphs(input: ImportInput, options?: ImportGraphOptions): Promise<ImportGraphResult[]> {\n return registry.importAllGraphs(input, options);\n}\n\n/**\n * The graphs of an input that can hold several, through the default registry.\n * @param input - the text, bytes, stream or chunks to read\n * @param options - the format, hints, common and format-specific import options\n * @returns one listing per graph, in document order; null when the format does not list its graphs\n */\nexport function listGraphs(input: ImportInput, options?: ImportGraphOptions): Promise<readonly GraphListing[] | null> {\n return registry.listGraphs(input, options);\n}\n\n/**\n * Write a snapshot in a format through the default registry, as UTF-8 chunks.\n * @param snapshot - the snapshot\n * @param format - the format name\n * @param options - the exporter's common and format-specific options\n * @returns the encoded chunks\n */\nexport function exportGraph(\n snapshot: GraphSnapshot,\n format: string,\n options?: ExportGraphOptions,\n): AsyncIterable<Uint8Array> {\n return registry.exportGraph(snapshot, format, options);\n}\n\n/**\n * Write a snapshot in a format through the default registry, as one string.\n * @param snapshot - the snapshot\n * @param format - the format name\n * @param options - the exporter's common and format-specific options\n * @returns the whole document\n */\nexport async function exportGraphToString(\n snapshot: GraphSnapshot,\n format: string,\n options?: ExportGraphOptions,\n): Promise<string> {\n return registry.exportGraphToString(snapshot, format, options);\n}\n\n/**\n * What exporting a snapshot in a format would lose, through the default registry.\n * @param snapshot - the snapshot\n * @param format - the format name\n * @param options - the exporter's common and format-specific options\n * @returns the loss notes, empty when the export is exact\n */\nexport function checkExport(\n snapshot: GraphSnapshot,\n format: string,\n options?: ExportGraphOptions,\n): readonly LossNote[] {\n return registry.checkExport(snapshot, format, options);\n}\n\n/**\n * Sniff an input's format through the default registry.\n * @param hints - the filename, MIME type and / or head of the input\n * @returns the best candidate, or null when no built-in importer claims it\n */\nexport function sniff(hints: SniffHints): SniffResult | null {\n return registry.sniff(hints);\n}\n\n/**\n * The options handed to the importer: everything but the registry's own keys.\n * @param options - the importGraph options\n * @returns the importer's options\n */\nfunction importerOptions(options: ImportGraphOptions): CommonImportOptions {\n const out: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(options)) {\n if (!REGISTRY_KEYS.has(key)) {\n out[key] = value;\n }\n }\n return out;\n}\n\n/** The importer chosen for an input, and the input to hand it. */\ninterface ChosenImporter {\n /** The importer. */\n readonly importer: GraphImporter;\n /** The sniff that chose it, or null when the caller named the format. */\n readonly sniff: SniffResult | null;\n /** The input to read: the original, or a replaying iterable for a peeked stream. */\n readonly source: ImportInput;\n /** The peeked head of a sniffed input, or null. */\n readonly peeked: PeekedInput | null;\n}\n\n/**\n * A fresh builder seeded from the common options, `directed: true` as a placeholder the importer\n * overrides from the file.\n * @param options - the importGraph options\n * @returns the builder\n */\nfunction seededBuilder(options: ImportGraphOptions): GraphBuilder {\n return new GraphBuilder({\n weightDtype: options.weightDtype ?? \"f64\",\n ...options.builder,\n directed: true,\n addMissingNodes: options.addMissingNodes ?? true,\n duplicateEdges: options.duplicateEdges ?? \"keep\",\n selfLoops: options.selfLoops ?? \"keep\",\n });\n}\n\n/**\n * Freeze an imported builder into an importGraph result.\n * @param chosen - the importer and its sniff\n * @param builder - the filled builder\n * @param report - the importer's report\n * @param options - the importGraph options\n * @returns the frozen result\n */\nfunction result(\n chosen: ChosenImporter,\n builder: GraphBuilder,\n report: ImportReport,\n options: ImportGraphOptions,\n): ImportGraphResult {\n const frozen = builder.freezeWithReport(options.freeze);\n return Object.freeze({\n format: chosen.importer.format,\n sniff: chosen.sniff,\n snapshot: frozen.snapshot,\n report,\n freeze: frozen.report,\n });\n}\n\n/**\n * The E_UNSUPPORTED error of a format name nothing is registered under.\n * @param kind - importer or exporter\n * @param format - the requested name\n * @param known - the registered names\n * @returns the error\n */\nfunction unknownFormat(kind: \"importer\" | \"exporter\", format: string, known: Iterable<string>): GraphFormatError {\n const supported = [...known];\n return new GraphFormatError(\n \"E_UNSUPPORTED\",\n `no ${kind} is registered for format ${JSON.stringify(format)}; known: ${supported.join(\", \")}`,\n { option: \"format\", found: format, supported },\n );\n}\n\n/**\n * The hints of an import, for the unknown-format message.\n * @param options - the importGraph options\n * @returns \" (filename ..., MIME type ...)\" or an empty string\n */\nfunction describeHints(options: ImportGraphOptions): string {\n const parts: string[] = [];\n if (typeof options.filename === \"string\" && options.filename.length > 0) {\n parts.push(`filename ${JSON.stringify(options.filename)}`);\n }\n if (typeof options.mimeType === \"string\" && options.mimeType.length > 0) {\n parts.push(`MIME type ${JSON.stringify(options.mimeType)}`);\n }\n return parts.length === 0 ? \"\" : ` (${parts.join(\", \")})`;\n}\n\n/** A head read from an input, and the input to hand the importer (the same bytes, replayed for a stream). */\ninterface PeekedInput {\n /** The first bytes (or, for a text input, characters) of the content. */\n readonly head: Uint8Array | string;\n /** The input to read: the original for in-memory input, a replaying iterable for a stream. */\n readonly input: ImportInput;\n /**\n * Close the source when the importer never iterated the replaying input (it threw first, an\n * abort for instance): a stream's reader is cancelled and released, an async generator finalised.\n * @returns when the source is closed\n */\n close(): Promise<void>;\n}\n\n/**\n * The first `bytes` of an input without consuming it: in-memory input is sliced; a stream or an\n * async iterable is read until enough is buffered and then replayed (the buffered chunks first,\n * the rest as it arrives) through a new async iterable that cancels the source when the importer\n * stops early.\n * @param input - the input\n * @param bytes - how much to peek\n * @param signal - the cancellation signal, or null\n * @returns the head and the input to read\n */\nasync function peekHead(input: ImportInput, bytes: number, signal: AbortSignal | null): Promise<PeekedInput> {\n if (typeof input === \"string\") {\n return { head: input.slice(0, bytes), input, close: (): Promise<void> => Promise.resolve() };\n }\n if (input instanceof Uint8Array) {\n return { head: input.subarray(0, bytes), input, close: (): Promise<void> => Promise.resolve() };\n }\n throwIfAborted(signal);\n const source: AsyncIterator<string | Uint8Array> =\n typeof (input as { getReader?: unknown }).getReader === \"function\"\n ? readerIterator(input as ReadableStream<Uint8Array>)\n : (input as AsyncIterable<string | Uint8Array>)[Symbol.asyncIterator]();\n const buffered: (string | Uint8Array)[] = [];\n let size = 0;\n let finished = false;\n while (size < bytes) {\n if (signal !== null && signal.aborted) {\n await source.return?.();\n throwIfAborted(signal);\n }\n const next = await source.next();\n if (next.done === true) {\n finished = true;\n break;\n }\n buffered.push(next.value);\n size += typeof next.value === \"string\" ? next.value.length : next.value.byteLength;\n }\n if (!finished && signal !== null && signal.aborted) {\n // an abort that landed on the read completing the head: close the source before rethrowing\n await source.return?.();\n throwIfAborted(signal);\n }\n const replayed = replay(buffered, source, finished);\n return { head: joinHead(buffered, bytes), input: replayed, close: (): Promise<void> => replayed.close() };\n}\n\n/**\n * The head text or bytes of the buffered chunks: bytes when every chunk is bytes, text otherwise\n * (byte chunks decoded leniently; the importer decodes the real input strictly).\n * @param chunks - the buffered chunks\n * @param bytes - the head size\n * @returns the head\n */\nfunction joinHead(chunks: readonly (string | Uint8Array)[], bytes: number): Uint8Array | string {\n if (chunks.every((c) => c instanceof Uint8Array)) {\n const total = Math.min(\n bytes,\n chunks.reduce((sum, c) => sum + c.byteLength, 0),\n );\n const head = new Uint8Array(total);\n let offset = 0;\n for (const chunk of chunks) {\n if (offset >= total) {\n break;\n }\n const part = chunk.subarray(0, Math.min(chunk.byteLength, total - offset));\n head.set(part, offset);\n offset += part.byteLength;\n }\n return head;\n }\n const decoder = new TextDecoder(\"utf-8\", { fatal: false });\n let text = \"\";\n for (const chunk of chunks) {\n text += typeof chunk === \"string\" ? chunk : decoder.decode(chunk, { stream: true });\n if (text.length >= bytes) {\n break;\n }\n }\n return text.slice(0, bytes);\n}\n\n/**\n * An async iterable that yields the buffered chunks, then the rest of the source; the source is\n * closed when the consumer stops early.\n * @param buffered - the chunks already read\n * @param source - the iterator positioned after them\n * @param finished - whether the source is already exhausted\n * @returns the replaying iterable\n */\nfunction replay(\n buffered: readonly (string | Uint8Array)[],\n source: AsyncIterator<string | Uint8Array>,\n finished: boolean,\n): AsyncIterable<string | Uint8Array> & { close(): Promise<void> } {\n let exhausted = finished;\n const close = async (): Promise<void> => {\n if (!exhausted) {\n exhausted = true;\n await source.return?.();\n }\n };\n return {\n close,\n [Symbol.asyncIterator](): AsyncIterator<string | Uint8Array> {\n let position = 0;\n return {\n async next(): Promise<IteratorResult<string | Uint8Array>> {\n if (position < buffered.length) {\n return { done: false, value: buffered[position++] };\n }\n if (exhausted) {\n return { done: true, value: undefined };\n }\n const next = await source.next();\n if (next.done === true) {\n exhausted = true;\n return { done: true, value: undefined };\n }\n return next;\n },\n async return(): Promise<IteratorResult<string | Uint8Array>> {\n await close();\n return { done: true, value: undefined };\n },\n };\n },\n };\n}\n\n/**\n * An async iterator over a ReadableStream's chunks that cancels the stream when closed early.\n * @param stream - the stream\n * @returns the iterator\n */\nfunction readerIterator(stream: ReadableStream<Uint8Array>): AsyncIterator<Uint8Array> {\n const reader = stream.getReader();\n let done = false;\n return {\n async next(): Promise<IteratorResult<Uint8Array>> {\n if (done) {\n return { done: true, value: undefined };\n }\n const result = await reader.read();\n if (result.done) {\n done = true;\n reader.releaseLock();\n return { done: true, value: undefined };\n }\n return { done: false, value: result.value };\n },\n async return(): Promise<IteratorResult<Uint8Array>> {\n if (!done) {\n done = true;\n await reader.cancel().catch(() => undefined);\n reader.releaseLock();\n }\n return { done: true, value: undefined };\n },\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A,MAAM,SAA8C;AAChD,UAAI,CAAC,MAAM;AACP,eAAO;AACP,cAAM,OAAO,OAAA,EAAS,MAAM,MAAM,MAAS;AAC3C,eAAO,YAAA;AAAA,MACX;AACA,aAAO,EAAE,MAAM,MAAM,OAAO,OAAA;AAAA,IAChC;AAAA,EAAA;AAER;"}
|
package/dist/graphml.js
CHANGED
package/dist/json.js
CHANGED
package/dist/neo4j.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { c as checkRecordSyntax, R as RecordReader, B as BAD_QUOTE_CODE, U as UNCLOSED_QUOTE_CODE } from "./chunks/records-
|
|
1
|
+
import { a1 as ROLE_TAKEN_CODE$1, u as ID_MERGED_CODE$1, o as DUPLICATE_NODE_CODE$1, M as MISSING_ENDPOINT_CODE$1, K as MISSING_ID_CODE$1, aC as resolveImportOptions, I as ImportReportBuilder, az as reportSinkOptions, aA as reportUnusedOptions, t as throwIfAborted, F as IdCoercer, p as DirectionResolver, J as ImportError, aI as declareAttribute, aV as declareOn, aE as uniqueColumnName, _ as RENAMED_CODE, aJ as parseDeclaredTemporal, aK as parseDeclaredValue, aL as losesPrecision, aq as declareCompanion, Z as PRECISION_CODE, aN as splitListText, aw as isImportInput, aW as takenIn, at as inputLength, v as ID_TEXT_COLLISION_CODE, w as ID_TEXT_TYPE_CODE, aB as resolveExportOptions, ax as pairFolding, aQ as mapDeclaredType, av as isCanonicalIntegerText, aS as formatTemporal, a2 as SINK_OPTION_CODE, U as OPTION_IGNORED_CODE, C as COLUMN_RENAMED_CODE, ad as UNKNOWN_ATTR_TYPE_CODE, af as UNKNOWN_ENCODING_CODE, r as ENCODING_FALLBACK_CODE, y as INVALID_ENCODING_CODE, z as INVALID_UTF8_CODE, ai as WEIGHT_KEY_CLASH_CODE, a0 as ROLE_DROPPED_CODE, R as MUTUAL_EXPANDED_CODE } from "./chunks/report-BcWboivV.js";
|
|
2
|
+
import { c as checkRecordSyntax, R as RecordReader, B as BAD_QUOTE_CODE, U as UNCLOSED_QUOTE_CODE } from "./chunks/records-BzNicMsf.js";
|
|
3
3
|
import { GraphFormatError, INVALID_INDEX } from "@graphty/graph-format";
|
|
4
|
-
import { m as quoteCsvCell } from "./chunks/escape-
|
|
5
|
-
import {
|
|
4
|
+
import { m as quoteCsvCell } from "./chunks/escape-CWExcecC.js";
|
|
5
|
+
import { c as capabilities, j as joinText, e as encodeChunks, a as checkCapabilities, L as LOSS } from "./chunks/writer-DQiKgQJc.js";
|
|
6
|
+
import { p as parseWeightText, e as explicitWeights, b as formatF64, a as formatF32, d as formatInteger } from "./chunks/weights-CwISIpCP.js";
|
|
6
7
|
const STRUCTURAL = /* @__PURE__ */ new Set(["ID", "LABEL", "START_ID", "END_ID", "TYPE", "IGNORE"]);
|
|
7
8
|
const SPACE_KINDS = /* @__PURE__ */ new Set(["ID", "START_ID", "END_ID"]);
|
|
8
9
|
const HEADER_MARKER = /^[^:{}()]*:\s*(ID|START_ID|END_ID)\s*(\(|\{|$)/i;
|