@azure/core-client 1.4.1-alpha.20220112.1 → 1.5.1-alpha.20220204.4
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/CHANGELOG.md +11 -3
- package/dist/index.js +396 -378
- package/dist/index.js.map +1 -1
- package/dist-esm/src/authorizeRequestOnClaimChallenge.js.map +1 -1
- package/dist-esm/src/deserializationPolicy.js +1 -1
- package/dist-esm/src/deserializationPolicy.js.map +1 -1
- package/dist-esm/src/index.js.map +1 -1
- package/dist-esm/src/interfaceHelpers.js.map +1 -1
- package/dist-esm/src/interfaces.js.map +1 -1
- package/dist-esm/src/operationHelpers.js.map +1 -1
- package/dist-esm/src/pipeline.js +1 -1
- package/dist-esm/src/pipeline.js.map +1 -1
- package/dist-esm/src/serializationPolicy.js +2 -2
- package/dist-esm/src/serializationPolicy.js.map +1 -1
- package/dist-esm/src/serializer.js +2 -2
- package/dist-esm/src/serializer.js.map +1 -1
- package/dist-esm/src/serviceClient.js +14 -3
- package/dist-esm/src/serviceClient.js.map +1 -1
- package/dist-esm/src/urlHelpers.js +9 -1
- package/dist-esm/src/urlHelpers.js.map +1 -1
- package/package.json +5 -6
- package/types/3.1/core-client.d.ts +20 -0
- package/types/latest/core-client.d.ts +21 -0
package/dist/index.js
CHANGED
|
@@ -6,6 +6,46 @@ var coreRestPipeline = require('@azure/core-rest-pipeline');
|
|
|
6
6
|
var logger = require('@azure/logger');
|
|
7
7
|
require('@azure/core-asynciterator-polyfill');
|
|
8
8
|
|
|
9
|
+
// Copyright (c) Microsoft Corporation.
|
|
10
|
+
/**
|
|
11
|
+
* Encodes a byte array in base64 format.
|
|
12
|
+
* @param value - the Uint8Aray to encode
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
function encodeByteArray(value) {
|
|
16
|
+
// Buffer.from accepts <ArrayBuffer> | <SharedArrayBuffer>-- the TypeScript definition is off here
|
|
17
|
+
// https://nodejs.org/api/buffer.html#buffer_class_method_buffer_from_arraybuffer_byteoffset_length
|
|
18
|
+
const bufferValue = value instanceof Buffer ? value : Buffer.from(value.buffer);
|
|
19
|
+
return bufferValue.toString("base64");
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Decodes a base64 string into a byte array.
|
|
23
|
+
* @param value - the base64 string to decode
|
|
24
|
+
* @internal
|
|
25
|
+
*/
|
|
26
|
+
function decodeString(value) {
|
|
27
|
+
return Buffer.from(value, "base64");
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Decodes a base64 string into a string.
|
|
31
|
+
* @param value - the base64 string to decode
|
|
32
|
+
* @internal
|
|
33
|
+
*/
|
|
34
|
+
function decodeStringToString(value) {
|
|
35
|
+
return Buffer.from(value, "base64").toString();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Copyright (c) Microsoft Corporation.
|
|
39
|
+
// Licensed under the MIT license.
|
|
40
|
+
/**
|
|
41
|
+
* Default key used to access the XML attributes.
|
|
42
|
+
*/
|
|
43
|
+
const XML_ATTRKEY = "$";
|
|
44
|
+
/**
|
|
45
|
+
* Default key used to access the XML value content.
|
|
46
|
+
*/
|
|
47
|
+
const XML_CHARKEY = "_";
|
|
48
|
+
|
|
9
49
|
// Copyright (c) Microsoft Corporation.
|
|
10
50
|
// Licensed under the MIT license.
|
|
11
51
|
/**
|
|
@@ -121,46 +161,6 @@ function flattenResponse(fullResponse, responseSpec) {
|
|
|
121
161
|
});
|
|
122
162
|
}
|
|
123
163
|
|
|
124
|
-
// Copyright (c) Microsoft Corporation.
|
|
125
|
-
/**
|
|
126
|
-
* Encodes a byte array in base64 format.
|
|
127
|
-
* @param value - the Uint8Aray to encode
|
|
128
|
-
* @internal
|
|
129
|
-
*/
|
|
130
|
-
function encodeByteArray(value) {
|
|
131
|
-
// Buffer.from accepts <ArrayBuffer> | <SharedArrayBuffer>-- the TypeScript definition is off here
|
|
132
|
-
// https://nodejs.org/api/buffer.html#buffer_class_method_buffer_from_arraybuffer_byteoffset_length
|
|
133
|
-
const bufferValue = value instanceof Buffer ? value : Buffer.from(value.buffer);
|
|
134
|
-
return bufferValue.toString("base64");
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Decodes a base64 string into a byte array.
|
|
138
|
-
* @param value - the base64 string to decode
|
|
139
|
-
* @internal
|
|
140
|
-
*/
|
|
141
|
-
function decodeString(value) {
|
|
142
|
-
return Buffer.from(value, "base64");
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Decodes a base64 string into a string.
|
|
146
|
-
* @param value - the base64 string to decode
|
|
147
|
-
* @internal
|
|
148
|
-
*/
|
|
149
|
-
function decodeStringToString(value) {
|
|
150
|
-
return Buffer.from(value, "base64").toString();
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// Copyright (c) Microsoft Corporation.
|
|
154
|
-
// Licensed under the MIT license.
|
|
155
|
-
/**
|
|
156
|
-
* Default key used to access the XML attributes.
|
|
157
|
-
*/
|
|
158
|
-
const XML_ATTRKEY = "$";
|
|
159
|
-
/**
|
|
160
|
-
* Default key used to access the XML value content.
|
|
161
|
-
*/
|
|
162
|
-
const XML_CHARKEY = "_";
|
|
163
|
-
|
|
164
164
|
// Copyright (c) Microsoft Corporation.
|
|
165
165
|
class SerializerImpl {
|
|
166
166
|
constructor(modelMappers = {}, isXML = false) {
|
|
@@ -1036,43 +1036,6 @@ const MapperTypeNames = {
|
|
|
1036
1036
|
UnixTime: "UnixTime",
|
|
1037
1037
|
};
|
|
1038
1038
|
|
|
1039
|
-
// Copyright (c) Microsoft Corporation.
|
|
1040
|
-
/**
|
|
1041
|
-
* Gets the list of status codes for streaming responses.
|
|
1042
|
-
* @internal
|
|
1043
|
-
*/
|
|
1044
|
-
function getStreamingResponseStatusCodes(operationSpec) {
|
|
1045
|
-
const result = new Set();
|
|
1046
|
-
for (const statusCode in operationSpec.responses) {
|
|
1047
|
-
const operationResponse = operationSpec.responses[statusCode];
|
|
1048
|
-
if (operationResponse.bodyMapper &&
|
|
1049
|
-
operationResponse.bodyMapper.type.name === MapperTypeNames.Stream) {
|
|
1050
|
-
result.add(Number(statusCode));
|
|
1051
|
-
}
|
|
1052
|
-
}
|
|
1053
|
-
return result;
|
|
1054
|
-
}
|
|
1055
|
-
/**
|
|
1056
|
-
* Get the path to this parameter's value as a dotted string (a.b.c).
|
|
1057
|
-
* @param parameter - The parameter to get the path string for.
|
|
1058
|
-
* @returns The path to this parameter's value as a dotted string.
|
|
1059
|
-
* @internal
|
|
1060
|
-
*/
|
|
1061
|
-
function getPathStringFromParameter(parameter) {
|
|
1062
|
-
const { parameterPath, mapper } = parameter;
|
|
1063
|
-
let result;
|
|
1064
|
-
if (typeof parameterPath === "string") {
|
|
1065
|
-
result = parameterPath;
|
|
1066
|
-
}
|
|
1067
|
-
else if (Array.isArray(parameterPath)) {
|
|
1068
|
-
result = parameterPath.join(".");
|
|
1069
|
-
}
|
|
1070
|
-
else {
|
|
1071
|
-
result = mapper.serializedName;
|
|
1072
|
-
}
|
|
1073
|
-
return result;
|
|
1074
|
-
}
|
|
1075
|
-
|
|
1076
1039
|
// Copyright (c) Microsoft Corporation.
|
|
1077
1040
|
// Licensed under the MIT license.
|
|
1078
1041
|
/**
|
|
@@ -1160,319 +1123,85 @@ function getOperationRequestInfo(request) {
|
|
|
1160
1123
|
return info;
|
|
1161
1124
|
}
|
|
1162
1125
|
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1126
|
+
// Copyright (c) Microsoft Corporation.
|
|
1127
|
+
const defaultJsonContentTypes = ["application/json", "text/json"];
|
|
1128
|
+
const defaultXmlContentTypes = ["application/xml", "application/atom+xml"];
|
|
1129
|
+
/**
|
|
1130
|
+
* The programmatic identifier of the deserializationPolicy.
|
|
1131
|
+
*/
|
|
1132
|
+
const deserializationPolicyName = "deserializationPolicy";
|
|
1133
|
+
/**
|
|
1134
|
+
* This policy handles parsing out responses according to OperationSpecs on the request.
|
|
1135
|
+
*/
|
|
1136
|
+
function deserializationPolicy(options = {}) {
|
|
1137
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
1138
|
+
const jsonContentTypes = (_b = (_a = options.expectedContentTypes) === null || _a === void 0 ? void 0 : _a.json) !== null && _b !== void 0 ? _b : defaultJsonContentTypes;
|
|
1139
|
+
const xmlContentTypes = (_d = (_c = options.expectedContentTypes) === null || _c === void 0 ? void 0 : _c.xml) !== null && _d !== void 0 ? _d : defaultXmlContentTypes;
|
|
1140
|
+
const parseXML = options.parseXML;
|
|
1141
|
+
const serializerOptions = options.serializerOptions;
|
|
1142
|
+
const updatedOptions = {
|
|
1143
|
+
xml: {
|
|
1144
|
+
rootName: (_e = serializerOptions === null || serializerOptions === void 0 ? void 0 : serializerOptions.xml.rootName) !== null && _e !== void 0 ? _e : "",
|
|
1145
|
+
includeRoot: (_f = serializerOptions === null || serializerOptions === void 0 ? void 0 : serializerOptions.xml.includeRoot) !== null && _f !== void 0 ? _f : false,
|
|
1146
|
+
xmlCharKey: (_g = serializerOptions === null || serializerOptions === void 0 ? void 0 : serializerOptions.xml.xmlCharKey) !== null && _g !== void 0 ? _g : XML_CHARKEY,
|
|
1147
|
+
},
|
|
1148
|
+
};
|
|
1149
|
+
return {
|
|
1150
|
+
name: deserializationPolicyName,
|
|
1151
|
+
async sendRequest(request, next) {
|
|
1152
|
+
const response = await next(request);
|
|
1153
|
+
return deserializeResponseBody(jsonContentTypes, xmlContentTypes, response, updatedOptions, parseXML);
|
|
1154
|
+
},
|
|
1155
|
+
};
|
|
1156
|
+
}
|
|
1157
|
+
function getOperationResponseMap(parsedResponse) {
|
|
1158
|
+
let result;
|
|
1159
|
+
const request = parsedResponse.request;
|
|
1160
|
+
const operationInfo = getOperationRequestInfo(request);
|
|
1161
|
+
const operationSpec = operationInfo === null || operationInfo === void 0 ? void 0 : operationInfo.operationSpec;
|
|
1162
|
+
if (operationSpec) {
|
|
1163
|
+
if (!(operationInfo === null || operationInfo === void 0 ? void 0 : operationInfo.operationResponseGetter)) {
|
|
1164
|
+
result = operationSpec.responses[parsedResponse.status];
|
|
1182
1165
|
}
|
|
1183
1166
|
else {
|
|
1184
|
-
|
|
1167
|
+
result = operationInfo === null || operationInfo === void 0 ? void 0 : operationInfo.operationResponseGetter(operationSpec, parsedResponse);
|
|
1185
1168
|
}
|
|
1186
1169
|
}
|
|
1187
|
-
const { queryParams, sequenceParams } = calculateQueryParameters(operationSpec, operationArguments, fallbackObject);
|
|
1188
|
-
/**
|
|
1189
|
-
* Notice that this call sets the `noOverwrite` parameter to true if the `requestUrl`
|
|
1190
|
-
* is an absolute path. This ensures that existing query parameter values in `requestUrl`
|
|
1191
|
-
* do not get overwritten. On the other hand when `requestUrl` is not absolute path, it
|
|
1192
|
-
* is still being built so there is nothing to overwrite.
|
|
1193
|
-
*/
|
|
1194
|
-
requestUrl = appendQueryParams(requestUrl, queryParams, sequenceParams, isAbsolutePath);
|
|
1195
|
-
return requestUrl;
|
|
1196
|
-
}
|
|
1197
|
-
function replaceAll(input, replacements) {
|
|
1198
|
-
let result = input;
|
|
1199
|
-
for (const [searchValue, replaceValue] of replacements) {
|
|
1200
|
-
result = result.split(searchValue).join(replaceValue);
|
|
1201
|
-
}
|
|
1202
1170
|
return result;
|
|
1203
1171
|
}
|
|
1204
|
-
function
|
|
1205
|
-
|
|
1206
|
-
const
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1172
|
+
function shouldDeserializeResponse(parsedResponse) {
|
|
1173
|
+
const request = parsedResponse.request;
|
|
1174
|
+
const operationInfo = getOperationRequestInfo(request);
|
|
1175
|
+
const shouldDeserialize = operationInfo === null || operationInfo === void 0 ? void 0 : operationInfo.shouldDeserialize;
|
|
1176
|
+
let result;
|
|
1177
|
+
if (shouldDeserialize === undefined) {
|
|
1178
|
+
result = true;
|
|
1179
|
+
}
|
|
1180
|
+
else if (typeof shouldDeserialize === "boolean") {
|
|
1181
|
+
result = shouldDeserialize;
|
|
1182
|
+
}
|
|
1183
|
+
else {
|
|
1184
|
+
result = shouldDeserialize(parsedResponse);
|
|
1217
1185
|
}
|
|
1218
1186
|
return result;
|
|
1219
1187
|
}
|
|
1220
|
-
function
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
if (!pathToAppend) {
|
|
1225
|
-
return url;
|
|
1226
|
-
}
|
|
1227
|
-
const parsedUrl = new URL(url);
|
|
1228
|
-
let newPath = parsedUrl.pathname;
|
|
1229
|
-
if (!newPath.endsWith("/")) {
|
|
1230
|
-
newPath = `${newPath}/`;
|
|
1188
|
+
async function deserializeResponseBody(jsonContentTypes, xmlContentTypes, response, options, parseXML) {
|
|
1189
|
+
const parsedResponse = await parse(jsonContentTypes, xmlContentTypes, response, options, parseXML);
|
|
1190
|
+
if (!shouldDeserializeResponse(parsedResponse)) {
|
|
1191
|
+
return parsedResponse;
|
|
1231
1192
|
}
|
|
1232
|
-
|
|
1233
|
-
|
|
1193
|
+
const operationInfo = getOperationRequestInfo(parsedResponse.request);
|
|
1194
|
+
const operationSpec = operationInfo === null || operationInfo === void 0 ? void 0 : operationInfo.operationSpec;
|
|
1195
|
+
if (!operationSpec || !operationSpec.responses) {
|
|
1196
|
+
return parsedResponse;
|
|
1234
1197
|
}
|
|
1235
|
-
const
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
newPath = newPath + path;
|
|
1240
|
-
if (search) {
|
|
1241
|
-
parsedUrl.search = parsedUrl.search ? `${parsedUrl.search}&${search}` : search;
|
|
1242
|
-
}
|
|
1198
|
+
const responseSpec = getOperationResponseMap(parsedResponse);
|
|
1199
|
+
const { error, shouldReturnResponse } = handleErrorResponse(parsedResponse, operationSpec, responseSpec);
|
|
1200
|
+
if (error) {
|
|
1201
|
+
throw error;
|
|
1243
1202
|
}
|
|
1244
|
-
else {
|
|
1245
|
-
|
|
1246
|
-
}
|
|
1247
|
-
parsedUrl.pathname = newPath;
|
|
1248
|
-
return parsedUrl.toString();
|
|
1249
|
-
}
|
|
1250
|
-
function calculateQueryParameters(operationSpec, operationArguments, fallbackObject) {
|
|
1251
|
-
var _a;
|
|
1252
|
-
const result = new Map();
|
|
1253
|
-
const sequenceParams = new Set();
|
|
1254
|
-
if ((_a = operationSpec.queryParameters) === null || _a === void 0 ? void 0 : _a.length) {
|
|
1255
|
-
for (const queryParameter of operationSpec.queryParameters) {
|
|
1256
|
-
if (queryParameter.mapper.type.name === "Sequence" && queryParameter.mapper.serializedName) {
|
|
1257
|
-
sequenceParams.add(queryParameter.mapper.serializedName);
|
|
1258
|
-
}
|
|
1259
|
-
let queryParameterValue = getOperationArgumentValueFromParameter(operationArguments, queryParameter, fallbackObject);
|
|
1260
|
-
if ((queryParameterValue !== undefined && queryParameterValue !== null) ||
|
|
1261
|
-
queryParameter.mapper.required) {
|
|
1262
|
-
queryParameterValue = operationSpec.serializer.serialize(queryParameter.mapper, queryParameterValue, getPathStringFromParameter(queryParameter));
|
|
1263
|
-
const delimiter = queryParameter.collectionFormat
|
|
1264
|
-
? CollectionFormatToDelimiterMap[queryParameter.collectionFormat]
|
|
1265
|
-
: "";
|
|
1266
|
-
if (Array.isArray(queryParameterValue)) {
|
|
1267
|
-
// replace null and undefined
|
|
1268
|
-
queryParameterValue = queryParameterValue.map((item) => {
|
|
1269
|
-
if (item === null || item === undefined) {
|
|
1270
|
-
return "";
|
|
1271
|
-
}
|
|
1272
|
-
return item;
|
|
1273
|
-
});
|
|
1274
|
-
}
|
|
1275
|
-
if (queryParameter.collectionFormat === "Multi" && queryParameterValue.length === 0) {
|
|
1276
|
-
continue;
|
|
1277
|
-
}
|
|
1278
|
-
else if (Array.isArray(queryParameterValue) &&
|
|
1279
|
-
(queryParameter.collectionFormat === "SSV" || queryParameter.collectionFormat === "TSV")) {
|
|
1280
|
-
queryParameterValue = queryParameterValue.join(delimiter);
|
|
1281
|
-
}
|
|
1282
|
-
if (!queryParameter.skipEncoding) {
|
|
1283
|
-
if (Array.isArray(queryParameterValue)) {
|
|
1284
|
-
queryParameterValue = queryParameterValue.map((item) => {
|
|
1285
|
-
return encodeURIComponent(item);
|
|
1286
|
-
});
|
|
1287
|
-
}
|
|
1288
|
-
else {
|
|
1289
|
-
queryParameterValue = encodeURIComponent(queryParameterValue);
|
|
1290
|
-
}
|
|
1291
|
-
}
|
|
1292
|
-
// Join pipes and CSV *after* encoding, or the server will be upset.
|
|
1293
|
-
if (Array.isArray(queryParameterValue) &&
|
|
1294
|
-
(queryParameter.collectionFormat === "CSV" || queryParameter.collectionFormat === "Pipes")) {
|
|
1295
|
-
queryParameterValue = queryParameterValue.join(delimiter);
|
|
1296
|
-
}
|
|
1297
|
-
result.set(queryParameter.mapper.serializedName || getPathStringFromParameter(queryParameter), queryParameterValue);
|
|
1298
|
-
}
|
|
1299
|
-
}
|
|
1300
|
-
}
|
|
1301
|
-
return {
|
|
1302
|
-
queryParams: result,
|
|
1303
|
-
sequenceParams,
|
|
1304
|
-
};
|
|
1305
|
-
}
|
|
1306
|
-
function simpleParseQueryParams(queryString) {
|
|
1307
|
-
const result = new Map();
|
|
1308
|
-
if (!queryString || queryString[0] !== "?") {
|
|
1309
|
-
return result;
|
|
1310
|
-
}
|
|
1311
|
-
// remove the leading ?
|
|
1312
|
-
queryString = queryString.slice(1);
|
|
1313
|
-
const pairs = queryString.split("&");
|
|
1314
|
-
for (const pair of pairs) {
|
|
1315
|
-
const [name, value] = pair.split("=", 2);
|
|
1316
|
-
const existingValue = result.get(name);
|
|
1317
|
-
if (existingValue) {
|
|
1318
|
-
if (Array.isArray(existingValue)) {
|
|
1319
|
-
existingValue.push(value);
|
|
1320
|
-
}
|
|
1321
|
-
else {
|
|
1322
|
-
result.set(name, [existingValue, value]);
|
|
1323
|
-
}
|
|
1324
|
-
}
|
|
1325
|
-
else {
|
|
1326
|
-
result.set(name, value);
|
|
1327
|
-
}
|
|
1328
|
-
}
|
|
1329
|
-
return result;
|
|
1330
|
-
}
|
|
1331
|
-
/** @internal */
|
|
1332
|
-
function appendQueryParams(url, queryParams, sequenceParams, noOverwrite = false) {
|
|
1333
|
-
if (queryParams.size === 0) {
|
|
1334
|
-
return url;
|
|
1335
|
-
}
|
|
1336
|
-
const parsedUrl = new URL(url);
|
|
1337
|
-
// QUIRK: parsedUrl.searchParams will have their name/value pairs decoded, which
|
|
1338
|
-
// can change their meaning to the server, such as in the case of a SAS signature.
|
|
1339
|
-
// To avoid accidentally un-encoding a query param, we parse the key/values ourselves
|
|
1340
|
-
const combinedParams = simpleParseQueryParams(parsedUrl.search);
|
|
1341
|
-
for (const [name, value] of queryParams) {
|
|
1342
|
-
const existingValue = combinedParams.get(name);
|
|
1343
|
-
if (Array.isArray(existingValue)) {
|
|
1344
|
-
if (Array.isArray(value)) {
|
|
1345
|
-
existingValue.push(...value);
|
|
1346
|
-
const valueSet = new Set(existingValue);
|
|
1347
|
-
combinedParams.set(name, Array.from(valueSet));
|
|
1348
|
-
}
|
|
1349
|
-
else {
|
|
1350
|
-
existingValue.push(value);
|
|
1351
|
-
}
|
|
1352
|
-
}
|
|
1353
|
-
else if (existingValue) {
|
|
1354
|
-
if (Array.isArray(value)) {
|
|
1355
|
-
value.unshift(existingValue);
|
|
1356
|
-
}
|
|
1357
|
-
else if (sequenceParams.has(name)) {
|
|
1358
|
-
combinedParams.set(name, [existingValue, value]);
|
|
1359
|
-
}
|
|
1360
|
-
if (!noOverwrite) {
|
|
1361
|
-
combinedParams.set(name, value);
|
|
1362
|
-
}
|
|
1363
|
-
}
|
|
1364
|
-
else {
|
|
1365
|
-
combinedParams.set(name, value);
|
|
1366
|
-
}
|
|
1367
|
-
}
|
|
1368
|
-
const searchPieces = [];
|
|
1369
|
-
for (const [name, value] of combinedParams) {
|
|
1370
|
-
if (typeof value === "string") {
|
|
1371
|
-
searchPieces.push(`${name}=${value}`);
|
|
1372
|
-
}
|
|
1373
|
-
else if (Array.isArray(value)) {
|
|
1374
|
-
// QUIRK: If we get an array of values, include multiple key/value pairs
|
|
1375
|
-
for (const subValue of value) {
|
|
1376
|
-
searchPieces.push(`${name}=${subValue}`);
|
|
1377
|
-
}
|
|
1378
|
-
}
|
|
1379
|
-
else {
|
|
1380
|
-
searchPieces.push(`${name}=${value}`);
|
|
1381
|
-
}
|
|
1382
|
-
}
|
|
1383
|
-
// QUIRK: we have to set search manually as searchParams will encode comma when it shouldn't.
|
|
1384
|
-
parsedUrl.search = searchPieces.length ? `?${searchPieces.join("&")}` : "";
|
|
1385
|
-
return parsedUrl.toString();
|
|
1386
|
-
}
|
|
1387
|
-
|
|
1388
|
-
// Copyright (c) Microsoft Corporation.
|
|
1389
|
-
let cachedHttpClient;
|
|
1390
|
-
function getCachedDefaultHttpClient() {
|
|
1391
|
-
if (!cachedHttpClient) {
|
|
1392
|
-
cachedHttpClient = coreRestPipeline.createDefaultHttpClient();
|
|
1393
|
-
}
|
|
1394
|
-
return cachedHttpClient;
|
|
1395
|
-
}
|
|
1396
|
-
|
|
1397
|
-
// Copyright (c) Microsoft Corporation.
|
|
1398
|
-
const defaultJsonContentTypes = ["application/json", "text/json"];
|
|
1399
|
-
const defaultXmlContentTypes = ["application/xml", "application/atom+xml"];
|
|
1400
|
-
/**
|
|
1401
|
-
* The programmatic identifier of the deserializationPolicy.
|
|
1402
|
-
*/
|
|
1403
|
-
const deserializationPolicyName = "deserializationPolicy";
|
|
1404
|
-
/**
|
|
1405
|
-
* This policy handles parsing out responses according to OperationSpecs on the request.
|
|
1406
|
-
*/
|
|
1407
|
-
function deserializationPolicy(options = {}) {
|
|
1408
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
1409
|
-
const jsonContentTypes = (_b = (_a = options.expectedContentTypes) === null || _a === void 0 ? void 0 : _a.json) !== null && _b !== void 0 ? _b : defaultJsonContentTypes;
|
|
1410
|
-
const xmlContentTypes = (_d = (_c = options.expectedContentTypes) === null || _c === void 0 ? void 0 : _c.xml) !== null && _d !== void 0 ? _d : defaultXmlContentTypes;
|
|
1411
|
-
const parseXML = options.parseXML;
|
|
1412
|
-
const serializerOptions = options.serializerOptions;
|
|
1413
|
-
const updatedOptions = {
|
|
1414
|
-
xml: {
|
|
1415
|
-
rootName: (_e = serializerOptions === null || serializerOptions === void 0 ? void 0 : serializerOptions.xml.rootName) !== null && _e !== void 0 ? _e : "",
|
|
1416
|
-
includeRoot: (_f = serializerOptions === null || serializerOptions === void 0 ? void 0 : serializerOptions.xml.includeRoot) !== null && _f !== void 0 ? _f : false,
|
|
1417
|
-
xmlCharKey: (_g = serializerOptions === null || serializerOptions === void 0 ? void 0 : serializerOptions.xml.xmlCharKey) !== null && _g !== void 0 ? _g : XML_CHARKEY,
|
|
1418
|
-
},
|
|
1419
|
-
};
|
|
1420
|
-
return {
|
|
1421
|
-
name: deserializationPolicyName,
|
|
1422
|
-
async sendRequest(request, next) {
|
|
1423
|
-
const response = await next(request);
|
|
1424
|
-
return deserializeResponseBody(jsonContentTypes, xmlContentTypes, response, updatedOptions, parseXML);
|
|
1425
|
-
},
|
|
1426
|
-
};
|
|
1427
|
-
}
|
|
1428
|
-
function getOperationResponseMap(parsedResponse) {
|
|
1429
|
-
let result;
|
|
1430
|
-
const request = parsedResponse.request;
|
|
1431
|
-
const operationInfo = getOperationRequestInfo(request);
|
|
1432
|
-
const operationSpec = operationInfo === null || operationInfo === void 0 ? void 0 : operationInfo.operationSpec;
|
|
1433
|
-
if (operationSpec) {
|
|
1434
|
-
if (!(operationInfo === null || operationInfo === void 0 ? void 0 : operationInfo.operationResponseGetter)) {
|
|
1435
|
-
result = operationSpec.responses[parsedResponse.status];
|
|
1436
|
-
}
|
|
1437
|
-
else {
|
|
1438
|
-
result = operationInfo === null || operationInfo === void 0 ? void 0 : operationInfo.operationResponseGetter(operationSpec, parsedResponse);
|
|
1439
|
-
}
|
|
1440
|
-
}
|
|
1441
|
-
return result;
|
|
1442
|
-
}
|
|
1443
|
-
function shouldDeserializeResponse(parsedResponse) {
|
|
1444
|
-
const request = parsedResponse.request;
|
|
1445
|
-
const operationInfo = getOperationRequestInfo(request);
|
|
1446
|
-
const shouldDeserialize = operationInfo === null || operationInfo === void 0 ? void 0 : operationInfo.shouldDeserialize;
|
|
1447
|
-
let result;
|
|
1448
|
-
if (shouldDeserialize === undefined) {
|
|
1449
|
-
result = true;
|
|
1450
|
-
}
|
|
1451
|
-
else if (typeof shouldDeserialize === "boolean") {
|
|
1452
|
-
result = shouldDeserialize;
|
|
1453
|
-
}
|
|
1454
|
-
else {
|
|
1455
|
-
result = shouldDeserialize(parsedResponse);
|
|
1456
|
-
}
|
|
1457
|
-
return result;
|
|
1458
|
-
}
|
|
1459
|
-
async function deserializeResponseBody(jsonContentTypes, xmlContentTypes, response, options, parseXML) {
|
|
1460
|
-
const parsedResponse = await parse(jsonContentTypes, xmlContentTypes, response, options, parseXML);
|
|
1461
|
-
if (!shouldDeserializeResponse(parsedResponse)) {
|
|
1462
|
-
return parsedResponse;
|
|
1463
|
-
}
|
|
1464
|
-
const operationInfo = getOperationRequestInfo(parsedResponse.request);
|
|
1465
|
-
const operationSpec = operationInfo === null || operationInfo === void 0 ? void 0 : operationInfo.operationSpec;
|
|
1466
|
-
if (!operationSpec || !operationSpec.responses) {
|
|
1467
|
-
return parsedResponse;
|
|
1468
|
-
}
|
|
1469
|
-
const responseSpec = getOperationResponseMap(parsedResponse);
|
|
1470
|
-
const { error, shouldReturnResponse } = handleErrorResponse(parsedResponse, operationSpec, responseSpec);
|
|
1471
|
-
if (error) {
|
|
1472
|
-
throw error;
|
|
1473
|
-
}
|
|
1474
|
-
else if (shouldReturnResponse) {
|
|
1475
|
-
return parsedResponse;
|
|
1203
|
+
else if (shouldReturnResponse) {
|
|
1204
|
+
return parsedResponse;
|
|
1476
1205
|
}
|
|
1477
1206
|
// An operation response spec does exist for current status code, so
|
|
1478
1207
|
// use it to deserialize the response.
|
|
@@ -1620,6 +1349,43 @@ async function parse(jsonContentTypes, xmlContentTypes, operationResponse, opts,
|
|
|
1620
1349
|
return operationResponse;
|
|
1621
1350
|
}
|
|
1622
1351
|
|
|
1352
|
+
// Copyright (c) Microsoft Corporation.
|
|
1353
|
+
/**
|
|
1354
|
+
* Gets the list of status codes for streaming responses.
|
|
1355
|
+
* @internal
|
|
1356
|
+
*/
|
|
1357
|
+
function getStreamingResponseStatusCodes(operationSpec) {
|
|
1358
|
+
const result = new Set();
|
|
1359
|
+
for (const statusCode in operationSpec.responses) {
|
|
1360
|
+
const operationResponse = operationSpec.responses[statusCode];
|
|
1361
|
+
if (operationResponse.bodyMapper &&
|
|
1362
|
+
operationResponse.bodyMapper.type.name === MapperTypeNames.Stream) {
|
|
1363
|
+
result.add(Number(statusCode));
|
|
1364
|
+
}
|
|
1365
|
+
}
|
|
1366
|
+
return result;
|
|
1367
|
+
}
|
|
1368
|
+
/**
|
|
1369
|
+
* Get the path to this parameter's value as a dotted string (a.b.c).
|
|
1370
|
+
* @param parameter - The parameter to get the path string for.
|
|
1371
|
+
* @returns The path to this parameter's value as a dotted string.
|
|
1372
|
+
* @internal
|
|
1373
|
+
*/
|
|
1374
|
+
function getPathStringFromParameter(parameter) {
|
|
1375
|
+
const { parameterPath, mapper } = parameter;
|
|
1376
|
+
let result;
|
|
1377
|
+
if (typeof parameterPath === "string") {
|
|
1378
|
+
result = parameterPath;
|
|
1379
|
+
}
|
|
1380
|
+
else if (Array.isArray(parameterPath)) {
|
|
1381
|
+
result = parameterPath.join(".");
|
|
1382
|
+
}
|
|
1383
|
+
else {
|
|
1384
|
+
result = mapper.serializedName;
|
|
1385
|
+
}
|
|
1386
|
+
return result;
|
|
1387
|
+
}
|
|
1388
|
+
|
|
1623
1389
|
// Copyright (c) Microsoft Corporation.
|
|
1624
1390
|
/**
|
|
1625
1391
|
* The programmatic identifier of the serializationPolicy.
|
|
@@ -1790,6 +1556,247 @@ function createClientPipeline(options = {}) {
|
|
|
1790
1556
|
return pipeline;
|
|
1791
1557
|
}
|
|
1792
1558
|
|
|
1559
|
+
// Copyright (c) Microsoft Corporation.
|
|
1560
|
+
let cachedHttpClient;
|
|
1561
|
+
function getCachedDefaultHttpClient() {
|
|
1562
|
+
if (!cachedHttpClient) {
|
|
1563
|
+
cachedHttpClient = coreRestPipeline.createDefaultHttpClient();
|
|
1564
|
+
}
|
|
1565
|
+
return cachedHttpClient;
|
|
1566
|
+
}
|
|
1567
|
+
|
|
1568
|
+
// Copyright (c) Microsoft Corporation.
|
|
1569
|
+
const CollectionFormatToDelimiterMap = {
|
|
1570
|
+
CSV: ",",
|
|
1571
|
+
SSV: " ",
|
|
1572
|
+
Multi: "Multi",
|
|
1573
|
+
TSV: "\t",
|
|
1574
|
+
Pipes: "|",
|
|
1575
|
+
};
|
|
1576
|
+
function getRequestUrl(baseUri, operationSpec, operationArguments, fallbackObject) {
|
|
1577
|
+
const urlReplacements = calculateUrlReplacements(operationSpec, operationArguments, fallbackObject);
|
|
1578
|
+
let isAbsolutePath = false;
|
|
1579
|
+
let requestUrl = replaceAll(baseUri, urlReplacements);
|
|
1580
|
+
if (operationSpec.path) {
|
|
1581
|
+
let path = replaceAll(operationSpec.path, urlReplacements);
|
|
1582
|
+
// QUIRK: sometimes we get a path component like /{nextLink}
|
|
1583
|
+
// which may be a fully formed URL with a leading /. In that case, we should
|
|
1584
|
+
// remove the leading /
|
|
1585
|
+
if (operationSpec.path === "/{nextLink}" && path.startsWith("/")) {
|
|
1586
|
+
path = path.substring(1);
|
|
1587
|
+
}
|
|
1588
|
+
// QUIRK: sometimes we get a path component like {nextLink}
|
|
1589
|
+
// which may be a fully formed URL. In that case, we should
|
|
1590
|
+
// ignore the baseUri.
|
|
1591
|
+
if (isAbsoluteUrl(path)) {
|
|
1592
|
+
requestUrl = path;
|
|
1593
|
+
isAbsolutePath = true;
|
|
1594
|
+
}
|
|
1595
|
+
else {
|
|
1596
|
+
requestUrl = appendPath(requestUrl, path);
|
|
1597
|
+
}
|
|
1598
|
+
}
|
|
1599
|
+
const { queryParams, sequenceParams } = calculateQueryParameters(operationSpec, operationArguments, fallbackObject);
|
|
1600
|
+
/**
|
|
1601
|
+
* Notice that this call sets the `noOverwrite` parameter to true if the `requestUrl`
|
|
1602
|
+
* is an absolute path. This ensures that existing query parameter values in `requestUrl`
|
|
1603
|
+
* do not get overwritten. On the other hand when `requestUrl` is not absolute path, it
|
|
1604
|
+
* is still being built so there is nothing to overwrite.
|
|
1605
|
+
*/
|
|
1606
|
+
requestUrl = appendQueryParams(requestUrl, queryParams, sequenceParams, isAbsolutePath);
|
|
1607
|
+
return requestUrl;
|
|
1608
|
+
}
|
|
1609
|
+
function replaceAll(input, replacements) {
|
|
1610
|
+
let result = input;
|
|
1611
|
+
for (const [searchValue, replaceValue] of replacements) {
|
|
1612
|
+
result = result.split(searchValue).join(replaceValue);
|
|
1613
|
+
}
|
|
1614
|
+
return result;
|
|
1615
|
+
}
|
|
1616
|
+
function calculateUrlReplacements(operationSpec, operationArguments, fallbackObject) {
|
|
1617
|
+
var _a;
|
|
1618
|
+
const result = new Map();
|
|
1619
|
+
if ((_a = operationSpec.urlParameters) === null || _a === void 0 ? void 0 : _a.length) {
|
|
1620
|
+
for (const urlParameter of operationSpec.urlParameters) {
|
|
1621
|
+
let urlParameterValue = getOperationArgumentValueFromParameter(operationArguments, urlParameter, fallbackObject);
|
|
1622
|
+
const parameterPathString = getPathStringFromParameter(urlParameter);
|
|
1623
|
+
urlParameterValue = operationSpec.serializer.serialize(urlParameter.mapper, urlParameterValue, parameterPathString);
|
|
1624
|
+
if (!urlParameter.skipEncoding) {
|
|
1625
|
+
urlParameterValue = encodeURIComponent(urlParameterValue);
|
|
1626
|
+
}
|
|
1627
|
+
result.set(`{${urlParameter.mapper.serializedName || parameterPathString}}`, urlParameterValue);
|
|
1628
|
+
}
|
|
1629
|
+
}
|
|
1630
|
+
return result;
|
|
1631
|
+
}
|
|
1632
|
+
function isAbsoluteUrl(url) {
|
|
1633
|
+
return url.includes("://");
|
|
1634
|
+
}
|
|
1635
|
+
function appendPath(url, pathToAppend) {
|
|
1636
|
+
if (!pathToAppend) {
|
|
1637
|
+
return url;
|
|
1638
|
+
}
|
|
1639
|
+
const parsedUrl = new URL(url);
|
|
1640
|
+
let newPath = parsedUrl.pathname;
|
|
1641
|
+
if (!newPath.endsWith("/")) {
|
|
1642
|
+
newPath = `${newPath}/`;
|
|
1643
|
+
}
|
|
1644
|
+
if (pathToAppend.startsWith("/")) {
|
|
1645
|
+
pathToAppend = pathToAppend.substring(1);
|
|
1646
|
+
}
|
|
1647
|
+
const searchStart = pathToAppend.indexOf("?");
|
|
1648
|
+
if (searchStart !== -1) {
|
|
1649
|
+
const path = pathToAppend.substring(0, searchStart);
|
|
1650
|
+
const search = pathToAppend.substring(searchStart + 1);
|
|
1651
|
+
newPath = newPath + path;
|
|
1652
|
+
if (search) {
|
|
1653
|
+
parsedUrl.search = parsedUrl.search ? `${parsedUrl.search}&${search}` : search;
|
|
1654
|
+
}
|
|
1655
|
+
}
|
|
1656
|
+
else {
|
|
1657
|
+
newPath = newPath + pathToAppend;
|
|
1658
|
+
}
|
|
1659
|
+
parsedUrl.pathname = newPath;
|
|
1660
|
+
return parsedUrl.toString();
|
|
1661
|
+
}
|
|
1662
|
+
function calculateQueryParameters(operationSpec, operationArguments, fallbackObject) {
|
|
1663
|
+
var _a;
|
|
1664
|
+
const result = new Map();
|
|
1665
|
+
const sequenceParams = new Set();
|
|
1666
|
+
if ((_a = operationSpec.queryParameters) === null || _a === void 0 ? void 0 : _a.length) {
|
|
1667
|
+
for (const queryParameter of operationSpec.queryParameters) {
|
|
1668
|
+
if (queryParameter.mapper.type.name === "Sequence" && queryParameter.mapper.serializedName) {
|
|
1669
|
+
sequenceParams.add(queryParameter.mapper.serializedName);
|
|
1670
|
+
}
|
|
1671
|
+
let queryParameterValue = getOperationArgumentValueFromParameter(operationArguments, queryParameter, fallbackObject);
|
|
1672
|
+
if ((queryParameterValue !== undefined && queryParameterValue !== null) ||
|
|
1673
|
+
queryParameter.mapper.required) {
|
|
1674
|
+
queryParameterValue = operationSpec.serializer.serialize(queryParameter.mapper, queryParameterValue, getPathStringFromParameter(queryParameter));
|
|
1675
|
+
const delimiter = queryParameter.collectionFormat
|
|
1676
|
+
? CollectionFormatToDelimiterMap[queryParameter.collectionFormat]
|
|
1677
|
+
: "";
|
|
1678
|
+
if (Array.isArray(queryParameterValue)) {
|
|
1679
|
+
// replace null and undefined
|
|
1680
|
+
queryParameterValue = queryParameterValue.map((item) => {
|
|
1681
|
+
if (item === null || item === undefined) {
|
|
1682
|
+
return "";
|
|
1683
|
+
}
|
|
1684
|
+
return item;
|
|
1685
|
+
});
|
|
1686
|
+
}
|
|
1687
|
+
if (queryParameter.collectionFormat === "Multi" && queryParameterValue.length === 0) {
|
|
1688
|
+
continue;
|
|
1689
|
+
}
|
|
1690
|
+
else if (Array.isArray(queryParameterValue) &&
|
|
1691
|
+
(queryParameter.collectionFormat === "SSV" || queryParameter.collectionFormat === "TSV")) {
|
|
1692
|
+
queryParameterValue = queryParameterValue.join(delimiter);
|
|
1693
|
+
}
|
|
1694
|
+
if (!queryParameter.skipEncoding) {
|
|
1695
|
+
if (Array.isArray(queryParameterValue)) {
|
|
1696
|
+
queryParameterValue = queryParameterValue.map((item) => {
|
|
1697
|
+
return encodeURIComponent(item);
|
|
1698
|
+
});
|
|
1699
|
+
}
|
|
1700
|
+
else {
|
|
1701
|
+
queryParameterValue = encodeURIComponent(queryParameterValue);
|
|
1702
|
+
}
|
|
1703
|
+
}
|
|
1704
|
+
// Join pipes and CSV *after* encoding, or the server will be upset.
|
|
1705
|
+
if (Array.isArray(queryParameterValue) &&
|
|
1706
|
+
(queryParameter.collectionFormat === "CSV" || queryParameter.collectionFormat === "Pipes")) {
|
|
1707
|
+
queryParameterValue = queryParameterValue.join(delimiter);
|
|
1708
|
+
}
|
|
1709
|
+
result.set(queryParameter.mapper.serializedName || getPathStringFromParameter(queryParameter), queryParameterValue);
|
|
1710
|
+
}
|
|
1711
|
+
}
|
|
1712
|
+
}
|
|
1713
|
+
return {
|
|
1714
|
+
queryParams: result,
|
|
1715
|
+
sequenceParams,
|
|
1716
|
+
};
|
|
1717
|
+
}
|
|
1718
|
+
function simpleParseQueryParams(queryString) {
|
|
1719
|
+
const result = new Map();
|
|
1720
|
+
if (!queryString || queryString[0] !== "?") {
|
|
1721
|
+
return result;
|
|
1722
|
+
}
|
|
1723
|
+
// remove the leading ?
|
|
1724
|
+
queryString = queryString.slice(1);
|
|
1725
|
+
const pairs = queryString.split("&");
|
|
1726
|
+
for (const pair of pairs) {
|
|
1727
|
+
const [name, value] = pair.split("=", 2);
|
|
1728
|
+
const existingValue = result.get(name);
|
|
1729
|
+
if (existingValue) {
|
|
1730
|
+
if (Array.isArray(existingValue)) {
|
|
1731
|
+
existingValue.push(value);
|
|
1732
|
+
}
|
|
1733
|
+
else {
|
|
1734
|
+
result.set(name, [existingValue, value]);
|
|
1735
|
+
}
|
|
1736
|
+
}
|
|
1737
|
+
else {
|
|
1738
|
+
result.set(name, value);
|
|
1739
|
+
}
|
|
1740
|
+
}
|
|
1741
|
+
return result;
|
|
1742
|
+
}
|
|
1743
|
+
/** @internal */
|
|
1744
|
+
function appendQueryParams(url, queryParams, sequenceParams, noOverwrite = false) {
|
|
1745
|
+
if (queryParams.size === 0) {
|
|
1746
|
+
return url;
|
|
1747
|
+
}
|
|
1748
|
+
const parsedUrl = new URL(url);
|
|
1749
|
+
// QUIRK: parsedUrl.searchParams will have their name/value pairs decoded, which
|
|
1750
|
+
// can change their meaning to the server, such as in the case of a SAS signature.
|
|
1751
|
+
// To avoid accidentally un-encoding a query param, we parse the key/values ourselves
|
|
1752
|
+
const combinedParams = simpleParseQueryParams(parsedUrl.search);
|
|
1753
|
+
for (const [name, value] of queryParams) {
|
|
1754
|
+
const existingValue = combinedParams.get(name);
|
|
1755
|
+
if (Array.isArray(existingValue)) {
|
|
1756
|
+
if (Array.isArray(value)) {
|
|
1757
|
+
existingValue.push(...value);
|
|
1758
|
+
const valueSet = new Set(existingValue);
|
|
1759
|
+
combinedParams.set(name, Array.from(valueSet));
|
|
1760
|
+
}
|
|
1761
|
+
else {
|
|
1762
|
+
existingValue.push(value);
|
|
1763
|
+
}
|
|
1764
|
+
}
|
|
1765
|
+
else if (existingValue) {
|
|
1766
|
+
if (Array.isArray(value)) {
|
|
1767
|
+
value.unshift(existingValue);
|
|
1768
|
+
}
|
|
1769
|
+
else if (sequenceParams.has(name)) {
|
|
1770
|
+
combinedParams.set(name, [existingValue, value]);
|
|
1771
|
+
}
|
|
1772
|
+
if (!noOverwrite) {
|
|
1773
|
+
combinedParams.set(name, value);
|
|
1774
|
+
}
|
|
1775
|
+
}
|
|
1776
|
+
else {
|
|
1777
|
+
combinedParams.set(name, value);
|
|
1778
|
+
}
|
|
1779
|
+
}
|
|
1780
|
+
const searchPieces = [];
|
|
1781
|
+
for (const [name, value] of combinedParams) {
|
|
1782
|
+
if (typeof value === "string") {
|
|
1783
|
+
searchPieces.push(`${name}=${value}`);
|
|
1784
|
+
}
|
|
1785
|
+
else if (Array.isArray(value)) {
|
|
1786
|
+
// QUIRK: If we get an array of values, include multiple key/value pairs
|
|
1787
|
+
for (const subValue of value) {
|
|
1788
|
+
searchPieces.push(`${name}=${subValue}`);
|
|
1789
|
+
}
|
|
1790
|
+
}
|
|
1791
|
+
else {
|
|
1792
|
+
searchPieces.push(`${name}=${value}`);
|
|
1793
|
+
}
|
|
1794
|
+
}
|
|
1795
|
+
// QUIRK: we have to set search manually as searchParams will encode comma when it shouldn't.
|
|
1796
|
+
parsedUrl.search = searchPieces.length ? `?${searchPieces.join("&")}` : "";
|
|
1797
|
+
return parsedUrl.toString();
|
|
1798
|
+
}
|
|
1799
|
+
|
|
1793
1800
|
// Copyright (c) Microsoft Corporation.
|
|
1794
1801
|
/**
|
|
1795
1802
|
* Initializes a new instance of the ServiceClient.
|
|
@@ -1801,11 +1808,22 @@ class ServiceClient {
|
|
|
1801
1808
|
* @param options - The service client options that govern the behavior of the client.
|
|
1802
1809
|
*/
|
|
1803
1810
|
constructor(options = {}) {
|
|
1811
|
+
var _a;
|
|
1804
1812
|
this._requestContentType = options.requestContentType;
|
|
1805
1813
|
this._baseUri = options.baseUri;
|
|
1806
1814
|
this._allowInsecureConnection = options.allowInsecureConnection;
|
|
1807
1815
|
this._httpClient = options.httpClient || getCachedDefaultHttpClient();
|
|
1808
1816
|
this.pipeline = options.pipeline || createDefaultPipeline(options);
|
|
1817
|
+
if ((_a = options.additionalPolicies) === null || _a === void 0 ? void 0 : _a.length) {
|
|
1818
|
+
for (const { policy, position } of options.additionalPolicies) {
|
|
1819
|
+
// Sign happens after Retry and is commonly needed to occur
|
|
1820
|
+
// before policies that intercept post-retry.
|
|
1821
|
+
const afterPhase = position === "perRetry" ? "Sign" : undefined;
|
|
1822
|
+
this.pipeline.addPolicy(policy, {
|
|
1823
|
+
afterPhase,
|
|
1824
|
+
});
|
|
1825
|
+
}
|
|
1826
|
+
}
|
|
1809
1827
|
}
|
|
1810
1828
|
/**
|
|
1811
1829
|
* Send the provided httpRequest.
|