@optimiser/common 1.0.365 → 1.0.367
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/dist/aws/awsservices.d.ts +39 -39
- package/dist/aws/awsservices.js +398 -398
- package/dist/constants.d.ts +35 -35
- package/dist/constants.js +36 -36
- package/dist/enums/databasetype.enum.d.ts +7 -7
- package/dist/enums/databasetype.enum.js +11 -11
- package/dist/enums/log.enum.d.ts +22 -22
- package/dist/enums/log.enum.js +26 -26
- package/dist/index.d.ts +25 -25
- package/dist/index.js +69 -61
- package/dist/lib/activity.d.ts +1 -1
- package/dist/lib/activity.js +44 -44
- package/dist/lib/calculatedbsize.d.ts +15 -15
- package/dist/lib/calculatedbsize.js +75 -75
- package/dist/lib/connection.d.ts +116 -116
- package/dist/lib/connection.js +595 -595
- package/dist/lib/convertfilesize.d.ts +2 -2
- package/dist/lib/convertfilesize.js +15 -15
- package/dist/lib/countrycode.d.ts +2 -2
- package/dist/lib/countrycode.js +255 -255
- package/dist/lib/event.d.ts +26 -26
- package/dist/lib/event.js +252 -248
- package/dist/lib/helper.d.ts +94 -93
- package/dist/lib/helper.js +1016 -1009
- package/dist/lib/memoryserverclient.d.ts +40 -40
- package/dist/lib/memoryserverclient.js +256 -252
- package/dist/lib/operautilitycommon.d.ts +65 -65
- package/dist/lib/operautilitycommon.js +620 -620
- package/dist/lib/redis.d.ts +21 -21
- package/dist/lib/redis.js +46 -46
- package/dist/lib/socketidfromredis.d.ts +3 -3
- package/dist/lib/socketidfromredis.js +5 -5
- package/dist/lib/taskutils.d.ts +40 -40
- package/dist/lib/taskutils.js +656 -656
- package/dist/lib/utility.d.ts +300 -298
- package/dist/lib/utility.js +5626 -5621
- package/dist/lib/validateRequest.d.ts +3 -3
- package/dist/lib/validateRequest.js +13 -13
- package/dist/logs/auditlog.d.ts +25 -25
- package/dist/logs/auditlog.js +1033 -1029
- package/dist/logs/checklogtable.d.ts +3 -3
- package/dist/logs/checklogtable.js +67 -67
- package/dist/logs/log.table.d.ts +7 -7
- package/dist/logs/log.table.js +127 -127
- package/dist/modals/connection.modal.d.ts +32 -32
- package/dist/modals/connection.modal.js +2 -2
- package/dist/modals/globalNotification.modal.d.ts +8 -8
- package/dist/modals/globalNotification.modal.js +2 -2
- package/dist/modals/log.modal.d.ts +64 -64
- package/dist/modals/log.modal.js +2 -2
- package/dist/modals/mail.modal.d.ts +6 -6
- package/dist/modals/mail.modal.js +2 -2
- package/dist/modals/notificationData.modal.d.ts +29 -29
- package/dist/modals/notificationData.modal.js +2 -2
- package/dist/modals/redisconfig.modal.d.ts +6 -6
- package/dist/modals/redisconfig.modal.js +2 -2
- package/dist/modals/sqsconfig.modal.d.ts +8 -8
- package/dist/modals/sqsconfig.modal.js +2 -2
- package/dist/modals/utility.modal.d.ts +17 -17
- package/dist/modals/utility.modal.js +2 -2
- package/dist/utility/crypto.d.ts +4 -4
- package/dist/utility/crypto.js +43 -43
- package/dist/utility/errorHandler.d.ts +30 -30
- package/dist/utility/errorHandler.js +24 -24
- package/dist/utility/errorHandlerForServices.d.ts +22 -22
- package/dist/utility/errorHandlerForServices.js +19 -19
- package/dist/utility/mail.d.ts +21 -21
- package/dist/utility/mail.js +91 -87
- package/package.json +3 -3
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import * as net from 'net';
|
|
3
|
-
import { AnyObjectInterface } from '../modals/utility.modal';
|
|
4
|
-
declare class MemoryDBConnect {
|
|
5
|
-
private client?;
|
|
6
|
-
private portNo;
|
|
7
|
-
private host;
|
|
8
|
-
private isConnected;
|
|
9
|
-
private messages;
|
|
10
|
-
private memBuffObj;
|
|
11
|
-
/**
|
|
12
|
-
* @param masterConfig Master Connectivity Object
|
|
13
|
-
* @param redisClient Redisclient
|
|
14
|
-
* @description connect to master database and maintain master config and redis client for furture ref
|
|
15
|
-
*/
|
|
16
|
-
constructor(portNumber: number, hostName: string);
|
|
17
|
-
/**
|
|
18
|
-
* @description connect to memory server on specified port and host
|
|
19
|
-
* @returns Promise with error first approach and success | failed.
|
|
20
|
-
*/
|
|
21
|
-
Initialize(): Promise<[Error?, string?]>;
|
|
22
|
-
/**
|
|
23
|
-
* @param method specifies the function of memory server which needs to execute
|
|
24
|
-
* @param data an object which has data for memory server
|
|
25
|
-
* @param data.CompanyID
|
|
26
|
-
* @param data.DataSet name of dataset to refer the data in memory server
|
|
27
|
-
* @param data.findQuery query by data need to retrieve from memory server
|
|
28
|
-
* @param data.FullDoc data to add, update and delete in memeory server
|
|
29
|
-
* @description write to server stream of memory server and data data from memory server by specific message id
|
|
30
|
-
* LOV:
|
|
31
|
-
* method : search | execute | insertInDataSet | updateInDataSet | deleteInDataSet
|
|
32
|
-
*/
|
|
33
|
-
Fetch(method: string, data: AnyObjectInterface): Promise<[any?, AnyObjectInterface?]>;
|
|
34
|
-
/**
|
|
35
|
-
* @description get connection object of memory server if already created other wise create and provide.
|
|
36
|
-
* @returns null | socket client
|
|
37
|
-
*/
|
|
38
|
-
Connect(): Promise<net.Socket | undefined>;
|
|
39
|
-
}
|
|
40
|
-
export { MemoryDBConnect };
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import * as net from 'net';
|
|
3
|
+
import { AnyObjectInterface } from '../modals/utility.modal';
|
|
4
|
+
declare class MemoryDBConnect {
|
|
5
|
+
private client?;
|
|
6
|
+
private portNo;
|
|
7
|
+
private host;
|
|
8
|
+
private isConnected;
|
|
9
|
+
private messages;
|
|
10
|
+
private memBuffObj;
|
|
11
|
+
/**
|
|
12
|
+
* @param masterConfig Master Connectivity Object
|
|
13
|
+
* @param redisClient Redisclient
|
|
14
|
+
* @description connect to master database and maintain master config and redis client for furture ref
|
|
15
|
+
*/
|
|
16
|
+
constructor(portNumber: number, hostName: string);
|
|
17
|
+
/**
|
|
18
|
+
* @description connect to memory server on specified port and host
|
|
19
|
+
* @returns Promise with error first approach and success | failed.
|
|
20
|
+
*/
|
|
21
|
+
Initialize(): Promise<[Error?, string?]>;
|
|
22
|
+
/**
|
|
23
|
+
* @param method specifies the function of memory server which needs to execute
|
|
24
|
+
* @param data an object which has data for memory server
|
|
25
|
+
* @param data.CompanyID
|
|
26
|
+
* @param data.DataSet name of dataset to refer the data in memory server
|
|
27
|
+
* @param data.findQuery query by data need to retrieve from memory server
|
|
28
|
+
* @param data.FullDoc data to add, update and delete in memeory server
|
|
29
|
+
* @description write to server stream of memory server and data data from memory server by specific message id
|
|
30
|
+
* LOV:
|
|
31
|
+
* method : search | execute | insertInDataSet | updateInDataSet | deleteInDataSet
|
|
32
|
+
*/
|
|
33
|
+
Fetch(method: string, data: AnyObjectInterface): Promise<[any?, AnyObjectInterface?]>;
|
|
34
|
+
/**
|
|
35
|
+
* @description get connection object of memory server if already created other wise create and provide.
|
|
36
|
+
* @returns null | socket client
|
|
37
|
+
*/
|
|
38
|
+
Connect(): Promise<net.Socket | undefined>;
|
|
39
|
+
}
|
|
40
|
+
export { MemoryDBConnect };
|
|
@@ -1,252 +1,256 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (t[
|
|
50
|
-
_.
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
this.
|
|
110
|
-
this.
|
|
111
|
-
this.
|
|
112
|
-
this.
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
//
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
//
|
|
146
|
-
//
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
* @param
|
|
183
|
-
* @param data
|
|
184
|
-
* @
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
message_1
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
if (
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
}
|
|
252
|
-
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
35
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
36
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
37
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
38
|
+
function step(op) {
|
|
39
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
40
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
41
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
42
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
43
|
+
switch (op[0]) {
|
|
44
|
+
case 0: case 1: t = op; break;
|
|
45
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
46
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
47
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
48
|
+
default:
|
|
49
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
50
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
51
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
52
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
53
|
+
if (t[2]) _.ops.pop();
|
|
54
|
+
_.trys.pop(); continue;
|
|
55
|
+
}
|
|
56
|
+
op = body.call(thisArg, _);
|
|
57
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
58
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
62
|
+
exports.MemoryDBConnect = void 0;
|
|
63
|
+
//var net = require('net');
|
|
64
|
+
var net = __importStar(require("net"));
|
|
65
|
+
var crypto = __importStar(require("crypto"));
|
|
66
|
+
var MessageBuffer = /** @class */ (function () {
|
|
67
|
+
function MessageBuffer(delimiter) {
|
|
68
|
+
this.delimiter = delimiter;
|
|
69
|
+
this.buffer = "";
|
|
70
|
+
}
|
|
71
|
+
MessageBuffer.prototype.isFinished = function () {
|
|
72
|
+
if (this.buffer.length === 0 ||
|
|
73
|
+
this.buffer.indexOf(this.delimiter) === -1) {
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
return false;
|
|
77
|
+
};
|
|
78
|
+
MessageBuffer.prototype.push = function (data) {
|
|
79
|
+
this.buffer += data;
|
|
80
|
+
};
|
|
81
|
+
MessageBuffer.prototype.getMessage = function () {
|
|
82
|
+
var delimiterIndex = this.buffer.indexOf(this.delimiter);
|
|
83
|
+
if (delimiterIndex !== -1) {
|
|
84
|
+
var message = this.buffer.slice(0, delimiterIndex);
|
|
85
|
+
this.buffer = this.buffer.replace(message + this.delimiter, "");
|
|
86
|
+
return message;
|
|
87
|
+
}
|
|
88
|
+
return null;
|
|
89
|
+
};
|
|
90
|
+
MessageBuffer.prototype.handleData = function () {
|
|
91
|
+
/**
|
|
92
|
+
* Try to accumulate the buffer with messages
|
|
93
|
+
*
|
|
94
|
+
* If the server isnt sending delimiters for some reason
|
|
95
|
+
* then nothing will ever come back for these requests
|
|
96
|
+
*/
|
|
97
|
+
var message = this.getMessage();
|
|
98
|
+
return message;
|
|
99
|
+
};
|
|
100
|
+
return MessageBuffer;
|
|
101
|
+
}());
|
|
102
|
+
var MemoryDBConnect = /** @class */ (function () {
|
|
103
|
+
/**
|
|
104
|
+
* @param masterConfig Master Connectivity Object
|
|
105
|
+
* @param redisClient Redisclient
|
|
106
|
+
* @description connect to master database and maintain master config and redis client for furture ref
|
|
107
|
+
*/
|
|
108
|
+
function MemoryDBConnect(portNumber, hostName) {
|
|
109
|
+
this.client = undefined;
|
|
110
|
+
this.portNo = 0;
|
|
111
|
+
this.host = "";
|
|
112
|
+
this.isConnected = false;
|
|
113
|
+
this.messages = {};
|
|
114
|
+
this.memBuffObj = new MessageBuffer("##message_response##");
|
|
115
|
+
this.portNo = portNumber;
|
|
116
|
+
this.host = hostName;
|
|
117
|
+
// this.Initialize().then(([error, result]) => {
|
|
118
|
+
// if (result == 'failed') {
|
|
119
|
+
// console.log('connection to memory server failed');
|
|
120
|
+
// }
|
|
121
|
+
// })
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* @description connect to memory server on specified port and host
|
|
125
|
+
* @returns Promise with error first approach and success | failed.
|
|
126
|
+
*/
|
|
127
|
+
MemoryDBConnect.prototype.Initialize = function () {
|
|
128
|
+
var _this = this;
|
|
129
|
+
return new Promise(function (resolve, reject) {
|
|
130
|
+
var newConnectRequest = true;
|
|
131
|
+
_this.client = new net.Socket();
|
|
132
|
+
_this.client.connect(_this.portNo, _this.host, function () {
|
|
133
|
+
_this.isConnected = true;
|
|
134
|
+
console.log("client connected to ".concat(_this.portNo, ":").concat(_this.host));
|
|
135
|
+
if (newConnectRequest) {
|
|
136
|
+
resolve([undefined, 'success']);
|
|
137
|
+
newConnectRequest = false;
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
_this.client.on('data', function (data) {
|
|
141
|
+
console.log("Data from MemServer", (data || "").toString());
|
|
142
|
+
//console.log("")
|
|
143
|
+
// let message = null;
|
|
144
|
+
try {
|
|
145
|
+
// data = JSON.parse(data);
|
|
146
|
+
// message = this.messages[data.id];
|
|
147
|
+
// if (message) {
|
|
148
|
+
// delete this.messages[data.id];
|
|
149
|
+
// message(data);
|
|
150
|
+
// }
|
|
151
|
+
_this.memBuffObj.push(data);
|
|
152
|
+
while (!_this.memBuffObj.isFinished()) {
|
|
153
|
+
var message = _this.memBuffObj.handleData();
|
|
154
|
+
// console.log(message);
|
|
155
|
+
// console.log(JSON.parse(message))
|
|
156
|
+
if (message) {
|
|
157
|
+
message = JSON.parse(message);
|
|
158
|
+
var messageCallbackFn = _this.messages[message.id];
|
|
159
|
+
delete _this.messages[message.id];
|
|
160
|
+
messageCallbackFn(message);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
catch (error) {
|
|
165
|
+
console.log("Error in parsing MemServer data", error);
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
_this.client.on('close', function () {
|
|
169
|
+
_this.isConnected = false;
|
|
170
|
+
console.log("Client closed for port:host - ".concat(_this.portNo, ":").concat(_this.host));
|
|
171
|
+
if (newConnectRequest) {
|
|
172
|
+
resolve([undefined, 'failed']);
|
|
173
|
+
newConnectRequest = false;
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
_this.client.on('error', function (err) {
|
|
177
|
+
console.error('Error in Memory server socket', err);
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
};
|
|
181
|
+
/**
|
|
182
|
+
* @param method specifies the function of memory server which needs to execute
|
|
183
|
+
* @param data an object which has data for memory server
|
|
184
|
+
* @param data.CompanyID
|
|
185
|
+
* @param data.DataSet name of dataset to refer the data in memory server
|
|
186
|
+
* @param data.findQuery query by data need to retrieve from memory server
|
|
187
|
+
* @param data.FullDoc data to add, update and delete in memeory server
|
|
188
|
+
* @description write to server stream of memory server and data data from memory server by specific message id
|
|
189
|
+
* LOV:
|
|
190
|
+
* method : search | execute | insertInDataSet | updateInDataSet | deleteInDataSet
|
|
191
|
+
*/
|
|
192
|
+
MemoryDBConnect.prototype.Fetch = function (method, data) {
|
|
193
|
+
var _this = this;
|
|
194
|
+
return new Promise(function (resolve, reject) {
|
|
195
|
+
var _a;
|
|
196
|
+
try {
|
|
197
|
+
console.log('socket connected==>', (_a = _this.client) === null || _a === void 0 ? void 0 : _a.connect);
|
|
198
|
+
var id = crypto.randomBytes(16).toString("hex");
|
|
199
|
+
var message_1 = { id: id, method: method, data: data, status: "0" };
|
|
200
|
+
_this.messages[id] = function (res) {
|
|
201
|
+
if (message_1.status == "0") {
|
|
202
|
+
resolve([undefined, res]);
|
|
203
|
+
message_1.status = "1";
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
//timeout event binding : after 30seconds request willbe timeout
|
|
207
|
+
setTimeout(function () {
|
|
208
|
+
if (message_1.status == "0") {
|
|
209
|
+
console.log("memory server request timed out");
|
|
210
|
+
resolve([new Error("REQUEST_TIMEDOUT"), undefined]);
|
|
211
|
+
message_1.status = "-1";
|
|
212
|
+
}
|
|
213
|
+
}, 60000);
|
|
214
|
+
if (_this.client && _this.isConnected) {
|
|
215
|
+
_this.client.write(JSON.stringify(message_1) + "##message##");
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
//to avoid again resolve by set timeout
|
|
219
|
+
message_1.status = "-1";
|
|
220
|
+
resolve([new Error('CLIENT_NOT_CONNECTED'), undefined]);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
catch (err) {
|
|
224
|
+
resolve([err, undefined]);
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
};
|
|
228
|
+
/**
|
|
229
|
+
* @description get connection object of memory server if already created other wise create and provide.
|
|
230
|
+
* @returns null | socket client
|
|
231
|
+
*/
|
|
232
|
+
MemoryDBConnect.prototype.Connect = function () {
|
|
233
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
234
|
+
var _a, error, result;
|
|
235
|
+
return __generator(this, function (_b) {
|
|
236
|
+
switch (_b.label) {
|
|
237
|
+
case 0:
|
|
238
|
+
if (!(this.client == null || this.isConnected == false)) return [3 /*break*/, 2];
|
|
239
|
+
return [4 /*yield*/, this.Initialize()];
|
|
240
|
+
case 1:
|
|
241
|
+
_a = _b.sent(), error = _a[0], result = _a[1];
|
|
242
|
+
if (result != 'success') {
|
|
243
|
+
console.log('memory server socket connection not initialized');
|
|
244
|
+
//To Do : add code for handling this situation after getting some clarity on work.
|
|
245
|
+
}
|
|
246
|
+
_b.label = 2;
|
|
247
|
+
case 2:
|
|
248
|
+
//check client connected code : to do list by satyam
|
|
249
|
+
return [2 /*return*/, this.client];
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
});
|
|
253
|
+
};
|
|
254
|
+
return MemoryDBConnect;
|
|
255
|
+
}());
|
|
256
|
+
exports.MemoryDBConnect = MemoryDBConnect;
|