@natlibfi/melinda-rest-api-commons 2.3.2-alpha.6 → 2.3.2-alpha.7
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 +22 -54
- package/dist/amqp.js.map +1 -1
- package/dist/constants.js +5 -3
- package/dist/constants.js.map +1 -1
- package/dist/helpers/conversion.js +5 -25
- package/dist/helpers/conversion.js.map +1 -1
- package/dist/helpers/conversion.spec.js +1 -7
- package/dist/helpers/conversion.spec.js.map +1 -1
- package/dist/helpers/fix-constants.js +6 -4
- package/dist/helpers/fix-constants.js.map +1 -1
- package/dist/helpers/fix-handle-tempurns.js +19 -27
- package/dist/helpers/fix-handle-tempurns.js.map +1 -1
- package/dist/helpers/fix-strip-f884s.js +12 -16
- package/dist/helpers/fix-strip-f884s.js.map +1 -1
- package/dist/helpers/fix-utils.js +9 -15
- package/dist/helpers/fix-utils.js.map +1 -1
- package/dist/helpers/fix.js +17 -32
- package/dist/helpers/fix.js.map +1 -1
- package/dist/helpers/fix.spec.js +1 -12
- package/dist/helpers/fix.spec.js.map +1 -1
- package/dist/helpers/validation.js +0 -6
- package/dist/helpers/validation.js.map +1 -1
- package/dist/helpers/validation.spec.js +1 -7
- package/dist/helpers/validation.spec.js.map +1 -1
- package/dist/index.js +8 -14
- package/dist/index.js.map +1 -1
- package/dist/mongo.js +38 -87
- package/dist/mongo.js.map +1 -1
- package/dist/mongoLog.js +5 -29
- package/dist/mongoLog.js.map +1 -1
- package/dist/utils.js +33 -35
- package/dist/utils.js.map +1 -1
- package/package.json +3 -3
package/dist/amqp.js
CHANGED
|
@@ -4,25 +4,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = _default;
|
|
7
|
-
|
|
8
7
|
var _amqplib = _interopRequireDefault(require("amqplib"));
|
|
9
|
-
|
|
10
8
|
var _marcRecord = require("@natlibfi/marc-record");
|
|
11
|
-
|
|
12
9
|
var _melindaCommons = require("@natlibfi/melinda-commons");
|
|
13
|
-
|
|
14
10
|
var _melindaBackendCommons = require("@natlibfi/melinda-backend-commons");
|
|
15
|
-
|
|
16
11
|
var _constants = require("./constants");
|
|
17
|
-
|
|
18
12
|
var _utils = require("./utils");
|
|
19
|
-
|
|
20
13
|
var _util = require("util");
|
|
21
|
-
|
|
22
14
|
var _httpStatus = _interopRequireDefault(require("http-status"));
|
|
23
|
-
|
|
24
15
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
25
|
-
|
|
26
16
|
/**
|
|
27
17
|
*
|
|
28
18
|
* @licstart The following is the entire license notice for the JavaScript code in this file.
|
|
@@ -50,6 +40,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
50
40
|
* for the JavaScript code in this file.
|
|
51
41
|
*
|
|
52
42
|
*/
|
|
43
|
+
|
|
53
44
|
async function _default(AMQP_URL) {
|
|
54
45
|
const connection = await _amqplib.default.connect(AMQP_URL);
|
|
55
46
|
const channel = await connection.createChannel();
|
|
@@ -63,8 +54,9 @@ async function _default(AMQP_URL) {
|
|
|
63
54
|
sendToQueue,
|
|
64
55
|
removeQueue,
|
|
65
56
|
messagesToRecords
|
|
66
|
-
};
|
|
57
|
+
};
|
|
67
58
|
|
|
59
|
+
// eslint-disable-next-line max-statements
|
|
68
60
|
async function checkQueue({
|
|
69
61
|
queue,
|
|
70
62
|
style = 'basic',
|
|
@@ -72,13 +64,11 @@ async function _default(AMQP_URL) {
|
|
|
72
64
|
purge = false
|
|
73
65
|
}) {
|
|
74
66
|
logger.silly(`checkQueue: ${queue}, Style: ${style}: toRecord: ${toRecord}, Purge: ${purge}`);
|
|
75
|
-
|
|
76
67
|
try {
|
|
77
68
|
errorUndefinedQueue(queue);
|
|
78
69
|
const channelInfo = await channel.assertQueue(queue, {
|
|
79
70
|
durable: true
|
|
80
71
|
});
|
|
81
|
-
|
|
82
72
|
if (purge) {
|
|
83
73
|
await purgeQueue(purge);
|
|
84
74
|
logger.verbose(`Queue ${queue} has purged ${channelInfo.messageCount} messages`);
|
|
@@ -87,57 +77,51 @@ async function _default(AMQP_URL) {
|
|
|
87
77
|
style
|
|
88
78
|
});
|
|
89
79
|
}
|
|
90
|
-
|
|
91
80
|
if (channelInfo.messageCount < 1) {
|
|
92
81
|
logger.silly(`checkQueue: ${channelInfo.messageCount} - ${queue} is empty`);
|
|
93
82
|
return false;
|
|
94
83
|
}
|
|
95
|
-
|
|
96
84
|
logger.silly(`Queue ${queue} has ${channelInfo.messageCount} messages`);
|
|
97
|
-
|
|
98
85
|
if (style === 'messages') {
|
|
99
86
|
return channelInfo.messageCount;
|
|
100
|
-
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Note: returns one message (+ record, of toRecord: true)
|
|
101
90
|
// note: if toRecord is false returns just plain message / false
|
|
102
91
|
// note: if toRecord is true returns {headers, records, messages} -object / false
|
|
103
92
|
// should this be more consistent?
|
|
104
|
-
|
|
105
|
-
|
|
106
93
|
if (style === 'one') {
|
|
107
94
|
return consumeOne(queue, toRecord);
|
|
108
|
-
}
|
|
109
|
-
// returns {headers, records, messages} object or {headers, messages} object depending on toRecord
|
|
110
|
-
|
|
95
|
+
}
|
|
111
96
|
|
|
97
|
+
// Note: returns a chunk of (100) messages (+ records, if toRecord: true)
|
|
98
|
+
// returns {headers, records, messages} object or {headers, messages} object depending on toRecord
|
|
112
99
|
if (style === 'basic') {
|
|
113
100
|
return consumeChunk(queue, toRecord);
|
|
114
|
-
}
|
|
115
|
-
|
|
101
|
+
}
|
|
116
102
|
|
|
103
|
+
// Defaults:
|
|
117
104
|
throw new _melindaCommons.Error(_httpStatus.default.UNPROCESSABLE_ENTITY);
|
|
118
105
|
} catch (error) {
|
|
119
106
|
(0, _utils.logError)(error);
|
|
120
107
|
}
|
|
121
|
-
|
|
122
108
|
function purgeQueue(purge) {
|
|
123
109
|
if (purge) {
|
|
124
110
|
return channel.purgeQueue(queue);
|
|
125
111
|
}
|
|
126
112
|
}
|
|
127
113
|
}
|
|
128
|
-
|
|
129
114
|
async function consumeChunk(queue, toRecord) {
|
|
130
115
|
logger.silly(`Prepared to consumeChunk from queue: ${queue}`);
|
|
131
|
-
|
|
132
116
|
try {
|
|
133
117
|
await channel.assertQueue(queue, {
|
|
134
118
|
durable: true
|
|
135
|
-
});
|
|
119
|
+
});
|
|
136
120
|
|
|
121
|
+
// getData: next chunk (100) messages
|
|
137
122
|
const messages = await getData(queue);
|
|
138
123
|
const headers = getHeaderInfo(messages[0]);
|
|
139
124
|
logger.debug(`consumeChunk (${messages ? messages.length : '0'} from queue ${queue}) ${toRecord ? 'to records' : 'just messages'}`);
|
|
140
|
-
|
|
141
125
|
if (toRecord) {
|
|
142
126
|
const records = await messagesToRecords(messages);
|
|
143
127
|
return {
|
|
@@ -146,7 +130,6 @@ async function _default(AMQP_URL) {
|
|
|
146
130
|
messages
|
|
147
131
|
};
|
|
148
132
|
}
|
|
149
|
-
|
|
150
133
|
return {
|
|
151
134
|
headers,
|
|
152
135
|
messages
|
|
@@ -155,24 +138,22 @@ async function _default(AMQP_URL) {
|
|
|
155
138
|
(0, _utils.logError)(error);
|
|
156
139
|
}
|
|
157
140
|
}
|
|
158
|
-
|
|
159
141
|
async function consumeOne(queue, toRecord) {
|
|
160
142
|
logger.silly(`Prepared to consumeOne from queue: ${queue}`);
|
|
161
|
-
|
|
162
143
|
try {
|
|
163
144
|
await channel.assertQueue(queue, {
|
|
164
145
|
durable: true
|
|
165
|
-
});
|
|
146
|
+
});
|
|
166
147
|
|
|
148
|
+
// Returns false if 0 items in queue
|
|
167
149
|
const message = await channel.get(queue);
|
|
168
150
|
logger.silly(`Message: ${(0, _util.inspect)(message, {
|
|
169
151
|
colors: true,
|
|
170
152
|
maxArrayLength: 3,
|
|
171
153
|
depth: 3
|
|
172
|
-
})}`);
|
|
173
|
-
|
|
154
|
+
})}`);
|
|
155
|
+
// Do not spam the logs
|
|
174
156
|
logger.debug(`consumeOne from queue: ${queue} ${toRecord ? 'to records' : 'just the message'}`);
|
|
175
|
-
|
|
176
157
|
if (message) {
|
|
177
158
|
if (toRecord) {
|
|
178
159
|
const headers = getHeaderInfo(message);
|
|
@@ -183,30 +164,25 @@ async function _default(AMQP_URL) {
|
|
|
183
164
|
messages: [message]
|
|
184
165
|
};
|
|
185
166
|
}
|
|
186
|
-
|
|
187
167
|
return message;
|
|
188
168
|
}
|
|
189
|
-
|
|
190
169
|
return false;
|
|
191
170
|
} catch (error) {
|
|
192
171
|
(0, _utils.logError)(error);
|
|
193
172
|
}
|
|
194
173
|
}
|
|
195
|
-
|
|
196
174
|
function ackMessages(messages) {
|
|
197
175
|
messages.forEach(message => {
|
|
198
176
|
logger.silly(`Ack message ${message.properties.correlationId}`);
|
|
199
177
|
channel.ack(message);
|
|
200
178
|
});
|
|
201
179
|
}
|
|
202
|
-
|
|
203
180
|
function nackMessages(messages) {
|
|
204
181
|
messages.forEach(message => {
|
|
205
182
|
logger.silly(`Nack message ${message.properties.correlationId}`);
|
|
206
183
|
channel.nack(message);
|
|
207
184
|
});
|
|
208
185
|
}
|
|
209
|
-
|
|
210
186
|
async function sendToQueue({
|
|
211
187
|
queue,
|
|
212
188
|
correlationId,
|
|
@@ -234,7 +210,6 @@ async function _default(AMQP_URL) {
|
|
|
234
210
|
(0, _utils.logError)(error);
|
|
235
211
|
}
|
|
236
212
|
}
|
|
237
|
-
|
|
238
213
|
async function removeQueue(queue) {
|
|
239
214
|
// deleteQueue borks the channel if the queue does not exist
|
|
240
215
|
// -> use throwaway tempChannel to avoid killing actual channel in use
|
|
@@ -242,16 +217,16 @@ async function _default(AMQP_URL) {
|
|
|
242
217
|
const tempChannel = await connection.createChannel();
|
|
243
218
|
logger.verbose(`Removing queue ${queue}.`);
|
|
244
219
|
await tempChannel.deleteQueue(queue);
|
|
245
|
-
|
|
246
220
|
if (tempChannel) {
|
|
247
221
|
// eslint-disable-line functional/no-conditional-statement
|
|
248
222
|
await tempChannel.close();
|
|
249
223
|
}
|
|
250
|
-
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// ----------------
|
|
251
227
|
// Helper functions
|
|
252
228
|
// ----------------
|
|
253
229
|
|
|
254
|
-
|
|
255
230
|
function messagesToRecords(messages) {
|
|
256
231
|
logger.debug(`Parsing messages (${messages.length}) to records`);
|
|
257
232
|
return messages.map(message => {
|
|
@@ -259,10 +234,8 @@ async function _default(AMQP_URL) {
|
|
|
259
234
|
return new _marcRecord.MarcRecord(content.data);
|
|
260
235
|
});
|
|
261
236
|
}
|
|
262
|
-
|
|
263
237
|
async function getData(queue) {
|
|
264
238
|
logger.debug(`Getting queue data from ${queue}`);
|
|
265
|
-
|
|
266
239
|
try {
|
|
267
240
|
const {
|
|
268
241
|
messageCount
|
|
@@ -276,30 +249,25 @@ async function _default(AMQP_URL) {
|
|
|
276
249
|
} catch (error) {
|
|
277
250
|
(0, _utils.logError)(error);
|
|
278
251
|
}
|
|
279
|
-
|
|
280
252
|
async function pump(count, results = [], identifiers = []) {
|
|
281
253
|
if (count === 0) {
|
|
282
254
|
return results;
|
|
283
255
|
}
|
|
284
|
-
|
|
285
256
|
const message = await channel.get(queue);
|
|
286
257
|
const identifier = {
|
|
287
258
|
correlationId: message.properties.correlationId,
|
|
288
259
|
deliveryTag: message.fields.deliveryTag
|
|
289
|
-
};
|
|
290
|
-
|
|
260
|
+
};
|
|
261
|
+
// Filter not unique messages
|
|
291
262
|
if (identifiers.includes(identifier)) {
|
|
292
263
|
return pump(count - 1, results, identifiers);
|
|
293
264
|
}
|
|
294
|
-
|
|
295
265
|
return pump(count - 1, results.concat(message), identifiers.concat(identifier));
|
|
296
266
|
}
|
|
297
267
|
}
|
|
298
|
-
|
|
299
268
|
function getHeaderInfo(data) {
|
|
300
269
|
return data.properties.headers;
|
|
301
270
|
}
|
|
302
|
-
|
|
303
271
|
function errorUndefinedQueue(queue) {
|
|
304
272
|
if (queue === undefined || queue === '' || queue === null) {
|
|
305
273
|
throw new _melindaCommons.Error(_httpStatus.default.INTERNAL_SERVER_ERROR, `Undefined queue!`);
|
package/dist/amqp.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,CAAgBH,QAAhB,CAAzB;EACA,MAAMI,OAAO,GA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,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
|
+
{"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;AAAqC;AAnCrC;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,QAAQ,EAAE;EACvC,MAAMC,UAAU,GAAG,MAAMC,gBAAO,CAACC,OAAO,CAACH,QAAQ,CAAC;EAClD,MAAMI,OAAO,GAAG,MAAMH,UAAU,CAACI,aAAa,EAAE;EAChD,MAAMC,MAAM,GAAG,IAAAC,mCAAY,GAAE;EAE7B,OAAO;IAACC,UAAU;IAAEC,YAAY;IAAEC,UAAU;IAAEC,WAAW;IAAEC,YAAY;IAAEC,WAAW;IAAEC,WAAW;IAAEC;EAAiB,CAAC;;EAErH;EACA,eAAeP,UAAU,CAAC;IAACQ,KAAK;IAAEC,KAAK,GAAG,OAAO;IAAEC,QAAQ,GAAG,IAAI;IAAEC,KAAK,GAAG;EAAK,CAAC,EAAE;IAClFb,MAAM,CAACc,KAAK,CAAE,eAAcJ,KAAM,YAAWC,KAAM,eAAcC,QAAS,Y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WAAW,CAAC;MAC9C;MAEA,OAAOH,IAAI,CAACC,KAAK,GAAG,CAAC,EAAEC,OAAO,CAACM,MAAM,CAACnC,OAAO,CAAC,EAAE8B,WAAW,CAACK,MAAM,CAACJ,UAAU,CAAC,CAAC;IACjF;EACF;EAEA,SAASnC,aAAa,CAACe,IAAI,EAAE;IAC3B,OAAOA,IAAI,CAACJ,UAAU,CAACZ,OAAO;EAChC;EAEA,SAASd,mBAAmB,CAACL,KAAK,EAAE;IAClC,IAAIA,KAAK,KAAK4D,SAAS,IAAI5D,KAAK,KAAK,EAAE,IAAIA,KAAK,KAAK,IAAI,EAAE;MACzD,MAAM,IAAIY,qBAAQ,CAACC,mBAAU,CAACgD,qBAAqB,EAAG,kBAAiB,CAAC;IAC1E;EACF;AACF"}
|
package/dist/constants.js
CHANGED
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.QUEUE_ITEM_STATE = exports.OPERATIONS = exports.LOG_ITEM_TYPE = exports.IMPORT_JOB_STATE = exports.CONVERSION_FORMATS = exports.CHUNK_SIZE = void 0;
|
|
7
|
-
|
|
8
7
|
/**
|
|
9
8
|
*
|
|
10
9
|
* @licstart The following is the entire license notice for the JavaScript code in this file.
|
|
@@ -32,7 +31,9 @@ exports.QUEUE_ITEM_STATE = exports.OPERATIONS = exports.LOG_ITEM_TYPE = exports.
|
|
|
32
31
|
* for the JavaScript code in this file.
|
|
33
32
|
*
|
|
34
33
|
*/
|
|
34
|
+
|
|
35
35
|
// QueueItemState flows: see README.md
|
|
36
|
+
|
|
36
37
|
const QUEUE_ITEM_STATE = {
|
|
37
38
|
VALIDATOR: {
|
|
38
39
|
PENDING_QUEUING: 'PENDING_QUEUING',
|
|
@@ -68,9 +69,10 @@ const OPERATIONS = {
|
|
|
68
69
|
UPDATE: 'UPDATE'
|
|
69
70
|
};
|
|
70
71
|
exports.OPERATIONS = OPERATIONS;
|
|
71
|
-
const CHUNK_SIZE = 100;
|
|
72
|
-
// ie. whether is has bulkSequence or bulkSequenceStart & bulkSequenceEnd
|
|
72
|
+
const CHUNK_SIZE = 100;
|
|
73
73
|
|
|
74
|
+
// We could configure here whether a logItemType is for a several records of a single record
|
|
75
|
+
// ie. whether is has bulkSequence or bulkSequenceStart & bulkSequenceEnd
|
|
74
76
|
exports.CHUNK_SIZE = CHUNK_SIZE;
|
|
75
77
|
const LOG_ITEM_TYPE = {
|
|
76
78
|
MERGE_LOG: 'MERGE_LOG',
|
package/dist/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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","LOG_ITEM_TYPE","MERGE_LOG","MATCH_LOG","SPLITTER_LOG","CONVERSION_FORMATS","MARCXML","ISO2709","JSON","ALEPHSEQ"],"sources":["../src/constants.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Shared modules for microservices of Melinda rest api batch import system\n*\n* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-rest-api-commons\n*\n* melinda-rest-api-commons program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Affero General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-rest-api-commons is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Affero General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\n// QueueItemState flows: see README.md\n\nexport const QUEUE_ITEM_STATE = {\n VALIDATOR: {\n PENDING_QUEUING: 'PENDING_QUEUING',\n PENDING_VALIDATION: 'PENDING_VALIDATION',\n QUEUING_IN_PROGRESS: 'QUEUING_IN_PROGRESS',\n UPLOADING: 'UPLOADING',\n VALIDATING: 'VALIDATING',\n WAITING_FOR_RECORDS: 'WAITING_FOR_RECORDS'\n },\n IMPORTER: {\n IMPORTING: 'IMPORTING',\n IN_PROCESS: 'IN_PROCESS',\n IN_QUEUE: 'IN_QUEUE'\n },\n DONE: 'DONE',\n ERROR: 'ERROR',\n ABORT: 'ABORT'\n};\n\nexport const IMPORT_JOB_STATE = {\n EMPTY: 'EMPTY',\n QUEUING: 'QUEUING',\n IN_QUEUE: 'IN_QUEUE',\n IMPORTING: 'IMPORTING',\n PROCESSING: 'PROCESSING',\n DONE: 'DONE',\n ERROR: 'ERROR',\n ABORT: 'ABORT'\n};\n\nexport const OPERATIONS = {\n CREATE: 'CREATE',\n UPDATE: 'UPDATE'\n};\n\nexport const CHUNK_SIZE = 100;\n\n// We could configure here whether a logItemType is for a several records of a single record\n// ie. whether is has bulkSequence or bulkSequenceStart & bulkSequenceEnd\nexport const LOG_ITEM_TYPE = {\n MERGE_LOG: 'MERGE_LOG',\n MATCH_LOG: 'MATCH_LOG',\n SPLITTER_LOG: 'SPLITTER_LOG'\n};\n\nexport const CONVERSION_FORMATS = {\n MARCXML: 'MARCXML',\n ISO2709: 'ISO2709',\n JSON: 'JSON',\n ALEPHSEQ: 'ALEPHSEQ'\n};\n"],"mappings":"
|
|
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","LOG_ITEM_TYPE","MERGE_LOG","MATCH_LOG","SPLITTER_LOG","CONVERSION_FORMATS","MARCXML","ISO2709","JSON","ALEPHSEQ"],"sources":["../src/constants.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Shared modules for microservices of Melinda rest api batch import system\n*\n* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-rest-api-commons\n*\n* melinda-rest-api-commons program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Affero General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-rest-api-commons is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Affero General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\n// QueueItemState flows: see README.md\n\nexport const QUEUE_ITEM_STATE = {\n VALIDATOR: {\n PENDING_QUEUING: 'PENDING_QUEUING',\n PENDING_VALIDATION: 'PENDING_VALIDATION',\n QUEUING_IN_PROGRESS: 'QUEUING_IN_PROGRESS',\n UPLOADING: 'UPLOADING',\n VALIDATING: 'VALIDATING',\n WAITING_FOR_RECORDS: 'WAITING_FOR_RECORDS'\n },\n IMPORTER: {\n IMPORTING: 'IMPORTING',\n IN_PROCESS: 'IN_PROCESS',\n IN_QUEUE: 'IN_QUEUE'\n },\n DONE: 'DONE',\n ERROR: 'ERROR',\n ABORT: 'ABORT'\n};\n\nexport const IMPORT_JOB_STATE = {\n EMPTY: 'EMPTY',\n QUEUING: 'QUEUING',\n IN_QUEUE: 'IN_QUEUE',\n IMPORTING: 'IMPORTING',\n PROCESSING: 'PROCESSING',\n DONE: 'DONE',\n ERROR: 'ERROR',\n ABORT: 'ABORT'\n};\n\nexport const OPERATIONS = {\n CREATE: 'CREATE',\n UPDATE: 'UPDATE'\n};\n\nexport const CHUNK_SIZE = 100;\n\n// We could configure here whether a logItemType is for a several records of a single record\n// ie. whether is has bulkSequence or bulkSequenceStart & bulkSequenceEnd\nexport const LOG_ITEM_TYPE = {\n MERGE_LOG: 'MERGE_LOG',\n MATCH_LOG: 'MATCH_LOG',\n SPLITTER_LOG: 'SPLITTER_LOG'\n};\n\nexport const CONVERSION_FORMATS = {\n MARCXML: 'MARCXML',\n ISO2709: 'ISO2709',\n JSON: 'JSON',\n ALEPHSEQ: 'ALEPHSEQ'\n};\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEO,MAAMA,gBAAgB,GAAG;EAC9BC,SAAS,EAAE;IACTC,eAAe,EAAE,iBAAiB;IAClCC,kBAAkB,EAAE,oBAAoB;IACxCC,mBAAmB,EAAE,qBAAqB;IAC1CC,SAAS,EAAE,WAAW;IACtBC,UAAU,EAAE,YAAY;IACxBC,mBAAmB,EAAE;EACvB,CAAC;EACDC,QAAQ,EAAE;IACRC,SAAS,EAAE,WAAW;IACtBC,UAAU,EAAE,YAAY;IACxBC,QAAQ,EAAE;EACZ,CAAC;EACDC,IAAI,EAAE,MAAM;EACZC,KAAK,EAAE,OAAO;EACdC,KAAK,EAAE;AACT,CAAC;AAAC;AAEK,MAAMC,gBAAgB,GAAG;EAC9BC,KAAK,EAAE,OAAO;EACdC,OAAO,EAAE,SAAS;EAClBN,QAAQ,EAAE,UAAU;EACpBF,SAAS,EAAE,WAAW;EACtBS,UAAU,EAAE,YAAY;EACxBN,IAAI,EAAE,MAAM;EACZC,KAAK,EAAE,OAAO;EACdC,KAAK,EAAE;AACT,CAAC;AAAC;AAEK,MAAMK,UAAU,GAAG;EACxBC,MAAM,EAAE,QAAQ;EAChBC,MAAM,EAAE;AACV,CAAC;AAAC;AAEK,MAAMC,UAAU,GAAG,GAAG;;AAE7B;AACA;AAAA;AACO,MAAMC,aAAa,GAAG;EAC3BC,SAAS,EAAE,WAAW;EACtBC,SAAS,EAAE,WAAW;EACtBC,YAAY,EAAE;AAChB,CAAC;AAAC;AAEK,MAAMC,kBAAkB,GAAG;EAChCC,OAAO,EAAE,SAAS;EAClBC,OAAO,EAAE,SAAS;EAClBC,IAAI,EAAE,MAAM;EACZC,QAAQ,EAAE;AACZ,CAAC;AAAC"}
|
|
@@ -4,21 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = _default;
|
|
7
|
-
|
|
8
7
|
var _httpStatus = _interopRequireDefault(require("http-status"));
|
|
9
|
-
|
|
10
8
|
var _marcRecordSerializers = require("@natlibfi/marc-record-serializers");
|
|
11
|
-
|
|
12
9
|
var _melindaBackendCommons = require("@natlibfi/melinda-backend-commons");
|
|
13
|
-
|
|
14
10
|
var _melindaCommons = require("@natlibfi/melinda-commons");
|
|
15
|
-
|
|
16
11
|
var _constants = require("../constants");
|
|
17
|
-
|
|
18
12
|
var _utils = require("../utils");
|
|
19
|
-
|
|
20
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
-
|
|
22
14
|
/**
|
|
23
15
|
*
|
|
24
16
|
* @licstart The following is the entire license notice for the JavaScript code in this file.
|
|
@@ -46,47 +38,42 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
46
38
|
* for the JavaScript code in this file.
|
|
47
39
|
*
|
|
48
40
|
*/
|
|
41
|
+
|
|
49
42
|
function _default() {
|
|
50
43
|
const logger = (0, _melindaBackendCommons.createLogger)();
|
|
51
44
|
return {
|
|
52
45
|
serialize,
|
|
53
46
|
unserialize
|
|
54
|
-
};
|
|
47
|
+
};
|
|
55
48
|
|
|
49
|
+
// This uses format as a number form contants CONVERSION_FORMATS
|
|
56
50
|
function serialize(record, format) {
|
|
57
51
|
logger.verbose(`Serializing record to ${format}`);
|
|
58
|
-
|
|
59
52
|
try {
|
|
60
53
|
if (format === _constants.CONVERSION_FORMATS.MARCXML) {
|
|
61
54
|
return _marcRecordSerializers.MARCXML.to(record);
|
|
62
55
|
}
|
|
63
|
-
|
|
64
56
|
if (format === _constants.CONVERSION_FORMATS.ISO2709) {
|
|
65
57
|
return _marcRecordSerializers.ISO2709.to(record);
|
|
66
58
|
}
|
|
67
|
-
|
|
68
59
|
if (format === _constants.CONVERSION_FORMATS.JSON) {
|
|
69
60
|
return _marcRecordSerializers.Json.to(record);
|
|
70
61
|
}
|
|
71
|
-
|
|
72
62
|
if (format === _constants.CONVERSION_FORMATS.ALEPHSEQ) {
|
|
73
63
|
return _marcRecordSerializers.AlephSequential.to(record);
|
|
74
64
|
}
|
|
75
|
-
|
|
76
65
|
throw new _melindaCommons.Error(_httpStatus.default.UNSUPPORTED_MEDIA_TYPE);
|
|
77
66
|
} catch (err) {
|
|
78
67
|
(0, _utils.logError)(err);
|
|
79
|
-
|
|
80
68
|
if (err instanceof _melindaCommons.Error) {
|
|
81
69
|
// eslint-disable-line functional/no-conditional-statement
|
|
82
70
|
throw err;
|
|
83
71
|
}
|
|
84
|
-
|
|
85
72
|
throw new _melindaCommons.Error(_httpStatus.default.BAD_REQUEST, 'Error while serializing record');
|
|
86
73
|
}
|
|
87
|
-
}
|
|
88
|
-
|
|
74
|
+
}
|
|
89
75
|
|
|
76
|
+
// eslint-disable-next-line max-statements
|
|
90
77
|
function unserialize(data, format, validationOptions = {
|
|
91
78
|
subfieldValues: false
|
|
92
79
|
}) {
|
|
@@ -94,37 +81,30 @@ function _default() {
|
|
|
94
81
|
logger.silly(`Format: ${format}`);
|
|
95
82
|
logger.debug(`Validation options: ${JSON.stringify(validationOptions)}`);
|
|
96
83
|
logger.silly(`Data: ${JSON.stringify(data)}`);
|
|
97
|
-
|
|
98
84
|
try {
|
|
99
85
|
if (format === _constants.CONVERSION_FORMATS.MARCXML) {
|
|
100
86
|
logger.silly('Unserialize format marcxml');
|
|
101
87
|
return _marcRecordSerializers.MARCXML.from(data, validationOptions);
|
|
102
88
|
}
|
|
103
|
-
|
|
104
89
|
if (format === _constants.CONVERSION_FORMATS.ISO2709) {
|
|
105
90
|
logger.silly('Unserialize format iso2709');
|
|
106
91
|
return _marcRecordSerializers.ISO2709.from(data, validationOptions);
|
|
107
92
|
}
|
|
108
|
-
|
|
109
93
|
if (format === _constants.CONVERSION_FORMATS.JSON) {
|
|
110
94
|
logger.silly('Unserialize format json');
|
|
111
95
|
return _marcRecordSerializers.Json.from(data, validationOptions);
|
|
112
96
|
}
|
|
113
|
-
|
|
114
97
|
if (format === _constants.CONVERSION_FORMATS.ALEPHSEQ) {
|
|
115
98
|
logger.silly('Unserialize format aleph sequential');
|
|
116
99
|
return _marcRecordSerializers.AlephSequential.from(data, validationOptions);
|
|
117
100
|
}
|
|
118
|
-
|
|
119
101
|
throw new _melindaCommons.Error(_httpStatus.default.UNSUPPORTED_MEDIA_TYPE);
|
|
120
102
|
} catch (err) {
|
|
121
103
|
(0, _utils.logError)(err);
|
|
122
|
-
|
|
123
104
|
if (err instanceof _melindaCommons.Error) {
|
|
124
105
|
// eslint-disable-line functional/no-conditional-statement
|
|
125
106
|
throw err;
|
|
126
107
|
}
|
|
127
|
-
|
|
128
108
|
throw new _melindaCommons.Error(_httpStatus.default.BAD_REQUEST, 'Error while unserializing record');
|
|
129
109
|
}
|
|
130
110
|
}
|
|
@@ -1 +1 @@
|
|
|
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":"
|
|
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;AAAkC;AAjClC;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;EACzB,MAAMA,MAAM,GAAG,IAAAC,mCAAY,GAAE;EAE7B,OAAO;IAACC,SAAS;IAAEC;EAAW,CAAC;;EAE/B;EACA,SAASD,SAAS,CAACE,MAAM,EAAEC,MAAM,EAAE;IACjCL,MAAM,CAACM,OAAO,CAAE,yBAAwBD,MAAO,EAAC,CAAC;IACjD,IAAI;MACF,IAAIA,MAAM,KAAKE,6BAAkB,CAACC,OAAO,EAAE;QACzC,OAAOA,8BAAO,CAACC,EAAE,CAACL,MAAM,CAAC;MAC3B;MAEA,IAAIC,MAAM,KAAKE,6BAAkB,CAACG,OAAO,EAAE;QACzC,OAAOA,8BAAO,CAACD,EAAE,CAACL,MAAM,CAAC;MAC3B;MAEA,IAAIC,MAAM,KAAKE,6BAAkB,CAACI,IAAI,EAAE;QACtC,OAAOC,2BAAI,CAACH,EAAE,CAACL,MAAM,CAAC;MACxB;MAEA,IAAIC,MAAM,KAAKE,6BAAkB,CAACM,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yB,CAAC;QACvC,OAAOZ,2BAAI,CAACe,IAAI,CAACN,IAAI,EAAEC,iBAAiB,CAAC;MAC3C;MAEA,IAAIjB,MAAM,KAAKE,6BAAkB,CAACM,QAAQ,EAAE;QAC1Cb,MAAM,CAACwB,KAAK,CAAC,qCAAqC,CAAC;QACnD,OAAOV,sCAAe,CAACa,IAAI,CAACN,IAAI,EAAEC,iBAAiB,CAAC;MACtD;MAEA,MAAM,IAAIP,qBAAe,CAACC,mBAAU,CAACC,sBAAsB,CAAC;IAC9D,CAAC,CAAC,OAAOC,GAAG,EAAE;MACZ,IAAAC,eAAQ,EAACD,GAAG,CAAC;MACb,IAAIA,GAAG,YAAYH,qBAAe,EAAE;QAAE;QACpC,MAAMG,GAAG;MACX;MACA,MAAM,IAAIH,qBAAe,CAACC,mBAAU,CAACI,WAAW,EAAE,kCAAkC,CAAC;IACvF;EACF;AACF"}
|
|
@@ -1,19 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _chai = require("chai");
|
|
4
|
-
|
|
5
4
|
var _fixura = _interopRequireDefault(require("@natlibfi/fixura"));
|
|
6
|
-
|
|
7
5
|
var _marcRecord = require("@natlibfi/marc-record");
|
|
8
|
-
|
|
9
6
|
var _melindaCommons = require("@natlibfi/melinda-commons");
|
|
10
|
-
|
|
11
7
|
var _conversion = _interopRequireDefault(require("./conversion"));
|
|
12
|
-
|
|
13
8
|
var _constants = require("../constants");
|
|
14
|
-
|
|
15
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
|
-
|
|
17
10
|
/**
|
|
18
11
|
*
|
|
19
12
|
* @licstart The following is the entire license notice for the JavaScript code in this file.
|
|
@@ -41,6 +34,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
41
34
|
* for the JavaScript code in this file.
|
|
42
35
|
*
|
|
43
36
|
*/
|
|
37
|
+
|
|
44
38
|
describe('services/conversion', () => {
|
|
45
39
|
const {
|
|
46
40
|
getFixture
|
|
@@ -1 +1 @@
|
|
|
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
|
|
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;AAC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