.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / table / node_modules / ajv / dist / types / jtd-schema.d.ts
1 /** required keys of an object, not undefined */
2 declare type RequiredKeys<T> = {
3     [K in keyof T]-?: undefined extends T[K] ? never : K;
4 }[keyof T];
5 /** optional or undifined-able keys of an object */
6 declare type OptionalKeys<T> = {
7     [K in keyof T]-?: undefined extends T[K] ? K : never;
8 }[keyof T];
9 /** type is true if T is a union type */
10 declare type IsUnion_<T, U extends T = T> = false extends (T extends unknown ? ([U] extends [T] ? false : true) : never) ? false : true;
11 declare type IsUnion<T> = IsUnion_<T>;
12 /** type is true if T is identically E */
13 declare type TypeEquality<T, E> = [T] extends [E] ? ([E] extends [T] ? true : false) : false;
14 /** type is true if T or null is identically E or null*/
15 declare type NullTypeEquality<T, E> = TypeEquality<T | null, E | null>;
16 /** gets only the string literals of a type or null if a type isn't a string literal */
17 declare type EnumString<T> = [T] extends [never] ? null : T extends string ? string extends T ? null : T : null;
18 /** true if type is a union of string literals */
19 declare type IsEnum<T> = null extends EnumString<Exclude<T, null>> ? false : true;
20 /** true only if all types are array types (not tuples) */
21 declare type IsElements<T> = false extends IsUnion<T> ? [T] extends [readonly unknown[]] ? undefined extends T[0.5] ? false : true : false : false;
22 /** true if the the type is a values type */
23 declare type IsValues<T> = false extends IsUnion<Exclude<T, null>> ? TypeEquality<keyof Exclude<T, null>, string> : false;
24 /** true if type is a proeprties type and Union is false, or type is a discriminator type and Union is true */
25 declare type IsRecord<T, Union extends boolean> = Union extends IsUnion<Exclude<T, null>> ? null extends EnumString<keyof Exclude<T, null>> ? false : true : false;
26 /** numeric strings */
27 declare type NumberType = "float32" | "float64" | "int8" | "uint8" | "int16" | "uint16" | "int32" | "uint32";
28 /** string strings */
29 declare type StringType = "string" | "timestamp";
30 /** actual schema */
31 export declare type JTDSchemaType<T, D extends Record<string, unknown> = Record<string, never>> = (// refs - where null wasn't specified, must match exactly
32 (null extends EnumString<keyof D> ? never : ({
33     [K in keyof D]: [T] extends [D[K]] ? {
34         ref: K;
35     } : never;
36 }[keyof D] & {
37     nullable?: false;
38 }) | (null extends T ? {
39     [K in keyof D]: [Exclude<T, null>] extends [Exclude<D[K], null>] ? {
40         ref: K;
41     } : never;
42 }[keyof D] & {
43     nullable: true;
44 } : never)) | (unknown extends T ? {
45     nullable?: boolean;
46 } : never) | ((true extends NullTypeEquality<T, number> ? {
47     type: NumberType;
48 } : true extends NullTypeEquality<T, boolean> ? {
49     type: "boolean";
50 } : true extends NullTypeEquality<T, string> ? {
51     type: StringType;
52 } : true extends NullTypeEquality<T, Date> ? {
53     type: "timestamp";
54 } : true extends IsEnum<T> ? {
55     enum: EnumString<Exclude<T, null>>[];
56 } : true extends IsElements<Exclude<T, null>> ? T extends readonly (infer E)[] ? {
57     elements: JTDSchemaType<E, D>;
58 } : never : true extends IsValues<T> ? T extends Record<string, infer V> ? {
59     values: JTDSchemaType<V>;
60 } : never : true extends IsRecord<T, false> ? ([RequiredKeys<Exclude<T, null>>] extends [never] ? {
61     properties?: Record<string, never>;
62 } : {
63     properties: {
64         [K in RequiredKeys<T>]: JTDSchemaType<T[K], D>;
65     };
66 }) & ([OptionalKeys<Exclude<T, null>>] extends [never] ? {
67     optionalProperties?: Record<string, never>;
68 } : {
69     optionalProperties: {
70         [K in OptionalKeys<T>]: JTDSchemaType<Exclude<T[K], undefined>, D>;
71     };
72 }) & {
73     additionalProperties?: boolean;
74 } : true extends IsRecord<T, true> ? {
75     [K in keyof Exclude<T, null>]-?: Exclude<T, null>[K] extends string ? {
76         discriminator: K;
77         mapping: {
78             [M in Exclude<T, null>[K]]: JTDSchemaType<Omit<T extends {
79                 [C in K]: M;
80             } ? T : never, K>, D>;
81         };
82     } : never;
83 }[keyof Exclude<T, null>] : never) & (null extends T ? {
84     nullable: true;
85 } : {
86     nullable?: false;
87 }))) & {
88     metadata?: Record<string, unknown>;
89     definitions?: {
90         [K in keyof D]: JTDSchemaType<D[K], D>;
91     };
92 };
93 declare type JTDDataDef<S, D extends Record<string, unknown>> = (S extends {
94     ref: string;
95 } ? JTDDataDef<D[S["ref"]], D> : S extends {
96     type: NumberType;
97 } ? number : S extends {
98     type: "string";
99 } ? string : S extends {
100     type: "timestamp";
101 } ? string | Date : S extends {
102     enum: readonly (infer E)[];
103 } ? string extends E ? never : [E] extends [string] ? E : never : S extends {
104     elements: infer E;
105 } ? JTDDataDef<E, D>[] : S extends {
106     properties: Record<string, unknown>;
107     optionalProperties?: Record<string, unknown>;
108     additionalProperties?: boolean;
109 } ? {
110     -readonly [K in keyof S["properties"]]-?: JTDDataDef<S["properties"][K], D>;
111 } & {
112     -readonly [K in keyof S["optionalProperties"]]+?: JTDDataDef<S["optionalProperties"][K], D>;
113 } & ([S["additionalProperties"]] extends [true] ? Record<string, unknown> : unknown) : S extends {
114     properties?: Record<string, unknown>;
115     optionalProperties: Record<string, unknown>;
116     additionalProperties?: boolean;
117 } ? {
118     -readonly [K in keyof S["properties"]]-?: JTDDataDef<S["properties"][K], D>;
119 } & {
120     -readonly [K in keyof S["optionalProperties"]]+?: JTDDataDef<S["optionalProperties"][K], D>;
121 } & ([S["additionalProperties"]] extends [true] ? Record<string, unknown> : unknown) : S extends {
122     values: infer V;
123 } ? Record<string, JTDDataDef<V, D>> : S extends {
124     discriminator: infer M;
125     mapping: Record<string, unknown>;
126 } ? [M] extends [string] ? {
127     [K in keyof S["mapping"]]: JTDDataDef<S["mapping"][K], D> & {
128         [KM in M]: K;
129     };
130 }[keyof S["mapping"]] : never : unknown) | (S extends {
131     nullable: true;
132 } ? null : never);
133 export declare type JTDDataType<S> = S extends {
134     definitions: Record<string, unknown>;
135 } ? JTDDataDef<S, S["definitions"]> : JTDDataDef<S, Record<string, never>>;
136 export {};