@natlibfi/melinda-rest-api-commons 4.0.16-alpha.2 → 4.0.16-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
@@ -41,7 +41,7 @@ var _constants = require("./constants");
41
41
  *
42
42
  */
43
43
 
44
- async function _default(MONGO_URI) {
44
+ async function _default(MONGO_URI, dbName = 'rest-api') {
45
45
  const logger = (0, _melindaBackendCommons.createLogger)();
46
46
 
47
47
  // Connect to mongo (MONGO)
@@ -49,13 +49,14 @@ async function _default(MONGO_URI) {
49
49
  useNewUrlParser: true,
50
50
  useUnifiedTopology: true
51
51
  });
52
- const db = client.db('rest-api');
52
+ const db = client.db(dbName);
53
53
  const collection = 'logs';
54
54
  return {
55
55
  addLogItem,
56
56
  query,
57
57
  queryById,
58
58
  getListOfLogs,
59
+ getCatalogersListOfLogs,
59
60
  getExpandedListOfLogs,
60
61
  protect,
61
62
  remove,
@@ -69,6 +70,7 @@ async function _default(MONGO_URI) {
69
70
  protected: false
70
71
  };
71
72
  try {
73
+ console.log(newLogItem); // eslint-disable-line
72
74
  checkLogItemType(logItem.logItemType, false);
73
75
  const result = await db.collection(collection).insertOne(newLogItem);
74
76
  if (result.acknowledged) {
@@ -79,6 +81,7 @@ async function _default(MONGO_URI) {
79
81
  } = logItem;
80
82
  const itemString = blobSequenceStart && blobSequenceEnd ? `${blobSequenceStart} - ${blobSequenceEnd}` : `${blobSequence}`;
81
83
  logger.info(`*** New ${logItem.logItemType} added for ${logItem.correlationId}, blobSequence(s): ${itemString}. ***`);
84
+ console.log('addLogItem done', result); // eslint-disable-line
82
85
  return;
83
86
  }
84
87
  throw new _melindaCommons.Error(_httpStatus.default.INTERNAL_SERVER_ERROR);
@@ -133,20 +136,26 @@ async function _default(MONGO_URI) {
133
136
  payload: result.length > 0 ? result : 'No logs found'
134
137
  };
135
138
  }
139
+ async function getCatalogersListOfLogs() {
140
+ logger.debug(`Getting expanded list of logs`);
141
+ const result = await db.collection(collection) // eslint-disable-line functional/immutable-data
142
+ .distinct('cataloger');
143
+ return result;
144
+ }
136
145
 
137
146
  // getExpandedListOfLogs returns groped MERGE_LOGs and MATCH_LOGs
138
- async function getExpandedListOfLogs() {
147
+ async function getExpandedListOfLogs({
148
+ logItemTypes = [_constants.LOG_ITEM_TYPE.MERGE_LOG, _constants.LOG_ITEM_TYPE.MATCH_LOG],
149
+ catalogers = [],
150
+ dateBefore = new Date(),
151
+ dateAfter = new Date('2000-01-01')
152
+ }) {
153
+ logger.debug(JSON.stringify(generateMatchObject(logItemTypes, catalogers, dateBefore, dateAfter))); // eslint-disable-line
139
154
  //checkLogItemType(logItemType, false, false);
140
155
  logger.debug(`Getting expanded list of logs`);
141
156
  const pipeline = [
142
157
  // currently return only MERGE_LOG and MATCH_LOG
143
- {
144
- '$match': {
145
- 'logItemType': {
146
- '$in': ['MERGE_LOG', 'MATCH_LOG']
147
- }
148
- }
149
- }, {
158
+ generateMatchObject(logItemTypes, catalogers, dateBefore, dateAfter), {
150
159
  '$sort': {
151
160
  'correlationId': 1,
152
161
  'logItemType': 1,
@@ -168,6 +177,12 @@ async function _default(MONGO_URI) {
168
177
  '$sum': 1
169
178
  }
170
179
  }
180
+ }, {
181
+ '$sort': {
182
+ 'correlationId': 1,
183
+ 'logItemType': 1,
184
+ 'creationTime': 1
185
+ }
171
186
  }];
172
187
  const result = await db.collection(collection) // eslint-disable-line functional/immutable-data
173
188
  .aggregate(pipeline).toArray();
@@ -196,6 +211,23 @@ async function _default(MONGO_URI) {
196
211
  status: fixedResult.length > 0 ? _httpStatus.default.OK : _httpStatus.default.NOT_FOUND,
197
212
  payload: fixedResult.length > 0 ? fixedResult : 'No logs found'
198
213
  };
214
+ function generateMatchObject(logItemTypes, catalogers, dateBefore, dateAfter) {
215
+ const matchOptions = {
216
+ '$match': {
217
+ 'logItemType': logItemTypes.length > 0 ? {
218
+ '$in': logItemTypes
219
+ } : /.*/ui,
220
+ 'cataloger': catalogers.length > 0 ? {
221
+ '$in': catalogers
222
+ } : /.*/ui,
223
+ 'creationTime': {
224
+ '$gte': dateAfter.toISOString(),
225
+ '$lte': dateBefore.toISOString()
226
+ }
227
+ }
228
+ };
229
+ return matchOptions;
230
+ }
199
231
  }
200
232
  async function protect(correlationId, blobSequence) {
201
233
  logger.info(`Protecting in Mongo (${collection}) correlationId: ${correlationId}, blobSequence: ${blobSequence}`);
@@ -1 +1 @@
1
- {"version":3,"file":"mongoLog.js","names":["_mongodb","require","_melindaBackendCommons","_melindaCommons","_utils","_moment","_interopRequireDefault","_httpStatus","_mongoSanitize","_constants","_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 // 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 // getExpandedListOfLogs returns groped MERGE_LOGs and MATCH_LOGs\n async function getExpandedListOfLogs() {\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"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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","_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(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;;AA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fixura = require("@natlibfi/fixura");
5
+ var _fixugen = _interopRequireDefault(require("@natlibfi/fixugen"));
6
+ var _fixuraMongo = _interopRequireDefault(require("@natlibfi/fixura-mongo"));
7
+ var _chai = require("chai");
8
+ var _mongoLog = _interopRequireDefault(require("./mongoLog"));
9
+ // import {expect} from 'chai';
10
+
11
+ let mongoFixtures; // eslint-disable-line functional/no-let
12
+
13
+ (0, _fixugen.default)({
14
+ callback,
15
+ path: [__dirname, '..', 'test-fixtures', 'mongoLog'],
16
+ recurse: false,
17
+ useMetadataFile: true,
18
+ fixura: {
19
+ failWhenNotFound: true,
20
+ reader: _fixura.READERS.JSON
21
+ },
22
+ mocha: {
23
+ before: async () => {
24
+ await initMongofixtures();
25
+ },
26
+ beforeEach: () => mongoFixtures.clear(),
27
+ afterEach: () => mongoFixtures.clear(),
28
+ after: async () => {
29
+ await mongoFixtures.close();
30
+ }
31
+ }
32
+ });
33
+ async function initMongofixtures() {
34
+ mongoFixtures = await (0, _fixuraMongo.default)({
35
+ rootPath: [__dirname, '..', 'test-fixtures', 'mongoLog'],
36
+ gridFS: {
37
+ bucketName: 'blobs'
38
+ },
39
+ useObjectId: true,
40
+ format: {
41
+ creationTime: v => new Date(v),
42
+ modificationTime: v => new Date(v)
43
+ }
44
+ });
45
+ }
46
+ async function callback({
47
+ getFixture,
48
+ functionName,
49
+ params,
50
+ preFillDb = false
51
+ }) {
52
+ const mongoUri = await mongoFixtures.getUri();
53
+ const mongoLogOperator = await (0, _mongoLog.default)(mongoUri, '');
54
+ const expectedResult = await getFixture('expectedResult.json');
55
+ // console.log(typeof mongoUri); // eslint-disable-line
56
+
57
+ if (preFillDb) {
58
+ // eslint-disable-line functional/no-conditional-statements
59
+ await mongoFixtures.populate(getFixture('dbContents.json'));
60
+ }
61
+ if (functionName === 'addLogItem') {
62
+ await mongoLogOperator.addLogItem(params);
63
+ const dump = await mongoFixtures.dump();
64
+ return (0, _chai.expect)(dump.logs[0]['0']).to.eql(expectedResult);
65
+ }
66
+ if (functionName === 'getCatalogersListOfLogs') {
67
+ const result = await mongoLogOperator.getCatalogersListOfLogs();
68
+ console.log(result); // eslint-disable-line
69
+
70
+ return (0, _chai.expect)(result).to.eql(expectedResult);
71
+ }
72
+ if (functionName === 'getExpandedListOfLogs') {
73
+ const result = await mongoLogOperator.getExpandedListOfLogs(params);
74
+ console.log(result); // eslint-disable-line
75
+
76
+ return (0, _chai.expect)(result).to.eql(expectedResult);
77
+ }
78
+ }
79
+ //# sourceMappingURL=mongoLog.spec.js.map
@@ -0,0 +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","console","log","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,CAAC;EACpDC,OAAO,EAAE,KAAK;EACdC,eAAe,EAAE,IAAI;EACrBC,MAAM,EAAE;IACNC,gBAAgB,EAAE,IAAI;IACtBC,MAAM,EAAEC,eAAO,CAACC;EAClB,CAAC;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AgB,CAACI,UAAU,CAACR,MAAM,CAAC;IACzC,MAAMS,IAAI,GAAG,MAAMzC,aAAa,CAACyC,IAAI,CAAC,CAAC;IAEvC,OAAO,IAAAC,YAAM,EAACD,IAAI,CAACE,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAACC,EAAE,CAACC,GAAG,CAACP,cAAc,CAAC;EACzD;EAEA,IAAIP,YAAY,KAAK,yBAAyB,EAAE;IAC9C,MAAMe,MAAM,GAAG,MAAMV,gBAAgB,CAACW,uBAAuB,CAAC,CAAC;IAC/DC,OAAO,CAACC,GAAG,CAACH,MAAM,CAAC,CAAC,CAAC;;IAErB,OAAO,IAAAJ,YAAM,EAACI,MAAM,CAAC,CAACF,EAAE,CAACC,GAAG,CAACP,cAAc,CAAC;EAC9C;EAEA,IAAIP,YAAY,KAAK,uBAAuB,EAAE;IAC5C,MAAMe,MAAM,GAAG,MAAMV,gBAAgB,CAACc,qBAAqB,CAAClB,MAAM,CAAC;IACnEgB,OAAO,CAACC,GAAG,CAACH,MAAM,CAAC,CAAC,CAAC;;IAErB,OAAO,IAAAJ,YAAM,EAACI,MAAM,CAAC,CAACF,EAAE,CAACC,GAAG,CAACP,cAAc,CAAC;EAC9C;AAGF"}
package/package.json CHANGED
@@ -1,123 +1,135 @@
1
1
  {
2
- "name": "@natlibfi/melinda-rest-api-commons",
3
- "description": "Shared modules for microservices of Melinda rest api import system",
4
- "author": {
5
- "name": "The National Library of Finland"
6
- },
7
- "keywords": [],
8
- "homepage": "https://github.com/natlibfi/melinda-rest-api-commons",
9
- "bugs": {
10
- "url": "https://github.com/natlibfi/melinda-rest-api-commons/issues"
11
- },
12
- "repository": {
13
- "type": "git",
14
- "url": "git@github.com:natlibfi/melinda-rest-api-commons.git"
15
- },
16
- "license": "AGPL-3.0+",
17
- "version": "4.0.16-alpha.2",
18
- "main": "./dist/index.js",
19
- "engines": {
20
- "node": ">=18"
21
- },
22
- "publishConfig": {
23
- "access": "public"
24
- },
25
- "scripts": {
26
- "prepare": "npm run build",
27
- "lint": "eslint ./src",
28
- "lint:dev": "eslint ./src --fix",
29
- "test": "npm run lint && npm run test:base -- src/**/*.spec.js",
30
- "test:dev": "npm run lint:dev && npm run test:base -- src/**/*.spec.js",
31
- "test:base": "cross-env NODE_ENV=test nyc mocha --require @babel/register --exclude src/amqp.health.spec.js --exclude src/amqp.tests.spec.js",
32
- "test:local": "cross-env NODE_ENV=test nyc mocha --require @babel/register -- src/amqp.*.spec.js",
33
- "test:healthcheck": "cross-env NODE_ENV=test nyc mocha --require @babel/register -- src/amqp.health.spec.js",
34
- "coverage": "npm run cover:unit && npm run cover:report",
35
- "cover:unit": "nyc --silent npm run test",
36
- "cover:report": "nyc report --reporter=lcov --reporter=text",
37
- "dev": "NODE_ENV=development cross-env DEBUG='@natlibfi/*' nodemon",
38
- "build": "babel src --source-maps --copy-files --delete-dir-on-start --out-dir=dist"
39
- },
40
- "dependencies": {
41
- "@natlibfi/marc-record": "^7.3.1",
42
- "@natlibfi/marc-record-serializers": "^10.1.1",
43
- "@natlibfi/marc-record-validate": "^8.0.3",
44
- "@natlibfi/marc-record-validators-melinda": "^10.14.0",
45
- "@natlibfi/melinda-backend-commons": "^2.2.1",
46
- "@natlibfi/melinda-commons": "^13.0.7",
47
- "amqplib": "^0.10.3",
48
- "debug": "^4.3.4",
49
- "http-status": "^1.7.3",
50
- "moment": "^2.29.4",
51
- "mongo-sanitize": "^1.1.0",
52
- "mongodb": "^4.17.1"
53
- },
54
- "devDependencies": {
55
- "@babel/cli": "^7.23.0",
56
- "@babel/core": "^7.23.2",
57
- "@babel/plugin-transform-runtime": "7.22.15",
58
- "@babel/preset-env": "^7.23.2",
59
- "@natlibfi/eslint-config-melinda-backend": "^3.0.2",
60
- "@natlibfi/fixugen": "^2.0.2",
61
- "@natlibfi/fixura": "^3.0.2",
62
- "babel-plugin-istanbul": "^6.1.1",
63
- "babel-plugin-rewire": "^1.2.0",
64
- "chai": "^4.3.10",
65
- "cross-env": "^7.0.3",
66
- "eslint": "^8.51.0",
67
- "mocha": "^10.2.0",
68
- "nodemon": "^3.0.1",
69
- "nyc": "^15.1.0"
70
- },
71
- "eslintConfig": {
72
- "extends": "@natlibfi/melinda-backend"
73
- },
74
- "babel": {
75
- "presets": [
76
- [
77
- "@babel/preset-env",
78
- {
79
- "targets": "maintained node versions"
80
- }
81
- ]
82
- ],
83
- "plugins": [
84
- [
85
- "@babel/transform-runtime"
86
- ]
87
- ],
88
- "env": {
89
- "test": {
90
- "plugins": [
91
- "istanbul",
92
- "rewire"
93
- ]
94
- }
2
+ "name": "@natlibfi/melinda-rest-api-commons",
3
+ "description": "Shared modules for microservices of Melinda rest api import system",
4
+ "author": {
5
+ "name": "The National Library of Finland"
6
+ },
7
+ "keywords": [],
8
+ "homepage": "https://github.com/natlibfi/melinda-rest-api-commons",
9
+ "bugs": {
10
+ "url": "https://github.com/natlibfi/melinda-rest-api-commons/issues"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git@github.com:natlibfi/melinda-rest-api-commons.git"
15
+ },
16
+ "license": "AGPL-3.0+",
17
+ "version": "4.0.16-alpha.5",
18
+ "main": "./dist/index.js",
19
+ "engines": {
20
+ "node": ">=18"
21
+ },
22
+ "publishConfig": {
23
+ "access": "public"
24
+ },
25
+ "scripts": {
26
+ "prepare": "npm run build",
27
+ "lint": "eslint ./src",
28
+ "lint:dev": "eslint ./src --fix",
29
+ "test": "npm run lint && npm run test:base -- src/**/*.spec.js src/*.spec.js",
30
+ "test:dev": "npm run lint:dev && npm run test:base -- src/**/*.spec.js",
31
+ "test:base": "cross-env NODE_ENV=test nyc mocha --package ./package.json --exclude src/amqp.health.spec.js --exclude src/amqp.tests.spec.js",
32
+ "test:local": "cross-env NODE_ENV=test nyc mocha --package ./package.json -- src/amqp.*.spec.js",
33
+ "test:healthcheck": "cross-env NODE_ENV=test nyc mocha --require @babel/register -- src/amqp.health.spec.js",
34
+ "coverage": "npm run cover:unit && npm run cover:report",
35
+ "cover:unit": "nyc --silent npm run test",
36
+ "cover:report": "nyc report --reporter=lcov --reporter=text",
37
+ "dev": "NODE_ENV=development cross-env DEBUG='@natlibfi/*' nodemon",
38
+ "build": "babel src --source-maps --copy-files --delete-dir-on-start --out-dir=dist"
39
+ },
40
+ "dependencies": {
41
+ "@natlibfi/marc-record": "^7.3.1",
42
+ "@natlibfi/marc-record-serializers": "^10.1.1",
43
+ "@natlibfi/marc-record-validate": "^8.0.1",
44
+ "@natlibfi/marc-record-validators-melinda": "^10.13.0",
45
+ "@natlibfi/melinda-backend-commons": "^2.2.1",
46
+ "@natlibfi/melinda-commons": "^13.0.6",
47
+ "amqplib": "^0.10.3",
48
+ "debug": "^4.3.4",
49
+ "http-status": "^1.7.0",
50
+ "moment": "^2.29.4",
51
+ "mongo-sanitize": "^1.1.0",
52
+ "mongodb": "^4.17.1"
53
+ },
54
+ "devDependencies": {
55
+ "@babel/cli": "^7.22.15",
56
+ "@babel/core": "^7.22.20",
57
+ "@babel/plugin-transform-runtime": "7.22.15",
58
+ "@babel/preset-env": "^7.22.20",
59
+ "@natlibfi/eslint-config-melinda-backend": "^3.0.2",
60
+ "@natlibfi/fixugen": "^2.0.1",
61
+ "@natlibfi/fixura": "^3.0.1",
62
+ "@natlibfi/fixura-mongo": "^2.0.10-alpha.1",
63
+ "babel-plugin-istanbul": "^6.1.1",
64
+ "babel-plugin-rewire": "^1.2.0",
65
+ "chai": "^4.3.8",
66
+ "cross-env": "^7.0.3",
67
+ "eslint": "^8.49.0",
68
+ "mocha": "^10.2.0",
69
+ "nodemon": "^3.0.1",
70
+ "nyc": "^15.1.0"
71
+ },
72
+ "eslintConfig": {
73
+ "extends": "@natlibfi/melinda-backend"
74
+ },
75
+ "babel": {
76
+ "presets": [
77
+ [
78
+ "@babel/preset-env",
79
+ {
80
+ "targets": "maintained node versions"
95
81
  }
96
- },
97
- "nyc": {
98
- "exclude": [
99
- "**/*.spec.js"
100
- ],
101
- "reporter": [
102
- "lcov",
103
- "html"
104
- ],
105
- "require": [
106
- "@babel/register"
107
- ],
108
- "sourceMap": false,
109
- "instrument": false,
110
- "lines": 80,
111
- "statements": 80,
112
- "functions": 80,
113
- "branches": 80
114
- },
115
- "nodemonConfig": {
116
- "exec": "npm run test:dev",
117
- "watch": [
118
- "src/*"
119
- ],
120
- "ext": "js",
121
- "delay": 2.5
82
+ ]
83
+ ],
84
+ "plugins": [
85
+ [
86
+ "@babel/transform-runtime"
87
+ ]
88
+ ],
89
+ "env": {
90
+ "test": {
91
+ "plugins": [
92
+ "istanbul",
93
+ "rewire"
94
+ ]
95
+ }
122
96
  }
97
+ },
98
+ "mocha": {
99
+ "spec": [
100
+ "src/*.spec.js"
101
+ ],
102
+ "require": [
103
+ "@babel/register"
104
+ ],
105
+ "inline-diffs": true,
106
+ "maxDiffSize": 25000,
107
+ "bail": true,
108
+ "exit": true
109
+ },
110
+ "nyc": {
111
+ "exclude": [
112
+ "**/*.spec.js"
113
+ ],
114
+ "reporter": [
115
+ "text"
116
+ ],
117
+ "require": [
118
+ "@babel/register"
119
+ ],
120
+ "sourceMap": false,
121
+ "instrument": false,
122
+ "lines": 80,
123
+ "statements": 80,
124
+ "functions": 80,
125
+ "branches": 80
126
+ },
127
+ "nodemonConfig": {
128
+ "exec": "npm run test:dev",
129
+ "watch": [
130
+ "src/*"
131
+ ],
132
+ "ext": "js",
133
+ "delay": 2.5
134
+ }
123
135
  }