@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
package/package.json CHANGED
@@ -13,44 +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.2",
16
+ "license": "MIT",
17
+ "version": "6.0.0-beta.6",
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
26
  "lint": "eslint ./src",
25
27
  "lint:dev": "eslint ./src --fix",
26
- "test:base": "cross-env NODE_ENV=test nyc mocha --require @babel/register",
27
- "test": "npm run lint && npm run test:base -- src/**/*.spec.js",
28
- "test:dev": "npm run lint:dev && npm run test:base -- src/**/*.spec.js && npm run coverage",
29
- "coverage": "nyc check-coverage --per-file",
28
+ "test:base": "cross-env NODE_ENV=test mocha --require @babel/register --reporter-option maxDiffSize=15000 src/reducers/*.spec.js",
29
+ "test": "npm run lint && npm run test:base",
30
+ "test:dev": "npm run lint:dev && npm run coverage",
31
+ "coverage": "npm run coverage:unit && npm run coverage:report",
32
+ "coverage:unit": "nyc --silent npm run test:base",
33
+ "coverage:report": "nyc report",
30
34
  "build:transpile": "babel src --copy-files --source-maps --delete-dir-on-start --out-dir=dist",
31
35
  "build": "npm run build:transpile",
32
- "watch:test": "cross-env DEBUG=1 NODE_ENV=test nodemon -w src -w test-fixtures --exec 'npm run test:dev'"
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'"
33
38
  },
34
39
  "dependencies": {
35
- "@natlibfi/fixura": "^2.1.3",
36
- "@natlibfi/marc-record": "^6.1.1",
37
- "debug": "^4.3.1",
38
- "normalize-diacritics": "^2.13.2"
40
+ "@natlibfi/fixugen": "1.1.0",
41
+ "@natlibfi/fixura": "^2.2.1",
42
+ "@natlibfi/marc-record": "^7.1.0-alpha.2",
43
+ "debug": "^4.3.4",
44
+ "normalize-diacritics": "2.14.0"
39
45
  },
40
46
  "devDependencies": {
41
- "@babel/cli": "^7.14.5",
42
- "@babel/core": "^7.14.6",
43
- "@babel/eslint-parser": "^7.14.5",
44
- "@babel/preset-env": "^7.14.5",
45
- "@babel/register": "^7.14.5",
46
- "@natlibfi/eslint-config-melinda-backend": "^1.0.6",
47
- "babel-plugin-istanbul": "^6.0.0",
47
+ "@babel/cli": "^7.17.10",
48
+ "@babel/core": "^7.18.0",
49
+ "@babel/eslint-parser": "^7.17.0",
50
+ "@babel/preset-env": "^7.18.0",
51
+ "@babel/register": "^7.17.7",
52
+ "@natlibfi/eslint-config-melinda-backend": "^2.0.0",
53
+ "babel-plugin-istanbul": "^6.1.1",
48
54
  "babel-plugin-rewire": "^1.2.0",
49
55
  "chai": "^4.3.4",
50
56
  "cross-env": "^7.0.3",
51
- "eslint": "^7.28.0",
52
- "mocha": "^9.0.0",
53
- "nodemon": "^2.0.7",
57
+ "eslint": "^8.16.0",
58
+ "mocha": "^10.0.0",
59
+ "nodemon": "^2.0.16",
54
60
  "nyc": "^15.1.0"
55
61
  },
56
62
  "eslintConfig": {
@@ -63,9 +69,7 @@
63
69
  [
64
70
  "@babel/preset-env",
65
71
  {
66
- "targets": {
67
- "node": "12"
68
- }
72
+ "targets": "maintained node versions"
69
73
  }
70
74
  ]
71
75
  ],
@@ -84,8 +88,7 @@
84
88
  "*/**/*.spec.js"
85
89
  ],
86
90
  "reporter": [
87
- "lcov",
88
- "html"
91
+ "text"
89
92
  ],
90
93
  "require": [
91
94
  "@babel/register"
package/src/index.js CHANGED
@@ -1,36 +1,4 @@
1
- /**
2
- *
3
- * @licstart The following is the entire license notice for the JavaScript code in this file.
4
- *
5
- * Merge MARC records
6
- *
7
- * Copyright (C) 2015-2019 University Of Helsinki (The National Library Of Finland)
8
- *
9
- * This file is part of marc-record-merge-js
10
-
11
- * marc-record-merge-js program is free software: you can redistribute it and/or modify
12
- * it under the terms of the GNU Lesser General Public License as
13
- * published by the Free Software Foundation, either version 3 of the
14
- * License, or (at your option) any later version.
15
- *
16
- * marc-record-merge-js is distributed in the hope that it will be useful,
17
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
- * GNU Lesser General Public License for more details.
20
- *
21
- * You should have received a copy of the GNU Lesser General Public License
22
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
23
- *
24
- * @licend The above is the entire license notice
25
- * for the JavaScript code in this file.
26
- *
27
- */
28
-
29
- import {MarcRecord} from '@natlibfi/marc-record';
30
1
  import Reducers from './reducers';
31
2
 
32
3
  export {Reducers};
33
- export default ({base, source, reducers, baseValidators = {}, sourceValidators = {}}) => {
34
- const sourceRecord = MarcRecord.clone(source, sourceValidators);
35
- return reducers.reduce((baseRecord, reducer) => reducer(baseRecord, sourceRecord), MarcRecord.clone(base, baseValidators));
36
- };
4
+ export default ({base, source, reducers}) => reducers.reduce((base, reducer) => reducer(base, source), base);
@@ -1,140 +1,331 @@
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
- /**
30
- * Test 01: If base does not contain the field at all, it is copied from source to base
31
- * Test 02: Identical control fields are not copied
32
- * Test 03: Add missing control field to base
33
- * Test 04: Identical data fields in base and source, not copied
34
- * Test 05: Different data fields are copied from source to base (multiple fields)
35
- * Test 06: compareTagsOnly: Field is copied from source only if it is missing in base, a different instance is not copied
36
- * Test 07: excludeSubfields: Ignore excluded subfields in comparing identicalness
37
- * Test 08: dropSubfields: Drop subfields from source before copying
38
- * Test 09: compareTagsOnly for repeatable fields, 2x each 260/264
39
- * */
1
+ /* eslint-disable max-statements */
2
+ /* eslint-disable no-unused-vars */
3
+
4
+ import {MarcRecord} from '@natlibfi/marc-record';
40
5
  import createDebugLogger from 'debug';
41
6
 
42
- export default ({tagPattern, compareTagsOnly = false, excludeSubfields = [], dropSubfields = []}) => (base, source) => {
7
+ export default ({
8
+ tagPattern,
9
+ compareTagsOnly = false,
10
+ compareWithoutIndicators = false,
11
+ subfieldsMustBeIdentical = true,
12
+ excludeSubfields = [],
13
+ dropSubfields = [],
14
+ copyUnless = [],
15
+ baseValidators = {subfieldValues: false},
16
+ sourceValidators = {subfieldValues: false},
17
+ swapTag = [],
18
+ swapSubfieldCode = [],
19
+ doNotCopyIfFieldPresent = false
20
+ }) => (base, source) => {
21
+ const baseRecord = new MarcRecord(base, baseValidators);
22
+ const sourceRecord = new MarcRecord(source, sourceValidators);
23
+
43
24
  const debug = createDebugLogger('@natlibfi/marc-record-merge');
44
- const baseFields = base.get(tagPattern);
45
- // Check whether there are subfields to drop from source before copying
46
- const sourceFields = checkDropSubfields(source.get(tagPattern));
47
- return copyFields();
48
-
49
- function copyFields() {
50
- const sourceTags = sourceFields.map(field => field.tag);
51
- sourceTags.forEach(tag => debug(`Comparing field ${tag}`));
52
-
53
- // If compareTagsOnly = true, only this part is run
54
- // The field is copied from source only if it is missing completely from base
55
- if (baseFields.length === 0) {
56
- sourceTags.forEach(tag => debug(`Missing field ${tag} copied from source to base`));
57
- sourceFields.forEach(f => base.insertField(f));
58
- return base;
25
+ const debugOptions = createDebugLogger('@natlibfi/marc-record-merge:compare-options');
26
+ const debugCompare = createDebugLogger('@natlibfi/marc-record-merge:compare');
27
+ debugOptions(`Tag Pattern: ${tagPattern}`);
28
+ debugOptions(`Compare tags only: ${compareTagsOnly}`);
29
+ debugOptions(`Compare without indicators ${compareWithoutIndicators}`);
30
+ debugOptions(`Copy if identical: ${subfieldsMustBeIdentical}`);
31
+ debugOptions(`Exclude subfields: [${excludeSubfields}]`);
32
+ debugOptions(`Drop subfields [${dropSubfields}]`);
33
+ debugOptions(`Copy unless contains subfields: ${JSON.stringify(copyUnless)}`);
34
+
35
+ const baseFields = baseRecord.get(tagPattern);
36
+ const sourceFields = sourceRecord.get(tagPattern);
37
+ const doNotCopy = doNotCopyIfFieldPresent ? baseRecord.get(doNotCopyIfFieldPresent).length > 0 : false;
38
+
39
+ if (doNotCopy) {
40
+ return baseRecord.toObject();
41
+ }
42
+
43
+ debug(`Base fields: `, baseFields);
44
+ debug(`Source fields: `, sourceFields);
45
+
46
+ const baseCompareFields = baseFields.map(baseField => createCompareField(baseField));
47
+ const compareResultFields = compareFields(sourceFields, baseCompareFields);
48
+ const droppedUnwantedSubfield = checkDropSubfields(compareResultFields);
49
+ const droppedUnwantedFields = checkCopyUnlessFields(droppedUnwantedSubfield);
50
+ const swappedSubfields = checkSwapSubfieldCodes(droppedUnwantedFields);
51
+ const swappedTags = checkSwapTag(swappedSubfields);
52
+ debug('Fields to be copied');
53
+ debug(JSON.stringify(swappedTags));
54
+
55
+ // Add fields to base;
56
+ swappedTags.forEach(field => baseRecord.insertField(field));
57
+ return baseRecord.toObject();
58
+ //return copyFields(baseFields, sourceFields);
59
+
60
+ function compareFields(sourceFields, baseCompareFields, uniqFields = []) {
61
+ const [sourceField, ...rest] = sourceFields;
62
+ if (sourceField === undefined) {
63
+ return uniqFields;
64
+ }
65
+
66
+ if (baseCompareFields.length === 0) {
67
+ return compareFields(rest, baseCompareFields, [...uniqFields, sourceField]);
59
68
  }
60
69
 
61
- // If compareTagsOnly = false (default)
62
70
  // Source and base are also compared for identicalness
63
71
  // Non-identical fields are copied from source to base as duplicates
64
- if (!compareTagsOnly) {
65
- const filterMissing = function(sourceField) {
66
- if ('value' in sourceField) {
67
- debug(`Checking control field ${sourceField.tag} for identicalness`);
68
- return baseFields.some(isIdenticalControlField) === false;
69
- }
70
- if ('subfields' in sourceField) {
71
- debug(`Checking data field ${sourceField.tag} for identicalness`);
72
- return baseFields.some(isIdenticalDataField) === false;
72
+ const sourceCompareField = createCompareField(sourceField);
73
+ const unique = checkCompareFields(baseCompareFields, sourceCompareField);
74
+
75
+ debugCompare(`${JSON.stringify(sourceField)} ${unique ? 'is UNIQUE' : 'not UNIQUE'}`);
76
+
77
+ if (unique) {
78
+ return compareFields(rest, baseCompareFields, [...uniqFields, sourceField]);
79
+ }
80
+
81
+ return compareFields(rest, baseCompareFields, uniqFields);
82
+
83
+ function checkCompareFields(baseCompareFields, sourceCompareField) {
84
+ let unique = true; // eslint-disable-line functional/no-let
85
+
86
+ baseCompareFields.forEach(baseCompareField => {
87
+ debugCompare(`Comparing ${JSON.stringify(sourceCompareField)} to ${JSON.stringify(baseCompareField)}}`);
88
+
89
+ if (sourceCompareField.value !== baseCompareField.value) {
90
+ debugCompare(`Value is different ${sourceCompareField.value} !== ${baseCompareField.value}`);
91
+ return;
73
92
  }
74
93
 
75
- function normalizeControlField(field) {
76
- return field.value.toLowerCase().replace(/\s+/u, '');
94
+ if (sourceCompareField.ind1 !== baseCompareField.ind1) {
95
+ debugCompare(`Ind1 is different ${sourceCompareField.ind1} !== ${baseCompareField.ind1}`);
96
+ return;
77
97
  }
78
98
 
79
- function isIdenticalControlField(baseField) {
80
- const normalizedBaseField = normalizeControlField(baseField);
81
- const normalizedSourceField = normalizeControlField(sourceField);
82
- return normalizedSourceField === normalizedBaseField;
99
+ if (sourceCompareField.ind2 !== baseCompareField.ind2) {
100
+ debugCompare(`Ind2 is different ${sourceCompareField.ind2} !== ${baseCompareField.ind2}`);
101
+ return;
83
102
  }
84
- function isIdenticalDataField(baseField) {
85
- // If excluded subfields have been defined for this field, they must be ignored first
86
- // (i.e. source and base fields are considered identical if all non-excluded subfields are identical)
87
- if (excludeSubfields.length > 0 &&
88
- sourceField.tag === baseField.tag &&
89
- sourceField.ind1 === baseField.ind1 &&
90
- sourceField.ind2 === baseField.ind2) {
91
- excludeSubfields.forEach(sub => debug(`Subfield ${sub} excluded from identicalness comparison`));
92
- // Compare only those subfields that are not excluded
93
- const baseSubsToCompare = baseField.subfields.filter(subfield => excludeSubfields.indexOf(subfield.code) === -1);
94
- return baseSubsToCompare.every(isIdenticalSubfield);
95
- }
96
- // If there are no excluded subfields (default case)
97
- if (sourceField.tag === baseField.tag &&
98
- sourceField.ind1 === baseField.ind1 &&
99
- sourceField.ind2 === baseField.ind2 &&
100
- sourceField.subfields.length === baseField.subfields.length) {
101
- return baseField.subfields.every(isIdenticalSubfield);
102
- }
103
- function normalizeSubfield(subfield) {
104
- return subfield.value.toLowerCase().replace(/\s+/u, '');
105
- }
106
- function isIdenticalSubfield(baseSub) {
107
- const normBaseSub = normalizeSubfield(baseSub);
108
- return sourceField.subfields.some(sourceSub => {
109
- const normSourceSub = normalizeSubfield(sourceSub);
110
- return normSourceSub === normBaseSub;
111
- });
103
+
104
+ if ('subfields' in sourceCompareField) {
105
+ const allFound = checkSubfields(sourceCompareField.subfields, baseCompareField.subfields);
106
+ debugCompare(`Subfields are different ${!allFound}`);
107
+ if (!allFound) {
108
+ return;
112
109
  }
110
+
111
+ unique = false;
112
+ return;
113
113
  }
114
- };
115
- // Search for fields missing from base
116
- const missingFields = sourceFields.filter(filterMissing);
117
- missingFields.forEach(f => base.insertField(f));
118
- if (missingFields.length > 0) {
119
- const missingTags = missingFields.map(field => field.tag);
120
- missingTags.forEach(tag => debug(`Field ${tag} copied from source to base`));
121
- return base;
114
+
115
+ unique = false;
116
+ return;
117
+ });
118
+
119
+ return unique;
120
+ }
121
+
122
+ function checkSubfields(sourceSubfields, baseSubfields) {
123
+ const foundSubs = sourceSubfields.filter(sSub => baseSubfields.some(bSub => sSub.code === bSub.code && sSub.value === bSub.value));
124
+
125
+ if (subfieldsMustBeIdentical) {
126
+ return foundSubs.length === sourceSubfields.length && foundSubs.length === baseSubfields.length;
122
127
  }
123
- if (missingFields.length === 0) {
124
- debug(`No missing fields found`);
125
- return base;
128
+
129
+ return foundSubs.length === sourceSubfields.length;
130
+ }
131
+ }
132
+
133
+ function createCompareField(field) {
134
+ if (compareTagsOnly) {
135
+ return {tag: field.tag};
136
+ }
137
+
138
+ if ('value' in field) {
139
+ return {tag: field.tag, value: field.value};
140
+ }
141
+
142
+ const [filteredField] = checkDropSubfields([field]);
143
+
144
+ const params = [
145
+ {name: 'tag', value: field.tag},
146
+ {name: 'ind1', value: compareWithoutIndicators ? undefined : field.ind1},
147
+ {name: 'ind2', value: compareWithoutIndicators ? undefined : field.ind2},
148
+ {name: 'subfields', value: createCompareSubfields(filteredField.subfields)}
149
+ ].map(param => [param.name, param.value]);
150
+
151
+ return Object.fromEntries(params);
152
+
153
+ function createCompareSubfields(subfields) {
154
+ const nonExcludedSubfields = subfields.filter(sub => !excludeSubfields.some(code => code === sub.code));
155
+ const normalizedSubfields = nonExcludedSubfields.map(sub => ({code: sub.code, value: normalizeSubfieldValue(sub.value)}));
156
+
157
+ return normalizedSubfields;
158
+
159
+ function normalizeSubfieldValue(value) {
160
+ return value.toLowerCase().replace(/\s+/ug, '');
126
161
  }
127
162
  }
128
- debug(`No missing fields found`);
129
- return base;
163
+ }
164
+
165
+ function checkSwapTag(fields) {
166
+ if (swapTag.length > 0) {
167
+ return fields.map(field => ({...field, tag: swapTagsFunc(field.tag)}));
168
+ }
169
+
170
+ return fields;
171
+
172
+ function swapTagsFunc(tag) {
173
+ const [foundRule] = swapTag.filter(rule => new RegExp(rule.from, 'u').test(tag));
174
+
175
+ if (foundRule === undefined) {
176
+ return tag;
177
+ }
178
+
179
+ return foundRule.to;
180
+ }
181
+ }
182
+
183
+ function checkSwapSubfieldCodes(fields) {
184
+ if (swapSubfieldCode.length > 0) {
185
+ return fields.map(field => ({...field, subfields: swapSubfieldCodesFunc(field.subfields)}));
186
+ }
187
+
188
+ return fields;
189
+
190
+ function swapSubfieldCodesFunc(subfields) {
191
+ return subfields.map(sub => {
192
+ const [foundRule] = swapSubfieldCode.filter(rule => rule.from === sub.code);
193
+
194
+ if (foundRule === undefined) {
195
+ return sub;
196
+ }
197
+
198
+ return {code: foundRule.to, value: sub.value};
199
+ });
200
+ }
130
201
  }
131
202
 
132
203
  function checkDropSubfields(fields) {
133
204
  if (dropSubfields.length > 0) {
134
- dropSubfields.forEach(sub => debug(`Subfield ${sub} dropped from source field before copying`));
135
- return fields.map((field) => ({...field, subfields: field.subfields.filter((subfield) => dropSubfields.indexOf(subfield.code) === -1)}));
205
+ return fields.map(field => ({...field, subfields: dropSubfieldsFunc(field.subfields)}))
206
+ .filter(field => field.subfields.length > 0);
136
207
  }
137
- debug(`No subfields to drop`);
208
+
209
+ return fields;
210
+
211
+ function dropSubfieldsFunc(subfields) {
212
+ return subfields.filter(sub => { // eslint-disable-line
213
+ return !dropSubfields.some(({code, value = false, condition = false}) => {
214
+ if (code !== sub.code) {
215
+ return false;
216
+ }
217
+
218
+ if (!condition && value) {
219
+ return value === sub.value;
220
+ }
221
+
222
+ if (condition === 'unless' && value) {
223
+ return !new RegExp(value, 'u').test(sub.value);
224
+ }
225
+
226
+ return true;
227
+ });
228
+ });
229
+ }
230
+ }
231
+
232
+ function checkCopyUnlessFields(fields) {
233
+ if (copyUnless.length > 0) {
234
+ return fields.filter(({subfields}) => copyUnless.some(filter => !subfields.some(sub => sub.code === filter.code && new RegExp(filter.value, 'u').test(sub.value))));
235
+ }
236
+
138
237
  return fields;
139
238
  }
140
239
  };
240
+
241
+ // function copyFields() { //eslint-disable-line no-unused-vars
242
+ // const sourceTags = sourceFields.map(field => field.tag);
243
+ // sourceTags.forEach(tag => debug(`Comparing field ${tag}`));
244
+
245
+ // /*
246
+ // if (combine.length > 0) {
247
+ // debug(`*** NOW Copy options: ${tagPattern}, ${compareTagsOnly}, ${compareWithoutIndicators}, ${subfieldsMustBeIdentical}, [${combine}], [${excludeSubfields}], [${dropSubfields}]`);
248
+ // combine.forEach(row => debug(` ### combine ${row} <- `));
249
+ // return [];
250
+ // }
251
+ // */
252
+
253
+ // // If compareTagsOnly = true, only this part is run
254
+ // // The field is copied from source only if it is missing completely from base
255
+ // if (compareTagsOnly && baseFields.length === 0) {
256
+ // sourceTags.forEach(tag => debug(`Missing field ${tag} copied from source to base`));
257
+ // sourceFields.forEach(f => base.insertField(f));
258
+ // return true;
259
+ // }
260
+
261
+ // // If compareTagsOnly = false (default)
262
+ // // Source and base are also compared for identicalness
263
+ // // Non-identical fields are copied from source to base as duplicates
264
+ // if (!compareTagsOnly) {
265
+ // const filterMissing = function (sourceField) {
266
+ // if ('value' in sourceField) {
267
+ // debug(`Checking control field ${sourceField.tag} for identicalness`);
268
+ // return baseFields.some(isIdenticalControlField) === false;
269
+ // }
270
+ // if ('subfields' in sourceField) {
271
+ // debug(`Checking data field ${sourceField.tag} for identicalness`);
272
+ // return baseFields.some(isIdenticalDataField) === false;
273
+ // }
274
+
275
+ // function normalizeControlField(field) {
276
+ // return field.value.toLowerCase().replace(/\s+/u, '');
277
+ // }
278
+
279
+ // function isIdenticalControlField(baseField) {
280
+ // const normalizedBaseField = normalizeControlField(baseField);
281
+ // const normalizedSourceField = normalizeControlField(sourceField);
282
+ // return normalizedSourceField === normalizedBaseField;
283
+ // }
284
+
285
+ // function isIdenticalDataField(baseField) {
286
+ // // If excluded subfields have been defined for this field, they must be ignored first
287
+ // // (i.e. source and base fields are considered identical if all non-excluded subfields are identical)
288
+ // if (excludeSubfields.length > 0 &&
289
+ // sourceField.tag === baseField.tag &&
290
+ // sourceField.ind1 === baseField.ind1 &&
291
+ // sourceField.ind2 === baseField.ind2) {
292
+ // excludeSubfields.forEach(sub => debug(`Subfield ${sub} excluded from identicalness comparison`));
293
+ // // Compare only those subfields that are not excluded
294
+ // const baseSubsToCompare = baseField.subfields.filter(subfield => excludeSubfields.indexOf(subfield.code) === -1);
295
+ // return baseSubsToCompare.every(isIdenticalSubfield);
296
+ // }
297
+ // // If there are no excluded subfields (default case)
298
+ // if (sourceField.tag === baseField.tag &&
299
+ // sourceField.ind1 === baseField.ind1 &&
300
+ // sourceField.ind2 === baseField.ind2 &&
301
+ // sourceField.subfields.length === baseField.subfields.length) {
302
+ // return baseField.subfields.every(isIdenticalSubfield);
303
+ // }
304
+ // function normalizeSubfield(subfield) {
305
+ // return subfield.value.toLowerCase().replace(/\s+/u, '');
306
+ // }
307
+ // function isIdenticalSubfield(baseSub) {
308
+ // const normBaseSub = normalizeSubfield(baseSub);
309
+ // return sourceField.subfields.some(sourceSub => {
310
+ // const normSourceSub = normalizeSubfield(sourceSub);
311
+ // return normSourceSub === normBaseSub;
312
+ // });
313
+ // }
314
+ // }
315
+ // };
316
+ // // Search for fields missing from base
317
+ // const missingFields = sourceFields.filter(filterMissing);
318
+ // missingFields.forEach(f => base.insertField(f));
319
+ // if (missingFields.length > 0) {
320
+ // const missingTags = missingFields.map(field => field.tag);
321
+ // missingTags.forEach(tag => debug(`Field ${tag} copied from source to base`));
322
+ // return base;
323
+ // }
324
+ // if (missingFields.length === 0) {
325
+ // debug(`No missing fields found`);
326
+ // return base;
327
+ // }
328
+ // }
329
+ // debug(`No missing fields found`);
330
+ // return base;
331
+ // }