@graphty/graph-io 0.3.2 → 0.3.4

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.
Files changed (91) hide show
  1. package/README.md +17 -4
  2. package/dist/chunks/{escape-CKied3Ri.js → escape-DXbOoLKl.js} +23 -5
  3. package/dist/chunks/{escape-CKied3Ri.js.map → escape-DXbOoLKl.js.map} +1 -1
  4. package/dist/chunks/{importer-DbMrAR_w.js → importer-B9qF4e32.js} +37 -2
  5. package/dist/chunks/importer-B9qF4e32.js.map +1 -0
  6. package/dist/chunks/{importer-DkzjTvHc.js → importer-BOxwmef_.js} +360 -16
  7. package/dist/chunks/importer-BOxwmef_.js.map +1 -0
  8. package/dist/chunks/{importer-D5pAsweZ.js → importer-C2caVvl6.js} +2 -2
  9. package/dist/chunks/{importer-D5pAsweZ.js.map → importer-C2caVvl6.js.map} +1 -1
  10. package/dist/chunks/{importer-C6QcIRIb.js → importer-xoHpRG5x.js} +2 -2
  11. package/dist/chunks/{importer-C6QcIRIb.js.map → importer-xoHpRG5x.js.map} +1 -1
  12. package/dist/csv.js +1 -1
  13. package/dist/dot.js +1 -1
  14. package/dist/gexf.js +1 -1
  15. package/dist/gml.js +34 -13
  16. package/dist/gml.js.map +1 -1
  17. package/dist/graph-io.js +9 -9
  18. package/dist/graph-io.js.map +1 -1
  19. package/dist/graphml.js +1 -1
  20. package/dist/json.js +1 -1
  21. package/dist/neo4j.js +60 -2
  22. package/dist/neo4j.js.map +1 -1
  23. package/dist/pajek.js +1 -1
  24. package/dist/src/common/escape.d.ts +4 -2
  25. package/dist/src/common/escape.d.ts.map +1 -1
  26. package/dist/src/common/escape.js +31 -5
  27. package/dist/src/common/escape.js.map +1 -1
  28. package/dist/src/formats/gml/importer.d.ts +2 -0
  29. package/dist/src/formats/gml/importer.d.ts.map +1 -1
  30. package/dist/src/formats/gml/importer.js +19 -5
  31. package/dist/src/formats/gml/importer.js.map +1 -1
  32. package/dist/src/formats/gml/index.d.ts +2 -0
  33. package/dist/src/formats/gml/index.d.ts.map +1 -1
  34. package/dist/src/formats/gml/index.js +3 -1
  35. package/dist/src/formats/gml/index.js.map +1 -1
  36. package/dist/src/formats/gml/syntax.d.ts +2 -0
  37. package/dist/src/formats/gml/syntax.d.ts.map +1 -1
  38. package/dist/src/formats/gml/syntax.js +8 -1
  39. package/dist/src/formats/gml/syntax.js.map +1 -1
  40. package/dist/src/formats/graphml/constants.d.ts +4 -0
  41. package/dist/src/formats/graphml/constants.d.ts.map +1 -1
  42. package/dist/src/formats/graphml/constants.js +4 -0
  43. package/dist/src/formats/graphml/constants.js.map +1 -1
  44. package/dist/src/formats/graphml/importer.d.ts.map +1 -1
  45. package/dist/src/formats/graphml/importer.js +28 -0
  46. package/dist/src/formats/graphml/importer.js.map +1 -1
  47. package/dist/src/formats/json/dialect.d.ts +21 -4
  48. package/dist/src/formats/json/dialect.d.ts.map +1 -1
  49. package/dist/src/formats/json/dialect.js +29 -4
  50. package/dist/src/formats/json/dialect.js.map +1 -1
  51. package/dist/src/formats/json/exporter.d.ts.map +1 -1
  52. package/dist/src/formats/json/exporter.js +27 -7
  53. package/dist/src/formats/json/exporter.js.map +1 -1
  54. package/dist/src/formats/json/importer.d.ts +19 -4
  55. package/dist/src/formats/json/importer.d.ts.map +1 -1
  56. package/dist/src/formats/json/importer.js +369 -8
  57. package/dist/src/formats/json/importer.js.map +1 -1
  58. package/dist/src/formats/json/index.d.ts +1 -1
  59. package/dist/src/formats/json/index.d.ts.map +1 -1
  60. package/dist/src/formats/json/index.js +1 -1
  61. package/dist/src/formats/json/index.js.map +1 -1
  62. package/dist/src/formats/neo4j/importer.d.ts +5 -0
  63. package/dist/src/formats/neo4j/importer.d.ts.map +1 -1
  64. package/dist/src/formats/neo4j/importer.js +57 -1
  65. package/dist/src/formats/neo4j/importer.js.map +1 -1
  66. package/dist/src/formats/neo4j/index.d.ts +2 -0
  67. package/dist/src/formats/neo4j/index.d.ts.map +1 -1
  68. package/dist/src/formats/neo4j/index.js +3 -1
  69. package/dist/src/formats/neo4j/index.js.map +1 -1
  70. package/dist/src/index.d.ts +1 -1
  71. package/dist/src/index.d.ts.map +1 -1
  72. package/dist/src/index.js.map +1 -1
  73. package/dist/src/sniff.d.ts +3 -3
  74. package/dist/src/sniff.d.ts.map +1 -1
  75. package/dist/src/sniff.js.map +1 -1
  76. package/package.json +2 -2
  77. package/src/common/escape.ts +5 -4
  78. package/src/formats/json/dialect.ts +40 -6
  79. package/src/formats/json/exporter.ts +28 -7
  80. package/src/formats/json/importer.ts +411 -21
  81. package/src/formats/json/index.ts +7 -1
  82. package/src/formats/neo4j/exporter.ts +43 -6
  83. package/src/formats/neo4j/importer.ts +56 -11
  84. package/src/formats/neo4j/index.ts +10 -3
  85. package/src/formats/pajek/exporter.ts +3 -1
  86. package/src/formats/pajek/importer.ts +284 -60
  87. package/src/formats/pajek/syntax.ts +98 -12
  88. package/src/index.ts +2 -0
  89. package/src/sniff.ts +3 -3
  90. package/dist/chunks/importer-DbMrAR_w.js.map +0 -1
  91. package/dist/chunks/importer-DkzjTvHc.js.map +0 -1
package/dist/csv.js CHANGED
@@ -2,7 +2,7 @@ import { a$ as DICT_SAMPLE_ROWS, a_ as DictHeuristic, X as ROLE_TAKEN_CODE$1, o
2
2
  import { i as inferTextDtype, T as TextCellWriter, p as parseTextCell, W as WIDENING_UNSUPPORTED_CODE } from "./chunks/text-Dr0Ifpag.js";
3
3
  import { GraphFormatError, INVALID_INDEX } from "@graphty/graph-format";
4
4
  import { s as sniffNewline, a as sniffDelimiter, C as CsvRecordReader, B as BAD_QUOTE_CODE, U as UNCLOSED_QUOTE_CODE } from "./chunks/records-BKSMowhR.js";
5
- import { n as quoteCsvCell } from "./chunks/escape-CKied3Ri.js";
5
+ import { n as quoteCsvCell } from "./chunks/escape-DXbOoLKl.js";
6
6
  const SOURCE_NAMES = Object.freeze([
7
7
  "source",
8
8
  "src",
package/dist/dot.js CHANGED
@@ -1,4 +1,4 @@
1
- import { D, a, d, b } from "./chunks/importer-C6QcIRIb.js";
1
+ import { D, a, d, b } from "./chunks/importer-xoHpRG5x.js";
2
2
  export {
3
3
  D as DOT_ISSUE,
4
4
  a as DOT_LOSS,
package/dist/gexf.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { aM as TIME_TEXT_ROLE, aN as TIME_TEXT_SUFFIX, aF as resolveImportOptions, I as ImportReportBuilder, aC as reportSinkOptions, aD as reportUnusedOptions, t as textChunks, aa as XML_SYNTAX_CODE, a as throwIfAborted, v as IdCoercer, l as DirectionResolver, _ as STRAY_TEXT_CODE, K as NO_GRAPH_CODE, d as COUNT_HINT_CODE, aw as isWeightField, aO as declareAttribute, ai as declareResolved, y as MISSING_ID_CODE, k as DUPLICATE_NODE_CODE, a6 as UNKNOWN_PARENT_CODE, M as MISSING_ENDPOINT_CODE, i as DUPLICATE_EDGE_ID_CODE, aA as parseWeightText, aP as parseDeclaredTemporal, ah as declareCompanion, aQ as parseDeclaredValue, aR as losesPrecision, T as PRECISION_CODE, aS as parseTimeText, aT as splitListText, a4 as UNKNOWN_ELEMENT_CODE, o as ID_MERGED_CODE, aU as timeTextCompanion, aV as parseDecimalText, ac as capabilities, L as LOSS, ax as joinText, ak as encodeChunks, aG as sanitizeIds, az as pairFolding, al as explicitWeights, aE as resolveExportOptions, ad as checkCapabilities, aW as formatTimeValue, an as formatF32, ao as formatF64, aX as mapDeclaredType, aY as joinListText, aZ as formatTemporal, aq as formatInteger, at as isCanonicalIntegerText, z as MIXED_DIRECTION_CODE, g as DIRECTION_FORCED_CODE, h as DIRECTION_REFUSED_CODE, Y as SINK_OPTION_CODE, P as OPTION_IGNORED_CODE, X as ROLE_TAKEN_CODE, C as COLUMN_RENAMED_CODE, b as BAD_OPTIONS_CODE, B as BAD_DEFAULT_CODE, a3 as UNKNOWN_ATTR_TYPE_CODE, a5 as UNKNOWN_ENCODING_CODE, n as ENCODING_FALLBACK_CODE, s as INVALID_ENCODING_CODE, u as INVALID_UTF8_CODE } from "./chunks/writer-BdMak4_J.js";
2
2
  import { GraphFormatError, INVALID_INDEX, MAX_COUNT } from "@graphty/graph-format";
3
- import { t as tokenizeXml, d as xmlDeclaredEncoding, X as XmlSyntaxError, l as localName, e as isWhitespace, x as xmlIllegalTextNotes, f as escapeXmlText, g as escapeXmlAttribute } from "./chunks/escape-CKied3Ri.js";
3
+ import { t as tokenizeXml, d as xmlDeclaredEncoding, X as XmlSyntaxError, l as localName, e as isWhitespace, x as xmlIllegalTextNotes, f as escapeXmlText, g as escapeXmlAttribute } from "./chunks/escape-DXbOoLKl.js";
4
4
  const GEXF_FORMAT = "gexf";
5
5
  const GEXF_NAMESPACES = {
6
6
  "1.2": { gexf: "http://www.gexf.net/1.2draft", viz: "http://www.gexf.net/1.2draft/viz" },
package/dist/gml.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { $ as SYNTAX_CODE, ax as joinText, ak as encodeChunks, ad as checkCapabilities, L as LOSS, az as pairFolding, ac as capabilities, aE as resolveExportOptions, a_ as DictHeuristic, aq as formatInteger, aG as sanitizeIds, aJ as countMixedEdges, al as explicitWeights, a$ as DICT_SAMPLE_ROWS, ap as formatGmlReal, X as ROLE_TAKEN_CODE$1, T as PRECISION_CODE$1, k as DUPLICATE_NODE_CODE$1, M as MISSING_ENDPOINT_CODE$1, y as MISSING_ID_CODE$1, A as MULTIPLE_GRAPHS_CODE, K as NO_GRAPH_CODE$1, aF as resolveImportOptions, I as ImportReportBuilder, aD as reportUnusedOptions, aB as readText, a as throwIfAborted, aC as reportSinkOptions, v as IdCoercer, l as DirectionResolver, aL as uniqueColumnName, aK as weightFromValue, aA as parseWeightText, ai as declareResolved, z as MIXED_DIRECTION_CODE, g as DIRECTION_FORCED_CODE, h as DIRECTION_REFUSED_CODE, Y as SINK_OPTION_CODE, P as OPTION_IGNORED_CODE, o as ID_MERGED_CODE, C as COLUMN_RENAMED_CODE, a5 as UNKNOWN_ENCODING_CODE, n as ENCODING_FALLBACK_CODE, s as INVALID_ENCODING_CODE, u as INVALID_UTF8_CODE } from "./chunks/writer-BdMak4_J.js";
2
2
  import { GraphFormatError, INVALID_INDEX } from "@graphty/graph-format";
3
- import { j as decodeGmlString, k as quoteGmlString } from "./chunks/escape-CKied3Ri.js";
3
+ import { j as decodeGmlString, k as quoteGmlString } from "./chunks/escape-DXbOoLKl.js";
4
4
  const TOKEN_WORD = 0;
5
5
  const TOKEN_INT = 1;
6
6
  const TOKEN_REAL = 2;
@@ -43,6 +43,7 @@ class GmlTokens {
43
43
  */
44
44
  constructor(text, capacity = 1024) {
45
45
  this.count = 0;
46
+ this.onUnknownEntity = null;
46
47
  this.text = text;
47
48
  this.kind = new Uint8Array(capacity);
48
49
  this.start = new Uint32Array(capacity);
@@ -81,7 +82,14 @@ class GmlTokens {
81
82
  * @returns the body with character references decoded
82
83
  */
83
84
  stringOf(i) {
84
- return decodeGmlString(this.textOf(i));
85
+ const text = this.textOf(i);
86
+ if (text.indexOf("&") < 0) {
87
+ return text;
88
+ }
89
+ const report = this.onUnknownEntity;
90
+ return decodeGmlString(text, report === null ? void 0 : (entity) => {
91
+ report(entity, this.line[i]);
92
+ });
85
93
  }
86
94
  /**
87
95
  * Whether a token is a `[` or `]`.
@@ -1346,6 +1354,7 @@ const REPEATED_KEY_CODE = "E_GML_REPEATED_KEY";
1346
1354
  const ELEMENT_TYPE_CODE = "E_GML_ELEMENT_TYPE";
1347
1355
  const FLAG_TYPE_CODE = "E_GML_FLAG_TYPE";
1348
1356
  const FLAG_VALUE_CODE = "W_GML_FLAG_VALUE";
1357
+ const UNKNOWN_ENTITY_CODE = "W_GML_UNKNOWN_ENTITY";
1349
1358
  const PRECISION_CODE = PRECISION_CODE$1;
1350
1359
  const ROLE_TAKEN_CODE = ROLE_TAKEN_CODE$1;
1351
1360
  const ID_DROPPED_CODE = "W_GML_ID_DROPPED";
@@ -1442,6 +1451,15 @@ class GmlImport {
1442
1451
  */
1443
1452
  run(tokens) {
1444
1453
  this.tokens = tokens;
1454
+ tokens.onUnknownEntity = (entity, line) => {
1455
+ this.report.warnOnce(
1456
+ "parse-error",
1457
+ UNKNOWN_ENTITY_CODE,
1458
+ `unknown character entity ${entity} is kept as written`,
1459
+ { line, element: entity },
1460
+ `${UNKNOWN_ENTITY_CODE}:${entity}`
1461
+ );
1462
+ };
1445
1463
  this.scan();
1446
1464
  this.push();
1447
1465
  }
@@ -1534,7 +1552,7 @@ class GmlImport {
1534
1552
  continue;
1535
1553
  }
1536
1554
  } else {
1537
- if (key === "source" || key === "target") {
1555
+ if (key === "source" || key === "target" || key === "directed") {
1538
1556
  continue;
1539
1557
  }
1540
1558
  if (key === weightFrom) {
@@ -1782,7 +1800,7 @@ class GmlImport {
1782
1800
  this.report.error(
1783
1801
  "validation-error",
1784
1802
  FLAG_TYPE_CODE,
1785
- `graph flag "${name}" must be the integer 0 or 1, found ${describeValue(t, v)}`,
1803
+ `flag "${name}" must be the integer 0 or 1, found ${describeValue(t, v)}`,
1786
1804
  { line: t.line[v], element: name }
1787
1805
  );
1788
1806
  return null;
@@ -1792,7 +1810,7 @@ class GmlImport {
1792
1810
  this.report.warning(
1793
1811
  "validation-error",
1794
1812
  FLAG_VALUE_CODE,
1795
- `graph flag "${name}" is ${n}; read as ${n !== 0 ? "1" : "0"}`,
1813
+ `flag "${name}" is ${n}; read as ${n !== 0 ? "1" : "0"}`,
1796
1814
  { line: t.line[v], element: name }
1797
1815
  );
1798
1816
  }
@@ -1990,12 +2008,15 @@ class GmlImport {
1990
2008
  let sourceTok = -1;
1991
2009
  let targetTok = -1;
1992
2010
  let weightTok = -1;
2011
+ let directedTok = -1;
1993
2012
  for (let p = open + 1; p < close; p = t.nextPair(p)) {
1994
2013
  const key = t.textOf(p);
1995
2014
  if (key === "source") {
1996
2015
  sourceTok = this.structuralToken(sourceTok, p, "source");
1997
2016
  } else if (key === "target") {
1998
2017
  targetTok = this.structuralToken(targetTok, p, "target");
2018
+ } else if (key === "directed") {
2019
+ directedTok = this.structuralToken(directedTok, p, "directed");
1999
2020
  } else if (key === options.weightFrom) {
2000
2021
  weightTok = p + 1;
2001
2022
  }
@@ -2011,13 +2032,11 @@ class GmlImport {
2011
2032
  const before = sink.edgeCount;
2012
2033
  const sourceNew = sink.indexOf(source) === INVALID_INDEX;
2013
2034
  const targetNew = source !== target && sink.indexOf(target) === INVALID_INDEX;
2014
- edge = this.requireResolver().addEdge(
2015
- source,
2016
- target,
2017
- this.headerDirected ? "directed" : "undirected",
2018
- weight,
2019
- { line, element }
2020
- );
2035
+ const directed = this.readFlag(directedTok, "directed") ?? this.headerDirected;
2036
+ edge = this.requireResolver().addEdge(source, target, directed ? "directed" : "undirected", weight, {
2037
+ line,
2038
+ element
2039
+ });
2021
2040
  report.counts.edges += sink.edgeCount - before;
2022
2041
  report.counts.nodes += (sourceNew ? 1 : 0) + (targetNew ? 1 : 0);
2023
2042
  } catch (err) {
@@ -2029,7 +2048,7 @@ class GmlImport {
2029
2048
  try {
2030
2049
  for (let p = open + 1; p < close; p = t.nextPair(p)) {
2031
2050
  const key = t.textOf(p);
2032
- if (key === "source" || key === "target" || key === options.weightFrom) {
2051
+ if (key === "source" || key === "target" || key === "directed" || key === options.weightFrom) {
2033
2052
  continue;
2034
2053
  }
2035
2054
  const plan = this.edgePlans.get(key);
@@ -2637,6 +2656,8 @@ const GML_ISSUE = Object.freeze({
2637
2656
  FLAG_TYPE: FLAG_TYPE_CODE,
2638
2657
  /** A `directed` / `multigraph` flag outside 0 / 1, or repeated. */
2639
2658
  FLAG_VALUE: FLAG_VALUE_CODE,
2659
+ /** A named entity in a string that no table decodes; kept as written. */
2660
+ UNKNOWN_ENTITY: UNKNOWN_ENTITY_CODE,
2640
2661
  /** An integer beyond 2^53 rounded to f64. */
2641
2662
  PRECISION: PRECISION_CODE,
2642
2663
  /** A column renamed `<name>#<key>` because the sink held the name with another shape. */