@natlibfi/melinda-record-matching 2.2.0-alpha.4 → 2.2.1-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 +10 -0
- package/.github/dependabot.yml +40 -0
- package/.github/workflows/melinda-node-tests.yml +70 -0
- package/package.json +1 -1
- package/dist/candidate-search/candidate-search-utils.js +0 -58
- package/dist/candidate-search/candidate-search-utils.js.map +0 -1
- package/dist/candidate-search/index.js +0 -273
- package/dist/candidate-search/index.js.map +0 -1
- package/dist/candidate-search/index.spec.js +0 -161
- package/dist/candidate-search/index.spec.js.map +0 -1
- package/dist/candidate-search/query-list/bib.js +0 -252
- package/dist/candidate-search/query-list/bib.js.map +0 -1
- package/dist/candidate-search/query-list/bib.spec.js +0 -72
- package/dist/candidate-search/query-list/bib.spec.js.map +0 -1
- package/dist/candidate-search/query-list/index.js +0 -67
- package/dist/candidate-search/query-list/index.js.map +0 -1
- package/dist/index.js +0 -578
- package/dist/index.js.map +0 -1
- package/dist/index.spec.js +0 -133
- package/dist/index.spec.js.map +0 -1
- package/dist/match-detection/features/bib/all-source-ids.js +0 -122
- package/dist/match-detection/features/bib/all-source-ids.js.map +0 -1
- package/dist/match-detection/features/bib/authors.js +0 -117
- package/dist/match-detection/features/bib/authors.js.map +0 -1
- package/dist/match-detection/features/bib/bibliographic-level.js +0 -42
- package/dist/match-detection/features/bib/bibliographic-level.js.map +0 -1
- package/dist/match-detection/features/bib/host-component.js +0 -42
- package/dist/match-detection/features/bib/host-component.js.map +0 -1
- package/dist/match-detection/features/bib/index.js +0 -104
- package/dist/match-detection/features/bib/index.js.map +0 -1
- package/dist/match-detection/features/bib/index.spec.js +0 -97
- package/dist/match-detection/features/bib/index.spec.js.map +0 -1
- package/dist/match-detection/features/bib/isbn.js +0 -55
- package/dist/match-detection/features/bib/isbn.js.map +0 -1
- package/dist/match-detection/features/bib/issn.js +0 -55
- package/dist/match-detection/features/bib/issn.js.map +0 -1
- package/dist/match-detection/features/bib/language.js +0 -113
- package/dist/match-detection/features/bib/language.js.map +0 -1
- package/dist/match-detection/features/bib/melinda-id.js +0 -52
- package/dist/match-detection/features/bib/melinda-id.js.map +0 -1
- package/dist/match-detection/features/bib/melinda-identifier-factory.js +0 -100
- package/dist/match-detection/features/bib/melinda-identifier-factory.js.map +0 -1
- package/dist/match-detection/features/bib/other-standard-identifier.js +0 -55
- package/dist/match-detection/features/bib/other-standard-identifier.js.map +0 -1
- package/dist/match-detection/features/bib/publication-time.js +0 -47
- package/dist/match-detection/features/bib/publication-time.js.map +0 -1
- package/dist/match-detection/features/bib/record-type.js +0 -42
- package/dist/match-detection/features/bib/record-type.js.map +0 -1
- package/dist/match-detection/features/bib/standard-identifier-factory.js +0 -126
- package/dist/match-detection/features/bib/standard-identifier-factory.js.map +0 -1
- package/dist/match-detection/features/bib/title.js +0 -91
- package/dist/match-detection/features/bib/title.js.map +0 -1
- package/dist/match-detection/features/index.js +0 -15
- package/dist/match-detection/features/index.js.map +0 -1
- package/dist/match-detection/index.js +0 -184
- package/dist/match-detection/index.js.map +0 -1
- package/dist/match-detection/index.spec.js +0 -99
- package/dist/match-detection/index.spec.js.map +0 -1
- package/dist/matching-utils.js +0 -95
- package/dist/matching-utils.js.map +0 -1
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
|
|
7
|
+
# With this line @NatLibFi/melinda-js-lead owns any files in the /src/
|
|
8
|
+
# directory at the root of the repository and any of its
|
|
9
|
+
# subdirectories.
|
|
10
|
+
/src/ @NatLibFi/melinda-js-lead
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
# Minor updates to npm production dependencies daily
|
|
15
|
+
- package-ecosystem: "npm"
|
|
16
|
+
directory: "/"
|
|
17
|
+
schedule:
|
|
18
|
+
interval: "daily"
|
|
19
|
+
time: "06:45"
|
|
20
|
+
timezone: "Europe/Helsinki"
|
|
21
|
+
versioning-strategy: lockfile-only
|
|
22
|
+
labels:
|
|
23
|
+
- "npm minor dependencies"
|
|
24
|
+
allow:
|
|
25
|
+
- dependency-type: "production"
|
|
26
|
+
|
|
27
|
+
# Major updates to npm dependencies weekly @tuesday
|
|
28
|
+
# Not possible yet https://github.com/dependabot/dependabot-core/issues/1778
|
|
29
|
+
# - package-ecosystem: "npm"
|
|
30
|
+
# directory: "/"
|
|
31
|
+
# schedule:
|
|
32
|
+
# interval: "weekly"
|
|
33
|
+
# day: "tuesday"
|
|
34
|
+
# time: "07:00"
|
|
35
|
+
# timezone: "Europe/Helsinki"
|
|
36
|
+
# versioning-strategy: increase-if-necessary
|
|
37
|
+
# labels:
|
|
38
|
+
# - "npm major dependencies"
|
|
39
|
+
# reviewers:
|
|
40
|
+
# - "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@v2
|
|
20
|
+
- name: Use Node.js ${{ matrix.node-version }}
|
|
21
|
+
uses: actions/setup-node@v3
|
|
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=high
|
|
28
|
+
- run: npm ci
|
|
29
|
+
- run: npm test
|
|
30
|
+
- run: npm run build --if-present
|
|
31
|
+
|
|
32
|
+
njsscan:
|
|
33
|
+
name: Njsscan check
|
|
34
|
+
runs-on: ubuntu-latest
|
|
35
|
+
|
|
36
|
+
steps:
|
|
37
|
+
- name: Checkout the code
|
|
38
|
+
uses: actions/checkout@v3
|
|
39
|
+
- name: nodejsscan scan
|
|
40
|
+
id: njsscan
|
|
41
|
+
uses: ajinabraham/njsscan-action@master
|
|
42
|
+
with:
|
|
43
|
+
args: '.'
|
|
44
|
+
|
|
45
|
+
license-scan:
|
|
46
|
+
name: License compliance check
|
|
47
|
+
runs-on: ubuntu-latest
|
|
48
|
+
|
|
49
|
+
steps:
|
|
50
|
+
- uses: actions/checkout@v3
|
|
51
|
+
- uses: mikaelvesavuori/license-compliance-action@v1.0.2
|
|
52
|
+
with:
|
|
53
|
+
exclude_pattern: /^@natlibfi/
|
|
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@v2
|
|
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_RECORD_MATCHING_NPM_TOKEN }}
|
package/package.json
CHANGED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.toQueries = toQueries;
|
|
7
|
-
|
|
8
|
-
var _debug = _interopRequireDefault(require("debug"));
|
|
9
|
-
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
*
|
|
14
|
-
* @licstart The following is the entire license notice for the JavaScript code in this file.
|
|
15
|
-
*
|
|
16
|
-
* Melinda record matching modules for Javascript
|
|
17
|
-
*
|
|
18
|
-
* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
|
|
19
|
-
*
|
|
20
|
-
* This file is part of melinda-record-matching-js
|
|
21
|
-
*
|
|
22
|
-
* melinda-record-matching-js program is free software: you can redistribute it and/or modify
|
|
23
|
-
* it under the terms of the GNU Lesser General Public License as
|
|
24
|
-
* published by the Free Software Foundation, either version 3 of the
|
|
25
|
-
* License, or (at your option) any later version.
|
|
26
|
-
*
|
|
27
|
-
* melinda-record-matching-js is distributed in the hope that it will be useful,
|
|
28
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
29
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
30
|
-
* GNU Lesser General Public License for more details.
|
|
31
|
-
*
|
|
32
|
-
* You should have received a copy of the GNU Affero General Public License
|
|
33
|
-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
34
|
-
*
|
|
35
|
-
* @licend The above is the entire license notice
|
|
36
|
-
* for the JavaScript code in this file.
|
|
37
|
-
*
|
|
38
|
-
*/
|
|
39
|
-
function toQueries(identifiers, queryString) {
|
|
40
|
-
const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:toQueries');
|
|
41
|
-
const debugData = debug.extend('data');
|
|
42
|
-
const quotedIdentifiers = identifiers.map(identifier => identifier.match(/\//u) ? `"${identifier}"` : `${identifier}`); // Aleph supports only two queries with or -operator (This is not actually true)
|
|
43
|
-
|
|
44
|
-
const pairs = toPairs(quotedIdentifiers);
|
|
45
|
-
const queries = pairs.map(([a, b]) => b ? `${queryString}=${a} or ${queryString}=${b}` : `${queryString}=${a}`);
|
|
46
|
-
debugData(`Pairs (${pairs.length}): ${JSON.stringify(pairs)}`);
|
|
47
|
-
debugData(`Queries (${queries.length}): ${JSON.stringify(queries)}`);
|
|
48
|
-
return queries;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function toPairs(array) {
|
|
52
|
-
if (array.length === 0) {
|
|
53
|
-
return [];
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return [array.slice(0, 2)].concat(toPairs(array.slice(2), 2));
|
|
57
|
-
}
|
|
58
|
-
//# sourceMappingURL=candidate-search-utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"candidate-search-utils.js","names":["toQueries","identifiers","queryString","debug","createDebugLogger","debugData","extend","quotedIdentifiers","map","identifier","match","pairs","toPairs","queries","a","b","length","JSON","stringify","array","slice","concat"],"sources":["../../src/candidate-search/candidate-search-utils.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Melinda record matching modules for Javascript\n*\n* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-record-matching-js\n*\n* melinda-record-matching-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-record-matching-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 Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\nimport createDebugLogger from 'debug';\n\nexport function toQueries(identifiers, queryString) {\n\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:toQueries');\n const debugData = debug.extend('data');\n\n const quotedIdentifiers = identifiers.map(identifier => identifier.match(/\\//u) ? `\"${identifier}\"` : `${identifier}`);\n\n // Aleph supports only two queries with or -operator (This is not actually true)\n const pairs = toPairs(quotedIdentifiers);\n const queries = pairs.map(([a, b]) => b ? `${queryString}=${a} or ${queryString}=${b}` : `${queryString}=${a}`);\n\n debugData(`Pairs (${pairs.length}): ${JSON.stringify(pairs)}`);\n debugData(`Queries (${queries.length}): ${JSON.stringify(queries)}`);\n\n return queries;\n}\n\nfunction toPairs(array) {\n if (array.length === 0) {\n return [];\n }\n return [array.slice(0, 2)].concat(toPairs(array.slice(2), 2));\n}\n"],"mappings":";;;;;;;AA4BA;;;;AA5BA;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;AAIO,SAASA,SAAT,CAAmBC,WAAnB,EAAgCC,WAAhC,EAA6C;EAElD,MAAMC,KAAK,GAAG,IAAAC,cAAA,EAAkB,6CAAlB,CAAd;EACA,MAAMC,SAAS,GAAGF,KAAK,CAACG,MAAN,CAAa,MAAb,CAAlB;EAEA,MAAMC,iBAAiB,GAAGN,WAAW,CAACO,GAAZ,CAAgBC,UAAU,IAAIA,UAAU,CAACC,KAAX,CAAiB,KAAjB,IAA2B,IAAGD,UAAW,GAAzC,GAA+C,GAAEA,UAAW,EAA1F,CAA1B,CALkD,CAOlD;;EACA,MAAME,KAAK,GAAGC,OAAO,CAACL,iBAAD,CAArB;EACA,MAAMM,OAAO,GAAGF,KAAK,CAACH,GAAN,CAAU,CAAC,CAACM,CAAD,EAAIC,CAAJ,CAAD,KAAYA,CAAC,GAAI,GAAEb,WAAY,IAAGY,CAAE,OAAMZ,WAAY,IAAGa,CAAE,EAA9C,GAAmD,GAAEb,WAAY,IAAGY,CAAE,EAA7F,CAAhB;EAEAT,SAAS,CAAE,UAASM,KAAK,CAACK,MAAO,MAAKC,IAAI,CAACC,SAAL,CAAeP,KAAf,CAAsB,EAAnD,CAAT;EACAN,SAAS,CAAE,YAAWQ,OAAO,CAACG,MAAO,MAAKC,IAAI,CAACC,SAAL,CAAeL,OAAf,CAAwB,EAAzD,CAAT;EAEA,OAAOA,OAAP;AACD;;AAED,SAASD,OAAT,CAAiBO,KAAjB,EAAwB;EACtB,IAAIA,KAAK,CAACH,MAAN,KAAiB,CAArB,EAAwB;IACtB,OAAO,EAAP;EACD;;EACD,OAAO,CAACG,KAAK,CAACC,KAAN,CAAY,CAAZ,EAAe,CAAf,CAAD,EAAoBC,MAApB,CAA2BT,OAAO,CAACO,KAAK,CAACC,KAAN,CAAY,CAAZ,CAAD,EAAiB,CAAjB,CAAlC,CAAP;AACD"}
|
|
@@ -1,273 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = exports.CandidateSearchError = void 0;
|
|
7
|
-
Object.defineProperty(exports, "searchTypes", {
|
|
8
|
-
enumerable: true,
|
|
9
|
-
get: function () {
|
|
10
|
-
return _queryList.searchTypes;
|
|
11
|
-
}
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
var _debug = _interopRequireDefault(require("debug"));
|
|
15
|
-
|
|
16
|
-
var _sruClient = _interopRequireWildcard(require("@natlibfi/sru-client"));
|
|
17
|
-
|
|
18
|
-
var _marcRecord = require("@natlibfi/marc-record");
|
|
19
|
-
|
|
20
|
-
var _marcRecordSerializers = require("@natlibfi/marc-record-serializers");
|
|
21
|
-
|
|
22
|
-
var _queryList = _interopRequireWildcard(require("./query-list"));
|
|
23
|
-
|
|
24
|
-
var _melindaCommons = require("@natlibfi/melinda-commons");
|
|
25
|
-
|
|
26
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
27
|
-
|
|
28
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
29
|
-
|
|
30
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
*
|
|
34
|
-
* @licstart The following is the entire license notice for the JavaScript code in this file.
|
|
35
|
-
*
|
|
36
|
-
* Melinda record matching modules for Javascript
|
|
37
|
-
*
|
|
38
|
-
* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
|
|
39
|
-
*
|
|
40
|
-
* This file is part of melinda-record-matching-js
|
|
41
|
-
*
|
|
42
|
-
* melinda-record-matching-js program is free software: you can redistribute it and/or modify
|
|
43
|
-
* it under the terms of the GNU Lesser General Public License as
|
|
44
|
-
* published by the Free Software Foundation, either version 3 of the
|
|
45
|
-
* License, or (at your option) any later version.
|
|
46
|
-
*
|
|
47
|
-
* melinda-record-matching-js is distributed in the hope that it will be useful,
|
|
48
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
49
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
50
|
-
* GNU Lesser General Public License for more details.
|
|
51
|
-
*
|
|
52
|
-
* You should have received a copy of the GNU Affero General Public License
|
|
53
|
-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
54
|
-
*
|
|
55
|
-
* @licend The above is the entire license notice
|
|
56
|
-
* for the JavaScript code in this file.
|
|
57
|
-
*
|
|
58
|
-
*/
|
|
59
|
-
class CandidateSearchError extends Error {} // serverMaxResults : maximum size of total search result available from the server, defaults to Aleph's 20000
|
|
60
|
-
// eslint-disable-next-line max-statements
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
exports.CandidateSearchError = CandidateSearchError;
|
|
64
|
-
|
|
65
|
-
var _default = ({
|
|
66
|
-
record,
|
|
67
|
-
searchSpec,
|
|
68
|
-
url,
|
|
69
|
-
maxCandidates,
|
|
70
|
-
maxRecordsPerRequest = 50,
|
|
71
|
-
serverMaxResult = 20000
|
|
72
|
-
}) => {
|
|
73
|
-
_marcRecord.MarcRecord.setValidationOptions({
|
|
74
|
-
subfieldValues: false
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:candidate-search');
|
|
78
|
-
const debugData = debug.extend('data');
|
|
79
|
-
debugData(`SearchSpec: ${JSON.stringify(searchSpec)}`);
|
|
80
|
-
debugData(`Url: ${url}`);
|
|
81
|
-
debugData(`MaxRecordsPerRequest ${maxRecordsPerRequest}`);
|
|
82
|
-
debugData(`ServerMaxResult: ${serverMaxResult}`);
|
|
83
|
-
debugData(`MaxCandidates: ${maxCandidates}`); // Do not retrieve more candidates than defined in maxCandidates
|
|
84
|
-
|
|
85
|
-
const adjustedMaxRecordsPerRequest = maxRecordsPerRequest >= maxCandidates ? maxCandidates : maxRecordsPerRequest;
|
|
86
|
-
const inputRecordId = getRecordId(record);
|
|
87
|
-
const queryList = (0, _queryList.default)(record, searchSpec);
|
|
88
|
-
const client = (0, _sruClient.default)({
|
|
89
|
-
url,
|
|
90
|
-
maxRecordsPerRequest: adjustedMaxRecordsPerRequest,
|
|
91
|
-
version: '2.0',
|
|
92
|
-
retrieveAll: false
|
|
93
|
-
});
|
|
94
|
-
debug(`Searching matches for ${inputRecordId}`);
|
|
95
|
-
debug(`Generated queryList ${JSON.stringify(queryList)}`); // if generateQueryList errored we should throw 422
|
|
96
|
-
|
|
97
|
-
if (queryList.length === 0) {
|
|
98
|
-
// eslint-disable-line functional/no-conditional-statement
|
|
99
|
-
throw new CandidateSearchError(`Generated query list contains no queries`);
|
|
100
|
-
} // state.totalRecords : amount of candidate records available to the current query (undefined, if there was no queries left)
|
|
101
|
-
// state.query : current query (undefined if there was no queries left)
|
|
102
|
-
// state.searchCounter : sequence for current search for current query (undefined, if there we no queries left)
|
|
103
|
-
// state.queryCandidateCounter: amount of candidates (records+failures) retrieved from SRU for matching for current query, including the current record+failure set (undefined if there were no queries left)
|
|
104
|
-
// state.queriesLeft : amount of queries left
|
|
105
|
-
// state.queryCounter : sequence for current query
|
|
106
|
-
// state.maxedQueries : queries that resulted in more than serverMaxResults hits
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
return async ({
|
|
110
|
-
queryOffset = 0,
|
|
111
|
-
resultSetOffset = 1,
|
|
112
|
-
totalRecords = 0,
|
|
113
|
-
searchCounter = 0,
|
|
114
|
-
queryCandidateCounter = 0,
|
|
115
|
-
queryCounter = 0,
|
|
116
|
-
maxedQueries = []
|
|
117
|
-
}) => {
|
|
118
|
-
const query = queryList[queryOffset];
|
|
119
|
-
|
|
120
|
-
if (query) {
|
|
121
|
-
const {
|
|
122
|
-
records,
|
|
123
|
-
failures,
|
|
124
|
-
nextOffset,
|
|
125
|
-
total
|
|
126
|
-
} = await retrieveRecords(); // If resultSetOffset === 1 this is the first search for the current query
|
|
127
|
-
|
|
128
|
-
debugData(`ResultSetOffset: ${resultSetOffset}`);
|
|
129
|
-
const newTotalRecords = resultSetOffset === 1 ? total : totalRecords;
|
|
130
|
-
const newQueryCounter = resultSetOffset === 1 ? queryCounter + 1 : queryCounter;
|
|
131
|
-
const newSearchCounter = resultSetOffset === 1 ? 1 : searchCounter + 1;
|
|
132
|
-
const newQueryCandidateCounter = resultSetOffset === 1 ? records.length + failures.length : queryCandidateCounter + records.length + failures.length;
|
|
133
|
-
const maxedQuery = resultSetOffset === 1 ? checkMaxedQuery(query, total, serverMaxResult) : undefined;
|
|
134
|
-
const newMaxedQueries = maxedQuery ? maxedQueries.concat(maxedQuery) : maxedQueries;
|
|
135
|
-
|
|
136
|
-
if (typeof nextOffset === 'number') {
|
|
137
|
-
debug(`Next search will be for query ${queryOffset} ${query}, starting from record ${nextOffset}`);
|
|
138
|
-
return {
|
|
139
|
-
records,
|
|
140
|
-
failures,
|
|
141
|
-
queryOffset,
|
|
142
|
-
resultSetOffset: nextOffset,
|
|
143
|
-
queriesLeft: queryList.length - (queryOffset + 1),
|
|
144
|
-
totalRecords: newTotalRecords,
|
|
145
|
-
query,
|
|
146
|
-
searchCounter: newSearchCounter,
|
|
147
|
-
queryCandidateCounter: newQueryCandidateCounter,
|
|
148
|
-
queryCounter: newQueryCounter,
|
|
149
|
-
maxedQueries: newMaxedQueries
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
debug(`Query ${queryOffset} ${query} done.`);
|
|
154
|
-
debug(`There are (${queryList.length - (queryOffset + 1)} queries left)`);
|
|
155
|
-
return {
|
|
156
|
-
records,
|
|
157
|
-
failures,
|
|
158
|
-
queryOffset: queryOffset + 1,
|
|
159
|
-
queriesLeft: queryList.length - (queryOffset + 1),
|
|
160
|
-
totalRecords: newTotalRecords,
|
|
161
|
-
query,
|
|
162
|
-
searchCounter: newSearchCounter,
|
|
163
|
-
queryCandidateCounter: newQueryCandidateCounter,
|
|
164
|
-
queryCounter: newQueryCounter,
|
|
165
|
-
maxedQueries: newMaxedQueries
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
debug(`All ${queryList.length} queries done, there's no query for ${queryOffset}`);
|
|
170
|
-
return {
|
|
171
|
-
records: [],
|
|
172
|
-
failures: [],
|
|
173
|
-
queriesLeft: 0,
|
|
174
|
-
queryCounter,
|
|
175
|
-
maxedQueries
|
|
176
|
-
};
|
|
177
|
-
|
|
178
|
-
function retrieveRecords() {
|
|
179
|
-
return new Promise((resolve, reject) => {
|
|
180
|
-
const promises = []; // eslint-disable-next-line functional/no-let
|
|
181
|
-
|
|
182
|
-
let totalRecords = 0;
|
|
183
|
-
debug(`Searching for candidates with query: ${query} (Offset ${resultSetOffset})`);
|
|
184
|
-
client.searchRetrieve(query, {
|
|
185
|
-
startRecord: resultSetOffset
|
|
186
|
-
}).on('error', err => {
|
|
187
|
-
// eslint-disable-next-line functional/no-conditional-statement
|
|
188
|
-
if (err instanceof _sruClient.SruSearchError) {
|
|
189
|
-
debug(`SRU SruSearchError for query: ${query}: ${err}`);
|
|
190
|
-
reject(new CandidateSearchError(`SRU SruSearchError for query: ${query}: ${err}`));
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
debug(`SRU error for query: ${query}: ${err}`);
|
|
194
|
-
reject(new CandidateSearchError(`SRU error for query: ${query}: ${err}`));
|
|
195
|
-
}).on('total', total => {
|
|
196
|
-
debug(`Got total: ${total}`);
|
|
197
|
-
totalRecords += total;
|
|
198
|
-
}).on('end', async nextOffset => {
|
|
199
|
-
try {
|
|
200
|
-
const recordPromises = await Promise.allSettled(promises);
|
|
201
|
-
debug(`All recordPromises: ${JSON.stringify(recordPromises)}`);
|
|
202
|
-
const filtered = recordPromises.filter(r => r.status === 'fulfilled').map(r => r.value);
|
|
203
|
-
const failures = recordPromises.filter(r => r.status === 'rejected').map(r => ({
|
|
204
|
-
status: r.reason.status,
|
|
205
|
-
payload: r.reason.payload
|
|
206
|
-
}));
|
|
207
|
-
debug(`Found ${JSON.stringify(recordPromises)} records`);
|
|
208
|
-
debug(`Found ${filtered.length} convertable candidates`);
|
|
209
|
-
debug(`Found ${failures.length} NON-convertable candidates`);
|
|
210
|
-
debug(`Converted: ${JSON.stringify(filtered)}.`);
|
|
211
|
-
debug(`Not converted: ${JSON.stringify(failures)}.`);
|
|
212
|
-
resolve({
|
|
213
|
-
nextOffset,
|
|
214
|
-
records: filtered,
|
|
215
|
-
failures,
|
|
216
|
-
total: totalRecords
|
|
217
|
-
});
|
|
218
|
-
} catch (err) {
|
|
219
|
-
debug(`Error caught on END`);
|
|
220
|
-
reject(err);
|
|
221
|
-
}
|
|
222
|
-
}).on('record', recordXML => {
|
|
223
|
-
promises.push(handleRecord()); // eslint-disable-line functional/immutable-data
|
|
224
|
-
|
|
225
|
-
async function handleRecord() {
|
|
226
|
-
try {
|
|
227
|
-
const recordMarc = await _marcRecordSerializers.MARCXML.from(recordXML, {
|
|
228
|
-
subfieldValues: false
|
|
229
|
-
});
|
|
230
|
-
const recordId = getRecordId(recordMarc);
|
|
231
|
-
return {
|
|
232
|
-
record: recordMarc,
|
|
233
|
-
id: recordId
|
|
234
|
-
};
|
|
235
|
-
} catch (err) {
|
|
236
|
-
// What should this do?
|
|
237
|
-
const idFromXML = getRecordIdFromXML(recordXML);
|
|
238
|
-
debugData(`Failed converting record: ${err.message}, id: ${idFromXML}, data: ${recordXML}`); //return {message: `Failed converting record: ${err.message}`, id: idFromXML, data: recordXML};
|
|
239
|
-
|
|
240
|
-
throw new _melindaCommons.Error(422, {
|
|
241
|
-
message: `Failed converting record: ${err.message}`,
|
|
242
|
-
id: idFromXML || '000000000',
|
|
243
|
-
data: recordXML
|
|
244
|
-
});
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
});
|
|
248
|
-
});
|
|
249
|
-
}
|
|
250
|
-
};
|
|
251
|
-
|
|
252
|
-
function checkMaxedQuery(query, total, serverMaxResult) {
|
|
253
|
-
// eslint-disable-next-line functional/no-conditional-statement
|
|
254
|
-
if (total >= serverMaxResult) {
|
|
255
|
-
debug(`WARNING: Query ${query} resulted in ${total} hits which meets the serverMaxResult (${serverMaxResult}) `);
|
|
256
|
-
return query;
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
function getRecordId(record) {
|
|
261
|
-
const [field] = record.get(/^001$/u);
|
|
262
|
-
return field ? field.value : '';
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
function getRecordIdFromXML(recordXML) {
|
|
266
|
-
//<controlfield tag=\"001\">015376846</controlfield
|
|
267
|
-
debug(`Cannot yet find possible database record id from recordXML (length ${recordXML.length})`);
|
|
268
|
-
return undefined;
|
|
269
|
-
}
|
|
270
|
-
};
|
|
271
|
-
|
|
272
|
-
exports.default = _default;
|
|
273
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["CandidateSearchError","Error","record","searchSpec","url","maxCandidates","maxRecordsPerRequest","serverMaxResult","MarcRecord","setValidationOptions","subfieldValues","debug","createDebugLogger","debugData","extend","JSON","stringify","adjustedMaxRecordsPerRequest","inputRecordId","getRecordId","queryList","generateQueryList","client","createClient","version","retrieveAll","length","queryOffset","resultSetOffset","totalRecords","searchCounter","queryCandidateCounter","queryCounter","maxedQueries","query","records","failures","nextOffset","total","retrieveRecords","newTotalRecords","newQueryCounter","newSearchCounter","newQueryCandidateCounter","maxedQuery","checkMaxedQuery","undefined","newMaxedQueries","concat","queriesLeft","Promise","resolve","reject","promises","searchRetrieve","startRecord","on","err","SruSearchError","recordPromises","allSettled","filtered","filter","r","status","map","value","reason","payload","recordXML","push","handleRecord","recordMarc","MARCXML","from","recordId","id","idFromXML","getRecordIdFromXML","message","MatchingError","data","field","get"],"sources":["../../src/candidate-search/index.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Melinda record matching modules for Javascript\n*\n* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-record-matching-js\n*\n* melinda-record-matching-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-record-matching-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 Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\nimport createDebugLogger from 'debug';\nimport createClient, {SruSearchError} from '@natlibfi/sru-client';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport {MARCXML} from '@natlibfi/marc-record-serializers';\nimport generateQueryList from './query-list';\nimport {Error as MatchingError} from '@natlibfi/melinda-commons';\n\nexport {searchTypes} from './query-list';\n\nexport class CandidateSearchError extends Error {}\n\n// serverMaxResults : maximum size of total search result available from the server, defaults to Aleph's 20000\n\n// eslint-disable-next-line max-statements\nexport default ({record, searchSpec, url, maxCandidates, maxRecordsPerRequest = 50, serverMaxResult = 20000}) => {\n MarcRecord.setValidationOptions({subfieldValues: false});\n\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search');\n const debugData = debug.extend('data');\n\n debugData(`SearchSpec: ${JSON.stringify(searchSpec)}`);\n debugData(`Url: ${url}`);\n debugData(`MaxRecordsPerRequest ${maxRecordsPerRequest}`);\n debugData(`ServerMaxResult: ${serverMaxResult}`);\n debugData(`MaxCandidates: ${maxCandidates}`);\n\n // Do not retrieve more candidates than defined in maxCandidates\n const adjustedMaxRecordsPerRequest = maxRecordsPerRequest >= maxCandidates ? maxCandidates : maxRecordsPerRequest;\n\n const inputRecordId = getRecordId(record);\n const queryList = generateQueryList(record, searchSpec);\n const client = createClient({\n url,\n maxRecordsPerRequest: adjustedMaxRecordsPerRequest,\n version: '2.0',\n retrieveAll: false\n });\n\n debug(`Searching matches for ${inputRecordId}`);\n debug(`Generated queryList ${JSON.stringify(queryList)}`);\n\n // if generateQueryList errored we should throw 422\n\n if (queryList.length === 0) { // eslint-disable-line functional/no-conditional-statement\n throw new CandidateSearchError(`Generated query list contains no queries`);\n }\n\n // state.totalRecords : amount of candidate records available to the current query (undefined, if there was no queries left)\n // state.query : current query (undefined if there was no queries left)\n // state.searchCounter : sequence for current search for current query (undefined, if there we no queries left)\n // state.queryCandidateCounter: amount of candidates (records+failures) retrieved from SRU for matching for current query, including the current record+failure set (undefined if there were no queries left)\n // state.queriesLeft : amount of queries left\n // state.queryCounter : sequence for current query\n // state.maxedQueries : queries that resulted in more than serverMaxResults hits\n\n\n return async ({queryOffset = 0, resultSetOffset = 1, totalRecords = 0, searchCounter = 0, queryCandidateCounter = 0, queryCounter = 0, maxedQueries = []}) => {\n const query = queryList[queryOffset];\n\n if (query) {\n const {records, failures, nextOffset, total} = await retrieveRecords();\n\n // If resultSetOffset === 1 this is the first search for the current query\n debugData(`ResultSetOffset: ${resultSetOffset}`);\n const newTotalRecords = resultSetOffset === 1 ? total : totalRecords;\n const newQueryCounter = resultSetOffset === 1 ? queryCounter + 1 : queryCounter;\n const newSearchCounter = resultSetOffset === 1 ? 1 : searchCounter + 1;\n const newQueryCandidateCounter = resultSetOffset === 1 ? records.length + failures.length : queryCandidateCounter + records.length + failures.length;\n\n const maxedQuery = resultSetOffset === 1 ? checkMaxedQuery(query, total, serverMaxResult) : undefined;\n const newMaxedQueries = maxedQuery ? maxedQueries.concat(maxedQuery) : maxedQueries;\n\n if (typeof nextOffset === 'number') {\n debug(`Next search will be for query ${queryOffset} ${query}, starting from record ${nextOffset}`);\n return {records, failures, queryOffset, resultSetOffset: nextOffset, queriesLeft: queryList.length - (queryOffset + 1), totalRecords: newTotalRecords, query, searchCounter: newSearchCounter, queryCandidateCounter: newQueryCandidateCounter, queryCounter: newQueryCounter, maxedQueries: newMaxedQueries};\n }\n debug(`Query ${queryOffset} ${query} done.`);\n debug(`There are (${queryList.length - (queryOffset + 1)} queries left)`);\n return {records, failures, queryOffset: queryOffset + 1, queriesLeft: queryList.length - (queryOffset + 1), totalRecords: newTotalRecords, query, searchCounter: newSearchCounter, queryCandidateCounter: newQueryCandidateCounter, queryCounter: newQueryCounter, maxedQueries: newMaxedQueries};\n }\n\n debug(`All ${queryList.length} queries done, there's no query for ${queryOffset}`);\n return {records: [], failures: [], queriesLeft: 0, queryCounter, maxedQueries};\n\n function retrieveRecords() {\n return new Promise((resolve, reject) => {\n const promises = [];\n // eslint-disable-next-line functional/no-let\n let totalRecords = 0;\n\n debug(`Searching for candidates with query: ${query} (Offset ${resultSetOffset})`);\n\n client.searchRetrieve(query, {startRecord: resultSetOffset})\n .on('error', err => {\n // eslint-disable-next-line functional/no-conditional-statement\n if (err instanceof SruSearchError) {\n debug(`SRU SruSearchError for query: ${query}: ${err}`);\n reject(new CandidateSearchError(`SRU SruSearchError for query: ${query}: ${err}`));\n }\n debug(`SRU error for query: ${query}: ${err}`);\n reject(new CandidateSearchError(`SRU error for query: ${query}: ${err}`));\n })\n .on('total', total => {\n debug(`Got total: ${total}`);\n totalRecords += total;\n })\n .on('end', async nextOffset => {\n try {\n const recordPromises = await Promise.allSettled(promises);\n debug(`All recordPromises: ${JSON.stringify(recordPromises)}`);\n const filtered = recordPromises.filter(r => r.status === 'fulfilled').map(r => r.value);\n const failures = recordPromises.filter(r => r.status === 'rejected').map(r => ({status: r.reason.status, payload: r.reason.payload}));\n\n debug(`Found ${JSON.stringify(recordPromises)} records`);\n debug(`Found ${filtered.length} convertable candidates`);\n debug(`Found ${failures.length} NON-convertable candidates`);\n debug(`Converted: ${JSON.stringify(filtered)}.`);\n debug(`Not converted: ${JSON.stringify(failures)}.`);\n\n\n resolve({nextOffset, records: filtered, failures, total: totalRecords});\n } catch (err) {\n debug(`Error caught on END`);\n reject(err);\n }\n })\n .on('record', recordXML => {\n promises.push(handleRecord()); // eslint-disable-line functional/immutable-data\n\n async function handleRecord() {\n try {\n const recordMarc = await MARCXML.from(recordXML, {subfieldValues: false});\n const recordId = getRecordId(recordMarc);\n\n return {record: recordMarc, id: recordId};\n } catch (err) {\n // What should this do?\n const idFromXML = getRecordIdFromXML(recordXML);\n debugData(`Failed converting record: ${err.message}, id: ${idFromXML}, data: ${recordXML}`);\n //return {message: `Failed converting record: ${err.message}`, id: idFromXML, data: recordXML};\n throw new MatchingError(422, {message: `Failed converting record: ${err.message}`, id: idFromXML || '000000000', data: recordXML});\n }\n }\n });\n });\n }\n };\n\n function checkMaxedQuery(query, total, serverMaxResult) {\n // eslint-disable-next-line functional/no-conditional-statement\n if (total >= serverMaxResult) {\n debug(`WARNING: Query ${query} resulted in ${total} hits which meets the serverMaxResult (${serverMaxResult}) `);\n return query;\n }\n }\n\n\n function getRecordId(record) {\n const [field] = record.get(/^001$/u);\n return field ? field.value : '';\n }\n\n function getRecordIdFromXML(recordXML) {\n //<controlfield tag=\\\"001\\\">015376846</controlfield\n debug(`Cannot yet find possible database record id from recordXML (length ${recordXML.length})`);\n return undefined;\n }\n\n};\n"],"mappings":";;;;;;;;;;;;;AA4BA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;AAjCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAWO,MAAMA,oBAAN,SAAmCC,KAAnC,CAAyC,E,CAEhD;AAEA;;;;;eACe,CAAC;EAACC,MAAD;EAASC,UAAT;EAAqBC,GAArB;EAA0BC,aAA1B;EAAyCC,oBAAoB,GAAG,E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cACA,MAAM,IAAIW,qBAAJ,CAAkB,GAAlB,EAAuB;gBAACD,OAAO,EAAG,6BAA4BtB,GAAG,CAACsB,OAAQ,EAAnD;gBAAsDH,EAAE,EAAEC,SAAS,IAAI,WAAvE;gBAAoFI,IAAI,EAAEZ;cAA1F,CAAvB,CAAN;YACD;UACF;QACF,CAnDH;MAoDD,CA3DM,CAAP;IA4DD;EACF,CA1FD;;EA4FA,SAASxB,eAAT,CAAyBX,KAAzB,EAAgCI,KAAhC,EAAuC/B,eAAvC,EAAwD;IACtD;IACA,IAAI+B,KAAK,IAAI/B,eAAb,EAA8B;MAC5BI,KAAK,CAAE,kBAAiBuB,KAAM,gBAAeI,KAAM,0CAAyC/B,eAAgB,IAAvG,CAAL;MACA,OAAO2B,KAAP;IACD;EACF;;EAGD,SAASf,WAAT,CAAqBjB,MAArB,EAA6B;IAC3B,MAAM,CAACgF,KAAD,IAAUhF,MAAM,CAACiF,GAAP,CAAW,QAAX,CAAhB;IACA,OAAOD,KAAK,GAAGA,KAAK,CAAChB,KAAT,GAAiB,EAA7B;EACD;;EAED,SAASY,kBAAT,CAA4BT,SAA5B,EAAuC;IACrC;IACA1D,KAAK,CAAE,sEAAqE0D,SAAS,CAAC3C,MAAO,GAAxF,CAAL;IACA,OAAOoB,SAAP;EACD;AAEF,C"}
|
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _chai = require("chai");
|
|
4
|
-
|
|
5
|
-
var _fixura = require("@natlibfi/fixura");
|
|
6
|
-
|
|
7
|
-
var _fixugenHttpClient = _interopRequireDefault(require("@natlibfi/fixugen-http-client"));
|
|
8
|
-
|
|
9
|
-
var _marcRecord = require("@natlibfi/marc-record");
|
|
10
|
-
|
|
11
|
-
var _melindaCommons = require("@natlibfi/melinda-commons");
|
|
12
|
-
|
|
13
|
-
var _ = _interopRequireWildcard(require("."));
|
|
14
|
-
|
|
15
|
-
var _debug = _interopRequireDefault(require("debug"));
|
|
16
|
-
|
|
17
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
18
|
-
|
|
19
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
20
|
-
|
|
21
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
*
|
|
25
|
-
* @licstart The following is the entire license notice for the JavaScript code in this file.
|
|
26
|
-
*
|
|
27
|
-
* Melinda record matching modules for Javascript
|
|
28
|
-
*
|
|
29
|
-
* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
|
|
30
|
-
*
|
|
31
|
-
* This file is part of melinda-record-matching-js
|
|
32
|
-
*
|
|
33
|
-
* melinda-record-matching-js program is free software: you can redistribute it and/or modify
|
|
34
|
-
* it under the terms of the GNU Lesser General Public License as
|
|
35
|
-
* published by the Free Software Foundation, either version 3 of the
|
|
36
|
-
* License, or (at your option) any later version.
|
|
37
|
-
*
|
|
38
|
-
* melinda-record-matching-js is distributed in the hope that it will be useful,
|
|
39
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
40
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
41
|
-
* GNU Lesser General Public License for more details.
|
|
42
|
-
*
|
|
43
|
-
* You should have received a copy of the GNU Affero General Public License
|
|
44
|
-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
45
|
-
*
|
|
46
|
-
* @licend The above is the entire license notice
|
|
47
|
-
* for the JavaScript code in this file.
|
|
48
|
-
*
|
|
49
|
-
*/
|
|
50
|
-
const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:candidate-search:test');
|
|
51
|
-
describe('candidate-search', () => {
|
|
52
|
-
(0, _fixugenHttpClient.default)({
|
|
53
|
-
callback,
|
|
54
|
-
path: [__dirname, '..', '..', 'test-fixtures', 'candidate-search', 'index'],
|
|
55
|
-
recurse: false,
|
|
56
|
-
fixura: {
|
|
57
|
-
reader: _fixura.READERS.JSON
|
|
58
|
-
}
|
|
59
|
-
}); // eslint-disable-next-line max-statements
|
|
60
|
-
|
|
61
|
-
async function callback({
|
|
62
|
-
getFixture,
|
|
63
|
-
factoryOptions,
|
|
64
|
-
searchOptions,
|
|
65
|
-
expectedFactoryError = false,
|
|
66
|
-
expectedSearchError = false,
|
|
67
|
-
enabled = true
|
|
68
|
-
}) {
|
|
69
|
-
const url = 'http://foo.bar';
|
|
70
|
-
|
|
71
|
-
if (!enabled) {
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (expectedFactoryError) {
|
|
76
|
-
if (expectedFactoryError.isCandidateSearchError) {
|
|
77
|
-
(0, _chai.expect)(() => (0, _.default)({ ...formatFactoryOptions(),
|
|
78
|
-
url
|
|
79
|
-
})).to.throw(_.CandidateSearchError, new RegExp(expectedFactoryError, 'u'));
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
(0, _chai.expect)(() => (0, _.default)({ ...formatFactoryOptions(),
|
|
84
|
-
url
|
|
85
|
-
})).to.throw(new RegExp(expectedFactoryError, 'u'));
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const search = (0, _.default)({ ...formatFactoryOptions(),
|
|
90
|
-
url
|
|
91
|
-
});
|
|
92
|
-
await iterate({
|
|
93
|
-
searchOptions,
|
|
94
|
-
expectedSearchError
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
function formatFactoryOptions() {
|
|
98
|
-
debug(`Using factoryOptions: ${JSON.stringify(factoryOptions)}`);
|
|
99
|
-
return { ...factoryOptions,
|
|
100
|
-
maxRecordsPerRequest: factoryOptions.maxRecordsPerRequest || 1,
|
|
101
|
-
maxServerResults: factoryOptions.maxServerResults || undefined,
|
|
102
|
-
record: new _marcRecord.MarcRecord(factoryOptions.record, {
|
|
103
|
-
subfieldValues: false
|
|
104
|
-
})
|
|
105
|
-
};
|
|
106
|
-
} // eslint-disable-next-line max-statements
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
async function iterate({
|
|
110
|
-
searchOptions,
|
|
111
|
-
expectedSearchError,
|
|
112
|
-
expectedErrorStatus,
|
|
113
|
-
count = 1
|
|
114
|
-
}) {
|
|
115
|
-
const expectedResults = getFixture(`expectedResults${count}.json`);
|
|
116
|
-
|
|
117
|
-
if (expectedSearchError) {
|
|
118
|
-
// eslint-disable-line functional/no-conditional-statement
|
|
119
|
-
try {
|
|
120
|
-
await search(searchOptions);
|
|
121
|
-
throw new Error('Expected an error');
|
|
122
|
-
} catch (err) {
|
|
123
|
-
debug(`Got an error: ${err}`);
|
|
124
|
-
(0, _chai.expect)(err).to.be.an('error');
|
|
125
|
-
const errorMessage = err instanceof _melindaCommons.Error ? err.payload.message : err.message;
|
|
126
|
-
const errorStatus = err instanceof _melindaCommons.Error ? err.status : undefined;
|
|
127
|
-
debug(`errorMessage: ${errorMessage}, errorStatus: ${errorStatus}`);
|
|
128
|
-
(0, _chai.expect)(errorMessage).to.match(new RegExp(expectedSearchError, 'u'));
|
|
129
|
-
|
|
130
|
-
if (expectedErrorStatus) {
|
|
131
|
-
(0, _chai.expect)(errorStatus).to.be(expectedErrorStatus);
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
} // eslint-disable-next-line functional/no-conditional-statement
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
if (!expectedSearchError) {
|
|
141
|
-
const results = await search(searchOptions);
|
|
142
|
-
(0, _chai.expect)(formatResults(results)).to.eql(expectedResults);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
function formatResults(results) {
|
|
146
|
-
debug(results); //eslint-disable-line
|
|
147
|
-
|
|
148
|
-
return { ...results,
|
|
149
|
-
records: results.records.map(({
|
|
150
|
-
record,
|
|
151
|
-
id
|
|
152
|
-
}) => ({
|
|
153
|
-
id,
|
|
154
|
-
record: record.toObject()
|
|
155
|
-
}))
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
//# sourceMappingURL=index.spec.js.map
|