@natlibfi/marc-record-merge 6.0.0-beta.1 → 6.0.0-beta.11

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 (263) 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 +122 -2
  6. package/dist/index.js +56 -42
  7. package/dist/index.js.map +1 -1
  8. package/dist/index.spec.js +59 -0
  9. package/dist/index.spec.js.map +1 -0
  10. package/dist/reducers/copy.js +254 -80
  11. package/dist/reducers/copy.js.map +1 -1
  12. package/dist/reducers/copy.spec.js +57 -72
  13. package/dist/reducers/copy.spec.js.map +1 -1
  14. package/dist/reducers/copy2.spec.js +67 -0
  15. package/dist/reducers/copy2.spec.js.map +1 -0
  16. package/dist/reducers/index.js +13 -24
  17. package/dist/reducers/index.js.map +1 -1
  18. package/dist/reducers/select.js +63 -58
  19. package/dist/reducers/select.js.map +1 -1
  20. package/dist/reducers/select.spec.js +45 -92
  21. package/dist/reducers/select.spec.js.map +1 -1
  22. package/dist/reducers/select2.spec.js +58 -0
  23. package/dist/reducers/select2.spec.js.map +1 -0
  24. package/package.json +33 -32
  25. package/src/index.js +50 -32
  26. package/src/index.spec.js +45 -0
  27. package/src/reducers/copy.js +262 -80
  28. package/src/reducers/copy.spec.js +50 -48
  29. package/src/reducers/copy2.spec.js +55 -0
  30. package/src/reducers/index.js +3 -30
  31. package/src/reducers/select.js +53 -39
  32. package/src/reducers/select.spec.js +41 -56
  33. package/src/reducers/select2.spec.js +49 -0
  34. package/test-fixtures/index/01/base.json +24 -0
  35. package/test-fixtures/index/01/merged.json +24 -0
  36. package/test-fixtures/index/01/metadata.json +8 -0
  37. package/test-fixtures/index/01/source.json +40 -0
  38. package/test-fixtures/index/02/base.json +24 -0
  39. package/test-fixtures/index/02/merged.json +24 -0
  40. package/test-fixtures/index/02/metadata.json +7 -0
  41. package/test-fixtures/index/02/source.json +40 -0
  42. package/test-fixtures/reducers/copy/{01/base.json → 01 - copy/01/base.json } +1 -1
  43. package/test-fixtures/reducers/copy/{01 → 01 - copy/01}/merged.json +0 -0
  44. package/test-fixtures/reducers/copy/01 - copy/01/metadata.json +4 -0
  45. package/test-fixtures/reducers/copy/{01 → 01 - copy/01}/source.json +0 -0
  46. package/test-fixtures/reducers/copy/{02/source.json → 01 - copy/02/base.json} +0 -0
  47. package/test-fixtures/reducers/copy/{02 → 01 - copy/02}/merged.json +0 -0
  48. package/test-fixtures/reducers/copy/01 - copy/02/metadata.json +4 -0
  49. package/test-fixtures/reducers/copy/{02/base.json → 01 - copy/02/source.json } +1 -1
  50. package/test-fixtures/reducers/copy/{03/base.json → 01 - copy/03/base.json } +1 -1
  51. package/test-fixtures/reducers/copy/{03 → 01 - copy/03}/merged.json +0 -0
  52. package/test-fixtures/reducers/copy/01 - copy/03/metadata.json +4 -0
  53. package/test-fixtures/reducers/copy/{03 → 01 - copy/03}/source.json +0 -0
  54. package/test-fixtures/reducers/copy/{05/base.json → 01 - copy/04/base.json } +1 -1
  55. package/test-fixtures/reducers/copy/{04/merged.json → 01 - copy/04/merged.json } +1 -1
  56. package/test-fixtures/reducers/copy/01 - copy/04/metadata.json +4 -0
  57. package/test-fixtures/reducers/copy/{04/source.json → 01 - copy/04/source.json } +1 -1
  58. package/test-fixtures/reducers/copy/{04/base.json → 01 - copy/05/base.json } +1 -1
  59. package/test-fixtures/reducers/copy/01 - copy/05/merged.json +77 -0
  60. package/test-fixtures/reducers/copy/01 - copy/05/metadata.json +4 -0
  61. package/test-fixtures/reducers/copy/01 - copy/05/source.json +62 -0
  62. package/test-fixtures/reducers/copy/01 - copy/06/base.json +24 -0
  63. package/test-fixtures/reducers/copy/01 - copy/06/merged.json +39 -0
  64. package/test-fixtures/reducers/copy/01 - copy/06/metadata.json +4 -0
  65. package/test-fixtures/reducers/copy/01 - copy/06/source.json +24 -0
  66. package/test-fixtures/reducers/copy/01 - copy/07/base.json +39 -0
  67. package/test-fixtures/reducers/copy/01 - copy/07/merged.json +39 -0
  68. package/test-fixtures/reducers/copy/01 - copy/07/metadata.json +5 -0
  69. package/test-fixtures/reducers/copy/01 - copy/07/source.json +24 -0
  70. package/test-fixtures/reducers/copy/01 - copy/08/base.json +28 -0
  71. package/test-fixtures/reducers/copy/01 - copy/08/merged.json +28 -0
  72. package/test-fixtures/reducers/copy/01 - copy/08/metadata.json +4 -0
  73. package/test-fixtures/reducers/copy/01 - copy/08/source.json +24 -0
  74. package/test-fixtures/reducers/copy/02 - doNotCopyIfFieldPresent/01/base.json +17 -0
  75. package/test-fixtures/reducers/copy/02 - doNotCopyIfFieldPresent/01/merged.json +20 -0
  76. package/test-fixtures/reducers/copy/02 - doNotCopyIfFieldPresent/01/metadata.json +6 -0
  77. package/test-fixtures/reducers/copy/02 - doNotCopyIfFieldPresent/01/source.json +20 -0
  78. package/test-fixtures/reducers/copy/02 - doNotCopyIfFieldPresent/02/base.json +9 -0
  79. package/test-fixtures/reducers/copy/02 - doNotCopyIfFieldPresent/02/merged.json +20 -0
  80. package/test-fixtures/reducers/copy/02 - doNotCopyIfFieldPresent/02/metadata.json +6 -0
  81. package/test-fixtures/reducers/copy/02 - doNotCopyIfFieldPresent/02/source.json +20 -0
  82. package/test-fixtures/reducers/copy/03 - compareTagsOnly/01/base.json +24 -0
  83. package/test-fixtures/reducers/copy/03 - compareTagsOnly/01/merged.json +24 -0
  84. package/test-fixtures/reducers/copy/03 - compareTagsOnly/01/metadata.json +5 -0
  85. package/test-fixtures/reducers/copy/03 - compareTagsOnly/01/source.json +24 -0
  86. package/test-fixtures/reducers/copy/03 - compareTagsOnly/02/base.json +24 -0
  87. package/test-fixtures/reducers/copy/03 - compareTagsOnly/02/merged.json +100 -0
  88. package/test-fixtures/reducers/copy/03 - compareTagsOnly/02/metadata.json +5 -0
  89. package/test-fixtures/reducers/copy/03 - compareTagsOnly/02/source.json +100 -0
  90. package/test-fixtures/reducers/copy/04 - compareWithoutIndicators/01/base.json +24 -0
  91. package/test-fixtures/reducers/copy/04 - compareWithoutIndicators/01/merged.json +24 -0
  92. package/test-fixtures/reducers/copy/04 - compareWithoutIndicators/01/metadata.json +5 -0
  93. package/test-fixtures/reducers/copy/04 - compareWithoutIndicators/01/source.json +24 -0
  94. package/test-fixtures/reducers/copy/04 - compareWithoutIndicators/02/base.json +24 -0
  95. package/test-fixtures/reducers/copy/04 - compareWithoutIndicators/02/merged.json +39 -0
  96. package/test-fixtures/reducers/copy/04 - compareWithoutIndicators/02/metadata.json +5 -0
  97. package/test-fixtures/reducers/copy/04 - compareWithoutIndicators/02/source.json +24 -0
  98. package/test-fixtures/reducers/copy/04 - compareWithoutIndicators/03/metadata.json +6 -0
  99. package/test-fixtures/reducers/copy/04 - compareWithoutIndicators/04/base.json +20 -0
  100. package/test-fixtures/reducers/copy/04 - compareWithoutIndicators/04/merged.json +31 -0
  101. package/test-fixtures/reducers/copy/04 - compareWithoutIndicators/04/metadata.json +5 -0
  102. package/test-fixtures/reducers/copy/04 - compareWithoutIndicators/04/source.json +20 -0
  103. package/test-fixtures/reducers/copy/05 - copyUnless/01/base.json +9 -0
  104. package/test-fixtures/reducers/copy/05 - copyUnless/01/merged.json +24 -0
  105. package/test-fixtures/reducers/copy/05 - copyUnless/01/metadata.json +5 -0
  106. package/test-fixtures/reducers/copy/05 - copyUnless/01/source.json +47 -0
  107. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/01/base.json +24 -0
  108. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/01/merged.json +39 -0
  109. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/01/metadata.json +5 -0
  110. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/01/source.json +24 -0
  111. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/02/base.json +24 -0
  112. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/02/merged.json +24 -0
  113. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/02/metadata.json +5 -0
  114. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/02/source.json +24 -0
  115. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/03/base.json +28 -0
  116. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/03/merged.json +43 -0
  117. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/03/metadata.json +5 -0
  118. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/03/source.json +24 -0
  119. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/04/base.json +28 -0
  120. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/04/merged.json +28 -0
  121. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/04/metadata.json +5 -0
  122. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/04/source.json +24 -0
  123. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/05/base.json +20 -0
  124. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/05/merged.json +35 -0
  125. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/05/metadata.json +5 -0
  126. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/05/source.json +24 -0
  127. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/06/base.json +20 -0
  128. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/06/merged.json +35 -0
  129. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/06/metadata.json +5 -0
  130. package/test-fixtures/reducers/copy/06 - subfieldsMustBeIdentical/06/source.json +24 -0
  131. package/test-fixtures/reducers/copy/07 - excludeSubfields/01/base.json +39 -0
  132. package/test-fixtures/reducers/copy/07 - excludeSubfields/01/merged.json +39 -0
  133. package/test-fixtures/reducers/copy/07 - excludeSubfields/01/metadata.json +8 -0
  134. package/test-fixtures/reducers/copy/{05/source.json → 07 - excludeSubfields/01/source.json } +1 -1
  135. package/test-fixtures/reducers/copy/07 - excludeSubfields/02/base.json +39 -0
  136. package/test-fixtures/reducers/copy/{05/merged.json → 07 - excludeSubfields/02/merged.json } +5 -5
  137. package/test-fixtures/reducers/copy/07 - excludeSubfields/02/metadata.json +5 -0
  138. package/test-fixtures/reducers/copy/07 - excludeSubfields/02/source.json +43 -0
  139. package/test-fixtures/reducers/copy/08 - dropSubfields/01/base.json +35 -0
  140. package/test-fixtures/reducers/copy/08 - dropSubfields/01/merged.json +54 -0
  141. package/test-fixtures/reducers/copy/08 - dropSubfields/01/metadata.json +5 -0
  142. package/test-fixtures/reducers/copy/08 - dropSubfields/01/source.json +43 -0
  143. package/test-fixtures/reducers/copy/08 - dropSubfields/02/base.json +43 -0
  144. package/test-fixtures/reducers/copy/08 - dropSubfields/02/merged.json +58 -0
  145. package/test-fixtures/reducers/copy/08 - dropSubfields/02/metadata.json +5 -0
  146. package/test-fixtures/reducers/copy/08 - dropSubfields/02/source.json +32 -0
  147. package/test-fixtures/reducers/copy/08 - dropSubfields/03/base.json +43 -0
  148. package/test-fixtures/reducers/copy/08 - dropSubfields/03/merged.json +58 -0
  149. package/test-fixtures/reducers/copy/08 - dropSubfields/03/metadata.json +5 -0
  150. package/test-fixtures/reducers/copy/08 - dropSubfields/03/source.json +32 -0
  151. package/test-fixtures/reducers/copy/08 - dropSubfields/04/base.json +43 -0
  152. package/test-fixtures/reducers/copy/08 - dropSubfields/04/merged.json +43 -0
  153. package/test-fixtures/reducers/copy/08 - dropSubfields/04/metadata.json +5 -0
  154. package/test-fixtures/reducers/copy/08 - dropSubfields/04/source.json +32 -0
  155. package/test-fixtures/reducers/copy/09 - swapSubfieldCode/01/base.json +9 -0
  156. package/test-fixtures/reducers/copy/09 - swapSubfieldCode/01/merged.json +20 -0
  157. package/test-fixtures/reducers/copy/09 - swapSubfieldCode/01/metadata.json +6 -0
  158. package/test-fixtures/reducers/copy/09 - swapSubfieldCode/01/source.json +20 -0
  159. package/test-fixtures/reducers/copy/09 - swapSubfieldCode/02/base.json +9 -0
  160. package/test-fixtures/reducers/copy/09 - swapSubfieldCode/02/merged.json +20 -0
  161. package/test-fixtures/reducers/copy/09 - swapSubfieldCode/02/metadata.json +6 -0
  162. package/test-fixtures/reducers/copy/09 - swapSubfieldCode/02/source.json +20 -0
  163. package/test-fixtures/reducers/copy/09 - swapSubfieldCode/03/base.json +9 -0
  164. package/test-fixtures/reducers/copy/09 - swapSubfieldCode/03/merged.json +31 -0
  165. package/test-fixtures/reducers/copy/09 - swapSubfieldCode/03/metadata.json +6 -0
  166. package/test-fixtures/reducers/copy/09 - swapSubfieldCode/03/source.json +31 -0
  167. package/test-fixtures/reducers/copy/09 - swapSubfieldCode/04/base.json +9 -0
  168. package/test-fixtures/reducers/copy/09 - swapSubfieldCode/04/merged.json +42 -0
  169. package/test-fixtures/reducers/copy/09 - swapSubfieldCode/04/metadata.json +6 -0
  170. package/test-fixtures/reducers/copy/09 - swapSubfieldCode/04/source.json +42 -0
  171. package/test-fixtures/reducers/copy/10 - swapTag/01/base.json +17 -0
  172. package/test-fixtures/reducers/copy/10 - swapTag/01/merged.json +28 -0
  173. package/test-fixtures/reducers/copy/10 - swapTag/01/metadata.json +6 -0
  174. package/test-fixtures/reducers/copy/10 - swapTag/01/source.json +20 -0
  175. package/test-fixtures/reducers/copy/11 - compareWithoutTag/01/base.json +28 -0
  176. package/test-fixtures/reducers/copy/11 - compareWithoutTag/01/merged.json +28 -0
  177. package/test-fixtures/reducers/copy/11 - compareWithoutTag/01/metadata.json +6 -0
  178. package/test-fixtures/reducers/copy/11 - compareWithoutTag/01/source.json +20 -0
  179. package/test-fixtures/reducers/copy/11 - compareWithoutTag/02/base.json +28 -0
  180. package/test-fixtures/reducers/copy/11 - compareWithoutTag/02/merged.json +39 -0
  181. package/test-fixtures/reducers/copy/11 - compareWithoutTag/02/metadata.json +6 -0
  182. package/test-fixtures/reducers/copy/11 - compareWithoutTag/02/source.json +31 -0
  183. package/test-fixtures/reducers/copy/11 - compareWithoutTag/03/base.json +28 -0
  184. package/test-fixtures/reducers/copy/11 - compareWithoutTag/03/merged.json +28 -0
  185. package/test-fixtures/reducers/copy/11 - compareWithoutTag/03/metadata.json +7 -0
  186. package/test-fixtures/reducers/copy/11 - compareWithoutTag/03/source.json +20 -0
  187. package/test-fixtures/reducers/copy/11 - compareWithoutTag/04/base.json +17 -0
  188. package/test-fixtures/reducers/copy/11 - compareWithoutTag/04/merged.json +28 -0
  189. package/test-fixtures/reducers/copy/11 - compareWithoutTag/04/metadata.json +7 -0
  190. package/test-fixtures/reducers/copy/11 - compareWithoutTag/04/source.json +31 -0
  191. package/test-fixtures/reducers/copy/11 - compareWithoutTag/05/base.json +28 -0
  192. package/test-fixtures/reducers/copy/11 - compareWithoutTag/05/merged.json +28 -0
  193. package/test-fixtures/reducers/copy/11 - compareWithoutTag/05/metadata.json +7 -0
  194. package/test-fixtures/reducers/copy/11 - compareWithoutTag/05/source.json +28 -0
  195. package/test-fixtures/reducers/metadata.json +4 -0
  196. package/test-fixtures/reducers/select/01/metadata.json +5 -0
  197. package/test-fixtures/reducers/select/02/metadata.json +4 -0
  198. package/test-fixtures/reducers/select/03/metadata.json +4 -0
  199. package/test-fixtures/reducers/select/04/metadata.json +5 -0
  200. package/test-fixtures/reducers/select/05/metadata.json +4 -0
  201. package/test-fixtures/reducers/select/06/base.json +4 -0
  202. package/test-fixtures/reducers/select/06/merged.json +4 -0
  203. package/test-fixtures/reducers/select/06/metadata.json +4 -0
  204. package/test-fixtures/reducers/select/06/source.json +4 -0
  205. package/test-fixtures/reducers/select/07/metadata.json +5 -0
  206. package/test-fixtures/reducers/select/08/metadata.json +4 -0
  207. package/test-fixtures/reducers/select/09/metadata.json +4 -0
  208. package/test-fixtures/reducers/select/10/metadata.json +5 -0
  209. package/test-fixtures/reducers/select/11/metadata.json +4 -0
  210. package/test-fixtures/reducers/select/12/metadata.json +5 -0
  211. package/test-fixtures/reducers/select/13/metadata.json +4 -0
  212. package/test-fixtures/reducers/select/14/base.json +24 -0
  213. package/test-fixtures/reducers/select/14/merged.json +24 -0
  214. package/test-fixtures/reducers/select/14/metadata.json +4 -0
  215. package/test-fixtures/reducers/select/14/source.json +24 -0
  216. package/.drone.yml +0 -92
  217. package/.nyc_output/7ecda3cd-9f84-4416-a466-fa1e5889c6a3.json +0 -1
  218. package/.nyc_output/processinfo/7ecda3cd-9f84-4416-a466-fa1e5889c6a3.json +0 -1
  219. package/.nyc_output/processinfo/index.json +0 -1
  220. package/LICENSE.txt +0 -165
  221. package/coverage/base.css +0 -224
  222. package/coverage/block-navigation.js +0 -79
  223. package/coverage/copy.js.html +0 -344
  224. package/coverage/favicon.png +0 -0
  225. package/coverage/index.html +0 -126
  226. package/coverage/lcov-report/base.css +0 -224
  227. package/coverage/lcov-report/block-navigation.js +0 -79
  228. package/coverage/lcov-report/copy.js.html +0 -344
  229. package/coverage/lcov-report/favicon.png +0 -0
  230. package/coverage/lcov-report/index.html +0 -126
  231. package/coverage/lcov-report/prettify.css +0 -1
  232. package/coverage/lcov-report/prettify.js +0 -2
  233. package/coverage/lcov-report/select.js.html +0 -431
  234. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  235. package/coverage/lcov-report/sorter.js +0 -170
  236. package/coverage/lcov.info +0 -195
  237. package/coverage/prettify.css +0 -1
  238. package/coverage/prettify.js +0 -2
  239. package/coverage/select.js.html +0 -431
  240. package/coverage/sort-arrow-sprite.png +0 -0
  241. package/coverage/sorter.js +0 -170
  242. package/test-fixtures/reducers/copy/01/pattern.txt +0 -1
  243. package/test-fixtures/reducers/copy/02/pattern.txt +0 -1
  244. package/test-fixtures/reducers/copy/03/pattern.txt +0 -1
  245. package/test-fixtures/reducers/copy/04/pattern.txt +0 -1
  246. package/test-fixtures/reducers/copy/05/pattern.txt +0 -1
  247. package/test-fixtures/reducers/select/01/expected-error.txt +0 -1
  248. package/test-fixtures/reducers/select/01/pattern.txt +0 -1
  249. package/test-fixtures/reducers/select/02/pattern.txt +0 -1
  250. package/test-fixtures/reducers/select/03/pattern.txt +0 -1
  251. package/test-fixtures/reducers/select/04/pattern.txt +0 -1
  252. package/test-fixtures/reducers/select/05/pattern.txt +0 -1
  253. package/test-fixtures/reducers/select/06/pattern.txt +0 -1
  254. package/test-fixtures/reducers/select/07/equalityFunction.txt +0 -1
  255. package/test-fixtures/reducers/select/07/pattern.txt +0 -1
  256. package/test-fixtures/reducers/select/08/pattern.txt +0 -1
  257. package/test-fixtures/reducers/select/09/pattern.txt +0 -1
  258. package/test-fixtures/reducers/select/10/equalityFunction.txt +0 -1
  259. package/test-fixtures/reducers/select/10/pattern.txt +0 -1
  260. package/test-fixtures/reducers/select/11/pattern.txt +0 -1
  261. package/test-fixtures/reducers/select/12/equalityFunction.txt +0 -1
  262. package/test-fixtures/reducers/select/12/pattern.txt +0 -1
  263. package/test-fixtures/reducers/select/13/pattern.txt +0 -1
package/package.json CHANGED
@@ -13,46 +13,50 @@
13
13
  "type": "git",
14
14
  "url": "git@github.com:natlibfi/marc-record-merge-js.git"
15
15
  },
16
- "license": "LGPL-3.0+",
17
- "version": "6.0.0-beta.1",
16
+ "license": "MIT",
17
+ "version": "6.0.0-beta.11",
18
18
  "main": "./dist/index.js",
19
19
  "engines": {
20
- "node": ">=12"
20
+ "node": ">=14"
21
21
  },
22
+ "type": "commonjs",
22
23
  "scripts": {
24
+ "prepare": "npm run build",
23
25
  "prepublishOnly": "npm run build:transpile",
24
- "check-deps": "npm-check;exit 0",
25
26
  "lint": "eslint ./src",
26
27
  "lint:dev": "eslint ./src --fix",
27
- "test:base": "cross-env NODE_ENV=test nyc mocha --require @babel/register",
28
- "test": "npm run lint && npm run test:base -- src/**/*.spec.js",
29
- "test:dev": "npm run lint:dev && npm run test:base -- src/**/*.spec.js && npm run coverage",
30
- "coverage": "nyc check-coverage --per-file",
28
+ "test:base": "cross-env NODE_ENV=test mocha --require @babel/register --reporter-option maxDiffSize=15000",
29
+ "test": "npm run lint && npm run test:base -- --recursive src",
30
+ "test:dev": "npm run lint:dev && npm run coverage",
31
+ "coverage": "npm run coverage:unit && npm run coverage:report",
32
+ "coverage:unit": "nyc --silent npm run test:base",
33
+ "coverage:report": "nyc report",
31
34
  "build:transpile": "babel src --copy-files --source-maps --delete-dir-on-start --out-dir=dist",
32
- "build": "npm run build:transpile && npm run check-deps",
33
- "watch:test": "cross-env DEBUG=1 NODE_ENV=test nodemon -w src -w test-fixtures --exec 'npm run test:dev'"
35
+ "build": "npm run build:transpile",
36
+ "dev:test": "cross-env NODE_ENV=test nodemon -w src -w test-fixtures --exec 'clear && npm run test:dev'",
37
+ "dev:test:debug": "cross-env DEBUG=@natlibfi/* NODE_ENV=test nodemon -w src -w test-fixtures --exec 'clear && npm run test:dev'"
34
38
  },
35
39
  "dependencies": {
36
- "@natlibfi/fixura": "^2.0.0",
37
- "@natlibfi/marc-record": "^6.0.0",
38
- "debug": "^4.1.1",
39
- "normalize-diacritics": "^2.11.1"
40
+ "@natlibfi/fixugen": "1.1.0",
41
+ "@natlibfi/fixura": "^2.2.5",
42
+ "@natlibfi/marc-record": "^7.2.2",
43
+ "debug": "^4.3.4",
44
+ "normalize-diacritics": "2.14.0"
40
45
  },
41
46
  "devDependencies": {
42
- "@babel/cli": "^7.10.1",
43
- "@babel/core": "^7.10.2",
44
- "@babel/preset-env": "^7.10.2",
45
- "@babel/register": "^7.10.1",
46
- "@natlibfi/eslint-config-melinda-backend": "^1.0.3",
47
- "babel-eslint": "^10.0.3",
48
- "babel-plugin-istanbul": "^6.0.0",
47
+ "@babel/cli": "^7.19.3",
48
+ "@babel/core": "^7.19.6",
49
+ "@babel/eslint-parser": "^7.19.1",
50
+ "@babel/preset-env": "^7.19.4",
51
+ "@babel/register": "^7.18.9",
52
+ "@natlibfi/eslint-config-melinda-backend": "^2.0.1",
53
+ "babel-plugin-istanbul": "^6.1.1",
49
54
  "babel-plugin-rewire": "^1.2.0",
50
- "chai": "^4.2.0",
51
- "cross-env": "^7.0.2",
52
- "eslint": "^7.1.0",
53
- "mocha": "^7.2.0",
54
- "nodemon": "^2.0.4",
55
- "npm-check": "^5.9.0",
55
+ "chai": "^4.3.6",
56
+ "cross-env": "^7.0.3",
57
+ "eslint": "^8.25.0",
58
+ "mocha": "^10.1.0",
59
+ "nodemon": "^2.0.20",
56
60
  "nyc": "^15.1.0"
57
61
  },
58
62
  "eslintConfig": {
@@ -65,9 +69,7 @@
65
69
  [
66
70
  "@babel/preset-env",
67
71
  {
68
- "targets": {
69
- "node": "12"
70
- }
72
+ "targets": "maintained node versions"
71
73
  }
72
74
  ]
73
75
  ],
@@ -86,8 +88,7 @@
86
88
  "*/**/*.spec.js"
87
89
  ],
88
90
  "reporter": [
89
- "lcov",
90
- "html"
91
+ "text"
91
92
  ],
92
93
  "require": [
93
94
  "@babel/register"
package/src/index.js CHANGED
@@ -1,36 +1,54 @@
1
- /**
2
- *
3
- * @licstart The following is the entire license notice for the JavaScript code in this file.
4
- *
5
- * Merge MARC records
6
- *
7
- * Copyright (C) 2015-2019 University Of Helsinki (The National Library Of Finland)
8
- *
9
- * This file is part of marc-record-merge-js
10
-
11
- * marc-record-merge-js program is free software: you can redistribute it and/or modify
12
- * it under the terms of the GNU Lesser General Public License as
13
- * published by the Free Software Foundation, either version 3 of the
14
- * License, or (at your option) any later version.
15
- *
16
- * marc-record-merge-js is distributed in the hope that it will be useful,
17
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
- * GNU Lesser General Public License for more details.
20
- *
21
- * You should have received a copy of the GNU Lesser General Public License
22
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
23
- *
24
- * @licend The above is the entire license notice
25
- * for the JavaScript code in this file.
26
- *
27
- */
28
-
29
- import * as Reducers from './reducers';
30
- import {MarcRecord} from '@natlibfi/marc-record';
1
+ import Reducers from './reducers';
2
+ import createDebugLogger from 'debug';
3
+
4
+ const debug = createDebugLogger('@natlibfi/melinda-marc-record-merge:index');
5
+ const debugData = debug.extend('data');
31
6
 
32
7
  export {Reducers};
8
+ // export default ({base, source, reducers}) => reducers.reduce((base, reducer) => reducer(base, source), base);
9
+
10
+ // NV: Modified the reducer loop so, that not only base, but also is carried back.
11
+ // However, we try to be backward-compatible: normally after the reducers, only base is returned.
12
+
33
13
  export default ({base, source, reducers}) => {
34
- const sourceRecord = MarcRecord.clone(source);
35
- return reducers.reduce((baseRecord, reducer) => reducer(baseRecord, sourceRecord), MarcRecord.clone(base));
14
+
15
+ const combo = {base, source};
16
+ const resultCombo = reducers.reduce((combo, reducer) => {
17
+ const returnCombo = singleRound(reducer, combo.base, combo.source);
18
+ //debugData(`returnCombo after current reducer: ${JSON.stringify(returnCombo)}`);
19
+ return returnCombo;
20
+ }, combo);
21
+
22
+ debugData(`ResultCombo after reducers: ${JSON.stringify(resultCombo)}`);
23
+
24
+ // Hack to make my melinda-marc-record-merge-reducers single tests that expect both
25
+ // base and source to return them both:
26
+ if (reducers.length === 1 && resultCombo.base && resultCombo.source) {
27
+ debug('Single reducer, returning resultCombo');
28
+ debugData(JSON.stringify(resultCombo));
29
+
30
+ return resultCombo;
31
+ }
32
+ // All other tests return just base... Backward (compability) it is!
33
+ debug('Multiple reducers, returning just base');
34
+ debugData(JSON.stringify(resultCombo.base));
35
+ return resultCombo.base;
36
+
37
+ function singleRound(reducer, base, source) {
38
+ //debug(`SINGLE ROUND INPUT (base, source)`);
39
+ //debugData(base);
40
+ //debugData(base);
41
+ const reducerResult = reducer(base, source);
42
+ //debug(`reducerResult:`);
43
+ //debugData(reducerResult);
44
+ if (reducerResult.base !== undefined && reducerResult.source !== undefined) {
45
+ debug('NEW STYLE REDUCER RESULT v2');
46
+ const combo = reducerResult;
47
+ //debugData(combo);
48
+ return combo;
49
+ }
50
+ debug('OLD SCHOOL REDUCER RESULT v2');
51
+ //debugData({base: reducerResult, source});
52
+ return {base: reducerResult, source};
53
+ }
36
54
  };
@@ -0,0 +1,45 @@
1
+ import merger, {Reducers} from './index';
2
+ import {inspect} from 'util';
3
+ import createDebugLogger from 'debug';
4
+ import {expect} from 'chai';
5
+ import {MarcRecord} from '@natlibfi/marc-record';
6
+ import {READERS} from '@natlibfi/fixura';
7
+ import generateTests from '@natlibfi/fixugen';
8
+
9
+ generateTests({
10
+ callback,
11
+ path: [__dirname, '..', 'test-fixtures', 'index'],
12
+ recurse: false,
13
+ useMetadataFile: true,
14
+ fixura: {
15
+ failWhenNotFound: false,
16
+ reader: READERS.JSON
17
+ }
18
+ });
19
+
20
+ function callback({getFixture, reducerConfigs = []}) {
21
+ const base = new MarcRecord(getFixture('base.json'), {subfieldValues: false});
22
+ const source = new MarcRecord(getFixture('source.json'), {subfieldValues: false});
23
+ const expectedRecord = getFixture('merged.json');
24
+
25
+ const debug = createDebugLogger('@natlibfi/melinda-marc-record-merge-reducers:index:test');
26
+ const debugData = debug.extend('data');
27
+
28
+ const testReducerConfigs = reducerConfigs;
29
+ const reducers = [...testReducerConfigs.map(conf => Reducers.copy(conf))];
30
+
31
+ debugData(`Reducers: ${inspect(reducers, {colors: true, maxArrayLength: 10, depth: 8})})}`);
32
+
33
+ const result = merger({base, source, reducers});
34
+
35
+ debug(`Merge result is: ${result.constructor.name}`);
36
+ debugData(`${JSON.stringify(result)}`);
37
+
38
+ // Use either result.base or a plain result as resultRecord
39
+ // It can also be a MarcRecord or a plain object
40
+ const resultRecord = result.base || result;
41
+ const resultRecordToRecord = new MarcRecord(resultRecord, {subfieldValues: false});
42
+ expect(resultRecordToRecord.toObject()).to.eql(expectedRecord);
43
+
44
+
45
+ }
@@ -1,88 +1,270 @@
1
- /**
2
- *
3
- * @licstart The following is the entire license notice for the JavaScript code in this file.
4
- *
5
- * Merge MARC records
6
- *
7
- * Copyright (C) 2015-2019 University Of Helsinki (The National Library Of Finland)
8
- *
9
- * This file is part of marc-record-merge-js
10
-
11
- * marc-record-merge-js program is free software: you can redistribute it and/or modify
12
- * it under the terms of the GNU Lesser General Public License as
13
- * published by the Free Software Foundation, either version 3 of the
14
- * License, or (at your option) any later version.
15
- *
16
- * marc-record-merge-js is distributed in the hope that it will be useful,
17
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
- * GNU Lesser General Public License for more details.
20
- *
21
- * You should have received a copy of the GNU Lesser General Public License
22
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
23
- *
24
- * @licend The above is the entire license notice
25
- * for the JavaScript code in this file.
26
- *
27
- */
28
- // Import createDebugLogger from 'debug';
29
-
30
- export default (pattern) => (base, source) => {
31
- // Const debug = createDebugLogger('@natlibfi/marc-record-merge');
32
- const baseFields = base.get(pattern);
33
- const sourceFields = source.get(pattern);
34
- return copyFields();
35
-
36
- function copyFields() {
37
- // Test 01: If base does not contain the field at all, it is copied from source to base
38
- if (baseFields.length === 0) {
39
- sourceFields.forEach(f => base.insertField(f));
40
- return base;
41
- }
42
- const filterMissing = function(sourceField) {
43
- // Test 02: Identical control fields are not copied
44
- if ('value' in sourceField) {
45
- return baseFields.some(isIdenticalControlField) === false;
46
- }
47
- // Test 04: Identical data fields in base and source, not copied
48
- // Test 05: Different data fields are copied from source to base
49
- if ('subfields' in sourceField) {
50
- return baseFields.some(isIdenticalDataField) === false;
51
- }
1
+ /* eslint-disable max-statements */
2
+ /* eslint-disable no-unused-vars */
52
3
 
53
- function normalizeControlField(field) {
54
- return field.value.toLowerCase().replace(/\s+/u, '');
55
- }
4
+ import {MarcRecord} from '@natlibfi/marc-record';
5
+ import createDebugLogger from 'debug';
56
6
 
57
- function isIdenticalControlField(baseField) {
58
- const normalizedBaseField = normalizeControlField(baseField);
59
- const normalizedSourceField = normalizeControlField(sourceField);
60
- return normalizedSourceField === normalizedBaseField;
61
- }
62
- function isIdenticalDataField(baseField) {
63
- if (sourceField.tag === baseField.tag &&
64
- sourceField.ind1 === baseField.ind1 &&
65
- sourceField.ind2 === baseField.ind2 &&
66
- sourceField.subfields.length === baseField.subfields.length) {
67
- return baseField.subfields.every(isIdenticalSubfield);
7
+ export default ({
8
+ tagPattern,
9
+ compareTagsOnly = false,
10
+ compareWithoutTag = false,
11
+ compareWithoutIndicators = false,
12
+ compareWithoutIndicator1 = false,
13
+ compareWithoutIndicator2 = false,
14
+ subfieldsMustBeIdentical = true,
15
+ excludeSubfields = [],
16
+ dropSubfields = [],
17
+ copyUnless = [],
18
+ baseValidators = {subfieldValues: false},
19
+ sourceValidators = {subfieldValues: false},
20
+ swapTag = [],
21
+ swapSubfieldCode = [],
22
+ doNotCopyIfFieldPresent = false
23
+ }) => (base, source) => {
24
+
25
+ const debug = createDebugLogger('@natlibfi/marc-record-merge:copy');
26
+ const debugData = debug.extend('data');
27
+ const debugOptions = createDebugLogger('@natlibfi/marc-record-merge:compare-options');
28
+ const debugCompare = createDebugLogger('@natlibfi/marc-record-merge:compare');
29
+
30
+ debugData(`base: ${JSON.stringify(base)}`);
31
+ debugData(`source: ${JSON.stringify(source)}`);
32
+
33
+ const {baseRecord, sourceRecord} = getRecordsFromParameters(base, source, baseValidators, sourceValidators);
34
+
35
+ function getRecordsFromParameters(base, source, baseValidators, sourceValidators) {
36
+ // records if we got an object ({base, source}) as a parameter
37
+ if (source === undefined && base.base !== undefined && base.source !== undefined) {
38
+ const baseRecord = new MarcRecord(base.base, baseValidators);
39
+ const sourceRecord = new MarcRecord(base.source, sourceValidators);
40
+ return {baseRecord, sourceRecord};
41
+ }
42
+ // records if we got an non-object (base, source) as a parameter
43
+ const baseRecord = new MarcRecord(base, baseValidators);
44
+ const sourceRecord = new MarcRecord(source, sourceValidators);
45
+ return {baseRecord, sourceRecord};
46
+ }
47
+
48
+ const ignoreInd1 = compareWithoutIndicators || compareWithoutIndicator1;
49
+ const ignoreInd2 = compareWithoutIndicators || compareWithoutIndicator2;
50
+
51
+ debugOptions(`Tag Pattern: ${tagPattern}`);
52
+ debugOptions(`Compare tags only: ${compareTagsOnly}`);
53
+ debugOptions(`Omit indicator 1 from comparison: ${ignoreInd1}`);
54
+ debugOptions(`Omit indicator 2 from comparison: ${ignoreInd2}`);
55
+ debugOptions(`Copy if identical: ${subfieldsMustBeIdentical}`);
56
+ debugOptions(`Exclude subfields: [${excludeSubfields}]`);
57
+ debugOptions(`Drop subfields [${dropSubfields}]`);
58
+ debugOptions(`Copy unless contains subfields: ${JSON.stringify(copyUnless)}`);
59
+
60
+ const baseFields = baseRecord.get(tagPattern);
61
+ const sourceFields = sourceRecord.get(tagPattern);
62
+ const doNotCopy = doNotCopyIfFieldPresent ? baseRecord.get(doNotCopyIfFieldPresent).length > 0 : false;
63
+
64
+ if (doNotCopy) {
65
+ return baseRecord.toObject();
66
+ }
67
+ debug(`FFS: ${compareWithoutIndicator1}, ${compareWithoutIndicators}, ${ignoreInd1}`);
68
+ debug(`Base fields: `, baseFields);
69
+ debug(`Source fields: `, sourceFields);
70
+
71
+ // Logic steps
72
+ const baseCompareFields = baseFields.map(baseField => createCompareField(baseField));
73
+ const compareResultFields = compareFields(sourceFields, baseCompareFields);
74
+ const droppedUnwantedSubfield = checkDropSubfields(compareResultFields);
75
+ const droppedUnwantedFields = checkCopyUnlessFields(droppedUnwantedSubfield);
76
+ const swappedSubfields = checkSwapSubfieldCodes(droppedUnwantedFields);
77
+ const swappedTags = checkSwapTag(swappedSubfields);
78
+ const uniqueFields = [...new Set(swappedTags.map(field => JSON.stringify(field)))].map(field => JSON.parse(field));
79
+ debug('Fields to be copied');
80
+ debug(JSON.stringify(uniqueFields));
81
+
82
+ // Add fields to base;
83
+ uniqueFields.forEach(field => baseRecord.insertField(field));
84
+ debugData(`baseRecord before return: ${JSON.stringify(baseRecord)}`);
85
+ //return baseRecord;
86
+ return baseRecord.toObject();
87
+
88
+ function compareFields(sourceFields, baseCompareFields, uniqFields = []) {
89
+ const [sourceField, ...rest] = sourceFields;
90
+ if (sourceField === undefined) {
91
+ return uniqFields;
92
+ }
93
+
94
+ if (baseCompareFields.length === 0) {
95
+ return compareFields(rest, baseCompareFields, [...uniqFields, sourceField]);
96
+ }
97
+
98
+ // Source and base are also compared for identicalness
99
+ // Non-identical fields are copied from source to base as duplicates
100
+ const sourceCompareField = createCompareField(sourceField);
101
+ const unique = checkCompareFields(baseCompareFields, sourceCompareField);
102
+
103
+ debugCompare(`${JSON.stringify(sourceField)} ${unique ? 'is UNIQUE' : 'not UNIQUE'}`);
104
+
105
+ if (unique) {
106
+ return compareFields(rest, baseCompareFields, [...uniqFields, sourceField]);
107
+ }
108
+
109
+ return compareFields(rest, baseCompareFields, uniqFields);
110
+
111
+ function checkCompareFields(baseCompareFields, sourceCompareField) {
112
+ let unique = true; // eslint-disable-line functional/no-let
113
+
114
+ baseCompareFields.forEach(baseCompareField => {
115
+ debugCompare(`Comparing ${JSON.stringify(sourceCompareField)} to ${JSON.stringify(baseCompareField)}}`);
116
+
117
+ if (sourceCompareField.value !== baseCompareField.value) {
118
+ debugCompare(`Value is different ${sourceCompareField.value} !== ${baseCompareField.value}`);
119
+ return;
68
120
  }
69
- function normalizeSubfield(subfield) {
70
- return subfield.value.toLowerCase().replace(/\s+/u, '');
121
+
122
+ if (sourceCompareField.ind1 !== baseCompareField.ind1) {
123
+ debugCompare(`Ind1 is different ${sourceCompareField.ind1} !== ${baseCompareField.ind1}`);
124
+ return;
71
125
  }
72
- function isIdenticalSubfield(baseSub) {
73
- const normBaseSub = normalizeSubfield(baseSub);
74
- return sourceField.subfields.some(sourceSub => {
75
- const normSourceSub = normalizeSubfield(sourceSub);
76
- return normSourceSub === normBaseSub;
77
- });
126
+
127
+ if (sourceCompareField.ind2 !== baseCompareField.ind2) {
128
+ debugCompare(`Ind2 is different ${sourceCompareField.ind2} !== ${baseCompareField.ind2}`);
129
+ return;
78
130
  }
131
+
132
+ if ('subfields' in sourceCompareField) {
133
+ const allFound = checkSubfields(sourceCompareField.subfields, baseCompareField.subfields);
134
+ debugCompare(`Subfields are different ${!allFound}`);
135
+ if (!allFound) {
136
+ return;
137
+ }
138
+
139
+ unique = false;
140
+ return;
141
+ }
142
+
143
+ unique = false;
144
+ return;
145
+ });
146
+
147
+ return unique;
148
+ }
149
+
150
+ function checkSubfields(sourceSubfields, baseSubfields) {
151
+ const foundSubs = sourceSubfields.filter(sSub => baseSubfields.some(bSub => sSub.code === bSub.code && sSub.value === bSub.value));
152
+
153
+ if (subfieldsMustBeIdentical) {
154
+ return foundSubs.length === sourceSubfields.length && foundSubs.length === baseSubfields.length;
79
155
  }
80
- };
81
- // Search for fields missing from base
82
- const missingFields = sourceFields.filter(filterMissing);
83
- // Test 03: Add missing control field to base
84
- // Test 05: Add missing data field to base
85
- missingFields.forEach(f => base.insertField(f));
86
- return base; // This is returned by copyFields
156
+
157
+ return foundSubs.length === sourceSubfields.length;
158
+ }
159
+ }
160
+
161
+ // compare objects have only fields that matter in comparison
162
+ function createCompareField(field) {
163
+ if (compareTagsOnly) {
164
+ return {tag: field.tag};
165
+ }
166
+
167
+ if ('value' in field) {
168
+ return {tag: field.tag, value: field.value};
169
+ }
170
+
171
+ const [filteredField] = checkDropSubfields([field]);
172
+ const [foundRule] = swapTag.filter(rule => new RegExp(rule.from, 'u').test(field.tag));
173
+ const replacementTag = foundRule ? foundRule.to : undefined;
174
+
175
+ const params = [
176
+ {name: 'tag', value: compareWithoutTag ? replacementTag : field.tag},
177
+ {name: 'ind1', value: ignoreInd1 ? undefined : field.ind1},
178
+ {name: 'ind2', value: ignoreInd2 ? undefined : field.ind2},
179
+ {name: 'subfields', value: createCompareSubfields(filteredField.subfields)}
180
+ ].map(param => [param.name, param.value]);
181
+
182
+ return Object.fromEntries(params);
183
+
184
+ function createCompareSubfields(subfields) {
185
+ const nonExcludedSubfields = subfields.filter(sub => !excludeSubfields.some(code => code === sub.code));
186
+ const normalizedSubfields = nonExcludedSubfields.map(sub => ({code: sub.code, value: normalizeSubfieldValue(sub.value)}));
187
+
188
+ return normalizedSubfields;
189
+
190
+ function normalizeSubfieldValue(value) {
191
+ return value.toLowerCase().replace(/\s+/ug, '');
192
+ }
193
+ }
194
+ }
195
+
196
+ function checkSwapTag(fields) {
197
+ if (swapTag.length > 0) {
198
+ return fields.map(field => ({...field, tag: swapTagsFunc(field.tag)}));
199
+ }
200
+
201
+ return fields;
202
+
203
+ function swapTagsFunc(tag) {
204
+ const [foundRule] = swapTag.filter(rule => new RegExp(rule.from, 'u').test(tag));
205
+
206
+ if (foundRule === undefined) {
207
+ return tag;
208
+ }
209
+
210
+ return foundRule.to;
211
+ }
212
+ }
213
+
214
+ function checkSwapSubfieldCodes(fields) {
215
+ if (swapSubfieldCode.length > 0) {
216
+ return fields.map(field => ({...field, subfields: swapSubfieldCodesFunc(field.subfields)}));
217
+ }
218
+
219
+ return fields;
220
+
221
+ function swapSubfieldCodesFunc(subfields) {
222
+ return subfields.map(sub => {
223
+ const [foundRule] = swapSubfieldCode.filter(rule => rule.from === sub.code);
224
+
225
+ if (foundRule === undefined) {
226
+ return sub;
227
+ }
228
+
229
+ return {code: foundRule.to, value: sub.value};
230
+ });
231
+ }
232
+ }
233
+
234
+ function checkDropSubfields(fields) {
235
+ if (dropSubfields.length > 0) {
236
+ return fields.map(field => ({...field, subfields: dropSubfieldsFunc(field.subfields)}))
237
+ .filter(field => field.subfields.length > 0);
238
+ }
239
+
240
+ return fields;
241
+
242
+ function dropSubfieldsFunc(subfields) {
243
+ return subfields.filter(sub => { // eslint-disable-line
244
+ return !dropSubfields.some(({code, value = false, condition = false}) => {
245
+ if (code !== sub.code) {
246
+ return false;
247
+ }
248
+
249
+ if (!condition && value) {
250
+ return value === sub.value;
251
+ }
252
+
253
+ if (condition === 'unless' && value) {
254
+ return !new RegExp(value, 'u').test(sub.value);
255
+ }
256
+
257
+ return true;
258
+ });
259
+ });
260
+ }
261
+ }
262
+
263
+ function checkCopyUnlessFields(fields) {
264
+ if (copyUnless.length > 0) {
265
+ return fields.filter(({subfields}) => copyUnless.some(filter => !subfields.some(sub => sub.code === filter.code && new RegExp(filter.value, 'u').test(sub.value))));
266
+ }
267
+
268
+ return fields;
87
269
  }
88
270
  };