@lakutata/nats 1.1.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/CHANGELOG.md +11 -0
- package/README.md +38 -0
- package/dist/CommonExports.d.ts +14 -0
- package/dist/CommonExports.d.ts.map +1 -0
- package/dist/CommonExports.js +24 -0
- package/dist/codecs/JSONCodec.d.ts +3 -0
- package/dist/codecs/JSONCodec.d.ts.map +1 -0
- package/dist/codecs/JSONCodec.js +15 -0
- package/dist/components/NATS.d.ts +129 -0
- package/dist/components/NATS.d.ts.map +1 -0
- package/dist/components/NATS.js +205 -0
- package/dist/entrypoints/SetupNatsServiceEntrypoint.d.ts +8 -0
- package/dist/entrypoints/SetupNatsServiceEntrypoint.d.ts.map +1 -0
- package/dist/entrypoints/SetupNatsServiceEntrypoint.js +20 -0
- package/dist/exceptions/NatsBadRequestException.d.ts +7 -0
- package/dist/exceptions/NatsBadRequestException.d.ts.map +1 -0
- package/dist/exceptions/NatsBadRequestException.js +13 -0
- package/dist/exceptions/NatsForbiddenException.d.ts +7 -0
- package/dist/exceptions/NatsForbiddenException.d.ts.map +1 -0
- package/dist/exceptions/NatsForbiddenException.js +13 -0
- package/dist/exceptions/NatsInternalServerException.d.ts +7 -0
- package/dist/exceptions/NatsInternalServerException.d.ts.map +1 -0
- package/dist/exceptions/NatsInternalServerException.js +13 -0
- package/dist/exceptions/NatsNoRespondersAvailableException.d.ts +7 -0
- package/dist/exceptions/NatsNoRespondersAvailableException.d.ts.map +1 -0
- package/dist/exceptions/NatsNoRespondersAvailableException.js +13 -0
- package/dist/exceptions/NatsNotFoundException.d.ts +7 -0
- package/dist/exceptions/NatsNotFoundException.d.ts.map +1 -0
- package/dist/exceptions/NatsNotFoundException.js +13 -0
- package/dist/exceptions/NatsRequestTimeoutException.d.ts +7 -0
- package/dist/exceptions/NatsRequestTimeoutException.d.ts.map +1 -0
- package/dist/exceptions/NatsRequestTimeoutException.js +13 -0
- package/dist/interfaces/NatsClientOptions.d.ts +18 -0
- package/dist/interfaces/NatsClientOptions.d.ts.map +1 -0
- package/dist/interfaces/NatsClientOptions.js +2 -0
- package/dist/tests/NatsTest.spec.d.ts +2 -0
- package/dist/tests/NatsTest.spec.d.ts.map +1 -0
- package/dist/tests/NatsTest.spec.js +85 -0
- package/dist/types/SubscribeOptions.d.ts +5 -0
- package/dist/types/SubscribeOptions.d.ts.map +1 -0
- package/dist/types/SubscribeOptions.js +2 -0
- package/package.json +35 -0
- package/tsconfig.json +7 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
# 1.1.0 (2025-09-27)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **nats:** implement JSON codec for message serialization ([422e56e](https://github.com/lakutata/lakutata-packages/commit/422e56e672172ad2aafde80457e5495f40d4a792))
|
package/README.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
</div>
|
|
6
|
+
|
|
7
|
+
<div align="center">
|
|
8
|
+
|
|
9
|
+
)
|
|
10
|
+
)
|
|
11
|
+
)
|
|
12
|
+
)
|
|
13
|
+

|
|
14
|
+
|
|
15
|
+
</div>
|
|
16
|
+
|
|
17
|
+
## 💫 Description
|
|
18
|
+
|
|
19
|
+
Lakutata is a generic development framework written in TypeScript and designed with IoC principles. Its main objective
|
|
20
|
+
is to provide a universal, efficient, and stable development framework. The design goals of Lakutata are not limited to
|
|
21
|
+
web application development; it aims to serve as a foundational framework for desktop applications, embedded systems
|
|
22
|
+
applications, and web applications. The framework primarily adopts an OOP (Object-Oriented Programming) approach and
|
|
23
|
+
encapsulates functionalities such as subprocesses, threads, permission management, and database ORM, enabling the
|
|
24
|
+
framework to be used out of the box.
|
|
25
|
+
|
|
26
|
+
In addition, Lakutata also supports the integration of third-party libraries into the application, allowing developers
|
|
27
|
+
to freely encapsulate and call third-party modules using Lakutata's dependency injection.
|
|
28
|
+
|
|
29
|
+
## ✨ Getting started
|
|
30
|
+
|
|
31
|
+
- Install lakutata NATS client
|
|
32
|
+
```shell
|
|
33
|
+
npm install @lakutata/nats
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## 🌎 License
|
|
37
|
+
|
|
38
|
+
Lakutata is [MIT licensed](LICENSE).
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { SetupNatsServiceEntrypoint } from './entrypoints/SetupNatsServiceEntrypoint';
|
|
2
|
+
export { NATS, buildNatsClientOptions } from './components/NATS';
|
|
3
|
+
export { JSONCodec } from './codecs/JSONCodec';
|
|
4
|
+
export { StringCodec } from 'nats';
|
|
5
|
+
export type { SubscribeOptions } from './types/SubscribeOptions';
|
|
6
|
+
export type { Subscription, Codec } from 'nats';
|
|
7
|
+
export type { NatsClientOptions } from './interfaces/NatsClientOptions';
|
|
8
|
+
export { NatsBadRequestException } from './exceptions/NatsBadRequestException';
|
|
9
|
+
export { NatsForbiddenException } from './exceptions/NatsForbiddenException';
|
|
10
|
+
export { NatsInternalServerException } from './exceptions/NatsInternalServerException';
|
|
11
|
+
export { NatsNoRespondersAvailableException } from './exceptions/NatsNoRespondersAvailableException';
|
|
12
|
+
export { NatsNotFoundException } from './exceptions/NatsNotFoundException';
|
|
13
|
+
export { NatsRequestTimeoutException } from './exceptions/NatsRequestTimeoutException';
|
|
14
|
+
//# sourceMappingURL=CommonExports.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CommonExports.d.ts","sourceRoot":"","sources":["../src/CommonExports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,0BAA0B,EAAC,MAAM,0CAA0C,CAAA;AACnF,OAAO,EAAC,IAAI,EAAE,sBAAsB,EAAC,MAAM,mBAAmB,CAAA;AAC9D,OAAO,EAAC,SAAS,EAAC,MAAM,oBAAoB,CAAA;AAC5C,OAAO,EAAC,WAAW,EAAC,MAAM,MAAM,CAAA;AAChC,YAAY,EAAC,gBAAgB,EAAC,MAAM,0BAA0B,CAAA;AAC9D,YAAY,EAAC,YAAY,EAAE,KAAK,EAAC,MAAM,MAAM,CAAA;AAC7C,YAAY,EAAC,iBAAiB,EAAC,MAAM,gCAAgC,CAAA;AACrE,OAAO,EAAC,uBAAuB,EAAC,MAAM,sCAAsC,CAAA;AAC5E,OAAO,EAAC,sBAAsB,EAAC,MAAM,qCAAqC,CAAA;AAC1E,OAAO,EAAC,2BAA2B,EAAC,MAAM,0CAA0C,CAAA;AACpF,OAAO,EAAC,kCAAkC,EAAC,MAAM,iDAAiD,CAAA;AAClG,OAAO,EAAC,qBAAqB,EAAC,MAAM,oCAAoC,CAAA;AACxE,OAAO,EAAC,2BAA2B,EAAC,MAAM,0CAA0C,CAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NatsRequestTimeoutException = exports.NatsNotFoundException = exports.NatsNoRespondersAvailableException = exports.NatsInternalServerException = exports.NatsForbiddenException = exports.NatsBadRequestException = exports.StringCodec = exports.JSONCodec = exports.buildNatsClientOptions = exports.NATS = exports.SetupNatsServiceEntrypoint = void 0;
|
|
4
|
+
var SetupNatsServiceEntrypoint_1 = require("./entrypoints/SetupNatsServiceEntrypoint");
|
|
5
|
+
Object.defineProperty(exports, "SetupNatsServiceEntrypoint", { enumerable: true, get: function () { return SetupNatsServiceEntrypoint_1.SetupNatsServiceEntrypoint; } });
|
|
6
|
+
var NATS_1 = require("./components/NATS");
|
|
7
|
+
Object.defineProperty(exports, "NATS", { enumerable: true, get: function () { return NATS_1.NATS; } });
|
|
8
|
+
Object.defineProperty(exports, "buildNatsClientOptions", { enumerable: true, get: function () { return NATS_1.buildNatsClientOptions; } });
|
|
9
|
+
var JSONCodec_1 = require("./codecs/JSONCodec");
|
|
10
|
+
Object.defineProperty(exports, "JSONCodec", { enumerable: true, get: function () { return JSONCodec_1.JSONCodec; } });
|
|
11
|
+
var nats_1 = require("nats");
|
|
12
|
+
Object.defineProperty(exports, "StringCodec", { enumerable: true, get: function () { return nats_1.StringCodec; } });
|
|
13
|
+
var NatsBadRequestException_1 = require("./exceptions/NatsBadRequestException");
|
|
14
|
+
Object.defineProperty(exports, "NatsBadRequestException", { enumerable: true, get: function () { return NatsBadRequestException_1.NatsBadRequestException; } });
|
|
15
|
+
var NatsForbiddenException_1 = require("./exceptions/NatsForbiddenException");
|
|
16
|
+
Object.defineProperty(exports, "NatsForbiddenException", { enumerable: true, get: function () { return NatsForbiddenException_1.NatsForbiddenException; } });
|
|
17
|
+
var NatsInternalServerException_1 = require("./exceptions/NatsInternalServerException");
|
|
18
|
+
Object.defineProperty(exports, "NatsInternalServerException", { enumerable: true, get: function () { return NatsInternalServerException_1.NatsInternalServerException; } });
|
|
19
|
+
var NatsNoRespondersAvailableException_1 = require("./exceptions/NatsNoRespondersAvailableException");
|
|
20
|
+
Object.defineProperty(exports, "NatsNoRespondersAvailableException", { enumerable: true, get: function () { return NatsNoRespondersAvailableException_1.NatsNoRespondersAvailableException; } });
|
|
21
|
+
var NatsNotFoundException_1 = require("./exceptions/NatsNotFoundException");
|
|
22
|
+
Object.defineProperty(exports, "NatsNotFoundException", { enumerable: true, get: function () { return NatsNotFoundException_1.NatsNotFoundException; } });
|
|
23
|
+
var NatsRequestTimeoutException_1 = require("./exceptions/NatsRequestTimeoutException");
|
|
24
|
+
Object.defineProperty(exports, "NatsRequestTimeoutException", { enumerable: true, get: function () { return NatsRequestTimeoutException_1.NatsRequestTimeoutException; } });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JSONCodec.d.ts","sourceRoot":"","sources":["../../src/codecs/JSONCodec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAC,MAAM,MAAM,CAAA;AAE1B,wBAAgB,SAAS,IAAI,KAAK,CAAC,GAAG,CAAC,CAUtC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.JSONCodec = void 0;
|
|
4
|
+
function JSONCodec() {
|
|
5
|
+
return {
|
|
6
|
+
encode(d) {
|
|
7
|
+
return Buffer.from(JSON.stringify([d]));
|
|
8
|
+
},
|
|
9
|
+
decode(a) {
|
|
10
|
+
const [res] = JSON.parse(Buffer.from(a).toString());
|
|
11
|
+
return res;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
exports.JSONCodec = JSONCodec;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { Component, ComponentOptionsBuilder } from 'lakutata';
|
|
2
|
+
import { type Codec, Subscription } from 'nats';
|
|
3
|
+
import { SubscribeOptions } from '../types/SubscribeOptions';
|
|
4
|
+
import { NatsClientOptions } from '../interfaces/NatsClientOptions';
|
|
5
|
+
export declare const buildNatsClientOptions: ComponentOptionsBuilder<NatsClientOptions>;
|
|
6
|
+
export declare class NATS extends Component {
|
|
7
|
+
#private;
|
|
8
|
+
/**
|
|
9
|
+
* NATS servers
|
|
10
|
+
* @protected
|
|
11
|
+
*/
|
|
12
|
+
protected readonly servers: string | string[];
|
|
13
|
+
/**
|
|
14
|
+
* NATS message codec
|
|
15
|
+
* @protected
|
|
16
|
+
*/
|
|
17
|
+
protected readonly codec: Codec<unknown>;
|
|
18
|
+
/**
|
|
19
|
+
* Sets the number of milliseconds the client should wait for a server
|
|
20
|
+
* handshake to be established
|
|
21
|
+
* @protected
|
|
22
|
+
*/
|
|
23
|
+
protected readonly timeout?: number;
|
|
24
|
+
/**
|
|
25
|
+
* Set to a client authentication token. Note that these tokens are
|
|
26
|
+
* a specific authentication strategy on the nats-server
|
|
27
|
+
* @protected
|
|
28
|
+
*/
|
|
29
|
+
protected readonly token?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Sets the username for a client connection
|
|
32
|
+
* @protected
|
|
33
|
+
*/
|
|
34
|
+
protected readonly user?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Sets the password for a client connection
|
|
37
|
+
* @protected
|
|
38
|
+
*/
|
|
39
|
+
protected readonly pass?: string;
|
|
40
|
+
/**
|
|
41
|
+
* When set to `true` the client will print protocol messages that it receives
|
|
42
|
+
* or sends to the server
|
|
43
|
+
* @protected
|
|
44
|
+
*/
|
|
45
|
+
protected readonly debug?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Sets the maximum count of ping commands that can be awaiting a response
|
|
48
|
+
* before rasing a stale connection status notification and initiating a reconnect
|
|
49
|
+
* @protected
|
|
50
|
+
*/
|
|
51
|
+
protected readonly maxPingOut?: number;
|
|
52
|
+
/**
|
|
53
|
+
* Sets the maximum count of per-server reconnect attempts before giving up.
|
|
54
|
+
* Set to `-1` to never give up
|
|
55
|
+
*
|
|
56
|
+
* @default 10
|
|
57
|
+
* @protected
|
|
58
|
+
*/
|
|
59
|
+
protected readonly maxReconnectAttempts?: number;
|
|
60
|
+
/**
|
|
61
|
+
* Sets the client name. When set, the server monitoring pages will display
|
|
62
|
+
* this name when referring to this client
|
|
63
|
+
* @protected
|
|
64
|
+
*/
|
|
65
|
+
protected readonly name?: string;
|
|
66
|
+
/**
|
|
67
|
+
* When set to true, messages published by this client will not match
|
|
68
|
+
* this client's subscriptions, so the client is guaranteed to never
|
|
69
|
+
* receive self-published messages on a subject that it is listening on
|
|
70
|
+
* @protected
|
|
71
|
+
*/
|
|
72
|
+
protected readonly noEcho?: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* If set to true, the client will not randomize its server connection list
|
|
75
|
+
* @protected
|
|
76
|
+
*/
|
|
77
|
+
protected readonly noRandomize?: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Sets the number of milliseconds between client initiated ping commands
|
|
80
|
+
*
|
|
81
|
+
* @default 2 minutes.
|
|
82
|
+
* @protected
|
|
83
|
+
*/
|
|
84
|
+
protected readonly pingInterval?: number;
|
|
85
|
+
/**
|
|
86
|
+
* When set to true, the server will attempt to reconnect so long as doesn't prevent it
|
|
87
|
+
*
|
|
88
|
+
* @default true
|
|
89
|
+
* @protected
|
|
90
|
+
*/
|
|
91
|
+
protected readonly reconnect?: boolean;
|
|
92
|
+
/**
|
|
93
|
+
* Initializer
|
|
94
|
+
* @protected
|
|
95
|
+
*/
|
|
96
|
+
protected init(): Promise<void>;
|
|
97
|
+
/**
|
|
98
|
+
* Destroyer
|
|
99
|
+
* @protected
|
|
100
|
+
*/
|
|
101
|
+
protected destroy(): Promise<void>;
|
|
102
|
+
/**
|
|
103
|
+
* Publishes the specified data to the specified subject.
|
|
104
|
+
* @param subject
|
|
105
|
+
* @param payload
|
|
106
|
+
*/
|
|
107
|
+
publish(subject: string, payload: any): void;
|
|
108
|
+
/**
|
|
109
|
+
* Publishes a request with specified data in the specified subject expecting a
|
|
110
|
+
* response before timeout milliseconds. The api returns a
|
|
111
|
+
* Promise that resolves when the first response to the request is received. If
|
|
112
|
+
* there are no responders (a subscription) listening on the request subject,
|
|
113
|
+
* the request will fail as soon as the server processes it
|
|
114
|
+
* @param subject
|
|
115
|
+
* @param payload
|
|
116
|
+
* @param timeout
|
|
117
|
+
*/
|
|
118
|
+
request(subject: string, payload?: any, timeout?: number): Promise<any>;
|
|
119
|
+
/**
|
|
120
|
+
* Subscribe expresses interest in the specified subject. The subject may
|
|
121
|
+
* have wildcards. Messages are delivered to the callback.
|
|
122
|
+
* If the subscription receives request, the callback return's value will respond to requester
|
|
123
|
+
* @param subject
|
|
124
|
+
* @param callback
|
|
125
|
+
* @param subscribeOptions
|
|
126
|
+
*/
|
|
127
|
+
subscribe(subject: string, callback: (data: any) => any | Promise<any>, subscribeOptions?: SubscribeOptions): Subscription;
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=NATS.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NATS.d.ts","sourceRoot":"","sources":["../../src/components/NATS.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,SAAS,EAET,uBAAuB,EAE1B,MAAM,UAAU,CAAA;AAEjB,OAAO,EAAC,KAAK,KAAK,EAA6C,YAAY,EAAC,MAAM,MAAM,CAAA;AACxF,OAAO,EAAC,gBAAgB,EAAC,MAAM,2BAA2B,CAAA;AAO1D,OAAO,EAAC,iBAAiB,EAAC,MAAM,iCAAiC,CAAA;AAGjE,eAAO,MAAM,sBAAsB,EAAE,uBAAuB,CAAC,iBAAiB,CAkB7E,CAAA;AAED,qBAAa,IAAK,SAAQ,SAAS;;IAC/B;;;OAGG;IAEH,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IAE7C;;;OAGG;IAKH,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,CAAA;IAExC;;;;OAIG;IAEH,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;IAEnC;;;;OAIG;IAEH,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;IAEjC;;;OAGG;IAEH,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;IAEhC;;;OAGG;IAEH,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;IAEhC;;;;OAIG;IAEH,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAA;IAElC;;;;OAIG;IAEH,SAAS,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAA;IAEtC;;;;;;OAMG;IAEH,SAAS,CAAC,QAAQ,CAAC,oBAAoB,CAAC,EAAE,MAAM,CAAA;IAEhD;;;;OAIG;IAEH,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;IAEhC;;;;;OAKG;IAEH,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAA;IAEnC;;;OAGG;IAEH,SAAS,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,CAAA;IAExC;;;;;OAKG;IAEH,SAAS,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAA;IAExC;;;;;OAKG;IAEH,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAA;IAQtC;;;OAGG;cACa,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAkBrC;;;OAGG;cACa,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAIxC;;;;OAIG;IACI,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,GAAG,IAAI;IAInD;;;;;;;;;OASG;IACU,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IA4BpF;;;;;;;OAOG;IACI,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,EAAE,gBAAgB,CAAC,EAAE,gBAAgB,GAAG,YAAY;CAYpI"}
|
|
@@ -0,0 +1,205 @@
|
|
|
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
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.NATS = exports.buildNatsClientOptions = void 0;
|
|
13
|
+
const lakutata_1 = require("lakutata");
|
|
14
|
+
const di_1 = require("lakutata/decorator/di");
|
|
15
|
+
const nats_1 = require("nats");
|
|
16
|
+
const NatsBadRequestException_1 = require("../exceptions/NatsBadRequestException");
|
|
17
|
+
const NatsForbiddenException_1 = require("../exceptions/NatsForbiddenException");
|
|
18
|
+
const NatsNotFoundException_1 = require("../exceptions/NatsNotFoundException");
|
|
19
|
+
const NatsRequestTimeoutException_1 = require("../exceptions/NatsRequestTimeoutException");
|
|
20
|
+
const NatsNoRespondersAvailableException_1 = require("../exceptions/NatsNoRespondersAvailableException");
|
|
21
|
+
const NatsInternalServerException_1 = require("../exceptions/NatsInternalServerException");
|
|
22
|
+
const JSONCodec_1 = require("../codecs/JSONCodec");
|
|
23
|
+
const buildNatsClientOptions = (options) => {
|
|
24
|
+
return {
|
|
25
|
+
class: NATS,
|
|
26
|
+
servers: options.servers,
|
|
27
|
+
codec: options.codec,
|
|
28
|
+
timeout: options.timeout,
|
|
29
|
+
token: options.token,
|
|
30
|
+
user: options.user,
|
|
31
|
+
pass: options.pass,
|
|
32
|
+
debug: options.debug,
|
|
33
|
+
maxPingOut: options.maxPingOut,
|
|
34
|
+
maxReconnectAttempts: options.maxReconnectAttempts,
|
|
35
|
+
name: options.name,
|
|
36
|
+
noEcho: options.noEcho,
|
|
37
|
+
noRandomize: options.noRandomize,
|
|
38
|
+
pingInterval: options.pingInterval,
|
|
39
|
+
reconnect: options.reconnect
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
exports.buildNatsClientOptions = buildNatsClientOptions;
|
|
43
|
+
class NATS extends lakutata_1.Component {
|
|
44
|
+
/**
|
|
45
|
+
* NATS client instance
|
|
46
|
+
* @private
|
|
47
|
+
*/
|
|
48
|
+
#conn;
|
|
49
|
+
/**
|
|
50
|
+
* Initializer
|
|
51
|
+
* @protected
|
|
52
|
+
*/
|
|
53
|
+
async init() {
|
|
54
|
+
this.#conn = await (0, nats_1.connect)({
|
|
55
|
+
servers: this.servers,
|
|
56
|
+
user: this.user,
|
|
57
|
+
pass: this.pass,
|
|
58
|
+
timeout: this.timeout,
|
|
59
|
+
token: this.token,
|
|
60
|
+
debug: this.debug,
|
|
61
|
+
maxPingOut: this.maxPingOut,
|
|
62
|
+
maxReconnectAttempts: this.maxReconnectAttempts,
|
|
63
|
+
name: this.name,
|
|
64
|
+
noEcho: this.noEcho,
|
|
65
|
+
noRandomize: this.noRandomize,
|
|
66
|
+
pingInterval: this.pingInterval,
|
|
67
|
+
reconnect: this.reconnect
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Destroyer
|
|
72
|
+
* @protected
|
|
73
|
+
*/
|
|
74
|
+
async destroy() {
|
|
75
|
+
await this.#conn.close();
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Publishes the specified data to the specified subject.
|
|
79
|
+
* @param subject
|
|
80
|
+
* @param payload
|
|
81
|
+
*/
|
|
82
|
+
publish(subject, payload) {
|
|
83
|
+
return this.#conn.publish(subject, this.codec.encode(payload));
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Publishes a request with specified data in the specified subject expecting a
|
|
87
|
+
* response before timeout milliseconds. The api returns a
|
|
88
|
+
* Promise that resolves when the first response to the request is received. If
|
|
89
|
+
* there are no responders (a subscription) listening on the request subject,
|
|
90
|
+
* the request will fail as soon as the server processes it
|
|
91
|
+
* @param subject
|
|
92
|
+
* @param payload
|
|
93
|
+
* @param timeout
|
|
94
|
+
*/
|
|
95
|
+
async request(subject, payload, timeout) {
|
|
96
|
+
try {
|
|
97
|
+
const response = await this.#conn.request(subject, this.codec.encode(payload), { timeout: timeout ? timeout : 0 });
|
|
98
|
+
return this.codec.decode(response.data);
|
|
99
|
+
}
|
|
100
|
+
catch (e) {
|
|
101
|
+
if (e.code) {
|
|
102
|
+
switch (e.code.toString()) {
|
|
103
|
+
case '400':
|
|
104
|
+
throw new NatsBadRequestException_1.NatsBadRequestException();
|
|
105
|
+
case '403':
|
|
106
|
+
throw new NatsForbiddenException_1.NatsForbiddenException();
|
|
107
|
+
case '404':
|
|
108
|
+
throw new NatsNotFoundException_1.NatsNotFoundException();
|
|
109
|
+
case '408':
|
|
110
|
+
throw new NatsRequestTimeoutException_1.NatsRequestTimeoutException();
|
|
111
|
+
case '503':
|
|
112
|
+
throw new NatsNoRespondersAvailableException_1.NatsNoRespondersAvailableException();
|
|
113
|
+
case '500':
|
|
114
|
+
throw new NatsInternalServerException_1.NatsInternalServerException();
|
|
115
|
+
default:
|
|
116
|
+
throw e;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
throw e;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Subscribe expresses interest in the specified subject. The subject may
|
|
126
|
+
* have wildcards. Messages are delivered to the callback.
|
|
127
|
+
* If the subscription receives request, the callback return's value will respond to requester
|
|
128
|
+
* @param subject
|
|
129
|
+
* @param callback
|
|
130
|
+
* @param subscribeOptions
|
|
131
|
+
*/
|
|
132
|
+
subscribe(subject, callback, subscribeOptions) {
|
|
133
|
+
return this.#conn.subscribe(subject, {
|
|
134
|
+
queue: subscribeOptions?.queue,
|
|
135
|
+
max: subscribeOptions?.max,
|
|
136
|
+
callback: async (err, msg) => {
|
|
137
|
+
if (err)
|
|
138
|
+
this.emit('error', err);
|
|
139
|
+
const data = this.codec.decode(msg.data);
|
|
140
|
+
const result = await callback(data);
|
|
141
|
+
msg.respond(this.codec.encode(result));
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
exports.NATS = NATS;
|
|
147
|
+
__decorate([
|
|
148
|
+
(0, di_1.Configurable)(lakutata_1.DTO.Alternatives(lakutata_1.DTO.String(), lakutata_1.DTO.Array(lakutata_1.DTO.String())).required()),
|
|
149
|
+
__metadata("design:type", Object)
|
|
150
|
+
], NATS.prototype, "servers", void 0);
|
|
151
|
+
__decorate([
|
|
152
|
+
(0, di_1.Configurable)(lakutata_1.DTO.Object({
|
|
153
|
+
encode: lakutata_1.DTO.Function().arity(1).required(),
|
|
154
|
+
decode: lakutata_1.DTO.Function().arity(1).required()
|
|
155
|
+
}).optional().default((0, JSONCodec_1.JSONCodec)())),
|
|
156
|
+
__metadata("design:type", Object)
|
|
157
|
+
], NATS.prototype, "codec", void 0);
|
|
158
|
+
__decorate([
|
|
159
|
+
(0, di_1.Configurable)(lakutata_1.DTO.Number().integer().optional()),
|
|
160
|
+
__metadata("design:type", Number)
|
|
161
|
+
], NATS.prototype, "timeout", void 0);
|
|
162
|
+
__decorate([
|
|
163
|
+
(0, di_1.Configurable)(lakutata_1.DTO.String().optional()),
|
|
164
|
+
__metadata("design:type", String)
|
|
165
|
+
], NATS.prototype, "token", void 0);
|
|
166
|
+
__decorate([
|
|
167
|
+
(0, di_1.Configurable)(lakutata_1.DTO.String().optional()),
|
|
168
|
+
__metadata("design:type", String)
|
|
169
|
+
], NATS.prototype, "user", void 0);
|
|
170
|
+
__decorate([
|
|
171
|
+
(0, di_1.Configurable)(lakutata_1.DTO.String().optional()),
|
|
172
|
+
__metadata("design:type", String)
|
|
173
|
+
], NATS.prototype, "pass", void 0);
|
|
174
|
+
__decorate([
|
|
175
|
+
(0, di_1.Configurable)(lakutata_1.DTO.Boolean().optional()),
|
|
176
|
+
__metadata("design:type", Boolean)
|
|
177
|
+
], NATS.prototype, "debug", void 0);
|
|
178
|
+
__decorate([
|
|
179
|
+
(0, di_1.Configurable)(lakutata_1.DTO.Number().optional()),
|
|
180
|
+
__metadata("design:type", Number)
|
|
181
|
+
], NATS.prototype, "maxPingOut", void 0);
|
|
182
|
+
__decorate([
|
|
183
|
+
(0, di_1.Configurable)(lakutata_1.DTO.Number().optional().default(10)),
|
|
184
|
+
__metadata("design:type", Number)
|
|
185
|
+
], NATS.prototype, "maxReconnectAttempts", void 0);
|
|
186
|
+
__decorate([
|
|
187
|
+
(0, di_1.Configurable)(lakutata_1.DTO.String().optional()),
|
|
188
|
+
__metadata("design:type", String)
|
|
189
|
+
], NATS.prototype, "name", void 0);
|
|
190
|
+
__decorate([
|
|
191
|
+
(0, di_1.Configurable)(lakutata_1.DTO.Boolean().optional()),
|
|
192
|
+
__metadata("design:type", Boolean)
|
|
193
|
+
], NATS.prototype, "noEcho", void 0);
|
|
194
|
+
__decorate([
|
|
195
|
+
(0, di_1.Configurable)(lakutata_1.DTO.Boolean().optional()),
|
|
196
|
+
__metadata("design:type", Boolean)
|
|
197
|
+
], NATS.prototype, "noRandomize", void 0);
|
|
198
|
+
__decorate([
|
|
199
|
+
(0, di_1.Configurable)(lakutata_1.DTO.Number().optional().default(1000 * 60 * 2)),
|
|
200
|
+
__metadata("design:type", Number)
|
|
201
|
+
], NATS.prototype, "pingInterval", void 0);
|
|
202
|
+
__decorate([
|
|
203
|
+
(0, di_1.Configurable)(lakutata_1.DTO.Boolean().optional().default(true)),
|
|
204
|
+
__metadata("design:type", Boolean)
|
|
205
|
+
], NATS.prototype, "reconnect", void 0);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ServiceEntrypoint } from 'lakutata/com/entrypoint';
|
|
2
|
+
/**
|
|
3
|
+
* Setup service based on NATS
|
|
4
|
+
* @param natsComponentName
|
|
5
|
+
* @constructor
|
|
6
|
+
*/
|
|
7
|
+
export declare function SetupNatsServiceEntrypoint(natsComponentName: string): ServiceEntrypoint;
|
|
8
|
+
//# sourceMappingURL=SetupNatsServiceEntrypoint.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SetupNatsServiceEntrypoint.d.ts","sourceRoot":"","sources":["../../src/entrypoints/SetupNatsServiceEntrypoint.ts"],"names":[],"mappings":"AAAA,OAAO,EAGH,iBAAiB,EAEpB,MAAM,yBAAyB,CAAA;AAIhC;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,iBAAiB,EAAE,MAAM,GAAG,iBAAiB,CASvF"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SetupNatsServiceEntrypoint = void 0;
|
|
4
|
+
const entrypoint_1 = require("lakutata/com/entrypoint");
|
|
5
|
+
/**
|
|
6
|
+
* Setup service based on NATS
|
|
7
|
+
* @param natsComponentName
|
|
8
|
+
* @constructor
|
|
9
|
+
*/
|
|
10
|
+
function SetupNatsServiceEntrypoint(natsComponentName) {
|
|
11
|
+
return (0, entrypoint_1.BuildServiceEntrypoint)(async (module, handler) => {
|
|
12
|
+
const nats = await module.getObject(natsComponentName);
|
|
13
|
+
nats.subscribe(module.appId, async (incomeRequestPayload) => {
|
|
14
|
+
return await handler(new entrypoint_1.ServiceContext({
|
|
15
|
+
data: incomeRequestPayload
|
|
16
|
+
}));
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
exports.SetupNatsServiceEntrypoint = SetupNatsServiceEntrypoint;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NatsBadRequestException.d.ts","sourceRoot":"","sources":["../../src/exceptions/NatsBadRequestException.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,UAAU,CAAA;AAElC,qBAAa,uBAAwB,SAAQ,SAAS;IAC3C,KAAK,EAAE,MAAM,GAAG,MAAM,CAAuB;IAC7C,OAAO,EAAE,MAAM,CAAgB;IAC/B,UAAU,EAAE,MAAM,CAAM;CAClC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NatsBadRequestException = void 0;
|
|
4
|
+
const lakutata_1 = require("lakutata");
|
|
5
|
+
class NatsBadRequestException extends lakutata_1.Exception {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(...arguments);
|
|
8
|
+
this.errno = 'E_NATS_BAD_REQUEST';
|
|
9
|
+
this.message = 'Bad Request';
|
|
10
|
+
this.statusCode = 400;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.NatsBadRequestException = NatsBadRequestException;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NatsForbiddenException.d.ts","sourceRoot":"","sources":["../../src/exceptions/NatsForbiddenException.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,UAAU,CAAA;AAElC,qBAAa,sBAAuB,SAAQ,SAAS;IAC1C,KAAK,EAAE,MAAM,GAAG,MAAM,CAAqB;IAC3C,OAAO,EAAE,MAAM,CAAc;IAC7B,UAAU,EAAE,MAAM,CAAM;CAClC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NatsForbiddenException = void 0;
|
|
4
|
+
const lakutata_1 = require("lakutata");
|
|
5
|
+
class NatsForbiddenException extends lakutata_1.Exception {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(...arguments);
|
|
8
|
+
this.errno = 'E_NATS_FORBIDDEN';
|
|
9
|
+
this.message = 'Forbidden';
|
|
10
|
+
this.statusCode = 403;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.NatsForbiddenException = NatsForbiddenException;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NatsInternalServerException.d.ts","sourceRoot":"","sources":["../../src/exceptions/NatsInternalServerException.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,UAAU,CAAA;AAElC,qBAAa,2BAA4B,SAAQ,SAAS;IAC/C,KAAK,EAAE,MAAM,GAAG,MAAM,CAA2B;IACjD,OAAO,EAAE,MAAM,CAA0B;IACzC,UAAU,EAAE,MAAM,CAAM;CAClC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NatsInternalServerException = void 0;
|
|
4
|
+
const lakutata_1 = require("lakutata");
|
|
5
|
+
class NatsInternalServerException extends lakutata_1.Exception {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(...arguments);
|
|
8
|
+
this.errno = 'E_NATS_INTERNAL_SERVER';
|
|
9
|
+
this.message = 'Internal Server Error';
|
|
10
|
+
this.statusCode = 500;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.NatsInternalServerException = NatsInternalServerException;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NatsNoRespondersAvailableException.d.ts","sourceRoot":"","sources":["../../src/exceptions/NatsNoRespondersAvailableException.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,UAAU,CAAA;AAElC,qBAAa,kCAAmC,SAAQ,SAAS;IACtD,KAAK,EAAE,MAAM,GAAG,MAAM,CAAmC;IACzD,OAAO,EAAE,MAAM,CAA4B;IAC3C,UAAU,EAAE,MAAM,CAAM;CAClC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NatsNoRespondersAvailableException = void 0;
|
|
4
|
+
const lakutata_1 = require("lakutata");
|
|
5
|
+
class NatsNoRespondersAvailableException extends lakutata_1.Exception {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(...arguments);
|
|
8
|
+
this.errno = 'E_NATS_NO_RESPONDERS_AVAILABLE';
|
|
9
|
+
this.message = 'No Responders Available';
|
|
10
|
+
this.statusCode = 503;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.NatsNoRespondersAvailableException = NatsNoRespondersAvailableException;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NatsNotFoundException.d.ts","sourceRoot":"","sources":["../../src/exceptions/NatsNotFoundException.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,UAAU,CAAA;AAElC,qBAAa,qBAAsB,SAAQ,SAAS;IACzC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAqB;IAC3C,OAAO,EAAE,MAAM,CAAsB;IACrC,UAAU,EAAE,MAAM,CAAM;CAClC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NatsNotFoundException = void 0;
|
|
4
|
+
const lakutata_1 = require("lakutata");
|
|
5
|
+
class NatsNotFoundException extends lakutata_1.Exception {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(...arguments);
|
|
8
|
+
this.errno = 'E_NATS_NOT_FOUND';
|
|
9
|
+
this.message = 'Subject Not Found';
|
|
10
|
+
this.statusCode = 404;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.NatsNotFoundException = NatsNotFoundException;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NatsRequestTimeoutException.d.ts","sourceRoot":"","sources":["../../src/exceptions/NatsRequestTimeoutException.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,UAAU,CAAA;AAElC,qBAAa,2BAA4B,SAAQ,SAAS;IAC/C,KAAK,EAAE,MAAM,GAAG,MAAM,CAA2B;IACjD,OAAO,EAAE,MAAM,CAAoB;IACnC,UAAU,EAAE,MAAM,CAAM;CAClC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NatsRequestTimeoutException = void 0;
|
|
4
|
+
const lakutata_1 = require("lakutata");
|
|
5
|
+
class NatsRequestTimeoutException extends lakutata_1.Exception {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(...arguments);
|
|
8
|
+
this.errno = 'E_NATS_REQUEST_TIMEOUT';
|
|
9
|
+
this.message = 'Request Timeout';
|
|
10
|
+
this.statusCode = 408;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.NatsRequestTimeoutException = NatsRequestTimeoutException;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Codec } from 'nats';
|
|
2
|
+
export interface NatsClientOptions {
|
|
3
|
+
servers: string | string[];
|
|
4
|
+
codec?: Codec<unknown>;
|
|
5
|
+
timeout?: number;
|
|
6
|
+
token?: string;
|
|
7
|
+
user?: string;
|
|
8
|
+
pass?: string;
|
|
9
|
+
debug?: boolean;
|
|
10
|
+
maxPingOut?: number;
|
|
11
|
+
maxReconnectAttempts?: number;
|
|
12
|
+
name?: string;
|
|
13
|
+
noEcho?: boolean;
|
|
14
|
+
noRandomize?: boolean;
|
|
15
|
+
pingInterval?: number;
|
|
16
|
+
reconnect?: boolean;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=NatsClientOptions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NatsClientOptions.d.ts","sourceRoot":"","sources":["../../src/interfaces/NatsClientOptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAC,MAAM,MAAM,CAAA;AAE1B,MAAM,WAAW,iBAAiB;IAC9B,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IAC1B,KAAK,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,CAAA;IACtB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,oBAAoB,CAAC,EAAE,MAAM,CAAA;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,SAAS,CAAC,EAAE,OAAO,CAAA;CACtB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NatsTest.spec.d.ts","sourceRoot":"","sources":["../../src/tests/NatsTest.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,85 @@
|
|
|
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
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const lakutata_1 = require("lakutata");
|
|
13
|
+
const entrypoint_1 = require("lakutata/com/entrypoint");
|
|
14
|
+
const di_1 = require("lakutata/decorator/di");
|
|
15
|
+
const CommonExports_1 = require("../CommonExports");
|
|
16
|
+
const ctrl_1 = require("lakutata/decorator/ctrl");
|
|
17
|
+
class TestComponent extends lakutata_1.Component {
|
|
18
|
+
async init() {
|
|
19
|
+
// this.nats.subscribe('test-invoke', (msg) => {
|
|
20
|
+
// console.log('msg:', msg)
|
|
21
|
+
// return Date.now()
|
|
22
|
+
// })
|
|
23
|
+
// this.nats.subscribe('test', (data: any) => {
|
|
24
|
+
// console.log(data)
|
|
25
|
+
// })
|
|
26
|
+
//
|
|
27
|
+
// setInterval(async () => {
|
|
28
|
+
// this.nats.publish('test', 1234)
|
|
29
|
+
// console.log('res:', await this.nats.request('test-invoke', JSON.stringify({haha: true})), 1000000)
|
|
30
|
+
// }, 1)
|
|
31
|
+
console.log(await this.nats.request(this.app.appId, { test: true }));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
__decorate([
|
|
35
|
+
(0, di_1.Inject)(lakutata_1.Application),
|
|
36
|
+
__metadata("design:type", lakutata_1.Application)
|
|
37
|
+
], TestComponent.prototype, "app", void 0);
|
|
38
|
+
__decorate([
|
|
39
|
+
(0, di_1.Inject)('nats'),
|
|
40
|
+
__metadata("design:type", CommonExports_1.NATS)
|
|
41
|
+
], TestComponent.prototype, "nats", void 0);
|
|
42
|
+
class TestController extends entrypoint_1.Controller {
|
|
43
|
+
async test(inp) {
|
|
44
|
+
// return 'hahahah'
|
|
45
|
+
return {
|
|
46
|
+
test: true,
|
|
47
|
+
num: 1234,
|
|
48
|
+
sub: {
|
|
49
|
+
a: 1234,
|
|
50
|
+
b: '1234234',
|
|
51
|
+
c: [{ test: true }]
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
// return ['hahahah']
|
|
55
|
+
// return {
|
|
56
|
+
// test: 123456
|
|
57
|
+
// }
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
__decorate([
|
|
61
|
+
(0, ctrl_1.ServiceAction)({ test: true }),
|
|
62
|
+
__metadata("design:type", Function),
|
|
63
|
+
__metadata("design:paramtypes", [Object]),
|
|
64
|
+
__metadata("design:returntype", Promise)
|
|
65
|
+
], TestController.prototype, "test", null);
|
|
66
|
+
lakutata_1.Application.run({
|
|
67
|
+
id: 'test.app',
|
|
68
|
+
name: 'TestApp',
|
|
69
|
+
components: {
|
|
70
|
+
entrypoint: (0, entrypoint_1.BuildEntrypoints)({
|
|
71
|
+
controllers: [TestController],
|
|
72
|
+
service: (0, CommonExports_1.SetupNatsServiceEntrypoint)('nats')
|
|
73
|
+
}),
|
|
74
|
+
nats: (0, CommonExports_1.buildNatsClientOptions)({
|
|
75
|
+
servers: '127.0.0.1:4222'
|
|
76
|
+
}),
|
|
77
|
+
test: {
|
|
78
|
+
class: TestComponent
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
bootstrap: [
|
|
82
|
+
'entrypoint',
|
|
83
|
+
'test'
|
|
84
|
+
]
|
|
85
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SubscribeOptions.d.ts","sourceRoot":"","sources":["../../src/types/SubscribeOptions.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GAAG;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,GAAG,CAAC,EAAE,MAAM,CAAA;CACf,CAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lakutata/nats",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Lakutata NATS Client",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"lakutata",
|
|
7
|
+
"NATS",
|
|
8
|
+
"client"
|
|
9
|
+
],
|
|
10
|
+
"author": "myq1991 <myq1991@gmail.com>",
|
|
11
|
+
"homepage": "https://github.com/lakutata/lakutata-packages",
|
|
12
|
+
"license": "Apache-2.0",
|
|
13
|
+
"main": "./dist/CommonExports.js",
|
|
14
|
+
"types": "./dist/CommonExports.d.ts",
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
},
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/lakutata/lakutata-packages.git"
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"clean": "shx rm -rf ./dist",
|
|
24
|
+
"build": "tsc",
|
|
25
|
+
"rebuild": "npm run clean && npm run build",
|
|
26
|
+
"test": "bun src/tests/NatsTest.spec.ts"
|
|
27
|
+
},
|
|
28
|
+
"bugs": {
|
|
29
|
+
"url": "https://github.com/lakutata/lakutata-packages/issues"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"nats": "^2.29.3"
|
|
33
|
+
},
|
|
34
|
+
"gitHead": "30da3fc101c09b9f3495c90bc88ceae78401e64a"
|
|
35
|
+
}
|