@azure-rest/maps-route 1.0.0-beta.1
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 +255 -0
- package/dist/index.js +234 -0
- package/dist/index.js.map +1 -0
- package/dist-esm/src/generated/clientDefinitions.js +4 -0
- package/dist-esm/src/generated/clientDefinitions.js.map +1 -0
- package/dist-esm/src/generated/index.js +13 -0
- package/dist-esm/src/generated/index.js.map +1 -0
- package/dist-esm/src/generated/isUnexpected.js +77 -0
- package/dist-esm/src/generated/isUnexpected.js.map +1 -0
- package/dist-esm/src/generated/mapsRouteClient.js +25 -0
- package/dist-esm/src/generated/mapsRouteClient.js.map +1 -0
- package/dist-esm/src/generated/models.js +4 -0
- package/dist-esm/src/generated/models.js.map +1 -0
- package/dist-esm/src/generated/outputModels.js +4 -0
- package/dist-esm/src/generated/outputModels.js.map +1 -0
- package/dist-esm/src/generated/parameters.js +4 -0
- package/dist-esm/src/generated/parameters.js.map +1 -0
- package/dist-esm/src/generated/pollingHelper.js +51 -0
- package/dist-esm/src/generated/pollingHelper.js.map +1 -0
- package/dist-esm/src/generated/responses.js +4 -0
- package/dist-esm/src/generated/responses.js.map +1 -0
- package/dist-esm/src/helpers.js +43 -0
- package/dist-esm/src/helpers.js.map +1 -0
- package/dist-esm/src/index.js +7 -0
- package/dist-esm/src/index.js.map +1 -0
- package/dist-esm/src/mapsRoute.js +29 -0
- package/dist-esm/src/mapsRoute.js.map +1 -0
- package/package.json +132 -0
- package/review/maps-route.api.md +907 -0
- package/types/maps-route-rest.d.ts +3413 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Microsoft
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
# Azure MapsRoute client library for JavaScript/TypeScript
|
|
2
|
+
|
|
3
|
+
The Route Directions and Route Matrix APIs in Azure Maps Route Service can be used to calculate the estimated arrival times (ETAs) for each requested route. Route APIs consider factors such as real-time traffic information and historic traffic data, like the typical road speeds on the requested day of the week and time of day. The APIs return the shortest or fastest routes available to multiple destinations at a time in sequence or in optimized order, based on time or distance. Users can also request specialized routes and details for walkers, bicyclists, and commercial vehicles like trucks.
|
|
4
|
+
|
|
5
|
+
**Please rely heavily on our [REST client docs](https://github.com/Azure/azure-sdk-for-js/blob/main/documentation/rest-clients.md) to use this library**
|
|
6
|
+
|
|
7
|
+
Key links:
|
|
8
|
+
|
|
9
|
+
- [Source code][source_code]
|
|
10
|
+
- [Package (NPM)][npm_link]
|
|
11
|
+
- [API reference documentation][api_ref]
|
|
12
|
+
- [Product Information](https://docs.microsoft.com/rest/api/maps/route)
|
|
13
|
+
|
|
14
|
+
## Getting started
|
|
15
|
+
|
|
16
|
+
### Currently supported environments
|
|
17
|
+
|
|
18
|
+
- [LTS versions of Node.js](https://nodejs.org/about/releases/)
|
|
19
|
+
- Latest versions of Safari, Chrome, Edge and Firefox.
|
|
20
|
+
|
|
21
|
+
### Prerequisites
|
|
22
|
+
|
|
23
|
+
- An [Azure subscription][azure_sub].
|
|
24
|
+
- An [Azure Maps account](https://docs.microsoft.com/azure/azure-maps/how-to-manage-account-keys). You can create the resource via the [Azure Portal][azure_portal], the [Azure PowerShell][azure_powershell], or the [Azure CLI][azure_cli].
|
|
25
|
+
|
|
26
|
+
If you use Azure CLI, replace `<resource-group-name>` and `<map-account-name>` of your choice, and select a proper [pricing tier](https://docs.microsoft.com/azure/azure-maps/choose-pricing-tier) based on your needs via the `<sku-name>` parameter. Please refer to [this page](https://docs.microsoft.com/cli/azure/maps/account?view=azure-cli-latest#az_maps_account_create) for more details.
|
|
27
|
+
|
|
28
|
+
### Install the `@azure-rest/maps-route` package
|
|
29
|
+
|
|
30
|
+
Install the Azure MapsRoute client REST client library for JavaScript with `npm`:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npm install @azure-rest/maps-route
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Create and authenticate a `MapsRouteClient`
|
|
37
|
+
|
|
38
|
+
To create a client object to access the Azure Maps Route APIs, you will need a `credential` object. The Azure Maps Route client can use an Azure Active Directory credential or an Azure Key credential to authenticate.
|
|
39
|
+
|
|
40
|
+
#### Using an Azure Active Directory Credential
|
|
41
|
+
|
|
42
|
+
You can authenticate with Azure Active Directory using the [Azure Identity library][azure_identity]. To use the [DefaultAzureCredential][defaultazurecredential] provider shown below, or other credential providers provided with the Azure SDK, please install the `@azure/identity` package:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
npm install @azure/identity
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
You will also need to register a new AAD application and grant access to Azure Maps by assigning the suitable role to your service principal. Please refer to the [Manage authentication](https://docs.microsoft.com/azure/azure-maps/how-to-manage-authentication) page.
|
|
49
|
+
|
|
50
|
+
Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: `AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, `AZURE_CLIENT_SECRET`.
|
|
51
|
+
|
|
52
|
+
You will also need to specify the Azure Maps resource you intend to use by specifying the `clientId` in the client options.
|
|
53
|
+
The Azure Maps resource client id can be found in the Authentication sections in the Azure Maps resource. Please refer to the [documentation](https://docs.microsoft.com/azure/azure-maps/how-to-manage-authentication#view-authentication-details) on how to find it.
|
|
54
|
+
|
|
55
|
+
```javascript
|
|
56
|
+
const MapsRoute = require("@azure-rest/maps-route").default;
|
|
57
|
+
const { DefaultAzureCredential } = require("@azure/identity");
|
|
58
|
+
|
|
59
|
+
const credential = new DefaultAzureCredential();
|
|
60
|
+
const client = MapsRoute(credential, "<maps-account-client-id>");
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
#### Using a Subscription Key Credential
|
|
64
|
+
|
|
65
|
+
You can authenticate with your Azure Maps Subscription Key.
|
|
66
|
+
|
|
67
|
+
```javascript
|
|
68
|
+
const MapsRoute = require("@azure-rest/maps-route").default;
|
|
69
|
+
const { AzureKeyCredential } = require("@azure-core-auth");
|
|
70
|
+
|
|
71
|
+
const credential = new AzureKeyCredential("<subscription-key>");
|
|
72
|
+
const client = MapsRoute(credential);
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Examples
|
|
76
|
+
|
|
77
|
+
The following sections provide several code snippets covering some of the most common Azure Maps Route tasks, including:
|
|
78
|
+
|
|
79
|
+
- [Request historic and real-time data](#request-historic-and-real-time-data)
|
|
80
|
+
- [Request a route for a commercial vehicle](#request-a-route-for-a-commercial-vehicle)
|
|
81
|
+
- [Calculate and optimize a multi-stop route](#calculate-and-optimize-a-multi-stop-route)
|
|
82
|
+
|
|
83
|
+
### Request historic and real-time data
|
|
84
|
+
|
|
85
|
+
By default, the Route service assumes the traveling mode is a car and the departure time is now. It returns route based on real-time traffic conditions unless a route calculation request specifies otherwise.
|
|
86
|
+
|
|
87
|
+
To retrieve the route direction, you need to pass in the parameters the coordinates through which the route is calculated, delimited by a colon. A minimum of two coordinates are required. The first one is the origin and the last is the destination of the route.
|
|
88
|
+
|
|
89
|
+
By default, the Route service will return an array of coordinates. The response will contain the coordinates that make up the path in a list named points. Route response also includes the distance from the start of the route and the estimated elapsed time. These values can be used to calculate the average speed for the entire route.
|
|
90
|
+
|
|
91
|
+
```javascript
|
|
92
|
+
const routeDirectionsResult = await client.path("/route/directions/{format}", "json").get({
|
|
93
|
+
queryParameters: {
|
|
94
|
+
query: "51.368752,-0.118332:41.385426,-0.128929",
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// You can use the helper function `toColonDelimitedLatLonString` to compose the query string.
|
|
99
|
+
const { toColonDelimitedLatLonString } = require("@azure-rest/maps-route");
|
|
100
|
+
const routeDirectionsResult = await client.path("/route/directions/{format}", "json").get({
|
|
101
|
+
queryParameters: {
|
|
102
|
+
query: toColonDelimitedLatLonString([
|
|
103
|
+
// Origin:
|
|
104
|
+
[51.368752, -0.118332],
|
|
105
|
+
// Waypoints (Optional):
|
|
106
|
+
[45.49735, 9.182435],
|
|
107
|
+
[48.886128, 2.329742],
|
|
108
|
+
[48.159642, 11.518011],
|
|
109
|
+
// Destination:
|
|
110
|
+
[41.385426, -0.128929],
|
|
111
|
+
]),
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
// Handle the error if the request failed
|
|
116
|
+
if (isUnexpected(routeDirectionsResult)) {
|
|
117
|
+
throw routeDirectionsResult.body.error;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const { summary, legs } = routeDirectionsResult.body.routes;
|
|
121
|
+
console.log(
|
|
122
|
+
`The total distance is ${summary.lengthInMeters} meters, and it takes ${summary.travelTimeInSeconds} seconds.`
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
legs.points.forEach(({ summary: { travelTimeInSeconds }, points }, idx) => {
|
|
126
|
+
console.log(`${idx + 1}th leg takes ${travelTimeInSeconds} seconds to travel, and the path is: `);
|
|
127
|
+
points.points.forEach(({ latitude, longitude }, idx) =>
|
|
128
|
+
console.log(`${idx}: (${latitude}, ${longitude})`)
|
|
129
|
+
});
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Request a route for a commercial vehicle
|
|
133
|
+
|
|
134
|
+
The service supports commercial vehicle routing, covering commercial trucks routing. The APIs consider specified limits. Such as, the height and weight of the vehicle, and if the vehicle is carrying hazardous cargo. For example, if a vehicle is carrying flammable, the routing engine avoid certain tunnels that are near residential areas.
|
|
135
|
+
|
|
136
|
+
```javascript
|
|
137
|
+
const routeDirectionsResult = await client.path("/route/directions/{format}", "json").get({
|
|
138
|
+
queryParameters: {
|
|
139
|
+
query: toColonDelimitedLatLonString([
|
|
140
|
+
// Origin
|
|
141
|
+
[51.368752, -0.118332],
|
|
142
|
+
// Waypoints (Optional):
|
|
143
|
+
[45.49735, 9.182435],
|
|
144
|
+
[48.886128, 2.329742],
|
|
145
|
+
[48.159642, 11.518011],
|
|
146
|
+
// Destination:
|
|
147
|
+
[41.385426, -0.128929],
|
|
148
|
+
]),
|
|
149
|
+
vehicleWidthInMeters: 2,
|
|
150
|
+
vehicleHeightInMeters: 2,
|
|
151
|
+
vehicleLoadType: "USHazmatClass1",
|
|
152
|
+
travelMode: "truck",
|
|
153
|
+
isCommercialVehicle: true,
|
|
154
|
+
},
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
if (isUnexpected(routeDirectionsResult)) {
|
|
158
|
+
throw routeDirectionsResult.body.error;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const { summary, legs } = routeDirectionsResult.body.routes;
|
|
162
|
+
console.log(
|
|
163
|
+
`The total distance is ${summary.lengthInMeters} meters, and it takes ${summary.travelTimeInSeconds} seconds.`
|
|
164
|
+
);
|
|
165
|
+
|
|
166
|
+
legs.points.forEach(({ summary: { travelTimeInSeconds }, points }, idx) => {
|
|
167
|
+
console.log(`${idx + 1}th leg takes ${travelTimeInSeconds} seconds to travel, and the path is: `);
|
|
168
|
+
points.points.forEach(({ latitude, longitude }, idx) =>
|
|
169
|
+
console.log(`${idx}: (${latitude}, ${longitude})`)
|
|
170
|
+
});
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### Calculate and optimize a multi-stop route
|
|
174
|
+
|
|
175
|
+
Azure Maps currently provides two forms of route optimizations:
|
|
176
|
+
|
|
177
|
+
- Optimizations based on the requested route type, without changing the order of waypoints. You can find the [supported route types here](https://docs.microsoft.com/rest/api/maps/route/post-route-directions?tabs=HTTP#routetype).
|
|
178
|
+
- Traveling salesman optimization, which changes the order of the waypoints to obtain the best order to visit each stop
|
|
179
|
+
|
|
180
|
+
For multi-stop routing, up to 150 waypoints may be specified in a single route request. The starting and ending coordinate locations can be the same, as would be the case with a round trip. But you need to provide at least one additional waypoint to make the route calculation. Waypoints can be added to the query in-between the origin and destination coordinates.
|
|
181
|
+
|
|
182
|
+
If you want to optimize the best order to visit the given waypoints, then you need to specify `computeBestWaypointOrder=true`. This scenario is also known as the traveling salesman optimization problem.
|
|
183
|
+
|
|
184
|
+
```javascript
|
|
185
|
+
const routeDirectionsResult = await client.path("/route/directions/{format}", "json").get({
|
|
186
|
+
queryParameters: {
|
|
187
|
+
query: toColonDelimitedLatLonString([
|
|
188
|
+
// Origin:
|
|
189
|
+
[51.368752, -0.118332],
|
|
190
|
+
// Waypoints:
|
|
191
|
+
[45.49735, 9.182435],
|
|
192
|
+
[48.886128, 2.329742],
|
|
193
|
+
[48.159642, 11.518011],
|
|
194
|
+
// Destination:
|
|
195
|
+
[41.385426, -0.128929],
|
|
196
|
+
]),
|
|
197
|
+
computeBestWaypointOrder: true,
|
|
198
|
+
routeType: "shortest",
|
|
199
|
+
},
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
if (isUnexpected(routeDirectionsResult)) {
|
|
203
|
+
throw routeDirectionsResult.body.error;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const { summary } = routeDirectionsResult.body.routes;
|
|
207
|
+
console.log(
|
|
208
|
+
`The optimized distance is ${summary.lengthInMeters} meters, and it takes ${summary.travelTimeInSeconds} seconds.`
|
|
209
|
+
);
|
|
210
|
+
console.log("The route is optimized by: ");
|
|
211
|
+
routeDirectionsResult.body.routes.optimizedWaypoints.forEach(
|
|
212
|
+
({ providedIndex, optimizedIndex }) => `Moving index ${providedIndex} to ${optimizedIndex}`
|
|
213
|
+
);
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
## Troubleshooting
|
|
217
|
+
|
|
218
|
+
### Logging
|
|
219
|
+
|
|
220
|
+
Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:
|
|
221
|
+
|
|
222
|
+
```javascript
|
|
223
|
+
const { setLogLevel } = require("@azure/logger");
|
|
224
|
+
|
|
225
|
+
setLogLevel("info");
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
For more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger).
|
|
229
|
+
|
|
230
|
+
## Next steps
|
|
231
|
+
|
|
232
|
+
Please take a look at the [samples][samples] directory for detailed examples on how to use this library.
|
|
233
|
+
|
|
234
|
+
## Contributing
|
|
235
|
+
|
|
236
|
+
If you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/master/CONTRIBUTING.md) to learn more about how to build and test the code.
|
|
237
|
+
|
|
238
|
+
## Related projects
|
|
239
|
+
|
|
240
|
+
- [Microsoft Azure SDK for JavaScript](https://github.com/Azure/azure-sdk-for-js)
|
|
241
|
+
|
|
242
|
+

|
|
243
|
+
|
|
244
|
+
[source_code]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/maps/maps-route-rest
|
|
245
|
+
|
|
246
|
+
<!-- [npm_link]: https://www.npmjs.com/package/@azure-rest/maps-route -->
|
|
247
|
+
<!-- [api_ref]: https://docs.microsoft.com/javascript/api/@azure-rest/maps-route?view=azure-node-preview -->
|
|
248
|
+
|
|
249
|
+
[samples]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/maps/maps-route-rest/samples
|
|
250
|
+
[azure_cli]: https://docs.microsoft.com/cli/azure
|
|
251
|
+
[azure_sub]: https://azure.microsoft.com/free/
|
|
252
|
+
[azure_portal]: https://portal.azure.com
|
|
253
|
+
[azure_powershell]: https://docs.microsoft.com/powershell/module/az.maps/new-azmapsaccount
|
|
254
|
+
[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity
|
|
255
|
+
[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity#defaultazurecredential
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var coreAuth = require('@azure/core-auth');
|
|
6
|
+
var mapsCommon = require('@azure/maps-common');
|
|
7
|
+
var coreClient = require('@azure-rest/core-client');
|
|
8
|
+
var coreRestPipeline = require('@azure/core-rest-pipeline');
|
|
9
|
+
var coreLro = require('@azure/core-lro');
|
|
10
|
+
|
|
11
|
+
// Copyright (c) Microsoft Corporation.
|
|
12
|
+
/**
|
|
13
|
+
* Initialize a new instance of the class MapsRouteClient class.
|
|
14
|
+
* @param credentials type: KeyCredential
|
|
15
|
+
*/
|
|
16
|
+
function createClient(credentials, options = {}) {
|
|
17
|
+
var _a, _b;
|
|
18
|
+
const baseUrl = (_a = options.baseUrl) !== null && _a !== void 0 ? _a : `https://atlas.microsoft.com`;
|
|
19
|
+
options.apiVersion = (_b = options.apiVersion) !== null && _b !== void 0 ? _b : "1.0";
|
|
20
|
+
options = Object.assign(Object.assign({}, options), { credentials: {
|
|
21
|
+
apiKeyHeaderName: "subscription-key"
|
|
22
|
+
} });
|
|
23
|
+
const userAgentInfo = `azsdk-js-maps-route-rest/1.0.0-beta.1`;
|
|
24
|
+
const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
|
|
25
|
+
? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}`
|
|
26
|
+
: `${userAgentInfo}`;
|
|
27
|
+
options = Object.assign(Object.assign({}, options), { userAgentOptions: {
|
|
28
|
+
userAgentPrefix
|
|
29
|
+
} });
|
|
30
|
+
const client = coreClient.getClient(baseUrl, credentials, options);
|
|
31
|
+
return client;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Copyright (c) Microsoft Corporation.
|
|
35
|
+
// Licensed under the MIT license.
|
|
36
|
+
const responseMap = {
|
|
37
|
+
"POST /route/matrix/{format}": ["200", "202"],
|
|
38
|
+
"GET /route/matrix/{format}": ["200", "202"],
|
|
39
|
+
"POST /route/matrix/sync/{format}": ["200"],
|
|
40
|
+
"GET /route/directions/{format}": ["200"],
|
|
41
|
+
"POST /route/directions/{format}": ["200"],
|
|
42
|
+
"GET /route/range/{format}": ["200"],
|
|
43
|
+
"POST /route/directions/batch/{format}": ["200", "202"],
|
|
44
|
+
"GET /route/directions/batch/{format}": ["200", "202"],
|
|
45
|
+
"POST /route/directions/batch/sync/{format}": ["200"]
|
|
46
|
+
};
|
|
47
|
+
function isUnexpected(response) {
|
|
48
|
+
const lroOriginal = response.headers["x-ms-original-url"];
|
|
49
|
+
const url = new URL(lroOriginal !== null && lroOriginal !== void 0 ? lroOriginal : response.request.url);
|
|
50
|
+
const method = response.request.method;
|
|
51
|
+
let pathDetails = responseMap[`${method} ${url.pathname}`];
|
|
52
|
+
if (!pathDetails) {
|
|
53
|
+
pathDetails = geParametrizedPathSuccess(method, url.pathname);
|
|
54
|
+
}
|
|
55
|
+
return !pathDetails.includes(response.status);
|
|
56
|
+
}
|
|
57
|
+
function geParametrizedPathSuccess(method, path) {
|
|
58
|
+
var _a, _b;
|
|
59
|
+
const pathParts = path.split("/");
|
|
60
|
+
// Iterate the responseMap to find a match
|
|
61
|
+
for (const [key, value] of Object.entries(responseMap)) {
|
|
62
|
+
// Extracting the path from the map key which is in format
|
|
63
|
+
// GET /path/foo
|
|
64
|
+
if (!key.startsWith(method)) {
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
const candidatePath = getPathFromMapKey(key);
|
|
68
|
+
// Get each part of the url path
|
|
69
|
+
const candidateParts = candidatePath.split("/");
|
|
70
|
+
// If the candidate and actual paths don't match in size
|
|
71
|
+
// we move on to the next candidate path
|
|
72
|
+
if (candidateParts.length === pathParts.length &&
|
|
73
|
+
hasParametrizedPath(key)) {
|
|
74
|
+
// track if we have found a match to return the values found.
|
|
75
|
+
let found = true;
|
|
76
|
+
for (let i = 0; i < candidateParts.length; i++) {
|
|
77
|
+
if (((_a = candidateParts[i]) === null || _a === void 0 ? void 0 : _a.startsWith("{")) &&
|
|
78
|
+
((_b = candidateParts[i]) === null || _b === void 0 ? void 0 : _b.endsWith("}"))) {
|
|
79
|
+
// If the current part of the candidate is a "template" part
|
|
80
|
+
// it is a match with the actual path part on hand
|
|
81
|
+
// skip as the parameterized part can match anything
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
// If the candidate part is not a template and
|
|
85
|
+
// the parts don't match mark the candidate as not found
|
|
86
|
+
// to move on with the next candidate path.
|
|
87
|
+
if (candidateParts[i] !== pathParts[i]) {
|
|
88
|
+
found = false;
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
// We finished evaluating the current candidate parts
|
|
93
|
+
// if all parts matched we return the success values form
|
|
94
|
+
// the path mapping.
|
|
95
|
+
if (found) {
|
|
96
|
+
return value;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
// No match was found, return an empty array.
|
|
101
|
+
return [];
|
|
102
|
+
}
|
|
103
|
+
function hasParametrizedPath(path) {
|
|
104
|
+
return path.includes("/{");
|
|
105
|
+
}
|
|
106
|
+
function getPathFromMapKey(mapKey) {
|
|
107
|
+
const pathStart = mapKey.indexOf("/");
|
|
108
|
+
return mapKey.slice(pathStart);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Copyright (c) Microsoft Corporation.
|
|
112
|
+
/**
|
|
113
|
+
* Helper function that builds a Poller object to help polling a long running operation.
|
|
114
|
+
* @param client - Client to use for sending the request to get additional pages.
|
|
115
|
+
* @param initialResponse - The initial response.
|
|
116
|
+
* @param options - Options to set a resume state or custom polling interval.
|
|
117
|
+
* @returns - A poller object to poll for operation state updates and eventually get the final response.
|
|
118
|
+
*/
|
|
119
|
+
function getLongRunningPoller(client, initialResponse, options = {}) {
|
|
120
|
+
const poller = {
|
|
121
|
+
requestMethod: initialResponse.request.method,
|
|
122
|
+
requestPath: initialResponse.request.url,
|
|
123
|
+
sendInitialRequest: async () => {
|
|
124
|
+
// In the case of Rest Clients we are building the LRO poller object from a response that's the reason
|
|
125
|
+
// we are not triggering the initial request here, just extracting the information from the
|
|
126
|
+
// response we were provided.
|
|
127
|
+
return getLroResponse(initialResponse);
|
|
128
|
+
},
|
|
129
|
+
sendPollRequest: async (path) => {
|
|
130
|
+
// This is the callback that is going to be called to poll the service
|
|
131
|
+
// to get the latest status. We use the client provided and the polling path
|
|
132
|
+
// which is an opaque URL provided by caller, the service sends this in one of the following headers: operation-location, azure-asyncoperation or location
|
|
133
|
+
// depending on the lro pattern that the service implements. If non is provided we default to the initial path.
|
|
134
|
+
const response = await client
|
|
135
|
+
.pathUnchecked(path !== null && path !== void 0 ? path : initialResponse.request.url)
|
|
136
|
+
.get();
|
|
137
|
+
const lroResponse = getLroResponse(response);
|
|
138
|
+
lroResponse.rawResponse.headers["x-ms-original-url"] =
|
|
139
|
+
initialResponse.request.url;
|
|
140
|
+
return lroResponse;
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
return new coreLro.LroEngine(poller, options);
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Converts a Rest Client response to a response that the LRO engine knows about
|
|
147
|
+
* @param response - a rest client http response
|
|
148
|
+
* @returns - An LRO response that the LRO engine can work with
|
|
149
|
+
*/
|
|
150
|
+
function getLroResponse(response) {
|
|
151
|
+
if (Number.isNaN(response.status)) {
|
|
152
|
+
throw new TypeError(`Status code of the response is not a number. Value: ${response.status}`);
|
|
153
|
+
}
|
|
154
|
+
return {
|
|
155
|
+
flatResponse: response,
|
|
156
|
+
rawResponse: Object.assign(Object.assign({}, response), { statusCode: Number.parseInt(response.status), body: response.body })
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// Copyright (c) Microsoft Corporation.
|
|
161
|
+
function MapsRoute(credential, clientIdOrOptions = {}, maybeOptions = {}) {
|
|
162
|
+
const options = typeof clientIdOrOptions === "string" ? maybeOptions : clientIdOrOptions;
|
|
163
|
+
/**
|
|
164
|
+
* maps service requires a header "ms-x-client-id", which is different from the standard AAD.
|
|
165
|
+
* So we need to do our own implementation.
|
|
166
|
+
* This customized authentication is following by this guide: https://github.com/Azure/azure-sdk-for-js/blob/main/documentation/RLC-customization.md#custom-authentication
|
|
167
|
+
*/
|
|
168
|
+
if (coreAuth.isTokenCredential(credential)) {
|
|
169
|
+
const clientId = typeof clientIdOrOptions === "string" ? clientIdOrOptions : "";
|
|
170
|
+
if (!clientId) {
|
|
171
|
+
throw Error("Client id is needed for TokenCredential");
|
|
172
|
+
}
|
|
173
|
+
const client = createClient(undefined, options);
|
|
174
|
+
client.pipeline.addPolicy(coreRestPipeline.bearerTokenAuthenticationPolicy({
|
|
175
|
+
credential,
|
|
176
|
+
scopes: `${options.baseUrl || "https://atlas.microsoft.com"}/.default`,
|
|
177
|
+
}));
|
|
178
|
+
client.pipeline.addPolicy(mapsCommon.createMapsClientIdPolicy(clientId));
|
|
179
|
+
return client;
|
|
180
|
+
}
|
|
181
|
+
return createClient(credential, options);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// Copyright (c) Microsoft Corporation.
|
|
185
|
+
// Licensed under the MIT license.
|
|
186
|
+
function toLatLonString(coordinates) {
|
|
187
|
+
return `${coordinates[0]},${coordinates[1]}`;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Transform an array of [Latitude, Longtitute] to a string in the following format:
|
|
191
|
+
* "Latitude_1,Longtitute_1:Latitude_2,Longtitute_2:..."
|
|
192
|
+
*
|
|
193
|
+
* @param coordinates - An array of Latitude/Longtitute pair to transform.
|
|
194
|
+
* @returns The transformed string.
|
|
195
|
+
*/
|
|
196
|
+
function toColonDelimitedLatLonString(coordinates) {
|
|
197
|
+
return coordinates.map((c) => toLatLonString(c)).join(":");
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Create a batch request body of a bunch of route direction requests.
|
|
201
|
+
*
|
|
202
|
+
* @param queryParamProperties - An object of the query parameters for a route direction request
|
|
203
|
+
* @returns The composed batch request.
|
|
204
|
+
*/
|
|
205
|
+
function createRouteDirectionsBatchRequest(queryParamProperties) {
|
|
206
|
+
return {
|
|
207
|
+
batchItems: queryParamProperties.map((queryParam) => ({
|
|
208
|
+
query: "?" +
|
|
209
|
+
Object.entries(queryParam)
|
|
210
|
+
.map(([k, v]) => {
|
|
211
|
+
// Skip if no value
|
|
212
|
+
if (typeof v === "undefined" || v === null) {
|
|
213
|
+
return "";
|
|
214
|
+
}
|
|
215
|
+
// Check name mappings: Array values
|
|
216
|
+
if ((k === "departAt" || k === "arriveAt") && v instanceof Date) {
|
|
217
|
+
return `${k}=${v.toISOString()}`;
|
|
218
|
+
}
|
|
219
|
+
return `${k}=${v}`;
|
|
220
|
+
})
|
|
221
|
+
.filter((s) => s !== "")
|
|
222
|
+
.join("&"),
|
|
223
|
+
})),
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// Copyright (c) Microsoft Corporation.
|
|
228
|
+
|
|
229
|
+
exports.createRouteDirectionsBatchRequest = createRouteDirectionsBatchRequest;
|
|
230
|
+
exports["default"] = MapsRoute;
|
|
231
|
+
exports.getLongRunningPoller = getLongRunningPoller;
|
|
232
|
+
exports.isUnexpected = isUnexpected;
|
|
233
|
+
exports.toColonDelimitedLatLonString = toColonDelimitedLatLonString;
|
|
234
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/generated/mapsRouteClient.ts","../src/generated/isUnexpected.ts","../src/generated/pollingHelper.ts","../src/mapsRoute.ts","../src/helpers.ts","../src/index.ts"],"sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { getClient, ClientOptions } from \"@azure-rest/core-client\";\nimport { KeyCredential } from \"@azure/core-auth\";\nimport { MapsRouteClient } from \"./clientDefinitions\";\n\n/**\n * Initialize a new instance of the class MapsRouteClient class.\n * @param credentials type: KeyCredential\n */\nexport default function createClient(\n credentials: KeyCredential,\n options: ClientOptions = {}\n): MapsRouteClient {\n const baseUrl = options.baseUrl ?? `https://atlas.microsoft.com`;\n options.apiVersion = options.apiVersion ?? \"1.0\";\n options = {\n ...options,\n credentials: {\n apiKeyHeaderName: \"subscription-key\"\n }\n };\n\n const userAgentInfo = `azsdk-js-maps-route-rest/1.0.0-beta.1`;\n const userAgentPrefix =\n options.userAgentOptions && options.userAgentOptions.userAgentPrefix\n ? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}`\n : `${userAgentInfo}`;\n options = {\n ...options,\n userAgentOptions: {\n userAgentPrefix\n }\n };\n\n const client = getClient(baseUrl, credentials, options) as MapsRouteClient;\n\n return client;\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n RouteRequestRouteMatrixSync200Response,\n RouteRequestRouteMatrixSync408Response,\n RouteRequestRouteMatrixSyncDefaultResponse,\n RouteGetRouteDirections200Response,\n RouteGetRouteDirectionsDefaultResponse,\n RouteGetRouteDirectionsWithAdditionalParameters200Response,\n RouteGetRouteDirectionsWithAdditionalParametersDefaultResponse,\n RouteGetRouteRange200Response,\n RouteGetRouteRangeDefaultResponse,\n RouteRequestRouteDirectionsBatchSync200Response,\n RouteRequestRouteDirectionsBatchSync408Response,\n RouteRequestRouteDirectionsBatchSyncDefaultResponse\n} from \"./responses\";\n\nconst responseMap: Record<string, string[]> = {\n \"POST /route/matrix/{format}\": [\"200\", \"202\"],\n \"GET /route/matrix/{format}\": [\"200\", \"202\"],\n \"POST /route/matrix/sync/{format}\": [\"200\"],\n \"GET /route/directions/{format}\": [\"200\"],\n \"POST /route/directions/{format}\": [\"200\"],\n \"GET /route/range/{format}\": [\"200\"],\n \"POST /route/directions/batch/{format}\": [\"200\", \"202\"],\n \"GET /route/directions/batch/{format}\": [\"200\", \"202\"],\n \"POST /route/directions/batch/sync/{format}\": [\"200\"]\n};\n\nexport function isUnexpected(\n response:\n | RouteRequestRouteMatrixSync200Response\n | RouteRequestRouteMatrixSync408Response\n | RouteRequestRouteMatrixSyncDefaultResponse\n): response is RouteRequestRouteMatrixSync408Response;\nexport function isUnexpected(\n response:\n | RouteGetRouteDirections200Response\n | RouteGetRouteDirectionsDefaultResponse\n): response is RouteGetRouteDirectionsDefaultResponse;\nexport function isUnexpected(\n response:\n | RouteGetRouteDirectionsWithAdditionalParameters200Response\n | RouteGetRouteDirectionsWithAdditionalParametersDefaultResponse\n): response is RouteGetRouteDirectionsWithAdditionalParametersDefaultResponse;\nexport function isUnexpected(\n response: RouteGetRouteRange200Response | RouteGetRouteRangeDefaultResponse\n): response is RouteGetRouteRangeDefaultResponse;\nexport function isUnexpected(\n response:\n | RouteRequestRouteDirectionsBatchSync200Response\n | RouteRequestRouteDirectionsBatchSync408Response\n | RouteRequestRouteDirectionsBatchSyncDefaultResponse\n): response is RouteRequestRouteDirectionsBatchSync408Response;\nexport function isUnexpected(\n response:\n | RouteRequestRouteMatrixSync200Response\n | RouteRequestRouteMatrixSync408Response\n | RouteRequestRouteMatrixSyncDefaultResponse\n | RouteGetRouteDirections200Response\n | RouteGetRouteDirectionsDefaultResponse\n | RouteGetRouteDirectionsWithAdditionalParameters200Response\n | RouteGetRouteDirectionsWithAdditionalParametersDefaultResponse\n | RouteGetRouteRange200Response\n | RouteGetRouteRangeDefaultResponse\n | RouteRequestRouteDirectionsBatchSync200Response\n | RouteRequestRouteDirectionsBatchSync408Response\n | RouteRequestRouteDirectionsBatchSyncDefaultResponse\n): response is\n | RouteRequestRouteMatrixSync408Response\n | RouteRequestRouteMatrixSyncDefaultResponse\n | RouteGetRouteDirectionsDefaultResponse\n | RouteGetRouteDirectionsWithAdditionalParametersDefaultResponse\n | RouteGetRouteRangeDefaultResponse\n | RouteRequestRouteDirectionsBatchSync408Response\n | RouteRequestRouteDirectionsBatchSyncDefaultResponse {\n const lroOriginal = response.headers[\"x-ms-original-url\"];\n const url = new URL(lroOriginal ?? response.request.url);\n const method = response.request.method;\n let pathDetails = responseMap[`${method} ${url.pathname}`];\n if (!pathDetails) {\n pathDetails = geParametrizedPathSuccess(method, url.pathname);\n }\n return !pathDetails.includes(response.status);\n}\n\nfunction geParametrizedPathSuccess(method: string, path: string): string[] {\n const pathParts = path.split(\"/\");\n\n // Iterate the responseMap to find a match\n for (const [key, value] of Object.entries(responseMap)) {\n // Extracting the path from the map key which is in format\n // GET /path/foo\n if (!key.startsWith(method)) {\n continue;\n }\n const candidatePath = getPathFromMapKey(key);\n // Get each part of the url path\n const candidateParts = candidatePath.split(\"/\");\n\n // If the candidate and actual paths don't match in size\n // we move on to the next candidate path\n if (\n candidateParts.length === pathParts.length &&\n hasParametrizedPath(key)\n ) {\n // track if we have found a match to return the values found.\n let found = true;\n for (let i = 0; i < candidateParts.length; i++) {\n if (\n candidateParts[i]?.startsWith(\"{\") &&\n candidateParts[i]?.endsWith(\"}\")\n ) {\n // If the current part of the candidate is a \"template\" part\n // it is a match with the actual path part on hand\n // skip as the parameterized part can match anything\n continue;\n }\n\n // If the candidate part is not a template and\n // the parts don't match mark the candidate as not found\n // to move on with the next candidate path.\n if (candidateParts[i] !== pathParts[i]) {\n found = false;\n break;\n }\n }\n\n // We finished evaluating the current candidate parts\n // if all parts matched we return the success values form\n // the path mapping.\n if (found) {\n return value;\n }\n }\n }\n\n // No match was found, return an empty array.\n return [];\n}\n\nfunction hasParametrizedPath(path: string): boolean {\n return path.includes(\"/{\");\n}\n\nfunction getPathFromMapKey(mapKey: string): string {\n const pathStart = mapKey.indexOf(\"/\");\n return mapKey.slice(pathStart);\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { Client, HttpResponse } from \"@azure-rest/core-client\";\nimport {\n LongRunningOperation,\n LroEngine,\n LroEngineOptions,\n LroResponse,\n PollerLike,\n PollOperationState\n} from \"@azure/core-lro\";\n\n/**\n * Helper function that builds a Poller object to help polling a long running operation.\n * @param client - Client to use for sending the request to get additional pages.\n * @param initialResponse - The initial response.\n * @param options - Options to set a resume state or custom polling interval.\n * @returns - A poller object to poll for operation state updates and eventually get the final response.\n */\nexport function getLongRunningPoller<TResult extends HttpResponse>(\n client: Client,\n initialResponse: TResult,\n options: LroEngineOptions<TResult, PollOperationState<TResult>> = {}\n): PollerLike<PollOperationState<TResult>, TResult> {\n const poller: LongRunningOperation<TResult> = {\n requestMethod: initialResponse.request.method,\n requestPath: initialResponse.request.url,\n sendInitialRequest: async () => {\n // In the case of Rest Clients we are building the LRO poller object from a response that's the reason\n // we are not triggering the initial request here, just extracting the information from the\n // response we were provided.\n return getLroResponse(initialResponse);\n },\n sendPollRequest: async (path) => {\n // This is the callback that is going to be called to poll the service\n // to get the latest status. We use the client provided and the polling path\n // which is an opaque URL provided by caller, the service sends this in one of the following headers: operation-location, azure-asyncoperation or location\n // depending on the lro pattern that the service implements. If non is provided we default to the initial path.\n const response = await client\n .pathUnchecked(path ?? initialResponse.request.url)\n .get();\n const lroResponse = getLroResponse(response as TResult);\n lroResponse.rawResponse.headers[\"x-ms-original-url\"] =\n initialResponse.request.url;\n return lroResponse;\n }\n };\n\n return new LroEngine(poller, options);\n}\n\n/**\n * Converts a Rest Client response to a response that the LRO engine knows about\n * @param response - a rest client http response\n * @returns - An LRO response that the LRO engine can work with\n */\nfunction getLroResponse<TResult extends HttpResponse>(\n response: TResult\n): LroResponse<TResult> {\n if (Number.isNaN(response.status)) {\n throw new TypeError(\n `Status code of the response is not a number. Value: ${response.status}`\n );\n }\n\n return {\n flatResponse: response,\n rawResponse: {\n ...response,\n statusCode: Number.parseInt(response.status),\n body: response.body\n }\n };\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { ClientOptions } from \"@azure-rest/core-client\";\nimport { AzureKeyCredential, TokenCredential, isTokenCredential } from \"@azure/core-auth\";\nimport { createMapsClientIdPolicy } from \"@azure/maps-common\";\nimport { MapsRouteClient } from \"./generated\";\nimport createClient from \"./generated\";\nimport { bearerTokenAuthenticationPolicy } from \"@azure/core-rest-pipeline\";\n\n/**\n * Creates an instance of MapsRouteClient from a subscription key.\n *\n * @example\n * ```ts\n * import MapsRoute from \"@azure-rest/maps-route\";\n * import { AzureKeyCredential } from \"@azure/core-auth\";\n *\n * const credential = new AzureKeyCredential(\"<subscription-key>\");\n * const client = MapsRoute(credential);\n *```\n *\n * @param credential - An AzureKeyCredential instance used to authenticate requests to the service\n * @param options - Options used to configure the Route Client\n */\nexport default function MapsRoute(\n credential: AzureKeyCredential,\n options?: ClientOptions\n): MapsRouteClient;\n/**\n * Creates an instance of MapsRoute from an Azure Identity `TokenCredential`.\n *\n * @example\n * ```ts\n * import MapsRoute from \"@azure/maps-route\";\n * import { DefaultAzureCredential } from \"@azure/identity\";\n *\n * const credential = new DefaultAzureCredential();\n * const client = MapsRoute(credential, \"<maps-account-client-id>\");\n *```\n *\n * @param credential - An TokenCredential instance used to authenticate requests to the service\n * @param mapsAccountClientId - The Azure Maps client id of a specific map resource\n * @param options - Options used to configure the Route Client\n */\nexport default function MapsRoute(\n credential: TokenCredential,\n mapsAccountClientId: string,\n options?: ClientOptions\n): MapsRouteClient;\nexport default function MapsRoute(\n credential: TokenCredential | AzureKeyCredential,\n clientIdOrOptions: string | ClientOptions = {},\n maybeOptions: ClientOptions = {}\n): MapsRouteClient {\n const options = typeof clientIdOrOptions === \"string\" ? maybeOptions : clientIdOrOptions;\n\n /**\n * maps service requires a header \"ms-x-client-id\", which is different from the standard AAD.\n * So we need to do our own implementation.\n * This customized authentication is following by this guide: https://github.com/Azure/azure-sdk-for-js/blob/main/documentation/RLC-customization.md#custom-authentication\n */\n if (isTokenCredential(credential)) {\n const clientId = typeof clientIdOrOptions === \"string\" ? clientIdOrOptions : \"\";\n if (!clientId) {\n throw Error(\"Client id is needed for TokenCredential\");\n }\n const client = createClient(undefined as any, options);\n client.pipeline.addPolicy(\n bearerTokenAuthenticationPolicy({\n credential,\n scopes: `${options.baseUrl || \"https://atlas.microsoft.com\"}/.default`,\n })\n );\n client.pipeline.addPolicy(createMapsClientIdPolicy(clientId));\n return client;\n }\n return createClient(credential, options);\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { LatLon } from \"@azure/maps-common\";\nimport { BatchRequest, RouteGetRouteDirectionsQueryParamProperties } from \"./generated\";\n\nfunction toLatLonString(coordinates: LatLon): string {\n return `${coordinates[0]},${coordinates[1]}`;\n}\n\n/**\n * Transform an array of [Latitude, Longtitute] to a string in the following format:\n * \"Latitude_1,Longtitute_1:Latitude_2,Longtitute_2:...\"\n *\n * @param coordinates - An array of Latitude/Longtitute pair to transform.\n * @returns The transformed string.\n */\nexport function toColonDelimitedLatLonString(coordinates: LatLon[]): string {\n return coordinates.map((c) => toLatLonString(c)).join(\":\");\n}\n\n/**\n * Create a batch request body of a bunch of route direction requests.\n *\n * @param queryParamProperties - An object of the query parameters for a route direction request\n * @returns The composed batch request.\n */\nexport function createRouteDirectionsBatchRequest(\n queryParamProperties: RouteGetRouteDirectionsQueryParamProperties[]\n): BatchRequest {\n return {\n batchItems: queryParamProperties.map((queryParam) => ({\n query:\n \"?\" +\n Object.entries(queryParam)\n .map(([k, v]) => {\n // Skip if no value\n if (typeof v === \"undefined\" || v === null) {\n return \"\";\n }\n // Check name mappings: Array values\n if ((k === \"departAt\" || k === \"arriveAt\") && v instanceof Date) {\n return `${k}=${v.toISOString()}`;\n }\n return `${k}=${v}`;\n })\n .filter((s) => s !== \"\")\n .join(\"&\"),\n })),\n };\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport MapsRoute from \"./mapsRoute\";\n\nexport * from \"./generated\";\nexport * from \"./helpers\";\n\nexport default MapsRoute;\n"],"names":["getClient","LroEngine","isTokenCredential","bearerTokenAuthenticationPolicy","createMapsClientIdPolicy"],"mappings":";;;;;;;;;;AAAA;AAOA;;;AAGG;AACqB,SAAA,YAAY,CAClC,WAA0B,EAC1B,UAAyB,EAAE,EAAA;;IAE3B,MAAM,OAAO,GAAG,CAAA,EAAA,GAAA,OAAO,CAAC,OAAO,MAAA,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,EAAA,GAAI,6BAA6B,CAAC;IACjE,OAAO,CAAC,UAAU,GAAG,CAAA,EAAA,GAAA,OAAO,CAAC,UAAU,MAAI,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,EAAA,GAAA,KAAK,CAAC;AACjD,IAAA,OAAO,GACF,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,EAAA,EAAA,OAAO,CACV,EAAA,EAAA,WAAW,EAAE;AACX,YAAA,gBAAgB,EAAE,kBAAkB;AACrC,SAAA,EAAA,CACF,CAAC;IAEF,MAAM,aAAa,GAAG,CAAA,qCAAA,CAAuC,CAAC;IAC9D,MAAM,eAAe,GACnB,OAAO,CAAC,gBAAgB,IAAI,OAAO,CAAC,gBAAgB,CAAC,e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