bengaluru-transit 0.1.0
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.
- package/LICENSE +21 -0
- package/README.md +507 -0
- package/dist/api/info.d.ts +77 -0
- package/dist/api/info.d.ts.map +1 -0
- package/dist/api/info.js +197 -0
- package/dist/api/info.js.map +1 -0
- package/dist/api/locations.d.ts +26 -0
- package/dist/api/locations.d.ts.map +1 -0
- package/dist/api/locations.js +57 -0
- package/dist/api/locations.js.map +1 -0
- package/dist/api/routes.d.ts +341 -0
- package/dist/api/routes.d.ts.map +1 -0
- package/dist/api/routes.js +1133 -0
- package/dist/api/routes.js.map +1 -0
- package/dist/api/stops.d.ts +92 -0
- package/dist/api/stops.d.ts.map +1 -0
- package/dist/api/stops.js +237 -0
- package/dist/api/stops.js.map +1 -0
- package/dist/api/vehicles.d.ts +49 -0
- package/dist/api/vehicles.d.ts.map +1 -0
- package/dist/api/vehicles.js +154 -0
- package/dist/api/vehicles.js.map +1 -0
- package/dist/client/base-client.d.ts +52 -0
- package/dist/client/base-client.d.ts.map +1 -0
- package/dist/client/base-client.js +76 -0
- package/dist/client/base-client.js.map +1 -0
- package/dist/client/transit-client.d.ts +91 -0
- package/dist/client/transit-client.d.ts.map +1 -0
- package/dist/client/transit-client.js +98 -0
- package/dist/client/transit-client.js.map +1 -0
- package/dist/constants/api.d.ts +16 -0
- package/dist/constants/api.d.ts.map +1 -0
- package/dist/constants/api.js +16 -0
- package/dist/constants/api.js.map +1 -0
- package/dist/constants/routes.d.ts +16 -0
- package/dist/constants/routes.d.ts.map +1 -0
- package/dist/constants/routes.js +16 -0
- package/dist/constants/routes.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/schemas/common.d.ts +34 -0
- package/dist/schemas/common.d.ts.map +1 -0
- package/dist/schemas/common.js +20 -0
- package/dist/schemas/common.js.map +1 -0
- package/dist/schemas/index.d.ts +7 -0
- package/dist/schemas/index.d.ts.map +1 -0
- package/dist/schemas/index.js +7 -0
- package/dist/schemas/index.js.map +1 -0
- package/dist/schemas/info.d.ts +390 -0
- package/dist/schemas/info.d.ts.map +1 -0
- package/dist/schemas/info.js +110 -0
- package/dist/schemas/info.js.map +1 -0
- package/dist/schemas/locations.d.ts +84 -0
- package/dist/schemas/locations.d.ts.map +1 -0
- package/dist/schemas/locations.js +31 -0
- package/dist/schemas/locations.js.map +1 -0
- package/dist/schemas/routes.d.ts +3967 -0
- package/dist/schemas/routes.d.ts.map +1 -0
- package/dist/schemas/routes.js +532 -0
- package/dist/schemas/routes.js.map +1 -0
- package/dist/schemas/stops.d.ts +543 -0
- package/dist/schemas/stops.d.ts.map +1 -0
- package/dist/schemas/stops.js +129 -0
- package/dist/schemas/stops.js.map +1 -0
- package/dist/schemas/vehicles.d.ts +602 -0
- package/dist/schemas/vehicles.d.ts.map +1 -0
- package/dist/schemas/vehicles.js +116 -0
- package/dist/schemas/vehicles.js.map +1 -0
- package/dist/types/api.d.ts +9 -0
- package/dist/types/api.d.ts.map +1 -0
- package/dist/types/api.js +5 -0
- package/dist/types/api.js.map +1 -0
- package/dist/types/coordinates.d.ts +7 -0
- package/dist/types/coordinates.d.ts.map +1 -0
- package/dist/types/coordinates.js +2 -0
- package/dist/types/coordinates.js.map +1 -0
- package/dist/types/geojson.d.ts +84 -0
- package/dist/types/geojson.d.ts.map +1 -0
- package/dist/types/geojson.js +2 -0
- package/dist/types/geojson.js.map +1 -0
- package/dist/types/index.d.ts +16 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +12 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/info.d.ts +133 -0
- package/dist/types/info.d.ts.map +1 -0
- package/dist/types/info.js +5 -0
- package/dist/types/info.js.map +1 -0
- package/dist/types/locations.d.ts +59 -0
- package/dist/types/locations.d.ts.map +1 -0
- package/dist/types/locations.js +5 -0
- package/dist/types/locations.js.map +1 -0
- package/dist/types/routes.d.ts +1137 -0
- package/dist/types/routes.d.ts.map +1 -0
- package/dist/types/routes.js +14 -0
- package/dist/types/routes.js.map +1 -0
- package/dist/types/stops.d.ts +286 -0
- package/dist/types/stops.d.ts.map +1 -0
- package/dist/types/stops.js +26 -0
- package/dist/types/stops.js.map +1 -0
- package/dist/types/vehicles.d.ts +138 -0
- package/dist/types/vehicles.d.ts.map +1 -0
- package/dist/types/vehicles.js +5 -0
- package/dist/types/vehicles.js.map +1 -0
- package/dist/utils/date.d.ts +35 -0
- package/dist/utils/date.d.ts.map +1 -0
- package/dist/utils/date.js +49 -0
- package/dist/utils/date.js.map +1 -0
- package/dist/utils/errors.d.ts +34 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +41 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/geojson.d.ts +36 -0
- package/dist/utils/geojson.d.ts.map +1 -0
- package/dist/utils/geojson.js +115 -0
- package/dist/utils/geojson.js.map +1 -0
- package/dist/utils/validation.d.ts +40 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +62 -0
- package/dist/utils/validation.js.map +1 -0
- package/package.json +77 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom error classes for Bangalore Transit SDK
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Base error class for all transit SDK errors
|
|
6
|
+
*/
|
|
7
|
+
export class TransitError extends Error {
|
|
8
|
+
/**
|
|
9
|
+
* Error code (e.g., 'VALIDATION_ERROR', 'API_ERROR')
|
|
10
|
+
*/
|
|
11
|
+
code;
|
|
12
|
+
/**
|
|
13
|
+
* Optional cause (original error)
|
|
14
|
+
*/
|
|
15
|
+
cause;
|
|
16
|
+
constructor(message, code = 'TRANSIT_ERROR', cause) {
|
|
17
|
+
super(message);
|
|
18
|
+
this.name = 'TransitError';
|
|
19
|
+
this.code = code;
|
|
20
|
+
this.cause = cause;
|
|
21
|
+
// Maintains proper stack trace for where our error was thrown (only available on V8)
|
|
22
|
+
if (Error.captureStackTrace) {
|
|
23
|
+
Error.captureStackTrace(this, TransitError);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Validation error thrown when input parameters fail Zod schema validation
|
|
29
|
+
*/
|
|
30
|
+
export class TransitValidationError extends TransitError {
|
|
31
|
+
/**
|
|
32
|
+
* Validation error details from Zod
|
|
33
|
+
*/
|
|
34
|
+
details;
|
|
35
|
+
constructor(message, details, cause) {
|
|
36
|
+
super(message, 'VALIDATION_ERROR', cause);
|
|
37
|
+
this.name = 'TransitValidationError';
|
|
38
|
+
this.details = details;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/utils/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,OAAO,YAAa,SAAQ,KAAK;IACtC;;OAEG;IACa,IAAI,CAAS;IAE7B;;OAEG;IACa,KAAK,CAAS;IAE9B,YAAY,OAAe,EAAE,OAAe,eAAe,EAAE,KAAa;QACzE,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QAEnB,qFAAqF;QACrF,IAAI,KAAK,CAAC,iBAAiB,EAAE,CAAC;YAC7B,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;QAC7C,CAAC;IACF,CAAC;CACD;AAED;;GAEG;AACH,MAAM,OAAO,sBAAuB,SAAQ,YAAY;IACvD;;OAEG;IACa,OAAO,CAA2C;IAElE,YACC,OAAe,EACf,OAAiD,EACjD,KAAa;QAEb,KAAK,CAAC,OAAO,EAAE,kBAAkB,EAAE,KAAK,CAAC,CAAC;QAC1C,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;QACrC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACxB,CAAC;CACD"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Feature, FeatureCollection, Position } from 'geojson';
|
|
2
|
+
import type { FacilityFeature, FacilityProperties, LocationFeature, LocationProperties, RouteFeature, RouteProperties, StopFeature, StopProperties } from '../types/geojson';
|
|
3
|
+
/**
|
|
4
|
+
* GeoJSON utility functions for BMTC data conversion
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Creates a Point feature for a bus stop
|
|
8
|
+
*/
|
|
9
|
+
export declare function createStopFeature(coordinates: Position, properties: StopProperties): StopFeature;
|
|
10
|
+
/**
|
|
11
|
+
* Creates a LineString feature for a bus route
|
|
12
|
+
*/
|
|
13
|
+
export declare function createRouteFeature(coordinates: Position[], properties: RouteProperties): RouteFeature;
|
|
14
|
+
/**
|
|
15
|
+
* Creates a Point feature for a bus location
|
|
16
|
+
*/
|
|
17
|
+
export declare function createLocationFeature(coordinates: Position, properties: LocationProperties): LocationFeature;
|
|
18
|
+
/**
|
|
19
|
+
* Creates a Point feature for a facility/amenity
|
|
20
|
+
*/
|
|
21
|
+
export declare function createFacilityFeature(coordinates: Position, properties: FacilityProperties): FacilityFeature;
|
|
22
|
+
/**
|
|
23
|
+
* Creates a FeatureCollection from an array of features
|
|
24
|
+
*/
|
|
25
|
+
export declare function createFeatureCollection<T extends Feature>(features: T[]): FeatureCollection<T['geometry'], T['properties']>;
|
|
26
|
+
/**
|
|
27
|
+
* Validates that coordinates are in [longitude, latitude] format
|
|
28
|
+
* GeoJSON standard requires longitude first, then latitude
|
|
29
|
+
*/
|
|
30
|
+
export declare function validateCoordinates(coordinates: Position): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Converts BMTC coordinate format to GeoJSON Position
|
|
33
|
+
* Handles different possible input formats
|
|
34
|
+
*/
|
|
35
|
+
export declare function normalizeCoordinates(input: unknown): Position | null;
|
|
36
|
+
//# sourceMappingURL=geojson.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geojson.d.ts","sourceRoot":"","sources":["../../src/utils/geojson.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EACP,iBAAiB,EACjB,QAAQ,EACT,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EACV,eAAe,EACf,kBAAkB,EAClB,eAAe,EACf,kBAAkB,EAClB,YAAY,EACZ,eAAe,EACf,WAAW,EACX,cAAc,EACf,MAAM,kBAAkB,CAAC;AAE1B;;GAEG;AAEH;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,WAAW,EAAE,QAAQ,EACrB,UAAU,EAAE,cAAc,GACzB,WAAW,CASb;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,WAAW,EAAE,QAAQ,EAAE,EACvB,UAAU,EAAE,eAAe,GAC1B,YAAY,CASd;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,WAAW,EAAE,QAAQ,EACrB,UAAU,EAAE,kBAAkB,GAC7B,eAAe,CASjB;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,WAAW,EAAE,QAAQ,EACrB,UAAU,EAAE,kBAAkB,GAC7B,eAAe,CASjB;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,SAAS,OAAO,EACvD,QAAQ,EAAE,CAAC,EAAE,GACZ,iBAAiB,CAAC,CAAC,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,YAAY,CAAC,CAAC,CAKnD;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,QAAQ,GAAG,OAAO,CAsBlE;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,OAAO,GACb,QAAQ,GAAG,IAAI,CAyBjB"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GeoJSON utility functions for BMTC data conversion
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Creates a Point feature for a bus stop
|
|
6
|
+
*/
|
|
7
|
+
export function createStopFeature(coordinates, properties) {
|
|
8
|
+
return {
|
|
9
|
+
type: 'Feature',
|
|
10
|
+
geometry: {
|
|
11
|
+
type: 'Point',
|
|
12
|
+
coordinates,
|
|
13
|
+
},
|
|
14
|
+
properties,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Creates a LineString feature for a bus route
|
|
19
|
+
*/
|
|
20
|
+
export function createRouteFeature(coordinates, properties) {
|
|
21
|
+
return {
|
|
22
|
+
type: 'Feature',
|
|
23
|
+
geometry: {
|
|
24
|
+
type: 'LineString',
|
|
25
|
+
coordinates,
|
|
26
|
+
},
|
|
27
|
+
properties,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Creates a Point feature for a bus location
|
|
32
|
+
*/
|
|
33
|
+
export function createLocationFeature(coordinates, properties) {
|
|
34
|
+
return {
|
|
35
|
+
type: 'Feature',
|
|
36
|
+
geometry: {
|
|
37
|
+
type: 'Point',
|
|
38
|
+
coordinates,
|
|
39
|
+
},
|
|
40
|
+
properties,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Creates a Point feature for a facility/amenity
|
|
45
|
+
*/
|
|
46
|
+
export function createFacilityFeature(coordinates, properties) {
|
|
47
|
+
return {
|
|
48
|
+
type: 'Feature',
|
|
49
|
+
geometry: {
|
|
50
|
+
type: 'Point',
|
|
51
|
+
coordinates,
|
|
52
|
+
},
|
|
53
|
+
properties,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Creates a FeatureCollection from an array of features
|
|
58
|
+
*/
|
|
59
|
+
export function createFeatureCollection(features) {
|
|
60
|
+
return {
|
|
61
|
+
type: 'FeatureCollection',
|
|
62
|
+
features,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Validates that coordinates are in [longitude, latitude] format
|
|
67
|
+
* GeoJSON standard requires longitude first, then latitude
|
|
68
|
+
*/
|
|
69
|
+
export function validateCoordinates(coordinates) {
|
|
70
|
+
if (!Array.isArray(coordinates) || coordinates.length < 2) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
const [lng, lat] = coordinates;
|
|
74
|
+
if (typeof lng !== 'number' || typeof lat !== 'number') {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
// Validate longitude: -180 to 180
|
|
78
|
+
if (lng < -180 || lng > 180) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
// Validate latitude: -90 to 90
|
|
82
|
+
if (lat < -90 || lat > 90) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Converts BMTC coordinate format to GeoJSON Position
|
|
89
|
+
* Handles different possible input formats
|
|
90
|
+
*/
|
|
91
|
+
export function normalizeCoordinates(input) {
|
|
92
|
+
if (!Array.isArray(input)) {
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
// Handle [lng, lat] or [lat, lng] - we'll assume [lng, lat] is correct
|
|
96
|
+
if (input.length >= 2) {
|
|
97
|
+
const [first, second] = input;
|
|
98
|
+
if (typeof first === 'number' && typeof second === 'number') {
|
|
99
|
+
// If first value is > 90, it's likely longitude (India is ~70-90 lng)
|
|
100
|
+
// If first value is < 90, it might be latitude
|
|
101
|
+
// For Bangalore, longitude is ~77, latitude is ~13
|
|
102
|
+
const coords = [first, second];
|
|
103
|
+
if (validateCoordinates(coords)) {
|
|
104
|
+
return coords;
|
|
105
|
+
}
|
|
106
|
+
// Try swapping if validation fails
|
|
107
|
+
const swapped = [second, first];
|
|
108
|
+
if (validateCoordinates(swapped)) {
|
|
109
|
+
return swapped;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=geojson.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geojson.js","sourceRoot":"","sources":["../../src/utils/geojson.ts"],"names":[],"mappings":"AAgBA;;GAEG;AAEH;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAC/B,WAAqB,EACrB,UAA0B;IAE1B,OAAO;QACL,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE;YACR,IAAI,EAAE,OAAO;YACb,WAAW;SACZ;QACD,UAAU;KACX,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAChC,WAAuB,EACvB,UAA2B;IAE3B,OAAO;QACL,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE;YACR,IAAI,EAAE,YAAY;YAClB,WAAW;SACZ;QACD,UAAU;KACX,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,qBAAqB,CACnC,WAAqB,EACrB,UAA8B;IAE9B,OAAO;QACL,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE;YACR,IAAI,EAAE,OAAO;YACb,WAAW;SACZ;QACD,UAAU;KACX,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,qBAAqB,CACnC,WAAqB,EACrB,UAA8B;IAE9B,OAAO;QACL,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE;YACR,IAAI,EAAE,OAAO;YACb,WAAW;SACZ;QACD,UAAU;KACX,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,uBAAuB,CACrC,QAAa;IAEb,OAAO;QACL,IAAI,EAAE,mBAAmB;QACzB,QAAQ;KACT,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,WAAqB;IACvD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,WAAW,CA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AO,OAAO,CAAC;YACjB,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Validation utility functions
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Parse a string ID to a number (base 10)
|
|
7
|
+
* Used consistently throughout the wrapper to convert string IDs to numbers for API calls
|
|
8
|
+
* @param id - String ID to parse
|
|
9
|
+
* @returns Parsed number
|
|
10
|
+
*/
|
|
11
|
+
export declare function parseId(id: string): number;
|
|
12
|
+
/**
|
|
13
|
+
* Convert a number ID to a string
|
|
14
|
+
* Used consistently throughout the wrapper to convert number IDs to strings for user-facing types
|
|
15
|
+
* @param id - Number ID to convert
|
|
16
|
+
* @returns String representation of the ID
|
|
17
|
+
*/
|
|
18
|
+
export declare function stringifyId(id: number): string;
|
|
19
|
+
/**
|
|
20
|
+
* Validates data against a Zod schema and throws a formatted error if invalid
|
|
21
|
+
*/
|
|
22
|
+
export declare function validate<T>(schema: z.ZodSchema<T>, data: unknown, errorMessage?: string): T;
|
|
23
|
+
/**
|
|
24
|
+
* Safely validates data and returns a result object
|
|
25
|
+
*/
|
|
26
|
+
export declare function safeValidate<T>(schema: z.ZodSchema<T>, data: unknown): {
|
|
27
|
+
success: true;
|
|
28
|
+
data: T;
|
|
29
|
+
} | {
|
|
30
|
+
success: false;
|
|
31
|
+
error: {
|
|
32
|
+
message: string;
|
|
33
|
+
code: string;
|
|
34
|
+
details?: Array<{
|
|
35
|
+
path: string;
|
|
36
|
+
message: string;
|
|
37
|
+
}>;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB;;GAEG;AAEH;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAE1C;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAE9C;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EACxB,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EACtB,IAAI,EAAE,OAAO,EACb,YAAY,CAAC,EAAE,MAAM,GACpB,CAAC,CAiBH;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAC5B,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EACtB,IAAI,EAAE,OAAO,GACZ;IAAE,OAAO,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,CAAC,CAAA;CAAE,GAAG;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,KAAK,CAAC;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,OAAO,EAAE,MAAM,CAAA;SAAE,CAAC,CAAA;KAAE,CAAA;CAAE,CAuB/I"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { TransitValidationError } from './errors';
|
|
2
|
+
/**
|
|
3
|
+
* Validation utility functions
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Parse a string ID to a number (base 10)
|
|
7
|
+
* Used consistently throughout the wrapper to convert string IDs to numbers for API calls
|
|
8
|
+
* @param id - String ID to parse
|
|
9
|
+
* @returns Parsed number
|
|
10
|
+
*/
|
|
11
|
+
export function parseId(id) {
|
|
12
|
+
return parseInt(id, 10);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Convert a number ID to a string
|
|
16
|
+
* Used consistently throughout the wrapper to convert number IDs to strings for user-facing types
|
|
17
|
+
* @param id - Number ID to convert
|
|
18
|
+
* @returns String representation of the ID
|
|
19
|
+
*/
|
|
20
|
+
export function stringifyId(id) {
|
|
21
|
+
return id.toString();
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Validates data against a Zod schema and throws a formatted error if invalid
|
|
25
|
+
*/
|
|
26
|
+
export function validate(schema, data, errorMessage) {
|
|
27
|
+
const result = schema.safeParse(data);
|
|
28
|
+
if (!result.success) {
|
|
29
|
+
// Add detailed validation errors
|
|
30
|
+
const details = result.error.errors.map((err) => ({
|
|
31
|
+
path: err.path.join('.'),
|
|
32
|
+
message: err.message,
|
|
33
|
+
}));
|
|
34
|
+
throw new TransitValidationError(errorMessage || 'Validation failed', details);
|
|
35
|
+
}
|
|
36
|
+
return result.data;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Safely validates data and returns a result object
|
|
40
|
+
*/
|
|
41
|
+
export function safeValidate(schema, data) {
|
|
42
|
+
const result = schema.safeParse(data);
|
|
43
|
+
if (!result.success) {
|
|
44
|
+
const details = result.error.errors.map((err) => ({
|
|
45
|
+
path: err.path.join('.'),
|
|
46
|
+
message: err.message,
|
|
47
|
+
}));
|
|
48
|
+
return {
|
|
49
|
+
success: false,
|
|
50
|
+
error: {
|
|
51
|
+
message: 'Validation failed',
|
|
52
|
+
code: 'VALIDATION_ERROR',
|
|
53
|
+
details,
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
success: true,
|
|
59
|
+
data: result.data,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAElD;;GAEG;AAEH;;;;;GAKG;AACH,MAAM,UAAU,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BACL,OAAO,EAAE,mBAAmB;gBAC5B,IAAI,EAAE,kBAAkB;gBACxB,OAAO;aACR;SACF,CAAC;IACJ,CAAC;IAED,OAAO;QACL,OAAO,EAAE,IAAI;QACb,IAAI,EAAE,MAAM,CAAC,IAAI;KAClB,CAAC;AACJ,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "bengaluru-transit",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Type-safe TypeScript SDK for Bangalore public transit APIs with Zod validation and GeoJSON support",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"module": "dist/index.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"require": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md",
|
|
18
|
+
"LICENSE"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsc -p tsconfig.build.json",
|
|
22
|
+
"test": "vitest run",
|
|
23
|
+
"test:watch": "vitest",
|
|
24
|
+
"test:ui": "vitest --ui",
|
|
25
|
+
"test:integration": "cross-env RUN_REAL_API_TESTS=true vitest run tests/integration/real-api.test.ts --pool=forks --poolOptions.forks.singleFork=true",
|
|
26
|
+
"test:integration:helpline": "cross-env RUN_REAL_API_TESTS=true TEST_ENDPOINT=helpline vitest run tests/integration/real-api.test.ts --pool=forks --poolOptions.forks.singleFork=true",
|
|
27
|
+
"test:integration:service": "cross-env RUN_REAL_API_TESTS=true TEST_ENDPOINT=service vitest run tests/integration/real-api.test.ts --pool=forks --poolOptions.forks.singleFork=true",
|
|
28
|
+
"test:integration:about": "cross-env RUN_REAL_API_TESTS=true TEST_ENDPOINT=about vitest run tests/integration/real-api.test.ts --pool=forks --poolOptions.forks.singleFork=true",
|
|
29
|
+
"test:integration:emergency": "cross-env RUN_REAL_API_TESTS=true TEST_ENDPOINT=emergency vitest run tests/integration/real-api.test.ts --pool=forks --poolOptions.forks.singleFork=true",
|
|
30
|
+
"test:integration:vehicle": "cross-env RUN_REAL_API_TESTS=true TEST_ENDPOINT=vehicle vitest run tests/integration/real-api.test.ts --pool=forks --poolOptions.forks.singleFork=true",
|
|
31
|
+
"test:integration:route": "cross-env RUN_REAL_API_TESTS=true TEST_ENDPOINT=route vitest run tests/integration/real-api.test.ts --pool=forks --poolOptions.forks.singleFork=true",
|
|
32
|
+
"test:integration:fare": "cross-env RUN_REAL_API_TESTS=true TEST_ENDPOINT=fare vitest run tests/integration/real-api.test.ts --pool=forks --poolOptions.forks.singleFork=true",
|
|
33
|
+
"test:integration:stop": "cross-env RUN_REAL_API_TESTS=true TEST_ENDPOINT=stop vitest run tests/integration/real-api.test.ts --pool=forks --poolOptions.forks.singleFork=true",
|
|
34
|
+
"test:integration:place": "cross-env RUN_REAL_API_TESTS=true TEST_ENDPOINT=place vitest run tests/integration/real-api.test.ts --pool=forks --poolOptions.forks.singleFork=true",
|
|
35
|
+
"test:unit": "vitest run tests/unit",
|
|
36
|
+
"test:build": "vitest run tests/build",
|
|
37
|
+
"prepublishOnly": "npm run build && npm run test:unit && npm run test:build"
|
|
38
|
+
},
|
|
39
|
+
"keywords": [
|
|
40
|
+
"bangalore",
|
|
41
|
+
"transit",
|
|
42
|
+
"bus",
|
|
43
|
+
"transport",
|
|
44
|
+
"api",
|
|
45
|
+
"typescript",
|
|
46
|
+
"geojson",
|
|
47
|
+
"public-transport",
|
|
48
|
+
"india",
|
|
49
|
+
"sdk"
|
|
50
|
+
],
|
|
51
|
+
"author": "Sync271 <67158080+Sync271@users.noreply.github.com>",
|
|
52
|
+
"license": "MIT",
|
|
53
|
+
"repository": {
|
|
54
|
+
"type": "git",
|
|
55
|
+
"url": "git+https://github.com/Sync271/bengaluru-transit.git"
|
|
56
|
+
},
|
|
57
|
+
"dependencies": {
|
|
58
|
+
"@googlemaps/polyline-codec": "^1.0.28",
|
|
59
|
+
"@here/flexpolyline": "^0.1.0",
|
|
60
|
+
"@mapbox/polyline": "^1.2.1",
|
|
61
|
+
"@types/geojson": "^7946.0.15",
|
|
62
|
+
"ky": "^1.7.3",
|
|
63
|
+
"zod": "^3.23.8"
|
|
64
|
+
},
|
|
65
|
+
"devDependencies": {
|
|
66
|
+
"@types/mapbox__polyline": "^1.0.5",
|
|
67
|
+
"@types/node": "^22.10.2",
|
|
68
|
+
"@vitest/ui": "^2.1.8",
|
|
69
|
+
"cross-env": "^10.1.0",
|
|
70
|
+
"nock": "^13.5.5",
|
|
71
|
+
"typescript": "^5.7.2",
|
|
72
|
+
"vitest": "^2.1.8"
|
|
73
|
+
},
|
|
74
|
+
"engines": {
|
|
75
|
+
"node": ">=18.0.0"
|
|
76
|
+
}
|
|
77
|
+
}
|