fixed typescript
This commit is contained in:
parent
931f212ec7
commit
4096e91e67
6 changed files with 112 additions and 147 deletions
|
|
@ -1,4 +1,4 @@
|
|||
// Modern TC39 Stage 3 decorators for handler registration
|
||||
// Bun-compatible decorators (hybrid approach)
|
||||
|
||||
/**
|
||||
* Handler decorator - marks a class as a handler
|
||||
|
|
@ -7,13 +7,12 @@
|
|||
export function Handler(name: string) {
|
||||
return function <T extends { new (...args: any[]): {} }>(
|
||||
target: T,
|
||||
context: ClassDecoratorContext
|
||||
_context?: any
|
||||
) {
|
||||
// Store handler name on the constructor
|
||||
(target as any).__handlerName = name;
|
||||
(target as any).__needsAutoRegistration = true;
|
||||
|
||||
console.log('Handler decorator applied', { name, className: context.name });
|
||||
return target;
|
||||
};
|
||||
}
|
||||
|
|
@ -22,39 +21,24 @@ export function Handler(name: string) {
|
|||
* Operation decorator - marks a method as an operation
|
||||
* @param name Operation name
|
||||
*/
|
||||
export function Operation(name: string) {
|
||||
export function Operation(name: string): any {
|
||||
return function (
|
||||
_target: Function,
|
||||
context: ClassMethodDecoratorContext
|
||||
) {
|
||||
const methodName = String(context.name);
|
||||
target: any,
|
||||
methodName: string,
|
||||
descriptor?: PropertyDescriptor
|
||||
): any {
|
||||
// Store metadata directly on the class constructor
|
||||
const constructor = target.constructor;
|
||||
|
||||
console.log('Operation decorator applied', {
|
||||
operationName: name,
|
||||
methodName,
|
||||
contextName: context.name,
|
||||
contextKind: context.kind
|
||||
if (!constructor.__operations) {
|
||||
constructor.__operations = [];
|
||||
}
|
||||
constructor.__operations.push({
|
||||
name,
|
||||
method: methodName,
|
||||
});
|
||||
|
||||
// Use context.addInitializer to run code when the class is constructed
|
||||
context.addInitializer(function(this: any) {
|
||||
const constructor = this.constructor as any;
|
||||
if (!constructor.__operations) {
|
||||
constructor.__operations = [];
|
||||
}
|
||||
constructor.__operations.push({
|
||||
name,
|
||||
method: methodName,
|
||||
});
|
||||
|
||||
console.log('Operation registered via initializer', {
|
||||
name,
|
||||
methodName,
|
||||
className: constructor.name
|
||||
});
|
||||
});
|
||||
|
||||
// Don't return anything - just modify metadata
|
||||
return descriptor;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -70,27 +54,25 @@ export function QueueSchedule(
|
|||
immediately?: boolean;
|
||||
description?: string;
|
||||
}
|
||||
) {
|
||||
): any {
|
||||
return function (
|
||||
_target: Function,
|
||||
context: ClassMethodDecoratorContext
|
||||
) {
|
||||
const methodName = String(context.name);
|
||||
target: any,
|
||||
methodName: string,
|
||||
descriptor?: PropertyDescriptor
|
||||
): any {
|
||||
// Store metadata directly on the class constructor
|
||||
const constructor = target.constructor;
|
||||
|
||||
// Use context.addInitializer to run code when the class is constructed
|
||||
context.addInitializer(function(this: any) {
|
||||
const constructor = this.constructor as any;
|
||||
if (!constructor.__schedules) {
|
||||
constructor.__schedules = [];
|
||||
}
|
||||
constructor.__schedules.push({
|
||||
operation: methodName,
|
||||
cronPattern,
|
||||
...options,
|
||||
});
|
||||
if (!constructor.__schedules) {
|
||||
constructor.__schedules = [];
|
||||
}
|
||||
constructor.__schedules.push({
|
||||
operation: methodName,
|
||||
cronPattern,
|
||||
...options,
|
||||
});
|
||||
|
||||
// Don't return anything - just modify metadata
|
||||
return descriptor;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue