@natlibfi/melinda-rest-api-commons 2.2.0-alpha.6 → 2.2.0-alpha.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constants.js +7 -7
- package/dist/constants.js.map +1 -1
- package/dist/helpers/conversion.js +9 -9
- package/dist/helpers/conversion.js.map +1 -1
- package/dist/helpers/conversion.spec.js +9 -9
- package/dist/helpers/conversion.spec.js.map +1 -1
- package/dist/index.js +15 -1
- package/dist/index.js.map +1 -1
- package/dist/utils.js +83 -0
- package/dist/utils.js.map +1 -1
- package/package.json +4 -4
package/dist/constants.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.QUEUE_ITEM_STATE = exports.OPERATIONS = exports.IMPORT_JOB_STATE = exports.CONVERSION_FORMATS = exports.CHUNK_SIZE = void 0;
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
*
|
|
@@ -70,11 +70,11 @@ const OPERATIONS = {
|
|
|
70
70
|
exports.OPERATIONS = OPERATIONS;
|
|
71
71
|
const CHUNK_SIZE = 100;
|
|
72
72
|
exports.CHUNK_SIZE = CHUNK_SIZE;
|
|
73
|
-
const
|
|
74
|
-
MARCXML:
|
|
75
|
-
ISO2709:
|
|
76
|
-
JSON:
|
|
77
|
-
ALEPHSEQ:
|
|
73
|
+
const CONVERSION_FORMATS = {
|
|
74
|
+
MARCXML: 'MARCXML',
|
|
75
|
+
ISO2709: 'ISO2709',
|
|
76
|
+
JSON: 'JSON',
|
|
77
|
+
ALEPHSEQ: 'ALEPHSEQ'
|
|
78
78
|
};
|
|
79
|
-
exports.
|
|
79
|
+
exports.CONVERSION_FORMATS = CONVERSION_FORMATS;
|
|
80
80
|
//# sourceMappingURL=constants.js.map
|
package/dist/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/constants.js"],"names":["QUEUE_ITEM_STATE","VALIDATOR","PENDING_QUEUING","PENDING_VALIDATION","QUEUING_IN_PROGRESS","UPLOADING","VALIDATING","WAITING_FOR_RECORDS","IMPORTER","IMPORTING","IN_PROCESS","IN_QUEUE","DONE","ERROR","ABORT","IMPORT_JOB_STATE","EMPTY","QUEUING","PROCESSING","OPERATIONS","CREATE","UPDATE","CHUNK_SIZE","
|
|
1
|
+
{"version":3,"sources":["../src/constants.js"],"names":["QUEUE_ITEM_STATE","VALIDATOR","PENDING_QUEUING","PENDING_VALIDATION","QUEUING_IN_PROGRESS","UPLOADING","VALIDATING","WAITING_FOR_RECORDS","IMPORTER","IMPORTING","IN_PROCESS","IN_QUEUE","DONE","ERROR","ABORT","IMPORT_JOB_STATE","EMPTY","QUEUING","PROCESSING","OPERATIONS","CREATE","UPDATE","CHUNK_SIZE","CONVERSION_FORMATS","MARCXML","ISO2709","JSON","ALEPHSEQ"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AAEO,MAAMA,gBAAgB,GAAG;AAC9BC,EAAAA,SAAS,EAAE;AACTC,IAAAA,eAAe,EAAE,iBADR;AAETC,IAAAA,kBAAkB,EAAE,oBAFX;AAGTC,IAAAA,mBAAmB,EAAE,qBAHZ;AAITC,IAAAA,SAAS,EAAE,WAJF;AAKTC,IAAAA,UAAU,EAAE,YALH;AAMTC,IAAAA,mBAAmB,EAAE;AANZ,GADmB;AAS9BC,EAAAA,QAAQ,EAAE;AACRC,IAAAA,SAAS,EAAE,WADH;AAERC,IAAAA,UAAU,EAAE,YAFJ;AAGRC,IAAAA,QAAQ,EAAE;AAHF,GAToB;AAc9BC,EAAAA,IAAI,EAAE,MAdwB;AAe9BC,EAAAA,KAAK,EAAE,OAfuB;AAgB9BC,EAAAA,KAAK,EAAE;AAhBuB,CAAzB;;AAmBA,MAAMC,gBAAgB,GAAG;AAC9BC,EAAAA,KAAK,EAAE,OADuB;AAE9BC,EAAAA,OAAO,EAAE,SAFqB;AAG9BN,EAAAA,QAAQ,EAAE,UAHoB;AAI9BF,EAAAA,SAAS,EAAE,WAJmB;AAK9BS,EAAAA,UAAU,EAAE,YALkB;AAM9BN,EAAAA,IAAI,EAAE,MANwB;AAO9BC,EAAAA,KAAK,EAAE,OAPuB;AAQ9BC,EAAAA,KAAK,EAAE;AARuB,CAAzB;;AAWA,MAAMK,UAAU,GAAG;AACxBC,EAAAA,MAAM,EAAE,QADgB;AAExBC,EAAAA,MAAM,EAAE;AAFgB,CAAnB;;AAKA,MAAMC,UAAU,GAAG,GAAnB;;AAEA,MAAMC,kBAAkB,GAAG;AAChCC,EAAAA,OAAO,EAAE,SADuB;AAEhCC,EAAAA,OAAO,EAAE,SAFuB;AAGhCC,EAAAA,IAAI,EAAE,MAH0B;AAIhCC,EAAAA,QAAQ,EAAE;AAJsB,CAA3B","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\n// QueueItemState flows: see README.md\n\nexport const QUEUE_ITEM_STATE = {\n VALIDATOR: {\n PENDING_QUEUING: 'PENDING_QUEUING',\n PENDING_VALIDATION: 'PENDING_VALIDATION',\n QUEUING_IN_PROGRESS: 'QUEUING_IN_PROGRESS',\n UPLOADING: 'UPLOADING',\n VALIDATING: 'VALIDATING',\n WAITING_FOR_RECORDS: 'WAITING_FOR_RECORDS'\n },\n IMPORTER: {\n IMPORTING: 'IMPORTING',\n IN_PROCESS: 'IN_PROCESS',\n IN_QUEUE: 'IN_QUEUE'\n },\n DONE: 'DONE',\n ERROR: 'ERROR',\n ABORT: 'ABORT'\n};\n\nexport const IMPORT_JOB_STATE = {\n EMPTY: 'EMPTY',\n QUEUING: 'QUEUING',\n IN_QUEUE: 'IN_QUEUE',\n IMPORTING: 'IMPORTING',\n PROCESSING: 'PROCESSING',\n DONE: 'DONE',\n ERROR: 'ERROR',\n ABORT: 'ABORT'\n};\n\nexport const OPERATIONS = {\n CREATE: 'CREATE',\n UPDATE: 'UPDATE'\n};\n\nexport const CHUNK_SIZE = 100;\n\nexport const CONVERSION_FORMATS = {\n MARCXML: 'MARCXML',\n ISO2709: 'ISO2709',\n JSON: 'JSON',\n ALEPHSEQ: 'ALEPHSEQ'\n};\n"],"file":"constants.js"}
|
|
@@ -51,25 +51,25 @@ function _default() {
|
|
|
51
51
|
return {
|
|
52
52
|
serialize,
|
|
53
53
|
unserialize
|
|
54
|
-
};
|
|
54
|
+
}; // This uses format as a number form contants CONVERSION_FORMATS
|
|
55
55
|
|
|
56
56
|
function serialize(record, format) {
|
|
57
57
|
logger.verbose(`Serializing record to ${format}`);
|
|
58
58
|
|
|
59
59
|
try {
|
|
60
|
-
if (format === _constants.
|
|
60
|
+
if (format === _constants.CONVERSION_FORMATS.MARCXML) {
|
|
61
61
|
return _marcRecordSerializers.MARCXML.to(record);
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
if (format === _constants.
|
|
64
|
+
if (format === _constants.CONVERSION_FORMATS.ISO2709) {
|
|
65
65
|
return _marcRecordSerializers.ISO2709.to(record);
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
if (format === _constants.
|
|
68
|
+
if (format === _constants.CONVERSION_FORMATS.JSON) {
|
|
69
69
|
return _marcRecordSerializers.Json.to(record);
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
if (format === _constants.
|
|
72
|
+
if (format === _constants.CONVERSION_FORMATS.ALEPHSEQ) {
|
|
73
73
|
return _marcRecordSerializers.AlephSequential.to(record);
|
|
74
74
|
}
|
|
75
75
|
|
|
@@ -96,22 +96,22 @@ function _default() {
|
|
|
96
96
|
logger.silly(`Data: ${JSON.stringify(data)}`);
|
|
97
97
|
|
|
98
98
|
try {
|
|
99
|
-
if (format === _constants.
|
|
99
|
+
if (format === _constants.CONVERSION_FORMATS.MARCXML) {
|
|
100
100
|
logger.silly('Unserialize format marcxml');
|
|
101
101
|
return _marcRecordSerializers.MARCXML.from(data, validationOptions);
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
if (format === _constants.
|
|
104
|
+
if (format === _constants.CONVERSION_FORMATS.ISO2709) {
|
|
105
105
|
logger.silly('Unserialize format iso2709');
|
|
106
106
|
return _marcRecordSerializers.ISO2709.from(data, validationOptions);
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
if (format === _constants.
|
|
109
|
+
if (format === _constants.CONVERSION_FORMATS.JSON) {
|
|
110
110
|
logger.silly('Unserialize format json');
|
|
111
111
|
return _marcRecordSerializers.Json.from(data, validationOptions);
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
-
if (format === _constants.
|
|
114
|
+
if (format === _constants.CONVERSION_FORMATS.ALEPHSEQ) {
|
|
115
115
|
logger.silly('Unserialize format aleph sequential');
|
|
116
116
|
return _marcRecordSerializers.AlephSequential.from(data, validationOptions);
|
|
117
117
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/helpers/conversion.js"],"names":["logger","serialize","unserialize","record","format","verbose","
|
|
1
|
+
{"version":3,"sources":["../../src/helpers/conversion.js"],"names":["logger","serialize","unserialize","record","format","verbose","CONVERSION_FORMATS","MARCXML","to","ISO2709","JSON","Json","ALEPHSEQ","AlephSequential","ConversionError","httpStatus","UNSUPPORTED_MEDIA_TYPE","err","BAD_REQUEST","data","validationOptions","subfieldValues","silly","debug","stringify","from"],"mappings":";;;;;;;AA4BA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;AAjCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AASe,oBAAY;AACzB,QAAMA,MAAM,GAAG,0CAAf;AAEA,SAAO;AAACC,IAAAA,SAAD;AAAYC,IAAAA;AAAZ,GAAP,CAHyB,CAKzB;;AACA,WAASD,SAAT,CAAmBE,MAAnB,EAA2BC,MAA3B,EAAmC;AACjCJ,IAAAA,MAAM,CAACK,OAAP,CAAgB,yBAAwBD,MAAO,EAA/C;;AACA,QAAI;AACF,UAAIA,MAAM,KAAKE,8BAAmBC,OAAlC,EAA2C;AACzC,eAAOA,+BAAQC,EAAR,CAAWL,MAAX,CAAP;AACD;;AAED,UAAIC,MAAM,KAAKE,8BAAmBG,OAAlC,EAA2C;AACzC,eAAOA,+BAAQD,EAAR,CAAWL,MAAX,CAAP;AACD;;AAED,UAAIC,MAAM,KAAKE,8BAAmBI,IAAlC,EAAwC;AACtC,eAAOC,4BAAKH,EAAL,CAAQL,MAAR,CAAP;AACD;;AAED,UAAIC,MAAM,KAAKE,8BAAmBM,QAAlC,EAA4C;AAC1C,eAAOC,uCAAgBL,EAAhB,CAAmBL,MAAnB,CAAP;AACD;;AAED,YAAM,IAAIW,qBAAJ,CAAoBC,oBAAWC,sBAA/B,CAAN;AACD,KAlBD,CAkBE,OAAOC,GAAP,EAAY;AACZ,2BAASA,GAAT;;AACA,UAAIA,GAAG,YAAYH,qBAAnB,EAAoC;AAAE;AACpC,cAAMG,GAAN;AACD;;AACD,Y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N,qBAAJ,CAAoBC,oBAAWC,sBAA/B,CAAN;AACD,KAtBD,CAsBE,OAAOC,GAAP,EAAY;AACZ,2BAASA,GAAT;;AACA,UAAIA,GAAG,YAAYH,qBAAnB,EAAoC;AAAE;AACpC,cAAMG,GAAN;AACD;;AACD,YAAM,IAAIH,qBAAJ,CAAoBC,oBAAWG,WAA/B,EAA4C,kCAA5C,CAAN;AACD;AACF;AACF","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 httpStatus from 'http-status';\nimport {MARCXML, ISO2709, Json, AlephSequential} from '@natlibfi/marc-record-serializers';\nimport {createLogger} from '@natlibfi/melinda-backend-commons';\nimport {Error as ConversionError} from '@natlibfi/melinda-commons';\nimport {CONVERSION_FORMATS} from '../constants';\nimport {logError} from '../utils';\n\nexport default function () {\n const logger = createLogger();\n\n return {serialize, unserialize};\n\n // This uses format as a number form contants CONVERSION_FORMATS\n function serialize(record, format) {\n logger.verbose(`Serializing record to ${format}`);\n try {\n if (format === CONVERSION_FORMATS.MARCXML) {\n return MARCXML.to(record);\n }\n\n if (format === CONVERSION_FORMATS.ISO2709) {\n return ISO2709.to(record);\n }\n\n if (format === CONVERSION_FORMATS.JSON) {\n return Json.to(record);\n }\n\n if (format === CONVERSION_FORMATS.ALEPHSEQ) {\n return AlephSequential.to(record);\n }\n\n throw new ConversionError(httpStatus.UNSUPPORTED_MEDIA_TYPE);\n } catch (err) {\n logError(err);\n if (err instanceof ConversionError) { // eslint-disable-line functional/no-conditional-statement\n throw err;\n }\n throw new ConversionError(httpStatus.BAD_REQUEST, 'Error while serializing record');\n }\n }\n\n // eslint-disable-next-line max-statements\n function unserialize(data, format, validationOptions = {subfieldValues: false}) {\n logger.verbose(`Unserializing record from ${format}`);\n logger.silly(`Format: ${format}`);\n logger.debug(`Validation options: ${JSON.stringify(validationOptions)}`);\n logger.silly(`Data: ${JSON.stringify(data)}`);\n try {\n if (format === CONVERSION_FORMATS.MARCXML) {\n logger.silly('Unserialize format marcxml');\n return MARCXML.from(data, validationOptions);\n }\n\n if (format === CONVERSION_FORMATS.ISO2709) {\n logger.silly('Unserialize format iso2709');\n return ISO2709.from(data, validationOptions);\n }\n\n if (format === CONVERSION_FORMATS.JSON) {\n logger.silly('Unserialize format json');\n return Json.from(data, validationOptions);\n }\n\n if (format === CONVERSION_FORMATS.ALEPHSEQ) {\n logger.silly('Unserialize format aleph sequential');\n return AlephSequential.from(data, validationOptions);\n }\n\n throw new ConversionError(httpStatus.UNSUPPORTED_MEDIA_TYPE);\n } catch (err) {\n logError(err);\n if (err instanceof ConversionError) { // eslint-disable-line functional/no-conditional-statement\n throw err;\n }\n throw new ConversionError(httpStatus.BAD_REQUEST, 'Error while unserializing record');\n }\n }\n}\n"],"file":"conversion.js"}
|
|
@@ -76,19 +76,19 @@ describe('services/conversion', () => {
|
|
|
76
76
|
(0, _chai.expect)(conversionService.serialize).to.throw();
|
|
77
77
|
});
|
|
78
78
|
it('Should serialize to MARCXML', () => {
|
|
79
|
-
const data = conversionService.serialize(marcRecord, _constants.
|
|
79
|
+
const data = conversionService.serialize(marcRecord, _constants.CONVERSION_FORMATS.MARCXML);
|
|
80
80
|
(0, _chai.expect)(data).to.equal(marcXml);
|
|
81
81
|
});
|
|
82
82
|
it('Should serialize to ISO2709', () => {
|
|
83
|
-
const data = conversionService.serialize(marcRecord, _constants.
|
|
83
|
+
const data = conversionService.serialize(marcRecord, _constants.CONVERSION_FORMATS.ISO2709);
|
|
84
84
|
(0, _chai.expect)(data).to.equal(iso2709);
|
|
85
85
|
});
|
|
86
86
|
it('Should serialize to JSON', () => {
|
|
87
|
-
const data = conversionService.serialize(marcRecord, _constants.
|
|
87
|
+
const data = conversionService.serialize(marcRecord, _constants.CONVERSION_FORMATS.JSON);
|
|
88
88
|
(0, _chai.expect)(data).to.equal(json);
|
|
89
89
|
});
|
|
90
90
|
it('Should serialize to aleph sequential', () => {
|
|
91
|
-
const data = conversionService.serialize(marcRecord, _constants.
|
|
91
|
+
const data = conversionService.serialize(marcRecord, _constants.CONVERSION_FORMATS.ALEPHSEQ);
|
|
92
92
|
(0, _chai.expect)(data).to.equal(alephSeq);
|
|
93
93
|
});
|
|
94
94
|
});
|
|
@@ -97,24 +97,24 @@ describe('services/conversion', () => {
|
|
|
97
97
|
(0, _chai.expect)(conversionService.unserialize).to.throw();
|
|
98
98
|
});
|
|
99
99
|
it('Should unserialize from MARCXML', async () => {
|
|
100
|
-
const record = await conversionService.unserialize(marcXml, _constants.
|
|
100
|
+
const record = await conversionService.unserialize(marcXml, _constants.CONVERSION_FORMATS.MARCXML);
|
|
101
101
|
(0, _chai.expect)(record.equalsTo(marcRecord)).to.equal(true);
|
|
102
102
|
});
|
|
103
103
|
it('Should unserialize from ISO2709', () => {
|
|
104
|
-
const record = conversionService.unserialize(iso2709, _constants.
|
|
104
|
+
const record = conversionService.unserialize(iso2709, _constants.CONVERSION_FORMATS.ISO2709);
|
|
105
105
|
(0, _chai.expect)(record.equalsTo(marcRecord)).to.equal(true);
|
|
106
106
|
});
|
|
107
107
|
it('Should unserialize from JSON', () => {
|
|
108
|
-
const record = conversionService.unserialize(json, _constants.
|
|
108
|
+
const record = conversionService.unserialize(json, _constants.CONVERSION_FORMATS.JSON);
|
|
109
109
|
(0, _chai.expect)(record.equalsTo(marcRecord)).to.equal(true);
|
|
110
110
|
});
|
|
111
111
|
it('Should unserialize from Aleph sequential', () => {
|
|
112
|
-
const record = conversionService.unserialize(alephSeq, _constants.
|
|
112
|
+
const record = conversionService.unserialize(alephSeq, _constants.CONVERSION_FORMATS.ALEPHSEQ);
|
|
113
113
|
(0, _chai.expect)(record.equalsTo(marcRecord)).to.equal(true);
|
|
114
114
|
});
|
|
115
115
|
it('Should throw because the record could not be unserialized', () => {
|
|
116
116
|
(0, _chai.expect)(() => {
|
|
117
|
-
conversionService.unserialize('', _constants.
|
|
117
|
+
conversionService.unserialize('', _constants.CONVERSION_FORMATS.JSON);
|
|
118
118
|
}).to.throw(_melindaCommons.Error);
|
|
119
119
|
});
|
|
120
120
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/helpers/conversion.spec.js"],"names":["describe","getFixture","root","__dirname","conversionService","marcRecord","MarcRecord","JSON","parse","components","subfieldValues","marcXml","iso2709","json","alephSeq","it","service","to","be","an","and","respondTo","serialize","throw","data","
|
|
1
|
+
{"version":3,"sources":["../../src/helpers/conversion.spec.js"],"names":["describe","getFixture","root","__dirname","conversionService","marcRecord","MarcRecord","JSON","parse","components","subfieldValues","marcXml","iso2709","json","alephSeq","it","service","to","be","an","and","respondTo","serialize","throw","data","CONVERSION_FORMATS","MARCXML","equal","ISO2709","ALEPHSEQ","unserialize","record","equalsTo","ConversionError"],"mappings":";;AA4BA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;AAjCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AASAA,QAAQ,CAAC,qBAAD,EAAwB,MAAM;AACpC,QAAM;AAACC,IAAAA;AAAD,MAAe,qBAAe;AAACC,IAAAA,IAAI,EAAE,CACzCC,SADyC,EAE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,CAACC,QAAP,CAAgB3B,UAAhB,CAAP,EAAoCY,EAApC,CAAuCU,KAAvC,CAA6C,IAA7C;AACD,KAHC,CAAF;AAKAZ,IAAAA,EAAE,CAAC,iCAAD,EAAoC,MAAM;AAC1C,YAAMgB,MAAM,GAAG3B,iBAAiB,CAAC0B,WAAlB,CAA8BlB,OAA9B,EAAuCa,8BAAmBG,OAA1D,CAAf;AACA,wBAAOG,MAAM,CAACC,QAAP,CAAgB3B,UAAhB,CAAP,EAAoCY,EAApC,CAAuCU,KAAvC,CAA6C,IAA7C;AACD,KAHC,CAAF;AAKAZ,IAAAA,EAAE,CAAC,8BAAD,EAAiC,MAAM;AACvC,YAAMgB,MAAM,GAAG3B,iBAAiB,CAAC0B,WAAlB,CAA8BjB,IAA9B,EAAoCY,8BAAmBlB,IAAvD,CAAf;AACA,wBAAOwB,MAAM,CAACC,QAAP,CAAgB3B,UAAhB,CAAP,EAAoCY,EAApC,CAAuCU,KAAvC,CAA6C,IAA7C;AACD,KAHC,CAAF;AAKAZ,IAAAA,EAAE,CAAC,0CAAD,EAA6C,MAAM;AACnD,YAAMgB,MAAM,GAAG3B,iBAAiB,CAAC0B,WAAlB,CAA8BhB,QAA9B,EAAwCW,8BAAmBI,QAA3D,CAAf;AACA,wBAAOE,MAAM,CAACC,QAAP,CAAgB3B,UAAhB,CAAP,EAAoCY,EAApC,CAAuCU,KAAvC,CAA6C,IAA7C;AACD,KAHC,CAAF;AAMAZ,IAAAA,EAAE,CAAC,2DAAD,EAA8D,MAAM;AACpE,wBAAO,MAAM;AACXX,QAAAA,iBAAiB,CAAC0B,WAAlB,CAA8B,EAA9B,EAAkCL,8BAAmBlB,IAArD;AACD,OAFD,EAEGU,EAFH,CAEMM,KAFN,CAEYU,qBAFZ;AAGD,KAJC,CAAF;AAKD,GA/BO,CAAR;AAgCD,CArFO,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-2021 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-rest-api-commons\n*\n* melinda-rest-api-commons program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Affero General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-rest-api-commons is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Affero General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\nimport {expect} from 'chai';\nimport fixtureFactory from '@natlibfi/fixura';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport {Error as ConversionError} from '@natlibfi/melinda-commons';\nimport createConversionService from './conversion';\nimport {CONVERSION_FORMATS} from '../constants';\n\ndescribe('services/conversion', () => {\n const {getFixture} = fixtureFactory({root: [\n __dirname,\n '..',\n '..',\n 'test-fixtures',\n 'conversion'\n ]});\n const conversionService = createConversionService();\n\n const marcRecord = new MarcRecord(JSON.parse(getFixture({components: ['json1']})), {subfieldValues: false});\n const marcXml = getFixture({components: ['marcxml1']});\n const iso2709 = getFixture({components: ['iso2709_1']});\n const json = getFixture({components: ['json1']});\n const alephSeq = getFixture({components: ['aleph_sequential']});\n\n\n describe('factory', () => {\n it('Should create the expected object', () => {\n const service = createConversionService();\n expect(service).to.be.an('object').and\n .respondTo('serialize')\n .respondTo('unserialize');\n });\n });\n\n describe('#serialize', () => {\n it('Should throw because of unsupported format', () => {\n expect(conversionService.serialize).to.throw();\n });\n\n it('Should serialize to MARCXML', () => {\n const data = conversionService.serialize(marcRecord, CONVERSION_FORMATS.MARCXML);\n expect(data).to.equal(marcXml);\n });\n\n it('Should serialize to ISO2709', () => {\n const data = conversionService.serialize(marcRecord, CONVERSION_FORMATS.ISO2709);\n expect(data).to.equal(iso2709);\n });\n\n it('Should serialize to JSON', () => {\n const data = conversionService.serialize(marcRecord, CONVERSION_FORMATS.JSON);\n expect(data).to.equal(json);\n });\n\n it('Should serialize to aleph sequential', () => {\n const data = conversionService.serialize(marcRecord, CONVERSION_FORMATS.ALEPHSEQ);\n expect(data).to.equal(alephSeq);\n });\n\n });\n\n describe('#unserialize', () => {\n it('Should throw because of unsupported format', () => {\n expect(conversionService.unserialize).to.throw();\n });\n\n it('Should unserialize from MARCXML', async () => {\n const record = await conversionService.unserialize(marcXml, CONVERSION_FORMATS.MARCXML);\n expect(record.equalsTo(marcRecord)).to.equal(true);\n });\n\n it('Should unserialize from ISO2709', () => {\n const record = conversionService.unserialize(iso2709, CONVERSION_FORMATS.ISO2709);\n expect(record.equalsTo(marcRecord)).to.equal(true);\n });\n\n it('Should unserialize from JSON', () => {\n const record = conversionService.unserialize(json, CONVERSION_FORMATS.JSON);\n expect(record.equalsTo(marcRecord)).to.equal(true);\n });\n\n it('Should unserialize from Aleph sequential', () => {\n const record = conversionService.unserialize(alephSeq, CONVERSION_FORMATS.ALEPHSEQ);\n expect(record.equalsTo(marcRecord)).to.equal(true);\n });\n\n\n it('Should throw because the record could not be unserialized', () => {\n expect(() => {\n conversionService.unserialize('', CONVERSION_FORMATS.JSON);\n }).to.throw(ConversionError);\n });\n });\n});\n"],"file":"conversion.spec.js"}
|
package/dist/index.js
CHANGED
|
@@ -11,8 +11,16 @@ var _exportNames = {
|
|
|
11
11
|
format: true,
|
|
12
12
|
logError: true,
|
|
13
13
|
createImportJobState: true,
|
|
14
|
-
createImportJobStateForQuery: true
|
|
14
|
+
createImportJobStateForQuery: true,
|
|
15
|
+
createRecordResponseItem: true,
|
|
16
|
+
addRecordResponseItem: true
|
|
15
17
|
};
|
|
18
|
+
Object.defineProperty(exports, "addRecordResponseItem", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _utils.addRecordResponseItem;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
16
24
|
Object.defineProperty(exports, "amqpFactory", {
|
|
17
25
|
enumerable: true,
|
|
18
26
|
get: function () {
|
|
@@ -37,6 +45,12 @@ Object.defineProperty(exports, "createImportJobStateForQuery", {
|
|
|
37
45
|
return _utils.createImportJobStateForQuery;
|
|
38
46
|
}
|
|
39
47
|
});
|
|
48
|
+
Object.defineProperty(exports, "createRecordResponseItem", {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
get: function () {
|
|
51
|
+
return _utils.createRecordResponseItem;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
40
54
|
exports.format = void 0;
|
|
41
55
|
Object.defineProperty(exports, "logError", {
|
|
42
56
|
enumerable: true,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA;;AACA;;AACA;;AACA;;AACA;;;;AACA;;AAGA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA","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 amqpFactory from './amqp';\nimport conversions from './helpers/conversion';\nimport validations from './helpers/validation';\nimport * as format from './helpers/format';\nimport {logError, createImportJobState, createImportJobStateForQuery, createRecordResponseItem, addRecordResponseItem} from './utils';\n\nexport {mongoFactory, amqpFactory, conversions, validations, format, logError, createImportJobState, createImportJobStateForQuery, createRecordResponseItem, addRecordResponseItem};\nexport * from './constants';\n"],"file":"index.js"}
|
package/dist/utils.js
CHANGED
|
@@ -3,7 +3,10 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.addRecordResponseItem = addRecordResponseItem;
|
|
6
7
|
exports.createImportJobState = createImportJobState;
|
|
8
|
+
exports.createRecordResponseItem = createRecordResponseItem;
|
|
9
|
+
exports.getRecordResponseStatus = getRecordResponseStatus;
|
|
7
10
|
exports.logError = logError;
|
|
8
11
|
|
|
9
12
|
var _melindaBackendCommons = require("@natlibfi/melinda-backend-commons");
|
|
@@ -12,6 +15,10 @@ var _melindaCommons = require("@natlibfi/melinda-commons");
|
|
|
12
15
|
|
|
13
16
|
var _constants = require("./constants");
|
|
14
17
|
|
|
18
|
+
var _httpStatus = _interopRequireDefault(require("http-status"));
|
|
19
|
+
|
|
20
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
+
|
|
15
22
|
/**
|
|
16
23
|
*
|
|
17
24
|
* @licstart The following is the entire license notice for the JavaScript code in this file.
|
|
@@ -76,4 +83,80 @@ function createImportJobState(operation, state, queryImportJobState = false) {
|
|
|
76
83
|
[operation]: state
|
|
77
84
|
};
|
|
78
85
|
}
|
|
86
|
+
|
|
87
|
+
function createRecordResponseItem({
|
|
88
|
+
responsePayload,
|
|
89
|
+
responseStatus,
|
|
90
|
+
recordMetadata,
|
|
91
|
+
id
|
|
92
|
+
}) {
|
|
93
|
+
const recordResponseStatus = getRecordResponseStatus(responseStatus, responsePayload);
|
|
94
|
+
const recordResponseItem = {
|
|
95
|
+
melindaId: id || '000000000',
|
|
96
|
+
recordMetadata: recordMetadata || undefined,
|
|
97
|
+
...recordResponseStatus
|
|
98
|
+
};
|
|
99
|
+
return recordResponseItem;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function getRecordResponseStatus(responseStatus, responsePayload) {
|
|
103
|
+
logger.verbose(`Response status: ${responseStatus} responsePayload: ${JSON.stringify(responsePayload)}`);
|
|
104
|
+
const responseStatusName = _httpStatus.default[`${responseStatus}_NAME`];
|
|
105
|
+
logger.verbose(`Response status name: ${responseStatusName}`); // Non-http statuses
|
|
106
|
+
|
|
107
|
+
if (['UPDATED', 'CREATED', 'INVALID', 'ERROR', 'UNKNOWN'].includes(responseStatus)) {
|
|
108
|
+
return {
|
|
109
|
+
status: responseStatus,
|
|
110
|
+
message: responsePayload
|
|
111
|
+
};
|
|
112
|
+
} // Duplicates and other conflicts
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
if ([_httpStatus.default.CONFLICT, 'CONFLICT'].includes(responseStatus)) {
|
|
116
|
+
if (/^Duplicates in database/u.test(responsePayload.message)) {
|
|
117
|
+
return {
|
|
118
|
+
status: 'DUPLICATE',
|
|
119
|
+
message: responsePayload.message,
|
|
120
|
+
duplicateIds: responsePayload.ids
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return {
|
|
125
|
+
status: 'CONFLICT',
|
|
126
|
+
message: responsePayload.message
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if ([_httpStatus.default.UNPROCESSABLE_ENTITY, 'UNPROCESSABLE_ENTITY'].includes(responseStatus)) {
|
|
131
|
+
return {
|
|
132
|
+
status: 'UNPROCESSABLE_ENTITY',
|
|
133
|
+
message: responsePayload
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if ([_httpStatus.default.NOT_FOUND, 'NOT_FOUND'].includes(responseStatus)) {
|
|
138
|
+
return {
|
|
139
|
+
status: 'NOT_FOUND',
|
|
140
|
+
message: responsePayload
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return {
|
|
145
|
+
status: 'ERROR',
|
|
146
|
+
message: responsePayload
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
async function addRecordResponseItem({
|
|
151
|
+
recordResponseItem,
|
|
152
|
+
correlationId,
|
|
153
|
+
mongoOperator
|
|
154
|
+
}) {
|
|
155
|
+
await mongoOperator.pushMessages({
|
|
156
|
+
correlationId,
|
|
157
|
+
messages: [recordResponseItem],
|
|
158
|
+
messageField: 'records'
|
|
159
|
+
});
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
79
162
|
//# sourceMappingURL=utils.js.map
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils.js"],"names":["logger","logError","err","ApiError","error","JSON","stringify","stack","undefined","createImportJobState","operation","state","queryImportJobState","IMPORT_JOB_STATE","Error","OPERATIONS","importJobStateWithOperation","importJobStateForQuery"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/utils.js"],"names":["logger","logError","err","ApiError","error","JSON","stringify","stack","undefined","createImportJobState","operation","state","queryImportJobState","IMPORT_JOB_STATE","Error","OPERATIONS","importJobStateWithOperation","importJobStateForQuery","createRecordResponseItem","responsePayload","responseStatus","recordMetadata","id","recordResponseStatus","getRecordResponseStatus","recordResponseItem","melindaId","verbose","responseStatusName","httpStatus","includes","status","message","CONFLICT","test","duplicateIds","ids","UNPROCESSABLE_ENTITY","NOT_FOUND","addRecordResponseItem","correlationId","mongoOperator","pushMessages","messages","messageField"],"mappings":";;;;;;;;;;;AA4BA;;AACA;;AACA;;AACA;;;;AA/BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A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,CAAJ,EAAwF;AACtF,WAAO;AAACW,MAAAA,MAAM,EAAE,sBAAT;AAAiCC,MAAAA,OAAO,EAAEb;AAA1C,KAAP;AACD;;AAED,MAAI,CAACU,oBAAWS,SAAZ,EAAuB,WAAvB,EAAoCR,QAApC,CAA6CV,cAA7C,CAAJ,EAAkE;AAChE,WAAO;AAACW,MAAAA,MAAM,EAAE,WAAT;AAAsBC,MAAAA,OAAO,EAAEb;AAA/B,KAAP;AACD;;AAED,SAAO;AAACY,IAAAA,MAAM,EAAE,OAAT;AAAkBC,IAAAA,OAAO,EAAEb;AAA3B,GAAP;AACD;;AAEM,eAAeoB,qBAAf,CAAqC;AAACd,EAAAA,kBAAD;AAAqBe,EAAAA,aAArB;AAAoCC,EAAAA;AAApC,CAArC,EAAyF;AAC9F,QAAMA,aAAa,CAACC,YAAd,CAA2B;AAACF,IAAAA,aAAD;AAAgBG,IAAAA,QAAQ,EAAE,CAAClB,kBAAD,CAA1B;AAAgDmB,IAAAA,YAAY,EAAE;AAA9D,GAA3B,CAAN;AACA,SAAO,IAAP;AACD","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 {createLogger} from '@natlibfi/melinda-backend-commons';\nimport {Error as ApiError} from '@natlibfi/melinda-commons';\nimport {IMPORT_JOB_STATE, OPERATIONS} from './constants';\nimport httpStatus from 'http-status';\n\nconst logger = createLogger();\n\nexport function logError(err) {\n if (err instanceof ApiError) {\n logger.error(JSON.stringify(err));\n return;\n }\n\n if (err === 'SIGINT') {\n logger.error(err);\n return;\n }\n\n logger.error(err.stack === undefined ? err : err.stack);\n}\n\nexport function createImportJobState(operation, state, queryImportJobState = false) {\n if (!(state in IMPORT_JOB_STATE)) {\n throw new Error('Invalid IMPORT_JOB_STATE');\n }\n\n if (!(operation in OPERATIONS)) {\n throw new Error('Invalid operation');\n }\n\n if (queryImportJobState) {\n const importJobStateWithOperation = `importJobState.${operation}`;\n const importJobStateForQuery = {[importJobStateWithOperation]: state};\n\n return importJobStateForQuery;\n }\n\n return {[operation]: state};\n}\n\nexport function createRecordResponseItem({responsePayload, responseStatus, recordMetadata, id}) {\n const recordResponseStatus = getRecordResponseStatus(responseStatus, responsePayload);\n const recordResponseItem = {\n melindaId: id || '000000000',\n recordMetadata: recordMetadata || undefined,\n ...recordResponseStatus\n };\n return recordResponseItem;\n}\n\nexport function getRecordResponseStatus(responseStatus, responsePayload) {\n\n logger.verbose(`Response status: ${responseStatus} responsePayload: ${JSON.stringify(responsePayload)}`);\n const responseStatusName = httpStatus[`${responseStatus}_NAME`];\n logger.verbose(`Response status name: ${responseStatusName}`);\n\n // Non-http statuses\n if (['UPDATED', 'CREATED', 'INVALID', 'ERROR', 'UNKNOWN'].includes(responseStatus)) {\n return {status: responseStatus, message: responsePayload};\n }\n\n // Duplicates and other conflicts\n if ([httpStatus.CONFLICT, 'CONFLICT'].includes(responseStatus)) {\n if ((/^Duplicates in database/u).test(responsePayload.message)) {\n return {status: 'DUPLICATE', message: responsePayload.message, duplicateIds: responsePayload.ids};\n }\n return {status: 'CONFLICT', message: responsePayload.message};\n }\n\n if ([httpStatus.UNPROCESSABLE_ENTITY, 'UNPROCESSABLE_ENTITY'].includes(responseStatus)) {\n return {status: 'UNPROCESSABLE_ENTITY', message: responsePayload};\n }\n\n if ([httpStatus.NOT_FOUND, 'NOT_FOUND'].includes(responseStatus)) {\n return {status: 'NOT_FOUND', message: responsePayload};\n }\n\n return {status: 'ERROR', message: responsePayload};\n}\n\nexport async function addRecordResponseItem({recordResponseItem, correlationId, mongoOperator}) {\n await mongoOperator.pushMessages({correlationId, messages: [recordResponseItem], messageField: 'records'});\n return true;\n}\n\n"],"file":"utils.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.2.0-alpha.
|
|
17
|
+
"version": "2.2.0-alpha.9",
|
|
18
18
|
"main": "./dist/index.js",
|
|
19
19
|
"engines": {
|
|
20
20
|
"node": ">=14"
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@babel/cli": "^7.17.6",
|
|
50
|
-
"@babel/core": "^7.17.
|
|
50
|
+
"@babel/core": "^7.17.8",
|
|
51
51
|
"@babel/eslint-parser": "^7.17.0",
|
|
52
52
|
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
|
53
53
|
"@babel/preset-env": "^7.16.11",
|
|
@@ -58,8 +58,8 @@
|
|
|
58
58
|
"babel-plugin-rewire": "^1.2.0",
|
|
59
59
|
"chai": "^4.3.6",
|
|
60
60
|
"cross-env": "^7.0.3",
|
|
61
|
-
"eslint": "^8.
|
|
62
|
-
"mocha": "^9.2.
|
|
61
|
+
"eslint": "^8.12.0",
|
|
62
|
+
"mocha": "^9.2.2",
|
|
63
63
|
"nodemon": "^2.0.15",
|
|
64
64
|
"nyc": "^15.1.0"
|
|
65
65
|
},
|