@natlibfi/melinda-rest-api-commons 4.0.1 → 4.0.2-alpha.2

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.
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.stripF884s = stripF884s;
7
7
  var _marcRecord = require("@natlibfi/marc-record");
8
8
  var _debug = _interopRequireDefault(require("debug"));
9
- var _fixUtils = require("./fix-utils");
9
+ var _util = require("util");
10
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
11
  /**
12
12
  *
@@ -14,7 +14,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
14
14
  *
15
15
  * Shared modules for microservices of Melinda rest api batch import system
16
16
  *
17
- * Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
17
+ * Copyright (C) 2020-2023 University Of Helsinki (The National Library Of Finland)
18
18
  *
19
19
  * This file is part of melinda-rest-api-commons
20
20
  *
@@ -36,6 +36,8 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
36
36
  *
37
37
  */
38
38
 
39
+ //import {sortFieldsBySubfieldValue, removeSubfield} from './fix-utils';
40
+
39
41
  function stripF884s(newRecord, options) {
40
42
  const debug = (0, _debug.default)('@natlibfi/melinda-rest-api-commons:fixRecord:stripF884s');
41
43
  const debugData = debug.extend('data');
@@ -53,29 +55,117 @@ function stripF884s(newRecord, options) {
53
55
  }) => code === '5' && value === 'MELINDA');
54
56
  const f884Melindas = newRecord.fields.filter(isMelindaf884);
55
57
  debugData(`Melinda's f884s (${f884Melindas.length}) \n ${JSON.stringify(f884Melindas)}`);
58
+ //debugData(`Melinda's f884s (${f884Melindas.length}) \n ${inspect(f884Melindas, {depth: 3})}`);
59
+
56
60
  if (f884Melindas.length < 2) {
57
- debug(`Not enough Melinda's f884.s to filter (${f884Melindas.length})`);
61
+ debug(`Not enough Melinda's f884s to filter (${f884Melindas.length})`);
58
62
  return newRecord;
59
63
  }
60
64
 
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)}`);
65
+ // Pick data (firstDate, lastDate, hash with latest date) for all conversion : source combinations
66
+ const results = f884Melindas.reduce((allResults, f884, index) => {
67
+ debugData(`All results: ${JSON.stringify(allResults)}`);
68
+ //debugData(`Handling field (${index}): ${inspect(f884, {depth: 3})}`);
69
+ debugData(`Handling field (${index}): ${JSON.stringify(f884)}`);
70
+ const conversion = findConversion(f884);
71
+ const source = findSource(f884);
72
+ const convSource = `${conversion}:${source}`;
73
+ const {
74
+ firstDate,
75
+ lastDate
76
+ } = findDates(f884);
77
+ const hash = findHash(f884);
64
78
 
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)}`);
79
+ // Find currently existing data for conversion : source combination
80
+ const currResult = allResults[convSource];
81
+ debugData(JSON.stringify(currResult));
68
82
 
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;
83
+ // If we do not have any current data, add data from field
84
+ if (!currResult) {
85
+ debug(`Add a new convSource ${convSource} to results`);
86
+ const newResult = {
87
+ conversion,
88
+ source,
89
+ firstDate,
90
+ lastDate,
91
+ hash
92
+ };
93
+ debugData(`- New result: ${JSON.stringify(newResult)}`);
94
+ return {
95
+ ...allResults,
96
+ [convSource]: newResult
97
+ };
98
+ }
99
+ // If we have current data, update it from the data from field, if needed
100
+ debug(`Update result for ${convSource}`);
101
+ debugData(`- Current result: ${JSON.stringify(currResult)}`);
102
+ const updatedResult = {
103
+ ...currResult,
104
+ firstDate: currResult.firstDate > firstDate && firstDate !== '00000000' ? firstDate : currResult.firstDate,
105
+ lastDate: currResult.lastDate < lastDate ? lastDate : currResult.lastDate,
106
+ hash: currResult.lastDate < lastDate && lastDate !== '00000000' && hash !== '0000000000000000000000000000000000000000000000000000000000000000' ? hash : currResult.hash
107
+ };
108
+ debugData(`- Updated result: ${JSON.stringify(updatedResult)}`);
109
+ return {
110
+ ...allResults,
111
+ [convSource]: updatedResult
112
+ };
113
+ }, {});
114
+ debugData(`RESULTS: ${JSON.stringify(results)}`);
115
+ const editedf884s = editFields(f884Melindas, results);
116
+ debug(`Edited fields (${editedf884s.length})`);
117
+ //debugData(inspect(editedf884s, {depth: 3}));
118
+ debugData(`${JSON.stringify(editedf884s)}`);
119
+
120
+ // We update each field based on the results we got from fields
121
+ // Note: we do not add $g:s or $k:s if the field doesn't have them
122
+ function editFields(fields, results) {
123
+ const editedFields = fields.map(field => {
124
+ const convSource = `${findConversion(field)}:${findSource(field)}`;
125
+ if (convSource && results[convSource]) {
126
+ const firstDate = results[convSource].firstDate && results[convSource].firstDate !== '00000000' ? results[convSource].firstDate : '';
127
+ const lastDate = results[convSource].lastDate && results[convSource].lastDate !== '00000000' ? results[convSource].lastDate : '';
128
+ const source = results[convSource].source && results[convSource].source !== 'NO_SOURCE' ? results[convSource].source : '';
129
+ const hash = results[convSource].hash && results[convSource].hash !== '0000000000000000000000000000000000000000000000000000000000000000' ? results[convSource].hash : '';
130
+ const sfGAll = firstDate === lastDate ? `${firstDate}` : `${firstDate} - ${lastDate}`;
131
+ const sfKAll = `${source}:${hash}`;
132
+ const sfG = sfGAll.replace(/^ - /u, '').replace(/ - $/u, '');
133
+ const sfK = sfKAll.replace(/^:/u, '').replace(/:$/u, '');
134
+ return {
135
+ ...field,
136
+ subfields: field.subfields.map(subfield => {
137
+ // we don't get $g or $k if the original field doesn't have them
138
+ if (subfield.code === 'g') {
139
+ return {
140
+ code: subfield.code,
141
+ value: sfG
142
+ };
143
+ }
144
+ if (subfield.code === 'k') {
145
+ return {
146
+ code: subfield.code,
147
+ value: sfK
148
+ };
149
+ }
150
+ return subfield;
151
+ })
152
+ };
153
+ }
154
+ return field;
155
+ });
156
+ return editedFields;
157
+ }
158
+
159
+ // we'll need to uniq these too
74
160
 
75
- // Keep just first instance of each similar field, compare without subfield with subfieldCode
76
- function uniqWithOutSubfield(fields, subfieldCode) {
161
+ const uniq884s = uniqFields(editedf884s);
162
+ debug(`UniqFields (${uniq884s.length})`);
163
+ debugData((0, _util.inspect)(uniq884s, {
164
+ depth: 3
165
+ }));
166
+ function uniqFields(fields) {
77
167
  return fields.reduce((uniq, field) => {
78
- if (!uniq.some(f => _marcRecord.MarcRecord.isEqual((0, _fixUtils.removeSubfield)(f, subfieldCode), (0, _fixUtils.removeSubfield)(field, subfieldCode)))) {
168
+ if (!uniq.some(f => _marcRecord.MarcRecord.isEqual(f, field))) {
79
169
  // eslint-disable-line functional/no-conditional-statement
80
170
  uniq.push(field); // eslint-disable-line functional/immutable-data
81
171
  }
@@ -83,5 +173,62 @@ function stripF884s(newRecord, options) {
83
173
  return uniq;
84
174
  }, []);
85
175
  }
176
+ // Replace original Melinda-f884s with remaining Melinda-f884s
177
+ // NOTE: this sorts MELINDA-f884s after possible other f884s
178
+ newRecord.removeFields(f884Melindas);
179
+ newRecord.insertFields(uniq884s);
180
+ return newRecord;
181
+
182
+ // Find conversion:source pairs
183
+ // Find first date
184
+ // Find last date and last hash
185
+
186
+ function findConversion(f884) {
187
+ const [sfA] = f884.subfields.filter(subfield => subfield.code === 'a').map(subfield => subfield.value);
188
+ const conversion = sfA;
189
+ debugData(`Conversion: "${conversion}"`);
190
+ return conversion;
191
+ }
192
+ function findSource(f884) {
193
+ const [sfK] = f884.subfields.filter(subfield => subfield.code === 'k').map(subfield => subfield.value);
194
+ const source = sfK.replace(/:.*$/u, '');
195
+ if (source && source.length !== 64) {
196
+ debugData(`Source: "${source}"`);
197
+ return source;
198
+ }
199
+ const emptySource = 'NO_SOURCE';
200
+ debugData(`Source: "${emptySource}"`);
201
+ return emptySource;
202
+ }
203
+ function findHash(f884) {
204
+ const [sfK] = f884.subfields.filter(subfield => subfield.code === 'k').map(subfield => subfield.value);
205
+ const hash = sfK.replace(/^.*:/u, '');
206
+ if (hash && hash.length === 64) {
207
+ debugData(`Hash: "${hash}"`);
208
+ return hash;
209
+ }
210
+ const emptyHash = '0000000000000000000000000000000000000000000000000000000000000000';
211
+ debugData(`Hash: "${emptyHash}"`);
212
+ return emptyHash;
213
+ }
214
+ function findDates(f884) {
215
+ const [sfG] = f884.subfields.filter(subfield => subfield.code === 'g').map(subfield => subfield.value);
216
+ if (sfG && / - /u.test(sfG)) {
217
+ const firstDate = sfG.replace(/ - .*$/u, '');
218
+ const lastDate = sfG.replace(/^.* - /u, '');
219
+ debugData(`FirstDate: "${firstDate}", LastDate: "${lastDate}"`);
220
+ return {
221
+ firstDate,
222
+ lastDate
223
+ };
224
+ }
225
+ const firstDate = sfG || '00000000';
226
+ const lastDate = sfG || '00000000';
227
+ debugData(`FirstDate: "${firstDate}", LastDate: "${lastDate}"`);
228
+ return {
229
+ firstDate,
230
+ lastDate
231
+ };
232
+ }
86
233
  }
87
234
  //# sourceMappingURL=fix-strip-f884s.js.map
@@ -1 +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,MAAMC,YAAY,GAAGf,SAAS,CAACgB,MAAM,CAACC,MAAM,CAACT,aAAa,CAAC;EAC3DJ,SAAS,CAAE,oBAAmBW,YAAY,CAACG,MAAO,QAAOZ,IAAI,CAACC,SAAS,CAACQ,YAAY,CAAE,EAAC,CAAC;EAExF,IAAIA,YAAY,CAACG,MAAM,GAAG,CAAC,EAAE;IAC3BhB,KAAK,CAAE,0CAAyCa,YAAY,CAACG,MAAO,GAAE,CAAC;IACvE,OAAOlB,SAAS;EAClB;;EAEA;EACA,MAAMmB,YAAY,GAAG,IAAAC,mCAAyB,EAACL,YAAY,EAAE,GAAG,CAAC;EACjEX,SAAS,CAAE,kDAAiDe,YAAY,CAACD,MAAO,QAAOZ,IAAI,CAACC,SAAS,CAACY,YAAY,CAAE,EAAC,CAAC;;EAEtH;EACA,MAAME,UAAU,GAAGC,mBAAmB,CAACH,YAAY,EAAE,GAAG,CAAC;EACzDf,SAAS,CAAE,yCAAwCiB,UAAU,CAACH,MAAO,QAAOZ,IAAI,CAACC,SAAS,CAACc,UAAU,CAAE,EAAC,CAAC;;EAEzG;EACA;EACArB,SAAS,CAACuB,YAAY,CAACR,YAAY,CAAC;EACpCf,SAAS,CAACwB,YAAY,CAACH,UAAU,CAAC;EAClC,OAAOrB,SAAS;;EAEhB;EACA,SAASsB,mBAAmB,CAACN,MAAM,EAAES,YAAY,EAAE;IACjD,OAAOT,MAAM,CAACU,MAAM,CAAC,CAACC,IAAI,EAAEC,KAAK,KAAK;MACpC,IAAI,CAACD,IAAI,CAACf,IAAI,CAACH,CAAC,IAAIoB,sBAAU,CAACC,OAAO,CAAC,IAAAC,wBAAc,EAACtB,CAAC,EAAEgB,YAAY,CAAC,EAAE,IAAAM,wBAAc,EAACH,KAAK,EAAEH,YAAY,CAAC,CAAC,CAAC,EAAE;QAAE;QAC/GE,IAAI,CAACK,IAAI,CAACJ,KAAK,CAAC,CAAC,CAAC;MACpB;;MAEA,OAAOD,IAAI;IACb,CAAC,EAAE,EAAE,CAAC;EACR;AACF"}
1
+ {"version":3,"file":"fix-strip-f884s.js","names":["_marcRecord","require","_debug","_interopRequireDefault","_util","obj","__esModule","default","stripF884s","newRecord","options","debug","createDebugLogger","debugData","extend","JSON","stringify","isMelindaf884","f","tag","subfields","some","code","value","f884Melindas","fields","filter","length","results","reduce","allResults","f884","index","conversion","findConversion","source","findSource","convSource","firstDate","lastDate","findDates","hash","findHash","currResult","newResult","updatedResult","editedf884s","editFields","editedFields","map","field","sfGAll","sfKAll","sfG","replace","sfK","subfield","uniq884s","uniqFields","inspect","depth","uniq","MarcRecord","isEqual","push","removeFields","insertFields","sfA","emptySource","emptyHash","test"],"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-2023 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';\n//import {sortFieldsBySubfieldValue, removeSubfield} from './fix-utils';\nimport {inspect} from 'util';\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 //debugData(`Melinda's f884s (${f884Melindas.length}) \\n ${inspect(f884Melindas, {depth: 3})}`);\n\n if (f884Melindas.length < 2) {\n debug(`Not enough Melinda's f884s to filter (${f884Melindas.length})`);\n return newRecord;\n }\n\n // Pick data (firstDate, lastDate, hash with latest date) for all conversion : source combinations\n const results = f884Melindas.reduce((allResults, f884, index) => {\n debugData(`All results: ${JSON.stringify(allResults)}`);\n //debugData(`Handling field (${index}): ${inspect(f884, {depth: 3})}`);\n debugData(`Handling field (${index}): ${JSON.stringify(f884)}`);\n\n const conversion = findConversion(f884);\n const source = findSource(f884);\n const convSource = `${conversion}:${source}`;\n const {firstDate, lastDate} = findDates(f884);\n const hash = findHash(f884);\n\n // Find currently existing data for conversion : source combination\n const currResult = allResults[convSource];\n debugData(JSON.stringify(currResult));\n\n // If we do not have any current data, add data from field\n if (!currResult) {\n debug(`Add a new convSource ${convSource} to results`);\n const newResult = {\n conversion,\n source,\n firstDate,\n lastDate,\n hash\n };\n debugData(`- New result: ${JSON.stringify(newResult)}`);\n return {\n ...allResults,\n [convSource]: newResult\n };\n }\n // If we have current data, update it from the data from field, if needed\n debug(`Update result for ${convSource}`);\n debugData(`- Current result: ${JSON.stringify(currResult)}`);\n\n const updatedResult = {\n ...currResult,\n firstDate: currResult.firstDate > firstDate && firstDate !== '00000000' ? firstDate : currResult.firstDate,\n lastDate: currResult.lastDate < lastDate ? lastDate : currResult.lastDate,\n hash: currResult.lastDate < lastDate && lastDate !== '00000000' && hash !== '0000000000000000000000000000000000000000000000000000000000000000' ? hash : currResult.hash\n };\n debugData(`- Updated result: ${JSON.stringify(updatedResult)}`);\n return {\n ...allResults,\n [convSource]: updatedResult\n };\n }, {});\n\n debugData(`RESULTS: ${JSON.stringify(results)}`);\n const editedf884s = editFields(f884Melindas, results);\n\n debug(`Edited fields (${editedf884s.length})`);\n //debugData(inspect(editedf884s, {depth: 3}));\n debugData(`${JSON.stringify(editedf884s)}`);\n\n // We update each field based on the results we got from fields\n // Note: we do not add $g:s or $k:s if the field doesn't have them\n function editFields(fields, results) {\n const editedFields = fields.map((field) => {\n const convSource = `${findConversion(field)}:${findSource(field)}`;\n\n if (convSource && results[convSource]) {\n const firstDate = results[convSource].firstDate && results[convSource].firstDate !== '00000000' ? results[convSource].firstDate : '';\n const lastDate = results[convSource].lastDate && results[convSource].lastDate !== '00000000' ? results[convSource].lastDate : '';\n\n const source = results[convSource].source && results[convSource].source !== 'NO_SOURCE' ? results[convSource].source : '';\n const hash = results[convSource].hash && results[convSource].hash !== '0000000000000000000000000000000000000000000000000000000000000000' ? results[convSource].hash : '';\n\n const sfGAll = firstDate === lastDate ? `${firstDate}` : `${firstDate} - ${lastDate}`;\n const sfKAll = `${source}:${hash}`;\n\n const sfG = sfGAll.replace(/^ - /u, '').replace(/ - $/u, '');\n const sfK = sfKAll.replace(/^:/u, '').replace(/:$/u, '');\n\n return {\n ...field,\n subfields: field.subfields.map(subfield => {\n\n // we don't get $g or $k if the original field doesn't have them\n if (subfield.code === 'g') {\n return {\n code: subfield.code,\n value: sfG\n };\n }\n\n if (subfield.code === 'k') {\n return {\n code: subfield.code,\n value: sfK\n };\n }\n\n return subfield;\n })\n\n };\n\n\n }\n\n return field;\n });\n return editedFields;\n }\n\n // we'll need to uniq these too\n\n const uniq884s = uniqFields(editedf884s);\n debug(`UniqFields (${uniq884s.length})`);\n debugData(inspect(uniq884s, {depth: 3}));\n\n\n function uniqFields(fields) {\n return fields.reduce((uniq, field) => {\n if (!uniq.some(f => MarcRecord.isEqual(f, field))) { // 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 // 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(uniq884s);\n\n return newRecord;\n\n\n // Find conversion:source pairs\n // Find first date\n // Find last date and last hash\n\n\n function findConversion(f884) {\n const [sfA] = f884.subfields.filter((subfield) => subfield.code === 'a').map(subfield => subfield.value);\n const conversion = sfA;\n debugData(`Conversion: \"${conversion}\"`);\n return conversion;\n }\n\n function findSource(f884) {\n const [sfK] = f884.subfields.filter((subfield) => subfield.code === 'k').map(subfield => subfield.value);\n const source = sfK.replace(/:.*$/u, '');\n if (source && source.length !== 64) {\n debugData(`Source: \"${source}\"`);\n return source;\n }\n const emptySource = 'NO_SOURCE';\n debugData(`Source: \"${emptySource}\"`);\n return emptySource;\n }\n\n function findHash(f884) {\n const [sfK] = f884.subfields.filter((subfield) => subfield.code === 'k').map(subfield => subfield.value);\n const hash = sfK.replace(/^.*:/u, '');\n if (hash && hash.length === 64) {\n debugData(`Hash: \"${hash}\"`);\n return hash;\n }\n const emptyHash = '0000000000000000000000000000000000000000000000000000000000000000';\n debugData(`Hash: \"${emptyHash}\"`);\n return emptyHash;\n }\n\n function findDates(f884) {\n const [sfG] = f884.subfields.filter((subfield) => subfield.code === 'g').map(subfield => subfield.value);\n if (sfG && (/ - /u).test(sfG)) {\n const firstDate = sfG.replace(/ - .*$/u, '');\n const lastDate = sfG.replace(/^.* - /u, '');\n debugData(`FirstDate: \"${firstDate}\", LastDate: \"${lastDate}\"`);\n return {firstDate, lastDate};\n }\n const firstDate = sfG || '00000000';\n const lastDate = sfG || '00000000';\n debugData(`FirstDate: \"${firstDate}\", LastDate: \"${lastDate}\"`);\n return {firstDate, lastDate};\n }\n\n}\n"],"mappings":";;;;;;AA4BA,IAAAA,WAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAC,sBAAA,CAAAF,OAAA;AAEA,IAAAG,KAAA,GAAAH,OAAA;AAA6B,SAAAE,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAA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AQ,IAAIA,QAAQ,CAACjC,KAAK,CAAC;IACxG,IAAI8B,GAAG,IAAK,MAAM,CAAEiB,IAAI,CAACjB,GAAG,CAAC,EAAE;MAC7B,MAAMf,SAAS,GAAGe,GAAG,CAACC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC;MAC5C,MAAMf,QAAQ,GAAGc,GAAG,CAACC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC;MAC3CzC,SAAS,CAAE,eAAcyB,SAAU,iBAAgBC,QAAS,GAAE,CAAC;MAC/D,OAAO;QAACD,SAAS;QAAEC;MAAQ,CAAC;IAC9B;IACA,MAAMD,SAAS,GAAGe,GAAG,IAAI,UAAU;IACnC,MAAMd,QAAQ,GAAGc,GAAG,IAAI,UAAU;IAClCxC,SAAS,CAAE,eAAcyB,SAAU,iBAAgBC,QAAS,GAAE,CAAC;IAC/D,OAAO;MAACD,SAAS;MAAEC;IAAQ,CAAC;EAC9B;AAEF"}
@@ -1 +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,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ils.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,cAAcA,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;IAEA,OAAO;MACLN,GAAG,EAAEH,KAAK,CAACG,GAAG;MACdO,IAAI,EAAEV,KAAK,CAACU,IAAI;MAChBC,IAAI,EAAEX,KAAK,CAACW,IAAI;MAChBL,SAAS,EAAED;IACb,CAAC;EACH;EACA;EACA,OAAOL,KAAK;AACd;;AAGA;AACO,SAASY,yBAAyBA,CAACC,MAAM,EAAEC,YAAY,EAAE;EAC9D,OAAO,CAAC,GAAGD,MAAM,CAAC,CAACE,IAAI,CAAC,CAACC,CAAC,EAAEC,CAAC,KAAK;IAChC,MAAMC,OAAO,GAAGC,qBAAqB,CAACH,CAAC,EAAEF,YAAY,CAAC;IACtD,MAAMM,OAAO,GAAGD,qBAAqB,CAACF,CAAC,EAAEH,YAAY,CAAC;IACtD,IAAII,OAAO,IAAI,CAACE,OAAO,EAAE;MACvB,OAAO,CAAC,CAAC;IACX;IACA,IAAI,CAACF,OAAO,IAAIE,OAAO,EAAE;MACvB,OAAO,CAAC;IACV;IACA,IAAIF,OAAO,GAAGE,OAAO,EAAE;MACrB,OAAO,CAAC;IACV;IACA,IAAIA,OAAO,GAAGF,OAAO,EAAE;MACrB,OAAO,CAAC,CAAC;IACX;IACA,OAAO,CAAC;EACV,CAAC,CAAC;EACF;EACA,SAASC,qBAAqBA,CAACnB,KAAK,EAAEc,YAAY,EAAE;IAClD,MAAMO,IAAI,GAAGrB,KAAK,CAACM,SAAS,GAAGN,KAAK,CAACM,SAAS,CAACC,MAAM,CAACe,IAAI,IAAIA,IAAI,CAACrB,IAAI,KAAKa,YAAY,CAAC,GAAG,EAAE;IAC9F,OAAOO,IAAI,CAACZ,MAAM,GAAG,CAAC,GAAGY,IAAI,CAAC,CAAC,CAAC,CAACE,KAAK,GAAG,EAAE;EAC7C;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"fix.js","names":["logger","createLogger","debug","createDebugLogger","debugData","extend","fixRecord","record","settings","verbose","JSON","stringify","newRecord","MarcRecord","clone","subfieldValues","generateMissingSIDsOptions","generateMissingSIDs","undefined","newRecord1","replacePrefixesOptions","replacePrefixes","newRecord2","replaceAllPrefixes","newRecord3","handleTempUrns","newRecord4","stripF884s","toObject","length","forEach","options","replacePrefix","oldPrefix","newPrefix","prefixReplaceCodes","pattern","replacement","getDatafields","field","subfields","filter","code","includes","subfield","value","replace","f035Filters","fSIDFilters","f035s","f035ToSidInfo","get","fSIDs","sidsToSidInfo","sidsToBeAdded","genNewSids","f035SidInfo","some","fSIDInfo","SID","sidField","insertField","map","sidInfo","tag","ind1","ind2","SIDs","flatMap","sub","wantedSub","regexp","test","findIndex","slice","indexOf"],"sources":["../../src/helpers/fix.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 {createLogger} from '@natlibfi/melinda-backend-commons';\nimport createDebugLogger from 'debug';\n\nimport {handleTempUrns} from './fix-handle-tempurns';\nimport {stripF884s} from './fix-strip-f884s';\n\nexport * from './fix-constants';\n\nconst logger = createLogger();\nconst debug = createDebugLogger('@natlibfi/melinda-rest-api-commons:fixRecord');\nconst debugData = debug.extend('data');\n\nexport function fixRecord(record, settings = {}) {\n\n logger.verbose(`We will apply formatting to the record according to settings: ${JSON.stringify(settings)}`);\n const newRecord = MarcRecord.clone(record, {subfieldValues: false});\n debugData(`settings: ${JSON.stringify(settings)}`);\n\n // We should handle these in some prettier way ...\n\n // Fix 1, generate SIDs\n const generateMissingSIDsOptions = settings.generateMissingSIDs || undefined;\n const newRecord1 = generateMissingSIDs(newRecord, generateMissingSIDsOptions);\n\n // Fix 2, replace identifier prefixes\n const replacePrefixesOptions = settings.replacePrefixes || [];\n const newRecord2 = replaceAllPrefixes(newRecord1, replacePrefixesOptions);\n\n // Fix 3, handle temporary URNs from legal deposit record import\n const newRecord3 = handleTempUrns(newRecord2, settings.handleTempUrns);\n\n // Fix 4, strip extra field 884s\n const newRecord4 = stripF884s(newRecord3, settings.stripF884s);\n\n return newRecord4.toObject();\n\n}\n\n\nfunction replaceAllPrefixes(record, replacePrefixesOptions) {\n if (replacePrefixesOptions.length < 1) {\n debug(`NOT running replacePrefixes, no options`);\n return record;\n }\n\n debug(`Running replacePrefixes fixer`);\n debugData(`replacePrefixesOptions: ${JSON.stringify(replacePrefixesOptions)}`);\n\n replacePrefixesOptions.forEach(options => {\n replacePrefix(record, options);\n });\n return record;\n}\n\n\n// Replace prefix in all specified subfields\nfunction replacePrefix(record, options) {\n const {oldPrefix, newPrefix, prefixReplaceCodes} = options;\n debug(`Replacing ${oldPrefix} with ${newPrefix} in subfields ${prefixReplaceCodes}`);\n const pattern = `(${oldPrefix})`;\n const replacement = `(${newPrefix})`;\n record.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 return record;\n}\n\n\nfunction generateMissingSIDs(record, options) {\n\n const f035Filters = options && options.f035Filters ? options.f035Filters : [];\n const fSIDFilters = options && options.fSIDFilters ? options.fSIDFilters : [];\n\n if (f035Filters.length !== fSIDFilters.length || f035Filters.length < 1 || fSIDFilters.length < 1) {\n debug(`NOT running generateMissingsSIDs, no options`);\n return record;\n }\n\n debug(`Running generateMissingSIDs fixer`);\n debugData(`generateMissingSIDs options: ${JSON.stringify(options)}`);\n\n const f035s = f035ToSidInfo(record.get(/^035$/u));\n const fSIDs = sidsToSidInfo(record.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 sidsToBeAdded.forEach(sidField => record.insertField(sidField));\n return record;\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"],"mappings":";;;;;;;;;AA4BA;AACA;AACA;AAEA;AACA;AAEA;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AAAgC;AAnChC;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;;AAWA,MAAMA,MAAM,GAAG,IAAAC,mCAAY,GAAE;AAC7B,MAAMC,KAAK,GAAG,IAAAC,cAAiB,EAAC,8CAA8C,CAAC;AAC/E,MAAMC,SAAS,GAAGF,KAAK,CAACG,MAAM,CAAC,MAAM,CAAC;AAE/B,SAASC,SAAS,CAACC,MAAM,EAAEC,QAAQ,GAAG,CAAC,CAAC,EAAE;EAE/CR,MAAM,CAACS,OAAO,CAAE,iEAAgEC,IAAI,CAACC,SAAS,CAACH,QAAQ,CAAE,EAAC,CAAC;EAC3G,MAAMI,SAAS,GAAGC,sBAAU,CAACC,KAAK,CAACP,MAAM,EAAE;IAACQ,cAAc,EAAE;EAAK,CAAC,CAAC;EACnEX,S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B,KAAK,KAAK3B,SAAS,CAAC,CAAC4C,GAAG,CAACO,GAAG,IAAIA,GAAG,CAACxB,KAAK,CAAC;MAE1G,IAAIc,GAAG,IAAId,KAAK,EAAE;QAChB,OAAO;UACLc,GAAG;UACHd;QACF,CAAC;MACH;MAEA,OAAO3B,SAAS;IAClB,CAAC,CAAC,CAACuB,MAAM,CAACI,KAAK,IAAIA,KAAK,KAAK3B,SAAS,CAAC;EACzC;EAEA,SAASgC,aAAa,CAACD,KAAK,EAAE;IAC5B,OAAOA,KAAK,CAACmB,OAAO,CAAC,CAAC;MAAC5B;IAAS,CAAC,KAAK;MACpC,MAAM,CAAC8B,SAAS,CAAC,GAAG9B,SAAS,CAACC,MAAM,CAAC4B,GAAG,IAAIA,GAAG,CAAC3B,IAAI,KAAK,GAAG,IAAIK,WAAW,CAACU,IAAI,CAACc,MAAM,IAAIA,MAAM,CAACC,IAAI,CAACH,GAAG,CAACxB,KAAK,CAAC,CAAC,CAAC;MAEnH,IAAIyB,SAAS,EAAE;QACb,OAAO;UACLX,GAAG,EAAEX,WAAW,CAACD,WAAW,CAAC0B,SAAS,CAACF,MAAM,IAAIA,MAAM,CAACC,IAAI,CAACF,SAAS,CAACzB,KAAK,CAAC,CAAC,CAAC;UAC/EA,KAAK,EAAEyB,SAAS,CAACzB,KAAK,CAAC6B,KAAK,CAACJ,SAAS,CAACzB,KAAK,CAAC8B,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;QAC/D,CAAC;MACH;MAEA,OAAOzD,SAAS;IAClB,CAAC,CAAC,CAACuB,MAAM,CAACI,KAAK,IAAIA,KAAK,KAAK3B,SAAS,CAAC;EACzC;AACF"}
1
+ {"version":3,"file":"fix.js","names":["_marcRecord","require","_melindaBackendCommons","_debug","_interopRequireDefault","_fixHandleTempurns","_fixStripF884s","_fixConstants","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","obj","__esModule","default","logger","createLogger","debug","createDebugLogger","debugData","extend","fixRecord","record","settings","verbose","JSON","stringify","newRecord","MarcRecord","clone","subfieldValues","generateMissingSIDsOptions","generateMissingSIDs","undefined","newRecord1","replacePrefixesOptions","replacePrefixes","newRecord2","replaceAllPrefixes","newRecord3","handleTempUrns","newRecord4","stripF884s","toObject","length","options","replacePrefix","oldPrefix","newPrefix","prefixReplaceCodes","pattern","replacement","getDatafields","field","subfields","filter","code","includes","subfield","value","replace","f035Filters","fSIDFilters","f035s","f035ToSidInfo","fSIDs","sidsToSidInfo","sidsToBeAdded","genNewSids","f035SidInfo","some","fSIDInfo","SID","sidField","insertField","map","sidInfo","tag","ind1","ind2","SIDs","flatMap","sub","wantedSub","regexp","test","findIndex","slice","indexOf"],"sources":["../../src/helpers/fix.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 {createLogger} from '@natlibfi/melinda-backend-commons';\nimport createDebugLogger from 'debug';\n\nimport {handleTempUrns} from './fix-handle-tempurns';\nimport {stripF884s} from './fix-strip-f884s';\n\nexport * from './fix-constants';\n\nconst logger = createLogger();\nconst debug = createDebugLogger('@natlibfi/melinda-rest-api-commons:fixRecord');\nconst debugData = debug.extend('data');\n\nexport function fixRecord(record, settings = {}) {\n\n logger.verbose(`We will apply formatting to the record according to settings: ${JSON.stringify(settings)}`);\n const newRecord = MarcRecord.clone(record, {subfieldValues: false});\n debugData(`settings: ${JSON.stringify(settings)}`);\n\n // We should handle these in some prettier way ...\n\n // Fix 1, generate SIDs\n const generateMissingSIDsOptions = settings.generateMissingSIDs || undefined;\n const newRecord1 = generateMissingSIDs(newRecord, generateMissingSIDsOptions);\n\n // Fix 2, replace identifier prefixes\n const replacePrefixesOptions = settings.replacePrefixes || [];\n const newRecord2 = replaceAllPrefixes(newRecord1, replacePrefixesOptions);\n\n // Fix 3, handle temporary URNs from legal deposit record import\n const newRecord3 = handleTempUrns(newRecord2, settings.handleTempUrns);\n\n // Fix 4, strip extra field 884s\n const newRecord4 = stripF884s(newRecord3, settings.stripF884s);\n\n return newRecord4.toObject();\n\n}\n\n\nfunction replaceAllPrefixes(record, replacePrefixesOptions) {\n if (replacePrefixesOptions.length < 1) {\n debug(`NOT running replacePrefixes, no options`);\n return record;\n }\n\n debug(`Running replacePrefixes fixer`);\n debugData(`replacePrefixesOptions: ${JSON.stringify(replacePrefixesOptions)}`);\n\n replacePrefixesOptions.forEach(options => {\n replacePrefix(record, options);\n });\n return record;\n}\n\n\n// Replace prefix in all specified subfields\nfunction replacePrefix(record, options) {\n const {oldPrefix, newPrefix, prefixReplaceCodes} = options;\n debug(`Replacing ${oldPrefix} with ${newPrefix} in subfields ${prefixReplaceCodes}`);\n const pattern = `(${oldPrefix})`;\n const replacement = `(${newPrefix})`;\n record.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 return record;\n}\n\n\nfunction generateMissingSIDs(record, options) {\n\n const f035Filters = options && options.f035Filters ? options.f035Filters : [];\n const fSIDFilters = options && options.fSIDFilters ? options.fSIDFilters : [];\n\n if (f035Filters.length !== fSIDFilters.length || f035Filters.length < 1 || fSIDFilters.length < 1) {\n debug(`NOT running generateMissingsSIDs, no options`);\n return record;\n }\n\n debug(`Running generateMissingSIDs fixer`);\n debugData(`generateMissingSIDs options: ${JSON.stringify(options)}`);\n\n const f035s = f035ToSidInfo(record.get(/^035$/u));\n const fSIDs = sidsToSidInfo(record.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 sidsToBeAdded.forEach(sidField => record.insertField(sidField));\n return record;\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"],"mappings":";;;;;;;;;AA4BA,IAAAA,WAAA,GAAAC,OAAA;AACA,IAAAC,sBAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAC,sBAAA,CAAAH,OAAA;AA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S,CAAC,CAAC0C,GAAG,CAACO,GAAG,IAAIA,GAAG,CAACvB,KAAK,CAAC;MAE1G,IAAIa,GAAG,IAAIb,KAAK,EAAE;QAChB,OAAO;UACLa,GAAG;UACHb;QACF,CAAC;MACH;MAEA,OAAO1B,SAAS;IAClB,CAAC,CAAC,CAACsB,MAAM,CAACI,KAAK,IAAIA,KAAK,KAAK1B,SAAS,CAAC;EACzC;EAEA,SAAS+B,aAAaA,CAACD,KAAK,EAAE;IAC5B,OAAOA,KAAK,CAACkB,OAAO,CAAC,CAAC;MAAC3B;IAAS,CAAC,KAAK;MACpC,MAAM,CAAC6B,SAAS,CAAC,GAAG7B,SAAS,CAACC,MAAM,CAAC2B,GAAG,IAAIA,GAAG,CAAC1B,IAAI,KAAK,GAAG,IAAIK,WAAW,CAACS,IAAI,CAACc,MAAM,IAAIA,MAAM,CAACC,IAAI,CAACH,GAAG,CAACvB,KAAK,CAAC,CAAC,CAAC;MAEnH,IAAIwB,SAAS,EAAE;QACb,OAAO;UACLX,GAAG,EAAEV,WAAW,CAACD,WAAW,CAACyB,SAAS,CAACF,MAAM,IAAIA,MAAM,CAACC,IAAI,CAACF,SAAS,CAACxB,KAAK,CAAC,CAAC,CAAC;UAC/EA,KAAK,EAAEwB,SAAS,CAACxB,KAAK,CAAC4B,KAAK,CAACJ,SAAS,CAACxB,KAAK,CAAC6B,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;QAC/D,CAAC;MACH;MAEA,OAAOvD,SAAS;IAClB,CAAC,CAAC,CAACsB,MAAM,CAACI,KAAK,IAAIA,KAAK,KAAK1B,SAAS,CAAC;EACzC;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"fix.spec.js","names":["debug","createDebugLogger","debugData","extend","generateTests","callback","path","__dirname","recurse","useMetadataFile","fixura","failWhenNotFound","reader","READERS","JSON","getFixture","settings","undefined","fixSettings","Error","runSettings","record","MarcRecord","subfieldValues","expectedRecord","stringify","resultRecord","fixRecord","expect","to","eql"],"sources":["../../src/helpers/fix.spec.js"],"sourcesContent":["import {expect} from 'chai';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport {READERS} from '@natlibfi/fixura';\nimport generateTests from '@natlibfi/fixugen';\nimport {fixRecord} from './fix';\nimport * as fixSettings from './fix-constants';\nimport createDebugLogger from 'debug';\n//import inspect from 'util';\n\nconst debug = createDebugLogger('@natlibfi/melinda-rest-api-commons:fix:test');\nconst debugData = debug.extend('data');\n\ngenerateTests({\n callback,\n path: [__dirname, '..', '..', 'test-fixtures', 'fix'],\n recurse: true,\n useMetadataFile: true,\n fixura: {\n failWhenNotFound: false,\n reader: READERS.JSON\n }\n});\n\nfunction callback({getFixture, settings = undefined}) {\n if (settings !== undefined && fixSettings[settings] === undefined) {\n throw new Error(`There are no settings ${settings} defined!`);\n }\n const runSettings = fixSettings[settings] || settings;\n\n const record = new MarcRecord(getFixture('record.json'), {subfieldValues: false});\n const expectedRecord = getFixture('expectedRecord.json');\n\n debug(`Running fixer with settings ${settings}.`);\n debugData(JSON.stringify(runSettings, null, 2));\n\n const resultRecord = fixRecord(record, runSettings);\n debugData(resultRecord);\n debugData(expectedRecord);\n expect(resultRecord).to.eql(expectedRecord);\n\n}\n"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AAAsC;AAAA;AAAA;AACtC;;AAEA,MAAMA,KAAK,GAAG,IAAAC,cAAiB,EAAC,6CAA6C,CAAC;AAC9E,MAAMC,SAAS,GAAGF,KAAK,CAACG,MAAM,CAAC,MAAM,CAAC;AAEtC,IAAAC,gBAAa,EAAC;EACZC,QAAQ;EACRC,IAAI,EAAE,CAACC,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,eAAe,EAAE,KAAK,CAAC;EACrDC,OAAO,EAAE,IAAI;EACbC,eAAe,EAAE,IAAI;EACrBC,MAAM,EAAE;IACNC,gBAAgB,EAAE,KAAK;IACvBC,MAAM,EAAEC,eAAO,CAACC;EAClB;AACF,CAAC,CAAC;AAEF,SAAST,QAAQ,CAAC;EAACU,UAAU;EAAEC,QAAQ,GAAGC;AAAS,CAAC,EAAE;EACpD,IAAID,QAAQ,KAAKC,SAAS,IAAIC,WAAW,CAACF,QAAQ,CAAC,KAAKC,SAAS,EAAE;IACjE,MAAM,IAAIE,KAAK,CAAE,yBAAwBH,QAAS,WAAU,CAAC;EAC/D;EACA,MAAMI,WAAW,GAAGF,WAAW,CAACF,QAAQ,CAAC,IAAIA,QAAQ;EAErD,MAAMK,MAAM,GAAG,IAAIC,sBAAU,CAACP,UAAU,CAAC,aAAa,CAAC,EAAE;IAACQ,cAAc,EAAE;EAAK,CAAC,CAAC;EACjF,MAAMC,cAAc,GAAGT,UAAU,CAAC,qBAAqB,CAAC;EAExDf,KAAK,CAAE,+BAA8BgB,QAAS,GAAE,CAAC;EACjDd,SAAS,CAACY,IAAI,CAACW,SAAS,CAACL,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;EAE/C,MAAMM,YAAY,GAAG,IAAAC,cAAS,EAACN,MAAM,EAAED,WAAW,CAAC;EACnDlB,SAAS,CAACwB,YAAY,CAAC;EACvBxB,SAAS,CAACsB,cAAc,CAAC;EACzB,IAAAI,YAAM,EAACF,YAAY,CAAC,CAACG,EAAE,CAACC,GAAG,CAACN,cAAc,CAAC;AAE7C"}
1
+ {"version":3,"file":"fix.spec.js","names":["_chai","require","_marcRecord","_fixura","_fixugen","_interopRequireDefault","_fix","fixSettings","_interopRequireWildcard","_debug","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","debug","createDebugLogger","debugData","extend","generateTests","callback","path","__dirname","recurse","useMetadataFile","fixura","failWhenNotFound","reader","READERS","JSON","getFixture","settings","undefined","Error","runSettings","record","MarcRecord","subfieldValues","expectedRecord","stringify","resultRecord","fixRecord","expect","to","eql"],"sources":["../../src/helpers/fix.spec.js"],"sourcesContent":["import {expect} from 'chai';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport {READERS} from '@natlibfi/fixura';\nimport generateTests from '@natlibfi/fixugen';\nimport {fixRecord} from './fix';\nimport * as fixSettings from './fix-constants';\nimport createDebugLogger from 'debug';\n//import inspect from 'util';\n\nconst debug = createDebugLogger('@natlibfi/melinda-rest-api-commons:fix:test');\nconst debugData = debug.extend('data');\n\ngenerateTests({\n callback,\n path: [__dirname, '..', '..', 'test-fixtures', 'fix'],\n recurse: true,\n useMetadataFile: true,\n fixura: {\n failWhenNotFound: false,\n reader: READERS.JSON\n }\n});\n\nfunction callback({getFixture, settings = undefined}) {\n if (settings !== undefined && fixSettings[settings] === undefined) {\n throw new Error(`There are no settings ${settings} defined!`);\n }\n const runSettings = fixSettings[settings] || settings;\n\n const record = new MarcRecord(getFixture('record.json'), {subfieldValues: false});\n const expectedRecord = getFixture('expectedRecord.json');\n\n debug(`Running fixer with settings ${settings}.`);\n debugData(JSON.stringify(runSettings, null, 2));\n\n const resultRecord = fixRecord(record, runSettings);\n debugData(resultRecord);\n debugData(expectedRecord);\n expect(resultRecord).to.eql(expectedRecord);\n\n}\n"],"mappings":";;AAAA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAC,sBAAA,CAAAJ,OAAA;AACA,IAAAK,IAAA,GAAAL,OAAA;AACA,IAAAM,WAAA,GAAAC,uBAAA,CAAAP,OAAA;AACA,IAAAQ,MAAA,GAAAJ,sBAAA,CAAAJ,OAAA;AAAsC,SAAAS,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAH,wBAAAO,GAAA,E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K,CAAC;EACrDC,OAAO,EAAE,IAAI;EACbC,eAAe,EAAE,IAAI;EACrBC,MAAM,EAAE;IACNC,gBAAgB,EAAE,KAAK;IACvBC,MAAM,EAAEC,eAAO,CAACC;EAClB;AACF,CAAC,CAAC;AAEF,SAAST,QAAQA,CAAC;EAACU,UAAU;EAAEC,QAAQ,GAAGC;AAAS,CAAC,EAAE;EACpD,IAAID,QAAQ,KAAKC,SAAS,IAAI1C,WAAW,CAACyC,QAAQ,CAAC,KAAKC,SAAS,EAAE;IACjE,MAAM,IAAIC,KAAK,CAAE,yBAAwBF,QAAS,WAAU,CAAC;EAC/D;EACA,MAAMG,WAAW,GAAG5C,WAAW,CAACyC,QAAQ,CAAC,IAAIA,QAAQ;EAErD,MAAMI,MAAM,GAAG,IAAIC,sBAAU,CAACN,UAAU,CAAC,aAAa,CAAC,EAAE;IAACO,cAAc,EAAE;EAAK,CAAC,CAAC;EACjF,MAAMC,cAAc,GAAGR,UAAU,CAAC,qBAAqB,CAAC;EAExDf,KAAK,CAAE,+BAA8BgB,QAAS,GAAE,CAAC;EACjDd,SAAS,CAACY,IAAI,CAACU,SAAS,CAACL,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;EAE/C,MAAMM,YAAY,GAAG,IAAAC,cAAS,EAACN,MAAM,EAAED,WAAW,CAAC;EACnDjB,SAAS,CAACuB,YAAY,CAAC;EACvBvB,SAAS,CAACqB,cAAc,CAAC;EACzB,IAAAI,YAAM,EAACF,YAAY,CAAC,CAACG,EAAE,CAACC,GAAG,CAACN,cAAc,CAAC;AAE7C"}
@@ -1 +1 @@
1
- {"version":3,"file":"validation.js","names":["logger","createLogger","verbose","validate","validateFactory","fieldStructure","tag","valuePattern","unvalidRecord","record","valid","report","fix","validateFixes","subfieldValues","failed","messages"],"sources":["../../src/helpers/validation.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 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 validateFactory from '@natlibfi/marc-record-validate';\nimport {\n FieldStructure as fieldStructure\n} from '@natlibfi/marc-record-validators-melinda';\nimport {createLogger} from '@natlibfi/melinda-backend-commons';\n\nexport default async () => {\n const logger = createLogger();\n\n logger.verbose('Running inbuilt record validations');\n const validate = validateFactory([await fieldStructure([{tag: /^003$/u, valuePattern: /^FI-MELINDA$/u}])]);\n\n return async unvalidRecord => {\n const {record, valid, report} = await validate(unvalidRecord, {fix: false, validateFixes: false}, {subfieldValues: false});\n\n return {\n record,\n failed: valid === false,\n messages: report\n };\n };\n};\n"],"mappings":";;;;;;AA4BA;AACA;AAGA;AAA+D;AAhC/D;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;AA1BA,eAkCe,YAAY;EACzB,MAAMA,MAAM,GAAG,IAAAC,mCAAY,GAAE;EAE7BD,MAAM,CAACE,OAAO,CAAC,oCAAoC,CAAC;EACpD,MAAMC,QAAQ,GAAG,IAAAC,2BAAe,EAAC,CAAC,MAAM,IAAAC,2CAAc,EAAC,CAAC;IAACC,GAAG,EAAE,QAAQ;IAAEC,YAAY,EAAE;EAAe,CAAC,CAAC,CAAC,CAAC,CAAC;EAE1G,OAAO,MAAMC,aAAa,IAAI;IAC5B,MAAM;MAACC,MAAM;MAAEC,KAAK;MAAEC;IAAM,CAAC,GAAG,MAAMR,QAAQ,CAACK,aAAa,EAAE;MAACI,GAAG,EAAE,KAAK;MAAEC,aAAa,EAAE;IAAK,CAAC,EAAE;MAACC,cAAc,EAAE;IAAK,CAAC,CAAC;IAE1H,OAAO;MACLL,MAAM;MACNM,MAAM,EAAEL,KAAK,KAAK,KAAK;MACvBM,QAAQ,EAAEL;IACZ,CAAC;EACH,CAAC;AACH,CAAC;AAAA"}
1
+ {"version":3,"file":"validation.js","names":["_marcRecordValidate","_interopRequireDefault","require","_marcRecordValidatorsMelinda","_melindaBackendCommons","obj","__esModule","default","_default","logger","createLogger","verbose","validate","validateFactory","fieldStructure","tag","valuePattern","unvalidRecord","record","valid","report","fix","validateFixes","subfieldValues","failed","messages","exports"],"sources":["../../src/helpers/validation.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 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 validateFactory from '@natlibfi/marc-record-validate';\nimport {\n FieldStructure as fieldStructure\n} from '@natlibfi/marc-record-validators-melinda';\nimport {createLogger} from '@natlibfi/melinda-backend-commons';\n\nexport default async () => {\n const logger = createLogger();\n\n logger.verbose('Running inbuilt record validations');\n const validate = validateFactory([await fieldStructure([{tag: /^003$/u, valuePattern: /^FI-MELINDA$/u}])]);\n\n return async unvalidRecord => {\n const {record, valid, report} = await validate(unvalidRecord, {fix: false, validateFixes: false}, {subfieldValues: false});\n\n return {\n record,\n failed: valid === false,\n messages: report\n };\n };\n};\n"],"mappings":";;;;;;AA4BA,IAAAA,mBAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,4BAAA,GAAAD,OAAA;AAGA,IAAAE,sBAAA,GAAAF,OAAA;AAA+D,SAAAD,uBAAAI,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAhC/D;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;AA1BA,IAAAG,QAAA,GAkCe,MAAAA,CAAA,KAAY;EACzB,MAAMC,MAAM,GAAG,IAAAC,mCAAY,GAAE;EAE7BD,MAAM,CAACE,OAAO,CAAC,oCAAoC,CAAC;EACpD,MAAMC,QAAQ,GAAG,IAAAC,2BAAe,EAAC,CAAC,MAAM,IAAAC,2CAAc,EAAC,CAAC;IAACC,GAAG,EAAE,QAAQ;IAAEC,YAAY,EAAE;EAAe,CAAC,CAAC,CAAC,CAAC,CAAC;EAE1G,OAAO,MAAMC,aAAa,IAAI;IAC5B,MAAM;MAACC,MAAM;MAAEC,KAAK;MAAEC;IAAM,CAAC,GAAG,MAAMR,QAAQ,CAACK,aAAa,EAAE;MAACI,GAAG,EAAE,KAAK;MAAEC,aAAa,EAAE;IAAK,CAAC,EAAE;MAACC,cAAc,EAAE;IAAK,CAAC,CAAC;IAE1H,OAAO;MACLL,MAAM;MACNM,MAAM,EAAEL,KAAK,KAAK,KAAK;MACvBM,QAAQ,EAAEL;IACZ,CAAC;EACH,CAAC;AACH,CAAC;AAAAM,OAAA,CAAAnB,OAAA,GAAAC,QAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"validation.spec.js","names":["describe","FIXTURES_PATH","__dirname","getFixture","fixtureFactory","root","reader","READERS","JSON","it","validator","createValidator","record","MarcRecord","components","result","toObject","expected","expect","to","eql","failed","equal"],"sources":["../../src/helpers/validation.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 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"],"mappings":";;AA4BA;AACA;AACA;AACA;AAA2C;AAAA;AAAA;AA/B3C;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,mBAAmB,EAAE,MAAM;EAClC,MAAMC,aAAa,GAAG,CACpBC,SAAS,EACT,IAAI,EACJ,IAAI,EACJ,eAAe,EACf,YAAY,CACb;EACD,MAAM;IAACC;EAAU,CAAC,GAAG,IAAAC,eAAc,EAAC;IAACC,IAAI,EAAEJ,aAAa;IAAEK,MAAM,EAAEC,eAAO,CAACC;EAAI,CAAC,CAAC;EAEhFR,QAAQ,CAAC,iBAAiB,EAAE,MAAM;IAChCS,EAAE,CAAC,2BAA2B,EAAE,YAAY;MAC1C,MAAMC,SAAS,GAAG,MAAM,IAAAC,mBAAe,GAAE;MACzC,MAAMC,MAAM,GAAG,IAAIC,sBAAU,CAACV,UAAU,CAAC;QACvCW,UAAU,EAAE,CACV,IAAI,EACJ,sBAAsB;MAE1B,CAAC,CAAC,CAAC;MACH,MAAMC,MAAM,GAAG,MAAML,SAAS,CAACE,MAAM,CAACI,QAAQ,EAAE,CAAC;MACjD,MAAMC,QAAQ,GAAGd,UAAU,CAAC;QAC1BW,UAAU,EAAE,CACV,KAAK,EACL,sBAAsB;MAE1B,CAAC,CAAC;MACF,IAAAI,YAAM,EAACH,MAAM,CAAC,CAACI,EAAE,CAACC,GAAG,CAACH,QAAQ,CAAC;MAC/B,IAAAC,YAAM,EAACH,MAAM,CAACM,MAAM,CAAC,CAACF,EAAE,CAACG,KAAK,CAAC,KAAK,CAAC;IACvC,CAAC,CAAC;EACJ,CAAC,CAAC;EAEFtB,QAAQ,CAAC,qBAAqB,EAAE,MAAM;IACpCS,EAAE,CAAC,0BAA0B,EAAE,YAAY;MACzC,MAAMC,SAAS,GAAG,MAAM,IAAAC,mBAAe,GAAE;MACzC,MAAMC,MAAM,GAAG,IAAIC,sBAAU,CAACV,UAAU,CAAC;QACvCW,UAAU,EAAE,CACV,IAAI,EACJ,0BAA0B;MAE9B,CAAC,CAAC,CAAC;MACH,MAAMC,MAAM,GAAG,MAAML,SAAS,CAACE,MAAM,CAACI,QAAQ,EAAE,CAAC;MACjD,MAAMC,QAAQ,GAAGd,UAAU,CAAC;QAC1BW,UAAU,EAAE,CACV,KAAK,EACL,0BAA0B;MAE9B,CAAC,CAAC;MACF,IAAAI,YAAM,EAACH,MAAM,CAAC,CAACI,EAAE,CAACC,GAAG,CAACH,QAAQ,CAAC;MAC/B,IAAAC,YAAM,EAACH,MAAM,CAACM,MAAM,CAAC,CAACF,EAAE,CAACG,KAAK,CAAC,IAAI,CAAC;IACtC,CAAC,CAAC;EACJ,CAAC,CAAC;AACJ,CAAC,CAAC"}
1
+ {"version":3,"file":"validation.spec.js","names":["_chai","require","_fixura","_interopRequireWildcard","_marcRecord","_validation","_interopRequireDefault","obj","__esModule","default","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","describe","FIXTURES_PATH","__dirname","getFixture","fixtureFactory","root","reader","READERS","JSON","it","validator","createValidator","record","MarcRecord","components","result","toObject","expected","expect","to","eql","failed","equal"],"sources":["../../src/helpers/validation.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 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"],"mappings":";;AA4BA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAC,uB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C,mBAAe,GAAE;MACzC,MAAMC,MAAM,GAAG,IAAIC,sBAAU,CAACV,UAAU,CAAC;QACvCW,UAAU,EAAE,CACV,IAAI,EACJ,0BAA0B;MAE9B,CAAC,CAAC,CAAC;MACH,MAAMC,MAAM,GAAG,MAAML,SAAS,CAACE,MAAM,CAACI,QAAQ,EAAE,CAAC;MACjD,MAAMC,QAAQ,GAAGd,UAAU,CAAC;QAC1BW,UAAU,EAAE,CACV,KAAK,EACL,0BAA0B;MAE9B,CAAC,CAAC;MACF,IAAAI,YAAM,EAACH,MAAM,CAAC,CAACI,EAAE,CAACC,GAAG,CAACH,QAAQ,CAAC;MAC/B,IAAAC,YAAM,EAACH,MAAM,CAACM,MAAM,CAAC,CAACF,EAAE,CAACG,KAAK,CAAC,IAAI,CAAC;IACtC,CAAC,CAAC;EACJ,CAAC,CAAC;AACJ,CAAC,CAAC"}
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/index.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 mongoFactory from './mongo';\nimport mongoLogFactory from './mongoLog';\nimport amqpFactory from './amqp';\nimport conversions from './helpers/conversion';\nimport validations from './helpers/validation';\nimport * as fixes from './helpers/fix';\nimport {logError, createImportJobState, createImportJobStateForQuery, createRecordResponseItem, addRecordResponseItem, addRecordResponseItems} from './utils';\n\nexport {mongoFactory, mongoLogFactory, amqpFactory, conversions, validations, fixes, logError, createImportJobState, createImportJobStateForQuery, createRecordResponseItem, addRecordResponseItem, addRecordResponseItems};\nexport * from './constants';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA;AACA;AACA;AACA;AACA;AACA;AAAuC;AACvC;AAGA;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AAA4B;AAAA;AAAA"}
1
+ {"version":3,"file":"index.js","names":["_mongo","_interopRequireDefault","require","_mongoLog","_amqp","_conversion","_validation","fixes","_interopRequireWildcard","exports","_utils","_constants","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","defineProperty","enumerable","get","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","newObj","hasPropertyDescriptor","getOwnPropertyDescriptor","desc","set"],"sources":["../src/index.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 mongoFactory from './mongo';\nimport mongoLogFactory from './mongoLog';\nimport amqpFactory from './amqp';\nimport conversions from './helpers/conversion';\nimport validations from './helpers/validation';\nimport * as fixes from './helpers/fix';\nimport {logError, createImportJobState, createImportJobStateForQuery, createRecordResponseItem, addRecordResponseItem, addRecordResponseItems} from './utils';\n\nexport {mongoFactory, mongoLogFactory, amqpFactory, conversions, validations, fixes, logError, createImportJobState, createImportJobStateForQuery, createRecordResponseItem, addRecordResponseItem, addRecordResponseItems};\nexport * from './constants';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,SAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,KAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,WAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,WAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,KAAA,GAAAC,uBAAA,CAAAN,OAAA;AAAuCO,OAAA,CAAAF,KAAA,GAAAA,KAAA;AACvC,IAAAG,MAAA,GAAAR,OAAA;AAGA,IAAAS,UAAA,GAAAT,OAAA;AAAAU,MAAA,CAAAC,IAAA,CAAAF,UAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAN,OAAA,IAAAA,OAAA,CAAAM,GAAA,MAAAJ,UAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAQ,cAAA,CAAAX,OAAA,EAAAM,GAAA;IAAAM,UAAA;IAA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,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA"}
package/dist/mongo.js CHANGED
@@ -43,7 +43,6 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
43
43
  */
44
44
 
45
45
  //import isDeepStrictEqual from 'util';
46
-
47
46
  /* QueueItem:
48
47
  {
49
48
  "correlationId":"FOO",
@@ -72,7 +71,6 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
72
71
  "modificationTime":"2020-01-01T00:00:01.000Z",
73
72
  }
74
73
  */
75
-
76
74
  async function _default(MONGO_URI, collection) {
77
75
  const logger = (0, _melindaBackendCommons.createLogger)();
78
76