@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/src/reducers/copy.js
CHANGED
|
@@ -1,88 +1,251 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
1
|
+
/* eslint-disable max-statements */
|
|
2
|
+
/* eslint-disable no-unused-vars */
|
|
3
|
+
|
|
4
|
+
import {MarcRecord} from '@natlibfi/marc-record';
|
|
5
|
+
import createDebugLogger from 'debug';
|
|
6
|
+
|
|
7
|
+
export default ({
|
|
8
|
+
tagPattern,
|
|
9
|
+
compareTagsOnly = false,
|
|
10
|
+
compareWithoutTag = false,
|
|
11
|
+
compareWithoutIndicators = false,
|
|
12
|
+
compareWithoutIndicator1 = false,
|
|
13
|
+
compareWithoutIndicator2 = false,
|
|
14
|
+
subfieldsMustBeIdentical = true,
|
|
15
|
+
excludeSubfields = [],
|
|
16
|
+
dropSubfields = [],
|
|
17
|
+
copyUnless = [],
|
|
18
|
+
baseValidators = {subfieldValues: false},
|
|
19
|
+
sourceValidators = {subfieldValues: false},
|
|
20
|
+
swapTag = [],
|
|
21
|
+
swapSubfieldCode = [],
|
|
22
|
+
doNotCopyIfFieldPresent = false
|
|
23
|
+
}) => (base, source) => {
|
|
24
|
+
const baseRecord = new MarcRecord(base, baseValidators);
|
|
25
|
+
const sourceRecord = new MarcRecord(source, sourceValidators);
|
|
26
|
+
|
|
27
|
+
const debug = createDebugLogger('@natlibfi/marc-record-merge');
|
|
28
|
+
const debugOptions = createDebugLogger('@natlibfi/marc-record-merge:compare-options');
|
|
29
|
+
const debugCompare = createDebugLogger('@natlibfi/marc-record-merge:compare');
|
|
30
|
+
|
|
31
|
+
const ignoreInd1 = compareWithoutIndicators || compareWithoutIndicator1;
|
|
32
|
+
const ignoreInd2 = compareWithoutIndicators || compareWithoutIndicator2;
|
|
33
|
+
|
|
34
|
+
debugOptions(`Tag Pattern: ${tagPattern}`);
|
|
35
|
+
debugOptions(`Compare tags only: ${compareTagsOnly}`);
|
|
36
|
+
debugOptions(`Omit indicator 1 from comparison: ${ignoreInd1}`);
|
|
37
|
+
debugOptions(`Omit indicator 2 from comparison: ${ignoreInd2}`);
|
|
38
|
+
debugOptions(`Copy if identical: ${subfieldsMustBeIdentical}`);
|
|
39
|
+
debugOptions(`Exclude subfields: [${excludeSubfields}]`);
|
|
40
|
+
debugOptions(`Drop subfields [${dropSubfields}]`);
|
|
41
|
+
debugOptions(`Copy unless contains subfields: ${JSON.stringify(copyUnless)}`);
|
|
42
|
+
|
|
43
|
+
const baseFields = baseRecord.get(tagPattern);
|
|
44
|
+
const sourceFields = sourceRecord.get(tagPattern);
|
|
45
|
+
const doNotCopy = doNotCopyIfFieldPresent ? baseRecord.get(doNotCopyIfFieldPresent).length > 0 : false;
|
|
46
|
+
|
|
47
|
+
if (doNotCopy) {
|
|
48
|
+
return baseRecord.toObject();
|
|
49
|
+
}
|
|
50
|
+
debug(`FFS: ${compareWithoutIndicator1}, ${compareWithoutIndicators}, ${ignoreInd1}`);
|
|
51
|
+
debug(`Base fields: `, baseFields);
|
|
52
|
+
debug(`Source fields: `, sourceFields);
|
|
53
|
+
|
|
54
|
+
// Logic steps
|
|
55
|
+
const baseCompareFields = baseFields.map(baseField => createCompareField(baseField));
|
|
56
|
+
const compareResultFields = compareFields(sourceFields, baseCompareFields);
|
|
57
|
+
const droppedUnwantedSubfield = checkDropSubfields(compareResultFields);
|
|
58
|
+
const droppedUnwantedFields = checkCopyUnlessFields(droppedUnwantedSubfield);
|
|
59
|
+
const swappedSubfields = checkSwapSubfieldCodes(droppedUnwantedFields);
|
|
60
|
+
const swappedTags = checkSwapTag(swappedSubfields);
|
|
61
|
+
const uniqueFields = [...new Set(swappedTags.map(field => JSON.stringify(field)))].map(field => JSON.parse(field));
|
|
62
|
+
debug('Fields to be copied');
|
|
63
|
+
debug(JSON.stringify(uniqueFields));
|
|
64
|
+
|
|
65
|
+
// Add fields to base;
|
|
66
|
+
uniqueFields.forEach(field => baseRecord.insertField(field));
|
|
67
|
+
return baseRecord.toObject();
|
|
68
|
+
|
|
69
|
+
function compareFields(sourceFields, baseCompareFields, uniqFields = []) {
|
|
70
|
+
const [sourceField, ...rest] = sourceFields;
|
|
71
|
+
if (sourceField === undefined) {
|
|
72
|
+
return uniqFields;
|
|
41
73
|
}
|
|
42
|
-
const filterMissing = function(sourceField) {
|
|
43
|
-
// Test 02: Identical control fields are not copied
|
|
44
|
-
if ('value' in sourceField) {
|
|
45
|
-
return baseFields.some(isIdenticalControlField) === false;
|
|
46
|
-
}
|
|
47
|
-
// Test 04: Identical data fields in base and source, not copied
|
|
48
|
-
// Test 05: Different data fields are copied from source to base
|
|
49
|
-
if ('subfields' in sourceField) {
|
|
50
|
-
return baseFields.some(isIdenticalDataField) === false;
|
|
51
|
-
}
|
|
52
74
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
75
|
+
if (baseCompareFields.length === 0) {
|
|
76
|
+
return compareFields(rest, baseCompareFields, [...uniqFields, sourceField]);
|
|
77
|
+
}
|
|
56
78
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
79
|
+
// Source and base are also compared for identicalness
|
|
80
|
+
// Non-identical fields are copied from source to base as duplicates
|
|
81
|
+
const sourceCompareField = createCompareField(sourceField);
|
|
82
|
+
const unique = checkCompareFields(baseCompareFields, sourceCompareField);
|
|
83
|
+
|
|
84
|
+
debugCompare(`${JSON.stringify(sourceField)} ${unique ? 'is UNIQUE' : 'not UNIQUE'}`);
|
|
85
|
+
|
|
86
|
+
if (unique) {
|
|
87
|
+
return compareFields(rest, baseCompareFields, [...uniqFields, sourceField]);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return compareFields(rest, baseCompareFields, uniqFields);
|
|
91
|
+
|
|
92
|
+
function checkCompareFields(baseCompareFields, sourceCompareField) {
|
|
93
|
+
let unique = true; // eslint-disable-line functional/no-let
|
|
94
|
+
|
|
95
|
+
baseCompareFields.forEach(baseCompareField => {
|
|
96
|
+
debugCompare(`Comparing ${JSON.stringify(sourceCompareField)} to ${JSON.stringify(baseCompareField)}}`);
|
|
97
|
+
|
|
98
|
+
if (sourceCompareField.value !== baseCompareField.value) {
|
|
99
|
+
debugCompare(`Value is different ${sourceCompareField.value} !== ${baseCompareField.value}`);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (sourceCompareField.ind1 !== baseCompareField.ind1) {
|
|
104
|
+
debugCompare(`Ind1 is different ${sourceCompareField.ind1} !== ${baseCompareField.ind1}`);
|
|
105
|
+
return;
|
|
68
106
|
}
|
|
69
|
-
|
|
70
|
-
|
|
107
|
+
|
|
108
|
+
if (sourceCompareField.ind2 !== baseCompareField.ind2) {
|
|
109
|
+
debugCompare(`Ind2 is different ${sourceCompareField.ind2} !== ${baseCompareField.ind2}`);
|
|
110
|
+
return;
|
|
71
111
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
112
|
+
|
|
113
|
+
if ('subfields' in sourceCompareField) {
|
|
114
|
+
const allFound = checkSubfields(sourceCompareField.subfields, baseCompareField.subfields);
|
|
115
|
+
debugCompare(`Subfields are different ${!allFound}`);
|
|
116
|
+
if (!allFound) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
unique = false;
|
|
121
|
+
return;
|
|
78
122
|
}
|
|
123
|
+
|
|
124
|
+
unique = false;
|
|
125
|
+
return;
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
return unique;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function checkSubfields(sourceSubfields, baseSubfields) {
|
|
132
|
+
const foundSubs = sourceSubfields.filter(sSub => baseSubfields.some(bSub => sSub.code === bSub.code && sSub.value === bSub.value));
|
|
133
|
+
|
|
134
|
+
if (subfieldsMustBeIdentical) {
|
|
135
|
+
return foundSubs.length === sourceSubfields.length && foundSubs.length === baseSubfields.length;
|
|
79
136
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
137
|
+
|
|
138
|
+
return foundSubs.length === sourceSubfields.length;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// compare objects have only fields that matter in comparison
|
|
143
|
+
function createCompareField(field) {
|
|
144
|
+
if (compareTagsOnly) {
|
|
145
|
+
return {tag: field.tag};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if ('value' in field) {
|
|
149
|
+
return {tag: field.tag, value: field.value};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const [filteredField] = checkDropSubfields([field]);
|
|
153
|
+
const [foundRule] = swapTag.filter(rule => new RegExp(rule.from, 'u').test(field.tag));
|
|
154
|
+
const replacementTag = foundRule ? foundRule.to : undefined;
|
|
155
|
+
|
|
156
|
+
const params = [
|
|
157
|
+
{name: 'tag', value: compareWithoutTag ? replacementTag : field.tag},
|
|
158
|
+
{name: 'ind1', value: ignoreInd1 ? undefined : field.ind1},
|
|
159
|
+
{name: 'ind2', value: ignoreInd2 ? undefined : field.ind2},
|
|
160
|
+
{name: 'subfields', value: createCompareSubfields(filteredField.subfields)}
|
|
161
|
+
].map(param => [param.name, param.value]);
|
|
162
|
+
|
|
163
|
+
return Object.fromEntries(params);
|
|
164
|
+
|
|
165
|
+
function createCompareSubfields(subfields) {
|
|
166
|
+
const nonExcludedSubfields = subfields.filter(sub => !excludeSubfields.some(code => code === sub.code));
|
|
167
|
+
const normalizedSubfields = nonExcludedSubfields.map(sub => ({code: sub.code, value: normalizeSubfieldValue(sub.value)}));
|
|
168
|
+
|
|
169
|
+
return normalizedSubfields;
|
|
170
|
+
|
|
171
|
+
function normalizeSubfieldValue(value) {
|
|
172
|
+
return value.toLowerCase().replace(/\s+/ug, '');
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function checkSwapTag(fields) {
|
|
178
|
+
if (swapTag.length > 0) {
|
|
179
|
+
return fields.map(field => ({...field, tag: swapTagsFunc(field.tag)}));
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return fields;
|
|
183
|
+
|
|
184
|
+
function swapTagsFunc(tag) {
|
|
185
|
+
const [foundRule] = swapTag.filter(rule => new RegExp(rule.from, 'u').test(tag));
|
|
186
|
+
|
|
187
|
+
if (foundRule === undefined) {
|
|
188
|
+
return tag;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return foundRule.to;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function checkSwapSubfieldCodes(fields) {
|
|
196
|
+
if (swapSubfieldCode.length > 0) {
|
|
197
|
+
return fields.map(field => ({...field, subfields: swapSubfieldCodesFunc(field.subfields)}));
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
return fields;
|
|
201
|
+
|
|
202
|
+
function swapSubfieldCodesFunc(subfields) {
|
|
203
|
+
return subfields.map(sub => {
|
|
204
|
+
const [foundRule] = swapSubfieldCode.filter(rule => rule.from === sub.code);
|
|
205
|
+
|
|
206
|
+
if (foundRule === undefined) {
|
|
207
|
+
return sub;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return {code: foundRule.to, value: sub.value};
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function checkDropSubfields(fields) {
|
|
216
|
+
if (dropSubfields.length > 0) {
|
|
217
|
+
return fields.map(field => ({...field, subfields: dropSubfieldsFunc(field.subfields)}))
|
|
218
|
+
.filter(field => field.subfields.length > 0);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
return fields;
|
|
222
|
+
|
|
223
|
+
function dropSubfieldsFunc(subfields) {
|
|
224
|
+
return subfields.filter(sub => { // eslint-disable-line
|
|
225
|
+
return !dropSubfields.some(({code, value = false, condition = false}) => {
|
|
226
|
+
if (code !== sub.code) {
|
|
227
|
+
return false;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
if (!condition && value) {
|
|
231
|
+
return value === sub.value;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
if (condition === 'unless' && value) {
|
|
235
|
+
return !new RegExp(value, 'u').test(sub.value);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
return true;
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function checkCopyUnlessFields(fields) {
|
|
245
|
+
if (copyUnless.length > 0) {
|
|
246
|
+
return fields.filter(({subfields}) => copyUnless.some(filter => !subfields.some(sub => sub.code === filter.code && new RegExp(filter.value, 'u').test(sub.value))));
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return fields;
|
|
87
250
|
}
|
|
88
251
|
};
|
|
@@ -1,52 +1,54 @@
|
|
|
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
|
-
import chai from 'chai';
|
|
29
|
-
import fs from 'fs';
|
|
30
|
-
import path from 'path';
|
|
31
|
-
import {MarcRecord} from '@natlibfi/marc-record';
|
|
1
|
+
import {expect} from 'chai';
|
|
2
|
+
import {READERS} from '@natlibfi/fixura';
|
|
32
3
|
import createReducer from './copy';
|
|
33
|
-
import
|
|
34
|
-
|
|
35
|
-
MarcRecord.setValidationOptions({subfieldValues: false});
|
|
4
|
+
import generateTests from '@natlibfi/fixugen';
|
|
36
5
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const fixturesPath = path.join(__dirname, '..', '..', 'test-fixtures', 'reducers', 'copy');
|
|
6
|
+
//import createDebugLogger from 'debug'; // <---
|
|
7
|
+
//const debug = createDebugLogger('@natlibfi/marc-record-merge/copy.spec.js'); // <---
|
|
40
8
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
});
|
|
51
|
-
});
|
|
9
|
+
generateTests({
|
|
10
|
+
callback,
|
|
11
|
+
path: [__dirname, '..', '..', 'test-fixtures', 'reducers', 'copy'],
|
|
12
|
+
useMetadataFile: true,
|
|
13
|
+
recurse: true,
|
|
14
|
+
fixura: {
|
|
15
|
+
reader: READERS.JSON,
|
|
16
|
+
failWhenNotFound: false
|
|
17
|
+
}
|
|
52
18
|
});
|
|
19
|
+
|
|
20
|
+
function callback({
|
|
21
|
+
getFixture,
|
|
22
|
+
tagPatternRegExp,
|
|
23
|
+
compareTagsOnly = false,
|
|
24
|
+
compareWithoutTag = false,
|
|
25
|
+
compareWithoutIndicators = false,
|
|
26
|
+
compareWithoutIndicator1 = false,
|
|
27
|
+
compareWithoutIndicator2 = false,
|
|
28
|
+
subfieldsMustBeIdentical = false,
|
|
29
|
+
copyUnless = undefined,
|
|
30
|
+
excludeSubfields = undefined,
|
|
31
|
+
dropSubfields = undefined,
|
|
32
|
+
swapSubfieldCode = [],
|
|
33
|
+
swapTag = [],
|
|
34
|
+
doNotCopyIfFieldPresent = false
|
|
35
|
+
}) {
|
|
36
|
+
const base = getFixture('base.json');
|
|
37
|
+
const source = getFixture('source.json');
|
|
38
|
+
const tagPattern = new RegExp(tagPatternRegExp, 'u');
|
|
39
|
+
const expectedRecord = getFixture('merged.json');
|
|
40
|
+
|
|
41
|
+
const merged = createReducer({
|
|
42
|
+
tagPattern, compareTagsOnly, compareWithoutTag, compareWithoutIndicators, compareWithoutIndicator1, compareWithoutIndicator2,
|
|
43
|
+
copyUnless, subfieldsMustBeIdentical, excludeSubfields,
|
|
44
|
+
dropSubfields, swapSubfieldCode, swapTag,
|
|
45
|
+
doNotCopyIfFieldPresent
|
|
46
|
+
})(base, source);
|
|
47
|
+
//debug(`*** mergedRecord: `, mergedRecord); //<--
|
|
48
|
+
//debug(`*** mergedRecord,Strfy: `, JSON.stringify(mergedRecord)); //<--
|
|
49
|
+
//debug(`*** expectedRecord: `, expectedRecord); //<--
|
|
50
|
+
//debug(`*** expectedRecord,Strfy: `, JSON.stringify(expectedRecord)); //<--
|
|
51
|
+
expect(merged.constructor.name).not.to.eql('MarcRecord');
|
|
52
|
+
expect(merged.constructor.name).to.eql('Object');
|
|
53
|
+
expect(merged).to.eql(expectedRecord);
|
|
54
|
+
}
|
package/src/reducers/index.js
CHANGED
|
@@ -1,31 +1,4 @@
|
|
|
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
|
-
export * from './copy';
|
|
30
|
-
export * from './select';
|
|
1
|
+
import copy from './copy';
|
|
2
|
+
import select, {strictEquality, subsetEquality} from './select';
|
|
31
3
|
|
|
4
|
+
export default {copy, select, strictEquality, subsetEquality};
|
package/src/reducers/select.js
CHANGED
|
@@ -1,56 +1,40 @@
|
|
|
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
1
|
import {normalizeSync} from 'normalize-diacritics';
|
|
2
|
+
import createDebugLogger from 'debug';
|
|
3
|
+
import {MarcRecord} from '@natlibfi/marc-record';
|
|
29
4
|
|
|
30
5
|
export function strictEquality(subfieldA, subfieldB) {
|
|
31
6
|
return subfieldA.code === subfieldB.code &&
|
|
32
|
-
|
|
7
|
+
subfieldA.value === subfieldB.value;
|
|
33
8
|
}
|
|
34
9
|
|
|
35
10
|
export function subsetEquality(subfieldA, subfieldB) {
|
|
36
11
|
return subfieldA.code === subfieldB.code &&
|
|
37
|
-
|
|
12
|
+
(subfieldA.value.indexOf(subfieldB.value) !== -1 || subfieldB.value.indexOf(subfieldA.value) !== -1);
|
|
38
13
|
}
|
|
39
|
-
|
|
40
|
-
export default ({
|
|
41
|
-
const
|
|
42
|
-
const
|
|
14
|
+
// EqualityFunction can be either strictEquality or subsetEquality
|
|
15
|
+
export default ({tagPattern, equalityFunction = strictEquality}) => (base, source) => {
|
|
16
|
+
const debug = createDebugLogger('@natlibfi/marc-record-merge:select');
|
|
17
|
+
const baseRecord = new MarcRecord(base, {subfieldValues: false});
|
|
18
|
+
const sourceRecord = new MarcRecord(source, {subfieldValues: false});
|
|
19
|
+
const baseFields = baseRecord.get(tagPattern);
|
|
20
|
+
const sourceFields = sourceRecord.get(tagPattern);
|
|
21
|
+
const fieldTag = sourceFields.map(field => field.tag);
|
|
22
|
+
debug(`Comparing field ${fieldTag}`);
|
|
43
23
|
|
|
44
24
|
checkFieldType(baseFields);
|
|
45
25
|
checkFieldType(sourceFields);
|
|
46
26
|
|
|
47
27
|
if (baseFields.length > 1 || sourceFields.length > 1) {
|
|
28
|
+
debug(`Multiple fields in base or source`);
|
|
29
|
+
debug(`No changes to base`);
|
|
48
30
|
return base;
|
|
49
31
|
}
|
|
50
32
|
const [baseField] = baseFields;
|
|
51
33
|
const [sourceField] = sourceFields;
|
|
52
34
|
|
|
53
35
|
if (baseField.tag === sourceField.tag === false) {
|
|
36
|
+
debug(`Base tag ${baseField.tag} is not equal to source tag ${sourceField.tag}`);
|
|
37
|
+
debug(`No changes to base`);
|
|
54
38
|
return base;
|
|
55
39
|
}
|
|
56
40
|
const baseSubs = baseField.subfields;
|
|
@@ -62,19 +46,26 @@ export default ({pattern, equalityFunction = strictEquality}) => (base, source)
|
|
|
62
46
|
const sourceSubsNormalized = sourceSubs
|
|
63
47
|
.map(({code, value}) => ({code, value: normalizeSubfieldValue(value)}));
|
|
64
48
|
|
|
49
|
+
// Returns the base subfields for which a matching source subfield is found
|
|
65
50
|
const equalSubfieldsBase = baseSubsNormalized
|
|
66
51
|
.filter(baseSubfield => sourceSubsNormalized
|
|
67
52
|
.some(sourceSubfield => equalityFunction(baseSubfield, sourceSubfield)));
|
|
53
|
+
debug(`equalSubfieldsBase: ${JSON.stringify(equalSubfieldsBase, undefined, 2)}`);
|
|
68
54
|
|
|
55
|
+
// Returns the source subfields for which a matching base subfield is found
|
|
69
56
|
const equalSubfieldsSource = sourceSubsNormalized
|
|
70
57
|
.filter(sourceSubfield => baseSubsNormalized
|
|
71
58
|
.some(baseSubfield => equalityFunction(sourceSubfield, baseSubfield)));
|
|
59
|
+
debug(`equalSubfieldsSource: ${JSON.stringify(equalSubfieldsSource, undefined, 2)}`);
|
|
72
60
|
|
|
73
61
|
if (baseSubs.length === sourceSubs.length && equalSubfieldsBase.length < baseSubs.length) {
|
|
62
|
+
debug(`Base and source subfields are not equal`);
|
|
63
|
+
debug(`No changes to base`);
|
|
74
64
|
return base;
|
|
75
65
|
}
|
|
76
66
|
|
|
77
67
|
if (baseSubs.length === sourceSubs.length && equalSubfieldsBase.length === equalSubfieldsSource.length) {
|
|
68
|
+
debug(`Checking subfield equality`);
|
|
78
69
|
const totalSubfieldLengthBase = baseSubsNormalized
|
|
79
70
|
.map(({value}) => value.length)
|
|
80
71
|
.reduce((acc, value) => acc + value);
|
|
@@ -91,11 +82,13 @@ export default ({pattern, equalityFunction = strictEquality}) => (base, source)
|
|
|
91
82
|
return replaceBasefieldWithSourcefield(base);
|
|
92
83
|
}
|
|
93
84
|
|
|
85
|
+
debug(`No changes to base`);
|
|
94
86
|
return base;
|
|
95
87
|
|
|
96
88
|
function replaceBasefieldWithSourcefield(base) {
|
|
97
89
|
const index = base.fields.findIndex(field => field === baseField);
|
|
98
90
|
base.fields.splice(index, 1, sourceField); // eslint-disable-line functional/immutable-data
|
|
91
|
+
debug(`Source field is longer, replacing base with source`);
|
|
99
92
|
return base;
|
|
100
93
|
}
|
|
101
94
|
|
|
@@ -111,7 +104,7 @@ export default ({pattern, equalityFunction = strictEquality}) => (base, source)
|
|
|
111
104
|
|
|
112
105
|
function normalizeSubfieldValue(value) {
|
|
113
106
|
// Regexp options: g: global search, u: unicode
|
|
114
|
-
const punctuation = /[
|
|
107
|
+
const punctuation = /[.,\-/#!?$%^&*;:{}=_`~()[\]]/gu;
|
|
115
108
|
return normalizeSync(value).toLowerCase().replace(punctuation, '', 'u').replace(/\s+/gu, ' ').trim();
|
|
116
109
|
}
|
|
117
110
|
};
|