@graphty/graph-io 0.3.43 → 0.3.45
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/dist/chunks/approximations-DJMHdDvv.js +40 -0
- package/dist/chunks/approximations-DJMHdDvv.js.map +1 -0
- package/dist/chunks/block-CPCHkX42.js +2777 -0
- package/dist/chunks/block-CPCHkX42.js.map +1 -0
- package/dist/chunks/{choose-DvpbdRuz.js → choose--jM0yYCo.js} +3 -2
- package/dist/chunks/{choose-DvpbdRuz.js.map → choose--jM0yYCo.js.map} +1 -1
- package/dist/chunks/{constants-fT3E8JYY.js → constants-BKwqelYD.js} +6 -2
- package/dist/chunks/constants-BKwqelYD.js.map +1 -0
- package/dist/chunks/convert-BcQ8_jMo.js +59 -0
- package/dist/chunks/convert-BcQ8_jMo.js.map +1 -0
- package/dist/chunks/emit-DZy6JgdA.js +3456 -0
- package/dist/chunks/emit-DZy6JgdA.js.map +1 -0
- package/dist/chunks/{escape-B62ZGM_a.js → escape-CgzxiYPg.js} +44 -21
- package/dist/chunks/escape-CgzxiYPg.js.map +1 -0
- package/dist/chunks/{export-rKLeGQMo.js → export-BvqAXCKh.js} +196 -792
- package/dist/chunks/export-BvqAXCKh.js.map +1 -0
- package/dist/chunks/{exporter-yLxKBvLE.js → exporter--Mk9gXCJ.js} +4 -3
- package/dist/chunks/{exporter-yLxKBvLE.js.map → exporter--Mk9gXCJ.js.map} +1 -1
- package/dist/chunks/{exporter-RVtXVetw.js → exporter-C-9cgZKa.js} +1805 -287
- package/dist/chunks/exporter-C-9cgZKa.js.map +1 -0
- package/dist/chunks/{exporter-8hLNemFk.js → exporter-DFqJhBnj.js} +133 -74
- package/dist/chunks/exporter-DFqJhBnj.js.map +1 -0
- package/dist/chunks/{exporter-BWwEuOPT.js → exporter-DteVeJki.js} +22 -12
- package/dist/chunks/exporter-DteVeJki.js.map +1 -0
- package/dist/chunks/format-BpQBx8MZ.js +676 -0
- package/dist/chunks/format-BpQBx8MZ.js.map +1 -0
- package/dist/chunks/generic-BGO71QBv.js +1347 -0
- package/dist/chunks/generic-BGO71QBv.js.map +1 -0
- package/dist/chunks/{importer-C98dpSH4.js → importer-B-9Rc1zO.js} +141 -82
- package/dist/chunks/importer-B-9Rc1zO.js.map +1 -0
- package/dist/chunks/{importer-D794XUTe.js → importer-BVVR740x.js} +31 -8
- package/dist/chunks/importer-BVVR740x.js.map +1 -0
- package/dist/chunks/{importer-WrGRZb0N.js → importer-C0AjA3Ax.js} +449 -102
- package/dist/chunks/importer-C0AjA3Ax.js.map +1 -0
- package/dist/chunks/{importer-BbNb7eNg.js → importer-C7pvJe1L.js} +1398 -129
- package/dist/chunks/importer-C7pvJe1L.js.map +1 -0
- package/dist/chunks/{importer-xZ-3suY1.js → importer-ClwoVx3O.js} +791 -135
- package/dist/chunks/importer-ClwoVx3O.js.map +1 -0
- package/dist/chunks/{importer-Ht7LNg8L.js → importer-D0sC_6bO.js} +116 -296
- package/dist/chunks/importer-D0sC_6bO.js.map +1 -0
- package/dist/chunks/{importer-Dz7tI8Sa.js → importer-EHQk1jbM.js} +617 -115
- package/dist/chunks/importer-EHQk1jbM.js.map +1 -0
- package/dist/chunks/{json-elements-DKSqpNW1.js → json-elements-DJZRZ6jd.js} +123 -32
- package/dist/chunks/json-elements-DJZRZ6jd.js.map +1 -0
- package/dist/chunks/lexicon-WMsNddyU.js +509 -0
- package/dist/chunks/lexicon-WMsNddyU.js.map +1 -0
- package/dist/chunks/{ontology-export-CtRXjg_i.js → ontology-export-G4MqRdux.js} +3 -2
- package/dist/chunks/{ontology-export-CtRXjg_i.js.map → ontology-export-G4MqRdux.js.map} +1 -1
- package/dist/chunks/{records-Cu4bxYOm.js → records-CiaWZrFH.js} +2 -2
- package/dist/chunks/{records-Cu4bxYOm.js.map → records-CiaWZrFH.js.map} +1 -1
- package/dist/chunks/styles-DvoFBKCK.js +690 -0
- package/dist/chunks/styles-DvoFBKCK.js.map +1 -0
- package/dist/chunks/styles-yed-Cz9rLBCP.js +842 -0
- package/dist/chunks/styles-yed-Cz9rLBCP.js.map +1 -0
- package/dist/chunks/styles-zNTmz5R7.js +2102 -0
- package/dist/chunks/styles-zNTmz5R7.js.map +1 -0
- package/dist/chunks/{text-DHOJXnED.js → text-CzJNFOS9.js} +2 -2
- package/dist/chunks/{text-DHOJXnED.js.map → text-CzJNFOS9.js.map} +1 -1
- package/dist/chunks/units-XMZFIFe1.js +19 -0
- package/dist/chunks/units-XMZFIFe1.js.map +1 -0
- package/dist/chunks/writer-gQ8kx99H.js +448 -0
- package/dist/chunks/writer-gQ8kx99H.js.map +1 -0
- package/dist/csv.js +5 -4
- package/dist/csv.js.map +1 -1
- package/dist/cx.js +1 -1
- package/dist/cx2.js +2 -2
- package/dist/cys.js +1 -1
- package/dist/dot.js +5 -2
- package/dist/dot.js.map +1 -1
- package/dist/gexf.js +292 -412
- package/dist/gexf.js.map +1 -1
- package/dist/gml.js +927 -74
- package/dist/gml.js.map +1 -1
- package/dist/graph-io.js +351 -236
- package/dist/graph-io.js.map +1 -1
- package/dist/graphml.js +4 -2
- package/dist/graphml.js.map +1 -1
- package/dist/json.js +1 -1
- package/dist/neo4j.js +4 -3
- package/dist/neo4j.js.map +1 -1
- package/dist/obo.js +1 -1
- package/dist/pajek.js +4 -2
- package/dist/positions.d.ts +1 -0
- package/dist/positions.js +427 -0
- package/dist/positions.js.map +1 -0
- package/dist/src/common/codes.d.ts +6 -0
- package/dist/src/common/codes.d.ts.map +1 -1
- package/dist/src/common/codes.js +6 -0
- package/dist/src/common/codes.js.map +1 -1
- package/dist/src/common/escape.d.ts.map +1 -1
- package/dist/src/common/escape.js +4 -2
- package/dist/src/common/escape.js.map +1 -1
- package/dist/src/common/export.d.ts +10 -0
- package/dist/src/common/export.d.ts.map +1 -1
- package/dist/src/common/export.js +123 -100
- package/dist/src/common/export.js.map +1 -1
- package/dist/src/common/input.d.ts.map +1 -1
- package/dist/src/common/input.js +8 -1
- package/dist/src/common/input.js.map +1 -1
- package/dist/src/common/json-elements.d.ts +12 -9
- package/dist/src/common/json-elements.d.ts.map +1 -1
- package/dist/src/common/json-elements.js +160 -37
- package/dist/src/common/json-elements.js.map +1 -1
- package/dist/src/common/notes.d.ts +42 -0
- package/dist/src/common/notes.d.ts.map +1 -0
- package/dist/src/common/notes.js +72 -0
- package/dist/src/common/notes.js.map +1 -0
- package/dist/src/common/report.d.ts +18 -0
- package/dist/src/common/report.d.ts.map +1 -1
- package/dist/src/common/report.js +36 -1
- package/dist/src/common/report.js.map +1 -1
- package/dist/src/common/units.d.ts +24 -0
- package/dist/src/common/units.d.ts.map +1 -0
- package/dist/src/common/units.js +26 -0
- package/dist/src/common/units.js.map +1 -0
- package/dist/src/common/xml.d.ts +18 -0
- package/dist/src/common/xml.d.ts.map +1 -1
- package/dist/src/common/xml.js +42 -5
- package/dist/src/common/xml.js.map +1 -1
- package/dist/src/formats/cx/exporter.d.ts +6 -0
- package/dist/src/formats/cx/exporter.d.ts.map +1 -1
- package/dist/src/formats/cx/exporter.js +71 -8
- package/dist/src/formats/cx/exporter.js.map +1 -1
- package/dist/src/formats/cx/importer.d.ts +5 -2
- package/dist/src/formats/cx/importer.d.ts.map +1 -1
- package/dist/src/formats/cx/importer.js +102 -72
- package/dist/src/formats/cx/importer.js.map +1 -1
- package/dist/src/formats/cx/styles.d.ts +102 -0
- package/dist/src/formats/cx/styles.d.ts.map +1 -0
- package/dist/src/formats/cx/styles.js +225 -0
- package/dist/src/formats/cx/styles.js.map +1 -0
- package/dist/src/formats/cx2/exporter.d.ts +5 -0
- package/dist/src/formats/cx2/exporter.d.ts.map +1 -1
- package/dist/src/formats/cx2/exporter.js +181 -71
- package/dist/src/formats/cx2/exporter.js.map +1 -1
- package/dist/src/formats/cx2/importer.d.ts +4 -1
- package/dist/src/formats/cx2/importer.d.ts.map +1 -1
- package/dist/src/formats/cx2/importer.js +19 -1
- package/dist/src/formats/cx2/importer.js.map +1 -1
- package/dist/src/formats/cx2/styles.d.ts +18 -0
- package/dist/src/formats/cx2/styles.d.ts.map +1 -0
- package/dist/src/formats/cx2/styles.js +24 -0
- package/dist/src/formats/cx2/styles.js.map +1 -0
- package/dist/src/formats/cys/constants.d.ts +2 -0
- package/dist/src/formats/cys/constants.d.ts.map +1 -1
- package/dist/src/formats/cys/constants.js +2 -0
- package/dist/src/formats/cys/constants.js.map +1 -1
- package/dist/src/formats/cys/exporter.d.ts +6 -2
- package/dist/src/formats/cys/exporter.d.ts.map +1 -1
- package/dist/src/formats/cys/exporter.js +215 -53
- package/dist/src/formats/cys/exporter.js.map +1 -1
- package/dist/src/formats/cys/importer.d.ts +2 -1
- package/dist/src/formats/cys/importer.d.ts.map +1 -1
- package/dist/src/formats/cys/importer.js +119 -6
- package/dist/src/formats/cys/importer.js.map +1 -1
- package/dist/src/formats/cys/session.d.ts +2 -0
- package/dist/src/formats/cys/session.d.ts.map +1 -1
- package/dist/src/formats/cys/session.js +5 -0
- package/dist/src/formats/cys/session.js.map +1 -1
- package/dist/src/formats/cys/styles.d.ts +38 -0
- package/dist/src/formats/cys/styles.d.ts.map +1 -0
- package/dist/src/formats/cys/styles.js +213 -0
- package/dist/src/formats/cys/styles.js.map +1 -0
- package/dist/src/formats/cys/tables.d.ts +8 -3
- package/dist/src/formats/cys/tables.d.ts.map +1 -1
- package/dist/src/formats/cys/tables.js +88 -34
- package/dist/src/formats/cys/tables.js.map +1 -1
- package/dist/src/formats/dot/exporter.d.ts +2 -0
- package/dist/src/formats/dot/exporter.d.ts.map +1 -1
- package/dist/src/formats/dot/exporter.js +195 -81
- package/dist/src/formats/dot/exporter.js.map +1 -1
- package/dist/src/formats/dot/importer.d.ts.map +1 -1
- package/dist/src/formats/dot/importer.js +100 -20
- package/dist/src/formats/dot/importer.js.map +1 -1
- package/dist/src/formats/dot/index.d.ts +1 -0
- package/dist/src/formats/dot/index.d.ts.map +1 -1
- package/dist/src/formats/dot/index.js +1 -0
- package/dist/src/formats/dot/index.js.map +1 -1
- package/dist/src/formats/dot/positions.d.ts +14 -0
- package/dist/src/formats/dot/positions.d.ts.map +1 -0
- package/dist/src/formats/dot/positions.js +70 -0
- package/dist/src/formats/dot/positions.js.map +1 -0
- package/dist/src/formats/dot/styles.d.ts +82 -0
- package/dist/src/formats/dot/styles.d.ts.map +1 -0
- package/dist/src/formats/dot/styles.js +1496 -0
- package/dist/src/formats/dot/styles.js.map +1 -0
- package/dist/src/formats/gexf/exporter.d.ts.map +1 -1
- package/dist/src/formats/gexf/exporter.js +20 -5
- package/dist/src/formats/gexf/exporter.js.map +1 -1
- package/dist/src/formats/gexf/importer.d.ts +8 -1
- package/dist/src/formats/gexf/importer.d.ts.map +1 -1
- package/dist/src/formats/gexf/importer.js +251 -131
- package/dist/src/formats/gexf/importer.js.map +1 -1
- package/dist/src/formats/gexf/index.d.ts +8 -0
- package/dist/src/formats/gexf/index.d.ts.map +1 -1
- package/dist/src/formats/gexf/index.js +10 -2
- package/dist/src/formats/gexf/index.js.map +1 -1
- package/dist/src/formats/gexf/schema.d.ts +5 -0
- package/dist/src/formats/gexf/schema.d.ts.map +1 -1
- package/dist/src/formats/gexf/schema.js +5 -0
- package/dist/src/formats/gexf/schema.js.map +1 -1
- package/dist/src/formats/gexf/styles.d.ts +74 -0
- package/dist/src/formats/gexf/styles.d.ts.map +1 -0
- package/dist/src/formats/gexf/styles.js +604 -0
- package/dist/src/formats/gexf/styles.js.map +1 -0
- package/dist/src/formats/gml/exporter.d.ts +1 -5
- package/dist/src/formats/gml/exporter.d.ts.map +1 -1
- package/dist/src/formats/gml/exporter.js +19 -8
- package/dist/src/formats/gml/exporter.js.map +1 -1
- package/dist/src/formats/gml/importer.d.ts.map +1 -1
- package/dist/src/formats/gml/importer.js +4 -0
- package/dist/src/formats/gml/importer.js.map +1 -1
- package/dist/src/formats/gml/index.d.ts +2 -1
- package/dist/src/formats/gml/index.d.ts.map +1 -1
- package/dist/src/formats/gml/index.js +2 -1
- package/dist/src/formats/gml/index.js.map +1 -1
- package/dist/src/formats/gml/positions.d.ts +14 -0
- package/dist/src/formats/gml/positions.d.ts.map +1 -0
- package/dist/src/formats/gml/positions.js +46 -0
- package/dist/src/formats/gml/positions.js.map +1 -0
- package/dist/src/formats/gml/styles.d.ts +59 -0
- package/dist/src/formats/gml/styles.d.ts.map +1 -0
- package/dist/src/formats/gml/styles.js +1056 -0
- package/dist/src/formats/gml/styles.js.map +1 -0
- package/dist/src/formats/gml/syntax.d.ts +11 -0
- package/dist/src/formats/gml/syntax.d.ts.map +1 -1
- package/dist/src/formats/gml/syntax.js +151 -62
- package/dist/src/formats/gml/syntax.js.map +1 -1
- package/dist/src/formats/graphml/constants.d.ts +4 -0
- package/dist/src/formats/graphml/constants.d.ts.map +1 -1
- package/dist/src/formats/graphml/constants.js +5 -1
- package/dist/src/formats/graphml/constants.js.map +1 -1
- package/dist/src/formats/graphml/exporter.d.ts.map +1 -1
- package/dist/src/formats/graphml/exporter.js +133 -65
- package/dist/src/formats/graphml/exporter.js.map +1 -1
- package/dist/src/formats/graphml/importer.d.ts +4 -1
- package/dist/src/formats/graphml/importer.d.ts.map +1 -1
- package/dist/src/formats/graphml/importer.js +100 -44
- package/dist/src/formats/graphml/importer.js.map +1 -1
- package/dist/src/formats/graphml/index.d.ts +1 -0
- package/dist/src/formats/graphml/index.d.ts.map +1 -1
- package/dist/src/formats/graphml/index.js +1 -0
- package/dist/src/formats/graphml/index.js.map +1 -1
- package/dist/src/formats/graphml/styles-plain.d.ts +19 -0
- package/dist/src/formats/graphml/styles-plain.d.ts.map +1 -0
- package/dist/src/formats/graphml/styles-plain.js +187 -0
- package/dist/src/formats/graphml/styles-plain.js.map +1 -0
- package/dist/src/formats/graphml/styles-yed.d.ts +179 -0
- package/dist/src/formats/graphml/styles-yed.d.ts.map +1 -0
- package/dist/src/formats/graphml/styles-yed.js +1086 -0
- package/dist/src/formats/graphml/styles-yed.js.map +1 -0
- package/dist/src/formats/graphml/styles-yfiles3.d.ts +19 -0
- package/dist/src/formats/graphml/styles-yfiles3.d.ts.map +1 -0
- package/dist/src/formats/graphml/styles-yfiles3.js +508 -0
- package/dist/src/formats/graphml/styles-yfiles3.js.map +1 -0
- package/dist/src/formats/graphml/tree.d.ts.map +1 -1
- package/dist/src/formats/graphml/tree.js +34 -19
- package/dist/src/formats/graphml/tree.js.map +1 -1
- package/dist/src/formats/graphml/yfiles.d.ts +16 -2
- package/dist/src/formats/graphml/yfiles.d.ts.map +1 -1
- package/dist/src/formats/graphml/yfiles.js +83 -12
- package/dist/src/formats/graphml/yfiles.js.map +1 -1
- package/dist/src/formats/json/exporter.d.ts +5 -0
- package/dist/src/formats/json/exporter.d.ts.map +1 -1
- package/dist/src/formats/json/exporter.js +68 -25
- package/dist/src/formats/json/exporter.js.map +1 -1
- package/dist/src/formats/json/importer.d.ts +22 -3
- package/dist/src/formats/json/importer.d.ts.map +1 -1
- package/dist/src/formats/json/importer.js +439 -264
- package/dist/src/formats/json/importer.js.map +1 -1
- package/dist/src/formats/json/positions.d.ts +16 -0
- package/dist/src/formats/json/positions.d.ts.map +1 -0
- package/dist/src/formats/json/positions.js +44 -0
- package/dist/src/formats/json/positions.js.map +1 -0
- package/dist/src/formats/json/styles.d.ts +102 -0
- package/dist/src/formats/json/styles.d.ts.map +1 -0
- package/dist/src/formats/json/styles.js +1753 -0
- package/dist/src/formats/json/styles.js.map +1 -0
- package/dist/src/formats/neo4j/exporter.d.ts.map +1 -1
- package/dist/src/formats/neo4j/exporter.js +2 -1
- package/dist/src/formats/neo4j/exporter.js.map +1 -1
- package/dist/src/formats/pajek/exporter.d.ts +2 -0
- package/dist/src/formats/pajek/exporter.d.ts.map +1 -1
- package/dist/src/formats/pajek/exporter.js +142 -76
- package/dist/src/formats/pajek/exporter.js.map +1 -1
- package/dist/src/formats/pajek/importer.d.ts +4 -0
- package/dist/src/formats/pajek/importer.d.ts.map +1 -1
- package/dist/src/formats/pajek/importer.js +60 -6
- package/dist/src/formats/pajek/importer.js.map +1 -1
- package/dist/src/formats/pajek/index.d.ts +2 -0
- package/dist/src/formats/pajek/index.d.ts.map +1 -1
- package/dist/src/formats/pajek/index.js +2 -0
- package/dist/src/formats/pajek/index.js.map +1 -1
- package/dist/src/formats/pajek/styles.d.ts +50 -0
- package/dist/src/formats/pajek/styles.d.ts.map +1 -0
- package/dist/src/formats/pajek/styles.js +569 -0
- package/dist/src/formats/pajek/styles.js.map +1 -0
- package/dist/src/formats/pajek/syntax.d.ts +6 -0
- package/dist/src/formats/pajek/syntax.d.ts.map +1 -1
- package/dist/src/formats/pajek/syntax.js +6 -0
- package/dist/src/formats/pajek/syntax.js.map +1 -1
- package/dist/src/formats/xgmml/columns.d.ts.map +1 -1
- package/dist/src/formats/xgmml/columns.js +34 -9
- package/dist/src/formats/xgmml/columns.js.map +1 -1
- package/dist/src/formats/xgmml/constants.d.ts +2 -0
- package/dist/src/formats/xgmml/constants.d.ts.map +1 -1
- package/dist/src/formats/xgmml/constants.js +3 -1
- package/dist/src/formats/xgmml/constants.js.map +1 -1
- package/dist/src/formats/xgmml/document.d.ts +12 -8
- package/dist/src/formats/xgmml/document.d.ts.map +1 -1
- package/dist/src/formats/xgmml/document.js +56 -13
- package/dist/src/formats/xgmml/document.js.map +1 -1
- package/dist/src/formats/xgmml/emit.d.ts.map +1 -1
- package/dist/src/formats/xgmml/emit.js +12 -6
- package/dist/src/formats/xgmml/emit.js.map +1 -1
- package/dist/src/formats/xgmml/exporter.d.ts +3 -1
- package/dist/src/formats/xgmml/exporter.d.ts.map +1 -1
- package/dist/src/formats/xgmml/exporter.js +22 -9
- package/dist/src/formats/xgmml/exporter.js.map +1 -1
- package/dist/src/formats/xgmml/importer.d.ts +2 -1
- package/dist/src/formats/xgmml/importer.d.ts.map +1 -1
- package/dist/src/formats/xgmml/importer.js +31 -24
- package/dist/src/formats/xgmml/importer.js.map +1 -1
- package/dist/src/formats/xgmml/styles.d.ts +104 -0
- package/dist/src/formats/xgmml/styles.d.ts.map +1 -0
- package/dist/src/formats/xgmml/styles.js +310 -0
- package/dist/src/formats/xgmml/styles.js.map +1 -0
- package/dist/src/index.d.ts +9 -7
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +7 -7
- package/dist/src/index.js.map +1 -1
- package/dist/src/positions/codes.d.ts +31 -0
- package/dist/src/positions/codes.d.ts.map +1 -0
- package/dist/src/positions/codes.js +26 -0
- package/dist/src/positions/codes.js.map +1 -0
- package/dist/src/positions/convert.d.ts +58 -0
- package/dist/src/positions/convert.d.ts.map +1 -0
- package/dist/src/positions/convert.js +107 -0
- package/dist/src/positions/convert.js.map +1 -0
- package/dist/src/positions/extract.d.ts +27 -0
- package/dist/src/positions/extract.d.ts.map +1 -0
- package/dist/src/positions/extract.js +526 -0
- package/dist/src/positions/extract.js.map +1 -0
- package/dist/src/positions/index.d.ts +10 -0
- package/dist/src/positions/index.d.ts.map +1 -0
- package/dist/src/positions/index.js +9 -0
- package/dist/src/positions/index.js.map +1 -0
- package/dist/src/positions/types.d.ts +208 -0
- package/dist/src/positions/types.d.ts.map +1 -0
- package/dist/src/positions/types.js +10 -0
- package/dist/src/positions/types.js.map +1 -0
- package/dist/src/registry.d.ts +30 -0
- package/dist/src/registry.d.ts.map +1 -1
- package/dist/src/registry.js +130 -9
- package/dist/src/registry.js.map +1 -1
- package/dist/src/styles/annotations.d.ts +132 -0
- package/dist/src/styles/annotations.d.ts.map +1 -0
- package/dist/src/styles/annotations.js +320 -0
- package/dist/src/styles/annotations.js.map +1 -0
- package/dist/src/styles/budget.d.ts +45 -0
- package/dist/src/styles/budget.d.ts.map +1 -0
- package/dist/src/styles/budget.js +58 -0
- package/dist/src/styles/budget.js.map +1 -0
- package/dist/src/styles/canon/bends.d.ts +32 -0
- package/dist/src/styles/canon/bends.d.ts.map +1 -0
- package/dist/src/styles/canon/bends.js +74 -0
- package/dist/src/styles/canon/bends.js.map +1 -0
- package/dist/src/styles/canon/color-tables.d.ts +22 -0
- package/dist/src/styles/canon/color-tables.d.ts.map +1 -0
- package/dist/src/styles/canon/color-tables.js +369 -0
- package/dist/src/styles/canon/color-tables.js.map +1 -0
- package/dist/src/styles/canon/color.d.ts +66 -0
- package/dist/src/styles/canon/color.d.ts.map +1 -0
- package/dist/src/styles/canon/color.js +548 -0
- package/dist/src/styles/canon/color.js.map +1 -0
- package/dist/src/styles/canon/enums.d.ts +25 -0
- package/dist/src/styles/canon/enums.d.ts.map +1 -0
- package/dist/src/styles/canon/enums.js +187 -0
- package/dist/src/styles/canon/enums.js.map +1 -0
- package/dist/src/styles/canon/graphviz.d.ts +48 -0
- package/dist/src/styles/canon/graphviz.d.ts.map +1 -0
- package/dist/src/styles/canon/graphviz.js +160 -0
- package/dist/src/styles/canon/graphviz.js.map +1 -0
- package/dist/src/styles/canon/index.d.ts +13 -0
- package/dist/src/styles/canon/index.d.ts.map +1 -0
- package/dist/src/styles/canon/index.js +13 -0
- package/dist/src/styles/canon/index.js.map +1 -0
- package/dist/src/styles/canon/number.d.ts +59 -0
- package/dist/src/styles/canon/number.d.ts.map +1 -0
- package/dist/src/styles/canon/number.js +142 -0
- package/dist/src/styles/canon/number.js.map +1 -0
- package/dist/src/styles/canon/site.d.ts +51 -0
- package/dist/src/styles/canon/site.d.ts.map +1 -0
- package/dist/src/styles/canon/site.js +63 -0
- package/dist/src/styles/canon/site.js.map +1 -0
- package/dist/src/styles/canon/text.d.ts +61 -0
- package/dist/src/styles/canon/text.d.ts.map +1 -0
- package/dist/src/styles/canon/text.js +199 -0
- package/dist/src/styles/canon/text.js.map +1 -0
- package/dist/src/styles/codes.d.ts +95 -0
- package/dist/src/styles/codes.d.ts.map +1 -0
- package/dist/src/styles/codes.js +97 -0
- package/dist/src/styles/codes.js.map +1 -0
- package/dist/src/styles/cyjs/cascade.d.ts +134 -0
- package/dist/src/styles/cyjs/cascade.d.ts.map +1 -0
- package/dist/src/styles/cyjs/cascade.js +2252 -0
- package/dist/src/styles/cyjs/cascade.js.map +1 -0
- package/dist/src/styles/cyjs/defaults-table.d.ts +25 -0
- package/dist/src/styles/cyjs/defaults-table.d.ts.map +1 -0
- package/dist/src/styles/cyjs/defaults-table.js +76 -0
- package/dist/src/styles/cyjs/defaults-table.js.map +1 -0
- package/dist/src/styles/cyjs/emit.d.ts +82 -0
- package/dist/src/styles/cyjs/emit.d.ts.map +1 -0
- package/dist/src/styles/cyjs/emit.js +791 -0
- package/dist/src/styles/cyjs/emit.js.map +1 -0
- package/dist/src/styles/cyjs/index.d.ts +13 -0
- package/dist/src/styles/cyjs/index.d.ts.map +1 -0
- package/dist/src/styles/cyjs/index.js +13 -0
- package/dist/src/styles/cyjs/index.js.map +1 -0
- package/dist/src/styles/cyjs/live.d.ts +46 -0
- package/dist/src/styles/cyjs/live.d.ts.map +1 -0
- package/dist/src/styles/cyjs/live.js +108 -0
- package/dist/src/styles/cyjs/live.js.map +1 -0
- package/dist/src/styles/cyjs/mappers.d.ts +147 -0
- package/dist/src/styles/cyjs/mappers.d.ts.map +1 -0
- package/dist/src/styles/cyjs/mappers.js +744 -0
- package/dist/src/styles/cyjs/mappers.js.map +1 -0
- package/dist/src/styles/cyjs/selector.d.ts +113 -0
- package/dist/src/styles/cyjs/selector.d.ts.map +1 -0
- package/dist/src/styles/cyjs/selector.js +611 -0
- package/dist/src/styles/cyjs/selector.js.map +1 -0
- package/dist/src/styles/cyjs/stylesheet-text.d.ts +37 -0
- package/dist/src/styles/cyjs/stylesheet-text.d.ts.map +1 -0
- package/dist/src/styles/cyjs/stylesheet-text.js +181 -0
- package/dist/src/styles/cyjs/stylesheet-text.js.map +1 -0
- package/dist/src/styles/cytoscape/emit.d.ts +125 -0
- package/dist/src/styles/cytoscape/emit.d.ts.map +1 -0
- package/dist/src/styles/cytoscape/emit.js +1025 -0
- package/dist/src/styles/cytoscape/emit.js.map +1 -0
- package/dist/src/styles/cytoscape/index.d.ts +10 -0
- package/dist/src/styles/cytoscape/index.d.ts.map +1 -0
- package/dist/src/styles/cytoscape/index.js +10 -0
- package/dist/src/styles/cytoscape/index.js.map +1 -0
- package/dist/src/styles/cytoscape/lexicon.d.ts +49 -0
- package/dist/src/styles/cytoscape/lexicon.d.ts.map +1 -0
- package/dist/src/styles/cytoscape/lexicon.js +605 -0
- package/dist/src/styles/cytoscape/lexicon.js.map +1 -0
- package/dist/src/styles/cytoscape/mappings.d.ts +171 -0
- package/dist/src/styles/cytoscape/mappings.d.ts.map +1 -0
- package/dist/src/styles/cytoscape/mappings.js +460 -0
- package/dist/src/styles/cytoscape/mappings.js.map +1 -0
- package/dist/src/styles/cytoscape/resolve.d.ts +137 -0
- package/dist/src/styles/cytoscape/resolve.d.ts.map +1 -0
- package/dist/src/styles/cytoscape/resolve.js +381 -0
- package/dist/src/styles/cytoscape/resolve.js.map +1 -0
- package/dist/src/styles/cytoscape/translate.d.ts +50 -0
- package/dist/src/styles/cytoscape/translate.d.ts.map +1 -0
- package/dist/src/styles/cytoscape/translate.js +156 -0
- package/dist/src/styles/cytoscape/translate.js.map +1 -0
- package/dist/src/styles/defaults.d.ts +90 -0
- package/dist/src/styles/defaults.d.ts.map +1 -0
- package/dist/src/styles/defaults.js +414 -0
- package/dist/src/styles/defaults.js.map +1 -0
- package/dist/src/styles/index.d.ts +15 -0
- package/dist/src/styles/index.d.ts.map +1 -0
- package/dist/src/styles/index.js +14 -0
- package/dist/src/styles/index.js.map +1 -0
- package/dist/src/styles/internal.d.ts +17 -0
- package/dist/src/styles/internal.d.ts.map +1 -0
- package/dist/src/styles/internal.js +16 -0
- package/dist/src/styles/internal.js.map +1 -0
- package/dist/src/styles/io/approximations.d.ts +24 -0
- package/dist/src/styles/io/approximations.d.ts.map +1 -0
- package/dist/src/styles/io/approximations.js +51 -0
- package/dist/src/styles/io/approximations.js.map +1 -0
- package/dist/src/styles/io/block.d.ts +166 -0
- package/dist/src/styles/io/block.d.ts.map +1 -0
- package/dist/src/styles/io/block.js +930 -0
- package/dist/src/styles/io/block.js.map +1 -0
- package/dist/src/styles/io/generic.d.ts +88 -0
- package/dist/src/styles/io/generic.d.ts.map +1 -0
- package/dist/src/styles/io/generic.js +516 -0
- package/dist/src/styles/io/generic.js.map +1 -0
- package/dist/src/styles/io/index.d.ts +8 -0
- package/dist/src/styles/io/index.d.ts.map +1 -0
- package/dist/src/styles/io/index.js +7 -0
- package/dist/src/styles/io/index.js.map +1 -0
- package/dist/src/styles/io/writer.d.ts +89 -0
- package/dist/src/styles/io/writer.d.ts.map +1 -0
- package/dist/src/styles/io/writer.js +626 -0
- package/dist/src/styles/io/writer.js.map +1 -0
- package/dist/src/styles/notes.d.ts +47 -0
- package/dist/src/styles/notes.d.ts.map +1 -0
- package/dist/src/styles/notes.js +140 -0
- package/dist/src/styles/notes.js.map +1 -0
- package/dist/src/styles/plan/classes.d.ts +31 -0
- package/dist/src/styles/plan/classes.d.ts.map +1 -0
- package/dist/src/styles/plan/classes.js +139 -0
- package/dist/src/styles/plan/classes.js.map +1 -0
- package/dist/src/styles/plan/continuous.d.ts +32 -0
- package/dist/src/styles/plan/continuous.d.ts.map +1 -0
- package/dist/src/styles/plan/continuous.js +165 -0
- package/dist/src/styles/plan/continuous.js.map +1 -0
- package/dist/src/styles/plan/discrete.d.ts +39 -0
- package/dist/src/styles/plan/discrete.d.ts.map +1 -0
- package/dist/src/styles/plan/discrete.js +127 -0
- package/dist/src/styles/plan/discrete.js.map +1 -0
- package/dist/src/styles/plan/families.d.ts +31 -0
- package/dist/src/styles/plan/families.d.ts.map +1 -0
- package/dist/src/styles/plan/families.js +95 -0
- package/dist/src/styles/plan/families.js.map +1 -0
- package/dist/src/styles/plan/features.d.ts +58 -0
- package/dist/src/styles/plan/features.d.ts.map +1 -0
- package/dist/src/styles/plan/features.js +185 -0
- package/dist/src/styles/plan/features.js.map +1 -0
- package/dist/src/styles/plan/index.d.ts +7 -0
- package/dist/src/styles/plan/index.d.ts.map +1 -0
- package/dist/src/styles/plan/index.js +7 -0
- package/dist/src/styles/plan/index.js.map +1 -0
- package/dist/src/styles/plan/plan.d.ts +71 -0
- package/dist/src/styles/plan/plan.d.ts.map +1 -0
- package/dist/src/styles/plan/plan.js +893 -0
- package/dist/src/styles/plan/plan.js.map +1 -0
- package/dist/src/styles/plan/resolve.d.ts +137 -0
- package/dist/src/styles/plan/resolve.d.ts.map +1 -0
- package/dist/src/styles/plan/resolve.js +587 -0
- package/dist/src/styles/plan/resolve.js.map +1 -0
- package/dist/src/styles/types.d.ts +702 -0
- package/dist/src/styles/types.d.ts.map +1 -0
- package/dist/src/styles/types.js +10 -0
- package/dist/src/styles/types.js.map +1 -0
- package/dist/src/styles/vocabulary.d.ts +41 -0
- package/dist/src/styles/vocabulary.d.ts.map +1 -0
- package/dist/src/styles/vocabulary.js +140 -0
- package/dist/src/styles/vocabulary.js.map +1 -0
- package/dist/src/types.d.ts +64 -1
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/types.js.map +1 -1
- package/dist/styles.d.ts +1 -0
- package/dist/styles.js +322 -0
- package/dist/styles.js.map +1 -0
- package/dist/xgmml.js +5 -4
- package/dist/xgmml.js.map +1 -1
- package/package.json +13 -2
- package/src/common/codes.ts +7 -0
- package/src/common/escape.ts +5 -2
- package/src/common/export.ts +179 -140
- package/src/common/input.ts +8 -4
- package/src/common/json-elements.ts +169 -38
- package/src/common/notes.ts +94 -0
- package/src/common/report.ts +41 -1
- package/src/common/units.ts +42 -0
- package/src/common/xml.ts +45 -5
- package/src/formats/cx/exporter.ts +95 -11
- package/src/formats/cx/importer.ts +126 -90
- package/src/formats/cx/styles.ts +304 -0
- package/src/formats/cx2/exporter.ts +234 -77
- package/src/formats/cx2/importer.ts +19 -1
- package/src/formats/cx2/styles.ts +29 -0
- package/src/formats/cys/constants.ts +3 -0
- package/src/formats/cys/exporter.ts +246 -60
- package/src/formats/cys/importer.ts +125 -9
- package/src/formats/cys/session.ts +6 -0
- package/src/formats/cys/styles.ts +254 -0
- package/src/formats/cys/tables.ts +117 -48
- package/src/formats/dot/exporter.ts +262 -126
- package/src/formats/dot/importer.ts +111 -20
- package/src/formats/dot/index.ts +1 -0
- package/src/formats/dot/positions.ts +77 -0
- package/src/formats/dot/styles.ts +1755 -0
- package/src/formats/gexf/exporter.ts +27 -11
- package/src/formats/gexf/importer.ts +308 -158
- package/src/formats/gexf/index.ts +10 -0
- package/src/formats/gexf/schema.ts +5 -0
- package/src/formats/gexf/styles.ts +719 -0
- package/src/formats/gml/exporter.ts +33 -14
- package/src/formats/gml/importer.ts +4 -0
- package/src/formats/gml/index.ts +2 -1
- package/src/formats/gml/positions.ts +52 -0
- package/src/formats/gml/styles.ts +1248 -0
- package/src/formats/gml/syntax.ts +173 -62
- package/src/formats/graphml/constants.ts +5 -0
- package/src/formats/graphml/exporter.ts +163 -71
- package/src/formats/graphml/importer.ts +119 -45
- package/src/formats/graphml/index.ts +1 -0
- package/src/formats/graphml/styles-plain.ts +236 -0
- package/src/formats/graphml/styles-yed.ts +1221 -0
- package/src/formats/graphml/styles-yfiles3.ts +573 -0
- package/src/formats/graphml/tree.ts +36 -20
- package/src/formats/graphml/yfiles.ts +89 -13
- package/src/formats/json/exporter.ts +76 -26
- package/src/formats/json/importer.ts +541 -322
- package/src/formats/json/positions.ts +50 -0
- package/src/formats/json/styles.ts +2082 -0
- package/src/formats/neo4j/exporter.ts +2 -1
- package/src/formats/pajek/exporter.ts +195 -106
- package/src/formats/pajek/importer.ts +78 -9
- package/src/formats/pajek/index.ts +2 -0
- package/src/formats/pajek/styles.ts +685 -0
- package/src/formats/pajek/syntax.ts +7 -0
- package/src/formats/xgmml/columns.ts +39 -9
- package/src/formats/xgmml/constants.ts +3 -0
- package/src/formats/xgmml/document.ts +54 -12
- package/src/formats/xgmml/emit.ts +11 -6
- package/src/formats/xgmml/exporter.ts +32 -13
- package/src/formats/xgmml/importer.ts +43 -29
- package/src/formats/xgmml/styles.ts +400 -0
- package/src/index.ts +16 -0
- package/src/positions/codes.ts +32 -0
- package/src/positions/convert.ts +123 -0
- package/src/positions/extract.ts +619 -0
- package/src/positions/index.ts +23 -0
- package/src/positions/types.ts +221 -0
- package/src/registry.ts +179 -8
- package/src/styles/annotations.ts +478 -0
- package/src/styles/budget.ts +60 -0
- package/src/styles/canon/bends.ts +84 -0
- package/src/styles/canon/color-tables.ts +386 -0
- package/src/styles/canon/color.ts +624 -0
- package/src/styles/canon/enums.ts +211 -0
- package/src/styles/canon/graphviz.ts +189 -0
- package/src/styles/canon/index.ts +13 -0
- package/src/styles/canon/number.ts +152 -0
- package/src/styles/canon/site.ts +87 -0
- package/src/styles/canon/text.ts +221 -0
- package/src/styles/codes.ts +104 -0
- package/src/styles/cyjs/cascade.ts +2670 -0
- package/src/styles/cyjs/defaults-table.ts +82 -0
- package/src/styles/cyjs/emit.ts +952 -0
- package/src/styles/cyjs/index.ts +37 -0
- package/src/styles/cyjs/live.ts +147 -0
- package/src/styles/cyjs/mappers.ts +879 -0
- package/src/styles/cyjs/selector.ts +778 -0
- package/src/styles/cyjs/stylesheet-text.ts +214 -0
- package/src/styles/cytoscape/emit.ts +1264 -0
- package/src/styles/cytoscape/index.ts +40 -0
- package/src/styles/cytoscape/lexicon.ts +658 -0
- package/src/styles/cytoscape/mappings.ts +603 -0
- package/src/styles/cytoscape/resolve.ts +521 -0
- package/src/styles/cytoscape/translate.ts +237 -0
- package/src/styles/defaults.ts +504 -0
- package/src/styles/index.ts +57 -0
- package/src/styles/internal.ts +17 -0
- package/src/styles/io/approximations.ts +47 -0
- package/src/styles/io/block.ts +1138 -0
- package/src/styles/io/generic.ts +687 -0
- package/src/styles/io/index.ts +18 -0
- package/src/styles/io/writer.ts +780 -0
- package/src/styles/notes.ts +165 -0
- package/src/styles/plan/classes.ts +166 -0
- package/src/styles/plan/continuous.ts +218 -0
- package/src/styles/plan/discrete.ts +165 -0
- package/src/styles/plan/families.ts +115 -0
- package/src/styles/plan/features.ts +234 -0
- package/src/styles/plan/index.ts +7 -0
- package/src/styles/plan/plan.ts +1129 -0
- package/src/styles/plan/resolve.ts +685 -0
- package/src/styles/types.ts +814 -0
- package/src/styles/vocabulary.ts +172 -0
- package/src/types.ts +76 -1
- package/dist/chunks/constants-fT3E8JYY.js.map +0 -1
- package/dist/chunks/escape-B62ZGM_a.js.map +0 -1
- package/dist/chunks/export-rKLeGQMo.js.map +0 -1
- package/dist/chunks/exporter-8hLNemFk.js.map +0 -1
- package/dist/chunks/exporter-BWwEuOPT.js.map +0 -1
- package/dist/chunks/exporter-RVtXVetw.js.map +0 -1
- package/dist/chunks/importer-BbNb7eNg.js.map +0 -1
- package/dist/chunks/importer-C98dpSH4.js.map +0 -1
- package/dist/chunks/importer-D794XUTe.js.map +0 -1
- package/dist/chunks/importer-Dz7tI8Sa.js.map +0 -1
- package/dist/chunks/importer-Ht7LNg8L.js.map +0 -1
- package/dist/chunks/importer-WrGRZb0N.js.map +0 -1
- package/dist/chunks/importer-xZ-3suY1.js.map +0 -1
- package/dist/chunks/json-elements-DKSqpNW1.js.map +0 -1
package/dist/graph-io.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graph-io.js","sources":["../src/common/line-format.ts","../src/common/compare.ts","../src/common/cell-budget.ts","../src/registry.ts"],"sourcesContent":["/**\n * defineLineFormat(): an importer for a text format with one node or one edge per line, built from\n * one function that reads a line. Everything else an importer must do (options, decoding, the\n * report and its counts, ids, direction, weights, attribute types, cancelling) is done here.\n */\n\nimport { GraphFormatError, type GraphSink, INVALID_INDEX } from \"@graphty/graph-format\";\n\nimport { type CommonImportOptions, type GraphImporter, type ImportInput, type ImportReport } from \"../types.js\";\nimport { BAD_LINE_CODE } from \"./codes.js\";\nimport { DirectionResolver } from \"./direction.js\";\nimport { IdCoercer } from \"./ids.js\";\nimport { LineReader, throwIfAborted } from \"./input.js\";\nimport { reportSinkOptions, reportUnusedOptions, resolveImportOptions } from \"./options.js\";\nimport { ImportReportBuilder, isAbortError, messageOf } from \"./report.js\";\nimport { TextCellWriter } from \"./text.js\";\nimport { parseWeightText } from \"./weights.js\";\n\n/**\n * Attribute values for a node or an edge added by defineLineFormat()'s `parseLine`.\n * @category Writing a format\n */\nexport type LineAttributes = Readonly<Record<string, string | number | boolean | null | undefined>>;\n\n/**\n * What `parseLine` adds a line's node or edge with.\n * @category Writing a format\n */\nexport interface LineGraph {\n /**\n * Add a node, or give a node that already exists more attributes. A `label` attribute is the\n * node's label, which `snapshot.nodes.byRole(\"label\")` finds; any other attribute's type (text,\n * integer, number, boolean) is worked out from its values, as for a CSV column.\n * @param id - the node id as written in the file\n * @param attributes - attribute values, such as `{ label: \"Alice\" }`\n */\n node(id: string, attributes?: LineAttributes): void;\n /**\n * Add an edge. A node it names that does not exist yet is added. The attribute that `weightFrom`\n * names (`weight` unless the caller passes another name) becomes the edge weight.\n * @param source - the source node id as written in the file\n * @param target - the target node id as written in the file\n * @param attributes - attribute values, such as `{ weight: \"2.5\" }`\n */\n edge(source: string, target: string, attributes?: LineAttributes): void;\n}\n\n/**\n * A text format with one node or one edge per line, for defineLineFormat().\n * @category Writing a format\n */\nexport interface LineFormat {\n /** The format name, which callers pass as `format`. */\n readonly format: string;\n /** The file extensions, with the dot (`[\".tgf\"]`); format detection matches them. */\n readonly extensions: readonly string[];\n /** MIME types the format is served as; none when left out. */\n readonly mimeTypes?: readonly string[] | undefined;\n /** Whether a file is directed when the caller passes no `defaultDirected`; false when left out. */\n readonly directed?: boolean | undefined;\n /** Lines that start with this text are skipped; `\"#\"` when left out, null to skip none. Blank lines are always skipped. */\n readonly comment?: string | null | undefined;\n /**\n * How sure you are that the first bytes of a file are this format, from 0 to 1. A file is\n * recognized by its content only when this returns 0.5 or more; without it, detection goes by\n * the file extension.\n */\n readonly sniff?: ((head: Uint8Array) => number) | undefined;\n /**\n * Read one line. `fields` is the line split on whitespace. Call `graph.node()` or `graph.edge()`\n * for what the line holds, and throw an Error to skip a line you cannot read: its message is\n * recorded as an `E_BAD_LINE` error with the line number.\n */\n readonly parseLine: (fields: readonly string[], graph: LineGraph, line: string) => void;\n}\n\n/** The common options a line format reads; a caller's other ones are reported as W_OPTION_IGNORED. */\nconst USED = new Set<keyof CommonImportOptions>([\"ids\", \"defaultDirected\", \"weightFrom\", \"addMissingNodes\"]);\n\n/**\n * Make an importer for a text format with one node or one edge per line. You write `parseLine`,\n * which reads one line; the importer handles every input graph-io takes, the options every importer\n * takes, the import report and its counts, cancelling and progress. Register the result with\n * `registry.registerImporter()`.\n * @example\n * ```ts\n * // \"a b\" is an edge, \"a\" alone is a node\n * const edgeList = defineLineFormat({\n * format: \"edges\",\n * extensions: [\".edges\"],\n * parseLine(fields, graph) {\n * if (fields.length === 1) {\n * graph.node(fields[0]);\n * } else if (fields.length === 2) {\n * graph.edge(fields[0], fields[1]);\n * } else {\n * throw new Error(\"expected one or two node ids\");\n * }\n * },\n * });\n * registry.registerImporter(edgeList);\n * ```\n * @param definition - the format: its name, extensions and `parseLine`\n * @returns the importer\n * @category Writing a format\n */\nexport function defineLineFormat(definition: LineFormat): GraphImporter {\n const { format, extensions, mimeTypes = [], directed = false, comment = \"#\", sniff, parseLine } = definition;\n const importer: GraphImporter = {\n format,\n extensions,\n mimeTypes,\n options: [],\n import: async (input: ImportInput, sink: GraphSink, options?: CommonImportOptions): Promise<ImportReport> => {\n const opts = resolveImportOptions(options, {\n ids: \"canonical\",\n defaultDirected: directed,\n weightFrom: \"weight\",\n });\n const report = new ImportReportBuilder(format, opts.errorLimit);\n reportSinkOptions(sink, options, report);\n reportUnusedOptions(options, report, USED);\n const ids = new IdCoercer(opts.ids);\n const edges = new DirectionResolver(sink, report, opts.onMixedDirection);\n const kind = opts.defaultDirected ? \"directed\" : \"undirected\";\n edges.setHeader(opts.defaultDirected);\n const attributes = new AttributeWriter(sink, report, opts.weightFrom);\n const write = (domain: \"node\" | \"edge\", row: number, values: LineAttributes | undefined): void => {\n attributes.write(domain, row, values);\n };\n const addNode = (id: string): number => {\n const nodeId = ids.text(id);\n if (sink.indexOf(nodeId) === INVALID_INDEX) {\n report.counts.nodes++;\n }\n return sink.addNode(nodeId);\n };\n let line = 0;\n const graph: LineGraph = {\n node: (id, attributes) => {\n write(\"node\", addNode(id), attributes);\n },\n edge: (source, target, attributes) => {\n const raw = opts.weightFrom === null ? undefined : attributes?.[opts.weightFrom];\n const weight = raw === null || raw === undefined ? undefined : parseWeightText(String(raw), report);\n const [s, t] = [ids.text(source), ids.text(target)];\n const added = new Set([s, t].filter((id) => sink.indexOf(id) === INVALID_INDEX)).size;\n const edge = edges.addEdge(s, t, kind, weight, { line });\n report.counts.nodes += added;\n report.counts.edges++;\n write(\"edge\", edge, attributes);\n },\n };\n const lines = new LineReader(input, report, opts);\n for await (const text of lines) {\n ({ line } = lines);\n if (line % 64 === 0) {\n throwIfAborted(opts.signal);\n }\n const trimmed = text.trim();\n if (trimmed === \"\" || (comment !== null && trimmed.startsWith(comment))) {\n continue;\n }\n try {\n parseLine(trimmed.split(/\\s+/), graph, text);\n } catch (err) {\n recordLineError(report, err, line);\n }\n }\n throwIfAborted(opts.signal);\n return report.finish();\n },\n };\n return Object.freeze(sniff === undefined ? importer : { ...importer, sniff });\n}\n\n/**\n * Record what a line's parser threw: a GraphFormatError with its own code, any other error as\n * BAD_LINE_CODE. A cancellation is rethrown.\n * @param report - the report\n * @param err - what the parser threw\n * @param line - the line number\n */\nfunction recordLineError(report: ImportReportBuilder, err: unknown, line: number): void {\n if (isAbortError(err)) {\n throw err;\n }\n if (err instanceof GraphFormatError) {\n report.recordError(err, { line });\n } else {\n report.error(\"parse-error\", BAD_LINE_CODE, err instanceof Error ? err.message : messageOf(err), { line });\n }\n}\n\n/** Writes the attributes a line format's parser gives a node or an edge into columns. */\nclass AttributeWriter {\n private readonly writers = { node: new Map<string, TextCellWriter>(), edge: new Map<string, TextCellWriter>() };\n\n /**\n * Create a writer.\n * @param sink - the sink\n * @param report - the report\n * @param weightFrom - the edge attribute read as the weight (not written as a column), or null\n */\n constructor(\n private readonly sink: GraphSink,\n private readonly report: ImportReportBuilder,\n private readonly weightFrom: string | null,\n ) {}\n\n /**\n * Write one element's attributes; null and undefined values are left unset.\n * @param domain - node or edge\n * @param row - the element's index\n * @param attributes - the attributes, or undefined\n */\n write(domain: \"node\" | \"edge\", row: number, attributes: LineAttributes | undefined): void {\n for (const [name, value] of Object.entries(attributes ?? {})) {\n if (value === null || value === undefined || (domain === \"edge\" && name === this.weightFrom)) {\n continue;\n }\n if (name === \"label\") {\n this.writeLabel(domain, row, String(value));\n continue;\n }\n let writer = this.writers[domain].get(name);\n if (writer === undefined) {\n writer = new TextCellWriter(name, domain, this.sink, this.report);\n this.writers[domain].set(name, writer);\n }\n writer.write(row, String(value));\n }\n }\n\n /**\n * Write a label: text, whatever it looks like, in the column that byRole(\"label\") finds.\n * @param domain - node or edge\n * @param row - the element's index\n * @param text - the label\n */\n private writeLabel(domain: \"node\" | \"edge\", row: number, text: string): void {\n const decl = { name: \"label\", dtype: \"string\", role: \"label\" } as const;\n if (domain === \"node\") {\n this.sink.setNodeValue(this.sink.declareNodeColumn(decl), row, text);\n } else {\n this.sink.setEdgeValue(this.sink.declareEdgeColumn(decl), row, text);\n }\n }\n}\n","/**\n * Compare two snapshots node by node, edge by edge and value by value, for testing a format plugin:\n * read a file, save it, read the saved file back, and compare. Every difference should be one that\n * the save's checkExport() notes announced.\n */\n\nimport { type Column, type GraphSnapshot } from \"@graphty/graph-format\";\n\n/**\n * One difference between two snapshots.\n * @category Plugin helpers\n */\nexport interface SnapshotDiff {\n /** Where: \"directed\", \"ids[3]\", \"nodes.label[4]\", \"edges.weight[0]\", \"extensions.temporal:node:price.rowCount\"... */\n readonly path: string;\n /** The value in the expected snapshot. */\n readonly expected: unknown;\n /** The value in the actual snapshot. */\n readonly actual: unknown;\n /** A one-line description. */\n readonly message: string;\n}\n\n/**\n * What compareSnapshots() compares.\n * @category Plugin helpers\n */\nexport interface CompareOptions {\n /** Column names to skip in every table (format-owned helpers an exporter adds, for instance). */\n readonly ignoreColumns?: readonly string[] | undefined;\n /** Column roles to skip in every table. */\n readonly ignoreRoles?: readonly string[] | undefined;\n /** Whether the actual snapshot may hold columns the expected one lacks (default true). */\n readonly allowExtraColumns?: boolean | undefined;\n /** Whether dtypes must match (default true); false compares values only. */\n readonly dtypes?: boolean | undefined;\n /** Whether roles must match (default true). */\n readonly roles?: boolean | undefined;\n /** Whether origin.type must match (default false). */\n readonly originType?: boolean | undefined;\n /** Absolute tolerance for numeric cell and weight comparisons (default 0: Object.is). */\n readonly tolerance?: number | undefined;\n /** Whether the explicit / defaulted status of weights must match (default true). */\n readonly weightExplicitness?: boolean | undefined;\n /** Whether extension tables are compared (default true). */\n readonly extensions?: boolean | undefined;\n /** Stop after this many differences (default 50). */\n readonly limit?: number | undefined;\n}\n\n/**\n * Compare two snapshots: the direction, the node ids, the edges, the weights and every attribute\n * value. Use it to test a format plugin: read a file, save it in your format, read the saved file\n * back, and compare the two graphs. Each difference has a `path` (\"ids[3]\", \"nodes.label[4]\",\n * \"edges.weight[0]\") and a one-line `message`; every one should match a note that `checkExport()`\n * returned for the save.\n * @example\n * ```ts\n * const notes = checkExport(original, \"pairs\");\n * const readBack = (await importGraph(await exportGraphToString(original, \"pairs\"), { format: \"pairs\" })).snapshot;\n * console.log(describeDiffs(compareSnapshots(original, readBack)));\n * ```\n * @param expected - the graph you saved\n * @param actual - the graph read back from the saved file\n * @param options - what to compare\n * @returns the differences, empty when the graphs are the same\n * @category Plugin helpers\n */\nexport function compareSnapshots(\n expected: GraphSnapshot,\n actual: GraphSnapshot,\n options: CompareOptions = {},\n): SnapshotDiff[] {\n const diffs: SnapshotDiff[] = [];\n const limit = options.limit ?? 50;\n const tolerance = options.tolerance ?? 0;\n const ctx: CompareContext = {\n options,\n diff: (path, e, a, message) => {\n diffs.push({\n path,\n expected: e,\n actual: a,\n message: message ?? `${path}: expected ${show(e)}, got ${show(a)}`,\n });\n if (diffs.length >= limit) {\n throw new LimitReached();\n }\n },\n same: (e, a) => valuesEqual(e, a, tolerance),\n };\n try {\n compareGraphs(expected, actual, ctx);\n } catch (err) {\n if (!(err instanceof LimitReached)) {\n throw err;\n }\n }\n return diffs;\n}\n\n/** Thrown by the recorder once the limit of differences is reached, to end the walk. */\nclass LimitReached extends Error {}\n\n/** What every comparison step shares: the options, the recorder and the value comparator. */\ninterface CompareContext {\n readonly options: CompareOptions;\n /** Records a difference (with a default message); throws LimitReached at the limit. */\n readonly diff: (path: string, e: unknown, a: unknown, message?: string) => void;\n /** Value equality under the tolerance. */\n readonly same: (e: unknown, a: unknown) => boolean;\n}\n\n/** A table shape both AttributeTable and extension tables satisfy. */\ninterface TableLike extends Iterable<Column> {\n readonly rowCount: number;\n names(): readonly string[];\n get(name: string): Column | null;\n}\n\n/**\n * Compare two snapshots step by step: the counts, the ids, the topology, the weights, the tables.\n * @param expected - the reference\n * @param actual - the snapshot under test\n * @param ctx - the comparison context\n */\nfunction compareGraphs(expected: GraphSnapshot, actual: GraphSnapshot, ctx: CompareContext): void {\n const { diff } = ctx;\n if (expected.directed !== actual.directed) {\n diff(\"directed\", expected.directed, actual.directed);\n }\n if (expected.nodeCount !== actual.nodeCount) {\n diff(\"nodeCount\", expected.nodeCount, actual.nodeCount);\n }\n if (expected.edgeCount !== actual.edgeCount) {\n diff(\"edgeCount\", expected.edgeCount, actual.edgeCount);\n }\n compareIds(expected, actual, diff);\n if (expected.nodeCount !== actual.nodeCount || expected.edgeCount !== actual.edgeCount) {\n return;\n }\n compareTopology(expected, actual, diff);\n compareWeights(expected, actual, ctx);\n compareTables(\"nodes\", expected.nodes, actual.nodes, ctx);\n compareTables(\"edges\", expected.edges, actual.edges, ctx);\n compareTables(\"graph\", expected.graph, actual.graph, ctx);\n if (ctx.options.extensions !== false) {\n compareExtensions(expected, actual, ctx);\n }\n}\n\n/**\n * Compare the node ids in index order.\n * @param expected - the reference\n * @param actual - the snapshot under test\n * @param diff - the recorder\n */\nfunction compareIds(expected: GraphSnapshot, actual: GraphSnapshot, diff: CompareContext[\"diff\"]): void {\n const expectedIds = expected.ids.toArray();\n const actualIds = actual.ids.toArray();\n const n = Math.min(expectedIds.length, actualIds.length);\n for (let i = 0; i < n; i++) {\n if (!Object.is(expectedIds[i], actualIds[i])) {\n diff(`ids[${i}]`, expectedIds[i], actualIds[i]);\n }\n }\n}\n\n/**\n * Compare the topology: the CSR arrays (identical when node order and edge order survived), then the\n * orientation of every logical edge.\n * @param expected - the reference\n * @param actual - the snapshot under test, with as many nodes and edges\n * @param diff - the recorder\n */\nfunction compareTopology(expected: GraphSnapshot, actual: GraphSnapshot, diff: CompareContext[\"diff\"]): void {\n if (!typedEqual(expected.rowPtr, actual.rowPtr)) {\n diff(\"rowPtr\", expected.rowPtr, actual.rowPtr, \"rowPtr differs\");\n }\n if (!typedEqual(expected.colIdx, actual.colIdx)) {\n diff(\"colIdx\", expected.colIdx, actual.colIdx, \"colIdx differs\");\n }\n const el = expected.edgeList();\n const al = actual.edgeList();\n for (let e = 0; e < expected.edgeCount; e++) {\n if (el.src[e] !== al.src[e] || el.dst[e] !== al.dst[e]) {\n diff(`edge[${e}]`, `${el.src[e]}->${el.dst[e]}`, `${al.src[e]}->${al.dst[e]}`);\n }\n }\n}\n\n/**\n * Compare the weights of two snapshots: the exact weight column when both have one, the 32-bit\n * weights otherwise.\n * @param expected - the reference\n * @param actual - the snapshot under test\n * @param ctx - the comparison context\n */\nfunction compareWeights(expected: GraphSnapshot, actual: GraphSnapshot, ctx: CompareContext): void {\n if (expected.flags.weighted !== actual.flags.weighted) {\n ctx.diff(\"flags.weighted\", expected.flags.weighted, actual.flags.weighted);\n return;\n }\n if (!expected.flags.weighted) {\n return;\n }\n const eShadow = expected.edges.byRole(\"weight\");\n const aShadow = actual.edges.byRole(\"weight\");\n if (eShadow !== null && aShadow !== null) {\n compareExactWeights(expected.edgeCount, eShadow, aShadow, ctx);\n return;\n }\n if (ctx.options.weightExplicitness !== false && (eShadow === null) !== (aShadow === null)) {\n ctx.diff(\n \"weightColumn\",\n eShadow !== null,\n aShadow !== null,\n \"one snapshot has a role-weight column, the other does not\",\n );\n }\n const ew = expected.edgeList().weights;\n const aw = actual.edgeList().weights;\n for (let e = 0; e < expected.edgeCount; e++) {\n const ev = ew === null ? 1 : ew[e];\n const av = aw === null ? 1 : aw[e];\n if (!ctx.same(ev, av)) {\n ctx.diff(`weight[${e}]`, ev, av);\n }\n }\n}\n\n/**\n * Compare the exact weight columns of two snapshots: which edges have an explicit weight, and its value.\n * @param edgeCount - the number of edges\n * @param expected - the reference's weight column\n * @param actual - the weight column under test\n * @param ctx - the comparison context\n */\nfunction compareExactWeights(edgeCount: number, expected: Column, actual: Column, ctx: CompareContext): void {\n for (let e = 0; e < edgeCount; e++) {\n const eSet = expected.isSet(e);\n const aSet = actual.isSet(e);\n if (ctx.options.weightExplicitness !== false && eSet !== aSet) {\n ctx.diff(`weightExplicit[${e}]`, eSet, aSet);\n } else if (eSet && aSet && !ctx.same(expected.value(e), actual.value(e))) {\n ctx.diff(`weight[${e}]`, expected.value(e), actual.value(e));\n }\n }\n}\n\n/**\n * Compare the extension tables: which exist, their row counts and their columns.\n * @param expected - the reference\n * @param actual - the snapshot under test\n * @param ctx - the comparison context\n */\nfunction compareExtensions(expected: GraphSnapshot, actual: GraphSnapshot, ctx: CompareContext): void {\n for (const [name, table] of expected.extensions) {\n const other = actual.extensions.get(name);\n if (other === undefined) {\n ctx.diff(`extensions.${name}`, \"present\", \"absent\");\n } else if (table.rowCount === other.rowCount) {\n compareTables(`extensions.${name}`, table, other, ctx);\n } else {\n ctx.diff(`extensions.${name}.rowCount`, table.rowCount, other.rowCount);\n }\n }\n if (ctx.options.allowExtraColumns === false) {\n for (const name of actual.extensions.keys()) {\n if (!expected.extensions.has(name)) {\n ctx.diff(`extensions.${name}`, \"absent\", \"present\");\n }\n }\n }\n}\n\n/**\n * Compare the columns of one table.\n * @param label - the table name for paths\n * @param expected - the reference table\n * @param actual - the table under test\n * @param ctx - the comparison context\n */\nfunction compareTables(label: string, expected: TableLike, actual: TableLike, ctx: CompareContext): void {\n const ignoreNames = new Set(ctx.options.ignoreColumns ?? []);\n const ignoreRoles = new Set(ctx.options.ignoreRoles ?? []);\n // the role-weight shadow column is compared by the weights step, not as a declared column\n const skip = (column: Column): boolean => {\n const { name, role } = column.meta;\n return (\n ignoreNames.has(name) ||\n (role !== null && (ignoreRoles.has(role) || (label === \"edges\" && role === \"weight\")))\n );\n };\n for (const column of expected) {\n if (skip(column)) {\n continue;\n }\n const path = `${label}.${column.meta.name}`;\n const other = actual.get(column.meta.name);\n if (other === null) {\n ctx.diff(path, \"present\", \"absent\", `${path}: column missing after round trip`);\n } else {\n compareColumn(path, column, other, ctx);\n }\n }\n if (ctx.options.allowExtraColumns === false) {\n for (const column of actual) {\n if (!skip(column) && expected.get(column.meta.name) === null) {\n const path = `${label}.${column.meta.name}`;\n ctx.diff(path, \"absent\", \"present\", `${path}: extra column after round trip`);\n }\n }\n }\n}\n\n/**\n * Compare one column: its declaration, then every cell.\n * @param path - the column's path for messages\n * @param column - the reference column\n * @param other - the column under test\n * @param ctx - the comparison context\n */\nfunction compareColumn(path: string, column: Column, other: Column, ctx: CompareContext): void {\n compareDeclaration(path, column, other, ctx);\n if (column.length !== other.length) {\n ctx.diff(`${path}.length`, column.length, other.length);\n return;\n }\n for (let r = 0; r < column.length; r++) {\n const eSet = column.isSet(r);\n const aSet = other.isSet(r);\n if (eSet !== aSet) {\n ctx.diff(`${path}[${r}]`, eSet ? column.value(r) : undefined, aSet ? other.value(r) : undefined);\n } else if (eSet) {\n const ev = cellValue(column, r);\n const av = cellValue(other, r);\n if (!ctx.same(ev, av)) {\n ctx.diff(`${path}[${r}]`, ev, av);\n }\n }\n }\n}\n\n/**\n * Compare what two columns declare: dtype, item dtype, components, role and origin type, as the\n * options ask.\n * @param path - the column's path for messages\n * @param column - the reference column\n * @param other - the column under test\n * @param ctx - the comparison context\n */\nfunction compareDeclaration(path: string, column: Column, other: Column, ctx: CompareContext): void {\n const { options, diff } = ctx;\n const e = column.meta;\n const a = other.meta;\n if (options.dtypes !== false) {\n for (const key of [\"dtype\", \"itemDtype\", \"components\"] as const) {\n if (e[key] !== a[key]) {\n diff(`${path}.${key}`, e[key], a[key]);\n }\n }\n }\n if (options.roles !== false && e.role !== a.role) {\n diff(`${path}.role`, e.role, a.role);\n }\n const eType = e.origin?.type ?? null;\n const aType = a.origin?.type ?? null;\n if (options.originType === true && eType !== aType) {\n diff(`${path}.origin.type`, eType, aType);\n }\n}\n\n/**\n * The comparable value of a set cell: list rows through sliceOf, json rows through values, the\n * typed accessor otherwise (a components > 1 subarray becomes a plain array).\n * @param column - the column\n * @param row - the row\n * @returns the value\n */\nfunction cellValue(column: Column, row: number): unknown {\n switch (column.dtype) {\n case \"list\":\n return [...column.sliceOf(row)];\n case \"json\":\n return column.values[row];\n default: {\n const value = column.value(row);\n return ArrayBuffer.isView(value) ? Array.from(value as ArrayLike<number>) : value;\n }\n }\n}\n\n/**\n * Deep equality with a numeric tolerance (for the tests).\n * @param e - expected\n * @param a - actual\n * @param tolerance - absolute tolerance for numbers\n * @returns true when equal\n */\nexport function valuesEqual(e: unknown, a: unknown, tolerance: number): boolean {\n if (typeof e === \"number\" && typeof a === \"number\") {\n if (Object.is(e, a)) {\n return true;\n }\n return Number.isFinite(e) && Number.isFinite(a) && Math.abs(e - a) <= tolerance;\n }\n if (Array.isArray(e) || ArrayBuffer.isView(e)) {\n const ea = Array.from(e as ArrayLike<unknown>);\n if (!(Array.isArray(a) || ArrayBuffer.isView(a))) {\n return false;\n }\n const aa = Array.from(a as ArrayLike<unknown>);\n return ea.length === aa.length && ea.every((v, i) => valuesEqual(v, aa[i], tolerance));\n }\n if (typeof e === \"object\" && e !== null && typeof a === \"object\" && a !== null) {\n const eo = e as Record<string, unknown>;\n const ao = a as Record<string, unknown>;\n const keys = Object.keys(eo);\n if (keys.length !== Object.keys(ao).length) {\n return false;\n }\n return keys.every((k) => Object.hasOwn(ao, k) && valuesEqual(eo[k], ao[k], tolerance));\n }\n return Object.is(e, a);\n}\n\n/**\n * Element-wise equality of two typed arrays.\n * @param a - one array\n * @param b - the other\n * @returns true when same length and contents\n */\nfunction typedEqual(a: ArrayLike<number>, b: ArrayLike<number>): boolean {\n if (a.length !== b.length) {\n return false;\n }\n for (let i = 0; i < a.length; i++) {\n if (a[i] !== b[i]) {\n return false;\n }\n }\n return true;\n}\n\n/**\n * A short text of a value for messages.\n * @param v - the value\n * @returns JSON when possible, else String()\n */\nfunction show(v: unknown): string {\n if (ArrayBuffer.isView(v)) {\n const items = Array.from(v as unknown as ArrayLike<number>);\n return `[${items.slice(0, 8).join(\", \")}${items.length > 8 ? \", ...\" : \"\"}]`;\n }\n try {\n const text = JSON.stringify(v);\n return text ?? String(v);\n } catch {\n return String(v);\n }\n}\n\n/**\n * The differences compareSnapshots() found, one per line, for printing.\n * @param diffs - the differences\n * @returns one line per difference, \"no differences\" when empty\n * @category Plugin helpers\n */\nexport function describeDiffs(diffs: readonly SnapshotDiff[]): string {\n return diffs.length === 0 ? \"no differences\" : diffs.map((d) => ` - ${d.message}`).join(\"\\n\");\n}\n","/**\n * A memory guard for the builder importGraph() fills. graph-format stores every attribute as a dense\n * column, one slot per node (or edge) whether or not that element has a value, so a file whose nodes\n * each carry a differently named attribute holds n values but allocates n x n slots: a few hundred\n * kilobytes of input can need gigabytes. The guard counts the slots that hold no value and stops the\n * import once they pass a limit. A dense file has almost no empty slots, so it is never stopped\n * however large it is.\n */\n\nimport {\n type ColumnDecl,\n type ColumnHandle,\n GraphBuilder,\n type GraphBuilderOptions,\n GraphFormatError,\n type NodeId,\n} from \"@graphty/graph-format\";\n\nimport { describe } from \"./options.js\";\nimport { plural } from \"./plural.js\";\nimport { ImportReportBuilder } from \"./report.js\";\n\n/**\n * Import stopped for allocating too many empty attribute slots.\n * @category Issue and loss codes\n */\nexport const TOO_MANY_EMPTY_CELLS_CODE = \"E_TOO_MANY_EMPTY_CELLS\";\n\n/** The default limit: 2^24 empty slots, about 130 MB of f64 columns. */\nconst DEFAULT_MAX_EMPTY_CELLS = 2 ** 24;\n\n/**\n * Resolve the maxEmptyCells option.\n * @param value - the caller's value\n * @returns a non-negative integer or Infinity\n * @throws GraphFormatError E_UNSUPPORTED for anything else\n * @category Plugin helpers\n */\nexport function maxEmptyCellsOption(value: unknown): number {\n if (value === undefined) {\n return DEFAULT_MAX_EMPTY_CELLS;\n }\n if (typeof value === \"number\" && value >= 0 && (Number.isInteger(value) || value === Infinity)) {\n return value;\n }\n throw new GraphFormatError(\n \"E_UNSUPPORTED\",\n `option maxEmptyCells: ${describe(value)} is not a non-negative integer or Infinity`,\n { option: \"maxEmptyCells\", found: value },\n );\n}\n\n/**\n * A GraphBuilder that throws an ImportError once its attribute columns hold too many empty slots.\n * @category Plugin helpers\n */\nexport class CellBudgetBuilder extends GraphBuilder {\n private readonly nodeColumns = new Set<number>();\n private readonly edgeColumns = new Set<number>();\n private values = 0;\n\n /**\n * Create a builder with a limit.\n * @param options - the builder options\n * @param format - the format being read, for the error's report\n * @param maxEmptyCells - the most empty slots allowed\n */\n constructor(\n options: GraphBuilderOptions,\n private readonly format: string,\n private readonly maxEmptyCells: number,\n ) {\n super(options);\n }\n\n /**\n * Add a node, then check the limit (its row adds a slot to every node column).\n * @param id - the node id\n * @returns the node index\n */\n override addNode(id: NodeId): number {\n const index = super.addNode(id);\n this.checkBudget();\n return index;\n }\n\n /**\n * Add an edge, then check the limit (its row adds a slot to every edge column).\n * @param source - source id\n * @param target - target id\n * @param weight - the weight\n * @returns the edge index\n */\n override addEdge(source: NodeId, target: NodeId, weight?: number): number {\n const edge = super.addEdge(source, target, weight);\n this.checkBudget();\n return edge;\n }\n\n /**\n * Declare a node column, then check the limit.\n * @param decl - the declaration\n * @returns the column handle\n */\n override declareNodeColumn(decl: ColumnDecl): ColumnHandle {\n const handle = super.declareNodeColumn(decl);\n this.nodeColumns.add(handle);\n this.checkBudget();\n return handle;\n }\n\n /**\n * Declare an edge column, then check the limit.\n * @param decl - the declaration\n * @returns the column handle\n */\n override declareEdgeColumn(decl: ColumnDecl): ColumnHandle {\n const handle = super.declareEdgeColumn(decl);\n this.edgeColumns.add(handle);\n this.checkBudget();\n return handle;\n }\n\n /**\n * Set a node cell (a new name declares a column), then check the limit.\n * @param column - the handle or name\n * @param index - the node index\n * @param value - the value\n */\n override setNodeValue(column: ColumnHandle | string, index: number, value: unknown): void {\n super.setNodeValue(column, index, value);\n this.nodeColumns.add(typeof column === \"string\" ? this.nodeColumn(column) : column);\n this.count(value);\n }\n\n /**\n * Set an edge cell (a new name declares a column), then check the limit.\n * @param column - the handle or name\n * @param edge - the edge index\n * @param value - the value\n */\n override setEdgeValue(column: ColumnHandle | string, edge: number, value: unknown): void {\n super.setEdgeValue(column, edge, value);\n this.edgeColumns.add(typeof column === \"string\" ? this.edgeColumn(column) : column);\n this.count(value);\n }\n\n /**\n * Count a written value and check the budget.\n * @param value - the value; null and undefined unset a slot and do not count\n */\n private count(value: unknown): void {\n if (value !== null && value !== undefined) {\n this.values++;\n }\n this.checkBudget();\n }\n\n /**\n * Throw when the columns' slots minus the values written pass the limit.\n * @throws ImportError E_TOO_MANY_EMPTY_CELLS\n */\n private checkBudget(): void {\n const slots = this.nodeColumns.size * this.nodeBound + this.edgeColumns.size * this.edgeBound;\n const empty = slots - this.values;\n if (empty > this.maxEmptyCells) {\n new ImportReportBuilder(this.format, Infinity).fail(\n TOO_MANY_EMPTY_CELLS_CODE,\n `the attributes are too sparse: ${this.nodeColumns.size} node and ${this.edgeColumns.size} edge ` +\n `attribute columns over ${this.nodeBound} node${plural(this.nodeBound)} and ${this.edgeBound} edge${plural(this.edgeBound)} would ` +\n `allocate more than ${this.maxEmptyCells} slots that hold no value; pass a larger ` +\n `maxEmptyCells (or Infinity) to read the file anyway`,\n undefined,\n { emptyCells: empty, maxEmptyCells: this.maxEmptyCells },\n );\n }\n }\n}\n","/**\n * The importer / exporter registry: the 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 { CellBudgetBuilder, maxEmptyCellsOption } from \"./common/cell-budget.js\";\nimport {\n EDGES_MERGED_CODE,\n EMPTY_INPUT_CODE,\n FETCH_CODE,\n OPTION_IGNORED_CODE,\n SELF_LOOPS_DROPPED_CODE,\n UNKNOWN_OPTION_CODE,\n WEIGHT_NOT_FOUND_CODE,\n} from \"./common/codes.js\";\nimport { abortable, foreignKind, lockReader, normalizeInput, throwIfAborted } from \"./common/input.js\";\nimport { chooseGraph, resolveImportOptions } from \"./common/options.js\";\nimport { agree, plural } from \"./common/plural.js\";\nimport { ImportReportBuilder, isAbortError, messageOf } from \"./common/report.js\";\nimport { collectBytes } from \"./common/writer.js\";\nimport { csvExporter, csvImporter } from \"./formats/csv/index.js\";\nimport { cxExporter, cxImporter } from \"./formats/cx/index.js\";\nimport { cx2Exporter, cx2Importer } from \"./formats/cx2/index.js\";\nimport { cysExporter, cysImporter } from \"./formats/cys/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 { oboExporter, oboImporter } from \"./formats/obo/index.js\";\nimport { pajekExporter, pajekImporter } from \"./formats/pajek/index.js\";\nimport { xgmmlExporter, xgmmlImporter } from \"./formats/xgmml/index.js\";\nimport { type FormatName, rankFormats, SNIFF_HEAD_BYTES, type SniffHints, type SniffResult } from \"./sniff.js\";\nimport {\n type CommonExportOptions,\n type CommonImportOptions,\n type ExportCapabilities,\n type GraphChoiceOptions,\n type GraphExporter,\n type GraphImporter,\n type GraphListing,\n ImportError,\n type ImportInput,\n type ImportIssue,\n type ImportReport,\n type IssueCategory,\n type LossNote,\n} from \"./types.js\";\n\n/**\n * The input is in no format graph-io can read (or none of the formats you registered, for your own FormatRegistry).\n * Pass `format` when you know what the file is.\n * @category Issue and loss codes\n */\nexport const UNKNOWN_FORMAT_CODE = \"E_UNKNOWN_FORMAT\";\n\n/**\n * Registered importer whose sniff() threw while the format was being chosen; that importer was treated as not\n * recognizing the input (a defect in that importer).\n * @category Issue and loss codes\n */\nexport const SNIFF_FAILED_CODE = \"W_SNIFF_FAILED\";\n\n/**\n * The `builder` option of importGraph(): settings for building the graph that the common import\n * options do not cover. `weighted`: \"auto\" (the default) gives the graph weights when any edge has\n * one, true always does (every weight 1 when the file has none), false never does. `expectedNodes`\n * and `expectedEdges`: how many nodes and edges to make room for up front, which saves time on a\n * large file whose size you know.\n * @category Loading\n */\nexport type BuilderSeed = Omit<\n GraphBuilderOptions,\n \"directed\" | \"addMissingNodes\" | \"duplicateEdges\" | \"selfLoops\" | \"weightDtype\"\n>;\n\n/**\n * The options of importGraph(), importAllGraphs(), listGraphs() and loadFromFile(): the common\n * import options, the format and the hints used to detect it, the graph to read from a file that\n * holds several, and any format-specific option (`delimiter`, `dialect`, ...), which reaches the\n * importer unchanged.\n * @category Loading\n */\nexport interface ImportGraphOptions extends CommonImportOptions, GraphChoiceOptions {\n /**\n * The format to read the input as (\"graphml\", \"csv\", ...; `listFormats()` names them all), or\n * \"auto\" to work it out from `filename`, `mimeType` and the first bytes of the input. Name it to\n * be strict: detection reads a file graph-io cannot place as the closest format it recognizes.\n * @defaultValue \"auto\"\n */\n readonly format?: FormatName | \"auto\" | undefined;\n /**\n * The file name or full path the input came from; only its extension is used, as a format hint.\n * loadFromUrl() takes it from the URL and loadFromFile() from a File's name when you do not pass\n * it.\n */\n readonly filename?: string | null | undefined;\n /**\n * The MIME type the input was served as, a format hint. loadFromUrl() takes it from the\n * response's Content-Type and loadFromFile() from the Blob's `type` when you do not pass it.\n */\n readonly mimeType?: string | null | undefined;\n /**\n * Settings for building the graph: `weighted` (\"auto\", true or false: whether the graph gets\n * weights), `expectedNodes` and `expectedEdges` (room to make up front for a large file). Most\n * programs never set it.\n */\n readonly builder?: BuilderSeed | undefined;\n /**\n * Settings for the last step of an import, which turns what was read into the snapshot:\n * `label` (a name for debugging, read back as `snapshot.label`), `prepare` (views of the graph\n * to compute up front, such as `[\"reverse\"]`), `checksum` (record checksums, which\n * `snapshot.validate({ checksum: true })` compares later to catch changed memory) and `profile` (record how long each step took, in `result.freeze.timings`). Most\n * programs never set it.\n */\n readonly freeze?: FreezeOptions | undefined;\n /**\n * The most attribute slots that hold no value the import may allocate before it stops with an\n * ImportError whose `issue.code` is E_TOO_MANY_EMPTY_CELLS. Every attribute is a column with one slot per node (or edge), so a file\n * whose nodes each have a differently named attribute would otherwise need nodes x attributes\n * memory. Infinity turns the check off. Files whose elements mostly share their attributes are\n * never stopped.\n * @defaultValue 16777216\n */\n readonly maxEmptyCells?: number | undefined;\n /** Format-specific options, passed to the importer as they are. */\n readonly [formatOption: string]: unknown;\n}\n\n/**\n * What importGraph(), loadFromUrl() and loadFromFile() return.\n * @category Loading\n */\nexport interface ImportGraphResult {\n /** The format the input was read as (\"graphml\", ...). */\n readonly format: string;\n /**\n * How the format was detected (the candidate's `confidence` and what matched), or null when you\n * named the format. Most callers can ignore it. For the JSON dialect that was read, call\n * `jsonShapeOf(snapshot)` from `@graphty/graph-io/json`.\n */\n readonly sniff: SniffResult | null;\n /**\n * The graph. `snapshot.nodeCount`, `snapshot.edgeCount`, attribute tables and so on come from\n * the `@graphty/graph-format` package.\n */\n readonly snapshot: GraphSnapshot;\n /**\n * What happened during the import. `errorCount` counts skipped elements (see `errorLimit`,\n * default 100); `warningCount` counts elements that were kept but changed; `issues` lists both;\n * `counts.skippedNodes` / `counts.skippedEdges` say how much is missing from `snapshot`.\n */\n readonly report: ImportReport;\n /**\n * What the last step of the import did to the graph: `mergedEdges` (parallel edges merged by\n * `duplicateEdges`), `droppedSelfLoops` (removed by `selfLoops: \"drop\"`), and `timings` when you\n * passed `freeze: { profile: true }`. Both counts are also reported as warnings, so most callers\n * can ignore it. It is not enumerable, so `console.log(result)` and `{ ...result }` leave it out.\n */\n readonly freeze: FreezeReport;\n}\n\n/**\n * Options for loadFromUrl(): everything importGraph() accepts, plus the fetch request settings.\n * @example\n * ```ts\n * await loadFromUrl(\"/api/graph.csv\", { request: { headers: { Authorization: token } }, delimiter: \";\" });\n * ```\n * @category Loading\n */\nexport interface LoadFromUrlOptions extends ImportGraphOptions {\n /**\n * Passed to fetch() as its second argument: headers, credentials, mode and so on. If you set\n * `signal` in the import options and not here, the same signal also cancels the download.\n */\n readonly request?: RequestInit | undefined;\n}\n\n/**\n * Options for downloadGraph(): the export options plus the name of the saved file.\n * @example\n * ```ts\n * await downloadGraph(snapshot, \"graphml\", { filename: \"network.graphml\" });\n * ```\n * @category Saving\n */\nexport interface DownloadGraphOptions extends ExportGraphOptions {\n /**\n * The file name the browser saves as. The default is \"graph\" plus the first entry of the\n * format's `extensions` (\"graph.graphml\"), or \"graph.<format>\" when it lists none.\n * @defaultValue \"graph\" plus the format's extension\n */\n readonly filename?: string | undefined;\n}\n\n/**\n * One format the registry can read, write or both.\n * @category Formats and detection\n */\nexport interface FormatInfo {\n /** The name you pass as `format`: \"graphml\", \"gexf\", \"csv\", \"pajek\", ... */\n readonly format: string;\n /**\n * File extensions with the leading dot, most common first (\".graphml\", \".net\"). Empty only for a\n * custom format that declares none.\n */\n readonly extensions: readonly string[];\n /** MIME types, most specific first. Empty when the format declares none. */\n readonly mimeTypes: readonly string[];\n /** Whether loadFromUrl(), loadFromFile() and importGraph() can read it. */\n readonly canImport: boolean;\n /** Whether the export functions can write it. */\n readonly canExport: boolean;\n /**\n * What the format can store exactly, or null when it cannot be written. The fields are\n * mixedDirection, multiEdges, selfLoops, edgeIds, idCharset, dtypes, components, lists, json,\n * defaults, options, hierarchy, temporal, graphAttributes, positions and viz (each documented on\n * ExportCapabilities). checkExport() tells you where a particular graph goes beyond this.\n */\n readonly capabilities: ExportCapabilities | null;\n}\n\n/**\n * The options of exportGraph(): the common export options plus any format-specific option, passed through.\n * @category Saving\n */\nexport interface ExportGraphOptions extends CommonExportOptions {\n /** Format-specific options, passed to the exporter as they are. */\n readonly [formatOption: string]: unknown;\n}\n\n/**\n * The options the load and save functions take themselves: the common import and export options and the functions'\n * own. With the formats' own `options` lists, these are the names a load or a save knows.\n */\nconst FUNCTION_OPTIONS: ReadonlySet<string> = new Set([\n \"addMissingNodes\",\n \"builder\",\n \"defaultDirected\",\n \"duplicateEdges\",\n \"encoding\",\n \"errorLimit\",\n \"filename\",\n \"format\",\n \"freeze\",\n \"graphIndex\",\n \"graphName\",\n \"hyperedges\",\n \"ids\",\n \"long\",\n \"maxEmptyCells\",\n \"mimeType\",\n \"nodeIdFrom\",\n \"onMixedDirection\",\n \"onProgress\",\n \"request\",\n \"restoreMangledIds\",\n \"sanitizeIds\",\n \"selfLoops\",\n \"signal\",\n \"weightDtype\",\n \"weightFrom\",\n]);\n\n/** The keys of ImportGraphOptions that belong to the registry, never to an importer. */\nconst REGISTRY_KEYS: ReadonlySet<string> = new Set([\n \"format\",\n \"filename\",\n \"mimeType\",\n \"builder\",\n \"freeze\",\n \"maxEmptyCells\",\n]);\n\n/**\n * A registry of importers and exporters by format name. Registration order is the tie-break\n * order of sniffing; the default registry lists the built-in formats in the\n * order of GRAPH_FORMATS.\n * @category Formats and detection\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: FormatName): 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: FormatName): 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: FormatName): 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: FormatName): 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 * Every format that could be the input, best first, from the same hints as sniff(): use it to\n * offer the user a choice when the best guess is not certain.\n * @param hints - `{ filename, mimeType, head }`, any of them\n * @returns the candidates, best first; empty when no format claims the input\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 a graph from a string, bytes or a stream. The format is the one you name in `format`,\n * else it is detected from `filename`, `mimeType` and the first bytes of the content. From an\n * input that holds several graphs, it reads the one `graphIndex` or `graphName` chooses, else\n * the first, with a W_MULTIPLE_GRAPHS warning; 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 graph (`snapshot`), the format it was read as, and the import report\n */\n async importGraph(\n input: ImportInput,\n options: ImportGraphOptions | CommonImportOptions = {},\n ): Promise<ImportGraphResult> {\n const opts = options as ImportGraphOptions;\n const picked = await this.choose(input, opts);\n const unknown = this.unknownOptions(opts).map((name): ImportIssue =>\n Object.freeze({\n category: \"unsupported\",\n severity: \"warning\",\n code: UNKNOWN_OPTION_CODE,\n message: unknownOptionText(name),\n line: null,\n element: name,\n }),\n );\n const chosen = unknown.length === 0 ? picked : { ...picked, warnings: [...picked.warnings, ...unknown] };\n const { importer } = chosen;\n if (\n (opts.graphIndex !== undefined || opts.graphName !== undefined) &&\n importer.importAll !== undefined &&\n importer.listGraphs === undefined\n ) {\n // an importer that reads several graphs but does not choose among them itself (DOT, GML,\n // Pajek): read them all and return the chosen one, so the choice is never ignored\n const all = await this.readAll(chosen, opts);\n const names = all.map((r) => r.snapshot.meta.name);\n return all[chooseGraph(names, opts, new ImportReportBuilder(importer.format, 0))];\n }\n let builder: GraphBuilder;\n let report: ImportReport;\n try {\n builder = seededBuilder(opts, chosen.importer.format);\n report = await chosen.importer.import(chosen.source, builder, importerOptions(opts));\n } catch (err) {\n await chosen.peeked?.close();\n throw chosen.sniff === null ? notReadableAs(err, importer.format, opts.filename) : err;\n }\n return result(chosen, builder, report, opts);\n }\n\n /**\n * Fetch a graph file from a URL and load it; see the top-level loadFromUrl() for the full\n * description.\n * @param url - an absolute URL, or in a browser one relative to the page\n * @param options - import options, plus `request` for fetch\n * @returns the graph, the format it was read as, and the import report\n */\n async loadFromUrl(\n url: string | URL,\n options: LoadFromUrlOptions | CommonImportOptions = {},\n ): Promise<ImportGraphResult> {\n const opts = options as LoadFromUrlOptions;\n const { request, ...rest } = opts;\n const signal = request?.signal ?? rest.signal ?? null;\n const method = request?.method ?? \"GET\";\n const where = `${method} ${String(url)}`;\n let response: Response;\n try {\n response = await fetch(url, { signal: rest.signal, ...request });\n } catch (err) {\n if (signal?.aborted === true || isAbortError(err)) {\n throw err;\n }\n return fetchFailed(rest, url, `${where} failed: ${fetchErrorText(url, err)}`, null, err);\n }\n if (!response.ok) {\n await response.body?.cancel().catch(() => undefined);\n const status = `${String(response.status)} ${response.statusText}`.trim();\n return fetchFailed(rest, url, `${where} failed: ${status}`, response.status, null);\n }\n return this.importGraph(response.body ?? new Uint8Array(0), {\n ...rest,\n filename: rest.filename ?? urlFilename(url),\n mimeType: rest.mimeType ?? response.headers.get(\"content-type\"),\n });\n }\n\n /**\n * Load a graph from a File or Blob; see the top-level loadFromFile() for the full description.\n * @param file - the File or Blob to read\n * @param options - the same options as importGraph()\n * @returns the graph, the format it was read as, and the import report\n */\n loadFromFile(file: Blob, options: ImportGraphOptions | CommonImportOptions = {}): Promise<ImportGraphResult> {\n const opts = options as ImportGraphOptions;\n const { name } = file as { name?: unknown };\n return this.importGraph(file.stream(), {\n ...opts,\n filename: opts.filename ?? (typeof name === \"string\" ? name : null),\n mimeType: opts.mimeType ?? (file.type === \"\" ? null : file.type),\n });\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 as its own snapshot. A format that holds\n * one graph per file gives one result. Options and detection 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(\n input: ImportInput,\n options: ImportGraphOptions | CommonImportOptions = {},\n ): Promise<ImportGraphResult[]> {\n const opts = options as ImportGraphOptions;\n return this.readAll(await this.choose(input, opts), opts);\n }\n\n /**\n * Read every graph of an input with the chosen importer.\n * @param chosen - the importer and the input to hand it\n * @param options - the importGraph options\n * @returns one result per graph, in document order\n */\n private async readAll(chosen: ChosenImporter, options: ImportGraphOptions): Promise<ImportGraphResult[]> {\n const { importer } = chosen;\n const builders: GraphBuilder[] = [];\n let reports: ImportReport[];\n try {\n if (importer.importAll === undefined) {\n builders.push(seededBuilder(options, importer.format));\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, importer.format);\n builders.push(builder);\n return builder;\n },\n importerOptions(options),\n );\n }\n } catch (err) {\n await chosen.peeked?.close();\n throw inGraph(\n chosen.sniff === null ? notReadableAs(err, importer.format, options.filename) : err,\n builders.length - 1,\n );\n }\n return reports.map((report, i) => {\n try {\n return result(chosen, builders[i], report, options);\n } catch (err) {\n throw inGraph(err, i);\n }\n });\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(\n input: ImportInput,\n options: ImportGraphOptions | CommonImportOptions = {},\n ): Promise<readonly GraphListing[] | null> {\n const opts = options as ImportGraphOptions;\n const chosen = await this.choose(input, opts);\n try {\n return chosen.importer.listGraphs === undefined\n ? null\n : await chosen.importer.listGraphs(chosen.source, importerOptions(opts));\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 rawInput - the input as the caller passed it\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(rawInput: ImportInput, options: ImportGraphOptions): Promise<ChosenImporter> {\n const input = normalizeInput(rawInput);\n const requested = options.format ?? \"auto\";\n if (requested !== \"auto\") {\n return { importer: this.importer(requested), sniff: null, source: input, peeked: null, warnings: [] };\n }\n // the options are checked before the input is touched, so a bad option never leaves a\n // peeked stream locked; the importer resolves them again with its own defaults\n const common = resolveImportOptions(options, { ids: \"keep\", defaultDirected: true, weightFrom: null });\n maxEmptyCellsOption(options.maxEmptyCells);\n const peeked = await peekHead(input, SNIFF_HEAD_BYTES, common.signal);\n // the head is sniffed as the importer will read it: in the caller's encoding when given\n const head =\n common.encoding !== null && peeked.head instanceof Uint8Array\n ? new TextDecoder(common.encoding).decode(peeked.head, { stream: true })\n : peeked.head;\n let sniff: SniffResult | null;\n const failures = new ImportReportBuilder(\"unknown\", 0);\n const warnings: ImportIssue[] = [];\n try {\n const hints = { filename: options.filename, mimeType: options.mimeType, head };\n const ranked = rankFormats(hints, this.importerMap.values(), (format, err) => {\n warnings.push(\n failures.warning(\n \"unsupported\",\n SNIFF_FAILED_CODE,\n `the ${format} importer's sniff() threw (${messageOf(err)}); it was treated as not recognizing the input`,\n { element: format },\n ),\n );\n });\n sniff = ranked.length > 0 ? ranked[0] : null;\n } catch (err) {\n await peeked.close();\n throw err;\n }\n // a known non-graph file is refused whatever its name says, unless an importer claims its\n // content (a Cytoscape session is a zip); an HTML page always (the XML sniffers would\n // otherwise claim it by its markup)\n const foreign = foreignKind(peeked.head);\n const claimed = sniff !== null && sniff.content > 0 && !(foreign?.startsWith(\"an HTML\") ?? false);\n if (sniff === null || (foreign !== null && !claimed)) {\n await peeked.close();\n return this.refuseUndetected(failures, head, foreign, options);\n }\n return { importer: this.importer(sniff.format), sniff, source: peeked.input, peeked, warnings };\n }\n\n /**\n * Refuse an input no importer recognizes: empty, or not in a known graph format.\n * @param failures - the report the error is recorded in\n * @param head - the head, as sniffed\n * @param foreign - what known non-graph file the head is, or null\n * @param options - the importGraph options\n * @returns never: always throws\n */\n private refuseUndetected(\n failures: ImportReportBuilder,\n head: Uint8Array | string | null,\n foreign: string | null,\n options: ImportGraphOptions,\n ): never {\n const text = typeof head === \"string\" ? head : new TextDecoder().decode(head ?? new Uint8Array(0));\n if (text.trim() === \"\" && text.length < SNIFF_HEAD_BYTES) {\n // nothing to detect: say the input is empty, as a named format would\n return failures.fail(\n EMPTY_INPUT_CODE,\n text === \"\" ? \"the input is empty\" : \"the input holds only whitespace\",\n );\n }\n const what = foreign === null ? \"\" : `: it is ${foreign}`;\n return failures.fail(\n UNKNOWN_FORMAT_CODE,\n `the input is not in a graph format graph-io recognizes${describeHints(options)}${what}; if you know its format, pass it as the format option`,\n undefined,\n { formats: this.formats() },\n );\n }\n\n /**\n * Write a snapshot in a format, 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 */\n exportGraph(\n snapshot: GraphSnapshot,\n format: FormatName,\n options?: ExportGraphOptions | CommonExportOptions,\n ): 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(\n snapshot: GraphSnapshot,\n format: FormatName,\n options?: ExportGraphOptions | CommonExportOptions,\n ): Promise<string> {\n return this.exporter(format).exportToString(snapshot, options);\n }\n\n /**\n * Write a snapshot in a format as one buffer of UTF-8 bytes; see the top-level\n * exportGraphToBytes().\n * @param snapshot - the graph to write\n * @param format - a format name where `canExport` is true\n * @param options - sanitizeIds, onMixedDirection and the format's own options\n * @returns the encoded file\n */\n exportGraphToBytes(\n snapshot: GraphSnapshot,\n format: FormatName,\n options?: ExportGraphOptions | CommonExportOptions,\n ): Promise<Uint8Array> {\n return collectBytes(this.exportGraph(snapshot, format, options));\n }\n\n /**\n * Write a snapshot in a format as a Blob typed with the format's first MIME type; see the\n * top-level exportGraphToBlob().\n * @param snapshot - the graph to write\n * @param format - a format name where `canExport` is true\n * @param options - sanitizeIds, onMixedDirection and the format's own options\n * @returns the file as a Blob\n */\n async exportGraphToBlob(\n snapshot: GraphSnapshot,\n format: FormatName,\n options?: ExportGraphOptions | CommonExportOptions,\n ): Promise<Blob> {\n const parts: Uint8Array[] = [];\n for await (const chunk of this.exportGraph(snapshot, format, options)) {\n parts.push(chunk);\n }\n const info = this.listFormats().find((f) => f.format === format);\n return new Blob(parts as BlobPart[], { type: info?.mimeTypes[0] ?? \"application/octet-stream\" });\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(\n snapshot: GraphSnapshot,\n format: FormatName,\n options?: ExportGraphOptions | CommonExportOptions,\n ): readonly LossNote[] {\n const notes = this.exporter(format).check(snapshot, options);\n const unknown = this.unknownOptions(options);\n if (unknown.length === 0) {\n return notes;\n }\n return Object.freeze([\n ...notes,\n ...unknown.map((name) =>\n Object.freeze({\n code: UNKNOWN_OPTION_CODE,\n message: unknownOptionText(name),\n column: null,\n count: null,\n }),\n ),\n ]);\n }\n\n /**\n * The option names no registered format and no load or save function takes (misspellings), or none while a\n * registered format does not list its options.\n * @param options - the caller's options\n * @returns the unknown names\n */\n private unknownOptions(options: object | null | undefined): string[] {\n if (options === null || options === undefined) {\n return [];\n }\n const known = new Set(FUNCTION_OPTIONS);\n for (const plugin of [...this.importerMap.values(), ...this.exporterMap.values()]) {\n if (plugin.options === undefined) {\n return [];\n }\n for (const name of plugin.options) {\n known.add(name);\n }\n }\n return Object.entries(options)\n .filter(([name, value]) => value !== undefined && !known.has(name))\n .map(([name]) => name);\n }\n\n /**\n * Browser only: write a graph in a format and have the browser save it as a file; see the\n * top-level downloadGraph(). Use this method on a registry from createRegistry() to download\n * without bundling every built-in format.\n * @param snapshot - the graph to write\n * @param format - a format name from listFormats() where `canExport` is true\n * @param options - the export options, plus `filename`\n * @returns resolves once the download has been handed to the browser\n */\n async downloadGraph(\n snapshot: GraphSnapshot,\n format: FormatName,\n options: DownloadGraphOptions | CommonExportOptions = {},\n ): Promise<void> {\n if (typeof document === \"undefined\") {\n throw new GraphFormatError(\n \"E_UNSUPPORTED\",\n \"downloadGraph() needs a browser document; use exportGraphToBytes() and write the bytes yourself\",\n );\n }\n const { filename, ...rest } = options as DownloadGraphOptions;\n const blob = await this.exportGraphToBlob(snapshot, format, rest);\n const extension = this.listFormats().find((f) => f.format === format)?.extensions[0] ?? `.${format}`;\n const href = URL.createObjectURL(blob);\n const anchor = document.createElement(\"a\");\n anchor.href = href;\n anchor.download = filename ?? `graph${extension}`;\n anchor.click();\n // Safari cancels the download when the URL is revoked in the same task\n setTimeout(() => {\n URL.revokeObjectURL(href);\n }, 0);\n }\n\n /**\n * Every format this registry can read or write, in registration order; see the top-level\n * listFormats().\n * @returns one entry per format\n */\n listFormats(): readonly FormatInfo[] {\n return this.formats().map((format) => {\n const importer = this.importerMap.get(format);\n const exporter = this.exporterMap.get(format);\n return Object.freeze({\n format,\n extensions: importer?.extensions ?? exporter?.extensions ?? [],\n mimeTypes: importer?.mimeTypes ?? exporter?.mimeTypes ?? [],\n canImport: importer !== undefined,\n canExport: exporter !== undefined,\n capabilities: exporter?.capabilities ?? null,\n });\n });\n }\n}\n\n/**\n * A new registry holding every built-in importer and exporter, in the order of GRAPH_FORMATS.\n * @returns a new registry\n * @category Formats and detection\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(xgmmlImporter)\n .registerExporter(xgmmlExporter)\n .registerImporter(cx2Importer)\n .registerExporter(cx2Exporter)\n .registerImporter(cxImporter)\n .registerExporter(cxExporter)\n .registerImporter(oboImporter)\n .registerExporter(oboExporter)\n .registerImporter(cysImporter)\n .registerExporter(cysExporter);\n}\n\n/**\n * The default registry: every built-in format.\n * @category Formats and detection\n */\nexport const registry: FormatRegistry = /* @__PURE__ */ createRegistry();\n\n/**\n * Read a graph from a string, bytes or a stream. The format is the one you name in `format`, else\n * it is detected from `filename`, `mimeType` and the first bytes; an input that matches no format\n * fails with E_UNKNOWN_FORMAT. From a file that holds several graphs it reads the one `graphIndex`\n * or `graphName` chooses, else the first, with a W_MULTIPLE_GRAPHS warning. For a File or Blob use\n * loadFromFile(), for a URL loadFromUrl().\n * @param input - the whole text, the bytes (a Uint8Array or a Node Buffer), a ReadableStream of\n * bytes, or an async iterable of text or byte chunks (a Node read stream)\n * @param options - the format, format hints, the options every importer takes and the format's own\n * options\n * @returns the graph (`snapshot`), the format it was read as, and the import report\n * @throws ImportError when the input could not be read; `err.issue?.code` says why\n * @throws GraphFormatError with code E_UNSUPPORTED for a `format` no importer is registered for, or\n * an option value that is not allowed (`err.details.option` names it)\n * @throws the signal's reason when `signal` aborts\n * @category Loading\n */\nexport function importGraph(\n input: ImportInput,\n options?: ImportGraphOptions | CommonImportOptions,\n): Promise<ImportGraphResult> {\n return registry.importGraph(input, options);\n}\n\n/**\n * Read every graph of a file that can hold several (DOT, GML, a Pajek project, a JSON Graph Format\n * or OBO Graphs document, CX, XGMML, a Cytoscape session). A format that holds one graph per file\n * gives one result. Options and errors are the same as importGraph()'s.\n * @param input - the text, bytes or stream to read\n * @param options - the same options as importGraph()\n * @returns one result per graph, in file order\n * @category Loading\n */\nexport function importAllGraphs(\n input: ImportInput,\n options?: ImportGraphOptions | CommonImportOptions,\n): Promise<ImportGraphResult[]> {\n return registry.importAllGraphs(input, options);\n}\n\n/**\n * List the graphs of a file without reading them: each one's `index`, `name`, and node and edge\n * counts when the file states them. Pass the index or name to importGraph() as `graphIndex` or\n * `graphName`. The counts come from the file and can differ from what an import reads, for example\n * when the import adds edges the listing does not count. JSON, CX, XGMML and Cytoscape sessions can\n * list their graphs; for DOT, GML and Pajek it returns null, and importAllGraphs() is the way to see\n * them.\n * @param input - the text, bytes or stream to read\n * @param options - the same options as importGraph()\n * @returns one listing per graph, in file order; null when the format cannot list its graphs\n * @category Loading\n */\nexport function listGraphs(\n input: ImportInput,\n options?: ImportGraphOptions | CommonImportOptions,\n): Promise<readonly GraphListing[] | null> {\n return registry.listGraphs(input, options);\n}\n\n/**\n * Write a graph in a format as a stream of UTF-8 byte chunks, for a graph too large to hold as one\n * file in memory. In Node, pipe it to a file with `pipeline(exportGraph(...), createWriteStream(path))`.\n * Options and errors are the same as exportGraphToBytes()'s.\n * @param snapshot - the graph to write\n * @param format - a format name from listFormats() where `canExport` is true\n * @param options - sanitizeIds, onMixedDirection and the format's own options\n * @returns the file's bytes, chunk by chunk\n * @category Saving\n */\nexport function exportGraph(\n snapshot: GraphSnapshot,\n format: FormatName,\n options?: ExportGraphOptions | CommonExportOptions,\n): AsyncIterable<Uint8Array> {\n return registry.exportGraph(snapshot, format, options);\n}\n\n/**\n * Write a graph in a format and return the file as one string. A binary format (a Cytoscape\n * session) cannot be a string and fails with E_UNSUPPORTED; use exportGraphToBytes() for it. Options\n * and errors are the same as exportGraphToBytes()'s.\n * @param snapshot - the graph to write\n * @param format - a format name from listFormats() where `canExport` is true\n * @param options - sanitizeIds, onMixedDirection and the format's own options\n * @returns the whole file\n * @category Saving\n */\nexport async function exportGraphToString(\n snapshot: GraphSnapshot,\n format: FormatName,\n options?: ExportGraphOptions | CommonExportOptions,\n): Promise<string> {\n return registry.exportGraphToString(snapshot, format, options);\n}\n\n/**\n * What saving a graph in a format would lose, without writing anything. Pass the same options you\n * will pass to the save. Each note has a stable `code`: \"E_\" means the save would throw, \"W_\" means\n * the file is written but that part does not read back the same. An empty array means the file\n * reads back as the same graph. Runs synchronously.\n * @param snapshot - the graph to check\n * @param format - a format name from listFormats() where `canExport` is true\n * @param options - the options you will save with\n * @returns the loss notes, empty when the save is exact\n * @throws GraphFormatError with code E_UNSUPPORTED when no exporter is registered for `format`, or\n * when an option value is not allowed (`err.details.option` names it)\n * @category Saving\n */\nexport function checkExport(\n snapshot: GraphSnapshot,\n format: FormatName,\n options?: ExportGraphOptions | CommonExportOptions,\n): readonly LossNote[] {\n return registry.checkExport(snapshot, format, options);\n}\n\n/**\n * Fetch a graph file from a URL and load it. The file is streamed into the importer as it\n * downloads, so a large file is not held in memory twice. When you do not name a `format`, it is\n * worked out from the URL's file name, the response's Content-Type and the first bytes of the\n * file. Your own `filename` or `mimeType` option takes the place of the hint from the URL or the\n * response. Every other option goes to importGraph() unchanged, including format-specific ones\n * such as `delimiter` or `dialect`, and `graphIndex` / `graphName` for files that hold several\n * graphs. The result is the same as importGraph()'s. A successful load can still have skipped\n * elements; check `report.errorCount` and `report.warningCount`, or pass `errorLimit: 0` to make\n * the first error fatal. Works wherever fetch exists: browsers, Node 18 and later, Deno, Bun and\n * workers.\n * @param url - an absolute URL, or in a browser one relative to the page\n * @param options - import options, plus `request` for fetch\n * @returns the graph, the format it was read as, and the import report\n * @throws ImportError when the file could not be loaded; `err.issue?.code` is \"E_FETCH\" for a\n * network failure, a CORS refusal or a status outside 200-299 (`err.details.url`,\n * `err.details.status` -- null for a network failure -- and `err.details.cause`, fetch's own\n * error), \"E_UNKNOWN_FORMAT\" when no format recognizes the file (pass `format`), or the code of\n * the parse error\n * @throws GraphFormatError with code E_UNSUPPORTED when `format` names no registered importer\n * @throws the signal's reason when `signal` aborts\n * @example\n * ```ts\n * import { GraphFormatError, loadFromUrl } from \"@graphty/graph-io\";\n *\n * try {\n * const { snapshot, format } = await loadFromUrl(\"https://example.com/data/karate.gml\");\n * console.log(`${format}: ${snapshot.nodeCount} nodes, ${snapshot.edgeCount} edges`);\n * } catch (err) {\n * if (err instanceof GraphFormatError) {\n * console.error(err.message);\n * } else {\n * throw err;\n * }\n * }\n * ```\n * @category Loading\n */\nexport function loadFromUrl(\n url: string | URL,\n options?: LoadFromUrlOptions | CommonImportOptions,\n): Promise<ImportGraphResult> {\n return registry.loadFromUrl(url, options);\n}\n\n/**\n * Load a graph from a File or Blob: a file the user picked in an `<input type=\"file\">`, a file\n * dropped on the page, a Blob you built, or in Node a Blob from `fs.openAsBlob(path)`. The content\n * is streamed into the importer. A File's `name` and the Blob's `type` are used as format hints\n * unless you pass `filename` or `mimeType` yourself. Options, result and errors are the same as\n * loadFromUrl()'s, without E_FETCH.\n * @param file - the File or Blob to read\n * @param options - the same options as importGraph()\n * @returns the graph, the format it was read as, and the import report\n * @throws ImportError when the file could not be loaded (`err.issue?.code` E_UNKNOWN_FORMAT or a parse error)\n * @throws GraphFormatError with code E_UNSUPPORTED when `format` names no registered importer\n * @throws the signal's reason when `signal` aborts\n * @example\n * ```ts\n * input.addEventListener(\"change\", async () => {\n * const file = input.files?.[0];\n * if (file) {\n * const { snapshot, report } = await loadFromFile(file);\n * console.log(`${snapshot.nodeCount} nodes, ${report.errorCount} skipped`);\n * }\n * });\n * ```\n * @category Loading\n */\nexport function loadFromFile(\n file: Blob,\n options?: ImportGraphOptions | CommonImportOptions,\n): Promise<ImportGraphResult> {\n return registry.loadFromFile(file, options);\n}\n\n/**\n * Write a graph in a format and return the whole file as UTF-8 bytes, ready for fs.writeFile, a\n * fetch body or a zip entry. Prefer this over exportGraphToString() when the result goes to a file\n * or the network. To stream a very large graph, use exportGraph(). To find out beforehand what the\n * file will not keep, call checkExport() with the same format and the same options object: every\n * \"E_\" note it returns makes this call throw, and every \"W_\" note describes a loss this call\n * accepts. Most \"E_\" notes go away with `sanitizeIds: \"mangle\"` (rewrite ids the format cannot\n * hold) or `onMixedDirection: \"directed\"` / `\"undirected\"`. The format's own options (the CSV\n * `table` and `dialect`, the GEXF `version`, ...) go in the same object.\n * @param snapshot - the graph to write\n * @param format - a format name from listFormats() where `canExport` is true\n * @param options - sanitizeIds, onMixedDirection and the format's own options\n * @returns the encoded file\n * @throws GraphFormatError with code E_UNSUPPORTED when no exporter is registered for `format`\n * @throws GraphFormatError when the graph cannot be written in this format under these options\n * (checkExport() returns an \"E_\" note for the same call). The thrown code names the kind of\n * failure rather than the note: E_INVALID_ID for ids (the E_ID_CHARSET and E_ID_TEXT_COLLISION\n * notes), E_DIRECTED for direction (E_MIXED_DIRECTION), and E_COLUMN_TYPE or E_UNSUPPORTED for a\n * value the format cannot write; each note's entry on the codes page says which\n * @throws GraphFormatError with code E_UNSUPPORTED for an option value that is not allowed\n * (`err.details.option` names it)\n * @example\n * ```ts\n * import { writeFile } from \"node:fs/promises\";\n *\n * await writeFile(\"out.gexf\", await exportGraphToBytes(snapshot, \"gexf\"));\n * ```\n * @category Saving\n */\nexport function exportGraphToBytes(\n snapshot: GraphSnapshot,\n format: FormatName,\n options?: ExportGraphOptions | CommonExportOptions,\n): Promise<Uint8Array> {\n return registry.exportGraphToBytes(snapshot, format, options);\n}\n\n/**\n * Write a graph in a format and return it as a Blob, for uploading with fetch or FormData or for\n * offering as a download. The Blob's `type` is the first entry of the format's `mimeTypes` in\n * listFormats(), or application/octet-stream when the format lists none. The exporter's chunks\n * are kept as they are and never joined into one string. Options and errors are the same as\n * exportGraphToBytes().\n * @param snapshot - the graph to write\n * @param format - a format name from listFormats() where `canExport` is true\n * @param options - sanitizeIds, onMixedDirection and the format's own options\n * @returns the file as a Blob\n * @throws the same errors as exportGraphToBytes()\n * @example\n * ```ts\n * const body = new FormData();\n * body.append(\"file\", await exportGraphToBlob(snapshot, \"graphml\"), \"graph.graphml\");\n * await fetch(\"/api/graphs\", { method: \"POST\", body });\n * ```\n * @category Saving\n */\nexport function exportGraphToBlob(\n snapshot: GraphSnapshot,\n format: FormatName,\n options?: ExportGraphOptions | CommonExportOptions,\n): Promise<Blob> {\n return registry.exportGraphToBlob(snapshot, format, options);\n}\n\n/**\n * Browser only: write a graph in a format and have the browser save it as a file, the same as\n * clicking a download link. Call it from a click handler; awaiting other work first is fine. The\n * promise resolves once the file has been handed to the browser. There is no way to learn\n * whether the user then canceled the save. Calling it where there is no `document` (Node, a\n * worker) throws instead of silently doing nothing; importing it is safe everywhere. Formats you\n * registered with `registry.registerExporter()` can be downloaded too.\n * @param snapshot - the graph to write\n * @param format - a format name from listFormats() where `canExport` is true\n * @param options - the export options, plus `filename`\n * @returns resolves once the download has been handed to the browser\n * @throws GraphFormatError with code E_UNSUPPORTED when called without a DOM `document`\n * @throws the same errors as exportGraphToBytes()\n * @example\n * ```ts\n * saveButton.addEventListener(\"click\", () => {\n * void downloadGraph(snapshot, \"graphml\", { filename: \"network.graphml\" });\n * });\n * ```\n * @category Saving\n */\nexport async function downloadGraph(\n snapshot: GraphSnapshot,\n format: FormatName,\n options: DownloadGraphOptions | CommonExportOptions = {},\n): Promise<void> {\n return registry.downloadGraph(snapshot, format, options);\n}\n\n/**\n * Every format the default registry can read or write, including any you registered yourself:\n * the built-in formats in the order of GRAPH_FORMATS (the order format detection prefers them),\n * then yours in registration order. Use it to fill a \"Save as\" menu (the entries with\n * `canExport`), a file input's `accept` attribute (the `extensions` of the entries with\n * `canImport`), or to pick the output format from a file name.\n * @returns one entry per format\n * @example\n * ```ts\n * input.accept = listFormats().filter((f) => f.canImport).flatMap((f) => f.extensions).join(\",\");\n * const target = listFormats().find((f) => f.canExport && f.extensions.includes(extensionOf(path) ?? \"\"));\n * ```\n * @category Formats and detection\n */\nexport function listFormats(): readonly FormatInfo[] {\n return registry.listFormats();\n}\n\n/**\n * Detect a file's format without reading it, from what you know about it: a `filename` (only the\n * extension counts), a `mimeType`, and `head`, the file's first bytes or characters (up to\n * SNIFF_HEAD_BYTES; pass `bytes.subarray(0, SNIFF_HEAD_BYTES)`). It uses every format of the default\n * registry, including the ones you registered. For every candidate, best first, call\n * `registry.sniffAll(hints)`.\n * @param hints - `{ filename, mimeType, head }`, any of them\n * @returns the best candidate (`format`, `confidence` and what matched), or null when no format\n * claims the input\n * @example\n * ```ts\n * sniff({ filename: \"graph.xml\", head: \"<?xml version=\\\"1.0\\\"?><gexf\" })?.format; // \"gexf\"\n * ```\n * @category Formats and detection\n */\nexport function sniff(hints: SniffHints): SniffResult | null {\n return registry.sniff(hints);\n}\n\n/**\n * Abort a loadFromUrl() whose fetch failed with an E_FETCH ImportError.\n * @param options - the import options (for the format name on the report)\n * @param url - the URL\n * @param message - the message\n * @param status - the HTTP status, or null for a network failure\n * @param cause - fetch's own error, or null\n * @returns never; always throws\n */\nfunction fetchFailed(\n options: ImportGraphOptions,\n url: string | URL,\n message: string,\n status: number | null,\n cause: unknown,\n): never {\n const format = options.format === undefined || options.format === \"auto\" ? \"unknown\" : options.format;\n return new ImportReportBuilder(format, 0).fail(FETCH_CODE, message, undefined, { url: String(url), status, cause });\n}\n\n/**\n * The error for an input refused by the format the caller named before any element was read: the\n * parser's message (\"line 1: text outside the root element\") prefixed with the file and the format,\n * since the likely cause is a file of another kind, not a damaged one.\n * @param err - what the importer threw\n * @param format - the format named in `format`\n * @param filename - the file name hint, if any\n * @returns the error to throw\n */\nfunction notReadableAs(err: unknown, format: string, filename: string | null | undefined): unknown {\n if (\n !(err instanceof ImportError) ||\n err.issue?.category !== \"parse-error\" ||\n err.report.errorCount > 1 ||\n err.report.counts.nodes + err.report.counts.edges > 0\n ) {\n return err;\n }\n const what = filename === undefined || filename === null ? \"the input\" : JSON.stringify(filename);\n return new ImportError(`${what} could not be read as ${format}: ${err.message}`, err.report, err.details);\n}\n\n/**\n * Why fetch() rejected, in words that point at the fix: a relative URL with no page to resolve it\n * against (Node), a file: URL fetch() does not read, or a network error, which in a browser\n * includes a CORS refusal.\n * @param url - the URL as given\n * @param err - what fetch() threw\n * @returns the reason\n */\nfunction fetchErrorText(url: string | URL, err: unknown): string {\n let absolute: URL | null = null;\n try {\n absolute = new URL(url);\n } catch {\n // relative: resolvable only against a page's location\n }\n if (absolute === null && (globalThis as { location?: unknown }).location === undefined) {\n return \"a relative URL needs a web page to resolve against; outside a browser pass an absolute http(s) URL, or read a local file with loadFromFile() or importGraph()\";\n }\n if (absolute?.protocol === \"file:\") {\n return \"fetch() cannot read file: URLs here; read a local file with loadFromFile() or importGraph()\";\n }\n const cause = (err as { cause?: { message?: unknown } } | null)?.cause?.message;\n const detail = typeof cause === \"string\" && cause !== \"\" ? ` (${cause})` : \"\";\n return `the server could not be reached, or (in a browser) it does not allow this page to read the file (CORS)${detail}`;\n}\n\n/**\n * The last path segment of a URL, as a format hint.\n * @param url - the URL, absolute or relative\n * @returns the file name, or null when the path ends in \"/\"\n */\nfunction urlFilename(url: string | URL): string | null {\n const path = new URL(url, \"http://localhost/\").pathname;\n const name = path.slice(path.lastIndexOf(\"/\") + 1);\n return name === \"\" ? null : name;\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 /** W_SNIFF_FAILED warnings for the import report, one per importer whose sniff() threw. */\n readonly warnings: readonly ImportIssue[];\n}\n\n/**\n * A fresh builder seeded from the common options, `directed: true` as a placeholder the importer\n * overrides from the file, that stops the import when its attributes get too sparse.\n * @param options - the importGraph options\n * @param format - the format being read\n * @returns the builder\n */\nfunction seededBuilder(options: ImportGraphOptions, format: string): GraphBuilder {\n const maxEmptyCells = maxEmptyCellsOption(options.maxEmptyCells);\n try {\n return newBuilder(options, format, maxEmptyCells);\n } catch (err) {\n // the builder names a bad value by its field; report it as the option the caller passed\n if (err instanceof GraphFormatError && err.code === \"E_UNSUPPORTED\" && typeof err.details.field === \"string\") {\n const option = err.details.field;\n throw new GraphFormatError(\n \"E_UNSUPPORTED\",\n `option ${option}: ${JSON.stringify(err.details.found)} is not one of the values it takes`,\n { option, found: err.details.found },\n );\n }\n throw err;\n }\n}\n\n/**\n * The builder of seededBuilder(), before its option errors are reworded.\n * @param options - the importGraph options\n * @param format - the format being read\n * @param maxEmptyCells - the empty-cell budget\n * @returns the builder\n */\nfunction newBuilder(options: ImportGraphOptions, format: string, maxEmptyCells: number): GraphBuilder {\n return new CellBudgetBuilder(\n {\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 format,\n maxEmptyCells,\n );\n}\n\n/**\n * Name the graph an importAllGraphs() failure belongs to: the report is that graph's own, so the\n * message is prefixed with its index and `details.graphIndex` set, for every graph including the\n * first. Anything other than an ImportError raised while a graph was being read passes unchanged.\n * @param err - the error thrown while reading or freezing a graph\n * @param index - the index of that graph, -1 before the first graph began\n * @returns the error to throw\n */\nfunction inGraph(err: unknown, index: number): unknown {\n if (!(err instanceof ImportError) || index < 0) {\n return err;\n }\n return new ImportError(`graph ${index}: ${err.message}`, err.report, { ...err.details, graphIndex: index });\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 let frozen: ReturnType<GraphBuilder[\"freezeWithReport\"]>;\n try {\n frozen = builder.freezeWithReport(options.freeze);\n } catch (err) {\n throw freezeFailure(err, report);\n }\n const { warnings } = chosen;\n const result = {\n format: chosen.importer.format,\n sniff: chosen.sniff,\n snapshot: frozen.snapshot,\n report: withFreezeWarnings(\n weightNotFound(\n warnings.length === 0\n ? report\n : Object.freeze({\n ...report,\n issues: Object.freeze([...warnings, ...report.issues]),\n warningCount: report.warningCount + warnings.length,\n }),\n frozen.snapshot,\n options.weightFrom,\n ),\n frozen.report,\n ),\n };\n // not enumerable: it holds one entry per edge, and console.log(result) should show the graph, not that\n Object.defineProperty(result, \"freeze\", { value: frozen.report, enumerable: false });\n return Object.freeze(result as ImportGraphResult);\n}\n\n/**\n * The message of a W_UNKNOWN_OPTION warning or note.\n * @param name - the option name\n * @returns the message\n */\nfunction unknownOptionText(name: string): string {\n return `option ${JSON.stringify(name)} is not an option of any format or of the load and save functions, so it has no effect; check its spelling`;\n}\n\n/**\n * The import report with one W_WEIGHT_NOT_FOUND warning when the caller's `weightFrom` named an attribute that gave\n * no edge a weight, so a name that misses (a shared options object read against GML's `value`) is not silent. A\n * format that does not read `weightFrom` already reported it as W_OPTION_IGNORED.\n * @param report - the import's report\n * @param snapshot - the graph read\n * @param weightFrom - the caller's option\n * @returns the report, with the warning added when it applies\n */\nfunction weightNotFound(report: ImportReport, snapshot: GraphSnapshot, weightFrom: unknown): ImportReport {\n if (\n typeof weightFrom !== \"string\" ||\n snapshot.edgeCount === 0 ||\n snapshot.edgeList().weights !== null ||\n report.issues.some((i) => i.code === OPTION_IGNORED_CODE && i.element === \"weightFrom\")\n ) {\n return report;\n }\n const issue: ImportIssue = Object.freeze({\n category: \"missing-value\",\n severity: \"warning\",\n code: WEIGHT_NOT_FOUND_CODE,\n message: `weightFrom: ${JSON.stringify(weightFrom)} names no attribute an edge has a value for, so the graph has no weights`,\n line: null,\n element: \"weightFrom\",\n });\n return Object.freeze({\n ...report,\n issues: Object.freeze([...report.issues, issue]),\n warningCount: report.warningCount + 1,\n });\n}\n\n/**\n * The import report with what the builder's policies changed while the graph was built: one\n * W_EDGES_MERGED warning when `duplicateEdges` merged parallel edges (whatever told them apart, a\n * relation or a label, is lost) and one W_SELF_LOOPS_DROPPED warning when `selfLoops: \"drop\"`\n * removed self-loops, so nothing the caller's options removed goes unreported.\n * @param report - the import's report\n * @param freeze - the freeze report\n * @returns the report, with the warnings added\n */\nfunction withFreezeWarnings(report: ImportReport, freeze: FreezeReport): ImportReport {\n const added: ImportIssue[] = [];\n const warn = (category: IssueCategory, code: string, message: string): void => {\n added.push(Object.freeze({ category, severity: \"warning\" as const, code, message, line: null, element: null }));\n };\n if (freeze.mergedEdges > 0) {\n warn(\n \"merged\",\n EDGES_MERGED_CODE,\n `${freeze.mergedEdges} parallel edge${plural(freeze.mergedEdges)} ${agree(freeze.mergedEdges, \"was\", \"were\")} merged into one edge per pair by the duplicateEdges policy; whatever told them apart (a relation, a label) is lost`,\n );\n }\n if (freeze.droppedSelfLoops > 0) {\n warn(\n \"validation-error\",\n SELF_LOOPS_DROPPED_CODE,\n `${freeze.droppedSelfLoops} self-loop${plural(freeze.droppedSelfLoops)} ${agree(freeze.droppedSelfLoops, \"was\", \"were\")} removed by selfLoops: \"drop\"`,\n );\n }\n if (added.length === 0) {\n return report;\n }\n return Object.freeze({\n ...report,\n issues: Object.freeze([...report.issues, ...added]),\n warningCount: report.warningCount + added.length,\n });\n}\n\n/**\n * The ImportError of a freeze the builder refused (a `duplicateEdges: \"error\"` or `selfLoops:\n * \"error\"` policy meeting a duplicate edge or a self-loop the file holds): the builder's code\n * recorded as an error issue on the import's report, so the caller gets the report and the file's\n * defect rather than a bare GraphFormatError.\n * @param err - what freezeWithReport() threw\n * @param report - the import's report\n * @returns the error to throw (anything that is not a GraphFormatError, unchanged)\n */\nfunction freezeFailure(err: unknown, report: ImportReport): unknown {\n if (!(err instanceof GraphFormatError) || err instanceof ImportError) {\n return err;\n }\n const issue = Object.freeze({\n category: \"validation-error\" as const,\n severity: \"error\" as const,\n code: err.code,\n message: err.message,\n line: null,\n element: null,\n });\n const failed: ImportReport = Object.freeze({\n ...report,\n issues: Object.freeze([...report.issues, issue]),\n errorCount: report.errorCount + 1,\n });\n return new ImportError(`the graph cannot be frozen: ${err.message}`, failed, { code: err.code, ...err.details });\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 canceled 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>, signal)\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?.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?.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 (with the signal's\n * reason) when closed early or when the signal fires during a read, and releases the reader when\n * the stream ends or errors.\n * @param stream - the stream\n * @param signal - the cancellation signal, or null\n * @returns the iterator\n */\nfunction readerIterator(stream: ReadableStream<Uint8Array>, signal: AbortSignal | null): AsyncIterator<Uint8Array> {\n const reader = lockReader(stream);\n let done = false;\n return {\n async next(): Promise<IteratorResult<Uint8Array>> {\n if (done) {\n return { done: true, value: undefined };\n }\n let result: ReadableStreamReadResult<Uint8Array>;\n try {\n result = await abortable(reader.read(), signal);\n } catch (err) {\n done = true;\n await reader.cancel(signal?.reason).catch(() => undefined);\n reader.releaseLock();\n throw err;\n }\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(signal?.reason).catch(() => undefined);\n reader.releaseLock();\n }\n return { done: true, value: undefined };\n },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AAAA,MACX;AACA,aAAO,EAAE,MAAM,MAAM,OAAO,OAAA;AAAA,IAChC;AAAA,EAAA;AAER;"}
|
|
1
|
+
{"version":3,"file":"graph-io.js","sources":["../src/common/line-format.ts","../src/common/compare.ts","../src/common/cell-budget.ts","../src/registry.ts"],"sourcesContent":["/**\n * defineLineFormat(): an importer for a text format with one node or one edge per line, built from\n * one function that reads a line. Everything else an importer must do (options, decoding, the\n * report and its counts, ids, direction, weights, attribute types, cancelling) is done here.\n */\n\nimport { GraphFormatError, type GraphSink, INVALID_INDEX } from \"@graphty/graph-format\";\n\nimport { type CommonImportOptions, type GraphImporter, type ImportInput, type ImportReport } from \"../types.js\";\nimport { BAD_LINE_CODE } from \"./codes.js\";\nimport { DirectionResolver } from \"./direction.js\";\nimport { IdCoercer } from \"./ids.js\";\nimport { LineReader, throwIfAborted } from \"./input.js\";\nimport { reportSinkOptions, reportUnusedOptions, resolveImportOptions } from \"./options.js\";\nimport { ImportReportBuilder, isAbortError, messageOf } from \"./report.js\";\nimport { TextCellWriter } from \"./text.js\";\nimport { parseWeightText } from \"./weights.js\";\n\n/**\n * Attribute values for a node or an edge added by defineLineFormat()'s `parseLine`.\n * @category Writing a format\n */\nexport type LineAttributes = Readonly<Record<string, string | number | boolean | null | undefined>>;\n\n/**\n * What `parseLine` adds a line's node or edge with.\n * @category Writing a format\n */\nexport interface LineGraph {\n /**\n * Add a node, or give a node that already exists more attributes. A `label` attribute is the\n * node's label, which `snapshot.nodes.byRole(\"label\")` finds; any other attribute's type (text,\n * integer, number, boolean) is worked out from its values, as for a CSV column.\n * @param id - the node id as written in the file\n * @param attributes - attribute values, such as `{ label: \"Alice\" }`\n */\n node(id: string, attributes?: LineAttributes): void;\n /**\n * Add an edge. A node it names that does not exist yet is added. The attribute that `weightFrom`\n * names (`weight` unless the caller passes another name) becomes the edge weight.\n * @param source - the source node id as written in the file\n * @param target - the target node id as written in the file\n * @param attributes - attribute values, such as `{ weight: \"2.5\" }`\n */\n edge(source: string, target: string, attributes?: LineAttributes): void;\n}\n\n/**\n * A text format with one node or one edge per line, for defineLineFormat().\n * @category Writing a format\n */\nexport interface LineFormat {\n /** The format name, which callers pass as `format`. */\n readonly format: string;\n /** The file extensions, with the dot (`[\".tgf\"]`); format detection matches them. */\n readonly extensions: readonly string[];\n /** MIME types the format is served as; none when left out. */\n readonly mimeTypes?: readonly string[] | undefined;\n /** Whether a file is directed when the caller passes no `defaultDirected`; false when left out. */\n readonly directed?: boolean | undefined;\n /** Lines that start with this text are skipped; `\"#\"` when left out, null to skip none. Blank lines are always skipped. */\n readonly comment?: string | null | undefined;\n /**\n * How sure you are that the first bytes of a file are this format, from 0 to 1. A file is\n * recognized by its content only when this returns 0.5 or more; without it, detection goes by\n * the file extension.\n */\n readonly sniff?: ((head: Uint8Array) => number) | undefined;\n /**\n * Read one line. `fields` is the line split on whitespace. Call `graph.node()` or `graph.edge()`\n * for what the line holds, and throw an Error to skip a line you cannot read: its message is\n * recorded as an `E_BAD_LINE` error with the line number.\n */\n readonly parseLine: (fields: readonly string[], graph: LineGraph, line: string) => void;\n}\n\n/** The common options a line format reads; a caller's other ones are reported as W_OPTION_IGNORED. */\nconst USED = new Set<keyof CommonImportOptions>([\"ids\", \"defaultDirected\", \"weightFrom\", \"addMissingNodes\"]);\n\n/**\n * Make an importer for a text format with one node or one edge per line. You write `parseLine`,\n * which reads one line; the importer handles every input graph-io takes, the options every importer\n * takes, the import report and its counts, cancelling and progress. Register the result with\n * `registry.registerImporter()`.\n * @example\n * ```ts\n * // \"a b\" is an edge, \"a\" alone is a node\n * const edgeList = defineLineFormat({\n * format: \"edges\",\n * extensions: [\".edges\"],\n * parseLine(fields, graph) {\n * if (fields.length === 1) {\n * graph.node(fields[0]);\n * } else if (fields.length === 2) {\n * graph.edge(fields[0], fields[1]);\n * } else {\n * throw new Error(\"expected one or two node ids\");\n * }\n * },\n * });\n * registry.registerImporter(edgeList);\n * ```\n * @param definition - the format: its name, extensions and `parseLine`\n * @returns the importer\n * @category Writing a format\n */\nexport function defineLineFormat(definition: LineFormat): GraphImporter {\n const { format, extensions, mimeTypes = [], directed = false, comment = \"#\", sniff, parseLine } = definition;\n const importer: GraphImporter = {\n format,\n extensions,\n mimeTypes,\n options: [],\n import: async (input: ImportInput, sink: GraphSink, options?: CommonImportOptions): Promise<ImportReport> => {\n const opts = resolveImportOptions(options, {\n ids: \"canonical\",\n defaultDirected: directed,\n weightFrom: \"weight\",\n });\n const report = new ImportReportBuilder(format, opts.errorLimit);\n reportSinkOptions(sink, options, report);\n reportUnusedOptions(options, report, USED);\n const ids = new IdCoercer(opts.ids);\n const edges = new DirectionResolver(sink, report, opts.onMixedDirection);\n const kind = opts.defaultDirected ? \"directed\" : \"undirected\";\n edges.setHeader(opts.defaultDirected);\n const attributes = new AttributeWriter(sink, report, opts.weightFrom);\n const write = (domain: \"node\" | \"edge\", row: number, values: LineAttributes | undefined): void => {\n attributes.write(domain, row, values);\n };\n const addNode = (id: string): number => {\n const nodeId = ids.text(id);\n if (sink.indexOf(nodeId) === INVALID_INDEX) {\n report.counts.nodes++;\n }\n return sink.addNode(nodeId);\n };\n let line = 0;\n const graph: LineGraph = {\n node: (id, attributes) => {\n write(\"node\", addNode(id), attributes);\n },\n edge: (source, target, attributes) => {\n const raw = opts.weightFrom === null ? undefined : attributes?.[opts.weightFrom];\n const weight = raw === null || raw === undefined ? undefined : parseWeightText(String(raw), report);\n const [s, t] = [ids.text(source), ids.text(target)];\n const added = new Set([s, t].filter((id) => sink.indexOf(id) === INVALID_INDEX)).size;\n const edge = edges.addEdge(s, t, kind, weight, { line });\n report.counts.nodes += added;\n report.counts.edges++;\n write(\"edge\", edge, attributes);\n },\n };\n const lines = new LineReader(input, report, opts);\n for await (const text of lines) {\n ({ line } = lines);\n if (line % 64 === 0) {\n throwIfAborted(opts.signal);\n }\n const trimmed = text.trim();\n if (trimmed === \"\" || (comment !== null && trimmed.startsWith(comment))) {\n continue;\n }\n try {\n parseLine(trimmed.split(/\\s+/), graph, text);\n } catch (err) {\n recordLineError(report, err, line);\n }\n }\n throwIfAborted(opts.signal);\n return report.finish();\n },\n };\n return Object.freeze(sniff === undefined ? importer : { ...importer, sniff });\n}\n\n/**\n * Record what a line's parser threw: a GraphFormatError with its own code, any other error as\n * BAD_LINE_CODE. A cancellation is rethrown.\n * @param report - the report\n * @param err - what the parser threw\n * @param line - the line number\n */\nfunction recordLineError(report: ImportReportBuilder, err: unknown, line: number): void {\n if (isAbortError(err)) {\n throw err;\n }\n if (err instanceof GraphFormatError) {\n report.recordError(err, { line });\n } else {\n report.error(\"parse-error\", BAD_LINE_CODE, err instanceof Error ? err.message : messageOf(err), { line });\n }\n}\n\n/** Writes the attributes a line format's parser gives a node or an edge into columns. */\nclass AttributeWriter {\n private readonly writers = { node: new Map<string, TextCellWriter>(), edge: new Map<string, TextCellWriter>() };\n\n /**\n * Create a writer.\n * @param sink - the sink\n * @param report - the report\n * @param weightFrom - the edge attribute read as the weight (not written as a column), or null\n */\n constructor(\n private readonly sink: GraphSink,\n private readonly report: ImportReportBuilder,\n private readonly weightFrom: string | null,\n ) {}\n\n /**\n * Write one element's attributes; null and undefined values are left unset.\n * @param domain - node or edge\n * @param row - the element's index\n * @param attributes - the attributes, or undefined\n */\n write(domain: \"node\" | \"edge\", row: number, attributes: LineAttributes | undefined): void {\n for (const [name, value] of Object.entries(attributes ?? {})) {\n if (value === null || value === undefined || (domain === \"edge\" && name === this.weightFrom)) {\n continue;\n }\n if (name === \"label\") {\n this.writeLabel(domain, row, String(value));\n continue;\n }\n let writer = this.writers[domain].get(name);\n if (writer === undefined) {\n writer = new TextCellWriter(name, domain, this.sink, this.report);\n this.writers[domain].set(name, writer);\n }\n writer.write(row, String(value));\n }\n }\n\n /**\n * Write a label: text, whatever it looks like, in the column that byRole(\"label\") finds.\n * @param domain - node or edge\n * @param row - the element's index\n * @param text - the label\n */\n private writeLabel(domain: \"node\" | \"edge\", row: number, text: string): void {\n const decl = { name: \"label\", dtype: \"string\", role: \"label\" } as const;\n if (domain === \"node\") {\n this.sink.setNodeValue(this.sink.declareNodeColumn(decl), row, text);\n } else {\n this.sink.setEdgeValue(this.sink.declareEdgeColumn(decl), row, text);\n }\n }\n}\n","/**\n * Compare two snapshots node by node, edge by edge and value by value, for testing a format plugin:\n * read a file, save it, read the saved file back, and compare. Every difference should be one that\n * the save's checkExport() notes announced.\n */\n\nimport { type Column, type GraphSnapshot } from \"@graphty/graph-format\";\n\n/**\n * One difference between two snapshots.\n * @category Plugin helpers\n */\nexport interface SnapshotDiff {\n /** Where: \"directed\", \"ids[3]\", \"nodes.label[4]\", \"edges.weight[0]\", \"extensions.temporal:node:price.rowCount\"... */\n readonly path: string;\n /** The value in the expected snapshot. */\n readonly expected: unknown;\n /** The value in the actual snapshot. */\n readonly actual: unknown;\n /** A one-line description. */\n readonly message: string;\n}\n\n/**\n * What compareSnapshots() compares.\n * @category Plugin helpers\n */\nexport interface CompareOptions {\n /** Column names to skip in every table (format-owned helpers an exporter adds, for instance). */\n readonly ignoreColumns?: readonly string[] | undefined;\n /** Column roles to skip in every table. */\n readonly ignoreRoles?: readonly string[] | undefined;\n /** Whether the actual snapshot may hold columns the expected one lacks (default true). */\n readonly allowExtraColumns?: boolean | undefined;\n /** Whether dtypes must match (default true); false compares values only. */\n readonly dtypes?: boolean | undefined;\n /** Whether roles must match (default true). */\n readonly roles?: boolean | undefined;\n /** Whether origin.type must match (default false). */\n readonly originType?: boolean | undefined;\n /** Absolute tolerance for numeric cell and weight comparisons (default 0: Object.is). */\n readonly tolerance?: number | undefined;\n /** Whether the explicit / defaulted status of weights must match (default true). */\n readonly weightExplicitness?: boolean | undefined;\n /** Whether extension tables are compared (default true). */\n readonly extensions?: boolean | undefined;\n /** Stop after this many differences (default 50). */\n readonly limit?: number | undefined;\n}\n\n/**\n * Compare two snapshots: the direction, the node ids, the edges, the weights and every attribute\n * value. Use it to test a format plugin: read a file, save it in your format, read the saved file\n * back, and compare the two graphs. Each difference has a `path` (\"ids[3]\", \"nodes.label[4]\",\n * \"edges.weight[0]\") and a one-line `message`; every one should match a note that `checkExport()`\n * returned for the save.\n * @example\n * ```ts\n * const notes = checkExport(original, \"pairs\");\n * const readBack = (await importGraph(await exportGraphToString(original, \"pairs\"), { format: \"pairs\" })).snapshot;\n * console.log(describeDiffs(compareSnapshots(original, readBack)));\n * ```\n * @param expected - the graph you saved\n * @param actual - the graph read back from the saved file\n * @param options - what to compare\n * @returns the differences, empty when the graphs are the same\n * @category Plugin helpers\n */\nexport function compareSnapshots(\n expected: GraphSnapshot,\n actual: GraphSnapshot,\n options: CompareOptions = {},\n): SnapshotDiff[] {\n const diffs: SnapshotDiff[] = [];\n const limit = options.limit ?? 50;\n const tolerance = options.tolerance ?? 0;\n const ctx: CompareContext = {\n options,\n diff: (path, e, a, message) => {\n diffs.push({\n path,\n expected: e,\n actual: a,\n message: message ?? `${path}: expected ${show(e)}, got ${show(a)}`,\n });\n if (diffs.length >= limit) {\n throw new LimitReached();\n }\n },\n same: (e, a) => valuesEqual(e, a, tolerance),\n };\n try {\n compareGraphs(expected, actual, ctx);\n } catch (err) {\n if (!(err instanceof LimitReached)) {\n throw err;\n }\n }\n return diffs;\n}\n\n/** Thrown by the recorder once the limit of differences is reached, to end the walk. */\nclass LimitReached extends Error {}\n\n/** What every comparison step shares: the options, the recorder and the value comparator. */\ninterface CompareContext {\n readonly options: CompareOptions;\n /** Records a difference (with a default message); throws LimitReached at the limit. */\n readonly diff: (path: string, e: unknown, a: unknown, message?: string) => void;\n /** Value equality under the tolerance. */\n readonly same: (e: unknown, a: unknown) => boolean;\n}\n\n/** A table shape both AttributeTable and extension tables satisfy. */\ninterface TableLike extends Iterable<Column> {\n readonly rowCount: number;\n names(): readonly string[];\n get(name: string): Column | null;\n}\n\n/**\n * Compare two snapshots step by step: the counts, the ids, the topology, the weights, the tables.\n * @param expected - the reference\n * @param actual - the snapshot under test\n * @param ctx - the comparison context\n */\nfunction compareGraphs(expected: GraphSnapshot, actual: GraphSnapshot, ctx: CompareContext): void {\n const { diff } = ctx;\n if (expected.directed !== actual.directed) {\n diff(\"directed\", expected.directed, actual.directed);\n }\n if (expected.nodeCount !== actual.nodeCount) {\n diff(\"nodeCount\", expected.nodeCount, actual.nodeCount);\n }\n if (expected.edgeCount !== actual.edgeCount) {\n diff(\"edgeCount\", expected.edgeCount, actual.edgeCount);\n }\n compareIds(expected, actual, diff);\n if (expected.nodeCount !== actual.nodeCount || expected.edgeCount !== actual.edgeCount) {\n return;\n }\n compareTopology(expected, actual, diff);\n compareWeights(expected, actual, ctx);\n compareTables(\"nodes\", expected.nodes, actual.nodes, ctx);\n compareTables(\"edges\", expected.edges, actual.edges, ctx);\n compareTables(\"graph\", expected.graph, actual.graph, ctx);\n if (ctx.options.extensions !== false) {\n compareExtensions(expected, actual, ctx);\n }\n}\n\n/**\n * Compare the node ids in index order.\n * @param expected - the reference\n * @param actual - the snapshot under test\n * @param diff - the recorder\n */\nfunction compareIds(expected: GraphSnapshot, actual: GraphSnapshot, diff: CompareContext[\"diff\"]): void {\n const expectedIds = expected.ids.toArray();\n const actualIds = actual.ids.toArray();\n const n = Math.min(expectedIds.length, actualIds.length);\n for (let i = 0; i < n; i++) {\n if (!Object.is(expectedIds[i], actualIds[i])) {\n diff(`ids[${i}]`, expectedIds[i], actualIds[i]);\n }\n }\n}\n\n/**\n * Compare the topology: the CSR arrays (identical when node order and edge order survived), then the\n * orientation of every logical edge.\n * @param expected - the reference\n * @param actual - the snapshot under test, with as many nodes and edges\n * @param diff - the recorder\n */\nfunction compareTopology(expected: GraphSnapshot, actual: GraphSnapshot, diff: CompareContext[\"diff\"]): void {\n if (!typedEqual(expected.rowPtr, actual.rowPtr)) {\n diff(\"rowPtr\", expected.rowPtr, actual.rowPtr, \"rowPtr differs\");\n }\n if (!typedEqual(expected.colIdx, actual.colIdx)) {\n diff(\"colIdx\", expected.colIdx, actual.colIdx, \"colIdx differs\");\n }\n const el = expected.edgeList();\n const al = actual.edgeList();\n for (let e = 0; e < expected.edgeCount; e++) {\n if (el.src[e] !== al.src[e] || el.dst[e] !== al.dst[e]) {\n diff(`edge[${e}]`, `${el.src[e]}->${el.dst[e]}`, `${al.src[e]}->${al.dst[e]}`);\n }\n }\n}\n\n/**\n * Compare the weights of two snapshots: the exact weight column when both have one, the 32-bit\n * weights otherwise.\n * @param expected - the reference\n * @param actual - the snapshot under test\n * @param ctx - the comparison context\n */\nfunction compareWeights(expected: GraphSnapshot, actual: GraphSnapshot, ctx: CompareContext): void {\n if (expected.flags.weighted !== actual.flags.weighted) {\n ctx.diff(\"flags.weighted\", expected.flags.weighted, actual.flags.weighted);\n return;\n }\n if (!expected.flags.weighted) {\n return;\n }\n const eShadow = expected.edges.byRole(\"weight\");\n const aShadow = actual.edges.byRole(\"weight\");\n if (eShadow !== null && aShadow !== null) {\n compareExactWeights(expected.edgeCount, eShadow, aShadow, ctx);\n return;\n }\n if (ctx.options.weightExplicitness !== false && (eShadow === null) !== (aShadow === null)) {\n ctx.diff(\n \"weightColumn\",\n eShadow !== null,\n aShadow !== null,\n \"one snapshot has a role-weight column, the other does not\",\n );\n }\n const ew = expected.edgeList().weights;\n const aw = actual.edgeList().weights;\n for (let e = 0; e < expected.edgeCount; e++) {\n const ev = ew === null ? 1 : ew[e];\n const av = aw === null ? 1 : aw[e];\n if (!ctx.same(ev, av)) {\n ctx.diff(`weight[${e}]`, ev, av);\n }\n }\n}\n\n/**\n * Compare the exact weight columns of two snapshots: which edges have an explicit weight, and its value.\n * @param edgeCount - the number of edges\n * @param expected - the reference's weight column\n * @param actual - the weight column under test\n * @param ctx - the comparison context\n */\nfunction compareExactWeights(edgeCount: number, expected: Column, actual: Column, ctx: CompareContext): void {\n for (let e = 0; e < edgeCount; e++) {\n const eSet = expected.isSet(e);\n const aSet = actual.isSet(e);\n if (ctx.options.weightExplicitness !== false && eSet !== aSet) {\n ctx.diff(`weightExplicit[${e}]`, eSet, aSet);\n } else if (eSet && aSet && !ctx.same(expected.value(e), actual.value(e))) {\n ctx.diff(`weight[${e}]`, expected.value(e), actual.value(e));\n }\n }\n}\n\n/**\n * Compare the extension tables: which exist, their row counts and their columns.\n * @param expected - the reference\n * @param actual - the snapshot under test\n * @param ctx - the comparison context\n */\nfunction compareExtensions(expected: GraphSnapshot, actual: GraphSnapshot, ctx: CompareContext): void {\n for (const [name, table] of expected.extensions) {\n const other = actual.extensions.get(name);\n if (other === undefined) {\n ctx.diff(`extensions.${name}`, \"present\", \"absent\");\n } else if (table.rowCount === other.rowCount) {\n compareTables(`extensions.${name}`, table, other, ctx);\n } else {\n ctx.diff(`extensions.${name}.rowCount`, table.rowCount, other.rowCount);\n }\n }\n if (ctx.options.allowExtraColumns === false) {\n for (const name of actual.extensions.keys()) {\n if (!expected.extensions.has(name)) {\n ctx.diff(`extensions.${name}`, \"absent\", \"present\");\n }\n }\n }\n}\n\n/**\n * Compare the columns of one table.\n * @param label - the table name for paths\n * @param expected - the reference table\n * @param actual - the table under test\n * @param ctx - the comparison context\n */\nfunction compareTables(label: string, expected: TableLike, actual: TableLike, ctx: CompareContext): void {\n const ignoreNames = new Set(ctx.options.ignoreColumns ?? []);\n const ignoreRoles = new Set(ctx.options.ignoreRoles ?? []);\n // the role-weight shadow column is compared by the weights step, not as a declared column\n const skip = (column: Column): boolean => {\n const { name, role } = column.meta;\n return (\n ignoreNames.has(name) ||\n (role !== null && (ignoreRoles.has(role) || (label === \"edges\" && role === \"weight\")))\n );\n };\n for (const column of expected) {\n if (skip(column)) {\n continue;\n }\n const path = `${label}.${column.meta.name}`;\n const other = actual.get(column.meta.name);\n if (other === null) {\n ctx.diff(path, \"present\", \"absent\", `${path}: column missing after round trip`);\n } else {\n compareColumn(path, column, other, ctx);\n }\n }\n if (ctx.options.allowExtraColumns === false) {\n for (const column of actual) {\n if (!skip(column) && expected.get(column.meta.name) === null) {\n const path = `${label}.${column.meta.name}`;\n ctx.diff(path, \"absent\", \"present\", `${path}: extra column after round trip`);\n }\n }\n }\n}\n\n/**\n * Compare one column: its declaration, then every cell.\n * @param path - the column's path for messages\n * @param column - the reference column\n * @param other - the column under test\n * @param ctx - the comparison context\n */\nfunction compareColumn(path: string, column: Column, other: Column, ctx: CompareContext): void {\n compareDeclaration(path, column, other, ctx);\n if (column.length !== other.length) {\n ctx.diff(`${path}.length`, column.length, other.length);\n return;\n }\n for (let r = 0; r < column.length; r++) {\n const eSet = column.isSet(r);\n const aSet = other.isSet(r);\n if (eSet !== aSet) {\n ctx.diff(`${path}[${r}]`, eSet ? column.value(r) : undefined, aSet ? other.value(r) : undefined);\n } else if (eSet) {\n const ev = cellValue(column, r);\n const av = cellValue(other, r);\n if (!ctx.same(ev, av)) {\n ctx.diff(`${path}[${r}]`, ev, av);\n }\n }\n }\n}\n\n/**\n * Compare what two columns declare: dtype, item dtype, components, role and origin type, as the\n * options ask.\n * @param path - the column's path for messages\n * @param column - the reference column\n * @param other - the column under test\n * @param ctx - the comparison context\n */\nfunction compareDeclaration(path: string, column: Column, other: Column, ctx: CompareContext): void {\n const { options, diff } = ctx;\n const e = column.meta;\n const a = other.meta;\n if (options.dtypes !== false) {\n for (const key of [\"dtype\", \"itemDtype\", \"components\"] as const) {\n if (e[key] !== a[key]) {\n diff(`${path}.${key}`, e[key], a[key]);\n }\n }\n }\n if (options.roles !== false && e.role !== a.role) {\n diff(`${path}.role`, e.role, a.role);\n }\n const eType = e.origin?.type ?? null;\n const aType = a.origin?.type ?? null;\n if (options.originType === true && eType !== aType) {\n diff(`${path}.origin.type`, eType, aType);\n }\n}\n\n/**\n * The comparable value of a set cell: list rows through sliceOf, json rows through values, the\n * typed accessor otherwise (a components > 1 subarray becomes a plain array).\n * @param column - the column\n * @param row - the row\n * @returns the value\n */\nfunction cellValue(column: Column, row: number): unknown {\n switch (column.dtype) {\n case \"list\":\n return [...column.sliceOf(row)];\n case \"json\":\n return column.values[row];\n default: {\n const value = column.value(row);\n return ArrayBuffer.isView(value) ? Array.from(value as ArrayLike<number>) : value;\n }\n }\n}\n\n/**\n * Deep equality with a numeric tolerance (for the tests).\n * @param e - expected\n * @param a - actual\n * @param tolerance - absolute tolerance for numbers\n * @returns true when equal\n */\nexport function valuesEqual(e: unknown, a: unknown, tolerance: number): boolean {\n if (typeof e === \"number\" && typeof a === \"number\") {\n if (Object.is(e, a)) {\n return true;\n }\n return Number.isFinite(e) && Number.isFinite(a) && Math.abs(e - a) <= tolerance;\n }\n if (Array.isArray(e) || ArrayBuffer.isView(e)) {\n const ea = Array.from(e as ArrayLike<unknown>);\n if (!(Array.isArray(a) || ArrayBuffer.isView(a))) {\n return false;\n }\n const aa = Array.from(a as ArrayLike<unknown>);\n return ea.length === aa.length && ea.every((v, i) => valuesEqual(v, aa[i], tolerance));\n }\n if (typeof e === \"object\" && e !== null && typeof a === \"object\" && a !== null) {\n const eo = e as Record<string, unknown>;\n const ao = a as Record<string, unknown>;\n const keys = Object.keys(eo);\n if (keys.length !== Object.keys(ao).length) {\n return false;\n }\n return keys.every((k) => Object.hasOwn(ao, k) && valuesEqual(eo[k], ao[k], tolerance));\n }\n return Object.is(e, a);\n}\n\n/**\n * Element-wise equality of two typed arrays.\n * @param a - one array\n * @param b - the other\n * @returns true when same length and contents\n */\nfunction typedEqual(a: ArrayLike<number>, b: ArrayLike<number>): boolean {\n if (a.length !== b.length) {\n return false;\n }\n for (let i = 0; i < a.length; i++) {\n if (a[i] !== b[i]) {\n return false;\n }\n }\n return true;\n}\n\n/**\n * A short text of a value for messages.\n * @param v - the value\n * @returns JSON when possible, else String()\n */\nfunction show(v: unknown): string {\n if (ArrayBuffer.isView(v)) {\n const items = Array.from(v as unknown as ArrayLike<number>);\n return `[${items.slice(0, 8).join(\", \")}${items.length > 8 ? \", ...\" : \"\"}]`;\n }\n try {\n const text = JSON.stringify(v);\n return text ?? String(v);\n } catch {\n return String(v);\n }\n}\n\n/**\n * The differences compareSnapshots() found, one per line, for printing.\n * @param diffs - the differences\n * @returns one line per difference, \"no differences\" when empty\n * @category Plugin helpers\n */\nexport function describeDiffs(diffs: readonly SnapshotDiff[]): string {\n return diffs.length === 0 ? \"no differences\" : diffs.map((d) => ` - ${d.message}`).join(\"\\n\");\n}\n","/**\n * A memory guard for the builder importGraph() fills. graph-format stores every attribute as a dense\n * column, one slot per node (or edge) whether or not that element has a value, so a file whose nodes\n * each carry a differently named attribute holds n values but allocates n x n slots: a few hundred\n * kilobytes of input can need gigabytes. The guard counts the slots that hold no value and stops the\n * import once they pass a limit. A dense file has almost no empty slots, so it is never stopped\n * however large it is.\n */\n\nimport {\n type ColumnDecl,\n type ColumnHandle,\n GraphBuilder,\n type GraphBuilderOptions,\n GraphFormatError,\n type NodeId,\n} from \"@graphty/graph-format\";\n\nimport { describe } from \"./options.js\";\nimport { plural } from \"./plural.js\";\nimport { ImportReportBuilder } from \"./report.js\";\n\n/**\n * Import stopped for allocating too many empty attribute slots.\n * @category Issue and loss codes\n */\nexport const TOO_MANY_EMPTY_CELLS_CODE = \"E_TOO_MANY_EMPTY_CELLS\";\n\n/** The default limit: 2^24 empty slots, about 130 MB of f64 columns. */\nconst DEFAULT_MAX_EMPTY_CELLS = 2 ** 24;\n\n/**\n * Resolve the maxEmptyCells option.\n * @param value - the caller's value\n * @returns a non-negative integer or Infinity\n * @throws GraphFormatError E_UNSUPPORTED for anything else\n * @category Plugin helpers\n */\nexport function maxEmptyCellsOption(value: unknown): number {\n if (value === undefined) {\n return DEFAULT_MAX_EMPTY_CELLS;\n }\n if (typeof value === \"number\" && value >= 0 && (Number.isInteger(value) || value === Infinity)) {\n return value;\n }\n throw new GraphFormatError(\n \"E_UNSUPPORTED\",\n `option maxEmptyCells: ${describe(value)} is not a non-negative integer or Infinity`,\n { option: \"maxEmptyCells\", found: value },\n );\n}\n\n/**\n * A GraphBuilder that throws an ImportError once its attribute columns hold too many empty slots.\n * @category Plugin helpers\n */\nexport class CellBudgetBuilder extends GraphBuilder {\n private readonly nodeColumns = new Set<number>();\n private readonly edgeColumns = new Set<number>();\n private values = 0;\n\n /**\n * Create a builder with a limit.\n * @param options - the builder options\n * @param format - the format being read, for the error's report\n * @param maxEmptyCells - the most empty slots allowed\n */\n constructor(\n options: GraphBuilderOptions,\n private readonly format: string,\n private readonly maxEmptyCells: number,\n ) {\n super(options);\n }\n\n /**\n * Add a node, then check the limit (its row adds a slot to every node column).\n * @param id - the node id\n * @returns the node index\n */\n override addNode(id: NodeId): number {\n const index = super.addNode(id);\n this.checkBudget();\n return index;\n }\n\n /**\n * Add an edge, then check the limit (its row adds a slot to every edge column).\n * @param source - source id\n * @param target - target id\n * @param weight - the weight\n * @returns the edge index\n */\n override addEdge(source: NodeId, target: NodeId, weight?: number): number {\n const edge = super.addEdge(source, target, weight);\n this.checkBudget();\n return edge;\n }\n\n /**\n * Declare a node column, then check the limit.\n * @param decl - the declaration\n * @returns the column handle\n */\n override declareNodeColumn(decl: ColumnDecl): ColumnHandle {\n const handle = super.declareNodeColumn(decl);\n this.nodeColumns.add(handle);\n this.checkBudget();\n return handle;\n }\n\n /**\n * Declare an edge column, then check the limit.\n * @param decl - the declaration\n * @returns the column handle\n */\n override declareEdgeColumn(decl: ColumnDecl): ColumnHandle {\n const handle = super.declareEdgeColumn(decl);\n this.edgeColumns.add(handle);\n this.checkBudget();\n return handle;\n }\n\n /**\n * Set a node cell (a new name declares a column), then check the limit.\n * @param column - the handle or name\n * @param index - the node index\n * @param value - the value\n */\n override setNodeValue(column: ColumnHandle | string, index: number, value: unknown): void {\n super.setNodeValue(column, index, value);\n this.nodeColumns.add(typeof column === \"string\" ? this.nodeColumn(column) : column);\n this.count(value);\n }\n\n /**\n * Set an edge cell (a new name declares a column), then check the limit.\n * @param column - the handle or name\n * @param edge - the edge index\n * @param value - the value\n */\n override setEdgeValue(column: ColumnHandle | string, edge: number, value: unknown): void {\n super.setEdgeValue(column, edge, value);\n this.edgeColumns.add(typeof column === \"string\" ? this.edgeColumn(column) : column);\n this.count(value);\n }\n\n /**\n * Count a written value and check the budget.\n * @param value - the value; null and undefined unset a slot and do not count\n */\n private count(value: unknown): void {\n if (value !== null && value !== undefined) {\n this.values++;\n }\n this.checkBudget();\n }\n\n /**\n * Throw when the columns' slots minus the values written pass the limit.\n * @throws ImportError E_TOO_MANY_EMPTY_CELLS\n */\n private checkBudget(): void {\n const slots = this.nodeColumns.size * this.nodeBound + this.edgeColumns.size * this.edgeBound;\n const empty = slots - this.values;\n if (empty > this.maxEmptyCells) {\n new ImportReportBuilder(this.format, Infinity).fail(\n TOO_MANY_EMPTY_CELLS_CODE,\n `the attributes are too sparse: ${this.nodeColumns.size} node and ${this.edgeColumns.size} edge ` +\n `attribute columns over ${this.nodeBound} node${plural(this.nodeBound)} and ${this.edgeBound} edge${plural(this.edgeBound)} would ` +\n `allocate more than ${this.maxEmptyCells} slots that hold no value; pass a larger ` +\n `maxEmptyCells (or Infinity) to read the file anyway`,\n undefined,\n { emptyCells: empty, maxEmptyCells: this.maxEmptyCells },\n );\n }\n }\n}\n","/**\n * The importer / exporter registry: the 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 { CellBudgetBuilder, maxEmptyCellsOption } from \"./common/cell-budget.js\";\nimport {\n EDGES_MERGED_CODE,\n EMPTY_INPUT_CODE,\n FETCH_CODE,\n OPTION_IGNORED_CODE,\n SELF_LOOPS_DROPPED_CODE,\n STYLES_NOT_IMPORTED_CODE,\n UNKNOWN_OPTION_CODE,\n WEIGHT_NOT_FOUND_CODE,\n} from \"./common/codes.js\";\nimport { abortable, foreignKind, lockReader, normalizeInput, throwIfAborted } from \"./common/input.js\";\nimport { chooseGraph, resolveImportOptions } from \"./common/options.js\";\nimport { agree, plural } from \"./common/plural.js\";\nimport { ImportReportBuilder, isAbortError, messageOf } from \"./common/report.js\";\nimport { collectBytes } from \"./common/writer.js\";\nimport { csvExporter, csvImporter } from \"./formats/csv/index.js\";\nimport { cxExporter, cxImporter } from \"./formats/cx/index.js\";\nimport { cx2Exporter, cx2Importer } from \"./formats/cx2/index.js\";\nimport { cysExporter, cysImporter } from \"./formats/cys/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 { oboExporter, oboImporter } from \"./formats/obo/index.js\";\nimport { pajekExporter, pajekImporter } from \"./formats/pajek/index.js\";\nimport { xgmmlExporter, xgmmlImporter } from \"./formats/xgmml/index.js\";\nimport { type FormatName, rankFormats, SNIFF_HEAD_BYTES, type SniffHints, type SniffResult } from \"./sniff.js\";\nimport { extractStyles, type StyleImportOptions } from \"./styles/io/generic.js\";\nimport { isKeptGraphtyProperty, prepareStyleExport } from \"./styles/io/writer.js\";\nimport type { ExtractedStyles } from \"./styles/types.js\";\nimport {\n type CommonExportOptions,\n type CommonImportOptions,\n type ExportCapabilities,\n type GraphChoiceOptions,\n type GraphExporter,\n type GraphImporter,\n type GraphListing,\n ImportError,\n type ImportInput,\n type ImportIssue,\n type ImportReport,\n type IssueCategory,\n type LossNote,\n} from \"./types.js\";\n\n/**\n * The input is in no format graph-io can read (or none of the formats you registered, for your own FormatRegistry).\n * Pass `format` when you know what the file is.\n * @category Issue and loss codes\n */\nexport const UNKNOWN_FORMAT_CODE = \"E_UNKNOWN_FORMAT\";\n\n/**\n * Registered importer whose sniff() threw while the format was being chosen; that importer was treated as not\n * recognizing the input (a defect in that importer).\n * @category Issue and loss codes\n */\nexport const SNIFF_FAILED_CODE = \"W_SNIFF_FAILED\";\n\n/**\n * The `builder` option of importGraph(): settings for building the graph that the common import\n * options do not cover. `weighted`: \"auto\" (the default) gives the graph weights when any edge has\n * one, true always does (every weight 1 when the file has none), false never does. `expectedNodes`\n * and `expectedEdges`: how many nodes and edges to make room for up front, which saves time on a\n * large file whose size you know.\n * @category Loading\n */\nexport type BuilderSeed = Omit<\n GraphBuilderOptions,\n \"directed\" | \"addMissingNodes\" | \"duplicateEdges\" | \"selfLoops\" | \"weightDtype\"\n>;\n\n/**\n * The options of importGraph(), importAllGraphs(), listGraphs() and loadFromFile(): the common\n * import options, the format and the hints used to detect it, the graph to read from a file that\n * holds several, and any format-specific option (`delimiter`, `dialect`, ...), which reaches the\n * importer unchanged.\n * @category Loading\n */\nexport interface ImportGraphOptions extends CommonImportOptions, GraphChoiceOptions {\n /**\n * The format to read the input as (\"graphml\", \"csv\", ...; `listFormats()` names them all), or\n * \"auto\" to work it out from `filename`, `mimeType` and the first bytes of the input. Name it to\n * be strict: detection reads a file graph-io cannot place as the closest format it recognizes.\n * @defaultValue \"auto\"\n */\n readonly format?: FormatName | \"auto\" | undefined;\n /**\n * The file name or full path the input came from; only its extension is used, as a format hint.\n * loadFromUrl() takes it from the URL and loadFromFile() from a File's name when you do not pass\n * it.\n */\n readonly filename?: string | null | undefined;\n /**\n * The MIME type the input was served as, a format hint. loadFromUrl() takes it from the\n * response's Content-Type and loadFromFile() from the Blob's `type` when you do not pass it.\n */\n readonly mimeType?: string | null | undefined;\n /**\n * Settings for building the graph: `weighted` (\"auto\", true or false: whether the graph gets\n * weights), `expectedNodes` and `expectedEdges` (room to make up front for a large file). Most\n * programs never set it.\n */\n readonly builder?: BuilderSeed | undefined;\n /**\n * Settings for the last step of an import, which turns what was read into the snapshot:\n * `label` (a name for debugging, read back as `snapshot.label`), `prepare` (views of the graph\n * to compute up front, such as `[\"reverse\"]`), `checksum` (record checksums, which\n * `snapshot.validate({ checksum: true })` compares later to catch changed memory) and `profile` (record how long each step took, in `result.freeze.timings`). Most\n * programs never set it.\n */\n readonly freeze?: FreezeOptions | undefined;\n /**\n * The most attribute slots that hold no value the import may allocate before it stops with an\n * ImportError whose `issue.code` is E_TOO_MANY_EMPTY_CELLS. Every attribute is a column with one slot per node (or edge), so a file\n * whose nodes each have a differently named attribute would otherwise need nodes x attributes\n * memory. Infinity turns the check off. Files whose elements mostly share their attributes are\n * never stopped.\n * @defaultValue 16777216\n */\n readonly maxEmptyCells?: number | undefined;\n /**\n * Read the file's styles too: `true`, or `{ toolDefaults: false }` to leave out the defaults of the program\n * that wrote the file. The styles are in `result.styles`; the graph, the report and every export are the same\n * either way.\n * @defaultValue false\n */\n readonly styles?: boolean | StyleImportOptions | undefined;\n /** Format-specific options, passed to the importer as they are. */\n readonly [formatOption: string]: unknown;\n}\n\n/**\n * What importGraph(), loadFromUrl() and loadFromFile() return.\n * @category Loading\n */\nexport interface ImportGraphResult {\n /** The format the input was read as (\"graphml\", ...). */\n readonly format: string;\n /**\n * How the format was detected (the candidate's `confidence` and what matched), or null when you\n * named the format. Most callers can ignore it. For the JSON dialect that was read, call\n * `jsonShapeOf(snapshot)` from `@graphty/graph-io/json`.\n */\n readonly sniff: SniffResult | null;\n /**\n * The graph. `snapshot.nodeCount`, `snapshot.edgeCount`, attribute tables and so on come from\n * the `@graphty/graph-format` package.\n */\n readonly snapshot: GraphSnapshot;\n /**\n * What happened during the import. `errorCount` counts skipped elements (see `errorLimit`,\n * default 100); `warningCount` counts elements that were kept but changed; `issues` lists both;\n * `counts.skippedNodes` / `counts.skippedEdges` say how much is missing from `snapshot`.\n */\n readonly report: ImportReport;\n /**\n * What the last step of the import did to the graph: `mergedEdges` (parallel edges merged by\n * `duplicateEdges`), `droppedSelfLoops` (removed by `selfLoops: \"drop\"`), and `timings` when you\n * passed `freeze: { profile: true }`. Both counts are also reported as warnings, so most callers\n * can ignore it. It is not enumerable, so `console.log(result)` and `{ ...result }` leave it out.\n */\n readonly freeze: FreezeReport;\n /**\n * The file's styles, when you passed the `styles` option: the rules that reproduce how the program that wrote\n * the file draws each node and edge, read by the importer that read the file. Null when the file has none.\n * Absent without the option.\n */\n readonly styles?: ExtractedStyles | null;\n}\n\n/**\n * Options for loadFromUrl(): everything importGraph() accepts, plus the fetch request settings.\n * @example\n * ```ts\n * await loadFromUrl(\"/api/graph.csv\", { request: { headers: { Authorization: token } }, delimiter: \";\" });\n * ```\n * @category Loading\n */\nexport interface LoadFromUrlOptions extends ImportGraphOptions {\n /**\n * Passed to fetch() as its second argument: headers, credentials, mode and so on. If you set\n * `signal` in the import options and not here, the same signal also cancels the download.\n */\n readonly request?: RequestInit | undefined;\n}\n\n/**\n * Options for downloadGraph(): the export options plus the name of the saved file.\n * @example\n * ```ts\n * await downloadGraph(snapshot, \"graphml\", { filename: \"network.graphml\" });\n * ```\n * @category Saving\n */\nexport interface DownloadGraphOptions extends ExportGraphOptions {\n /**\n * The file name the browser saves as. The default is \"graph\" plus the first entry of the\n * format's `extensions` (\"graph.graphml\"), or \"graph.<format>\" when it lists none.\n * @defaultValue \"graph\" plus the format's extension\n */\n readonly filename?: string | undefined;\n}\n\n/**\n * One format the registry can read, write or both.\n * @category Formats and detection\n */\nexport interface FormatInfo {\n /** The name you pass as `format`: \"graphml\", \"gexf\", \"csv\", \"pajek\", ... */\n readonly format: string;\n /**\n * File extensions with the leading dot, most common first (\".graphml\", \".net\"). Empty only for a\n * custom format that declares none.\n */\n readonly extensions: readonly string[];\n /** MIME types, most specific first. Empty when the format declares none. */\n readonly mimeTypes: readonly string[];\n /** Whether loadFromUrl(), loadFromFile() and importGraph() can read it. */\n readonly canImport: boolean;\n /** Whether the export functions can write it. */\n readonly canExport: boolean;\n /**\n * What the format can store exactly, or null when it cannot be written. The fields are\n * mixedDirection, multiEdges, selfLoops, edgeIds, idCharset, dtypes, components, lists, json,\n * defaults, options, hierarchy, temporal, graphAttributes, positions and viz (each documented on\n * ExportCapabilities). checkExport() tells you where a particular graph goes beyond this.\n */\n readonly capabilities: ExportCapabilities | null;\n}\n\n/**\n * The options of exportGraph(): the common export options plus any format-specific option, passed through.\n * @category Saving\n */\nexport interface ExportGraphOptions extends CommonExportOptions {\n /**\n * Write these styles too (`result.styles` of an import, or styles built for this graph): each element's look in\n * the format's own style slots and, where the format can keep them, the rules, so importing the file back\n * rebuilds them. What the format cannot hold is a W_STYLE_ note of checkExport(). Styles read from or built for a\n * different graph fail with E_STYLES_MISMATCH before anything is written.\n */\n readonly styles?: ExtractedStyles | null | undefined;\n /** Format-specific options, passed to the exporter as they are. */\n readonly [formatOption: string]: unknown;\n}\n\n/**\n * The options the load and save functions take themselves: the common import and export options and the functions'\n * own. With the formats' own `options` lists, these are the names a load or a save knows.\n */\nconst FUNCTION_OPTIONS: ReadonlySet<string> = new Set([\n \"addMissingNodes\",\n \"builder\",\n \"defaultDirected\",\n \"duplicateEdges\",\n \"encoding\",\n \"errorLimit\",\n \"filename\",\n \"format\",\n \"freeze\",\n \"graphIndex\",\n \"graphName\",\n \"hyperedges\",\n \"ids\",\n \"long\",\n \"maxEmptyCells\",\n \"mimeType\",\n \"nodeIdFrom\",\n \"onMixedDirection\",\n \"onProgress\",\n \"request\",\n \"restoreMangledIds\",\n \"sanitizeIds\",\n \"selfLoops\",\n \"signal\",\n \"styles\",\n \"weightDtype\",\n \"weightFrom\",\n]);\n\n/** The keys of ImportGraphOptions that belong to the registry, never to an importer. */\nconst REGISTRY_KEYS: ReadonlySet<string> = new Set([\n \"format\",\n \"filename\",\n \"mimeType\",\n \"builder\",\n \"freeze\",\n \"maxEmptyCells\",\n \"styles\",\n]);\n\n/**\n * A registry of importers and exporters by format name. Registration order is the tie-break\n * order of sniffing; the default registry lists the built-in formats in the\n * order of GRAPH_FORMATS.\n * @category Formats and detection\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: FormatName): 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: FormatName): 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: FormatName): 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: FormatName): 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 * Every format that could be the input, best first, from the same hints as sniff(): use it to\n * offer the user a choice when the best guess is not certain.\n * @param hints - `{ filename, mimeType, head }`, any of them\n * @returns the candidates, best first; empty when no format claims the input\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 a graph from a string, bytes or a stream. The format is the one you name in `format`,\n * else it is detected from `filename`, `mimeType` and the first bytes of the content. From an\n * input that holds several graphs, it reads the one `graphIndex` or `graphName` chooses, else\n * the first, with a W_MULTIPLE_GRAPHS warning; 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 graph (`snapshot`), the format it was read as, and the import report\n */\n async importGraph(\n input: ImportInput,\n options: ImportGraphOptions | CommonImportOptions = {},\n ): Promise<ImportGraphResult> {\n const opts = options as ImportGraphOptions;\n const picked = await this.choose(input, opts);\n const unknown = this.unknownOptions(opts).map((name): ImportIssue =>\n Object.freeze({\n category: \"unsupported\",\n severity: \"warning\",\n code: UNKNOWN_OPTION_CODE,\n message: unknownOptionText(name),\n line: null,\n element: name,\n }),\n );\n const chosen = unknown.length === 0 ? picked : { ...picked, warnings: [...picked.warnings, ...unknown] };\n const { importer } = chosen;\n if (\n (opts.graphIndex !== undefined || opts.graphName !== undefined) &&\n importer.importAll !== undefined &&\n importer.listGraphs === undefined\n ) {\n // an importer that reads several graphs but does not choose among them itself (DOT, GML,\n // Pajek): read them all and return the chosen one, so the choice is never ignored\n const all = await this.readAll(chosen, opts);\n const names = all.map((r) => r.snapshot.meta.name);\n return all[chooseGraph(names, opts, new ImportReportBuilder(importer.format, 0))];\n }\n let builder: GraphBuilder;\n let report: ImportReport;\n try {\n builder = seededBuilder(opts, chosen.importer.format);\n report = await chosen.importer.import(chosen.source, builder, importerOptions(opts));\n } catch (err) {\n await chosen.peeked?.close();\n throw chosen.sniff === null ? notReadableAs(err, importer.format, opts.filename) : err;\n }\n return result(chosen, builder, report, opts);\n }\n\n /**\n * Fetch a graph file from a URL and load it; see the top-level loadFromUrl() for the full\n * description.\n * @param url - an absolute URL, or in a browser one relative to the page\n * @param options - import options, plus `request` for fetch\n * @returns the graph, the format it was read as, and the import report\n */\n async loadFromUrl(\n url: string | URL,\n options: LoadFromUrlOptions | CommonImportOptions = {},\n ): Promise<ImportGraphResult> {\n const opts = options as LoadFromUrlOptions;\n const { request, ...rest } = opts;\n const signal = request?.signal ?? rest.signal ?? null;\n const method = request?.method ?? \"GET\";\n const where = `${method} ${String(url)}`;\n let response: Response;\n try {\n response = await fetch(url, { signal: rest.signal, ...request });\n } catch (err) {\n if (signal?.aborted === true || isAbortError(err)) {\n throw err;\n }\n return fetchFailed(rest, url, `${where} failed: ${fetchErrorText(url, err)}`, null, err);\n }\n if (!response.ok) {\n await response.body?.cancel().catch(() => undefined);\n const status = `${String(response.status)} ${response.statusText}`.trim();\n return fetchFailed(rest, url, `${where} failed: ${status}`, response.status, null);\n }\n return this.importGraph(response.body ?? new Uint8Array(0), {\n ...rest,\n filename: rest.filename ?? urlFilename(url),\n mimeType: rest.mimeType ?? response.headers.get(\"content-type\"),\n });\n }\n\n /**\n * Load a graph from a File or Blob; see the top-level loadFromFile() for the full description.\n * @param file - the File or Blob to read\n * @param options - the same options as importGraph()\n * @returns the graph, the format it was read as, and the import report\n */\n loadFromFile(file: Blob, options: ImportGraphOptions | CommonImportOptions = {}): Promise<ImportGraphResult> {\n const opts = options as ImportGraphOptions;\n const { name } = file as { name?: unknown };\n return this.importGraph(file.stream(), {\n ...opts,\n filename: opts.filename ?? (typeof name === \"string\" ? name : null),\n mimeType: opts.mimeType ?? (file.type === \"\" ? null : file.type),\n });\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 as its own snapshot. A format that holds\n * one graph per file gives one result. Options and detection 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(\n input: ImportInput,\n options: ImportGraphOptions | CommonImportOptions = {},\n ): Promise<ImportGraphResult[]> {\n const opts = options as ImportGraphOptions;\n return this.readAll(await this.choose(input, opts), opts);\n }\n\n /**\n * Read every graph of an input with the chosen importer.\n * @param chosen - the importer and the input to hand it\n * @param options - the importGraph options\n * @returns one result per graph, in document order\n */\n private async readAll(chosen: ChosenImporter, options: ImportGraphOptions): Promise<ImportGraphResult[]> {\n const { importer } = chosen;\n const builders: GraphBuilder[] = [];\n let reports: ImportReport[];\n try {\n if (importer.importAll === undefined) {\n builders.push(seededBuilder(options, importer.format));\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, importer.format);\n builders.push(builder);\n return builder;\n },\n importerOptions(options),\n );\n }\n } catch (err) {\n await chosen.peeked?.close();\n throw inGraph(\n chosen.sniff === null ? notReadableAs(err, importer.format, options.filename) : err,\n builders.length - 1,\n );\n }\n return reports.map((report, i) => {\n try {\n return result(chosen, builders[i], report, options);\n } catch (err) {\n throw inGraph(err, i);\n }\n });\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(\n input: ImportInput,\n options: ImportGraphOptions | CommonImportOptions = {},\n ): Promise<readonly GraphListing[] | null> {\n const opts = options as ImportGraphOptions;\n const chosen = await this.choose(input, opts);\n try {\n return chosen.importer.listGraphs === undefined\n ? null\n : await chosen.importer.listGraphs(chosen.source, importerOptions(opts));\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 rawInput - the input as the caller passed it\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(rawInput: ImportInput, options: ImportGraphOptions): Promise<ChosenImporter> {\n const input = normalizeInput(rawInput);\n const requested = options.format ?? \"auto\";\n if (requested !== \"auto\") {\n return { importer: this.importer(requested), sniff: null, source: input, peeked: null, warnings: [] };\n }\n // the options are checked before the input is touched, so a bad option never leaves a\n // peeked stream locked; the importer resolves them again with its own defaults\n const common = resolveImportOptions(options, { ids: \"keep\", defaultDirected: true, weightFrom: null });\n maxEmptyCellsOption(options.maxEmptyCells);\n const peeked = await peekHead(input, SNIFF_HEAD_BYTES, common.signal);\n // the head is sniffed as the importer will read it: in the caller's encoding when given\n const head =\n common.encoding !== null && peeked.head instanceof Uint8Array\n ? new TextDecoder(common.encoding).decode(peeked.head, { stream: true })\n : peeked.head;\n let sniff: SniffResult | null;\n const failures = new ImportReportBuilder(\"unknown\", 0);\n const warnings: ImportIssue[] = [];\n try {\n const hints = { filename: options.filename, mimeType: options.mimeType, head };\n const ranked = rankFormats(hints, this.importerMap.values(), (format, err) => {\n warnings.push(\n failures.warning(\n \"unsupported\",\n SNIFF_FAILED_CODE,\n `the ${format} importer's sniff() threw (${messageOf(err)}); it was treated as not recognizing the input`,\n { element: format },\n ),\n );\n });\n sniff = ranked.length > 0 ? ranked[0] : null;\n } catch (err) {\n await peeked.close();\n throw err;\n }\n // a known non-graph file is refused whatever its name says, unless an importer claims its\n // content (a Cytoscape session is a zip); an HTML page always (the XML sniffers would\n // otherwise claim it by its markup)\n const foreign = foreignKind(peeked.head);\n const claimed = sniff !== null && sniff.content > 0 && !(foreign?.startsWith(\"an HTML\") ?? false);\n if (sniff === null || (foreign !== null && !claimed)) {\n await peeked.close();\n return this.refuseUndetected(failures, head, foreign, options);\n }\n return { importer: this.importer(sniff.format), sniff, source: peeked.input, peeked, warnings };\n }\n\n /**\n * Refuse an input no importer recognizes: empty, or not in a known graph format.\n * @param failures - the report the error is recorded in\n * @param head - the head, as sniffed\n * @param foreign - what known non-graph file the head is, or null\n * @param options - the importGraph options\n * @returns never: always throws\n */\n private refuseUndetected(\n failures: ImportReportBuilder,\n head: Uint8Array | string | null,\n foreign: string | null,\n options: ImportGraphOptions,\n ): never {\n const text = typeof head === \"string\" ? head : new TextDecoder().decode(head ?? new Uint8Array(0));\n if (text.trim() === \"\" && text.length < SNIFF_HEAD_BYTES) {\n // nothing to detect: say the input is empty, as a named format would\n return failures.fail(\n EMPTY_INPUT_CODE,\n text === \"\" ? \"the input is empty\" : \"the input holds only whitespace\",\n );\n }\n const what = foreign === null ? \"\" : `: it is ${foreign}`;\n return failures.fail(\n UNKNOWN_FORMAT_CODE,\n `the input is not in a graph format graph-io recognizes${describeHints(options)}${what}; if you know its format, pass it as the format option`,\n undefined,\n { formats: this.formats() },\n );\n }\n\n /**\n * Write a snapshot in a format, 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 */\n exportGraph(\n snapshot: GraphSnapshot,\n format: FormatName,\n options?: ExportGraphOptions | CommonExportOptions,\n ): AsyncIterable<Uint8Array> {\n const styled = this.styled(snapshot, format, options);\n if (styled === null) {\n return this.exporter(format).export(snapshot, options);\n }\n if (styled.refusal !== null) {\n return refuse(styled.refusal);\n }\n return styled.exporter.export(styled.snapshot, styled.options);\n }\n\n /**\n * An export with styles worked out, or null when no styles were given (the export is then exactly as before).\n * @param snapshot - the graph\n * @param format - the format name\n * @param options - the caller's options\n * @returns the exporter, the snapshot and options to hand it, the style losses and any refusal\n */\n private styled(\n snapshot: GraphSnapshot,\n format: FormatName,\n options: ExportGraphOptions | CommonExportOptions | undefined,\n ): StyledExport | null {\n const styles = (options as ExportGraphOptions | undefined)?.styles;\n if (styles === undefined || styles === null) {\n return null;\n }\n const exporter = this.exporter(format);\n const { styles: _given, ...rest } = options as ExportGraphOptions;\n const prepared = prepareStyleExport(snapshot, exporter, styles, rest);\n return {\n exporter,\n snapshot: prepared.snapshot,\n options: prepared.input === null ? rest : { ...rest, styles: prepared.input },\n plain: rest,\n notes: prepared.notes,\n refusal: prepared.refusal,\n };\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(\n snapshot: GraphSnapshot,\n format: FormatName,\n options?: ExportGraphOptions | CommonExportOptions,\n ): Promise<string> {\n const styled = this.styled(snapshot, format, options);\n if (styled === null) {\n return this.exporter(format).exportToString(snapshot, options);\n }\n if (styled.refusal !== null) {\n throw refusalError(styled.refusal);\n }\n return styled.exporter.exportToString(styled.snapshot, styled.options);\n }\n\n /**\n * Write a snapshot in a format as one buffer of UTF-8 bytes; see the top-level\n * exportGraphToBytes().\n * @param snapshot - the graph to write\n * @param format - a format name where `canExport` is true\n * @param options - sanitizeIds, onMixedDirection and the format's own options\n * @returns the encoded file\n */\n exportGraphToBytes(\n snapshot: GraphSnapshot,\n format: FormatName,\n options?: ExportGraphOptions | CommonExportOptions,\n ): Promise<Uint8Array> {\n return collectBytes(this.exportGraph(snapshot, format, options));\n }\n\n /**\n * Write a snapshot in a format as a Blob typed with the format's first MIME type; see the\n * top-level exportGraphToBlob().\n * @param snapshot - the graph to write\n * @param format - a format name where `canExport` is true\n * @param options - sanitizeIds, onMixedDirection and the format's own options\n * @returns the file as a Blob\n */\n async exportGraphToBlob(\n snapshot: GraphSnapshot,\n format: FormatName,\n options?: ExportGraphOptions | CommonExportOptions,\n ): Promise<Blob> {\n const parts: Uint8Array[] = [];\n for await (const chunk of this.exportGraph(snapshot, format, options)) {\n parts.push(chunk);\n }\n const info = this.listFormats().find((f) => f.format === format);\n return new Blob(parts as BlobPart[], { type: info?.mimeTypes[0] ?? \"application/octet-stream\" });\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(\n snapshot: GraphSnapshot,\n format: FormatName,\n options?: ExportGraphOptions | CommonExportOptions,\n ): readonly LossNote[] {\n const styled = this.styled(snapshot, format, options);\n let notes: readonly LossNote[];\n if (styled === null) {\n notes = this.exporter(format).check(snapshot, options);\n } else if (styled.refusal === null) {\n // a property graph-io already reports as not written is reported once, whoever else notices\n const key = (n: LossNote): string =>\n `${n.code}\\u0000${n.style?.target ?? \"\"}\\u0000${n.style?.property ?? \"\"}`;\n const reported = new Set(styled.notes.filter((n) => n.style !== undefined).map(key));\n notes = [\n ...styled.exporter\n .check(styled.snapshot, styled.options)\n .filter(\n (n) =>\n n.style === undefined ||\n (!reported.has(key(n)) && !isKeptGraphtyProperty(n, styled.exporter)),\n ),\n ...styled.notes,\n ];\n } else {\n notes = [...styled.exporter.check(snapshot, styled.plain), styled.refusal];\n }\n const unknown = this.unknownOptions(options);\n if (unknown.length === 0) {\n return notes;\n }\n return Object.freeze([\n ...notes,\n ...unknown.map((name) =>\n Object.freeze({\n code: UNKNOWN_OPTION_CODE,\n message: unknownOptionText(name),\n column: null,\n count: null,\n }),\n ),\n ]);\n }\n\n /**\n * The option names no registered format and no load or save function takes (misspellings), or none while a\n * registered format does not list its options.\n * @param options - the caller's options\n * @returns the unknown names\n */\n private unknownOptions(options: object | null | undefined): string[] {\n if (options === null || options === undefined) {\n return [];\n }\n const known = new Set(FUNCTION_OPTIONS);\n for (const plugin of [...this.importerMap.values(), ...this.exporterMap.values()]) {\n if (plugin.options === undefined) {\n return [];\n }\n for (const name of plugin.options) {\n known.add(name);\n }\n }\n return Object.entries(options)\n .filter(([name, value]) => value !== undefined && !known.has(name))\n .map(([name]) => name);\n }\n\n /**\n * Browser only: write a graph in a format and have the browser save it as a file; see the\n * top-level downloadGraph(). Use this method on a registry from createRegistry() to download\n * without bundling every built-in format.\n * @param snapshot - the graph to write\n * @param format - a format name from listFormats() where `canExport` is true\n * @param options - the export options, plus `filename`\n * @returns resolves once the download has been handed to the browser\n */\n async downloadGraph(\n snapshot: GraphSnapshot,\n format: FormatName,\n options: DownloadGraphOptions | CommonExportOptions = {},\n ): Promise<void> {\n if (typeof document === \"undefined\") {\n throw new GraphFormatError(\n \"E_UNSUPPORTED\",\n \"downloadGraph() needs a browser document; use exportGraphToBytes() and write the bytes yourself\",\n );\n }\n const { filename, ...rest } = options as DownloadGraphOptions;\n const blob = await this.exportGraphToBlob(snapshot, format, rest);\n const extension = this.listFormats().find((f) => f.format === format)?.extensions[0] ?? `.${format}`;\n const href = URL.createObjectURL(blob);\n const anchor = document.createElement(\"a\");\n anchor.href = href;\n anchor.download = filename ?? `graph${extension}`;\n anchor.click();\n // Safari cancels the download when the URL is revoked in the same task\n setTimeout(() => {\n URL.revokeObjectURL(href);\n }, 0);\n }\n\n /**\n * Every format this registry can read or write, in registration order; see the top-level\n * listFormats().\n * @returns one entry per format\n */\n listFormats(): readonly FormatInfo[] {\n return this.formats().map((format) => {\n const importer = this.importerMap.get(format);\n const exporter = this.exporterMap.get(format);\n return Object.freeze({\n format,\n extensions: importer?.extensions ?? exporter?.extensions ?? [],\n mimeTypes: importer?.mimeTypes ?? exporter?.mimeTypes ?? [],\n canImport: importer !== undefined,\n canExport: exporter !== undefined,\n capabilities: capabilitiesOf(exporter),\n });\n });\n }\n}\n\n/**\n * A new registry holding every built-in importer and exporter, in the order of GRAPH_FORMATS.\n * @returns a new registry\n * @category Formats and detection\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(xgmmlImporter)\n .registerExporter(xgmmlExporter)\n .registerImporter(cx2Importer)\n .registerExporter(cx2Exporter)\n .registerImporter(cxImporter)\n .registerExporter(cxExporter)\n .registerImporter(oboImporter)\n .registerExporter(oboExporter)\n .registerImporter(cysImporter)\n .registerExporter(cysExporter);\n}\n\n/**\n * The default registry: every built-in format.\n * @category Formats and detection\n */\nexport const registry: FormatRegistry = /* @__PURE__ */ createRegistry();\n\n/**\n * Read a graph from a string, bytes or a stream. The format is the one you name in `format`, else\n * it is detected from `filename`, `mimeType` and the first bytes; an input that matches no format\n * fails with E_UNKNOWN_FORMAT. From a file that holds several graphs it reads the one `graphIndex`\n * or `graphName` chooses, else the first, with a W_MULTIPLE_GRAPHS warning. For a File or Blob use\n * loadFromFile(), for a URL loadFromUrl().\n * @param input - the whole text, the bytes (a Uint8Array or a Node Buffer), a ReadableStream of\n * bytes, or an async iterable of text or byte chunks (a Node read stream)\n * @param options - the format, format hints, the options every importer takes and the format's own\n * options\n * @returns the graph (`snapshot`), the format it was read as, and the import report\n * @throws ImportError when the input could not be read; `err.issue?.code` says why\n * @throws GraphFormatError with code E_UNSUPPORTED for a `format` no importer is registered for, or\n * an option value that is not allowed (`err.details.option` names it)\n * @throws the signal's reason when `signal` aborts\n * @category Loading\n */\nexport function importGraph(\n input: ImportInput,\n options?: ImportGraphOptions | CommonImportOptions,\n): Promise<ImportGraphResult> {\n return registry.importGraph(input, options);\n}\n\n/**\n * Read every graph of a file that can hold several (DOT, GML, a Pajek project, a JSON Graph Format\n * or OBO Graphs document, CX, XGMML, a Cytoscape session). A format that holds one graph per file\n * gives one result. Options and errors are the same as importGraph()'s.\n * @param input - the text, bytes or stream to read\n * @param options - the same options as importGraph()\n * @returns one result per graph, in file order\n * @category Loading\n */\nexport function importAllGraphs(\n input: ImportInput,\n options?: ImportGraphOptions | CommonImportOptions,\n): Promise<ImportGraphResult[]> {\n return registry.importAllGraphs(input, options);\n}\n\n/**\n * List the graphs of a file without reading them: each one's `index`, `name`, and node and edge\n * counts when the file states them. Pass the index or name to importGraph() as `graphIndex` or\n * `graphName`. The counts come from the file and can differ from what an import reads, for example\n * when the import adds edges the listing does not count. JSON, CX, XGMML and Cytoscape sessions can\n * list their graphs; for DOT, GML and Pajek it returns null, and importAllGraphs() is the way to see\n * them.\n * @param input - the text, bytes or stream to read\n * @param options - the same options as importGraph()\n * @returns one listing per graph, in file order; null when the format cannot list its graphs\n * @category Loading\n */\nexport function listGraphs(\n input: ImportInput,\n options?: ImportGraphOptions | CommonImportOptions,\n): Promise<readonly GraphListing[] | null> {\n return registry.listGraphs(input, options);\n}\n\n/**\n * Write a graph in a format as a stream of UTF-8 byte chunks, for a graph too large to hold as one\n * file in memory. In Node, pipe it to a file with `pipeline(exportGraph(...), createWriteStream(path))`.\n * Options and errors are the same as exportGraphToBytes()'s.\n * @param snapshot - the graph to write\n * @param format - a format name from listFormats() where `canExport` is true\n * @param options - sanitizeIds, onMixedDirection and the format's own options\n * @returns the file's bytes, chunk by chunk\n * @category Saving\n */\nexport function exportGraph(\n snapshot: GraphSnapshot,\n format: FormatName,\n options?: ExportGraphOptions | CommonExportOptions,\n): AsyncIterable<Uint8Array> {\n return registry.exportGraph(snapshot, format, options);\n}\n\n/**\n * Write a graph in a format and return the file as one string. A binary format (a Cytoscape\n * session) cannot be a string and fails with E_UNSUPPORTED; use exportGraphToBytes() for it. Options\n * and errors are the same as exportGraphToBytes()'s.\n * @param snapshot - the graph to write\n * @param format - a format name from listFormats() where `canExport` is true\n * @param options - sanitizeIds, onMixedDirection and the format's own options\n * @returns the whole file\n * @category Saving\n */\nexport async function exportGraphToString(\n snapshot: GraphSnapshot,\n format: FormatName,\n options?: ExportGraphOptions | CommonExportOptions,\n): Promise<string> {\n return registry.exportGraphToString(snapshot, format, options);\n}\n\n/**\n * What saving a graph in a format would lose, without writing anything. Pass the same options you\n * will pass to the save. Each note has a stable `code`: \"E_\" means the save would throw, \"W_\" means\n * the file is written but that part does not read back the same. An empty array means the file\n * reads back as the same graph. Runs synchronously.\n * @param snapshot - the graph to check\n * @param format - a format name from listFormats() where `canExport` is true\n * @param options - the options you will save with\n * @returns the loss notes, empty when the save is exact\n * @throws GraphFormatError with code E_UNSUPPORTED when no exporter is registered for `format`, or\n * when an option value is not allowed (`err.details.option` names it)\n * @category Saving\n */\nexport function checkExport(\n snapshot: GraphSnapshot,\n format: FormatName,\n options?: ExportGraphOptions | CommonExportOptions,\n): readonly LossNote[] {\n return registry.checkExport(snapshot, format, options);\n}\n\n/**\n * Fetch a graph file from a URL and load it. The file is streamed into the importer as it\n * downloads, so a large file is not held in memory twice. When you do not name a `format`, it is\n * worked out from the URL's file name, the response's Content-Type and the first bytes of the\n * file. Your own `filename` or `mimeType` option takes the place of the hint from the URL or the\n * response. Every other option goes to importGraph() unchanged, including format-specific ones\n * such as `delimiter` or `dialect`, and `graphIndex` / `graphName` for files that hold several\n * graphs. The result is the same as importGraph()'s. A successful load can still have skipped\n * elements; check `report.errorCount` and `report.warningCount`, or pass `errorLimit: 0` to make\n * the first error fatal. Works wherever fetch exists: browsers, Node 18 and later, Deno, Bun and\n * workers.\n * @param url - an absolute URL, or in a browser one relative to the page\n * @param options - import options, plus `request` for fetch\n * @returns the graph, the format it was read as, and the import report\n * @throws ImportError when the file could not be loaded; `err.issue?.code` is \"E_FETCH\" for a\n * network failure, a CORS refusal or a status outside 200-299 (`err.details.url`,\n * `err.details.status` -- null for a network failure -- and `err.details.cause`, fetch's own\n * error), \"E_UNKNOWN_FORMAT\" when no format recognizes the file (pass `format`), or the code of\n * the parse error\n * @throws GraphFormatError with code E_UNSUPPORTED when `format` names no registered importer\n * @throws the signal's reason when `signal` aborts\n * @example\n * ```ts\n * import { GraphFormatError, loadFromUrl } from \"@graphty/graph-io\";\n *\n * try {\n * const { snapshot, format } = await loadFromUrl(\"https://example.com/data/karate.gml\");\n * console.log(`${format}: ${snapshot.nodeCount} nodes, ${snapshot.edgeCount} edges`);\n * } catch (err) {\n * if (err instanceof GraphFormatError) {\n * console.error(err.message);\n * } else {\n * throw err;\n * }\n * }\n * ```\n * @category Loading\n */\nexport function loadFromUrl(\n url: string | URL,\n options?: LoadFromUrlOptions | CommonImportOptions,\n): Promise<ImportGraphResult> {\n return registry.loadFromUrl(url, options);\n}\n\n/**\n * Load a graph from a File or Blob: a file the user picked in an `<input type=\"file\">`, a file\n * dropped on the page, a Blob you built, or in Node a Blob from `fs.openAsBlob(path)`. The content\n * is streamed into the importer. A File's `name` and the Blob's `type` are used as format hints\n * unless you pass `filename` or `mimeType` yourself. Options, result and errors are the same as\n * loadFromUrl()'s, without E_FETCH.\n * @param file - the File or Blob to read\n * @param options - the same options as importGraph()\n * @returns the graph, the format it was read as, and the import report\n * @throws ImportError when the file could not be loaded (`err.issue?.code` E_UNKNOWN_FORMAT or a parse error)\n * @throws GraphFormatError with code E_UNSUPPORTED when `format` names no registered importer\n * @throws the signal's reason when `signal` aborts\n * @example\n * ```ts\n * input.addEventListener(\"change\", async () => {\n * const file = input.files?.[0];\n * if (file) {\n * const { snapshot, report } = await loadFromFile(file);\n * console.log(`${snapshot.nodeCount} nodes, ${report.errorCount} skipped`);\n * }\n * });\n * ```\n * @category Loading\n */\nexport function loadFromFile(\n file: Blob,\n options?: ImportGraphOptions | CommonImportOptions,\n): Promise<ImportGraphResult> {\n return registry.loadFromFile(file, options);\n}\n\n/**\n * Write a graph in a format and return the whole file as UTF-8 bytes, ready for fs.writeFile, a\n * fetch body or a zip entry. Prefer this over exportGraphToString() when the result goes to a file\n * or the network. To stream a very large graph, use exportGraph(). To find out beforehand what the\n * file will not keep, call checkExport() with the same format and the same options object: every\n * \"E_\" note it returns makes this call throw, and every \"W_\" note describes a loss this call\n * accepts. Most \"E_\" notes go away with `sanitizeIds: \"mangle\"` (rewrite ids the format cannot\n * hold) or `onMixedDirection: \"directed\"` / `\"undirected\"`. The format's own options (the CSV\n * `table` and `dialect`, the GEXF `version`, ...) go in the same object.\n * @param snapshot - the graph to write\n * @param format - a format name from listFormats() where `canExport` is true\n * @param options - sanitizeIds, onMixedDirection and the format's own options\n * @returns the encoded file\n * @throws GraphFormatError with code E_UNSUPPORTED when no exporter is registered for `format`\n * @throws GraphFormatError when the graph cannot be written in this format under these options\n * (checkExport() returns an \"E_\" note for the same call). The thrown code names the kind of\n * failure rather than the note: E_INVALID_ID for ids (the E_ID_CHARSET and E_ID_TEXT_COLLISION\n * notes), E_DIRECTED for direction (E_MIXED_DIRECTION), and E_COLUMN_TYPE or E_UNSUPPORTED for a\n * value the format cannot write; each note's entry on the codes page says which\n * @throws GraphFormatError with code E_UNSUPPORTED for an option value that is not allowed\n * (`err.details.option` names it)\n * @example\n * ```ts\n * import { writeFile } from \"node:fs/promises\";\n *\n * await writeFile(\"out.gexf\", await exportGraphToBytes(snapshot, \"gexf\"));\n * ```\n * @category Saving\n */\nexport function exportGraphToBytes(\n snapshot: GraphSnapshot,\n format: FormatName,\n options?: ExportGraphOptions | CommonExportOptions,\n): Promise<Uint8Array> {\n return registry.exportGraphToBytes(snapshot, format, options);\n}\n\n/**\n * Write a graph in a format and return it as a Blob, for uploading with fetch or FormData or for\n * offering as a download. The Blob's `type` is the first entry of the format's `mimeTypes` in\n * listFormats(), or application/octet-stream when the format lists none. The exporter's chunks\n * are kept as they are and never joined into one string. Options and errors are the same as\n * exportGraphToBytes().\n * @param snapshot - the graph to write\n * @param format - a format name from listFormats() where `canExport` is true\n * @param options - sanitizeIds, onMixedDirection and the format's own options\n * @returns the file as a Blob\n * @throws the same errors as exportGraphToBytes()\n * @example\n * ```ts\n * const body = new FormData();\n * body.append(\"file\", await exportGraphToBlob(snapshot, \"graphml\"), \"graph.graphml\");\n * await fetch(\"/api/graphs\", { method: \"POST\", body });\n * ```\n * @category Saving\n */\nexport function exportGraphToBlob(\n snapshot: GraphSnapshot,\n format: FormatName,\n options?: ExportGraphOptions | CommonExportOptions,\n): Promise<Blob> {\n return registry.exportGraphToBlob(snapshot, format, options);\n}\n\n/**\n * Browser only: write a graph in a format and have the browser save it as a file, the same as\n * clicking a download link. Call it from a click handler; awaiting other work first is fine. The\n * promise resolves once the file has been handed to the browser. There is no way to learn\n * whether the user then canceled the save. Calling it where there is no `document` (Node, a\n * worker) throws instead of silently doing nothing; importing it is safe everywhere. Formats you\n * registered with `registry.registerExporter()` can be downloaded too.\n * @param snapshot - the graph to write\n * @param format - a format name from listFormats() where `canExport` is true\n * @param options - the export options, plus `filename`\n * @returns resolves once the download has been handed to the browser\n * @throws GraphFormatError with code E_UNSUPPORTED when called without a DOM `document`\n * @throws the same errors as exportGraphToBytes()\n * @example\n * ```ts\n * saveButton.addEventListener(\"click\", () => {\n * void downloadGraph(snapshot, \"graphml\", { filename: \"network.graphml\" });\n * });\n * ```\n * @category Saving\n */\nexport async function downloadGraph(\n snapshot: GraphSnapshot,\n format: FormatName,\n options: DownloadGraphOptions | CommonExportOptions = {},\n): Promise<void> {\n return registry.downloadGraph(snapshot, format, options);\n}\n\n/**\n * Every format the default registry can read or write, including any you registered yourself:\n * the built-in formats in the order of GRAPH_FORMATS (the order format detection prefers them),\n * then yours in registration order. Use it to fill a \"Save as\" menu (the entries with\n * `canExport`), a file input's `accept` attribute (the `extensions` of the entries with\n * `canImport`), or to pick the output format from a file name.\n * @returns one entry per format\n * @example\n * ```ts\n * input.accept = listFormats().filter((f) => f.canImport).flatMap((f) => f.extensions).join(\",\");\n * const target = listFormats().find((f) => f.canExport && f.extensions.includes(extensionOf(path) ?? \"\"));\n * ```\n * @category Formats and detection\n */\nexport function listFormats(): readonly FormatInfo[] {\n return registry.listFormats();\n}\n\n/**\n * Detect a file's format without reading it, from what you know about it: a `filename` (only the\n * extension counts), a `mimeType`, and `head`, the file's first bytes or characters (up to\n * SNIFF_HEAD_BYTES; pass `bytes.subarray(0, SNIFF_HEAD_BYTES)`). It uses every format of the default\n * registry, including the ones you registered. For every candidate, best first, call\n * `registry.sniffAll(hints)`.\n * @param hints - `{ filename, mimeType, head }`, any of them\n * @returns the best candidate (`format`, `confidence` and what matched), or null when no format\n * claims the input\n * @example\n * ```ts\n * sniff({ filename: \"graph.xml\", head: \"<?xml version=\\\"1.0\\\"?><gexf\" })?.format; // \"gexf\"\n * ```\n * @category Formats and detection\n */\nexport function sniff(hints: SniffHints): SniffResult | null {\n return registry.sniff(hints);\n}\n\n/**\n * Abort a loadFromUrl() whose fetch failed with an E_FETCH ImportError.\n * @param options - the import options (for the format name on the report)\n * @param url - the URL\n * @param message - the message\n * @param status - the HTTP status, or null for a network failure\n * @param cause - fetch's own error, or null\n * @returns never; always throws\n */\nfunction fetchFailed(\n options: ImportGraphOptions,\n url: string | URL,\n message: string,\n status: number | null,\n cause: unknown,\n): never {\n const format = options.format === undefined || options.format === \"auto\" ? \"unknown\" : options.format;\n return new ImportReportBuilder(format, 0).fail(FETCH_CODE, message, undefined, { url: String(url), status, cause });\n}\n\n/**\n * The error for an input refused by the format the caller named before any element was read: the\n * parser's message (\"line 1: text outside the root element\") prefixed with the file and the format,\n * since the likely cause is a file of another kind, not a damaged one.\n * @param err - what the importer threw\n * @param format - the format named in `format`\n * @param filename - the file name hint, if any\n * @returns the error to throw\n */\nfunction notReadableAs(err: unknown, format: string, filename: string | null | undefined): unknown {\n if (\n !(err instanceof ImportError) ||\n err.issue?.category !== \"parse-error\" ||\n err.report.errorCount > 1 ||\n err.report.counts.nodes + err.report.counts.edges > 0\n ) {\n return err;\n }\n const what = filename === undefined || filename === null ? \"the input\" : JSON.stringify(filename);\n return new ImportError(`${what} could not be read as ${format}: ${err.message}`, err.report, err.details);\n}\n\n/**\n * Why fetch() rejected, in words that point at the fix: a relative URL with no page to resolve it\n * against (Node), a file: URL fetch() does not read, or a network error, which in a browser\n * includes a CORS refusal.\n * @param url - the URL as given\n * @param err - what fetch() threw\n * @returns the reason\n */\nfunction fetchErrorText(url: string | URL, err: unknown): string {\n let absolute: URL | null = null;\n try {\n absolute = new URL(url);\n } catch {\n // relative: resolvable only against a page's location\n }\n if (absolute === null && (globalThis as { location?: unknown }).location === undefined) {\n return \"a relative URL needs a web page to resolve against; outside a browser pass an absolute http(s) URL, or read a local file with loadFromFile() or importGraph()\";\n }\n if (absolute?.protocol === \"file:\") {\n return \"fetch() cannot read file: URLs here; read a local file with loadFromFile() or importGraph()\";\n }\n const cause = (err as { cause?: { message?: unknown } } | null)?.cause?.message;\n const detail = typeof cause === \"string\" && cause !== \"\" ? ` (${cause})` : \"\";\n return `the server could not be reached, or (in a browser) it does not allow this page to read the file (CORS)${detail}`;\n}\n\n/**\n * The last path segment of a URL, as a format hint.\n * @param url - the URL, absolute or relative\n * @returns the file name, or null when the path ends in \"/\"\n */\nfunction urlFilename(url: string | URL): string | null {\n const path = new URL(url, \"http://localhost/\").pathname;\n const name = path.slice(path.lastIndexOf(\"/\") + 1);\n return name === \"\" ? null : name;\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 /** W_SNIFF_FAILED warnings for the import report, one per importer whose sniff() threw. */\n readonly warnings: readonly ImportIssue[];\n}\n\n/**\n * A fresh builder seeded from the common options, `directed: true` as a placeholder the importer\n * overrides from the file, that stops the import when its attributes get too sparse.\n * @param options - the importGraph options\n * @param format - the format being read\n * @returns the builder\n */\nfunction seededBuilder(options: ImportGraphOptions, format: string): GraphBuilder {\n const maxEmptyCells = maxEmptyCellsOption(options.maxEmptyCells);\n try {\n return newBuilder(options, format, maxEmptyCells);\n } catch (err) {\n // the builder names a bad value by its field; report it as the option the caller passed\n if (err instanceof GraphFormatError && err.code === \"E_UNSUPPORTED\" && typeof err.details.field === \"string\") {\n const option = err.details.field;\n throw new GraphFormatError(\n \"E_UNSUPPORTED\",\n `option ${option}: ${JSON.stringify(err.details.found)} is not one of the values it takes`,\n { option, found: err.details.found },\n );\n }\n throw err;\n }\n}\n\n/**\n * The builder of seededBuilder(), before its option errors are reworded.\n * @param options - the importGraph options\n * @param format - the format being read\n * @param maxEmptyCells - the empty-cell budget\n * @returns the builder\n */\nfunction newBuilder(options: ImportGraphOptions, format: string, maxEmptyCells: number): GraphBuilder {\n return new CellBudgetBuilder(\n {\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 format,\n maxEmptyCells,\n );\n}\n\n/**\n * Name the graph an importAllGraphs() failure belongs to: the report is that graph's own, so the\n * message is prefixed with its index and `details.graphIndex` set, for every graph including the\n * first. Anything other than an ImportError raised while a graph was being read passes unchanged.\n * @param err - the error thrown while reading or freezing a graph\n * @param index - the index of that graph, -1 before the first graph began\n * @returns the error to throw\n */\nfunction inGraph(err: unknown, index: number): unknown {\n if (!(err instanceof ImportError) || index < 0) {\n return err;\n }\n return new ImportError(`graph ${index}: ${err.message}`, err.report, { ...err.details, graphIndex: index });\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 let frozen: ReturnType<GraphBuilder[\"freezeWithReport\"]>;\n try {\n frozen = builder.freezeWithReport(options.freeze);\n } catch (err) {\n throw freezeFailure(err, report);\n }\n const { warnings } = chosen;\n const wanted = options.styles;\n let styles: ExtractedStyles | null | undefined;\n if (wanted !== undefined && wanted !== false) {\n styles = extractStyles(chosen.importer, frozen.snapshot, report, {\n signal: options.signal,\n toolDefaults: typeof wanted === \"object\" ? wanted.toolDefaults : undefined,\n });\n }\n const read =\n styles !== undefined && chosen.importer.styles !== undefined ? withoutStylesNotImported(report) : report;\n const result = {\n format: chosen.importer.format,\n sniff: chosen.sniff,\n snapshot: frozen.snapshot,\n report: withFreezeWarnings(\n weightNotFound(\n warnings.length === 0\n ? read\n : Object.freeze({\n ...read,\n issues: Object.freeze([...warnings, ...read.issues]),\n warningCount: read.warningCount + warnings.length,\n }),\n frozen.snapshot,\n options.weightFrom,\n ),\n frozen.report,\n ),\n };\n if (styles !== undefined) {\n Object.assign(result, { styles });\n }\n // not enumerable: it holds one entry per edge, and console.log(result) should show the graph, not that\n Object.defineProperty(result, \"freeze\", { value: frozen.report, enumerable: false });\n return Object.freeze(result as ImportGraphResult);\n}\n\n/**\n * A report without its W_STYLES_NOT_IMPORTED warnings: the importer read the styles it would have named.\n * @param report - the importer's report\n * @returns the report, a copy only when it held such a warning\n */\nfunction withoutStylesNotImported(report: ImportReport): ImportReport {\n const issues = report.issues.filter((i) => i.code !== STYLES_NOT_IMPORTED_CODE);\n if (issues.length === report.issues.length) {\n return report;\n }\n return Object.freeze({\n ...report,\n issues: Object.freeze(issues),\n warningCount: report.warningCount - (report.issues.length - issues.length),\n });\n}\n\n/** An export with styles, worked out by FormatRegistry.styled(). */\ninterface StyledExport {\n /** The exporter. */\n readonly exporter: GraphExporter;\n /** The snapshot to hand it. */\n readonly snapshot: GraphSnapshot;\n /** The options to hand it: the caller's, with `styles` replaced by the exporter's input or left out. */\n readonly options: ExportGraphOptions;\n /** The caller's options without `styles`. */\n readonly plain: ExportGraphOptions;\n /** The style losses. */\n readonly notes: readonly LossNote[];\n /** E_STYLES_MISMATCH, or null. */\n readonly refusal: LossNote | null;\n}\n\n/**\n * The error an export refused for its styles throws.\n * @param note - the refusal note\n * @returns the error\n */\nfunction refusalError(note: LossNote): GraphFormatError {\n return new GraphFormatError(\"E_UNSUPPORTED\", note.message, { code: note.code });\n}\n\n/**\n * Chunks that fail on the first read, before any byte: an export refused for its styles.\n * @param note - the refusal note\n * @returns chunks whose first read rejects\n */\nfunction refuse(note: LossNote): AsyncIterable<Uint8Array> {\n return {\n [Symbol.asyncIterator]: () => ({ next: () => Promise.reject(refusalError(note)) }),\n };\n}\n\n/**\n * The capabilities listFormats() reports for an exporter: its table plus, when it writes styles, their capabilities.\n * @param exporter - the exporter, or undefined\n * @returns the capabilities, or null\n */\nfunction capabilitiesOf(exporter: GraphExporter | undefined): ExportCapabilities | null {\n if (exporter === undefined) {\n return null;\n }\n if (exporter.styles === undefined) {\n return exporter.capabilities;\n }\n return Object.freeze({ ...exporter.capabilities, styles: exporter.styles.capabilities });\n}\n\n/**\n * The message of a W_UNKNOWN_OPTION warning or note.\n * @param name - the option name\n * @returns the message\n */\nfunction unknownOptionText(name: string): string {\n return `option ${JSON.stringify(name)} is not an option of any format or of the load and save functions, so it has no effect; check its spelling`;\n}\n\n/**\n * The import report with one W_WEIGHT_NOT_FOUND warning when the caller's `weightFrom` named an attribute that gave\n * no edge a weight, so a name that misses (a shared options object read against GML's `value`) is not silent. A\n * format that does not read `weightFrom` already reported it as W_OPTION_IGNORED.\n * @param report - the import's report\n * @param snapshot - the graph read\n * @param weightFrom - the caller's option\n * @returns the report, with the warning added when it applies\n */\nfunction weightNotFound(report: ImportReport, snapshot: GraphSnapshot, weightFrom: unknown): ImportReport {\n if (\n typeof weightFrom !== \"string\" ||\n snapshot.edgeCount === 0 ||\n snapshot.edgeList().weights !== null ||\n report.issues.some((i) => i.code === OPTION_IGNORED_CODE && i.element === \"weightFrom\")\n ) {\n return report;\n }\n const issue: ImportIssue = Object.freeze({\n category: \"missing-value\",\n severity: \"warning\",\n code: WEIGHT_NOT_FOUND_CODE,\n message: `weightFrom: ${JSON.stringify(weightFrom)} names no attribute an edge has a value for, so the graph has no weights`,\n line: null,\n element: \"weightFrom\",\n });\n return Object.freeze({\n ...report,\n issues: Object.freeze([...report.issues, issue]),\n warningCount: report.warningCount + 1,\n });\n}\n\n/**\n * The import report with what the builder's policies changed while the graph was built: one\n * W_EDGES_MERGED warning when `duplicateEdges` merged parallel edges (whatever told them apart, a\n * relation or a label, is lost) and one W_SELF_LOOPS_DROPPED warning when `selfLoops: \"drop\"`\n * removed self-loops, so nothing the caller's options removed goes unreported.\n * @param report - the import's report\n * @param freeze - the freeze report\n * @returns the report, with the warnings added\n */\nfunction withFreezeWarnings(report: ImportReport, freeze: FreezeReport): ImportReport {\n const added: ImportIssue[] = [];\n const warn = (category: IssueCategory, code: string, message: string): void => {\n added.push(Object.freeze({ category, severity: \"warning\" as const, code, message, line: null, element: null }));\n };\n if (freeze.mergedEdges > 0) {\n warn(\n \"merged\",\n EDGES_MERGED_CODE,\n `${freeze.mergedEdges} parallel edge${plural(freeze.mergedEdges)} ${agree(freeze.mergedEdges, \"was\", \"were\")} merged into one edge per pair by the duplicateEdges policy; whatever told them apart (a relation, a label) is lost`,\n );\n }\n if (freeze.droppedSelfLoops > 0) {\n warn(\n \"validation-error\",\n SELF_LOOPS_DROPPED_CODE,\n `${freeze.droppedSelfLoops} self-loop${plural(freeze.droppedSelfLoops)} ${agree(freeze.droppedSelfLoops, \"was\", \"were\")} removed by selfLoops: \"drop\"`,\n );\n }\n if (added.length === 0) {\n return report;\n }\n return Object.freeze({\n ...report,\n issues: Object.freeze([...report.issues, ...added]),\n warningCount: report.warningCount + added.length,\n });\n}\n\n/**\n * The ImportError of a freeze the builder refused (a `duplicateEdges: \"error\"` or `selfLoops:\n * \"error\"` policy meeting a duplicate edge or a self-loop the file holds): the builder's code\n * recorded as an error issue on the import's report, so the caller gets the report and the file's\n * defect rather than a bare GraphFormatError.\n * @param err - what freezeWithReport() threw\n * @param report - the import's report\n * @returns the error to throw (anything that is not a GraphFormatError, unchanged)\n */\nfunction freezeFailure(err: unknown, report: ImportReport): unknown {\n if (!(err instanceof GraphFormatError) || err instanceof ImportError) {\n return err;\n }\n const issue = Object.freeze({\n category: \"validation-error\" as const,\n severity: \"error\" as const,\n code: err.code,\n message: err.message,\n line: null,\n element: null,\n });\n const failed: ImportReport = Object.freeze({\n ...report,\n issues: Object.freeze([...report.issues, issue]),\n errorCount: report.errorCount + 1,\n });\n return new ImportError(`the graph cannot be frozen: ${err.message}`, failed, { code: err.code, ...err.details });\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 canceled 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>, signal)\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?.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?.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 (with the signal's\n * reason) when closed early or when the signal fires during a read, and releases the reader when\n * the stream ends or errors.\n * @param stream - the stream\n * @param signal - the cancellation signal, or null\n * @returns the iterator\n */\nfunction readerIterator(stream: ReadableStream<Uint8Array>, signal: AbortSignal | null): AsyncIterator<Uint8Array> {\n const reader = lockReader(stream);\n let done = false;\n return {\n async next(): Promise<IteratorResult<Uint8Array>> {\n if (done) {\n return { done: true, value: undefined };\n }\n let result: ReadableStreamReadResult<Uint8Array>;\n try {\n result = await abortable(reader.read(), signal);\n } catch (err) {\n done = true;\n await reader.cancel(signal?.reason).catch(() => undefined);\n reader.releaseLock();\n throw err;\n }\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(signal?.reason).catch(() => undefined);\n reader.releaseLock();\n }\n return { done: true, value: undefined };\n },\n };\n}\n"],"names":["sniff","attributes","s","t","e","a","n","i","aw","av","r","aa","v","k","b","d","f","result","c"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6EA,MAAM,2BAAW,IAA+B,CAAC,OAAO,mBAAmB,cAAc,iBAAiB,CAAC;AA6BpG,SAAS,iBAAiB,YAAuC;AACpE,QAAM,EAAE,QAAQ,YAAY,YAAY,CAAA,GAAI,WAAW,OAAO,UAAU,KAAK,OAAAA,QAAO,UAAA,IAAc;AAClG,QAAM,WAA0B;AAAA,IAC5B;AAAA,IACA;AAAA,IACA;AAAA,IACA,SAAS,CAAA;AAAA,IACT,QAAQ,OAAO,OAAoB,MAAiB,YAAyD;AACzG,YAAM,OAAO,qBAAqB,SAAS;AAAA,QACvC,KAAK;AAAA,QACL,iBAAiB;AAAA,QACjB,YAAY;AAAA,MAAA,CACf;AACD,YAAM,SAAS,IAAI,oBAAoB,QAAQ,KAAK,UAAU;AAC9D,wBAAkB,MAAM,SAAS,MAAM;AACvC,0BAAoB,SAAS,QAAQ,IAAI;AACzC,YAAM,MAAM,IAAI,UAAU,KAAK,GAAG;AAClC,YAAM,QAAQ,IAAI,kBAAkB,MAAM,QAAQ,KAAK,gBAAgB;AACvE,YAAM,OAAO,KAAK,kBAAkB,aAAa;AACjD,YAAM,UAAU,KAAK,eAAe;AACpC,YAAM,aAAa,IAAI,gBAAgB,MAAM,QAAQ,KAAK,UAAU;AACpE,YAAM,QAAQ,CAAC,QAAyB,KAAa,WAA6C;AAC9F,mBAAW,MAAM,QAAQ,KAAK,MAAM;AA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