export declare enum TypeKind { NULL = "null", BOOLEAN = "boolean", BOOLEAN_LITERAL = "boolean-literal", STRING = "string", STRING_LITERAL = "string-literal", FLOAT = "float", DOUBLE = "double", FLOAT_LITERAL = "float-literal", INT32 = "int32", INT64 = "int64", INT_LITERAL = "integer-literal", DATE = "date", DATE_TIME = "date-time", OBJECT = "object", ARRAY = "array", UNION = "union", REFERENCE = "reference", INTERSECTION = "intersection" } export type Type = NullType | BooleanType | BooleanLiteralType | StringType | StringLiteralType | FloatType | DoubleType | FloatLiteralType | Int32Type | Int64Type | IntLiteralType | DateType | DateTimeType | ObjectType | ArrayType | UnionType | ReferenceType | IntersectionType; /** * A concrete type is any type that is not a union of types, intersection or reference to a type. */ export type ConcreteType = Exclude; /** * A primitive type is any type that is not an object, array, union, reference or intersection */ export type PrimitiveType = Exclude; export interface SchemaProp { name: string; value: boolean | number | string; } export type LiteralType = BooleanLiteralType | StringLiteralType | FloatLiteralType | IntLiteralType; export interface NullType { kind: TypeKind.NULL; } export interface BooleanType { kind: TypeKind.BOOLEAN; schemaProps?: SchemaProp[]; } export interface BooleanLiteralType { kind: TypeKind.BOOLEAN_LITERAL; value: boolean; schemaProps?: SchemaProp[]; } export interface StringType { kind: TypeKind.STRING; schemaProps?: SchemaProp[]; } export interface StringLiteralType { kind: TypeKind.STRING_LITERAL; value: string; schemaProps?: SchemaProp[]; } export interface FloatType { kind: TypeKind.FLOAT; schemaProps?: SchemaProp[]; } export interface DoubleType { kind: TypeKind.DOUBLE; schemaProps?: SchemaProp[]; } export interface FloatLiteralType { kind: TypeKind.FLOAT_LITERAL; value: number; schemaProps?: SchemaProp[]; } export interface Int32Type { kind: TypeKind.INT32; schemaProps?: SchemaProp[]; } export interface Int64Type { kind: TypeKind.INT64; schemaProps?: SchemaProp[]; } export interface IntLiteralType { kind: TypeKind.INT_LITERAL; value: number; schemaProps?: SchemaProp[]; } export interface DateType { kind: TypeKind.DATE; schemaProps?: SchemaProp[]; } export interface DateTimeType { kind: TypeKind.DATE_TIME; schemaProps?: SchemaProp[]; } export interface ObjectPropertiesType { name: string; description?: string; optional: boolean; type: Type; } export interface ObjectType { kind: TypeKind.OBJECT; properties: Array; schemaProps?: SchemaProp[]; } export interface ArrayType { kind: TypeKind.ARRAY; elementType: Type; schemaProps?: SchemaProp[]; } export interface UnionType { kind: TypeKind.UNION; types: Type[]; discriminator?: string; schemaProps?: SchemaProp[]; } export interface IntersectionType { kind: TypeKind.INTERSECTION; types: Type[]; schemaProps?: SchemaProp[]; } export interface ReferenceType { kind: TypeKind.REFERENCE; name: string; } export declare function nullType(): NullType; export declare function booleanType(): BooleanType; export declare function booleanLiteralType(value: boolean): BooleanLiteralType; export declare function stringType(): StringType; export declare function stringLiteralType(value: string): StringLiteralType; export declare function floatType(): FloatType; export declare function doubleType(): DoubleType; export declare function floatLiteralType(value: number): FloatLiteralType; export declare function int32Type(): Int32Type; export declare function int64Type(): Int64Type; export declare function intLiteralType(value: number): IntLiteralType; export declare function dateType(): DateType; export declare function dateTimeType(): DateTimeType; export declare function objectType(properties: ObjectPropertiesType[]): ObjectType; export declare function arrayType(elementType: Type): ArrayType; export declare function unionType(unionTypes: Type[], discriminator?: string): UnionType; export declare function intersectionType(intersectionTypes: Type[]): IntersectionType; export declare function referenceType(name: string): ReferenceType; export declare function isNullType(type: Type): type is NullType; export declare function isNotNullType(type: T): type is Exclude; export declare function isBooleanType(type: Type): type is BooleanType; export declare function isBooleanLiteralType(type: Type): type is BooleanLiteralType; export declare function areBooleanLiteralTypes(types: Type[]): types is BooleanLiteralType[]; export declare function isStringType(type: Type): type is StringType; export declare function isNotStringType(type: T): type is Exclude; export declare function isStringLiteralType(type: Type): type is StringLiteralType; export declare function areStringLiteralTypes(types: Type[]): types is StringLiteralType[]; export declare function isFloatType(type: Type): type is FloatType; export declare function isDoubleType(type: Type): type is DoubleType; export declare function isFloatLiteralType(type: Type): type is FloatLiteralType; export declare function areFloatLiteralTypes(types: Type[]): types is FloatLiteralType[]; export declare function isInt32Type(type: Type): type is Int32Type; export declare function isInt64Type(type: Type): type is Int64Type; export declare function isIntLiteralType(type: Type): type is IntLiteralType; export declare function areIntLiteralTypes(types: Type[]): types is IntLiteralType[]; export declare function areIntOrIntLiteralTypes(types: Type[]): types is Array; export declare function areStringOrStringLiteralTypes(types: Type[]): types is Array; export declare function areFloatOrFloatLiteralTypes(types: Type[]): types is Array; export declare function areBooleanOrBooleanLiteralTypes(types: Type[]): types is Array; export declare function isDateType(type: Type): type is DateType; export declare function isDateTimeType(type: Type): type is DateTimeType; export declare function isObjectType(type: Type): type is ObjectType; export declare function isArrayType(type: Type): type is ArrayType; export declare function isUnionType(type: Type): type is UnionType; export declare function isIntersectionType(type: Type): type is IntersectionType; export declare function isReferenceType(type: Type): type is ReferenceType; export declare function isNotReferenceType(type: T): type is Exclude; export declare function isPrimitiveType(type: Type): type is PrimitiveType; export declare function isLiteralType(type: Type): type is LiteralType; export declare function isNotLiteralType(type: T): type is Exclude; export declare function isSchemaPropAllowedType(type: T): type is Exclude; export declare function possibleRootTypes(type: Type, typeTable: TypeTable): ConcreteType[]; export declare function dereferenceType(type: Type, typeTable: TypeTable): Exclude; /** * Given a list of types, try to find a disriminator. The null type is ignored. * * @param types list of types * @param typeTable a TypeTable */ export declare function inferDiscriminator(types: Type[], typeTable: TypeTable): string | undefined; /** * Given a list of types, if any property exists as both a string and * string literal on an intersection, then resolve it to the narrowest type * * @param types list of types */ export declare function resolveIntersectionToNarrowestType(types: Array): Array; /** * Given a list of types, try to find if the intersection evaluates to * a `never` type * * @param types list of types * @param typeTable a TypeTable */ export declare function doesInterfaceEvaluatesToNever(types: Array, typeTable: TypeTable): boolean; /** * Loci table is a lookup table for types. */ export declare class TypeTable { /** * Retrieve the number of entries in the type table. */ get size(): number; static fromArray(typeTableArr: { name: string; typeDef: TypeDef; }[]): TypeTable; private typeDefs; constructor(types?: Map); /** * Return an object representation of the type table. */ toArray(): { name: string; typeDef: TypeDef; }[]; /** * Add a type to the type table. If the type key is already present, `add` will throw an error. * * @param key lookup key * @param typeDef target type definition */ add(key: string, typeDef: TypeDef): void; /** * Retrieve a type by lookup key. * * @param key lookup key */ get(key: string): TypeDef | undefined; /** * Retrieve a type by lookup key. * * @param key lookup key */ getOrError(key: string): TypeDef; /** * Check if a type exists in the table. * * @param key lookup key */ exists(key: string): boolean; } export interface TypeDef { type: Type; description?: string; }