@graphty/graph-io 0.0.0 → 0.2.0
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/LICENSE +21 -0
- package/README.md +250 -28
- package/dist/chunks/children-CL3Cy0ez.js +238 -0
- package/dist/chunks/children-CL3Cy0ez.js.map +1 -0
- package/dist/chunks/escape-DyI8JofU.js +938 -0
- package/dist/chunks/escape-DyI8JofU.js.map +1 -0
- package/dist/chunks/importer-CQnJuWJw.js +2987 -0
- package/dist/chunks/importer-CQnJuWJw.js.map +1 -0
- package/dist/chunks/importer-CpCpfbxr.js +2015 -0
- package/dist/chunks/importer-CpCpfbxr.js.map +1 -0
- package/dist/chunks/importer-DbnGYr3_.js +2342 -0
- package/dist/chunks/importer-DbnGYr3_.js.map +1 -0
- package/dist/chunks/importer-GozH8DkN.js +3050 -0
- package/dist/chunks/importer-GozH8DkN.js.map +1 -0
- package/dist/chunks/records-CGpxszm1.js +605 -0
- package/dist/chunks/records-CGpxszm1.js.map +1 -0
- package/dist/chunks/text-CajMdVFy.js +189 -0
- package/dist/chunks/text-CajMdVFy.js.map +1 -0
- package/dist/chunks/writer-DxSKC7TL.js +2842 -0
- package/dist/chunks/writer-DxSKC7TL.js.map +1 -0
- package/dist/csv.d.ts +1 -0
- package/dist/csv.js +1702 -0
- package/dist/csv.js.map +1 -0
- package/dist/dot.d.ts +1 -0
- package/dist/dot.js +8 -0
- package/dist/dot.js.map +1 -0
- package/dist/gexf.d.ts +1 -0
- package/dist/gexf.js +3466 -0
- package/dist/gexf.js.map +1 -0
- package/dist/gml.d.ts +1 -0
- package/dist/gml.js +2647 -0
- package/dist/gml.js.map +1 -0
- package/dist/graph-io.d.ts +1 -0
- package/dist/graph-io.js +790 -0
- package/dist/graph-io.js.map +1 -0
- package/dist/graphml.d.ts +1 -0
- package/dist/graphml.js +8 -0
- package/dist/graphml.js.map +1 -0
- package/dist/json.d.ts +1 -0
- package/dist/json.js +11 -0
- package/dist/json.js.map +1 -0
- package/dist/neo4j.d.ts +1 -0
- package/dist/neo4j.js +2046 -0
- package/dist/neo4j.js.map +1 -0
- package/dist/pajek.d.ts +1 -0
- package/dist/pajek.js +8 -0
- package/dist/pajek.js.map +1 -0
- package/dist/src/children.d.ts +134 -0
- package/dist/src/children.d.ts.map +1 -0
- package/dist/src/children.js +274 -0
- package/dist/src/children.js.map +1 -0
- package/dist/src/common/attributes.d.ts +229 -0
- package/dist/src/common/attributes.d.ts.map +1 -0
- package/dist/src/common/attributes.js +368 -0
- package/dist/src/common/attributes.js.map +1 -0
- package/dist/src/common/codes.d.ts +105 -0
- package/dist/src/common/codes.d.ts.map +1 -0
- package/dist/src/common/codes.js +107 -0
- package/dist/src/common/codes.js.map +1 -0
- package/dist/src/common/declared-types.d.ts +84 -0
- package/dist/src/common/declared-types.d.ts.map +1 -0
- package/dist/src/common/declared-types.js +326 -0
- package/dist/src/common/declared-types.js.map +1 -0
- package/dist/src/common/direction.d.ts +206 -0
- package/dist/src/common/direction.d.ts.map +1 -0
- package/dist/src/common/direction.js +370 -0
- package/dist/src/common/direction.js.map +1 -0
- package/dist/src/common/escape.d.ts +92 -0
- package/dist/src/common/escape.d.ts.map +1 -0
- package/dist/src/common/escape.js +212 -0
- package/dist/src/common/escape.js.map +1 -0
- package/dist/src/common/export.d.ts +249 -0
- package/dist/src/common/export.d.ts.map +1 -0
- package/dist/src/common/export.js +594 -0
- package/dist/src/common/export.js.map +1 -0
- package/dist/src/common/format.d.ts +59 -0
- package/dist/src/common/format.d.ts.map +1 -0
- package/dist/src/common/format.js +106 -0
- package/dist/src/common/format.js.map +1 -0
- package/dist/src/common/ids.d.ts +83 -0
- package/dist/src/common/ids.d.ts.map +1 -0
- package/dist/src/common/ids.js +158 -0
- package/dist/src/common/ids.js.map +1 -0
- package/dist/src/common/input.d.ts +100 -0
- package/dist/src/common/input.d.ts.map +1 -0
- package/dist/src/common/input.js +335 -0
- package/dist/src/common/input.js.map +1 -0
- package/dist/src/common/lists.d.ts +34 -0
- package/dist/src/common/lists.d.ts.map +1 -0
- package/dist/src/common/lists.js +185 -0
- package/dist/src/common/lists.js.map +1 -0
- package/dist/src/common/options.d.ts +108 -0
- package/dist/src/common/options.d.ts.map +1 -0
- package/dist/src/common/options.js +265 -0
- package/dist/src/common/options.js.map +1 -0
- package/dist/src/common/report.d.ts +187 -0
- package/dist/src/common/report.d.ts.map +1 -0
- package/dist/src/common/report.js +274 -0
- package/dist/src/common/report.js.map +1 -0
- package/dist/src/common/temporal.d.ts +71 -0
- package/dist/src/common/temporal.d.ts.map +1 -0
- package/dist/src/common/temporal.js +266 -0
- package/dist/src/common/temporal.js.map +1 -0
- package/dist/src/common/text.d.ts +104 -0
- package/dist/src/common/text.d.ts.map +1 -0
- package/dist/src/common/text.js +255 -0
- package/dist/src/common/text.js.map +1 -0
- package/dist/src/common/weights.d.ts +77 -0
- package/dist/src/common/weights.d.ts.map +1 -0
- package/dist/src/common/weights.js +156 -0
- package/dist/src/common/weights.js.map +1 -0
- package/dist/src/common/writer.d.ts +51 -0
- package/dist/src/common/writer.d.ts.map +1 -0
- package/dist/src/common/writer.js +108 -0
- package/dist/src/common/writer.js.map +1 -0
- package/dist/src/common/xml.d.ts +245 -0
- package/dist/src/common/xml.d.ts.map +1 -0
- package/dist/src/common/xml.js +942 -0
- package/dist/src/common/xml.js.map +1 -0
- package/dist/src/formats/csv/exporter.d.ts +70 -0
- package/dist/src/formats/csv/exporter.d.ts.map +1 -0
- package/dist/src/formats/csv/exporter.js +682 -0
- package/dist/src/formats/csv/exporter.js.map +1 -0
- package/dist/src/formats/csv/header.d.ts +66 -0
- package/dist/src/formats/csv/header.d.ts.map +1 -0
- package/dist/src/formats/csv/header.js +152 -0
- package/dist/src/formats/csv/header.js.map +1 -0
- package/dist/src/formats/csv/importer.d.ts +82 -0
- package/dist/src/formats/csv/importer.d.ts.map +1 -0
- package/dist/src/formats/csv/importer.js +849 -0
- package/dist/src/formats/csv/importer.js.map +1 -0
- package/dist/src/formats/csv/index.d.ts +60 -0
- package/dist/src/formats/csv/index.d.ts.map +1 -0
- package/dist/src/formats/csv/index.js +63 -0
- package/dist/src/formats/csv/index.js.map +1 -0
- package/dist/src/formats/csv/records.d.ts +188 -0
- package/dist/src/formats/csv/records.d.ts.map +1 -0
- package/dist/src/formats/csv/records.js +702 -0
- package/dist/src/formats/csv/records.js.map +1 -0
- package/dist/src/formats/csv/values.d.ts +105 -0
- package/dist/src/formats/csv/values.d.ts.map +1 -0
- package/dist/src/formats/csv/values.js +192 -0
- package/dist/src/formats/csv/values.js.map +1 -0
- package/dist/src/formats/dot/exporter.d.ts +52 -0
- package/dist/src/formats/dot/exporter.d.ts.map +1 -0
- package/dist/src/formats/dot/exporter.js +836 -0
- package/dist/src/formats/dot/exporter.js.map +1 -0
- package/dist/src/formats/dot/importer.d.ts +102 -0
- package/dist/src/formats/dot/importer.d.ts.map +1 -0
- package/dist/src/formats/dot/importer.js +1291 -0
- package/dist/src/formats/dot/importer.js.map +1 -0
- package/dist/src/formats/dot/index.d.ts +7 -0
- package/dist/src/formats/dot/index.d.ts.map +1 -0
- package/dist/src/formats/dot/index.js +7 -0
- package/dist/src/formats/dot/index.js.map +1 -0
- package/dist/src/formats/dot/names.d.ts +29 -0
- package/dist/src/formats/dot/names.d.ts.map +1 -0
- package/dist/src/formats/dot/names.js +28 -0
- package/dist/src/formats/dot/names.js.map +1 -0
- package/dist/src/formats/dot/tokenizer.d.ts +114 -0
- package/dist/src/formats/dot/tokenizer.d.ts.map +1 -0
- package/dist/src/formats/dot/tokenizer.js +341 -0
- package/dist/src/formats/dot/tokenizer.js.map +1 -0
- package/dist/src/formats/gexf/exporter.d.ts +56 -0
- package/dist/src/formats/gexf/exporter.d.ts.map +1 -0
- package/dist/src/formats/gexf/exporter.js +1395 -0
- package/dist/src/formats/gexf/exporter.js.map +1 -0
- package/dist/src/formats/gexf/importer.d.ts +73 -0
- package/dist/src/formats/gexf/importer.d.ts.map +1 -0
- package/dist/src/formats/gexf/importer.js +1880 -0
- package/dist/src/formats/gexf/importer.js.map +1 -0
- package/dist/src/formats/gexf/index.d.ts +96 -0
- package/dist/src/formats/gexf/index.d.ts.map +1 -0
- package/dist/src/formats/gexf/index.js +97 -0
- package/dist/src/formats/gexf/index.js.map +1 -0
- package/dist/src/formats/gexf/schema.d.ts +135 -0
- package/dist/src/formats/gexf/schema.d.ts.map +1 -0
- package/dist/src/formats/gexf/schema.js +323 -0
- package/dist/src/formats/gexf/schema.js.map +1 -0
- package/dist/src/formats/gml/exporter.d.ts +69 -0
- package/dist/src/formats/gml/exporter.d.ts.map +1 -0
- package/dist/src/formats/gml/exporter.js +1093 -0
- package/dist/src/formats/gml/exporter.js.map +1 -0
- package/dist/src/formats/gml/importer.d.ts +66 -0
- package/dist/src/formats/gml/importer.d.ts.map +1 -0
- package/dist/src/formats/gml/importer.js +1331 -0
- package/dist/src/formats/gml/importer.js.map +1 -0
- package/dist/src/formats/gml/index.d.ts +85 -0
- package/dist/src/formats/gml/index.d.ts.map +1 -0
- package/dist/src/formats/gml/index.js +88 -0
- package/dist/src/formats/gml/index.js.map +1 -0
- package/dist/src/formats/gml/syntax.d.ts +186 -0
- package/dist/src/formats/gml/syntax.d.ts.map +1 -0
- package/dist/src/formats/gml/syntax.js +467 -0
- package/dist/src/formats/gml/syntax.js.map +1 -0
- package/dist/src/formats/graphml/constants.d.ts +169 -0
- package/dist/src/formats/graphml/constants.d.ts.map +1 -0
- package/dist/src/formats/graphml/constants.js +165 -0
- package/dist/src/formats/graphml/constants.js.map +1 -0
- package/dist/src/formats/graphml/exporter.d.ts +34 -0
- package/dist/src/formats/graphml/exporter.d.ts.map +1 -0
- package/dist/src/formats/graphml/exporter.js +1176 -0
- package/dist/src/formats/graphml/exporter.js.map +1 -0
- package/dist/src/formats/graphml/importer.d.ts +31 -0
- package/dist/src/formats/graphml/importer.d.ts.map +1 -0
- package/dist/src/formats/graphml/importer.js +1607 -0
- package/dist/src/formats/graphml/importer.js.map +1 -0
- package/dist/src/formats/graphml/index.d.ts +8 -0
- package/dist/src/formats/graphml/index.d.ts.map +1 -0
- package/dist/src/formats/graphml/index.js +8 -0
- package/dist/src/formats/graphml/index.js.map +1 -0
- package/dist/src/formats/graphml/tree.d.ts +72 -0
- package/dist/src/formats/graphml/tree.d.ts.map +1 -0
- package/dist/src/formats/graphml/tree.js +290 -0
- package/dist/src/formats/graphml/tree.js.map +1 -0
- package/dist/src/formats/json/dialect.d.ts +125 -0
- package/dist/src/formats/json/dialect.d.ts.map +1 -0
- package/dist/src/formats/json/dialect.js +262 -0
- package/dist/src/formats/json/dialect.js.map +1 -0
- package/dist/src/formats/json/exporter.d.ts +89 -0
- package/dist/src/formats/json/exporter.d.ts.map +1 -0
- package/dist/src/formats/json/exporter.js +1358 -0
- package/dist/src/formats/json/exporter.js.map +1 -0
- package/dist/src/formats/json/importer.d.ts +108 -0
- package/dist/src/formats/json/importer.d.ts.map +1 -0
- package/dist/src/formats/json/importer.js +1838 -0
- package/dist/src/formats/json/importer.js.map +1 -0
- package/dist/src/formats/json/index.d.ts +8 -0
- package/dist/src/formats/json/index.d.ts.map +1 -0
- package/dist/src/formats/json/index.js +8 -0
- package/dist/src/formats/json/index.js.map +1 -0
- package/dist/src/formats/neo4j/exporter.d.ts +68 -0
- package/dist/src/formats/neo4j/exporter.d.ts.map +1 -0
- package/dist/src/formats/neo4j/exporter.js +1055 -0
- package/dist/src/formats/neo4j/exporter.js.map +1 -0
- package/dist/src/formats/neo4j/header.d.ts +52 -0
- package/dist/src/formats/neo4j/header.d.ts.map +1 -0
- package/dist/src/formats/neo4j/header.js +131 -0
- package/dist/src/formats/neo4j/header.js.map +1 -0
- package/dist/src/formats/neo4j/importer.d.ts +73 -0
- package/dist/src/formats/neo4j/importer.d.ts.map +1 -0
- package/dist/src/formats/neo4j/importer.js +932 -0
- package/dist/src/formats/neo4j/importer.js.map +1 -0
- package/dist/src/formats/neo4j/index.d.ts +79 -0
- package/dist/src/formats/neo4j/index.d.ts.map +1 -0
- package/dist/src/formats/neo4j/index.js +83 -0
- package/dist/src/formats/neo4j/index.js.map +1 -0
- package/dist/src/formats/pajek/exporter.d.ts +58 -0
- package/dist/src/formats/pajek/exporter.d.ts.map +1 -0
- package/dist/src/formats/pajek/exporter.js +825 -0
- package/dist/src/formats/pajek/exporter.js.map +1 -0
- package/dist/src/formats/pajek/importer.d.ts +88 -0
- package/dist/src/formats/pajek/importer.d.ts.map +1 -0
- package/dist/src/formats/pajek/importer.js +1047 -0
- package/dist/src/formats/pajek/importer.js.map +1 -0
- package/dist/src/formats/pajek/index.d.ts +7 -0
- package/dist/src/formats/pajek/index.d.ts.map +1 -0
- package/dist/src/formats/pajek/index.js +7 -0
- package/dist/src/formats/pajek/index.js.map +1 -0
- package/dist/src/formats/pajek/syntax.d.ts +112 -0
- package/dist/src/formats/pajek/syntax.d.ts.map +1 -0
- package/dist/src/formats/pajek/syntax.js +269 -0
- package/dist/src/formats/pajek/syntax.js.map +1 -0
- package/dist/src/index.d.ts +35 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +39 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/registry.d.ts +207 -0
- package/dist/src/registry.d.ts.map +1 -0
- package/dist/src/registry.js +481 -0
- package/dist/src/registry.js.map +1 -0
- package/dist/src/sniff.d.ts +104 -0
- package/dist/src/sniff.d.ts.map +1 -0
- package/dist/src/sniff.js +357 -0
- package/dist/src/sniff.js.map +1 -0
- package/dist/src/types.d.ts +238 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +29 -0
- package/dist/src/types.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/package.json +122 -7
- package/src/children.ts +335 -0
- package/src/common/attributes.ts +520 -0
- package/src/common/codes.ts +153 -0
- package/src/common/declared-types.ts +374 -0
- package/src/common/direction.ts +518 -0
- package/src/common/escape.ts +231 -0
- package/src/common/export.ts +817 -0
- package/src/common/format.ts +111 -0
- package/src/common/ids.ts +176 -0
- package/src/common/input.ts +378 -0
- package/src/common/lists.ts +196 -0
- package/src/common/options.ts +377 -0
- package/src/common/report.ts +352 -0
- package/src/common/temporal.ts +302 -0
- package/src/common/text.ts +294 -0
- package/src/common/weights.ts +202 -0
- package/src/common/writer.ts +123 -0
- package/src/common/xml.ts +1053 -0
- package/src/formats/csv/exporter.ts +894 -0
- package/src/formats/csv/header.ts +172 -0
- package/src/formats/csv/importer.ts +1104 -0
- package/src/formats/csv/index.ts +88 -0
- package/src/formats/csv/records.ts +813 -0
- package/src/formats/csv/values.ts +224 -0
- package/src/formats/dot/exporter.ts +1014 -0
- package/src/formats/dot/importer.ts +1549 -0
- package/src/formats/dot/index.ts +7 -0
- package/src/formats/dot/names.ts +40 -0
- package/src/formats/dot/tokenizer.ts +384 -0
- package/src/formats/gexf/exporter.ts +1696 -0
- package/src/formats/gexf/importer.ts +2333 -0
- package/src/formats/gexf/index.ts +142 -0
- package/src/formats/gexf/schema.ts +361 -0
- package/src/formats/gml/exporter.ts +1404 -0
- package/src/formats/gml/importer.ts +1591 -0
- package/src/formats/gml/index.ts +128 -0
- package/src/formats/gml/syntax.ts +545 -0
- package/src/formats/graphml/constants.ts +225 -0
- package/src/formats/graphml/exporter.ts +1458 -0
- package/src/formats/graphml/importer.ts +2027 -0
- package/src/formats/graphml/index.ts +8 -0
- package/src/formats/graphml/tree.ts +318 -0
- package/src/formats/json/dialect.ts +317 -0
- package/src/formats/json/exporter.ts +1616 -0
- package/src/formats/json/importer.ts +2271 -0
- package/src/formats/json/index.ts +8 -0
- package/src/formats/neo4j/exporter.ts +1287 -0
- package/src/formats/neo4j/header.ts +156 -0
- package/src/formats/neo4j/importer.ts +1220 -0
- package/src/formats/neo4j/index.ts +116 -0
- package/src/formats/pajek/exporter.ts +1000 -0
- package/src/formats/pajek/importer.ts +1311 -0
- package/src/formats/pajek/index.ts +7 -0
- package/src/formats/pajek/syntax.ts +307 -0
- package/src/index.ts +244 -0
- package/src/registry.ts +617 -0
- package/src/sniff.ts +397 -0
- package/src/types.ts +262 -0
package/dist/graph-io.js
ADDED
|
@@ -0,0 +1,790 @@
|
|
|
1
|
+
import { I as ImportReportBuilder, a as throwIfAborted } from "./chunks/writer-DxSKC7TL.js";
|
|
2
|
+
import { B, b, C, c, d, D, e, f, g, h, i, j, k, l, E, m, H, n, o, p, q, r, s, u, L, v, M, w, x, y, z, A, F, N, G, O, J, P, K, Q, R, S, T, U, V, W, X, Y, Z, _, $, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, aa, ab, ac, ad, ae, af, ag, ah, ai, aj, ak, al, am, an, ao, ap, aq, ar, as, at, au, av, aw, ax, ay, az, aA, aB, aC, aD, t, aE } from "./chunks/writer-DxSKC7TL.js";
|
|
3
|
+
import { C as C2, c as c2, a } from "./chunks/children-CL3Cy0ez.js";
|
|
4
|
+
import { GraphBuilder, GraphFormatError } from "@graphty/graph-format";
|
|
5
|
+
import { csvImporter, csvExporter } from "./csv.js";
|
|
6
|
+
import { CSV_CAPABILITIES, CSV_ISSUE, CSV_LOSS } from "./csv.js";
|
|
7
|
+
import { b as dotImporter, d as dotExporter } from "./chunks/importer-DbnGYr3_.js";
|
|
8
|
+
import { D as D2, a as a10 } from "./chunks/importer-DbnGYr3_.js";
|
|
9
|
+
import { gexfImporter, gexfExporter } from "./gexf.js";
|
|
10
|
+
import { GEXF_1_2_CAPABILITIES, GEXF_ISSUE, GEXF_LOSS } from "./gexf.js";
|
|
11
|
+
import { gmlImporter, gmlExporter } from "./gml.js";
|
|
12
|
+
import { GML_ISSUE, GML_LOSS } from "./gml.js";
|
|
13
|
+
import { b as graphmlImporter, g as graphmlExporter } from "./chunks/importer-GozH8DkN.js";
|
|
14
|
+
import { G as G2, a as a11 } from "./chunks/importer-GozH8DkN.js";
|
|
15
|
+
import { s as sniffJsonDialect, e as jsonImporter, c as jsonExporter } from "./chunks/importer-CQnJuWJw.js";
|
|
16
|
+
import { J as J2, a as a12, b as b2, d as d2, j as j2 } from "./chunks/importer-CQnJuWJw.js";
|
|
17
|
+
import { neo4jImporter, neo4jExporter } from "./neo4j.js";
|
|
18
|
+
import { ID_SPACE_COLUMN, LABELS_COLUMN, NEO4J_CAPABILITIES, NEO4J_ISSUE, NEO4J_LOSS, TYPE_COLUMN } from "./neo4j.js";
|
|
19
|
+
import { b as pajekImporter, p as pajekExporter } from "./chunks/importer-CpCpfbxr.js";
|
|
20
|
+
import { P as P2, a as a13 } from "./chunks/importer-CpCpfbxr.js";
|
|
21
|
+
import { T as T2, W as W2, i as i2, a as a14, p as p2 } from "./chunks/text-CajMdVFy.js";
|
|
22
|
+
import { X as X2, a as a15, h as h2, t as t2, x as x2 } from "./chunks/escape-DyI8JofU.js";
|
|
23
|
+
const GRAPH_FORMATS = Object.freeze([
|
|
24
|
+
"json",
|
|
25
|
+
"graphml",
|
|
26
|
+
"gexf",
|
|
27
|
+
"csv",
|
|
28
|
+
"gml",
|
|
29
|
+
"dot",
|
|
30
|
+
"pajek",
|
|
31
|
+
"neo4j"
|
|
32
|
+
]);
|
|
33
|
+
const SNIFF_HEAD_BYTES = 8192;
|
|
34
|
+
function extensionOf(filename) {
|
|
35
|
+
const base = filename.slice(Math.max(filename.lastIndexOf("/"), filename.lastIndexOf("\\")) + 1);
|
|
36
|
+
const dot = base.lastIndexOf(".");
|
|
37
|
+
if (dot <= 0 || dot === base.length - 1) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
return base.slice(dot).toLowerCase();
|
|
41
|
+
}
|
|
42
|
+
function normalizeMimeType(mimeType) {
|
|
43
|
+
const semicolon = mimeType.indexOf(";");
|
|
44
|
+
return (semicolon < 0 ? mimeType : mimeType.slice(0, semicolon)).trim().toLowerCase();
|
|
45
|
+
}
|
|
46
|
+
function headBytes(head) {
|
|
47
|
+
if (typeof head === "string") {
|
|
48
|
+
return new TextEncoder().encode(head.slice(0, SNIFF_HEAD_BYTES)).subarray(0, SNIFF_HEAD_BYTES);
|
|
49
|
+
}
|
|
50
|
+
return head.byteLength > SNIFF_HEAD_BYTES ? head.subarray(0, SNIFF_HEAD_BYTES) : head;
|
|
51
|
+
}
|
|
52
|
+
function rankFormats(hints, importers) {
|
|
53
|
+
const extension = typeof hints.filename === "string" ? extensionOf(hints.filename) : null;
|
|
54
|
+
const mime = typeof hints.mimeType === "string" ? normalizeMimeType(hints.mimeType) : null;
|
|
55
|
+
const head = hints.head === void 0 || hints.head === null ? null : headBytes(hints.head);
|
|
56
|
+
const candidates = [];
|
|
57
|
+
let rank = 0;
|
|
58
|
+
for (const importer of importers) {
|
|
59
|
+
const extensionMatch = extension !== null && importer.extensions.some((e2) => e2.toLowerCase() === extension);
|
|
60
|
+
const mimeMatch = mime !== null && importer.mimeTypes.some((m2) => m2.toLowerCase() === mime);
|
|
61
|
+
let content = 0;
|
|
62
|
+
if (head !== null && head.byteLength > 0 && typeof importer.sniff === "function") {
|
|
63
|
+
content = clamp(importer.sniff(head));
|
|
64
|
+
}
|
|
65
|
+
let confidence;
|
|
66
|
+
if (content > 0) {
|
|
67
|
+
confidence = 0.5 + 0.35 * content + (extensionMatch ? 0.1 : 0) + (mimeMatch ? 0.05 : 0);
|
|
68
|
+
} else if (extensionMatch || mimeMatch) {
|
|
69
|
+
confidence = (extensionMatch ? 0.3 : 0) + (mimeMatch ? 0.1 : 0);
|
|
70
|
+
} else {
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
const dialect = importer.format === "json" && head !== null ? sniffJsonDialectHead(head) : null;
|
|
74
|
+
const result = Object.freeze({
|
|
75
|
+
format: importer.format,
|
|
76
|
+
confidence: Math.min(1, confidence),
|
|
77
|
+
content,
|
|
78
|
+
extension: extensionMatch,
|
|
79
|
+
mimeType: mimeMatch,
|
|
80
|
+
dialect
|
|
81
|
+
});
|
|
82
|
+
candidates.push({ result, rank: rank++ });
|
|
83
|
+
}
|
|
84
|
+
candidates.sort((a16, b3) => b3.result.confidence - a16.result.confidence || a16.rank - b3.rank);
|
|
85
|
+
return candidates.map((c3) => c3.result);
|
|
86
|
+
}
|
|
87
|
+
function sniffFormat(hints, importers) {
|
|
88
|
+
const ranked = rankFormats(hints, importers);
|
|
89
|
+
return ranked.length > 0 ? ranked[0] : null;
|
|
90
|
+
}
|
|
91
|
+
function sniffJsonDialectHead(head) {
|
|
92
|
+
const text = typeof head === "string" ? head : new TextDecoder("utf-8", { fatal: false }).decode(head);
|
|
93
|
+
const body = text.charCodeAt(0) === 65279 ? text.slice(1) : text;
|
|
94
|
+
const trimmed = body.trimStart();
|
|
95
|
+
if (!trimmed.startsWith("{") && !trimmed.startsWith("[")) {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
let root;
|
|
99
|
+
try {
|
|
100
|
+
root = JSON.parse(trimmed);
|
|
101
|
+
} catch {
|
|
102
|
+
root = skeletonOf(trimmed);
|
|
103
|
+
}
|
|
104
|
+
return sniffJsonDialect(root);
|
|
105
|
+
}
|
|
106
|
+
function skeletonOf(text) {
|
|
107
|
+
const keys = scanKeys(text);
|
|
108
|
+
if (text.startsWith("[")) {
|
|
109
|
+
const first = keys.get("nodes[0]");
|
|
110
|
+
return first === void 0 ? null : [objectOf(first)];
|
|
111
|
+
}
|
|
112
|
+
const rootKeys = keys.get("");
|
|
113
|
+
if (rootKeys === void 0) {
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
const root = {};
|
|
117
|
+
for (const key of rootKeys) {
|
|
118
|
+
switch (key) {
|
|
119
|
+
case "graph":
|
|
120
|
+
case "options":
|
|
121
|
+
root[key] = objectOf(keys.get(key));
|
|
122
|
+
break;
|
|
123
|
+
case "graphs":
|
|
124
|
+
root[key] = [];
|
|
125
|
+
break;
|
|
126
|
+
case "nodes":
|
|
127
|
+
case "edges":
|
|
128
|
+
case "links": {
|
|
129
|
+
const first = keys.get(`${key}[0]`);
|
|
130
|
+
root[key] = first === void 0 ? [] : [objectOf(first)];
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
default:
|
|
134
|
+
root[key] = true;
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return root;
|
|
139
|
+
}
|
|
140
|
+
function objectOf(names) {
|
|
141
|
+
const out = {};
|
|
142
|
+
if (names !== void 0) {
|
|
143
|
+
for (const name of names) {
|
|
144
|
+
out[name] = name === "attributes" || name === "data" ? {} : true;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return out;
|
|
148
|
+
}
|
|
149
|
+
function scanKeys(text) {
|
|
150
|
+
const found = /* @__PURE__ */ new Map();
|
|
151
|
+
const kinds = [];
|
|
152
|
+
const labels = [];
|
|
153
|
+
const counts = [];
|
|
154
|
+
let pendingKey = null;
|
|
155
|
+
let expectingKey = false;
|
|
156
|
+
const pathOf = () => {
|
|
157
|
+
const depth = kinds.length;
|
|
158
|
+
if (depth === 1) {
|
|
159
|
+
return kinds[0] === "object" ? "" : null;
|
|
160
|
+
}
|
|
161
|
+
if (depth === 2 && kinds[0] === "array" && kinds[1] === "object" && labels[1] === "0") {
|
|
162
|
+
return "nodes[0]";
|
|
163
|
+
}
|
|
164
|
+
if (depth === 2 && kinds[0] === "object" && kinds[1] === "object") {
|
|
165
|
+
return labels[1] === "graph" || labels[1] === "options" ? labels[1] : null;
|
|
166
|
+
}
|
|
167
|
+
if (depth === 3 && kinds[0] === "object" && kinds[1] === "array" && kinds[2] === "object") {
|
|
168
|
+
const section = labels[1];
|
|
169
|
+
if ((section === "nodes" || section === "edges" || section === "links") && labels[2] === "0") {
|
|
170
|
+
return `${section}[0]`;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return null;
|
|
174
|
+
};
|
|
175
|
+
let i3 = 0;
|
|
176
|
+
const n2 = text.length;
|
|
177
|
+
while (i3 < n2) {
|
|
178
|
+
const ch = text[i3];
|
|
179
|
+
if (ch === '"') {
|
|
180
|
+
const end = scanString(text, i3 + 1);
|
|
181
|
+
if (end < 0) {
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
const literal = text.slice(i3 + 1, end);
|
|
185
|
+
i3 = end + 1;
|
|
186
|
+
if (expectingKey) {
|
|
187
|
+
pendingKey = decodeKey(literal);
|
|
188
|
+
expectingKey = false;
|
|
189
|
+
}
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
if (ch === "{" || ch === "[") {
|
|
193
|
+
let label = "";
|
|
194
|
+
if (kinds.length > 0) {
|
|
195
|
+
label = kinds[kinds.length - 1] === "object" ? pendingKey ?? "" : String(counts[counts.length - 1]);
|
|
196
|
+
}
|
|
197
|
+
kinds.push(ch === "{" ? "object" : "array");
|
|
198
|
+
labels.push(label);
|
|
199
|
+
counts.push(0);
|
|
200
|
+
expectingKey = ch === "{";
|
|
201
|
+
pendingKey = null;
|
|
202
|
+
} else if (ch === "}" || ch === "]") {
|
|
203
|
+
kinds.pop();
|
|
204
|
+
labels.pop();
|
|
205
|
+
counts.pop();
|
|
206
|
+
expectingKey = false;
|
|
207
|
+
pendingKey = null;
|
|
208
|
+
} else if (ch === ":") {
|
|
209
|
+
if (pendingKey !== null) {
|
|
210
|
+
const path = pathOf();
|
|
211
|
+
if (path !== null) {
|
|
212
|
+
let set = found.get(path);
|
|
213
|
+
if (set === void 0) {
|
|
214
|
+
set = /* @__PURE__ */ new Set();
|
|
215
|
+
found.set(path, set);
|
|
216
|
+
}
|
|
217
|
+
set.add(pendingKey);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
} else if (ch === ",") {
|
|
221
|
+
const top = kinds.length - 1;
|
|
222
|
+
if (top >= 0) {
|
|
223
|
+
counts[top]++;
|
|
224
|
+
expectingKey = kinds[top] === "object";
|
|
225
|
+
}
|
|
226
|
+
pendingKey = null;
|
|
227
|
+
}
|
|
228
|
+
i3++;
|
|
229
|
+
}
|
|
230
|
+
return found;
|
|
231
|
+
}
|
|
232
|
+
function scanString(text, from) {
|
|
233
|
+
let i3 = from;
|
|
234
|
+
while (i3 < text.length) {
|
|
235
|
+
const ch = text[i3];
|
|
236
|
+
if (ch === "\\") {
|
|
237
|
+
i3 += 2;
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
if (ch === '"') {
|
|
241
|
+
return i3;
|
|
242
|
+
}
|
|
243
|
+
i3++;
|
|
244
|
+
}
|
|
245
|
+
return -1;
|
|
246
|
+
}
|
|
247
|
+
function decodeKey(literal) {
|
|
248
|
+
if (!literal.includes("\\")) {
|
|
249
|
+
return literal;
|
|
250
|
+
}
|
|
251
|
+
try {
|
|
252
|
+
return JSON.parse(`"${literal}"`);
|
|
253
|
+
} catch {
|
|
254
|
+
return literal;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
function clamp(value) {
|
|
258
|
+
if (!(value > 0)) {
|
|
259
|
+
return 0;
|
|
260
|
+
}
|
|
261
|
+
return value > 1 ? 1 : value;
|
|
262
|
+
}
|
|
263
|
+
const UNKNOWN_FORMAT_CODE = "E_UNKNOWN_FORMAT";
|
|
264
|
+
const REGISTRY_KEYS = /* @__PURE__ */ new Set(["format", "filename", "mimeType", "builder", "freeze"]);
|
|
265
|
+
class FormatRegistry {
|
|
266
|
+
constructor() {
|
|
267
|
+
this.importerMap = /* @__PURE__ */ new Map();
|
|
268
|
+
this.exporterMap = /* @__PURE__ */ new Map();
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Register an importer under its format name, replacing one of the same name in place (the
|
|
272
|
+
* original registration order is kept).
|
|
273
|
+
* @param importer - the importer
|
|
274
|
+
* @returns this registry, for chaining
|
|
275
|
+
*/
|
|
276
|
+
registerImporter(importer) {
|
|
277
|
+
this.importerMap.set(importer.format, importer);
|
|
278
|
+
return this;
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Register an exporter under its format name, replacing one of the same name.
|
|
282
|
+
* @param exporter - the exporter
|
|
283
|
+
* @returns this registry, for chaining
|
|
284
|
+
*/
|
|
285
|
+
registerExporter(exporter) {
|
|
286
|
+
this.exporterMap.set(exporter.format, exporter);
|
|
287
|
+
return this;
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* The importer of a format.
|
|
291
|
+
* @param format - the format name
|
|
292
|
+
* @returns the importer; E_UNSUPPORTED when none is registered
|
|
293
|
+
*/
|
|
294
|
+
importer(format) {
|
|
295
|
+
const importer = this.importerMap.get(format);
|
|
296
|
+
if (importer === void 0) {
|
|
297
|
+
throw unknownFormat("importer", format, this.importerMap.keys());
|
|
298
|
+
}
|
|
299
|
+
return importer;
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* The exporter of a format.
|
|
303
|
+
* @param format - the format name
|
|
304
|
+
* @returns the exporter; E_UNSUPPORTED when none is registered
|
|
305
|
+
*/
|
|
306
|
+
exporter(format) {
|
|
307
|
+
const exporter = this.exporterMap.get(format);
|
|
308
|
+
if (exporter === void 0) {
|
|
309
|
+
throw unknownFormat("exporter", format, this.exporterMap.keys());
|
|
310
|
+
}
|
|
311
|
+
return exporter;
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Whether an importer is registered for a format.
|
|
315
|
+
* @param format - the format name
|
|
316
|
+
* @returns true when importer(format) would succeed
|
|
317
|
+
*/
|
|
318
|
+
hasImporter(format) {
|
|
319
|
+
return this.importerMap.has(format);
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Whether an exporter is registered for a format.
|
|
323
|
+
* @param format - the format name
|
|
324
|
+
* @returns true when exporter(format) would succeed
|
|
325
|
+
*/
|
|
326
|
+
hasExporter(format) {
|
|
327
|
+
return this.exporterMap.has(format);
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Every registered importer, in registration order.
|
|
331
|
+
* @returns the importers
|
|
332
|
+
*/
|
|
333
|
+
importers() {
|
|
334
|
+
return [...this.importerMap.values()];
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Every registered exporter, in registration order.
|
|
338
|
+
* @returns the exporters
|
|
339
|
+
*/
|
|
340
|
+
exporters() {
|
|
341
|
+
return [...this.exporterMap.values()];
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* The names of every format with an importer or an exporter, importers' order first.
|
|
345
|
+
* @returns the format names, each once
|
|
346
|
+
*/
|
|
347
|
+
formats() {
|
|
348
|
+
return [.../* @__PURE__ */ new Set([...this.importerMap.keys(), ...this.exporterMap.keys()])];
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Rank the registered importers for an input (design section 8.2; the successor of
|
|
352
|
+
* graphty-element's detectFormat()).
|
|
353
|
+
* @param hints - the filename, MIME type and / or head of the input
|
|
354
|
+
* @returns the candidates, best first; empty when nothing matches
|
|
355
|
+
*/
|
|
356
|
+
sniffAll(hints) {
|
|
357
|
+
return rankFormats(hints, this.importerMap.values());
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* The best importer for an input, or null when no registered importer claims it.
|
|
361
|
+
* @param hints - the filename, MIME type and / or head of the input
|
|
362
|
+
* @returns the best candidate, or null
|
|
363
|
+
*/
|
|
364
|
+
sniff(hints) {
|
|
365
|
+
const ranked = this.sniffAll(hints);
|
|
366
|
+
return ranked.length > 0 ? ranked[0] : null;
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* Read an input into a fresh builder and freeze it (design section 8.4: for callers who do not
|
|
370
|
+
* own a sink). The format is the one named in the options, else sniffed from the filename,
|
|
371
|
+
* the MIME type and the first bytes of the content; the builder is seeded from the common
|
|
372
|
+
* options with `directed: true` as a placeholder that the importer overrides from the file.
|
|
373
|
+
* @param input - the text, bytes, stream or chunks to read
|
|
374
|
+
* @param options - the format, hints, common and format-specific import options
|
|
375
|
+
* @returns the snapshot, the import report and the freeze report
|
|
376
|
+
*/
|
|
377
|
+
async importGraph(input, options = {}) {
|
|
378
|
+
const requested = options.format ?? "auto";
|
|
379
|
+
let importer;
|
|
380
|
+
let sniff2 = null;
|
|
381
|
+
let source = input;
|
|
382
|
+
let peeked = null;
|
|
383
|
+
if (requested === "auto") {
|
|
384
|
+
peeked = await peekHead(input, SNIFF_HEAD_BYTES, options.signal ?? null);
|
|
385
|
+
source = peeked.input;
|
|
386
|
+
sniff2 = this.sniff({ filename: options.filename, mimeType: options.mimeType, head: peeked.head });
|
|
387
|
+
if (sniff2 === null) {
|
|
388
|
+
const report2 = new ImportReportBuilder("unknown", 0);
|
|
389
|
+
return report2.fail(
|
|
390
|
+
UNKNOWN_FORMAT_CODE,
|
|
391
|
+
`no registered importer recognises the input${describeHints(options)}; pass the format explicitly`,
|
|
392
|
+
void 0,
|
|
393
|
+
{ formats: this.formats() }
|
|
394
|
+
);
|
|
395
|
+
}
|
|
396
|
+
importer = this.importer(sniff2.format);
|
|
397
|
+
} else {
|
|
398
|
+
importer = this.importer(requested);
|
|
399
|
+
}
|
|
400
|
+
const builder = new GraphBuilder({
|
|
401
|
+
weightDtype: options.weightDtype ?? "f64",
|
|
402
|
+
...options.builder,
|
|
403
|
+
directed: true,
|
|
404
|
+
addMissingNodes: options.addMissingNodes ?? true,
|
|
405
|
+
duplicateEdges: options.duplicateEdges ?? "keep",
|
|
406
|
+
selfLoops: options.selfLoops ?? "keep"
|
|
407
|
+
});
|
|
408
|
+
let report;
|
|
409
|
+
try {
|
|
410
|
+
report = await importer.import(source, builder, importerOptions(options));
|
|
411
|
+
} catch (err) {
|
|
412
|
+
await peeked?.close();
|
|
413
|
+
throw err;
|
|
414
|
+
}
|
|
415
|
+
const frozen = builder.freezeWithReport(options.freeze);
|
|
416
|
+
return Object.freeze({
|
|
417
|
+
format: importer.format,
|
|
418
|
+
sniff: sniff2,
|
|
419
|
+
snapshot: frozen.snapshot,
|
|
420
|
+
report,
|
|
421
|
+
freeze: frozen.report
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Write a snapshot in a format, as UTF-8 chunks (design section 8.5).
|
|
426
|
+
* @param snapshot - the snapshot
|
|
427
|
+
* @param format - the format name
|
|
428
|
+
* @param options - the exporter's common and format-specific options
|
|
429
|
+
* @returns the encoded chunks
|
|
430
|
+
*/
|
|
431
|
+
exportGraph(snapshot, format, options) {
|
|
432
|
+
return this.exporter(format).export(snapshot, options);
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* Write a snapshot in a format, as one string.
|
|
436
|
+
* @param snapshot - the snapshot
|
|
437
|
+
* @param format - the format name
|
|
438
|
+
* @param options - the exporter's common and format-specific options
|
|
439
|
+
* @returns the whole document
|
|
440
|
+
*/
|
|
441
|
+
async exportGraphToString(snapshot, format, options) {
|
|
442
|
+
return this.exporter(format).exportToString(snapshot, options);
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* What exporting a snapshot in a format would lose, without writing anything.
|
|
446
|
+
* @param snapshot - the snapshot
|
|
447
|
+
* @param format - the format name
|
|
448
|
+
* @param options - the exporter's common and format-specific options
|
|
449
|
+
* @returns the loss notes, empty when the export is exact
|
|
450
|
+
*/
|
|
451
|
+
checkExport(snapshot, format, options) {
|
|
452
|
+
return this.exporter(format).check(snapshot, options);
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
function createRegistry() {
|
|
456
|
+
return new FormatRegistry().registerImporter(jsonImporter).registerExporter(jsonExporter).registerImporter(graphmlImporter).registerExporter(graphmlExporter).registerImporter(gexfImporter).registerExporter(gexfExporter).registerImporter(csvImporter).registerExporter(csvExporter).registerImporter(gmlImporter).registerExporter(gmlExporter).registerImporter(dotImporter).registerExporter(dotExporter).registerImporter(pajekImporter).registerExporter(pajekExporter).registerImporter(neo4jImporter).registerExporter(neo4jExporter);
|
|
457
|
+
}
|
|
458
|
+
const registry = createRegistry();
|
|
459
|
+
function importGraph(input, options) {
|
|
460
|
+
return registry.importGraph(input, options);
|
|
461
|
+
}
|
|
462
|
+
function exportGraph(snapshot, format, options) {
|
|
463
|
+
return registry.exportGraph(snapshot, format, options);
|
|
464
|
+
}
|
|
465
|
+
async function exportGraphToString(snapshot, format, options) {
|
|
466
|
+
return registry.exportGraphToString(snapshot, format, options);
|
|
467
|
+
}
|
|
468
|
+
function checkExport(snapshot, format, options) {
|
|
469
|
+
return registry.checkExport(snapshot, format, options);
|
|
470
|
+
}
|
|
471
|
+
function sniff(hints) {
|
|
472
|
+
return registry.sniff(hints);
|
|
473
|
+
}
|
|
474
|
+
function importerOptions(options) {
|
|
475
|
+
const out = {};
|
|
476
|
+
for (const [key, value] of Object.entries(options)) {
|
|
477
|
+
if (!REGISTRY_KEYS.has(key)) {
|
|
478
|
+
out[key] = value;
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
return out;
|
|
482
|
+
}
|
|
483
|
+
function unknownFormat(kind, format, known) {
|
|
484
|
+
const supported = [...known];
|
|
485
|
+
return new GraphFormatError(
|
|
486
|
+
"E_UNSUPPORTED",
|
|
487
|
+
`no ${kind} is registered for format ${JSON.stringify(format)}; known: ${supported.join(", ")}`,
|
|
488
|
+
{ option: "format", found: format, supported }
|
|
489
|
+
);
|
|
490
|
+
}
|
|
491
|
+
function describeHints(options) {
|
|
492
|
+
const parts = [];
|
|
493
|
+
if (typeof options.filename === "string" && options.filename.length > 0) {
|
|
494
|
+
parts.push(`filename ${JSON.stringify(options.filename)}`);
|
|
495
|
+
}
|
|
496
|
+
if (typeof options.mimeType === "string" && options.mimeType.length > 0) {
|
|
497
|
+
parts.push(`MIME type ${JSON.stringify(options.mimeType)}`);
|
|
498
|
+
}
|
|
499
|
+
return parts.length === 0 ? "" : ` (${parts.join(", ")})`;
|
|
500
|
+
}
|
|
501
|
+
async function peekHead(input, bytes, signal) {
|
|
502
|
+
if (typeof input === "string") {
|
|
503
|
+
return { head: input.slice(0, bytes), input, close: () => Promise.resolve() };
|
|
504
|
+
}
|
|
505
|
+
if (input instanceof Uint8Array) {
|
|
506
|
+
return { head: input.subarray(0, bytes), input, close: () => Promise.resolve() };
|
|
507
|
+
}
|
|
508
|
+
throwIfAborted(signal);
|
|
509
|
+
const source = typeof input.getReader === "function" ? readerIterator(input) : input[Symbol.asyncIterator]();
|
|
510
|
+
const buffered = [];
|
|
511
|
+
let size = 0;
|
|
512
|
+
let finished = false;
|
|
513
|
+
while (size < bytes) {
|
|
514
|
+
if (signal !== null && signal.aborted) {
|
|
515
|
+
await source.return?.();
|
|
516
|
+
throwIfAborted(signal);
|
|
517
|
+
}
|
|
518
|
+
const next = await source.next();
|
|
519
|
+
if (next.done === true) {
|
|
520
|
+
finished = true;
|
|
521
|
+
break;
|
|
522
|
+
}
|
|
523
|
+
buffered.push(next.value);
|
|
524
|
+
size += typeof next.value === "string" ? next.value.length : next.value.byteLength;
|
|
525
|
+
}
|
|
526
|
+
if (!finished && signal !== null && signal.aborted) {
|
|
527
|
+
await source.return?.();
|
|
528
|
+
throwIfAborted(signal);
|
|
529
|
+
}
|
|
530
|
+
const replayed = replay(buffered, source, finished);
|
|
531
|
+
return { head: joinHead(buffered, bytes), input: replayed, close: () => replayed.close() };
|
|
532
|
+
}
|
|
533
|
+
function joinHead(chunks, bytes) {
|
|
534
|
+
if (chunks.every((c3) => c3 instanceof Uint8Array)) {
|
|
535
|
+
const total = Math.min(
|
|
536
|
+
bytes,
|
|
537
|
+
chunks.reduce((sum, c3) => sum + c3.byteLength, 0)
|
|
538
|
+
);
|
|
539
|
+
const head = new Uint8Array(total);
|
|
540
|
+
let offset = 0;
|
|
541
|
+
for (const chunk of chunks) {
|
|
542
|
+
if (offset >= total) {
|
|
543
|
+
break;
|
|
544
|
+
}
|
|
545
|
+
const part = chunk.subarray(0, Math.min(chunk.byteLength, total - offset));
|
|
546
|
+
head.set(part, offset);
|
|
547
|
+
offset += part.byteLength;
|
|
548
|
+
}
|
|
549
|
+
return head;
|
|
550
|
+
}
|
|
551
|
+
const decoder = new TextDecoder("utf-8", { fatal: false });
|
|
552
|
+
let text = "";
|
|
553
|
+
for (const chunk of chunks) {
|
|
554
|
+
text += typeof chunk === "string" ? chunk : decoder.decode(chunk, { stream: true });
|
|
555
|
+
if (text.length >= bytes) {
|
|
556
|
+
break;
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
return text.slice(0, bytes);
|
|
560
|
+
}
|
|
561
|
+
function replay(buffered, source, finished) {
|
|
562
|
+
let exhausted = finished;
|
|
563
|
+
const close = async () => {
|
|
564
|
+
if (!exhausted) {
|
|
565
|
+
exhausted = true;
|
|
566
|
+
await source.return?.();
|
|
567
|
+
}
|
|
568
|
+
};
|
|
569
|
+
return {
|
|
570
|
+
close,
|
|
571
|
+
[Symbol.asyncIterator]() {
|
|
572
|
+
let position = 0;
|
|
573
|
+
return {
|
|
574
|
+
async next() {
|
|
575
|
+
if (position < buffered.length) {
|
|
576
|
+
return { done: false, value: buffered[position++] };
|
|
577
|
+
}
|
|
578
|
+
if (exhausted) {
|
|
579
|
+
return { done: true, value: void 0 };
|
|
580
|
+
}
|
|
581
|
+
const next = await source.next();
|
|
582
|
+
if (next.done === true) {
|
|
583
|
+
exhausted = true;
|
|
584
|
+
return { done: true, value: void 0 };
|
|
585
|
+
}
|
|
586
|
+
return next;
|
|
587
|
+
},
|
|
588
|
+
async return() {
|
|
589
|
+
await close();
|
|
590
|
+
return { done: true, value: void 0 };
|
|
591
|
+
}
|
|
592
|
+
};
|
|
593
|
+
}
|
|
594
|
+
};
|
|
595
|
+
}
|
|
596
|
+
function readerIterator(stream) {
|
|
597
|
+
const reader = stream.getReader();
|
|
598
|
+
let done = false;
|
|
599
|
+
return {
|
|
600
|
+
async next() {
|
|
601
|
+
if (done) {
|
|
602
|
+
return { done: true, value: void 0 };
|
|
603
|
+
}
|
|
604
|
+
const result = await reader.read();
|
|
605
|
+
if (result.done) {
|
|
606
|
+
done = true;
|
|
607
|
+
reader.releaseLock();
|
|
608
|
+
return { done: true, value: void 0 };
|
|
609
|
+
}
|
|
610
|
+
return { done: false, value: result.value };
|
|
611
|
+
},
|
|
612
|
+
async return() {
|
|
613
|
+
if (!done) {
|
|
614
|
+
done = true;
|
|
615
|
+
await reader.cancel().catch(() => void 0);
|
|
616
|
+
reader.releaseLock();
|
|
617
|
+
}
|
|
618
|
+
return { done: true, value: void 0 };
|
|
619
|
+
}
|
|
620
|
+
};
|
|
621
|
+
}
|
|
622
|
+
export {
|
|
623
|
+
B as BAD_DEFAULT_CODE,
|
|
624
|
+
b as BAD_OPTIONS_CODE,
|
|
625
|
+
C as COLUMN_RENAMED_CODE,
|
|
626
|
+
c as COLUMN_RENAMED_LOSS_CODE,
|
|
627
|
+
d as COUNT_HINT_CODE,
|
|
628
|
+
CSV_CAPABILITIES,
|
|
629
|
+
CSV_ISSUE,
|
|
630
|
+
CSV_LOSS,
|
|
631
|
+
C2 as ChildrenCsr,
|
|
632
|
+
D as DEFAULT_CHUNK_BYTES,
|
|
633
|
+
e as DEFAULT_ERROR_LIMIT,
|
|
634
|
+
f as DIRECTED_COLUMN,
|
|
635
|
+
g as DIRECTION_FORCED_CODE,
|
|
636
|
+
h as DIRECTION_REFUSED_CODE,
|
|
637
|
+
D2 as DOT_ISSUE,
|
|
638
|
+
a10 as DOT_LOSS,
|
|
639
|
+
i as DUPLICATE_EDGE_ID_CODE,
|
|
640
|
+
j as DUPLICATE_KEY_CODE,
|
|
641
|
+
k as DUPLICATE_NODE_CODE,
|
|
642
|
+
l as DirectionResolver,
|
|
643
|
+
E as EMPTY_COLUMN_DROPPED_CODE,
|
|
644
|
+
m as EMPTY_INPUT_CODE,
|
|
645
|
+
FormatRegistry,
|
|
646
|
+
GEXF_1_2_CAPABILITIES,
|
|
647
|
+
GEXF_ISSUE,
|
|
648
|
+
GEXF_LOSS,
|
|
649
|
+
GML_ISSUE,
|
|
650
|
+
GML_LOSS,
|
|
651
|
+
G2 as GRAPHML_ISSUE,
|
|
652
|
+
a11 as GRAPHML_LOSS,
|
|
653
|
+
GRAPH_FORMATS,
|
|
654
|
+
H as HYPEREDGE_CODE,
|
|
655
|
+
n as ID_MERGED_CODE,
|
|
656
|
+
ID_SPACE_COLUMN,
|
|
657
|
+
o as ID_TEXT_COLLISION_CODE,
|
|
658
|
+
p as ID_TEXT_TYPE_CODE,
|
|
659
|
+
q as INTEGRAL_F64_CODE,
|
|
660
|
+
r as INVALID_UTF8_CODE,
|
|
661
|
+
s as IdCoercer,
|
|
662
|
+
u as ImportError,
|
|
663
|
+
ImportReportBuilder,
|
|
664
|
+
J2 as JSON_DIALECTS,
|
|
665
|
+
a12 as JSON_ISSUE,
|
|
666
|
+
b2 as JSON_LOSS,
|
|
667
|
+
LABELS_COLUMN,
|
|
668
|
+
L as LOSS,
|
|
669
|
+
v as LineReader,
|
|
670
|
+
M as MISSING_ENDPOINT_CODE,
|
|
671
|
+
w as MISSING_ID_CODE,
|
|
672
|
+
x as MIXED_DIRECTION_CODE,
|
|
673
|
+
y as MULTIPLE_GRAPHS_CODE,
|
|
674
|
+
z as MUTUAL_AS_UNDIRECTED_CODE,
|
|
675
|
+
A as MUTUAL_COLUMN,
|
|
676
|
+
F as MUTUAL_EXPANDED_CODE,
|
|
677
|
+
NEO4J_CAPABILITIES,
|
|
678
|
+
NEO4J_ISSUE,
|
|
679
|
+
NEO4J_LOSS,
|
|
680
|
+
N as NO_CAPABILITIES,
|
|
681
|
+
G as NO_GRAPH_CODE,
|
|
682
|
+
O as OPTIONS_GAINED_CODE,
|
|
683
|
+
J as OPTION_IGNORED_CODE,
|
|
684
|
+
P as PAIR_COLUMN,
|
|
685
|
+
P2 as PAJEK_ISSUE,
|
|
686
|
+
a13 as PAJEK_LOSS,
|
|
687
|
+
K as PARENTS_DROPPED_CODE,
|
|
688
|
+
Q as PARSE_ERROR_CODE,
|
|
689
|
+
R as PRECISION_CODE,
|
|
690
|
+
S as RENAMED_CODE,
|
|
691
|
+
T as ROLE_ASSUMED_CODE,
|
|
692
|
+
U as ROLE_DROPPED_CODE,
|
|
693
|
+
V as ROLE_TAKEN_CODE,
|
|
694
|
+
W as SINK_OPTION_CODE,
|
|
695
|
+
SNIFF_HEAD_BYTES,
|
|
696
|
+
X as STORAGE_CLASS_CODE,
|
|
697
|
+
Y as STRAY_TEXT_CODE,
|
|
698
|
+
Z as SYNTAX_CODE,
|
|
699
|
+
_ as TEMPORAL_DROPPED_CODE,
|
|
700
|
+
$ as TEMPORAL_TEXT_DROPPED_CODE,
|
|
701
|
+
a0 as TEXT_INFERRED_CODE,
|
|
702
|
+
TYPE_COLUMN,
|
|
703
|
+
T2 as TextCellWriter,
|
|
704
|
+
a1 as UNKNOWN_ATTR_TYPE_CODE,
|
|
705
|
+
a2 as UNKNOWN_ELEMENT_CODE,
|
|
706
|
+
UNKNOWN_FORMAT_CODE,
|
|
707
|
+
a3 as UNKNOWN_PARENT_CODE,
|
|
708
|
+
a4 as UNKNOWN_TYPE_CODE,
|
|
709
|
+
a5 as WEIGHT_KEY_CLASH_CODE,
|
|
710
|
+
W2 as WIDENING_UNSUPPORTED_CODE,
|
|
711
|
+
a6 as XML_ILLEGAL_CHAR_CODE,
|
|
712
|
+
a7 as XML_SYNTAX_CODE,
|
|
713
|
+
X2 as XmlSyntaxError,
|
|
714
|
+
a15 as XmlTokenizer,
|
|
715
|
+
a8 as canonicalId,
|
|
716
|
+
a9 as capabilities,
|
|
717
|
+
aa as checkCapabilities,
|
|
718
|
+
checkExport,
|
|
719
|
+
c2 as childrenCsr,
|
|
720
|
+
a as childrenFromColumn,
|
|
721
|
+
ab as coerceId,
|
|
722
|
+
ac as coerceIdText,
|
|
723
|
+
ad as collectBytes,
|
|
724
|
+
createRegistry,
|
|
725
|
+
csvExporter,
|
|
726
|
+
csvImporter,
|
|
727
|
+
ae as declareCompanion,
|
|
728
|
+
af as declareResolved,
|
|
729
|
+
ag as decodeChunks,
|
|
730
|
+
d2 as dialectCapabilities,
|
|
731
|
+
dotExporter,
|
|
732
|
+
dotImporter,
|
|
733
|
+
ah as encodeChunks,
|
|
734
|
+
ai as explicitWeights,
|
|
735
|
+
exportGraph,
|
|
736
|
+
exportGraphToString,
|
|
737
|
+
extensionOf,
|
|
738
|
+
aj as formatDecimal,
|
|
739
|
+
ak as formatF32,
|
|
740
|
+
al as formatF64,
|
|
741
|
+
am as formatGmlReal,
|
|
742
|
+
an as formatInteger,
|
|
743
|
+
gexfExporter,
|
|
744
|
+
gexfImporter,
|
|
745
|
+
gmlExporter,
|
|
746
|
+
gmlImporter,
|
|
747
|
+
graphmlExporter,
|
|
748
|
+
graphmlImporter,
|
|
749
|
+
h2 as hasIllegalXmlChar,
|
|
750
|
+
headBytes,
|
|
751
|
+
importGraph,
|
|
752
|
+
i2 as inferTextDtype,
|
|
753
|
+
ao as inputLength,
|
|
754
|
+
ap as isAbortError,
|
|
755
|
+
aq as isCanonicalIntegerText,
|
|
756
|
+
ar as isImportInput,
|
|
757
|
+
as as isNmtoken,
|
|
758
|
+
a14 as isNumericText,
|
|
759
|
+
at as isWeightField,
|
|
760
|
+
au as joinText,
|
|
761
|
+
j2 as jsonCapabilities,
|
|
762
|
+
jsonExporter,
|
|
763
|
+
jsonImporter,
|
|
764
|
+
av as mangleNmtoken,
|
|
765
|
+
neo4jExporter,
|
|
766
|
+
neo4jImporter,
|
|
767
|
+
normalizeMimeType,
|
|
768
|
+
aw as pairFolding,
|
|
769
|
+
pajekExporter,
|
|
770
|
+
pajekImporter,
|
|
771
|
+
p2 as parseTextCell,
|
|
772
|
+
ax as parseWeightText,
|
|
773
|
+
rankFormats,
|
|
774
|
+
ay as readText,
|
|
775
|
+
registry,
|
|
776
|
+
az as reportSinkOptions,
|
|
777
|
+
aA as reportUnusedOptions,
|
|
778
|
+
aB as resolveExportOptions,
|
|
779
|
+
aC as resolveImportOptions,
|
|
780
|
+
aD as sanitizeIds,
|
|
781
|
+
sniff,
|
|
782
|
+
sniffFormat,
|
|
783
|
+
sniffJsonDialectHead,
|
|
784
|
+
t as textChunks,
|
|
785
|
+
throwIfAborted,
|
|
786
|
+
aE as toReadableStream,
|
|
787
|
+
t2 as tokenizeXml,
|
|
788
|
+
x2 as xmlIllegalTextNotes
|
|
789
|
+
};
|
|
790
|
+
//# sourceMappingURL=graph-io.js.map
|