@asenajs/asena 0.7.1 → 0.8.1
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/README.md +2 -2
- package/dist/lib/adapter/AsenaAdapter.d.ts +2 -2
- package/dist/lib/adapter/AsenaAdapter.js.map +1 -1
- package/dist/lib/adapter/types/ServeOptions.d.ts +16 -0
- package/dist/lib/adapter/types/ValidationError.d.ts +53 -0
- package/dist/lib/adapter/types/ValidationError.js +24 -0
- package/dist/lib/adapter/types/ValidationError.js.map +1 -0
- package/dist/lib/adapter/types/index.d.ts +1 -0
- package/dist/lib/adapter/types/index.js +1 -0
- package/dist/lib/adapter/types/index.js.map +1 -1
- package/dist/lib/ioc/Container.d.ts +25 -0
- package/dist/lib/ioc/Container.js +47 -0
- package/dist/lib/ioc/Container.js.map +1 -1
- package/dist/lib/ioc/CoreContainer.d.ts +5 -3
- package/dist/lib/ioc/CoreContainer.js +9 -3
- package/dist/lib/ioc/CoreContainer.js.map +1 -1
- package/dist/lib/ioc/IocEngine.d.ts +50 -4
- package/dist/lib/ioc/IocEngine.js +138 -12
- package/dist/lib/ioc/IocEngine.js.map +1 -1
- package/dist/lib/ioc/component/componentRegistry.d.ts +22 -0
- package/dist/lib/ioc/component/componentRegistry.js +119 -0
- package/dist/lib/ioc/component/componentRegistry.js.map +1 -0
- package/dist/lib/ioc/component/componentUtils.js +4 -0
- package/dist/lib/ioc/component/componentUtils.js.map +1 -1
- package/dist/lib/ioc/component/decorators/Inject.js +16 -0
- package/dist/lib/ioc/component/decorators/Inject.js.map +1 -1
- package/dist/lib/ioc/component/index.d.ts +1 -0
- package/dist/lib/ioc/component/index.js +1 -0
- package/dist/lib/ioc/component/index.js.map +1 -1
- package/dist/lib/ioc/constants/ComponentConstants.d.ts +4 -0
- package/dist/lib/ioc/constants/ComponentConstants.js +5 -0
- package/dist/lib/ioc/constants/ComponentConstants.js.map +1 -1
- package/dist/lib/ioc/helper/fileHelper.d.ts +9 -0
- package/dist/lib/ioc/helper/fileHelper.js +41 -11
- package/dist/lib/ioc/helper/fileHelper.js.map +1 -1
- package/dist/lib/ioc/types/ICoreServiceNamesType.d.ts +1 -0
- package/dist/lib/ioc/types/ICoreServiceNamesType.js +1 -0
- package/dist/lib/ioc/types/ICoreServiceNamesType.js.map +1 -1
- package/dist/lib/ioc/types/InjectableComponent.d.ts +10 -0
- package/dist/lib/ioc/types/IocConfig.d.ts +7 -0
- package/dist/lib/ioc/types/decorators/ComponentType.d.ts +2 -1
- package/dist/lib/ioc/types/decorators/ComponentType.js +1 -0
- package/dist/lib/ioc/types/decorators/ComponentType.js.map +1 -1
- package/dist/lib/server/AsenaServer.d.ts +47 -3
- package/dist/lib/server/AsenaServer.js +167 -28
- package/dist/lib/server/AsenaServer.js.map +1 -1
- package/dist/lib/server/AsenaServerFactory.d.ts +38 -3
- package/dist/lib/server/AsenaServerFactory.js +21 -2
- package/dist/lib/server/AsenaServerFactory.js.map +1 -1
- package/dist/lib/server/config/AsenaConfig.d.ts +82 -4
- package/dist/lib/server/config/AsenaConfig.js +39 -1
- package/dist/lib/server/config/AsenaConfig.js.map +1 -1
- package/dist/lib/server/decorators/components/MessageController.d.ts +49 -0
- package/dist/lib/server/decorators/components/MessageController.js +62 -0
- package/dist/lib/server/decorators/components/MessageController.js.map +1 -0
- package/dist/lib/server/decorators/components/index.d.ts +1 -0
- package/dist/lib/server/decorators/components/index.js +1 -0
- package/dist/lib/server/decorators/components/index.js.map +1 -1
- package/dist/lib/server/event/EventDispatchService.d.ts +3 -7
- package/dist/lib/server/event/EventDispatchService.js +9 -40
- package/dist/lib/server/event/EventDispatchService.js.map +1 -1
- package/dist/lib/server/event/PatternHandlerIndex.d.ts +53 -0
- package/dist/lib/server/event/PatternHandlerIndex.js +100 -0
- package/dist/lib/server/event/PatternHandlerIndex.js.map +1 -0
- package/dist/lib/server/event/decorators/On.d.ts +4 -0
- package/dist/lib/server/event/decorators/On.js +6 -0
- package/dist/lib/server/event/decorators/On.js.map +1 -1
- package/dist/lib/server/event/index.d.ts +1 -0
- package/dist/lib/server/event/index.js +2 -0
- package/dist/lib/server/event/index.js.map +1 -1
- package/dist/lib/server/event/types.d.ts +12 -0
- package/dist/lib/server/health/HealthServer.d.ts +26 -0
- package/dist/lib/server/health/HealthServer.js +63 -0
- package/dist/lib/server/health/HealthServer.js.map +1 -0
- package/dist/lib/server/health/index.d.ts +1 -0
- package/dist/lib/server/health/index.js +2 -0
- package/dist/lib/server/health/index.js.map +1 -0
- package/dist/lib/server/messaging/Ulak.d.ts +156 -0
- package/dist/lib/server/messaging/Ulak.js +174 -0
- package/dist/lib/server/messaging/Ulak.js.map +1 -1
- package/dist/lib/server/messaging/types.d.ts +5 -1
- package/dist/lib/server/messaging/types.js +5 -0
- package/dist/lib/server/messaging/types.js.map +1 -1
- package/dist/lib/server/microservice/InMemoryTransport.d.ts +45 -0
- package/dist/lib/server/microservice/InMemoryTransport.js +124 -0
- package/dist/lib/server/microservice/InMemoryTransport.js.map +1 -0
- package/dist/lib/server/microservice/MicroserviceTransport.d.ts +132 -0
- package/dist/lib/server/microservice/MicroserviceTransport.js +2 -0
- package/dist/lib/server/microservice/MicroserviceTransport.js.map +1 -0
- package/dist/lib/server/microservice/decorators/EventPattern.d.ts +38 -0
- package/dist/lib/server/microservice/decorators/EventPattern.js +59 -0
- package/dist/lib/server/microservice/decorators/EventPattern.js.map +1 -0
- package/dist/lib/server/microservice/decorators/MessagePattern.d.ts +31 -0
- package/dist/lib/server/microservice/decorators/MessagePattern.js +55 -0
- package/dist/lib/server/microservice/decorators/MessagePattern.js.map +1 -0
- package/dist/lib/server/microservice/decorators/index.d.ts +2 -0
- package/dist/lib/server/microservice/decorators/index.js +3 -0
- package/dist/lib/server/microservice/decorators/index.js.map +1 -0
- package/dist/lib/server/microservice/index.d.ts +5 -0
- package/dist/lib/server/microservice/index.js +11 -0
- package/dist/lib/server/microservice/index.js.map +1 -0
- package/dist/lib/server/microservice/interceptorChain.d.ts +20 -0
- package/dist/lib/server/microservice/interceptorChain.js +39 -0
- package/dist/lib/server/microservice/interceptorChain.js.map +1 -0
- package/dist/lib/server/microservice/types.d.ts +142 -0
- package/dist/lib/server/microservice/types.js +5 -0
- package/dist/lib/server/microservice/types.js.map +1 -0
- package/dist/lib/server/src/services/PrepareEventService.d.ts +4 -1
- package/dist/lib/server/src/services/PrepareEventService.js +10 -3
- package/dist/lib/server/src/services/PrepareEventService.js.map +1 -1
- package/dist/lib/server/src/services/PrepareMicroserviceService.d.ts +66 -0
- package/dist/lib/server/src/services/PrepareMicroserviceService.js +193 -0
- package/dist/lib/server/src/services/PrepareMicroserviceService.js.map +1 -0
- package/dist/lib/test/factory/deepMock.d.ts +25 -0
- package/dist/lib/test/factory/deepMock.js +105 -0
- package/dist/lib/test/factory/deepMock.js.map +1 -0
- package/dist/lib/test/factory/ulakStub.d.ts +44 -0
- package/dist/lib/test/factory/ulakStub.js +40 -0
- package/dist/lib/test/factory/ulakStub.js.map +1 -0
- package/dist/lib/test/harness/createTestApp.d.ts +33 -0
- package/dist/lib/test/harness/createTestApp.js +105 -0
- package/dist/lib/test/harness/createTestApp.js.map +1 -0
- package/dist/lib/test/harness/createWebTest.d.ts +28 -0
- package/dist/lib/test/harness/createWebTest.js +127 -0
- package/dist/lib/test/harness/createWebTest.js.map +1 -0
- package/dist/lib/test/harness/silentLogger.d.ts +27 -0
- package/dist/lib/test/harness/silentLogger.js +54 -0
- package/dist/lib/test/harness/silentLogger.js.map +1 -0
- package/dist/lib/test/harness/types.d.ts +147 -0
- package/dist/lib/test/harness/types.js +2 -0
- package/dist/lib/test/harness/types.js.map +1 -0
- package/dist/lib/test/http/TestHttpCall.d.ts +78 -0
- package/dist/lib/test/http/TestHttpCall.js +149 -0
- package/dist/lib/test/http/TestHttpCall.js.map +1 -0
- package/dist/lib/test/http/TestHttpResponse.d.ts +46 -0
- package/dist/lib/test/http/TestHttpResponse.js +70 -0
- package/dist/lib/test/http/TestHttpResponse.js.map +1 -0
- package/dist/lib/test/index.d.ts +9 -0
- package/dist/lib/test/index.js +8 -0
- package/dist/lib/test/index.js.map +1 -1
- package/dist/lib/test/metadata/discovery.d.ts +21 -0
- package/dist/lib/test/metadata/discovery.js +37 -8
- package/dist/lib/test/metadata/discovery.js.map +1 -1
- package/dist/lib/test/mockComponent.d.ts +25 -0
- package/dist/lib/test/mockComponent.js +39 -6
- package/dist/lib/test/mockComponent.js.map +1 -1
- package/dist/lib/test/types.d.ts +13 -0
- package/package.json +11 -7
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { ComponentConstants } from '../../../ioc';
|
|
2
|
+
import { defineTypedMetadata, getOwnTypedMetadata } from '../../../utils';
|
|
3
|
+
/**
|
|
4
|
+
* @description EventPattern decorator - Marks a method as a fire-and-forget event handler
|
|
5
|
+
*
|
|
6
|
+
* Methods decorated with @EventPattern will be automatically registered into the
|
|
7
|
+
* configured microservice transport when the server boots (via PrepareMicroserviceService).
|
|
8
|
+
* No reply is produced; delivery is at-least-once on durable transports, so handlers
|
|
9
|
+
* should be idempotent (use context.messageId for deduplication).
|
|
10
|
+
*
|
|
11
|
+
* The controller prefix is joined onto the pattern ('order' + 'created' →
|
|
12
|
+
* 'order.created'), matching what ulak.messages('order').emit('created') publishes.
|
|
13
|
+
* Pass `prefix: false` when the pattern is absolute — another service's event
|
|
14
|
+
* vocabulary, a Kafka external topic name, or a global catch-all.
|
|
15
|
+
* Wildcards are supported: 'payment.*', '*.completed', 'user.*.created'.
|
|
16
|
+
* Note that under a prefix, '*' becomes 'order.*' and is no longer a global catch-all.
|
|
17
|
+
*
|
|
18
|
+
* @param params - Event pattern or configuration object
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* @MessageController('order')
|
|
22
|
+
* export class OrderHandler {
|
|
23
|
+
* @EventPattern('created') // Handles 'order.created'
|
|
24
|
+
* async onCreated(event: OrderEvent, context: MessageContext) { }
|
|
25
|
+
*
|
|
26
|
+
* // Absolute - another service's event vocabulary
|
|
27
|
+
* @EventPattern({ pattern: 'payment.completed', prefix: false })
|
|
28
|
+
* async onPaymentCompleted(event: PaymentEvent, context: MessageContext) {
|
|
29
|
+
* await this.orderService.markPaid(event.orderId);
|
|
30
|
+
* }
|
|
31
|
+
*
|
|
32
|
+
* @EventPattern('*') // Wildcards allowed - handles 'order.*'
|
|
33
|
+
* async onAnyOrderEvent(event: any, context: MessageContext) { }
|
|
34
|
+
*
|
|
35
|
+
* @EventPattern({ pattern: 'stock.depleted', skip: true }) // Temporarily disabled
|
|
36
|
+
* async onStockDepleted(event: any, context: MessageContext) { }
|
|
37
|
+
* }
|
|
38
|
+
*/
|
|
39
|
+
export function EventPattern(params) {
|
|
40
|
+
// Normalize params - support both object and string
|
|
41
|
+
const _params = typeof params === 'string' ? { pattern: params, skip: false } : params;
|
|
42
|
+
return function (target, propertyKey, descriptor) {
|
|
43
|
+
// Get existing handlers metadata (other @MessagePattern/@EventPattern methods)
|
|
44
|
+
const handlers = getOwnTypedMetadata(ComponentConstants.MessageHandlersKey, target.constructor) || {};
|
|
45
|
+
// Add this handler's metadata
|
|
46
|
+
handlers[propertyKey.toString()] = {
|
|
47
|
+
pattern: _params.pattern,
|
|
48
|
+
type: 'event',
|
|
49
|
+
methodName: propertyKey.toString(),
|
|
50
|
+
// `!== false` covers the string shorthand and objects that omit the flag
|
|
51
|
+
prefix: _params.prefix !== false,
|
|
52
|
+
skip: _params.skip || false,
|
|
53
|
+
};
|
|
54
|
+
// Store updated metadata
|
|
55
|
+
defineTypedMetadata(ComponentConstants.MessageHandlersKey, handlers, target.constructor);
|
|
56
|
+
return descriptor;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=EventPattern.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EventPattern.js","sourceRoot":"","sources":["../../../../../lib/server/microservice/decorators/EventPattern.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAG1E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,MAAM,UAAU,YAAY,CAAC,MAAmC;IAC9D,oDAAoD;IACpD,MAAM,OAAO,GAAG,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;IAEvF,OAAO,UAAU,MAAc,EAAE,WAA4B,EAAE,UAA8B;QAC3F,+EAA+E;QAC/E,MAAM,QAAQ,GACZ,mBAAmB,CACjB,kBAAkB,CAAC,kBAAkB,EACrC,MAAM,CAAC,WAAW,CACnB,IAAI,EAAE,CAAC;QAEV,8BAA8B;QAC9B,QAAQ,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAC,GAAG;YACjC,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,IAAI,EAAE,OAAO;YACb,UAAU,EAAE,WAAW,CAAC,QAAQ,EAAE;YAClC,yEAAyE;YACzE,MAAM,EAAE,OAAO,CAAC,MAAM,KAAK,KAAK;YAChC,IAAI,EAAE,OAAO,CAAC,IAAI,IAAI,KAAK;SAC5B,CAAC;QAEF,yBAAyB;QACzB,mBAAmB,CAAC,kBAAkB,CAAC,kBAAkB,EAAE,QAAQ,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC;QAEzF,OAAO,UAAU,CAAC;IACpB,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { MessagePatternParams } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* @description MessagePattern decorator - Marks a method as a request/response handler
|
|
4
|
+
*
|
|
5
|
+
* Methods decorated with @MessagePattern will be automatically registered into the
|
|
6
|
+
* configured microservice transport when the server boots (via PrepareMicroserviceService).
|
|
7
|
+
* The method's return value is sent back to the caller as the reply.
|
|
8
|
+
*
|
|
9
|
+
* The controller prefix is joined onto the pattern ('order' + 'create' → 'order.create').
|
|
10
|
+
* Pass `prefix: false` to register the pattern verbatim.
|
|
11
|
+
* Wildcards are NOT allowed — request/response requires exact routing — and
|
|
12
|
+
* `prefix: false` does not relax that.
|
|
13
|
+
*
|
|
14
|
+
* @param params - Request pattern or configuration object
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* @MessageController('order')
|
|
18
|
+
* export class OrderHandler {
|
|
19
|
+
* @MessagePattern('create') // Handles 'order.create'
|
|
20
|
+
* async create(data: CreateOrderDto, context: MessageContext) {
|
|
21
|
+
* return this.orderService.create(data); // reply sent to caller
|
|
22
|
+
* }
|
|
23
|
+
*
|
|
24
|
+
* @MessagePattern({ pattern: 'ping', prefix: false }) // Handles 'ping'
|
|
25
|
+
* async ping(data: any, context: MessageContext) { }
|
|
26
|
+
*
|
|
27
|
+
* @MessagePattern({ pattern: 'delete', skip: true }) // Temporarily disabled
|
|
28
|
+
* async delete(data: any, context: MessageContext) { }
|
|
29
|
+
* }
|
|
30
|
+
*/
|
|
31
|
+
export declare function MessagePattern(params: MessagePatternParams | string): MethodDecorator;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { ComponentConstants } from '../../../ioc';
|
|
2
|
+
import { defineTypedMetadata, getOwnTypedMetadata } from '../../../utils';
|
|
3
|
+
/**
|
|
4
|
+
* @description MessagePattern decorator - Marks a method as a request/response handler
|
|
5
|
+
*
|
|
6
|
+
* Methods decorated with @MessagePattern will be automatically registered into the
|
|
7
|
+
* configured microservice transport when the server boots (via PrepareMicroserviceService).
|
|
8
|
+
* The method's return value is sent back to the caller as the reply.
|
|
9
|
+
*
|
|
10
|
+
* The controller prefix is joined onto the pattern ('order' + 'create' → 'order.create').
|
|
11
|
+
* Pass `prefix: false` to register the pattern verbatim.
|
|
12
|
+
* Wildcards are NOT allowed — request/response requires exact routing — and
|
|
13
|
+
* `prefix: false` does not relax that.
|
|
14
|
+
*
|
|
15
|
+
* @param params - Request pattern or configuration object
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* @MessageController('order')
|
|
19
|
+
* export class OrderHandler {
|
|
20
|
+
* @MessagePattern('create') // Handles 'order.create'
|
|
21
|
+
* async create(data: CreateOrderDto, context: MessageContext) {
|
|
22
|
+
* return this.orderService.create(data); // reply sent to caller
|
|
23
|
+
* }
|
|
24
|
+
*
|
|
25
|
+
* @MessagePattern({ pattern: 'ping', prefix: false }) // Handles 'ping'
|
|
26
|
+
* async ping(data: any, context: MessageContext) { }
|
|
27
|
+
*
|
|
28
|
+
* @MessagePattern({ pattern: 'delete', skip: true }) // Temporarily disabled
|
|
29
|
+
* async delete(data: any, context: MessageContext) { }
|
|
30
|
+
* }
|
|
31
|
+
*/
|
|
32
|
+
export function MessagePattern(params) {
|
|
33
|
+
// Normalize params - support both object and string
|
|
34
|
+
const _params = typeof params === 'string' ? { pattern: params, skip: false } : params;
|
|
35
|
+
if (_params.pattern.includes('*')) {
|
|
36
|
+
throw new Error(`@MessagePattern('${_params.pattern}') cannot contain wildcards - request/response requires exact patterns. Use @EventPattern for wildcard subscriptions.`);
|
|
37
|
+
}
|
|
38
|
+
return function (target, propertyKey, descriptor) {
|
|
39
|
+
// Get existing handlers metadata (other @MessagePattern/@EventPattern methods)
|
|
40
|
+
const handlers = getOwnTypedMetadata(ComponentConstants.MessageHandlersKey, target.constructor) || {};
|
|
41
|
+
// Add this handler's metadata
|
|
42
|
+
handlers[propertyKey.toString()] = {
|
|
43
|
+
pattern: _params.pattern,
|
|
44
|
+
type: 'message',
|
|
45
|
+
methodName: propertyKey.toString(),
|
|
46
|
+
// `!== false` covers the string shorthand and objects that omit the flag
|
|
47
|
+
prefix: _params.prefix !== false,
|
|
48
|
+
skip: _params.skip || false,
|
|
49
|
+
};
|
|
50
|
+
// Store updated metadata
|
|
51
|
+
defineTypedMetadata(ComponentConstants.MessageHandlersKey, handlers, target.constructor);
|
|
52
|
+
return descriptor;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=MessagePattern.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MessagePattern.js","sourceRoot":"","sources":["../../../../../lib/server/microservice/decorators/MessagePattern.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAG1E;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,UAAU,cAAc,CAAC,MAAqC;IAClE,oDAAoD;IACpD,MAAM,OAAO,GAAG,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;IAEvF,IAAI,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAClC,MAAM,IAAI,KAAK,CACb,oBAAoB,OAAO,CAAC,OAAO,uHAAuH,CAC3J,CAAC;IACJ,CAAC;IAED,OAAO,UAAU,MAAc,EAAE,WAA4B,EAAE,UAA8B;QAC3F,+EAA+E;QAC/E,MAAM,QAAQ,GACZ,mBAAmB,CACjB,kBAAkB,CAAC,kBAAkB,EACrC,MAAM,CAAC,WAAW,CACnB,IAAI,EAAE,CAAC;QAEV,8BAA8B;QAC9B,QAAQ,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAC,GAAG;YACjC,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,IAAI,EAAE,SAAS;YACf,UAAU,EAAE,WAAW,CAAC,QAAQ,EAAE;YAClC,yEAAyE;YACzE,MAAM,EAAE,OAAO,CAAC,MAAM,KAAK,KAAK;YAChC,IAAI,EAAE,OAAO,CAAC,IAAI,IAAI,KAAK;SAC5B,CAAC;QAEF,yBAAyB;QACzB,mBAAmB,CAAC,kBAAkB,CAAC,kBAAkB,EAAE,QAAQ,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC;QAEzF,OAAO,UAAU,CAAC;IACpB,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../lib/server/microservice/decorators/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Transport SPI
|
|
2
|
+
export * from './MicroserviceTransport';
|
|
3
|
+
// Types (params, metadata, interceptor SPI)
|
|
4
|
+
export * from './types';
|
|
5
|
+
// In-process reference transport
|
|
6
|
+
export * from './InMemoryTransport';
|
|
7
|
+
// Interceptor composition (used by Ulak and PrepareMicroserviceService)
|
|
8
|
+
export * from './interceptorChain';
|
|
9
|
+
// Decorators
|
|
10
|
+
export * from './decorators';
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../lib/server/microservice/index.ts"],"names":[],"mappings":"AAAA,gBAAgB;AAChB,cAAc,yBAAyB,CAAC;AAExC,4CAA4C;AAC5C,cAAc,SAAS,CAAC;AAExB,iCAAiC;AACjC,cAAc,qBAAqB,CAAC;AAEpC,wEAAwE;AACxE,cAAc,oBAAoB,CAAC;AAEnC,aAAa;AACb,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { MessageContext } from './MicroserviceTransport';
|
|
2
|
+
import type { MessagingInterceptor, OutboundContext } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* @description Composes interceptor onSend hooks around an outgoing operation.
|
|
5
|
+
* Interceptors run in registration order (first interceptor is outermost).
|
|
6
|
+
*
|
|
7
|
+
* @param interceptors - Registered messaging interceptors
|
|
8
|
+
* @param ctx - Outbound context (interceptors may mutate ctx.headers)
|
|
9
|
+
* @param operation - The actual transport send/emit call
|
|
10
|
+
*/
|
|
11
|
+
export declare function composeOnSend(interceptors: MessagingInterceptor[], ctx: OutboundContext, operation: () => Promise<any>): Promise<any>;
|
|
12
|
+
/**
|
|
13
|
+
* @description Composes interceptor onReceive hooks around a handler invocation.
|
|
14
|
+
* Interceptors run in registration order (first interceptor is outermost).
|
|
15
|
+
*
|
|
16
|
+
* @param interceptors - Registered messaging interceptors
|
|
17
|
+
* @param ctx - Incoming message context
|
|
18
|
+
* @param operation - The actual handler invocation
|
|
19
|
+
*/
|
|
20
|
+
export declare function composeOnReceive(interceptors: MessagingInterceptor[], ctx: MessageContext, operation: () => Promise<any>): Promise<any>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description Composes interceptor onSend hooks around an outgoing operation.
|
|
3
|
+
* Interceptors run in registration order (first interceptor is outermost).
|
|
4
|
+
*
|
|
5
|
+
* @param interceptors - Registered messaging interceptors
|
|
6
|
+
* @param ctx - Outbound context (interceptors may mutate ctx.headers)
|
|
7
|
+
* @param operation - The actual transport send/emit call
|
|
8
|
+
*/
|
|
9
|
+
export function composeOnSend(interceptors, ctx, operation) {
|
|
10
|
+
let next = operation;
|
|
11
|
+
for (let i = interceptors.length - 1; i >= 0; i--) {
|
|
12
|
+
const interceptor = interceptors[i];
|
|
13
|
+
if (interceptor.onSend) {
|
|
14
|
+
const inner = next;
|
|
15
|
+
next = () => interceptor.onSend(ctx, inner);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return next();
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* @description Composes interceptor onReceive hooks around a handler invocation.
|
|
22
|
+
* Interceptors run in registration order (first interceptor is outermost).
|
|
23
|
+
*
|
|
24
|
+
* @param interceptors - Registered messaging interceptors
|
|
25
|
+
* @param ctx - Incoming message context
|
|
26
|
+
* @param operation - The actual handler invocation
|
|
27
|
+
*/
|
|
28
|
+
export function composeOnReceive(interceptors, ctx, operation) {
|
|
29
|
+
let next = operation;
|
|
30
|
+
for (let i = interceptors.length - 1; i >= 0; i--) {
|
|
31
|
+
const interceptor = interceptors[i];
|
|
32
|
+
if (interceptor.onReceive) {
|
|
33
|
+
const inner = next;
|
|
34
|
+
next = () => interceptor.onReceive(ctx, inner);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return next();
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=interceptorChain.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interceptorChain.js","sourceRoot":"","sources":["../../../../lib/server/microservice/interceptorChain.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa,CAC3B,YAAoC,EACpC,GAAoB,EACpB,SAA6B;IAE7B,IAAI,IAAI,GAAG,SAAS,CAAC;IAErB,KAAK,IAAI,CAAC,GAAG,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAClD,MAAM,WAAW,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;QAEpC,IAAI,WAAW,CAAC,MAAM,EAAE,CAAC;YACvB,MAAM,KAAK,GAAG,IAAI,CAAC;YAEnB,IAAI,GAAG,GAAG,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC9C,CAAC;IACH,CAAC;IAED,OAAO,IAAI,EAAE,CAAC;AAChB,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,gBAAgB,CAC9B,YAAoC,EACpC,GAAmB,EACnB,SAA6B;IAE7B,IAAI,IAAI,GAAG,SAAS,CAAC;IAErB,KAAK,IAAI,CAAC,GAAG,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAClD,MAAM,WAAW,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;QAEpC,IAAI,WAAW,CAAC,SAAS,EAAE,CAAC;YAC1B,MAAM,KAAK,GAAG,IAAI,CAAC;YAEnB,IAAI,GAAG,GAAG,EAAE,CAAC,WAAW,CAAC,SAAS,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QACjD,CAAC;IACH,CAAC;IAED,OAAO,IAAI,EAAE,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import type { ComponentParams } from '../../ioc';
|
|
2
|
+
import type { MessageContext } from './MicroserviceTransport';
|
|
3
|
+
/**
|
|
4
|
+
* @description Name used when a single (unnamed) microservice transport is configured
|
|
5
|
+
*/
|
|
6
|
+
export declare const DEFAULT_TRANSPORT_NAME = "default";
|
|
7
|
+
/**
|
|
8
|
+
* @description Parameters for @MessageController decorator
|
|
9
|
+
*/
|
|
10
|
+
export interface MessageControllerParams extends ComponentParams {
|
|
11
|
+
/**
|
|
12
|
+
* Prefix joined (with a dot) onto every @MessagePattern AND @EventPattern in
|
|
13
|
+
* this controller. A single handler opts out with `prefix: false`.
|
|
14
|
+
* Must be a literal path segment — a wildcard prefix is rejected at boot.
|
|
15
|
+
* @example 'order' turns @MessagePattern('create') into 'order.create'
|
|
16
|
+
* and @EventPattern('created') into 'order.created'
|
|
17
|
+
*/
|
|
18
|
+
prefix?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Name of the microservice transport this controller binds to.
|
|
21
|
+
* Only needed when multiple named transports are configured in transport()
|
|
22
|
+
* (e.g. part of the project on Redis, part on NATS).
|
|
23
|
+
* @default 'default'
|
|
24
|
+
*/
|
|
25
|
+
transport?: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* @description Parameters for @MessagePattern method decorator
|
|
29
|
+
*/
|
|
30
|
+
export interface MessagePatternParams {
|
|
31
|
+
/**
|
|
32
|
+
* Request pattern to handle. Must be exact — wildcards are not allowed
|
|
33
|
+
* (request/response requires exact routing).
|
|
34
|
+
* @example 'create' (joined with the controller prefix → 'order.create')
|
|
35
|
+
*/
|
|
36
|
+
pattern: string;
|
|
37
|
+
/**
|
|
38
|
+
* Join the @MessageController prefix onto `pattern`.
|
|
39
|
+
* Set false to register the pattern verbatim — for patterns that belong to
|
|
40
|
+
* another service's vocabulary rather than this controller's.
|
|
41
|
+
* @default true
|
|
42
|
+
*/
|
|
43
|
+
prefix?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Skip this handler (useful for temporarily disabling handlers)
|
|
46
|
+
* @default false
|
|
47
|
+
*/
|
|
48
|
+
skip?: boolean;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* @description Parameters for @EventPattern method decorator
|
|
52
|
+
*/
|
|
53
|
+
export interface EventPatternParams {
|
|
54
|
+
/**
|
|
55
|
+
* Event pattern to handle. Wildcards are supported.
|
|
56
|
+
* The controller prefix is joined on unless `prefix: false`.
|
|
57
|
+
* @example 'created' (joined with the controller prefix → 'order.created')
|
|
58
|
+
*/
|
|
59
|
+
pattern: string;
|
|
60
|
+
/**
|
|
61
|
+
* Join the @MessageController prefix onto `pattern`.
|
|
62
|
+
* Set false for absolute names: another service's event vocabulary, a Kafka
|
|
63
|
+
* external topic name, or a global catch-all ('*').
|
|
64
|
+
* @default true
|
|
65
|
+
*/
|
|
66
|
+
prefix?: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Skip this handler (useful for temporarily disabling handlers)
|
|
69
|
+
* @default false
|
|
70
|
+
*/
|
|
71
|
+
skip?: boolean;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* @description Metadata stored for each @MessagePattern/@EventPattern method
|
|
75
|
+
* Used by PrepareMicroserviceService to register handlers into the transport
|
|
76
|
+
*/
|
|
77
|
+
export interface MessageHandlerMetadata {
|
|
78
|
+
/**
|
|
79
|
+
* Pattern as written on the decorator. The @MessageController prefix is
|
|
80
|
+
* joined on later by PrepareMicroserviceService unless `prefix` is false.
|
|
81
|
+
*/
|
|
82
|
+
pattern: string;
|
|
83
|
+
/**
|
|
84
|
+
* Handler semantics: request/response ('message') or fire-and-forget ('event')
|
|
85
|
+
*/
|
|
86
|
+
type: 'message' | 'event';
|
|
87
|
+
/**
|
|
88
|
+
* Method name to call when a message arrives
|
|
89
|
+
*/
|
|
90
|
+
methodName: string;
|
|
91
|
+
/**
|
|
92
|
+
* Whether the controller prefix is joined onto `pattern`.
|
|
93
|
+
* Normalized at decoration time (`prefix: false` opt-out → false).
|
|
94
|
+
*/
|
|
95
|
+
prefix: boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Whether this handler should be skipped
|
|
98
|
+
*/
|
|
99
|
+
skip: boolean;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* @description Context passed to MessagingInterceptor.onSend for outgoing messages
|
|
103
|
+
*/
|
|
104
|
+
export interface OutboundContext {
|
|
105
|
+
/**
|
|
106
|
+
* Full outgoing pattern (prefix already applied)
|
|
107
|
+
*/
|
|
108
|
+
pattern: string;
|
|
109
|
+
/**
|
|
110
|
+
* Whether this is a request ('send') or a fire-and-forget event ('emit')
|
|
111
|
+
*/
|
|
112
|
+
kind: 'send' | 'emit';
|
|
113
|
+
/**
|
|
114
|
+
* Mutable outgoing headers — interceptors inject metadata here (e.g. trace context)
|
|
115
|
+
*/
|
|
116
|
+
headers: Record<string, string>;
|
|
117
|
+
/**
|
|
118
|
+
* Outgoing payload (read-only by convention)
|
|
119
|
+
*/
|
|
120
|
+
data: unknown;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* @description Zero-dependency messaging interceptor SPI.
|
|
124
|
+
*
|
|
125
|
+
* Both hooks are wrappers around the actual operation, so an interceptor can
|
|
126
|
+
* measure duration and observe errors/replies (e.g. OpenTelemetry spans).
|
|
127
|
+
* Interceptors are registered via the transport() config hook:
|
|
128
|
+
* `transport() { return { microservice, interceptors: [myInterceptor] } }`
|
|
129
|
+
*/
|
|
130
|
+
export interface MessagingInterceptor {
|
|
131
|
+
/**
|
|
132
|
+
* Wraps outgoing send/emit. Mutate ctx.headers to inject metadata,
|
|
133
|
+
* call next() to perform the operation (its promise resolves with the
|
|
134
|
+
* reply for 'send', undefined for 'emit').
|
|
135
|
+
*/
|
|
136
|
+
onSend?(ctx: OutboundContext, next: () => Promise<any>): Promise<any>;
|
|
137
|
+
/**
|
|
138
|
+
* Wraps an incoming handler invocation. Call next() to run the handler
|
|
139
|
+
* (and any inner interceptors); its promise carries the handler result.
|
|
140
|
+
*/
|
|
141
|
+
onReceive?(ctx: MessageContext, next: () => Promise<any>): Promise<any>;
|
|
142
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../lib/server/microservice/types.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,SAAS,CAAC"}
|
|
@@ -15,6 +15,7 @@ import type { ICoreService } from '../../../ioc';
|
|
|
15
15
|
* - Prefix='user', event='created' → 'user.created'
|
|
16
16
|
* - Prefix='user', event='*.updated' → 'user.*.updated'
|
|
17
17
|
* - Prefix='user', event='' → 'user'
|
|
18
|
+
* - Handler opted out (prefix: false) → event, verbatim
|
|
18
19
|
*/
|
|
19
20
|
export declare class PrepareEventService implements ICoreService {
|
|
20
21
|
readonly serviceName = "PrepareEventService";
|
|
@@ -31,7 +32,9 @@ export declare class PrepareEventService implements ICoreService {
|
|
|
31
32
|
/**
|
|
32
33
|
* Build final event pattern from prefix and event
|
|
33
34
|
*
|
|
34
|
-
* Rules
|
|
35
|
+
* Rules (identical to PrepareMicroserviceService.buildPattern and
|
|
36
|
+
* UlakMessages.buildPattern):
|
|
37
|
+
* - Handler opted out (prefix: false) → event
|
|
35
38
|
* - No prefix → event
|
|
36
39
|
* - No event → prefix
|
|
37
40
|
* - Both → prefix.event
|
|
@@ -26,6 +26,7 @@ import { getTypedMetadata } from '../../../utils';
|
|
|
26
26
|
* - Prefix='user', event='created' → 'user.created'
|
|
27
27
|
* - Prefix='user', event='*.updated' → 'user.*.updated'
|
|
28
28
|
* - Prefix='user', event='' → 'user'
|
|
29
|
+
* - Handler opted out (prefix: false) → event, verbatim
|
|
29
30
|
*/
|
|
30
31
|
let PrepareEventService = class PrepareEventService {
|
|
31
32
|
serviceName = 'PrepareEventService';
|
|
@@ -65,7 +66,9 @@ let PrepareEventService = class PrepareEventService {
|
|
|
65
66
|
continue;
|
|
66
67
|
}
|
|
67
68
|
// Build final event pattern
|
|
68
|
-
|
|
69
|
+
// `!== false`: metadata written by a pre-0.8 decorator build carries no
|
|
70
|
+
// flag and must follow the current default (apply the prefix)
|
|
71
|
+
const finalPattern = this.buildEventPattern(prefix, metadata.pattern, metadata.prefix !== false);
|
|
69
72
|
// Bind method to service instance
|
|
70
73
|
const boundHandler = service[methodName].bind(service);
|
|
71
74
|
// Register with EventEmitter
|
|
@@ -75,12 +78,16 @@ let PrepareEventService = class PrepareEventService {
|
|
|
75
78
|
/**
|
|
76
79
|
* Build final event pattern from prefix and event
|
|
77
80
|
*
|
|
78
|
-
* Rules
|
|
81
|
+
* Rules (identical to PrepareMicroserviceService.buildPattern and
|
|
82
|
+
* UlakMessages.buildPattern):
|
|
83
|
+
* - Handler opted out (prefix: false) → event
|
|
79
84
|
* - No prefix → event
|
|
80
85
|
* - No event → prefix
|
|
81
86
|
* - Both → prefix.event
|
|
82
87
|
*/
|
|
83
|
-
buildEventPattern(prefix, event) {
|
|
88
|
+
buildEventPattern(prefix, event, applyPrefix) {
|
|
89
|
+
if (!applyPrefix)
|
|
90
|
+
return event;
|
|
84
91
|
if (!prefix)
|
|
85
92
|
return event;
|
|
86
93
|
if (!event)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrepareEventService.js","sourceRoot":"","sources":["../../../../../lib/server/src/services/PrepareEventService.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjG,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAGlD
|
|
1
|
+
{"version":3,"file":"PrepareEventService.js","sourceRoot":"","sources":["../../../../../lib/server/src/services/PrepareEventService.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjG,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAGlD;;;;;;;;;;;;;;;;;GAiBG;AAEI,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IACd,WAAW,GAAG,qBAAqB,CAAC;IAG5C,SAAS,CAAa;IAGtB,eAAe,CAAwB;IAE/C;;OAEG;IACI,KAAK,CAAC,OAAO;QAClB,gCAAgC;QAChC,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,UAAU,CAAM,aAAa,CAAC,KAAK,CAAC,CAAC;QAEhF,IAAI,CAAC,aAAa,IAAI,aAAa,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACjD,sCAAsC;YACtC,OAAO;QACT,CAAC;QAED,gCAAgC;QAChC,KAAK,MAAM,OAAO,IAAI,aAAa,EAAE,CAAC;YACpC,MAAM,IAAI,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC;QAC3C,CAAC;IACH,CAAC;IAED;;OAEG;IACK,KAAK,CAAC,oBAAoB,CAAC,OAAY;QAC7C,0BAA0B;QAC1B,MAAM,MAAM,GAAG,gBAAgB,CAAS,kBAAkB,CAAC,cAAc,EAAE,OAAO,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC;QAEtG,4BAA4B;QAC5B,MAAM,QAAQ,GAAG,gBAAgB,CAC/B,kBAAkB,CAAC,gBAAgB,EACnC,OAAO,CAAC,WAAW,CACpB,CAAC;QAEF,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,wBAAwB;YACxB,OAAO;QACT,CAAC;QAED,wBAAwB;QACxB,KAAK,MAAM,CAAC,UAAU,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC9D,4BAA4B;YAC5B,IAAI,QAAQ,CAAC,IAAI,EAAE,CAAC;gBAClB,SAAS;YACX,CAAC;YAED,4BAA4B;YAC5B,wEAAwE;YACxE,8DAA8D;YAC9D,MAAM,YAAY,GAAG,IAAI,CAAC,iBAAiB,CAAC,MAAM,EAAE,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,KAAK,KAAK,CAAC,CAAC;YAEjG,kCAAkC;YAClC,MAAM,YAAY,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAEvD,6BAA6B;YAC7B,IAAI,CAAC,eAAe,CAAC,eAAe,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC;QACnE,CAAC;IACH,CAAC;IAED;;;;;;;;;OASG;IACK,iBAAiB,CAAC,MAAc,EAAE,KAAa,EAAE,WAAoB;QAC3E,IAAI,CAAC,WAAW;YAAE,OAAO,KAAK,CAAC;QAC/B,IAAI,CAAC,MAAM;YAAE,OAAO,KAAK,CAAC;QAC1B,IAAI,CAAC,KAAK;YAAE,OAAO,MAAM,CAAC;QAC1B,OAAO,GAAG,MAAM,IAAI,KAAK,EAAE,CAAC;IAC9B,CAAC;CACF,CAAA;AA7ES;IADP,MAAM,CAAC,iBAAiB,CAAC,SAAS,CAAC;;sDACN;AAGtB;IADP,MAAM,CAAC,iBAAiB,CAAC,sBAAsB,CAAC;;4DACF;AAPpC,mBAAmB;IAD/B,WAAW,CAAC,iBAAiB,CAAC,qBAAqB,CAAC;GACxC,mBAAmB,CAiF/B"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { ICoreService } from '../../../ioc';
|
|
2
|
+
import type { MessagingInterceptor } from '../../microservice/types';
|
|
3
|
+
import type { DestroyOptions, MicroserviceTransport } from '../../microservice/MicroserviceTransport';
|
|
4
|
+
/**
|
|
5
|
+
* @description PrepareMicroserviceService - Registers microservice message handlers during bootstrap
|
|
6
|
+
*
|
|
7
|
+
* Scan Process:
|
|
8
|
+
* 1. Resolve all ComponentType.MESSAGE_CONTROLLER from container
|
|
9
|
+
* 2. Extract prefix + transport binding metadata from class
|
|
10
|
+
* 3. Extract handler metadata (@MessagePattern/@EventPattern methods)
|
|
11
|
+
* 4. Build final pattern: the controller prefix is joined onto BOTH message and event
|
|
12
|
+
* patterns, unless the handler opted out with prefix: false
|
|
13
|
+
* 5. Bind method to instance, wrap with interceptor onReceive chain
|
|
14
|
+
* 6. Register into the bound transport, then init() + listen() every transport
|
|
15
|
+
* 7. Wire transports into Ulak (send/emit client side)
|
|
16
|
+
*
|
|
17
|
+
* Rules:
|
|
18
|
+
* - Controllers found but no transport configured → throw (fail fast)
|
|
19
|
+
* - Transport configured but no controllers → still init + wire Ulak (client-only mode);
|
|
20
|
+
* the transport contract guarantees no consumer loop starts with zero handlers
|
|
21
|
+
* - Controller bound to an unknown named transport → throw listing available names
|
|
22
|
+
* - A handler with prefix: false registers its pattern verbatim (external topics,
|
|
23
|
+
* another service's event vocabulary, global catch-alls)
|
|
24
|
+
* - A prefix containing '*' is a boot error - the prefix must be a literal path segment
|
|
25
|
+
*/
|
|
26
|
+
export declare class PrepareMicroserviceService implements ICoreService {
|
|
27
|
+
readonly serviceName = "PrepareMicroserviceService";
|
|
28
|
+
private container;
|
|
29
|
+
private logger;
|
|
30
|
+
private ulak;
|
|
31
|
+
private transports;
|
|
32
|
+
/**
|
|
33
|
+
* Prepare microservice handlers - Called during bootstrap (before the HTTP adapter starts)
|
|
34
|
+
*
|
|
35
|
+
* @param transports - Named transports from the transport() config hook
|
|
36
|
+
* @param interceptors - Messaging interceptors applied to all transports
|
|
37
|
+
*/
|
|
38
|
+
prepare(transports?: Map<string, MicroserviceTransport>, interceptors?: MessagingInterceptor[]): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Gracefully shut down all transports - Called from AsenaServer.stop()
|
|
41
|
+
*/
|
|
42
|
+
destroy(options?: DestroyOptions): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Register all handlers from a single message controller
|
|
45
|
+
*/
|
|
46
|
+
private registerController;
|
|
47
|
+
/**
|
|
48
|
+
* Build the final pattern from the controller prefix and the handler pattern
|
|
49
|
+
*
|
|
50
|
+
* Rules (identical for @MessagePattern and @EventPattern, and identical to
|
|
51
|
+
* UlakMessages.buildPattern on the outbound side and PrepareEventService
|
|
52
|
+
* .buildEventPattern for the in-process event system):
|
|
53
|
+
* - Handler opted out (prefix: false) → pattern
|
|
54
|
+
* - No prefix → pattern
|
|
55
|
+
* - No pattern → prefix
|
|
56
|
+
* - Both → prefix.pattern
|
|
57
|
+
*/
|
|
58
|
+
private buildPattern;
|
|
59
|
+
/**
|
|
60
|
+
* Log one line per controller with the RESOLVED patterns
|
|
61
|
+
*
|
|
62
|
+
* Asena 0.8 changed the prefix rule for @EventPattern, so the joined result
|
|
63
|
+
* must be visible at boot - but per-handler lines would drown the startup output.
|
|
64
|
+
*/
|
|
65
|
+
private logResolved;
|
|
66
|
+
}
|