@domorium/validator 2.2.0 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ import type { PayloadKind } from "../types/structure";
2
+ import type { GedcomDialect } from "../validator/versionRegistry";
3
+ export declare function escapePayload(value: string, dialect: GedcomDialect, kind: PayloadKind["kind"]): string;
4
+ export declare function unescapePayload(value: string, dialect: GedcomDialect, kind: PayloadKind["kind"]): string;
@@ -0,0 +1,2 @@
1
+ /** The extensions of the files a genealogy program attaches to a medium. */
2
+ export declare const KNOWN_FILE_EXTENSIONS: ReadonlySet<string>;
@@ -0,0 +1,6 @@
1
+ export type FilePathProblem = "absolute" | "parent-folder" | "unescaped-character";
2
+ /**
3
+ * Why a GEDCOM 7 local file reference, a relative URI reference with no
4
+ * scheme, names no file beside the document, or nothing where it does.
5
+ */
6
+ export declare function filePathProblem(path: string): FilePathProblem | undefined;
@@ -1,3 +1,4 @@
1
+ import type { FilePathProblem } from "../payload/filePath";
1
2
  import { Range } from "./position";
2
3
  /**
3
4
  * Every code this package emits. A consumer filters, suppresses or offers a
@@ -39,6 +40,29 @@ export declare enum GedcomErrorCode {
39
40
  * silent and held to it, as its calendars are the same ones.
40
41
  */
41
42
  ImpossibleYear = "VAL016",
43
+ /**
44
+ * A line break in a value whose datatype keeps to one line. Answered for a
45
+ * value about to be written; a file that already has one is not reported.
46
+ */
47
+ SpansLines = "VAL017",
48
+ /**
49
+ * A value for a structure the standard gives no payload descriptor. Answered
50
+ * for a value about to be written; a file that already has one is not reported.
51
+ */
52
+ ValueNotAllowed = "VAL018",
53
+ /**
54
+ * A GEDCOM 7 record an empty value would leave with neither a payload nor a
55
+ * substructure, which 7.0 forbids of every structure. Answered for a value
56
+ * about to be written only.
57
+ */
58
+ EmptyStructure = "VAL019",
59
+ /**
60
+ * A GEDCOM 7 local file path that names no file beside the document. Answered
61
+ * for a value about to be written; a file that already has one is not reported.
62
+ */
63
+ FileTargetUnsupported = "VAL020",
64
+ /** A 5.5.1 multimedia format outside the standard's list that is a known file extension. */
65
+ ToleratedForm = "VAL021",
42
66
  /** A pointer whose xref names no record of the required type. */
43
67
  UnresolvedXref = "unresolved-xref",
44
68
  /** A line whose level cannot follow the line above it. */
@@ -56,6 +80,20 @@ export interface GedcomError {
56
80
  xref?: string;
57
81
  requiredRecordTag?: string;
58
82
  expectedLevel?: number;
83
+ missingTag?: string;
84
+ /** Absent where the missing structure belongs at the root. */
85
+ parentTag?: string;
86
+ /** The document has no `HEAD` record at all, as against one without a version. */
87
+ missingHeader?: boolean;
88
+ day?: number;
89
+ month?: string;
90
+ monthLength?: number;
91
+ year?: number;
92
+ calendar?: string;
93
+ /** Set only where the tag is a standard one written in the wrong case. */
94
+ meantTag?: string;
95
+ tag?: string;
96
+ pathProblem?: FilePathProblem;
59
97
  };
60
98
  range: Range;
61
99
  level: "error" | "warning" | "info";
@@ -0,0 +1,37 @@
1
+ import type { GedcomError } from "./errors";
2
+ export type PayloadKind = {
3
+ kind: "text" | "integer" | "boolean" | "date" | "date-period" | "date-exact" | "time" | "age" | "language-tag" | "media-type" | "latitude" | "longitude" | "personal-name" | "tag-definition" | "none";
4
+ } | {
5
+ kind: "enum";
6
+ values: string[];
7
+ multiple: boolean;
8
+ /** Set where a value outside `values` that is a known file extension is a warning, not an error. */
9
+ tolerates?: "file-extension";
10
+ } | {
11
+ kind: "pointer" | "text-or-pointer";
12
+ to: string;
13
+ };
14
+ export interface StructureField {
15
+ tag: string;
16
+ schemaId: string;
17
+ min: number;
18
+ max: number | null;
19
+ payload: PayloadKind;
20
+ payloadRequired: boolean;
21
+ lineBreaks: boolean;
22
+ prose: boolean;
23
+ }
24
+ export interface StructureShape {
25
+ schemaId: string;
26
+ payload: PayloadKind;
27
+ payloadRequired: boolean;
28
+ lineBreaks: boolean;
29
+ prose: boolean;
30
+ fields: StructureField[];
31
+ }
32
+ export interface PayloadProblem {
33
+ code: string;
34
+ message: string;
35
+ data?: GedcomError["data"];
36
+ level: "error" | "warning" | "info";
37
+ }
@@ -13,6 +13,7 @@
13
13
  */
14
14
  import { GedcomScheme } from "../schemes/schema-types";
15
15
  import type { GedcomDate } from "../types/date";
16
+ import { ExtensionContext } from "./extensions";
16
17
  export declare const LENGTHS: Record<string, number>;
17
18
  export interface ImpossibleYear {
18
19
  year: number;
@@ -26,7 +27,7 @@ export interface ImpossibleDay {
26
27
  }
27
28
  export declare function isLeapYear(year: number, calendar: string): boolean;
28
29
  export declare function daysInMonth(month: string, year: number | null, calendar: string): number | null;
29
- export declare function impossibleDays(scheme: GedcomScheme, value: string): ImpossibleDay[];
30
+ export declare function impossibleDays(scheme: GedcomScheme, value: string, extensions?: ExtensionContext): ImpossibleDay[];
30
31
  /**
31
32
  * Judged on what a grammar read rather than on tokens: only the grammar knows
32
33
  * that `0BC` is a year and an epoch, or that `_CAL 0` is not Gregorian.
@@ -0,0 +1,5 @@
1
+ import type { ASTNode } from "../parser";
2
+ import type { GedcomScheme, GedcomType } from "../schemes/schema-types";
3
+ import type { PayloadProblem } from "../types/structure";
4
+ import type { ExtensionContext } from "./extensions";
5
+ export declare function checkPayload(scheme: GedcomScheme, pointers: Map<string, ASTNode[]>, extensions: ExtensionContext, parentType: GedcomType, tag: string, value: string, occurrences: number, replacing?: ASTNode): PayloadProblem[];
@@ -0,0 +1,5 @@
1
+ import type { GedcomScheme, GedcomType } from "../schemes/schema-types";
2
+ export declare function lineBreaksOf(scheme: GedcomScheme, type: GedcomType): {
3
+ lineBreaks: boolean;
4
+ prose: boolean;
5
+ };
@@ -2,6 +2,7 @@ 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
+ import type { PayloadKind } from "../types/structure";
5
6
  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" | "age-v7" | "personal-name" | "latitude" | "longitude" | "media-type" | "language-tag" | "tag-def" | null;
6
7
  export declare const PAYLOAD_FIELD_TYPES: Record<string, Exclude<FieldType, null>>;
7
8
  export declare class RuleNode {
@@ -15,6 +16,10 @@ export declare class RuleNode {
15
16
  type: FieldType;
16
17
  to: GedcomType | undefined;
17
18
  };
19
+ payloadShape(tagType: GedcomType): {
20
+ payload: PayloadKind;
21
+ required: boolean;
22
+ };
18
23
  private mayOmitPayload;
19
24
  private validateEnumeration;
20
25
  getAvailableValues(tagType: GedcomType): string[] | null;
@@ -0,0 +1,6 @@
1
+ import type { GedcomScheme } from "../schemes/schema-types";
2
+ import { GedcomType } from "../schemes/schema-types";
3
+ import type { StructureShape } from "../types/structure";
4
+ import type { RuleNode } from "./rule-node";
5
+ export declare function typeAtPath(scheme: GedcomScheme, path: readonly string[]): GedcomType | undefined;
6
+ export declare function structureShape(scheme: GedcomScheme, ruleNode: RuleNode, type: GedcomType): StructureShape | undefined;
@@ -1,11 +1,21 @@
1
- import { GedcomType, GedcomScheme } from "../schemes/schema-types";
1
+ import { GedcomTag, GedcomType, Payload, GedcomScheme } from "../schemes/schema-types";
2
2
  import { ASTNode } from "../parser";
3
3
  import { GedcomError } from "../types/errors";
4
+ import type { Range } from "../types/position";
4
5
  import { ExtensionContext } from "./extensions";
5
6
  export declare function parseCardinality(str: string): {
6
7
  min: number;
7
8
  max: number;
8
9
  } | null;
10
+ export interface Rule {
11
+ min: number;
12
+ max: number;
13
+ type: GedcomType;
14
+ payload: Payload;
15
+ }
16
+ export declare function getRules(scheme: GedcomScheme, parentType: GedcomType): Map<GedcomTag, Rule> | undefined;
17
+ export declare function unknownTagError(rules: Map<GedcomTag, Rule>, tag: GedcomTag, parentTag: string | undefined, range: Range): GedcomError;
18
+ export declare function tooManyError(tag: GedcomTag, parentTag: string | undefined, range: Range): GedcomError;
9
19
  export declare function schemeFor(nodes: ASTNode[]): GedcomScheme;
10
20
  export declare class GedcomValidator {
11
21
  private readonly pointers;
@@ -29,6 +29,7 @@ export type VersionResolution = ({
29
29
  } | ({
30
30
  kind: "undetermined";
31
31
  range: Range;
32
+ missingHeader: boolean;
32
33
  } & SchemaChoice);
33
34
  /** The schema a caller names outright, for text that carries no header. */
34
35
  export declare function schemaForDialect(dialect: GedcomDialect): SchemaChoice;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domorium/validator",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "description": "GEDCOM 5.5.1 and 7.0 parser and validator",
5
5
  "keywords": [
6
6
  "gedcom",