@kanian77/choux 0.1.7 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/HookRegistry.spec.js +11 -0
- package/dist/core/HookRegistry.spec.js.map +1 -1
- package/dist/core/PluginManager.d.ts +3 -2
- package/dist/core/PluginManager.d.ts.map +1 -1
- package/dist/core/PluginManager.js +9 -6
- package/dist/core/PluginManager.js.map +1 -1
- package/dist/decorators/enableHooksDecorator.d.ts +4 -0
- package/dist/decorators/enableHooksDecorator.d.ts.map +1 -0
- package/dist/decorators/enableHooksDecorator.js +10 -0
- package/dist/decorators/enableHooksDecorator.js.map +1 -0
- package/dist/decorators/hookDecorator.d.ts +0 -6
- package/dist/decorators/hookDecorator.d.ts.map +1 -1
- package/dist/decorators/hookDecorator.js +1 -8
- package/dist/decorators/hookDecorator.js.map +1 -1
- package/dist/decorators/hookDecorator.spec.d.ts +2 -0
- package/dist/decorators/hookDecorator.spec.d.ts.map +1 -0
- package/dist/decorators/hookDecorator.spec.js +51 -0
- package/dist/decorators/hookDecorator.spec.js.map +1 -0
- package/dist/decorators/index.d.ts +1 -0
- package/dist/decorators/index.d.ts.map +1 -1
- package/dist/decorators/index.js +1 -0
- package/dist/decorators/index.js.map +1 -1
- package/dist/lib/functions/registerHookHandler.d.ts +1 -1
- package/dist/lib/functions/registerHookHandler.d.ts.map +1 -1
- package/dist/lib/functions/registerHookHandler.js +4 -4
- package/dist/lib/functions/registerHookHandler.js.map +1 -1
- package/dist/lib/functions/registerInstanceHooks.d.ts +2 -0
- package/dist/lib/functions/registerInstanceHooks.d.ts.map +1 -0
- package/dist/lib/functions/registerInstanceHooks.js +19 -0
- package/dist/lib/functions/registerInstanceHooks.js.map +1 -0
- package/package.json +1 -1
|
@@ -14,6 +14,17 @@ describe('HookRegistry', () => {
|
|
|
14
14
|
await registry.trigger('test:hook');
|
|
15
15
|
expect(called).toBe(true);
|
|
16
16
|
});
|
|
17
|
+
it('registers and triggers a hook with payload', async () => {
|
|
18
|
+
let called = false;
|
|
19
|
+
const payload = { test: 'data' };
|
|
20
|
+
const fn = (payload) => {
|
|
21
|
+
called = true;
|
|
22
|
+
expect(payload).toEqual({ test: 'data' });
|
|
23
|
+
};
|
|
24
|
+
registry.register('test:hook', fn);
|
|
25
|
+
await registry.trigger('test:hook', payload);
|
|
26
|
+
expect(called).toBe(true);
|
|
27
|
+
});
|
|
17
28
|
it('unregisters a specific hook handler', async () => {
|
|
18
29
|
let called = false;
|
|
19
30
|
const fn = () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HookRegistry.spec.js","sourceRoot":"","sources":["../../src/core/HookRegistry.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAG9C,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC5B,IAAI,QAAsB,CAAC;IAE3B,UAAU,CAAC,GAAG,EAAE;QACd,QAAQ,GAAG,IAAI,YAAY,EAAE,CAAC;IAChC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,+BAA+B,EAAE,KAAK,IAAI,EAAE;QAC7C,IAAI,MAAM,GAAG,KAAK,CAAC;QACnB,MAAM,EAAE,GAAW,GAAG,EAAE;YACtB,MAAM,GAAG,IAAI,CAAC;QAChB,CAAC,CAAC;QACF,QAAQ,CAAC,QAAQ,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;QACnC,MAAM,QAAQ,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QACpC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,qCAAqC,EAAE,KAAK,IAAI,EAAE;QACnD,IAAI,MAAM,GAAG,KAAK,CAAC;QACn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,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;QAC7B,MAAM,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IAC/B,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,yBAAyB,EAAE,GAAG,EAAE;QACjC,MAAM,EAAE,GAAW,GAAG,EAAE,GAAE,CAAC,CAAC;QAC5B,QAAQ,CAAC,QAAQ,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;QACnC,QAAQ,CAAC,KAAK,EAAE,CAAC;QACjB,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACxD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6CAA6C,EAAE,KAAK,IAAI,EAAE;QAC3D,IAAI,MAAM,GAAG,EAAE,CAAC;QAChB,MAAM,GAAG,GAAW,KAAK,IAAI,EAAE;YAC7B,MAAM,IAAI,GAAG,CAAC;QAChB,CAAC,CAAC;QACF,MAAM,GAAG,GAAW,KAAK,IAAI,EAAE;YAC7B,MAAM,IAAI,GAAG,CAAC;QAChB,CAAC,CAAC;QACF,QAAQ,CAAC,QAAQ,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC;QACpC,QAAQ,CAAC,QAAQ,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC;QACpC,MAAM,QAAQ,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QACpC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import type { IHookRegistry, IPluginManager, LoadedPlugin } from '../lib/types';
|
|
2
2
|
import { PluginLoader } from './PluginLoader';
|
|
3
3
|
export declare class PluginManager implements IPluginManager {
|
|
4
|
-
private
|
|
4
|
+
private readonly hkRegistry;
|
|
5
5
|
private loader;
|
|
6
|
-
constructor(
|
|
6
|
+
constructor(hkRegistry: IHookRegistry, loader: PluginLoader);
|
|
7
7
|
initialize(...pluginsDir: string[]): Promise<void>;
|
|
8
8
|
shutdown(): Promise<void>;
|
|
9
9
|
getPlugin(name: string): LoadedPlugin | undefined;
|
|
10
10
|
getAllPlugins(): LoadedPlugin[];
|
|
11
|
+
get hookRegistry(): IHookRegistry;
|
|
11
12
|
}
|
|
12
13
|
//# sourceMappingURL=PluginManager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PluginManager.d.ts","sourceRoot":"","sources":["../../src/core/PluginManager.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAChF,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAI9C,qBACa,aAAc,YAAW,cAAc;IAEnB,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"PluginManager.d.ts","sourceRoot":"","sources":["../../src/core/PluginManager.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAChF,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAI9C,qBACa,aAAc,YAAW,cAAc;IAEnB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAClC,OAAO,CAAC,MAAM;gBADU,UAAU,EAAE,aAAa,EACzC,MAAM,EAAE,YAAY;IAG9C,UAAU,CAAC,GAAG,UAAU,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAelD,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAa/B,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;IAIjD,aAAa,IAAI,YAAY,EAAE;IAI/B,IAAI,YAAY,IAAI,aAAa,CAEhC;CACF"}
|
|
@@ -16,14 +16,14 @@ import { PLUGIN_MANAGER_TOKEN, HOOK_REGISTRY_TOKEN } from '../lib/types/tokens';
|
|
|
16
16
|
import { PluginLoader } from './PluginLoader';
|
|
17
17
|
// Removed local interface IPluginManager, now imported from lib/types
|
|
18
18
|
let PluginManager = class PluginManager {
|
|
19
|
-
|
|
19
|
+
hkRegistry;
|
|
20
20
|
loader;
|
|
21
|
-
constructor(
|
|
22
|
-
this.
|
|
21
|
+
constructor(hkRegistry, loader) {
|
|
22
|
+
this.hkRegistry = hkRegistry;
|
|
23
23
|
this.loader = loader;
|
|
24
24
|
}
|
|
25
25
|
async initialize(...pluginsDir) {
|
|
26
|
-
await this.
|
|
26
|
+
await this.hkRegistry.trigger(LIFECYCLE_HOOKS.APPLICATION_START);
|
|
27
27
|
let plugins = [];
|
|
28
28
|
await Promise.all(pluginsDir.map(async (dir) => {
|
|
29
29
|
const loaded = await this.loader.loadPlugins(dir);
|
|
@@ -35,13 +35,13 @@ let PluginManager = class PluginManager {
|
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
37
|
async shutdown() {
|
|
38
|
-
await this.
|
|
38
|
+
await this.hkRegistry.trigger(LIFECYCLE_HOOKS.APPLICATION_SHUTDOWN);
|
|
39
39
|
const plugins = this.loader.getAllPlugins();
|
|
40
40
|
// Unload in reverse dependency order
|
|
41
41
|
for (const plugin of plugins.reverse()) {
|
|
42
42
|
await this.loader.unloadPlugin(plugin.metadata.name);
|
|
43
43
|
}
|
|
44
|
-
this.
|
|
44
|
+
this.hkRegistry.clear();
|
|
45
45
|
}
|
|
46
46
|
getPlugin(name) {
|
|
47
47
|
return this.loader.getPlugin(name);
|
|
@@ -49,6 +49,9 @@ let PluginManager = class PluginManager {
|
|
|
49
49
|
getAllPlugins() {
|
|
50
50
|
return this.loader.getAllPlugins();
|
|
51
51
|
}
|
|
52
|
+
get hookRegistry() {
|
|
53
|
+
return this.hkRegistry;
|
|
54
|
+
}
|
|
52
55
|
};
|
|
53
56
|
PluginManager = __decorate([
|
|
54
57
|
Service({ token: PLUGIN_MANAGER_TOKEN }),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PluginManager.js","sourceRoot":"","sources":["../../src/core/PluginManager.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAU,OAAO,EAAE,MAAM,EAAU,MAAM,qBAAqB,CAAC;AACtE,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAEhF,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,sEAAsE;AAG/D,IAAM,aAAa,GAAnB,MAAM,aAAa;
|
|
1
|
+
{"version":3,"file":"PluginManager.js","sourceRoot":"","sources":["../../src/core/PluginManager.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAU,OAAO,EAAE,MAAM,EAAU,MAAM,qBAAqB,CAAC;AACtE,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAEhF,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,sEAAsE;AAG/D,IAAM,aAAa,GAAnB,MAAM,aAAa;IAEwB;IAChB;IAFhC,YACgD,UAAyB,EACzC,MAAoB;QADJ,eAAU,GAAV,UAAU,CAAe;QACzC,WAAM,GAAN,MAAM,CAAc;IACjD,CAAC;IAEJ,KAAK,CAAC,UAAU,CAAC,GAAG,UAAoB;QACtC,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,eAAe,CAAC,iBAAiB,CAAC,CAAC;QAEjE,IAAI,OAAO,GAAmB,EAAE,CAAC;QACjC,MAAM,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;YAC7C,MAAM,MAAM,GAAG,MAAM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AA,MAAM,CAAC,YAAY,CAAC,CAAA;6CAAiB,YAAY;GAHzC,aAAa,CA6CzB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enableHooksDecorator.d.ts","sourceRoot":"","sources":["../../src/decorators/enableHooksDecorator.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS;IAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,CAAA;CAAE,EAChE,aAAa,CAAC,KAOT,CACN,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { registerInstanceHooks } from '../lib/functions/registerInstanceHooks';
|
|
2
|
+
export const EnableHooks = (constructor) => {
|
|
3
|
+
return class extends constructor {
|
|
4
|
+
constructor(...args) {
|
|
5
|
+
super(...args);
|
|
6
|
+
registerInstanceHooks(this);
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=enableHooksDecorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enableHooksDecorator.js","sourceRoot":"","sources":["../../src/decorators/enableHooksDecorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,wCAAwC,CAAC;AAE/E,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,WAAc,EACd,EAAE;IACF,OAAO,KAAM,SAAQ,WAAW;QAC9B,YAAY,GAAG,IAAW;YACxB,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;YACf,qBAAqB,CAAC,IAAI,CAAC,CAAC;QAC9B,CAAC;KACG,CAAC;AACT,CAAC,CAAC"}
|
|
@@ -1,8 +1,2 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Decorator to register a method as a hook handler.
|
|
3
|
-
* This allows the method to be called when the specified hook is triggered.
|
|
4
|
-
* @param hookName The name of the hook to register this method for.
|
|
5
|
-
* @returns
|
|
6
|
-
*/
|
|
7
1
|
export declare function Hook(hookName: string): <T extends (...args: any[]) => any>(target: any, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T> | void;
|
|
8
2
|
//# sourceMappingURL=hookDecorator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hookDecorator.d.ts","sourceRoot":"","sources":["../../src/decorators/hookDecorator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"hookDecorator.d.ts","sourceRoot":"","sources":["../../src/decorators/hookDecorator.ts"],"names":[],"mappings":"AAEA,wBAAgB,IAAI,CAAC,QAAQ,EAAE,MAAM,IAClB,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EAChD,QAAQ,GAAG,EACX,aAAa,MAAM,GAAG,MAAM,EAC5B,YAAY,uBAAuB,CAAC,CAAC,CAAC,KACrC,uBAAuB,CAAC,CAAC,CAAC,GAAG,IAAI,CAarC"}
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
import { HOOK_METADATA_KEY } from '../lib/types
|
|
2
|
-
/**
|
|
3
|
-
* Decorator to register a method as a hook handler.
|
|
4
|
-
* This allows the method to be called when the specified hook is triggered.
|
|
5
|
-
* @param hookName The name of the hook to register this method for.
|
|
6
|
-
* @returns
|
|
7
|
-
*/
|
|
1
|
+
import { HOOK_METADATA_KEY } from '../lib/types';
|
|
8
2
|
export function Hook(hookName) {
|
|
9
3
|
return function (target, propertyKey, descriptor) {
|
|
10
4
|
// Store hook metadata on the class prototype
|
|
@@ -15,7 +9,6 @@ export function Hook(hookName) {
|
|
|
15
9
|
hookName,
|
|
16
10
|
methodName: propertyKey.toString(),
|
|
17
11
|
});
|
|
18
|
-
// Return the descriptor (or void, both are valid)
|
|
19
12
|
return descriptor;
|
|
20
13
|
};
|
|
21
14
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hookDecorator.js","sourceRoot":"","sources":["../../src/decorators/hookDecorator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"hookDecorator.js","sourceRoot":"","sources":["../../src/decorators/hookDecorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEjD,MAAM,UAAU,IAAI,CAAC,QAAgB;IACnC,OAAO,UACL,MAAW,EACX,WAA4B,EAC5B,UAAsC;QAEtC,6CAA6C;QAC7C,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,iBAAiB,CAAC,EAAE,CAAC;YAC3C,MAAM,CAAC,WAAW,CAAC,iBAAiB,CAAC,GAAG,EAAE,CAAC;QAC7C,CAAC;QAED,MAAM,CAAC,WAAW,CAAC,iBAAiB,CAAC,CAAC,IAAI,CAAC;YACzC,QAAQ;YACR,UAAU,EAAE,WAAW,CAAC,QAAQ,EAAE;SACnC,CAAC,CAAC;QAEH,OAAO,UAAU,CAAC;IACpB,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hookDecorator.spec.d.ts","sourceRoot":"","sources":["../../src/decorators/hookDecorator.spec.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import 'reflect-metadata';
|
|
11
|
+
import { describe, it, expect, beforeAll } from 'bun:test';
|
|
12
|
+
import { HookRegistry } from '../core';
|
|
13
|
+
import { Hook } from './hookDecorator';
|
|
14
|
+
import { bootstrap, inject, Module } from '@kanian77/simple-di';
|
|
15
|
+
import { HOOK_REGISTRY_TOKEN } from '../lib/types';
|
|
16
|
+
import { EnableHooks } from './enableHooksDecorator';
|
|
17
|
+
describe('hook decorators', () => {
|
|
18
|
+
let registry;
|
|
19
|
+
beforeAll(() => {
|
|
20
|
+
const RegistryModule = new Module({
|
|
21
|
+
providers: [
|
|
22
|
+
{
|
|
23
|
+
provide: HOOK_REGISTRY_TOKEN,
|
|
24
|
+
useClass: HookRegistry,
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
});
|
|
28
|
+
bootstrap(RegistryModule);
|
|
29
|
+
});
|
|
30
|
+
it('registers a hook', async () => {
|
|
31
|
+
let called = false;
|
|
32
|
+
let TestClass = class TestClass {
|
|
33
|
+
testMethod() {
|
|
34
|
+
called = true;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
__decorate([
|
|
38
|
+
Hook('test:hook'),
|
|
39
|
+
__metadata("design:type", Function),
|
|
40
|
+
__metadata("design:paramtypes", []),
|
|
41
|
+
__metadata("design:returntype", void 0)
|
|
42
|
+
], TestClass.prototype, "testMethod", null);
|
|
43
|
+
TestClass = __decorate([
|
|
44
|
+
EnableHooks
|
|
45
|
+
], TestClass);
|
|
46
|
+
const instance = new TestClass();
|
|
47
|
+
await inject(HOOK_REGISTRY_TOKEN).trigger('test:hook');
|
|
48
|
+
expect(called).toBe(true);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
//# sourceMappingURL=hookDecorator.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hookDecorator.spec.js","sourceRoot":"","sources":["../../src/decorators/hookDecorator.spec.ts"],"names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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC"}
|
package/dist/decorators/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare
|
|
1
|
+
export declare const registerHookHandler: (hookName: string, handler: (...args: any[]) => void | Promise<void>) => void;
|
|
2
2
|
//# sourceMappingURL=registerHookHandler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registerHookHandler.d.ts","sourceRoot":"","sources":["../../../src/lib/functions/registerHookHandler.ts"],"names":[],"mappings":"AAIA,
|
|
1
|
+
{"version":3,"file":"registerHookHandler.d.ts","sourceRoot":"","sources":["../../../src/lib/functions/registerHookHandler.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,mBAAmB,GAC9B,UAAU,MAAM,EAChB,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,SAIlD,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { inject } from
|
|
2
|
-
import { HOOK_REGISTRY_TOKEN } from
|
|
3
|
-
export
|
|
1
|
+
import { inject } from '@kanian77/simple-di';
|
|
2
|
+
import { HOOK_REGISTRY_TOKEN } from '../types/tokens';
|
|
3
|
+
export const registerHookHandler = (hookName, handler) => {
|
|
4
4
|
const hookRegistry = inject(HOOK_REGISTRY_TOKEN);
|
|
5
5
|
hookRegistry.register(hookName, handler);
|
|
6
|
-
}
|
|
6
|
+
};
|
|
7
7
|
//# sourceMappingURL=registerHookHandler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registerHookHandler.js","sourceRoot":"","sources":["../../../src/lib/functions/registerHookHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAE7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEtD,MAAM,
|
|
1
|
+
{"version":3,"file":"registerHookHandler.js","sourceRoot":"","sources":["../../../src/lib/functions/registerHookHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAE7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEtD,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,QAAgB,EAChB,OAAiD,EACjD,EAAE;IACF,MAAM,YAAY,GAAG,MAAM,CAAgB,mBAAmB,CAAC,CAAC;IAChE,YAAY,CAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;AAC3C,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registerInstanceHooks.d.ts","sourceRoot":"","sources":["../../../src/lib/functions/registerInstanceHooks.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,qBAAqB,GAAI,UAAU,GAAG,KAAG,IAerD,CAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { HOOK_METADATA_KEY } from "../types";
|
|
2
|
+
import { registerHookHandler } from "./registerHookHandler";
|
|
3
|
+
export const registerInstanceHooks = (instance) => {
|
|
4
|
+
try {
|
|
5
|
+
const hookMetadata = instance.constructor[HOOK_METADATA_KEY] || [];
|
|
6
|
+
for (const { hookName, methodName } of hookMetadata) {
|
|
7
|
+
const method = instance[methodName];
|
|
8
|
+
if (typeof method === 'function') {
|
|
9
|
+
// Get the original unwrapped method
|
|
10
|
+
const originalMethod = method.__original || method;
|
|
11
|
+
registerHookHandler(hookName, originalMethod.bind(instance));
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
console.warn('Failed to register hooks:', error);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=registerInstanceHooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registerInstanceHooks.js","sourceRoot":"","sources":["../../../src/lib/functions/registerInstanceHooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,QAAa,EAAQ,EAAE;IAC3D,IAAI,CAAC;QACH,MAAM,YAAY,GAAG,QAAQ,CAAC,WAAW,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC;QAEnE,KAAK,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,IAAI,YAAY,EAAE,CAAC;YACpD,MAAM,MAAM,GAAG,QAAQ,CAAC,UAAU,CAAC,CAAC;YACpC,IAAI,OAAO,MAAM,KAAK,UAAU,EAAE,CAAC;gBACjC,oCAAoC;gBACpC,MAAM,cAAc,GAAG,MAAM,CAAC,UAAU,IAAI,MAAM,CAAC;gBACnD,mBAAmB,CAAC,QAAQ,EAAE,cAAc,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;YAC/D,CAAC;QACH,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,IAAI,CAAC,2BAA2B,EAAE,KAAK,CAAC,CAAC;IACnD,CAAC;AACH,CAAC,CAAA"}
|