@domorium/validator 1.8.2 → 2.0.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.
@@ -2,10 +2,14 @@
2
2
  * The part of a date the grammar cannot express: `31 FEB` is two well-formed
3
3
  * tokens naming a day February does not have.
4
4
  *
5
- * GREGORIAN and JULIAN share the twelve month tags and their lengths, and
6
- * differ only in which years February gets a 29th, which is why one table
7
- * serves both. HEBREW and FRENCH_R have months of their own.
5
+ * Which calendars there are and which months each takes is the schema's, read
6
+ * through calendars.ts. What is here is the arithmetic the specification never
7
+ * states: how long a month is, and which years February gets a 29th in.
8
+ * GREGORIAN and JULIAN share the twelve month tags and their lengths and differ
9
+ * only in that rule, which is why one table serves both.
8
10
  */
11
+ import { GedcomScheme } from "../schemes/schema-types";
12
+ export declare const LENGTHS: Record<string, number>;
9
13
  export interface ImpossibleDay {
10
14
  day: number;
11
15
  month: string;
@@ -14,4 +18,4 @@ export interface ImpossibleDay {
14
18
  }
15
19
  export declare function isLeapYear(year: number, calendar: string): boolean;
16
20
  export declare function daysInMonth(month: string, year: number | null, calendar: string): number | null;
17
- export declare function impossibleDays(value: string): ImpossibleDay[];
21
+ export declare function impossibleDays(scheme: GedcomScheme, value: string): ImpossibleDay[];
@@ -0,0 +1,38 @@
1
+ /**
2
+ * The one reader of the schema's `calendar` table, for everything that has to
3
+ * know which calendars there are, which months each takes and which epoch may
4
+ * close a year: the 5.5.1 date rules, the GEDCOM 7 date grammar, the day-length
5
+ * check and date completion.
6
+ *
7
+ * Month lengths are not here and not in the schema. The specification gives
8
+ * `day = Integer` and says no more, so a length is arithmetic rather than
9
+ * vocabulary; calendarDays.ts holds it, and a test binds its table to this one.
10
+ */
11
+ import { GedcomScheme, GedcomTag } from "../schemes/schema-types";
12
+ /** An absent calendar means GREGORIAN, in both dialects. */
13
+ export declare const DEFAULT_CALENDAR: GedcomTag;
14
+ export interface Vocabulary {
15
+ /** Permitted months, or null where the schema describes no such calendar. */
16
+ months: Set<string> | null;
17
+ epochs: Set<string> | null;
18
+ }
19
+ export declare function vocabularyOf(scheme: GedcomScheme, calendar: GedcomTag): Vocabulary;
20
+ /**
21
+ * An extension tag that is not an alias is accepted in any of the three slots a
22
+ * calendar constrains: an extension calendar defines its own months and epochs,
23
+ * and rejecting an undeclared one here would report files this validator cannot
24
+ * prove wrong. An alias resolves to the standard tag it abbreviates and is held
25
+ * to the calendar's own vocabulary like any other standard tag.
26
+ */
27
+ export declare function permits(vocabulary: Set<string> | null, token: string): boolean;
28
+ /** How 5.5.1 writes a calendar, which is the form completion has to offer. */
29
+ export declare function calendarEscape(calendar: string): string;
30
+ /** The calendar a token names, in either dialect's form, or null. */
31
+ export declare function calendarNamed(scheme: GedcomScheme, token: string): GedcomTag | null;
32
+ /** The leading calendar escape 5.5.1 puts in front of a date, and the rest. */
33
+ export declare function stripCalendarEscape(value: string): {
34
+ calendar: GedcomTag | null;
35
+ rest: string;
36
+ };
37
+ /** The tokens of a date, with an escape kept whole however it is spaced. */
38
+ export declare function dateTokens(value: string): string[];
@@ -3,6 +3,7 @@ import { ASTNode } from "../parser";
3
3
  import { GedcomError } from "../types/errors";
4
4
  import { ExtensionContext } from "./extensions";
5
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" | "age-v7" | "personal-name" | "latitude" | "longitude" | "media-type" | "language-tag" | "tag-def" | null;
6
+ export declare const PAYLOAD_FIELD_TYPES: Record<string, Exclude<FieldType, null>>;
6
7
  export declare class RuleNode {
7
8
  private readonly scheme;
8
9
  private readonly pointerMap;
@@ -27,5 +28,6 @@ export declare class RuleNode {
27
28
  private getUniversalType;
28
29
  getNodeType(node: ASTNode): GedcomType;
29
30
  validate(node: ASTNode, _tagType?: GedcomType): GedcomError[];
31
+ collect(errors: GedcomError[], node: ASTNode, _tagType?: GedcomType): void;
30
32
  }
31
33
  export {};
@@ -2,6 +2,10 @@ 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 parseCardinality(str: string): {
6
+ min: number;
7
+ max: number;
8
+ } | null;
5
9
  export declare function schemeFor(nodes: ASTNode[]): GedcomScheme;
6
10
  export declare class GedcomValidator {
7
11
  private readonly pointers;
@@ -12,7 +16,8 @@ export declare class GedcomValidator {
12
16
  /** A fragment is not a document, so nothing is required of its root. */
13
17
  fragment?: boolean);
14
18
  setScheme(nodes: ASTNode[]): GedcomScheme;
15
- validate(nodes: ASTNode[], parentType?: GedcomType, _scheme?: GedcomScheme,
19
+ validate(nodes: ASTNode[], parentType?: GedcomType, _scheme?: GedcomScheme, parent?: ASTNode): GedcomError[];
20
+ collect(errors: GedcomError[], nodes: ASTNode[], parentType: GedcomType, scheme: GedcomScheme,
16
21
  /** Absent at the root, where the start of the document is the honest place. */
17
- parent?: ASTNode): GedcomError[];
22
+ parent?: ASTNode): void;
18
23
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domorium/validator",
3
- "version": "1.8.2",
3
+ "version": "2.0.0",
4
4
  "description": "GEDCOM 5.5.1 and 7.0 parser and validator",
5
5
  "keywords": [
6
6
  "gedcom",