@natlibfi/marc-record-merge 6.0.0-beta.2 → 6.0.0-beta.4
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 +92 -2
- package/dist/index.js +2 -37
- package/dist/index.js.map +1 -1
- package/dist/reducers/copy.js +246 -111
- package/dist/reducers/copy.js.map +1 -1
- package/dist/reducers/copy.spec.js +53 -99
- package/dist/reducers/copy.spec.js.map +1 -1
- package/dist/reducers/index.js +0 -27
- package/dist/reducers/index.js.map +1 -1
- package/dist/reducers/select.js +2 -48
- package/dist/reducers/select.js.map +1 -1
- package/dist/reducers/select.spec.js +49 -83
- package/dist/reducers/select.spec.js.map +1 -1
- package/package.json +27 -22
- package/src/index.js +1 -33
- package/src/reducers/copy.js +253 -119
- package/src/reducers/copy.spec.js +41 -65
- package/src/reducers/index.js +0 -27
- package/src/reducers/select.js +1 -47
- package/src/reducers/select.spec.js +37 -58
- package/test-fixtures/reducers/copy/{01/base.json → basic copy/01/base.json } +1 -1
- package/test-fixtures/reducers/copy/{01 → basic copy/01}/merged.json +0 -0
- package/test-fixtures/reducers/copy/basic copy/01/metadata.json +5 -0
- package/test-fixtures/reducers/copy/{01 → basic copy/01}/source.json +0 -0
- package/test-fixtures/reducers/copy/{02/source.json → basic copy/02/base.json} +0 -0
- package/test-fixtures/reducers/copy/{02 → basic copy/02}/merged.json +0 -0
- package/test-fixtures/reducers/copy/basic copy/02/metadata.json +5 -0
- package/test-fixtures/reducers/copy/{02/base.json → basic copy/02/source.json } +1 -1
- package/test-fixtures/reducers/copy/{03/base.json → basic copy/03/base.json } +1 -1
- package/test-fixtures/reducers/copy/{03 → basic copy/03}/merged.json +0 -0
- package/test-fixtures/reducers/copy/basic copy/03/metadata.json +5 -0
- package/test-fixtures/reducers/copy/{03 → basic copy/03}/source.json +0 -0
- package/test-fixtures/reducers/copy/{05/base.json → basic copy/04/base.json } +1 -1
- package/test-fixtures/reducers/copy/{04/merged.json → basic copy/04/merged.json } +1 -1
- package/test-fixtures/reducers/copy/basic copy/04/metadata.json +5 -0
- package/test-fixtures/reducers/copy/{04/source.json → basic copy/04/source.json } +1 -1
- package/test-fixtures/reducers/copy/{04/base.json → basic copy/05/base.json } +1 -1
- package/test-fixtures/reducers/copy/{05 → basic copy/05}/merged.json +0 -0
- package/test-fixtures/reducers/copy/basic copy/05/metadata.json +5 -0
- package/test-fixtures/reducers/copy/{05 → basic copy/05}/source.json +0 -0
- package/test-fixtures/reducers/copy/basic copy/06/base.json +24 -0
- package/test-fixtures/reducers/copy/basic copy/06/merged.json +39 -0
- package/test-fixtures/reducers/copy/basic copy/06/metadata.json +5 -0
- package/test-fixtures/reducers/copy/basic copy/06/source.json +24 -0
- package/test-fixtures/reducers/copy/{06 → compareTagsOnly/01}/base.json +0 -0
- package/test-fixtures/reducers/copy/{06 → compareTagsOnly/01}/merged.json +0 -0
- package/test-fixtures/reducers/copy/compareTagsOnly/01/metadata.json +6 -0
- package/test-fixtures/reducers/copy/{06 → compareTagsOnly/01}/source.json +0 -0
- package/test-fixtures/reducers/copy/{09 → compareTagsOnly/02}/base.json +0 -0
- package/test-fixtures/reducers/copy/{09 → compareTagsOnly/02}/merged.json +0 -0
- package/test-fixtures/reducers/copy/compareTagsOnly/02/metadata.json +6 -0
- package/test-fixtures/reducers/copy/{09 → compareTagsOnly/02}/source.json +0 -0
- package/test-fixtures/reducers/copy/compareWithoutIndicators/01/base.json +24 -0
- package/test-fixtures/reducers/copy/compareWithoutIndicators/01/merged.json +24 -0
- package/test-fixtures/reducers/copy/compareWithoutIndicators/01/metadata.json +6 -0
- package/test-fixtures/reducers/copy/compareWithoutIndicators/01/source.json +24 -0
- package/test-fixtures/reducers/copy/compareWithoutIndicators/02/base.json +24 -0
- package/test-fixtures/reducers/copy/compareWithoutIndicators/02/merged.json +39 -0
- package/test-fixtures/reducers/copy/compareWithoutIndicators/02/metadata.json +6 -0
- package/test-fixtures/reducers/copy/compareWithoutIndicators/02/source.json +24 -0
- package/test-fixtures/reducers/copy/copyUnless/01/base.json +9 -0
- package/test-fixtures/reducers/copy/copyUnless/01/merged.json +24 -0
- package/test-fixtures/reducers/copy/copyUnless/01/metadata.json +6 -0
- package/test-fixtures/reducers/copy/copyUnless/01/source.json +47 -0
- package/test-fixtures/reducers/copy/{08 → dropSubfields/01}/base.json +0 -0
- package/test-fixtures/reducers/copy/{08 → dropSubfields/01}/merged.json +8 -0
- package/test-fixtures/reducers/copy/dropSubfields/01/metadata.json +6 -0
- package/test-fixtures/reducers/copy/{08 → dropSubfields/01}/source.json +0 -0
- package/test-fixtures/reducers/copy/dropSubfields/02/base.json +43 -0
- package/test-fixtures/reducers/copy/dropSubfields/02/merged.json +58 -0
- package/test-fixtures/reducers/copy/dropSubfields/02/metadata.json +6 -0
- package/test-fixtures/reducers/copy/dropSubfields/02/source.json +32 -0
- package/test-fixtures/reducers/copy/dropSubfields/03/base.json +43 -0
- package/test-fixtures/reducers/copy/dropSubfields/03/merged.json +58 -0
- package/test-fixtures/reducers/copy/dropSubfields/03/metadata.json +6 -0
- package/test-fixtures/reducers/copy/dropSubfields/03/source.json +32 -0
- package/test-fixtures/reducers/copy/dropSubfields/04/base.json +43 -0
- package/test-fixtures/reducers/copy/dropSubfields/04/merged.json +43 -0
- package/test-fixtures/reducers/copy/dropSubfields/04/metadata.json +6 -0
- package/test-fixtures/reducers/copy/dropSubfields/04/source.json +32 -0
- package/test-fixtures/reducers/copy/{07 → excludeSubfields/01}/base.json +0 -0
- package/test-fixtures/reducers/copy/{07 → excludeSubfields/01}/merged.json +0 -0
- package/test-fixtures/reducers/copy/excludeSubfields/01/metadata.json +9 -0
- package/test-fixtures/reducers/copy/{07 → excludeSubfields/01}/source.json +0 -0
- package/test-fixtures/reducers/copy/subfieldsMustBeIdentical/01/base.json +24 -0
- package/test-fixtures/reducers/copy/subfieldsMustBeIdentical/01/merged.json +39 -0
- package/test-fixtures/reducers/copy/subfieldsMustBeIdentical/01/metadata.json +6 -0
- package/test-fixtures/reducers/copy/subfieldsMustBeIdentical/01/source.json +24 -0
- package/test-fixtures/reducers/copy/subfieldsMustBeIdentical/02/base.json +24 -0
- package/test-fixtures/reducers/copy/subfieldsMustBeIdentical/02/merged.json +24 -0
- package/test-fixtures/reducers/copy/subfieldsMustBeIdentical/02/metadata.json +6 -0
- package/test-fixtures/reducers/copy/subfieldsMustBeIdentical/02/source.json +24 -0
- package/test-fixtures/reducers/copy/subfieldsMustBeIdentical/03/base.json +28 -0
- package/test-fixtures/reducers/copy/subfieldsMustBeIdentical/03/merged.json +43 -0
- package/test-fixtures/reducers/copy/subfieldsMustBeIdentical/03/metadata.json +6 -0
- package/test-fixtures/reducers/copy/subfieldsMustBeIdentical/03/source.json +24 -0
- package/test-fixtures/reducers/copy/subfieldsMustBeIdentical/04/base.json +28 -0
- package/test-fixtures/reducers/copy/subfieldsMustBeIdentical/04/merged.json +28 -0
- package/test-fixtures/reducers/copy/subfieldsMustBeIdentical/04/metadata.json +6 -0
- package/test-fixtures/reducers/copy/subfieldsMustBeIdentical/04/source.json +24 -0
- package/test-fixtures/reducers/copy/subfieldsMustBeIdentical/05/base.json +20 -0
- package/test-fixtures/reducers/copy/subfieldsMustBeIdentical/05/merged.json +35 -0
- package/test-fixtures/reducers/copy/subfieldsMustBeIdentical/05/metadata.json +6 -0
- package/test-fixtures/reducers/copy/subfieldsMustBeIdentical/05/source.json +24 -0
- package/test-fixtures/reducers/copy/subfieldsMustBeIdentical/06/base.json +20 -0
- package/test-fixtures/reducers/copy/subfieldsMustBeIdentical/06/merged.json +35 -0
- package/test-fixtures/reducers/copy/subfieldsMustBeIdentical/06/metadata.json +6 -0
- package/test-fixtures/reducers/copy/subfieldsMustBeIdentical/06/source.json +24 -0
- package/test-fixtures/reducers/metadata.json +5 -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/metadata.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/metadata.json +4 -0
- package/.nyc_output/72717fff-b4ac-4aef-a145-37cae88e07f8.json +0 -1
- package/.nyc_output/processinfo/72717fff-b4ac-4aef-a145-37cae88e07f8.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 -500
- 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 -500
- 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 -539
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -170
- package/coverage/lcov.info +0 -274
- package/coverage/prettify.css +0 -1
- package/coverage/prettify.js +0 -2
- package/coverage/select.js.html +0 -539
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +0 -170
- package/test-fixtures/reducers/copy/01/tagPattern.txt +0 -1
- package/test-fixtures/reducers/copy/02/tagPattern.txt +0 -1
- package/test-fixtures/reducers/copy/03/tagPattern.txt +0 -1
- package/test-fixtures/reducers/copy/04/tagPattern.txt +0 -1
- package/test-fixtures/reducers/copy/05/tagPattern.txt +0 -1
- package/test-fixtures/reducers/copy/06/compareTagsOnly.txt +0 -1
- package/test-fixtures/reducers/copy/06/tagPattern.txt +0 -1
- package/test-fixtures/reducers/copy/07/excludeSubfields.json +0 -1
- package/test-fixtures/reducers/copy/07/tagPattern.txt +0 -1
- package/test-fixtures/reducers/copy/08/dropSubfields.json +0 -1
- package/test-fixtures/reducers/copy/08/tagPattern.txt +0 -1
- package/test-fixtures/reducers/copy/09/compareTagsOnly.txt +0 -1
- package/test-fixtures/reducers/copy/09/tagPattern.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/test-fixtures/reducers/select/14/pattern.txt +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"copy.spec.js","names":["generateTests","callback","path","__dirname","useMetadataFile","recurse","fixura","reader","READERS","JSON","failWhenNotFound","getFixture","tagPatternRegExp","compareTagsOnly","compareWithoutIndicators","subfieldsMustBeIdentical","copyUnless","undefined","excludeSubfields","dropSubfields","disabled","console","log","base","MarcRecord","subfieldValues","source","tagPattern","RegExp","expectedRecord","mergedRecord","createReducer","expect","to","eql"],"sources":["../../src/reducers/copy.spec.js"],"sourcesContent":["import {expect} from 'chai';\nimport {READERS} from '@natlibfi/fixura';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport createReducer from './copy';\nimport generateTests from '@natlibfi/fixugen';\n\n// import createDebugLogger from 'debug'; // <---\n// const debug = createDebugLogger('@natlibfi/marc-record-merge/copy.spec.js'); // <---\n\ngenerateTests({\n callback,\n path: [__dirname, '..', '..', 'test-fixtures', 'reducers', 'copy'],\n useMetadataFile: true,\n recurse: true,\n fixura: {\n reader: READERS.JSON,\n failWhenNotFound: false\n }\n});\n\nfunction callback({\n getFixture,\n tagPatternRegExp,\n compareTagsOnly = false,\n compareWithoutIndicators = false,\n subfieldsMustBeIdentical = false,\n copyUnless = undefined,\n excludeSubfields = undefined,\n dropSubfields = undefined,\n disabled = false\n}) {\n if (disabled) {\n console.log('TEST DISABLED!'); // eslint-disable-line no-console\n return;\n }\n\n const base = new MarcRecord(getFixture('base.json'), {subfieldValues: false});\n const source = new MarcRecord(getFixture('source.json'), {subfieldValues: false});\n const tagPattern = new RegExp(tagPatternRegExp, 'u');\n const expectedRecord = getFixture('merged.json');\n\n const mergedRecord = createReducer({tagPattern, compareTagsOnly, compareWithoutIndicators, copyUnless, subfieldsMustBeIdentical, excludeSubfields, dropSubfields})(base, source);\n //debug(`*** mergedRecord: `, mergedRecord); //<--\n //debug(`*** mergedRecord,Strfy: `, JSON.stringify(mergedRecord.toObject())); //<--\n //debug(`*** expectedRecord: `, expectedRecord); //<--\n //debug(`*** expectedRecord,Strfy: `, JSON.stringify(expectedRecord)); //<--\n expect(mergedRecord).to.eql(expectedRecord);\n}\n"],"mappings":";;AAAA;;AACA;;AACA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YD;EACA;EACA;EACA;;EACA,IAAAM,YAAA,EAAOF,YAAP,EAAqBG,EAArB,CAAwBC,GAAxB,CAA4BL,cAA5B;AACD"}
|
package/dist/reducers/index.js
CHANGED
|
@@ -15,33 +15,6 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
|
15
15
|
|
|
16
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
17
|
|
|
18
|
-
/**
|
|
19
|
-
*
|
|
20
|
-
* @licstart The following is the entire license notice for the JavaScript code in this file.
|
|
21
|
-
*
|
|
22
|
-
* Merge MARC records
|
|
23
|
-
*
|
|
24
|
-
* Copyright (C) 2015-2019 University Of Helsinki (The National Library Of Finland)
|
|
25
|
-
*
|
|
26
|
-
* This file is part of marc-record-merge-js
|
|
27
|
-
|
|
28
|
-
* marc-record-merge-js program is free software: you can redistribute it and/or modify
|
|
29
|
-
* it under the terms of the GNU Lesser General Public License as
|
|
30
|
-
* published by the Free Software Foundation, either version 3 of the
|
|
31
|
-
* License, or (at your option) any later version.
|
|
32
|
-
*
|
|
33
|
-
* marc-record-merge-js is distributed in the hope that it will be useful,
|
|
34
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
35
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
36
|
-
* GNU Lesser General Public License for more details.
|
|
37
|
-
*
|
|
38
|
-
* You should have received a copy of the GNU Lesser General Public License
|
|
39
|
-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
40
|
-
*
|
|
41
|
-
* @licend The above is the entire license notice
|
|
42
|
-
* for the JavaScript code in this file.
|
|
43
|
-
*
|
|
44
|
-
*/
|
|
45
18
|
var _default = {
|
|
46
19
|
copy: _copy.default,
|
|
47
20
|
select: _select.default,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.js","names":["copy","select","strictEquality","subsetEquality"],"sources":["../../src/reducers/index.js"],"sourcesContent":["import copy from './copy';\nimport select, {strictEquality, subsetEquality} from './select';\n\nexport default {copy, select, strictEquality, subsetEquality};\n"],"mappings":";;;;;;;AAAA;;AACA;;;;;;;;eAEe;EAACA,IAAI,EAAJA,aAAD;EAAOC,MAAM,EAANA,eAAP;EAAeC,cAAc,EAAdA,sBAAf;EAA+BC,cAAc,EAAdA;AAA/B,C"}
|
package/dist/reducers/select.js
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
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
9
|
|
|
10
10
|
var _normalizeDiacritics = require("normalize-diacritics");
|
|
11
11
|
|
|
@@ -13,52 +13,6 @@ var _debug = _interopRequireDefault(require("debug"));
|
|
|
13
13
|
|
|
14
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
15
|
|
|
16
|
-
/**
|
|
17
|
-
*
|
|
18
|
-
* @licstart The following is the entire license notice for the JavaScript code in this file.
|
|
19
|
-
*
|
|
20
|
-
* Merge MARC records
|
|
21
|
-
*
|
|
22
|
-
* Copyright (C) 2015-2019 University Of Helsinki (The National Library Of Finland)
|
|
23
|
-
*
|
|
24
|
-
* This file is part of marc-record-merge-js
|
|
25
|
-
|
|
26
|
-
* marc-record-merge-js program is free software: you can redistribute it and/or modify
|
|
27
|
-
* it under the terms of the GNU Lesser General Public License as
|
|
28
|
-
* published by the Free Software Foundation, either version 3 of the
|
|
29
|
-
* License, or (at your option) any later version.
|
|
30
|
-
*
|
|
31
|
-
* marc-record-merge-js is distributed in the hope that it will be useful,
|
|
32
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
33
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
34
|
-
* GNU Lesser General Public License for more details.
|
|
35
|
-
*
|
|
36
|
-
* You should have received a copy of the GNU Lesser General Public License
|
|
37
|
-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
38
|
-
*
|
|
39
|
-
* @licend The above is the entire license notice
|
|
40
|
-
* for the JavaScript code in this file.
|
|
41
|
-
*
|
|
42
|
-
*/
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Test 01: The field is a control field (contains 'value') --> error message
|
|
46
|
-
* Test 02: If there are multiple fields, return base
|
|
47
|
-
* Test 03: Base and source tags are equal for one field --> return base
|
|
48
|
-
* Test 04: Base and source tags are not equal --> return base
|
|
49
|
-
* Note: to test for this, tagPattern has to allow two tags,
|
|
50
|
-
* otherwise the unequal tag does not even pass source.get(tagPattern)
|
|
51
|
-
* Test 05: Normalize subfield values (base and source are equal) --> return base
|
|
52
|
-
* Test 06: Two subfields, both equal --> return base
|
|
53
|
-
* Test 07: Two subfields, same codes, values of source are subsets of values of base --> replaceBasefieldWithSourcefield
|
|
54
|
-
* Test 08: Two subfields, one is a subset, one has a different code --> return base
|
|
55
|
-
* Test 09: Two subfields, same codes, values are not subsets --> return base
|
|
56
|
-
* Test 10: sourceField is a proper superset of baseField (subfields a and b are equal, c is new) --> replaceBasefieldWithSourcefield
|
|
57
|
-
* Test 11: sourceField is not a proper superset of baseField (different values in a and b, also new subfield c) --> return base
|
|
58
|
-
* Test 12: sourceField is a proper superset of baseField (base values a and b are subsets of source values a and b, c is new in source) --> replaceBasefieldWithSourcefield
|
|
59
|
-
* Test 13: Opposite of test 12, baseField is a proper superset of sourceField --> return base
|
|
60
|
-
* Test 14: Normalization test with Cyrillic characters
|
|
61
|
-
*/
|
|
62
16
|
function strictEquality(subfieldA, subfieldB) {
|
|
63
17
|
return subfieldA.code === subfieldB.code && subfieldA.value === subfieldB.value;
|
|
64
18
|
}
|
|
@@ -72,7 +26,7 @@ var _default = ({
|
|
|
72
26
|
tagPattern,
|
|
73
27
|
equalityFunction = strictEquality
|
|
74
28
|
}) => (base, source) => {
|
|
75
|
-
const debug = (0, _debug.default)('@natlibfi/marc-record-merge');
|
|
29
|
+
const debug = (0, _debug.default)('@natlibfi/marc-record-merge:select');
|
|
76
30
|
const baseFields = base.get(tagPattern);
|
|
77
31
|
const sourceFields = source.get(tagPattern);
|
|
78
32
|
const fieldTag = sourceFields.map(field => field.tag);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/reducers/select.js"],"names":["strictEquality","subfieldA","subfieldB","code","value","subsetEquality","indexOf","tagPattern","equalityFunction","base","source","debug","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","toLowerCase","replace","trim"],"mappings":";;;;;;;;;AA8CA;;AACA;;;;AA/CA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAKO,SAASA,cAAT,CAAwBC,SAAxB,EAAmCC,SAAnC,EAA8C;AACnD,SAAOD,SAAS,CAACE,IAAV,KAAmBD,SAAS,CAACC,IAA7B,IACPF,SAAS,CAACG,KAAV,KAAoBF,SAAS,CAACE,KAD9B;AAED;;AAEM,SAASC,cAAT,CAAwBJ,SAAxB,EAAmCC,SAAnC,EAA8C;AACnD,SAAOD,SAAS,CAACE,IAAV,KAAmBD,SAAS,CAACC,IAA7B,KACNF,SAAS,CAACG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EAA0B,CAA1B,EAA6BrB,WAA7B,EAF6C,CAEF;;AAC3CX,IAAAA,KAAK,CAAE,oDAAF,CAAL;AACA,WAAOF,IAAP;AACD;;AAED,WAASU,cAAT,CAAwByB,MAAxB,EAAgC;AAC9B,UAAMG,aAAa,GAAGH,MAAM,CAAC5B,GAAP,CAAWC,KAAK,IAAI;AACxC,UAAI,WAAWA,KAAf,EAAsB;AAAE;AACtB,cAAM,IAAI+B,KAAJ,CAAU,4CAAV,CAAN;AACD;;AACD,aAAO/B,KAAP;AACD,KALqB,CAAtB;AAMA,WAAO8B,aAAP;AACD;;AAED,WAASpB,sBAAT,CAAgCvB,KAAhC,EAAuC;AACrC;AACA,UAAM6C,WAAW,GAAG,gCAApB;AACA,WAAO,wCAAc7C,KAAd,EAAqB8C,WAArB,GAAmCC,OAAnC,CAA2CF,WAA3C,EAAwD,EAAxD,EAA4D,GAA5D,EAAiEE,OAAjE,CAAyE,OAAzE,EAAkF,GAAlF,EAAuFC,IAAvF,EAAP;AACD;AACF,C","sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Merge MARC records\n*\n* Copyright (C) 2015-2019 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of marc-record-merge-js\n\n* marc-record-merge-js program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Lesser General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* marc-record-merge-js is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Lesser General Public License for more details.\n*\n* You should have received a copy of the GNU Lesser General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n/**\n * Test 01: The field is a control field (contains 'value') --> error message\n * Test 02: If there are multiple fields, return base\n * Test 03: Base and source tags are equal for one field --> return base\n * Test 04: Base and source tags are not equal --> return base\n * Note: to test for this, tagPattern has to allow two tags,\n * otherwise the unequal tag does not even pass source.get(tagPattern)\n * Test 05: Normalize subfield values (base and source are equal) --> return base\n * Test 06: Two subfields, both equal --> return base\n * Test 07: Two subfields, same codes, values of source are subsets of values of base --> replaceBasefieldWithSourcefield\n * Test 08: Two subfields, one is a subset, one has a different code --> return base\n * Test 09: Two subfields, same codes, values are not subsets --> return base\n * Test 10: sourceField is a proper superset of baseField (subfields a and b are equal, c is new) --> replaceBasefieldWithSourcefield\n * Test 11: sourceField is not a proper superset of baseField (different values in a and b, also new subfield c) --> return base\n * Test 12: sourceField is a proper superset of baseField (base values a and b are subsets of source values a and b, c is new in source) --> replaceBasefieldWithSourcefield\n * Test 13: Opposite of test 12, baseField is a proper superset of sourceField --> return base\n * Test 14: Normalization test with Cyrillic characters\n */\n\nimport {normalizeSync} from 'normalize-diacritics';\nimport createDebugLogger from 'debug';\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');\n const baseFields = base.get(tagPattern);\n const sourceFields = source.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"],"file":"select.js"}
|
|
1
|
+
{"version":3,"file":"select.js","names":["strictEquality","subfieldA","subfieldB","code","value","subsetEquality","indexOf","tagPattern","equalityFunction","base","source","debug","createDebugLogger","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';\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 baseFields = base.get(tagPattern);\n const sourceFields = source.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;;;;AAEO,SAASA,cAAT,CAAwBC,SAAxB,EAAmCC,SAAnC,EAA8C;EACnD,OAAOD,SAAS,CAACE,IAAV,KAAmBD,SAAS,CAACC,IAA7B,IACPF,SAAS,CAACG,KAAV,KAAoBF,SAAS,CAACE,KAD9B;AAED;;AAEM,SAASC,cAAT,CAAwBJ,SAAxB,EAAmCC,SAAnC,EAA8C;EACnD,OAAOD,SAAS,CAACE,IAAV,KAAmBD,SAAS,CAACC,IAA7B,KACNF,SAAS,CAACG,KAAV,CAAgBE,OAAhB,CAAwBJ,SAAS,CAACE,KAAlC,MAA6C,CAAC,CAA9C,IAAmDF,SAAS,CAACE,KAAV,CAAgBE,OAAhB,CAAwBL,SAAS,CAACG,KAAlC,MAA6C,CAAC,CAD3F,CAAP;AAED,C,CACD;;;eACe,CAAC;EAACG,UAAD;EAAaC,gBAAgB,GAAGR;AAAhC,CAAD,KAAqD,CAACS,IAAD,EAAOC,MAAP,KAAkB;EACpF,MAAMC,KAAK,GAAG,IAAAC,cAAA,EAAkB,oCAAlB,CAAd;EACA,MAAMC,UAAU,GAAGJ,IAAI,CAACK,GAAL,CAASP,UAAT,CAAnB;EACA,MAAMQ,YAAY,GAAGL,MAAM,CAACI,GAA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AP;EACD;AACF,C"}
|
|
@@ -1,102 +1,68 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _chai =
|
|
4
|
-
|
|
5
|
-
var _fs = _interopRequireDefault(require("fs"));
|
|
6
|
-
|
|
7
|
-
var _path = _interopRequireDefault(require("path"));
|
|
3
|
+
var _chai = require("chai");
|
|
8
4
|
|
|
9
5
|
var _marcRecord = require("@natlibfi/marc-record");
|
|
10
6
|
|
|
11
7
|
var _select = _interopRequireWildcard(require("./select"));
|
|
12
8
|
|
|
13
|
-
var _fixura =
|
|
14
|
-
|
|
15
|
-
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); }
|
|
9
|
+
var _fixura = require("@natlibfi/fixura");
|
|
16
10
|
|
|
17
|
-
|
|
11
|
+
var _fixugen = _interopRequireDefault(require("@natlibfi/fixugen"));
|
|
18
12
|
|
|
19
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
20
14
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
|
15
|
+
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); }
|
|
16
|
+
|
|
17
|
+
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; }
|
|
30
18
|
|
|
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
|
-
*/
|
|
48
19
|
_marcRecord.MarcRecord.setValidationOptions({
|
|
49
20
|
subfieldValues: false
|
|
50
21
|
});
|
|
51
22
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
} = (0, _fixura.default)({
|
|
63
|
-
root: [fixturesPath, subDir],
|
|
64
|
-
reader: _fixura.READERS.JSON,
|
|
65
|
-
failWhenNotFound: false
|
|
66
|
-
});
|
|
67
|
-
it(subDir, () => {
|
|
68
|
-
const base = new _marcRecord.MarcRecord(getFixture('base.json'));
|
|
69
|
-
const source = new _marcRecord.MarcRecord(getFixture('source.json'));
|
|
70
|
-
const tagPattern = 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(); // Bypass expected error in testing
|
|
80
|
-
|
|
81
|
-
if (expectedError) {
|
|
82
|
-
expect(() => _select.default.to.throw(Error, 'control field'));
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const mergedRecord = (0, _select.default)({
|
|
87
|
-
tagPattern,
|
|
88
|
-
equalityFunction
|
|
89
|
-
})(base, source);
|
|
90
|
-
expect(mergedRecord.toObject()).to.eql(expectedRecord); // Choose which equality function to use
|
|
23
|
+
(0, _fixugen.default)({
|
|
24
|
+
callback,
|
|
25
|
+
path: [__dirname, '..', '..', 'test-fixtures', 'reducers', 'select'],
|
|
26
|
+
useMetadataFile: true,
|
|
27
|
+
recurse: false,
|
|
28
|
+
fixura: {
|
|
29
|
+
reader: _fixura.READERS.JSON,
|
|
30
|
+
failWhenNotFound: false
|
|
31
|
+
}
|
|
32
|
+
});
|
|
91
33
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
34
|
+
function callback({
|
|
35
|
+
getFixture,
|
|
36
|
+
disabled = false,
|
|
37
|
+
tagPatternRegExp = false,
|
|
38
|
+
expectedError = false,
|
|
39
|
+
useSubsetEquality = false
|
|
40
|
+
}) {
|
|
41
|
+
if (disabled) {
|
|
42
|
+
console.log('TEST DISABLED!'); // eslint-disable-line no-console
|
|
43
|
+
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const base = new _marcRecord.MarcRecord(getFixture('base.json'), {
|
|
48
|
+
subfieldValues: false
|
|
100
49
|
});
|
|
101
|
-
|
|
50
|
+
const source = new _marcRecord.MarcRecord(getFixture('source.json'), {
|
|
51
|
+
subfieldValues: false
|
|
52
|
+
});
|
|
53
|
+
const tagPattern = new RegExp(tagPatternRegExp, 'u');
|
|
54
|
+
const expectedRecord = getFixture('merged.json');
|
|
55
|
+
const equalityFunction = useSubsetEquality ? _select.subsetEquality : undefined; // Bypass expected error in testing
|
|
56
|
+
|
|
57
|
+
if (expectedError) {
|
|
58
|
+
(0, _chai.expect)(() => _select.default.to.throw(Error, 'control field'));
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const mergedRecord = (0, _select.default)({
|
|
63
|
+
tagPattern,
|
|
64
|
+
equalityFunction
|
|
65
|
+
})(base, source);
|
|
66
|
+
(0, _chai.expect)(mergedRecord.toObject()).to.eql(expectedRecord);
|
|
67
|
+
}
|
|
102
68
|
//# 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","toObject","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 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.toObject()).to.eql(expectedRecord);\n}\n"],"mappings":";;AAAA;;AACA;;AACA;;AACA;;AACA;;;;;;;;AAEAA,sBAAA,CAAWC,oBAAX,CAAgC;EAACC,cAAc,EAAE;AAAjB,CAAhC;;AAEA,IAAAC,gBAAA,EAAc;EACZC,QADY;EAEZC,IAAI,EAAE,CAACC,SAAD,EAAY,IAAZ,EAAkB,IAAlB,EAAwB,eAAxB,EAAyC,UAAzC,EAAqD,QAArD,CAFM;EAGZC,eAAe,EAAE,IAHL;EAIZC,OAAO,EAAE,KAJG;EAKZC,MAAM,EAAE;IACNC,MAAM,EAAEC,eAAA,CAAQC,IADV;IAENC,gBAAgB,EAAE;EAFZ;AALI,CAAd;;AAWA,SAAST,QAAT,CAAkB;EAChBU,UADgB;EAEhBC,QAAQ,GAAG,KAFK;EAGhBC,gBAAgB,GAAG,KAHH;EAIhBC,aAAa,GAAG,KAJA;EAKhBC,iBAAiB,GAAG;AALJ,CAAlB,EAMG;EACD,IAAIH,QAAJ,EAAc;IACZI,OAAO,CAACC,GAAR,CAAY,gBAAZ,EADY,CACmB;;IAC/B;EACD;;EACD,MAAMC,IAAI,GAAG,IAAIrB,sBAAJ,CAAec,UAAU,CAAC,WAAD,CAAzB,EAAwC;IAACZ,cAAc,EAAE;EAAjB,CAAxC,CAAb;EACA,MAAMoB,MAAM,GAAG,IAAItB,sBAAJ,CAAec,UAAU,CAAC,aAAD,CAAzB,EAA0C;IAACZ,cAAc,EAAE;EAAjB,CAA1C,CAAf;EACA,MAAMqB,UAAU,GAAG,IAAIC,MAAJ,CAAWR,gBAAX,EAA6B,GAA7B,CAAnB;EACA,MAAMS,cAAc,GAAGX,UAAU,CAAC,aAAD,CAAjC;EACA,MAAMY,gBAAgB,GAAGR,iBAAiB,GAAGS,sBAAH,GAAoBC,SAA9D,CATC,CAWD;;EACA,IAAIX,aAAJ,EAAmB;IACjB,IAAAY,YAAA,EAAO,MAAMC,eAAA,CAAcC,EAAd,CAAiBC,KAAjB,CAAuBC,KAAvB,EAA8B,eAA9B,CAAb;IACA;EACD;;EAED,MAAMC,YAAY,GAAG,IAAAJ,eAAA,EAAc;IAACP,UAAD;IAAaG;EAAb,CAAd,EAA8CL,IAA9C,EAAoDC,MAApD,CAArB;EACA,IAAAO,YAAA,EAAOK,YAAY,CAACC,QAAb,EAAP,EAAgCJ,EAAhC,CAAmCK,GAAnC,CAAuCX,cAAvC;AACD"}
|
package/package.json
CHANGED
|
@@ -13,44 +13,49 @@
|
|
|
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.4",
|
|
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
26
|
"lint": "eslint ./src",
|
|
25
27
|
"lint:dev": "eslint ./src --fix",
|
|
26
|
-
"test:base": "cross-env NODE_ENV=test
|
|
27
|
-
"test": "npm run lint && npm run test:base
|
|
28
|
-
"test:dev": "npm run lint:dev && npm run
|
|
29
|
-
"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 --reporter=text",
|
|
30
34
|
"build:transpile": "babel src --copy-files --source-maps --delete-dir-on-start --out-dir=dist",
|
|
31
35
|
"build": "npm run build:transpile",
|
|
32
|
-
"
|
|
36
|
+
"dev:test": "cross-env DEBUG=@natlibfi/* NODE_ENV=test nodemon -w src -w test-fixtures --exec 'clear && npm run test:dev'"
|
|
33
37
|
},
|
|
34
38
|
"dependencies": {
|
|
35
|
-
"@natlibfi/
|
|
36
|
-
"@natlibfi/
|
|
37
|
-
"
|
|
39
|
+
"@natlibfi/fixugen": "^1.0.2",
|
|
40
|
+
"@natlibfi/fixura": "^2.2.1",
|
|
41
|
+
"@natlibfi/marc-record": "^7.1.0-alpha.1",
|
|
42
|
+
"debug": "^4.3.4",
|
|
38
43
|
"normalize-diacritics": "^2.13.2"
|
|
39
44
|
},
|
|
40
45
|
"devDependencies": {
|
|
41
|
-
"@babel/cli": "^7.
|
|
42
|
-
"@babel/core": "^7.
|
|
43
|
-
"@babel/eslint-parser": "^7.
|
|
44
|
-
"@babel/preset-env": "^7.
|
|
45
|
-
"@babel/register": "^7.
|
|
46
|
-
"@natlibfi/eslint-config-melinda-backend": "^
|
|
47
|
-
"babel-plugin-istanbul": "^6.
|
|
46
|
+
"@babel/cli": "^7.17.10",
|
|
47
|
+
"@babel/core": "^7.18.0",
|
|
48
|
+
"@babel/eslint-parser": "^7.17.0",
|
|
49
|
+
"@babel/preset-env": "^7.18.0",
|
|
50
|
+
"@babel/register": "^7.17.7",
|
|
51
|
+
"@natlibfi/eslint-config-melinda-backend": "^2.0.0",
|
|
52
|
+
"babel-plugin-istanbul": "^6.1.1",
|
|
48
53
|
"babel-plugin-rewire": "^1.2.0",
|
|
49
54
|
"chai": "^4.3.4",
|
|
50
55
|
"cross-env": "^7.0.3",
|
|
51
|
-
"eslint": "^
|
|
52
|
-
"mocha": "^
|
|
53
|
-
"nodemon": "^2.0.
|
|
56
|
+
"eslint": "^8.16.0",
|
|
57
|
+
"mocha": "^10.0.0",
|
|
58
|
+
"nodemon": "^2.0.16",
|
|
54
59
|
"nyc": "^15.1.0"
|
|
55
60
|
},
|
|
56
61
|
"eslintConfig": {
|
|
@@ -64,7 +69,7 @@
|
|
|
64
69
|
"@babel/preset-env",
|
|
65
70
|
{
|
|
66
71
|
"targets": {
|
|
67
|
-
"node": "
|
|
72
|
+
"node": "14"
|
|
68
73
|
}
|
|
69
74
|
}
|
|
70
75
|
]
|
package/src/index.js
CHANGED
|
@@ -1,36 +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
|
-
import {MarcRecord} from '@natlibfi/marc-record';
|
|
30
1
|
import Reducers from './reducers';
|
|
31
2
|
|
|
32
3
|
export {Reducers};
|
|
33
|
-
export default ({base, source, reducers,
|
|
34
|
-
const sourceRecord = MarcRecord.clone(source, sourceValidators);
|
|
35
|
-
return reducers.reduce((baseRecord, reducer) => reducer(baseRecord, sourceRecord), MarcRecord.clone(base, baseValidators));
|
|
36
|
-
};
|
|
4
|
+
export default ({base, source, reducers}) => reducers.reduce((base, reducer) => reducer(base, source), base);
|