@natlibfi/melinda-rest-api-commons 4.0.16-alpha.7 → 4.0.17-alpha.1
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/.github/dependabot.yml +4 -9
- package/dist/amqp.js +4 -2
- package/dist/amqp.js.map +1 -1
- package/dist/constants.js +12 -6
- package/dist/constants.js.map +1 -1
- package/dist/helpers/fix-constants.js +18 -10
- package/dist/helpers/fix-constants.js.map +1 -1
- package/dist/helpers/fix.spec.js +2 -2
- package/dist/helpers/fix.spec.js.map +1 -1
- package/dist/helpers/validation.spec.js +2 -2
- package/dist/helpers/validation.spec.js.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/mongoLog.js +10 -43
- package/dist/mongoLog.js.map +1 -1
- package/package.json +119 -131
- package/dist/mongoLog.spec.js +0 -79
- package/dist/mongoLog.spec.js.map +0 -1
package/.github/dependabot.yml
CHANGED
|
@@ -10,7 +10,7 @@ updates:
|
|
|
10
10
|
interval: "daily"
|
|
11
11
|
time: "06:30"
|
|
12
12
|
timezone: "Europe/Helsinki"
|
|
13
|
-
target-branch: "
|
|
13
|
+
target-branch: "dependencies"
|
|
14
14
|
|
|
15
15
|
# Minor updates to npm production dependencies daily
|
|
16
16
|
- package-ecosystem: "npm"
|
|
@@ -20,14 +20,9 @@ updates:
|
|
|
20
20
|
time: "06:45"
|
|
21
21
|
timezone: "Europe/Helsinki"
|
|
22
22
|
versioning-strategy: lockfile-only
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
groups:
|
|
27
|
-
production-dependencies:
|
|
28
|
-
dependency-type: "production"
|
|
29
|
-
development-dependencies:
|
|
30
|
-
dependency-type: "development"
|
|
23
|
+
allow:
|
|
24
|
+
- dependency-type: "production"
|
|
25
|
+
target-branch: "dependencies"
|
|
31
26
|
|
|
32
27
|
# Major updates to npm dependencies weekly @tuesday
|
|
33
28
|
# Not possible yet https://github.com/dependabot/dependabot-core/issues/1778
|
package/dist/amqp.js
CHANGED
|
@@ -294,8 +294,10 @@ async function _default(AMQP_URL, runHealthCheck = false) {
|
|
|
294
294
|
debug(`Parsing messages (${messages.length}) to records`);
|
|
295
295
|
return messages.map(message => {
|
|
296
296
|
const content = JSON.parse(message.content.toString());
|
|
297
|
-
//
|
|
298
|
-
return new _marcRecord.MarcRecord(content.data
|
|
297
|
+
// Use subfieldValues: false validationOption here
|
|
298
|
+
return new _marcRecord.MarcRecord(content.data, {
|
|
299
|
+
subfieldValues: false
|
|
300
|
+
});
|
|
299
301
|
});
|
|
300
302
|
}
|
|
301
303
|
async function getData(queue) {
|
package/dist/amqp.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"amqp.js","names":["_amqplib","_interopRequireDefault","require","_marcRecord","_melindaCommons","_melindaBackendCommons","_debug","_constants","_util","_httpStatus","_utils","_default","AMQP_URL","runHealthCheck","logger","createLogger","debug","createDebugLogger","debugHC","extend","debugData","connection","amqplib","connect","channel","createChannel","healthCheckLoop","healthCheck","checkQueue","consumeChunk","consumeOne","ackMessages","nackMessages","sendToQueue","removeQueue","messagesToRecords","closeChannel","closeConnection","close","wait","setTimeoutPromise","promisify","setTimeout","assertQueue","durable","error","JSON","stringify","handleAmqpErrors","queue","style","toRecord","purge","errorUndefinedQueue","channelInfo","purgeQueue","verbose","messageCount","checkMessageCount","ApiError","httpStatus","INTERNAL_SERVER_ERROR","messages","getData","headers","getHeaderInfo","length","records","message","get","inspect","colors","maxArrayLength","depth","forEach","properties","correlationId","ack","nack","data","Buffer","from","persistent","errorToThrow","tempChannel","deleteQueue","map","content","parse","toString","MarcRecord","messagesToGet","CHUNK_SIZE","pump","count","results","identifiers","identifier","deliveryTag","fields","includes","concat","undefined","newError","status","payload","logError"],"sources":["../src/amqp.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 amqplib from 'amqplib';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport {Error as ApiError} from '@natlibfi/melinda-commons';\nimport {createLogger} from '@natlibfi/melinda-backend-commons';\nimport createDebugLogger from 'debug';\nimport {CHUNK_SIZE} from './constants';\nimport {promisify, inspect} from 'util';\nimport httpStatus from 'http-status';\nimport {logError} from './utils';\n\nexport default async function (AMQP_URL, runHealthCheck = false) {\n const logger = createLogger();\n const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons:amqp');\n const debugHC = debug.extend('HC');\n const debugData = debug.extend('data');\n\n debug(`Creating an AMQP operator to ${AMQP_URL}`);\n const connection = await amqplib.connect(AMQP_URL);\n const channel = await connection.createChannel();\n\n const healthCheckLoop = runHealthCheck ? healthCheck() : false;\n\n debug(`Connection: ${connection}`);\n debug(`Channel: ${channel}`);\n debug(`HealthCheckLoop: ${healthCheckLoop ? 'Running health check' : 'Not running health check'}`);\n\n return {checkQueue, consumeChunk, consumeOne, ackMessages, nackMessages, sendToQueue, removeQueue, messagesToRecords, closeChannel, closeConnection};\n\n async function closeChannel() {\n debug(`Closing channel`);\n await channel.close();\n debug(`Channel: ${channel}`);\n }\n\n async function closeConnection() {\n debug(`Closing connection`);\n await connection.close();\n debug(`Connection: ${connection}`);\n }\n\n async function healthCheck(wait = false) {\n const setTimeoutPromise = promisify(setTimeout);\n if (wait) {\n await setTimeoutPromise(wait);\n return healthCheck(false);\n }\n\n try {\n debugHC(`Health checking amqp by asserting a queue`);\n await channel.assertQueue('HEALTHCHECK', {durable: false});\n debugHC(`Waiting 200ms before running healthCheck next`);\n return healthCheck('200');\n } catch (error) {\n debugHC(`HealthCheck error ${JSON.stringify(error)}`);\n handleAmqpErrors(error);\n }\n }\n\n // eslint-disable-next-line max-statements\n async function checkQueue({queue, style = 'basic', toRecord = true, purge = false}) {\n debug(`checkQueue: ${queue}, Style: ${style}, toRecord: ${toRecord}, Purge: ${purge}`);\n\n try {\n\n errorUndefinedQueue(queue);\n const channelInfo = await channel.assertQueue(queue, {durable: true});\n\n if (purge) {\n await purgeQueue(purge);\n logger.verbose(`Queue ${queue} has purged ${channelInfo.messageCount} messages`);\n debug(`Queue ${queue} has purged ${channelInfo.messageCount} messages`);\n return checkQueue({queue, style});\n }\n\n if (style === 'messages') {\n return channelInfo.messageCount;\n }\n\n\n // Note: returns one message (+ record, of toRecord: true)\n // note: if toRecord is false returns just plain message / false\n // note: if toRecord is true returns {headers, records, messages} -object / false\n // should this be more consistent?\n if (style === 'one') {\n if (checkMessageCount(channelInfo)) {\n return consumeOne(queue, toRecord);\n }\n return false;\n }\n\n // Note: returns a chunk of (100) messages (+ records, if toRecord: true)\n // returns {headers, records, messages} object or {headers, messages} object depending on toRecord\n if (style === 'basic') {\n if (checkMessageCount(channelInfo)) {\n return consumeChunk(queue, toRecord);\n }\n return false;\n }\n\n // Defaults:\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, `CheckQueue does not recognize style ${style}`);\n } catch (error) {\n handleAmqpErrors(error);\n }\n\n function checkMessageCount(channelInfo) {\n if (channelInfo.messageCount < 1) {\n debug(`checkQueue: ${channelInfo.messageCount} - ${queue} is empty`);\n return false;\n }\n debug(`Queue ${queue} has ${channelInfo.messageCount} messages`);\n return true;\n }\n\n function purgeQueue(purge) {\n debug(`Purging queue: ${queue}, purge: ${purge}`);\n if (purge) {\n return channel.purgeQueue(queue);\n }\n }\n }\n\n async function consumeChunk(queue, toRecord) {\n debug(`Prepared to consumeChunk from queue: ${queue}`);\n try {\n await channel.assertQueue(queue, {durable: true});\n\n // getData: next chunk (100) messages\n const messages = await getData(queue);\n\n // Note: headers are from the first message of the chunk\n const headers = getHeaderInfo(messages[0]);\n debug(`consumeChunk (${messages ? messages.length : '0'} from queue ${queue}) ${toRecord ? 'to records' : 'just messages'}`);\n\n if (toRecord) {\n const records = await messagesToRecords(messages);\n return {headers, records, messages};\n }\n\n return {headers, messages};\n } catch (error) {\n handleAmqpErrors(error);\n }\n }\n\n async function consumeOne(queue, toRecord) {\n debug(`Prepared to consumeOne from queue: ${queue}`);\n try {\n await channel.assertQueue(queue, {durable: true});\n\n // Returns false if 0 items in queue\n const message = await channel.get(queue);\n\n debugData(`Message: ${inspect(message, {colors: true, maxArrayLength: 3, depth: 3})}`);\n // Do not spam the logs\n debug(`consumeOne from queue: ${queue} ${toRecord ? 'to records' : 'just the message'}`);\n\n if (message) {\n if (toRecord) {\n const headers = getHeaderInfo(message);\n const records = messagesToRecords([message]);\n return {headers, records, messages: [message]};\n }\n\n return message;\n }\n\n return false;\n } catch (error) {\n handleAmqpErrors(error);\n }\n }\n\n function ackMessages(messages) {\n messages.forEach(message => {\n debug(`Ack message ${message.properties.correlationId}`);\n channel.ack(message);\n });\n }\n\n function nackMessages(messages) {\n messages.forEach(message => {\n debug(`Nack message ${message.properties.correlationId}`);\n channel.nack(message);\n });\n }\n\n async function sendToQueue({queue, correlationId, headers, data}) {\n debug(`sendToQueue`);\n // eslint-disable-next-line no-useless-catch\n try {\n debug(`Queue ${queue}`);\n debug(`CorrelationId ${correlationId}`);\n debugData(`Data ${JSON.stringify(data)}`);\n debug(`Headers ${JSON.stringify(headers)}`);\n\n errorUndefinedQueue(queue);\n\n debug(`Asserting queue: ${queue}`);\n await channel.assertQueue(queue, {durable: true});\n\n debug(`Actually sendToQueue: ${queue}`);\n await channel.sendToQueue(\n queue,\n Buffer.from(JSON.stringify({data})),\n {\n correlationId,\n persistent: true,\n headers\n }\n );\n debug(`Send message for ${correlationId} to queue: ${queue}`);\n\n\n } catch (error) {\n const errorToThrow = error;\n //if (error instanceof ApiError) {\n // throw error;\n //}\n debug(`SendToQueue errored: ${JSON.stringify(error)}`);\n handleAmqpErrors(errorToThrow);\n }\n }\n\n async function removeQueue(queue) {\n // deleteQueue borks the channel if the queue does not exist\n // -> use throwaway tempChannel to avoid killing actual channel in use\n // this might be doable also with assertQueue before deleteQueue\n const tempChannel = await connection.createChannel();\n logger.verbose(`Removing queue ${queue}.`);\n debug(`Removing queue ${queue}.`);\n await tempChannel.deleteQueue(queue);\n\n if (tempChannel) {\n await tempChannel.close();\n return;\n }\n\n return;\n }\n\n // ----------------\n // Helper functions\n // ----------------\n\n function messagesToRecords(messages) {\n debug(`Parsing messages (${messages.length}) to records`);\n\n return messages.map(message => {\n const content = JSON.parse(message.content.toString());\n // Should we have here validationOptions\n return new MarcRecord(content.data);\n });\n }\n\n async function getData(queue) {\n debug(`Getting queue data from ${queue}`);\n try {\n const {messageCount} = await channel.checkQueue(queue);\n debug(`There is ${messageCount} messages in queue ${queue}`);\n const messagesToGet = messageCount >= CHUNK_SIZE ? CHUNK_SIZE : messageCount;\n debug(`Getting ${messagesToGet} messages from queue ${queue}`);\n\n const messages = await pump(messagesToGet);\n\n debug(`Returning ${messages.length} unique messages`);\n\n return messages;\n } catch (error) {\n handleAmqpErrors(error);\n }\n\n async function pump(count, results = [], identifiers = []) {\n if (count === 0) {\n return results;\n }\n\n const message = await channel.get(queue);\n const identifier = {\n correlationId: message.properties.correlationId,\n deliveryTag: message.fields.deliveryTag\n };\n // Filter not unique messages\n if (identifiers.includes(identifier)) {\n return pump(count - 1, results, identifiers);\n }\n\n return pump(count - 1, results.concat(message), identifiers.concat(identifier));\n }\n }\n\n function getHeaderInfo(data) {\n return data.properties.headers;\n }\n\n function errorUndefinedQueue(queue) {\n if (queue === undefined || queue === '' || queue === null) {\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, `Undefined queue!`);\n }\n }\n\n function handleAmqpErrors(error) {\n const newError = error;\n debug(`HandleAmqpErrors got an error: ${JSON.stringify(error)}`);\n if (error instanceof ApiError) {\n debug(`We have an ApiError`);\n throw new ApiError(newError.status, newError.payload);\n }\n debug(`We have a non-ApiError`);\n logError(error);\n throw newError;\n }\n}\n\n\n"],"mappings":";;;;;;;AA4BA,IAAAA,QAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,eAAA,GAAAF,OAAA;AACA,IAAAG,sBAAA,GAAAH,OAAA;AACA,IAAAI,MAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,UAAA,GAAAL,OAAA;AACA,IAAAM,KAAA,GAAAN,OAAA;AACA,IAAAO,WAAA,GAAAR,sBAAA,CAAAC,OAAA;AACA,IAAAQ,MAAA,GAAAR,OAAA;AApCA;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;;AAYe,eAAAS,SAAgBC,QAAQ,EAAEC,cAAc,GAAG,KAAK,EAAE;EAC/D,MAAMC,MAAM,GAAG,IAAAC,mCAAY,EAAC,CAAC;EAC7B,MAAMC,KAAK,GAAG,IAAAC,cAAiB,EAAC,yCAAyC,CAAC;EAC1E,MAAMC,OAAO,GAAGF,KAAK,CAACG,MAAM,CAAC,IAAI,CAAC;EAClC,MAAMC,SAAS,GAAGJ,KAAK,CAACG,MAAM,CAAC,MAAM,CAAC;EAEtCH,KAAK,CAAE,gCAA+BJ,QAAS,EAAC,CAAC;EACjD,MAAMS,UAAU,GAAG,MAAMC,gBAAO,CAACC,OAAO,CAACX,QAAQ,CAAC;EAClD,MAAMY,OAAO,GAAG,MAAMH,UAAU,CAACI,aAAa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qB,EAAG,kBAAiB,CAAC;IAC1E;EACF;EAEA,SAASb,gBAAgBA,CAACH,KAAK,EAAE;IAC/B,MAAM0D,QAAQ,GAAG1D,KAAK;IACtB7B,KAAK,CAAE,kCAAiC8B,IAAI,CAACC,SAAS,CAACF,KAAK,CAAE,EAAC,CAAC;IAChE,IAAIA,KAAK,YAAYc,qBAAQ,EAAE;MAC7B3C,KAAK,CAAE,qBAAoB,CAAC;MAC5B,MAAM,IAAI2C,qBAAQ,CAAC4C,QAAQ,CAACC,MAAM,EAAED,QAAQ,CAACE,OAAO,CAAC;IACvD;IACAzF,KAAK,CAAE,wBAAuB,CAAC;IAC/B,IAAA0F,eAAQ,EAAC7D,KAAK,CAAC;IACf,MAAM0D,QAAQ;EAChB;AACF"}
|
|
1
|
+
{"version":3,"file":"amqp.js","names":["_amqplib","_interopRequireDefault","require","_marcRecord","_melindaCommons","_melindaBackendCommons","_debug","_constants","_util","_httpStatus","_utils","_default","AMQP_URL","runHealthCheck","logger","createLogger","debug","createDebugLogger","debugHC","extend","debugData","connection","amqplib","connect","channel","createChannel","healthCheckLoop","healthCheck","checkQueue","consumeChunk","consumeOne","ackMessages","nackMessages","sendToQueue","removeQueue","messagesToRecords","closeChannel","closeConnection","close","wait","setTimeoutPromise","promisify","setTimeout","assertQueue","durable","error","JSON","stringify","handleAmqpErrors","queue","style","toRecord","purge","errorUndefinedQueue","channelInfo","purgeQueue","verbose","messageCount","checkMessageCount","ApiError","httpStatus","INTERNAL_SERVER_ERROR","messages","getData","headers","getHeaderInfo","length","records","message","get","inspect","colors","maxArrayLength","depth","forEach","properties","correlationId","ack","nack","data","Buffer","from","persistent","errorToThrow","tempChannel","deleteQueue","map","content","parse","toString","MarcRecord","subfieldValues","messagesToGet","CHUNK_SIZE","pump","count","results","identifiers","identifier","deliveryTag","fields","includes","concat","undefined","newError","status","payload","logError"],"sources":["../src/amqp.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 amqplib from 'amqplib';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport {Error as ApiError} from '@natlibfi/melinda-commons';\nimport {createLogger} from '@natlibfi/melinda-backend-commons';\nimport createDebugLogger from 'debug';\nimport {CHUNK_SIZE} from './constants';\nimport {promisify, inspect} from 'util';\nimport httpStatus from 'http-status';\nimport {logError} from './utils';\n\nexport default async function (AMQP_URL, runHealthCheck = false) {\n const logger = createLogger();\n const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons:amqp');\n const debugHC = debug.extend('HC');\n const debugData = debug.extend('data');\n\n debug(`Creating an AMQP operator to ${AMQP_URL}`);\n const connection = await amqplib.connect(AMQP_URL);\n const channel = await connection.createChannel();\n\n const healthCheckLoop = runHealthCheck ? healthCheck() : false;\n\n debug(`Connection: ${connection}`);\n debug(`Channel: ${channel}`);\n debug(`HealthCheckLoop: ${healthCheckLoop ? 'Running health check' : 'Not running health check'}`);\n\n return {checkQueue, consumeChunk, consumeOne, ackMessages, nackMessages, sendToQueue, removeQueue, messagesToRecords, closeChannel, closeConnection};\n\n async function closeChannel() {\n debug(`Closing channel`);\n await channel.close();\n debug(`Channel: ${channel}`);\n }\n\n async function closeConnection() {\n debug(`Closing connection`);\n await connection.close();\n debug(`Connection: ${connection}`);\n }\n\n async function healthCheck(wait = false) {\n const setTimeoutPromise = promisify(setTimeout);\n if (wait) {\n await setTimeoutPromise(wait);\n return healthCheck(false);\n }\n\n try {\n debugHC(`Health checking amqp by asserting a queue`);\n await channel.assertQueue('HEALTHCHECK', {durable: false});\n debugHC(`Waiting 200ms before running healthCheck next`);\n return healthCheck('200');\n } catch (error) {\n debugHC(`HealthCheck error ${JSON.stringify(error)}`);\n handleAmqpErrors(error);\n }\n }\n\n // eslint-disable-next-line max-statements\n async function checkQueue({queue, style = 'basic', toRecord = true, purge = false}) {\n debug(`checkQueue: ${queue}, Style: ${style}, toRecord: ${toRecord}, Purge: ${purge}`);\n\n try {\n\n errorUndefinedQueue(queue);\n const channelInfo = await channel.assertQueue(queue, {durable: true});\n\n if (purge) {\n await purgeQueue(purge);\n logger.verbose(`Queue ${queue} has purged ${channelInfo.messageCount} messages`);\n debug(`Queue ${queue} has purged ${channelInfo.messageCount} messages`);\n return checkQueue({queue, style});\n }\n\n if (style === 'messages') {\n return channelInfo.messageCount;\n }\n\n\n // Note: returns one message (+ record, of toRecord: true)\n // note: if toRecord is false returns just plain message / false\n // note: if toRecord is true returns {headers, records, messages} -object / false\n // should this be more consistent?\n if (style === 'one') {\n if (checkMessageCount(channelInfo)) {\n return consumeOne(queue, toRecord);\n }\n return false;\n }\n\n // Note: returns a chunk of (100) messages (+ records, if toRecord: true)\n // returns {headers, records, messages} object or {headers, messages} object depending on toRecord\n if (style === 'basic') {\n if (checkMessageCount(channelInfo)) {\n return consumeChunk(queue, toRecord);\n }\n return false;\n }\n\n // Defaults:\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, `CheckQueue does not recognize style ${style}`);\n } catch (error) {\n handleAmqpErrors(error);\n }\n\n function checkMessageCount(channelInfo) {\n if (channelInfo.messageCount < 1) {\n debug(`checkQueue: ${channelInfo.messageCount} - ${queue} is empty`);\n return false;\n }\n debug(`Queue ${queue} has ${channelInfo.messageCount} messages`);\n return true;\n }\n\n function purgeQueue(purge) {\n debug(`Purging queue: ${queue}, purge: ${purge}`);\n if (purge) {\n return channel.purgeQueue(queue);\n }\n }\n }\n\n async function consumeChunk(queue, toRecord) {\n debug(`Prepared to consumeChunk from queue: ${queue}`);\n try {\n await channel.assertQueue(queue, {durable: true});\n\n // getData: next chunk (100) messages\n const messages = await getData(queue);\n\n // Note: headers are from the first message of the chunk\n const headers = getHeaderInfo(messages[0]);\n debug(`consumeChunk (${messages ? messages.length : '0'} from queue ${queue}) ${toRecord ? 'to records' : 'just messages'}`);\n\n if (toRecord) {\n const records = await messagesToRecords(messages);\n return {headers, records, messages};\n }\n\n return {headers, messages};\n } catch (error) {\n handleAmqpErrors(error);\n }\n }\n\n async function consumeOne(queue, toRecord) {\n debug(`Prepared to consumeOne from queue: ${queue}`);\n try {\n await channel.assertQueue(queue, {durable: true});\n\n // Returns false if 0 items in queue\n const message = await channel.get(queue);\n\n debugData(`Message: ${inspect(message, {colors: true, maxArrayLength: 3, depth: 3})}`);\n // Do not spam the logs\n debug(`consumeOne from queue: ${queue} ${toRecord ? 'to records' : 'just the message'}`);\n\n if (message) {\n if (toRecord) {\n const headers = getHeaderInfo(message);\n const records = messagesToRecords([message]);\n return {headers, records, messages: [message]};\n }\n\n return message;\n }\n\n return false;\n } catch (error) {\n handleAmqpErrors(error);\n }\n }\n\n function ackMessages(messages) {\n messages.forEach(message => {\n debug(`Ack message ${message.properties.correlationId}`);\n channel.ack(message);\n });\n }\n\n function nackMessages(messages) {\n messages.forEach(message => {\n debug(`Nack message ${message.properties.correlationId}`);\n channel.nack(message);\n });\n }\n\n async function sendToQueue({queue, correlationId, headers, data}) {\n debug(`sendToQueue`);\n // eslint-disable-next-line no-useless-catch\n try {\n debug(`Queue ${queue}`);\n debug(`CorrelationId ${correlationId}`);\n debugData(`Data ${JSON.stringify(data)}`);\n debug(`Headers ${JSON.stringify(headers)}`);\n\n errorUndefinedQueue(queue);\n\n debug(`Asserting queue: ${queue}`);\n await channel.assertQueue(queue, {durable: true});\n\n debug(`Actually sendToQueue: ${queue}`);\n await channel.sendToQueue(\n queue,\n Buffer.from(JSON.stringify({data})),\n {\n correlationId,\n persistent: true,\n headers\n }\n );\n debug(`Send message for ${correlationId} to queue: ${queue}`);\n\n\n } catch (error) {\n const errorToThrow = error;\n //if (error instanceof ApiError) {\n // throw error;\n //}\n debug(`SendToQueue errored: ${JSON.stringify(error)}`);\n handleAmqpErrors(errorToThrow);\n }\n }\n\n async function removeQueue(queue) {\n // deleteQueue borks the channel if the queue does not exist\n // -> use throwaway tempChannel to avoid killing actual channel in use\n // this might be doable also with assertQueue before deleteQueue\n const tempChannel = await connection.createChannel();\n logger.verbose(`Removing queue ${queue}.`);\n debug(`Removing queue ${queue}.`);\n await tempChannel.deleteQueue(queue);\n\n if (tempChannel) {\n await tempChannel.close();\n return;\n }\n\n return;\n }\n\n // ----------------\n // Helper functions\n // ----------------\n\n function messagesToRecords(messages) {\n debug(`Parsing messages (${messages.length}) to records`);\n\n return messages.map(message => {\n const content = JSON.parse(message.content.toString());\n // Use subfieldValues: false validationOption here\n return new MarcRecord(content.data, {subfieldValues: false});\n });\n }\n\n async function getData(queue) {\n debug(`Getting queue data from ${queue}`);\n try {\n const {messageCount} = await channel.checkQueue(queue);\n debug(`There is ${messageCount} messages in queue ${queue}`);\n const messagesToGet = messageCount >= CHUNK_SIZE ? CHUNK_SIZE : messageCount;\n debug(`Getting ${messagesToGet} messages from queue ${queue}`);\n\n const messages = await pump(messagesToGet);\n\n debug(`Returning ${messages.length} unique messages`);\n\n return messages;\n } catch (error) {\n handleAmqpErrors(error);\n }\n\n async function pump(count, results = [], identifiers = []) {\n if (count === 0) {\n return results;\n }\n\n const message = await channel.get(queue);\n const identifier = {\n correlationId: message.properties.correlationId,\n deliveryTag: message.fields.deliveryTag\n };\n // Filter not unique messages\n if (identifiers.includes(identifier)) {\n return pump(count - 1, results, identifiers);\n }\n\n return pump(count - 1, results.concat(message), identifiers.concat(identifier));\n }\n }\n\n function getHeaderInfo(data) {\n return data.properties.headers;\n }\n\n function errorUndefinedQueue(queue) {\n if (queue === undefined || queue === '' || queue === null) {\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, `Undefined queue!`);\n }\n }\n\n function handleAmqpErrors(error) {\n const newError = error;\n debug(`HandleAmqpErrors got an error: ${JSON.stringify(error)}`);\n if (error instanceof ApiError) {\n debug(`We have an ApiError`);\n throw new ApiError(newError.status, newError.payload);\n }\n debug(`We have a non-ApiError`);\n logError(error);\n throw newError;\n }\n}\n\n\n"],"mappings":";;;;;;;AA4BA,IAAAA,QAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,eAAA,GAAAF,OAAA;AACA,IAAAG,sBAAA,GAAAH,OAAA;AACA,IAAAI,MAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,UAAA,GAAAL,OAAA;AACA,IAAAM,KAAA,GAAAN,OAAA;AACA,IAAAO,WAAA,GAAAR,sBAAA,CAAAC,OAAA;AACA,IAAAQ,MAAA,GAAAR,OAAA;AApCA;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;;AAYe,eAAAS,SAAgBC,QAAQ,EAAEC,cAAc,GAAG,KAAK,EAAE;EAC/D,MAAMC,MAAM,GAAG,IAAAC,mCAAY,EAAC,CAAC;EAC7B,MAAMC,KAAK,GAAG,IAAAC,cAAiB,EAAC,yCAAyC,CAAC;EAC1E,MAAMC,OAAO,GAAGF,KAAK,CAACG,MAAM,CAAC,IAAI,CAAC;EAClC,MAAMC,SAAS,GAAGJ,KAAK,CAACG,MAAM,CAAC,MAAM,CAAC;EAEtCH,KAAK,CAAE,gCAA+BJ,QAAS,EAAC,CAAC;EACjD,MAAMS,UAAU,GAAG,MAAMC,gBAAO,CAACC,OAAO,CAACX,QAAQ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KAAK,EAAE,IAAIA,KAAK,KAAK,IAAI,EAAE;MACzD,MAAM,IAAIU,qBAAQ,CAACC,mBAAU,CAACC,qBAAqB,EAAG,kBAAiB,CAAC;IAC1E;EACF;EAEA,SAASb,gBAAgBA,CAACH,KAAK,EAAE;IAC/B,MAAM2D,QAAQ,GAAG3D,KAAK;IACtB7B,KAAK,CAAE,kCAAiC8B,IAAI,CAACC,SAAS,CAACF,KAAK,CAAE,EAAC,CAAC;IAChE,IAAIA,KAAK,YAAYc,qBAAQ,EAAE;MAC7B3C,KAAK,CAAE,qBAAoB,CAAC;MAC5B,MAAM,IAAI2C,qBAAQ,CAAC6C,QAAQ,CAACC,MAAM,EAAED,QAAQ,CAACE,OAAO,CAAC;IACvD;IACA1F,KAAK,CAAE,wBAAuB,CAAC;IAC/B,IAAA2F,eAAQ,EAAC9D,KAAK,CAAC;IACf,MAAM2D,QAAQ;EAChB;AACF"}
|
package/dist/constants.js
CHANGED
|
@@ -34,7 +34,7 @@ exports.QUEUE_ITEM_STATE = exports.OPERATIONS = exports.LOG_ITEM_TYPE = exports.
|
|
|
34
34
|
|
|
35
35
|
// QueueItemState flows: see README.md
|
|
36
36
|
|
|
37
|
-
const QUEUE_ITEM_STATE =
|
|
37
|
+
const QUEUE_ITEM_STATE = {
|
|
38
38
|
VALIDATOR: {
|
|
39
39
|
PENDING_QUEUING: 'PENDING_QUEUING',
|
|
40
40
|
PENDING_VALIDATION: 'PENDING_VALIDATION',
|
|
@@ -52,7 +52,8 @@ const QUEUE_ITEM_STATE = exports.QUEUE_ITEM_STATE = {
|
|
|
52
52
|
ERROR: 'ERROR',
|
|
53
53
|
ABORT: 'ABORT'
|
|
54
54
|
};
|
|
55
|
-
|
|
55
|
+
exports.QUEUE_ITEM_STATE = QUEUE_ITEM_STATE;
|
|
56
|
+
const IMPORT_JOB_STATE = {
|
|
56
57
|
EMPTY: 'EMPTY',
|
|
57
58
|
QUEUING: 'QUEUING',
|
|
58
59
|
IN_QUEUE: 'IN_QUEUE',
|
|
@@ -62,25 +63,30 @@ const IMPORT_JOB_STATE = exports.IMPORT_JOB_STATE = {
|
|
|
62
63
|
ERROR: 'ERROR',
|
|
63
64
|
ABORT: 'ABORT'
|
|
64
65
|
};
|
|
65
|
-
|
|
66
|
+
exports.IMPORT_JOB_STATE = IMPORT_JOB_STATE;
|
|
67
|
+
const OPERATIONS = {
|
|
66
68
|
CREATE: 'CREATE',
|
|
67
69
|
UPDATE: 'UPDATE'
|
|
68
70
|
};
|
|
69
|
-
|
|
71
|
+
exports.OPERATIONS = OPERATIONS;
|
|
72
|
+
const CHUNK_SIZE = 100;
|
|
70
73
|
|
|
71
74
|
// We could configure here whether a logItemType is for a several records of a single record
|
|
72
75
|
// ie. whether is has bulkSequence or bulkSequenceStart & bulkSequenceEnd
|
|
73
|
-
|
|
76
|
+
exports.CHUNK_SIZE = CHUNK_SIZE;
|
|
77
|
+
const LOG_ITEM_TYPE = {
|
|
74
78
|
INPUT_RECORD_LOG: 'INPUT_RECORD_LOG',
|
|
75
79
|
MERGE_LOG: 'MERGE_LOG',
|
|
76
80
|
MATCH_LOG: 'MATCH_LOG',
|
|
77
81
|
RESULT_RECORD_LOG: 'RESULT_RECORD_LOG',
|
|
78
82
|
SPLITTER_LOG: 'SPLITTER_LOG'
|
|
79
83
|
};
|
|
80
|
-
|
|
84
|
+
exports.LOG_ITEM_TYPE = LOG_ITEM_TYPE;
|
|
85
|
+
const CONVERSION_FORMATS = {
|
|
81
86
|
MARCXML: 'MARCXML',
|
|
82
87
|
ISO2709: 'ISO2709',
|
|
83
88
|
JSON: 'JSON',
|
|
84
89
|
ALEPHSEQ: 'ALEPHSEQ'
|
|
85
90
|
};
|
|
91
|
+
exports.CONVERSION_FORMATS = CONVERSION_FORMATS;
|
|
86
92
|
//# sourceMappingURL=constants.js.map
|
package/dist/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","names":["QUEUE_ITEM_STATE","
|
|
1
|
+
{"version":3,"file":"constants.js","names":["QUEUE_ITEM_STATE","VALIDATOR","PENDING_QUEUING","PENDING_VALIDATION","QUEUING_IN_PROGRESS","UPLOADING","VALIDATING","WAITING_FOR_RECORDS","IMPORTER","IMPORTING","IN_PROCESS","IN_QUEUE","DONE","ERROR","ABORT","exports","IMPORT_JOB_STATE","EMPTY","QUEUING","PROCESSING","OPERATIONS","CREATE","UPDATE","CHUNK_SIZE","LOG_ITEM_TYPE","INPUT_RECORD_LOG","MERGE_LOG","MATCH_LOG","RESULT_RECORD_LOG","SPLITTER_LOG","CONVERSION_FORMATS","MARCXML","ISO2709","JSON","ALEPHSEQ"],"sources":["../src/constants.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Shared modules for microservices of Melinda rest api batch import system\n*\n* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-rest-api-commons\n*\n* melinda-rest-api-commons program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Affero General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-rest-api-commons is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Affero General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\n// QueueItemState flows: see README.md\n\nexport const QUEUE_ITEM_STATE = {\n VALIDATOR: {\n PENDING_QUEUING: 'PENDING_QUEUING',\n PENDING_VALIDATION: 'PENDING_VALIDATION',\n QUEUING_IN_PROGRESS: 'QUEUING_IN_PROGRESS',\n UPLOADING: 'UPLOADING',\n VALIDATING: 'VALIDATING',\n WAITING_FOR_RECORDS: 'WAITING_FOR_RECORDS'\n },\n IMPORTER: {\n IMPORTING: 'IMPORTING',\n IN_PROCESS: 'IN_PROCESS',\n IN_QUEUE: 'IN_QUEUE'\n },\n DONE: 'DONE',\n ERROR: 'ERROR',\n ABORT: 'ABORT'\n};\n\nexport const IMPORT_JOB_STATE = {\n EMPTY: 'EMPTY',\n QUEUING: 'QUEUING',\n IN_QUEUE: 'IN_QUEUE',\n IMPORTING: 'IMPORTING',\n PROCESSING: 'PROCESSING',\n DONE: 'DONE',\n ERROR: 'ERROR',\n ABORT: 'ABORT'\n};\n\nexport const OPERATIONS = {\n CREATE: 'CREATE',\n UPDATE: 'UPDATE'\n};\n\nexport const CHUNK_SIZE = 100;\n\n// We could configure here whether a logItemType is for a several records of a single record\n// ie. whether is has bulkSequence or bulkSequenceStart & bulkSequenceEnd\nexport const LOG_ITEM_TYPE = {\n INPUT_RECORD_LOG: 'INPUT_RECORD_LOG',\n MERGE_LOG: 'MERGE_LOG',\n MATCH_LOG: 'MATCH_LOG',\n RESULT_RECORD_LOG: 'RESULT_RECORD_LOG',\n SPLITTER_LOG: 'SPLITTER_LOG'\n};\n\nexport const CONVERSION_FORMATS = {\n MARCXML: 'MARCXML',\n ISO2709: 'ISO2709',\n JSON: 'JSON',\n ALEPHSEQ: 'ALEPHSEQ'\n};\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEO,MAAMA,gBAAgB,GAAG;EAC9BC,SAAS,EAAE;IACTC,eAAe,EAAE,iBAAiB;IAClCC,kBAAkB,EAAE,oBAAoB;IACxCC,mBAAmB,EAAE,qBAAqB;IAC1CC,SAAS,EAAE,WAAW;IACtBC,UAAU,EAAE,YAAY;IACxBC,mBAAmB,EAAE;EACvB,CAAC;EACDC,QAAQ,EAAE;IACRC,SAAS,EAAE,WAAW;IACtBC,UAAU,EAAE,YAAY;IACxBC,QAAQ,EAAE;EACZ,CAAC;EACDC,IAAI,EAAE,MAAM;EACZC,KAAK,EAAE,OAAO;EACdC,KAAK,EAAE;AACT,CAAC;AAACC,OAAA,CAAAf,gBAAA,GAAAA,gBAAA;AAEK,MAAMgB,gBAAgB,GAAG;EAC9BC,KAAK,EAAE,OAAO;EACdC,OAAO,EAAE,SAAS;EAClBP,QAAQ,EAAE,UAAU;EACpBF,SAAS,EAAE,WAAW;EACtBU,UAAU,EAAE,YAAY;EACxBP,IAAI,EAAE,MAAM;EACZC,KAAK,EAAE,OAAO;EACdC,KAAK,EAAE;AACT,CAAC;AAACC,OAAA,CAAAC,gBAAA,GAAAA,gBAAA;AAEK,MAAMI,UAAU,GAAG;EACxBC,MAAM,EAAE,QAAQ;EAChBC,MAAM,EAAE;AACV,CAAC;AAACP,OAAA,CAAAK,UAAA,GAAAA,UAAA;AAEK,MAAMG,UAAU,GAAG,GAAG;;AAE7B;AACA;AAAAR,OAAA,CAAAQ,UAAA,GAAAA,UAAA;AACO,MAAMC,aAAa,GAAG;EAC3BC,gBAAgB,EAAE,kBAAkB;EACpCC,SAAS,EAAE,WAAW;EACtBC,SAAS,EAAE,WAAW;EACtBC,iBAAiB,EAAE,mBAAmB;EACtCC,YAAY,EAAE;AAChB,CAAC;AAACd,OAAA,CAAAS,aAAA,GAAAA,aAAA;AAEK,MAAMM,kBAAkB,GAAG;EAChCC,OAAO,EAAE,SAAS;EAClBC,OAAO,EAAE,SAAS;EAClBC,IAAI,EAAE,MAAM;EACZC,QAAQ,EAAE;AACZ,CAAC;AAACnB,OAAA,CAAAe,kBAAA,GAAAA,kBAAA"}
|
|
@@ -33,13 +33,14 @@ exports.REPLACE_PREFIXES = exports.BIB_STRIP_F884S_SETTINGS = exports.BIB_PREVAL
|
|
|
33
33
|
*/
|
|
34
34
|
|
|
35
35
|
// This could be formatted so that 035-prefix and SID contents would be better connected than by just an array index
|
|
36
|
-
const BIB_F035_TO_SID =
|
|
36
|
+
const BIB_F035_TO_SID = {
|
|
37
37
|
f035Filters: [/^\(FI-BTJ\)/u, /^\(FI-TATI\)/u],
|
|
38
38
|
fSIDFilters: ['FI-BTJ', 'tati']
|
|
39
39
|
};
|
|
40
40
|
|
|
41
41
|
// There is somewhere other implementations of this same standardPrefixes to alephInternalPrefixes normalization
|
|
42
|
-
|
|
42
|
+
exports.BIB_F035_TO_SID = BIB_F035_TO_SID;
|
|
43
|
+
const REPLACE_PREFIXES = [{
|
|
43
44
|
oldPrefix: 'FI-MELINDA',
|
|
44
45
|
newPrefix: 'FIN01',
|
|
45
46
|
prefixReplaceCodes: ['w']
|
|
@@ -63,28 +64,35 @@ const REPLACE_PREFIXES = exports.REPLACE_PREFIXES = [{
|
|
|
63
64
|
|
|
64
65
|
// If placed in config.js testing needs envs
|
|
65
66
|
// BIB_FORMAT_SETTINGS is outdated, use other settings instead
|
|
66
|
-
|
|
67
|
-
const BIB_FORMAT_SETTINGS =
|
|
67
|
+
exports.REPLACE_PREFIXES = REPLACE_PREFIXES;
|
|
68
|
+
const BIB_FORMAT_SETTINGS = {
|
|
68
69
|
replacePrefixes: REPLACE_PREFIXES,
|
|
69
70
|
generateMissingSIDs: BIB_F035_TO_SID
|
|
70
71
|
};
|
|
71
|
-
|
|
72
|
+
exports.BIB_FORMAT_SETTINGS = BIB_FORMAT_SETTINGS;
|
|
73
|
+
const BIB_PREVALIDATION_FIX_SETTINGS = {
|
|
72
74
|
generateMissingSIDs: BIB_F035_TO_SID
|
|
73
75
|
};
|
|
74
|
-
|
|
76
|
+
exports.BIB_PREVALIDATION_FIX_SETTINGS = BIB_PREVALIDATION_FIX_SETTINGS;
|
|
77
|
+
const BIB_POSTMERGE_FIX_SETTINGS = {
|
|
75
78
|
handleTempUrns: true,
|
|
76
79
|
stripF884s: true
|
|
77
80
|
};
|
|
78
|
-
|
|
81
|
+
exports.BIB_POSTMERGE_FIX_SETTINGS = BIB_POSTMERGE_FIX_SETTINGS;
|
|
82
|
+
const BIB_PREIMPORT_FIX_SETTINGS = {
|
|
79
83
|
replacePrefixes: REPLACE_PREFIXES
|
|
80
84
|
};
|
|
81
|
-
|
|
85
|
+
exports.BIB_PREIMPORT_FIX_SETTINGS = BIB_PREIMPORT_FIX_SETTINGS;
|
|
86
|
+
const AUTNAME_PREIMPORT_FIX_SETTINGS = {
|
|
82
87
|
replacePrefixes: REPLACE_PREFIXES
|
|
83
88
|
};
|
|
84
|
-
|
|
89
|
+
exports.AUTNAME_PREIMPORT_FIX_SETTINGS = AUTNAME_PREIMPORT_FIX_SETTINGS;
|
|
90
|
+
const BIB_HANDLE_TEMP_URNS_SETTINGS = {
|
|
85
91
|
handleTempUrns: true
|
|
86
92
|
};
|
|
87
|
-
|
|
93
|
+
exports.BIB_HANDLE_TEMP_URNS_SETTINGS = BIB_HANDLE_TEMP_URNS_SETTINGS;
|
|
94
|
+
const BIB_STRIP_F884S_SETTINGS = {
|
|
88
95
|
stripF884s: true
|
|
89
96
|
};
|
|
97
|
+
exports.BIB_STRIP_F884S_SETTINGS = BIB_STRIP_F884S_SETTINGS;
|
|
90
98
|
//# sourceMappingURL=fix-constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fix-constants.js","names":["BIB_F035_TO_SID","
|
|
1
|
+
{"version":3,"file":"fix-constants.js","names":["BIB_F035_TO_SID","f035Filters","fSIDFilters","exports","REPLACE_PREFIXES","oldPrefix","newPrefix","prefixReplaceCodes","BIB_FORMAT_SETTINGS","replacePrefixes","generateMissingSIDs","BIB_PREVALIDATION_FIX_SETTINGS","BIB_POSTMERGE_FIX_SETTINGS","handleTempUrns","stripF884s","BIB_PREIMPORT_FIX_SETTINGS","AUTNAME_PREIMPORT_FIX_SETTINGS","BIB_HANDLE_TEMP_URNS_SETTINGS","BIB_STRIP_F884S_SETTINGS"],"sources":["../../src/helpers/fix-constants.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Shared modules for microservices of Melinda rest api batch import system\n*\n* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-rest-api-commons\n*\n* melinda-rest-api-commons program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Affero General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-rest-api-commons is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Affero General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\n// This could be formatted so that 035-prefix and SID contents would be better connected than by just an array index\nexport const BIB_F035_TO_SID = {\n f035Filters: [/^\\(FI-BTJ\\)/u, /^\\(FI-TATI\\)/u],\n fSIDFilters: ['FI-BTJ', 'tati']\n};\n\n// There is somewhere other implementations of this same standardPrefixes to alephInternalPrefixes normalization\nexport const REPLACE_PREFIXES = [\n {\n oldPrefix: 'FI-MELINDA',\n newPrefix: 'FIN01',\n prefixReplaceCodes: ['w']\n },\n {\n oldPrefix: 'FI-ASTERI-S',\n newPrefix: 'FIN10',\n prefixReplaceCodes: ['0']\n },\n {\n oldPrefix: 'FI-ASTERI-N',\n newPrefix: 'FIN11',\n prefixReplaceCodes: ['0']\n },\n {\n oldPrefix: 'FI-ASTERI-A',\n newPrefix: 'FIN12',\n prefixReplaceCodes: ['0']\n },\n {\n oldPrefix: 'FI-ASTERI-W',\n newPrefix: 'FIN13',\n prefixReplaceCodes: ['0']\n }\n];\n\n\n// If placed in config.js testing needs envs\n// BIB_FORMAT_SETTINGS is outdated, use other settings instead\n\n\nexport const BIB_FORMAT_SETTINGS = {\n replacePrefixes: REPLACE_PREFIXES,\n generateMissingSIDs: BIB_F035_TO_SID\n};\n\nexport const BIB_PREVALIDATION_FIX_SETTINGS = {\n generateMissingSIDs: BIB_F035_TO_SID\n};\n\nexport const BIB_POSTMERGE_FIX_SETTINGS = {\n handleTempUrns: true,\n stripF884s: true\n};\n\nexport const BIB_PREIMPORT_FIX_SETTINGS = {\n replacePrefixes: REPLACE_PREFIXES\n};\n\nexport const AUTNAME_PREIMPORT_FIX_SETTINGS = {\n replacePrefixes: REPLACE_PREFIXES\n};\n\nexport const BIB_HANDLE_TEMP_URNS_SETTINGS = {\n handleTempUrns: true\n};\n\nexport const BIB_STRIP_F884S_SETTINGS = {\n stripF884s: true\n};\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACO,MAAMA,eAAe,GAAG;EAC7BC,WAAW,EAAE,CAAC,cAAc,EAAE,eAAe,CAAC;EAC9CC,WAAW,EAAE,CAAC,QAAQ,EAAE,MAAM;AAChC,CAAC;;AAED;AAAAC,OAAA,CAAAH,eAAA,GAAAA,eAAA;AACO,MAAMI,gBAAgB,GAAG,CAC9B;EACEC,SAAS,EAAE,YAAY;EACvBC,SAAS,EAAE,OAAO;EAClBC,kBAAkB,EAAE,CAAC,GAAG;AAC1B,CAAC,EACD;EACEF,SAAS,EAAE,aAAa;EACxBC,SAAS,EAAE,OAAO;EAClBC,kBAAkB,EAAE,CAAC,GAAG;AAC1B,CAAC,EACD;EACEF,SAAS,EAAE,aAAa;EACxBC,SAAS,EAAE,OAAO;EAClBC,kBAAkB,EAAE,CAAC,GAAG;AAC1B,CAAC,EACD;EACEF,SAAS,EAAE,aAAa;EACxBC,SAAS,EAAE,OAAO;EAClBC,kBAAkB,EAAE,CAAC,GAAG;AAC1B,CAAC,EACD;EACEF,SAAS,EAAE,aAAa;EACxBC,SAAS,EAAE,OAAO;EAClBC,kBAAkB,EAAE,CAAC,GAAG;AAC1B,CAAC,CACF;;AAGD;AACA;AAAAJ,OAAA,CAAAC,gBAAA,GAAAA,gBAAA;AAGO,MAAMI,mBAAmB,GAAG;EACjCC,eAAe,EAAEL,gBAAgB;EACjCM,mBAAmB,EAAEV;AACvB,CAAC;AAACG,OAAA,CAAAK,mBAAA,GAAAA,mBAAA;AAEK,MAAMG,8BAA8B,GAAG;EAC5CD,mBAAmB,EAAEV;AACvB,CAAC;AAACG,OAAA,CAAAQ,8BAAA,GAAAA,8BAAA;AAEK,MAAMC,0BAA0B,GAAG;EACxCC,cAAc,EAAE,IAAI;EACpBC,UAAU,EAAE;AACd,CAAC;AAACX,OAAA,CAAAS,0BAAA,GAAAA,0BAAA;AAEK,MAAMG,0BAA0B,GAAG;EACxCN,eAAe,EAAEL;AACnB,CAAC;AAACD,OAAA,CAAAY,0BAAA,GAAAA,0BAAA;AAEK,MAAMC,8BAA8B,GAAG;EAC5CP,eAAe,EAAEL;AACnB,CAAC;AAACD,OAAA,CAAAa,8BAAA,GAAAA,8BAAA;AAEK,MAAMC,6BAA6B,GAAG;EAC3CJ,cAAc,EAAE;AAClB,CAAC;AAACV,OAAA,CAAAc,6BAAA,GAAAA,6BAAA;AAEK,MAAMC,wBAAwB,GAAG;EACtCJ,UAAU,EAAE;AACd,CAAC;AAACX,OAAA,CAAAe,wBAAA,GAAAA,wBAAA"}
|
package/dist/helpers/fix.spec.js
CHANGED
|
@@ -8,8 +8,8 @@ var _fixugen = _interopRequireDefault(require("@natlibfi/fixugen"));
|
|
|
8
8
|
var _fix = require("./fix");
|
|
9
9
|
var fixSettings = _interopRequireWildcard(require("./fix-constants"));
|
|
10
10
|
var _debug = _interopRequireDefault(require("debug"));
|
|
11
|
-
function _getRequireWildcardCache(
|
|
12
|
-
function _interopRequireWildcard(
|
|
11
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
12
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
13
13
|
// import inspect from 'util';
|
|
14
14
|
|
|
15
15
|
const debug = (0, _debug.default)('@natlibfi/melinda-rest-api-commons:fix:test');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fix.spec.js","names":["_chai","require","_marcRecord","_fixura","_fixugen","_interopRequireDefault","_fix","fixSettings","_interopRequireWildcard","_debug","_getRequireWildcardCache","
|
|
1
|
+
{"version":3,"file":"fix.spec.js","names":["_chai","require","_marcRecord","_fixura","_fixugen","_interopRequireDefault","_fix","fixSettings","_interopRequireWildcard","_debug","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","debug","createDebugLogger","debugData","extend","generateTests","callback","path","__dirname","recurse","useMetadataFile","fixura","failWhenNotFound","reader","READERS","JSON","getFixture","settings","undefined","Error","runSettings","record","MarcRecord","subfieldValues","expectedRecord","stringify","resultRecord","fixRecord","expect","to","eql"],"sources":["../../src/helpers/fix.spec.js"],"sourcesContent":["import {expect} from 'chai';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport {READERS} from '@natlibfi/fixura';\nimport generateTests from '@natlibfi/fixugen';\nimport {fixRecord} from './fix';\nimport * as fixSettings from './fix-constants';\nimport createDebugLogger from 'debug';\n// import inspect from 'util';\n\nconst debug = createDebugLogger('@natlibfi/melinda-rest-api-commons:fix:test');\nconst debugData = debug.extend('data');\n\ngenerateTests({\n callback,\n path: [__dirname, '..', '..', 'test-fixtures', 'fix'],\n recurse: true,\n useMetadataFile: true,\n fixura: {\n failWhenNotFound: false,\n reader: READERS.JSON\n }\n});\n\nfunction callback({getFixture, settings = undefined}) {\n if (settings !== undefined && fixSettings[settings] === undefined) {\n throw new Error(`There are no settings ${settings} defined!`);\n }\n const runSettings = fixSettings[settings] || settings;\n\n const record = new MarcRecord(getFixture('record.json'), {subfieldValues: false});\n const expectedRecord = getFixture('expectedRecord.json');\n\n debug(`Running fixer with settings ${settings}.`);\n debugData(JSON.stringify(runSettings, null, 2));\n\n const resultRecord = fixRecord(record, runSettings);\n debugData(`Result: ${JSON.stringify(resultRecord)}`);\n debugData(`Expected: ${JSON.stringify(expectedRecord)}`);\n expect(resultRecord).to.eql(expectedRecord);\n\n}\n"],"mappings":";;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAC,sBAAA,CAAAJ,OAAA;AACA,IAAAK,IAAA,GAAAL,OAAA;AACA,IAAAM,WAAA,GAAAC,uBAAA,CAAAP,OAAA;AACA,IAAAQ,MAAA,GAAAJ,sBAAA,CAAAJ,OAAA;AAAsC,SAAAS,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAH,wBAAAO,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAA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Q,GAAGC;AAAS,CAAC,EAAE;EACpD,IAAID,QAAQ,KAAKC,SAAS,IAAI1C,WAAW,CAACyC,QAAQ,CAAC,KAAKC,SAAS,EAAE;IACjE,MAAM,IAAIC,KAAK,CAAE,yBAAwBF,QAAS,WAAU,CAAC;EAC/D;EACA,MAAMG,WAAW,GAAG5C,WAAW,CAACyC,QAAQ,CAAC,IAAIA,QAAQ;EAErD,MAAMI,MAAM,GAAG,IAAIC,sBAAU,CAACN,UAAU,CAAC,aAAa,CAAC,EAAE;IAACO,cAAc,EAAE;EAAK,CAAC,CAAC;EACjF,MAAMC,cAAc,GAAGR,UAAU,CAAC,qBAAqB,CAAC;EAExDf,KAAK,CAAE,+BAA8BgB,QAAS,GAAE,CAAC;EACjDd,SAAS,CAACY,IAAI,CAACU,SAAS,CAACL,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;EAE/C,MAAMM,YAAY,GAAG,IAAAC,cAAS,EAACN,MAAM,EAAED,WAAW,CAAC;EACnDjB,SAAS,CAAE,aAAYY,IAAI,CAACU,SAAS,CAACC,YAAY,CAAE,EAAC,CAAC;EACtDvB,SAAS,CAAE,aAAYY,IAAI,CAACU,SAAS,CAACD,cAAc,CAAE,EAAC,CAAC;EACxD,IAAAI,YAAM,EAACF,YAAY,CAAC,CAACG,EAAE,CAACC,GAAG,CAACN,cAAc,CAAC;AAE7C"}
|
|
@@ -5,8 +5,8 @@ var _chai = require("chai");
|
|
|
5
5
|
var _fixura = _interopRequireWildcard(require("@natlibfi/fixura"));
|
|
6
6
|
var _marcRecord = require("@natlibfi/marc-record");
|
|
7
7
|
var _validation = _interopRequireDefault(require("./validation"));
|
|
8
|
-
function _getRequireWildcardCache(
|
|
9
|
-
function _interopRequireWildcard(
|
|
8
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
9
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
10
10
|
/**
|
|
11
11
|
*
|
|
12
12
|
* @licstart The following is the entire license notice for the JavaScript code in this file.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.spec.js","names":["_chai","require","_fixura","_interopRequireWildcard","_marcRecord","_validation","_interopRequireDefault","_getRequireWildcardCache","
|
|
1
|
+
{"version":3,"file":"validation.spec.js","names":["_chai","require","_fixura","_interopRequireWildcard","_marcRecord","_validation","_interopRequireDefault","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","describe","FIXTURES_PATH","__dirname","getFixture","fixtureFactory","root","reader","READERS","JSON","it","validator","createValidator","record","MarcRecord","components","result","toObject","expected","expect","to","eql","failed","equal"],"sources":["../../src/helpers/validation.spec.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 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 {expect} from 'chai';\nimport fixtureFactory, {READERS} from '@natlibfi/fixura';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport createValidator from './validation';\n\ndescribe('services/validate', () => {\n const FIXTURES_PATH = [\n __dirname,\n '..',\n '..',\n 'test-fixtures',\n 'validation'\n ];\n const {getFixture} = fixtureFactory({root: FIXTURES_PATH, reader: READERS.JSON});\n\n describe('f003-fi-melinda', () => {\n it('Should have failed: false', async () => {\n const validator = await createValidator();\n const record = new MarcRecord(getFixture({\n components: [\n 'in',\n 'f003-fi-melinda.json'\n ]\n }));\n const result = await validator(record.toObject());\n const expected = getFixture({\n components: [\n 'out',\n 'f003-fi-melinda.json'\n ]\n });\n expect(result).to.eql(expected);\n expect(result.failed).to.equal(false);\n });\n });\n\n describe('f003-not-fi-melinda', () => {\n it('Should have failed: true', async () => {\n const validator = await createValidator();\n const record = new MarcRecord(getFixture({\n components: [\n 'in',\n 'f003-not-fi-melinda.json'\n ]\n }));\n const result = await validator(record.toObject());\n const expected = getFixture({\n components: [\n 'out',\n 'f003-not-fi-melinda.json'\n ]\n });\n expect(result).to.eql(expected);\n expect(result.failed).to.equal(true);\n });\n });\n});\n\n"],"mappings":";;;AA4BA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAC,uBAAA,CAAAF,OAAA;AACA,IAAAG,WAAA,GAAAH,OAAA;AACA,IAAAI,WAAA,GAAAC,sBAAA,CAAAL,OA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M,CAACI,QAAQ,CAAC,CAAC,CAAC;MACjD,MAAMC,QAAQ,GAAGd,UAAU,CAAC;QAC1BW,UAAU,EAAE,CACV,KAAK,EACL,0BAA0B;MAE9B,CAAC,CAAC;MACF,IAAAI,YAAM,EAACH,MAAM,CAAC,CAACI,EAAE,CAACC,GAAG,CAACH,QAAQ,CAAC;MAC/B,IAAAC,YAAM,EAACH,MAAM,CAACM,MAAM,CAAC,CAACF,EAAE,CAACG,KAAK,CAAC,IAAI,CAAC;IACtC,CAAC,CAAC;EACJ,CAAC,CAAC;AACJ,CAAC,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -105,6 +105,6 @@ Object.keys(_constants).forEach(function (key) {
|
|
|
105
105
|
}
|
|
106
106
|
});
|
|
107
107
|
});
|
|
108
|
-
function _getRequireWildcardCache(
|
|
109
|
-
function _interopRequireWildcard(
|
|
108
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
109
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
110
110
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_mongo","_interopRequireDefault","require","_mongoLog","_amqp","_conversion","_validation","fixes","_interopRequireWildcard","exports","_utils","_constants","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","defineProperty","enumerable","get","_getRequireWildcardCache","
|
|
1
|
+
{"version":3,"file":"index.js","names":["_mongo","_interopRequireDefault","require","_mongoLog","_amqp","_conversion","_validation","fixes","_interopRequireWildcard","exports","_utils","_constants","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","defineProperty","enumerable","get","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","newObj","hasPropertyDescriptor","getOwnPropertyDescriptor","desc","set"],"sources":["../src/index.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-2021 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 mongoFactory from './mongo';\nimport mongoLogFactory from './mongoLog';\nimport amqpFactory from './amqp';\nimport conversions from './helpers/conversion';\nimport validations from './helpers/validation';\nimport * as fixes from './helpers/fix';\nimport {logError, createImportJobState, createImportJobStateForQuery, createRecordResponseItem, addRecordResponseItem, addRecordResponseItems} from './utils';\n\nexport {mongoFactory, mongoLogFactory, amqpFactory, conversions, validations, fixes, logError, createImportJobState, createImportJobStateForQuery, createRecordResponseItem, addRecordResponseItem, addRecordResponseItems};\nexport * from './constants';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,SAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,KAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,WAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,WAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,KAAA,GAAAC,uBAAA,CAAAN,OAAA;AAAuCO,OAAA,CAAAF,KAAA,GAAAA,KAAA;AACvC,IAAAG,MAAA,GAAAR,OAAA;AAGA,IAAAS,UAAA,GAAAT,OAAA;AAAAU,MAAA,CAAAC,IAAA,CAAAF,UAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAN,OAAA,IAAAA,OAAA,CAAAM,GAAA,MAAAJ,UAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAQ,cAAA,CAAAX,OAAA,EAAAM,GAAA;IAAAM,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAX,UAAA,CAAAI,GAAA;IAAA;EAAA;AAAA;AAA4B,SAAAQ,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAhB,wBAAAoB,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA,EAAAF,GAAA,UAAAG,KAAA,GAAAR,wBAAA,CAAAC,WAAA,OAAAO,KAAA,IAAAA,KAAA,CAAAC,GAAA,CAAAJ,GAAA,YAAAG,KAAA,CAAAT,GAAA,CAAAM,GAAA,SAAAK,MAAA,WAAAC,qBAAA,GAAAtB,MAAA,CAAAQ,cAAA,IAAAR,MAAA,CAAAuB,wBAAA,WAAApB,GAAA,IAAAa,GAAA,QAAAb,GAAA,kBAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAU,GAAA,EAAAb,GAAA,SAAAqB,IAAA,GAAAF,qBAAA,GAAAtB,MAAA,CAAAuB,wBAAA,CAAAP,GAAA,EAAAb,GAAA,cAAAqB,IAAA,KAAAA,IAAA,CAAAd,GAAA,IAAAc,IAAA,CAAAC,GAAA,KAAAzB,MAAA,CAAAQ,cAAA,CAAAa,MAAA,EAAAlB,GAAA,EAAAqB,IAAA,YAAAH,MAAA,CAAAlB,GAAA,IAAAa,GAAA,CAAAb,GAAA,SAAAkB,MAAA,CAAAH,OAAA,GAAAF,GAAA,MAAAG,KAAA,IAAAA,KAAA,CAAAM,GAAA,CAAAT,GAAA,EAAAK,MAAA,YAAAA,MAAA"}
|
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) {
|
|
45
45
|
const logger = (0, _melindaBackendCommons.createLogger)();
|
|
46
46
|
|
|
47
47
|
// Connect to mongo (MONGO)
|
|
@@ -49,14 +49,13 @@ async function _default(MONGO_URI, dbName = 'rest-api') {
|
|
|
49
49
|
useNewUrlParser: true,
|
|
50
50
|
useUnifiedTopology: true
|
|
51
51
|
});
|
|
52
|
-
const db = client.db(
|
|
52
|
+
const db = client.db('rest-api');
|
|
53
53
|
const collection = 'logs';
|
|
54
54
|
return {
|
|
55
55
|
addLogItem,
|
|
56
56
|
query,
|
|
57
57
|
queryById,
|
|
58
58
|
getListOfLogs,
|
|
59
|
-
getCatalogersListOfLogs,
|
|
60
59
|
getExpandedListOfLogs,
|
|
61
60
|
protect,
|
|
62
61
|
remove,
|
|
@@ -70,7 +69,6 @@ async function _default(MONGO_URI, dbName = 'rest-api') {
|
|
|
70
69
|
protected: false
|
|
71
70
|
};
|
|
72
71
|
try {
|
|
73
|
-
console.log(newLogItem); // eslint-disable-line
|
|
74
72
|
checkLogItemType(logItem.logItemType, false);
|
|
75
73
|
const result = await db.collection(collection).insertOne(newLogItem);
|
|
76
74
|
if (result.acknowledged) {
|
|
@@ -81,7 +79,6 @@ async function _default(MONGO_URI, dbName = 'rest-api') {
|
|
|
81
79
|
} = logItem;
|
|
82
80
|
const itemString = blobSequenceStart && blobSequenceEnd ? `${blobSequenceStart} - ${blobSequenceEnd}` : `${blobSequence}`;
|
|
83
81
|
logger.info(`*** New ${logItem.logItemType} added for ${logItem.correlationId}, blobSequence(s): ${itemString}. ***`);
|
|
84
|
-
console.log('addLogItem done', result); // eslint-disable-line
|
|
85
82
|
return;
|
|
86
83
|
}
|
|
87
84
|
throw new _melindaCommons.Error(_httpStatus.default.INTERNAL_SERVER_ERROR);
|
|
@@ -136,27 +133,20 @@ async function _default(MONGO_URI, dbName = 'rest-api') {
|
|
|
136
133
|
payload: result.length > 0 ? result : 'No logs found'
|
|
137
134
|
};
|
|
138
135
|
}
|
|
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
|
-
}
|
|
145
136
|
|
|
146
137
|
// getExpandedListOfLogs returns groped MERGE_LOGs and MATCH_LOGs
|
|
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(`commons: logItemTypes: ${JSON.stringify(logItemTypes)}, dateAfter: ${dateAfter}, dateBefore: ${dateBefore}}, catalogers: ${JSON.stringify(catalogers)}`);
|
|
154
|
-
logger.debug(JSON.stringify(generateMatchObject(logItemTypes, catalogers, dateBefore, dateAfter))); // eslint-disable-line
|
|
138
|
+
async function getExpandedListOfLogs() {
|
|
155
139
|
//checkLogItemType(logItemType, false, false);
|
|
156
140
|
logger.debug(`Getting expanded list of logs`);
|
|
157
141
|
const pipeline = [
|
|
158
142
|
// currently return only MERGE_LOG and MATCH_LOG
|
|
159
|
-
|
|
143
|
+
{
|
|
144
|
+
'$match': {
|
|
145
|
+
'logItemType': {
|
|
146
|
+
'$in': ['MERGE_LOG', 'MATCH_LOG']
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}, {
|
|
160
150
|
'$sort': {
|
|
161
151
|
'correlationId': 1,
|
|
162
152
|
'logItemType': 1,
|
|
@@ -178,12 +168,6 @@ async function _default(MONGO_URI, dbName = 'rest-api') {
|
|
|
178
168
|
'$sum': 1
|
|
179
169
|
}
|
|
180
170
|
}
|
|
181
|
-
}, {
|
|
182
|
-
'$sort': {
|
|
183
|
-
'correlationId': 1,
|
|
184
|
-
'logItemType': 1,
|
|
185
|
-
'creationTime': 1
|
|
186
|
-
}
|
|
187
171
|
}];
|
|
188
172
|
const result = await db.collection(collection) // eslint-disable-line functional/immutable-data
|
|
189
173
|
.aggregate(pipeline).toArray();
|
|
@@ -212,23 +196,6 @@ async function _default(MONGO_URI, dbName = 'rest-api') {
|
|
|
212
196
|
status: fixedResult.length > 0 ? _httpStatus.default.OK : _httpStatus.default.NOT_FOUND,
|
|
213
197
|
payload: fixedResult.length > 0 ? fixedResult : 'No logs found'
|
|
214
198
|
};
|
|
215
|
-
function generateMatchObject(logItemTypes, catalogers, dateBefore, dateAfter) {
|
|
216
|
-
const matchOptions = {
|
|
217
|
-
'$match': {
|
|
218
|
-
'logItemType': logItemTypes.length > 0 ? {
|
|
219
|
-
'$in': logItemTypes
|
|
220
|
-
} : /.*/ui,
|
|
221
|
-
'cataloger': catalogers.length > 0 ? {
|
|
222
|
-
'$in': catalogers
|
|
223
|
-
} : /.*/ui,
|
|
224
|
-
'creationTime': {
|
|
225
|
-
'$gte': new Date(dateAfter).toISOString(),
|
|
226
|
-
'$lte': new Date(dateBefore).toISOString()
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
};
|
|
230
|
-
return matchOptions;
|
|
231
|
-
}
|
|
232
199
|
}
|
|
233
200
|
async function protect(correlationId, blobSequence) {
|
|
234
201
|
logger.info(`Protecting in Mongo (${collection}) correlationId: ${correlationId}, blobSequence: ${blobSequence}`);
|
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': new Date(dateAfter).toISOString(),\n '$lte': new Date(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;IAAEC;EAAiB,CAAC;EAExI,eAAeR,UAAUA,CAACS,OAAO,EAAE;IACjC,MAAMC,IAAI,GAAG,IAAAC,eAAM,EAAC,CAAC,CAACC,MAAM,CAAC,CAAC;IAC9B,MAAMC,UAAU,GAAG;MACjB,GAAGJ,OAAO;M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,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","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"],"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,EAAE;EACxC,MAAMC,MAAM,GAAG,IAAAC,mCAAY,EAAC,CAAC;;EAE7B;EACA,MAAMC,MAAM,GAAG,MAAMC,oBAAW,CAACC,OAAO,CAACL,SAAS,EAAE;IAACM,eAAe,EAAE,IAAI;IAAEC,kBAAkB,EAAE;EAAI,CAAC,CAAC;EACtG,MAAMC,EAAE,GAAGL,MAAM,CAACK,EAAE,CAAC,UAAU,CAAC;EAChC,MAAMC,UAAU,GAAG,MAAM;EACzB,OAAO;IAACC,UAAU;IAAEC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|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
],
|
|
84
|
-
"plugins": [
|
|
85
|
-
[
|
|
86
|
-
"@babel/transform-runtime"
|
|
87
|
-
]
|
|
88
|
-
],
|
|
89
|
-
"env": {
|
|
90
|
-
"test": {
|
|
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.17-alpha.1",
|
|
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": "^8.0.0",
|
|
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
|
+
"babel-plugin-istanbul": "^6.1.1",
|
|
63
|
+
"babel-plugin-rewire": "^1.2.0",
|
|
64
|
+
"chai": "^4.3.8",
|
|
65
|
+
"cross-env": "^7.0.3",
|
|
66
|
+
"eslint": "^8.49.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
|
+
],
|
|
91
83
|
"plugins": [
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
84
|
+
[
|
|
85
|
+
"@babel/transform-runtime"
|
|
86
|
+
]
|
|
87
|
+
],
|
|
88
|
+
"env": {
|
|
89
|
+
"test": {
|
|
90
|
+
"plugins": [
|
|
91
|
+
"istanbul",
|
|
92
|
+
"rewire"
|
|
93
|
+
]
|
|
94
|
+
}
|
|
95
|
+
}
|
|
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
|
|
96
122
|
}
|
|
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
|
-
}
|
|
135
123
|
}
|
package/dist/mongoLog.spec.js
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
var _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
|
|
@@ -1 +0,0 @@
|
|
|
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;EACDC,KAAK,EAAE;IACLC,MAAM,EAAE,MAAAA,CAAA,KAAY;MAClB,MAAMC,iBAAiB,CAAC,CAAC;IAC3B,CAAC;IACDC,UAAU,EAAEA,CAAA,KAAMf,aAAa,CAACgB,KAAK,CAAC,CAAC;IACvCC,SAAS,EAAEA,CAAA,KAAMjB,aAAa,CAACgB,KAAK,CAAC,CAAC;IACtCE,KAAK,EAAE,MAAAA,CAAA,KAAY;MACjB,MAAMlB,aAAa,CAACmB,KAAK,CAAC,CAAC;IAC7B;EACF;AACF,CAAC,CAAC;AAEF,eAAeL,iBAAiBA,CAAA,EAAG;EACjCd,aAAa,GAAG,MAAM,IAAAoB,oBAAoB,EAAC;IACzCC,QAAQ,EAAE,CAACjB,SAAS,EAAE,IAAI,EAAE,eAAe,EAAE,UAAU,CAAC;IACxDkB,MAAM,EAAE;MAACC,UAAU,EAAE;IAAO,CAAC;IAC7BC,WAAW,EAAE,IAAI;IACjBC,MAAM,EAAE;MACNC,YAAY,EAAEC,CAAC,IAAI,IAAIC,IAAI,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