@lad-tech/nsc-toolkit 0.5.2
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/.eslintrc.js +105 -0
- package/.github/workflows/publish-package-to-npmjs.yml +18 -0
- package/.prettierrc.json +9 -0
- package/LICENSE +21 -0
- package/README.md +118 -0
- package/dist/Client.js +198 -0
- package/dist/Client.js.map +1 -0
- package/dist/Method.js +7 -0
- package/dist/Method.js.map +1 -0
- package/dist/Root.js +66 -0
- package/dist/Root.js.map +1 -0
- package/dist/Service.js +387 -0
- package/dist/Service.js.map +1 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/injector.js +39 -0
- package/dist/injector.js.map +1 -0
- package/dist/interfaces.js +4 -0
- package/dist/interfaces.js.map +1 -0
- package/dist/types/Client.d.ts +25 -0
- package/dist/types/Method.d.ts +6 -0
- package/dist/types/Root.d.ts +26 -0
- package/dist/types/Service.d.ts +78 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/injector.d.ts +11 -0
- package/dist/types/interfaces.d.ts +72 -0
- package/examples/HttpGate/index.ts +61 -0
- package/examples/HttpGate/package-lock.json +835 -0
- package/examples/HttpGate/package.json +15 -0
- package/examples/LogicService/index.ts +16 -0
- package/examples/LogicService/interfaces.ts +10 -0
- package/examples/LogicService/methods/WeirdSum.ts +20 -0
- package/examples/LogicService/service.json +31 -0
- package/examples/LogicService/service.ts +15 -0
- package/examples/MathService/Untitled-1.json +62 -0
- package/examples/MathService/index.ts +22 -0
- package/examples/MathService/interfaces.ts +26 -0
- package/examples/MathService/methods/Fibonacci.ts +29 -0
- package/examples/MathService/methods/Sum.ts +16 -0
- package/examples/MathService/methods/SumStream.ts +18 -0
- package/examples/MathService/service.json +64 -0
- package/examples/MathService/service.ts +18 -0
- package/examples/SimpleCache.ts +21 -0
- package/examples/misc/trace_1.png +0 -0
- package/examples/misc/trace_2.png +0 -0
- package/package.json +41 -0
- package/src/Client.ts +237 -0
- package/src/Method.ts +7 -0
- package/src/Root.ts +69 -0
- package/src/Service.ts +419 -0
- package/src/index.ts +5 -0
- package/src/injector.ts +43 -0
- package/src/interfaces.ts +89 -0
- package/tsconfig.json +19 -0
package/dist/Service.js
ADDED
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Service = void 0;
|
|
4
|
+
const Root_1 = require("./Root");
|
|
5
|
+
const nats_1 = require("nats");
|
|
6
|
+
const sdk_trace_base_1 = require("@opentelemetry/sdk-trace-base");
|
|
7
|
+
const resources_1 = require("@opentelemetry/resources");
|
|
8
|
+
const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
|
|
9
|
+
const api_1 = require("@opentelemetry/api");
|
|
10
|
+
const injector_1 = require("./injector");
|
|
11
|
+
const exporter_jaeger_1 = require("@opentelemetry/exporter-jaeger");
|
|
12
|
+
const stream_1 = require("stream");
|
|
13
|
+
const toolbelt_1 = require("@lad-tech/toolbelt");
|
|
14
|
+
const http = require("http");
|
|
15
|
+
const os = require("os");
|
|
16
|
+
class Service extends Root_1.Root {
|
|
17
|
+
constructor(options) {
|
|
18
|
+
var _a;
|
|
19
|
+
super(options.brokerConnection, (_a = options.cache) === null || _a === void 0 ? void 0 : _a.service);
|
|
20
|
+
this.options = options;
|
|
21
|
+
this.emitter = {};
|
|
22
|
+
this.subscriptions = [];
|
|
23
|
+
this.httpMethods = new Map();
|
|
24
|
+
this.rootSpans = new Map();
|
|
25
|
+
this.serviceName = options.name;
|
|
26
|
+
this.logger.setLocation(this.serviceName);
|
|
27
|
+
if (options.events.length) {
|
|
28
|
+
this.emitter = options.events.reduce((result, action) => {
|
|
29
|
+
result[action] = ((params) => {
|
|
30
|
+
this.brocker.publish(`${options.name}.${String(action)}`, this.buildMessage(params));
|
|
31
|
+
});
|
|
32
|
+
return result;
|
|
33
|
+
}, this.emitter);
|
|
34
|
+
}
|
|
35
|
+
this.createTracer();
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Create global Tracer
|
|
39
|
+
*/
|
|
40
|
+
createTracer() {
|
|
41
|
+
const provider = new sdk_trace_base_1.BasicTracerProvider({
|
|
42
|
+
resource: new resources_1.Resource({
|
|
43
|
+
[semantic_conventions_1.SemanticResourceAttributes.SERVICE_NAME]: this.options.name,
|
|
44
|
+
}),
|
|
45
|
+
});
|
|
46
|
+
const exporter = new exporter_jaeger_1.JaegerExporter({
|
|
47
|
+
endpoint: this.getSettingFromEnv('OTEL_AGENT', false),
|
|
48
|
+
});
|
|
49
|
+
provider.addSpanProcessor(new sdk_trace_base_1.SimpleSpanProcessor(exporter));
|
|
50
|
+
provider.register();
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Wrapper for async methods. Create span
|
|
54
|
+
*/
|
|
55
|
+
async perform(func, funcContext, arg, tracer, context) {
|
|
56
|
+
const span = tracer.startSpan(func.name, undefined, context);
|
|
57
|
+
const query = func.apply(funcContext, arg);
|
|
58
|
+
query
|
|
59
|
+
.then(() => span.end())
|
|
60
|
+
.catch(error => {
|
|
61
|
+
span.setAttribute('error', true);
|
|
62
|
+
span.setAttribute('error.kind', error);
|
|
63
|
+
span.end();
|
|
64
|
+
throw error;
|
|
65
|
+
});
|
|
66
|
+
return query;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Creating an object to inject into Method (business logic)
|
|
70
|
+
*/
|
|
71
|
+
createObjectWithDependencies(action, tracer, baggage) {
|
|
72
|
+
const services = injector_1.ServiceContainer.get(action);
|
|
73
|
+
const dependences = {};
|
|
74
|
+
if (services === null || services === void 0 ? void 0 : services.size) {
|
|
75
|
+
services.forEach((Dependence, key) => {
|
|
76
|
+
dependences[key] = new Dependence(this.brocker, baggage, this.options.cache);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
const perform = this.perform;
|
|
80
|
+
const context = this.getContext(baggage);
|
|
81
|
+
const instances = injector_1.InstanceContainer.get(action);
|
|
82
|
+
if (instances === null || instances === void 0 ? void 0 : instances.size) {
|
|
83
|
+
instances.forEach((instance, key) => {
|
|
84
|
+
const trap = {
|
|
85
|
+
get(target, propKey, receiver) {
|
|
86
|
+
const method = Reflect.get(target, propKey, receiver);
|
|
87
|
+
if (typeof method === 'function') {
|
|
88
|
+
return function (...args) {
|
|
89
|
+
return perform(method, instance, args, tracer, context);
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
return method;
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
dependences[key] = new Proxy(instance, trap);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
dependences['logger'] = new toolbelt_1.Logs.Logger({ location: `${this.serviceName}.${action}`, metadata: baggage });
|
|
101
|
+
return dependences;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Create Method (business logic) context
|
|
105
|
+
*/
|
|
106
|
+
createMethodContext(Method, dependencies) {
|
|
107
|
+
const context = new Method();
|
|
108
|
+
for (const key in dependencies) {
|
|
109
|
+
context[key] = dependencies[key];
|
|
110
|
+
}
|
|
111
|
+
context['emitter'] = this.emitter;
|
|
112
|
+
return context;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Create Baggage from span. Expired one-on-one business logic call
|
|
116
|
+
*/
|
|
117
|
+
getNextBaggage(span, baggage) {
|
|
118
|
+
const { traceId, spanId, traceFlags } = span.spanContext();
|
|
119
|
+
return { traceId, spanId, traceFlags, expired: baggage === null || baggage === void 0 ? void 0 : baggage.expired };
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* If there is no baggage. For example, in HTTP Gateway
|
|
123
|
+
*/
|
|
124
|
+
getRootBaggage(subject, headers, ownTimeout) {
|
|
125
|
+
const baggage = headers ? this.getBaggageFromHTTPHeader(headers) : undefined;
|
|
126
|
+
const tracer = api_1.trace.getTracer('');
|
|
127
|
+
const context = this.getContext(baggage);
|
|
128
|
+
const span = tracer.startSpan(subject, undefined, context);
|
|
129
|
+
const newBaggage = this.getNextBaggage(span, baggage);
|
|
130
|
+
this.rootSpans.set(newBaggage.traceId, span);
|
|
131
|
+
return {
|
|
132
|
+
...newBaggage,
|
|
133
|
+
expired: this.getExpired(undefined, ownTimeout),
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* End root baggage
|
|
138
|
+
*/
|
|
139
|
+
endRootSpan(traceId, error) {
|
|
140
|
+
const span = this.rootSpans.get(traceId);
|
|
141
|
+
if (span) {
|
|
142
|
+
if (error) {
|
|
143
|
+
span.setAttribute('error', true);
|
|
144
|
+
span.setAttribute('error.kind', error.message);
|
|
145
|
+
}
|
|
146
|
+
span.end();
|
|
147
|
+
this.rootSpans.delete(traceId);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
buildService(Client, baggage) {
|
|
151
|
+
return new Client(this.brocker, baggage, this.options.cache);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Create service Method for send HTTP settings
|
|
155
|
+
*/
|
|
156
|
+
async runServiceMethodForHttp() {
|
|
157
|
+
const subject = `${this.serviceName}.${this.SERVICE_SUBJECT_FOR_GET_HTTP_SETTINGS}`;
|
|
158
|
+
const subscription = this.brocker.subscribe(subject, { queue: this.serviceName });
|
|
159
|
+
this.subscriptions.push(subscription);
|
|
160
|
+
for await (const message of subscription) {
|
|
161
|
+
message.respond(this.buildMessage(this.getHttpSettings()));
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
makeHttpSingleResponse(response, data) {
|
|
165
|
+
const responseData = JSON.stringify(data);
|
|
166
|
+
response
|
|
167
|
+
.writeHead(200, {
|
|
168
|
+
'Content-Length': Buffer.byteLength(responseData),
|
|
169
|
+
'Content-Type': 'application/json',
|
|
170
|
+
})
|
|
171
|
+
.write(responseData);
|
|
172
|
+
response.end();
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Create transform stream for convert object to string in stream pipeline
|
|
176
|
+
*/
|
|
177
|
+
getStringifyTransform() {
|
|
178
|
+
return new stream_1.Transform({
|
|
179
|
+
objectMode: true,
|
|
180
|
+
transform(chunk, encoding, push) {
|
|
181
|
+
try {
|
|
182
|
+
if (chunk instanceof Buffer) {
|
|
183
|
+
push(null, chunk);
|
|
184
|
+
}
|
|
185
|
+
const result = JSON.stringify(chunk);
|
|
186
|
+
push(null, result);
|
|
187
|
+
}
|
|
188
|
+
catch (error) {
|
|
189
|
+
push(error);
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
makeHttpStreamReponse(response, data) {
|
|
195
|
+
data.payload.on('error', error => {
|
|
196
|
+
this.logger.error(error);
|
|
197
|
+
});
|
|
198
|
+
response.writeHead(200, {
|
|
199
|
+
'Content-Type': 'application/octet-stream',
|
|
200
|
+
});
|
|
201
|
+
(0, stream_1.pipeline)(data.payload, this.getStringifyTransform(), response, () => { });
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Up HTTP server and start listen http routes
|
|
205
|
+
*/
|
|
206
|
+
async buildHTTPHandlers() {
|
|
207
|
+
await this.upHTTPServer();
|
|
208
|
+
this.runServiceMethodForHttp();
|
|
209
|
+
this.httpServer.on('request', async (request, response) => {
|
|
210
|
+
var _a, _b, _c, _d;
|
|
211
|
+
try {
|
|
212
|
+
if (request.method !== 'POST' || !request.url) {
|
|
213
|
+
throw new Error('Wrong http request');
|
|
214
|
+
}
|
|
215
|
+
const parsedUrl = request.url.split('/');
|
|
216
|
+
parsedUrl.shift();
|
|
217
|
+
const [serviceName, action, ...other] = parsedUrl;
|
|
218
|
+
const wrongServiceName = this.serviceName !== serviceName;
|
|
219
|
+
const Method = this.httpMethods.get(action);
|
|
220
|
+
if (other.length || wrongServiceName || !Method) {
|
|
221
|
+
throw new Error('Wrong url or service name or action');
|
|
222
|
+
}
|
|
223
|
+
const baggage = this.getBaggageFromHTTPHeader(request.headers);
|
|
224
|
+
if ((_b = (_a = Method.settings.options) === null || _a === void 0 ? void 0 : _a.useStream) === null || _b === void 0 ? void 0 : _b.request) {
|
|
225
|
+
const result = await this.handled(request, Method, baggage);
|
|
226
|
+
if (Method.settings.options.useStream.response && result.payload instanceof stream_1.Readable) {
|
|
227
|
+
this.makeHttpStreamReponse(response, result);
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
this.makeHttpSingleResponse(response, result);
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
const requestDataRaw = [];
|
|
234
|
+
for await (const data of request) {
|
|
235
|
+
requestDataRaw.push(data);
|
|
236
|
+
}
|
|
237
|
+
const requestData = Buffer.concat(requestDataRaw).toString();
|
|
238
|
+
const result = await this.handled(JSON.parse(requestData), Method, baggage);
|
|
239
|
+
if (((_d = (_c = Method.settings.options) === null || _c === void 0 ? void 0 : _c.useStream) === null || _d === void 0 ? void 0 : _d.response) && result.payload instanceof stream_1.Readable) {
|
|
240
|
+
this.makeHttpStreamReponse(response, result);
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
this.makeHttpSingleResponse(response, result);
|
|
244
|
+
}
|
|
245
|
+
catch (error) {
|
|
246
|
+
this.logger.error(error);
|
|
247
|
+
if (error instanceof Error) {
|
|
248
|
+
this.makeHttpSingleResponse(response, this.buildErrorMessage(error));
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
this.makeHttpSingleResponse(response, this.buildErrorMessage('System unknown error'));
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Run business logic for request
|
|
257
|
+
*/
|
|
258
|
+
async handled(payload, Method, baggage) {
|
|
259
|
+
const subject = `${this.serviceName}.${Method.settings.action}`;
|
|
260
|
+
const tracer = api_1.trace.getTracer('');
|
|
261
|
+
const context = this.getContext(baggage);
|
|
262
|
+
const span = tracer.startSpan(subject, undefined, context);
|
|
263
|
+
try {
|
|
264
|
+
const requestedDependencies = this.createObjectWithDependencies(Method.settings.action, tracer, this.getNextBaggage(span, baggage));
|
|
265
|
+
const context = this.createMethodContext(Method, requestedDependencies);
|
|
266
|
+
const result = {
|
|
267
|
+
payload: await context.handler.call(context, payload),
|
|
268
|
+
};
|
|
269
|
+
span.end();
|
|
270
|
+
return result;
|
|
271
|
+
}
|
|
272
|
+
catch (error) {
|
|
273
|
+
this.logger.error(error);
|
|
274
|
+
span.setAttribute('error', true);
|
|
275
|
+
span.setAttribute('error.kind', error);
|
|
276
|
+
span.end();
|
|
277
|
+
return this.buildErrorMessage(error);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Start service. Subscribe for subject and up http server
|
|
282
|
+
*/
|
|
283
|
+
async start() {
|
|
284
|
+
const { methods } = this.options;
|
|
285
|
+
try {
|
|
286
|
+
methods.forEach(async (Method) => {
|
|
287
|
+
var _a;
|
|
288
|
+
if ((_a = Method.settings.options) === null || _a === void 0 ? void 0 : _a.useStream) {
|
|
289
|
+
this.httpMethods.set(Method.settings.action, Method);
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
const subject = `${this.serviceName}.${Method.settings.action}`;
|
|
293
|
+
const subscription = this.brocker.subscribe(subject, { queue: this.serviceName });
|
|
294
|
+
this.subscriptions.push(subscription);
|
|
295
|
+
for await (const message of subscription) {
|
|
296
|
+
const { payload, baggage } = (0, nats_1.JSONCodec)().decode(message.data);
|
|
297
|
+
try {
|
|
298
|
+
const result = await this.handled(payload, Method, baggage);
|
|
299
|
+
message.respond(this.buildMessage(result));
|
|
300
|
+
}
|
|
301
|
+
catch (error) {
|
|
302
|
+
message.respond(this.buildMessage({ error: error.message }));
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
if (this.httpMethods.size > 0) {
|
|
307
|
+
await this.buildHTTPHandlers();
|
|
308
|
+
}
|
|
309
|
+
this.logger.info('Service successfully started!');
|
|
310
|
+
}
|
|
311
|
+
catch (error) {
|
|
312
|
+
if (error instanceof Error) {
|
|
313
|
+
this.logger.error(error.name, error.message);
|
|
314
|
+
}
|
|
315
|
+
else {
|
|
316
|
+
this.logger.error('An error occurred while starting the service', error);
|
|
317
|
+
}
|
|
318
|
+
process.exit(1);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Build message for broker
|
|
323
|
+
*/
|
|
324
|
+
buildMessage(message) {
|
|
325
|
+
return Buffer.from(JSON.stringify(message));
|
|
326
|
+
}
|
|
327
|
+
async upHTTPServer() {
|
|
328
|
+
this.httpServer = http.createServer();
|
|
329
|
+
this.ipAddress = this.getMyIpV4();
|
|
330
|
+
this.httpPort = await new Promise((resolve, reject) => {
|
|
331
|
+
this.httpServer = this.httpServer.listen(0, () => {
|
|
332
|
+
const address = this.httpServer.address();
|
|
333
|
+
if (!address) {
|
|
334
|
+
reject(new Error('Failed to get the port number: server is not listening'));
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
if (typeof address === 'string') {
|
|
338
|
+
reject(new Error('Listening on a unix socket is not supported'));
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
resolve(address.port);
|
|
342
|
+
});
|
|
343
|
+
});
|
|
344
|
+
return this.httpServer;
|
|
345
|
+
}
|
|
346
|
+
getMyIpV4() {
|
|
347
|
+
const networkInterfaces = os.networkInterfaces();
|
|
348
|
+
const myIpV4Address = Object.keys(networkInterfaces).reduce((ip, key) => {
|
|
349
|
+
if (ip) {
|
|
350
|
+
return ip;
|
|
351
|
+
}
|
|
352
|
+
const networkInterface = networkInterfaces[key];
|
|
353
|
+
const externalIpV4Interface = networkInterface === null || networkInterface === void 0 ? void 0 : networkInterface.find(item => !item.internal && item.family === 'IPv4');
|
|
354
|
+
if (externalIpV4Interface) {
|
|
355
|
+
return externalIpV4Interface.address;
|
|
356
|
+
}
|
|
357
|
+
return ip;
|
|
358
|
+
}, '');
|
|
359
|
+
if (!myIpV4Address) {
|
|
360
|
+
throw new Error('Failed to get service ip address');
|
|
361
|
+
}
|
|
362
|
+
return myIpV4Address;
|
|
363
|
+
}
|
|
364
|
+
getHttpSettings() {
|
|
365
|
+
return {
|
|
366
|
+
ip: this.ipAddress,
|
|
367
|
+
port: this.httpPort,
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
getBaggageFromHTTPHeader(headers) {
|
|
371
|
+
const expired = headers['nsc-expired'] ? +headers['nsc-expired'] : undefined;
|
|
372
|
+
const traceId = headers['nsc-trace-id'];
|
|
373
|
+
const spanId = headers['nsc-span-id'];
|
|
374
|
+
const traceFlags = headers['nsc-trace-flags'] ? +headers['nsc-trace-flags'] : undefined;
|
|
375
|
+
if (traceId && spanId && traceFlags) {
|
|
376
|
+
return {
|
|
377
|
+
traceId,
|
|
378
|
+
spanId,
|
|
379
|
+
traceFlags,
|
|
380
|
+
expired,
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
return undefined;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
exports.Service = Service;
|
|
387
|
+
//# sourceMappingURL=Service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Service.js","sourceRoot":"","sources":["../src/Service.ts"],"names":[],"mappings":";;;AAAA,iCAA8B;AAC9B,+BAA+C;AAE/C,kEAAyF;AACzF,wDAAoD;AACpD,8EAAiF;AACjF,4CAAkE;AAClE,yCAAiE;AACjE,oEAAgE;AAEhE,mCAAuD;AACvD,iDAA0C;AAC1C,6BAA6B;AAC7B,yBAAyB;AAEzB,MAAa,OAAgC,SAAQ,WAAI;IAUvD,YAAoB,OAA0B;;QAC5C,KAAK,CAAC,OAAO,CAAC,gBAAgB,EAAE,MAAA,OAAO,CAAC,KAAK,0CAAE,OAAO,CAAC,CAAC;QADtC,YAAO,GAAP,OAAO,CAAmB;QATvC,YAAO,GAAG,EAAO,CAAC;QAKjB,kBAAa,GAAmB,EAAE,CAAC;QACnC,gBAAW,GAAG,IAAI,GAAG,EA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C,CAAC;YACvG,IAAI,qBAAqB,EAAE;gBACzB,OAAO,qBAAqB,CAAC,OAAO,CAAC;aACtC;YACD,OAAO,EAAE,CAAC;QACZ,CAAC,EAAE,EAAE,CAAC,CAAC;QACP,IAAI,CAAC,aAAa,EAAE;YAClB,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;SACrD;QACD,OAAO,aAAa,CAAC;IACvB,CAAC;IAEO,eAAe;QACrB,OAAO;YACL,EAAE,EAAE,IAAI,CAAC,SAAS;YAClB,IAAI,EAAE,IAAI,CAAC,QAAQ;SACpB,CAAC;IACJ,CAAC;IAEO,wBAAwB,CAAC,OAAwB;QACvD,MAAM,OAAO,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QAC7E,MAAM,OAAO,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;QACxC,MAAM,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;QACtC,MAAM,UAAU,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QACxF,IAAI,OAAO,IAAI,MAAM,IAAI,UAAU,EAAE;YACnC,OAAO;gBACL,OAAO;gBACP,MAAM;gBACN,UAAU;gBACV,OAAO;aACR,CAAC;SACH;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;CACF;AAnZD,0BAmZC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
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("./Service"), exports);
|
|
18
|
+
__exportStar(require("./Client"), exports);
|
|
19
|
+
__exportStar(require("./Method"), exports);
|
|
20
|
+
__exportStar(require("./injector"), exports);
|
|
21
|
+
__exportStar(require("./interfaces"), exports);
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,2CAAyB;AACzB,2CAAyB;AACzB,6CAA2B;AAC3B,+CAA6B"}
|
package/dist/injector.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.instance = exports.service = exports.related = exports.InstanceContainer = exports.ServiceContainer = void 0;
|
|
4
|
+
require("reflect-metadata");
|
|
5
|
+
const serviceMetaKey = Symbol('services');
|
|
6
|
+
const instanceMetaKey = Symbol('instance');
|
|
7
|
+
exports.ServiceContainer = new Map();
|
|
8
|
+
exports.InstanceContainer = new Map();
|
|
9
|
+
function related(target) {
|
|
10
|
+
const dependencies = Reflect.getMetadata(serviceMetaKey, target.prototype);
|
|
11
|
+
const instances = Reflect.getMetadata(instanceMetaKey, target.prototype);
|
|
12
|
+
exports.ServiceContainer.set(target.settings.action, dependencies);
|
|
13
|
+
exports.InstanceContainer.set(target.settings.action, instances);
|
|
14
|
+
}
|
|
15
|
+
exports.related = related;
|
|
16
|
+
function setMetaData(item, itemName, metaKey, target) {
|
|
17
|
+
let storage;
|
|
18
|
+
if (Reflect.hasMetadata(metaKey, target)) {
|
|
19
|
+
storage = Reflect.getMetadata(metaKey, target);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
storage = new Map();
|
|
23
|
+
Reflect.defineMetadata(metaKey, storage, target);
|
|
24
|
+
}
|
|
25
|
+
storage.set(itemName, item);
|
|
26
|
+
}
|
|
27
|
+
function service(dependence) {
|
|
28
|
+
return function (target, dependenceName) {
|
|
29
|
+
setMetaData(dependence, dependenceName, serviceMetaKey, target);
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
exports.service = service;
|
|
33
|
+
function instance(instance) {
|
|
34
|
+
return function (target, instanceName) {
|
|
35
|
+
setMetaData(instance, instanceName, instanceMetaKey, target);
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
exports.instance = instance;
|
|
39
|
+
//# sourceMappingURL=injector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"injector.js","sourceRoot":"","sources":["../src/injector.ts"],"names":[],"mappings":";;;AAAA,4BAA0B;AAQ1B,MAAM,cAAc,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;AAC1C,MAAM,eAAe,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;AAE9B,QAAA,gBAAgB,GAAmC,IAAI,GAAG,EAAE,CAAC;AAC7D,QAAA,iBAAiB,GAAiC,IAAI,GAAG,EAAE,CAAC;AAEzE,SAAgB,OAAO,CAAmB,MAAS;IACjD,MAAM,YAAY,GAAsB,OAAO,CAAC,WAAW,CAAC,cAAc,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC;IAC9F,MAAM,SAAS,GAAoB,OAAO,CAAC,WAAW,CAAC,eAAe,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC;IAC1F,wBAAgB,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IAC3D,yBAAiB,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;AAC3D,CAAC;AALD,0BAKC;AAED,SAAS,WAAW,CAAC,IAA2B,EAAE,QAAgB,EAAE,OAAe,EAAE,MAAW;IAC9F,IAAI,OAA6B,CAAC;IAClC,IAAI,OAAO,CAAC,WAAW,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE;QACxC,OAAO,GAAG,OAAO,CAAC,WAAW,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;KAChD;SAAM;QACL,OAAO,GAAG,IAAI,GAAG,EAAE,CAAC;QACpB,OAAO,CAAC,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;KAClD;IACD,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;AAC9B,CAAC;AAED,SAAgB,OAAO,CAAC,UAAsB;IAC5C,OAAO,UAAU,MAAW,EAAE,cAAsB;QAClD,WAAW,CAAC,UAAU,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,CAAC,CAAC;IAClE,CAAC,CAAC;AACJ,CAAC;AAJD,0BAIC;AAED,SAAgB,QAAQ,CAAC,QAAkB;IACzC,OAAO,UAAU,MAAW,EAAE,YAAoB;QAChD,WAAW,CAAC,QAAQ,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,CAAC,CAAC;IAC/D,CAAC,CAAC;AACJ,CAAC;AAJD,4BAIC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":";AAAA,SAAS"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Root } from './Root';
|
|
3
|
+
import { NatsConnection } from 'nats';
|
|
4
|
+
import { Baggage, Emitter, Listener, CacheSettings, MethodSettings } from './interfaces';
|
|
5
|
+
import { Readable } from 'stream';
|
|
6
|
+
export declare class Client<E extends Emitter = {}> extends Root {
|
|
7
|
+
private serviceName;
|
|
8
|
+
private baggage?;
|
|
9
|
+
private cache?;
|
|
10
|
+
private subscriptions;
|
|
11
|
+
private REQUEST_HTTP_SETTINGS_TIMEOUT;
|
|
12
|
+
constructor(natsConnection: NatsConnection, serviceName: string, baggage?: Baggage | undefined, cache?: CacheSettings | undefined);
|
|
13
|
+
/**
|
|
14
|
+
* Make listener for service events. Auto subscribe and unsubscribe to subject
|
|
15
|
+
*/
|
|
16
|
+
getListener<A extends keyof E>(eventNames: Array<A>, queue?: string): Listener<E>;
|
|
17
|
+
private createCacheKey;
|
|
18
|
+
private validate;
|
|
19
|
+
protected request<R = any>(subject: string, data: Record<string, unknown> | Readable, { options, request, response }: MethodSettings): Promise<R>;
|
|
20
|
+
private getHTTPSettingsFromRemoteService;
|
|
21
|
+
private isStream;
|
|
22
|
+
private makeBrokerRequest;
|
|
23
|
+
private makeHttpRequest;
|
|
24
|
+
private convertBaggaggeToExternalHeader;
|
|
25
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Baggage, CacheService } from './interfaces';
|
|
2
|
+
import * as opentelemetry from '@opentelemetry/api';
|
|
3
|
+
import { NatsConnection } from 'nats';
|
|
4
|
+
import { Logs } from '@lad-tech/toolbelt';
|
|
5
|
+
export declare class Root {
|
|
6
|
+
protected brocker: NatsConnection;
|
|
7
|
+
protected SERVICE_SUBJECT_FOR_GET_HTTP_SETTINGS: string;
|
|
8
|
+
protected CACHE_SERVICE_KEY: string;
|
|
9
|
+
protected: any;
|
|
10
|
+
protected logger: Logs.Logger;
|
|
11
|
+
constructor(brocker: NatsConnection, cache?: CacheService);
|
|
12
|
+
protected castToNumber(value?: string): number;
|
|
13
|
+
protected getSettingFromEnv(name: string, required?: boolean): string | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* Make opentelemetry context from baggagge
|
|
16
|
+
*/
|
|
17
|
+
protected getContext(baggage?: Baggage): opentelemetry.Context | undefined;
|
|
18
|
+
protected getExpired(expired?: number, ownTimeout?: number): number;
|
|
19
|
+
protected buildErrorMessage(error: string | Error, code?: number): {
|
|
20
|
+
payload: null;
|
|
21
|
+
error: {
|
|
22
|
+
message: string;
|
|
23
|
+
code: number | undefined;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Root } from './Root';
|
|
2
|
+
import { Emitter, ServiceOptions, Baggage, ExternalBaggage, ClientService } from './interfaces';
|
|
3
|
+
export declare class Service<E extends Emitter = {}> extends Root {
|
|
4
|
+
private options;
|
|
5
|
+
emitter: E;
|
|
6
|
+
private serviceName;
|
|
7
|
+
private httpServer?;
|
|
8
|
+
protected httpPort?: number;
|
|
9
|
+
protected ipAddress?: string;
|
|
10
|
+
private subscriptions;
|
|
11
|
+
private httpMethods;
|
|
12
|
+
private rootSpans;
|
|
13
|
+
constructor(options: ServiceOptions<E>);
|
|
14
|
+
/**
|
|
15
|
+
* Create global Tracer
|
|
16
|
+
*/
|
|
17
|
+
private createTracer;
|
|
18
|
+
/**
|
|
19
|
+
* Wrapper for async methods. Create span
|
|
20
|
+
*/
|
|
21
|
+
private perform;
|
|
22
|
+
/**
|
|
23
|
+
* Creating an object to inject into Method (business logic)
|
|
24
|
+
*/
|
|
25
|
+
private createObjectWithDependencies;
|
|
26
|
+
/**
|
|
27
|
+
* Create Method (business logic) context
|
|
28
|
+
*/
|
|
29
|
+
private createMethodContext;
|
|
30
|
+
/**
|
|
31
|
+
* Create Baggage from span. Expired one-on-one business logic call
|
|
32
|
+
*/
|
|
33
|
+
private getNextBaggage;
|
|
34
|
+
/**
|
|
35
|
+
* If there is no baggage. For example, in HTTP Gateway
|
|
36
|
+
*/
|
|
37
|
+
getRootBaggage(subject: string, headers?: ExternalBaggage, ownTimeout?: number): {
|
|
38
|
+
expired: number;
|
|
39
|
+
traceId: string;
|
|
40
|
+
spanId: string;
|
|
41
|
+
traceFlags: number;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* End root baggage
|
|
45
|
+
*/
|
|
46
|
+
endRootSpan(traceId: string, error?: Error): void;
|
|
47
|
+
buildService<C extends ClientService>(Client: C, baggage?: Baggage): InstanceType<C>;
|
|
48
|
+
/**
|
|
49
|
+
* Create service Method for send HTTP settings
|
|
50
|
+
*/
|
|
51
|
+
private runServiceMethodForHttp;
|
|
52
|
+
private makeHttpSingleResponse;
|
|
53
|
+
/**
|
|
54
|
+
* Create transform stream for convert object to string in stream pipeline
|
|
55
|
+
*/
|
|
56
|
+
private getStringifyTransform;
|
|
57
|
+
private makeHttpStreamReponse;
|
|
58
|
+
/**
|
|
59
|
+
* Up HTTP server and start listen http routes
|
|
60
|
+
*/
|
|
61
|
+
private buildHTTPHandlers;
|
|
62
|
+
/**
|
|
63
|
+
* Run business logic for request
|
|
64
|
+
*/
|
|
65
|
+
private handled;
|
|
66
|
+
/**
|
|
67
|
+
* Start service. Subscribe for subject and up http server
|
|
68
|
+
*/
|
|
69
|
+
start(): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Build message for broker
|
|
72
|
+
*/
|
|
73
|
+
private buildMessage;
|
|
74
|
+
private upHTTPServer;
|
|
75
|
+
private getMyIpV4;
|
|
76
|
+
private getHttpSettings;
|
|
77
|
+
private getBaggageFromHTTPHeader;
|
|
78
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import { Method, ClientService } from './interfaces';
|
|
3
|
+
export declare type Instance = Record<string, (props: unknown) => Promise<unknown>>;
|
|
4
|
+
export declare type Dependence = ClientService<unknown>;
|
|
5
|
+
export declare type DependenceStorage = Map<string, Dependence>;
|
|
6
|
+
export declare type InstanceStorage = Map<string, Instance>;
|
|
7
|
+
export declare const ServiceContainer: Map<string, DependenceStorage>;
|
|
8
|
+
export declare const InstanceContainer: Map<string, InstanceStorage>;
|
|
9
|
+
export declare function related<T extends Method>(target: T): void;
|
|
10
|
+
export declare function service(dependence: Dependence): (target: any, dependenceName: string) => void;
|
|
11
|
+
export declare function instance(instance: Instance): (target: any, instanceName: string) => void;
|