Tweak types a little
This commit is contained in:
parent
5a6af74413
commit
6e342b9667
@ -6,15 +6,12 @@ type PolicyTuple<Opts = unknown> = [policy: Policy<Opts>, opts?: Opts];
|
|||||||
/** Helper type for proper type inference of PolicyTuples in the pipeline. */
|
/** Helper type for proper type inference of PolicyTuples in the pipeline. */
|
||||||
// https://stackoverflow.com/a/75806165
|
// https://stackoverflow.com/a/75806165
|
||||||
// https://stackoverflow.com/a/54608401
|
// https://stackoverflow.com/a/54608401
|
||||||
type PolicyTuplesRest<T extends PolicyTuple[]> = {
|
type PolicySpread<T extends any[]> = {
|
||||||
[K in keyof T]: PolicyTuple<T[K]> | Policy<T[K]>;
|
[K in keyof T]: PolicyTuple<T[K]> | Policy<T[K]>;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Processes messages through multiple policies, bailing early on rejection. */
|
/** Processes messages through multiple policies, bailing early on rejection. */
|
||||||
async function pipeline<P extends any[]>(
|
async function pipeline<T extends any[]>(msg: InputMessage, policies: [...PolicySpread<T>]): Promise<OutputMessage> {
|
||||||
msg: InputMessage,
|
|
||||||
policies: [...PolicyTuplesRest<P>],
|
|
||||||
): Promise<OutputMessage> {
|
|
||||||
for (const item of policies) {
|
for (const item of policies) {
|
||||||
const [policy, opts] = toTuple(item);
|
const [policy, opts] = toTuple(item);
|
||||||
const result = await policy(msg, opts);
|
const result = await policy(msg, opts);
|
||||||
|
Loading…
Reference in New Issue
Block a user