@natlibfi/melinda-rest-api-commons 2.3.2-alpha.6 → 2.3.2-alpha.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/amqp.js +118 -87
- package/dist/amqp.js.map +1 -1
- package/dist/amqp.spec.js +252 -0
- package/dist/amqp.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 +6 -4
- package/dist/helpers/fix-constants.js.map +1 -1
- package/dist/helpers/fix-handle-tempurns.js +19 -27
- package/dist/helpers/fix-handle-tempurns.js.map +1 -1
- package/dist/helpers/fix-strip-f884s.js +12 -16
- package/dist/helpers/fix-strip-f884s.js.map +1 -1
- package/dist/helpers/fix-utils.js +9 -15
- package/dist/helpers/fix-utils.js.map +1 -1
- package/dist/helpers/fix.js +17 -32
- package/dist/helpers/fix.js.map +1 -1
- package/dist/helpers/fix.spec.js +1 -12
- package/dist/helpers/fix.spec.js.map +1 -1
- package/dist/helpers/validation.js +0 -6
- package/dist/helpers/validation.js.map +1 -1
- package/dist/helpers/validation.spec.js +1 -7
- package/dist/helpers/validation.spec.js.map +1 -1
- package/dist/index.js +8 -14
- package/dist/index.js.map +1 -1
- package/dist/mongo.js +38 -87
- package/dist/mongo.js.map +1 -1
- package/dist/mongoLog.js +5 -29
- package/dist/mongoLog.js.map +1 -1
- package/dist/utils.js +33 -35
- package/dist/utils.js.map +1 -1
- package/package.json +5 -4
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _chai = require("chai");
|
|
4
|
+
var _fixura = require("@natlibfi/fixura");
|
|
5
|
+
var _fixugen = _interopRequireDefault(require("@natlibfi/fixugen"));
|
|
6
|
+
var _debug = _interopRequireDefault(require("debug"));
|
|
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
|
+
//import inspect from 'util';
|
|
40
|
+
|
|
41
|
+
const debug = (0, _debug.default)('@natlibfi/melinda-rest-api-commons:amqp:test');
|
|
42
|
+
//const debugData = debug.extend('data');
|
|
43
|
+
|
|
44
|
+
const setTimeoutPromise = (0, _util.promisify)(setTimeout);
|
|
45
|
+
(0, _fixugen.default)({
|
|
46
|
+
callback,
|
|
47
|
+
path: [__dirname, '..', 'test-fixtures', 'amqp'],
|
|
48
|
+
recurse: false,
|
|
49
|
+
useMetadataFile: true,
|
|
50
|
+
fixura: {
|
|
51
|
+
failWhenNotFound: false,
|
|
52
|
+
reader: _fixura.READERS.JSON
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
// eslint-disable-next-line max-statements
|
|
57
|
+
async function callback() {
|
|
58
|
+
const testData = {
|
|
59
|
+
queue: 'TESTQUEUE',
|
|
60
|
+
correlationId: '5b7be681-0d4d-47ca-b5d7-1531173ec6bf',
|
|
61
|
+
data: {
|
|
62
|
+
'leader': '02518cam a2200745zi 4500',
|
|
63
|
+
'fields': [{
|
|
64
|
+
'tag': '001',
|
|
65
|
+
'value': '000019640'
|
|
66
|
+
}]
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
debug(`Testing amqp against a local AMQP instance - we'll need some kind of mockup for this`);
|
|
70
|
+
const amqpUrl = 'amqp://127.0.0.1:5672/';
|
|
71
|
+
debug(`Connecting to ${amqpUrl}, with healthCheck running`);
|
|
72
|
+
const amqpOperator = await (0, _index.amqpFactory)(amqpUrl, true);
|
|
73
|
+
debug(`**********`);
|
|
74
|
+
await testHealthCheckLoopWorking(amqpOperator);
|
|
75
|
+
debug(`**********`);
|
|
76
|
+
await testHealthCheckLoopErroring(amqpOperator);
|
|
77
|
+
await amqpOperator.closeConnection();
|
|
78
|
+
debug(`--- Create a new amqpOperator2 ----`);
|
|
79
|
+
debug(`Connecting to ${amqpUrl}, without healthCheck running`);
|
|
80
|
+
const amqpOperator2 = await (0, _index.amqpFactory)(amqpUrl);
|
|
81
|
+
debug(`**********`);
|
|
82
|
+
debug(`*** Test purging the queue: ${testData.queue} *******`);
|
|
83
|
+
const purgeMessage = await amqpOperator2.checkQueue({
|
|
84
|
+
queue: testData.queue,
|
|
85
|
+
toRecord: false,
|
|
86
|
+
purge: true
|
|
87
|
+
});
|
|
88
|
+
(0, _chai.expect)(purgeMessage).to.eql(false);
|
|
89
|
+
await testSendToQueue(amqpOperator2, testData);
|
|
90
|
+
debug(`* wait, otherwise queue is not ready *`);
|
|
91
|
+
await setTimeoutPromise('100');
|
|
92
|
+
debug(`*** Test getting messageCount from theQueue: ${testData.queue} *******`);
|
|
93
|
+
const messageCount = await amqpOperator2.checkQueue({
|
|
94
|
+
queue: testData.queue,
|
|
95
|
+
style: 'messages'
|
|
96
|
+
});
|
|
97
|
+
debug(messageCount);
|
|
98
|
+
(0, _chai.expect)(messageCount).to.eql(1);
|
|
99
|
+
debug(`*** Test checking theQueue: ${testData.queue} *******`);
|
|
100
|
+
const message = await amqpOperator2.checkQueue({
|
|
101
|
+
queue: testData.queue,
|
|
102
|
+
style: 'one',
|
|
103
|
+
toRecord: false,
|
|
104
|
+
purge: false
|
|
105
|
+
});
|
|
106
|
+
(0, _chai.expect)(message).to.not.equal('goo');
|
|
107
|
+
debug(message);
|
|
108
|
+
debug(`*** Test nacking the message: ${testData.queue} *******`);
|
|
109
|
+
await amqpOperator2.nackMessages([message]);
|
|
110
|
+
debug(`* wait, otherwise queue is not ready *`);
|
|
111
|
+
await setTimeoutPromise('100');
|
|
112
|
+
const messageCountAfterNack = await amqpOperator2.checkQueue({
|
|
113
|
+
queue: testData.queue,
|
|
114
|
+
style: 'messages'
|
|
115
|
+
});
|
|
116
|
+
debug(`After nack: ${messageCountAfterNack}`);
|
|
117
|
+
(0, _chai.expect)(messageCountAfterNack).to.eql(1);
|
|
118
|
+
const message2 = await amqpOperator2.checkQueue({
|
|
119
|
+
queue: testData.queue,
|
|
120
|
+
style: 'one',
|
|
121
|
+
toRecord: false,
|
|
122
|
+
purge: false
|
|
123
|
+
});
|
|
124
|
+
debug(`*** Test acking the message: ${testData.queue} *******`);
|
|
125
|
+
await amqpOperator2.ackMessages([message2]);
|
|
126
|
+
debug(`* wait, otherwise queue is not ready *`);
|
|
127
|
+
await setTimeoutPromise('100');
|
|
128
|
+
const messageCountAfterAck = await amqpOperator2.checkQueue({
|
|
129
|
+
queue: testData.queue,
|
|
130
|
+
style: 'messages'
|
|
131
|
+
});
|
|
132
|
+
debug(`After ack: ${messageCountAfterAck}`);
|
|
133
|
+
(0, _chai.expect)(messageCountAfterAck).to.eql(0);
|
|
134
|
+
debug(`*** Test removing the the queue: ${testData.queue} *******`);
|
|
135
|
+
const removeResult = await amqpOperator2.removeQueue(testData.queue);
|
|
136
|
+
debug(removeResult);
|
|
137
|
+
debug(`**********`);
|
|
138
|
+
try {
|
|
139
|
+
await testUndefinedQueue(amqpOperator2, testData);
|
|
140
|
+
} catch (error) {
|
|
141
|
+
//expect(error()).to.be.an('apierror');
|
|
142
|
+
const errorAsString = JSON.stringify(error);
|
|
143
|
+
(0, _chai.expect)(error).to.be.an.instanceof(_melindaCommons.Error);
|
|
144
|
+
(0, _chai.expect)(errorAsString).to.eql(`{"status":500,"payload":"Undefined queue!"}`);
|
|
145
|
+
}
|
|
146
|
+
debug(`**********`);
|
|
147
|
+
debug(`--- Closing amqpOperator2 ----`);
|
|
148
|
+
await amqpOperator2.closeChannel();
|
|
149
|
+
await amqpOperator2.closeConnection();
|
|
150
|
+
debug(`**********`);
|
|
151
|
+
try {
|
|
152
|
+
await testSendToQueue(amqpOperator2, testData);
|
|
153
|
+
} catch (error) {
|
|
154
|
+
(0, _chai.expect)(error.message).to.eql(`Channel closed`);
|
|
155
|
+
debug(`We got an error: ${JSON.stringify(error)}`);
|
|
156
|
+
}
|
|
157
|
+
debug(`**********`);
|
|
158
|
+
debug(`Done`);
|
|
159
|
+
//}
|
|
160
|
+
|
|
161
|
+
async function testHealthCheckLoopWorking(amqpOperator) {
|
|
162
|
+
debug(`Testing healthCheckLoop for ${amqpOperator}`);
|
|
163
|
+
debug(`Waiting 0.5s and expecting healthCheckLoop to work`);
|
|
164
|
+
await setTimeoutPromise('500');
|
|
165
|
+
debug(`Amqp Operator should have been alive.`);
|
|
166
|
+
}
|
|
167
|
+
async function testHealthCheckLoopErroring(amqpOperator) {
|
|
168
|
+
debug(`Testing healthCheckLoop with closed channel`);
|
|
169
|
+
amqpOperator.closeChannel();
|
|
170
|
+
debug(`Waiting 0.5s and expecting healthCheckLoop to throw error`);
|
|
171
|
+
await setTimeoutPromise('500');
|
|
172
|
+
debug(`amqpOperator should have errored`);
|
|
173
|
+
}
|
|
174
|
+
async function testSendToQueue(amqpOperator, testData) {
|
|
175
|
+
// Test sendToQueue
|
|
176
|
+
debug(`*** Testing sendToQueue ***`);
|
|
177
|
+
const {
|
|
178
|
+
queue,
|
|
179
|
+
correlationId,
|
|
180
|
+
data
|
|
181
|
+
} = testData;
|
|
182
|
+
const headers = {
|
|
183
|
+
correlationId
|
|
184
|
+
};
|
|
185
|
+
await amqpOperator.sendToQueue({
|
|
186
|
+
queue,
|
|
187
|
+
correlationId,
|
|
188
|
+
headers,
|
|
189
|
+
data
|
|
190
|
+
});
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/*
|
|
195
|
+
async function testCheckQueue(amqpOperator, testData) {
|
|
196
|
+
debug(`Testing checkQueue`);
|
|
197
|
+
const {queue} = testData;
|
|
198
|
+
const message = await amqpOperator.checkQueue({queue, style: 'one', toRecord: false, purge: false});
|
|
199
|
+
debug(message);
|
|
200
|
+
return message;
|
|
201
|
+
//expect(message).to.be.defined;
|
|
202
|
+
}
|
|
203
|
+
*/
|
|
204
|
+
|
|
205
|
+
async function testUndefinedQueue(amqpOperator, testData) {
|
|
206
|
+
// Test sendToQueue
|
|
207
|
+
debug(`Testing sendToQueue with undefined queue`);
|
|
208
|
+
const {
|
|
209
|
+
correlationId,
|
|
210
|
+
data
|
|
211
|
+
} = testData;
|
|
212
|
+
const headers = {
|
|
213
|
+
correlationId
|
|
214
|
+
};
|
|
215
|
+
const queue = undefined;
|
|
216
|
+
(0, _chai.expect)(await amqpOperator.sendToQueue({
|
|
217
|
+
queue,
|
|
218
|
+
correlationId,
|
|
219
|
+
headers,
|
|
220
|
+
data
|
|
221
|
+
})).to.throw();
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/*
|
|
225
|
+
await amqpOperator.sendToQueue({queue, correlationId, headers, data});
|
|
226
|
+
await amqpOperator.ackMessages([message]);
|
|
227
|
+
const message2 = await amqpOperator.checkQueue({queue, style: 'one', toRecord: false, purge: false});
|
|
228
|
+
await amqpOperator.ackMessages([message2]);
|
|
229
|
+
expect(message2).to.be(true);
|
|
230
|
+
//debug(`FOO: ${JSON.stringify(message)}`);
|
|
231
|
+
// http:
|
|
232
|
+
// await amqpOperator.sendToQueue({queue: 'REQUESTS', correlationId, headers, data});
|
|
233
|
+
// validator:
|
|
234
|
+
// const message = await amqpOperator.checkQueue({queue: 'REQUESTS', style: 'one', toRecord: false, purge: false});
|
|
235
|
+
// await amqpOperator.ackMessages([message]);
|
|
236
|
+
// const message = await amqpOperator.checkQueue({queue: validatorQueue, style: 'one', toRecord: false, purge: false});
|
|
237
|
+
// amqpOperator.removeQueue(validatorQueue);
|
|
238
|
+
//await amqpOperator.checkQueue({queue: operationQueue, style: 'messages', purge: true});
|
|
239
|
+
// await amqpOperator.checkQueue({queue: `${headers.operation}.${correlationId}`, style: 'messages', purge: true});
|
|
240
|
+
// importer
|
|
241
|
+
/*
|
|
242
|
+
const {headers, records, messages} = await amqpOperator.checkQueue({queue: `${operation}.${correlationId}`, style: 'basic', toRecord: true, purge: purgeQueues});
|
|
243
|
+
await amqpOperator.nackMessages(messages);
|
|
244
|
+
await amqpOperator.sendToQueue({
|
|
245
|
+
const {messages} = await amqpOperator.checkQueue({queue, style: 'basic', toRecords: false, purge: false});
|
|
246
|
+
await amqpOperator.ackMessages(messages);
|
|
247
|
+
const processMessage = await amqpOperator.checkQueue({queue: processQueue, style: 'one', toRecord: false, purge: false});
|
|
248
|
+
const {headers: firstMessageHeaders, messages} = await amqpOperator.checkQueue({queue, style: 'basic', toRecord: false, purge: false});
|
|
249
|
+
const queueMessagesCount = await amqpOperator.checkQueue({queue, style: 'messages'});
|
|
250
|
+
*/
|
|
251
|
+
}
|
|
252
|
+
//# sourceMappingURL=amqp.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"amqp.spec.js","names":["debug","createDebugLogger","setTimeoutPromise","promisify","setTimeout","generateTests","callback","path","__dirname","recurse","useMetadataFile","fixura","failWhenNotFound","reader","READERS","JSON","testData","queue","correlationId","data","amqpUrl","amqpOperator","amqpFactory","testHealthCheckLoopWorking","testHealthCheckLoopErroring","closeConnection","amqpOperator2","purgeMessage","checkQueue","toRecord","purge","expect","to","eql","testSendToQueue","messageCount","style","message","not","equal","nackMessages","messageCountAfterNack","message2","ackMessages","messageCountAfterAck","removeResult","removeQueue","testUndefinedQueue","error","errorAsString","stringify","be","an","instanceof","ApiError","closeChannel","headers","sendToQueue","undefined","throw"],"sources":["../src/amqp.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 generateTests from '@natlibfi/fixugen';\nimport createDebugLogger from 'debug';\nimport {amqpFactory} from './index';\nimport {Error as ApiError} from '@natlibfi/melinda-commons';\n//import inspect from 'util';\nimport {promisify} from 'util';\n\nconst debug = createDebugLogger('@natlibfi/melinda-rest-api-commons:amqp:test');\n//const debugData = debug.extend('data');\n\nconst setTimeoutPromise = promisify(setTimeout);\n\ngenerateTests({\n callback,\n path: [__dirname, '..', 'test-fixtures', 'amqp'],\n recurse: false,\n useMetadataFile: true,\n fixura: {\n failWhenNotFound: false,\n reader: READERS.JSON\n }\n});\n\n// eslint-disable-next-line max-statements\nasync function callback() {\n\n const testData = {\n queue: 'TESTQUEUE',\n correlationId: '5b7be681-0d4d-47ca-b5d7-1531173ec6bf',\n data: {'leader': '02518cam a2200745zi 4500', 'fields': [{'tag': '001', 'value': '000019640'}]}\n };\n\n debug(`Testing amqp against a local AMQP instance - we'll need some kind of mockup for this`);\n const amqpUrl = 'amqp://127.0.0.1:5672/';\n\n debug(`Connecting to ${amqpUrl}, with healthCheck running`);\n const amqpOperator = await amqpFactory(amqpUrl, true);\n\n debug(`**********`);\n await testHealthCheckLoopWorking(amqpOperator);\n\n debug(`**********`);\n await testHealthCheckLoopErroring(amqpOperator);\n\n await amqpOperator.closeConnection();\n\n debug(`--- Create a new amqpOperator2 ----`);\n debug(`Connecting to ${amqpUrl}, without healthCheck running`);\n const amqpOperator2 = await amqpFactory(amqpUrl);\n\n debug(`**********`);\n debug(`*** Test purging the queue: ${testData.queue} *******`);\n const purgeMessage = await amqpOperator2.checkQueue({queue: testData.queue, toRecord: false, purge: true});\n expect(purgeMessage).to.eql(false);\n await testSendToQueue(amqpOperator2, testData);\n debug(`* wait, otherwise queue is not ready *`);\n await setTimeoutPromise('100');\n\n debug(`*** Test getting messageCount from theQueue: ${testData.queue} *******`);\n const messageCount = await amqpOperator2.checkQueue({queue: testData.queue, style: 'messages'});\n debug(messageCount);\n expect(messageCount).to.eql(1);\n\n debug(`*** Test checking theQueue: ${testData.queue} *******`);\n const message = await amqpOperator2.checkQueue({queue: testData.queue, style: 'one', toRecord: false, purge: false});\n expect(message).to.not.equal('goo');\n debug(message);\n\n debug(`*** Test nacking the message: ${testData.queue} *******`);\n await amqpOperator2.nackMessages([message]);\n debug(`* wait, otherwise queue is not ready *`);\n await setTimeoutPromise('100');\n\n const messageCountAfterNack = await amqpOperator2.checkQueue({queue: testData.queue, style: 'messages'});\n debug(`After nack: ${messageCountAfterNack}`);\n expect(messageCountAfterNack).to.eql(1);\n\n const message2 = await amqpOperator2.checkQueue({queue: testData.queue, style: 'one', toRecord: false, purge: false});\n\n debug(`*** Test acking the message: ${testData.queue} *******`);\n await amqpOperator2.ackMessages([message2]);\n debug(`* wait, otherwise queue is not ready *`);\n await setTimeoutPromise('100');\n\n const messageCountAfterAck = await amqpOperator2.checkQueue({queue: testData.queue, style: 'messages'});\n debug(`After ack: ${messageCountAfterAck}`);\n expect(messageCountAfterAck).to.eql(0);\n\n debug(`*** Test removing the the queue: ${testData.queue} *******`);\n const removeResult = await amqpOperator2.removeQueue(testData.queue);\n debug(removeResult);\n\n\n debug(`**********`);\n try {\n await testUndefinedQueue(amqpOperator2, testData);\n } catch (error) {\n //expect(error()).to.be.an('apierror');\n const errorAsString = JSON.stringify(error);\n expect(error).to.be.an.instanceof(ApiError);\n expect(errorAsString).to.eql(`{\"status\":500,\"payload\":\"Undefined queue!\"}`);\n }\n debug(`**********`);\n\n debug(`--- Closing amqpOperator2 ----`);\n await amqpOperator2.closeChannel();\n await amqpOperator2.closeConnection();\n\n debug(`**********`);\n\n try {\n await testSendToQueue(amqpOperator2, testData);\n } catch (error) {\n expect(error.message).to.eql(`Channel closed`);\n debug(`We got an error: ${JSON.stringify(error)}`);\n }\n debug(`**********`);\n\n debug(`Done`);\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 setTimeoutPromise('500');\n debug(`amqpOperator should have errored`);\n }\n\n async function testSendToQueue(amqpOperator, testData) {\n // Test sendToQueue\n debug(`*** Testing sendToQueue ***`);\n\n const {queue, correlationId, data} = testData;\n const headers = {correlationId};\n\n await amqpOperator.sendToQueue({queue, correlationId, headers, data});\n return;\n }\n\n /*\n async function testCheckQueue(amqpOperator, testData) {\n debug(`Testing checkQueue`);\n const {queue} = testData;\n const message = await amqpOperator.checkQueue({queue, style: 'one', toRecord: false, purge: false});\n debug(message);\n return message;\n //expect(message).to.be.defined;\n }\n*/\n\n async function testUndefinedQueue(amqpOperator, testData) {\n // Test sendToQueue\n debug(`Testing sendToQueue with undefined queue`);\n const {correlationId, data} = testData;\n const headers = {correlationId};\n const queue = undefined;\n\n expect(await amqpOperator.sendToQueue({queue, correlationId, headers, data})).to.throw();\n }\n\n\n /*\n\n\n await amqpOperator.sendToQueue({queue, correlationId, headers, data});\n\n\n await amqpOperator.ackMessages([message]);\n const message2 = await amqpOperator.checkQueue({queue, style: 'one', toRecord: false, purge: false});\n await amqpOperator.ackMessages([message2]);\n\n expect(message2).to.be(true);\n\n\n //debug(`FOO: ${JSON.stringify(message)}`);\n\n\n // http:\n // await amqpOperator.sendToQueue({queue: 'REQUESTS', correlationId, headers, data});\n\n // validator:\n // const message = await amqpOperator.checkQueue({queue: 'REQUESTS', style: 'one', toRecord: false, purge: false});\n // await amqpOperator.ackMessages([message]);\n // const message = await amqpOperator.checkQueue({queue: validatorQueue, style: 'one', toRecord: false, purge: false});\n // amqpOperator.removeQueue(validatorQueue);\n //await amqpOperator.checkQueue({queue: operationQueue, style: 'messages', purge: true});\n // await amqpOperator.checkQueue({queue: `${headers.operation}.${correlationId}`, style: 'messages', purge: true});\n\n // importer\n /*\nconst {headers, records, messages} = await amqpOperator.checkQueue({queue: `${operation}.${correlationId}`, style: 'basic', toRecord: true, purge: purgeQueues});\n await amqpOperator.nackMessages(messages);\n await amqpOperator.sendToQueue({\n const {messages} = await amqpOperator.checkQueue({queue, style: 'basic', toRecords: false, purge: false});\n await amqpOperator.ackMessages(messages);\n const processMessage = await amqpOperator.checkQueue({queue: processQueue, style: 'one', toRecord: false, purge: false});\n const {headers: firstMessageHeaders, messages} = await amqpOperator.checkQueue({queue, style: 'basic', toRecord: false, purge: false});\n const queueMessagesCount = await amqpOperator.checkQueue({queue, style: 'messages'});\n\n\n */\n\n}\n\n"],"mappings":";;AA4BA;AACA;AACA;AACA;AACA;AACA;AAEA;AAA+B;AAnC/B;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;;AAQA;;AAGA,MAAMA,KAAK,GAAG,IAAAC,cAAiB,EAAC,8CAA8C,CAAC;AAC/E;;AAEA,MAAMC,iBAAiB,GAAG,IAAAC,eAAS,EAACC,UAAU,CAAC;AAE/C,IAAAC,gBAAa,EAAC;EACZC,QAAQ;EACRC,IAAI,EAAE,CAACC,SAAS,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,CAAC;EAChDC,OAAO,EAAE,KAAK;EACdC,eAAe,EAAE,IAAI;EACrBC,MAAM,EAAE;IACNC,gBAAgB,EAAE,KAAK;IACvBC,MAAM,EAAEC,eAAO,CAACC;EAClB;AACF,CAAC,CAAC;;AAEF;AACA,eAAeT,QAAQ,GAAG;EAExB,MAAMU,QAAQ,GAAG;IACfC,KAAK,EAAE,WAAW;IAClBC,aAAa,EAAE,sCAAsC;IACrDC,IAAI,EAAE;MAAC,QAAQ,EAAE,0BAA0B;MAAE,QAAQ,EAAE,CAAC;QAAC,KAAK,EAAE,KAAK;QAAE,OAAO,EAAE;MAAW,CAAC;IAAC;EAC/F,CAAC;EAEDnB,KAAK,CAAE,sFAAqF,CAAC;EAC7F,MAAMoB,OAAO,GAAG,wBAAwB;EAExCpB,KAAK,CAAE,iBAAgBoB,OAAQ,4BAA2B,CAAC;EAC3D,MAAMC,YAAY,GAAG,MAAM,IA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C,aAAa;MAAEsC,OAAO;MAAErC;IAAI,CAAC,CAAC,CAAC,CAACa,EAAE,CAAC2B,KAAK,EAAE;EAC1F;;EAGA;AACF;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"}
|
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;QAAE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AC;MACtD;MAEA,MAAM,IAAIP,qBAAe,CAACC,mBAAU,CAACC,sBAAsB,CAAC;IAC9D,CAAC,CAAC,OAAOC,GAAG,EAAE;MACZ,IAAAC,eAAQ,EAACD,GAAG,CAAC;MACb,IAAIA,GAAG,YAAYH,qBAAe,EAAE;QAAE;QACpC,MAAMG,GAAG;MACX;MACA,MAAM,IAAIH,qBAAe,CAACC,mBAAU,CAACI,WAAW,EAAE,kCAAkC,CAAC;IACvF;EACF;AACF"}
|
|
@@ -1,19 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _chai = require("chai");
|
|
4
|
-
|
|
5
4
|
var _fixura = _interopRequireDefault(require("@natlibfi/fixura"));
|
|
6
|
-
|
|
7
5
|
var _marcRecord = require("@natlibfi/marc-record");
|
|
8
|
-
|
|
9
6
|
var _melindaCommons = require("@natlibfi/melinda-commons");
|
|
10
|
-
|
|
11
7
|
var _conversion = _interopRequireDefault(require("./conversion"));
|
|
12
|
-
|
|
13
8
|
var _constants = require("../constants");
|
|
14
|
-
|
|
15
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
|
-
|
|
17
10
|
/**
|
|
18
11
|
*
|
|
19
12
|
* @licstart The following is the entire license notice for the JavaScript code in this file.
|
|
@@ -41,6 +34,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
41
34
|
* for the JavaScript code in this file.
|
|
42
35
|
*
|
|
43
36
|
*/
|
|
37
|
+
|
|
44
38
|
describe('services/conversion', () => {
|
|
45
39
|
const {
|
|
46
40
|
getFixture
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conversion.spec.js","names":["describe","getFixture","fixtureFactory","root","__dirname","conversionService","createConversionService","marcRecord","MarcRecord","JSON","parse","components","subfieldValues","marcXml","iso2709","json","alephSeq","it","service","expect","to","be","an","and","respondTo","serialize","throw","data","CONVERSION_FORMATS","MARCXML","equal","ISO2709","ALEPHSEQ","unserialize","record","equalsTo","ConversionError"],"sources":["../../src/helpers/conversion.spec.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Shared modules for microservices of Melinda rest api batch import system\n*\n* Copyright (C) 2020-2021 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-rest-api-commons\n*\n* melinda-rest-api-commons program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Affero General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-rest-api-commons is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Affero General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\nimport {expect} from 'chai';\nimport fixtureFactory from '@natlibfi/fixura';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport {Error as ConversionError} from '@natlibfi/melinda-commons';\nimport createConversionService from './conversion';\nimport {CONVERSION_FORMATS} from '../constants';\n\ndescribe('services/conversion', () => {\n const {getFixture} = fixtureFactory({root: [\n __dirname,\n '..',\n '..',\n 'test-fixtures',\n 'conversion'\n ]});\n const conversionService = createConversionService();\n\n const marcRecord = new MarcRecord(JSON.parse(getFixture({components: ['json1']})), {subfieldValues: false});\n const marcXml = getFixture({components: ['marcxml1']});\n const iso2709 = getFixture({components: ['iso2709_1']});\n const json = getFixture({components: ['json1']});\n const alephSeq = getFixture({components: ['aleph_sequential']});\n\n\n describe('factory', () => {\n it('Should create the expected object', () => {\n const service = createConversionService();\n expect(service).to.be.an('object').and\n .respondTo('serialize')\n .respondTo('unserialize');\n });\n });\n\n describe('#serialize', () => {\n it('Should throw because of unsupported format', () => {\n expect(conversionService.serialize).to.throw();\n });\n\n it('Should serialize to MARCXML', () => {\n const data = conversionService.serialize(marcRecord, CONVERSION_FORMATS.MARCXML);\n expect(data).to.equal(marcXml);\n });\n\n it('Should serialize to ISO2709', () => {\n const data = conversionService.serialize(marcRecord, CONVERSION_FORMATS.ISO2709);\n expect(data).to.equal(iso2709);\n });\n\n it('Should serialize to JSON', () => {\n const data = conversionService.serialize(marcRecord, CONVERSION_FORMATS.JSON);\n expect(data).to.equal(json);\n });\n\n it('Should serialize to aleph sequential', () => {\n const data = conversionService.serialize(marcRecord, CONVERSION_FORMATS.ALEPHSEQ);\n expect(data).to.equal(alephSeq);\n });\n\n });\n\n describe('#unserialize', () => {\n it('Should throw because of unsupported format', () => {\n expect(conversionService.unserialize).to.throw();\n });\n\n it('Should unserialize from MARCXML', async () => {\n const record = await conversionService.unserialize(marcXml, CONVERSION_FORMATS.MARCXML);\n expect(record.equalsTo(marcRecord)).to.equal(true);\n });\n\n it('Should unserialize from ISO2709', () => {\n const record = conversionService.unserialize(iso2709, CONVERSION_FORMATS.ISO2709);\n expect(record.equalsTo(marcRecord)).to.equal(true);\n });\n\n it('Should unserialize from JSON', () => {\n const record = conversionService.unserialize(json, CONVERSION_FORMATS.JSON);\n expect(record.equalsTo(marcRecord)).to.equal(true);\n });\n\n it('Should unserialize from Aleph sequential', () => {\n const record = conversionService.unserialize(alephSeq, CONVERSION_FORMATS.ALEPHSEQ);\n expect(record.equalsTo(marcRecord)).to.equal(true);\n });\n\n\n it('Should throw because the record could not be unserialized', () => {\n expect(() => {\n conversionService.unserialize('', CONVERSION_FORMATS.JSON);\n }).to.throw(ConversionError);\n });\n });\n});\n"],"mappings":";;AA4BA
|
|
1
|
+
{"version":3,"file":"conversion.spec.js","names":["describe","getFixture","fixtureFactory","root","__dirname","conversionService","createConversionService","marcRecord","MarcRecord","JSON","parse","components","subfieldValues","marcXml","iso2709","json","alephSeq","it","service","expect","to","be","an","and","respondTo","serialize","throw","data","CONVERSION_FORMATS","MARCXML","equal","ISO2709","ALEPHSEQ","unserialize","record","equalsTo","ConversionError"],"sources":["../../src/helpers/conversion.spec.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Shared modules for microservices of Melinda rest api batch import system\n*\n* Copyright (C) 2020-2021 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-rest-api-commons\n*\n* melinda-rest-api-commons program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Affero General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-rest-api-commons is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Affero General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\nimport {expect} from 'chai';\nimport fixtureFactory from '@natlibfi/fixura';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport {Error as ConversionError} from '@natlibfi/melinda-commons';\nimport createConversionService from './conversion';\nimport {CONVERSION_FORMATS} from '../constants';\n\ndescribe('services/conversion', () => {\n const {getFixture} = fixtureFactory({root: [\n __dirname,\n '..',\n '..',\n 'test-fixtures',\n 'conversion'\n ]});\n const conversionService = createConversionService();\n\n const marcRecord = new MarcRecord(JSON.parse(getFixture({components: ['json1']})), {subfieldValues: false});\n const marcXml = getFixture({components: ['marcxml1']});\n const iso2709 = getFixture({components: ['iso2709_1']});\n const json = getFixture({components: ['json1']});\n const alephSeq = getFixture({components: ['aleph_sequential']});\n\n\n describe('factory', () => {\n it('Should create the expected object', () => {\n const service = createConversionService();\n expect(service).to.be.an('object').and\n .respondTo('serialize')\n .respondTo('unserialize');\n });\n });\n\n describe('#serialize', () => {\n it('Should throw because of unsupported format', () => {\n expect(conversionService.serialize).to.throw();\n });\n\n it('Should serialize to MARCXML', () => {\n const data = conversionService.serialize(marcRecord, CONVERSION_FORMATS.MARCXML);\n expect(data).to.equal(marcXml);\n });\n\n it('Should serialize to ISO2709', () => {\n const data = conversionService.serialize(marcRecord, CONVERSION_FORMATS.ISO2709);\n expect(data).to.equal(iso2709);\n });\n\n it('Should serialize to JSON', () => {\n const data = conversionService.serialize(marcRecord, CONVERSION_FORMATS.JSON);\n expect(data).to.equal(json);\n });\n\n it('Should serialize to aleph sequential', () => {\n const data = conversionService.serialize(marcRecord, CONVERSION_FORMATS.ALEPHSEQ);\n expect(data).to.equal(alephSeq);\n });\n\n });\n\n describe('#unserialize', () => {\n it('Should throw because of unsupported format', () => {\n expect(conversionService.unserialize).to.throw();\n });\n\n it('Should unserialize from MARCXML', async () => {\n const record = await conversionService.unserialize(marcXml, CONVERSION_FORMATS.MARCXML);\n expect(record.equalsTo(marcRecord)).to.equal(true);\n });\n\n it('Should unserialize from ISO2709', () => {\n const record = conversionService.unserialize(iso2709, CONVERSION_FORMATS.ISO2709);\n expect(record.equalsTo(marcRecord)).to.equal(true);\n });\n\n it('Should unserialize from JSON', () => {\n const record = conversionService.unserialize(json, CONVERSION_FORMATS.JSON);\n expect(record.equalsTo(marcRecord)).to.equal(true);\n });\n\n it('Should unserialize from Aleph sequential', () => {\n const record = conversionService.unserialize(alephSeq, CONVERSION_FORMATS.ALEPHSEQ);\n expect(record.equalsTo(marcRecord)).to.equal(true);\n });\n\n\n it('Should throw because the record could not be unserialized', () => {\n expect(() => {\n conversionService.unserialize('', CONVERSION_FORMATS.JSON);\n }).to.throw(ConversionError);\n });\n });\n});\n"],"mappings":";;AA4BA;AACA;AACA;AACA;AACA;AACA;AAAgD;AAjChD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AASAA,QAAQ,CAAC,qBAAqB,EAAE,MAAM;EACpC,MAAM;IAACC;EAAU,CAAC,GAAG,IAAAC,eAAc,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,CAAC,CAAC"}
|
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.REPLACE_PREFIXES = 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
|
-
|
|
8
7
|
/**
|
|
9
8
|
*
|
|
10
9
|
* @licstart The following is the entire license notice for the JavaScript code in this file.
|
|
@@ -32,12 +31,14 @@ exports.REPLACE_PREFIXES = exports.BIB_STRIP_F884S_SETTINGS = exports.BIB_PREVAL
|
|
|
32
31
|
* for the JavaScript code in this file.
|
|
33
32
|
*
|
|
34
33
|
*/
|
|
34
|
+
|
|
35
35
|
// This could be formatted so that 035-prefix and SID contents would be better connected than by just an array index
|
|
36
36
|
const BIB_F035_TO_SID = {
|
|
37
37
|
f035Filters: [/^\(FI-BTJ\)/u, /^\(FI-TATI\)/u],
|
|
38
38
|
fSIDFilters: ['FI-BTJ', 'tati']
|
|
39
|
-
};
|
|
39
|
+
};
|
|
40
40
|
|
|
41
|
+
// There is somewhere other implementations of this same standardPrefixes to alephInternalPrefixes normalization
|
|
41
42
|
exports.BIB_F035_TO_SID = BIB_F035_TO_SID;
|
|
42
43
|
const REPLACE_PREFIXES = [{
|
|
43
44
|
oldPrefix: 'FI-MELINDA',
|
|
@@ -59,9 +60,10 @@ const REPLACE_PREFIXES = [{
|
|
|
59
60
|
oldPrefix: 'FI-ASTERI-W',
|
|
60
61
|
newPrefix: 'FIN13',
|
|
61
62
|
prefixReplaceCodes: ['0']
|
|
62
|
-
}];
|
|
63
|
-
// BIB_FORMAT_SETTINGS is outdated, use other settings instead
|
|
63
|
+
}];
|
|
64
64
|
|
|
65
|
+
// If placed in config.js testing needs envs
|
|
66
|
+
// BIB_FORMAT_SETTINGS is outdated, use other settings instead
|
|
65
67
|
exports.REPLACE_PREFIXES = REPLACE_PREFIXES;
|
|
66
68
|
const BIB_FORMAT_SETTINGS = {
|
|
67
69
|
replacePrefixes: REPLACE_PREFIXES,
|