@graphty/graph-io 0.3.38 → 0.3.40

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 (152) hide show
  1. package/dist/chunks/{choose-CsO24U-5.js → choose-CS3fvGT1.js} +2 -2
  2. package/dist/chunks/{choose-CsO24U-5.js.map → choose-CS3fvGT1.js.map} +1 -1
  3. package/dist/chunks/{constants-BPRiVyBu.js → constants-DqKZT6cH.js} +2 -2
  4. package/dist/chunks/{constants-BPRiVyBu.js.map → constants-DqKZT6cH.js.map} +1 -1
  5. package/dist/chunks/{escape-BRcyzD77.js → escape-BJRLd3vJ.js} +4 -3
  6. package/dist/chunks/escape-BJRLd3vJ.js.map +1 -0
  7. package/dist/chunks/{export-CTUlibzr.js → export-B-aVCwyG.js} +103 -92
  8. package/dist/chunks/export-B-aVCwyG.js.map +1 -0
  9. package/dist/chunks/{exporter-Bf5tZA0X.js → exporter-6ocL_9x_.js} +6 -5
  10. package/dist/chunks/exporter-6ocL_9x_.js.map +1 -0
  11. package/dist/chunks/{exporter-Bn4jdYfd.js → exporter-BVXnV9-9.js} +43 -30
  12. package/dist/chunks/exporter-BVXnV9-9.js.map +1 -0
  13. package/dist/chunks/{exporter-D-qQuRcG.js → exporter-Bcp-l4Bo.js} +6 -6
  14. package/dist/chunks/exporter-Bcp-l4Bo.js.map +1 -0
  15. package/dist/chunks/{exporter-F0vT919P.js → exporter-SFYkDzD0.js} +5 -4
  16. package/dist/chunks/exporter-SFYkDzD0.js.map +1 -0
  17. package/dist/chunks/{importer-Bgb9sgZZ.js → importer-AjwOJrn2.js} +6 -8
  18. package/dist/chunks/importer-AjwOJrn2.js.map +1 -0
  19. package/dist/chunks/{importer-BuzbaFFY.js → importer-BJlGAOht.js} +28 -13
  20. package/dist/chunks/importer-BJlGAOht.js.map +1 -0
  21. package/dist/chunks/{importer-DqMtyYLX.js → importer-BpuS3J8C.js} +12 -14
  22. package/dist/chunks/importer-BpuS3J8C.js.map +1 -0
  23. package/dist/chunks/{importer-CEuUmyPe.js → importer-CPqnIY8m.js} +6 -6
  24. package/dist/chunks/{importer-CEuUmyPe.js.map → importer-CPqnIY8m.js.map} +1 -1
  25. package/dist/chunks/{importer-yWUPR_nU.js → importer-DEp_fYjf.js} +30 -12
  26. package/dist/chunks/importer-DEp_fYjf.js.map +1 -0
  27. package/dist/chunks/{importer-CNMQnHDd.js → importer-D_srHyj6.js} +112 -62
  28. package/dist/chunks/importer-D_srHyj6.js.map +1 -0
  29. package/dist/chunks/{importer-oIUx9u_g.js → importer-DcKB97kW.js} +40 -18
  30. package/dist/chunks/importer-DcKB97kW.js.map +1 -0
  31. package/dist/chunks/{json-elements-AkglPS3m.js → json-elements-DpO6AXIc.js} +7 -5
  32. package/dist/chunks/{json-elements-AkglPS3m.js.map → json-elements-DpO6AXIc.js.map} +1 -1
  33. package/dist/chunks/{ontology-export-DDoG3egY.js → ontology-export-50L9DOV4.js} +2 -2
  34. package/dist/chunks/{ontology-export-DDoG3egY.js.map → ontology-export-50L9DOV4.js.map} +1 -1
  35. package/dist/chunks/{records-ChmWZGuz.js → records-r3SFHz11.js} +137 -96
  36. package/dist/chunks/records-r3SFHz11.js.map +1 -0
  37. package/dist/chunks/{text-Btw3sBe_.js → text-Bjfa1xYL.js} +2 -2
  38. package/dist/chunks/{text-Btw3sBe_.js.map → text-Bjfa1xYL.js.map} +1 -1
  39. package/dist/csv.js +4 -4
  40. package/dist/cx.js +1 -1
  41. package/dist/cx2.js +2 -2
  42. package/dist/cys.js +1 -1
  43. package/dist/dot.js +1 -1
  44. package/dist/gexf.js +6 -4
  45. package/dist/gexf.js.map +1 -1
  46. package/dist/gml.js +8 -6
  47. package/dist/gml.js.map +1 -1
  48. package/dist/graph-io.js +26 -26
  49. package/dist/graphml.js +2 -2
  50. package/dist/json.js +1 -1
  51. package/dist/neo4j.js +3 -3
  52. package/dist/obo.js +1 -1
  53. package/dist/pajek.js +1 -1
  54. package/dist/src/common/direction.js +1 -1
  55. package/dist/src/common/direction.js.map +1 -1
  56. package/dist/src/common/export.d.ts.map +1 -1
  57. package/dist/src/common/export.js +136 -71
  58. package/dist/src/common/export.js.map +1 -1
  59. package/dist/src/common/input.js +1 -1
  60. package/dist/src/common/input.js.map +1 -1
  61. package/dist/src/common/json-elements.d.ts.map +1 -1
  62. package/dist/src/common/json-elements.js +4 -2
  63. package/dist/src/common/json-elements.js.map +1 -1
  64. package/dist/src/common/xml.d.ts.map +1 -1
  65. package/dist/src/common/xml.js +2 -1
  66. package/dist/src/common/xml.js.map +1 -1
  67. package/dist/src/formats/csv/records.d.ts.map +1 -1
  68. package/dist/src/formats/csv/records.js +138 -100
  69. package/dist/src/formats/csv/records.js.map +1 -1
  70. package/dist/src/formats/cx/importer.d.ts.map +1 -1
  71. package/dist/src/formats/cx/importer.js +108 -53
  72. package/dist/src/formats/cx/importer.js.map +1 -1
  73. package/dist/src/formats/cx2/exporter.d.ts.map +1 -1
  74. package/dist/src/formats/cx2/exporter.js +2 -1
  75. package/dist/src/formats/cx2/exporter.js.map +1 -1
  76. package/dist/src/formats/cx2/importer.d.ts.map +1 -1
  77. package/dist/src/formats/cx2/importer.js +28 -6
  78. package/dist/src/formats/cx2/importer.js.map +1 -1
  79. package/dist/src/formats/dot/importer.d.ts +6 -0
  80. package/dist/src/formats/dot/importer.d.ts.map +1 -1
  81. package/dist/src/formats/dot/importer.js +11 -6
  82. package/dist/src/formats/dot/importer.js.map +1 -1
  83. package/dist/src/formats/dot/names.d.ts +5 -0
  84. package/dist/src/formats/dot/names.d.ts.map +1 -1
  85. package/dist/src/formats/dot/names.js +5 -0
  86. package/dist/src/formats/dot/names.js.map +1 -1
  87. package/dist/src/formats/dot/tokenizer.js +9 -9
  88. package/dist/src/formats/dot/tokenizer.js.map +1 -1
  89. package/dist/src/formats/gexf/exporter.d.ts.map +1 -1
  90. package/dist/src/formats/gexf/exporter.js +4 -2
  91. package/dist/src/formats/gexf/exporter.js.map +1 -1
  92. package/dist/src/formats/gml/importer.d.ts +6 -0
  93. package/dist/src/formats/gml/importer.d.ts.map +1 -1
  94. package/dist/src/formats/gml/importer.js +6 -3
  95. package/dist/src/formats/gml/importer.js.map +1 -1
  96. package/dist/src/formats/graphml/exporter.d.ts.map +1 -1
  97. package/dist/src/formats/graphml/exporter.js +2 -1
  98. package/dist/src/formats/graphml/exporter.js.map +1 -1
  99. package/dist/src/formats/graphml/importer.d.ts.map +1 -1
  100. package/dist/src/formats/graphml/importer.js +5 -6
  101. package/dist/src/formats/graphml/importer.js.map +1 -1
  102. package/dist/src/formats/obo/importer.d.ts.map +1 -1
  103. package/dist/src/formats/obo/importer.js +2 -1
  104. package/dist/src/formats/obo/importer.js.map +1 -1
  105. package/dist/src/formats/pajek/exporter.d.ts.map +1 -1
  106. package/dist/src/formats/pajek/exporter.js +4 -5
  107. package/dist/src/formats/pajek/exporter.js.map +1 -1
  108. package/dist/src/formats/xgmml/emit.d.ts +6 -0
  109. package/dist/src/formats/xgmml/emit.d.ts.map +1 -1
  110. package/dist/src/formats/xgmml/emit.js +33 -10
  111. package/dist/src/formats/xgmml/emit.js.map +1 -1
  112. package/dist/src/formats/xgmml/exporter.d.ts.map +1 -1
  113. package/dist/src/formats/xgmml/exporter.js +54 -22
  114. package/dist/src/formats/xgmml/exporter.js.map +1 -1
  115. package/dist/src/sniff.js +1 -1
  116. package/dist/src/sniff.js.map +1 -1
  117. package/dist/xgmml.js +2 -2
  118. package/package.json +2 -2
  119. package/src/common/direction.ts +1 -1
  120. package/src/common/export.ts +190 -97
  121. package/src/common/input.ts +1 -1
  122. package/src/common/json-elements.ts +4 -2
  123. package/src/common/xml.ts +2 -1
  124. package/src/formats/csv/records.ts +143 -99
  125. package/src/formats/cx/importer.ts +140 -58
  126. package/src/formats/cx2/exporter.ts +2 -1
  127. package/src/formats/cx2/importer.ts +34 -10
  128. package/src/formats/dot/importer.ts +35 -4
  129. package/src/formats/dot/names.ts +6 -0
  130. package/src/formats/dot/tokenizer.ts +9 -9
  131. package/src/formats/gexf/exporter.ts +4 -2
  132. package/src/formats/gml/importer.ts +14 -3
  133. package/src/formats/graphml/exporter.ts +2 -3
  134. package/src/formats/graphml/importer.ts +5 -6
  135. package/src/formats/obo/importer.ts +2 -1
  136. package/src/formats/pajek/exporter.ts +6 -4
  137. package/src/formats/xgmml/emit.ts +34 -10
  138. package/src/formats/xgmml/exporter.ts +63 -23
  139. package/src/sniff.ts +1 -1
  140. package/dist/chunks/escape-BRcyzD77.js.map +0 -1
  141. package/dist/chunks/export-CTUlibzr.js.map +0 -1
  142. package/dist/chunks/exporter-Bf5tZA0X.js.map +0 -1
  143. package/dist/chunks/exporter-Bn4jdYfd.js.map +0 -1
  144. package/dist/chunks/exporter-D-qQuRcG.js.map +0 -1
  145. package/dist/chunks/exporter-F0vT919P.js.map +0 -1
  146. package/dist/chunks/importer-Bgb9sgZZ.js.map +0 -1
  147. package/dist/chunks/importer-BuzbaFFY.js.map +0 -1
  148. package/dist/chunks/importer-CNMQnHDd.js.map +0 -1
  149. package/dist/chunks/importer-DqMtyYLX.js.map +0 -1
  150. package/dist/chunks/importer-oIUx9u_g.js.map +0 -1
  151. package/dist/chunks/importer-yWUPR_nU.js.map +0 -1
  152. package/dist/chunks/records-ChmWZGuz.js.map +0 -1
@@ -592,9 +592,10 @@ function checkNumberVerification(value, count, report, line) {
592
592
  const raw = isRecord(value) ? value.longNumber : undefined;
593
593
  const digits = raw instanceof ExactInteger ? raw.digits : String(raw);
594
594
  if (count > 1 || !NUMBER_VERIFICATION_VALUES.has(digits)) {
595
+ const held = raw === undefined ? null : digits;
595
596
  report.warning("validation-error", CX_ISSUE.NUMBER_VERIFICATION, count > 1
596
597
  ? "a second numberVerification element; ignored"
597
- : `numberVerification holds ${shown(raw === undefined ? null : digits)}, not 281474976710655`, { line, element: "numberVerification" });
598
+ : `numberVerification holds ${shown(held)}, not 281474976710655`, { line, element: "numberVerification" });
598
599
  }
599
600
  }
600
601
  /**
@@ -752,7 +753,8 @@ async function readDocument(input, report, options) {
752
753
  break;
753
754
  }
754
755
  countMember(event.block, null);
755
- report.error("parse-error", BAD_ASPECT_BLOCK_CODE, `a member of the document is ${keys.length > 1 ? `an object with ${keys.length} keys (${keys.join(", ")})` : shown(value)}, not a one-key aspect fragment; skipped`, { line: event.line, element: keys[0] ?? null });
756
+ const what = keys.length > 1 ? `an object with ${keys.length} keys (${keys.join(", ")})` : shown(value);
757
+ report.error("parse-error", BAD_ASPECT_BLOCK_CODE, `a member of the document is ${what}, not a one-key aspect fragment; skipped`, { line: event.line, element: keys[0] ?? null });
756
758
  break;
757
759
  }
758
760
  case "block":
@@ -1048,6 +1050,14 @@ function layoutViews(doc) {
1048
1050
  function memberCount(members, total) {
1049
1051
  return members === null ? total : members.size;
1050
1052
  }
1053
+ /**
1054
+ * A visual property value as text: a string as it is, anything else as JSON.
1055
+ * @param raw - the value
1056
+ * @returns its text
1057
+ */
1058
+ function visualText(raw) {
1059
+ return typeof raw === "string" ? raw : JSON.stringify(raw);
1060
+ }
1051
1061
  /** Reads one graph of a collected document into a sink. */
1052
1062
  class CxReader {
1053
1063
  /**
@@ -2215,57 +2225,87 @@ class CxReader {
2215
2225
  * applied.
2216
2226
  */
2217
2227
  readVisualProperties() {
2218
- const entries = aspect(this.doc, "cyVisualProperties");
2219
2228
  // Cytoscape's table-cell styles: a visual property aspect graph-io keeps but does not read
2220
2229
  const tableStyles = TABLE_STYLE_ASPECTS.reduce((n, name) => n + (this.doc.kept.get(name)?.length ?? 0), 0);
2221
2230
  // the graph's own view (its first): the one its positions come from; the others stay in meta.extra.cx
2222
2231
  const views = new Set(this.plan.views.slice(0, 1));
2223
- const columns = { node: new Map(), edge: new Map() };
2224
- const network = new Map();
2225
- let defaults = 0;
2226
- let mappings = 0;
2227
- let dependencies = 0;
2228
- for (const { value } of entries) {
2229
- if (!isRecord(value)) {
2230
- continue;
2231
- }
2232
- const view = value.view === undefined || value.view === null ? null : refId(value.view);
2233
- if (view !== null && views.size > 0 && !views.has(view)) {
2234
- continue;
2232
+ const visual = {
2233
+ columns: { node: new Map(), edge: new Map() },
2234
+ network: new Map(),
2235
+ defaults: 0,
2236
+ mappings: 0,
2237
+ dependencies: 0,
2238
+ };
2239
+ for (const { value } of aspect(this.doc, "cyVisualProperties")) {
2240
+ if (isRecord(value)) {
2241
+ this.collectVisualEntry(value, views, visual);
2235
2242
  }
2236
- const properties = isRecord(value.properties) ? value.properties : {};
2237
- mappings += isRecord(value.mappings) ? Object.keys(value.mappings).length : 0;
2238
- dependencies += isRecord(value.dependencies) ? Object.keys(value.dependencies).length : 0;
2239
- switch (value.properties_of) {
2240
- case "nodes":
2241
- case "edges": {
2242
- const domain = value.properties_of === "nodes" ? "node" : "edge";
2243
- const target = refId(value.applies_to);
2244
- const rows = domain === "node" ? this.nodeRows : this.edgeRows;
2245
- const row = target === null ? undefined : rows.get(target);
2246
- if (row === undefined) {
2247
- if (target === null || !(domain === "node" ? this.rootNodes : this.rootEdges).has(target)) {
2248
- this.dangle(`${domain} visual property entry`);
2249
- }
2250
- continue;
2251
- }
2252
- for (const [property, raw] of Object.entries(properties)) {
2253
- const list = columns[domain].get(property) ?? [];
2254
- list.push([row, typeof raw === "string" ? raw : JSON.stringify(raw)]);
2255
- columns[domain].set(property, list);
2256
- }
2257
- break;
2243
+ }
2244
+ this.writeBypassColumns(visual.columns);
2245
+ this.writeBypassNetwork(visual.network);
2246
+ this.reportStyleRules(visual, tableStyles);
2247
+ }
2248
+ /**
2249
+ * File one cyVisualProperties element of this graph's view into the collection: per-element and
2250
+ * network values by property, defaults, mappings and dependencies counted.
2251
+ * @param value - the element
2252
+ * @param views - the views read (empty: every view)
2253
+ * @param visual - the collection to add to
2254
+ */
2255
+ collectVisualEntry(value, views, visual) {
2256
+ const view = value.view === undefined || value.view === null ? null : refId(value.view);
2257
+ if (view !== null && views.size > 0 && !views.has(view)) {
2258
+ return;
2259
+ }
2260
+ const properties = isRecord(value.properties) ? value.properties : {};
2261
+ visual.mappings += isRecord(value.mappings) ? Object.keys(value.mappings).length : 0;
2262
+ visual.dependencies += isRecord(value.dependencies) ? Object.keys(value.dependencies).length : 0;
2263
+ switch (value.properties_of) {
2264
+ case "nodes":
2265
+ this.collectElementProperties("node", value.applies_to, properties, visual.columns);
2266
+ break;
2267
+ case "edges":
2268
+ this.collectElementProperties("edge", value.applies_to, properties, visual.columns);
2269
+ break;
2270
+ case "network":
2271
+ for (const [property, raw] of Object.entries(properties)) {
2272
+ visual.network.set(property, visualText(raw));
2258
2273
  }
2259
- case "network":
2260
- for (const [property, raw] of Object.entries(properties)) {
2261
- network.set(property, typeof raw === "string" ? raw : JSON.stringify(raw));
2262
- }
2263
- break;
2264
- default:
2265
- defaults += Object.keys(properties).length;
2266
- break;
2274
+ break;
2275
+ default:
2276
+ visual.defaults += Object.keys(properties).length;
2277
+ break;
2278
+ }
2279
+ }
2280
+ /**
2281
+ * File the visual values of one node or edge under its row; an element not in this graph is
2282
+ * skipped, and reported dangling when it is in no graph of the file.
2283
+ * @param domain - node or edge
2284
+ * @param appliesTo - the element's applies_to
2285
+ * @param properties - its visual properties
2286
+ * @param columns - the per-property cells to add to
2287
+ */
2288
+ collectElementProperties(domain, appliesTo, properties, columns) {
2289
+ const target = refId(appliesTo);
2290
+ const rows = domain === "node" ? this.nodeRows : this.edgeRows;
2291
+ const row = target === null ? undefined : rows.get(target);
2292
+ if (row === undefined) {
2293
+ if (target === null || !(domain === "node" ? this.rootNodes : this.rootEdges).has(target)) {
2294
+ this.dangle(`${domain} visual property entry`);
2267
2295
  }
2296
+ return;
2268
2297
  }
2298
+ for (const [property, raw] of Object.entries(properties)) {
2299
+ const list = columns[domain].get(property) ?? [];
2300
+ list.push([row, visualText(raw)]);
2301
+ columns[domain].set(property, list);
2302
+ }
2303
+ }
2304
+ /**
2305
+ * Write the collected per-element visual values as string columns in the cx.bypass namespace.
2306
+ * @param columns - the per-property cells of each domain
2307
+ */
2308
+ writeBypassColumns(columns) {
2269
2309
  for (const domain of ["node", "edge"]) {
2270
2310
  for (const [property, cells] of columns[domain]) {
2271
2311
  const handle = declareFresh(this.sink, domain, {
@@ -2284,6 +2324,12 @@ class CxReader {
2284
2324
  }
2285
2325
  }
2286
2326
  }
2327
+ }
2328
+ /**
2329
+ * Write the network visual values as graph values in the cx.bypass namespace.
2330
+ * @param network - the value of each property
2331
+ */
2332
+ writeBypassNetwork(network) {
2287
2333
  for (const [property, text] of network) {
2288
2334
  try {
2289
2335
  this.sink.setGraphValue(property, text, {
@@ -2295,15 +2341,24 @@ class CxReader {
2295
2341
  this.report.recordError(err, { element: property });
2296
2342
  }
2297
2343
  }
2298
- if (defaults + mappings + dependencies + tableStyles > 0) {
2299
- const parts = [
2300
- `cyVisualProperties: ${defaults} default${plural(defaults)}, ${mappings} mapping${plural(mappings)}, ${dependencies} dependenc(ies)`,
2301
- ];
2302
- if (tableStyles > 0) {
2303
- parts.push(`${tableStyles} table style element${plural(tableStyles)}`);
2304
- }
2305
- this.report.warning("unsupported", STYLES_NOT_IMPORTED_CODE, `the file's style rules are not applied (${parts.join("; ")}); they are kept in meta.extra.cx`, { element: "cyVisualProperties" });
2344
+ }
2345
+ /**
2346
+ * Warn that the style rules (defaults, mappings, dependencies, table styles) are kept, not applied.
2347
+ * @param visual - the counted rules
2348
+ * @param tableStyles - the number of table style elements
2349
+ */
2350
+ reportStyleRules(visual, tableStyles) {
2351
+ const { defaults, mappings, dependencies } = visual;
2352
+ if (defaults + mappings + dependencies + tableStyles === 0) {
2353
+ return;
2354
+ }
2355
+ const parts = [
2356
+ `cyVisualProperties: ${defaults} default${plural(defaults)}, ${mappings} mapping${plural(mappings)}, ${dependencies} dependenc(ies)`,
2357
+ ];
2358
+ if (tableStyles > 0) {
2359
+ parts.push(`${tableStyles} table style element${plural(tableStyles)}`);
2306
2360
  }
2361
+ this.report.warning("unsupported", STYLES_NOT_IMPORTED_CODE, `the file's style rules are not applied (${parts.join("; ")}); they are kept in meta.extra.cx`, { element: "cyVisualProperties" });
2307
2362
  }
2308
2363
  /**
2309
2364
  * Read the provenance aspects: citations and supports as extension tables cx:citations and