@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,21 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { Application } from '@loopback/core';
|
|
2
|
+
import type { Observable } from 'rxjs';
|
|
3
|
+
import type { MessageHandler } from './message-handler.interface';
|
|
3
4
|
/**
|
|
4
5
|
* Transport connection status.
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
5
8
|
*/
|
|
6
9
|
export type TransportStatus = 'connected' | 'disconnected' | 'reconnecting' | 'error';
|
|
7
10
|
/**
|
|
8
|
-
* Interface that all transport servers must implement.
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
+
* Interface that all transport servers must implement. Each transport
|
|
12
|
+
* (Kafka, RabbitMQ, gRPC, MQTT, NATS) provides a concrete
|
|
13
|
+
* implementation.
|
|
14
|
+
*
|
|
15
|
+
* @public
|
|
11
16
|
*/
|
|
12
17
|
export interface TransportServer {
|
|
13
18
|
/**
|
|
14
19
|
* Start listening for messages.
|
|
20
|
+
*
|
|
21
|
+
* @returns Resolves once the server is ready to receive.
|
|
15
22
|
*/
|
|
16
23
|
listen(): Promise<void>;
|
|
17
24
|
/**
|
|
18
25
|
* Stop listening and close connections.
|
|
26
|
+
*
|
|
27
|
+
* @returns Resolves once the server has been torn down.
|
|
19
28
|
*/
|
|
20
29
|
close(): Promise<void>;
|
|
21
30
|
/**
|
|
@@ -23,7 +32,9 @@ export interface TransportServer {
|
|
|
23
32
|
*/
|
|
24
33
|
readonly status$: Observable<TransportStatus>;
|
|
25
34
|
/**
|
|
26
|
-
* Access the underlying native client (e.g
|
|
35
|
+
* Access the underlying native client (e.g. a KafkaJS `Consumer`).
|
|
36
|
+
*
|
|
37
|
+
* @typeParam T - Caller-asserted native client shape.
|
|
27
38
|
*/
|
|
28
39
|
unwrap<T>(): T;
|
|
29
40
|
/**
|
|
@@ -31,14 +42,29 @@ export interface TransportServer {
|
|
|
31
42
|
*/
|
|
32
43
|
addHandler(pattern: string, handler: MessageHandler): void;
|
|
33
44
|
/**
|
|
34
|
-
* Get all registered handlers. Returns a read-only view.
|
|
35
|
-
*
|
|
45
|
+
* Get all registered handlers. Returns a read-only view. Each
|
|
46
|
+
* pattern maps to an array of handlers (one for request/response,
|
|
36
47
|
* potentially many for event fan-out).
|
|
37
48
|
*/
|
|
38
49
|
getHandlers(): ReadonlyMap<string, readonly MessageHandler[]>;
|
|
39
50
|
/**
|
|
40
|
-
* Remove all registered handlers.
|
|
41
|
-
*
|
|
51
|
+
* Remove all registered handlers. Called before rebinding on
|
|
52
|
+
* restart to prevent duplicate registration.
|
|
42
53
|
*/
|
|
43
54
|
clearHandlers(): void;
|
|
55
|
+
/**
|
|
56
|
+
* Resolve the serializer/deserializer pair for this server from the app
|
|
57
|
+
* container. Precedence is transport-scoped, then generic, then the
|
|
58
|
+
* implementation default. Called by the transport lifecycle observer between
|
|
59
|
+
* `bindToServers` and `listen()`. Plugins contribute tag-based serializers
|
|
60
|
+
* via {@link SERIALIZER_TAG} / {@link DESERIALIZER_TAG}; implementation-level
|
|
61
|
+
* defaults are honored when no tagged binding matches.
|
|
62
|
+
*
|
|
63
|
+
* Implementations that do not need tag-based serializer resolution
|
|
64
|
+
* (servers that hardcode their codec) may provide a no-op implementation.
|
|
65
|
+
* Subclasses of {@link ServerBase} inherit a default implementation.
|
|
66
|
+
*
|
|
67
|
+
* @public
|
|
68
|
+
*/
|
|
69
|
+
resolveSerializer(app: Application): Promise<void>;
|
|
44
70
|
}
|
package/dist/keys.d.ts
CHANGED
|
@@ -1,30 +1,154 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { BindingKey } from '@loopback/core';
|
|
2
|
+
import type { DiscoveryService } from './discovery';
|
|
3
|
+
import type { TransportClient, TransportServer } from './interfaces';
|
|
3
4
|
import type { HandlerRegistry } from './registry';
|
|
4
5
|
/**
|
|
5
|
-
* Tag
|
|
6
|
-
*
|
|
6
|
+
* Tag attached to every transport server binding so the booter can
|
|
7
|
+
* discover servers via `app.findByTag(TRANSPORT_SERVER_TAG)`.
|
|
8
|
+
*
|
|
9
|
+
* Equivalent to `TransportBindings.tags.SERVER` — both forms are
|
|
10
|
+
* supported.
|
|
11
|
+
*
|
|
12
|
+
* @public
|
|
7
13
|
*/
|
|
8
14
|
export declare const TRANSPORT_SERVER_TAG = "transport-server";
|
|
9
15
|
/**
|
|
10
|
-
* Tag key
|
|
16
|
+
* Tag key carrying the transport name (e.g. `'kafka'`, `'rabbitmq'`)
|
|
17
|
+
* on a transport server binding. The booter reads this to route
|
|
18
|
+
* transport-specific handlers.
|
|
19
|
+
*
|
|
20
|
+
* Equivalent to `TransportBindings.tags.NAME` — both forms are
|
|
21
|
+
* supported.
|
|
22
|
+
*
|
|
23
|
+
* @public
|
|
11
24
|
*/
|
|
12
25
|
export declare const TRANSPORT_NAME_TAG = "transport";
|
|
26
|
+
/**
|
|
27
|
+
* Tag attached to every `HandlerDiscoverer` binding so the handler
|
|
28
|
+
* registry can discover them via
|
|
29
|
+
* `app.findByTag(HANDLER_DISCOVERER_TAG)`.
|
|
30
|
+
*
|
|
31
|
+
* Equivalent to `TransportBindings.tags.HANDLER_DISCOVERER` — both
|
|
32
|
+
* forms are supported.
|
|
33
|
+
*
|
|
34
|
+
* @public
|
|
35
|
+
*/
|
|
36
|
+
export declare const HANDLER_DISCOVERER_TAG = "transport-handler-discoverer";
|
|
37
|
+
/**
|
|
38
|
+
* Tag identifying bindings that contribute a
|
|
39
|
+
* {@link Serializer | `Serializer`} to the transport layer.
|
|
40
|
+
*
|
|
41
|
+
* Combine with {@link TRANSPORT_NAME_TAG} (set to a transport name
|
|
42
|
+
* string such as `'kafka'`) to scope the serializer to a specific
|
|
43
|
+
* transport. Bindings tagged with `SERIALIZER_TAG` but without a
|
|
44
|
+
* `TRANSPORT_NAME_TAG` tag are treated as generic and apply to any
|
|
45
|
+
* transport that does not have a transport-scoped match.
|
|
46
|
+
*
|
|
47
|
+
* Resolution precedence at boot (most specific wins):
|
|
48
|
+
*
|
|
49
|
+
* 1. Transport-scoped binding (`SERIALIZER_TAG` + matching
|
|
50
|
+
* `TRANSPORT_NAME_TAG`).
|
|
51
|
+
* 2. Generic binding (`SERIALIZER_TAG` only).
|
|
52
|
+
* 3. Subclass default set via the `protected serializer` field on
|
|
53
|
+
* `ServerBase`.
|
|
54
|
+
*
|
|
55
|
+
* Equivalent to `TransportBindings.tags.SERIALIZER` — both forms are
|
|
56
|
+
* supported.
|
|
57
|
+
*
|
|
58
|
+
* @public
|
|
59
|
+
*/
|
|
60
|
+
export declare const SERIALIZER_TAG = "transport-serializer";
|
|
61
|
+
/**
|
|
62
|
+
* Tag identifying bindings that contribute a
|
|
63
|
+
* {@link Deserializer | `Deserializer`} to the transport layer.
|
|
64
|
+
*
|
|
65
|
+
* See {@link SERIALIZER_TAG} for scoping rules and resolution
|
|
66
|
+
* precedence.
|
|
67
|
+
*
|
|
68
|
+
* Equivalent to `TransportBindings.tags.DESERIALIZER` — both forms are
|
|
69
|
+
* supported.
|
|
70
|
+
*
|
|
71
|
+
* @public
|
|
72
|
+
*/
|
|
73
|
+
export declare const DESERIALIZER_TAG = "transport-deserializer";
|
|
74
|
+
/**
|
|
75
|
+
* Binding keys and tag constants for the transport core.
|
|
76
|
+
*
|
|
77
|
+
* Registration helpers (`registerServer`, `registerServerClass`,
|
|
78
|
+
* `registerServerProvider`) live in `helpers/register-server.ts` and
|
|
79
|
+
* are exported from the package root.
|
|
80
|
+
*
|
|
81
|
+
* @public
|
|
82
|
+
*/
|
|
13
83
|
export declare namespace TransportBindings {
|
|
14
84
|
/**
|
|
15
|
-
*
|
|
85
|
+
* Tag values used by transport server bindings. Prefer these typed
|
|
86
|
+
* accessors over the raw string exports.
|
|
87
|
+
*
|
|
88
|
+
* @public
|
|
89
|
+
*/
|
|
90
|
+
namespace tags {
|
|
91
|
+
/**
|
|
92
|
+
* Tag attached to every transport server binding.
|
|
93
|
+
*/
|
|
94
|
+
const SERVER = "transport-server";
|
|
95
|
+
/**
|
|
96
|
+
* Tag key holding the transport name on a server binding.
|
|
97
|
+
*/
|
|
98
|
+
const NAME = "transport";
|
|
99
|
+
/**
|
|
100
|
+
* Tag attached to every `HandlerDiscoverer` binding. Plugins that
|
|
101
|
+
* contribute a custom decorator vocabulary bind their discoverer
|
|
102
|
+
* under this tag so the handler registry consults it during boot.
|
|
103
|
+
*/
|
|
104
|
+
const HANDLER_DISCOVERER = "transport-handler-discoverer";
|
|
105
|
+
/**
|
|
106
|
+
* Tag attached to every `Serializer` binding. Plugins contribute a
|
|
107
|
+
* tag-based serializer via this tag; combine with {@link NAME} to
|
|
108
|
+
* scope the serializer to a specific transport. See
|
|
109
|
+
* {@link SERIALIZER_TAG} for resolution precedence.
|
|
110
|
+
*/
|
|
111
|
+
const SERIALIZER = "transport-serializer";
|
|
112
|
+
/**
|
|
113
|
+
* Tag attached to every `Deserializer` binding. See
|
|
114
|
+
* {@link DESERIALIZER_TAG} for resolution precedence.
|
|
115
|
+
*/
|
|
116
|
+
const DESERIALIZER = "transport-deserializer";
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Binding key for the singleton handler registry that owns the
|
|
120
|
+
* mapping between message patterns and controller method handlers.
|
|
16
121
|
*/
|
|
17
122
|
const HANDLER_REGISTRY: BindingKey<HandlerRegistry>;
|
|
18
123
|
/**
|
|
19
|
-
* Binding key for the
|
|
20
|
-
*
|
|
124
|
+
* Binding key for the singleton {@link DiscoveryService}. Populated
|
|
125
|
+
* by the transport lifecycle observer after discovery and wrapping
|
|
126
|
+
* complete. Cross-cutting plugins inject this service to enumerate
|
|
127
|
+
* every handler the application contains.
|
|
128
|
+
*/
|
|
129
|
+
const DISCOVERY_SERVICE: BindingKey<DiscoveryService>;
|
|
130
|
+
/**
|
|
131
|
+
* Binding key for the current message payload. The handler registry
|
|
132
|
+
* binds this per-message inside the invocation child context.
|
|
21
133
|
*/
|
|
22
134
|
const CURRENT_PAYLOAD: BindingKey<unknown>;
|
|
23
135
|
/**
|
|
24
|
-
* Binding key for the
|
|
25
|
-
*
|
|
136
|
+
* Binding key for the transport-specific context object passed to the
|
|
137
|
+
* handler (Kafka context, RabbitMQ context, etc.). The handler
|
|
138
|
+
* registry binds this per-message inside the invocation child context.
|
|
26
139
|
*/
|
|
27
140
|
const CURRENT_CONTEXT: BindingKey<unknown>;
|
|
141
|
+
/**
|
|
142
|
+
* Controls whether boot-time binding validation throws on misconfigurations
|
|
143
|
+
* (handler references unknown transport) or emits debug logs instead.
|
|
144
|
+
*
|
|
145
|
+
* Default: `true` (throw). Set to `false` via
|
|
146
|
+
* `app.bind(TransportBindings.STRICT_BINDING).to(false)` before `app.start()`
|
|
147
|
+
* if you need to register handlers ahead of their transport servers.
|
|
148
|
+
*
|
|
149
|
+
* @public
|
|
150
|
+
*/
|
|
151
|
+
const STRICT_BINDING: BindingKey<boolean>;
|
|
28
152
|
/**
|
|
29
153
|
* Binding key prefix for transport configurations.
|
|
30
154
|
*/
|
|
@@ -39,50 +163,23 @@ export declare namespace TransportBindings {
|
|
|
39
163
|
const SERVER_PREFIX = "transport.server";
|
|
40
164
|
/**
|
|
41
165
|
* Get a binding key for a specific transport's configuration.
|
|
166
|
+
*
|
|
167
|
+
* @param transport - Transport name (e.g. `'kafka'`).
|
|
168
|
+
* @returns The typed binding key.
|
|
42
169
|
*/
|
|
43
170
|
function config(transport: string): BindingKey<Record<string, unknown>>;
|
|
44
171
|
/**
|
|
45
172
|
* Get a binding key for a specific transport's client.
|
|
173
|
+
*
|
|
174
|
+
* @param transport - Transport name (e.g. `'kafka'`).
|
|
175
|
+
* @returns The typed binding key.
|
|
46
176
|
*/
|
|
47
177
|
function client(transport: string): BindingKey<TransportClient>;
|
|
48
178
|
/**
|
|
49
179
|
* Get a binding key for a specific transport's server.
|
|
50
|
-
*/
|
|
51
|
-
function server(transport: string): BindingKey<TransportServer>;
|
|
52
|
-
/**
|
|
53
|
-
* Register a concrete transport server instance.
|
|
54
|
-
*
|
|
55
|
-
* Use when the server is already constructed (e.g., in tests or
|
|
56
|
-
* when no DI is needed).
|
|
57
|
-
*
|
|
58
|
-
* @param app - The LoopBack application
|
|
59
|
-
* @param transport - Transport name (e.g., 'kafka', 'rabbitmq')
|
|
60
|
-
* @param instance - A concrete transport server instance
|
|
61
|
-
*/
|
|
62
|
-
function registerServer(app: Application, transport: string, instance: TransportServer): Binding<TransportServer>;
|
|
63
|
-
/**
|
|
64
|
-
* Register a transport server class with the IoC container.
|
|
65
|
-
*
|
|
66
|
-
* The class is instantiated by the container, enabling constructor
|
|
67
|
-
* injection of config, clients, health checks, and other dependencies.
|
|
68
|
-
* This is the recommended registration method for transport adapters.
|
|
69
|
-
*
|
|
70
|
-
* @param app - The LoopBack application
|
|
71
|
-
* @param transport - Transport name (e.g., 'kafka', 'rabbitmq')
|
|
72
|
-
* @param serverClass - A transport server class constructor
|
|
73
|
-
*/
|
|
74
|
-
function registerServerClass(app: Application, transport: string, serverClass: Constructor<TransportServer>): Binding<TransportServer>;
|
|
75
|
-
/**
|
|
76
|
-
* Register a transport server provider.
|
|
77
180
|
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
* complex setup logic. The binding is singleton-scoped so every
|
|
81
|
-
* resolution returns the same server instance.
|
|
82
|
-
*
|
|
83
|
-
* @param app - The LoopBack application
|
|
84
|
-
* @param transport - Transport name (e.g., 'kafka', 'rabbitmq')
|
|
85
|
-
* @param serverProvider - A provider class that produces a TransportServer
|
|
181
|
+
* @param transport - Transport name (e.g. `'kafka'`).
|
|
182
|
+
* @returns The typed binding key.
|
|
86
183
|
*/
|
|
87
|
-
function
|
|
184
|
+
function server(transport: string): BindingKey<TransportServer>;
|
|
88
185
|
}
|
package/dist/keys.js
CHANGED
|
@@ -1,32 +1,156 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TransportBindings = exports.TRANSPORT_NAME_TAG = exports.TRANSPORT_SERVER_TAG = void 0;
|
|
3
|
+
exports.TransportBindings = exports.DESERIALIZER_TAG = exports.SERIALIZER_TAG = exports.HANDLER_DISCOVERER_TAG = exports.TRANSPORT_NAME_TAG = exports.TRANSPORT_SERVER_TAG = void 0;
|
|
4
4
|
const core_1 = require("@loopback/core");
|
|
5
5
|
/**
|
|
6
|
-
* Tag
|
|
7
|
-
*
|
|
6
|
+
* Tag attached to every transport server binding so the booter can
|
|
7
|
+
* discover servers via `app.findByTag(TRANSPORT_SERVER_TAG)`.
|
|
8
|
+
*
|
|
9
|
+
* Equivalent to `TransportBindings.tags.SERVER` — both forms are
|
|
10
|
+
* supported.
|
|
11
|
+
*
|
|
12
|
+
* @public
|
|
8
13
|
*/
|
|
9
14
|
exports.TRANSPORT_SERVER_TAG = 'transport-server';
|
|
10
15
|
/**
|
|
11
|
-
* Tag key
|
|
16
|
+
* Tag key carrying the transport name (e.g. `'kafka'`, `'rabbitmq'`)
|
|
17
|
+
* on a transport server binding. The booter reads this to route
|
|
18
|
+
* transport-specific handlers.
|
|
19
|
+
*
|
|
20
|
+
* Equivalent to `TransportBindings.tags.NAME` — both forms are
|
|
21
|
+
* supported.
|
|
22
|
+
*
|
|
23
|
+
* @public
|
|
12
24
|
*/
|
|
13
25
|
exports.TRANSPORT_NAME_TAG = 'transport';
|
|
26
|
+
/**
|
|
27
|
+
* Tag attached to every `HandlerDiscoverer` binding so the handler
|
|
28
|
+
* registry can discover them via
|
|
29
|
+
* `app.findByTag(HANDLER_DISCOVERER_TAG)`.
|
|
30
|
+
*
|
|
31
|
+
* Equivalent to `TransportBindings.tags.HANDLER_DISCOVERER` — both
|
|
32
|
+
* forms are supported.
|
|
33
|
+
*
|
|
34
|
+
* @public
|
|
35
|
+
*/
|
|
36
|
+
exports.HANDLER_DISCOVERER_TAG = 'transport-handler-discoverer';
|
|
37
|
+
/**
|
|
38
|
+
* Tag identifying bindings that contribute a
|
|
39
|
+
* {@link Serializer | `Serializer`} to the transport layer.
|
|
40
|
+
*
|
|
41
|
+
* Combine with {@link TRANSPORT_NAME_TAG} (set to a transport name
|
|
42
|
+
* string such as `'kafka'`) to scope the serializer to a specific
|
|
43
|
+
* transport. Bindings tagged with `SERIALIZER_TAG` but without a
|
|
44
|
+
* `TRANSPORT_NAME_TAG` tag are treated as generic and apply to any
|
|
45
|
+
* transport that does not have a transport-scoped match.
|
|
46
|
+
*
|
|
47
|
+
* Resolution precedence at boot (most specific wins):
|
|
48
|
+
*
|
|
49
|
+
* 1. Transport-scoped binding (`SERIALIZER_TAG` + matching
|
|
50
|
+
* `TRANSPORT_NAME_TAG`).
|
|
51
|
+
* 2. Generic binding (`SERIALIZER_TAG` only).
|
|
52
|
+
* 3. Subclass default set via the `protected serializer` field on
|
|
53
|
+
* `ServerBase`.
|
|
54
|
+
*
|
|
55
|
+
* Equivalent to `TransportBindings.tags.SERIALIZER` — both forms are
|
|
56
|
+
* supported.
|
|
57
|
+
*
|
|
58
|
+
* @public
|
|
59
|
+
*/
|
|
60
|
+
exports.SERIALIZER_TAG = 'transport-serializer';
|
|
61
|
+
/**
|
|
62
|
+
* Tag identifying bindings that contribute a
|
|
63
|
+
* {@link Deserializer | `Deserializer`} to the transport layer.
|
|
64
|
+
*
|
|
65
|
+
* See {@link SERIALIZER_TAG} for scoping rules and resolution
|
|
66
|
+
* precedence.
|
|
67
|
+
*
|
|
68
|
+
* Equivalent to `TransportBindings.tags.DESERIALIZER` — both forms are
|
|
69
|
+
* supported.
|
|
70
|
+
*
|
|
71
|
+
* @public
|
|
72
|
+
*/
|
|
73
|
+
exports.DESERIALIZER_TAG = 'transport-deserializer';
|
|
74
|
+
/**
|
|
75
|
+
* Binding keys and tag constants for the transport core.
|
|
76
|
+
*
|
|
77
|
+
* Registration helpers (`registerServer`, `registerServerClass`,
|
|
78
|
+
* `registerServerProvider`) live in `helpers/register-server.ts` and
|
|
79
|
+
* are exported from the package root.
|
|
80
|
+
*
|
|
81
|
+
* @public
|
|
82
|
+
*/
|
|
14
83
|
var TransportBindings;
|
|
15
84
|
(function (TransportBindings) {
|
|
16
85
|
/**
|
|
17
|
-
*
|
|
86
|
+
* Tag values used by transport server bindings. Prefer these typed
|
|
87
|
+
* accessors over the raw string exports.
|
|
88
|
+
*
|
|
89
|
+
* @public
|
|
90
|
+
*/
|
|
91
|
+
let tags;
|
|
92
|
+
(function (tags) {
|
|
93
|
+
/**
|
|
94
|
+
* Tag attached to every transport server binding.
|
|
95
|
+
*/
|
|
96
|
+
tags.SERVER = exports.TRANSPORT_SERVER_TAG;
|
|
97
|
+
/**
|
|
98
|
+
* Tag key holding the transport name on a server binding.
|
|
99
|
+
*/
|
|
100
|
+
tags.NAME = exports.TRANSPORT_NAME_TAG;
|
|
101
|
+
/**
|
|
102
|
+
* Tag attached to every `HandlerDiscoverer` binding. Plugins that
|
|
103
|
+
* contribute a custom decorator vocabulary bind their discoverer
|
|
104
|
+
* under this tag so the handler registry consults it during boot.
|
|
105
|
+
*/
|
|
106
|
+
tags.HANDLER_DISCOVERER = exports.HANDLER_DISCOVERER_TAG;
|
|
107
|
+
/**
|
|
108
|
+
* Tag attached to every `Serializer` binding. Plugins contribute a
|
|
109
|
+
* tag-based serializer via this tag; combine with {@link NAME} to
|
|
110
|
+
* scope the serializer to a specific transport. See
|
|
111
|
+
* {@link SERIALIZER_TAG} for resolution precedence.
|
|
112
|
+
*/
|
|
113
|
+
tags.SERIALIZER = exports.SERIALIZER_TAG;
|
|
114
|
+
/**
|
|
115
|
+
* Tag attached to every `Deserializer` binding. See
|
|
116
|
+
* {@link DESERIALIZER_TAG} for resolution precedence.
|
|
117
|
+
*/
|
|
118
|
+
tags.DESERIALIZER = exports.DESERIALIZER_TAG;
|
|
119
|
+
})(tags = TransportBindings.tags || (TransportBindings.tags = {}));
|
|
120
|
+
/**
|
|
121
|
+
* Binding key for the singleton handler registry that owns the
|
|
122
|
+
* mapping between message patterns and controller method handlers.
|
|
18
123
|
*/
|
|
19
124
|
TransportBindings.HANDLER_REGISTRY = core_1.BindingKey.create('transport.handler-registry');
|
|
20
125
|
/**
|
|
21
|
-
* Binding key for the
|
|
22
|
-
*
|
|
126
|
+
* Binding key for the singleton {@link DiscoveryService}. Populated
|
|
127
|
+
* by the transport lifecycle observer after discovery and wrapping
|
|
128
|
+
* complete. Cross-cutting plugins inject this service to enumerate
|
|
129
|
+
* every handler the application contains.
|
|
130
|
+
*/
|
|
131
|
+
TransportBindings.DISCOVERY_SERVICE = core_1.BindingKey.create('transport.discovery-service');
|
|
132
|
+
/**
|
|
133
|
+
* Binding key for the current message payload. The handler registry
|
|
134
|
+
* binds this per-message inside the invocation child context.
|
|
23
135
|
*/
|
|
24
136
|
TransportBindings.CURRENT_PAYLOAD = core_1.BindingKey.create('transport.current.payload');
|
|
25
137
|
/**
|
|
26
|
-
* Binding key for the
|
|
27
|
-
*
|
|
138
|
+
* Binding key for the transport-specific context object passed to the
|
|
139
|
+
* handler (Kafka context, RabbitMQ context, etc.). The handler
|
|
140
|
+
* registry binds this per-message inside the invocation child context.
|
|
28
141
|
*/
|
|
29
142
|
TransportBindings.CURRENT_CONTEXT = core_1.BindingKey.create('transport.current.context');
|
|
143
|
+
/**
|
|
144
|
+
* Controls whether boot-time binding validation throws on misconfigurations
|
|
145
|
+
* (handler references unknown transport) or emits debug logs instead.
|
|
146
|
+
*
|
|
147
|
+
* Default: `true` (throw). Set to `false` via
|
|
148
|
+
* `app.bind(TransportBindings.STRICT_BINDING).to(false)` before `app.start()`
|
|
149
|
+
* if you need to register handlers ahead of their transport servers.
|
|
150
|
+
*
|
|
151
|
+
* @public
|
|
152
|
+
*/
|
|
153
|
+
TransportBindings.STRICT_BINDING = core_1.BindingKey.create('transport.strict-binding');
|
|
30
154
|
/**
|
|
31
155
|
* Binding key prefix for transport configurations.
|
|
32
156
|
*/
|
|
@@ -41,6 +165,9 @@ var TransportBindings;
|
|
|
41
165
|
TransportBindings.SERVER_PREFIX = 'transport.server';
|
|
42
166
|
/**
|
|
43
167
|
* Get a binding key for a specific transport's configuration.
|
|
168
|
+
*
|
|
169
|
+
* @param transport - Transport name (e.g. `'kafka'`).
|
|
170
|
+
* @returns The typed binding key.
|
|
44
171
|
*/
|
|
45
172
|
function config(transport) {
|
|
46
173
|
return core_1.BindingKey.create(`${TransportBindings.CONFIG_PREFIX}.${transport}`);
|
|
@@ -48,6 +175,9 @@ var TransportBindings;
|
|
|
48
175
|
TransportBindings.config = config;
|
|
49
176
|
/**
|
|
50
177
|
* Get a binding key for a specific transport's client.
|
|
178
|
+
*
|
|
179
|
+
* @param transport - Transport name (e.g. `'kafka'`).
|
|
180
|
+
* @returns The typed binding key.
|
|
51
181
|
*/
|
|
52
182
|
function client(transport) {
|
|
53
183
|
return core_1.BindingKey.create(`${TransportBindings.CLIENT_PREFIX}.${transport}`);
|
|
@@ -55,69 +185,13 @@ var TransportBindings;
|
|
|
55
185
|
TransportBindings.client = client;
|
|
56
186
|
/**
|
|
57
187
|
* Get a binding key for a specific transport's server.
|
|
188
|
+
*
|
|
189
|
+
* @param transport - Transport name (e.g. `'kafka'`).
|
|
190
|
+
* @returns The typed binding key.
|
|
58
191
|
*/
|
|
59
192
|
function server(transport) {
|
|
60
193
|
return core_1.BindingKey.create(`${TransportBindings.SERVER_PREFIX}.${transport}`);
|
|
61
194
|
}
|
|
62
195
|
TransportBindings.server = server;
|
|
63
|
-
/**
|
|
64
|
-
* Tag a transport server binding for booter discovery.
|
|
65
|
-
*/
|
|
66
|
-
function tagServerBinding(binding, transport) {
|
|
67
|
-
return binding
|
|
68
|
-
.tag(exports.TRANSPORT_SERVER_TAG)
|
|
69
|
-
.tag({ [exports.TRANSPORT_NAME_TAG]: transport });
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Register a concrete transport server instance.
|
|
73
|
-
*
|
|
74
|
-
* Use when the server is already constructed (e.g., in tests or
|
|
75
|
-
* when no DI is needed).
|
|
76
|
-
*
|
|
77
|
-
* @param app - The LoopBack application
|
|
78
|
-
* @param transport - Transport name (e.g., 'kafka', 'rabbitmq')
|
|
79
|
-
* @param instance - A concrete transport server instance
|
|
80
|
-
*/
|
|
81
|
-
function registerServer(app, transport, instance) {
|
|
82
|
-
return tagServerBinding(app.bind(server(transport)).to(instance), transport);
|
|
83
|
-
}
|
|
84
|
-
TransportBindings.registerServer = registerServer;
|
|
85
|
-
/**
|
|
86
|
-
* Register a transport server class with the IoC container.
|
|
87
|
-
*
|
|
88
|
-
* The class is instantiated by the container, enabling constructor
|
|
89
|
-
* injection of config, clients, health checks, and other dependencies.
|
|
90
|
-
* This is the recommended registration method for transport adapters.
|
|
91
|
-
*
|
|
92
|
-
* @param app - The LoopBack application
|
|
93
|
-
* @param transport - Transport name (e.g., 'kafka', 'rabbitmq')
|
|
94
|
-
* @param serverClass - A transport server class constructor
|
|
95
|
-
*/
|
|
96
|
-
function registerServerClass(app, transport, serverClass) {
|
|
97
|
-
return tagServerBinding(app
|
|
98
|
-
.bind(server(transport))
|
|
99
|
-
.toClass(serverClass)
|
|
100
|
-
.inScope(core_1.BindingScope.SINGLETON), transport);
|
|
101
|
-
}
|
|
102
|
-
TransportBindings.registerServerClass = registerServerClass;
|
|
103
|
-
/**
|
|
104
|
-
* Register a transport server provider.
|
|
105
|
-
*
|
|
106
|
-
* Providers enable async factory patterns with full DI support.
|
|
107
|
-
* Use when server construction requires async initialization or
|
|
108
|
-
* complex setup logic. The binding is singleton-scoped so every
|
|
109
|
-
* resolution returns the same server instance.
|
|
110
|
-
*
|
|
111
|
-
* @param app - The LoopBack application
|
|
112
|
-
* @param transport - Transport name (e.g., 'kafka', 'rabbitmq')
|
|
113
|
-
* @param serverProvider - A provider class that produces a TransportServer
|
|
114
|
-
*/
|
|
115
|
-
function registerServerProvider(app, transport, serverProvider) {
|
|
116
|
-
return tagServerBinding(app
|
|
117
|
-
.bind(server(transport))
|
|
118
|
-
.toProvider(serverProvider)
|
|
119
|
-
.inScope(core_1.BindingScope.SINGLETON), transport);
|
|
120
|
-
}
|
|
121
|
-
TransportBindings.registerServerProvider = registerServerProvider;
|
|
122
196
|
})(TransportBindings || (exports.TransportBindings = TransportBindings = {}));
|
|
123
197
|
//# sourceMappingURL=keys.js.map
|
package/dist/keys.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keys.js","sourceRoot":"","sources":["../src/keys.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"keys.js","sourceRoot":"","sources":["../src/keys.ts"],"names":[],"mappings":";;;AAAA,yCAA0C;AAK1C;;;;;;;;GAQG;AACU,QAAA,oBAAoB,GAAG,kBAAkB,CAAC;AAEvD;;;;;;;;;GASG;AACU,QAAA,kBAAkB,GAAG,WAAW,CAAC;AAE9C;;;;;;;;;GASG;AACU,QAAA,sBAAsB,GAAG,8BAA8B,CAAC;AAErE;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACU,QAAA,cAAc,GAAG,sBAAsB,CAAC;AAErD;;;;;;;;;;;GAWG;AACU,QAAA,gBAAgB,GAAG,wBAAwB,CAAC;AAEzD;;;;;;;;GAQG;AACH,IAAiB,iBAAiB,CAuIjC;AAvID,WAAiB,iBAAiB;IAChC;;;;;OAKG;IACH,IAAiB,IAAI,CA+BpB;IA/BD,WAAiB,IAAI;QACnB;;WAEG;QACU,WAAM,GAAG,4BAAoB,CAAC;QAE3C;;WAEG;QACU,SAAI,GAAG,0BAAkB,CAAC;QAEvC;;;;WAIG;QACU,uBAAkB,GAAG,8BAAsB,CAAC;QAEzD;;;;;WAKG;QACU,eAAU,GAAG,sBAAc,CAAC;QAEzC;;;WAGG;QACU,iBAAY,GAAG,wBAAgB,CAAC;IAC/C,CAAC,EA/BgB,IAAI,GAAJ,sBAAI,KAAJ,sBAAI,QA+BpB;IAED;;;OAGG;IACU,kCAAgB,GAAG,iBAAU,CAAC,MAAM,CAC/C,4BAA4B,CAC7B,CAAC;IAEF;;;;;OAKG;IACU,mCAAiB,GAAG,iBAAU,CAAC,MAAM,CAChD,6BAA6B,CAC9B,CAAC;IAEF;;;OAGG;IACU,iCAAe,GAAG,iBAAU,CAAC,MAAM,CAC9C,2BAA2B,CAC5B,CAAC;IAEF;;;;OAIG;IACU,iCAAe,GAAG,iBAAU,CAAC,MAAM,CAC9C,2BAA2B,CAC5B,CAAC;IAEF;;;;;;;;;OASG;IACU,gCAAc,GAAG,iBAAU,CAAC,MAAM,CAC7C,0BAA0B,CAC3B,CAAC;IAEF;;OAEG;IACU,+BAAa,GAAG,kBAAkB,CAAC;IAEhD;;OAEG;IACU,+BAAa,GAAG,kBAAkB,CAAC;IAEhD;;OAEG;IACU,+BAAa,GAAG,kBAAkB,CAAC;IAEhD;;;;;OAKG;IACH,SAAgB,MAAM,CACpB,SAAiB;QAEjB,OAAO,iBAAU,CAAC,MAAM,CAAC,GAAG,kBAAA,aAAa,IAAI,SAAS,EAAE,CAAC,CAAC;IAC5D,CAAC;IAJe,wBAAM,SAIrB,CAAA;IAED;;;;;OAKG;IACH,SAAgB,MAAM,CAAC,SAAiB;QACtC,OAAO,iBAAU,CAAC,MAAM,CAAC,GAAG,kBAAA,aAAa,IAAI,SAAS,EAAE,CAAC,CAAC;IAC5D,CAAC;IAFe,wBAAM,SAErB,CAAA;IAED;;;;;OAKG;IACH,SAAgB,MAAM,CAAC,SAAiB;QACtC,OAAO,iBAAU,CAAC,MAAM,CAAC,GAAG,kBAAA,aAAa,IAAI,SAAS,EAAE,CAAC,CAAC;IAC5D,CAAC;IAFe,wBAAM,SAErB,CAAA;AACH,CAAC,EAvIgB,iBAAiB,iCAAjB,iBAAiB,QAuIjC"}
|