hvv-client 0.0.2 → 0.0.3
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/build/src/client/hvvClient.d.ts +42 -0
- package/build/src/client/hvvClient.js +140 -0
- package/build/src/client/hvvClient.js.map +1 -0
- package/build/src/client/hvvClientOptions.d.ts +6 -0
- package/build/src/client/hvvClientOptions.js +3 -0
- package/build/src/client/hvvClientOptions.js.map +1 -0
- package/build/src/converters/attributes.converter.d.ts +5 -0
- package/build/src/converters/attributes.converter.js +15 -0
- package/build/src/converters/attributes.converter.js.map +1 -0
- package/build/src/converters/date.converter.d.ts +31 -0
- package/build/src/converters/date.converter.js +70 -0
- package/build/src/converters/date.converter.js.map +1 -0
- package/build/src/converters/line.converter.d.ts +10 -0
- package/build/src/converters/line.converter.js +48 -0
- package/build/src/converters/line.converter.js.map +1 -0
- package/build/src/converters/lineDepartureConverter.d.ts +5 -0
- package/build/src/converters/lineDepartureConverter.js +35 -0
- package/build/src/converters/lineDepartureConverter.js.map +1 -0
- package/build/src/converters/routePoint.converter.d.ts +10 -0
- package/build/src/converters/routePoint.converter.js +147 -0
- package/build/src/converters/routePoint.converter.js.map +1 -0
- package/build/src/index.d.ts +2 -0
- package/build/src/index.js +19 -0
- package/build/src/index.js.map +1 -0
- package/build/src/models/attribute.d.ts +7 -0
- package/build/src/models/attribute.js +3 -0
- package/build/src/models/attribute.js.map +1 -0
- package/build/src/models/coordinate.d.ts +4 -0
- package/build/src/models/coordinate.js +3 -0
- package/build/src/models/coordinate.js.map +1 -0
- package/build/src/models/coordinates.d.ts +4 -0
- package/build/src/models/coordinates.js +3 -0
- package/build/src/models/coordinates.js.map +1 -0
- package/build/src/models/direction.d.ts +1 -0
- package/build/src/models/direction.js +3 -0
- package/build/src/models/direction.js.map +1 -0
- package/build/src/models/filter.d.ts +1 -0
- package/build/src/models/filter.js +3 -0
- package/build/src/models/filter.js.map +1 -0
- package/build/src/models/line.d.ts +50 -0
- package/build/src/models/line.js +38 -0
- package/build/src/models/line.js.map +1 -0
- package/build/src/models/lineDeparture.d.ts +13 -0
- package/build/src/models/lineDeparture.js +3 -0
- package/build/src/models/lineDeparture.js.map +1 -0
- package/build/src/models/routePoint.d.ts +30 -0
- package/build/src/models/routePoint.js +3 -0
- package/build/src/models/routePoint.js.map +1 -0
- package/build/src/models/service.d.ts +1 -0
- package/build/src/models/service.js +11 -0
- package/build/src/models/service.js.map +1 -0
- package/build/src/models/stationDepartureInfo.d.ts +5 -0
- package/build/src/models/stationDepartureInfo.js +3 -0
- package/build/src/models/stationDepartureInfo.js.map +1 -0
- package/build/src/models/timeRange.d.ts +4 -0
- package/build/src/models/timeRange.js +3 -0
- package/build/src/models/timeRange.js.map +1 -0
- package/build/src/models/timeRealtime.d.ts +17 -0
- package/build/src/models/timeRealtime.js +3 -0
- package/build/src/models/timeRealtime.js.map +1 -0
- package/build/src/validators/apiResponse/gtiCheckName.d.ts +1024 -0
- package/build/src/validators/apiResponse/gtiCheckName.js +19 -0
- package/build/src/validators/apiResponse/gtiCheckName.js.map +1 -0
- package/build/src/validators/apiResponse/gtiDepartureList.d.ts +250 -0
- package/build/src/validators/apiResponse/gtiDepartureList.js +13 -0
- package/build/src/validators/apiResponse/gtiDepartureList.js.map +1 -0
- package/build/src/validators/gtiAttribute.d.ts +19 -0
- package/build/src/validators/gtiAttribute.js +21 -0
- package/build/src/validators/gtiAttribute.js.map +1 -0
- package/build/src/validators/gtiCoordinate.d.ts +11 -0
- package/build/src/validators/gtiCoordinate.js +9 -0
- package/build/src/validators/gtiCoordinate.js.map +1 -0
- package/build/src/validators/gtiDeparture.d.ts +165 -0
- package/build/src/validators/gtiDeparture.js +40 -0
- package/build/src/validators/gtiDeparture.js.map +1 -0
- package/build/src/validators/gtiDirection.d.ts +9 -0
- package/build/src/validators/gtiDirection.js +14 -0
- package/build/src/validators/gtiDirection.js.map +1 -0
- package/build/src/validators/gtiFilterEntry.d.ts +17 -0
- package/build/src/validators/gtiFilterEntry.js +11 -0
- package/build/src/validators/gtiFilterEntry.js.map +1 -0
- package/build/src/validators/gtiFilterServiceType.d.ts +2 -0
- package/build/src/validators/gtiFilterServiceType.js +21 -0
- package/build/src/validators/gtiFilterServiceType.js.map +1 -0
- package/build/src/validators/gtiSDName.d.ts +702 -0
- package/build/src/validators/gtiSDName.js +45 -0
- package/build/src/validators/gtiSDName.js.map +1 -0
- package/build/src/validators/gtiService.d.ts +206 -0
- package/build/src/validators/gtiService.js +93 -0
- package/build/src/validators/gtiService.js.map +1 -0
- package/build/src/validators/gtiServiceType.d.ts +2 -0
- package/build/src/validators/gtiServiceType.js +16 -0
- package/build/src/validators/gtiServiceType.js.map +1 -0
- package/build/src/validators/gtiTariffDetails.d.ts +41 -0
- package/build/src/validators/gtiTariffDetails.js +19 -0
- package/build/src/validators/gtiTariffDetails.js.map +1 -0
- package/build/src/validators/validator.d.ts +250 -0
- package/build/src/validators/validator.js +13 -0
- package/build/src/validators/validator.js.map +1 -0
- package/build/tsconfig.tsbuildinfo +1 -0
- package/package.json +4 -3
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { HvvClientOptions } from './hvvClientOptions';
|
|
2
|
+
import { RoutePointStation, RoutePointStationSimple } from '../models/routePoint';
|
|
3
|
+
import { Filter } from '../models/filter';
|
|
4
|
+
import { Service } from '../models/service';
|
|
5
|
+
import { StationDepartureInfo } from '../models/stationDepartureInfo';
|
|
6
|
+
import { Coordinate } from '../models/coordinate';
|
|
7
|
+
export declare class HvvClient {
|
|
8
|
+
private readonly options;
|
|
9
|
+
constructor(options: HvvClientOptions);
|
|
10
|
+
/**
|
|
11
|
+
*
|
|
12
|
+
*/
|
|
13
|
+
getNearbyStations({ coordinate, maxDistanceMeters, returnTariffDetails, }: {
|
|
14
|
+
coordinate: Coordinate;
|
|
15
|
+
maxDistanceMeters: number;
|
|
16
|
+
returnTariffDetails?: boolean;
|
|
17
|
+
}): Promise<{
|
|
18
|
+
stations: {
|
|
19
|
+
routePoint: RoutePointStation;
|
|
20
|
+
distanceMeters: number;
|
|
21
|
+
walkingDistanceMinutes: number;
|
|
22
|
+
}[];
|
|
23
|
+
}>;
|
|
24
|
+
/**
|
|
25
|
+
* Get departures of a given station.
|
|
26
|
+
*/
|
|
27
|
+
getDepartures({ stations, time, filters, serviceFilters, realtime, maxResults, maxOffsetMinutes, allStationsInChangingNode, returnFilters, }: {
|
|
28
|
+
stations: RoutePointStationSimple[];
|
|
29
|
+
time: Date;
|
|
30
|
+
filters?: Filter[];
|
|
31
|
+
serviceFilters?: Service[];
|
|
32
|
+
realtime?: boolean;
|
|
33
|
+
maxResults?: number;
|
|
34
|
+
maxOffsetMinutes?: number;
|
|
35
|
+
allStationsInChangingNode?: boolean;
|
|
36
|
+
returnFilters?: boolean;
|
|
37
|
+
}): Promise<{
|
|
38
|
+
departures: StationDepartureInfo[];
|
|
39
|
+
}>;
|
|
40
|
+
private makeRequest;
|
|
41
|
+
private getAuthHeaders;
|
|
42
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.HvvClient = void 0;
|
|
13
|
+
const hmac_sha1_1 = require("crypto-js/hmac-sha1");
|
|
14
|
+
const enc_base64_1 = require("crypto-js/enc-base64");
|
|
15
|
+
const date_converter_1 = require("../converters/date.converter");
|
|
16
|
+
const gtiDepartureList_1 = require("../validators/apiResponse/gtiDepartureList");
|
|
17
|
+
const lineDepartureConverter_1 = require("../converters/lineDepartureConverter");
|
|
18
|
+
const routePoint_converter_1 = require("../converters/routePoint.converter");
|
|
19
|
+
const gtiCheckName_1 = require("../validators/apiResponse/gtiCheckName");
|
|
20
|
+
const defaultOptions = {
|
|
21
|
+
user: '',
|
|
22
|
+
key: '',
|
|
23
|
+
version: 59,
|
|
24
|
+
host: 'https://gti.geofox.de',
|
|
25
|
+
};
|
|
26
|
+
class HvvClient {
|
|
27
|
+
constructor(options) {
|
|
28
|
+
this.options = Object.assign(Object.assign({}, defaultOptions), options);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
*
|
|
32
|
+
*/
|
|
33
|
+
getNearbyStations(_a) {
|
|
34
|
+
return __awaiter(this, arguments, void 0, function* ({ coordinate, maxDistanceMeters = 800, returnTariffDetails = false, }) {
|
|
35
|
+
const body = {
|
|
36
|
+
theName: {
|
|
37
|
+
type: 'STATION',
|
|
38
|
+
coordinate: {
|
|
39
|
+
x: coordinate.long,
|
|
40
|
+
y: coordinate.lat,
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
maxDistance: maxDistanceMeters,
|
|
44
|
+
coordinateType: 'EPSG_4326',
|
|
45
|
+
tariffDetails: returnTariffDetails,
|
|
46
|
+
allowTypeSwitch: false,
|
|
47
|
+
};
|
|
48
|
+
return yield this.makeRequest({
|
|
49
|
+
endpoint: 'checkName',
|
|
50
|
+
body,
|
|
51
|
+
validator: gtiCheckName_1.gtiCheckNameCoordinatesResponseSchema,
|
|
52
|
+
converter: data => {
|
|
53
|
+
// filter stations
|
|
54
|
+
const filtered = data.results.filter(item => {
|
|
55
|
+
return item.type === 'STATION';
|
|
56
|
+
});
|
|
57
|
+
return {
|
|
58
|
+
stations: filtered.map(result => ({
|
|
59
|
+
routePoint: routePoint_converter_1.routePointConverter.stationToDto(result),
|
|
60
|
+
distanceMeters: result.distance,
|
|
61
|
+
walkingDistanceMinutes: result.time,
|
|
62
|
+
})),
|
|
63
|
+
};
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Get departures of a given station.
|
|
70
|
+
*/
|
|
71
|
+
getDepartures(_a) {
|
|
72
|
+
return __awaiter(this, arguments, void 0, function* ({ stations, time, filters, serviceFilters, realtime = true, maxResults = 4, maxOffsetMinutes = 60, allStationsInChangingNode = true, returnFilters = false, }) {
|
|
73
|
+
const body = {
|
|
74
|
+
stations: stations.map(routePoint_converter_1.routePointConverter.dtoToGti),
|
|
75
|
+
time: date_converter_1.dateConverter.dateToGtiTime(time),
|
|
76
|
+
maxList: maxResults,
|
|
77
|
+
maxTimeOffset: maxOffsetMinutes,
|
|
78
|
+
allStationsInChangingNode: allStationsInChangingNode,
|
|
79
|
+
returnFilters: returnFilters,
|
|
80
|
+
useRealtime: realtime,
|
|
81
|
+
};
|
|
82
|
+
if (filters !== undefined) {
|
|
83
|
+
body.filter = filters;
|
|
84
|
+
}
|
|
85
|
+
if (serviceFilters !== undefined) {
|
|
86
|
+
body.serviceTypes = serviceFilters;
|
|
87
|
+
}
|
|
88
|
+
return yield this.makeRequest({
|
|
89
|
+
endpoint: 'departureList',
|
|
90
|
+
body,
|
|
91
|
+
validator: gtiDepartureList_1.gtiDepartureListResponseSchema,
|
|
92
|
+
converter: data => {
|
|
93
|
+
const departures = data.departures.map(departure => {
|
|
94
|
+
var _a, _b;
|
|
95
|
+
return ({
|
|
96
|
+
stationId: (_b = (_a = departure.station) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : null,
|
|
97
|
+
departure: lineDepartureConverter_1.lineDepartureConverter.toDto(departure, time),
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
return {
|
|
101
|
+
departures: departures,
|
|
102
|
+
// TODO: other fields?
|
|
103
|
+
};
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
// ---
|
|
109
|
+
makeRequest(_a) {
|
|
110
|
+
return __awaiter(this, arguments, void 0, function* ({ endpoint, body, validator, converter, }) {
|
|
111
|
+
const fullBody = Object.assign({ version: this.options.version }, body);
|
|
112
|
+
const headers = Object.assign(Object.assign({}, this.getAuthHeaders(fullBody)), { 'Content-Type': 'application/json' });
|
|
113
|
+
console.log('full API request body', fullBody);
|
|
114
|
+
const response = yield fetch(`${this.options.host}/gti/public/${endpoint}`, {
|
|
115
|
+
method: 'POST',
|
|
116
|
+
body: JSON.stringify(fullBody),
|
|
117
|
+
headers,
|
|
118
|
+
});
|
|
119
|
+
const responseBody = yield response.json();
|
|
120
|
+
console.dir(responseBody);
|
|
121
|
+
const { success, data, error } = validator.safeParse(responseBody);
|
|
122
|
+
if (!success) {
|
|
123
|
+
// eslint-disable-next-line no-debugger
|
|
124
|
+
debugger;
|
|
125
|
+
throw error;
|
|
126
|
+
}
|
|
127
|
+
return converter(data);
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
getAuthHeaders(requestBody) {
|
|
131
|
+
const hmac = (0, hmac_sha1_1.default)(JSON.stringify(requestBody), this.options.key);
|
|
132
|
+
const signature = enc_base64_1.default.stringify(hmac);
|
|
133
|
+
return {
|
|
134
|
+
'geofox-auth-user': this.options.user,
|
|
135
|
+
'geofox-auth-signature': signature,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
exports.HvvClient = HvvClient;
|
|
140
|
+
//# sourceMappingURL=hvvClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hvvClient.js","sourceRoot":"","sources":["../../../src/client/hvvClient.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,mDAA2C;AAC3C,qDAA0C;AAO1C,iEAA2D;AAC3D,iFAA0F;AAC1F,iFAA4E;AAC5E,6EAAuE;AAEvE,yEAA6F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kBAAkB,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI;YACrC,uBAAuB,EAAE,SAAS;SACnC,CAAC;IACJ,CAAC;CACF;AApLD,8BAoLC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hvvClientOptions.js","sourceRoot":"","sources":["../../../src/client/hvvClientOptions.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.attributeConverter = void 0;
|
|
4
|
+
exports.attributeConverter = {
|
|
5
|
+
toDto(gti) {
|
|
6
|
+
var _a;
|
|
7
|
+
return {
|
|
8
|
+
id: (_a = gti.id) !== null && _a !== void 0 ? _a : null,
|
|
9
|
+
isPlanned: gti.isPlanned,
|
|
10
|
+
value: gti.value,
|
|
11
|
+
types: gti.types,
|
|
12
|
+
};
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=attributes.converter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attributes.converter.js","sourceRoot":"","sources":["../../../src/converters/attributes.converter.ts"],"names":[],"mappings":";;;AAGa,QAAA,kBAAkB,GAAG;IAChC,KAAK,CAAC,GAAiB;;QACrB,OAAO;YACL,EAAE,EAAE,MAAA,GAAG,CAAC,EAAE,mCAAI,IAAI;YAClB,SAAS,EAAE,GAAG,CAAC,SAAS;YACxB,KAAK,EAAE,GAAG,CAAC,KAAK;YAChB,KAAK,EAAE,GAAG,CAAC,KAAK;SACjB,CAAC;IACJ,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { TimeRealtime } from '../models/timeRealtime';
|
|
2
|
+
import { TimeRange } from '../models/timeRange';
|
|
3
|
+
export type GtiTime = {
|
|
4
|
+
date: string;
|
|
5
|
+
time: string;
|
|
6
|
+
};
|
|
7
|
+
export type GtiTimeRange = {
|
|
8
|
+
begin: string;
|
|
9
|
+
end: string;
|
|
10
|
+
};
|
|
11
|
+
export declare const dateConverter: {
|
|
12
|
+
/**
|
|
13
|
+
* Converts a Date into the DateTime object required by the Geofox API (GTI).
|
|
14
|
+
* @param date
|
|
15
|
+
*/
|
|
16
|
+
dateToGtiTime(date: Date): GtiTime;
|
|
17
|
+
/**
|
|
18
|
+
* Converts a date into a `DateTime` string used by the Geofox API.
|
|
19
|
+
* This is not a standard ISO string, as the docs require a timezone offset at the end.
|
|
20
|
+
* The default `.toISOString()` generates something like:
|
|
21
|
+
* `2024-11-02T09:58:00.000Z`, however the Geofox API expects something like
|
|
22
|
+
* `2024-11-02T09:58:00.000+0000`
|
|
23
|
+
* @param date
|
|
24
|
+
*/
|
|
25
|
+
dateToApiDateTime(date: Date): string;
|
|
26
|
+
apiDateTimeToDate(apiDateTime: string): Date;
|
|
27
|
+
gtiTimeToDate(gtiTime: GtiTime): Date;
|
|
28
|
+
gtiTimeRangeToDto(gtiTimeRange: GtiTimeRange): TimeRange;
|
|
29
|
+
gtiTimeRealtimeCancelToDto(gtiTime: GtiTime, delaySeconds: number | null, isCancelled: boolean): TimeRealtime;
|
|
30
|
+
apiTimeRealtimeToDto(apiDateTime: string, delaySeconds: number | null): TimeRealtime;
|
|
31
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dateConverter = void 0;
|
|
4
|
+
const date_fns_tz_1 = require("date-fns-tz");
|
|
5
|
+
const date_fns_1 = require("date-fns");
|
|
6
|
+
const GTI_TIMEZONE = 'Europe/Berlin';
|
|
7
|
+
exports.dateConverter = {
|
|
8
|
+
/**
|
|
9
|
+
* Converts a Date into the DateTime object required by the Geofox API (GTI).
|
|
10
|
+
* @param date
|
|
11
|
+
*/
|
|
12
|
+
dateToGtiTime(date) {
|
|
13
|
+
// Geofox dates must always be in german timezone as it does not accept ISO dates.
|
|
14
|
+
// Figure out german timezone and respect that when converting to GtiTime.
|
|
15
|
+
// convert to germany time
|
|
16
|
+
const germanyTime = (0, date_fns_tz_1.toZonedTime)(date, GTI_TIMEZONE);
|
|
17
|
+
const gti = {
|
|
18
|
+
date: (0, date_fns_tz_1.format)(germanyTime, 'dd.MM.y'),
|
|
19
|
+
time: (0, date_fns_tz_1.format)(germanyTime, 'HH:mm'),
|
|
20
|
+
};
|
|
21
|
+
return gti;
|
|
22
|
+
},
|
|
23
|
+
/**
|
|
24
|
+
* Converts a date into a `DateTime` string used by the Geofox API.
|
|
25
|
+
* This is not a standard ISO string, as the docs require a timezone offset at the end.
|
|
26
|
+
* The default `.toISOString()` generates something like:
|
|
27
|
+
* `2024-11-02T09:58:00.000Z`, however the Geofox API expects something like
|
|
28
|
+
* `2024-11-02T09:58:00.000+0000`
|
|
29
|
+
* @param date
|
|
30
|
+
*/
|
|
31
|
+
dateToApiDateTime(date) {
|
|
32
|
+
const isoString = date.toISOString();
|
|
33
|
+
// remove last letter from isoString
|
|
34
|
+
return isoString.slice(0, -1) + '+0000';
|
|
35
|
+
},
|
|
36
|
+
apiDateTimeToDate(apiDateTime) {
|
|
37
|
+
return new Date(apiDateTime);
|
|
38
|
+
},
|
|
39
|
+
gtiTimeToDate(gtiTime) {
|
|
40
|
+
const dateParts = gtiTime.date.split('.');
|
|
41
|
+
const germanyTime = new Date(`${dateParts[2]}-${dateParts[1]}-${dateParts[0]}T${gtiTime.time}`);
|
|
42
|
+
const utc = (0, date_fns_tz_1.fromZonedTime)(germanyTime, GTI_TIMEZONE);
|
|
43
|
+
return utc;
|
|
44
|
+
},
|
|
45
|
+
gtiTimeRangeToDto(gtiTimeRange) {
|
|
46
|
+
const fromDateGermanyTime = new Date(gtiTimeRange.begin);
|
|
47
|
+
const toDateGermanyTime = new Date(gtiTimeRange.end);
|
|
48
|
+
return {
|
|
49
|
+
from: (0, date_fns_tz_1.fromZonedTime)(fromDateGermanyTime, GTI_TIMEZONE),
|
|
50
|
+
to: (0, date_fns_tz_1.fromZonedTime)(toDateGermanyTime, GTI_TIMEZONE),
|
|
51
|
+
};
|
|
52
|
+
},
|
|
53
|
+
gtiTimeRealtimeCancelToDto(gtiTime, delaySeconds, isCancelled) {
|
|
54
|
+
const planned = exports.dateConverter.gtiTimeToDate(gtiTime);
|
|
55
|
+
return {
|
|
56
|
+
planned,
|
|
57
|
+
actual: isCancelled ? null : (0, date_fns_1.addSeconds)(planned, delaySeconds !== null && delaySeconds !== void 0 ? delaySeconds : 0),
|
|
58
|
+
delaySeconds,
|
|
59
|
+
};
|
|
60
|
+
},
|
|
61
|
+
apiTimeRealtimeToDto(apiDateTime, delaySeconds) {
|
|
62
|
+
const planned = exports.dateConverter.apiDateTimeToDate(apiDateTime);
|
|
63
|
+
return {
|
|
64
|
+
planned,
|
|
65
|
+
actual: (0, date_fns_1.addSeconds)(planned, delaySeconds !== null && delaySeconds !== void 0 ? delaySeconds : 0),
|
|
66
|
+
delaySeconds,
|
|
67
|
+
};
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
//# sourceMappingURL=date.converter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date.converter.js","sourceRoot":"","sources":["../../../src/converters/date.converter.ts"],"names":[],"mappings":";;;AAAA,6CAA+D;AAC/D,uCAAoC;AAOpC,MAAM,YAAY,GAAG,eAAe,CAAC;AAExB,QAAA,aAAa,GAAG;IAC3B;;;OAGG;IACH,aAAa,CAAC,IAAU;QACtB,kFAAkF;QAClF,0EAA0E;QAE1E,0BAA0B;QAC1B,MAAM,WAAW,GAAG,IAAA,yBAAW,EAAC,IAAI,EAAE,YAAY,CAAC,CAAC;QAEpD,MAAM,GAAG,GAAG;YACV,IAAI,EAAE,IAAA,oBAAM,EAAC,WAAW,EAAE,SAAS,CAAC;YACpC,IAAI,EAAE,IAAA,oBAAM,EAAC,WAAW,EAAE,OAAO,CAAC;SACnC,CAAC;QAEF,OAAO,GAAG,CAAC;IACb,CAAC;IA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,IAAA,qBAAU,EAAC,OAAO,EAAE,YAAY,aAAZ,YAAY,cAAZ,YAAY,GAAI,CAAC,CAAC;YACnE,YAAY;SACb,CAAC;IACJ,CAAC;IAED,oBAAoB,CAClB,WAAmB,EACnB,YAA2B;QAE3B,MAAM,OAAO,GAAG,qBAAa,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC;QAE7D,OAAO;YACL,OAAO;YACP,MAAM,EAAE,IAAA,qBAAU,EAAC,OAAO,EAAE,YAAY,aAAZ,YAAY,cAAZ,YAAY,GAAI,CAAC,CAAC;YAC9C,YAAY;SACb,CAAC;IACJ,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.lineConverter = void 0;
|
|
4
|
+
const gtiService_1 = require("../validators/gtiService");
|
|
5
|
+
const gtiDirection_1 = require("../validators/gtiDirection");
|
|
6
|
+
function getLineImageUrl(lineId) {
|
|
7
|
+
return `https://cloud.geofox.de/icon/line?height=28&lineKey=${lineId}`;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Converter for a `Line`.
|
|
11
|
+
*
|
|
12
|
+
* In Geofox, this is called a `Service`.
|
|
13
|
+
*/
|
|
14
|
+
exports.lineConverter = {
|
|
15
|
+
toDto(gti) {
|
|
16
|
+
const base = {
|
|
17
|
+
name: gti.name,
|
|
18
|
+
};
|
|
19
|
+
if ((0, gtiService_1.isGtiServicePublicTransport)(gti)) {
|
|
20
|
+
switch (gti.type.simpleType) {
|
|
21
|
+
case gtiService_1.GtiSimpleServiceType.BUS:
|
|
22
|
+
return Object.assign(Object.assign({}, base), { type: 'bus', direction: gti.direction, directionType: gti.directionId === gtiDirection_1.GtiDirection.FORWARDS
|
|
23
|
+
? 'forward'
|
|
24
|
+
: 'backward', id: gti.id, iconUrl: getLineImageUrl(gti.id) });
|
|
25
|
+
case gtiService_1.GtiSimpleServiceType.TRAIN:
|
|
26
|
+
return Object.assign(Object.assign({}, base), { type: 'train', direction: gti.direction, directionType: gti.directionId === gtiDirection_1.GtiDirection.FORWARDS
|
|
27
|
+
? 'forward'
|
|
28
|
+
: 'backward', id: gti.id, iconUrl: getLineImageUrl(gti.id) });
|
|
29
|
+
case gtiService_1.GtiSimpleServiceType.SHIP:
|
|
30
|
+
return Object.assign(Object.assign({}, base), { type: 'ship', direction: gti.direction, directionType: gti.directionId === gtiDirection_1.GtiDirection.FORWARDS
|
|
31
|
+
? 'forward'
|
|
32
|
+
: 'backward', id: gti.id, iconUrl: getLineImageUrl(gti.id) });
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
switch (gti.type.simpleType) {
|
|
36
|
+
case gtiService_1.GtiSimpleServiceType.BICYCLE:
|
|
37
|
+
return Object.assign(Object.assign({}, base), { type: 'bicycle' });
|
|
38
|
+
case gtiService_1.GtiSimpleServiceType.FOOTPATH:
|
|
39
|
+
return Object.assign(Object.assign({}, base), { type: 'footwalk' });
|
|
40
|
+
case gtiService_1.GtiSimpleServiceType.CHANGE:
|
|
41
|
+
return Object.assign(Object.assign({}, base), { type: 'changeStation' });
|
|
42
|
+
case gtiService_1.GtiSimpleServiceType.CHANGE_SAME_PLATFORM:
|
|
43
|
+
return Object.assign(Object.assign({}, base), { type: 'changePlatform' });
|
|
44
|
+
}
|
|
45
|
+
throw new Error(`unknown line type: ${gti.type.simpleType}`);
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=line.converter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"line.converter.js","sourceRoot":"","sources":["../../../src/converters/line.converter.ts"],"names":[],"mappings":";;;AAAA,yDAIkC;AAClC,6DAAwD;AAGxD,SAAS,eAAe,CAAC,MAAc;IACrC,OAAO,uDAAuD,MAAM,EAAE,CAAC;AACzE,CAAC;AAED;;;;GAIG;AACU,QAAA,aAAa,GAAG;IAC3B,KAAK,CAAC,GA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AAoB,CAAC,OAAO;gBAC/B,uCACK,IAAI,KACP,IAAI,EAAE,SAAS,IACf;YACJ,KAAK,iCAAoB,CAAC,QAAQ;gBAChC,uCACK,IAAI,KACP,IAAI,EAAE,UAAU,IAChB;YACJ,KAAK,iCAAoB,CAAC,MAAM;gBAC9B,uCACK,IAAI,KACP,IAAI,EAAE,eAAe,IACrB;YACJ,KAAK,iCAAoB,CAAC,oBAAoB;gBAC5C,uCACK,IAAI,KACP,IAAI,EAAE,gBAAgB,IACtB;QACN,CAAC;QAED,MAAM,IAAI,KAAK,CAAC,sBAAsB,GAAG,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;IAC/D,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.lineDepartureConverter = void 0;
|
|
4
|
+
const date_fns_1 = require("date-fns");
|
|
5
|
+
const line_converter_1 = require("./line.converter");
|
|
6
|
+
const line_1 = require("../models/line");
|
|
7
|
+
const attributes_converter_1 = require("./attributes.converter");
|
|
8
|
+
exports.lineDepartureConverter = {
|
|
9
|
+
toDto(gti, referenceTime) {
|
|
10
|
+
var _a, _b, _c, _d, _e, _f;
|
|
11
|
+
const isCancelled = (_a = gti.cancelled) !== null && _a !== void 0 ? _a : false;
|
|
12
|
+
const delaySeconds = (_b = gti.delay) !== null && _b !== void 0 ? _b : null;
|
|
13
|
+
const planned = (0, date_fns_1.addMinutes)(referenceTime, gti.timeOffset);
|
|
14
|
+
const actual = isCancelled ? null : (0, date_fns_1.addSeconds)(planned, delaySeconds !== null && delaySeconds !== void 0 ? delaySeconds : 0);
|
|
15
|
+
const line = line_converter_1.lineConverter.toDto(Object.assign({ directionId: gti.directionId }, gti.line));
|
|
16
|
+
if (!(0, line_1.isLinePublicTransport)(line)) {
|
|
17
|
+
throw new Error('Invalid line: not public transport');
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
line,
|
|
21
|
+
departure: {
|
|
22
|
+
planned,
|
|
23
|
+
actual,
|
|
24
|
+
delaySeconds,
|
|
25
|
+
},
|
|
26
|
+
departurePlatformPlanned: (_c = gti.platform) !== null && _c !== void 0 ? _c : null,
|
|
27
|
+
departurePlatformActual: (_d = gti.realtimePlatform) !== null && _d !== void 0 ? _d : null,
|
|
28
|
+
attributes: ((_e = gti.attributes) !== null && _e !== void 0 ? _e : []).map(att => attributes_converter_1.attributeConverter.toDto(att)),
|
|
29
|
+
isExtra: (_f = gti.extra) !== null && _f !== void 0 ? _f : false,
|
|
30
|
+
isCancelled,
|
|
31
|
+
uniqueServiceId: gti.serviceId,
|
|
32
|
+
};
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=lineDepartureConverter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lineDepartureConverter.js","sourceRoot":"","sources":["../../../src/converters/lineDepartureConverter.ts"],"names":[],"mappings":";;;AAAA,uCAAgD;AAEhD,qDAA+C;AAI/C,yCAAqD;AACrD,iEAA0D;AAE7C,QAAA,sBAAsB,GAAG;IACpC,KAAK,CAAC,GAAiB,EAAE,aAAmB;;QAC1C,MAAM,WAAW,GAAG,MAAA,GAAG,CAAC,SAAS,mCAAI,KAAK,CAAC;QAC3C,MAAM,YAAY,GAAG,MAAA,GAAG,CAAC,KAAK,mCAAI,IAAI,CAAC;QACvC,MAAM,OAAO,GAAG,IAAA,qBAAU,EAAC,aAAa,EAAE,GAAG,CAAC,UAAU,CAAC,CAAC;QAC1D,MAAM,MAAM,GAAG,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAA,qBAAU,EAAC,OAAO,EAAE,YAAY,aAAZ,YAAY,cAAZ,YAAY,GAAI,CAAC,CAAC,CAAC;QAE3E,MAAM,IAAI,GAAG,8BAAa,CAAC,KAAK,iBAC9B,WAAW,EAAE,GAAG,CAAC,WAAW,IACzB,GAAG,CAAC,IAAI,EACX,CAAC;QACH,IAAI,CAAC,IAAA,4BAAqB,EAAC,IAAI,CAAC,EAAE,CAAC;YACjC,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;QACxD,CAAC;QAED,OAAO;YACL,IAAI;YACJ,SAAS,EAAE;gBACT,OAAO;gBACP,MAAM;gBACN,YAAY;aACb;YACD,wBAAwB,EAAE,MAAA,GAAG,CAAC,QAAQ,mCAAI,IAAI;YAC9C,uBAAuB,EAAE,MAAA,GAAG,CAAC,gBAAgB,mCAAI,IAAI;YACrD,UAAU,EAAE,CAAC,MAAA,GAAG,CAAC,UAAU,mCAAI,EAAE,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAC3C,yCAAkB,CAAC,KAAK,CAAC,GAAG,CAAC,CAC9B;YACD,OAAO,EAAE,MAAA,GAAG,CAAC,KAAK,mCAAI,KAAK;YAC3B,WAAW;YACX,eAAe,EAAE,GAAG,CAAC,SAAS;SAC/B,CAAC;IACJ,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { RoutePoint, RoutePointStation, RoutePointStationSimple } from '../models/routePoint';
|
|
2
|
+
import { GtiSDName, GtiSDNameRequest, GtiSDNameStation } from '../validators/gtiSDName';
|
|
3
|
+
declare function stationToDto(gti: GtiSDNameStation): RoutePointStation;
|
|
4
|
+
declare function toDto(gti: GtiSDName): RoutePoint;
|
|
5
|
+
export declare const routePointConverter: {
|
|
6
|
+
stationToDto: typeof stationToDto;
|
|
7
|
+
toDto: typeof toDto;
|
|
8
|
+
dtoToGti(dto: RoutePoint | RoutePointStationSimple): GtiSDNameRequest;
|
|
9
|
+
};
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.routePointConverter = void 0;
|
|
4
|
+
const gtiSDName_1 = require("../validators/gtiSDName");
|
|
5
|
+
function getServiceImageUrl(serviceTypes) {
|
|
6
|
+
const supported = serviceTypes.filter(s => [
|
|
7
|
+
'abahn',
|
|
8
|
+
'a',
|
|
9
|
+
'sbahn',
|
|
10
|
+
's',
|
|
11
|
+
'ubahn',
|
|
12
|
+
'u',
|
|
13
|
+
'rbahn',
|
|
14
|
+
'r',
|
|
15
|
+
'fbahn',
|
|
16
|
+
'train',
|
|
17
|
+
'bus',
|
|
18
|
+
'faehre',
|
|
19
|
+
'ship',
|
|
20
|
+
'ast',
|
|
21
|
+
'fbus',
|
|
22
|
+
'rb',
|
|
23
|
+
're',
|
|
24
|
+
'schnellbus',
|
|
25
|
+
'Schnellbus',
|
|
26
|
+
'ice',
|
|
27
|
+
'ICE',
|
|
28
|
+
'Fussweg',
|
|
29
|
+
].includes(s));
|
|
30
|
+
if (supported.length === 0) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
return `https://cloud.geofox.de/icon/vehicle?types=${supported.join(';')}&height=60&varSize=true`;
|
|
34
|
+
}
|
|
35
|
+
function stationToDto(gti) {
|
|
36
|
+
var _a;
|
|
37
|
+
const dto = {
|
|
38
|
+
id: gti.id,
|
|
39
|
+
name: gti.combinedName,
|
|
40
|
+
city: gti.city,
|
|
41
|
+
type: 'station',
|
|
42
|
+
services: gti.serviceTypes,
|
|
43
|
+
servicesIconUrl: getServiceImageUrl((_a = gti.serviceTypes) !== null && _a !== void 0 ? _a : []),
|
|
44
|
+
platformPlanned: null, // gti.platform ?? null,
|
|
45
|
+
platformActual: null, // gti.realtimePlatform ?? null,
|
|
46
|
+
isCancelled: false, // gti.cancelled ?? false,
|
|
47
|
+
isExtra: false, //gti.extra ?? false,
|
|
48
|
+
distanceMeters: null, //gti.distance ?? null,
|
|
49
|
+
};
|
|
50
|
+
return dto;
|
|
51
|
+
}
|
|
52
|
+
function toDto(gti) {
|
|
53
|
+
switch (gti.type) {
|
|
54
|
+
case 'STATION': {
|
|
55
|
+
return stationToDto(gti);
|
|
56
|
+
}
|
|
57
|
+
case 'ADDRESS': {
|
|
58
|
+
const dto = {
|
|
59
|
+
id: gti.id,
|
|
60
|
+
name: gti.combinedName,
|
|
61
|
+
city: gti.city,
|
|
62
|
+
type: 'address',
|
|
63
|
+
};
|
|
64
|
+
return dto;
|
|
65
|
+
}
|
|
66
|
+
default:
|
|
67
|
+
throw new Error(`unknown route point type: ${gti.type}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.routePointConverter = {
|
|
71
|
+
stationToDto,
|
|
72
|
+
toDto,
|
|
73
|
+
/*
|
|
74
|
+
withDepartureTimeMayCancelledToDto(
|
|
75
|
+
gtiJourneySDName: any,
|
|
76
|
+
): RoutePointWithDepartureTimeMayCancelledDto<RoutePointDto> {
|
|
77
|
+
return {
|
|
78
|
+
...toDto(gtiJourneySDName),
|
|
79
|
+
departure: dateConverter.gtiTimeRealtimeCancelToDto(
|
|
80
|
+
gtiJourneySDName.depTime,
|
|
81
|
+
gtiJourneySDName.depDelay ?? null,
|
|
82
|
+
gtiJourneySDName.cancelled,
|
|
83
|
+
),
|
|
84
|
+
};
|
|
85
|
+
},
|
|
86
|
+
withDepartureTimeToDto(
|
|
87
|
+
gti: any,
|
|
88
|
+
): RoutePointWithDepartureTimeDto<RoutePointDto> {
|
|
89
|
+
const planned = dateConverter.gtiTimeToDate(gti.depTime);
|
|
90
|
+
const delaySeconds = (gti.depDelay as number | undefined) ?? null;
|
|
91
|
+
|
|
92
|
+
return {
|
|
93
|
+
...toDto(gti),
|
|
94
|
+
departure: {
|
|
95
|
+
planned,
|
|
96
|
+
actual: addSeconds(planned, delaySeconds ?? 0),
|
|
97
|
+
delaySeconds: delaySeconds,
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
},
|
|
101
|
+
|
|
102
|
+
withArrivalTimeMayCancelledToDto(
|
|
103
|
+
gtiJourneySDName: any,
|
|
104
|
+
): RoutePointWithArrivalTimeMayCancelledDto<RoutePointDto> {
|
|
105
|
+
return {
|
|
106
|
+
...toDto(gtiJourneySDName),
|
|
107
|
+
arrival: dateConverter.gtiTimeRealtimeCancelToDto(
|
|
108
|
+
gtiJourneySDName.arrTime,
|
|
109
|
+
gtiJourneySDName.arrDelay ?? null,
|
|
110
|
+
gtiJourneySDName.cancelled,
|
|
111
|
+
),
|
|
112
|
+
};
|
|
113
|
+
},
|
|
114
|
+
withArrivalTimeToDto(gti: any): RoutePointWithArrivalTimeDto<RoutePointDto> {
|
|
115
|
+
const planned = dateConverter.gtiTimeToDate(gti.arrTime);
|
|
116
|
+
const delaySeconds = (gti.arrDelay as number | undefined) ?? null;
|
|
117
|
+
|
|
118
|
+
return {
|
|
119
|
+
...toDto(gti),
|
|
120
|
+
arrival: {
|
|
121
|
+
planned,
|
|
122
|
+
actual: addSeconds(planned, delaySeconds ?? 0),
|
|
123
|
+
delaySeconds: delaySeconds,
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
},
|
|
127
|
+
*/
|
|
128
|
+
dtoToGti(dto) {
|
|
129
|
+
switch (dto.type) {
|
|
130
|
+
case 'station':
|
|
131
|
+
return {
|
|
132
|
+
id: dto.id,
|
|
133
|
+
name: dto.name,
|
|
134
|
+
city: dto.city,
|
|
135
|
+
type: gtiSDName_1.GtiSDType.STATION,
|
|
136
|
+
};
|
|
137
|
+
case 'address':
|
|
138
|
+
return {
|
|
139
|
+
id: dto.id,
|
|
140
|
+
name: dto.name,
|
|
141
|
+
city: dto.city,
|
|
142
|
+
type: gtiSDName_1.GtiSDType.ADDRESS,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
//# sourceMappingURL=routePoint.converter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routePoint.converter.js","sourceRoot":"","sources":["../../../src/converters/routePoint.converter.ts"],"names":[],"mappings":";;;AAMA,uDAKiC;AAEjC,SAAS,kBAAkB,CAAC,YAAsB;IAChD,MAAM,SAAS,GAAG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AAS,CAAC,CAAC,CAAC;YACf,MAAM,GAAG,GAAsB;gBAC7B,EAAE,EAAE,GAAG,CAAC,EAAE;gBACV,IAAI,EAAE,GAAG,CAAC,YAAY;gBACtB,IAAI,EAAE,GAAG,CAAC,IAAI;gBACd,IAAI,EAAE,SAAS;aAChB,CAAC;YACF,OAAO,GAAG,CAAC;QACb,CAAC;QACD;YACE,MAAM,IAAI,KAAK,CAAC,6BAA6B,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;IAC7D,CAAC;AACH,CAAC;AAEY,QAAA,mBAAmB,GAAG;IACjC,YAAY;IACZ,KAAK;IAEL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAsDE;IAEF,QAAQ,CAAC,GAAyC;QAChD,QAAQ,GAAG,CAAC,IAAI,EAAE,CAAC;YACjB,KAAK,SAAS;gBACZ,OAAO;oBACL,EAAE,EAAE,GAAG,CAAC,EAAE;oBACV,IAAI,EAAE,GAAG,CAAC,IAAI;oBACd,IAAI,EAAE,GAAG,CAAC,IAAI;oBACd,IAAI,EAAE,qBAAS,CAAC,OAAO;iBACxB,CAAC;YACJ,KAAK,SAAS;gBACZ,OAAO;oBACL,EAAE,EAAE,GAAG,CAAC,EAAE;oBACV,IAAI,EAAE,GAAG,CAAC,IAAI;oBACd,IAAI,EAAE,GAAG,CAAC,IAAI;oBACd,IAAI,EAAE,qBAAS,CAAC,OAAO;iBACxB,CAAC;QACN,CAAC;IACH,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./client/hvvClient"), exports);
|
|
18
|
+
__exportStar(require("./client/hvvClientOptions"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC;AACnC,4DAA0C"}
|