@resolveio/server-lib 1.1.11 → 1.1.12

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.
@@ -16,7 +16,7 @@ export declare class MethodManager {
16
16
  getMainServer(): ResolveIOMainServer;
17
17
  methods(method: MethodModel): void;
18
18
  callMethodCron(method: string, ...methodData: any[]): void;
19
- callMethodQueue(update: QueueMethodModel): void;
19
+ callMethodQueue(update: QueueMethodModel): Promise<{}>;
20
20
  callMethod(ws: WebSocket, messageId: any, method: any, ...methodData: any[]): void;
21
21
  callMethodInternal(method: any, ...methodData: any[]): Promise<any>;
22
22
  callSupportMethodInternal(supportMethod: any, ...methodData: any[]): Promise<any>;
@@ -177,6 +177,15 @@ var MethodManager = /** @class */ (function () {
177
177
  user: ws['user'],
178
178
  messageId: sendItem.data.messageId
179
179
  });
180
+ method_response_collection_1.MethodResponses.create({
181
+ _id: mongoose_1.Types.ObjectId().toHexString(),
182
+ __v: 0,
183
+ id_user: ws['id_user'],
184
+ message_id: sendItem.data.messageId,
185
+ data: JSON.stringify(sendItem.methodData),
186
+ response: sendItem.data,
187
+ method: sendItem.method
188
+ });
180
189
  }
181
190
  else {
182
191
  log_collection_1.Logs.create({
@@ -205,15 +214,6 @@ var MethodManager = /** @class */ (function () {
205
214
  messageId: sendItem.data.messageId
206
215
  });
207
216
  }
208
- method_response_collection_1.MethodResponses.create({
209
- _id: mongoose_1.Types.ObjectId().toHexString(),
210
- __v: 0,
211
- id_user: ws['id_user'],
212
- message_id: sendItem.data.messageId,
213
- data: JSON.stringify(sendItem.methodData),
214
- response: sendItem.data,
215
- method: sendItem.method
216
- });
217
217
  }
218
218
  }
219
219
  else {
@@ -280,85 +280,89 @@ var MethodManager = /** @class */ (function () {
280
280
  (_a = that._methods[method].function).call.apply(_a, [Object.assign({}, that, MethodManager.prototype, { id_user: '', user: '', id_ws: '' })].concat(methodData));
281
281
  };
282
282
  MethodManager.prototype.callMethodQueue = function (update) {
283
- // console.log('Call Method Queue', update);
284
283
  var _this = this;
285
- var _a;
286
- var updateCopy = common_1.deepCopy(update);
287
- var that = this;
288
- if (!that._methods[update.method]) {
289
- console.log('No Method: ' + update.method);
290
- that.sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + that.serverConfig['CLIENT_NAME'], 'No Method: ' + update.method);
291
- var serverRes = {
292
- messageId: update.messageId,
293
- hasError: true,
294
- data: 'Internal Error'
295
- };
296
- this._mainServer.getQueueManager().addMethodResponse(updateCopy, serverRes);
297
- return;
298
- }
299
- if ((update.method_data.length > 1 || update.method_data[0]) && !that._methods[update.method].skipValidation) {
300
- if (!that._methods[update.method].check) {
301
- console.error('No Check Function For Method ' + update.method);
302
- that.sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + that.serverConfig['CLIENT_NAME'], 'No Check Function For Method ' + update.method);
303
- var serverRes = {
304
- messageId: update.messageId,
305
- hasError: true,
306
- data: 'Internal Error'
307
- };
308
- this._mainServer.getQueueManager().addMethodResponse(updateCopy, serverRes);
309
- return;
310
- }
311
- else if (!that._methods[update.method].check._schema) {
312
- console.error('No Check Schema For Method ' + update.method);
313
- that.sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + that.serverConfig['CLIENT_NAME'], 'No Check Function For Method ' + update.method);
284
+ // console.log('Call Method Queue', update);
285
+ return new Promise(function (resolve, reject) {
286
+ var _a;
287
+ var updateCopy = common_1.deepCopy(update);
288
+ var that = _this;
289
+ if (!that._methods[update.method]) {
290
+ console.log('No Method: ' + update.method);
291
+ that.sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + that.serverConfig['CLIENT_NAME'], 'No Method: ' + update.method);
314
292
  var serverRes = {
315
293
  messageId: update.messageId,
316
294
  hasError: true,
317
295
  data: 'Internal Error'
318
296
  };
319
- this._mainServer.getQueueManager().addMethodResponse(updateCopy, serverRes);
320
- return;
297
+ _this._mainServer.getQueueManager().addMethodResponse(updateCopy, serverRes);
298
+ return reject('No Method: ' + update.method);
321
299
  }
322
- else {
323
- var valObj = {};
324
- var valKeys = Object.keys(that._methods[update.method].check._schema);
325
- var rootKeys = valKeys.filter(function (a) { return !a.includes('.'); });
326
- for (var i = 0; i < update.method_data.length; i++) {
327
- valObj[rootKeys[i]] = update.method_data[i];
300
+ if ((update.method_data.length > 1 || update.method_data[0]) && !that._methods[update.method].skipValidation) {
301
+ if (!that._methods[update.method].check) {
302
+ console.error('No Check Function For Method ' + update.method);
303
+ that.sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + that.serverConfig['CLIENT_NAME'], 'No Check Function For Method ' + update.method);
304
+ var serverRes = {
305
+ messageId: update.messageId,
306
+ hasError: true,
307
+ data: 'Internal Error'
308
+ };
309
+ _this._mainServer.getQueueManager().addMethodResponse(updateCopy, serverRes);
310
+ return reject('No Check Function For Method ' + update.method);
328
311
  }
329
- try {
330
- that._methods[update.method].check.validate(valObj);
312
+ else if (!that._methods[update.method].check._schema) {
313
+ console.error('No Check Schema For Method ' + update.method);
314
+ that.sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + that.serverConfig['CLIENT_NAME'], 'No Check Function For Method ' + update.method);
315
+ var serverRes = {
316
+ messageId: update.messageId,
317
+ hasError: true,
318
+ data: 'Internal Error'
319
+ };
320
+ _this._mainServer.getQueueManager().addMethodResponse(updateCopy, serverRes);
321
+ return reject('No Check Schema For Method ' + update.method);
331
322
  }
332
- catch (errors) {
333
- if (errors) {
334
- console.error('Error in Method Check (' + update.method + ')', errors);
335
- that.sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + that.serverConfig['CLIENT_NAME'], 'Match Error On Method ' + update.method + '\n\nData Being Checked\n' + JSON.stringify(valObj, null, 2) + '\n\nErrors\n' + JSON.stringify(errors, null, 2));
336
- var serverRes = {
337
- messageId: update.messageId,
338
- hasError: true,
339
- data: 'Internal Error'
340
- };
341
- this._mainServer.getQueueManager().addMethodResponse(updateCopy, serverRes);
342
- return;
323
+ else {
324
+ var valObj = {};
325
+ var valKeys = Object.keys(that._methods[update.method].check._schema);
326
+ var rootKeys = valKeys.filter(function (a) { return !a.includes('.'); });
327
+ for (var i = 0; i < update.method_data.length; i++) {
328
+ valObj[rootKeys[i]] = update.method_data[i];
329
+ }
330
+ try {
331
+ that._methods[update.method].check.validate(valObj);
332
+ }
333
+ catch (errors) {
334
+ if (errors) {
335
+ console.error('Error in Method Check (' + update.method + ')', errors);
336
+ that.sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + that.serverConfig['CLIENT_NAME'], 'Match Error On Method ' + update.method + '\n\nData Being Checked\n' + JSON.stringify(valObj, null, 2) + '\n\nErrors\n' + JSON.stringify(errors, null, 2));
337
+ var serverRes = {
338
+ messageId: update.messageId,
339
+ hasError: true,
340
+ data: 'Internal Error'
341
+ };
342
+ _this._mainServer.getQueueManager().addMethodResponse(updateCopy, serverRes);
343
+ return reject('Error in Method Check (' + update.method + ')');
344
+ }
343
345
  }
344
346
  }
345
347
  }
346
- }
347
- // console.log('Run Method', update.method);
348
- (_a = that._methods[update.method].function).call.apply(_a, [Object.assign({}, that, MethodManager.prototype, { id_user: update.id_user, user: update.user, id_ws: update.id_ws })].concat(update.method_data)).then(function (res) {
349
- var serverRes = {
350
- messageId: update.messageId,
351
- hasError: false,
352
- data: res
353
- };
354
- _this._mainServer.getQueueManager().addMethodResponse(updateCopy, serverRes);
355
- }, function (err) {
356
- var serverRes = {
357
- messageId: update.messageId,
358
- hasError: true,
359
- data: err
360
- };
361
- _this._mainServer.getQueueManager().addMethodResponse(updateCopy, serverRes);
348
+ // console.log('Run Method', update.method);
349
+ (_a = that._methods[update.method].function).call.apply(_a, [Object.assign({}, that, MethodManager.prototype, { id_user: update.id_user, user: update.user, id_ws: update.id_ws })].concat(update.method_data)).then(function (res) {
350
+ var serverRes = {
351
+ messageId: update.messageId,
352
+ hasError: false,
353
+ data: res
354
+ };
355
+ _this._mainServer.getQueueManager().addMethodResponse(updateCopy, serverRes);
356
+ resolve(serverRes);
357
+ }, function (err) {
358
+ var serverRes = {
359
+ messageId: update.messageId,
360
+ hasError: true,
361
+ data: err
362
+ };
363
+ _this._mainServer.getQueueManager().addMethodResponse(updateCopy, serverRes);
364
+ reject(serverRes);
365
+ });
362
366
  });
363
367
  };
364
368
  // Call/run method (Emit on Socket)
@@ -76,6 +76,15 @@ var QueueMethodManager = /** @class */ (function () {
76
76
  user: ws['user'],
77
77
  messageId: sendItem.messageId
78
78
  });
79
+ method_response_collection_1.MethodResponses.create({
80
+ _id: mongoose_1.Types.ObjectId().toHexString(),
81
+ __v: 0,
82
+ id_user: sendItem.id_user,
83
+ message_id: sendItem.messageId,
84
+ data: JSON.stringify(sendItem.method_data),
85
+ response: sendItem.response,
86
+ method: sendItem.method
87
+ });
79
88
  }
80
89
  else {
81
90
  log_collection_1.Logs.create({
@@ -104,15 +113,6 @@ var QueueMethodManager = /** @class */ (function () {
104
113
  messageId: sendItem.messageId
105
114
  });
106
115
  }
107
- method_response_collection_1.MethodResponses.create({
108
- _id: mongoose_1.Types.ObjectId().toHexString(),
109
- __v: 0,
110
- id_user: sendItem.id_user,
111
- message_id: sendItem.messageId,
112
- data: JSON.stringify(sendItem.method_data),
113
- response: sendItem.response,
114
- method: sendItem.method
115
- });
116
116
  }
117
117
  }
118
118
  };
@@ -164,25 +164,26 @@ function loadCollectionMethods(methodManager) {
164
164
  reject('Schema Errors');
165
165
  }
166
166
  else {
167
+ var updates_1 = common_1.getMongoUpdates(currDoc, f_document, true);
167
168
  index_1.ResolveIOServer.getMainDB().model(index_1.ResolveIOServer.getMainDB().model(collection)['versionCollection']).create(versionDoc).then(function (doc) {
168
169
  index_1.ResolveIOServer.getMainDB().model(index_1.ResolveIOServer.getMainDB().model(collection)['versionCollection']).deleteMany({
169
170
  $and: [
170
171
  { '_id._id': currDoc._id },
171
172
  { '_id.__v': { $lte: currDoc.__v - 4 } }
172
173
  ]
173
- }).exec();
174
+ }).exec().then(function () {
175
+ if (updates_1) {
176
+ index_1.ResolveIOServer.getMainDB().model(collection).updateOne({ _id: f_document['_id'] }, updates_1, { strict: false }).exec().then(function (res) {
177
+ resolve(res.nModified);
178
+ }, function (err) { return reject(err); });
179
+ }
180
+ else {
181
+ resolve(1);
182
+ }
183
+ });
174
184
  }, function (err) {
175
185
  console.log(err);
176
186
  });
177
- var updates = common_1.getMongoUpdates(currDoc, f_document, true);
178
- if (updates) {
179
- index_1.ResolveIOServer.getMainDB().model(collection).updateOne({ _id: f_document['_id'] }, updates, { strict: false }).exec().then(function (res) {
180
- resolve(res.nModified);
181
- }, function (err) { return reject(err); });
182
- }
183
- else {
184
- resolve(1);
185
- }
186
187
  if (common_1.getBinarySize(JSON.stringify(f_document)) < 200000) {
187
188
  log_collection_1.Logs.create({
188
189
  _id: mongoose_1.Types.ObjectId().toHexString(),
@@ -236,8 +237,9 @@ function loadCollectionMethods(methodManager) {
236
237
  { '_id._id': versionDoc_1._id._id },
237
238
  { '_id.__v': { $lte: versionDoc_1._id.__v - 4 } }
238
239
  ]
239
- }).exec();
240
- resolve(res.nModified);
240
+ }).exec().then(function () {
241
+ resolve(res.nModified);
242
+ });
241
243
  });
242
244
  }, function (err) { return reject(err); });
243
245
  }
@@ -305,25 +307,26 @@ function loadCollectionMethods(methodManager) {
305
307
  reject('Schema Errors');
306
308
  }
307
309
  else {
310
+ var updates_2 = common_1.getMongoUpdates(currDoc, modifiedDoc_1, true);
308
311
  index_1.ResolveIOServer.getMainDB().model(index_1.ResolveIOServer.getMainDB().model(collection)['versionCollection']).create(versionDoc).then(function (doc) {
309
312
  index_1.ResolveIOServer.getMainDB().model(index_1.ResolveIOServer.getMainDB().model(collection)['versionCollection']).deleteMany({
310
313
  $and: [
311
314
  { '_id._id': currDoc._id },
312
315
  { '_id.__v': { $lte: currDoc.__v - 4 } }
313
316
  ]
314
- }).exec();
317
+ }).exec().then(function () {
318
+ if (updates_2) {
319
+ index_1.ResolveIOServer.getMainDB().model(collection).updateOne({ _id: modifiedDoc_1._id }, updates_2, { strict: false }).exec().then(function (res) {
320
+ resolve(res.ok);
321
+ }, function (err) { return reject(err); });
322
+ }
323
+ else {
324
+ resolve(1);
325
+ }
326
+ });
315
327
  }, function (err) {
316
328
  console.log(err);
317
329
  });
318
- var updates = common_1.getMongoUpdates(currDoc, modifiedDoc_1, true);
319
- if (updates) {
320
- index_1.ResolveIOServer.getMainDB().model(collection).updateOne({ _id: modifiedDoc_1._id }, updates, { strict: false }).exec().then(function (res) {
321
- resolve(res.ok);
322
- }, function (err) { return reject(err); });
323
- }
324
- else {
325
- resolve(1);
326
- }
327
330
  if (common_1.getBinarySize(JSON.stringify(updateParams)) < 200000) {
328
331
  log_collection_1.Logs.create({
329
332
  _id: mongoose_1.Types.ObjectId().toHexString(),
@@ -377,11 +380,12 @@ function loadCollectionMethods(methodManager) {
377
380
  { '_id._id': versionDoc_2._id._id },
378
381
  { '_id.__v': { $lte: versionDoc_2._id.__v - 4 } }
379
382
  ]
380
- }).exec();
383
+ }).exec().then(function () {
384
+ resolve(res.nModified);
385
+ });
381
386
  }, function (err) {
382
387
  console.log(err);
383
388
  });
384
- resolve(res.nModified);
385
389
  }, function (err) { return reject(err); });
386
390
  }
387
391
  else {
@@ -435,25 +439,26 @@ function loadCollectionMethods(methodManager) {
435
439
  reject('Schema Errors');
436
440
  }
437
441
  else {
442
+ var updates_3 = common_1.getMongoUpdates(currDoc, f_document, true);
438
443
  index_1.ResolveIOServer.getMainDB().model(index_1.ResolveIOServer.getMainDB().model(collection)['versionCollection']).create(versionDoc).then(function (doc) {
439
444
  index_1.ResolveIOServer.getMainDB().model(index_1.ResolveIOServer.getMainDB().model(collection)['versionCollection']).deleteMany({
440
445
  $and: [
441
446
  { '_id._id': currDoc._id },
442
447
  { '_id.__v': { $lte: currDoc.__v - 4 } }
443
448
  ]
444
- }).exec();
449
+ }).exec().then(function () {
450
+ if (updates_3) {
451
+ index_1.ResolveIOServer.getMainDB().model(collection).updateOne({ _id: f_document['_id'] }, updates_3, { strict: false }).exec().then(function (res) {
452
+ resolve(res.nModified);
453
+ }, function (err) { return reject(err); });
454
+ }
455
+ else {
456
+ resolve(1);
457
+ }
458
+ });
445
459
  }, function (err) {
446
460
  console.log(err);
447
461
  });
448
- var updates = common_1.getMongoUpdates(currDoc, f_document, true);
449
- if (updates) {
450
- index_1.ResolveIOServer.getMainDB().model(collection).updateOne({ _id: f_document['_id'] }, updates, { strict: false }).exec().then(function (res) {
451
- resolve(res.nModified);
452
- }, function (err) { return reject(err); });
453
- }
454
- else {
455
- resolve(1);
456
- }
457
462
  if (common_1.getBinarySize(JSON.stringify(f_document)) < 200000) {
458
463
  log_collection_1.Logs.create({
459
464
  _id: mongoose_1.Types.ObjectId().toHexString(),
@@ -501,11 +506,12 @@ function loadCollectionMethods(methodManager) {
501
506
  { '_id._id': versionDoc_3._id._id },
502
507
  { '_id.__v': { $lte: versionDoc_3._id.__v - 4 } }
503
508
  ]
504
- }).exec();
509
+ }).exec().then(function () {
510
+ resolve(res.nModified);
511
+ });
505
512
  }, function (err) {
506
513
  console.log(err);
507
514
  });
508
- resolve(res.nModified);
509
515
  }, function (err) { return reject(err); });
510
516
  }
511
517
  else {
@@ -575,25 +581,26 @@ function loadCollectionMethods(methodManager) {
575
581
  reject('Schema Errors');
576
582
  }
577
583
  else {
584
+ var updates_4 = common_1.getMongoUpdates(currDoc, modifiedDoc_2, true);
578
585
  index_1.ResolveIOServer.getMainDB().model(index_1.ResolveIOServer.getMainDB().model(collection)['versionCollection']).create(versionDoc).then(function (doc) {
579
586
  index_1.ResolveIOServer.getMainDB().model(index_1.ResolveIOServer.getMainDB().model(collection)['versionCollection']).deleteMany({
580
587
  $and: [
581
588
  { '_id._id': currDoc._id },
582
589
  { '_id.__v': { $lte: currDoc.__v - 4 } }
583
590
  ]
584
- }).exec();
591
+ }).exec().then(function () {
592
+ if (updates_4) {
593
+ index_1.ResolveIOServer.getMainDB().model(collection).updateOne({ _id: modifiedDoc_2._id }, updates_4, { strict: false }).exec().then(function (res) {
594
+ resolve(res.ok);
595
+ }, function (err) { return reject(err); });
596
+ }
597
+ else {
598
+ resolve(1);
599
+ }
600
+ });
585
601
  }, function (err) {
586
602
  console.log(err);
587
603
  });
588
- var updates = common_1.getMongoUpdates(currDoc, modifiedDoc_2, true);
589
- if (updates) {
590
- index_1.ResolveIOServer.getMainDB().model(collection).updateOne({ _id: modifiedDoc_2._id }, updates, { strict: false }).exec().then(function (res) {
591
- resolve(res.ok);
592
- }, function (err) { return reject(err); });
593
- }
594
- else {
595
- resolve(1);
596
- }
597
604
  if (common_1.getBinarySize(JSON.stringify(updateParams)) < 200000) {
598
605
  log_collection_1.Logs.create({
599
606
  _id: mongoose_1.Types.ObjectId().toHexString(),
@@ -641,11 +648,12 @@ function loadCollectionMethods(methodManager) {
641
648
  { '_id._id': versionDoc_4._id._id },
642
649
  { '_id.__v': { $lte: versionDoc_4._id.__v - 4 } }
643
650
  ]
644
- }).exec();
651
+ }).exec().then(function () {
652
+ resolve(res.nModified);
653
+ });
645
654
  }, function (err) {
646
655
  console.log(err);
647
656
  });
648
- resolve(res.nModified);
649
657
  }, function (err) { return reject(err); });
650
658
  }
651
659
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@resolveio/server-lib",
3
- "version": "1.1.11",
3
+ "version": "1.1.12",
4
4
  "description": "",
5
5
  "main": "index.ts",
6
6
  "scripts": {