@natlibfi/melinda-rest-api-commons 4.2.5 → 5.0.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/.github/workflows/melinda-node-tests.yml +9 -6
- package/dist/conversion.js +70 -0
- package/dist/conversion.js.map +7 -0
- package/dist/fix-constants.js +63 -0
- package/dist/fix-constants.js.map +7 -0
- package/dist/fix-handle-tempurns.js +83 -0
- package/dist/fix-handle-tempurns.js.map +7 -0
- package/dist/fix-strip-f884s.js +160 -0
- package/dist/fix-strip-f884s.js.map +7 -0
- package/dist/fix-utils.js +39 -0
- package/dist/fix-utils.js.map +7 -0
- package/dist/fix.js +142 -0
- package/dist/fix.js.map +7 -0
- package/dist/validation.js +19 -0
- package/dist/validation.js.map +7 -0
- package/eslint.config.js +53 -0
- package/package.json +23 -96
- package/tests/{amqp.health.spec.js → amqp.healthtest.js} +2 -2
- package/tests/{amqp.tests.spec.js → amqp.tests.localtest.js} +46 -46
- package/tests/helpers/{conversion.spec.js → conversion.test.js} +38 -25
- package/tests/helpers/{fix.spec.js → fix.test.js} +6 -6
- package/tests/helpers/{validation.spec.js → validation.test.js} +12 -9
- package/tests/{mongo-add-blob-size.spec.js → mongo-add-blob-size.test.js} +6 -6
- package/tests/{mongo-check-and-check-state.spec.js → mongo-check-and-check-state.test.js} +7 -7
- package/tests/{mongo-check-and-set-import-job-state.spec.js → mongo-check-and-set-import-job-state.test.js} +7 -7
- package/tests/{mongo-check-timeout.spec.js → mongo-check-timeout.test.js} +7 -7
- package/tests/{mongo-create-bulk.spec.js → mongo-create-bulk.test.js} +5 -5
- package/tests/{mongo-create-prio.spec.js → mongo-create-prio.test.js} +6 -6
- package/tests/{mongo-get-one.spec.js → mongo-get-one.test.js} +7 -7
- package/tests/{mongo-get-stream.spec.js → mongo-get-stream.test.js} +7 -7
- package/tests/{mongo-push-ids.spec.js → mongo-push-ids.test.js} +5 -5
- package/tests/{mongo-push-messages.spec.js → mongo-push-messages.test.js} +6 -6
- package/tests/{mongo-query-by-id.spec.js → mongo-query-by-id.test.js} +7 -7
- package/tests/{mongo-query.spec.js → mongo-query.test.js} +7 -7
- package/tests/{mongo-read-content.spec.js → mongo-read-content.test.js} +8 -8
- package/tests/{mongo-remove.spec.js → mongo-remove.test.js} +6 -6
- package/tests/{mongo-set-blob-size.spec.js → mongo-set-blob-size.test.js} +6 -6
- package/tests/{mongo-set-import-job-state.spec.js → mongo-set-import-job-state.test.js} +6 -6
- package/tests/{mongo-set-operation.spec.js → mongo-set-operation.test.js} +6 -6
- package/tests/{mongo-set-operations.spec.js → mongo-set-operations.test.js} +6 -6
- package/tests/{mongo-set-state.spec.js → mongo-set-state.test.js} +7 -7
- package/tests/{mongoLog.spec.js → mongoLog.test.js} +10 -11
- package/tests/testUtils.js +9 -8
- package/dist/amqp.js +0 -326
- package/dist/amqp.js.map +0 -1
- package/dist/constants.js +0 -60
- package/dist/constants.js.map +0 -1
- package/dist/helpers/conversion.js +0 -88
- package/dist/helpers/conversion.js.map +0 -1
- package/dist/helpers/fix-constants.js +0 -70
- package/dist/helpers/fix-constants.js.map +0 -1
- package/dist/helpers/fix-handle-tempurns.js +0 -133
- package/dist/helpers/fix-handle-tempurns.js.map +0 -1
- package/dist/helpers/fix-strip-f884s.js +0 -210
- package/dist/helpers/fix-strip-f884s.js.map +0 -1
- package/dist/helpers/fix-utils.js +0 -54
- package/dist/helpers/fix-utils.js.map +0 -1
- package/dist/helpers/fix.js +0 -202
- package/dist/helpers/fix.js.map +0 -1
- package/dist/helpers/validation.js +0 -37
- package/dist/helpers/validation.js.map +0 -1
- package/dist/index.js +0 -109
- package/dist/index.js.map +0 -1
- package/dist/mongo.js +0 -822
- package/dist/mongo.js.map +0 -1
- package/dist/mongoLog.js +0 -409
- package/dist/mongoLog.js.map +0 -1
- package/dist/utils.js +0 -211
- package/dist/utils.js.map +0 -1
package/dist/amqp.js
DELETED
|
@@ -1,326 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.default = _default;
|
|
8
|
-
var _amqplib = _interopRequireDefault(require("amqplib"));
|
|
9
|
-
var _marcRecord = require("@natlibfi/marc-record");
|
|
10
|
-
var _melindaCommons = require("@natlibfi/melinda-commons");
|
|
11
|
-
var _melindaBackendCommons = require("@natlibfi/melinda-backend-commons");
|
|
12
|
-
var _debug = _interopRequireDefault(require("debug"));
|
|
13
|
-
var _constants = require("./constants");
|
|
14
|
-
var _util = require("util");
|
|
15
|
-
var _httpStatus = _interopRequireDefault(require("http-status"));
|
|
16
|
-
var _utils = require("./utils");
|
|
17
|
-
async function _default(AMQP_URL, runHealthCheck = false) {
|
|
18
|
-
const logger = (0, _melindaBackendCommons.createLogger)();
|
|
19
|
-
const debug = (0, _debug.default)('@natlibfi/melinda-rest-api-commons:amqp');
|
|
20
|
-
const debugHC = debug.extend('HC');
|
|
21
|
-
const debugData = debug.extend('data');
|
|
22
|
-
const setTimeoutPromise = (0, _util.promisify)(setTimeout);
|
|
23
|
-
debug(`Creating an AMQP operator to ${AMQP_URL}`);
|
|
24
|
-
const connection = await _amqplib.default.connect(AMQP_URL);
|
|
25
|
-
const channel = await connection.createChannel();
|
|
26
|
-
const healthCheckLoop = runHealthCheck ? healthCheck() : false;
|
|
27
|
-
debug(`Connection: ${connection}`);
|
|
28
|
-
debug(`Channel: ${channel}`);
|
|
29
|
-
debug(`HealthCheckLoop: ${healthCheckLoop ? 'Running health check' : 'Not running health check'}`);
|
|
30
|
-
return {
|
|
31
|
-
checkQueue,
|
|
32
|
-
consumeChunk,
|
|
33
|
-
consumeOne,
|
|
34
|
-
ackMessages,
|
|
35
|
-
nackMessages,
|
|
36
|
-
sendToQueue,
|
|
37
|
-
removeQueue,
|
|
38
|
-
messagesToRecords,
|
|
39
|
-
closeChannel,
|
|
40
|
-
closeConnection
|
|
41
|
-
};
|
|
42
|
-
async function closeChannel() {
|
|
43
|
-
debug(`Closing channel`);
|
|
44
|
-
await channel.close();
|
|
45
|
-
debug(`Channel: ${channel}`);
|
|
46
|
-
}
|
|
47
|
-
async function closeConnection() {
|
|
48
|
-
debug(`Closing connection`);
|
|
49
|
-
await connection.close();
|
|
50
|
-
debug(`Connection: ${connection}`);
|
|
51
|
-
}
|
|
52
|
-
async function healthCheck(wait = false) {
|
|
53
|
-
if (wait) {
|
|
54
|
-
await setTimeoutPromise(wait);
|
|
55
|
-
return healthCheck(false);
|
|
56
|
-
}
|
|
57
|
-
try {
|
|
58
|
-
debugHC(`Health checking amqp by asserting a queue`);
|
|
59
|
-
await channel.assertQueue('HEALTHCHECK', {
|
|
60
|
-
durable: false
|
|
61
|
-
});
|
|
62
|
-
debugHC(`Waiting 200ms before running healthCheck next`);
|
|
63
|
-
return healthCheck(200);
|
|
64
|
-
} catch (error) {
|
|
65
|
-
debugHC(`HealthCheck error ${JSON.stringify(error)}`);
|
|
66
|
-
handleAmqpErrors(error);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// eslint-disable-next-line max-statements
|
|
71
|
-
async function checkQueue({
|
|
72
|
-
queue,
|
|
73
|
-
style = 'basic',
|
|
74
|
-
toRecord = true,
|
|
75
|
-
purge = false
|
|
76
|
-
}) {
|
|
77
|
-
debug(`checkQueue: ${queue}, Style: ${style}, toRecord: ${toRecord}, Purge: ${purge}`);
|
|
78
|
-
try {
|
|
79
|
-
errorUndefinedQueue(queue);
|
|
80
|
-
const channelInfo = await channel.assertQueue(queue, {
|
|
81
|
-
durable: true
|
|
82
|
-
});
|
|
83
|
-
if (purge) {
|
|
84
|
-
await purgeQueue(purge);
|
|
85
|
-
logger.verbose(`Queue ${queue} has purged ${channelInfo.messageCount} messages`);
|
|
86
|
-
debug(`Queue ${queue} has purged ${channelInfo.messageCount} messages`);
|
|
87
|
-
return checkQueue({
|
|
88
|
-
queue,
|
|
89
|
-
style
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
if (style === 'messages') {
|
|
93
|
-
return channelInfo.messageCount;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// Note: returns one message (+ record, of toRecord: true)
|
|
97
|
-
// note: if toRecord is false returns just plain message / false
|
|
98
|
-
// note: if toRecord is true returns {headers, records, messages} -object / false
|
|
99
|
-
// should this be more consistent?
|
|
100
|
-
if (style === 'one') {
|
|
101
|
-
if (checkMessageCount(channelInfo)) {
|
|
102
|
-
return consumeOne(queue, toRecord);
|
|
103
|
-
}
|
|
104
|
-
return false;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// Note: returns a chunk of (100) messages (+ records, if toRecord: true)
|
|
108
|
-
// returns {headers, records, messages} object or {headers, messages} object depending on toRecord
|
|
109
|
-
if (style === 'basic') {
|
|
110
|
-
if (checkMessageCount(channelInfo)) {
|
|
111
|
-
return consumeChunk(queue, toRecord);
|
|
112
|
-
}
|
|
113
|
-
return false;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// Defaults:
|
|
117
|
-
throw new _melindaCommons.Error(_httpStatus.default.INTERNAL_SERVER_ERROR, `CheckQueue does not recognize style ${style}`);
|
|
118
|
-
} catch (error) {
|
|
119
|
-
handleAmqpErrors(error);
|
|
120
|
-
}
|
|
121
|
-
function checkMessageCount(channelInfo) {
|
|
122
|
-
if (channelInfo.messageCount < 1) {
|
|
123
|
-
debug(`checkQueue: ${channelInfo.messageCount} - ${queue} is empty`);
|
|
124
|
-
return false;
|
|
125
|
-
}
|
|
126
|
-
debug(`Queue ${queue} has ${channelInfo.messageCount} messages`);
|
|
127
|
-
return true;
|
|
128
|
-
}
|
|
129
|
-
function purgeQueue(purge) {
|
|
130
|
-
debug(`Purging queue: ${queue}, purge: ${purge}`);
|
|
131
|
-
if (purge) {
|
|
132
|
-
return channel.purgeQueue(queue);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
async function consumeChunk(queue, toRecord) {
|
|
137
|
-
debug(`Prepared to consumeChunk from queue: ${queue}`);
|
|
138
|
-
try {
|
|
139
|
-
await channel.assertQueue(queue, {
|
|
140
|
-
durable: true
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
// getData: next chunk (100) messages
|
|
144
|
-
const messages = await getData(queue);
|
|
145
|
-
|
|
146
|
-
// Note: headers are from the first message of the chunk
|
|
147
|
-
const headers = getHeaderInfo(messages[0]);
|
|
148
|
-
debug(`consumeChunk (${messages ? messages.length : '0'} from queue ${queue}) ${toRecord ? 'to records' : 'just messages'}`);
|
|
149
|
-
if (toRecord) {
|
|
150
|
-
const records = await messagesToRecords(messages);
|
|
151
|
-
return {
|
|
152
|
-
headers,
|
|
153
|
-
records,
|
|
154
|
-
messages
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
return {
|
|
158
|
-
headers,
|
|
159
|
-
messages
|
|
160
|
-
};
|
|
161
|
-
} catch (error) {
|
|
162
|
-
handleAmqpErrors(error);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
async function consumeOne(queue, toRecord) {
|
|
166
|
-
debug(`Prepared to consumeOne from queue: ${queue}`);
|
|
167
|
-
try {
|
|
168
|
-
await channel.assertQueue(queue, {
|
|
169
|
-
durable: true
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
// Returns false if 0 items in queue
|
|
173
|
-
const message = await channel.get(queue);
|
|
174
|
-
debugData(`Message: ${(0, _util.inspect)(message, {
|
|
175
|
-
colors: true,
|
|
176
|
-
maxArrayLength: 3,
|
|
177
|
-
depth: 3
|
|
178
|
-
})}`);
|
|
179
|
-
// Do not spam the logs
|
|
180
|
-
debug(`consumeOne from queue: ${queue} ${toRecord ? 'to records' : 'just the message'}`);
|
|
181
|
-
if (message) {
|
|
182
|
-
if (toRecord) {
|
|
183
|
-
const headers = getHeaderInfo(message);
|
|
184
|
-
const records = messagesToRecords([message]);
|
|
185
|
-
return {
|
|
186
|
-
headers,
|
|
187
|
-
records,
|
|
188
|
-
messages: [message]
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
return message;
|
|
192
|
-
}
|
|
193
|
-
return false;
|
|
194
|
-
} catch (error) {
|
|
195
|
-
handleAmqpErrors(error);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
function ackMessages(messages) {
|
|
199
|
-
messages.forEach(message => {
|
|
200
|
-
debug(`Ack message ${message.properties.correlationId}`);
|
|
201
|
-
channel.ack(message);
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
function nackMessages(messages) {
|
|
205
|
-
messages.forEach(message => {
|
|
206
|
-
debug(`Nack message ${message.properties.correlationId}`);
|
|
207
|
-
channel.nack(message);
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
async function sendToQueue({
|
|
211
|
-
queue,
|
|
212
|
-
correlationId,
|
|
213
|
-
headers,
|
|
214
|
-
data
|
|
215
|
-
}) {
|
|
216
|
-
debug(`sendToQueue`);
|
|
217
|
-
// eslint-disable-next-line no-useless-catch
|
|
218
|
-
try {
|
|
219
|
-
debug(`Queue ${queue}`);
|
|
220
|
-
debug(`CorrelationId ${correlationId}`);
|
|
221
|
-
debugData(`Data ${JSON.stringify(data)}`);
|
|
222
|
-
debug(`Headers ${JSON.stringify(headers)}`);
|
|
223
|
-
errorUndefinedQueue(queue);
|
|
224
|
-
debug(`Asserting queue: ${queue}`);
|
|
225
|
-
await channel.assertQueue(queue, {
|
|
226
|
-
durable: true
|
|
227
|
-
});
|
|
228
|
-
debug(`Actually sendToQueue: ${queue}`);
|
|
229
|
-
await channel.sendToQueue(queue, Buffer.from(JSON.stringify({
|
|
230
|
-
data
|
|
231
|
-
})), {
|
|
232
|
-
correlationId,
|
|
233
|
-
persistent: true,
|
|
234
|
-
headers
|
|
235
|
-
});
|
|
236
|
-
debug(`Send message for ${correlationId} to queue: ${queue}`);
|
|
237
|
-
} catch (error) {
|
|
238
|
-
const errorToThrow = error;
|
|
239
|
-
//if (error instanceof ApiError) {
|
|
240
|
-
// throw error;
|
|
241
|
-
//}
|
|
242
|
-
debug(`SendToQueue errored: ${JSON.stringify(error)}`);
|
|
243
|
-
handleAmqpErrors(errorToThrow);
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
async function removeQueue(queue) {
|
|
247
|
-
// deleteQueue borks the channel if the queue does not exist
|
|
248
|
-
// -> use throwaway tempChannel to avoid killing actual channel in use
|
|
249
|
-
// this might be doable also with assertQueue before deleteQueue
|
|
250
|
-
const tempChannel = await connection.createChannel();
|
|
251
|
-
logger.verbose(`Removing queue ${queue}.`);
|
|
252
|
-
debug(`Removing queue ${queue}.`);
|
|
253
|
-
await tempChannel.deleteQueue(queue);
|
|
254
|
-
if (tempChannel) {
|
|
255
|
-
await tempChannel.close();
|
|
256
|
-
return;
|
|
257
|
-
}
|
|
258
|
-
return;
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
// ----------------
|
|
262
|
-
// Helper functions
|
|
263
|
-
// ----------------
|
|
264
|
-
|
|
265
|
-
function messagesToRecords(messages) {
|
|
266
|
-
debug(`Parsing messages (${messages.length}) to records`);
|
|
267
|
-
return messages.map(message => {
|
|
268
|
-
const content = JSON.parse(message.content.toString());
|
|
269
|
-
// Use subfieldValues: false validationOption here
|
|
270
|
-
return new _marcRecord.MarcRecord(content.data, {
|
|
271
|
-
subfieldValues: false
|
|
272
|
-
});
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
async function getData(queue) {
|
|
276
|
-
debug(`Getting queue data from ${queue}`);
|
|
277
|
-
try {
|
|
278
|
-
const {
|
|
279
|
-
messageCount
|
|
280
|
-
} = await channel.checkQueue(queue);
|
|
281
|
-
debug(`There is ${messageCount} messages in queue ${queue}`);
|
|
282
|
-
const messagesToGet = messageCount >= _constants.CHUNK_SIZE ? _constants.CHUNK_SIZE : messageCount;
|
|
283
|
-
debug(`Getting ${messagesToGet} messages from queue ${queue}`);
|
|
284
|
-
const messages = await pump(messagesToGet);
|
|
285
|
-
debug(`Returning ${messages.length} unique messages`);
|
|
286
|
-
return messages;
|
|
287
|
-
} catch (error) {
|
|
288
|
-
handleAmqpErrors(error);
|
|
289
|
-
}
|
|
290
|
-
async function pump(count, results = [], identifiers = []) {
|
|
291
|
-
if (count === 0) {
|
|
292
|
-
return results;
|
|
293
|
-
}
|
|
294
|
-
const message = await channel.get(queue);
|
|
295
|
-
const identifier = {
|
|
296
|
-
correlationId: message.properties.correlationId,
|
|
297
|
-
deliveryTag: message.fields.deliveryTag
|
|
298
|
-
};
|
|
299
|
-
// Filter not unique messages
|
|
300
|
-
if (identifiers.includes(identifier)) {
|
|
301
|
-
return pump(count - 1, results, identifiers);
|
|
302
|
-
}
|
|
303
|
-
return pump(count - 1, results.concat(message), identifiers.concat(identifier));
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
function getHeaderInfo(data) {
|
|
307
|
-
return data.properties.headers;
|
|
308
|
-
}
|
|
309
|
-
function errorUndefinedQueue(queue) {
|
|
310
|
-
if (queue === undefined || queue === '' || queue === null) {
|
|
311
|
-
throw new _melindaCommons.Error(_httpStatus.default.INTERNAL_SERVER_ERROR, `Undefined queue!`);
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
function handleAmqpErrors(error) {
|
|
315
|
-
const newError = error;
|
|
316
|
-
debug(`HandleAmqpErrors got an error: ${JSON.stringify(error)}`);
|
|
317
|
-
if (error instanceof _melindaCommons.Error) {
|
|
318
|
-
debug(`We have an ApiError`);
|
|
319
|
-
throw new _melindaCommons.Error(newError.status, newError.payload);
|
|
320
|
-
}
|
|
321
|
-
debug(`We have a non-ApiError`);
|
|
322
|
-
(0, _utils.logError)(error);
|
|
323
|
-
throw newError;
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
//# sourceMappingURL=amqp.js.map
|
package/dist/amqp.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"amqp.js","names":["_amqplib","_interopRequireDefault","require","_marcRecord","_melindaCommons","_melindaBackendCommons","_debug","_constants","_util","_httpStatus","_utils","_default","AMQP_URL","runHealthCheck","logger","createLogger","debug","createDebugLogger","debugHC","extend","debugData","setTimeoutPromise","promisify","setTimeout","connection","amqplib","connect","channel","createChannel","healthCheckLoop","healthCheck","checkQueue","consumeChunk","consumeOne","ackMessages","nackMessages","sendToQueue","removeQueue","messagesToRecords","closeChannel","closeConnection","close","wait","assertQueue","durable","error","JSON","stringify","handleAmqpErrors","queue","style","toRecord","purge","errorUndefinedQueue","channelInfo","purgeQueue","verbose","messageCount","checkMessageCount","ApiError","httpStatus","INTERNAL_SERVER_ERROR","messages","getData","headers","getHeaderInfo","length","records","message","get","inspect","colors","maxArrayLength","depth","forEach","properties","correlationId","ack","nack","data","Buffer","from","persistent","errorToThrow","tempChannel","deleteQueue","map","content","parse","toString","MarcRecord","subfieldValues","messagesToGet","CHUNK_SIZE","pump","count","results","identifiers","identifier","deliveryTag","fields","includes","concat","undefined","newError","status","payload","logError"],"sources":["../src/amqp.js"],"sourcesContent":["import amqplib from 'amqplib';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport {Error as ApiError} from '@natlibfi/melinda-commons';\nimport {createLogger} from '@natlibfi/melinda-backend-commons';\nimport createDebugLogger from 'debug';\nimport {CHUNK_SIZE} from './constants';\nimport {promisify, inspect} from 'util';\nimport httpStatus from 'http-status';\nimport {logError} from './utils';\n\nexport default async function (AMQP_URL, runHealthCheck = false) {\n const logger = createLogger();\n const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons:amqp');\n const debugHC = debug.extend('HC');\n const debugData = debug.extend('data');\n const setTimeoutPromise = promisify(setTimeout);\n\n debug(`Creating an AMQP operator to ${AMQP_URL}`);\n const connection = await amqplib.connect(AMQP_URL);\n const channel = await connection.createChannel();\n\n const healthCheckLoop = runHealthCheck ? healthCheck() : false;\n\n debug(`Connection: ${connection}`);\n debug(`Channel: ${channel}`);\n debug(`HealthCheckLoop: ${healthCheckLoop ? 'Running health check' : 'Not running health check'}`);\n\n return {checkQueue, consumeChunk, consumeOne, ackMessages, nackMessages, sendToQueue, removeQueue, messagesToRecords, closeChannel, closeConnection};\n\n async function closeChannel() {\n debug(`Closing channel`);\n await channel.close();\n debug(`Channel: ${channel}`);\n }\n\n async function closeConnection() {\n debug(`Closing connection`);\n await connection.close();\n debug(`Connection: ${connection}`);\n }\n\n async function healthCheck(wait = false) {\n if (wait) {\n await setTimeoutPromise(wait);\n return healthCheck(false);\n }\n\n try {\n debugHC(`Health checking amqp by asserting a queue`);\n await channel.assertQueue('HEALTHCHECK', {durable: false});\n debugHC(`Waiting 200ms before running healthCheck next`);\n return healthCheck(200);\n } catch (error) {\n debugHC(`HealthCheck error ${JSON.stringify(error)}`);\n handleAmqpErrors(error);\n }\n }\n\n // eslint-disable-next-line max-statements\n async function checkQueue({queue, style = 'basic', toRecord = true, purge = false}) {\n debug(`checkQueue: ${queue}, Style: ${style}, toRecord: ${toRecord}, Purge: ${purge}`);\n\n try {\n\n errorUndefinedQueue(queue);\n const channelInfo = await channel.assertQueue(queue, {durable: true});\n\n if (purge) {\n await purgeQueue(purge);\n logger.verbose(`Queue ${queue} has purged ${channelInfo.messageCount} messages`);\n debug(`Queue ${queue} has purged ${channelInfo.messageCount} messages`);\n return checkQueue({queue, style});\n }\n\n if (style === 'messages') {\n return channelInfo.messageCount;\n }\n\n\n // Note: returns one message (+ record, of toRecord: true)\n // note: if toRecord is false returns just plain message / false\n // note: if toRecord is true returns {headers, records, messages} -object / false\n // should this be more consistent?\n if (style === 'one') {\n if (checkMessageCount(channelInfo)) {\n return consumeOne(queue, toRecord);\n }\n return false;\n }\n\n // Note: returns a chunk of (100) messages (+ records, if toRecord: true)\n // returns {headers, records, messages} object or {headers, messages} object depending on toRecord\n if (style === 'basic') {\n if (checkMessageCount(channelInfo)) {\n return consumeChunk(queue, toRecord);\n }\n return false;\n }\n\n // Defaults:\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, `CheckQueue does not recognize style ${style}`);\n } catch (error) {\n handleAmqpErrors(error);\n }\n\n function checkMessageCount(channelInfo) {\n if (channelInfo.messageCount < 1) {\n debug(`checkQueue: ${channelInfo.messageCount} - ${queue} is empty`);\n return false;\n }\n debug(`Queue ${queue} has ${channelInfo.messageCount} messages`);\n return true;\n }\n\n function purgeQueue(purge) {\n debug(`Purging queue: ${queue}, purge: ${purge}`);\n if (purge) {\n return channel.purgeQueue(queue);\n }\n }\n }\n\n async function consumeChunk(queue, toRecord) {\n debug(`Prepared to consumeChunk from queue: ${queue}`);\n try {\n await channel.assertQueue(queue, {durable: true});\n\n // getData: next chunk (100) messages\n const messages = await getData(queue);\n\n // Note: headers are from the first message of the chunk\n const headers = getHeaderInfo(messages[0]);\n debug(`consumeChunk (${messages ? messages.length : '0'} from queue ${queue}) ${toRecord ? 'to records' : 'just messages'}`);\n\n if (toRecord) {\n const records = await messagesToRecords(messages);\n return {headers, records, messages};\n }\n\n return {headers, messages};\n } catch (error) {\n handleAmqpErrors(error);\n }\n }\n\n async function consumeOne(queue, toRecord) {\n debug(`Prepared to consumeOne from queue: ${queue}`);\n try {\n await channel.assertQueue(queue, {durable: true});\n\n // Returns false if 0 items in queue\n const message = await channel.get(queue);\n\n debugData(`Message: ${inspect(message, {colors: true, maxArrayLength: 3, depth: 3})}`);\n // Do not spam the logs\n debug(`consumeOne from queue: ${queue} ${toRecord ? 'to records' : 'just the message'}`);\n\n if (message) {\n if (toRecord) {\n const headers = getHeaderInfo(message);\n const records = messagesToRecords([message]);\n return {headers, records, messages: [message]};\n }\n\n return message;\n }\n\n return false;\n } catch (error) {\n handleAmqpErrors(error);\n }\n }\n\n function ackMessages(messages) {\n messages.forEach(message => {\n debug(`Ack message ${message.properties.correlationId}`);\n channel.ack(message);\n });\n }\n\n function nackMessages(messages) {\n messages.forEach(message => {\n debug(`Nack message ${message.properties.correlationId}`);\n channel.nack(message);\n });\n }\n\n async function sendToQueue({queue, correlationId, headers, data}) {\n debug(`sendToQueue`);\n // eslint-disable-next-line no-useless-catch\n try {\n debug(`Queue ${queue}`);\n debug(`CorrelationId ${correlationId}`);\n debugData(`Data ${JSON.stringify(data)}`);\n debug(`Headers ${JSON.stringify(headers)}`);\n\n errorUndefinedQueue(queue);\n\n debug(`Asserting queue: ${queue}`);\n await channel.assertQueue(queue, {durable: true});\n\n debug(`Actually sendToQueue: ${queue}`);\n await channel.sendToQueue(\n queue,\n Buffer.from(JSON.stringify({data})),\n {\n correlationId,\n persistent: true,\n headers\n }\n );\n debug(`Send message for ${correlationId} to queue: ${queue}`);\n\n\n } catch (error) {\n const errorToThrow = error;\n //if (error instanceof ApiError) {\n // throw error;\n //}\n debug(`SendToQueue errored: ${JSON.stringify(error)}`);\n handleAmqpErrors(errorToThrow);\n }\n }\n\n async function removeQueue(queue) {\n // deleteQueue borks the channel if the queue does not exist\n // -> use throwaway tempChannel to avoid killing actual channel in use\n // this might be doable also with assertQueue before deleteQueue\n const tempChannel = await connection.createChannel();\n logger.verbose(`Removing queue ${queue}.`);\n debug(`Removing queue ${queue}.`);\n await tempChannel.deleteQueue(queue);\n\n if (tempChannel) {\n await tempChannel.close();\n return;\n }\n\n return;\n }\n\n // ----------------\n // Helper functions\n // ----------------\n\n function messagesToRecords(messages) {\n debug(`Parsing messages (${messages.length}) to records`);\n\n return messages.map(message => {\n const content = JSON.parse(message.content.toString());\n // Use subfieldValues: false validationOption here\n return new MarcRecord(content.data, {subfieldValues: false});\n });\n }\n\n async function getData(queue) {\n debug(`Getting queue data from ${queue}`);\n try {\n const {messageCount} = await channel.checkQueue(queue);\n debug(`There is ${messageCount} messages in queue ${queue}`);\n const messagesToGet = messageCount >= CHUNK_SIZE ? CHUNK_SIZE : messageCount;\n debug(`Getting ${messagesToGet} messages from queue ${queue}`);\n\n const messages = await pump(messagesToGet);\n\n debug(`Returning ${messages.length} unique messages`);\n\n return messages;\n } catch (error) {\n handleAmqpErrors(error);\n }\n\n async function pump(count, results = [], identifiers = []) {\n if (count === 0) {\n return results;\n }\n\n const message = await channel.get(queue);\n const identifier = {\n correlationId: message.properties.correlationId,\n deliveryTag: message.fields.deliveryTag\n };\n // Filter not unique messages\n if (identifiers.includes(identifier)) {\n return pump(count - 1, results, identifiers);\n }\n\n return pump(count - 1, results.concat(message), identifiers.concat(identifier));\n }\n }\n\n function getHeaderInfo(data) {\n return data.properties.headers;\n }\n\n function errorUndefinedQueue(queue) {\n if (queue === undefined || queue === '' || queue === null) {\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, `Undefined queue!`);\n }\n }\n\n function handleAmqpErrors(error) {\n const newError = error;\n debug(`HandleAmqpErrors got an error: ${JSON.stringify(error)}`);\n if (error instanceof ApiError) {\n debug(`We have an ApiError`);\n throw new ApiError(newError.status, newError.payload);\n }\n debug(`We have a non-ApiError`);\n logError(error);\n throw newError;\n }\n}\n\n\n"],"mappings":";;;;;;;AAAA,IAAAA,QAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,eAAA,GAAAF,OAAA;AACA,IAAAG,sBAAA,GAAAH,OAAA;AACA,IAAAI,MAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,UAAA,GAAAL,OAAA;AACA,IAAAM,KAAA,GAAAN,OAAA;AACA,IAAAO,WAAA,GAAAR,sBAAA,CAAAC,OAAA;AACA,IAAAQ,MAAA,GAAAR,OAAA;AAEe,eAAAS,SAAgBC,QAAQ,EAAEC,cAAc,GAAG,KAAK,EAAE;EAC/D,MAAMC,MAAM,GAAG,IAAAC,mCAAY,EAAC,CAAC;EAC7B,MAAMC,KAAK,GAAG,IAAAC,cAAiB,EAAC,yCAAyC,CAAC;EAC1E,MAAMC,OAAO,GAAGF,KAAK,CAACG,MAAM,CAAC,IAAI,CAAC;EAClC,MAAMC,SAAS,GAAGJ,KAAK,CAACG,MAAM,CAAC,MAAM,CAAC;EACtC,MAAME,iBAAiB,GAAG,IA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AASX,mBAAmBA,CAACJ,KAAK,EAAE;IAClC,IAAIA,KAAK,KAAKsD,SAAS,IAAItD,KAAK,KAAK,EAAE,IAAIA,KAAK,KAAK,IAAI,EAAE;MACzD,MAAM,IAAIU,qBAAQ,CAACC,mBAAU,CAACC,qBAAqB,EAAE,kBAAkB,CAAC;IAC1E;EACF;EAEA,SAASb,gBAAgBA,CAACH,KAAK,EAAE;IAC/B,MAAM2D,QAAQ,GAAG3D,KAAK;IACtB7B,KAAK,CAAC,kCAAkC8B,IAAI,CAACC,SAAS,CAACF,KAAK,CAAC,EAAE,CAAC;IAChE,IAAIA,KAAK,YAAYc,qBAAQ,EAAE;MAC7B3C,KAAK,CAAC,qBAAqB,CAAC;MAC5B,MAAM,IAAI2C,qBAAQ,CAAC6C,QAAQ,CAACC,MAAM,EAAED,QAAQ,CAACE,OAAO,CAAC;IACvD;IACA1F,KAAK,CAAC,wBAAwB,CAAC;IAC/B,IAAA2F,eAAQ,EAAC9D,KAAK,CAAC;IACf,MAAM2D,QAAQ;EAChB;AACF","ignoreList":[]}
|
package/dist/constants.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.QUEUE_ITEM_STATE = exports.OPERATIONS = exports.LOG_ITEM_TYPE = exports.IMPORT_JOB_STATE = exports.CONVERSION_FORMATS = exports.CHUNK_SIZE = void 0;
|
|
7
|
-
// QueueItemState flows: see README.md
|
|
8
|
-
|
|
9
|
-
const QUEUE_ITEM_STATE = exports.QUEUE_ITEM_STATE = {
|
|
10
|
-
VALIDATOR: {
|
|
11
|
-
PENDING_QUEUING: 'PENDING_QUEUING',
|
|
12
|
-
PENDING_VALIDATION: 'PENDING_VALIDATION',
|
|
13
|
-
QUEUING_IN_PROGRESS: 'QUEUING_IN_PROGRESS',
|
|
14
|
-
UPLOADING: 'UPLOADING',
|
|
15
|
-
VALIDATING: 'VALIDATING',
|
|
16
|
-
WAITING_FOR_RECORDS: 'WAITING_FOR_RECORDS'
|
|
17
|
-
},
|
|
18
|
-
IMPORTER: {
|
|
19
|
-
IMPORTING: 'IMPORTING',
|
|
20
|
-
IN_PROCESS: 'IN_PROCESS',
|
|
21
|
-
IN_QUEUE: 'IN_QUEUE'
|
|
22
|
-
},
|
|
23
|
-
DONE: 'DONE',
|
|
24
|
-
ERROR: 'ERROR',
|
|
25
|
-
ABORT: 'ABORT'
|
|
26
|
-
};
|
|
27
|
-
const IMPORT_JOB_STATE = exports.IMPORT_JOB_STATE = {
|
|
28
|
-
EMPTY: 'EMPTY',
|
|
29
|
-
QUEUING: 'QUEUING',
|
|
30
|
-
IN_QUEUE: 'IN_QUEUE',
|
|
31
|
-
IMPORTING: 'IMPORTING',
|
|
32
|
-
PROCESSING: 'PROCESSING',
|
|
33
|
-
DONE: 'DONE',
|
|
34
|
-
ERROR: 'ERROR',
|
|
35
|
-
ABORT: 'ABORT'
|
|
36
|
-
};
|
|
37
|
-
const OPERATIONS = exports.OPERATIONS = {
|
|
38
|
-
CREATE: 'CREATE',
|
|
39
|
-
UPDATE: 'UPDATE',
|
|
40
|
-
FIX: 'FIX'
|
|
41
|
-
};
|
|
42
|
-
const CHUNK_SIZE = exports.CHUNK_SIZE = 100;
|
|
43
|
-
|
|
44
|
-
// We could configure here whether a logItemType is for a several records of a single record
|
|
45
|
-
// ie. whether is has bulkSequence or bulkSequenceStart & bulkSequenceEnd
|
|
46
|
-
const LOG_ITEM_TYPE = exports.LOG_ITEM_TYPE = {
|
|
47
|
-
INPUT_RECORD_LOG: 'INPUT_RECORD_LOG',
|
|
48
|
-
MERGE_LOG: 'MERGE_LOG',
|
|
49
|
-
MATCH_LOG: 'MATCH_LOG',
|
|
50
|
-
RESULT_RECORD_LOG: 'RESULT_RECORD_LOG',
|
|
51
|
-
SPLITTER_LOG: 'SPLITTER_LOG',
|
|
52
|
-
LOAD_PROCESS_LOG: 'LOAD_PROCESS_LOG'
|
|
53
|
-
};
|
|
54
|
-
const CONVERSION_FORMATS = exports.CONVERSION_FORMATS = {
|
|
55
|
-
MARCXML: 'MARCXML',
|
|
56
|
-
ISO2709: 'ISO2709',
|
|
57
|
-
JSON: 'JSON',
|
|
58
|
-
ALEPHSEQ: 'ALEPHSEQ'
|
|
59
|
-
};
|
|
60
|
-
//# sourceMappingURL=constants.js.map
|
package/dist/constants.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","names":["QUEUE_ITEM_STATE","exports","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","FIX","CHUNK_SIZE","LOG_ITEM_TYPE","INPUT_RECORD_LOG","MERGE_LOG","MATCH_LOG","RESULT_RECORD_LOG","SPLITTER_LOG","LOAD_PROCESS_LOG","CONVERSION_FORMATS","MARCXML","ISO2709","JSON","ALEPHSEQ"],"sources":["../src/constants.js"],"sourcesContent":["// 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 FIX: 'FIX'\n};\n\nexport const CHUNK_SIZE = 100;\n\n// We could configure here whether a logItemType is for a several records of a single record\n// ie. whether is has bulkSequence or bulkSequenceStart & bulkSequenceEnd\nexport const LOG_ITEM_TYPE = {\n INPUT_RECORD_LOG: 'INPUT_RECORD_LOG',\n MERGE_LOG: 'MERGE_LOG',\n MATCH_LOG: 'MATCH_LOG',\n RESULT_RECORD_LOG: 'RESULT_RECORD_LOG',\n SPLITTER_LOG: 'SPLITTER_LOG',\n LOAD_PROCESS_LOG: 'LOAD_PROCESS_LOG'\n};\n\nexport const CONVERSION_FORMATS = {\n MARCXML: 'MARCXML',\n ISO2709: 'ISO2709',\n JSON: 'JSON',\n ALEPHSEQ: 'ALEPHSEQ'\n};\n"],"mappings":";;;;;;AAAA;;AAEO,MAAMA,gBAAgB,GAAAC,OAAA,CAAAD,gBAAA,GAAG;EAC9BE,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;AAEM,MAAMC,gBAAgB,GAAAf,OAAA,CAAAe,gBAAA,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;AAEM,MAAMK,UAAU,GAAAnB,OAAA,CAAAmB,UAAA,GAAG;EACxBC,MAAM,EAAE,QAAQ;EAChBC,MAAM,EAAE,QAAQ;EAChBC,GAAG,EAAE;AACP,CAAC;AAEM,MAAMC,UAAU,GAAAvB,OAAA,CAAAuB,UAAA,GAAG,GAAG;;AAE7B;AACA;AACO,MAAMC,aAAa,GAAAxB,OAAA,CAAAwB,aAAA,GAAG;EAC3BC,gBAAgB,EAAE,kBAAkB;EACpCC,SAAS,EAAE,WAAW;EACtBC,SAAS,EAAE,WAAW;EACtBC,iBAAiB,EAAE,mBAAmB;EACtCC,YAAY,EAAE,cAAc;EAC5BC,gBAAgB,EAAE;AACpB,CAAC;AAEM,MAAMC,kBAAkB,GAAA/B,OAAA,CAAA+B,kBAAA,GAAG;EAChCC,OAAO,EAAE,SAAS;EAClBC,OAAO,EAAE,SAAS;EAClBC,IAAI,EAAE,MAAM;EACZC,QAAQ,EAAE;AACZ,CAAC","ignoreList":[]}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.default = _default;
|
|
8
|
-
var _httpStatus = _interopRequireDefault(require("http-status"));
|
|
9
|
-
var _marcRecordSerializers = require("@natlibfi/marc-record-serializers");
|
|
10
|
-
var _melindaBackendCommons = require("@natlibfi/melinda-backend-commons");
|
|
11
|
-
var _melindaCommons = require("@natlibfi/melinda-commons");
|
|
12
|
-
var _constants = require("../constants");
|
|
13
|
-
var _utils = require("../utils");
|
|
14
|
-
function _default() {
|
|
15
|
-
const logger = (0, _melindaBackendCommons.createLogger)();
|
|
16
|
-
return {
|
|
17
|
-
serialize,
|
|
18
|
-
unserialize
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
// This uses format as a number form contants CONVERSION_FORMATS
|
|
22
|
-
function serialize(record, format) {
|
|
23
|
-
logger.verbose(`Serializing record to ${format}`);
|
|
24
|
-
try {
|
|
25
|
-
if (format === _constants.CONVERSION_FORMATS.MARCXML) {
|
|
26
|
-
return _marcRecordSerializers.MARCXML.to(record);
|
|
27
|
-
}
|
|
28
|
-
if (format === _constants.CONVERSION_FORMATS.ISO2709) {
|
|
29
|
-
return _marcRecordSerializers.ISO2709.to(record);
|
|
30
|
-
}
|
|
31
|
-
if (format === _constants.CONVERSION_FORMATS.JSON) {
|
|
32
|
-
return _marcRecordSerializers.Json.to(record);
|
|
33
|
-
}
|
|
34
|
-
if (format === _constants.CONVERSION_FORMATS.ALEPHSEQ) {
|
|
35
|
-
return _marcRecordSerializers.AlephSequential.to(record);
|
|
36
|
-
}
|
|
37
|
-
throw new _melindaCommons.Error(_httpStatus.default.UNSUPPORTED_MEDIA_TYPE);
|
|
38
|
-
} catch (err) {
|
|
39
|
-
(0, _utils.logError)(err);
|
|
40
|
-
const message = err.message || err.payload?.message || err.payload;
|
|
41
|
-
logger.debug(`${message}`);
|
|
42
|
-
if (err instanceof _melindaCommons.Error) {
|
|
43
|
-
// eslint-disable-line functional/no-conditional-statements
|
|
44
|
-
throw err;
|
|
45
|
-
}
|
|
46
|
-
throw new _melindaCommons.Error(_httpStatus.default.BAD_REQUEST, `Error while serializing record. ${message}`);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// eslint-disable-next-line max-statements
|
|
51
|
-
function unserialize(data, format, validationOptions = {
|
|
52
|
-
subfieldValues: false
|
|
53
|
-
}) {
|
|
54
|
-
logger.verbose(`Unserializing record from ${format}`);
|
|
55
|
-
logger.silly(`Format: ${format}`);
|
|
56
|
-
logger.debug(`Validation options: ${JSON.stringify(validationOptions)}`);
|
|
57
|
-
logger.silly(`Data: ${JSON.stringify(data)}`);
|
|
58
|
-
try {
|
|
59
|
-
if (format === _constants.CONVERSION_FORMATS.MARCXML) {
|
|
60
|
-
logger.silly('Unserialize format marcxml');
|
|
61
|
-
return _marcRecordSerializers.MARCXML.from(data, validationOptions);
|
|
62
|
-
}
|
|
63
|
-
if (format === _constants.CONVERSION_FORMATS.ISO2709) {
|
|
64
|
-
logger.silly('Unserialize format iso2709');
|
|
65
|
-
return _marcRecordSerializers.ISO2709.from(data, validationOptions);
|
|
66
|
-
}
|
|
67
|
-
if (format === _constants.CONVERSION_FORMATS.JSON) {
|
|
68
|
-
logger.silly('Unserialize format json');
|
|
69
|
-
return _marcRecordSerializers.Json.from(data, validationOptions);
|
|
70
|
-
}
|
|
71
|
-
if (format === _constants.CONVERSION_FORMATS.ALEPHSEQ) {
|
|
72
|
-
logger.silly('Unserialize format aleph sequential');
|
|
73
|
-
return _marcRecordSerializers.AlephSequential.from(data, validationOptions);
|
|
74
|
-
}
|
|
75
|
-
throw new _melindaCommons.Error(_httpStatus.default.UNSUPPORTED_MEDIA_TYPE);
|
|
76
|
-
} catch (err) {
|
|
77
|
-
(0, _utils.logError)(err);
|
|
78
|
-
const message = err.message || err.payload?.message || err.payload;
|
|
79
|
-
logger.debug(`${message}`);
|
|
80
|
-
if (err instanceof _melindaCommons.Error) {
|
|
81
|
-
// eslint-disable-line functional/no-conditional-statements
|
|
82
|
-
throw err;
|
|
83
|
-
}
|
|
84
|
-
throw new _melindaCommons.Error(_httpStatus.default.BAD_REQUEST, `Error while unserializing record. ${message}`);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
//# sourceMappingURL=conversion.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"conversion.js","names":["_httpStatus","_interopRequireDefault","require","_marcRecordSerializers","_melindaBackendCommons","_melindaCommons","_constants","_utils","_default","logger","createLogger","serialize","unserialize","record","format","verbose","CONVERSION_FORMATS","MARCXML","to","ISO2709","JSON","Json","ALEPHSEQ","AlephSequential","ConversionError","httpStatus","UNSUPPORTED_MEDIA_TYPE","err","logError","message","payload","debug","BAD_REQUEST","data","validationOptions","subfieldValues","silly","stringify","from"],"sources":["../../src/helpers/conversion.js"],"sourcesContent":["\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 const message = err.message || err.payload?.message || err.payload;\n logger.debug(`${message}`);\n if (err instanceof ConversionError) { // eslint-disable-line functional/no-conditional-statements\n throw err;\n }\n throw new ConversionError(httpStatus.BAD_REQUEST, `Error while serializing record. ${message}`);\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 const message = err.message || err.payload?.message || err.payload;\n logger.debug(`${message}`);\n if (err instanceof ConversionError) { // eslint-disable-line functional/no-conditional-statements\n throw err;\n }\n throw new ConversionError(httpStatus.BAD_REQUEST, `Error while unserializing record. ${message}`);\n }\n }\n}\n"],"mappings":";;;;;;;AAEA,IAAAA,WAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,sBAAA,GAAAD,OAAA;AACA,IAAAE,sBAAA,GAAAF,OAAA;AACA,IAAAG,eAAA,GAAAH,OAAA;AACA,IAAAI,UAAA,GAAAJ,OAAA;AACA,IAAAK,MAAA,GAAAL,OAAA;AAEe,SAAAM,SAAA,EAAY;EACzB,MAAMC,MAAM,GAAG,IAAAC,mCAAY,EAAC,CAAC;EAE7B,OAAO;IAACC,SAAS;IAAEC;EAAW,CAAC;;EAE/B;EACA,SAASD,SAASA,CAACE,MAAM,EAAEC,MAAM,EAAE;IACjCL,MAAM,CAACM,OAAO,CAAC,yBAAyBD,MAAM,EAAE,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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CAACG,OAAO,EAAE;QACzCV,MAAM,CAAC2B,KAAK,CAAC,4BAA4B,CAAC;QAC1C,OAAOjB,8BAAO,CAACmB,IAAI,CAACL,IAAI,EAAEC,iBAAiB,CAAC;MAC9C;MAEA,IAAIpB,MAAM,KAAKE,6BAAkB,CAACI,IAAI,EAAE;QACtCX,MAAM,CAAC2B,KAAK,CAAC,yBAAyB,CAAC;QACvC,OAAOf,2BAAI,CAACiB,IAAI,CAACL,IAAI,EAAEC,iBAAiB,CAAC;MAC3C;MAEA,IAAIpB,MAAM,KAAKE,6BAAkB,CAACM,QAAQ,EAAE;QAC1Cb,MAAM,CAAC2B,KAAK,CAAC,qCAAqC,CAAC;QACnD,OAAOb,sCAAe,CAACe,IAAI,CAACL,IAAI,EAAEC,iBAAiB,CAAC;MACtD;MAEA,MAAM,IAAIV,qBAAe,CAACC,mBAAU,CAACC,sBAAsB,CAAC;IAC9D,CAAC,CAAC,OAAOC,GAAG,EAAE;MACZ,IAAAC,eAAQ,EAACD,GAAG,CAAC;MACb,MAAME,OAAO,GAAGF,GAAG,CAACE,OAAO,IAAIF,GAAG,CAACG,OAAO,EAAED,OAAO,IAAIF,GAAG,CAACG,OAAO;MAClErB,MAAM,CAACsB,KAAK,CAAC,GAAGF,OAAO,EAAE,CAAC;MAC1B,IAAIF,GAAG,YAAYH,qBAAe,EAAE;QAAE;QACpC,MAAMG,GAAG;MACX;MACA,MAAM,IAAIH,qBAAe,CAACC,mBAAU,CAACO,WAAW,EAAE,qCAAqCH,OAAO,EAAE,CAAC;IACnG;EACF;AACF","ignoreList":[]}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.REPLACE_PREFIXES = exports.BIB_STRIP_MELINDA_TEMP_SUBFIELDS_SETTINGS = exports.BIB_STRIP_F984S_SETTINGS = exports.BIB_STRIP_F884S_SETTINGS = exports.BIB_PREVALIDATION_FIX_SETTINGS = exports.BIB_PREIMPORT_FIX_SETTINGS = exports.BIB_POSTMERGE_FIX_SETTINGS = exports.BIB_HANDLE_TEMP_URNS_SETTINGS = exports.BIB_FORMAT_SETTINGS = exports.BIB_F035_TO_SID = exports.AUTNAME_PREIMPORT_FIX_SETTINGS = void 0;
|
|
7
|
-
// This could be formatted so that 035-prefix and SID contents would be better connected than by just an array index
|
|
8
|
-
const BIB_F035_TO_SID = exports.BIB_F035_TO_SID = {
|
|
9
|
-
f035Filters: [/^\(FI-BTJ\)/u, /^\(FI-TATI\)/u],
|
|
10
|
-
fSIDFilters: ['FI-BTJ', 'tati']
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
// There is somewhere other implementations of this same standardPrefixes to alephInternalPrefixes normalization
|
|
14
|
-
const REPLACE_PREFIXES = exports.REPLACE_PREFIXES = [{
|
|
15
|
-
oldPrefix: 'FI-MELINDA',
|
|
16
|
-
newPrefix: 'FIN01',
|
|
17
|
-
prefixReplaceCodes: ['w']
|
|
18
|
-
}, {
|
|
19
|
-
oldPrefix: 'FI-ASTERI-S',
|
|
20
|
-
newPrefix: 'FIN10',
|
|
21
|
-
prefixReplaceCodes: ['0']
|
|
22
|
-
}, {
|
|
23
|
-
oldPrefix: 'FI-ASTERI-N',
|
|
24
|
-
newPrefix: 'FIN11',
|
|
25
|
-
prefixReplaceCodes: ['0']
|
|
26
|
-
}, {
|
|
27
|
-
oldPrefix: 'FI-ASTERI-A',
|
|
28
|
-
newPrefix: 'FIN12',
|
|
29
|
-
prefixReplaceCodes: ['0']
|
|
30
|
-
}, {
|
|
31
|
-
oldPrefix: 'FI-ASTERI-W',
|
|
32
|
-
newPrefix: 'FIN13',
|
|
33
|
-
prefixReplaceCodes: ['0']
|
|
34
|
-
}];
|
|
35
|
-
|
|
36
|
-
// If placed in config.js testing needs envs
|
|
37
|
-
// BIB_FORMAT_SETTINGS is outdated, use other settings instead
|
|
38
|
-
|
|
39
|
-
const BIB_FORMAT_SETTINGS = exports.BIB_FORMAT_SETTINGS = {
|
|
40
|
-
replacePrefixes: REPLACE_PREFIXES,
|
|
41
|
-
generateMissingSIDs: BIB_F035_TO_SID
|
|
42
|
-
};
|
|
43
|
-
const BIB_PREVALIDATION_FIX_SETTINGS = exports.BIB_PREVALIDATION_FIX_SETTINGS = {
|
|
44
|
-
generateMissingSIDs: BIB_F035_TO_SID
|
|
45
|
-
};
|
|
46
|
-
const BIB_POSTMERGE_FIX_SETTINGS = exports.BIB_POSTMERGE_FIX_SETTINGS = {
|
|
47
|
-
handleTempUrns: true,
|
|
48
|
-
stripF884s: true
|
|
49
|
-
};
|
|
50
|
-
const BIB_PREIMPORT_FIX_SETTINGS = exports.BIB_PREIMPORT_FIX_SETTINGS = {
|
|
51
|
-
replacePrefixes: REPLACE_PREFIXES,
|
|
52
|
-
stripMelindaTempSubfields: true,
|
|
53
|
-
stripF984s: true
|
|
54
|
-
};
|
|
55
|
-
const AUTNAME_PREIMPORT_FIX_SETTINGS = exports.AUTNAME_PREIMPORT_FIX_SETTINGS = {
|
|
56
|
-
replacePrefixes: REPLACE_PREFIXES
|
|
57
|
-
};
|
|
58
|
-
const BIB_HANDLE_TEMP_URNS_SETTINGS = exports.BIB_HANDLE_TEMP_URNS_SETTINGS = {
|
|
59
|
-
handleTempUrns: true
|
|
60
|
-
};
|
|
61
|
-
const BIB_STRIP_F884S_SETTINGS = exports.BIB_STRIP_F884S_SETTINGS = {
|
|
62
|
-
stripF884s: true
|
|
63
|
-
};
|
|
64
|
-
const BIB_STRIP_F984S_SETTINGS = exports.BIB_STRIP_F984S_SETTINGS = {
|
|
65
|
-
stripF984s: true
|
|
66
|
-
};
|
|
67
|
-
const BIB_STRIP_MELINDA_TEMP_SUBFIELDS_SETTINGS = exports.BIB_STRIP_MELINDA_TEMP_SUBFIELDS_SETTINGS = {
|
|
68
|
-
stripMelindaTempSubfields: true
|
|
69
|
-
};
|
|
70
|
-
//# sourceMappingURL=fix-constants.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fix-constants.js","names":["BIB_F035_TO_SID","exports","f035Filters","fSIDFilters","REPLACE_PREFIXES","oldPrefix","newPrefix","prefixReplaceCodes","BIB_FORMAT_SETTINGS","replacePrefixes","generateMissingSIDs","BIB_PREVALIDATION_FIX_SETTINGS","BIB_POSTMERGE_FIX_SETTINGS","handleTempUrns","stripF884s","BIB_PREIMPORT_FIX_SETTINGS","stripMelindaTempSubfields","stripF984s","AUTNAME_PREIMPORT_FIX_SETTINGS","BIB_HANDLE_TEMP_URNS_SETTINGS","BIB_STRIP_F884S_SETTINGS","BIB_STRIP_F984S_SETTINGS","BIB_STRIP_MELINDA_TEMP_SUBFIELDS_SETTINGS"],"sources":["../../src/helpers/fix-constants.js"],"sourcesContent":["// This could be formatted so that 035-prefix and SID contents would be better connected than by just an array index\nexport const BIB_F035_TO_SID = {\n f035Filters: [/^\\(FI-BTJ\\)/u, /^\\(FI-TATI\\)/u],\n fSIDFilters: ['FI-BTJ', 'tati']\n};\n\n// There is somewhere other implementations of this same standardPrefixes to alephInternalPrefixes normalization\nexport const REPLACE_PREFIXES = [\n {\n oldPrefix: 'FI-MELINDA',\n newPrefix: 'FIN01',\n prefixReplaceCodes: ['w']\n },\n {\n oldPrefix: 'FI-ASTERI-S',\n newPrefix: 'FIN10',\n prefixReplaceCodes: ['0']\n },\n {\n oldPrefix: 'FI-ASTERI-N',\n newPrefix: 'FIN11',\n prefixReplaceCodes: ['0']\n },\n {\n oldPrefix: 'FI-ASTERI-A',\n newPrefix: 'FIN12',\n prefixReplaceCodes: ['0']\n },\n {\n oldPrefix: 'FI-ASTERI-W',\n newPrefix: 'FIN13',\n prefixReplaceCodes: ['0']\n }\n];\n\n// If placed in config.js testing needs envs\n// BIB_FORMAT_SETTINGS is outdated, use other settings instead\n\n\nexport const BIB_FORMAT_SETTINGS = {\n replacePrefixes: REPLACE_PREFIXES,\n generateMissingSIDs: BIB_F035_TO_SID\n};\n\nexport const BIB_PREVALIDATION_FIX_SETTINGS = {\n generateMissingSIDs: BIB_F035_TO_SID\n};\n\nexport const BIB_POSTMERGE_FIX_SETTINGS = {\n handleTempUrns: true,\n stripF884s: true\n};\n\nexport const BIB_PREIMPORT_FIX_SETTINGS = {\n replacePrefixes: REPLACE_PREFIXES,\n stripMelindaTempSubfields: true,\n stripF984s: true\n};\n\nexport const AUTNAME_PREIMPORT_FIX_SETTINGS = {\n replacePrefixes: REPLACE_PREFIXES\n};\n\nexport const BIB_HANDLE_TEMP_URNS_SETTINGS = {\n handleTempUrns: true\n};\n\nexport const BIB_STRIP_F884S_SETTINGS = {\n stripF884s: true\n};\n\nexport const BIB_STRIP_F984S_SETTINGS = {\n stripF984s: true\n};\n\nexport const BIB_STRIP_MELINDA_TEMP_SUBFIELDS_SETTINGS = {\n stripMelindaTempSubfields: true\n};\n"],"mappings":";;;;;;AAAA;AACO,MAAMA,eAAe,GAAAC,OAAA,CAAAD,eAAA,GAAG;EAC7BE,WAAW,EAAE,CAAC,cAAc,EAAE,eAAe,CAAC;EAC9CC,WAAW,EAAE,CAAC,QAAQ,EAAE,MAAM;AAChC,CAAC;;AAED;AACO,MAAMC,gBAAgB,GAAAH,OAAA,CAAAG,gBAAA,GAAG,CAC9B;EACEC,SAAS,EAAE,YAAY;EACvBC,SAAS,EAAE,OAAO;EAClBC,kBAAkB,EAAE,CAAC,GAAG;AAC1B,CAAC,EACD;EACEF,SAAS,EAAE,aAAa;EACxBC,SAAS,EAAE,OAAO;EAClBC,kBAAkB,EAAE,CAAC,GAAG;AAC1B,CAAC,EACD;EACEF,SAAS,EAAE,aAAa;EACxBC,SAAS,EAAE,OAAO;EAClBC,kBAAkB,EAAE,CAAC,GAAG;AAC1B,CAAC,EACD;EACEF,SAAS,EAAE,aAAa;EACxBC,SAAS,EAAE,OAAO;EAClBC,kBAAkB,EAAE,CAAC,GAAG;AAC1B,CAAC,EACD;EACEF,SAAS,EAAE,aAAa;EACxBC,S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