import { type FnReturn } from '../../mod.js'; export type OnionNext = FnReturn>; export type OnionRing = (ctx: T, next: OnionNext) => RR | Promise; interface OnionCompose { (...middleware: [OnionRing]): (ctx: A) => RR extends Promise ? RR : Promise; (...middleware: [ OnionRing, OnionRing ]): (ctx: B) => RR extends Promise ? RR : Promise; (...middleware: [ OnionRing, OnionRing, OnionRing ]): (ctx: C) => RR extends Promise ? RR : Promise; (...middleware: [ OnionRing, OnionRing, OnionRing, OnionRing ]): (ctx: C) => RR extends Promise ? RR : Promise; (...middleware: [ OnionRing, OnionRing, OnionRing, OnionRing, OnionRing ]): (ctx: C) => RR extends Promise ? RR : Promise; (...middleware: [ OnionRing, OnionRing, OnionRing, OnionRing, OnionRing, OnionRing ]): (ctx: C) => RR extends Promise ? RR : Promise; (...middleware: [ OnionRing, OnionRing, OnionRing, OnionRing, OnionRing, OnionRing, OnionRing ]): (ctx: C) => RR extends Promise ? RR : Promise; (...middleware: [ OnionRing, OnionRing, OnionRing, OnionRing, OnionRing, OnionRing, OnionRing, OnionRing ]): (ctx: C) => RR extends Promise ? RR : Promise; } /** ## `onion_compose` : 洋葱模型 @example Usage ```ts const onion_one = async (context: number, next: OnionNext) => { const STEP = 1 const result = await next() return STEP + result + context } const onion_two = async (_context: number, next: OnionNext) => { const STEP = 2 const result = await next() return STEP + result } const onion_finish = (_context: any, _next: OnionNext) => { const STEP = 3 return STEP } const result_a = await onion_compose(onion_one, onion_two, onion_finish)(1) assert(result_a === 1 + 1 + 2 + 3) const onion_multiple_call = async ( context: number, next: OnionNext, ) => { const STEP = 1 // next() 不可多次调用,否则会报错 await next() await next() return STEP + context } await onion_compose(onion_multiple_call)(1).catch((e) => { assert((e as IllegalOperatError).instance_of(IllegalOperatError)) }) ``` @throws 当`next`在一个Ring中被多次调用时 {@link IllegalOperatError} @category Function */ export declare const onion_compose: OnionCompose; export {}; //# sourceMappingURL=onion.d.ts.map