UNPKG

@fjell/core

Version:

Core Item and Key Framework for Fjell

37 lines (36 loc) 1.46 kB
/** * Wrapper for one() operation * * Provides automatic validation for one() operation parameters. */ import { Coordinate, Item, OneMethod } from "@fjell/types"; import type { WrapperOptions } from "./types"; /** * Creates a wrapped one() method with automatic parameter validation. * * The wrapper handles: * - Query validation * - Location array validation against coordinate * - Parameter normalization (undefined → defaults) * - Consistent error handling * * @param coordinate - The coordinate defining the item hierarchy * @param implementation - The core logic for the operation (no validation needed) * @param options - Optional configuration * @returns A fully validated one() method * * @example * ```typescript * const one = createOneWrapper( * coordinate, * async (query, locations) => { * // Just implement the logic - validation is automatic * return await database.findOne(query, locations); * } * ); * * // Usage * const item = await one({ status: 'active' }, [{ kt: 'org', lk: '123' }]); * ``` */ export declare function createOneWrapper<V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(coordinate: Coordinate<S, L1, L2, L3, L4, L5>, implementation: OneMethod<V, S, L1, L2, L3, L4, L5>, options?: WrapperOptions): OneMethod<V, S, L1, L2, L3, L4, L5>;