/** * The {@link Type} module provides the {@link Expression} types. * * @module Type * */ import { Data } from '../utils/variant'; /** * A subset of {@link Value} relating to primitive values. * * @category Type */ export type PrimitiveValue = null | string | number | boolean | bigint | Date; /** * A subset of {@link Value} relating to numeric values. * * @category Type */ export type NumericValue = number | bigint; /** * An {@link ArrayValue} * * @category Type */ export type ArrayValue = Value[]; /** * A {@link SetValue} * * @category Type */ export type SetValue = Set; /** * A {@link DictValue} * * @category Type */ export type DictValue = Map; /** @internal */ export declare abstract class EastSet implements Set { abstract has(key: K): boolean; abstract add(key: K): this; abstract delete(key: K): boolean; abstract clear(): void; abstract readonly size: number; abstract forEach(callbackfn: (key: K, value: K, set: Set) => void, thisArg?: any): void; abstract entries(): IterableIterator<[K, K]>; abstract keys(): IterableIterator; abstract values(): IterableIterator; abstract [Symbol.iterator](): IterableIterator; abstract [Symbol.toStringTag]: string; } /** @internal */ export declare abstract class EastMap implements Map { abstract has(key: K): boolean; abstract get(key: K): T | undefined; abstract set(key: K, value: T): this; abstract delete(key: K): boolean; abstract clear(): void; abstract readonly size: number; abstract forEach(callbackfn: (value: T, key: K, map: Map) => void, thisArg?: any): void; abstract entries(): IterableIterator<[K, T]>; abstract keys(): IterableIterator; abstract values(): IterableIterator; abstract [Symbol.iterator](): IterableIterator<[K, T]>; abstract [Symbol.toStringTag]: string; } /** * A {@link VariantValue} * * @category Type */ export type VariantValue = { type: string; [Data]: Value; }; /** * A {@link StructValue} * * @category Type */ export type StructValue = { [key: string]: Value; }; /** * A {@link BlobValue} * * @category Type */ export type BlobValue = Uint8Array; /** * A {@link Value} * * @category Type */ export type Value = PrimitiveValue | ArrayValue | SetValue | DictValue | VariantValue | StructValue | BlobValue; /** * An {@link EastType} for a dataless value, `null`. * * @category Type */ export type NullType = { nullable: true; }; export declare const NullType: NullType; /** * An {@link EastType} for a nullable value of another type, where values may optionally be * `null`. * * @category Type * * @example * * ```ts * type NullableStringType = Nullable * const NullableStringType = Nullable(StringType) * ``` */ export type Nullable = T & { nullable: true; }; export declare function Nullable(type: T): Nullable; /** * An {@link EastType} for `true` or `false`. * * @category Type */ export type BooleanType = { type: "Boolean"; value: null; }; export declare const BooleanType: BooleanType; /** * An {@link EastType} for 64-bit signed integers. Represented by `bigint`s in the * JavaScript runtime, such as `0n`, `1n`, etc. * * @category Type */ export type IntegerType = { type: "Integer"; value: null; }; export declare const IntegerType: IntegerType; /** * An {@link EastType} for 64-bit IEEE 654 floating-point numbers. Represented by `number`s * in the JavaScript runtime, such as `0`, `3.14`, `Infinity`, etc. * * @category Type */ export type FloatType = { type: "Float"; value: null; }; export declare const FloatType: FloatType; /** * An {@link EastType} for a unicode text string. Represented by `string`s in the JavaScript * runtime, such as `"abc"`. * * @category Type */ export type StringType = { type: "String"; value: null; }; export declare const StringType: StringType; /** * An {@link EastType} for a UTC datetime. Represented by `Date`s in the JavaScript * runtime, such as `new Date("2022-01-01T00:00:00.000Z")`. * * @category Type */ export type DateTimeType = { type: "DateTime"; value: null; }; export declare const DateTimeType: DateTimeType; /** * An {@link EastType} for a set of distinct keys of a uniform type. Currently keys must be * strings, and are represented by `Set` in the JavaScript runtime, such as * `new Set(["a", "b", "c"])`. * * @category Type */ export type SetType = { type: "Set"; value: K; }; /** * Return a `SetType` with the corresponding key type. * * @param key the type of the set's keys * * @category Type */ export declare function SetType(key: K): SetType; /** * An {@link EastType} for a 0-indexed array of values of uniform type. Represented by * `Array` in the JavaScript runtime, such as `["a", "b", "c"]`. * * @category Type */ export type ArrayType = { type: "Array"; value: T; }; /** * Return an `ArrayType` with the given value type. * * @param value the type of the array's values * * @category Type */ export declare function ArrayType(value: T): ArrayType; /** * An {@link EastType} for a dictionary of keys and values of uniform types. Currently the * keys must be strings. Represented by `Map` in the JavaScript runtime, such as * `new Map([["a", true], ["b", false]])`. * * @category Type */ export type DictType = { type: "Dict"; value: { key: K; value: T; }; }; /** * Construct a `DictType` with the given key and value types * * @param key the type of the dictionary's keys * @param value the type of the dictionary's values * * @category Type */ export declare function DictType(key: K, value: T): DictType; /** * An {@link EastType} for a variant (also known as tagged unions, sum types, or * enumerations). A variant value consists of a one of the possible "tags" along with any * associated data, and can constructed with the `Variant` function. * * @category Type */ export type VariantType = Record> = { type: "Variant"; value: T; }; /** * Return a `VariantType` with the corresponding tag names and associated types. * * @param cases a record of the variant case (or tag) names and their associated types * * @category Type */ export declare function VariantType>(cases: T): VariantType; /** * An {@link EastType} for a struct of values (also known as a records, product types or * objects). A struct contains a fixed set of named fields with value of the corresponding * type for each. In the JavaScript runtime these are represented as `object`s such as * `{ a: true, b: "abc" }`. * * @category Type */ export type StructType = Record> = { type: "Struct"; value: T; }; /** * Return a `StructType` with the given field names and corresponding types. * * @param fields a record of the struct's fields and their corresponding types * * @category Type */ export declare function StructType>(fields: T): StructType; /** * An {@link EastType} for a binary blob - a collection of bytes. * * @category Type */ export type BlobType = { type: "Blob"; value: null; }; export declare const BlobType: BlobType; /** @internal */ export type EastType = NullType | BooleanType | BooleanType & NullType | IntegerType | IntegerType & NullType | FloatType | FloatType & NullType | StringType | StringType & NullType | DateTimeType | DateTimeType & NullType | { type: "Set"; value: StringType; } | { type: "Set"; value: StringType; nullable: true; } | { type: "Array"; value: EastType; } | { type: "Array"; value: EastType; nullable: true; } | { type: "Dict"; value: { key: StringType; value: EastType; }; } | { type: "Dict"; value: { key: StringType; value: EastType; }; nullable: true; } | { type: "Variant"; value: Record; } | { type: "Variant"; value: Record; nullable: true; } | { type: "Struct"; value: Record; } | { type: "Struct"; value: Record; nullable: true; } | BlobType | BlobType & NullType; /** @internal */ export type PrimitiveType = NullType | BooleanType | Nullable | IntegerType | Nullable | FloatType | Nullable | StringType | Nullable | DateTimeType | Nullable; /** @internal */ export declare function isPrimitiveType(t: EastType): t is PrimitiveType; /** @internal */ export type CollectionType = ArrayType | SetType | DictType; /** @internal */ export type NonNullable = T extends BooleanType ? BooleanType : T extends IntegerType ? IntegerType : T extends FloatType ? FloatType : T extends StringType ? StringType : T extends DateTimeType ? DateTimeType : T extends ArrayType ? { type: "Array"; value: T["value"]; } : T extends SetType ? { type: "Set"; value: T["value"]; } : T extends DictType ? { type: "Dict"; value: T["value"]; } : T extends StructType ? { type: "Struct"; value: T["value"]; } : T extends VariantType ? { type: "Variant"; value: T["value"]; } : never; /** @internal */ export declare function NonNullable(t: T): NonNullable; /** @internal */ export type PromoteType = T extends Nullable ? T : T extends FloatType ? U extends Nullable ? Nullable : FloatType : T extends Nullable ? U extends IntegerType ? Nullable : Nullable : T extends IntegerType ? U extends Nullable ? Nullable : U extends IntegerType ? IntegerType : U extends Nullable ? Nullable : FloatType : never; /** @internal */ export declare function PromoteType(t: T, u: U): PromoteType; /** @internal */ export type JsonValue = null | string | number | boolean | JsonValue[] | { [key: string]: JsonValue; }; /** * A subset of {@link EastType} relating to numeric values. * * @category Type */ export type NumericType = FloatType | IntegerType; /** @internal */ export declare function isNumericType(type: EastType): type is NumericType; /** @internal */ export declare function isContinuousType(type: EastType): type is NumericType; /** @internal */ export declare function isNullType(type: EastType): type is NullType; /** @internal */ export declare function isNullableType(type: EastType): type is Nullable; /** @internal */ export declare function isBooleanType(type: EastType): type is BooleanType; /** @internal */ export declare function isIntegerType(type: EastType): type is IntegerType; /** @internal */ export declare function isFloatType(type: EastType): type is FloatType; /** @internal */ export declare function isStringType(type: EastType): type is StringType; /** @internal */ export declare function isDateTimeType(type: EastType): type is DateTimeType; /** @internal */ export declare function isSetType(type: EastType): type is SetType; /** @internal */ export declare function isArrayType(type: EastType): type is ArrayType; /** @internal */ export declare function isDictType(type: EastType): type is DictType; /** @internal */ export declare function isVariantType(type: EastType): type is VariantType; /** @internal */ export declare function isStructType(type: EastType): type is StructType; /** @internal */ export declare function isBlobType(type: EastType): type is BlobType; /** @internal */ export type ValueTypeOf = T extends BooleanType ? T extends NullType ? null | boolean : boolean : T extends IntegerType ? T extends NullType ? null | bigint : bigint : T extends FloatType ? T extends NullType ? null | number : number : T extends StringType ? T extends NullType ? null | string : string : T extends DateTimeType ? T extends NullType ? null | Date : Date : T extends SetType ? T extends NullType ? null | Set> : Set> : T extends ArrayType ? T extends NullType ? null | ValueTypeOf[] : ValueTypeOf[] : T extends DictType ? T extends NullType ? null | Map, ValueTypeOf> : Map, ValueTypeOf> : T extends VariantType ? T extends NullType ? null | { [K in keyof U]: { type: K; [Data]: ValueTypeOf; }; }[keyof U] : { [K in keyof U]: { type: K; [Data]: ValueTypeOf; }; }[keyof U] : T extends StructType ? T extends NullType ? null | { [K in keyof U]: ValueTypeOf; } : { [K in keyof U]: ValueTypeOf; } : T extends BlobType ? T extends NullType ? null | Uint8Array : Uint8Array : T extends NullType ? null : T extends EastType ? Value : never; /** @internal */ export type EastTypeOf = (T & null) extends never ? (T extends boolean ? BooleanType : T extends bigint ? IntegerType : T extends number ? FloatType : T extends string ? StringType : T extends Date ? DateTimeType : T extends Uint8Array ? BlobType : T extends Set ? SetType : T extends (infer U)[] ? ArrayType> : T extends Map ? DictType> : T extends VariantValue ? { type: "Variant"; value: { [K in T["type"]]: EastTypeOf<(T & { type: K; })[Data]>; }; } : T extends { [K: string]: Value; } ? { type: "Struct"; value: { [K in keyof T]: EastTypeOf; }; } : never) : (Exclude extends never ? NullType : Exclude extends boolean ? Nullable : Exclude extends bigint ? Nullable : Exclude extends number ? Nullable : Exclude extends string ? Nullable : Exclude extends Date ? Nullable : Exclude extends Uint8Array ? Nullable : Exclude extends Set ? Nullable> : Exclude extends (infer U)[] ? Nullable>> : Exclude extends Map ? Nullable>> : Exclude extends VariantValue ? { type: "Variant"; value: { [K in Exclude["type"]]: EastTypeOf<(Exclude & { type: K; })[Data]>; }; nullable: true; } : Exclude extends { [K: string]: Value; } ? { type: "Struct"; value: { [K in keyof Exclude]: EastTypeOf[K]>; }; nullable: true; } : T extends Value ? EastType : never); /** @internal */ export declare function EastType(x: T): EastTypeOf; /** @internal */ export declare function eastTypeEqual(t1: EastType, t2: EastType): boolean; /** @internal */ export declare function eastSubtype(t1: EastType, t2: EastType): boolean; /** @internal */ export declare function isValueOf(value: Value, type: EastType): boolean; /** * Construct an EastType that can hold values of `t1` and `t2`. Currently this means * making the output nullable if one of the two outputs are nullable. * * @internal */ export declare function widenTypes(t1: T1, t2: T2): T1 & T2; /** * Construct an EastType that can hold values of `t1` and `t2`. This version expands * nullability and merges variants together. * * @internal */ export declare function widenTypes2(t1: T1, t2: T2): T1 & T2; /** * Create a default {@link Value} of a given East `type`. * * @remarks For nullable types this is `null`, otherwise numeric types default to zero, * Boolean to false, strings, arrays, sets and dictionaries are empty, for variants the * first variant type is chosen, and structs are created recursively. * * @category StdLib * * @param type the {@link EastType} */ export declare function DefaultValue(type: T): ValueTypeOf; export type SubType = T extends BooleanType ? T extends NullType ? { nullable?: true; type?: "Boolean"; value?: null; } : BooleanType : T extends IntegerType ? T extends NullType ? { nullable?: true; type?: "Integer"; value?: null; } : IntegerType : T extends FloatType ? T extends NullType ? { nullable?: true; type?: "Float"; value?: null; } : FloatType : T extends StringType ? T extends NullType ? { nullable?: true; type?: "String"; value?: null; } : StringType : T extends DateTimeType ? T extends NullType ? { nullable?: true; type?: "DateTime"; value?: null; } : DateTimeType : T extends ArrayType ? T extends NullType ? { nullable?: true; type?: "Array"; value?: SubType; } : { type: "Array"; value: SubType; } : T extends SetType ? T extends NullType ? { nullable?: true; type?: "Set"; value?: SubType; } : { type: "Set"; value: SubType; } : T extends DictType ? T extends NullType ? { nullable?: true; type?: "Dict"; value?: { key: SubType; value: SubType; }; } : { type: "Dict"; value: { key: SubType; value: SubType; }; } : T extends StructType ? T extends NullType ? { nullable?: true; type?: "Struct"; value?: { [K in keyof T["value"]]: SubType; }; } : { type: "Struct"; value: { [K in keyof T["value"]]: SubType; }; } : T extends VariantType ? T extends NullType ? { nullable?: true; type?: "Variant"; value?: { [K in keyof T["value"]]?: SubType; }; } : { type: "Variant"; value: { [K in keyof T["value"]]?: SubType; }; } : T extends NullType ? NullType : never;