@natlibfi/melinda-rest-api-commons 2.2.0-alpha.7 → 2.3.0-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/dist/amqp.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/amqp.js"],"names":["AMQP_URL","connection","amqplib","connect","channel","createChannel","logger","checkQueue","consumeChunk","consumeOne","ackMessages","nackMessages","sendToQueue","removeQueue","messagesToRecords","queue","style","toRecord","purge","silly","errorUndefinedQueue","channelInfo","assertQueue","durable","purgeQueue","verbose","messageCount","ApiError","httpStatus","UNPROCESSABLE_ENTITY","error","messages","getData","headers","getHeaderInfo","debug","length","records","message","get","colors","maxArrayLength","depth","forEach","properties","correlationId","ack","nack","data","JSON","stringify","Buffer","from","persistent","tempChannel","deleteQueue","close","map","content","parse","toString","MarcRecord","messagesToGet","CHUNK_SIZE","pump","count","results","identifiers","identifier","deliveryTag","fields","includes","concat","undefined","INTERNAL_SERVER_ERROR"],"mappings":";;;;;;;AA4BA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;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,wBAAgBA,QAAhB,EAA0B;AACvC,QAAMC,UAAU,GAAG,MAAMC,iBAAQC,OAAR,CAAgBH,QAAhB,CAAzB;AACA,QAAMI,OAAO,GAAG,MAAMH,UAAU,CAACI,aAAX,EAAtB;AACA,QAAMC,MAAM,GAAG,0CAAf;AAEA,SAAO;AAACC,IAAAA,UAAD;AAAaC,IAAAA,YAAb;AAA2BC,IAAAA,UAA3B;AAAuCC,IAAAA,WAAvC;AAAoDC,IAAAA,YAApD;AAAkEC,IAAAA,WAAlE;AAA+EC,IAAAA,WAA/E;AAA4FC,IAAAA;AAA5F,GAAP,CALuC,CAOvC;;A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OAAOD,KAAP,EAAc;AACd,2BAASA,KAAT;AACD;;AAED,mBAAekC,IAAf,CAAoBC,KAApB,EAA2BC,OAAO,GAAG,EAArC,EAAyCC,WAAW,GAAG,EAAvD,EAA2D;AACzD,UAAIF,KAAK,KAAK,CAAd,EAAiB;AACf,eAAOC,OAAP;AACD;;AAED,YAAM5B,OAAO,GAAG,MAAMlC,OAAO,CAACmC,GAAR,CAAYxB,KAAZ,CAAtB;AACA,YAAMqD,UAAU,GAAG;AACjBvB,QAAAA,aAAa,EAAEP,OAAO,CAACM,UAAR,CAAmBC,aADjB;AAEjBwB,QAAAA,WAAW,EAAE/B,OAAO,CAACgC,MAAR,CAAeD;AAFX,OAAnB,CANyD,CAUzD;;AACA,UAAIF,WAAW,CAACI,QAAZ,CAAqBH,UAArB,CAAJ,EAAsC;AACpC,eAAOJ,IAAI,CAACC,KAAK,GAAG,CAAT,EAAYC,OAAZ,EAAqBC,WAArB,CAAX;AACD;;AAED,aAAOH,IAAI,CAACC,KAAK,GAAG,CAAT,EAAYC,OAAO,CAACM,MAAR,CAAelC,OAAf,CAAZ,EAAqC6B,WAAW,CAACK,MAAZ,CAAmBJ,UAAnB,CAArC,CAAX;AACD;AACF;;AAED,WAASlC,aAAT,CAAuBc,IAAvB,EAA6B;AAC3B,WAAOA,IAAI,CAACJ,UAAL,CAAgBX,OAAvB;AACD;;AAED,WAASb,mBAAT,CAA6BL,KAA7B,EAAoC;AAClC,QAAIA,KAAK,KAAK0D,SAAV,IAAuB1D,KAAK,KAAK,EAAjC,IAAuCA,KAAK,KAAK,IAArD,EAA2D;AACzD,YAAM,IAAIY,qBAAJ,CAAaC,oBAAW8C,qBAAxB,EAAgD,kBAAhD,CAAN;AACD;AACF;AACF","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 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 {CHUNK_SIZE} from './constants';\nimport {logError} from './utils';\nimport {inspect} from 'util';\nimport httpStatus from 'http-status';\n\nexport default async function (AMQP_URL) {\n const connection = await amqplib.connect(AMQP_URL);\n const channel = await connection.createChannel();\n const logger = createLogger();\n\n return {checkQueue, consumeChunk, consumeOne, ackMessages, nackMessages, sendToQueue, removeQueue, messagesToRecords};\n\n // eslint-disable-next-line max-statements\n async function checkQueue({queue, style = 'basic', toRecord = true, purge = false}) {\n logger.silly(`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 return checkQueue({queue, style});\n }\n\n if (channelInfo.messageCount < 1) {\n logger.silly(`checkQueue: ${channelInfo.messageCount} - ${queue} is empty`);\n return false;\n }\n logger.silly(`Queue ${queue} has ${channelInfo.messageCount} messages`);\n\n if (style === 'messages') {\n return channelInfo.messageCount;\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 return consumeOne(queue, toRecord);\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 return consumeChunk(queue, toRecord);\n }\n\n // Defaults:\n throw new ApiError(httpStatus.UNPROCESSABLE_ENTITY);\n } catch (error) {\n logError(error);\n }\n\n function purgeQueue(purge) {\n if (purge) {\n return channel.purgeQueue(queue);\n }\n }\n }\n\n async function consumeChunk(queue, toRecord) {\n logger.silly(`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 const headers = getHeaderInfo(messages[0]);\n logger.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 logError(error);\n }\n }\n\n async function consumeOne(queue, toRecord) {\n logger.silly(`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 logger.silly(`Message: ${inspect(message, {colors: true, maxArrayLength: 3, depth: 3})}`);\n // Do not spam the logs\n logger.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 logError(error);\n }\n }\n\n function ackMessages(messages) {\n messages.forEach(message => {\n logger.silly(`Ack message ${message.properties.correlationId}`);\n channel.ack(message);\n });\n }\n\n function nackMessages(messages) {\n messages.forEach(message => {\n logger.silly(`Nack message ${message.properties.correlationId}`);\n channel.nack(message);\n });\n }\n\n async function sendToQueue({queue, correlationId, headers, data}) {\n try {\n logger.silly(`Queue ${queue}`);\n logger.silly(`CorrelationId ${correlationId}`);\n logger.silly(`Data ${JSON.stringify(data)}`);\n logger.silly(`Headers ${JSON.stringify(headers)}`);\n\n errorUndefinedQueue(queue);\n await channel.assertQueue(queue, {durable: true});\n\n channel.sendToQueue(\n queue,\n Buffer.from(JSON.stringify({data})),\n {\n correlationId,\n persistent: true,\n headers\n }\n );\n logger.silly(`Send message for ${correlationId} to queue: ${queue}`);\n } catch (error) {\n logError(error);\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 await tempChannel.deleteQueue(queue);\n if (tempChannel) { // eslint-disable-line functional/no-conditional-statement\n await tempChannel.close();\n }\n }\n\n // ----------------\n // Helper functions\n // ----------------\n\n function messagesToRecords(messages) {\n logger.debug(`Parsing messages (${messages.length}) to records`);\n\n return messages.map(message => {\n const content = JSON.parse(message.content.toString());\n return new MarcRecord(content.data);\n });\n }\n\n async function getData(queue) {\n logger.debug(`Getting queue data from ${queue}`);\n try {\n const {messageCount} = await channel.checkQueue(queue);\n logger.silly(`There is ${messageCount} messages in queue ${queue}`);\n const messagesToGet = messageCount >= CHUNK_SIZE ? CHUNK_SIZE : messageCount;\n logger.silly(`Getting ${messagesToGet} messages from queue ${queue}`);\n\n const messages = await pump(messagesToGet);\n\n logger.debug(`Returning ${messages.length} unique messages`);\n\n return messages;\n } catch (error) {\n logError(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\n\n"],"file":"amqp.js"}
1
+ {"version":3,"file":"amqp.js","names":["AMQP_URL","connection","amqplib","connect","channel","createChannel","logger","createLogger","checkQueue","consumeChunk","consumeOne","ackMessages","nackMessages","sendToQueue","removeQueue","messagesToRecords","queue","style","toRecord","purge","silly","errorUndefinedQueue","channelInfo","assertQueue","durable","purgeQueue","verbose","messageCount","ApiError","httpStatus","UNPROCESSABLE_ENTITY","error","logError","messages","getData","headers","getHeaderInfo","debug","length","records","message","get","inspect","colors","maxArrayLength","depth","forEach","properties","correlationId","ack","nack","data","JSON","stringify","Buffer","from","persistent","tempChannel","deleteQueue","close","map","content","parse","toString","MarcRecord","messagesToGet","CHUNK_SIZE","pump","count","results","identifiers","identifier","deliveryTag","fields","includes","concat","undefined","INTERNAL_SERVER_ERROR"],"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-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 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 {CHUNK_SIZE} from './constants';\nimport {logError} from './utils';\nimport {inspect} from 'util';\nimport httpStatus from 'http-status';\n\nexport default async function (AMQP_URL) {\n const connection = await amqplib.connect(AMQP_URL);\n const channel = await connection.createChannel();\n const logger = createLogger();\n\n return {checkQueue, consumeChunk, consumeOne, ackMessages, nackMessages, sendToQueue, removeQueue, messagesToRecords};\n\n // eslint-disable-next-line max-statements\n async function checkQueue({queue, style = 'basic', toRecord = true, purge = false}) {\n logger.silly(`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 return checkQueue({queue, style});\n }\n\n if (channelInfo.messageCount < 1) {\n logger.silly(`checkQueue: ${channelInfo.messageCount} - ${queue} is empty`);\n return false;\n }\n logger.silly(`Queue ${queue} has ${channelInfo.messageCount} messages`);\n\n if (style === 'messages') {\n return channelInfo.messageCount;\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 return consumeOne(queue, toRecord);\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 return consumeChunk(queue, toRecord);\n }\n\n // Defaults:\n throw new ApiError(httpStatus.UNPROCESSABLE_ENTITY);\n } catch (error) {\n logError(error);\n }\n\n function purgeQueue(purge) {\n if (purge) {\n return channel.purgeQueue(queue);\n }\n }\n }\n\n async function consumeChunk(queue, toRecord) {\n logger.silly(`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 const headers = getHeaderInfo(messages[0]);\n logger.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 logError(error);\n }\n }\n\n async function consumeOne(queue, toRecord) {\n logger.silly(`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 logger.silly(`Message: ${inspect(message, {colors: true, maxArrayLength: 3, depth: 3})}`);\n // Do not spam the logs\n logger.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 logError(error);\n }\n }\n\n function ackMessages(messages) {\n messages.forEach(message => {\n logger.silly(`Ack message ${message.properties.correlationId}`);\n channel.ack(message);\n });\n }\n\n function nackMessages(messages) {\n messages.forEach(message => {\n logger.silly(`Nack message ${message.properties.correlationId}`);\n channel.nack(message);\n });\n }\n\n async function sendToQueue({queue, correlationId, headers, data}) {\n try {\n logger.silly(`Queue ${queue}`);\n logger.silly(`CorrelationId ${correlationId}`);\n logger.silly(`Data ${JSON.stringify(data)}`);\n logger.silly(`Headers ${JSON.stringify(headers)}`);\n\n errorUndefinedQueue(queue);\n await channel.assertQueue(queue, {durable: true});\n\n channel.sendToQueue(\n queue,\n Buffer.from(JSON.stringify({data})),\n {\n correlationId,\n persistent: true,\n headers\n }\n );\n logger.silly(`Send message for ${correlationId} to queue: ${queue}`);\n } catch (error) {\n logError(error);\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 await tempChannel.deleteQueue(queue);\n if (tempChannel) { // eslint-disable-line functional/no-conditional-statement\n await tempChannel.close();\n }\n }\n\n // ----------------\n // Helper functions\n // ----------------\n\n function messagesToRecords(messages) {\n logger.debug(`Parsing messages (${messages.length}) to records`);\n\n return messages.map(message => {\n const content = JSON.parse(message.content.toString());\n return new MarcRecord(content.data);\n });\n }\n\n async function getData(queue) {\n logger.debug(`Getting queue data from ${queue}`);\n try {\n const {messageCount} = await channel.checkQueue(queue);\n logger.silly(`There is ${messageCount} messages in queue ${queue}`);\n const messagesToGet = messageCount >= CHUNK_SIZE ? CHUNK_SIZE : messageCount;\n logger.silly(`Getting ${messagesToGet} messages from queue ${queue}`);\n\n const messages = await pump(messagesToGet);\n\n logger.debug(`Returning ${messages.length} unique messages`);\n\n return messages;\n } catch (error) {\n logError(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\n\n"],"mappings":";;;;;;;AA4BA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;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,wBAAgBA,QAAhB,EAA0B;EACvC,MAAMC,UAAU,GAAG,MAAMC,gBAAA,CAAQC,OAAR,CAAg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GAAG,EAArC,EAAyCC,WAAW,GAAG,EAAvD,EAA2D;MACzD,IAAIF,KAAK,KAAK,CAAd,EAAiB;QACf,OAAOC,OAAP;MACD;;MAED,MAAM7B,OAAO,GAAG,MAAMpC,OAAO,CAACqC,GAAR,CAAYzB,KAAZ,CAAtB;MACA,MAAMuD,UAAU,GAAG;QACjBvB,aAAa,EAAER,OAAO,CAACO,UAAR,CAAmBC,aADjB;QAEjBwB,WAAW,EAAEhC,OAAO,CAACiC,MAAR,CAAeD;MAFX,CAAnB,CANyD,CAUzD;;MACA,IAAIF,WAAW,CAACI,QAAZ,CAAqBH,UAArB,CAAJ,EAAsC;QACpC,OAAOJ,IAAI,CAACC,KAAK,GAAG,CAAT,EAAYC,OAAZ,EAAqBC,WAArB,CAAX;MACD;;MAED,OAAOH,IAAI,CAACC,KAAK,GAAG,CAAT,EAAYC,OAAO,CAACM,MAAR,CAAenC,OAAf,CAAZ,EAAqC8B,WAAW,CAACK,MAAZ,CAAmBJ,UAAnB,CAArC,CAAX;IACD;EACF;;EAED,SAASnC,aAAT,CAAuBe,IAAvB,EAA6B;IAC3B,OAAOA,IAAI,CAACJ,UAAL,CAAgBZ,OAAvB;EACD;;EAED,SAASd,mBAAT,CAA6BL,KAA7B,EAAoC;IAClC,IAAIA,KAAK,KAAK4D,SAAV,IAAuB5D,KAAK,KAAK,EAAjC,IAAuCA,KAAK,KAAK,IAArD,EAA2D;MACzD,MAAM,IAAIY,qBAAJ,CAAaC,mBAAA,CAAWgD,qBAAxB,EAAgD,kBAAhD,CAAN;IACD;EACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/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","IMPORT_JOB_STATE","EMPTY","QUEUING","PROCESSING","OPERAT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AO,EAAE,SADuB;AAEhCC,EAAAA,OAAO,EAAE,SAFuB;AAGhCC,EAAAA,IAAI,EAAE,MAH0B;AAIhCC,EAAAA,QAAQ,EAAE;AAJsB,CAA3B","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\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\nexport const CONVERSION_FORMATS = {\n MARCXML: 'MARCXML',\n ISO2709: 'ISO2709',\n JSON: 'JSON',\n ALEPHSEQ: 'ALEPHSEQ'\n};\n"],"file":"constants.js"}
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","IMPORT_JOB_STATE","EMPTY","QUEUING","PROCESSING","OPERATIONS","CREATE","UPDATE","CHUNK_SIZE","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-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\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\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,iBADR;IAETC,kBAAkB,EAAE,oBAFX;IAGTC,mBAAmB,EAAE,qBAHZ;IAITC,SAAS,EAAE,WAJF;IAKTC,UAAU,EAAE,YALH;IAMTC,mBAAmB,EAAE;EANZ,CADmB;EAS9BC,QAAQ,EAAE;IACRC,SAAS,EAAE,WADH;IAERC,UAAU,EAAE,YAFJ;IAGRC,QAAQ,EAAE;EAHF,CAToB;EAc9BC,IAAI,EAAE,MAdwB;EAe9BC,KAAK,EAAE,OAfuB;EAgB9BC,KAAK,EAAE;AAhBuB,CAAzB;;AAmBA,MAAMC,gBAAgB,GAAG;EAC9BC,KAAK,EAAE,OADuB;EAE9BC,OAAO,EAAE,SAFqB;EAG9BN,QAAQ,EAAE,UAHoB;EAI9BF,SAAS,EAAE,WAJmB;EAK9BS,UAAU,EAAE,YALkB;EAM9BN,IAAI,EAAE,MANwB;EAO9BC,KAAK,EAAE,OAPuB;EAQ9BC,KAAK,EAAE;AARuB,CAAzB;;AAWA,MAAMK,UAAU,GAAG;EACxBC,MAAM,EAAE,QADgB;EAExBC,MAAM,EAAE;AAFgB,CAAnB;;AAKA,MAAMC,UAAU,GAAG,GAAnB;;AAEA,MAAMC,kBAAkB,GAAG;EAChCC,OAAO,EAAE,SADuB;EAEhCC,OAAO,EAAE,SAFuB;EAGhCC,IAAI,EAAE,MAH0B;EAIhCC,QAAQ,EAAE;AAJsB,CAA3B"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/helpers/conversion.js"],"names":["logger","serialize","unserialize","record","format","verbose","CONVERSION_FORMATS","MARCXML","to","ISO2709","JSON","Json","ALEPHSEQ","AlephSequential","ConversionError","httpStatus","UNSUPPORTED_MEDIA_TYPE","err","BAD_REQUEST","data","validationOptions","subfieldValues","silly","debug","stringify","from"],"mappings":";;;;;;;AA4BA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;AAjCA;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;AASe,oBAAY;AACzB,QAAMA,MAAM,GAAG,0CAAf;AAEA,SAAO;AAACC,IAAAA,SAAD;AAAYC,IAAAA;AAAZ,GAAP,CAHyB,CAKzB;;AACA,WAASD,SAAT,CAAmBE,MAAnB,EAA2BC,MAA3B,EAAmC;AACjCJ,IAAAA,MAAM,CAACK,OAAP,CAAgB,yBAAwBD,MAAO,EAA/C;;AACA,QAAI;AACF,UAAIA,MAAM,KAAKE,8BAAmBC,OAAlC,EAA2C;AACzC,eAAOA,+BAAQC,EAAR,CAAWL,MAAX,CA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,UAAIhB,MAAM,KAAKE,8BAAmBG,OAAlC,EAA2C;AACzCT,QAAAA,MAAM,CAACsB,KAAP,CAAa,4BAAb;AACA,eAAOb,+BAAQgB,IAAR,CAAaN,IAAb,EAAmBC,iBAAnB,CAAP;AACD;;AAED,UAAIhB,MAAM,KAAKE,8BAAmBI,IAAlC,EAAwC;AACtCV,QAAAA,MAAM,CAACsB,KAAP,CAAa,yBAAb;AACA,eAAOX,4BAAKc,IAAL,CAAUN,IAAV,EAAgBC,iBAAhB,CAAP;AACD;;AAED,UAAIhB,MAAM,KAAKE,8BAAmBM,QAAlC,EAA4C;AAC1CZ,QAAAA,MAAM,CAACsB,KAAP,CAAa,qCAAb;AACA,eAAOT,uCAAgBY,IAAhB,CAAqBN,IAArB,EAA2BC,iBAA3B,CAAP;AACD;;AAED,YAAM,IAAIN,qBAAJ,CAAoBC,oBAAWC,sBAA/B,CAAN;AACD,KAtBD,CAsBE,OAAOC,GAAP,EAAY;AACZ,2BAASA,GAAT;;AACA,UAAIA,GAAG,YAAYH,qBAAnB,EAAoC;AAAE;AACpC,cAAMG,GAAN;AACD;;AACD,YAAM,IAAIH,qBAAJ,CAAoBC,oBAAWG,WAA/B,EAA4C,kCAA5C,CAAN;AACD;AACF;AACF","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 httpStatus from 'http-status';\nimport {MARCXML, ISO2709, Json, AlephSequential} from '@natlibfi/marc-record-serializers';\nimport {createLogger} from '@natlibfi/melinda-backend-commons';\nimport {Error as ConversionError} from '@natlibfi/melinda-commons';\nimport {CONVERSION_FORMATS} from '../constants';\nimport {logError} from '../utils';\n\nexport default function () {\n const logger = createLogger();\n\n return {serialize, unserialize};\n\n // This uses format as a number form contants CONVERSION_FORMATS\n function serialize(record, format) {\n logger.verbose(`Serializing record to ${format}`);\n try {\n if (format === CONVERSION_FORMATS.MARCXML) {\n return MARCXML.to(record);\n }\n\n if (format === CONVERSION_FORMATS.ISO2709) {\n return ISO2709.to(record);\n }\n\n if (format === CONVERSION_FORMATS.JSON) {\n return Json.to(record);\n }\n\n if (format === CONVERSION_FORMATS.ALEPHSEQ) {\n return AlephSequential.to(record);\n }\n\n throw new ConversionError(httpStatus.UNSUPPORTED_MEDIA_TYPE);\n } catch (err) {\n logError(err);\n if (err instanceof ConversionError) { // eslint-disable-line functional/no-conditional-statement\n throw err;\n }\n throw new ConversionError(httpStatus.BAD_REQUEST, 'Error while serializing record');\n }\n }\n\n // eslint-disable-next-line max-statements\n function unserialize(data, format, validationOptions = {subfieldValues: false}) {\n logger.verbose(`Unserializing record from ${format}`);\n logger.silly(`Format: ${format}`);\n logger.debug(`Validation options: ${JSON.stringify(validationOptions)}`);\n logger.silly(`Data: ${JSON.stringify(data)}`);\n try {\n if (format === CONVERSION_FORMATS.MARCXML) {\n logger.silly('Unserialize format marcxml');\n return MARCXML.from(data, validationOptions);\n }\n\n if (format === CONVERSION_FORMATS.ISO2709) {\n logger.silly('Unserialize format iso2709');\n return ISO2709.from(data, validationOptions);\n }\n\n if (format === CONVERSION_FORMATS.JSON) {\n logger.silly('Unserialize format json');\n return Json.from(data, validationOptions);\n }\n\n if (format === CONVERSION_FORMATS.ALEPHSEQ) {\n logger.silly('Unserialize format aleph sequential');\n return AlephSequential.from(data, validationOptions);\n }\n\n throw new ConversionError(httpStatus.UNSUPPORTED_MEDIA_TYPE);\n } catch (err) {\n logError(err);\n if (err instanceof ConversionError) { // eslint-disable-line functional/no-conditional-statement\n throw err;\n }\n throw new ConversionError(httpStatus.BAD_REQUEST, 'Error while unserializing record');\n }\n }\n}\n"],"file":"conversion.js"}
1
+ {"version":3,"file":"conversion.js","names":["logger","createLogger","serialize","unserialize","record","format","verbose","CONVERSION_FORMATS","MARCXML","to","ISO2709","JSON","Json","ALEPHSEQ","AlephSequential","ConversionError","httpStatus","UNSUPPORTED_MEDIA_TYPE","err","logError","BAD_REQUEST","data","validationOptions","subfieldValues","silly","debug","stringify","from"],"sources":["../../src/helpers/conversion.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 httpStatus from 'http-status';\nimport {MARCXML, ISO2709, Json, AlephSequential} from '@natlibfi/marc-record-serializers';\nimport {createLogger} from '@natlibfi/melinda-backend-commons';\nimport {Error as ConversionError} from '@natlibfi/melinda-commons';\nimport {CONVERSION_FORMATS} from '../constants';\nimport {logError} from '../utils';\n\nexport default function () {\n const logger = createLogger();\n\n return {serialize, unserialize};\n\n // This uses format as a number form contants CONVERSION_FORMATS\n function serialize(record, format) {\n logger.verbose(`Serializing record to ${format}`);\n try {\n if (format === CONVERSION_FORMATS.MARCXML) {\n return MARCXML.to(record);\n }\n\n if (format === CONVERSION_FORMATS.ISO2709) {\n return ISO2709.to(record);\n }\n\n if (format === CONVERSION_FORMATS.JSON) {\n return Json.to(record);\n }\n\n if (format === CONVERSION_FORMATS.ALEPHSEQ) {\n return AlephSequential.to(record);\n }\n\n throw new ConversionError(httpStatus.UNSUPPORTED_MEDIA_TYPE);\n } catch (err) {\n logError(err);\n if (err instanceof ConversionError) { // eslint-disable-line functional/no-conditional-statement\n throw err;\n }\n throw new ConversionError(httpStatus.BAD_REQUEST, 'Error while serializing record');\n }\n }\n\n // eslint-disable-next-line max-statements\n function unserialize(data, format, validationOptions = {subfieldValues: false}) {\n logger.verbose(`Unserializing record from ${format}`);\n logger.silly(`Format: ${format}`);\n logger.debug(`Validation options: ${JSON.stringify(validationOptions)}`);\n logger.silly(`Data: ${JSON.stringify(data)}`);\n try {\n if (format === CONVERSION_FORMATS.MARCXML) {\n logger.silly('Unserialize format marcxml');\n return MARCXML.from(data, validationOptions);\n }\n\n if (format === CONVERSION_FORMATS.ISO2709) {\n logger.silly('Unserialize format iso2709');\n return ISO2709.from(data, validationOptions);\n }\n\n if (format === CONVERSION_FORMATS.JSON) {\n logger.silly('Unserialize format json');\n return Json.from(data, validationOptions);\n }\n\n if (format === CONVERSION_FORMATS.ALEPHSEQ) {\n logger.silly('Unserialize format aleph sequential');\n return AlephSequential.from(data, validationOptions);\n }\n\n throw new ConversionError(httpStatus.UNSUPPORTED_MEDIA_TYPE);\n } catch (err) {\n logError(err);\n if (err instanceof ConversionError) { // eslint-disable-line functional/no-conditional-statement\n throw err;\n }\n throw new ConversionError(httpStatus.BAD_REQUEST, 'Error while unserializing record');\n }\n }\n}\n"],"mappings":";;;;;;;AA4BA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;AAjCA;AACA;AACA;AAC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AAJ,CAAoBC,mBAAA,CAAWI,WAA/B,EAA4C,kCAA5C,CAAN;IACD;EACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/helpers/conversion.spec.js"],"names":["describe","getFixture","root","__dirname","conversionService","marcRecord","MarcRecord","JSON","parse","components","subfieldValues","marcXml","iso2709","json","alephSeq","it","service","to","be","an","and","respondTo","serialize","throw","data","CONVERSION_FORMATS","MARCXML","equal","ISO2709","ALEPHSEQ","unserialize","record","equalsTo","ConversionError"],"mappings":";;AA4BA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;AAjCA;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;AASAA,QAAQ,CAAC,qBAAD,EAAwB,MAAM;AACpC,QAAM;AAACC,IAAAA;AAAD,MAAe,qBAAe;AAACC,IAAAA,IAAI,EAAE,CACzCC,SADyC,EAEzC,IAFyC,EAGzC,IAHyC,EAIzC,eAJyC,EAKzC,YALyC;AAAP,GAAf,CAArB;AAOA,QAAMC,iBAAiB,GAAG,0BAA1B;AAEA,QAAMC,UAAU,GAAG,IAAIC,sBAAJ,CAAeC,IAAI,CAACC,KAAL,CAAWP,UAAU,CAAC;AAACQ,IAAAA,UAAU,EAAE,CAAC,OAAD;AAAb,GAAD,CAArB,CAAf,EAAgE;AAACC,IAAAA,cAAc,EAAE;AAAjB,GAAhE,CAAnB;AACA,QAAMC,OAAO,GAAGV,UAAU,CAAC;AAACQ,IAAAA,UAAU,EAAE,CAAC,UAAD;AAAb,GAAD,CAA1B;AACA,QAAMG,OAAO,GAAGX,UAAU,CAAC;AAACQ,IAAAA,UAAU,EAAE,CAAC,WAAD;AAAb,GAAD,CAA1B;AACA,QAAMI,IAAI,GAAGZ,UAAU,CAAC;AAACQ,IAAAA,UAAU,EAAE,CAAC,OAAD;AAAb,GAAD,CAAvB;AACA,QAAMK,QA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7C;AACD,KAHC,CAAF;AAKAZ,IAAAA,EAAE,CAAC,0CAAD,EAA6C,MAAM;AACnD,YAAMgB,MAAM,GAAG3B,iBAAiB,CAAC0B,WAAlB,CAA8BhB,QAA9B,EAAwCW,8BAAmBI,QAA3D,CAAf;AACA,wBAAOE,MAAM,CAACC,QAAP,CAAgB3B,UAAhB,CAAP,EAAoCY,EAApC,CAAuCU,KAAvC,CAA6C,IAA7C;AACD,KAHC,CAAF;AAMAZ,IAAAA,EAAE,CAAC,2DAAD,EAA8D,MAAM;AACpE,wBAAO,MAAM;AACXX,QAAAA,iBAAiB,CAAC0B,WAAlB,CAA8B,EAA9B,EAAkCL,8BAAmBlB,IAArD;AACD,OAFD,EAEGU,EAFH,CAEMM,KAFN,CAEYU,qBAFZ;AAGD,KAJC,CAAF;AAKD,GA/BO,CAAR;AAgCD,CArFO,CAAR","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 {expect} from 'chai';\nimport fixtureFactory from '@natlibfi/fixura';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport {Error as ConversionError} from '@natlibfi/melinda-commons';\nimport createConversionService from './conversion';\nimport {CONVERSION_FORMATS} from '../constants';\n\ndescribe('services/conversion', () => {\n const {getFixture} = fixtureFactory({root: [\n __dirname,\n '..',\n '..',\n 'test-fixtures',\n 'conversion'\n ]});\n const conversionService = createConversionService();\n\n const marcRecord = new MarcRecord(JSON.parse(getFixture({components: ['json1']})), {subfieldValues: false});\n const marcXml = getFixture({components: ['marcxml1']});\n const iso2709 = getFixture({components: ['iso2709_1']});\n const json = getFixture({components: ['json1']});\n const alephSeq = getFixture({components: ['aleph_sequential']});\n\n\n describe('factory', () => {\n it('Should create the expected object', () => {\n const service = createConversionService();\n expect(service).to.be.an('object').and\n .respondTo('serialize')\n .respondTo('unserialize');\n });\n });\n\n describe('#serialize', () => {\n it('Should throw because of unsupported format', () => {\n expect(conversionService.serialize).to.throw();\n });\n\n it('Should serialize to MARCXML', () => {\n const data = conversionService.serialize(marcRecord, CONVERSION_FORMATS.MARCXML);\n expect(data).to.equal(marcXml);\n });\n\n it('Should serialize to ISO2709', () => {\n const data = conversionService.serialize(marcRecord, CONVERSION_FORMATS.ISO2709);\n expect(data).to.equal(iso2709);\n });\n\n it('Should serialize to JSON', () => {\n const data = conversionService.serialize(marcRecord, CONVERSION_FORMATS.JSON);\n expect(data).to.equal(json);\n });\n\n it('Should serialize to aleph sequential', () => {\n const data = conversionService.serialize(marcRecord, CONVERSION_FORMATS.ALEPHSEQ);\n expect(data).to.equal(alephSeq);\n });\n\n });\n\n describe('#unserialize', () => {\n it('Should throw because of unsupported format', () => {\n expect(conversionService.unserialize).to.throw();\n });\n\n it('Should unserialize from MARCXML', async () => {\n const record = await conversionService.unserialize(marcXml, CONVERSION_FORMATS.MARCXML);\n expect(record.equalsTo(marcRecord)).to.equal(true);\n });\n\n it('Should unserialize from ISO2709', () => {\n const record = conversionService.unserialize(iso2709, CONVERSION_FORMATS.ISO2709);\n expect(record.equalsTo(marcRecord)).to.equal(true);\n });\n\n it('Should unserialize from JSON', () => {\n const record = conversionService.unserialize(json, CONVERSION_FORMATS.JSON);\n expect(record.equalsTo(marcRecord)).to.equal(true);\n });\n\n it('Should unserialize from Aleph sequential', () => {\n const record = conversionService.unserialize(alephSeq, CONVERSION_FORMATS.ALEPHSEQ);\n expect(record.equalsTo(marcRecord)).to.equal(true);\n });\n\n\n it('Should throw because the record could not be unserialized', () => {\n expect(() => {\n conversionService.unserialize('', CONVERSION_FORMATS.JSON);\n }).to.throw(ConversionError);\n });\n });\n});\n"],"file":"conversion.spec.js"}
1
+ {"version":3,"file":"conversion.spec.js","names":["describe","getFixture","fixtureFactory","root","__dirname","conversionService","createConversionService","marcRecord","MarcRecord","JSON","parse","components","subfieldValues","marcXml","iso2709","json","alephSeq","it","service","expect","to","be","an","and","respondTo","serialize","throw","data","CONVERSION_FORMATS","MARCXML","equal","ISO2709","ALEPHSEQ","unserialize","record","equalsTo","ConversionError"],"sources":["../../src/helpers/conversion.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-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 {expect} from 'chai';\nimport fixtureFactory from '@natlibfi/fixura';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport {Error as ConversionError} from '@natlibfi/melinda-commons';\nimport createConversionService from './conversion';\nimport {CONVERSION_FORMATS} from '../constants';\n\ndescribe('services/conversion', () => {\n const {getFixture} = fixtureFactory({root: [\n __dirname,\n '..',\n '..',\n 'test-fixtures',\n 'conversion'\n ]});\n const conversionService = createConversionService();\n\n const marcRecord = new MarcRecord(JSON.parse(getFixture({components: ['json1']})), {subfieldValues: false});\n const marcXml = getFixture({components: ['marcxml1']});\n const iso2709 = getFixture({components: ['iso2709_1']});\n const json = getFixture({components: ['json1']});\n const alephSeq = getFixture({components: ['aleph_sequential']});\n\n\n describe('factory', () => {\n it('Should create the expected object', () => {\n const service = createConversionService();\n expect(service).to.be.an('object').and\n .respondTo('serialize')\n .respondTo('unserialize');\n });\n });\n\n describe('#serialize', () => {\n it('Should throw because of unsupported format', () => {\n expect(conversionService.serialize).to.throw();\n });\n\n it('Should serialize to MARCXML', () => {\n const data = conversionService.serialize(marcRecord, CONVERSION_FORMATS.MARCXML);\n expect(data).to.equal(marcXml);\n });\n\n it('Should serialize to ISO2709', () => {\n const data = conversionService.serialize(marcRecord, CONVERSION_FORMATS.ISO2709);\n expect(data).to.equal(iso2709);\n });\n\n it('Should serialize to JSON', () => {\n const data = conversionService.serialize(marcRecord, CONVERSION_FORMATS.JSON);\n expect(data).to.equal(json);\n });\n\n it('Should serialize to aleph sequential', () => {\n const data = conversionService.serialize(marcRecord, CONVERSION_FORMATS.ALEPHSEQ);\n expect(data).to.equal(alephSeq);\n });\n\n });\n\n describe('#unserialize', () => {\n it('Should throw because of unsupported format', () => {\n expect(conversionService.unserialize).to.throw();\n });\n\n it('Should unserialize from MARCXML', async () => {\n const record = await conversionService.unserialize(marcXml, CONVERSION_FORMATS.MARCXML);\n expect(record.equalsTo(marcRecord)).to.equal(true);\n });\n\n it('Should unserialize from ISO2709', () => {\n const record = conversionService.unserialize(iso2709, CONVERSION_FORMATS.ISO2709);\n expect(record.equalsTo(marcRecord)).to.equal(true);\n });\n\n it('Should unserialize from JSON', () => {\n const record = conversionService.unserialize(json, CONVERSION_FORMATS.JSON);\n expect(record.equalsTo(marcRecord)).to.equal(true);\n });\n\n it('Should unserialize from Aleph sequential', () => {\n const record = conversionService.unserialize(alephSeq, CONVERSION_FORMATS.ALEPHSEQ);\n expect(record.equalsTo(marcRecord)).to.equal(true);\n });\n\n\n it('Should throw because the record could not be unserialized', () => {\n expect(() => {\n conversionService.unserialize('', CONVERSION_FORMATS.JSON);\n }).to.throw(ConversionError);\n });\n });\n});\n"],"mappings":";;AA4BA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;AAjCA;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;AASAA,QAAQ,CAAC,qBAAD,EAAwB,MAAM;EACpC,MAAM;IAACC;EAAD,IAAe,IAAAC,eAAA,EAAe;IAACC,IAAI,EAAE,CACzCC,SADyC,EAEzC,IAFyC,EAGzC,IAHyC,EAIzC,eAJyC,EAKzC,YALyC;EAAP,CAAf,CAArB;EAOA,MAAMC,iBAAiB,GAAG,IAAAC,mBAAA,GAA1B;EAEA,MAAMC,UAAU,GAAG,IAAIC,sBAAJ,CAAeC,IAAI,CAACC,KAAL,CAAWT,UAAU,CAAC;IAACU,UAAU,EAAE,CAAC,OAAD;EAAb,CAAD,CAArB,CAAf,EAAgE;IAACC,cAAc,EAAE;EAAjB,CAAhE,CAAnB;EACA,MAAMC,OAAO,GAAGZ,UAAU,CAAC;IAACU,UAAU,EAAE,CAAC,UAAD;EAAb,CAAD,CAA1B;EACA,MAAMG,OAAO,GAAGb,UAAU,CAAC;IAACU,UAAU,EAAE,CAAC,WAAD;EAAb,CAAD,CAA1B;EACA,MAAMI,IAAI,GAAGd,UAAU,CAAC;IAACU,UAAU,EAAE,CAAC,OAAD;EAAb,CAAD,CAAvB;EACA,MAAMK,QAAQ,GAAGf,UAAU,CAAC;IAACU,UAAU,EAAE,CAAC,kBAAD;EAAb,CAAD,CAA3B;EAGAX,QAAQ,CAAC,SAAD,EAAY,MAAM;IACxBiB,EAAE,CAAC,mCAAD,EAAs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nD,MAAMiB,MAAM,GAAG7B,iBAAiB,CAAC4B,WAAlB,CAA8BjB,QAA9B,EAAwCY,6BAAA,CAAmBI,QAA3D,CAAf;MACA,IAAAb,YAAA,EAAOe,MAAM,CAACC,QAAP,CAAgB5B,UAAhB,CAAP,EAAoCa,EAApC,CAAuCU,KAAvC,CAA6C,IAA7C;IACD,CAHC,CAAF;IAMAb,EAAE,CAAC,2DAAD,EAA8D,MAAM;MACpE,IAAAE,YAAA,EAAO,MAAM;QACXd,iBAAiB,CAAC4B,WAAlB,CAA8B,EAA9B,EAAkCL,6BAAA,CAAmBnB,IAArD;MACD,CAFD,EAEGW,EAFH,CAEMM,KAFN,CAEYU,qBAFZ;IAGD,CAJC,CAAF;EAKD,CA/BO,CAAR;AAgCD,CArFO,CAAR"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/helpers/format.js"],"names":["formatRecord","record","settings","logger","verbose","newRecord","MarcRecord","clone","subfieldValues","generateMissingSIDs","forEach","options","replacePrefixes","toObject","oldPrefix","newPrefix","prefixReplaceCodes","pattern","replacement","getDatafields","field","subfields","filter","code","includes","subfield","value","replace","f035Filters","fSIDFilters","f035s","f035ToSidInfo","get","fSIDs","sidsToSidInfo","sidsToBeAdded","genNewSids","length","f035SidInfo","some","fSIDInfo","SID","sidField","insertField","map","sidInfo","tag","ind1","ind2","SIDs","flatMap","sub","undefined","wantedSub","regexp","test","findIndex","slice","indexOf","BIB_FORMAT_SETTINGS"],"mappings":";;;;;;;;AA4BA;;AACA;;AA7BA;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;AAKO,SAASA,YAAT,CAAsBC,MAAtB,EAA8BC,QAAQ,GAAG,EAAzC,EAA6C;AAClD,QAAMC,MAAM,GAAG,0CAAf;AAEAA,EAAAA,MAAM,CAACC,OAAP,CAAe,oBAAf;;AACA,QAAMC,SAA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,SAAS,EAAE,YADb;AAEEC,EAAAA,SAAS,EAAE,OAFb;AAGEC,EAAAA,kBAAkB,EAAE,CAAC,GAAD;AAHtB,CADiC,EAMjC;AACEF,EAAAA,SAAS,EAAE,aADb;AAEEC,EAAAA,SAAS,EAAE,OAFb;AAGEC,EAAAA,kBAAkB,EAAE,CAAC,GAAD;AAHtB,CANiC,EAWjC;AACEF,EAAAA,SAAS,EAAE,aADb;AAEEC,EAAAA,SAAS,EAAE,OAFb;AAGEC,EAAAA,kBAAkB,EAAE,CAAC,GAAD;AAHtB,CAXiC,CAA5B","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 {MarcRecord} from '@natlibfi/marc-record';\nimport {createLogger} from '@natlibfi/melinda-backend-commons';\n\nexport function formatRecord(record, settings = []) {\n const logger = createLogger();\n\n logger.verbose('Applying formating');\n const newRecord = MarcRecord.clone(record, {subfieldValues: false});\n\n generateMissingSIDs();\n\n settings.forEach(options => {\n replacePrefixes(options);\n });\n\n return newRecord.toObject();\n\n // Replace prefix in all specified subfields\n function replacePrefixes(options) {\n const {oldPrefix, newPrefix, prefixReplaceCodes} = options;\n const pattern = `(${oldPrefix})`;\n const replacement = `(${newPrefix})`;\n newRecord.getDatafields()\n .forEach(field => {\n field.subfields\n .filter(({code}) => prefixReplaceCodes.includes(code))\n .forEach(subfield => {\n subfield.value = subfield.value.replace(pattern, replacement); // eslint-disable-line functional/immutable-data\n });\n });\n }\n\n\n function generateMissingSIDs() {\n const f035Filters = [/^\\(FI-BTJ\\)/u, /^\\(FI-TATI\\)/u];\n const fSIDFilters = ['FI-BTJ', 'tati'];\n const f035s = f035ToSidInfo(newRecord.get(/^035$/u));\n const fSIDs = sidsToSidInfo(newRecord.get(/^SID$/u));\n\n const sidsToBeAdded = genNewSids(fSIDs.length === 0\n ? f035s\n // test that SIDs are not there yet\n : f035s.filter(f035SidInfo => fSIDs.some(fSIDInfo => f035SidInfo.SID !== fSIDInfo.SID && f035SidInfo.value !== fSIDInfo.value)));\n\n // Add new SIDs\n return sidsToBeAdded.forEach(sidField => newRecord.insertField(sidField));\n\n function genNewSids(sidsToBeAdded) {\n return sidsToBeAdded.map(sidInfo => ({tag: 'SID', ind1: ' ', ind2: ' ', subfields: [{code: 'c', value: sidInfo.value}, {code: 'b', value: sidInfo.SID}]}));\n }\n\n function sidsToSidInfo(SIDs) {\n return SIDs.flatMap(({subfields}) => {\n const [SID] = subfields.filter(sub => sub.code === 'b' && fSIDFilters.includes(sub.value)).map(sub => sub.value);\n const [value] = subfields.filter(sub => sub.code === 'c' && sub.value !== undefined).map(sub => sub.value);\n\n if (SID && value) {\n return {\n SID,\n value\n };\n }\n\n return undefined;\n }).filter(value => value !== undefined);\n }\n\n function f035ToSidInfo(f035s) {\n return f035s.flatMap(({subfields}) => {\n const [wantedSub] = subfields.filter(sub => sub.code === 'a' && f035Filters.some(regexp => regexp.test(sub.value)));\n\n if (wantedSub) {\n return {\n SID: fSIDFilters[f035Filters.findIndex(regexp => regexp.test(wantedSub.value))],\n value: wantedSub.value.slice(wantedSub.value.indexOf(')') + 1)\n };\n }\n\n return undefined;\n }).filter(value => value !== undefined);\n }\n }\n}\n\n// If placed in config.js testing needs envs\nexport const BIB_FORMAT_SETTINGS = [\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"],"file":"format.js"}
1
+ {"version":3,"file":"format.js","names":["formatRecord","record","settings","logger","createLogger","verbose","newRecord","MarcRecord","clone","subfieldValues","generateMissingSIDs","forEach","options","replacePrefixes","toObject","oldPrefix","newPrefix","prefixReplaceCodes","pattern","replacement","getDatafields","field","subfields","filter","code","includes","subfield","value","replace","f035Filters","fSIDFilters","f035s","f035ToSidInfo","get","fSIDs","sidsToSidInfo","sidsToBeAdded","genNewSids","length","f035SidInfo","some","fSIDInfo","SID","sidField","insertField","map","sidInfo","tag","ind1","ind2","SIDs","flatMap","sub","undefined","wantedSub","regexp","test","findIndex","slice","indexOf","BIB_FORMAT_SETTINGS"],"sources":["../../src/helpers/format.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 {MarcRecord} from '@natlibfi/marc-record';\nimport {createLogger} from '@natlibfi/melinda-backend-commons';\n\nexport function formatRecord(record, settings = []) {\n const logger = createLogger();\n\n logger.verbose('Applying formating');\n const newRecord = MarcRecord.clone(record, {subfieldValues: false});\n\n generateMissingSIDs();\n\n settings.forEach(options => {\n replacePrefixes(options);\n });\n\n return newRecord.toObject();\n\n // Replace prefix in all specified subfields\n function replacePrefixes(options) {\n const {oldPrefix, newPrefix, prefixReplaceCodes} = options;\n const pattern = `(${oldPrefix})`;\n const replacement = `(${newPrefix})`;\n newRecord.getDatafields()\n .forEach(field => {\n field.subfields\n .filter(({code}) => prefixReplaceCodes.includes(code))\n .forEach(subfield => {\n subfield.value = subfield.value.replace(pattern, replacement); // eslint-disable-line functional/immutable-data\n });\n });\n }\n\n\n function generateMissingSIDs() {\n const f035Filters = [/^\\(FI-BTJ\\)/u, /^\\(FI-TATI\\)/u];\n const fSIDFilters = ['FI-BTJ', 'tati'];\n const f035s = f035ToSidInfo(newRecord.get(/^035$/u));\n const fSIDs = sidsToSidInfo(newRecord.get(/^SID$/u));\n\n const sidsToBeAdded = genNewSids(fSIDs.length === 0\n ? f035s\n // test that SIDs are not there yet\n : f035s.filter(f035SidInfo => fSIDs.some(fSIDInfo => f035SidInfo.SID !== fSIDInfo.SID && f035SidInfo.value !== fSIDInfo.value)));\n\n // Add new SIDs\n return sidsToBeAdded.forEach(sidField => newRecord.insertField(sidField));\n\n function genNewSids(sidsToBeAdded) {\n return sidsToBeAdded.map(sidInfo => ({tag: 'SID', ind1: ' ', ind2: ' ', subfields: [{code: 'c', value: sidInfo.value}, {code: 'b', value: sidInfo.SID}]}));\n }\n\n function sidsToSidInfo(SIDs) {\n return SIDs.flatMap(({subfields}) => {\n const [SID] = subfields.filter(sub => sub.code === 'b' && fSIDFilters.includes(sub.value)).map(sub => sub.value);\n const [value] = subfields.filter(sub => sub.code === 'c' && sub.value !== undefined).map(sub => sub.value);\n\n if (SID && value) {\n return {\n SID,\n value\n };\n }\n\n return undefined;\n }).filter(value => value !== undefined);\n }\n\n function f035ToSidInfo(f035s) {\n return f035s.flatMap(({subfields}) => {\n const [wantedSub] = subfields.filter(sub => sub.code === 'a' && f035Filters.some(regexp => regexp.test(sub.value)));\n\n if (wantedSub) {\n return {\n SID: fSIDFilters[f035Filters.findIndex(regexp => regexp.test(wantedSub.value))],\n value: wantedSub.value.slice(wantedSub.value.indexOf(')') + 1)\n };\n }\n\n return undefined;\n }).filter(value => value !== undefined);\n }\n }\n}\n\n// If placed in config.js testing needs envs\nexport const BIB_FORMAT_SETTINGS = [\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"],"mappings":";;;;;;;;AA4BA;;AACA;;AA7BA;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;AAKO,SAASA,YAAT,CAAsBC,MAAtB,EAA8BC,QAAQ,GAAG,EAAzC,EAA6C;EAClD,MAAMC,MAAM,GAAG,IAAAC,mCAAA,GAAf;EAEAD,MAAM,CAACE,OAAP,CAAe,oBAAf;;EACA,MAAMC,SAAS,GAAGC,sBAAA,CAAWC,KAAX,CAAiBP,MAAjB,EAAyB;IAACQ,cAAc,EAAE;EAAjB,CAAzB,CAAlB;;EAEAC,mBAAmB;EAEnBR,QAAQ,CAACS,OAAT,CAAiBC,OAAO,IAAI;IAC1BC,eAAe,CAACD,OAAD,CAAf;EACD,CAFD;EAIA,OAAON,SAAS,CAACQ,QAAV,EAAP,CAZkD,CAclD;;EACA,SAASD,eAAT,CAAyBD,OAAzB,EAAkC;IAChC,MAAM;MAACG,SAAD;MAAYC,SAAZ;MAAuBC;IAAvB,IAA6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gC,SAAD,IAAchC,SAAS,CAACC,MAAV,CAAiB6B,GAAG,IAAIA,GAAG,CAAC5B,IAAJ,KAAa,GAAb,IAAoBK,WAAW,CAACW,IAAZ,CAAiBe,MAAM,IAAIA,MAAM,CAACC,IAAP,CAAYJ,GAAG,CAACzB,KAAhB,CAA3B,CAA5C,CAApB;;QAEA,IAAI2B,SAAJ,EAAe;UACb,OAAO;YACLZ,GAAG,EAAEZ,WAAW,CAACD,WAAW,CAAC4B,SAAZ,CAAsBF,MAAM,IAAIA,MAAM,CAACC,IAAP,CAAYF,SAAS,CAAC3B,KAAtB,CAAhC,CAAD,CADX;YAELA,KAAK,EAAE2B,SAAS,CAAC3B,KAAV,CAAgB+B,KAAhB,CAAsBJ,SAAS,CAAC3B,KAAV,CAAgBgC,OAAhB,CAAwB,GAAxB,IAA+B,CAArD;UAFF,CAAP;QAID;;QAED,OAAON,SAAP;MACD,CAXM,EAWJ9B,MAXI,CAWGI,KAAK,IAAIA,KAAK,KAAK0B,SAXtB,CAAP;IAYD;EACF;AACF,C,CAED;;;AACO,MAAMO,mBAAmB,GAAG,CACjC;EACE7C,SAAS,EAAE,YADb;EAEEC,SAAS,EAAE,OAFb;EAGEC,kBAAkB,EAAE,CAAC,GAAD;AAHtB,CADiC,EAMjC;EACEF,SAAS,EAAE,aADb;EAEEC,SAAS,EAAE,OAFb;EAGEC,kBAAkB,EAAE,CAAC,GAAD;AAHtB,CANiC,EAWjC;EACEF,SAAS,EAAE,aADb;EAEEC,SAAS,EAAE,OAFb;EAGEC,kBAAkB,EAAE,CAAC,GAAD;AAHtB,CAXiC,CAA5B"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/helpers/format.spec.js"],"names":["describe","FIXTURES_PATH","__dirname","getFixture","root","reader","READERS","JSON","it","record","MarcRecord","components","result","toObject","BIB_FORMAT_SETTINGS","expected","to","eql"],"mappings":";;AA4BA;;AACA;;AACA;;AACA;;;;;;AA/BA;AACA;AACA;AACA;AACA;AACA;AACA;A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AAoBAf,EAAAA,QAAQ,CAAC,UAAD,EAAa,MAAM;AACzBQ,IAAAA,EAAE,CAAC,qBAAD,EAAwB,MAAM;AAC9B,YAAMC,MAAM,GAAG,IAAIC,sBAAJ,CAAeP,UAAU,CAAC;AACvCQ,QAAAA,UAAU,EAAE,CACV,IADU,EAEV,eAFU;AAD2B,OAAD,CAAzB,CAAf;AAMA,YAAMC,MAAM,GAAG,0BAAaH,MAAM,CAACI,QAAP,EAAb,CAAf;AACA,YAAME,QAAQ,GAAGZ,UAAU,CAAC;AAC1BQ,QAAAA,UAAU,EAAE,CACV,KADU,EAEV,eAFU;AADc,OAAD,CAA3B;AAOA,wBAAOC,MAAP,EAAeI,EAAf,CAAkBC,GAAlB,CAAsBF,QAAtB;AACD,KAhBC,CAAF;AAiBD,GAlBO,CAAR;AAoBAf,EAAAA,QAAQ,CAAC,kBAAD,EAAqB,MAAM;AACjCQ,IAAAA,EAAE,CAAC,yCAAD,EAA4C,MAAM;AAClD,YAAMC,MAAM,GAAG,IAAIC,sBAAJ,CAAeP,UAAU,CAAC;AACvCQ,QAAAA,UAAU,EAAE,CACV,IADU,EAEV,uBAFU;AAD2B,OAAD,CAAzB,CAAf;AAMA,YAAMC,MAAM,GAAG,0BAAaH,MAAM,CAACI,QAAP,EAAb,CAAf;AACA,YAAME,QAAQ,GAAGZ,UAAU,CAAC;AAC1BQ,QAAAA,UAAU,EAAE,CACV,KADU,EAEV,uBAFU;AADc,OAAD,CAA3B;AAOA,wBAAOC,MAAP,EAAeI,EAAf,CAAkBC,GAAlB,CAAsBF,QAAtB;AACD,KAhBC,CAAF;AAiBD,GAlBO,CAAR;AAmBD,CAjIO,CAAR","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 {formatRecord, BIB_FORMAT_SETTINGS} from './format';\n\ndescribe('services/format', () => {\n const FIXTURES_PATH = [\n __dirname,\n '..',\n '..',\n 'test-fixtures',\n 'format'\n ];\n const {getFixture} = fixtureFactory({root: FIXTURES_PATH, reader: READERS.JSON});\n\n describe('fiAsteriN0Fin11', () => {\n it('Should succeed', () => {\n const record = new MarcRecord(getFixture({\n components: [\n 'in',\n 'fiAsteriN0Fin11.json'\n ]\n }));\n const result = formatRecord(record.toObject(), BIB_FORMAT_SETTINGS);\n const expected = getFixture({\n components: [\n 'out',\n 'fiAsteriN0Fin11.json'\n ]\n });\n\n expect(result).to.eql(expected);\n });\n });\n\n describe('fiAsteriS0Fin10', () => {\n it('Should succeed', () => {\n const record = new MarcRecord(getFixture({\n components: [\n 'in',\n 'fiAsteriS0Fin10.json'\n ]\n }));\n const result = formatRecord(record.toObject(), BIB_FORMAT_SETTINGS);\n const expected = getFixture({\n components: [\n 'out',\n 'fiAsteriS0Fin10.json'\n ]\n });\n\n expect(result).to.eql(expected);\n });\n });\n\n describe('fiMelindaWFin01', () => {\n it('Should succeed', () => {\n const record = new MarcRecord(getFixture({\n components: [\n 'in',\n 'fiMelindaWFin01.json'\n ]\n }));\n const result = formatRecord(record.toObject(), BIB_FORMAT_SETTINGS);\n const expected = getFixture({\n components: [\n 'out',\n 'fiMelindaWFin01.json'\n ]\n });\n\n expect(result).to.eql(expected);\n });\n });\n\n describe('f035fibtj', () => {\n it('Should add FI-BTJ SID', () => {\n const record = new MarcRecord(getFixture({\n components: [\n 'in',\n 'f035fibtj.json'\n ]\n }));\n const result = formatRecord(record.toObject());\n const expected = getFixture({\n components: [\n 'out',\n 'f035fibtj.json'\n ]\n });\n\n expect(result).to.eql(expected);\n });\n });\n\n describe('f035tati', () => {\n it('Should add tati SID', () => {\n const record = new MarcRecord(getFixture({\n components: [\n 'in',\n 'f035tati.json'\n ]\n }));\n const result = formatRecord(record.toObject());\n const expected = getFixture({\n components: [\n 'out',\n 'f035tati.json'\n ]\n });\n\n expect(result).to.eql(expected);\n });\n });\n\n describe('f035fibtjAndTati', () => {\n it('Should add tati SID and skip FI-BTJ SID', () => {\n const record = new MarcRecord(getFixture({\n components: [\n 'in',\n 'f035fibtjAndTati.json'\n ]\n }));\n const result = formatRecord(record.toObject());\n const expected = getFixture({\n components: [\n 'out',\n 'f035fibtjAndTati.json'\n ]\n });\n\n expect(result).to.eql(expected);\n });\n });\n});\n"],"file":"format.spec.js"}
1
+ {"version":3,"file":"format.spec.js","names":["describe","FIXTURES_PATH","__dirname","getFixture","fixtureFactory","root","reader","READERS","JSON","it","record","MarcRecord","components","result","formatRecord","toObject","BIB_FORMAT_SETTINGS","expected","expect","to","eql"],"sources":["../../src/helpers/format.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 {formatRecord, BIB_FORMAT_SETTINGS} from './format';\n\ndescribe('services/format', () => {\n const FIXTURES_PATH = [\n __dirname,\n '..',\n '..',\n 'test-fixtures',\n 'format'\n ];\n const {getFixture} = fixtureFactory({root: FIXTURES_PATH, reader: READERS.JSON});\n\n describe('fiAsteriN0Fin11', () => {\n it('Should succeed', () => {\n const record = new MarcRecord(getFixture({\n components: [\n 'in',\n 'fiAsteriN0Fin11.json'\n ]\n }));\n const result = formatRecord(record.toObject(), BIB_FORMAT_SETTINGS);\n const expected = getFixture({\n components: [\n 'out',\n 'fiAsteriN0Fin11.json'\n ]\n });\n\n expect(result).to.eql(expected);\n });\n });\n\n describe('fiAsteriS0Fin10', () => {\n it('Should succeed', () => {\n const record = new MarcRecord(getFixture({\n components: [\n 'in',\n 'fiAsteriS0Fin10.json'\n ]\n }));\n const result = formatRecord(record.toObject(), BIB_FORMAT_SETTINGS);\n const expected = getFixture({\n components: [\n 'out',\n 'fiAsteriS0Fin10.json'\n ]\n });\n\n expect(result).to.eql(expected);\n });\n });\n\n describe('fiMelindaWFin01', () => {\n it('Should succeed', () => {\n const record = new MarcRecord(getFixture({\n components: [\n 'in',\n 'fiMelindaWFin01.json'\n ]\n }));\n const result = formatRecord(record.toObject(), BIB_FORMAT_SETTINGS);\n const expected = getFixture({\n components: [\n 'out',\n 'fiMelindaWFin01.json'\n ]\n });\n\n expect(result).to.eql(expected);\n });\n });\n\n describe('f035fibtj', () => {\n it('Should add FI-BTJ SID', () => {\n const record = new MarcRecord(getFixture({\n components: [\n 'in',\n 'f035fibtj.json'\n ]\n }));\n const result = formatRecord(record.toObject());\n const expected = getFixture({\n components: [\n 'out',\n 'f035fibtj.json'\n ]\n });\n\n expect(result).to.eql(expected);\n });\n });\n\n describe('f035tati', () => {\n it('Should add tati SID', () => {\n const record = new MarcRecord(getFixture({\n components: [\n 'in',\n 'f035tati.json'\n ]\n }));\n const result = formatRecord(record.toObject());\n const expected = getFixture({\n components: [\n 'out',\n 'f035tati.json'\n ]\n });\n\n expect(result).to.eql(expected);\n });\n });\n\n describe('f035fibtjAndTati', () => {\n it('Should add tati SID and skip FI-BTJ SID', () => {\n const record = new MarcRecord(getFixture({\n components: [\n 'in',\n 'f035fibtjAndTati.json'\n ]\n }));\n const result = formatRecord(record.toObject());\n const expected = getFixture({\n components: [\n 'out',\n 'f035fibtjAndTati.json'\n ]\n });\n\n expect(result).to.eql(expected);\n });\n });\n});\n"],"mappings":";;AA4BA;;AACA;;AACA;;AACA;;;;;;AA/BA;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;AAOAA,QAAQ,CAAC,iBAAD,EAAoB,MAAM;EAChC,MAAMC,aAAa,GAAG,CACpBC,SADoB,EAEpB,IAFoB,EAGpB,IAHoB,EAIpB,eAJoB,EAKpB,QALoB,CAAtB;EAOA,MAAM;IAACC;EAAD,IAAe,IAAAC,eAAA,EAAe;IAACC,IAAI,EAAEJ,aAAP;IAAsBK,MAAM,EAAEC,eAAA,CAAQC;EAAtC,CAAf,CAArB;EAEAR,QAAQ,CAAC,iBAAD,EAAoB,MAAM;IAChCS,EAAE,CAAC,gBAAD,EAAmB,MAAM;MACzB,MAAMC,MAAM,GAAG,IAAIC,sBAAJ,CAAeR,UAAU,CAAC;QACvCS,UAAU,EAAE,CACV,IADU,EAEV,sBAFU;MAD2B,CAAD,CAAzB,CAAf;MAMA,MAAMC,MAAM,GAAG,IAAAC,oBAAA,EAAaJ,MAAM,CAAC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ACV,IADU,EAEV,uBAFU;MAD2B,CAAD,CAAzB,CAAf;MAMA,MAAMC,MAAM,GAAG,IAAAC,oBAAA,EAAaJ,MAAM,CAACK,QAAP,EAAb,CAAf;MACA,MAAME,QAAQ,GAAGd,UAAU,CAAC;QAC1BS,UAAU,EAAE,CACV,KADU,EAEV,uBAFU;MADc,CAAD,CAA3B;MAOA,IAAAM,YAAA,EAAOL,MAAP,EAAeM,EAAf,CAAkBC,GAAlB,CAAsBH,QAAtB;IACD,CAhBC,CAAF;EAiBD,CAlBO,CAAR;AAmBD,CAjIO,CAAR"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/helpers/validation.js"],"names":["logger","verbose","validate","tag","valuePattern","unvalidRecord","record","valid","report","fix","validateFixes","subfieldValues","failed","messages"],"mappings":";;;;;;;AA4BA;;AACA;;AAGA;;;;AAhCA;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;eAQe,YAAY;AACzB,QAAMA,MAAM,GAAG,0CAAf;AAEAA,EAAAA,MAAM,CAACC,OAAP,CAAe,oCAAf;AACA,QAAMC,QAAQ,GAAG,iCAAgB,CAAC,MAAM,iDAAe,CAAC;AAACC,IAAAA,GAAG,EAAE,QAAN;AAAgBC,IAAAA,YAAY,EAAE;AAA9B,GAAD,CAAf,CAAP,CAAhB,CAAjB;AAEA,SAAO,MAAMC,aAAN,IAAuB;AAC5B,UAAM;AAACC,MAAAA,MAAD;AAASC,MAAAA,KAAT;AAAgBC,MAAAA;AAAhB,QAA0B,MAAMN,QAAQ,CAACG,aAAD,EAAgB;AAACI,MAAAA,GAAG,EAAE,KAAN;AAAaC,MAAAA,aAAa,EAAE;AAA5B,KAAhB,EAAoD;AAACC,MAAAA,cAAc,EAAE;AAAjB,KAApD,CAA9C;AAEA,WAAO;AACLL,MAAAA,MADK;AAELM,MAAAA,MAAM,EAAEL,KAAK,KAAK,KAFb;AAGLM,MAAAA,QAAQ,EAAEL;AAHL,KAAP;AAKD,GARD;AASD,C","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 validateFactory from '@natlibfi/marc-record-validate';\nimport {\n FieldStructure as fieldStructure\n} from '@natlibfi/marc-record-validators-melinda';\nimport {createLogger} from '@natlibfi/melinda-backend-commons';\n\nexport default async () => {\n const logger = createLogger();\n\n logger.verbose('Running inbuilt record validations');\n const validate = validateFactory([await fieldStructure([{tag: /^003$/u, valuePattern: /^FI-MELINDA$/u}])]);\n\n return async unvalidRecord => {\n const {record, valid, report} = await validate(unvalidRecord, {fix: false, validateFixes: false}, {subfieldValues: false});\n\n return {\n record,\n failed: valid === false,\n messages: report\n };\n };\n};\n"],"file":"validation.js"}
1
+ {"version":3,"file":"validation.js","names":["logger","createLogger","verbose","validate","validateFactory","fieldStructure","tag","valuePattern","unvalidRecord","record","valid","report","fix","validateFixes","subfieldValues","failed","messages"],"sources":["../../src/helpers/validation.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 validateFactory from '@natlibfi/marc-record-validate';\nimport {\n FieldStructure as fieldStructure\n} from '@natlibfi/marc-record-validators-melinda';\nimport {createLogger} from '@natlibfi/melinda-backend-commons';\n\nexport default async () => {\n const logger = createLogger();\n\n logger.verbose('Running inbuilt record validations');\n const validate = validateFactory([await fieldStructure([{tag: /^003$/u, valuePattern: /^FI-MELINDA$/u}])]);\n\n return async unvalidRecord => {\n const {record, valid, report} = await validate(unvalidRecord, {fix: false, validateFixes: false}, {subfieldValues: false});\n\n return {\n record,\n failed: valid === false,\n messages: report\n };\n };\n};\n"],"mappings":";;;;;;;AA4BA;;AACA;;AAGA;;;;AAhCA;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;eAQe,YAAY;EACzB,MAAMA,MAAM,GAAG,IAAAC,mCAAA,GAAf;EAEAD,MAAM,CAACE,OAAP,CAAe,oCAAf;EACA,MAAMC,QAAQ,GAAG,IAAAC,2BAAA,EAAgB,CAAC,MAAM,IAAAC,2CAAA,EAAe,CAAC;IAACC,GAAG,EAAE,QAAN;IAAgBC,YAAY,EAAE;EAA9B,CAAD,CAAf,CAAP,CAAhB,CAAjB;EAEA,OAAO,MAAMC,aAAN,IAAuB;IAC5B,MAAM;MAACC,MAAD;MAASC,KAAT;MAAgBC;IAAhB,IAA0B,MAAMR,QAAQ,CAACK,aAAD,EAAgB;MAACI,GAAG,EAAE,KAAN;MAAaC,aAAa,EAAE;IAA5B,CAAhB,EAAoD;MAACC,cAAc,EAAE;IAAjB,CAApD,CAA9C;IAEA,OAAO;MACLL,MADK;MAELM,MAAM,EAAEL,KAAK,KAAK,KAFb;MAGLM,QAAQ,EAAEL;IAHL,CAAP;EAKD,CARD;AASD,C"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/helpers/validation.spec.js"],"names":["describe","FIXTURES_PATH","__dirname","getFixture","root","reader","READERS","JSON","it","validator","record","MarcRecord","components","result","toObject","expected","to","eql","failed","equal"],"mappings":";;AA4BA;;AACA;;AACA;;AACA;;;;;;;;AA/BA;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;AAOAA,QAAQ,CAAC,mBAAD,EAAsB,MAAM;AAClC,QAAMC,aAAa,GAAG,CACpBC,SADoB,EAEpB,IAFoB,EAGpB,IAHoB,EAIpB,eAJoB,EAKpB,YALoB,CAAtB;AAOA,QAAM;AAACC,IAAAA;AAAD,MAAe,qBAAe;AAACC,IAAAA,IAAI,EAAEH,aAAP;AAAsBI,IAAAA,MAAM,EAAEC,gBAAQC;AAAtC,GAAf,CAArB;AAEAP,EAAAA,QAAQ,CAAC,iBAAD,EAAoB,MAAM;AAChCQ,IAAAA,EAAE,CAAC,2BAAD,EAA8B,YAAY;AAC1C,YAAMC,SAAS,GAAG,MAAM,0BAAxB;AACA,YAAMC,MAAM,GAAG,IAAIC,sBAAJ,CAAeR,UAAU,CAAC;AACvCS,QAAAA,UAAU,EAAE,CACV,IADU,EAEV,sBAFU;AAD2B,OAAD,CAAzB,CAAf;AAMA,YAAMC,MAAM,GAAG,MAAMJ,SAAS,CAACC,MAAM,CAACI,QAAP,EAAD,CAA9B;AACA,YAAMC,QAAQ,GAAGZ,UAAU,CAAC;AAC1BS,QAAAA,UAAU,EAAE,CACV,KADU,EAEV,sBAFU;AADc,OAAD,CAA3B;AAMA,wBAAOC,MAAP,EAAeG,EAAf,CAAkBC,GAAlB,CAAsBF,QAAtB;AACA,wBAAOF,MAAM,CAACK,MAAd,EAAsBF,EAAtB,CAAyBG,KAAzB,CAA+B,KAA/B;AACD,KAjBC,CAAF;AAkBD,GAnBO,CAAR;AAqBAnB,EAAAA,QAAQ,CAAC,qBAAD,EAAwB,MAAM;AACpCQ,IAAAA,EAAE,CAAC,0BAAD,EAA6B,YAAY;AACzC,YAAMC,SAAS,GAAG,MAAM,0BAAxB;AACA,YAAMC,MAAM,GAAG,IAAIC,sBAAJ,CAAeR,UAAU,CAAC;AACvCS,QAAAA,UAAU,EAAE,CACV,IADU,EAEV,0BAFU;AAD2B,OAAD,CAAzB,CAAf;AAMA,YAAMC,MAAM,GAAG,MAAMJ,SAAS,CAACC,MAAM,CAACI,QAAP,EAAD,CAA9B;AACA,YAAMC,QAAQ,GAAGZ,UAAU,CAAC;AAC1BS,QAAAA,UAAU,EAAE,CACV,KADU,EAEV,0BAFU;AADc,OAAD,CAA3B;AAMA,wBAAOC,MAAP,EAAeG,EAAf,CAAkBC,GAAlB,CAAsBF,QAAtB;AACA,wBAAOF,MAAM,CAACK,MAAd,EAAsBF,EAAtB,CAAyBG,KAAzB,CAA+B,IAA/B;AACD,KAjBC,CAAF;AAkBD,GAnBO,CAAR;AAoBD,CAnDO,CAAR","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"],"file":"validation.spec.js"}
1
+ {"version":3,"file":"validation.spec.js","names":["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;;AACA;;AACA;;AACA;;;;;;;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AAU,CAAC;QACvCW,UAAU,EAAE,CACV,IADU,EAEV,0BAFU;MAD2B,CAAD,CAAzB,CAAf;MAMA,MAAMC,MAAM,GAAG,MAAML,SAAS,CAACE,MAAM,CAACI,QAAP,EAAD,CAA9B;MACA,MAAMC,QAAQ,GAAGd,UAAU,CAAC;QAC1BW,UAAU,EAAE,CACV,KADU,EAEV,0BAFU;MADc,CAAD,CAA3B;MAMA,IAAAI,YAAA,EAAOH,MAAP,EAAeI,EAAf,CAAkBC,GAAlB,CAAsBH,QAAtB;MACA,IAAAC,YAAA,EAAOH,MAAM,CAACM,MAAd,EAAsBF,EAAtB,CAAyBG,KAAzB,CAA+B,IAA/B;IACD,CAjBC,CAAF;EAkBD,CAnBO,CAAR;AAoBD,CAnDO,CAAR"}
package/dist/index.js CHANGED
@@ -5,14 +5,23 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  var _exportNames = {
7
7
  mongoFactory: true,
8
+ mongoLogFactory: true,
8
9
  amqpFactory: true,
9
10
  conversions: true,
10
11
  validations: true,
11
12
  format: true,
12
13
  logError: true,
13
14
  createImportJobState: true,
14
- createImportJobStateForQuery: true
15
+ createImportJobStateForQuery: true,
16
+ createRecordResponseItem: true,
17
+ addRecordResponseItem: true
15
18
  };
19
+ Object.defineProperty(exports, "addRecordResponseItem", {
20
+ enumerable: true,
21
+ get: function () {
22
+ return _utils.addRecordResponseItem;
23
+ }
24
+ });
16
25
  Object.defineProperty(exports, "amqpFactory", {
17
26
  enumerable: true,
18
27
  get: function () {
@@ -37,6 +46,12 @@ Object.defineProperty(exports, "createImportJobStateForQuery", {
37
46
  return _utils.createImportJobStateForQuery;
38
47
  }
39
48
  });
49
+ Object.defineProperty(exports, "createRecordResponseItem", {
50
+ enumerable: true,
51
+ get: function () {
52
+ return _utils.createRecordResponseItem;
53
+ }
54
+ });
40
55
  exports.format = void 0;
41
56
  Object.defineProperty(exports, "logError", {
42
57
  enumerable: true,
@@ -50,6 +65,12 @@ Object.defineProperty(exports, "mongoFactory", {
50
65
  return _mongo.default;
51
66
  }
52
67
  });
68
+ Object.defineProperty(exports, "mongoLogFactory", {
69
+ enumerable: true,
70
+ get: function () {
71
+ return _mongoLog.default;
72
+ }
73
+ });
53
74
  Object.defineProperty(exports, "validations", {
54
75
  enumerable: true,
55
76
  get: function () {
@@ -59,6 +80,8 @@ Object.defineProperty(exports, "validations", {
59
80
 
60
81
  var _mongo = _interopRequireDefault(require("./mongo"));
61
82
 
83
+ var _mongoLog = _interopRequireDefault(require("./mongoLog"));
84
+
62
85
  var _amqp = _interopRequireDefault(require("./amqp"));
63
86
 
64
87
  var _conversion = _interopRequireDefault(require("./helpers/conversion"));
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA;;AACA;;AACA;;AACA;;AACA;;;;AACA;;AAGA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA","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 amqpFactory from './amqp';\nimport conversions from './helpers/conversion';\nimport validations from './helpers/validation';\nimport * as format from './helpers/format';\nimport {logError, createImportJobState, createImportJobStateForQuery} from './utils';\n\nexport {mongoFactory, amqpFactory, conversions, validations, format, logError, createImportJobState, createImportJobStateForQuery};\nexport * from './constants';\n"],"file":"index.js"}
1
+ {"version":3,"file":"index.js","names":[],"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 format from './helpers/format';\nimport {logError, createImportJobState, createImportJobStateForQuery, createRecordResponseItem, addRecordResponseItem} from './utils';\n\nexport {mongoFactory, mongoLogFactory, amqpFactory, conversions, validations, format, logError, createImportJobState, createImportJobStateForQuery, createRecordResponseItem, addRecordResponseItem};\nexport * from './constants';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;AACA;;AAGA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
package/dist/mongo.js CHANGED
@@ -50,6 +50,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
50
50
  * for the JavaScript code in this file.
51
51
  *
52
52
  */
53
+ //import isDeepStrictEqual from 'util';
53
54
 
54
55
  /* QueueItem:
55
56
  {
@@ -71,9 +72,12 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
71
72
  "CREATE": "EMPTY",
72
73
  "UPDATE": "EMPTY"
73
74
  },
75
+ blobSize: 1,
76
+ records: [],
77
+ errorMessage: '',
78
+ errorStatus: '',
74
79
  "creationTime":"2020-01-01T00:00:00.000Z",
75
80
  "modificationTime":"2020-01-01T00:00:01.000Z",
76
- "handledIds": []
77
81
  }
78
82
  */
79
83
  async function _default(MONGO_URI, collection) {
@@ -104,7 +108,9 @@ async function _default(MONGO_URI, collection) {
104
108
  pushIds,
105
109
  pushMessages,
106
110
  setOperation,
107
- setOperations
111
+ setOperations,
112
+ addBlobSize,
113
+ setBlobSize
108
114
  };
109
115
 
110
116
  async function createPrio({
@@ -126,14 +132,16 @@ async function _default(MONGO_URI, collection) {
126
132
  ...operationSettings
127
133
  },
128
134
  queueItemState: _constants.QUEUE_ITEM_STATE.VALIDATOR.PENDING_VALIDATION,
135
+ blobSize: 1,
129
136
  importJobState: {
130
137
  CREATE: _constants.IMPORT_JOB_STATE.EMPTY,
131
138
  UPDATE: _constants.IMPORT_JOB_STATE.EMPTY
132
139
  },
140
+ records: [],
141
+ errorMessage: '',
142
+ errorStatus: '',
133
143
  creationTime: time,
134
- modificationTime: time,
135
- handledIds: [],
136
- rejectedIds: []
144
+ modificationTime: time
137
145
  };
138
146
 
139
147
  try {
@@ -175,14 +183,16 @@ async function _default(MONGO_URI, collection) {
175
183
  contentType,
176
184
  recordLoadParams,
177
185
  queueItemState: stream ? _constants.QUEUE_ITEM_STATE.VALIDATOR.UPLOADING : _constants.QUEUE_ITEM_STATE.VALIDATOR.WAITING_FOR_RECORDS,
186
+ blobSize: 0,
178
187
  importJobState: {
179
188
  CREATE: _constants.IMPORT_JOB_STATE.EMPTY,
180
189
  UPDATE: _constants.IMPORT_JOB_STATE.EMPTY
181
190
  },
191
+ records: [],
192
+ errorMessage: '',
193
+ errorStatus: '',
182
194
  creationTime: time,
183
- modificationTime: time,
184
- handledIds: [],
185
- rejectedIds: []
195
+ modificationTime: time
186
196
  }; // eslint-disable-next-line functional/no-conditional-statement
187
197
 
188
198
  if (stream) {
@@ -279,12 +289,27 @@ async function _default(MONGO_URI, collection) {
279
289
  return false;
280
290
  }
281
291
 
282
- async function query(params) {
283
- const result = await db.collection(collection).find(params, {
292
+ async function query(params, showParams = {}) {
293
+ const {
294
+ showOperations = 0,
295
+ showOperationSettings = 0,
296
+ showRecordLoadParams = 0,
297
+ showImportJobState = 0
298
+ } = showParams;
299
+ const {
300
+ limit = 1000,
301
+ skip = 0,
302
+ ...rest
303
+ } = params;
304
+ const result = await db.collection(collection).find(rest, {
284
305
  projection: {
285
- _id: 0
306
+ _id: 0,
307
+ operations: showOperations,
308
+ operationSettings: showOperationSettings,
309
+ recordLoadParams: showRecordLoadParams,
310
+ importJobState: showImportJobState
286
311
  }
287
- }).toArray();
312
+ }).limit(parseInt(limit, 10)).skip(parseInt(skip, 10)).toArray();
288
313
  logger.debug(`Query result: ${result.length > 0 ? 'Found!' : 'Not found!'}`);
289
314
  return result;
290
315
  }
@@ -413,13 +438,26 @@ async function _default(MONGO_URI, collection) {
413
438
  }); // njsscan-ignore: node_nosqli_injection
414
439
 
415
440
  if (result) {
416
- return {
417
- contentType: result.contentType,
418
- readStream: gridFSBucket.openDownloadStreamByName(clean)
419
- };
441
+ const {
442
+ operationSettings
443
+ } = result;
444
+
445
+ if (operationSettings.prio === false && operationSettings.noStream === false) {
446
+ return {
447
+ contentType: result.contentType,
448
+ readStream: gridFSBucket.openDownloadStreamByName(clean)
449
+ };
450
+ }
451
+
452
+ logger.debug(`OperationSetting for ${correlationId}: ${JSON.stringify(operationSettings)}`);
453
+ throw new _melindaCommons.Error(_httpStatus.default.BAD_REQUEST, {
454
+ message: `Content is only available for streamBulk jobs. ${correlationId} is not a streamBulk job.`
455
+ });
420
456
  }
421
457
 
422
- throw new _melindaCommons.Error(_httpStatus.default.NOT_FOUND);
458
+ throw new _melindaCommons.Error(_httpStatus.default.NOT_FOUND, {
459
+ message: `Job ${correlationId} not found.`
460
+ });
423
461
  }
424
462
 
425
463
  async function removeContent(params) {
@@ -545,7 +583,7 @@ async function _default(MONGO_URI, collection) {
545
583
  errorMessage = undefined,
546
584
  errorStatus = undefined
547
585
  }) {
548
- const errorString = errorMessage || errorStatus ? `, Error message: '${errorMessage || ''}', Error status: '${errorStatus || ''}'` : '';
586
+ const errorString = errorMessage || errorStatus ? `, Error message: '${JSON.stringify(errorMessage) || ''}', Error status: '${errorStatus || ''}'` : '';
549
587
  logger.info(`Setting queue-item state ${state} for ${correlationId}${errorString} to ${collection}`);
550
588
  const stateInQueueItemStates = Object.values(_constants.QUEUE_ITEM_STATE).indexOf(state) > -1;
551
589
  const stateInQueueItemStatesValidator = Object.values(_constants.QUEUE_ITEM_STATE.VALIDATOR).indexOf(state) > -1;
@@ -648,16 +686,17 @@ async function _default(MONGO_URI, collection) {
648
686
  addOperation,
649
687
  removeOperation = undefined
650
688
  }) {
651
- const cleanCorrelationId = (0, _mongoSanitize.default)(correlationId); //logger.info(`Setting queue-item operation from ${JSON.stringify(oldOperations)} by adding ${addOperation} and removing ${removeOperation} for ${correlationId} to ${collection}`);
652
-
689
+ const cleanCorrelationId = (0, _mongoSanitize.default)(correlationId);
653
690
  const queueItem = await db.collection(collection).findOne({
654
691
  correlationId: cleanCorrelationId
655
692
  });
656
- logger.debug(`We fould a queueItem: ${JSON.stringify(queueItem)}`);
693
+ logger.silly(`We found a queueItem: ${JSON.stringify(queueItem)}`);
657
694
  const oldOperations = queueItem.operations;
658
- logger.info(`Setting queue-item operation from ${JSON.stringify(oldOperations)} by adding ${addOperation} and removing ${removeOperation} for ${correlationId} to ${collection}`);
695
+ logger.info(`Setting queue-item operations from ${JSON.stringify(oldOperations)} by adding ${addOperation} and removing ${removeOperation} for ${correlationId} to ${collection}`);
659
696
  const operationsAfterRemove = oldOperations.filter(operation => operation !== removeOperation);
660
- const operationsAfterRemoveAndAdd = [addOperation, ...operationsAfterRemove];
697
+ const operationsAfterRemoveAndAdd = operationsAfterRemove.includes(addOperation) ? operationsAfterRemove : [...operationsAfterRemove, addOperation];
698
+ logger.silly(`operationsAfterRemove: ${operationsAfterRemove}`);
699
+ logger.silly(`operationAfterRemoveAndAdd: ${operationsAfterRemoveAndAdd}`);
661
700
  const result = await db.collection(collection).findOneAndUpdate({
662
701
  correlationId: cleanCorrelationId
663
702
  }, {
@@ -673,5 +712,52 @@ async function _default(MONGO_URI, collection) {
673
712
  });
674
713
  return result.ok; // logger.debug(JSON.stringify(result));
675
714
  }
715
+
716
+ async function addBlobSize({
717
+ correlationId
718
+ }) {
719
+ const cleanCorrelationId = (0, _mongoSanitize.default)(correlationId);
720
+ const result = await db.collection(collection).findOneAndUpdate({
721
+ correlationId: cleanCorrelationId,
722
+ queueItemState: _constants.QUEUE_ITEM_STATE.VALIDATOR.WAITING_FOR_RECORDS
723
+ }, {
724
+ $inc: {
725
+ blobSize: 1
726
+ },
727
+ $set: {
728
+ modificationTime: (0, _moment.default)().toDate()
729
+ }
730
+ }, {
731
+ projection: {
732
+ _id: 0
733
+ },
734
+ returnNewDocument: true
735
+ });
736
+ logger.verbose(`AddBlobSizeResult in mongo: ${JSON.stringify(result)}`);
737
+ return result;
738
+ }
739
+
740
+ async function setBlobSize({
741
+ correlationId,
742
+ blobSize
743
+ }) {
744
+ const cleanCorrelationId = (0, _mongoSanitize.default)(correlationId);
745
+ const cleanBlobSize = (0, _mongoSanitize.default)(blobSize);
746
+ const result = await db.collection(collection).findOneAndUpdate({
747
+ correlationId: cleanCorrelationId
748
+ }, {
749
+ $set: {
750
+ blobSize: cleanBlobSize,
751
+ modificationTime: (0, _moment.default)().toDate()
752
+ }
753
+ }, {
754
+ projection: {
755
+ _id: 0
756
+ },
757
+ returnNewDocument: true
758
+ });
759
+ logger.verbose(`SetBlobSizeResult in mongo: ${JSON.stringify(result)}`);
760
+ return result;
761
+ }
676
762
  }
677
763
  //# sourceMappingURL=mongo.js.map
package/dist/mongo.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/mongo.js"],"names":["MONGO_URI","collection","logger","client","MongoClient","connect","useNewUrlParser","useUnifiedTopology","db","gridFSBucket","GridFSBucket","bucketName","createPrio","createBulk","checkAndSetState","checkAndSetImportJobState","query","queryById","remove","readContent","removeContent","getOne","getStream","setState","setImportJobState","pushIds","pushMessages","setOperation","setOperations","correlationId","cataloger","oCatalogerIn","operation","operationSettings","time","toDate","newQueueItem","operations","prio","queueItemState","QUEUE_ITEM_STATE","VALIDATOR","PENDING_VALIDATION","importJobState","CREATE","IMPORT_JOB_STATE","EMPTY","UPDATE","creationTime","modificationTime","handledIds","rejectedIds","result","insertOne","acknowledged","info","ApiError","httpStatus","INTERNAL_SERVER_ERROR","error","contentType","recordLoadParams","stream","UPLOADING","WAITING_FOR_RECORDS","Promise","resolve","reject","outputStream","openUploadStream","on","chunk","write","end","undefined","debug","state","errorMessage","errorStatus","timeOut","checkTimeOut","params","find","projection","_id","toArray","length","checkModTime","findOne","queueitemState","oldState","ABORT","ERROR","DONE","includes","silly","timeoutTime","add","isBefore","finalImportJobStates","REQUEST_TIMEOUT","JSON","stringify","clean","noContent","deleteOne","err","MongoDriverError","message","indexOf","readStream","openDownloadStreamByName","NOT_FOUND","delete","cleanQueueItemState","verbose","updateOne","$set","$push","$each","messages","messageField","cleanMessageField","errorString","stateInQueueItemStates","Object","values","stateInQueueItemStatesValidator","stateInQueueItemStatesImporter","IMPORTER","BAD_REQUEST","updateValues","keys","forEach","key","findOneAndUpdate","returnNewDocument","cleanCorrelationId","cleanImportJobState","OPERATIONS","newJobState","newOperation","oldOperation","cleanNewOperation","ok","addOperation","removeOperation","queueItem","oldOperations","operationsAfterRemove","filter","operationsAfterRemoveAndAdd"],"mappings":";;;;;;;AA4BA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;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;;AAWA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEe,wBAAgBA,SAAhB,EAA2BC,UAA3B,EAAuC;AACpD,QAAMC,MAAM,GAAG,0CAAf,CADoD,CAGpD;;AACA,QAAMC,MAAM,GAAG,MAAMC,qBAAYC,OAAZ,CAAoBL,SAApB,EAA+B;AAACM,IAAAA,eAAe,EAAE,IAAlB;AAAwBC,IAAAA,kBAAkB,EAAE;AAA5C,GAA/B,CAArB;AACA,QAAMC,EAAE,GAAGL,MAAM,CAACK,EAAP,CAAU,UAAV,CAAX;AACA,QAAMC,YAAY,GAAG,IAAIC,qBAAJ,CAAiBF,EAAjB,EAAqB;AAACG,IAAAA,UAAU,EAAEV;AAAb,GAArB,CAArB;AAEA,SAAO;AAACW,IAAAA,UAAD;AAAaC,IAAAA,UAAb;AAAyBC,IAAAA,gBAAzB;AAA2CC,IAAAA,yBAA3C;AAAsEC,IAAAA,KAAtE;AAA6EC,IAAAA,SAA7E;AAAwFC,IAAAA,MAAxF;AAAgGC,IAAAA,WAAhG;AAA6GC,IAAAA,aAA7G;AAA4HC,IAAAA,MAA5H;AAAoIC,IAAAA,SAApI;AAA+IC,IAAAA,QAA/I;AAAyJC,IAAAA,iBAAzJ;AAA4KC,IAAAA,OAA5K;AAAqLC,IAAAA,YAArL;AAAmMC,IAAAA,YAAnM;AAAiNC,IAAAA;AAAjN,GAAP;;AAEA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AIA,SAAS,KAAKkH,eAAhD,CAA9B;AACA,UAAMK,2BAA2B,GAAG,CAACN,YAAD,EAAe,GAAGI,qBAAlB,CAApC;AAEA,UAAMjG,MAAM,GAAG,MAAM5C,EAAE,CAACP,UAAH,CAAcA,UAAd,EAA0BsI,gBAA1B,CAA2C;AAC9D1G,MAAAA,aAAa,EAAE4G;AAD+C,KAA3C,EAElB;AACDpB,MAAAA,IAAI,EAAE;AACJhF,QAAAA,UAAU,EAAEkH,2BADR;AAEJtG,QAAAA,gBAAgB,EAAE,uBAASd,MAAT;AAFd;AADL,KAFkB,EAOlB;AAACgD,MAAAA,UAAU,EAAE;AAACC,QAAAA,GAAG,EAAE;AAAN,OAAb;AAAuBoD,MAAAA,iBAAiB,EAAE;AAA1C,KAPkB,CAArB;AASA,WAAOpF,MAAM,CAAC4F,EAAd,CAxBuF,CAyBvF;AACD;AACF","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 {MongoClient, GridFSBucket, MongoDriverError} from 'mongodb';\nimport {createLogger} from '@natlibfi/melinda-backend-commons';\nimport {Error as ApiError} from '@natlibfi/melinda-commons';\nimport {QUEUE_ITEM_STATE, IMPORT_JOB_STATE, OPERATIONS} from './constants';\nimport {logError} from './utils.js';\nimport moment from 'moment';\nimport httpStatus from 'http-status';\nimport sanitize from 'mongo-sanitize';\n\n/* QueueItem:\n{\n \"correlationId\":\"FOO\",\n \"cataloger\":\"xxx0000\",\n \"oCatalogerIn\":\"xxx0000\"\n \"operation\":\"UPDATE\",\n \"operations\":[\"UPDATE\", \"CREATE\"]\n \"contentType\":\"application/json\",\n \"recordLoadParams\": {\n \"pActiveLibrary\": \"XXX00\",\n \"pInputFile\": \"filename.seq\",\n \"pRejectFile\": \"filename.rej\",\n \"pLogFile\": \"filename.syslog\",\n \"pOldNew\": \"NEW\"\n },\n \"queueItemState\":\"PENDING_QUEUING\",\n \"importJobState\": {\n \"CREATE\": \"EMPTY\",\n \"UPDATE\": \"EMPTY\"\n },\n \"creationTime\":\"2020-01-01T00:00:00.000Z\",\n \"modificationTime\":\"2020-01-01T00:00:01.000Z\",\n \"handledIds\": []\n}\n*/\n\nexport default async function (MONGO_URI, collection) {\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 gridFSBucket = new GridFSBucket(db, {bucketName: collection});\n\n return {createPrio, createBulk, checkAndSetState, checkAndSetImportJobState, query, queryById, remove, readContent, removeContent, getOne, getStream, setState, setImportJobState, pushIds, pushMessages, setOperation, setOperations};\n\n async function createPrio({correlationId, cataloger, oCatalogerIn, operation, operationSettings}) {\n const time = moment().toDate();\n const newQueueItem = {\n correlationId,\n cataloger,\n operation,\n operations: [operation],\n oCatalogerIn,\n operationSettings: {\n prio: true,\n ...operationSettings\n },\n queueItemState: QUEUE_ITEM_STATE.VALIDATOR.PENDING_VALIDATION,\n importJobState: {\n CREATE: IMPORT_JOB_STATE.EMPTY,\n UPDATE: IMPORT_JOB_STATE.EMPTY\n },\n creationTime: time,\n modificationTime: time,\n handledIds: [],\n rejectedIds: []\n };\n try {\n const result = await db.collection(collection).insertOne(newQueueItem);\n if (result.acknowledged) {\n logger.info(`New PRIO queue item for ${operation} ${correlationId} has been made in ${collection}`);\n return;\n }\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR);\n } catch (error) {\n logError(error);\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR);\n }\n }\n\n async function createBulk({correlationId, cataloger, oCatalogerIn, operation, contentType, recordLoadParams, stream, operationSettings}) {\n const time = moment().toDate();\n const newQueueItem = {\n correlationId,\n cataloger,\n oCatalogerIn,\n operation,\n operations: [operation],\n operationSettings: {\n prio: false,\n ...operationSettings\n },\n contentType,\n recordLoadParams,\n queueItemState: stream ? QUEUE_ITEM_STATE.VALIDATOR.UPLOADING : QUEUE_ITEM_STATE.VALIDATOR.WAITING_FOR_RECORDS,\n importJobState: {\n CREATE: IMPORT_JOB_STATE.EMPTY,\n UPDATE: IMPORT_JOB_STATE.EMPTY\n },\n creationTime: time,\n modificationTime: time,\n handledIds: [],\n rejectedIds: []\n };\n\n // eslint-disable-next-line functional/no-conditional-statement\n if (stream) {\n try {\n // No await here, promises later\n db.collection(collection).insertOne(newQueueItem);\n logger.info(`New BULK queue item for ${operation} ${correlationId} has been made in ${collection}!`);\n return new Promise((resolve, reject) => {\n const outputStream = gridFSBucket.openUploadStream(correlationId);\n\n stream\n .on('error', reject)\n .on('data', chunk => outputStream.write(chunk))\n .on('end', () => outputStream.end(undefined, undefined, () => {\n resolve(correlationId);\n }));\n });\n } catch (error) {\n logError(error);\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR);\n }\n }\n\n logger.debug(`No stream`);\n // eslint-disable-next-line functional/no-conditional-statement\n if (!stream) {\n try {\n const result = await db.collection(collection).insertOne(newQueueItem);\n if (result.acknowledged) {\n logger.info(`New noStream BULK queue item for ${operation} ${correlationId} has been made in ${collection}`);\n return {correlationId, queueItemState: QUEUE_ITEM_STATE.VALIDATOR.WAITING_FOR_RECORDS};\n }\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR);\n } catch (error) {\n logError(error);\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR);\n }\n }\n }\n\n // Check state that the queueItem has not waited too long and set state\n async function checkAndSetState({correlationId, state, errorMessage = undefined, errorStatus = undefined}) {\n // checkTimeOut returns true, if queueItem is fresher than 1 minute and it's state is not ABORT/ERROR\n // otherwise it sets queueItem to state ABORT (408, 'Timeout')\n const timeOut = await checkTimeOut({correlationId});\n if (timeOut) {\n return setState({correlationId, state, errorMessage, errorStatus});\n }\n return false;\n }\n\n // Check state that the queueItem has not waited too long and set state\n async function checkAndSetImportJobState({correlationId, operation, importJobState, errorMessage = '', errorStatus = ''}) {\n // checkTimeOut returns true, if queueItem is fresher than 1 minute and it's state is not ABORT/ERROR\n // otherwise it sets queueItem to state ABORT (408, 'Timeout')\n logger.debug(`${correlationId}, ${importJobState}, ${operation}`);\n const timeOut = await checkTimeOut({correlationId, operation, importJobState});\n if (timeOut) {\n return setImportJobState({correlationId, operation, importJobState, errorMessage, errorStatus});\n }\n return false;\n }\n\n async function query(params) {\n const result = await db.collection(collection).find(params, {projection: {_id: 0}})\n .toArray();\n logger.debug(`Query result: ${result.length > 0 ? 'Found!' : 'Not found!'}`);\n return result;\n }\n\n async function queryById({correlationId, checkModTime = false}) {\n const result = await db.collection(collection).findOne({correlationId});\n if (checkModTime) {\n const timeOut = await checkTimeOut({correlationId});\n if (timeOut) {\n return queryById({correlationId});\n }\n return result;\n }\n\n return result;\n }\n\n // Check that if the item has waited too long\n // If the last modification time for the queueItem is older than 1 minute\n // set state to ABORT and return false, otherwise return true\n // If the state is already ABORT or ERROR return false\n\n async function checkTimeOut({correlationId}) {\n const {modificationTime, queueitemState: oldState, importJobState} = await db.collection(collection).findOne({correlationId});\n\n // should we check for DONE too?\n if ([QUEUE_ITEM_STATE.ABORT, QUEUE_ITEM_STATE.ERROR, QUEUE_ITEM_STATE.DONE].includes(oldState)) {\n logger.silly(`${correlationId} has already state: ${oldState}`);\n return false;\n }\n\n const timeoutTime = moment(modificationTime).add(1, 'm');\n logger.silly(`timeOut @ ${timeoutTime}`);\n\n if (timeoutTime.isBefore()) {\n const finalImportJobStates = [IMPORT_JOB_STATE.ABORT, IMPORT_JOB_STATE.DONE, IMPORT_JOB_STATE.EMPTY, IMPORT_JOB_STATE.ERROR];\n if (!finalImportJobStates.includes(importJobState.CREATE)) { // eslint-disable-line\n await setImportJobState({correlationId, operation: 'CREATE', importJobState: IMPORT_JOB_STATE.ABORT});\n }\n\n if (!finalImportJobStates.includes(importJobState.UPDATE)) { // eslint-disable-line\n await setImportJobState({correlationId, operation: 'UPDATE', importJobState: IMPORT_JOB_STATE.ABORT});\n }\n\n await setState({correlationId, state: QUEUE_ITEM_STATE.ABORT, errorStatus: httpStatus.REQUEST_TIMEOUT, errorMessage: `Timeout in ${oldState}`});\n\n return false;\n }\n\n return true;\n }\n\n async function remove(params) {\n logger.silly(`${JSON.stringify(params)}`);\n logger.info(`Removing from Mongo (${collection}) id: ${params.correlationId}`);\n const clean = sanitize(params.correlationId);\n logger.silly(`mongo/remove: clean: ${JSON.stringify(clean)}`);\n\n try {\n //const metadataResult = await getFileMetadata({filename: clean});\n //logger.debug(`mongo/remove: metadataResult: ${JSON.stringify(metadataResult)}`);\n const noContent = await removeContent(params);\n if (noContent) {\n await db.collection(collection).deleteOne({correlationId: clean});\n return true;\n }\n } catch (err) {\n if (err instanceof MongoDriverError) {\n if (err.message.indexOf('File not found for id') !== -1) {\n logger.silly(`mongo/remove: File not found, removing queueItem ${JSON.stringify(clean)} from ${collection}`);\n await db.collection(collection).deleteOne({correlationId: clean});\n return true;\n }\n logger.error(err.message);\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, err.message);\n }\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, err.message);\n }\n }\n\n async function readContent(correlationId) {\n logger.info(`Reading content from mongo for id: ${correlationId} in ${collection}`);\n const clean = sanitize(correlationId);\n const result = await db.collection(collection).findOne({correlationId: clean}); // njsscan-ignore: node_nosqli_injection\n\n if (result) {\n return {\n contentType: result.contentType,\n readStream: gridFSBucket.openDownloadStreamByName(clean)\n };\n }\n\n throw new ApiError(httpStatus.NOT_FOUND);\n }\n\n async function removeContent(params) {\n logger.info(`Removing content from mongo for id: ${params.correlationId} in ${collection}`);\n const clean = sanitize(params.correlationId);\n\n const result = await db.collection(collection).findOne({correlationId: clean}); // njsscan-ignore: node_nosqli_injection\n logger.silly(`mongo/removeContent: result ${JSON.stringify(result)}`);\n\n if (result) {\n await gridFSBucket.delete(clean);\n return true;\n }\n\n return true;\n }\n\n // eslint-disable-next-line max-statements\n function getOne({queueItemState, importJobState = undefined}) {\n\n logger.silly(`queueItemState: ${queueItemState}, importJobState: ${JSON.stringify(importJobState)}`);\n const cleanQueueItemState = queueItemState ? {queueItemState: sanitize(queueItemState)} : undefined;\n\n try {\n\n // Just queueItemState\n if (queueItemState && importJobState === undefined) {\n logger.silly(`Checking DB ${collection} for just ${JSON.stringify(cleanQueueItemState.queueItemState)}`);\n return db.collection(collection).findOne({...cleanQueueItemState});\n }\n\n // importJobState\n if (importJobState && queueItemState === undefined) {\n logger.silly(`Checking DB ${collection} for ${JSON.stringify(importJobState)}`);\n return db.collection(collection).findOne({...importJobState});\n }\n\n // importJobState and queueItemState\n if (importJobState && queueItemState) {\n logger.silly(`Checking DB ${collection} for ${queueItemState} and ${JSON.stringify(importJobState)}`);\n return db.collection(collection).findOne({...cleanQueueItemState, ...importJobState});\n }\n\n logger.debug(`getOne not working!`);\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, 'Missing parameters, cannot get queueItem');\n\n } catch (error) {\n logError(error);\n }\n }\n\n function getStream(correlationId) {\n logger.info(`Forming stream from mongo for ${correlationId} in ${collection}`);\n const clean = sanitize(correlationId);\n try {\n // Return content stream\n return gridFSBucket.openDownloadStreamByName(clean);\n } catch (error) {\n logError(error);\n }\n }\n\n async function pushIds({correlationId, handledIds, rejectedIds}) {\n logger.verbose(`Push ids (${handledIds.length}) and rejectedIds (${rejectedIds.length}) ${correlationId} to ${collection}`);\n logger.debug(`ids (${handledIds.length}): ${JSON.stringify(handledIds)}, rejectedIds ${rejectedIds.length}: ${JSON.stringify(rejectedIds)}`);\n const clean = sanitize(correlationId);\n await db.collection(collection).updateOne({\n correlationId: clean\n }, {\n $set: {\n modificationTime: moment().toDate()\n },\n $push: {\n handledIds: {$each: handledIds},\n rejectedIds: {$each: rejectedIds}\n }\n });\n }\n\n async function pushMessages({correlationId, messages, messageField = 'messages'}) {\n logger.verbose(`Push messages (${messages.length}) to ${messageField} ${correlationId} to ${collection}`);\n logger.silly(`Messages (${messages.length}): ${JSON.stringify(messages)}}`);\n const clean = sanitize(correlationId);\n const cleanMessageField = sanitize(messageField);\n await db.collection(collection).updateOne({\n correlationId: clean\n }, {\n $set: {\n modificationTime: moment().toDate()\n },\n $push: {\n [cleanMessageField]: {$each: messages}\n }\n });\n }\n\n function setState({correlationId, state, errorMessage = undefined, errorStatus = undefined}) {\n const errorString = errorMessage || errorStatus ? `, Error message: '${errorMessage || ''}', Error status: '${errorStatus || ''}'` : '';\n logger.info(`Setting queue-item state ${state} for ${correlationId}${errorString} to ${collection}`);\n\n const stateInQueueItemStates = Object.values(QUEUE_ITEM_STATE).indexOf(state) > -1;\n const stateInQueueItemStatesValidator = Object.values(QUEUE_ITEM_STATE.VALIDATOR).indexOf(state) > -1;\n const stateInQueueItemStatesImporter = Object.values(QUEUE_ITEM_STATE.IMPORTER).indexOf(state) > -1;\n if (!stateInQueueItemStates && !stateInQueueItemStatesValidator && !stateInQueueItemStatesImporter) {\n throw new ApiError(httpStatus.BAD_REQUEST, 'Trying to set invalid state');\n }\n\n const clean = sanitize(correlationId);\n const updateValues = {\n queueItemState: state,\n modificationTime: moment().toDate(),\n errorMessage,\n errorStatus\n };\n\n // Do not update value that are undefined\n // eslint-disable-next-line functional/immutable-data\n Object.keys(updateValues).forEach(key => updateValues[key] === undefined && delete updateValues[key]);\n\n return db.collection(collection)\n .findOneAndUpdate(\n {correlationId: clean},\n {$set: updateValues},\n {projection: {_id: 0}, returnNewDocument: true}\n );\n }\n\n function setImportJobState({correlationId, operation, importJobState}) {\n\n // should this also get importJobState as previously created object? {}\n logger.info(`Setting queue-item importJobState: {${operation}: ${importJobState}} for ${correlationId}`);\n const cleanCorrelationId = sanitize(correlationId);\n const cleanImportJobState = sanitize(importJobState);\n\n if (!(operation in OPERATIONS)) {\n throw new ApiError('400', 'Invalid operation for import job state');\n }\n\n if (!(cleanImportJobState in IMPORT_JOB_STATE)) {\n throw new ApiError('400', 'Invalid import job state');\n }\n\n const newJobState = operation === OPERATIONS.CREATE ? {'importJobState.CREATE': cleanImportJobState} : {'importJobState.UPDATE': cleanImportJobState};\n return db.collection(collection).findOneAndUpdate({\n correlationId: cleanCorrelationId\n }, {\n $set: {\n ...newJobState,\n modificationTime: moment().toDate()\n }\n }, {projection: {_id: 0}, returnNewDocument: true});\n }\n\n async function setOperation({correlationId, operation}) {\n const newOperation = operation;\n const {operation: oldOperation} = await db.collection(collection).findOne({correlationId});\n logger.info(`Setting queue-item operation from ${oldOperation} to ${newOperation} for ${correlationId} to ${collection}`);\n const cleanCorrelationId = sanitize(correlationId);\n const cleanNewOperation = sanitize(newOperation);\n\n const result = await db.collection(collection).findOneAndUpdate({\n correlationId: cleanCorrelationId\n }, {\n $set: {\n operation: cleanNewOperation,\n modificationTime: moment().toDate()\n }\n }, {projection: {_id: 0}, returnNewDocument: true});\n\n return result.ok;\n // logger.debug(JSON.stringify(result));\n }\n\n async function setOperations({correlationId, addOperation, removeOperation = undefined}) {\n const cleanCorrelationId = sanitize(correlationId);\n\n //logger.info(`Setting queue-item operation from ${JSON.stringify(oldOperations)} by adding ${addOperation} and removing ${removeOperation} for ${correlationId} to ${collection}`);\n\n const queueItem = await db.collection(collection).findOne({correlationId: cleanCorrelationId});\n logger.debug(`We fould a queueItem: ${JSON.stringify(queueItem)}`);\n\n const oldOperations = queueItem.operations;\n\n logger.info(`Setting queue-item operation from ${JSON.stringify(oldOperations)} by adding ${addOperation} and removing ${removeOperation} for ${correlationId} to ${collection}`);\n\n const operationsAfterRemove = oldOperations.filter(operation => operation !== removeOperation);\n const operationsAfterRemoveAndAdd = [addOperation, ...operationsAfterRemove];\n\n const result = await db.collection(collection).findOneAndUpdate({\n correlationId: cleanCorrelationId\n }, {\n $set: {\n operations: operationsAfterRemoveAndAdd,\n modificationTime: moment().toDate()\n }\n }, {projection: {_id: 0}, returnNewDocument: true});\n\n return result.ok;\n // logger.debug(JSON.stringify(result));\n }\n}\n"],"file":"mongo.js"}
1
+ {"version":3,"file":"mongo.js","names":["MONGO_URI","collection","logger","createLogger","client","MongoClient","connect","useNewUrlParser","useUnifiedTopology","db","gridFSBucket","GridFSBucket","bucketName","createPrio","createBulk","checkAndSetState","checkAndSetImportJobState","query","queryById","remove","readContent","removeContent","getOne","getStream","setState","setImportJobState","pushIds","pushMessages","setOperation","setOperations","addBlobSize","setBlobSize","correlationId","cataloger","oCatalogerIn","operation","operationSettings","time","moment","toDate","newQueueItem","operations","prio","queueItemState","QUEUE_ITEM_STATE","VALIDATOR","PENDING_VALIDATION","blobSize","importJobState","CREATE","IMPORT_JOB_STATE","EMPTY","UPDATE","records","errorMessage","errorStatus","creationTime","modificationTime","result","insertOne","acknowledged","info","ApiError","httpStatus","INTERNAL_SERVER_ERROR","error","logError","contentType","recordLoadParams","stream","UPLOADING","WAITING_FOR_RECORDS","Promise","resolve","reject","outputStream","openUploadStream","on","chunk","write","end","undefined","debug","state","timeOut","checkTimeOut","params","showParams","showOperations","showOperationSettings","showRecordLoadParams","showImportJobState","limit","skip","rest","find","projection","_id","parseInt","toArray","length","checkModTime","findOne","queueitemState","oldState","ABORT","ERROR","DONE","includes","silly","timeoutTime","add","isBefore","finalImportJobStates","REQUEST_TIMEOUT","JSON","stringify","clean","sanitize","noContent","deleteOne","err","MongoDriverError","message","indexOf","noStream","readStream","openDownloadStreamByName","BAD_REQUEST","NOT_FOUND","delete","cleanQueueItemState","handledIds","rejectedIds","verbose","updateOne","$set","$push","$each","messages","messageField","cleanMessageField","errorString","stateInQueueItemStates","Object","values","stateInQueueItemStatesValidator","stateInQueueItemStatesImporter","IMPORTER","updateValues","keys","forEach","key","findOneAndUpdate","returnNewDocument","cleanCorrelationId","cleanImportJobState","OPERATIONS","newJobState","newOperation","oldOperation","cleanNewOperation","ok","addOperation","removeOperation","queueItem","oldOperations","operationsAfterRemove","filter","operationsAfterRemoveAndAdd","$inc","cleanBlobSize"],"sources":["../src/mongo.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 {MongoClient, GridFSBucket, MongoDriverError} from 'mongodb';\nimport {createLogger} from '@natlibfi/melinda-backend-commons';\nimport {Error as ApiError} from '@natlibfi/melinda-commons';\nimport {QUEUE_ITEM_STATE, IMPORT_JOB_STATE, OPERATIONS} from './constants';\nimport {logError} from './utils.js';\nimport moment from 'moment';\nimport httpStatus from 'http-status';\nimport sanitize from 'mongo-sanitize';\n//import isDeepStrictEqual from 'util';\n\n/* QueueItem:\n{\n \"correlationId\":\"FOO\",\n \"cataloger\":\"xxx0000\",\n \"oCatalogerIn\":\"xxx0000\"\n \"operation\":\"UPDATE\",\n \"operations\":[\"UPDATE\", \"CREATE\"]\n \"contentType\":\"application/json\",\n \"recordLoadParams\": {\n \"pActiveLibrary\": \"XXX00\",\n \"pInputFile\": \"filename.seq\",\n \"pRejectFile\": \"filename.rej\",\n \"pLogFile\": \"filename.syslog\",\n \"pOldNew\": \"NEW\"\n },\n \"queueItemState\":\"PENDING_QUEUING\",\n \"importJobState\": {\n \"CREATE\": \"EMPTY\",\n \"UPDATE\": \"EMPTY\"\n },\n blobSize: 1,\n records: [],\n errorMessage: '',\n errorStatus: '',\n \"creationTime\":\"2020-01-01T00:00:00.000Z\",\n \"modificationTime\":\"2020-01-01T00:00:01.000Z\",\n}\n*/\n\nexport default async function (MONGO_URI, collection) {\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 gridFSBucket = new GridFSBucket(db, {bucketName: collection});\n\n return {createPrio, createBulk, checkAndSetState, checkAndSetImportJobState, query, queryById, remove, readContent, removeContent, getOne, getStream, setState, setImportJobState, pushIds, pushMessages, setOperation, setOperations, addBlobSize, setBlobSize};\n\n async function createPrio({correlationId, cataloger, oCatalogerIn, operation, operationSettings}) {\n const time = moment().toDate();\n const newQueueItem = {\n correlationId,\n cataloger,\n operation,\n operations: [operation],\n oCatalogerIn,\n operationSettings: {\n prio: true,\n ...operationSettings\n },\n queueItemState: QUEUE_ITEM_STATE.VALIDATOR.PENDING_VALIDATION,\n blobSize: 1,\n importJobState: {\n CREATE: IMPORT_JOB_STATE.EMPTY,\n UPDATE: IMPORT_JOB_STATE.EMPTY\n },\n records: [],\n errorMessage: '',\n errorStatus: '',\n creationTime: time,\n modificationTime: time\n };\n try {\n const result = await db.collection(collection).insertOne(newQueueItem);\n if (result.acknowledged) {\n logger.info(`New PRIO queue item for ${operation} ${correlationId} has been made in ${collection}`);\n return;\n }\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR);\n } catch (error) {\n logError(error);\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR);\n }\n }\n\n async function createBulk({correlationId, cataloger, oCatalogerIn, operation, contentType, recordLoadParams, stream, operationSettings}) {\n const time = moment().toDate();\n const newQueueItem = {\n correlationId,\n cataloger,\n oCatalogerIn,\n operation,\n operations: [operation],\n operationSettings: {\n prio: false,\n ...operationSettings\n },\n contentType,\n recordLoadParams,\n queueItemState: stream ? QUEUE_ITEM_STATE.VALIDATOR.UPLOADING : QUEUE_ITEM_STATE.VALIDATOR.WAITING_FOR_RECORDS,\n blobSize: 0,\n importJobState: {\n CREATE: IMPORT_JOB_STATE.EMPTY,\n UPDATE: IMPORT_JOB_STATE.EMPTY\n },\n records: [],\n errorMessage: '',\n errorStatus: '',\n creationTime: time,\n modificationTime: time\n };\n\n // eslint-disable-next-line functional/no-conditional-statement\n if (stream) {\n try {\n // No await here, promises later\n db.collection(collection).insertOne(newQueueItem);\n logger.info(`New BULK queue item for ${operation} ${correlationId} has been made in ${collection}!`);\n return new Promise((resolve, reject) => {\n const outputStream = gridFSBucket.openUploadStream(correlationId);\n\n stream\n .on('error', reject)\n .on('data', chunk => outputStream.write(chunk))\n .on('end', () => outputStream.end(undefined, undefined, () => {\n resolve(correlationId);\n }));\n });\n } catch (error) {\n logError(error);\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR);\n }\n }\n\n logger.debug(`No stream`);\n // eslint-disable-next-line functional/no-conditional-statement\n if (!stream) {\n try {\n const result = await db.collection(collection).insertOne(newQueueItem);\n if (result.acknowledged) {\n logger.info(`New noStream BULK queue item for ${operation} ${correlationId} has been made in ${collection}`);\n return {correlationId, queueItemState: QUEUE_ITEM_STATE.VALIDATOR.WAITING_FOR_RECORDS};\n }\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR);\n } catch (error) {\n logError(error);\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR);\n }\n }\n }\n\n // Check state that the queueItem has not waited too long and set state\n async function checkAndSetState({correlationId, state, errorMessage = undefined, errorStatus = undefined}) {\n // checkTimeOut returns true, if queueItem is fresher than 1 minute and it's state is not ABORT/ERROR\n // otherwise it sets queueItem to state ABORT (408, 'Timeout')\n const timeOut = await checkTimeOut({correlationId});\n if (timeOut) {\n return setState({correlationId, state, errorMessage, errorStatus});\n }\n return false;\n }\n\n // Check state that the queueItem has not waited too long and set state\n async function checkAndSetImportJobState({correlationId, operation, importJobState, errorMessage = '', errorStatus = ''}) {\n // checkTimeOut returns true, if queueItem is fresher than 1 minute and it's state is not ABORT/ERROR\n // otherwise it sets queueItem to state ABORT (408, 'Timeout')\n logger.debug(`${correlationId}, ${importJobState}, ${operation}`);\n const timeOut = await checkTimeOut({correlationId, operation, importJobState});\n if (timeOut) {\n return setImportJobState({correlationId, operation, importJobState, errorMessage, errorStatus});\n }\n return false;\n }\n\n async function query(params, showParams = {}) {\n const {showOperations = 0, showOperationSettings = 0, showRecordLoadParams = 0, showImportJobState = 0} = showParams;\n const {limit = 1000, skip = 0, ...rest} = params;\n const result = await db.collection(collection).find(rest, {projection: {\n _id: 0,\n operations: showOperations,\n operationSettings: showOperationSettings,\n recordLoadParams: showRecordLoadParams,\n importJobState: showImportJobState\n }})\n .limit(parseInt(limit, 10))\n .skip(parseInt(skip, 10))\n .toArray();\n logger.debug(`Query result: ${result.length > 0 ? 'Found!' : 'Not found!'}`);\n return result;\n }\n\n async function queryById({correlationId, checkModTime = false}) {\n const result = await db.collection(collection).findOne({correlationId});\n if (checkModTime) {\n const timeOut = await checkTimeOut({correlationId});\n if (timeOut) {\n return queryById({correlationId});\n }\n return result;\n }\n\n return result;\n }\n\n // Check that if the item has waited too long\n // If the last modification time for the queueItem is older than 1 minute\n // set state to ABORT and return false, otherwise return true\n // If the state is already ABORT or ERROR return false\n\n async function checkTimeOut({correlationId}) {\n const {modificationTime, queueitemState: oldState, importJobState} = await db.collection(collection).findOne({correlationId});\n\n // should we check for DONE too?\n if ([QUEUE_ITEM_STATE.ABORT, QUEUE_ITEM_STATE.ERROR, QUEUE_ITEM_STATE.DONE].includes(oldState)) {\n logger.silly(`${correlationId} has already state: ${oldState}`);\n return false;\n }\n\n const timeoutTime = moment(modificationTime).add(1, 'm');\n logger.silly(`timeOut @ ${timeoutTime}`);\n\n if (timeoutTime.isBefore()) {\n const finalImportJobStates = [IMPORT_JOB_STATE.ABORT, IMPORT_JOB_STATE.DONE, IMPORT_JOB_STATE.EMPTY, IMPORT_JOB_STATE.ERROR];\n if (!finalImportJobStates.includes(importJobState.CREATE)) { // eslint-disable-line\n await setImportJobState({correlationId, operation: 'CREATE', importJobState: IMPORT_JOB_STATE.ABORT});\n }\n\n if (!finalImportJobStates.includes(importJobState.UPDATE)) { // eslint-disable-line\n await setImportJobState({correlationId, operation: 'UPDATE', importJobState: IMPORT_JOB_STATE.ABORT});\n }\n\n await setState({correlationId, state: QUEUE_ITEM_STATE.ABORT, errorStatus: httpStatus.REQUEST_TIMEOUT, errorMessage: `Timeout in ${oldState}`});\n\n return false;\n }\n\n return true;\n }\n\n async function remove(params) {\n logger.silly(`${JSON.stringify(params)}`);\n logger.info(`Removing from Mongo (${collection}) id: ${params.correlationId}`);\n const clean = sanitize(params.correlationId);\n logger.silly(`mongo/remove: clean: ${JSON.stringify(clean)}`);\n\n try {\n //const metadataResult = await getFileMetadata({filename: clean});\n //logger.debug(`mongo/remove: metadataResult: ${JSON.stringify(metadataResult)}`);\n const noContent = await removeContent(params);\n if (noContent) {\n await db.collection(collection).deleteOne({correlationId: clean});\n return true;\n }\n } catch (err) {\n if (err instanceof MongoDriverError) {\n if (err.message.indexOf('File not found for id') !== -1) {\n logger.silly(`mongo/remove: File not found, removing queueItem ${JSON.stringify(clean)} from ${collection}`);\n await db.collection(collection).deleteOne({correlationId: clean});\n return true;\n }\n logger.error(err.message);\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, err.message);\n }\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, err.message);\n }\n }\n\n async function readContent(correlationId) {\n logger.info(`Reading content from mongo for id: ${correlationId} in ${collection}`);\n const clean = sanitize(correlationId);\n const result = await db.collection(collection).findOne({correlationId: clean}); // njsscan-ignore: node_nosqli_injection\n\n if (result) {\n const {operationSettings} = result;\n if (operationSettings.prio === false && operationSettings.noStream === false) {\n return {\n contentType: result.contentType,\n readStream: gridFSBucket.openDownloadStreamByName(clean)\n };\n }\n logger.debug(`OperationSetting for ${correlationId}: ${JSON.stringify(operationSettings)}`);\n throw new ApiError(httpStatus.BAD_REQUEST, {message: `Content is only available for streamBulk jobs. ${correlationId} is not a streamBulk job.`});\n }\n\n throw new ApiError(httpStatus.NOT_FOUND, {message: `Job ${correlationId} not found.`});\n }\n\n async function removeContent(params) {\n logger.info(`Removing content from mongo for id: ${params.correlationId} in ${collection}`);\n const clean = sanitize(params.correlationId);\n\n const result = await db.collection(collection).findOne({correlationId: clean}); // njsscan-ignore: node_nosqli_injection\n logger.silly(`mongo/removeContent: result ${JSON.stringify(result)}`);\n\n if (result) {\n await gridFSBucket.delete(clean);\n return true;\n }\n\n return true;\n }\n\n // eslint-disable-next-line max-statements\n function getOne({queueItemState, importJobState = undefined}) {\n\n logger.silly(`queueItemState: ${queueItemState}, importJobState: ${JSON.stringify(importJobState)}`);\n const cleanQueueItemState = queueItemState ? {queueItemState: sanitize(queueItemState)} : undefined;\n\n try {\n\n // Just queueItemState\n if (queueItemState && importJobState === undefined) {\n logger.silly(`Checking DB ${collection} for just ${JSON.stringify(cleanQueueItemState.queueItemState)}`);\n return db.collection(collection).findOne({...cleanQueueItemState});\n }\n\n // importJobState\n if (importJobState && queueItemState === undefined) {\n logger.silly(`Checking DB ${collection} for ${JSON.stringify(importJobState)}`);\n return db.collection(collection).findOne({...importJobState});\n }\n\n // importJobState and queueItemState\n if (importJobState && queueItemState) {\n logger.silly(`Checking DB ${collection} for ${queueItemState} and ${JSON.stringify(importJobState)}`);\n return db.collection(collection).findOne({...cleanQueueItemState, ...importJobState});\n }\n\n logger.debug(`getOne not working!`);\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, 'Missing parameters, cannot get queueItem');\n\n } catch (error) {\n logError(error);\n }\n }\n\n function getStream(correlationId) {\n logger.info(`Forming stream from mongo for ${correlationId} in ${collection}`);\n const clean = sanitize(correlationId);\n try {\n // Return content stream\n return gridFSBucket.openDownloadStreamByName(clean);\n } catch (error) {\n logError(error);\n }\n }\n\n async function pushIds({correlationId, handledIds, rejectedIds}) {\n logger.verbose(`Push ids (${handledIds.length}) and rejectedIds (${rejectedIds.length}) ${correlationId} to ${collection}`);\n logger.debug(`ids (${handledIds.length}): ${JSON.stringify(handledIds)}, rejectedIds ${rejectedIds.length}: ${JSON.stringify(rejectedIds)}`);\n const clean = sanitize(correlationId);\n await db.collection(collection).updateOne({\n correlationId: clean\n }, {\n $set: {\n modificationTime: moment().toDate()\n },\n $push: {\n handledIds: {$each: handledIds},\n rejectedIds: {$each: rejectedIds}\n }\n });\n }\n\n async function pushMessages({correlationId, messages, messageField = 'messages'}) {\n logger.verbose(`Push messages (${messages.length}) to ${messageField} ${correlationId} to ${collection}`);\n logger.silly(`Messages (${messages.length}): ${JSON.stringify(messages)}}`);\n const clean = sanitize(correlationId);\n const cleanMessageField = sanitize(messageField);\n await db.collection(collection).updateOne({\n correlationId: clean\n }, {\n $set: {\n modificationTime: moment().toDate()\n },\n $push: {\n [cleanMessageField]: {$each: messages}\n }\n });\n }\n\n function setState({correlationId, state, errorMessage = undefined, errorStatus = undefined}) {\n const errorString = errorMessage || errorStatus ? `, Error message: '${JSON.stringify(errorMessage) || ''}', Error status: '${errorStatus || ''}'` : '';\n logger.info(`Setting queue-item state ${state} for ${correlationId}${errorString} to ${collection}`);\n\n const stateInQueueItemStates = Object.values(QUEUE_ITEM_STATE).indexOf(state) > -1;\n const stateInQueueItemStatesValidator = Object.values(QUEUE_ITEM_STATE.VALIDATOR).indexOf(state) > -1;\n const stateInQueueItemStatesImporter = Object.values(QUEUE_ITEM_STATE.IMPORTER).indexOf(state) > -1;\n if (!stateInQueueItemStates && !stateInQueueItemStatesValidator && !stateInQueueItemStatesImporter) {\n throw new ApiError(httpStatus.BAD_REQUEST, 'Trying to set invalid state');\n }\n\n const clean = sanitize(correlationId);\n const updateValues = {\n queueItemState: state,\n modificationTime: moment().toDate(),\n errorMessage,\n errorStatus\n };\n\n // Do not update value that are undefined\n // eslint-disable-next-line functional/immutable-data\n Object.keys(updateValues).forEach(key => updateValues[key] === undefined && delete updateValues[key]);\n\n return db.collection(collection)\n .findOneAndUpdate(\n {correlationId: clean},\n {$set: updateValues},\n {projection: {_id: 0}, returnNewDocument: true}\n );\n }\n\n function setImportJobState({correlationId, operation, importJobState}) {\n\n // should this also get importJobState as previously created object? {}\n logger.info(`Setting queue-item importJobState: {${operation}: ${importJobState}} for ${correlationId}`);\n const cleanCorrelationId = sanitize(correlationId);\n const cleanImportJobState = sanitize(importJobState);\n\n if (!(operation in OPERATIONS)) {\n throw new ApiError('400', 'Invalid operation for import job state');\n }\n\n if (!(cleanImportJobState in IMPORT_JOB_STATE)) {\n throw new ApiError('400', 'Invalid import job state');\n }\n\n const newJobState = operation === OPERATIONS.CREATE ? {'importJobState.CREATE': cleanImportJobState} : {'importJobState.UPDATE': cleanImportJobState};\n return db.collection(collection).findOneAndUpdate({\n correlationId: cleanCorrelationId\n }, {\n $set: {\n ...newJobState,\n modificationTime: moment().toDate()\n }\n }, {projection: {_id: 0}, returnNewDocument: true});\n }\n\n async function setOperation({correlationId, operation}) {\n const newOperation = operation;\n const {operation: oldOperation} = await db.collection(collection).findOne({correlationId});\n logger.info(`Setting queue-item operation from ${oldOperation} to ${newOperation} for ${correlationId} to ${collection}`);\n const cleanCorrelationId = sanitize(correlationId);\n const cleanNewOperation = sanitize(newOperation);\n\n const result = await db.collection(collection).findOneAndUpdate({\n correlationId: cleanCorrelationId\n }, {\n $set: {\n operation: cleanNewOperation,\n modificationTime: moment().toDate()\n }\n }, {projection: {_id: 0}, returnNewDocument: true});\n\n return result.ok;\n // logger.debug(JSON.stringify(result));\n }\n\n async function setOperations({correlationId, addOperation, removeOperation = undefined}) {\n const cleanCorrelationId = sanitize(correlationId);\n\n const queueItem = await db.collection(collection).findOne({correlationId: cleanCorrelationId});\n logger.silly(`We found a queueItem: ${JSON.stringify(queueItem)}`);\n\n const oldOperations = queueItem.operations;\n\n logger.info(`Setting queue-item operations from ${JSON.stringify(oldOperations)} by adding ${addOperation} and removing ${removeOperation} for ${correlationId} to ${collection}`);\n\n const operationsAfterRemove = oldOperations.filter(operation => operation !== removeOperation);\n const operationsAfterRemoveAndAdd = operationsAfterRemove.includes(addOperation) ? operationsAfterRemove : [...operationsAfterRemove, addOperation];\n\n logger.silly(`operationsAfterRemove: ${operationsAfterRemove}`);\n logger.silly(`operationAfterRemoveAndAdd: ${operationsAfterRemoveAndAdd}`);\n\n const result = await db.collection(collection).findOneAndUpdate({\n correlationId: cleanCorrelationId\n }, {\n $set: {\n operations: operationsAfterRemoveAndAdd,\n modificationTime: moment().toDate()\n }\n }, {projection: {_id: 0}, returnNewDocument: true});\n\n return result.ok;\n // logger.debug(JSON.stringify(result));\n }\n\n async function addBlobSize({correlationId}) {\n const cleanCorrelationId = sanitize(correlationId);\n\n const result = await db.collection(collection).findOneAndUpdate({\n correlationId: cleanCorrelationId,\n queueItemState: QUEUE_ITEM_STATE.VALIDATOR.WAITING_FOR_RECORDS\n }, {\n $inc: {\n blobSize: 1\n },\n $set: {\n modificationTime: moment().toDate()\n }\n }, {projection: {_id: 0}, returnNewDocument: true});\n\n logger.verbose(`AddBlobSizeResult in mongo: ${JSON.stringify(result)}`);\n return result;\n }\n\n async function setBlobSize({correlationId, blobSize}) {\n const cleanCorrelationId = sanitize(correlationId);\n const cleanBlobSize = sanitize(blobSize);\n\n const result = await db.collection(collection).findOneAndUpdate({\n correlationId: cleanCorrelationId\n }, {\n $set: {\n blobSize: cleanBlobSize,\n modificationTime: moment().toDate()\n }\n }, {projection: {_id: 0}, returnNewDocument: true});\n\n logger.verbose(`SetBlobSizeResult in mongo: ${JSON.stringify(result)}`);\n return result;\n }\n\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AJL,CAHkB,EAUlB;MAACyD,UAAU,EAAE;QAACC,GAAG,EAAE;MAAN,CAAb;MAAuByD,iBAAiB,EAAE;IAA1C,CAVkB,CAArB;IAYAxJ,MAAM,CAACoI,OAAP,CAAgB,+BAA8BnB,IAAI,CAACC,SAAL,CAAe1D,MAAf,CAAuB,EAArE;IACA,OAAOA,MAAP;EACD;;EAED,eAAe3B,WAAf,CAA2B;IAACC,aAAD;IAAgBe;EAAhB,CAA3B,EAAsD;IACpD,MAAM4G,kBAAkB,GAAG,IAAArC,sBAAA,EAAStF,aAAT,CAA3B;IACA,MAAM2I,aAAa,GAAG,IAAArD,sBAAA,EAASvE,QAAT,CAAtB;IAEA,MAAMW,MAAM,GAAG,MAAMjD,EAAE,CAACR,UAAH,CAAcA,UAAd,EAA0BwJ,gBAA1B,CAA2C;MAC9DzH,aAAa,EAAE2H;IAD+C,CAA3C,EAElB;MACDnB,IAAI,EAAE;QACJzF,QAAQ,EAAE4H,aADN;QAEJlH,gBAAgB,EAAE,IAAAnB,eAAA,IAASC,MAAT;MAFd;IADL,CAFkB,EAOlB;MAACyD,UAAU,EAAE;QAACC,GAAG,EAAE;MAAN,CAAb;MAAuByD,iBAAiB,EAAE;IAA1C,CAPkB,CAArB;IASAxJ,MAAM,CAACoI,OAAP,CAAgB,+BAA8BnB,IAAI,CAACC,SAAL,CAAe1D,MAAf,CAAuB,EAArE;IACA,OAAOA,MAAP;EACD;AAEF"}
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = _default;
7
+
8
+ var _mongodb = require("mongodb");
9
+
10
+ var _melindaBackendCommons = require("@natlibfi/melinda-backend-commons");
11
+
12
+ var _melindaCommons = require("@natlibfi/melinda-commons");
13
+
14
+ var _utils = require("./utils.js");
15
+
16
+ var _moment = _interopRequireDefault(require("moment"));
17
+
18
+ var _httpStatus = _interopRequireDefault(require("http-status"));
19
+
20
+ var _mongoSanitize = _interopRequireDefault(require("mongo-sanitize"));
21
+
22
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
+
24
+ /**
25
+ *
26
+ * @licstart The following is the entire license notice for the JavaScript code in this file.
27
+ *
28
+ * Shared modules for microservices of Melinda rest api batch import system
29
+ *
30
+ * Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
31
+ *
32
+ * This file is part of melinda-rest-api-commons
33
+ *
34
+ * melinda-rest-api-commons program is free software: you can redistribute it and/or modify
35
+ * it under the terms of the GNU Affero General Public License as
36
+ * published by the Free Software Foundation, either version 3 of the
37
+ * License, or (at your option) any later version.
38
+ *
39
+ * melinda-rest-api-commons is distributed in the hope that it will be useful,
40
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
41
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
42
+ * GNU Affero General Public License for more details.
43
+ *
44
+ * You should have received a copy of the GNU Affero General Public License
45
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
46
+ *
47
+ * @licend The above is the entire license notice
48
+ * for the JavaScript code in this file.
49
+ *
50
+ */
51
+ async function _default(MONGO_URI) {
52
+ const logger = (0, _melindaBackendCommons.createLogger)(); // Connect to mongo (MONGO)
53
+
54
+ const client = await _mongodb.MongoClient.connect(MONGO_URI, {
55
+ useNewUrlParser: true,
56
+ useUnifiedTopology: true
57
+ });
58
+ const db = client.db('rest-api');
59
+ const collection = 'logs';
60
+ return {
61
+ addLogItem,
62
+ query,
63
+ queryById,
64
+ remove
65
+ };
66
+
67
+ async function addLogItem(logItem) {
68
+ const time = (0, _moment.default)().toDate();
69
+ const newLogItem = { ...logItem,
70
+ creationTime: time
71
+ };
72
+
73
+ try {
74
+ const result = await db.collection(collection).insertOne(newLogItem);
75
+
76
+ if (result.acknowledged) {
77
+ logger.info(`*** New ${logItem.logItemType} added for ${logItem.correlationId} items ${logItem.blobSequenceStart}-${logItem.blobSequenceEnd}. ***`);
78
+ return;
79
+ }
80
+
81
+ throw new _melindaCommons.Error(_httpStatus.default.INTERNAL_SERVER_ERROR);
82
+ } catch (error) {
83
+ (0, _utils.logError)(error);
84
+ throw new _melindaCommons.Error(_httpStatus.default.INTERNAL_SERVER_ERROR);
85
+ }
86
+ }
87
+
88
+ async function query(params) {
89
+ logger.debug(`Query params: ${JSON.stringify(params)}`);
90
+ const result = await db.collection(collection).find(params).toArray();
91
+ logger.debug(result);
92
+ logger.debug(`Query result: ${result.length > 0 ? `Found ${result.length} log items!` : 'Not found!'}`);
93
+ return result;
94
+ }
95
+
96
+ async function queryById(correlationIdString) {
97
+ logger.debug(`QueryById: ${correlationIdString}`);
98
+ const result = await db.collection(collection).find({
99
+ correlationId: correlationIdString
100
+ }).toArray();
101
+ logger.debug(`Query result: ${result.length > 0 ? `Found ${result.length} log items!` : 'Not found!'}`);
102
+ return result;
103
+ }
104
+
105
+ async function remove(params) {
106
+ logger.silly(`${JSON.stringify(params)}`);
107
+ logger.info(`Removing from Mongo (${collection}) correlationId: ${params.correlationId}`);
108
+ const clean = (0, _mongoSanitize.default)(params.correlationId);
109
+ logger.silly(`mongo/remove: clean: ${JSON.stringify(clean)}`);
110
+
111
+ try {
112
+ await db.collection(collection).deleteMany({
113
+ correlationId: clean
114
+ });
115
+ return true;
116
+ } catch (err) {
117
+ throw new _melindaCommons.Error(_httpStatus.default.INTERNAL_SERVER_ERROR, err.message);
118
+ }
119
+ }
120
+ }
121
+ //# sourceMappingURL=mongoLog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mongoLog.js","names":["MONGO_URI","logger","createLogger","client","MongoClient","connect","useNewUrlParser","useUnifiedTopology","db","collection","addLogItem","query","queryById","remove","logItem","time","moment","toDate","newLogItem","creationTime","result","insertOne","acknowledged","info","logItemType","correlationId","blobSequenceStart","blobSequenceEnd","ApiError","httpStatus","INTERNAL_SERVER_ERROR","error","logError","params","debug","JSON","stringify","find","toArray","length","correlationIdString","silly","clean","sanitize","deleteMany","err","message"],"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';\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, remove};\n\n async function addLogItem(logItem) {\n const time = moment().toDate();\n const newLogItem = {\n ...logItem,\n creationTime: time\n };\n try {\n const result = await db.collection(collection).insertOne(newLogItem);\n if (result.acknowledged) {\n logger.info(`*** New ${logItem.logItemType} added for ${logItem.correlationId} items ${logItem.blobSequenceStart}-${logItem.blobSequenceEnd}. ***`);\n return;\n }\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR);\n } catch (error) {\n logError(error);\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR);\n }\n }\n\n\n async function query(params) {\n logger.debug(`Query params: ${JSON.stringify(params)}`);\n const result = await db.collection(collection).find(params).toArray();\n logger.debug(result);\n logger.debug(`Query result: ${result.length > 0 ? `Found ${result.length} log items!` : 'Not found!'}`);\n return result;\n }\n\n async function queryById(correlationIdString) {\n logger.debug(`QueryById: ${correlationIdString}`);\n const result = await db.collection(collection).find({correlationId: correlationIdString}).toArray();\n logger.debug(`Query result: ${result.length > 0 ? `Found ${result.length} log items!` : 'Not found!'}`);\n return result;\n }\n\n async function remove(params) {\n logger.silly(`${JSON.stringify(params)}`);\n logger.info(`Removing from Mongo (${collection}) correlationId: ${params.correlationId}`);\n const clean = sanitize(params.correlationId);\n logger.silly(`mongo/remove: clean: ${JSON.stringify(clean)}`);\n\n try {\n await db.collection(collection).deleteMany({correlationId: clean});\n return true;\n } catch (err) {\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, err.message);\n }\n }\n}\n"],"mappings":";;;;;;;AA4BA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;AAlCA;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;AAUe,wBAAgBA,SAAhB,EAA2B;EACxC,MAAMC,MAAM,GAAG,IAAAC,mCAAA,GAAf,CADwC,CAGxC;;EACA,MAAMC,MAAM,GAAG,MAAMC,oBAAA,CAAYC,OAAZ,CAAoBL,SAApB,EAA+B;IAACM,eAAe,EAAE,IAAlB;IAAwBC,kBAAkB,EAAE;EAA5C,CAA/B,CAArB;EACA,MAAMC,EAAE,GAAGL,MAAM,CAACK,EAAP,CAAU,UAAV,CAAX;EACA,MAAMC,UAAU,GAAG,MAAnB;EACA,OAAO;IAACC,UAAD;IAAaC,KAAb;IAAoBC,SAApB;IAA+BC;EAA/B,CAAP;;EAEA,eAAeH,UAAf,CAA0BI,OAA1B,EAAmC;IACjC,MAAMC,IAAI,GAAG,IAAAC,eAAA,IAASC,MAAT,EAA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MAACZ,aAAa,EAAEe;IAAhB,CAA/B,EAAqEF,OAArE,EAArB;IACArC,MAAM,CAACiC,KAAP,CAAc,iBAAgBd,MAAM,CAACmB,MAAP,GAAgB,CAAhB,GAAqB,SAAQnB,MAAM,CAACmB,MAAO,aAA3C,GAA0D,YAAa,EAArG;IACA,OAAOnB,MAAP;EACD;;EAED,eAAeP,MAAf,CAAsBoB,MAAtB,EAA8B;IAC5BhC,MAAM,CAACwC,KAAP,CAAc,GAAEN,IAAI,CAACC,SAAL,CAAeH,MAAf,CAAuB,EAAvC;IACAhC,MAAM,CAACsB,IAAP,CAAa,wBAAuBd,UAAW,oBAAmBwB,MAAM,CAACR,aAAc,EAAvF;IACA,MAAMiB,KAAK,GAAG,IAAAC,sBAAA,EAASV,MAAM,CAACR,aAAhB,CAAd;IACAxB,MAAM,CAACwC,KAAP,CAAc,wBAAuBN,IAAI,CAACC,SAAL,CAAeM,KAAf,CAAsB,EAA3D;;IAEA,IAAI;MACF,MAAMlC,EAAE,CAACC,UAAH,CAAcA,UAAd,EAA0BmC,UAA1B,CAAqC;QAACnB,aAAa,EAAEiB;MAAhB,CAArC,CAAN;MACA,OAAO,IAAP;IACD,CAHD,CAGE,OAAOG,GAAP,EAAY;MACZ,MAAM,IAAIjB,qBAAJ,CAAaC,mBAAA,CAAWC,qBAAxB,EAA+Ce,GAAG,CAACC,OAAnD,CAAN;IACD;EACF;AACF"}
package/dist/utils.js CHANGED
@@ -3,7 +3,9 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.addRecordResponseItem = addRecordResponseItem;
6
7
  exports.createImportJobState = createImportJobState;
8
+ exports.createRecordResponseItem = createRecordResponseItem;
7
9
  exports.logError = logError;
8
10
 
9
11
  var _melindaBackendCommons = require("@natlibfi/melinda-backend-commons");
@@ -12,6 +14,10 @@ var _melindaCommons = require("@natlibfi/melinda-commons");
12
14
 
13
15
  var _constants = require("./constants");
14
16
 
17
+ var _httpStatus = _interopRequireDefault(require("http-status"));
18
+
19
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
20
+
15
21
  /**
16
22
  *
17
23
  * @licstart The following is the entire license notice for the JavaScript code in this file.
@@ -76,4 +82,131 @@ function createImportJobState(operation, state, queryImportJobState = false) {
76
82
  [operation]: state
77
83
  };
78
84
  }
85
+
86
+ function createRecordResponseItem({
87
+ responsePayload,
88
+ responseStatus,
89
+ recordMetadata,
90
+ id
91
+ }) {
92
+ const recordResponseStatusAndMessage = getRecordResponseStatusAndMessage(responseStatus, responsePayload);
93
+ const recordResponseItem = {
94
+ databaseId: id || '000000000',
95
+ recordMetadata: responsePayload.recordMetadata || recordMetadata || undefined,
96
+ ...recordResponseStatusAndMessage
97
+ };
98
+ return recordResponseItem;
99
+ } // eslint-disable-next-line max-statements
100
+
101
+
102
+ function getRecordResponseStatusAndMessage(responseStatus, responsePayload) {
103
+ logger.debug(`Response status: ${responseStatus} responsePayload: ${JSON.stringify(responsePayload)}`);
104
+ const responseStatusName = _httpStatus.default[`${responseStatus}_NAME`];
105
+ logger.debug(`Response status name: ${responseStatusName}`);
106
+ const message = getMessageFromResponsePayload(responsePayload);
107
+ logger.debug(`Response message: ${message}`); // Non-http statuses
108
+
109
+ if (['UPDATED', 'CREATED', 'INVALID', 'ERROR'].includes(responseStatus)) {
110
+ return {
111
+ status: responseStatus,
112
+ message
113
+ };
114
+ }
115
+
116
+ if (['UNKNOWN'].includes(responseStatus)) {
117
+ const possibleIds = responsePayload.ids || [];
118
+ return {
119
+ status: responseStatus,
120
+ message,
121
+ possibleIds
122
+ };
123
+ } // Duplicates and other CONFLICT statuses
124
+
125
+
126
+ if ([_httpStatus.default.CONFLICT, 'CONFLICT'].includes(responseStatus)) {
127
+ if (/^Duplicates in database/u.test(message)) {
128
+ const duplicateIds = responsePayload.ids || [];
129
+ return {
130
+ status: 'DUPLICATE',
131
+ message,
132
+ duplicateIds
133
+ };
134
+ }
135
+
136
+ if (/^MatchValidation for all/u.test(message)) {
137
+ const duplicateIds = responsePayload.ids || [];
138
+ return {
139
+ status: 'CONFLICT',
140
+ message,
141
+ duplicateIds
142
+ };
143
+ }
144
+
145
+ const conflictIds = responsePayload.ids || [];
146
+
147
+ if (conflictIds.length > 0) {
148
+ return {
149
+ status: 'CONFLICT',
150
+ message,
151
+ conflictIds
152
+ };
153
+ }
154
+
155
+ return {
156
+ status: 'CONFLICT',
157
+ message
158
+ };
159
+ }
160
+
161
+ if ([_httpStatus.default.UNPROCESSABLE_ENTITY, 'UNPROCESSABLE_ENTITY'].includes(responseStatus)) {
162
+ const unprocessableIds = responsePayload.ids || [];
163
+ const response = unprocessableIds.length > 0 ? {
164
+ status: 'UNPROCESSABLE_ENTITY',
165
+ message,
166
+ unprocessableIds
167
+ } : {
168
+ status: 'UNPROCESSABLE_ENTITY',
169
+ message
170
+ };
171
+ return response;
172
+ }
173
+
174
+ if ([_httpStatus.default.NOT_FOUND, 'NOT_FOUND'].includes(responseStatus)) {
175
+ return {
176
+ status: 'NOT_FOUND',
177
+ message
178
+ };
179
+ } // Otherwise
180
+
181
+
182
+ return {
183
+ status: 'ERROR',
184
+ message
185
+ };
186
+ }
187
+
188
+ function getMessageFromResponsePayload(responsePayload) {
189
+ if (responsePayload.message) {
190
+ return responsePayload.message;
191
+ }
192
+
193
+ if (typeof responsePayload === 'string' || responsePayload instanceof String) {
194
+ return responsePayload;
195
+ }
196
+
197
+ return '';
198
+ }
199
+
200
+ async function addRecordResponseItem({
201
+ recordResponseItem,
202
+ correlationId,
203
+ mongoOperator
204
+ }) {
205
+ await mongoOperator.pushMessages({
206
+ correlationId,
207
+ messages: [recordResponseItem],
208
+ messageField: 'records'
209
+ });
210
+ return true;
211
+ }
79
212
  //# sourceMappingURL=utils.js.map
package/dist/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/utils.js"],"names":["logger","logError","err","ApiError","error","JSON","stringify","stack","undefined","createImportJobState","operation","state","queryImportJobState","IMPORT_JOB_STATE","Error","OPERATIONS","importJobStateWithOperation","importJobStateForQuery"],"mappings":";;;;;;;;AA4BA;;AACA;;AACA;;AA9BA;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;AAMA,MAAMA,MAAM,GAAG,0CAAf;;AAEO,SAASC,QAAT,CAAkBC,GAAlB,EAAuB;AAC5B,MAAIA,GAAG,YAAYC,qBAAnB,EAA6B;AAC3BH,IAAAA,MAAM,CAACI,KAAP,CAAaC,IAAI,CAACC,SAAL,CAAeJ,GAAf,CAAb;AACA;AACD;;AAED,MAAIA,GAAG,KAAK,QAAZ,EAAsB;AACpBF,IAAAA,MAAM,CAACI,KAAP,CAAaF,GAAb;AACA;AACD;;AAEDF,EAAAA,MAAM,CAACI,KAAP,CAAaF,GAAG,CAACK,KAAJ,KAAcC,SAAd,GAA0BN,GAA1B,GAAgCA,GAAG,CAACK,KAAjD;AACD;;AAEM,SAASE,oBAAT,CAA8BC,SAA9B,EAAyCC,KAAzC,EAAgDC,mBAAmB,GAAG,KAAtE,EAA6E;AAClF,MAAI,EAAED,KAAK,IAAIE,2BAAX,CAAJ,EAAkC;AAChC,UAAM,IAAIC,KAAJ,CAAU,0BAAV,CAAN;AACD;;AAED,MAAI,EAAEJ,SAAS,IAAIK,qBAAf,CAAJ,EAAgC;AAC9B,UAAM,IAAID,KAAJ,CAAU,mBAAV,CAAN;AACD;;AAED,MAAIF,mBAAJ,EAAyB;AACvB,UAAMI,2BAA2B,GAAI,kBAAiBN,SAAU,EAAhE;AACA,UAAMO,sBAAsB,GAAG;AAAC,OAACD,2BAAD,GAA+BL;AAAhC,KAA/B;AAEA,WAAOM,sBAAP;AACD;;AAED,SAAO;AAAC,KAACP,SAAD,GAAaC;AAAd,GAAP;AACD","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 {createLogger} from '@natlibfi/melinda-backend-commons';\nimport {Error as ApiError} from '@natlibfi/melinda-commons';\nimport {IMPORT_JOB_STATE, OPERATIONS} from './constants';\n\nconst logger = createLogger();\n\nexport function logError(err) {\n if (err instanceof ApiError) {\n logger.error(JSON.stringify(err));\n return;\n }\n\n if (err === 'SIGINT') {\n logger.error(err);\n return;\n }\n\n logger.error(err.stack === undefined ? err : err.stack);\n}\n\nexport function createImportJobState(operation, state, queryImportJobState = false) {\n if (!(state in IMPORT_JOB_STATE)) {\n throw new Error('Invalid IMPORT_JOB_STATE');\n }\n\n if (!(operation in OPERATIONS)) {\n throw new Error('Invalid operation');\n }\n\n if (queryImportJobState) {\n const importJobStateWithOperation = `importJobState.${operation}`;\n const importJobStateForQuery = {[importJobStateWithOperation]: state};\n\n return importJobStateForQuery;\n }\n\n return {[operation]: state};\n}\n"],"file":"utils.js"}
1
+ {"version":3,"file":"utils.js","names":["logger","createLogger","logError","err","ApiError","error","JSON","stringify","stack","undefined","createImportJobState","operation","state","queryImportJobState","IMPORT_JOB_STATE","Error","OPERATIONS","importJobStateWithOperation","importJobStateForQuery","createRecordResponseItem","responsePayload","responseStatus","recordMetadata","id","recordResponseStatusAndMessage","getRecordResponseStatusAndMessage","recordResponseItem","databaseId","debug","responseStatusName","httpStatus","message","getMessageFromResponsePayload","includes","status","possibleIds","ids","CONFLICT","test","duplicateIds","conflictIds","length","UNPROCESSABLE_ENTITY","unprocessableIds","response","NOT_FOUND","String","addRecordResponseItem","correlationId","mongoOperator","pushMessages","messages","messageField"],"sources":["../src/utils.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 {createLogger} from '@natlibfi/melinda-backend-commons';\nimport {Error as ApiError} from '@natlibfi/melinda-commons';\nimport {IMPORT_JOB_STATE, OPERATIONS} from './constants';\nimport httpStatus from 'http-status';\n\nconst logger = createLogger();\n\nexport function logError(err) {\n if (err instanceof ApiError) {\n logger.error(JSON.stringify(err));\n return;\n }\n\n if (err === 'SIGINT') {\n logger.error(err);\n return;\n }\n\n logger.error(err.stack === undefined ? err : err.stack);\n}\n\nexport function createImportJobState(operation, state, queryImportJobState = false) {\n if (!(state in IMPORT_JOB_STATE)) {\n throw new Error('Invalid IMPORT_JOB_STATE');\n }\n\n if (!(operation in OPERATIONS)) {\n throw new Error('Invalid operation');\n }\n\n if (queryImportJobState) {\n const importJobStateWithOperation = `importJobState.${operation}`;\n const importJobStateForQuery = {[importJobStateWithOperation]: state};\n\n return importJobStateForQuery;\n }\n\n return {[operation]: state};\n}\n\nexport function createRecordResponseItem({responsePayload, responseStatus, recordMetadata, id}) {\n const recordResponseStatusAndMessage = getRecordResponseStatusAndMessage(responseStatus, responsePayload);\n const recordResponseItem = {\n databaseId: id || '000000000',\n recordMetadata: responsePayload.recordMetadata || recordMetadata || undefined,\n ...recordResponseStatusAndMessage\n };\n return recordResponseItem;\n}\n\n// eslint-disable-next-line max-statements\nfunction getRecordResponseStatusAndMessage(responseStatus, responsePayload) {\n\n logger.debug(`Response status: ${responseStatus} responsePayload: ${JSON.stringify(responsePayload)}`);\n const responseStatusName = httpStatus[`${responseStatus}_NAME`];\n logger.debug(`Response status name: ${responseStatusName}`);\n\n const message = getMessageFromResponsePayload(responsePayload);\n\n logger.debug(`Response message: ${message}`);\n\n // Non-http statuses\n if (['UPDATED', 'CREATED', 'INVALID', 'ERROR'].includes(responseStatus)) {\n return {status: responseStatus, message};\n }\n\n if (['UNKNOWN'].includes(responseStatus)) {\n const possibleIds = responsePayload.ids || [];\n return {status: responseStatus, message, possibleIds};\n }\n\n // Duplicates and other CONFLICT statuses\n if ([httpStatus.CONFLICT, 'CONFLICT'].includes(responseStatus)) {\n if ((/^Duplicates in database/u).test(message)) {\n const duplicateIds = responsePayload.ids || [];\n return {status: 'DUPLICATE', message, duplicateIds};\n }\n if ((/^MatchValidation for all/u).test(message)) {\n const duplicateIds = responsePayload.ids || [];\n return {status: 'CONFLICT', message, duplicateIds};\n }\n const conflictIds = responsePayload.ids || [];\n if (conflictIds.length > 0) {\n return {status: 'CONFLICT', message, conflictIds};\n }\n return {status: 'CONFLICT', message};\n }\n\n if ([httpStatus.UNPROCESSABLE_ENTITY, 'UNPROCESSABLE_ENTITY'].includes(responseStatus)) {\n const unprocessableIds = responsePayload.ids || [];\n const response = unprocessableIds.length > 0 ? {status: 'UNPROCESSABLE_ENTITY', message, unprocessableIds} : {status: 'UNPROCESSABLE_ENTITY', message};\n return response;\n }\n\n if ([httpStatus.NOT_FOUND, 'NOT_FOUND'].includes(responseStatus)) {\n return {status: 'NOT_FOUND', message};\n }\n\n // Otherwise\n return {status: 'ERROR', message};\n}\n\nfunction getMessageFromResponsePayload(responsePayload) {\n if (responsePayload.message) {\n return responsePayload.message;\n }\n if (typeof responsePayload === 'string' || responsePayload instanceof String) {\n return responsePayload;\n }\n return '';\n}\n\nexport async function addRecordResponseItem({recordResponseItem, correlationId, mongoOperator}) {\n await mongoOperator.pushMessages({correlationId, messages: [recordResponseItem], messageField: 'records'});\n return true;\n}\n\n"],"mappings":";;;;;;;;;;AA4BA;;AACA;;AACA;;AACA;;;;AA/BA;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;AAOA,MAAMA,MAAM,GAAG,IAAAC,mCAAA,GAAf;;AAEO,SAASC,QAAT,CAAkBC,GAAlB,EAAuB;EAC5B,IAAIA,GAAG,YAAYC,qBAAnB,EAA6B;IAC3BJ,MAAM,CAACK,KAAP,CAAaC,IAAI,CAACC,SAAL,CAAeJ,GAAf,CAAb;IACA;EACD;;EAED,IAAIA,GAAG,KAAK,QAAZ,EAAsB;IACpBH,MAAM,CAACK,KAAP,CAAaF,GAAb;IACA;EACD;;EAEDH,MAAM,CAACK,KAAP,CAAaF,GAAG,CAACK,KAAJ,KAAcC,SAAd,GAA0BN,GAA1B,GAAgCA,GAAG,CAACK,KAAjD;AACD;;AAEM,SAASE,oBAAT,CAA8BC,SAA9B,EAAyCC,KAAzC,EAAgDC,mBAAmB,GAAG,KAAtE,EAA6E;EAClF,IAAI,EAAED,KAAK,IAAIE,2BAAX,CAAJ,EAAkC;IAChC,MAAM,IAAIC,KAAJ,CAAU,0BAAV,CAAN;EACD;;EAED,IAAI,EAAEJ,SAAS,IAAIK,qBAAf,CAAJ,EAAgC;IAC9B,MAAM,IAAID,KAAJ,CAAU,mBAAV,CAA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T;MAAiCH,OAAjC;MAA0CY;IAA1C,CAA9B,GAA4F;MAACT,MAAM,EAAE,sBAAT;MAAiCH;IAAjC,CAA7G;IACA,OAAOa,QAAP;EACD;;EAED,IAAI,CAACd,mBAAA,CAAWe,SAAZ,EAAuB,WAAvB,EAAoCZ,QAApC,CAA6CZ,cAA7C,CAAJ,EAAkE;IAChE,OAAO;MAACa,MAAM,EAAE,WAAT;MAAsBH;IAAtB,CAAP;EACD,CA7CyE,CA+C1E;;;EACA,OAAO;IAACG,MAAM,EAAE,OAAT;IAAkBH;EAAlB,CAAP;AACD;;AAED,SAASC,6BAAT,CAAuCZ,eAAvC,EAAwD;EACtD,IAAIA,eAAe,CAACW,OAApB,EAA6B;IAC3B,OAAOX,eAAe,CAACW,OAAvB;EACD;;EACD,IAAI,OAAOX,eAAP,KAA2B,QAA3B,IAAuCA,eAAe,YAAY0B,MAAtE,EAA8E;IAC5E,OAAO1B,eAAP;EACD;;EACD,OAAO,EAAP;AACD;;AAEM,eAAe2B,qBAAf,CAAqC;EAACrB,kBAAD;EAAqBsB,aAArB;EAAoCC;AAApC,CAArC,EAAyF;EAC9F,MAAMA,aAAa,CAACC,YAAd,CAA2B;IAACF,aAAD;IAAgBG,QAAQ,EAAE,CAACzB,kBAAD,CAA1B;IAAgD0B,YAAY,EAAE;EAA9D,CAA3B,CAAN;EACA,OAAO,IAAP;AACD"}
package/package.json CHANGED
@@ -14,7 +14,7 @@
14
14
  "url": "git@github.com:natlibfi/melinda-rest-api-commons.git"
15
15
  },
16
16
  "license": "AGPL-3.0+",
17
- "version": "2.2.0-alpha.7",
17
+ "version": "2.3.0-alpha.1",
18
18
  "main": "./dist/index.js",
19
19
  "engines": {
20
20
  "node": ">=14"
@@ -36,21 +36,21 @@
36
36
  "@natlibfi/marc-record": "^7.0.0",
37
37
  "@natlibfi/marc-record-serializers": "^8.1.0",
38
38
  "@natlibfi/marc-record-validate": "^7.0.1",
39
- "@natlibfi/marc-record-validators-melinda": "^9.0.4",
39
+ "@natlibfi/marc-record-validators-melinda": "^9.0.9",
40
40
  "@natlibfi/melinda-backend-commons": "^2.0.5",
41
41
  "@natlibfi/melinda-commons": "^12.0.3",
42
42
  "amqplib": ">=0.8.0 <1.0.0",
43
- "http-status": "^1.5.0",
44
- "moment": "^2.29.1",
43
+ "http-status": "^1.5.2",
44
+ "moment": "^2.29.3",
45
45
  "mongo-sanitize": "^1.1.0",
46
- "mongodb": "^4.1.3"
46
+ "mongodb": "^4.6.0"
47
47
  },
48
48
  "devDependencies": {
49
- "@babel/cli": "^7.17.6",
50
- "@babel/core": "^7.17.5",
49
+ "@babel/cli": "^7.17.10",
50
+ "@babel/core": "^7.17.12",
51
51
  "@babel/eslint-parser": "^7.17.0",
52
52
  "@babel/plugin-syntax-dynamic-import": "^7.8.3",
53
- "@babel/preset-env": "^7.16.11",
53
+ "@babel/preset-env": "^7.17.12",
54
54
  "@natlibfi/eslint-config-melinda-backend": "^2.0.0",
55
55
  "@natlibfi/fixura": "^2.2.1",
56
56
  "babel-plugin-dynamic-import-node": "^2.3.3",
@@ -58,9 +58,9 @@
58
58
  "babel-plugin-rewire": "^1.2.0",
59
59
  "chai": "^4.3.6",
60
60
  "cross-env": "^7.0.3",
61
- "eslint": "^8.10.0",
62
- "mocha": "^9.2.1",
63
- "nodemon": "^2.0.15",
61
+ "eslint": "^8.15.0",
62
+ "mocha": "^10.0.0",
63
+ "nodemon": "^2.0.16",
64
64
  "nyc": "^15.1.0"
65
65
  },
66
66
  "eslintConfig": {