@resolveio/server-lib 20.11.13 → 20.11.15

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.
@@ -55,6 +55,7 @@ function loadCollectionMethods(methodManager) {
55
55
  },
56
56
  // Query database for any collection and query
57
57
  findOne: {
58
+ bypassSession: true,
58
59
  check: new simpl_schema_1.default({
59
60
  collection: {
60
61
  type: String
@@ -73,6 +74,7 @@ function loadCollectionMethods(methodManager) {
73
74
  }
74
75
  },
75
76
  find: {
77
+ bypassSession: true,
76
78
  check: new simpl_schema_1.default({
77
79
  collection: {
78
80
  type: String
@@ -97,6 +99,7 @@ function loadCollectionMethods(methodManager) {
97
99
  }
98
100
  },
99
101
  findWithOptions: {
102
+ bypassSession: true,
100
103
  check: new simpl_schema_1.default({
101
104
  collection: {
102
105
  type: String
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/methods/collections.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,sDA2cC;AAjdD,6CAAwC;AAExC,+DAAwF;AACxF,gEAA0D;AAC1D,yCAAsF;AAEtF,SAAgB,qBAAqB,CAAC,aAA4B;IACjE,aAAa,CAAC,OAAO,CAAC;QACrB,iBAAiB,EAAE;YAClB,QAAQ,EAAE;gBACT,OAAO,OAAO,CAAC,OAAO,CAAC,sCAAe,CAAC,eAAe,EAAE,CAAC,WAAW,EAAE,CAAC,GAAG,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,cAAc,EAAhB,CAAgB,CAAC,CAAC,IAAI,CAAC,UAAC,CAAC,EAAE,CAAC,IAAK,OAAA,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,EAAlB,CAAkB,CAAC,CAAC,CAAC;YACvI,CAAC;SACD;QACD,gBAAgB,EAAE;YACjB,QAAQ,EAAE;gBACT,OAAO,OAAO,CAAC,OAAO,CAAC,sCAAe,CAAC,eAAe,EAAE,CAAC,WAAW,EAAE,CA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,sCAAe,CAAC,eAAe,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,EAAA;;gCAA/E,SAA+E,CAAC;gCAEhF,sBAAO,IAAI,EAAC;;;;aACZ;SACD;QACD,wBAAwB,EAAE;YACzB,KAAK,EAAE,IAAI,sBAAY,CAAC;gBACvB,UAAU,EAAE;oBACX,IAAI,EAAE,MAAM;iBACZ;gBACD,KAAK,EAAE;oBACN,IAAI,EAAE,MAAM;oBACZ,QAAQ,EAAE,IAAI;iBACd;aACD,CAAC;YACF,QAAQ,EAAE,UAAe,UAAkB,EAAE,KAAa;;;;;gCACzD,IAAI,CAAC,sCAAe,CAAC,eAAe,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;oCAC/D,MAAM,IAAI,KAAK,CAAC,sEAAsE,CAAC,CAAC;gCACzF,CAAC;gCAED,qBAAM,sCAAe,CAAC,eAAe,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,EAAA;;gCAAhF,SAAgF,CAAC;gCAEjF,sBAAO,IAAI,EAAC;;;;aACZ;SACD;KACD,CAAC,CAAC;AACJ,CAAC","file":"collections.js","sourcesContent":["import SimpleSchema from 'simpl-schema';\nimport { MethodManager } from '../managers/method.manager';\nimport { PaginationOptions, PaginationOptionsSchema } from '../models/pagination.model';\nimport { ResolveIOServer } from '../resolveio-server-app';\nimport { deepCopy, getMongoMergeUpdatedDoc, objectIdHexString } from '../util/common';\n\nexport function loadCollectionMethods(methodManager: MethodManager) {\n\tmethodManager.methods({\n\t\tcollectionListAll: {\n\t\t\tfunction: function() {\n\t\t\t\treturn Promise.resolve(ResolveIOServer.getMongoManager().collections().map(a => a.collectionName).sort((a, b) => a.localeCompare(b)));\n\t\t\t}\n\t\t},\n\t\tcollectionListRB: {\n\t\t\tfunction: function() {\n\t\t\t\treturn Promise.resolve(ResolveIOServer.getMongoManager().collections().filter(a => a.useRB).map(a => a.collectionName).sort((a, b) => a.localeCompare(b)));\n\t\t\t}\n\t\t},\n\t\t// Query database for any collection and query\n\t\tfindOne: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tquery: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: function(collection: string, query = {}) {\n\t\t\t\tif (!ResolveIOServer.getMongoManager().collection(collection)) {\n\t\t\t\t\tthrow new Error('Error in Find One Collection: Invalid collection');\n\t\t\t\t}\n\n\t\t\t\treturn ResolveIOServer.getMongoManager().collection(collection).findOne(query);\n\t\t\t}\n\t\t},\n\t\tfind: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tquery: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t},\n\t\t\t\tsort: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true,\n\t\t\t\t\toptional: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: function(collection: string, query = {}, sortQuery = {}) {\n\t\t\t\tif (!ResolveIOServer.getMongoManager().collection(collection)) {\n\t\t\t\t\tthrow new Error('Error in Find Collection: Invalid collection');\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\treturn ResolveIOServer.getMongoManager().collection(collection).find(query, {sort: sortQuery});\n\t\t\t}\n\t\t},\n\t\tfindWithOptions: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tquery: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t},\n\t\t\t\toptions: {\n\t\t\t\t\ttype: PaginationOptionsSchema\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: function(collection: string, query: Object, options: PaginationOptions) {\n\t\t\t\tif (!ResolveIOServer.getMongoManager().collection(collection)) {\n\t\t\t\t\tthrow new Error('Error in Find With Options Collection: Invalid collection');\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tlet optionsQuery = {};\n\n\t\t\t\t\tif (options.fields && Object.keys(options.fields).length) {\n\t\t\t\t\t\toptionsQuery['projection'] = options.fields;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (options.sort && Object.keys(options.sort).length) {\n\t\t\t\t\t\toptionsQuery['sort'] = options.sort;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (options.limit) {\n\t\t\t\t\t\toptionsQuery['limit'] = options.limit;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (options.skip) {\n\t\t\t\t\t\toptionsQuery['skip'] = options.skip;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn ResolveIOServer.getMongoManager().collection(collection).find(query, optionsQuery);\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t// Insert 1 document\n\t\t// @Inputs: collection, document\n\t\t// @Outputs: res = _id of new document, err = not inserted\n\t\tinsertDocument: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tdocument: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(collection: string, document: Object) {\n\t\t\t\tif (!ResolveIOServer.getMongoManager().collection(collection)) {\n\t\t\t\t\tthrow new Error('Error in Insert Document Collection: Invalid collection');\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tlet id = objectIdHexString();\n\t\t\t\t\tdocument['_id'] = id;\n\t\t\t\t\tdocument['__v'] = 0;\n\n\t\t\t\t\tawait ResolveIOServer.getMongoManager().collection(collection).insertOne(document);\n\t\t\t\t\treturn id;\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t// Insert 1 document\n\t\t// @Inputs: collection, document\n\t\t// @Outputs: res = _id of new document, err = not inserted\n\t\tinsertManyDocuments: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tdocuments: {\n\t\t\t\t\ttype: Array\n\t\t\t\t},\n\t\t\t\t'documents.$': {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(collection: string, documents: Object[]) {\n\t\t\t\tif (!ResolveIOServer.getMongoManager().collection(collection)) {\n\t\t\t\t\tthrow new Error('Error in Insert Many Documents Collection: Invalid collection');\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tdocuments.forEach(document => {\n\t\t\t\t\t\tdocument['_id'] = objectIdHexString();\n\t\t\t\t\t\tdocument['__v'] = 0;\n\t\t\t\t\t});\n\n\t\t\t\t\tawait ResolveIOServer.getMongoManager().collection(collection).insertMany(documents);\n\t\t\t\t\treturn documents.map(a => a['_id']);\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t// Replaces 1 document with new document (from _id)\n\t\t// @Inputs: collection, document id\n\t\t// @Outputs: res = 1 (updated 1), err = not updated/wrong version\n\t\t// Search for doc, check version, if found then try and update\n\t\tupdateDocument: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tf_document: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(collection: string, f_document: Object) {\n\t\t\t\tif (!ResolveIOServer.getMongoManager().collection(collection)) {\n\t\t\t\t\tthrow new Error('Error in Update Document Collection: Invalid collection');\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tawait ResolveIOServer.getMongoManager().collection(collection).replaceOne({_id: f_document['_id']}, f_document);\n\t\t\t\treturn true;\n\t\t\t}\n\t\t},\n\t\t// Updates 1 document's props (from _id)\n\t\t// @Inputs: collection, document id, document version, update paramters ({prop: 'xxx', data: 'yyy})\n\t\t// @Outputs: res = 1 (updated 1), res = 0 (not updated), err = not updated/wrong version\n\t\t// Search for doc, check version, if found then try and update props\n\t\tupdateDocumentProps: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tdoc_id: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tupdateParams: {\n\t\t\t\t\ttype: Array\n\t\t\t\t},\n\t\t\t\t'updateParams.$': {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t},\n\t\t\t\tdoc__v: {\n\t\t\t\t\ttype: Number,\n\t\t\t\t\toptional: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(collection: string, doc_id: string, updateParams: any[], doc__v?: number) {\n\t\t\t\tif (!ResolveIOServer.getMongoManager().collection(collection)) {\n\t\t\t\t\tthrow new Error('Error in Update Document Props Collection: Invalid collection');\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tlet currDoc = await ResolveIOServer.getMongoManager().collection(collection).findOne({_id: doc_id});\n\t\t\t\t\tif (currDoc) {\n\t\t\t\t\t\tlet modifiedDoc = deepCopy(currDoc);\n\n\t\t\t\t\t\tupdateParams.forEach(data => {\n\t\t\t\t\t\t\tmodifiedDoc[data.prop] = data.data;\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tif (!doc__v || modifiedDoc.__v === doc__v) {\n\t\t\t\t\t\t\tawait ResolveIOServer.getMongoManager().collection(collection).replaceOne({_id: modifiedDoc._id}, modifiedDoc, {}, false, false, currDoc);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tconsole.log(new Date(), 'invalid version - ' + collection, currDoc.__v, doc__v);\n\n\t\t\t\t\t\t\tif (ResolveIOServer.getMongoManager().collection(collection + '.versions')) {\n\t\t\t\t\t\t\t\tlet oldDoc = await ResolveIOServer.getMongoManager().collection(collection + '.versions').findOne({\n\t\t\t\t\t\t\t\t\t_id: {\n\t\t\t\t\t\t\t\t\t\t_id: currDoc._id,\n\t\t\t\t\t\t\t\t\t\t__v: doc__v\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\tlet newCurrDocId = currDoc._id;\n\t\t\t\t\t\t\t\tlet newCurrDocV = currDoc.__v;\n\n\t\t\t\t\t\t\t\tif (oldDoc) {\n\t\t\t\t\t\t\t\t\tlet updatedDoc = getMongoMergeUpdatedDoc(modifiedDoc, currDoc, oldDoc);\n\t\t\t\t\t\t\t\t\tupdatedDoc._id = newCurrDocId;\n\t\t\t\t\t\t\t\t\tupdatedDoc.__v = newCurrDocV;\n\t\t\t\t\t\t\t\t\tcurrDoc._id = newCurrDocId;\n\t\t\t\t\t\t\t\t\tcurrDoc.__v = newCurrDocV;\n\n\t\t\t\t\t\t\t\t\tawait ResolveIOServer.getMongoManager().collection(collection).replaceOne({_id: newCurrDocId}, updatedDoc, {}, false, false, currDoc);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\tthrow new Error('Error In Update Document Props Collections: Invalid Version And Could Not Find History Props - DB: ' + newCurrDocV + ', Trying to update with :' + doc__v);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tthrow new Error('Error In Update Document Props Collections: Invalid Version And We Are NOT Using Versions On This Collection!');\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tthrow new Error('Error in Update Document Props Collections: No Document');\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn true;\n\t\t\t}\n\t\t},\n\t\tupdateDocumentOffline: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tf_document: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(collection: string, f_document: Object) {\n\t\t\t\tif (!ResolveIOServer.getMongoManager().collection(collection)) {\n\t\t\t\t\tthrow new Error('Error in Update Document Offline Collection: Invalid collection');\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tlet currDoc = await ResolveIOServer.getMongoManager().collection(collection).findOne({_id: f_document['_id']});\n\t\t\t\t\tif (currDoc) {\n\t\t\t\t\t\tif (currDoc.__v === f_document['__v']) {\n\t\t\t\t\t\t\tawait ResolveIOServer.getMongoManager().collection(collection).replaceOne({_id: f_document['_id']}, f_document, {}, false, false, currDoc);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tconsole.log('OFFLINE - invalid version - ' + collection, currDoc.__v, f_document['__v']);\n\n\t\t\t\t\t\t\tlet newCurrDocId = currDoc._id;\n\t\t\t\t\t\t\tlet newCurrDocV = currDoc.__v;\n\t\t\t\t\t\t\tlet oldDocV = f_document['__v'];\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tif (ResolveIOServer.getMongoManager().collection(collection + '.versions')) {\n\t\t\t\t\t\t\t\tlet oldDoc = await ResolveIOServer.getMongoManager().collection(collection + '.versions').findOne({\n\t\t\t\t\t\t\t\t\t_id: {\n\t\t\t\t\t\t\t\t\t\t_id: newCurrDocId,\n\t\t\t\t\t\t\t\t\t\t__v: oldDocV\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\tif (oldDoc) {\n\t\t\t\t\t\t\t\t\tlet updatedDoc = getMongoMergeUpdatedDoc(f_document, currDoc, oldDoc);\n\t\t\t\t\t\t\t\t\tupdatedDoc._id = newCurrDocId;\n\t\t\t\t\t\t\t\t\tupdatedDoc.__v = newCurrDocV;\n\t\t\t\t\t\t\t\t\tcurrDoc._id = newCurrDocId;\n\t\t\t\t\t\t\t\t\tcurrDoc.__v = newCurrDocV;\n\n\t\t\t\t\t\t\t\t\tawait ResolveIOServer.getMongoManager().collection(collection).replaceOne({_id: newCurrDocId}, updatedDoc, {}, false, false, currDoc);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\tthrow new Error('Error in Update Document Offline Collections: OFFLINE - Invalid Version And Could Not Find History Props - DB: ' + newCurrDocV + ', Trying to update with :' + oldDocV);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tthrow new Error('Error in Update Document Offline Collections: Invalid Version And We Are NOT Using Versions On This Collection!');\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tthrow new Error('Error in Update Document Offline Collections: No Document');\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn true;\n\t\t\t}\n\t\t},\n\t\t// Updates 1 document's props (from _id)\n\t\t// @Inputs: collection, document id, document version, update paramters ({prop: 'xxx', data: 'yyy})\n\t\t// @Outputs: res = 1 (updated 1), res = 0 (not updated), err = not updated/wrong version\n\t\t// Search for doc, check version, if found then try and update props\n\t\tupdateDocumentPropsOffline: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tdoc_id: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tupdateParams: {\n\t\t\t\t\ttype: Array\n\t\t\t\t},\n\t\t\t\t'updateParams.$': {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t},\n\t\t\t\tdoc__v: {\n\t\t\t\t\ttype: Number\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(collection: string, doc_id: string, updateParams: any[], doc__v: number) {\n\t\t\t\tif (!ResolveIOServer.getMongoManager().collection(collection)) {\n\t\t\t\t\tthrow new Error('Error in Update Document Props Offline Collection: Invalid collection');\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tlet currDoc = await ResolveIOServer.getMongoManager().collection(collection).findOne({_id: doc_id}, null, true);\n\t\t\t\t\tif (currDoc) {\n\t\t\t\t\t\tlet modifiedDoc = deepCopy(currDoc);\n\n\t\t\t\t\t\tupdateParams.forEach(data => {\n\t\t\t\t\t\t\tmodifiedDoc[data.prop] = data.data;\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tif (modifiedDoc.__v === doc__v) {\n\t\t\t\t\t\t\tawait ResolveIOServer.getMongoManager().collection(collection).replaceOne({_id: modifiedDoc._id}, modifiedDoc, {}, false, false, currDoc);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tconsole.log('OFFLINE - invalid version - ' + collection, currDoc.__v, doc__v);\n\n\t\t\t\t\t\t\tlet newCurrDocId = currDoc._id;\n\t\t\t\t\t\t\tlet newCurrDocV = currDoc.__v;\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tif (ResolveIOServer.getMongoManager().collection(collection + '.versions')) {\n\t\t\t\t\t\t\t\tlet oldDoc = await ResolveIOServer.getMongoManager().collection(collection + '.versions').findOne({\n\t\t\t\t\t\t\t\t\t_id: {\n\t\t\t\t\t\t\t\t\t\t_id: currDoc._id,\n\t\t\t\t\t\t\t\t\t\t__v: doc__v\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\tif (oldDoc) {\n\t\t\t\t\t\t\t\t\tlet updatedDoc = getMongoMergeUpdatedDoc(modifiedDoc, currDoc, oldDoc);\n\t\t\t\t\t\t\t\t\tupdatedDoc._id = newCurrDocId;\n\t\t\t\t\t\t\t\t\tupdatedDoc.__v = newCurrDocV;\n\t\t\t\t\t\t\t\t\tcurrDoc._id = newCurrDocId;\n\t\t\t\t\t\t\t\t\tcurrDoc.__v = newCurrDocV;\n\n\t\t\t\t\t\t\t\t\tawait ResolveIOServer.getMongoManager().collection(collection).replaceOne({_id: newCurrDocId}, updatedDoc, {}, false, false, currDoc);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\tthrow new Error('Error in Update Document Props Offline Collections: OFFLINE - Invalid Version And Could Not Find History Props - DB: ' + newCurrDocV + ', Trying to update with :' + doc__v);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tthrow new Error('Error in Update Document Props Offline Collections: Invalid Version And We Are NOT Using Versions On This Collection!');\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tthrow new Error('Error in Update Document Props Offline Collections: No Document');\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn true;\n\t\t\t}\n\t\t},\n\t\t// Removes 1 document (from _id)\n\t\t// @Inputs: collection, document id\n\t\t// @Outputs: res = 1 (deleted), res = 0 (not deleted), err = not deleted\n\t\t// Search for doc, if found then try and remove\n\t\tremoveDocument: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tdoc_id: {\n\t\t\t\t\ttype: String\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(collection: string, doc_id: string) {\n\t\t\t\tif (!ResolveIOServer.getMongoManager().collection(collection)) {\n\t\t\t\t\tthrow new Error('Error in Remove Document Collection: Invalid collection');\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tawait ResolveIOServer.getMongoManager().collection(collection).deleteOne({_id: doc_id});\n\n\t\t\t\treturn true;\n\t\t\t}\n\t\t},\n\t\tremoveDocumentWithQuery: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tquery: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(collection: string, query: Object) {\n\t\t\t\tif (!ResolveIOServer.getMongoManager().collection(collection)) {\n\t\t\t\t\tthrow new Error('Error in Remove Document With Query Collection: Invalid collection');\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tawait ResolveIOServer.getMongoManager().collection(collection).deleteOne(query);\n\n\t\t\t\treturn true;\n\t\t\t}\n\t\t},\n\t\tremoveDocumentsWithQuery: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tquery: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(collection: string, query: Object) {\n\t\t\t\tif (!ResolveIOServer.getMongoManager().collection(collection)) {\n\t\t\t\t\tthrow new Error('Error in Remove Documents With Query Collections: Invalid Collection');\n\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\tawait ResolveIOServer.getMongoManager().collection(collection).deleteMany(query);\n\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t});\n}"]}
1
+ {"version":3,"sources":["../../src/methods/collections.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,sDA8cC;AApdD,6CAAwC;AAExC,+DAAwF;AACxF,gEAA0D;AAC1D,yCAAsF;AAEtF,SAAgB,qBAAqB,CAAC,aAA4B;IACjE,aAAa,CAAC,OAAO,CAAC;QACrB,iBAAiB,EAAE;YAClB,QAAQ,EAAE;gBACT,OAAO,OAAO,CAAC,OAAO,CAAC,sCAAe,CAAC,eAAe,EAAE,CAAC,WAAW,EAAE,CAAC,GAAG,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,cAAc,EAAhB,CAAgB,CAAC,CAAC,IAAI,CAAC,UAAC,CAA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BACZ;gBACD,KAAK,EAAE;oBACN,IAAI,EAAE,MAAM;oBACZ,QAAQ,EAAE,IAAI;iBACd;aACD,CAAC;YACF,QAAQ,EAAE,UAAe,UAAkB,EAAE,KAAa;;;;;gCACzD,IAAI,CAAC,sCAAe,CAAC,eAAe,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;oCAC/D,MAAM,IAAI,KAAK,CAAC,oEAAoE,CAAC,CAAC;gCACvF,CAAC;gCAED,qBAAM,sCAAe,CAAC,eAAe,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,EAAA;;gCAA/E,SAA+E,CAAC;gCAEhF,sBAAO,IAAI,EAAC;;;;aACZ;SACD;QACD,wBAAwB,EAAE;YACzB,KAAK,EAAE,IAAI,sBAAY,CAAC;gBACvB,UAAU,EAAE;oBACX,IAAI,EAAE,MAAM;iBACZ;gBACD,KAAK,EAAE;oBACN,IAAI,EAAE,MAAM;oBACZ,QAAQ,EAAE,IAAI;iBACd;aACD,CAAC;YACF,QAAQ,EAAE,UAAe,UAAkB,EAAE,KAAa;;;;;gCACzD,IAAI,CAAC,sCAAe,CAAC,eAAe,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;oCAC/D,MAAM,IAAI,KAAK,CAAC,sEAAsE,CAAC,CAAC;gCACzF,CAAC;gCAED,qBAAM,sCAAe,CAAC,eAAe,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,EAAA;;gCAAhF,SAAgF,CAAC;gCAEjF,sBAAO,IAAI,EAAC;;;;aACZ;SACD;KACD,CAAC,CAAC;AACJ,CAAC","file":"collections.js","sourcesContent":["import SimpleSchema from 'simpl-schema';\nimport { MethodManager } from '../managers/method.manager';\nimport { PaginationOptions, PaginationOptionsSchema } from '../models/pagination.model';\nimport { ResolveIOServer } from '../resolveio-server-app';\nimport { deepCopy, getMongoMergeUpdatedDoc, objectIdHexString } from '../util/common';\n\nexport function loadCollectionMethods(methodManager: MethodManager) {\n\tmethodManager.methods({\n\t\tcollectionListAll: {\n\t\t\tfunction: function() {\n\t\t\t\treturn Promise.resolve(ResolveIOServer.getMongoManager().collections().map(a => a.collectionName).sort((a, b) => a.localeCompare(b)));\n\t\t\t}\n\t\t},\n\t\tcollectionListRB: {\n\t\t\tfunction: function() {\n\t\t\t\treturn Promise.resolve(ResolveIOServer.getMongoManager().collections().filter(a => a.useRB).map(a => a.collectionName).sort((a, b) => a.localeCompare(b)));\n\t\t\t}\n\t\t},\n\t\t// Query database for any collection and query\n\t\tfindOne: {\n\t\t\tbypassSession: true,\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tquery: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: function(collection: string, query = {}) {\n\t\t\t\tif (!ResolveIOServer.getMongoManager().collection(collection)) {\n\t\t\t\t\tthrow new Error('Error in Find One Collection: Invalid collection');\n\t\t\t\t}\n\n\t\t\t\treturn ResolveIOServer.getMongoManager().collection(collection).findOne(query);\n\t\t\t}\n\t\t},\n\t\tfind: {\n\t\t\tbypassSession: true,\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tquery: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t},\n\t\t\t\tsort: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true,\n\t\t\t\t\toptional: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: function(collection: string, query = {}, sortQuery = {}) {\n\t\t\t\tif (!ResolveIOServer.getMongoManager().collection(collection)) {\n\t\t\t\t\tthrow new Error('Error in Find Collection: Invalid collection');\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\treturn ResolveIOServer.getMongoManager().collection(collection).find(query, {sort: sortQuery});\n\t\t\t}\n\t\t},\n\t\tfindWithOptions: {\n\t\t\tbypassSession: true,\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tquery: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t},\n\t\t\t\toptions: {\n\t\t\t\t\ttype: PaginationOptionsSchema\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: function(collection: string, query: Object, options: PaginationOptions) {\n\t\t\t\tif (!ResolveIOServer.getMongoManager().collection(collection)) {\n\t\t\t\t\tthrow new Error('Error in Find With Options Collection: Invalid collection');\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tlet optionsQuery = {};\n\n\t\t\t\t\tif (options.fields && Object.keys(options.fields).length) {\n\t\t\t\t\t\toptionsQuery['projection'] = options.fields;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (options.sort && Object.keys(options.sort).length) {\n\t\t\t\t\t\toptionsQuery['sort'] = options.sort;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (options.limit) {\n\t\t\t\t\t\toptionsQuery['limit'] = options.limit;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (options.skip) {\n\t\t\t\t\t\toptionsQuery['skip'] = options.skip;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn ResolveIOServer.getMongoManager().collection(collection).find(query, optionsQuery);\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t// Insert 1 document\n\t\t// @Inputs: collection, document\n\t\t// @Outputs: res = _id of new document, err = not inserted\n\t\tinsertDocument: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tdocument: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(collection: string, document: Object) {\n\t\t\t\tif (!ResolveIOServer.getMongoManager().collection(collection)) {\n\t\t\t\t\tthrow new Error('Error in Insert Document Collection: Invalid collection');\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tlet id = objectIdHexString();\n\t\t\t\t\tdocument['_id'] = id;\n\t\t\t\t\tdocument['__v'] = 0;\n\n\t\t\t\t\tawait ResolveIOServer.getMongoManager().collection(collection).insertOne(document);\n\t\t\t\t\treturn id;\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t// Insert 1 document\n\t\t// @Inputs: collection, document\n\t\t// @Outputs: res = _id of new document, err = not inserted\n\t\tinsertManyDocuments: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tdocuments: {\n\t\t\t\t\ttype: Array\n\t\t\t\t},\n\t\t\t\t'documents.$': {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(collection: string, documents: Object[]) {\n\t\t\t\tif (!ResolveIOServer.getMongoManager().collection(collection)) {\n\t\t\t\t\tthrow new Error('Error in Insert Many Documents Collection: Invalid collection');\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tdocuments.forEach(document => {\n\t\t\t\t\t\tdocument['_id'] = objectIdHexString();\n\t\t\t\t\t\tdocument['__v'] = 0;\n\t\t\t\t\t});\n\n\t\t\t\t\tawait ResolveIOServer.getMongoManager().collection(collection).insertMany(documents);\n\t\t\t\t\treturn documents.map(a => a['_id']);\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t// Replaces 1 document with new document (from _id)\n\t\t// @Inputs: collection, document id\n\t\t// @Outputs: res = 1 (updated 1), err = not updated/wrong version\n\t\t// Search for doc, check version, if found then try and update\n\t\tupdateDocument: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tf_document: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(collection: string, f_document: Object) {\n\t\t\t\tif (!ResolveIOServer.getMongoManager().collection(collection)) {\n\t\t\t\t\tthrow new Error('Error in Update Document Collection: Invalid collection');\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tawait ResolveIOServer.getMongoManager().collection(collection).replaceOne({_id: f_document['_id']}, f_document);\n\t\t\t\treturn true;\n\t\t\t}\n\t\t},\n\t\t// Updates 1 document's props (from _id)\n\t\t// @Inputs: collection, document id, document version, update paramters ({prop: 'xxx', data: 'yyy})\n\t\t// @Outputs: res = 1 (updated 1), res = 0 (not updated), err = not updated/wrong version\n\t\t// Search for doc, check version, if found then try and update props\n\t\tupdateDocumentProps: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tdoc_id: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tupdateParams: {\n\t\t\t\t\ttype: Array\n\t\t\t\t},\n\t\t\t\t'updateParams.$': {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t},\n\t\t\t\tdoc__v: {\n\t\t\t\t\ttype: Number,\n\t\t\t\t\toptional: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(collection: string, doc_id: string, updateParams: any[], doc__v?: number) {\n\t\t\t\tif (!ResolveIOServer.getMongoManager().collection(collection)) {\n\t\t\t\t\tthrow new Error('Error in Update Document Props Collection: Invalid collection');\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tlet currDoc = await ResolveIOServer.getMongoManager().collection(collection).findOne({_id: doc_id});\n\t\t\t\t\tif (currDoc) {\n\t\t\t\t\t\tlet modifiedDoc = deepCopy(currDoc);\n\n\t\t\t\t\t\tupdateParams.forEach(data => {\n\t\t\t\t\t\t\tmodifiedDoc[data.prop] = data.data;\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tif (!doc__v || modifiedDoc.__v === doc__v) {\n\t\t\t\t\t\t\tawait ResolveIOServer.getMongoManager().collection(collection).replaceOne({_id: modifiedDoc._id}, modifiedDoc, {}, false, false, currDoc);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tconsole.log(new Date(), 'invalid version - ' + collection, currDoc.__v, doc__v);\n\n\t\t\t\t\t\t\tif (ResolveIOServer.getMongoManager().collection(collection + '.versions')) {\n\t\t\t\t\t\t\t\tlet oldDoc = await ResolveIOServer.getMongoManager().collection(collection + '.versions').findOne({\n\t\t\t\t\t\t\t\t\t_id: {\n\t\t\t\t\t\t\t\t\t\t_id: currDoc._id,\n\t\t\t\t\t\t\t\t\t\t__v: doc__v\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\tlet newCurrDocId = currDoc._id;\n\t\t\t\t\t\t\t\tlet newCurrDocV = currDoc.__v;\n\n\t\t\t\t\t\t\t\tif (oldDoc) {\n\t\t\t\t\t\t\t\t\tlet updatedDoc = getMongoMergeUpdatedDoc(modifiedDoc, currDoc, oldDoc);\n\t\t\t\t\t\t\t\t\tupdatedDoc._id = newCurrDocId;\n\t\t\t\t\t\t\t\t\tupdatedDoc.__v = newCurrDocV;\n\t\t\t\t\t\t\t\t\tcurrDoc._id = newCurrDocId;\n\t\t\t\t\t\t\t\t\tcurrDoc.__v = newCurrDocV;\n\n\t\t\t\t\t\t\t\t\tawait ResolveIOServer.getMongoManager().collection(collection).replaceOne({_id: newCurrDocId}, updatedDoc, {}, false, false, currDoc);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\tthrow new Error('Error In Update Document Props Collections: Invalid Version And Could Not Find History Props - DB: ' + newCurrDocV + ', Trying to update with :' + doc__v);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tthrow new Error('Error In Update Document Props Collections: Invalid Version And We Are NOT Using Versions On This Collection!');\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tthrow new Error('Error in Update Document Props Collections: No Document');\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn true;\n\t\t\t}\n\t\t},\n\t\tupdateDocumentOffline: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tf_document: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(collection: string, f_document: Object) {\n\t\t\t\tif (!ResolveIOServer.getMongoManager().collection(collection)) {\n\t\t\t\t\tthrow new Error('Error in Update Document Offline Collection: Invalid collection');\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tlet currDoc = await ResolveIOServer.getMongoManager().collection(collection).findOne({_id: f_document['_id']});\n\t\t\t\t\tif (currDoc) {\n\t\t\t\t\t\tif (currDoc.__v === f_document['__v']) {\n\t\t\t\t\t\t\tawait ResolveIOServer.getMongoManager().collection(collection).replaceOne({_id: f_document['_id']}, f_document, {}, false, false, currDoc);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tconsole.log('OFFLINE - invalid version - ' + collection, currDoc.__v, f_document['__v']);\n\n\t\t\t\t\t\t\tlet newCurrDocId = currDoc._id;\n\t\t\t\t\t\t\tlet newCurrDocV = currDoc.__v;\n\t\t\t\t\t\t\tlet oldDocV = f_document['__v'];\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tif (ResolveIOServer.getMongoManager().collection(collection + '.versions')) {\n\t\t\t\t\t\t\t\tlet oldDoc = await ResolveIOServer.getMongoManager().collection(collection + '.versions').findOne({\n\t\t\t\t\t\t\t\t\t_id: {\n\t\t\t\t\t\t\t\t\t\t_id: newCurrDocId,\n\t\t\t\t\t\t\t\t\t\t__v: oldDocV\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\tif (oldDoc) {\n\t\t\t\t\t\t\t\t\tlet updatedDoc = getMongoMergeUpdatedDoc(f_document, currDoc, oldDoc);\n\t\t\t\t\t\t\t\t\tupdatedDoc._id = newCurrDocId;\n\t\t\t\t\t\t\t\t\tupdatedDoc.__v = newCurrDocV;\n\t\t\t\t\t\t\t\t\tcurrDoc._id = newCurrDocId;\n\t\t\t\t\t\t\t\t\tcurrDoc.__v = newCurrDocV;\n\n\t\t\t\t\t\t\t\t\tawait ResolveIOServer.getMongoManager().collection(collection).replaceOne({_id: newCurrDocId}, updatedDoc, {}, false, false, currDoc);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\tthrow new Error('Error in Update Document Offline Collections: OFFLINE - Invalid Version And Could Not Find History Props - DB: ' + newCurrDocV + ', Trying to update with :' + oldDocV);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tthrow new Error('Error in Update Document Offline Collections: Invalid Version And We Are NOT Using Versions On This Collection!');\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tthrow new Error('Error in Update Document Offline Collections: No Document');\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn true;\n\t\t\t}\n\t\t},\n\t\t// Updates 1 document's props (from _id)\n\t\t// @Inputs: collection, document id, document version, update paramters ({prop: 'xxx', data: 'yyy})\n\t\t// @Outputs: res = 1 (updated 1), res = 0 (not updated), err = not updated/wrong version\n\t\t// Search for doc, check version, if found then try and update props\n\t\tupdateDocumentPropsOffline: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tdoc_id: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tupdateParams: {\n\t\t\t\t\ttype: Array\n\t\t\t\t},\n\t\t\t\t'updateParams.$': {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t},\n\t\t\t\tdoc__v: {\n\t\t\t\t\ttype: Number\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(collection: string, doc_id: string, updateParams: any[], doc__v: number) {\n\t\t\t\tif (!ResolveIOServer.getMongoManager().collection(collection)) {\n\t\t\t\t\tthrow new Error('Error in Update Document Props Offline Collection: Invalid collection');\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tlet currDoc = await ResolveIOServer.getMongoManager().collection(collection).findOne({_id: doc_id}, null, true);\n\t\t\t\t\tif (currDoc) {\n\t\t\t\t\t\tlet modifiedDoc = deepCopy(currDoc);\n\n\t\t\t\t\t\tupdateParams.forEach(data => {\n\t\t\t\t\t\t\tmodifiedDoc[data.prop] = data.data;\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tif (modifiedDoc.__v === doc__v) {\n\t\t\t\t\t\t\tawait ResolveIOServer.getMongoManager().collection(collection).replaceOne({_id: modifiedDoc._id}, modifiedDoc, {}, false, false, currDoc);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tconsole.log('OFFLINE - invalid version - ' + collection, currDoc.__v, doc__v);\n\n\t\t\t\t\t\t\tlet newCurrDocId = currDoc._id;\n\t\t\t\t\t\t\tlet newCurrDocV = currDoc.__v;\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tif (ResolveIOServer.getMongoManager().collection(collection + '.versions')) {\n\t\t\t\t\t\t\t\tlet oldDoc = await ResolveIOServer.getMongoManager().collection(collection + '.versions').findOne({\n\t\t\t\t\t\t\t\t\t_id: {\n\t\t\t\t\t\t\t\t\t\t_id: currDoc._id,\n\t\t\t\t\t\t\t\t\t\t__v: doc__v\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\tif (oldDoc) {\n\t\t\t\t\t\t\t\t\tlet updatedDoc = getMongoMergeUpdatedDoc(modifiedDoc, currDoc, oldDoc);\n\t\t\t\t\t\t\t\t\tupdatedDoc._id = newCurrDocId;\n\t\t\t\t\t\t\t\t\tupdatedDoc.__v = newCurrDocV;\n\t\t\t\t\t\t\t\t\tcurrDoc._id = newCurrDocId;\n\t\t\t\t\t\t\t\t\tcurrDoc.__v = newCurrDocV;\n\n\t\t\t\t\t\t\t\t\tawait ResolveIOServer.getMongoManager().collection(collection).replaceOne({_id: newCurrDocId}, updatedDoc, {}, false, false, currDoc);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\tthrow new Error('Error in Update Document Props Offline Collections: OFFLINE - Invalid Version And Could Not Find History Props - DB: ' + newCurrDocV + ', Trying to update with :' + doc__v);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tthrow new Error('Error in Update Document Props Offline Collections: Invalid Version And We Are NOT Using Versions On This Collection!');\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tthrow new Error('Error in Update Document Props Offline Collections: No Document');\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn true;\n\t\t\t}\n\t\t},\n\t\t// Removes 1 document (from _id)\n\t\t// @Inputs: collection, document id\n\t\t// @Outputs: res = 1 (deleted), res = 0 (not deleted), err = not deleted\n\t\t// Search for doc, if found then try and remove\n\t\tremoveDocument: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tdoc_id: {\n\t\t\t\t\ttype: String\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(collection: string, doc_id: string) {\n\t\t\t\tif (!ResolveIOServer.getMongoManager().collection(collection)) {\n\t\t\t\t\tthrow new Error('Error in Remove Document Collection: Invalid collection');\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tawait ResolveIOServer.getMongoManager().collection(collection).deleteOne({_id: doc_id});\n\n\t\t\t\treturn true;\n\t\t\t}\n\t\t},\n\t\tremoveDocumentWithQuery: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tquery: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(collection: string, query: Object) {\n\t\t\t\tif (!ResolveIOServer.getMongoManager().collection(collection)) {\n\t\t\t\t\tthrow new Error('Error in Remove Document With Query Collection: Invalid collection');\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tawait ResolveIOServer.getMongoManager().collection(collection).deleteOne(query);\n\n\t\t\t\treturn true;\n\t\t\t}\n\t\t},\n\t\tremoveDocumentsWithQuery: {\n\t\t\tcheck: new SimpleSchema({\n\t\t\t\tcollection: {\n\t\t\t\t\ttype: String\n\t\t\t\t},\n\t\t\t\tquery: {\n\t\t\t\t\ttype: Object,\n\t\t\t\t\tblackbox: true\n\t\t\t\t}\n\t\t\t}),\n\t\t\tfunction: async function(collection: string, query: Object) {\n\t\t\t\tif (!ResolveIOServer.getMongoManager().collection(collection)) {\n\t\t\t\t\tthrow new Error('Error in Remove Documents With Query Collections: Invalid Collection');\n\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\tawait ResolveIOServer.getMongoManager().collection(collection).deleteMany(query);\n\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t});\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@resolveio/server-lib",
3
- "version": "20.11.13",
3
+ "version": "20.11.15",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "package": "./build_package.sh",
@@ -19,6 +19,9 @@ export declare class ResolveIOServer {
19
19
  private static handleMongoDisconnect;
20
20
  private static reconnectMongo;
21
21
  private static delay;
22
+ private static resolveMongoClientOptions;
23
+ private static pickMongoOptionValue;
24
+ private static pickMongoBooleanOptionValue;
22
25
  constructor();
23
26
  static create(serverConfig: any, clientRoutes: string[], client: string, clientDir: any, sesMail?: boolean, standardProgram?: boolean): Promise<ResolveIOServer>;
24
27
  private initialize;
@@ -35,6 +35,17 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
35
35
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
36
  }
37
37
  };
38
+ var __values = (this && this.__values) || function(o) {
39
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
40
+ if (m) return m.call(o);
41
+ if (o && typeof o.length === "number") return {
42
+ next: function () {
43
+ if (o && i >= o.length) o = void 0;
44
+ return { value: o && o[i++], done: !o };
45
+ }
46
+ };
47
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
48
+ };
38
49
  Object.defineProperty(exports, "__esModule", { value: true });
39
50
  exports.ResolveIOServer = void 0;
40
51
  var mongodb_1 = require("mongodb");
@@ -43,10 +54,13 @@ var ResolveIOServer = /** @class */ (function () {
43
54
  }
44
55
  ResolveIOServer.connectMongo = function () {
45
56
  return __awaiter(this, void 0, void 0, function () {
46
- var client;
57
+ var mongoUrl, clientOptions, client;
47
58
  return __generator(this, function (_a) {
48
59
  switch (_a.label) {
49
- case 0: return [4 /*yield*/, mongodb_1.MongoClient.connect(ResolveIOServer.getServerConfig()['MONGO_URL'])];
60
+ case 0:
61
+ mongoUrl = ResolveIOServer.getServerConfig()['MONGO_URL'];
62
+ clientOptions = ResolveIOServer.resolveMongoClientOptions();
63
+ return [4 /*yield*/, mongodb_1.MongoClient.connect(mongoUrl, clientOptions)];
50
64
  case 1:
51
65
  client = _a.sent();
52
66
  client.on('close', ResolveIOServer.handleMongoDisconnect);
@@ -124,6 +138,99 @@ var ResolveIOServer = /** @class */ (function () {
124
138
  });
125
139
  });
126
140
  };
141
+ ResolveIOServer.resolveMongoClientOptions = function () {
142
+ var e_1, _a, _b, e_2, _c, _d;
143
+ var config = ResolveIOServer.getServerConfig();
144
+ var options = {};
145
+ var numericOptionKeys = [
146
+ { key: 'maxPoolSize', env: 'MONGO_MAX_POOL_SIZE', configKey: 'MONGO_MAX_POOL_SIZE' },
147
+ { key: 'minPoolSize', env: 'MONGO_MIN_POOL_SIZE', configKey: 'MONGO_MIN_POOL_SIZE' },
148
+ { key: 'waitQueueTimeoutMS', env: 'MONGO_WAIT_QUEUE_TIMEOUT_MS', configKey: 'MONGO_WAIT_QUEUE_TIMEOUT_MS' },
149
+ { key: 'maxIdleTimeMS', env: 'MONGO_MAX_IDLE_TIME_MS', configKey: 'MONGO_MAX_IDLE_TIME_MS' }
150
+ ];
151
+ try {
152
+ for (var numericOptionKeys_1 = __values(numericOptionKeys), numericOptionKeys_1_1 = numericOptionKeys_1.next(); !numericOptionKeys_1_1.done; numericOptionKeys_1_1 = numericOptionKeys_1.next()) {
153
+ var option = numericOptionKeys_1_1.value;
154
+ var value = ResolveIOServer.pickMongoOptionValue(option.env, option.configKey);
155
+ if (typeof value === 'number') {
156
+ Object.assign(options, (_b = {}, _b[option.key] = value, _b));
157
+ }
158
+ }
159
+ }
160
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
161
+ finally {
162
+ try {
163
+ if (numericOptionKeys_1_1 && !numericOptionKeys_1_1.done && (_a = numericOptionKeys_1.return)) _a.call(numericOptionKeys_1);
164
+ }
165
+ finally { if (e_1) throw e_1.error; }
166
+ }
167
+ var booleanOptionKeys = [
168
+ { key: 'retryWrites', env: 'MONGO_RETRY_WRITES', configKey: 'MONGO_RETRY_WRITES' }
169
+ ];
170
+ try {
171
+ for (var booleanOptionKeys_1 = __values(booleanOptionKeys), booleanOptionKeys_1_1 = booleanOptionKeys_1.next(); !booleanOptionKeys_1_1.done; booleanOptionKeys_1_1 = booleanOptionKeys_1.next()) {
172
+ var option = booleanOptionKeys_1_1.value;
173
+ var value = ResolveIOServer.pickMongoBooleanOptionValue(option.env, option.configKey);
174
+ if (typeof value === 'boolean') {
175
+ Object.assign(options, (_d = {}, _d[option.key] = value, _d));
176
+ }
177
+ }
178
+ }
179
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
180
+ finally {
181
+ try {
182
+ if (booleanOptionKeys_1_1 && !booleanOptionKeys_1_1.done && (_c = booleanOptionKeys_1.return)) _c.call(booleanOptionKeys_1);
183
+ }
184
+ finally { if (e_2) throw e_2.error; }
185
+ }
186
+ var structuredOptions = config === null || config === void 0 ? void 0 : config['MONGO_CLIENT_OPTIONS'];
187
+ if (structuredOptions && typeof structuredOptions === 'object' && !Array.isArray(structuredOptions)) {
188
+ Object.assign(options, structuredOptions);
189
+ }
190
+ return Object.keys(options).length ? options : undefined;
191
+ };
192
+ ResolveIOServer.pickMongoOptionValue = function (envKey, configKey) {
193
+ var rawEnv = process.env[envKey];
194
+ if (rawEnv && !Number.isNaN(Number(rawEnv))) {
195
+ var parsed = parseInt(rawEnv, 10);
196
+ return Number.isFinite(parsed) && parsed > 0 ? parsed : undefined;
197
+ }
198
+ var config = ResolveIOServer.getServerConfig();
199
+ var configValue = config === null || config === void 0 ? void 0 : config[configKey];
200
+ if (typeof configValue === 'number' && Number.isFinite(configValue) && configValue > 0) {
201
+ return configValue;
202
+ }
203
+ if (typeof configValue === 'string' && configValue.trim().length && !Number.isNaN(Number(configValue))) {
204
+ var parsed = parseInt(configValue, 10);
205
+ return Number.isFinite(parsed) && parsed > 0 ? parsed : undefined;
206
+ }
207
+ return undefined;
208
+ };
209
+ ResolveIOServer.pickMongoBooleanOptionValue = function (envKey, configKey) {
210
+ var rawEnv = process.env[envKey];
211
+ if (typeof rawEnv === 'string' && rawEnv.length) {
212
+ if (['true', '1', 'yes'].includes(rawEnv.toLowerCase())) {
213
+ return true;
214
+ }
215
+ else if (['false', '0', 'no'].includes(rawEnv.toLowerCase())) {
216
+ return false;
217
+ }
218
+ }
219
+ var config = ResolveIOServer.getServerConfig();
220
+ var configValue = config === null || config === void 0 ? void 0 : config[configKey];
221
+ if (typeof configValue === 'boolean') {
222
+ return configValue;
223
+ }
224
+ if (typeof configValue === 'string' && configValue.length) {
225
+ if (['true', '1', 'yes'].includes(configValue.toLowerCase())) {
226
+ return true;
227
+ }
228
+ else if (['false', '0', 'no'].includes(configValue.toLowerCase())) {
229
+ return false;
230
+ }
231
+ }
232
+ return undefined;
233
+ };
127
234
  ResolveIOServer.create = function (serverConfig_1, clientRoutes_1, client_1, clientDir_1) {
128
235
  return __awaiter(this, arguments, void 0, function (serverConfig, clientRoutes, client, clientDir, sesMail, standardProgram) {
129
236
  var resolveioServer;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/resolveio-server-app.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mCAA0C;AAK1C;IA+DC;IAAe,CAAC;IAhDK,4BAAY,GAAjC;;;;;4BACgB,qBAAM,qBAAW,CAAC,OAAO,CAAC,eAAe,CAAC,eAAe,EAAE,CAAC,WAAW,CAAC,CAAC,EAAA;;wBAAlF,MAAM,GAAG,SAAyE;wBACxF,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,eAAe,CAAC,qBAAqB,CAAC,CAAC;wBAC1D,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,eAAe,CAAC,qBAAqB,CAAC,CAAC;wBAC1D,MAAM,CAAC,EAAE,CAAC,uBAAuB,EAAE,eAAe,CAAC,qBAAqB,CAAC,CAAC;wBAC1E,sBAAO,MAAM,EAAC;;;;KACd;IAEoB,qCAAqB,GAA1C,UAA2C,GAAG;;;;;wBAC7C,OAAO,CAAC,KAAK,CAAC,IAAI,IAAI,EAAE,EAAE,uBAAuB,EAAE,GAAG,CAAC,CAAC;w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,CAAC;IAC9C,CAAC;IAEa,kCAAkB,GAAhC;QACC,OAAO,eAAe,CAAC,gBAAgB,CAAC;IACzC,CAAC;IAEa,kCAAkB,GAAhC,UAAiC,eAAgC;QAChE,eAAe,CAAC,gBAAgB,GAAG,eAAe,CAAC;IACpD,CAAC;IAEa,+BAAe,GAA7B;QACC,OAAO,eAAe,CAAC,aAAa,CAAC;IACtC,CAAC;IAEa,+BAAe,GAA7B;QACC,OAAO,eAAe,CAAC,aAAa,CAAC;IACtC,CAAC;IAEa,4BAAY,GAA1B;QACC,OAAO,eAAe,CAAC,UAAU,CAAC;IACnC,CAAC;IAEa,0BAAU,GAAxB;QACC,OAAO,eAAe,CAAC,QAAQ,CAAC;IACjC,CAAC;IAEa,kCAAkB,GAAhC;QACC,OAAO,eAAe,CAAC,gBAAgB,CAAC;IACzC,CAAC;IAnLc,6BAAa,GAAG,IAAI,CAAC;IACrB,6BAAa,GAAG,EAAE,CAAC;IACnB,gCAAgB,GAAgB,IAAI,CAAC;IACrC,uBAAO,GAAO,IAAI,CAAC;IACnB,2BAAW,GAAG,IAAI,CAAC;IACnB,gCAAgB,GAAG,IAAI,CAAC;IACxB,6BAAa,GAAG,IAAI,CAAC;IACrB,uBAAO,GAAG,EAAE,CAAC;IACb,0BAAU,GAAG,EAAE,CAAC;IAChB,wBAAQ,GAAG,IAAI,CAAC;IAChB,gCAAgB,GAAG,KAAK,CAAC;IAEzB,6BAAa,GAAG,KAAK,CAAC;IAwKtC,sBAAC;CArLD,AAqLC,IAAA;AArLY,0CAAe","file":"resolveio-server-app.js","sourcesContent":["import { Db, MongoClient } from 'mongodb';\nimport { LocalLogManager } from './managers/local-log.manager';\nimport { MongoManager } from './managers/mongo.manager';\nimport { ResolveIOMainServer } from './server-app';\n\nexport class ResolveIOServer {\n\tprivate static _serverConfig = null;\n\tprivate static _clientRoutes = [];\n\tprivate static _mongoConnection: MongoClient = null;\n\tprivate static _mainDB: Db = null;\n\tprivate static _mainServer = null;\n\tprivate static _localLogManager = null;\n\tprivate static _mongoManager = null;\n\tprivate static _client = '';\n\tprivate static _clientDir = '';\n\tprivate static _sesMail = true;\n\tprivate static _standardProgram = false;\n\n\tprivate static _reconnecting = false;\n\n\tprivate static async connectMongo(): Promise<MongoClient> {\n\t\tconst client = await MongoClient.connect(ResolveIOServer.getServerConfig()['MONGO_URL']);\n\t\tclient.on('close', ResolveIOServer.handleMongoDisconnect);\n\t\tclient.on('error', ResolveIOServer.handleMongoDisconnect);\n\t\tclient.on('connectionPoolCleared', ResolveIOServer.handleMongoDisconnect);\n\t\treturn client;\n\t}\n\n\tprivate static async handleMongoDisconnect(err): Promise<void> {\n\t\tconsole.error(new Date(), 'Mongo connection lost', err);\n\t\tif (ResolveIOServer._reconnecting) {\n\t\t\treturn;\n\t\t}\n\n\t\tResolveIOServer._reconnecting = true;\n\n\t\ttry {\n\t\t\tawait ResolveIOServer.reconnectMongo();\n\t\t}\n\t\tfinally {\n\t\t\tResolveIOServer._reconnecting = false;\n\t\t}\n\t}\n\n\tprivate static async reconnectMongo(): Promise<void> {\n\t\tlet attempt = 0;\n\n\t\twhile (true) {\n\t\t\ttry {\n\t\t\t\tconst client = await ResolveIOServer.connectMongo();\n\t\t\t\tResolveIOServer.setMongoConnection(client);\n\t\t\t\tResolveIOServer.setMainDB(client.db(ResolveIOServer.getServerConfig()['DATABASE']));\n\t\t\t\tconsole.log(new Date(), 'Mongo reconnected');\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcatch (err) {\n\t\t\t\tattempt++;\n\t\t\t\tconsole.error(new Date(), 'Mongo reconnect failed', err);\n\t\t\t\tawait ResolveIOServer.delay(Math.min(attempt * 1000, 10000));\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate static async delay(ms: number) {\n\t\t// eslint-disable-next-line no-restricted-syntax\n\t\treturn new Promise(resolve => setTimeout(resolve, ms));\n\t}\n\n\tconstructor() {}\n\t\n\tpublic static async create(serverConfig, clientRoutes: string[], client: string, clientDir, sesMail = true, standardProgram = false) {\n\t\tconst resolveioServer = new ResolveIOServer();\n\t\tawait resolveioServer.initialize(serverConfig, clientRoutes, client, clientDir, sesMail, standardProgram);\n\t\treturn resolveioServer;\n\t}\n\n\tprivate async initialize(serverConfig, clientRoutes: string[], client: string, clientDir, sesMail = true, standardProgram = false) {\n\t\tResolveIOServer._serverConfig = serverConfig;\n\t\tResolveIOServer._clientRoutes = clientRoutes;\n\t\tResolveIOServer._client = client;\n\t\tResolveIOServer._clientDir = clientDir;\n\t\tResolveIOServer._sesMail = sesMail;\n\t\tResolveIOServer._standardProgram = standardProgram;\n\t\t\n\t\ttry {\n\t\t\tlet dbConnection = await ResolveIOServer.connectMongo();\n\t\t\tprocess.removeAllListeners('unhandledRejection');\n\n\t\t\tResolveIOServer.setMongoConnection(dbConnection);\n\t\t\tResolveIOServer.setMainDB(dbConnection.db(ResolveIOServer.getServerConfig()['DATABASE']));\n\n\t\t\t// dbConnection\n\t\t\t// .on('error', error => {\n\t\t\t// \tif (typeof error.message === 'string' && error.message.includes('ns does not exist')) {\n\t\t\t// \t\treturn;\n\t\t\t// \t}\n\t\t\t\t\t\n\t\t\t// \t// Otherwise log normally\n\t\t\t// \tthrow error;\n\t\t\t// })\n\t\t\t// .on('close', () => process.exit(1));\n\t\n\t\t\tlet LocalLogManager = (await import('./managers/local-log.manager')).LocalLogManager;\n\t\t\tlet localLogManager = LocalLogManager.create();\n\t\t\tResolveIOServer.setLocalLogManager(localLogManager);\n\n\t\t\tlet MongoManager = (await import('./managers/mongo.manager')).MongoManager;\n\t\t\tlet mongoManager = await MongoManager.create();\n\t\t\tResolveIOServer.setMongoManager(mongoManager);\n\t\t\t\n\t\t\tlet serverApp = (await import('./server-app')).ResolveIOMainServer;\n\t\t\tlet app = await serverApp.create();\n\t\t\tResolveIOServer.setMainServer(app);\n\t\t\t\n\t\t\treturn true;\n\t\t}\n\t\tcatch (err) {\n\t\t\terr.message = 'Error in ResolveIOServer (initialize): Mongo Client Connect And Run ResolveIO Server App Library - ' + err.message;\n\t\t\tconsole.error(err.message);\n\t\t\tprocess.exit(1);\n\t\t}\n\t}\n\n\tpublic static getClientName() {\n\t\treturn this._client;\n\t}\n\n\tpublic static getMainServer(): ResolveIOMainServer {\n\t\treturn ResolveIOServer._mainServer;\n\t}\n\n\tpublic static setMainServer(mainServer: ResolveIOMainServer) {\n\t\tResolveIOServer._mainServer = mainServer;\n\t}\n\n\tpublic static setMongoConnection(mongoConnection: MongoClient) {\n\t\tResolveIOServer._mongoConnection = mongoConnection;\n\t}\n\n\tpublic static getMongoConnection(): MongoClient {\n\t\treturn ResolveIOServer._mongoConnection;\n\t}\n\n\tpublic static getMainDB(): Db {\n\t\treturn ResolveIOServer._mainDB;\n\t}\n\n\tpublic static setMainDB(mainDB: Db) {\n\t\tResolveIOServer._mainDB = mainDB\n\t}\n\n\tpublic static getMongoManager(): MongoManager {\n\t\treturn ResolveIOServer._mongoManager;\n\t}\n\n\tpublic static setMongoManager(mongoManager: MongoManager) {\n\t\tResolveIOServer._mongoManager = mongoManager;\n\t}\n\n\tpublic static getLocalLogManager(): LocalLogManager {\n\t\treturn ResolveIOServer._localLogManager;\n\t}\n\n\tpublic static setLocalLogManager(localLogManager: LocalLogManager) {\n\t\tResolveIOServer._localLogManager = localLogManager;\n\t}\n\n\tpublic static getServerConfig() {\n\t\treturn ResolveIOServer._serverConfig;\n\t}\n\n\tpublic static getClientRoutes() {\n\t\treturn ResolveIOServer._clientRoutes;\n\t}\n\n\tpublic static getClientDir(): string {\n\t\treturn ResolveIOServer._clientDir;\n\t}\n\n\tpublic static getSESMail(): boolean {\n\t\treturn ResolveIOServer._sesMail;\n\t}\n\n\tpublic static getStandardProgram(): boolean {\n\t\treturn ResolveIOServer._standardProgram;\n\t}\n}"]}
1
+ {"version":3,"sources":["../../src/resolveio-server-app.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mCAA8D;AAK9D;IAwJC;IAA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aAAa,CAAC;IACtC,CAAC;IAEa,+BAAe,GAA7B;QACC,OAAO,eAAe,CAAC,aAAa,CAAC;IACtC,CAAC;IAEa,4BAAY,GAA1B;QACC,OAAO,eAAe,CAAC,UAAU,CAAC;IACnC,CAAC;IAEa,0BAAU,GAAxB;QACC,OAAO,eAAe,CAAC,QAAQ,CAAC;IACjC,CAAC;IAEa,kCAAkB,GAAhC;QACC,OAAO,eAAe,CAAC,gBAAgB,CAAC;IACzC,CAAC;IA5Qc,6BAAa,GAAG,IAAI,CAAC;IACrB,6BAAa,GAAG,EAAE,CAAC;IACnB,gCAAgB,GAAgB,IAAI,CAAC;IACrC,uBAAO,GAAO,IAAI,CAAC;IACnB,2BAAW,GAAG,IAAI,CAAC;IACnB,gCAAgB,GAAG,IAAI,CAAC;IACxB,6BAAa,GAAG,IAAI,CAAC;IACrB,uBAAO,GAAG,EAAE,CAAC;IACb,0BAAU,GAAG,EAAE,CAAC;IAChB,wBAAQ,GAAG,IAAI,CAAC;IAChB,gCAAgB,GAAG,KAAK,CAAC;IAEzB,6BAAa,GAAG,KAAK,CAAC;IAiQtC,sBAAC;CA9QD,AA8QC,IAAA;AA9QY,0CAAe","file":"resolveio-server-app.js","sourcesContent":["import { Db, MongoClient, MongoClientOptions } from 'mongodb';\nimport { LocalLogManager } from './managers/local-log.manager';\nimport { MongoManager } from './managers/mongo.manager';\nimport { ResolveIOMainServer } from './server-app';\n\nexport class ResolveIOServer {\n\tprivate static _serverConfig = null;\n\tprivate static _clientRoutes = [];\n\tprivate static _mongoConnection: MongoClient = null;\n\tprivate static _mainDB: Db = null;\n\tprivate static _mainServer = null;\n\tprivate static _localLogManager = null;\n\tprivate static _mongoManager = null;\n\tprivate static _client = '';\n\tprivate static _clientDir = '';\n\tprivate static _sesMail = true;\n\tprivate static _standardProgram = false;\n\n\tprivate static _reconnecting = false;\n\n\tprivate static async connectMongo(): Promise<MongoClient> {\n\t\tconst mongoUrl = ResolveIOServer.getServerConfig()['MONGO_URL'];\n\t\tconst clientOptions = ResolveIOServer.resolveMongoClientOptions();\n\t\tconst client = await MongoClient.connect(mongoUrl, clientOptions);\n\t\tclient.on('close', ResolveIOServer.handleMongoDisconnect);\n\t\tclient.on('error', ResolveIOServer.handleMongoDisconnect);\n\t\tclient.on('connectionPoolCleared', ResolveIOServer.handleMongoDisconnect);\n\t\treturn client;\n\t}\n\n\tprivate static async handleMongoDisconnect(err): Promise<void> {\n\t\tconsole.error(new Date(), 'Mongo connection lost', err);\n\t\tif (ResolveIOServer._reconnecting) {\n\t\t\treturn;\n\t\t}\n\n\t\tResolveIOServer._reconnecting = true;\n\n\t\ttry {\n\t\t\tawait ResolveIOServer.reconnectMongo();\n\t\t}\n\t\tfinally {\n\t\t\tResolveIOServer._reconnecting = false;\n\t\t}\n\t}\n\n\tprivate static async reconnectMongo(): Promise<void> {\n\t\tlet attempt = 0;\n\n\t\twhile (true) {\n\t\t\ttry {\n\t\t\t\tconst client = await ResolveIOServer.connectMongo();\n\t\t\t\tResolveIOServer.setMongoConnection(client);\n\t\t\t\tResolveIOServer.setMainDB(client.db(ResolveIOServer.getServerConfig()['DATABASE']));\n\t\t\t\tconsole.log(new Date(), 'Mongo reconnected');\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcatch (err) {\n\t\t\t\tattempt++;\n\t\t\t\tconsole.error(new Date(), 'Mongo reconnect failed', err);\n\t\t\t\tawait ResolveIOServer.delay(Math.min(attempt * 1000, 10000));\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate static async delay(ms: number) {\n\t\t// eslint-disable-next-line no-restricted-syntax\n\t\treturn new Promise(resolve => setTimeout(resolve, ms));\n\t}\n\n\tprivate static resolveMongoClientOptions(): MongoClientOptions | undefined {\n\t\tconst config = ResolveIOServer.getServerConfig();\n\t\tconst options: MongoClientOptions = {};\n\n\t\tconst numericOptionKeys: Array<{ key: keyof MongoClientOptions; env: string; configKey: string }> = [\n\t\t\t{ key: 'maxPoolSize', env: 'MONGO_MAX_POOL_SIZE', configKey: 'MONGO_MAX_POOL_SIZE' },\n\t\t\t{ key: 'minPoolSize', env: 'MONGO_MIN_POOL_SIZE', configKey: 'MONGO_MIN_POOL_SIZE' },\n\t\t\t{ key: 'waitQueueTimeoutMS', env: 'MONGO_WAIT_QUEUE_TIMEOUT_MS', configKey: 'MONGO_WAIT_QUEUE_TIMEOUT_MS' },\n\t\t\t{ key: 'maxIdleTimeMS', env: 'MONGO_MAX_IDLE_TIME_MS', configKey: 'MONGO_MAX_IDLE_TIME_MS' }\n\t\t];\n\n\t\tfor (const option of numericOptionKeys) {\n\t\t\tconst value = ResolveIOServer.pickMongoOptionValue(option.env, option.configKey);\n\t\t\tif (typeof value === 'number') {\n\t\t\t\tObject.assign(options, { [option.key]: value });\n\t\t\t}\n\t\t}\n\n\t\tconst booleanOptionKeys: Array<{ key: keyof MongoClientOptions; env: string; configKey: string }> = [\n\t\t\t{ key: 'retryWrites', env: 'MONGO_RETRY_WRITES', configKey: 'MONGO_RETRY_WRITES' }\n\t\t];\n\n\t\tfor (const option of booleanOptionKeys) {\n\t\t\tconst value = ResolveIOServer.pickMongoBooleanOptionValue(option.env, option.configKey);\n\t\t\tif (typeof value === 'boolean') {\n\t\t\t\tObject.assign(options, { [option.key]: value });\n\t\t\t}\n\t\t}\n\n\t\tconst structuredOptions = config?.['MONGO_CLIENT_OPTIONS'];\n\t\tif (structuredOptions && typeof structuredOptions === 'object' && !Array.isArray(structuredOptions)) {\n\t\t\tObject.assign(options, structuredOptions);\n\t\t}\n\n\t\treturn Object.keys(options).length ? options : undefined;\n\t}\n\n\tprivate static pickMongoOptionValue(envKey: string, configKey: string): number | undefined {\n\t\tconst rawEnv = process.env[envKey];\n\t\tif (rawEnv && !Number.isNaN(Number(rawEnv))) {\n\t\t\tconst parsed = parseInt(rawEnv, 10);\n\t\t\treturn Number.isFinite(parsed) && parsed > 0 ? parsed : undefined;\n\t\t}\n\n\t\tconst config = ResolveIOServer.getServerConfig();\n\t\tconst configValue = config?.[configKey];\n\t\tif (typeof configValue === 'number' && Number.isFinite(configValue) && configValue > 0) {\n\t\t\treturn configValue;\n\t\t}\n\n\t\tif (typeof configValue === 'string' && configValue.trim().length && !Number.isNaN(Number(configValue))) {\n\t\t\tconst parsed = parseInt(configValue, 10);\n\t\t\treturn Number.isFinite(parsed) && parsed > 0 ? parsed : undefined;\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\tprivate static pickMongoBooleanOptionValue(envKey: string, configKey: string): boolean | undefined {\n\t\tconst rawEnv = process.env[envKey];\n\t\tif (typeof rawEnv === 'string' && rawEnv.length) {\n\t\t\tif (['true', '1', 'yes'].includes(rawEnv.toLowerCase())) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\telse if (['false', '0', 'no'].includes(rawEnv.toLowerCase())) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\tconst config = ResolveIOServer.getServerConfig();\n\t\tconst configValue = config?.[configKey];\n\t\tif (typeof configValue === 'boolean') {\n\t\t\treturn configValue;\n\t\t}\n\n\t\tif (typeof configValue === 'string' && configValue.length) {\n\t\t\tif (['true', '1', 'yes'].includes(configValue.toLowerCase())) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\telse if (['false', '0', 'no'].includes(configValue.toLowerCase())) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\tconstructor() {}\n\t\n\tpublic static async create(serverConfig, clientRoutes: string[], client: string, clientDir, sesMail = true, standardProgram = false) {\n\t\tconst resolveioServer = new ResolveIOServer();\n\t\tawait resolveioServer.initialize(serverConfig, clientRoutes, client, clientDir, sesMail, standardProgram);\n\t\treturn resolveioServer;\n\t}\n\n\tprivate async initialize(serverConfig, clientRoutes: string[], client: string, clientDir, sesMail = true, standardProgram = false) {\n\t\tResolveIOServer._serverConfig = serverConfig;\n\t\tResolveIOServer._clientRoutes = clientRoutes;\n\t\tResolveIOServer._client = client;\n\t\tResolveIOServer._clientDir = clientDir;\n\t\tResolveIOServer._sesMail = sesMail;\n\t\tResolveIOServer._standardProgram = standardProgram;\n\t\t\n\t\ttry {\n\t\t\tlet dbConnection = await ResolveIOServer.connectMongo();\n\t\t\tprocess.removeAllListeners('unhandledRejection');\n\n\t\t\tResolveIOServer.setMongoConnection(dbConnection);\n\t\t\tResolveIOServer.setMainDB(dbConnection.db(ResolveIOServer.getServerConfig()['DATABASE']));\n\n\t\t\t// dbConnection\n\t\t\t// .on('error', error => {\n\t\t\t// \tif (typeof error.message === 'string' && error.message.includes('ns does not exist')) {\n\t\t\t// \t\treturn;\n\t\t\t// \t}\n\t\t\t\t\t\n\t\t\t// \t// Otherwise log normally\n\t\t\t// \tthrow error;\n\t\t\t// })\n\t\t\t// .on('close', () => process.exit(1));\n\t\n\t\t\tlet LocalLogManager = (await import('./managers/local-log.manager')).LocalLogManager;\n\t\t\tlet localLogManager = LocalLogManager.create();\n\t\t\tResolveIOServer.setLocalLogManager(localLogManager);\n\n\t\t\tlet MongoManager = (await import('./managers/mongo.manager')).MongoManager;\n\t\t\tlet mongoManager = await MongoManager.create();\n\t\t\tResolveIOServer.setMongoManager(mongoManager);\n\t\t\t\n\t\t\tlet serverApp = (await import('./server-app')).ResolveIOMainServer;\n\t\t\tlet app = await serverApp.create();\n\t\t\tResolveIOServer.setMainServer(app);\n\t\t\t\n\t\t\treturn true;\n\t\t}\n\t\tcatch (err) {\n\t\t\terr.message = 'Error in ResolveIOServer (initialize): Mongo Client Connect And Run ResolveIO Server App Library - ' + err.message;\n\t\t\tconsole.error(err.message);\n\t\t\tprocess.exit(1);\n\t\t}\n\t}\n\n\tpublic static getClientName() {\n\t\treturn this._client;\n\t}\n\n\tpublic static getMainServer(): ResolveIOMainServer {\n\t\treturn ResolveIOServer._mainServer;\n\t}\n\n\tpublic static setMainServer(mainServer: ResolveIOMainServer) {\n\t\tResolveIOServer._mainServer = mainServer;\n\t}\n\n\tpublic static setMongoConnection(mongoConnection: MongoClient) {\n\t\tResolveIOServer._mongoConnection = mongoConnection;\n\t}\n\n\tpublic static getMongoConnection(): MongoClient {\n\t\treturn ResolveIOServer._mongoConnection;\n\t}\n\n\tpublic static getMainDB(): Db {\n\t\treturn ResolveIOServer._mainDB;\n\t}\n\n\tpublic static setMainDB(mainDB: Db) {\n\t\tResolveIOServer._mainDB = mainDB\n\t}\n\n\tpublic static getMongoManager(): MongoManager {\n\t\treturn ResolveIOServer._mongoManager;\n\t}\n\n\tpublic static setMongoManager(mongoManager: MongoManager) {\n\t\tResolveIOServer._mongoManager = mongoManager;\n\t}\n\n\tpublic static getLocalLogManager(): LocalLogManager {\n\t\treturn ResolveIOServer._localLogManager;\n\t}\n\n\tpublic static setLocalLogManager(localLogManager: LocalLogManager) {\n\t\tResolveIOServer._localLogManager = localLogManager;\n\t}\n\n\tpublic static getServerConfig() {\n\t\treturn ResolveIOServer._serverConfig;\n\t}\n\n\tpublic static getClientRoutes() {\n\t\treturn ResolveIOServer._clientRoutes;\n\t}\n\n\tpublic static getClientDir(): string {\n\t\treturn ResolveIOServer._clientDir;\n\t}\n\n\tpublic static getSESMail(): boolean {\n\t\treturn ResolveIOServer._sesMail;\n\t}\n\n\tpublic static getStandardProgram(): boolean {\n\t\treturn ResolveIOServer._standardProgram;\n\t}\n}\n"]}
package/server-app.d.ts CHANGED
@@ -28,6 +28,8 @@ export declare class ResolveIOMainServer {
28
28
  private _clientRoutes;
29
29
  private _workerDispatcherManager;
30
30
  private _workerServerManager;
31
+ private _httpServerClosePromise;
32
+ private _websocketServerClosePromise;
31
33
  private _serverStartTime;
32
34
  private _lastErrorMsg;
33
35
  private _debugMsgRecv;
@@ -41,6 +43,9 @@ export declare class ResolveIOMainServer {
41
43
  constructor();
42
44
  static create(): Promise<ResolveIOMainServer>;
43
45
  private initialize;
46
+ private shutdownNetworkServers;
47
+ private closeHttpServerGracefully;
48
+ private closeWebSocketServerGracefully;
44
49
  private startServerInstance;
45
50
  private safeShutdown;
46
51
  getIsWorkersEnabled(): boolean;
package/server-app.js CHANGED
@@ -107,6 +107,8 @@ var ResolveIOMainServer = /** @class */ (function () {
107
107
  this._rebootFlag = false;
108
108
  this.LOGGER = 'ERROR'; //ERROR / DEBUG
109
109
  this._clientRoutes = [];
110
+ this._httpServerClosePromise = null;
111
+ this._websocketServerClosePromise = null;
110
112
  this._lastErrorMsg = null;
111
113
  this._debugMsgRecv = 0;
112
114
  this._debugMsgQueue = 0;
@@ -291,45 +293,72 @@ var ResolveIOMainServer = /** @class */ (function () {
291
293
  }); });
292
294
  //PM2 wants to reboot/restart
293
295
  process.on('SIGINT', function () { return __awaiter(_this, void 0, void 0, function () {
296
+ var error_1;
294
297
  return __generator(this, function (_a) {
295
298
  switch (_a.label) {
296
299
  case 0:
297
300
  this._rebootFlag = true;
298
- if (this._serverHTTP) {
299
- this._serverHTTP.close();
300
- }
301
- return [4 /*yield*/, this.safeShutdown()];
301
+ _a.label = 1;
302
302
  case 1:
303
+ _a.trys.push([1, 3, , 4]);
304
+ return [4 /*yield*/, this.shutdownNetworkServers()];
305
+ case 2:
306
+ _a.sent();
307
+ return [3 /*break*/, 4];
308
+ case 3:
309
+ error_1 = _a.sent();
310
+ console.error(new Date(), 'Error closing network servers (SIGINT)', error_1);
311
+ return [3 /*break*/, 4];
312
+ case 4: return [4 /*yield*/, this.safeShutdown()];
313
+ case 5:
303
314
  _a.sent();
304
315
  return [2 /*return*/];
305
316
  }
306
317
  });
307
318
  }); });
308
319
  process.on('SIGTERM', function () { return __awaiter(_this, void 0, void 0, function () {
320
+ var error_2;
309
321
  return __generator(this, function (_a) {
310
322
  switch (_a.label) {
311
323
  case 0:
312
324
  this._rebootFlag = true;
313
- if (this._serverHTTP) {
314
- this._serverHTTP.close();
315
- }
316
- return [4 /*yield*/, this.safeShutdown()];
325
+ _a.label = 1;
317
326
  case 1:
327
+ _a.trys.push([1, 3, , 4]);
328
+ return [4 /*yield*/, this.shutdownNetworkServers()];
329
+ case 2:
330
+ _a.sent();
331
+ return [3 /*break*/, 4];
332
+ case 3:
333
+ error_2 = _a.sent();
334
+ console.error(new Date(), 'Error closing network servers (SIGTERM)', error_2);
335
+ return [3 /*break*/, 4];
336
+ case 4: return [4 /*yield*/, this.safeShutdown()];
337
+ case 5:
318
338
  _a.sent();
319
339
  return [2 /*return*/];
320
340
  }
321
341
  });
322
342
  }); });
323
343
  process.on('SIGQUIT', function () { return __awaiter(_this, void 0, void 0, function () {
344
+ var error_3;
324
345
  return __generator(this, function (_a) {
325
346
  switch (_a.label) {
326
347
  case 0:
327
348
  this._rebootFlag = true;
328
- if (this._serverHTTP) {
329
- this._serverHTTP.close();
330
- }
331
- return [4 /*yield*/, this.safeShutdown()];
349
+ _a.label = 1;
332
350
  case 1:
351
+ _a.trys.push([1, 3, , 4]);
352
+ return [4 /*yield*/, this.shutdownNetworkServers()];
353
+ case 2:
354
+ _a.sent();
355
+ return [3 /*break*/, 4];
356
+ case 3:
357
+ error_3 = _a.sent();
358
+ console.error(new Date(), 'Error closing network servers (SIGQUIT)', error_3);
359
+ return [3 /*break*/, 4];
360
+ case 4: return [4 /*yield*/, this.safeShutdown()];
361
+ case 5:
333
362
  _a.sent();
334
363
  return [2 /*return*/];
335
364
  }
@@ -371,6 +400,107 @@ var ResolveIOMainServer = /** @class */ (function () {
371
400
  });
372
401
  });
373
402
  };
403
+ ResolveIOMainServer.prototype.shutdownNetworkServers = function () {
404
+ return __awaiter(this, void 0, void 0, function () {
405
+ return __generator(this, function (_a) {
406
+ switch (_a.label) {
407
+ case 0: return [4 /*yield*/, this.closeWebSocketServerGracefully()];
408
+ case 1:
409
+ _a.sent();
410
+ return [4 /*yield*/, this.closeHttpServerGracefully()];
411
+ case 2:
412
+ _a.sent();
413
+ return [2 /*return*/];
414
+ }
415
+ });
416
+ });
417
+ };
418
+ ResolveIOMainServer.prototype.closeHttpServerGracefully = function () {
419
+ return __awaiter(this, void 0, void 0, function () {
420
+ var _this = this;
421
+ return __generator(this, function (_a) {
422
+ switch (_a.label) {
423
+ case 0:
424
+ if (!this._serverHTTP) {
425
+ return [2 /*return*/];
426
+ }
427
+ if (!(this._httpServerClosePromise !== null)) return [3 /*break*/, 2];
428
+ return [4 /*yield*/, this._httpServerClosePromise];
429
+ case 1:
430
+ _a.sent();
431
+ return [2 /*return*/];
432
+ case 2:
433
+ // eslint-disable-next-line no-restricted-syntax
434
+ this._httpServerClosePromise = new Promise(function (resolve) {
435
+ try {
436
+ _this._serverHTTP.close(function (error) {
437
+ if (error && error['code'] !== 'ERR_SERVER_NOT_RUNNING') {
438
+ console.error(new Date(), 'Error closing HTTP server before shutdown', error);
439
+ }
440
+ resolve();
441
+ });
442
+ }
443
+ catch (error) {
444
+ if (error && error['code'] !== 'ERR_SERVER_NOT_RUNNING') {
445
+ console.error(new Date(), 'Error closing HTTP server before shutdown', error);
446
+ }
447
+ resolve();
448
+ }
449
+ });
450
+ return [4 /*yield*/, this._httpServerClosePromise];
451
+ case 3:
452
+ _a.sent();
453
+ return [2 /*return*/];
454
+ }
455
+ });
456
+ });
457
+ };
458
+ ResolveIOMainServer.prototype.closeWebSocketServerGracefully = function () {
459
+ return __awaiter(this, void 0, void 0, function () {
460
+ var _this = this;
461
+ return __generator(this, function (_a) {
462
+ switch (_a.label) {
463
+ case 0:
464
+ if (!this._serverWSS) {
465
+ return [2 /*return*/];
466
+ }
467
+ if (!(this._websocketServerClosePromise !== null)) return [3 /*break*/, 2];
468
+ return [4 /*yield*/, this._websocketServerClosePromise];
469
+ case 1:
470
+ _a.sent();
471
+ return [2 /*return*/];
472
+ case 2:
473
+ this._serverWSS.clients.forEach(function (ws) {
474
+ try {
475
+ ws.close(1001, 'Server restarting');
476
+ }
477
+ catch (error) {
478
+ console.error(new Date(), 'Error closing WebSocket client before shutdown', error);
479
+ }
480
+ });
481
+ // eslint-disable-next-line no-restricted-syntax
482
+ this._websocketServerClosePromise = new Promise(function (resolve) {
483
+ try {
484
+ _this._serverWSS.close(function (error) {
485
+ if (error) {
486
+ console.error(new Date(), 'Error closing WebSocket server before shutdown', error);
487
+ }
488
+ resolve();
489
+ });
490
+ }
491
+ catch (error) {
492
+ console.error(new Date(), 'Error closing WebSocket server before shutdown', error);
493
+ resolve();
494
+ }
495
+ });
496
+ return [4 /*yield*/, this._websocketServerClosePromise];
497
+ case 3:
498
+ _a.sent();
499
+ return [2 /*return*/];
500
+ }
501
+ });
502
+ });
503
+ };
374
504
  ResolveIOMainServer.prototype.startServerInstance = function () {
375
505
  // Start express app
376
506
  this._app = express();