@common-stack/server-core 7.2.1-alpha.49 → 7.2.1-alpha.50

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.
@@ -1,91 +0,0 @@
1
- import'reflect-metadata';// from package: store-mongo
2
- /* eslint-disable @typescript-eslint/no-namespace */
3
- /**
4
- * @file moleculer-event-handler.ts
5
- * @description Decorator for marking service methods as Moleculer event handlers
6
- *
7
- * This allows event handlers to be defined directly in the service class
8
- * and automatically registered as Moleculer events.
9
- */
10
- /**
11
- * Moleculer namespace containing event handler utilities
12
- */
13
- var Moleculer;
14
- (function (Moleculer) {
15
- /**
16
- * Metadata key for storing event handler information
17
- */
18
- Moleculer.EVENT_HANDLER_METADATA_KEY = 'moleculer:eventHandler';
19
- /**
20
- * Decorator for marking a service method as a Moleculer event handler
21
- *
22
- * @param eventName - The event name to listen for
23
- * @param options - Optional event configuration
24
- *
25
- * @example
26
- * ```typescript
27
- * class OrganizationService implements IOrganizationService {
28
- * @Moleculer.EventHandler(UserBroadcasterAction.OnUserCreated)
29
- * async onUserCreated(event: IUserCreationEvent): Promise<void> {
30
- * await this.createDefaultOrganization(event.user);
31
- * }
32
- *
33
- * @Moleculer.EventHandler(OrganizationServiceAction.OnOrganizationCreated, { group: 'org-setup' })
34
- * async onOrganizationCreated(event: IOrganizationCreatedEvent): Promise<void> {
35
- * // Handle organization creation
36
- * }
37
- * }
38
- * ```
39
- */
40
- function EventHandler(eventName, options) {
41
- return function moleculerEventHandlerDecorator(target, propertyKey, descriptor) {
42
- // Get existing event handlers for this class
43
- const existingHandlers = Reflect.getMetadata(Moleculer.EVENT_HANDLER_METADATA_KEY, target.constructor) || [];
44
- // Add this handler to the list
45
- const metadata = {
46
- eventName,
47
- methodName: propertyKey.toString(),
48
- group: options?.group,
49
- };
50
- existingHandlers.push(metadata);
51
- // Store the updated list
52
- Reflect.defineMetadata(Moleculer.EVENT_HANDLER_METADATA_KEY, existingHandlers, target.constructor);
53
- return descriptor;
54
- };
55
- }
56
- Moleculer.EventHandler = EventHandler;
57
- /**
58
- * Get all Moleculer event handlers defined on a service class
59
- *
60
- * @param serviceClassOrInstance - The service class constructor or instance
61
- * @returns Array of event handler metadata
62
- *
63
- * @example
64
- * ```typescript
65
- * const handlers = Moleculer.getEventHandlers(OrganizationService);
66
- * // Returns: [
67
- * // { eventName: 'user.created', methodName: 'onUserCreated' },
68
- * // { eventName: 'org.created', methodName: 'onOrganizationCreated' }
69
- * // ]
70
- * ```
71
- */
72
- function getEventHandlers(serviceClassOrInstance) {
73
- const target = typeof serviceClassOrInstance === 'function'
74
- ? serviceClassOrInstance
75
- : serviceClassOrInstance.constructor;
76
- return Reflect.getMetadata(Moleculer.EVENT_HANDLER_METADATA_KEY, target) || [];
77
- }
78
- Moleculer.getEventHandlers = getEventHandlers;
79
- /**
80
- * Check if a method is marked as a Moleculer event handler
81
- *
82
- * @param serviceClassOrInstance - The service class constructor or instance
83
- * @param methodName - The method name to check
84
- * @returns Event handler metadata if found, undefined otherwise
85
- */
86
- function isEventHandler(serviceClassOrInstance, methodName) {
87
- const handlers = getEventHandlers(serviceClassOrInstance);
88
- return handlers.find((h) => h.methodName === methodName);
89
- }
90
- Moleculer.isEventHandler = isEventHandler;
91
- })(Moleculer || (Moleculer = {}));export{Moleculer};//# sourceMappingURL=moleculerEventHandler.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"moleculerEventHandler.js","sources":["../../src/moleculer-generation/moleculerEventHandler.ts"],"sourcesContent":[null],"names":[],"mappings":"yBAAA;AACA;AACA;;;;;;AAMG;AAIH;;AAEG;AACG,IAAW,UAqGhB;AArGD,CAAA,UAAiB,SAAS,EAAA;AACtB;;AAEG;IACU,SAA0B,CAAA,0BAAA,GAAG,wBAAwB,CAAC;AAWnE;;;;;;;;;;;;;;;;;;;;AAoBG;AACH,IAAA,SAAgB,YAAY,CAAC,SAAiB,EAAE,OAA4B,EAAA;AACxE,QAAA,OAAO,SAAS,8BAA8B,CAC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S,KAAT,SAAS,GAqGzB,EAAA,CAAA,CAAA"}
@@ -1,156 +0,0 @@
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
- * Base CRUD methods from IBaseService that are inherited on server side
14
- * but need to be generated as remote calls on proxy/client side
15
- */
16
- const BASE_CRUD_METHODS = new Set([
17
- 'get',
18
- 'getAll',
19
- 'getAllWithCount',
20
- 'count',
21
- 'create',
22
- 'update',
23
- 'delete',
24
- 'bulkCreate',
25
- 'bulkDelete',
26
- 'getByName',
27
- 'getByIds',
28
- 'insert',
29
- ]);
30
- /**
31
- * Check if a method should be excluded from auto-generation
32
- *
33
- * @param methodName - The method name to check
34
- * @param context - Generation context: 'moleculer' for server-side, 'proxy' for client-side
35
- * @returns true if the method should be excluded
36
- */
37
- function isExcludedMethod(methodName, context = 'moleculer') {
38
- // Always exclude these utility/infrastructure methods regardless of context
39
- const alwaysExcluded = ['dispose', 'broker', 'logger', 'topic', 'callAction'];
40
- if (alwaysExcluded.includes(methodName)) {
41
- return true;
42
- }
43
- // For Moleculer services: exclude base CRUD methods (they're inherited from BaseService2)
44
- // For Proxy services: DON'T exclude them (they need to be generated as remote calls)
45
- if (context === 'moleculer' && BASE_CRUD_METHODS.has(methodName)) {
46
- return true;
47
- }
48
- return false;
49
- }
50
- /**
51
- * Get all method names from a service instance, traversing the prototype chain.
52
- *
53
- * This function walks up the prototype chain to include inherited methods from
54
- * parent classes, which is essential for services that extend base classes.
55
- *
56
- * @param obj - The service instance to analyze
57
- * @returns Array of method names (includes inherited methods)
58
- *
59
- * @example
60
- * ```typescript
61
- * class BaseService {
62
- * get() {}
63
- * getAll() {}
64
- * }
65
- *
66
- * class UserService extends BaseService {
67
- * createUser() {}
68
- * }
69
- *
70
- * const service = new UserService();
71
- * const methods = getAllMethodNames(service);
72
- * // Returns: ['createUser', 'get', 'getAll', 'constructor']
73
- * ```
74
- */
75
- function getAllMethodNames(obj) {
76
- const methods = new Set();
77
- let current = obj;
78
- // Traverse prototype chain
79
- while (current && current !== Object.prototype) {
80
- const props = Object.getOwnPropertyNames(current);
81
- for (const prop of props) {
82
- if (prop !== 'constructor') {
83
- try {
84
- const descriptor = Object.getOwnPropertyDescriptor(current, prop);
85
- if (descriptor && typeof descriptor.value === 'function') {
86
- methods.add(prop);
87
- }
88
- }
89
- catch (error) {
90
- // Skip properties that can't be accessed
91
- }
92
- }
93
- }
94
- current = Object.getPrototypeOf(current);
95
- }
96
- return Array.from(methods);
97
- }
98
- /**
99
- * Convert method name to action name using camelCase convention.
100
- *
101
- * **IMPORTANT**: We use camelCase (method name as-is) for action names to match
102
- * the Moleculer service action registration pattern. Both server-side Moleculer
103
- * services and client-side proxy services must use the same convention.
104
- *
105
- * @param methodName - The method name (e.g., 'getTags', 'createTag')
106
- * @returns The action name in camelCase (same as method name)
107
- *
108
- * @example
109
- * ```typescript
110
- * getActionName('getTags') // Returns: 'getTags'
111
- * getActionName('createTag') // Returns: 'createTag'
112
- * getActionName('removeTag') // Returns: 'removeTag'
113
- * ```
114
- *
115
- * @deprecated PascalCase conversion (e.g., GetTags, CreateTag) is no longer used.
116
- * Previous behavior caused mismatches between proxy and Moleculer services.
117
- */
118
- function getActionName(methodName) {
119
- // Use method name as-is (camelCase) for action names
120
- // This ensures proxy services and Moleculer services use the same action keys
121
- return methodName;
122
- }
123
- /**
124
- * Convert string to PascalCase (first letter uppercase).
125
- *
126
- * **DEPRECATED**: This function is kept for backward compatibility with command enums
127
- * but should NOT be used for action name generation. Use getActionName() instead.
128
- *
129
- * @param str - The string to convert
130
- * @returns String with first letter uppercase
131
- *
132
- * @example
133
- * ```typescript
134
- * toPascalCase('getTags') // Returns: 'GetTags'
135
- * toPascalCase('createTag') // Returns: 'CreateTag'
136
- * ```
137
- */
138
- function toPascalCase(str) {
139
- return str.charAt(0).toUpperCase() + str.slice(1);
140
- }
141
- /**
142
- * Build the full Moleculer action path from topic and action name.
143
- *
144
- * @param topic - The Moleculer service topic (e.g., 'Tag', 'User')
145
- * @param actionName - The action name (e.g., 'getTags', 'createTag')
146
- * @returns Full action path (e.g., 'Tag.getTags', 'User.createUser')
147
- *
148
- * @example
149
- * ```typescript
150
- * buildActionPath('Tag', 'getTags') // Returns: 'Tag.getTags'
151
- * buildActionPath('User', 'createUser') // Returns: 'User.createUser'
152
- * ```
153
- */
154
- function buildActionPath(topic, actionName) {
155
- return `${topic}.${actionName}`;
156
- }export{buildActionPath,getActionName,getAllMethodNames,isExcludedMethod,toPascalCase};//# sourceMappingURL=serviceGenerationUtils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"serviceGenerationUtils.js","sources":["../../src/moleculer-generation/serviceGenerationUtils.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAA;;;;;;;;;;AAUG;AAwBH;;;AAGG;AACH,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC;IAC9B,KAAK;IACL,QAAQ;IACR,iBAAiB;IACjB,OAAO;IACP,QAAQ;IACR,QAAQ;IACR,QAAQ;IACR,YAAY;IACZ,YAAY;IACZ,WAAW;IACX,UAAU;IACV,QAAQ;AACX,CAAA,CAAC,CAAC;AAEH;;;;;;AAMG;SACa,gBAAgB,CAAC,UAAkB,EAAE,UAAiC,WAAW,EAAA;;AAE7F,IAAA,MAAM,cAAc,GAAG,CAAC,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;AAC9E,IAAA,IAAI,cAAc,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE;AACrC,QAAA,OAAO,IAAI,CAAC;KACf;;;IAID,IAAI,OAAO,KAAK,WAAW,IAAI,iBAAiB,CAAC,GAAG,CAAC,UAAU,CAAC,EA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