@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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GraphFormatError, INVALID_INDEX } from "@graphty/graph-format";
|
|
2
|
-
import {
|
|
2
|
+
import { ac as capabilities, L as LOSS, ax as joinText, ak as encodeChunks, ad as checkCapabilities, aE as resolveExportOptions, aJ as countMixedEdges, al as explicitWeights, az as pairFolding, an as formatF32, ao as formatF64, a5 as UNKNOWN_ENCODING_CODE, n as ENCODING_FALLBACK_CODE, s as INVALID_ENCODING_CODE, u as INVALID_UTF8_CODE, P as OPTION_IGNORED_CODE, Y as SINK_OPTION_CODE, H as HYPEREDGE_CODE, A as MULTIPLE_GRAPHS_CODE, o as ID_MERGED_CODE, i as DUPLICATE_EDGE_ID_CODE, k as DUPLICATE_NODE_CODE, a6 as UNKNOWN_PARENT_CODE, M as MISSING_ENDPOINT_CODE, y as MISSING_ID_CODE, $ as SYNTAX_CODE, m as EMPTY_INPUT_CODE, aF as resolveImportOptions, I as ImportReportBuilder, aB as readText, aC as reportSinkOptions, aD as reportUnusedOptions, a as throwIfAborted, v as IdCoercer, l as DirectionResolver, aK as weightFromValue, aL as uniqueColumnName } from "./writer-BdMak4_J.js";
|
|
3
3
|
const JSON_DIALECTS = Object.freeze([
|
|
4
4
|
"node-link",
|
|
5
5
|
"d3",
|
|
@@ -293,7 +293,7 @@ function numberText(value, f32, nonfinite) {
|
|
|
293
293
|
if (f32) {
|
|
294
294
|
return formatF32(value);
|
|
295
295
|
}
|
|
296
|
-
return
|
|
296
|
+
return formatF64(value);
|
|
297
297
|
}
|
|
298
298
|
function valueText(value, f32, nonfinite) {
|
|
299
299
|
switch (typeof value) {
|
|
@@ -673,11 +673,18 @@ function inferenceNotes(ctx, column, domain, setRows) {
|
|
|
673
673
|
return;
|
|
674
674
|
}
|
|
675
675
|
const { data } = column;
|
|
676
|
+
let finite = 0;
|
|
676
677
|
for (let r = 0; r < column.length; r++) {
|
|
677
|
-
if (column.isSet(r) &&
|
|
678
|
-
|
|
678
|
+
if (column.isSet(r) && Number.isFinite(data[r])) {
|
|
679
|
+
if (!Number.isInteger(data[r])) {
|
|
680
|
+
return;
|
|
681
|
+
}
|
|
682
|
+
finite++;
|
|
679
683
|
}
|
|
680
684
|
}
|
|
685
|
+
if (finite === 0) {
|
|
686
|
+
return;
|
|
687
|
+
}
|
|
681
688
|
ctx.note(
|
|
682
689
|
LOSS.INTEGRAL_F64,
|
|
683
690
|
`${domain} column "${column.meta.name}" is f64 with integral values only; JSON declares no types and it reads back as i32`,
|
|
@@ -1362,7 +1369,15 @@ const JSON_ISSUE = Object.freeze({
|
|
|
1362
1369
|
/** A builder-policy option (addMissingNodes, duplicateEdges, selfLoops, weightDtype) differs from the sink's (the shared W_SINK_OPTION). */
|
|
1363
1370
|
SINK_OPTION: SINK_OPTION_CODE,
|
|
1364
1371
|
/** A common option the dialect has no use for (nodeIdFrom outside node-link, long, restoreMangledIds). */
|
|
1365
|
-
OPTION_IGNORED: OPTION_IGNORED_CODE
|
|
1372
|
+
OPTION_IGNORED: OPTION_IGNORED_CODE,
|
|
1373
|
+
/** The input holds invalid UTF-8 (fatal). */
|
|
1374
|
+
INVALID_UTF8: INVALID_UTF8_CODE,
|
|
1375
|
+
/** Invalid bytes in the encoding a BOM, a declaration or the encoding option chose (fatal). */
|
|
1376
|
+
INVALID_ENCODING: INVALID_ENCODING_CODE,
|
|
1377
|
+
/** Bytes that are not UTF-8 and declare no encoding were read as windows-1252. */
|
|
1378
|
+
ENCODING_FALLBACK: ENCODING_FALLBACK_CODE,
|
|
1379
|
+
/** A declared encoding the platform cannot decode was ignored. */
|
|
1380
|
+
UNKNOWN_ENCODING: UNKNOWN_ENCODING_CODE
|
|
1366
1381
|
});
|
|
1367
1382
|
const USED_OPTIONS = /* @__PURE__ */ new Set([
|
|
1368
1383
|
"ids",
|
|
@@ -2565,11 +2580,11 @@ function jgfGraphOf(ctx, root) {
|
|
|
2565
2580
|
if (graphs.length === 0) {
|
|
2566
2581
|
report.fail(JSON_ISSUE.SHAPE, "a JGF document needs a graph object or a non-empty graphs array");
|
|
2567
2582
|
}
|
|
2568
|
-
if (graphs.length > 1) {
|
|
2583
|
+
if (graphs.length > 1 && ctx.json.all !== true) {
|
|
2569
2584
|
report.warning(
|
|
2570
2585
|
"unsupported",
|
|
2571
2586
|
JSON_ISSUE.MULTIPLE_GRAPHS,
|
|
2572
|
-
`the document holds ${graphs.length} graphs; only graphs[${ctx.json.graphIndex}] is read`,
|
|
2587
|
+
`the document holds ${graphs.length} graphs; only graphs[${ctx.json.graphIndex}] is read (${graphs.length - 1} skipped), importAll() reads every one`,
|
|
2573
2588
|
{ element: "graphs" }
|
|
2574
2589
|
);
|
|
2575
2590
|
}
|
|
@@ -2939,41 +2954,68 @@ const jsonImporter = Object.freeze({
|
|
|
2939
2954
|
const text = await readText(input, report, resolved);
|
|
2940
2955
|
const root = parseDocument(text, report);
|
|
2941
2956
|
const dialect = detectDialect(root, json.dialect, report);
|
|
2942
|
-
|
|
2943
|
-
reportSinkOptions(sink, options, report);
|
|
2944
|
-
reportUnusedOptions(options, report, USED_OPTIONS);
|
|
2945
|
-
if (dialect === "cytoscape") {
|
|
2946
|
-
importCytoscape(ctx, root);
|
|
2947
|
-
throwIfAborted(resolved.signal);
|
|
2948
|
-
return report.finish();
|
|
2949
|
-
}
|
|
2950
|
-
const doc = isJsonObject(root) ? root : report.fail(JSON_ISSUE.SHAPE, `a ${dialect} document must be a JSON object, found ${describe(root)}`);
|
|
2951
|
-
switch (dialect) {
|
|
2952
|
-
case "node-link":
|
|
2953
|
-
case "d3":
|
|
2954
|
-
importNodeLink(ctx, doc, dialect);
|
|
2955
|
-
break;
|
|
2956
|
-
case "jgf":
|
|
2957
|
-
importJgf(ctx, doc);
|
|
2958
|
-
break;
|
|
2959
|
-
case "graphology":
|
|
2960
|
-
importGraphology(ctx, doc);
|
|
2961
|
-
break;
|
|
2962
|
-
case "vis":
|
|
2963
|
-
importVis(ctx, doc);
|
|
2964
|
-
break;
|
|
2965
|
-
default: {
|
|
2966
|
-
const name = dialect;
|
|
2967
|
-
throw new GraphFormatError("E_UNSUPPORTED", `unknown dialect ${name}`, {
|
|
2968
|
-
option: "dialect",
|
|
2969
|
-
found: name
|
|
2970
|
-
});
|
|
2971
|
-
}
|
|
2972
|
-
}
|
|
2973
|
-
throwIfAborted(resolved.signal);
|
|
2957
|
+
readGraph(root, dialect, sink, report, resolved, json, options);
|
|
2974
2958
|
return report.finish();
|
|
2959
|
+
},
|
|
2960
|
+
/**
|
|
2961
|
+
* Read every graph of a JSON document: each entry of a JGF `graphs` array into its own sink;
|
|
2962
|
+
* any other document holds one graph.
|
|
2963
|
+
* @param input - the text, bytes or stream
|
|
2964
|
+
* @param sinkFor - the sink of the graph with this index, called before its first push
|
|
2965
|
+
* @param options - format-specific and common options
|
|
2966
|
+
* @returns one report per graph
|
|
2967
|
+
*/
|
|
2968
|
+
async importAll(input, sinkFor, options) {
|
|
2969
|
+
const resolved = resolveImportOptions(options, FORMAT_DEFAULTS);
|
|
2970
|
+
const json = resolveJsonOptions(options);
|
|
2971
|
+
const first = new ImportReportBuilder("json", resolved.errorLimit);
|
|
2972
|
+
const text = await readText(input, first, resolved);
|
|
2973
|
+
const root = parseDocument(text, first);
|
|
2974
|
+
const dialect = detectDialect(root, json.dialect, first);
|
|
2975
|
+
const graphs = dialect === "jgf" && isJsonObject(root) && !isJsonObject(root.graph) && Array.isArray(root.graphs) ? root.graphs.length : 1;
|
|
2976
|
+
const reports = [];
|
|
2977
|
+
for (let i = 0; i < Math.max(graphs, 1); i++) {
|
|
2978
|
+
const report = i === 0 ? first : new ImportReportBuilder("json", resolved.errorLimit);
|
|
2979
|
+
readGraph(root, dialect, sinkFor(i), report, resolved, { ...json, graphIndex: i, all: true }, options);
|
|
2980
|
+
reports.push(report.finish());
|
|
2981
|
+
}
|
|
2982
|
+
return reports;
|
|
2975
2983
|
}
|
|
2976
2984
|
});
|
|
2985
|
+
function readGraph(root, dialect, sink, report, resolved, json, options) {
|
|
2986
|
+
const ctx = new ImportContext(sink, report, resolved, json, options?.defaultDirected !== void 0);
|
|
2987
|
+
reportSinkOptions(sink, options, report);
|
|
2988
|
+
reportUnusedOptions(options, report, USED_OPTIONS);
|
|
2989
|
+
if (dialect === "cytoscape") {
|
|
2990
|
+
importCytoscape(ctx, root);
|
|
2991
|
+
throwIfAborted(resolved.signal);
|
|
2992
|
+
return;
|
|
2993
|
+
}
|
|
2994
|
+
const doc = isJsonObject(root) ? root : report.fail(JSON_ISSUE.SHAPE, `a ${dialect} document must be a JSON object, found ${describe(root)}`);
|
|
2995
|
+
switch (dialect) {
|
|
2996
|
+
case "node-link":
|
|
2997
|
+
case "d3":
|
|
2998
|
+
importNodeLink(ctx, doc, dialect);
|
|
2999
|
+
break;
|
|
3000
|
+
case "jgf":
|
|
3001
|
+
importJgf(ctx, doc);
|
|
3002
|
+
break;
|
|
3003
|
+
case "graphology":
|
|
3004
|
+
importGraphology(ctx, doc);
|
|
3005
|
+
break;
|
|
3006
|
+
case "vis":
|
|
3007
|
+
importVis(ctx, doc);
|
|
3008
|
+
break;
|
|
3009
|
+
default: {
|
|
3010
|
+
const name = dialect;
|
|
3011
|
+
throw new GraphFormatError("E_UNSUPPORTED", `unknown dialect ${name}`, {
|
|
3012
|
+
option: "dialect",
|
|
3013
|
+
found: name
|
|
3014
|
+
});
|
|
3015
|
+
}
|
|
3016
|
+
}
|
|
3017
|
+
throwIfAborted(resolved.signal);
|
|
3018
|
+
}
|
|
2977
3019
|
export {
|
|
2978
3020
|
JSON_DIALECTS as J,
|
|
2979
3021
|
JSON_ISSUE as a,
|
|
@@ -2984,4 +3026,4 @@ export {
|
|
|
2984
3026
|
jsonCapabilities as j,
|
|
2985
3027
|
sniffJsonDialect as s
|
|
2986
3028
|
};
|
|
2987
|
-
//# sourceMappingURL=importer-
|
|
3029
|
+
//# sourceMappingURL=importer-DkzjTvHc.js.map
|