fix(server): event handler bindings (#10165)

This commit is contained in:
forehalo
2025-02-14 11:29:02 +00:00
parent 42e0563d2e
commit 3dde47dd08
18 changed files with 486 additions and 260 deletions
@@ -0,0 +1,45 @@
export function makeMethodDecorator<
T extends any[],
Fn extends (...args: any[]) => any,
>(
decorator: (...args: T) => (target: any, key: string | symbol, fn: Fn) => Fn
) {
return (...args: T) => {
return (
target: any,
key: string | symbol,
desc: TypedPropertyDescriptor<any>
) => {
const originalFn = desc.value;
if (!originalFn || typeof originalFn !== 'function') {
throw new Error(
`MethodDecorator must be applied to a function but got ${typeof originalFn}`
);
}
const decoratedFn = decorator(...args)(target, key, originalFn);
desc.value = decoratedFn;
return desc;
};
};
}
export function PushMetadata<T>(key: string | symbol, value: T) {
const decorator: ClassDecorator | MethodDecorator = (
target,
_,
descriptor
) => {
const metadataTarget = descriptor?.value ?? target;
const metadataArray = Reflect.getMetadata(key, metadataTarget) || [];
metadataArray.push(value);
Reflect.defineMetadata(key, metadataArray, metadataTarget);
};
return decorator;
}
export function sliceMetadata<T>(key: string | symbol, target: any): T[] {
return Reflect.getMetadata(key, target) || [];
}
@@ -1,3 +1,4 @@
import './config';
export * from './decorator';
export * from './exception';
export * from './optional-module';