@natlibfi/marc-record-merge 6.0.0-beta.1 → 6.0.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/CODEOWNERS +9 -0
- package/.github/dependabot.yml +41 -0
- package/.github/workflows/melinda-node-tests.yml +60 -0
- package/LICENSE +21 -0
- package/README.md +122 -2
- package/dist/index.js +42 -43
- package/dist/index.js.map +1 -1
- package/dist/reducers/copy.js +232 -83
- package/dist/reducers/copy.js.map +1 -1
- package/dist/reducers/copy.spec.js +57 -72
- package/dist/reducers/copy.spec.js.map +1 -1
- package/dist/reducers/index.js +13 -24
- package/dist/reducers/index.js.map +1 -1
- package/dist/reducers/select.js +33 -51
- package/dist/reducers/select.js.map +1 -1
- package/dist/reducers/select.spec.js +45 -92
- package/dist/reducers/select.spec.js.map +1 -1
- package/package.json +33 -32
- package/src/index.js +30 -32
- package/src/reducers/copy.js +242 -79
- package/src/reducers/copy.spec.js +50 -48
- package/src/reducers/index.js +3 -30
- package/src/reducers/select.js +27 -34
- package/src/reducers/select.spec.js +41 -56
- package/test-fixtures/reducers/copy/{01/base.json → 01 - copy/01/base.json } +1 -1
- package/test-fixtures/reducers/copy/{01 → 01 - copy/01}/merged.json +0 -0
- package/test-fixtures/reducers/copy/01 - copy/01/metadata.json +4 -0
- package/test-fixtures/reducers/copy/{01 → 01 - copy/01}/source.json +0 -0
- package/test-fixtures/reducers/copy/{02/source.json → 01 - copy/02/base.json} +0 -0
- package/test-fixtures/reducers/copy/{02 → 01 - copy/02}/merged.json +0 -0
- package/test-fixtures/reducers/copy/01 - copy/02/metadata.json +4 -0
- package/test-fixtures/reducers/copy/{02/base.json → 01 - copy/02/source.json } +1 -1
- package/test-fixtures/reducers/copy/{03/base.json → 01 - copy/03/base.json } +1 -1
- package/test-fixtures/reducers/copy/{03 → 01 - copy/03}/merged.json +0 -0
- package/test-fixtures/reducers/copy/01 - copy/03/metadata.json +4 -0
- package/test-fixtures/reducers/copy/{03 → 01 - copy/03}/source.json +0 -0
- package/test-fixtures/reducers/copy/{05/base.json → 01 - copy/04/base.json } +1 -1
- package/test-fixtures/reducers/copy/{04/merged.json → 01 - copy/04/merged.json } +1 -1
- package/test-fixtures/reducers/copy/01 - copy/04/metadata.json +4 -0
- package/test-fixtures/reducers/copy/{04/source.json → 01 - copy/04/source.json } +1 -1
- package/test-fixtures/reducers/copy/{04/base.json → 01 - copy/05/base.json } +1 -1
- package/test-fixtures/reducers/copy/01 - copy/05/merged.json +77 -0
- package/test-fixtures/reducers/copy/01 - copy/05/metadata.json +4 -0
- package/test-fixtures/reducers/copy/01 - copy/05/source.json +62 -0
- package/test-fixtures/reducers/copy/01 - copy/06/base.json +24 -0
- package/test-fixtures/reducers/copy/01 - copy/06/merged.json +39 -0
- package/test-fixtures/reducers/copy/01 - copy/06/metadata.json +4 -0
- package/test-fixtures/reducers/copy/01 - copy/06/source.json +24 -0
- package/test-fixtures/reducers/copy/01 - copy/07/base.json +39 -0
- package/test-fixtures/reducers/copy/01 - copy/07/merged.json +39 -0
- package/test-fixtures/reducers/copy/01 - copy/07/metadata.json +5 -0
- package/test-fixtures/reducers/copy/01 - copy/07/source.json +24 -0
- package/test-fixtures/reducers/copy/01 - copy/08/base.json +28 -0
- package/test-fixtures/reducers/copy/01 - copy/08/merged.json +28 -0
- package/test-fixtures/reducers/copy/01 - copy/08/metadata.json +4 -0
- package/test-fixtures/reducers/copy/01 - copy/08/source.json +24 -0
- package/test-fixtures/reducers/copy/02 - doNotCopyIfFieldPresent/01/base.json +17 -0
- package/test-fixtures/reducers/copy/02 - doNotCopyIfFieldPresent/01/merged.json +20 -0
- package/test-fixtures/reducers/copy/02 - doNotCopyIfFieldPresent/01/metadata.json +6 -0
- package/test-fixtures/reducers/copy/02 - doNotCopyIfFieldPresent/01/source.json +20 -0
- package/test-fixtures/reducers/copy/02 - doNotCopyIfFieldPresent/02/base.json +9 -0
- package/test-fixtures/reducers/copy/02 - doNotCopyIfFieldPresent/02/merged.json +20 -0
- package/test-fixtures/reducers/copy/02 - doNotCopyIfFieldPresent/02/metadata.json +6 -0
- package/test-fixtures/reducers/copy/02 - doNotCopyIfFieldPresent/02/source.json +20 -0
- package/test-fixtures/reducers/copy/03 - compareTagsOnly/01/base.json +24 -0
- package/test-fixtures/reducers/copy/03 - compareTagsOnly/01/merged.json +24 -0
- package/test-fixtures/reducers/copy/03 - compareTagsOnly/01/metadata.json +5 -0
- package/test-fixtures/reducers/copy/03 - compareTagsOnly/01/source.json +24 -0
- package/test-fixtures/reducers/copy/03 - compareTagsOnly/02/base.json +24 -0
- package/test-fixtures/reducers/copy/03 - compareTagsOnly/02/merged.json +100 -0
- package/test-fixtures/reducers/copy/03 - compareTagsOnly/02/metadata.json +5 -0
- package/test-fixtures/reducers/copy/03 - compareTagsOnly/02/source.json +100 -0
- package/test-fixtures/reducers/copy/04 - compareWithoutIndicators/01/base.json +24 -0
- package/test-fixtures/reducers/copy/04 - compareWithoutIndicators/01/merged.json +24 -0
- package/test-fixtures/reducers/copy/04 - compareWithoutIndicators/01/metadata.json +5 -0
- package/test-fixtures/reducers/copy/04 - compareWithoutIndicators/01/source.json +24 -0
- package/test-fixtures/reducers/copy/04 - compareWithoutIndicators/02/base.json +24 -0
- package/test-fixtures/reducers/copy/04 - compareWithoutIndicators/02/merged.json +39 -0
- package/test-fixtures/reducers/copy/04 - compareWithoutIndicators/02/metadata.json +5 -0
- package/test-fixtures/reducers/copy/04 - compareWithoutIndicators/02/source.json +24 -0
- package/test-fixtures/reducers/copy/04 - compareWithoutIndicators/03/metadata.json +6 -0
- package/test-fixtures/reducers/copy/04 - compareWithoutIndicators/04/base.json +20 -0
- package/test-fixtures/reducers/copy/04 - compareWithoutIndicators/04/merged.json +31 -0
- package/test-fixtures/reducers/copy/04 - compareWithoutIndicators/04/metadata.json +5 -0
- package/test-fixtures/reducers/copy/04 - compareWithoutIndicators/04/source.json +20 -0
- package/test-fixtures/reducers/copy/05 - copyUnless/01/base.json +9 -0
- package/test-fixtures/reducers/copy/05 - copyUnless/01/merged.json +24 -0
- package/test-fixtures/reducers/copy/05 - copyUnless/01/metadata.json +5 -0
- package/test-fixtures/reducers/copy/05 - copyUnless/01/source.json +47 -0
- package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/01/base.json +24 -0
- package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/01/merged.json +39 -0
- package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/01/metadata.json +5 -0
- package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/01/source.json +24 -0
- package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/02/base.json +24 -0
- package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/02/merged.json +24 -0
- package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/02/metadata.json +5 -0
- package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/02/source.json +24 -0
- package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/03/base.json +28 -0
- package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/03/merged.json +43 -0
- package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/03/metadata.json +5 -0
- package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/03/source.json +24 -0
- package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/04/base.json +28 -0
- package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/04/merged.json +28 -0
- package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/04/metadata.json +5 -0
- package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/04/source.json +24 -0
- package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/05/base.json +20 -0
- package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/05/merged.json +35 -0
- package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/05/metadata.json +5 -0
- package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/05/source.json +24 -0
- package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/06/base.json +20 -0
- package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/06/merged.json +35 -0
- package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/06/metadata.json +5 -0
- package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/06/source.json +24 -0
- package/test-fixtures/reducers/copy/07 - excludeSubfields/01/base.json +39 -0
- package/test-fixtures/reducers/copy/07 - excludeSubfields/01/merged.json +39 -0
- package/test-fixtures/reducers/copy/07 - excludeSubfields/01/metadata.json +8 -0
- package/test-fixtures/reducers/copy/{05/source.json → 07 - excludeSubfields/01/source.json } +1 -1
- package/test-fixtures/reducers/copy/07 - excludeSubfields/02/base.json +39 -0
- package/test-fixtures/reducers/copy/{05/merged.json → 07 - excludeSubfields/02/merged.json } +5 -5
- package/test-fixtures/reducers/copy/07 - excludeSubfields/02/metadata.json +5 -0
- package/test-fixtures/reducers/copy/07 - excludeSubfields/02/source.json +43 -0
- package/test-fixtures/reducers/copy/08 - dropSubfields/01/base.json +35 -0
- package/test-fixtures/reducers/copy/08 - dropSubfields/01/merged.json +54 -0
- package/test-fixtures/reducers/copy/08 - dropSubfields/01/metadata.json +5 -0
- package/test-fixtures/reducers/copy/08 - dropSubfields/01/source.json +43 -0
- package/test-fixtures/reducers/copy/08 - dropSubfields/02/base.json +43 -0
- package/test-fixtures/reducers/copy/08 - dropSubfields/02/merged.json +58 -0
- package/test-fixtures/reducers/copy/08 - dropSubfields/02/metadata.json +5 -0
- package/test-fixtures/reducers/copy/08 - dropSubfields/02/source.json +32 -0
- package/test-fixtures/reducers/copy/08 - dropSubfields/03/base.json +43 -0
- package/test-fixtures/reducers/copy/08 - dropSubfields/03/merged.json +58 -0
- package/test-fixtures/reducers/copy/08 - dropSubfields/03/metadata.json +5 -0
- package/test-fixtures/reducers/copy/08 - dropSubfields/03/source.json +32 -0
- package/test-fixtures/reducers/copy/08 - dropSubfields/04/base.json +43 -0
- package/test-fixtures/reducers/copy/08 - dropSubfields/04/merged.json +43 -0
- package/test-fixtures/reducers/copy/08 - dropSubfields/04/metadata.json +5 -0
- package/test-fixtures/reducers/copy/08 - dropSubfields/04/source.json +32 -0
- package/test-fixtures/reducers/copy/09 - swapSubfieldCode/01/base.json +9 -0
- package/test-fixtures/reducers/copy/09 - swapSubfieldCode/01/merged.json +20 -0
- package/test-fixtures/reducers/copy/09 - swapSubfieldCode/01/metadata.json +6 -0
- package/test-fixtures/reducers/copy/09 - swapSubfieldCode/01/source.json +20 -0
- package/test-fixtures/reducers/copy/09 - swapSubfieldCode/02/base.json +9 -0
- package/test-fixtures/reducers/copy/09 - swapSubfieldCode/02/merged.json +20 -0
- package/test-fixtures/reducers/copy/09 - swapSubfieldCode/02/metadata.json +6 -0
- package/test-fixtures/reducers/copy/09 - swapSubfieldCode/02/source.json +20 -0
- package/test-fixtures/reducers/copy/09 - swapSubfieldCode/03/base.json +9 -0
- package/test-fixtures/reducers/copy/09 - swapSubfieldCode/03/merged.json +31 -0
- package/test-fixtures/reducers/copy/09 - swapSubfieldCode/03/metadata.json +6 -0
- package/test-fixtures/reducers/copy/09 - swapSubfieldCode/03/source.json +31 -0
- package/test-fixtures/reducers/copy/09 - swapSubfieldCode/04/base.json +9 -0
- package/test-fixtures/reducers/copy/09 - swapSubfieldCode/04/merged.json +42 -0
- package/test-fixtures/reducers/copy/09 - swapSubfieldCode/04/metadata.json +6 -0
- package/test-fixtures/reducers/copy/09 - swapSubfieldCode/04/source.json +42 -0
- package/test-fixtures/reducers/copy/10 - swapTag/01/base.json +17 -0
- package/test-fixtures/reducers/copy/10 - swapTag/01/merged.json +28 -0
- package/test-fixtures/reducers/copy/10 - swapTag/01/metadata.json +6 -0
- package/test-fixtures/reducers/copy/10 - swapTag/01/source.json +20 -0
- package/test-fixtures/reducers/copy/11 - compareWithoutTag/01/base.json +28 -0
- package/test-fixtures/reducers/copy/11 - compareWithoutTag/01/merged.json +28 -0
- package/test-fixtures/reducers/copy/11 - compareWithoutTag/01/metadata.json +6 -0
- package/test-fixtures/reducers/copy/11 - compareWithoutTag/01/source.json +20 -0
- package/test-fixtures/reducers/copy/11 - compareWithoutTag/02/base.json +28 -0
- package/test-fixtures/reducers/copy/11 - compareWithoutTag/02/merged.json +39 -0
- package/test-fixtures/reducers/copy/11 - compareWithoutTag/02/metadata.json +6 -0
- package/test-fixtures/reducers/copy/11 - compareWithoutTag/02/source.json +31 -0
- package/test-fixtures/reducers/copy/11 - compareWithoutTag/03/base.json +28 -0
- package/test-fixtures/reducers/copy/11 - compareWithoutTag/03/merged.json +28 -0
- package/test-fixtures/reducers/copy/11 - compareWithoutTag/03/metadata.json +7 -0
- package/test-fixtures/reducers/copy/11 - compareWithoutTag/03/source.json +20 -0
- package/test-fixtures/reducers/copy/11 - compareWithoutTag/04/base.json +17 -0
- package/test-fixtures/reducers/copy/11 - compareWithoutTag/04/merged.json +28 -0
- package/test-fixtures/reducers/copy/11 - compareWithoutTag/04/metadata.json +7 -0
- package/test-fixtures/reducers/copy/11 - compareWithoutTag/04/source.json +31 -0
- package/test-fixtures/reducers/copy/11 - compareWithoutTag/05/base.json +28 -0
- package/test-fixtures/reducers/copy/11 - compareWithoutTag/05/merged.json +28 -0
- package/test-fixtures/reducers/copy/11 - compareWithoutTag/05/metadata.json +7 -0
- package/test-fixtures/reducers/copy/11 - compareWithoutTag/05/source.json +28 -0
- package/test-fixtures/reducers/metadata.json +4 -0
- package/test-fixtures/reducers/select/01/metadata.json +5 -0
- package/test-fixtures/reducers/select/02/metadata.json +4 -0
- package/test-fixtures/reducers/select/03/metadata.json +4 -0
- package/test-fixtures/reducers/select/04/metadata.json +5 -0
- package/test-fixtures/reducers/select/05/metadata.json +4 -0
- package/test-fixtures/reducers/select/06/base.json +4 -0
- package/test-fixtures/reducers/select/06/merged.json +4 -0
- package/test-fixtures/reducers/select/06/metadata.json +4 -0
- package/test-fixtures/reducers/select/06/source.json +4 -0
- package/test-fixtures/reducers/select/07/metadata.json +5 -0
- package/test-fixtures/reducers/select/08/metadata.json +4 -0
- package/test-fixtures/reducers/select/09/metadata.json +4 -0
- package/test-fixtures/reducers/select/10/metadata.json +5 -0
- package/test-fixtures/reducers/select/11/metadata.json +4 -0
- package/test-fixtures/reducers/select/12/metadata.json +5 -0
- package/test-fixtures/reducers/select/13/metadata.json +4 -0
- package/test-fixtures/reducers/select/14/base.json +24 -0
- package/test-fixtures/reducers/select/14/merged.json +24 -0
- package/test-fixtures/reducers/select/14/metadata.json +4 -0
- package/test-fixtures/reducers/select/14/source.json +24 -0
- package/.drone.yml +0 -92
- package/.nyc_output/7ecda3cd-9f84-4416-a466-fa1e5889c6a3.json +0 -1
- package/.nyc_output/processinfo/7ecda3cd-9f84-4416-a466-fa1e5889c6a3.json +0 -1
- package/.nyc_output/processinfo/index.json +0 -1
- package/LICENSE.txt +0 -165
- package/coverage/base.css +0 -224
- package/coverage/block-navigation.js +0 -79
- package/coverage/copy.js.html +0 -344
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +0 -126
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -79
- package/coverage/lcov-report/copy.js.html +0 -344
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -126
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/select.js.html +0 -431
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -170
- package/coverage/lcov.info +0 -195
- package/coverage/prettify.css +0 -1
- package/coverage/prettify.js +0 -2
- package/coverage/select.js.html +0 -431
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +0 -170
- package/test-fixtures/reducers/copy/01/pattern.txt +0 -1
- package/test-fixtures/reducers/copy/02/pattern.txt +0 -1
- package/test-fixtures/reducers/copy/03/pattern.txt +0 -1
- package/test-fixtures/reducers/copy/04/pattern.txt +0 -1
- package/test-fixtures/reducers/copy/05/pattern.txt +0 -1
- package/test-fixtures/reducers/select/01/expected-error.txt +0 -1
- package/test-fixtures/reducers/select/01/pattern.txt +0 -1
- package/test-fixtures/reducers/select/02/pattern.txt +0 -1
- package/test-fixtures/reducers/select/03/pattern.txt +0 -1
- package/test-fixtures/reducers/select/04/pattern.txt +0 -1
- package/test-fixtures/reducers/select/05/pattern.txt +0 -1
- package/test-fixtures/reducers/select/06/pattern.txt +0 -1
- package/test-fixtures/reducers/select/07/equalityFunction.txt +0 -1
- package/test-fixtures/reducers/select/07/pattern.txt +0 -1
- package/test-fixtures/reducers/select/08/pattern.txt +0 -1
- package/test-fixtures/reducers/select/09/pattern.txt +0 -1
- package/test-fixtures/reducers/select/10/equalityFunction.txt +0 -1
- package/test-fixtures/reducers/select/10/pattern.txt +0 -1
- package/test-fixtures/reducers/select/11/pattern.txt +0 -1
- package/test-fixtures/reducers/select/12/equalityFunction.txt +0 -1
- package/test-fixtures/reducers/select/12/pattern.txt +0 -1
- package/test-fixtures/reducers/select/13/pattern.txt +0 -1
package/dist/reducers/select.js
CHANGED
|
@@ -3,67 +3,49 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.default = void 0;
|
|
6
7
|
exports.strictEquality = strictEquality;
|
|
7
8
|
exports.subsetEquality = subsetEquality;
|
|
8
|
-
exports.default = void 0;
|
|
9
|
-
|
|
10
9
|
var _normalizeDiacritics = require("normalize-diacritics");
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
* @licstart The following is the entire license notice for the JavaScript code in this file.
|
|
15
|
-
*
|
|
16
|
-
* Merge MARC records
|
|
17
|
-
*
|
|
18
|
-
* Copyright (C) 2015-2019 University Of Helsinki (The National Library Of Finland)
|
|
19
|
-
*
|
|
20
|
-
* This file is part of marc-record-merge-js
|
|
21
|
-
|
|
22
|
-
* marc-record-merge-js program is free software: you can redistribute it and/or modify
|
|
23
|
-
* it under the terms of the GNU Lesser General Public License as
|
|
24
|
-
* published by the Free Software Foundation, either version 3 of the
|
|
25
|
-
* License, or (at your option) any later version.
|
|
26
|
-
*
|
|
27
|
-
* marc-record-merge-js is distributed in the hope that it will be useful,
|
|
28
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
29
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
30
|
-
* GNU Lesser General Public License for more details.
|
|
31
|
-
*
|
|
32
|
-
* You should have received a copy of the GNU Lesser General Public License
|
|
33
|
-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
34
|
-
*
|
|
35
|
-
* @licend The above is the entire license notice
|
|
36
|
-
* for the JavaScript code in this file.
|
|
37
|
-
*
|
|
38
|
-
*/
|
|
10
|
+
var _debug = _interopRequireDefault(require("debug"));
|
|
11
|
+
var _marcRecord = require("@natlibfi/marc-record");
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
39
13
|
function strictEquality(subfieldA, subfieldB) {
|
|
40
14
|
return subfieldA.code === subfieldB.code && subfieldA.value === subfieldB.value;
|
|
41
15
|
}
|
|
42
|
-
|
|
43
16
|
function subsetEquality(subfieldA, subfieldB) {
|
|
44
17
|
return subfieldA.code === subfieldB.code && (subfieldA.value.indexOf(subfieldB.value) !== -1 || subfieldB.value.indexOf(subfieldA.value) !== -1);
|
|
45
18
|
}
|
|
46
|
-
|
|
19
|
+
// EqualityFunction can be either strictEquality or subsetEquality
|
|
47
20
|
var _default = ({
|
|
48
|
-
|
|
21
|
+
tagPattern,
|
|
49
22
|
equalityFunction = strictEquality
|
|
50
23
|
}) => (base, source) => {
|
|
51
|
-
const
|
|
52
|
-
const
|
|
24
|
+
const debug = (0, _debug.default)('@natlibfi/marc-record-merge:select');
|
|
25
|
+
const baseRecord = new _marcRecord.MarcRecord(base, {
|
|
26
|
+
subfieldValues: false
|
|
27
|
+
});
|
|
28
|
+
const sourceRecord = new _marcRecord.MarcRecord(source, {
|
|
29
|
+
subfieldValues: false
|
|
30
|
+
});
|
|
31
|
+
const baseFields = baseRecord.get(tagPattern);
|
|
32
|
+
const sourceFields = sourceRecord.get(tagPattern);
|
|
33
|
+
const fieldTag = sourceFields.map(field => field.tag);
|
|
34
|
+
debug(`Comparing field ${fieldTag}`);
|
|
53
35
|
checkFieldType(baseFields);
|
|
54
36
|
checkFieldType(sourceFields);
|
|
55
|
-
|
|
56
37
|
if (baseFields.length > 1 || sourceFields.length > 1) {
|
|
38
|
+
debug(`Multiple fields in base or source`);
|
|
39
|
+
debug(`No changes to base`);
|
|
57
40
|
return base;
|
|
58
41
|
}
|
|
59
|
-
|
|
60
42
|
const [baseField] = baseFields;
|
|
61
43
|
const [sourceField] = sourceFields;
|
|
62
|
-
|
|
63
44
|
if (baseField.tag === sourceField.tag === false) {
|
|
45
|
+
debug(`Base tag ${baseField.tag} is not equal to source tag ${sourceField.tag}`);
|
|
46
|
+
debug(`No changes to base`);
|
|
64
47
|
return base;
|
|
65
48
|
}
|
|
66
|
-
|
|
67
49
|
const baseSubs = baseField.subfields;
|
|
68
50
|
const sourceSubs = sourceField.subfields;
|
|
69
51
|
const baseSubsNormalized = baseSubs.map(({
|
|
@@ -80,57 +62,57 @@ var _default = ({
|
|
|
80
62
|
code,
|
|
81
63
|
value: normalizeSubfieldValue(value)
|
|
82
64
|
}));
|
|
65
|
+
|
|
66
|
+
// Returns the base subfields for which a matching source subfield is found
|
|
83
67
|
const equalSubfieldsBase = baseSubsNormalized.filter(baseSubfield => sourceSubsNormalized.some(sourceSubfield => equalityFunction(baseSubfield, sourceSubfield)));
|
|
84
|
-
|
|
68
|
+
debug(`equalSubfieldsBase: ${JSON.stringify(equalSubfieldsBase, undefined, 2)}`);
|
|
85
69
|
|
|
70
|
+
// Returns the source subfields for which a matching base subfield is found
|
|
71
|
+
const equalSubfieldsSource = sourceSubsNormalized.filter(sourceSubfield => baseSubsNormalized.some(baseSubfield => equalityFunction(sourceSubfield, baseSubfield)));
|
|
72
|
+
debug(`equalSubfieldsSource: ${JSON.stringify(equalSubfieldsSource, undefined, 2)}`);
|
|
86
73
|
if (baseSubs.length === sourceSubs.length && equalSubfieldsBase.length < baseSubs.length) {
|
|
74
|
+
debug(`Base and source subfields are not equal`);
|
|
75
|
+
debug(`No changes to base`);
|
|
87
76
|
return base;
|
|
88
77
|
}
|
|
89
|
-
|
|
90
78
|
if (baseSubs.length === sourceSubs.length && equalSubfieldsBase.length === equalSubfieldsSource.length) {
|
|
79
|
+
debug(`Checking subfield equality`);
|
|
91
80
|
const totalSubfieldLengthBase = baseSubsNormalized.map(({
|
|
92
81
|
value
|
|
93
82
|
}) => value.length).reduce((acc, value) => acc + value);
|
|
94
83
|
const totalSubfieldLengthSource = sourceSubsNormalized.map(({
|
|
95
84
|
value
|
|
96
85
|
}) => value.length).reduce((acc, value) => acc + value);
|
|
97
|
-
|
|
98
86
|
if (totalSubfieldLengthSource > totalSubfieldLengthBase) {
|
|
99
87
|
return replaceBasefieldWithSourcefield(base);
|
|
100
88
|
}
|
|
101
89
|
}
|
|
102
|
-
|
|
103
90
|
if (sourceSubs.length > baseSubs.length && equalSubfieldsBase.length === baseSubs.length) {
|
|
104
91
|
return replaceBasefieldWithSourcefield(base);
|
|
105
92
|
}
|
|
106
|
-
|
|
93
|
+
debug(`No changes to base`);
|
|
107
94
|
return base;
|
|
108
|
-
|
|
109
95
|
function replaceBasefieldWithSourcefield(base) {
|
|
110
96
|
const index = base.fields.findIndex(field => field === baseField);
|
|
111
97
|
base.fields.splice(index, 1, sourceField); // eslint-disable-line functional/immutable-data
|
|
112
|
-
|
|
98
|
+
debug(`Source field is longer, replacing base with source`);
|
|
113
99
|
return base;
|
|
114
100
|
}
|
|
115
|
-
|
|
116
101
|
function checkFieldType(fields) {
|
|
117
102
|
const checkedFields = fields.map(field => {
|
|
118
103
|
if ('value' in field) {
|
|
119
104
|
// eslint-disable-line functional/no-conditional-statement
|
|
120
105
|
throw new Error('Invalid control field, expected data field');
|
|
121
106
|
}
|
|
122
|
-
|
|
123
107
|
return field;
|
|
124
108
|
});
|
|
125
109
|
return checkedFields;
|
|
126
110
|
}
|
|
127
|
-
|
|
128
111
|
function normalizeSubfieldValue(value) {
|
|
129
112
|
// Regexp options: g: global search, u: unicode
|
|
130
|
-
const punctuation = /[
|
|
113
|
+
const punctuation = /[.,\-/#!?$%^&*;:{}=_`~()[\]]/gu;
|
|
131
114
|
return (0, _normalizeDiacritics.normalizeSync)(value).toLowerCase().replace(punctuation, '', 'u').replace(/\s+/gu, ' ').trim();
|
|
132
115
|
}
|
|
133
116
|
};
|
|
134
|
-
|
|
135
117
|
exports.default = _default;
|
|
136
118
|
//# sourceMappingURL=select.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"select.js","names":["strictEquality","subfieldA","subfieldB","code","value","subsetEquality","indexOf","tagPattern","equalityFunction","base","source","debug","createDebugLogger","baseRecord","MarcRecord","subfieldValues","sourceRecord","baseFields","get","sourceFields","fieldTag","map","field","tag","checkFieldType","length","baseField","sourceField","baseSubs","subfields","sourceSubs","baseSubsNormalized","normalizeSubfieldValue","sourceSubsNormalized","equalSubfieldsBase","filter","baseSubfield","some","sourceSubfield","JSON","stringify","undefined","equalSubfieldsSource","totalSubfieldLengthBase","reduce","acc","totalSubfieldLengthSource","replaceBasefieldWithSourcefield","index","fields","findIndex","splice","checkedFields","Error","punctuation","normalizeSync","toLowerCase","replace","trim"],"sources":["../../src/reducers/select.js"],"sourcesContent":["import {normalizeSync} from 'normalize-diacritics';\nimport createDebugLogger from 'debug';\nimport {MarcRecord} from '@natlibfi/marc-record';\n\nexport function strictEquality(subfieldA, subfieldB) {\n return subfieldA.code === subfieldB.code &&\n subfieldA.value === subfieldB.value;\n}\n\nexport function subsetEquality(subfieldA, subfieldB) {\n return subfieldA.code === subfieldB.code &&\n (subfieldA.value.indexOf(subfieldB.value) !== -1 || subfieldB.value.indexOf(subfieldA.value) !== -1);\n}\n// EqualityFunction can be either strictEquality or subsetEquality\nexport default ({tagPattern, equalityFunction = strictEquality}) => (base, source) => {\n const debug = createDebugLogger('@natlibfi/marc-record-merge:select');\n const baseRecord = new MarcRecord(base, {subfieldValues: false});\n const sourceRecord = new MarcRecord(source, {subfieldValues: false});\n const baseFields = baseRecord.get(tagPattern);\n const sourceFields = sourceRecord.get(tagPattern);\n const fieldTag = sourceFields.map(field => field.tag);\n debug(`Comparing field ${fieldTag}`);\n\n checkFieldType(baseFields);\n checkFieldType(sourceFields);\n\n if (baseFields.length > 1 || sourceFields.length > 1) {\n debug(`Multiple fields in base or source`);\n debug(`No changes to base`);\n return base;\n }\n const [baseField] = baseFields;\n const [sourceField] = sourceFields;\n\n if (baseField.tag === sourceField.tag === false) {\n debug(`Base tag ${baseField.tag} is not equal to source tag ${sourceField.tag}`);\n debug(`No changes to base`);\n return base;\n }\n const baseSubs = baseField.subfields;\n const sourceSubs = sourceField.subfields;\n\n const baseSubsNormalized = baseSubs\n .map(({code, value}) => ({code, value: normalizeSubfieldValue(value)}));\n\n const sourceSubsNormalized = sourceSubs\n .map(({code, value}) => ({code, value: normalizeSubfieldValue(value)}));\n\n // Returns the base subfields for which a matching source subfield is found\n const equalSubfieldsBase = baseSubsNormalized\n .filter(baseSubfield => sourceSubsNormalized\n .some(sourceSubfield => equalityFunction(baseSubfield, sourceSubfield)));\n debug(`equalSubfieldsBase: ${JSON.stringify(equalSubfieldsBase, undefined, 2)}`);\n\n // Returns the source subfields for which a matching base subfield is found\n const equalSubfieldsSource = sourceSubsNormalized\n .filter(sourceSubfield => baseSubsNormalized\n .some(baseSubfield => equalityFunction(sourceSubfield, baseSubfield)));\n debug(`equalSubfieldsSource: ${JSON.stringify(equalSubfieldsSource, undefined, 2)}`);\n\n if (baseSubs.length === sourceSubs.length && equalSubfieldsBase.length < baseSubs.length) {\n debug(`Base and source subfields are not equal`);\n debug(`No changes to base`);\n return base;\n }\n\n if (baseSubs.length === sourceSubs.length && equalSubfieldsBase.length === equalSubfieldsSource.length) {\n debug(`Checking subfield equality`);\n const totalSubfieldLengthBase = baseSubsNormalized\n .map(({value}) => value.length)\n .reduce((acc, value) => acc + value);\n const totalSubfieldLengthSource = sourceSubsNormalized\n .map(({value}) => value.length)\n .reduce((acc, value) => acc + value);\n\n if (totalSubfieldLengthSource > totalSubfieldLengthBase) {\n return replaceBasefieldWithSourcefield(base);\n }\n }\n\n if (sourceSubs.length > baseSubs.length && equalSubfieldsBase.length === baseSubs.length) {\n return replaceBasefieldWithSourcefield(base);\n }\n\n debug(`No changes to base`);\n return base;\n\n function replaceBasefieldWithSourcefield(base) {\n const index = base.fields.findIndex(field => field === baseField);\n base.fields.splice(index, 1, sourceField); // eslint-disable-line functional/immutable-data\n debug(`Source field is longer, replacing base with source`);\n return base;\n }\n\n function checkFieldType(fields) {\n const checkedFields = fields.map(field => {\n if ('value' in field) { // eslint-disable-line functional/no-conditional-statement\n throw new Error('Invalid control field, expected data field');\n }\n return field;\n });\n return checkedFields;\n }\n\n function normalizeSubfieldValue(value) {\n // Regexp options: g: global search, u: unicode\n const punctuation = /[.,\\-/#!?$%^&*;:{}=_`~()[\\]]/gu;\n return normalizeSync(value).toLowerCase().replace(punctuation, '', 'u').replace(/\\s+/gu, ' ').trim();\n }\n};\n"],"mappings":";;;;;;;;AAAA;AACA;AACA;AAAiD;AAE1C,SAASA,cAAc,CAACC,SAAS,EAAEC,SAAS,EAAE;EACnD,OAAOD,SAAS,CAACE,IAAI,KAAKD,SAAS,CAACC,IAAI,IACtCF,SAAS,CAACG,KAAK,KAAKF,SAAS,CAACE,KAAK;AACvC;AAEO,SAASC,cAAc,CAACJ,SAAS,EAAEC,SAAS,EAAE;EACnD,OAAOD,SAAS,CAACE,IAAI,KAAKD,SAAS,CAACC,IAAI,KACrCF,SAAS,CAACG,KAAK,CAACE,OAAO,CAACJ,SAAS,CAACE,KAAK,CAAC,KAAK,CAAC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EA,SAASe,cAAc,CAACyB,MAAM,EAAE;IAC9B,MAAMG,aAAa,GAAGH,MAAM,CAAC5B,GAAG,CAACC,KAAK,IAAI;MACxC,IAAI,OAAO,IAAIA,KAAK,EAAE;QAAE;QACtB,MAAM,IAAI+B,KAAK,CAAC,4CAA4C,CAAC;MAC/D;MACA,OAAO/B,KAAK;IACd,CAAC,CAAC;IACF,OAAO8B,aAAa;EACtB;EAEA,SAASpB,sBAAsB,CAAC5B,KAAK,EAAE;IACrC;IACA,MAAMkD,WAAW,GAAG,gCAAgC;IACpD,OAAO,IAAAC,kCAAa,EAACnD,KAAK,CAAC,CAACoD,WAAW,EAAE,CAACC,OAAO,CAACH,WAAW,EAAE,EAAE,EAAE,GAAG,CAAC,CAACG,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAACC,IAAI,EAAE;EACtG;AACF,CAAC;AAAA"}
|
|
@@ -1,102 +1,55 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _chai =
|
|
4
|
-
|
|
5
|
-
var _fs = _interopRequireDefault(require("fs"));
|
|
6
|
-
|
|
7
|
-
var _path = _interopRequireDefault(require("path"));
|
|
8
|
-
|
|
3
|
+
var _chai = require("chai");
|
|
9
4
|
var _marcRecord = require("@natlibfi/marc-record");
|
|
10
|
-
|
|
11
5
|
var _select = _interopRequireWildcard(require("./select"));
|
|
12
|
-
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
16
|
-
|
|
17
|
-
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (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; }
|
|
18
|
-
|
|
6
|
+
var _fixura = require("@natlibfi/fixura");
|
|
7
|
+
var _fixugen = _interopRequireDefault(require("@natlibfi/fixugen"));
|
|
19
8
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
*
|
|
23
|
-
* @licstart The following is the entire license notice for the JavaScript code in this file.
|
|
24
|
-
*
|
|
25
|
-
* Merge MARC records
|
|
26
|
-
*
|
|
27
|
-
* Copyright (C) 2015-2019 University Of Helsinki (The National Library Of Finland)
|
|
28
|
-
*
|
|
29
|
-
* This file is part of marc-record-merge-js
|
|
30
|
-
|
|
31
|
-
* marc-record-merge-js program is free software: you can redistribute it and/or modify
|
|
32
|
-
* it under the terms of the GNU Lesser General Public License as
|
|
33
|
-
* published by the Free Software Foundation, either version 3 of the
|
|
34
|
-
* License, or (at your option) any later version.
|
|
35
|
-
*
|
|
36
|
-
* marc-record-merge-js is distributed in the hope that it will be useful,
|
|
37
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
38
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
39
|
-
* GNU Lesser General Public License for more details.
|
|
40
|
-
*
|
|
41
|
-
* You should have received a copy of the GNU Lesser General Public License
|
|
42
|
-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
43
|
-
*
|
|
44
|
-
* @licend The above is the entire license notice
|
|
45
|
-
* for the JavaScript code in this file.
|
|
46
|
-
*
|
|
47
|
-
*/
|
|
9
|
+
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); }
|
|
10
|
+
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; }
|
|
48
11
|
_marcRecord.MarcRecord.setValidationOptions({
|
|
49
12
|
subfieldValues: false
|
|
50
13
|
});
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const {
|
|
61
|
-
getFixture
|
|
62
|
-
} = (0, _fixura.default)({
|
|
63
|
-
root: [fixturesPath, subDir],
|
|
64
|
-
reader: _fixura.READERS.JSON,
|
|
65
|
-
failWhenNotFound: false
|
|
66
|
-
});
|
|
67
|
-
it(subDir, () => {
|
|
68
|
-
const baseTest = new _marcRecord.MarcRecord(getFixture('base.json'));
|
|
69
|
-
const sourceTest = new _marcRecord.MarcRecord(getFixture('source.json'));
|
|
70
|
-
const patternTest = new RegExp(getFixture({
|
|
71
|
-
components: ['pattern.txt'],
|
|
72
|
-
reader: _fixura.READERS.TEXT
|
|
73
|
-
}), 'u');
|
|
74
|
-
const expectedRecord = getFixture('merged.json');
|
|
75
|
-
const expectedError = getFixture({
|
|
76
|
-
components: ['expected-error.txt'],
|
|
77
|
-
reader: _fixura.READERS.TEXT
|
|
78
|
-
});
|
|
79
|
-
const equalityFunction = getEqualityFunction();
|
|
80
|
-
|
|
81
|
-
if (expectedError) {
|
|
82
|
-
expect(() => _select.default.to.throw(Error, 'control field'));
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const mergedRecord = (0, _select.default)({
|
|
87
|
-
pattern: patternTest,
|
|
88
|
-
equalityFunction
|
|
89
|
-
})(baseTest, sourceTest);
|
|
90
|
-
expect(mergedRecord.toObject()).to.eql(expectedRecord);
|
|
91
|
-
|
|
92
|
-
function getEqualityFunction() {
|
|
93
|
-
const functionName = getFixture({
|
|
94
|
-
components: ['equalityFunction.txt'],
|
|
95
|
-
reader: _fixura.READERS.TEXT
|
|
96
|
-
});
|
|
97
|
-
return functionName === 'subsetEquality' ? _select.subsetEquality : undefined;
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
});
|
|
14
|
+
(0, _fixugen.default)({
|
|
15
|
+
callback,
|
|
16
|
+
path: [__dirname, '..', '..', 'test-fixtures', 'reducers', 'select'],
|
|
17
|
+
useMetadataFile: true,
|
|
18
|
+
recurse: false,
|
|
19
|
+
fixura: {
|
|
20
|
+
reader: _fixura.READERS.JSON,
|
|
21
|
+
failWhenNotFound: false
|
|
22
|
+
}
|
|
101
23
|
});
|
|
24
|
+
function callback({
|
|
25
|
+
getFixture,
|
|
26
|
+
disabled = false,
|
|
27
|
+
tagPatternRegExp = false,
|
|
28
|
+
expectedError = false,
|
|
29
|
+
useSubsetEquality = false
|
|
30
|
+
}) {
|
|
31
|
+
if (disabled) {
|
|
32
|
+
console.log('TEST DISABLED!'); // eslint-disable-line no-console
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
// const base = new MarcRecord(getFixture('base.json'), {subfieldValues: false});
|
|
36
|
+
// const source = new MarcRecord(getFixture('source.json'), {subfieldValues: false});
|
|
37
|
+
|
|
38
|
+
const base = getFixture('base.json');
|
|
39
|
+
const source = getFixture('source.json');
|
|
40
|
+
const tagPattern = new RegExp(tagPatternRegExp, 'u');
|
|
41
|
+
const expectedRecord = getFixture('merged.json');
|
|
42
|
+
const equalityFunction = useSubsetEquality ? _select.subsetEquality : undefined;
|
|
43
|
+
|
|
44
|
+
// Bypass expected error in testing
|
|
45
|
+
if (expectedError) {
|
|
46
|
+
(0, _chai.expect)(() => _select.default.to.throw(Error, 'control field'));
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const mergedRecord = (0, _select.default)({
|
|
50
|
+
tagPattern,
|
|
51
|
+
equalityFunction
|
|
52
|
+
})(base, source);
|
|
53
|
+
(0, _chai.expect)(mergedRecord).to.eql(expectedRecord);
|
|
54
|
+
}
|
|
102
55
|
//# sourceMappingURL=select.spec.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"select.spec.js","names":["MarcRecord","setValidationOptions","subfieldValues","generateTests","callback","path","__dirname","useMetadataFile","recurse","fixura","reader","READERS","JSON","failWhenNotFound","getFixture","disabled","tagPatternRegExp","expectedError","useSubsetEquality","console","log","base","source","tagPattern","RegExp","expectedRecord","equalityFunction","subsetEquality","undefined","expect","createReducer","to","throw","Error","mergedRecord","eql"],"sources":["../../src/reducers/select.spec.js"],"sourcesContent":["import {expect} from 'chai';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport createReducer, {subsetEquality} from './select';\nimport {READERS} from '@natlibfi/fixura';\nimport generateTests from '@natlibfi/fixugen';\n\nMarcRecord.setValidationOptions({subfieldValues: false});\n\ngenerateTests({\n callback,\n path: [__dirname, '..', '..', 'test-fixtures', 'reducers', 'select'],\n useMetadataFile: true,\n recurse: false,\n fixura: {\n reader: READERS.JSON,\n failWhenNotFound: false\n }\n});\n\nfunction callback({\n getFixture,\n disabled = false,\n tagPatternRegExp = false,\n expectedError = false,\n useSubsetEquality = false\n}) {\n if (disabled) {\n console.log('TEST DISABLED!'); // eslint-disable-line no-console\n return;\n }\n // const base = new MarcRecord(getFixture('base.json'), {subfieldValues: false});\n // const source = new MarcRecord(getFixture('source.json'), {subfieldValues: false});\n\n const base = getFixture('base.json');\n const source = getFixture('source.json');\n\n const tagPattern = new RegExp(tagPatternRegExp, 'u');\n const expectedRecord = getFixture('merged.json');\n const equalityFunction = useSubsetEquality ? subsetEquality : undefined;\n\n // Bypass expected error in testing\n if (expectedError) {\n expect(() => createReducer.to.throw(Error, 'control field'));\n return;\n }\n\n const mergedRecord = createReducer({tagPattern, equalityFunction})(base, source);\n expect(mergedRecord).to.eql(expectedRecord);\n}\n"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AAA8C;AAAA;AAAA;AAE9CA,sBAAU,CAACC,oBAAoB,CAAC;EAACC,cAAc,EAAE;AAAK,CAAC,CAAC;AAExD,IAAAC,gBAAa,EAAC;EACZC,QAAQ;EACRC,IAAI,EAAE,CAACC,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,eAAe,EAAE,UAAU,EAAE,QAAQ,CAAC;EACpEC,eAAe,EAAE,IAAI;EACrBC,OAAO,EAAE,KAAK;EACdC,MAAM,EAAE;IACNC,MAAM,EAAEC,eAAO,CAACC,IAAI;IACpBC,gBAAgB,EAAE;EACpB;AACF,CAAC,CAAC;AAEF,SAAST,QAAQ,CAAC;EAChBU,UAAU;EACVC,QAAQ,GAAG,KAAK;EAChBC,gBAAgB,GAAG,KAAK;EACxBC,aAAa,GAAG,KAAK;EACrBC,iBAAiB,GAAG;AACtB,CAAC,EAAE;EACD,IAAIH,QAAQ,EAAE;IACZI,OAAO,CAACC,GAAG,CAAC,gBAAgB,CAAC,CAAC,CAAC;IAC/B;EACF;EACA;EACA;;EAEA,MAAMC,IAAI,GAAGP,UAAU,CAAC,WAAW,CAAC;EACpC,MAAMQ,MAAM,GAAGR,UAAU,CAAC,aAAa,CAAC;EAExC,MAAMS,UAAU,GAAG,IAAIC,MAAM,CAACR,gBAAgB,EAAE,GAAG,CAAC;EACpD,MAAMS,cAAc,GAAGX,UAAU,CAAC,aAAa,CAAC;EAChD,MAAMY,gBAAgB,GAAGR,iBAAiB,GAAGS,sBAAc,GAAGC,SAAS;;EAEvE;EACA,IAAIX,aAAa,EAAE;IACjB,IAAAY,YAAM,EAAC,MAAMC,eAAa,CAACC,EAAE,CAACC,KAAK,CAACC,KAAK,EAAE,eAAe,CAAC,CAAC;IAC5D;EACF;EAEA,MAAMC,YAAY,GAAG,IAAAJ,eAAa,EAAC;IAACP,UAAU;IAAEG;EAAgB,CAAC,CAAC,CAACL,IAAI,EAAEC,MAAM,CAAC;EAChF,IAAAO,YAAM,EAACK,YAAY,CAAC,CAACH,EAAE,CAACI,GAAG,CAACV,cAAc,CAAC;AAC7C"}
|
package/package.json
CHANGED
|
@@ -13,46 +13,50 @@
|
|
|
13
13
|
"type": "git",
|
|
14
14
|
"url": "git@github.com:natlibfi/marc-record-merge-js.git"
|
|
15
15
|
},
|
|
16
|
-
"license": "
|
|
17
|
-
"version": "6.0.0-beta.
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"version": "6.0.0-beta.10",
|
|
18
18
|
"main": "./dist/index.js",
|
|
19
19
|
"engines": {
|
|
20
|
-
"node": ">=
|
|
20
|
+
"node": ">=14"
|
|
21
21
|
},
|
|
22
|
+
"type": "commonjs",
|
|
22
23
|
"scripts": {
|
|
24
|
+
"prepare": "npm run build",
|
|
23
25
|
"prepublishOnly": "npm run build:transpile",
|
|
24
|
-
"check-deps": "npm-check;exit 0",
|
|
25
26
|
"lint": "eslint ./src",
|
|
26
27
|
"lint:dev": "eslint ./src --fix",
|
|
27
|
-
"test:base": "cross-env NODE_ENV=test
|
|
28
|
-
"test": "npm run lint && npm run test:base
|
|
29
|
-
"test:dev": "npm run lint:dev && npm run
|
|
30
|
-
"coverage": "
|
|
28
|
+
"test:base": "cross-env NODE_ENV=test mocha --require @babel/register --reporter-option maxDiffSize=15000 src/reducers/*.spec.js",
|
|
29
|
+
"test": "npm run lint && npm run test:base",
|
|
30
|
+
"test:dev": "npm run lint:dev && npm run coverage",
|
|
31
|
+
"coverage": "npm run coverage:unit && npm run coverage:report",
|
|
32
|
+
"coverage:unit": "nyc --silent npm run test:base",
|
|
33
|
+
"coverage:report": "nyc report",
|
|
31
34
|
"build:transpile": "babel src --copy-files --source-maps --delete-dir-on-start --out-dir=dist",
|
|
32
|
-
"build": "npm run build:transpile
|
|
33
|
-
"
|
|
35
|
+
"build": "npm run build:transpile",
|
|
36
|
+
"dev:test": "cross-env NODE_ENV=test nodemon -w src -w test-fixtures --exec 'clear && npm run test:dev'",
|
|
37
|
+
"dev:test:debug": "cross-env DEBUG=@natlibfi/* NODE_ENV=test nodemon -w src -w test-fixtures --exec 'clear && npm run test:dev'"
|
|
34
38
|
},
|
|
35
39
|
"dependencies": {
|
|
36
|
-
"@natlibfi/
|
|
37
|
-
"@natlibfi/
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
+
"@natlibfi/fixugen": "1.1.0",
|
|
41
|
+
"@natlibfi/fixura": "^2.2.1",
|
|
42
|
+
"@natlibfi/marc-record": "^7.1.0-alpha.2",
|
|
43
|
+
"debug": "^4.3.4",
|
|
44
|
+
"normalize-diacritics": "2.14.0"
|
|
40
45
|
},
|
|
41
46
|
"devDependencies": {
|
|
42
|
-
"@babel/cli": "^7.10
|
|
43
|
-
"@babel/core": "^7.
|
|
44
|
-
"@babel/
|
|
45
|
-
"@babel/
|
|
46
|
-
"@
|
|
47
|
-
"
|
|
48
|
-
"babel-plugin-istanbul": "^6.
|
|
47
|
+
"@babel/cli": "^7.17.10",
|
|
48
|
+
"@babel/core": "^7.18.5",
|
|
49
|
+
"@babel/eslint-parser": "^7.18.2",
|
|
50
|
+
"@babel/preset-env": "^7.18.2",
|
|
51
|
+
"@babel/register": "^7.17.7",
|
|
52
|
+
"@natlibfi/eslint-config-melinda-backend": "^2.0.0",
|
|
53
|
+
"babel-plugin-istanbul": "^6.1.1",
|
|
49
54
|
"babel-plugin-rewire": "^1.2.0",
|
|
50
|
-
"chai": "^4.
|
|
51
|
-
"cross-env": "^7.0.
|
|
52
|
-
"eslint": "^
|
|
53
|
-
"mocha": "^
|
|
54
|
-
"nodemon": "^2.0.
|
|
55
|
-
"npm-check": "^5.9.0",
|
|
55
|
+
"chai": "^4.3.6",
|
|
56
|
+
"cross-env": "^7.0.3",
|
|
57
|
+
"eslint": "^8.17.0",
|
|
58
|
+
"mocha": "^10.0.0",
|
|
59
|
+
"nodemon": "^2.0.16",
|
|
56
60
|
"nyc": "^15.1.0"
|
|
57
61
|
},
|
|
58
62
|
"eslintConfig": {
|
|
@@ -65,9 +69,7 @@
|
|
|
65
69
|
[
|
|
66
70
|
"@babel/preset-env",
|
|
67
71
|
{
|
|
68
|
-
"targets":
|
|
69
|
-
"node": "12"
|
|
70
|
-
}
|
|
72
|
+
"targets": "maintained node versions"
|
|
71
73
|
}
|
|
72
74
|
]
|
|
73
75
|
],
|
|
@@ -86,8 +88,7 @@
|
|
|
86
88
|
"*/**/*.spec.js"
|
|
87
89
|
],
|
|
88
90
|
"reporter": [
|
|
89
|
-
"
|
|
90
|
-
"html"
|
|
91
|
+
"text"
|
|
91
92
|
],
|
|
92
93
|
"require": [
|
|
93
94
|
"@babel/register"
|
package/src/index.js
CHANGED
|
@@ -1,36 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
3
|
-
* @licstart The following is the entire license notice for the JavaScript code in this file.
|
|
4
|
-
*
|
|
5
|
-
* Merge MARC records
|
|
6
|
-
*
|
|
7
|
-
* Copyright (C) 2015-2019 University Of Helsinki (The National Library Of Finland)
|
|
8
|
-
*
|
|
9
|
-
* This file is part of marc-record-merge-js
|
|
10
|
-
|
|
11
|
-
* marc-record-merge-js program is free software: you can redistribute it and/or modify
|
|
12
|
-
* it under the terms of the GNU Lesser General Public License as
|
|
13
|
-
* published by the Free Software Foundation, either version 3 of the
|
|
14
|
-
* License, or (at your option) any later version.
|
|
15
|
-
*
|
|
16
|
-
* marc-record-merge-js is distributed in the hope that it will be useful,
|
|
17
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
19
|
-
* GNU Lesser General Public License for more details.
|
|
20
|
-
*
|
|
21
|
-
* You should have received a copy of the GNU Lesser General Public License
|
|
22
|
-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
23
|
-
*
|
|
24
|
-
* @licend The above is the entire license notice
|
|
25
|
-
* for the JavaScript code in this file.
|
|
26
|
-
*
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
import * as Reducers from './reducers';
|
|
30
|
-
import {MarcRecord} from '@natlibfi/marc-record';
|
|
1
|
+
import Reducers from './reducers';
|
|
31
2
|
|
|
32
3
|
export {Reducers};
|
|
4
|
+
// export default ({base, source, reducers}) => reducers.reduce((base, reducer) => reducer(base, source), base);
|
|
5
|
+
|
|
6
|
+
// NV: Modified the reducer loop so, that not only base, but also is carried back.
|
|
7
|
+
// However, we try to be backward-compatible: normally after the reducers, only base is returned.
|
|
33
8
|
export default ({base, source, reducers}) => {
|
|
34
|
-
const
|
|
35
|
-
|
|
9
|
+
const combo = {base, source}; // eslint-disable-line functional/no-let
|
|
10
|
+
|
|
11
|
+
reducers.reduce((combo, reducer) => {
|
|
12
|
+
combo = singleRound(reducer, combo.base, combo.source); // eslint-disable-line no-param-reassign
|
|
13
|
+
|
|
14
|
+
return combo;
|
|
15
|
+
}, combo);
|
|
16
|
+
|
|
17
|
+
// Hack to make my melinda-marc-record-merge-reducers single tests that expect both
|
|
18
|
+
// base and source to return them both:
|
|
19
|
+
if (reducers.length === 1 && combo.base && combo.source) {
|
|
20
|
+
return combo;
|
|
21
|
+
}
|
|
22
|
+
// All other tests return just base... Backward (compability) it is!
|
|
23
|
+
return combo.base;
|
|
24
|
+
|
|
25
|
+
function singleRound(reducer, base, source) {
|
|
26
|
+
const combo = reducer(base, source);
|
|
27
|
+
if (combo.base !== undefined && combo.source !== undefined) {
|
|
28
|
+
//console.info('NEW STYLE REDUCER RESULT v2'); // eslint-disable-line no-console
|
|
29
|
+
return combo;
|
|
30
|
+
}
|
|
31
|
+
//console.info('OLD SCHOOL REDUCER RESULT v2'); // eslint-disable-line no-console
|
|
32
|
+
return {base: combo.base, source};
|
|
33
|
+
}
|
|
36
34
|
};
|