Add getByRid to TrainsModule
All checks were successful
Publish Package / build-and-publish (push) Successful in 13s
All checks were successful
Publish Package / build-and-publish (push) Successful in 13s
This commit is contained in:
1784
package-lock.json
generated
1784
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -30,8 +30,10 @@
|
|||||||
"author": "Frederick Boniface",
|
"author": "Frederick Boniface",
|
||||||
"license": "GPL-3.0",
|
"license": "GPL-3.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@owlboard/api-schema-types": "^3.0.3-alpha1",
|
"@owlboard/api-schema-types": "^3.0.3-alpha8",
|
||||||
"latlon-geohash": "^2.0.0"
|
"install": "^0.13.0",
|
||||||
|
"latlon-geohash": "^2.0.0",
|
||||||
|
"npm": "^11.13.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/latlon-geohash": "^2.0.4",
|
"@types/latlon-geohash": "^2.0.4",
|
||||||
|
|||||||
@@ -25,6 +25,24 @@ export const IsValidCrs = (CRS: string): boolean => {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if a string is a valid RID, with 15-16 numeric characters
|
||||||
|
* @param rid The RID to validate
|
||||||
|
* @returns True/False - Whether valid or not
|
||||||
|
*/
|
||||||
|
export const IsValidRid = (rid: string): boolean => {
|
||||||
|
if (rid.length > 16 || rid.length < 15) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for (let i = 0; i < rid.length; i++) {
|
||||||
|
const char = rid.charCodeAt(i);
|
||||||
|
if (!isDigit(char)) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if a string is a valid TIPLOC (Syntactically Only)
|
* Checks if a string is a valid TIPLOC (Syntactically Only)
|
||||||
* using byte level checking for max performance
|
* using byte level checking for max performance
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { ApiTrainsTrainByHeadcode } from '@owlboard/api-schema-types';
|
import { ApiTrainsTrainByHeadcode, ApiTrainsTrainDetails } from '@owlboard/api-schema-types';
|
||||||
import type { BaseClient, ApiResult } from '../lib/base.js';
|
import type { BaseClient, ApiResult } from '../lib/base.js';
|
||||||
import { IsValidHeadcode, IsValidToc, IsValidDateStr } from '../lib/validation.js';
|
import { IsValidHeadcode, IsValidRid, IsValidToc, IsValidDateStr } from '../lib/validation.js';
|
||||||
import { ensureDateString } from '../lib/helpers.js';
|
import { ensureDateString } from '../lib/helpers.js';
|
||||||
import { ValidationError } from '../lib/errors.js';
|
import { ValidationError } from '../lib/errors.js';
|
||||||
|
|
||||||
@@ -32,5 +32,14 @@ export class TrainsModule {
|
|||||||
}, customFetch);
|
}, customFetch);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getByRid(rid: string, customFetch?: typeof fetch) {}
|
async getByRid(rid: string, customFetch?: typeof fetch): Promise<ApiResult<ApiTrainsTrainDetails.TrainDetailsResponse>> {
|
||||||
|
if (!IsValidRid(rid)) {
|
||||||
|
throw new ValidationError("RID", "Invalid RID format, must be 15-16 numerals")
|
||||||
|
}
|
||||||
|
|
||||||
|
const path = `/train/${rid}`
|
||||||
|
return this.client.request<ApiTrainsTrainDetails.TrainDetailsResponse>(path, {
|
||||||
|
method: 'GET',
|
||||||
|
}, customFetch);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user