import { Data } from '../../utils/variant'; import { ConstFunction, EastFunction } from '../functions'; import { Variable } from '../functions'; import { BooleanType, DateTimeType, EastType, EastTypeOf, FloatType, IntegerType, NullType, StringType, Value, ValueTypeOf } from '../types'; /** @internal */ export declare function randomIdentifier(n?: number): string; /** @internal */ export declare function genSym(name?: string, scope?: string[]): string; /** @internal */ export type ArrayOf = T extends (infer U)[] ? U : never; /** @internal */ export type MapOf = T extends Map ? U : never; /** * An {@link Expression} may either be a {@link Value} or {@link EastFunction} * * @category Expression * */ export type Expression = ValueTypeOf | EastFunction; /** @internal */ export type ExpressionTypeOf = T extends null ? NullType : T extends boolean ? BooleanType : T extends bigint ? IntegerType : T extends number ? FloatType : T extends string ? StringType : T extends Date ? DateTimeType : T extends Set ? { type: "Set"; value: StringType; } : T extends Map ? { type: "Dict"; value: { key: StringType; value: EastTypeOf; }; } : T extends (infer U)[] ? { type: "Array"; value: EastTypeOf; } : T extends { type: string; [Data]: any; } ? { type: "Variant"; value: { [K in T["type"]]: EastTypeOf; }; } : T extends { ast_type: string; type: infer U; } ? U : T extends { [key: string]: Value; } ? { type: "Struct"; value: { [K in keyof T]: EastTypeOf; }; } : never; /** @internal */ export type ExpressionType = T extends Expression ? U : never; /** @internal */ export declare function ExpressionType(x: Expression): T; /** @internal */ export declare function isValue(x: Expression): x is Value; /** @internal */ export declare function isFunction(x: Expression): x is EastFunction; /** @internal */ export declare function toEastFunction(x: Expression): EastFunction; /** * Declare a constant value, specifying the type explicitly. Providing the type may be * necessary when it is impossible to determine the type from the value alone - e.g. for * nullable types, or for empty arrays, sets, or dictionaries. * * @param value the {@link Value} to declare * @category Expression * * @example * ```typescript * // ... * // create a constant string 'New Employee' * category: Const('New Employee', NullableString), * // ... * ``` */ export declare function Const(value: ValueTypeOf, type: T): ConstFunction; /** * Declare a constant value, inferring the type automatically from the value. * * Note: In some cases the East type cannot be easily inferred, and the corresponding type * should be provided as a second argument. * * @param value the {@link Value} to declare * @category Expression * * @example * ```typescript * // ... * // create a constant string 'New Employee' * category: Const('New Employee'), * // ... * ``` */ export declare function Const(value: T): ConstFunction>; /** * Defines a new variable in scope that can be accessed by the inner `expression`. * * @param value The value to assign to the new variable * @param expression A JavaScript function that returns an {@link Expression} to evaluate given the new variable in scope * * @category Expression * * @example * ```typescript * // ... * // if name is null, replace with 'Unknown' string * Wage: Let( * Max(0, Subtract(Variable("Hours", FloatType), 8), * overtime => Add( * Multiply( * Variable("NormalRate", FloatType), * Subtract(Variable("Hours", FloatType), overtime) * ), * Multiply( * Variable("OvertimeRate", FloatType), * overtime * ) * ) * ), * // ... * ``` */ export declare function Let) => EastFunction>(value: EastFunction, expression: F): EastFunction["type"]>; export declare function Let>) => EastFunction>(value: U, expression: F): EastFunction["type"]>; /** * Create an {@link EastFunction} returning the default value of a given `type`. * * @see {@link DefaultValue} * * @category Expression * * @param type the {@link EastType} */ export declare function Default(type: T): EastFunction;