@natlibfi/melinda-commons 13.0.21 → 13.2.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/subRecordPicker.js +41 -7
- package/dist/subRecordPicker.js.map +1 -1
- package/dist/subRecordPicker.spec.js +24 -4
- package/dist/subRecordPicker.spec.js.map +1 -1
- package/dist/utils.js +40 -0
- package/dist/utils.js.map +1 -1
- package/dist/utils.spec.js +42 -0
- package/dist/utils.spec.js.map +1 -1
- package/package.json +1 -1
- package/src/subRecordPicker.js +41 -8
- package/src/subRecordPicker.spec.js +21 -3
- package/src/utils.js +43 -0
- package/src/utils.spec.js +55 -1
- package/test-fixtures/subRecordPicker/readAllSubrecords/01/metadata.json +1 -0
- package/test-fixtures/subRecordPicker/readAllSubrecords/02/expected-records.json +632 -0
- package/test-fixtures/subRecordPicker/readAllSubrecords/02/metadata.json +22 -0
- package/test-fixtures/subRecordPicker/readAllSubrecords/02/response01.xml +136 -0
- package/test-fixtures/subRecordPicker/readAllSubrecords/02/response02.xml +71 -0
- package/test-fixtures/subRecordPicker/readAllSubrecords/03/expected-records.json +1 -0
- package/test-fixtures/subRecordPicker/readAllSubrecords/03/metadata.json +17 -0
- package/test-fixtures/subRecordPicker/readAllSubrecords/03/response01.xml +4 -0
- package/test-fixtures/subRecordPicker/readSomeSubrecords/01/metadata.json +1 -0
- package/test-fixtures/subRecordPicker/readSubrecordAmount/01/metadata.json +16 -0
- package/test-fixtures/subRecordPicker/readSubrecordAmount/01/response01.xml +4 -0
- package/test-fixtures/utils/isComponentRecord/record1.json +35 -0
- package/test-fixtures/utils/isComponentRecord/record2.json +35 -0
- package/test-fixtures/utils/isComponentRecord/record3.json +20 -0
- package/test-fixtures/utils/isComponentRecord/record4.json +20 -0
- package/test-fixtures/utils/isComponentRecord/record5.json +20 -0
- package/test-fixtures/utils/isComponentRecord/record6.json +35 -0
- package/test-fixtures/utils/isComponentRecord/record7.json +35 -0
package/src/utils.js
CHANGED
|
@@ -28,6 +28,49 @@ export function isDeletedRecord(record) {
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
export function isComponentRecord(record, ignoreCollections = false, additionalHostFields = []) {
|
|
32
|
+
|
|
33
|
+
// Record is a component record if it has bibliografic level of a component in leader
|
|
34
|
+
// and/or has at least one host link field (f773)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
// Ignore collections - optionally do not handle collections (LDR/07 'c')
|
|
38
|
+
// or collection subUnits (LDR/07 'd') as components, even if they do have f773
|
|
39
|
+
|
|
40
|
+
// https://www.loc.gov/marc/bibliographic/bdleader.html
|
|
41
|
+
// LDR/07
|
|
42
|
+
// c - Collection
|
|
43
|
+
// d - Subunit (in a collection)
|
|
44
|
+
|
|
45
|
+
if (ignoreCollections && ['c', 'd'].includes(record.leader[7])) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// https://www.loc.gov/marc/bibliographic/bdleader.html
|
|
50
|
+
// LDR/07
|
|
51
|
+
// a - Monographic component part
|
|
52
|
+
// b - Serial component part
|
|
53
|
+
// d - Subunit (in a collection)
|
|
54
|
+
|
|
55
|
+
if (['a', 'b', 'd'].includes(record.leader[7])) {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// https://www.loc.gov/marc/bibliographic/bd773.html
|
|
60
|
+
// 773 - Host Item Entry (R)
|
|
61
|
+
|
|
62
|
+
// additionalHostFields (for example f973 for Viola's multihost componenets)
|
|
63
|
+
// optionally recognize fields given in additionalHostFields array as hostFields
|
|
64
|
+
|
|
65
|
+
const hostFields = additionalHostFields.concat('773');
|
|
66
|
+
const hostFieldPatternString = `^(${hostFields.join('|')})$`;
|
|
67
|
+
const hostFieldRegex = new RegExp(hostFieldPatternString, 'u');
|
|
68
|
+
|
|
69
|
+
const recordHasHostFields = record.get(hostFieldRegex).length > 0;
|
|
70
|
+
return recordHasHostFields;
|
|
71
|
+
//return record.get(/^773$/u).length > 0;
|
|
72
|
+
}
|
|
73
|
+
|
|
31
74
|
export function parseBoolean(value) {
|
|
32
75
|
if (value === undefined) {
|
|
33
76
|
return false;
|
package/src/utils.spec.js
CHANGED
|
@@ -4,7 +4,7 @@ import {expect} from 'chai';
|
|
|
4
4
|
import {MarcRecord} from '@natlibfi/marc-record';
|
|
5
5
|
import {
|
|
6
6
|
generateAuthorizationHeader, isDeletedRecord, parseBoolean, clone,
|
|
7
|
-
getRecordTitle, getRecordStandardIdentifiers
|
|
7
|
+
getRecordTitle, getRecordStandardIdentifiers, isComponentRecord
|
|
8
8
|
} from './utils';
|
|
9
9
|
|
|
10
10
|
MarcRecord.setValidationOptions({subfieldValues: false});
|
|
@@ -104,6 +104,60 @@ describe('utils', () => {
|
|
|
104
104
|
|
|
105
105
|
});
|
|
106
106
|
|
|
107
|
+
describe('isComponentRecord', () => {
|
|
108
|
+
it('Should find out that the record is a component record (f773)', () => {
|
|
109
|
+
const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isComponentRecord/record1.json'), 'utf8');
|
|
110
|
+
const record = new MarcRecord(JSON.parse(data));
|
|
111
|
+
expect(isComponentRecord(record)).to.equal(true);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('Should find out that the record is a component record (f773 + LDR/07 "a")', () => {
|
|
115
|
+
const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isComponentRecord/record2.json'), 'utf8');
|
|
116
|
+
const record = new MarcRecord(JSON.parse(data));
|
|
117
|
+
expect(isComponentRecord(record)).to.equal(true);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('Should find out that the record is a component (LDR/07 "d")', () => {
|
|
121
|
+
const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isComponentRecord/record3.json'), 'utf8');
|
|
122
|
+
const record = new MarcRecord(JSON.parse(data));
|
|
123
|
+
expect(isComponentRecord(record)).to.equal(true);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('Should find out that the record is not a component record', () => {
|
|
127
|
+
const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isComponentRecord/record4.json'), 'utf8');
|
|
128
|
+
const record = new MarcRecord(JSON.parse(data));
|
|
129
|
+
expect(isComponentRecord(record)).to.equal(false);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('Should find out that the record is not a component record when ignoring collections', () => {
|
|
133
|
+
const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isComponentRecord/record4.json'), 'utf8');
|
|
134
|
+
const record = new MarcRecord(JSON.parse(data));
|
|
135
|
+
expect(isComponentRecord(record, true)).to.equal(false);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
it('Should find out that the record is not a component record when ignoring collections (LDR/07 "d")', () => {
|
|
140
|
+
const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isComponentRecord/record5.json'), 'utf8');
|
|
141
|
+
const record = new MarcRecord(JSON.parse(data));
|
|
142
|
+
expect(isComponentRecord(record, true)).to.equal(false);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
it('Should find out that the record is not a component record when ignoring collections (LDR/07 "c" and f773)', () => {
|
|
147
|
+
const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isComponentRecord/record6.json'), 'utf8');
|
|
148
|
+
const record = new MarcRecord(JSON.parse(data));
|
|
149
|
+
expect(isComponentRecord(record, true)).to.equal(false);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it('Should find out that the record is a component record when using additional host fields (f973)', () => {
|
|
153
|
+
const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isComponentRecord/record7.json'), 'utf8');
|
|
154
|
+
const record = new MarcRecord(JSON.parse(data));
|
|
155
|
+
expect(isComponentRecord(record, false, ['973'])).to.equal(true);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
|
|
107
161
|
describe('getRecordTitle', () => {
|
|
108
162
|
[
|
|
109
163
|
'Should find a title',
|