@graphty/graph-io 0.2.4 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (180) hide show
  1. package/README.md +29 -7
  2. package/dist/chunks/{escape-DyI8JofU.js → escape-CKied3Ri.js} +16 -10
  3. package/dist/chunks/escape-CKied3Ri.js.map +1 -0
  4. package/dist/chunks/{importer-DbnGYr3_.js → importer-C6QcIRIb.js} +129 -39
  5. package/dist/chunks/importer-C6QcIRIb.js.map +1 -0
  6. package/dist/chunks/{importer-CpCpfbxr.js → importer-D5pAsweZ.js} +136 -31
  7. package/dist/chunks/importer-D5pAsweZ.js.map +1 -0
  8. package/dist/chunks/{importer-GozH8DkN.js → importer-DbMrAR_w.js} +10 -4
  9. package/dist/chunks/importer-DbMrAR_w.js.map +1 -0
  10. package/dist/chunks/{importer-CQnJuWJw.js → importer-DkzjTvHc.js} +82 -40
  11. package/dist/chunks/importer-DkzjTvHc.js.map +1 -0
  12. package/dist/chunks/{records-CGpxszm1.js → records-BKSMowhR.js} +3 -3
  13. package/dist/chunks/{records-CGpxszm1.js.map → records-BKSMowhR.js.map} +1 -1
  14. package/dist/chunks/{text-CajMdVFy.js → text-Dr0Ifpag.js} +2 -2
  15. package/dist/chunks/{text-CajMdVFy.js.map → text-Dr0Ifpag.js.map} +1 -1
  16. package/dist/chunks/{writer-DxSKC7TL.js → writer-BdMak4_J.js} +341 -112
  17. package/dist/chunks/writer-BdMak4_J.js.map +1 -0
  18. package/dist/csv.js +24 -6
  19. package/dist/csv.js.map +1 -1
  20. package/dist/dot.js +1 -1
  21. package/dist/gexf.js +42 -10
  22. package/dist/gexf.js.map +1 -1
  23. package/dist/gml.js +69 -25
  24. package/dist/gml.js.map +1 -1
  25. package/dist/graph-io.js +186 -129
  26. package/dist/graph-io.js.map +1 -1
  27. package/dist/graphml.js +1 -1
  28. package/dist/json.js +1 -1
  29. package/dist/neo4j.js +10 -4
  30. package/dist/neo4j.js.map +1 -1
  31. package/dist/pajek.js +1 -1
  32. package/dist/src/common/codes.d.ts +6 -0
  33. package/dist/src/common/codes.d.ts.map +1 -1
  34. package/dist/src/common/codes.js +6 -0
  35. package/dist/src/common/codes.js.map +1 -1
  36. package/dist/src/common/escape.d.ts +5 -4
  37. package/dist/src/common/escape.d.ts.map +1 -1
  38. package/dist/src/common/escape.js +6 -5
  39. package/dist/src/common/escape.js.map +1 -1
  40. package/dist/src/common/format.d.ts +3 -3
  41. package/dist/src/common/format.js +5 -5
  42. package/dist/src/common/format.js.map +1 -1
  43. package/dist/src/common/input.d.ts +24 -6
  44. package/dist/src/common/input.d.ts.map +1 -1
  45. package/dist/src/common/input.js +259 -23
  46. package/dist/src/common/input.js.map +1 -1
  47. package/dist/src/common/options.d.ts +2 -0
  48. package/dist/src/common/options.d.ts.map +1 -1
  49. package/dist/src/common/options.js +17 -0
  50. package/dist/src/common/options.js.map +1 -1
  51. package/dist/src/common/text.js +4 -4
  52. package/dist/src/common/text.js.map +1 -1
  53. package/dist/src/common/weights.d.ts.map +1 -1
  54. package/dist/src/common/weights.js +8 -0
  55. package/dist/src/common/weights.js.map +1 -1
  56. package/dist/src/common/xml.d.ts +7 -0
  57. package/dist/src/common/xml.d.ts.map +1 -1
  58. package/dist/src/common/xml.js +12 -0
  59. package/dist/src/common/xml.js.map +1 -1
  60. package/dist/src/formats/csv/exporter.d.ts +5 -1
  61. package/dist/src/formats/csv/exporter.d.ts.map +1 -1
  62. package/dist/src/formats/csv/exporter.js +8 -1
  63. package/dist/src/formats/csv/exporter.js.map +1 -1
  64. package/dist/src/formats/csv/importer.d.ts.map +1 -1
  65. package/dist/src/formats/csv/importer.js +1 -0
  66. package/dist/src/formats/csv/importer.js.map +1 -1
  67. package/dist/src/formats/csv/index.d.ts +6 -0
  68. package/dist/src/formats/csv/index.d.ts.map +1 -1
  69. package/dist/src/formats/csv/index.js +7 -1
  70. package/dist/src/formats/csv/index.js.map +1 -1
  71. package/dist/src/formats/csv/records.js +1 -1
  72. package/dist/src/formats/csv/records.js.map +1 -1
  73. package/dist/src/formats/dot/exporter.d.ts +1 -1
  74. package/dist/src/formats/dot/exporter.d.ts.map +1 -1
  75. package/dist/src/formats/dot/exporter.js +3 -3
  76. package/dist/src/formats/dot/exporter.js.map +1 -1
  77. package/dist/src/formats/dot/importer.d.ts +6 -0
  78. package/dist/src/formats/dot/importer.d.ts.map +1 -1
  79. package/dist/src/formats/dot/importer.js +151 -24
  80. package/dist/src/formats/dot/importer.js.map +1 -1
  81. package/dist/src/formats/gexf/exporter.d.ts.map +1 -1
  82. package/dist/src/formats/gexf/exporter.js +32 -7
  83. package/dist/src/formats/gexf/exporter.js.map +1 -1
  84. package/dist/src/formats/gexf/importer.d.ts.map +1 -1
  85. package/dist/src/formats/gexf/importer.js +2 -2
  86. package/dist/src/formats/gexf/importer.js.map +1 -1
  87. package/dist/src/formats/gexf/index.d.ts +6 -0
  88. package/dist/src/formats/gexf/index.d.ts.map +1 -1
  89. package/dist/src/formats/gexf/index.js +7 -1
  90. package/dist/src/formats/gexf/index.js.map +1 -1
  91. package/dist/src/formats/gml/importer.d.ts +2 -2
  92. package/dist/src/formats/gml/importer.d.ts.map +1 -1
  93. package/dist/src/formats/gml/importer.js +66 -25
  94. package/dist/src/formats/gml/importer.js.map +1 -1
  95. package/dist/src/formats/gml/index.d.ts +7 -1
  96. package/dist/src/formats/gml/index.d.ts.map +1 -1
  97. package/dist/src/formats/gml/index.js +8 -2
  98. package/dist/src/formats/gml/index.js.map +1 -1
  99. package/dist/src/formats/graphml/constants.d.ts +6 -0
  100. package/dist/src/formats/graphml/constants.d.ts.map +1 -1
  101. package/dist/src/formats/graphml/constants.js +7 -1
  102. package/dist/src/formats/graphml/constants.js.map +1 -1
  103. package/dist/src/formats/graphml/importer.d.ts.map +1 -1
  104. package/dist/src/formats/graphml/importer.js +2 -2
  105. package/dist/src/formats/graphml/importer.js.map +1 -1
  106. package/dist/src/formats/json/exporter.d.ts.map +1 -1
  107. package/dist/src/formats/json/exporter.js +14 -5
  108. package/dist/src/formats/json/exporter.js.map +1 -1
  109. package/dist/src/formats/json/importer.d.ts +8 -0
  110. package/dist/src/formats/json/importer.d.ts.map +1 -1
  111. package/dist/src/formats/json/importer.js +84 -37
  112. package/dist/src/formats/json/importer.js.map +1 -1
  113. package/dist/src/formats/neo4j/importer.js +1 -1
  114. package/dist/src/formats/neo4j/importer.js.map +1 -1
  115. package/dist/src/formats/neo4j/index.d.ts +6 -0
  116. package/dist/src/formats/neo4j/index.d.ts.map +1 -1
  117. package/dist/src/formats/neo4j/index.js +7 -1
  118. package/dist/src/formats/neo4j/index.js.map +1 -1
  119. package/dist/src/formats/pajek/exporter.d.ts +2 -0
  120. package/dist/src/formats/pajek/exporter.d.ts.map +1 -1
  121. package/dist/src/formats/pajek/exporter.js +13 -2
  122. package/dist/src/formats/pajek/exporter.js.map +1 -1
  123. package/dist/src/formats/pajek/importer.d.ts +8 -2
  124. package/dist/src/formats/pajek/importer.d.ts.map +1 -1
  125. package/dist/src/formats/pajek/importer.js +122 -26
  126. package/dist/src/formats/pajek/importer.js.map +1 -1
  127. package/dist/src/index.d.ts +1 -1
  128. package/dist/src/index.d.ts.map +1 -1
  129. package/dist/src/index.js +1 -1
  130. package/dist/src/index.js.map +1 -1
  131. package/dist/src/registry.d.ts +26 -0
  132. package/dist/src/registry.d.ts.map +1 -1
  133. package/dist/src/registry.js +101 -35
  134. package/dist/src/registry.js.map +1 -1
  135. package/dist/src/sniff.d.ts +1 -1
  136. package/dist/src/sniff.d.ts.map +1 -1
  137. package/dist/src/sniff.js +6 -1
  138. package/dist/src/sniff.js.map +1 -1
  139. package/dist/src/types.d.ts +22 -3
  140. package/dist/src/types.d.ts.map +1 -1
  141. package/dist/src/types.js.map +1 -1
  142. package/package.json +4 -3
  143. package/src/common/codes.ts +9 -0
  144. package/src/common/escape.ts +6 -5
  145. package/src/common/format.ts +5 -5
  146. package/src/common/input.ts +293 -22
  147. package/src/common/options.ts +24 -0
  148. package/src/common/text.ts +4 -4
  149. package/src/common/weights.ts +9 -0
  150. package/src/common/xml.ts +14 -0
  151. package/src/formats/csv/exporter.ts +12 -1
  152. package/src/formats/csv/importer.ts +1 -0
  153. package/src/formats/csv/index.ts +9 -0
  154. package/src/formats/csv/records.ts +1 -1
  155. package/src/formats/dot/exporter.ts +3 -3
  156. package/src/formats/dot/importer.ts +172 -32
  157. package/src/formats/gexf/exporter.ts +38 -7
  158. package/src/formats/gexf/importer.ts +12 -2
  159. package/src/formats/gexf/index.ts +9 -0
  160. package/src/formats/gml/importer.ts +75 -22
  161. package/src/formats/gml/index.ts +10 -1
  162. package/src/formats/graphml/constants.ts +9 -0
  163. package/src/formats/graphml/importer.ts +9 -2
  164. package/src/formats/json/exporter.ts +14 -5
  165. package/src/formats/json/importer.ts +104 -36
  166. package/src/formats/neo4j/importer.ts +1 -1
  167. package/src/formats/neo4j/index.ts +9 -0
  168. package/src/formats/pajek/exporter.ts +19 -2
  169. package/src/formats/pajek/importer.ts +145 -28
  170. package/src/index.ts +1 -0
  171. package/src/registry.ts +131 -40
  172. package/src/sniff.ts +6 -1
  173. package/src/types.ts +26 -3
  174. package/dist/chunks/escape-DyI8JofU.js.map +0 -1
  175. package/dist/chunks/importer-CQnJuWJw.js.map +0 -1
  176. package/dist/chunks/importer-CpCpfbxr.js.map +0 -1
  177. package/dist/chunks/importer-DbnGYr3_.js.map +0 -1
  178. package/dist/chunks/importer-GozH8DkN.js.map +0 -1
  179. package/dist/chunks/writer-DxSKC7TL.js.map +0 -1
  180. package/dist/tsconfig.build.tsbuildinfo +0 -1
@@ -1,7 +1,7 @@
1
1
  import { GraphFormatError, INVALID_INDEX } from "@graphty/graph-format";
2
- import { L as LOSS, au as joinText, ah as encodeChunks, aB as resolveExportOptions, aD as sanitizeIds, aa as checkCapabilities, aw as pairFolding, a9 as capabilities, ai as explicitWeights, al as formatF64, aj as formatDecimal, ak as formatF32, an as formatInteger, a8 as canonicalId, W as SINK_OPTION_CODE, J as OPTION_IGNORED_CODE, V as ROLE_TAKEN_CODE, S as RENAMED_CODE, n as ID_MERGED_CODE, k as DUPLICATE_NODE_CODE, Z as SYNTAX_CODE, r as INVALID_UTF8_CODE, aC as resolveImportOptions, I as ImportReportBuilder, az as reportSinkOptions, aA as reportUnusedOptions, v as LineReader, a as throwIfAborted, l as DirectionResolver, s as IdCoercer, ac as coerceIdText, af as declareResolved, at as isWeightField, ax as parseWeightText } from "./writer-DxSKC7TL.js";
3
- import { i as isPajekLabel, q as quotePajekLabel } from "./escape-DyI8JofU.js";
4
- import { W as WIDENING_UNSUPPORTED_CODE, a as isNumericText, T as TextCellWriter } from "./text-CajMdVFy.js";
2
+ import { L as LOSS, ax as joinText, ak as encodeChunks, aE as resolveExportOptions, aG as sanitizeIds, ad as checkCapabilities, az as pairFolding, ac as capabilities, al as explicitWeights, ao as formatF64, am as formatDecimal, an as formatF32, aq as formatInteger, ab as canonicalId, Y as SINK_OPTION_CODE, P as OPTION_IGNORED_CODE, X as ROLE_TAKEN_CODE, U as RENAMED_CODE, o as ID_MERGED_CODE, k as DUPLICATE_NODE_CODE, $ as SYNTAX_CODE, A as MULTIPLE_GRAPHS_CODE, a5 as UNKNOWN_ENCODING_CODE, n as ENCODING_FALLBACK_CODE, s as INVALID_ENCODING_CODE, u as INVALID_UTF8_CODE, aF as resolveImportOptions, I as ImportReportBuilder, aD as reportUnusedOptions, x as LineReader, a as throwIfAborted, aC as reportSinkOptions, l as DirectionResolver, v as IdCoercer, af as coerceIdText, ai as declareResolved, aw as isWeightField, aA as parseWeightText } from "./writer-BdMak4_J.js";
3
+ import { i as isPajekLabel, q as quotePajekLabel } from "./escape-CKied3Ri.js";
4
+ import { i as inferTextDtype, W as WIDENING_UNSUPPORTED_CODE, a as isNumericText, T as TextCellWriter } from "./text-Dr0Ifpag.js";
5
5
  const LABEL_COLUMN = "label";
6
6
  const POSITION_COLUMN = "position";
7
7
  const SHAPE_COLUMN = "shape";
@@ -220,7 +220,9 @@ const PAJEK_LOSS = Object.freeze({
220
220
  /** A role-less node column named `label` reads back with the label role (its values become the vertex labels). */
221
221
  ROLE_ASSUMED: LOSS.ROLE_ASSUMED,
222
222
  /** Under sanitizeIds "mangle": an original id whose text reads back as the other type under ids "canonical". */
223
- ID_TEXT_TYPE: LOSS.ID_TEXT_TYPE
223
+ ID_TEXT_TYPE: LOSS.ID_TEXT_TYPE,
224
+ /** Parameter text that looks like a number or a boolean reads back as one (parameters are untyped, design 5.1). */
225
+ TEXT_INFERRED: LOSS.TEXT_INFERRED
224
226
  });
225
227
  const SLOT_ROLES = /* @__PURE__ */ new Set(["label"]);
226
228
  const ROLE_NAMES = Object.freeze({ label: "label" });
@@ -477,6 +479,7 @@ function checkCells(planned, domain, notes) {
477
479
  const { name } = column.meta;
478
480
  let badText = 0;
479
481
  let nonFinite = 0;
482
+ let typed = 0;
480
483
  for (let r = 0; r < column.length; r++) {
481
484
  if (!column.isSet(r)) {
482
485
  continue;
@@ -491,8 +494,11 @@ function checkCells(planned, domain, notes) {
491
494
  nonFinite++;
492
495
  }
493
496
  } else if (column.dtype === "string" || column.dtype === "dict") {
494
- if (!isPajekLabel(column.value(r))) {
497
+ const text = column.value(r);
498
+ if (!isPajekLabel(text)) {
495
499
  badText++;
500
+ } else if (slot === "param" && inferTextDtype(text) !== "string") {
501
+ typed++;
496
502
  }
497
503
  }
498
504
  }
@@ -506,6 +512,16 @@ function checkCells(planned, domain, notes) {
506
512
  )
507
513
  );
508
514
  }
515
+ if (typed > 0) {
516
+ notes.push(
517
+ note(
518
+ PAJEK_LOSS.TEXT_INFERRED,
519
+ `${typed} value(s) of ${domain} column "${name}" look like numbers or booleans; Pajek parameters are untyped and they read back as such`,
520
+ name,
521
+ typed
522
+ )
523
+ );
524
+ }
509
525
  if (nonFinite > 0) {
510
526
  notes.push(
511
527
  note(
@@ -947,12 +963,18 @@ const pajekExporter = Object.freeze({
947
963
  const PAJEK_ISSUE = Object.freeze({
948
964
  /** The input holds invalid UTF-8 (fatal). */
949
965
  INVALID_UTF8: INVALID_UTF8_CODE,
966
+ /** Invalid bytes in the encoding a BOM, a declaration or the encoding option chose (fatal). */
967
+ INVALID_ENCODING: INVALID_ENCODING_CODE,
968
+ /** Bytes that are not UTF-8 and declare no encoding were read as windows-1252. */
969
+ ENCODING_FALLBACK: ENCODING_FALLBACK_CODE,
970
+ /** A declared encoding the platform cannot decode was ignored. */
971
+ UNKNOWN_ENCODING: UNKNOWN_ENCODING_CODE,
950
972
  /** Fatal: no `*Vertices` section (an empty file, or not a Pajek network). */
951
973
  NO_VERTICES: "E_PAJEK_NO_VERTICES",
952
974
  /** Fatal: `*Vertices` without a vertex count, or one the sink cannot hold. */
953
975
  VERTICES_COUNT: "E_PAJEK_VERTICES_COUNT",
954
- /** Aborts: a second `*Vertices` or `*Network` section; only one network per file is read. */
955
- MULTIPLE_NETWORKS: "E_PAJEK_MULTIPLE_NETWORKS",
976
+ /** A project file holds several networks; import() reads the first, importAll() reads every one. */
977
+ MULTIPLE_GRAPHS: MULTIPLE_GRAPHS_CODE,
956
978
  /** A data line before the first section header. */
957
979
  OUTSIDE_SECTION: "E_PAJEK_OUTSIDE_SECTION",
958
980
  /** A section header the importer cannot parse. */
@@ -1111,6 +1133,7 @@ class PajekParser {
1111
1133
  this.relationHandle = INVALID_INDEX;
1112
1134
  this.edgeSpellsHandle = INVALID_INDEX;
1113
1135
  this.nodeParams = /* @__PURE__ */ new Map();
1136
+ this.ended = false;
1114
1137
  this.edgeParams = /* @__PURE__ */ new Map();
1115
1138
  this.sink = sink;
1116
1139
  this.report = report;
@@ -1123,15 +1146,16 @@ class PajekParser {
1123
1146
  * Handle one line; every problem of the line is recorded as an issue and the line skipped.
1124
1147
  * @param text - the line without its terminator
1125
1148
  * @param line - the 1-based line number
1149
+ * @returns true when the line is the header of the next network (not consumed: this network is complete)
1126
1150
  */
1127
1151
  line(text, line) {
1128
1152
  if (isCommentOrBlank(text)) {
1129
- return;
1153
+ return false;
1130
1154
  }
1131
1155
  try {
1132
1156
  if (isSectionLine(text)) {
1133
1157
  this.header(text, line);
1134
- return;
1158
+ return this.ended;
1135
1159
  }
1136
1160
  switch (this.section) {
1137
1161
  case "none":
@@ -1142,18 +1166,18 @@ class PajekParser {
1142
1166
  );
1143
1167
  case "vertices":
1144
1168
  this.vertexLine(text, line);
1145
- return;
1169
+ return false;
1146
1170
  case "lines":
1147
1171
  this.edgeLine(text, line);
1148
- return;
1172
+ return false;
1149
1173
  case "list":
1150
1174
  this.listLine(text, line);
1151
- return;
1175
+ return false;
1152
1176
  case "matrix":
1153
1177
  this.matrixLine(text, line);
1154
- return;
1178
+ return false;
1155
1179
  case "skip":
1156
- return;
1180
+ return false;
1157
1181
  default: {
1158
1182
  const name = this.section;
1159
1183
  throw new Error(`unknown section state ${name}`);
@@ -1162,9 +1186,10 @@ class PajekParser {
1162
1186
  } catch (err) {
1163
1187
  if (err instanceof LineError) {
1164
1188
  this.report.error(err.category, err.code, err.message, { line });
1165
- return;
1189
+ return false;
1166
1190
  }
1167
1191
  this.report.recordError(err, { line });
1192
+ return false;
1168
1193
  }
1169
1194
  }
1170
1195
  /**
@@ -1224,7 +1249,8 @@ class PajekParser {
1224
1249
  switch (h.kind) {
1225
1250
  case "network":
1226
1251
  if (this.networkName !== null || this.vertexCount >= 0) {
1227
- this.refuseSecondNetwork(h.keyword, line);
1252
+ this.ended = true;
1253
+ return;
1228
1254
  }
1229
1255
  this.networkName = h.name ?? "";
1230
1256
  this.section = "none";
@@ -1234,6 +1260,10 @@ class PajekParser {
1234
1260
  this.section = "skip";
1235
1261
  return;
1236
1262
  }
1263
+ if (this.vertexCount >= 0) {
1264
+ this.ended = true;
1265
+ return;
1266
+ }
1237
1267
  this.verticesHeader(h, line);
1238
1268
  return;
1239
1269
  case "arcs":
@@ -1269,9 +1299,6 @@ class PajekParser {
1269
1299
  * @param line - the line number
1270
1300
  */
1271
1301
  verticesHeader(h, line) {
1272
- if (this.vertexCount >= 0) {
1273
- this.refuseSecondNetwork(h.keyword, line);
1274
- }
1275
1302
  if (h.count === null) {
1276
1303
  this.report.fail(PAJEK_ISSUE.VERTICES_COUNT, "*Vertices needs a vertex count", { line });
1277
1304
  }
@@ -1330,16 +1357,6 @@ class PajekParser {
1330
1357
  this.kind = kind;
1331
1358
  this.relation = h.relation === null ? null : h.name ?? String(h.relation);
1332
1359
  }
1333
- /**
1334
- * Refuse a second network: an issue, then ImportError with the report so far.
1335
- * @param keyword - the header keyword
1336
- * @param line - the line number
1337
- */
1338
- refuseSecondNetwork(keyword, line) {
1339
- const message = `*${keyword} starts a second network; the importer reads one network per file`;
1340
- this.report.error("unsupported", PAJEK_ISSUE.MULTIPLE_NETWORKS, message, { line });
1341
- throw this.report.abort(message, { code: PAJEK_ISSUE.MULTIPLE_NETWORKS, line });
1342
- }
1343
1360
  /**
1344
1361
  * Checks that run when a section ends.
1345
1362
  */
@@ -1993,23 +2010,111 @@ const pajekImporter = Object.freeze({
1993
2010
  reportUnusedOptions(options, report, USED_OPTIONS);
1994
2011
  const parser = new PajekParser(sink, report, resolved, firstVertex);
1995
2012
  const reader = new LineReader(input, report, resolved);
2013
+ let rest = null;
2014
+ let restLine = 0;
1996
2015
  let sinceCheck = 0;
1997
2016
  for await (const text of reader) {
1998
- parser.line(text, reader.line);
2017
+ if (rest !== null) {
2018
+ rest.line(text);
2019
+ } else if (parser.line(text, reader.line)) {
2020
+ rest = new NetworkCounter();
2021
+ rest.line(text);
2022
+ restLine = reader.line;
2023
+ }
1999
2024
  if (++sinceCheck >= ABORT_CHECK_INTERVAL) {
2000
2025
  sinceCheck = 0;
2001
2026
  throwIfAborted(resolved.signal);
2002
2027
  }
2003
2028
  }
2004
2029
  parser.finish();
2030
+ if (rest !== null) {
2031
+ report.warning(
2032
+ "unsupported",
2033
+ PAJEK_ISSUE.MULTIPLE_GRAPHS,
2034
+ `the project file holds ${rest.count} more network(s) after the first; import() reads the first, importAll() reads every one`,
2035
+ { line: restLine }
2036
+ );
2037
+ }
2005
2038
  throwIfAborted(resolved.signal);
2006
2039
  return report.finish();
2040
+ },
2041
+ /**
2042
+ * Read every network of a Pajek project file (`.paj`), each into its own sink. A network starts
2043
+ * at `*Network` or at a `*Vertices` that does not belong to a `*Partition` / `*Vector` section.
2044
+ * @param input - the text, bytes or stream
2045
+ * @param sinkFor - the sink of the network with this index, called before its first push
2046
+ * @param options - common and Pajek options
2047
+ * @returns one report per network
2048
+ */
2049
+ async importAll(input, sinkFor, options) {
2050
+ const resolved = resolveImportOptions(options, DEFAULTS);
2051
+ const firstVertex = firstVertexOption(options?.firstVertex);
2052
+ const reports = [new ImportReportBuilder("pajek", resolved.errorLimit)];
2053
+ reportUnusedOptions(options, reports[0], USED_OPTIONS);
2054
+ const open = () => {
2055
+ const report = reports[reports.length - 1];
2056
+ const sink = sinkFor(reports.length - 1);
2057
+ reportSinkOptions(sink, options, report);
2058
+ return new PajekParser(sink, report, resolved, firstVertex);
2059
+ };
2060
+ let parser = open();
2061
+ const reader = new LineReader(input, reports[0], resolved);
2062
+ let sinceCheck = 0;
2063
+ for await (const text of reader) {
2064
+ if (parser.line(text, reader.line)) {
2065
+ parser.finish();
2066
+ reports.push(new ImportReportBuilder("pajek", resolved.errorLimit));
2067
+ parser = open();
2068
+ parser.line(text, reader.line);
2069
+ }
2070
+ if (++sinceCheck >= ABORT_CHECK_INTERVAL) {
2071
+ sinceCheck = 0;
2072
+ throwIfAborted(resolved.signal);
2073
+ }
2074
+ }
2075
+ parser.finish();
2076
+ throwIfAborted(resolved.signal);
2077
+ return reports.map((r) => r.finish());
2007
2078
  }
2008
2079
  });
2080
+ class NetworkCounter {
2081
+ constructor() {
2082
+ this.count = 0;
2083
+ this.named = false;
2084
+ this.populated = false;
2085
+ this.skipping = false;
2086
+ }
2087
+ /**
2088
+ * Feed one line.
2089
+ * @param text - the line
2090
+ */
2091
+ line(text) {
2092
+ if (!isSectionLine(text)) {
2093
+ return;
2094
+ }
2095
+ const h = parseSectionHeader(text);
2096
+ const kind = h === null ? "unsupported" : h.kind;
2097
+ const { skipping } = this;
2098
+ this.skipping = kind === "unsupported" || kind === "vertices" && skipping && this.populated;
2099
+ if (kind === "network") {
2100
+ if (this.count === 0 || this.named || this.populated) {
2101
+ this.count++;
2102
+ this.populated = false;
2103
+ }
2104
+ this.named = true;
2105
+ } else if (kind === "vertices" && !this.skipping) {
2106
+ if (this.count === 0 || this.populated) {
2107
+ this.count++;
2108
+ this.named = false;
2109
+ }
2110
+ this.populated = true;
2111
+ }
2112
+ }
2113
+ }
2009
2114
  export {
2010
2115
  PAJEK_ISSUE as P,
2011
2116
  PAJEK_LOSS as a,
2012
2117
  pajekImporter as b,
2013
2118
  pajekExporter as p
2014
2119
  };
2015
- //# sourceMappingURL=importer-CpCpfbxr.js.map
2120
+ //# sourceMappingURL=importer-D5pAsweZ.js.map