import { Effect, Schema } from 'effect'; /** Type-level brand for CommandDefinition values. */ export declare const CommandDefinitionTypeId: unique symbol; /** Type-level brand for CommandDefinition values. */ export type CommandDefinitionTypeId = typeof CommandDefinitionTypeId; /** A named Effect that produces a message, optionally carrying the args used to construct it. */ export type Command = [T] extends [Schema.Top] ? Readonly<{ name: string; args?: Record; effect: Effect.Effect, E, R>; }> : Readonly<{ name: string; args?: Record; effect: Effect.Effect; }>; /** A Command definition for a Command with no declared args. Call as `Definition()` to produce a Command instance. */ export interface CommandDefinitionNoArgs> { readonly [CommandDefinitionTypeId]: CommandDefinitionTypeId; readonly name: Name; (): Readonly<{ name: Name; effect: Eff; }>; } /** A Command definition for a Command with declared args. Call as `Definition(args)` to produce a Command instance. */ export interface CommandDefinitionWithArgs> { readonly [CommandDefinitionTypeId]: CommandDefinitionTypeId; readonly name: Name; (args: Schema.Schema.Type>): Readonly<{ name: Name; args: Schema.Schema.Type>; effect: Eff; }>; } /** A Command definition created with `Command.define`. Union over the no-args and with-args shapes; consumers that only need name/identity can accept this. */ export type CommandDefinition = CommandDefinitionNoArgs> | CommandDefinitionWithArgs>; /** * Defines a Command. Two forms, distinguished by whether the second argument * is a Schema (a result message) or a record of Schemas (the args declaration). * * The Effect (or effect builder) is bound at definition time. The returned * Definition is callable: with no args for a Command that doesn't declare any, * or with the declared args record otherwise. * * @example No args * ```ts * const LockScroll = Command.define('LockScroll', CompletedLockScroll)( * Dom.lockScroll.pipe(Effect.as(CompletedLockScroll())), * ) * // Call site: * LockScroll() * ``` * * @example With args * ```ts * const FetchWeather = Command.define( * 'FetchWeather', * { zipCode: S.String }, * SucceededFetchWeather, * FailedFetchWeather, * )(({ zipCode }) => * Effect.gen(function* () { ... }), * ) * // Call site: * FetchWeather({ zipCode: '90210' }) * ``` */ export declare function define>(name: Name, ...results: Results): , any, any>>(effect: Eff) => CommandDefinitionNoArgs; export declare function define>(name: Name, args: Fields, ...results: Results): , any, any>>(effectBuilder: (args: Schema.Schema.Type>) => Eff) => CommandDefinitionWithArgs; /** Transforms the Effect inside a Command while preserving its name and args. */ export declare const mapEffect: { (f: (effect: Effect.Effect) => Effect.Effect): (command: Readonly<{ name: string; args?: Record; effect: Effect.Effect; }>) => Readonly<{ name: string; args?: Record; effect: Effect.Effect; }>; (command: Readonly<{ name: string; args?: Record; effect: Effect.Effect; }>, f: (effect: Effect.Effect) => Effect.Effect): Readonly<{ name: string; args?: Record; effect: Effect.Effect; }>; }; /** Lifts a single Command's result Message through `f`, transforming * `FromMessage` to `ToMessage`. The singular complement to * {@link mapMessages}: reach for this when a child returns one Command * (e.g. an animation leave Command), reach for `mapMessages` when it * returns a list. * * Preserves the Command's `name` and `args` so traces still attribute * it to the originating Submodel. When you need to transform the * Effect itself (not just the result Message), reach for * {@link mapEffect} instead. */ export declare const mapMessage: { (command: Readonly<{ name: string; args?: Record; effect: Effect.Effect; }>, f: (message: FromMessage) => ToMessage): Readonly<{ name: string; args?: Record; effect: Effect.Effect; }>; (f: (message: FromMessage) => ToMessage): (command: Readonly<{ name: string; args?: Record; effect: Effect.Effect; }>) => Readonly<{ name: string; args?: Record; effect: Effect.Effect; }>; }; /** Lifts every Command in a list through `f`, transforming the result * Message type from `FromMessage` to `ToMessage`. Reach for this at the * boundary where a child Submodel's `update` returns Commands typed in * the child's Message and the parent needs them typed in the parent's * Message: * * ```ts * GotChildMessage: ({ message }) => { * const [nextChild, commands, maybeOutMessage] = Child.update(model.child, message) * const mappedCommands = Command.mapMessages( * commands, * message => GotChildMessage({ message }), * ) * // ... * } * ``` * * Preserves each Command's `name` and `args` so traces still attribute * the Command to the originating Submodel. When you need to transform * the Effect itself (not just the result Message), reach for * {@link mapEffect} instead. */ export declare const mapMessages: { (commands: ReadonlyArray; effect: Effect.Effect; }>>, f: (message: FromMessage) => ToMessage): ReadonlyArray; effect: Effect.Effect; }>>; (f: (message: FromMessage) => ToMessage): (commands: ReadonlyArray; effect: Effect.Effect; }>>) => ReadonlyArray; effect: Effect.Effect; }>>; }; //# sourceMappingURL=index.d.ts.map