@ebarahona/loopback-transport-core 1.0.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/LICENSE +21 -0
- package/README.md +297 -0
- package/dist/client/client-proxy.d.ts +147 -0
- package/dist/client/client-proxy.js +225 -0
- package/dist/client/client-proxy.js.map +1 -0
- package/dist/client/index.d.ts +1 -0
- package/dist/client/index.js +18 -0
- package/dist/client/index.js.map +1 -0
- package/dist/context/execution-context.d.ts +102 -0
- package/dist/context/execution-context.js +110 -0
- package/dist/context/execution-context.js.map +1 -0
- package/dist/context/index.d.ts +1 -0
- package/dist/context/index.js +18 -0
- package/dist/context/index.js.map +1 -0
- package/dist/decorators/constants.d.ts +41 -0
- package/dist/decorators/constants.js +13 -0
- package/dist/decorators/constants.js.map +1 -0
- package/dist/decorators/event-handler.decorator.d.ts +28 -0
- package/dist/decorators/event-handler.decorator.js +42 -0
- package/dist/decorators/event-handler.decorator.js.map +1 -0
- package/dist/decorators/index.d.ts +4 -0
- package/dist/decorators/index.js +21 -0
- package/dist/decorators/index.js.map +1 -0
- package/dist/decorators/message-handler.decorator.d.ts +26 -0
- package/dist/decorators/message-handler.decorator.js +40 -0
- package/dist/decorators/message-handler.decorator.js.map +1 -0
- package/dist/decorators/payload.decorator.d.ts +30 -0
- package/dist/decorators/payload.decorator.js +42 -0
- package/dist/decorators/payload.decorator.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +42 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces/index.d.ts +4 -0
- package/dist/interfaces/index.js +21 -0
- package/dist/interfaces/index.js.map +1 -0
- package/dist/interfaces/message-handler.interface.d.ts +21 -0
- package/dist/interfaces/message-handler.interface.js +3 -0
- package/dist/interfaces/message-handler.interface.js.map +1 -0
- package/dist/interfaces/packet.interface.d.ts +42 -0
- package/dist/interfaces/packet.interface.js +3 -0
- package/dist/interfaces/packet.interface.js.map +1 -0
- package/dist/interfaces/transport-client.interface.d.ts +41 -0
- package/dist/interfaces/transport-client.interface.js +3 -0
- package/dist/interfaces/transport-client.interface.js.map +1 -0
- package/dist/interfaces/transport-server.interface.d.ts +44 -0
- package/dist/interfaces/transport-server.interface.js +3 -0
- package/dist/interfaces/transport-server.interface.js.map +1 -0
- package/dist/keys.d.ts +88 -0
- package/dist/keys.js +123 -0
- package/dist/keys.js.map +1 -0
- package/dist/registry/handler-registry.d.ts +77 -0
- package/dist/registry/handler-registry.js +265 -0
- package/dist/registry/handler-registry.js.map +1 -0
- package/dist/registry/index.d.ts +1 -0
- package/dist/registry/index.js +18 -0
- package/dist/registry/index.js.map +1 -0
- package/dist/serializers/index.d.ts +1 -0
- package/dist/serializers/index.js +18 -0
- package/dist/serializers/index.js.map +1 -0
- package/dist/serializers/serializer.interface.d.ts +62 -0
- package/dist/serializers/serializer.interface.js +52 -0
- package/dist/serializers/serializer.interface.js.map +1 -0
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.js +18 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/server-base.d.ts +154 -0
- package/dist/server/server-base.js +287 -0
- package/dist/server/server-base.js.map +1 -0
- package/dist/transport-booter.d.ts +31 -0
- package/dist/transport-booter.js +117 -0
- package/dist/transport-booter.js.map +1 -0
- package/dist/transport.component.d.ts +26 -0
- package/dist/transport.component.js +42 -0
- package/dist/transport.component.js.map +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +6 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/normalize-pattern.d.ts +18 -0
- package/dist/utils/normalize-pattern.js +75 -0
- package/dist/utils/normalize-pattern.js.map +1 -0
- package/package.json +73 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client-proxy.js","sourceRoot":"","sources":["../../src/client/client-proxy.ts"],"names":[],"mappings":";;;AAAA,mCAAkC;AAClC,+BAAgE;AAEhE,oCAA0C;AAY1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;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CAAC,KAAK,GAAG,WAAW,CAAC;oBACzB,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;iBACtC;qBAAM;oBACL,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;iBACxD;YACH,CAAC,CAAC;iBACD,KAAK,CAAC,GAAG,CAAC,EAAE;gBACX,IAAI,IAAI,CAAC,KAAK,KAAK,EAAE,EAAE;oBACrB,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC;iBACrB;gBACD,MAAM,GAAG,CAAC;YACZ,CAAC,CAAC;iBACD,OAAO,CAAC,GAAG,EAAE;gBACZ,IAAI,IAAI,CAAC,iBAAiB,KAAK,OAAO,EAAE;oBACtC,IAAI,CAAC,iBAAiB,GAAG,SAAS,CAAC;oBACnC,IAAI,CAAC,eAAe,GAAG,SAAS,CAAC;iBAClC;YACH,CAAC,CAAC,CAAC;YACL,IAAI,CAAC,iBAAiB,GAAG,OAAO,CAAC;SAClC;QAED,MAAM,IAAI,CAAC,iBAAiB,CAAC;QAE7B,sDAAsD;QACtD,iEAAiE;QACjE,IAAI,IAAI,CAAC,KAAK,KAAK,YAAY,EAAE;YAC/B,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;SACxD;QACD,IAAI,CAAC,eAAe,EAAE,CAAC;IACzB,CAAC;CACF;AA7PD,kCA6PC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './client-proxy';
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./client-proxy"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA+B"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The type of transport handling the current request.
|
|
3
|
+
*/
|
|
4
|
+
export type ContextType = 'http' | 'rpc' | 'event';
|
|
5
|
+
/**
|
|
6
|
+
* Handler function type. Avoids bare `Function`.
|
|
7
|
+
*/
|
|
8
|
+
export type HandlerFunction = (...args: unknown[]) => unknown;
|
|
9
|
+
/**
|
|
10
|
+
* Controller class type. Avoids bare `Function`.
|
|
11
|
+
*/
|
|
12
|
+
export type ControllerClass<T = unknown> = abstract new (...args: never[]) => T;
|
|
13
|
+
/**
|
|
14
|
+
* HTTP-specific context. Wraps Express request/response.
|
|
15
|
+
*/
|
|
16
|
+
export interface HttpContext {
|
|
17
|
+
getRequest<T = unknown>(): T;
|
|
18
|
+
getResponse<T = unknown>(): T;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* RPC-specific context (gRPC, request/response patterns).
|
|
22
|
+
*/
|
|
23
|
+
export interface RpcContext {
|
|
24
|
+
getData<T = unknown>(): T;
|
|
25
|
+
getContext<T = unknown>(): T;
|
|
26
|
+
getMethod(): string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Event-specific context (Kafka, RabbitMQ, MQTT, NATS events).
|
|
30
|
+
*/
|
|
31
|
+
export interface EventContext {
|
|
32
|
+
getData<T = unknown>(): T;
|
|
33
|
+
getPattern(): string;
|
|
34
|
+
getContext<T = unknown>(): T;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Unified execution context that works across HTTP, RPC, and event transports.
|
|
38
|
+
*
|
|
39
|
+
* Immutable after construction. Created via static factory methods
|
|
40
|
+
* that guarantee the transport-specific context is present.
|
|
41
|
+
* No half-built contexts, no post-construction mutation.
|
|
42
|
+
*
|
|
43
|
+
* NestJS-compatible mental model: getType() + switchToHttp/Rpc/Event.
|
|
44
|
+
* Cleaner construction: factory methods enforce correct state.
|
|
45
|
+
*/
|
|
46
|
+
export declare class ExecutionContext {
|
|
47
|
+
private readonly type;
|
|
48
|
+
private readonly args;
|
|
49
|
+
private readonly handler;
|
|
50
|
+
private readonly controllerClass;
|
|
51
|
+
private readonly httpCtx?;
|
|
52
|
+
private readonly rpcCtx?;
|
|
53
|
+
private readonly eventCtx?;
|
|
54
|
+
private constructor();
|
|
55
|
+
/**
|
|
56
|
+
* Create an HTTP execution context.
|
|
57
|
+
*/
|
|
58
|
+
static forHttp(args: unknown[], handler: HandlerFunction, controllerClass: ControllerClass, httpCtx: HttpContext): ExecutionContext;
|
|
59
|
+
/**
|
|
60
|
+
* Create an RPC execution context (gRPC, request/response patterns).
|
|
61
|
+
*/
|
|
62
|
+
static forRpc(args: unknown[], handler: HandlerFunction, controllerClass: ControllerClass, rpcCtx: RpcContext): ExecutionContext;
|
|
63
|
+
/**
|
|
64
|
+
* Create an event execution context (Kafka, RabbitMQ, MQTT, NATS).
|
|
65
|
+
*/
|
|
66
|
+
static forEvent(args: unknown[], handler: HandlerFunction, controllerClass: ControllerClass, eventCtx: EventContext): ExecutionContext;
|
|
67
|
+
/**
|
|
68
|
+
* Returns the transport type handling this request.
|
|
69
|
+
*/
|
|
70
|
+
getType(): ContextType;
|
|
71
|
+
/**
|
|
72
|
+
* Returns the controller class the handler belongs to.
|
|
73
|
+
*/
|
|
74
|
+
getClass<T = unknown>(): ControllerClass<T>;
|
|
75
|
+
/**
|
|
76
|
+
* Returns the handler function that will be invoked.
|
|
77
|
+
*/
|
|
78
|
+
getHandler(): HandlerFunction;
|
|
79
|
+
/**
|
|
80
|
+
* Returns a copy of the arguments array.
|
|
81
|
+
*/
|
|
82
|
+
getArgs<T extends readonly unknown[] = readonly unknown[]>(): T;
|
|
83
|
+
/**
|
|
84
|
+
* Returns a specific argument by index.
|
|
85
|
+
*/
|
|
86
|
+
getArgByIndex<T = unknown>(index: number): T;
|
|
87
|
+
/**
|
|
88
|
+
* Switch to HTTP context.
|
|
89
|
+
* Throws if the current type is not 'http' or context is missing.
|
|
90
|
+
*/
|
|
91
|
+
switchToHttp(): HttpContext;
|
|
92
|
+
/**
|
|
93
|
+
* Switch to RPC context.
|
|
94
|
+
* Throws if the current type is not 'rpc' or context is missing.
|
|
95
|
+
*/
|
|
96
|
+
switchToRpc(): RpcContext;
|
|
97
|
+
/**
|
|
98
|
+
* Switch to event context.
|
|
99
|
+
* Throws if the current type is not 'event' or context is missing.
|
|
100
|
+
*/
|
|
101
|
+
switchToEvent(): EventContext;
|
|
102
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExecutionContext = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Unified execution context that works across HTTP, RPC, and event transports.
|
|
6
|
+
*
|
|
7
|
+
* Immutable after construction. Created via static factory methods
|
|
8
|
+
* that guarantee the transport-specific context is present.
|
|
9
|
+
* No half-built contexts, no post-construction mutation.
|
|
10
|
+
*
|
|
11
|
+
* NestJS-compatible mental model: getType() + switchToHttp/Rpc/Event.
|
|
12
|
+
* Cleaner construction: factory methods enforce correct state.
|
|
13
|
+
*/
|
|
14
|
+
class ExecutionContext {
|
|
15
|
+
constructor(type, args, handler, controllerClass, contexts) {
|
|
16
|
+
this.type = type;
|
|
17
|
+
this.args = [...args];
|
|
18
|
+
this.handler = handler;
|
|
19
|
+
this.controllerClass = controllerClass;
|
|
20
|
+
this.httpCtx = contexts.http;
|
|
21
|
+
this.rpcCtx = contexts.rpc;
|
|
22
|
+
this.eventCtx = contexts.event;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Create an HTTP execution context.
|
|
26
|
+
*/
|
|
27
|
+
static forHttp(args, handler, controllerClass, httpCtx) {
|
|
28
|
+
return new ExecutionContext('http', args, handler, controllerClass, {
|
|
29
|
+
http: httpCtx,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Create an RPC execution context (gRPC, request/response patterns).
|
|
34
|
+
*/
|
|
35
|
+
static forRpc(args, handler, controllerClass, rpcCtx) {
|
|
36
|
+
return new ExecutionContext('rpc', args, handler, controllerClass, {
|
|
37
|
+
rpc: rpcCtx,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Create an event execution context (Kafka, RabbitMQ, MQTT, NATS).
|
|
42
|
+
*/
|
|
43
|
+
static forEvent(args, handler, controllerClass, eventCtx) {
|
|
44
|
+
return new ExecutionContext('event', args, handler, controllerClass, {
|
|
45
|
+
event: eventCtx,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Returns the transport type handling this request.
|
|
50
|
+
*/
|
|
51
|
+
getType() {
|
|
52
|
+
return this.type;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Returns the controller class the handler belongs to.
|
|
56
|
+
*/
|
|
57
|
+
getClass() {
|
|
58
|
+
return this.controllerClass;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Returns the handler function that will be invoked.
|
|
62
|
+
*/
|
|
63
|
+
getHandler() {
|
|
64
|
+
return this.handler;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Returns a copy of the arguments array.
|
|
68
|
+
*/
|
|
69
|
+
getArgs() {
|
|
70
|
+
return [...this.args];
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Returns a specific argument by index.
|
|
74
|
+
*/
|
|
75
|
+
getArgByIndex(index) {
|
|
76
|
+
return this.args[index];
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Switch to HTTP context.
|
|
80
|
+
* Throws if the current type is not 'http' or context is missing.
|
|
81
|
+
*/
|
|
82
|
+
switchToHttp() {
|
|
83
|
+
if (this.type !== 'http' || !this.httpCtx) {
|
|
84
|
+
throw new Error(`Cannot switch to HTTP context: current transport type is "${this.type}"`);
|
|
85
|
+
}
|
|
86
|
+
return this.httpCtx;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Switch to RPC context.
|
|
90
|
+
* Throws if the current type is not 'rpc' or context is missing.
|
|
91
|
+
*/
|
|
92
|
+
switchToRpc() {
|
|
93
|
+
if (this.type !== 'rpc' || !this.rpcCtx) {
|
|
94
|
+
throw new Error(`Cannot switch to RPC context: current transport type is "${this.type}"`);
|
|
95
|
+
}
|
|
96
|
+
return this.rpcCtx;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Switch to event context.
|
|
100
|
+
* Throws if the current type is not 'event' or context is missing.
|
|
101
|
+
*/
|
|
102
|
+
switchToEvent() {
|
|
103
|
+
if (this.type !== 'event' || !this.eventCtx) {
|
|
104
|
+
throw new Error(`Cannot switch to event context: current transport type is "${this.type}"`);
|
|
105
|
+
}
|
|
106
|
+
return this.eventCtx;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
exports.ExecutionContext = ExecutionContext;
|
|
110
|
+
//# sourceMappingURL=execution-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execution-context.js","sourceRoot":"","sources":["../../src/context/execution-context.ts"],"names":[],"mappings":";;;AA2CA;;;;;;;;;GASG;AACH,MAAa,gBAAgB;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AC;IAED;;OAEG;IACH,UAAU;QACR,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED;;OAEG;IACH,OAAO;QACL,OAAO,CAAC,GAAG,IAAI,CAAC,IAAI,CAAiB,CAAC;IACxC,CAAC;IAED;;OAEG;IACH,aAAa,CAAc,KAAa;QACtC,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAM,CAAC;IAC/B,CAAC;IAED;;;OAGG;IACH,YAAY;QACV,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;YACzC,MAAM,IAAI,KAAK,CACb,6DAA6D,IAAI,CAAC,IAAI,GAAG,CAC1E,CAAC;SACH;QACD,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED;;;OAGG;IACH,WAAW;QACT,IAAI,IAAI,CAAC,IAAI,KAAK,KAAK,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;YACvC,MAAM,IAAI,KAAK,CACb,4DAA4D,IAAI,CAAC,IAAI,GAAG,CACzE,CAAC;SACH;QACD,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED;;;OAGG;IACH,aAAa;QACX,IAAI,IAAI,CAAC,IAAI,KAAK,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;YAC3C,MAAM,IAAI,KAAK,CACb,8DAA8D,IAAI,CAAC,IAAI,GAAG,CAC3E,CAAC;SACH;QACD,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;CACF;AAhJD,4CAgJC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './execution-context';
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./execution-context"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/context/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sDAAoC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { MetadataAccessor } from '@loopback/metadata';
|
|
2
|
+
/**
|
|
3
|
+
* Options for @messageHandler and @eventHandler decorators.
|
|
4
|
+
* Extracted as a named type for public API stability.
|
|
5
|
+
*/
|
|
6
|
+
export interface HandlerOptions {
|
|
7
|
+
transport?: string;
|
|
8
|
+
extras?: Readonly<Record<string, unknown>>;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Metadata stored by @messageHandler.
|
|
12
|
+
*
|
|
13
|
+
* Pattern is stored as a normalized string via normalizePattern().
|
|
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.
|
|
17
|
+
*/
|
|
18
|
+
export interface MessageHandlerMetadata {
|
|
19
|
+
pattern: string;
|
|
20
|
+
transport?: string;
|
|
21
|
+
extras?: Readonly<Record<string, unknown>>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Metadata stored by @eventHandler.
|
|
25
|
+
*
|
|
26
|
+
* Pattern is stored as a normalized string via normalizePattern().
|
|
27
|
+
* Object patterns are deep-sorted by key and stringified.
|
|
28
|
+
*/
|
|
29
|
+
export interface EventHandlerMetadata {
|
|
30
|
+
pattern: string;
|
|
31
|
+
transport?: string;
|
|
32
|
+
extras?: Readonly<Record<string, unknown>>;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Metadata key for @messageHandler decorator.
|
|
36
|
+
*/
|
|
37
|
+
export declare const MESSAGE_HANDLER_METADATA: MetadataAccessor<MessageHandlerMetadata, MethodDecorator>;
|
|
38
|
+
/**
|
|
39
|
+
* Metadata key for @eventHandler decorator.
|
|
40
|
+
*/
|
|
41
|
+
export declare const EVENT_HANDLER_METADATA: MetadataAccessor<EventHandlerMetadata, MethodDecorator>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EVENT_HANDLER_METADATA = exports.MESSAGE_HANDLER_METADATA = void 0;
|
|
4
|
+
const metadata_1 = require("@loopback/metadata");
|
|
5
|
+
/**
|
|
6
|
+
* Metadata key for @messageHandler decorator.
|
|
7
|
+
*/
|
|
8
|
+
exports.MESSAGE_HANDLER_METADATA = metadata_1.MetadataAccessor.create('transport:message-handler');
|
|
9
|
+
/**
|
|
10
|
+
* Metadata key for @eventHandler decorator.
|
|
11
|
+
*/
|
|
12
|
+
exports.EVENT_HANDLER_METADATA = metadata_1.MetadataAccessor.create('transport:event-handler');
|
|
13
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/decorators/constants.ts"],"names":[],"mappings":";;;AAAA,iDAAoD;AAqCpD;;GAEG;AACU,QAAA,wBAAwB,GAAG,2BAAgB,CAAC,MAAM,CAG7D,2BAA2B,CAAC,CAAC;AAE/B;;GAEG;AACU,QAAA,sBAAsB,GAAG,2BAAgB,CAAC,MAAM,CAG3D,yBAAyB,CAAC,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { HandlerOptions } from './constants';
|
|
2
|
+
/**
|
|
3
|
+
* Mark a controller method as a fire-and-forget event handler.
|
|
4
|
+
*
|
|
5
|
+
* The transport server dispatches matching events to this method.
|
|
6
|
+
* No response is sent back to the emitter.
|
|
7
|
+
*
|
|
8
|
+
* Multiple event handlers can be registered for the same pattern.
|
|
9
|
+
* They are chained and all execute.
|
|
10
|
+
*
|
|
11
|
+
* @param pattern - String or object pattern to match (e.g., 'order.placed' or {event: 'order.placed'})
|
|
12
|
+
* @param options - Optional transport name and extras
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* // String pattern
|
|
17
|
+
* @eventHandler('order.placed')
|
|
18
|
+
* async handleOrder(@payload() data: OrderDto): Promise<void> { ... }
|
|
19
|
+
*
|
|
20
|
+
* // With transport and extras override
|
|
21
|
+
* @eventHandler('payment.received', {
|
|
22
|
+
* transport: 'redis',
|
|
23
|
+
* extras: {mode: 'stream', consumerGroup: 'payment-workers'},
|
|
24
|
+
* })
|
|
25
|
+
* async handlePayment(@payload() data: PaymentDto): Promise<void> { ... }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare function eventHandler(pattern: string | Record<string, unknown>, options?: HandlerOptions): MethodDecorator;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.eventHandler = void 0;
|
|
4
|
+
const metadata_1 = require("@loopback/metadata");
|
|
5
|
+
const constants_1 = require("./constants");
|
|
6
|
+
const utils_1 = require("../utils");
|
|
7
|
+
/**
|
|
8
|
+
* Mark a controller method as a fire-and-forget event handler.
|
|
9
|
+
*
|
|
10
|
+
* The transport server dispatches matching events to this method.
|
|
11
|
+
* No response is sent back to the emitter.
|
|
12
|
+
*
|
|
13
|
+
* Multiple event handlers can be registered for the same pattern.
|
|
14
|
+
* They are chained and all execute.
|
|
15
|
+
*
|
|
16
|
+
* @param pattern - String or object pattern to match (e.g., 'order.placed' or {event: 'order.placed'})
|
|
17
|
+
* @param options - Optional transport name and extras
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* // String pattern
|
|
22
|
+
* @eventHandler('order.placed')
|
|
23
|
+
* async handleOrder(@payload() data: OrderDto): Promise<void> { ... }
|
|
24
|
+
*
|
|
25
|
+
* // With transport and extras override
|
|
26
|
+
* @eventHandler('payment.received', {
|
|
27
|
+
* transport: 'redis',
|
|
28
|
+
* extras: {mode: 'stream', consumerGroup: 'payment-workers'},
|
|
29
|
+
* })
|
|
30
|
+
* async handlePayment(@payload() data: PaymentDto): Promise<void> { ... }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
function eventHandler(pattern, options) {
|
|
34
|
+
const serializedPattern = (0, utils_1.normalizePattern)(pattern);
|
|
35
|
+
return metadata_1.MethodDecoratorFactory.createDecorator(constants_1.EVENT_HANDLER_METADATA, {
|
|
36
|
+
pattern: serializedPattern,
|
|
37
|
+
transport: options?.transport,
|
|
38
|
+
extras: options?.extras,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
exports.eventHandler = eventHandler;
|
|
42
|
+
//# sourceMappingURL=event-handler.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-handler.decorator.js","sourceRoot":"","sources":["../../src/decorators/event-handler.decorator.ts"],"names":[],"mappings":";;;AAAA,iDAA0D;AAC1D,2CAIqB;AACrB,oCAA0C;AAE1C;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,SAAgB,YAAY,CAC1B,OAAyC,EACzC,OAAwB;IAExB,MAAM,iBAAiB,GAAG,IAAA,wBAAgB,EAAC,OAAO,CAAC,CAAC;IAEpD,OAAO,iCAAsB,CAAC,eAAe,CAC3C,kCAAsB,EACtB;QACE,OAAO,EAAE,iBAAiB;QAC1B,SAAS,EAAE,OAAO,EAAE,SAAS;QAC7B,MAAM,EAAE,OAAO,EAAE,MAAM;KACxB,CACF,CAAC;AACJ,CAAC;AAdD,oCAcC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./constants"), exports);
|
|
18
|
+
__exportStar(require("./message-handler.decorator"), exports);
|
|
19
|
+
__exportStar(require("./event-handler.decorator"), exports);
|
|
20
|
+
__exportStar(require("./payload.decorator"), exports);
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,8DAA4C;AAC5C,4DAA0C;AAC1C,sDAAoC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { HandlerOptions } from './constants';
|
|
2
|
+
/**
|
|
3
|
+
* Mark a controller method as a request/response message handler.
|
|
4
|
+
*
|
|
5
|
+
* The transport server dispatches matching messages to this method
|
|
6
|
+
* and returns the result to the caller.
|
|
7
|
+
*
|
|
8
|
+
* @param pattern - String or object pattern to match (e.g., 'order.get' or {cmd: 'order.get'})
|
|
9
|
+
* @param options - Optional transport name and extras
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* // String pattern
|
|
14
|
+
* @messageHandler('order.get')
|
|
15
|
+
* async getOrder(@payload() data: GetOrderReq): Promise<Order> { ... }
|
|
16
|
+
*
|
|
17
|
+
* // Object pattern
|
|
18
|
+
* @messageHandler({cmd: 'order.get', version: 2})
|
|
19
|
+
* async getOrderV2(@payload() data: GetOrderReq): Promise<Order> { ... }
|
|
20
|
+
*
|
|
21
|
+
* // With transport targeting
|
|
22
|
+
* @messageHandler('order.get', {transport: 'kafka'})
|
|
23
|
+
* async getOrder(@payload() data: GetOrderReq): Promise<Order> { ... }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare function messageHandler(pattern: string | Record<string, unknown>, options?: HandlerOptions): MethodDecorator;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.messageHandler = void 0;
|
|
4
|
+
const metadata_1 = require("@loopback/metadata");
|
|
5
|
+
const constants_1 = require("./constants");
|
|
6
|
+
const utils_1 = require("../utils");
|
|
7
|
+
/**
|
|
8
|
+
* Mark a controller method as a request/response message handler.
|
|
9
|
+
*
|
|
10
|
+
* The transport server dispatches matching messages to this method
|
|
11
|
+
* and returns the result to the caller.
|
|
12
|
+
*
|
|
13
|
+
* @param pattern - String or object pattern to match (e.g., 'order.get' or {cmd: 'order.get'})
|
|
14
|
+
* @param options - Optional transport name and extras
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* // String pattern
|
|
19
|
+
* @messageHandler('order.get')
|
|
20
|
+
* async getOrder(@payload() data: GetOrderReq): Promise<Order> { ... }
|
|
21
|
+
*
|
|
22
|
+
* // Object pattern
|
|
23
|
+
* @messageHandler({cmd: 'order.get', version: 2})
|
|
24
|
+
* async getOrderV2(@payload() data: GetOrderReq): Promise<Order> { ... }
|
|
25
|
+
*
|
|
26
|
+
* // With transport targeting
|
|
27
|
+
* @messageHandler('order.get', {transport: 'kafka'})
|
|
28
|
+
* async getOrder(@payload() data: GetOrderReq): Promise<Order> { ... }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
function messageHandler(pattern, options) {
|
|
32
|
+
const serializedPattern = (0, utils_1.normalizePattern)(pattern);
|
|
33
|
+
return metadata_1.MethodDecoratorFactory.createDecorator(constants_1.MESSAGE_HANDLER_METADATA, {
|
|
34
|
+
pattern: serializedPattern,
|
|
35
|
+
transport: options?.transport,
|
|
36
|
+
extras: options?.extras,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
exports.messageHandler = messageHandler;
|
|
40
|
+
//# sourceMappingURL=message-handler.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message-handler.decorator.js","sourceRoot":"","sources":["../../src/decorators/message-handler.decorator.ts"],"names":[],"mappings":";;;AAAA,iDAA0D;AAC1D,2CAIqB;AACrB,oCAA0C;AAE1C;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,SAAgB,cAAc,CAC5B,OAAyC,EACzC,OAAwB;IAExB,MAAM,iBAAiB,GAAG,IAAA,wBAAgB,EAAC,OAAO,CAAC,CAAC;IAEpD,OAAO,iCAAsB,CAAC,eAAe,CAC3C,oCAAwB,EACxB;QACE,OAAO,EAAE,iBAAiB;QAC1B,SAAS,EAAE,OAAO,EAAE,SAAS;QAC7B,MAAM,EAAE,OAAO,EAAE,MAAM;KACxB,CACF,CAAC;AACJ,CAAC;AAdD,wCAcC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parameter decorator that injects the message payload.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```typescript
|
|
6
|
+
* @eventHandler('order.placed')
|
|
7
|
+
* async handle(@payload() data: OrderDto): Promise<void> { ... }
|
|
8
|
+
* ```
|
|
9
|
+
*/
|
|
10
|
+
export declare function payload(): (target: Object, member: string | undefined, methodDescriptorOrParameterIndex?: number | TypedPropertyDescriptor<any> | undefined) => void;
|
|
11
|
+
/**
|
|
12
|
+
* Parameter decorator that injects the transport-specific context.
|
|
13
|
+
*
|
|
14
|
+
* The context type depends on the transport:
|
|
15
|
+
* - Kafka: KafkaContext (topic, partition, offset, consumer)
|
|
16
|
+
* - RabbitMQ: RmqContext (channel, message, pattern)
|
|
17
|
+
* - gRPC: GrpcContext (metadata, call)
|
|
18
|
+
* - MQTT: MqttContext (topic, packet)
|
|
19
|
+
* - NATS: NatsContext (subject, headers)
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* @eventHandler('order.placed')
|
|
24
|
+
* async handle(
|
|
25
|
+
* @payload() data: OrderDto,
|
|
26
|
+
* @transportCtx() ctx: KafkaContext,
|
|
27
|
+
* ): Promise<void> { ... }
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare function transportCtx(): (target: Object, member: string | undefined, methodDescriptorOrParameterIndex?: number | TypedPropertyDescriptor<any> | undefined) => void;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transportCtx = exports.payload = void 0;
|
|
4
|
+
const core_1 = require("@loopback/core");
|
|
5
|
+
const keys_1 = require("../keys");
|
|
6
|
+
/**
|
|
7
|
+
* Parameter decorator that injects the message payload.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* @eventHandler('order.placed')
|
|
12
|
+
* async handle(@payload() data: OrderDto): Promise<void> { ... }
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
function payload() {
|
|
16
|
+
return (0, core_1.inject)(keys_1.TransportBindings.CURRENT_PAYLOAD);
|
|
17
|
+
}
|
|
18
|
+
exports.payload = payload;
|
|
19
|
+
/**
|
|
20
|
+
* Parameter decorator that injects the transport-specific context.
|
|
21
|
+
*
|
|
22
|
+
* The context type depends on the transport:
|
|
23
|
+
* - Kafka: KafkaContext (topic, partition, offset, consumer)
|
|
24
|
+
* - RabbitMQ: RmqContext (channel, message, pattern)
|
|
25
|
+
* - gRPC: GrpcContext (metadata, call)
|
|
26
|
+
* - MQTT: MqttContext (topic, packet)
|
|
27
|
+
* - NATS: NatsContext (subject, headers)
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* @eventHandler('order.placed')
|
|
32
|
+
* async handle(
|
|
33
|
+
* @payload() data: OrderDto,
|
|
34
|
+
* @transportCtx() ctx: KafkaContext,
|
|
35
|
+
* ): Promise<void> { ... }
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
function transportCtx() {
|
|
39
|
+
return (0, core_1.inject)(keys_1.TransportBindings.CURRENT_CONTEXT);
|
|
40
|
+
}
|
|
41
|
+
exports.transportCtx = transportCtx;
|
|
42
|
+
//# sourceMappingURL=payload.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payload.decorator.js","sourceRoot":"","sources":["../../src/decorators/payload.decorator.ts"],"names":[],"mappings":";;;AAAA,yCAAsC;AACtC,kCAA0C;AAE1C;;;;;;;;GAQG;AACH,SAAgB,OAAO;IACrB,OAAO,IAAA,aAAM,EAAC,wBAAiB,CAAC,eAAe,CAAC,CAAC;AACnD,CAAC;AAFD,0BAEC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAgB,YAAY;IAC1B,OAAO,IAAA,aAAM,EAAC,wBAAiB,CAAC,eAAe,CAAC,CAAC;AACnD,CAAC;AAFD,oCAEC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { TransportComponent } from './transport.component';
|
|
2
|
+
export { TransportBooter } from './transport-booter';
|
|
3
|
+
export { TransportBindings, TRANSPORT_SERVER_TAG, TRANSPORT_NAME_TAG, } from './keys';
|
|
4
|
+
export { HandlerRegistry } from './registry';
|
|
5
|
+
export { PacketId, ReadPacket, WritePacket, OutgoingRequest, OutgoingEvent, IncomingRequest, IncomingEvent, IncomingResponse, TransportServer, TransportClient, TransportStatus, MessageHandler, } from './interfaces';
|
|
6
|
+
export { ExecutionContext, ContextType, HttpContext, RpcContext, EventContext, } from './context';
|
|
7
|
+
export { messageHandler, eventHandler, payload, transportCtx, HandlerOptions, MessageHandlerMetadata, EventHandlerMetadata, MESSAGE_HANDLER_METADATA, EVENT_HANDLER_METADATA, } from './decorators';
|
|
8
|
+
export { normalizePattern } from './utils';
|
|
9
|
+
export { ClientProxy } from './client';
|
|
10
|
+
export { ServerBase, HandlerResult } from './server';
|
|
11
|
+
export { Serializer, Deserializer, JsonSerializer, JsonDeserializer, TransportPacket, } from './serializers';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.JsonDeserializer = exports.JsonSerializer = exports.ServerBase = exports.ClientProxy = exports.normalizePattern = exports.EVENT_HANDLER_METADATA = exports.MESSAGE_HANDLER_METADATA = exports.transportCtx = exports.payload = exports.eventHandler = exports.messageHandler = exports.ExecutionContext = exports.HandlerRegistry = exports.TRANSPORT_NAME_TAG = exports.TRANSPORT_SERVER_TAG = exports.TransportBindings = exports.TransportBooter = exports.TransportComponent = void 0;
|
|
4
|
+
// Component
|
|
5
|
+
var transport_component_1 = require("./transport.component");
|
|
6
|
+
Object.defineProperty(exports, "TransportComponent", { enumerable: true, get: function () { return transport_component_1.TransportComponent; } });
|
|
7
|
+
// Booter
|
|
8
|
+
var transport_booter_1 = require("./transport-booter");
|
|
9
|
+
Object.defineProperty(exports, "TransportBooter", { enumerable: true, get: function () { return transport_booter_1.TransportBooter; } });
|
|
10
|
+
// Binding keys and tags
|
|
11
|
+
var keys_1 = require("./keys");
|
|
12
|
+
Object.defineProperty(exports, "TransportBindings", { enumerable: true, get: function () { return keys_1.TransportBindings; } });
|
|
13
|
+
Object.defineProperty(exports, "TRANSPORT_SERVER_TAG", { enumerable: true, get: function () { return keys_1.TRANSPORT_SERVER_TAG; } });
|
|
14
|
+
Object.defineProperty(exports, "TRANSPORT_NAME_TAG", { enumerable: true, get: function () { return keys_1.TRANSPORT_NAME_TAG; } });
|
|
15
|
+
// Registry
|
|
16
|
+
var registry_1 = require("./registry");
|
|
17
|
+
Object.defineProperty(exports, "HandlerRegistry", { enumerable: true, get: function () { return registry_1.HandlerRegistry; } });
|
|
18
|
+
// Context
|
|
19
|
+
var context_1 = require("./context");
|
|
20
|
+
Object.defineProperty(exports, "ExecutionContext", { enumerable: true, get: function () { return context_1.ExecutionContext; } });
|
|
21
|
+
// Decorators
|
|
22
|
+
var decorators_1 = require("./decorators");
|
|
23
|
+
Object.defineProperty(exports, "messageHandler", { enumerable: true, get: function () { return decorators_1.messageHandler; } });
|
|
24
|
+
Object.defineProperty(exports, "eventHandler", { enumerable: true, get: function () { return decorators_1.eventHandler; } });
|
|
25
|
+
Object.defineProperty(exports, "payload", { enumerable: true, get: function () { return decorators_1.payload; } });
|
|
26
|
+
Object.defineProperty(exports, "transportCtx", { enumerable: true, get: function () { return decorators_1.transportCtx; } });
|
|
27
|
+
Object.defineProperty(exports, "MESSAGE_HANDLER_METADATA", { enumerable: true, get: function () { return decorators_1.MESSAGE_HANDLER_METADATA; } });
|
|
28
|
+
Object.defineProperty(exports, "EVENT_HANDLER_METADATA", { enumerable: true, get: function () { return decorators_1.EVENT_HANDLER_METADATA; } });
|
|
29
|
+
// Utils
|
|
30
|
+
var utils_1 = require("./utils");
|
|
31
|
+
Object.defineProperty(exports, "normalizePattern", { enumerable: true, get: function () { return utils_1.normalizePattern; } });
|
|
32
|
+
// Client
|
|
33
|
+
var client_1 = require("./client");
|
|
34
|
+
Object.defineProperty(exports, "ClientProxy", { enumerable: true, get: function () { return client_1.ClientProxy; } });
|
|
35
|
+
// Server
|
|
36
|
+
var server_1 = require("./server");
|
|
37
|
+
Object.defineProperty(exports, "ServerBase", { enumerable: true, get: function () { return server_1.ServerBase; } });
|
|
38
|
+
// Serializers
|
|
39
|
+
var serializers_1 = require("./serializers");
|
|
40
|
+
Object.defineProperty(exports, "JsonSerializer", { enumerable: true, get: function () { return serializers_1.JsonSerializer; } });
|
|
41
|
+
Object.defineProperty(exports, "JsonDeserializer", { enumerable: true, get: function () { return serializers_1.JsonDeserializer; } });
|
|
42
|
+
//# sourceMappingURL=index.js.map
|