@natlibfi/melinda-commons 12.0.3-alpha.1 → 12.0.4-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/CODEOWNERS +9 -0
- package/.github/dependabot.yml +41 -0
- package/.github/workflows/melinda-node-tests.yml +70 -0
- package/dist/error.js +6 -35
- package/dist/error.js.map +1 -1
- package/dist/error.spec.js +3 -3
- package/dist/error.spec.js.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/subRecordPicker.js +34 -88
- package/dist/subRecordPicker.js.map +1 -1
- package/dist/subRecordPicker.spec.js +31 -67
- package/dist/subRecordPicker.spec.js.map +1 -1
- package/dist/utils.js +27 -43
- package/dist/utils.js.map +1 -1
- package/dist/utils.spec.js +53 -53
- package/dist/utils.spec.js.map +1 -1
- package/package.json +19 -19
- package/src/subRecordPicker.spec.js +0 -11
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# With this line @NatLibFi/melinda-js-lead owns any files in the /.github/
|
|
2
|
+
# directory at the root of the repository and any of its
|
|
3
|
+
# subdirectories.
|
|
4
|
+
/.github/ @NatLibFi/melinda-js-lead
|
|
5
|
+
|
|
6
|
+
# With this line @NatLibFi/melinda-js-lead owns any files in the /src/
|
|
7
|
+
# directory at the root of the repository and any of its
|
|
8
|
+
# subdirectories.
|
|
9
|
+
/src/ @NatLibFi/melinda-js-lead
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# NatLibFi/Melinda maintenance strategy
|
|
2
|
+
# https://docs.github.com/en/code-security/supply-chain-security/keeping-your-dependencies-updated-automatically/configuration-options-for-dependency-updates
|
|
3
|
+
|
|
4
|
+
version: 2
|
|
5
|
+
updates:
|
|
6
|
+
# Maintain dependencies for GitHub Actions
|
|
7
|
+
- package-ecosystem: "github-actions"
|
|
8
|
+
directory: "/"
|
|
9
|
+
schedule:
|
|
10
|
+
interval: "daily"
|
|
11
|
+
time: "06:30"
|
|
12
|
+
timezone: "Europe/Helsinki"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
# Minor updates to npm production dependencies daily
|
|
16
|
+
- package-ecosystem: "npm"
|
|
17
|
+
directory: "/"
|
|
18
|
+
schedule:
|
|
19
|
+
interval: "daily"
|
|
20
|
+
time: "06:45"
|
|
21
|
+
timezone: "Europe/Helsinki"
|
|
22
|
+
versioning-strategy: lockfile-only
|
|
23
|
+
labels:
|
|
24
|
+
- "npm minor dependencies"
|
|
25
|
+
allow:
|
|
26
|
+
- dependency-type: "production"
|
|
27
|
+
|
|
28
|
+
# Major updates to npm dependencies weekly @tuesday
|
|
29
|
+
# Not possible yet https://github.com/dependabot/dependabot-core/issues/1778
|
|
30
|
+
# - package-ecosystem: "npm"
|
|
31
|
+
# directory: "/"
|
|
32
|
+
# schedule:
|
|
33
|
+
# interval: "weekly"
|
|
34
|
+
# day: "tuesday"
|
|
35
|
+
# time: "07:00"
|
|
36
|
+
# timezone: "Europe/Helsinki"
|
|
37
|
+
# versioning-strategy: increase-if-necessary
|
|
38
|
+
# labels:
|
|
39
|
+
# - "npm major dependencies"
|
|
40
|
+
# reviewers:
|
|
41
|
+
# - "natlibfi/melinda-js-lead"
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# Melinda node tests
|
|
2
|
+
|
|
3
|
+
name: Melinda node tests
|
|
4
|
+
|
|
5
|
+
on: push
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
build-node-versions:
|
|
9
|
+
name: Node version matrix
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
|
|
12
|
+
strategy:
|
|
13
|
+
matrix:
|
|
14
|
+
node-version: [14.x, 16.x, 18.x]
|
|
15
|
+
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
|
|
16
|
+
|
|
17
|
+
steps:
|
|
18
|
+
- name: Checkout the code
|
|
19
|
+
uses: actions/checkout@v3
|
|
20
|
+
- name: Use Node.js ${{ matrix.node-version }}
|
|
21
|
+
uses: actions/setup-node@v2
|
|
22
|
+
with:
|
|
23
|
+
node-version: ${{ matrix.node-version }}
|
|
24
|
+
cache: 'npm'
|
|
25
|
+
env:
|
|
26
|
+
NPM_CONFIG_IGNORE_SCRIPTS: true
|
|
27
|
+
- run: npm audit --package-lock-only --production --audit-level=moderate
|
|
28
|
+
- run: npm ci
|
|
29
|
+
- run: npm test
|
|
30
|
+
- run: npm run build --if-present
|
|
31
|
+
|
|
32
|
+
license-scan:
|
|
33
|
+
name: License compliance check
|
|
34
|
+
runs-on: ubuntu-latest
|
|
35
|
+
|
|
36
|
+
steps:
|
|
37
|
+
- uses: actions/checkout@v3
|
|
38
|
+
- uses: mikaelvesavuori/license-compliance-action@v1.0.2
|
|
39
|
+
with:
|
|
40
|
+
exclude_pattern: /^@natlibfi/
|
|
41
|
+
|
|
42
|
+
njsscan:
|
|
43
|
+
name: Njsscan check
|
|
44
|
+
runs-on: ubuntu-latest
|
|
45
|
+
|
|
46
|
+
steps:
|
|
47
|
+
- name: Checkout the code
|
|
48
|
+
uses: actions/checkout@v3
|
|
49
|
+
- name: nodejsscan scan
|
|
50
|
+
id: njsscan
|
|
51
|
+
uses: ajinabraham/njsscan-action@master
|
|
52
|
+
with:
|
|
53
|
+
args: '.'
|
|
54
|
+
|
|
55
|
+
publish:
|
|
56
|
+
runs-on: ubuntu-latest
|
|
57
|
+
needs: [build-node-versions, njsscan]
|
|
58
|
+
if: contains(github.ref, 'refs/tags/')
|
|
59
|
+
|
|
60
|
+
steps:
|
|
61
|
+
- uses: actions/checkout@v3
|
|
62
|
+
# Setup .npmrc file to publish to npm
|
|
63
|
+
- uses: actions/setup-node@v3
|
|
64
|
+
with:
|
|
65
|
+
node-version: '14.x'
|
|
66
|
+
registry-url: 'https://registry.npmjs.org'
|
|
67
|
+
- run: npm ci
|
|
68
|
+
- run: npm publish
|
|
69
|
+
env:
|
|
70
|
+
NODE_AUTH_TOKEN: ${{ secrets.MELINDA_COMMONS_NPM_TOKEN }}
|
package/dist/error.js
CHANGED
|
@@ -1,28 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
3
|
Object.defineProperty(exports, "__esModule", {
|
|
6
4
|
value: true
|
|
7
5
|
});
|
|
8
6
|
exports.default = void 0;
|
|
9
7
|
|
|
10
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
11
|
-
|
|
12
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
13
|
-
|
|
14
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
15
|
-
|
|
16
|
-
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
17
|
-
|
|
18
|
-
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
19
|
-
|
|
20
|
-
var _wrapNativeSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/wrapNativeSuper"));
|
|
21
|
-
|
|
22
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
|
|
23
|
-
|
|
24
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
25
|
-
|
|
26
8
|
/**
|
|
27
9
|
*
|
|
28
10
|
* @licstart The following is the entire license notice for the JavaScript code in this file.
|
|
@@ -50,30 +32,19 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
50
32
|
* for the JavaScript code in this file.
|
|
51
33
|
*
|
|
52
34
|
*/
|
|
53
|
-
|
|
54
|
-
(
|
|
55
|
-
|
|
56
|
-
var _super = _createSuper(_default);
|
|
57
|
-
|
|
58
|
-
function _default(status, payload) {
|
|
59
|
-
var _this;
|
|
60
|
-
|
|
61
|
-
(0, _classCallCheck2.default)(this, _default);
|
|
62
|
-
|
|
35
|
+
class _default extends Error {
|
|
36
|
+
constructor(status, payload) {
|
|
63
37
|
for (var _len = arguments.length, params = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
64
38
|
params[_key - 2] = arguments[_key];
|
|
65
39
|
}
|
|
66
40
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
_this.payload = payload; // eslint-disable-line functional/no-this-expression
|
|
41
|
+
super(params);
|
|
42
|
+
this.status = status; // eslint-disable-line functional/no-this-expression
|
|
71
43
|
|
|
72
|
-
|
|
44
|
+
this.payload = payload; // eslint-disable-line functional/no-this-expression
|
|
73
45
|
}
|
|
74
46
|
|
|
75
|
-
|
|
76
|
-
}( /*#__PURE__*/(0, _wrapNativeSuper2.default)(Error));
|
|
47
|
+
}
|
|
77
48
|
|
|
78
49
|
exports.default = _default;
|
|
79
50
|
//# sourceMappingURL=error.js.map
|
package/dist/error.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"error.js","names":["Error","constructor","status","payload","params"],"sources":["../src/error.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Shared modules for Melinda's software\n*\n* Copyright (C) 2018-2021 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-commons-js\n*\n* melinda-commons-js program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Lesser 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-commons-js 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 Lesser General Public License for more details.\n*\n* You should have received a copy of the GNU Lesser 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 default class extends Error {\n constructor(status, payload, ...params) {\n super(params);\n this.status = status; // eslint-disable-line functional/no-this-expression\n this.payload = payload; // eslint-disable-line functional/no-this-expression\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;AAEe,uBAAcA,KAAd,CAAoB;EACjCC,WAAW,CAACC,MAAD,EAASC,OAAT,EAA6B;IAAA,kCAARC,MAAQ;MAARA,MAAQ;IAAA;;IACtC,MAAMA,MAAN;IACA,KAAKF,MAAL,GAAcA,MAAd,CAFsC,CAEhB;;IACtB,KAAKC,OAAL,GAAeA,OAAf,CAHsC,CAGd;EACzB;;AALgC"}
|
package/dist/error.spec.js
CHANGED
|
@@ -33,9 +33,9 @@ var _error = _interopRequireDefault(require("./error"));
|
|
|
33
33
|
* for the JavaScript code in this file.
|
|
34
34
|
*
|
|
35
35
|
*/
|
|
36
|
-
describe('error',
|
|
37
|
-
it('Should construct the expected instance',
|
|
38
|
-
|
|
36
|
+
describe('error', () => {
|
|
37
|
+
it('Should construct the expected instance', () => {
|
|
38
|
+
const error = new _error.default(200, 'foobar');
|
|
39
39
|
(0, _chai.expect)(error).to.be.an.instanceOf(Error);
|
|
40
40
|
(0, _chai.expect)(error.status).to.equal(200);
|
|
41
41
|
(0, _chai.expect)(error.payload).to.equal('foobar');
|
package/dist/error.spec.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"error.spec.js","names":["describe","it","error","CommonsError","expect","to","be","an","instanceOf","Error","status","equal","payload"],"sources":["../src/error.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 Melinda's software\n*\n* Copyright (C) 2018-2021 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-commons-js\n*\n* melinda-commons-js program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Lesser 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-commons-js 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 Lesser General Public License for more details.\n*\n* You should have received a copy of the GNU Lesser 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 CommonsError from './error';\n\ndescribe('error', () => {\n it('Should construct the expected instance', () => {\n const error = new CommonsError(200, 'foobar');\n\n expect(error).to.be.an.instanceOf(Error);\n expect(error.status).to.equal(200);\n expect(error.payload).to.equal('foobar');\n });\n});\n"],"mappings":";;;;AA4BA;;AACA;;AA7BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAKAA,QAAQ,CAAC,OAAD,EAAU,MAAM;EACtBC,EAAE,CAAC,wCAAD,EAA2C,MAAM;IACjD,MAAMC,KAAK,GAAG,IAAIC,cAAJ,CAAiB,GAAjB,EAAsB,QAAtB,CAAd;IAEA,IAAAC,YAAA,EAAOF,KAAP,EAAcG,EAAd,CAAiBC,EAAjB,CAAoBC,EAApB,CAAuBC,UAAvB,CAAkCC,KAAlC;IACA,IAAAL,YAAA,EAAOF,KAAK,CAACQ,MAAb,EAAqBL,EAArB,CAAwBM,KAAxB,CAA8B,GAA9B;IACA,IAAAP,YAAA,EAAOF,KAAK,CAACU,OAAb,EAAsBP,EAAtB,CAAyBM,KAAzB,CAA+B,QAA/B;EACD,CANC,CAAF;AAOD,CARO,CAAR"}
|
package/dist/index.js
CHANGED
|
@@ -11,13 +11,13 @@ var _exportNames = {
|
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "Error", {
|
|
13
13
|
enumerable: true,
|
|
14
|
-
get: function
|
|
14
|
+
get: function () {
|
|
15
15
|
return _error.default;
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
18
|
Object.defineProperty(exports, "createSubrecordPicker", {
|
|
19
19
|
enumerable: true,
|
|
20
|
-
get: function
|
|
20
|
+
get: function () {
|
|
21
21
|
return _subRecordPicker.createSubrecordPicker;
|
|
22
22
|
}
|
|
23
23
|
});
|
|
@@ -34,7 +34,7 @@ Object.keys(_utils).forEach(function (key) {
|
|
|
34
34
|
if (key in exports && exports[key] === _utils[key]) return;
|
|
35
35
|
Object.defineProperty(exports, key, {
|
|
36
36
|
enumerable: true,
|
|
37
|
-
get: function
|
|
37
|
+
get: function () {
|
|
38
38
|
return _utils[key];
|
|
39
39
|
}
|
|
40
40
|
});
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.js","names":["MarcRecord","setValidationOptions","subfieldValues"],"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 Melinda's software\n*\n* Copyright (C) 2018-2021 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-commons-js\n*\n* melinda-commons-js program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Lesser 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-commons-js 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 Lesser General Public License for more details.\n*\n* You should have received a copy of the GNU Lesser 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';\n\n// Aleph creates partial subfields...\nMarcRecord.setValidationOptions({subfieldValues: false});\n\nimport {createSubrecordPicker} from './subRecordPicker';\n\nexport * from './utils';\n\nexport {default as Error} from './error';\nexport {createSubrecordPicker};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA4BA;;AAKA;;AAEA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AAEA;;AArCA;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;AAIA;AACAA,sBAAA,CAAWC,oBAAX,CAAgC;EAACC,cAAc,EAAE;AAAjB,CAAhC"}
|
package/dist/subRecordPicker.js
CHANGED
|
@@ -7,10 +7,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports.createSubrecordPicker = createSubrecordPicker;
|
|
9
9
|
|
|
10
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
11
|
-
|
|
12
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
13
|
-
|
|
14
10
|
var _sruClient = _interopRequireDefault(require("@natlibfi/sru-client"));
|
|
15
11
|
|
|
16
12
|
var _marcRecordSerializers = require("@natlibfi/marc-record-serializers");
|
|
@@ -20,118 +16,68 @@ var _debug = _interopRequireDefault(require("debug"));
|
|
|
20
16
|
var _error = require("./error");
|
|
21
17
|
|
|
22
18
|
function createSubrecordPicker(sruUrl) {
|
|
23
|
-
|
|
19
|
+
let retrieveAll = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
24
20
|
|
|
25
21
|
if (sruUrl === undefined) {
|
|
26
22
|
// eslint-disable-line functional/no-conditional-statement
|
|
27
23
|
throw new _error.Error(400, 'Invalid sru url');
|
|
28
24
|
}
|
|
29
25
|
|
|
30
|
-
|
|
26
|
+
const debug = (0, _debug.default)('@natlibfi/melinda-commons:subRecordPicker');
|
|
31
27
|
debug("SRU client url: ".concat(sruUrl));
|
|
32
|
-
|
|
28
|
+
const sruClient = (0, _sruClient.default)({
|
|
33
29
|
url: sruUrl,
|
|
34
30
|
recordSchema: 'marcxml',
|
|
35
|
-
retrieveAll
|
|
31
|
+
retrieveAll
|
|
36
32
|
});
|
|
37
33
|
return {
|
|
38
|
-
readSomeSubrecords
|
|
39
|
-
readAllSubrecords
|
|
34
|
+
readSomeSubrecords,
|
|
35
|
+
readAllSubrecords
|
|
40
36
|
};
|
|
41
37
|
|
|
42
38
|
function readSomeSubrecords(recordId) {
|
|
43
|
-
|
|
39
|
+
let offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
44
40
|
debug("Picking subrecords for ".concat(recordId));
|
|
45
|
-
return new Promise(
|
|
46
|
-
|
|
41
|
+
return new Promise((resolve, reject) => {
|
|
42
|
+
const promises = [];
|
|
47
43
|
sruClient.searchRetrieve("melinda.partsofhost=".concat(recordId), {
|
|
48
44
|
startRecord: offset
|
|
49
|
-
}).on('record',
|
|
45
|
+
}).on('record', xmlString => {
|
|
50
46
|
promises.push(_marcRecordSerializers.MARCXML.from(xmlString, {
|
|
51
47
|
subfieldValues: false
|
|
52
48
|
})); // eslint-disable-line functional/immutable-data
|
|
53
|
-
}).on('end',
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
case 3:
|
|
65
|
-
records = _context.sent;
|
|
66
|
-
resolve({
|
|
67
|
-
nextRecordOffset: nextRecordOffset,
|
|
68
|
-
records: records
|
|
69
|
-
});
|
|
70
|
-
_context.next = 10;
|
|
71
|
-
break;
|
|
72
|
-
|
|
73
|
-
case 7:
|
|
74
|
-
_context.prev = 7;
|
|
75
|
-
_context.t0 = _context["catch"](0);
|
|
76
|
-
reject(_context.t0);
|
|
77
|
-
|
|
78
|
-
case 10:
|
|
79
|
-
case "end":
|
|
80
|
-
return _context.stop();
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}, _callee, null, [[0, 7]]);
|
|
84
|
-
}));
|
|
85
|
-
|
|
86
|
-
return function (_x) {
|
|
87
|
-
return _ref.apply(this, arguments);
|
|
88
|
-
};
|
|
89
|
-
}()).on('error', function (err) {
|
|
90
|
-
return reject(err);
|
|
91
|
-
});
|
|
49
|
+
}).on('end', async nextRecordOffset => {
|
|
50
|
+
try {
|
|
51
|
+
const records = await Promise.all(promises);
|
|
52
|
+
resolve({
|
|
53
|
+
nextRecordOffset,
|
|
54
|
+
records
|
|
55
|
+
});
|
|
56
|
+
} catch (error) {
|
|
57
|
+
reject(error);
|
|
58
|
+
}
|
|
59
|
+
}).on('error', err => reject(err));
|
|
92
60
|
});
|
|
93
61
|
}
|
|
94
62
|
|
|
95
63
|
function readAllSubrecords(recordId) {
|
|
96
64
|
debug("Picking subrecords for ".concat(recordId));
|
|
97
|
-
return new Promise(
|
|
98
|
-
|
|
99
|
-
sruClient.searchRetrieve("melinda.partsofhost=".concat(recordId)).on('record',
|
|
65
|
+
return new Promise((resolve, reject) => {
|
|
66
|
+
const promises = [];
|
|
67
|
+
sruClient.searchRetrieve("melinda.partsofhost=".concat(recordId)).on('record', xmlString => {
|
|
100
68
|
promises.push(_marcRecordSerializers.MARCXML.from(xmlString, {
|
|
101
69
|
subfieldValues: false
|
|
102
70
|
})); // eslint-disable-line functional/immutable-data
|
|
103
|
-
}).on('end',
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
case 3:
|
|
114
|
-
records = _context2.sent;
|
|
115
|
-
resolve({
|
|
116
|
-
records: records
|
|
117
|
-
});
|
|
118
|
-
_context2.next = 10;
|
|
119
|
-
break;
|
|
120
|
-
|
|
121
|
-
case 7:
|
|
122
|
-
_context2.prev = 7;
|
|
123
|
-
_context2.t0 = _context2["catch"](0);
|
|
124
|
-
reject(_context2.t0);
|
|
125
|
-
|
|
126
|
-
case 10:
|
|
127
|
-
case "end":
|
|
128
|
-
return _context2.stop();
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}, _callee2, null, [[0, 7]]);
|
|
132
|
-
}))).on('error', function (err) {
|
|
133
|
-
return reject(err);
|
|
134
|
-
});
|
|
71
|
+
}).on('end', async () => {
|
|
72
|
+
try {
|
|
73
|
+
const records = await Promise.all(promises);
|
|
74
|
+
resolve({
|
|
75
|
+
records
|
|
76
|
+
});
|
|
77
|
+
} catch (error) {
|
|
78
|
+
reject(error);
|
|
79
|
+
}
|
|
80
|
+
}).on('error', err => reject(err));
|
|
135
81
|
});
|
|
136
82
|
}
|
|
137
83
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"subRecordPicker.js","names":["createSubrecordPicker","sruUrl","retrieveAll","undefined","ApiError","debug","createDebugLogger","sruClient","createSruClient","url","recordSchema","readSomeSubrecords","readAllSubrecords","recordId","offset","Promise","resolve","reject","promises","searchRetrieve","startRecord","on","xmlString","push","MARCXML","from","subfieldValues","nextRecordOffset","records","all","error","err"],"sources":["../src/subRecordPicker.js"],"sourcesContent":["import createSruClient from '@natlibfi/sru-client';\nimport {MARCXML} from '@natlibfi/marc-record-serializers';\nimport createDebugLogger from 'debug';\nimport {Error as ApiError} from './error';\n\nexport function createSubrecordPicker(sruUrl, retrieveAll = false) {\n if (sruUrl === undefined) { // eslint-disable-line functional/no-conditional-statement\n throw new ApiError(400, 'Invalid sru url');\n }\n\n const debug = createDebugLogger('@natlibfi/melinda-commons:subRecordPicker');\n debug(`SRU client url: ${sruUrl}`);\n const sruClient = createSruClient({url: sruUrl, recordSchema: 'marcxml', retrieveAll});\n\n return {readSomeSubrecords, readAllSubrecords};\n\n function readSomeSubrecords(recordId, offset = 1) {\n debug(`Picking subrecords for ${recordId}`);\n return new Promise((resolve, reject) => {\n const promises = [];\n sruClient.searchRetrieve(`melinda.partsofhost=${recordId}`, {startRecord: offset})\n .on('record', xmlString => {\n promises.push(MARCXML.from(xmlString, {subfieldValues: false})); // eslint-disable-line functional/immutable-data\n })\n .on('end', async nextRecordOffset => {\n try {\n const records = await Promise.all(promises);\n resolve({nextRecordOffset, records});\n } catch (error) {\n reject(error);\n }\n })\n .on('error', err => reject(err));\n });\n }\n\n function readAllSubrecords(recordId) {\n debug(`Picking subrecords for ${recordId}`);\n return new Promise((resolve, reject) => {\n const promises = [];\n sruClient.searchRetrieve(`melinda.partsofhost=${recordId}`)\n .on('record', xmlString => {\n promises.push(MARCXML.from(xmlString, {subfieldValues: false})); // eslint-disable-line functional/immutable-data\n })\n .on('end', async () => {\n try {\n const records = await Promise.all(promises);\n resolve({records});\n } catch (error) {\n reject(error);\n }\n })\n .on('error', err => reject(err));\n });\n }\n}\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AAEO,SAASA,qBAAT,CAA+BC,MAA/B,EAA4D;EAAA,IAArBC,WAAqB,uEAAP,KAAO;;EACjE,IAAID,MAAM,KAAKE,SAAf,EAA0B;IAAE;IAC1B,MAAM,IAAIC,YAAJ,CAAa,GAAb,EAAkB,iBAAlB,CAAN;EACD;;EAED,MAAMC,KAAK,GAAG,IAAAC,cAAA,EAAkB,2CAAlB,CAAd;EACAD,KAAK,2BAAoBJ,MAApB,EAAL;EACA,MAAMM,SAAS,GAAG,IAAAC,k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AS,IAAI;QACzBJ,QAAQ,CAACK,IAAT,CAAcC,8BAAA,CAAQC,IAAR,CAAaH,SAAb,EAAwB;UAACI,cAAc,EAAE;QAAjB,CAAxB,CAAd,EADyB,CACwC;MAClE,CAHH,EAIGL,EAJH,CAIM,KAJN,EAIa,YAAY;QACrB,IAAI;UACF,MAAMO,OAAO,GAAG,MAAMb,OAAO,CAACc,GAAR,CAAYX,QAAZ,CAAtB;UACAF,OAAO,CAAC;YAACY;UAAD,CAAD,CAAP;QACD,CAHD,CAGE,OAAOE,KAAP,EAAc;UACdb,MAAM,CAACa,KAAD,CAAN;QACD;MACF,CAXH,EAYGT,EAZH,CAYM,OAZN,EAYeU,GAAG,IAAId,MAAM,CAACc,GAAD,CAZ5B;IAaD,CAfM,CAAP;EAgBD;AACF"}
|
|
@@ -2,12 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
4
|
|
|
5
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
6
|
-
|
|
7
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
8
|
-
|
|
9
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
10
|
-
|
|
11
5
|
var _chai = require("chai");
|
|
12
6
|
|
|
13
7
|
var _subRecordPicker = require("./subRecordPicker");
|
|
@@ -16,10 +10,6 @@ var _fixura = require("@natlibfi/fixura");
|
|
|
16
10
|
|
|
17
11
|
var _fixugenHttpClient = _interopRequireDefault(require("@natlibfi/fixugen-http-client"));
|
|
18
12
|
|
|
19
|
-
var _marcRecord = require("@natlibfi/marc-record");
|
|
20
|
-
|
|
21
|
-
var _debug = _interopRequireDefault(require("debug"));
|
|
22
|
-
|
|
23
13
|
/**
|
|
24
14
|
*
|
|
25
15
|
* @licstart The following is the entire license notice for the JavaScript code in this file.
|
|
@@ -47,76 +37,50 @@ var _debug = _interopRequireDefault(require("debug"));
|
|
|
47
37
|
* for the JavaScript code in this file.
|
|
48
38
|
*
|
|
49
39
|
*/
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
var client = (0, _subRecordPicker.createSubrecordPicker)(sruUrl, retrieveAll);
|
|
40
|
+
describe('subRecordPicker', () => {
|
|
41
|
+
const sruUrl = 'https://sru';
|
|
42
|
+
const retrieveAll = false;
|
|
43
|
+
describe('createSubrecordPicker', () => {
|
|
44
|
+
it('Client should have methods', () => {
|
|
45
|
+
const client = (0, _subRecordPicker.createSubrecordPicker)(sruUrl, retrieveAll);
|
|
57
46
|
(0, _chai.expect)(client).to.respondTo('readAllSubrecords');
|
|
58
47
|
(0, _chai.expect)(client).to.respondTo('readSomeSubrecords');
|
|
59
48
|
});
|
|
60
|
-
it('Create client should work with just one parametter',
|
|
61
|
-
|
|
49
|
+
it('Create client should work with just one parametter', () => {
|
|
50
|
+
const client = (0, _subRecordPicker.createSubrecordPicker)(sruUrl);
|
|
62
51
|
(0, _chai.expect)(client).to.respondTo('readAllSubrecords');
|
|
63
52
|
(0, _chai.expect)(client).to.respondTo('readSomeSubrecords');
|
|
64
53
|
});
|
|
65
|
-
it('Create client should have at least one parametter',
|
|
54
|
+
it('Create client should have at least one parametter', () => {
|
|
66
55
|
(0, _chai.expect)(_subRecordPicker.createSubrecordPicker).to.throw();
|
|
67
56
|
});
|
|
68
57
|
});
|
|
69
58
|
(0, _fixugenHttpClient.default)({
|
|
70
|
-
callback
|
|
59
|
+
callback,
|
|
71
60
|
path: [__dirname, '..', 'test-fixtures', 'subRecordPicker']
|
|
72
61
|
});
|
|
73
62
|
|
|
74
|
-
function callback(
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
components: ['expected-records.json'],
|
|
96
|
-
reader: _fixura.READERS.JSON
|
|
97
|
-
});
|
|
98
|
-
_context.next = 6;
|
|
99
|
-
return client[method](recordId);
|
|
100
|
-
|
|
101
|
-
case 6:
|
|
102
|
-
_yield$client$method = _context.sent;
|
|
103
|
-
records = _yield$client$method.records;
|
|
104
|
-
// Expect records to be marc records
|
|
105
|
-
_records = (0, _slicedToArray2.default)(records, 1), recordObject = _records[0];
|
|
106
|
-
debug(recordObject);
|
|
107
|
-
record = new _marcRecord.MarcRecord(recordObject);
|
|
108
|
-
debug(record);
|
|
109
|
-
(0, _chai.expect)(record).to.be.instanceof(_marcRecord.MarcRecord);
|
|
110
|
-
(0, _chai.expect)(format()).to.eql(expectedRecords);
|
|
111
|
-
|
|
112
|
-
case 14:
|
|
113
|
-
case "end":
|
|
114
|
-
return _context.stop();
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}, _callee);
|
|
118
|
-
}));
|
|
119
|
-
return _callback.apply(this, arguments);
|
|
63
|
+
async function callback(_ref) {
|
|
64
|
+
let {
|
|
65
|
+
getFixture,
|
|
66
|
+
method,
|
|
67
|
+
sruUrl,
|
|
68
|
+
retrieveAll,
|
|
69
|
+
recordId
|
|
70
|
+
} = _ref;
|
|
71
|
+
const client = (0, _subRecordPicker.createSubrecordPicker)(sruUrl, retrieveAll);
|
|
72
|
+
const expectedRecords = getFixture({
|
|
73
|
+
components: ['expected-records.json'],
|
|
74
|
+
reader: _fixura.READERS.JSON
|
|
75
|
+
});
|
|
76
|
+
const {
|
|
77
|
+
records
|
|
78
|
+
} = await client[method](recordId);
|
|
79
|
+
(0, _chai.expect)(format()).to.eql(expectedRecords);
|
|
80
|
+
|
|
81
|
+
function format() {
|
|
82
|
+
return records.map(r => r.toObject());
|
|
83
|
+
}
|
|
120
84
|
}
|
|
121
85
|
});
|
|
122
86
|
//# sourceMappingURL=subRecordPicker.spec.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"subRecordPicker.spec.js","names":["describe","sruUrl","retrieveAll","it","client","createSubrecordPicker","expect","to","respondTo","throw","generateTests","callback","path","__dirname","getFixture","method","recordId","expectedRecords","components","reader","READERS","JSON","records","format","eql","map","r","toObject"],"sources":["../src/subRecordPicker.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 Melinda's software\n*\n* Copyright (C) 2018-2021 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-commons-js\n*\n* melinda-commons-js program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Lesser 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-commons-js 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 Lesser General Public License for more details.\n*\n* You should have received a copy of the GNU Lesser 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 {createSubrecordPicker} from './subRecordPicker';\nimport {READERS} from '@natlibfi/fixura';\nimport generateTests from '@natlibfi/fixugen-http-client';\n\ndescribe('subRecordPicker', () => {\n const sruUrl = 'https://sru';\n const retrieveAll = false;\n\n describe('createSubrecordPicker', () => {\n it('Client should have methods', () => {\n const client = createSubrecordPicker(sruUrl, retrieveAll);\n expect(client).to.respondTo('readAllSubrecords');\n expect(client).to.respondTo('readSomeSubrecords');\n });\n\n it('Create client should work with just one parametter', () => {\n const client = createSubrecordPicker(sruUrl);\n expect(client).to.respondTo('readAllSubrecords');\n expect(client).to.respondTo('readSomeSubrecords');\n });\n\n it('Create client should have at least one parametter', () => {\n expect(createSubrecordPicker).to.throw();\n });\n });\n\n generateTests({\n callback,\n path: [__dirname, '..', 'test-fixtures', 'subRecordPicker']\n });\n\n async function callback({getFixture, method, sruUrl, retrieveAll, recordId}) {\n const client = createSubrecordPicker(sruUrl, retrieveAll);\n const expectedRecords = getFixture({components: ['expected-records.json'], reader: READERS.JSON});\n const {records} = await client[method](recordId);\n\n expect(format()).to.eql(expectedRecords);\n\n function format() {\n return records.map(r => r.toObject());\n }\n }\n});\n"],"mappings":";;;;AA4BA;;AACA;;AACA;;AACA;;AA/BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAOAA,QAAQ,CAAC,iBAAD,EAAoB,MAAM;EAChC,MAAMC,MAAM,GAAG,aAAf;EACA,MAAMC,WAAW,GAAG,KAApB;EAEAF,QAAQ,CAAC,uBAAD,EAA0B,MAAM;IACtCG,EAAE,CAAC,4BAAD,EAA+B,MAAM;MACrC,MAAMC,MAAM,GAAG,IAAAC,sCAAA,EAAsBJ,MAAtB,EAA8BC,WAA9B,CAAf;MACA,IAAAI,YAAA,EAAOF,MAAP,EAAeG,EAAf,CAAkBC,SAAlB,CAA4B,mBAA5B;MACA,IAAAF,YAAA,EAAOF,MAAP,EAAeG,EAAf,CAAkBC,SAAlB,CAA4B,oBAA5B;IACD,CAJC,CAAF;IAMAL,EAAE,CAAC,oDAAD,EAAuD,MAAM;MAC7D,MAAMC,MAAM,GAAG,IAAAC,sCAAA,EAAsBJ,MAAtB,CAAf;MACA,IAAAK,YAAA,EAAOF,MAAP,EAAeG,EAAf,CAAkBC,SAAlB,CAA4B,mBAA5B;MACA,IAAAF,YAAA,EAAOF,MAAP,EAAeG,EAAf,CAAkBC,SAAlB,CAA4B,oBAA5B;IACD,CAJC,CAAF;IAMAL,EAAE,CAAC,mDAAD,EAAsD,MAAM;MAC5D,IAAAG,YAAA,EAAOD,sCAAP,EAA8BE,EAA9B,CAAiCE,KAAjC;IACD,CAFC,CAAF;EAGD,CAhBO,CAAR;EAkBA,IAAAC,0BAAA,EAAc;IACZC,QADY;IAEZC,IAAI,EAAE,CAACC,SAAD,EAAY,IAAZ,EAAkB,eAAlB,EAAmC,iBAAnC;EAFM,CAAd;;EAKA,eAAeF,QAAf,OAA6E;IAAA,IAArD;MAACG,UAAD;MAAaC,MAAb;MAAqBd,MAArB;MAA6BC,WAA7B;MAA0Cc;IAA1C,CAAqD;IAC3E,MAAMZ,MAAM,GAAG,IAAAC,sCAAA,EAAsBJ,MAAtB,EAA8BC,WAA9B,CAAf;IACA,MAAMe,eAAe,GAAGH,UAAU,CAAC;MAACI,UAAU,EAAE,CAAC,uBAAD,CAAb;MAAwCC,MAAM,EAAEC,eAAA,CAAQC;IAAxD,CAAD,CAAlC;IACA,MAAM;MAACC;IAAD,IAAY,MAAMlB,MAAM,CAACW,MAAD,CAAN,CAAeC,QAAf,CAAxB;IAEA,IAAAV,YAAA,EAAOiB,MAAM,EAAb,EAAiBhB,EAAjB,CAAoBiB,GAApB,CAAwBP,eAAxB;;IAEA,SAASM,MAAT,GAAkB;MAChB,OAAOD,OAAO,CAACG,GAAR,CAAYC,CAAC,IAAIA,CAAC,CAACC,QAAF,EAAjB,CAAP;IACD;EACF;AACF,CAtCO,CAAR"}
|
package/dist/utils.js
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
6
|
-
|
|
7
3
|
Object.defineProperty(exports, "__esModule", {
|
|
8
4
|
value: true
|
|
9
5
|
});
|
|
@@ -16,12 +12,6 @@ exports.isDeletedRecord = isDeletedRecord;
|
|
|
16
12
|
exports.parseBoolean = parseBoolean;
|
|
17
13
|
exports.toAlephId = toAlephId;
|
|
18
14
|
|
|
19
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
20
|
-
|
|
21
|
-
var _setPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/setPrototypeOf"));
|
|
22
|
-
|
|
23
|
-
function _wrapRegExp() { _wrapRegExp = function _wrapRegExp(re, groups) { return new BabelRegExp(re, void 0, groups); }; var _super = RegExp.prototype, _groups = new WeakMap(); function BabelRegExp(re, flags, groups) { var _this = new RegExp(re, flags); return _groups.set(_this, groups || _groups.get(re)), (0, _setPrototypeOf2.default)(_this, BabelRegExp.prototype); } function buildGroups(result, re) { var g = _groups.get(re); return Object.keys(g).reduce(function (groups, name) { return groups[name] = result[g[name]], groups; }, Object.create(null)); } return (0, _inherits2.default)(BabelRegExp, RegExp), BabelRegExp.prototype.exec = function (str) { var result = _super.exec.call(this, str); return result && (result.groups = buildGroups(result, this)), result; }, BabelRegExp.prototype[Symbol.replace] = function (str, substitution) { if ("string" == typeof substitution) { var groups = _groups.get(this); return _super[Symbol.replace].call(this, str, substitution.replace(/\$<([^>]+)>/g, function (_, name) { return "$" + groups[name]; })); } if ("function" == typeof substitution) { var _this = this; return _super[Symbol.replace].call(this, str, function () { var args = arguments; return "object" != _typeof(args[args.length - 1]) && (args = [].slice.call(args)).push(buildGroups(args, _this)), substitution.apply(this, args); }); } return _super[Symbol.replace].call(this, str, substitution); }, _wrapRegExp.apply(this, arguments); }
|
|
24
|
-
|
|
25
15
|
/**
|
|
26
16
|
*
|
|
27
17
|
* @licstart The following is the entire license notice for the JavaScript code in this file.
|
|
@@ -50,8 +40,8 @@ function _wrapRegExp() { _wrapRegExp = function _wrapRegExp(re, groups) { return
|
|
|
50
40
|
*
|
|
51
41
|
*/
|
|
52
42
|
function generateAuthorizationHeader(username) {
|
|
53
|
-
|
|
54
|
-
|
|
43
|
+
let password = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
44
|
+
const encoded = Buffer.from("".concat(username, ":").concat(password)).toString('base64');
|
|
55
45
|
return "Basic ".concat(encoded);
|
|
56
46
|
}
|
|
57
47
|
|
|
@@ -63,27 +53,35 @@ function isDeletedRecord(record) {
|
|
|
63
53
|
return checkDel() || checkSta();
|
|
64
54
|
|
|
65
55
|
function checkDel() {
|
|
66
|
-
return record.get(/^DEL$/).some(check);
|
|
56
|
+
return record.get(/^DEL$/u).some(check);
|
|
67
57
|
|
|
68
58
|
function check(_ref) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
59
|
+
let {
|
|
60
|
+
subfields
|
|
61
|
+
} = _ref;
|
|
62
|
+
return subfields.some(_ref2 => {
|
|
63
|
+
let {
|
|
64
|
+
code,
|
|
65
|
+
value
|
|
66
|
+
} = _ref2;
|
|
73
67
|
return code === 'a' && value === 'Y';
|
|
74
68
|
});
|
|
75
69
|
}
|
|
76
70
|
}
|
|
77
71
|
|
|
78
72
|
function checkSta() {
|
|
79
|
-
return record.get(/^STA$/).some(check);
|
|
73
|
+
return record.get(/^STA$/u).some(check);
|
|
80
74
|
|
|
81
75
|
function check(_ref3) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
76
|
+
let {
|
|
77
|
+
subfields
|
|
78
|
+
} = _ref3;
|
|
79
|
+
const values = ['DELETED', 'DELETED-SPLIT', 'DELETED-DEPRECATED'];
|
|
80
|
+
return subfields.some(_ref4 => {
|
|
81
|
+
let {
|
|
82
|
+
code,
|
|
83
|
+
value
|
|
84
|
+
} = _ref4;
|
|
87
85
|
return code === 'a' && values.includes(value);
|
|
88
86
|
});
|
|
89
87
|
}
|
|
@@ -103,33 +101,19 @@ function parseBoolean(value) {
|
|
|
103
101
|
}
|
|
104
102
|
|
|
105
103
|
function getRecordTitle(record) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
return f.subfields.some(function (sf) {
|
|
109
|
-
return sf.code === 'a';
|
|
110
|
-
});
|
|
111
|
-
});
|
|
104
|
+
const TRIM_PATTERN = '[?!.,(){}:;/ ]*';
|
|
105
|
+
const field = record.get(/^245$/u).find(f => f.subfields.some(sf => sf.code === 'a'));
|
|
112
106
|
|
|
113
107
|
if (field) {
|
|
114
|
-
return field.subfields.find(
|
|
115
|
-
return sf.code === 'a';
|
|
116
|
-
}).value.replace(new RegExp("^".concat(TRIM_PATTERN), 'u'), '').replace(new RegExp("".concat(TRIM_PATTERN, "$"), 'u'), '');
|
|
108
|
+
return field.subfields.find(sf => sf.code === 'a').value.replace(new RegExp("^".concat(TRIM_PATTERN), 'u'), '').replace(new RegExp("".concat(TRIM_PATTERN, "$"), 'u'), '');
|
|
117
109
|
}
|
|
118
110
|
|
|
119
111
|
return '';
|
|
120
112
|
}
|
|
121
113
|
|
|
122
114
|
function getRecordStandardIdentifiers(record) {
|
|
123
|
-
return record.get(
|
|
124
|
-
|
|
125
|
-
})).filter(function (f) {
|
|
126
|
-
return f.subfields.some(function (sf) {
|
|
127
|
-
return ['a', 'z'].includes(sf.code);
|
|
128
|
-
});
|
|
129
|
-
}).map(function (field) {
|
|
130
|
-
var subfield = field.subfields.find(function (sf) {
|
|
131
|
-
return ['a', 'z'].includes(sf.code);
|
|
132
|
-
});
|
|
115
|
+
return record.get(/^(?<def>020|022|024)$/u).filter(f => f.subfields.some(sf => ['a', 'z'].includes(sf.code))).map(field => {
|
|
116
|
+
const subfield = field.subfields.find(sf => ['a', 'z'].includes(sf.code));
|
|
133
117
|
return subfield.value;
|
|
134
118
|
});
|
|
135
119
|
}
|
|
@@ -143,6 +127,6 @@ function toAlephId(id) {
|
|
|
143
127
|
}
|
|
144
128
|
|
|
145
129
|
function fromAlephId(id) {
|
|
146
|
-
return id.replace(/^0
|
|
130
|
+
return id.replace(/^0+/u, '');
|
|
147
131
|
}
|
|
148
132
|
//# sourceMappingURL=utils.js.map
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"utils.js","names":["generateAuthorizationHeader","username","password","encoded","Buffer","from","toString","isDeletedRecord","record","includes","leader","checkDel","checkSta","get","some","check","subfields","code","value","values","parseBoolean","undefined","Number","isNaN","length","Boolean","getRecordTitle","TRIM_PATTERN","field","find","f","sf","replace","RegExp","getRecordStandardIdentifiers","filter","map","subfield","clone","o","JSON","parse","stringify","toAlephId","id","padStart","fromAlephId"],"sources":["../src/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 Melinda's software\n*\n* Copyright (C) 2018-2021 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-commons-js\n*\n* melinda-commons-js program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Lesser 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-commons-js 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 Lesser General Public License for more details.\n*\n* You should have received a copy of the GNU Lesser 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 generateAuthorizationHeader(username, password = '') {\n const encoded = Buffer.from(`${username}:${password}`).toString('base64');\n return `Basic ${encoded}`;\n}\n\nexport function isDeletedRecord(record) {\n if (['d', 's', 'x'].includes(record.leader[5])) {\n return true;\n }\n\n return checkDel() || checkSta();\n\n function checkDel() {\n return record.get(/^DEL$/u).some(check);\n\n function check({subfields}) {\n return subfields.some(({code, value}) => code === 'a' && value === 'Y');\n }\n }\n\n function checkSta() {\n return record.get(/^STA$/u).some(check);\n\n function check({subfields}) {\n const values = ['DELETED', 'DELETED-SPLIT', 'DELETED-DEPRECATED'];\n return subfields.some(({code, value}) => code === 'a' && values.includes(value));\n }\n }\n}\n\nexport function parseBoolean(value) {\n if (value === undefined) {\n return false;\n }\n\n if (Number.isNaN(Number(value))) {\n return value.length > 0 && value !== 'false';\n }\n\n return Boolean(Number(value));\n}\n\nexport function getRecordTitle(record) {\n const TRIM_PATTERN = '[?!.,(){}:;/ ]*';\n const field = record\n .get(/^245$/u)\n .find(f => f.subfields.some(sf => sf.code === 'a'));\n\n if (field) {\n return field.subfields.find(sf => sf.code === 'a').value\n .replace(new RegExp(`^${TRIM_PATTERN}`, 'u'), '')\n .replace(new RegExp(`${TRIM_PATTERN}$`, 'u'), '');\n }\n\n return '';\n}\n\nexport function getRecordStandardIdentifiers(record) {\n return record.get(/^(?<def>020|022|024)$/u)\n .filter(f => f.subfields.some(sf => ['a', 'z'].includes(sf.code)))\n .map(field => {\n const subfield = field.subfields.find(sf => ['a', 'z'].includes(sf.code));\n return subfield.value;\n });\n}\n\nexport function clone(o) {\n return JSON.parse(JSON.stringify(o));\n}\n\nexport function toAlephId(id) {\n return id.padStart(9, '0');\n}\n\nexport function fromAlephId(id) {\n return id.replace(/^0+/u, '');\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,2BAAT,CAAqCC,QAArC,EAA8D;EAAA,IAAfC,QAAe,uEAAJ,EAAI;EACnE,MAAMC,OAAO,GAAGC,MAAM,CAACC,IAAP,WAAeJ,QAAf,cAA2BC,QAA3B,GAAuCI,QAAvC,CAAgD,QAAhD,CAAhB;EACA,uBAAgBH,OAAhB;AACD;;AAEM,SAASI,eAAT,CAAyBC,MAAzB,EAAiC;EACtC,IAAI,CAAC,GAAD,EAAM,GAAN,EAAW,GAAX,EAAgBC,QAAhB,CAAyBD,MAAM,CAACE,MAAP,CAAc,CAAd,CAAzB,CAAJ,EAAgD;IAC9C,OAAO,IAAP;EACD;;EAED,OAAOC,QAAQ,MAAMC,QAAQ,EAA7B;;EAE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yB;EAC9B,OAAOA,EAAE,CAACZ,OAAH,CAAW,MAAX,EAAmB,EAAnB,CAAP;AACD"}
|
package/dist/utils.spec.js
CHANGED
|
@@ -43,114 +43,114 @@ _marcRecord.MarcRecord.setValidationOptions({
|
|
|
43
43
|
subfieldValues: false
|
|
44
44
|
});
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
const FIXTURES_PATH = _path.default.join(__dirname, '../test-fixtures/utils');
|
|
47
47
|
|
|
48
|
-
describe('utils',
|
|
49
|
-
describe('generateAuthorizationHeader',
|
|
50
|
-
it('Should create a proper Authorization header',
|
|
51
|
-
|
|
48
|
+
describe('utils', () => {
|
|
49
|
+
describe('generateAuthorizationHeader', () => {
|
|
50
|
+
it('Should create a proper Authorization header', () => {
|
|
51
|
+
const value = (0, _utils.generateAuthorizationHeader)('foo', 'bar');
|
|
52
52
|
(0, _chai.expect)(value).to.equal('Basic Zm9vOmJhcg==');
|
|
53
53
|
});
|
|
54
54
|
});
|
|
55
|
-
describe('isDeletedRecord',
|
|
56
|
-
it('Should find the record deleted (Leader)',
|
|
57
|
-
|
|
55
|
+
describe('isDeletedRecord', () => {
|
|
56
|
+
it('Should find the record deleted (Leader)', () => {
|
|
57
|
+
const data = _fs.default.readFileSync(_path.default.join(FIXTURES_PATH, 'isDeletedRecord/record1.json'), 'utf8');
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
const record = new _marcRecord.MarcRecord(JSON.parse(data));
|
|
60
60
|
(0, _chai.expect)((0, _utils.isDeletedRecord)(record)).to.equal(true);
|
|
61
61
|
});
|
|
62
|
-
it('Should find the record deleted (DEL)',
|
|
63
|
-
|
|
62
|
+
it('Should find the record deleted (DEL)', () => {
|
|
63
|
+
const data = _fs.default.readFileSync(_path.default.join(FIXTURES_PATH, 'isDeletedRecord/record2.json'), 'utf8');
|
|
64
64
|
|
|
65
|
-
|
|
65
|
+
const record = new _marcRecord.MarcRecord(JSON.parse(data));
|
|
66
66
|
(0, _chai.expect)((0, _utils.isDeletedRecord)(record)).to.equal(true);
|
|
67
67
|
});
|
|
68
|
-
it('Should find the record deleted (STA)',
|
|
69
|
-
|
|
68
|
+
it('Should find the record deleted (STA)', () => {
|
|
69
|
+
const data = _fs.default.readFileSync(_path.default.join(FIXTURES_PATH, 'isDeletedRecord/record3.json'), 'utf8');
|
|
70
70
|
|
|
71
|
-
|
|
71
|
+
const record = new _marcRecord.MarcRecord(JSON.parse(data));
|
|
72
72
|
(0, _chai.expect)((0, _utils.isDeletedRecord)(record)).to.equal(true);
|
|
73
73
|
});
|
|
74
|
-
it('Should find the record not deleted',
|
|
75
|
-
|
|
74
|
+
it('Should find the record not deleted', () => {
|
|
75
|
+
const data = _fs.default.readFileSync(_path.default.join(FIXTURES_PATH, 'isDeletedRecord/record4.json'), 'utf8');
|
|
76
76
|
|
|
77
|
-
|
|
77
|
+
const record = new _marcRecord.MarcRecord(JSON.parse(data));
|
|
78
78
|
(0, _chai.expect)((0, _utils.isDeletedRecord)(record)).to.equal(false);
|
|
79
79
|
});
|
|
80
|
-
it('Should find the record deleted (Split)',
|
|
81
|
-
|
|
80
|
+
it('Should find the record deleted (Split)', () => {
|
|
81
|
+
const data = _fs.default.readFileSync(_path.default.join(FIXTURES_PATH, 'isDeletedRecord/record5.json'), 'utf8');
|
|
82
82
|
|
|
83
|
-
|
|
83
|
+
const record = new _marcRecord.MarcRecord(JSON.parse(data));
|
|
84
84
|
(0, _chai.expect)((0, _utils.isDeletedRecord)(record)).to.equal(true);
|
|
85
85
|
});
|
|
86
|
-
it('Should find the record deleted (Deprecated)',
|
|
87
|
-
|
|
86
|
+
it('Should find the record deleted (Deprecated)', () => {
|
|
87
|
+
const data = _fs.default.readFileSync(_path.default.join(FIXTURES_PATH, 'isDeletedRecord/record6.json'), 'utf8');
|
|
88
88
|
|
|
89
|
-
|
|
89
|
+
const record = new _marcRecord.MarcRecord(JSON.parse(data));
|
|
90
90
|
(0, _chai.expect)((0, _utils.isDeletedRecord)(record)).to.equal(true);
|
|
91
91
|
});
|
|
92
|
-
it('Should find the record deleted (Split (Aleph))',
|
|
93
|
-
|
|
92
|
+
it('Should find the record deleted (Split (Aleph))', () => {
|
|
93
|
+
const data = _fs.default.readFileSync(_path.default.join(FIXTURES_PATH, 'isDeletedRecord/record7.json'), 'utf8');
|
|
94
94
|
|
|
95
|
-
|
|
95
|
+
const record = new _marcRecord.MarcRecord(JSON.parse(data));
|
|
96
96
|
(0, _chai.expect)((0, _utils.isDeletedRecord)(record)).to.equal(true);
|
|
97
97
|
});
|
|
98
|
-
it('Should find the record deleted (Deprecated (Aleph))',
|
|
99
|
-
|
|
98
|
+
it('Should find the record deleted (Deprecated (Aleph))', () => {
|
|
99
|
+
const data = _fs.default.readFileSync(_path.default.join(FIXTURES_PATH, 'isDeletedRecord/record8.json'), 'utf8');
|
|
100
100
|
|
|
101
|
-
|
|
101
|
+
const record = new _marcRecord.MarcRecord(JSON.parse(data));
|
|
102
102
|
(0, _chai.expect)((0, _utils.isDeletedRecord)(record)).to.equal(true);
|
|
103
103
|
});
|
|
104
104
|
});
|
|
105
|
-
describe('parseBoolean',
|
|
106
|
-
it('Should parse undefined as false',
|
|
105
|
+
describe('parseBoolean', () => {
|
|
106
|
+
it('Should parse undefined as false', () => {
|
|
107
107
|
(0, _chai.expect)((0, _utils.parseBoolean)(undefined)).to.equal(false);
|
|
108
108
|
});
|
|
109
|
-
it('Should parse zero-length string as false',
|
|
109
|
+
it('Should parse zero-length string as false', () => {
|
|
110
110
|
(0, _chai.expect)((0, _utils.parseBoolean)('')).to.equal(false);
|
|
111
111
|
});
|
|
112
|
-
it('Should parse numericish value as true',
|
|
112
|
+
it('Should parse numericish value as true', () => {
|
|
113
113
|
(0, _chai.expect)((0, _utils.parseBoolean)('1')).to.equal(true);
|
|
114
114
|
});
|
|
115
|
-
it('Should parse numericush value as false',
|
|
115
|
+
it('Should parse numericush value as false', () => {
|
|
116
116
|
(0, _chai.expect)((0, _utils.parseBoolean)('0')).to.equal(false);
|
|
117
117
|
});
|
|
118
|
-
it('Should parse literal \'false\' value as false',
|
|
118
|
+
it('Should parse literal \'false\' value as false', () => {
|
|
119
119
|
(0, _chai.expect)((0, _utils.parseBoolean)('false')).to.equal(false);
|
|
120
120
|
});
|
|
121
|
-
it('Should parse non-numericish value as true',
|
|
121
|
+
it('Should parse non-numericish value as true', () => {
|
|
122
122
|
(0, _chai.expect)((0, _utils.parseBoolean)('foo')).to.equal(true);
|
|
123
123
|
});
|
|
124
124
|
});
|
|
125
|
-
describe('getRecordTitle',
|
|
126
|
-
['Should find a title', 'Should not find a title'].forEach(
|
|
127
|
-
it(descr,
|
|
128
|
-
|
|
125
|
+
describe('getRecordTitle', () => {
|
|
126
|
+
['Should find a title', 'Should not find a title'].forEach((descr, index) => {
|
|
127
|
+
it(descr, () => {
|
|
128
|
+
const title = _fs.default.readFileSync(_path.default.join(FIXTURES_PATH, "getRecordTitle/title".concat(index, ".txt")), 'utf8');
|
|
129
129
|
|
|
130
|
-
|
|
130
|
+
const recordData = _fs.default.readFileSync(_path.default.join(FIXTURES_PATH, "getRecordTitle/record".concat(index, ".json")), 'utf8');
|
|
131
131
|
|
|
132
|
-
|
|
132
|
+
const record = new _marcRecord.MarcRecord(JSON.parse(recordData));
|
|
133
133
|
(0, _chai.expect)((0, _utils.getRecordTitle)(record)).to.equal(title);
|
|
134
134
|
});
|
|
135
135
|
});
|
|
136
136
|
});
|
|
137
|
-
describe('getRecordStandardIdentifiers',
|
|
138
|
-
['Should find identifiers', 'Should not find an identifier'].forEach(
|
|
139
|
-
it(descr,
|
|
140
|
-
|
|
137
|
+
describe('getRecordStandardIdentifiers', () => {
|
|
138
|
+
['Should find identifiers', 'Should not find an identifier'].forEach((descr, index) => {
|
|
139
|
+
it(descr, () => {
|
|
140
|
+
const identifiers = JSON.parse(_fs.default.readFileSync(_path.default.join(FIXTURES_PATH, "getRecordStandardIdentifiers/identifiers".concat(index, ".json")), 'utf8'));
|
|
141
141
|
|
|
142
|
-
|
|
142
|
+
const recordData = _fs.default.readFileSync(_path.default.join(FIXTURES_PATH, "getRecordStandardIdentifiers/record".concat(index, ".json")), 'utf8');
|
|
143
143
|
|
|
144
|
-
|
|
144
|
+
const record = new _marcRecord.MarcRecord(JSON.parse(recordData));
|
|
145
145
|
(0, _chai.expect)((0, _utils.getRecordStandardIdentifiers)(record)).to.eql(identifiers);
|
|
146
146
|
});
|
|
147
147
|
});
|
|
148
148
|
});
|
|
149
|
-
describe('clone',
|
|
149
|
+
describe('clone', () => {
|
|
150
150
|
it('Should clone an object', function () {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
151
|
+
let index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '1';
|
|
152
|
+
const obj = JSON.parse(_fs.default.readFileSync(_path.default.join(FIXTURES_PATH, "clone/".concat(index, "/obj.json")), 'utf8'));
|
|
153
|
+
const cloned = (0, _utils.clone)(obj);
|
|
154
154
|
(0, _chai.expect)(obj).to.not.equal(cloned);
|
|
155
155
|
(0, _chai.expect)(cloned).to.eql(obj);
|
|
156
156
|
});
|
package/dist/utils.spec.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils.spec.js"],"names":["MarcRecord","setValidationOptions","subfieldValues","FIXTURES_PATH","path","join","__dirname","describe","it","value","to","equal","data","fs","readFileSync","record","JSON","parse","undefined","forEach","descr","index","title","recordData","identifiers","eql","obj","cloned","not"],"mappings":";;;;AA4BA;;AACA;;AACA;;AACA;;AACA;;AAhCA;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;AAWAA,uBAAWC,oBAAX,CAAgC;AAACC,EAAAA,cAAc,EAAE;AAAjB,CAAhC;;AAEA,IAAMC,aAAa,GAAGC,cAAKC,IAAL,CAAUC,SAAV,EAAqB,wBAArB,CAAtB;;AAEAC,QAAQ,CAAC,OAAD,EAA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R,IAAI,CAACC,KAAL,CAAWJ,YAAGC,YAAH,CAAgBV,cAAKC,IAAL,CAAUF,aAAV,oDAAoEkB,KAApE,WAAhB,EAAmG,MAAnG,CAAX,CAApB;;AACA,YAAME,UAAU,GAAGV,YAAGC,YAAH,CAAgBV,cAAKC,IAAL,CAAUF,aAAV,+CAA+DkB,KAA/D,WAAhB,EAA8F,MAA9F,CAAnB;;AACA,YAAMN,MAAM,GAAG,IAAIf,sBAAJ,CAAegB,IAAI,CAACC,KAAL,CAAWM,UAAX,CAAf,CAAf;AAEA,0BAAO,yCAA6BR,MAA7B,CAAP,EAA6CL,EAA7C,CAAgDe,GAAhD,CAAoDD,WAApD;AACD,OANC,CAAF;AAOD,KAXD;AAYD,GAbO,CAAR;AAeAjB,EAAAA,QAAQ,CAAC,OAAD,EAAU,YAAM;AACtBC,IAAAA,EAAE,CAAC,wBAAD,EAA2B,YAAiB;AAAA,UAAhBa,KAAgB,uEAAR,GAAQ;AAC5C,UAAMK,GAAG,GAAGV,IAAI,CAACC,KAAL,CAAWJ,YAAGC,YAAH,CAAgBV,cAAKC,IAAL,CAAUF,aAAV,kBAAkCkB,KAAlC,eAAhB,EAAqE,MAArE,CAAX,CAAZ;AACA,UAAMM,MAAM,GAAG,kBAAMD,GAAN,CAAf;AAEA,wBAAOA,GAAP,EAAYhB,EAAZ,CAAekB,GAAf,CAAmBjB,KAAnB,CAAyBgB,MAAzB;AACA,wBAAOA,MAAP,EAAejB,EAAf,CAAkBe,GAAlB,CAAsBC,GAAtB;AACD,KANC,CAAF;AAOD,GARO,CAAR;AASD,CA3HO,CAAR","sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Shared modules for Melinda's software\n*\n* Copyright (C) 2018-2021 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-commons-js\n*\n* melinda-commons-js program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Lesser 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-commons-js 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 Lesser General Public License for more details.\n*\n* You should have received a copy of the GNU Lesser 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 fs from 'fs';\nimport path from 'path';\nimport {expect} from 'chai';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport {\n generateAuthorizationHeader, isDeletedRecord, parseBoolean, clone,\n getRecordTitle, getRecordStandardIdentifiers\n} from './utils';\n\nMarcRecord.setValidationOptions({subfieldValues: false});\n\nconst FIXTURES_PATH = path.join(__dirname, '../test-fixtures/utils');\n\ndescribe('utils', () => {\n describe('generateAuthorizationHeader', () => {\n it('Should create a proper Authorization header', () => {\n const value = generateAuthorizationHeader('foo', 'bar');\n expect(value).to.equal('Basic Zm9vOmJhcg==');\n });\n });\n\n describe('isDeletedRecord', () => {\n it('Should find the record deleted (Leader)', () => {\n const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isDeletedRecord/record1.json'), 'utf8');\n const record = new MarcRecord(JSON.parse(data));\n expect(isDeletedRecord(record)).to.equal(true);\n });\n\n it('Should find the record deleted (DEL)', () => {\n const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isDeletedRecord/record2.json'), 'utf8');\n const record = new MarcRecord(JSON.parse(data));\n expect(isDeletedRecord(record)).to.equal(true);\n });\n\n it('Should find the record deleted (STA)', () => {\n const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isDeletedRecord/record3.json'), 'utf8');\n const record = new MarcRecord(JSON.parse(data));\n expect(isDeletedRecord(record)).to.equal(true);\n });\n\n it('Should find the record not deleted', () => {\n const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isDeletedRecord/record4.json'), 'utf8');\n const record = new MarcRecord(JSON.parse(data));\n expect(isDeletedRecord(record)).to.equal(false);\n });\n\n it('Should find the record deleted (Split)', () => {\n const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isDeletedRecord/record5.json'), 'utf8');\n const record = new MarcRecord(JSON.parse(data));\n expect(isDeletedRecord(record)).to.equal(true);\n });\n\n it('Should find the record deleted (Deprecated)', () => {\n const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isDeletedRecord/record6.json'), 'utf8');\n const record = new MarcRecord(JSON.parse(data));\n expect(isDeletedRecord(record)).to.equal(true);\n });\n\n it('Should find the record deleted (Split (Aleph))', () => {\n const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isDeletedRecord/record7.json'), 'utf8');\n const record = new MarcRecord(JSON.parse(data));\n expect(isDeletedRecord(record)).to.equal(true);\n });\n\n it('Should find the record deleted (Deprecated (Aleph))', () => {\n const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isDeletedRecord/record8.json'), 'utf8');\n const record = new MarcRecord(JSON.parse(data));\n expect(isDeletedRecord(record)).to.equal(true);\n });\n });\n\n describe('parseBoolean', () => {\n it('Should parse undefined as false', () => {\n expect(parseBoolean(undefined)).to.equal(false);\n });\n\n it('Should parse zero-length string as false', () => {\n expect(parseBoolean('')).to.equal(false);\n });\n\n it('Should parse numericish value as true', () => {\n expect(parseBoolean('1')).to.equal(true);\n });\n\n it('Should parse numericush value as false', () => {\n expect(parseBoolean('0')).to.equal(false);\n });\n\n it('Should parse literal \\'false\\' value as false', () => {\n expect(parseBoolean('false')).to.equal(false);\n });\n\n it('Should parse non-numericish value as true', () => {\n expect(parseBoolean('foo')).to.equal(true);\n });\n });\n\n describe('getRecordTitle', () => {\n [\n 'Should find a title',\n 'Should not find a title'\n ].forEach((descr, index) => {\n it(descr, () => {\n const title = fs.readFileSync(path.join(FIXTURES_PATH, `getRecordTitle/title${index}.txt`), 'utf8');\n const recordData = fs.readFileSync(path.join(FIXTURES_PATH, `getRecordTitle/record${index}.json`), 'utf8');\n const record = new MarcRecord(JSON.parse(recordData));\n\n expect(getRecordTitle(record)).to.equal(title);\n });\n });\n });\n\n describe('getRecordStandardIdentifiers', () => {\n [\n 'Should find identifiers',\n 'Should not find an identifier'\n ].forEach((descr, index) => {\n it(descr, () => {\n const identifiers = JSON.parse(fs.readFileSync(path.join(FIXTURES_PATH, `getRecordStandardIdentifiers/identifiers${index}.json`), 'utf8'));\n const recordData = fs.readFileSync(path.join(FIXTURES_PATH, `getRecordStandardIdentifiers/record${index}.json`), 'utf8');\n const record = new MarcRecord(JSON.parse(recordData));\n\n expect(getRecordStandardIdentifiers(record)).to.eql(identifiers);\n });\n });\n });\n\n describe('clone', () => {\n it('Should clone an object', (index = '1') => {\n const obj = JSON.parse(fs.readFileSync(path.join(FIXTURES_PATH, `clone/${index}/obj.json`), 'utf8'));\n const cloned = clone(obj);\n\n expect(obj).to.not.equal(cloned);\n expect(cloned).to.eql(obj);\n });\n });\n});\n"],"file":"utils.spec.js"}
|
|
1
|
+
{"version":3,"file":"utils.spec.js","names":["MarcRecord","setValidationOptions","subfieldValues","FIXTURES_PATH","path","join","__dirname","describe","it","value","generateAuthorizationHeader","expect","to","equal","data","fs","readFileSync","record","JSON","parse","isDeletedRecord","parseBoolean","undefined","forEach","descr","index","title","recordData","getRecordTitle","identifiers","getRecordStandardIdentifiers","eql","obj","cloned","clone","not"],"sources":["../src/utils.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 Melinda's software\n*\n* Copyright (C) 2018-2021 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-commons-js\n*\n* melinda-commons-js program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Lesser 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-commons-js 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 Lesser General Public License for more details.\n*\n* You should have received a copy of the GNU Lesser 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 fs from 'fs';\nimport path from 'path';\nimport {expect} from 'chai';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport {\n generateAuthorizationHeader, isDeletedRecord, parseBoolean, clone,\n getRecordTitle, getRecordStandardIdentifiers\n} from './utils';\n\nMarcRecord.setValidationOptions({subfieldValues: false});\n\nconst FIXTURES_PATH = path.join(__dirname, '../test-fixtures/utils');\n\ndescribe('utils', () => {\n describe('generateAuthorizationHeader', () => {\n it('Should create a proper Authorization header', () => {\n const value = generateAuthorizationHeader('foo', 'bar');\n expect(value).to.equal('Basic Zm9vOmJhcg==');\n });\n });\n\n describe('isDeletedRecord', () => {\n it('Should find the record deleted (Leader)', () => {\n const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isDeletedRecord/record1.json'), 'utf8');\n const record = new MarcRecord(JSON.parse(data));\n expect(isDeletedRecord(record)).to.equal(true);\n });\n\n it('Should find the record deleted (DEL)', () => {\n const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isDeletedRecord/record2.json'), 'utf8');\n const record = new MarcRecord(JSON.parse(data));\n expect(isDeletedRecord(record)).to.equal(true);\n });\n\n it('Should find the record deleted (STA)', () => {\n const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isDeletedRecord/record3.json'), 'utf8');\n const record = new MarcRecord(JSON.parse(data));\n expect(isDeletedRecord(record)).to.equal(true);\n });\n\n it('Should find the record not deleted', () => {\n const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isDeletedRecord/record4.json'), 'utf8');\n const record = new MarcRecord(JSON.parse(data));\n expect(isDeletedRecord(record)).to.equal(false);\n });\n\n it('Should find the record deleted (Split)', () => {\n const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isDeletedRecord/record5.json'), 'utf8');\n const record = new MarcRecord(JSON.parse(data));\n expect(isDeletedRecord(record)).to.equal(true);\n });\n\n it('Should find the record deleted (Deprecated)', () => {\n const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isDeletedRecord/record6.json'), 'utf8');\n const record = new MarcRecord(JSON.parse(data));\n expect(isDeletedRecord(record)).to.equal(true);\n });\n\n it('Should find the record deleted (Split (Aleph))', () => {\n const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isDeletedRecord/record7.json'), 'utf8');\n const record = new MarcRecord(JSON.parse(data));\n expect(isDeletedRecord(record)).to.equal(true);\n });\n\n it('Should find the record deleted (Deprecated (Aleph))', () => {\n const data = fs.readFileSync(path.join(FIXTURES_PATH, 'isDeletedRecord/record8.json'), 'utf8');\n const record = new MarcRecord(JSON.parse(data));\n expect(isDeletedRecord(record)).to.equal(true);\n });\n });\n\n describe('parseBoolean', () => {\n it('Should parse undefined as false', () => {\n expect(parseBoolean(undefined)).to.equal(false);\n });\n\n it('Should parse zero-length string as false', () => {\n expect(parseBoolean('')).to.equal(false);\n });\n\n it('Should parse numericish value as true', () => {\n expect(parseBoolean('1')).to.equal(true);\n });\n\n it('Should parse numericush value as false', () => {\n expect(parseBoolean('0')).to.equal(false);\n });\n\n it('Should parse literal \\'false\\' value as false', () => {\n expect(parseBoolean('false')).to.equal(false);\n });\n\n it('Should parse non-numericish value as true', () => {\n expect(parseBoolean('foo')).to.equal(true);\n });\n });\n\n describe('getRecordTitle', () => {\n [\n 'Should find a title',\n 'Should not find a title'\n ].forEach((descr, index) => {\n it(descr, () => {\n const title = fs.readFileSync(path.join(FIXTURES_PATH, `getRecordTitle/title${index}.txt`), 'utf8');\n const recordData = fs.readFileSync(path.join(FIXTURES_PATH, `getRecordTitle/record${index}.json`), 'utf8');\n const record = new MarcRecord(JSON.parse(recordData));\n\n expect(getRecordTitle(record)).to.equal(title);\n });\n });\n });\n\n describe('getRecordStandardIdentifiers', () => {\n [\n 'Should find identifiers',\n 'Should not find an identifier'\n ].forEach((descr, index) => {\n it(descr, () => {\n const identifiers = JSON.parse(fs.readFileSync(path.join(FIXTURES_PATH, `getRecordStandardIdentifiers/identifiers${index}.json`), 'utf8'));\n const recordData = fs.readFileSync(path.join(FIXTURES_PATH, `getRecordStandardIdentifiers/record${index}.json`), 'utf8');\n const record = new MarcRecord(JSON.parse(recordData));\n\n expect(getRecordStandardIdentifiers(record)).to.eql(identifiers);\n });\n });\n });\n\n describe('clone', () => {\n it('Should clone an object', (index = '1') => {\n const obj = JSON.parse(fs.readFileSync(path.join(FIXTURES_PATH, `clone/${index}/obj.json`), 'utf8'));\n const cloned = clone(obj);\n\n expect(obj).to.not.equal(cloned);\n expect(cloned).to.eql(obj);\n });\n });\n});\n"],"mappings":";;;;AA4BA;;AACA;;AACA;;AACA;;AACA;;AAhCA;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;AAWAA,sBAAA,CAAWC,oBAAX,CAAgC;EAACC,cAAc,EAAE;AAAjB,CAAhC;;AAEA,MAAMC,aAAa,GAAGC,aAAA,CAAKC,IAAL,CAAUC,SAAV,EAAqB,wBAArB,CAAtB;;AAEAC,QAAQ,CAAC,OAAD,EAAU,MAAM;EACtBA,QAAQ,CAAC,6BAAD,EAAgC,MAAM;IAC5CC,EAAE,CAAC,6CAAD,EAAgD,MAAM;MACtD,MAAMC,KAAK,GAAG,IAAAC,kCAAA,EAA4B,KAA5B,EAAmC,KAAnC,CAAd;MACA,IAAAC,YAAA,EAAOF,KAAP,EAAcG,EAAd,CAAiBC,KAAjB,CAAuB,oBAAvB;IACD,CAHC,CAAF;EAID,CALO,CAAR;EAOAN,QAAQ,CAAC,iBAAD,EAAoB,MAAM;IAChCC,EAAE,CAAC,yCAAD,EAA4C,MAAM;MAClD,MAAMM,IAAI,GAAGC,WAAA,CAAGC,YAAH,CAAgBZ,aAAA,CAAKC,IAAL,CAAUF,aAAV,EAAyB,8BAAzB,CAAhB,EAA0E,MAA1E,C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aAAV,oDAAoEsB,KAApE,WAAhB,EAAmG,MAAnG,CAAX,CAApB;;QACA,MAAME,UAAU,GAAGZ,WAAA,CAAGC,YAAH,CAAgBZ,aAAA,CAAKC,IAAL,CAAUF,aAAV,+CAA+DsB,KAA/D,WAAhB,EAA8F,MAA9F,CAAnB;;QACA,MAAMR,MAAM,GAAG,IAAIjB,sBAAJ,CAAekB,IAAI,CAACC,KAAL,CAAWQ,UAAX,CAAf,CAAf;QAEA,IAAAhB,YAAA,EAAO,IAAAmB,mCAAA,EAA6Bb,MAA7B,CAAP,EAA6CL,EAA7C,CAAgDmB,GAAhD,CAAoDF,WAApD;MACD,CANC,CAAF;IAOD,CAXD;EAYD,CAbO,CAAR;EAeAtB,QAAQ,CAAC,OAAD,EAAU,MAAM;IACtBC,EAAE,CAAC,wBAAD,EAA2B,YAAiB;MAAA,IAAhBiB,KAAgB,uEAAR,GAAQ;MAC5C,MAAMO,GAAG,GAAGd,IAAI,CAACC,KAAL,CAAWJ,WAAA,CAAGC,YAAH,CAAgBZ,aAAA,CAAKC,IAAL,CAAUF,aAAV,kBAAkCsB,KAAlC,eAAhB,EAAqE,MAArE,CAAX,CAAZ;MACA,MAAMQ,MAAM,GAAG,IAAAC,YAAA,EAAMF,GAAN,CAAf;MAEA,IAAArB,YAAA,EAAOqB,GAAP,EAAYpB,EAAZ,CAAeuB,GAAf,CAAmBtB,KAAnB,CAAyBoB,MAAzB;MACA,IAAAtB,YAAA,EAAOsB,MAAP,EAAerB,EAAf,CAAkBmB,GAAlB,CAAsBC,GAAtB;IACD,CANC,CAAF;EAOD,CARO,CAAR;AASD,CA3HO,CAAR"}
|
package/package.json
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"url": "git@github.com:natlibfi/melinda-commons-js.git"
|
|
15
15
|
},
|
|
16
16
|
"license": "LGPL-3.0+",
|
|
17
|
-
"version": "12.0.
|
|
17
|
+
"version": "12.0.4-alpha.1",
|
|
18
18
|
"main": "./dist/index.js",
|
|
19
19
|
"engines": {
|
|
20
20
|
"node": ">=14"
|
|
@@ -34,34 +34,34 @@
|
|
|
34
34
|
"watch:test": "cross-env DEBUG=1 NODE_ENV=test nodemon -w src -w test-fixtures --exec 'npm run test:dev'"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@natlibfi/marc-record": "^7.0.
|
|
38
|
-
"@natlibfi/marc-record-serializers": "^
|
|
37
|
+
"@natlibfi/marc-record": "^7.2.0-alpha.1",
|
|
38
|
+
"@natlibfi/marc-record-serializers": "^9.0.0-alpha.4",
|
|
39
39
|
"@natlibfi/sru-client": "^5.0.1",
|
|
40
|
-
"debug": "^4.3.
|
|
41
|
-
"deep-eql": "^4.
|
|
42
|
-
"http-status": "^1.5.
|
|
43
|
-
"moment": "^2.29.
|
|
44
|
-
"nock": "^13.2.
|
|
40
|
+
"debug": "^4.3.4",
|
|
41
|
+
"deep-eql": "^4.1.0",
|
|
42
|
+
"http-status": "^1.5.2",
|
|
43
|
+
"moment": "^2.29.4",
|
|
44
|
+
"nock": "^13.2.9",
|
|
45
45
|
"node-fetch": "^2.6.7"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@babel/cli": "^7.
|
|
49
|
-
"@babel/core": "^7.
|
|
50
|
-
"@babel/eslint-parser": "^7.
|
|
51
|
-
"@babel/node": "^7.
|
|
52
|
-
"@babel/plugin-transform-runtime": "^7.
|
|
53
|
-
"@babel/preset-env": "^7.
|
|
54
|
-
"@babel/register": "^7.
|
|
55
|
-
"@natlibfi/eslint-config-melinda-backend": "^2.0.
|
|
56
|
-
"@natlibfi/fixugen-http-client": "^
|
|
48
|
+
"@babel/cli": "^7.18.10",
|
|
49
|
+
"@babel/core": "^7.18.13",
|
|
50
|
+
"@babel/eslint-parser": "^7.18.9",
|
|
51
|
+
"@babel/node": "^7.18.10",
|
|
52
|
+
"@babel/plugin-transform-runtime": "^7.18.10",
|
|
53
|
+
"@babel/preset-env": "^7.18.10",
|
|
54
|
+
"@babel/register": "^7.18.9",
|
|
55
|
+
"@natlibfi/eslint-config-melinda-backend": "^2.0.1",
|
|
56
|
+
"@natlibfi/fixugen-http-client": "^2.0.1",
|
|
57
57
|
"@natlibfi/fixura": "^2.2.1",
|
|
58
58
|
"babel-plugin-istanbul": "^6.1.1",
|
|
59
59
|
"babel-plugin-rewire": "^1.2.0",
|
|
60
60
|
"chai": "^4.3.6",
|
|
61
61
|
"cross-env": "^7.0.3",
|
|
62
|
-
"eslint": "^8.
|
|
62
|
+
"eslint": "^8.23.0",
|
|
63
63
|
"mocha": "^9.2.0",
|
|
64
|
-
"nodemon": "^2.0.
|
|
64
|
+
"nodemon": "^2.0.19",
|
|
65
65
|
"nyc": "^15.1.0"
|
|
66
66
|
},
|
|
67
67
|
"eslintConfig": {
|
|
@@ -30,10 +30,6 @@ import {expect} from 'chai';
|
|
|
30
30
|
import {createSubrecordPicker} from './subRecordPicker';
|
|
31
31
|
import {READERS} from '@natlibfi/fixura';
|
|
32
32
|
import generateTests from '@natlibfi/fixugen-http-client';
|
|
33
|
-
import {MarcRecord} from '@natlibfi/marc-record';
|
|
34
|
-
import createDebugLogger from 'debug';
|
|
35
|
-
|
|
36
|
-
const debug = createDebugLogger('@natlibfi/melinda-commons:subRecordPicker:test');
|
|
37
33
|
|
|
38
34
|
describe('subRecordPicker', () => {
|
|
39
35
|
const sruUrl = 'https://sru';
|
|
@@ -67,13 +63,6 @@ describe('subRecordPicker', () => {
|
|
|
67
63
|
const expectedRecords = getFixture({components: ['expected-records.json'], reader: READERS.JSON});
|
|
68
64
|
const {records} = await client[method](recordId);
|
|
69
65
|
|
|
70
|
-
// Expect records to be marc records
|
|
71
|
-
const [recordObject] = records;
|
|
72
|
-
debug(recordObject);
|
|
73
|
-
const record = new MarcRecord(recordObject);
|
|
74
|
-
debug(record);
|
|
75
|
-
|
|
76
|
-
expect(record).to.be.instanceof(MarcRecord);
|
|
77
66
|
expect(format()).to.eql(expectedRecords);
|
|
78
67
|
|
|
79
68
|
function format() {
|