@natlibfi/marc-record-merge 7.0.10-alpha.1 → 8.0.0-alpha.1
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/workflows/melinda-node-tests.yml +3 -3
- package/dist/index.js +20 -58
- package/dist/index.js.map +7 -1
- package/dist/reducers/copy.js +78 -148
- package/dist/reducers/copy.js.map +7 -1
- package/dist/reducers/index.js +4 -17
- package/dist/reducers/index.js.map +7 -1
- package/dist/reducers/select.js +36 -84
- package/dist/reducers/select.js.map +7 -1
- package/eslint.config.mjs +52 -0
- package/package.json +18 -87
- package/src/index.js +1 -1
- package/src/reducers/copy.js +1 -4
- package/src/reducers/index.js +2 -2
- package/src/reducers/select.js +2 -2
- package/{src/index.spec.js → test/index.test.js} +4 -5
- package/{src/reducers/copy.spec.js → test/reducers/copy.test.js} +7 -6
- package/{src/reducers/copy2.spec.js → test/reducers/copy2.test.js} +7 -6
- package/test/reducers/select.test.js +61 -0
- package/test/reducers/select2.test.js +61 -0
- package/test-fixtures/reducers/select/01/metadata.json +5 -1
- package/dist/index.spec.js +0 -58
- package/dist/index.spec.js.map +0 -1
- package/dist/reducers/copy.spec.js +0 -64
- package/dist/reducers/copy.spec.js.map +0 -1
- package/dist/reducers/copy2.spec.js +0 -67
- package/dist/reducers/copy2.spec.js.map +0 -1
- package/dist/reducers/select.spec.js +0 -54
- package/dist/reducers/select.spec.js.map +0 -1
- package/dist/reducers/select2.spec.js +0 -57
- package/dist/reducers/select2.spec.js.map +0 -1
- package/src/reducers/select.spec.js +0 -49
- package/src/reducers/select2.spec.js +0 -49
|
@@ -11,12 +11,12 @@ jobs:
|
|
|
11
11
|
|
|
12
12
|
strategy:
|
|
13
13
|
matrix:
|
|
14
|
-
node-version: [
|
|
14
|
+
node-version: [22.x, 23.x, 24.x]
|
|
15
15
|
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
|
|
16
16
|
|
|
17
17
|
steps:
|
|
18
18
|
- name: Checkout the code
|
|
19
|
-
uses: actions/checkout@
|
|
19
|
+
uses: actions/checkout@v5
|
|
20
20
|
- name: Use Node.js ${{ matrix.node-version }}
|
|
21
21
|
uses: actions/setup-node@v4
|
|
22
22
|
with:
|
|
@@ -48,7 +48,7 @@ jobs:
|
|
|
48
48
|
if: contains(github.ref, 'refs/tags/')
|
|
49
49
|
|
|
50
50
|
steps:
|
|
51
|
-
- uses: actions/checkout@
|
|
51
|
+
- uses: actions/checkout@v5
|
|
52
52
|
# Setup .npmrc file to publish to npm
|
|
53
53
|
- uses: actions/setup-node@v4
|
|
54
54
|
with:
|
package/dist/index.js
CHANGED
|
@@ -1,70 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
exports.default = void 0;
|
|
13
|
-
var _reducers = _interopRequireDefault(require("./reducers"));
|
|
14
|
-
var _debug = _interopRequireDefault(require("debug"));
|
|
15
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
16
|
-
const debug = (0, _debug.default)('@natlibfi/melinda-marc-record-merge:index');
|
|
17
|
-
const debugData = debug.extend('data');
|
|
18
|
-
// export default ({base, source, reducers}) => reducers.reduce((base, reducer) => reducer(base, source), base);
|
|
19
|
-
// NV: Modified the reducer loop so, that not only base, but also is carried back.
|
|
20
|
-
// However, we try to be backward-compatible: normally after the reducers, only base is returned.
|
|
21
|
-
var _default = ({
|
|
22
|
-
base,
|
|
23
|
-
source,
|
|
24
|
-
reducers
|
|
25
|
-
}) => {
|
|
26
|
-
const combo = {
|
|
27
|
-
base,
|
|
28
|
-
source
|
|
29
|
-
};
|
|
30
|
-
const resultCombo = reducers.reduce((combo, reducer) => {
|
|
31
|
-
const returnCombo = singleRound(reducer, combo.base, combo.source);
|
|
32
|
-
//debugData(`returnCombo after current reducer: ${JSON.stringify(returnCombo)}`);
|
|
1
|
+
import Reducers from "./reducers/index.js";
|
|
2
|
+
import createDebugLogger from "debug";
|
|
3
|
+
const debug = createDebugLogger("@natlibfi/melinda-marc-record-merge:index");
|
|
4
|
+
const debugData = debug.extend("data");
|
|
5
|
+
export { Reducers };
|
|
6
|
+
export default ({ base, source, reducers }) => {
|
|
7
|
+
const combo = { base, source };
|
|
8
|
+
const resultCombo = reducers.reduce((combo2, reducer) => {
|
|
9
|
+
const returnCombo = singleRound(reducer, combo2.base, combo2.source);
|
|
33
10
|
return returnCombo;
|
|
34
11
|
}, combo);
|
|
35
12
|
debugData(`ResultCombo after reducers: ${JSON.stringify(resultCombo)}`);
|
|
36
|
-
|
|
37
|
-
// Hack to make my melinda-marc-record-merge-reducers single tests that expect both
|
|
38
|
-
// base and source to return them both:
|
|
39
13
|
if (reducers.length === 1 && resultCombo.base && resultCombo.source) {
|
|
40
|
-
debug(
|
|
14
|
+
debug("Single reducer, returning resultCombo");
|
|
41
15
|
debugData(JSON.stringify(resultCombo));
|
|
42
16
|
return resultCombo;
|
|
43
17
|
}
|
|
44
|
-
|
|
45
|
-
debug('Multiple reducers, returning just base');
|
|
18
|
+
debug("Multiple reducers, returning just base");
|
|
46
19
|
debugData(JSON.stringify(resultCombo.base));
|
|
47
20
|
return resultCombo.base;
|
|
48
|
-
function singleRound(reducer,
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
//debugData(reducerResult);
|
|
55
|
-
if (reducerResult.base !== undefined && reducerResult.source !== undefined) {
|
|
56
|
-
debug('NEW STYLE REDUCER RESULT v2');
|
|
57
|
-
const combo = reducerResult;
|
|
58
|
-
//debugData(combo);
|
|
59
|
-
return combo;
|
|
21
|
+
function singleRound(reducer, base2, source2) {
|
|
22
|
+
const reducerResult = reducer(base2, source2);
|
|
23
|
+
if (reducerResult.base !== void 0 && reducerResult.source !== void 0) {
|
|
24
|
+
debug("NEW STYLE REDUCER RESULT v2");
|
|
25
|
+
const combo2 = reducerResult;
|
|
26
|
+
return combo2;
|
|
60
27
|
}
|
|
61
|
-
debug(
|
|
62
|
-
|
|
63
|
-
return {
|
|
64
|
-
base: reducerResult,
|
|
65
|
-
source
|
|
66
|
-
};
|
|
28
|
+
debug("OLD SCHOOL REDUCER RESULT v2");
|
|
29
|
+
return { base: reducerResult, source: source2 };
|
|
67
30
|
}
|
|
68
31
|
};
|
|
69
|
-
|
|
70
|
-
//# sourceMappingURL=index.js.map
|
|
32
|
+
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/index.js"],
|
|
4
|
+
"sourcesContent": ["import Reducers from './reducers/index.js';\nimport createDebugLogger from 'debug';\n\nconst debug = createDebugLogger('@natlibfi/melinda-marc-record-merge:index');\nconst debugData = debug.extend('data');\n\nexport {Reducers};\n// export default ({base, source, reducers}) => reducers.reduce((base, reducer) => reducer(base, source), base);\n\n// NV: Modified the reducer loop so, that not only base, but also is carried back.\n// However, we try to be backward-compatible: normally after the reducers, only base is returned.\n\nexport default ({base, source, reducers}) => {\n\n const combo = {base, source};\n const resultCombo = reducers.reduce((combo, reducer) => {\n const returnCombo = singleRound(reducer, combo.base, combo.source);\n //debugData(`returnCombo after current reducer: ${JSON.stringify(returnCombo)}`);\n return returnCombo;\n }, combo);\n\n debugData(`ResultCombo after reducers: ${JSON.stringify(resultCombo)}`);\n\n // Hack to make my melinda-marc-record-merge-reducers single tests that expect both\n // base and source to return them both:\n if (reducers.length === 1 && resultCombo.base && resultCombo.source) {\n debug('Single reducer, returning resultCombo');\n debugData(JSON.stringify(resultCombo));\n\n return resultCombo;\n }\n // All other tests return just base... Backward (compability) it is!\n debug('Multiple reducers, returning just base');\n debugData(JSON.stringify(resultCombo.base));\n return resultCombo.base;\n\n function singleRound(reducer, base, source) {\n //debug(`SINGLE ROUND INPUT (base, source)`);\n //debugData(base);\n //debugData(base);\n const reducerResult = reducer(base, source);\n //debug(`reducerResult:`);\n //debugData(reducerResult);\n if (reducerResult.base !== undefined && reducerResult.source !== undefined) {\n debug('NEW STYLE REDUCER RESULT v2');\n const combo = reducerResult;\n //debugData(combo);\n return combo;\n }\n debug('OLD SCHOOL REDUCER RESULT v2');\n //debugData({base: reducerResult, source});\n return {base: reducerResult, source};\n }\n};\n"],
|
|
5
|
+
"mappings": "AAAA,OAAO,cAAc;AACrB,OAAO,uBAAuB;AAE9B,MAAM,QAAQ,kBAAkB,2CAA2C;AAC3E,MAAM,YAAY,MAAM,OAAO,MAAM;AAErC,SAAQ;AAMR,eAAe,CAAC,EAAC,MAAM,QAAQ,SAAQ,MAAM;AAE3C,QAAM,QAAQ,EAAC,MAAM,OAAM;AAC3B,QAAM,cAAc,SAAS,OAAO,CAACA,QAAO,YAAY;AACtD,UAAM,cAAc,YAAY,SAASA,OAAM,MAAMA,OAAM,MAAM;AAEjE,WAAO;AAAA,EACT,GAAG,KAAK;AAER,YAAU,+BAA+B,KAAK,UAAU,WAAW,CAAC,EAAE;AAItE,MAAI,SAAS,WAAW,KAAK,YAAY,QAAQ,YAAY,QAAQ;AACnE,UAAM,uCAAuC;AAC7C,cAAU,KAAK,UAAU,WAAW,CAAC;AAErC,WAAO;AAAA,EACT;AAEA,QAAM,wCAAwC;AAC9C,YAAU,KAAK,UAAU,YAAY,IAAI,CAAC;AAC1C,SAAO,YAAY;AAEnB,WAAS,YAAY,SAASC,OAAMC,SAAQ;AAI1C,UAAM,gBAAgB,QAAQD,OAAMC,OAAM;AAG1C,QAAI,cAAc,SAAS,UAAa,cAAc,WAAW,QAAW;AAC1E,YAAM,6BAA6B;AACnC,YAAMF,SAAQ;AAEd,aAAOA;AAAA,IACT;AACA,UAAM,8BAA8B;AAEpC,WAAO,EAAC,MAAM,eAAe,QAAAE,QAAM;AAAA,EACrC;AACF;",
|
|
6
|
+
"names": ["combo", "base", "source"]
|
|
7
|
+
}
|
package/dist/reducers/copy.js
CHANGED
|
@@ -1,15 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _marcRecord = require("@natlibfi/marc-record");
|
|
8
|
-
var _debug = _interopRequireDefault(require("debug"));
|
|
9
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
-
/* eslint-disable max-statements */
|
|
11
|
-
/* eslint-disable no-unused-vars */
|
|
12
|
-
var _default = ({
|
|
1
|
+
import { MarcRecord } from "@natlibfi/marc-record";
|
|
2
|
+
import createDebugLogger from "debug";
|
|
3
|
+
export default ({
|
|
13
4
|
tagPattern,
|
|
14
5
|
compareTagsOnly = false,
|
|
15
6
|
compareWithoutTag = false,
|
|
@@ -20,43 +11,28 @@ var _default = ({
|
|
|
20
11
|
excludeSubfields = [],
|
|
21
12
|
dropSubfields = [],
|
|
22
13
|
copyUnless = [],
|
|
23
|
-
baseValidators = {
|
|
24
|
-
|
|
25
|
-
},
|
|
26
|
-
sourceValidators = {
|
|
27
|
-
subfieldValues: false
|
|
28
|
-
},
|
|
14
|
+
baseValidators = { subfieldValues: false },
|
|
15
|
+
sourceValidators = { subfieldValues: false },
|
|
29
16
|
swapTag = [],
|
|
30
17
|
swapSubfieldCode = [],
|
|
31
18
|
doNotCopyIfFieldPresent = false
|
|
32
19
|
}) => (base, source) => {
|
|
33
|
-
const debug = (
|
|
34
|
-
const debugData = debug.extend(
|
|
35
|
-
const debugOptions = (
|
|
36
|
-
const debugCompare = (
|
|
20
|
+
const debug = createDebugLogger("@natlibfi/marc-record-merge:copy");
|
|
21
|
+
const debugData = debug.extend("data");
|
|
22
|
+
const debugOptions = createDebugLogger("@natlibfi/marc-record-merge:compare-options");
|
|
23
|
+
const debugCompare = createDebugLogger("@natlibfi/marc-record-merge:compare");
|
|
37
24
|
debugData(`base: ${JSON.stringify(base)}`);
|
|
38
25
|
debugData(`source: ${JSON.stringify(source)}`);
|
|
39
|
-
const {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
baseRecord,
|
|
50
|
-
sourceRecord
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
// records if we got an non-object (base, source) as a parameter
|
|
54
|
-
const baseRecord = new _marcRecord.MarcRecord(base, baseValidators);
|
|
55
|
-
const sourceRecord = new _marcRecord.MarcRecord(source, sourceValidators);
|
|
56
|
-
return {
|
|
57
|
-
baseRecord,
|
|
58
|
-
sourceRecord
|
|
59
|
-
};
|
|
26
|
+
const { baseRecord, sourceRecord } = getRecordsFromParameters(base, source, baseValidators, sourceValidators);
|
|
27
|
+
function getRecordsFromParameters(base2, source2, baseValidators2, sourceValidators2) {
|
|
28
|
+
if (source2 === void 0 && base2.base !== void 0 && base2.source !== void 0) {
|
|
29
|
+
const baseRecord3 = new MarcRecord(base2.base, baseValidators2);
|
|
30
|
+
const sourceRecord3 = new MarcRecord(base2.source, sourceValidators2);
|
|
31
|
+
return { baseRecord: baseRecord3, sourceRecord: sourceRecord3 };
|
|
32
|
+
}
|
|
33
|
+
const baseRecord2 = new MarcRecord(base2, baseValidators2);
|
|
34
|
+
const sourceRecord2 = new MarcRecord(source2, sourceValidators2);
|
|
35
|
+
return { baseRecord: baseRecord2, sourceRecord: sourceRecord2 };
|
|
60
36
|
}
|
|
61
37
|
const ignoreInd1 = compareWithoutIndicators || compareWithoutIndicator1;
|
|
62
38
|
const ignoreInd2 = compareWithoutIndicators || compareWithoutIndicator2;
|
|
@@ -77,134 +53,105 @@ var _default = ({
|
|
|
77
53
|
debug(`FFS: ${compareWithoutIndicator1}, ${compareWithoutIndicators}, ${ignoreInd1}`);
|
|
78
54
|
debug(`Base fields: `, baseFields);
|
|
79
55
|
debug(`Source fields: `, sourceFields);
|
|
80
|
-
|
|
81
|
-
// Logic steps
|
|
82
|
-
const baseCompareFields = baseFields.map(baseField => createCompareField(baseField));
|
|
56
|
+
const baseCompareFields = baseFields.map((baseField) => createCompareField(baseField));
|
|
83
57
|
const compareResultFields = compareFields(sourceFields, baseCompareFields);
|
|
84
58
|
const droppedUnwantedSubfield = checkDropSubfields(compareResultFields);
|
|
85
59
|
const droppedUnwantedFields = checkCopyUnlessFields(droppedUnwantedSubfield);
|
|
86
60
|
const swappedSubfields = checkSwapSubfieldCodes(droppedUnwantedFields);
|
|
87
61
|
const swappedTags = checkSwapTag(swappedSubfields);
|
|
88
|
-
const uniqueFields = [...new Set(swappedTags.map(field => JSON.stringify(field)))].map(field => JSON.parse(field));
|
|
89
|
-
debug(
|
|
62
|
+
const uniqueFields = [...new Set(swappedTags.map((field) => JSON.stringify(field)))].map((field) => JSON.parse(field));
|
|
63
|
+
debug("Fields to be copied");
|
|
90
64
|
debug(JSON.stringify(uniqueFields));
|
|
91
|
-
|
|
92
|
-
// Add fields to base;
|
|
93
|
-
uniqueFields.forEach(field => baseRecord.insertField(field));
|
|
65
|
+
uniqueFields.forEach((field) => baseRecord.insertField(field));
|
|
94
66
|
debugData(`baseRecord before return: ${JSON.stringify(baseRecord)}`);
|
|
95
|
-
//return baseRecord;
|
|
96
67
|
return baseRecord.toObject();
|
|
97
|
-
function compareFields(
|
|
98
|
-
const [sourceField, ...rest] =
|
|
99
|
-
if (sourceField ===
|
|
68
|
+
function compareFields(sourceFields2, baseCompareFields2, uniqFields = []) {
|
|
69
|
+
const [sourceField, ...rest] = sourceFields2;
|
|
70
|
+
if (sourceField === void 0) {
|
|
100
71
|
return uniqFields;
|
|
101
72
|
}
|
|
102
|
-
if (
|
|
103
|
-
return compareFields(rest,
|
|
73
|
+
if (baseCompareFields2.length === 0) {
|
|
74
|
+
return compareFields(rest, baseCompareFields2, [...uniqFields, sourceField]);
|
|
104
75
|
}
|
|
105
|
-
|
|
106
|
-
// Source and base are also compared for identicalness
|
|
107
|
-
// Non-identical fields are copied from source to base as duplicates
|
|
108
76
|
const sourceCompareField = createCompareField(sourceField);
|
|
109
|
-
const unique = checkCompareFields(
|
|
110
|
-
debugCompare(`${JSON.stringify(sourceField)} ${unique ?
|
|
77
|
+
const unique = checkCompareFields(baseCompareFields2, sourceCompareField);
|
|
78
|
+
debugCompare(`${JSON.stringify(sourceField)} ${unique ? "is UNIQUE" : "not UNIQUE"}`);
|
|
111
79
|
if (unique) {
|
|
112
|
-
return compareFields(rest,
|
|
113
|
-
}
|
|
114
|
-
return compareFields(rest,
|
|
115
|
-
function checkCompareFields(
|
|
116
|
-
let
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
debugCompare(`Value is different ${sourceCompareField.value} !== ${baseCompareField.value}`);
|
|
80
|
+
return compareFields(rest, baseCompareFields2, [...uniqFields, sourceField]);
|
|
81
|
+
}
|
|
82
|
+
return compareFields(rest, baseCompareFields2, uniqFields);
|
|
83
|
+
function checkCompareFields(baseCompareFields3, sourceCompareField2) {
|
|
84
|
+
let unique2 = true;
|
|
85
|
+
baseCompareFields3.forEach((baseCompareField) => {
|
|
86
|
+
debugCompare(`Comparing ${JSON.stringify(sourceCompareField2)} to ${JSON.stringify(baseCompareField)}}`);
|
|
87
|
+
if (sourceCompareField2.value !== baseCompareField.value) {
|
|
88
|
+
debugCompare(`Value is different ${sourceCompareField2.value} !== ${baseCompareField.value}`);
|
|
122
89
|
return;
|
|
123
90
|
}
|
|
124
|
-
if (
|
|
125
|
-
debugCompare(`Ind1 is different ${
|
|
91
|
+
if (sourceCompareField2.ind1 !== baseCompareField.ind1) {
|
|
92
|
+
debugCompare(`Ind1 is different ${sourceCompareField2.ind1} !== ${baseCompareField.ind1}`);
|
|
126
93
|
return;
|
|
127
94
|
}
|
|
128
|
-
if (
|
|
129
|
-
debugCompare(`Ind2 is different ${
|
|
95
|
+
if (sourceCompareField2.ind2 !== baseCompareField.ind2) {
|
|
96
|
+
debugCompare(`Ind2 is different ${sourceCompareField2.ind2} !== ${baseCompareField.ind2}`);
|
|
130
97
|
return;
|
|
131
98
|
}
|
|
132
|
-
if (
|
|
133
|
-
const allFound = checkSubfields(
|
|
99
|
+
if ("subfields" in sourceCompareField2) {
|
|
100
|
+
const allFound = checkSubfields(sourceCompareField2.subfields, baseCompareField.subfields);
|
|
134
101
|
debugCompare(`Subfields are different ${!allFound}`);
|
|
135
102
|
if (!allFound) {
|
|
136
103
|
return;
|
|
137
104
|
}
|
|
138
|
-
|
|
105
|
+
unique2 = false;
|
|
139
106
|
return;
|
|
140
107
|
}
|
|
141
|
-
|
|
108
|
+
unique2 = false;
|
|
142
109
|
return;
|
|
143
110
|
});
|
|
144
|
-
return
|
|
111
|
+
return unique2;
|
|
145
112
|
}
|
|
146
113
|
function checkSubfields(sourceSubfields, baseSubfields) {
|
|
147
|
-
const foundSubs = sourceSubfields.filter(sSub => baseSubfields.some(bSub => sSub.code === bSub.code && sSub.value === bSub.value));
|
|
114
|
+
const foundSubs = sourceSubfields.filter((sSub) => baseSubfields.some((bSub) => sSub.code === bSub.code && sSub.value === bSub.value));
|
|
148
115
|
if (subfieldsMustBeIdentical) {
|
|
149
116
|
return foundSubs.length === sourceSubfields.length && foundSubs.length === baseSubfields.length;
|
|
150
117
|
}
|
|
151
118
|
return foundSubs.length === sourceSubfields.length;
|
|
152
119
|
}
|
|
153
120
|
}
|
|
154
|
-
|
|
155
|
-
// compare objects have only fields that matter in comparison
|
|
156
121
|
function createCompareField(field) {
|
|
157
122
|
if (compareTagsOnly) {
|
|
158
|
-
return {
|
|
159
|
-
tag: field.tag
|
|
160
|
-
};
|
|
123
|
+
return { tag: field.tag };
|
|
161
124
|
}
|
|
162
|
-
if (
|
|
163
|
-
return {
|
|
164
|
-
tag: field.tag,
|
|
165
|
-
value: field.value
|
|
166
|
-
};
|
|
125
|
+
if ("value" in field) {
|
|
126
|
+
return { tag: field.tag, value: field.value };
|
|
167
127
|
}
|
|
168
128
|
const [filteredField] = checkDropSubfields([field]);
|
|
169
|
-
const [foundRule] = swapTag.filter(rule => new RegExp(rule.from,
|
|
170
|
-
const replacementTag = foundRule ? foundRule.to :
|
|
171
|
-
const params = [
|
|
172
|
-
name:
|
|
173
|
-
value:
|
|
174
|
-
|
|
175
|
-
name:
|
|
176
|
-
|
|
177
|
-
}, {
|
|
178
|
-
name: 'ind2',
|
|
179
|
-
value: ignoreInd2 ? undefined : field.ind2
|
|
180
|
-
}, {
|
|
181
|
-
name: 'subfields',
|
|
182
|
-
value: createCompareSubfields(filteredField.subfields)
|
|
183
|
-
}].map(param => [param.name, param.value]);
|
|
129
|
+
const [foundRule] = swapTag.filter((rule) => new RegExp(rule.from, "u").test(field.tag));
|
|
130
|
+
const replacementTag = foundRule ? foundRule.to : void 0;
|
|
131
|
+
const params = [
|
|
132
|
+
{ name: "tag", value: compareWithoutTag ? replacementTag : field.tag },
|
|
133
|
+
{ name: "ind1", value: ignoreInd1 ? void 0 : field.ind1 },
|
|
134
|
+
{ name: "ind2", value: ignoreInd2 ? void 0 : field.ind2 },
|
|
135
|
+
{ name: "subfields", value: createCompareSubfields(filteredField.subfields) }
|
|
136
|
+
].map((param) => [param.name, param.value]);
|
|
184
137
|
return Object.fromEntries(params);
|
|
185
138
|
function createCompareSubfields(subfields) {
|
|
186
|
-
const nonExcludedSubfields = subfields.filter(sub => !excludeSubfields.some(code => code === sub.code));
|
|
187
|
-
const normalizedSubfields = nonExcludedSubfields.map(sub => ({
|
|
188
|
-
code: sub.code,
|
|
189
|
-
value: normalizeSubfieldValue(sub.value)
|
|
190
|
-
}));
|
|
139
|
+
const nonExcludedSubfields = subfields.filter((sub) => !excludeSubfields.some((code) => code === sub.code));
|
|
140
|
+
const normalizedSubfields = nonExcludedSubfields.map((sub) => ({ code: sub.code, value: normalizeSubfieldValue(sub.value) }));
|
|
191
141
|
return normalizedSubfields;
|
|
192
142
|
function normalizeSubfieldValue(value) {
|
|
193
|
-
return value.toLowerCase().replace(/\s+/ug,
|
|
143
|
+
return value.toLowerCase().replace(/\s+/ug, "");
|
|
194
144
|
}
|
|
195
145
|
}
|
|
196
146
|
}
|
|
197
147
|
function checkSwapTag(fields) {
|
|
198
148
|
if (swapTag.length > 0) {
|
|
199
|
-
return fields.map(field => ({
|
|
200
|
-
...field,
|
|
201
|
-
tag: swapTagsFunc(field.tag)
|
|
202
|
-
}));
|
|
149
|
+
return fields.map((field) => ({ ...field, tag: swapTagsFunc(field.tag) }));
|
|
203
150
|
}
|
|
204
151
|
return fields;
|
|
205
152
|
function swapTagsFunc(tag) {
|
|
206
|
-
const [foundRule] = swapTag.filter(rule => new RegExp(rule.from,
|
|
207
|
-
if (foundRule ===
|
|
153
|
+
const [foundRule] = swapTag.filter((rule) => new RegExp(rule.from, "u").test(tag));
|
|
154
|
+
if (foundRule === void 0) {
|
|
208
155
|
return tag;
|
|
209
156
|
}
|
|
210
157
|
return foundRule.to;
|
|
@@ -212,49 +159,35 @@ var _default = ({
|
|
|
212
159
|
}
|
|
213
160
|
function checkSwapSubfieldCodes(fields) {
|
|
214
161
|
if (swapSubfieldCode.length > 0) {
|
|
215
|
-
return fields.map(field => ({
|
|
216
|
-
...field,
|
|
217
|
-
subfields: swapSubfieldCodesFunc(field.subfields)
|
|
218
|
-
}));
|
|
162
|
+
return fields.map((field) => ({ ...field, subfields: swapSubfieldCodesFunc(field.subfields) }));
|
|
219
163
|
}
|
|
220
164
|
return fields;
|
|
221
165
|
function swapSubfieldCodesFunc(subfields) {
|
|
222
|
-
return subfields.map(sub => {
|
|
223
|
-
const [foundRule] = swapSubfieldCode.filter(rule => rule.from === sub.code);
|
|
224
|
-
if (foundRule ===
|
|
166
|
+
return subfields.map((sub) => {
|
|
167
|
+
const [foundRule] = swapSubfieldCode.filter((rule) => rule.from === sub.code);
|
|
168
|
+
if (foundRule === void 0) {
|
|
225
169
|
return sub;
|
|
226
170
|
}
|
|
227
|
-
return {
|
|
228
|
-
code: foundRule.to,
|
|
229
|
-
value: sub.value
|
|
230
|
-
};
|
|
171
|
+
return { code: foundRule.to, value: sub.value };
|
|
231
172
|
});
|
|
232
173
|
}
|
|
233
174
|
}
|
|
234
175
|
function checkDropSubfields(fields) {
|
|
235
176
|
if (dropSubfields.length > 0) {
|
|
236
|
-
return fields.map(field => ({
|
|
237
|
-
...field,
|
|
238
|
-
subfields: dropSubfieldsFunc(field.subfields)
|
|
239
|
-
})).filter(field => field.subfields.length > 0);
|
|
177
|
+
return fields.map((field) => ({ ...field, subfields: dropSubfieldsFunc(field.subfields) })).filter((field) => field.subfields.length > 0);
|
|
240
178
|
}
|
|
241
179
|
return fields;
|
|
242
180
|
function dropSubfieldsFunc(subfields) {
|
|
243
|
-
return subfields.filter(sub => {
|
|
244
|
-
|
|
245
|
-
return !dropSubfields.some(({
|
|
246
|
-
code,
|
|
247
|
-
value = false,
|
|
248
|
-
condition = false
|
|
249
|
-
}) => {
|
|
181
|
+
return subfields.filter((sub) => {
|
|
182
|
+
return !dropSubfields.some(({ code, value = false, condition = false }) => {
|
|
250
183
|
if (code !== sub.code) {
|
|
251
184
|
return false;
|
|
252
185
|
}
|
|
253
186
|
if (!condition && value) {
|
|
254
187
|
return value === sub.value;
|
|
255
188
|
}
|
|
256
|
-
if (condition ===
|
|
257
|
-
return !new RegExp(value,
|
|
189
|
+
if (condition === "unless" && value) {
|
|
190
|
+
return !new RegExp(value, "u").test(sub.value);
|
|
258
191
|
}
|
|
259
192
|
return true;
|
|
260
193
|
});
|
|
@@ -263,12 +196,9 @@ var _default = ({
|
|
|
263
196
|
}
|
|
264
197
|
function checkCopyUnlessFields(fields) {
|
|
265
198
|
if (copyUnless.length > 0) {
|
|
266
|
-
return fields.filter(({
|
|
267
|
-
subfields
|
|
268
|
-
}) => copyUnless.some(filter => !subfields.some(sub => sub.code === filter.code && new RegExp(filter.value, 'u').test(sub.value))));
|
|
199
|
+
return fields.filter(({ subfields }) => copyUnless.some((filter) => !subfields.some((sub) => sub.code === filter.code && new RegExp(filter.value, "u").test(sub.value))));
|
|
269
200
|
}
|
|
270
201
|
return fields;
|
|
271
202
|
}
|
|
272
203
|
};
|
|
273
|
-
|
|
274
|
-
//# sourceMappingURL=copy.js.map
|
|
204
|
+
//# sourceMappingURL=copy.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{"version":3,"file":"copy.js","names":["_marcRecord","require","_debug","_interopRequireDefault","e","__esModule","default","_default","tagPattern","compareTagsOnly","compareWithoutTag","compareWithoutIndicators","compareWithoutIndicator1","compareWithoutIndicator2","subfieldsMustBeIdentical","excludeSubfields","dropSubfields","copyUnless","baseValidators","subfieldValues","sourceValidators","swapTag","swapSubfieldCode","doNotCopyIfFieldPresent","base","source","debug","createDebugLogger","debugData","extend","debugOptions","debugCompare","JSON","stringify","baseRecord","sourceRecord","getRecordsFromParameters","undefined","MarcRecord","ignoreInd1","ignoreInd2","baseFields","get","sourceFields","doNotCopy","length","toObject","baseCompareFields","map","baseField","createCompareField","compareResultFields","compareFields","droppedUnwantedSubfield","checkDropSubfields","droppedUnwantedFields","checkCopyUnlessFields","swappedSubfields","checkSwapSubfieldCodes","swappedTags","checkSwapTag","uniqueFields","Set","field","parse","forEach","insertField","uniqFields","sourceField","rest","sourceCompareField","unique","checkCompareFields","baseCompareField","value","ind1","ind2","allFound","checkSubfields","subfields","sourceSubfields","baseSubfields","foundSubs","filter","sSub","some","bSub","code","tag","filteredField","foundRule","rule","RegExp","from","test","replacementTag","to","params","name","createCompareSubfields","param","Object","fromEntries","nonExcludedSubfields","sub","normalizedSubfields","normalizeSubfieldValue","toLowerCase","replace","fields","swapTagsFunc","swapSubfieldCodesFunc","dropSubfieldsFunc","condition","exports"],"sources":["../../src/reducers/copy.js"],"sourcesContent":["/* eslint-disable max-statements */\n/* eslint-disable no-unused-vars */\n\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport createDebugLogger from 'debug';\n\nexport default ({\n tagPattern,\n compareTagsOnly = false,\n compareWithoutTag = false,\n compareWithoutIndicators = false,\n compareWithoutIndicator1 = false,\n compareWithoutIndicator2 = false,\n subfieldsMustBeIdentical = true,\n excludeSubfields = [],\n dropSubfields = [],\n copyUnless = [],\n baseValidators = {subfieldValues: false},\n sourceValidators = {subfieldValues: false},\n swapTag = [],\n swapSubfieldCode = [],\n doNotCopyIfFieldPresent = false\n}) => (base, source) => {\n\n const debug = createDebugLogger('@natlibfi/marc-record-merge:copy');\n const debugData = debug.extend('data');\n const debugOptions = createDebugLogger('@natlibfi/marc-record-merge:compare-options');\n const debugCompare = createDebugLogger('@natlibfi/marc-record-merge:compare');\n\n debugData(`base: ${JSON.stringify(base)}`);\n debugData(`source: ${JSON.stringify(source)}`);\n\n const {baseRecord, sourceRecord} = getRecordsFromParameters(base, source, baseValidators, sourceValidators);\n\n function getRecordsFromParameters(base, source, baseValidators, sourceValidators) {\n // records if we got an object ({base, source}) as a parameter\n if (source === undefined && base.base !== undefined && base.source !== undefined) {\n const baseRecord = new MarcRecord(base.base, baseValidators);\n const sourceRecord = new MarcRecord(base.source, sourceValidators);\n return {baseRecord, sourceRecord};\n }\n // records if we got an non-object (base, source) as a parameter\n const baseRecord = new MarcRecord(base, baseValidators);\n const sourceRecord = new MarcRecord(source, sourceValidators);\n return {baseRecord, sourceRecord};\n }\n\n const ignoreInd1 = compareWithoutIndicators || compareWithoutIndicator1;\n const ignoreInd2 = compareWithoutIndicators || compareWithoutIndicator2;\n\n debugOptions(`Tag Pattern: ${tagPattern}`);\n debugOptions(`Compare tags only: ${compareTagsOnly}`);\n debugOptions(`Omit indicator 1 from comparison: ${ignoreInd1}`);\n debugOptions(`Omit indicator 2 from comparison: ${ignoreInd2}`);\n debugOptions(`Copy if identical: ${subfieldsMustBeIdentical}`);\n debugOptions(`Exclude subfields: [${excludeSubfields}]`);\n debugOptions(`Drop subfields [${dropSubfields}]`);\n debugOptions(`Copy unless contains subfields: ${JSON.stringify(copyUnless)}`);\n\n const baseFields = baseRecord.get(tagPattern);\n const sourceFields = sourceRecord.get(tagPattern);\n const doNotCopy = doNotCopyIfFieldPresent ? baseRecord.get(doNotCopyIfFieldPresent).length > 0 : false;\n\n if (doNotCopy) {\n return baseRecord.toObject();\n }\n debug(`FFS: ${compareWithoutIndicator1}, ${compareWithoutIndicators}, ${ignoreInd1}`);\n debug(`Base fields: `, baseFields);\n debug(`Source fields: `, sourceFields);\n\n // Logic steps\n const baseCompareFields = baseFields.map(baseField => createCompareField(baseField));\n const compareResultFields = compareFields(sourceFields, baseCompareFields);\n const droppedUnwantedSubfield = checkDropSubfields(compareResultFields);\n const droppedUnwantedFields = checkCopyUnlessFields(droppedUnwantedSubfield);\n const swappedSubfields = checkSwapSubfieldCodes(droppedUnwantedFields);\n const swappedTags = checkSwapTag(swappedSubfields);\n const uniqueFields = [...new Set(swappedTags.map(field => JSON.stringify(field)))].map(field => JSON.parse(field));\n debug('Fields to be copied');\n debug(JSON.stringify(uniqueFields));\n\n // Add fields to base;\n uniqueFields.forEach(field => baseRecord.insertField(field));\n debugData(`baseRecord before return: ${JSON.stringify(baseRecord)}`);\n //return baseRecord;\n return baseRecord.toObject();\n\n function compareFields(sourceFields, baseCompareFields, uniqFields = []) {\n const [sourceField, ...rest] = sourceFields;\n if (sourceField === undefined) {\n return uniqFields;\n }\n\n if (baseCompareFields.length === 0) {\n return compareFields(rest, baseCompareFields, [...uniqFields, sourceField]);\n }\n\n // Source and base are also compared for identicalness\n // Non-identical fields are copied from source to base as duplicates\n const sourceCompareField = createCompareField(sourceField);\n const unique = checkCompareFields(baseCompareFields, sourceCompareField);\n\n debugCompare(`${JSON.stringify(sourceField)} ${unique ? 'is UNIQUE' : 'not UNIQUE'}`);\n\n if (unique) {\n return compareFields(rest, baseCompareFields, [...uniqFields, sourceField]);\n }\n\n return compareFields(rest, baseCompareFields, uniqFields);\n\n function checkCompareFields(baseCompareFields, sourceCompareField) {\n let unique = true; // eslint-disable-line functional/no-let\n\n baseCompareFields.forEach(baseCompareField => {\n debugCompare(`Comparing ${JSON.stringify(sourceCompareField)} to ${JSON.stringify(baseCompareField)}}`);\n\n if (sourceCompareField.value !== baseCompareField.value) {\n debugCompare(`Value is different ${sourceCompareField.value} !== ${baseCompareField.value}`);\n return;\n }\n\n if (sourceCompareField.ind1 !== baseCompareField.ind1) {\n debugCompare(`Ind1 is different ${sourceCompareField.ind1} !== ${baseCompareField.ind1}`);\n return;\n }\n\n if (sourceCompareField.ind2 !== baseCompareField.ind2) {\n debugCompare(`Ind2 is different ${sourceCompareField.ind2} !== ${baseCompareField.ind2}`);\n return;\n }\n\n if ('subfields' in sourceCompareField) {\n const allFound = checkSubfields(sourceCompareField.subfields, baseCompareField.subfields);\n debugCompare(`Subfields are different ${!allFound}`);\n if (!allFound) {\n return;\n }\n\n unique = false;\n return;\n }\n\n unique = false;\n return;\n });\n\n return unique;\n }\n\n function checkSubfields(sourceSubfields, baseSubfields) {\n const foundSubs = sourceSubfields.filter(sSub => baseSubfields.some(bSub => sSub.code === bSub.code && sSub.value === bSub.value));\n\n if (subfieldsMustBeIdentical) {\n return foundSubs.length === sourceSubfields.length && foundSubs.length === baseSubfields.length;\n }\n\n return foundSubs.length === sourceSubfields.length;\n }\n }\n\n // compare objects have only fields that matter in comparison\n function createCompareField(field) {\n if (compareTagsOnly) {\n return {tag: field.tag};\n }\n\n if ('value' in field) {\n return {tag: field.tag, value: field.value};\n }\n\n const [filteredField] = checkDropSubfields([field]);\n const [foundRule] = swapTag.filter(rule => new RegExp(rule.from, 'u').test(field.tag));\n const replacementTag = foundRule ? foundRule.to : undefined;\n\n const params = [\n {name: 'tag', value: compareWithoutTag ? replacementTag : field.tag},\n {name: 'ind1', value: ignoreInd1 ? undefined : field.ind1},\n {name: 'ind2', value: ignoreInd2 ? undefined : field.ind2},\n {name: 'subfields', value: createCompareSubfields(filteredField.subfields)}\n ].map(param => [param.name, param.value]);\n\n return Object.fromEntries(params);\n\n function createCompareSubfields(subfields) {\n const nonExcludedSubfields = subfields.filter(sub => !excludeSubfields.some(code => code === sub.code));\n const normalizedSubfields = nonExcludedSubfields.map(sub => ({code: sub.code, value: normalizeSubfieldValue(sub.value)}));\n\n return normalizedSubfields;\n\n function normalizeSubfieldValue(value) {\n return value.toLowerCase().replace(/\\s+/ug, '');\n }\n }\n }\n\n function checkSwapTag(fields) {\n if (swapTag.length > 0) {\n return fields.map(field => ({...field, tag: swapTagsFunc(field.tag)}));\n }\n\n return fields;\n\n function swapTagsFunc(tag) {\n const [foundRule] = swapTag.filter(rule => new RegExp(rule.from, 'u').test(tag));\n\n if (foundRule === undefined) {\n return tag;\n }\n\n return foundRule.to;\n }\n }\n\n function checkSwapSubfieldCodes(fields) {\n if (swapSubfieldCode.length > 0) {\n return fields.map(field => ({...field, subfields: swapSubfieldCodesFunc(field.subfields)}));\n }\n\n return fields;\n\n function swapSubfieldCodesFunc(subfields) {\n return subfields.map(sub => {\n const [foundRule] = swapSubfieldCode.filter(rule => rule.from === sub.code);\n\n if (foundRule === undefined) {\n return sub;\n }\n\n return {code: foundRule.to, value: sub.value};\n });\n }\n }\n\n function checkDropSubfields(fields) {\n if (dropSubfields.length > 0) {\n return fields.map(field => ({...field, subfields: dropSubfieldsFunc(field.subfields)}))\n .filter(field => field.subfields.length > 0);\n }\n\n return fields;\n\n function dropSubfieldsFunc(subfields) {\n return subfields.filter(sub => { // eslint-disable-line\n return !dropSubfields.some(({code, value = false, condition = false}) => {\n if (code !== sub.code) {\n return false;\n }\n\n if (!condition && value) {\n return value === sub.value;\n }\n\n if (condition === 'unless' && value) {\n return !new RegExp(value, 'u').test(sub.value);\n }\n\n return true;\n });\n });\n }\n }\n\n function checkCopyUnlessFields(fields) {\n if (copyUnless.length > 0) {\n return fields.filter(({subfields}) => copyUnless.some(filter => !subfields.some(sub => sub.code === filter.code && new RegExp(filter.value, 'u').test(sub.value))));\n }\n\n return fields;\n }\n};\n"],"mappings":";;;;;;AAGA,IAAAA,WAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAC,sBAAA,CAAAF,OAAA;AAAsC,SAAAE,uBAAAC,CAAA,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AI1B,IAAI,KAAKiB,GAAG,CAACjB,IAAI,EAAE;YACrB,OAAO,KAAK;UACd;UAEA,IAAI,CAAC0B,SAAS,IAAIvC,KAAK,EAAE;YACvB,OAAOA,KAAK,KAAK8B,GAAG,CAAC9B,KAAK;UAC5B;UAEA,IAAIuC,SAAS,KAAK,QAAQ,IAAIvC,KAAK,EAAE;YACnC,OAAO,CAAC,IAAIkB,MAAM,CAAClB,KAAK,EAAE,GAAG,CAAC,CAACoB,IAAI,CAACU,GAAG,CAAC9B,KAAK,CAAC;UAChD;UAEA,OAAO,IAAI;QACb,CAAC,CAAC;MACJ,CAAC,CAAC;IACJ;EACF;EAEA,SAASlB,qBAAqBA,CAACqD,MAAM,EAAE;IACrC,IAAI5F,UAAU,CAAC4B,MAAM,GAAG,CAAC,EAAE;MACzB,OAAOgE,MAAM,CAAC1B,MAAM,CAAC,CAAC;QAACJ;MAAS,CAAC,KAAK9D,UAAU,CAACoE,IAAI,CAACF,MAAM,IAAI,CAACJ,SAAS,CAACM,IAAI,CAACmB,GAAG,IAAIA,GAAG,CAACjB,IAAI,KAAKJ,MAAM,CAACI,IAAI,IAAI,IAAIK,MAAM,CAACT,MAAM,CAACT,KAAK,EAAE,GAAG,CAAC,CAACoB,IAAI,CAACU,GAAG,CAAC9B,KAAK,CAAC,CAAC,CAAC,CAAC;IACrK;IAEA,OAAOmC,MAAM;EACf;AACF,CAAC;AAAAK,OAAA,CAAA5G,OAAA,GAAAC,QAAA","ignoreList":[]}
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/reducers/copy.js"],
|
|
4
|
+
"sourcesContent": ["import {MarcRecord} from '@natlibfi/marc-record';\nimport createDebugLogger from 'debug';\n\nexport default ({\n tagPattern,\n compareTagsOnly = false,\n compareWithoutTag = false,\n compareWithoutIndicators = false,\n compareWithoutIndicator1 = false,\n compareWithoutIndicator2 = false,\n subfieldsMustBeIdentical = true,\n excludeSubfields = [],\n dropSubfields = [],\n copyUnless = [],\n baseValidators = {subfieldValues: false},\n sourceValidators = {subfieldValues: false},\n swapTag = [],\n swapSubfieldCode = [],\n doNotCopyIfFieldPresent = false\n}) => (base, source) => {\n\n const debug = createDebugLogger('@natlibfi/marc-record-merge:copy');\n const debugData = debug.extend('data');\n const debugOptions = createDebugLogger('@natlibfi/marc-record-merge:compare-options');\n const debugCompare = createDebugLogger('@natlibfi/marc-record-merge:compare');\n\n debugData(`base: ${JSON.stringify(base)}`);\n debugData(`source: ${JSON.stringify(source)}`);\n\n const {baseRecord, sourceRecord} = getRecordsFromParameters(base, source, baseValidators, sourceValidators);\n\n function getRecordsFromParameters(base, source, baseValidators, sourceValidators) {\n // records if we got an object ({base, source}) as a parameter\n if (source === undefined && base.base !== undefined && base.source !== undefined) {\n const baseRecord = new MarcRecord(base.base, baseValidators);\n const sourceRecord = new MarcRecord(base.source, sourceValidators);\n return {baseRecord, sourceRecord};\n }\n // records if we got an non-object (base, source) as a parameter\n const baseRecord = new MarcRecord(base, baseValidators);\n const sourceRecord = new MarcRecord(source, sourceValidators);\n return {baseRecord, sourceRecord};\n }\n\n const ignoreInd1 = compareWithoutIndicators || compareWithoutIndicator1;\n const ignoreInd2 = compareWithoutIndicators || compareWithoutIndicator2;\n\n debugOptions(`Tag Pattern: ${tagPattern}`);\n debugOptions(`Compare tags only: ${compareTagsOnly}`);\n debugOptions(`Omit indicator 1 from comparison: ${ignoreInd1}`);\n debugOptions(`Omit indicator 2 from comparison: ${ignoreInd2}`);\n debugOptions(`Copy if identical: ${subfieldsMustBeIdentical}`);\n debugOptions(`Exclude subfields: [${excludeSubfields}]`);\n debugOptions(`Drop subfields [${dropSubfields}]`);\n debugOptions(`Copy unless contains subfields: ${JSON.stringify(copyUnless)}`);\n\n const baseFields = baseRecord.get(tagPattern);\n const sourceFields = sourceRecord.get(tagPattern);\n const doNotCopy = doNotCopyIfFieldPresent ? baseRecord.get(doNotCopyIfFieldPresent).length > 0 : false;\n\n if (doNotCopy) {\n return baseRecord.toObject();\n }\n debug(`FFS: ${compareWithoutIndicator1}, ${compareWithoutIndicators}, ${ignoreInd1}`);\n debug(`Base fields: `, baseFields);\n debug(`Source fields: `, sourceFields);\n\n // Logic steps\n const baseCompareFields = baseFields.map(baseField => createCompareField(baseField));\n const compareResultFields = compareFields(sourceFields, baseCompareFields);\n const droppedUnwantedSubfield = checkDropSubfields(compareResultFields);\n const droppedUnwantedFields = checkCopyUnlessFields(droppedUnwantedSubfield);\n const swappedSubfields = checkSwapSubfieldCodes(droppedUnwantedFields);\n const swappedTags = checkSwapTag(swappedSubfields);\n const uniqueFields = [...new Set(swappedTags.map(field => JSON.stringify(field)))].map(field => JSON.parse(field));\n debug('Fields to be copied');\n debug(JSON.stringify(uniqueFields));\n\n // Add fields to base;\n uniqueFields.forEach(field => baseRecord.insertField(field));\n debugData(`baseRecord before return: ${JSON.stringify(baseRecord)}`);\n //return baseRecord;\n return baseRecord.toObject();\n\n function compareFields(sourceFields, baseCompareFields, uniqFields = []) {\n const [sourceField, ...rest] = sourceFields;\n if (sourceField === undefined) {\n return uniqFields;\n }\n\n if (baseCompareFields.length === 0) {\n return compareFields(rest, baseCompareFields, [...uniqFields, sourceField]);\n }\n\n // Source and base are also compared for identicalness\n // Non-identical fields are copied from source to base as duplicates\n const sourceCompareField = createCompareField(sourceField);\n const unique = checkCompareFields(baseCompareFields, sourceCompareField);\n\n debugCompare(`${JSON.stringify(sourceField)} ${unique ? 'is UNIQUE' : 'not UNIQUE'}`);\n\n if (unique) {\n return compareFields(rest, baseCompareFields, [...uniqFields, sourceField]);\n }\n\n return compareFields(rest, baseCompareFields, uniqFields);\n\n function checkCompareFields(baseCompareFields, sourceCompareField) {\n let unique = true;\n\n baseCompareFields.forEach(baseCompareField => {\n debugCompare(`Comparing ${JSON.stringify(sourceCompareField)} to ${JSON.stringify(baseCompareField)}}`);\n\n if (sourceCompareField.value !== baseCompareField.value) {\n debugCompare(`Value is different ${sourceCompareField.value} !== ${baseCompareField.value}`);\n return;\n }\n\n if (sourceCompareField.ind1 !== baseCompareField.ind1) {\n debugCompare(`Ind1 is different ${sourceCompareField.ind1} !== ${baseCompareField.ind1}`);\n return;\n }\n\n if (sourceCompareField.ind2 !== baseCompareField.ind2) {\n debugCompare(`Ind2 is different ${sourceCompareField.ind2} !== ${baseCompareField.ind2}`);\n return;\n }\n\n if ('subfields' in sourceCompareField) {\n const allFound = checkSubfields(sourceCompareField.subfields, baseCompareField.subfields);\n debugCompare(`Subfields are different ${!allFound}`);\n if (!allFound) {\n return;\n }\n\n unique = false;\n return;\n }\n\n unique = false;\n return;\n });\n\n return unique;\n }\n\n function checkSubfields(sourceSubfields, baseSubfields) {\n const foundSubs = sourceSubfields.filter(sSub => baseSubfields.some(bSub => sSub.code === bSub.code && sSub.value === bSub.value));\n\n if (subfieldsMustBeIdentical) {\n return foundSubs.length === sourceSubfields.length && foundSubs.length === baseSubfields.length;\n }\n\n return foundSubs.length === sourceSubfields.length;\n }\n }\n\n // compare objects have only fields that matter in comparison\n function createCompareField(field) {\n if (compareTagsOnly) {\n return {tag: field.tag};\n }\n\n if ('value' in field) {\n return {tag: field.tag, value: field.value};\n }\n\n const [filteredField] = checkDropSubfields([field]);\n const [foundRule] = swapTag.filter(rule => new RegExp(rule.from, 'u').test(field.tag));\n const replacementTag = foundRule ? foundRule.to : undefined;\n\n const params = [\n {name: 'tag', value: compareWithoutTag ? replacementTag : field.tag},\n {name: 'ind1', value: ignoreInd1 ? undefined : field.ind1},\n {name: 'ind2', value: ignoreInd2 ? undefined : field.ind2},\n {name: 'subfields', value: createCompareSubfields(filteredField.subfields)}\n ].map(param => [param.name, param.value]);\n\n return Object.fromEntries(params);\n\n function createCompareSubfields(subfields) {\n const nonExcludedSubfields = subfields.filter(sub => !excludeSubfields.some(code => code === sub.code));\n const normalizedSubfields = nonExcludedSubfields.map(sub => ({code: sub.code, value: normalizeSubfieldValue(sub.value)}));\n\n return normalizedSubfields;\n\n function normalizeSubfieldValue(value) {\n return value.toLowerCase().replace(/\\s+/ug, '');\n }\n }\n }\n\n function checkSwapTag(fields) {\n if (swapTag.length > 0) {\n return fields.map(field => ({...field, tag: swapTagsFunc(field.tag)}));\n }\n\n return fields;\n\n function swapTagsFunc(tag) {\n const [foundRule] = swapTag.filter(rule => new RegExp(rule.from, 'u').test(tag));\n\n if (foundRule === undefined) {\n return tag;\n }\n\n return foundRule.to;\n }\n }\n\n function checkSwapSubfieldCodes(fields) {\n if (swapSubfieldCode.length > 0) {\n return fields.map(field => ({...field, subfields: swapSubfieldCodesFunc(field.subfields)}));\n }\n\n return fields;\n\n function swapSubfieldCodesFunc(subfields) {\n return subfields.map(sub => {\n const [foundRule] = swapSubfieldCode.filter(rule => rule.from === sub.code);\n\n if (foundRule === undefined) {\n return sub;\n }\n\n return {code: foundRule.to, value: sub.value};\n });\n }\n }\n\n function checkDropSubfields(fields) {\n if (dropSubfields.length > 0) {\n return fields.map(field => ({...field, subfields: dropSubfieldsFunc(field.subfields)}))\n .filter(field => field.subfields.length > 0);\n }\n\n return fields;\n\n function dropSubfieldsFunc(subfields) {\n return subfields.filter(sub => { // eslint-disable-line\n return !dropSubfields.some(({code, value = false, condition = false}) => {\n if (code !== sub.code) {\n return false;\n }\n\n if (!condition && value) {\n return value === sub.value;\n }\n\n if (condition === 'unless' && value) {\n return !new RegExp(value, 'u').test(sub.value);\n }\n\n return true;\n });\n });\n }\n }\n\n function checkCopyUnlessFields(fields) {\n if (copyUnless.length > 0) {\n return fields.filter(({subfields}) => copyUnless.some(filter => !subfields.some(sub => sub.code === filter.code && new RegExp(filter.value, 'u').test(sub.value))));\n }\n\n return fields;\n }\n};\n"],
|
|
5
|
+
"mappings": "AAAA,SAAQ,kBAAiB;AACzB,OAAO,uBAAuB;AAE9B,eAAe,CAAC;AAAA,EACd;AAAA,EACA,kBAAkB;AAAA,EAClB,oBAAoB;AAAA,EACpB,2BAA2B;AAAA,EAC3B,2BAA2B;AAAA,EAC3B,2BAA2B;AAAA,EAC3B,2BAA2B;A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,OAAO,YAAY,MAAK,MAAM;AACvE,cAAI,SAAS,IAAI,MAAM;AACrB,mBAAO;AAAA,UACT;AAEA,cAAI,CAAC,aAAa,OAAO;AACvB,mBAAO,UAAU,IAAI;AAAA,UACvB;AAEA,cAAI,cAAc,YAAY,OAAO;AACnC,mBAAO,CAAC,IAAI,OAAO,OAAO,GAAG,EAAE,KAAK,IAAI,KAAK;AAAA,UAC/C;AAEA,iBAAO;AAAA,QACT,CAAC;AAAA,MACH,CAAC;AAAA,IACH;AAAA,EACF;AAEA,WAAS,sBAAsB,QAAQ;AACrC,QAAI,WAAW,SAAS,GAAG;AACzB,aAAO,OAAO,OAAO,CAAC,EAAC,UAAS,MAAM,WAAW,KAAK,YAAU,CAAC,UAAU,KAAK,SAAO,IAAI,SAAS,OAAO,QAAQ,IAAI,OAAO,OAAO,OAAO,GAAG,EAAE,KAAK,IAAI,KAAK,CAAC,CAAC,CAAC;AAAA,IACpK;AAEA,WAAO;AAAA,EACT;AACF;",
|
|
6
|
+
"names": ["base", "source", "baseValidators", "sourceValidators", "baseRecord", "sourceRecord", "sourceFields", "baseCompareFields", "sourceCompareField", "unique"]
|
|
7
|
+
}
|
package/dist/reducers/index.js
CHANGED
|
@@ -1,17 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _copy = _interopRequireDefault(require("./copy"));
|
|
8
|
-
var _select = _interopRequireWildcard(require("./select"));
|
|
9
|
-
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
10
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
-
var _default = exports.default = {
|
|
12
|
-
copy: _copy.default,
|
|
13
|
-
select: _select.default,
|
|
14
|
-
strictEquality: _select.strictEquality,
|
|
15
|
-
subsetEquality: _select.subsetEquality
|
|
16
|
-
};
|
|
17
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
import copy from "./copy.js";
|
|
2
|
+
import select, { strictEquality, subsetEquality } from "./select.js";
|
|
3
|
+
export default { copy, select, strictEquality, subsetEquality };
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/reducers/index.js"],
|
|
4
|
+
"sourcesContent": ["import copy from './copy.js';\nimport select, {strictEquality, subsetEquality} from './select.js';\n\nexport default {copy, select, strictEquality, subsetEquality};\n"],
|
|
5
|
+
"mappings": "AAAA,OAAO,UAAU;AACjB,OAAO,UAAS,gBAAgB,sBAAqB;AAErD,eAAe,EAAC,MAAM,QAAQ,gBAAgB,eAAc;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|