import { Stream } from "../data"; import { AbstractTypeBuilder, DictType, EastType, EastTypeOf, StringType, StructType, TypeBuilder, Value, ValueTypeOf, Variable } from "../east"; import { GenericPipelineBuilder, PipelineBuilder, TabularPipelineBuilder } from '../pipeline'; import { Builder, ModulePath, Template } from "../template"; import { ModuleBuilder } from '../template/ModuleBuilder'; /** @internal */ type ResourceMapping = { mapping_type: 'value'; value: ValueTypeOf; } | { mapping_type: 'stream'; stream: Stream; } | { mapping_type: 'pipeline'; pipeline: T extends DictType ? TabularPipelineBuilder> : GenericPipelineBuilder>; }; /** * A builder to define a resource for simulation. * * @category Resource * * @example * ```typescript * const cash = new ResourceBuilder("cash") * .mapFromValue(1.0) * .assert({ * predicate: x => GreaterEqual(x, 0), * message: "Cash must be positive", * }); * * const sales = new ProcessBuilder("sales") * .resource(cash) * .value("amount", FloatType) * .set("cash", (props, resources) => Add(resources.cash, props.amount)) * .mapFromValue({ date: new Date(0), amount: 42.0, }); * * const scenario = new ScenarioBuilder('my_scenario') * .resource(cash) * .process(sales); * ``` * * */ export declare class ResourceBuilder { private name; private module; /** * Construct a resource with a given name. * * @param name the name of the {@link ResourceBuilder}. * * @category Resource * * @example * ```typescript * const cash = new ResourceBuilder("cash") * .mapFromValue(1.0) * .assert({ * predicate: x => GreaterEqual(x, 0), * message: "Cash must be positive", * }); * * const sales = new ProcessBuilder("sales") * .resource(cash) * .value("amount", FloatType) * .set("cash", (props, resources) => Add(resources.cash, props.amount)) * .mapFromValue({ date: new Date(0), amount: 42.0, }); * * const scenario = new ScenarioBuilder('my_scenario') * .resource(cash) * .process(sales); * ``` * * */ constructor(name: Name, module?: ModuleBuilder | ModulePath); /** * Assign the resource's initial state to the provided value. * * @param value the value to map from. * * @remarks The type `value` may be a value of any valid {@link EastType} type, such as {@link PrimitiveValue}, {@link ArrayValue}, {@link SetValue}, {@link DictValue}, {@link VariantValue}, {@link StructValue}, {@link BlobValue}. * * @category Resource * * @example * ```typescript * // map some inventory from data * const inventory = new ResourceBuilder("inventory") * .mapFromValue(new Map([ * ["socks", { qty: 1n }], * ["chairs", { qty: 3n }] * ])) * ``` * * */ mapFromValue(value: T): SimulationResourceBuilder>; /** * Assign the resource's initial state to the provided value and type. * * @param value the value to map from. * @param type the type to use for the resource value. * * @remarks The `type` may be any valid {@link EastType} type, such as {@link PrimitiveValue}, {@link ArrayValue}, {@link SetValue}, {@link DictValue}, {@link VariantValue}, {@link StructValue}, {@link BlobValue}. * * @category Resource * * @example * ```typescript * // map some inventory from data * const inventory = new ResourceBuilder("inventory") * .mapFromValue(new Map([ * ["socks", { qty: 1n }], * ["chairs", { qty: 3n }] * ]), DictType(StringType, StructType({ qty: IntegerType}))) * ``` * * */ mapFromValue(value: ValueTypeOf, type: T): SimulationResourceBuilder; /** * Assign the resource's initial state to the value contained in a datastream. * * @param stream the stream to map from. * @param type optional type to use for the resource. * * @remarks The `stream` can be any {@link EastType} stream * * @category Resource * * @example * ```typescript * // create a stream with some inventory * const data = new SourceBuilder("inventory data") * .value({ * value: new Map([ * ["one", { * date: new Date(0), * qty: 10 * }], * ["two", { * date: new Date(0), * qty: 5 * }] * ]) * }) * * // map some inventory from the stream * const inventory = new ResourceBuilder("inventory") * .mapFromStream(data.outputStream()) * ``` */ mapFromStream(stream: Stream): SimulationResourceBuilder; mapFromStream(stream: Stream, type: T): SimulationResourceBuilder; /** * Assign the resource's initial state to the value contained output from a pipeline. * * @param builder a function with a {@link PipelineBuilder} outputing a stream to map a value from. * @param type optional type to use for the resource. * * @remarks The `pipeline` can output any {@link EastType} stream * * @category Resource * * @example * ```typescript * // a stream to map from * const data = new SourceBuilder("inventory data") * .value({ * value: new Map([ * ["one", { * date: new Date(0), * qty: 10 * }], * ["two", { * date: new Date(0), * qty: 5 * }] * ]) * }) * * const inventory = new ResourceBuilder("inventory") * .mapFromPipeline(builder => builder * .from(data.outputStream()) * ) * ``` * */ mapFromPipeline

(GenericPipelineBuilder> | TabularPipelineBuilder, Record>)>(pipeline: P): SimulationResourceBuilder["outputStream"]>["type"]>; mapFromPipeline(pipeline: (builder: PipelineBuilder) => (GenericPipelineBuilder> | TabularPipelineBuilder, Record>), type: T): SimulationResourceBuilder; } /** @internal */ export declare class SimulationResourceBuilder extends Builder { protected name: Name; protected resourceType: T; protected mapping: ResourceMapping; protected description: AbstractTypeBuilder; constructor(name: Name, module: ModulePath, resourceType: T, mapping: ResourceMapping, description?: AbstractTypeBuilder); /** Add a human-readable description of the resource. * * @param description the type builder with descriptions. * * @category Resource * * @example * ```typescript * // map some inventory from data * const inventory = new ResourceBuilder("inventory") * .mapFromValue(new Map([ * ["socks", { qty: 1n }], * ["chairs", { qty: 3n }] * ])) * .describe("A dictionary mapping inventory items to the quantity in stock") * ``` * */ describe(def: AbstractTypeBuilder | ((builder: TypeBuilder) => AbstractTypeBuilder)): SimulationResourceBuilder; /** * Return the `Stream` containing the resource's initial state. * * @category Resource * * */ resourceStream(): Stream; /** @internal */ toType(): AbstractTypeBuilder; /** * Convert the built resource into an {@link Template}, for usage in * an EDK project. * * @returns a {@link Template} * * @category Resource * **/ toTemplate(): Template; } export {};