mirror of
https://github.com/KeygraphHQ/shannon.git
synced 2026-05-20 07:54:47 +02:00
53b4c6b83f
- Remove unnecessary non-null assertions where values are guaranteed - Replace array index access with .at() for safer element retrieval - Use local variables to avoid repeated process.env lookups - Replace any types with unknown in functional utilities - Use nullish coalescing for TOTP hash byte access - Auto-format security patches to match biome config
27 lines
861 B
TypeScript
27 lines
861 B
TypeScript
// Copyright (C) 2025 Keygraph, Inc.
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU Affero General Public License version 3
|
|
// as published by the Free Software Foundation.
|
|
|
|
/**
|
|
* Functional Programming Utilities
|
|
*
|
|
* Generic functional composition patterns for async operations.
|
|
*/
|
|
|
|
// biome-ignore lint/suspicious/noExplicitAny: pipeline functions need flexible typing for composition
|
|
type PipelineFunction = (x: any) => any | Promise<any>;
|
|
|
|
/**
|
|
* Async pipeline that passes result through a series of functions.
|
|
* Clearer than reduce-based pipe and easier to debug.
|
|
*/
|
|
export async function asyncPipe<TResult>(initial: unknown, ...fns: PipelineFunction[]): Promise<TResult> {
|
|
let result = initial;
|
|
for (const fn of fns) {
|
|
result = await fn(result);
|
|
}
|
|
return result as TResult;
|
|
}
|