@natlibfi/melinda-commons 12.0.3 → 12.0.4-alpha.3
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/README.md +1 -1
- package/dist/error.js +7 -36
- package/dist/error.js.map +1 -1
- package/dist/error.spec.js +4 -4
- package/dist/error.spec.js.map +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/subRecordPicker.js +61 -88
- package/dist/subRecordPicker.js.map +1 -1
- package/dist/subRecordPicker.spec.js +31 -54
- package/dist/subRecordPicker.spec.js.map +1 -1
- package/dist/utils.js +29 -45
- package/dist/utils.js.map +1 -1
- package/dist/utils.spec.js +57 -54
- package/dist/utils.spec.js.map +1 -1
- package/package.json +19 -19
- package/src/error.js +1 -1
- package/src/error.spec.js +1 -1
- package/src/index.js +1 -1
- package/src/subRecordPicker.js +28 -0
- package/src/subRecordPicker.spec.js +1 -1
- package/src/utils.js +2 -2
- package/src/utils.spec.js +6 -1
- package/.drone.yml +0 -93
|
@@ -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/README.md
CHANGED
|
@@ -5,6 +5,6 @@ Shared modules for Melinda's software
|
|
|
5
5
|
|
|
6
6
|
## License and copyright
|
|
7
7
|
|
|
8
|
-
Copyright (c) 2018-
|
|
8
|
+
Copyright (c) 2018-2022 **University Of Helsinki (The National Library Of Finland)**
|
|
9
9
|
|
|
10
10
|
This project's source code is licensed under the terms of **GNU Lesser General Public License Version 3** or any later version.
|
package/dist/error.js
CHANGED
|
@@ -1,35 +1,17 @@
|
|
|
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.
|
|
29
11
|
*
|
|
30
12
|
* Shared modules for Melinda's software
|
|
31
13
|
*
|
|
32
|
-
* Copyright (C) 2018-
|
|
14
|
+
* Copyright (C) 2018-2022 University Of Helsinki (The National Library Of Finland)
|
|
33
15
|
*
|
|
34
16
|
* This file is part of melinda-commons-js
|
|
35
17
|
*
|
|
@@ -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-2022 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
|
@@ -12,7 +12,7 @@ var _error = _interopRequireDefault(require("./error"));
|
|
|
12
12
|
*
|
|
13
13
|
* Shared modules for Melinda's software
|
|
14
14
|
*
|
|
15
|
-
* Copyright (C) 2018-
|
|
15
|
+
* Copyright (C) 2018-2022 University Of Helsinki (The National Library Of Finland)
|
|
16
16
|
*
|
|
17
17
|
* This file is part of melinda-commons-js
|
|
18
18
|
*
|
|
@@ -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-2022 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
|
});
|
|
@@ -48,7 +48,7 @@ var _error = _interopRequireDefault(require("./error"));
|
|
|
48
48
|
*
|
|
49
49
|
* Shared modules for Melinda's software
|
|
50
50
|
*
|
|
51
|
-
* Copyright (C) 2018-
|
|
51
|
+
* Copyright (C) 2018-2022 University Of Helsinki (The National Library Of Finland)
|
|
52
52
|
*
|
|
53
53
|
* This file is part of melinda-commons-js
|
|
54
54
|
*
|
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-2022 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");
|
|
@@ -19,119 +15,96 @@ var _debug = _interopRequireDefault(require("debug"));
|
|
|
19
15
|
|
|
20
16
|
var _error = require("./error");
|
|
21
17
|
|
|
18
|
+
/**
|
|
19
|
+
*
|
|
20
|
+
* @licstart The following is the entire license notice for the JavaScript code in this file.
|
|
21
|
+
*
|
|
22
|
+
* Shared modules for Melinda's software
|
|
23
|
+
*
|
|
24
|
+
* Copyright (C) 2018-2022 University Of Helsinki (The National Library Of Finland)
|
|
25
|
+
*
|
|
26
|
+
* This file is part of melinda-commons-js
|
|
27
|
+
*
|
|
28
|
+
* melinda-commons-js program is free software: you can redistribute it and/or modify
|
|
29
|
+
* it under the terms of the GNU Lesser General Public License as
|
|
30
|
+
* published by the Free Software Foundation, either version 3 of the
|
|
31
|
+
* License, or (at your option) any later version.
|
|
32
|
+
*
|
|
33
|
+
* melinda-commons-js is distributed in the hope that it will be useful,
|
|
34
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
35
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
36
|
+
* GNU Lesser General Public License for more details.
|
|
37
|
+
*
|
|
38
|
+
* You should have received a copy of the GNU Lesser General Public License
|
|
39
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
40
|
+
*
|
|
41
|
+
* @licend The above is the entire license notice
|
|
42
|
+
* for the JavaScript code in this file.
|
|
43
|
+
*
|
|
44
|
+
*/
|
|
22
45
|
function createSubrecordPicker(sruUrl) {
|
|
23
|
-
|
|
46
|
+
let retrieveAll = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
24
47
|
|
|
25
48
|
if (sruUrl === undefined) {
|
|
26
49
|
// eslint-disable-line functional/no-conditional-statement
|
|
27
50
|
throw new _error.Error(400, 'Invalid sru url');
|
|
28
51
|
}
|
|
29
52
|
|
|
30
|
-
|
|
53
|
+
const debug = (0, _debug.default)('@natlibfi/melinda-commons:subRecordPicker');
|
|
31
54
|
debug("SRU client url: ".concat(sruUrl));
|
|
32
|
-
|
|
55
|
+
const sruClient = (0, _sruClient.default)({
|
|
33
56
|
url: sruUrl,
|
|
34
57
|
recordSchema: 'marcxml',
|
|
35
|
-
retrieveAll
|
|
58
|
+
retrieveAll
|
|
36
59
|
});
|
|
37
60
|
return {
|
|
38
|
-
readSomeSubrecords
|
|
39
|
-
readAllSubrecords
|
|
61
|
+
readSomeSubrecords,
|
|
62
|
+
readAllSubrecords
|
|
40
63
|
};
|
|
41
64
|
|
|
42
65
|
function readSomeSubrecords(recordId) {
|
|
43
|
-
|
|
66
|
+
let offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
44
67
|
debug("Picking subrecords for ".concat(recordId));
|
|
45
|
-
return new Promise(
|
|
46
|
-
|
|
68
|
+
return new Promise((resolve, reject) => {
|
|
69
|
+
const promises = [];
|
|
47
70
|
sruClient.searchRetrieve("melinda.partsofhost=".concat(recordId), {
|
|
48
71
|
startRecord: offset
|
|
49
|
-
}).on('record',
|
|
72
|
+
}).on('record', xmlString => {
|
|
50
73
|
promises.push(_marcRecordSerializers.MARCXML.from(xmlString, {
|
|
51
74
|
subfieldValues: false
|
|
52
75
|
})); // 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
|
-
});
|
|
76
|
+
}).on('end', async nextRecordOffset => {
|
|
77
|
+
try {
|
|
78
|
+
const records = await Promise.all(promises);
|
|
79
|
+
resolve({
|
|
80
|
+
nextRecordOffset,
|
|
81
|
+
records
|
|
82
|
+
});
|
|
83
|
+
} catch (error) {
|
|
84
|
+
reject(error);
|
|
85
|
+
}
|
|
86
|
+
}).on('error', err => reject(err));
|
|
92
87
|
});
|
|
93
88
|
}
|
|
94
89
|
|
|
95
90
|
function readAllSubrecords(recordId) {
|
|
96
91
|
debug("Picking subrecords for ".concat(recordId));
|
|
97
|
-
return new Promise(
|
|
98
|
-
|
|
99
|
-
sruClient.searchRetrieve("melinda.partsofhost=".concat(recordId)).on('record',
|
|
92
|
+
return new Promise((resolve, reject) => {
|
|
93
|
+
const promises = [];
|
|
94
|
+
sruClient.searchRetrieve("melinda.partsofhost=".concat(recordId)).on('record', xmlString => {
|
|
100
95
|
promises.push(_marcRecordSerializers.MARCXML.from(xmlString, {
|
|
101
96
|
subfieldValues: false
|
|
102
97
|
})); // 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
|
-
});
|
|
98
|
+
}).on('end', async () => {
|
|
99
|
+
try {
|
|
100
|
+
const records = await Promise.all(promises);
|
|
101
|
+
resolve({
|
|
102
|
+
records
|
|
103
|
+
});
|
|
104
|
+
} catch (error) {
|
|
105
|
+
reject(error);
|
|
106
|
+
}
|
|
107
|
+
}).on('error', err => reject(err));
|
|
135
108
|
});
|
|
136
109
|
}
|
|
137
110
|
}
|
|
@@ -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":["/**\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-2022 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 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":";;;;;;;;;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;AAOO,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,kBAAA,EAAgB;IAACC,GAAG,EAAER,MAAN;IAAcS,YAAY,EAAE,SAA5B;IAAuCR;EAAvC,CAAhB,CAAlB;EAEA,OAAO;IAACS,kBAAD;IAAqBC;EAArB,CAAP;;EAEA,SAASD,kBAAT,CAA4BE,QAA5B,EAAkD;IAAA,IAAZC,MAAY,uEAAH,CAAG;IAChDT,KAAK,kCAA2BQ,QAA3B,EAAL;IACA,OAAO,IAAIE,OAAJ,CAAY,CAACC,OAAD,EAAUC,MAAV,KAAqB;MACtC,MAAMC,QAAQ,GAAG,EAAjB;MACAX,SAAS,CAACY,cAAV,+BAAgDN,QAAhD,GAA4D;QAACO,WAAW,EAAEN;MAAd,CAA5D,EACGO,EADH,CACM,QADN,EACgBC,SAAS,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,MAAMM,gBAAN,IAA0B;QACnC,IAAI;UACF,MAAMC,OAAO,GAAG,MAAMb,OAAO,CAACc,GAAR,CAAYX,QAAZ,CAAtB;UACAF,OAAO,CAAC;YAACW,gBAAD;YAAmBC;UAAnB,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;;EAED,SAASnB,iBAAT,CAA2BC,QAA3B,EAAqC;IACnCR,KAAK,kCAA2BQ,QAA3B,EAAL;IACA,OAAO,IAAIE,OAAJ,CAAY,CAACC,OAAD,EAAUC,MAAV,KAAqB;MACtC,MAAMC,QAAQ,GAAG,EAAjB;MACAX,SAAS,CAACY,cAAV,+BAAgDN,QAAhD,GACGQ,EADH,CACM,QADN,EACgBC,SAAS,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,10 +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 _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
8
|
-
|
|
9
5
|
var _chai = require("chai");
|
|
10
6
|
|
|
11
7
|
var _subRecordPicker = require("./subRecordPicker");
|
|
@@ -20,7 +16,7 @@ var _fixugenHttpClient = _interopRequireDefault(require("@natlibfi/fixugen-http-
|
|
|
20
16
|
*
|
|
21
17
|
* Shared modules for Melinda's software
|
|
22
18
|
*
|
|
23
|
-
* Copyright (C) 2018-
|
|
19
|
+
* Copyright (C) 2018-2022 University Of Helsinki (The National Library Of Finland)
|
|
24
20
|
*
|
|
25
21
|
* This file is part of melinda-commons-js
|
|
26
22
|
*
|
|
@@ -41,69 +37,50 @@ var _fixugenHttpClient = _interopRequireDefault(require("@natlibfi/fixugen-http-
|
|
|
41
37
|
* for the JavaScript code in this file.
|
|
42
38
|
*
|
|
43
39
|
*/
|
|
44
|
-
describe('subRecordPicker',
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
describe('createSubrecordPicker',
|
|
48
|
-
it('Client should have methods',
|
|
49
|
-
|
|
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);
|
|
50
46
|
(0, _chai.expect)(client).to.respondTo('readAllSubrecords');
|
|
51
47
|
(0, _chai.expect)(client).to.respondTo('readSomeSubrecords');
|
|
52
48
|
});
|
|
53
|
-
it('Create client should work with just one parametter',
|
|
54
|
-
|
|
49
|
+
it('Create client should work with just one parametter', () => {
|
|
50
|
+
const client = (0, _subRecordPicker.createSubrecordPicker)(sruUrl);
|
|
55
51
|
(0, _chai.expect)(client).to.respondTo('readAllSubrecords');
|
|
56
52
|
(0, _chai.expect)(client).to.respondTo('readSomeSubrecords');
|
|
57
53
|
});
|
|
58
|
-
it('Create client should have at least one parametter',
|
|
54
|
+
it('Create client should have at least one parametter', () => {
|
|
59
55
|
(0, _chai.expect)(_subRecordPicker.createSubrecordPicker).to.throw();
|
|
60
56
|
});
|
|
61
57
|
});
|
|
62
58
|
(0, _fixugenHttpClient.default)({
|
|
63
|
-
callback
|
|
59
|
+
callback,
|
|
64
60
|
path: [__dirname, '..', 'test-fixtures', 'subRecordPicker']
|
|
65
61
|
});
|
|
66
62
|
|
|
67
|
-
function callback(
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
getFixture = _ref.getFixture, method = _ref.method, sruUrl = _ref.sruUrl, retrieveAll = _ref.retrieveAll, recordId = _ref.recordId;
|
|
86
|
-
client = (0, _subRecordPicker.createSubrecordPicker)(sruUrl, retrieveAll);
|
|
87
|
-
expectedRecords = getFixture({
|
|
88
|
-
components: ['expected-records.json'],
|
|
89
|
-
reader: _fixura.READERS.JSON
|
|
90
|
-
});
|
|
91
|
-
_context.next = 6;
|
|
92
|
-
return client[method](recordId);
|
|
93
|
-
|
|
94
|
-
case 6:
|
|
95
|
-
_yield$client$method = _context.sent;
|
|
96
|
-
records = _yield$client$method.records;
|
|
97
|
-
(0, _chai.expect)(format()).to.eql(expectedRecords);
|
|
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);
|
|
98
80
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}, _callee);
|
|
105
|
-
}));
|
|
106
|
-
return _callback.apply(this, arguments);
|
|
81
|
+
function format() {
|
|
82
|
+
return records.map(r => r.toObject());
|
|
83
|
+
}
|
|
107
84
|
}
|
|
108
85
|
});
|
|
109
86
|
//# sourceMappingURL=subRecordPicker.spec.js.map
|