'f'
mh-two-thousand-and-two
2024-04-12 26f2711ef9461961fb953e2b497bd314ef95e345
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
export type Fork = {
    use<T>(plugin: Plugin<T>): T;
};
export type Plugin<T> = (fork: Fork) => T;
export type Omit<T, K> = Pick<T, Exclude<keyof T, K>>;
type Deep = boolean | ((type: Type<any>, value: any) => void);
export type Type<T> = ArrayType<T> | IdentityType<T> | ObjectType<T> | OrType<T> | PredicateType<T>;
export interface AnyType {
    toString(): string;
    check(value: any, deep?: Deep): boolean;
    assert(value: any, deep?: Deep): boolean;
    arrayOf(): AnyType;
}
declare abstract class BaseType<T> {
    abstract toString(): string;
    abstract check(value: any, deep?: Deep): value is T;
    assert(value: any, deep?: Deep): value is T;
    arrayOf(): Type<T[]>;
}
declare class ArrayType<T> extends BaseType<T> {
    readonly elemType: Type<T extends (infer E)[] ? E : never>;
    readonly kind: "ArrayType";
    constructor(elemType: Type<T extends (infer E)[] ? E : never>);
    toString(): string;
    check(value: any, deep?: Deep): value is T;
}
declare class IdentityType<T> extends BaseType<T> {
    readonly value: T;
    readonly kind: "IdentityType";
    constructor(value: T);
    toString(): string;
    check(value: any, deep?: Deep): value is T;
}
declare class ObjectType<T> extends BaseType<T> {
    readonly fields: Field<any>[];
    readonly kind: "ObjectType";
    constructor(fields: Field<any>[]);
    toString(): string;
    check(value: any, deep?: Deep): value is T;
}
declare class OrType<T> extends BaseType<T> {
    readonly types: Type<any>[];
    readonly kind: "OrType";
    constructor(types: Type<any>[]);
    toString(): string;
    check(value: any, deep?: Deep): value is T;
}
declare class PredicateType<T> extends BaseType<T> {
    readonly name: string;
    readonly predicate: (value: any, deep?: Deep) => boolean;
    readonly kind: "PredicateType";
    constructor(name: string, predicate: (value: any, deep?: Deep) => boolean);
    toString(): string;
    check(value: any, deep?: Deep): value is T;
}
export declare abstract class Def<T = any> {
    readonly type: Type<T>;
    readonly typeName: string;
    baseNames: string[];
    ownFields: {
        [name: string]: Field<any>;
    };
    allSupertypes: {
        [name: string]: Def<any>;
    };
    supertypeList: string[];
    allFields: {
        [name: string]: Field<any>;
    };
    fieldNames: string[];
    finalized: boolean;
    buildable: boolean;
    buildParams: string[];
    constructor(type: Type<T>, typeName: string);
    isSupertypeOf(that: Def<any>): boolean;
    checkAllFields(value: any, deep?: any): boolean;
    abstract check(value: any, deep?: any): boolean;
    bases(...supertypeNames: string[]): this;
    abstract build(...buildParams: string[]): this;
    abstract field(name: string, type: any, defaultFn?: Function, hidden?: boolean): this;
    abstract finalize(): void;
}
declare class Field<T> {
    readonly name: string;
    readonly type: Type<T>;
    readonly defaultFn?: Function | undefined;
    readonly hidden: boolean;
    constructor(name: string, type: Type<T>, defaultFn?: Function | undefined, hidden?: boolean);
    toString(): string;
    getValue(obj: {
        [key: string]: any;
    }): any;
}
type FieldType<T> = Field<T>;
export { FieldType as Field };
export interface ASTNode {
    type: string;
}
export interface Builder {
    (...args: any[]): ASTNode;
    from(obj: {
        [param: string]: any;
    }): ASTNode;
}
export default function typesPlugin(_fork: Fork): {
    Type: {
        or(...types: any[]): Type<any>;
        from<T>(value: any, name?: string): Type<T>;
        def(typeName: string): Def;
        hasDef(typeName: string): boolean;
    };
    builtInTypes: {
        string: Type<string>;
        function: Type<Function>;
        array: Type<any[]>;
        object: Type<{
            [key: string]: any;
        }>;
        RegExp: Type<RegExp>;
        Date: Type<Date>;
        number: Type<number>;
        boolean: Type<boolean>;
        null: Type<null>;
        undefined: Type<undefined>;
        BigInt: Type<BigInt>;
    };
    getSupertypeNames: (typeName: string) => string[];
    computeSupertypeLookupTable: (candidates: any) => {
        [typeName: string]: any;
    };
    builders: import("./gen/builders").builders;
    defineMethod: (name: any, func?: Function) => Function;
    getBuilderName: (typeName: any) => any;
    getStatementBuilderName: (typeName: any) => any;
    namedTypes: import("./gen/namedTypes").NamedTypes;
    getFieldNames: (object: any) => string[];
    getFieldValue: (object: any, fieldName: any) => any;
    eachField: (object: any, callback: (name: any, value: any) => any, context?: any) => void;
    someField: (object: any, callback: (name: any, value: any) => any, context?: any) => boolean;
    finalize: () => void;
};