@natlibfi/marc-record-validators-melinda 11.3.5 → 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/cyrillux.js +1 -1
- package/dist/cyrillux.js.map +1 -1
- 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/cyrillux.js +1 -1
- 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 +130 -0
- package/test-fixtures/cyrillux/f09/metadata.json +10 -0
- package/test-fixtures/cyrillux/f09/record.json +104 -0
- 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.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"urn.js","names":["_nodeFetch","_interopRequireDefault","require","_utils","_debug","e","__esModule","default","URN_GENERATOR_URL","_default","isLegalDeposit","useMelindaTemp","debug","createDebugLogger","debugData","extend","hasURN","f","tag","subfields","some","code","value","test","description","validate","fix","record","f856sUrn","fields","filter","JSON","stringify","ldSubfields","createLDSubfields","length","generated","createURNSubfield","tempSubField","insertField","ind1","ind2","forEach","sf","hasOld856LdPhrase","find","ldsf","push","rec","isbn","reduce","acc","a","undefined","createURN","response","fetch","body","text","fieldHasLDSubfields","field","every","validateLD","f856sUrnWithLdSubfields","isElectronicMaterial","valid"],"sources":["../src/urn.js"],"sourcesContent":["import fetch from 'node-fetch';\nimport {isElectronicMaterial} from './utils';\nimport createDebugLogger from 'debug';\n\nconst URN_GENERATOR_URL = 'https://generator.urn.fi/cgi-bin/urn_generator.cgi?type=nbn';\n\nexport default function (isLegalDeposit = false, useMelindaTemp = true) {\n const debug = createDebugLogger('@natlibfi/marc-record-validators-melinda:urn');\n const debugData = debug.extend('data');\n\n // We should check that the f856 with URN has second indicator '0' (Resource), ' ' (No information provided) or '8' (No display constant generated)\n // - 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\n\n // This checks only the existence of URNs from the Finnish urn.fi -resolver\n\n const hasURN = f => f.tag === '856' && f.subfields.some(({code, value}) => code === 'u' && (/urn.fi/u).test(value));\n\n return {\n description: 'Adds URN for record, to 856-field (if not existing). If isLegalDeposit is active, adds legal deposit subfields to the f856s with URN.',\n validate,\n fix\n };\n\n async function fix(record) {\n const f856sUrn = record.fields.filter(hasURN);\n debugData(`f856sUrn: ${JSON.stringify(f856sUrn)}`);\n\n const ldSubfields = isLegalDeposit ? createLDSubfields() : [];\n debugData(`IsLegalDeposit: ${isLegalDeposit}, LegalDepositSubfields: ${JSON.stringify(ldSubfields)}`);\n\n // We add the URN even if we're not getting the legalDeposit - where does this URN resolve?\n // We probably should not do these additions\n\n if (f856sUrn.length === 0) { // eslint-disable-line functional/no-conditional-statements\n const {code, value, generated} = await createURNSubfield(record);\n\n if (generated && useMelindaTemp) {\n const tempSubField = {code: '9', value: 'MELINDA<TEMP>'};\n\n record.insertField({\n tag: '856',\n ind1: '4',\n ind2: '0',\n subfields: [{code, value}, ...ldSubfields, tempSubField]\n });\n\n return true;\n }\n\n record.insertField({\n tag: '856',\n ind1: '4',\n ind2: '0',\n subfields: [{code, value}, ...ldSubfields]\n });\n\n return true;\n } else if (isLegalDeposit) { // eslint-disable-line functional/no-conditional-statements\n\n // We add here legal deposit information to all URN-f856s - we probably should not do this\n // We should add extra f856 URN / URNs for legal deposits that already have a open (non-legal-deposit) URN\n // How do we decide which URN to use as a template if there are several URNs\n // We should check for existence of a legal deposit URN anyways\n\n f856sUrn.forEach(f => {\n // Change phrase from old to new if field with old phrase is found\n if (f.subfields.some(sf => hasOld856LdPhrase(sf))) { // eslint-disable-line functional/no-conditional-statements\n f.subfields // eslint-disable-line functional/immutable-data\n .find(sf => hasOld856LdPhrase(sf))\n .value = 'Käytettävissä vapaakappaletyöasemilla';\n }\n\n // Create subfields if necessary\n ldSubfields.forEach(ldsf => {\n if (!f.subfields.some(sf => sf.code === ldsf.code && sf.value === ldsf.value && !hasOld856LdPhrase(sf))) { // eslint-disable-line functional/no-conditional-statements\n f.subfields.push(ldsf); // eslint-disable-line functional/immutable-data\n }\n });\n });\n }\n\n return true;\n\n // We should check existence of URN in f024 i1: '7' $2 urn/URN for this too\n\n async function createURNSubfield(rec) {\n // isbn is picked from the last 020 $a in the record\n // what should we do in case of several 020 $a:s\n const isbn = rec.fields.reduce((acc, f) => {\n if (f.tag === '020') {\n const a = f.subfields.find(sf => sf.code === 'a');\n return a ? a.value : undefined;\n }\n\n return acc;\n }, undefined);\n\n debugData(`isbns: ${isbn}`);\n\n const {generated, value} = await createURN(isbn);\n return {code: 'u', value, generated};\n\n async function createURN(isbn = false) {\n if (isbn) {\n return {generated: false, value: `https://urn.fi/URN:ISBN:${isbn}`};\n }\n\n const response = await fetch(URN_GENERATOR_URL);\n const body = await response.text();\n\n // If we generated URN we could also add it to the 024\n // generated 024 should also have $9 MELINDA<TEMP>\n return {generated: true, value: `https://urn.fi/${body}`};\n }\n }\n\n function hasOld856LdPhrase({code, value}) {\n if (code === 'z' && value === 'Käytettävissä vapaakappalekirjastoissa') {\n return true;\n }\n\n return false;\n }\n\n }\n\n // Later when the new subfields that have f506/f540 -type contents, we should add also them here\n function createLDSubfields() {\n return [\n {\n code: 'z',\n value: 'Käytettävissä vapaakappaletyöasemilla'\n },\n {\n code: '5',\n value: 'FI-Vapaa'\n }\n ];\n }\n\n function fieldHasLDSubfields(field, ldSubfields) {\n if (ldSubfields.every(ldsf => field.subfields.some(sf => sf.code === ldsf.code && sf.value === ldsf.value))) {\n return true;\n }\n }\n\n function validateLD(f856sUrn) {\n debug(`Validating the existence of legal deposit subfields`);\n const ldSubfields = createLDSubfields();\n const f856sUrnWithLdSubfields = f856sUrn.filter(field => fieldHasLDSubfields(field, ldSubfields));\n if (f856sUrnWithLdSubfields.length > 0) {\n debug(`Record has ${f856sUrnWithLdSubfields.length} URN fields with all necessary legal deposit subfields`);\n debugData(`f856sUrnWithLdSubfields: ${JSON.stringify(f856sUrnWithLdSubfields)}`);\n return true;\n }\n return false;\n }\n\n function validate(record) {\n // if not electronic skip this validator\n if (!isElectronicMaterial(record)) {\n debug(`Record is not electronic - no need to validate legal deposit URNs`);\n return {valid: true};\n }\n\n const f856sUrn = record.fields.filter(hasURN);\n\n if (f856sUrn.length > 0) {\n debug(`Record has ${f856sUrn.length} URN fields`);\n debugData(`f856sUrn: ${JSON.stringify(f856sUrn)}`);\n\n if (!isLegalDeposit || validateLD(f856sUrn)) {\n debug(`Record is valid`);\n return {valid: true};\n }\n }\n debug(`No (valid) URN fields - Record is not valid`);\n return {valid: false};\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,UAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAH,sBAAA,CAAAC,OAAA;AAAsC,SAAAD,uBAAAI,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAEtC,MAAMG,iBAAiB,GAAG,6DAA6D;AAExE,SAAAC,SAAUC,cAAc,GAAG,KAAK,EAAEC,cAAc,GAAG,IAAI,EAAE;EACtE,MAAMC,KAAK,GAAG,IAAAC,cAAiB,EAAC,8CAA8C,CAAC;EAC/E,MAAMC,SAAS,G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MAElD,IAAI,CAAClB,cAAc,IAAIoD,UAAU,CAAClC,QAAQ,CAAC,EAAE;QAC3ChB,KAAK,CAAC,iBAAiB,CAAC;QACxB,OAAO;UAACqD,KAAK,EAAE;QAAI,CAAC;MACtB;IACF;IACArD,KAAK,CAAC,6CAA6C,CAAC;IACpD,OAAO;MAACqD,KAAK,EAAE;IAAK,CAAC;EACvB;AACF","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"urn.js","names":["_nodeFetch","_interopRequireDefault","require","_utils","_debug","e","__esModule","default","URN_GENERATOR_URL","_default","isLegalDeposit","useMelindaTemp","debug","createDebugLogger","debugData","extend","hasLegalDepositURN","field","tag","includes","ind2","subfields","some","sf","code","value","test","description","validate","fix","record","f856sUrn","fields","filter","JSON","stringify","ldSubfields","createLDSubfields","length","generated","createURNSubfield","tempSubField","insertField","ind1","forEach","f","hasOld856LdPhrase","find","ldsf","push","rec","isbn","reduce","acc","a","undefined","createURN","response","fetch","body","text","fieldHasLDSubfields","every","validateLD","f856sUrnWithLdSubfields","isElectronicMaterial","valid"],"sources":["../src/urn.js"],"sourcesContent":["import fetch from 'node-fetch';\nimport {isElectronicMaterial} from './utils';\nimport createDebugLogger from 'debug';\n\nconst URN_GENERATOR_URL = 'https://generator.urn.fi/cgi-bin/urn_generator.cgi?type=nbn';\n\nexport default function (isLegalDeposit = false, useMelindaTemp = true) {\n const debug = createDebugLogger('@natlibfi/marc-record-validators-melinda:urn');\n const debugData = debug.extend('data');\n\n //console.log(`IS LEGAL DEPOSIT? ${isLegalDeposit ? 'YES' : 'NO'}`); // eslint-disable-line no-console\n\n // We should check that the f856 with URN has second indicator '0' (Resource), ' ' (No information provided) or '8' (No display constant generated)\n // - 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\n\n // This checks only the existence of URNs from the Finnish urn.fi -resolver\n\n function hasLegalDepositURN(field) {\n if (field.tag !== '856' || ['1', '2', '3', '4'].includes(field.ind2)) {\n return false;\n }\n\n // First attempt to fix MET-573. However, does useMelindaTemp come into play as well?\n if (isLegalDeposit && !field.subfields.some(sf => sf.code === '5' && sf.value === 'FI-Vapaa')) {\n return false;\n }\n\n return field.subfields.some(sf => sf.code === 'u' && (/^https?:\\/\\/urn\\.fi/u).test(sf.value));\n }\n\n\n return {\n description: 'Adds URN for record, to 856-field (if not existing). If isLegalDeposit is active, adds legal deposit subfields to the f856s with URN.',\n validate,\n fix\n };\n\n async function fix(record) {\n const f856sUrn = record.fields.filter(hasLegalDepositURN);\n debugData(`f856sUrn: ${JSON.stringify(f856sUrn)}`);\n\n const ldSubfields = isLegalDeposit ? createLDSubfields() : [];\n debugData(`IsLegalDeposit: ${isLegalDeposit}, LegalDepositSubfields: ${JSON.stringify(ldSubfields)}`);\n\n // We add the URN even if we're not getting the legalDeposit - where does this URN resolve?\n // We probably should not do these additions\n\n if (f856sUrn.length === 0) { // eslint-disable-line functional/no-conditional-statements\n const {code, value, generated} = await createURNSubfield(record);\n\n if (generated && useMelindaTemp) {\n const tempSubField = {code: '9', value: 'MELINDA<TEMP>'};\n\n record.insertField({\n tag: '856',\n ind1: '4',\n ind2: '0',\n subfields: [{code, value}, ...ldSubfields, tempSubField]\n });\n\n return true;\n }\n\n record.insertField({\n tag: '856',\n ind1: '4',\n ind2: '0',\n subfields: [{code, value}, ...ldSubfields]\n });\n\n return true;\n } else if (isLegalDeposit) { // eslint-disable-line functional/no-conditional-statements\n\n // We add here legal deposit information to all URN-f856s - we probably should not do this\n // We should add extra f856 URN / URNs for legal deposits that already have a open (non-legal-deposit) URN\n // How do we decide which URN to use as a template if there are several URNs\n // We should check for existence of a legal deposit URN anyways\n\n f856sUrn.forEach(f => {\n // Change phrase from old to new if field with old phrase is found\n if (f.subfields.some(sf => hasOld856LdPhrase(sf))) { // eslint-disable-line functional/no-conditional-statements\n f.subfields // eslint-disable-line functional/immutable-data\n .find(sf => hasOld856LdPhrase(sf))\n .value = 'Käytettävissä vapaakappaletyöasemilla';\n }\n\n // Create subfields if necessary\n ldSubfields.forEach(ldsf => {\n if (!f.subfields.some(sf => sf.code === ldsf.code && sf.value === ldsf.value && !hasOld856LdPhrase(sf))) { // eslint-disable-line functional/no-conditional-statements\n f.subfields.push(ldsf); // eslint-disable-line functional/immutable-data\n }\n });\n });\n }\n\n return true;\n\n // We should check existence of URN in f024 i1: '7' $2 urn/URN for this too\n\n async function createURNSubfield(rec) {\n // isbn is picked from the last 020 $a in the record\n // what should we do in case of several 020 $a:s\n const isbn = rec.fields.reduce((acc, f) => {\n if (f.tag === '020') {\n const a = f.subfields.find(sf => sf.code === 'a');\n return a ? a.value : undefined;\n }\n\n return acc;\n }, undefined);\n\n debugData(`isbns: ${isbn}`);\n\n const {generated, value} = await createURN(isbn);\n return {code: 'u', value, generated};\n\n async function createURN(isbn = false) {\n if (isbn) {\n return {generated: false, value: `https://urn.fi/URN:ISBN:${isbn}`};\n }\n\n const response = await fetch(URN_GENERATOR_URL);\n const body = await response.text();\n\n // If we generated URN we could also add it to the 024\n // generated 024 should also have $9 MELINDA<TEMP>\n return {generated: true, value: `https://urn.fi/${body}`};\n }\n }\n\n function hasOld856LdPhrase({code, value}) {\n if (code === 'z' && value === 'Käytettävissä vapaakappalekirjastoissa') {\n return true;\n }\n\n return false;\n }\n\n }\n\n // Later when the new subfields that have f506/f540 -type contents, we should add also them here\n function createLDSubfields() {\n return [\n {\n code: 'z',\n value: 'Käytettävissä vapaakappaletyöasemilla'\n },\n {\n code: '5',\n value: 'FI-Vapaa'\n }\n ];\n }\n\n function fieldHasLDSubfields(field, ldSubfields) {\n if (ldSubfields.every(ldsf => field.subfields.some(sf => sf.code === ldsf.code && sf.value === ldsf.value))) {\n return true;\n }\n }\n\n function validateLD(f856sUrn) {\n debug(`Validating the existence of legal deposit subfields`);\n const ldSubfields = createLDSubfields();\n const f856sUrnWithLdSubfields = f856sUrn.filter(field => fieldHasLDSubfields(field, ldSubfields));\n if (f856sUrnWithLdSubfields.length > 0) {\n debug(`Record has ${f856sUrnWithLdSubfields.length} URN fields with all necessary legal deposit subfields`);\n debugData(`f856sUrnWithLdSubfields: ${JSON.stringify(f856sUrnWithLdSubfields)}`);\n return true;\n }\n return false;\n }\n\n function validate(record) {\n // if not electronic skip this validator\n if (!isElectronicMaterial(record)) {\n debug(`Record is not electronic - no need to validate legal deposit URNs`);\n return {valid: true};\n }\n\n const f856sUrn = record.fields.filter(hasLegalDepositURN);\n\n if (f856sUrn.length > 0) {\n debug(`Record has ${f856sUrn.length} URN fields`);\n debugData(`f856sUrn: ${JSON.stringify(f856sUrn)}`);\n\n if (!isLegalDeposit || validateLD(f856sUrn)) {\n debug(`Record is valid`);\n return {valid: true};\n }\n }\n debug(`No (valid) URN fields - Record is not valid`);\n return {valid: false};\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,UAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAH,sBAAA,CAAAC,OAAA;AAAsC,SAAAD,uBAAAI,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAEtC,MAAMG,iBAAiB,GAAG,6DAA6D;AAExE,SAAAC,SAAUC,cAAc,GAAG,KAAK,EAAEC,cAAc,GAAG,IAAI,EAAE;EACtE,MAAMC,KAAK,GAAG,IAAAC,cAAiB,EAAC,8CAA8C,CAAC;EAC/E,MAAMC,SAAS,GAAGF,KAAK,CAACG,MAAM,CAAC,MAAM,CAAC;;EAEtC;;EAEA;EACA;;EAEA;;EAEA,SAASC,kBAAkBA,CAACC,KAAK,EAAE;IACjC,IAAIA,KAAK,CAACC,GAAG,KAAK,KAAK,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAACC,QAAQ,CAACF,KAAK,CAACG,IAAI,CAAC,EAAE;MACpE,OAAO,KAAK;IACd;;IAEA;IACA,IAAIV,cAAc,IAAI,CAACO,KAAK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,CAACJ,QAAQ,CAAC,EAAE,CAAC;MAElD,IAAI,CAACrB,cAAc,IAAIqD,UAAU,CAAChC,QAAQ,CAAC,EAAE;QAC3CnB,KAAK,CAAC,iBAAiB,CAAC;QACxB,OAAO;UAACsD,KAAK,EAAE;QAAI,CAAC;MACtB;IACF;IACAtD,KAAK,CAAC,6CAA6C,CAAC;IACpD,OAAO;MAACsD,KAAK,EAAE;IAAK,CAAC;EACvB;AACF","ignoreList":[]}
|
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,CACT;MAACC,IAAI,EAAE,GAAG;MAAEC,KAAK,EAAE;IAAG,CAAC,EACvB;MAACD,IAAI,EAAE,GAAG;MAAEC,KAAK,EAAE;IAAU,CAAC;EAElC,CAAC;EAED,MAAMC,iBAAiB,GAAG;IACxBN,GAAG,EAAE,KAAK;IACVC,IAAI,EAAE,GAAG;IACTC,IAAI,EAAE,GAAG;IACTC,SAAS,EAAE,CACT;MAACC,IAAI,EAAE,GAAG;MAAEC,KAAK,EAAE;IAAG,CAAC,EACvB;MAACD,IAAI,EAAE,GAAG;MAAEC,KAAK,EAAE;IAAU,CAAC;EAElC,CAAC;EAED,MAAME,MAAM,GAAG;IAC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MD,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,EAAEC,eAAO,CAACC;EAClB,CAAC;EACDC,KAAK,EAAE;IACLC,MAAM,EAAEA,CAAA,KAAMC,oBAAoB,CAAC;EACrC;AACF,CAAC,CAAC;AACF,MAAMC,KAAK,GAAG,IAAAC,cAAiB,EAAC,mDAAmD,CAAC;AAEpF,eAAeF,oBAAoBA,CAAA,EAAG;EACpC,MAAMG,SAAS,GAAG,MAAM,IAAAC,YAAgB,EAAC,CAAC;EAE1C,IAAAC,YAAM,EAACF,SAAS,CAAC,CACdG,EAAE,CAACC,EAAE,CAACC,EAAE,CAAC,QAAQ,CAAC,CAClBC,IAAI,CAACC,GAAG,CAACC,GAAG,CAACC,IAAI,CAAC,aAAa,EAAE,UAAU,CAAC;EAE/C,IAAAP,YAAM,EAACF,SAAS,CAACU,WAAW,CAAC,CAACP,EAAE,CAACC,EAAE,CAACO,CAAC,CAAC,QAAQ,CAAC;EAC/C,IAAAT,YAAM,EAACF,SAAS,CAACY,QAAQ,CAAC,CAACT,EAAE,CAACC,EAAE,CAACO,CAAC,CAAC,UAAU,CAAC;AAChD;AAEA,eAAezB,QAAQA,CAAC;EAAC2B,UAAU;EAAEC,OAAO,GAAG,IAAI;EAAEC,GAAG,GAAG,IAAI;EAAEC,cAAc,GAAG;AAAK,CAAC,EAAE;EACxF,IAAIF,OAAO,KAAK,KAAK,EAAE;IACrBhB,KAAK,CAAC,eAAe,CAAC;IACtB;EACF;EAEA,MAAME,SAAS,GAAG,MAAM,IAAAC,YAAgB,EAACe,cAAc,CAAC;EACxD,MAAMC,MAAM,GAAG,IAAIC,sBAAU,CAACL,UAAU,CAAC,YAAY,CAAC,CAAC;EACvD,MAAMM,cAAc,GAAGN,UAAU,CAAC,aAAa,CAAC;EAChD;;EAEA,IAAI,CAACE,GAAG,EAAE;IACR,MAAMK,MAAM,GAAG,MAAMpB,SAAS,CAACY,QAAQ,CAACK,MAAM,CAAC;IAC/C,IAAAf,YAAM,EAACkB,MAAM,CAAC,CAACjB,EAAE,CAACkB,GAAG,CAACF,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/cyrillux.js
CHANGED
|
@@ -239,7 +239,7 @@ export default function (config = {}) {
|
|
|
239
239
|
|
|
240
240
|
function sfs4900PairCanBeTransliterated(field, record) {
|
|
241
241
|
// MELINDA-10330: we already have public library data: (unmarked) SFS-4900 in FIELD and (unmarked) Cyrillic in 880
|
|
242
|
-
if (!tagCanBeTransliterated(field.tag) || !config.doISO9Transliteration) {
|
|
242
|
+
if (!field.subfields || !tagCanBeTransliterated(field.tag) || !config.doISO9Transliteration) {
|
|
243
243
|
return false;
|
|
244
244
|
}
|
|
245
245
|
|
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`);
|