@common-stack/store-mongo 7.2.1-alpha.31 → 7.2.1-alpha.32
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/lib/index.d.ts +0 -1
- package/lib/index.js +1 -1
- package/package.json +2 -2
- package/lib/moleculer-generation/index.d.ts +0 -15
- package/lib/moleculer-generation/moleculerEventHandler.d.ts +0 -73
- package/lib/moleculer-generation/moleculerEventHandler.js +0 -91
- package/lib/moleculer-generation/moleculerEventHandler.js.map +0 -1
- package/lib/moleculer-generation/serviceGenerationUtils.d.ts +0 -99
- package/lib/moleculer-generation/serviceGenerationUtils.js +0 -146
- package/lib/moleculer-generation/serviceGenerationUtils.js.map +0 -1
- package/lib/moleculer-generation/typedMoleculerService.d.ts +0 -491
- package/lib/moleculer-generation/typedMoleculerService.js +0 -656
- package/lib/moleculer-generation/typedMoleculerService.js.map +0 -1
- package/lib/moleculer-generation/typedProxyService.d.ts +0 -116
- package/lib/moleculer-generation/typedProxyService.js +0 -205
- package/lib/moleculer-generation/typedProxyService.js.map +0 -1
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{generateMongo}from'./helpers/mongoose-connection.js';export{BaseService2}from'./services/BaseService.js';export{BaseProxyService2}from'./services/BaseProxyService.js';export{BaseService}from'./services/base-service.js';export{BaseProxyService}from'./services/base-proxy-service.js';export{addIdVirtualFields2,commonModelSchemaOptions2}from'./store/models/common-options-v2.js';export{addIdVirtualFields,commonModeSchemaOptions}from'./store/models/common-options.js';export{BaseMongoRepository}from'./store/repositories/BaseMongoRepository.js';export{BaseRepository}from'./store/repositories/base-repository.js';export{BulkDataLoader2}from'./dataloaders/bulk-dataloader-v2.js';export{BulkDataLoader}from'./dataloaders/bulk-dataloader.js';export{BaseServiceMixin as BaseServiceMixin2}from'./mixins/BaseServiceMixin.js';export{BaseServiceMixin}from'./mixins/base-service-mixin.js';export{PAGINATION_OPTIONS}from'./interfaces/getAllArgs.js'
|
|
1
|
+
export{generateMongo}from'./helpers/mongoose-connection.js';export{BaseService2}from'./services/BaseService.js';export{BaseProxyService2}from'./services/BaseProxyService.js';export{BaseService}from'./services/base-service.js';export{BaseProxyService}from'./services/base-proxy-service.js';export{addIdVirtualFields2,commonModelSchemaOptions2}from'./store/models/common-options-v2.js';export{addIdVirtualFields,commonModeSchemaOptions}from'./store/models/common-options.js';export{BaseMongoRepository}from'./store/repositories/BaseMongoRepository.js';export{BaseRepository}from'./store/repositories/base-repository.js';export{BulkDataLoader2}from'./dataloaders/bulk-dataloader-v2.js';export{BulkDataLoader}from'./dataloaders/bulk-dataloader.js';export{BaseServiceMixin as BaseServiceMixin2}from'./mixins/BaseServiceMixin.js';export{BaseServiceMixin}from'./mixins/base-service-mixin.js';export{PAGINATION_OPTIONS}from'./interfaces/getAllArgs.js';//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@common-stack/store-mongo",
|
|
3
|
-
"version": "7.2.1-alpha.
|
|
3
|
+
"version": "7.2.1-alpha.32",
|
|
4
4
|
"description": "Sample core for higher packages to depend on",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "CDMBase LLC",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
]
|
|
59
59
|
}
|
|
60
60
|
},
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "6585d3213eab8f5db2bb43f8c15768b070404f21",
|
|
62
62
|
"typescript": {
|
|
63
63
|
"definition": "lib/index.d.ts"
|
|
64
64
|
}
|
|
@@ -1,15 +0,0 @@
|
|
|
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';
|
|
@@ -1,73 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -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":["// from package: store-mongo\n/* eslint-disable @typescript-eslint/no-namespace */\n/**\n * @file moleculer-event-handler.ts\n * @description Decorator for marking service methods as Moleculer event handlers\n * \n * This allows event handlers to be defined directly in the service class\n * and automatically registered as Moleculer events.\n */\n\nimport 'reflect-metadata';\n\n/**\n * Moleculer namespace containing event handler utilities\n */\nexport namespace Moleculer {\n /**\n * Metadata key for storing event handler information\n */\n export const EVENT_HANDLER_METADATA_KEY = 'moleculer:eventHandler';\n\n /**\n * Event handler metadata interface\n */\n export interface EventHandlerMetadata {\n eventName: string;\n methodName: string;\n group?: string;\n }\n\n /**\n * Decorator for marking a service method as a Moleculer event handler\n * \n * @param eventName - The event name to listen for\n * @param options - Optional event configuration\n * \n * @example\n * ```typescript\n * class OrganizationService implements IOrganizationService {\n * @Moleculer.EventHandler(UserBroadcasterAction.OnUserCreated)\n * async onUserCreated(event: IUserCreationEvent): Promise<void> {\n * await this.createDefaultOrganization(event.user);\n * }\n * \n * @Moleculer.EventHandler(OrganizationServiceAction.OnOrganizationCreated, { group: 'org-setup' })\n * async onOrganizationCreated(event: IOrganizationCreatedEvent): Promise<void> {\n * // Handle organization creation\n * }\n * }\n * ```\n */\n export function EventHandler(\n eventName: string,\n options?: { group?: string }\n ): MethodDecorator {\n return function moleculerEventHandlerDecorator(\n target: object,\n propertyKey: string | symbol,\n descriptor: PropertyDescriptor\n ): PropertyDescriptor {\n // Get existing event handlers for this class\n const existingHandlers: EventHandlerMetadata[] = \n Reflect.getMetadata(EVENT_HANDLER_METADATA_KEY, target.constructor) || [];\n \n // Add this handler to the list\n const metadata: EventHandlerMetadata = {\n eventName,\n methodName: propertyKey.toString(),\n group: options?.group,\n };\n \n existingHandlers.push(metadata);\n \n // Store the updated list\n Reflect.defineMetadata(EVENT_HANDLER_METADATA_KEY, existingHandlers, target.constructor);\n \n return descriptor;\n };\n }\n\n /**\n * Get all Moleculer event handlers defined on a service class\n * \n * @param serviceClassOrInstance - The service class constructor or instance\n * @returns Array of event handler metadata\n * \n * @example\n * ```typescript\n * const handlers = Moleculer.getEventHandlers(OrganizationService);\n * // Returns: [\n * // { eventName: 'user.created', methodName: 'onUserCreated' },\n * // { eventName: 'org.created', methodName: 'onOrganizationCreated' }\n * // ]\n * ```\n */\n export function getEventHandlers(\n serviceClassOrInstance: (new (...args: unknown[]) => unknown) | object\n ): EventHandlerMetadata[] {\n const target = typeof serviceClassOrInstance === 'function' \n ? serviceClassOrInstance \n : (serviceClassOrInstance as { constructor: new (...args: unknown[]) => unknown }).constructor;\n return Reflect.getMetadata(EVENT_HANDLER_METADATA_KEY, target) || [];\n }\n\n /**\n * Check if a method is marked as a Moleculer event handler\n * \n * @param serviceClassOrInstance - The service class constructor or instance\n * @param methodName - The method name to check\n * @returns Event handler metadata if found, undefined otherwise\n */\n export function isEventHandler(\n serviceClassOrInstance: (new (...args: unknown[]) => unknown) | object,\n methodName: string\n ): EventHandlerMetadata | undefined {\n const handlers = getEventHandlers(serviceClassOrInstance);\n return handlers.find(h => h.methodName === methodName);\n }\n}\n"],"names":[],"mappings":"yBAAA;AACA;AACA;;;;;;AAMG;AAIH;;AAEG;AACG,IAAW,UAuGhB;AAvGD,CAAA,UAAiB,SAAS,EAAA;AACtB;;AAEG;IACU,SAA0B,CAAA,0BAAA,GAAG,wBAAwB,CAAC;AAWnE;;;;;;;;;;;;;;;;;;;;AAoBG;AACH,IAAA,SAAgB,YAAY,CACxB,SAAiB,EACjB,OAA4B,EAAA;AAE5B,QAAA,OAAO,SAAS,8BAA8B,CAC1C,MAAc,EACd,WAA4B,EAC5B,UAA8B,EAAA;;AAG9B,YAAA,MAAM,gBAAgB,GAClB,OAAO,CAAC,WAAW,CAAC,SAAA,CAAA,0BAA0B,EAAE,MAAM,CAAC,WAA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ating 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
|
-
* @returns true if the method should be excluded
|
|
21
|
-
*/
|
|
22
|
-
export declare function isExcludedMethod(methodName: string): boolean;
|
|
23
|
-
/**
|
|
24
|
-
* Get all method names from a service instance, traversing the prototype chain.
|
|
25
|
-
*
|
|
26
|
-
* This function walks up the prototype chain to include inherited methods from
|
|
27
|
-
* parent classes, which is essential for services that extend base classes.
|
|
28
|
-
*
|
|
29
|
-
* @param obj - The service instance to analyze
|
|
30
|
-
* @returns Array of method names (includes inherited methods)
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* ```typescript
|
|
34
|
-
* class BaseService {
|
|
35
|
-
* get() {}
|
|
36
|
-
* getAll() {}
|
|
37
|
-
* }
|
|
38
|
-
*
|
|
39
|
-
* class UserService extends BaseService {
|
|
40
|
-
* createUser() {}
|
|
41
|
-
* }
|
|
42
|
-
*
|
|
43
|
-
* const service = new UserService();
|
|
44
|
-
* const methods = getAllMethodNames(service);
|
|
45
|
-
* // Returns: ['createUser', 'get', 'getAll', 'constructor']
|
|
46
|
-
* ```
|
|
47
|
-
*/
|
|
48
|
-
export declare function getAllMethodNames(obj: unknown): string[];
|
|
49
|
-
/**
|
|
50
|
-
* Convert method name to action name using camelCase convention.
|
|
51
|
-
*
|
|
52
|
-
* **IMPORTANT**: We use camelCase (method name as-is) for action names to match
|
|
53
|
-
* the Moleculer service action registration pattern. Both server-side Moleculer
|
|
54
|
-
* services and client-side proxy services must use the same convention.
|
|
55
|
-
*
|
|
56
|
-
* @param methodName - The method name (e.g., 'getTags', 'createTag')
|
|
57
|
-
* @returns The action name in camelCase (same as method name)
|
|
58
|
-
*
|
|
59
|
-
* @example
|
|
60
|
-
* ```typescript
|
|
61
|
-
* getActionName('getTags') // Returns: 'getTags'
|
|
62
|
-
* getActionName('createTag') // Returns: 'createTag'
|
|
63
|
-
* getActionName('removeTag') // Returns: 'removeTag'
|
|
64
|
-
* ```
|
|
65
|
-
*
|
|
66
|
-
* @deprecated PascalCase conversion (e.g., GetTags, CreateTag) is no longer used.
|
|
67
|
-
* Previous behavior caused mismatches between proxy and Moleculer services.
|
|
68
|
-
*/
|
|
69
|
-
export declare function getActionName(methodName: string): string;
|
|
70
|
-
/**
|
|
71
|
-
* Convert string to PascalCase (first letter uppercase).
|
|
72
|
-
*
|
|
73
|
-
* **DEPRECATED**: This function is kept for backward compatibility with command enums
|
|
74
|
-
* but should NOT be used for action name generation. Use getActionName() instead.
|
|
75
|
-
*
|
|
76
|
-
* @param str - The string to convert
|
|
77
|
-
* @returns String with first letter uppercase
|
|
78
|
-
*
|
|
79
|
-
* @example
|
|
80
|
-
* ```typescript
|
|
81
|
-
* toPascalCase('getTags') // Returns: 'GetTags'
|
|
82
|
-
* toPascalCase('createTag') // Returns: 'CreateTag'
|
|
83
|
-
* ```
|
|
84
|
-
*/
|
|
85
|
-
export declare function toPascalCase(str: string): string;
|
|
86
|
-
/**
|
|
87
|
-
* Build the full Moleculer action path from topic and action name.
|
|
88
|
-
*
|
|
89
|
-
* @param topic - The Moleculer service topic (e.g., 'Tag', 'User')
|
|
90
|
-
* @param actionName - The action name (e.g., 'getTags', 'createTag')
|
|
91
|
-
* @returns Full action path (e.g., 'Tag.getTags', 'User.createUser')
|
|
92
|
-
*
|
|
93
|
-
* @example
|
|
94
|
-
* ```typescript
|
|
95
|
-
* buildActionPath('Tag', 'getTags') // Returns: 'Tag.getTags'
|
|
96
|
-
* buildActionPath('User', 'createUser') // Returns: 'User.createUser'
|
|
97
|
-
* ```
|
|
98
|
-
*/
|
|
99
|
-
export declare function buildActionPath(topic: string, actionName: string): string;
|
|
@@ -1,146 +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
|
-
* Check if a method should be excluded from auto-generation
|
|
14
|
-
*
|
|
15
|
-
* @param methodName - The method name to check
|
|
16
|
-
* @returns true if the method should be excluded
|
|
17
|
-
*/
|
|
18
|
-
function isExcludedMethod(methodName) {
|
|
19
|
-
const excludedMethods = [
|
|
20
|
-
'dispose',
|
|
21
|
-
'get',
|
|
22
|
-
'getAll',
|
|
23
|
-
'bulkDelete',
|
|
24
|
-
'delete',
|
|
25
|
-
'count',
|
|
26
|
-
'getByName',
|
|
27
|
-
'getByIds',
|
|
28
|
-
'getAllWithCount',
|
|
29
|
-
'create',
|
|
30
|
-
'update',
|
|
31
|
-
'bulkCreate',
|
|
32
|
-
'insert',
|
|
33
|
-
'broker',
|
|
34
|
-
'logger',
|
|
35
|
-
'topic',
|
|
36
|
-
'callAction',
|
|
37
|
-
];
|
|
38
|
-
return excludedMethods.includes(methodName);
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Get all method names from a service instance, traversing the prototype chain.
|
|
42
|
-
*
|
|
43
|
-
* This function walks up the prototype chain to include inherited methods from
|
|
44
|
-
* parent classes, which is essential for services that extend base classes.
|
|
45
|
-
*
|
|
46
|
-
* @param obj - The service instance to analyze
|
|
47
|
-
* @returns Array of method names (includes inherited methods)
|
|
48
|
-
*
|
|
49
|
-
* @example
|
|
50
|
-
* ```typescript
|
|
51
|
-
* class BaseService {
|
|
52
|
-
* get() {}
|
|
53
|
-
* getAll() {}
|
|
54
|
-
* }
|
|
55
|
-
*
|
|
56
|
-
* class UserService extends BaseService {
|
|
57
|
-
* createUser() {}
|
|
58
|
-
* }
|
|
59
|
-
*
|
|
60
|
-
* const service = new UserService();
|
|
61
|
-
* const methods = getAllMethodNames(service);
|
|
62
|
-
* // Returns: ['createUser', 'get', 'getAll', 'constructor']
|
|
63
|
-
* ```
|
|
64
|
-
*/
|
|
65
|
-
function getAllMethodNames(obj) {
|
|
66
|
-
const methods = new Set();
|
|
67
|
-
let current = obj;
|
|
68
|
-
// Traverse prototype chain
|
|
69
|
-
while (current && current !== Object.prototype) {
|
|
70
|
-
const props = Object.getOwnPropertyNames(current);
|
|
71
|
-
for (const prop of props) {
|
|
72
|
-
if (prop !== 'constructor') {
|
|
73
|
-
try {
|
|
74
|
-
const descriptor = Object.getOwnPropertyDescriptor(current, prop);
|
|
75
|
-
if (descriptor && typeof descriptor.value === 'function') {
|
|
76
|
-
methods.add(prop);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
catch (error) {
|
|
80
|
-
// Skip properties that can't be accessed
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
current = Object.getPrototypeOf(current);
|
|
85
|
-
}
|
|
86
|
-
return Array.from(methods);
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Convert method name to action name using camelCase convention.
|
|
90
|
-
*
|
|
91
|
-
* **IMPORTANT**: We use camelCase (method name as-is) for action names to match
|
|
92
|
-
* the Moleculer service action registration pattern. Both server-side Moleculer
|
|
93
|
-
* services and client-side proxy services must use the same convention.
|
|
94
|
-
*
|
|
95
|
-
* @param methodName - The method name (e.g., 'getTags', 'createTag')
|
|
96
|
-
* @returns The action name in camelCase (same as method name)
|
|
97
|
-
*
|
|
98
|
-
* @example
|
|
99
|
-
* ```typescript
|
|
100
|
-
* getActionName('getTags') // Returns: 'getTags'
|
|
101
|
-
* getActionName('createTag') // Returns: 'createTag'
|
|
102
|
-
* getActionName('removeTag') // Returns: 'removeTag'
|
|
103
|
-
* ```
|
|
104
|
-
*
|
|
105
|
-
* @deprecated PascalCase conversion (e.g., GetTags, CreateTag) is no longer used.
|
|
106
|
-
* Previous behavior caused mismatches between proxy and Moleculer services.
|
|
107
|
-
*/
|
|
108
|
-
function getActionName(methodName) {
|
|
109
|
-
// Use method name as-is (camelCase) for action names
|
|
110
|
-
// This ensures proxy services and Moleculer services use the same action keys
|
|
111
|
-
return methodName;
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Convert string to PascalCase (first letter uppercase).
|
|
115
|
-
*
|
|
116
|
-
* **DEPRECATED**: This function is kept for backward compatibility with command enums
|
|
117
|
-
* but should NOT be used for action name generation. Use getActionName() instead.
|
|
118
|
-
*
|
|
119
|
-
* @param str - The string to convert
|
|
120
|
-
* @returns String with first letter uppercase
|
|
121
|
-
*
|
|
122
|
-
* @example
|
|
123
|
-
* ```typescript
|
|
124
|
-
* toPascalCase('getTags') // Returns: 'GetTags'
|
|
125
|
-
* toPascalCase('createTag') // Returns: 'CreateTag'
|
|
126
|
-
* ```
|
|
127
|
-
*/
|
|
128
|
-
function toPascalCase(str) {
|
|
129
|
-
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Build the full Moleculer action path from topic and action name.
|
|
133
|
-
*
|
|
134
|
-
* @param topic - The Moleculer service topic (e.g., 'Tag', 'User')
|
|
135
|
-
* @param actionName - The action name (e.g., 'getTags', 'createTag')
|
|
136
|
-
* @returns Full action path (e.g., 'Tag.getTags', 'User.createUser')
|
|
137
|
-
*
|
|
138
|
-
* @example
|
|
139
|
-
* ```typescript
|
|
140
|
-
* buildActionPath('Tag', 'getTags') // Returns: 'Tag.getTags'
|
|
141
|
-
* buildActionPath('User', 'createUser') // Returns: 'User.createUser'
|
|
142
|
-
* ```
|
|
143
|
-
*/
|
|
144
|
-
function buildActionPath(topic, actionName) {
|
|
145
|
-
return `${topic}.${actionName}`;
|
|
146
|
-
}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":["/**\n * @file serviceGenerationUtils.ts\n * @description Shared utilities for auto-generating Moleculer services and proxy services.\n * \n * This module provides common functionality used by both:\n * - typedMoleculerService.ts (server-side Moleculer service generation)\n * - typedProxyService.ts (client-side proxy service generation)\n * \n * Centralizing these utilities ensures consistency in action naming conventions\n * and method discovery across the entire microservice architecture.\n */\n\n/**\n * Excluded base service methods that should not be auto-generated as actions\n */\nexport type ExcludedServiceMethods =\n | 'dispose'\n | 'get'\n | 'getAll'\n | 'bulkDelete'\n | 'delete'\n | 'count'\n | 'getByName'\n | 'getByIds'\n | 'getAllWithCount'\n | 'create'\n | 'update'\n | 'bulkCreate'\n | 'insert'\n | 'broker'\n | 'logger'\n | 'topic'\n | 'callAction';\n\n/**\n * Check if a method should be excluded from auto-generation\n * \n * @param methodName - The method name to check\n * @returns true if the method should be excluded\n */\nexport function isExcludedMethod(methodName: string): boolean {\n const excludedMethods: ExcludedServiceMethods[] = [\n 'dispose',\n 'get',\n 'getAll',\n 'bulkDelete',\n 'delete',\n 'count',\n 'getByName',\n 'getByIds',\n 'getAllWithCount',\n 'create',\n 'update',\n 'bulkCreate',\n 'insert',\n 'broker',\n 'logger',\n 'topic',\n 'callAction',\n ];\n\n return excludedMethods.includes(methodName as ExcludedServiceMethods);\n}\n\n/**\n * Get all method names from a service instance, traversing the prototype chain.\n * \n * This function walks up the prototype chain to include inherited methods from\n * parent classes, which is essential for services that extend base classes.\n * \n * @param obj - The service instance to analyze\n * @returns Array of method names (includes inherited methods)\n * \n * @example\n * ```typescript\n * class BaseService {\n * get() {}\n * getAll() {}\n * }\n * \n * class UserService extends BaseService {\n * createUser() {}\n * }\n * \n * const service = new UserService();\n * const methods = getAllMethodNames(service);\n * // Returns: ['createUser', 'get', 'getAll', 'constructor']\n * ```\n */\nexport function getAllMethodNames(obj: unknown): string[] {\n const methods = new Set<string>();\n let current = obj;\n\n // Traverse prototype chain\n while (current && current !== Object.prototype) {\n const props = Object.getOwnPropertyNames(current);\n for (const prop of props) {\n if (prop !== 'constructor') {\n try {\n const descriptor = Object.getOwnPropertyDescriptor(current, prop);\n if (descriptor && typeof descriptor.value === 'function') {\n methods.add(prop);\n }\n } catch (error) {\n // Skip properties that can't be accessed\n }\n }\n }\n current = Object.getPrototypeOf(current);\n }\n\n return Array.from(methods);\n}\n\n/**\n * Convert method name to action name using camelCase convention.\n * \n * **IMPORTANT**: We use camelCase (method name as-is) for action names to match\n * the Moleculer service action registration pattern. Both server-side Moleculer\n * services and client-side proxy services must use the same convention.\n * \n * @param methodName - The method name (e.g., 'getTags', 'createTag')\n * @returns The action name in camelCase (same as method name)\n * \n * @example\n * ```typescript\n * getActionName('getTags') // Returns: 'getTags'\n * getActionName('createTag') // Returns: 'createTag'\n * getActionName('removeTag') // Returns: 'removeTag'\n * ```\n * \n * @deprecated PascalCase conversion (e.g., GetTags, CreateTag) is no longer used.\n * Previous behavior caused mismatches between proxy and Moleculer services.\n */\nexport function getActionName(methodName: string): string {\n // Use method name as-is (camelCase) for action names\n // This ensures proxy services and Moleculer services use the same action keys\n return methodName;\n}\n\n/**\n * Convert string to PascalCase (first letter uppercase).\n * \n * **DEPRECATED**: This function is kept for backward compatibility with command enums\n * but should NOT be used for action name generation. Use getActionName() instead.\n * \n * @param str - The string to convert\n * @returns String with first letter uppercase\n * \n * @example\n * ```typescript\n * toPascalCase('getTags') // Returns: 'GetTags'\n * toPascalCase('createTag') // Returns: 'CreateTag'\n * ```\n */\nexport function toPascalCase(str: string): string {\n return str.charAt(0).toUpperCase() + str.slice(1);\n}\n\n/**\n * Build the full Moleculer action path from topic and action name.\n * \n * @param topic - The Moleculer service topic (e.g., 'Tag', 'User')\n * @param actionName - The action name (e.g., 'getTags', 'createTag')\n * @returns Full action path (e.g., 'Tag.getTags', 'User.createUser')\n * \n * @example\n * ```typescript\n * buildActionPath('Tag', 'getTags') // Returns: 'Tag.getTags'\n * buildActionPath('User', 'createUser') // Returns: 'User.createUser'\n * ```\n */\nexport function buildActionPath(topic: string, actionName: string): string {\n return `${topic}.${actionName}`;\n}\n"],"names":[],"mappings":"AAAA;;;;;;;;;;AAUG;AAwBH;;;;;AAKG;AACG,SAAU,gBAAgB,CAAC,UAAkB,EAAA;AAC/C,IAAA,MAAM,eAAe,GAA6B;QAC9C,SAAS;QACT,KAAK;QACL,QAAQ;QACR,YAAY;QACZ,QAAQ;QACR,OAAO;QACP,WAAW;QACX,UAAU;QACV,iBAAiB;QACjB,QAAQ;QACR,QAAQ;QACR,YAAY;QACZ,QAAQ;QACR,QAAQ;QACR,QAAQ;QACR,OAAO;QACP,YAAY;KACf,CAAC;AAEF,IAAA,OAAO,eAAe,CAAC,QAAQ,CAAC,UAAoC,CAAC,CAAC;AAC1E,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;AAwBG;AACG,SAAU,iBAAiB,CAAC,GAAY,EAAA;AAC1C,IAAA,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;IAClC,IAAI,OAAO,GAAG,GAAG,CAAC;;IAGlB,OAAO,OAAO,IAAI,OAAO,KAAK,MAAM,CAAC,SAAS,EAAE;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