From 36624b7a96cbb987ae0a9d5f498afe3c49d8472b Mon Sep 17 00:00:00 2001 From: Jannis R Date: Mon, 27 May 2019 16:53:18 +0200 Subject: [PATCH 1/5] transformResBody hook --- lib/default-profile.js | 1 + lib/request.js | 1 + 2 files changed, 2 insertions(+) diff --git a/lib/default-profile.js b/lib/default-profile.js index 1706e13f2..a4cf51b88 100644 --- a/lib/default-profile.js +++ b/lib/default-profile.js @@ -35,6 +35,7 @@ const defaultProfile = { transformReqBody: id, transformReq: id, + transformResBody: body => body, transformJourneysQuery: id, diff --git a/lib/request.js b/lib/request.js index bbb1f58af..e2d6386cc 100644 --- a/lib/request.js +++ b/lib/request.js @@ -100,6 +100,7 @@ const request = (profile, userAgent, opt, data) => { }) .then((b) => { if (DEBUG) console.error(JSON.stringify(b)) + b = profile.transformResBody(b) if (b.err && b.err !== 'OK') { addErrorInfo(err, b.err, b.errTxt) From 084e948fbe649473bb3828a2b85b81bdbffd6d50 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Mon, 27 May 2019 16:54:18 +0200 Subject: [PATCH 2/5] find-unknown-fields CI step closes #109 --- .travis.yml | 2 ++ find-unknown-fields/index.js | 37 ++++++++++++++++++++++++++++++++++++ package.json | 2 ++ 3 files changed, 41 insertions(+) create mode 100644 find-unknown-fields/index.js diff --git a/.travis.yml b/.travis.yml index 594a7057d..91fde0098 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,3 +5,5 @@ node_js: - 'lts/*' - '8' cache: npm +after_script: + - if [[ $TRAVIS_EVENT_TYPE == "cron" ]]; then npm run find-unknown-fields; fi diff --git a/find-unknown-fields/index.js b/find-unknown-fields/index.js new file mode 100644 index 000000000..49e795847 --- /dev/null +++ b/find-unknown-fields/index.js @@ -0,0 +1,37 @@ +'use strict' + +const Ajv = require('ajv') +const omit = require('lodash/omit') +const createClient = require('..') + +const tasks = [] + +const userAgent = 'hafas-client find-unknown-fields' +const fetchResponse = (profile, query) => { + return new Promise((resolve, reject) => { + query(createClient({ + ...profile, + transformResBody: (body) => { + resolve(body) + return body + } + }, userAgent)).catch(reject) + }) +} + +;(async () => { + const ajv = new Ajv({verbose: true, allErrors: true, strictKeywords: true}) + for await (const [profile, query, schema] of tasks) { + const validate = ajv.compile(schema) + const res = await fetchResponse(profile, query) + if (!validate(res)) { + for (const err of validate.errors) { + console.error('\n', omit(err, ['schema', 'parentSchema'])) + } + } + } +})() +.catch((err) => { + console.error(err) + process.exitCode = 1 +}) diff --git a/package.json b/package.json index 2c2bdfe31..972ba9a10 100644 --- a/package.json +++ b/package.json @@ -53,6 +53,7 @@ "vbb-translate-ids": "^3.1.0" }, "devDependencies": { + "ajv": "^6.10.0", "db-stations": "^2.3.0", "is-coordinates": "^2.0.2", "is-roughly-equal": "^0.1.0", @@ -64,6 +65,7 @@ }, "scripts": { "test": "env NODE_ENV=dev node test/index.js", + "find-unknown-fields": "node find-unknown-fields/index.js", "prepublishOnly": "npm test | tap-spec", "install": "node lib/generate-install-id.js >id.json" } From bbe9ac49b6f36cc53fe378b9e5f738ee51966aab Mon Sep 17 00:00:00 2001 From: Jannis R Date: Mon, 27 May 2019 17:19:11 +0200 Subject: [PATCH 3/5] find-unknown-fields: basic journeys() schema, VBB & DB queries --- find-unknown-fields/index.js | 34 +- find-unknown-fields/journeys.schema.json | 1481 ++++++++++++++++++++++ 2 files changed, 1514 insertions(+), 1 deletion(-) create mode 100644 find-unknown-fields/journeys.schema.json diff --git a/find-unknown-fields/index.js b/find-unknown-fields/index.js index 49e795847..a56677692 100644 --- a/find-unknown-fields/index.js +++ b/find-unknown-fields/index.js @@ -3,8 +3,40 @@ const Ajv = require('ajv') const omit = require('lodash/omit') const createClient = require('..') +const vbbProfile = require('../p/vbb') +const bvgProfile = require('../p/bvg') +const dbProfile = require('../p/db') +const journeysSchema = require('./journeys.schema.json') +// todo: https://github.com/epoberezkin/ajv#formats +// todo: https://github.com/epoberezkin/ajv#combining-schemas-with-ref -const tasks = [] +const fetchJourneys = (from, to) => (client) => { + return client.journeys(from, to, { + results: 3, tickets: true, stopovers: true, remarks: true, polylines: true + }) +} +const tasks = [ + [ + vbbProfile, + fetchJourneys('900000175013', '900000087171'), // Risaer Str. to TXL + journeysSchema + ], + [ + bvgProfile, + fetchJourneys('900000175013', '900000087171'), // Risaer Str. to TXL + journeysSchema + ], + [ + dbProfile, + // Siegessäule Berlin to München Hbf + c => c.journeys({ + type: 'location', id: '991668043', poi: true, + name: 'Berlin, Siegessäule (Tourismus)', + latitude: 52.515189, longitude: 13.350123 + }, '8000261', journeysOpts), + journeysSchema + ] +] const userAgent = 'hafas-client find-unknown-fields' const fetchResponse = (profile, query) => { diff --git a/find-unknown-fields/journeys.schema.json b/find-unknown-fields/journeys.schema.json new file mode 100644 index 000000000..7790ec46c --- /dev/null +++ b/find-unknown-fields/journeys.schema.json @@ -0,0 +1,1481 @@ +{ + "title": "journeys response", + "type": "object", + "properties": { + "ver": { + "type": "string" + }, + "ext": { + "type": "string" + }, + "lang": { + "type": "string" + }, + "id": { + "type": "string" + }, + "svcResL": { + "type": "array", + "items": { + "type": "object", + "properties": { + "meth": { + "type": "string" + }, + "err": { + "type": "string" + }, + "res": { + "type": "object", + "properties": { + "common": { + "type": "object", + "properties": { + "locL": { + "type": "array", + "items": { + "type": "object", + "properties": { + "lid": { + "type": "string" + }, + "type": { + "type": "string" + }, + "name": { + "type": "string" + }, + "icoX": { + "type": "number" + }, + "extId": { + "type": "string" + }, + "state": { + "type": "string" + }, + "crd": { + "type": "object", + "properties": { + "x": { + "type": "number" + }, + "y": { + "type": "number" + }, + "type": { + "type": "string" + }, + "layerX": { + "type": "number" + }, + "crdSysX": { + "type": "number" + }, + "z": { + "type": "number" + } + } + }, + "pCls": { + "type": "number" + }, + "mMastLocX": { + "type": "number" + }, + "entry": { + "type": "boolean" + } + }, + "required": [ + "lid", + "type", + "name", + "icoX", + "extId", + "state", + "crd", + "pCls", + "mMastLocX", + "entry" + ] + } + }, + "prodL": { + "type": "array", + "items": { + "type": "object", + "properties": { + "pid": { + "type": "string" + }, + "name": { + "type": "string" + }, + "nameS": { + "type": "string" + }, + "number": { + "type": "string" + }, + "icoX": { + "type": "number" + }, + "cls": { + "type": "number" + }, + "oprX": { + "type": "number" + }, + "prodCtx": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "num": { + "type": "string" + }, + "line": { + "type": "string" + }, + "matchId": { + "type": "string" + }, + "catOut": { + "type": "string" + }, + "catOutS": { + "type": "string" + }, + "catOutL": { + "type": "string" + }, + "catIn": { + "type": "string" + }, + "catCode": { + "type": "string" + }, + "admin": { + "type": "string" + } + } + }, + "himIdL": { + "type": "array", + "items": { + "type": "string" + } + } + }, + "required": [ + "pid", + "name", + "nameS", + "number", + "icoX", + "cls", + "oprX", + "prodCtx", + "himIdL" + ] + } + }, + "polyL": { + "type": "array", + "items": { + "type": "object", + "properties": { + "delta": { + "type": "boolean" + }, + "dim": { + "type": "number" + }, + "type": { + "type": "string" + }, + "crdEncYX": { + "type": "string" + }, + "crdEncS": { + "type": "string" + }, + "crdEncF": { + "type": "string" + }, + "ppLocRefL": { + "type": "array", + "items": { + "type": "object", + "properties": { + "ppIdx": { + "type": "number" + }, + "locX": { + "type": "number" + } + }, + "required": [ + "ppIdx", + "locX" + ] + } + }, + "crdEncZ": { + "type": "string" + } + }, + "required": [ + "delta", + "dim", + "type", + "crdEncYX", + "crdEncS", + "crdEncF", + "ppLocRefL", + "crdEncZ" + ] + } + }, + "layerL": { + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "name": { + "type": "string" + }, + "index": { + "type": "number" + }, + "annoCnt": { + "type": "number" + } + }, + "required": [ + "id", + "name", + "index", + "annoCnt" + ] + } + }, + "crdSysL": { + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "index": { + "type": "number" + }, + "type": { + "type": "string" + }, + "dim": { + "type": "number" + } + }, + "required": [ + "id", + "index", + "type", + "dim" + ] + } + }, + "opL": { + "type": "array", + "items": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "icoX": { + "type": "number" + }, + "id": { + "type": "string" + } + }, + "required": [ + "name", + "icoX", + "id" + ] + } + }, + "remL": { + "type": "array", + "items": { + "type": "object", + "properties": { + "type": { + "type": "string" + }, + "code": { + "type": "string" + }, + "prio": { + "type": "number" + }, + "icoX": { + "type": "number" + }, + "txtN": { + "type": "string" + }, + "sIdx": { + "type": "number" + } + }, + "required": [ + "type", + "code", + "prio", + "icoX", + "txtN" + ] + } + }, + "himL": { + "type": "array", + "items": { + "type": "object", + "properties": { + "hid": { + "type": "string" + }, + "act": { + "type": "boolean" + }, + "pub": { + "type": "string" + }, + "head": { + "type": "string" + }, + "lead": { + "type": "string" + }, + "text": { + "type": "string" + }, + "tckr": { + "type": "string" + }, + "icoX": { + "type": "number" + }, + "prio": { + "type": "number" + }, + "fLocX": { + "type": "number" + }, + "prod": { + "type": "number" + }, + "lModDate": { + "type": "string" + }, + "lModTime": { + "type": "string" + }, + "sDate": { + "type": "string" + }, + "sTime": { + "type": "string" + }, + "eDate": { + "type": "string" + }, + "eTime": { + "type": "string" + }, + "comp": { + "type": "string" + }, + "cat": { + "type": "number" + }, + "pubChL": { + "type": "array", + "items": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "fDate": { + "type": "string" + }, + "fTime": { + "type": "string" + }, + "tDate": { + "type": "string" + }, + "tTime": { + "type": "string" + } + }, + "required": [ + "name", + "fDate", + "fTime", + "tDate", + "tTime" + ] + } + } + }, + "required": [ + "hid", + "act", + "pub", + "head", + "lead", + "text", + "tckr", + "icoX", + "prio", + "fLocX", + "prod", + "lModDate", + "lModTime", + "sDate", + "sTime", + "eDate", + "eTime", + "comp", + "cat", + "pubChL" + ] + } + }, + "icoL": { + "type": "array", + "items": { + "type": "object", + "properties": { + "res": { + "type": "string" + }, + "fg": { + "type": "object", + "properties": { + "r": { + "type": "number" + }, + "g": { + "type": "number" + }, + "b": { + "type": "number" + }, + "a": { + "type": "number" + } + } + }, + "bg": { + "type": "object", + "properties": { + "r": { + "type": "number" + }, + "g": { + "type": "number" + }, + "b": { + "type": "number" + }, + "a": { + "type": "number" + } + } + }, + "txt": { + "type": "string" + } + }, + "required": [ + "res", + "fg", + "bg", + "txt" + ] + } + }, + "tcocL": { + "type": "array", + "items": { + "type": "object", + "properties": { + "c": { + "type": "string" + } + }, + "required": [ + "c" + ] + } + } + } + }, + "outConL": { + "type": "array", + "items": { + "type": "object", + "properties": { + "cid": { + "type": "string" + }, + "date": { + "type": "string" + }, + "dur": { + "type": "string" + }, + "chg": { + "type": "number" + }, + "sDays": { + "type": "object", + "properties": { + "sDaysR": { + "type": "string" + }, + "sDaysI": { + "type": "string" + }, + "sDaysB": { + "type": "string" + } + } + }, + "dep": { + "type": "object", + "properties": { + "locX": { + "type": "number" + }, + "idx": { + "type": "number" + }, + "dProdX": { + "type": "number" + }, + "dInR": { + "type": "boolean" + }, + "dTimeS": { + "type": "string" + }, + "dTimeR": { + "type": "string" + }, + "dProgType": { + "type": "string" + }, + "type": { + "type": "string" + } + } + }, + "arr": { + "type": "object", + "properties": { + "locX": { + "type": "number" + }, + "idx": { + "type": "number" + }, + "aOutR": { + "type": "boolean" + }, + "aTimeS": { + "type": "string" + }, + "aProgType": { + "type": "string" + }, + "type": { + "type": "string" + }, + "aTimeR": { + "type": "string" + }, + "aProdX": { + "type": "number" + }, + "aPlatfS": { + "type": "string" + }, + "aTZOffset": { + "type": "number" + } + } + }, + "secL": { + "type": "array", + "items": { + "type": "object", + "properties": { + "type": { + "type": "string" + }, + "icoX": { + "type": "number" + }, + "dep": { + "type": "object", + "properties": { + "locX": { + "type": "number" + }, + "idx": { + "type": "number" + }, + "dProdX": { + "type": "number" + }, + "dInR": { + "type": "boolean" + }, + "dTimeS": { + "type": "string" + }, + "dTimeR": { + "type": "string" + }, + "dProgType": { + "type": "string" + }, + "type": { + "type": "string" + }, + "dPlatfS": { + "type": "string" + }, + "dPlatfR": { + "type": "string" + }, + "dCncl": { + "type": "boolean" + }, + "msgL": { + "type": "array", + "items": { + "type": "object", + "properties": { + "type": { + "type": "string" + }, + "remX": { + "type": "number" + }, + "tagL": { + "type": "array", + "items": { + "type": "string" + } + }, + "txtC": { + "type": "object", + "properties": { + "r": { + "type": "number" + }, + "g": { + "type": "number" + }, + "b": { + "type": "number" + }, + "a": { + "type": "number" + } + } + }, + "prio": { + "type": "number" + }, + "fIdx": { + "type": "number" + }, + "tIdx": { + "type": "number" + } + }, + "required": [ + "type", + "remX", + "tagL" + ] + } + }, + "dTZOffset": { + "type": "number" + }, + "dTrnCmpSX": { + "type": "object", + "properties": { + "tcocX": { + "type": "array", + "items": { + "type": "number" + } + }, + "tcM": { + "type": "number" + } + } + } + } + }, + "arr": { + "type": "object", + "properties": { + "locX": { + "type": "number" + }, + "idx": { + "type": "number" + }, + "aOutR": { + "type": "boolean" + }, + "aTimeS": { + "type": "string" + }, + "aTimeR": { + "type": "string" + }, + "aProgType": { + "type": "string" + }, + "type": { + "type": "string" + }, + "aProdX": { + "type": "number" + }, + "aPlatfS": { + "type": "string" + }, + "aPlatfR": { + "type": "string" + }, + "aCncl": { + "type": "boolean" + }, + "msgL": { + "type": "array", + "items": { + "type": "object", + "properties": { + "type": { + "type": "string" + }, + "remX": { + "type": "number" + }, + "tagL": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + }, + "aTZOffset": { + "type": "number" + }, + "aTrnCmpSX": { + "type": "object", + "properties": { + "tcM": { + "type": "number" + } + } + } + } + }, + "jny": { + "type": "object", + "properties": { + "jid": { + "type": "string" + }, + "prodX": { + "type": "number" + }, + "dirTxt": { + "type": "string" + }, + "status": { + "type": "string" + }, + "isRchbl": { + "type": "boolean" + }, + "stopL": { + "type": "array", + "items": { + "type": "object", + "properties": { + "locX": { + "type": "number" + }, + "idx": { + "type": "number" + }, + "dProdX": { + "type": "number" + }, + "dInR": { + "type": "boolean" + }, + "dTimeS": { + "type": "string" + }, + "dTimeR": { + "type": "string" + }, + "dProgType": { + "type": "string" + }, + "dDirTxt": { + "type": "string" + }, + "dDirFlg": { + "type": "string" + }, + "type": { + "type": "string" + }, + "aProdX": { + "type": "number" + }, + "aOutR": { + "type": "boolean" + }, + "aTimeS": { + "type": "string" + }, + "aTimeR": { + "type": "string" + }, + "aProgType": { + "type": "string" + }, + "dCncl": { + "type": "boolean" + }, + "msgL": { + "type": "array", + "items": { + "type": "object", + "properties": { + "type": { + "type": "string" + }, + "remX": { + "type": "number" + }, + "tagL": { + "type": "array", + "items": { + "type": "string" + } + }, + "txtC": { + "type": "object", + "properties": { + "r": { + "type": "number" + }, + "g": { + "type": "number" + }, + "b": { + "type": "number" + }, + "a": { + "type": "number" + } + } + }, + "prio": { + "type": "number" + }, + "fIdx": { + "type": "number" + }, + "tIdx": { + "type": "number" + } + }, + "required": [ + "type", + "remX", + "tagL" + ] + } + }, + "aCncl": { + "type": "boolean" + }, + "dTZOffset": { + "type": "number" + }, + "aTZOffset": { + "type": "number" + }, + "dPlatfS": { + "type": "string" + }, + "aPlatfS": { + "type": "string" + }, + "dTrnCmpSX": { + "type": "object", + "properties": { + "tcocX": { + "type": "array", + "items": { + "type": "number" + } + } + } + } + }, + "required": [ + "locX", + "idx", + "dProdX", + "dInR", + "dTimeS", + "dTimeR", + "dProgType", + "type", + "aProdX", + "aOutR", + "aTimeS", + "aTimeR", + "aProgType", + "dDirTxt", + "dDirFlg", + "dCncl", + "msgL", + "aCncl", + "dTZOffset", + "aTZOffset", + "dPlatfS", + "aPlatfS", + "dTrnCmpSX" + ] + } + }, + "polyG": { + "type": "object", + "properties": { + "polyXL": { + "type": "array", + "items": { + "type": "number" + } + }, + "layerX": { + "type": "number" + }, + "crdSysX": { + "type": "number" + } + } + }, + "freq": { + "type": "object", + "properties": { + "minC": { + "type": "number" + }, + "maxC": { + "type": "number" + }, + "numC": { + "type": "number" + }, + "jnyL": { + "type": "array", + "items": { + "type": "object", + "properties": { + "jid": { + "type": "string" + }, + "prodX": { + "type": "number" + }, + "dirTxt": { + "type": "string" + }, + "stopL": { + "type": "array", + "items": { + "type": "object", + "properties": { + "locX": { + "type": "number" + }, + "idx": { + "type": "number" + }, + "dProdX": { + "type": "number" + }, + "dTimeS": { + "type": "string" + }, + "dDirTxt": { + "type": "string" + }, + "dDirFlg": { + "type": "string" + }, + "type": { + "type": "string" + }, + "aProdX": { + "type": "number" + }, + "aTimeS": { + "type": "string" + } + }, + "required": [ + "locX", + "idx", + "type", + "dProdX", + "dTimeS", + "dDirTxt", + "dDirFlg", + "aProdX", + "aTimeS" + ] + } + }, + "ctxRecon": { + "type": "string" + }, + "msgL": { + "type": "array", + "items": { + "type": "object", + "properties": { + "type": { + "type": "string" + }, + "remX": { + "type": "number" + }, + "fLocX": { + "type": "number" + }, + "tLocX": { + "type": "number" + }, + "tagL": { + "type": "array", + "items": { + "type": "string" + } + } + }, + "required": [ + "type", + "remX", + "fLocX", + "tLocX", + "tagL" + ] + } + }, + "subscr": { + "type": "string" + } + }, + "required": [ + "jid", + "prodX", + "dirTxt", + "stopL", + "ctxRecon", + "msgL", + "subscr" + ] + } + } + } + }, + "ctxRecon": { + "type": "string" + }, + "msgL": { + "type": "array", + "items": { + "type": "object", + "properties": { + "type": { + "type": "string" + }, + "remX": { + "type": "number" + }, + "fLocX": { + "type": "number" + }, + "tLocX": { + "type": "number" + }, + "tagL": { + "type": "array", + "items": { + "type": "string" + } + }, + "himX": { + "type": "number" + }, + "fIdx": { + "type": "number" + }, + "tIdx": { + "type": "number" + } + }, + "required": [ + "type", + "remX", + "fLocX", + "tLocX", + "tagL", + "himX", + "fIdx", + "tIdx" + ] + } + }, + "subscr": { + "type": "string" + }, + "isCncl": { + "type": "boolean" + }, + "chgDurR": { + "type": "number" + } + } + }, + "minChg": { + "type": "string" + }, + "gis": { + "type": "object", + "properties": { + "dist": { + "type": "number" + }, + "durS": { + "type": "string" + }, + "ctx": { + "type": "string" + }, + "dirGeo": { + "type": "number" + }, + "polyG": { + "type": "object", + "properties": { + "polyXL": { + "type": "array", + "items": { + "type": "number" + } + }, + "layerX": { + "type": "number" + }, + "crdSysX": { + "type": "number" + } + } + }, + "gisPrvr": { + "type": "string" + } + } + }, + "resState": { + "type": "string" + }, + "resRecommendation": { + "type": "string" + }, + "hide": { + "type": "boolean" + } + }, + "required": [ + "type", + "icoX", + "dep", + "arr", + "jny", + "minChg", + "gis", + "resState", + "resRecommendation", + "hide" + ] + } + }, + "ctxRecon": { + "type": "string" + }, + "freq": { + "type": "object", + "properties": { + "minC": { + "type": "number" + } + } + }, + "conSubscr": { + "type": "string" + }, + "cksum": { + "type": "string" + }, + "isNotRdbl": { + "type": "boolean" + }, + "badSecRefX": { + "type": "number" + }, + "msgL": { + "type": "array", + "items": { + "type": "object", + "properties": { + "type": { + "type": "string" + }, + "remX": { + "type": "number" + }, + "tagL": { + "type": "array", + "items": { + "type": "string" + } + } + }, + "required": [ + "type", + "remX", + "tagL" + ] + } + }, + "trfRes": { + "type": "object", + "properties": { + "statusCode": { + "type": "string" + }, + "fareSetL": { + "type": "array", + "items": { + "type": "object", + "properties": { + "fareL": { + "type": "array", + "items": { + "type": "object", + "properties": { + "prc": { + "type": "number" + }, + "isFromPrice": { + "type": "boolean" + }, + "isBookable": { + "type": "boolean" + }, + "isUpsell": { + "type": "boolean" + }, + "targetCtx": { + "type": "string" + }, + "addHint": { + "type": "string" + }, + "buttonText": { + "type": "string" + } + }, + "required": [ + "prc", + "isFromPrice", + "isBookable", + "isUpsell", + "targetCtx", + "buttonText" + ] + } + } + }, + "required": [ + "fareL" + ] + } + } + } + }, + "resState": { + "type": "string" + }, + "resRecommendation": { + "type": "string" + }, + "recState": { + "type": "string" + }, + "sotRating": { + "type": "number" + }, + "isSotCon": { + "type": "boolean" + }, + "showARSLink": { + "type": "boolean" + }, + "sotCtxt": { + "type": "object", + "properties": { + "calcDate": { + "type": "string" + }, + "locMode": { + "type": "string" + }, + "reqMode": { + "type": "string" + }, + "calcTime": { + "type": "string" + } + } + } + }, + "required": [ + "cid", + "date", + "dur", + "chg", + "sDays", + "dep", + "arr", + "secL", + "ctxRecon", + "freq", + "conSubscr", + "cksum", + "isNotRdbl", + "badSecRefX", + "msgL", + "trfRes", + "resState", + "resRecommendation", + "recState", + "sotRating", + "isSotCon", + "showARSLink", + "sotCtxt" + ] + } + }, + "outCtxScrB": { + "type": "string" + }, + "outCtxScrF": { + "type": "string" + }, + "retCtxScrF": { + "type": "string" + }, + "fpB": { + "type": "string" + }, + "fpE": { + "type": "string" + }, + "planrtTS": { + "type": "string" + }, + "bfATS": { + "type": "number" + }, + "bfIOSTS": { + "type": "number" + } + } + } + }, + "required": [ + "meth", + "err", + "res" + ] + } + }, + "cInfo": { + "type": "object", + "properties": { + "code": { + "type": "string" + }, + "url": { + "type": "string" + }, + "msg": { + "type": "string" + } + } + } + }, + "required": [ + "ver", + "ext", + "lang", + "id", + "svcResL" + ] +} From ee797404f8ed10187ae7e6a8feee939e304753e5 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Mon, 27 May 2019 17:49:50 +0200 Subject: [PATCH 4/5] find-unknown-fields: basic departures() schema, VBB & DB queries --- find-unknown-fields/departures.schema.json | 654 +++++++++++++++++++++ find-unknown-fields/index.js | 26 +- 2 files changed, 673 insertions(+), 7 deletions(-) create mode 100644 find-unknown-fields/departures.schema.json diff --git a/find-unknown-fields/departures.schema.json b/find-unknown-fields/departures.schema.json new file mode 100644 index 000000000..686aeca87 --- /dev/null +++ b/find-unknown-fields/departures.schema.json @@ -0,0 +1,654 @@ +{ + "title": "departures response", + "type": "object", + "properties": { + "ver": { + "type": "string" + }, + "ext": { + "type": "string" + }, + "lang": { + "type": "string" + }, + "id": { + "type": "string" + }, + "svcResL": { + "type": "array", + "items": { + "type": "object", + "properties": { + "meth": { + "type": "string" + }, + "err": { + "type": "string" + }, + "res": { + "type": "object", + "properties": { + "common": { + "type": "object", + "properties": { + "locL": { + "type": "array", + "items": { + "type": "object", + "properties": { + "lid": { + "type": "string" + }, + "type": { + "type": "string" + }, + "name": { + "type": "string" + }, + "icoX": { + "type": "number" + }, + "extId": { + "type": "string" + }, + "state": { + "type": "string" + }, + "crd": { + "type": "object", + "properties": { + "x": { + "type": "number" + }, + "y": { + "type": "number" + }, + "type": { + "type": "string" + }, + "layerX": { + "type": "number" + }, + "crdSysX": { + "type": "number" + } + } + }, + "pCls": { + "type": "number" + }, + "pRefL": { + "type": "array", + "items": { + "type": "number" + } + }, + "msgL": { + "type": "array", + "items": { + "type": "object", + "properties": { + "type": { + "type": "string" + }, + "remX": { + "type": "number" + }, + "tagL": { + "type": "array", + "items": { + "type": "string" + } + } + }, + "required": [ + "type", + "remX", + "tagL" + ] + } + } + }, + "required": [ + "lid", + "type", + "name", + "icoX", + "extId", + "state", + "crd", + "pCls", + "pRefL", + "msgL" + ] + } + }, + "prodL": { + "type": "array", + "items": { + "type": "object", + "properties": { + "pid": { + "type": "string" + }, + "name": { + "type": "string" + }, + "nameS": { + "type": "string" + }, + "number": { + "type": "string" + }, + "icoX": { + "type": "number" + }, + "cls": { + "type": "number" + }, + "oprX": { + "type": "number" + }, + "prodCtx": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "num": { + "type": "string" + }, + "line": { + "type": "string" + }, + "matchId": { + "type": "string" + }, + "catOut": { + "type": "string" + }, + "catOutS": { + "type": "string" + }, + "catOutL": { + "type": "string" + }, + "catIn": { + "type": "string" + }, + "catCode": { + "type": "string" + }, + "admin": { + "type": "string" + }, + "lineId": { + "type": "string" + } + } + }, + "himIdL": { + "type": "array", + "items": { + "type": "string" + } + } + }, + "required": [ + "name", + "icoX", + "cls", + "nameS", + "prodCtx", + "pid", + "number", + "oprX", + "himIdL" + ] + } + }, + "polyL": { + "type": "array", + "items": {} + }, + "layerL": { + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "name": { + "type": "string" + }, + "index": { + "type": "number" + }, + "annoCnt": { + "type": "number" + } + } + } + }, + "crdSysL": { + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "index": { + "type": "number" + }, + "type": { + "type": "string" + }, + "dim": { + "type": "number" + } + } + } + }, + "opL": { + "type": "array", + "items": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "icoX": { + "type": "number" + }, + "id": { + "type": "string" + } + }, + "required": [ + "name", + "icoX", + "id" + ] + } + }, + "remL": { + "type": "array", + "items": { + "type": "object", + "properties": { + "type": { + "type": "string" + }, + "code": { + "type": "string" + }, + "prio": { + "type": "number" + }, + "icoX": { + "type": "number" + }, + "txtN": { + "type": "string" + } + }, + "required": [ + "type", + "code", + "prio", + "icoX", + "txtN" + ] + } + }, + "icoL": { + "type": "array", + "items": { + "type": "object", + "properties": { + "res": { + "type": "string" + }, + "fg": { + "type": "object", + "properties": { + "r": { + "type": "number" + }, + "g": { + "type": "number" + }, + "b": { + "type": "number" + }, + "a": { + "type": "number" + } + } + }, + "bg": { + "type": "object", + "properties": { + "r": { + "type": "number" + }, + "g": { + "type": "number" + }, + "b": { + "type": "number" + }, + "a": { + "type": "number" + } + } + }, + "txt": { + "type": "string" + } + }, + "required": [ + "res", + "fg", + "bg", + "txt" + ] + } + }, + "himL": { + "type": "array", + "items": { + "type": "object", + "properties": { + "hid": { + "type": "string" + }, + "act": { + "type": "boolean" + }, + "pub": { + "type": "string" + }, + "head": { + "type": "string" + }, + "lead": { + "type": "string" + }, + "text": { + "type": "string" + }, + "tckr": { + "type": "string" + }, + "icoX": { + "type": "number" + }, + "prio": { + "type": "number" + }, + "fLocX": { + "type": "number" + }, + "prod": { + "type": "number" + }, + "lModDate": { + "type": "string" + }, + "lModTime": { + "type": "string" + }, + "sDate": { + "type": "string" + }, + "sTime": { + "type": "string" + }, + "eDate": { + "type": "string" + }, + "eTime": { + "type": "string" + }, + "cat": { + "type": "number" + }, + "pubChL": { + "type": "array", + "items": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "fDate": { + "type": "string" + }, + "fTime": { + "type": "string" + }, + "tDate": { + "type": "string" + }, + "tTime": { + "type": "string" + } + } + } + } + } + } + } + } + }, + "type": { + "type": "string" + }, + "jnyL": { + "type": "array", + "items": { + "type": "object", + "properties": { + "jid": { + "type": "string" + }, + "date": { + "type": "string" + }, + "prodX": { + "type": "number" + }, + "dirTxt": { + "type": "string" + }, + "status": { + "type": "string" + }, + "isRchbl": { + "type": "boolean" + }, + "stbStop": { + "type": "object", + "properties": { + "locX": { + "type": "number" + }, + "idx": { + "type": "number" + }, + "dProdX": { + "type": "number" + }, + "dPlatfS": { + "type": "string" + }, + "dInR": { + "type": "boolean" + }, + "dTimeS": { + "type": "string" + }, + "type": { + "type": "string" + }, + "dTimeR": { + "type": "string" + }, + "dProgType": { + "type": "string" + }, + "dPlatfR": { + "type": "string" + } + } + }, + "stopL": { + "type": "array", + "items": { + "type": "object", + "properties": { + "locX": { + "type": "number" + }, + "idx": { + "type": "number" + }, + "dPlatfS": { + "type": "string" + }, + "dInR": { + "type": "boolean" + }, + "dTimeS": { + "type": "string" + }, + "isImp": { + "type": "boolean" + }, + "type": { + "type": "string" + }, + "aOutR": { + "type": "boolean" + }, + "aTimeS": { + "type": "string" + }, + "dTimeR": { + "type": "string" + }, + "dProgType": { + "type": "string" + }, + "dPlatfR": { + "type": "string" + } + }, + "required": [ + "locX", + "idx", + "isImp", + "type", + "aOutR", + "aTimeS", + "dPlatfS", + "dInR", + "dTimeS", + "dTimeR", + "dProgType", + "dPlatfR" + ] + } + }, + "msgL": { + "type": "array", + "items": { + "type": "object", + "properties": { + "type": { + "type": "string" + }, + "remX": { + "type": "number" + }, + "fLocX": { + "type": "number" + }, + "tLocX": { + "type": "number" + }, + "tagL": { + "type": "array", + "items": { + "type": "string" + } + }, + "himX": { + "type": "number" + } + }, + "required": [ + "type", + "remX", + "fLocX", + "tLocX", + "tagL", + "himX" + ] + } + }, + "subscr": { + "type": "string" + } + }, + "required": [ + "jid", + "date", + "prodX", + "dirTxt", + "status", + "isRchbl", + "stbStop", + "stopL", + "msgL", + "subscr" + ] + } + }, + "fpB": { + "type": "string" + }, + "fpE": { + "type": "string" + }, + "planrtTS": { + "type": "string" + }, + "sD": { + "type": "string" + }, + "sT": { + "type": "string" + } + } + } + }, + "required": [ + "meth", + "err", + "res" + ] + } + } + }, + "required": [ + "ver", + "ext", + "lang", + "id", + "svcResL" + ] +} diff --git a/find-unknown-fields/index.js b/find-unknown-fields/index.js index a56677692..4e0f78bae 100644 --- a/find-unknown-fields/index.js +++ b/find-unknown-fields/index.js @@ -7,23 +7,25 @@ const vbbProfile = require('../p/vbb') const bvgProfile = require('../p/bvg') const dbProfile = require('../p/db') const journeysSchema = require('./journeys.schema.json') +const departuresSchema = require('./departures.schema.json') // todo: https://github.com/epoberezkin/ajv#formats // todo: https://github.com/epoberezkin/ajv#combining-schemas-with-ref -const fetchJourneys = (from, to) => (client) => { - return client.journeys(from, to, { - results: 3, tickets: true, stopovers: true, remarks: true, polylines: true - }) +const journeysOpts = { + results: 3, tickets: true, stopovers: true, remarks: true, polylines: true +} +const departuresOpts = { + duration: 10, linesOfStops: true, remarks: true, stopovers: true, includeRelatedStations: true } const tasks = [ [ vbbProfile, - fetchJourneys('900000175013', '900000087171'), // Risaer Str. to TXL + c => c.journeys('900000175013', '900000087171', journeysOpts), // Risaer Str. to TXL journeysSchema ], [ bvgProfile, - fetchJourneys('900000175013', '900000087171'), // Risaer Str. to TXL + c => c.journeys('900000175013', '900000087171', journeysOpts), // Risaer Str. to TXL journeysSchema ], [ @@ -35,7 +37,17 @@ const tasks = [ latitude: 52.515189, longitude: 13.350123 }, '8000261', journeysOpts), journeysSchema - ] + ], + [ + vbbProfile, + client => client.departures('900000230999', departuresOpts), // S Potsdam Hbf + departuresSchema + ], + [ + bvgProfile, + client => client.departures('900000078101', departuresOpts), // U Hermannplatz + departuresSchema + ], ] const userAgent = 'hafas-client find-unknown-fields' From f03ae836eebce76ca00f8506ead9e2cdb4f45f84 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Mon, 8 Jul 2019 22:45:10 +0200 Subject: [PATCH 5/5] move find-unknown-fields into tools dir, separate package.json --- package.json | 2 -- .../find-unknown-fields}/departures.schema.json | 0 .../find-unknown-fields}/index.js | 8 ++++---- .../find-unknown-fields}/journeys.schema.json | 0 tools/find-unknown-fields/package.json | 9 +++++++++ 5 files changed, 13 insertions(+), 6 deletions(-) rename {find-unknown-fields => tools/find-unknown-fields}/departures.schema.json (100%) rename {find-unknown-fields => tools/find-unknown-fields}/index.js (92%) rename {find-unknown-fields => tools/find-unknown-fields}/journeys.schema.json (100%) create mode 100644 tools/find-unknown-fields/package.json diff --git a/package.json b/package.json index 972ba9a10..2c2bdfe31 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,6 @@ "vbb-translate-ids": "^3.1.0" }, "devDependencies": { - "ajv": "^6.10.0", "db-stations": "^2.3.0", "is-coordinates": "^2.0.2", "is-roughly-equal": "^0.1.0", @@ -65,7 +64,6 @@ }, "scripts": { "test": "env NODE_ENV=dev node test/index.js", - "find-unknown-fields": "node find-unknown-fields/index.js", "prepublishOnly": "npm test | tap-spec", "install": "node lib/generate-install-id.js >id.json" } diff --git a/find-unknown-fields/departures.schema.json b/tools/find-unknown-fields/departures.schema.json similarity index 100% rename from find-unknown-fields/departures.schema.json rename to tools/find-unknown-fields/departures.schema.json diff --git a/find-unknown-fields/index.js b/tools/find-unknown-fields/index.js similarity index 92% rename from find-unknown-fields/index.js rename to tools/find-unknown-fields/index.js index 4e0f78bae..678bf0715 100644 --- a/find-unknown-fields/index.js +++ b/tools/find-unknown-fields/index.js @@ -2,10 +2,10 @@ const Ajv = require('ajv') const omit = require('lodash/omit') -const createClient = require('..') -const vbbProfile = require('../p/vbb') -const bvgProfile = require('../p/bvg') -const dbProfile = require('../p/db') +const createClient = require('../..') +const vbbProfile = require('../../p/vbb') +const bvgProfile = require('../../p/bvg') +const dbProfile = require('../../p/db') const journeysSchema = require('./journeys.schema.json') const departuresSchema = require('./departures.schema.json') // todo: https://github.com/epoberezkin/ajv#formats diff --git a/find-unknown-fields/journeys.schema.json b/tools/find-unknown-fields/journeys.schema.json similarity index 100% rename from find-unknown-fields/journeys.schema.json rename to tools/find-unknown-fields/journeys.schema.json diff --git a/tools/find-unknown-fields/package.json b/tools/find-unknown-fields/package.json new file mode 100644 index 000000000..a35c773ea --- /dev/null +++ b/tools/find-unknown-fields/package.json @@ -0,0 +1,9 @@ +{ + "private": true, + "name": "find-unknown-fields", + "version": "1.0.0", + "main": "index.js", + "dependencies": { + "ajv": "^6.10.1" + } +}