@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
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import type { TransportServer } from '../interfaces';
|
|
2
|
+
import type { Deserializer, Serializer } from '../serializers';
|
|
3
|
+
import type { HandlerDiscoverer } from './handler-discoverer';
|
|
4
|
+
import type { HandlerKind } from './handler-kind';
|
|
5
|
+
import type { RegisteredHandler } from './registered-handler';
|
|
6
|
+
/**
|
|
7
|
+
* Internal record describing a tag-discovered serializer binding. The
|
|
8
|
+
* `transport` field is `undefined` for generic bindings (no
|
|
9
|
+
* `TRANSPORT_NAME_TAG`) and the transport name string for
|
|
10
|
+
* transport-scoped bindings.
|
|
11
|
+
*
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
export interface DiscoveredSerializer {
|
|
15
|
+
readonly instance: Serializer;
|
|
16
|
+
readonly transport: string | undefined;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Internal record describing a tag-discovered deserializer binding.
|
|
20
|
+
* See {@link DiscoveredSerializer}.
|
|
21
|
+
*
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
export interface DiscoveredDeserializer {
|
|
25
|
+
readonly instance: Deserializer;
|
|
26
|
+
readonly transport: string | undefined;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Universal discovery service for the transport-core handler graph.
|
|
30
|
+
*
|
|
31
|
+
* Bound at `TransportBindings.DISCOVERY_SERVICE` and populated by the
|
|
32
|
+
* transport lifecycle observer after discovery and wrapping complete.
|
|
33
|
+
* Cross-cutting plugins inject this service to enumerate every handler
|
|
34
|
+
* the application contains, regardless of which {@link HandlerDiscoverer}
|
|
35
|
+
* found it or which {@link TransportServer} will serve it.
|
|
36
|
+
*
|
|
37
|
+
* Equivalent in concept to NestJS's `DiscoveryService` from
|
|
38
|
+
* `@nestjs/core`.
|
|
39
|
+
*
|
|
40
|
+
* The service stores an immutable snapshot. Every accessor returns a
|
|
41
|
+
* defensive copy so callers cannot mutate internal state.
|
|
42
|
+
*
|
|
43
|
+
* @public
|
|
44
|
+
*/
|
|
45
|
+
export declare class DiscoveryService {
|
|
46
|
+
private handlers;
|
|
47
|
+
private discoverers;
|
|
48
|
+
private servers;
|
|
49
|
+
private serializerEntries;
|
|
50
|
+
private deserializerEntries;
|
|
51
|
+
/**
|
|
52
|
+
* Every handler discovered at boot.
|
|
53
|
+
*
|
|
54
|
+
* @public
|
|
55
|
+
* @returns Frozen, defensively-copied snapshot of all registered
|
|
56
|
+
* handlers.
|
|
57
|
+
*/
|
|
58
|
+
getHandlers(): readonly RegisteredHandler[];
|
|
59
|
+
/**
|
|
60
|
+
* Handlers bound to a specific transport server (e.g. `'kafka'`,
|
|
61
|
+
* `'redis-pubsub'`).
|
|
62
|
+
*
|
|
63
|
+
* @public
|
|
64
|
+
* @param transport - Transport server tag.
|
|
65
|
+
*/
|
|
66
|
+
getHandlersForTransport(transport: string): readonly RegisteredHandler[];
|
|
67
|
+
/**
|
|
68
|
+
* Handlers of a given kind.
|
|
69
|
+
*
|
|
70
|
+
* @public
|
|
71
|
+
* @param kind - `'request'` or `'event'`.
|
|
72
|
+
*/
|
|
73
|
+
getHandlersByKind(kind: HandlerKind): readonly RegisteredHandler[];
|
|
74
|
+
/**
|
|
75
|
+
* Handlers produced by a specific discoverer (by
|
|
76
|
+
* `HandlerDiscoverer.id`).
|
|
77
|
+
*
|
|
78
|
+
* @public
|
|
79
|
+
* @param discovererId - Stable id of the discoverer (e.g. `'message'`).
|
|
80
|
+
*/
|
|
81
|
+
getHandlersByDiscoverer(discovererId: string): readonly RegisteredHandler[];
|
|
82
|
+
/**
|
|
83
|
+
* All bound `HandlerDiscoverer` instances (default + plugin-contributed).
|
|
84
|
+
*
|
|
85
|
+
* @public
|
|
86
|
+
*/
|
|
87
|
+
getDiscoverers(): readonly HandlerDiscoverer[];
|
|
88
|
+
/**
|
|
89
|
+
* All bound `TransportServer` instances.
|
|
90
|
+
*
|
|
91
|
+
* @public
|
|
92
|
+
*/
|
|
93
|
+
getTransportServers(): readonly TransportServer[];
|
|
94
|
+
/**
|
|
95
|
+
* All bound `Serializer` instances discovered by tag at boot.
|
|
96
|
+
*
|
|
97
|
+
* Includes both generic and transport-scoped bindings. Use
|
|
98
|
+
* {@link getSerializerForTransport} to resolve which serializer a
|
|
99
|
+
* specific transport server would use.
|
|
100
|
+
*
|
|
101
|
+
* @public
|
|
102
|
+
*/
|
|
103
|
+
getSerializers(): readonly Serializer[];
|
|
104
|
+
/**
|
|
105
|
+
* All bound `Deserializer` instances discovered by tag at boot.
|
|
106
|
+
*
|
|
107
|
+
* Includes both generic and transport-scoped bindings. Use
|
|
108
|
+
* {@link getDeserializerForTransport} to resolve which deserializer
|
|
109
|
+
* a specific transport server would use.
|
|
110
|
+
*
|
|
111
|
+
* @public
|
|
112
|
+
*/
|
|
113
|
+
getDeserializers(): readonly Deserializer[];
|
|
114
|
+
/**
|
|
115
|
+
* Resolve the serializer that would be used by a server with the
|
|
116
|
+
* given transport name, applying the same transport-scoped \> generic
|
|
117
|
+
* precedence as `ServerBase.resolveSerializer`.
|
|
118
|
+
*
|
|
119
|
+
* Returns `undefined` if no tagged binding exists, in which case the
|
|
120
|
+
* subclass default on the server would be used.
|
|
121
|
+
*
|
|
122
|
+
* @public
|
|
123
|
+
* @param transport - Transport name tag (e.g. `'kafka'`).
|
|
124
|
+
*/
|
|
125
|
+
getSerializerForTransport(transport: string): Serializer | undefined;
|
|
126
|
+
/**
|
|
127
|
+
* Resolve the deserializer that would be used by a server with the
|
|
128
|
+
* given transport name. See {@link getSerializerForTransport} for
|
|
129
|
+
* precedence rules.
|
|
130
|
+
*
|
|
131
|
+
* @public
|
|
132
|
+
* @param transport - Transport name tag (e.g. `'kafka'`).
|
|
133
|
+
*/
|
|
134
|
+
getDeserializerForTransport(transport: string): Deserializer | undefined;
|
|
135
|
+
/**
|
|
136
|
+
* Replace the service's internal snapshot. Called by the transport
|
|
137
|
+
* lifecycle observer after discovery and handler wrapping complete.
|
|
138
|
+
*
|
|
139
|
+
* @internal Package-internal contract between the lifecycle observer
|
|
140
|
+
* and the service. Not part of the consumer-facing API.
|
|
141
|
+
*/
|
|
142
|
+
_populate(handlers: readonly RegisteredHandler[], discoverers: readonly HandlerDiscoverer[], servers: readonly TransportServer[], serializers?: readonly DiscoveredSerializer[], deserializers?: readonly DiscoveredDeserializer[]): void;
|
|
143
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.DiscoveryService = void 0;
|
|
10
|
+
const core_1 = require("@loopback/core");
|
|
11
|
+
/**
|
|
12
|
+
* Universal discovery service for the transport-core handler graph.
|
|
13
|
+
*
|
|
14
|
+
* Bound at `TransportBindings.DISCOVERY_SERVICE` and populated by the
|
|
15
|
+
* transport lifecycle observer after discovery and wrapping complete.
|
|
16
|
+
* Cross-cutting plugins inject this service to enumerate every handler
|
|
17
|
+
* the application contains, regardless of which {@link HandlerDiscoverer}
|
|
18
|
+
* found it or which {@link TransportServer} will serve it.
|
|
19
|
+
*
|
|
20
|
+
* Equivalent in concept to NestJS's `DiscoveryService` from
|
|
21
|
+
* `@nestjs/core`.
|
|
22
|
+
*
|
|
23
|
+
* The service stores an immutable snapshot. Every accessor returns a
|
|
24
|
+
* defensive copy so callers cannot mutate internal state.
|
|
25
|
+
*
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
let DiscoveryService = class DiscoveryService {
|
|
29
|
+
handlers = Object.freeze([]);
|
|
30
|
+
discoverers = Object.freeze([]);
|
|
31
|
+
servers = Object.freeze([]);
|
|
32
|
+
serializerEntries = Object.freeze([]);
|
|
33
|
+
deserializerEntries = Object.freeze([]);
|
|
34
|
+
/**
|
|
35
|
+
* Every handler discovered at boot.
|
|
36
|
+
*
|
|
37
|
+
* @public
|
|
38
|
+
* @returns Frozen, defensively-copied snapshot of all registered
|
|
39
|
+
* handlers.
|
|
40
|
+
*/
|
|
41
|
+
getHandlers() {
|
|
42
|
+
return Object.freeze(this.handlers.slice());
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Handlers bound to a specific transport server (e.g. `'kafka'`,
|
|
46
|
+
* `'redis-pubsub'`).
|
|
47
|
+
*
|
|
48
|
+
* @public
|
|
49
|
+
* @param transport - Transport server tag.
|
|
50
|
+
*/
|
|
51
|
+
getHandlersForTransport(transport) {
|
|
52
|
+
return Object.freeze(this.handlers.filter(h => h.transport === transport));
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Handlers of a given kind.
|
|
56
|
+
*
|
|
57
|
+
* @public
|
|
58
|
+
* @param kind - `'request'` or `'event'`.
|
|
59
|
+
*/
|
|
60
|
+
getHandlersByKind(kind) {
|
|
61
|
+
return Object.freeze(this.handlers.filter(h => h.kind === kind));
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Handlers produced by a specific discoverer (by
|
|
65
|
+
* `HandlerDiscoverer.id`).
|
|
66
|
+
*
|
|
67
|
+
* @public
|
|
68
|
+
* @param discovererId - Stable id of the discoverer (e.g. `'message'`).
|
|
69
|
+
*/
|
|
70
|
+
getHandlersByDiscoverer(discovererId) {
|
|
71
|
+
return Object.freeze(this.handlers.filter(h => h.discovererId === discovererId));
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* All bound `HandlerDiscoverer` instances (default + plugin-contributed).
|
|
75
|
+
*
|
|
76
|
+
* @public
|
|
77
|
+
*/
|
|
78
|
+
getDiscoverers() {
|
|
79
|
+
return Object.freeze(this.discoverers.slice());
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* All bound `TransportServer` instances.
|
|
83
|
+
*
|
|
84
|
+
* @public
|
|
85
|
+
*/
|
|
86
|
+
getTransportServers() {
|
|
87
|
+
return Object.freeze(this.servers.slice());
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* All bound `Serializer` instances discovered by tag at boot.
|
|
91
|
+
*
|
|
92
|
+
* Includes both generic and transport-scoped bindings. Use
|
|
93
|
+
* {@link getSerializerForTransport} to resolve which serializer a
|
|
94
|
+
* specific transport server would use.
|
|
95
|
+
*
|
|
96
|
+
* @public
|
|
97
|
+
*/
|
|
98
|
+
getSerializers() {
|
|
99
|
+
return Object.freeze(this.serializerEntries.map(entry => entry.instance));
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* All bound `Deserializer` instances discovered by tag at boot.
|
|
103
|
+
*
|
|
104
|
+
* Includes both generic and transport-scoped bindings. Use
|
|
105
|
+
* {@link getDeserializerForTransport} to resolve which deserializer
|
|
106
|
+
* a specific transport server would use.
|
|
107
|
+
*
|
|
108
|
+
* @public
|
|
109
|
+
*/
|
|
110
|
+
getDeserializers() {
|
|
111
|
+
return Object.freeze(this.deserializerEntries.map(entry => entry.instance));
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Resolve the serializer that would be used by a server with the
|
|
115
|
+
* given transport name, applying the same transport-scoped \> generic
|
|
116
|
+
* precedence as `ServerBase.resolveSerializer`.
|
|
117
|
+
*
|
|
118
|
+
* Returns `undefined` if no tagged binding exists, in which case the
|
|
119
|
+
* subclass default on the server would be used.
|
|
120
|
+
*
|
|
121
|
+
* @public
|
|
122
|
+
* @param transport - Transport name tag (e.g. `'kafka'`).
|
|
123
|
+
*/
|
|
124
|
+
getSerializerForTransport(transport) {
|
|
125
|
+
const scoped = this.serializerEntries.find(entry => entry.transport === transport);
|
|
126
|
+
if (scoped !== undefined)
|
|
127
|
+
return scoped.instance;
|
|
128
|
+
const generic = this.serializerEntries.find(entry => entry.transport === undefined);
|
|
129
|
+
return generic?.instance;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Resolve the deserializer that would be used by a server with the
|
|
133
|
+
* given transport name. See {@link getSerializerForTransport} for
|
|
134
|
+
* precedence rules.
|
|
135
|
+
*
|
|
136
|
+
* @public
|
|
137
|
+
* @param transport - Transport name tag (e.g. `'kafka'`).
|
|
138
|
+
*/
|
|
139
|
+
getDeserializerForTransport(transport) {
|
|
140
|
+
const scoped = this.deserializerEntries.find(entry => entry.transport === transport);
|
|
141
|
+
if (scoped !== undefined)
|
|
142
|
+
return scoped.instance;
|
|
143
|
+
const generic = this.deserializerEntries.find(entry => entry.transport === undefined);
|
|
144
|
+
return generic?.instance;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Replace the service's internal snapshot. Called by the transport
|
|
148
|
+
* lifecycle observer after discovery and handler wrapping complete.
|
|
149
|
+
*
|
|
150
|
+
* @internal Package-internal contract between the lifecycle observer
|
|
151
|
+
* and the service. Not part of the consumer-facing API.
|
|
152
|
+
*/
|
|
153
|
+
_populate(handlers, discoverers, servers, serializers = [], deserializers = []) {
|
|
154
|
+
this.handlers = Object.freeze(handlers.slice());
|
|
155
|
+
this.discoverers = Object.freeze(discoverers.slice());
|
|
156
|
+
this.servers = Object.freeze(servers.slice());
|
|
157
|
+
this.serializerEntries = Object.freeze(serializers.map(entry => Object.freeze({ ...entry })));
|
|
158
|
+
this.deserializerEntries = Object.freeze(deserializers.map(entry => Object.freeze({ ...entry })));
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
exports.DiscoveryService = DiscoveryService;
|
|
162
|
+
exports.DiscoveryService = DiscoveryService = __decorate([
|
|
163
|
+
(0, core_1.injectable)({ scope: core_1.BindingScope.SINGLETON })
|
|
164
|
+
], DiscoveryService);
|
|
165
|
+
//# sourceMappingURL=discovery.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discovery.service.js","sourceRoot":"","sources":["../../src/discovery/discovery.service.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Constructor } from '@loopback/core';
|
|
2
|
+
import type { DiscoveredHandler, HandlerDiscoverer } from './handler-discoverer';
|
|
3
|
+
/**
|
|
4
|
+
* Default {@link HandlerDiscoverer} for the `@eventHandler` decorator
|
|
5
|
+
* vocabulary. Reads `EVENT_HANDLER_METADATA` from every method on the
|
|
6
|
+
* supplied controller class and emits a `DiscoveredHandler` of
|
|
7
|
+
* `kind: 'event'` for each one.
|
|
8
|
+
*
|
|
9
|
+
* Registered automatically by `TransportComponent` under the
|
|
10
|
+
* `TransportBindings.tags.HANDLER_DISCOVERER` tag. Subclass or replace
|
|
11
|
+
* this discoverer to alter how `@eventHandler` decorators are
|
|
12
|
+
* interpreted; bind under the same tag to add a new vocabulary instead.
|
|
13
|
+
*
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
export declare class EventHandlerDiscoverer implements HandlerDiscoverer {
|
|
17
|
+
readonly id = "event";
|
|
18
|
+
discover(controllerClass: Constructor<unknown>): DiscoveredHandler[];
|
|
19
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EventHandlerDiscoverer = void 0;
|
|
4
|
+
const core_1 = require("@loopback/core");
|
|
5
|
+
const decorators_1 = require("../decorators");
|
|
6
|
+
const handler_kind_1 = require("./handler-kind");
|
|
7
|
+
/**
|
|
8
|
+
* Default {@link HandlerDiscoverer} for the `@eventHandler` decorator
|
|
9
|
+
* vocabulary. Reads `EVENT_HANDLER_METADATA` from every method on the
|
|
10
|
+
* supplied controller class and emits a `DiscoveredHandler` of
|
|
11
|
+
* `kind: 'event'` for each one.
|
|
12
|
+
*
|
|
13
|
+
* Registered automatically by `TransportComponent` under the
|
|
14
|
+
* `TransportBindings.tags.HANDLER_DISCOVERER` tag. Subclass or replace
|
|
15
|
+
* this discoverer to alter how `@eventHandler` decorators are
|
|
16
|
+
* interpreted; bind under the same tag to add a new vocabulary instead.
|
|
17
|
+
*
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
class EventHandlerDiscoverer {
|
|
21
|
+
id = 'event';
|
|
22
|
+
discover(controllerClass) {
|
|
23
|
+
const methods = core_1.MetadataInspector.getAllMethodMetadata(decorators_1.EVENT_HANDLER_METADATA.key, controllerClass.prototype);
|
|
24
|
+
if (!methods)
|
|
25
|
+
return [];
|
|
26
|
+
const handlers = [];
|
|
27
|
+
for (const [methodName, metadata] of Object.entries(methods)) {
|
|
28
|
+
const options = {};
|
|
29
|
+
if (metadata.transport !== undefined) {
|
|
30
|
+
options.transport = metadata.transport;
|
|
31
|
+
}
|
|
32
|
+
if (metadata.extras !== undefined) {
|
|
33
|
+
options.extras = metadata.extras;
|
|
34
|
+
}
|
|
35
|
+
const discovered = {
|
|
36
|
+
pattern: metadata.pattern,
|
|
37
|
+
transport: metadata.transport ?? '*',
|
|
38
|
+
kind: handler_kind_1.HANDLER_KIND_EVENT,
|
|
39
|
+
methodName,
|
|
40
|
+
};
|
|
41
|
+
if (options.transport !== undefined || options.extras !== undefined) {
|
|
42
|
+
discovered.options = options;
|
|
43
|
+
}
|
|
44
|
+
handlers.push(discovered);
|
|
45
|
+
}
|
|
46
|
+
return handlers;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.EventHandlerDiscoverer = EventHandlerDiscoverer;
|
|
50
|
+
//# sourceMappingURL=event-handler-discoverer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-handler-discoverer.js","sourceRoot":"","sources":["../../src/discovery/event-handler-discoverer.ts"],"names":[],"mappings":";;;AACA,yCAAiD;AACjD,8CAIuB;AAEvB,iDAAkD;AAElD;;;;;;;;;;;;GAYG;AACH,MAAa,sBAAsB;IACxB,EAAE,GAAG,OAAO,CAAC;IAEtB,QAAQ,CAAC,eAAqC;QAC5C,MAAM,OAAO,GACX,wBAAiB,CAAC,oBAAoB,CACpC,mCAAsB,CAAC,GAAG,EAC1B,eAAe,CAAC,SAAS,CAC1B,CAAC;QACJ,IAAI,CAAC,OAAO;YAAE,OAAO,EAAE,CAAC;QAExB,MAAM,QAAQ,GAAwB,EAAE,CAAC;QACzC,KAAK,MAAM,CAAC,UAAU,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;YAC7D,MAAM,OAAO,GAAmB,EAAE,CAAC;YACnC,IAAI,QAAQ,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;gBACrC,OAAO,CAAC,SAAS,GAAG,QAAQ,CAAC,SAAS,CAAC;YACzC,CAAC;YACD,IAAI,QAAQ,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;gBAClC,OAAO,CAAC,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC;YACnC,CAAC;YAED,MAAM,UAAU,GAAsB;gBACpC,OAAO,EAAE,QAAQ,CAAC,OAAO;gBACzB,SAAS,EAAE,QAAQ,CAAC,SAAS,IAAI,GAAG;gBACpC,IAAI,EAAE,iCAAkB;gBACxB,UAAU;aACX,CAAC;YACF,IAAI,OAAO,CAAC,SAAS,KAAK,SAAS,IAAI,OAAO,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;gBACpE,UAAU,CAAC,OAAO,GAAG,OAAO,CAAC;YAC/B,CAAC;YACD,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC5B,CAAC;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF;AAlCD,wDAkCC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { Constructor } from '@loopback/core';
|
|
2
|
+
import type { HandlerOptions } from '../decorators';
|
|
3
|
+
import type { HandlerKind } from './handler-kind';
|
|
4
|
+
/**
|
|
5
|
+
* Metadata describing a single discovered transport handler. Returned by
|
|
6
|
+
* {@link HandlerDiscoverer} implementations and consumed by `HandlerRegistry`.
|
|
7
|
+
*
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export interface DiscoveredHandler {
|
|
11
|
+
/** Routing pattern; string for simple matches, object for structured matchers. */
|
|
12
|
+
pattern: string | Record<string, unknown>;
|
|
13
|
+
/** Tag of the transport server this handler is for, or `'*'` for wildcard. */
|
|
14
|
+
transport: string;
|
|
15
|
+
/** `'request'` = single-response handler; `'event'` = fire-and-forget, chainable. Plugins may use any string for custom kinds. */
|
|
16
|
+
kind: HandlerKind;
|
|
17
|
+
/** Name of the method on the controller prototype to invoke. */
|
|
18
|
+
methodName: string;
|
|
19
|
+
/** Discoverer-specific options forwarded to the registry / server. */
|
|
20
|
+
options?: HandlerOptions;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Contributes a decorator vocabulary to the transport-core handler registry.
|
|
24
|
+
* Implementations are bound with the `TransportBindings.tags.HANDLER_DISCOVERER`
|
|
25
|
+
* tag and consulted on every controller class at boot.
|
|
26
|
+
*
|
|
27
|
+
* The two built-in discoverers (`MessageHandlerDiscoverer` and
|
|
28
|
+
* `EventHandlerDiscoverer`) are registered automatically by
|
|
29
|
+
* `TransportComponent`. Plugins (gRPC routes, cron schedules, WebSocket
|
|
30
|
+
* subscriptions, etc.) can bind additional implementations under the same
|
|
31
|
+
* tag without modifying transport-core.
|
|
32
|
+
*
|
|
33
|
+
* @public
|
|
34
|
+
*/
|
|
35
|
+
export interface HandlerDiscoverer {
|
|
36
|
+
/** Stable identifier for logging / debugging (e.g. `'message'`, `'event'`, `'grpc'`). */
|
|
37
|
+
readonly id: string;
|
|
38
|
+
/**
|
|
39
|
+
* Read decorator metadata from a controller class and return its handlers.
|
|
40
|
+
*
|
|
41
|
+
* Implementations may return synchronously (`DiscoveredHandler[]`) or
|
|
42
|
+
* asynchronously (`Promise<DiscoveredHandler[]>`) to support metadata
|
|
43
|
+
* sources that require I/O (e.g. loading schemas from disk, querying a
|
|
44
|
+
* service registry). The registry awaits the result transparently, so
|
|
45
|
+
* both forms are equivalent from the caller's perspective.
|
|
46
|
+
*/
|
|
47
|
+
discover(controllerClass: Constructor<unknown>): DiscoveredHandler[] | Promise<DiscoveredHandler[]>;
|
|
48
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handler-discoverer.js","sourceRoot":"","sources":["../../src/discovery/handler-discoverer.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kind of a transport handler. The two well-known values
|
|
3
|
+
* (`'request'` and `'event'`) ship as default constants below; plugin
|
|
4
|
+
* discoverers may use any string value to declare additional kinds
|
|
5
|
+
* (e.g. `'cron'`, `'subscription'`, `'stream'`) without requiring a
|
|
6
|
+
* transport-core release.
|
|
7
|
+
*
|
|
8
|
+
* The open shape uses the `string & {}` autocomplete trick so editors
|
|
9
|
+
* still suggest the well-known values while accepting any string.
|
|
10
|
+
*
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
export type HandlerKind = 'request' | 'event' | (string & {});
|
|
14
|
+
/**
|
|
15
|
+
* Well-known kind for request/response handlers (`@messageHandler`).
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
export declare const HANDLER_KIND_REQUEST = "request";
|
|
19
|
+
/**
|
|
20
|
+
* Well-known kind for fire-and-forget chainable event handlers (`@eventHandler`).
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
export declare const HANDLER_KIND_EVENT = "event";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HANDLER_KIND_EVENT = exports.HANDLER_KIND_REQUEST = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Well-known kind for request/response handlers (`@messageHandler`).
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
exports.HANDLER_KIND_REQUEST = 'request';
|
|
9
|
+
/**
|
|
10
|
+
* Well-known kind for fire-and-forget chainable event handlers (`@eventHandler`).
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
exports.HANDLER_KIND_EVENT = 'event';
|
|
14
|
+
//# sourceMappingURL=handler-kind.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handler-kind.js","sourceRoot":"","sources":["../../src/discovery/handler-kind.ts"],"names":[],"mappings":";;;AAcA;;;GAGG;AACU,QAAA,oBAAoB,GAAG,SAAS,CAAC;AAE9C;;;GAGG;AACU,QAAA,kBAAkB,GAAG,OAAO,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type { DiscoveredHandler, HandlerDiscoverer } from './handler-discoverer';
|
|
2
|
+
export type { HandlerKind } from './handler-kind';
|
|
3
|
+
export { HANDLER_KIND_EVENT, HANDLER_KIND_REQUEST } from './handler-kind';
|
|
4
|
+
export { MessageHandlerDiscoverer } from './message-handler-discoverer';
|
|
5
|
+
export { EventHandlerDiscoverer } from './event-handler-discoverer';
|
|
6
|
+
export type { RegisteredHandler } from './registered-handler';
|
|
7
|
+
export { DiscoveryService } from './discovery.service';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DiscoveryService = exports.EventHandlerDiscoverer = exports.MessageHandlerDiscoverer = exports.HANDLER_KIND_REQUEST = exports.HANDLER_KIND_EVENT = void 0;
|
|
4
|
+
var handler_kind_1 = require("./handler-kind");
|
|
5
|
+
Object.defineProperty(exports, "HANDLER_KIND_EVENT", { enumerable: true, get: function () { return handler_kind_1.HANDLER_KIND_EVENT; } });
|
|
6
|
+
Object.defineProperty(exports, "HANDLER_KIND_REQUEST", { enumerable: true, get: function () { return handler_kind_1.HANDLER_KIND_REQUEST; } });
|
|
7
|
+
var message_handler_discoverer_1 = require("./message-handler-discoverer");
|
|
8
|
+
Object.defineProperty(exports, "MessageHandlerDiscoverer", { enumerable: true, get: function () { return message_handler_discoverer_1.MessageHandlerDiscoverer; } });
|
|
9
|
+
var event_handler_discoverer_1 = require("./event-handler-discoverer");
|
|
10
|
+
Object.defineProperty(exports, "EventHandlerDiscoverer", { enumerable: true, get: function () { return event_handler_discoverer_1.EventHandlerDiscoverer; } });
|
|
11
|
+
var discovery_service_1 = require("./discovery.service");
|
|
12
|
+
Object.defineProperty(exports, "DiscoveryService", { enumerable: true, get: function () { return discovery_service_1.DiscoveryService; } });
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/discovery/index.ts"],"names":[],"mappings":";;;AAEA,+CAAwE;AAAhE,kHAAA,kBAAkB,OAAA;AAAE,oHAAA,oBAAoB,OAAA;AAChD,2EAAsE;AAA9D,sIAAA,wBAAwB,OAAA;AAChC,uEAAkE;AAA1D,kIAAA,sBAAsB,OAAA;AAE9B,yDAAqD;AAA7C,qHAAA,gBAAgB,OAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Constructor } from '@loopback/core';
|
|
2
|
+
import type { DiscoveredHandler, HandlerDiscoverer } from './handler-discoverer';
|
|
3
|
+
/**
|
|
4
|
+
* Default {@link HandlerDiscoverer} for the `@messageHandler` decorator
|
|
5
|
+
* vocabulary. Reads `MESSAGE_HANDLER_METADATA` from every method on the
|
|
6
|
+
* supplied controller class and emits a `DiscoveredHandler` of
|
|
7
|
+
* `kind: 'request'` for each one.
|
|
8
|
+
*
|
|
9
|
+
* Registered automatically by `TransportComponent` under the
|
|
10
|
+
* `TransportBindings.tags.HANDLER_DISCOVERER` tag. Subclass or replace
|
|
11
|
+
* this discoverer to alter how `@messageHandler` decorators are
|
|
12
|
+
* interpreted; bind under the same tag to add a new vocabulary instead.
|
|
13
|
+
*
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
export declare class MessageHandlerDiscoverer implements HandlerDiscoverer {
|
|
17
|
+
readonly id = "message";
|
|
18
|
+
discover(controllerClass: Constructor<unknown>): DiscoveredHandler[];
|
|
19
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MessageHandlerDiscoverer = void 0;
|
|
4
|
+
const core_1 = require("@loopback/core");
|
|
5
|
+
const decorators_1 = require("../decorators");
|
|
6
|
+
const handler_kind_1 = require("./handler-kind");
|
|
7
|
+
/**
|
|
8
|
+
* Default {@link HandlerDiscoverer} for the `@messageHandler` decorator
|
|
9
|
+
* vocabulary. Reads `MESSAGE_HANDLER_METADATA` from every method on the
|
|
10
|
+
* supplied controller class and emits a `DiscoveredHandler` of
|
|
11
|
+
* `kind: 'request'` for each one.
|
|
12
|
+
*
|
|
13
|
+
* Registered automatically by `TransportComponent` under the
|
|
14
|
+
* `TransportBindings.tags.HANDLER_DISCOVERER` tag. Subclass or replace
|
|
15
|
+
* this discoverer to alter how `@messageHandler` decorators are
|
|
16
|
+
* interpreted; bind under the same tag to add a new vocabulary instead.
|
|
17
|
+
*
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
class MessageHandlerDiscoverer {
|
|
21
|
+
id = 'message';
|
|
22
|
+
discover(controllerClass) {
|
|
23
|
+
const methods = core_1.MetadataInspector.getAllMethodMetadata(decorators_1.MESSAGE_HANDLER_METADATA.key, controllerClass.prototype);
|
|
24
|
+
if (!methods)
|
|
25
|
+
return [];
|
|
26
|
+
const handlers = [];
|
|
27
|
+
for (const [methodName, metadata] of Object.entries(methods)) {
|
|
28
|
+
const options = {};
|
|
29
|
+
if (metadata.transport !== undefined) {
|
|
30
|
+
options.transport = metadata.transport;
|
|
31
|
+
}
|
|
32
|
+
if (metadata.extras !== undefined) {
|
|
33
|
+
options.extras = metadata.extras;
|
|
34
|
+
}
|
|
35
|
+
const discovered = {
|
|
36
|
+
pattern: metadata.pattern,
|
|
37
|
+
transport: metadata.transport ?? '*',
|
|
38
|
+
kind: handler_kind_1.HANDLER_KIND_REQUEST,
|
|
39
|
+
methodName,
|
|
40
|
+
};
|
|
41
|
+
if (options.transport !== undefined || options.extras !== undefined) {
|
|
42
|
+
discovered.options = options;
|
|
43
|
+
}
|
|
44
|
+
handlers.push(discovered);
|
|
45
|
+
}
|
|
46
|
+
return handlers;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.MessageHandlerDiscoverer = MessageHandlerDiscoverer;
|
|
50
|
+
//# sourceMappingURL=message-handler-discoverer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message-handler-discoverer.js","sourceRoot":"","sources":["../../src/discovery/message-handler-discoverer.ts"],"names":[],"mappings":";;;AACA,yCAAiD;AACjD,8CAIuB;AAEvB,iDAAoD;AAEpD;;;;;;;;;;;;GAYG;AACH,MAAa,wBAAwB;IAC1B,EAAE,GAAG,SAAS,CAAC;IAExB,QAAQ,CAAC,eAAqC;QAC5C,MAAM,OAAO,GACX,wBAAiB,CAAC,oBAAoB,CACpC,qCAAwB,CAAC,GAAG,EAC5B,eAAe,CAAC,SAAS,CAC1B,CAAC;QACJ,IAAI,CAAC,OAAO;YAAE,OAAO,EAAE,CAAC;QAExB,MAAM,QAAQ,GAAwB,EAAE,CAAC;QACzC,KAAK,MAAM,CAAC,UAAU,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;YAC7D,MAAM,OAAO,GAAmB,EAAE,CAAC;YACnC,IAAI,QAAQ,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;gBACrC,OAAO,CAAC,SAAS,GAAG,QAAQ,CAAC,SAAS,CAAC;YACzC,CAAC;YACD,IAAI,QAAQ,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;gBAClC,OAAO,CAAC,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC;YACnC,CAAC;YAED,MAAM,UAAU,GAAsB;gBACpC,OAAO,EAAE,QAAQ,CAAC,OAAO;gBACzB,SAAS,EAAE,QAAQ,CAAC,SAAS,IAAI,GAAG;gBACpC,IAAI,EAAE,mCAAoB;gBAC1B,UAAU;aACX,CAAC;YACF,IAAI,OAAO,CAAC,SAAS,KAAK,SAAS,IAAI,OAAO,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;gBACpE,UAAU,CAAC,OAAO,GAAG,OAAO,CAAC;YAC/B,CAAC;YACD,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC5B,CAAC;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF;AAlCD,4DAkCC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Constructor } from '@loopback/core';
|
|
2
|
+
import type { HandlerOptions } from '../decorators';
|
|
3
|
+
import type { MessageHandler } from '../interfaces';
|
|
4
|
+
import type { HandlerKind } from './handler-kind';
|
|
5
|
+
/**
|
|
6
|
+
* Immutable view of a transport handler that was discovered at boot.
|
|
7
|
+
* Returned by {@link DiscoveryService} for cross-cutting plugins
|
|
8
|
+
* (metrics, tracing, audit, schema generation) to enumerate the
|
|
9
|
+
* full handler graph without coupling to specific transports or
|
|
10
|
+
* decorator vocabularies.
|
|
11
|
+
*
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
export interface RegisteredHandler {
|
|
15
|
+
/** Routing pattern (string or structured object). */
|
|
16
|
+
readonly pattern: string | Record<string, unknown>;
|
|
17
|
+
/** Transport server tag this handler is bound to. */
|
|
18
|
+
readonly transport: string;
|
|
19
|
+
/** Handler kind. */
|
|
20
|
+
readonly kind: HandlerKind;
|
|
21
|
+
/** Controller class that declared this handler. */
|
|
22
|
+
readonly controllerClass: Constructor<unknown>;
|
|
23
|
+
/** Method name on the controller prototype. */
|
|
24
|
+
readonly methodName: string;
|
|
25
|
+
/** Identifier of the {@link HandlerDiscoverer} that produced this entry. */
|
|
26
|
+
readonly discovererId: string;
|
|
27
|
+
/** Discoverer-specific handler options. */
|
|
28
|
+
readonly options?: HandlerOptions;
|
|
29
|
+
/**
|
|
30
|
+
* Handler function as produced by the registry's `createHandler()`.
|
|
31
|
+
* The LB4 interceptor chain (including any `@globalInterceptor`s) runs
|
|
32
|
+
* at invocation time inside this function.
|
|
33
|
+
*/
|
|
34
|
+
readonly invoke: MessageHandler;
|
|
35
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registered-handler.js","sourceRoot":"","sources":["../../src/discovery/registered-handler.ts"],"names":[],"mappings":""}
|