import { type CopyObjectFunction } from '../object/object'; import { type PromiseOrValue } from '../promise/promise.type'; import { type ClassType } from '../type'; import { type MapFunction } from '../value/map'; import { type Maybe } from '../value/maybe.type'; /** * Function that returns a value. */ export type Getter = () => T; /** * Getter with the design of returning a new value each time. */ export type Factory = Getter; /** * Getter that returns a promise. */ export type AsyncFactory = Factory>; /** * Function that returns a value with an optional single argument. */ export type FactoryWithInput = (args?: I) => O; /** * Function that returns a value with a single argument. */ export type FactoryWithRequiredInput = MapFunction; /** * Either a Getter, or an instance of the item. */ export type GetterOrValue = T | Getter; /** * A GetterOrValue returned from a Promise. */ export type AsyncGetterOrValue = GetterOrValue>; /** * Either a GetterWithInput, or a Getter. */ export type GetterOrFactoryWithInput = Getter | FactoryWithInput; /** * Types of values that can safely be retrieved via getValueFromGetter() or asGetter(). */ export type GetterDistinctValue = boolean | string | number | object | symbol | ClassType; /** * Either a GetterOrValue, or a FactoryWithInput. */ export type GetterOrValueWithInput = GetterOrValue | FactoryWithInput; export type StringOrGetter = GetterOrValue; /** * Returns true if the input value is a non-class function (i.e., likely a Getter). * * @param value - The value to check * @returns True if the value is a non-class function */ export declare function isGetter(value: unknown): value is Getter; /** * If the input is a function, it is executed and the result returned. Otherwise, the value itself is returned. * * @param input - A value or a getter/factory function * @returns The resolved value */ export declare function getValueFromGetter(input: GetterOrValue): T; export declare function getValueFromGetter(this: unknown, input: GetterOrValue): T; export declare function getValueFromGetter(this: unknown, input: FactoryWithRequiredInput, args: A): T; export declare function getValueFromGetter(this: unknown, input: GetterOrFactoryWithInput, args?: A): T; export declare function getValueFromGetter(this: unknown, input: GetterOrValueWithInput, args?: A): T; /** * Wraps the input as a Getter function. If it's already a function, returns it directly. * * @param input - A value or getter function * @returns A Getter function that returns the value */ export declare function asGetter(input: GetterOrValue): Getter; /** * A factory that returns a copy of a value. */ export type ObjectCopyFactory = Factory; /** * Creates a factory that returns a shallow copy of the input value on each call. * * @param value - The object to copy * @param copyFunction - Optional custom copy function (defaults to copyObject) * @returns A factory that produces copies of the value */ export declare function objectCopyFactory(value: T, copyFunction?: CopyObjectFunction): ObjectCopyFactory; /** * Converts the input to an ObjectCopyFactory. If the input is an object, wraps it with objectCopyFactory. * If it's already a function (Getter), it's returned directly. * * @param input - An object value or a getter function * @param copyFunction - Optional custom copy function * @returns An ObjectCopyFactory for the input */ export declare function asObjectCopyFactory(input: T | ObjectCopyFactory, copyFunction?: CopyObjectFunction): ObjectCopyFactory; /** * Wraps the input value in a Getter function that always returns it. * * @param input - The value to wrap * @returns A Getter that returns the input value */ export declare function makeGetter(input: T): Getter; /** * A factory that can take in an index input optionally. */ export type FactoryWithIndex = FactoryWithInput | FactoryWithRequiredInput; /** * Calls a factory function the specified number of times and returns the results as an array. * * @param factory - The factory function to call (receives the current index as argument) * @param count - The number of items to create * @returns An array of produced values */ export declare function makeWithFactory(factory: Factory | FactoryWithIndex, count: number): T[]; /** * Maps an array of inputs through a factory function to produce an array of outputs. * * @param factory - The factory function to call with each input * @param input - The array of inputs to pass to the factory * @returns An array of produced values */ export declare function makeWithFactoryInput(factory: FactoryWithInput, input: Maybe[]): T[]; export declare function makeWithFactoryInput(factory: FactoryWithRequiredInput, input: A[]): T[]; /** * Wraps a factory so that no arguments are forwarded when it's called. * Useful for protecting a factory from accidentally receiving arguments. * * @param factory - The factory to wrap * @returns A new factory that calls the original with no arguments */ export declare function protectedFactory(factory: Factory): Factory;