@xml-auditfile/auditfile 0.0.0-stage → 0.0.2-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +183 -2
  3. package/package.json +62 -4
  4. package/src/auditfile.js +186 -0
  5. package/src/definitions/dialect.js +40 -0
  6. package/src/definitions/element-definition.js +27 -0
  7. package/src/definitions/localized-text.js +41 -0
  8. package/src/definitions/manifest.js +160 -0
  9. package/src/definitions/names.js +42 -0
  10. package/src/definitions/resources.js +29 -0
  11. package/src/definitions/view-definition.js +160 -0
  12. package/src/diagnostics/collector.js +139 -0
  13. package/src/diagnostics/diagnostic.js +53 -0
  14. package/src/diagnostics/report.js +56 -0
  15. package/src/generated/spec.js +74 -0
  16. package/src/index.js +20 -0
  17. package/src/internal/composite-key.js +2 -0
  18. package/src/internal/decimal.js +193 -0
  19. package/src/internal/encoding.js +118 -0
  20. package/src/internal/json.js +106 -0
  21. package/src/internal/sha256.js +147 -0
  22. package/src/internal/streams.js +232 -0
  23. package/src/internal/xml-reader.js +247 -0
  24. package/src/memory/memory-sink.js +68 -0
  25. package/src/reading/mapping-plan.js +91 -0
  26. package/src/reading/read-options.js +136 -0
  27. package/src/reading/read-session.js +446 -0
  28. package/src/reading/row-loader.js +362 -0
  29. package/src/reading/row.js +123 -0
  30. package/src/reading/source.js +146 -0
  31. package/src/reading/value-converter.js +136 -0
  32. package/src/schema/schema.js +256 -0
  33. package/src/sinks/sink.js +53 -0
  34. package/src/validation/reference-checker.js +146 -0
  35. package/src/validation/xaf-rules.js +167 -0
  36. package/src/versioning/version-resolver.js +119 -0
  37. package/src/versioning/version.js +217 -0
  38. package/src/views/view-result.js +20 -0
  39. package/src/views/view-runner.js +449 -0
  40. package/src/xsd/datatypes.js +141 -0
  41. package/src/xsd/regex.js +121 -0
  42. package/src/xsd/schema-set.js +555 -0
  43. package/src/xsd/validator.js +484 -0
  44. package/types/auditfile.d.ts +57 -0
  45. package/types/definitions/dialect.d.ts +27 -0
  46. package/types/definitions/element-definition.d.ts +16 -0
  47. package/types/definitions/localized-text.d.ts +25 -0
  48. package/types/definitions/manifest.d.ts +118 -0
  49. package/types/definitions/names.d.ts +25 -0
  50. package/types/definitions/resources.d.ts +9 -0
  51. package/types/definitions/view-definition.d.ts +85 -0
  52. package/types/diagnostics/collector.d.ts +38 -0
  53. package/types/diagnostics/diagnostic.d.ts +37 -0
  54. package/types/diagnostics/report.d.ts +32 -0
  55. package/types/generated/spec.d.ts +6 -0
  56. package/types/index.d.ts +18 -0
  57. package/types/internal/composite-key.d.ts +2 -0
  58. package/types/internal/decimal.d.ts +55 -0
  59. package/types/internal/encoding.d.ts +43 -0
  60. package/types/internal/json.d.ts +17 -0
  61. package/types/internal/sha256.d.ts +17 -0
  62. package/types/internal/streams.d.ts +35 -0
  63. package/types/internal/xml-reader.d.ts +50 -0
  64. package/types/memory/memory-sink.d.ts +29 -0
  65. package/types/reading/mapping-plan.d.ts +45 -0
  66. package/types/reading/read-options.d.ts +69 -0
  67. package/types/reading/read-session.d.ts +28 -0
  68. package/types/reading/row-loader.d.ts +18 -0
  69. package/types/reading/row.d.ts +53 -0
  70. package/types/reading/source.d.ts +73 -0
  71. package/types/reading/value-converter.d.ts +15 -0
  72. package/types/schema/schema.d.ts +116 -0
  73. package/types/sinks/sink.d.ts +59 -0
  74. package/types/validation/reference-checker.d.ts +11 -0
  75. package/types/validation/xaf-rules.d.ts +13 -0
  76. package/types/versioning/version-resolver.d.ts +25 -0
  77. package/types/versioning/version.d.ts +71 -0
  78. package/types/views/view-result.d.ts +13 -0
  79. package/types/views/view-runner.d.ts +1 -0
  80. package/types/xsd/datatypes.d.ts +40 -0
  81. package/types/xsd/regex.d.ts +6 -0
  82. package/types/xsd/schema-set.d.ts +20 -0
  83. package/types/xsd/validator.d.ts +48 -0
@@ -0,0 +1,45 @@
1
+ /**
2
+ * The paths of an import as a tree, built once per import: every node knows its table, column or group.
3
+ * Reading an element is then one lookup of its local name under the current node, instead of building the
4
+ * full path as a string and looking that up. Only known paths have a node, so a file cannot make the tree grow.
5
+ */
6
+ export declare class MappingPlan {
7
+ #private;
8
+ /** Above the root element: its only child is the root element of the version. */
9
+ root: PathNode;
10
+ /** @param {import('../schema/schema.js').AuditfileSchema} schema */
11
+ constructor(schema: import('../schema/schema.js').AuditfileSchema);
12
+ }
13
+ /** A known element or attribute path. */
14
+ export declare class PathNode {
15
+ path: string;
16
+ /** @type {TablePlan | null} */
17
+ table: TablePlan | null;
18
+ /** @type {{ table: TablePlan, column: import('../schema/schema.js').SchemaColumn } | null} */
19
+ column: {
20
+ table: TablePlan;
21
+ column: import('../schema/schema.js').SchemaColumn;
22
+ } | null;
23
+ /** A flattened element or pure container: no table and no column. */
24
+ isGroup: boolean;
25
+ /** @type {Map<string, PathNode>} Child elements by local name. */
26
+ children: Map<string, PathNode>;
27
+ /** @type {Map<string, PathNode>} Attributes by local name. */
28
+ attributes: Map<string, PathNode>;
29
+ /** @param {string} path The full path, e.g. "auditfile/company/transactions"; attributes as ".../@name". */
30
+ constructor(path: string);
31
+ /** The path of an unknown child, for a diagnostic. */
32
+ childPath(localName: any): any;
33
+ }
34
+ export declare class TablePlan {
35
+ table: import("../schema/schema.js").SchemaTable;
36
+ /** A repeating simple element: one "value" column read from the element text. */
37
+ isValueTable: boolean;
38
+ /** @type {{ column: import('../schema/schema.js').SchemaColumn, group: PathNode | null }[]} Columns with minOccurs ≥ 1, with the group they are in. */
39
+ required: {
40
+ column: import('../schema/schema.js').SchemaColumn;
41
+ group: PathNode | null;
42
+ }[];
43
+ /** @param {import('../schema/schema.js').SchemaTable} table */
44
+ constructor(table: import('../schema/schema.js').SchemaTable);
45
+ }
@@ -0,0 +1,69 @@
1
+ import { AuditfileVersion } from '../versioning/version.js';
2
+ /** How the reader treats the file. */
3
+ export declare const ReadMode: Readonly<{
4
+ /** Validate against the XSD first; load only a valid file. */
5
+ Verified: "verified";
6
+ /** Load directly with the manifest; elements outside the manifest are reported and skipped. */
7
+ Unverified: "unverified";
8
+ }>;
9
+ /** Progress of a read. */
10
+ export declare class ReadProgress {
11
+ /** Rows read so far. */
12
+ rowsRead: any;
13
+ /** Total rows, when known from the scan phase; otherwise null. */
14
+ totalRows: any;
15
+ }
16
+ export type ReadOptions = {
17
+ /**
18
+ * Force a version, e.g. `AuditfileVersion.Financial.V3_2` or "xaf/3.2". Null: determine from the namespace.
19
+ */
20
+ version?: AuditfileVersion | string | null;
21
+ /**
22
+ * Verified (default) or unverified.
23
+ */
24
+ mode?: 'verified' | 'unverified';
25
+ /**
26
+ * Derive the version from an unknown namespace, e.g. ".../XAF/3.2/". Off by default.
27
+ */
28
+ useResolver?: boolean;
29
+ /**
30
+ * Own XSD instead of the built-in one, as a factory of bytes or a stream. Null: use the built-in XSD.
31
+ */
32
+ xsd?: (() => unknown) | null;
33
+ /**
34
+ * Apply known dialect corrections. On by default.
35
+ */
36
+ applyDialects?: boolean;
37
+ /**
38
+ * Rows per table handed to the sink at once (default 1000).
39
+ */
40
+ batchSize?: number;
41
+ /**
42
+ * Language of diagnostic messages (default Dutch).
43
+ */
44
+ language?: 'nl' | 'en';
45
+ /**
46
+ * Maximum number of diagnostics; the rest is summarized (default 1000).
47
+ */
48
+ maxDiagnostics?: number;
49
+ /**
50
+ * Maximum element nesting; deeper files are refused (default 64).
51
+ */
52
+ maxDepth?: number;
53
+ /**
54
+ * Maximum characters in the whole document, all parts together; a larger file stops with XAF-X001 (default 4 Gi; 0 is no limit).
55
+ */
56
+ maxCharactersInDocument?: number;
57
+ /**
58
+ * Maximum characters of one value; a longer value is skipped with XAF-S008 and never held in memory as a whole (default 65536; the longest value an XSD allows is 999).
59
+ */
60
+ maxValueLength?: number;
61
+ /**
62
+ * Receives progress after every batch.
63
+ */
64
+ onProgress?: ((progress: ReadProgress) => void) | null;
65
+ /**
66
+ * Cancels reading, in the scan phase as well as the load phase; the call then rejects with the signal's reason.
67
+ */
68
+ signal?: AbortSignal | null;
69
+ };
@@ -0,0 +1,28 @@
1
+ import { DiagnosticCollector } from '../diagnostics/collector.js';
2
+ import { AuditfileReport } from '../diagnostics/report.js';
3
+ import { AuditfileSchema } from '../schema/schema.js';
4
+ /**
5
+ * One read of one source: resolve the version, optionally scan (validate and count),
6
+ * then load (stream rows). Holds the diagnostics and the part statistics.
7
+ */
8
+ export declare class ReadSession {
9
+ #private;
10
+ diagnostics: DiagnosticCollector;
11
+ /** @type {import('../versioning/version-resolver.js').Resolution | null} */
12
+ resolution: import('../versioning/version-resolver.js').Resolution | null;
13
+ /** @type {AuditfileSchema | null} */
14
+ schema: AuditfileSchema | null;
15
+ /** True when the load phase must validate against the XSD itself (single-use source). */
16
+ validateDuringLoad: boolean;
17
+ constructor(source: any, options: any);
18
+ get parts(): any;
19
+ /** Resolves the version and runs the scan phase when useful. Returns false when loading must not start. */
20
+ prepare(sinkNeedsRowCounts: any, scanOnly?: boolean): Promise<boolean>;
21
+ /** The load phase as a stream of rows. Diagnostics are collected along the way. Can be iterated once. */
22
+ load(): AsyncGenerator<import("./row.js").AuditfileRow, void, unknown>;
23
+ /** True when the load phase has read the whole file. */
24
+ get loaded(): boolean;
25
+ createReport(loaded: any): AuditfileReport;
26
+ /** Releases a document kept for loading that will not be loaded after all. */
27
+ dispose(): Promise<void>;
28
+ }
@@ -0,0 +1,18 @@
1
+ import { AuditfileRow } from './row.js';
2
+ /**
3
+ * The load phase: walks the XML once and turns elements into rows using the mapping plan.
4
+ * A row is emitted when its element closes, so all its columns are known; ids are assigned when it opens,
5
+ * so they follow document order. Only the open elements are kept in memory.
6
+ */
7
+ export declare class RowLoader {
8
+ #private;
9
+ /** True when reading stopped on a fatal error. */
10
+ stopped: boolean;
11
+ /**
12
+ * @param {import('../internal/xml-reader.js').XmlReader} reader
13
+ * @param {((event: object) => void) | null} validate Feeds the XSD validator, when validating during load.
14
+ */
15
+ constructor(reader: import('../internal/xml-reader.js').XmlReader, schema: any, resolution: any, options: any, diagnostics: any, observers: any, validate: ((event: object) => void) | null);
16
+ /** @returns {AsyncGenerator<AuditfileRow>} Rows in document order of their closing tags. */
17
+ rows(): AsyncGenerator<AuditfileRow>;
18
+ }
@@ -0,0 +1,53 @@
1
+ import { Decimal } from '../internal/decimal.js';
2
+ /**
3
+ * One row of a table. {@link AuditfileRow#values} follows the column order of {@link AuditfileRow#table};
4
+ * the JavaScript type of a value follows the column type (string, Decimal, number, Date, string "HH:MM:SS", boolean) or is null.
5
+ *
6
+ * Prefer the typed accessors ({@link AuditfileRow#getDecimal}, {@link AuditfileRow#getString}, ...) over {@link AuditfileRow#get}:
7
+ * they check the column type and say what is wrong. Every accessor takes a column name or a `SchemaColumn`; in a loop over
8
+ * many rows, look the column up once with `table.findColumn()` and pass it.
9
+ */
10
+ export declare class AuditfileRow {
11
+ #private;
12
+ /** @type {import('../schema/schema.js').SchemaTable} The table this row belongs to. */
13
+ table: import('../schema/schema.js').SchemaTable;
14
+ /** Unique within the import; assigned in document order. */
15
+ id: any;
16
+ /** Id of the parent row, or null for the root. */
17
+ parentId: any;
18
+ /** Position under the parent row (1-based), per table. */
19
+ ordinal: any;
20
+ /** Source part the row came from (1-based). */
21
+ part: any;
22
+ /** @type {readonly unknown[]} Column values in column order. */
23
+ values: readonly unknown[];
24
+ /**
25
+ * Value of a column.
26
+ * @param {string | import('../schema/schema.js').SchemaColumn} column
27
+ * @throws {RangeError} The column does not exist in this table.
28
+ */
29
+ get(column: string | import('../schema/schema.js').SchemaColumn): unknown;
30
+ /**
31
+ * True when this table has the column (a column may exist in one version and not in another).
32
+ * @param {string} column
33
+ */
34
+ has(column: string): boolean;
35
+ /** @returns {string | null} A string column. @throws {RangeError | TypeError} */
36
+ getString(column: any): string | null;
37
+ /**
38
+ * A decimal column, or an integer column as a Decimal (a column can be integer in one version and decimal in another).
39
+ * @returns {Decimal | null}
40
+ * @throws {RangeError | TypeError}
41
+ */
42
+ getDecimal(column: any): Decimal | null;
43
+ /** @returns {number | null} An integer column. @throws {RangeError | TypeError} */
44
+ getInteger(column: any): number | null;
45
+ /** @returns {Date | null} A date column (midnight UTC). @throws {RangeError | TypeError} */
46
+ getDate(column: any): Date | null;
47
+ /** @returns {Date | null} A date-time column, or a date column at midnight UTC. @throws {RangeError | TypeError} */
48
+ getDateTime(column: any): Date | null;
49
+ /** @returns {string | null} A time column, "HH:MM:SS". @throws {RangeError | TypeError} */
50
+ getTime(column: any): string | null;
51
+ /** @returns {boolean | null} A boolean column. @throws {RangeError | TypeError} */
52
+ getBoolean(column: any): boolean | null;
53
+ }
@@ -0,0 +1,73 @@
1
+ /** Opens a part; internal so callers cannot bypass the single-use check. */
2
+ export declare const OPEN: unique symbol;
3
+ /** A source used in a way it does not allow, such as reading a single-use stream twice: the caller's mistake. */
4
+ export declare class SourceUsageError extends Error {
5
+ constructor(message: any);
6
+ }
7
+ /**
8
+ * Where an audit file comes from: one stream, or several streams for the parts of a split audit file.
9
+ * The reader never opens files itself; the caller supplies the streams, so the same code runs on a server and in the browser.
10
+ * A factory can be read twice (scan, then load); a plain stream only once.
11
+ *
12
+ * A stream is a Node Readable, a web ReadableStream, a Blob, a Uint8Array, an ArrayBuffer,
13
+ * or any (async) iterable of Uint8Array chunks.
14
+ */
15
+ export declare class AuditfileSource {
16
+ /** @type {readonly SourcePart[]} The parts in reading order. */
17
+ parts: readonly SourcePart[];
18
+ /** @param {SourcePart[]} parts */
19
+ constructor(parts: SourcePart[]);
20
+ /** True when every part can be opened again, so the reader can scan before loading. */
21
+ get canReadTwice(): boolean;
22
+ /**
23
+ * A stream that can be read only once. The reader does not close or destroy it.
24
+ * @param {unknown} stream
25
+ * @param {string} [name]
26
+ */
27
+ static fromStream(stream: unknown, name?: string): AuditfileSource;
28
+ /**
29
+ * A split audit file as streams that can be read only once: the first part followed by its continuation parts, in order.
30
+ * The reader does not close or destroy the streams.
31
+ * @param {...[string, unknown]} parts
32
+ */
33
+ static fromStreams(...parts: [string, unknown][]): AuditfileSource;
34
+ /**
35
+ * A stream factory that returns a fresh stream (or a promise of one) on every call, so the source can be read twice.
36
+ * The reader closes the streams it gets.
37
+ * @example
38
+ * AuditfileSource.fromFactory(() => fs.createReadStream('admin.xaf'), 'admin.xaf');
39
+ * AuditfileSource.fromFactory(() => bytes);
40
+ * @param {() => unknown} open
41
+ * @param {string} [name]
42
+ */
43
+ static fromFactory(open: () => unknown, name?: string): AuditfileSource;
44
+ /**
45
+ * A split audit file as stream factories: the first part followed by its continuation parts, in order.
46
+ * Every factory returns a fresh stream on every call, so the source can be read twice. The reader closes the streams it gets.
47
+ * @param {...[string, () => unknown]} parts
48
+ */
49
+ static fromFactories(...parts: [string, () => unknown][]): AuditfileSource;
50
+ }
51
+ /** One part of a source. */
52
+ export declare class SourcePart {
53
+ #private;
54
+ /** Part number (1-based). */
55
+ number: any;
56
+ /** File or stream name. */
57
+ name: any;
58
+ /** True when the part can be opened more than once. */
59
+ reopenable: any;
60
+ }
61
+ /** Size, checksum and line count of a source part, known after it has been read once. */
62
+ export declare class PartInfo {
63
+ /** Part number (1-based). */
64
+ number: any;
65
+ /** File or stream name. */
66
+ name: any;
67
+ /** Size in bytes. */
68
+ size: any;
69
+ /** SHA-256 of the bytes as read, lowercase hex. */
70
+ sha256: any;
71
+ /** Number of lines. */
72
+ lines: any;
73
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Empty text becomes null. Returns `{ ok: false }` when the text is not valid for the type.
3
+ * @param {string} raw
4
+ * @param {string} type One of {@link ColumnType}.
5
+ * @returns {{ ok: boolean, value: unknown }}
6
+ */
7
+ export declare function tryConvert(raw: string, type: string): {
8
+ ok: boolean;
9
+ value: unknown;
10
+ };
11
+ /**
12
+ * Text form of a value for keys and messages: dates as yyyy-mm-dd, decimals as written.
13
+ * @param {unknown} value
14
+ */
15
+ export declare function toText(value: unknown): string;
@@ -0,0 +1,116 @@
1
+ import { ManifestKey, ManifestReference } from '../definitions/manifest.js';
2
+ import { AuditfileVersion } from '../versioning/version.js';
3
+ /** How the version of an import was determined. */
4
+ export declare const VersionSource: Readonly<{
5
+ /** The file uses the official namespace. */
6
+ Official: "official";
7
+ /** The file uses a known alias namespace. */
8
+ Alias: "alias";
9
+ /** The caller forced the version. */
10
+ Forced: "forced";
11
+ /** The resolver derived the version from the namespace. */
12
+ Resolved: "resolved";
13
+ }>;
14
+ /**
15
+ * The schema of one import: tables, columns, types, keys, references, row counts and origin.
16
+ * This is the contract everything after the reader builds on, regardless of where the data is stored.
17
+ * Converts to and from JSON without loss (definitions are re-attached from the version when known).
18
+ */
19
+ export declare class AuditfileSchema {
20
+ #private;
21
+ /** Version key, e.g. "xaf/3.2". */
22
+ versionKey: any;
23
+ /** @type {AuditfileVersion | null} The version, or null when this reader does not know it (schema loaded from JSON). */
24
+ version: AuditfileVersion | null;
25
+ /** Namespace as found in the file. */
26
+ namespace: any;
27
+ /** How the version was determined, one of {@link VersionSource}. */
28
+ source: any;
29
+ /** Name of the applied dialect, or null. */
30
+ dialect: any;
31
+ /** True when the row count is known for every table. */
32
+ hasRowCounts: any;
33
+ /** @type {readonly SchemaTable[]} All tables in document order. */
34
+ tables: readonly SchemaTable[];
35
+ /**
36
+ * Finds a table by name, or returns null.
37
+ * @param {string} name
38
+ * @returns {SchemaTable | null}
39
+ */
40
+ findTable(name: string): SchemaTable | null;
41
+ /**
42
+ * Returns a table by name.
43
+ * @param {string} name
44
+ * @throws {RangeError} The table does not exist.
45
+ */
46
+ table(name: string): SchemaTable;
47
+ /** Serializes the schema to compact JSON, e.g. for storage in a database. */
48
+ toJson(): string;
49
+ /**
50
+ * Reads a schema written by {@link AuditfileSchema#toJson}.
51
+ * @param {string} json
52
+ * @throws {SyntaxError} The JSON is not a valid schema, or uses a format version, column type or version source this reader does not know.
53
+ */
54
+ static fromJson(json: string): AuditfileSchema;
55
+ }
56
+ /** A table of an import. */
57
+ export declare class SchemaTable {
58
+ #private;
59
+ /** Table name, e.g. "tr_line". */
60
+ name: any;
61
+ /** Element name, e.g. "trLine". */
62
+ xmlName: any;
63
+ /** Full XML path. */
64
+ path: any;
65
+ /** Parent table name, or null for the root. */
66
+ parent: any;
67
+ /** Minimum occurrences relative to the XML parent element. */
68
+ minOccurs: any;
69
+ /** Maximum occurrences relative to the XML parent element; null means unbounded. */
70
+ maxOccurs: any;
71
+ /** Required by the standard. */
72
+ isRequired: any;
73
+ /** Expected in practice. */
74
+ isExpected: any;
75
+ /** Number of rows, when known from the scan phase; otherwise null. */
76
+ rowCount: any;
77
+ /** Position in the schema. */
78
+ index: any;
79
+ /** @type {readonly SchemaColumn[]} Columns; {@link AuditfileRow#values} uses the same order. */
80
+ columns: readonly SchemaColumn[];
81
+ /** @type {readonly ManifestKey[]} Natural keys. */
82
+ keys: readonly ManifestKey[];
83
+ /** @type {readonly ManifestReference[]} References to keys of other tables. */
84
+ references: readonly ManifestReference[];
85
+ /** @type {import('../definitions/element-definition.js').ElementDefinition | null} Documentation, when available. */
86
+ definition: import('../definitions/element-definition.js').ElementDefinition | null;
87
+ /**
88
+ * Finds a column by name, or returns null.
89
+ * @param {string} name
90
+ * @returns {SchemaColumn | null}
91
+ */
92
+ findColumn(name: string): SchemaColumn | null;
93
+ toString(): any;
94
+ }
95
+ /** A column of an import table. */
96
+ export declare class SchemaColumn {
97
+ /** Column name. */
98
+ name: any;
99
+ /** Element or attribute name. */
100
+ xmlName: any;
101
+ /** Path relative to the table element. */
102
+ path: any;
103
+ /** "element" or "attribute". */
104
+ kind: any;
105
+ /** Logical type, one of {@link ColumnType}; determines the JavaScript type of the value. */
106
+ type: any;
107
+ /** XSD type name. */
108
+ xsdType: any;
109
+ /** Minimum occurrences relative to the XML parent element. */
110
+ minOccurs: any;
111
+ /** Position in {@link AuditfileRow#values}. */
112
+ index: any;
113
+ /** @type {import('../definitions/element-definition.js').ElementDefinition | null} Documentation, when available. */
114
+ definition: import('../definitions/element-definition.js').ElementDefinition | null;
115
+ toString(): any;
116
+ }
@@ -0,0 +1,59 @@
1
+ /** What a sink needs from the reader (bit flags). */
2
+ export declare const SinkCapabilities: Readonly<{
3
+ /** Nothing special. */
4
+ None: 0;
5
+ /** The sink wants row counts before the first row (e.g. to pre-allocate); the reader scans first. */
6
+ NeedsRowCounts: 1;
7
+ }>;
8
+ export type Sink = {
9
+ /**
10
+ * What the sink needs, as {@link SinkCapabilities} flags.
11
+ */
12
+ capabilities?: number;
13
+ /**
14
+ * Start of an import. The schema contains row counts when the reader scanned first.
15
+ */
16
+ begin: (context: ImportContext) => void | Promise<void>;
17
+ /**
18
+ * A batch of rows of one table. Child rows can arrive before their parent row; ids are already assigned.
19
+ */
20
+ write: (table: import('../schema/schema.js').SchemaTable, rows: readonly import('../reading/row.js').AuditfileRow[]) => void | Promise<void>;
21
+ /**
22
+ * The import is complete; commit.
23
+ */
24
+ complete: (report: import('../diagnostics/report.js').AuditfileReport) => void | Promise<void>;
25
+ /**
26
+ * The import failed; discard everything received since begin.
27
+ */
28
+ abort: (report: import('../diagnostics/report.js').AuditfileReport) => void | Promise<void>;
29
+ };
30
+ /**
31
+ * Receives an import: first the schema, then rows per table in batches, then completion or abort.
32
+ * All validation, merging and reporting happens before the sink, so a custom sink gets the same result as a built-in one.
33
+ * Every method may return a promise.
34
+ *
35
+ * @typedef {object} Sink
36
+ * @property {number} [capabilities] What the sink needs, as {@link SinkCapabilities} flags.
37
+ * @property {(context: ImportContext) => void | Promise<void>} begin Start of an import. The schema contains row counts when the reader scanned first.
38
+ * @property {(table: import('../schema/schema.js').SchemaTable, rows: readonly import('../reading/row.js').AuditfileRow[]) => void | Promise<void>} write
39
+ * A batch of rows of one table. Child rows can arrive before their parent row; ids are already assigned.
40
+ * @property {(report: import('../diagnostics/report.js').AuditfileReport) => void | Promise<void>} complete The import is complete; commit.
41
+ * @property {(report: import('../diagnostics/report.js').AuditfileReport) => void | Promise<void>} abort The import failed; discard everything received since begin.
42
+ */
43
+ /** Information at the start of an import. */
44
+ export declare class ImportContext {
45
+ /** @type {import('../schema/schema.js').AuditfileSchema} The import schema. */
46
+ schema: import('../schema/schema.js').AuditfileSchema;
47
+ /** @type {readonly import('../reading/source.js').SourcePart[]} The source parts. */
48
+ parts: readonly import('../reading/source.js').SourcePart[];
49
+ }
50
+ /** Discards everything; used for validation. */
51
+ export declare const NULL_SINK: Readonly<{
52
+ capabilities: 0;
53
+ begin(): void;
54
+ write(): void;
55
+ complete(): void;
56
+ abort(): void;
57
+ }>;
58
+ /** @param {unknown} sink */
59
+ export declare function checkSink(sink: unknown): unknown;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Checks keys (unique) and references (existing) from the schema.
3
+ * Only key values and unresolved reference values are kept in memory; references are resolved at the end,
4
+ * so a reference to a key that appears later (e.g. in a later part) is still found.
5
+ */
6
+ export declare class ReferenceChecker {
7
+ #private;
8
+ constructor(schema: any, diagnostics: any);
9
+ onRow(row: any): void;
10
+ onEnd(): void;
11
+ }
@@ -0,0 +1,13 @@
1
+ /** Audit file type these rules apply to. */
2
+ export declare const XAF = "xaf";
3
+ /**
4
+ * Business rules for Auditfile Financieel (XAF):
5
+ * every transaction balances, and the counts and totals in the headers match the lines.
6
+ * Rules whose tables or columns do not exist in a version are skipped. Columns are looked up once, not per row.
7
+ */
8
+ export declare class XafRules {
9
+ #private;
10
+ constructor(schema: any, diagnostics: any);
11
+ onRow(row: any): void;
12
+ onEnd(): void;
13
+ }
@@ -0,0 +1,25 @@
1
+ import { AuditfileVersion } from './version.js';
2
+ /** The outcome of version resolution. */
3
+ export declare class Resolution {
4
+ /** @type {AuditfileVersion} */
5
+ version: AuditfileVersion;
6
+ source: any;
7
+ fileNamespace: any;
8
+ /** @type {import('../definitions/dialect.js').Dialect | null} Set later when header/softwareDesc selects a dialect. */
9
+ dialect: import('../definitions/dialect.js').Dialect | null;
10
+ constructor(version: any, source: any, fileNamespace: any, dialect: any);
11
+ get needsMapping(): boolean;
12
+ /**
13
+ * Recognizes a dialect by the software description in the header, when none was recognized by namespace.
14
+ * Returns true when a dialect was found.
15
+ * @param {string} software
16
+ * @param {boolean} applyDialects
17
+ */
18
+ useSoftware(software: string, applyDialects: boolean): boolean;
19
+ }
20
+ /**
21
+ * Determines the version: forced by the caller, then the registry (official namespace, alias or dialect),
22
+ * then optionally the resolver. Anything else is fatal.
23
+ * @returns {Resolution | null}
24
+ */
25
+ export declare function resolveVersion(rootName: any, fileNamespace: any, options: any, diagnostics: any): Resolution | null;
@@ -0,0 +1,71 @@
1
+ import { Dialect } from '../definitions/dialect.js';
2
+ import { ElementDefinition } from '../definitions/element-definition.js';
3
+ import { AuditfileManifest } from '../definitions/manifest.js';
4
+ import { ViewDefinition } from '../definitions/view-definition.js';
5
+ /**
6
+ * One audit file type and version, with its manifest, XSD, definitions and dialects.
7
+ * Use the constants, e.g. `AuditfileVersion.Financial.V3_2`, or {@link AuditfileVersion.parse} with "xaf/3.2".
8
+ */
9
+ export declare class AuditfileVersion {
10
+ #private;
11
+ /** Registry key, e.g. "xaf/3.2". */
12
+ key: string;
13
+ /** Audit file type, e.g. "xaf". */
14
+ type: string;
15
+ /** Type name used for version objects, e.g. "financial". */
16
+ typeName: string;
17
+ /** Version, e.g. "3.2". */
18
+ version: string;
19
+ /** Folder of the definitions, e.g. "standards/xaf/3_2". */
20
+ folder: string;
21
+ /** Name of the root element. */
22
+ rootElement: string;
23
+ /** "official" or "reconstructed". */
24
+ provenance: string;
25
+ /** The official namespace. */
26
+ namespace: string;
27
+ /** @type {readonly string[]} Other namespaces known to be used for this version. */
28
+ aliases: readonly string[];
29
+ /** @type {readonly AuditfileVersion[]} All versions this reader knows, in registry order. */
30
+ static get all(): readonly AuditfileVersion[];
31
+ /** True when the XSD is the official one published by the Belastingdienst. */
32
+ get hasOfficialXsd(): boolean;
33
+ /** @type {AuditfileManifest} Structure: tables and columns. */
34
+ get manifest(): AuditfileManifest;
35
+ /** @type {ReadonlyMap<string, ElementDefinition>} Definitions by key ("tr_line", "tr_line.amnt"). */
36
+ get definitions(): ReadonlyMap<string, ElementDefinition>;
37
+ /** @type {readonly Dialect[]} Known dialects of this version. */
38
+ get dialects(): readonly Dialect[];
39
+ /** @type {readonly ViewDefinition[]} Views of this audit file type, e.g. the trial balance. Shared by all versions of the type. */
40
+ get views(): readonly ViewDefinition[];
41
+ /**
42
+ * Finds a view by name, or returns null.
43
+ * @param {string} name
44
+ */
45
+ findView(name: string): ViewDefinition | null;
46
+ /**
47
+ * Finds a version by key, e.g. "xaf/3.2" (case-insensitive). Returns null when unknown.
48
+ * @param {string} key
49
+ */
50
+ static find(key: string): AuditfileVersion | null;
51
+ /**
52
+ * Returns the version for a key such as "xaf/3.2".
53
+ * @param {string} key
54
+ * @throws {RangeError} The key is unknown.
55
+ */
56
+ static parse(key: string): AuditfileVersion;
57
+ /** The bytes of the XSD of this version. */
58
+ openXsd(): Uint8Array<ArrayBuffer>;
59
+ /** The compiled XSD of this version, ready for validation. Compiled once and shared; it is immutable. */
60
+ createSchemaSet(): any;
61
+ toString(): string;
62
+ }
63
+ export declare namespace AuditfileVersion {
64
+ var Financial: Readonly<{}>;
65
+ var CashRegister: Readonly<{}>;
66
+ var TaxiOnboardComputer: Readonly<{}>;
67
+ var TripRegistration: Readonly<{}>;
68
+ var Payroll: Readonly<{}>;
69
+ }
70
+ /** The groups of version constants, for the test that compares them with the registry. */
71
+ export declare const VERSION_GROUPS: readonly string[];
@@ -0,0 +1,13 @@
1
+ /** The outcome of running a {@link ViewDefinition}. */
2
+ export declare class ViewResult {
3
+ /** @type {import('../definitions/view-definition.js').ViewDefinition} The view that was run. */
4
+ view: import('../definitions/view-definition.js').ViewDefinition;
5
+ /** False when the version lacks a table or column the view needs (XAF-Q001); there are no rows then. */
6
+ isAvailable: any;
7
+ /** @type {readonly (readonly unknown[])[]} Result rows, sorted by the view's orderBy; one value per column. */
8
+ rows: readonly (readonly unknown[])[];
9
+ /** @type {readonly import('../diagnostics/diagnostic.js').Diagnostic[]} Findings while running the view. */
10
+ diagnostics: readonly import('../diagnostics/diagnostic.js').Diagnostic[];
11
+ /** Output columns; each row has one value per column, in this order. */
12
+ get columns(): readonly import("../definitions/view-definition.js").ViewColumn[];
13
+ }
@@ -0,0 +1 @@
1
+ export {};