UNPKG

@daiso-tech/core

Version:

The library offers flexible, framework-agnostic solutions for modern web applications, built on adaptable components that integrate seamlessly with popular frameworks like Next Js.

28 lines (27 loc) 1.05 kB
/** * @module Middleware */ import { type Middleware } from "../../middleware/contracts/use.contract.js"; import { type InvokableFn, type OneOrMore } from "../../utilities/_module.js"; /** * IMPORT_PATH: `@daiso-tech/core/middleware` * @group Contracts */ export type InferMethodNames<TInstance> = { [TKey in keyof TInstance]: TInstance[TKey] extends InvokableFn<any, any> ? TKey : never; }[keyof TInstance]; /** * IMPORT_PATH: `@daiso-tech/core/middleware` * @group Contracts */ export type InferParameters<TValue> = TValue extends InvokableFn<infer R, any> ? R : never; /** * IMPORT_PATH: `@daiso-tech/core/middleware` * @group Contracts */ export type InferReturn<TValue> = TValue extends InvokableFn<Array<any>, infer R> ? R : never; /** * IMPORT_PATH: `@daiso-tech/core/middleware` * @group Contracts */ export type Enhance = <TInstance, TField extends InferMethodNames<TInstance>>(obj: TInstance, field: TField, middlewares: OneOrMore<Middleware<InferParameters<TInstance[TField]>, InferReturn<TInstance[TField]>>>) => void;