This commit is contained in:
Traines 2025-01-11 20:56:08 +00:00
parent 01b95e74f4
commit 977da80885
4 changed files with 23 additions and 49 deletions

View file

@ -1,23 +0,0 @@
import objectScan from 'object-scan';
const createFindInTree = (needles) => {
const scanner = objectScan(needles, {
filterFn: ({value, parents, matchedBy, context}) => {
matchedBy.forEach((needle) => {
context[needle].push([value, parents]);
});
},
});
return (haystack) => {
const context = Object.create(null);
needles.forEach((needle) => {
context[needle] = [];
});
return scanner(haystack, context);
};
};
export {
createFindInTree,
};

30
package-lock.json generated
View file

@ -1,28 +1,22 @@
{ {
"name": "db-vendo-client", "name": "db-vendo-client",
"version": "6.3.1", "version": "6.3.2",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "db-vendo-client", "name": "db-vendo-client",
"version": "6.3.1", "version": "6.3.2",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"@derhuerst/br2nl": "^1.0.0",
"@derhuerst/round-robin-scheduler": "^1.0.4", "@derhuerst/round-robin-scheduler": "^1.0.4",
"content-type": "^1.0.4", "content-type": "^1.0.4",
"create-hash": "^1.2.0",
"cross-fetch": "^4.0.0", "cross-fetch": "^4.0.0",
"db-hafas-stations": "^1.0.0", "db-hafas-stations": "^1.0.0",
"google-polyline": "^1.0.3",
"gps-distance": "0.0.4", "gps-distance": "0.0.4",
"https-proxy-agent": "^7.0.0", "https-proxy-agent": "^7.0.0",
"lodash": "^4.17.5", "lodash": "^4.17.5",
"luxon": "^3.1.1", "luxon": "^3.1.1",
"object-scan": "^19.0.5",
"p-retry": "^6.0.0",
"p-throttle": "^5.0.0",
"qs": "^6.6.0", "qs": "^6.6.0",
"slugg": "^1.2.0" "slugg": "^1.2.0"
}, },
@ -36,6 +30,8 @@
"hafas-rest-api": "^5.1.3", "hafas-rest-api": "^5.1.3",
"is-coordinates": "^2.0.2", "is-coordinates": "^2.0.2",
"is-roughly-equal": "^0.1.0", "is-roughly-equal": "^0.1.0",
"p-retry": "^6.0.0",
"p-throttle": "^5.0.0",
"tap": "^19.2.5", "tap": "^19.2.5",
"validate-fptf": "^3.0.0" "validate-fptf": "^3.0.0"
}, },
@ -111,6 +107,7 @@
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/@derhuerst/br2nl/-/br2nl-1.0.0.tgz", "resolved": "https://registry.npmjs.org/@derhuerst/br2nl/-/br2nl-1.0.0.tgz",
"integrity": "sha512-aGzqSMKM9eqHd9orDSe7yOvekRM9EMt9Jbc9vAG+a3jbn50WOTThVQX20c75yk0WBmu+6A5hdHGRM49dlp0I9w==", "integrity": "sha512-aGzqSMKM9eqHd9orDSe7yOvekRM9EMt9Jbc9vAG+a3jbn50WOTThVQX20c75yk0WBmu+6A5hdHGRM49dlp0I9w==",
"dev": true,
"engines": { "engines": {
"node": ">=6" "node": ">=6"
} }
@ -1741,7 +1738,8 @@
"node_modules/@types/retry": { "node_modules/@types/retry": {
"version": "0.12.2", "version": "0.12.2",
"resolved": "https://registry.npmjs.org/@types/retry/-/retry-0.12.2.tgz", "resolved": "https://registry.npmjs.org/@types/retry/-/retry-0.12.2.tgz",
"integrity": "sha512-XISRgDJ2Tc5q4TRqvgJtzsRkFYNJzZrhTdtMoGVBttwzzQJkPnS3WWTFc7kuDRoPtPakl+T+OfdEUjYJj7Jbow==" "integrity": "sha512-XISRgDJ2Tc5q4TRqvgJtzsRkFYNJzZrhTdtMoGVBttwzzQJkPnS3WWTFc7kuDRoPtPakl+T+OfdEUjYJj7Jbow==",
"dev": true
}, },
"node_modules/@types/semver": { "node_modules/@types/semver": {
"version": "7.5.8", "version": "7.5.8",
@ -2529,6 +2527,7 @@
"version": "1.0.6", "version": "1.0.6",
"resolved": "https://registry.npmjs.org/cipher-base/-/cipher-base-1.0.6.tgz", "resolved": "https://registry.npmjs.org/cipher-base/-/cipher-base-1.0.6.tgz",
"integrity": "sha512-3Ek9H3X6pj5TgenXYtNWdaBon1tgYCaebd+XPg0keyjEbEfkD4KkmAxkQ/i1vYvxdcT5nscLBfq9VJRmCBcFSw==", "integrity": "sha512-3Ek9H3X6pj5TgenXYtNWdaBon1tgYCaebd+XPg0keyjEbEfkD4KkmAxkQ/i1vYvxdcT5nscLBfq9VJRmCBcFSw==",
"dev": true,
"dependencies": { "dependencies": {
"inherits": "^2.0.4", "inherits": "^2.0.4",
"safe-buffer": "^5.2.1" "safe-buffer": "^5.2.1"
@ -2855,6 +2854,7 @@
"version": "1.2.0", "version": "1.2.0",
"resolved": "https://registry.npmjs.org/create-hash/-/create-hash-1.2.0.tgz", "resolved": "https://registry.npmjs.org/create-hash/-/create-hash-1.2.0.tgz",
"integrity": "sha512-z00bCGNHDG8mHAkP7CtT1qVu+bFQUPjYq/4Iv3C3kWjTFV10zIjfSoeqXo9Asws8gwSHDGj/hl2u4OGIjapeCg==", "integrity": "sha512-z00bCGNHDG8mHAkP7CtT1qVu+bFQUPjYq/4Iv3C3kWjTFV10zIjfSoeqXo9Asws8gwSHDGj/hl2u4OGIjapeCg==",
"dev": true,
"dependencies": { "dependencies": {
"cipher-base": "^1.0.1", "cipher-base": "^1.0.1",
"inherits": "^2.0.1", "inherits": "^2.0.1",
@ -3887,7 +3887,8 @@
"node_modules/google-polyline": { "node_modules/google-polyline": {
"version": "1.0.3", "version": "1.0.3",
"resolved": "https://registry.npmjs.org/google-polyline/-/google-polyline-1.0.3.tgz", "resolved": "https://registry.npmjs.org/google-polyline/-/google-polyline-1.0.3.tgz",
"integrity": "sha512-36BnqVxmVcR8lTvzO6aeXdICNChAwQLlfMkR1P9IBpTWE8hA6bAbQHCVArwMHB5WIMq9owywtAkjioe3crNq4Q==" "integrity": "sha512-36BnqVxmVcR8lTvzO6aeXdICNChAwQLlfMkR1P9IBpTWE8hA6bAbQHCVArwMHB5WIMq9owywtAkjioe3crNq4Q==",
"dev": true
}, },
"node_modules/gopd": { "node_modules/gopd": {
"version": "1.2.0", "version": "1.2.0",
@ -4039,6 +4040,7 @@
"version": "3.1.0", "version": "3.1.0",
"resolved": "https://registry.npmjs.org/hash-base/-/hash-base-3.1.0.tgz", "resolved": "https://registry.npmjs.org/hash-base/-/hash-base-3.1.0.tgz",
"integrity": "sha512-1nmYp/rhMDiE7AYkDw+lLwlAzz0AntGIe51F3RfFfEqyQ3feY2eI/NcwC6umIQVOASPMsWJLJScWKSSvzL9IVA==", "integrity": "sha512-1nmYp/rhMDiE7AYkDw+lLwlAzz0AntGIe51F3RfFfEqyQ3feY2eI/NcwC6umIQVOASPMsWJLJScWKSSvzL9IVA==",
"dev": true,
"dependencies": { "dependencies": {
"inherits": "^2.0.4", "inherits": "^2.0.4",
"readable-stream": "^3.6.0", "readable-stream": "^3.6.0",
@ -4512,6 +4514,7 @@
"version": "1.1.0", "version": "1.1.0",
"resolved": "https://registry.npmjs.org/is-network-error/-/is-network-error-1.1.0.tgz", "resolved": "https://registry.npmjs.org/is-network-error/-/is-network-error-1.1.0.tgz",
"integrity": "sha512-tUdRRAnhT+OtCZR/LxZelH/C7QtjtFrTu5tXCA8pl55eTUElUHT+GPYV8MBMBvea/j+NxQqVt3LbWMRir7Gx9g==", "integrity": "sha512-tUdRRAnhT+OtCZR/LxZelH/C7QtjtFrTu5tXCA8pl55eTUElUHT+GPYV8MBMBvea/j+NxQqVt3LbWMRir7Gx9g==",
"dev": true,
"engines": { "engines": {
"node": ">=16" "node": ">=16"
}, },
@ -4911,6 +4914,7 @@
"version": "1.3.5", "version": "1.3.5",
"resolved": "https://registry.npmjs.org/md5.js/-/md5.js-1.3.5.tgz", "resolved": "https://registry.npmjs.org/md5.js/-/md5.js-1.3.5.tgz",
"integrity": "sha512-xitP+WxNPcTTOgnTJcrhM0xvdPepipPSf3I8EIpGKeFLjt3PlJLIDG3u8EX53ZIubkb+5U2+3rELYpEhHhzdkg==", "integrity": "sha512-xitP+WxNPcTTOgnTJcrhM0xvdPepipPSf3I8EIpGKeFLjt3PlJLIDG3u8EX53ZIubkb+5U2+3rELYpEhHhzdkg==",
"dev": true,
"dependencies": { "dependencies": {
"hash-base": "^3.0.0", "hash-base": "^3.0.0",
"inherits": "^2.0.1", "inherits": "^2.0.1",
@ -5642,6 +5646,7 @@
"version": "19.0.5", "version": "19.0.5",
"resolved": "https://registry.npmjs.org/object-scan/-/object-scan-19.0.5.tgz", "resolved": "https://registry.npmjs.org/object-scan/-/object-scan-19.0.5.tgz",
"integrity": "sha512-5rr03NDQJ3oW4gWamHxON45ZLoFe6VCsRJ+trMlYWXlnYTGsuX/eD6MPp9yItzqFhd0pUpgzPm0jrYoeubIsIA==", "integrity": "sha512-5rr03NDQJ3oW4gWamHxON45ZLoFe6VCsRJ+trMlYWXlnYTGsuX/eD6MPp9yItzqFhd0pUpgzPm0jrYoeubIsIA==",
"dev": true,
"engines": { "engines": {
"node": ">= 16" "node": ">= 16"
} }
@ -5775,6 +5780,7 @@
"version": "6.2.1", "version": "6.2.1",
"resolved": "https://registry.npmjs.org/p-retry/-/p-retry-6.2.1.tgz", "resolved": "https://registry.npmjs.org/p-retry/-/p-retry-6.2.1.tgz",
"integrity": "sha512-hEt02O4hUct5wtwg4H4KcWgDdm+l1bOaEy/hWzd8xtXB9BqxTWBBhb+2ImAtH4Cv4rPjV76xN3Zumqk3k3AhhQ==", "integrity": "sha512-hEt02O4hUct5wtwg4H4KcWgDdm+l1bOaEy/hWzd8xtXB9BqxTWBBhb+2ImAtH4Cv4rPjV76xN3Zumqk3k3AhhQ==",
"dev": true,
"dependencies": { "dependencies": {
"@types/retry": "0.12.2", "@types/retry": "0.12.2",
"is-network-error": "^1.0.0", "is-network-error": "^1.0.0",
@ -5791,6 +5797,7 @@
"version": "5.1.0", "version": "5.1.0",
"resolved": "https://registry.npmjs.org/p-throttle/-/p-throttle-5.1.0.tgz", "resolved": "https://registry.npmjs.org/p-throttle/-/p-throttle-5.1.0.tgz",
"integrity": "sha512-+N+s2g01w1Zch4D0K3OpnPDqLOKmLcQ4BvIFq3JC0K29R28vUOjWpO+OJZBNt8X9i3pFCksZJZ0YXkUGjaFE6g==", "integrity": "sha512-+N+s2g01w1Zch4D0K3OpnPDqLOKmLcQ4BvIFq3JC0K29R28vUOjWpO+OJZBNt8X9i3pFCksZJZ0YXkUGjaFE6g==",
"dev": true,
"engines": { "engines": {
"node": "^12.20.0 || ^14.13.1 || >=16.0.0" "node": "^12.20.0 || ^14.13.1 || >=16.0.0"
}, },
@ -6586,6 +6593,7 @@
"version": "0.13.1", "version": "0.13.1",
"resolved": "https://registry.npmjs.org/retry/-/retry-0.13.1.tgz", "resolved": "https://registry.npmjs.org/retry/-/retry-0.13.1.tgz",
"integrity": "sha512-XQBQ3I8W1Cge0Seh+6gjj03LbmRFWuoszgK9ooCpwYIrhhoO80pfq4cUkU5DkknwfOfFteRwlZ56PYOGYyFWdg==", "integrity": "sha512-XQBQ3I8W1Cge0Seh+6gjj03LbmRFWuoszgK9ooCpwYIrhhoO80pfq4cUkU5DkknwfOfFteRwlZ56PYOGYyFWdg==",
"dev": true,
"engines": { "engines": {
"node": ">= 4" "node": ">= 4"
} }
@ -6620,6 +6628,7 @@
"version": "2.0.2", "version": "2.0.2",
"resolved": "https://registry.npmjs.org/ripemd160/-/ripemd160-2.0.2.tgz", "resolved": "https://registry.npmjs.org/ripemd160/-/ripemd160-2.0.2.tgz",
"integrity": "sha512-ii4iagi25WusVoiC4B4lq7pbXfAp3D9v5CwfkY33vffw2+pkDjY1D8GaN7spsxvCSx8dkPqOZCEZyfxcmJG2IA==", "integrity": "sha512-ii4iagi25WusVoiC4B4lq7pbXfAp3D9v5CwfkY33vffw2+pkDjY1D8GaN7spsxvCSx8dkPqOZCEZyfxcmJG2IA==",
"dev": true,
"dependencies": { "dependencies": {
"hash-base": "^3.0.0", "hash-base": "^3.0.0",
"inherits": "^2.0.1" "inherits": "^2.0.1"
@ -6819,6 +6828,7 @@
"version": "2.4.11", "version": "2.4.11",
"resolved": "https://registry.npmjs.org/sha.js/-/sha.js-2.4.11.tgz", "resolved": "https://registry.npmjs.org/sha.js/-/sha.js-2.4.11.tgz",
"integrity": "sha512-QMEp5B7cftE7APOjk5Y6xgrbWu+WkLVQwk8JNjZ8nKRciZaByEW6MubieAiToS7+dwvrjGhH8jRXz3MVd0AYqQ==", "integrity": "sha512-QMEp5B7cftE7APOjk5Y6xgrbWu+WkLVQwk8JNjZ8nKRciZaByEW6MubieAiToS7+dwvrjGhH8jRXz3MVd0AYqQ==",
"dev": true,
"dependencies": { "dependencies": {
"inherits": "^2.0.1", "inherits": "^2.0.1",
"safe-buffer": "^5.0.1" "safe-buffer": "^5.0.1"

View file

@ -1,7 +1,7 @@
{ {
"name": "db-vendo-client", "name": "db-vendo-client",
"description": "Client for bahn.de public transport APIs.", "description": "Client for bahn.de public transport APIs.",
"version": "6.3.1", "version": "6.3.2",
"type": "module", "type": "module",
"main": "index.js", "main": "index.js",
"files": [ "files": [
@ -56,20 +56,14 @@
"node": ">=16" "node": ">=16"
}, },
"dependencies": { "dependencies": {
"@derhuerst/br2nl": "^1.0.0",
"@derhuerst/round-robin-scheduler": "^1.0.4", "@derhuerst/round-robin-scheduler": "^1.0.4",
"content-type": "^1.0.4", "content-type": "^1.0.4",
"create-hash": "^1.2.0",
"cross-fetch": "^4.0.0", "cross-fetch": "^4.0.0",
"db-hafas-stations": "^1.0.0", "db-hafas-stations": "^1.0.0",
"google-polyline": "^1.0.3",
"gps-distance": "0.0.4", "gps-distance": "0.0.4",
"https-proxy-agent": "^7.0.0", "https-proxy-agent": "^7.0.0",
"lodash": "^4.17.5", "lodash": "^4.17.5",
"luxon": "^3.1.1", "luxon": "^3.1.1",
"object-scan": "^19.0.5",
"p-retry": "^6.0.0",
"p-throttle": "^5.0.0",
"qs": "^6.6.0", "qs": "^6.6.0",
"slugg": "^1.2.0" "slugg": "^1.2.0"
}, },
@ -83,6 +77,8 @@
"hafas-rest-api": "^5.1.3", "hafas-rest-api": "^5.1.3",
"is-coordinates": "^2.0.2", "is-coordinates": "^2.0.2",
"is-roughly-equal": "^0.1.0", "is-roughly-equal": "^0.1.0",
"p-retry": "^6.0.0",
"p-throttle": "^5.0.0",
"tap": "^19.2.5", "tap": "^19.2.5",
"validate-fptf": "^3.0.0" "validate-fptf": "^3.0.0"
}, },

View file

@ -4,24 +4,15 @@ import {createRequire} from 'module';
const require = createRequire(import.meta.url); const require = createRequire(import.meta.url);
import tap from 'tap'; import tap from 'tap';
import forEach from 'lodash/forEach.js';
import { import {
checkIfResponseIsOk as checkIfResIsOk, checkIfResponseIsOk as checkIfResIsOk,
request,
} from '../../lib/request.js'; } from '../../lib/request.js';
import { import {
INVALID_REQUEST,
NOT_FOUND,
HafasError, HafasError,
HafasInvalidRequestError,
HafasNotFoundError,
} from '../../lib/errors.js'; } from '../../lib/errors.js';
import {formatTripReq} from '../../format/trip-req.js';
const resNoMatch = {verbindungen: [], verbindungReference: {}, fehlerNachricht: {code: 'MDA-AK-MSG-1001', ueberschrift: 'Datum liegt außerhalb der Fahrplanperiode.', text: 'Das Datum liegt außerhalb der Fahrplanperiode.'}}; const resNoMatch = {verbindungen: [], verbindungReference: {}, fehlerNachricht: {code: 'MDA-AK-MSG-1001', ueberschrift: 'Datum liegt außerhalb der Fahrplanperiode.', text: 'Das Datum liegt außerhalb der Fahrplanperiode.'}};
const USER_AGENT = 'public-transport/hafas-client:test';
const secret = Symbol('secret'); const secret = Symbol('secret');
tap.test('checkIfResponseIsOk properly throws HAFAS errors', (t) => { tap.test('checkIfResponseIsOk properly throws HAFAS errors', (t) => {