@natlibfi/melinda-rest-api-commons 4.2.0-alpha.3 → 4.2.1-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.
|
@@ -81,14 +81,23 @@ function getf856sUrns(newRecord) {
|
|
|
81
81
|
|
|
82
82
|
function validateLD(f856sUrn) {
|
|
83
83
|
debug(`Validating the existence of legal deposit subfields`);
|
|
84
|
-
const
|
|
84
|
+
const LD_SUBFIELDS_OLD = [{
|
|
85
85
|
code: 'z',
|
|
86
86
|
value: 'Käytettävissä vapaakappalekirjastoissa'
|
|
87
87
|
}, {
|
|
88
88
|
code: '5',
|
|
89
89
|
value: 'FI-Vapaa'
|
|
90
90
|
}];
|
|
91
|
-
const
|
|
91
|
+
const LD_SUBFIELDS_NEW = [{
|
|
92
|
+
code: 'z',
|
|
93
|
+
value: 'Käytettävissä vapaakappaletyöasemilla'
|
|
94
|
+
}, {
|
|
95
|
+
code: '5',
|
|
96
|
+
value: 'FI-Vapaa'
|
|
97
|
+
}];
|
|
98
|
+
const f856sUrnWithOldLdSubfields = f856sUrn.filter(field => fieldHasLDSubfields(field, LD_SUBFIELDS_OLD));
|
|
99
|
+
const f856sUrnWithNewLdSubfields = f856sUrn.filter(field => fieldHasLDSubfields(field, LD_SUBFIELDS_NEW));
|
|
100
|
+
const f856sUrnWithLdSubfields = [...f856sUrnWithNewLdSubfields, ...f856sUrnWithOldLdSubfields];
|
|
92
101
|
if (f856sUrnWithLdSubfields.length > 0) {
|
|
93
102
|
debug(`Record has ${f856sUrnWithLdSubfields.length} URN fields with all necessary legal deposit subfields`);
|
|
94
103
|
debugData(`f856sUrnWithLdSubfields: ${JSON.stringify(f856sUrnWithLdSubfields)}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fix-handle-tempurns.js","names":["_debug","_interopRequireDefault","require","debug","createDebugLogger","debugData","extend","handleTempUrns","newRecord","options","JSON","stringify","f856sUrnsWithTempSubfields","f856sUrnsWithNoTempSubfields","getf856sUrns","length","existingLegalDepositURN","validateLD","removeFields","fixedFields","map","removeTempSubfield","filter","field","insertFields","hasURN","f","tag","subfields","some","code","value","test","hasTempSubfield","hasNoTempSubfield","f856sUrn","fields","
|
|
1
|
+
{"version":3,"file":"fix-handle-tempurns.js","names":["_debug","_interopRequireDefault","require","debug","createDebugLogger","debugData","extend","handleTempUrns","newRecord","options","JSON","stringify","f856sUrnsWithTempSubfields","f856sUrnsWithNoTempSubfields","getf856sUrns","length","existingLegalDepositURN","validateLD","removeFields","fixedFields","map","removeTempSubfield","filter","field","insertFields","hasURN","f","tag","subfields","some","code","value","test","hasTempSubfield","hasNoTempSubfield","f856sUrn","fields","LD_SUBFIELDS_OLD","LD_SUBFIELDS_NEW","f856sUrnWithOldLdSubfields","fieldHasLDSubfields","f856sUrnWithNewLdSubfields","f856sUrnWithLdSubfields","ldSubfields","every","ldsf","sf","isNaN","parseInt","filteredSubfields","ind1","ind2"],"sources":["../../src/helpers/fix-handle-tempurns.js"],"sourcesContent":["\n\n//import {MarcRecord} from '@natlibfi/marc-record';\nimport createDebugLogger from 'debug';\n\nconst debug = createDebugLogger('@natlibfi/melinda-rest-api-commons:fixRecord:handleTempUrns');\nconst debugData = debug.extend('data');\n\n// eslint-disable-next-line max-statements\nexport function handleTempUrns(newRecord, options) {\n\n if (options !== true) {\n debug(`NOT running handleTempUrns fixer, no options`);\n return newRecord;\n }\n\n debug(`Running handleTempUrns fixer`);\n debugData(`Options for handleTempUrns: ${JSON.stringify(options)}`);\n\n const {f856sUrnsWithTempSubfields, f856sUrnsWithNoTempSubfields} = getf856sUrns(newRecord);\n\n // None of the URNs has temp subfields, we don't need to do anything\n if (f856sUrnsWithTempSubfields.length < 1) {\n debug(`No Urns with temp subfield`);\n return newRecord;\n }\n\n // Do we have an existing URN with legal deposit subfields, if we have, we can remove the temp URN field(s)\n const existingLegalDepositURN = validateLD(f856sUrnsWithNoTempSubfields);\n debug(`existingLegalDepositURN: ${existingLegalDepositURN}`);\n\n if (existingLegalDepositURN) {\n debug(`We have an existing LD URN, we can delete temp fields (${f856sUrnsWithTempSubfields.length})`);\n newRecord.removeFields(f856sUrnsWithTempSubfields);\n return newRecord;\n }\n\n // We do not have an existing legalDepositURN, we should use the tempURN and remove the temp subfields from it\n if (!existingLegalDepositURN && f856sUrnsWithTempSubfields.length > 0) {\n //debug(`All Urns (${f856sUrn.length}) have a temp subfield`);\n debugData(`Original temp URNs: (${JSON.stringify(f856sUrnsWithTempSubfields)})`);\n const fixedFields = f856sUrnsWithTempSubfields.map(removeTempSubfield).filter(field => field);\n debug(`We removed temp subfields: (${JSON.stringify(fixedFields)})`);\n newRecord.removeFields(f856sUrnsWithTempSubfields);\n newRecord.insertFields(fixedFields);\n return newRecord;\n }\n // Should we check that the non-temp URN has 2nd ind '0' - meaning that the URN handles the actual resource itself?\n}\n\nfunction getf856sUrns(newRecord) {\n const hasURN = f => f.tag === '856' && f.subfields.some(({code, value}) => code === 'u' && (/urn.fi/u).test(value));\n\n const hasTempSubfield = f => f.subfields.some(({code, value}) => code === '9' && (/^MELINDA<TEMP>$/u).test(value));\n const hasNoTempSubfield = f => !f.subfields.some(({code, value}) => code === '9' && (/^MELINDA<TEMP>$/u).test(value));\n\n const f856sUrn = newRecord.fields.filter(hasURN);\n const f856sUrnsWithTempSubfields = f856sUrn.filter(hasTempSubfield);\n const f856sUrnsWithNoTempSubfields = f856sUrn.filter(hasNoTempSubfield);\n\n debugData(`URN f856s: ${JSON.stringify(f856sUrn)}`);\n debugData(`URN f856s with temp subfield: ${JSON.stringify(f856sUrnsWithTempSubfields)}`);\n return {f856sUrn, f856sUrnsWithTempSubfields, f856sUrnsWithNoTempSubfields};\n}\n\n\n// ---- LD-functions below are same as in https://github.com/NatLibFi/marc-record-validators-melinda/blob/feature-updates-to-urn/src/urn.js\n// we propably should develop the urn/legaldeposit -validator to use also here\n\nfunction validateLD(f856sUrn) {\n debug(`Validating the existence of legal deposit subfields`);\n\n const LD_SUBFIELDS_OLD = [\n {code: 'z', value: 'Käytettävissä vapaakappalekirjastoissa'},\n {code: '5', value: 'FI-Vapaa'}\n ];\n\n const LD_SUBFIELDS_NEW = [\n {code: 'z', value: 'Käytettävissä vapaakappaletyöasemilla'},\n {code: '5', value: 'FI-Vapaa'}\n ];\n\n const f856sUrnWithOldLdSubfields = f856sUrn.filter(field => fieldHasLDSubfields(field, LD_SUBFIELDS_OLD));\n const f856sUrnWithNewLdSubfields = f856sUrn.filter(field => fieldHasLDSubfields(field, LD_SUBFIELDS_NEW));\n const f856sUrnWithLdSubfields = [...f856sUrnWithNewLdSubfields, ...f856sUrnWithOldLdSubfields];\n\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\nfunction 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\nfunction removeTempSubfield(field) {\n\n // Handle non-numeric fields, and fields with a numeric tag of 010 and greater\n // Aleph's FMT as a controlfield might be a problem\n if (!isNaN(field.tag) && parseInt(field.tag, 10) >= 10) {\n\n const filteredSubfields = field.subfields.filter(sf => sf.code !== '9' && !(/^MELINDA<TEMP>$/u).test(sf.value));\n\n // Remove whole field if there are no subfields left\n if (filteredSubfields.length < 1) {\n return false;\n }\n\n return {\n tag: field.tag,\n ind1: field.ind1,\n ind2: field.ind2,\n subfields: filteredSubfields\n };\n }\n // return controlFields as is\n return field;\n}\n\n\n"],"mappings":";;;;;;;AAGA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AADA;;AAGA,MAAMC,KAAK,GAAG,IAAAC,cAAiB,EAAC,6DAA6D,CAAC;AAC9F,MAAMC,SAAS,GAAGF,KAAK,CAACG,MAAM,CAA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,KAAK,CAACI,GAAG,CAAC,IAAIqB,QAAQ,CAACzB,KAAK,CAACI,GAAG,EAAE,EAAE,CAAC,IAAI,EAAE,EAAE;IAEtD,MAAMsB,iBAAiB,GAAG1B,KAAK,CAACK,SAAS,CAACN,MAAM,CAACwB,EAAE,IAAIA,EAAE,CAAChB,IAAI,KAAK,GAAG,IAAI,CAAE,kBAAkB,CAAEE,IAAI,CAACc,EAAE,CAACf,KAAK,CAAC,CAAC;;IAE/G;IACA,IAAIkB,iBAAiB,CAAClC,MAAM,GAAG,CAAC,EAAE;MAChC,OAAO,KAAK;IACd;IAEA,OAAO;MACLY,GAAG,EAAEJ,KAAK,CAACI,GAAG;MACduB,IAAI,EAAE3B,KAAK,CAAC2B,IAAI;MAChBC,IAAI,EAAE5B,KAAK,CAAC4B,IAAI;MAChBvB,SAAS,EAAEqB;IACb,CAAC;EACH;EACA;EACA,OAAO1B,KAAK;AACd","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"url": "git@github.com:natlibfi/melinda-rest-api-commons.git"
|
|
15
15
|
},
|
|
16
16
|
"license": "MIT",
|
|
17
|
-
"version": "4.2.
|
|
17
|
+
"version": "4.2.1-alpha.1",
|
|
18
18
|
"main": "./dist/index.js",
|
|
19
19
|
"engines": {
|
|
20
20
|
"node": ">=18"
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"@natlibfi/marc-record": "^9.0.1",
|
|
40
40
|
"@natlibfi/marc-record-serializers": "^10.1.2",
|
|
41
41
|
"@natlibfi/marc-record-validate": "^8.0.10",
|
|
42
|
-
"@natlibfi/marc-record-validators-melinda": "^11.3.
|
|
42
|
+
"@natlibfi/marc-record-validators-melinda": "^11.3.6",
|
|
43
43
|
"@natlibfi/melinda-backend-commons": "^2.3.1",
|
|
44
44
|
"@natlibfi/melinda-commons": "^13.0.17",
|
|
45
45
|
"amqplib": "^0.10.4",
|
|
@@ -63,10 +63,10 @@
|
|
|
63
63
|
"babel-plugin-rewire": "^1.2.0",
|
|
64
64
|
"chai": "^4.5.0",
|
|
65
65
|
"cross-env": "^7.0.3",
|
|
66
|
-
"eslint": "^8.57.
|
|
66
|
+
"eslint": "^8.57.1",
|
|
67
67
|
"mocha": "^10.7.3",
|
|
68
|
-
"nodemon": "^3.1.
|
|
69
|
-
"nyc": "^17.
|
|
68
|
+
"nodemon": "^3.1.7",
|
|
69
|
+
"nyc": "^17.1.0"
|
|
70
70
|
},
|
|
71
71
|
"eslintConfig": {
|
|
72
72
|
"extends": "@natlibfi/melinda-backend"
|