@natlibfi/melinda-rest-api-commons 2.3.1-alpha.6 → 2.3.1-alpha.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constants.js +4 -2
- package/dist/constants.js.map +1 -1
- package/dist/mongoLog.js +17 -8
- package/dist/mongoLog.js.map +1 -1
- package/package.json +1 -1
package/dist/constants.js
CHANGED
|
@@ -11,7 +11,7 @@ exports.QUEUE_ITEM_STATE = exports.OPERATIONS = exports.LOG_ITEM_TYPE = exports.
|
|
|
11
11
|
*
|
|
12
12
|
* Shared modules for microservices of Melinda rest api batch import system
|
|
13
13
|
*
|
|
14
|
-
* Copyright (C) 2020-
|
|
14
|
+
* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
|
|
15
15
|
*
|
|
16
16
|
* This file is part of melinda-rest-api-commons
|
|
17
17
|
*
|
|
@@ -68,7 +68,9 @@ const OPERATIONS = {
|
|
|
68
68
|
UPDATE: 'UPDATE'
|
|
69
69
|
};
|
|
70
70
|
exports.OPERATIONS = OPERATIONS;
|
|
71
|
-
const CHUNK_SIZE = 100;
|
|
71
|
+
const CHUNK_SIZE = 100; // We could configure here whether a logItemType is for a several records of a single record
|
|
72
|
+
// ie. whether is has bulkSequence or bulkSequenceStart & bulkSequenceEnd
|
|
73
|
+
|
|
72
74
|
exports.CHUNK_SIZE = CHUNK_SIZE;
|
|
73
75
|
const LOG_ITEM_TYPE = {
|
|
74
76
|
MERGE_LOG: 'MERGE_LOG',
|
package/dist/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","names":["QUEUE_ITEM_STATE","VALIDATOR","PENDING_QUEUING","PENDING_VALIDATION","QUEUING_IN_PROGRESS","UPLOADING","VALIDATING","WAITING_FOR_RECORDS","IMPORTER","IMPORTING","IN_PROCESS","IN_QUEUE","DONE","ERROR","ABORT","IMPORT_JOB_STATE","EMPTY","QUEUING","PROCESSING","OPERATIONS","CREATE","UPDATE","CHUNK_SIZE","LOG_ITEM_TYPE","MERGE_LOG","MATCH_LOG","SPLITTER_LOG","CONVERSION_FORMATS","MARCXML","ISO2709","JSON","ALEPHSEQ"],"sources":["../src/constants.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Shared modules for microservices of Melinda rest api batch import system\n*\n* Copyright (C) 2020-
|
|
1
|
+
{"version":3,"file":"constants.js","names":["QUEUE_ITEM_STATE","VALIDATOR","PENDING_QUEUING","PENDING_VALIDATION","QUEUING_IN_PROGRESS","UPLOADING","VALIDATING","WAITING_FOR_RECORDS","IMPORTER","IMPORTING","IN_PROCESS","IN_QUEUE","DONE","ERROR","ABORT","IMPORT_JOB_STATE","EMPTY","QUEUING","PROCESSING","OPERATIONS","CREATE","UPDATE","CHUNK_SIZE","LOG_ITEM_TYPE","MERGE_LOG","MATCH_LOG","SPLITTER_LOG","CONVERSION_FORMATS","MARCXML","ISO2709","JSON","ALEPHSEQ"],"sources":["../src/constants.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Shared modules for microservices of Melinda rest api batch import system\n*\n* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-rest-api-commons\n*\n* melinda-rest-api-commons program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Affero General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-rest-api-commons is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Affero General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\n// QueueItemState flows: see README.md\n\nexport const QUEUE_ITEM_STATE = {\n VALIDATOR: {\n PENDING_QUEUING: 'PENDING_QUEUING',\n PENDING_VALIDATION: 'PENDING_VALIDATION',\n QUEUING_IN_PROGRESS: 'QUEUING_IN_PROGRESS',\n UPLOADING: 'UPLOADING',\n VALIDATING: 'VALIDATING',\n WAITING_FOR_RECORDS: 'WAITING_FOR_RECORDS'\n },\n IMPORTER: {\n IMPORTING: 'IMPORTING',\n IN_PROCESS: 'IN_PROCESS',\n IN_QUEUE: 'IN_QUEUE'\n },\n DONE: 'DONE',\n ERROR: 'ERROR',\n ABORT: 'ABORT'\n};\n\nexport const IMPORT_JOB_STATE = {\n EMPTY: 'EMPTY',\n QUEUING: 'QUEUING',\n IN_QUEUE: 'IN_QUEUE',\n IMPORTING: 'IMPORTING',\n PROCESSING: 'PROCESSING',\n DONE: 'DONE',\n ERROR: 'ERROR',\n ABORT: 'ABORT'\n};\n\nexport const OPERATIONS = {\n CREATE: 'CREATE',\n UPDATE: 'UPDATE'\n};\n\nexport const CHUNK_SIZE = 100;\n\n// We could configure here whether a logItemType is for a several records of a single record\n// ie. whether is has bulkSequence or bulkSequenceStart & bulkSequenceEnd\nexport const LOG_ITEM_TYPE = {\n MERGE_LOG: 'MERGE_LOG',\n MATCH_LOG: 'MATCH_LOG',\n SPLITTER_LOG: 'SPLITTER_LOG'\n};\n\nexport const CONVERSION_FORMATS = {\n MARCXML: 'MARCXML',\n ISO2709: 'ISO2709',\n JSON: 'JSON',\n ALEPHSEQ: 'ALEPHSEQ'\n};\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AAEO,MAAMA,gBAAgB,GAAG;EAC9BC,SAAS,EAAE;IACTC,eAAe,EAAE,iBADR;IAETC,kBAAkB,EAAE,oBAFX;IAGTC,mBAAmB,EAAE,qBAHZ;IAITC,SAAS,EAAE,WAJF;IAKTC,UAAU,EAAE,YALH;IAMTC,mBAAmB,EAAE;EANZ,CADmB;EAS9BC,QAAQ,EAAE;IACRC,SAAS,EAAE,WADH;IAERC,UAAU,EAAE,YAFJ;IAGRC,QAAQ,EAAE;EAHF,CAToB;EAc9BC,IAAI,EAAE,MAdwB;EAe9BC,KAAK,EAAE,OAfuB;EAgB9BC,KAAK,EAAE;AAhBuB,CAAzB;;AAmBA,MAAMC,gBAAgB,GAAG;EAC9BC,KAAK,EAAE,OADuB;EAE9BC,OAAO,EAAE,SAFqB;EAG9BN,QAAQ,EAAE,UAHoB;EAI9BF,SAAS,EAAE,WAJmB;EAK9BS,UAAU,EAAE,YALkB;EAM9BN,IAAI,EAAE,MANwB;EAO9BC,KAAK,EAAE,OAPuB;EAQ9BC,KAAK,EAAE;AARuB,CAAzB;;AAWA,MAAMK,UAAU,GAAG;EACxBC,MAAM,EAAE,QADgB;EAExBC,MAAM,EAAE;AAFgB,CAAnB;;AAKA,MAAMC,UAAU,GAAG,GAAnB,C,CAEP;AACA;;;AACO,MAAMC,aAAa,GAAG;EAC3BC,SAAS,EAAE,WADgB;EAE3BC,SAAS,EAAE,WAFgB;EAG3BC,YAAY,EAAE;AAHa,CAAtB;;AAMA,MAAMC,kBAAkB,GAAG;EAChCC,OAAO,EAAE,SADuB;EAEhCC,OAAO,EAAE,SAFuB;EAGhCC,IAAI,EAAE,MAH0B;EAIhCC,QAAQ,EAAE;AAJsB,CAA3B"}
|
package/dist/mongoLog.js
CHANGED
|
@@ -99,6 +99,7 @@ async function _default(MONGO_URI) {
|
|
|
99
99
|
|
|
100
100
|
async function query(params) {
|
|
101
101
|
logger.debug(`Query params: ${JSON.stringify(params)}`);
|
|
102
|
+
checkLogItemType(params.logItemType, false, false);
|
|
102
103
|
const {
|
|
103
104
|
limit = 5,
|
|
104
105
|
skip = 0,
|
|
@@ -126,7 +127,7 @@ async function _default(MONGO_URI) {
|
|
|
126
127
|
}
|
|
127
128
|
|
|
128
129
|
async function getListOfLogs(logItemType = 'MERGE_LOG') {
|
|
129
|
-
checkLogItemType(logItemType, false);
|
|
130
|
+
checkLogItemType(logItemType, false, false);
|
|
130
131
|
const result = await db.collection(collection) // eslint-disable-line functional/immutable-data
|
|
131
132
|
.distinct('correlationId', {
|
|
132
133
|
logItemType
|
|
@@ -190,18 +191,26 @@ async function _default(MONGO_URI) {
|
|
|
190
191
|
}
|
|
191
192
|
}
|
|
192
193
|
|
|
193
|
-
function checkLogItemType(logItemType, errorUnknown = false) {
|
|
194
|
-
|
|
194
|
+
function checkLogItemType(logItemType, errorUnknown = false, errorNotExisting = false) {
|
|
195
|
+
if (logItemType) {
|
|
196
|
+
const typeInLogItemTypes = Object.values(_constants.LOG_ITEM_TYPE).indexOf(logItemType) > -1;
|
|
195
197
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
+
if (typeInLogItemTypes) {
|
|
199
|
+
return logger.debug(`Valid logItemType: ${logItemType}`);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
if (errorUnknown) {
|
|
203
|
+
throw new _melindaCommons.Error(_httpStatus.default.INTERNAL_SERVER_ERROR, `Unknown logItemType: ${logItemType}`);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
return logger.debug(`WARN: We have unknown logType: ${logItemType}`);
|
|
198
207
|
}
|
|
199
208
|
|
|
200
|
-
if (
|
|
201
|
-
throw new _melindaCommons.Error(_httpStatus.default.INTERNAL_SERVER_ERROR, `
|
|
209
|
+
if (errorNotExisting) {
|
|
210
|
+
throw new _melindaCommons.Error(_httpStatus.default.INTERNAL_SERVER_ERROR, `No logItemType: ${logItemType}`);
|
|
202
211
|
}
|
|
203
212
|
|
|
204
|
-
return logger.debug(`
|
|
213
|
+
return logger.debug(`No logItemType: ${logItemType}`);
|
|
205
214
|
}
|
|
206
215
|
}
|
|
207
216
|
//# sourceMappingURL=mongoLog.js.map
|
package/dist/mongoLog.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mongoLog.js","names":["MONGO_URI","logger","createLogger","client","MongoClient","connect","useNewUrlParser","useUnifiedTopology","db","collection","addLogItem","query","queryById","getListOfLogs","protect","remove","logItem","time","moment","toDate","newLogItem","creationTime","protected","checkLogItemType","logItemType","result","insertOne","acknowledged","blobSequence","blobSequenceStart","blobSequenceEnd","itemString","info","correlationId","ApiError","httpStatus","INTERNAL_SERVER_ERROR","error","logError","params","debug","JSON","stringify","limit","skip","rest","find","sort","parseInt","toArray","length","correlationIdString","distinct","status","OK","NOT_FOUND","payload","cleanCorrelationId","sanitize","cleanBlobSequence","filter","updateMany","$set","modificationTime","$not","modifiedCount","err","message","force","clean","$ne","deleteMany","deletedCount","errorUnknown","typeInLogItemTypes","Object","values","LOG_ITEM_TYPE","indexOf"],"sources":["../src/mongoLog.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Shared modules for microservices of Melinda rest api batch import system\n*\n* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-rest-api-commons\n*\n* melinda-rest-api-commons program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Affero General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-rest-api-commons is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Affero General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\nimport {MongoClient} from 'mongodb';\nimport {createLogger} from '@natlibfi/melinda-backend-commons';\nimport {Error as ApiError} from '@natlibfi/melinda-commons';\nimport {logError} from './utils.js';\nimport moment from 'moment';\nimport httpStatus from 'http-status';\nimport sanitize from 'mongo-sanitize';\nimport {LOG_ITEM_TYPE} from './constants';\n\nexport default async function (MONGO_URI) {\n const logger = createLogger();\n\n // Connect to mongo (MONGO)\n const client = await MongoClient.connect(MONGO_URI, {useNewUrlParser: true, useUnifiedTopology: true});\n const db = client.db('rest-api');\n const collection = 'logs';\n return {addLogItem, query, queryById, getListOfLogs, protect, remove};\n\n async function addLogItem(logItem) {\n const time = moment().toDate();\n const newLogItem = {\n ...logItem,\n creationTime: time,\n protected: false\n };\n try {\n checkLogItemType(logItem.logItemType, false);\n const result = await db.collection(collection).insertOne(newLogItem);\n if (result.acknowledged) {\n const {blobSequence, blobSequenceStart, blobSequenceEnd} = logItem;\n const itemString = blobSequenceStart && blobSequenceEnd ? `${blobSequenceStart} - ${blobSequenceEnd}` : `${blobSequence}`;\n logger.info(`*** New ${logItem.logItemType} added for ${logItem.correlationId}, blobSequence(s): ${itemString}. ***`);\n return;\n }\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR);\n } catch (error) {\n logError(error);\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR);\n }\n }\n\n async function query(params) {\n logger.debug(`Query params: ${JSON.stringify(params)}`);\n const {limit = 5, skip = 0, ...rest} = params;\n const result = await db.collection(collection) // eslint-disable-line functional/immutable-data\n .find(rest)\n .sort({blobSequence: 1})\n .skip(parseInt(skip, 10))\n .limit(parseInt(limit, 10))\n .toArray();\n logger.debug(`Query result: ${result}`);\n logger.debug(`Query result: ${result.length > 0 ? `Found ${result.length} log items! (skip: ${skip} limit: ${limit})` : 'Not found!'}`);\n return result;\n }\n\n async function queryById(correlationIdString, skip = 0, limit = 1) {\n logger.debug(`QueryById: ${correlationIdString}`);\n const result = await db.collection(collection) // eslint-disable-line functional/immutable-data\n .find({correlationId: correlationIdString})\n .sort({blobSequence: 1})\n .skip(parseInt(skip, 10))\n .limit(parseInt(limit, 10))\n .toArray();\n logger.debug(`Query result: ${result.length > 0 ? `Found ${result.length} log items!` : 'Not found!'}`);\n return result;\n }\n\n async function getListOfLogs(logItemType = 'MERGE_LOG') {\n checkLogItemType(logItemType, false);\n const result = await db.collection(collection) // eslint-disable-line functional/immutable-data\n .distinct('correlationId', {logItemType});\n logger.debug(`Query result: ${result.length > 0 ? `Found ${result.length} log items!` : 'Not found!'}`);\n return {status: result.length > 0 ? httpStatus.OK : httpStatus.NOT_FOUND, payload: result.length > 0 ? result : 'No logs found'};\n }\n\n async function protect(correlationId, blobSequence) {\n logger.info(`Protecting in Mongo (${collection}) correlationId: ${correlationId}, blobSequence: ${blobSequence}`);\n const cleanCorrelationId = sanitize(correlationId);\n const cleanBlobSequence = sanitize(blobSequence);\n const filter = blobSequence ? {correlationId: cleanCorrelationId, blobSequence: cleanBlobSequence} : {correlationId: cleanCorrelationId};\n\n try {\n const result = await db.collection(collection).updateMany(\n filter,\n {\n $set: {\n modificationTime: moment().toDate(),\n protect: {$not: '$protect'}\n }\n }\n );\n return {status: result.modifiedCount > 0 ? httpStatus.OK : httpStatus.NOT_FOUND, payload: result.modifiedCount > 0 ? result : 'No logs found'};\n } catch (err) {\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, err.message);\n }\n }\n\n async function remove(correlationId, force = false) {\n logger.info(`Removing from Mongo (${collection}) correlationId: ${correlationId}`);\n const clean = sanitize(correlationId);\n const filter = force ? {correlationId: clean} : {correlationId: clean, protected: {$ne: true}};\n\n try {\n const result = await db.collection(collection).deleteMany(filter);\n return {status: result.deletedCount > 0 ? httpStatus.OK : httpStatus.NOT_FOUND, payload: result.deletedCount > 0 ? result : 'No logs found'};\n } catch (err) {\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, err.message);\n }\n }\n\n function checkLogItemType(logItemType, errorUnknown = false) {\n const typeInLogItemTypes = Object.values(LOG_ITEM_TYPE).indexOf(logItemType) > -1;\n if (typeInLogItemTypes) {\n return logger.debug(`Valid logItemType: ${logItemType}`);\n }\n if (errorUnknown) {\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, `Unknown logItemType: ${logItemType}`);\n }\n return logger.debug(`WARN: We have unknown logType: ${logItemType}`);\n }\n}\n"],"mapp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C,KAAhB;MAAuB/C,SAAS,EAAE;QAACgD,GAAG,EAAE;MAAN;IAAlC,CAAhD;;IAEA,IAAI;MACF,MAAM7C,MAAM,GAAG,MAAMjB,EAAE,CAACC,UAAH,CAAcA,UAAd,EAA0B8D,UAA1B,CAAqCX,MAArC,CAArB;MACA,OAAO;QAACP,MAAM,EAAE5B,MAAM,CAAC+C,YAAP,GAAsB,CAAtB,GAA0BrC,mBAAA,CAAWmB,EAArC,GAA0CnB,mBAAA,CAAWoB,SAA9D;QAAyEC,OAAO,EAAE/B,MAAM,CAAC+C,YAAP,GAAsB,CAAtB,GAA0B/C,MAA1B,GAAmC;MAArH,CAAP;IACD,CAHD,CAGE,OAAOyC,GAAP,EAAY;MACZ,MAAM,IAAIhC,qBAAJ,CAAaC,mBAAA,CAAWC,qBAAxB,EAA+C8B,GAAG,CAACC,OAAnD,CAAN;IACD;EACF;;EAED,SAAS5C,gBAAT,CAA0BC,WAA1B,EAAuCiD,YAAY,GAAG,KAAtD,EAA6D;IAC3D,MAAMC,kBAAkB,GAAGC,MAAM,CAACC,MAAP,CAAcC,wBAAd,EAA6BC,OAA7B,CAAqCtD,WAArC,IAAoD,CAAC,CAAhF;;IACA,IAAIkD,kBAAJ,EAAwB;MACtB,OAAOzE,MAAM,CAACuC,KAAP,CAAc,sBAAqBhB,WAAY,EAA/C,CAAP;IACD;;IACD,IAAIiD,YAAJ,EAAkB;MAChB,MAAM,IAAIvC,qBAAJ,CAAaC,mBAAA,CAAWC,qBAAxB,EAAgD,wBAAuBZ,WAAY,EAAnF,CAAN;IACD;;IACD,OAAOvB,MAAM,CAACuC,KAAP,CAAc,kCAAiChB,WAAY,EAA3D,CAAP;EACD;AACF"}
|
|
1
|
+
{"version":3,"file":"mongoLog.js","names":["MONGO_URI","logger","createLogger","client","MongoClient","connect","useNewUrlParser","useUnifiedTopology","db","collection","addLogItem","query","queryById","getListOfLogs","protect","remove","logItem","time","moment","toDate","newLogItem","creationTime","protected","checkLogItemType","logItemType","result","insertOne","acknowledged","blobSequence","blobSequenceStart","blobSequenceEnd","itemString","info","correlationId","ApiError","httpStatus","INTERNAL_SERVER_ERROR","error","logError","params","debug","JSON","stringify","limit","skip","rest","find","sort","parseInt","toArray","length","correlationIdString","distinct","status","OK","NOT_FOUND","payload","cleanCorrelationId","sanitize","cleanBlobSequence","filter","updateMany","$set","modificationTime","$not","modifiedCount","err","message","force","clean","$ne","deleteMany","deletedCount","errorUnknown","errorNotExisting","typeInLogItemTypes","Object","values","LOG_ITEM_TYPE","indexOf"],"sources":["../src/mongoLog.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Shared modules for microservices of Melinda rest api batch import system\n*\n* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-rest-api-commons\n*\n* melinda-rest-api-commons program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Affero General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-rest-api-commons is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Affero General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\nimport {MongoClient} from 'mongodb';\nimport {createLogger} from '@natlibfi/melinda-backend-commons';\nimport {Error as ApiError} from '@natlibfi/melinda-commons';\nimport {logError} from './utils.js';\nimport moment from 'moment';\nimport httpStatus from 'http-status';\nimport sanitize from 'mongo-sanitize';\nimport {LOG_ITEM_TYPE} from './constants';\n\nexport default async function (MONGO_URI) {\n const logger = createLogger();\n\n // Connect to mongo (MONGO)\n const client = await MongoClient.connect(MONGO_URI, {useNewUrlParser: true, useUnifiedTopology: true});\n const db = client.db('rest-api');\n const collection = 'logs';\n return {addLogItem, query, queryById, getListOfLogs, protect, remove};\n\n async function addLogItem(logItem) {\n const time = moment().toDate();\n const newLogItem = {\n ...logItem,\n creationTime: time,\n protected: false\n };\n try {\n checkLogItemType(logItem.logItemType, false);\n const result = await db.collection(collection).insertOne(newLogItem);\n if (result.acknowledged) {\n const {blobSequence, blobSequenceStart, blobSequenceEnd} = logItem;\n const itemString = blobSequenceStart && blobSequenceEnd ? `${blobSequenceStart} - ${blobSequenceEnd}` : `${blobSequence}`;\n logger.info(`*** New ${logItem.logItemType} added for ${logItem.correlationId}, blobSequence(s): ${itemString}. ***`);\n return;\n }\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR);\n } catch (error) {\n logError(error);\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR);\n }\n }\n\n async function query(params) {\n logger.debug(`Query params: ${JSON.stringify(params)}`);\n checkLogItemType(params.logItemType, false, false);\n const {limit = 5, skip = 0, ...rest} = params;\n const result = await db.collection(collection) // eslint-disable-line functional/immutable-data\n .find(rest)\n .sort({blobSequence: 1})\n .skip(parseInt(skip, 10))\n .limit(parseInt(limit, 10))\n .toArray();\n logger.debug(`Query result: ${result}`);\n logger.debug(`Query result: ${result.length > 0 ? `Found ${result.length} log items! (skip: ${skip} limit: ${limit})` : 'Not found!'}`);\n return result;\n }\n\n async function queryById(correlationIdString, skip = 0, limit = 1) {\n logger.debug(`QueryById: ${correlationIdString}`);\n const result = await db.collection(collection) // eslint-disable-line functional/immutable-data\n .find({correlationId: correlationIdString})\n .sort({blobSequence: 1})\n .skip(parseInt(skip, 10))\n .limit(parseInt(limit, 10))\n .toArray();\n logger.debug(`Query result: ${result.length > 0 ? `Found ${result.length} log items!` : 'Not found!'}`);\n return result;\n }\n\n async function getListOfLogs(logItemType = 'MERGE_LOG') {\n checkLogItemType(logItemType, false, false);\n const result = await db.collection(collection) // eslint-disable-line functional/immutable-data\n .distinct('correlationId', {logItemType});\n logger.debug(`Query result: ${result.length > 0 ? `Found ${result.length} log items!` : 'Not found!'}`);\n return {status: result.length > 0 ? httpStatus.OK : httpStatus.NOT_FOUND, payload: result.length > 0 ? result : 'No logs found'};\n }\n\n async function protect(correlationId, blobSequence) {\n logger.info(`Protecting in Mongo (${collection}) correlationId: ${correlationId}, blobSequence: ${blobSequence}`);\n const cleanCorrelationId = sanitize(correlationId);\n const cleanBlobSequence = sanitize(blobSequence);\n const filter = blobSequence ? {correlationId: cleanCorrelationId, blobSequence: cleanBlobSequence} : {correlationId: cleanCorrelationId};\n\n try {\n const result = await db.collection(collection).updateMany(\n filter,\n {\n $set: {\n modificationTime: moment().toDate(),\n protect: {$not: '$protect'}\n }\n }\n );\n return {status: result.modifiedCount > 0 ? httpStatus.OK : httpStatus.NOT_FOUND, payload: result.modifiedCount > 0 ? result : 'No logs found'};\n } catch (err) {\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, err.message);\n }\n }\n\n async function remove(correlationId, force = false) {\n logger.info(`Removing from Mongo (${collection}) correlationId: ${correlationId}`);\n const clean = sanitize(correlationId);\n const filter = force ? {correlationId: clean} : {correlationId: clean, protected: {$ne: true}};\n\n try {\n const result = await db.collection(collection).deleteMany(filter);\n return {status: result.deletedCount > 0 ? httpStatus.OK : httpStatus.NOT_FOUND, payload: result.deletedCount > 0 ? result : 'No logs found'};\n } catch (err) {\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, err.message);\n }\n }\n\n function checkLogItemType(logItemType, errorUnknown = false, errorNotExisting = false) {\n\n if (logItemType) {\n const typeInLogItemTypes = Object.values(LOG_ITEM_TYPE).indexOf(logItemType) > -1;\n if (typeInLogItemTypes) {\n return logger.debug(`Valid logItemType: ${logItemType}`);\n }\n if (errorUnknown) {\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, `Unknown logItemType: ${logItemType}`);\n }\n return logger.debug(`WARN: We have unknown logType: ${logItemType}`);\n }\n\n if (errorNotExisting) {\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, `No logItemType: ${logItemType}`);\n }\n return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