@natlibfi/marc-record-merge 6.0.0-beta.4 → 6.0.0-beta.7
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/README.md +24 -10
- package/dist/reducers/copy.js +101 -35
- package/dist/reducers/copy.js.map +1 -1
- package/dist/reducers/copy.spec.js +18 -20
- package/dist/reducers/copy.spec.js.map +1 -1
- package/dist/reducers/select.js +10 -2
- package/dist/reducers/select.js.map +1 -1
- package/dist/reducers/select.spec.js +6 -8
- package/dist/reducers/select.spec.js.map +1 -1
- package/package.json +9 -11
- package/src/reducers/copy.js +93 -36
- package/src/reducers/copy.spec.js +21 -13
- package/src/reducers/select.js +7 -4
- package/src/reducers/select.spec.js +7 -3
- package/test-fixtures/reducers/copy/{basic copy → 01 - copy}/01/base.json +0 -0
- package/test-fixtures/reducers/copy/{basic copy → 01 - copy}/01/merged.json +0 -0
- package/test-fixtures/reducers/copy/{basic copy → 01 - copy}/01/metadata.json +1 -2
- package/test-fixtures/reducers/copy/{basic copy → 01 - copy}/01/source.json +0 -0
- package/test-fixtures/reducers/copy/{basic copy → 01 - copy}/02/base.json +0 -0
- package/test-fixtures/reducers/copy/{basic copy → 01 - copy}/02/merged.json +0 -0
- package/test-fixtures/reducers/copy/{basic copy → 01 - copy}/02/metadata.json +1 -2
- package/test-fixtures/reducers/copy/{basic copy → 01 - copy}/02/source.json +0 -0
- package/test-fixtures/reducers/copy/{basic copy → 01 - copy}/03/base.json +0 -0
- package/test-fixtures/reducers/copy/{basic copy → 01 - copy}/03/merged.json +0 -0
- package/test-fixtures/reducers/copy/{basic copy → 01 - copy}/03/metadata.json +1 -2
- package/test-fixtures/reducers/copy/{basic copy → 01 - copy}/03/source.json +0 -0
- package/test-fixtures/reducers/copy/{basic copy → 01 - copy}/04/base.json +0 -0
- package/test-fixtures/reducers/copy/{basic copy → 01 - copy}/04/merged.json +0 -0
- package/test-fixtures/reducers/copy/{basic copy → 01 - copy}/04/metadata.json +1 -2
- package/test-fixtures/reducers/copy/{basic copy → 01 - copy}/04/source.json +0 -0
- package/test-fixtures/reducers/copy/{basic copy → 01 - copy}/05/base.json +0 -0
- package/test-fixtures/reducers/copy/{basic copy → 01 - copy}/05/merged.json +0 -0
- package/test-fixtures/reducers/copy/{basic copy → 01 - copy}/05/metadata.json +1 -2
- package/test-fixtures/reducers/copy/{basic copy → 01 - copy}/05/source.json +0 -0
- package/test-fixtures/reducers/copy/{basic copy → 01 - copy}/06/base.json +0 -0
- package/test-fixtures/reducers/copy/{basic copy → 01 - copy}/06/merged.json +0 -0
- package/test-fixtures/reducers/copy/{basic copy → 01 - copy}/06/metadata.json +1 -2
- package/test-fixtures/reducers/copy/{basic copy → 01 - copy}/06/source.json +0 -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/{copyUnless/01 → 02 - doNotCopyIfFieldPresent/02}/base.json +0 -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/{compareTagsOnly → 03 - compareTagsOnly}/01/base.json +0 -0
- package/test-fixtures/reducers/copy/{compareTagsOnly → 03 - compareTagsOnly}/01/merged.json +0 -0
- package/test-fixtures/reducers/copy/{compareTagsOnly/01/metadata.json → 03 - compareTagsOnly/01/metadata.json } +1 -2
- package/test-fixtures/reducers/copy/{compareTagsOnly → 03 - compareTagsOnly}/01/source.json +0 -0
- package/test-fixtures/reducers/copy/{compareTagsOnly → 03 - compareTagsOnly}/02/base.json +0 -0
- package/test-fixtures/reducers/copy/{compareTagsOnly → 03 - compareTagsOnly}/02/merged.json +0 -0
- package/test-fixtures/reducers/copy/{compareTagsOnly/02/metadata.json → 03 - compareTagsOnly/02/metadata.json } +1 -2
- package/test-fixtures/reducers/copy/{compareTagsOnly → 03 - compareTagsOnly}/02/source.json +0 -0
- package/test-fixtures/reducers/copy/{compareWithoutIndicators → 04 - compareWithoutIndicators}/01/base.json +0 -0
- package/test-fixtures/reducers/copy/{compareWithoutIndicators → 04 - compareWithoutIndicators}/01/merged.json +0 -0
- package/test-fixtures/reducers/copy/{compareWithoutIndicators/01/metadata.json → 04 - compareWithoutIndicators/01/metadata.json } +1 -2
- package/test-fixtures/reducers/copy/{compareWithoutIndicators → 04 - compareWithoutIndicators}/01/source.json +0 -0
- package/test-fixtures/reducers/copy/{compareWithoutIndicators → 04 - compareWithoutIndicators}/02/base.json +0 -0
- package/test-fixtures/reducers/copy/{compareWithoutIndicators → 04 - compareWithoutIndicators}/02/merged.json +0 -0
- package/test-fixtures/reducers/copy/{compareWithoutIndicators/02/metadata.json → 04 - compareWithoutIndicators/02/metadata.json } +1 -2
- package/test-fixtures/reducers/copy/{compareWithoutIndicators → 04 - compareWithoutIndicators}/02/source.json +0 -0
- package/test-fixtures/reducers/copy/05 - copyUnless/01/base.json +9 -0
- package/test-fixtures/reducers/copy/{copyUnless → 05 - copyUnless}/01/merged.json +0 -0
- package/test-fixtures/reducers/copy/{copyUnless/01/metadata.json → 05 - copyUnless/01/metadata.json } +1 -2
- package/test-fixtures/reducers/copy/{copyUnless → 05 - copyUnless}/01/source.json +0 -0
- package/test-fixtures/reducers/copy/{subfieldsMustBeIdentical → 06 - subfieldsMustBeIdentical}/01/base.json +0 -0
- package/test-fixtures/reducers/copy/{subfieldsMustBeIdentical → 06 - subfieldsMustBeIdentical}/01/merged.json +0 -0
- package/test-fixtures/reducers/copy/{subfieldsMustBeIdentical/01/metadata.json → 06 - subfieldsMustBeIdentical/01/metadata.json } +1 -2
- package/test-fixtures/reducers/copy/{subfieldsMustBeIdentical → 06 - subfieldsMustBeIdentical}/01/source.json +0 -0
- package/test-fixtures/reducers/copy/{subfieldsMustBeIdentical → 06 - subfieldsMustBeIdentical}/02/base.json +0 -0
- package/test-fixtures/reducers/copy/{subfieldsMustBeIdentical → 06 - subfieldsMustBeIdentical}/02/merged.json +0 -0
- package/test-fixtures/reducers/copy/{subfieldsMustBeIdentical/02/metadata.json → 06 - subfieldsMustBeIdentical/02/metadata.json } +1 -2
- package/test-fixtures/reducers/copy/{subfieldsMustBeIdentical → 06 - subfieldsMustBeIdentical}/02/source.json +0 -0
- package/test-fixtures/reducers/copy/{subfieldsMustBeIdentical → 06 - subfieldsMustBeIdentical}/03/base.json +0 -0
- package/test-fixtures/reducers/copy/{subfieldsMustBeIdentical → 06 - subfieldsMustBeIdentical}/03/merged.json +0 -0
- package/test-fixtures/reducers/copy/{subfieldsMustBeIdentical/03/metadata.json → 06 - subfieldsMustBeIdentical/03/metadata.json } +1 -2
- package/test-fixtures/reducers/copy/{subfieldsMustBeIdentical → 06 - subfieldsMustBeIdentical}/03/source.json +0 -0
- package/test-fixtures/reducers/copy/{subfieldsMustBeIdentical → 06 - subfieldsMustBeIdentical}/04/base.json +0 -0
- package/test-fixtures/reducers/copy/{subfieldsMustBeIdentical → 06 - subfieldsMustBeIdentical}/04/merged.json +0 -0
- package/test-fixtures/reducers/copy/{subfieldsMustBeIdentical/04/metadata.json → 06 - subfieldsMustBeIdentical/04/metadata.json } +1 -2
- package/test-fixtures/reducers/copy/{subfieldsMustBeIdentical → 06 - subfieldsMustBeIdentical}/04/source.json +0 -0
- package/test-fixtures/reducers/copy/{subfieldsMustBeIdentical → 06 - subfieldsMustBeIdentical}/05/base.json +0 -0
- package/test-fixtures/reducers/copy/{subfieldsMustBeIdentical → 06 - subfieldsMustBeIdentical}/05/merged.json +0 -0
- package/test-fixtures/reducers/copy/{subfieldsMustBeIdentical/05/metadata.json → 06 - subfieldsMustBeIdentical/05/metadata.json } +1 -2
- package/test-fixtures/reducers/copy/{subfieldsMustBeIdentical → 06 - subfieldsMustBeIdentical}/05/source.json +0 -0
- package/test-fixtures/reducers/copy/{subfieldsMustBeIdentical → 06 - subfieldsMustBeIdentical}/06/base.json +0 -0
- package/test-fixtures/reducers/copy/{subfieldsMustBeIdentical → 06 - subfieldsMustBeIdentical}/06/merged.json +0 -0
- package/test-fixtures/reducers/copy/{subfieldsMustBeIdentical/06/metadata.json → 06 - subfieldsMustBeIdentical/06/metadata.json } +1 -2
- package/test-fixtures/reducers/copy/{subfieldsMustBeIdentical → 06 - subfieldsMustBeIdentical}/06/source.json +0 -0
- package/test-fixtures/reducers/copy/{excludeSubfields → 07 - excludeSubfields}/01/base.json +0 -0
- package/test-fixtures/reducers/copy/{excludeSubfields → 07 - excludeSubfields}/01/merged.json +0 -0
- package/test-fixtures/reducers/copy/07 - excludeSubfields/01/metadata.json +8 -0
- package/test-fixtures/reducers/copy/{excludeSubfields → 07 - excludeSubfields}/01/source.json +0 -0
- package/test-fixtures/reducers/copy/07 - excludeSubfields/02/base.json +39 -0
- package/test-fixtures/reducers/copy/07 - excludeSubfields/02/merged.json +58 -0
- 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/{dropSubfields → 08 - dropSubfields}/01/base.json +0 -0
- package/test-fixtures/reducers/copy/{dropSubfields → 08 - dropSubfields}/01/merged.json +0 -0
- package/test-fixtures/reducers/copy/{dropSubfields/01/metadata.json → 08 - dropSubfields/01/metadata.json } +1 -2
- package/test-fixtures/reducers/copy/{dropSubfields → 08 - dropSubfields}/01/source.json +0 -0
- package/test-fixtures/reducers/copy/{dropSubfields → 08 - dropSubfields}/02/base.json +0 -0
- package/test-fixtures/reducers/copy/{dropSubfields/02/merged.json → 08 - dropSubfields/02/merged.json } +1 -1
- package/test-fixtures/reducers/copy/{dropSubfields/02/metadata.json → 08 - dropSubfields/02/metadata.json } +2 -3
- package/test-fixtures/reducers/copy/{dropSubfields/03/source.json → 08 - dropSubfields/02/source.json } +2 -2
- package/test-fixtures/reducers/copy/{dropSubfields → 08 - dropSubfields}/03/base.json +0 -0
- package/test-fixtures/reducers/copy/{dropSubfields/03/merged.json → 08 - dropSubfields/03/merged.json } +1 -1
- package/test-fixtures/reducers/copy/{dropSubfields/03/metadata.json → 08 - dropSubfields/03/metadata.json } +2 -3
- package/test-fixtures/reducers/copy/{dropSubfields/04/source.json → 08 - dropSubfields/03/source.json } +2 -2
- package/test-fixtures/reducers/copy/{dropSubfields → 08 - dropSubfields}/04/base.json +0 -0
- package/test-fixtures/reducers/copy/{dropSubfields → 08 - dropSubfields}/04/merged.json +0 -0
- package/test-fixtures/reducers/copy/{dropSubfields/04/metadata.json → 08 - dropSubfields/04/metadata.json } +1 -2
- package/test-fixtures/reducers/copy/{dropSubfields/02/source.json → 08 - dropSubfields/04/source.json } +2 -2
- 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/metadata.json +1 -2
- package/.drone.yml +0 -92
- package/test-fixtures/reducers/copy/excludeSubfields/01/metadata.json +0 -9
package/package.json
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"url": "git@github.com:natlibfi/marc-record-merge-js.git"
|
|
15
15
|
},
|
|
16
16
|
"license": "MIT",
|
|
17
|
-
"version": "6.0.0-beta.
|
|
17
|
+
"version": "6.0.0-beta.7",
|
|
18
18
|
"main": "./dist/index.js",
|
|
19
19
|
"engines": {
|
|
20
20
|
"node": ">=14"
|
|
@@ -30,17 +30,18 @@
|
|
|
30
30
|
"test:dev": "npm run lint:dev && npm run coverage",
|
|
31
31
|
"coverage": "npm run coverage:unit && npm run coverage:report",
|
|
32
32
|
"coverage:unit": "nyc --silent npm run test:base",
|
|
33
|
-
"coverage:report": "nyc report
|
|
33
|
+
"coverage:report": "nyc report",
|
|
34
34
|
"build:transpile": "babel src --copy-files --source-maps --delete-dir-on-start --out-dir=dist",
|
|
35
35
|
"build": "npm run build:transpile",
|
|
36
|
-
"dev:test": "cross-env
|
|
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'"
|
|
37
38
|
},
|
|
38
39
|
"dependencies": {
|
|
39
|
-
"@natlibfi/fixugen": "
|
|
40
|
+
"@natlibfi/fixugen": "1.1.0",
|
|
40
41
|
"@natlibfi/fixura": "^2.2.1",
|
|
41
|
-
"@natlibfi/marc-record": "^7.1.0-alpha.
|
|
42
|
+
"@natlibfi/marc-record": "^7.1.0-alpha.2",
|
|
42
43
|
"debug": "^4.3.4",
|
|
43
|
-
"normalize-diacritics": "
|
|
44
|
+
"normalize-diacritics": "2.14.0"
|
|
44
45
|
},
|
|
45
46
|
"devDependencies": {
|
|
46
47
|
"@babel/cli": "^7.17.10",
|
|
@@ -68,9 +69,7 @@
|
|
|
68
69
|
[
|
|
69
70
|
"@babel/preset-env",
|
|
70
71
|
{
|
|
71
|
-
"targets":
|
|
72
|
-
"node": "14"
|
|
73
|
-
}
|
|
72
|
+
"targets": "maintained node versions"
|
|
74
73
|
}
|
|
75
74
|
]
|
|
76
75
|
],
|
|
@@ -89,8 +88,7 @@
|
|
|
89
88
|
"*/**/*.spec.js"
|
|
90
89
|
],
|
|
91
90
|
"reporter": [
|
|
92
|
-
"
|
|
93
|
-
"html"
|
|
91
|
+
"text"
|
|
94
92
|
],
|
|
95
93
|
"require": [
|
|
96
94
|
"@babel/register"
|
package/src/reducers/copy.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable max-statements */
|
|
1
2
|
/* eslint-disable no-unused-vars */
|
|
2
3
|
|
|
3
4
|
import {MarcRecord} from '@natlibfi/marc-record';
|
|
@@ -12,7 +13,10 @@ export default ({
|
|
|
12
13
|
dropSubfields = [],
|
|
13
14
|
copyUnless = [],
|
|
14
15
|
baseValidators = {subfieldValues: false},
|
|
15
|
-
sourceValidators = {subfieldValues: false}
|
|
16
|
+
sourceValidators = {subfieldValues: false},
|
|
17
|
+
swapTag = [],
|
|
18
|
+
swapSubfieldCode = [],
|
|
19
|
+
doNotCopyIfFieldPresent = false
|
|
16
20
|
}) => (base, source) => {
|
|
17
21
|
const baseRecord = new MarcRecord(base, baseValidators);
|
|
18
22
|
const sourceRecord = new MarcRecord(source, sourceValidators);
|
|
@@ -30,74 +34,89 @@ export default ({
|
|
|
30
34
|
|
|
31
35
|
const baseFields = baseRecord.get(tagPattern);
|
|
32
36
|
const sourceFields = sourceRecord.get(tagPattern);
|
|
37
|
+
const doNotCopy = doNotCopyIfFieldPresent ? baseRecord.get(doNotCopyIfFieldPresent).length > 0 : false;
|
|
38
|
+
|
|
39
|
+
if (doNotCopy) {
|
|
40
|
+
return baseRecord.toObject();
|
|
41
|
+
}
|
|
33
42
|
|
|
34
43
|
debug(`Base fields: `, baseFields);
|
|
35
44
|
debug(`Source fields: `, sourceFields);
|
|
36
45
|
|
|
37
|
-
const
|
|
46
|
+
const baseCompareFields = baseFields.map(baseField => createCompareField(baseField));
|
|
47
|
+
const compareResultFields = compareFields(sourceFields, baseCompareFields);
|
|
38
48
|
const droppedUnwantedSubfield = checkDropSubfields(compareResultFields);
|
|
39
49
|
const droppedUnwantedFields = checkCopyUnlessFields(droppedUnwantedSubfield);
|
|
50
|
+
const swappedSubfields = checkSwapSubfieldCodes(droppedUnwantedFields);
|
|
51
|
+
const swappedTags = checkSwapTag(swappedSubfields);
|
|
40
52
|
debug('Fields to be copied');
|
|
41
|
-
debug(JSON.stringify(
|
|
53
|
+
debug(JSON.stringify(swappedTags));
|
|
42
54
|
|
|
43
55
|
// Add fields to base;
|
|
44
|
-
|
|
56
|
+
swappedTags.forEach(field => baseRecord.insertField(field));
|
|
45
57
|
return baseRecord.toObject();
|
|
46
58
|
//return copyFields(baseFields, sourceFields);
|
|
47
59
|
|
|
48
|
-
function compareFields(sourceFields,
|
|
60
|
+
function compareFields(sourceFields, baseCompareFields, uniqFields = []) {
|
|
49
61
|
const [sourceField, ...rest] = sourceFields;
|
|
50
62
|
if (sourceField === undefined) {
|
|
51
63
|
return uniqFields;
|
|
52
64
|
}
|
|
53
65
|
|
|
54
|
-
if (
|
|
55
|
-
return compareFields(rest,
|
|
66
|
+
if (baseCompareFields.length === 0) {
|
|
67
|
+
return compareFields(rest, baseCompareFields, [...uniqFields, sourceField]);
|
|
56
68
|
}
|
|
57
69
|
|
|
58
70
|
// Source and base are also compared for identicalness
|
|
59
71
|
// Non-identical fields are copied from source to base as duplicates
|
|
60
|
-
const
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
const unique = checkCompareFields(baseCompareFields, sourceComapareField);
|
|
72
|
+
const sourceCompareField = createCompareField(sourceField);
|
|
73
|
+
const unique = checkCompareFields(baseCompareFields, sourceCompareField);
|
|
64
74
|
|
|
65
75
|
debugCompare(`${JSON.stringify(sourceField)} ${unique ? 'is UNIQUE' : 'not UNIQUE'}`);
|
|
66
76
|
|
|
67
77
|
if (unique) {
|
|
68
|
-
return compareFields(rest,
|
|
78
|
+
return compareFields(rest, baseCompareFields, [...uniqFields, sourceField]);
|
|
69
79
|
}
|
|
70
80
|
|
|
71
|
-
return compareFields(rest,
|
|
81
|
+
return compareFields(rest, baseCompareFields, uniqFields);
|
|
72
82
|
|
|
73
|
-
function checkCompareFields(baseCompareFields,
|
|
74
|
-
|
|
75
|
-
if (baseCompareField === undefined) {
|
|
76
|
-
return true;
|
|
77
|
-
}
|
|
83
|
+
function checkCompareFields(baseCompareFields, sourceCompareField) {
|
|
84
|
+
let unique = true; // eslint-disable-line functional/no-let
|
|
78
85
|
|
|
79
|
-
|
|
80
|
-
debugCompare(`
|
|
81
|
-
return true;
|
|
82
|
-
}
|
|
86
|
+
baseCompareFields.forEach(baseCompareField => {
|
|
87
|
+
debugCompare(`Comparing ${JSON.stringify(sourceCompareField)} to ${JSON.stringify(baseCompareField)}}`);
|
|
83
88
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
89
|
+
if (sourceCompareField.value !== baseCompareField.value) {
|
|
90
|
+
debugCompare(`Value is different ${sourceCompareField.value} !== ${baseCompareField.value}`);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
88
93
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
94
|
+
if (sourceCompareField.ind1 !== baseCompareField.ind1) {
|
|
95
|
+
debugCompare(`Ind1 is different ${sourceCompareField.ind1} !== ${baseCompareField.ind1}`);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
93
98
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
+
if (sourceCompareField.ind2 !== baseCompareField.ind2) {
|
|
100
|
+
debugCompare(`Ind2 is different ${sourceCompareField.ind2} !== ${baseCompareField.ind2}`);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
99
103
|
|
|
100
|
-
|
|
104
|
+
if ('subfields' in sourceCompareField) {
|
|
105
|
+
const allFound = checkSubfields(sourceCompareField.subfields, baseCompareField.subfields);
|
|
106
|
+
debugCompare(`Subfields are different ${!allFound}`);
|
|
107
|
+
if (!allFound) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
unique = false;
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
unique = false;
|
|
116
|
+
return;
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
return unique;
|
|
101
120
|
}
|
|
102
121
|
|
|
103
122
|
function checkSubfields(sourceSubfields, baseSubfields) {
|
|
@@ -143,6 +162,44 @@ export default ({
|
|
|
143
162
|
}
|
|
144
163
|
}
|
|
145
164
|
|
|
165
|
+
function checkSwapTag(fields) {
|
|
166
|
+
if (swapTag.length > 0) {
|
|
167
|
+
return fields.map(field => ({...field, tag: swapTagsFunc(field.tag)}));
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return fields;
|
|
171
|
+
|
|
172
|
+
function swapTagsFunc(tag) {
|
|
173
|
+
const [foundRule] = swapTag.filter(rule => new RegExp(rule.from, 'u').test(tag));
|
|
174
|
+
|
|
175
|
+
if (foundRule === undefined) {
|
|
176
|
+
return tag;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
return foundRule.to;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function checkSwapSubfieldCodes(fields) {
|
|
184
|
+
if (swapSubfieldCode.length > 0) {
|
|
185
|
+
return fields.map(field => ({...field, subfields: swapSubfieldCodesFunc(field.subfields)}));
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return fields;
|
|
189
|
+
|
|
190
|
+
function swapSubfieldCodesFunc(subfields) {
|
|
191
|
+
return subfields.map(sub => {
|
|
192
|
+
const [foundRule] = swapSubfieldCode.filter(rule => rule.from === sub.code);
|
|
193
|
+
|
|
194
|
+
if (foundRule === undefined) {
|
|
195
|
+
return sub;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return {code: foundRule.to, value: sub.value};
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
146
203
|
function checkDropSubfields(fields) {
|
|
147
204
|
if (dropSubfields.length > 0) {
|
|
148
205
|
return fields.map(field => ({...field, subfields: dropSubfieldsFunc(field.subfields)}))
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {expect} from 'chai';
|
|
2
2
|
import {READERS} from '@natlibfi/fixura';
|
|
3
|
-
import {MarcRecord} from '@natlibfi/marc-record';
|
|
3
|
+
//import {MarcRecord} from '@natlibfi/marc-record';
|
|
4
4
|
import createReducer from './copy';
|
|
5
5
|
import generateTests from '@natlibfi/fixugen';
|
|
6
6
|
|
|
7
|
-
//
|
|
8
|
-
//
|
|
7
|
+
//import createDebugLogger from 'debug'; // <---
|
|
8
|
+
//const debug = createDebugLogger('@natlibfi/marc-record-merge/copy.spec.js'); // <---
|
|
9
9
|
|
|
10
10
|
generateTests({
|
|
11
11
|
callback,
|
|
@@ -27,22 +27,30 @@ function callback({
|
|
|
27
27
|
copyUnless = undefined,
|
|
28
28
|
excludeSubfields = undefined,
|
|
29
29
|
dropSubfields = undefined,
|
|
30
|
-
|
|
30
|
+
swapSubfieldCode = [],
|
|
31
|
+
swapTag = [],
|
|
32
|
+
doNotCopyIfFieldPresent = false
|
|
31
33
|
}) {
|
|
32
|
-
if (disabled) {
|
|
33
|
-
console.log('TEST DISABLED!'); // eslint-disable-line no-console
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
34
|
|
|
37
|
-
const base =
|
|
38
|
-
const source =
|
|
35
|
+
const base = getFixture('base.json');
|
|
36
|
+
const source = getFixture('source.json');
|
|
37
|
+
|
|
38
|
+
// const base = new MarcRecord(getFixture('base.json'), {subfieldValues: false});
|
|
39
|
+
// const source = new MarcRecord(getFixture('source.json'), {subfieldValues: false});
|
|
39
40
|
const tagPattern = new RegExp(tagPatternRegExp, 'u');
|
|
40
41
|
const expectedRecord = getFixture('merged.json');
|
|
41
42
|
|
|
42
|
-
const
|
|
43
|
+
const merged = createReducer({
|
|
44
|
+
tagPattern, compareTagsOnly, compareWithoutIndicators,
|
|
45
|
+
copyUnless, subfieldsMustBeIdentical, excludeSubfields,
|
|
46
|
+
dropSubfields, swapSubfieldCode, swapTag,
|
|
47
|
+
doNotCopyIfFieldPresent
|
|
48
|
+
})(base, source);
|
|
43
49
|
//debug(`*** mergedRecord: `, mergedRecord); //<--
|
|
44
|
-
//debug(`*** mergedRecord,Strfy: `, JSON.stringify(mergedRecord
|
|
50
|
+
//debug(`*** mergedRecord,Strfy: `, JSON.stringify(mergedRecord)); //<--
|
|
45
51
|
//debug(`*** expectedRecord: `, expectedRecord); //<--
|
|
46
52
|
//debug(`*** expectedRecord,Strfy: `, JSON.stringify(expectedRecord)); //<--
|
|
47
|
-
expect(
|
|
53
|
+
expect(merged.constructor.name).not.to.eql('MarcRecord');
|
|
54
|
+
expect(merged.constructor.name).to.eql('Object');
|
|
55
|
+
expect(merged).to.eql(expectedRecord);
|
|
48
56
|
}
|
package/src/reducers/select.js
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
import {normalizeSync} from 'normalize-diacritics';
|
|
2
2
|
import createDebugLogger from 'debug';
|
|
3
|
+
import {MarcRecord} from '@natlibfi/marc-record';
|
|
3
4
|
|
|
4
5
|
export function strictEquality(subfieldA, subfieldB) {
|
|
5
6
|
return subfieldA.code === subfieldB.code &&
|
|
6
|
-
|
|
7
|
+
subfieldA.value === subfieldB.value;
|
|
7
8
|
}
|
|
8
9
|
|
|
9
10
|
export function subsetEquality(subfieldA, subfieldB) {
|
|
10
11
|
return subfieldA.code === subfieldB.code &&
|
|
11
|
-
|
|
12
|
+
(subfieldA.value.indexOf(subfieldB.value) !== -1 || subfieldB.value.indexOf(subfieldA.value) !== -1);
|
|
12
13
|
}
|
|
13
14
|
// EqualityFunction can be either strictEquality or subsetEquality
|
|
14
15
|
export default ({tagPattern, equalityFunction = strictEquality}) => (base, source) => {
|
|
15
16
|
const debug = createDebugLogger('@natlibfi/marc-record-merge:select');
|
|
16
|
-
const
|
|
17
|
-
const
|
|
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);
|
|
18
21
|
const fieldTag = sourceFields.map(field => field.tag);
|
|
19
22
|
debug(`Comparing field ${fieldTag}`);
|
|
20
23
|
|
|
@@ -28,8 +28,12 @@ function callback({
|
|
|
28
28
|
console.log('TEST DISABLED!'); // eslint-disable-line no-console
|
|
29
29
|
return;
|
|
30
30
|
}
|
|
31
|
-
const base = new MarcRecord(getFixture('base.json'), {subfieldValues: false});
|
|
32
|
-
const source = new MarcRecord(getFixture('source.json'), {subfieldValues: false});
|
|
31
|
+
// const base = new MarcRecord(getFixture('base.json'), {subfieldValues: false});
|
|
32
|
+
// const source = new MarcRecord(getFixture('source.json'), {subfieldValues: false});
|
|
33
|
+
|
|
34
|
+
const base = getFixture('base.json');
|
|
35
|
+
const source = getFixture('source.json');
|
|
36
|
+
|
|
33
37
|
const tagPattern = new RegExp(tagPatternRegExp, 'u');
|
|
34
38
|
const expectedRecord = getFixture('merged.json');
|
|
35
39
|
const equalityFunction = useSubsetEquality ? subsetEquality : undefined;
|
|
@@ -41,5 +45,5 @@ function callback({
|
|
|
41
45
|
}
|
|
42
46
|
|
|
43
47
|
const mergedRecord = createReducer({tagPattern, equalityFunction})(base, source);
|
|
44
|
-
expect(mergedRecord
|
|
48
|
+
expect(mergedRecord).to.eql(expectedRecord);
|
|
45
49
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"leader": "01331cam a22003494i 4500",
|
|
3
|
+
"fields": [
|
|
4
|
+
{
|
|
5
|
+
"tag": "001",
|
|
6
|
+
"value": "007346734"
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
"tag": "010",
|
|
10
|
+
"ind1": " ",
|
|
11
|
+
"ind2": " ",
|
|
12
|
+
"subfields": [
|
|
13
|
+
{
|
|
14
|
+
"code": "a",
|
|
15
|
+
"value": "##2002021346"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"code": "b",
|
|
19
|
+
"value": "##2002021356"
|
|
20
|
+
}
|
|
21
|
+
]
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"tag": "010",
|
|
25
|
+
"ind1": " ",
|
|
26
|
+
"ind2": "1",
|
|
27
|
+
"subfields": [
|
|
28
|
+
{
|
|
29
|
+
"code": "a",
|
|
30
|
+
"value": "##2002021346"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"code": "b",
|
|
34
|
+
"value": "##2002021356"
|
|
35
|
+
}
|
|
36
|
+
]
|
|
37
|
+
}
|
|
38
|
+
]
|
|
39
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"leader": "01331cam a22003494i 4500",
|
|
3
|
+
"fields": [
|
|
4
|
+
{
|
|
5
|
+
"tag": "001",
|
|
6
|
+
"value": "007346734"
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
"tag": "010",
|
|
10
|
+
"ind1": " ",
|
|
11
|
+
"ind2": " ",
|
|
12
|
+
"subfields": [
|
|
13
|
+
{
|
|
14
|
+
"code": "a",
|
|
15
|
+
"value": "##2002021346"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"code": "b",
|
|
19
|
+
"value": "##2002021356"
|
|
20
|
+
}
|
|
21
|
+
]
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"tag": "010",
|
|
25
|
+
"ind1": " ",
|
|
26
|
+
"ind2": "1",
|
|
27
|
+
"subfields": [
|
|
28
|
+
{
|
|
29
|
+
"code": "a",
|
|
30
|
+
"value": "##2002021346"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"code": "b",
|
|
34
|
+
"value": "##2002021356"
|
|
35
|
+
}
|
|
36
|
+
]
|
|
37
|
+
}
|
|
38
|
+
]
|
|
39
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"leader": "01331cam a22003494i 4500",
|
|
3
|
+
"fields": [
|
|
4
|
+
{
|
|
5
|
+
"tag": "001",
|
|
6
|
+
"value": "007346734"
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
"tag": "010",
|
|
10
|
+
"ind1": " ",
|
|
11
|
+
"ind2": "1",
|
|
12
|
+
"subfields": [
|
|
13
|
+
{
|
|
14
|
+
"code": "a",
|
|
15
|
+
"value": "##2002021346"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"code": "b",
|
|
19
|
+
"value": "##2002021356"
|
|
20
|
+
}
|
|
21
|
+
]
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"leader": "01331cam a22003494i 4500",
|
|
3
|
+
"fields": [
|
|
4
|
+
{
|
|
5
|
+
"tag": "001",
|
|
6
|
+
"value": "007346734"
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
"tag": "007",
|
|
10
|
+
"value": "ou"
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"tag": "007",
|
|
14
|
+
"value": "vf^cbaho|"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"tag": "010",
|
|
18
|
+
"ind1": " ",
|
|
19
|
+
"ind2": " ",
|
|
20
|
+
"subfields": [
|
|
21
|
+
{
|
|
22
|
+
"code": "a",
|
|
23
|
+
"value": "##2002021346"
|
|
24
|
+
}
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
]
|
|
28
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"leader": "01331cam a22003494i 4500",
|
|
3
|
+
"fields": [
|
|
4
|
+
{
|
|
5
|
+
"tag": "001",
|
|
6
|
+
"value": "007346734"
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
"tag": "007",
|
|
10
|
+
"value": "ou"
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"tag": "007",
|
|
14
|
+
"value": "vf^cbaho|"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"tag": "010",
|
|
18
|
+
"ind1": " ",
|
|
19
|
+
"ind2": " ",
|
|
20
|
+
"subfields": [
|
|
21
|
+
{
|
|
22
|
+
"code": "a",
|
|
23
|
+
"value": "##2002021346"
|
|
24
|
+
}
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
]
|
|
28
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"leader": "01331cam a22003494i 4500",
|
|
3
|
+
"fields": [
|
|
4
|
+
{
|
|
5
|
+
"tag": "001",
|
|
6
|
+
"value": "007346734"
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
"tag": "007",
|
|
10
|
+
"value": "vf^cbaho|"
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"tag": "010",
|
|
14
|
+
"ind1": " ",
|
|
15
|
+
"ind2": " ",
|
|
16
|
+
"subfields": [
|
|
17
|
+
{
|
|
18
|
+
"code": "a",
|
|
19
|
+
"value": "##2002021346"
|
|
20
|
+
}
|
|
21
|
+
]
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
}
|