@kanian77/choux 0.1.5 → 0.1.7

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.
Files changed (135) hide show
  1. package/dist/core/ChouxModule.d.ts +3 -0
  2. package/dist/core/ChouxModule.d.ts.map +1 -0
  3. package/{src/core/ChouxModule.ts → dist/core/ChouxModule.js} +11 -11
  4. package/dist/core/ChouxModule.js.map +1 -0
  5. package/dist/core/HookRegistry.d.ts +47 -0
  6. package/dist/core/HookRegistry.d.ts.map +1 -0
  7. package/dist/core/HookRegistry.js +79 -0
  8. package/dist/core/HookRegistry.js.map +1 -0
  9. package/dist/core/HookRegistry.spec.d.ts +2 -0
  10. package/dist/core/HookRegistry.spec.d.ts.map +1 -0
  11. package/dist/core/HookRegistry.spec.js +67 -0
  12. package/dist/core/HookRegistry.spec.js.map +1 -0
  13. package/dist/core/Plugin.d.ts +22 -0
  14. package/dist/core/Plugin.d.ts.map +1 -0
  15. package/dist/core/Plugin.js +4 -0
  16. package/dist/core/Plugin.js.map +1 -0
  17. package/dist/core/PluginLoader.d.ts +13 -0
  18. package/dist/core/PluginLoader.d.ts.map +1 -0
  19. package/dist/core/PluginLoader.js +147 -0
  20. package/dist/core/PluginLoader.js.map +1 -0
  21. package/dist/core/PluginLoader.spec.d.ts +2 -0
  22. package/dist/core/PluginLoader.spec.d.ts.map +1 -0
  23. package/dist/core/PluginLoader.spec.js +114 -0
  24. package/dist/core/PluginLoader.spec.js.map +1 -0
  25. package/dist/core/PluginManager.d.ts +12 -0
  26. package/dist/core/PluginManager.d.ts.map +1 -0
  27. package/dist/core/PluginManager.js +60 -0
  28. package/dist/core/PluginManager.js.map +1 -0
  29. package/dist/core/PluginManager.spec.d.ts +2 -0
  30. package/dist/core/PluginManager.spec.d.ts.map +1 -0
  31. package/dist/core/PluginManager.spec.js +50 -0
  32. package/dist/core/PluginManager.spec.js.map +1 -0
  33. package/dist/core/index.d.ts +5 -0
  34. package/dist/core/index.d.ts.map +1 -0
  35. package/{src/core/index.ts → dist/core/index.js} +1 -0
  36. package/dist/core/index.js.map +1 -0
  37. package/dist/decorators/hookDecorator.d.ts +8 -0
  38. package/dist/decorators/hookDecorator.d.ts.map +1 -0
  39. package/dist/decorators/hookDecorator.js +22 -0
  40. package/dist/decorators/hookDecorator.js.map +1 -0
  41. package/dist/decorators/index.d.ts +2 -0
  42. package/dist/decorators/index.d.ts.map +1 -0
  43. package/{src/decorators/index.ts → dist/decorators/index.js} +1 -0
  44. package/dist/decorators/index.js.map +1 -0
  45. package/dist/example-plugin/module.d.ts.map +1 -0
  46. package/{src → dist}/example-plugin/module.js +9 -9
  47. package/dist/example-plugin/module.js.map +1 -0
  48. package/dist/example-plugin/services.d.ts.map +1 -0
  49. package/{src → dist}/example-plugin/services.js +2 -1
  50. package/dist/example-plugin/services.js.map +1 -0
  51. package/dist/example-plugin/tokens.d.ts.map +1 -0
  52. package/dist/example-plugin/tokens.js.map +1 -0
  53. package/dist/index.d.ts +5 -0
  54. package/dist/index.d.ts.map +1 -0
  55. package/{src/index.ts → dist/index.js} +1 -0
  56. package/dist/index.js.map +1 -0
  57. package/dist/lib/functions/index.d.ts +3 -0
  58. package/dist/lib/functions/index.d.ts.map +1 -0
  59. package/{src/lib/functions/index.ts → dist/lib/functions/index.js} +1 -0
  60. package/dist/lib/functions/index.js.map +1 -0
  61. package/dist/lib/functions/registerHookHandler.d.ts +2 -0
  62. package/dist/lib/functions/registerHookHandler.d.ts.map +1 -0
  63. package/dist/lib/functions/registerHookHandler.js +7 -0
  64. package/dist/lib/functions/registerHookHandler.js.map +1 -0
  65. package/dist/lib/functions/registerHooksForInstance.d.ts +2 -0
  66. package/dist/lib/functions/registerHooksForInstance.d.ts.map +1 -0
  67. package/dist/lib/functions/registerHooksForInstance.js +22 -0
  68. package/dist/lib/functions/registerHooksForInstance.js.map +1 -0
  69. package/dist/lib/test-related/plugins/plugin-a/module.d.ts +21 -0
  70. package/dist/lib/test-related/plugins/plugin-a/module.d.ts.map +1 -0
  71. package/dist/lib/test-related/plugins/plugin-a/module.js +84 -0
  72. package/dist/lib/test-related/plugins/plugin-a/module.js.map +1 -0
  73. package/dist/lib/test-related/plugins/plugin-b/module.d.ts +21 -0
  74. package/dist/lib/test-related/plugins/plugin-b/module.d.ts.map +1 -0
  75. package/dist/lib/test-related/plugins/plugin-b/module.js +84 -0
  76. package/dist/lib/test-related/plugins/plugin-b/module.js.map +1 -0
  77. package/dist/lib/types/HookMetadata.d.ts +5 -0
  78. package/dist/lib/types/HookMetadata.d.ts.map +1 -0
  79. package/dist/lib/types/HookMetadata.js +1 -0
  80. package/dist/lib/types/HookMetadata.js.map +1 -0
  81. package/dist/lib/types/IHookRegistry.d.ts +10 -0
  82. package/dist/lib/types/IHookRegistry.d.ts.map +1 -0
  83. package/dist/lib/types/IHookRegistry.js +1 -0
  84. package/dist/lib/types/IHookRegistry.js.map +1 -0
  85. package/dist/lib/types/IPluginManager.d.ts +8 -0
  86. package/dist/lib/types/IPluginManager.d.ts.map +1 -0
  87. package/dist/lib/types/IPluginManager.js +1 -0
  88. package/dist/lib/types/IPluginManager.js.map +1 -0
  89. package/{src/lib/types/LoadedPlugin.ts → dist/lib/types/LoadedPlugin.d.ts} +4 -4
  90. package/dist/lib/types/LoadedPlugin.d.ts.map +1 -0
  91. package/dist/lib/types/LoadedPlugin.js +1 -0
  92. package/dist/lib/types/LoadedPlugin.js.map +1 -0
  93. package/dist/lib/types/PluginMetadata.d.ts +7 -0
  94. package/dist/lib/types/PluginMetadata.d.ts.map +1 -0
  95. package/dist/lib/types/PluginMetadata.js +1 -0
  96. package/dist/lib/types/PluginMetadata.js.map +1 -0
  97. package/dist/lib/types/index.d.ts +7 -0
  98. package/dist/lib/types/index.d.ts.map +1 -0
  99. package/{src/lib/types/index.ts → dist/lib/types/index.js} +1 -0
  100. package/dist/lib/types/index.js.map +1 -0
  101. package/dist/lib/types/tokens.d.ts +5 -0
  102. package/dist/lib/types/tokens.d.ts.map +1 -0
  103. package/{src/lib/types/tokens.ts → dist/lib/types/tokens.js} +1 -0
  104. package/dist/lib/types/tokens.js.map +1 -0
  105. package/package.json +1 -1
  106. package/src/core/HookRegistry.spec.ts +0 -75
  107. package/src/core/HookRegistry.ts +0 -78
  108. package/src/core/Plugin.ts +0 -26
  109. package/src/core/PluginLoader.spec.ts +0 -138
  110. package/src/core/PluginLoader.ts +0 -192
  111. package/src/core/PluginManager.spec.ts +0 -57
  112. package/src/core/PluginManager.ts +0 -47
  113. package/src/decorators/hookDecorator.ts +0 -30
  114. package/src/example-plugin/module.d.ts.map +0 -1
  115. package/src/example-plugin/module.js.map +0 -1
  116. package/src/example-plugin/module.ts +0 -80
  117. package/src/example-plugin/services.d.ts.map +0 -1
  118. package/src/example-plugin/services.js.map +0 -1
  119. package/src/example-plugin/services.ts +0 -22
  120. package/src/example-plugin/tokens.d.ts.map +0 -1
  121. package/src/example-plugin/tokens.js.map +0 -1
  122. package/src/example-plugin/tokens.ts +0 -1
  123. package/src/lib/functions/registerHookHandler.ts +0 -11
  124. package/src/lib/functions/registerHooksForInstance.ts +0 -26
  125. package/src/lib/test-related/plugins/plugin-a/module.ts +0 -74
  126. package/src/lib/test-related/plugins/plugin-b/module.ts +0 -74
  127. package/src/lib/types/HookMetadata.ts +0 -4
  128. package/src/lib/types/IHookRegistry.ts +0 -10
  129. package/src/lib/types/IPluginManager.ts +0 -8
  130. package/src/lib/types/PluginMetadata.ts +0 -9
  131. package/src/lib/types/README.md +0 -3
  132. /package/{src → dist}/example-plugin/module.d.ts +0 -0
  133. /package/{src → dist}/example-plugin/services.d.ts +0 -0
  134. /package/{src → dist}/example-plugin/tokens.d.ts +0 -0
  135. /package/{src → dist}/example-plugin/tokens.js +0 -0
@@ -1,57 +0,0 @@
1
- import { describe, it, expect, beforeEach, afterEach } from 'bun:test';
2
- import { PluginManager } from './PluginManager';
3
- import { resolve } from 'path';
4
- import { inject } from '@kanian77/simple-di';
5
- import { PLUGIN_MANAGER_TOKEN } from '../lib/types/tokens';
6
-
7
- describe('PluginManager', () => {
8
- let manager: PluginManager;
9
- const pluginsDir = resolve('src/lib/test-related/plugins');
10
-
11
- beforeEach(() => {
12
- manager = inject<PluginManager>(PLUGIN_MANAGER_TOKEN);
13
- });
14
-
15
- afterEach(async () => {
16
- // No cleanup needed for static test plugins
17
- });
18
-
19
- it('initialize loads plugins and prints info', async () => {
20
- let logOutput = '';
21
- const origLog = console.log;
22
- console.log = (msg: string) => {
23
- logOutput += msg + '\n';
24
- };
25
- await manager.initialize(pluginsDir);
26
- expect(logOutput).toContain('Loaded 2 plugins:');
27
- expect(logOutput).toContain('plugin-a');
28
- expect(logOutput).toContain('plugin-b');
29
- console.log = origLog;
30
- });
31
-
32
- it('getPlugin returns correct plugin', async () => {
33
- await manager.initialize(pluginsDir);
34
- const pluginA = manager.getPlugin('pluginA');
35
- expect(pluginA).toBeDefined();
36
- expect(pluginA?.metadata.name).toBe('pluginA');
37
- const pluginB = manager.getPlugin('pluginB');
38
- expect(pluginB).toBeDefined();
39
- expect(pluginB?.metadata.name).toBe('pluginB');
40
- });
41
-
42
- it('getAllPlugins returns all loaded plugins', async () => {
43
- await manager.initialize(pluginsDir);
44
- const all = manager.getAllPlugins();
45
- expect(all.length).toBe(2);
46
- expect(all.map((p) => p.metadata.name).sort()).toEqual([
47
- 'pluginA',
48
- 'pluginB',
49
- ]);
50
- });
51
-
52
- it('shutdown unloads all plugins and clears registry', async () => {
53
- await manager.initialize(pluginsDir);
54
- await manager.shutdown();
55
- expect(manager.getAllPlugins()).toEqual([]);
56
- });
57
- });
@@ -1,47 +0,0 @@
1
- import { Module, Service, Inject, inject } from '@kanian77/simple-di';
2
- import { LIFECYCLE_HOOKS } from './HookRegistry';
3
- import { PLUGIN_MANAGER_TOKEN, HOOK_REGISTRY_TOKEN } from '../lib/types/tokens';
4
- import type { IHookRegistry, IPluginManager, LoadedPlugin } from '../lib/types';
5
- import { PluginLoader } from './PluginLoader';
6
-
7
- // Removed local interface IPluginManager, now imported from lib/types
8
-
9
- @Service({ token: PLUGIN_MANAGER_TOKEN })
10
- export class PluginManager implements IPluginManager {
11
- constructor(
12
- @Inject(HOOK_REGISTRY_TOKEN) private hookRegistry: IHookRegistry,
13
- @Inject(PluginLoader) private loader: PluginLoader
14
- ) {}
15
-
16
- async initialize(pluginsDir: string): Promise<void> {
17
- await this.hookRegistry.trigger(LIFECYCLE_HOOKS.APPLICATION_START);
18
-
19
- const plugins = await this.loader.loadPlugins(pluginsDir);
20
-
21
- console.log(`Loaded ${plugins.length} plugins:`);
22
- plugins.forEach((p) => {
23
- console.log(` - ${p.metadata.name} v${p.metadata.version}`);
24
- });
25
- }
26
-
27
- async shutdown(): Promise<void> {
28
- await this.hookRegistry.trigger(LIFECYCLE_HOOKS.APPLICATION_SHUTDOWN);
29
-
30
- const plugins = this.loader.getAllPlugins();
31
-
32
- // Unload in reverse dependency order
33
- for (const plugin of plugins.reverse()) {
34
- await this.loader.unloadPlugin(plugin.metadata.name);
35
- }
36
-
37
- this.hookRegistry.clear();
38
- }
39
-
40
- getPlugin(name: string): LoadedPlugin | undefined {
41
- return this.loader.getPlugin(name);
42
- }
43
-
44
- getAllPlugins(): LoadedPlugin[] {
45
- return this.loader.getAllPlugins();
46
- }
47
- }
@@ -1,30 +0,0 @@
1
- import { inject } from '@kanian77/simple-di';
2
- import { HOOK_METADATA_KEY, HOOK_REGISTRY_TOKEN } from '../lib/types/tokens';
3
- import type { IHookRegistry } from '../lib/types';
4
-
5
- /**
6
- * Decorator to register a method as a hook handler.
7
- * This allows the method to be called when the specified hook is triggered.
8
- * @param hookName The name of the hook to register this method for.
9
- * @returns
10
- */
11
- export function Hook(hookName: string) {
12
- return function <T extends (...args: any[]) => any>(
13
- target: any,
14
- propertyKey: string | symbol,
15
- descriptor: TypedPropertyDescriptor<T>
16
- ): TypedPropertyDescriptor<T> | void {
17
- // Store hook metadata on the class prototype
18
- if (!target.constructor[HOOK_METADATA_KEY]) {
19
- target.constructor[HOOK_METADATA_KEY] = [];
20
- }
21
-
22
- target.constructor[HOOK_METADATA_KEY].push({
23
- hookName,
24
- methodName: propertyKey.toString(),
25
- });
26
-
27
- // Return the descriptor (or void, both are valid)
28
- return descriptor;
29
- };
30
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"module.d.ts","sourceRoot":"","sources":["module.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAI/C,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,MAAM;IAC/C,QAAQ,CAAC,QAAQ;;;;;MAKf;;IAgBa,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAIvB,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAOvB,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;cAItB,mBAAmB,IAAI,IAAI;YAQhC,kBAAkB;YAKlB,kBAAkB;YAKlB,kBAAkB;IAKhC,OAAO,CAAC,uBAAuB;YAOjB,iBAAiB;CAGhC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"module.js","sourceRoot":"","sources":["module.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AACjD,OAAO,EAAE,IAAI,EAAE,MAAM,oCAAoC,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAE/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEjE,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,MAAM;IAQ/C;QACE,2DAA2D;QAC3D,KAAK,CAAC;YACJ,SAAS,EAAE;gBACT;oBACE,OAAO,EAAE,qBAAqB;oBAC9B,QAAQ,EAAE,cAAc;iBACzB;aACF;YACD,0CAA0C;YAC1C,8BAA8B;SAC/B,CAAC,CAAC;QAlBI,aAAQ,GAAG;YAClB,IAAI,EAAE,gBAAgB;YACtB,OAAO,EAAE,OAAO;YAChB,WAAW,EAAE,mBAAmB;YAChC,YAAY,EAAE,EAAE,EAAE,qCAAqC;SACxD,CAAC;IAcF,CAAC;IAEQ,KAAK,CAAC,MAAM;QACnB,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;IAC1C,CAAC;IAEQ,KAAK,CAAC,MAAM;QACnB,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;QAE1C,gDAAgD;QAChD,IAAI,CAAC,uBAAuB,EAAE,CAAC;IACjC,CAAC;IAEQ,KAAK,CAAC,SAAS;QACtB,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;IAC1C,CAAC;IAEkB,mBAAmB;QACpC,gDAAgD;QAChD,0CAA0C;QAC1C,OAAO,CAAC,GAAG,CAAC,4CAA4C,CAAC,CAAC;IAC5D,CAAC;IAED,kEAAkE;IAEpD,AAAN,KAAK,CAAC,kBAAkB,CAAC,IAAS;QACxC,OAAO,CAAC,GAAG,CAAC,uCAAuC,EAAE,IAAI,CAAC,CAAC;IAC7D,CAAC;IAGa,AAAN,KAAK,CAAC,kBAAkB;QAC9B,OAAO,CAAC,GAAG,CAAC,6DAA6D,CAAC,CAAC;IAC7E,CAAC;IAGa,AAAN,KAAK,CAAC,kBAAkB,CAAC,UAAkB;QACjD,OAAO,CAAC,GAAG,CAAC,kCAAkC,EAAE,UAAU,CAAC,CAAC;IAC9D,CAAC;IAED,iDAAiD;IACzC,uBAAuB;QAC7B,MAAM,YAAY,GAAG,MAAM,CAAgB,mBAAmB,CAAC,CAAC;QAEhE,+CAA+C;QAC/C,YAAY,CAAC,QAAQ,CAAC,qBAAqB,EAAE,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAClF,CAAC;IAEO,KAAK,CAAC,iBAAiB,CAAC,IAAS;QACvC,OAAO,CAAC,GAAG,CAAC,wBAAwB,EAAE,IAAI,CAAC,CAAC;IAC9C,CAAC;CACF;AAzBe;IADb,IAAI,CAAC,sBAAsB,CAAC;;;;uDAG5B;AAGa;IADb,IAAI,CAAC,wBAAwB,CAAC;;;;uDAG9B;AAGa;IADb,IAAI,CAAC,yBAAyB,CAAC;;;;uDAG/B"}
@@ -1,80 +0,0 @@
1
- import { Module } from '@kanian77/simple-di';
2
- import { ExampleService } from './services';
3
- import { EXAMPLE_SERVICE_TOKEN } from './tokens';
4
- import { Hook } from '../decorators/hookDecorator';
5
- import { inject } from '@kanian77/simple-di';
6
- import { Plugin } from '../core/Plugin';
7
- import type { IHookRegistry } from '../../src/lib/types';
8
- import { HOOK_REGISTRY_TOKEN } from '../lib/types/tokens';
9
-
10
- export default class ExamplePlugin extends Plugin {
11
- readonly metadata = {
12
- name: 'example-plugin',
13
- version: '1.0.0',
14
- description: 'An example plugin',
15
- dependencies: [], // other plugin names this depends on
16
- };
17
-
18
- constructor() {
19
- // Call parent Module constructor with plugin configuration
20
- super({
21
- providers: [
22
- {
23
- provide: EXAMPLE_SERVICE_TOKEN,
24
- useClass: ExampleService,
25
- },
26
- ],
27
- // Can also import other modules if needed
28
- // imports: [SomeOtherModule],
29
- });
30
- }
31
-
32
- override async onLoad(): Promise<void> {
33
- console.log('ExamplePlugin loading...');
34
- }
35
-
36
- override async onInit(): Promise<void> {
37
- console.log('ExamplePlugin initialized!');
38
-
39
- // Additional manual hook registration if needed
40
- this.registerAdditionalHooks();
41
- }
42
-
43
- override async onDestroy(): Promise<void> {
44
- console.log('ExamplePlugin destroyed!');
45
- }
46
-
47
- protected override registerCustomHooks(): void {
48
- // Define custom hooks that this plugin provides
49
- // Other plugins can listen to these hooks
50
- console.log('Registering custom hooks for ExamplePlugin');
51
- }
52
-
53
- // These methods will be automatically registered as hook handlers
54
- @Hook('custom:example-event')
55
- private async handleExampleEvent(data: any): Promise<void> {
56
- console.log('Handling example event via decorator:', data);
57
- }
58
-
59
- @Hook('core:application-start')
60
- private async onApplicationStart(): Promise<void> {
61
- console.log('ExamplePlugin responding to application start via decorator');
62
- }
63
-
64
- @Hook('core:before-plugin-load')
65
- private async onBeforePluginLoad(pluginPath: string): Promise<void> {
66
- console.log('Another plugin is about to load:', pluginPath);
67
- }
68
-
69
- // Manual hook registration for dynamic scenarios
70
- private registerAdditionalHooks(): void {
71
- const hookRegistry = inject<IHookRegistry>(HOOK_REGISTRY_TOKEN);
72
-
73
- // Register additional hooks manually if needed
74
- hookRegistry.register('dynamic:custom-hook', this.handleDynamicHook.bind(this));
75
- }
76
-
77
- private async handleDynamicHook(data: any): Promise<void> {
78
- console.log('Handling dynamic hook:', data);
79
- }
80
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"services.d.ts","sourceRoot":"","sources":["services.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,eAAe;IAC9B,WAAW,IAAI,IAAI,CAAC;CACrB;AAED,qBACa,cAAe,YAAW,eAAe;IACpD,OAAO,CAAC,YAAY,CAAgB;;IAKpC,WAAW,IAAI,IAAI;CAKpB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"services.js","sourceRoot":"","sources":["services.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,OAAO,EAAU,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAQ1D,IAAM,cAAc,GAApB,MAAM,cAAc;IAEzB;QACE,IAAI,CAAC,YAAY,GAAG,MAAM,CAAgB,mBAAmB,CAAC,CAAC;IACjE,CAAC;IAED,WAAW;QACT,OAAO,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAC;QACjD,2BAA2B;QAC3B,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,wBAAwB,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;IAC3E,CAAC;CACF,CAAA;AAXY,cAAc;IAD1B,OAAO,CAAC,EAAE,KAAK,EAAE,qBAAqB,EAAE,CAAC;;GAC7B,cAAc,CAW1B"}
@@ -1,22 +0,0 @@
1
- import { Service, Inject, inject } from '@kanian77/simple-di';
2
- import { EXAMPLE_SERVICE_TOKEN } from './tokens';
3
- import { HOOK_REGISTRY_TOKEN } from '../lib/types/tokens';
4
- import type { IHookRegistry } from '../../src/lib/types';
5
-
6
- export interface IExampleService {
7
- doSomething(): void;
8
- }
9
-
10
- @Service({ token: EXAMPLE_SERVICE_TOKEN })
11
- export class ExampleService implements IExampleService {
12
- private hookRegistry: IHookRegistry;
13
- constructor() {
14
- this.hookRegistry = inject<IHookRegistry>(HOOK_REGISTRY_TOKEN);
15
- }
16
-
17
- doSomething(): void {
18
- console.log('ExampleService doing something...');
19
- // Can trigger custom hooks
20
- this.hookRegistry.trigger('example:something-done', { data: 'example' });
21
- }
22
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["tokens.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,eAA2B,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"tokens.js","sourceRoot":"","sources":["tokens.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC"}
@@ -1 +0,0 @@
1
- export const EXAMPLE_SERVICE_TOKEN = Symbol('ExampleService');
@@ -1,11 +0,0 @@
1
- import { inject } from "@kanian77/simple-di";
2
- import type { IHookRegistry } from "../types";
3
- import { HOOK_REGISTRY_TOKEN } from "../types/tokens";
4
-
5
- export function registerHookHandler(
6
- hookName: string,
7
- handler: (...args: any[]) => void | Promise<void>
8
- ) {
9
- const hookRegistry = inject<IHookRegistry>(HOOK_REGISTRY_TOKEN);
10
- hookRegistry.register(hookName, handler);
11
- }
@@ -1,26 +0,0 @@
1
- import { inject } from "@kanian77/simple-di";
2
- import type { IHookRegistry } from "../types";
3
- import type { HookMetadata } from "../types/HookMetadata";
4
- import { HOOK_METADATA_KEY, HOOK_REGISTRY_TOKEN } from "../types/tokens";
5
-
6
- export function registerHooksForInstance(instance: any): void {
7
- const constructor = instance.constructor;
8
- const hookMetadata: HookMetadata[] = constructor[HOOK_METADATA_KEY] || [];
9
-
10
- if (hookMetadata.length === 0) {
11
- return;
12
- }
13
-
14
- try {
15
- const hookRegistry = inject<IHookRegistry>(HOOK_REGISTRY_TOKEN);
16
-
17
- for (const { hookName, methodName } of hookMetadata) {
18
- const method = instance[methodName];
19
- if (typeof method === 'function') {
20
- hookRegistry.register(hookName, method.bind(instance));
21
- }
22
- }
23
- } catch (error) {
24
- console.warn('Failed to register hooks - HookRegistry may not be available yet:', error);
25
- }
26
- }
@@ -1,74 +0,0 @@
1
- import { inject } from '@kanian77/simple-di';
2
- import { ExampleService } from '../../../../example-plugin/services';
3
- import { Plugin } from '../../../../core';
4
- import { Hook } from '../../../../decorators';
5
- import type { IHookRegistry } from '../../../types';
6
- import { HOOK_REGISTRY_TOKEN } from '../../../types/tokens';
7
-
8
- export const PLUGIN_A_TOKEN = 'PLUGIN_A_TOKEN';
9
- export default class PluginA extends Plugin {
10
- readonly metadata = {
11
- name: 'pluginA',
12
- version: '1.0.0',
13
- description: 'An example plugin',
14
- dependencies: [], // other plugin names this depends on
15
- };
16
-
17
- constructor() {
18
- // Call parent Module constructor with plugin configuration
19
- super({
20
- providers: [
21
- {
22
- provide: PLUGIN_A_TOKEN,
23
- useClass: ExampleService,
24
- },
25
- ],
26
- });
27
- }
28
-
29
- override async onLoad(): Promise<void> {
30
- console.log('PluginA loading...');
31
- }
32
-
33
- override async onInit(): Promise<void> {
34
- console.log('PluginA initialized!');
35
-
36
- // Additional manual hook registration if needed
37
- this.registerAdditionalHooks();
38
- }
39
-
40
- override async onDestroy(): Promise<void> {
41
- console.log('PluginA destroyed!');
42
- }
43
-
44
- protected override registerCustomHooks(): void {
45
- console.log('Registering custom hooks for PluginA');
46
- }
47
-
48
- // These methods will be automatically registered as hook handlers
49
- @Hook('custom:example-event')
50
- private async handleExampleEvent(data: any): Promise<void> {
51
- console.log('Handling example event via decorator:', data);
52
- }
53
-
54
- @Hook('core:application-start')
55
- private async onApplicationStart(): Promise<void> {
56
- console.log('PluginA responding to application start via decorator');
57
- }
58
-
59
- @Hook('core:before-plugin-load')
60
- private async onBeforePluginLoad(pluginPath: string): Promise<void> {
61
- console.log('Another plugin is about to load:', pluginPath);
62
- }
63
-
64
- private registerAdditionalHooks(): void {
65
- const hookRegistry = inject<IHookRegistry>(HOOK_REGISTRY_TOKEN);
66
- hookRegistry.register(
67
- 'dynamic:custom-hook',
68
- this.handleDynamicHook.bind(this)
69
- );
70
- }
71
- private async handleDynamicHook(data: any): Promise<void> {
72
- console.log('Handling dynamic hook:', data);
73
- }
74
- }
@@ -1,74 +0,0 @@
1
- import { inject } from '@kanian77/simple-di';
2
- import { ExampleService } from '../../../../example-plugin/services';
3
- import { Plugin } from '../../../../core';
4
- import { Hook } from '../../../../decorators';
5
- import type { IHookRegistry } from '../../../types';
6
- import { HOOK_REGISTRY_TOKEN } from '../../../types/tokens';
7
-
8
- export const PLUGIN_B_TOKEN = 'PLUGIN_B_TOKEN';
9
- export default class PluginB extends Plugin {
10
- readonly metadata = {
11
- name: 'pluginB',
12
- version: '1.0.0',
13
- description: 'An example plugin',
14
- dependencies: [], // other plugin names this depends on
15
- };
16
-
17
- constructor() {
18
- // Call parent Module constructor with plugin configuration
19
- super({
20
- providers: [
21
- {
22
- provide: PLUGIN_B_TOKEN,
23
- useClass: ExampleService,
24
- },
25
- ],
26
- });
27
- }
28
-
29
- override async onLoad(): Promise<void> {
30
- console.log('PluginB loading...');
31
- }
32
-
33
- override async onInit(): Promise<void> {
34
- console.log('PluginB initialized!');
35
-
36
- // Additional manual hook registration if needed
37
- this.registerAdditionalHooks();
38
- }
39
-
40
- override async onDestroy(): Promise<void> {
41
- console.log('PluginB destroyed!');
42
- }
43
-
44
- protected override registerCustomHooks(): void {
45
- console.log('Registering custom hooks for PluginB');
46
- }
47
-
48
- // These methods will be automatically registered as hook handlers
49
- @Hook('custom:example-event')
50
- private async handleExampleEvent(data: any): Promise<void> {
51
- console.log('Handling example event via decorator:', data);
52
- }
53
-
54
- @Hook('core:application-start')
55
- private async onApplicationStart(): Promise<void> {
56
- console.log('PluginB responding to application start via decorator');
57
- }
58
-
59
- @Hook('core:before-plugin-load')
60
- private async onBeforePluginLoad(pluginPath: string): Promise<void> {
61
- console.log('Another plugin is about to load:', pluginPath);
62
- }
63
-
64
- private registerAdditionalHooks(): void {
65
- const hookRegistry = inject<IHookRegistry>(HOOK_REGISTRY_TOKEN);
66
- hookRegistry.register(
67
- 'dynamic:custom-hook',
68
- this.handleDynamicHook.bind(this)
69
- );
70
- }
71
- private async handleDynamicHook(data: any): Promise<void> {
72
- console.log('Handling dynamic hook:', data);
73
- }
74
- }
@@ -1,4 +0,0 @@
1
- export interface HookMetadata {
2
- hookName: string;
3
- methodName: string;
4
- }
@@ -1,10 +0,0 @@
1
- export type HookFn = (...args: any[]) => void | Promise<void>;
2
- export type HookMap = Map<string, HookFn[]>;
3
-
4
- export interface IHookRegistry {
5
- register(name: string, fn: HookFn): void;
6
- trigger(name: string, ...args: any[]): Promise<void>;
7
- unregister(name: string, fn?: HookFn): void;
8
- getHooks(name: string): HookFn[];
9
- clear(): void;
10
- }
@@ -1,8 +0,0 @@
1
- import type { LoadedPlugin } from './LoadedPlugin';
2
-
3
- export interface IPluginManager {
4
- initialize(pluginsDir: string): Promise<void>;
5
- shutdown(): Promise<void>;
6
- getPlugin(name: string): LoadedPlugin | undefined;
7
- getAllPlugins(): LoadedPlugin[];
8
- }
@@ -1,9 +0,0 @@
1
- import type { Module } from '@kanian77/simple-di';
2
-
3
- export interface PluginMetadata {
4
- name: string;
5
- version: string;
6
- description?: string;
7
- dependencies?: string[];
8
- }
9
-
@@ -1,3 +0,0 @@
1
- # Types Exports
2
-
3
- This folder contains all shared interfaces and types for the plugin system. Use `import { ... } from 'src/lib/types'` for type-safe imports.
File without changes
File without changes
File without changes
File without changes