@natlibfi/melinda-rest-api-commons 2.3.2-alpha.1 → 2.3.2-alpha.11
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.health.spec.js +69 -0
- package/dist/amqp.health.spec.js.map +1 -0
- package/dist/amqp.js +135 -92
- package/dist/amqp.js.map +1 -1
- package/dist/amqp.tests.spec.js +338 -0
- package/dist/amqp.tests.spec.js.map +1 -0
- 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 +98 -0
- package/dist/helpers/fix-constants.js.map +1 -0
- package/dist/helpers/fix-handle-tempurns.js +153 -0
- package/dist/helpers/fix-handle-tempurns.js.map +1 -0
- package/dist/helpers/fix-strip-f884s.js +87 -0
- package/dist/helpers/fix-strip-f884s.js.map +1 -0
- package/dist/helpers/fix-utils.js +82 -0
- package/dist/helpers/fix-utils.js.map +1 -0
- package/dist/helpers/fix.js +178 -0
- package/dist/helpers/fix.js.map +1 -0
- package/dist/helpers/fix.spec.js +46 -0
- package/dist/helpers/fix.spec.js.map +1 -0
- 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 +12 -18
- package/dist/index.js.map +1 -1
- package/dist/mongo.js +50 -89
- package/dist/mongo.js.map +1 -1
- package/dist/mongo.spec.js.draft +54 -0
- package/dist/mongoLog.js +16 -35
- package/dist/mongoLog.js.map +1 -1
- package/dist/utils.js +33 -35
- package/dist/utils.js.map +1 -1
- package/package.json +122 -116
- package/dist/helpers/format.js +0 -305
- package/dist/helpers/format.js.map +0 -1
- package/dist/helpers/format.spec.js +0 -224
- package/dist/helpers/format.spec.js.map +0 -1
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _chai = require("chai");
|
|
4
|
+
var _fixura = require("@natlibfi/fixura");
|
|
5
|
+
var _debug = _interopRequireDefault(require("debug"));
|
|
6
|
+
var _fixugen = _interopRequireDefault(require("@natlibfi/fixugen"));
|
|
7
|
+
var _index = require("./index");
|
|
8
|
+
var _melindaCommons = require("@natlibfi/melinda-commons");
|
|
9
|
+
var _util = require("util");
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
* @licstart The following is the entire license notice for the JavaScript code in this file.
|
|
14
|
+
*
|
|
15
|
+
* Shared modules for microservices of Melinda rest api batch import system
|
|
16
|
+
*
|
|
17
|
+
* Copyright (C) 2022 University Of Helsinki (The National Library Of Finland)
|
|
18
|
+
*
|
|
19
|
+
* This file is part of melinda-rest-api-commons
|
|
20
|
+
*
|
|
21
|
+
* melinda-rest-api-commons program is free software: you can redistribute it and/or modify
|
|
22
|
+
* it under the terms of the GNU Affero General Public License as
|
|
23
|
+
* published by the Free Software Foundation, either version 3 of the
|
|
24
|
+
* License, or (at your option) any later version.
|
|
25
|
+
*
|
|
26
|
+
* melinda-rest-api-commons is distributed in the hope that it will be useful,
|
|
27
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
28
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
29
|
+
* GNU Affero General Public License for more details.
|
|
30
|
+
*
|
|
31
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
32
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
33
|
+
*
|
|
34
|
+
* @licend The above is the entire license notice
|
|
35
|
+
* for the JavaScript code in this file.
|
|
36
|
+
*
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
const setTimeoutPromise = (0, _util.promisify)(setTimeout);
|
|
40
|
+
const debug = (0, _debug.default)('@natlibfi/melinda-rest-api-commons:amqp:test');
|
|
41
|
+
//const debugData = debug.extend('data');
|
|
42
|
+
|
|
43
|
+
const testData = {
|
|
44
|
+
queue: 'TESTQUEUE',
|
|
45
|
+
correlationId: 'aaaaaaaa-0000-aaaa-0000-000000000000',
|
|
46
|
+
data: {
|
|
47
|
+
'leader': '02518cam a2200745zi 4500',
|
|
48
|
+
'fields': [{
|
|
49
|
+
'tag': '001',
|
|
50
|
+
'value': '000019640'
|
|
51
|
+
}]
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
debug(`Testing amqp against a local AMQP instance - we'll need some kind of mockup for this`);
|
|
55
|
+
const amqpUrl = 'amqp://127.0.0.1:5672/';
|
|
56
|
+
// eslint-disable-next-line functional/no-let
|
|
57
|
+
let amqpOperator;
|
|
58
|
+
(0, _fixugen.default)({
|
|
59
|
+
callback,
|
|
60
|
+
path: [__dirname, '..', 'test-fixtures', 'amqp'],
|
|
61
|
+
recurse: false,
|
|
62
|
+
useMetadataFile: true,
|
|
63
|
+
fixura: {
|
|
64
|
+
failWhenNotFound: true,
|
|
65
|
+
reader: _fixura.READERS.JSON
|
|
66
|
+
},
|
|
67
|
+
mocha: {
|
|
68
|
+
before: async () => {
|
|
69
|
+
debug(`Connecting to ${amqpUrl}, with healthCheck running`);
|
|
70
|
+
amqpOperator = await (0, _index.amqpFactory)(amqpUrl, true);
|
|
71
|
+
},
|
|
72
|
+
beforeEach: async () => {
|
|
73
|
+
await amqpOperator.checkQueue({
|
|
74
|
+
queue: testData.queue,
|
|
75
|
+
toRecord: false,
|
|
76
|
+
purge: true
|
|
77
|
+
});
|
|
78
|
+
},
|
|
79
|
+
afterEach: async () => {
|
|
80
|
+
await amqpOperator.removeQueue(testData.queue);
|
|
81
|
+
},
|
|
82
|
+
after: async () => {
|
|
83
|
+
await amqpOperator.closeConnection();
|
|
84
|
+
//await testHeathCheck();
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
// eslint-disable-next-line max-statements
|
|
90
|
+
async function callback({
|
|
91
|
+
getFixture,
|
|
92
|
+
expectToFail = false,
|
|
93
|
+
expectedErrorStatus = '',
|
|
94
|
+
ackMessages = false,
|
|
95
|
+
nackMessages = false,
|
|
96
|
+
checkNextMessage = false,
|
|
97
|
+
checkQueueStyle = false,
|
|
98
|
+
queue = testData.queue,
|
|
99
|
+
sentToQueue,
|
|
100
|
+
expectedMessageCount,
|
|
101
|
+
removeQueue = false,
|
|
102
|
+
expectedErrorMessage = undefined,
|
|
103
|
+
expectApiError = false,
|
|
104
|
+
expectFalseCheckResult = false
|
|
105
|
+
}) {
|
|
106
|
+
try {
|
|
107
|
+
await sendMessagesToQueue();
|
|
108
|
+
await ackOrNackMessages();
|
|
109
|
+
await checkQueue();
|
|
110
|
+
await queueRemoval();
|
|
111
|
+
const messageCount = await amqpOperator.checkQueue({
|
|
112
|
+
queue,
|
|
113
|
+
style: 'messages'
|
|
114
|
+
});
|
|
115
|
+
debug(`MessageCount: ${messageCount}`);
|
|
116
|
+
(0, _chai.expect)(messageCount).to.eql(expectedMessageCount);
|
|
117
|
+
if (checkNextMessage) {
|
|
118
|
+
// eslint-disable-line
|
|
119
|
+
const {
|
|
120
|
+
headers,
|
|
121
|
+
records
|
|
122
|
+
} = await queueCheckNextMessage();
|
|
123
|
+
const nextMessage = {
|
|
124
|
+
headers,
|
|
125
|
+
records
|
|
126
|
+
};
|
|
127
|
+
const expectedNextMessage = getFixture('expectedMessage.json');
|
|
128
|
+
(0, _chai.expect)(nextMessage).to.eql(expectedNextMessage);
|
|
129
|
+
}
|
|
130
|
+
} catch (error) {
|
|
131
|
+
if (!expectToFail) {
|
|
132
|
+
throw error;
|
|
133
|
+
}
|
|
134
|
+
(0, _chai.expect)(expectToFail, 'This is expected to fail').to.equal(true);
|
|
135
|
+
testErrors(error);
|
|
136
|
+
}
|
|
137
|
+
function testErrors(error) {
|
|
138
|
+
if (expectApiError) {
|
|
139
|
+
(0, _chai.expect)(error).to.be.instanceOf(_melindaCommons.Error);
|
|
140
|
+
debug(`We expected and got an ApiError`);
|
|
141
|
+
(0, _chai.expect)(error.status).to.equal(expectedErrorStatus);
|
|
142
|
+
if (expectedErrorMessage) {
|
|
143
|
+
(0, _chai.expect)(error.payload).to.eql(expectedErrorMessage);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
(0, _chai.expect)(error).not.to.be.instanceOf(_melindaCommons.Error);
|
|
149
|
+
debug(`We expected and got an non-ApiError`);
|
|
150
|
+
debug(`Error is a ${error.constructor.name}`);
|
|
151
|
+
}
|
|
152
|
+
function queueRemoval() {
|
|
153
|
+
if (removeQueue) {
|
|
154
|
+
return amqpOperator.removeQueue(removeQueue);
|
|
155
|
+
}
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
function queueCheckNextMessage() {
|
|
159
|
+
if (checkNextMessage) {
|
|
160
|
+
return amqpOperator.consumeOne(testData.queue, true);
|
|
161
|
+
}
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// eslint-disable-next-line max-statements
|
|
166
|
+
async function checkQueue() {
|
|
167
|
+
debug(`checkQueueStyle: ${checkQueueStyle}`);
|
|
168
|
+
if (checkQueueStyle === 'oneToRecord') {
|
|
169
|
+
const result = await amqpOperator.checkQueue({
|
|
170
|
+
queue,
|
|
171
|
+
style: 'one',
|
|
172
|
+
toRecord: true,
|
|
173
|
+
purge: false
|
|
174
|
+
});
|
|
175
|
+
if (expectFalseCheckResult) {
|
|
176
|
+
(0, _chai.expect)(result).to.eql(false);
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
(0, _chai.expect)(result).to.have.property('headers');
|
|
180
|
+
(0, _chai.expect)(result).to.have.property('records');
|
|
181
|
+
(0, _chai.expect)(result).to.have.property('messages');
|
|
182
|
+
(0, _chai.expect)(result.records.length).to.eql(1);
|
|
183
|
+
(0, _chai.expect)(result.messages.length).to.eql(1);
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
if (checkQueueStyle === 'oneNotRecord') {
|
|
187
|
+
const result = await amqpOperator.checkQueue({
|
|
188
|
+
queue,
|
|
189
|
+
style: 'one',
|
|
190
|
+
toRecord: false,
|
|
191
|
+
purge: false
|
|
192
|
+
});
|
|
193
|
+
const {
|
|
194
|
+
fields
|
|
195
|
+
} = result;
|
|
196
|
+
if (expectFalseCheckResult) {
|
|
197
|
+
(0, _chai.expect)(result).to.eql(false);
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
(0, _chai.expect)(fields).to.have.property('deliveryTag');
|
|
201
|
+
(0, _chai.expect)(fields).to.have.property('exchange');
|
|
202
|
+
(0, _chai.expect)(fields).to.have.property('messageCount');
|
|
203
|
+
(0, _chai.expect)(fields).to.have.property('redelivered');
|
|
204
|
+
(0, _chai.expect)(fields).to.have.property('routingKey');
|
|
205
|
+
(0, _chai.expect)(typeof fields.deliveryTag).to.be.eql('number');
|
|
206
|
+
(0, _chai.expect)(typeof fields.messageCount).to.be.eql('number');
|
|
207
|
+
(0, _chai.expect)(typeof fields.redelivered).to.be.eql('boolean');
|
|
208
|
+
(0, _chai.expect)(typeof fields.routingKey).to.be.eql('string');
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
if (checkQueueStyle === 'basicToRecord') {
|
|
212
|
+
const result = await amqpOperator.checkQueue({
|
|
213
|
+
queue,
|
|
214
|
+
style: 'basic',
|
|
215
|
+
toRecord: true,
|
|
216
|
+
purge: false
|
|
217
|
+
});
|
|
218
|
+
if (expectFalseCheckResult) {
|
|
219
|
+
(0, _chai.expect)(result).to.eql(false);
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
(0, _chai.expect)(result).to.have.property('headers');
|
|
223
|
+
(0, _chai.expect)(result).to.have.property('records');
|
|
224
|
+
(0, _chai.expect)(result).to.have.property('messages');
|
|
225
|
+
(0, _chai.expect)(result.records.length).to.eql(3);
|
|
226
|
+
(0, _chai.expect)(result.messages.length).to.eql(3);
|
|
227
|
+
const expectedResult = getFixture('expectedResult.json');
|
|
228
|
+
(0, _chai.expect)(result.records).to.eql(expectedResult);
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
if (checkQueueStyle === 'basicNotRecord') {
|
|
232
|
+
const result = await amqpOperator.checkQueue({
|
|
233
|
+
queue,
|
|
234
|
+
style: 'basic',
|
|
235
|
+
toRecord: false,
|
|
236
|
+
purge: false
|
|
237
|
+
});
|
|
238
|
+
if (expectFalseCheckResult) {
|
|
239
|
+
(0, _chai.expect)(result).to.eql(false);
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
(0, _chai.expect)(result).to.have.property('headers');
|
|
243
|
+
(0, _chai.expect)(result).to.have.property('messages');
|
|
244
|
+
(0, _chai.expect)(result.messages.length).to.eql(3);
|
|
245
|
+
const [{
|
|
246
|
+
fields
|
|
247
|
+
}] = result.messages;
|
|
248
|
+
(0, _chai.expect)(fields).to.have.property('deliveryTag');
|
|
249
|
+
(0, _chai.expect)(fields).to.have.property('exchange');
|
|
250
|
+
(0, _chai.expect)(fields).to.have.property('messageCount');
|
|
251
|
+
(0, _chai.expect)(fields).to.have.property('redelivered');
|
|
252
|
+
(0, _chai.expect)(fields).to.have.property('routingKey');
|
|
253
|
+
(0, _chai.expect)(typeof fields.deliveryTag).to.be.eql('number');
|
|
254
|
+
(0, _chai.expect)(typeof fields.messageCount).to.be.eql('number');
|
|
255
|
+
(0, _chai.expect)(typeof fields.redelivered).to.be.eql('boolean');
|
|
256
|
+
(0, _chai.expect)(typeof fields.routingKey).to.be.eql('string');
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
if (checkQueueStyle === 'purge') {
|
|
260
|
+
return amqpOperator.checkQueue({
|
|
261
|
+
queue,
|
|
262
|
+
style: 'messages',
|
|
263
|
+
purge: true
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
if (checkQueueStyle === 'foobar') {
|
|
267
|
+
return amqpOperator.checkQueue({
|
|
268
|
+
queue,
|
|
269
|
+
style: 'foobar',
|
|
270
|
+
toRecord: false,
|
|
271
|
+
purge: false
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
return false;
|
|
275
|
+
}
|
|
276
|
+
async function ackOrNackMessages() {
|
|
277
|
+
if (ackMessages) {
|
|
278
|
+
const message = await amqpOperator.consumeOne(testData.queue, false);
|
|
279
|
+
await amqpOperator.ackMessages([message]);
|
|
280
|
+
return setTimeoutPromise(10);
|
|
281
|
+
}
|
|
282
|
+
if (nackMessages) {
|
|
283
|
+
const message = await amqpOperator.consumeOne(testData.queue, false);
|
|
284
|
+
await amqpOperator.nackMessages([message]);
|
|
285
|
+
return setTimeoutPromise(10);
|
|
286
|
+
}
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
async function sendMessagesToQueue() {
|
|
290
|
+
if (sentToQueue) {
|
|
291
|
+
const messages = getFixture('input.json');
|
|
292
|
+
// {queue, correlationId, headers, data}
|
|
293
|
+
|
|
294
|
+
const promises = messages.map(message => amqpOperator.sendToQueue(message));
|
|
295
|
+
await Promise.all(promises);
|
|
296
|
+
return setTimeoutPromise(10);
|
|
297
|
+
}
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/*
|
|
303
|
+
function testHeathCheck() {
|
|
304
|
+
return it('expects healthCheck', async () => {
|
|
305
|
+
|
|
306
|
+
const amqpOperator2 = await amqpFactory(amqpUrl, true);
|
|
307
|
+
try {
|
|
308
|
+
|
|
309
|
+
debug(`**********`);
|
|
310
|
+
await testHealthCheckLoopWorking(amqpOperator2);
|
|
311
|
+
|
|
312
|
+
debug(`**********`);
|
|
313
|
+
await testHealthCheckLoopErroring(amqpOperator2);
|
|
314
|
+
} catch (error) {
|
|
315
|
+
debug(error);
|
|
316
|
+
expect(error).to.eql('');
|
|
317
|
+
} finally {
|
|
318
|
+
amqpOperator2.closeConnection();
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
async function testHealthCheckLoopWorking(amqpOperator) {
|
|
322
|
+
debug(`Testing healthCheckLoop for ${amqpOperator}`);
|
|
323
|
+
debug(`Waiting 0.5s and expecting healthCheckLoop to work`);
|
|
324
|
+
await setTimeoutPromise('500');
|
|
325
|
+
debug(`Amqp Operator should have been alive.`);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
async function testHealthCheckLoopErroring(amqpOperator) {
|
|
329
|
+
debug(`Testing healthCheckLoop with closed channel`);
|
|
330
|
+
amqpOperator.closeChannel();
|
|
331
|
+
debug(`Waiting 0.5s and expecting healthCheckLoop to throw error`);
|
|
332
|
+
await setTimeoutPromise('500');
|
|
333
|
+
debug(`amqpOperator should have errored`);
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
*/
|
|
338
|
+
//# sourceMappingURL=amqp.tests.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"amqp.tests.spec.js","names":["setTimeoutPromise","promisify","setTimeout","debug","createDebugLogger","testData","queue","correlationId","data","amqpUrl","amqpOperator","generateTests","callback","path","__dirname","recurse","useMetadataFile","fixura","failWhenNotFound","reader","READERS","JSON","mocha","before","amqpFactory","beforeEach","checkQueue","toRecord","purge","afterEach","removeQueue","after","closeConnection","getFixture","expectToFail","expectedErrorStatus","ackMessages","nackMessages","checkNextMessage","checkQueueStyle","sentToQueue","expectedMessageCount","expectedErrorMessage","undefined","expectApiError","expectFalseCheckResult","sendMessagesToQueue","ackOrNackMessages","queueRemoval","messageCount","style","expect","to","eql","headers","records","queueCheckNextMessage","nextMessage","expectedNextMessage","error","equal","testErrors","be","instanceOf","ApiError","status","payload","not","constructor","name","consumeOne","result","have","property","length","messages","fields","deliveryTag","redelivered","routingKey","expectedResult","message","promises","map","sendToQueue","Promise","all"],"sources":["../src/amqp.tests.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) 2022 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-rest-api-commons\n*\n* melinda-rest-api-commons program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Affero General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-rest-api-commons is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Affero General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\nimport {expect} from 'chai';\nimport {READERS} from '@natlibfi/fixura';\nimport createDebugLogger from 'debug';\nimport generateTests from '@natlibfi/fixugen';\nimport {amqpFactory} from './index';\nimport {Error as ApiError} from '@natlibfi/melinda-commons';\nimport {promisify} from 'util';\n\nconst setTimeoutPromise = promisify(setTimeout);\nconst debug = createDebugLogger('@natlibfi/melinda-rest-api-commons:amqp:test');\n//const debugData = debug.extend('data');\n\nconst testData = {\n queue: 'TESTQUEUE',\n correlationId: 'aaaaaaaa-0000-aaaa-0000-000000000000',\n data: {'leader': '02518cam a2200745zi 4500', 'fields': [{'tag': '001', 'value': '000019640'}]}\n};\n\ndebug(`Testing amqp against a local AMQP instance - we'll need some kind of mockup for this`);\nconst amqpUrl = 'amqp://127.0.0.1:5672/';\n// eslint-disable-next-line functional/no-let\nlet amqpOperator;\n\ngenerateTests({\n callback,\n path: [__dirname, '..', 'test-fixtures', 'amqp'],\n recurse: false,\n useMetadataFile: true,\n fixura: {\n failWhenNotFound: true,\n reader: READERS.JSON\n },\n mocha: {\n before: async () => {\n debug(`Connecting to ${amqpUrl}, with healthCheck running`);\n amqpOperator = await amqpFactory(amqpUrl, true);\n },\n beforeEach: async () => {\n await amqpOperator.checkQueue({queue: testData.queue, toRecord: false, purge: true});\n },\n afterEach: async () => {\n await amqpOperator.removeQueue(testData.queue);\n },\n after: async () => {\n await amqpOperator.closeConnection();\n //await testHeathCheck();\n }\n }\n});\n\n// eslint-disable-next-line max-statements\nasync function callback({\n getFixture,\n expectToFail = false,\n expectedErrorStatus = '',\n ackMessages = false,\n nackMessages = false,\n checkNextMessage = false,\n checkQueueStyle = false,\n queue = testData.queue,\n sentToQueue,\n expectedMessageCount,\n removeQueue = false,\n expectedErrorMessage = undefined,\n expectApiError = false,\n expectFalseCheckResult = false\n}) {\n try {\n await sendMessagesToQueue();\n\n await ackOrNackMessages();\n\n await checkQueue();\n\n await queueRemoval();\n\n const messageCount = await amqpOperator.checkQueue({queue, style: 'messages'});\n debug(`MessageCount: ${messageCount}`);\n expect(messageCount).to.eql(expectedMessageCount);\n\n if (checkNextMessage) { // eslint-disable-line\n const {headers, records} = await queueCheckNextMessage();\n const nextMessage = {headers, records};\n const expectedNextMessage = getFixture('expectedMessage.json');\n expect(nextMessage).to.eql(expectedNextMessage);\n }\n\n } catch (error) {\n if (!expectToFail) {\n throw error;\n }\n expect(expectToFail, 'This is expected to fail').to.equal(true);\n testErrors(error);\n }\n\n function testErrors(error) {\n\n if (expectApiError) {\n expect(error).to.be.instanceOf(ApiError);\n debug(`We expected and got an ApiError`);\n expect(error.status).to.equal(expectedErrorStatus);\n\n if (expectedErrorMessage) {\n expect(error.payload).to.eql(expectedErrorMessage);\n return;\n }\n\n return;\n }\n expect(error).not.to.be.instanceOf(ApiError);\n debug(`We expected and got an non-ApiError`);\n debug(`Error is a ${error.constructor.name}`);\n }\n\n function queueRemoval() {\n if (removeQueue) {\n return amqpOperator.removeQueue(removeQueue);\n }\n\n return;\n }\n\n function queueCheckNextMessage() {\n if (checkNextMessage) {\n return amqpOperator.consumeOne(testData.queue, true);\n }\n\n return false;\n }\n\n // eslint-disable-next-line max-statements\n async function checkQueue() {\n debug(`checkQueueStyle: ${checkQueueStyle}`);\n\n if (checkQueueStyle === 'oneToRecord') {\n const result = await amqpOperator.checkQueue({queue, style: 'one', toRecord: true, purge: false});\n\n if (expectFalseCheckResult) {\n expect(result).to.eql(false);\n return;\n }\n\n expect(result).to.have.property('headers');\n expect(result).to.have.property('records');\n expect(result).to.have.property('messages');\n expect(result.records.length).to.eql(1);\n expect(result.messages.length).to.eql(1);\n\n return;\n }\n\n if (checkQueueStyle === 'oneNotRecord') {\n const result = await amqpOperator.checkQueue({queue, style: 'one', toRecord: false, purge: false});\n const {fields} = result;\n\n if (expectFalseCheckResult) {\n expect(result).to.eql(false);\n return;\n }\n\n expect(fields).to.have.property('deliveryTag');\n expect(fields).to.have.property('exchange');\n expect(fields).to.have.property('messageCount');\n expect(fields).to.have.property('redelivered');\n expect(fields).to.have.property('routingKey');\n expect(typeof fields.deliveryTag).to.be.eql('number');\n expect(typeof fields.messageCount).to.be.eql('number');\n expect(typeof fields.redelivered).to.be.eql('boolean');\n expect(typeof fields.routingKey).to.be.eql('string');\n\n return;\n }\n\n if (checkQueueStyle === 'basicToRecord') {\n const result = await amqpOperator.checkQueue({queue, style: 'basic', toRecord: true, purge: false});\n\n if (expectFalseCheckResult) {\n expect(result).to.eql(false);\n return;\n }\n\n expect(result).to.have.property('headers');\n expect(result).to.have.property('records');\n expect(result).to.have.property('messages');\n expect(result.records.length).to.eql(3);\n expect(result.messages.length).to.eql(3);\n const expectedResult = getFixture('expectedResult.json');\n expect(result.records).to.eql(expectedResult);\n\n return;\n }\n\n if (checkQueueStyle === 'basicNotRecord') {\n const result = await amqpOperator.checkQueue({queue, style: 'basic', toRecord: false, purge: false});\n\n if (expectFalseCheckResult) {\n expect(result).to.eql(false);\n return;\n }\n\n expect(result).to.have.property('headers');\n expect(result).to.have.property('messages');\n expect(result.messages.length).to.eql(3);\n\n const [{fields}] = result.messages;\n\n expect(fields).to.have.property('deliveryTag');\n expect(fields).to.have.property('exchange');\n expect(fields).to.have.property('messageCount');\n expect(fields).to.have.property('redelivered');\n expect(fields).to.have.property('routingKey');\n\n expect(typeof fields.deliveryTag).to.be.eql('number');\n expect(typeof fields.messageCount).to.be.eql('number');\n expect(typeof fields.redelivered).to.be.eql('boolean');\n expect(typeof fields.routingKey).to.be.eql('string');\n\n return;\n }\n\n if (checkQueueStyle === 'purge') {\n return amqpOperator.checkQueue({queue, style: 'messages', purge: true});\n }\n\n if (checkQueueStyle === 'foobar') {\n return amqpOperator.checkQueue({queue, style: 'foobar', toRecord: false, purge: false});\n }\n\n return false;\n }\n\n async function ackOrNackMessages() {\n if (ackMessages) {\n const message = await amqpOperator.consumeOne(testData.queue, false);\n await amqpOperator.ackMessages([message]);\n\n return setTimeoutPromise(10);\n }\n\n if (nackMessages) {\n const message = await amqpOperator.consumeOne(testData.queue, false);\n await amqpOperator.nackMessages([message]);\n\n return setTimeoutPromise(10);\n }\n\n return;\n }\n\n async function sendMessagesToQueue() {\n if (sentToQueue) {\n const messages = getFixture('input.json');\n // {queue, correlationId, headers, data}\n\n const promises = messages.map(message => amqpOperator.sendToQueue(message));\n await Promise.all(promises);\n\n return setTimeoutPromise(10);\n }\n\n return;\n }\n}\n\n/*\nfunction testHeathCheck() {\n return it('expects healthCheck', async () => {\n\n const amqpOperator2 = await amqpFactory(amqpUrl, true);\n try {\n\n debug(`**********`);\n await testHealthCheckLoopWorking(amqpOperator2);\n\n debug(`**********`);\n await testHealthCheckLoopErroring(amqpOperator2);\n } catch (error) {\n debug(error);\n expect(error).to.eql('');\n } finally {\n amqpOperator2.closeConnection();\n }\n\n async function testHealthCheckLoopWorking(amqpOperator) {\n debug(`Testing healthCheckLoop for ${amqpOperator}`);\n debug(`Waiting 0.5s and expecting healthCheckLoop to work`);\n await setTimeoutPromise('500');\n debug(`Amqp Operator should have been alive.`);\n }\n\n async function testHealthCheckLoopErroring(amqpOperator) {\n debug(`Testing healthCheckLoop with closed channel`);\n amqpOperator.closeChannel();\n debug(`Waiting 0.5s and expecting healthCheckLoop to throw error`);\n await setTime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,OAAOlF,iBAAiB,CAAC,EAAE,CAAC;IAC9B;IAEA;EACF;AACF;;AAEA;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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA"}
|
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,QAAQ,EAAE;QAC1C,OAAOC,sCAAe,CAACL,EAAE,CAACL,MAAM,CAAC;MACnC;MAEA,MAAM,IAAIW,qBAAe,CAACC,mBAAU,CAACC,sBAAsB,CAAC;IAC9D,CAAC,CAAC,OAAOC,GAAG,EAAE;MACZ,IAAAC,eAAQ,EAACD,GAAG,CAAC;MACb,IAAIA,GAAG,YAAYH,qBAAe,EAAE;QA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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
|