@graphty/graph-io 0.3.16 → 0.3.18
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/LICENSE +1 -1
- package/README.md +29 -3
- package/dist/chunks/{escape-D1f9-cwf.js → escape-D-gZWO26.js} +3 -2
- package/dist/chunks/{escape-D1f9-cwf.js.map → escape-D-gZWO26.js.map} +1 -1
- package/dist/chunks/{importer-D7ZcGCeb.js → importer-Br_QeAeE.js} +4 -3
- package/dist/chunks/{importer-D7ZcGCeb.js.map → importer-Br_QeAeE.js.map} +1 -1
- package/dist/chunks/{importer-CXEiicAN.js → importer-DHagxvDD.js} +4 -3
- package/dist/chunks/{importer-CXEiicAN.js.map → importer-DHagxvDD.js.map} +1 -1
- package/dist/chunks/{importer-C7mnGdr_.js → importer-Du5crN9l.js} +510 -26
- package/dist/chunks/importer-Du5crN9l.js.map +1 -0
- package/dist/chunks/importer-aNJfe0qu.js +1614 -0
- package/dist/chunks/importer-aNJfe0qu.js.map +1 -0
- package/dist/chunks/{importer-B8lsjFWx.js → importer-d0uQxFp6.js} +4 -3
- package/dist/chunks/{importer-B8lsjFWx.js.map → importer-d0uQxFp6.js.map} +1 -1
- package/dist/chunks/ontology-BnrJ4I98.js +113 -0
- package/dist/chunks/ontology-BnrJ4I98.js.map +1 -0
- package/dist/chunks/{records-IHsCfv7s.js → records-Bk9jgodz.js} +2 -2
- package/dist/chunks/{records-IHsCfv7s.js.map → records-Bk9jgodz.js.map} +1 -1
- package/dist/chunks/{writer-BtWpUaiH.js → report-BOk0p5y8.js} +181 -912
- package/dist/chunks/report-BOk0p5y8.js.map +1 -0
- package/dist/chunks/writer-GAdltGmC.js +827 -0
- package/dist/chunks/writer-GAdltGmC.js.map +1 -0
- package/dist/csv.js +4 -3
- package/dist/csv.js.map +1 -1
- package/dist/dot.js +1 -1
- package/dist/gexf.js +3 -2
- package/dist/gexf.js.map +1 -1
- package/dist/gml.js +3 -2
- package/dist/gml.js.map +1 -1
- package/dist/graph-io.js +191 -134
- package/dist/graph-io.js.map +1 -1
- package/dist/graphml.js +1 -1
- package/dist/json.js +1 -1
- package/dist/neo4j.js +4 -3
- package/dist/neo4j.js.map +1 -1
- package/dist/obo.d.ts +1 -0
- package/dist/obo.js +6 -0
- package/dist/obo.js.map +1 -0
- package/dist/pajek.js +1 -1
- package/dist/src/common/codes.d.ts +43 -0
- package/dist/src/common/codes.d.ts.map +1 -1
- package/dist/src/common/codes.js +43 -0
- package/dist/src/common/codes.js.map +1 -1
- package/dist/src/common/input.d.ts +9 -0
- package/dist/src/common/input.d.ts.map +1 -1
- package/dist/src/common/input.js +16 -0
- package/dist/src/common/input.js.map +1 -1
- package/dist/src/common/ontology.d.ts +59 -0
- package/dist/src/common/ontology.d.ts.map +1 -0
- package/dist/src/common/ontology.js +147 -0
- package/dist/src/common/ontology.js.map +1 -0
- package/dist/src/common/options.d.ts +12 -1
- package/dist/src/common/options.d.ts.map +1 -1
- package/dist/src/common/options.js +51 -1
- package/dist/src/common/options.js.map +1 -1
- package/dist/src/formats/json/dialect.d.ts +8 -6
- package/dist/src/formats/json/dialect.d.ts.map +1 -1
- package/dist/src/formats/json/dialect.js +26 -3
- package/dist/src/formats/json/dialect.js.map +1 -1
- package/dist/src/formats/json/importer.d.ts +324 -7
- package/dist/src/formats/json/importer.d.ts.map +1 -1
- package/dist/src/formats/json/importer.js +154 -23
- package/dist/src/formats/json/importer.js.map +1 -1
- package/dist/src/formats/json/obographs.d.ts +21 -0
- package/dist/src/formats/json/obographs.d.ts.map +1 -0
- package/dist/src/formats/json/obographs.js +476 -0
- package/dist/src/formats/json/obographs.js.map +1 -0
- package/dist/src/formats/obo/importer.d.ts +90 -0
- package/dist/src/formats/obo/importer.d.ts.map +1 -0
- package/dist/src/formats/obo/importer.js +1248 -0
- package/dist/src/formats/obo/importer.js.map +1 -0
- package/dist/src/formats/obo/index.d.ts +7 -0
- package/dist/src/formats/obo/index.d.ts.map +1 -0
- package/dist/src/formats/obo/index.js +7 -0
- package/dist/src/formats/obo/index.js.map +1 -0
- package/dist/src/formats/obo/syntax.d.ts +121 -0
- package/dist/src/formats/obo/syntax.d.ts.map +1 -0
- package/dist/src/formats/obo/syntax.js +424 -0
- package/dist/src/formats/obo/syntax.js.map +1 -0
- package/dist/src/index.d.ts +5 -4
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +4 -3
- package/dist/src/index.js.map +1 -1
- package/dist/src/registry.d.ts +21 -3
- package/dist/src/registry.d.ts.map +1 -1
- package/dist/src/registry.js +32 -1
- 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 +23 -3
- package/dist/src/sniff.js.map +1 -1
- package/dist/src/types.d.ts +31 -0
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/types.js.map +1 -1
- package/package.json +6 -1
- package/src/common/codes.ts +58 -0
- package/src/common/input.ts +16 -0
- package/src/common/ontology.ts +169 -0
- package/src/common/options.ts +78 -2
- package/src/formats/json/dialect.ts +37 -7
- package/src/formats/json/importer.ts +206 -28
- package/src/formats/json/obographs.ts +563 -0
- package/src/formats/obo/importer.ts +1695 -0
- package/src/formats/obo/index.ts +7 -0
- package/src/formats/obo/syntax.ts +466 -0
- package/src/index.ts +6 -0
- package/src/registry.ts +38 -3
- package/src/sniff.ts +35 -5
- package/src/types.ts +40 -1
- package/dist/chunks/importer-C7mnGdr_.js.map +0 -1
- package/dist/chunks/writer-BtWpUaiH.js.map +0 -1
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
const OBO_NODE_COLUMNS = Object.freeze({
|
|
2
|
+
type: { dtype: "dict" },
|
|
3
|
+
name: { dtype: "string", role: "label" },
|
|
4
|
+
namespace: { dtype: "dict" },
|
|
5
|
+
def: { dtype: "string" },
|
|
6
|
+
"def.xrefs": { dtype: "list" },
|
|
7
|
+
comment: { dtype: "string" },
|
|
8
|
+
synonym: { dtype: "json" },
|
|
9
|
+
xref: { dtype: "list" },
|
|
10
|
+
"xref.descriptions": { dtype: "json" },
|
|
11
|
+
alt_id: { dtype: "list" },
|
|
12
|
+
subset: { dtype: "list" },
|
|
13
|
+
replaced_by: { dtype: "list" },
|
|
14
|
+
consider: { dtype: "list" },
|
|
15
|
+
is_obsolete: { dtype: "bool" },
|
|
16
|
+
is_anonymous: { dtype: "bool" },
|
|
17
|
+
builtin: { dtype: "bool" },
|
|
18
|
+
created_by: { dtype: "string" },
|
|
19
|
+
creation_date: { dtype: "string" },
|
|
20
|
+
intersection_of: { dtype: "json" },
|
|
21
|
+
union_of: { dtype: "list" },
|
|
22
|
+
equivalent_to: { dtype: "list" },
|
|
23
|
+
disjoint_from: { dtype: "list" },
|
|
24
|
+
property_value: { dtype: "json" },
|
|
25
|
+
// Typedef frames, under typedefs: "nodes"
|
|
26
|
+
domain: { dtype: "string" },
|
|
27
|
+
range: { dtype: "string" },
|
|
28
|
+
inverse_of: { dtype: "string" },
|
|
29
|
+
transitive_over: { dtype: "list" },
|
|
30
|
+
disjoint_over: { dtype: "list" },
|
|
31
|
+
holds_over_chain: { dtype: "json" },
|
|
32
|
+
equivalent_to_chain: { dtype: "json" },
|
|
33
|
+
expand_assertion_to: { dtype: "json" },
|
|
34
|
+
expand_expression_to: { dtype: "json" },
|
|
35
|
+
is_cyclic: { dtype: "bool" },
|
|
36
|
+
is_reflexive: { dtype: "bool" },
|
|
37
|
+
is_symmetric: { dtype: "bool" },
|
|
38
|
+
is_anti_symmetric: { dtype: "bool" },
|
|
39
|
+
is_asymmetric: { dtype: "bool" },
|
|
40
|
+
is_transitive: { dtype: "bool" },
|
|
41
|
+
is_functional: { dtype: "bool" },
|
|
42
|
+
is_inverse_functional: { dtype: "bool" },
|
|
43
|
+
is_metadata_tag: { dtype: "bool" },
|
|
44
|
+
is_class_level: { dtype: "bool" },
|
|
45
|
+
// OBO Graphs only
|
|
46
|
+
propertyType: { dtype: "dict" },
|
|
47
|
+
// what has no column of its own
|
|
48
|
+
"obo.qualifiers": { dtype: "json" },
|
|
49
|
+
"obo.unrecognized": { dtype: "json" }
|
|
50
|
+
});
|
|
51
|
+
const OBO_EDGE_COLUMNS = Object.freeze({
|
|
52
|
+
relation: { dtype: "dict", role: "kind" },
|
|
53
|
+
qualifiers: { dtype: "json" },
|
|
54
|
+
meta: { dtype: "json" }
|
|
55
|
+
});
|
|
56
|
+
const PLACEHOLDER_COLUMN = "graphty.placeholder";
|
|
57
|
+
function oboColumnDecl(domain, name) {
|
|
58
|
+
if (name === PLACEHOLDER_COLUMN) {
|
|
59
|
+
return { name, dtype: "bool", nullable: true, origin: { format: "graphty", id: "placeholder" } };
|
|
60
|
+
}
|
|
61
|
+
const spec = (domain === "node" ? OBO_NODE_COLUMNS : OBO_EDGE_COLUMNS)[name];
|
|
62
|
+
const decl = { name, dtype: spec.dtype, nullable: true, origin: { format: "obo", id: name } };
|
|
63
|
+
if (spec.dtype === "list") {
|
|
64
|
+
decl.itemDtype = "string";
|
|
65
|
+
}
|
|
66
|
+
if (spec.role !== void 0) {
|
|
67
|
+
decl.role = spec.role;
|
|
68
|
+
}
|
|
69
|
+
return decl;
|
|
70
|
+
}
|
|
71
|
+
const OBO_PURL = "http://purl.obolibrary.org/obo/";
|
|
72
|
+
const OBO_IN_OWL = "http://www.geneontology.org/formats/oboInOwl#";
|
|
73
|
+
function compactOboIri(iri) {
|
|
74
|
+
if (!iri.startsWith(OBO_PURL)) {
|
|
75
|
+
return iri;
|
|
76
|
+
}
|
|
77
|
+
const rest = iri.slice(OBO_PURL.length);
|
|
78
|
+
const hash = rest.indexOf("#");
|
|
79
|
+
if (hash > 0) {
|
|
80
|
+
const local = rest.slice(hash + 1);
|
|
81
|
+
return local.length > 0 && !rest.slice(0, hash).includes("/") ? local : iri;
|
|
82
|
+
}
|
|
83
|
+
const underscore = rest.indexOf("_");
|
|
84
|
+
if (underscore <= 0 || rest.includes("/") || underscore === rest.length - 1) {
|
|
85
|
+
return iri;
|
|
86
|
+
}
|
|
87
|
+
return `${rest.slice(0, underscore)}:${rest.slice(underscore + 1)}`;
|
|
88
|
+
}
|
|
89
|
+
const SYNONYM_SCOPES = /* @__PURE__ */ new Set(["EXACT", "BROAD", "NARROW", "RELATED"]);
|
|
90
|
+
function synonymScopeOf(pred) {
|
|
91
|
+
const local = pred.startsWith(OBO_IN_OWL) ? pred.slice(OBO_IN_OWL.length) : pred;
|
|
92
|
+
const match = /^has(Exact|Broad|Narrow|Related)Synonym$/.exec(local);
|
|
93
|
+
return match === null ? null : match[1].toUpperCase();
|
|
94
|
+
}
|
|
95
|
+
const OBOGRAPHS_PREDICATE_TAGS = /* @__PURE__ */ new Map([
|
|
96
|
+
[`${OBO_IN_OWL}hasOBONamespace`, "namespace"],
|
|
97
|
+
[`${OBO_IN_OWL}hasAlternativeId`, "alt_id"],
|
|
98
|
+
[`${OBO_IN_OWL}created_by`, "created_by"],
|
|
99
|
+
[`${OBO_IN_OWL}creation_date`, "creation_date"],
|
|
100
|
+
[`${OBO_PURL}IAO_0100001`, "replaced_by"],
|
|
101
|
+
[`${OBO_IN_OWL}consider`, "consider"],
|
|
102
|
+
[`${OBO_IN_OWL}shorthand`, "shorthand"]
|
|
103
|
+
]);
|
|
104
|
+
export {
|
|
105
|
+
OBO_NODE_COLUMNS as O,
|
|
106
|
+
PLACEHOLDER_COLUMN as P,
|
|
107
|
+
SYNONYM_SCOPES as S,
|
|
108
|
+
OBOGRAPHS_PREDICATE_TAGS as a,
|
|
109
|
+
compactOboIri as c,
|
|
110
|
+
oboColumnDecl as o,
|
|
111
|
+
synonymScopeOf as s
|
|
112
|
+
};
|
|
113
|
+
//# sourceMappingURL=ontology-BnrJ4I98.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ontology-BnrJ4I98.js","sources":["../../src/common/ontology.ts"],"sourcesContent":["/**\n * What the OBO importer and the JSON importer's `obographs` dialect share (design section 1.0, the\n * `ontology.ts` building block): the OBO column vocabulary (names, dtypes, roles), so the `.obo` and\n * the `.json` of one ontology give the same columns, and the OBO 1.4 rule for turning the IRIs\n * OBO Graphs writes back into the identifiers the `.obo` file writes (section 4.6).\n */\n\nimport { type ColumnDecl } from \"@graphty/graph-format\";\n\n/** The dtypes the OBO vocabulary uses. */\ntype OboDtype = \"string\" | \"dict\" | \"bool\" | \"list\" | \"json\";\n\n/** One column of the OBO vocabulary. */\ninterface OboColumnSpec {\n /** The dtype. */\n readonly dtype: OboDtype;\n /** The role, when the column carries one. */\n readonly role?: \"label\" | \"kind\" | undefined;\n}\n\n/**\n * The node columns of the OBO vocabulary, keyed by column name (design section 4.2). The names are\n * the OBO tag names, so a Gene Ontology user finds `namespace`, `def` and `is_obsolete` under the\n * names the GO documentation uses.\n */\nexport const OBO_NODE_COLUMNS: Readonly<Record<string, OboColumnSpec>> = Object.freeze({\n type: { dtype: \"dict\" },\n name: { dtype: \"string\", role: \"label\" },\n namespace: { dtype: \"dict\" },\n def: { dtype: \"string\" },\n \"def.xrefs\": { dtype: \"list\" },\n comment: { dtype: \"string\" },\n synonym: { dtype: \"json\" },\n xref: { dtype: \"list\" },\n \"xref.descriptions\": { dtype: \"json\" },\n alt_id: { dtype: \"list\" },\n subset: { dtype: \"list\" },\n replaced_by: { dtype: \"list\" },\n consider: { dtype: \"list\" },\n is_obsolete: { dtype: \"bool\" },\n is_anonymous: { dtype: \"bool\" },\n builtin: { dtype: \"bool\" },\n created_by: { dtype: \"string\" },\n creation_date: { dtype: \"string\" },\n intersection_of: { dtype: \"json\" },\n union_of: { dtype: \"list\" },\n equivalent_to: { dtype: \"list\" },\n disjoint_from: { dtype: \"list\" },\n property_value: { dtype: \"json\" },\n // Typedef frames, under typedefs: \"nodes\"\n domain: { dtype: \"string\" },\n range: { dtype: \"string\" },\n inverse_of: { dtype: \"string\" },\n transitive_over: { dtype: \"list\" },\n disjoint_over: { dtype: \"list\" },\n holds_over_chain: { dtype: \"json\" },\n equivalent_to_chain: { dtype: \"json\" },\n expand_assertion_to: { dtype: \"json\" },\n expand_expression_to: { dtype: \"json\" },\n is_cyclic: { dtype: \"bool\" },\n is_reflexive: { dtype: \"bool\" },\n is_symmetric: { dtype: \"bool\" },\n is_anti_symmetric: { dtype: \"bool\" },\n is_asymmetric: { dtype: \"bool\" },\n is_transitive: { dtype: \"bool\" },\n is_functional: { dtype: \"bool\" },\n is_inverse_functional: { dtype: \"bool\" },\n is_metadata_tag: { dtype: \"bool\" },\n is_class_level: { dtype: \"bool\" },\n // OBO Graphs only\n propertyType: { dtype: \"dict\" },\n // what has no column of its own\n \"obo.qualifiers\": { dtype: \"json\" },\n \"obo.unrecognized\": { dtype: \"json\" },\n});\n\n/** The edge columns of the OBO vocabulary. */\nconst OBO_EDGE_COLUMNS: Readonly<Record<string, OboColumnSpec>> = Object.freeze({\n relation: { dtype: \"dict\", role: \"kind\" },\n qualifiers: { dtype: \"json\" },\n meta: { dtype: \"json\" },\n});\n\n/** The node column that marks a node made for an undeclared reference (design section 4.2). */\nexport const PLACEHOLDER_COLUMN = \"graphty.placeholder\";\n\n/**\n * The declaration of an OBO vocabulary column.\n * @param domain - node or edge\n * @param name - the column name (a key of OBO_NODE_COLUMNS / OBO_EDGE_COLUMNS, or the placeholder column)\n * @returns the declaration, nullable, with origin `{ format: \"obo\", id: name }`\n */\nexport function oboColumnDecl(domain: \"node\" | \"edge\", name: string): ColumnDecl {\n if (name === PLACEHOLDER_COLUMN) {\n return { name, dtype: \"bool\", nullable: true, origin: { format: \"graphty\", id: \"placeholder\" } };\n }\n const spec = (domain === \"node\" ? OBO_NODE_COLUMNS : OBO_EDGE_COLUMNS)[name];\n const decl: ColumnDecl = { name, dtype: spec.dtype, nullable: true, origin: { format: \"obo\", id: name } };\n if (spec.dtype === \"list\") {\n decl.itemDtype = \"string\";\n }\n if (spec.role !== undefined) {\n decl.role = spec.role;\n }\n return decl;\n}\n\n/** The OBO PURL base every OBO Foundry IRI starts with. */\nconst OBO_PURL = \"http://purl.obolibrary.org/obo/\";\n\n/** The oboInOwl namespace of the OBO-to-OWL mapping's annotation properties. */\nconst OBO_IN_OWL = \"http://www.geneontology.org/formats/oboInOwl#\";\n\n/**\n * An IRI as the identifier the `.obo` file writes (the OBO 1.4 mapping, section 5.9, read\n * backwards): `http://purl.obolibrary.org/obo/GO_0008150` is `GO:0008150` (the prefix is the text\n * before the first underscore), and `http://purl.obolibrary.org/obo/go#regulates` (how the OWL\n * translation writes an unprefixed OBO id: subsets, relations, synonym types) is `regulates`.\n * Every other IRI, and an OBO PURL that fits neither form (`.../obo/T/Female`), is kept.\n * @param iri - the IRI\n * @returns the CURIE or local id, or the IRI unchanged\n */\nexport function compactOboIri(iri: string): string {\n if (!iri.startsWith(OBO_PURL)) {\n return iri;\n }\n const rest = iri.slice(OBO_PURL.length);\n const hash = rest.indexOf(\"#\");\n if (hash > 0) {\n const local = rest.slice(hash + 1);\n return local.length > 0 && !rest.slice(0, hash).includes(\"/\") ? local : iri;\n }\n const underscore = rest.indexOf(\"_\");\n if (underscore <= 0 || rest.includes(\"/\") || underscore === rest.length - 1) {\n return iri;\n }\n return `${rest.slice(0, underscore)}:${rest.slice(underscore + 1)}`;\n}\n\n/** The OBO synonym scopes. */\nexport const SYNONYM_SCOPES: ReadonlySet<string> = new Set([\"EXACT\", \"BROAD\", \"NARROW\", \"RELATED\"]);\n\n/**\n * The OBO synonym scope of an OBO Graphs synonym predicate (`hasExactSynonym`, with or without the\n * oboInOwl namespace).\n * @param pred - the predicate\n * @returns the scope, or null for a predicate that is not one of the four\n */\nexport function synonymScopeOf(pred: string): string | null {\n const local = pred.startsWith(OBO_IN_OWL) ? pred.slice(OBO_IN_OWL.length) : pred;\n const match = /^has(Exact|Broad|Narrow|Related)Synonym$/.exec(local);\n return match === null ? null : match[1].toUpperCase();\n}\n\n/**\n * The OBO tag a `basicPropertyValues` predicate of OBO Graphs came from (the OBO-to-OWL mapping of\n * the tags that are annotations), so the `.json` of an ontology fills the same columns as its\n * `.obo`. `shorthand` is the relation's short name; every predicate not listed is a\n * `property_value`.\n */\nexport const OBOGRAPHS_PREDICATE_TAGS: ReadonlyMap<string, string> = new Map([\n [`${OBO_IN_OWL}hasOBONamespace`, \"namespace\"],\n [`${OBO_IN_OWL}hasAlternativeId`, \"alt_id\"],\n [`${OBO_IN_OWL}created_by`, \"created_by\"],\n [`${OBO_IN_OWL}creation_date`, \"creation_date\"],\n [`${OBO_PURL}IAO_0100001`, \"replaced_by\"],\n [`${OBO_IN_OWL}consider`, \"consider\"],\n [`${OBO_IN_OWL}shorthand`, \"shorthand\"],\n]);\n"],"names":[],"mappings":"AAyBO,MAAM,mBAA4D,OAAO,OAAO;AAAA,EACnF,MAAM,EAAE,OAAO,OAAA;AAAA,EACf,MAAM,EAAE,OAAO,UAAU,MAAM,QAAA;AAAA,EAC/B,WAAW,EAAE,OAAO,OAAA;AAAA,EACpB,KAAK,EAAE,OAAO,SAAA;AAAA,EACd,aAAa,EAAE,OAAO,OAAA;AAAA,EACtB,SAAS,EAAE,OAAO,SAAA;AAAA,EAClB,SAAS,EAAE,OAAO,OAAA;AAAA,EAClB,MAAM,EAAE,OAAO,OAAA;AAAA,EACf,qBAAqB,EAAE,OAAO,OAAA;AAAA,EAC9B,QAAQ,EAAE,OAAO,OAAA;AAAA,EACjB,QAAQ,EAAE,OAAO,OAAA;AAAA,EACjB,aAAa,EAAE,OAAO,OAAA;AAAA,EACtB,UAAU,EAAE,OAAO,OAAA;AAAA,EACnB,aAAa,EAAE,OAAO,OAAA;AAAA,EACtB,cAAc,EAAE,OAAO,OAAA;AAAA,EACvB,SAAS,EAAE,OAAO,OAAA;AAAA,EAClB,YAAY,EAAE,OAAO,SAAA;AAAA,EACrB,eAAe,EAAE,OAAO,SAAA;AAAA,EACxB,iBAAiB,EAAE,OAAO,OAAA;AAAA,EAC1B,UAAU,EAAE,OAAO,OAAA;AAAA,EACnB,eAAe,EAAE,OAAO,OAAA;AAAA,EACxB,eAAe,EAAE,OAAO,OAAA;AAAA,EACxB,gBAAgB,EAAE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,WAAW;AAAA,EAC5C,CAAC,GAAG,UAAU,oBAAoB,QAAQ;AAAA,EAC1C,CAAC,GAAG,UAAU,cAAc,YAAY;AAAA,EACxC,CAAC,GAAG,UAAU,iBAAiB,eAAe;AAAA,EAC9C,CAAC,GAAG,QAAQ,eAAe,aAAa;AAAA,EACxC,CAAC,GAAG,UAAU,YAAY,UAAU;AAAA,EACpC,CAAC,GAAG,UAAU,aAAa,WAAW;AAC1C,CAAC;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GraphFormatError } from "@graphty/graph-format";
|
|
2
|
-
import { t as textChunks } from "./
|
|
2
|
+
import { t as textChunks } from "./report-BOk0p5y8.js";
|
|
3
3
|
const UNCLOSED_QUOTE_CODE = "E_CSV_UNCLOSED_QUOTE";
|
|
4
4
|
const BAD_QUOTE_CODE = "E_CSV_QUOTE";
|
|
5
5
|
const DELIMITER_CANDIDATES = Object.freeze([",", " ", ";", "|", " "]);
|
|
@@ -615,4 +615,4 @@ export {
|
|
|
615
615
|
checkRecordSyntax as c,
|
|
616
616
|
sniffNewline as s
|
|
617
617
|
};
|
|
618
|
-
//# sourceMappingURL=records-
|
|
618
|
+
//# sourceMappingURL=records-Bk9jgodz.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"records-IHsCfv7s.js","sources":["../../src/formats/csv/records.ts"],"sourcesContent":["/**\n * The one streaming CSV record reader of the package (design sections 8.2 and 8.4: hand-written\n * tokenisers per format; CSV and Neo4j CSV are line-oriented over a byte stream): RFC 4180 records\n * with a configurable single-character delimiter and quote, a doubled quote inside a quoted field,\n * quoted fields spanning lines, LF / CRLF / lone-CR terminators, read from the common text reader\n * one chunk at a time as a character state machine. Only the open field is ever held, so a field\n * spanning many chunks costs its length once and a multi-gigabyte file is never buffered.\n *\n * `RecordReader` (used by the Neo4j importer) keeps one reusable cell array and one reusable\n * \"was quoted\" array: a quoted empty field (`\"\"`) is an empty string while an unquoted empty field\n * means \"not set\", and only the tokeniser can tell the two apart. `CsvRecordReader` (the CSV\n * importer) wraps it with delimiter sniffing over a bounded preview and yields a fresh cell array\n * per row. A malformed quoted field is fatal for both: an unterminated quote swallows the rest of\n * the file, and text after a closing quote makes every later cell boundary unreliable.\n */\n\nimport { GraphFormatError } from \"@graphty/graph-format\";\n\nimport { type ReadOptions, textChunks } from \"../../common/input.js\";\nimport { type ImportReportBuilder } from \"../../common/report.js\";\nimport { type ImportInput } from \"../../types.js\";\n\n/** Issue code: a quoted field is never closed; the import aborts (everything after it would be one cell). */\nexport const UNCLOSED_QUOTE_CODE = \"E_CSV_UNCLOSED_QUOTE\";\n\n/** Issue code: a closing quote is followed by text other than a delimiter or a line break; the import aborts. */\nexport const BAD_QUOTE_CODE = \"E_CSV_QUOTE\";\n\n/** The delimiters tried, in priority order, when none is given. */\nexport const DELIMITER_CANDIDATES: readonly string[] = Object.freeze([\",\", \"\\t\", \";\", \"|\", \" \"]);\n\n/** Rows the delimiter sniff looks at. */\nconst PREVIEW_ROWS = 10;\n\n/** Characters buffered for the sniff when the input has fewer than PREVIEW_ROWS line breaks. */\nconst PREVIEW_CHARS = 64 * 1024;\n\nconst LF = 10;\nconst CR = 13;\n\n/** Tokeniser state: at the start of a field. */\nconst START = 0;\n/** Tokeniser state: inside an unquoted field. */\nconst UNQUOTED = 1;\n/** Tokeniser state: inside a quoted field. */\nconst QUOTED = 2;\n/** Tokeniser state: just after a quote inside a quoted field (a second quote is a literal, anything else ends the field). */\nconst CLOSING = 3;\n/** Tokeniser state: after a closed quoted field, before the delimiter (text here is malformed). */\nconst AFTER_QUOTED = 4;\n/** Inside a leading comment line (skipped up to its line break). */\nconst COMMENT = 5;\n\ntype State = typeof START | typeof UNQUOTED | typeof QUOTED | typeof CLOSING | typeof AFTER_QUOTED | typeof COMMENT;\n\n/** The delimiter and quote of a reader. */\nexport interface RecordSyntax {\n /** The field delimiter, one character; null sniffs it from the first rows. */\n readonly delimiter: string | null;\n /** The quote character, one character. */\n readonly quote: string;\n /** The delimiters tried when `delimiter` is null; DELIMITER_CANDIDATES by default. */\n readonly candidates?: readonly string[] | undefined;\n /**\n * Characters that open a comment line while no record has been read yet (SNAP `#`, KONECT\n * `%`): such leading lines are skipped, kept in `leadingComments` and left out of the delimiter\n * sniff. A later line starting with one of them is an ordinary record. Default: none.\n */\n readonly comments?: readonly string[] | undefined;\n /**\n * Whether the delimiter sniff skips a candidate under which a closing quote is followed by\n * other text (see sniffDelimiter). False by default: that text then aborts the read.\n */\n readonly skipQuoteErrors?: boolean | undefined;\n}\n\n/**\n * Check a delimiter or quote option: exactly one character that is not a line break, and the two\n * must differ.\n * @param syntax - the delimiter (or null for sniffing) and quote\n * @returns the syntax unchanged; E_UNSUPPORTED when invalid\n */\nexport function checkRecordSyntax(syntax: RecordSyntax): RecordSyntax {\n for (const [option, value] of [\n [\"delimiter\", syntax.delimiter],\n [\"quote\", syntax.quote],\n ] as const) {\n if (value === null) {\n continue;\n }\n if (value.length !== 1 || value === \"\\n\" || value === \"\\r\") {\n throw new GraphFormatError(\n \"E_UNSUPPORTED\",\n `option ${option}: ${JSON.stringify(value)} is not a single non-line-break character`,\n { option, found: value },\n );\n }\n }\n if (syntax.delimiter !== null && syntax.delimiter === syntax.quote) {\n throw new GraphFormatError(\"E_UNSUPPORTED\", \"options delimiter and quote must differ\", {\n option: \"delimiter\",\n found: syntax.delimiter,\n });\n }\n return syntax;\n}\n\n/**\n * Sniff the line terminator of a text: a lone `\\r` only when the text has `\\r` and no `\\n` at all\n * (classic Mac files); `\\n` otherwise.\n * @param text - the preview text\n * @returns \"\\n\" or \"\\r\"\n */\nexport function sniffNewline(text: string): \"\\n\" | \"\\r\" {\n return !text.includes(\"\\n\") && text.includes(\"\\r\") ? \"\\r\" : \"\\n\";\n}\n\n/**\n * Split a text into records synchronously (the first `maxRows` of them), honouring quotes; for\n * the delimiter sniff and the registry's head sniff, where the input is a bounded preview.\n * @param text - the text\n * @param delimiter - the delimiter\n * @param quote - the quote character\n * @param maxRows - the most rows to return\n * @param strictQuotes - return null when a closing quote is followed by text other than the\n * delimiter or a line break (the import would abort under this delimiter)\n * @returns the rows as cell arrays (blank lines skipped), or null (see strictQuotes)\n */\nfunction splitRecords(\n text: string,\n delimiter: string,\n quote: string,\n maxRows: number,\n strictQuotes = false,\n): string[][] | null {\n const rows: string[][] = [];\n const delimiterCode = delimiter.charCodeAt(0);\n const quoteCode = quote.charCodeAt(0);\n let cells: string[] = [];\n let state: State = START;\n let segment = 0;\n let field = \"\";\n const n = text.length;\n for (let i = 0; i < n && rows.length < maxRows; i++) {\n const c = text.charCodeAt(i);\n if (state === QUOTED) {\n if (c === quoteCode) {\n field += text.slice(segment, i);\n state = CLOSING;\n }\n continue;\n }\n if (state === CLOSING) {\n if (c === quoteCode) {\n field += quote;\n segment = i + 1;\n state = QUOTED;\n continue;\n }\n if (strictQuotes && c !== delimiterCode && c !== LF && c !== CR) {\n return null;\n }\n state = AFTER_QUOTED;\n segment = i;\n }\n if (c === delimiterCode || c === LF || c === CR) {\n if (state === UNQUOTED || state === AFTER_QUOTED) {\n field += text.slice(segment, i);\n }\n if (c === delimiterCode) {\n cells.push(field);\n field = \"\";\n state = START;\n } else {\n if (state !== START || cells.length > 0) {\n cells.push(field);\n rows.push(cells);\n cells = [];\n field = \"\";\n }\n state = START;\n if (c === CR && text.charCodeAt(i + 1) === LF) {\n i++;\n }\n }\n segment = i + 1;\n continue;\n }\n if (state === START) {\n if (c === quoteCode) {\n state = QUOTED;\n segment = i + 1;\n } else {\n state = UNQUOTED;\n segment = i;\n }\n }\n }\n if (rows.length < maxRows && (state !== START || cells.length > 0)) {\n if (state === UNQUOTED || state === AFTER_QUOTED || state === QUOTED) {\n field += text.slice(segment, n);\n }\n cells.push(field);\n rows.push(cells);\n }\n return rows;\n}\n\n/**\n * The preview text without its leading comment lines (those starting with one of the comment\n * characters), so the sniff sees the records only.\n * @param text - the preview text\n * @param comments - the comment characters\n * @returns the text from the first non-comment line on\n */\nfunction stripLeadingComments(text: string, comments: readonly string[]): string {\n if (comments.length === 0) {\n return text;\n }\n let at = 0;\n while (at < text.length && comments.includes(text[at])) {\n const lf = text.indexOf(\"\\n\", at);\n const cr = text.indexOf(\"\\r\", at);\n const end = Math.min(lf < 0 ? Infinity : lf, cr < 0 ? Infinity : cr);\n if (end === Infinity) {\n return \"\";\n }\n at = end + 1;\n if (text[at - 1] === \"\\r\" && text[at] === \"\\n\") {\n at++;\n }\n }\n return at === 0 ? text : text.slice(at);\n}\n\n/**\n * Sniff the delimiter of a text: every candidate is tried over the first rows and the one whose\n * field count is most consistent across rows wins (ties broken by the higher field count); a\n * candidate that yields fewer than two fields per row on average is never chosen. `null` when no\n * candidate qualifies (a single-column file).\n * @param text - the preview text\n * @param newline - the sniffed line terminator (unused by the splitter, which reads every kind;\n * kept for callers that sniffed it)\n * @param candidates - the delimiters to try, in priority order\n * @param quote - the quote character\n * @param skipQuoteErrors - also never choose a candidate under which a closing quote is followed\n * by other text. Only for inputs whose field counts say nothing (an adjacency table's rows vary in\n * width): elsewhere a stray character after a quote would make a worse candidate win silently\n * instead of aborting the read\n * @returns the delimiter, or null\n */\nexport function sniffDelimiter(\n text: string,\n newline: \"\\n\" | \"\\r\" = \"\\n\",\n candidates: readonly string[] = DELIMITER_CANDIDATES,\n quote = '\"',\n skipQuoteErrors = false,\n): string | null {\n let best: string | null = null;\n let bestDelta = Infinity;\n let bestAverage = 0;\n const terminated = text.endsWith(\"\\n\") || text.endsWith(\"\\r\");\n for (const delimiter of candidates) {\n if (delimiter === quote || delimiter === newline) {\n continue;\n }\n const split = splitRecords(text, delimiter, quote, PREVIEW_ROWS, skipQuoteErrors);\n if (split === null) {\n // a quoted cell this delimiter does not close: it is not the file's delimiter\n continue;\n }\n let rows = split.filter((row) => !isBlankRow(row));\n if (rows.length > 1 && !terminated) {\n // the preview is a prefix of the file: its last row may be cut short\n rows = rows.slice(0, -1);\n }\n if (rows.length === 0) {\n continue;\n }\n let total = 0;\n let delta = 0;\n for (let i = 0; i < rows.length; i++) {\n const count = rows[i].length;\n total += count;\n if (i > 0) {\n delta += Math.abs(count - rows[i - 1].length);\n }\n }\n const average = total / rows.length;\n if (average > 1.99 && (delta < bestDelta || (delta === bestDelta && average > bestAverage))) {\n best = delimiter;\n bestDelta = delta;\n bestAverage = average;\n }\n }\n return best;\n}\n\n/**\n * Whether a parsed row is a blank line: one cell holding only whitespace.\n * @param row - the row\n * @returns true for a blank line\n */\nfunction isBlankRow(row: readonly string[]): boolean {\n return row.length === 1 && row[0].trim().length === 0;\n}\n\n/**\n * Reads the records of one input. Iterate with `for await (const count of reader)`: each\n * iteration fills `reader.cells[0..count)` and `reader.quoted[0..count)` and sets `reader.line`\n * to the 1-based line the record started on. Blank lines (an empty unquoted record of one field)\n * are skipped. The arrays are reused between records. When the syntax gives no delimiter, the\n * first rows (PREVIEW_ROWS, or PREVIEW_CHARS characters) are buffered and the delimiter sniffed\n * from them before the first record is yielded.\n */\nexport class RecordReader implements AsyncIterable<number> {\n /** The cells of the record most recently yielded; only the first `count` entries are valid. */\n readonly cells: string[] = [];\n\n /** Whether each cell of the record most recently yielded was quoted. */\n readonly quoted: boolean[] = [];\n\n /** The leading comment lines (without their line breaks), in order; empty without `syntax.comments`. */\n readonly leadingComments: string[] = [];\n\n private readonly input: ImportInput;\n\n private readonly report: ImportReportBuilder;\n\n private readonly readOptions: ReadOptions;\n\n /** The delimiter (null while unsniffed), quote and comment characters. */\n readonly syntax: RecordSyntax;\n\n private delimiterText: string | null;\n\n private recordLine = 0;\n\n /**\n * Create a reader; nothing is read until iteration starts.\n * @param input - the input (or an async iterable of already decoded text chunks)\n * @param report - the report decode and quoting errors are recorded in\n * @param syntax - the delimiter (null to sniff) and quote (already checked)\n * @param readOptions - cancellation and progress\n */\n constructor(input: ImportInput, report: ImportReportBuilder, syntax: RecordSyntax, readOptions: ReadOptions) {\n this.input = input;\n this.report = report;\n this.readOptions = readOptions;\n this.syntax = syntax;\n this.delimiterText = syntax.delimiter;\n }\n\n /**\n * The 1-based line the most recently yielded record started on.\n * @returns the line number; 0 before the first record\n */\n get line(): number {\n return this.recordLine;\n }\n\n /**\n * The delimiter in use.\n * @returns the given or sniffed delimiter; null before the sniff ran\n */\n get delimiter(): string | null {\n return this.delimiterText;\n }\n\n /**\n * Iterate the records.\n * @yields the number of cells of each record\n * @returns nothing\n */\n async *[Symbol.asyncIterator](): AsyncGenerator<number, void, undefined> {\n const scanner = new RecordScanner(this);\n for await (const chunk of this.chunks()) {\n // the first chunk arrives after the sniff (or with the given delimiter)\n scanner.setDelimiter((this.delimiterText ?? \",\").charCodeAt(0));\n let i = 0;\n while (i < chunk.length) {\n i = scanner.scan(chunk, i);\n if (scanner.ready) {\n scanner.ready = false;\n this.recordLine = scanner.recordLine;\n yield scanner.count;\n scanner.count = 0;\n }\n }\n scanner.endChunk(chunk);\n }\n if (scanner.finish()) {\n this.recordLine = scanner.recordLine;\n yield scanner.count;\n }\n }\n\n /**\n * Record a text-after-quote error (fatal).\n * @param line - the line the field started on\n * @returns never\n */\n badQuote(line: number): never {\n return this.report.fail(BAD_QUOTE_CODE, `line ${line}: text after the closing quote of a quoted field`, {\n line,\n });\n }\n\n /**\n * Record an unclosed-quote error (fatal).\n * @param line - the line the field started on\n * @returns never\n */\n unclosedQuote(line: number): never {\n return this.report.fail(UNCLOSED_QUOTE_CODE, `a quoted field starting on line ${line} is never closed`, {\n line,\n });\n }\n\n /**\n * The decoded text chunks of the input; when the delimiter is to be sniffed, the first rows\n * are buffered (bounded by PREVIEW_ROWS line breaks or PREVIEW_CHARS characters), the sniff\n * runs, and the buffered text is yielded as one chunk before the rest streams through.\n * @yields the text chunks\n * @returns nothing\n */\n private async *chunks(): AsyncGenerator<string, void, undefined> {\n const source = textChunks(this.input, this.report, this.readOptions);\n if (this.delimiterText !== null) {\n yield* source;\n return;\n }\n const pieces: string[] = [];\n let length = 0;\n let breaks = 0;\n let lastWasCr = false;\n let sniffed = false;\n for await (const chunk of source) {\n if (sniffed) {\n yield chunk;\n continue;\n }\n pieces.push(chunk);\n length += chunk.length;\n for (let i = 0; i < chunk.length && breaks < PREVIEW_ROWS; i++) {\n const c = chunk.charCodeAt(i);\n if (c === LF) {\n if (!lastWasCr) {\n breaks++;\n }\n } else if (c === CR) {\n breaks++;\n }\n lastWasCr = c === CR;\n }\n if (breaks < PREVIEW_ROWS && length < PREVIEW_CHARS) {\n continue;\n }\n const text = pieces.join(\"\");\n pieces.length = 0;\n this.sniff(text);\n sniffed = true;\n yield text;\n }\n if (!sniffed) {\n const text = pieces.join(\"\");\n if (text.length > 0) {\n this.sniff(text);\n yield text;\n }\n }\n }\n\n /**\n * Sniff the delimiter from the preview text and record it.\n * @param text - the preview\n */\n private sniff(text: string): void {\n const candidates = this.syntax.candidates ?? DELIMITER_CANDIDATES;\n // the sniff is a heuristic over the first rows: a single chunk holding a huge quoted cell\n // is capped so the candidate scans stay bounded\n const body = stripLeadingComments(text.slice(0, PREVIEW_CHARS), this.syntax.comments ?? []);\n this.delimiterText =\n sniffDelimiter(body, sniffNewline(body), candidates, this.syntax.quote, this.syntax.skipQuoteErrors) ??\n candidates[0];\n }\n}\n\n/**\n * The record state machine of RecordReader, resumable at every record end so the reader can\n * yield a record before the next one overwrites the shared cell arrays. Every state lives on the\n * instance; `scan()` runs the per-character loop over one chunk from a position and returns where\n * it stopped (after the character that completed a record, with `ready` set, or the chunk end).\n */\nclass RecordScanner {\n /** Whether a record just completed. */\n ready = false;\n\n /** The cell count of the record in progress (the completed one while `ready`). */\n count = 0;\n\n /** The line the completed record started on (valid while `ready`, and after finish()). */\n recordLine = 1;\n\n /** The line the record in progress started on. */\n private startLine = 1;\n\n private readonly reader: RecordReader;\n\n private readonly quoteCode: number;\n\n private readonly quoteText: string;\n\n private readonly commentCodes: readonly number[];\n\n private delimiterCode = -1;\n\n private state: State = START;\n\n private field = \"\";\n\n private fieldQuoted = false;\n\n private line = 1;\n\n private lastWasCr = false;\n\n /** Whether no record has started yet (comment lines are recognised until one does). */\n private leading: boolean;\n\n private comment = \"\";\n\n /** The start of the unconsumed run of the current chunk that belongs to the field or comment. */\n private segment = 0;\n\n /**\n * Create a scanner over a reader's cell arrays.\n * @param reader - the reader\n */\n constructor(reader: RecordReader) {\n this.reader = reader;\n this.quoteCode = reader.syntax.quote.charCodeAt(0);\n this.quoteText = reader.syntax.quote;\n this.commentCodes = (reader.syntax.comments ?? []).map((c) => c.charCodeAt(0));\n this.leading = this.commentCodes.length > 0;\n }\n\n /**\n * Set the delimiter once it is known (before the first chunk is scanned).\n * @param code - the delimiter's character code\n */\n setDelimiter(code: number): void {\n if (this.delimiterCode < 0) {\n this.delimiterCode = code;\n }\n }\n\n /**\n * Scan one chunk from a position until a record completes or the chunk ends.\n * @param chunk - the chunk\n * @param from - where to start\n * @returns the position after the last character consumed\n */\n scan(chunk: string, from: number): number {\n const { quoteCode, delimiterCode } = this;\n const n = chunk.length;\n let i = from;\n this.segment = from;\n while (i < n) {\n const c = chunk.charCodeAt(i);\n if (this.state === COMMENT) {\n if (c === LF || c === CR) {\n this.comment += chunk.slice(this.segment, i);\n this.reader.leadingComments.push(this.comment);\n this.comment = \"\";\n this.state = START;\n this.endLine(c);\n this.segment = i + 1;\n }\n i++;\n continue;\n }\n if (this.state === QUOTED) {\n // jump to the next quote; the run in between is field text whose line breaks are counted\n const q = chunk.indexOf(this.quoteText, i);\n const end = q < 0 ? n : q;\n if (end > i) {\n this.countLineBreaks(chunk, i, end);\n }\n if (q < 0) {\n i = n;\n break;\n }\n this.field += chunk.slice(this.segment, q);\n this.state = CLOSING;\n this.lastWasCr = false;\n i = q + 1;\n continue;\n }\n if (this.state === CLOSING) {\n if (c === quoteCode) {\n this.field += this.quoteText;\n this.segment = i + 1;\n this.state = QUOTED;\n this.lastWasCr = false;\n i++;\n continue;\n }\n if (c !== delimiterCode && c !== LF && c !== CR) {\n this.reader.badQuote(this.startLine);\n }\n this.state = AFTER_QUOTED;\n this.segment = i;\n // fall through to the delimiter / line-end handling below without consuming c\n }\n if (c === delimiterCode || c === LF || c === CR) {\n if (c === LF && this.lastWasCr) {\n // the second half of a CRLF already ended the record\n this.lastWasCr = false;\n this.segment = i + 1;\n i++;\n continue;\n }\n if (this.state === UNQUOTED) {\n this.field += chunk.slice(this.segment, i);\n }\n if (c === delimiterCode) {\n this.push();\n this.state = START;\n this.lastWasCr = false;\n this.segment = i + 1;\n i++;\n continue;\n }\n const blank = this.state === START && this.count === 0;\n if (!blank) {\n this.push();\n this.ready = true;\n this.recordLine = this.startLine;\n }\n this.state = START;\n this.endLine(c);\n this.segment = i + 1;\n i++;\n if (this.ready) {\n return i;\n }\n continue;\n }\n this.lastWasCr = false;\n if (this.state === START) {\n if (this.leading && this.count === 0 && this.commentCodes.includes(c)) {\n this.state = COMMENT;\n this.segment = i;\n i++;\n continue;\n }\n this.leading = false;\n if (c === quoteCode) {\n this.state = QUOTED;\n this.fieldQuoted = true;\n this.segment = i + 1;\n } else {\n this.state = UNQUOTED;\n this.segment = i;\n }\n }\n i++;\n }\n return i;\n }\n\n /**\n * Keep the tail of a chunk that belongs to an open field or comment.\n * @param chunk - the chunk just scanned to its end\n */\n endChunk(chunk: string): void {\n const n = chunk.length;\n if (this.segment >= n) {\n return;\n }\n if (this.state === COMMENT) {\n this.comment += chunk.slice(this.segment, n);\n } else if (this.state === QUOTED || this.state === UNQUOTED) {\n this.field += chunk.slice(this.segment, n);\n }\n this.segment = n;\n }\n\n /**\n * The end of the input: an open comment is kept, an open quote is fatal, an open record\n * (no trailing line break) is completed.\n * @returns true when a last record is ready\n */\n finish(): boolean {\n const { state } = this;\n if (state === COMMENT) {\n this.reader.leadingComments.push(this.comment);\n return false;\n }\n if (state === QUOTED) {\n this.reader.unclosedQuote(this.startLine);\n }\n if (state !== START || this.count > 0) {\n this.push();\n this.recordLine = this.startLine;\n return true;\n }\n return false;\n }\n\n /**\n * Count the line breaks of a run of quoted text (a CRLF counts once, like the record loop).\n * @param chunk - the chunk\n * @param from - the first index of the run\n * @param to - the index after the run\n */\n private countLineBreaks(chunk: string, from: number, to: number): void {\n let { line, lastWasCr } = this;\n for (let i = from; i < to; i++) {\n const c = chunk.charCodeAt(i);\n if (c === LF) {\n if (!lastWasCr) {\n line++;\n }\n lastWasCr = false;\n } else if (c === CR) {\n line++;\n lastWasCr = true;\n } else {\n lastWasCr = false;\n }\n }\n this.line = line;\n this.lastWasCr = lastWasCr;\n }\n\n /** Store the field in progress as the next cell. */\n private push(): void {\n const { reader, count } = this;\n reader.cells[count] = this.field;\n reader.quoted[count] = this.fieldQuoted;\n this.count = count + 1;\n this.field = \"\";\n this.fieldQuoted = false;\n }\n\n /**\n * Count a line break that ends a record or a comment line.\n * @param c - the LF or CR\n */\n private endLine(c: number): void {\n if (!(c === LF && this.lastWasCr)) {\n this.line++;\n }\n this.startLine = this.line;\n this.lastWasCr = c === CR;\n }\n}\n\n/** What the CSV importer's reader needs besides the input. */\nexport interface CsvReaderOptions extends ReadOptions {\n /** The delimiter; null or undefined sniffs it from the preview. */\n readonly delimiter?: string | null | undefined;\n /** The characters opening a leading comment line (RecordSyntax.comments); none by default. */\n readonly comments?: readonly string[] | undefined;\n /** RecordSyntax.skipQuoteErrors; false by default. */\n readonly skipQuoteErrors?: boolean | undefined;\n}\n\n/**\n * Records of a CSV input, one string array per row, streamed: iterate with\n * `for await (const row of reader)` and read `reader.line` for the 1-based line the row starts\n * on. The delimiter is known after the first row (`reader.delimiter`). Rows come out as fresh\n * arrays of cell texts exactly as written (no trimming, no typing); `reader.quoted` tells, for\n * the row just yielded, which cells were quoted (a quoted empty cell is the empty string, an\n * unquoted one is \"not set\"). Blank lines and whitespace-only single-cell lines are skipped.\n */\nexport class CsvRecordReader implements AsyncIterable<string[]> {\n private readonly inner: RecordReader;\n\n /**\n * Create a reader; nothing is read until iteration starts.\n * @param input - the input\n * @param report - the report parse errors are recorded in\n * @param options - the delimiter, cancellation and progress\n */\n constructor(input: ImportInput, report: ImportReportBuilder, options: CsvReaderOptions = {}) {\n this.inner = new RecordReader(\n input,\n report,\n {\n delimiter: options.delimiter ?? null,\n quote: '\"',\n comments: options.comments,\n skipQuoteErrors: options.skipQuoteErrors,\n },\n { signal: options.signal, onProgress: options.onProgress, encoding: options.encoding },\n );\n }\n\n /**\n * The leading comment lines the reader skipped (SNAP `#` lines, the KONECT `%` header), in order.\n * @returns the lines without their line breaks\n */\n get leadingComments(): readonly string[] {\n return this.inner.leadingComments;\n }\n\n /**\n * The 1-based line the most recently yielded row starts on.\n * @returns the line; 0 before the first row\n */\n get line(): number {\n return this.inner.line;\n }\n\n /**\n * The delimiter in use.\n * @returns the given or sniffed delimiter; null before the sniff ran\n */\n get delimiter(): string | null {\n return this.inner.delimiter;\n }\n\n /**\n * Whether each cell of the row most recently yielded was quoted.\n * @returns the flags (valid for the first `row.length` entries)\n */\n get quoted(): readonly boolean[] {\n return this.inner.quoted;\n }\n\n /**\n * Iterate the rows.\n * @yields one row at a time as its cell texts\n * @returns nothing\n */\n async *[Symbol.asyncIterator](): AsyncGenerator<string[], void, undefined> {\n const { inner } = this;\n for await (const count of inner) {\n if (count === 1 && !inner.quoted[0] && inner.cells[0].trim().length === 0) {\n continue;\n }\n yield inner.cells.slice(0, count);\n }\n }\n}\n"],"names":[],"mappings":";;AAuBO,MAAM,sBAAsB;AAG5B,MAAM,iBAAiB;AAGvB,MAAM,uBAA0C,OAAO,OAAO,CAAC,KAAK,KAAM,KAAK,KAAK,GAAG,CAAC;AAG/F,MAAM,eAAe;AAGrB,MAAM,gBAAgB,KAAK;AAE3B,MAAM,KAAK;AACX,MAAM,KAAK;AAGX,MAAM,QAAQ;AAEd,MAAM,WAAW;AAEjB,MAAM,SAAS;AAEf,MAAM,UAAU;AAEhB,MAAM,eAAe;AAErB,MAAM,UAAU;AA+BT,SAAS,kBAAkB,QAAoC;AAClE,aAAW,CAAC,QAAQ,KAAK,KAAK;AAAA,IAC1B,CAAC,aAAa,OAAO,SAAS;AAAA,IAC9B,CAAC,SAAS,OAAO,KAAK;AAAA,EAAA,GACd;AACR,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AE,QAAQ,QAAQ,QAAQ,YAAY,QAAQ,YAAY,UAAU,QAAQ,SAAA;AAAA,IAAS;AAAA,EAE7F;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,IAAI,kBAAqC;AACrC,WAAO,KAAK,MAAM;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,IAAI,OAAe;AACf,WAAO,KAAK,MAAM;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,IAAI,YAA2B;AAC3B,WAAO,KAAK,MAAM;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,IAAI,SAA6B;AAC7B,WAAO,KAAK,MAAM;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,QAAQ,OAAO,aAAa,IAA+C;AACvE,UAAM,EAAE,UAAU;AAClB,qBAAiB,SAAS,OAAO;AAC7B,UAAI,UAAU,KAAK,CAAC,MAAM,OAAO,CAAC,KAAK,MAAM,MAAM,CAAC,EAAE,KAAA,EAAO,WAAW,GAAG;AACvE;AAAA,MACJ;AACA,YAAM,MAAM,MAAM,MAAM,GAAG,KAAK;AAAA,IACpC;AAAA,EACJ;AACJ;"}
|
|
1
|
+
{"version":3,"file":"records-Bk9jgodz.js","sources":["../../src/formats/csv/records.ts"],"sourcesContent":["/**\n * The one streaming CSV record reader of the package (design sections 8.2 and 8.4: hand-written\n * tokenisers per format; CSV and Neo4j CSV are line-oriented over a byte stream): RFC 4180 records\n * with a configurable single-character delimiter and quote, a doubled quote inside a quoted field,\n * quoted fields spanning lines, LF / CRLF / lone-CR terminators, read from the common text reader\n * one chunk at a time as a character state machine. Only the open field is ever held, so a field\n * spanning many chunks costs its length once and a multi-gigabyte file is never buffered.\n *\n * `RecordReader` (used by the Neo4j importer) keeps one reusable cell array and one reusable\n * \"was quoted\" array: a quoted empty field (`\"\"`) is an empty string while an unquoted empty field\n * means \"not set\", and only the tokeniser can tell the two apart. `CsvRecordReader` (the CSV\n * importer) wraps it with delimiter sniffing over a bounded preview and yields a fresh cell array\n * per row. A malformed quoted field is fatal for both: an unterminated quote swallows the rest of\n * the file, and text after a closing quote makes every later cell boundary unreliable.\n */\n\nimport { GraphFormatError } from \"@graphty/graph-format\";\n\nimport { type ReadOptions, textChunks } from \"../../common/input.js\";\nimport { type ImportReportBuilder } from \"../../common/report.js\";\nimport { type ImportInput } from \"../../types.js\";\n\n/** Issue code: a quoted field is never closed; the import aborts (everything after it would be one cell). */\nexport const UNCLOSED_QUOTE_CODE = \"E_CSV_UNCLOSED_QUOTE\";\n\n/** Issue code: a closing quote is followed by text other than a delimiter or a line break; the import aborts. */\nexport const BAD_QUOTE_CODE = \"E_CSV_QUOTE\";\n\n/** The delimiters tried, in priority order, when none is given. */\nexport const DELIMITER_CANDIDATES: readonly string[] = Object.freeze([\",\", \"\\t\", \";\", \"|\", \" \"]);\n\n/** Rows the delimiter sniff looks at. */\nconst PREVIEW_ROWS = 10;\n\n/** Characters buffered for the sniff when the input has fewer than PREVIEW_ROWS line breaks. */\nconst PREVIEW_CHARS = 64 * 1024;\n\nconst LF = 10;\nconst CR = 13;\n\n/** Tokeniser state: at the start of a field. */\nconst START = 0;\n/** Tokeniser state: inside an unquoted field. */\nconst UNQUOTED = 1;\n/** Tokeniser state: inside a quoted field. */\nconst QUOTED = 2;\n/** Tokeniser state: just after a quote inside a quoted field (a second quote is a literal, anything else ends the field). */\nconst CLOSING = 3;\n/** Tokeniser state: after a closed quoted field, before the delimiter (text here is malformed). */\nconst AFTER_QUOTED = 4;\n/** Inside a leading comment line (skipped up to its line break). */\nconst COMMENT = 5;\n\ntype State = typeof START | typeof UNQUOTED | typeof QUOTED | typeof CLOSING | typeof AFTER_QUOTED | typeof COMMENT;\n\n/** The delimiter and quote of a reader. */\nexport interface RecordSyntax {\n /** The field delimiter, one character; null sniffs it from the first rows. */\n readonly delimiter: string | null;\n /** The quote character, one character. */\n readonly quote: string;\n /** The delimiters tried when `delimiter` is null; DELIMITER_CANDIDATES by default. */\n readonly candidates?: readonly string[] | undefined;\n /**\n * Characters that open a comment line while no record has been read yet (SNAP `#`, KONECT\n * `%`): such leading lines are skipped, kept in `leadingComments` and left out of the delimiter\n * sniff. A later line starting with one of them is an ordinary record. Default: none.\n */\n readonly comments?: readonly string[] | undefined;\n /**\n * Whether the delimiter sniff skips a candidate under which a closing quote is followed by\n * other text (see sniffDelimiter). False by default: that text then aborts the read.\n */\n readonly skipQuoteErrors?: boolean | undefined;\n}\n\n/**\n * Check a delimiter or quote option: exactly one character that is not a line break, and the two\n * must differ.\n * @param syntax - the delimiter (or null for sniffing) and quote\n * @returns the syntax unchanged; E_UNSUPPORTED when invalid\n */\nexport function checkRecordSyntax(syntax: RecordSyntax): RecordSyntax {\n for (const [option, value] of [\n [\"delimiter\", syntax.delimiter],\n [\"quote\", syntax.quote],\n ] as const) {\n if (value === null) {\n continue;\n }\n if (value.length !== 1 || value === \"\\n\" || value === \"\\r\") {\n throw new GraphFormatError(\n \"E_UNSUPPORTED\",\n `option ${option}: ${JSON.stringify(value)} is not a single non-line-break character`,\n { option, found: value },\n );\n }\n }\n if (syntax.delimiter !== null && syntax.delimiter === syntax.quote) {\n throw new GraphFormatError(\"E_UNSUPPORTED\", \"options delimiter and quote must differ\", {\n option: \"delimiter\",\n found: syntax.delimiter,\n });\n }\n return syntax;\n}\n\n/**\n * Sniff the line terminator of a text: a lone `\\r` only when the text has `\\r` and no `\\n` at all\n * (classic Mac files); `\\n` otherwise.\n * @param text - the preview text\n * @returns \"\\n\" or \"\\r\"\n */\nexport function sniffNewline(text: string): \"\\n\" | \"\\r\" {\n return !text.includes(\"\\n\") && text.includes(\"\\r\") ? \"\\r\" : \"\\n\";\n}\n\n/**\n * Split a text into records synchronously (the first `maxRows` of them), honouring quotes; for\n * the delimiter sniff and the registry's head sniff, where the input is a bounded preview.\n * @param text - the text\n * @param delimiter - the delimiter\n * @param quote - the quote character\n * @param maxRows - the most rows to return\n * @param strictQuotes - return null when a closing quote is followed by text other than the\n * delimiter or a line break (the import would abort under this delimiter)\n * @returns the rows as cell arrays (blank lines skipped), or null (see strictQuotes)\n */\nfunction splitRecords(\n text: string,\n delimiter: string,\n quote: string,\n maxRows: number,\n strictQuotes = false,\n): string[][] | null {\n const rows: string[][] = [];\n const delimiterCode = delimiter.charCodeAt(0);\n const quoteCode = quote.charCodeAt(0);\n let cells: string[] = [];\n let state: State = START;\n let segment = 0;\n let field = \"\";\n const n = text.length;\n for (let i = 0; i < n && rows.length < maxRows; i++) {\n const c = text.charCodeAt(i);\n if (state === QUOTED) {\n if (c === quoteCode) {\n field += text.slice(segment, i);\n state = CLOSING;\n }\n continue;\n }\n if (state === CLOSING) {\n if (c === quoteCode) {\n field += quote;\n segment = i + 1;\n state = QUOTED;\n continue;\n }\n if (strictQuotes && c !== delimiterCode && c !== LF && c !== CR) {\n return null;\n }\n state = AFTER_QUOTED;\n segment = i;\n }\n if (c === delimiterCode || c === LF || c === CR) {\n if (state === UNQUOTED || state === AFTER_QUOTED) {\n field += text.slice(segment, i);\n }\n if (c === delimiterCode) {\n cells.push(field);\n field = \"\";\n state = START;\n } else {\n if (state !== START || cells.length > 0) {\n cells.push(field);\n rows.push(cells);\n cells = [];\n field = \"\";\n }\n state = START;\n if (c === CR && text.charCodeAt(i + 1) === LF) {\n i++;\n }\n }\n segment = i + 1;\n continue;\n }\n if (state === START) {\n if (c === quoteCode) {\n state = QUOTED;\n segment = i + 1;\n } else {\n state = UNQUOTED;\n segment = i;\n }\n }\n }\n if (rows.length < maxRows && (state !== START || cells.length > 0)) {\n if (state === UNQUOTED || state === AFTER_QUOTED || state === QUOTED) {\n field += text.slice(segment, n);\n }\n cells.push(field);\n rows.push(cells);\n }\n return rows;\n}\n\n/**\n * The preview text without its leading comment lines (those starting with one of the comment\n * characters), so the sniff sees the records only.\n * @param text - the preview text\n * @param comments - the comment characters\n * @returns the text from the first non-comment line on\n */\nfunction stripLeadingComments(text: string, comments: readonly string[]): string {\n if (comments.length === 0) {\n return text;\n }\n let at = 0;\n while (at < text.length && comments.includes(text[at])) {\n const lf = text.indexOf(\"\\n\", at);\n const cr = text.indexOf(\"\\r\", at);\n const end = Math.min(lf < 0 ? Infinity : lf, cr < 0 ? Infinity : cr);\n if (end === Infinity) {\n return \"\";\n }\n at = end + 1;\n if (text[at - 1] === \"\\r\" && text[at] === \"\\n\") {\n at++;\n }\n }\n return at === 0 ? text : text.slice(at);\n}\n\n/**\n * Sniff the delimiter of a text: every candidate is tried over the first rows and the one whose\n * field count is most consistent across rows wins (ties broken by the higher field count); a\n * candidate that yields fewer than two fields per row on average is never chosen. `null` when no\n * candidate qualifies (a single-column file).\n * @param text - the preview text\n * @param newline - the sniffed line terminator (unused by the splitter, which reads every kind;\n * kept for callers that sniffed it)\n * @param candidates - the delimiters to try, in priority order\n * @param quote - the quote character\n * @param skipQuoteErrors - also never choose a candidate under which a closing quote is followed\n * by other text. Only for inputs whose field counts say nothing (an adjacency table's rows vary in\n * width): elsewhere a stray character after a quote would make a worse candidate win silently\n * instead of aborting the read\n * @returns the delimiter, or null\n */\nexport function sniffDelimiter(\n text: string,\n newline: \"\\n\" | \"\\r\" = \"\\n\",\n candidates: readonly string[] = DELIMITER_CANDIDATES,\n quote = '\"',\n skipQuoteErrors = false,\n): string | null {\n let best: string | null = null;\n let bestDelta = Infinity;\n let bestAverage = 0;\n const terminated = text.endsWith(\"\\n\") || text.endsWith(\"\\r\");\n for (const delimiter of candidates) {\n if (delimiter === quote || delimiter === newline) {\n continue;\n }\n const split = splitRecords(text, delimiter, quote, PREVIEW_ROWS, skipQuoteErrors);\n if (split === null) {\n // a quoted cell this delimiter does not close: it is not the file's delimiter\n continue;\n }\n let rows = split.filter((row) => !isBlankRow(row));\n if (rows.length > 1 && !terminated) {\n // the preview is a prefix of the file: its last row may be cut short\n rows = rows.slice(0, -1);\n }\n if (rows.length === 0) {\n continue;\n }\n let total = 0;\n let delta = 0;\n for (let i = 0; i < rows.length; i++) {\n const count = rows[i].length;\n total += count;\n if (i > 0) {\n delta += Math.abs(count - rows[i - 1].length);\n }\n }\n const average = total / rows.length;\n if (average > 1.99 && (delta < bestDelta || (delta === bestDelta && average > bestAverage))) {\n best = delimiter;\n bestDelta = delta;\n bestAverage = average;\n }\n }\n return best;\n}\n\n/**\n * Whether a parsed row is a blank line: one cell holding only whitespace.\n * @param row - the row\n * @returns true for a blank line\n */\nfunction isBlankRow(row: readonly string[]): boolean {\n return row.length === 1 && row[0].trim().length === 0;\n}\n\n/**\n * Reads the records of one input. Iterate with `for await (const count of reader)`: each\n * iteration fills `reader.cells[0..count)` and `reader.quoted[0..count)` and sets `reader.line`\n * to the 1-based line the record started on. Blank lines (an empty unquoted record of one field)\n * are skipped. The arrays are reused between records. When the syntax gives no delimiter, the\n * first rows (PREVIEW_ROWS, or PREVIEW_CHARS characters) are buffered and the delimiter sniffed\n * from them before the first record is yielded.\n */\nexport class RecordReader implements AsyncIterable<number> {\n /** The cells of the record most recently yielded; only the first `count` entries are valid. */\n readonly cells: string[] = [];\n\n /** Whether each cell of the record most recently yielded was quoted. */\n readonly quoted: boolean[] = [];\n\n /** The leading comment lines (without their line breaks), in order; empty without `syntax.comments`. */\n readonly leadingComments: string[] = [];\n\n private readonly input: ImportInput;\n\n private readonly report: ImportReportBuilder;\n\n private readonly readOptions: ReadOptions;\n\n /** The delimiter (null while unsniffed), quote and comment characters. */\n readonly syntax: RecordSyntax;\n\n private delimiterText: string | null;\n\n private recordLine = 0;\n\n /**\n * Create a reader; nothing is read until iteration starts.\n * @param input - the input (or an async iterable of already decoded text chunks)\n * @param report - the report decode and quoting errors are recorded in\n * @param syntax - the delimiter (null to sniff) and quote (already checked)\n * @param readOptions - cancellation and progress\n */\n constructor(input: ImportInput, report: ImportReportBuilder, syntax: RecordSyntax, readOptions: ReadOptions) {\n this.input = input;\n this.report = report;\n this.readOptions = readOptions;\n this.syntax = syntax;\n this.delimiterText = syntax.delimiter;\n }\n\n /**\n * The 1-based line the most recently yielded record started on.\n * @returns the line number; 0 before the first record\n */\n get line(): number {\n return this.recordLine;\n }\n\n /**\n * The delimiter in use.\n * @returns the given or sniffed delimiter; null before the sniff ran\n */\n get delimiter(): string | null {\n return this.delimiterText;\n }\n\n /**\n * Iterate the records.\n * @yields the number of cells of each record\n * @returns nothing\n */\n async *[Symbol.asyncIterator](): AsyncGenerator<number, void, undefined> {\n const scanner = new RecordScanner(this);\n for await (const chunk of this.chunks()) {\n // the first chunk arrives after the sniff (or with the given delimiter)\n scanner.setDelimiter((this.delimiterText ?? \",\").charCodeAt(0));\n let i = 0;\n while (i < chunk.length) {\n i = scanner.scan(chunk, i);\n if (scanner.ready) {\n scanner.ready = false;\n this.recordLine = scanner.recordLine;\n yield scanner.count;\n scanner.count = 0;\n }\n }\n scanner.endChunk(chunk);\n }\n if (scanner.finish()) {\n this.recordLine = scanner.recordLine;\n yield scanner.count;\n }\n }\n\n /**\n * Record a text-after-quote error (fatal).\n * @param line - the line the field started on\n * @returns never\n */\n badQuote(line: number): never {\n return this.report.fail(BAD_QUOTE_CODE, `line ${line}: text after the closing quote of a quoted field`, {\n line,\n });\n }\n\n /**\n * Record an unclosed-quote error (fatal).\n * @param line - the line the field started on\n * @returns never\n */\n unclosedQuote(line: number): never {\n return this.report.fail(UNCLOSED_QUOTE_CODE, `a quoted field starting on line ${line} is never closed`, {\n line,\n });\n }\n\n /**\n * The decoded text chunks of the input; when the delimiter is to be sniffed, the first rows\n * are buffered (bounded by PREVIEW_ROWS line breaks or PREVIEW_CHARS characters), the sniff\n * runs, and the buffered text is yielded as one chunk before the rest streams through.\n * @yields the text chunks\n * @returns nothing\n */\n private async *chunks(): AsyncGenerator<string, void, undefined> {\n const source = textChunks(this.input, this.report, this.readOptions);\n if (this.delimiterText !== null) {\n yield* source;\n return;\n }\n const pieces: string[] = [];\n let length = 0;\n let breaks = 0;\n let lastWasCr = false;\n let sniffed = false;\n for await (const chunk of source) {\n if (sniffed) {\n yield chunk;\n continue;\n }\n pieces.push(chunk);\n length += chunk.length;\n for (let i = 0; i < chunk.length && breaks < PREVIEW_ROWS; i++) {\n const c = chunk.charCodeAt(i);\n if (c === LF) {\n if (!lastWasCr) {\n breaks++;\n }\n } else if (c === CR) {\n breaks++;\n }\n lastWasCr = c === CR;\n }\n if (breaks < PREVIEW_ROWS && length < PREVIEW_CHARS) {\n continue;\n }\n const text = pieces.join(\"\");\n pieces.length = 0;\n this.sniff(text);\n sniffed = true;\n yield text;\n }\n if (!sniffed) {\n const text = pieces.join(\"\");\n if (text.length > 0) {\n this.sniff(text);\n yield text;\n }\n }\n }\n\n /**\n * Sniff the delimiter from the preview text and record it.\n * @param text - the preview\n */\n private sniff(text: string): void {\n const candidates = this.syntax.candidates ?? DELIMITER_CANDIDATES;\n // the sniff is a heuristic over the first rows: a single chunk holding a huge quoted cell\n // is capped so the candidate scans stay bounded\n const body = stripLeadingComments(text.slice(0, PREVIEW_CHARS), this.syntax.comments ?? []);\n this.delimiterText =\n sniffDelimiter(body, sniffNewline(body), candidates, this.syntax.quote, this.syntax.skipQuoteErrors) ??\n candidates[0];\n }\n}\n\n/**\n * The record state machine of RecordReader, resumable at every record end so the reader can\n * yield a record before the next one overwrites the shared cell arrays. Every state lives on the\n * instance; `scan()` runs the per-character loop over one chunk from a position and returns where\n * it stopped (after the character that completed a record, with `ready` set, or the chunk end).\n */\nclass RecordScanner {\n /** Whether a record just completed. */\n ready = false;\n\n /** The cell count of the record in progress (the completed one while `ready`). */\n count = 0;\n\n /** The line the completed record started on (valid while `ready`, and after finish()). */\n recordLine = 1;\n\n /** The line the record in progress started on. */\n private startLine = 1;\n\n private readonly reader: RecordReader;\n\n private readonly quoteCode: number;\n\n private readonly quoteText: string;\n\n private readonly commentCodes: readonly number[];\n\n private delimiterCode = -1;\n\n private state: State = START;\n\n private field = \"\";\n\n private fieldQuoted = false;\n\n private line = 1;\n\n private lastWasCr = false;\n\n /** Whether no record has started yet (comment lines are recognised until one does). */\n private leading: boolean;\n\n private comment = \"\";\n\n /** The start of the unconsumed run of the current chunk that belongs to the field or comment. */\n private segment = 0;\n\n /**\n * Create a scanner over a reader's cell arrays.\n * @param reader - the reader\n */\n constructor(reader: RecordReader) {\n this.reader = reader;\n this.quoteCode = reader.syntax.quote.charCodeAt(0);\n this.quoteText = reader.syntax.quote;\n this.commentCodes = (reader.syntax.comments ?? []).map((c) => c.charCodeAt(0));\n this.leading = this.commentCodes.length > 0;\n }\n\n /**\n * Set the delimiter once it is known (before the first chunk is scanned).\n * @param code - the delimiter's character code\n */\n setDelimiter(code: number): void {\n if (this.delimiterCode < 0) {\n this.delimiterCode = code;\n }\n }\n\n /**\n * Scan one chunk from a position until a record completes or the chunk ends.\n * @param chunk - the chunk\n * @param from - where to start\n * @returns the position after the last character consumed\n */\n scan(chunk: string, from: number): number {\n const { quoteCode, delimiterCode } = this;\n const n = chunk.length;\n let i = from;\n this.segment = from;\n while (i < n) {\n const c = chunk.charCodeAt(i);\n if (this.state === COMMENT) {\n if (c === LF || c === CR) {\n this.comment += chunk.slice(this.segment, i);\n this.reader.leadingComments.push(this.comment);\n this.comment = \"\";\n this.state = START;\n this.endLine(c);\n this.segment = i + 1;\n }\n i++;\n continue;\n }\n if (this.state === QUOTED) {\n // jump to the next quote; the run in between is field text whose line breaks are counted\n const q = chunk.indexOf(this.quoteText, i);\n const end = q < 0 ? n : q;\n if (end > i) {\n this.countLineBreaks(chunk, i, end);\n }\n if (q < 0) {\n i = n;\n break;\n }\n this.field += chunk.slice(this.segment, q);\n this.state = CLOSING;\n this.lastWasCr = false;\n i = q + 1;\n continue;\n }\n if (this.state === CLOSING) {\n if (c === quoteCode) {\n this.field += this.quoteText;\n this.segment = i + 1;\n this.state = QUOTED;\n this.lastWasCr = false;\n i++;\n continue;\n }\n if (c !== delimiterCode && c !== LF && c !== CR) {\n this.reader.badQuote(this.startLine);\n }\n this.state = AFTER_QUOTED;\n this.segment = i;\n // fall through to the delimiter / line-end handling below without consuming c\n }\n if (c === delimiterCode || c === LF || c === CR) {\n if (c === LF && this.lastWasCr) {\n // the second half of a CRLF already ended the record\n this.lastWasCr = false;\n this.segment = i + 1;\n i++;\n continue;\n }\n if (this.state === UNQUOTED) {\n this.field += chunk.slice(this.segment, i);\n }\n if (c === delimiterCode) {\n this.push();\n this.state = START;\n this.lastWasCr = false;\n this.segment = i + 1;\n i++;\n continue;\n }\n const blank = this.state === START && this.count === 0;\n if (!blank) {\n this.push();\n this.ready = true;\n this.recordLine = this.startLine;\n }\n this.state = START;\n this.endLine(c);\n this.segment = i + 1;\n i++;\n if (this.ready) {\n return i;\n }\n continue;\n }\n this.lastWasCr = false;\n if (this.state === START) {\n if (this.leading && this.count === 0 && this.commentCodes.includes(c)) {\n this.state = COMMENT;\n this.segment = i;\n i++;\n continue;\n }\n this.leading = false;\n if (c === quoteCode) {\n this.state = QUOTED;\n this.fieldQuoted = true;\n this.segment = i + 1;\n } else {\n this.state = UNQUOTED;\n this.segment = i;\n }\n }\n i++;\n }\n return i;\n }\n\n /**\n * Keep the tail of a chunk that belongs to an open field or comment.\n * @param chunk - the chunk just scanned to its end\n */\n endChunk(chunk: string): void {\n const n = chunk.length;\n if (this.segment >= n) {\n return;\n }\n if (this.state === COMMENT) {\n this.comment += chunk.slice(this.segment, n);\n } else if (this.state === QUOTED || this.state === UNQUOTED) {\n this.field += chunk.slice(this.segment, n);\n }\n this.segment = n;\n }\n\n /**\n * The end of the input: an open comment is kept, an open quote is fatal, an open record\n * (no trailing line break) is completed.\n * @returns true when a last record is ready\n */\n finish(): boolean {\n const { state } = this;\n if (state === COMMENT) {\n this.reader.leadingComments.push(this.comment);\n return false;\n }\n if (state === QUOTED) {\n this.reader.unclosedQuote(this.startLine);\n }\n if (state !== START || this.count > 0) {\n this.push();\n this.recordLine = this.startLine;\n return true;\n }\n return false;\n }\n\n /**\n * Count the line breaks of a run of quoted text (a CRLF counts once, like the record loop).\n * @param chunk - the chunk\n * @param from - the first index of the run\n * @param to - the index after the run\n */\n private countLineBreaks(chunk: string, from: number, to: number): void {\n let { line, lastWasCr } = this;\n for (let i = from; i < to; i++) {\n const c = chunk.charCodeAt(i);\n if (c === LF) {\n if (!lastWasCr) {\n line++;\n }\n lastWasCr = false;\n } else if (c === CR) {\n line++;\n lastWasCr = true;\n } else {\n lastWasCr = false;\n }\n }\n this.line = line;\n this.lastWasCr = lastWasCr;\n }\n\n /** Store the field in progress as the next cell. */\n private push(): void {\n const { reader, count } = this;\n reader.cells[count] = this.field;\n reader.quoted[count] = this.fieldQuoted;\n this.count = count + 1;\n this.field = \"\";\n this.fieldQuoted = false;\n }\n\n /**\n * Count a line break that ends a record or a comment line.\n * @param c - the LF or CR\n */\n private endLine(c: number): void {\n if (!(c === LF && this.lastWasCr)) {\n this.line++;\n }\n this.startLine = this.line;\n this.lastWasCr = c === CR;\n }\n}\n\n/** What the CSV importer's reader needs besides the input. */\nexport interface CsvReaderOptions extends ReadOptions {\n /** The delimiter; null or undefined sniffs it from the preview. */\n readonly delimiter?: string | null | undefined;\n /** The characters opening a leading comment line (RecordSyntax.comments); none by default. */\n readonly comments?: readonly string[] | undefined;\n /** RecordSyntax.skipQuoteErrors; false by default. */\n readonly skipQuoteErrors?: boolean | undefined;\n}\n\n/**\n * Records of a CSV input, one string array per row, streamed: iterate with\n * `for await (const row of reader)` and read `reader.line` for the 1-based line the row starts\n * on. The delimiter is known after the first row (`reader.delimiter`). Rows come out as fresh\n * arrays of cell texts exactly as written (no trimming, no typing); `reader.quoted` tells, for\n * the row just yielded, which cells were quoted (a quoted empty cell is the empty string, an\n * unquoted one is \"not set\"). Blank lines and whitespace-only single-cell lines are skipped.\n */\nexport class CsvRecordReader implements AsyncIterable<string[]> {\n private readonly inner: RecordReader;\n\n /**\n * Create a reader; nothing is read until iteration starts.\n * @param input - the input\n * @param report - the report parse errors are recorded in\n * @param options - the delimiter, cancellation and progress\n */\n constructor(input: ImportInput, report: ImportReportBuilder, options: CsvReaderOptions = {}) {\n this.inner = new RecordReader(\n input,\n report,\n {\n delimiter: options.delimiter ?? null,\n quote: '\"',\n comments: options.comments,\n skipQuoteErrors: options.skipQuoteErrors,\n },\n { signal: options.signal, onProgress: options.onProgress, encoding: options.encoding },\n );\n }\n\n /**\n * The leading comment lines the reader skipped (SNAP `#` lines, the KONECT `%` header), in order.\n * @returns the lines without their line breaks\n */\n get leadingComments(): readonly string[] {\n return this.inner.leadingComments;\n }\n\n /**\n * The 1-based line the most recently yielded row starts on.\n * @returns the line; 0 before the first row\n */\n get line(): number {\n return this.inner.line;\n }\n\n /**\n * The delimiter in use.\n * @returns the given or sniffed delimiter; null before the sniff ran\n */\n get delimiter(): string | null {\n return this.inner.delimiter;\n }\n\n /**\n * Whether each cell of the row most recently yielded was quoted.\n * @returns the flags (valid for the first `row.length` entries)\n */\n get quoted(): readonly boolean[] {\n return this.inner.quoted;\n }\n\n /**\n * Iterate the rows.\n * @yields one row at a time as its cell texts\n * @returns nothing\n */\n async *[Symbol.asyncIterator](): AsyncGenerator<string[], void, undefined> {\n const { inner } = this;\n for await (const count of inner) {\n if (count === 1 && !inner.quoted[0] && inner.cells[0].trim().length === 0) {\n continue;\n }\n yield inner.cells.slice(0, count);\n }\n }\n}\n"],"names":[],"mappings":";;AAuBO,MAAM,sBAAsB;AAG5B,MAAM,iBAAiB;AAGvB,MAAM,uBAA0C,OAAO,OAAO,CAAC,KAAK,KAAM,KAAK,KAAK,GAAG,CAAC;AAG/F,MAAM,eAAe;AAGrB,MAAM,gBAAgB,KAAK;AAE3B,MAAM,KAAK;AACX,MAAM,KAAK;AAGX,MAAM,QAAQ;AAEd,MAAM,WAAW;AAEjB,MAAM,SAAS;AAEf,MAAM,UAAU;AAEhB,MAAM,eAAe;AAErB,MAAM,UAAU;AA+BT,SAAS,kBAAkB,QAAoC;AAClE,aAAW,CAAC,QAAQ,KAAK,KAAK;AAAA,IAC1B,CAAC,aAAa,OAAO,SAAS;AAAA,IAC9B,CAAC,SAAS,OAAO,KAAK;AAAA,EAAA,GACd;AACR,QAAI,UAAU,MAAM;AAChB;AAAA,IACJ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