@natlibfi/melinda-rest-api-commons 4.0.12-alpha.4 → 4.0.12-alpha.5

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/mongoLog.js CHANGED
@@ -98,13 +98,8 @@ async function _default(MONGO_URI) {
98
98
  } = params;
99
99
  logger.debug(`Actual query params: ${JSON.stringify(rest)}`);
100
100
  const result = await db.collection(collection) // eslint-disable-line functional/immutable-data
101
- .find(rest)
102
- // DEVELOP: we'd like to sort so, that correlationIds would be sorted latest first, but when corralationId is
103
- // same sorting would be based on blobSequence
104
- .sort({
105
- correlationId: 1
106
- }, {
107
- blobSequence: 1
101
+ .find(rest).sort({
102
+ creationTime: 1
108
103
  }).skip(parseInt(skip, 10)).limit(parseInt(limit, 10)).toArray();
109
104
  logger.debug(`Query result: ${result}`);
110
105
  logger.debug(`Query result: ${result.length > 0 ? `Found ${result.length} log items! (skip: ${skip} limit: ${limit})` : 'Not found!'}`);
@@ -159,7 +154,6 @@ async function _default(MONGO_URI) {
159
154
  'creationTime': {
160
155
  '$first': '$creationTime'
161
156
  },
162
- // We don't currently have cataloger in logs, this will always be null
163
157
  'cataloger': {
164
158
  '$first': '$cataloger'
165
159
  },
@@ -1 +1 @@
1
- {"version":3,"file":"mongoLog.js","names":["_mongodb","require","_melindaBackendCommons","_melindaCommons","_utils","_moment","_interopRequireDefault","_httpStatus","_mongoSanitize","_constants","obj","__esModule","default","_default","MONGO_URI","logger","createLogger","client","MongoClient","connect","useNewUrlParser","useUnifiedTopology","db","collection","addLogItem","query","queryById","getListOfLogs","getExpandedListOfLogs","protect","remove","removeBySequences","logItem","time","moment","toDate","newLogItem","creationTime","protected","checkLogItemType","logItemType","result","insertOne","acknowledged","blobSequence","blobSequenceStart","blobSequenceEnd","itemString","info","correlationId","ApiError","httpStatus","INTERNAL_SERVER_ERROR","error","errorMessage","payload","message","logError","params","debug","JSON","stringify","limit","skip","rest","find","sort","parseInt","toArray","length","correlationIdString","distinct","status","OK","NOT_FOUND","pipeline","aggregate","fixedResult","map","logListing","_id","cataloger","logCount","silly","cleanCorrelationId","sanitize","cleanBlobSequence","filter","updateMany","$set","modificationTime","$not","modifiedCount","force","clean","$ne","deleteMany","deletedCount","sequences","cleanSequences","sequence","Number","isInteger","$in","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, getExpandedListOfLogs, protect, remove, removeBySequences};\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 const errorMessage = error.payload || error.message || '';\n logError(error);\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, `Mongo errored: ${errorMessage}`);\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 logger.debug(`Actual query params: ${JSON.stringify(rest)}`);\n const result = await db.collection(collection) // eslint-disable-line functional/immutable-data\n .find(rest)\n // DEVELOP: we'd like to sort so, that correlationIds would be sorted latest first, but when corralationId is\n // same sorting would be based on blobSequence\n .sort({correlationId: 1}, {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 getExpandedListOfLogs(logItemType = 'MERGE_LOG') {\n checkLogItemType(logItemType, false, false);\n logger.debug(`Getting expanded list of logs`);\n const pipeline = [\n // currently return only MERGE_LOG and MATCH_LOG\n {'$match': {'logItemType': {'$in': ['MERGE_LOG', 'MATCH_LOG']}}},\n {'$sort':\n {'correlationId': 1, 'logItemType': 1, 'creationTime': 1}},\n {'$group':\n {'_id': {'correlationId': '$correlationId', 'logItemType': '$logItemType'},\n 'creationTime': {'$first': '$creationTime'},\n // We don't currently have cataloger in logs, this will always be null\n 'cataloger': {'$first': '$cataloger'},\n 'logCount': {'$sum': 1}}}\n ];\n\n const result = await db.collection(collection) // eslint-disable-line functional/immutable-data\n .aggregate(pipeline)\n .toArray();\n\n const fixedResult = result.map((logListing) => {\n const {correlationId, logItemType} = logListing._id;\n const {cataloger, creationTime, logCount} = logListing;\n return {correlationId, logItemType, cataloger, creationTime, logCount};\n });\n\n logger.silly(`Query result: ${JSON.stringify(result)}`);\n logger.silly(`Query result: ${JSON.stringify(fixedResult)}`);\n\n logger.debug(`Query result: ${fixedResult.length > 0 ? `Found ${fixedResult.length} log items!` : 'Not found!'}`);\n return {status: fixedResult.length > 0 ? httpStatus.OK : httpStatus.NOT_FOUND, payload: fixedResult.length > 0 ? fixedResult : '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: parseInt(cleanBlobSequence, 10)} : {correlationId: cleanCorrelationId};\n\n try {\n const result = await db.collection(collection).updateMany(\n filter,\n [\n {\n $set: {\n modificationTime: moment().toDate(),\n protected: {$not: '$protected'}\n }\n }\n ]\n );\n return {status: result.modifiedCount > 0 ? httpStatus.OK : httpStatus.NOT_FOUND, payload: result.modifiedCount > 0 ? result : 'No logs found'};\n } catch (error) {\n const errorMessage = error.payload || error.message || '';\n logError(error);\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, `Mongo errored: ${errorMessage}`);\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 (error) {\n const errorMessage = error.payload || error.message || '';\n logError(error);\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, `Mongo errored: ${errorMessage}`);\n }\n }\n\n async function removeBySequences(correlationId, sequences = [], force = false) {\n logger.info(`Removing from Mongo (${collection}) correlationId: ${correlationId}, sequences: ${sequences.length}`);\n const clean = sanitize(correlationId);\n // blobSequences are integers that start from 1\n // we accept also strings that are convertilble to integers greated than 0\n const cleanSequences = sequences.filter(sequence => Number.isInteger(Number(sequence)) && sequence > 0);\n\n if (sequences.length !== cleanSequences.length) {\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, `Invalid sequences in removeBySequences. Sequences should be positive integers`);\n }\n\n const filter = force ? {correlationId: clean, blobSequence: {$in: cleanSequences}} : {correlationId: clean, blobSequence: {$in: sequences}, 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 (error) {\n const errorMessage = error.payload || error.message || '';\n logError(error);\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, `Mongo errored: ${errorMessage}`);\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 logger.debug(`No logItemType: ${logItemType}`);\n }\n}\n"],"mappings":";;;;;;AA4BA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,sBAAA,GAAAD,OAAA;AACA,IAAAE,eAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAC,sBAAA,CAAAL,OAAA;AACA,IAAAM,WAAA,GAAAD,sBAAA,CAAAL,OAAA;AACA,IAAAO,cAAA,GAAAF,sBAAA,CAAAL,OAAA;AACA,IAAAQ,UAAA,GAAAR,OAAA;AAA0C,SAAAK,uBAAAI,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAnC1C;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;;AAWe,eAAAG,SAAgBC,SAAS,EAAE;EACxC,MAAMC,MAAM,GAAG,IAAAC,mCAAY,EAAC,CAAC;;EAE7B;EACA,MAAMC,MAAM,GAAG,MAAMC,oBAAW,CAACC,OAAO,CAACL,SAAS,EAAE;IAACM,eAAe,EAAE,IAAI;IAAEC,kBAAkB,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AM,GAAG;MAAe,CAAC;IAC9I,CAAC,CAAC,OAAOY,KAAK,EAAE;MACd,MAAMC,YAAY,GAAGD,KAAK,CAACE,OAAO,IAAIF,KAAK,CAACG,OAAO,IAAI,EAAE;MACzD,IAAAC,eAAQ,EAACJ,KAAK,CAAC;MACf,MAAM,IAAIH,qBAAQ,CAACC,mBAAU,CAACC,qBAAqB,EAAG,kBAAiBE,YAAa,EAAC,CAAC;IACxF;EACF;EAEA,SAASf,gBAAgBA,CAACC,WAAW,EAAEgE,YAAY,GAAG,KAAK,EAAEC,gBAAgB,GAAG,KAAK,EAAE;IAErF,IAAIjE,WAAW,EAAE;MACf,MAAMkE,kBAAkB,GAAGC,MAAM,CAACC,MAAM,CAACC,wBAAa,CAAC,CAACC,OAAO,CAACtE,WAAW,CAAC,GAAG,CAAC,CAAC;MACjF,IAAIkE,kBAAkB,EAAE;QACtB,OAAO3F,MAAM,CAAC4C,KAAK,CAAE,sBAAqBnB,WAAY,EAAC,CAAC;MAC1D;MACA,IAAIgE,YAAY,EAAE;QAChB,MAAM,IAAItD,qBAAQ,CAACC,mBAAU,CAACC,qBAAqB,EAAG,wBAAuBZ,WAAY,EAAC,CAAC;MAC7F;MACA,OAAOzB,MAAM,CAAC4C,KAAK,CAAE,kCAAiCnB,WAAY,EAAC,CAAC;IACtE;IAEA,IAAIiE,gBAAgB,EAAE;MACpB,MAAM,IAAIvD,qBAAQ,CAACC,mBAAU,CAACC,qBAAqB,EAAG,mBAAkBZ,WAAY,EAAC,CAAC;IACxF;IACA,OAAOzB,MAAM,CAAC4C,KAAK,CAAE,mBAAkBnB,WAAY,EAAC,CAAC;EACvD;AACF"}
1
+ {"version":3,"file":"mongoLog.js","names":["_mongodb","require","_melindaBackendCommons","_melindaCommons","_utils","_moment","_interopRequireDefault","_httpStatus","_mongoSanitize","_constants","obj","__esModule","default","_default","MONGO_URI","logger","createLogger","client","MongoClient","connect","useNewUrlParser","useUnifiedTopology","db","collection","addLogItem","query","queryById","getListOfLogs","getExpandedListOfLogs","protect","remove","removeBySequences","logItem","time","moment","toDate","newLogItem","creationTime","protected","checkLogItemType","logItemType","result","insertOne","acknowledged","blobSequence","blobSequenceStart","blobSequenceEnd","itemString","info","correlationId","ApiError","httpStatus","INTERNAL_SERVER_ERROR","error","errorMessage","payload","message","logError","params","debug","JSON","stringify","limit","skip","rest","find","sort","parseInt","toArray","length","correlationIdString","distinct","status","OK","NOT_FOUND","pipeline","aggregate","fixedResult","map","logListing","_id","cataloger","logCount","silly","cleanCorrelationId","sanitize","cleanBlobSequence","filter","updateMany","$set","modificationTime","$not","modifiedCount","force","clean","$ne","deleteMany","deletedCount","sequences","cleanSequences","sequence","Number","isInteger","$in","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, getExpandedListOfLogs, protect, remove, removeBySequences};\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 const errorMessage = error.payload || error.message || '';\n logError(error);\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, `Mongo errored: ${errorMessage}`);\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 logger.debug(`Actual query params: ${JSON.stringify(rest)}`);\n const result = await db.collection(collection) // eslint-disable-line functional/immutable-data\n .find(rest)\n .sort({creationTime: 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 getExpandedListOfLogs(logItemType = 'MERGE_LOG') {\n checkLogItemType(logItemType, false, false);\n logger.debug(`Getting expanded list of logs`);\n const pipeline = [\n // currently return only MERGE_LOG and MATCH_LOG\n {'$match': {'logItemType': {'$in': ['MERGE_LOG', 'MATCH_LOG']}}},\n {'$sort':\n {'correlationId': 1, 'logItemType': 1, 'creationTime': 1}},\n {'$group':\n {'_id': {'correlationId': '$correlationId', 'logItemType': '$logItemType'},\n 'creationTime': {'$first': '$creationTime'},\n 'cataloger': {'$first': '$cataloger'},\n 'logCount': {'$sum': 1}}}\n ];\n\n const result = await db.collection(collection) // eslint-disable-line functional/immutable-data\n .aggregate(pipeline)\n .toArray();\n\n const fixedResult = result.map((logListing) => {\n const {correlationId, logItemType} = logListing._id;\n const {cataloger, creationTime, logCount} = logListing;\n return {correlationId, logItemType, cataloger, creationTime, logCount};\n });\n\n logger.silly(`Query result: ${JSON.stringify(result)}`);\n logger.silly(`Query result: ${JSON.stringify(fixedResult)}`);\n\n logger.debug(`Query result: ${fixedResult.length > 0 ? `Found ${fixedResult.length} log items!` : 'Not found!'}`);\n return {status: fixedResult.length > 0 ? httpStatus.OK : httpStatus.NOT_FOUND, payload: fixedResult.length > 0 ? fixedResult : '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: parseInt(cleanBlobSequence, 10)} : {correlationId: cleanCorrelationId};\n\n try {\n const result = await db.collection(collection).updateMany(\n filter,\n [\n {\n $set: {\n modificationTime: moment().toDate(),\n protected: {$not: '$protected'}\n }\n }\n ]\n );\n return {status: result.modifiedCount > 0 ? httpStatus.OK : httpStatus.NOT_FOUND, payload: result.modifiedCount > 0 ? result : 'No logs found'};\n } catch (error) {\n const errorMessage = error.payload || error.message || '';\n logError(error);\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, `Mongo errored: ${errorMessage}`);\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 (error) {\n const errorMessage = error.payload || error.message || '';\n logError(error);\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, `Mongo errored: ${errorMessage}`);\n }\n }\n\n async function removeBySequences(correlationId, sequences = [], force = false) {\n logger.info(`Removing from Mongo (${collection}) correlationId: ${correlationId}, sequences: ${sequences.length}`);\n const clean = sanitize(correlationId);\n // blobSequences are integers that start from 1\n // we accept also strings that are convertilble to integers greated than 0\n const cleanSequences = sequences.filter(sequence => Number.isInteger(Number(sequence)) && sequence > 0);\n\n if (sequences.length !== cleanSequences.length) {\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, `Invalid sequences in removeBySequences. Sequences should be positive integers`);\n }\n\n const filter = force ? {correlationId: clean, blobSequence: {$in: cleanSequences}} : {correlationId: clean, blobSequence: {$in: sequences}, 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 (error) {\n const errorMessage = error.payload || error.message || '';\n logError(error);\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, `Mongo errored: ${errorMessage}`);\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 logger.debug(`No logItemType: ${logItemType}`);\n }\n}\n"],"mappings":";;;;;;AA4BA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,sBAAA,GAAAD,OAAA;AACA,IAAAE,eAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAC,sBAAA,CAAAL,OAAA;AACA,IAAAM,WAAA,GAAAD,sBAAA,CAAAL,OAAA;AACA,IAAAO,cAAA,GAAAF,sBAAA,CAAAL,OAAA;AACA,IAAAQ,UAAA,GAAAR,OAAA;AAA0C,SAAAK,uBAAAI,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAnC1C;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;;AAWe,eAAAG,SAAgBC,SAAS,EAAE;EACxC,MAAMC,MAAM,GAAG,IAAAC,mC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BAAU,CAACuB,SAAS;QAAEnB,OAAO,EAAEd,MAAM,CAACwD,YAAY,GAAG,CAAC,GAAGxD,MAAM,GAAG;MAAe,CAAC;IAC9I,CAAC,CAAC,OAAOY,KAAK,EAAE;MACd,MAAMC,YAAY,GAAGD,KAAK,CAACE,OAAO,IAAIF,KAAK,CAACG,OAAO,IAAI,EAAE;MACzD,IAAAC,eAAQ,EAACJ,KAAK,CAAC;MACf,MAAM,IAAIH,qBAAQ,CAACC,mBAAU,CAACC,qBAAqB,EAAG,kBAAiBE,YAAa,EAAC,CAAC;IACxF;EACF;EAEA,SAASf,gBAAgBA,CAACC,WAAW,EAAEgE,YAAY,GAAG,KAAK,EAAEC,gBAAgB,GAAG,KAAK,EAAE;IAErF,IAAIjE,WAAW,EAAE;MACf,MAAMkE,kBAAkB,GAAGC,MAAM,CAACC,MAAM,CAACC,wBAAa,CAAC,CAACC,OAAO,CAACtE,WAAW,CAAC,GAAG,CAAC,CAAC;MACjF,IAAIkE,kBAAkB,EAAE;QACtB,OAAO3F,MAAM,CAAC4C,KAAK,CAAE,sBAAqBnB,WAAY,EAAC,CAAC;MAC1D;MACA,IAAIgE,YAAY,EAAE;QAChB,MAAM,IAAItD,qBAAQ,CAACC,mBAAU,CAACC,qBAAqB,EAAG,wBAAuBZ,WAAY,EAAC,CAAC;MAC7F;MACA,OAAOzB,MAAM,CAAC4C,KAAK,CAAE,kCAAiCnB,WAAY,EAAC,CAAC;IACtE;IAEA,IAAIiE,gBAAgB,EAAE;MACpB,MAAM,IAAIvD,qBAAQ,CAACC,mBAAU,CAACC,qBAAqB,EAAG,mBAAkBZ,WAAY,EAAC,CAAC;IACxF;IACA,OAAOzB,MAAM,CAAC4C,KAAK,CAAE,mBAAkBnB,WAAY,EAAC,CAAC;EACvD;AACF"}
package/package.json CHANGED
@@ -14,7 +14,7 @@
14
14
  "url": "git@github.com:natlibfi/melinda-rest-api-commons.git"
15
15
  },
16
16
  "license": "AGPL-3.0+",
17
- "version": "4.0.12-alpha.4",
17
+ "version": "4.0.12-alpha.5",
18
18
  "main": "./dist/index.js",
19
19
  "engines": {
20
20
  "node": ">=18"