feat(pockethost): extensible filter data types

This commit is contained in:
Ben Allfree 2024-06-29 14:26:17 -07:00
parent dd3ceaa324
commit 82dde2db37
2 changed files with 19 additions and 4 deletions

View File

@ -0,0 +1,5 @@
---
'pockethost': minor
---
Enhancement: filters now have extensible data types

View File

@ -81,8 +81,15 @@ function createCustomFilterWithContext<TCarry, TContext extends {} = {}>(
return [
async (initialValue: TCarry, context: TContext) =>
filter<TCarry, TContext>(filterName, initialValue, context),
async (handler: FilterHandler<TCarry, TContext>, priority = 10) =>
registerFilter<TCarry, TContext>(filterName, handler, priority),
async <TExtraCarry = unknown>(
handler: FilterHandler<TCarry & TExtraCarry, TContext>,
priority = 10,
) =>
registerFilter<TCarry & TExtraCarry, TContext>(
filterName,
handler,
priority,
),
] as const
}
@ -90,8 +97,11 @@ function createCustomFilter<TCarry>(filterName: string) {
return [
async (initialValue: TCarry) =>
filter<TCarry>(filterName, initialValue, {}),
async (handler: FilterHandler<TCarry, {}>, priority = 10) =>
registerFilter<TCarry, {}>(filterName, handler, priority),
async <TExtraCarry = unknown>(
handler: FilterHandler<TCarry & TExtraCarry, {}>,
priority = 10,
) =>
registerFilter<TCarry & TExtraCarry, {}>(filterName, handler, priority),
] as const
}