@natlibfi/melinda-record-matching 5.0.0-alpha.3 → 5.0.0-alpha.4

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.
@@ -108,10 +108,16 @@ export function retrieveRecords(client, query, resultSetOffset) {
108
108
  reject(err);
109
109
  }
110
110
  }).on("record", (record) => {
111
- const [field] = record.get(/^001$/u);
112
- debug(field);
113
- const id = field.value ? field.value : "";
114
- records.push({ record, id });
111
+ try {
112
+ const marcRecord = new MarcRecord(record);
113
+ const [field] = marcRecord.get(/^001$/u);
114
+ debug(field);
115
+ const id = field.value ? field.value : "";
116
+ records.push({ record: marcRecord, id });
117
+ } catch (error) {
118
+ debug(`Sru => record error: ${error}`);
119
+ debug(`Sru => record: ${record}`);
120
+ }
115
121
  });
116
122
  });
117
123
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/candidate-search/index.js"],
4
- "sourcesContent": ["import createDebugLogger from 'debug';\nimport createClient, {SruSearchError} from '@natlibfi/sru-client';\nimport {MarcRecord} from '@natlibfi/marc-record';\n\nimport generateQueryList from './query-list/index.js';\nimport chooseQueries from './choose-queries.js';\n\nexport {searchTypes} from './query-list/index.js';\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 client = createClient({\n url,\n maxRecordsPerRequest: adjustedMaxRecordsPerRequest,\n version: '2.0',\n retrieveAll: false,\n metadataFormat: 'marcJson'\n });\n\n const inputRecordId = getRecordId(record);\n const queryListResult = await generateQueryList(record, searchSpec, client);\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 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 const query = chosenQueryList[queryOffset];\n debug(`Running query ${JSON.stringify(query)} (${queryOffset})`);\n\n if (query) {\n const {records, nextOffset, total} = await retrieveRecords(client, query, resultSetOffset);\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 : queryCandidateCounter + records.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, 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, 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: [], queriesLeft: 0, queryCounter, maxedQueries};\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\nexport function retrieveRecords(client, query, resultSetOffset) {\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:retrieveRecords');\n // eslint-disable-next-line no-unused-vars\n const debugData = debug.extend('data');\n\n return new Promise((resolve, reject) => {\n const records = [];\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 if (err instanceof SruSearchError) {\n debug(`SRU SruSearchError for query: ${query}: ${err}`);\n reject(new CandidateSearchError(`SRU SruSearchError for query: ${query}: ${err}`));\n }\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', nextOffset => {\n try {\n debug(`Found ${records.length} records`);\n\n resolve({nextOffset, records, total: totalRecords});\n } catch (err) {\n debug(`Error caught on END`);\n reject(err);\n }\n })\n .on('record', record => {\n const [field] = record.get(/^001$/u);\n debug(field);\n const id = field.value ? field.value : '';\n records.push({record, id});\n });\n });\n}\n"],
5
- "mappings": "AAAA,OAAO,uBAAuB;AAC9B,OAAO,gBAAe,sBAAqB;AAC3C,SAAQ,kBAAiB;AAEzB,OAAO,uBAAuB;AAC9B,OAAO,mBAAmB;AAE1B,SAAQ,mBAAkB;AAEnB,aAAM,6BAA6B,MAAM;AAAE;AAIlD,eAAe,OAAO,EAAC,QAAQ,YAAY,KAAK,eAAe,uBAAuB,IAAI,kBAAkB,IAAK,MAAM;AACrH,aAAW,qBAAqB,EAAC,gBAAgB,MAAK,CAAC;AAEvD,QAAM,QAAQ,kBAAkB,oDAAoD;AACpF,QAAM,YAAY,MAAM,OAAO,MAAM;AAErC,YAAU,eAAe,KAAK,UAAU,UAAU,CAAC,EAAE;AACrD,YAAU,QAAQ,GAAG,EAAE;AACvB,YAAU,wBAAwB,oBAAoB,EAAE;AACxD,YAAU,oBAAoB,eAAe,EAAE;AAC/C,YAAU,kBAAkB,aAAa,EAAE;AAG3C,QA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IACF,CAAC,EACA,GAAG,UAAU,YAAU;AACtB,YAAM,CAAC,KAAK,IAAI,OAAO,IAAI,QAAQ;AACnC,YAAM,KAAK;AACX,YAAM,KAAK,MAAM,QAAQ,MAAM,QAAQ;AACvC,cAAQ,KAAK,EAAC,QAAQ,GAAE,CAAC;AAAA,IAC3B,CAAC;AAAA,EACL,CAAC;AACH;",
4
+ "sourcesContent": ["import createDebugLogger from 'debug';\nimport createClient, {SruSearchError} from '@natlibfi/sru-client';\nimport {MarcRecord} from '@natlibfi/marc-record';\n\nimport generateQueryList from './query-list/index.js';\nimport chooseQueries from './choose-queries.js';\n\nexport {searchTypes} from './query-list/index.js';\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 client = createClient({\n url,\n maxRecordsPerRequest: adjustedMaxRecordsPerRequest,\n version: '2.0',\n retrieveAll: false,\n metadataFormat: 'marcJson'\n });\n\n const inputRecordId = getRecordId(record);\n const queryListResult = await generateQueryList(record, searchSpec, client);\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 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 const query = chosenQueryList[queryOffset];\n debug(`Running query ${JSON.stringify(query)} (${queryOffset})`);\n\n if (query) {\n const {records, nextOffset, total} = await retrieveRecords(client, query, resultSetOffset);\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 : queryCandidateCounter + records.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, 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, 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: [], queriesLeft: 0, queryCounter, maxedQueries};\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\nexport function retrieveRecords(client, query, resultSetOffset) {\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:retrieveRecords');\n // eslint-disable-next-line no-unused-vars\n const debugData = debug.extend('data');\n\n return new Promise((resolve, reject) => {\n const records = [];\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 if (err instanceof SruSearchError) {\n debug(`SRU SruSearchError for query: ${query}: ${err}`);\n reject(new CandidateSearchError(`SRU SruSearchError for query: ${query}: ${err}`));\n }\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', nextOffset => {\n try {\n debug(`Found ${records.length} records`);\n\n resolve({nextOffset, records, total: totalRecords});\n } catch (err) {\n debug(`Error caught on END`);\n reject(err);\n }\n })\n .on('record', record => {\n // MarcRecord Error handling\n try {\n const marcRecord = new MarcRecord(record);\n const [field] = marcRecord.get(/^001$/u);\n debug(field);\n const id = field.value ? field.value : '';\n records.push({record: marcRecord, id});\n } catch (error) {\n debug(`Sru => record error: ${error}`);\n debug(`Sru => record: ${record}`);\n }\n });\n });\n}\n"],
5
+ "mappings": "AAAA,OAAO,uBAAuB;AAC9B,OAAO,gBAAe,sBAAqB;AAC3C,SAAQ,kBAAiB;AAEzB,OAAO,uBAAuB;AAC9B,OAAO,mBAAmB;AAE1B,SAAQ,mBAAkB;AAEnB,aAAM,6BAA6B,MAAM;AAAE;AAIlD,eAAe,OAAO,EAAC,QAAQ,YAAY,KAAK,eAAe,uBAAuB,IAAI,kBAAkB,IAAK,MAAM;AACrH,aAAW,qBAAqB,EAAC,gBAAgB,MAAK,CAAC;AAEvD,QAAM,QAAQ,kBAAkB,oDAAoD;AACpF,QAAM,YAAY,MAAM,OAAO,MAAM;AAErC,YAAU,eAAe,KAAK,UAAU,UAAU,CAAC,EAAE;AACrD,YAAU,QAAQ,GAAG,EAAE;AACvB,YAAU,wBAAwB,oBAAoB,EAAE;AACxD,YAAU,oBAAoB,eAAe,EAAE;AAC/C,YAAU,kBAAkB,aAAa,EAAE;AAG3C,QAAM,+BAA+B,wBAAwB,gBAAgB,gBAAgB;AAE7F,QAAM,SAAS,aAAa;AAAA,IAC1B;AAAA,IACA,sBAAsB;AAAA,IACtB,SAAS;AAAA,IACT,aAAa;AAAA,IACb,gBAAgB;AAAA,EAClB,CAAC;AAED,QAAM,gBAAgB,YAAY,MAAM;AACxC,QAAM,kBAAkB,MAAM,kBAAkB,QAAQ,YAA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AAAA,MACvC,SAAS,OAAO;AACd,cAAM,wBAAwB,KAAK,EAAE;AACrC,cAAM,kBAAkB,MAAM,EAAE;AAAA,MAClC;AAAA,IACF,CAAC;AAAA,EACL,CAAC;AACH;",
6
6
  "names": ["queryList", "queryListType", "maxCandidates", "queryListResult", "serverMaxResult", "record"]
7
7
  }
package/package.json CHANGED
@@ -13,9 +13,9 @@
13
13
  "url": "https://github.com/NatLibFi/melinda-record-matching-js"
14
14
  },
15
15
  "license": "MIT",
16
- "version": "5.0.0-alpha.3",
17
- "main": "./dist/index.js",
16
+ "version": "5.0.0-alpha.4",
18
17
  "type": "module",
18
+ "main": "./dist/index.js",
19
19
  "bin": "./dist/cli.js",
20
20
  "engines": {
21
21
  "node": ">=22"
@@ -30,31 +30,30 @@
30
30
  "cli": "node dist/cli.js",
31
31
  "lint": "eslint ./src",
32
32
  "lint:dev": "eslint --fix ./src",
33
- "test:base": "node --test --test-force-exit --experimental-test-coverage --test-reporter=spec './src/*.test.js' './src/**/*.test.js'",
33
+ "test:base": "node --test --test-force-exit --experimental-test-coverage --test-reporter=spec './src/**/*.test.js'",
34
34
  "test": "npm run lint && npm run test:base",
35
- "watch:test": "cross-env DEBUG=@natlibfi/* NODE_ENV=test node --watch --test --experimental-test-coverage --test-reporter=spec './src/*.test.js' './src/**/*.test.js'",
35
+ "watch:test": "cross-env DEBUG=@natlibfi/* NODE_ENV=test node --watch --test --experimental-test-coverage --test-reporter=spec './src/**/*.test.js'",
36
36
  "dev": "npm run watch:test",
37
37
  "dev:debug": "cross-env LOG_LEVEL=debug DEBUG=@natlibfi/* NODE_ENV=test npm run watch:test"
38
38
  },
39
39
  "dependencies": {
40
- "@natlibfi/marc-record": "next",
41
- "@natlibfi/marc-record-serializers": "next",
42
- "@natlibfi/melinda-commons": "next",
43
- "@natlibfi/sru-client": "next",
44
- "debug": "^4.4.1",
45
- "isbn3": "^1.2.14",
40
+ "@natlibfi/marc-record": "^10.0.0",
41
+ "@natlibfi/marc-record-serializers": "^11.0.0",
42
+ "@natlibfi/melinda-commons": "^14.0.0",
43
+ "@natlibfi/sru-client": "^7.0.0",
44
+ "debug": "^4.4.3",
45
+ "isbn3": "^2.0.0",
46
46
  "moment": "^2.30.1",
47
- "natural": "^8.0.1",
47
+ "natural": "^8.1.0",
48
48
  "uuid": "^13.0.0",
49
- "winston": "^3.17.0",
50
49
  "yargs": "^18.0.0"
51
50
  },
52
51
  "devDependencies": {
53
- "@natlibfi/fixugen": "next",
54
- "@natlibfi/fixugen-http-client": "next",
55
- "@natlibfi/fixura": "next",
56
- "cross-env": "^7.0.3",
57
- "esbuild": "^0.25.9",
58
- "eslint": "^9.35.0"
52
+ "@natlibfi/fixugen": "^3.0.0",
53
+ "@natlibfi/fixugen-http-client": "^4.0.0",
54
+ "@natlibfi/fixura": "^4.0.0",
55
+ "cross-env": "^10.1.0",
56
+ "esbuild": "^0.27.0",
57
+ "eslint": "^9.39.1"
59
58
  }
60
59
  }
@@ -153,10 +153,17 @@ export function retrieveRecords(client, query, resultSetOffset) {
153
153
  }
154
154
  })
155
155
  .on('record', record => {
156
- const [field] = record.get(/^001$/u);
157
- debug(field);
158
- const id = field.value ? field.value : '';
159
- records.push({record, id});
156
+ // MarcRecord Error handling
157
+ try {
158
+ const marcRecord = new MarcRecord(record);
159
+ const [field] = marcRecord.get(/^001$/u);
160
+ debug(field);
161
+ const id = field.value ? field.value : '';
162
+ records.push({record: marcRecord, id});
163
+ } catch (error) {
164
+ debug(`Sru => record error: ${error}`);
165
+ debug(`Sru => record: ${record}`);
166
+ }
160
167
  });
161
168
  });
162
169
  }