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