@tiducto/spider-sdk-typescript 0.1.1 → 1.0.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/README.md +1 -1
- package/dist/client.d.ts +14 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +19 -0
- package/dist/client.js.map +1 -1
- package/dist/contract/routing/Leg.d.ts +1 -0
- package/dist/contract/routing/Leg.d.ts.map +1 -1
- package/dist/contract/routing/PlanConnectionStreamData.d.ts +5 -0
- package/dist/contract/routing/PlanConnectionStreamData.d.ts.map +1 -0
- package/dist/contract/routing/PlanConnectionStreamData.js +2 -0
- package/dist/contract/routing/PlanConnectionStreamData.js.map +1 -0
- package/dist/contract/routing/PlanConnectionStreamResponse.d.ts +7 -0
- package/dist/contract/routing/PlanConnectionStreamResponse.d.ts.map +1 -0
- package/dist/contract/routing/PlanConnectionStreamResponse.js +2 -0
- package/dist/contract/routing/PlanConnectionStreamResponse.js.map +1 -0
- package/dist/contract/routing/PlanConnectionStreamVariables.d.ts +18 -0
- package/dist/contract/routing/PlanConnectionStreamVariables.d.ts.map +1 -0
- package/dist/contract/routing/PlanConnectionStreamVariables.js +2 -0
- package/dist/contract/routing/PlanConnectionStreamVariables.js.map +1 -0
- package/dist/contract/routing/Route.d.ts +3 -0
- package/dist/contract/routing/Route.d.ts.map +1 -1
- package/dist/contract/routing/Stop.d.ts +2 -0
- package/dist/contract/routing/Stop.d.ts.map +1 -1
- package/dist/contract/routing/StopDeparturesData.d.ts +3 -3
- package/dist/contract/routing/StopDeparturesData.d.ts.map +1 -1
- package/dist/contract/routing/StopDeparturesRoute.d.ts +3 -0
- package/dist/contract/routing/StopDeparturesRoute.d.ts.map +1 -1
- package/dist/contract/routing/StopDeparturesStop.d.ts +1 -5
- package/dist/contract/routing/StopDeparturesStop.d.ts.map +1 -1
- package/dist/contract/routing/StopDeparturesStop2.d.ts +9 -0
- package/dist/contract/routing/StopDeparturesStop2.d.ts.map +1 -0
- package/dist/contract/routing/StopDeparturesStop2.js +2 -0
- package/dist/contract/routing/StopDeparturesStop2.js.map +1 -0
- package/dist/contract/routing/StopDeparturesStoptime.d.ts +14 -0
- package/dist/contract/routing/StopDeparturesStoptime.d.ts.map +1 -0
- package/dist/contract/routing/StopDeparturesStoptime.js +2 -0
- package/dist/contract/routing/StopDeparturesStoptime.js.map +1 -0
- package/dist/contract/routing/StopDeparturesTrip.d.ts +2 -0
- package/dist/contract/routing/StopDeparturesTrip.d.ts.map +1 -1
- package/dist/contract/routing/StopDeparturesVariables.d.ts +2 -2
- package/dist/contract/routing/StopDeparturesVariables.d.ts.map +1 -1
- package/dist/contract/routing/Stoptime.d.ts +4 -3
- package/dist/contract/routing/Stoptime.d.ts.map +1 -1
- package/dist/contract/routing/TripRoute.d.ts +3 -0
- package/dist/contract/routing/TripRoute.d.ts.map +1 -1
- package/dist/contract/routing/TripStop.d.ts +2 -0
- package/dist/contract/routing/TripStop.d.ts.map +1 -1
- package/dist/contract/routing/TripTrip.d.ts +4 -2
- package/dist/contract/routing/TripTrip.d.ts.map +1 -1
- package/dist/contract/routing/index.d.ts +5 -1
- package/dist/contract/routing/index.d.ts.map +1 -1
- package/dist/contract.d.ts +0 -1
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +0 -12
- package/dist/contract.js.map +1 -1
- package/dist/contractVersion.d.ts +1 -1
- package/dist/contractVersion.js +1 -1
- package/dist/enums.d.ts +11 -4
- package/dist/enums.d.ts.map +1 -1
- package/dist/enums.js +43 -24
- package/dist/enums.js.map +1 -1
- package/dist/errors.d.ts +30 -10
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +55 -18
- package/dist/errors.js.map +1 -1
- package/dist/http.d.ts +39 -1
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +78 -32
- package/dist/http.js.map +1 -1
- package/dist/index.d.ts +4 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/dist/location.d.ts +4 -0
- package/dist/location.d.ts.map +1 -1
- package/dist/location.js +4 -0
- package/dist/location.js.map +1 -1
- package/dist/persistedQueries.d.ts +1 -0
- package/dist/persistedQueries.d.ts.map +1 -1
- package/dist/persistedQueries.js +4 -3
- package/dist/persistedQueries.js.map +1 -1
- package/dist/polling.d.ts +2 -1
- package/dist/polling.d.ts.map +1 -1
- package/dist/polling.js +5 -2
- package/dist/polling.js.map +1 -1
- package/dist/realtime.d.ts +23 -2
- package/dist/realtime.d.ts.map +1 -1
- package/dist/realtime.js +42 -21
- package/dist/realtime.js.map +1 -1
- package/dist/routing.d.ts +133 -32
- package/dist/routing.d.ts.map +1 -1
- package/dist/routing.js +309 -86
- package/dist/routing.js.map +1 -1
- package/dist/sdk.d.ts +1 -1
- package/dist/sdkVersion.d.ts +1 -1
- package/dist/sdkVersion.js +1 -1
- package/dist/serviceDate.d.ts +6 -0
- package/dist/serviceDate.d.ts.map +1 -0
- package/dist/serviceDate.js +17 -0
- package/dist/serviceDate.js.map +1 -0
- package/dist/stops.d.ts +12 -1
- package/dist/stops.d.ts.map +1 -1
- package/dist/stops.js +15 -6
- package/dist/stops.js.map +1 -1
- package/package.json +1 -1
- package/dist/contract/routing/TripStoptime.d.ts +0 -13
- package/dist/contract/routing/TripStoptime.d.ts.map +0 -1
- package/dist/contract/routing/TripStoptime.js +0 -2
- package/dist/contract/routing/TripStoptime.js.map +0 -1
package/dist/enums.js
CHANGED
|
@@ -1,34 +1,53 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
// Every decoded enum is a closed union: a wire value this SDK version doesn't know decodes to 'UNKNOWN', so
|
|
2
|
+
// a newer server can add values without breaking older apps.
|
|
3
|
+
const TRANSIT_MODES = {
|
|
4
|
+
AIRPLANE: true, BICYCLE: true, BUS: true, CABLE_CAR: true, CAR: true, CARPOOL: true, COACH: true, FERRY: true,
|
|
5
|
+
FLEX: true, FLEXIBLE: true, FUNICULAR: true, GONDOLA: true, LEG_SWITCH: true, MONORAIL: true, RAIL: true,
|
|
6
|
+
SCOOTER: true, SNOW_AND_ICE: true, SUBWAY: true, TAXI: true, TRAM: true, TRANSIT: true, TROLLEYBUS: true, WALK: true,
|
|
7
|
+
};
|
|
8
|
+
const OCCUPANCY_STATUSES = {
|
|
9
|
+
EMPTY: true, MANY_SEATS_AVAILABLE: true, FEW_SEATS_AVAILABLE: true, STANDING_ROOM_ONLY: true,
|
|
10
|
+
CRUSHED_STANDING_ROOM_ONLY: true, FULL: true, NOT_ACCEPTING_PASSENGERS: true, NOT_BOARDABLE: true,
|
|
11
|
+
};
|
|
12
|
+
const WHEELCHAIR_BOARDING = { POSSIBLE: true, NOT_POSSIBLE: true };
|
|
13
|
+
const BIKES_ALLOWED = { ALLOWED: true, NOT_ALLOWED: true };
|
|
14
|
+
const REALTIME_STATES = { ADDED: true, CANCELED: true, MODIFIED: true, SCHEDULED: true, UPDATED: true };
|
|
15
|
+
const ROUTING_ERROR_CODES = {
|
|
16
|
+
LOCATION_NOT_FOUND: true, NO_STOPS_IN_RANGE: true, NO_TRANSIT_CONNECTION: true,
|
|
17
|
+
NO_TRANSIT_CONNECTION_IN_SEARCH_WINDOW: true, OUTSIDE_BOUNDS: true, OUTSIDE_SERVICE_PERIOD: true,
|
|
18
|
+
WALKING_BETTER_THAN_TRANSIT: true,
|
|
19
|
+
};
|
|
20
|
+
const INPUT_FIELDS = { DATE_TIME: true, FROM: true, TO: true, VIA: true };
|
|
21
|
+
function decode(known, raw) {
|
|
22
|
+
return (Object.hasOwn(known, raw) ? raw : 'UNKNOWN');
|
|
23
|
+
}
|
|
6
24
|
export function transitModeFromWire(raw) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
25
|
+
return raw == null ? null : decode(TRANSIT_MODES, raw);
|
|
26
|
+
}
|
|
27
|
+
export function realtimeStateFromWire(raw) {
|
|
28
|
+
return raw == null ? null : decode(REALTIME_STATES, raw);
|
|
29
|
+
}
|
|
30
|
+
export function routingErrorCodeFromWire(raw) {
|
|
31
|
+
return raw == null ? 'UNKNOWN' : decode(ROUTING_ERROR_CODES, raw);
|
|
32
|
+
}
|
|
33
|
+
export function inputFieldFromWire(raw) {
|
|
34
|
+
return raw == null ? null : decode(INPUT_FIELDS, raw);
|
|
10
35
|
}
|
|
11
36
|
export function wheelchairFromWire(raw) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
37
|
+
return raw == null || raw === 'NO_INFORMATION' ? null : decode(WHEELCHAIR_BOARDING, raw);
|
|
38
|
+
}
|
|
39
|
+
/** GTFS `wheelchair_boarding` as the stop-search index carries it: 1 possible, 2 not possible, 0 no information. */
|
|
40
|
+
export function wheelchairFromGtfs(raw) {
|
|
41
|
+
if (raw == null || raw === 0)
|
|
42
|
+
return null;
|
|
43
|
+
return raw === 1 ? 'POSSIBLE' : raw === 2 ? 'NOT_POSSIBLE' : 'UNKNOWN';
|
|
17
44
|
}
|
|
18
45
|
export function bikesAllowedFromWire(raw) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
if (raw === 'NOT_ALLOWED')
|
|
22
|
-
return 'NotAllowed';
|
|
23
|
-
return null;
|
|
24
|
-
}
|
|
25
|
-
const OCCUPANCY_STATUSES = new Set([
|
|
26
|
-
'EMPTY', 'MANY_SEATS_AVAILABLE', 'FEW_SEATS_AVAILABLE', 'STANDING_ROOM_ONLY',
|
|
27
|
-
'CRUSHED_STANDING_ROOM_ONLY', 'FULL', 'NOT_ACCEPTING_PASSENGERS', 'NOT_BOARDABLE',
|
|
28
|
-
]);
|
|
46
|
+
return raw == null || raw === 'NO_INFORMATION' ? null : decode(BIKES_ALLOWED, raw);
|
|
47
|
+
}
|
|
29
48
|
export function occupancyFromWire(raw) {
|
|
30
49
|
if (raw == null || raw === 'NO_DATA_AVAILABLE')
|
|
31
50
|
return null;
|
|
32
|
-
return OCCUPANCY_STATUSES
|
|
51
|
+
return decode(OCCUPANCY_STATUSES, raw);
|
|
33
52
|
}
|
|
34
53
|
//# sourceMappingURL=enums.js.map
|
package/dist/enums.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enums.js","sourceRoot":"","sources":["../src/enums.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"enums.js","sourceRoot":"","sources":["../src/enums.ts"],"names":[],"mappings":"AAAA,4GAA4G;AAC5G,6DAA6D;AA2D7D,MAAM,aAAa,GAAuB;IACxC,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI;IAC7G,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI;IACxG,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI;CACrH,CAAC;AAEF,MAAM,kBAAkB,GAA2B;IACjD,KAAK,EAAE,IAAI,EAAE,oBAAoB,EAAE,IAAI,EAAE,mBAAmB,EAAE,IAAI,EAAE,kBAAkB,EAAE,IAAI;IAC5F,0BAA0B,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,wBAAwB,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI;CAClG,CAAC;AAEF,MAAM,mBAAmB,GAA8B,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;AAE9F,MAAM,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mBAAmB,EAAE,GAAG,CAAC,CAAC;AACpE,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,GAA8B;IAC/D,OAAO,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,YAAY,EAAE,GAAG,CAAC,CAAC;AACxD,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,GAA8B;IAC/D,OAAO,GAAG,IAAI,IAAI,IAAI,GAAG,KAAK,gBAAgB,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,mBAAmB,EAAE,GAAG,CAAC,CAAC;AAC3F,CAAC;AAED,oHAAoH;AACpH,MAAM,UAAU,kBAAkB,CAAC,GAA8B;IAC/D,IAAI,GAAG,IAAI,IAAI,IAAI,GAAG,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAC1C,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,SAAS,CAAC;AACzE,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,GAA8B;IACjE,OAAO,GAAG,IAAI,IAAI,IAAI,GAAG,KAAK,gBAAgB,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,aAAa,EAAE,GAAG,CAAC,CAAC;AACrF,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,GAA8B;IAC9D,IAAI,GAAG,IAAI,IAAI,IAAI,GAAG,KAAK,mBAAmB;QAAE,OAAO,IAAI,CAAC;IAC5D,OAAO,MAAM,CAAC,kBAAkB,EAAE,GAAG,CAAC,CAAC;AACzC,CAAC"}
|
package/dist/errors.d.ts
CHANGED
|
@@ -1,33 +1,53 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* What went wrong. `bad_request` is an invalid or missing input, caught by the SDK before sending or
|
|
3
|
+
* rejected by the server; `field` names it. `query_retired` means the API no longer serves the persisted
|
|
4
|
+
* query behind the call (HTTP 410 Gone). `planning_limit_reached` means the project has reached the trip
|
|
5
|
+
* planning limit its plan includes; it applies to trip planning only. `agreement_inactive` means the project has
|
|
6
|
+
* no active agreement; it applies to every call made with a client key.
|
|
7
|
+
*/
|
|
8
|
+
export type SpiderErrorCode = 'network' | 'timeout' | 'unauthorized' | 'bad_request' | 'not_found' | 'query_retired' | 'planning_limit_reached' | 'agreement_inactive' | 'server' | 'rate_limited' | 'decoding' | 'unknown';
|
|
2
9
|
export interface SpiderError {
|
|
3
10
|
readonly code: SpiderErrorCode;
|
|
4
11
|
readonly message: string;
|
|
5
12
|
readonly httpStatus?: number;
|
|
6
|
-
readonly serverCode?: string;
|
|
7
13
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
14
|
+
* The server's machine-readable error code, when it sends one: e.g. `persisted_query_rejected` on an
|
|
15
|
+
* `unauthorized` when the environment doesn't recognise the query id, or `query_retired`.
|
|
10
16
|
*/
|
|
17
|
+
readonly serverCode?: string;
|
|
18
|
+
/** For a `bad_request`, the input field it names (e.g. `searchWindow`, `maxWindow`, `via`, `limit`). */
|
|
11
19
|
readonly field?: string;
|
|
12
20
|
readonly cause?: unknown;
|
|
13
21
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
readonly actual: string;
|
|
17
|
-
constructor(expected: string, actual: string);
|
|
18
|
-
}
|
|
22
|
+
/** A `bad_request` that names only the field, like the server's own validation errors. */
|
|
23
|
+
export declare function badRequest(field: string, problem?: 'is required' | 'is out of range' | 'is invalid'): SpiderError;
|
|
19
24
|
export type TransportErrorKind = 'http' | 'no_data' | 'upstream' | 'bad_request';
|
|
20
25
|
export declare class TransportError extends Error {
|
|
21
26
|
readonly kind: TransportErrorKind;
|
|
22
27
|
readonly httpStatus: number | undefined;
|
|
23
28
|
readonly serverCode: string | undefined;
|
|
24
29
|
readonly field: string | undefined;
|
|
25
|
-
|
|
30
|
+
/** The response body's own `message`, when it has one. */
|
|
31
|
+
readonly serverMessage: string | undefined;
|
|
32
|
+
/** The code-shaped `error` field of the response body, where the gateway puts its own refusal codes. */
|
|
33
|
+
readonly gatewayCode: string | undefined;
|
|
34
|
+
constructor(kind: TransportErrorKind, message: string, httpStatus?: number, serverCode?: string, field?: string, body?: {
|
|
35
|
+
readonly message?: string;
|
|
36
|
+
readonly gatewayCode?: string;
|
|
37
|
+
});
|
|
26
38
|
}
|
|
27
39
|
export declare function parseErrorEnvelope(text: string): {
|
|
28
40
|
code?: string;
|
|
29
41
|
message?: string;
|
|
42
|
+
gatewayCode?: string;
|
|
30
43
|
};
|
|
44
|
+
/** A non-2xx response → an `http` TransportError carrying the body's error code, and for a 400 the field it names. */
|
|
45
|
+
export declare function httpFailure(where: string, status: number, text: string, detail?: string): TransportError;
|
|
46
|
+
/**
|
|
47
|
+
* The plan-limit error an `http` failure's body `error` field names (`planning_limit_reached`,
|
|
48
|
+
* `agreement_inactive`), whatever its status, or `undefined` when it names neither. A `code` field is not read.
|
|
49
|
+
*/
|
|
50
|
+
export declare function limitRefusal(e: TransportError): SpiderError | undefined;
|
|
31
51
|
export declare class DecodingError extends Error {
|
|
32
52
|
readonly cause: unknown;
|
|
33
53
|
constructor(message: string, cause?: unknown);
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,eAAe,GACvB,SAAS,GACT,SAAS,GACT,cAAc,GACd,aAAa,GACb,WAAW,GACX,QAAQ,GACR,cAAc,GACd,UAAU,GACV,SAAS,CAAC;AAEd,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAC;IAC/B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,UAAU,CAA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;gBAGvC,IAAI,EAAE,kBAAkB,EACxB,OAAO,EAAE,MAAM,EACf,UAAU,CAAC,EAAE,MAAM,EACnB,UAAU,CAAC,EAAE,MAAM,EACnB,KAAK,CAAC,EAAE,MAAM,EACd,IAAI,CAAC,EAAE;QAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE;CAWtE;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,CAmB1G;AAKD,sHAAsH;AACtH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,cAAc,CAKxG;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,cAAc,GAAG,WAAW,GAAG,SAAS,CAIvE;AAED,qBAAa,aAAc,SAAQ,KAAK;IACtC,SAAkB,KAAK,EAAE,OAAO,CAAC;gBAErB,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO;CAK7C;AAYD,wBAAgB,aAAa,CAAC,CAAC,EAAE,OAAO,GAAG,WAAW,CA4BrD"}
|
package/dist/errors.js
CHANGED
|
@@ -1,25 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
1
|
+
const QUERY_RETIRED = 'query_retired';
|
|
2
|
+
// Plan-limit refusals: the body code names the state, and the fixed wording stands in for a body without a message.
|
|
3
|
+
const LIMIT_MESSAGES = {
|
|
4
|
+
planning_limit_reached: 'trip planning limit reached',
|
|
5
|
+
agreement_inactive: 'agreement is not active',
|
|
6
|
+
};
|
|
7
|
+
/** A `bad_request` that names only the field, like the server's own validation errors. */
|
|
8
|
+
export function badRequest(field, problem = 'is out of range') {
|
|
9
|
+
return { code: 'bad_request', message: `${field} ${problem}`, field };
|
|
10
10
|
}
|
|
11
11
|
export class TransportError extends Error {
|
|
12
12
|
kind;
|
|
13
13
|
httpStatus;
|
|
14
14
|
serverCode;
|
|
15
15
|
field;
|
|
16
|
-
|
|
16
|
+
/** The response body's own `message`, when it has one. */
|
|
17
|
+
serverMessage;
|
|
18
|
+
/** The code-shaped `error` field of the response body, where the gateway puts its own refusal codes. */
|
|
19
|
+
gatewayCode;
|
|
20
|
+
constructor(kind, message, httpStatus, serverCode, field, body) {
|
|
17
21
|
super(message);
|
|
18
22
|
this.name = 'TransportError';
|
|
19
23
|
this.kind = kind;
|
|
20
24
|
this.httpStatus = httpStatus;
|
|
21
25
|
this.serverCode = serverCode;
|
|
22
26
|
this.field = field;
|
|
27
|
+
this.serverMessage = body?.message;
|
|
28
|
+
this.gatewayCode = body?.gatewayCode;
|
|
23
29
|
}
|
|
24
30
|
}
|
|
25
31
|
export function parseErrorEnvelope(text) {
|
|
@@ -32,13 +38,36 @@ export function parseErrorEnvelope(text) {
|
|
|
32
38
|
}
|
|
33
39
|
if (typeof body === 'object' && body !== null) {
|
|
34
40
|
const b = body;
|
|
41
|
+
// The gateway's own rejections carry their code in `error` (e.g. "query_retired"); other
|
|
42
|
+
// services put a human sentence there, so only a code-shaped value counts.
|
|
43
|
+
const gatewayCode = typeof b.error === 'string' && /^[a-z][a-z0-9_]*$/.test(b.error) ? b.error : undefined;
|
|
35
44
|
return {
|
|
36
|
-
code: typeof b.code === 'string' ? b.code :
|
|
45
|
+
code: typeof b.code === 'string' ? b.code : gatewayCode,
|
|
37
46
|
message: typeof b.message === 'string' ? b.message : undefined,
|
|
47
|
+
gatewayCode,
|
|
38
48
|
};
|
|
39
49
|
}
|
|
40
50
|
return {};
|
|
41
51
|
}
|
|
52
|
+
// The fixed wording of the gateway's and services' own 400s, e.g. "limit is out of range".
|
|
53
|
+
const FIELD_PROBLEM = /^([A-Za-z_]\w*) (?:is required|is out of range|is invalid)$/;
|
|
54
|
+
/** A non-2xx response → an `http` TransportError carrying the body's error code, and for a 400 the field it names. */
|
|
55
|
+
export function httpFailure(where, status, text, detail) {
|
|
56
|
+
const env = parseErrorEnvelope(text);
|
|
57
|
+
const message = (detail ?? env.message ?? text.slice(0, 300)).trim();
|
|
58
|
+
const field = status === 400 ? FIELD_PROBLEM.exec(message)?.[1] : undefined;
|
|
59
|
+
return new TransportError('http', `${where} -> ${status}: ${message}`, status, env.code, field, env);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The plan-limit error an `http` failure's body `error` field names (`planning_limit_reached`,
|
|
63
|
+
* `agreement_inactive`), whatever its status, or `undefined` when it names neither. A `code` field is not read.
|
|
64
|
+
*/
|
|
65
|
+
export function limitRefusal(e) {
|
|
66
|
+
if (e.kind !== 'http' || e.gatewayCode == null || !Object.hasOwn(LIMIT_MESSAGES, e.gatewayCode))
|
|
67
|
+
return undefined;
|
|
68
|
+
const code = e.gatewayCode;
|
|
69
|
+
return { code, message: e.serverMessage?.trim() || LIMIT_MESSAGES[code], httpStatus: e.httpStatus, serverCode: code };
|
|
70
|
+
}
|
|
42
71
|
export class DecodingError extends Error {
|
|
43
72
|
cause;
|
|
44
73
|
constructor(message, cause) {
|
|
@@ -59,14 +88,22 @@ function isAbort(e) {
|
|
|
59
88
|
export function toSpiderError(e) {
|
|
60
89
|
if (e instanceof TransportError) {
|
|
61
90
|
if (e.kind === 'http') {
|
|
91
|
+
// The body code decides whatever the status, since a proxy may rewrite it; plan limits have no status fallback.
|
|
92
|
+
const refusal = limitRefusal(e);
|
|
93
|
+
if (refusal != null)
|
|
94
|
+
return refusal;
|
|
62
95
|
const status = e.httpStatus ?? 0;
|
|
63
|
-
|
|
64
|
-
:
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
96
|
+
if (e.serverCode === QUERY_RETIRED || status === 410) {
|
|
97
|
+
return { code: 'query_retired', message: 'persisted query is retired', httpStatus: status, serverCode: e.serverCode };
|
|
98
|
+
}
|
|
99
|
+
const code = status === 400 ? 'bad_request'
|
|
100
|
+
: status === 401 || status === 403 ? 'unauthorized'
|
|
101
|
+
: status === 404 ? 'not_found'
|
|
102
|
+
: status === 408 || status === 504 ? 'timeout'
|
|
103
|
+
: status === 429 ? 'rate_limited'
|
|
104
|
+
: status >= 500 && status <= 599 ? 'server'
|
|
105
|
+
: 'unknown';
|
|
106
|
+
return { code, message: e.message, httpStatus: status, serverCode: e.serverCode, field: e.field };
|
|
70
107
|
}
|
|
71
108
|
if (e.kind === 'no_data')
|
|
72
109
|
return { code: 'not_found', message: e.message };
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAmCA,MAAM,aAAa,GAAG,eAAe,CAAC;AACtC,oHAAoH;AACpH,MAAM,cAAc,GAAG;IACrB,sBAAsB,EAAE,6BAA6B;IACrD,kBAAkB,EAAE,yBAAyB;CACc,CAAC;AAG9D,0FAA0F;AAC1F,MAAM,UAAU,UAAU,CACxB,KAAa,EACb,UAA4D,iBAAiB;IAE7E,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,OAAO,EAAE,GAAG,KAAK,IAAI,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC;AACxE,CAAC;AAID,MAAM,OAAO,cAAe,SAAQ,KAAK;IAC9B,IAAI,CAAqB;IACzB,UAAU,CAAqB;IAC/B,UAAU,CAAqB;IAC/B,KAAK,CAAqB;IACnC,0DAA0D;IACjD,aAAa,CAAqB;IAC3C,wGAAwG;IAC/F,WAAW,CAAqB;IAEzC,YAC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AY,SAAS;QAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;IACxF,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;AAC9D,CAAC"}
|
package/dist/http.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { TransportError } from './errors.ts';
|
|
1
2
|
export type FetchLike = typeof fetch;
|
|
2
3
|
export interface AutoRetryOptions {
|
|
3
4
|
readonly maxAttempts?: number;
|
|
@@ -24,6 +25,19 @@ export interface RawResponse {
|
|
|
24
25
|
readonly status: number;
|
|
25
26
|
readonly text: string;
|
|
26
27
|
}
|
|
28
|
+
export interface GraphQLError {
|
|
29
|
+
message: string;
|
|
30
|
+
extensions?: {
|
|
31
|
+
code?: string;
|
|
32
|
+
field?: string;
|
|
33
|
+
} | null;
|
|
34
|
+
}
|
|
35
|
+
export interface GraphQLEnvelope<D> {
|
|
36
|
+
data?: D | null;
|
|
37
|
+
errors?: ReadonlyArray<GraphQLError> | null;
|
|
38
|
+
}
|
|
39
|
+
/** A GraphQL `errors` array → a typed bad_request for a BAD_REQUEST extension (with its field), else upstream. */
|
|
40
|
+
export declare function graphqlFailure(where: string, errors: ReadonlyArray<GraphQLError>): TransportError;
|
|
27
41
|
export declare function parseJson<T>(text: string, where: string): T;
|
|
28
42
|
export declare class Transport {
|
|
29
43
|
private readonly baseUrl;
|
|
@@ -37,9 +51,33 @@ export declare class Transport {
|
|
|
37
51
|
path: string;
|
|
38
52
|
}, variables: unknown): Promise<D>;
|
|
39
53
|
postJson<D>(path: string, body: unknown, errorMessage?: (raw: string) => string): Promise<D>;
|
|
54
|
+
/**
|
|
55
|
+
* Opens a Server-Sent Events stream: POSTs `{ id, variables }` to `/routing/{op.path}` and returns the raw
|
|
56
|
+
* streaming {@link Response} for the caller to read frame-by-frame. Unlike {@link send}, it does not
|
|
57
|
+
* auto-retry — a streamed response is consumed over time, so retrying (or aborting once the body is
|
|
58
|
+
* flowing) makes no sense; the connect timeout guards only the initial handshake and is cleared the moment
|
|
59
|
+
* the response headers arrive, leaving the body to stream uninterrupted.
|
|
60
|
+
*/
|
|
61
|
+
stream(op: {
|
|
62
|
+
id: string;
|
|
63
|
+
path: string;
|
|
64
|
+
}, variables: unknown): Promise<Response>;
|
|
40
65
|
getJson<D>(path: string, query?: Record<string, string>): Promise<D>;
|
|
41
66
|
getRaw(path: string, query?: Record<string, string>): Promise<RawResponse>;
|
|
42
|
-
|
|
67
|
+
/**
|
|
68
|
+
* Best-effort connection warm-up. Issues one `GET {baseUrl}/ping`, authenticated with the
|
|
69
|
+
* client apikey, through this transport's own fetch, so the TLS handshake + connection it opens
|
|
70
|
+
* joins the per-origin pool and is reused by the first real call. Returns the measured
|
|
71
|
+
* round-trip in milliseconds.
|
|
72
|
+
*
|
|
73
|
+
* Never rejects: a network error, a timeout, or a non-2xx (e.g. a 401 against a keyless gateway,
|
|
74
|
+
* or a 404 before the `/ping` route is deployed) all still opened — or attempted to open — the
|
|
75
|
+
* connection, so the elapsed time is returned regardless. Only the apikey rides the request — it
|
|
76
|
+
* comes from the transport's shared request setup in `send()`; `/ping` is not contract-gated, so
|
|
77
|
+
* no contract/sdk headers are sent.
|
|
78
|
+
*/
|
|
79
|
+
ping(): Promise<number>;
|
|
80
|
+
private contractHeaders;
|
|
43
81
|
private send;
|
|
44
82
|
}
|
|
45
83
|
//# sourceMappingURL=http.d.ts.map
|
package/dist/http.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAEA,OAAO,EAAiB,cAAc,EAAe,MAAM,aAAa,C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AAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC;IAWhF;;;;;;;;;;;OAWG;IACG,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC;IAc7B,OAAO,CAAC,eAAe;YAOT,IAAI;CAkCnB"}
|
package/dist/http.js
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
import { CONTRACT_HEADER, CONTRACT_VERSION
|
|
1
|
+
import { CONTRACT_HEADER, CONTRACT_VERSION } from "./contract.js";
|
|
2
2
|
import { SDK_HEADER, SDK_IDENTITY } from "./sdk.js";
|
|
3
|
-
import { DecodingError, TransportError,
|
|
3
|
+
import { DecodingError, TransportError, httpFailure } from "./errors.js";
|
|
4
|
+
/** A GraphQL `errors` array → a typed bad_request for a BAD_REQUEST extension (with its field), else upstream. */
|
|
5
|
+
export function graphqlFailure(where, errors) {
|
|
6
|
+
const bad = errors.find((e) => e.extensions?.code === 'BAD_REQUEST');
|
|
7
|
+
if (bad != null) {
|
|
8
|
+
return new TransportError('bad_request', bad.message, undefined, undefined, bad.extensions?.field);
|
|
9
|
+
}
|
|
10
|
+
return new TransportError('upstream', `${where} errors: ${errors.map((e) => e.message).join(', ')}`);
|
|
11
|
+
}
|
|
4
12
|
export function parseJson(text, where) {
|
|
5
13
|
try {
|
|
6
14
|
return JSON.parse(text);
|
|
@@ -28,24 +36,15 @@ export class Transport {
|
|
|
28
36
|
async graphql(op, variables) {
|
|
29
37
|
const res = await this.send(`${this.baseUrl}/routing/${op.path}`, {
|
|
30
38
|
method: 'POST',
|
|
31
|
-
headers: this.
|
|
39
|
+
headers: this.contractHeaders({ 'content-type': 'application/json' }),
|
|
32
40
|
body: JSON.stringify({ id: op.id, variables }),
|
|
33
41
|
});
|
|
34
|
-
checkContract(res.headers.get(CONTRACT_HEADER));
|
|
35
42
|
const text = await res.text();
|
|
36
|
-
if (!res.ok)
|
|
37
|
-
|
|
38
|
-
const detail = env.message ?? text.slice(0, 300);
|
|
39
|
-
throw new TransportError('http', `routing ${op.path} -> ${res.status}: ${detail}`, res.status, env.code);
|
|
40
|
-
}
|
|
43
|
+
if (!res.ok)
|
|
44
|
+
throw httpFailure(`routing ${op.path}`, res.status, text);
|
|
41
45
|
const envelope = parseJson(text, `routing ${op.path}`);
|
|
42
46
|
if (envelope.errors != null && envelope.errors.length > 0) {
|
|
43
|
-
|
|
44
|
-
const bad = envelope.errors.find((e) => e.extensions?.code === 'BAD_REQUEST');
|
|
45
|
-
if (bad != null) {
|
|
46
|
-
throw new TransportError('bad_request', bad.message, undefined, undefined, bad.extensions?.field);
|
|
47
|
-
}
|
|
48
|
-
throw new TransportError('upstream', `routing ${op.path} errors: ${envelope.errors.map((e) => e.message).join(', ')}`);
|
|
47
|
+
throw graphqlFailure(`routing ${op.path}`, envelope.errors);
|
|
49
48
|
}
|
|
50
49
|
if (envelope.data == null) {
|
|
51
50
|
throw new TransportError('no_data', `routing ${op.path} returned no data`);
|
|
@@ -55,25 +54,42 @@ export class Transport {
|
|
|
55
54
|
async postJson(path, body, errorMessage) {
|
|
56
55
|
const res = await this.send(`${this.baseUrl}${path}`, {
|
|
57
56
|
method: 'POST',
|
|
58
|
-
headers: this.
|
|
57
|
+
headers: this.contractHeaders({ 'content-type': 'application/json' }),
|
|
59
58
|
body: JSON.stringify(body),
|
|
60
59
|
});
|
|
61
|
-
checkContract(res.headers.get(CONTRACT_HEADER));
|
|
62
60
|
const text = await res.text();
|
|
63
|
-
if (!res.ok)
|
|
64
|
-
|
|
65
|
-
const message = errorMessage ? errorMessage(text) : (env.message ?? text.slice(0, 300));
|
|
66
|
-
throw new TransportError('http', `POST ${path} -> ${res.status}: ${message}`, res.status, env.code);
|
|
67
|
-
}
|
|
61
|
+
if (!res.ok)
|
|
62
|
+
throw httpFailure(`POST ${path}`, res.status, text, errorMessage?.(text));
|
|
68
63
|
return parseJson(text, `POST ${path}`);
|
|
69
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* Opens a Server-Sent Events stream: POSTs `{ id, variables }` to `/routing/{op.path}` and returns the raw
|
|
67
|
+
* streaming {@link Response} for the caller to read frame-by-frame. Unlike {@link send}, it does not
|
|
68
|
+
* auto-retry — a streamed response is consumed over time, so retrying (or aborting once the body is
|
|
69
|
+
* flowing) makes no sense; the connect timeout guards only the initial handshake and is cleared the moment
|
|
70
|
+
* the response headers arrive, leaving the body to stream uninterrupted.
|
|
71
|
+
*/
|
|
72
|
+
async stream(op, variables) {
|
|
73
|
+
const headers = this.contractHeaders({ 'content-type': 'application/json', accept: 'text/event-stream' });
|
|
74
|
+
headers.set('apikey', this.apiKey);
|
|
75
|
+
const controller = new AbortController();
|
|
76
|
+
const timer = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
77
|
+
try {
|
|
78
|
+
return await this.doFetch(`${this.baseUrl}/routing/${op.path}`, {
|
|
79
|
+
method: 'POST',
|
|
80
|
+
headers,
|
|
81
|
+
body: JSON.stringify({ id: op.id, variables }),
|
|
82
|
+
signal: controller.signal,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
finally {
|
|
86
|
+
clearTimeout(timer);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
70
89
|
async getJson(path, query) {
|
|
71
90
|
const raw = await this.getRaw(path, query);
|
|
72
|
-
if (!raw.ok)
|
|
73
|
-
|
|
74
|
-
const detail = env.message ?? raw.text.slice(0, 300);
|
|
75
|
-
throw new TransportError('http', `GET ${path} -> ${raw.status}: ${detail}`, raw.status, env.code);
|
|
76
|
-
}
|
|
91
|
+
if (!raw.ok)
|
|
92
|
+
throw httpFailure(`GET ${path}`, raw.status, raw.text);
|
|
77
93
|
return parseJson(raw.text, `GET ${path}`);
|
|
78
94
|
}
|
|
79
95
|
async getRaw(path, query) {
|
|
@@ -83,18 +99,48 @@ export class Transport {
|
|
|
83
99
|
url.searchParams.set(key, value);
|
|
84
100
|
}
|
|
85
101
|
}
|
|
86
|
-
const res = await this.send(url.toString(), { method: 'GET', headers: this.
|
|
87
|
-
checkContract(res.headers.get(CONTRACT_HEADER));
|
|
102
|
+
const res = await this.send(url.toString(), { method: 'GET', headers: this.contractHeaders() });
|
|
88
103
|
return { ok: res.ok, status: res.status, text: await res.text() };
|
|
89
104
|
}
|
|
90
|
-
|
|
105
|
+
/**
|
|
106
|
+
* Best-effort connection warm-up. Issues one `GET {baseUrl}/ping`, authenticated with the
|
|
107
|
+
* client apikey, through this transport's own fetch, so the TLS handshake + connection it opens
|
|
108
|
+
* joins the per-origin pool and is reused by the first real call. Returns the measured
|
|
109
|
+
* round-trip in milliseconds.
|
|
110
|
+
*
|
|
111
|
+
* Never rejects: a network error, a timeout, or a non-2xx (e.g. a 401 against a keyless gateway,
|
|
112
|
+
* or a 404 before the `/ping` route is deployed) all still opened — or attempted to open — the
|
|
113
|
+
* connection, so the elapsed time is returned regardless. Only the apikey rides the request — it
|
|
114
|
+
* comes from the transport's shared request setup in `send()`; `/ping` is not contract-gated, so
|
|
115
|
+
* no contract/sdk headers are sent.
|
|
116
|
+
*/
|
|
117
|
+
async ping() {
|
|
118
|
+
const start = performance.now();
|
|
119
|
+
try {
|
|
120
|
+
const res = await this.send(`${this.baseUrl}/ping`, { method: 'GET' });
|
|
121
|
+
// Drain the body so the connection is released back to the pool for the first real call.
|
|
122
|
+
await res.text();
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
// Best-effort: the connection attempt itself is the warm-up — swallow every failure.
|
|
126
|
+
}
|
|
127
|
+
return performance.now() - start;
|
|
128
|
+
}
|
|
129
|
+
// Contract-gated calls carry the contract + sdk identity headers; the apikey is applied
|
|
130
|
+
// centrally in `send()`, so it's not set here.
|
|
131
|
+
contractHeaders(extra) {
|
|
91
132
|
const headers = new Headers(extra);
|
|
92
|
-
headers.set('apikey', this.apiKey);
|
|
93
133
|
headers.set(CONTRACT_HEADER, CONTRACT_VERSION);
|
|
94
134
|
headers.set(SDK_HEADER, SDK_IDENTITY);
|
|
95
135
|
return headers;
|
|
96
136
|
}
|
|
97
137
|
async send(url, init) {
|
|
138
|
+
// The client apikey is invariant for the client's whole life, so it's applied here on the
|
|
139
|
+
// shared request path — carried by every request (real calls and the warm-up) rather than
|
|
140
|
+
// re-attached per call.
|
|
141
|
+
const headers = new Headers(init.headers);
|
|
142
|
+
headers.set('apikey', this.apiKey);
|
|
143
|
+
const request = { ...init, headers };
|
|
98
144
|
const maxAttempts = this.retry?.maxAttempts ?? 1;
|
|
99
145
|
for (let attempt = 1;; attempt++) {
|
|
100
146
|
const controller = new AbortController();
|
|
@@ -102,7 +148,7 @@ export class Transport {
|
|
|
102
148
|
let res;
|
|
103
149
|
let err;
|
|
104
150
|
try {
|
|
105
|
-
res = await this.doFetch(url, { ...
|
|
151
|
+
res = await this.doFetch(url, { ...request, signal: controller.signal });
|
|
106
152
|
}
|
|
107
153
|
catch (e) {
|
|
108
154
|
err = e;
|
package/dist/http.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.js","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AA0CzE,kHAAkH;AAClH,MAAM,UAAU,cAAc,CAAC,KAAa,EAAE,MAAmC;IAC/E,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,EAAE,IAAI,KAAK,aAAa,CAAC,CAAC;IACrE,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;QAChB,OAAO,IAAI,cAAc,CAAC,aAAa,E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I,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;IAC3C,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC;AACtE,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,15 +2,14 @@ export { SpiderClient } from './client.ts';
|
|
|
2
2
|
export type { SpiderClientOptions, FetchLike, FeatureOptions, AutoRetryOptions } from './http.ts';
|
|
3
3
|
export type { SpiderResult } from './result.ts';
|
|
4
4
|
export type { SpiderError, SpiderErrorCode } from './errors.ts';
|
|
5
|
-
export { SpiderContractMismatchError } from './errors.ts';
|
|
6
5
|
export { Location, ViaLocation } from './location.ts';
|
|
7
|
-
export type { TransitMode, WheelchairBoarding, BikesAllowed, OccupancyStatus } from './enums.ts';
|
|
6
|
+
export type { TransitMode, WheelchairBoarding, BikesAllowed, OccupancyStatus, RealtimeState, RoutingErrorCode, InputField, } from './enums.ts';
|
|
8
7
|
export { SpiderRouting } from './routing.ts';
|
|
9
|
-
export type { Route, RouteEdge, Itinerary, Leg, LatLon, RoutePageInfo, RoutingError, Departure, TripDetails, TripStop, PlanOptions,
|
|
8
|
+
export type { Route, RouteEdge, Itinerary, Leg, LatLon, RoutePageInfo, RoutingError, Departure, TripDetails, TripStop, PlanOptions, PlanStreamRequestOptions, PlanStreamEvent, DeparturesOptions, } from './routing.ts';
|
|
10
9
|
export { SpiderStops } from './stops.ts';
|
|
11
10
|
export type { Stop, StopFilter, GeoPoint, GeoBoundingBox } from './stops.ts';
|
|
12
|
-
export { SpiderRealtime } from './realtime.ts';
|
|
13
|
-
export type { FeedFreshness, LiveVehicle, LiveVehicleUpdate, VehiclePositions, StopTimeUpdate, TripDelay, TripDelays, ServiceAlert, AlertActivePeriod, AlertInformedEntity, ServiceAlerts, } from './realtime.ts';
|
|
11
|
+
export { SpiderRealtime, delayFor } from './realtime.ts';
|
|
12
|
+
export type { FeedFreshness, LiveVehicle, LiveVehicleUpdate, VehiclePositions, StopTimeUpdate, TripDelay, ServiceDateDelays, TripDelays, ServiceAlert, AlertActivePeriod, AlertInformedEntity, ServiceAlerts, } from './realtime.ts';
|
|
14
13
|
export { pollVehicles, pollVehicleForTrip, pollDelays, pollAlerts } from './polling.ts';
|
|
15
14
|
export type { PollOptions } from './polling.ts';
|
|
16
15
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,YAAY,EAAE,mBAAmB,EAAE,SAAS,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAClG,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,YAAY,EAAE,mBAAmB,EAAE,SAAS,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAClG,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACtD,YAAY,EACV,WAAW,EACX,kBAAkB,EAClB,YAAY,EACZ,eAAe,EACf,aAAa,EACb,gBAAgB,EAChB,UAAU,GACX,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,YAAY,EACV,KAAK,EACL,SAAS,EACT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