@common-stack/server-core 7.2.1-alpha.47 → 7.2.1-alpha.49
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/__tests__/connector-inngest-arrays.test.d.ts +1 -0
- package/lib/connector/__tests__/container-connector.test.d.ts +2 -0
- package/lib/connector/__tests__/context-connector.test.d.ts +1 -0
- package/lib/connector/__tests__/fixtures/preferenfces/sample-settings.d.ts +98 -0
- package/lib/connector/__tests__/fixtures/sample-roles-permissions/account-api/permission-contribution.d.ts +90 -0
- package/lib/connector/__tests__/graphql-middleware.test.d.ts +1 -0
- package/lib/connector/__tests__/permissions.test.d.ts +1 -0
- package/lib/connector/__tests__/policies.test.d.ts +1 -0
- package/lib/connector/__tests__/preferences.test.d.ts +1 -0
- package/lib/connector/__tests__/roles-update-connector.test.d.ts +1 -0
- package/lib/connector/__tests__/rules-connector.test.d.ts +1 -0
- package/lib/connector/__tests__/samples/graphql/types/person_entity_type.d.ts +2 -0
- package/lib/connector/__tests__/samples/graphql/types/person_search_type.d.ts +2 -0
- package/lib/connector/__tests__/samples/graphql/types/vendor_type.d.ts +2 -0
- package/lib/connector/__tests__/schema-connector.test.d.ts +1 -0
- package/lib/connector/__tests__/service-connector.test.d.ts +2 -0
- package/lib/connector/__tests__/websocket-connector.test.d.ts +1 -0
- package/lib/connector/connector.d.ts +619 -0
- package/lib/connector/connector.js +470 -0
- package/lib/connector/connector.js.map +1 -0
- package/lib/connector/index.d.ts +1 -0
- package/lib/constants/directives.d.ts +1 -0
- package/lib/constants/directives.js +1 -0
- package/lib/constants/directives.js.map +1 -0
- package/lib/constants/index.d.ts +2 -0
- package/lib/constants/types.d.ts +8 -0
- package/lib/constants/types.js +8 -0
- package/lib/constants/types.js.map +1 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -0
- package/lib/interfaces/connector.d.ts +36 -0
- package/lib/interfaces/datasource.d.ts +14 -0
- package/lib/interfaces/index.d.ts +7 -0
- package/lib/interfaces/mongo-migration.d.ts +17 -0
- package/lib/interfaces/permissions.d.ts +5 -0
- package/lib/interfaces/policies.d.ts +5 -0
- package/lib/interfaces/roles.d.ts +8 -0
- package/lib/interfaces/rules.d.ts +12 -0
- package/lib/interfaces/rules.js +6 -0
- package/lib/interfaces/rules.js.map +1 -0
- package/lib/interfaces/store.d.ts +3 -0
- package/lib/logger/index.d.ts +1 -0
- package/lib/logger/logger.d.ts +2 -0
- package/lib/logger/logger.js +5 -0
- package/lib/logger/logger.js.map +1 -0
- package/lib/moleculer-generation/__tests__/integration-proxy-moleculer.test.d.ts +6 -0
- package/lib/moleculer-generation/__tests__/moleculerEventHandler.test.d.ts +5 -0
- package/lib/moleculer-generation/__tests__/serviceGenerationUtils.test.d.ts +5 -0
- package/lib/moleculer-generation/__tests__/typedMoleculerService.test.d.ts +5 -0
- package/lib/moleculer-generation/__tests__/typedProxyService.test.d.ts +5 -0
- package/lib/moleculer-generation/generateAllServiceSchemas.cjs +628 -0
- package/lib/moleculer-generation/index.d.ts +16 -0
- package/lib/moleculer-generation/moleculerEventHandler.d.ts +73 -0
- package/lib/moleculer-generation/moleculerEventHandler.js +91 -0
- package/lib/moleculer-generation/moleculerEventHandler.js.map +1 -0
- package/lib/moleculer-generation/serviceGenerationUtils.d.ts +100 -0
- package/lib/moleculer-generation/serviceGenerationUtils.js +156 -0
- package/lib/moleculer-generation/serviceGenerationUtils.js.map +1 -0
- package/lib/moleculer-generation/typedMoleculerService.d.ts +502 -0
- package/lib/moleculer-generation/typedMoleculerService.js +685 -0
- package/lib/moleculer-generation/typedMoleculerService.js.map +1 -0
- package/lib/moleculer-generation/typedProxyService.d.ts +119 -0
- package/lib/moleculer-generation/typedProxyService.js +226 -0
- package/lib/moleculer-generation/typedProxyService.js.map +1 -0
- package/lib/moleculer-generation/zodToMoleculer.d.ts +45 -0
- package/lib/moleculer-generation/zodToMoleculer.js +120 -0
- package/lib/moleculer-generation/zodToMoleculer.js.map +1 -0
- package/lib/utils/extract-tenant-id.d.ts +1 -0
- package/lib/utils/extract-tenant-id.js +4 -0
- package/lib/utils/extract-tenant-id.js.map +1 -0
- package/lib/utils/generate-query-cache-key.d.ts +11 -0
- package/lib/utils/generate-query-cache-key.js +13 -0
- package/lib/utils/generate-query-cache-key.js.map +1 -0
- package/lib/utils/get-directive-args-from-schema.d.ts +13 -0
- package/lib/utils/get-directive-args-from-schema.js +25 -0
- package/lib/utils/get-directive-args-from-schema.js.map +1 -0
- package/lib/utils/index.d.ts +4 -0
- package/lib/utils/preferences.d.ts +87 -0
- package/lib/utils/preferences.js +40 -0
- package/lib/utils/preferences.js.map +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,502 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file typed-moleculer-service.ts
|
|
3
|
+
* @description Provides type-safe base class for Moleculer services with ENFORCED
|
|
4
|
+
* compile-time verification AND automatic action generation from service methods.
|
|
5
|
+
*/
|
|
6
|
+
import type { ServiceSchema } from 'moleculer';
|
|
7
|
+
import { type ExcludedServiceMethods } from './serviceGenerationUtils';
|
|
8
|
+
/**
|
|
9
|
+
* Exclude base service CRUD methods and lifecycle methods
|
|
10
|
+
* @deprecated Use ExcludedServiceMethods from serviceGenerationUtils instead
|
|
11
|
+
*/
|
|
12
|
+
type ExcludedMethods = ExcludedServiceMethods;
|
|
13
|
+
/**
|
|
14
|
+
* Extract all method names from a service interface (excluding base methods)
|
|
15
|
+
*/
|
|
16
|
+
export type ServiceMethods<T> = {
|
|
17
|
+
[K in keyof T]: T[K] extends Function ? (K extends ExcludedMethods ? never : K) : never;
|
|
18
|
+
}[keyof T];
|
|
19
|
+
/**
|
|
20
|
+
* Required actions type - forces all service methods to have actions
|
|
21
|
+
*/
|
|
22
|
+
export type RequiredServiceActions<TService> = {
|
|
23
|
+
[K in ServiceMethods<TService>]: {
|
|
24
|
+
params?: Record<string, unknown>;
|
|
25
|
+
handler: (...args: unknown[]) => unknown;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Service schema with REQUIRED typed actions - TypeScript will error if any are missing
|
|
30
|
+
*/
|
|
31
|
+
export interface EnforcedServiceSchema<TService> extends Omit<ServiceSchema, 'actions'> {
|
|
32
|
+
name: string;
|
|
33
|
+
actions: RequiredServiceActions<TService> & Record<string, unknown>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* ADVANCED AUTO-GENERATED configuration with full control
|
|
37
|
+
* Params are inferred from TypeScript function signatures with optional fine-grained control
|
|
38
|
+
*/
|
|
39
|
+
export type AutoInferredActionConfig<TService> = {
|
|
40
|
+
/**
|
|
41
|
+
* Optional: Service topic/name for Moleculer actions
|
|
42
|
+
* Automatically extracted from schemas if using generateAllServiceSchemas.js pattern
|
|
43
|
+
* This makes service names minification-safe and centralized
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* topic: 'TagService' // Or extracted from TagServiceSchemas.topic
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
topic?: string;
|
|
51
|
+
/**
|
|
52
|
+
* Optional: Override param schemas for specific methods
|
|
53
|
+
* Use this when you need custom Moleculer validation beyond the default 'object' type
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* paramOverrides: {
|
|
58
|
+
* findAccountById: { id: 'string' }, // Override inferred 'object' with 'string'
|
|
59
|
+
* getUsers: { where: { type: 'object', optional: true } } // Add optional flag
|
|
60
|
+
* }
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
paramOverrides?: Partial<{
|
|
64
|
+
[K in ServiceMethods<TService>]: Record<string, unknown>;
|
|
65
|
+
}>;
|
|
66
|
+
/**
|
|
67
|
+
* Optional: Only include specific methods (whitelist approach)
|
|
68
|
+
* If specified, ONLY these methods will be auto-generated
|
|
69
|
+
* Takes precedence over exclude
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```typescript
|
|
73
|
+
* include: ['findAccountById', 'createAccount', 'updateAccount']
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
include?: Array<ServiceMethods<TService>>;
|
|
77
|
+
/**
|
|
78
|
+
* Optional: Exclude specific methods from auto-generation (blacklist approach)
|
|
79
|
+
* Ignored if 'include' is specified
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* exclude: ['deleteAccount', 'internalMethod']
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
exclude?: Array<ServiceMethods<TService>>;
|
|
87
|
+
/**
|
|
88
|
+
* Optional: Map action names to different method names
|
|
89
|
+
* Use this when your Moleculer action name differs from the service method name
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* actionToMethodMap: {
|
|
94
|
+
* 'accounts.find': 'findAccountById',
|
|
95
|
+
* 'accounts.create': 'createAccount'
|
|
96
|
+
* }
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
actionToMethodMap?: Record<string, string>;
|
|
100
|
+
/**
|
|
101
|
+
* Optional: Add custom Moleculer action properties for specific methods
|
|
102
|
+
* Allows setting visibility, caching, rate limiting, etc.
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```typescript
|
|
106
|
+
* actionConfig: {
|
|
107
|
+
* findAccountById: {
|
|
108
|
+
* cache: true,
|
|
109
|
+
* visibility: 'public'
|
|
110
|
+
* },
|
|
111
|
+
* deleteAccount: {
|
|
112
|
+
* visibility: 'protected'
|
|
113
|
+
* }
|
|
114
|
+
* }
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
actionConfig?: Partial<{
|
|
118
|
+
[K in ServiceMethods<TService>]: {
|
|
119
|
+
cache?: boolean | object;
|
|
120
|
+
visibility?: 'public' | 'protected' | 'private';
|
|
121
|
+
[key: string]: unknown;
|
|
122
|
+
};
|
|
123
|
+
}>;
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* ADVANCED AUTO-GENERATED: Generate actions with full control over inclusion, exclusion, and overrides.
|
|
127
|
+
* Params are inferred from TypeScript function signatures with optional fine-grained control.
|
|
128
|
+
*
|
|
129
|
+
* @param service - The service instance to wrap
|
|
130
|
+
* @param config - Advanced configuration for fine-grained control
|
|
131
|
+
* @returns Actions object with handlers for selected service methods
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```typescript
|
|
135
|
+
* // Basic: Auto-generate all methods
|
|
136
|
+
* const actions = generateAutoInferredServiceActions<IAccountService>(accountService);
|
|
137
|
+
*
|
|
138
|
+
* // Advanced: Include only specific methods
|
|
139
|
+
* const actions = generateAutoInferredServiceActions<IAccountService>(accountService, {
|
|
140
|
+
* include: ['findAccountById', 'createAccount', 'updateAccount']
|
|
141
|
+
* });
|
|
142
|
+
*
|
|
143
|
+
* // Advanced: Exclude specific methods
|
|
144
|
+
* const actions = generateAutoInferredServiceActions<IAccountService>(accountService, {
|
|
145
|
+
* exclude: ['deleteAccount', 'internalMethod']
|
|
146
|
+
* });
|
|
147
|
+
*
|
|
148
|
+
* // Advanced: Override param schemas for specific methods
|
|
149
|
+
* const actions = generateAutoInferredServiceActions<IAccountService>(accountService, {
|
|
150
|
+
* paramOverrides: {
|
|
151
|
+
* findAccountById: { id: 'string' },
|
|
152
|
+
* getUsers: { where: { type: 'object', optional: true } }
|
|
153
|
+
* }
|
|
154
|
+
* });
|
|
155
|
+
*
|
|
156
|
+
* // Advanced: Add custom action configuration
|
|
157
|
+
* const actions = generateAutoInferredServiceActions<IAccountService>(accountService, {
|
|
158
|
+
* actionConfig: {
|
|
159
|
+
* findAccountById: { cache: true, visibility: 'public' },
|
|
160
|
+
* deleteAccount: { visibility: 'protected' }
|
|
161
|
+
* }
|
|
162
|
+
* });
|
|
163
|
+
*
|
|
164
|
+
* // Advanced: Combine multiple options
|
|
165
|
+
* const actions = generateAutoInferredServiceActions<IAccountService>(accountService, {
|
|
166
|
+
* include: ['findAccountById', 'createAccount'],
|
|
167
|
+
* paramOverrides: {
|
|
168
|
+
* findAccountById: { id: 'string' }
|
|
169
|
+
* },
|
|
170
|
+
* actionConfig: {
|
|
171
|
+
* findAccountById: { cache: true }
|
|
172
|
+
* }
|
|
173
|
+
* });
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
176
|
+
export declare function generateAutoInferredServiceActions<TService>(service: TService, config?: AutoInferredActionConfig<TService>): Record<string, {
|
|
177
|
+
params?: Record<string, unknown>;
|
|
178
|
+
handler: (ctx: unknown) => unknown;
|
|
179
|
+
}>;
|
|
180
|
+
/**
|
|
181
|
+
* Generate both actions AND events from a service instance
|
|
182
|
+
* - Actions: Generated from regular service methods
|
|
183
|
+
* - Events: Generated from methods marked with @MoleculerEventHandler decorator
|
|
184
|
+
*
|
|
185
|
+
* @param service - The service instance to wrap
|
|
186
|
+
* @param config - Configuration for actions and events
|
|
187
|
+
* @returns Object with both actions and events
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```typescript
|
|
191
|
+
* // Service with decorator
|
|
192
|
+
* class OrganizationService {
|
|
193
|
+
* // Regular method becomes action
|
|
194
|
+
* async createOrganization(org: Org): Promise<Org> { }
|
|
195
|
+
*
|
|
196
|
+
* // Decorated method becomes event handler
|
|
197
|
+
* @MoleculerEventHandler(UserBroadcasterAction.OnUserCreated)
|
|
198
|
+
* async onUserCreated(event: UserEvent): Promise<void> { }
|
|
199
|
+
* }
|
|
200
|
+
*
|
|
201
|
+
* // Generate both
|
|
202
|
+
* const { actions, events } = generateServiceActionsAndEvents(service);
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
205
|
+
export declare function generateServiceActionsAndEvents<TService>(service: TService, config?: AutoInferredActionConfig<TService>): {
|
|
206
|
+
actions: Record<string, {
|
|
207
|
+
params?: Record<string, unknown>;
|
|
208
|
+
handler: (ctx: unknown) => unknown;
|
|
209
|
+
[key: string]: unknown;
|
|
210
|
+
}>;
|
|
211
|
+
events: Record<string, {
|
|
212
|
+
handler: (ctx: unknown) => Promise<void>;
|
|
213
|
+
group?: string;
|
|
214
|
+
}>;
|
|
215
|
+
};
|
|
216
|
+
export interface AutoActionConfig {
|
|
217
|
+
/**
|
|
218
|
+
* Custom parameter validation schema for specific actions
|
|
219
|
+
* Key is the action/method name, value is Moleculer params schema
|
|
220
|
+
*/
|
|
221
|
+
params?: Record<string, Record<string, unknown>>;
|
|
222
|
+
/**
|
|
223
|
+
* Actions to exclude from auto-generation (use manual handlers instead)
|
|
224
|
+
*/
|
|
225
|
+
exclude?: string[];
|
|
226
|
+
/**
|
|
227
|
+
* Action name mappings (if action name differs from method name)
|
|
228
|
+
* Key is the action name, value is the method name
|
|
229
|
+
*/
|
|
230
|
+
actionToMethodMap?: Record<string, string>;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Type-safe configuration that REQUIRES params for ALL service methods
|
|
234
|
+
* TypeScript will show compile error if any method is missing from params
|
|
235
|
+
*/
|
|
236
|
+
export type TypeSafeActionConfig<TService> = {
|
|
237
|
+
/**
|
|
238
|
+
* REQUIRED: Parameter validation schema for ALL service methods
|
|
239
|
+
* TypeScript will error if any method is missing
|
|
240
|
+
*/
|
|
241
|
+
params: {
|
|
242
|
+
[K in ServiceMethods<TService>]: Record<string, unknown>;
|
|
243
|
+
};
|
|
244
|
+
/**
|
|
245
|
+
* Optional: Actions to exclude from auto-generation
|
|
246
|
+
*/
|
|
247
|
+
exclude?: string[];
|
|
248
|
+
/**
|
|
249
|
+
* Optional: Action name mappings
|
|
250
|
+
*/
|
|
251
|
+
actionToMethodMap?: Record<string, string>;
|
|
252
|
+
};
|
|
253
|
+
/**
|
|
254
|
+
* Automatically generate Moleculer actions from a service instance.
|
|
255
|
+
*
|
|
256
|
+
* This eliminates the need to write repetitive action handlers - just pass your service
|
|
257
|
+
* and it will create handlers that forward all calls automatically.
|
|
258
|
+
*
|
|
259
|
+
* @param service - The service instance to wrap
|
|
260
|
+
* @param config - Optional configuration for customizing actions
|
|
261
|
+
* @returns Actions object with handlers for all service methods
|
|
262
|
+
*
|
|
263
|
+
* @example
|
|
264
|
+
* ```typescript
|
|
265
|
+
* const actions = generateServiceActions(accountService, {
|
|
266
|
+
* params: {
|
|
267
|
+
* findAccountById: { id: 'string' },
|
|
268
|
+
* createAccount: { account: 'object' }
|
|
269
|
+
* },
|
|
270
|
+
* exclude: ['get', 'getAll'] // Handle these manually
|
|
271
|
+
* });
|
|
272
|
+
* ```
|
|
273
|
+
*/
|
|
274
|
+
export declare function generateServiceActions<TService extends Record<string, unknown>>(service: TService, config?: AutoActionConfig): Record<string, {
|
|
275
|
+
params?: Record<string, unknown>;
|
|
276
|
+
handler: (ctx: unknown) => unknown;
|
|
277
|
+
}>;
|
|
278
|
+
/**
|
|
279
|
+
* TYPE-SAFE version: Generate Moleculer actions with COMPILE-TIME verification.
|
|
280
|
+
* TypeScript will error if any service method is missing from params.
|
|
281
|
+
*
|
|
282
|
+
* @param service - The service instance to wrap
|
|
283
|
+
* @param config - Type-safe configuration requiring ALL methods to have params
|
|
284
|
+
* @returns Actions object with handlers for all service methods
|
|
285
|
+
*
|
|
286
|
+
* @example
|
|
287
|
+
* ```typescript
|
|
288
|
+
* const actions = generateTypeSafeServiceActions<IAccountService>(accountService, {
|
|
289
|
+
* params: {
|
|
290
|
+
* // TypeScript enforces ALL IAccountService methods are here!
|
|
291
|
+
* findAccountById: { id: 'string' },
|
|
292
|
+
* createAccount: { account: 'object' },
|
|
293
|
+
* // ... if you forget any method, TypeScript will error
|
|
294
|
+
* }
|
|
295
|
+
* });
|
|
296
|
+
* ```
|
|
297
|
+
*/
|
|
298
|
+
export declare function generateTypeSafeServiceActions<TService>(service: TService, config: TypeSafeActionConfig<TService>): Record<string, {
|
|
299
|
+
params?: Record<string, unknown>;
|
|
300
|
+
handler: (ctx: unknown) => unknown;
|
|
301
|
+
}>;
|
|
302
|
+
/**
|
|
303
|
+
* Verify that all service methods have param validation defined.
|
|
304
|
+
* Throws an error if any methods are missing params.
|
|
305
|
+
*
|
|
306
|
+
* Use this in development to ensure you haven't forgotten any param schemas.
|
|
307
|
+
*
|
|
308
|
+
* @param service - The service instance
|
|
309
|
+
* @param config - The config used for generateServiceActions
|
|
310
|
+
* @throws Error if any methods are missing param validation
|
|
311
|
+
*
|
|
312
|
+
* @example
|
|
313
|
+
* ```typescript
|
|
314
|
+
* const config = { params: { ... }, exclude: [...] };
|
|
315
|
+
* verifyAllParamsDefined(accountService, config); // Throws if params missing
|
|
316
|
+
* const actions = generateServiceActions(accountService, config);
|
|
317
|
+
* ```
|
|
318
|
+
*/
|
|
319
|
+
export declare function verifyAllParamsDefined<TService extends Record<string, unknown>>(service: TService, config?: AutoActionConfig): void;
|
|
320
|
+
/**
|
|
321
|
+
* Type-safe Moleculer Service base class with ENFORCED action verification.
|
|
322
|
+
*
|
|
323
|
+
* @deprecated Use generateServiceActionsAndEvents() or generateAutoInferredServiceActions() instead
|
|
324
|
+
* This class requires importing Moleculer Service which causes build issues.
|
|
325
|
+
*
|
|
326
|
+
* Usage with auto-generated actions:
|
|
327
|
+
* ```typescript
|
|
328
|
+
* export class AccountMoleculerService extends Service {
|
|
329
|
+
* constructor(broker: ServiceBroker, { container }: { container: Container }) {
|
|
330
|
+
* super(broker);
|
|
331
|
+
* const accountService = container.get<IAccountService>(SERVER_TYPES.IAccountService);
|
|
332
|
+
*
|
|
333
|
+
* // Automatically generate ALL actions from the service!
|
|
334
|
+
* const autoActions = generateAutoInferredServiceActions(accountService);
|
|
335
|
+
*
|
|
336
|
+
* this.parseServiceSchema({
|
|
337
|
+
* name: MoleculerServiceName.AccountUser,
|
|
338
|
+
* actions: autoActions,
|
|
339
|
+
* });
|
|
340
|
+
* }
|
|
341
|
+
* }
|
|
342
|
+
* ```
|
|
343
|
+
*/
|
|
344
|
+
/**
|
|
345
|
+
* Placeholder for TypedMoleculerService for backward compatibility
|
|
346
|
+
* @deprecated Use generateServiceActionsAndEvents() instead
|
|
347
|
+
*/
|
|
348
|
+
export type TypedMoleculerService<TService> = unknown;
|
|
349
|
+
/**
|
|
350
|
+
* Helper type for explicit verification - use in const to get better error messages
|
|
351
|
+
*/
|
|
352
|
+
export type VerifyAllActionsImplemented<TService> = {
|
|
353
|
+
[K in ServiceMethods<TService>]: true;
|
|
354
|
+
};
|
|
355
|
+
/**
|
|
356
|
+
* Typed action handler with parameter and return type safety
|
|
357
|
+
*/
|
|
358
|
+
export interface TypedActionHandler<TParams = unknown, TReturn = unknown> {
|
|
359
|
+
params?: Record<string, unknown>;
|
|
360
|
+
handler: (ctx: {
|
|
361
|
+
params: TParams;
|
|
362
|
+
}) => TReturn | Promise<TReturn>;
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Helper to create a typed action handler
|
|
366
|
+
*/
|
|
367
|
+
export declare function createTypedAction<TParams, TReturn>(action: TypedActionHandler<TParams, TReturn>): TypedActionHandler<TParams, TReturn>;
|
|
368
|
+
/**
|
|
369
|
+
* Service schema type with better action type hints
|
|
370
|
+
*/
|
|
371
|
+
export interface TypedServiceSchema extends ServiceSchema {
|
|
372
|
+
actions?: Record<string, TypedActionHandler>;
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Extend Moleculer namespace with action generation utilities
|
|
376
|
+
*/
|
|
377
|
+
declare module './moleculerEventHandler' {
|
|
378
|
+
namespace Moleculer {
|
|
379
|
+
/**
|
|
380
|
+
* ADVANCED AUTO-GENERATED configuration with full control
|
|
381
|
+
*/
|
|
382
|
+
type AutoInferredActionConfig<TService> = {
|
|
383
|
+
paramOverrides?: Partial<{
|
|
384
|
+
[K in ServiceMethods<TService>]: Record<string, unknown>;
|
|
385
|
+
}>;
|
|
386
|
+
include?: Array<ServiceMethods<TService>>;
|
|
387
|
+
exclude?: Array<ServiceMethods<TService>>;
|
|
388
|
+
actionToMethodMap?: Record<string, string>;
|
|
389
|
+
actionConfig?: Partial<{
|
|
390
|
+
[K in ServiceMethods<TService>]: {
|
|
391
|
+
cache?: boolean | object;
|
|
392
|
+
visibility?: 'public' | 'protected' | 'private';
|
|
393
|
+
[key: string]: unknown;
|
|
394
|
+
};
|
|
395
|
+
}>;
|
|
396
|
+
};
|
|
397
|
+
/**
|
|
398
|
+
* Generate actions with full control over inclusion, exclusion, and overrides.
|
|
399
|
+
* Params are inferred from TypeScript function signatures.
|
|
400
|
+
*/
|
|
401
|
+
function generateAutoInferredActions<TService>(service: TService, config?: AutoInferredActionConfig<TService>): Record<string, {
|
|
402
|
+
params?: Record<string, unknown>;
|
|
403
|
+
handler: (ctx: unknown) => unknown;
|
|
404
|
+
}>;
|
|
405
|
+
/**
|
|
406
|
+
* Generate both actions AND events from a service instance
|
|
407
|
+
*/
|
|
408
|
+
function generateActionsAndEvents<TService>(service: TService, config?: AutoInferredActionConfig<TService>): {
|
|
409
|
+
actions: Record<string, {
|
|
410
|
+
params?: Record<string, unknown>;
|
|
411
|
+
handler: (ctx: unknown) => unknown;
|
|
412
|
+
[key: string]: unknown;
|
|
413
|
+
}>;
|
|
414
|
+
events: Record<string, {
|
|
415
|
+
handler: (ctx: unknown) => unknown;
|
|
416
|
+
group?: string;
|
|
417
|
+
}>;
|
|
418
|
+
};
|
|
419
|
+
/**
|
|
420
|
+
* DEBUG UTILITY: Extract parameter information for all service methods
|
|
421
|
+
* Returns detailed information about parameters, schemas, and configurations
|
|
422
|
+
*/
|
|
423
|
+
function debugServiceParams<TService>(service: TService, config?: AutoInferredActionConfig<TService>): Record<string, {
|
|
424
|
+
methodName: string;
|
|
425
|
+
paramNames: string[];
|
|
426
|
+
functionSignature: string;
|
|
427
|
+
inferredSchema: Record<string, unknown> | undefined;
|
|
428
|
+
overrideSchema: Record<string, unknown> | undefined;
|
|
429
|
+
isExcluded: boolean;
|
|
430
|
+
isEventHandler: boolean;
|
|
431
|
+
}>;
|
|
432
|
+
/**
|
|
433
|
+
* DEBUG UTILITY: Pretty print service parameter information to console
|
|
434
|
+
* Useful for understanding auto-generation and identifying methods needing overrides
|
|
435
|
+
*/
|
|
436
|
+
function printServiceParams<TService>(service: TService, config?: AutoInferredActionConfig<TService>, options?: {
|
|
437
|
+
onlyMissingOverrides?: boolean;
|
|
438
|
+
onlyIncluded?: boolean;
|
|
439
|
+
showExcluded?: boolean;
|
|
440
|
+
}): void;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* DEBUG UTILITY: Dumps parameter information for all service methods
|
|
445
|
+
*
|
|
446
|
+
* This function extracts and logs parameter names, types, and inferred schemas
|
|
447
|
+
* for debugging auto-generation issues. Use during development to understand
|
|
448
|
+
* what the auto-generation sees and optimize paramOverrides.
|
|
449
|
+
*
|
|
450
|
+
* @param service - The service instance to analyze
|
|
451
|
+
* @param config - Optional configuration to see what would be generated
|
|
452
|
+
* @returns Object with detailed parameter information for each method
|
|
453
|
+
*
|
|
454
|
+
* @example
|
|
455
|
+
* ```typescript
|
|
456
|
+
* // In development/debug mode
|
|
457
|
+
* const paramInfo = Moleculer.debugServiceParams(accountService);
|
|
458
|
+
* console.log(JSON.stringify(paramInfo, null, 2));
|
|
459
|
+
*
|
|
460
|
+
* // With config to see filtered results
|
|
461
|
+
* const paramInfo = Moleculer.debugServiceParams(accountService, {
|
|
462
|
+
* exclude: ['dispose', 'createUserToken']
|
|
463
|
+
* });
|
|
464
|
+
* ```
|
|
465
|
+
*/
|
|
466
|
+
export declare function debugServiceParams<TService>(service: TService, config?: AutoInferredActionConfig<TService>): Record<string, {
|
|
467
|
+
methodName: string;
|
|
468
|
+
paramNames: string[];
|
|
469
|
+
functionSignature: string;
|
|
470
|
+
inferredSchema: Record<string, unknown> | undefined;
|
|
471
|
+
overrideSchema: Record<string, unknown> | undefined;
|
|
472
|
+
isExcluded: boolean;
|
|
473
|
+
isEventHandler: boolean;
|
|
474
|
+
}>;
|
|
475
|
+
/**
|
|
476
|
+
* DEBUG UTILITY: Pretty prints service parameter information to console
|
|
477
|
+
*
|
|
478
|
+
* Formats and logs the output of debugServiceParams() in a readable way.
|
|
479
|
+
* Shows which methods need paramOverrides and what types are inferred.
|
|
480
|
+
*
|
|
481
|
+
* @param service - The service instance to analyze
|
|
482
|
+
* @param config - Optional configuration
|
|
483
|
+
* @param options - Display options
|
|
484
|
+
*
|
|
485
|
+
* @example
|
|
486
|
+
* ```typescript
|
|
487
|
+
* // Print all methods
|
|
488
|
+
* Moleculer.printServiceParams(accountService);
|
|
489
|
+
*
|
|
490
|
+
* // Print only methods without overrides
|
|
491
|
+
* Moleculer.printServiceParams(accountService, config, { onlyMissingOverrides: true });
|
|
492
|
+
*
|
|
493
|
+
* // Print only included methods
|
|
494
|
+
* Moleculer.printServiceParams(accountService, config, { onlyIncluded: true });
|
|
495
|
+
* ```
|
|
496
|
+
*/
|
|
497
|
+
export declare function printServiceParams<TService>(service: TService, config?: AutoInferredActionConfig<TService>, options?: {
|
|
498
|
+
onlyMissingOverrides?: boolean;
|
|
499
|
+
onlyIncluded?: boolean;
|
|
500
|
+
showExcluded?: boolean;
|
|
501
|
+
}): void;
|
|
502
|
+
export {};
|