@natlibfi/marc-record-merge 6.0.0-beta.2 → 6.0.0-beta.6

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.
Files changed (224) hide show
  1. package/.github/CODEOWNERS +9 -0
  2. package/.github/dependabot.yml +41 -0
  3. package/.github/workflows/melinda-node-tests.yml +60 -0
  4. package/LICENSE +21 -0
  5. package/README.md +106 -2
  6. package/dist/index.js +2 -37
  7. package/dist/index.js.map +1 -1
  8. package/dist/reducers/copy.js +310 -109
  9. package/dist/reducers/copy.js.map +1 -1
  10. package/dist/reducers/copy.spec.js +52 -99
  11. package/dist/reducers/copy.spec.js.map +1 -1
  12. package/dist/reducers/index.js +0 -27
  13. package/dist/reducers/index.js.map +1 -1
  14. package/dist/reducers/select.js +12 -50
  15. package/dist/reducers/select.js.map +1 -1
  16. package/dist/reducers/select.spec.js +49 -83
  17. package/dist/reducers/select.spec.js.map +1 -1
  18. package/package.json +30 -27
  19. package/src/index.js +1 -33
  20. package/src/reducers/copy.js +306 -115
  21. package/src/reducers/copy.spec.js +44 -66
  22. package/src/reducers/index.js +0 -27
  23. package/src/reducers/select.js +8 -51
  24. package/src/reducers/select.spec.js +37 -58
  25. package/test-fixtures/reducers/copy/{01/base.json → 01 - copy/01/base.json } +1 -1
  26. package/test-fixtures/reducers/copy/{01 → 01 - copy/01}/merged.json +0 -0
  27. package/test-fixtures/reducers/copy/01 - copy/01/metadata.json +4 -0
  28. package/test-fixtures/reducers/copy/{01 → 01 - copy/01}/source.json +0 -0
  29. package/test-fixtures/reducers/copy/{02/source.json → 01 - copy/02/base.json} +0 -0
  30. package/test-fixtures/reducers/copy/{02 → 01 - copy/02}/merged.json +0 -0
  31. package/test-fixtures/reducers/copy/01 - copy/02/metadata.json +4 -0
  32. package/test-fixtures/reducers/copy/{02/base.json → 01 - copy/02/source.json } +1 -1
  33. package/test-fixtures/reducers/copy/{03/base.json → 01 - copy/03/base.json } +1 -1
  34. package/test-fixtures/reducers/copy/{03 → 01 - copy/03}/merged.json +0 -0
  35. package/test-fixtures/reducers/copy/01 - copy/03/metadata.json +4 -0
  36. package/test-fixtures/reducers/copy/{03 → 01 - copy/03}/source.json +0 -0
  37. package/test-fixtures/reducers/copy/{05/base.json → 01 - copy/04/base.json } +1 -1
  38. package/test-fixtures/reducers/copy/{04/merged.json → 01 - copy/04/merged.json } +1 -1
  39. package/test-fixtures/reducers/copy/01 - copy/04/metadata.json +4 -0
  40. package/test-fixtures/reducers/copy/{04/source.json → 01 - copy/04/source.json } +1 -1
  41. package/test-fixtures/reducers/copy/{04/base.json → 01 - copy/05/base.json } +1 -1
  42. package/test-fixtures/reducers/copy/{05 → 01 - copy/05}/merged.json +0 -0
  43. package/test-fixtures/reducers/copy/01 - copy/05/metadata.json +4 -0
  44. package/test-fixtures/reducers/copy/{05 → 01 - copy/05}/source.json +0 -0
  45. package/test-fixtures/reducers/copy/01 - copy/06/base.json +24 -0
  46. package/test-fixtures/reducers/copy/01 - copy/06/merged.json +39 -0
  47. package/test-fixtures/reducers/copy/01 - copy/06/metadata.json +4 -0
  48. package/test-fixtures/reducers/copy/01 - copy/06/source.json +24 -0
  49. package/test-fixtures/reducers/copy/01 - copy/07/base.json +39 -0
  50. package/test-fixtures/reducers/copy/01 - copy/07/merged.json +39 -0
  51. package/test-fixtures/reducers/copy/01 - copy/07/metadata.json +5 -0
  52. package/test-fixtures/reducers/copy/01 - copy/07/source.json +24 -0
  53. package/test-fixtures/reducers/copy/01 - copy/08/base.json +28 -0
  54. package/test-fixtures/reducers/copy/01 - copy/08/merged.json +28 -0
  55. package/test-fixtures/reducers/copy/01 - copy/08/metadata.json +4 -0
  56. package/test-fixtures/reducers/copy/01 - copy/08/source.json +24 -0
  57. package/test-fixtures/reducers/copy/02 - doNotCopyIfFieldPresent/01/base.json +17 -0
  58. package/test-fixtures/reducers/copy/02 - doNotCopyIfFieldPresent/01/merged.json +20 -0
  59. package/test-fixtures/reducers/copy/02 - doNotCopyIfFieldPresent/01/metadata.json +6 -0
  60. package/test-fixtures/reducers/copy/02 - doNotCopyIfFieldPresent/01/source.json +20 -0
  61. package/test-fixtures/reducers/copy/02 - doNotCopyIfFieldPresent/02/base.json +9 -0
  62. package/test-fixtures/reducers/copy/02 - doNotCopyIfFieldPresent/02/merged.json +20 -0
  63. package/test-fixtures/reducers/copy/02 - doNotCopyIfFieldPresent/02/metadata.json +6 -0
  64. package/test-fixtures/reducers/copy/02 - doNotCopyIfFieldPresent/02/source.json +20 -0
  65. package/test-fixtures/reducers/copy/{06 → 03 - compareTagsOnly/01}/base.json +0 -0
  66. package/test-fixtures/reducers/copy/{06 → 03 - compareTagsOnly/01}/merged.json +0 -0
  67. package/test-fixtures/reducers/copy/03 - compareTagsOnly/01/metadata.json +5 -0
  68. package/test-fixtures/reducers/copy/{06 → 03 - compareTagsOnly/01}/source.json +0 -0
  69. package/test-fixtures/reducers/copy/{09 → 03 - compareTagsOnly/02}/base.json +0 -0
  70. package/test-fixtures/reducers/copy/{09 → 03 - compareTagsOnly/02}/merged.json +0 -0
  71. package/test-fixtures/reducers/copy/03 - compareTagsOnly/02/metadata.json +5 -0
  72. package/test-fixtures/reducers/copy/{09 → 03 - compareTagsOnly/02}/source.json +0 -0
  73. package/test-fixtures/reducers/copy/04 - compareWithoutIndicators/01/base.json +24 -0
  74. package/test-fixtures/reducers/copy/04 - compareWithoutIndicators/01/merged.json +24 -0
  75. package/test-fixtures/reducers/copy/04 - compareWithoutIndicators/01/metadata.json +5 -0
  76. package/test-fixtures/reducers/copy/04 - compareWithoutIndicators/01/source.json +24 -0
  77. package/test-fixtures/reducers/copy/04 - compareWithoutIndicators/02/base.json +24 -0
  78. package/test-fixtures/reducers/copy/04 - compareWithoutIndicators/02/merged.json +39 -0
  79. package/test-fixtures/reducers/copy/04 - compareWithoutIndicators/02/metadata.json +5 -0
  80. package/test-fixtures/reducers/copy/04 - compareWithoutIndicators/02/source.json +24 -0
  81. package/test-fixtures/reducers/copy/05 - copyUnless/01/base.json +9 -0
  82. package/test-fixtures/reducers/copy/05 - copyUnless/01/merged.json +24 -0
  83. package/test-fixtures/reducers/copy/05 - copyUnless/01/metadata.json +5 -0
  84. package/test-fixtures/reducers/copy/05 - copyUnless/01/source.json +47 -0
  85. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/01/base.json +24 -0
  86. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/01/merged.json +39 -0
  87. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/01/metadata.json +5 -0
  88. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/01/source.json +24 -0
  89. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/02/base.json +24 -0
  90. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/02/merged.json +24 -0
  91. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/02/metadata.json +5 -0
  92. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/02/source.json +24 -0
  93. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/03/base.json +28 -0
  94. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/03/merged.json +43 -0
  95. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/03/metadata.json +5 -0
  96. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/03/source.json +24 -0
  97. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/04/base.json +28 -0
  98. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/04/merged.json +28 -0
  99. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/04/metadata.json +5 -0
  100. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/04/source.json +24 -0
  101. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/05/base.json +20 -0
  102. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/05/merged.json +35 -0
  103. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/05/metadata.json +5 -0
  104. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/05/source.json +24 -0
  105. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/06/base.json +20 -0
  106. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/06/merged.json +35 -0
  107. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/06/metadata.json +5 -0
  108. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/06/source.json +24 -0
  109. package/test-fixtures/reducers/copy/{07 → 07 - excludeSubfields/01}/base.json +0 -0
  110. package/test-fixtures/reducers/copy/{07 → 07 - excludeSubfields/01}/merged.json +0 -0
  111. package/test-fixtures/reducers/copy/07 - excludeSubfields/01/metadata.json +8 -0
  112. package/test-fixtures/reducers/copy/{07 → 07 - excludeSubfields/01}/source.json +0 -0
  113. package/test-fixtures/reducers/copy/07 - excludeSubfields/02/base.json +39 -0
  114. package/test-fixtures/reducers/copy/07 - excludeSubfields/02/merged.json +58 -0
  115. package/test-fixtures/reducers/copy/07 - excludeSubfields/02/metadata.json +5 -0
  116. package/test-fixtures/reducers/copy/07 - excludeSubfields/02/source.json +43 -0
  117. package/test-fixtures/reducers/copy/{08 → 08 - dropSubfields/01}/base.json +0 -0
  118. package/test-fixtures/reducers/copy/{08/merged.json → 08 - dropSubfields/01/merged.json } +8 -0
  119. package/test-fixtures/reducers/copy/08 - dropSubfields/01/metadata.json +5 -0
  120. package/test-fixtures/reducers/copy/{08 → 08 - dropSubfields/01}/source.json +0 -0
  121. package/test-fixtures/reducers/copy/08 - dropSubfields/02/base.json +43 -0
  122. package/test-fixtures/reducers/copy/08 - dropSubfields/02/merged.json +58 -0
  123. package/test-fixtures/reducers/copy/08 - dropSubfields/02/metadata.json +5 -0
  124. package/test-fixtures/reducers/copy/08 - dropSubfields/02/source.json +32 -0
  125. package/test-fixtures/reducers/copy/08 - dropSubfields/03/base.json +43 -0
  126. package/test-fixtures/reducers/copy/08 - dropSubfields/03/merged.json +58 -0
  127. package/test-fixtures/reducers/copy/08 - dropSubfields/03/metadata.json +5 -0
  128. package/test-fixtures/reducers/copy/08 - dropSubfields/03/source.json +32 -0
  129. package/test-fixtures/reducers/copy/08 - dropSubfields/04/base.json +43 -0
  130. package/test-fixtures/reducers/copy/08 - dropSubfields/04/merged.json +43 -0
  131. package/test-fixtures/reducers/copy/08 - dropSubfields/04/metadata.json +5 -0
  132. package/test-fixtures/reducers/copy/08 - dropSubfields/04/source.json +32 -0
  133. package/test-fixtures/reducers/copy/09 - swapSubfieldCode/01/base.json +9 -0
  134. package/test-fixtures/reducers/copy/09 - swapSubfieldCode/01/merged.json +20 -0
  135. package/test-fixtures/reducers/copy/09 - swapSubfieldCode/01/metadata.json +6 -0
  136. package/test-fixtures/reducers/copy/09 - swapSubfieldCode/01/source.json +20 -0
  137. package/test-fixtures/reducers/copy/09 - swapSubfieldCode/02/base.json +9 -0
  138. package/test-fixtures/reducers/copy/09 - swapSubfieldCode/02/merged.json +20 -0
  139. package/test-fixtures/reducers/copy/09 - swapSubfieldCode/02/metadata.json +6 -0
  140. package/test-fixtures/reducers/copy/09 - swapSubfieldCode/02/source.json +20 -0
  141. package/test-fixtures/reducers/copy/09 - swapSubfieldCode/03/base.json +9 -0
  142. package/test-fixtures/reducers/copy/09 - swapSubfieldCode/03/merged.json +31 -0
  143. package/test-fixtures/reducers/copy/09 - swapSubfieldCode/03/metadata.json +6 -0
  144. package/test-fixtures/reducers/copy/09 - swapSubfieldCode/03/source.json +31 -0
  145. package/test-fixtures/reducers/copy/09 - swapSubfieldCode/04/base.json +9 -0
  146. package/test-fixtures/reducers/copy/09 - swapSubfieldCode/04/merged.json +42 -0
  147. package/test-fixtures/reducers/copy/09 - swapSubfieldCode/04/metadata.json +6 -0
  148. package/test-fixtures/reducers/copy/09 - swapSubfieldCode/04/source.json +42 -0
  149. package/test-fixtures/reducers/copy/10 - swapTag/01/base.json +17 -0
  150. package/test-fixtures/reducers/copy/10 - swapTag/01/merged.json +28 -0
  151. package/test-fixtures/reducers/copy/10 - swapTag/01/metadata.json +6 -0
  152. package/test-fixtures/reducers/copy/10 - swapTag/01/source.json +20 -0
  153. package/test-fixtures/reducers/metadata.json +4 -0
  154. package/test-fixtures/reducers/select/01/metadata.json +5 -0
  155. package/test-fixtures/reducers/select/02/metadata.json +4 -0
  156. package/test-fixtures/reducers/select/03/metadata.json +4 -0
  157. package/test-fixtures/reducers/select/04/metadata.json +5 -0
  158. package/test-fixtures/reducers/select/05/metadata.json +4 -0
  159. package/test-fixtures/reducers/select/06/metadata.json +4 -0
  160. package/test-fixtures/reducers/select/07/metadata.json +5 -0
  161. package/test-fixtures/reducers/select/08/metadata.json +4 -0
  162. package/test-fixtures/reducers/select/09/metadata.json +4 -0
  163. package/test-fixtures/reducers/select/10/metadata.json +5 -0
  164. package/test-fixtures/reducers/select/11/metadata.json +4 -0
  165. package/test-fixtures/reducers/select/12/metadata.json +5 -0
  166. package/test-fixtures/reducers/select/13/metadata.json +4 -0
  167. package/test-fixtures/reducers/select/14/metadata.json +4 -0
  168. package/.drone.yml +0 -92
  169. package/.nyc_output/72717fff-b4ac-4aef-a145-37cae88e07f8.json +0 -1
  170. package/.nyc_output/processinfo/72717fff-b4ac-4aef-a145-37cae88e07f8.json +0 -1
  171. package/.nyc_output/processinfo/index.json +0 -1
  172. package/LICENSE.txt +0 -165
  173. package/coverage/base.css +0 -224
  174. package/coverage/block-navigation.js +0 -79
  175. package/coverage/copy.js.html +0 -500
  176. package/coverage/favicon.png +0 -0
  177. package/coverage/index.html +0 -126
  178. package/coverage/lcov-report/base.css +0 -224
  179. package/coverage/lcov-report/block-navigation.js +0 -79
  180. package/coverage/lcov-report/copy.js.html +0 -500
  181. package/coverage/lcov-report/favicon.png +0 -0
  182. package/coverage/lcov-report/index.html +0 -126
  183. package/coverage/lcov-report/prettify.css +0 -1
  184. package/coverage/lcov-report/prettify.js +0 -2
  185. package/coverage/lcov-report/select.js.html +0 -539
  186. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  187. package/coverage/lcov-report/sorter.js +0 -170
  188. package/coverage/lcov.info +0 -274
  189. package/coverage/prettify.css +0 -1
  190. package/coverage/prettify.js +0 -2
  191. package/coverage/select.js.html +0 -539
  192. package/coverage/sort-arrow-sprite.png +0 -0
  193. package/coverage/sorter.js +0 -170
  194. package/test-fixtures/reducers/copy/01/tagPattern.txt +0 -1
  195. package/test-fixtures/reducers/copy/02/tagPattern.txt +0 -1
  196. package/test-fixtures/reducers/copy/03/tagPattern.txt +0 -1
  197. package/test-fixtures/reducers/copy/04/tagPattern.txt +0 -1
  198. package/test-fixtures/reducers/copy/05/tagPattern.txt +0 -1
  199. package/test-fixtures/reducers/copy/06/compareTagsOnly.txt +0 -1
  200. package/test-fixtures/reducers/copy/06/tagPattern.txt +0 -1
  201. package/test-fixtures/reducers/copy/07/excludeSubfields.json +0 -1
  202. package/test-fixtures/reducers/copy/07/tagPattern.txt +0 -1
  203. package/test-fixtures/reducers/copy/08/dropSubfields.json +0 -1
  204. package/test-fixtures/reducers/copy/08/tagPattern.txt +0 -1
  205. package/test-fixtures/reducers/copy/09/compareTagsOnly.txt +0 -1
  206. package/test-fixtures/reducers/copy/09/tagPattern.txt +0 -1
  207. package/test-fixtures/reducers/select/01/expected-error.txt +0 -1
  208. package/test-fixtures/reducers/select/01/pattern.txt +0 -1
  209. package/test-fixtures/reducers/select/02/pattern.txt +0 -1
  210. package/test-fixtures/reducers/select/03/pattern.txt +0 -1
  211. package/test-fixtures/reducers/select/04/pattern.txt +0 -1
  212. package/test-fixtures/reducers/select/05/pattern.txt +0 -1
  213. package/test-fixtures/reducers/select/06/pattern.txt +0 -1
  214. package/test-fixtures/reducers/select/07/equalityFunction.txt +0 -1
  215. package/test-fixtures/reducers/select/07/pattern.txt +0 -1
  216. package/test-fixtures/reducers/select/08/pattern.txt +0 -1
  217. package/test-fixtures/reducers/select/09/pattern.txt +0 -1
  218. package/test-fixtures/reducers/select/10/equalityFunction.txt +0 -1
  219. package/test-fixtures/reducers/select/10/pattern.txt +0 -1
  220. package/test-fixtures/reducers/select/11/pattern.txt +0 -1
  221. package/test-fixtures/reducers/select/12/equalityFunction.txt +0 -1
  222. package/test-fixtures/reducers/select/12/pattern.txt +0 -1
  223. package/test-fixtures/reducers/select/13/pattern.txt +0 -1
  224. package/test-fixtures/reducers/select/14/pattern.txt +0 -1
@@ -1,114 +1,67 @@
1
1
  "use strict";
2
2
 
3
- var _chai = _interopRequireDefault(require("chai"));
3
+ var _chai = require("chai");
4
4
 
5
- var _fs = _interopRequireDefault(require("fs"));
6
-
7
- var _path = _interopRequireDefault(require("path"));
5
+ var _fixura = require("@natlibfi/fixura");
8
6
 
9
7
  var _marcRecord = require("@natlibfi/marc-record");
10
8
 
11
9
  var _copy = _interopRequireDefault(require("./copy"));
12
10
 
13
- var _fixura = _interopRequireWildcard(require("@natlibfi/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); }
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; }
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
- * @licstart The following is the entire license notice for the JavaScript code in this file.
24
- *
25
- * Merge MARC records
26
- *
27
- * Copyright (C) 2015-2019 University Of Helsinki (The National Library Of Finland)
28
- *
29
- * This file is part of marc-record-merge-js
30
-
31
- * marc-record-merge-js program is free software: you can redistribute it and/or modify
32
- * it under the terms of the GNU Lesser General Public License as
33
- * published by the Free Software Foundation, either version 3 of the
34
- * License, or (at your option) any later version.
35
- *
36
- * marc-record-merge-js is distributed in the hope that it will be useful,
37
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
38
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
39
- * GNU Lesser General Public License for more details.
40
- *
41
- * You should have received a copy of the GNU Lesser General Public License
42
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
43
- *
44
- * @licend The above is the entire license notice
45
- * for the JavaScript code in this file.
46
- *
47
- */
48
- _marcRecord.MarcRecord.setValidationOptions({
49
- subfieldValues: false
15
+ //import createDebugLogger from 'debug'; // <---
16
+ //const debug = createDebugLogger('@natlibfi/marc-record-merge/copy.spec.js'); // <---
17
+ (0, _fixugen.default)({
18
+ callback,
19
+ path: [__dirname, '..', '..', 'test-fixtures', 'reducers', 'copy'],
20
+ useMetadataFile: true,
21
+ recurse: true,
22
+ fixura: {
23
+ reader: _fixura.READERS.JSON,
24
+ failWhenNotFound: false
25
+ }
50
26
  });
51
27
 
52
- describe('reducers/copy', () => {
53
- const {
54
- expect
55
- } = _chai.default;
56
-
57
- const fixturesPath = _path.default.join(__dirname, '..', '..', 'test-fixtures', 'reducers', 'copy');
58
-
59
- _fs.default.readdirSync(fixturesPath).forEach(subDir => {
60
- const {
61
- getFixture
62
- } = (0, _fixura.default)({
63
- root: [fixturesPath, subDir],
64
- reader: _fixura.READERS.JSON,
65
- failWhenNotFound: false
66
- });
67
- it(subDir, () => {
68
- const base = new _marcRecord.MarcRecord(getFixture('base.json'));
69
- const source = new _marcRecord.MarcRecord(getFixture('source.json'));
70
- const tagPattern = new RegExp(getFixture({
71
- components: ['tagPattern.txt'],
72
- reader: _fixura.READERS.TEXT
73
- }), 'u');
74
- const compareTagsOnly = getCompareTagsOnly();
75
- const excludeSubfields = getExcludeSubfields();
76
- const dropSubfields = getDropSubfields();
77
- const expectedRecord = getFixture('merged.json');
78
- const mergedRecord = (0, _copy.default)({
79
- tagPattern,
80
- compareTagsOnly,
81
- excludeSubfields,
82
- dropSubfields
83
- })(base, source);
84
- expect(mergedRecord.toObject()).to.eql(expectedRecord); // Non-repeatable MARC fields are copied from source only if they are missing from base
85
-
86
- function getCompareTagsOnly() {
87
- const functionName = getFixture({
88
- components: ['compareTagsOnly.txt'],
89
- reader: _fixura.READERS.TEXT
90
- });
91
- return functionName === 'true' ? 'true' : undefined;
92
- } // Check whether excludeSubfields.json exists and if it does, return its contents. If not, do nothing.
93
-
94
-
95
- function getExcludeSubfields() {
96
- const subfieldsToExclude = getFixture({
97
- components: ['excludeSubfields.json'],
98
- reader: _fixura.READERS.JSON
99
- });
100
- return subfieldsToExclude ? subfieldsToExclude : undefined;
101
- } // Check whether dropSubfields.json exists and if it does, return its contents. If not, do nothing.
102
-
103
-
104
- function getDropSubfields() {
105
- const subfieldsToDrop = getFixture({
106
- components: ['dropSubfields.json'],
107
- reader: _fixura.READERS.JSON
108
- });
109
- return subfieldsToDrop ? subfieldsToDrop : undefined;
110
- }
111
- });
28
+ function callback({
29
+ getFixture,
30
+ tagPatternRegExp,
31
+ compareTagsOnly = false,
32
+ compareWithoutIndicators = false,
33
+ subfieldsMustBeIdentical = false,
34
+ copyUnless = undefined,
35
+ excludeSubfields = undefined,
36
+ dropSubfields = undefined,
37
+ swapSubfieldCode = [],
38
+ swapTag = [],
39
+ doNotCopyIfFieldPresent = false
40
+ }) {
41
+ const base = new _marcRecord.MarcRecord(getFixture('base.json'), {
42
+ subfieldValues: false
112
43
  });
113
- });
44
+ const source = new _marcRecord.MarcRecord(getFixture('source.json'), {
45
+ subfieldValues: false
46
+ });
47
+ const tagPattern = new RegExp(tagPatternRegExp, 'u');
48
+ const expectedRecord = getFixture('merged.json');
49
+ const mergedRecord = (0, _copy.default)({
50
+ tagPattern,
51
+ compareTagsOnly,
52
+ compareWithoutIndicators,
53
+ copyUnless,
54
+ subfieldsMustBeIdentical,
55
+ excludeSubfields,
56
+ dropSubfields,
57
+ swapSubfieldCode,
58
+ swapTag,
59
+ doNotCopyIfFieldPresent
60
+ })(base, source); //debug(`*** mergedRecord: `, mergedRecord); //<--
61
+ //debug(`*** mergedRecord,Strfy: `, JSON.stringify(mergedRecord)); //<--
62
+ //debug(`*** expectedRecord: `, expectedRecord); //<--
63
+ //debug(`*** expectedRecord,Strfy: `, JSON.stringify(expectedRecord)); //<--
64
+
65
+ (0, _chai.expect)(mergedRecord).to.eql(expectedRecord);
66
+ }
114
67
  //# sourceMappingURL=copy.spec.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/reducers/copy.spec.js"],"names":["MarcRecord","setValidationOptions","subfieldValues","describe","expect","chai","fixturesPath","path","join","__dirname","fs","readdirSync","forEach","subDir","getFixture","root","reader","READERS","JSON","failWhenNotFound","it","base","source","tagPattern","RegExp","components","TEXT","compareTagsOnly","getCompareTagsOnly","excludeSubfields","getExcludeSubfields","dropSubfields","getDropSubfields","expectedRecord","mergedRecord","toObject","to","eql","functionName","undefined","subfieldsToExclude","subfieldsToDrop"],"mappings":";;AA2BA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;AAhCA;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;AAQAA,uBAAWC,oBAAX,CAAgC;AAACC,EAAAA,cAAc,EAAE;AAAjB,CAAhC;;AAEAC,QAAQ,CAAC,eAAD,EAAkB,MAAM;AAC9B,QAAM;AAACC,IAAA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CAAuCJ,cAAvC,EATe,CAWf;;AACA,eAASL,kBAAT,GAA8B;AAC5B,cAAMU,YAAY,GAAGxB,UAAU,CAAC;AAACW,UAAAA,UAAU,EAAE,CAAC,qBAAD,CAAb;AAAsCT,UAAAA,MAAM,EAAEC,gBAAQS;AAAtD,SAAD,CAA/B;AACA,eAAOY,YAAY,KAAK,MAAjB,GAA0B,MAA1B,GAAmCC,SAA1C;AACD,OAfc,CAgBf;;;AACA,eAAST,mBAAT,GAA+B;AAC7B,cAAMU,kBAAkB,GAAG1B,UAAU,CAAC;AAACW,UAAAA,UAAU,EAAE,CAAC,uBAAD,CAAb;AAAwCT,UAAAA,MAAM,EAAEC,gBAAQC;AAAxD,SAAD,CAArC;AACA,eAAOsB,kBAAkB,GAAGA,kBAAH,GAAwBD,SAAjD;AACD,OApBc,CAsBf;;;AACA,eAASP,gBAAT,GAA4B;AAC1B,cAAMS,eAAe,GAAG3B,UAAU,CAAC;AAACW,UAAAA,UAAU,EAAE,CAAC,oBAAD,CAAb;AAAqCT,UAAAA,MAAM,EAAEC,gBAAQC;AAArD,SAAD,CAAlC;AACA,eAAOuB,eAAe,GAAGA,eAAH,GAAqBF,SAA3C;AACD;AACF,KA3BC,CAAF;AA4BD,GA9BD;AA+BD,CAnCO,CAAR","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*/\nimport chai from 'chai';\nimport fs from 'fs';\nimport path from 'path';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport createReducer from './copy';\nimport fixturesFactory, {READERS} from '@natlibfi/fixura';\n\nMarcRecord.setValidationOptions({subfieldValues: false});\n\ndescribe('reducers/copy', () => {\n const {expect} = chai;\n const fixturesPath = path.join(__dirname, '..', '..', 'test-fixtures', 'reducers', 'copy');\n\n fs.readdirSync(fixturesPath).forEach(subDir => {\n const {getFixture} = fixturesFactory({root: [fixturesPath, subDir], reader: READERS.JSON, failWhenNotFound: false});\n it(subDir, () => {\n const base = new MarcRecord(getFixture('base.json'));\n const source = new MarcRecord(getFixture('source.json'));\n const tagPattern = new RegExp(getFixture({components: ['tagPattern.txt'], reader: READERS.TEXT}), 'u');\n const compareTagsOnly = getCompareTagsOnly();\n const excludeSubfields = getExcludeSubfields();\n const dropSubfields = getDropSubfields();\n const expectedRecord = getFixture('merged.json');\n const mergedRecord = createReducer({tagPattern, compareTagsOnly, excludeSubfields, dropSubfields})(base, source);\n expect(mergedRecord.toObject()).to.eql(expectedRecord);\n\n // Non-repeatable MARC fields are copied from source only if they are missing from base\n function getCompareTagsOnly() {\n const functionName = getFixture({components: ['compareTagsOnly.txt'], reader: READERS.TEXT});\n return functionName === 'true' ? 'true' : undefined;\n }\n // Check whether excludeSubfields.json exists and if it does, return its contents. If not, do nothing.\n function getExcludeSubfields() {\n const subfieldsToExclude = getFixture({components: ['excludeSubfields.json'], reader: READERS.JSON});\n return subfieldsToExclude ? subfieldsToExclude : undefined;\n }\n\n // Check whether dropSubfields.json exists and if it does, return its contents. If not, do nothing.\n function getDropSubfields() {\n const subfieldsToDrop = getFixture({components: ['dropSubfields.json'], reader: READERS.JSON});\n return subfieldsToDrop ? subfieldsToDrop : undefined;\n }\n });\n });\n});\n"],"file":"copy.spec.js"}
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","swapSubfieldCode","swapTag","doNotCopyIfFieldPresent","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 swapSubfieldCode = [],\n swapTag = [],\n doNotCopyIfFieldPresent = false\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({\n tagPattern, compareTagsOnly, compareWithoutIndicators,\n copyUnless, subfieldsMustBeIdentical, excludeSubfields,\n dropSubfields, swapSubfieldCode, swapTag,\n doNotCopyIfFieldPresent\n })(base, source);\n //debug(`*** mergedRecord: `, mergedRecord); //<--\n //debug(`*** mergedRecord,Strfy: `, JSON.stringify(mergedRecord)); //<--\n //debug(`*** expectedRecord: `, expectedRecord); //<--\n //debug(`*** expectedRecord,Strfy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C;IAGlBC,gBAHkB;IAGAC,OAHA;IAIjCC;EAJiC,CAAd,EAKlBC,IALkB,EAKZG,MALY,CAArB,CANC,CAYD;EACA;EACA;EACA;;EACA,IAAAM,YAAA,EAAOF,YAAP,EAAqBG,EAArB,CAAwBC,GAAxB,CAA4BL,cAA5B;AACD"}
@@ -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,"sources":["../../src/reducers/index.js"],"names":["copy","select","strictEquality","subsetEquality"],"mappings":";;;;;;;AA2BA;;AACA;;;;;;;;AA5BA;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;eAIe;AAACA,EAAAA,IAAI,EAAJA,aAAD;AAAOC,EAAAA,MAAM,EAANA,eAAP;AAAeC,EAAAA,cAAc,EAAdA,sBAAf;AAA+BC,EAAAA,cAAc,EAAdA;AAA/B,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*/\nimport copy from './copy';\nimport select, {strictEquality, subsetEquality} from './select';\n\nexport default {copy, select, strictEquality, subsetEquality};\n"],"file":"index.js"}
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"}
@@ -3,62 +3,18 @@
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
 
12
12
  var _debug = _interopRequireDefault(require("debug"));
13
13
 
14
+ var _marcRecord = require("@natlibfi/marc-record");
15
+
14
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
17
 
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
18
  function strictEquality(subfieldA, subfieldB) {
63
19
  return subfieldA.code === subfieldB.code && subfieldA.value === subfieldB.value;
64
20
  }
@@ -72,9 +28,15 @@ var _default = ({
72
28
  tagPattern,
73
29
  equalityFunction = strictEquality
74
30
  }) => (base, source) => {
75
- const debug = (0, _debug.default)('@natlibfi/marc-record-merge');
76
- const baseFields = base.get(tagPattern);
77
- const sourceFields = source.get(tagPattern);
31
+ const debug = (0, _debug.default)('@natlibfi/marc-record-merge:select');
32
+ const baseRecord = new _marcRecord.MarcRecord(base, {
33
+ subfieldValues: false
34
+ });
35
+ const sourceRecord = new _marcRecord.MarcRecord(source, {
36
+ subfieldValues: false
37
+ });
38
+ const baseFields = baseRecord.get(tagPattern);
39
+ const sourceFields = sourceRecord.get(tagPattern);
78
40
  const fieldTag = sourceFields.map(field => field.tag);
79
41
  debug(`Comparing field ${fieldTag}`);
80
42
  checkFieldType(baseFields);
@@ -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;AAC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BAAkB,CAACT,MAAnB,KAA8BG,QAAQ,CAACH,MAAlF,EAA0F;AACxF,WAAOsB,+BAA+B,CAACjC,IAAD,CAAtC;AACD;;AAEDE,EAAAA,KAAK,CAAE,oBAAF,CAAL;AACA,SAAOF,IAAP;;AAEA,WAASiC,+BAAT,CAAyCjC,IAAzC,EAA+C;AAC7C,UAAMkC,KAAK,GAAGlC,IAAI,CAACmC,MAAL,CAAYC,SAAZ,CAAsB5B,KAAK,IAAIA,KAAK,KAAKI,SAAzC,CAAd;AACAZ,IAAAA,IAAI,CAACmC,MAAL,CAAYE,MAAZ,CAAmBH,KAAnB,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","baseRecord","MarcRecord","subfieldValues","sourceRecord","baseFields","get","sourceFields","fieldTag","map","field","tag","checkFieldType","length","baseField","sourceField","baseSubs","subfields","sourceSubs","baseSubsNormalized","normalizeSubfieldValue","sourceSubsNormalized","equalSubfieldsBase","filter","baseSubfield","some","sourceSubfield","JSON","stringify","undefined","equalSubfieldsSource","totalSubfieldLengthBase","reduce","acc","totalSubfieldLengthSource","replaceBasefieldWithSourcefield","index","fields","findIndex","splice","checkedFields","Error","punctuation","normalizeSync","toLowerCase","replace","trim"],"sources":["../../src/reducers/select.js"],"sourcesContent":["import {normalizeSync} from 'normalize-diacritics';\nimport createDebugLogger from 'debug';\nimport {MarcRecord} from '@natlibfi/marc-record';\n\nexport function strictEquality(subfieldA, subfieldB) {\n return subfieldA.code === subfieldB.code &&\n subfieldA.value === subfieldB.value;\n}\n\nexport function subsetEquality(subfieldA, subfieldB) {\n return subfieldA.code === subfieldB.code &&\n (subfieldA.value.indexOf(subfieldB.value) !== -1 || subfieldB.value.indexOf(subfieldA.value) !== -1);\n}\n// EqualityFunction can be either strictEquality or subsetEquality\nexport default ({tagPattern, equalityFunction = strictEquality}) => (base, source) => {\n const debug = createDebugLogger('@natlibfi/marc-record-merge:select');\n const baseRecord = new MarcRecord(base, {subfieldValues: false});\n const sourceRecord = new MarcRecord(source, {subfieldValues: false});\n const baseFields = baseRecord.get(tagPattern);\n const sourceFields = sourceRecord.get(tagPattern);\n const fieldTag = sourceFields.map(field => field.tag);\n debug(`Comparing field ${fieldTag}`);\n\n checkFieldType(baseFields);\n checkFieldType(sourceFields);\n\n if (baseFields.length > 1 || sourceFields.length > 1) {\n debug(`Multiple fields in base or source`);\n debug(`No changes to base`);\n return base;\n }\n const [baseField] = baseFields;\n const [sourceField] = sourceFields;\n\n if (baseField.tag === sourceField.tag === false) {\n debug(`Base tag ${baseField.tag} is not equal to source tag ${sourceField.tag}`);\n debug(`No changes to base`);\n return base;\n }\n const baseSubs = baseField.subfields;\n const sourceSubs = sourceField.subfields;\n\n const baseSubsNormalized = baseSubs\n .map(({code, value}) => ({code, value: normalizeSubfieldValue(value)}));\n\n const sourceSubsNormalized = sourceSubs\n .map(({code, value}) => ({code, value: normalizeSubfieldValue(value)}));\n\n // Returns the base subfields for which a matching source subfield is found\n const equalSubfieldsBase = baseSubsNormalized\n .filter(baseSubfield => sourceSubsNormalized\n .some(sourceSubfield => equalityFunction(baseSubfield, sourceSubfield)));\n debug(`equalSubfieldsBase: ${JSON.stringify(equalSubfieldsBase, undefined, 2)}`);\n\n // Returns the source subfields for which a matching base subfield is found\n const equalSubfieldsSource = sourceSubsNormalized\n .filter(sourceSubfield => baseSubsNormalized\n .some(baseSubfield => equalityFunction(sourceSubfield, baseSubfield)));\n debug(`equalSubfieldsSource: ${JSON.stringify(equalSubfieldsSource, undefined, 2)}`);\n\n if (baseSubs.length === sourceSubs.length && equalSubfieldsBase.length < baseSubs.length) {\n debug(`Base and source subfields are not equal`);\n debug(`No changes to base`);\n return base;\n }\n\n if (baseSubs.length === sourceSubs.length && equalSubfieldsBase.length === equalSubfieldsSource.length) {\n debug(`Checking subfield equality`);\n const totalSubfieldLengthBase = baseSubsNormalized\n .map(({value}) => value.length)\n .reduce((acc, value) => acc + value);\n const totalSubfieldLengthSource = sourceSubsNormalized\n .map(({value}) => value.length)\n .reduce((acc, value) => acc + value);\n\n if (totalSubfieldLengthSource > totalSubfieldLengthBase) {\n return replaceBasefieldWithSourcefield(base);\n }\n }\n\n if (sourceSubs.length > baseSubs.length && equalSubfieldsBase.length === baseSubs.length) {\n return replaceBasefieldWithSourcefield(base);\n }\n\n debug(`No changes to base`);\n return base;\n\n function replaceBasefieldWithSourcefield(base) {\n const index = base.fields.findIndex(field => field === baseField);\n base.fields.splice(index, 1, sourceField); // eslint-disable-line functional/immutable-data\n debug(`Source field is longer, replacing base with source`);\n return base;\n }\n\n function checkFieldType(fields) {\n const checkedFields = fields.map(field => {\n if ('value' in field) { // eslint-disable-line functional/no-conditional-statement\n throw new Error('Invalid control field, expected data field');\n }\n return field;\n });\n return checkedFields;\n }\n\n function normalizeSubfieldValue(value) {\n // Regexp options: g: global search, u: unicode\n const punctuation = /[.,\\-/#!?$%^&*;:{}=_`~()[\\]]/gu;\n return normalizeSync(value).toLowerCase().replace(punctuation, '', 'u').replace(/\\s+/gu, ' ').trim();\n }\n};\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;;;AAEO,SAASA,cAAT,CAAwBC,SAAxB,EAAmCC,SAAnC,EAA8C;EACnD,OAAOD,SAAS,CAACE,IAAV,KAAmBD,SAAS,CAACC,IAA7B,IACLF,SAAS,CAACG,KAAV,KAAoBF,SAAS,CAACE,KADhC;AAED;;AAEM,SAASC,cAAT,CAAwBJ,SAAxB,EAAmCC,SAAnC,E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AAYC,SAAZ,CAAsB5B,KAAK,IAAIA,KAAK,KAAKI,SAAzC,CAAd;IACAjB,IAAI,CAACwC,MAAL,CAAYE,MAAZ,CAAmBH,KAAnB,EAA0B,CAA1B,EAA6BrB,WAA7B,EAF6C,CAEF;;IAC3ChB,KAAK,CAAE,oDAAF,CAAL;IACA,OAAOF,IAAP;EACD;;EAED,SAASe,cAAT,CAAwByB,MAAxB,EAAgC;IAC9B,MAAMG,aAAa,GAAGH,MAAM,CAAC5B,GAAP,CAAWC,KAAK,IAAI;MACxC,IAAI,WAAWA,KAAf,EAAsB;QAAE;QACtB,MAAM,IAAI+B,KAAJ,CAAU,4CAAV,CAAN;MACD;;MACD,OAAO/B,KAAP;IACD,CALqB,CAAtB;IAMA,OAAO8B,aAAP;EACD;;EAED,SAASpB,sBAAT,CAAgC5B,KAAhC,EAAuC;IACrC;IACA,MAAMkD,WAAW,GAAG,gCAApB;IACA,OAAO,IAAAC,kCAAA,EAAcnD,KAAd,EAAqBoD,WAArB,GAAmCC,OAAnC,CAA2CH,WAA3C,EAAwD,EAAxD,EAA4D,GAA5D,EAAiEG,OAAjE,CAAyE,OAAzE,EAAkF,GAAlF,EAAuFC,IAAvF,EAAP;EACD;AACF,C"}
@@ -1,102 +1,68 @@
1
1
  "use strict";
2
2
 
3
- var _chai = _interopRequireDefault(require("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 = _interopRequireWildcard(require("@natlibfi/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
- 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; }
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
- * @licstart The following is the entire license notice for the JavaScript code in this file.
24
- *
25
- * Merge MARC records
26
- *
27
- * Copyright (C) 2015-2019 University Of Helsinki (The National Library Of Finland)
28
- *
29
- * This file is part of marc-record-merge-js
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
- describe('reducers/select', () => {
53
- const {
54
- expect
55
- } = _chai.default;
56
-
57
- const fixturesPath = _path.default.join(__dirname, '..', '..', 'test-fixtures', 'reducers', 'select');
58
-
59
- _fs.default.readdirSync(fixturesPath).forEach(subDir => {
60
- const {
61
- getFixture
62
- } = (0, _fixura.default)({
63
- root: [fixturesPath, subDir],
64
- reader: _fixura.READERS.JSON,
65
- failWhenNotFound: false
66
- });
67
- it(subDir, () => {
68
- const 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
- function getEqualityFunction() {
93
- const functionName = getFixture({
94
- components: ['equalityFunction.txt'],
95
- reader: _fixura.READERS.TEXT
96
- });
97
- return functionName === 'subsetEquality' ? _select.subsetEquality : undefined;
98
- }
99
- });
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,"sources":["../../src/reducers/select.spec.js"],"names":["MarcRecord","setValidationOptions","subfieldValues","describe","expect","chai","fixturesPath","path","join","__dirname","fs","readdirSync","forEach","subDir","getFixture","root","reader","READERS","JSON","failWhenNotFound","it","base","source","tagPattern","RegExp","components","TEXT","expectedRecord","expectedError","equalityFunction","getEqualityFunction","createReducer","to","throw","Error","mergedRecord","toObject","eql","functionName","subsetEquality","undefined"],"mappings":";;AA2BA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;AAhCA;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;AAQAA,uBAAWC,oBAAX,CAAgC;AAACC,EAAAA,cAAc,EAAE;AAAjB,CAAhC;;AAEAC,QAAQ,CAAC,iBAAD,EAAoB,MAAM;AAChC,QAAM;AAACC,IAAAA;AAAD,MAAWC,aAAjB;;AACA,QAAMC,YAAY,GAAGC,cAAKC,IAAL,CAAUC,SAAV,EAAqB,IAArB,EAA2B,IAA3B,EAAiC,eAAjC,EAAkD,UAAlD,EAA8D,QAA9D,CAArB;;AAEAC,cAAGC,WAAH,CAAeL,YAAf,EAA6BM,OAA7B,CAAqCC,MAAM,IAAI;AAC7C,UAAM;AAACC,MAAAA;AAAD,QAAe,qBAAgB;AAACC,MAAAA,IAAI,EAAE,CAACT,YAAD,EAAeO,MAAf,CAAP;AAA+BG,MAAAA,MAAM,EAAEC,gBAAQC,IAA/C;AAAqDC,MAAAA,gBAAgB,EAAE;AAAvE,KAAhB,CAArB;AACAC,IAAAA,EAAE,CAACP,MAAD,EAAS,MAAM;AACf,YAAMQ,IAAI,GAAG,IAAIrB,sBAAJ,CAAec,UAAU,CAAC,WAAD,CAAzB,CAAb;AACA,YAAMQ,MAAM,GAAG,IAAItB,sBAAJ,CAAec,UAAU,CAAC,aAAD,CAAzB,CAAf;AACA,YAAMS,UAAU,GAAG,IAAIC,MAAJ,CAAWV,UAAU,CAAC;AAACW,QAAAA,UAAU,EAAE,CAAC,aAAD,CAAb;AAA8BT,QAAAA,MAAM,EAAEC,gBAAQS;AAA9C,OAAD,CAArB,EAA4E,GAA5E,CAAnB;AACA,YAAMC,cAAc,GAAGb,UAAU,CAAC,aAAD,CAAjC;AACA,YAAMc,aAAa,GAAGd,UAAU,CAAC;AAACW,QAAAA,UAAU,EAAE,CAAC,oBAAD,CAAb;AAAqCT,QAAAA,MAAM,EAAEC,gBAAQS;AAArD,OAAD,CAAhC;AACA,YAAMG,gBAAgB,GAAGC,mBAAmB,EAA5C,CANe,CAQf;;AACA,UAAIF,aAAJ,EAAmB;AACjBxB,QAAAA,MAAM,CAAC,MAAM2B,gBAAcC,EAAd,CAAiBC,KAAjB,CAAuBC,KAAvB,EAA8B,eAA9B,CAAP,CAAN;AACA;AACD;;AACD,YAAMC,YAAY,GAAG,qBAAc;AAACZ,QAAAA,UAAD;AAAaM,QAAAA;AAAb,OAAd,EAA8CR,IAA9C,EAAoDC,MAApD,CAArB;AACAlB,MAAAA,MAAM,CAAC+B,YAAY,CAACC,QAAb,EAAD,CAAN,CAAgCJ,EAAhC,CAAmCK,GAAnC,CAAuCV,cAAvC,EAde,CAgBf;;AACA,eAASG,mBAAT,GAA+B;AAC7B,cAAMQ,YAAY,GAAGxB,UAAU,CAAC;AAACW,UAAAA,UAAU,EAAE,CAAC,sBAAD,CAAb;AAAuCT,UAAAA,MAAM,EAAEC,gBAAQS;AAAvD,SAAD,CAA/B;AACA,eAAOY,YAAY,KAAK,gBAAjB,GAAoCC,sBAApC,GAAqDC,SAA5D;AACD;AACF,KArBC,CAAF;AAsBD,GAxBD;AAyBD,CA7BO,CAAR","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*/\nimport chai from 'chai';\nimport fs from 'fs';\nimport path from 'path';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport createReducer, {subsetEquality} from './select';\nimport fixturesFactory, {READERS} from '@natlibfi/fixura';\n\nMarcRecord.setValidationOptions({subfieldValues: false});\n\ndescribe('reducers/select', () => {\n const {expect} = chai;\n const fixturesPath = path.join(__dirname, '..', '..', 'test-fixtures', 'reducers', 'select');\n\n fs.readdirSync(fixturesPath).forEach(subDir => {\n const {getFixture} = fixturesFactory({root: [fixturesPath, subDir], reader: READERS.JSON, failWhenNotFound: false});\n it(subDir, () => {\n const base = new MarcRecord(getFixture('base.json'));\n const source = new MarcRecord(getFixture('source.json'));\n const tagPattern = new RegExp(getFixture({components: ['pattern.txt'], reader: READERS.TEXT}), 'u');\n const expectedRecord = getFixture('merged.json');\n const expectedError = getFixture({components: ['expected-error.txt'], reader: READERS.TEXT});\n const equalityFunction = getEqualityFunction();\n\n // Bypass expected error in testing\n if (expectedError) {\n expect(() => createReducer.to.throw(Error, 'control field'));\n return;\n }\n const mergedRecord = createReducer({tagPattern, equalityFunction})(base, source);\n expect(mergedRecord.toObject()).to.eql(expectedRecord);\n\n // Choose which equality function to use\n function getEqualityFunction() {\n const functionName = getFixture({components: ['equalityFunction.txt'], reader: READERS.TEXT});\n return functionName === 'subsetEquality' ? subsetEquality : undefined;\n }\n });\n });\n});\n"],"file":"select.spec.js"}
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,M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