@graphty/graph-io 0.3.8 → 0.3.10

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 (125) hide show
  1. package/README.md +29 -5
  2. package/dist/chunks/{escape-BjmIaFFo.js → escape-D1f9-cwf.js} +4 -4
  3. package/dist/chunks/{escape-BjmIaFFo.js.map → escape-D1f9-cwf.js.map} +1 -1
  4. package/dist/chunks/{importer-BddBW3sf.js → importer-9PxhqH4v.js} +336 -92
  5. package/dist/chunks/importer-9PxhqH4v.js.map +1 -0
  6. package/dist/chunks/{importer-DfI8POXb.js → importer-B8lsjFWx.js} +6 -5
  7. package/dist/chunks/importer-B8lsjFWx.js.map +1 -0
  8. package/dist/chunks/{importer-BtHFICnf.js → importer-C3HcYWAn.js} +5 -3
  9. package/dist/chunks/importer-C3HcYWAn.js.map +1 -0
  10. package/dist/chunks/{importer-BOxwmef_.js → importer-C7mnGdr_.js} +125 -8
  11. package/dist/chunks/importer-C7mnGdr_.js.map +1 -0
  12. package/dist/chunks/{records-BKSMowhR.js → records-IHsCfv7s.js} +20 -7
  13. package/dist/chunks/records-IHsCfv7s.js.map +1 -0
  14. package/dist/chunks/{writer-BdMak4_J.js → writer-BtWpUaiH.js} +4 -4
  15. package/dist/chunks/{writer-BdMak4_J.js.map → writer-BtWpUaiH.js.map} +1 -1
  16. package/dist/csv.js +239 -18
  17. package/dist/csv.js.map +1 -1
  18. package/dist/dot.js +1 -1
  19. package/dist/gexf.js +72 -33
  20. package/dist/gexf.js.map +1 -1
  21. package/dist/gml.js +44 -23
  22. package/dist/gml.js.map +1 -1
  23. package/dist/graph-io.js +11 -11
  24. package/dist/graphml.js +1 -1
  25. package/dist/json.js +1 -1
  26. package/dist/neo4j.js +5 -4
  27. package/dist/neo4j.js.map +1 -1
  28. package/dist/pajek.js +1 -1
  29. package/dist/src/common/export.js +1 -1
  30. package/dist/src/common/export.js.map +1 -1
  31. package/dist/src/formats/csv/exporter.d.ts +15 -4
  32. package/dist/src/formats/csv/exporter.d.ts.map +1 -1
  33. package/dist/src/formats/csv/exporter.js +125 -6
  34. package/dist/src/formats/csv/exporter.js.map +1 -1
  35. package/dist/src/formats/csv/importer.d.ts +36 -4
  36. package/dist/src/formats/csv/importer.d.ts.map +1 -1
  37. package/dist/src/formats/csv/importer.js +169 -8
  38. package/dist/src/formats/csv/importer.js.map +1 -1
  39. package/dist/src/formats/csv/records.d.ts +14 -1
  40. package/dist/src/formats/csv/records.d.ts.map +1 -1
  41. package/dist/src/formats/csv/records.js +28 -7
  42. package/dist/src/formats/csv/records.js.map +1 -1
  43. package/dist/src/formats/dot/exporter.d.ts.map +1 -1
  44. package/dist/src/formats/dot/exporter.js +2 -0
  45. package/dist/src/formats/dot/exporter.js.map +1 -1
  46. package/dist/src/formats/gexf/exporter.d.ts.map +1 -1
  47. package/dist/src/formats/gexf/exporter.js +36 -10
  48. package/dist/src/formats/gexf/exporter.js.map +1 -1
  49. package/dist/src/formats/gexf/importer.d.ts +9 -4
  50. package/dist/src/formats/gexf/importer.d.ts.map +1 -1
  51. package/dist/src/formats/gexf/importer.js +44 -21
  52. package/dist/src/formats/gexf/importer.js.map +1 -1
  53. package/dist/src/formats/gexf/index.d.ts +1 -1
  54. package/dist/src/formats/gexf/index.d.ts.map +1 -1
  55. package/dist/src/formats/gexf/index.js +1 -1
  56. package/dist/src/formats/gexf/index.js.map +1 -1
  57. package/dist/src/formats/gexf/schema.d.ts +2 -0
  58. package/dist/src/formats/gexf/schema.d.ts.map +1 -1
  59. package/dist/src/formats/gexf/schema.js +18 -0
  60. package/dist/src/formats/gexf/schema.js.map +1 -1
  61. package/dist/src/formats/gml/exporter.d.ts.map +1 -1
  62. package/dist/src/formats/gml/exporter.js +1 -0
  63. package/dist/src/formats/gml/exporter.js.map +1 -1
  64. package/dist/src/formats/gml/importer.d.ts +7 -4
  65. package/dist/src/formats/gml/importer.d.ts.map +1 -1
  66. package/dist/src/formats/gml/importer.js +32 -19
  67. package/dist/src/formats/gml/importer.js.map +1 -1
  68. package/dist/src/formats/gml/index.d.ts +3 -1
  69. package/dist/src/formats/gml/index.d.ts.map +1 -1
  70. package/dist/src/formats/gml/index.js +4 -2
  71. package/dist/src/formats/gml/index.js.map +1 -1
  72. package/dist/src/formats/graphml/constants.d.ts +2 -0
  73. package/dist/src/formats/graphml/constants.d.ts.map +1 -1
  74. package/dist/src/formats/graphml/constants.js +2 -0
  75. package/dist/src/formats/graphml/constants.js.map +1 -1
  76. package/dist/src/formats/graphml/exporter.d.ts.map +1 -1
  77. package/dist/src/formats/graphml/exporter.js +14 -2
  78. package/dist/src/formats/graphml/exporter.js.map +1 -1
  79. package/dist/src/formats/graphml/importer.d.ts +2 -1
  80. package/dist/src/formats/graphml/importer.d.ts.map +1 -1
  81. package/dist/src/formats/graphml/importer.js +91 -27
  82. package/dist/src/formats/graphml/importer.js.map +1 -1
  83. package/dist/src/formats/graphml/yfiles.d.ts +62 -0
  84. package/dist/src/formats/graphml/yfiles.d.ts.map +1 -0
  85. package/dist/src/formats/graphml/yfiles.js +269 -0
  86. package/dist/src/formats/graphml/yfiles.js.map +1 -0
  87. package/dist/src/formats/json/exporter.d.ts.map +1 -1
  88. package/dist/src/formats/json/exporter.js +9 -1
  89. package/dist/src/formats/json/exporter.js.map +1 -1
  90. package/dist/src/formats/json/importer.d.ts +14 -0
  91. package/dist/src/formats/json/importer.d.ts.map +1 -1
  92. package/dist/src/formats/json/importer.js +165 -4
  93. package/dist/src/formats/json/importer.js.map +1 -1
  94. package/dist/src/formats/neo4j/exporter.d.ts.map +1 -1
  95. package/dist/src/formats/neo4j/exporter.js +1 -0
  96. package/dist/src/formats/neo4j/exporter.js.map +1 -1
  97. package/dist/src/formats/pajek/exporter.d.ts.map +1 -1
  98. package/dist/src/formats/pajek/exporter.js +3 -2
  99. package/dist/src/formats/pajek/exporter.js.map +1 -1
  100. package/package.json +2 -2
  101. package/src/common/export.ts +1 -1
  102. package/src/formats/csv/exporter.ts +140 -10
  103. package/src/formats/csv/importer.ts +207 -18
  104. package/src/formats/csv/records.ts +41 -6
  105. package/src/formats/dot/exporter.ts +2 -0
  106. package/src/formats/gexf/exporter.ts +40 -11
  107. package/src/formats/gexf/importer.ts +47 -25
  108. package/src/formats/gexf/index.ts +1 -1
  109. package/src/formats/gexf/schema.ts +18 -0
  110. package/src/formats/gml/exporter.ts +1 -0
  111. package/src/formats/gml/importer.ts +47 -24
  112. package/src/formats/gml/index.ts +4 -1
  113. package/src/formats/graphml/constants.ts +2 -0
  114. package/src/formats/graphml/exporter.ts +21 -2
  115. package/src/formats/graphml/importer.ts +99 -28
  116. package/src/formats/graphml/yfiles.ts +292 -0
  117. package/src/formats/json/exporter.ts +9 -1
  118. package/src/formats/json/importer.ts +202 -4
  119. package/src/formats/neo4j/exporter.ts +1 -0
  120. package/src/formats/pajek/exporter.ts +3 -1
  121. package/dist/chunks/importer-BOxwmef_.js.map +0 -1
  122. package/dist/chunks/importer-BddBW3sf.js.map +0 -1
  123. package/dist/chunks/importer-BtHFICnf.js.map +0 -1
  124. package/dist/chunks/importer-DfI8POXb.js.map +0 -1
  125. package/dist/chunks/records-BKSMowhR.js.map +0 -1
package/dist/gml.js CHANGED
@@ -1,6 +1,6 @@
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";
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-BtWpUaiH.js";
2
2
  import { GraphFormatError, INVALID_INDEX } from "@graphty/graph-format";
3
- import { j as decodeGmlString, k as quoteGmlString } from "./chunks/escape-BjmIaFFo.js";
3
+ import { j as decodeGmlString, k as quoteGmlString } from "./chunks/escape-D1f9-cwf.js";
4
4
  const TOKEN_WORD = 0;
5
5
  const TOKEN_INT = 1;
6
6
  const TOKEN_REAL = 2;
@@ -395,7 +395,8 @@ const SKIPPED_ROLES = /* @__PURE__ */ new Set([
395
395
  "timestamp",
396
396
  "timestamps",
397
397
  "spells",
398
- "open"
398
+ "open",
399
+ "spellsOpen"
399
400
  ]);
400
401
  const NODE_RESERVED = /* @__PURE__ */ new Set(["id"]);
401
402
  const EDGE_RESERVED = /* @__PURE__ */ new Set(["source", "target"]);
@@ -1349,6 +1350,7 @@ const MISSING_ID_CODE = MISSING_ID_CODE$1;
1349
1350
  const MISSING_LABEL_CODE = "E_GML_MISSING_LABEL";
1350
1351
  const MISSING_ENDPOINT_CODE = MISSING_ENDPOINT_CODE$1;
1351
1352
  const ID_TYPE_CODE = "E_GML_ID_TYPE";
1353
+ const STRING_ID_CODE = "W_GML_STRING_ID";
1352
1354
  const DUPLICATE_NODE_CODE = DUPLICATE_NODE_CODE$1;
1353
1355
  const REPEATED_KEY_CODE = "E_GML_REPEATED_KEY";
1354
1356
  const ELEMENT_TYPE_CODE = "E_GML_ELEMENT_TYPE";
@@ -1933,7 +1935,7 @@ class GmlImport {
1933
1935
  if (idTok < 0) {
1934
1936
  throw new GraphFormatError("E_INVALID_ID", "node has no id", { reason: "missing id" });
1935
1937
  }
1936
- const fileId = this.integerOf(idTok, "id");
1938
+ const fileId = this.coerceFileId(idTok, this.fileIdOf(idTok, "id"));
1937
1939
  if (originalTok >= 0) {
1938
1940
  sinkId = this.restoredId(originalTok);
1939
1941
  } else {
@@ -1950,7 +1952,7 @@ class GmlImport {
1950
1952
  sinkId = ordinal;
1951
1953
  break;
1952
1954
  default:
1953
- sinkId = this.coerceInteger(idTok, fileId);
1955
+ sinkId = fileId;
1954
1956
  }
1955
1957
  }
1956
1958
  if (this.idMap !== null) {
@@ -2080,23 +2082,46 @@ class GmlImport {
2080
2082
  return p + 1;
2081
2083
  }
2082
2084
  /**
2083
- * The integer value of an id / source / target token (the GML grammar's integer ids; a string
2084
- * id is refused, as the malformed corpus pins, although NetworkX would accept it).
2085
+ * The value of an id / source / target token: an integer (the GML spec's type) as a number, a
2086
+ * string (NetworkX and Gephi write them) as its text with one warning per file.
2085
2087
  * @param v - the value token
2086
2088
  * @param key - the key name, for the error
2087
- * @returns the number
2089
+ * @returns the number or the string
2088
2090
  */
2089
- integerOf(v, key) {
2091
+ fileIdOf(v, key) {
2090
2092
  const t = this.requireTokens();
2093
+ if (t.kind[v] === TOKEN_STRING) {
2094
+ this.report.warnOnce(
2095
+ "validation-error",
2096
+ STRING_ID_CODE,
2097
+ `${key} is the string "${t.textOf(v)}"; GML ids are integers, string ids are kept under the ids rule`,
2098
+ { line: t.line[v], element: t.stringOf(v) }
2099
+ );
2100
+ return t.stringOf(v);
2101
+ }
2091
2102
  if (t.kind[v] !== TOKEN_INT) {
2092
- throw new GraphFormatError("E_INVALID_ID", `${key} must be an integer, found ${describeValue(t, v)}`, {
2093
- reason: "not an integer",
2094
- key,
2095
- value: t.kind[v] === TOKEN_OPEN ? "[...]" : t.textOf(v)
2096
- });
2103
+ throw new GraphFormatError(
2104
+ "E_INVALID_ID",
2105
+ `${key} must be an integer or a string, found ${describeValue(t, v)}`,
2106
+ {
2107
+ reason: "not an integer",
2108
+ key,
2109
+ value: t.kind[v] === TOKEN_OPEN ? "[...]" : t.textOf(v)
2110
+ }
2111
+ );
2097
2112
  }
2098
2113
  return Number(t.textOf(v));
2099
2114
  }
2115
+ /**
2116
+ * Coerce an id / source / target value under the `ids` rule: a string by its text, an integer
2117
+ * through coerceInteger().
2118
+ * @param v - the value token
2119
+ * @param id - its value (fileIdOf())
2120
+ * @returns the id
2121
+ */
2122
+ coerceFileId(v, id) {
2123
+ return typeof id === "string" ? this.coercer.text(id) : this.coerceInteger(v, id);
2124
+ }
2100
2125
  /**
2101
2126
  * Coerce an integer id token under the `ids` rule: a safe integer passes as a typed number
2102
2127
  * (so `01` is 1 and `-0` is 0), a larger one goes through the text rule (a string under
@@ -2156,14 +2181,8 @@ class GmlImport {
2156
2181
  * @returns the id
2157
2182
  */
2158
2183
  endpoint(v, key) {
2159
- const n = this.integerOf(v, key);
2160
- if (this.idMap !== null) {
2161
- const mapped = this.idMap.get(n);
2162
- if (mapped !== void 0) {
2163
- return mapped;
2164
- }
2165
- }
2166
- return this.coerceInteger(v, n);
2184
+ const id = this.coerceFileId(v, this.fileIdOf(v, key));
2185
+ return this.idMap?.get(id) ?? id;
2167
2186
  }
2168
2187
  /**
2169
2188
  * The weight of an edge from its weight token.
@@ -2644,8 +2663,10 @@ const GML_ISSUE = Object.freeze({
2644
2663
  MISSING_LABEL: MISSING_LABEL_CODE,
2645
2664
  /** An edge without `source` or `target`. */
2646
2665
  MISSING_ENDPOINT: MISSING_ENDPOINT_CODE,
2647
- /** A node id, source or target that is not an integer. */
2666
+ /** A node id, source or target that is neither an integer nor a string. */
2648
2667
  ID_TYPE: ID_TYPE_CODE,
2668
+ /** String node ids, sources or targets (outside the spec's integers), kept under the ids rule; warned once. */
2669
+ STRING_ID: STRING_ID_CODE,
2649
2670
  /** A node id declared twice (later keys overwrite). */
2650
2671
  DUPLICATE_NODE: DUPLICATE_NODE_CODE,
2651
2672
  /** A structural key repeated in one element. */