@natlibfi/melinda-rest-api-commons 6.0.1-alpha.1 → 6.1.0-alpha.0
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/README.md +34 -0
- package/dist/amqp.js +37 -15
- package/dist/amqp.js.map +2 -2
- package/dist/helpers/conversion.js +1 -2
- package/dist/helpers/conversion.js.map +2 -2
- package/dist/helpers/fix-strip-f884s.js +18 -4
- package/dist/helpers/fix-strip-f884s.js.map +2 -2
- package/dist/helpers/fix.js +12 -8
- package/dist/helpers/fix.js.map +2 -2
- package/dist/helpers/validation.js +1 -1
- package/dist/helpers/validation.js.map +1 -1
- package/dist/mongo.js +200 -109
- package/dist/mongo.js.map +3 -3
- package/dist/mongoLog.js +113 -35
- package/dist/mongoLog.js.map +3 -3
- package/dist/utils.js +33 -4
- package/dist/utils.js.map +2 -2
- package/package.json +11 -17
- package/tests/amqp-error-branches.test.js +535 -0
- package/tests/amqp.healthtest.js +12 -4
- package/tests/amqp.tests.localtest.js +13 -18
- package/tests/helpers/conversion.test.js +16 -0
- package/tests/helpers/fix-edge.test.js +197 -0
- package/tests/helpers/fix.test.js +20 -2
- package/tests/helpers/validation.test.js +6 -2
- package/tests/mongo-check-and-check-state.test.js +3 -1
- package/tests/mongo-check-and-set-import-job-state.test.js +3 -1
- package/tests/mongo-error-branches.test.js +787 -0
- package/tests/mongo-get-stream.test.js +4 -1
- package/tests/mongo-read-content.test.js +10 -0
- package/tests/mongoLog-protect.test.js +181 -0
- package/tests/mongoLog.test.js +113 -6
- package/tests/utils.test.js +360 -0
package/dist/mongoLog.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/mongoLog.js"],
|
|
4
|
-
"sourcesContent": ["import {MongoClient} from 'mongodb';\nimport moment from 'moment';\nimport httpStatus from 'http-status';\nimport sanitize from 'mongo-sanitize';\nimport {createLogger} from '@natlibfi/melinda-backend-commons';\nimport {Error as ApiError} from '@natlibfi/melinda-commons';\nimport {logError} from './utils.js';\nimport {LOG_ITEM_TYPE} from './constants.js';\n\n/**\n * Create log operator\n * @param {String} MONGO_URI connnection address to mongo\n * @param {String} dbName Mongo DB name, defaults 'rest-api'\n * @returns {Object} containing all log handling functions\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);\n const db = client.db(dbName);\n const collection = 'logs';\n return {addLogItem, query, queryById, getListOfLogs, getListOfCatalogers, getListOfCorrelationIds, getExpandedListOfLogs, protect, remove, removeBySequences};\n\n /**\n * Add log item to collection\n * @param {Object} logItem contains log item data\n * @returns void\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 /**\n * Query log items\n * @param {Integer} limit defaults 5\n * @param {Integer} skip defaults 0\n * @param {Object} rest query params\n * @returns result array\n */\n async function query({limit = 5, skip = 0, ...rest}) {\n logger.debug(`Query params: ${JSON.stringify(rest)}`);\n logger.debug(`Limit and skip params: ${limit} | ${skip}`);\n checkLogItemType(rest.logItemType, false, false);\n const result = await db.collection(collection)\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 /**\n * Get single log item by correlationId\n * @param {String} correlationId\n * @param {String} logItemType constant LOG_ITEM_TYPE defaults LOG_ITEM_TYPE.MERGE_LOG\n * @param {Integer} skip defaults 0\n * @param {Integer} limit defaults 1\n * @returns query result array\n */\n async function queryById(correlationId, logItemType = LOG_ITEM_TYPE.MERGE_LOG, skip = 0, limit = 1) {\n logger.debug(`QueryById: ${correlationId}, logItemType: ${logItemType}, skip: ${skip}, limit: ${limit}`);\n const result = await db.collection(collection)\n .find({correlationId, logItemType})\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 /**\n * Get list of correlationIds of logs filtered by logItemType\n * @param {String} logItemType constant LOG_ITEM_TYPE defaults LOG_ITEM_TYPE.MERGE_LOG\n * @returns Array of query results\n */\n async function getListOfLogs(logItemType = LOG_ITEM_TYPE.MERGE_LOG) {\n checkLogItemType(logItemType, true, true);\n //logger.debug(logItemType);\n // console.log(`${JSON.stringify(logItemType)}`);\n const result = await db.collection(collection)\n .distinct('correlationId', {logItemType: `${logItemType}`});\n logger.debug(`Query result for getListOfLogs: ${result.length > 0 ? `Found ${result.length} correlationIds for ${logItemType}!` : 'Not found!'}`);\n return result;\n }\n\n /**\n * Get list of catalogers from all available logs\n * @returns Array of query results\n */\n async function getListOfCatalogers() {\n logger.debug(`Getting list of Catalogers`);\n\n const result = await db.collection(collection)\n .distinct('cataloger');\n\n return result;\n }\n\n /**\n * Get list of correlationIds from all available logs\n * @returns Array of query results\n */\n async function getListOfCorrelationIds() {\n logger.debug(`Getting list of CorrelationIds`);\n\n const result = await db.collection(collection)\n .distinct('correlationId');\n\n return result;\n }\n\n\n /**\n * Get filtered list of logs with extra info. Give params in Object\n * @param {[String]} logItemTypes: String array of logItemTypes. Defaults [LOG_ITEM_TYPE.MERGE_LOG, LOG_ITEM_TYPE.MATCH_LOG]\n * @param {[String]} catalogers: String array of wanted catalogers. Defaults []\n * @param {String} dateBefore: String date schema 'YYYY-MM-DD'. Defaults new Date()\n * @param {String} dateAfter: String date schema 'YYYY-MM-DD'. Defaults '2000-01-01'\n * @param {Boolean} test: Boolean is this test run. Defaults false\n * @returns Parsed Object {'correlationId', 'logItemType', 'creationTime', 'cataloger', 'logCount'}\n */\n async function getExpandedListOfLogs({logItemTypes = [LOG_ITEM_TYPE.MERGE_LOG, LOG_ITEM_TYPE.MATCH_LOG], catalogers = [], dateBefore = new Date(), dateAfter = '2000-01-01', test = false}) {\n logger.debug(`commons/getExpandedListOfLogs: logItemTypes: ${JSON.stringify(logItemTypes)}, dateAfter: ${dateAfter}, dateBefore: ${dateBefore}}, catalogers: ${JSON.stringify(catalogers)}`);\n logger.silly(JSON.stringify(generateMatchObject({logItemTypes, catalogers, dateBefore, dateAfter})));\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, test}),\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)\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 fixedResult;\n\n /**\n * Generate match object for aggregation pipeline\n * @param {[String]} logItemTypes: String array of logItemTypes.\n * @param {[String]} catalogers: String array of wanted catalogers\n * @param {String} dateBefore: String date schema 'YYYY-MM-DD'\n * @param {String} dateAfter: String date schema 'YYYY-MM-DD'\n * @param {Boolean} test: Boolean is this test run. Defaults false\n * @returns Match Object\n */\n function generateMatchObject({logItemTypes, catalogers, dateBefore, dateAfter, test = false}) {\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': test ? new Date(dateAfter).toISOString() : new Date(dateAfter),\n '$lte': test ? new Date(dateBefore).toISOString() : new Date(dateBefore)\n }\n }\n };\n\n return matchOptions;\n }\n }\n\n /**\n * Protect logs from cleaning. Forced cleaning defaults 30days\n * @param {String} correlationId\n * @param {Integer} blobSequence\n * @returns result\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 result;\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 /**\n * Remove logs\n * @param {String} correlationId\n * @param {Boolean} force defaults false\n * @returns result\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 result;\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 /**\n * Remove logs by sequences\n * @param {String} correlationId\n * @param {[Integer]} sequences\n * @param {Boolean} force defaults false\n * @returns result\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 result;\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 /**\n * Checks existence and validity of logItemType\n * @param {String} logItemType constant LOG_ITEM_TYPE\n * @param {Boolean} errorUnknown defaults false\n * @param {Boolean} errorNotExisting defaults false\n * @returns void\n */\n function checkLogItemType(logItemType, errorUnknown = false, errorNotExisting = false) {\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"],
|
|
5
|
-
"mappings": "AAAA,SAAQ,mBAAkB;AAC1B,OAAO,
|
|
6
|
-
"names": ["logItemTypes", "catalogers", "dateBefore", "dateAfter"
|
|
4
|
+
"sourcesContent": ["import {MongoClient} from 'mongodb';\nimport httpStatus from 'http-status';\nimport {createLogger, Error as ApiError} from '@natlibfi/melinda-commons';\nimport {logError, assertString} from './utils.js';\nimport {LOG_ITEM_TYPE} from './constants.js';\n\n/**\n * Create log operator\n * @param {String} MONGO_URI connnection address to mongo\n * @param {String} dbName Mongo DB name, defaults 'rest-api'\n * @param {Object} deps optional dependencies, defaults {}. When deps.collection (a Mongo collection object) is provided, no real Mongo connection is made (used by unit tests)\n * @returns {Object} containing all log handling functions\n */\nexport default async function (MONGO_URI, dbName = 'rest-api', deps = {}) {\n const logger = createLogger();\n\n // blobSequence filters: falsy/undefined keeps the legacy behaviour (no\n // blobSequence in the filter). Otherwise a number or a string parseable\n // to an integer (existing parseInt behaviour) is accepted, anything else\n // is rejected with 400.\n function buildBlobSequenceFilter(correlationId, blobSequence) {\n if (!blobSequence) {\n return {correlationId};\n }\n if (typeof blobSequence === 'number') {\n return {correlationId, blobSequence: parseInt(blobSequence, 10)};\n }\n if (typeof blobSequence === 'string') {\n const parsed = parseInt(blobSequence, 10);\n if (!Number.isNaN(parsed)) {\n return {correlationId, blobSequence: parsed};\n }\n }\n throw new ApiError(httpStatus.BAD_REQUEST, 'blobSequence must be a number or a numeric string');\n }\n\n // Connect to mongo (MONGO), unless the logs collection is injected via\n // deps (used by unit tests to avoid a real connection)\n const collection = 'logs';\n let db;\n if (deps.collection) {\n db = {collection: () => deps.collection};\n } else {\n const client = await MongoClient.connect(MONGO_URI);\n db = client.db(dbName);\n }\n return {addLogItem, query, queryById, getListOfLogs, getListOfCatalogers, getListOfCorrelationIds, getExpandedListOfLogs, protect, unprotect, remove, removeBySequences};\n\n /**\n * Add log item to collection\n * @param {Object} logItem contains log item data\n * @returns void\n */\n async function addLogItem(logItem) {\n const time = new Date();\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 /**\n * Query log items\n * @param {Integer} limit defaults 5\n * @param {Integer} skip defaults 0\n * @param {Object} rest query params\n * @returns result array\n */\n async function query({limit = 5, skip = 0, ...rest}) {\n logger.debug(`Query params: ${JSON.stringify(rest)}`);\n logger.debug(`Limit and skip params: ${limit} | ${skip}`);\n checkLogItemType(rest.logItemType, false);\n // rest is an internal, trusted query object built by the calling service:\n // callers must not splice raw user input into it. Its keys may legitimately\n // use dot notation and $-operators, which is why rest is not\n // field-sanitized here.\n const result = await db.collection(collection)\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 /**\n * Get single log item by correlationId\n * @param {String} correlationId\n * @param {String} logItemType constant LOG_ITEM_TYPE defaults LOG_ITEM_TYPE.MERGE_LOG\n * @param {Integer} skip defaults 0\n * @param {Integer} limit defaults 1\n * @returns query result array\n */\n async function queryById(correlationId, logItemType = LOG_ITEM_TYPE.MERGE_LOG, skip = 0, limit = 1) {\n assertString(correlationId, 'correlationId');\n logger.debug(`QueryById: ${correlationId}, logItemType: ${logItemType}, skip: ${skip}, limit: ${limit}`);\n const result = await db.collection(collection)\n .find({correlationId, logItemType})\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 /**\n * Get list of correlationIds of logs filtered by logItemType\n * @param {String} logItemType constant LOG_ITEM_TYPE defaults LOG_ITEM_TYPE.MERGE_LOG\n * @returns Array of query results\n */\n async function getListOfLogs(logItemType = LOG_ITEM_TYPE.MERGE_LOG) {\n checkLogItemType(logItemType, true);\n //logger.debug(logItemType);\n // console.log(`${JSON.stringify(logItemType)}`);\n const result = await db.collection(collection)\n .distinct('correlationId', {logItemType: logItemType});\n logger.debug(`Query result for getListOfLogs: ${result.length > 0 ? `Found ${result.length} correlationIds for ${logItemType}!` : 'Not found!'}`);\n return result;\n }\n\n /**\n * Get list of catalogers from all available logs\n * @returns Array of query results\n */\n async function getListOfCatalogers() {\n logger.debug(`Getting list of Catalogers`);\n\n const result = await db.collection(collection)\n .distinct('cataloger');\n\n return result;\n }\n\n /**\n * Get list of correlationIds from all available logs\n * @returns Array of query results\n */\n async function getListOfCorrelationIds() {\n logger.debug(`Getting list of CorrelationIds`);\n\n const result = await db.collection(collection)\n .distinct('correlationId');\n\n return result;\n }\n\n\n /**\n * Get filtered list of logs with extra info. Give params in Object\n * @param {[String]} logItemTypes: String array of logItemTypes. Defaults [LOG_ITEM_TYPE.MERGE_LOG, LOG_ITEM_TYPE.MATCH_LOG]. When provided, must be an array and every element is validated (unknown types throw)\n * @param {[String]} catalogers: String array of wanted catalogers. Defaults []\n * @param {String|Date} dateBefore: upper bound, the day itself is EXCLUDED. 'YYYY-MM-DD' or Date, anchored to UTC. Defaults new Date()\n * @param {String|Date} dateAfter: lower bound, the day itself is INCLUDED. 'YYYY-MM-DD' or Date, anchored to UTC. Defaults '1970-01-01' (no lower bound)\n * @param {Boolean} test: kept for backwards compatibility only; no longer changes the match\n * @returns Parsed Object {'correlationId', 'logItemType', 'creationTime', 'cataloger', 'logCount'}\n */\n // test no longer changes the match behaviour (kept in the\n // signature for backwards compatibility only)\n // eslint-disable-next-line no-unused-vars\n async function getExpandedListOfLogs({logItemTypes, catalogers = [], dateBefore = new Date(), dateAfter = '1970-01-01', test = false}) {\n // An explicitly provided logItemTypes is validated per element (unknown\n // types throw); when it is omitted, the trusted default pair is used so\n // legacy callers that never pass it keep working unchanged\n const wantedLogItemTypes = logItemTypes === undefined\n ? [LOG_ITEM_TYPE.MERGE_LOG, LOG_ITEM_TYPE.MATCH_LOG]\n : logItemTypes;\n if (!Array.isArray(wantedLogItemTypes)) {\n throw new ApiError(httpStatus.BAD_REQUEST, `logItemTypes must be an array: ${logItemTypes}`);\n }\n if (logItemTypes !== undefined) {\n logItemTypes.forEach(logItemType => {\n if (Object.values(LOG_ITEM_TYPE).includes(logItemType)) {\n return;\n }\n throw new ApiError(httpStatus.BAD_REQUEST, `Unknown logItemType: ${logItemType}`);\n });\n }\n logger.debug(`commons/getExpandedListOfLogs: logItemTypes: ${JSON.stringify(wantedLogItemTypes)}, dateAfter: ${dateAfter}, dateBefore: ${dateBefore}}, catalogers: ${JSON.stringify(catalogers)}`);\n logger.silly(JSON.stringify(generateMatchObject({logItemTypes: wantedLogItemTypes, catalogers, dateBefore, dateAfter})));\n //logger.debug(`Getting expanded list of logs`);\n const pipeline = [\n // currently return only MERGE_LOG and MATCH_LOG\n generateMatchObject({logItemTypes: wantedLogItemTypes, 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 // after $group the output has no top-level correlationId /\n // logItemType, so the sort must address them via _id\n {\n '$sort':\n {'_id.correlationId': 1, '_id.logItemType': 1, 'creationTime': 1}\n }\n ];\n\n const result = await db.collection(collection)\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 fixedResult;\n\n /**\n * Generate match object for aggregation pipeline\n * @param {[String]} logItemTypes: String array of logItemTypes.\n * @param {[String]} catalogers: String array of wanted catalogers\n * @param {String|Date} dateBefore: upper bound. Date strings are anchored at UTC midnight of the day after; Date instances are used as-is\n * @param {String|Date} dateAfter: lower bound. Date strings are anchored at UTC midnight of that day (inclusive); Date instances are used as-is\n * @returns Match Object\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 is stored as a Date, so the bounds must be\n // Dates too (the old test=true branch compared against ISO strings\n // and never matched; the old non-test branch relied on\n // local-timezone parsing of new Date('YYYY-MM-DD')). Date strings\n // are anchored at UTC midnight so the result is deterministic\n // regardless of the server timezone.\n 'creationTime': {\n '$gte': dateToUtcStartOfDay(dateAfter),\n '$lt': dateToUtcExclusiveUpperBound(dateBefore)\n }\n }\n };\n\n return matchOptions;\n\n // Date string 'YYYY-MM-DD' -> UTC midnight of that day (inclusive\n // lower bound). Date instance or any other string format -> parsed\n // with Date (a timestamp, not a day).\n function dateToUtcStartOfDay(value) {\n if (value instanceof Date) {\n return value;\n }\n const parts = String(value).slice(0, 10).split('-');\n if (parts.length === 3) {\n return new Date(Date.UTC(parts[0], parts[1] - 1, parts[2]));\n }\n return new Date(value);\n }\n\n // Date string 'YYYY-MM-DD' -> UTC midnight of the NEXT day (exclusive\n // upper bound). Date instance or any other string format -> parsed\n // with Date (a timestamp, not a day).\n function dateToUtcExclusiveUpperBound(value) {\n if (value instanceof Date) {\n return value;\n }\n const parts = String(value).slice(0, 10).split('-');\n if (parts.length === 3) {\n return new Date(Date.UTC(parts[0], parts[1] - 1, parts[2]) + 86400000);\n }\n return new Date(value);\n }\n }\n }\n\n /**\n * Protect logs from cleaning. Idempotent: always sets protected to true\n * (a second call leaves the logs protected, unlike the old toggle).\n * Forced cleaning defaults 30days\n * @param {String} correlationId\n * @param {Integer} blobSequence\n * @returns result\n */\n async function protect(correlationId, blobSequence) {\n logger.info(`Protecting in Mongo (${collection}) correlationId: ${correlationId}, blobSequence: ${blobSequence}`);\n assertString(correlationId, 'correlationId');\n const filter = buildBlobSequenceFilter(correlationId, blobSequence);\n\n try {\n const result = await db.collection(collection).updateMany(\n filter,\n [\n {\n $set: {\n modificationTime: new Date(),\n // plain true, not a $not toggle: protect must be idempotent\n protected: true\n }\n }\n ]\n );\n return result;\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 /**\n * Unprotect logs so regular (non-forced) cleaning can remove them.\n * Same signature and behavior as protect, but sets protected to false.\n * @param {String} correlationId\n * @param {Integer} blobSequence\n * @returns result\n */\n async function unprotect(correlationId, blobSequence) {\n logger.info(`Unprotecting in Mongo (${collection}) correlationId: ${correlationId}, blobSequence: ${blobSequence}`);\n assertString(correlationId, 'correlationId');\n const filter = buildBlobSequenceFilter(correlationId, blobSequence);\n\n try {\n const result = await db.collection(collection).updateMany(\n filter,\n [\n {\n $set: {\n modificationTime: new Date(),\n protected: false\n }\n }\n ]\n );\n return result;\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 /**\n * Remove logs\n * @param {String} correlationId\n * @param {Boolean} force defaults false\n * @returns result\n */\n async function remove(correlationId, force = false) {\n logger.info(`Removing from Mongo (${collection}) correlationId: ${correlationId}`);\n assertString(correlationId, 'correlationId');\n const filter = force ? {correlationId} : {correlationId, protected: {$ne: true}};\n\n try {\n const result = await db.collection(collection).deleteMany(filter);\n return result;\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 /**\n * Remove logs by sequences\n * @param {String} correlationId\n * @param {[Integer]} sequences\n * @param {Boolean} force defaults false\n * @returns result\n */\n async function removeBySequences(correlationId, sequences = [], force = false) {\n logger.info(`Removing from Mongo (${collection}) correlationId: ${correlationId}, sequences: ${sequences.length}`);\n assertString(correlationId, 'correlationId');\n // NOTE: this matches only single-sequence items (blobSequence), NOT bulk\n // range items (blobSequenceStart/blobSequenceEnd); a requested sequence\n // inside a bulk range will not match and its logs are kept\n // blobSequences are integers that start from 1\n // we accept also strings that are convertilble to integers greated than 0\n // validate consistently via Number() and store the\n // converted numbers, since blobSequence is stored as a number in Mongo\n const cleanSequences = sequences\n .map(sequence => Number(sequence))\n .filter(sequence => Number.isInteger(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 // use the numeric cleanSequences in BOTH branches (the non-forced\n // branch used to pass raw `sequences`, so string inputs like '1' would\n // never match the stored numeric blobSequence)\n const filter = force\n ? {correlationId, blobSequence: {$in: cleanSequences}}\n : {correlationId, blobSequence: {$in: cleanSequences}, protected: {$ne: true}};\n\n try {\n const result = await db.collection(collection).deleteMany(filter);\n return result;\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 /**\n * Checks existence and validity of logItemType\n * @param {String} logItemType constant LOG_ITEM_TYPE\n * @param {Boolean} errorUnknown defaults false\n * @returns void\n */\n function checkLogItemType(logItemType, errorUnknown = false) {\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 return logger.debug(`No logItemType: ${logItemType}`);\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAQ,mBAAkB;AAC1B,OAAO,gBAAgB;AACvB,SAAQ,cAAc,SAAS,gBAAe;AAC9C,SAAQ,UAAU,oBAAmB;AACrC,SAAQ,qBAAoB;AAS5B,8BAA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@ -1,6 +1,5 @@
|
|
|
1
1
|
import httpStatus from "http-status";
|
|
2
|
-
import { createLogger } from "@natlibfi/melinda-
|
|
3
|
-
import { Error as ApiError } from "@natlibfi/melinda-commons";
|
|
2
|
+
import { createLogger, Error as ApiError } from "@natlibfi/melinda-commons";
|
|
4
3
|
import { IMPORT_JOB_STATE, OPERATIONS } from "./constants.js";
|
|
5
4
|
const logger = createLogger();
|
|
6
5
|
export function logError(err) {
|
|
@@ -14,6 +13,30 @@ export function logError(err) {
|
|
|
14
13
|
}
|
|
15
14
|
logger.error(err.stack === void 0 ? err : err.stack);
|
|
16
15
|
}
|
|
16
|
+
export function assertString(value, name) {
|
|
17
|
+
if (typeof value !== "string") {
|
|
18
|
+
throw new ApiError(httpStatus.BAD_REQUEST, `${name} must be a string`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export function assertNumber(value, name) {
|
|
22
|
+
if (typeof value !== "number") {
|
|
23
|
+
throw new ApiError(httpStatus.BAD_REQUEST, `${name} must be a number`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export function assertImportJobStateFilter(value, name) {
|
|
27
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
28
|
+
throw new ApiError(httpStatus.BAD_REQUEST, `${name} must be an object`);
|
|
29
|
+
}
|
|
30
|
+
const validKeys = Object.values(OPERATIONS).map((operation) => `importJobState.${operation}`);
|
|
31
|
+
for (const [key, state] of Object.entries(value)) {
|
|
32
|
+
if (!validKeys.includes(key)) {
|
|
33
|
+
throw new ApiError(httpStatus.BAD_REQUEST, `${name} key ${key} must be one of ${validKeys.join(", ")}`);
|
|
34
|
+
}
|
|
35
|
+
if (typeof state !== "string") {
|
|
36
|
+
throw new ApiError(httpStatus.BAD_REQUEST, `${name}.${key} must be a string`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
17
40
|
export function createImportJobState(operation, state, queryImportJobState = false) {
|
|
18
41
|
if (!(state in IMPORT_JOB_STATE)) {
|
|
19
42
|
throw new Error("Invalid IMPORT_JOB_STATE");
|
|
@@ -29,6 +52,9 @@ export function createImportJobState(operation, state, queryImportJobState = fal
|
|
|
29
52
|
return { [operation]: state };
|
|
30
53
|
}
|
|
31
54
|
export function createRecordResponseItem({ responsePayload, responseStatus, recordMetadata, id }) {
|
|
55
|
+
if (responsePayload === void 0 || responsePayload === null) {
|
|
56
|
+
throw new Error("responsePayload must be an object or a string!");
|
|
57
|
+
}
|
|
32
58
|
const recordResponseStatusAndMessage = getRecordResponseStatusAndMessage(responseStatus, responsePayload, id);
|
|
33
59
|
const recordResponseItem = {
|
|
34
60
|
databaseId: id || "000000000",
|
|
@@ -58,13 +84,13 @@ function getRecordResponseStatusAndMessage(responseStatus, responsePayload, id)
|
|
|
58
84
|
if (/^MatchValidation for all/u.test(message)) {
|
|
59
85
|
return { recordStatus: "ERROR", detailedRecordStatus: "CONFLICT", message, ids };
|
|
60
86
|
}
|
|
61
|
-
if (ids.length > 1 || ids[0] !== id) {
|
|
87
|
+
if (ids.length > 1 || ids.length > 0 && ids[0] !== id) {
|
|
62
88
|
return { recordStatus: "ERROR", detailedRecordStatus: "CONFLICT", message, ids };
|
|
63
89
|
}
|
|
64
90
|
return { recordStatus: "ERROR", detailedRecordStatus: "CONFLICT", message };
|
|
65
91
|
}
|
|
66
92
|
if ([httpStatus.UNPROCESSABLE_ENTITY, "UNPROCESSABLE_ENTITY"].includes(responseStatus)) {
|
|
67
|
-
if (ids.length > 1 || ids[0] !== id) {
|
|
93
|
+
if (ids.length > 1 || ids.length > 0 && ids[0] !== id) {
|
|
68
94
|
return { recordStatus: "INVALID", detailedRecordStatus: "UNPROCESSABLE_ENTITY", message, ids };
|
|
69
95
|
}
|
|
70
96
|
return { recordStatus: "INVALID", detailedRecordStatus: "UNPROCESSABLE_ENTITY", message };
|
|
@@ -89,6 +115,9 @@ function getMessageFromResponsePayload(responsePayload) {
|
|
|
89
115
|
return "";
|
|
90
116
|
}
|
|
91
117
|
export async function addRecordResponseItem({ recordResponseItem, correlationId, mongoOperator }) {
|
|
118
|
+
if (!recordResponseItem || typeof recordResponseItem !== "object" || Array.isArray(recordResponseItem)) {
|
|
119
|
+
throw new Error("RecordResponseItem is not an object!");
|
|
120
|
+
}
|
|
92
121
|
await mongoOperator.pushMessages({ correlationId, messages: [recordResponseItem], messageField: "records" });
|
|
93
122
|
return true;
|
|
94
123
|
}
|
package/dist/utils.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/utils.js"],
|
|
4
|
-
"sourcesContent": ["import httpStatus from 'http-status';\nimport {createLogger
|
|
5
|
-
"mappings": "AAAA,OAAO,gBAAgB;AACvB,SAAQ,
|
|
4
|
+
"sourcesContent": ["import httpStatus from 'http-status';\nimport {createLogger, Error as ApiError} from '@natlibfi/melinda-commons';\nimport {IMPORT_JOB_STATE, OPERATIONS} from './constants.js';\n\nconst logger = createLogger();\n\nexport function logError(err) {\n if (err instanceof ApiError) {\n logger.error(JSON.stringify(err));\n return;\n }\n\n if (err === 'SIGINT') {\n logger.error(err);\n return;\n }\n\n logger.error(err.stack === undefined ? err : err.stack);\n}\n\n// Entry-point type guards: correlationIds and scalar params are expected as\n// plain strings/numbers. A non-scalar (e.g. an object) would be spliced into\n// the query as a MongoDB operator, so reject it with 400 before any query.\nexport function assertString(value, name) {\n if (typeof value !== 'string') {\n throw new ApiError(httpStatus.BAD_REQUEST, `${name} must be a string`);\n }\n}\n\nexport function assertNumber(value, name) {\n if (typeof value !== 'number') {\n throw new ApiError(httpStatus.BAD_REQUEST, `${name} must be a number`);\n }\n}\n\n// getOne may filter on import job state subfields (importJobState.CREATE /\n// .UPDATE / .FIX), which are spliced straight into the Mongo filter, so a\n// $-operator key or an object value would inject operators: restrict the keys\n// to the known operations and the values to plain state strings.\nexport function assertImportJobStateFilter(value, name) {\n if (value === null || typeof value !== 'object' || Array.isArray(value)) {\n throw new ApiError(httpStatus.BAD_REQUEST, `${name} must be an object`);\n }\n const validKeys = Object.values(OPERATIONS).map(operation => `importJobState.${operation}`);\n for (const [key, state] of Object.entries(value)) {\n if (!validKeys.includes(key)) {\n throw new ApiError(httpStatus.BAD_REQUEST, `${name} key ${key} must be one of ${validKeys.join(', ')}`);\n }\n if (typeof state !== 'string') {\n throw new ApiError(httpStatus.BAD_REQUEST, `${name}.${key} must be a string`);\n }\n }\n}\n\nexport function createImportJobState(operation, state, queryImportJobState = false) {\n if (!(state in IMPORT_JOB_STATE)) {\n throw new Error('Invalid IMPORT_JOB_STATE');\n }\n\n if (!(operation in OPERATIONS)) {\n throw new Error('Invalid operation');\n }\n\n if (queryImportJobState) {\n const importJobStateWithOperation = `importJobState.${operation}`;\n const importJobStateForQuery = {[importJobStateWithOperation]: state};\n\n return importJobStateForQuery;\n }\n\n return {[operation]: state};\n}\n\nexport function createRecordResponseItem({responsePayload, responseStatus, recordMetadata, id}) {\n // symmetric with addRecordResponseItem \u2014 reject a missing payload up\n // front with a clear message instead of a raw TypeError further down.\n // Strings are a valid payload form (see getMessageFromResponsePayload),\n // so only undefined/null are rejected.\n if (responsePayload === undefined || responsePayload === null) {\n throw new Error('responsePayload must be an object or a string!');\n }\n\n const recordResponseStatusAndMessage = getRecordResponseStatusAndMessage(responseStatus, responsePayload, id);\n const recordResponseItem = {\n databaseId: id || '000000000',\n recordMetadata: responsePayload.recordMetadata || recordMetadata || undefined,\n ...recordResponseStatusAndMessage\n };\n return recordResponseItem;\n}\n\nfunction getRecordResponseStatusAndMessage(responseStatus, responsePayload, id) {\n\n logger.debug(`Response status: ${responseStatus} responsePayload: ${JSON.stringify(responsePayload)}`);\n //const responseStatusName = httpStatus[`${responseStatus}_NAME`];\n //logger.debug(`Response status name: ${responseStatusName}`);\n\n const message = getMessageFromResponsePayload(responsePayload);\n const ids = responsePayload.ids || [];\n\n logger.debug(`Response message: ${message}`);\n\n // We map responseStatus here for a wider recordStatus and more detailed detailedRecordStatus\n // recordStatus corresponds to RECORD_IMPORT_STATEs used in https://github.com/NatLibFi/melinda-record-import-commons-js\n\n // Non-http statuses\n if (['UPDATED', 'CREATED', 'INVALID', 'ERROR', 'SKIPPED', 'FIXED'].includes(responseStatus)) {\n return {recordStatus: responseStatus, detailedRecordStatus: responseStatus, message};\n }\n\n // More detailed SKIPPED statuses\n if (['SKIPPED_CHANGE', 'SKIPPED_UPDATE'].includes(responseStatus)) {\n return {recordStatus: 'SKIPPED', detailedRecordStatus: responseStatus, message};\n }\n\n if (['UNKNOWN'].includes(responseStatus)) {\n return {recordStatus: 'ERROR', detailedRecordStatus: responseStatus, message, ids};\n }\n\n // Duplicates and other CONFLICT statuses\n if ([httpStatus.CONFLICT, 'CONFLICT'].includes(responseStatus)) {\n if ((/^Duplicates in database/u).test(message)) {\n return {recordStatus: 'DUPLICATE', detailedRecordStatus: 'DUPLICATE', message, ids};\n }\n if ((/^MatchValidation for all/u).test(message)) {\n return {recordStatus: 'ERROR', detailedRecordStatus: 'CONFLICT', message, ids};\n }\n\n // Use ids only if there are more than one id or the id in payload does not match databaseId\n // only compare ids[0] when there is at least one id\n if (ids.length > 1 || (ids.length > 0 && ids[0] !== id)) {\n return {recordStatus: 'ERROR', detailedRecordStatus: 'CONFLICT', message, ids};\n }\n return {recordStatus: 'ERROR', detailedRecordStatus: 'CONFLICT', message};\n }\n\n if ([httpStatus.UNPROCESSABLE_ENTITY, 'UNPROCESSABLE_ENTITY'].includes(responseStatus)) {\n // only compare ids[0] when there is at least one id\n if (ids.length > 1 || (ids.length > 0 && ids[0] !== id)) {\n return {recordStatus: 'INVALID', detailedRecordStatus: 'UNPROCESSABLE_ENTITY', message, ids};\n }\n return {recordStatus: 'INVALID', detailedRecordStatus: 'UNPROCESSABLE_ENTITY', message};\n }\n\n if ([httpStatus.NOT_FOUND, 'NOT_FOUND'].includes(responseStatus)) {\n return {recordStatus: 'ERROR', detailedRecordStatus: 'NOT_FOUND', message};\n }\n\n if ([httpStatus.FORBIDDEN, 'FORBIDDEN'].includes(responseStatus)) {\n return {recordStatus: 'ERROR', detailedRecordStatus: 'FORBIDDEN', message};\n }\n\n // Otherwise\n logger.debug(`Unknown responseStatus: ${responseStatus}`);\n const newMessage = `${message} - Unknown recordStatus: ${responseStatus}`;\n return {recordStatus: 'ERROR', detailedRecordStatus: responseStatus, message: newMessage};\n}\n\nfunction getMessageFromResponsePayload(responsePayload) {\n if (responsePayload.message) {\n return responsePayload.message;\n }\n if (typeof responsePayload === 'string' || responsePayload instanceof String) {\n return responsePayload;\n }\n return '';\n}\n\nexport async function addRecordResponseItem({recordResponseItem, correlationId, mongoOperator}) {\n // symmetric with addRecordResponseItems \u2014 reject non-object input\n // (including arrays) before it gets pushed into the records field\n if (!recordResponseItem || typeof recordResponseItem !== 'object' || Array.isArray(recordResponseItem)) {\n throw new Error('RecordResponseItem is not an object!');\n }\n await mongoOperator.pushMessages({correlationId, messages: [recordResponseItem], messageField: 'records'});\n return true;\n}\n\n// Use addRecordResponseItems to add several recordResponseItems in one mongo operation to avoid writeconflicts\nexport async function addRecordResponseItems({recordResponseItems, correlationId, mongoOperator}) {\n if (!Array.isArray(recordResponseItems)) {\n throw new Error('RecordResponseItems is not an array!');\n }\n await mongoOperator.pushMessages({correlationId, messages: recordResponseItems, messageField: 'records'});\n return true;\n}\n\n"],
|
|
5
|
+
"mappings": "AAAA,OAAO,gBAAgB;AACvB,SAAQ,cAAc,SAAS,gBAAe;AAC9C,SAAQ,kBAAkB,kBAAiB;AAE3C,MAAM,SAAS,aAAa;AAErB,gBAAS,SAAS,KAAK;AAC5B,MAAI,eAAe,UAAU;AAC3B,WAAO,MAAM,KAAK,UAAU,GAAG,CAAC;AAChC;AAAA,EACF;AAEA,MAAI,QAAQ,UAAU;AACpB,WAAO,MAAM,GAAG;AAChB;AAAA,EACF;AAEA,SAAO,MAAM,IAAI,UAAU,SAAY,MAAM,IAAI,KAAK;AACxD;AAKO,gBAAS,aAAa,OAAO,MAAM;AACxC,MAAI,OAA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Ae,UAAU,CAAC,kBAAkB,GAAG,cAAc,UAAS,CAAC;AACzG,SAAO;AACT;AAGA,sBAAsB,uBAAuB,EAAC,qBAAqB,eAAe,cAAa,GAAG;AAChG,MAAI,CAAC,MAAM,QAAQ,mBAAmB,GAAG;AACvC,UAAM,IAAI,MAAM,sCAAsC;AAAA,EACxD;AACA,QAAM,cAAc,aAAa,EAAC,eAAe,UAAU,qBAAqB,cAAc,UAAS,CAAC;AACxG,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"url": "https://github.com/NatLibFi/melinda-rest-api-commons"
|
|
14
14
|
},
|
|
15
15
|
"license": "MIT",
|
|
16
|
-
"version": "6.0
|
|
16
|
+
"version": "6.1.0-alpha.0",
|
|
17
17
|
"main": "./dist/index.js",
|
|
18
18
|
"type": "module",
|
|
19
19
|
"engines": {
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"lint": "eslint ./src",
|
|
29
29
|
"lint:dev": "eslint --fix ./src",
|
|
30
30
|
"test": "npm run lint && npm run test:base",
|
|
31
|
-
"test:base": "node --test --test-force-exit --experimental-test-coverage --test-reporter=spec './tests/**/*.test.js'",
|
|
31
|
+
"test:base": "node --test --test-force-exit --experimental-test-coverage --test-coverage-lines=88 --test-coverage-branches=88 --test-coverage-functions=90 --test-reporter=spec './tests/**/*.test.js'",
|
|
32
32
|
"test:local": "cross-env NODE_ENV=test node --test --test-force-exit --experimental-test-coverage --test-reporter=spec './tests/amqp.*.localtest.js'",
|
|
33
33
|
"test:healthcheck": "cross-env NODE_ENV=test node --test --test-force-exit --experimental-test-coverage --test-reporter=spec './tests/amqp.healthtest.js'",
|
|
34
34
|
"watch:test": "cross-env DEBUG=@natlibfi/* NODE_ENV=test node --watch --test --experimental-test-coverage --test-reporter=spec './tests/**/*.test.js'",
|
|
@@ -36,28 +36,22 @@
|
|
|
36
36
|
"dev:debug": "cross-env LOG_LEVEL=debug DEBUG=@natlibfi/* NODE_ENV=test npm run watch:test"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@natlibfi/marc-record": "^
|
|
39
|
+
"@natlibfi/marc-record": "^11.0.3",
|
|
40
40
|
"@natlibfi/marc-record-serializers": "^11.0.4",
|
|
41
41
|
"@natlibfi/marc-record-validate": "^9.0.2",
|
|
42
|
-
"@natlibfi/marc-record-validators-melinda": "^13.0.
|
|
43
|
-
"@natlibfi/melinda-
|
|
44
|
-
"
|
|
45
|
-
"amqplib": "^0.10.9",
|
|
42
|
+
"@natlibfi/marc-record-validators-melinda": "^13.0.6",
|
|
43
|
+
"@natlibfi/melinda-commons": "^16.0.0",
|
|
44
|
+
"amqplib": "^2.2.0",
|
|
46
45
|
"debug": "^4.4.3",
|
|
47
46
|
"http-status": "^2.1.0",
|
|
48
|
-
"
|
|
49
|
-
"mongo-sanitize": "^1.1.0",
|
|
50
|
-
"mongodb": "^6.21.0"
|
|
47
|
+
"mongodb": "^7.7.0"
|
|
51
48
|
},
|
|
52
49
|
"devDependencies": {
|
|
53
|
-
"@natlibfi/fixugen": "^
|
|
54
|
-
"@natlibfi/fixura": "^
|
|
55
|
-
"@natlibfi/fixura-mongo": "^
|
|
50
|
+
"@natlibfi/fixugen": "^4.0.0",
|
|
51
|
+
"@natlibfi/fixura": "^5.0.0",
|
|
52
|
+
"@natlibfi/fixura-mongo": "^4.0.2",
|
|
56
53
|
"cross-env": "^10.1.0",
|
|
57
54
|
"esbuild": "^0.28.1",
|
|
58
|
-
"eslint": "^10.
|
|
59
|
-
},
|
|
60
|
-
"overrides": {
|
|
61
|
-
"nanoid": "^3.3.8"
|
|
55
|
+
"eslint": "^10.12.0"
|
|
62
56
|
}
|
|
63
57
|
}
|