@natlibfi/marc-record-validators-melinda 11.3.6 → 11.3.7-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/punctuation2.js +42 -10
- package/dist/punctuation2.js.map +1 -1
- package/dist/urn.js +15 -6
- package/dist/urn.js.map +1 -1
- package/dist/urn.spec.js +45 -276
- package/dist/urn.spec.js.map +1 -1
- package/package.json +10 -10
- package/src/punctuation2.js +27 -10
- package/src/urn.js +17 -3
- package/src/urn.spec.js +49 -264
- package/test-fixtures/cyrillux/f09/expectedResult.json +4 -4
- package/test-fixtures/punctuation2/787/expectedResult.json +14 -0
- package/test-fixtures/punctuation2/787/metadata.json +5 -0
- package/test-fixtures/punctuation2/787/record.json +13 -0
- package/test-fixtures/sort-fields/05/input.json +11 -10
- package/test-fixtures/sort-fields/05/result.json +10 -10
- package/test-fixtures/strip-punctuation/787/expectedResult.json +14 -0
- package/test-fixtures/strip-punctuation/787/metadata.json +5 -0
- package/test-fixtures/strip-punctuation/787/record.json +13 -0
- package/test-fixtures/urn/f01/input.json +15 -0
- package/test-fixtures/urn/f01/metadata.json +6 -0
- package/test-fixtures/urn/f01/result.json +16 -0
- package/test-fixtures/urn/f02/input.json +11 -0
- package/test-fixtures/urn/f02/metadata.json +7 -0
- package/test-fixtures/urn/f02/result.json +15 -0
- package/test-fixtures/urn/f03/input.json +8 -0
- package/test-fixtures/urn/f03/metadata.json +7 -0
- package/test-fixtures/urn/f03/result.json +12 -0
- package/test-fixtures/urn/f04/input.json +9 -0
- package/test-fixtures/urn/f04/metadata.json +7 -0
- package/test-fixtures/urn/f04/result.json +13 -0
- package/test-fixtures/urn/f05/input.json +9 -0
- package/test-fixtures/urn/f05/metadata.json +9 -0
- package/test-fixtures/urn/f05/result.json +13 -0
- package/test-fixtures/urn/f06/input.json +17 -0
- package/test-fixtures/urn/f06/metadata.json +6 -0
- package/test-fixtures/urn/f06/result.json +18 -0
- package/test-fixtures/urn/f07/input.json +17 -0
- package/test-fixtures/urn/f07/metadata.json +6 -0
- package/test-fixtures/urn/f07/result.json +18 -0
- package/test-fixtures/urn/f08/input.json +11 -0
- package/test-fixtures/urn/f08/metadata.json +6 -0
- package/test-fixtures/urn/f08/result.json +17 -0
- package/test-fixtures/urn/f09/input.json +7 -0
- package/test-fixtures/urn/f09/metadata.json +7 -0
- package/test-fixtures/urn/f09/result.json +8 -0
- package/test-fixtures/urn/f10/input.json +7 -0
- package/test-fixtures/urn/f10/metadata.json +7 -0
- package/test-fixtures/urn/f10/result.json +8 -0
- package/test-fixtures/urn/f11/input.json +7 -0
- package/test-fixtures/urn/f11/metadata.json +7 -0
- package/test-fixtures/urn/f11/result.json +8 -0
- package/test-fixtures/urn/f12/input.json +8 -0
- package/test-fixtures/urn/f12/metadata.json +6 -0
- package/test-fixtures/urn/f12/result.json +14 -0
- package/test-fixtures/urn/f13/input.json +14 -0
- package/test-fixtures/urn/f13/metadata.json +6 -0
- package/test-fixtures/urn/f13/result.json +20 -0
- package/test-fixtures/urn/f14/input.json +14 -0
- package/test-fixtures/urn/f14/metadata.json +6 -0
- package/test-fixtures/urn/f14/result.json +20 -0
- package/test-fixtures/urn/f15/input.json +11 -0
- package/test-fixtures/urn/f15/metadata.json +7 -0
- package/test-fixtures/urn/f15/result.json +17 -0
- package/test-fixtures/urn/v01/input.json +14 -0
- package/test-fixtures/urn/v01/metadata.json +6 -0
- package/test-fixtures/urn/v01/result.json +3 -0
- package/test-fixtures/urn/v02/input.json +18 -0
- package/test-fixtures/urn/v02/metadata.json +6 -0
- package/test-fixtures/urn/v02/result.json +3 -0
- package/test-fixtures/urn/v03/input.json +18 -0
- package/test-fixtures/urn/v03/metadata.json +6 -0
- package/test-fixtures/urn/v03/result.json +3 -0
- package/test-fixtures/urn/v04/input.json +18 -0
- package/test-fixtures/urn/v04/metadata.json +6 -0
- package/test-fixtures/urn/v04/result.json +3 -0
- package/test-fixtures/urn/v05/input.json +18 -0
- package/test-fixtures/urn/v05/metadata.json +6 -0
- package/test-fixtures/urn/v05/result.json +3 -0
- package/test-fixtures/urn/v06/input.json +16 -0
- package/test-fixtures/urn/v06/metadata.json +6 -0
- package/test-fixtures/urn/v06/result.json +3 -0
- package/test-fixtures/urn/v07/input.json +16 -0
- package/test-fixtures/urn/v07/metadata.json +6 -0
- package/test-fixtures/urn/v07/result.json +3 -0
- package/test-fixtures/urn/v08/input.json +15 -0
- package/test-fixtures/urn/v08/metadata.json +6 -0
- package/test-fixtures/urn/v08/result.json +3 -0
- package/test-fixtures/urn/v09/input.json +13 -0
- package/test-fixtures/urn/v09/metadata.json +6 -0
- package/test-fixtures/urn/v09/result.json +3 -0
- package/test-fixtures/urn/v10/input.json +13 -0
- package/test-fixtures/urn/v10/metadata.json +6 -0
- package/test-fixtures/urn/v10/result.json +3 -0
- package/test-fixtures/urn/v11/input.json +21 -0
- package/test-fixtures/urn/v11/metadata.json +6 -0
- package/test-fixtures/urn/v11/result.json +3 -0
- package/test-fixtures/urn/v12/input.json +12 -0
- package/test-fixtures/urn/v12/metadata.json +6 -0
- package/test-fixtures/urn/v12/result.json +3 -0
package/dist/urn.spec.js
CHANGED
|
@@ -2,282 +2,51 @@
|
|
|
2
2
|
|
|
3
3
|
var _chai = require("chai");
|
|
4
4
|
var _marcRecord = require("@natlibfi/marc-record");
|
|
5
|
-
var _urn = _interopRequireDefault(require("
|
|
5
|
+
var _urn = _interopRequireDefault(require("./urn"));
|
|
6
|
+
var _fixura = require("@natlibfi/fixura");
|
|
7
|
+
var _fixugen = _interopRequireDefault(require("@natlibfi/fixugen"));
|
|
8
|
+
var _debug = _interopRequireDefault(require("debug"));
|
|
6
9
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
value: 'rdamedia'
|
|
19
|
-
}]
|
|
20
|
-
};
|
|
21
|
-
const f337nonElectronic = {
|
|
22
|
-
tag: '337',
|
|
23
|
-
ind1: ' ',
|
|
24
|
-
ind2: ' ',
|
|
25
|
-
subfields: [{
|
|
26
|
-
code: 'b',
|
|
27
|
-
value: 'n'
|
|
28
|
-
}, {
|
|
29
|
-
code: '2',
|
|
30
|
-
value: 'rdamedia'
|
|
31
|
-
}]
|
|
32
|
-
};
|
|
33
|
-
const ldf856 = {
|
|
34
|
-
tag: '856',
|
|
35
|
-
ind1: '4',
|
|
36
|
-
ind2: '0',
|
|
37
|
-
subfields: [{
|
|
38
|
-
code: 'u',
|
|
39
|
-
value: 'http://urn.fi/URN:ISBN:978-951-9155-47-0'
|
|
40
|
-
}, {
|
|
41
|
-
code: 'z',
|
|
42
|
-
value: 'Käytettävissä vapaakappaletyöasemilla'
|
|
43
|
-
}, {
|
|
44
|
-
code: '5',
|
|
45
|
-
value: 'FI-Vapaa'
|
|
46
|
-
}]
|
|
47
|
-
};
|
|
48
|
-
const ldf856old = {
|
|
49
|
-
tag: '856',
|
|
50
|
-
ind1: '4',
|
|
51
|
-
ind2: '0',
|
|
52
|
-
subfields: [{
|
|
53
|
-
code: 'u',
|
|
54
|
-
value: 'http://urn.fi/URN:ISBN:978-951-9155-47-0'
|
|
55
|
-
}, {
|
|
56
|
-
code: 'z',
|
|
57
|
-
value: 'Käytettävissä vapaakappalekirjastoissa'
|
|
58
|
-
}, {
|
|
59
|
-
code: '5',
|
|
60
|
-
value: 'FI-Vapaa'
|
|
61
|
-
}]
|
|
62
|
-
};
|
|
63
|
-
const ldf856Https = {
|
|
64
|
-
tag: '856',
|
|
65
|
-
ind1: '4',
|
|
66
|
-
ind2: '0',
|
|
67
|
-
subfields: [{
|
|
68
|
-
code: 'u',
|
|
69
|
-
value: 'https://urn.fi/URN:ISBN:978-951-9155-47-0'
|
|
70
|
-
}, {
|
|
71
|
-
code: 'z',
|
|
72
|
-
value: 'Käytettävissä vapaakappaletyöasemilla'
|
|
73
|
-
}, {
|
|
74
|
-
code: '5',
|
|
75
|
-
value: 'FI-Vapaa'
|
|
76
|
-
}]
|
|
77
|
-
};
|
|
78
|
-
const ldf856partial = {
|
|
79
|
-
tag: '856',
|
|
80
|
-
ind1: '4',
|
|
81
|
-
ind2: '0',
|
|
82
|
-
subfields: [{
|
|
83
|
-
code: 'u',
|
|
84
|
-
value: 'http://urn.fi/URN:ISBN:978-951-9155-47-0'
|
|
85
|
-
}, {
|
|
86
|
-
code: '5',
|
|
87
|
-
value: 'FI-Vapaa'
|
|
88
|
-
}]
|
|
89
|
-
};
|
|
90
|
-
const f856URN = {
|
|
91
|
-
tag: '856',
|
|
92
|
-
ind1: '4',
|
|
93
|
-
ind2: '0',
|
|
94
|
-
subfields: [{
|
|
95
|
-
code: 'u',
|
|
96
|
-
value: 'http://urn.fi/URN:ISBN:978-951-9155-47-0'
|
|
97
|
-
}]
|
|
98
|
-
};
|
|
99
|
-
const f856URNHttps = {
|
|
100
|
-
tag: '856',
|
|
101
|
-
ind1: '4',
|
|
102
|
-
ind2: '0',
|
|
103
|
-
subfields: [{
|
|
104
|
-
code: 'u',
|
|
105
|
-
value: 'https://urn.fi/URN:ISBN:978-951-9155-47-0'
|
|
106
|
-
}]
|
|
107
|
-
};
|
|
108
|
-
const f856URNnotResource = {
|
|
109
|
-
tag: '856',
|
|
110
|
-
ind1: '4',
|
|
111
|
-
ind2: '1',
|
|
112
|
-
subfields: [{
|
|
113
|
-
code: 'u',
|
|
114
|
-
value: 'http://urn.fi/URN:ISBN:978-951-9155-47-0'
|
|
115
|
-
}]
|
|
116
|
-
};
|
|
117
|
-
const f856URL = {
|
|
118
|
-
tag: '856',
|
|
119
|
-
ind1: '4',
|
|
120
|
-
ind2: '0',
|
|
121
|
-
subfields: [{
|
|
122
|
-
code: 'u',
|
|
123
|
-
value: 'http://foo.bar/'
|
|
124
|
-
}]
|
|
125
|
-
};
|
|
126
|
-
const f020 = {
|
|
127
|
-
tag: '020',
|
|
128
|
-
ind1: ' ',
|
|
129
|
-
ind2: ' ',
|
|
130
|
-
subfields: [{
|
|
131
|
-
code: 'a',
|
|
132
|
-
value: '978-951-9155-47-0'
|
|
133
|
-
}]
|
|
134
|
-
};
|
|
135
|
-
const f020second = {
|
|
136
|
-
tag: '020',
|
|
137
|
-
ind1: ' ',
|
|
138
|
-
ind2: ' ',
|
|
139
|
-
subfields: [{
|
|
140
|
-
code: 'a',
|
|
141
|
-
value: '9789519155470'
|
|
142
|
-
}]
|
|
143
|
-
};
|
|
144
|
-
it('Creates a validator', async () => {
|
|
145
|
-
const validator = await (0, _urn.default)();
|
|
146
|
-
(0, _chai.expect)(validator).to.be.an('object').that.has.any.keys('description', 'validate');
|
|
147
|
-
(0, _chai.expect)(validator.description).to.be.a('string');
|
|
148
|
-
(0, _chai.expect)(validator.validate).to.be.a('function');
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
// Tests
|
|
152
|
-
const test = async isLegalDeposit => {
|
|
153
|
-
const validator = await (0, _urn.default)(isLegalDeposit);
|
|
154
|
-
return {
|
|
155
|
-
validate: async (valid, ...recfields) => {
|
|
156
|
-
const result = await validator.validate(new _marcRecord.MarcRecord({
|
|
157
|
-
fields: recfields
|
|
158
|
-
}));
|
|
159
|
-
(0, _chai.expect)(result).to.eql({
|
|
160
|
-
valid
|
|
161
|
-
});
|
|
162
|
-
},
|
|
163
|
-
fix: async (recfields, resfields) => {
|
|
164
|
-
const record = new _marcRecord.MarcRecord({
|
|
165
|
-
fields: recfields
|
|
166
|
-
});
|
|
167
|
-
await validator.fix(record);
|
|
168
|
-
(0, _chai.expect)(record.fields).to.eql(resfields);
|
|
169
|
-
}
|
|
170
|
-
};
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
/// Non-legal and legal deposit
|
|
174
|
-
const nonld = await test(false);
|
|
175
|
-
const ld = await test(true);
|
|
176
|
-
describe('#validate', () => {
|
|
177
|
-
// Validate non-electoronic
|
|
178
|
-
it('Finds the record valid; non-electronic record', async () => {
|
|
179
|
-
await nonld.validate(true, f337nonElectronic);
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
// Validate non-legal deposit
|
|
183
|
-
it('Finds the record valid; 856 with urn, and is non-legal deposit', async () => {
|
|
184
|
-
await nonld.validate(true, f337, f856URN);
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
// we should recognize that 856 with second indicator 1 is not describing the resource itself
|
|
188
|
-
it.skip('Finds the record invalid; 856 ind2: 1 with urn, and is non-legal deposit', async () => {
|
|
189
|
-
await nonld.validate(false, f337, f856URNnotResource);
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
// should we require urn if we're not handling a legal deposit
|
|
193
|
-
it('Finds the record invalid; 856 without urn, and is non-legal deposit', async () => {
|
|
194
|
-
await nonld.validate(false, f337, f856URL);
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
// should we require urn if we're not handling a legal deposit
|
|
198
|
-
it('Finds the record invalid; Missing 856, and is non-legal deposit', async () => {
|
|
199
|
-
await nonld.validate(false, f337, f020);
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
// Validate legal deposit
|
|
203
|
-
it('Finds the record invalid; 856 with urn, and is legal deposit', async () => {
|
|
204
|
-
await ld.validate(false, f020, f337, f856URN);
|
|
205
|
-
});
|
|
206
|
-
it('Finds the record invalid; 856 without urn, and is legal deposit', async () => {
|
|
207
|
-
await ld.validate(false, f020, f337, f856URL);
|
|
208
|
-
});
|
|
209
|
-
it('Finds the record invalid; Missing 856, and is legal deposit', async () => {
|
|
210
|
-
await ld.validate(false, f337, f020);
|
|
211
|
-
});
|
|
212
|
-
it('Finds the record valid; 856 with URN and legal deposit subfields, and is legal deposit', async () => {
|
|
213
|
-
await ld.validate(true, f337, f020, ldf856);
|
|
214
|
-
});
|
|
215
|
-
it('Finds the record invalid; old phrase is used in $z', async () => {
|
|
216
|
-
await ld.validate(false, f337, f020, ldf856old);
|
|
217
|
-
});
|
|
218
|
-
it('Finds the record valid; 856 with URN and legal deposit subfields and other f856s, and is legal deposit', async () => {
|
|
219
|
-
await ld.validate(true, f337, f020, ldf856partial, ldf856, f856URL);
|
|
220
|
-
});
|
|
221
|
-
it('Finds the record invalid; 856 with URN and partial legal deposit subfields, and is legal deposit', async () => {
|
|
222
|
-
await ld.validate(false, f337, f020, ldf856partial);
|
|
223
|
-
});
|
|
224
|
-
});
|
|
225
|
-
describe('#fix', () => {
|
|
226
|
-
// Fix non-legal deposit
|
|
227
|
-
it('856 with urn, and is non-legal deposit; Nothing to add', async () => {
|
|
228
|
-
await nonld.fix([f020, f856URL, f856URN], [f020, f856URL, f856URN]);
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
// should we actually add non-resolvable urns?
|
|
232
|
-
it('856 without urn, and is non-legal deposit; Adds 856 with urn (https)', async () => {
|
|
233
|
-
await nonld.fix([f020, f856URL], [f020, f856URL, f856URNHttps]);
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
// should we actually add non-resolvable urns?
|
|
237
|
-
it('Missing 856, and is non-legal deposit; Adds 856 with urn (https)', async () => {
|
|
238
|
-
await nonld.fix([f020], [f020, f856URNHttps]);
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
// should we actually add non-resolvable urns?
|
|
242
|
-
it('Missing 856, and is non-legal deposit, two 020 fields; Adds 856 with urn from second 020 (https)', async () => {
|
|
243
|
-
await nonld.fix([f020second, f020], [f020second, f020, f856URNHttps]);
|
|
244
|
-
});
|
|
245
|
-
|
|
246
|
-
// should we actually add non resovable urns?
|
|
247
|
-
// we should think about how to choose the isbn to use in case of several ISBNs
|
|
248
|
-
it.skip('Missing 856, and is non-legal deposit, two 020 fields; Adds 856 with urn from first 020 (https)', async () => {
|
|
249
|
-
await nonld.fix([f020, f020second], [f020, f020second, f856URNHttps]);
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
// Fix legal deposit
|
|
253
|
-
it('856 with urn and legal deposit fields, and is legal deposit; Nothing to add', async () => {
|
|
254
|
-
await ld.fix([f020, f856URL, ldf856], [f020, f856URL, ldf856]);
|
|
255
|
-
});
|
|
256
|
-
it('856 with urn and legal deposit fields, and is legal deposit but phrase is old; change phrase to new', async () => {
|
|
257
|
-
await ld.fix([f020, f856URL, ldf856old], [f020, f856URL, ldf856]);
|
|
258
|
-
});
|
|
259
|
-
it('856 without urn, and is legal deposit; Adds 856 with urn (https) and legal deposit fields', async () => {
|
|
260
|
-
await ld.fix([f020, f856URL], [f020, f856URL, ldf856Https]);
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
// we should test generating the URN in case of no ISBN
|
|
264
|
-
|
|
265
|
-
// we should test creating Melinda-temp field
|
|
266
|
-
|
|
267
|
-
// We shouldn't lock the open URN for legal deposit use
|
|
268
|
-
it('Missing 856, and is legal deposit; Adds 856 with urn (https) and legal deposit fields', async () => {
|
|
269
|
-
await ld.fix([f020], [f020, ldf856Https]);
|
|
270
|
-
});
|
|
271
|
-
|
|
272
|
-
// We should actually do this instead of locking the original non-legal deposit URN for legal deposit use
|
|
273
|
-
it.skip('856 with urn, and is legal deposit; Adds another f856 with URN and legal deposit fields', async () => {
|
|
274
|
-
await ld.fix([f020, f856URL, f856URN], [f020, f856URL, f856URN, ldf856Https]);
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
// We should actually add a new urn in case of a non-resource URN
|
|
278
|
-
it.skip('856 with non-resource-urn, and is legal deposit; Adds another f856 with URN and legal deposit fields', async () => {
|
|
279
|
-
await ld.fix([f020, f856URL, f856URNnotResource], [f020, f856URL, f856URNnotResource, ldf856Https]);
|
|
280
|
-
});
|
|
281
|
-
});
|
|
10
|
+
(0, _fixugen.default)({
|
|
11
|
+
callback,
|
|
12
|
+
path: [__dirname, '..', 'test-fixtures', 'urn'],
|
|
13
|
+
useMetadataFile: true,
|
|
14
|
+
recurse: false,
|
|
15
|
+
fixura: {
|
|
16
|
+
reader: _fixura.READERS.JSON
|
|
17
|
+
},
|
|
18
|
+
mocha: {
|
|
19
|
+
before: () => testValidatorFactory()
|
|
20
|
+
}
|
|
282
21
|
});
|
|
22
|
+
const debug = (0, _debug.default)('@natlibfi/marc-record-validators-melinda/urn:test');
|
|
23
|
+
async function testValidatorFactory() {
|
|
24
|
+
const validator = await (0, _urn.default)();
|
|
25
|
+
(0, _chai.expect)(validator).to.be.an('object').that.has.any.keys('description', 'validate');
|
|
26
|
+
(0, _chai.expect)(validator.description).to.be.a('string');
|
|
27
|
+
(0, _chai.expect)(validator.validate).to.be.a('function');
|
|
28
|
+
}
|
|
29
|
+
async function callback({
|
|
30
|
+
getFixture,
|
|
31
|
+
enabled = true,
|
|
32
|
+
fix = true,
|
|
33
|
+
isLegalDeposit = false
|
|
34
|
+
}) {
|
|
35
|
+
if (enabled === false) {
|
|
36
|
+
debug('TEST SKIPPED!');
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const validator = await (0, _urn.default)(isLegalDeposit);
|
|
40
|
+
const record = new _marcRecord.MarcRecord(getFixture('input.json'));
|
|
41
|
+
const expectedResult = getFixture('result.json');
|
|
42
|
+
// console.log(expectedResult); // eslint-disable-line
|
|
43
|
+
|
|
44
|
+
if (!fix) {
|
|
45
|
+
const result = await validator.validate(record);
|
|
46
|
+
(0, _chai.expect)(result).to.eql(expectedResult);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
await validator.fix(record);
|
|
50
|
+
(0, _chai.expect)(record).to.eql(expectedResult);
|
|
51
|
+
}
|
|
283
52
|
//# sourceMappingURL=urn.spec.js.map
|
package/dist/urn.spec.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"urn.spec.js","names":["_chai","require","_marcRecord","_urn","_interopRequireDefault","e","__esModule","default","describe","f337","tag","ind1","ind2","subfields","code","value","f337nonElectronic","ldf856","ldf856old","ldf856Https","ldf856partial","f856URN","f856URNHttps","f856URNnotResource","f856URL","f020","f020second","it","validator","validatorFactory","expect","to","be","an","that","has","any","keys","description","a","validate","test","isLegalDeposit","valid","recfields","result","MarcRecord","fields","eql","fix","resfields","record","nonld","ld","skip"],"sources":["../src/urn.spec.js"],"sourcesContent":["import {expect} from 'chai';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport validatorFactory from '../src/urn';\n\ndescribe('urn', async () => {\n // Fields\n const f337 = {\n tag: '337',\n ind1: ' ',\n ind2: ' ',\n subfields: [\n {code: 'b', value: 'c'},\n {code: '2', value: 'rdamedia'}\n ]\n };\n\n const f337nonElectronic = {\n tag: '337',\n ind1: ' ',\n ind2: ' ',\n subfields: [\n {code: 'b', value: 'n'},\n {code: '2', value: 'rdamedia'}\n ]\n };\n\n const ldf856 = {\n tag: '856',\n ind1: '4',\n ind2: '0',\n subfields: [\n {code: 'u', value: 'http://urn.fi/URN:ISBN:978-951-9155-47-0'},\n {code: 'z', value: 'Käytettävissä vapaakappaletyöasemilla'},\n {code: '5', value: 'FI-Vapaa'}\n ]\n };\n\n const ldf856old = {\n tag: '856',\n ind1: '4',\n ind2: '0',\n subfields: [\n {code: 'u', value: 'http://urn.fi/URN:ISBN:978-951-9155-47-0'},\n {code: 'z', value: 'Käytettävissä vapaakappalekirjastoissa'},\n {code: '5', value: 'FI-Vapaa'}\n ]\n };\n\n const ldf856Https = {\n tag: '856',\n ind1: '4',\n ind2: '0',\n subfields: [\n {code: 'u', value: 'https://urn.fi/URN:ISBN:978-951-9155-47-0'},\n {code: 'z', value: 'Käytettävissä vapaakappaletyöasemilla'},\n {code: '5', value: 'FI-Vapaa'}\n ]\n };\n\n const ldf856partial = {\n tag: '856',\n ind1: '4',\n ind2: '0',\n subfields: [\n {code: 'u', value: 'http://urn.fi/URN:ISBN:978-951-9155-47-0'},\n {code: '5', value: 'FI-Vapaa'}\n ]\n };\n\n const f856URN = {\n tag: '856',\n ind1: '4',\n ind2: '0',\n subfields: [{code: 'u', value: 'http://urn.fi/URN:ISBN:978-951-9155-47-0'}]\n };\n\n const f856URNHttps = {\n tag: '856',\n ind1: '4',\n ind2: '0',\n subfields: [{code: 'u', value: 'https://urn.fi/URN:ISBN:978-951-9155-47-0'}]\n };\n\n const f856URNnotResource = {\n tag: '856',\n ind1: '4',\n ind2: '1',\n subfields: [{code: 'u', value: 'http://urn.fi/URN:ISBN:978-951-9155-47-0'}]\n };\n\n\n const f856URL = {\n tag: '856',\n ind1: '4',\n ind2: '0',\n subfields: [{code: 'u', value: 'http://foo.bar/'}]\n };\n\n const f020 = {\n tag: '020',\n ind1: ' ',\n ind2: ' ',\n subfields: [{code: 'a', value: '978-951-9155-47-0'}]\n };\n\n const f020second = {\n tag: '020',\n ind1: ' ',\n ind2: ' ',\n subfields: [{code: 'a', value: '9789519155470'}]\n };\n\n\n it('Creates a validator', async () => {\n const validator = await validatorFactory();\n\n expect(validator)\n .to.be.an('object')\n .that.has.any.keys('description', 'validate');\n\n expect(validator.description).to.be.a('string');\n expect(validator.validate).to.be.a('function');\n });\n\n // Tests\n const test = async isLegalDeposit => {\n const validator = await validatorFactory(isLegalDeposit);\n return {\n validate: async (valid, ...recfields) => {\n const result = await validator.validate(new MarcRecord({fields: recfields}));\n expect(result).to.eql({valid});\n },\n\n fix: async (recfields, resfields) => {\n const record = new MarcRecord({fields: recfields});\n await validator.fix(record);\n expect(record.fields).to.eql(resfields);\n }\n };\n };\n\n /// Non-legal and legal deposit\n const nonld = await test(false);\n const ld = await test(true);\n\n describe('#validate', () => {\n // Validate non-electoronic\n it('Finds the record valid; non-electronic record', async () => {\n await nonld.validate(true, f337nonElectronic);\n });\n\n // Validate non-legal deposit\n it('Finds the record valid; 856 with urn, and is non-legal deposit', async () => {\n await nonld.validate(true, f337, f856URN);\n });\n\n // we should recognize that 856 with second indicator 1 is not describing the resource itself\n it.skip('Finds the record invalid; 856 ind2: 1 with urn, and is non-legal deposit', async () => {\n await nonld.validate(false, f337, f856URNnotResource);\n });\n\n // should we require urn if we're not handling a legal deposit\n it('Finds the record invalid; 856 without urn, and is non-legal deposit', async () => {\n await nonld.validate(false, f337, f856URL);\n });\n\n\n // should we require urn if we're not handling a legal deposit\n it('Finds the record invalid; Missing 856, and is non-legal deposit', async () => {\n await nonld.validate(false, f337, f020);\n });\n\n // Validate legal deposit\n it('Finds the record invalid; 856 with urn, and is legal deposit', async () => {\n await ld.validate(false, f020, f337, f856URN);\n });\n\n it('Finds the record invalid; 856 without urn, and is legal deposit', async () => {\n await ld.validate(false, f020, f337, f856URL);\n });\n\n it('Finds the record invalid; Missing 856, and is legal deposit', async () => {\n await ld.validate(false, f337, f020);\n });\n\n it('Finds the record valid; 856 with URN and legal deposit subfields, and is legal deposit', async () => {\n await ld.validate(true, f337, f020, ldf856);\n });\n\n it('Finds the record invalid; old phrase is used in $z', async () => {\n await ld.validate(false, f337, f020, ldf856old);\n });\n\n it('Finds the record valid; 856 with URN and legal deposit subfields and other f856s, and is legal deposit', async () => {\n await ld.validate(true, f337, f020, ldf856partial, ldf856, f856URL);\n });\n\n it('Finds the record invalid; 856 with URN and partial legal deposit subfields, and is legal deposit', async () => {\n await ld.validate(false, f337, f020, ldf856partial);\n });\n\n\n });\n\n describe('#fix', () => {\n // Fix non-legal deposit\n it('856 with urn, and is non-legal deposit; Nothing to add', async () => {\n await nonld.fix([f020, f856URL, f856URN], [f020, f856URL, f856URN]);\n });\n\n // should we actually add non-resolvable urns?\n it('856 without urn, and is non-legal deposit; Adds 856 with urn (https)', async () => {\n await nonld.fix([f020, f856URL], [f020, f856URL, f856URNHttps]);\n });\n\n // should we actually add non-resolvable urns?\n it('Missing 856, and is non-legal deposit; Adds 856 with urn (https)', async () => {\n await nonld.fix([f020], [f020, f856URNHttps]);\n });\n\n // should we actually add non-resolvable urns?\n it('Missing 856, and is non-legal deposit, two 020 fields; Adds 856 with urn from second 020 (https)', async () => {\n await nonld.fix([f020second, f020], [f020second, f020, f856URNHttps]);\n });\n\n // should we actually add non resovable urns?\n // we should think about how to choose the isbn to use in case of several ISBNs\n it.skip('Missing 856, and is non-legal deposit, two 020 fields; Adds 856 with urn from first 020 (https)', async () => {\n await nonld.fix([f020, f020second], [f020, f020second, f856URNHttps]);\n });\n\n\n // Fix legal deposit\n it('856 with urn and legal deposit fields, and is legal deposit; Nothing to add', async () => {\n await ld.fix([f020, f856URL, ldf856], [f020, f856URL, ldf856]);\n });\n\n it('856 with urn and legal deposit fields, and is legal deposit but phrase is old; change phrase to new', async () => {\n await ld.fix([f020, f856URL, ldf856old], [f020, f856URL, ldf856]);\n });\n\n it('856 without urn, and is legal deposit; Adds 856 with urn (https) and legal deposit fields', async () => {\n await ld.fix([f020, f856URL], [f020, f856URL, ldf856Https]);\n });\n\n // we should test generating the URN in case of no ISBN\n\n // we should test creating Melinda-temp field\n\n // We shouldn't lock the open URN for legal deposit use\n it('Missing 856, and is legal deposit; Adds 856 with urn (https) and legal deposit fields', async () => {\n await ld.fix([f020], [f020, ldf856Https]);\n });\n\n // We should actually do this instead of locking the original non-legal deposit URN for legal deposit use\n it.skip('856 with urn, and is legal deposit; Adds another f856 with URN and legal deposit fields', async () => {\n await ld.fix([f020, f856URL, f856URN], [f020, f856URL, f856URN, ldf856Https]);\n });\n\n // We should actually add a new urn in case of a non-resource URN\n it.skip('856 with non-resource-urn, and is legal deposit; Adds another f856 with URN and legal deposit fields', async () => {\n await ld.fix([f020, f856URL, f856URNnotResource], [f020, f856URL, f856URNnotResource, ldf856Https]);\n });\n\n\n });\n});\n"],"mappings":";;AAAA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,IAAA,GAAAC,sBAAA,CAAAH,OAAA;AAA0C,SAAAG,uBAAAC,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAE1CG,QAAQ,CAAC,KAAK,EAAE,YAAY;EAC1B;EACA,MAAMC,IAAI,GAAG;IACXC,GAAG,EAAE,KAAK;IACVC,IAAI,EAAE,GAAG;IACTC,IAAI,EAAE,GAAG;IACTC,SAAS,EAAE,CAC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YAAY;MAC1G,MAAM0B,EAAE,CAACJ,GAAG,CAAC,CAACxB,IAAI,EAAED,OAAO,CAAC,EAAE,CAACC,IAAI,EAAED,OAAO,EAAEL,WAAW,CAAC,CAAC;IAC7D,CAAC,CAAC;;IAEF;;IAEA;;IAEA;IACAQ,EAAE,CAAC,uFAAuF,EAAE,YAAY;MACtG,MAAM0B,EAAE,CAACJ,GAAG,CAAC,CAACxB,IAAI,CAAC,EAAE,CAACA,IAAI,EAAEN,WAAW,CAAC,CAAC;IAC3C,CAAC,CAAC;;IAEF;IACAQ,EAAE,CAAC2B,IAAI,CAAC,yFAAyF,EAAE,YAAY;MAC7G,MAAMD,EAAE,CAACJ,GAAG,CAAC,CAACxB,IAAI,EAAED,OAAO,EAAEH,OAAO,CAAC,EAAE,CAACI,IAAI,EAAED,OAAO,EAAEH,OAAO,EAAEF,WAAW,CAAC,CAAC;IAC/E,CAAC,CAAC;;IAEF;IACAQ,EAAE,CAAC2B,IAAI,CAAC,sGAAsG,EAAE,YAAY;MAC1H,MAAMD,EAAE,CAACJ,GAAG,CAAC,CAACxB,IAAI,EAAED,OAAO,EAAED,kBAAkB,CAAC,EAAE,CAACE,IAAI,EAAED,OAAO,EAAED,kBAAkB,EAAEJ,WAAW,CAAC,CAAC;IACrG,CAAC,CAAC;EAGJ,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"urn.spec.js","names":["_chai","require","_marcRecord","_urn","_interopRequireDefault","_fixura","_fixugen","_debug","e","__esModule","default","generateTests","callback","path","__dirname","useMetadataFile","recurse","fixura","reader","READERS","JSON","mocha","before","testValidatorFactory","debug","createDebugLogger","validator","validatorFactory","expect","to","be","an","that","has","any","keys","description","a","validate","getFixture","enabled","fix","isLegalDeposit","record","MarcRecord","expectedResult","result","eql"],"sources":["../src/urn.spec.js"],"sourcesContent":["import {expect} from 'chai';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport validatorFactory from './urn';\nimport {READERS} from '@natlibfi/fixura';\nimport generateTests from '@natlibfi/fixugen';\nimport createDebugLogger from 'debug';\n\ngenerateTests({\n callback,\n path: [__dirname, '..', 'test-fixtures', 'urn'],\n useMetadataFile: true,\n recurse: false,\n fixura: {\n reader: READERS.JSON\n },\n mocha: {\n before: () => testValidatorFactory()\n }\n});\nconst debug = createDebugLogger('@natlibfi/marc-record-validators-melinda/urn:test');\n\nasync function testValidatorFactory() {\n const validator = await validatorFactory();\n\n expect(validator)\n .to.be.an('object')\n .that.has.any.keys('description', 'validate');\n\n expect(validator.description).to.be.a('string');\n expect(validator.validate).to.be.a('function');\n}\n\nasync function callback({getFixture, enabled = true, fix = true, isLegalDeposit = false}) {\n if (enabled === false) {\n debug('TEST SKIPPED!');\n return;\n }\n\n const validator = await validatorFactory(isLegalDeposit);\n const record = new MarcRecord(getFixture('input.json'));\n const expectedResult = getFixture('result.json');\n // console.log(expectedResult); // eslint-disable-line\n\n if (!fix) {\n const result = await validator.validate(record);\n expect(result).to.eql(expectedResult);\n return;\n }\n\n await validator.fix(record);\n expect(record).to.eql(expectedResult);\n}\n"],"mappings":";;AAAA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,IAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AACA,IAAAK,QAAA,GAAAF,sBAAA,CAAAH,OAAA;AACA,IAAAM,MAAA,GAAAH,sBAAA,CAAAH,OAAA;AAAsC,SAAAG,uBAAAI,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAEtC,IAAAG,gBAAa,EAAC;EACZC,QAAQ;EACRC,IAAI,EAAE,CAACC,SAAS,EAAE,IAAI,EAAE,eAAe,EAAE,KAAK,CAAC;EAC/CC,eAAe,EAAE,IAAI;EACrBC,OAAO,EAAE,KAAK;EACdC,MAAM,EAAE;IACNC,MAAM,EAAE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ACF,cAAc,CAAC;IACrC;EACF;EAEA,MAAMnB,SAAS,CAACe,GAAG,CAACE,MAAM,CAAC;EAC3B,IAAAf,YAAM,EAACe,MAAM,CAAC,CAACd,EAAE,CAACkB,GAAG,CAACF,cAAc,CAAC;AACvC","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"url": "git@github.com:natlibfi/marc-record-validators-melinda.git"
|
|
15
15
|
},
|
|
16
16
|
"license": "MIT",
|
|
17
|
-
"version": "11.3.
|
|
17
|
+
"version": "11.3.7-alpha.1",
|
|
18
18
|
"main": "./dist/index.js",
|
|
19
19
|
"publishConfig": {
|
|
20
20
|
"access": "public"
|
|
@@ -37,15 +37,15 @@
|
|
|
37
37
|
"cover:report": "nyc report"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@babel/register": "^7.
|
|
40
|
+
"@babel/register": "^7.25.7",
|
|
41
41
|
"@natlibfi/issn-verify": "^1.0.4",
|
|
42
|
-
"@natlibfi/marc-record": "^9.0.
|
|
42
|
+
"@natlibfi/marc-record": "^9.0.2",
|
|
43
43
|
"@natlibfi/marc-record-validate": "^8.0.10",
|
|
44
44
|
"cld3-asm": "^3.1.1",
|
|
45
45
|
"clone": "^2.1.2",
|
|
46
46
|
"debug": "^4.3.7",
|
|
47
47
|
"iso9_1995": "^0.0.2",
|
|
48
|
-
"isbn3": "^1.2.
|
|
48
|
+
"isbn3": "^1.2.2",
|
|
49
49
|
"langs": "^2.0.0",
|
|
50
50
|
"node-fetch": "^2.7.0",
|
|
51
51
|
"sfs4900": "^0.0.1",
|
|
@@ -56,19 +56,19 @@
|
|
|
56
56
|
"@natlibfi/marc-record-validate": "^8.0.10"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@babel/cli": "^7.25.
|
|
60
|
-
"@babel/core": "^7.25.
|
|
61
|
-
"@babel/preset-env": "^7.25.
|
|
59
|
+
"@babel/cli": "^7.25.7",
|
|
60
|
+
"@babel/core": "^7.25.8",
|
|
61
|
+
"@babel/preset-env": "^7.25.8",
|
|
62
62
|
"@natlibfi/eslint-config-melinda-backend": "^3.0.5",
|
|
63
|
-
"@natlibfi/fixugen": "^2.0.
|
|
64
|
-
"@natlibfi/fixura": "^3.0.
|
|
63
|
+
"@natlibfi/fixugen": "^2.0.10",
|
|
64
|
+
"@natlibfi/fixura": "^3.0.10",
|
|
65
65
|
"babel-plugin-istanbul": "^7.0.0",
|
|
66
66
|
"babel-plugin-rewire": "^1.2.0",
|
|
67
67
|
"chai": "^4.5.0",
|
|
68
68
|
"chai-as-promised": "^7.1.2",
|
|
69
69
|
"cross-env": "^7.0.3",
|
|
70
70
|
"eslint": "^8.57.1",
|
|
71
|
-
"fetch-mock": "^11.1.
|
|
71
|
+
"fetch-mock": "^11.1.5",
|
|
72
72
|
"mocha": "^10.7.3",
|
|
73
73
|
"nyc": "^17.1.0"
|
|
74
74
|
},
|
package/src/punctuation2.js
CHANGED
|
@@ -91,6 +91,8 @@ const defaultNeedsPuncAfter2 = /(?:[\]a-zA-Z0-9)]|ä|å|ö|Å|Ä|Ö)$/u;
|
|
|
91
91
|
const doesNotEndInPunc = /[^!?.:;,]$/u; // non-punc for pre-240/700/XXX $, note that '.' comes if preceded by ')'
|
|
92
92
|
const blocksPuncRHS = /^(?:\()/u;
|
|
93
93
|
const allowsPuncRHS = /^(?:[A-Za-z0-9]|å|ä|ö|Å|Ä|Ö)/u;
|
|
94
|
+
const aToZ = 'abcdefghijklmnopqrstuvwxyz';
|
|
95
|
+
|
|
94
96
|
|
|
95
97
|
const dotIsProbablyPunc = /(?:[a-z0-9)]|å|ä|ö|(?:[A-Za-z0-9]|Å|Ä|Ö)(?:[A-Z]|Å|Ä|Ö))\.$/u;
|
|
96
98
|
const puncIsProbablyPunc = /(?:[a-z0-9)]|å|ä|ö) ?[.,:;]$/u;
|
|
@@ -146,7 +148,11 @@ const removeX30Whatever = removeCrapFromAllEntryFields;
|
|
|
146
148
|
|
|
147
149
|
const remove490And830Whatever = [{'code': 'axyzv', 'followedBy': 'axyzv', 'remove': /(?: *;| *=|,)$/u}];
|
|
148
150
|
|
|
149
|
-
const
|
|
151
|
+
const linkingEntryRemoveWhatever = [
|
|
152
|
+
{'code': 'i', 'followedBy': 'at', 'remove': / ?:$/u}, // ':'
|
|
153
|
+
{'code': 'at', 'remove': /\.$/u},
|
|
154
|
+
{'code': 'abdghiklmnopqrstuwxyz', 'followedBy': 'abdghiklmnopqrstuwxyz', 'remove': /\. -$/u}
|
|
155
|
+
];
|
|
150
156
|
|
|
151
157
|
|
|
152
158
|
// '!' means negation, thus '!b' means any other subfield but 'b'.
|
|
@@ -193,9 +199,10 @@ const cleanCrappyPunctuationRules = {
|
|
|
193
199
|
'710': removeX10Whatever,
|
|
194
200
|
'711': removeX11Whatever,
|
|
195
201
|
'730': removeX30Whatever,
|
|
196
|
-
'773':
|
|
197
|
-
'774':
|
|
198
|
-
'776':
|
|
202
|
+
'773': linkingEntryRemoveWhatever,
|
|
203
|
+
'774': linkingEntryRemoveWhatever,
|
|
204
|
+
'776': linkingEntryRemoveWhatever,
|
|
205
|
+
'787': linkingEntryRemoveWhatever,
|
|
199
206
|
'800': removeX00Whatever,
|
|
200
207
|
'810': removeX10Whatever,
|
|
201
208
|
'830': remove490And830Whatever,
|
|
@@ -316,6 +323,12 @@ const addSeriesTitle = [ // 490 and 830
|
|
|
316
323
|
addSemicolonBeforeVolumeDesignation // eg. 490$axyz-$v
|
|
317
324
|
];
|
|
318
325
|
|
|
326
|
+
const addLinkingEntry = [ // NB! Music 773 uses different punctuation rules, that are not implement here (can they even be?)
|
|
327
|
+
{'code': 'i', 'followedBy': aToZ, 'add': ':', 'context': defaultNeedsPuncAfter2},
|
|
328
|
+
{'code': 'a', 'followedBy': 't', 'add': '.', 'context': defaultNeedsPuncAfter2},
|
|
329
|
+
{'code': 't', 'followedBy': 'dghoz', 'add': '.', 'context': defaultNeedsPuncAfter2}
|
|
330
|
+
];
|
|
331
|
+
|
|
319
332
|
const addPairedPunctuationRules = {
|
|
320
333
|
'100': addX00,
|
|
321
334
|
'110': addX10,
|
|
@@ -355,6 +368,8 @@ const addPairedPunctuationRules = {
|
|
|
355
368
|
'710': addX10,
|
|
356
369
|
'711': addX11,
|
|
357
370
|
'730': addX30,
|
|
371
|
+
'773': addLinkingEntry,
|
|
372
|
+
'787': addLinkingEntry,
|
|
358
373
|
'800': addX00,
|
|
359
374
|
'810': addX10,
|
|
360
375
|
'811': addX11,
|
|
@@ -485,23 +500,23 @@ function applyPunctuationRules(field, subfield1, subfield2, ruleArray = null, op
|
|
|
485
500
|
|
|
486
501
|
//nvdebug(`OP=${operation} ${tag2}: '${subfield1.code}: ${subfield1.value}' ??? '${subfield2 ? subfield2.code : '#'}'`);
|
|
487
502
|
const candRules = ruleArray[tag2];
|
|
488
|
-
candRules.
|
|
503
|
+
candRules.every(rule => { // uses "every", not "forEach", so that only one rule is applies to the given subfields
|
|
489
504
|
//debugRule(rule);
|
|
490
|
-
//nvdebug(' WP1');
|
|
491
505
|
if (!checkRule(rule, field, subfield1, subfield2)) {
|
|
492
|
-
return;
|
|
506
|
+
return true;
|
|
493
507
|
}
|
|
494
|
-
//nvdebug(' WP2');
|
|
495
508
|
|
|
496
509
|
//const originalValue = subfield1.value;
|
|
497
|
-
if (rule.remove && [REMOVE, REMOVE_AND_ADD].includes(operation) && subfield1.value.match(rule.remove)) {
|
|
510
|
+
if (rule.remove && [REMOVE, REMOVE_AND_ADD].includes(operation) && subfield1.value.match(rule.remove)) {
|
|
498
511
|
//nvdebug(` PUNC REMOVAL TO BE PERFORMED FOR $${subfield1.code} '${subfield1.value}'`, debug);
|
|
499
512
|
subfield1.value = subfield1.value.replace(rule.remove, ''); // eslint-disable-line functional/immutable-data
|
|
500
513
|
//nvdebug(` PUNC REMOVAL PERFORMED FOR '${subfield1.value}'`);
|
|
514
|
+
return false;
|
|
501
515
|
}
|
|
502
|
-
if (rule.add && [ADD, REMOVE_AND_ADD].includes(operation)) {
|
|
516
|
+
if (rule.add && [ADD, REMOVE_AND_ADD].includes(operation)) {
|
|
503
517
|
subfield1.value += rule.add; // eslint-disable-line functional/immutable-data
|
|
504
518
|
//nvdebug(` ADDED '${rule.add}' TO FORM '${subfield1.value}'`);
|
|
519
|
+
return false;
|
|
505
520
|
}
|
|
506
521
|
|
|
507
522
|
/*
|
|
@@ -509,6 +524,8 @@ function applyPunctuationRules(field, subfield1, subfield2, ruleArray = null, op
|
|
|
509
524
|
nvdebug(` PROCESS PUNC: '‡${subfield1.code} ${originalValue}' => '‡${subfield1.code} ${subfield1.value}'`, debug); // eslint-disable-line functional/immutable-data
|
|
510
525
|
}
|
|
511
526
|
*/
|
|
527
|
+
|
|
528
|
+
return true;
|
|
512
529
|
});
|
|
513
530
|
}
|
|
514
531
|
|
package/src/urn.js
CHANGED
|
@@ -8,12 +8,26 @@ export default function (isLegalDeposit = false, useMelindaTemp = true) {
|
|
|
8
8
|
const debug = createDebugLogger('@natlibfi/marc-record-validators-melinda:urn');
|
|
9
9
|
const debugData = debug.extend('data');
|
|
10
10
|
|
|
11
|
+
//console.log(`IS LEGAL DEPOSIT? ${isLegalDeposit ? 'YES' : 'NO'}`); // eslint-disable-line no-console
|
|
12
|
+
|
|
11
13
|
// We should check that the f856 with URN has second indicator '0' (Resource), ' ' (No information provided) or '8' (No display constant generated)
|
|
12
14
|
// - if second indicator is '1' (Version of resource) or '2' (Related resource) the URN in f856 is not correct for the resource described in the record
|
|
13
15
|
|
|
14
16
|
// This checks only the existence of URNs from the Finnish urn.fi -resolver
|
|
15
17
|
|
|
16
|
-
|
|
18
|
+
function hasLegalDepositURN(field) {
|
|
19
|
+
if (field.tag !== '856' || ['1', '2', '3', '4'].includes(field.ind2)) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// First attempt to fix MET-573. However, does useMelindaTemp come into play as well?
|
|
24
|
+
if (isLegalDeposit && !field.subfields.some(sf => sf.code === '5' && sf.value === 'FI-Vapaa')) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return field.subfields.some(sf => sf.code === 'u' && (/^https?:\/\/urn\.fi/u).test(sf.value));
|
|
29
|
+
}
|
|
30
|
+
|
|
17
31
|
|
|
18
32
|
return {
|
|
19
33
|
description: 'Adds URN for record, to 856-field (if not existing). If isLegalDeposit is active, adds legal deposit subfields to the f856s with URN.',
|
|
@@ -22,7 +36,7 @@ export default function (isLegalDeposit = false, useMelindaTemp = true) {
|
|
|
22
36
|
};
|
|
23
37
|
|
|
24
38
|
async function fix(record) {
|
|
25
|
-
const f856sUrn = record.fields.filter(
|
|
39
|
+
const f856sUrn = record.fields.filter(hasLegalDepositURN);
|
|
26
40
|
debugData(`f856sUrn: ${JSON.stringify(f856sUrn)}`);
|
|
27
41
|
|
|
28
42
|
const ldSubfields = isLegalDeposit ? createLDSubfields() : [];
|
|
@@ -163,7 +177,7 @@ export default function (isLegalDeposit = false, useMelindaTemp = true) {
|
|
|
163
177
|
return {valid: true};
|
|
164
178
|
}
|
|
165
179
|
|
|
166
|
-
const f856sUrn = record.fields.filter(
|
|
180
|
+
const f856sUrn = record.fields.filter(hasLegalDepositURN);
|
|
167
181
|
|
|
168
182
|
if (f856sUrn.length > 0) {
|
|
169
183
|
debug(`Record has ${f856sUrn.length} URN fields`);
|