Skip to content

Commit

Permalink
Merge branch 'main' into db-tickets-without-ticket-url
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulSut authored Feb 18, 2024
2 parents 5693112 + 66d9fb5 commit 5b42626
Show file tree
Hide file tree
Showing 258 changed files with 19,628 additions and 11,120 deletions.
30 changes: 24 additions & 6 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,43 @@
"es2021": true,
"node": true
},
"extends": "eslint:recommended",
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"extends": ["eslint:recommended", "plugin:@stylistic/all-extends"],
"ignorePatterns": ["node_modules", "*example.js"],
"parserOptions": {
"ecmaVersion": 2021,
"sourceType": "module"
},
"rules": {
"curly": "error",
"no-implicit-coercion": "error",
"no-unused-vars": [
"error",
{
"vars": "all",
"args": "none",
"ignoreRestSiblings": false
}
]
],
"@stylistic/array-bracket-newline": ["error", "consistent"],
"@stylistic/array-element-newline": ["error", "consistent"],
"@stylistic/arrow-parens": "off",
"@stylistic/comma-dangle": ["error", "always-multiline"],
"@stylistic/dot-location": ["error", "property"],
"@stylistic/function-call-argument-newline": ["error", "consistent"],
"@stylistic/function-paren-newline": "off",
"@stylistic/indent": ["error", "tab"],
"@stylistic/indent-binary-ops": ["error", "tab"],
"@stylistic/max-len": "off",
"@stylistic/multiline-ternary": ["error", "always-multiline"],
"@stylistic/newline-per-chained-call": ["error", { "ignoreChainWithDepth": 1 }],
"@stylistic/no-mixed-operators": "off",
"@stylistic/no-tabs": "off",
"@stylistic/object-property-newline": "off",
"@stylistic/one-var-declaration-per-line": "off",
"@stylistic/operator-linebreak": ["error", "before"],
"@stylistic/padded-blocks": "off",
"@stylistic/quote-props": ["error", "consistent-as-needed"],
"@stylistic/quotes": ["error", "single"]
},
"overrides": [
{
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ jobs:
node-version: [16.x, 18.x, 20.x]
steps:
- name: checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: setup Node.js v${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

Expand All @@ -37,9 +37,9 @@ jobs:
node-version: [16.x, 18.x, 20.x]
steps:
- name: checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: setup Node.js v${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

Expand All @@ -62,9 +62,9 @@ jobs:
node-version: [16.x]
steps:
- name: checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: setup Node.js v${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ node_modules
npm-debug.log

package-lock.json

/.tap
9 changes: 1 addition & 8 deletions contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,4 @@ Thanks for helping! 🙏

## Adding integration/end-to-end tests

The [end-to-end/system tests](https://en.wikipedia.org/wiki/System_testing) in [`test/e2e`](test/e2e), executing via `npm run test-e2e`, are querying real HAFAS endpoints, expecting valid & *reasonable* responses.

The [integration tests](https://en.wikipedia.org/wiki/Integration_testing) (`npm run test-integration`) are the same `test/e2e` tests, running against *mocked* HAFAS responses from [`test/e2e/fixtures`](test/e2e/fixtures).

1. Add a new end-to-end test that tests your feature/bugfix.
2. Make sure the test passes. You can run your test exclusively using `test.only`.
3. Record the HAFAS responses as [fixtures](https://en.wikipedia.org/wiki/Test_fixture) using `npm run test-integration:record`.
4. Make sure the passes against *only* mocked responses using `npm run test-integration`.
Refer to the [testing docs](docs/tests.md).
15 changes: 15 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# Changelog

## `6.2.1`

- 8520eb3d [*mobil.nrw* profile](../p/mobil-nrw): fix `mode` for `ec-ic` product 🐛
- f29ced5b handle `PROBLEMS` HAFAS error code

[🏷 `6.2.1`](https://github.com/public-transport/hafas-client/releases/tag/6.2.1), 2024-01-18

## `6.2.0`

- 244e88de add attribute `additional` to additional stopovers ✅
- 02c781b1 `cross-fetch@4`, `p-retry@6`
- ecc8fccc `tap@18`

[🏷 `6.2.0`](https://github.com/public-transport/hafas-client/releases/tag/6.2.0), 2023-11-27

## `6.1.1`

- 45610fc9 [*IVB* profile](../p/ivb): update SSL CA certificate chain 🐛
Expand Down
18 changes: 9 additions & 9 deletions docs/profile-boilerplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@ const products = [
bitmasks: [16],
name: 'ACME Commuter Rail',
short: 'CR',
default: true
default: true,
},
{
id: 'metro',
mode: 'train',
bitmasks: [8],
name: 'Foo Bar Metro',
short: 'M',
default: true
}
]
default: true,
},
];

const transformReqBody = (body) => {
// get these from the recorded app requests
// body.client = { … }
// body.ver = …
// body.auth = { … }
// body.lang = …
return body
}
return body;
};

const insaProfile = {
// locale: …,
Expand All @@ -37,9 +37,9 @@ const insaProfile = {
products: products,

trip: false,
radar: false
}
radar: false,
};

export {
insaProfile,
}
};
20 changes: 11 additions & 9 deletions format/address.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
import {formatLocationIdentifier} from './location-identifier.js'
import {formatCoord} from './coord.js'
import {formatLocationIdentifier} from './location-identifier.js';
import {formatCoord} from './coord.js';

const formatAddress = (a) => {
if (a.type !== 'location' || !a.latitude || !a.longitude || !a.address) {
throw new TypeError('invalid address')
throw new TypeError('invalid address');
}

const data = {
A: '2', // address?
O: a.address,
X: formatCoord(a.longitude),
Y: formatCoord(a.latitude)
Y: formatCoord(a.latitude),
};
if (a.id) {
data.L = a.id;
}
if (a.id) data.L = a.id
return {
type: 'A', // address
name: a.address,
lid: formatLocationIdentifier(data)
}
}
lid: formatLocationIdentifier(data),
};
};

export {
formatAddress,
}
};
4 changes: 2 additions & 2 deletions format/coord.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const formatCoord = x => Math.round(x * 1000000)
const formatCoord = x => Math.round(x * 1000000);

export {
formatCoord,
}
};
29 changes: 16 additions & 13 deletions format/date.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
import {DateTime, IANAZone} from 'luxon'
import {luxonIANAZonesByProfile as timezones} from '../lib/luxon-timezones.js'
import {DateTime, IANAZone} from 'luxon';
import {luxonIANAZonesByProfile as timezones} from '../lib/luxon-timezones.js';

// todo: change to `(profile) => (when) => {}`
const formatDate = (profile, when) => {
let timezone
if (timezones.has(profile)) timezone = timezones.get(profile)
else {
timezone = new IANAZone(profile.timezone)
timezones.set(profile, timezone)
let timezone;
if (timezones.has(profile)) {
timezone = timezones.get(profile);
} else {
timezone = new IANAZone(profile.timezone);
timezones.set(profile, timezone);
}

return DateTime.fromMillis(+when, {
locale: profile.locale,
zone: timezone
}).toFormat('yyyyMMdd')
}
return DateTime
.fromMillis(Number(when), {
locale: profile.locale,
zone: timezone,
})
.toFormat('yyyyMMdd');
};

export {
formatDate,
}
};
8 changes: 4 additions & 4 deletions format/filters.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const bike = {type: 'BC', mode: 'INC'}
const bike = {type: 'BC', mode: 'INC'};

const accessibility = {
none: {type: 'META', mode: 'INC', meta: 'notBarrierfree'},
partial: {type: 'META', mode: 'INC', meta: 'limitedBarrierfree'},
complete: {type: 'META', mode: 'INC', meta: 'completeBarrierfree'}
}
complete: {type: 'META', mode: 'INC', meta: 'completeBarrierfree'},
};

export {
bike,
accessibility,
}
};
8 changes: 4 additions & 4 deletions format/lines-req.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ const formatLinesReq = (ctx, query) => {
meth: 'LineMatch',
req: {
input: query,
}
}
}
},
};
};

export {
formatLinesReq,
}
};
14 changes: 10 additions & 4 deletions format/location-filter.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
const formatLocationFilter = (stops, addresses, poi) => {
if (stops && addresses && poi) return 'ALL'
return (stops ? 'S' : '') + (addresses ? 'A' : '') + (poi ? 'P' : '')
}
if (stops && addresses && poi) {
return 'ALL';
}
return (
(stops ? 'S' : '')
+ (addresses ? 'A' : '')
+ (poi ? 'P' : '')
);
};

export {
formatLocationFilter,
}
};
16 changes: 9 additions & 7 deletions format/location-identifier.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
const sep = '@'
const sep = '@';

const formatLocationIdentifier = (data) => {
let str = ''
let str = '';
for (let key in data) {
if (!Object.prototype.hasOwnProperty.call(data, key)) continue
if (!Object.prototype.hasOwnProperty.call(data, key)) {
continue;
}

str += key + '=' + data[key] + sep // todo: escape, but how?
str += key + '=' + data[key] + sep; // todo: escape, but how?
}

return str
}
return str;
};

export {
formatLocationIdentifier,
}
};
26 changes: 17 additions & 9 deletions format/location.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
const formatLocation = (profile, l, name = 'location') => {
if ('string' === typeof l) return profile.formatStation(l)
if ('string' === typeof l) {
return profile.formatStation(l);
}
if ('object' === typeof l && !Array.isArray(l)) {
if (l.type === 'station' || l.type === 'stop') {
return profile.formatStation(l.id)
return profile.formatStation(l.id);
}
if (l.poi) {
return profile.formatPoi(l);
}
if ('string' === typeof l.address) {
return profile.formatAddress(l);
}
if (!l.type) {
throw new TypeError(`missing ${name}.type`);
}
if (l.poi) return profile.formatPoi(l)
if ('string' === typeof l.address) return profile.formatAddress(l)
if (!l.type) throw new TypeError(`missing ${name}.type`)
throw new TypeError(`invalid ${name}.type: ${l.type}`)
throw new TypeError(`invalid ${name}.type: ${l.type}`);
}
throw new TypeError(name + ': valid station, address or poi required.')
}
throw new TypeError(name + ': valid station, address or poi required.');
};

export {
formatLocation,
}
};
16 changes: 9 additions & 7 deletions format/locations-req.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
const formatLocationsReq = (ctx, query) => {
const {profile, opt} = ctx
const {profile, opt} = ctx;

return {
cfg: {polyEnc: 'GPA'},
meth: 'LocMatch',
req: {input: {
loc: {
type: profile.formatLocationFilter(opt.stops, opt.addresses, opt.poi),
name: opt.fuzzy ? query + '?' : query
name: opt.fuzzy
? query + '?'
: query,
},
maxLoc: opt.results,
field: 'S' // todo: what is this?
}}
}
}
field: 'S', // todo: what is this?
}},
};
};

export {
formatLocationsReq,
}
};
Loading

0 comments on commit 5b42626

Please sign in to comment.