@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.
- package/README.md +29 -7
- package/dist/chunks/{escape-DyI8JofU.js → escape-CKied3Ri.js} +16 -10
- package/dist/chunks/escape-CKied3Ri.js.map +1 -0
- package/dist/chunks/{importer-DbnGYr3_.js → importer-C6QcIRIb.js} +129 -39
- package/dist/chunks/importer-C6QcIRIb.js.map +1 -0
- package/dist/chunks/{importer-CpCpfbxr.js → importer-D5pAsweZ.js} +136 -31
- package/dist/chunks/importer-D5pAsweZ.js.map +1 -0
- package/dist/chunks/{importer-GozH8DkN.js → importer-DbMrAR_w.js} +10 -4
- package/dist/chunks/importer-DbMrAR_w.js.map +1 -0
- package/dist/chunks/{importer-CQnJuWJw.js → importer-DkzjTvHc.js} +82 -40
- package/dist/chunks/importer-DkzjTvHc.js.map +1 -0
- package/dist/chunks/{records-CGpxszm1.js → records-BKSMowhR.js} +3 -3
- package/dist/chunks/{records-CGpxszm1.js.map → records-BKSMowhR.js.map} +1 -1
- package/dist/chunks/{text-CajMdVFy.js → text-Dr0Ifpag.js} +2 -2
- package/dist/chunks/{text-CajMdVFy.js.map → text-Dr0Ifpag.js.map} +1 -1
- package/dist/chunks/{writer-DxSKC7TL.js → writer-BdMak4_J.js} +341 -112
- package/dist/chunks/writer-BdMak4_J.js.map +1 -0
- package/dist/csv.js +24 -6
- package/dist/csv.js.map +1 -1
- package/dist/dot.js +1 -1
- package/dist/gexf.js +42 -10
- package/dist/gexf.js.map +1 -1
- package/dist/gml.js +69 -25
- package/dist/gml.js.map +1 -1
- package/dist/graph-io.js +186 -129
- package/dist/graph-io.js.map +1 -1
- package/dist/graphml.js +1 -1
- package/dist/json.js +1 -1
- package/dist/neo4j.js +10 -4
- package/dist/neo4j.js.map +1 -1
- package/dist/pajek.js +1 -1
- 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 +5 -4
- package/dist/src/common/escape.d.ts.map +1 -1
- package/dist/src/common/escape.js +6 -5
- package/dist/src/common/escape.js.map +1 -1
- package/dist/src/common/format.d.ts +3 -3
- package/dist/src/common/format.js +5 -5
- package/dist/src/common/format.js.map +1 -1
- package/dist/src/common/input.d.ts +24 -6
- package/dist/src/common/input.d.ts.map +1 -1
- package/dist/src/common/input.js +259 -23
- package/dist/src/common/input.js.map +1 -1
- package/dist/src/common/options.d.ts +2 -0
- package/dist/src/common/options.d.ts.map +1 -1
- package/dist/src/common/options.js +17 -0
- package/dist/src/common/options.js.map +1 -1
- package/dist/src/common/text.js +4 -4
- package/dist/src/common/text.js.map +1 -1
- package/dist/src/common/weights.d.ts.map +1 -1
- package/dist/src/common/weights.js +8 -0
- package/dist/src/common/weights.js.map +1 -1
- package/dist/src/common/xml.d.ts +7 -0
- package/dist/src/common/xml.d.ts.map +1 -1
- package/dist/src/common/xml.js +12 -0
- package/dist/src/common/xml.js.map +1 -1
- package/dist/src/formats/csv/exporter.d.ts +5 -1
- package/dist/src/formats/csv/exporter.d.ts.map +1 -1
- package/dist/src/formats/csv/exporter.js +8 -1
- package/dist/src/formats/csv/exporter.js.map +1 -1
- package/dist/src/formats/csv/importer.d.ts.map +1 -1
- package/dist/src/formats/csv/importer.js +1 -0
- package/dist/src/formats/csv/importer.js.map +1 -1
- package/dist/src/formats/csv/index.d.ts +6 -0
- package/dist/src/formats/csv/index.d.ts.map +1 -1
- package/dist/src/formats/csv/index.js +7 -1
- package/dist/src/formats/csv/index.js.map +1 -1
- package/dist/src/formats/csv/records.js +1 -1
- package/dist/src/formats/csv/records.js.map +1 -1
- package/dist/src/formats/dot/exporter.d.ts +1 -1
- package/dist/src/formats/dot/exporter.d.ts.map +1 -1
- package/dist/src/formats/dot/exporter.js +3 -3
- package/dist/src/formats/dot/exporter.js.map +1 -1
- package/dist/src/formats/dot/importer.d.ts +6 -0
- package/dist/src/formats/dot/importer.d.ts.map +1 -1
- package/dist/src/formats/dot/importer.js +151 -24
- package/dist/src/formats/dot/importer.js.map +1 -1
- package/dist/src/formats/gexf/exporter.d.ts.map +1 -1
- package/dist/src/formats/gexf/exporter.js +32 -7
- package/dist/src/formats/gexf/exporter.js.map +1 -1
- package/dist/src/formats/gexf/importer.d.ts.map +1 -1
- package/dist/src/formats/gexf/importer.js +2 -2
- package/dist/src/formats/gexf/importer.js.map +1 -1
- package/dist/src/formats/gexf/index.d.ts +6 -0
- package/dist/src/formats/gexf/index.d.ts.map +1 -1
- package/dist/src/formats/gexf/index.js +7 -1
- package/dist/src/formats/gexf/index.js.map +1 -1
- package/dist/src/formats/gml/importer.d.ts +2 -2
- package/dist/src/formats/gml/importer.d.ts.map +1 -1
- package/dist/src/formats/gml/importer.js +66 -25
- package/dist/src/formats/gml/importer.js.map +1 -1
- package/dist/src/formats/gml/index.d.ts +7 -1
- package/dist/src/formats/gml/index.d.ts.map +1 -1
- package/dist/src/formats/gml/index.js +8 -2
- package/dist/src/formats/gml/index.js.map +1 -1
- package/dist/src/formats/graphml/constants.d.ts +6 -0
- package/dist/src/formats/graphml/constants.d.ts.map +1 -1
- package/dist/src/formats/graphml/constants.js +7 -1
- package/dist/src/formats/graphml/constants.js.map +1 -1
- package/dist/src/formats/graphml/importer.d.ts.map +1 -1
- package/dist/src/formats/graphml/importer.js +2 -2
- package/dist/src/formats/graphml/importer.js.map +1 -1
- package/dist/src/formats/json/exporter.d.ts.map +1 -1
- package/dist/src/formats/json/exporter.js +14 -5
- package/dist/src/formats/json/exporter.js.map +1 -1
- package/dist/src/formats/json/importer.d.ts +8 -0
- package/dist/src/formats/json/importer.d.ts.map +1 -1
- package/dist/src/formats/json/importer.js +84 -37
- package/dist/src/formats/json/importer.js.map +1 -1
- package/dist/src/formats/neo4j/importer.js +1 -1
- package/dist/src/formats/neo4j/importer.js.map +1 -1
- package/dist/src/formats/neo4j/index.d.ts +6 -0
- package/dist/src/formats/neo4j/index.d.ts.map +1 -1
- package/dist/src/formats/neo4j/index.js +7 -1
- package/dist/src/formats/neo4j/index.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 +13 -2
- package/dist/src/formats/pajek/exporter.js.map +1 -1
- package/dist/src/formats/pajek/importer.d.ts +8 -2
- package/dist/src/formats/pajek/importer.d.ts.map +1 -1
- package/dist/src/formats/pajek/importer.js +122 -26
- package/dist/src/formats/pajek/importer.js.map +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/registry.d.ts +26 -0
- package/dist/src/registry.d.ts.map +1 -1
- package/dist/src/registry.js +101 -35
- package/dist/src/registry.js.map +1 -1
- package/dist/src/sniff.d.ts +1 -1
- package/dist/src/sniff.d.ts.map +1 -1
- package/dist/src/sniff.js +6 -1
- package/dist/src/sniff.js.map +1 -1
- package/dist/src/types.d.ts +22 -3
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/types.js.map +1 -1
- package/package.json +4 -3
- package/src/common/codes.ts +9 -0
- package/src/common/escape.ts +6 -5
- package/src/common/format.ts +5 -5
- package/src/common/input.ts +293 -22
- package/src/common/options.ts +24 -0
- package/src/common/text.ts +4 -4
- package/src/common/weights.ts +9 -0
- package/src/common/xml.ts +14 -0
- package/src/formats/csv/exporter.ts +12 -1
- package/src/formats/csv/importer.ts +1 -0
- package/src/formats/csv/index.ts +9 -0
- package/src/formats/csv/records.ts +1 -1
- package/src/formats/dot/exporter.ts +3 -3
- package/src/formats/dot/importer.ts +172 -32
- package/src/formats/gexf/exporter.ts +38 -7
- package/src/formats/gexf/importer.ts +12 -2
- package/src/formats/gexf/index.ts +9 -0
- package/src/formats/gml/importer.ts +75 -22
- package/src/formats/gml/index.ts +10 -1
- package/src/formats/graphml/constants.ts +9 -0
- package/src/formats/graphml/importer.ts +9 -2
- package/src/formats/json/exporter.ts +14 -5
- package/src/formats/json/importer.ts +104 -36
- package/src/formats/neo4j/importer.ts +1 -1
- package/src/formats/neo4j/index.ts +9 -0
- package/src/formats/pajek/exporter.ts +19 -2
- package/src/formats/pajek/importer.ts +145 -28
- package/src/index.ts +1 -0
- package/src/registry.ts +131 -40
- package/src/sniff.ts +6 -1
- package/src/types.ts +26 -3
- package/dist/chunks/escape-DyI8JofU.js.map +0 -1
- package/dist/chunks/importer-CQnJuWJw.js.map +0 -1
- package/dist/chunks/importer-CpCpfbxr.js.map +0 -1
- package/dist/chunks/importer-DbnGYr3_.js.map +0 -1
- package/dist/chunks/importer-GozH8DkN.js.map +0 -1
- package/dist/chunks/writer-DxSKC7TL.js.map +0 -1
- package/dist/tsconfig.build.tsbuildinfo +0 -1
package/dist/gml.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
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 {
|
|
3
|
+
import { j as decodeGmlString, k as quoteGmlString } from "./chunks/escape-CKied3Ri.js";
|
|
4
4
|
const TOKEN_WORD = 0;
|
|
5
5
|
const TOKEN_INT = 1;
|
|
6
6
|
const TOKEN_REAL = 2;
|
|
@@ -1336,7 +1336,7 @@ function* lazyParts(snapshot, options) {
|
|
|
1336
1336
|
yield* gmlParts(contextOf(snapshot, options));
|
|
1337
1337
|
}
|
|
1338
1338
|
const NO_GRAPH_CODE = NO_GRAPH_CODE$1;
|
|
1339
|
-
const SECOND_GRAPH_CODE =
|
|
1339
|
+
const SECOND_GRAPH_CODE = MULTIPLE_GRAPHS_CODE;
|
|
1340
1340
|
const MISSING_ID_CODE = MISSING_ID_CODE$1;
|
|
1341
1341
|
const MISSING_LABEL_CODE = "E_GML_MISSING_LABEL";
|
|
1342
1342
|
const MISSING_ENDPOINT_CODE = MISSING_ENDPOINT_CODE$1;
|
|
@@ -1395,9 +1395,12 @@ class GmlImport {
|
|
|
1395
1395
|
* @param report - the report
|
|
1396
1396
|
* @param options - the resolved common options
|
|
1397
1397
|
* @param format - the format-specific options
|
|
1398
|
+
* @param which - which `graph [ ... ]` block to read (0: the first)
|
|
1398
1399
|
*/
|
|
1399
|
-
constructor(sink, report, options, format) {
|
|
1400
|
+
constructor(sink, report, options, format, which = 0) {
|
|
1401
|
+
this.which = which;
|
|
1400
1402
|
this.tokens = null;
|
|
1403
|
+
this.graphCount = 0;
|
|
1401
1404
|
this.resolver = null;
|
|
1402
1405
|
this.nodeSchema = /* @__PURE__ */ new Map();
|
|
1403
1406
|
this.edgeSchema = /* @__PURE__ */ new Map();
|
|
@@ -1434,19 +1437,11 @@ class GmlImport {
|
|
|
1434
1437
|
this.coercer = new IdCoercer(options.ids);
|
|
1435
1438
|
}
|
|
1436
1439
|
/**
|
|
1437
|
-
* Run the import over a text.
|
|
1438
|
-
* @param
|
|
1440
|
+
* Run the import over the tokens of a text.
|
|
1441
|
+
* @param tokens - the whole text, tokenized (tokenize())
|
|
1439
1442
|
*/
|
|
1440
|
-
run(
|
|
1441
|
-
|
|
1442
|
-
try {
|
|
1443
|
-
this.tokens = tokenizeGml(text);
|
|
1444
|
-
} catch (err) {
|
|
1445
|
-
if (err instanceof GmlSyntaxError) {
|
|
1446
|
-
report.fail(err.code, err.message, { line: err.line });
|
|
1447
|
-
}
|
|
1448
|
-
throw err;
|
|
1449
|
-
}
|
|
1443
|
+
run(tokens) {
|
|
1444
|
+
this.tokens = tokens;
|
|
1450
1445
|
this.scan();
|
|
1451
1446
|
this.push();
|
|
1452
1447
|
}
|
|
@@ -1462,13 +1457,10 @@ class GmlImport {
|
|
|
1462
1457
|
const v = p + 1;
|
|
1463
1458
|
const record = t.kind[v] === TOKEN_OPEN;
|
|
1464
1459
|
if (key === "graph" && record) {
|
|
1465
|
-
if (this.
|
|
1466
|
-
this.
|
|
1467
|
-
|
|
1468
|
-
});
|
|
1460
|
+
if (this.graphCount++ === this.which) {
|
|
1461
|
+
this.graphOpen = v;
|
|
1462
|
+
this.scanGraph(v);
|
|
1469
1463
|
}
|
|
1470
|
-
this.graphOpen = v;
|
|
1471
|
-
this.scanGraph(v);
|
|
1472
1464
|
} else if (key === "Creator" && !record && this.creatorToken < 0) {
|
|
1473
1465
|
this.creatorToken = v;
|
|
1474
1466
|
} else if (key === "Version" && !record && this.versionToken < 0) {
|
|
@@ -2559,22 +2551,74 @@ const gmlImporter = Object.freeze({
|
|
|
2559
2551
|
const report = new ImportReportBuilder("gml", resolved.errorLimit);
|
|
2560
2552
|
reportSinkOptions(sink, options, report);
|
|
2561
2553
|
reportUnusedOptions(options, report, USED_OPTIONS);
|
|
2562
|
-
const
|
|
2554
|
+
const tokens = tokenize(await readText(input, report, resolved), report);
|
|
2563
2555
|
throwIfAborted(resolved.signal);
|
|
2564
|
-
new GmlImport(sink, report, resolved, options)
|
|
2556
|
+
const gml = new GmlImport(sink, report, resolved, options);
|
|
2557
|
+
gml.run(tokens);
|
|
2558
|
+
if (gml.graphCount > 1) {
|
|
2559
|
+
report.warning(
|
|
2560
|
+
"unsupported",
|
|
2561
|
+
SECOND_GRAPH_CODE,
|
|
2562
|
+
`the input holds ${gml.graphCount - 1} more graph block(s) after the first; import() reads the first, importAll() reads every one`
|
|
2563
|
+
);
|
|
2564
|
+
}
|
|
2565
2565
|
throwIfAborted(resolved.signal);
|
|
2566
2566
|
return report.finish();
|
|
2567
|
+
},
|
|
2568
|
+
/**
|
|
2569
|
+
* Read every `graph [ ... ]` block of a GML text, each into its own sink; the top-level keys
|
|
2570
|
+
* (Creator, Version, ...) apply to each.
|
|
2571
|
+
* @param input - the text, bytes or stream
|
|
2572
|
+
* @param sinkFor - the sink of the graph with this index, called before its first push
|
|
2573
|
+
* @param options - format-specific and common options
|
|
2574
|
+
* @returns one report per graph block
|
|
2575
|
+
*/
|
|
2576
|
+
async importAll(input, sinkFor, options) {
|
|
2577
|
+
const resolved = resolveImportOptions(options, FORMAT_DEFAULTS);
|
|
2578
|
+
const first = new ImportReportBuilder("gml", resolved.errorLimit);
|
|
2579
|
+
reportUnusedOptions(options, first, USED_OPTIONS);
|
|
2580
|
+
const tokens = tokenize(await readText(input, first, resolved), first);
|
|
2581
|
+
const reports = [];
|
|
2582
|
+
let count = 1;
|
|
2583
|
+
for (let i = 0; i < count; i++) {
|
|
2584
|
+
throwIfAborted(resolved.signal);
|
|
2585
|
+
const report = i === 0 ? first : new ImportReportBuilder("gml", resolved.errorLimit);
|
|
2586
|
+
const sink = sinkFor(i);
|
|
2587
|
+
reportSinkOptions(sink, options, report);
|
|
2588
|
+
const gml = new GmlImport(sink, report, resolved, options, i);
|
|
2589
|
+
gml.run(tokens);
|
|
2590
|
+
count = gml.graphCount;
|
|
2591
|
+
reports.push(report.finish());
|
|
2592
|
+
}
|
|
2593
|
+
throwIfAborted(resolved.signal);
|
|
2594
|
+
return reports;
|
|
2567
2595
|
}
|
|
2568
2596
|
});
|
|
2597
|
+
function tokenize(text, report) {
|
|
2598
|
+
try {
|
|
2599
|
+
return tokenizeGml(text);
|
|
2600
|
+
} catch (err) {
|
|
2601
|
+
if (err instanceof GmlSyntaxError) {
|
|
2602
|
+
report.fail(err.code, err.message, { line: err.line });
|
|
2603
|
+
}
|
|
2604
|
+
throw err;
|
|
2605
|
+
}
|
|
2606
|
+
}
|
|
2569
2607
|
const GML_ISSUE = Object.freeze({
|
|
2570
2608
|
/** A grammar violation: an untokenisable bare token, an unclosed string or `[`, a stray `]`, a key without a value (fatal). */
|
|
2571
2609
|
SYNTAX: SYNTAX_CODE,
|
|
2572
2610
|
/** The input holds invalid UTF-8 (fatal). */
|
|
2573
2611
|
INVALID_UTF8: INVALID_UTF8_CODE,
|
|
2612
|
+
/** Invalid bytes in the encoding a BOM, a declaration or the encoding option chose (fatal). */
|
|
2613
|
+
INVALID_ENCODING: INVALID_ENCODING_CODE,
|
|
2614
|
+
/** Bytes that are not UTF-8 and declare no encoding were read as windows-1252. */
|
|
2615
|
+
ENCODING_FALLBACK: ENCODING_FALLBACK_CODE,
|
|
2616
|
+
/** A declared encoding the platform cannot decode was ignored. */
|
|
2617
|
+
UNKNOWN_ENCODING: UNKNOWN_ENCODING_CODE,
|
|
2574
2618
|
/** No `graph [` block (fatal). */
|
|
2575
2619
|
NO_GRAPH: NO_GRAPH_CODE,
|
|
2576
2620
|
/** More than one `graph` block (fatal). */
|
|
2577
|
-
|
|
2621
|
+
MULTIPLE_GRAPHS: SECOND_GRAPH_CODE,
|
|
2578
2622
|
/** A node without an `id`. */
|
|
2579
2623
|
MISSING_ID: MISSING_ID_CODE,
|
|
2580
2624
|
/** A node without a `label` under nodeIdFrom "label". */
|