@ubs-platform/crud-base 5.5.1 → 5.7.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/_monaembed/@ubs-platform/users-consts/package.json +1 -1
- package/dynamic-queue/src/dynamic-queue.d.ts +21 -0
- package/dynamic-queue/src/dynamic-queue.js +80 -0
- package/dynamic-queue/src/dynamic-queue.js.map +1 -0
- package/dynamic-queue/src/index.d.ts +1 -0
- package/dynamic-queue/src/index.js +18 -0
- package/dynamic-queue/src/index.js.map +1 -0
- package/microservice-setup-util/src/engine5/client.d.ts +20 -0
- package/microservice-setup-util/src/engine5/client.js +38 -0
- package/microservice-setup-util/src/engine5/client.js.map +1 -0
- package/microservice-setup-util/src/engine5/connection.d.ts +37 -0
- package/microservice-setup-util/src/engine5/connection.js +255 -0
- package/microservice-setup-util/src/engine5/connection.js.map +1 -0
- package/microservice-setup-util/src/engine5/payload.d.ts +18 -0
- package/microservice-setup-util/src/engine5/payload.js +12 -0
- package/microservice-setup-util/src/engine5/payload.js.map +1 -0
- package/microservice-setup-util/src/engine5/server.d.ts +21 -0
- package/microservice-setup-util/src/engine5/server.js +54 -0
- package/microservice-setup-util/src/engine5/server.js.map +1 -0
- package/microservice-setup-util/src/index.d.ts +4 -0
- package/microservice-setup-util/src/index.js +4 -0
- package/microservice-setup-util/src/index.js.map +1 -1
- package/microservice-setup-util/src/microservice-setup-util.d.ts +6 -1
- package/microservice-setup-util/src/microservice-setup-util.js +69 -5
- package/microservice-setup-util/src/microservice-setup-util.js.map +1 -1
- package/package.json +1 -1
- package/tsconfig.lib-publish.tsbuildinfo +1 -1
- package/users-microservice-helper/src/backend-jwt-utils.module.js +1 -6
- package/users-microservice-helper/src/backend-jwt-utils.module.js.map +1 -1
- package/users-microservice-helper/src/service/user.service.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@ubs-platform/users-consts","version":"5.
|
|
1
|
+
{"name":"@ubs-platform/users-consts","version":"5.7.0","description":"","repository":{"url":"https://github.com/ubs-platform/ubs-mona-mr"},"homepage":"https://github.com/ubs-platform/ubs-mona-mr","iksir":{"type":"LIBRARY","libraryMode":"EMBEDDED"},"scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"author":"","license":"ISC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Observable, ReplaySubject, Subject } from 'rxjs';
|
|
2
|
+
export interface QueueOrder {
|
|
3
|
+
key: number;
|
|
4
|
+
output: Observable<any>;
|
|
5
|
+
}
|
|
6
|
+
export interface QueueAction {
|
|
7
|
+
key: number;
|
|
8
|
+
actualTask: Observable<any>;
|
|
9
|
+
undoTask?: Observable<any>;
|
|
10
|
+
outputSubject: Subject<any>;
|
|
11
|
+
}
|
|
12
|
+
export declare class DynamicQueue {
|
|
13
|
+
private _tasks;
|
|
14
|
+
private _busy;
|
|
15
|
+
busyChange: ReplaySubject<boolean>;
|
|
16
|
+
constructor();
|
|
17
|
+
get busy(): boolean;
|
|
18
|
+
private setBusy;
|
|
19
|
+
push(newTask_: (() => any) | Observable<any> | Promise<any>): QueueOrder;
|
|
20
|
+
private runFirst;
|
|
21
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DynamicQueue = void 0;
|
|
4
|
+
const rxjs_1 = require("rxjs");
|
|
5
|
+
class DynamicQueue {
|
|
6
|
+
constructor() {
|
|
7
|
+
this._tasks = [];
|
|
8
|
+
this._busy = false;
|
|
9
|
+
this.busyChange = new rxjs_1.ReplaySubject(1);
|
|
10
|
+
this.setBusy(false);
|
|
11
|
+
}
|
|
12
|
+
get busy() {
|
|
13
|
+
return this._busy;
|
|
14
|
+
}
|
|
15
|
+
setBusy(b) {
|
|
16
|
+
this._busy = b;
|
|
17
|
+
this.busyChange.next(b);
|
|
18
|
+
}
|
|
19
|
+
push(newTask_) {
|
|
20
|
+
let newTask;
|
|
21
|
+
if (newTask_ instanceof Function) {
|
|
22
|
+
newTask = new rxjs_1.Observable((subscriber) => {
|
|
23
|
+
try {
|
|
24
|
+
const result = newTask_();
|
|
25
|
+
if (result instanceof Promise) {
|
|
26
|
+
result
|
|
27
|
+
.then((a) => subscriber.next(a))
|
|
28
|
+
.catch((e) => subscriber.error(e));
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
subscriber.next(result);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
subscriber.error(error);
|
|
36
|
+
}
|
|
37
|
+
subscriber.complete();
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
newTask = (0, rxjs_1.from)(newTask_);
|
|
42
|
+
}
|
|
43
|
+
const task = {
|
|
44
|
+
key: this._tasks.length,
|
|
45
|
+
actualTask: newTask,
|
|
46
|
+
outputSubject: new rxjs_1.Subject(),
|
|
47
|
+
};
|
|
48
|
+
this._tasks.push(task);
|
|
49
|
+
if (!this.busy) {
|
|
50
|
+
this.setBusy(true);
|
|
51
|
+
this.runFirst();
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
key: task.key,
|
|
55
|
+
output: task.outputSubject.asObservable(),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
runFirst() {
|
|
59
|
+
const firstStart = this._tasks.splice(0, 1)?.[0];
|
|
60
|
+
if (firstStart) {
|
|
61
|
+
firstStart.actualTask.subscribe({
|
|
62
|
+
next: (a) => {
|
|
63
|
+
firstStart.outputSubject.next(a);
|
|
64
|
+
},
|
|
65
|
+
error: (error) => {
|
|
66
|
+
firstStart.outputSubject.error(error);
|
|
67
|
+
},
|
|
68
|
+
complete: () => {
|
|
69
|
+
firstStart.outputSubject.complete();
|
|
70
|
+
this.runFirst();
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
this.setBusy(false);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.DynamicQueue = DynamicQueue;
|
|
80
|
+
//# sourceMappingURL=dynamic-queue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dynamic-queue.js","sourceRoot":"","sources":["../../../../../libs/dynamic-queue/src/dynamic-queue.ts"],"names":[],"mappings":";;;AACA,+BAA4E;AAkB5E,MAAa,YAAY;IAqBvB;QAjBQ,WAAM,GAAkB,EAAE,CAAC;QAK3B,UAAK,GAAG,KAAK,CAAC;QAKtB,eAAU,GAAG,IAAI,oBAAa,CAAU,CAAC,CAAC,CAAC;QAQzC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACtB,CAAC;IAKD,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAKO,OAAO,CAAC,CAAU;QACxB,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC;QACf,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC1B,CAAC;IAOD,IAAI,CAAC,QAAsD;QACzD,IAAI,OAAO,CAAC;QAEZ,IAAI,QAAQ,YAAY,QAAQ,EAAE,CAAC;YACjC,OAAO,GAAG,IAAI,iBAAU,CAAC,CAAC,UAAU,EAAE,EAAE;gBACtC,IAAI,CAAC;oBACH,MAAM,MAAM,GAAG,QAAQ,EAAE,CAAC;oBAC1B,IAAI,MAAM,YAAY,OAAO,EAAE,CAAC;wBAC9B,MAAM;6BACH,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;6BAC/B,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;oBACvC,CAAC;yBAAM,CAAC;wBACN,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;oBAC1B,CAAC;gBACH,CAAC;gBAAC,OAAO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CAAC,QAAQ,EAAE,CAAC;gBAClB,CAAC;aACF,CAAC,CAAC;QACL,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QACtB,CAAC;IACH,CAAC;CACF;AA5GD,oCA4GC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dynamic-queue';
|
|
@@ -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("./dynamic-queue"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../libs/dynamic-queue/src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAAgC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Engine5Connection } from './connection';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
interface E5NestClientConnectionOptions {
|
|
4
|
+
host: string;
|
|
5
|
+
port: string | number;
|
|
6
|
+
instanceId?: string;
|
|
7
|
+
instanceGroup?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare class E5NestClient {
|
|
10
|
+
private connectionInfo;
|
|
11
|
+
static appGlobalE5InstanceId: string;
|
|
12
|
+
connection: Engine5Connection;
|
|
13
|
+
constructor(connectionInfo: E5NestClientConnectionOptions);
|
|
14
|
+
subscribeToResponseOf(): void;
|
|
15
|
+
unwrap(): any;
|
|
16
|
+
emit<TResult = any, TInput = any>(pattern: any, data: TInput): Observable<TResult>;
|
|
17
|
+
send<TResult = any, TInput = any>(pattern: any, data: TInput): Observable<TResult>;
|
|
18
|
+
close(): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.E5NestClient = void 0;
|
|
4
|
+
const connection_1 = require("./connection");
|
|
5
|
+
const rxjs_1 = require("rxjs");
|
|
6
|
+
const crypto_1 = require("crypto");
|
|
7
|
+
class E5NestClient {
|
|
8
|
+
constructor(connectionInfo) {
|
|
9
|
+
this.connectionInfo = connectionInfo;
|
|
10
|
+
const { host, port, instanceId, instanceGroup } = connectionInfo;
|
|
11
|
+
this.connection = connection_1.Engine5Connection.create(host, port, instanceGroup || instanceId || E5NestClient.appGlobalE5InstanceId, E5NestClient.appGlobalE5InstanceId);
|
|
12
|
+
this.connection
|
|
13
|
+
.init();
|
|
14
|
+
}
|
|
15
|
+
subscribeToResponseOf() {
|
|
16
|
+
}
|
|
17
|
+
unwrap() {
|
|
18
|
+
return this.connection;
|
|
19
|
+
}
|
|
20
|
+
emit(pattern, data) {
|
|
21
|
+
console.info("Sending event: " + pattern);
|
|
22
|
+
return (0, rxjs_1.from)(this.connection.sendEvent(pattern, data));
|
|
23
|
+
}
|
|
24
|
+
send(pattern, data) {
|
|
25
|
+
return new rxjs_1.Observable((a) => {
|
|
26
|
+
this.connection.sendRequest(pattern, data).then((result) => {
|
|
27
|
+
a.next(result);
|
|
28
|
+
a.complete();
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
async close() {
|
|
33
|
+
await this.connection.close();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.E5NestClient = E5NestClient;
|
|
37
|
+
E5NestClient.appGlobalE5InstanceId = 'nest_client' + (0, crypto_1.randomUUID)();
|
|
38
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../../../../libs/microservice-setup-util/src/engine5/client.ts"],"names":[],"mappings":";;;AACA,6CAAiD;AACjD,+BAAwC;AACxC,mCAAoC;AAUpC,MAAa,YAAY;IAGrB,YAAoB,cAA6C;QAA7C,mBAAc,GAAd,cAAc,CAA+B;QAC7D,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,aAAa,EAAE,GAAG,cAAc,CAAA;QAChE,IAAI,CAAC,UAAU,GAAG,8BAAiB,CAAC,MAAM,CACtC,IAAI,EACJ,IAAI,EACJ,aAAa,IAAI,UAAU,IAAI,YAAY,CAAC,qBAAqB,EACjE,YAAY,CAAC,qBAAqB,CACrC,CAAC;QACF,IAAI,CAAC,UAAU;aACV,IAAI,EAAE,CAAA;IACf,CAAC;IAED,qBAAqB;IAErB,CAAC;IAKD,MAAM;QACF,OAAO,IAAI,CAAC,UAAiB,CAAC;IAClC,CAAC;IAED,IAAI,CACA,OAAY,EACZ,IAAY;QAEZ,OAAO,CAAC,IAAI,CAAC,iBAAiB,GAAG,OAAO,CAAC,CAAA;QACzC,OAAO,IAAA,WAAI,EACP,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,CAAC,CACpB,CAAC;IAC7B,CAAC;IAED,IAAI,CACA,OAAY,EACZ,IAAY;QAEZ,OAAO,IAAI,iBAAU,CAAU,CAAC,CAAC,EAAE,EAAE;YACjC,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;gBACvD,CAAC,CAAC,IAAI,CAAC,MAAiB,CAAC,CAAC;gBAC1B,CAAC,CAAC,QAAQ,EAAE,CAAC;YACjB,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC;IAED,KAAK,CAAC,KAAK;QACP,MAAM,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;IAClC,CAAC;;AAlDL,oCAmDC;AAlDU,kCAAqB,GAAG,aAAa,GAAG,IAAA,mBAAU,GAAE,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import * as net from 'net';
|
|
2
|
+
import { Payload } from './payload';
|
|
3
|
+
import { DynamicQueue } from '@ubs-platform/dynamic-queue';
|
|
4
|
+
import { ReplaySubject } from 'rxjs';
|
|
5
|
+
export declare class Engine5Connection {
|
|
6
|
+
private host;
|
|
7
|
+
private port;
|
|
8
|
+
private instanceGroup?;
|
|
9
|
+
private instanceId?;
|
|
10
|
+
tcpClient: net.Socket;
|
|
11
|
+
connected: boolean;
|
|
12
|
+
connectionReady: ReplaySubject<"CONNECTING" | "CLOSED" | "CONNECTED">;
|
|
13
|
+
listeningSubjectCallbacks: {
|
|
14
|
+
[key: string]: ((a: any) => any)[];
|
|
15
|
+
};
|
|
16
|
+
ongoingRequestsToComplete: {
|
|
17
|
+
[key: string]: (a: any) => void;
|
|
18
|
+
};
|
|
19
|
+
readonly queue: DynamicQueue;
|
|
20
|
+
reconnectOnFail: boolean;
|
|
21
|
+
constructor(host: string, port: string | number, instanceGroup?: string | undefined, instanceId?: string | undefined);
|
|
22
|
+
runAtWhenConnected(ac: () => any): Promise<unknown>;
|
|
23
|
+
writePayload(p: Payload): Promise<Engine5Connection>;
|
|
24
|
+
listen(subject: string, cb: (a: any) => any): Promise<void>;
|
|
25
|
+
private writeListenCommand;
|
|
26
|
+
private messageIdGenerate;
|
|
27
|
+
sendRequest(subject: string, data: any): Promise<unknown>;
|
|
28
|
+
sendEvent(subject: string, data: any): Promise<void>;
|
|
29
|
+
init(): Promise<Engine5Connection>;
|
|
30
|
+
private _init;
|
|
31
|
+
private startConnection;
|
|
32
|
+
private processIncomingData;
|
|
33
|
+
private processReceivedEvent;
|
|
34
|
+
close(): Promise<void>;
|
|
35
|
+
private static globalE5Connections;
|
|
36
|
+
static create(host: string, port: string | number, instanceGroup?: string, instanceId?: string): Engine5Connection;
|
|
37
|
+
}
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Engine5Connection = void 0;
|
|
4
|
+
const net = require("net");
|
|
5
|
+
const msgpack_1 = require("@msgpack/msgpack");
|
|
6
|
+
const dynamic_queue_1 = require("@ubs-platform/dynamic-queue");
|
|
7
|
+
const rxjs_1 = require("rxjs");
|
|
8
|
+
class Engine5Connection {
|
|
9
|
+
constructor(host, port, instanceGroup, instanceId) {
|
|
10
|
+
this.host = host;
|
|
11
|
+
this.port = port;
|
|
12
|
+
this.instanceGroup = instanceGroup;
|
|
13
|
+
this.instanceId = instanceId;
|
|
14
|
+
this.tcpClient = new net.Socket();
|
|
15
|
+
this.connected = false;
|
|
16
|
+
this.connectionReady = new rxjs_1.ReplaySubject(1);
|
|
17
|
+
this.listeningSubjectCallbacks = {};
|
|
18
|
+
this.ongoingRequestsToComplete = {};
|
|
19
|
+
this.queue = new dynamic_queue_1.DynamicQueue();
|
|
20
|
+
this.reconnectOnFail = false;
|
|
21
|
+
this.connectionReady.next("CLOSED");
|
|
22
|
+
this.queue.push(async () => {
|
|
23
|
+
await this.runAtWhenConnected(() => {
|
|
24
|
+
"This is for prevent add some events or requests before connection";
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
runAtWhenConnected(ac) {
|
|
29
|
+
let completed = false;
|
|
30
|
+
return new Promise((ok, fail) => {
|
|
31
|
+
let subscription = null;
|
|
32
|
+
subscription = this.connectionReady.subscribe(async (a) => {
|
|
33
|
+
if (!completed && a == "CONNECTED") {
|
|
34
|
+
completed = true;
|
|
35
|
+
subscription?.unsubscribe();
|
|
36
|
+
try {
|
|
37
|
+
const result = await ac();
|
|
38
|
+
ok(result);
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
fail(e);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
else if (completed) {
|
|
45
|
+
subscription?.unsubscribe();
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
async writePayload(p) {
|
|
51
|
+
return new Promise((ok, fail) => {
|
|
52
|
+
this.queue.push(() => {
|
|
53
|
+
try {
|
|
54
|
+
const buff = Buffer.from([...(0, msgpack_1.encode)(p), 4]);
|
|
55
|
+
this.tcpClient.write(buff, (e) => {
|
|
56
|
+
if (e)
|
|
57
|
+
fail(e);
|
|
58
|
+
else
|
|
59
|
+
ok(this);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
console.error(error);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
async listen(subject, cb) {
|
|
69
|
+
console.info("Listening Subject: " + subject);
|
|
70
|
+
this.queue.push(async () => {
|
|
71
|
+
await this.writeListenCommand(subject);
|
|
72
|
+
const ls = this.listeningSubjectCallbacks[subject] || [];
|
|
73
|
+
ls.push(cb);
|
|
74
|
+
this.listeningSubjectCallbacks[subject] = ls;
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
async writeListenCommand(subject) {
|
|
78
|
+
await this.writePayload({
|
|
79
|
+
Command: 'LISTEN',
|
|
80
|
+
Subject: subject,
|
|
81
|
+
MessageId: this.messageIdGenerate(),
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
messageIdGenerate() {
|
|
85
|
+
return Date.now() + '_' + (Math.random() * 100000).toFixed();
|
|
86
|
+
}
|
|
87
|
+
async sendRequest(subject, data) {
|
|
88
|
+
const messageId = Date.now() + '_' + (Math.random() * 100000).toFixed();
|
|
89
|
+
if (!this.connected) {
|
|
90
|
+
await this.init();
|
|
91
|
+
}
|
|
92
|
+
await this.writePayload({
|
|
93
|
+
Command: 'REQUEST',
|
|
94
|
+
Subject: subject,
|
|
95
|
+
Content: JSON.stringify(data),
|
|
96
|
+
MessageId: messageId,
|
|
97
|
+
});
|
|
98
|
+
return new Promise((ok, fail) => {
|
|
99
|
+
this.ongoingRequestsToComplete[messageId] = (response) => {
|
|
100
|
+
if (response.Content) {
|
|
101
|
+
const jsonObj = JSON.parse(response.Content);
|
|
102
|
+
ok(jsonObj);
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
ok(undefined);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
async sendEvent(subject, data) {
|
|
111
|
+
await this.writePayload({
|
|
112
|
+
Command: 'EVENT',
|
|
113
|
+
Subject: subject,
|
|
114
|
+
Content: JSON.stringify(data),
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
async init() {
|
|
118
|
+
let completed = false;
|
|
119
|
+
return new Promise((ok, fail) => {
|
|
120
|
+
let subscription = null;
|
|
121
|
+
subscription = this.connectionReady.subscribe((status) => {
|
|
122
|
+
if (completed) {
|
|
123
|
+
subscription?.unsubscribe();
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
if (status == "CLOSED") {
|
|
127
|
+
this._init((v) => {
|
|
128
|
+
completed = true;
|
|
129
|
+
subscription?.unsubscribe();
|
|
130
|
+
ok(v);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
this.runAtWhenConnected(() => {
|
|
135
|
+
completed = true;
|
|
136
|
+
subscription?.unsubscribe();
|
|
137
|
+
ok(this);
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
_init(ok) {
|
|
145
|
+
this.connectionReady.next("CONNECTING");
|
|
146
|
+
console.info('Connecting to server');
|
|
147
|
+
const client = this.tcpClient;
|
|
148
|
+
let currentBuff = [];
|
|
149
|
+
client.on('data', (data) => {
|
|
150
|
+
this.queue.push(() => {
|
|
151
|
+
let newBuffData = [...currentBuff, ...data];
|
|
152
|
+
let splitByteIndex = newBuffData.indexOf(4);
|
|
153
|
+
while (splitByteIndex > -1) {
|
|
154
|
+
const popped = newBuffData.slice(0, splitByteIndex);
|
|
155
|
+
this.processIncomingData(popped, ok);
|
|
156
|
+
newBuffData = newBuffData.slice(splitByteIndex + 1);
|
|
157
|
+
splitByteIndex = newBuffData.indexOf(4);
|
|
158
|
+
}
|
|
159
|
+
currentBuff = newBuffData;
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
client.on('error', (err) => {
|
|
163
|
+
console.error(`Error occured ${err}`);
|
|
164
|
+
});
|
|
165
|
+
client.on('close', async () => {
|
|
166
|
+
this.connected = false;
|
|
167
|
+
this.connectionReady.next("CLOSED");
|
|
168
|
+
console.log('Connection closed');
|
|
169
|
+
if (this.reconnectOnFail) {
|
|
170
|
+
try {
|
|
171
|
+
console.log('Client will try to connect again Engine5 after 5 seconds');
|
|
172
|
+
setTimeout(() => {
|
|
173
|
+
this.init().then().catch(e => console.error(e));
|
|
174
|
+
}, 5000);
|
|
175
|
+
}
|
|
176
|
+
catch (ex) {
|
|
177
|
+
console.error(ex);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
client.connect(parseInt(this.port), this.host, () => {
|
|
182
|
+
this.startConnection();
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
startConnection() {
|
|
186
|
+
this.writePayload({
|
|
187
|
+
Command: 'CONNECT',
|
|
188
|
+
InstanceId: this.instanceId || '',
|
|
189
|
+
InstanceGroup: this.instanceGroup || this.instanceId
|
|
190
|
+
});
|
|
191
|
+
const alreadyListeningSubjects = Object.keys(this.listeningSubjectCallbacks);
|
|
192
|
+
for (let alsIndex = 0; alsIndex < alreadyListeningSubjects.length; alsIndex++) {
|
|
193
|
+
const als = alreadyListeningSubjects[alsIndex];
|
|
194
|
+
this.writeListenCommand(als).then(() => console.info("Listening subject again: " + als)).catch(console.error);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
async processIncomingData(data, promiseResolveFunc) {
|
|
198
|
+
const decoded = (0, msgpack_1.decode)(data);
|
|
199
|
+
if (decoded.Command == 'CONNECT_SUCCESS') {
|
|
200
|
+
this.connected = true;
|
|
201
|
+
this.connectionReady.next("CONNECTED");
|
|
202
|
+
this.instanceId = decoded.InstanceId;
|
|
203
|
+
this.instanceGroup = decoded.InstanceGroup;
|
|
204
|
+
promiseResolveFunc?.(this);
|
|
205
|
+
console.info('Connected Successfully');
|
|
206
|
+
}
|
|
207
|
+
else if (decoded.Command == 'EVENT') {
|
|
208
|
+
console.info('Event recieved', decoded.Subject);
|
|
209
|
+
this.processReceivedEvent(decoded);
|
|
210
|
+
}
|
|
211
|
+
else if (decoded.Command == 'REQUEST') {
|
|
212
|
+
console.info('Request recieved: ', decoded.Subject);
|
|
213
|
+
try {
|
|
214
|
+
const ac = await this.listeningSubjectCallbacks[decoded.Subject][0](JSON.parse(decoded.Content));
|
|
215
|
+
await this.writePayload({
|
|
216
|
+
Command: 'RESPONSE',
|
|
217
|
+
Content: JSON.stringify(ac),
|
|
218
|
+
MessageId: this.messageIdGenerate(),
|
|
219
|
+
Subject: decoded.Subject,
|
|
220
|
+
ResponseOfMessageId: decoded.MessageId,
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
catch (ex) {
|
|
224
|
+
console.error(ex);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
else if (decoded.Command == 'RESPONSE') {
|
|
228
|
+
this.ongoingRequestsToComplete[decoded.ResponseOfMessageId](decoded);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
processReceivedEvent(decoded) {
|
|
232
|
+
const cbs = this.listeningSubjectCallbacks[decoded.Subject] || [];
|
|
233
|
+
for (let callbackIndex = 0; callbackIndex < cbs.length; callbackIndex++) {
|
|
234
|
+
const callback = cbs[callbackIndex];
|
|
235
|
+
callback(JSON.parse(decoded.Content));
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
async close() {
|
|
239
|
+
debugger;
|
|
240
|
+
console.info("E5JSCL - Connection is about to be closed");
|
|
241
|
+
this.reconnectOnFail = false;
|
|
242
|
+
await this.writePayload({ "Command": "CLOSE" });
|
|
243
|
+
}
|
|
244
|
+
static create(host, port, instanceGroup, instanceId) {
|
|
245
|
+
const key = `${instanceGroup}(${instanceId})@${host}:${port}`;
|
|
246
|
+
if (!this.globalE5Connections[key]) {
|
|
247
|
+
const nk = new Engine5Connection(host, port, instanceGroup, instanceId);
|
|
248
|
+
this.globalE5Connections[key] = nk;
|
|
249
|
+
}
|
|
250
|
+
return this.globalE5Connections[key];
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
exports.Engine5Connection = Engine5Connection;
|
|
254
|
+
Engine5Connection.globalE5Connections = {};
|
|
255
|
+
//# sourceMappingURL=connection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../../../../../../libs/microservice-setup-util/src/engine5/connection.ts"],"names":[],"mappings":";;;AACA,2BAA2B;AAE3B,8CAAkD;AAClD,+DAA2D;AAE3D,+BAAqC;AAGrC,MAAa,iBAAiB;IAW1B,YACY,IAAY,EACZ,IAAqB,EACrB,aAAsB,EACtB,UAAmB;QAHnB,SAAI,GAAJ,IAAI,CAAQ;QACZ,SAAI,GAAJ,IAAI,CAAiB;QACrB,kBAAa,GAAb,aAAa,CAAS;QACtB,eAAU,GAAV,UAAU,CAAS;QAd/B,cAAS,GAAG,IAAI,GAAG,CAAC,MAAM,EAAE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;AAfkB,qCAAmB,GAAyC,EAAE,AAA3C,CAA4C"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare const CtConnect = "CONNECT";
|
|
2
|
+
export declare const CtConnectSuccess = "CONNECT_SUCCESS";
|
|
3
|
+
export declare const CtReceived = "RECEIVED";
|
|
4
|
+
export declare const CtEvent = "EVENT";
|
|
5
|
+
export declare const CtRequest = "REQUEST";
|
|
6
|
+
export declare const CtResponse = "RESPONSE";
|
|
7
|
+
export declare const CtListen = "LISTEN";
|
|
8
|
+
export declare const CtClose = "CLOSE";
|
|
9
|
+
export type CommandType = typeof CtConnect | typeof CtConnectSuccess | typeof CtReceived | typeof CtEvent | typeof CtRequest | typeof CtResponse | typeof CtListen | typeof CtClose;
|
|
10
|
+
export interface Payload {
|
|
11
|
+
Command: CommandType;
|
|
12
|
+
Content?: string;
|
|
13
|
+
Subject?: string;
|
|
14
|
+
InstanceId?: string;
|
|
15
|
+
MessageId?: string;
|
|
16
|
+
ResponseOfMessageId?: string;
|
|
17
|
+
InstanceGroup?: string;
|
|
18
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CtClose = exports.CtListen = exports.CtResponse = exports.CtRequest = exports.CtEvent = exports.CtReceived = exports.CtConnectSuccess = exports.CtConnect = void 0;
|
|
4
|
+
exports.CtConnect = "CONNECT";
|
|
5
|
+
exports.CtConnectSuccess = "CONNECT_SUCCESS";
|
|
6
|
+
exports.CtReceived = "RECEIVED";
|
|
7
|
+
exports.CtEvent = "EVENT";
|
|
8
|
+
exports.CtRequest = "REQUEST";
|
|
9
|
+
exports.CtResponse = "RESPONSE";
|
|
10
|
+
exports.CtListen = "LISTEN";
|
|
11
|
+
exports.CtClose = "CLOSE";
|
|
12
|
+
//# sourceMappingURL=payload.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payload.js","sourceRoot":"","sources":["../../../../../../libs/microservice-setup-util/src/engine5/payload.ts"],"names":[],"mappings":";;;AAAa,QAAA,SAAS,GAAG,SAAS,CAAC;AACtB,QAAA,gBAAgB,GAAG,iBAAiB,CAAC;AACrC,QAAA,UAAU,GAAG,UAAU,CAAC;AACxB,QAAA,OAAO,GAAG,OAAO,CAAC;AAClB,QAAA,SAAS,GAAG,SAAS,CAAC;AACtB,QAAA,UAAU,GAAG,UAAU,CAAC;AACxB,QAAA,QAAQ,GAAG,QAAQ,CAAC;AACpB,QAAA,OAAO,GAAG,OAAO,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { MessageHandler, ReadPacket, WritePacket } from '@nestjs/microservices';
|
|
2
|
+
import { CustomTransportStrategy, Server } from '@nestjs/microservices';
|
|
3
|
+
import { Engine5Connection } from './connection';
|
|
4
|
+
import { ReplaySubject } from 'rxjs';
|
|
5
|
+
export declare class E5NestServer extends Server implements CustomTransportStrategy {
|
|
6
|
+
private host;
|
|
7
|
+
private port;
|
|
8
|
+
private instanceGroup?;
|
|
9
|
+
private instanceId?;
|
|
10
|
+
readonly id: `${string}-${string}-${string}-${string}-${string}`;
|
|
11
|
+
connection: Engine5Connection;
|
|
12
|
+
connectionIsReady: ReplaySubject<unknown>;
|
|
13
|
+
constructor(host: string, port: string | number, instanceGroup?: string | undefined, instanceId?: string | undefined);
|
|
14
|
+
listen(callback: () => void): void;
|
|
15
|
+
on<EventKey extends string = string, EventCallback extends Function = Function>(event: EventKey, callback: EventCallback): void;
|
|
16
|
+
close(): void;
|
|
17
|
+
unwrap<T>(): T;
|
|
18
|
+
protected dispatchEvent(packet: ReadPacket<any>): Promise<any>;
|
|
19
|
+
protected publish(packet: ReadPacket<any>, callback: (packet: WritePacket<any>) => void): () => void;
|
|
20
|
+
addHandler(pattern: any, callback: MessageHandler, isEventHandler?: boolean, extras?: Record<string, any>): void;
|
|
21
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.E5NestServer = void 0;
|
|
4
|
+
const microservices_1 = require("@nestjs/microservices");
|
|
5
|
+
const connection_1 = require("./connection");
|
|
6
|
+
const rxjs_1 = require("rxjs");
|
|
7
|
+
const crypto_1 = require("crypto");
|
|
8
|
+
class E5NestServer extends microservices_1.Server {
|
|
9
|
+
constructor(host, port, instanceGroup, instanceId) {
|
|
10
|
+
super();
|
|
11
|
+
this.host = host;
|
|
12
|
+
this.port = port;
|
|
13
|
+
this.instanceGroup = instanceGroup;
|
|
14
|
+
this.instanceId = instanceId;
|
|
15
|
+
this.id = (0, crypto_1.randomUUID)();
|
|
16
|
+
this.connectionIsReady = new rxjs_1.ReplaySubject(1);
|
|
17
|
+
if (!instanceId)
|
|
18
|
+
instanceId = 'nest_server' + (0, crypto_1.randomUUID)();
|
|
19
|
+
this.connection = connection_1.Engine5Connection.create(host, port, instanceGroup, instanceId);
|
|
20
|
+
}
|
|
21
|
+
listen(callback) {
|
|
22
|
+
this.connection.init().then(() => {
|
|
23
|
+
this.connectionIsReady.next(true);
|
|
24
|
+
callback();
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
on(event, callback) {
|
|
28
|
+
this.connection.listen(event, callback);
|
|
29
|
+
}
|
|
30
|
+
close() {
|
|
31
|
+
debugger;
|
|
32
|
+
this.connection.close();
|
|
33
|
+
}
|
|
34
|
+
unwrap() {
|
|
35
|
+
return this.connection;
|
|
36
|
+
}
|
|
37
|
+
dispatchEvent(packet) {
|
|
38
|
+
return this.connection.sendEvent(packet.pattern, packet.data);
|
|
39
|
+
}
|
|
40
|
+
publish(packet, callback) {
|
|
41
|
+
this.connection
|
|
42
|
+
.sendRequest(packet.pattern, packet.data)
|
|
43
|
+
.then((response) => callback({ response }));
|
|
44
|
+
return () => { };
|
|
45
|
+
}
|
|
46
|
+
addHandler(pattern, callback, isEventHandler, extras) {
|
|
47
|
+
let a = this.connectionIsReady.subscribe((isConnected) => {
|
|
48
|
+
this.connection.listen(pattern, callback);
|
|
49
|
+
a?.unsubscribe();
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.E5NestServer = E5NestServer;
|
|
54
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../../../../../libs/microservice-setup-util/src/engine5/server.ts"],"names":[],"mappings":";;;AAoBA,yDAAwE;AACxE,6CAAiD;AACjD,+BAAuD;AACvD,mCAAoC;AAGpC,MAAa,YAAa,SAAQ,sBAAM;IAOpC,YACY,IAAY,EACZ,IAAqB,EACrB,aAAsB,EACtB,UAAmB;QAE3B,KAAK,EAAE,CAAC;QALA,SAAI,GAAJ,IAAI,CAAQ;QACZ,SAAI,GAAJ,IAAI,CAAiB;QACrB,kBAAa,GAAb,aAAa,CAAS;QACtB,eAAU,GAAV,UAAU,CAAS;QAVtB,OAAE,GAAG,IAAA,mBAAU,GAAE,CAAC;QAE3B,sBAAiB,GAAG,IAAI,oBAAa,CAAC,CAAC,CAAC,CAAC;QAWrC,IAAI,CAAC,UAAU;YAAE,UAAU,GAAG,aAAa,GAAG,IAAA,mBAAU,GAAE,CAAC;QAE3D,IAAI,CAAC,UAAU,GAAG,8BAAiB,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,aAAa,EAAE,UAAU,CAAC,CAAC;IACtF,CAAC;IAID,MAAM,CAAC,QAAoB;QAGvB,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE;YAC7B,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;YACjC,QAAQ,EAAE,CAAC;QACf,CAAC,CAAC,CAAC;IACP,CAAC;IAED,EAAE,CAGA,KAAe,EAAE,QAAuB;QACtC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,EAAE,QAAe,CAAC,CAAC;IACnD,CAAC;IAKD,KAAK;QACD,QAAQ,CAAA;QACR,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;IAC5B,CAAC;IAiBD,MAAM;QACF,OAAO,IAAI,CAAC,UAAe,CAAC;IAChC,CAAC;IAES,aAAa,CAAC,MAAuB;QAC3C,OAAO,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;IAClE,CAAC;IAES,OAAO,CACb,MAAuB,EACvB,QAA4C;QAM5C,IAAI,CAAC,UAAU;aACV,WAAW,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC;aACxC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC;QAChD,OAAO,GAAG,EAAE,GAAG,CAAC,CAAC;IACrB,CAAC;IAED,UAAU,CAAC,OAAY,EAAE,QAAwB,EAAE,cAAwB,EAAE,MAA4B;QAGrG,IAAI,CAAC,GAAG,IAAI,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE,EAAE;YACrD,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,OAAO,EAAE,QAAe,CAAC,CAAC;YACjD,CAAC,EAAE,WAAW,EAAE,CAAC;QACrB,CAAC,CAAC,CAAA;IAEN,CAAC;CACJ;AA3FD,oCA2FC"}
|
|
@@ -15,4 +15,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./microservice-setup-util"), exports);
|
|
18
|
+
__exportStar(require("./engine5/connection"), exports);
|
|
19
|
+
__exportStar(require("./engine5/payload"), exports);
|
|
20
|
+
__exportStar(require("./engine5/server"), exports);
|
|
21
|
+
__exportStar(require("./engine5/client"), exports);
|
|
18
22
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../libs/microservice-setup-util/src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4DAA0C"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../libs/microservice-setup-util/src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4DAA0C;AAC1C,uDAAoC;AACpC,oDAAiC;AACjC,mDAAgC;AAChC,mDAAgC"}
|