@lad-tech/nsc-toolkit 2.0.4 → 2.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 +3 -3
- package/dist/Container.js +5 -10
- package/dist/Service.js +6 -2
- package/dist/types/Container.d.ts +1 -0
- package/dist/types/interfaces.d.ts +1 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
# [2.1.0](https://github.com/lad-tech/nsc-toolkit/compare/v2.0.5...v2.1.0) (2026-02-13)
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
###
|
|
4
|
+
### Features
|
|
5
5
|
|
|
6
|
-
*
|
|
6
|
+
* new race flar in method ([#171](https://github.com/lad-tech/nsc-toolkit/issues/171)) ([61885f5](https://github.com/lad-tech/nsc-toolkit/commit/61885f55829152f685b48c1158df46780196d594))
|
package/dist/Container.js
CHANGED
|
@@ -6,15 +6,10 @@ class Container {
|
|
|
6
6
|
constructor() {
|
|
7
7
|
this.container = new Map();
|
|
8
8
|
this.singletons = new Map();
|
|
9
|
+
this.initializedKeys = new Set();
|
|
9
10
|
}
|
|
10
11
|
buildDependency(key) {
|
|
11
|
-
|
|
12
|
-
if (this.isAdapterDependency(deepDependency.dependency)) {
|
|
13
|
-
return new deepDependency.dependency.value(...deepDependency.constructor);
|
|
14
|
-
}
|
|
15
|
-
if (this.isConstantDependency(deepDependency.dependency)) {
|
|
16
|
-
return deepDependency.dependency.value;
|
|
17
|
-
}
|
|
12
|
+
return this.getInstance(key);
|
|
18
13
|
}
|
|
19
14
|
inject(dependency) {
|
|
20
15
|
if (this.isServiceDependency(dependency)) {
|
|
@@ -107,14 +102,14 @@ class Container {
|
|
|
107
102
|
throw new Error(`Unknown dependency type for key ${key.toString()}`);
|
|
108
103
|
}
|
|
109
104
|
async initDependencies() {
|
|
110
|
-
var _a
|
|
105
|
+
var _a;
|
|
111
106
|
const initialized = [];
|
|
112
107
|
for await (const [key, dependency] of this.container) {
|
|
113
|
-
if (this.isAdapterDependency(dependency) && ((_a = dependency.options) === null || _a === void 0 ? void 0 : _a.init) && !this.
|
|
108
|
+
if (this.isAdapterDependency(dependency) && ((_a = dependency.options) === null || _a === void 0 ? void 0 : _a.init) && !this.initializedKeys.has(key)) {
|
|
114
109
|
const instance = this.getInstance(key);
|
|
115
110
|
await (instance === null || instance === void 0 ? void 0 : instance.init());
|
|
116
111
|
initialized.push(instance);
|
|
117
|
-
this.
|
|
112
|
+
this.initializedKeys.add(key);
|
|
118
113
|
}
|
|
119
114
|
}
|
|
120
115
|
return initialized;
|
package/dist/Service.js
CHANGED
|
@@ -460,13 +460,17 @@ class Service extends Root_1.Root {
|
|
|
460
460
|
const { methods } = this.options;
|
|
461
461
|
try {
|
|
462
462
|
methods.forEach(async (Method) => {
|
|
463
|
-
var _a;
|
|
463
|
+
var _a, _b, _c, _d, _e, _f;
|
|
464
464
|
if ((_a = Method.settings.options) === null || _a === void 0 ? void 0 : _a.useStream) {
|
|
465
465
|
this.httpMethods.set(Method.settings.action, Method);
|
|
466
466
|
return;
|
|
467
467
|
}
|
|
468
468
|
const subject = `${this.serviceName}.${Method.settings.action}`;
|
|
469
|
-
const
|
|
469
|
+
const isRace = (_b = Method.settings.options) === null || _b === void 0 ? void 0 : _b.race;
|
|
470
|
+
const isNotWebStreamRequest = !((_d = (_c = Method.settings.options) === null || _c === void 0 ? void 0 : _c.useStream) === null || _d === void 0 ? void 0 : _d.request);
|
|
471
|
+
const isNotWebStreamResponse = !((_f = (_e = Method.settings.options) === null || _e === void 0 ? void 0 : _e.useStream) === null || _f === void 0 ? void 0 : _f.response);
|
|
472
|
+
const queue = isRace && isNotWebStreamRequest && isNotWebStreamResponse ? {} : { queue: this.serviceName };
|
|
473
|
+
const subscription = this.broker.subscribe(subject, queue);
|
|
470
474
|
this.subscriptions.push(subscription);
|
|
471
475
|
for await (const message of subscription) {
|
|
472
476
|
const { payload, baggage } = (0, nats_1.JSONCodec)().decode(message.data);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lad-tech/nsc-toolkit",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Toolkit for create microservices around NATS",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "./dist/types/index.d.ts",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"@commitlint/cli": "^17.2.0",
|
|
16
16
|
"@commitlint/config-conventional": "^17.2.0",
|
|
17
17
|
"@semantic-release/changelog": "^6.0.2",
|
|
18
|
-
"@semantic-release/npm": "^
|
|
18
|
+
"@semantic-release/npm": "^13.1.4",
|
|
19
19
|
"@types/jest": "^27.5.2",
|
|
20
20
|
"@types/node": "^22.13.13",
|
|
21
21
|
"eslint": "^7.32.0",
|