@domorium/validator 1.2.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +63 -0
- package/README.md +48 -0
- package/dist/index.cjs.js +2 -2
- package/dist/index.d.ts +3 -0
- package/dist/index.esm.js +650 -518
- package/dist/types/errors.d.ts +34 -0
- package/dist/validator/date-v7.d.ts +9 -0
- package/dist/validator/extensions.d.ts +7 -6
- package/dist/validator/index.d.ts +1 -1
- package/dist/validator/rule-node.d.ts +6 -4
- package/dist/validator/validate.d.ts +1 -0
- package/package.json +1 -1
package/dist/types/errors.d.ts
CHANGED
|
@@ -1,4 +1,38 @@
|
|
|
1
1
|
import { Range } from "./position";
|
|
2
|
+
/**
|
|
3
|
+
* Every code this package emits. A consumer filters, suppresses or offers a
|
|
4
|
+
* fix by code, so each kind of problem needs one of its own.
|
|
5
|
+
*/
|
|
6
|
+
export declare enum GedcomErrorCode {
|
|
7
|
+
/** A tag the schema does not define in this position. */
|
|
8
|
+
UnknownTag = "VAL001",
|
|
9
|
+
/** A structure the schema requires is absent. */
|
|
10
|
+
MissingTag = "VAL002",
|
|
11
|
+
/** The payload is absent where one is required. */
|
|
12
|
+
MissingValue = "VAL003",
|
|
13
|
+
/** The payload is present and does not match its data type. */
|
|
14
|
+
IncorrectValue = "VAL004",
|
|
15
|
+
/** The payload is not one of the values the schema permits here. */
|
|
16
|
+
ShouldBeSetValue = "VAL005",
|
|
17
|
+
/** A pointer payload that is not written as a pointer. */
|
|
18
|
+
MissingRef = "VAL006",
|
|
19
|
+
/** More occurrences than the cardinality allows. */
|
|
20
|
+
ManyOccurrences = "VAL007",
|
|
21
|
+
/** A GEDCOM 7 extension tag used without a HEAD.SCHMA declaration. */
|
|
22
|
+
UndocumentedTag = "VAL008",
|
|
23
|
+
/** A tag declared more than once in HEAD.SCHMA. */
|
|
24
|
+
DuplicateDeclaration = "VAL009",
|
|
25
|
+
/** An event with neither a payload nor substructures asserts nothing. */
|
|
26
|
+
EmptyEvent = "VAL010",
|
|
27
|
+
/** A pointer whose xref names no record of the required type. */
|
|
28
|
+
UnresolvedXref = "unresolved-xref",
|
|
29
|
+
/** A line whose level cannot follow the line above it. */
|
|
30
|
+
InvalidLevel = "invalid-level",
|
|
31
|
+
/** The text could not be tokenized. */
|
|
32
|
+
Lexer = "LEXER",
|
|
33
|
+
/** The tokens could not be assembled into a tree. */
|
|
34
|
+
Parser = "PARSER"
|
|
35
|
+
}
|
|
2
36
|
export interface GedcomError {
|
|
3
37
|
code: string;
|
|
4
38
|
message: string;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { GedcomScheme } from "../schemes/schema-types";
|
|
2
|
+
import { ExtensionContext } from "./extensions";
|
|
3
|
+
export declare function isValidDateValue(value: string, scheme: GedcomScheme, extensions?: ExtensionContext): boolean;
|
|
4
|
+
export declare function isValidDatePeriod(value: string, scheme: GedcomScheme, extensions?: ExtensionContext): boolean;
|
|
5
|
+
/**
|
|
6
|
+
* `DateExact` names no calendar and takes no epoch: it is day, month and year in
|
|
7
|
+
* the Gregorian calendar, and all three are required.
|
|
8
|
+
*/
|
|
9
|
+
export declare function isValidDateExact(value: string, scheme: GedcomScheme, extensions?: ExtensionContext): boolean;
|
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
import { ASTNode } from "../parser";
|
|
2
|
-
import { GedcomTag } from "../schemes/schema-types";
|
|
2
|
+
import { GedcomScheme, GedcomTag } from "../schemes/schema-types";
|
|
3
3
|
import { GedcomError } from "../types/errors";
|
|
4
|
-
|
|
5
|
-
UndocumentedTag = "VAL008",
|
|
6
|
-
DuplicateDeclaration = "VAL009"
|
|
7
|
-
}
|
|
4
|
+
import { Range } from "../types/position";
|
|
8
5
|
export declare function isExtensionTag(tag: string): boolean;
|
|
9
6
|
export interface ExtensionContext {
|
|
10
7
|
tags: Map<GedcomTag, string>;
|
|
8
|
+
aliases: Map<GedcomTag, GedcomTag>;
|
|
11
9
|
requireDeclaration: boolean;
|
|
12
10
|
}
|
|
13
11
|
export declare function emptyExtensions(): ExtensionContext;
|
|
12
|
+
/** The standard tag `tag` abbreviates, or `tag` itself. */
|
|
13
|
+
export declare function resolveTag(extensions: ExtensionContext, tag: string): GedcomTag;
|
|
14
|
+
export declare function undocumentedTag(tag: GedcomTag, range: Range): GedcomError;
|
|
14
15
|
export declare function parseTagDef(value: string): {
|
|
15
16
|
tag: GedcomTag;
|
|
16
17
|
uri: string;
|
|
17
18
|
} | null;
|
|
18
|
-
export declare function collectExtensions(nodes: ASTNode[], requireDeclaration: boolean): {
|
|
19
|
+
export declare function collectExtensions(nodes: ASTNode[], requireDeclaration: boolean, scheme: GedcomScheme): {
|
|
19
20
|
context: ExtensionContext;
|
|
20
21
|
errors: GedcomError[];
|
|
21
22
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { GedcomValidator } from "./validate";
|
|
1
|
+
export { GedcomValidator, schemeFor } from "./validate";
|
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import { GedcomScheme, GedcomType } from "../schemes/schema-types";
|
|
2
2
|
import { ASTNode } from "../parser";
|
|
3
3
|
import { GedcomError } from "../types/errors";
|
|
4
|
-
|
|
4
|
+
import { ExtensionContext } from "./extensions";
|
|
5
|
+
type FieldType = "boolean" | "string" | "nonNegativeInteger" | "select" | "multiselect" | "date" | "date-v7" | "date-period" | "date-period-v7" | "date-exact" | "date-exact-v7" | "time" | "time-v7" | "pointer" | "age" | "personal-name" | "media-type" | "language-tag" | "tag-def" | null;
|
|
5
6
|
export declare class RuleNode {
|
|
6
7
|
private readonly scheme;
|
|
7
|
-
pointers: ASTNode[];
|
|
8
8
|
private readonly pointerMap;
|
|
9
|
-
|
|
9
|
+
private readonly extensions;
|
|
10
|
+
constructor(scheme: GedcomScheme, pointerMap: Map<string, ASTNode[]>, extensions?: ExtensionContext);
|
|
10
11
|
/** Whether `xref` names a record of the kind this pointer type expects. */
|
|
11
12
|
private isPointerTarget;
|
|
12
13
|
getFieldType(tagType: GedcomType): {
|
|
13
14
|
type: FieldType;
|
|
14
|
-
isList: boolean;
|
|
15
15
|
to: GedcomType | undefined;
|
|
16
16
|
};
|
|
17
|
+
private mayOmitPayload;
|
|
18
|
+
private validateEnumeration;
|
|
17
19
|
getAvailableValues(tagType: GedcomType): string[] | null;
|
|
18
20
|
/**
|
|
19
21
|
* CONT/CONC are universal line-continuation tags: they are deliberately
|
|
@@ -2,6 +2,7 @@ import { GedcomType, GedcomScheme } from "../schemes/schema-types";
|
|
|
2
2
|
import { ASTNode } from "../parser";
|
|
3
3
|
import { GedcomError } from "../types/errors";
|
|
4
4
|
import { ExtensionContext } from "./extensions";
|
|
5
|
+
export declare function schemeFor(nodes: ASTNode[]): GedcomScheme;
|
|
5
6
|
export declare class GedcomValidator {
|
|
6
7
|
private readonly pointers;
|
|
7
8
|
private readonly extensions;
|