@xml-auditfile/auditfile 0.0.0-stage → 0.0.2-alpha.3
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 +201 -0
- package/README.md +183 -2
- package/package.json +62 -4
- package/src/auditfile.js +186 -0
- package/src/definitions/dialect.js +40 -0
- package/src/definitions/element-definition.js +27 -0
- package/src/definitions/localized-text.js +41 -0
- package/src/definitions/manifest.js +160 -0
- package/src/definitions/names.js +42 -0
- package/src/definitions/resources.js +29 -0
- package/src/definitions/view-definition.js +160 -0
- package/src/diagnostics/collector.js +139 -0
- package/src/diagnostics/diagnostic.js +53 -0
- package/src/diagnostics/report.js +56 -0
- package/src/generated/spec.js +74 -0
- package/src/index.js +20 -0
- package/src/internal/composite-key.js +2 -0
- package/src/internal/decimal.js +193 -0
- package/src/internal/encoding.js +118 -0
- package/src/internal/json.js +106 -0
- package/src/internal/sha256.js +147 -0
- package/src/internal/streams.js +232 -0
- package/src/internal/xml-reader.js +247 -0
- package/src/memory/memory-sink.js +68 -0
- package/src/reading/mapping-plan.js +91 -0
- package/src/reading/read-options.js +136 -0
- package/src/reading/read-session.js +446 -0
- package/src/reading/row-loader.js +362 -0
- package/src/reading/row.js +123 -0
- package/src/reading/source.js +146 -0
- package/src/reading/value-converter.js +136 -0
- package/src/schema/schema.js +256 -0
- package/src/sinks/sink.js +53 -0
- package/src/validation/reference-checker.js +146 -0
- package/src/validation/xaf-rules.js +167 -0
- package/src/versioning/version-resolver.js +119 -0
- package/src/versioning/version.js +217 -0
- package/src/views/view-result.js +20 -0
- package/src/views/view-runner.js +449 -0
- package/src/xsd/datatypes.js +141 -0
- package/src/xsd/regex.js +121 -0
- package/src/xsd/schema-set.js +555 -0
- package/src/xsd/validator.js +484 -0
- package/types/auditfile.d.ts +57 -0
- package/types/definitions/dialect.d.ts +27 -0
- package/types/definitions/element-definition.d.ts +16 -0
- package/types/definitions/localized-text.d.ts +25 -0
- package/types/definitions/manifest.d.ts +118 -0
- package/types/definitions/names.d.ts +25 -0
- package/types/definitions/resources.d.ts +9 -0
- package/types/definitions/view-definition.d.ts +85 -0
- package/types/diagnostics/collector.d.ts +38 -0
- package/types/diagnostics/diagnostic.d.ts +37 -0
- package/types/diagnostics/report.d.ts +32 -0
- package/types/generated/spec.d.ts +6 -0
- package/types/index.d.ts +18 -0
- package/types/internal/composite-key.d.ts +2 -0
- package/types/internal/decimal.d.ts +55 -0
- package/types/internal/encoding.d.ts +43 -0
- package/types/internal/json.d.ts +17 -0
- package/types/internal/sha256.d.ts +17 -0
- package/types/internal/streams.d.ts +35 -0
- package/types/internal/xml-reader.d.ts +50 -0
- package/types/memory/memory-sink.d.ts +29 -0
- package/types/reading/mapping-plan.d.ts +45 -0
- package/types/reading/read-options.d.ts +69 -0
- package/types/reading/read-session.d.ts +28 -0
- package/types/reading/row-loader.d.ts +18 -0
- package/types/reading/row.d.ts +53 -0
- package/types/reading/source.d.ts +73 -0
- package/types/reading/value-converter.d.ts +15 -0
- package/types/schema/schema.d.ts +116 -0
- package/types/sinks/sink.d.ts +59 -0
- package/types/validation/reference-checker.d.ts +11 -0
- package/types/validation/xaf-rules.d.ts +13 -0
- package/types/versioning/version-resolver.d.ts +25 -0
- package/types/versioning/version.d.ts +71 -0
- package/types/views/view-result.d.ts +13 -0
- package/types/views/view-runner.d.ts +1 -0
- package/types/xsd/datatypes.d.ts +40 -0
- package/types/xsd/regex.d.ts +6 -0
- package/types/xsd/schema-set.d.ts +20 -0
- package/types/xsd/validator.d.ts +48 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/** Severity of a diagnostic, from least to most severe. */
|
|
2
|
+
export const DiagnosticSeverity = Object.freeze({
|
|
3
|
+
/** Information only. */
|
|
4
|
+
Info: 'info',
|
|
5
|
+
/** Something to look at; the result is still usable. */
|
|
6
|
+
Warning: 'warning',
|
|
7
|
+
/** The file does not meet the standard. */
|
|
8
|
+
Error: 'error',
|
|
9
|
+
/** Reading stopped. */
|
|
10
|
+
Fatal: 'fatal',
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const RANK = new Map([['info', 0], ['warning', 1], ['error', 2], ['fatal', 3]]);
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Orders severities: negative when `a` is less severe than `b`.
|
|
17
|
+
* @param {string} a
|
|
18
|
+
* @param {string} b
|
|
19
|
+
*/
|
|
20
|
+
export function compareSeverity(a, b) {
|
|
21
|
+
return RANK.get(a) - RANK.get(b);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** A finding about an audit file, with a stable code from auditfile-spec. */
|
|
25
|
+
export class Diagnostic {
|
|
26
|
+
/** @internal */
|
|
27
|
+
constructor(code, layer, severity, message, part, line, position, path) {
|
|
28
|
+
/** Code, e.g. "XAF-R001". */
|
|
29
|
+
this.code = code;
|
|
30
|
+
/** "xml", "version", "structure", "xsd", "rules", "dialect" or "view". */
|
|
31
|
+
this.layer = layer;
|
|
32
|
+
/** Severity, one of {@link DiagnosticSeverity}. */
|
|
33
|
+
this.severity = severity;
|
|
34
|
+
/** Message in the requested language. */
|
|
35
|
+
this.message = message;
|
|
36
|
+
/** Source part (1-based), when known; otherwise null. */
|
|
37
|
+
this.part = part;
|
|
38
|
+
/** Line number, when known; otherwise null. */
|
|
39
|
+
this.line = line;
|
|
40
|
+
/** Position on the line, when known; otherwise null. */
|
|
41
|
+
this.position = position;
|
|
42
|
+
/** XML path, when known; otherwise null. */
|
|
43
|
+
this.path = path;
|
|
44
|
+
Object.freeze(this);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
toString() {
|
|
48
|
+
const severity = this.severity[0].toUpperCase() + this.severity.slice(1);
|
|
49
|
+
return this.line === null
|
|
50
|
+
? `${this.code} ${severity}: ${this.message}`
|
|
51
|
+
: `${this.code} ${severity} (line ${this.line}): ${this.message}`;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { DiagnosticSeverity } from './diagnostic.js';
|
|
2
|
+
|
|
3
|
+
/** Outcome of a scan, validation or read. */
|
|
4
|
+
export class AuditfileReport {
|
|
5
|
+
#counts;
|
|
6
|
+
|
|
7
|
+
/** @internal */
|
|
8
|
+
constructor(schema, parts, diagnostics, counts, truncated, rowCounts, loaded, duration) {
|
|
9
|
+
/** @type {import('../schema/schema.js').AuditfileSchema | null} The import schema, or null when the version could not be determined. */
|
|
10
|
+
this.schema = schema;
|
|
11
|
+
/** @type {readonly import('../reading/source.js').PartInfo[]} Source parts with size and SHA-256 (empty when a part was not read completely). */
|
|
12
|
+
this.parts = Object.freeze([...parts]);
|
|
13
|
+
/**
|
|
14
|
+
* @type {readonly import('./diagnostic.js').Diagnostic[]} The diagnostics, in the order they were found, at most `maxDiagnostics`
|
|
15
|
+
* plus XAF-X900 when more were found. A full list makes room for errors by leaving out infos and warnings; fatal diagnostics are always included.
|
|
16
|
+
*/
|
|
17
|
+
this.diagnostics = Object.freeze([...diagnostics]);
|
|
18
|
+
/** True when diagnostics were left out of {@link AuditfileReport#diagnostics}; {@link AuditfileReport#count} still counts them. */
|
|
19
|
+
this.isTruncated = truncated;
|
|
20
|
+
/** @type {ReadonlyMap<string, number>} Rows per table. */
|
|
21
|
+
this.rowCounts = new Map(rowCounts);
|
|
22
|
+
/** True when rows were handed to the sink and completed. */
|
|
23
|
+
this.loaded = loaded;
|
|
24
|
+
/** Time taken, in milliseconds. */
|
|
25
|
+
this.duration = duration;
|
|
26
|
+
this.#counts = Object.freeze({ ...counts });
|
|
27
|
+
Object.freeze(this);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** True when a fatal diagnostic was found: reading stopped. */
|
|
31
|
+
get hasFatal() {
|
|
32
|
+
return this.#counts.fatal > 0;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** True when an error or fatal diagnostic was found, also when it is not in a truncated {@link AuditfileReport#diagnostics}. */
|
|
36
|
+
get hasErrors() {
|
|
37
|
+
return this.hasFatal || this.#counts.error > 0;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** True when there are no errors and no fatal diagnostics. */
|
|
41
|
+
get isValid() {
|
|
42
|
+
return !this.hasErrors;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Number of diagnostics with the given severity, including the ones left out of a truncated {@link AuditfileReport#diagnostics}.
|
|
47
|
+
* @param {string} severity One of {@link DiagnosticSeverity}.
|
|
48
|
+
*/
|
|
49
|
+
count(severity) {
|
|
50
|
+
if (!Object.values(DiagnosticSeverity).includes(severity)) {
|
|
51
|
+
throw new RangeError(`Unknown severity '${severity}'.`);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return this.#counts[severity];
|
|
55
|
+
}
|
|
56
|
+
}
|