import type { Internal } from './internal/types.js'; import type { StandardSchemaV1 as StandardSchema } from './deps/jsr.io/@standard-schema/spec/1.0.0/src/index.js'; import type { ApplySchemaReturn, Composable, Failure, Success } from './types.js'; /** * It receives any data (T) and returns a Success object. */ declare function success(data: T): Success; /** * It receives a list of errors and returns a Failure object. */ declare function failure(errors: Error[]): Failure; /** * Creates a composable function. * That function is gonna catch any errors and always return a Result. * @param fn a function to be used as a Composable */ declare function composable(fn: T): Composable; /** * It can be used to call a composable from another composable. It will return the output of the given function if it was successfull, otherwise it will throw a `ErrorList` that will bubble up to the parent function. * Also good to use it in successfull test cases. * @example * ```ts * import { composable, fromSuccess } from 'composable-functions' * * const add1 = composable((n: number) => n + 1) * const result = await add1(1) * // ^? Result * const data = await fromSuccess(add1)(n) * // ^? number * expect(data).toBe(n + 1) * ``` */ declare function fromSuccess(fn: Composable<(...a: P) => O>, onError?: (errors: Error[]) => Error[] | Promise): (...args: P) => Promise; /** * Takes a function and creates a ComposableWithSchema that will assert the input and context types according to the given schemas. * @param fn a function * @param inputSchema the schema for the input * @param contextSchema the schema for the context * @returns a composable function that will assert the input and context types at runtime. * @example * ```ts * const safeFunction = applySchema( * z.object({ greeting: z.string() }), * z.object({ * user: z.object({ name: z.string() }) * }), * ) * const fn = safeFunction(( * { greeting }: { greeting: string }, * { user }: { user: { name: string } }, * ) => ({ * message: `${greeting} ${user.name}` * })) * ``` */ declare function applySchema(inputSchema?: StandardSchema, contextSchema?: StandardSchema): (fn: (input: Input, context: Context) => R) => ApplySchemaReturn; /** * @deprecated use `applySchema` instead */ declare function withSchema(inputSchema?: StandardSchema, contextSchema?: StandardSchema): (fn: (input: Input, context: Context) => R) => ApplySchemaReturn R>; export { applySchema, composable, failure, fromSuccess, success, withSchema }; //# sourceMappingURL=constructors.d.ts.map