@natlibfi/melinda-rest-api-commons 2.0.2 → 2.1.0

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.
@@ -37,7 +37,7 @@ var _melindaBackendCommons = require("@natlibfi/melinda-backend-commons");
37
37
  * for the JavaScript code in this file.
38
38
  *
39
39
  */
40
- function formatRecord(record, settings) {
40
+ function formatRecord(record, settings = []) {
41
41
  const logger = (0, _melindaBackendCommons.createLogger)();
42
42
  logger.verbose('Applying formating');
43
43
 
@@ -45,10 +45,11 @@ function formatRecord(record, settings) {
45
45
  subfieldValues: false
46
46
  });
47
47
 
48
+ generateMissingSIDs();
48
49
  settings.forEach(options => {
49
50
  replacePrefixes(options);
50
51
  });
51
- return newRecord; // Replace prefix in all specified subfields
52
+ return newRecord.toObject(); // Replace prefix in all specified subfields
52
53
 
53
54
  function replacePrefixes(options) {
54
55
  const {
@@ -66,6 +67,67 @@ function formatRecord(record, settings) {
66
67
  });
67
68
  });
68
69
  }
70
+
71
+ function generateMissingSIDs() {
72
+ const f035Filters = [/^\(FI-BTJ\)/u, /^\(FI-TATI\)/u];
73
+ const fSIDFilters = ['FI-BTJ', 'tati'];
74
+ const f035s = f035ToSidInfo(newRecord.get(/^035$/u));
75
+ const fSIDs = sidsToSidInfo(newRecord.get(/^SID$/u));
76
+ const sidsToBeAdded = genNewSids(fSIDs.length === 0 ? f035s // test that SIDs are not there yet
77
+ : f035s.filter(f035SidInfo => fSIDs.some(fSIDInfo => f035SidInfo.SID !== fSIDInfo.SID && f035SidInfo.value !== fSIDInfo.value))); // Add new SIDs
78
+
79
+ return sidsToBeAdded.forEach(sidField => newRecord.insertField(sidField));
80
+
81
+ function genNewSids(sidsToBeAdded) {
82
+ return sidsToBeAdded.map(sidInfo => ({
83
+ tag: 'SID',
84
+ ind1: ' ',
85
+ ind2: ' ',
86
+ subfields: [{
87
+ code: 'c',
88
+ value: sidInfo.value
89
+ }, {
90
+ code: 'b',
91
+ value: sidInfo.SID
92
+ }]
93
+ }));
94
+ }
95
+
96
+ function sidsToSidInfo(SIDs) {
97
+ return SIDs.flatMap(({
98
+ subfields
99
+ }) => {
100
+ const [SID] = subfields.filter(sub => sub.code === 'b' && fSIDFilters.includes(sub.value)).map(sub => sub.value);
101
+ const [value] = subfields.filter(sub => sub.code === 'c' && sub.value !== undefined).map(sub => sub.value);
102
+
103
+ if (SID && value) {
104
+ return {
105
+ SID,
106
+ value
107
+ };
108
+ }
109
+
110
+ return undefined;
111
+ }).filter(value => value !== undefined);
112
+ }
113
+
114
+ function f035ToSidInfo(f035s) {
115
+ return f035s.flatMap(({
116
+ subfields
117
+ }) => {
118
+ const [wantedSub] = subfields.filter(sub => sub.code === 'a' && f035Filters.some(regexp => regexp.test(sub.value)));
119
+
120
+ if (wantedSub) {
121
+ return {
122
+ SID: fSIDFilters[f035Filters.findIndex(regexp => regexp.test(wantedSub.value))],
123
+ value: wantedSub.value.slice(wantedSub.value.indexOf(')') + 1)
124
+ };
125
+ }
126
+
127
+ return undefined;
128
+ }).filter(value => value !== undefined);
129
+ }
130
+ }
69
131
  } // If placed in config.js testing needs envs
70
132
 
71
133
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/helpers/format.js"],"names":["formatRecord","record","settings","logger","verbose","newRecord","MarcRecord","clone","subfieldValues","forEach","options","replacePrefixes","oldPrefix","newPrefix","prefixReplaceCodes","pattern","replacement","getDatafields","field","subfields","filter","code","includes","subfield","value","replace","BIB_FORMAT_SETTINGS"],"mappings":";;;;;;;;AA4BA;;AACA;;AA7BA;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;AAKO,SAASA,YAAT,CAAsBC,MAAtB,EAA8BC,QAA9B,EAAwC;AAC7C,QAAMC,MAAM,GAAG,0CAAf;AAEAA,EAAAA,MAAM,CAACC,OAAP,CAAe,oBAAf;;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B,EAAE,CAAC,GAAD;AAHtB,CAXiC,CAA5B","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 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 {createLogger} from '@natlibfi/melinda-backend-commons';\n\nexport function formatRecord(record, settings) {\n const logger = createLogger();\n\n logger.verbose('Applying formating');\n const newRecord = MarcRecord.clone(record, {subfieldValues: false});\n\n settings.forEach(options => {\n replacePrefixes(options);\n });\n\n return newRecord;\n\n // Replace prefix in all specified subfields\n function replacePrefixes(options) {\n const {oldPrefix, newPrefix, prefixReplaceCodes} = options;\n const pattern = `(${oldPrefix})`;\n const replacement = `(${newPrefix})`;\n newRecord.getDatafields()\n .forEach(field => {\n field.subfields\n .filter(({code}) => prefixReplaceCodes.includes(code))\n .forEach(subfield => {\n subfield.value = subfield.value.replace(pattern, replacement); // eslint-disable-line functional/immutable-data\n });\n });\n }\n}\n\n// If placed in config.js testing needs envs\nexport const BIB_FORMAT_SETTINGS = [\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"],"file":"format.js"}
1
+ {"version":3,"sources":["../../src/helpers/format.js"],"names":["formatRecord","record","settings","logger","verbose","newRecord","MarcRecord","clone","subfieldValues","generateMissingSIDs","forEach","options","replacePrefixes","toObject","oldPrefix","newPrefix","prefixReplaceCodes","pattern","replacement","getDatafields","field","subfields","filter","code","includes","subfield","value","replace","f035Filters","fSIDFilters","f035s","f035ToSidInfo","get","fSIDs","sidsToSidInfo","sidsToBeAdded","genNewSids","length","f035SidInfo","some","fSIDInfo","SID","sidField","insertField","map","sidInfo","tag","ind1","ind2","SIDs","flatMap","sub","undefined","wantedSub","regexp","test","findIndex","slice","indexOf","BIB_FORMAT_SETTINGS"],"mappings":";;;;;;;;AA4BA;;AACA;;AA7BA;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;AAKO,SAASA,YAAT,CAAsBC,MAAtB,EAA8BC,QAAQ,GAAG,EAAzC,EAA6C;AAClD,QAAMC,MAAM,GAAG,0CAAf;AAEAA,EAAAA,MAAM,CAACC,OAAP,CAAe,oBAAf;;AACA,QAAMC,SAAS,GAAGC,uBAAWC,KAAX,CAAiBN,MAAjB,EAAyB;AAACO,IAAAA,cAAc,EAAE;AAAjB,GAAzB,CAAlB;;AAEAC,EAAAA,mBAAmB;AAEnBP,EAAAA,QAAQ,CAACQ,OAAT,CAAiBC,OAAO,IAAI;AAC1BC,IAAAA,eAAe,CAACD,OAAD,CAAf;AACD,GAFD;AAIA,SAAON,SAAS,CAACQ,QAAV,EAAP,CAZkD,CAclD;;AACA,WAASD,eAAT,CAAyBD,OAAzB,EAAkC;AAChC,UAAM;AAACG,MAAAA,SAAD;AAAYC,MAAAA,SAAZ;AAAuBC,MAAAA;AAAvB,QAA6CL,OAAnD;AACA,UAAM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AAC5B,aAAOA,KAAK,CAACoB,OAAN,CAAc,CAAC;AAAC7B,QAAAA;AAAD,OAAD,KAAiB;AACpC,cAAM,CAACgC,SAAD,IAAchC,SAAS,CAACC,MAAV,CAAiB6B,GAAG,IAAIA,GAAG,CAAC5B,IAAJ,KAAa,GAAb,IAAoBK,WAAW,CAACW,IAAZ,CAAiBe,MAAM,IAAIA,MAAM,CAACC,IAAP,CAAYJ,GAAG,CAACzB,KAAhB,CAA3B,CAA5C,CAApB;;AAEA,YAAI2B,SAAJ,EAAe;AACb,iBAAO;AACLZ,YAAAA,GAAG,EAAEZ,WAAW,CAACD,WAAW,CAAC4B,SAAZ,CAAsBF,MAAM,IAAIA,MAAM,CAACC,IAAP,CAAYF,SAAS,CAAC3B,KAAtB,CAAhC,CAAD,CADX;AAELA,YAAAA,KAAK,EAAE2B,SAAS,CAAC3B,KAAV,CAAgB+B,KAAhB,CAAsBJ,SAAS,CAAC3B,KAAV,CAAgBgC,OAAhB,CAAwB,GAAxB,IAA+B,CAArD;AAFF,WAAP;AAID;;AAED,eAAON,SAAP;AACD,OAXM,EAWJ9B,MAXI,CAWGI,KAAK,IAAIA,KAAK,KAAK0B,SAXtB,CAAP;AAYD;AACF;AACF,C,CAED;;;AACO,MAAMO,mBAAmB,GAAG,CACjC;AACE7C,EAAAA,SAAS,EAAE,YADb;AAEEC,EAAAA,SAAS,EAAE,OAFb;AAGEC,EAAAA,kBAAkB,EAAE,CAAC,GAAD;AAHtB,CADiC,EAMjC;AACEF,EAAAA,SAAS,EAAE,aADb;AAEEC,EAAAA,SAAS,EAAE,OAFb;AAGEC,EAAAA,kBAAkB,EAAE,CAAC,GAAD;AAHtB,CANiC,EAWjC;AACEF,EAAAA,SAAS,EAAE,aADb;AAEEC,EAAAA,SAAS,EAAE,OAFb;AAGEC,EAAAA,kBAAkB,EAAE,CAAC,GAAD;AAHtB,CAXiC,CAA5B","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 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 {createLogger} from '@natlibfi/melinda-backend-commons';\n\nexport function formatRecord(record, settings = []) {\n const logger = createLogger();\n\n logger.verbose('Applying formating');\n const newRecord = MarcRecord.clone(record, {subfieldValues: false});\n\n generateMissingSIDs();\n\n settings.forEach(options => {\n replacePrefixes(options);\n });\n\n return newRecord.toObject();\n\n // Replace prefix in all specified subfields\n function replacePrefixes(options) {\n const {oldPrefix, newPrefix, prefixReplaceCodes} = options;\n const pattern = `(${oldPrefix})`;\n const replacement = `(${newPrefix})`;\n newRecord.getDatafields()\n .forEach(field => {\n field.subfields\n .filter(({code}) => prefixReplaceCodes.includes(code))\n .forEach(subfield => {\n subfield.value = subfield.value.replace(pattern, replacement); // eslint-disable-line functional/immutable-data\n });\n });\n }\n\n\n function generateMissingSIDs() {\n const f035Filters = [/^\\(FI-BTJ\\)/u, /^\\(FI-TATI\\)/u];\n const fSIDFilters = ['FI-BTJ', 'tati'];\n const f035s = f035ToSidInfo(newRecord.get(/^035$/u));\n const fSIDs = sidsToSidInfo(newRecord.get(/^SID$/u));\n\n const sidsToBeAdded = genNewSids(fSIDs.length === 0\n ? f035s\n // test that SIDs are not there yet\n : f035s.filter(f035SidInfo => fSIDs.some(fSIDInfo => f035SidInfo.SID !== fSIDInfo.SID && f035SidInfo.value !== fSIDInfo.value)));\n\n // Add new SIDs\n return sidsToBeAdded.forEach(sidField => newRecord.insertField(sidField));\n\n function genNewSids(sidsToBeAdded) {\n return sidsToBeAdded.map(sidInfo => ({tag: 'SID', ind1: ' ', ind2: ' ', subfields: [{code: 'c', value: sidInfo.value}, {code: 'b', value: sidInfo.SID}]}));\n }\n\n function sidsToSidInfo(SIDs) {\n return SIDs.flatMap(({subfields}) => {\n const [SID] = subfields.filter(sub => sub.code === 'b' && fSIDFilters.includes(sub.value)).map(sub => sub.value);\n const [value] = subfields.filter(sub => sub.code === 'c' && sub.value !== undefined).map(sub => sub.value);\n\n if (SID && value) {\n return {\n SID,\n value\n };\n }\n\n return undefined;\n }).filter(value => value !== undefined);\n }\n\n function f035ToSidInfo(f035s) {\n return f035s.flatMap(({subfields}) => {\n const [wantedSub] = subfields.filter(sub => sub.code === 'a' && f035Filters.some(regexp => regexp.test(sub.value)));\n\n if (wantedSub) {\n return {\n SID: fSIDFilters[f035Filters.findIndex(regexp => regexp.test(wantedSub.value))],\n value: wantedSub.value.slice(wantedSub.value.indexOf(')') + 1)\n };\n }\n\n return undefined;\n }).filter(value => value !== undefined);\n }\n }\n}\n\n// If placed in config.js testing needs envs\nexport const BIB_FORMAT_SETTINGS = [\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"],"file":"format.js"}
@@ -2,13 +2,15 @@
2
2
 
3
3
  var _chai = require("chai");
4
4
 
5
- var _fixura = _interopRequireDefault(require("@natlibfi/fixura"));
5
+ var _fixura = _interopRequireWildcard(require("@natlibfi/fixura"));
6
6
 
7
7
  var _marcRecord = require("@natlibfi/marc-record");
8
8
 
9
9
  var _format = require("./format");
10
10
 
11
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
12
+
13
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
12
14
 
13
15
  /**
14
16
  *
@@ -42,48 +44,79 @@ describe('services/format', () => {
42
44
  const {
43
45
  getFixture
44
46
  } = (0, _fixura.default)({
45
- root: FIXTURES_PATH
47
+ root: FIXTURES_PATH,
48
+ reader: _fixura.READERS.JSON
46
49
  });
47
50
  describe('fiAsteriN0Fin11', () => {
48
51
  it('Should succeed', () => {
49
- const record = new _marcRecord.MarcRecord(JSON.parse(getFixture({
52
+ const record = new _marcRecord.MarcRecord(getFixture({
50
53
  components: ['in', 'fiAsteriN0Fin11.json']
51
- })));
54
+ }));
52
55
  const result = (0, _format.formatRecord)(record.toObject(), _format.BIB_FORMAT_SETTINGS);
53
56
  const expected = getFixture({
54
57
  components: ['out', 'fiAsteriN0Fin11.json']
55
58
  });
56
- const stringResult = JSON.stringify({ ...result
57
- }, undefined, 2);
58
- (0, _chai.expect)(stringResult).to.eql(expected);
59
+ (0, _chai.expect)(result).to.eql(expected);
59
60
  });
60
61
  });
61
62
  describe('fiAsteriS0Fin10', () => {
62
63
  it('Should succeed', () => {
63
- const record = new _marcRecord.MarcRecord(JSON.parse(getFixture({
64
+ const record = new _marcRecord.MarcRecord(getFixture({
64
65
  components: ['in', 'fiAsteriS0Fin10.json']
65
- })));
66
+ }));
66
67
  const result = (0, _format.formatRecord)(record.toObject(), _format.BIB_FORMAT_SETTINGS);
67
68
  const expected = getFixture({
68
69
  components: ['out', 'fiAsteriS0Fin10.json']
69
70
  });
70
- const stringResult = JSON.stringify({ ...result
71
- }, undefined, 2);
72
- (0, _chai.expect)(stringResult).to.eql(expected);
71
+ (0, _chai.expect)(result).to.eql(expected);
73
72
  });
74
73
  });
75
74
  describe('fiMelindaWFin01', () => {
76
75
  it('Should succeed', () => {
77
- const record = new _marcRecord.MarcRecord(JSON.parse(getFixture({
76
+ const record = new _marcRecord.MarcRecord(getFixture({
78
77
  components: ['in', 'fiMelindaWFin01.json']
79
- })));
78
+ }));
80
79
  const result = (0, _format.formatRecord)(record.toObject(), _format.BIB_FORMAT_SETTINGS);
81
80
  const expected = getFixture({
82
81
  components: ['out', 'fiMelindaWFin01.json']
83
82
  });
84
- const stringResult = JSON.stringify({ ...result
85
- }, undefined, 2);
86
- (0, _chai.expect)(stringResult).to.eql(expected);
83
+ (0, _chai.expect)(result).to.eql(expected);
84
+ });
85
+ });
86
+ describe('f035fibtj', () => {
87
+ it('Should add FI-BTJ SID', () => {
88
+ const record = new _marcRecord.MarcRecord(getFixture({
89
+ components: ['in', 'f035fibtj.json']
90
+ }));
91
+ const result = (0, _format.formatRecord)(record.toObject());
92
+ const expected = getFixture({
93
+ components: ['out', 'f035fibtj.json']
94
+ });
95
+ (0, _chai.expect)(result).to.eql(expected);
96
+ });
97
+ });
98
+ describe('f035tati', () => {
99
+ it('Should add tati SID', () => {
100
+ const record = new _marcRecord.MarcRecord(getFixture({
101
+ components: ['in', 'f035tati.json']
102
+ }));
103
+ const result = (0, _format.formatRecord)(record.toObject());
104
+ const expected = getFixture({
105
+ components: ['out', 'f035tati.json']
106
+ });
107
+ (0, _chai.expect)(result).to.eql(expected);
108
+ });
109
+ });
110
+ describe('f035fibtjAndTati', () => {
111
+ it('Should add tati SID and skip FI-BTJ SID', () => {
112
+ const record = new _marcRecord.MarcRecord(getFixture({
113
+ components: ['in', 'f035fibtjAndTati.json']
114
+ }));
115
+ const result = (0, _format.formatRecord)(record.toObject());
116
+ const expected = getFixture({
117
+ components: ['out', 'f035fibtjAndTati.json']
118
+ });
119
+ (0, _chai.expect)(result).to.eql(expected);
87
120
  });
88
121
  });
89
122
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/helpers/format.spec.js"],"names":["describe","FIXTURES_PATH","__dirname","getFixture","root","it","record","MarcRecord","JSON","parse","components","result","toObject","BIB_FORMAT_SETTINGS","expected","stringResult","stringify","undefined","to","eql"],"mappings":";;AA4BA;;AACA;;AACA;;AACA;;;;AA/BA;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;AAOAA,QAAQ,CAAC,iBAAD,EAAoB,MAAM;AAChC,QAAMC,aAAa,GAAG,CACpBC,SADoB,EAEpB,IAFoB,EAGpB,IAHoB,EAIpB,eAJoB,EAKpB,QALoB,CAAtB;AAOA,QAAM;AAACC,IAAAA;AAAD,MAAe,qBAAe;AAACC,IAAAA,IAAI,EAAEH;AAAP,GAAf,CAArB;AAEAD,EAAAA,QAAQ,CAAC,iBAAD,EAAoB,MAAM;AAChCK,IAAAA,EAAE,CAAC,gBAAD,EAAmB,MAAM;AACzB,YAAMC,MAAM,GAAG,IAAIC,sBAAJ,CAAeC,IAAI,CAACC,KAAL,CAAWN,UAAU,CAAC;AAClDO,QAAAA,UAAU,EAAE,CACV,IADU,EAEV,sBAFU;AAD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AJ,CAAeC,IAAI,CAACC,KAAL,CAAWN,UAAU,CAAC;AAClDO,QAAAA,UAAU,EAAE,CACV,IADU,EAEV,sBAFU;AADsC,OAAD,CAArB,CAAf,CAAf;AAMA,YAAMC,MAAM,GAAG,0BAAaL,MAAM,CAACM,QAAP,EAAb,EAAgCC,2BAAhC,CAAf;AACA,YAAMC,QAAQ,GAAGX,UAAU,CAAC;AAC1BO,QAAAA,UAAU,EAAE,CACV,KADU,EAEV,sBAFU;AADc,OAAD,CAA3B;AAMA,YAAMK,YAAY,GAAGP,IAAI,CAACQ,SAAL,CAAe,EAAC,GAAGL;AAAJ,OAAf,EAA4BM,SAA5B,EAAuC,CAAvC,CAArB;AACA,wBAAOF,YAAP,EAAqBG,EAArB,CAAwBC,GAAxB,CAA4BL,QAA5B;AACD,KAhBC,CAAF;AAiBD,GAlBO,CAAR;AAmBD,CArEO,CAAR","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 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 {formatRecord, BIB_FORMAT_SETTINGS} from './format';\n\ndescribe('services/format', () => {\n const FIXTURES_PATH = [\n __dirname,\n '..',\n '..',\n 'test-fixtures',\n 'format'\n ];\n const {getFixture} = fixtureFactory({root: FIXTURES_PATH});\n\n describe('fiAsteriN0Fin11', () => {\n it('Should succeed', () => {\n const record = new MarcRecord(JSON.parse(getFixture({\n components: [\n 'in',\n 'fiAsteriN0Fin11.json'\n ]\n })));\n const result = formatRecord(record.toObject(), BIB_FORMAT_SETTINGS);\n const expected = getFixture({\n components: [\n 'out',\n 'fiAsteriN0Fin11.json'\n ]\n });\n const stringResult = JSON.stringify({...result}, undefined, 2);\n expect(stringResult).to.eql(expected);\n });\n });\n\n describe('fiAsteriS0Fin10', () => {\n it('Should succeed', () => {\n const record = new MarcRecord(JSON.parse(getFixture({\n components: [\n 'in',\n 'fiAsteriS0Fin10.json'\n ]\n })));\n const result = formatRecord(record.toObject(), BIB_FORMAT_SETTINGS);\n const expected = getFixture({\n components: [\n 'out',\n 'fiAsteriS0Fin10.json'\n ]\n });\n const stringResult = JSON.stringify({...result}, undefined, 2);\n expect(stringResult).to.eql(expected);\n });\n });\n\n describe('fiMelindaWFin01', () => {\n it('Should succeed', () => {\n const record = new MarcRecord(JSON.parse(getFixture({\n components: [\n 'in',\n 'fiMelindaWFin01.json'\n ]\n })));\n const result = formatRecord(record.toObject(), BIB_FORMAT_SETTINGS);\n const expected = getFixture({\n components: [\n 'out',\n 'fiMelindaWFin01.json'\n ]\n });\n const stringResult = JSON.stringify({...result}, undefined, 2);\n expect(stringResult).to.eql(expected);\n });\n });\n});\n"],"file":"format.spec.js"}
1
+ {"version":3,"sources":["../../src/helpers/format.spec.js"],"names":["describe","FIXTURES_PATH","__dirname","getFixture","root","reader","READERS","JSON","it","record","MarcRecord","components","result","toObject","BIB_FORMAT_SETTINGS","expected","to","eql"],"mappings":";;AA4BA;;AACA;;AACA;;AACA;;;;;;AA/BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;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,EAAwB,MAAM;AAC9B,YAAMC,MAAM,GAAG,IAAIC,sBAAJ,CAAeP,UAAU,CAAC;AACvCQ,QAAAA,UAAU,EAAE,CACV,IADU,EAEV,eAFU;AAD2B,OAAD,CAAzB,CAAf;AAMA,YAAMC,MAAM,GAAG,0BAAaH,MAAM,CAACI,QAAP,EAAb,CAAf;AACA,YAAME,QAAQ,GAAGZ,UAAU,CAAC;AAC1BQ,QAAAA,UAAU,EAAE,CACV,KADU,EAEV,eAFU;AADc,OAAD,CAA3B;AAOA,wBAAOC,MAAP,EAAeI,EAAf,CAAkBC,GAAlB,CAAsBF,QAAtB;AACD,KAhBC,CAAF;AAiBD,GAlBO,CAAR;AAoBAf,EAAAA,QAAQ,CAAC,kBAAD,EAAqB,MAAM;AACjCQ,IAAAA,EAAE,CAAC,yCAAD,EAA4C,MAAM;AAClD,YAAMC,MAAM,GAAG,IAAIC,sBAAJ,CAAeP,UAAU,CAAC;AACvCQ,QAAAA,UAAU,EAAE,CACV,IADU,EAEV,uBAFU;AAD2B,OAAD,CAAzB,CAAf;AAMA,YAAMC,MAAM,GAAG,0BAAaH,MAAM,CAACI,QAAP,EAAb,CAAf;AACA,YAAME,QAAQ,GAAGZ,UAAU,CAAC;AAC1BQ,QAAAA,UAAU,EAAE,CACV,KADU,EAEV,uBAFU;AADc,OAAD,CAA3B;AAOA,wBAAOC,MAAP,EAAeI,EAAf,CAAkBC,GAAlB,CAAsBF,QAAtB;AACD,KAhBC,CAAF;AAiBD,GAlBO,CAAR;AAmBD,CAjIO,CAAR","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 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, {READERS} from '@natlibfi/fixura';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport {formatRecord, BIB_FORMAT_SETTINGS} from './format';\n\ndescribe('services/format', () => {\n const FIXTURES_PATH = [\n __dirname,\n '..',\n '..',\n 'test-fixtures',\n 'format'\n ];\n const {getFixture} = fixtureFactory({root: FIXTURES_PATH, reader: READERS.JSON});\n\n describe('fiAsteriN0Fin11', () => {\n it('Should succeed', () => {\n const record = new MarcRecord(getFixture({\n components: [\n 'in',\n 'fiAsteriN0Fin11.json'\n ]\n }));\n const result = formatRecord(record.toObject(), BIB_FORMAT_SETTINGS);\n const expected = getFixture({\n components: [\n 'out',\n 'fiAsteriN0Fin11.json'\n ]\n });\n\n expect(result).to.eql(expected);\n });\n });\n\n describe('fiAsteriS0Fin10', () => {\n it('Should succeed', () => {\n const record = new MarcRecord(getFixture({\n components: [\n 'in',\n 'fiAsteriS0Fin10.json'\n ]\n }));\n const result = formatRecord(record.toObject(), BIB_FORMAT_SETTINGS);\n const expected = getFixture({\n components: [\n 'out',\n 'fiAsteriS0Fin10.json'\n ]\n });\n\n expect(result).to.eql(expected);\n });\n });\n\n describe('fiMelindaWFin01', () => {\n it('Should succeed', () => {\n const record = new MarcRecord(getFixture({\n components: [\n 'in',\n 'fiMelindaWFin01.json'\n ]\n }));\n const result = formatRecord(record.toObject(), BIB_FORMAT_SETTINGS);\n const expected = getFixture({\n components: [\n 'out',\n 'fiMelindaWFin01.json'\n ]\n });\n\n expect(result).to.eql(expected);\n });\n });\n\n describe('f035fibtj', () => {\n it('Should add FI-BTJ SID', () => {\n const record = new MarcRecord(getFixture({\n components: [\n 'in',\n 'f035fibtj.json'\n ]\n }));\n const result = formatRecord(record.toObject());\n const expected = getFixture({\n components: [\n 'out',\n 'f035fibtj.json'\n ]\n });\n\n expect(result).to.eql(expected);\n });\n });\n\n describe('f035tati', () => {\n it('Should add tati SID', () => {\n const record = new MarcRecord(getFixture({\n components: [\n 'in',\n 'f035tati.json'\n ]\n }));\n const result = formatRecord(record.toObject());\n const expected = getFixture({\n components: [\n 'out',\n 'f035tati.json'\n ]\n });\n\n expect(result).to.eql(expected);\n });\n });\n\n describe('f035fibtjAndTati', () => {\n it('Should add tati SID and skip FI-BTJ SID', () => {\n const record = new MarcRecord(getFixture({\n components: [\n 'in',\n 'f035fibtjAndTati.json'\n ]\n }));\n const result = formatRecord(record.toObject());\n const expected = getFixture({\n components: [\n 'out',\n 'f035fibtjAndTati.json'\n ]\n });\n\n expect(result).to.eql(expected);\n });\n });\n});\n"],"file":"format.spec.js"}
@@ -2,7 +2,7 @@
2
2
 
3
3
  var _chai = require("chai");
4
4
 
5
- var _fixura = _interopRequireDefault(require("@natlibfi/fixura"));
5
+ var _fixura = _interopRequireWildcard(require("@natlibfi/fixura"));
6
6
 
7
7
  var _marcRecord = require("@natlibfi/marc-record");
8
8
 
@@ -10,6 +10,10 @@ var _validation = _interopRequireDefault(require("./validation"));
10
10
 
11
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
12
 
13
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
14
+
15
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
16
+
13
17
  /**
14
18
  *
15
19
  * @licstart The following is the entire license notice for the JavaScript code in this file.
@@ -42,37 +46,34 @@ describe('services/validate', () => {
42
46
  const {
43
47
  getFixture
44
48
  } = (0, _fixura.default)({
45
- root: FIXTURES_PATH
49
+ root: FIXTURES_PATH,
50
+ reader: _fixura.READERS.JSON
46
51
  });
47
52
  describe('f003-fi-melinda', () => {
48
53
  it('Should have failed: false', async () => {
49
54
  const validator = await (0, _validation.default)();
50
- const record = new _marcRecord.MarcRecord(JSON.parse(getFixture({
55
+ const record = new _marcRecord.MarcRecord(getFixture({
51
56
  components: ['in', 'f003-fi-melinda.json']
52
- })));
57
+ }));
53
58
  const result = await validator(record.toObject());
54
59
  const expected = getFixture({
55
60
  components: ['out', 'f003-fi-melinda.json']
56
61
  });
57
- const stringResult = JSON.stringify({ ...result
58
- }, undefined, 2);
59
- (0, _chai.expect)(stringResult).to.eql(expected);
62
+ (0, _chai.expect)(result).to.eql(expected);
60
63
  (0, _chai.expect)(result.failed).to.equal(false);
61
64
  });
62
65
  });
63
66
  describe('f003-not-fi-melinda', () => {
64
67
  it('Should have failed: true', async () => {
65
68
  const validator = await (0, _validation.default)();
66
- const record = new _marcRecord.MarcRecord(JSON.parse(getFixture({
69
+ const record = new _marcRecord.MarcRecord(getFixture({
67
70
  components: ['in', 'f003-not-fi-melinda.json']
68
- })));
71
+ }));
69
72
  const result = await validator(record.toObject());
70
73
  const expected = getFixture({
71
74
  components: ['out', 'f003-not-fi-melinda.json']
72
75
  });
73
- const stringResult = JSON.stringify({ ...result
74
- }, undefined, 2);
75
- (0, _chai.expect)(stringResult).to.eql(expected);
76
+ (0, _chai.expect)(result).to.eql(expected);
76
77
  (0, _chai.expect)(result.failed).to.equal(true);
77
78
  });
78
79
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/helpers/validation.spec.js"],"names":["describe","FIXTURES_PATH","__dirname","getFixture","root","it","validator","record","MarcRecord","JSON","parse","components","result","toObject","expected","stringResult","stringify","undefined","to","eql","failed","equal"],"mappings":";;AA4BA;;AACA;;AACA;;AACA;;;;AA/BA;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;AAOAA,QAAQ,CAAC,mBAAD,EAAsB,MAAM;AAClC,QAAMC,aAAa,GAAG,CACpBC,SADoB,EAEpB,IAFoB,EAGpB,IAHoB,EAIpB,eAJoB,EAKpB,YALoB,CAAtB;AAOA,QAAM;AAACC,IAAAA;AAAD,MAAe,qBAAe;AAACC,IAAAA,IAAI,EAAEH;AAAP,GAAf,CAArB;AAEAD,EAAAA,QAAQ,CAAC,iBAAD,EAAoB,MAAM;AAChCK,IAAAA,EAAE,CAAC,2BAAD,EAA8B,YAAY;AAC1C,YAAMC,SAAS,GAAG,MAAM,0BAAxB;AACA,YAAMC,MAAM,GAAG,IAAIC,sBAAJ,CAAeC,IAAI,CAACC,KAAL,CAAWP,UAAU,CAAC;AAClDQ,QAAAA,UAAU,EAAE,CACV,IADU,EAEV,sBAFU;AADsC,OAAD,CAArB,CAAf,CAAf;AAMA,YAAMC,MAAM,GAAG,MAAMN,SAAS,CAACC,MAAM,CAACM,QAAP,EAAD,CAA9B;AACA,YAAMC,QAAQ,GAAGX,UAAU,CAAC;AAC1BQ,QAAAA,UAAU,EAAE,CACV,KADU,EAEV,sBAFU;AADc,OAAD,CAA3B;AAMA,YAAMI,YAAY,GAAGN,IAAI,CAACO,SAAL,CAAe,EAAC,GAAGJ;AAAJ,OAAf,EAA4BK,SAA5B,EAAuC,CAAvC,CAArB;AACA,wBAAOF,YAAP,EAAqBG,EAArB,CAAwBC,GAAxB,CAA4BL,QAA5B;AACA,wBAAOF,MAAM,CAACQ,MAAd,EAAsBF,EAAtB,CAAyBG,KAAzB,CAA+B,KAA/B;AACD,KAlBC,CAAF;AAmBD,GApBO,CAAR;AAsBArB,EAAAA,QAAQ,CAAC,qBAAD,EAAwB,MAAM;AACpCK,IAAAA,EAAE,CAAC,0BAAD,EAA6B,YAAY;AACzC,YAAMC,SAAS,GAAG,MAAM,0BAAxB;AACA,YAAMC,MAAM,GAAG,IAAIC,sBAAJ,CAAeC,IAAI,CAACC,KAAL,CAAWP,UAAU,CAAC;AAClDQ,QAAAA,UAAU,EAAE,CACV,IADU,EAEV,0BAFU;AADsC,OAAD,CAArB,CAAf,CAAf;AAMA,YAAMC,MAAM,GAAG,MAAMN,SAAS,CAACC,MAAM,CAACM,QAAP,EAAD,CAA9B;AACA,YAAMC,QAAQ,GAAGX,UAAU,CAAC;AAC1BQ,QAAAA,UAAU,EAAE,CACV,KADU,EAEV,0BAFU;AADc,OAAD,CAA3B;AAMA,YAAMI,YAAY,GAAGN,IAAI,CAACO,SAAL,CAAe,EAAC,GAAGJ;AAAJ,OAAf,EAA4BK,SAA5B,EAAuC,CAAvC,CAArB;AACA,wBAAOF,YAAP,EAAqBG,EAArB,CAAwBC,GAAxB,CAA4BL,QAA5B;AACA,wBAAOF,MAAM,CAACQ,MAAd,EAAsBF,EAAtB,CAAyBG,KAAzB,CAA+B,IAA/B;AACD,KAlBC,CAAF;AAmBD,GApBO,CAAR;AAqBD,CArDO,CAAR","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 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 createValidator from './validation';\n\ndescribe('services/validate', () => {\n const FIXTURES_PATH = [\n __dirname,\n '..',\n '..',\n 'test-fixtures',\n 'validation'\n ];\n const {getFixture} = fixtureFactory({root: FIXTURES_PATH});\n\n describe('f003-fi-melinda', () => {\n it('Should have failed: false', async () => {\n const validator = await createValidator();\n const record = new MarcRecord(JSON.parse(getFixture({\n components: [\n 'in',\n 'f003-fi-melinda.json'\n ]\n })));\n const result = await validator(record.toObject());\n const expected = getFixture({\n components: [\n 'out',\n 'f003-fi-melinda.json'\n ]\n });\n const stringResult = JSON.stringify({...result}, undefined, 2);\n expect(stringResult).to.eql(expected);\n expect(result.failed).to.equal(false);\n });\n });\n\n describe('f003-not-fi-melinda', () => {\n it('Should have failed: true', async () => {\n const validator = await createValidator();\n const record = new MarcRecord(JSON.parse(getFixture({\n components: [\n 'in',\n 'f003-not-fi-melinda.json'\n ]\n })));\n const result = await validator(record.toObject());\n const expected = getFixture({\n components: [\n 'out',\n 'f003-not-fi-melinda.json'\n ]\n });\n const stringResult = JSON.stringify({...result}, undefined, 2);\n expect(stringResult).to.eql(expected);\n expect(result.failed).to.equal(true);\n });\n });\n});\n\n"],"file":"validation.spec.js"}
1
+ {"version":3,"sources":["../../src/helpers/validation.spec.js"],"names":["describe","FIXTURES_PATH","__dirname","getFixture","root","reader","READERS","JSON","it","validator","record","MarcRecord","components","result","toObject","expected","to","eql","failed","equal"],"mappings":";;AA4BA;;AACA;;AACA;;AACA;;;;;;;;AA/BA;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;AAOAA,QAAQ,CAAC,mBAAD,EAAsB,MAAM;AAClC,QAAMC,aAAa,GAAG,CACpBC,SADoB,EAEpB,IAFoB,EAGpB,IAHoB,EAIpB,eAJoB,EAKpB,YALoB,CAAtB;AAOA,QAAM;AAACC,IAAAA;AAAD,MAAe,qBAAe;AAACC,IAAAA,IAAI,EAAEH,aAAP;AAAsBI,IAAAA,MAAM,EAAEC,gBAAQC;AAAtC,GAAf,CAArB;AAEAP,EAAAA,QAAQ,CAAC,iBAAD,EAAoB,MAAM;AAChCQ,IAAAA,EAAE,CAAC,2BAAD,EAA8B,YAAY;AAC1C,YAAMC,SAAS,GAAG,MAAM,0BAAxB;AACA,YAAMC,MAAM,GAAG,IAAIC,sBAAJ,CAAeR,UAAU,CAAC;AACvCS,QAAAA,UAAU,EAAE,CACV,IADU,EAEV,sBAFU;AAD2B,OAAD,CAAzB,CAAf;AAMA,YAAMC,MAAM,GAAG,MAAMJ,SAAS,CAACC,MAAM,CAACI,QAAP,EAAD,CAA9B;AACA,YAAMC,QAAQ,GAAGZ,UAAU,CAAC;AAC1BS,QAAAA,UAAU,EAAE,CACV,KADU,EAEV,sBAFU;AADc,OAAD,CAA3B;AAMA,wBAAOC,MAAP,EAAeG,EAAf,CAAkBC,GAAlB,CAAsBF,QAAtB;AACA,wBAAOF,MAAM,CAACK,MAAd,EAAsBF,EAAtB,CAAyBG,KAAzB,CAA+B,KAA/B;AACD,KAjBC,CAAF;AAkBD,GAnBO,CAAR;AAqBAnB,EAAAA,QAAQ,CAAC,qBAAD,EAAwB,MAAM;AACpCQ,IAAAA,EAAE,CAAC,0BAAD,EAA6B,YAAY;AACzC,YAAMC,SAAS,GAAG,MAAM,0BAAxB;AACA,YAAMC,MAAM,GAAG,IAAIC,sBAAJ,CAAeR,UAAU,CAAC;AACvCS,QAAAA,UAAU,EAAE,CACV,IADU,EAEV,0BAFU;AAD2B,OAAD,CAAzB,CAAf;AAMA,YAAMC,MAAM,GAAG,MAAMJ,SAAS,CAACC,MAAM,CAACI,QAAP,EAAD,CAA9B;AACA,YAAMC,QAAQ,GAAGZ,UAAU,CAAC;AAC1BS,QAAAA,UAAU,EAAE,CACV,KADU,EAEV,0BAFU;AADc,OAAD,CAA3B;AAMA,wBAAOC,MAAP,EAAeG,EAAf,CAAkBC,GAAlB,CAAsBF,QAAtB;AACA,wBAAOF,MAAM,CAACK,MAAd,EAAsBF,EAAtB,CAAyBG,KAAzB,CAA+B,IAA/B;AACD,KAjBC,CAAF;AAkBD,GAnBO,CAAR;AAoBD,CAnDO,CAAR","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 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, {READERS} from '@natlibfi/fixura';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport createValidator from './validation';\n\ndescribe('services/validate', () => {\n const FIXTURES_PATH = [\n __dirname,\n '..',\n '..',\n 'test-fixtures',\n 'validation'\n ];\n const {getFixture} = fixtureFactory({root: FIXTURES_PATH, reader: READERS.JSON});\n\n describe('f003-fi-melinda', () => {\n it('Should have failed: false', async () => {\n const validator = await createValidator();\n const record = new MarcRecord(getFixture({\n components: [\n 'in',\n 'f003-fi-melinda.json'\n ]\n }));\n const result = await validator(record.toObject());\n const expected = getFixture({\n components: [\n 'out',\n 'f003-fi-melinda.json'\n ]\n });\n expect(result).to.eql(expected);\n expect(result.failed).to.equal(false);\n });\n });\n\n describe('f003-not-fi-melinda', () => {\n it('Should have failed: true', async () => {\n const validator = await createValidator();\n const record = new MarcRecord(getFixture({\n components: [\n 'in',\n 'f003-not-fi-melinda.json'\n ]\n }));\n const result = await validator(record.toObject());\n const expected = getFixture({\n components: [\n 'out',\n 'f003-not-fi-melinda.json'\n ]\n });\n expect(result).to.eql(expected);\n expect(result.failed).to.equal(true);\n });\n });\n});\n\n"],"file":"validation.spec.js"}
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": "AGPL-3.0+",
17
- "version": "2.0.2",
17
+ "version": "2.1.0",
18
18
  "main": "./dist/index.js",
19
19
  "engines": {
20
20
  "node": ">=14"
@@ -37,7 +37,7 @@
37
37
  "@natlibfi/marc-record": "^6.1.2",
38
38
  "@natlibfi/marc-record-serializers": "^8.0.0",
39
39
  "@natlibfi/marc-record-validate": "^6.0.1",
40
- "@natlibfi/marc-record-validators-melinda": "^8.4.4",
40
+ "@natlibfi/marc-record-validators-melinda": "^8.4.6",
41
41
  "@natlibfi/melinda-backend-commons": "^2.0.5",
42
42
  "@natlibfi/melinda-commons": "^12.0.0",
43
43
  "amqplib": ">=0.8.0 <1.0.0",