@ebarahona/loopback-transport-core 1.0.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +472 -35
- package/dist/client/client-proxy.d.ts +73 -42
- package/dist/client/client-proxy.js +71 -42
- package/dist/client/client-proxy.js.map +1 -1
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.js +3 -15
- package/dist/client/index.js.map +1 -1
- package/dist/context/execution-context.d.ts +58 -11
- package/dist/context/execution-context.js +62 -17
- package/dist/context/execution-context.js.map +1 -1
- package/dist/context/index.d.ts +2 -1
- package/dist/context/index.js +3 -15
- package/dist/context/index.js.map +1 -1
- package/dist/decorators/constants.d.ts +20 -10
- package/dist/decorators/constants.js +6 -2
- package/dist/decorators/constants.js.map +1 -1
- package/dist/decorators/event-handler.decorator.d.ts +10 -7
- package/dist/decorators/event-handler.decorator.js +18 -13
- package/dist/decorators/event-handler.decorator.js.map +1 -1
- package/dist/decorators/index.d.ts +5 -4
- package/dist/decorators/index.js +11 -18
- package/dist/decorators/index.js.map +1 -1
- package/dist/decorators/message-handler.decorator.d.ts +8 -5
- package/dist/decorators/message-handler.decorator.js +16 -11
- package/dist/decorators/message-handler.decorator.js.map +1 -1
- package/dist/decorators/payload.decorator.d.ts +16 -7
- package/dist/decorators/payload.decorator.js +16 -8
- package/dist/decorators/payload.decorator.js.map +1 -1
- package/dist/discovery/discovery.service.d.ts +143 -0
- package/dist/discovery/discovery.service.js +165 -0
- package/dist/discovery/discovery.service.js.map +1 -0
- package/dist/discovery/event-handler-discoverer.d.ts +19 -0
- package/dist/discovery/event-handler-discoverer.js +50 -0
- package/dist/discovery/event-handler-discoverer.js.map +1 -0
- package/dist/discovery/handler-discoverer.d.ts +48 -0
- package/dist/discovery/handler-discoverer.js +3 -0
- package/dist/discovery/handler-discoverer.js.map +1 -0
- package/dist/discovery/handler-kind.d.ts +23 -0
- package/dist/discovery/handler-kind.js +14 -0
- package/dist/discovery/handler-kind.js.map +1 -0
- package/dist/discovery/index.d.ts +7 -0
- package/dist/discovery/index.js +13 -0
- package/dist/discovery/index.js.map +1 -0
- package/dist/discovery/message-handler-discoverer.d.ts +19 -0
- package/dist/discovery/message-handler-discoverer.js +50 -0
- package/dist/discovery/message-handler-discoverer.js.map +1 -0
- package/dist/discovery/registered-handler.d.ts +35 -0
- package/dist/discovery/registered-handler.js +3 -0
- package/dist/discovery/registered-handler.js.map +1 -0
- package/dist/helpers/errors.d.ts +61 -0
- package/dist/helpers/errors.js +80 -0
- package/dist/helpers/errors.js.map +1 -0
- package/dist/helpers/index.d.ts +2 -0
- package/dist/helpers/index.js +14 -0
- package/dist/helpers/index.js.map +1 -0
- package/dist/helpers/register-server.d.ts +44 -0
- package/dist/helpers/register-server.js +72 -0
- package/dist/helpers/register-server.js.map +1 -0
- package/dist/index.d.ts +15 -7
- package/dist/index.js +33 -9
- package/dist/index.js.map +1 -1
- package/dist/interfaces/index.d.ts +4 -4
- package/dist/interfaces/index.js +0 -18
- package/dist/interfaces/index.js.map +1 -1
- package/dist/interfaces/message-handler.interface.d.ts +12 -6
- package/dist/interfaces/packet.interface.d.ts +20 -2
- package/dist/interfaces/transport-client.interface.d.ts +25 -13
- package/dist/interfaces/transport-server.interface.d.ts +36 -10
- package/dist/keys.d.ts +143 -46
- package/dist/keys.js +142 -68
- package/dist/keys.js.map +1 -1
- package/dist/registry/handler-registry.d.ts +94 -24
- package/dist/registry/handler-registry.js +279 -89
- package/dist/registry/handler-registry.js.map +1 -1
- package/dist/registry/index.d.ts +1 -1
- package/dist/registry/index.js +3 -15
- package/dist/registry/index.js.map +1 -1
- package/dist/serializers/cloudevents-serializer.d.ts +107 -0
- package/dist/serializers/cloudevents-serializer.js +130 -0
- package/dist/serializers/cloudevents-serializer.js.map +1 -0
- package/dist/serializers/index.d.ts +4 -1
- package/dist/serializers/index.js +7 -15
- package/dist/serializers/index.js.map +1 -1
- package/dist/serializers/serializer.interface.d.ts +49 -16
- package/dist/serializers/serializer.interface.js +41 -15
- package/dist/serializers/serializer.interface.js.map +1 -1
- package/dist/server/index.d.ts +2 -1
- package/dist/server/index.js +3 -15
- package/dist/server/index.js.map +1 -1
- package/dist/server/server-base.d.ts +125 -52
- package/dist/server/server-base.js +168 -57
- package/dist/server/server-base.js.map +1 -1
- package/dist/transport.component.d.ts +21 -8
- package/dist/transport.component.js +41 -18
- package/dist/transport.component.js.map +1 -1
- package/dist/transport.observer.d.ts +91 -0
- package/dist/transport.observer.js +297 -0
- package/dist/transport.observer.js.map +1 -0
- package/dist/utils/normalize-pattern.d.ts +11 -6
- package/dist/utils/normalize-pattern.js +18 -13
- package/dist/utils/normalize-pattern.js.map +1 -1
- package/package.json +58 -16
- package/dist/transport-booter.d.ts +0 -31
- package/dist/transport-booter.js +0 -117
- package/dist/transport-booter.js.map +0 -1
|
@@ -1,28 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ExecutionContext = void 0;
|
|
4
|
+
const errors_1 = require("../helpers/errors");
|
|
4
5
|
/**
|
|
5
|
-
* Unified execution context that works across HTTP, RPC, and event
|
|
6
|
+
* Unified execution context that works across HTTP, RPC, and event
|
|
7
|
+
* transports.
|
|
6
8
|
*
|
|
7
|
-
* Immutable after construction. Created via static factory methods
|
|
8
|
-
*
|
|
9
|
-
*
|
|
9
|
+
* Immutable after construction. Created via static factory methods that
|
|
10
|
+
* guarantee the transport-specific context is present. No half-built
|
|
11
|
+
* contexts, no post-construction mutation.
|
|
10
12
|
*
|
|
11
|
-
* NestJS-compatible mental model: getType() + switchToHttp/Rpc/Event
|
|
13
|
+
* NestJS-compatible mental model: `getType()` + `switchToHttp/Rpc/Event`.
|
|
12
14
|
* Cleaner construction: factory methods enforce correct state.
|
|
15
|
+
*
|
|
16
|
+
* @public
|
|
13
17
|
*/
|
|
14
18
|
class ExecutionContext {
|
|
19
|
+
type;
|
|
20
|
+
args;
|
|
21
|
+
handler;
|
|
22
|
+
controllerClass;
|
|
23
|
+
httpCtx;
|
|
24
|
+
rpcCtx;
|
|
25
|
+
eventCtx;
|
|
15
26
|
constructor(type, args, handler, controllerClass, contexts) {
|
|
16
27
|
this.type = type;
|
|
17
28
|
this.args = [...args];
|
|
18
29
|
this.handler = handler;
|
|
19
30
|
this.controllerClass = controllerClass;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
31
|
+
if (contexts.http !== undefined)
|
|
32
|
+
this.httpCtx = contexts.http;
|
|
33
|
+
if (contexts.rpc !== undefined)
|
|
34
|
+
this.rpcCtx = contexts.rpc;
|
|
35
|
+
if (contexts.event !== undefined)
|
|
36
|
+
this.eventCtx = contexts.event;
|
|
23
37
|
}
|
|
24
38
|
/**
|
|
25
39
|
* Create an HTTP execution context.
|
|
40
|
+
*
|
|
41
|
+
* @public
|
|
26
42
|
*/
|
|
27
43
|
static forHttp(args, handler, controllerClass, httpCtx) {
|
|
28
44
|
return new ExecutionContext('http', args, handler, controllerClass, {
|
|
@@ -31,6 +47,8 @@ class ExecutionContext {
|
|
|
31
47
|
}
|
|
32
48
|
/**
|
|
33
49
|
* Create an RPC execution context (gRPC, request/response patterns).
|
|
50
|
+
*
|
|
51
|
+
* @public
|
|
34
52
|
*/
|
|
35
53
|
static forRpc(args, handler, controllerClass, rpcCtx) {
|
|
36
54
|
return new ExecutionContext('rpc', args, handler, controllerClass, {
|
|
@@ -39,6 +57,8 @@ class ExecutionContext {
|
|
|
39
57
|
}
|
|
40
58
|
/**
|
|
41
59
|
* Create an event execution context (Kafka, RabbitMQ, MQTT, NATS).
|
|
60
|
+
*
|
|
61
|
+
* @public
|
|
42
62
|
*/
|
|
43
63
|
static forEvent(args, handler, controllerClass, eventCtx) {
|
|
44
64
|
return new ExecutionContext('event', args, handler, controllerClass, {
|
|
@@ -47,61 +67,86 @@ class ExecutionContext {
|
|
|
47
67
|
}
|
|
48
68
|
/**
|
|
49
69
|
* Returns the transport type handling this request.
|
|
70
|
+
*
|
|
71
|
+
* @public
|
|
50
72
|
*/
|
|
51
73
|
getType() {
|
|
52
74
|
return this.type;
|
|
53
75
|
}
|
|
54
76
|
/**
|
|
55
77
|
* Returns the controller class the handler belongs to.
|
|
78
|
+
*
|
|
79
|
+
* @experimental The generic parameter is asserted, not inferred.
|
|
80
|
+
* Callers must verify the resulting class shape themselves.
|
|
81
|
+
* @typeParam T - Caller-asserted instance type.
|
|
56
82
|
*/
|
|
57
83
|
getClass() {
|
|
58
84
|
return this.controllerClass;
|
|
59
85
|
}
|
|
60
86
|
/**
|
|
61
87
|
* Returns the handler function that will be invoked.
|
|
88
|
+
*
|
|
89
|
+
* @public
|
|
62
90
|
*/
|
|
63
91
|
getHandler() {
|
|
64
92
|
return this.handler;
|
|
65
93
|
}
|
|
66
94
|
/**
|
|
67
95
|
* Returns a copy of the arguments array.
|
|
96
|
+
*
|
|
97
|
+
* @experimental Callers assert the tuple shape; no runtime check is
|
|
98
|
+
* performed.
|
|
99
|
+
* @typeParam T - Caller-asserted tuple type.
|
|
68
100
|
*/
|
|
69
101
|
getArgs() {
|
|
70
102
|
return [...this.args];
|
|
71
103
|
}
|
|
72
104
|
/**
|
|
73
105
|
* Returns a specific argument by index.
|
|
106
|
+
*
|
|
107
|
+
* @experimental Callers assert the value type; no runtime check is
|
|
108
|
+
* performed.
|
|
109
|
+
* @typeParam T - Caller-asserted argument type.
|
|
74
110
|
*/
|
|
75
111
|
getArgByIndex(index) {
|
|
76
112
|
return this.args[index];
|
|
77
113
|
}
|
|
78
114
|
/**
|
|
79
|
-
* Switch to HTTP context.
|
|
80
|
-
*
|
|
115
|
+
* Switch to HTTP context. Throws if the current type is not `http`
|
|
116
|
+
* or the context is missing.
|
|
117
|
+
*
|
|
118
|
+
* @public
|
|
119
|
+
* @throws TransportError When the current transport type is not HTTP.
|
|
81
120
|
*/
|
|
82
121
|
switchToHttp() {
|
|
83
122
|
if (this.type !== 'http' || !this.httpCtx) {
|
|
84
|
-
throw new
|
|
123
|
+
throw new errors_1.TransportError(`Cannot switch to HTTP context: current transport type is "${this.type}"`);
|
|
85
124
|
}
|
|
86
125
|
return this.httpCtx;
|
|
87
126
|
}
|
|
88
127
|
/**
|
|
89
|
-
* Switch to RPC context.
|
|
90
|
-
*
|
|
128
|
+
* Switch to RPC context. Throws if the current type is not `rpc` or
|
|
129
|
+
* the context is missing.
|
|
130
|
+
*
|
|
131
|
+
* @public
|
|
132
|
+
* @throws TransportError When the current transport type is not RPC.
|
|
91
133
|
*/
|
|
92
134
|
switchToRpc() {
|
|
93
135
|
if (this.type !== 'rpc' || !this.rpcCtx) {
|
|
94
|
-
throw new
|
|
136
|
+
throw new errors_1.TransportError(`Cannot switch to RPC context: current transport type is "${this.type}"`);
|
|
95
137
|
}
|
|
96
138
|
return this.rpcCtx;
|
|
97
139
|
}
|
|
98
140
|
/**
|
|
99
|
-
* Switch to event context.
|
|
100
|
-
*
|
|
141
|
+
* Switch to event context. Throws if the current type is not `event`
|
|
142
|
+
* or the context is missing.
|
|
143
|
+
*
|
|
144
|
+
* @public
|
|
145
|
+
* @throws TransportError When the current transport type is not event.
|
|
101
146
|
*/
|
|
102
147
|
switchToEvent() {
|
|
103
148
|
if (this.type !== 'event' || !this.eventCtx) {
|
|
104
|
-
throw new
|
|
149
|
+
throw new errors_1.TransportError(`Cannot switch to event context: current transport type is "${this.type}"`);
|
|
105
150
|
}
|
|
106
151
|
return this.eventCtx;
|
|
107
152
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execution-context.js","sourceRoot":"","sources":["../../src/context/execution-context.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"execution-context.js","sourceRoot":"","sources":["../../src/context/execution-context.ts"],"names":[],"mappings":";;;AAAA,8CAAiD;AAwDjD;;;;;;;;;;;;GAYG;AACH,MAAa,gBAAgB;IACV,IAAI,CAAc;IAClB,IAAI,CAAqB;IACzB,OAAO,CAAkB;IACzB,eAAe,CAAkB;IACjC,O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C"}
|
package/dist/context/index.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { ExecutionContext } from './execution-context';
|
|
2
|
+
export type { ContextType, ControllerClass, EventContext, HandlerFunction, HttpContext, RpcContext, } from './execution-context';
|
package/dist/context/index.js
CHANGED
|
@@ -1,18 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
|
|
3
|
+
exports.ExecutionContext = void 0;
|
|
4
|
+
var execution_context_1 = require("./execution-context");
|
|
5
|
+
Object.defineProperty(exports, "ExecutionContext", { enumerable: true, get: function () { return execution_context_1.ExecutionContext; } });
|
|
18
6
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/context/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/context/index.ts"],"names":[],"mappings":";;;AAAA,yDAAqD;AAA7C,qHAAA,gBAAgB,OAAA"}
|
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
import { MetadataAccessor } from '@loopback/metadata';
|
|
2
2
|
/**
|
|
3
|
-
* Options for
|
|
3
|
+
* Options for the `@messageHandler` and `@eventHandler` decorators.
|
|
4
4
|
* Extracted as a named type for public API stability.
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
5
7
|
*/
|
|
6
8
|
export interface HandlerOptions {
|
|
7
9
|
transport?: string;
|
|
8
10
|
extras?: Readonly<Record<string, unknown>>;
|
|
9
11
|
}
|
|
10
12
|
/**
|
|
11
|
-
* Metadata stored by
|
|
13
|
+
* Metadata stored by `@messageHandler`.
|
|
14
|
+
*
|
|
15
|
+
* Pattern is stored as a normalized string via `normalizePattern()`.
|
|
16
|
+
* Object patterns are deep-sorted by key and stringified so that the
|
|
17
|
+
* same logical pattern always produces the same string key regardless
|
|
18
|
+
* of property insertion order.
|
|
12
19
|
*
|
|
13
|
-
*
|
|
14
|
-
* Object patterns are deep-sorted by key and stringified so that
|
|
15
|
-
* the same logical pattern always produces the same string key
|
|
16
|
-
* regardless of property insertion order.
|
|
20
|
+
* @public
|
|
17
21
|
*/
|
|
18
22
|
export interface MessageHandlerMetadata {
|
|
19
23
|
pattern: string;
|
|
@@ -21,10 +25,12 @@ export interface MessageHandlerMetadata {
|
|
|
21
25
|
extras?: Readonly<Record<string, unknown>>;
|
|
22
26
|
}
|
|
23
27
|
/**
|
|
24
|
-
* Metadata stored by
|
|
28
|
+
* Metadata stored by `@eventHandler`.
|
|
25
29
|
*
|
|
26
|
-
* Pattern is stored as a normalized string via normalizePattern()
|
|
30
|
+
* Pattern is stored as a normalized string via `normalizePattern()`.
|
|
27
31
|
* Object patterns are deep-sorted by key and stringified.
|
|
32
|
+
*
|
|
33
|
+
* @public
|
|
28
34
|
*/
|
|
29
35
|
export interface EventHandlerMetadata {
|
|
30
36
|
pattern: string;
|
|
@@ -32,10 +38,14 @@ export interface EventHandlerMetadata {
|
|
|
32
38
|
extras?: Readonly<Record<string, unknown>>;
|
|
33
39
|
}
|
|
34
40
|
/**
|
|
35
|
-
* Metadata key for
|
|
41
|
+
* Metadata key for the `@messageHandler` decorator.
|
|
42
|
+
*
|
|
43
|
+
* @public
|
|
36
44
|
*/
|
|
37
45
|
export declare const MESSAGE_HANDLER_METADATA: MetadataAccessor<MessageHandlerMetadata, MethodDecorator>;
|
|
38
46
|
/**
|
|
39
|
-
* Metadata key for
|
|
47
|
+
* Metadata key for the `@eventHandler` decorator.
|
|
48
|
+
*
|
|
49
|
+
* @public
|
|
40
50
|
*/
|
|
41
51
|
export declare const EVENT_HANDLER_METADATA: MetadataAccessor<EventHandlerMetadata, MethodDecorator>;
|
|
@@ -3,11 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.EVENT_HANDLER_METADATA = exports.MESSAGE_HANDLER_METADATA = void 0;
|
|
4
4
|
const metadata_1 = require("@loopback/metadata");
|
|
5
5
|
/**
|
|
6
|
-
* Metadata key for
|
|
6
|
+
* Metadata key for the `@messageHandler` decorator.
|
|
7
|
+
*
|
|
8
|
+
* @public
|
|
7
9
|
*/
|
|
8
10
|
exports.MESSAGE_HANDLER_METADATA = metadata_1.MetadataAccessor.create('transport:message-handler');
|
|
9
11
|
/**
|
|
10
|
-
* Metadata key for
|
|
12
|
+
* Metadata key for the `@eventHandler` decorator.
|
|
13
|
+
*
|
|
14
|
+
* @public
|
|
11
15
|
*/
|
|
12
16
|
exports.EVENT_HANDLER_METADATA = metadata_1.MetadataAccessor.create('transport:event-handler');
|
|
13
17
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/decorators/constants.ts"],"names":[],"mappings":";;;AAAA,iDAAoD;
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/decorators/constants.ts"],"names":[],"mappings":";;;AAAA,iDAAoD;AA2CpD;;;;GAIG;AACU,QAAA,wBAAwB,GAAG,2BAAgB,CAAC,MAAM,CAG7D,2BAA2B,CAAC,CAAC;AAE/B;;;;GAIG;AACU,QAAA,sBAAsB,GAAG,2BAAgB,CAAC,MAAM,CAG3D,yBAAyB,CAAC,CAAC"}
|
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
import { HandlerOptions } from './constants';
|
|
1
|
+
import { type HandlerOptions } from './constants';
|
|
2
2
|
/**
|
|
3
3
|
* Mark a controller method as a fire-and-forget event handler.
|
|
4
4
|
*
|
|
5
|
-
* The transport server dispatches matching events to this method.
|
|
6
|
-
*
|
|
5
|
+
* The transport server dispatches matching events to this method. No
|
|
6
|
+
* response is sent back to the emitter.
|
|
7
7
|
*
|
|
8
|
-
* Multiple event handlers can be registered for the same pattern.
|
|
9
|
-
*
|
|
8
|
+
* Multiple event handlers can be registered for the same pattern. They
|
|
9
|
+
* are chained and all execute.
|
|
10
10
|
*
|
|
11
|
-
* @
|
|
12
|
-
* @param
|
|
11
|
+
* @public
|
|
12
|
+
* @param pattern - String or object pattern to match (e.g.
|
|
13
|
+
* `'order.placed'` or `{event: 'order.placed'}`).
|
|
14
|
+
* @param options - Optional transport name and extras.
|
|
15
|
+
* @returns A method decorator that stores the handler metadata.
|
|
13
16
|
*
|
|
14
17
|
* @example
|
|
15
18
|
* ```typescript
|
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.eventHandler =
|
|
3
|
+
exports.eventHandler = eventHandler;
|
|
4
4
|
const metadata_1 = require("@loopback/metadata");
|
|
5
5
|
const constants_1 = require("./constants");
|
|
6
6
|
const utils_1 = require("../utils");
|
|
7
7
|
/**
|
|
8
8
|
* Mark a controller method as a fire-and-forget event handler.
|
|
9
9
|
*
|
|
10
|
-
* The transport server dispatches matching events to this method.
|
|
11
|
-
*
|
|
10
|
+
* The transport server dispatches matching events to this method. No
|
|
11
|
+
* response is sent back to the emitter.
|
|
12
12
|
*
|
|
13
|
-
* Multiple event handlers can be registered for the same pattern.
|
|
14
|
-
*
|
|
13
|
+
* Multiple event handlers can be registered for the same pattern. They
|
|
14
|
+
* are chained and all execute.
|
|
15
15
|
*
|
|
16
|
-
* @
|
|
17
|
-
* @param
|
|
16
|
+
* @public
|
|
17
|
+
* @param pattern - String or object pattern to match (e.g.
|
|
18
|
+
* `'order.placed'` or `{event: 'order.placed'}`).
|
|
19
|
+
* @param options - Optional transport name and extras.
|
|
20
|
+
* @returns A method decorator that stores the handler metadata.
|
|
18
21
|
*
|
|
19
22
|
* @example
|
|
20
23
|
* ```typescript
|
|
@@ -32,11 +35,13 @@ const utils_1 = require("../utils");
|
|
|
32
35
|
*/
|
|
33
36
|
function eventHandler(pattern, options) {
|
|
34
37
|
const serializedPattern = (0, utils_1.normalizePattern)(pattern);
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
transport
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
const metadata = { pattern: serializedPattern };
|
|
39
|
+
if (options?.transport !== undefined) {
|
|
40
|
+
metadata.transport = options.transport;
|
|
41
|
+
}
|
|
42
|
+
if (options?.extras !== undefined) {
|
|
43
|
+
metadata.extras = options.extras;
|
|
44
|
+
}
|
|
45
|
+
return metadata_1.MethodDecoratorFactory.createDecorator(constants_1.EVENT_HANDLER_METADATA, metadata);
|
|
40
46
|
}
|
|
41
|
-
exports.eventHandler = eventHandler;
|
|
42
47
|
//# sourceMappingURL=event-handler.decorator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-handler.decorator.js","sourceRoot":"","sources":["../../src/decorators/event-handler.decorator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"event-handler.decorator.js","sourceRoot":"","sources":["../../src/decorators/event-handler.decorator.ts"],"names":[],"mappings":";;AAqCA,oCAkBC;AAvDD,iDAA0D;AAC1D,2CAIqB;AACrB,oCAA0C;AAE1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,SAAgB,YAAY,CAC1B,OAAyC,EACzC,OAAwB;IAExB,MAAM,iBAAiB,GAAG,IAAA,wBAAgB,EAAC,OAAO,CAAC,CAAC;IAEpD,MAAM,QAAQ,GAAyB,EAAC,OAAO,EAAE,iBAAiB,EAAC,CAAC;IACpE,IAAI,OAAO,EAAE,SAAS,KAAK,SAAS,EAAE,CAAC;QACrC,QAAQ,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;IACzC,CAAC;IACD,IAAI,OAAO,EAAE,MAAM,KAAK,SAAS,EAAE,CAAC;QAClC,QAAQ,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IACnC,CAAC;IAED,OAAO,iCAAsB,CAAC,eAAe,CAC3C,kCAAsB,EACtB,QAAQ,CACT,CAAC;AACJ,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
1
|
+
export { MESSAGE_HANDLER_METADATA, EVENT_HANDLER_METADATA } from './constants';
|
|
2
|
+
export type { HandlerOptions, MessageHandlerMetadata, EventHandlerMetadata, } from './constants';
|
|
3
|
+
export { messageHandler } from './message-handler.decorator';
|
|
4
|
+
export { eventHandler } from './event-handler.decorator';
|
|
5
|
+
export { payload, transportCtx } from './payload.decorator';
|
package/dist/decorators/index.js
CHANGED
|
@@ -1,21 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
3
|
+
exports.transportCtx = exports.payload = exports.eventHandler = exports.messageHandler = exports.EVENT_HANDLER_METADATA = exports.MESSAGE_HANDLER_METADATA = void 0;
|
|
4
|
+
var constants_1 = require("./constants");
|
|
5
|
+
Object.defineProperty(exports, "MESSAGE_HANDLER_METADATA", { enumerable: true, get: function () { return constants_1.MESSAGE_HANDLER_METADATA; } });
|
|
6
|
+
Object.defineProperty(exports, "EVENT_HANDLER_METADATA", { enumerable: true, get: function () { return constants_1.EVENT_HANDLER_METADATA; } });
|
|
7
|
+
var message_handler_decorator_1 = require("./message-handler.decorator");
|
|
8
|
+
Object.defineProperty(exports, "messageHandler", { enumerable: true, get: function () { return message_handler_decorator_1.messageHandler; } });
|
|
9
|
+
var event_handler_decorator_1 = require("./event-handler.decorator");
|
|
10
|
+
Object.defineProperty(exports, "eventHandler", { enumerable: true, get: function () { return event_handler_decorator_1.eventHandler; } });
|
|
11
|
+
var payload_decorator_1 = require("./payload.decorator");
|
|
12
|
+
Object.defineProperty(exports, "payload", { enumerable: true, get: function () { return payload_decorator_1.payload; } });
|
|
13
|
+
Object.defineProperty(exports, "transportCtx", { enumerable: true, get: function () { return payload_decorator_1.transportCtx; } });
|
|
21
14
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":";;;AAAA,yCAA6E;AAArE,qHAAA,wBAAwB,OAAA;AAAE,mHAAA,sBAAsB,OAAA;AAMxD,yEAA2D;AAAnD,2HAAA,cAAc,OAAA;AACtB,qEAAuD;AAA/C,uHAAA,YAAY,OAAA;AACpB,yDAA0D;AAAlD,4GAAA,OAAO,OAAA;AAAE,iHAAA,YAAY,OAAA"}
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import { HandlerOptions } from './constants';
|
|
1
|
+
import { type HandlerOptions } from './constants';
|
|
2
2
|
/**
|
|
3
3
|
* Mark a controller method as a request/response message handler.
|
|
4
4
|
*
|
|
5
|
-
* The transport server dispatches matching messages to this method
|
|
6
|
-
*
|
|
5
|
+
* The transport server dispatches matching messages to this method and
|
|
6
|
+
* returns the result to the caller.
|
|
7
7
|
*
|
|
8
|
-
* @
|
|
9
|
-
* @param
|
|
8
|
+
* @public
|
|
9
|
+
* @param pattern - String or object pattern to match (e.g. `'order.get'`
|
|
10
|
+
* or `{cmd: 'order.get'}`).
|
|
11
|
+
* @param options - Optional transport name and extras.
|
|
12
|
+
* @returns A method decorator that stores the handler metadata.
|
|
10
13
|
*
|
|
11
14
|
* @example
|
|
12
15
|
* ```typescript
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.messageHandler =
|
|
3
|
+
exports.messageHandler = messageHandler;
|
|
4
4
|
const metadata_1 = require("@loopback/metadata");
|
|
5
5
|
const constants_1 = require("./constants");
|
|
6
6
|
const utils_1 = require("../utils");
|
|
7
7
|
/**
|
|
8
8
|
* Mark a controller method as a request/response message handler.
|
|
9
9
|
*
|
|
10
|
-
* The transport server dispatches matching messages to this method
|
|
11
|
-
*
|
|
10
|
+
* The transport server dispatches matching messages to this method and
|
|
11
|
+
* returns the result to the caller.
|
|
12
12
|
*
|
|
13
|
-
* @
|
|
14
|
-
* @param
|
|
13
|
+
* @public
|
|
14
|
+
* @param pattern - String or object pattern to match (e.g. `'order.get'`
|
|
15
|
+
* or `{cmd: 'order.get'}`).
|
|
16
|
+
* @param options - Optional transport name and extras.
|
|
17
|
+
* @returns A method decorator that stores the handler metadata.
|
|
15
18
|
*
|
|
16
19
|
* @example
|
|
17
20
|
* ```typescript
|
|
@@ -30,11 +33,13 @@ const utils_1 = require("../utils");
|
|
|
30
33
|
*/
|
|
31
34
|
function messageHandler(pattern, options) {
|
|
32
35
|
const serializedPattern = (0, utils_1.normalizePattern)(pattern);
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
transport
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
const metadata = { pattern: serializedPattern };
|
|
37
|
+
if (options?.transport !== undefined) {
|
|
38
|
+
metadata.transport = options.transport;
|
|
39
|
+
}
|
|
40
|
+
if (options?.extras !== undefined) {
|
|
41
|
+
metadata.extras = options.extras;
|
|
42
|
+
}
|
|
43
|
+
return metadata_1.MethodDecoratorFactory.createDecorator(constants_1.MESSAGE_HANDLER_METADATA, metadata);
|
|
38
44
|
}
|
|
39
|
-
exports.messageHandler = messageHandler;
|
|
40
45
|
//# sourceMappingURL=message-handler.decorator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message-handler.decorator.js","sourceRoot":"","sources":["../../src/decorators/message-handler.decorator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"message-handler.decorator.js","sourceRoot":"","sources":["../../src/decorators/message-handler.decorator.ts"],"names":[],"mappings":";;AAmCA,wCAkBC;AArDD,iDAA0D;AAC1D,2CAIqB;AACrB,oCAA0C;AAE1C;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,SAAgB,cAAc,CAC5B,OAAyC,EACzC,OAAwB;IAExB,MAAM,iBAAiB,GAAG,IAAA,wBAAgB,EAAC,OAAO,CAAC,CAAC;IAEpD,MAAM,QAAQ,GAA2B,EAAC,OAAO,EAAE,iBAAiB,EAAC,CAAC;IACtE,IAAI,OAAO,EAAE,SAAS,KAAK,SAAS,EAAE,CAAC;QACrC,QAAQ,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;IACzC,CAAC;IACD,IAAI,OAAO,EAAE,MAAM,KAAK,SAAS,EAAE,CAAC;QAClC,QAAQ,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IACnC,CAAC;IAED,OAAO,iCAAsB,CAAC,eAAe,CAC3C,oCAAwB,EACxB,QAAQ,CACT,CAAC;AACJ,CAAC"}
|
|
@@ -1,22 +1,31 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Parameter decorator that injects the message payload.
|
|
3
3
|
*
|
|
4
|
+
* @public
|
|
5
|
+
* @returns The `@inject` decorator bound to
|
|
6
|
+
* `TransportBindings.CURRENT_PAYLOAD`.
|
|
7
|
+
*
|
|
4
8
|
* @example
|
|
5
9
|
* ```typescript
|
|
6
10
|
* @eventHandler('order.placed')
|
|
7
11
|
* async handle(@payload() data: OrderDto): Promise<void> { ... }
|
|
8
12
|
* ```
|
|
9
13
|
*/
|
|
10
|
-
export declare function payload(): (target: Object, member: string | undefined, methodDescriptorOrParameterIndex?:
|
|
14
|
+
export declare function payload(): (target: Object, member: string | undefined, methodDescriptorOrParameterIndex?: TypedPropertyDescriptor<import("@loopback/context").BoundValue> | number) => void;
|
|
11
15
|
/**
|
|
12
16
|
* Parameter decorator that injects the transport-specific context.
|
|
13
17
|
*
|
|
14
18
|
* The context type depends on the transport:
|
|
15
|
-
*
|
|
16
|
-
* -
|
|
17
|
-
* -
|
|
18
|
-
* -
|
|
19
|
-
* -
|
|
19
|
+
*
|
|
20
|
+
* - Kafka: `KafkaContext` (topic, partition, offset, consumer)
|
|
21
|
+
* - RabbitMQ: `RmqContext` (channel, message, pattern)
|
|
22
|
+
* - gRPC: `GrpcContext` (metadata, call)
|
|
23
|
+
* - MQTT: `MqttContext` (topic, packet)
|
|
24
|
+
* - NATS: `NatsContext` (subject, headers)
|
|
25
|
+
*
|
|
26
|
+
* @public
|
|
27
|
+
* @returns The `@inject` decorator bound to
|
|
28
|
+
* `TransportBindings.CURRENT_CONTEXT`.
|
|
20
29
|
*
|
|
21
30
|
* @example
|
|
22
31
|
* ```typescript
|
|
@@ -27,4 +36,4 @@ export declare function payload(): (target: Object, member: string | undefined,
|
|
|
27
36
|
* ): Promise<void> { ... }
|
|
28
37
|
* ```
|
|
29
38
|
*/
|
|
30
|
-
export declare function transportCtx(): (target: Object, member: string | undefined, methodDescriptorOrParameterIndex?:
|
|
39
|
+
export declare function transportCtx(): (target: Object, member: string | undefined, methodDescriptorOrParameterIndex?: TypedPropertyDescriptor<import("@loopback/context").BoundValue> | number) => void;
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.payload = payload;
|
|
4
|
+
exports.transportCtx = transportCtx;
|
|
4
5
|
const core_1 = require("@loopback/core");
|
|
5
6
|
const keys_1 = require("../keys");
|
|
6
7
|
/**
|
|
7
8
|
* Parameter decorator that injects the message payload.
|
|
8
9
|
*
|
|
10
|
+
* @public
|
|
11
|
+
* @returns The `@inject` decorator bound to
|
|
12
|
+
* `TransportBindings.CURRENT_PAYLOAD`.
|
|
13
|
+
*
|
|
9
14
|
* @example
|
|
10
15
|
* ```typescript
|
|
11
16
|
* @eventHandler('order.placed')
|
|
@@ -15,16 +20,20 @@ const keys_1 = require("../keys");
|
|
|
15
20
|
function payload() {
|
|
16
21
|
return (0, core_1.inject)(keys_1.TransportBindings.CURRENT_PAYLOAD);
|
|
17
22
|
}
|
|
18
|
-
exports.payload = payload;
|
|
19
23
|
/**
|
|
20
24
|
* Parameter decorator that injects the transport-specific context.
|
|
21
25
|
*
|
|
22
26
|
* The context type depends on the transport:
|
|
23
|
-
*
|
|
24
|
-
* -
|
|
25
|
-
* -
|
|
26
|
-
* -
|
|
27
|
-
* -
|
|
27
|
+
*
|
|
28
|
+
* - Kafka: `KafkaContext` (topic, partition, offset, consumer)
|
|
29
|
+
* - RabbitMQ: `RmqContext` (channel, message, pattern)
|
|
30
|
+
* - gRPC: `GrpcContext` (metadata, call)
|
|
31
|
+
* - MQTT: `MqttContext` (topic, packet)
|
|
32
|
+
* - NATS: `NatsContext` (subject, headers)
|
|
33
|
+
*
|
|
34
|
+
* @public
|
|
35
|
+
* @returns The `@inject` decorator bound to
|
|
36
|
+
* `TransportBindings.CURRENT_CONTEXT`.
|
|
28
37
|
*
|
|
29
38
|
* @example
|
|
30
39
|
* ```typescript
|
|
@@ -38,5 +47,4 @@ exports.payload = payload;
|
|
|
38
47
|
function transportCtx() {
|
|
39
48
|
return (0, core_1.inject)(keys_1.TransportBindings.CURRENT_CONTEXT);
|
|
40
49
|
}
|
|
41
|
-
exports.transportCtx = transportCtx;
|
|
42
50
|
//# sourceMappingURL=payload.decorator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"payload.decorator.js","sourceRoot":"","sources":["../../src/decorators/payload.decorator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"payload.decorator.js","sourceRoot":"","sources":["../../src/decorators/payload.decorator.ts"],"names":[],"mappings":";;AAgBA,0BAEC;AA0BD,oCAEC;AA9CD,yCAAsC;AACtC,kCAA0C;AAE1C;;;;;;;;;;;;GAYG;AACH,SAAgB,OAAO;IACrB,OAAO,IAAA,aAAM,EAAC,wBAAiB,CAAC,eAAe,CAAC,CAAC;AACnD,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,SAAgB,YAAY;IAC1B,OAAO,IAAA,aAAM,EAAC,wBAAiB,CAAC,eAAe,CAAC,CAAC;AACnD,CAAC"}
|