@natlibfi/melinda-rest-api-commons 2.3.2-alpha.1 → 2.3.2-alpha.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/dist/amqp.health.spec.js +69 -0
  2. package/dist/amqp.health.spec.js.map +1 -0
  3. package/dist/amqp.js +135 -92
  4. package/dist/amqp.js.map +1 -1
  5. package/dist/amqp.tests.spec.js +338 -0
  6. package/dist/amqp.tests.spec.js.map +1 -0
  7. package/dist/constants.js +5 -3
  8. package/dist/constants.js.map +1 -1
  9. package/dist/helpers/conversion.js +5 -25
  10. package/dist/helpers/conversion.js.map +1 -1
  11. package/dist/helpers/conversion.spec.js +1 -7
  12. package/dist/helpers/conversion.spec.js.map +1 -1
  13. package/dist/helpers/fix-constants.js +98 -0
  14. package/dist/helpers/fix-constants.js.map +1 -0
  15. package/dist/helpers/fix-handle-tempurns.js +153 -0
  16. package/dist/helpers/fix-handle-tempurns.js.map +1 -0
  17. package/dist/helpers/fix-strip-f884s.js +87 -0
  18. package/dist/helpers/fix-strip-f884s.js.map +1 -0
  19. package/dist/helpers/fix-utils.js +82 -0
  20. package/dist/helpers/fix-utils.js.map +1 -0
  21. package/dist/helpers/fix.js +178 -0
  22. package/dist/helpers/fix.js.map +1 -0
  23. package/dist/helpers/fix.spec.js +46 -0
  24. package/dist/helpers/fix.spec.js.map +1 -0
  25. package/dist/helpers/validation.js +0 -6
  26. package/dist/helpers/validation.js.map +1 -1
  27. package/dist/helpers/validation.spec.js +1 -7
  28. package/dist/helpers/validation.spec.js.map +1 -1
  29. package/dist/index.js +12 -18
  30. package/dist/index.js.map +1 -1
  31. package/dist/mongo.js +50 -89
  32. package/dist/mongo.js.map +1 -1
  33. package/dist/mongo.spec.js.draft +54 -0
  34. package/dist/mongoLog.js +16 -35
  35. package/dist/mongoLog.js.map +1 -1
  36. package/dist/utils.js +33 -35
  37. package/dist/utils.js.map +1 -1
  38. package/package.json +122 -116
  39. package/dist/helpers/format.js +0 -305
  40. package/dist/helpers/format.js.map +0 -1
  41. package/dist/helpers/format.spec.js +0 -224
  42. package/dist/helpers/format.spec.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"conversion.spec.js","names":["describe","getFixture","fixtureFactory","root","__dirname","conversionService","createConversionService","marcRecord","MarcRecord","JSON","parse","components","subfieldValues","marcXml","iso2709","json","alephSeq","it","service","expect","to","be","an","and","respondTo","serialize","throw","data","CONVERSION_FORMATS","MARCXML","equal","ISO2709","ALEPHSEQ","unserialize","record","equalsTo","ConversionError"],"sources":["../../src/helpers/conversion.spec.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Shared modules for microservices of Melinda rest api batch import system\n*\n* Copyright (C) 2020-2021 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-rest-api-commons\n*\n* melinda-rest-api-commons program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Affero General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-rest-api-commons is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Affero General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\nimport {expect} from 'chai';\nimport fixtureFactory from '@natlibfi/fixura';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport {Error as ConversionError} from '@natlibfi/melinda-commons';\nimport createConversionService from './conversion';\nimport {CONVERSION_FORMATS} from '../constants';\n\ndescribe('services/conversion', () => {\n const {getFixture} = fixtureFactory({root: [\n __dirname,\n '..',\n '..',\n 'test-fixtures',\n 'conversion'\n ]});\n const conversionService = createConversionService();\n\n const marcRecord = new MarcRecord(JSON.parse(getFixture({components: ['json1']})), {subfieldValues: false});\n const marcXml = getFixture({components: ['marcxml1']});\n const iso2709 = getFixture({components: ['iso2709_1']});\n const json = getFixture({components: ['json1']});\n const alephSeq = getFixture({components: ['aleph_sequential']});\n\n\n describe('factory', () => {\n it('Should create the expected object', () => {\n const service = createConversionService();\n expect(service).to.be.an('object').and\n .respondTo('serialize')\n .respondTo('unserialize');\n });\n });\n\n describe('#serialize', () => {\n it('Should throw because of unsupported format', () => {\n expect(conversionService.serialize).to.throw();\n });\n\n it('Should serialize to MARCXML', () => {\n const data = conversionService.serialize(marcRecord, CONVERSION_FORMATS.MARCXML);\n expect(data).to.equal(marcXml);\n });\n\n it('Should serialize to ISO2709', () => {\n const data = conversionService.serialize(marcRecord, CONVERSION_FORMATS.ISO2709);\n expect(data).to.equal(iso2709);\n });\n\n it('Should serialize to JSON', () => {\n const data = conversionService.serialize(marcRecord, CONVERSION_FORMATS.JSON);\n expect(data).to.equal(json);\n });\n\n it('Should serialize to aleph sequential', () => {\n const data = conversionService.serialize(marcRecord, CONVERSION_FORMATS.ALEPHSEQ);\n expect(data).to.equal(alephSeq);\n });\n\n });\n\n describe('#unserialize', () => {\n it('Should throw because of unsupported format', () => {\n expect(conversionService.unserialize).to.throw();\n });\n\n it('Should unserialize from MARCXML', async () => {\n const record = await conversionService.unserialize(marcXml, CONVERSION_FORMATS.MARCXML);\n expect(record.equalsTo(marcRecord)).to.equal(true);\n });\n\n it('Should unserialize from ISO2709', () => {\n const record = conversionService.unserialize(iso2709, CONVERSION_FORMATS.ISO2709);\n expect(record.equalsTo(marcRecord)).to.equal(true);\n });\n\n it('Should unserialize from JSON', () => {\n const record = conversionService.unserialize(json, CONVERSION_FORMATS.JSON);\n expect(record.equalsTo(marcRecord)).to.equal(true);\n });\n\n it('Should unserialize from Aleph sequential', () => {\n const record = conversionService.unserialize(alephSeq, CONVERSION_FORMATS.ALEPHSEQ);\n expect(record.equalsTo(marcRecord)).to.equal(true);\n });\n\n\n it('Should throw because the record could not be unserialized', () => {\n expect(() => {\n conversionService.unserialize('', CONVERSION_FORMATS.JSON);\n }).to.throw(ConversionError);\n });\n });\n});\n"],"mappings":";;AA4BA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;AAjCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AASAA,QAAQ,CAAC,qBAAD,EAAwB,MAAM;EACpC,MAAM;IAACC;EAAD,IAAe,IAAAC,eAAA,EAAe;IAACC,IAAI,EAAE,CACzCC,SADyC,EAEzC,IAFyC,EAGzC,IAHyC,EAIzC,eAJyC,EAKzC,YALyC;EAAP,CAAf,CAArB;EAOA,MAAMC,iBAAiB,GAAG,IAAAC,mBAAA,GAA1B;EAEA,MAAMC,UAAU,GAAG,IAAIC,sBAAJ,CAAeC,IAAI,CAACC,KAAL,CAAWT,UAAU,CAAC;IAACU,UAAU,EAAE,CAAC,OAAD;EAAb,CAAD,CAArB,CAAf,EAAgE;IAACC,cAAc,EAAE;EAAjB,CAAhE,CAAnB;EACA,MAAMC,OAAO,GAAGZ,UAAU,CAAC;IAACU,UAAU,EAAE,CAAC,UAAD;EAAb,CAAD,CAA1B;EACA,MAAMG,OAAO,GAAGb,UAAU,CAAC;IAACU,UAAU,EAAE,CAAC,WAAD;EAAb,CAAD,CAA1B;EACA,MAAMI,IAAI,GAAGd,UAAU,CAAC;IAACU,UAAU,EAAE,CAAC,OAAD;EAAb,CAAD,CAAvB;EACA,MAAMK,QAAQ,GAAGf,UAAU,CAAC;IAACU,UAAU,EAAE,CAAC,kBAAD;EAAb,CAAD,CAA3B;EAGAX,QAAQ,CAAC,SAAD,EAAY,MAAM;IACxBiB,EAAE,CAAC,mCAAD,EAAsC,MAAM;MAC5C,MAAMC,OAAO,GAAG,IAAAZ,mBAAA,GAAhB;MACA,IAAAa,YAAA,EAAOD,OAAP,EAAgBE,EAAhB,CAAmBC,EAAn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AAA,EAAOe,MAAM,CAACC,QAAP,CAAgB5B,UAAhB,CAAP,EAAoCa,EAApC,CAAuCU,KAAvC,CAA6C,IAA7C;IACD,CAHC,CAAF;IAMAb,EAAE,CAAC,2DAAD,EAA8D,MAAM;MACpE,IAAAE,YAAA,EAAO,MAAM;QACXd,iBAAiB,CAAC4B,WAAlB,CAA8B,EAA9B,EAAkCL,6BAAA,CAAmBnB,IAArD;MACD,CAFD,EAEGW,EAFH,CAEMM,KAFN,CAEYU,qBAFZ;IAGD,CAJC,CAAF;EAKD,CA/BO,CAAR;AAgCD,CArFO,CAAR"}
1
+ {"version":3,"file":"conversion.spec.js","names":["describe","getFixture","fixtureFactory","root","__dirname","conversionService","createConversionService","marcRecord","MarcRecord","JSON","parse","components","subfieldValues","marcXml","iso2709","json","alephSeq","it","service","expect","to","be","an","and","respondTo","serialize","throw","data","CONVERSION_FORMATS","MARCXML","equal","ISO2709","ALEPHSEQ","unserialize","record","equalsTo","ConversionError"],"sources":["../../src/helpers/conversion.spec.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Shared modules for microservices of Melinda rest api batch import system\n*\n* Copyright (C) 2020-2021 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-rest-api-commons\n*\n* melinda-rest-api-commons program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Affero General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-rest-api-commons is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Affero General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\nimport {expect} from 'chai';\nimport fixtureFactory from '@natlibfi/fixura';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport {Error as ConversionError} from '@natlibfi/melinda-commons';\nimport createConversionService from './conversion';\nimport {CONVERSION_FORMATS} from '../constants';\n\ndescribe('services/conversion', () => {\n const {getFixture} = fixtureFactory({root: [\n __dirname,\n '..',\n '..',\n 'test-fixtures',\n 'conversion'\n ]});\n const conversionService = createConversionService();\n\n const marcRecord = new MarcRecord(JSON.parse(getFixture({components: ['json1']})), {subfieldValues: false});\n const marcXml = getFixture({components: ['marcxml1']});\n const iso2709 = getFixture({components: ['iso2709_1']});\n const json = getFixture({components: ['json1']});\n const alephSeq = getFixture({components: ['aleph_sequential']});\n\n\n describe('factory', () => {\n it('Should create the expected object', () => {\n const service = createConversionService();\n expect(service).to.be.an('object').and\n .respondTo('serialize')\n .respondTo('unserialize');\n });\n });\n\n describe('#serialize', () => {\n it('Should throw because of unsupported format', () => {\n expect(conversionService.serialize).to.throw();\n });\n\n it('Should serialize to MARCXML', () => {\n const data = conversionService.serialize(marcRecord, CONVERSION_FORMATS.MARCXML);\n expect(data).to.equal(marcXml);\n });\n\n it('Should serialize to ISO2709', () => {\n const data = conversionService.serialize(marcRecord, CONVERSION_FORMATS.ISO2709);\n expect(data).to.equal(iso2709);\n });\n\n it('Should serialize to JSON', () => {\n const data = conversionService.serialize(marcRecord, CONVERSION_FORMATS.JSON);\n expect(data).to.equal(json);\n });\n\n it('Should serialize to aleph sequential', () => {\n const data = conversionService.serialize(marcRecord, CONVERSION_FORMATS.ALEPHSEQ);\n expect(data).to.equal(alephSeq);\n });\n\n });\n\n describe('#unserialize', () => {\n it('Should throw because of unsupported format', () => {\n expect(conversionService.unserialize).to.throw();\n });\n\n it('Should unserialize from MARCXML', async () => {\n const record = await conversionService.unserialize(marcXml, CONVERSION_FORMATS.MARCXML);\n expect(record.equalsTo(marcRecord)).to.equal(true);\n });\n\n it('Should unserialize from ISO2709', () => {\n const record = conversionService.unserialize(iso2709, CONVERSION_FORMATS.ISO2709);\n expect(record.equalsTo(marcRecord)).to.equal(true);\n });\n\n it('Should unserialize from JSON', () => {\n const record = conversionService.unserialize(json, CONVERSION_FORMATS.JSON);\n expect(record.equalsTo(marcRecord)).to.equal(true);\n });\n\n it('Should unserialize from Aleph sequential', () => {\n const record = conversionService.unserialize(alephSeq, CONVERSION_FORMATS.ALEPHSEQ);\n expect(record.equalsTo(marcRecord)).to.equal(true);\n });\n\n\n it('Should throw because the record could not be unserialized', () => {\n expect(() => {\n conversionService.unserialize('', CONVERSION_FORMATS.JSON);\n }).to.throw(ConversionError);\n });\n });\n});\n"],"mappings":";;AA4BA;AACA;AACA;AACA;AACA;AACA;AAAgD;AAjChD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AASAA,QAAQ,CAAC,qBAAqB,EAAE,MAAM;EACpC,MAAM;IAACC;EAAU,CAAC,GAAG,IAAAC,eAAc,EAAC;IAACC,IAAI,EAAE,CACzCC,SAAS,EACT,IAAI,EACJ,IAAI,EACJ,eAAe,EACf,YAAY;EACb,CAAC,CAAC;EACH,MAAMC,iBAAiB,GAAG,IAAAC,mBAAuB,GAAE;EAEnD,MAAMC,UAAU,GAAG,IAAIC,sBAAU,CAACC,IAAI,CAACC,KAAK,CAACT,UAAU,CAAC;IAACU,UAAU,EAAE,CAAC,OAAO;EAAC,CAAC,CAAC,CAAC,EAAE;IAACC,cAAc,EAAE;EAAK,CAAC,CAAC;EAC3G,MAAMC,OAAO,GAAGZ,UAAU,CAAC;IAACU,UAAU,EAAE,CAAC,UAAU;EAAC,CAAC,CAAC;EACtD,MAAMG,OAAO,GAAGb,UAAU,CAAC;IAACU,UAAU,EAAE,CAAC,WAAW;EAAC,CAAC,CAAC;EACvD,MAAMI,IAAI,GAAGd,UAAU,CAAC;IAACU,UAAU,EAAE,CAAC,OAAO;EAAC,CAAC,CAAC;EAChD,MAAMK,QAAQ,GAAGf,UAAU,CAAC;IAACU,UA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CAAC,CAAC,CAACa,EAAE,CAACU,KAAK,CAAC,IAAI,CAAC;IACpD,CAAC,CAAC;IAEFb,EAAE,CAAC,0CAA0C,EAAE,MAAM;MACnD,MAAMiB,MAAM,GAAG7B,iBAAiB,CAAC4B,WAAW,CAACjB,QAAQ,EAAEY,6BAAkB,CAACI,QAAQ,CAAC;MACnF,IAAAb,YAAM,EAACe,MAAM,CAACC,QAAQ,CAAC5B,UAAU,CAAC,CAAC,CAACa,EAAE,CAACU,KAAK,CAAC,IAAI,CAAC;IACpD,CAAC,CAAC;IAGFb,EAAE,CAAC,2DAA2D,EAAE,MAAM;MACpE,IAAAE,YAAM,EAAC,MAAM;QACXd,iBAAiB,CAAC4B,WAAW,CAAC,EAAE,EAAEL,6BAAkB,CAACnB,IAAI,CAAC;MAC5D,CAAC,CAAC,CAACW,EAAE,CAACM,KAAK,CAACU,qBAAe,CAAC;IAC9B,CAAC,CAAC;EACJ,CAAC,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.REPLACE_PREFIXES = exports.BIB_STRIP_F884S_SETTINGS = exports.BIB_PREVALIDATION_FIX_SETTINGS = exports.BIB_PREIMPORT_FIX_SETTINGS = exports.BIB_POSTMERGE_FIX_SETTINGS = exports.BIB_HANDLE_TEMP_URNS_SETTINGS = exports.BIB_FORMAT_SETTINGS = exports.BIB_F035_TO_SID = exports.AUTNAME_PREIMPORT_FIX_SETTINGS = void 0;
7
+ /**
8
+ *
9
+ * @licstart The following is the entire license notice for the JavaScript code in this file.
10
+ *
11
+ * Shared modules for microservices of Melinda rest api batch import system
12
+ *
13
+ * Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
14
+ *
15
+ * This file is part of melinda-rest-api-commons
16
+ *
17
+ * melinda-rest-api-commons program is free software: you can redistribute it and/or modify
18
+ * it under the terms of the GNU Affero General Public License as
19
+ * published by the Free Software Foundation, either version 3 of the
20
+ * License, or (at your option) any later version.
21
+ *
22
+ * melinda-rest-api-commons is distributed in the hope that it will be useful,
23
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
24
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25
+ * GNU Affero General Public License for more details.
26
+ *
27
+ * You should have received a copy of the GNU Affero General Public License
28
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
29
+ *
30
+ * @licend The above is the entire license notice
31
+ * for the JavaScript code in this file.
32
+ *
33
+ */
34
+
35
+ // This could be formatted so that 035-prefix and SID contents would be better connected than by just an array index
36
+ const BIB_F035_TO_SID = {
37
+ f035Filters: [/^\(FI-BTJ\)/u, /^\(FI-TATI\)/u],
38
+ fSIDFilters: ['FI-BTJ', 'tati']
39
+ };
40
+
41
+ // There is somewhere other implementations of this same standardPrefixes to alephInternalPrefixes normalization
42
+ exports.BIB_F035_TO_SID = BIB_F035_TO_SID;
43
+ const REPLACE_PREFIXES = [{
44
+ oldPrefix: 'FI-MELINDA',
45
+ newPrefix: 'FIN01',
46
+ prefixReplaceCodes: ['w']
47
+ }, {
48
+ oldPrefix: 'FI-ASTERI-S',
49
+ newPrefix: 'FIN10',
50
+ prefixReplaceCodes: ['0']
51
+ }, {
52
+ oldPrefix: 'FI-ASTERI-N',
53
+ newPrefix: 'FIN11',
54
+ prefixReplaceCodes: ['0']
55
+ }, {
56
+ oldPrefix: 'FI-ASTERI-A',
57
+ newPrefix: 'FIN12',
58
+ prefixReplaceCodes: ['0']
59
+ }, {
60
+ oldPrefix: 'FI-ASTERI-W',
61
+ newPrefix: 'FIN13',
62
+ prefixReplaceCodes: ['0']
63
+ }];
64
+
65
+ // If placed in config.js testing needs envs
66
+ // BIB_FORMAT_SETTINGS is outdated, use other settings instead
67
+ exports.REPLACE_PREFIXES = REPLACE_PREFIXES;
68
+ const BIB_FORMAT_SETTINGS = {
69
+ replacePrefixes: REPLACE_PREFIXES,
70
+ generateMissingSIDs: BIB_F035_TO_SID
71
+ };
72
+ exports.BIB_FORMAT_SETTINGS = BIB_FORMAT_SETTINGS;
73
+ const BIB_PREVALIDATION_FIX_SETTINGS = {
74
+ generateMissingSIDs: BIB_F035_TO_SID
75
+ };
76
+ exports.BIB_PREVALIDATION_FIX_SETTINGS = BIB_PREVALIDATION_FIX_SETTINGS;
77
+ const BIB_POSTMERGE_FIX_SETTINGS = {
78
+ handleTempUrns: true,
79
+ stripF884s: true
80
+ };
81
+ exports.BIB_POSTMERGE_FIX_SETTINGS = BIB_POSTMERGE_FIX_SETTINGS;
82
+ const BIB_PREIMPORT_FIX_SETTINGS = {
83
+ replacePrefixes: REPLACE_PREFIXES
84
+ };
85
+ exports.BIB_PREIMPORT_FIX_SETTINGS = BIB_PREIMPORT_FIX_SETTINGS;
86
+ const AUTNAME_PREIMPORT_FIX_SETTINGS = {
87
+ replacePrefixes: REPLACE_PREFIXES
88
+ };
89
+ exports.AUTNAME_PREIMPORT_FIX_SETTINGS = AUTNAME_PREIMPORT_FIX_SETTINGS;
90
+ const BIB_HANDLE_TEMP_URNS_SETTINGS = {
91
+ handleTempUrns: true
92
+ };
93
+ exports.BIB_HANDLE_TEMP_URNS_SETTINGS = BIB_HANDLE_TEMP_URNS_SETTINGS;
94
+ const BIB_STRIP_F884S_SETTINGS = {
95
+ stripF884s: true
96
+ };
97
+ exports.BIB_STRIP_F884S_SETTINGS = BIB_STRIP_F884S_SETTINGS;
98
+ //# sourceMappingURL=fix-constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fix-constants.js","names":["BIB_F035_TO_SID","f035Filters","fSIDFilters","REPLACE_PREFIXES","oldPrefix","newPrefix","prefixReplaceCodes","BIB_FORMAT_SETTINGS","replacePrefixes","generateMissingSIDs","BIB_PREVALIDATION_FIX_SETTINGS","BIB_POSTMERGE_FIX_SETTINGS","handleTempUrns","stripF884s","BIB_PREIMPORT_FIX_SETTINGS","AUTNAME_PREIMPORT_FIX_SETTINGS","BIB_HANDLE_TEMP_URNS_SETTINGS","BIB_STRIP_F884S_SETTINGS"],"sources":["../../src/helpers/fix-constants.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Shared modules for microservices of Melinda rest api batch import system\n*\n* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-rest-api-commons\n*\n* melinda-rest-api-commons program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Affero General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-rest-api-commons is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Affero General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\n// This could be formatted so that 035-prefix and SID contents would be better connected than by just an array index\nexport const BIB_F035_TO_SID = {\n f035Filters: [/^\\(FI-BTJ\\)/u, /^\\(FI-TATI\\)/u],\n fSIDFilters: ['FI-BTJ', 'tati']\n};\n\n// There is somewhere other implementations of this same standardPrefixes to alephInternalPrefixes normalization\nexport const REPLACE_PREFIXES = [\n {\n oldPrefix: 'FI-MELINDA',\n newPrefix: 'FIN01',\n prefixReplaceCodes: ['w']\n },\n {\n oldPrefix: 'FI-ASTERI-S',\n newPrefix: 'FIN10',\n prefixReplaceCodes: ['0']\n },\n {\n oldPrefix: 'FI-ASTERI-N',\n newPrefix: 'FIN11',\n prefixReplaceCodes: ['0']\n },\n {\n oldPrefix: 'FI-ASTERI-A',\n newPrefix: 'FIN12',\n prefixReplaceCodes: ['0']\n },\n {\n oldPrefix: 'FI-ASTERI-W',\n newPrefix: 'FIN13',\n prefixReplaceCodes: ['0']\n }\n];\n\n\n// If placed in config.js testing needs envs\n// BIB_FORMAT_SETTINGS is outdated, use other settings instead\n\n\nexport const BIB_FORMAT_SETTINGS = {\n replacePrefixes: REPLACE_PREFIXES,\n generateMissingSIDs: BIB_F035_TO_SID\n};\n\nexport const BIB_PREVALIDATION_FIX_SETTINGS = {\n generateMissingSIDs: BIB_F035_TO_SID\n};\n\nexport const BIB_POSTMERGE_FIX_SETTINGS = {\n handleTempUrns: true,\n stripF884s: true\n};\n\nexport const BIB_PREIMPORT_FIX_SETTINGS = {\n replacePrefixes: REPLACE_PREFIXES\n};\n\nexport const AUTNAME_PREIMPORT_FIX_SETTINGS = {\n replacePrefixes: REPLACE_PREFIXES\n};\n\nexport const BIB_HANDLE_TEMP_URNS_SETTINGS = {\n handleTempUrns: true\n};\n\nexport const BIB_STRIP_F884S_SETTINGS = {\n stripF884s: true\n};\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACO,MAAMA,eAAe,GAAG;EAC7BC,WAAW,EAAE,CAAC,cAAc,EAAE,eAAe,CAAC;EAC9CC,WAAW,EAAE,CAAC,QAAQ,EAAE,MAAM;AAChC,CAAC;;AAED;AAAA;AACO,MAAMC,gBAAgB,GAAG,CAC9B;EACEC,SAAS,EAAE,YAAY;EACvBC,SAAS,EAAE,OAAO;EAClBC,kBAAkB,EAAE,CAAC,GAAG;AAC1B,CAAC,EACD;EACEF,SAAS,EAAE,aAAa;EACxBC,SAAS,EAAE,OAAO;EAClBC,kBAAkB,EAAE,CAAC,GAAG;AAC1B,CAAC,EACD;EACEF,SAAS,EAAE,aAAa;EACxBC,SAAS,EAAE,OAAO;EAClBC,kBAAkB,EAAE,CAAC,GAAG;AAC1B,CAAC,EACD;EACEF,SAAS,EAAE,aAAa;EACxBC,SAAS,EAAE,OAAO;EAClBC,kBAAkB,EAAE,CAAC,GAAG;AAC1B,CAAC,EACD;EACEF,SAAS,EAAE,aAAa;EACxBC,SAAS,EAAE,OAAO;EAClBC,kBAAkB,EAAE,CAAC,GAAG;AAC1B,CAAC,CACF;;AAGD;AACA;AAAA;AAGO,MAAMC,mBAAmB,GAAG;EACjCC,eAAe,EAAEL,gBAAgB;EACjCM,mBAAmB,EAAET;AACvB,CAAC;AAAC;AAEK,MAAMU,8BAA8B,GAAG;EAC5CD,mBAAmB,EAAET;AACvB,CAAC;AAAC;AAEK,MAAMW,0BAA0B,GAAG;EACxCC,cAAc,EAAE,IAAI;EACpBC,UAAU,EAAE;AACd,CAAC;AAAC;AAEK,MAAMC,0BAA0B,GAAG;EACxCN,eAAe,EAAEL;AACnB,CAAC;AAAC;AAEK,MAAMY,8BAA8B,GAAG;EAC5CP,eAAe,EAAEL;AACnB,CAAC;AAAC;AAEK,MAAMa,6BAA6B,GAAG;EAC3CJ,cAAc,EAAE;AAClB,CAAC;AAAC;AAEK,MAAMK,wBAAwB,GAAG;EACtCJ,UAAU,EAAE;AACd,CAAC;AAAC"}
@@ -0,0 +1,153 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.handleTempUrns = handleTempUrns;
7
+ var _debug = _interopRequireDefault(require("debug"));
8
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
+ /**
10
+ *
11
+ * @licstart The following is the entire license notice for the JavaScript code in this file.
12
+ *
13
+ * Shared modules for microservices of Melinda rest api batch import system
14
+ *
15
+ * Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
16
+ *
17
+ * This file is part of melinda-rest-api-commons
18
+ *
19
+ * melinda-rest-api-commons program is free software: you can redistribute it and/or modify
20
+ * it under the terms of the GNU Affero General Public License as
21
+ * published by the Free Software Foundation, either version 3 of the
22
+ * License, or (at your option) any later version.
23
+ *
24
+ * melinda-rest-api-commons is distributed in the hope that it will be useful,
25
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
26
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27
+ * GNU Affero General Public License for more details.
28
+ *
29
+ * You should have received a copy of the GNU Affero General Public License
30
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
31
+ *
32
+ * @licend The above is the entire license notice
33
+ * for the JavaScript code in this file.
34
+ *
35
+ */
36
+
37
+ //import {MarcRecord} from '@natlibfi/marc-record';
38
+
39
+ const debug = (0, _debug.default)('@natlibfi/melinda-rest-api-commons:fixRecord:handleTempUrns');
40
+ const debugData = debug.extend('data');
41
+
42
+ // eslint-disable-next-line max-statements
43
+ function handleTempUrns(newRecord, options) {
44
+ if (options !== true) {
45
+ debug(`NOT running handleTempUrns fixer, no options`);
46
+ return newRecord;
47
+ }
48
+ debug(`Running handleTempUrns fixer`);
49
+ debugData(`Options for handleTempUrns: ${JSON.stringify(options)}`);
50
+ const {
51
+ f856sUrnsWithTempSubfields,
52
+ f856sUrnsWithNoTempSubfields
53
+ } = getf856sUrns(newRecord);
54
+
55
+ // None of the URNs has temp subfields, we don't need to do anything
56
+ if (f856sUrnsWithTempSubfields.length < 1) {
57
+ debug(`No Urns with temp subfield`);
58
+ return newRecord;
59
+ }
60
+
61
+ // Do we have an existing URN with legal deposit subfields, if we have, we can remove the temp URN field(s)
62
+ const existingLegalDepositURN = validateLD(f856sUrnsWithNoTempSubfields);
63
+ debug(`existingLegalDepositURN: ${existingLegalDepositURN}`);
64
+ if (existingLegalDepositURN) {
65
+ debug(`We have an existing LD URN, we can delete temp fields (${f856sUrnsWithTempSubfields.length})`);
66
+ newRecord.removeFields(f856sUrnsWithTempSubfields);
67
+ return newRecord;
68
+ }
69
+
70
+ // We do not have an existing legalDepositURN, we should use the tempURN and remove the temp subfields from it
71
+ if (!existingLegalDepositURN && f856sUrnsWithTempSubfields.length > 0) {
72
+ //debug(`All Urns (${f856sUrn.length}) have a temp subfield`);
73
+ debugData(`Original temp URNs: (${JSON.stringify(f856sUrnsWithTempSubfields)})`);
74
+ const fixedFields = f856sUrnsWithTempSubfields.map(removeTempSubfield).filter(field => field);
75
+ debug(`We removed temp subfields: (${JSON.stringify(fixedFields)})`);
76
+ newRecord.removeFields(f856sUrnsWithTempSubfields);
77
+ newRecord.insertFields(fixedFields);
78
+ return newRecord;
79
+ }
80
+ // Should we check that the non-temp URN has 2nd ind '0' - meaning that the URN handles the actual resource itself?
81
+ }
82
+
83
+ function getf856sUrns(newRecord) {
84
+ const hasURN = f => f.tag === '856' && f.subfields.some(({
85
+ code,
86
+ value
87
+ }) => code === 'u' && /urn.fi/u.test(value));
88
+ const hasTempSubfield = f => f.subfields.some(({
89
+ code,
90
+ value
91
+ }) => code === '9' && /^MELINDA<TEMP>$/u.test(value));
92
+ const hasNoTempSubfield = f => !f.subfields.some(({
93
+ code,
94
+ value
95
+ }) => code === '9' && /^MELINDA<TEMP>$/u.test(value));
96
+ const f856sUrn = newRecord.fields.filter(hasURN);
97
+ const f856sUrnsWithTempSubfields = f856sUrn.filter(hasTempSubfield);
98
+ const f856sUrnsWithNoTempSubfields = f856sUrn.filter(hasNoTempSubfield);
99
+ debugData(`URN f856s: ${JSON.stringify(f856sUrn)}`);
100
+ debugData(`URN f856s with temp subfield: ${JSON.stringify(f856sUrnsWithTempSubfields)}`);
101
+ return {
102
+ f856sUrn,
103
+ f856sUrnsWithTempSubfields,
104
+ f856sUrnsWithNoTempSubfields
105
+ };
106
+ }
107
+
108
+ // ---- LD-functions below are same as in https://github.com/NatLibFi/marc-record-validators-melinda/blob/feature-updates-to-urn/src/urn.js
109
+ // we propably should develop the urn/legaldeposit -validator to use also here
110
+
111
+ function validateLD(f856sUrn) {
112
+ debug(`Validating the existence of legal deposit subfields`);
113
+ const LD_SUBFIELDS = [{
114
+ code: 'z',
115
+ value: 'Käytettävissä vapaakappalekirjastoissa'
116
+ }, {
117
+ code: '5',
118
+ value: 'FI-Vapaa'
119
+ }];
120
+ const f856sUrnWithLdSubfields = f856sUrn.filter(field => fieldHasLDSubfields(field, LD_SUBFIELDS));
121
+ if (f856sUrnWithLdSubfields.length > 0) {
122
+ debug(`Record has ${f856sUrnWithLdSubfields.length} URN fields with all necessary legal deposit subfields`);
123
+ debugData(`f856sUrnWithLdSubfields: ${JSON.stringify(f856sUrnWithLdSubfields)}`);
124
+ return true;
125
+ }
126
+ return false;
127
+ }
128
+ function fieldHasLDSubfields(field, ldSubfields) {
129
+ if (ldSubfields.every(ldsf => field.subfields.some(sf => sf.code === ldsf.code && sf.value === ldsf.value))) {
130
+ return true;
131
+ }
132
+ }
133
+ function removeTempSubfield(field) {
134
+ // Handle non-numeric fields, and fields with a numeric tag of 010 and greater
135
+ // Aleph's FMT as a controlfield might be a problem
136
+ if (!isNaN(field.tag) && parseInt(field.tag, 10) >= 10) {
137
+ const filteredSubfields = field.subfields.filter(sf => sf.code !== '9' && !/^MELINDA<TEMP>$/u.test(sf.value));
138
+
139
+ // Remove whole field if there are no subfields left
140
+ if (filteredSubfields.length < 1) {
141
+ return false;
142
+ }
143
+ return {
144
+ tag: field.tag,
145
+ ind1: field.ind1,
146
+ ind2: field.ind2,
147
+ subfields: filteredSubfields
148
+ };
149
+ }
150
+ // return controlFields as is
151
+ return field;
152
+ }
153
+ //# sourceMappingURL=fix-handle-tempurns.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fix-handle-tempurns.js","names":["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","f856sUrnWithLdSubfields","fieldHasLDSubfields","ldSubfields","every","ldsf","sf","isNaN","parseInt","filteredSubfields","ind1","ind2"],"sources":["../../src/helpers/fix-handle-tempurns.js"],"sourcesContent":["\n/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Shared modules for microservices of Melinda rest api batch import system\n*\n* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-rest-api-commons\n*\n* melinda-rest-api-commons program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Affero General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-rest-api-commons is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Affero General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\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 = [\n {code: 'z', value: 'Käytettävissä vapaakappalekirjastoissa'},\n {code: '5', value: 'FI-Vapaa'}\n ];\n\n const f856sUrnWithLdSubfields = f856sUrn.filter(field => fieldHasLDSubfields(field, LD_SUBFIELDS));\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":";;;;;;AA8BA;AAAsC;AA7BtC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAGA,MAAMA,KAAK,GAAG,IAAAC,cAAiB,EAAC,6DAA6D,CAAC;AAC9F,MAAMC,SAAS,GAAGF,KAAK,CAACG,MAAM,CAAC,MAAM,CAAC;;AAEtC;AACO,SAASC,cAAc,CAACC,SAAS,EAAEC,OAAO,EAAE;EAEjD,IAAIA,OAAO,KAAK,IAAI,EAAE;IACpBN,KAAK,CAAE,8CAA6C,CAAC;IACrD,OAAOK,SAAS;EAClB;EAEAL,KAAK,CAAE,8BAA6B,CAAC;EACrCE,SAAS,CAAE,+BAA8BK,IAAI,CAACC,SAAS,CAACF,OAAO,CAAE,EAAC,CAAC;EAEnE,MAAM;IAACG,0BAA0B;IAAEC;EAA4B,CAAC,GAAGC,YAAY,CAACN,S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CAAC;IAC3GV,SAAS,CAAE,4BAA2BK,IAAI,CAACC,SAAS,CAAC2B,uBAAuB,CAAE,EAAC,CAAC;IAChF,OAAO,IAAI;EACb;EACA,OAAO,KAAK;AACd;AAEA,SAASC,mBAAmB,CAAChB,KAAK,EAAEiB,WAAW,EAAE;EAC/C,IAAIA,WAAW,CAACC,KAAK,CAACC,IAAI,IAAInB,KAAK,CAACK,SAAS,CAACC,IAAI,CAACc,EAAE,IAAIA,EAAE,CAACb,IAAI,KAAKY,IAAI,CAACZ,IAAI,IAAIa,EAAE,CAACZ,KAAK,KAAKW,IAAI,CAACX,KAAK,CAAC,CAAC,EAAE;IAC3G,OAAO,IAAI;EACb;AACF;AAEA,SAASV,kBAAkB,CAACE,KAAK,EAAE;EAEjC;EACA;EACA,IAAI,CAACqB,KAAK,CAACrB,KAAK,CAACI,GAAG,CAAC,IAAIkB,QAAQ,CAACtB,KAAK,CAACI,GAAG,EAAE,EAAE,CAAC,IAAI,EAAE,EAAE;IAEtD,MAAMmB,iBAAiB,GAAGvB,KAAK,CAACK,SAAS,CAACN,MAAM,CAACqB,EAAE,IAAIA,EAAE,CAACb,IAAI,KAAK,GAAG,IAAI,CAAE,kBAAkB,CAAEE,IAAI,CAACW,EAAE,CAACZ,KAAK,CAAC,CAAC;;IAE/G;IACA,IAAIe,iBAAiB,CAAC/B,MAAM,GAAG,CAAC,EAAE;MAChC,OAAO,KAAK;IACd;IAEA,OAAO;MACLY,GAAG,EAAEJ,KAAK,CAACI,GAAG;MACdoB,IAAI,EAAExB,KAAK,CAACwB,IAAI;MAChBC,IAAI,EAAEzB,KAAK,CAACyB,IAAI;MAChBpB,SAAS,EAAEkB;IACb,CAAC;EACH;EACA;EACA,OAAOvB,KAAK;AACd"}
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.stripF884s = stripF884s;
7
+ var _marcRecord = require("@natlibfi/marc-record");
8
+ var _debug = _interopRequireDefault(require("debug"));
9
+ var _fixUtils = require("./fix-utils");
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+ /**
12
+ *
13
+ * @licstart The following is the entire license notice for the JavaScript code in this file.
14
+ *
15
+ * Shared modules for microservices of Melinda rest api batch import system
16
+ *
17
+ * Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
18
+ *
19
+ * This file is part of melinda-rest-api-commons
20
+ *
21
+ * melinda-rest-api-commons program is free software: you can redistribute it and/or modify
22
+ * it under the terms of the GNU Affero General Public License as
23
+ * published by the Free Software Foundation, either version 3 of the
24
+ * License, or (at your option) any later version.
25
+ *
26
+ * melinda-rest-api-commons is distributed in the hope that it will be useful,
27
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
28
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29
+ * GNU Affero General Public License for more details.
30
+ *
31
+ * You should have received a copy of the GNU Affero General Public License
32
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
33
+ *
34
+ * @licend The above is the entire license notice
35
+ * for the JavaScript code in this file.
36
+ *
37
+ */
38
+
39
+ function stripF884s(newRecord, options) {
40
+ const debug = (0, _debug.default)('@natlibfi/melinda-rest-api-commons:fixRecord:stripF884s');
41
+ const debugData = debug.extend('data');
42
+ if (options !== true) {
43
+ debug(`NOT running stripF884s fixer, no options`);
44
+ return newRecord;
45
+ }
46
+ debug(`Running stripF884s fixer`);
47
+ debugData(`Options for stripF884s: ${JSON.stringify(options)}`);
48
+
49
+ // Handle only f884 with $5 MELINDA - let's no remove random f884s
50
+ const isMelindaf884 = f => f.tag === '884' && f.subfields.some(({
51
+ code,
52
+ value
53
+ }) => code === '5' && value === 'MELINDA');
54
+ const f884Melindas = newRecord.fields.filter(isMelindaf884);
55
+ debugData(`Melinda's f884s (${f884Melindas.length}) \n ${JSON.stringify(f884Melindas)}`);
56
+ if (f884Melindas.length < 2) {
57
+ debug(`Not enough Melinda's f884.s to filter (${f884Melindas.length})`);
58
+ return newRecord;
59
+ }
60
+
61
+ // Sort fields by date subfield $g, so we'll keep the oldest one
62
+ const sortedFields = (0, _fixUtils.sortFieldsBySubfieldValue)(f884Melindas, 'g');
63
+ debugData(`Melinda's f884s sorted by 'g' - oldest first: (${sortedFields.length}) \n ${JSON.stringify(sortedFields)}`);
64
+
65
+ // Drop fields that are similar without date subfield $g
66
+ const uniqFields = uniqWithOutSubfield(sortedFields, 'g');
67
+ debugData(`Melindas f884s uniqued without sf $g (${uniqFields.length}) \n ${JSON.stringify(uniqFields)}`);
68
+
69
+ // Replace original Melinda-f884s with remaining Melinda-f884s
70
+ // NOTE: this sorts MELINDA-f884s after possible other f884s
71
+ newRecord.removeFields(f884Melindas);
72
+ newRecord.insertFields(uniqFields);
73
+ return newRecord;
74
+
75
+ // Keep just first instance of each similar field, compare without subfield with subfieldCode
76
+ function uniqWithOutSubfield(fields, subfieldCode) {
77
+ return fields.reduce((uniq, field) => {
78
+ if (!uniq.some(f => _marcRecord.MarcRecord.isEqual((0, _fixUtils.removeSubfield)(f, subfieldCode), (0, _fixUtils.removeSubfield)(field, subfieldCode)))) {
79
+ // eslint-disable-line functional/no-conditional-statement
80
+ uniq.push(field); // eslint-disable-line functional/immutable-data
81
+ }
82
+
83
+ return uniq;
84
+ }, []);
85
+ }
86
+ }
87
+ //# sourceMappingURL=fix-strip-f884s.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fix-strip-f884s.js","names":["stripF884s","newRecord","options","debug","createDebugLogger","debugData","extend","JSON","stringify","isMelindaf884","f","tag","subfields","some","code","value","f884Melindas","fields","filter","length","sortedFields","sortFieldsBySubfieldValue","uniqFields","uniqWithOutSubfield","removeFields","insertFields","subfieldCode","reduce","uniq","field","MarcRecord","isEqual","removeSubfield","push"],"sources":["../../src/helpers/fix-strip-f884s.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Shared modules for microservices of Melinda rest api batch import system\n*\n* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-rest-api-commons\n*\n* melinda-rest-api-commons program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Affero General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-rest-api-commons is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Affero General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport createDebugLogger from 'debug';\nimport {sortFieldsBySubfieldValue, removeSubfield} from './fix-utils';\n\n\nexport function stripF884s(newRecord, options) {\n const debug = createDebugLogger('@natlibfi/melinda-rest-api-commons:fixRecord:stripF884s');\n const debugData = debug.extend('data');\n\n if (options !== true) {\n debug(`NOT running stripF884s fixer, no options`);\n return newRecord;\n }\n\n debug(`Running stripF884s fixer`);\n debugData(`Options for stripF884s: ${JSON.stringify(options)}`);\n\n // Handle only f884 with $5 MELINDA - let's no remove random f884s\n const isMelindaf884 = f => f.tag === '884' && f.subfields.some(({code, value}) => code === '5' && value === 'MELINDA');\n\n const f884Melindas = newRecord.fields.filter(isMelindaf884);\n debugData(`Melinda's f884s (${f884Melindas.length}) \\n ${JSON.stringify(f884Melindas)}`);\n\n if (f884Melindas.length < 2) {\n debug(`Not enough Melinda's f884.s to filter (${f884Melindas.length})`);\n return newRecord;\n }\n\n // Sort fields by date subfield $g, so we'll keep the oldest one\n const sortedFields = sortFieldsBySubfieldValue(f884Melindas, 'g');\n debugData(`Melinda's f884s sorted by 'g' - oldest first: (${sortedFields.length}) \\n ${JSON.stringify(sortedFields)}`);\n\n // Drop fields that are similar without date subfield $g\n const uniqFields = uniqWithOutSubfield(sortedFields, 'g');\n debugData(`Melindas f884s uniqued without sf $g (${uniqFields.length}) \\n ${JSON.stringify(uniqFields)}`);\n\n // Replace original Melinda-f884s with remaining Melinda-f884s\n // NOTE: this sorts MELINDA-f884s after possible other f884s\n newRecord.removeFields(f884Melindas);\n newRecord.insertFields(uniqFields);\n return newRecord;\n\n // Keep just first instance of each similar field, compare without subfield with subfieldCode\n function uniqWithOutSubfield(fields, subfieldCode) {\n return fields.reduce((uniq, field) => {\n if (!uniq.some(f => MarcRecord.isEqual(removeSubfield(f, subfieldCode), removeSubfield(field, subfieldCode)))) { // eslint-disable-line functional/no-conditional-statement\n uniq.push(field); // eslint-disable-line functional/immutable-data\n }\n\n return uniq;\n }, []);\n }\n}\n"],"mappings":";;;;;;AA4BA;AACA;AACA;AAAsE;AA9BtE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAOO,SAASA,UAAU,CAACC,SAAS,EAAEC,OAAO,EAAE;EAC7C,MAAMC,KAAK,GAAG,IAAAC,cAAiB,EAAC,yDAAyD,CAAC;EAC1F,MAAMC,SAAS,GAAGF,KAAK,CAACG,MAAM,CAAC,MAAM,CAAC;EAEtC,IAAIJ,OAAO,KAAK,IAAI,EAAE;IACpBC,KAAK,CAAE,0CAAyC,CAAC;IACjD,OAAOF,SAAS;EAClB;EAEAE,KAAK,CAAE,0BAAyB,CAAC;EACjCE,SAAS,CAAE,2BAA0BE,IAAI,CAACC,SAAS,CAACN,OAAO,CAAE,EAAC,CAAC;;EAE/D;EACA,MAAMO,aAAa,GAAGC,CAAC,IAAIA,CAAC,CAACC,GAAG,KAAK,KAAK,IAAID,CAAC,CAACE,SAAS,CAACC,IAAI,CAAC,CAAC;IAACC,IAAI;IAAEC;EAAK,CAAC,KAAKD,IAAI,KAAK,GAAG,IAAIC,KAAK,KAAK,SAAS,CAAC;EAEtH,M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CAAC;EACR;AACF"}
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.removeSubfield = removeSubfield;
7
+ exports.sortFieldsBySubfieldValue = sortFieldsBySubfieldValue;
8
+ /**
9
+ *
10
+ * @licstart The following is the entire license notice for the JavaScript code in this file.
11
+ *
12
+ * Shared modules for microservices of Melinda rest api batch import system
13
+ *
14
+ * Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
15
+ *
16
+ * This file is part of melinda-rest-api-commons
17
+ *
18
+ * melinda-rest-api-commons program is free software: you can redistribute it and/or modify
19
+ * it under the terms of the GNU Affero General Public License as
20
+ * published by the Free Software Foundation, either version 3 of the
21
+ * License, or (at your option) any later version.
22
+ *
23
+ * melinda-rest-api-commons is distributed in the hope that it will be useful,
24
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
25
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26
+ * GNU Affero General Public License for more details.
27
+ *
28
+ * You should have received a copy of the GNU Affero General Public License
29
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
30
+ *
31
+ * @licend The above is the entire license notice
32
+ * for the JavaScript code in this file.
33
+ *
34
+ */
35
+
36
+ function removeSubfield(field, code) {
37
+ // Handle non-numeric fields, and fields with a numeric tag of 010 and greater
38
+ // Aleph's FMT as a controlfield might be a problem
39
+ if (!isNaN(field.tag) && parseInt(field.tag, 10) >= 10) {
40
+ const filteredSubfields = field.subfields.filter(sf => sf.code !== code);
41
+
42
+ // Remove whole field if there are no subfields left
43
+ if (filteredSubfields.length < 1) {
44
+ return false;
45
+ }
46
+ return {
47
+ tag: field.tag,
48
+ ind1: field.ind1,
49
+ ind2: field.ind2,
50
+ subfields: filteredSubfields
51
+ };
52
+ }
53
+ // return controlFields as is
54
+ return field;
55
+ }
56
+
57
+ // sort fields by value of each fields first subfield with subfielCode
58
+ function sortFieldsBySubfieldValue(fields, subfieldCode) {
59
+ return [...fields].sort((a, b) => {
60
+ const a1value = getFirstSubfieldValue(a, subfieldCode);
61
+ const b1value = getFirstSubfieldValue(b, subfieldCode);
62
+ if (a1value && !b1value) {
63
+ return -1;
64
+ }
65
+ if (!a1value && b1value) {
66
+ return 1;
67
+ }
68
+ if (a1value > b1value) {
69
+ return 1;
70
+ }
71
+ if (b1value > a1value) {
72
+ return -1;
73
+ }
74
+ return 0;
75
+ });
76
+ // get value for the for instance of subfield with subfieldCode
77
+ function getFirstSubfieldValue(field, subfieldCode) {
78
+ const subs = field.subfields ? field.subfields.filter(subf => subf.code === subfieldCode) : [];
79
+ return subs.length > 0 ? subs[0].value : '';
80
+ }
81
+ }
82
+ //# sourceMappingURL=fix-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fix-utils.js","names":["removeSubfield","field","code","isNaN","tag","parseInt","filteredSubfields","subfields","filter","sf","length","ind1","ind2","sortFieldsBySubfieldValue","fields","subfieldCode","sort","a","b","a1value","getFirstSubfieldValue","b1value","subs","subf","value"],"sources":["../../src/helpers/fix-utils.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Shared modules for microservices of Melinda rest api batch import system\n*\n* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-rest-api-commons\n*\n* melinda-rest-api-commons program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Affero General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-rest-api-commons is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Affero General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\nexport function removeSubfield(field, code) {\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 !== code);\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// sort fields by value of each fields first subfield with subfielCode\nexport function sortFieldsBySubfieldValue(fields, subfieldCode) {\n return [...fields].sort((a, b) => {\n const a1value = getFirstSubfieldValue(a, subfieldCode);\n const b1value = getFirstSubfieldValue(b, subfieldCode);\n if (a1value && !b1value) {\n return -1;\n }\n if (!a1value && b1value) {\n return 1;\n }\n if (a1value > b1value) {\n return 1;\n }\n if (b1value > a1value) {\n return -1;\n }\n return 0;\n });\n // get value for the for instance of subfield with subfieldCode\n function getFirstSubfieldValue(field, subfieldCode) {\n const subs = field.subfields ? field.subfields.filter(subf => subf.code === subfieldCode) : [];\n return subs.length > 0 ? subs[0].value : '';\n }\n}\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEO,SAASA,cAAc,CAACC,KAAK,EAAEC,IAAI,EAAE;EAE1C;EACA;EACA,IAAI,CAACC,KAAK,CAACF,KAAK,CAACG,GAAG,CAAC,IAAIC,QAAQ,CAACJ,KAAK,CAACG,GAAG,EAAE,EAAE,CAAC,IAAI,EAAE,EAAE;IAEtD,MAAME,iBAAiB,GAAGL,KAAK,CAACM,SAAS,CAACC,MAAM,CAACC,EAAE,IAAIA,EAAE,CAACP,IAAI,KAAKA,IAAI,CAAC;;IAExE;IACA,IAAII,iBAAiB,CAACI,MAAM,GAAG,CAAC,EAAE;MAChC,OAAO,KAAK;IACd;IAE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