@natlibfi/melinda-rest-api-commons 4.0.16-alpha.6 → 4.0.16-alpha.8
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 +9 -7
- package/dist/mongoLog.js.map +1 -1
- package/dist/mongoLog.spec.js +2 -2
- package/dist/mongoLog.spec.js.map +1 -1
- package/package.json +1 -1
package/dist/mongoLog.js
CHANGED
|
@@ -56,7 +56,7 @@ async function _default(MONGO_URI, dbName = 'rest-api') {
|
|
|
56
56
|
query,
|
|
57
57
|
queryById,
|
|
58
58
|
getListOfLogs,
|
|
59
|
-
|
|
59
|
+
getListOfCatalogers,
|
|
60
60
|
getExpandedListOfLogs,
|
|
61
61
|
protect,
|
|
62
62
|
remove,
|
|
@@ -70,7 +70,7 @@ async function _default(MONGO_URI, dbName = 'rest-api') {
|
|
|
70
70
|
protected: false
|
|
71
71
|
};
|
|
72
72
|
try {
|
|
73
|
-
console.log(newLogItem); // eslint-disable-line
|
|
73
|
+
// console.log(newLogItem); // eslint-disable-line
|
|
74
74
|
checkLogItemType(logItem.logItemType, false);
|
|
75
75
|
const result = await db.collection(collection).insertOne(newLogItem);
|
|
76
76
|
if (result.acknowledged) {
|
|
@@ -81,7 +81,7 @@ async function _default(MONGO_URI, dbName = 'rest-api') {
|
|
|
81
81
|
} = logItem;
|
|
82
82
|
const itemString = blobSequenceStart && blobSequenceEnd ? `${blobSequenceStart} - ${blobSequenceEnd}` : `${blobSequence}`;
|
|
83
83
|
logger.info(`*** New ${logItem.logItemType} added for ${logItem.correlationId}, blobSequence(s): ${itemString}. ***`);
|
|
84
|
-
console.log('addLogItem done', result); // eslint-disable-line
|
|
84
|
+
// console.log('addLogItem done', result); // eslint-disable-line
|
|
85
85
|
return;
|
|
86
86
|
}
|
|
87
87
|
throw new _melindaCommons.Error(_httpStatus.default.INTERNAL_SERVER_ERROR);
|
|
@@ -136,8 +136,8 @@ async function _default(MONGO_URI, dbName = 'rest-api') {
|
|
|
136
136
|
payload: result.length > 0 ? result : 'No logs found'
|
|
137
137
|
};
|
|
138
138
|
}
|
|
139
|
-
async function
|
|
140
|
-
logger.debug(`Getting
|
|
139
|
+
async function getListOfCatalogers() {
|
|
140
|
+
logger.debug(`Getting list of Catalogers`);
|
|
141
141
|
const result = await db.collection(collection) // eslint-disable-line functional/immutable-data
|
|
142
142
|
.distinct('cataloger');
|
|
143
143
|
return result;
|
|
@@ -213,6 +213,8 @@ async function _default(MONGO_URI, dbName = 'rest-api') {
|
|
|
213
213
|
payload: fixedResult.length > 0 ? fixedResult : 'No logs found'
|
|
214
214
|
};
|
|
215
215
|
function generateMatchObject(logItemTypes, catalogers, dateBefore, dateAfter) {
|
|
216
|
+
const dateBeforeIso = new Date(dateBefore).toISOString();
|
|
217
|
+
const dateAfterIso = new Date(dateAfter).toISOString();
|
|
216
218
|
const matchOptions = {
|
|
217
219
|
'$match': {
|
|
218
220
|
'logItemType': logItemTypes.length > 0 ? {
|
|
@@ -222,8 +224,8 @@ async function _default(MONGO_URI, dbName = 'rest-api') {
|
|
|
222
224
|
'$in': catalogers
|
|
223
225
|
} : /.*/ui,
|
|
224
226
|
'creationTime': {
|
|
225
|
-
'$gte':
|
|
226
|
-
'$lte':
|
|
227
|
+
'$gte': dateAfterIso,
|
|
228
|
+
'$lte': dateBeforeIso
|
|
227
229
|
}
|
|
228
230
|
}
|
|
229
231
|
};
|
package/dist/mongoLog.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mongoLog.js","names":["_mongodb","require","_melindaBackendCommons","_melindaCommons","_utils","_moment","_interopRequireDefault","_httpStatus","_mongoSanitize","_constants","_default","MONGO_URI","dbName","logger","createLogger","client","MongoClient","connect","useNewUrlParser","useUnifiedTopology","db","collection","addLogItem","query","queryById","getListOfLogs","getCatalogersListOfLogs","getExpandedListOfLogs","protect","remove","removeBySequences","logItem","time","moment","toDate","newLogItem","creationTime","protected","console","log","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","logItemTypes","LOG_ITEM_TYPE","MERGE_LOG","MATCH_LOG","catalogers","dateBefore","Date","dateAfter","generateMatchObject","pipeline","aggregate","fixedResult","map","logListing","_id","cataloger","logCount","silly","matchOptions","toISOString","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","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, dbName = 'rest-api') {\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(dbName);\n const collection = 'logs';\n return {addLogItem, query, queryById, getListOfLogs, getCatalogersListOfLogs, 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 console.log(newLogItem); // eslint-disable-line\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 console.log('addLogItem done', result); // eslint-disable-line\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 // DEVELOP: queryById returns jsut one (randomish) log! is this useful?\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 // getListOfLogs returns list of correlationIds that have logs of given logItemType\n // if logItemType is not given, getListOfLogs returns list of correlationIds that have MERGE_LOG\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 getCatalogersListOfLogs() {\n logger.debug(`Getting expanded list of logs`);\n\n const result = await db.collection(collection) // eslint-disable-line functional/immutable-data\n .distinct('cataloger');\n\n return result;\n }\n\n // getExpandedListOfLogs returns groped MERGE_LOGs and MATCH_LOGs\n async function getExpandedListOfLogs({logItemTypes = [LOG_ITEM_TYPE.MERGE_LOG, LOG_ITEM_TYPE.MATCH_LOG], catalogers = [], dateBefore = new Date(), dateAfter = new Date('2000-01-01')}) {\n logger.debug(`commons: logItemTypes: ${JSON.stringify(logItemTypes)}, dateAfter: ${dateAfter}, dateBefore: ${dateBefore}}, catalogers: ${JSON.stringify(catalogers)}`);\n logger.debug(JSON.stringify(generateMatchObject(logItemTypes, catalogers, dateBefore, dateAfter))); // eslint-disable-line\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 generateMatchObject(logItemTypes, catalogers, dateBefore, dateAfter),\n {\n '$sort':\n {'correlationId': 1, 'logItemType': 1, 'creationTime': 1}\n },\n {\n '$group':\n {\n '_id': {'correlationId': '$correlationId', 'logItemType': '$logItemType'},\n 'creationTime': {'$first': '$creationTime'},\n 'cataloger': {'$first': '$cataloger'},\n 'logCount': {'$sum': 1}\n }\n },\n {\n '$sort':\n {'correlationId': 1, 'logItemType': 1, 'creationTime': 1}\n }\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 function generateMatchObject(logItemTypes, catalogers, dateBefore, dateAfter) {\n const matchOptions = {\n '$match': {\n 'logItemType': logItemTypes.length > 0 ? {'$in': logItemTypes} : /.*/ui,\n 'cataloger': catalogers.length > 0 ? {'$in': catalogers} : /.*/ui,\n 'creationTime': {\n '$gte': dateAfter.toISOString(),\n '$lte': dateBefore.toISOString()\n }\n }\n };\n\n return matchOptions;\n }\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;AAnCA;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,eAAAS,SAAgBC,SAAS,EAAEC,MAAM,GAAG,UAAU,EAAE;EAC7D,MAAMC,MAAM,GAAG,IAAAC,mCAAY,EAAC,CAAC;;EAE7B;EACA,MAAMC,MAAM,GAAG,MAAMC,oBAAW,CAACC,OAAO,CAACN,SAAS,EAAE;IAACO,eAAe,EAAE,IAAI;IAAEC,kBAAkB,EAAE;EAAI,CAAC,CAAC;EACtG,MAAMC,EAAE,GAAGL,MAAM,CAACK,EAAE,CAACR,MAAM,CAAC;EAC5B,MAAMS,UAAU,GAAG,MAAM;EACzB,OAAO;IAACC,UAAU;IAAEC,KAAK;IAAEC,SAAS;IAAEC,aAAa;IAAEC,uBAAuB;IAAEC,qBAAqB;IAAEC,OAAO;IAAEC,MAAM;IA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M,IAAIH,qBAAQ,CAACC,mBAAU,CAACC,qBAAqB,EAAG,kBAAiBE,YAAa,EAAC,CAAC;IACxF;EACF;EAEA,SAASf,gBAAgBA,CAACC,WAAW,EAAE2E,YAAY,GAAG,KAAK,EAAEC,gBAAgB,GAAG,KAAK,EAAE;IAErF,IAAI5E,WAAW,EAAE;MACf,MAAM6E,kBAAkB,GAAGC,MAAM,CAACC,MAAM,CAAC3C,wBAAa,CAAC,CAAC4C,OAAO,CAAChF,WAAW,CAAC,GAAG,CAAC,CAAC;MACjF,IAAI6E,kBAAkB,EAAE;QACtB,OAAOzG,MAAM,CAAC+C,KAAK,CAAE,sBAAqBnB,WAAY,EAAC,CAAC;MAC1D;MACA,IAAI2E,YAAY,EAAE;QAChB,MAAM,IAAIjE,qBAAQ,CAACC,mBAAU,CAACC,qBAAqB,EAAG,wBAAuBZ,WAAY,EAAC,CAAC;MAC7F;MACA,OAAO5B,MAAM,CAAC+C,KAAK,CAAE,kCAAiCnB,WAAY,EAAC,CAAC;IACtE;IAEA,IAAI4E,gBAAgB,EAAE;MACpB,MAAM,IAAIlE,qBAAQ,CAACC,mBAAU,CAACC,qBAAqB,EAAG,mBAAkBZ,WAAY,EAAC,CAAC;IACxF;IACA,OAAO5B,MAAM,CAAC+C,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","_default","MONGO_URI","dbName","logger","createLogger","client","MongoClient","connect","useNewUrlParser","useUnifiedTopology","db","collection","addLogItem","query","queryById","getListOfLogs","getListOfCatalogers","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","logItemTypes","LOG_ITEM_TYPE","MERGE_LOG","MATCH_LOG","catalogers","dateBefore","Date","dateAfter","generateMatchObject","pipeline","aggregate","fixedResult","map","logListing","_id","cataloger","logCount","silly","dateBeforeIso","toISOString","dateAfterIso","matchOptions","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","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, dbName = 'rest-api') {\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(dbName);\n const collection = 'logs';\n return {addLogItem, query, queryById, getListOfLogs, getListOfCatalogers, 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 // console.log(newLogItem); // eslint-disable-line\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 // console.log('addLogItem done', result); // eslint-disable-line\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 // DEVELOP: queryById returns jsut one (randomish) log! is this useful?\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 // getListOfLogs returns list of correlationIds that have logs of given logItemType\n // if logItemType is not given, getListOfLogs returns list of correlationIds that have MERGE_LOG\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 getListOfCatalogers() {\n logger.debug(`Getting list of Catalogers`);\n\n const result = await db.collection(collection) // eslint-disable-line functional/immutable-data\n .distinct('cataloger');\n\n return result;\n }\n\n // getExpandedListOfLogs returns groped MERGE_LOGs and MATCH_LOGs\n async function getExpandedListOfLogs({logItemTypes = [LOG_ITEM_TYPE.MERGE_LOG, LOG_ITEM_TYPE.MATCH_LOG], catalogers = [], dateBefore = new Date(), dateAfter = new Date('2000-01-01')}) {\n logger.debug(`commons: logItemTypes: ${JSON.stringify(logItemTypes)}, dateAfter: ${dateAfter}, dateBefore: ${dateBefore}}, catalogers: ${JSON.stringify(catalogers)}`);\n logger.debug(JSON.stringify(generateMatchObject(logItemTypes, catalogers, dateBefore, dateAfter))); // eslint-disable-line\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 generateMatchObject(logItemTypes, catalogers, dateBefore, dateAfter),\n {\n '$sort':\n {'correlationId': 1, 'logItemType': 1, 'creationTime': 1}\n },\n {\n '$group':\n {\n '_id': {'correlationId': '$correlationId', 'logItemType': '$logItemType'},\n 'creationTime': {'$first': '$creationTime'},\n 'cataloger': {'$first': '$cataloger'},\n 'logCount': {'$sum': 1}\n }\n },\n {\n '$sort':\n {'correlationId': 1, 'logItemType': 1, 'creationTime': 1}\n }\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 function generateMatchObject(logItemTypes, catalogers, dateBefore, dateAfter) {\n const dateBeforeIso = new Date(dateBefore).toISOString();\n const dateAfterIso = new Date(dateAfter).toISOString();\n const matchOptions = {\n '$match': {\n 'logItemType': logItemTypes.length > 0 ? {'$in': logItemTypes} : /.*/ui,\n 'cataloger': catalogers.length > 0 ? {'$in': catalogers} : /.*/ui,\n 'creationTime': {\n '$gte': dateAfterIso,\n '$lte': dateBeforeIso\n }\n }\n };\n\n return matchOptions;\n }\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;AAnCA;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,eAAAS,SAAgBC,SAAS,EAAEC,MAAM,GAAG,UAAU,EAAE;EAC7D,MAAMC,MAAM,GAAG,IAAAC,mCAAY,EAAC,CAAC;;EAE7B;EACA,MAAMC,MAAM,GAAG,MAAMC,oBAAW,CAACC,OAAO,CAACN,SAAS,EAAE;IAACO,eAAe,EAAE,IAAI;IAAEC,kBAAkB,EAAE;EAAI,CAAC,CAAC;EACtG,MAAMC,EAAE,GAAGL,MAAM,CAACK,EAAE,CAACR,MAAM,CAAC;EAC5B,MAAMS,UAAU,GAAG,MAAM;EACzB,OAAO;IAACC,UAAU;IAAEC,KAAK;IAAEC,SAAS;IAAEC,aAAa;IAAEC,mBAAmB;IAAEC,qBAAqB;IAAEC,OAAO;IAAEC,MAAM;IAAEC;EAAiB,CAAC;EAE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ACC,qBAAqB,EAAG,kBAAiBE,YAAa,EAAC,CAAC;IACxF;EACF;EAEA,SAASf,gBAAgBA,CAACC,WAAW,EAAE6E,YAAY,GAAG,KAAK,EAAEC,gBAAgB,GAAG,KAAK,EAAE;IAErF,IAAI9E,WAAW,EAAE;MACf,MAAM+E,kBAAkB,GAAGC,MAAM,CAACC,MAAM,CAAC7C,wBAAa,CAAC,CAAC8C,OAAO,CAAClF,WAAW,CAAC,GAAG,CAAC,CAAC;MACjF,IAAI+E,kBAAkB,EAAE;QACtB,OAAOzG,MAAM,CAAC6C,KAAK,CAAE,sBAAqBnB,WAAY,EAAC,CAAC;MAC1D;MACA,IAAI6E,YAAY,EAAE;QAChB,MAAM,IAAInE,qBAAQ,CAACC,mBAAU,CAACC,qBAAqB,EAAG,wBAAuBZ,WAAY,EAAC,CAAC;MAC7F;MACA,OAAO1B,MAAM,CAAC6C,KAAK,CAAE,kCAAiCnB,WAAY,EAAC,CAAC;IACtE;IAEA,IAAI8E,gBAAgB,EAAE;MACpB,MAAM,IAAIpE,qBAAQ,CAACC,mBAAU,CAACC,qBAAqB,EAAG,mBAAkBZ,WAAY,EAAC,CAAC;IACxF;IACA,OAAO1B,MAAM,CAAC6C,KAAK,CAAE,mBAAkBnB,WAAY,EAAC,CAAC;EACvD;AACF"}
|
package/dist/mongoLog.spec.js
CHANGED
|
@@ -65,13 +65,13 @@ async function callback({
|
|
|
65
65
|
}
|
|
66
66
|
if (functionName === 'getCatalogersListOfLogs') {
|
|
67
67
|
const result = await mongoLogOperator.getCatalogersListOfLogs();
|
|
68
|
-
console.log(result); // eslint-disable-line
|
|
68
|
+
// console.log(result); // eslint-disable-line
|
|
69
69
|
|
|
70
70
|
return (0, _chai.expect)(result).to.eql(expectedResult);
|
|
71
71
|
}
|
|
72
72
|
if (functionName === 'getExpandedListOfLogs') {
|
|
73
73
|
const result = await mongoLogOperator.getExpandedListOfLogs(params);
|
|
74
|
-
console.log(result); // eslint-disable-line
|
|
74
|
+
// console.log(result); // eslint-disable-line
|
|
75
75
|
|
|
76
76
|
return (0, _chai.expect)(result).to.eql(expectedResult);
|
|
77
77
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mongoLog.spec.js","names":["_fixura","require","_fixugen","_interopRequireDefault","_fixuraMongo","_chai","_mongoLog","mongoFixtures","generateTests","callback","path","__dirname","recurse","useMetadataFile","fixura","failWhenNotFound","reader","READERS","JSON","mocha","before","initMongofixtures","beforeEach","clear","afterEach","after","close","mongoFixturesFactory","rootPath","gridFS","bucketName","useObjectId","format","creationTime","v","Date","modificationTime","getFixture","functionName","params","preFillDb","mongoUri","getUri","mongoLogOperator","createMongoLogOperator","expectedResult","populate","addLogItem","dump","expect","logs","to","eql","result","getCatalogersListOfLogs","
|
|
1
|
+
{"version":3,"file":"mongoLog.spec.js","names":["_fixura","require","_fixugen","_interopRequireDefault","_fixuraMongo","_chai","_mongoLog","mongoFixtures","generateTests","callback","path","__dirname","recurse","useMetadataFile","fixura","failWhenNotFound","reader","READERS","JSON","mocha","before","initMongofixtures","beforeEach","clear","afterEach","after","close","mongoFixturesFactory","rootPath","gridFS","bucketName","useObjectId","format","creationTime","v","Date","modificationTime","getFixture","functionName","params","preFillDb","mongoUri","getUri","mongoLogOperator","createMongoLogOperator","expectedResult","populate","addLogItem","dump","expect","logs","to","eql","result","getCatalogersListOfLogs","getExpandedListOfLogs"],"sources":["../src/mongoLog.spec.js"],"sourcesContent":["// import {expect} from 'chai';\nimport {READERS} from '@natlibfi/fixura';\nimport generateTests from '@natlibfi/fixugen';\nimport mongoFixturesFactory from '@natlibfi/fixura-mongo';\nimport {expect} from 'chai';\nimport createMongoLogOperator from './mongoLog';\n\nlet mongoFixtures; // eslint-disable-line functional/no-let\n\ngenerateTests({\n callback,\n path: [__dirname, '..', 'test-fixtures', 'mongoLog'],\n recurse: false,\n useMetadataFile: true,\n fixura: {\n failWhenNotFound: true,\n reader: READERS.JSON\n },\n mocha: {\n before: async () => {\n await initMongofixtures();\n },\n beforeEach: () => mongoFixtures.clear(),\n afterEach: () => mongoFixtures.clear(),\n after: async () => {\n await mongoFixtures.close();\n }\n }\n});\n\nasync function initMongofixtures() {\n mongoFixtures = await mongoFixturesFactory({\n rootPath: [__dirname, '..', 'test-fixtures', 'mongoLog'],\n gridFS: {bucketName: 'blobs'},\n useObjectId: true,\n format: {\n creationTime: v => new Date(v),\n modificationTime: v => new Date(v)\n }\n });\n}\n\nasync function callback({\n getFixture,\n functionName,\n params,\n preFillDb = false\n}) {\n const mongoUri = await mongoFixtures.getUri();\n const mongoLogOperator = await createMongoLogOperator(mongoUri, '');\n const expectedResult = await getFixture('expectedResult.json');\n // console.log(typeof mongoUri); // eslint-disable-line\n\n if (preFillDb) { // eslint-disable-line functional/no-conditional-statements\n await mongoFixtures.populate(getFixture('dbContents.json'));\n }\n\n if (functionName === 'addLogItem') {\n await mongoLogOperator.addLogItem(params);\n const dump = await mongoFixtures.dump();\n\n return expect(dump.logs[0]['0']).to.eql(expectedResult);\n }\n\n if (functionName === 'getCatalogersListOfLogs') {\n const result = await mongoLogOperator.getCatalogersListOfLogs();\n // console.log(result); // eslint-disable-line\n\n return expect(result).to.eql(expectedResult);\n }\n\n if (functionName === 'getExpandedListOfLogs') {\n const result = await mongoLogOperator.getExpandedListOfLogs(params);\n // console.log(result); // eslint-disable-line\n\n return expect(result).to.eql(expectedResult);\n }\n\n\n}\n"],"mappings":";;;AACA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,YAAA,GAAAD,sBAAA,CAAAF,OAAA;AACA,IAAAI,KAAA,GAAAJ,OAAA;AACA,IAAAK,SAAA,GAAAH,sBAAA,CAAAF,OAAA;AALA;;AAOA,IAAIM,aAAa,CAAC,CAAC;;AAEnB,IAAAC,gBAAa,EAAC;EACZC,QAAQ;EACRC,IAAI,EAAE,CAACC,SAAS,EAAE,IAAI,EAAE,eAAe,EAAE,UAAU,CA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