@common-stack/server-core 8.0.2-alpha.0 → 8.2.1-alpha.0

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.
@@ -4,14 +4,10 @@ export interface IResolverOptions {
4
4
  logger?: CdmLogger.ILogger;
5
5
  [key: string]: any;
6
6
  }
7
- export declare enum ConfigurationScope {
8
- WINDOW = 1,
9
- RESOURCE = 2
10
- }
11
7
  export interface IWebsocketConfig {
12
8
  [key: string]: any;
13
9
  }
14
- export interface IPreferencesData<T = ConfigurationScope> {
10
+ export interface IPreferencesData<T = any> {
15
11
  type?: string | string[];
16
12
  default?: string | boolean | number | any;
17
13
  description?: string;
@@ -25,13 +21,13 @@ export interface IPreferencesData<T = ConfigurationScope> {
25
21
  };
26
22
  [key: string]: any;
27
23
  }
28
- export interface IPreferences<T = ConfigurationScope> {
24
+ export interface IPreferences<T = any> {
29
25
  [key: string]: IPreferencesData<T>;
30
26
  }
31
27
  /**
32
28
  * Formatted preferences data
33
29
  */
34
- export interface IPreferncesTransformed<T = ConfigurationScope> {
30
+ export interface IPreferncesTransformed<T = any> {
35
31
  type: string;
36
32
  data: IPreferencesData<T>;
37
33
  }
@@ -1,5 +1,5 @@
1
- import { ConfigurationScope, IPreferencesData } from "./connector";
2
- export interface IRoles<T = ConfigurationScope> {
1
+ import { IPreferencesData } from './connector';
2
+ export interface IRoles<T = any> {
3
3
  [key: string]: IPreferencesData<T>;
4
4
  }
5
5
  export interface IRoleUpdate<T> {
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @file integration-proxy-moleculer.test.ts
3
+ * @description Integration tests for full proxy → Moleculer → service cycle
4
+ * Tests parameter wrapping/unwrapping between proxy and Moleculer handler
5
+ */
6
+ export {};
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @file moleculerEventHandler.test.ts
3
+ * @description Test suite for Moleculer event handler decorator
4
+ */
5
+ export {};
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @file serviceGenerationUtils.test.ts
3
+ * @description Test suite for service generation utilities
4
+ */
5
+ export {};
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @file typedMoleculerService.test.ts
3
+ * @description Test suite for Moleculer service generation
4
+ */
5
+ export {};
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @file typedProxyService.test.ts
3
+ * @description Test suite for proxy service generation
4
+ */
5
+ export {};
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @file moleculer-generation/index.ts
3
+ * @description Auto-generation utilities for Moleculer services and proxy services
4
+ *
5
+ * This module provides utilities for auto-generating:
6
+ * - Server-side Moleculer service actions and events
7
+ * - Client-side proxy service methods
8
+ *
9
+ * All utilities ensure consistent naming conventions (camelCase) across
10
+ * the entire microservice architecture.
11
+ */
12
+ export * from './serviceGenerationUtils';
13
+ export * from './moleculerEventHandler';
14
+ export * from './typedMoleculerService';
15
+ export * from './typedProxyService';
16
+ export * from './zodToMoleculer';
@@ -0,0 +1,73 @@
1
+ /**
2
+ * @file moleculer-event-handler.ts
3
+ * @description Decorator for marking service methods as Moleculer event handlers
4
+ *
5
+ * This allows event handlers to be defined directly in the service class
6
+ * and automatically registered as Moleculer events.
7
+ */
8
+ import 'reflect-metadata';
9
+ /**
10
+ * Moleculer namespace containing event handler utilities
11
+ */
12
+ export declare namespace Moleculer {
13
+ /**
14
+ * Metadata key for storing event handler information
15
+ */
16
+ const EVENT_HANDLER_METADATA_KEY = "moleculer:eventHandler";
17
+ /**
18
+ * Event handler metadata interface
19
+ */
20
+ interface EventHandlerMetadata {
21
+ eventName: string;
22
+ methodName: string;
23
+ group?: string;
24
+ }
25
+ /**
26
+ * Decorator for marking a service method as a Moleculer event handler
27
+ *
28
+ * @param eventName - The event name to listen for
29
+ * @param options - Optional event configuration
30
+ *
31
+ * @example
32
+ * ```typescript
33
+ * class OrganizationService implements IOrganizationService {
34
+ * @Moleculer.EventHandler(UserBroadcasterAction.OnUserCreated)
35
+ * async onUserCreated(event: IUserCreationEvent): Promise<void> {
36
+ * await this.createDefaultOrganization(event.user);
37
+ * }
38
+ *
39
+ * @Moleculer.EventHandler(OrganizationServiceAction.OnOrganizationCreated, { group: 'org-setup' })
40
+ * async onOrganizationCreated(event: IOrganizationCreatedEvent): Promise<void> {
41
+ * // Handle organization creation
42
+ * }
43
+ * }
44
+ * ```
45
+ */
46
+ function EventHandler(eventName: string, options?: {
47
+ group?: string;
48
+ }): MethodDecorator;
49
+ /**
50
+ * Get all Moleculer event handlers defined on a service class
51
+ *
52
+ * @param serviceClassOrInstance - The service class constructor or instance
53
+ * @returns Array of event handler metadata
54
+ *
55
+ * @example
56
+ * ```typescript
57
+ * const handlers = Moleculer.getEventHandlers(OrganizationService);
58
+ * // Returns: [
59
+ * // { eventName: 'user.created', methodName: 'onUserCreated' },
60
+ * // { eventName: 'org.created', methodName: 'onOrganizationCreated' }
61
+ * // ]
62
+ * ```
63
+ */
64
+ function getEventHandlers(serviceClassOrInstance: (new (...args: unknown[]) => unknown) | object): EventHandlerMetadata[];
65
+ /**
66
+ * Check if a method is marked as a Moleculer event handler
67
+ *
68
+ * @param serviceClassOrInstance - The service class constructor or instance
69
+ * @param methodName - The method name to check
70
+ * @returns Event handler metadata if found, undefined otherwise
71
+ */
72
+ function isEventHandler(serviceClassOrInstance: (new (...args: unknown[]) => unknown) | object, methodName: string): EventHandlerMetadata | undefined;
73
+ }
@@ -0,0 +1,100 @@
1
+ /**
2
+ * @file serviceGenerationUtils.ts
3
+ * @description Shared utilities for auto-generating Moleculer services and proxy services.
4
+ *
5
+ * This module provides common functionality used by both:
6
+ * - typedMoleculerService.ts (server-side Moleculer service generation)
7
+ * - typedProxyService.ts (client-side proxy service generation)
8
+ *
9
+ * Centralizing these utilities ensures consistency in action naming conventions
10
+ * and method discovery across the entire microservice architecture.
11
+ */
12
+ /**
13
+ * Excluded base service methods that should not be auto-generated as actions
14
+ */
15
+ export type ExcludedServiceMethods = 'dispose' | 'get' | 'getAll' | 'bulkDelete' | 'delete' | 'count' | 'getByName' | 'getByIds' | 'getAllWithCount' | 'create' | 'update' | 'bulkCreate' | 'insert' | 'broker' | 'logger' | 'topic' | 'callAction';
16
+ /**
17
+ * Check if a method should be excluded from auto-generation
18
+ *
19
+ * @param methodName - The method name to check
20
+ * @param context - Generation context: 'moleculer' for server-side, 'proxy' for client-side
21
+ * @returns true if the method should be excluded
22
+ */
23
+ export declare function isExcludedMethod(methodName: string, context?: 'moleculer' | 'proxy'): boolean;
24
+ /**
25
+ * Get all method names from a service instance, traversing the prototype chain.
26
+ *
27
+ * This function walks up the prototype chain to include inherited methods from
28
+ * parent classes, which is essential for services that extend base classes.
29
+ *
30
+ * @param obj - The service instance to analyze
31
+ * @returns Array of method names (includes inherited methods)
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * class BaseService {
36
+ * get() {}
37
+ * getAll() {}
38
+ * }
39
+ *
40
+ * class UserService extends BaseService {
41
+ * createUser() {}
42
+ * }
43
+ *
44
+ * const service = new UserService();
45
+ * const methods = getAllMethodNames(service);
46
+ * // Returns: ['createUser', 'get', 'getAll', 'constructor']
47
+ * ```
48
+ */
49
+ export declare function getAllMethodNames(obj: unknown): string[];
50
+ /**
51
+ * Convert method name to action name using camelCase convention.
52
+ *
53
+ * **IMPORTANT**: We use camelCase (method name as-is) for action names to match
54
+ * the Moleculer service action registration pattern. Both server-side Moleculer
55
+ * services and client-side proxy services must use the same convention.
56
+ *
57
+ * @param methodName - The method name (e.g., 'getTags', 'createTag')
58
+ * @returns The action name in camelCase (same as method name)
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * getActionName('getTags') // Returns: 'getTags'
63
+ * getActionName('createTag') // Returns: 'createTag'
64
+ * getActionName('removeTag') // Returns: 'removeTag'
65
+ * ```
66
+ *
67
+ * @deprecated PascalCase conversion (e.g., GetTags, CreateTag) is no longer used.
68
+ * Previous behavior caused mismatches between proxy and Moleculer services.
69
+ */
70
+ export declare function getActionName(methodName: string): string;
71
+ /**
72
+ * Convert string to PascalCase (first letter uppercase).
73
+ *
74
+ * **DEPRECATED**: This function is kept for backward compatibility with command enums
75
+ * but should NOT be used for action name generation. Use getActionName() instead.
76
+ *
77
+ * @param str - The string to convert
78
+ * @returns String with first letter uppercase
79
+ *
80
+ * @example
81
+ * ```typescript
82
+ * toPascalCase('getTags') // Returns: 'GetTags'
83
+ * toPascalCase('createTag') // Returns: 'CreateTag'
84
+ * ```
85
+ */
86
+ export declare function toPascalCase(str: string): string;
87
+ /**
88
+ * Build the full Moleculer action path from topic and action name.
89
+ *
90
+ * @param topic - The Moleculer service topic (e.g., 'Tag', 'User')
91
+ * @param actionName - The action name (e.g., 'getTags', 'createTag')
92
+ * @returns Full action path (e.g., 'Tag.getTags', 'User.createUser')
93
+ *
94
+ * @example
95
+ * ```typescript
96
+ * buildActionPath('Tag', 'getTags') // Returns: 'Tag.getTags'
97
+ * buildActionPath('User', 'createUser') // Returns: 'User.createUser'
98
+ * ```
99
+ */
100
+ export declare function buildActionPath(topic: string, actionName: string): string;