@natlibfi/marc-record-merge 6.0.0-beta.8 → 7.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/.github/CODEOWNERS +2 -9
  2. package/.github/dependabot.yml +2 -3
  3. package/.github/workflows/melinda-node-tests.yml +2 -2
  4. package/README.md +16 -0
  5. package/dist/index.js +49 -4
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.spec.js +59 -0
  8. package/dist/index.spec.js.map +1 -0
  9. package/dist/reducers/copy.js +59 -148
  10. package/dist/reducers/copy.js.map +1 -1
  11. package/dist/reducers/copy.spec.js +9 -12
  12. package/dist/reducers/copy.spec.js.map +1 -1
  13. package/dist/reducers/copy2.spec.js +66 -0
  14. package/dist/reducers/copy2.spec.js.map +1 -0
  15. package/dist/reducers/index.js +0 -6
  16. package/dist/reducers/index.js.map +1 -1
  17. package/dist/reducers/select.js +43 -40
  18. package/dist/reducers/select.js.map +1 -1
  19. package/dist/reducers/select.spec.js +4 -15
  20. package/dist/reducers/select.spec.js.map +1 -1
  21. package/dist/reducers/select2.spec.js +58 -0
  22. package/dist/reducers/select2.spec.js.map +1 -0
  23. package/package.json +18 -18
  24. package/src/index.js +51 -1
  25. package/src/index.spec.js +45 -0
  26. package/src/reducers/copy.js +42 -103
  27. package/src/reducers/copy.spec.js +4 -6
  28. package/src/reducers/copy2.spec.js +55 -0
  29. package/src/reducers/select.js +31 -10
  30. package/src/reducers/select2.spec.js +49 -0
  31. package/test-fixtures/index/01/base.json +24 -0
  32. package/test-fixtures/index/01/merged.json +24 -0
  33. package/test-fixtures/index/01/metadata.json +8 -0
  34. package/test-fixtures/index/01/source.json +40 -0
  35. package/test-fixtures/index/02/base.json +24 -0
  36. package/test-fixtures/index/02/merged.json +24 -0
  37. package/test-fixtures/index/02/metadata.json +7 -0
  38. package/test-fixtures/index/02/source.json +40 -0
  39. package/test-fixtures/reducers/copy/04 - compareWithoutIndicators/03/metadata.json +6 -0
  40. package/test-fixtures/reducers/copy/04 - compareWithoutIndicators/04/base.json +20 -0
  41. package/test-fixtures/reducers/copy/04 - compareWithoutIndicators/04/merged.json +31 -0
  42. package/test-fixtures/reducers/copy/04 - compareWithoutIndicators/04/metadata.json +5 -0
  43. package/test-fixtures/reducers/copy/04 - compareWithoutIndicators/04/source.json +20 -0
  44. package/test-fixtures/reducers/copy/11 - compareWithoutTag/01/base.json +28 -0
  45. package/test-fixtures/reducers/copy/11 - compareWithoutTag/01/merged.json +28 -0
  46. package/test-fixtures/reducers/copy/11 - compareWithoutTag/01/metadata.json +6 -0
  47. package/test-fixtures/reducers/copy/11 - compareWithoutTag/01/source.json +20 -0
  48. package/test-fixtures/reducers/copy/11 - compareWithoutTag/02/base.json +28 -0
  49. package/test-fixtures/reducers/copy/11 - compareWithoutTag/02/merged.json +39 -0
  50. package/test-fixtures/reducers/copy/11 - compareWithoutTag/02/metadata.json +6 -0
  51. package/test-fixtures/reducers/copy/11 - compareWithoutTag/02/source.json +31 -0
  52. package/test-fixtures/reducers/copy/11 - compareWithoutTag/03/base.json +28 -0
  53. package/test-fixtures/reducers/copy/11 - compareWithoutTag/03/merged.json +28 -0
  54. package/test-fixtures/reducers/copy/11 - compareWithoutTag/03/metadata.json +7 -0
  55. package/test-fixtures/reducers/copy/11 - compareWithoutTag/03/source.json +20 -0
  56. package/test-fixtures/reducers/copy/11 - compareWithoutTag/04/base.json +17 -0
  57. package/test-fixtures/reducers/copy/11 - compareWithoutTag/04/merged.json +28 -0
  58. package/test-fixtures/reducers/copy/11 - compareWithoutTag/04/metadata.json +7 -0
  59. package/test-fixtures/reducers/copy/11 - compareWithoutTag/04/source.json +31 -0
  60. package/test-fixtures/reducers/copy/11 - compareWithoutTag/05/base.json +28 -0
  61. package/test-fixtures/reducers/copy/11 - compareWithoutTag/05/merged.json +28 -0
  62. package/test-fixtures/reducers/copy/11 - compareWithoutTag/05/metadata.json +7 -0
  63. package/test-fixtures/reducers/copy/11 - compareWithoutTag/05/source.json +28 -0
@@ -0,0 +1,49 @@
1
+ import {expect} from 'chai';
2
+ import {MarcRecord} from '@natlibfi/marc-record';
3
+ import createReducer, {subsetEquality} from './select';
4
+ import {READERS} from '@natlibfi/fixura';
5
+ import generateTests from '@natlibfi/fixugen';
6
+
7
+ MarcRecord.setValidationOptions({subfieldValues: false});
8
+
9
+ generateTests({
10
+ callback,
11
+ path: [__dirname, '..', '..', 'test-fixtures', 'reducers', 'select'],
12
+ useMetadataFile: true,
13
+ recurse: false,
14
+ fixura: {
15
+ reader: READERS.JSON,
16
+ failWhenNotFound: false
17
+ }
18
+ });
19
+
20
+ function callback({
21
+ getFixture,
22
+ disabled = false,
23
+ tagPatternRegExp = false,
24
+ expectedError = false,
25
+ useSubsetEquality = false
26
+ }) {
27
+ if (disabled) {
28
+ console.log('TEST DISABLED!'); // eslint-disable-line no-console
29
+ return;
30
+ }
31
+ // const base = new MarcRecord(getFixture('base.json'), {subfieldValues: false});
32
+ // const source = new MarcRecord(getFixture('source.json'), {subfieldValues: false});
33
+
34
+ const base = getFixture('base.json');
35
+ const source = getFixture('source.json');
36
+
37
+ const tagPattern = new RegExp(tagPatternRegExp, 'u');
38
+ const expectedRecord = getFixture('merged.json');
39
+ const equalityFunction = useSubsetEquality ? subsetEquality : undefined;
40
+
41
+ // Bypass expected error in testing
42
+ if (expectedError) {
43
+ expect(() => createReducer.to.throw(Error, 'control field'));
44
+ return;
45
+ }
46
+
47
+ const mergedRecord = createReducer({tagPattern, equalityFunction})({base, source});
48
+ expect(mergedRecord).to.eql(expectedRecord);
49
+ }
@@ -0,0 +1,24 @@
1
+ {
2
+ "leader": "01331cam a22003494i 4500",
3
+ "fields": [
4
+ {
5
+ "tag": "001",
6
+ "value": "001_base"
7
+ },
8
+ {
9
+ "tag": "010",
10
+ "ind1": " ",
11
+ "ind2": " ",
12
+ "subfields": [
13
+ {
14
+ "code": "a",
15
+ "value": "010a_base"
16
+ },
17
+ {
18
+ "code": "b",
19
+ "value": "010b_base"
20
+ }
21
+ ]
22
+ }
23
+ ]
24
+ }
@@ -0,0 +1,24 @@
1
+ {
2
+ "leader": "01331cam a22003494i 4500",
3
+ "fields": [
4
+ {
5
+ "tag": "001",
6
+ "value": "001_base"
7
+ },
8
+ {
9
+ "tag": "010",
10
+ "ind1": " ",
11
+ "ind2": " ",
12
+ "subfields": [
13
+ {
14
+ "code": "a",
15
+ "value": "010a_base"
16
+ },
17
+ {
18
+ "code": "b",
19
+ "value": "010b_base"
20
+ }
21
+ ]
22
+ }
23
+ ]
24
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "description":"Reducers should run after each another - two reducers",
3
+ "reducerConfigs": [
4
+ {"tagPattern": "/010/u", "compareTagsOnly": true},
5
+ {"tagPattern": "/33./u"}
6
+
7
+ ]
8
+ }
@@ -0,0 +1,40 @@
1
+ {
2
+ "leader": "01331cam a22003494i 4500",
3
+ "fields": [
4
+ {
5
+ "tag": "001",
6
+ "value": "001_sorsa"
7
+ },
8
+ {
9
+ "tag": "010",
10
+ "ind1": " ",
11
+ "ind2": " ",
12
+ "subfields": [
13
+ {
14
+ "code": "a",
15
+ "value": "010a_sorsa"
16
+ },
17
+ {
18
+ "code": "b",
19
+ "value": "010b_sorsa"
20
+ }
21
+ ]
22
+ },
23
+ {
24
+ "tag": "650",
25
+ "ind1": " ",
26
+ "ind2": "7",
27
+ "subfields": [
28
+ {
29
+ "code": "a",
30
+ "value": "poista mut"
31
+ },
32
+ {
33
+ "code": "2",
34
+ "value": "ysa"
35
+ }
36
+ ]
37
+ }
38
+
39
+ ]
40
+ }
@@ -0,0 +1,24 @@
1
+ {
2
+ "leader": "01331cam a22003494i 4500",
3
+ "fields": [
4
+ {
5
+ "tag": "001",
6
+ "value": "001_base"
7
+ },
8
+ {
9
+ "tag": "010",
10
+ "ind1": " ",
11
+ "ind2": " ",
12
+ "subfields": [
13
+ {
14
+ "code": "a",
15
+ "value": "010a_base"
16
+ },
17
+ {
18
+ "code": "b",
19
+ "value": "010b_base"
20
+ }
21
+ ]
22
+ }
23
+ ]
24
+ }
@@ -0,0 +1,24 @@
1
+ {
2
+ "leader": "01331cam a22003494i 4500",
3
+ "fields": [
4
+ {
5
+ "tag": "001",
6
+ "value": "001_base"
7
+ },
8
+ {
9
+ "tag": "010",
10
+ "ind1": " ",
11
+ "ind2": " ",
12
+ "subfields": [
13
+ {
14
+ "code": "a",
15
+ "value": "010a_base"
16
+ },
17
+ {
18
+ "code": "b",
19
+ "value": "010b_base"
20
+ }
21
+ ]
22
+ }
23
+ ]
24
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "description":"Reducers should run after each another - single reducer",
3
+ "reducerConfigs": [
4
+ {"tagPattern": "/33./u"}
5
+ ],
6
+ "skip": false
7
+ }
@@ -0,0 +1,40 @@
1
+ {
2
+ "leader": "01331cam a22003494i 4500",
3
+ "fields": [
4
+ {
5
+ "tag": "001",
6
+ "value": "001_sorsa"
7
+ },
8
+ {
9
+ "tag": "010",
10
+ "ind1": " ",
11
+ "ind2": " ",
12
+ "subfields": [
13
+ {
14
+ "code": "a",
15
+ "value": "010a_sorsa"
16
+ },
17
+ {
18
+ "code": "b",
19
+ "value": "010b_sorsa"
20
+ }
21
+ ]
22
+ },
23
+ {
24
+ "tag": "650",
25
+ "ind1": " ",
26
+ "ind2": "7",
27
+ "subfields": [
28
+ {
29
+ "code": "a",
30
+ "value": "poista mut"
31
+ },
32
+ {
33
+ "code": "2",
34
+ "value": "ysa"
35
+ }
36
+ ]
37
+ }
38
+
39
+ ]
40
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "description": "Copy fields 730: omit ind 1 from comparison - same field no copy",
3
+ "tagPatternRegExp": "^730$",
4
+ "compareWithoutIndicator1": true,
5
+ "skip": true
6
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "leader": "01331cam a22003494i 4500",
3
+ "fields": [
4
+ {
5
+ "tag": "001",
6
+ "value": "007346734"
7
+ },
8
+ {
9
+ "tag": "730",
10
+ "ind1": "4",
11
+ "ind2": " ",
12
+ "subfields": [
13
+ {
14
+ "code": "a",
15
+ "value": "The End"
16
+ }
17
+ ]
18
+ }
19
+ ]
20
+ }
@@ -0,0 +1,31 @@
1
+ {
2
+ "leader": "01331cam a22003494i 4500",
3
+ "fields": [
4
+ {
5
+ "tag": "001",
6
+ "value": "007346734"
7
+ },
8
+ {
9
+ "tag": "730",
10
+ "ind1": "4",
11
+ "ind2": " ",
12
+ "subfields": [
13
+ {
14
+ "code": "a",
15
+ "value": "The End"
16
+ }
17
+ ]
18
+ },
19
+ {
20
+ "tag": "730",
21
+ "ind1": "0",
22
+ "ind2": " ",
23
+ "subfields": [
24
+ {
25
+ "code": "a",
26
+ "value": "The End"
27
+ }
28
+ ]
29
+ }
30
+ ]
31
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "description": "Copy fields 730: omit ind 2 from comparison - different field -> copy",
3
+ "tagPatternRegExp": "^730$",
4
+ "compareWithoutIndicator2foo": true
5
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "leader": "01331cam a22003494i 4500",
3
+ "fields": [
4
+ {
5
+ "tag": "001",
6
+ "value": "007346734"
7
+ },
8
+ {
9
+ "tag": "730",
10
+ "ind1": "0",
11
+ "ind2": " ",
12
+ "subfields": [
13
+ {
14
+ "code": "a",
15
+ "value": "The End"
16
+ }
17
+ ]
18
+ }
19
+ ]
20
+ }
@@ -0,0 +1,28 @@
1
+ {
2
+ "leader": "01331cam a22003494i 4500",
3
+ "fields": [
4
+ {
5
+ "tag": "001",
6
+ "value": "007346734"
7
+ },
8
+ {
9
+ "tag": "100",
10
+ "ind1": " ",
11
+ "ind2": " ",
12
+ "subfields": [
13
+ {"code": "a", "value": "original"}
14
+ ]
15
+ },
16
+ {
17
+ "tag": "700",
18
+ "ind1": " ",
19
+ "ind2": " ",
20
+ "subfields": [
21
+ {
22
+ "code": "a",
23
+ "value": "test"
24
+ }
25
+ ]
26
+ }
27
+ ]
28
+ }
@@ -0,0 +1,28 @@
1
+ {
2
+ "leader": "01331cam a22003494i 4500",
3
+ "fields": [
4
+ {
5
+ "tag": "001",
6
+ "value": "007346734"
7
+ },
8
+ {
9
+ "tag": "100",
10
+ "ind1": " ",
11
+ "ind2": " ",
12
+ "subfields": [
13
+ {"code": "a", "value": "original"}
14
+ ]
15
+ },
16
+ {
17
+ "tag": "700",
18
+ "ind1": " ",
19
+ "ind2": " ",
20
+ "subfields": [
21
+ {
22
+ "code": "a",
23
+ "value": "test"
24
+ }
25
+ ]
26
+ }
27
+ ]
28
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "description": "compare fields 100 and 700, compareWithoutTag, source 100 found as 700 in base: no copy",
3
+ "tagPatternRegExp": "^(?<tags>100|700)$",
4
+ "compareWithoutTag": true,
5
+ "only": false
6
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "leader": "01331cam a22003494i 4500",
3
+ "fields": [
4
+ {
5
+ "tag": "001",
6
+ "value": "007346734"
7
+ },
8
+ {
9
+ "tag": "100",
10
+ "ind1": " ",
11
+ "ind2": " ",
12
+ "subfields": [
13
+ {
14
+ "code": "a",
15
+ "value": "test"
16
+ }
17
+ ]
18
+ }
19
+ ]
20
+ }
@@ -0,0 +1,28 @@
1
+ {
2
+ "leader": "01331cam a22003494i 4500",
3
+ "fields": [
4
+ {
5
+ "tag": "001",
6
+ "value": "007346734"
7
+ },
8
+ {
9
+ "tag": "100",
10
+ "ind1": " ",
11
+ "ind2": " ",
12
+ "subfields": [
13
+ {"code": "a", "value": "original"}
14
+ ]
15
+ },
16
+ {
17
+ "tag": "700",
18
+ "ind1": " ",
19
+ "ind2": " ",
20
+ "subfields": [
21
+ {
22
+ "code": "a",
23
+ "value": "test"
24
+ }
25
+ ]
26
+ }
27
+ ]
28
+ }
@@ -0,0 +1,39 @@
1
+ {
2
+ "leader": "01331cam a22003494i 4500",
3
+ "fields": [
4
+ {
5
+ "tag": "001",
6
+ "value": "007346734"
7
+ },
8
+ {
9
+ "tag": "100",
10
+ "ind1": " ",
11
+ "ind2": " ",
12
+ "subfields": [
13
+ {"code": "a", "value": "original"}
14
+ ]
15
+ },
16
+ {
17
+ "tag": "700",
18
+ "ind1": " ",
19
+ "ind2": " ",
20
+ "subfields": [
21
+ {
22
+ "code": "a",
23
+ "value": "test"
24
+ }
25
+ ]
26
+ },
27
+ {
28
+ "tag": "700",
29
+ "ind1": " ",
30
+ "ind2": " ",
31
+ "subfields": [
32
+ {
33
+ "code": "a",
34
+ "value": "test2"
35
+ }
36
+ ]
37
+ }
38
+ ]
39
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "description": "compare fields 100 and 700, compareWithoutTag, adds missing 700 from source to base",
3
+ "tagPatternRegExp": "^(?<tags>100|700)$",
4
+ "compareWithoutTag": true,
5
+ "only": false
6
+ }
@@ -0,0 +1,31 @@
1
+ {
2
+ "leader": "01331cam a22003494i 4500",
3
+ "fields": [
4
+ {
5
+ "tag": "001",
6
+ "value": "007346734"
7
+ },
8
+ {
9
+ "tag": "100",
10
+ "ind1": " ",
11
+ "ind2": " ",
12
+ "subfields": [
13
+ {
14
+ "code": "a",
15
+ "value": "test"
16
+ }
17
+ ]
18
+ },
19
+ {
20
+ "tag": "700",
21
+ "ind1": " ",
22
+ "ind2": " ",
23
+ "subfields": [
24
+ {
25
+ "code": "a",
26
+ "value": "test2"
27
+ }
28
+ ]
29
+ }
30
+ ]
31
+ }
@@ -0,0 +1,28 @@
1
+ {
2
+ "leader": "01331cam a22003494i 4500",
3
+ "fields": [
4
+ {
5
+ "tag": "001",
6
+ "value": "007346734"
7
+ },
8
+ {
9
+ "tag": "100",
10
+ "ind1": " ",
11
+ "ind2": " ",
12
+ "subfields": [
13
+ {"code": "a", "value": "original"}
14
+ ]
15
+ },
16
+ {
17
+ "tag": "700",
18
+ "ind1": " ",
19
+ "ind2": " ",
20
+ "subfields": [
21
+ {
22
+ "code": "a",
23
+ "value": "test"
24
+ }
25
+ ]
26
+ }
27
+ ]
28
+ }
@@ -0,0 +1,28 @@
1
+ {
2
+ "leader": "01331cam a22003494i 4500",
3
+ "fields": [
4
+ {
5
+ "tag": "001",
6
+ "value": "007346734"
7
+ },
8
+ {
9
+ "tag": "100",
10
+ "ind1": " ",
11
+ "ind2": " ",
12
+ "subfields": [
13
+ {"code": "a", "value": "original"}
14
+ ]
15
+ },
16
+ {
17
+ "tag": "700",
18
+ "ind1": " ",
19
+ "ind2": " ",
20
+ "subfields": [
21
+ {
22
+ "code": "a",
23
+ "value": "test"
24
+ }
25
+ ]
26
+ }
27
+ ]
28
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "description": "compare fields 100 and 700, compareWithoutTag, if copied: swapTag 700: base has 700 allready",
3
+ "tagPatternRegExp": "^(?<tags>100|700)$",
4
+ "compareWithoutTag": true,
5
+ "swapTag": [{"from": "^100$", "to": "700"}],
6
+ "only": false
7
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "leader": "01331cam a22003494i 4500",
3
+ "fields": [
4
+ {
5
+ "tag": "001",
6
+ "value": "007346734"
7
+ },
8
+ {
9
+ "tag": "100",
10
+ "ind1": " ",
11
+ "ind2": " ",
12
+ "subfields": [
13
+ {
14
+ "code": "a",
15
+ "value": "test"
16
+ }
17
+ ]
18
+ }
19
+ ]
20
+ }
@@ -0,0 +1,17 @@
1
+ {
2
+ "leader": "01331cam a22003494i 4500",
3
+ "fields": [
4
+ {
5
+ "tag": "001",
6
+ "value": "007346734"
7
+ },
8
+ {
9
+ "tag": "100",
10
+ "ind1": " ",
11
+ "ind2": " ",
12
+ "subfields": [
13
+ {"code": "a", "value": "original"}
14
+ ]
15
+ }
16
+ ]
17
+ }
@@ -0,0 +1,28 @@
1
+ {
2
+ "leader": "01331cam a22003494i 4500",
3
+ "fields": [
4
+ {
5
+ "tag": "001",
6
+ "value": "007346734"
7
+ },
8
+ {
9
+ "tag": "100",
10
+ "ind1": " ",
11
+ "ind2": " ",
12
+ "subfields": [
13
+ {"code": "a", "value": "original"}
14
+ ]
15
+ },
16
+ {
17
+ "tag": "700",
18
+ "ind1": " ",
19
+ "ind2": " ",
20
+ "subfields": [
21
+ {
22
+ "code": "a",
23
+ "value": "test"
24
+ }
25
+ ]
26
+ }
27
+ ]
28
+ }