@natlibfi/melinda-rest-api-commons 2.3.2-alpha.3 → 2.3.2-alpha.5
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/helpers/fix-constants.js +96 -0
- package/dist/helpers/fix-constants.js.map +1 -0
- package/dist/helpers/fix-handle-tempurns.js +161 -0
- package/dist/helpers/fix-handle-tempurns.js.map +1 -0
- package/dist/helpers/fix-strip-f884s.js +91 -0
- package/dist/helpers/fix-strip-f884s.js.map +1 -0
- package/dist/helpers/fix-utils.js +88 -0
- package/dist/helpers/fix-utils.js.map +1 -0
- package/dist/helpers/fix.js +127 -255
- package/dist/helpers/fix.js.map +1 -1
- package/dist/helpers/fix.spec.js +42 -209
- package/dist/helpers/fix.spec.js.map +1 -1
- package/dist/mongoLog.js +1 -1
- package/dist/mongoLog.js.map +1 -1
- package/package.json +8 -7
package/dist/helpers/fix.spec.js
CHANGED
|
@@ -2,223 +2,56 @@
|
|
|
2
2
|
|
|
3
3
|
var _chai = require("chai");
|
|
4
4
|
|
|
5
|
-
var _fixura = _interopRequireWildcard(require("@natlibfi/fixura"));
|
|
6
|
-
|
|
7
5
|
var _marcRecord = require("@natlibfi/marc-record");
|
|
8
6
|
|
|
7
|
+
var _fixura = require("@natlibfi/fixura");
|
|
8
|
+
|
|
9
|
+
var _fixugen = _interopRequireDefault(require("@natlibfi/fixugen"));
|
|
10
|
+
|
|
9
11
|
var _fix = require("./fix");
|
|
10
12
|
|
|
13
|
+
var fixSettings = _interopRequireWildcard(require("./fix-constants"));
|
|
14
|
+
|
|
15
|
+
var _debug = _interopRequireDefault(require("debug"));
|
|
16
|
+
|
|
11
17
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
12
18
|
|
|
13
19
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
14
20
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
* published by the Free Software Foundation, either version 3 of the
|
|
28
|
-
* License, or (at your option) any later version.
|
|
29
|
-
*
|
|
30
|
-
* melinda-rest-api-commons is distributed in the hope that it will be useful,
|
|
31
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
32
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
33
|
-
* GNU Affero General Public License for more details.
|
|
34
|
-
*
|
|
35
|
-
* You should have received a copy of the GNU Affero General Public License
|
|
36
|
-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
37
|
-
*
|
|
38
|
-
* @licend The above is the entire license notice
|
|
39
|
-
* for the JavaScript code in this file.
|
|
40
|
-
*
|
|
41
|
-
*/
|
|
42
|
-
//import {createDebugLogger} from 'debug';
|
|
43
|
-
describe('services/fix', () => {
|
|
44
|
-
const FIXTURES_PATH = [__dirname, '..', '..', 'test-fixtures', 'format'];
|
|
45
|
-
const {
|
|
46
|
-
getFixture
|
|
47
|
-
} = (0, _fixura.default)({
|
|
48
|
-
root: FIXTURES_PATH,
|
|
21
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
22
|
+
|
|
23
|
+
//import inspect from 'util';
|
|
24
|
+
const debug = (0, _debug.default)('@natlibfi/melinda-rest-api-commons:fix:test');
|
|
25
|
+
const debugData = debug.extend('data');
|
|
26
|
+
(0, _fixugen.default)({
|
|
27
|
+
callback,
|
|
28
|
+
path: [__dirname, '..', '..', 'test-fixtures', 'fix'],
|
|
29
|
+
recurse: true,
|
|
30
|
+
useMetadataFile: true,
|
|
31
|
+
fixura: {
|
|
32
|
+
failWhenNotFound: false,
|
|
49
33
|
reader: _fixura.READERS.JSON
|
|
50
|
-
}
|
|
51
|
-
describe('Undefined options', () => {
|
|
52
|
-
it(`Should not update link subfield prefixes if options are undefined`, () => {
|
|
53
|
-
const record = new _marcRecord.MarcRecord(getFixture({
|
|
54
|
-
components: ['in', 'fiAsteriN0Fin11.json']
|
|
55
|
-
}));
|
|
56
|
-
const result = (0, _fix.fixRecord)(record.toObject(), undefined);
|
|
57
|
-
const expected = getFixture({
|
|
58
|
-
components: ['in', 'fiAsteriN0Fin11.json']
|
|
59
|
-
});
|
|
60
|
-
(0, _chai.expect)(result).to.eql(expected);
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
describe('fiAsteriN0Fin11', () => {
|
|
64
|
-
it('Should succeed', () => {
|
|
65
|
-
const record = new _marcRecord.MarcRecord(getFixture({
|
|
66
|
-
components: ['in', 'fiAsteriN0Fin11.json']
|
|
67
|
-
}));
|
|
68
|
-
const result = (0, _fix.fixRecord)(record.toObject(), _fix.BIB_FORMAT_SETTINGS);
|
|
69
|
-
const expected = getFixture({
|
|
70
|
-
components: ['out', 'fiAsteriN0Fin11.json']
|
|
71
|
-
});
|
|
72
|
-
(0, _chai.expect)(result).to.eql(expected);
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
describe('fiAsteriS0Fin10', () => {
|
|
76
|
-
it('Should succeed', () => {
|
|
77
|
-
const record = new _marcRecord.MarcRecord(getFixture({
|
|
78
|
-
components: ['in', 'fiAsteriS0Fin10.json']
|
|
79
|
-
}));
|
|
80
|
-
const result = (0, _fix.fixRecord)(record.toObject(), _fix.BIB_FORMAT_SETTINGS);
|
|
81
|
-
const expected = getFixture({
|
|
82
|
-
components: ['out', 'fiAsteriS0Fin10.json']
|
|
83
|
-
});
|
|
84
|
-
(0, _chai.expect)(result).to.eql(expected);
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
describe('fiMelindaWFin01', () => {
|
|
88
|
-
it('Should succeed', () => {
|
|
89
|
-
const record = new _marcRecord.MarcRecord(getFixture({
|
|
90
|
-
components: ['in', 'fiMelindaWFin01.json']
|
|
91
|
-
}));
|
|
92
|
-
const result = (0, _fix.fixRecord)(record.toObject(), _fix.BIB_FORMAT_SETTINGS);
|
|
93
|
-
const expected = getFixture({
|
|
94
|
-
components: ['out', 'fiMelindaWFin01.json']
|
|
95
|
-
});
|
|
96
|
-
(0, _chai.expect)(result).to.eql(expected);
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
describe('f035fibtj', () => {
|
|
100
|
-
it('Should add FI-BTJ SID', () => {
|
|
101
|
-
const record = new _marcRecord.MarcRecord(getFixture({
|
|
102
|
-
components: ['in', 'f035fibtj.json']
|
|
103
|
-
}));
|
|
104
|
-
const result = (0, _fix.fixRecord)(record.toObject(), {
|
|
105
|
-
generateMissingSIDs: _fix.BIB_F035_TO_SID
|
|
106
|
-
});
|
|
107
|
-
const expected = getFixture({
|
|
108
|
-
components: ['out', 'f035fibtj.json']
|
|
109
|
-
});
|
|
110
|
-
(0, _chai.expect)(result).to.eql(expected);
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
describe('f035tati', () => {
|
|
114
|
-
it('Should add tati SID', () => {
|
|
115
|
-
const record = new _marcRecord.MarcRecord(getFixture({
|
|
116
|
-
components: ['in', 'f035tati.json']
|
|
117
|
-
}));
|
|
118
|
-
const result = (0, _fix.fixRecord)(record.toObject(), {
|
|
119
|
-
generateMissingSIDs: _fix.BIB_F035_TO_SID
|
|
120
|
-
});
|
|
121
|
-
const expected = getFixture({
|
|
122
|
-
components: ['out', 'f035tati.json']
|
|
123
|
-
});
|
|
124
|
-
(0, _chai.expect)(result).to.eql(expected);
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
|
-
describe('f035fibtjAndTati', () => {
|
|
128
|
-
it('Should add tati SID and skip FI-BTJ SID', () => {
|
|
129
|
-
const record = new _marcRecord.MarcRecord(getFixture({
|
|
130
|
-
components: ['in', 'f035fibtjAndTati.json']
|
|
131
|
-
}));
|
|
132
|
-
const result = (0, _fix.fixRecord)(record.toObject(), {
|
|
133
|
-
generateMissingSIDs: _fix.BIB_F035_TO_SID
|
|
134
|
-
});
|
|
135
|
-
const expected = getFixture({
|
|
136
|
-
components: ['out', 'f035fibtjAndTati.json']
|
|
137
|
-
}); // eslint-disable-next-line no-console
|
|
138
|
-
//console.log(`result: ${JSON.stringify(result)}`);
|
|
139
|
-
// eslint-disable-next-line no-console
|
|
140
|
-
//console.log(`expect: ${JSON.stringify(expected)}`);
|
|
141
|
-
|
|
142
|
-
(0, _chai.expect)(result).to.eql(expected);
|
|
143
|
-
});
|
|
144
|
-
});
|
|
145
|
-
describe('f035tati', () => {
|
|
146
|
-
it('Should NOT add tati SID with undefined options', () => {
|
|
147
|
-
const record = new _marcRecord.MarcRecord(getFixture({
|
|
148
|
-
components: ['in', 'f035tati.json']
|
|
149
|
-
}));
|
|
150
|
-
const result = (0, _fix.fixRecord)(record.toObject(), undefined);
|
|
151
|
-
const expected = getFixture({
|
|
152
|
-
components: ['in', 'f035tati.json']
|
|
153
|
-
});
|
|
154
|
-
(0, _chai.expect)(result).to.eql(expected);
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
describe('bib-prevalidation-fix -settings', () => {
|
|
158
|
-
it('Should add missing SIDs, but not handle sf $0s when running with BIB_PREVALIDATION_FIX_SETTINGS', () => {
|
|
159
|
-
const record = new _marcRecord.MarcRecord(getFixture({
|
|
160
|
-
components: ['in', 'f035tatiAndFin11-for-prevalidation.json']
|
|
161
|
-
}));
|
|
162
|
-
const result = (0, _fix.fixRecord)(record.toObject(), _fix.BIB_PREVALIDATION_FIX_SETTINGS);
|
|
163
|
-
const expected = getFixture({
|
|
164
|
-
components: ['out', 'f035tatiAndFin11-for-prevalidation.json']
|
|
165
|
-
});
|
|
166
|
-
(0, _chai.expect)(result).to.eql(expected);
|
|
167
|
-
});
|
|
168
|
-
});
|
|
169
|
-
describe('bib-postvalidation-fix -settings', () => {
|
|
170
|
-
it('Should handle link subfields, but not add missing SIDs, when running with BIB_PREIMPORT_FIX_SETTINGS', () => {
|
|
171
|
-
const record = new _marcRecord.MarcRecord(getFixture({
|
|
172
|
-
components: ['in', 'f035tatiAndFin11-for-postvalidation.json']
|
|
173
|
-
}));
|
|
174
|
-
const result = (0, _fix.fixRecord)(record.toObject(), _fix.BIB_PREIMPORT_FIX_SETTINGS);
|
|
175
|
-
const expected = getFixture({
|
|
176
|
-
components: ['out', 'f035tatiAndFin11-for-postvalidation.json']
|
|
177
|
-
});
|
|
178
|
-
(0, _chai.expect)(result).to.eql(expected);
|
|
179
|
-
});
|
|
180
|
-
});
|
|
181
|
-
describe('handle tempURNs', () => {
|
|
182
|
-
it('It should do nothing if there are not tempURNs', () => {
|
|
183
|
-
const record = new _marcRecord.MarcRecord(getFixture({
|
|
184
|
-
components: ['in', 'tempUrnNoTemp.json']
|
|
185
|
-
}));
|
|
186
|
-
const result = (0, _fix.fixRecord)(record.toObject(), _fix.BIB_HANDLE_TEMP_URNS_SETTINGS);
|
|
187
|
-
const expected = getFixture({
|
|
188
|
-
components: ['out', 'tempUrnNoTemp.json']
|
|
189
|
-
});
|
|
190
|
-
(0, _chai.expect)(result).to.eql(expected);
|
|
191
|
-
});
|
|
192
|
-
it('It should find a single tempURN and remove the temp subfield', () => {
|
|
193
|
-
const record = new _marcRecord.MarcRecord(getFixture({
|
|
194
|
-
components: ['in', 'tempUrnWithTemp.json']
|
|
195
|
-
}));
|
|
196
|
-
const result = (0, _fix.fixRecord)(record.toObject(), _fix.BIB_HANDLE_TEMP_URNS_SETTINGS);
|
|
197
|
-
const expected = getFixture({
|
|
198
|
-
components: ['out', 'tempUrnWithTemp.json']
|
|
199
|
-
});
|
|
200
|
-
(0, _chai.expect)(result).to.eql(expected);
|
|
201
|
-
});
|
|
202
|
-
it('It should find a tempURN and an existing legal deposit URN and remove the tempURN', () => {
|
|
203
|
-
const record = new _marcRecord.MarcRecord(getFixture({
|
|
204
|
-
components: ['in', 'tempUrnWithTempAndLD.json']
|
|
205
|
-
}));
|
|
206
|
-
const result = (0, _fix.fixRecord)(record.toObject(), _fix.BIB_HANDLE_TEMP_URNS_SETTINGS);
|
|
207
|
-
const expected = getFixture({
|
|
208
|
-
components: ['out', 'tempUrnWithTempAndLD.json']
|
|
209
|
-
});
|
|
210
|
-
(0, _chai.expect)(result).to.eql(expected);
|
|
211
|
-
});
|
|
212
|
-
it('It should find a tempURN and an existing non-legal deposit URN and remove the temp subfields from tempURN', () => {
|
|
213
|
-
const record = new _marcRecord.MarcRecord(getFixture({
|
|
214
|
-
components: ['in', 'tempUrnWithTempAndNoLD.json']
|
|
215
|
-
}));
|
|
216
|
-
const result = (0, _fix.fixRecord)(record.toObject(), _fix.BIB_HANDLE_TEMP_URNS_SETTINGS);
|
|
217
|
-
const expected = getFixture({
|
|
218
|
-
components: ['out', 'tempUrnWithTempAndNoLD.json']
|
|
219
|
-
});
|
|
220
|
-
(0, _chai.expect)(result).to.eql(expected);
|
|
221
|
-
});
|
|
222
|
-
});
|
|
34
|
+
}
|
|
223
35
|
});
|
|
36
|
+
|
|
37
|
+
function callback({
|
|
38
|
+
getFixture,
|
|
39
|
+
settings = undefined
|
|
40
|
+
}) {
|
|
41
|
+
if (settings !== undefined && fixSettings[settings] === undefined) {
|
|
42
|
+
throw new Error(`There are no settings ${settings} defined!`);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const runSettings = fixSettings[settings] || settings;
|
|
46
|
+
const record = new _marcRecord.MarcRecord(getFixture('record.json'), {
|
|
47
|
+
subfieldValues: false
|
|
48
|
+
});
|
|
49
|
+
const expectedRecord = getFixture('expectedRecord.json');
|
|
50
|
+
debug(`Running fixer with settings ${settings}.`);
|
|
51
|
+
debugData(JSON.stringify(runSettings, null, 2));
|
|
52
|
+
const resultRecord = (0, _fix.fixRecord)(record, runSettings);
|
|
53
|
+
debugData(resultRecord);
|
|
54
|
+
debugData(expectedRecord);
|
|
55
|
+
(0, _chai.expect)(resultRecord).to.eql(expectedRecord);
|
|
56
|
+
}
|
|
224
57
|
//# sourceMappingURL=fix.spec.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fix.spec.js","names":["describe","FIXTURES_PATH","__dirname","getFixture","fixtureFactory","root","reader","READERS","JSON","it","record","MarcRecord","components","result","fixRecord","toObject","undefined","expected","expect","to","eql","BIB_FORMAT_SETTINGS","generateMissingSIDs","BIB_F035_TO_SID","BIB_PREVALIDATION_FIX_SETTINGS","BIB_PREIMPORT_FIX_SETTINGS","BIB_HANDLE_TEMP_URNS_SETTINGS"],"sources":["../../src/helpers/fix.spec.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Shared modules for microservices of Melinda rest api batch import system\n*\n* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-rest-api-commons\n*\n* melinda-rest-api-commons program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Affero General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-rest-api-commons is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Affero General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\nimport {expect} from 'chai';\nimport fixtureFactory, {READERS} from '@natlibfi/fixura';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport {fixRecord, BIB_FORMAT_SETTINGS, BIB_F035_TO_SID, BIB_PREVALIDATION_FIX_SETTINGS, BIB_PREIMPORT_FIX_SETTINGS, BIB_HANDLE_TEMP_URNS_SETTINGS} from './fix';\n//import {createDebugLogger} from 'debug';\n\ndescribe('services/fix', () => {\n const FIXTURES_PATH = [\n __dirname,\n '..',\n '..',\n 'test-fixtures',\n 'format'\n ];\n const {getFixture} = fixtureFactory({root: FIXTURES_PATH, reader: READERS.JSON});\n\n describe('Undefined options', () => {\n it(`Should not update link subfield prefixes if options are undefined`, () => {\n const record = new MarcRecord(getFixture({\n components: [\n 'in',\n 'fiAsteriN0Fin11.json'\n ]\n }));\n const result = fixRecord(record.toObject(), undefined);\n const expected = getFixture({\n components: [\n 'in',\n 'fiAsteriN0Fin11.json'\n ]\n });\n\n expect(result).to.eql(expected);\n });\n });\n\n\n describe('fiAsteriN0Fin11', () => {\n it('Should succeed', () => {\n const record = new MarcRecord(getFixture({\n components: [\n 'in',\n 'fiAsteriN0Fin11.json'\n ]\n }));\n const result = fixRecord(record.toObject(), BIB_FORMAT_SETTINGS);\n const expected = getFixture({\n components: [\n 'out',\n 'fiAsteriN0Fin11.json'\n ]\n });\n\n expect(result).to.eql(expected);\n });\n });\n\n describe('fiAsteriS0Fin10', () => {\n it('Should succeed', () => {\n const record = new MarcRecord(getFixture({\n components: [\n 'in',\n 'fiAsteriS0Fin10.json'\n ]\n }));\n const result = fixRecord(record.toObject(), BIB_FORMAT_SETTINGS);\n const expected = getFixture({\n components: [\n 'out',\n 'fiAsteriS0Fin10.json'\n ]\n });\n\n expect(result).to.eql(expected);\n });\n });\n\n describe('fiMelindaWFin01', () => {\n it('Should succeed', () => {\n const record = new MarcRecord(getFixture({\n components: [\n 'in',\n 'fiMelindaWFin01.json'\n ]\n }));\n const result = fixRecord(record.toObject(), BIB_FORMAT_SETTINGS);\n const expected = getFixture({\n components: [\n 'out',\n 'fiMelindaWFin01.json'\n ]\n });\n\n expect(result).to.eql(expected);\n });\n });\n\n describe('f035fibtj', () => {\n it('Should add FI-BTJ SID', () => {\n const record = new MarcRecord(getFixture({\n components: [\n 'in',\n 'f035fibtj.json'\n ]\n }));\n const result = fixRecord(record.toObject(), {generateMissingSIDs: BIB_F035_TO_SID});\n const expected = getFixture({\n components: [\n 'out',\n 'f035fibtj.json'\n ]\n });\n\n expect(result).to.eql(expected);\n });\n });\n\n describe('f035tati', () => {\n it('Should add tati SID', () => {\n const record = new MarcRecord(getFixture({\n components: [\n 'in',\n 'f035tati.json'\n ]\n }));\n const result = fixRecord(record.toObject(), {generateMissingSIDs: BIB_F035_TO_SID});\n const expected = getFixture({\n components: [\n 'out',\n 'f035tati.json'\n ]\n });\n\n expect(result).to.eql(expected);\n });\n });\n\n describe('f035fibtjAndTati', () => {\n it('Should add tati SID and skip FI-BTJ SID', () => {\n const record = new MarcRecord(getFixture({\n components: [\n 'in',\n 'f035fibtjAndTati.json'\n ]\n }));\n const result = fixRecord(record.toObject(), {generateMissingSIDs: BIB_F035_TO_SID});\n const expected = getFixture({\n components: [\n 'out',\n 'f035fibtjAndTati.json'\n ]\n });\n // eslint-disable-next-line no-console\n //console.log(`result: ${JSON.stringify(result)}`);\n // eslint-disable-next-line no-console\n //console.log(`expect: ${JSON.stringify(expected)}`);\n expect(result).to.eql(expected);\n });\n });\n\n describe('f035tati', () => {\n it('Should NOT add tati SID with undefined options', () => {\n const record = new MarcRecord(getFixture({\n components: [\n 'in',\n 'f035tati.json'\n ]\n }));\n const result = fixRecord(record.toObject(), undefined);\n const expected = getFixture({\n components: [\n 'in',\n 'f035tati.json'\n ]\n });\n\n expect(result).to.eql(expected);\n });\n });\n\n describe('bib-prevalidation-fix -settings', () => {\n it('Should add missing SIDs, but not handle sf $0s when running with BIB_PREVALIDATION_FIX_SETTINGS', () => {\n const record = new MarcRecord(getFixture({\n components: [\n 'in',\n 'f035tatiAndFin11-for-prevalidation.json'\n ]\n }));\n const result = fixRecord(record.toObject(), BIB_PREVALIDATION_FIX_SETTINGS);\n const expected = getFixture({\n components: [\n 'out',\n 'f035tatiAndFin11-for-prevalidation.json'\n ]\n });\n\n expect(result).to.eql(expected);\n });\n });\n\n\n describe('bib-postvalidation-fix -settings', () => {\n it('Should handle link subfields, but not add missing SIDs, when running with BIB_PREIMPORT_FIX_SETTINGS', () => {\n const record = new MarcRecord(getFixture({\n components: [\n 'in',\n 'f035tatiAndFin11-for-postvalidation.json'\n ]\n }));\n const result = fixRecord(record.toObject(), BIB_PREIMPORT_FIX_SETTINGS);\n const expected = getFixture({\n components: [\n 'out',\n 'f035tatiAndFin11-for-postvalidation.json'\n ]\n });\n\n expect(result).to.eql(expected);\n });\n });\n\n describe('handle tempURNs', () => {\n it('It should do nothing if there are not tempURNs', () => {\n const record = new MarcRecord(getFixture({\n components: [\n 'in',\n 'tempUrnNoTemp.json'\n ]\n }));\n const result = fixRecord(record.toObject(), BIB_HANDLE_TEMP_URNS_SETTINGS);\n const expected = getFixture({\n components: [\n 'out',\n 'tempUrnNoTemp.json'\n ]\n });\n\n expect(result).to.eql(expected);\n });\n\n it('It should find a single tempURN and remove the temp subfield', () => {\n const record = new MarcRecord(getFixture({\n components: [\n 'in',\n 'tempUrnWithTemp.json'\n ]\n }));\n const result = fixRecord(record.toObject(), BIB_HANDLE_TEMP_URNS_SETTINGS);\n const expected = getFixture({\n components: [\n 'out',\n 'tempUrnWithTemp.json'\n ]\n });\n\n expect(result).to.eql(expected);\n });\n\n it('It should find a tempURN and an existing legal deposit URN and remove the tempURN', () => {\n const record = new MarcRecord(getFixture({\n components: [\n 'in',\n 'tempUrnWithTempAndLD.json'\n ]\n }));\n const result = fixRecord(record.toObject(), BIB_HANDLE_TEMP_URNS_SETTINGS);\n const expected = getFixture({\n components: [\n 'out',\n 'tempUrnWithTempAndLD.json'\n ]\n });\n\n expect(result).to.eql(expected);\n });\n\n it('It should find a tempURN and an existing non-legal deposit URN and remove the temp subfields from tempURN', () => {\n const record = new MarcRecord(getFixture({\n components: [\n 'in',\n 'tempUrnWithTempAndNoLD.json'\n ]\n }));\n const result = fixRecord(record.toObject(), BIB_HANDLE_TEMP_URNS_SETTINGS);\n const expected = getFixture({\n components: [\n 'out',\n 'tempUrnWithTempAndNoLD.json'\n ]\n });\n\n expect(result).to.eql(expected);\n });\n });\n\n});\n"],"mappings":";;AA4BA;;AACA;;AACA;;AACA;;;;;;AA/BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAMA;AAEAA,QAAQ,CAAC,cAAD,EAAiB,MAAM;EAC7B,MAAMC,aAAa,GAAG,CACpBC,SADoB,EAEpB,IAFoB,EAGpB,IAHoB,EAIpB,eAJoB,EAKpB,QALoB,CAAtB;EAOA,MAAM;IAACC;EAAD,IAAe,IAAAC,eAAA,EAAe;IAACC,IAAI,EAAEJ,aAAP;IAAsBK,MAAM,EAAEC,eAAA,CAAQC;EAAtC,CAAf,CAArB;EAEAR,QAAQ,CAAC,mBAAD,EAAsB,MAAM;IAClCS,EAAE,CAAE,mEAAF,EAAsE,MAAM;MAC5E,MAAMC,MAAM,GAAG,IAAIC,sBAAJ,CAAeR,UAAU,CAAC;QACvCS,UAAU,EAAE,CACV,IADU,EAEV,sBAFU;MAD2B,CAAD,CAAzB,CAAf;MAMA,MAAMC,MAAM,GAAG,IAAAC,cAAA,EAAUJ,MAAM,CAACK,QAAP,EAAV,EAA6BC,SAA7B,CAAf;MACA,MAAMC,QAAQ,GAAGd,UAAU,CAAC;QAC1BS,UAAU,EAAE,CACV,IADU,EAEV,sBAFU;MADc,CAAD,CAA3B;MAOA,IAAAM,YAA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AU,EAAE,CACV,KADU,EAEV,2BAFU;MADc,CAAD,CAA3B;MAOA,IAAAM,YAAA,EAAOL,MAAP,EAAeM,EAAf,CAAkBC,GAAlB,CAAsBH,QAAtB;IACD,CAhBC,CAAF;IAkBAR,EAAE,CAAC,2GAAD,EAA8G,MAAM;MACpH,MAAMC,MAAM,GAAG,IAAIC,sBAAJ,CAAeR,UAAU,CAAC;QACvCS,UAAU,EAAE,CACV,IADU,EAEV,6BAFU;MAD2B,CAAD,CAAzB,CAAf;MAMA,MAAMC,MAAM,GAAG,IAAAC,cAAA,EAAUJ,MAAM,CAACK,QAAP,EAAV,EAA6BW,kCAA7B,CAAf;MACA,MAAMT,QAAQ,GAAGd,UAAU,CAAC;QAC1BS,UAAU,EAAE,CACV,KADU,EAEV,6BAFU;MADc,CAAD,CAA3B;MAOA,IAAAM,YAAA,EAAOL,MAAP,EAAeM,EAAf,CAAkBC,GAAlB,CAAsBH,QAAtB;IACD,CAhBC,CAAF;EAiBD,CAxEO,CAAR;AA0ED,CAjSO,CAAR"}
|
|
1
|
+
{"version":3,"file":"fix.spec.js","names":["debug","createDebugLogger","debugData","extend","generateTests","callback","path","__dirname","recurse","useMetadataFile","fixura","failWhenNotFound","reader","READERS","JSON","getFixture","settings","undefined","fixSettings","Error","runSettings","record","MarcRecord","subfieldValues","expectedRecord","stringify","resultRecord","fixRecord","expect","to","eql"],"sources":["../../src/helpers/fix.spec.js"],"sourcesContent":["import {expect} from 'chai';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport {READERS} from '@natlibfi/fixura';\nimport generateTests from '@natlibfi/fixugen';\nimport {fixRecord} from './fix';\nimport * as fixSettings from './fix-constants';\nimport createDebugLogger from 'debug';\n//import inspect from 'util';\n\nconst debug = createDebugLogger('@natlibfi/melinda-rest-api-commons:fix:test');\nconst debugData = debug.extend('data');\n\ngenerateTests({\n callback,\n path: [__dirname, '..', '..', 'test-fixtures', 'fix'],\n recurse: true,\n useMetadataFile: true,\n fixura: {\n failWhenNotFound: false,\n reader: READERS.JSON\n }\n});\n\nfunction callback({getFixture, settings = undefined}) {\n if (settings !== undefined && fixSettings[settings] === undefined) {\n throw new Error(`There are no settings ${settings} defined!`);\n }\n const runSettings = fixSettings[settings] || settings;\n\n const record = new MarcRecord(getFixture('record.json'), {subfieldValues: false});\n const expectedRecord = getFixture('expectedRecord.json');\n\n debug(`Running fixer with settings ${settings}.`);\n debugData(JSON.stringify(runSettings, null, 2));\n\n const resultRecord = fixRecord(record, runSettings);\n debugData(resultRecord);\n debugData(expectedRecord);\n expect(resultRecord).to.eql(expectedRecord);\n\n}\n"],"mappings":";;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;AACA;AAEA,MAAMA,KAAK,GAAG,IAAAC,cAAA,EAAkB,6CAAlB,CAAd;AACA,MAAMC,SAAS,GAAGF,KAAK,CAACG,MAAN,CAAa,MAAb,CAAlB;AAEA,IAAAC,gBAAA,EAAc;EACZC,QADY;EAEZC,IAAI,EAAE,CAACC,SAAD,EAAY,IAAZ,EAAkB,IAAlB,EAAwB,eAAxB,EAAyC,KAAzC,CAFM;EAGZC,OAAO,EAAE,IAHG;EAIZC,eAAe,EAAE,IAJL;EAKZC,MAAM,EAAE;IACNC,gBAAgB,EAAE,KADZ;IAENC,MAAM,EAAEC,eAAA,CAAQC;EAFV;AALI,CAAd;;AAWA,SAAST,QAAT,CAAkB;EAACU,UAAD;EAAaC,QAAQ,GAAGC;AAAxB,CAAlB,EAAsD;EACpD,IAAID,QAAQ,KAAKC,SAAb,IAA0BC,WAAW,CAACF,QAAD,CAAX,KAA0BC,SAAxD,EAAmE;IACjE,MAAM,IAAIE,KAAJ,CAAW,yBAAwBH,QAAS,WAA5C,CAAN;EACD;;EACD,MAAMI,WAAW,GAAGF,WAAW,CAACF,QAAD,CAAX,IAAyBA,QAA7C;EAEA,MAAMK,MAAM,GAAG,IAAIC,sBAAJ,CAAeP,UAAU,CAAC,aAAD,CAAzB,EAA0C;IAACQ,cAAc,EAAE;EAAjB,CAA1C,CAAf;EACA,MAAMC,cAAc,GAAGT,UAAU,CAAC,qBAAD,CAAjC;EAEAf,KAAK,CAAE,+BAA8BgB,QAAS,GAAzC,CAAL;EACAd,SAAS,CAACY,IAAI,CAACW,SAAL,CAAeL,WAAf,EAA4B,IAA5B,EAAkC,CAAlC,CAAD,CAAT;EAEA,MAAMM,YAAY,GAAG,IAAAC,cAAA,EAAUN,MAAV,EAAkBD,WAAlB,CAArB;EACAlB,SAAS,CAACwB,YAAD,CAAT;EACAxB,SAAS,CAACsB,cAAD,CAAT;EACA,IAAAI,YAAA,EAAOF,YAAP,EAAqBG,EAArB,CAAwBC,GAAxB,CAA4BN,cAA5B;AAED"}
|
package/dist/mongoLog.js
CHANGED
|
@@ -145,7 +145,7 @@ async function _default(MONGO_URI) {
|
|
|
145
145
|
const cleanBlobSequence = (0, _mongoSanitize.default)(blobSequence);
|
|
146
146
|
const filter = blobSequence ? {
|
|
147
147
|
correlationId: cleanCorrelationId,
|
|
148
|
-
blobSequence: cleanBlobSequence
|
|
148
|
+
blobSequence: parseInt(cleanBlobSequence, 10)
|
|
149
149
|
} : {
|
|
150
150
|
correlationId: cleanCorrelationId
|
|
151
151
|
};
|
package/dist/mongoLog.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mongoLog.js","names":["MONGO_URI","logger","createLogger","client","MongoClient","connect","useNewUrlParser","useUnifiedTopology","db","collection","addLogItem","query","queryById","getListOfLogs","protect","remove","logItem","time","moment","toDate","newLogItem","creationTime","protected","checkLogItemType","logItemType","result","insertOne","acknowledged","blobSequence","blobSequenceStart","blobSequenceEnd","itemString","info","correlationId","ApiError","httpStatus","INTERNAL_SERVER_ERROR","error","logError","params","debug","JSON","stringify","limit","skip","rest","find","sort","parseInt","toArray","length","correlationIdString","distinct","status","OK","NOT_FOUND","payload","cleanCorrelationId","sanitize","cleanBlobSequence","filter","updateMany","$set","modificationTime","$not","modifiedCount","err","message","force","clean","$ne","deleteMany","deletedCount","errorUnknown","errorNotExisting","typeInLogItemTypes","Object","values","LOG_ITEM_TYPE","indexOf"],"sources":["../src/mongoLog.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Shared modules for microservices of Melinda rest api batch import system\n*\n* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-rest-api-commons\n*\n* melinda-rest-api-commons program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Affero General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-rest-api-commons is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Affero General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\nimport {MongoClient} from 'mongodb';\nimport {createLogger} from '@natlibfi/melinda-backend-commons';\nimport {Error as ApiError} from '@natlibfi/melinda-commons';\nimport {logError} from './utils.js';\nimport moment from 'moment';\nimport httpStatus from 'http-status';\nimport sanitize from 'mongo-sanitize';\nimport {LOG_ITEM_TYPE} from './constants';\n\nexport default async function (MONGO_URI) {\n const logger = createLogger();\n\n // Connect to mongo (MONGO)\n const client = await MongoClient.connect(MONGO_URI, {useNewUrlParser: true, useUnifiedTopology: true});\n const db = client.db('rest-api');\n const collection = 'logs';\n return {addLogItem, query, queryById, getListOfLogs, protect, remove};\n\n async function addLogItem(logItem) {\n const time = moment().toDate();\n const newLogItem = {\n ...logItem,\n creationTime: time,\n protected: false\n };\n try {\n checkLogItemType(logItem.logItemType, false);\n const result = await db.collection(collection).insertOne(newLogItem);\n if (result.acknowledged) {\n const {blobSequence, blobSequenceStart, blobSequenceEnd} = logItem;\n const itemString = blobSequenceStart && blobSequenceEnd ? `${blobSequenceStart} - ${blobSequenceEnd}` : `${blobSequence}`;\n logger.info(`*** New ${logItem.logItemType} added for ${logItem.correlationId}, blobSequence(s): ${itemString}. ***`);\n return;\n }\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR);\n } catch (error) {\n logError(error);\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR);\n }\n }\n\n async function query(params) {\n logger.debug(`Query params: ${JSON.stringify(params)}`);\n checkLogItemType(params.logItemType, false, false);\n const {limit = 5, skip = 0, ...rest} = params;\n const result = await db.collection(collection) // eslint-disable-line functional/immutable-data\n .find(rest)\n .sort({blobSequence: 1})\n .skip(parseInt(skip, 10))\n .limit(parseInt(limit, 10))\n .toArray();\n logger.debug(`Query result: ${result}`);\n logger.debug(`Query result: ${result.length > 0 ? `Found ${result.length} log items! (skip: ${skip} limit: ${limit})` : 'Not found!'}`);\n return result;\n }\n\n async function queryById(correlationIdString, skip = 0, limit = 1) {\n logger.debug(`QueryById: ${correlationIdString}`);\n const result = await db.collection(collection) // eslint-disable-line functional/immutable-data\n .find({correlationId: correlationIdString})\n .sort({blobSequence: 1})\n .skip(parseInt(skip, 10))\n .limit(parseInt(limit, 10))\n .toArray();\n logger.debug(`Query result: ${result.length > 0 ? `Found ${result.length} log items!` : 'Not found!'}`);\n return result;\n }\n\n async function getListOfLogs(logItemType = 'MERGE_LOG') {\n checkLogItemType(logItemType, false, false);\n const result = await db.collection(collection) // eslint-disable-line functional/immutable-data\n .distinct('correlationId', {logItemType});\n logger.debug(`Query result: ${result.length > 0 ? `Found ${result.length} log items!` : 'Not found!'}`);\n return {status: result.length > 0 ? httpStatus.OK : httpStatus.NOT_FOUND, payload: result.length > 0 ? result : 'No logs found'};\n }\n\n async function protect(correlationId, blobSequence) {\n logger.info(`Protecting in Mongo (${collection}) correlationId: ${correlationId}, blobSequence: ${blobSequence}`);\n const cleanCorrelationId = sanitize(correlationId);\n const cleanBlobSequence = sanitize(blobSequence);\n const filter = blobSequence ? {correlationId: cleanCorrelationId, blobSequence: cleanBlobSequence} : {correlationId: cleanCorrelationId};\n\n try {\n const result = await db.collection(collection).updateMany(\n filter,\n {\n $set: {\n modificationTime: moment().toDate(),\n protect: {$not: '$protect'}\n }\n }\n );\n return {status: result.modifiedCount > 0 ? httpStatus.OK : httpStatus.NOT_FOUND, payload: result.modifiedCount > 0 ? result : 'No logs found'};\n } catch (err) {\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, err.message);\n }\n }\n\n async function remove(correlationId, force = false) {\n logger.info(`Removing from Mongo (${collection}) correlationId: ${correlationId}`);\n const clean = sanitize(correlationId);\n const filter = force ? {correlationId: clean} : {correlationId: clean, protected: {$ne: true}};\n\n try {\n const result = await db.collection(collection).deleteMany(filter);\n return {status: result.deletedCount > 0 ? httpStatus.OK : httpStatus.NOT_FOUND, payload: result.deletedCount > 0 ? result : 'No logs found'};\n } catch (err) {\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, err.message);\n }\n }\n\n function checkLogItemType(logItemType, errorUnknown = false, errorNotExisting = false) {\n\n if (logItemType) {\n const typeInLogItemTypes = Object.values(LOG_ITEM_TYPE).indexOf(logItemType) > -1;\n if (typeInLogItemTypes) {\n return logger.debug(`Valid logItemType: ${logItemType}`);\n }\n if (errorUnknown) {\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, `Unknown logItemType: ${logItemType}`);\n }\n return logger.debug(`WARN: We have unknown logType: ${logItemType}`);\n }\n\n if (errorNotExisting) {\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, `No logItemType: ${logItemType}`);\n }\n return logger.debug(`No logItemType: ${logItemType}`);\n }\n}\n"],"mappings":";;;;;;;AA4BA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;AAnCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAWe,wBAAg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names":["MONGO_URI","logger","createLogger","client","MongoClient","connect","useNewUrlParser","useUnifiedTopology","db","collection","addLogItem","query","queryById","getListOfLogs","protect","remove","logItem","time","moment","toDate","newLogItem","creationTime","protected","checkLogItemType","logItemType","result","insertOne","acknowledged","blobSequence","blobSequenceStart","blobSequenceEnd","itemString","info","correlationId","ApiError","httpStatus","INTERNAL_SERVER_ERROR","error","logError","params","debug","JSON","stringify","limit","skip","rest","find","sort","parseInt","toArray","length","correlationIdString","distinct","status","OK","NOT_FOUND","payload","cleanCorrelationId","sanitize","cleanBlobSequence","filter","updateMany","$set","modificationTime","$not","modifiedCount","err","message","force","clean","$ne","deleteMany","deletedCount","errorUnknown","errorNotExisting","typeInLogItemTypes","Object","values","LOG_ITEM_TYPE","indexOf"],"sources":["../src/mongoLog.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Shared modules for microservices of Melinda rest api batch import system\n*\n* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-rest-api-commons\n*\n* melinda-rest-api-commons program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Affero General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-rest-api-commons is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Affero General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\nimport {MongoClient} from 'mongodb';\nimport {createLogger} from '@natlibfi/melinda-backend-commons';\nimport {Error as ApiError} from '@natlibfi/melinda-commons';\nimport {logError} from './utils.js';\nimport moment from 'moment';\nimport httpStatus from 'http-status';\nimport sanitize from 'mongo-sanitize';\nimport {LOG_ITEM_TYPE} from './constants';\n\nexport default async function (MONGO_URI) {\n const logger = createLogger();\n\n // Connect to mongo (MONGO)\n const client = await MongoClient.connect(MONGO_URI, {useNewUrlParser: true, useUnifiedTopology: true});\n const db = client.db('rest-api');\n const collection = 'logs';\n return {addLogItem, query, queryById, getListOfLogs, protect, remove};\n\n async function addLogItem(logItem) {\n const time = moment().toDate();\n const newLogItem = {\n ...logItem,\n creationTime: time,\n protected: false\n };\n try {\n checkLogItemType(logItem.logItemType, false);\n const result = await db.collection(collection).insertOne(newLogItem);\n if (result.acknowledged) {\n const {blobSequence, blobSequenceStart, blobSequenceEnd} = logItem;\n const itemString = blobSequenceStart && blobSequenceEnd ? `${blobSequenceStart} - ${blobSequenceEnd}` : `${blobSequence}`;\n logger.info(`*** New ${logItem.logItemType} added for ${logItem.correlationId}, blobSequence(s): ${itemString}. ***`);\n return;\n }\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR);\n } catch (error) {\n logError(error);\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR);\n }\n }\n\n async function query(params) {\n logger.debug(`Query params: ${JSON.stringify(params)}`);\n checkLogItemType(params.logItemType, false, false);\n const {limit = 5, skip = 0, ...rest} = params;\n const result = await db.collection(collection) // eslint-disable-line functional/immutable-data\n .find(rest)\n .sort({blobSequence: 1})\n .skip(parseInt(skip, 10))\n .limit(parseInt(limit, 10))\n .toArray();\n logger.debug(`Query result: ${result}`);\n logger.debug(`Query result: ${result.length > 0 ? `Found ${result.length} log items! (skip: ${skip} limit: ${limit})` : 'Not found!'}`);\n return result;\n }\n\n async function queryById(correlationIdString, skip = 0, limit = 1) {\n logger.debug(`QueryById: ${correlationIdString}`);\n const result = await db.collection(collection) // eslint-disable-line functional/immutable-data\n .find({correlationId: correlationIdString})\n .sort({blobSequence: 1})\n .skip(parseInt(skip, 10))\n .limit(parseInt(limit, 10))\n .toArray();\n logger.debug(`Query result: ${result.length > 0 ? `Found ${result.length} log items!` : 'Not found!'}`);\n return result;\n }\n\n async function getListOfLogs(logItemType = 'MERGE_LOG') {\n checkLogItemType(logItemType, false, false);\n const result = await db.collection(collection) // eslint-disable-line functional/immutable-data\n .distinct('correlationId', {logItemType});\n logger.debug(`Query result: ${result.length > 0 ? `Found ${result.length} log items!` : 'Not found!'}`);\n return {status: result.length > 0 ? httpStatus.OK : httpStatus.NOT_FOUND, payload: result.length > 0 ? result : 'No logs found'};\n }\n\n async function protect(correlationId, blobSequence) {\n logger.info(`Protecting in Mongo (${collection}) correlationId: ${correlationId}, blobSequence: ${blobSequence}`);\n const cleanCorrelationId = sanitize(correlationId);\n const cleanBlobSequence = sanitize(blobSequence);\n const filter = blobSequence ? {correlationId: cleanCorrelationId, blobSequence: parseInt(cleanBlobSequence, 10)} : {correlationId: cleanCorrelationId};\n\n try {\n const result = await db.collection(collection).updateMany(\n filter,\n {\n $set: {\n modificationTime: moment().toDate(),\n protect: {$not: '$protect'}\n }\n }\n );\n return {status: result.modifiedCount > 0 ? httpStatus.OK : httpStatus.NOT_FOUND, payload: result.modifiedCount > 0 ? result : 'No logs found'};\n } catch (err) {\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, err.message);\n }\n }\n\n async function remove(correlationId, force = false) {\n logger.info(`Removing from Mongo (${collection}) correlationId: ${correlationId}`);\n const clean = sanitize(correlationId);\n const filter = force ? {correlationId: clean} : {correlationId: clean, protected: {$ne: true}};\n\n try {\n const result = await db.collection(collection).deleteMany(filter);\n return {status: result.deletedCount > 0 ? httpStatus.OK : httpStatus.NOT_FOUND, payload: result.deletedCount > 0 ? result : 'No logs found'};\n } catch (err) {\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, err.message);\n }\n }\n\n function checkLogItemType(logItemType, errorUnknown = false, errorNotExisting = false) {\n\n if (logItemType) {\n const typeInLogItemTypes = Object.values(LOG_ITEM_TYPE).indexOf(logItemType) > -1;\n if (typeInLogItemTypes) {\n return logger.debug(`Valid logItemType: ${logItemType}`);\n }\n if (errorUnknown) {\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, `Unknown logItemType: ${logItemType}`);\n }\n return logger.debug(`WARN: We have unknown logType: ${logItemType}`);\n }\n\n if (errorNotExisting) {\n throw new ApiError(httpStatus.INTERNAL_SERVER_ERROR, `No logItemType: ${logItemType}`);\n }\n return logger.debug(`No logItemType: ${logItemType}`);\n }\n}\n"],"mappings":";;;;;;;AA4BA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;AAnCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAWe,wBAAgBA,SAAhB,EAA2B;EACxC,MAAMC,MAAM,GAAG,IAAAC,mCAAA,GAAf,CADwC,CAGxC;;EACA,MAAMC,MAAM,GAAG,MAAMC,oBAAA,CAAYC,OAAZ,CAAoBL,SAApB,EAA+B;IAACM,eAAe,EAAE,IAAlB;IAAwBC,kBAAkB,EAAE;EAA5C,CAA/B,CAArB;EACA,MAAMC,EAAE,GAAGL,MAAM,CAACK,EAAP,CAAU,UAAV,CAAX;EACA,MAAMC,UAAU,GAAG,MAAnB;EACA,OAAO;IAACC,UAAD;IAAaC,KAAb;IAAoBC,SAApB;IAA+BC,aAA/B;IAA8CC,OAA9C;IAAuDC;EAAvD,CAAP;;EAEA,eAAeL,UAAf,CAA0BM,OAA1B,EAAmC;IACjC,MAAMC,IAAI,GAAG,IAAAC,eAAA,IAASC,MAAT,EAAb;IACA,MAAMC,UAAU,GAAG,EACjB,GAAGJ,OADc;MAEjBK,YAAY,EAAEJ,IAFG;MAGjBK,SAAS,EAAE;IAHM,CAAnB;;IAKA,IAAI;MACFC,gBAAgB,CAACP,OAAO,CAACQ,WAAT,EAAsB,KAAtB,CAAhB;MACA,MAAMC,MAAM,GAAG,MAAMjB,EAAE,CAACC,UAAH,CAAcA,UAAd,EAA0BiB,SAA1B,CAAoCN,UAApC,CAArB;;MACA,IAAIK,MAAM,CAACE,YA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IiD,YAAJ,EAAkB;QAChB,MAAM,IAAIvC,qBAAJ,CAAaC,mBAAA,CAAWC,qBAAxB,EAAgD,wBAAuBZ,WAAY,EAAnF,CAAN;MACD;;MACD,OAAOvB,MAAM,CAACuC,KAAP,CAAc,kCAAiChB,WAAY,EAA3D,CAAP;IACD;;IAED,IAAIkD,gBAAJ,EAAsB;MACpB,MAAM,IAAIxC,qBAAJ,CAAaC,mBAAA,CAAWC,qBAAxB,EAAgD,mBAAkBZ,WAAY,EAA9E,CAAN;IACD;;IACD,OAAOvB,MAAM,CAACuC,KAAP,CAAc,mBAAkBhB,WAAY,EAA5C,CAAP;EACD;AACF"}
|
package/package.json
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"url": "git@github.com:natlibfi/melinda-rest-api-commons.git"
|
|
15
15
|
},
|
|
16
16
|
"license": "AGPL-3.0+",
|
|
17
|
-
"version": "2.3.2-alpha.
|
|
17
|
+
"version": "2.3.2-alpha.5",
|
|
18
18
|
"main": "./dist/index.js",
|
|
19
19
|
"engines": {
|
|
20
20
|
"node": ">=14"
|
|
@@ -33,12 +33,13 @@
|
|
|
33
33
|
"build": "babel src --source-maps --copy-files --delete-dir-on-start --out-dir=dist"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@natlibfi/
|
|
37
|
-
"@natlibfi/marc-record
|
|
36
|
+
"@natlibfi/fixugen": "^1.1.0",
|
|
37
|
+
"@natlibfi/marc-record": "^7.2.2",
|
|
38
|
+
"@natlibfi/marc-record-serializers": "^9.0.1",
|
|
38
39
|
"@natlibfi/marc-record-validate": "^7.0.2",
|
|
39
40
|
"@natlibfi/marc-record-validators-melinda": "^9.0.13",
|
|
40
41
|
"@natlibfi/melinda-backend-commons": "^2.1.0",
|
|
41
|
-
"@natlibfi/melinda-commons": "^12.0.
|
|
42
|
+
"@natlibfi/melinda-commons": "^12.0.5",
|
|
42
43
|
"amqplib": ">=0.8.0 <1.0.0",
|
|
43
44
|
"debug": "^4.3.4",
|
|
44
45
|
"http-status": "^1.5.3",
|
|
@@ -51,7 +52,7 @@
|
|
|
51
52
|
"@babel/core": "^7.19.3",
|
|
52
53
|
"@babel/eslint-parser": "^7.19.1",
|
|
53
54
|
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
|
54
|
-
"@babel/preset-env": "^7.19.
|
|
55
|
+
"@babel/preset-env": "^7.19.4",
|
|
55
56
|
"@natlibfi/eslint-config-melinda-backend": "^2.0.1",
|
|
56
57
|
"@natlibfi/fixura": "^2.2.5",
|
|
57
58
|
"babel-plugin-dynamic-import-node": "^2.3.3",
|
|
@@ -59,8 +60,8 @@
|
|
|
59
60
|
"babel-plugin-rewire": "^1.2.0",
|
|
60
61
|
"chai": "^4.3.6",
|
|
61
62
|
"cross-env": "^7.0.3",
|
|
62
|
-
"eslint": "^8.
|
|
63
|
-
"mocha": "^10.
|
|
63
|
+
"eslint": "^8.25.0",
|
|
64
|
+
"mocha": "^10.1.0",
|
|
64
65
|
"nodemon": "^2.0.20",
|
|
65
66
|
"nyc": "^15.1.0"
|
|
66
67
|
},
|