strfry-policies/src/pipeline.ts

20 lines
481 B
TypeScript
Raw Normal View History

import { InputMessage, OutputMessage, Policy } from './types.ts';
2023-03-24 19:36:11 +00:00
/** Processes messages through multiple policies, bailing early on rejection. */
async function pipeline(msg: InputMessage, policies: Policy[]): Promise<OutputMessage> {
for (const policy of policies) {
const result = await policy(msg);
if (result.action !== 'accept') {
return result;
}
}
return {
id: msg.event.id,
action: 'accept',
msg: '',
};
}
export default pipeline;