@natlibfi/melinda-record-matching 4.3.5 → 5.0.0-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.
Files changed (101) hide show
  1. package/.github/workflows/melinda-node-tests.yml +11 -7
  2. package/eslint.config.js +52 -0
  3. package/example.env +4 -0
  4. package/package.json +22 -90
  5. package/src/candidate-search/choose-queries.js +1 -3
  6. package/src/candidate-search/index.js +63 -89
  7. package/src/candidate-search/{index.spec.js → index.test.js} +19 -18
  8. package/src/candidate-search/query-list/bib.js +10 -4
  9. package/src/candidate-search/query-list/{bib.spec.js → bib.test.js} +8 -7
  10. package/src/candidate-search/query-list/component.js +127 -0
  11. package/src/candidate-search/query-list/index.js +23 -9
  12. package/src/cli.js +177 -0
  13. package/src/index.js +22 -37
  14. package/src/{index.spec.js → index.test.js} +11 -14
  15. package/src/match-detection/features/bib/all-source-ids.js +2 -2
  16. package/src/match-detection/features/bib/authors.js +3 -2
  17. package/src/match-detection/features/bib/index.js +16 -16
  18. package/src/match-detection/features/bib/{index.spec.js → index.test.js} +7 -6
  19. package/src/match-detection/features/bib/isbn.js +2 -2
  20. package/src/match-detection/features/bib/issn.js +1 -1
  21. package/src/match-detection/features/bib/language.js +5 -5
  22. package/src/match-detection/features/bib/media-type.js +1 -1
  23. package/src/match-detection/features/bib/melinda-id.js +1 -1
  24. package/src/match-detection/features/bib/melinda-identifier-factory.js +5 -5
  25. package/src/match-detection/features/bib/other-standard-identifier.js +1 -1
  26. package/src/match-detection/features/bib/publication-time-allow-cons-years-multi.js +6 -6
  27. package/src/match-detection/features/bib/publication-time-allow-cons-years.js +1 -1
  28. package/src/match-detection/features/bib/publication-time.js +1 -1
  29. package/src/match-detection/features/bib/standard-identifier-factory.js +1 -2
  30. package/src/match-detection/features/bib/title-version-original.js +2 -1
  31. package/src/match-detection/features/bib/title.js +6 -5
  32. package/src/match-detection/features/index.js +1 -1
  33. package/src/match-detection/index.js +1 -1
  34. package/src/match-detection/{index.spec.js → index.test.js} +9 -8
  35. package/src/matching-utils.js +8 -9
  36. package/dist/candidate-search/candidate-search-utils.js +0 -29
  37. package/dist/candidate-search/candidate-search-utils.js.map +0 -1
  38. package/dist/candidate-search/choose-queries.js +0 -122
  39. package/dist/candidate-search/choose-queries.js.map +0 -1
  40. package/dist/candidate-search/index.js +0 -260
  41. package/dist/candidate-search/index.js.map +0 -1
  42. package/dist/candidate-search/index.spec.js +0 -133
  43. package/dist/candidate-search/index.spec.js.map +0 -1
  44. package/dist/candidate-search/query-list/bib.js +0 -458
  45. package/dist/candidate-search/query-list/bib.js.map +0 -1
  46. package/dist/candidate-search/query-list/bib.spec.js +0 -46
  47. package/dist/candidate-search/query-list/bib.spec.js.map +0 -1
  48. package/dist/candidate-search/query-list/index.js +0 -47
  49. package/dist/candidate-search/query-list/index.js.map +0 -1
  50. package/dist/index.js +0 -555
  51. package/dist/index.js.map +0 -1
  52. package/dist/index.spec.js +0 -99
  53. package/dist/index.spec.js.map +0 -1
  54. package/dist/match-detection/features/bib/all-source-ids.js +0 -91
  55. package/dist/match-detection/features/bib/all-source-ids.js.map +0 -1
  56. package/dist/match-detection/features/bib/authors.js +0 -86
  57. package/dist/match-detection/features/bib/authors.js.map +0 -1
  58. package/dist/match-detection/features/bib/bibliographic-level.js +0 -15
  59. package/dist/match-detection/features/bib/bibliographic-level.js.map +0 -1
  60. package/dist/match-detection/features/bib/host-component.js +0 -15
  61. package/dist/match-detection/features/bib/host-component.js.map +0 -1
  62. package/dist/match-detection/features/bib/index.js +0 -119
  63. package/dist/match-detection/features/bib/index.js.map +0 -1
  64. package/dist/match-detection/features/bib/index.spec.js +0 -65
  65. package/dist/match-detection/features/bib/index.spec.js.map +0 -1
  66. package/dist/match-detection/features/bib/isbn.js +0 -49
  67. package/dist/match-detection/features/bib/isbn.js.map +0 -1
  68. package/dist/match-detection/features/bib/issn.js +0 -24
  69. package/dist/match-detection/features/bib/issn.js.map +0 -1
  70. package/dist/match-detection/features/bib/language.js +0 -113
  71. package/dist/match-detection/features/bib/language.js.map +0 -1
  72. package/dist/match-detection/features/bib/media-type.js +0 -56
  73. package/dist/match-detection/features/bib/media-type.js.map +0 -1
  74. package/dist/match-detection/features/bib/melinda-id.js +0 -21
  75. package/dist/match-detection/features/bib/melinda-id.js.map +0 -1
  76. package/dist/match-detection/features/bib/melinda-identifier-factory.js +0 -62
  77. package/dist/match-detection/features/bib/melinda-identifier-factory.js.map +0 -1
  78. package/dist/match-detection/features/bib/other-standard-identifier.js +0 -25
  79. package/dist/match-detection/features/bib/other-standard-identifier.js.map +0 -1
  80. package/dist/match-detection/features/bib/publication-time-allow-cons-years-multi.js +0 -229
  81. package/dist/match-detection/features/bib/publication-time-allow-cons-years-multi.js.map +0 -1
  82. package/dist/match-detection/features/bib/publication-time-allow-cons-years.js +0 -44
  83. package/dist/match-detection/features/bib/publication-time-allow-cons-years.js.map +0 -1
  84. package/dist/match-detection/features/bib/publication-time.js +0 -21
  85. package/dist/match-detection/features/bib/publication-time.js.map +0 -1
  86. package/dist/match-detection/features/bib/record-type.js +0 -18
  87. package/dist/match-detection/features/bib/record-type.js.map +0 -1
  88. package/dist/match-detection/features/bib/standard-identifier-factory.js +0 -188
  89. package/dist/match-detection/features/bib/standard-identifier-factory.js.map +0 -1
  90. package/dist/match-detection/features/bib/title-version-original.js +0 -52
  91. package/dist/match-detection/features/bib/title-version-original.js.map +0 -1
  92. package/dist/match-detection/features/bib/title.js +0 -70
  93. package/dist/match-detection/features/bib/title.js.map +0 -1
  94. package/dist/match-detection/features/index.js +0 -11
  95. package/dist/match-detection/features/index.js.map +0 -1
  96. package/dist/match-detection/index.js +0 -174
  97. package/dist/match-detection/index.js.map +0 -1
  98. package/dist/match-detection/index.spec.js +0 -63
  99. package/dist/match-detection/index.spec.js.map +0 -1
  100. package/dist/matching-utils.js +0 -115
  101. package/dist/matching-utils.js.map +0 -1
@@ -1,260 +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
- var _debug = _interopRequireDefault(require("debug"));
14
- var _sruClient = _interopRequireWildcard(require("@natlibfi/sru-client"));
15
- var _marcRecord = require("@natlibfi/marc-record");
16
- var _marcRecordSerializers = require("@natlibfi/marc-record-serializers");
17
- var _queryList = _interopRequireWildcard(require("./query-list"));
18
- var _melindaCommons = require("@natlibfi/melinda-commons");
19
- var _chooseQueries = _interopRequireDefault(require("./choose-queries"));
20
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
21
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
22
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
23
- class CandidateSearchError extends Error {}
24
-
25
- // serverMaxResults : maximum size of total search result available from the server, defaults to Aleph's 20000
26
- exports.CandidateSearchError = CandidateSearchError;
27
- var _default = async ({
28
- record,
29
- searchSpec,
30
- url,
31
- maxCandidates,
32
- maxRecordsPerRequest = 50,
33
- serverMaxResult = 20000
34
- }) => {
35
- _marcRecord.MarcRecord.setValidationOptions({
36
- subfieldValues: false
37
- });
38
- const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:candidate-search');
39
- const debugData = debug.extend('data');
40
- debugData(`SearchSpec: ${JSON.stringify(searchSpec)}`);
41
- debugData(`Url: ${url}`);
42
- debugData(`MaxRecordsPerRequest ${maxRecordsPerRequest}`);
43
- debugData(`ServerMaxResult: ${serverMaxResult}`);
44
- debugData(`MaxCandidates: ${maxCandidates}`);
45
-
46
- // Do not retrieve more candidates than defined in maxCandidates
47
- const adjustedMaxRecordsPerRequest = maxRecordsPerRequest >= maxCandidates ? maxCandidates : maxRecordsPerRequest;
48
- const inputRecordId = getRecordId(record);
49
- const queryListResult = (0, _queryList.default)(record, searchSpec);
50
- const queryList = queryListResult[0]?.queryList ? queryListResult[0].queryList : queryListResult;
51
- const queryListType = queryListResult[0]?.queryListType ? queryListResult[0].queryListType : undefined;
52
-
53
- // if generateQueryList errored we should throw 422
54
- if (queryList.length === 0) {
55
- debug(`Empty list`);
56
- throw new CandidateSearchError(`Generated query list contains no queries`);
57
- }
58
- if (queryListType && queryListType !== 'alternates') {
59
- debug(`Unknown queryListType`);
60
- throw new CandidateSearchError(`Generated query list has invalid type`);
61
- }
62
- const client = (0, _sruClient.default)({
63
- url,
64
- maxRecordsPerRequest: adjustedMaxRecordsPerRequest,
65
- version: '2.0',
66
- retrieveAll: false
67
- });
68
- debug(`Searching matches for ${inputRecordId}`);
69
- const chosenQueryList = await filterQueryList({
70
- queryList,
71
- queryListType
72
- });
73
- debug(`Chosen queries: ${JSON.stringify(chosenQueryList)}`);
74
- async function filterQueryList({
75
- queryList,
76
- queryListType,
77
- maxCandidates
78
- }) {
79
- debug(`Generated queryList (type: ${queryListType}) ${JSON.stringify(queryList)}`);
80
- if (queryListType === 'alternates' && queryList.length > 1) {
81
- const queryListResult = await (0, _chooseQueries.default)({
82
- url,
83
- queryList,
84
- queryListType,
85
- maxCandidates
86
- });
87
- debug(`queryListResult: ${JSON.stringify(queryListResult)}`);
88
- return queryListResult.map(elem => elem.query);
89
- }
90
- return queryList;
91
- }
92
- // state.totalRecords : amount of candidate records available to the current query (undefined, if there was no queries left)
93
- // state.query : current query (undefined if there was no queries left)
94
- // state.searchCounter : sequence for current search for current query (undefined, if there we no queries left)
95
- // 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)
96
- // state.queriesLeft : amount of queries left
97
- // state.queryCounter : sequence for current query
98
- // state.maxedQueries : queries that resulted in more than serverMaxResults hits
99
-
100
- return {
101
- search
102
- };
103
-
104
- // eslint-disable-next-line max-statements
105
- async function search({
106
- queryOffset = 0,
107
- resultSetOffset = 1,
108
- totalRecords = 0,
109
- searchCounter = 0,
110
- queryCandidateCounter = 0,
111
- queryCounter = 0,
112
- maxedQueries = []
113
- }) {
114
- const query = chosenQueryList[queryOffset];
115
- debug(`Running query ${JSON.stringify(query)} (${queryOffset})`);
116
- if (query) {
117
- const {
118
- records,
119
- failures,
120
- nextOffset,
121
- total
122
- } = await retrieveRecords();
123
-
124
- // If resultSetOffset === 1 this is the first search for the current query
125
- debugData(`ResultSetOffset: ${resultSetOffset}`);
126
- const newTotalRecords = resultSetOffset === 1 ? total : totalRecords;
127
- const newQueryCounter = resultSetOffset === 1 ? queryCounter + 1 : queryCounter;
128
- const newSearchCounter = resultSetOffset === 1 ? 1 : searchCounter + 1;
129
- const newQueryCandidateCounter = resultSetOffset === 1 ? records.length + failures.length : queryCandidateCounter + records.length + failures.length;
130
- const maxedQuery = resultSetOffset === 1 ? checkMaxedQuery(query, total, serverMaxResult) : undefined;
131
- const newMaxedQueries = maxedQuery ? maxedQueries.concat(maxedQuery) : maxedQueries;
132
- if (typeof nextOffset === 'number') {
133
- debug(`Next search will be for query ${queryOffset} ${query}, starting from record ${nextOffset}`);
134
- return {
135
- records,
136
- failures,
137
- queryOffset,
138
- resultSetOffset: nextOffset,
139
- queriesLeft: queryList.length - (queryOffset + 1),
140
- totalRecords: newTotalRecords,
141
- query,
142
- searchCounter: newSearchCounter,
143
- queryCandidateCounter: newQueryCandidateCounter,
144
- queryCounter: newQueryCounter,
145
- maxedQueries: newMaxedQueries
146
- };
147
- }
148
- debug(`Query ${queryOffset} ${query} done.`);
149
- debug(`There are (${queryList.length - (queryOffset + 1)} queries left)`);
150
- return {
151
- records,
152
- failures,
153
- queryOffset: queryOffset + 1,
154
- queriesLeft: queryList.length - (queryOffset + 1),
155
- totalRecords: newTotalRecords,
156
- query,
157
- searchCounter: newSearchCounter,
158
- queryCandidateCounter: newQueryCandidateCounter,
159
- queryCounter: newQueryCounter,
160
- maxedQueries: newMaxedQueries
161
- };
162
- }
163
- debug(`All ${queryList.length} queries done, there's no query for ${queryOffset}`);
164
- return {
165
- records: [],
166
- failures: [],
167
- queriesLeft: 0,
168
- queryCounter,
169
- maxedQueries
170
- };
171
- function retrieveRecords() {
172
- return new Promise((resolve, reject) => {
173
- const promises = [];
174
- // eslint-disable-next-line functional/no-let
175
- let totalRecords = 0;
176
- debug(`Searching for candidates with query: ${query} (Offset ${resultSetOffset})`);
177
- client.searchRetrieve(query, {
178
- startRecord: resultSetOffset
179
- }).on('error', err => {
180
- // eslint-disable-next-line functional/no-conditional-statements
181
- if (err instanceof _sruClient.SruSearchError) {
182
- debug(`SRU SruSearchError for query: ${query}: ${err}`);
183
- reject(new CandidateSearchError(`SRU SruSearchError for query: ${query}: ${err}`));
184
- }
185
- debug(`SRU error for query: ${query}: ${err}`);
186
- reject(new CandidateSearchError(`SRU error for query: ${query}: ${err}`));
187
- }).on('total', total => {
188
- debug(`Got total: ${total}`);
189
- totalRecords += total;
190
- }).on('end', async nextOffset => {
191
- try {
192
- const recordPromises = await Promise.allSettled(promises);
193
- debugData(`All recordPromises: ${JSON.stringify(recordPromises)}`);
194
- const filtered = recordPromises.filter(r => r.status === 'fulfilled').map(r => r.value);
195
- const failures = recordPromises.filter(r => r.status === 'rejected').map(r => ({
196
- status: r.reason.status,
197
- payload: r.reason.payload
198
- }));
199
- debug(`Found ${recordPromises.length} records`);
200
- debug(`Found ${filtered.length} convertable candidates`);
201
- debug(`Found ${failures.length} NON-convertable candidates`);
202
- debugData(`Converted: ${JSON.stringify(filtered)}.`);
203
- debugData(`Not converted: ${JSON.stringify(failures)}.`);
204
- resolve({
205
- nextOffset,
206
- records: filtered,
207
- failures,
208
- total: totalRecords
209
- });
210
- } catch (err) {
211
- debug(`Error caught on END`);
212
- reject(err);
213
- }
214
- }).on('record', recordXML => {
215
- promises.push(handleRecord()); // eslint-disable-line functional/immutable-data
216
-
217
- async function handleRecord() {
218
- try {
219
- const recordMarc = await _marcRecordSerializers.MARCXML.from(recordXML, {
220
- subfieldValues: false
221
- });
222
- const recordId = getRecordId(recordMarc);
223
- return {
224
- record: recordMarc,
225
- id: recordId
226
- };
227
- } catch (err) {
228
- // What should this do?
229
- const idFromXML = getRecordIdFromXML(recordXML);
230
- debugData(`Failed converting record: ${err.message}, id: ${idFromXML}, data: ${recordXML}`);
231
- //return {message: `Failed converting record: ${err.message}`, id: idFromXML, data: recordXML};
232
- throw new _melindaCommons.Error(422, {
233
- message: `Failed converting record: ${err.message}`,
234
- id: idFromXML || '000000000',
235
- data: recordXML
236
- });
237
- }
238
- }
239
- });
240
- });
241
- }
242
- }
243
- function checkMaxedQuery(query, total, serverMaxResult) {
244
- if (total >= serverMaxResult) {
245
- debug(`WARNING: Query ${query} resulted in ${total} hits which meets the serverMaxResult (${serverMaxResult}) `);
246
- return query;
247
- }
248
- }
249
- function getRecordId(record) {
250
- const [field] = record.get(/^001$/u);
251
- return field ? field.value : '';
252
- }
253
- function getRecordIdFromXML(recordXML) {
254
- //<controlfield tag=\"001\">015376846</controlfield
255
- debug(`Cannot yet find possible database record id from recordXML (length ${recordXML.length})`);
256
- return undefined;
257
- }
258
- };
259
- exports.default = _default;
260
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","names":["_debug","_interopRequireDefault","require","_sruClient","_interopRequireWildcard","_marcRecord","_marcRecordSerializers","_queryList","_melindaCommons","_chooseQueries","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","CandidateSearchError","Error","exports","_default","record","searchSpec","url","maxCandidates","maxRecordsPerRequest","serverMaxResult","MarcRecord","setValidationOptions","subfieldValues","debug","createDebugLogger","debugData","extend","JSON","stringify","adjustedMaxRecordsPerRequest","inputRecordId","getRecordId","queryListResult","generateQueryList","queryList","queryListType","undefined","length","client","createClient","version","retrieveAll","chosenQueryList","filterQueryList","chooseQueries","map","elem","query","search","queryOffset","resultSetOffset","totalRecords","searchCounter","queryCandidateCounter","queryCounter","maxedQueries","records","failures","nextOffset","total","retrieveRecords","newTotalRecords","newQueryCounter","newSearchCounter","newQueryCandidateCounter","maxedQuery","checkMaxedQuery","newMaxedQueries","concat","queriesLeft","Promise","resolve","reject","promises","searchRetrieve","startRecord","on","err","SruSearchError","recordPromises","allSettled","filtered","filter","status","value","reason","payload","recordXML","push","handleRecord","recordMarc","MARCXML","from","recordId","id","idFromXML","getRecordIdFromXML","message","MatchingError","data","field"],"sources":["../../src/candidate-search/index.js"],"sourcesContent":["import 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';\nimport chooseQueries from './choose-queries';\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\nexport default async ({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 queryListResult = generateQueryList(record, searchSpec);\n const queryList = queryListResult[0]?.queryList ? queryListResult[0].queryList : queryListResult;\n const queryListType = queryListResult[0]?.queryListType ? queryListResult[0].queryListType : undefined;\n\n // if generateQueryList errored we should throw 422\n if (queryList.length === 0) {\n debug(`Empty list`);\n throw new CandidateSearchError(`Generated query list contains no queries`);\n }\n if (queryListType && queryListType !== 'alternates') {\n debug(`Unknown queryListType`);\n throw new CandidateSearchError(`Generated query list has invalid type`);\n }\n\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 const chosenQueryList = await filterQueryList({queryList, queryListType});\n debug(`Chosen queries: ${JSON.stringify(chosenQueryList)}`);\n\n async function filterQueryList({queryList, queryListType, maxCandidates}) {\n debug(`Generated queryList (type: ${queryListType}) ${JSON.stringify(queryList)}`);\n\n if (queryListType === 'alternates' && queryList.length > 1) {\n const queryListResult = await chooseQueries({url, queryList, queryListType, maxCandidates});\n debug(`queryListResult: ${JSON.stringify(queryListResult)}`);\n return queryListResult.map(elem => elem.query);\n }\n return queryList;\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 return {search};\n\n // eslint-disable-next-line max-statements\n async function search({queryOffset = 0, resultSetOffset = 1, totalRecords = 0, searchCounter = 0, queryCandidateCounter = 0, queryCounter = 0, maxedQueries = []}) {\n\n const query = chosenQueryList[queryOffset];\n debug(`Running query ${JSON.stringify(query)} (${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-statements\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 debugData(`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 ${recordPromises.length} records`);\n debug(`Found ${filtered.length} convertable candidates`);\n debug(`Found ${failures.length} NON-convertable candidates`);\n debugData(`Converted: ${JSON.stringify(filtered)}.`);\n debugData(`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 if (total >= serverMaxResult) {\n debug(`WARNING: Query ${query} resulted in ${total} hits which meets the serverMaxResult (${serverMaxResult}) `);\n return query;\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"],"mappings":";;;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,UAAA,GAAAC,uBAAA,CAAAF,OAAA;AACA,IAAAG,WAAA,GAAAH,OAAA;AACA,IAAAI,sBAAA,GAAAJ,OAAA;AACA,IAAAK,UAAA,GAAAH,uBAAA,CAAAF,OAAA;AACA,IAAAM,eAAA,GAAAN,OAAA;AACA,IAAAO,cAAA,GAAAR,sBAAA,CAAAC,OAAA;AAA6C,SAAAQ,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAP,wBAAAO,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,OAAAQ,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,CAAA,IAAAd,CAAA,oBAAAc,CAAA,OAAAC,cAAA,CAAAC,IAAA,CAAAhB,CAAA,EAAAc,CAAA,SAAAG,CAAA,GAAAP,CAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAb,CAAA,EAAAc,CAAA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AAAhB,OAAA,GAAAiB,QAAA","ignoreList":[]}
@@ -1,133 +0,0 @@
1
- "use strict";
2
-
3
- var _chai = require("chai");
4
- var _fixura = require("@natlibfi/fixura");
5
- var _fixugenHttpClient = _interopRequireDefault(require("@natlibfi/fixugen-http-client"));
6
- var _marcRecord = require("@natlibfi/marc-record");
7
- var _melindaCommons = require("@natlibfi/melinda-commons");
8
- var _ = _interopRequireWildcard(require("."));
9
- var _debug = _interopRequireDefault(require("debug"));
10
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
11
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
12
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
- const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:candidate-search:test');
14
- describe('candidate-search', () => {
15
- (0, _fixugenHttpClient.default)({
16
- callback,
17
- path: [__dirname, '..', '..', 'test-fixtures', 'candidate-search', 'index'],
18
- recurse: false,
19
- fixura: {
20
- reader: _fixura.READERS.JSON
21
- }
22
- });
23
-
24
- // eslint-disable-next-line max-statements
25
- async function callback({
26
- getFixture,
27
- factoryOptions,
28
- searchOptions,
29
- expectedFactoryError = false,
30
- expectedSearchError = false,
31
- enabled = true
32
- }) {
33
- const url = 'http://foo.bar';
34
- if (!enabled) {
35
- return;
36
- }
37
- if (expectedFactoryError) {
38
- debug(`We're expecting an error`);
39
- if (expectedFactoryError.isCandidateSearchError) {
40
- try {
41
- const result = (0, _.default)({
42
- ...formatFactoryOptions(),
43
- url
44
- });
45
- debug(result);
46
- } catch (err) {
47
- (0, _chai.expect)(err).to.equal(new _.CandidateSearchError(expectedFactoryError));
48
- }
49
- return;
50
- }
51
- try {
52
- const result = (0, _.default)({
53
- ...formatFactoryOptions(),
54
- url
55
- });
56
- debug(result);
57
- } catch (err) {
58
- (0, _chai.expect)(err).to.equal(new Error(expectedFactoryError));
59
- }
60
- return;
61
- }
62
- const {
63
- search
64
- } = await (0, _.default)({
65
- ...formatFactoryOptions(),
66
- url
67
- });
68
- // eslint-disable-next-line no-console
69
- console.log(search);
70
- await iterate({
71
- searchOptions,
72
- expectedSearchError
73
- });
74
- function formatFactoryOptions() {
75
- debug(`Using factoryOptions: ${JSON.stringify(factoryOptions)}`);
76
- return {
77
- ...factoryOptions,
78
- maxRecordsPerRequest: factoryOptions.maxRecordsPerRequest || 1,
79
- maxServerResults: factoryOptions.maxServerResults || undefined,
80
- record: new _marcRecord.MarcRecord(factoryOptions.record, {
81
- subfieldValues: false
82
- })
83
- };
84
- }
85
- async function iterate({
86
- searchOptions,
87
- expectedSearchError,
88
- expectedErrorStatus,
89
- count = 1
90
- }) {
91
- const expectedResults = getFixture(`expectedResults${count}.json`);
92
- if (expectedSearchError) {
93
- // eslint-disable-line functional/no-conditional-statements
94
- try {
95
- await search(searchOptions);
96
- throw new Error('Expected an error');
97
- } catch (err) {
98
- debug(`Got an error: ${err}`);
99
- (0, _chai.expect)(err).to.be.an('error');
100
- const errorMessage = err instanceof _melindaCommons.Error ? err.payload.message : err.message;
101
- const errorStatus = err instanceof _melindaCommons.Error ? err.status : undefined;
102
- debug(`errorMessage: ${errorMessage}, errorStatus: ${errorStatus}`);
103
- (0, _chai.expect)(errorMessage).to.match(new RegExp(expectedSearchError, 'u'));
104
- if (expectedErrorStatus) {
105
- (0, _chai.expect)(errorStatus).to.be(expectedErrorStatus);
106
- return;
107
- }
108
- return;
109
- }
110
- }
111
-
112
- // eslint-disable-next-line functional/no-conditional-statements
113
- if (!expectedSearchError) {
114
- const results = await search(searchOptions);
115
- (0, _chai.expect)(formatResults(results)).to.eql(expectedResults);
116
- }
117
- function formatResults(results) {
118
- debug(results);
119
- return {
120
- ...results,
121
- records: results.records.map(({
122
- record,
123
- id
124
- }) => ({
125
- id,
126
- record: record.toObject()
127
- }))
128
- };
129
- }
130
- }
131
- }
132
- });
133
- //# sourceMappingURL=index.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.spec.js","names":["_chai","require","_fixura","_fixugenHttpClient","_interopRequireDefault","_marcRecord","_melindaCommons","_","_interopRequireWildcard","_debug","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","debug","createDebugLogger","describe","generateTests","callback","path","__dirname","recurse","fixura","reader","READERS","JSON","getFixture","factoryOptions","searchOptions","expectedFactoryError","expectedSearchError","enabled","url","isCandidateSearchError","result","createSearchInterface","formatFactoryOptions","err","expect","to","equal","CandidateSearchError","Error","search","console","log","iterate","stringify","maxRecordsPerRequest","maxServerResults","undefined","record","MarcRecord","subfieldValues","expectedErrorStatus","count","expectedResults","be","an","errorMessage","MatchingError","payload","message","errorStatus","status","match","RegExp","results","formatResults","eql","records","map","id","toObject"],"sources":["../../src/candidate-search/index.spec.js"],"sourcesContent":["import {expect} from 'chai';\nimport {READERS} from '@natlibfi/fixura';\nimport generateTests from '@natlibfi/fixugen-http-client';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport {Error as MatchingError} from '@natlibfi/melinda-commons';\nimport createSearchInterface, {CandidateSearchError} from '.';\nimport createDebugLogger from 'debug';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:test');\n\ndescribe('candidate-search', () => {\n generateTests({\n callback,\n path: [__dirname, '..', '..', 'test-fixtures', 'candidate-search', 'index'],\n recurse: false,\n fixura: {\n reader: READERS.JSON\n }\n });\n\n // eslint-disable-next-line max-statements\n async function callback({getFixture, factoryOptions, searchOptions, expectedFactoryError = false, expectedSearchError = false, enabled = true}) {\n const url = 'http://foo.bar';\n\n if (!enabled) {\n return;\n }\n\n if (expectedFactoryError) {\n debug(`We're expecting an error`);\n if (expectedFactoryError.isCandidateSearchError) {\n try {\n const result = createSearchInterface({...formatFactoryOptions(), url});\n debug(result);\n } catch (err) {\n expect(err).to.equal(new CandidateSearchError(expectedFactoryError));\n }\n return;\n }\n\n try {\n const result = createSearchInterface({...formatFactoryOptions(), url});\n debug(result);\n } catch (err) {\n expect(err).to.equal(new Error(expectedFactoryError));\n }\n return;\n }\n\n const {search} = await createSearchInterface({...formatFactoryOptions(), url});\n // eslint-disable-next-line no-console\n console.log(search);\n await iterate({searchOptions, expectedSearchError});\n\n function formatFactoryOptions() {\n debug(`Using factoryOptions: ${JSON.stringify(factoryOptions)}`);\n return {\n ...factoryOptions,\n maxRecordsPerRequest: factoryOptions.maxRecordsPerRequest || 1,\n maxServerResults: factoryOptions.maxServerResults || undefined,\n record: new MarcRecord(factoryOptions.record, {subfieldValues: false})\n };\n }\n\n async function iterate({searchOptions, expectedSearchError, expectedErrorStatus, count = 1}) {\n const expectedResults = getFixture(`expectedResults${count}.json`);\n\n if (expectedSearchError) { // eslint-disable-line functional/no-conditional-statements\n try {\n await search(searchOptions);\n throw new Error('Expected an error');\n } catch (err) {\n debug(`Got an error: ${err}`);\n expect(err).to.be.an('error');\n const errorMessage = err instanceof MatchingError ? err.payload.message : err.message;\n const errorStatus = err instanceof MatchingError ? err.status : undefined;\n debug(`errorMessage: ${errorMessage}, errorStatus: ${errorStatus}`);\n expect(errorMessage).to.match(new RegExp(expectedSearchError, 'u'));\n\n if (expectedErrorStatus) {\n expect(errorStatus).to.be(expectedErrorStatus);\n return;\n }\n return;\n }\n }\n\n // eslint-disable-next-line functional/no-conditional-statements\n if (!expectedSearchError) {\n const results = await search(searchOptions);\n expect(formatResults(results)).to.eql(expectedResults);\n }\n\n function formatResults(results) {\n debug(results);\n return {\n ...results,\n records: results.records.map(({record, id}) => ({id, record: record.toObject()}))\n };\n }\n\n }\n }\n});\n"],"mappings":";;AAAA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,kBAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,WAAA,GAAAJ,OAAA;AACA,IAAAK,eAAA,GAAAL,OAAA;AACA,IAAAM,CAAA,GAAAC,uBAAA,CAAAP,OAAA;AACA,IAAAQ,MAAA,GAAAL,sBAAA,CAAAH,OAAA;AAAsC,SAAAS,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAH,wBAAAG,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,OAAAQ,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,CAAA,IAAAd,CAAA,oBAAAc,CAAA,OAAAC,cAAA,CAAAC,IAAA,CAAAhB,CAAA,EAAAc,CAAA,SAAAG,CAAA,GAAAP,CAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAb,CAAA,EAAAc,CAAA,UAAAG,CAAA,KAAAA,CAAA,CAAAV,GAAA,IAAAU,CAAA,CAAAC,GAAA,IAAAP,MAAA,CAAAC,cAAA,CAA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