@domorium/validator 0.1.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 +10 -0
- package/LICENSE +21 -0
- package/README.md +28 -0
- package/dist/completion/completion.d.ts +18 -0
- package/dist/document/gedcomDocument.d.ts +18 -0
- package/dist/index.cjs.js +2 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.esm.js +713 -0
- package/dist/parser/index.d.ts +2 -0
- package/dist/parser/lexer.d.ts +30 -0
- package/dist/parser/parser.d.ts +7 -0
- package/dist/parser/visitor.d.ts +43 -0
- package/dist/schemes/schema-types.d.ts +41 -0
- package/dist/types/errors.d.ts +8 -0
- package/dist/types/position.d.ts +8 -0
- package/dist/validator/getGedcomVersion.d.ts +2 -0
- package/dist/validator/index.d.ts +1 -0
- package/dist/validator/rule-node.d.ts +26 -0
- package/dist/validator/validate.d.ts +9 -0
- package/package.json +62 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Lexer, ILexingResult, ILexerConfig } from "chevrotain";
|
|
2
|
+
import { IMultiModeLexerDefinition } from "@chevrotain/types";
|
|
3
|
+
export declare enum TokenNames {
|
|
4
|
+
LEVEL = "LEVEL",
|
|
5
|
+
POINTER = "POINTER",
|
|
6
|
+
TAG = "TAG",
|
|
7
|
+
XREF = "XREF",
|
|
8
|
+
VALUE = "VALUE"
|
|
9
|
+
}
|
|
10
|
+
export declare const Level: import("chevrotain").TokenType;
|
|
11
|
+
export declare const Pointer: import("chevrotain").TokenType;
|
|
12
|
+
export declare const Tag: import("chevrotain").TokenType;
|
|
13
|
+
export declare const Xref: import("chevrotain").TokenType;
|
|
14
|
+
export declare const Value: import("chevrotain").TokenType;
|
|
15
|
+
export declare const gedcomLexerDefinition: IMultiModeLexerDefinition;
|
|
16
|
+
export declare const tokens: {
|
|
17
|
+
Level: import("chevrotain").TokenType;
|
|
18
|
+
Pointer: import("chevrotain").TokenType;
|
|
19
|
+
Tag: import("chevrotain").TokenType;
|
|
20
|
+
Xref: import("chevrotain").TokenType;
|
|
21
|
+
Value: import("chevrotain").TokenType;
|
|
22
|
+
};
|
|
23
|
+
export interface ConfigurableLexerOptions extends ILexerConfig {
|
|
24
|
+
zeroBased?: boolean;
|
|
25
|
+
}
|
|
26
|
+
export declare class ConfigurableLexer extends Lexer {
|
|
27
|
+
private readonly zeroBased;
|
|
28
|
+
constructor(config?: ConfigurableLexerOptions);
|
|
29
|
+
tokenize(text: string, initialMode?: string): ILexingResult;
|
|
30
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { CstNode, CstParser, ParserMethod } from "chevrotain";
|
|
2
|
+
import { TokenVocabulary } from "@chevrotain/types";
|
|
3
|
+
export declare class GedcomParser extends CstParser {
|
|
4
|
+
root: ParserMethod<[], CstNode>;
|
|
5
|
+
line: ParserMethod<[], CstNode>;
|
|
6
|
+
constructor(lexerDefinition: TokenVocabulary);
|
|
7
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { CstNode } from "chevrotain";
|
|
2
|
+
import { CstElement } from "@chevrotain/types";
|
|
3
|
+
import { TokenNames } from "./lexer";
|
|
4
|
+
declare const BaseGedcomVisitor: new (...args: any[]) => import("chevrotain").ICstVisitor<any, any>;
|
|
5
|
+
interface Position {
|
|
6
|
+
line: number;
|
|
7
|
+
character: number;
|
|
8
|
+
}
|
|
9
|
+
export interface Range {
|
|
10
|
+
start: Position;
|
|
11
|
+
end: Position;
|
|
12
|
+
}
|
|
13
|
+
export interface ASTToken {
|
|
14
|
+
name: TokenNames;
|
|
15
|
+
range: Range;
|
|
16
|
+
value: string;
|
|
17
|
+
}
|
|
18
|
+
export interface ASTNode {
|
|
19
|
+
range: Range;
|
|
20
|
+
tokens: Partial<Record<TokenNames, ASTToken>>;
|
|
21
|
+
parent?: ASTNode;
|
|
22
|
+
children: ASTNode[];
|
|
23
|
+
level: number;
|
|
24
|
+
}
|
|
25
|
+
export interface VisitorResult {
|
|
26
|
+
nodes: ASTNode[];
|
|
27
|
+
pointers: Map<string, ASTNode[]>;
|
|
28
|
+
xrefs: Map<string, ASTToken[]>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Resolves a node's logical value by following CONT (new line) and CONC
|
|
32
|
+
* (concatenation) continuation children in document order, per the GEDCOM
|
|
33
|
+
* line-continuation rules.
|
|
34
|
+
*/
|
|
35
|
+
export declare function resolveValue(node: ASTNode): string;
|
|
36
|
+
export declare class GedcomVisitor extends BaseGedcomVisitor {
|
|
37
|
+
constructor();
|
|
38
|
+
root(ctx: CstNode | undefined): VisitorResult;
|
|
39
|
+
line({ children }: CstNode): ASTNode;
|
|
40
|
+
getTokens(elements?: CstElement[]): ASTToken[];
|
|
41
|
+
buildHierarchy(nodes: ASTNode[]): VisitorResult;
|
|
42
|
+
}
|
|
43
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Brand } from "ts-brand";
|
|
2
|
+
export type GedcomTag = Brand<string, "GedcomTag">;
|
|
3
|
+
export declare const GedcomTag: import("ts-brand").Brander<GedcomTag>;
|
|
4
|
+
export type GedcomType = Brand<string, "GedcomType">;
|
|
5
|
+
export declare const GedcomType: import("ts-brand").Brander<GedcomType>;
|
|
6
|
+
export interface GedcomScheme {
|
|
7
|
+
calendar: Record<GedcomTag, Calendar>;
|
|
8
|
+
label: Record<GedcomType, Label>;
|
|
9
|
+
payload: Record<GedcomType, Payload>;
|
|
10
|
+
set: Record<GedcomType, Set>;
|
|
11
|
+
substructure: Record<GedcomType, Substructure>;
|
|
12
|
+
tag: Record<GedcomType, GedcomTag>;
|
|
13
|
+
tagInContext: TagInContext;
|
|
14
|
+
}
|
|
15
|
+
export interface Calendar {
|
|
16
|
+
epochs: string[];
|
|
17
|
+
months: Months;
|
|
18
|
+
type: GedcomType;
|
|
19
|
+
}
|
|
20
|
+
export type Months = Record<GedcomTag, GedcomType>;
|
|
21
|
+
export type Label = Record<"en-US", string>;
|
|
22
|
+
export interface Payload {
|
|
23
|
+
to?: GedcomType;
|
|
24
|
+
set?: GedcomType;
|
|
25
|
+
type: null | "Y|<NULL>" | string;
|
|
26
|
+
}
|
|
27
|
+
export type Set = Record<string, GedcomType>;
|
|
28
|
+
export type Substructure = Record<GedcomTag, {
|
|
29
|
+
cardinality: string;
|
|
30
|
+
type: GedcomType;
|
|
31
|
+
}>;
|
|
32
|
+
export interface TagInContext {
|
|
33
|
+
cal: Cal;
|
|
34
|
+
enum: Enum;
|
|
35
|
+
month: Month;
|
|
36
|
+
struct: Struct;
|
|
37
|
+
}
|
|
38
|
+
export type Cal = Record<GedcomType, GedcomTag>;
|
|
39
|
+
export type Enum = Record<GedcomType, Record<GedcomType, GedcomTag>>;
|
|
40
|
+
export type Month = Record<GedcomType, Record<GedcomType, GedcomTag>>;
|
|
41
|
+
export type Struct = Record<GedcomType, Record<GedcomType, GedcomTag>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { GedcomValidator } from "./validate";
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { GedcomScheme, GedcomType } from "../schemes/schema-types";
|
|
2
|
+
import { ASTNode } from "../parser";
|
|
3
|
+
import { GedcomError } from "../types/errors";
|
|
4
|
+
type FieldType = "boolean" | "string" | "nonNegativeInteger" | "select" | "multiselect" | "date" | "date-period" | "date-exact" | "time" | "pointer" | "age" | "personal-name" | "media-type" | "language-tag" | null;
|
|
5
|
+
export declare class RuleNode {
|
|
6
|
+
private readonly scheme;
|
|
7
|
+
pointers: ASTNode[];
|
|
8
|
+
constructor(scheme: GedcomScheme, pointers: Map<string, ASTNode[]>);
|
|
9
|
+
getFieldType(tagType: GedcomType): {
|
|
10
|
+
type: FieldType;
|
|
11
|
+
isList: boolean;
|
|
12
|
+
to: GedcomType | undefined;
|
|
13
|
+
};
|
|
14
|
+
getAvailableValues(tagType: GedcomType): string[] | null;
|
|
15
|
+
/**
|
|
16
|
+
* CONT/CONC are universal line-continuation tags: they are deliberately
|
|
17
|
+
* left out of `substructure` (see validate.ts, which skips them before
|
|
18
|
+
* doing any substructure lookup), so they never appear on the walk done
|
|
19
|
+
* by getNodeType below. Resolve their type directly from the flat
|
|
20
|
+
* type->tag table instead.
|
|
21
|
+
*/
|
|
22
|
+
private getUniversalType;
|
|
23
|
+
getNodeType(node: ASTNode): GedcomType;
|
|
24
|
+
validate(node: ASTNode, _tagType?: GedcomType): GedcomError[];
|
|
25
|
+
}
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { GedcomType, GedcomScheme } from "../schemes/schema-types";
|
|
2
|
+
import { ASTNode } from "../parser";
|
|
3
|
+
import { GedcomError } from "../types/errors";
|
|
4
|
+
export declare class GedcomValidator {
|
|
5
|
+
private readonly pointers;
|
|
6
|
+
constructor(pointers?: Map<string, ASTNode[]>);
|
|
7
|
+
setScheme(nodes: ASTNode[]): GedcomScheme;
|
|
8
|
+
validate(nodes: ASTNode[], parentType?: GedcomType, _scheme?: GedcomScheme): GedcomError[];
|
|
9
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@domorium/validator",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "GEDCOM 5.5.1 and 7.0 parser and validator",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"gedcom",
|
|
7
|
+
"genealogy",
|
|
8
|
+
"parser",
|
|
9
|
+
"validator"
|
|
10
|
+
],
|
|
11
|
+
"homepage": "https://github.com/lavich/domorium#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/lavich/domorium/issues"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/lavich/domorium.git",
|
|
18
|
+
"directory": "packages/validator"
|
|
19
|
+
},
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"author": {
|
|
22
|
+
"name": "Andrey Lobanov",
|
|
23
|
+
"email": "lobanov.andrey.lavich@gmail.com",
|
|
24
|
+
"url": "https://github.com/lavich"
|
|
25
|
+
},
|
|
26
|
+
"sideEffects": false,
|
|
27
|
+
"main": "dist/index.cjs.js",
|
|
28
|
+
"module": "dist/index.esm.js",
|
|
29
|
+
"types": "dist/index.d.ts",
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
33
|
+
"require": "./dist/index.cjs.js",
|
|
34
|
+
"import": "./dist/index.esm.js"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"files": [
|
|
38
|
+
"dist",
|
|
39
|
+
"package.json",
|
|
40
|
+
"README.md",
|
|
41
|
+
"CHANGELOG.md",
|
|
42
|
+
"LICENSE"
|
|
43
|
+
],
|
|
44
|
+
"publishConfig": {
|
|
45
|
+
"access": "public"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"typecheck": "tsc --noEmit",
|
|
49
|
+
"build": "vite build && tsc --emitDeclarationOnly --declaration --outDir dist",
|
|
50
|
+
"watch": "vite build --watch",
|
|
51
|
+
"generate": "tsx scripts/generate-schema.ts",
|
|
52
|
+
"test": "vitest",
|
|
53
|
+
"prepack": "npm run build"
|
|
54
|
+
},
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"chevrotain": "^11.0.3",
|
|
57
|
+
"ts-brand": "^0.2.0"
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"tsx": "^4.23.1"
|
|
61
|
+
}
|
|
62
|
+
}
|