@azure/core-client 1.4.1-alpha.20220120.2 → 1.4.1-alpha.20220131.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/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,322 +1123,82 @@ function getOperationRequestInfo(request) {
1160
1123
  return info;
1161
1124
  }
1162
1125
 
1163
- const CollectionFormatToDelimiterMap = {
1164
- CSV: ",",
1165
- SSV: " ",
1166
- Multi: "Multi",
1167
- TSV: "\t",
1168
- Pipes: "|",
1169
- };
1170
- function getRequestUrl(baseUri, operationSpec, operationArguments, fallbackObject) {
1171
- const urlReplacements = calculateUrlReplacements(operationSpec, operationArguments, fallbackObject);
1172
- let isAbsolutePath = false;
1173
- let requestUrl = replaceAll(baseUri, urlReplacements);
1174
- if (operationSpec.path) {
1175
- let path = replaceAll(operationSpec.path, urlReplacements);
1176
- // QUIRK: sometimes we get a path component like /{nextLink}
1177
- // which may be a fully formed URL with a leading /. In that case, we should
1178
- // remove the leading /
1179
- if (operationSpec.path === "/{nextLink}" && path.startsWith("/")) {
1180
- path = path.substring(1);
1181
- }
1182
- // QUIRK: sometimes we get a path component like {nextLink}
1183
- // which may be a fully formed URL. In that case, we should
1184
- // ignore the baseUri.
1185
- if (isAbsoluteUrl(path)) {
1186
- requestUrl = path;
1187
- isAbsolutePath = true;
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];
1188
1165
  }
1189
1166
  else {
1190
- requestUrl = appendPath(requestUrl, path);
1167
+ result = operationInfo === null || operationInfo === void 0 ? void 0 : operationInfo.operationResponseGetter(operationSpec, parsedResponse);
1191
1168
  }
1192
1169
  }
1193
- const { queryParams, sequenceParams } = calculateQueryParameters(operationSpec, operationArguments, fallbackObject);
1194
- /**
1195
- * Notice that this call sets the `noOverwrite` parameter to true if the `requestUrl`
1196
- * is an absolute path. This ensures that existing query parameter values in `requestUrl`
1197
- * do not get overwritten. On the other hand when `requestUrl` is not absolute path, it
1198
- * is still being built so there is nothing to overwrite.
1199
- */
1200
- requestUrl = appendQueryParams(requestUrl, queryParams, sequenceParams, isAbsolutePath);
1201
- return requestUrl;
1202
- }
1203
- function replaceAll(input, replacements) {
1204
- let result = input;
1205
- for (const [searchValue, replaceValue] of replacements) {
1206
- result = result.split(searchValue).join(replaceValue);
1207
- }
1208
1170
  return result;
1209
1171
  }
1210
- function calculateUrlReplacements(operationSpec, operationArguments, fallbackObject) {
1211
- var _a;
1212
- const result = new Map();
1213
- if ((_a = operationSpec.urlParameters) === null || _a === void 0 ? void 0 : _a.length) {
1214
- for (const urlParameter of operationSpec.urlParameters) {
1215
- let urlParameterValue = getOperationArgumentValueFromParameter(operationArguments, urlParameter, fallbackObject);
1216
- const parameterPathString = getPathStringFromParameter(urlParameter);
1217
- urlParameterValue = operationSpec.serializer.serialize(urlParameter.mapper, urlParameterValue, parameterPathString);
1218
- if (!urlParameter.skipEncoding) {
1219
- urlParameterValue = encodeURIComponent(urlParameterValue);
1220
- }
1221
- result.set(`{${urlParameter.mapper.serializedName || parameterPathString}}`, urlParameterValue);
1222
- }
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);
1223
1185
  }
1224
1186
  return result;
1225
1187
  }
1226
- function isAbsoluteUrl(url) {
1227
- return url.includes("://");
1228
- }
1229
- function appendPath(url, pathToAppend) {
1230
- if (!pathToAppend) {
1231
- return url;
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;
1232
1192
  }
1233
- const parsedUrl = new URL(url);
1234
- let newPath = parsedUrl.pathname;
1235
- if (!newPath.endsWith("/")) {
1236
- newPath = `${newPath}/`;
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;
1237
1197
  }
1238
- if (pathToAppend.startsWith("/")) {
1239
- pathToAppend = pathToAppend.substring(1);
1240
- }
1241
- const searchStart = pathToAppend.indexOf("?");
1242
- if (searchStart !== -1) {
1243
- const path = pathToAppend.substring(0, searchStart);
1244
- const search = pathToAppend.substring(searchStart + 1);
1245
- newPath = newPath + path;
1246
- if (search) {
1247
- parsedUrl.search = parsedUrl.search ? `${parsedUrl.search}&${search}` : search;
1248
- }
1249
- }
1250
- else {
1251
- newPath = newPath + pathToAppend;
1252
- }
1253
- parsedUrl.pathname = newPath;
1254
- return parsedUrl.toString();
1255
- }
1256
- function calculateQueryParameters(operationSpec, operationArguments, fallbackObject) {
1257
- var _a;
1258
- const result = new Map();
1259
- const sequenceParams = new Set();
1260
- if ((_a = operationSpec.queryParameters) === null || _a === void 0 ? void 0 : _a.length) {
1261
- for (const queryParameter of operationSpec.queryParameters) {
1262
- if (queryParameter.mapper.type.name === "Sequence" && queryParameter.mapper.serializedName) {
1263
- sequenceParams.add(queryParameter.mapper.serializedName);
1264
- }
1265
- let queryParameterValue = getOperationArgumentValueFromParameter(operationArguments, queryParameter, fallbackObject);
1266
- if ((queryParameterValue !== undefined && queryParameterValue !== null) ||
1267
- queryParameter.mapper.required) {
1268
- queryParameterValue = operationSpec.serializer.serialize(queryParameter.mapper, queryParameterValue, getPathStringFromParameter(queryParameter));
1269
- const delimiter = queryParameter.collectionFormat
1270
- ? CollectionFormatToDelimiterMap[queryParameter.collectionFormat]
1271
- : "";
1272
- if (Array.isArray(queryParameterValue)) {
1273
- // replace null and undefined
1274
- queryParameterValue = queryParameterValue.map((item) => {
1275
- if (item === null || item === undefined) {
1276
- return "";
1277
- }
1278
- return item;
1279
- });
1280
- }
1281
- if (queryParameter.collectionFormat === "Multi" && queryParameterValue.length === 0) {
1282
- continue;
1283
- }
1284
- else if (Array.isArray(queryParameterValue) &&
1285
- (queryParameter.collectionFormat === "SSV" || queryParameter.collectionFormat === "TSV")) {
1286
- queryParameterValue = queryParameterValue.join(delimiter);
1287
- }
1288
- if (!queryParameter.skipEncoding) {
1289
- if (Array.isArray(queryParameterValue)) {
1290
- queryParameterValue = queryParameterValue.map((item) => {
1291
- return encodeURIComponent(item);
1292
- });
1293
- }
1294
- else {
1295
- queryParameterValue = encodeURIComponent(queryParameterValue);
1296
- }
1297
- }
1298
- // Join pipes and CSV *after* encoding, or the server will be upset.
1299
- if (Array.isArray(queryParameterValue) &&
1300
- (queryParameter.collectionFormat === "CSV" || queryParameter.collectionFormat === "Pipes")) {
1301
- queryParameterValue = queryParameterValue.join(delimiter);
1302
- }
1303
- result.set(queryParameter.mapper.serializedName || getPathStringFromParameter(queryParameter), queryParameterValue);
1304
- }
1305
- }
1306
- }
1307
- return {
1308
- queryParams: result,
1309
- sequenceParams,
1310
- };
1311
- }
1312
- function simpleParseQueryParams(queryString) {
1313
- const result = new Map();
1314
- if (!queryString || queryString[0] !== "?") {
1315
- return result;
1316
- }
1317
- // remove the leading ?
1318
- queryString = queryString.slice(1);
1319
- const pairs = queryString.split("&");
1320
- for (const pair of pairs) {
1321
- const [name, value] = pair.split("=", 2);
1322
- const existingValue = result.get(name);
1323
- if (existingValue) {
1324
- if (Array.isArray(existingValue)) {
1325
- existingValue.push(value);
1326
- }
1327
- else {
1328
- result.set(name, [existingValue, value]);
1329
- }
1330
- }
1331
- else {
1332
- result.set(name, value);
1333
- }
1334
- }
1335
- return result;
1336
- }
1337
- /** @internal */
1338
- function appendQueryParams(url, queryParams, sequenceParams, noOverwrite = false) {
1339
- if (queryParams.size === 0) {
1340
- return url;
1341
- }
1342
- const parsedUrl = new URL(url);
1343
- // QUIRK: parsedUrl.searchParams will have their name/value pairs decoded, which
1344
- // can change their meaning to the server, such as in the case of a SAS signature.
1345
- // To avoid accidentally un-encoding a query param, we parse the key/values ourselves
1346
- const combinedParams = simpleParseQueryParams(parsedUrl.search);
1347
- for (const [name, value] of queryParams) {
1348
- const existingValue = combinedParams.get(name);
1349
- if (Array.isArray(existingValue)) {
1350
- if (Array.isArray(value)) {
1351
- existingValue.push(...value);
1352
- const valueSet = new Set(existingValue);
1353
- combinedParams.set(name, Array.from(valueSet));
1354
- }
1355
- else {
1356
- existingValue.push(value);
1357
- }
1358
- }
1359
- else if (existingValue) {
1360
- if (Array.isArray(value)) {
1361
- value.unshift(existingValue);
1362
- }
1363
- else if (sequenceParams.has(name)) {
1364
- combinedParams.set(name, [existingValue, value]);
1365
- }
1366
- if (!noOverwrite) {
1367
- combinedParams.set(name, value);
1368
- }
1369
- }
1370
- else {
1371
- combinedParams.set(name, value);
1372
- }
1373
- }
1374
- const searchPieces = [];
1375
- for (const [name, value] of combinedParams) {
1376
- if (typeof value === "string") {
1377
- searchPieces.push(`${name}=${value}`);
1378
- }
1379
- else if (Array.isArray(value)) {
1380
- // QUIRK: If we get an array of values, include multiple key/value pairs
1381
- for (const subValue of value) {
1382
- searchPieces.push(`${name}=${subValue}`);
1383
- }
1384
- }
1385
- else {
1386
- searchPieces.push(`${name}=${value}`);
1387
- }
1388
- }
1389
- // QUIRK: we have to set search manually as searchParams will encode comma when it shouldn't.
1390
- parsedUrl.search = searchPieces.length ? `?${searchPieces.join("&")}` : "";
1391
- return parsedUrl.toString();
1392
- }
1393
-
1394
- // Copyright (c) Microsoft Corporation.
1395
- let cachedHttpClient;
1396
- function getCachedDefaultHttpClient() {
1397
- if (!cachedHttpClient) {
1398
- cachedHttpClient = coreRestPipeline.createDefaultHttpClient();
1399
- }
1400
- return cachedHttpClient;
1401
- }
1402
-
1403
- // Copyright (c) Microsoft Corporation.
1404
- const defaultJsonContentTypes = ["application/json", "text/json"];
1405
- const defaultXmlContentTypes = ["application/xml", "application/atom+xml"];
1406
- /**
1407
- * The programmatic identifier of the deserializationPolicy.
1408
- */
1409
- const deserializationPolicyName = "deserializationPolicy";
1410
- /**
1411
- * This policy handles parsing out responses according to OperationSpecs on the request.
1412
- */
1413
- function deserializationPolicy(options = {}) {
1414
- var _a, _b, _c, _d, _e, _f, _g;
1415
- const jsonContentTypes = (_b = (_a = options.expectedContentTypes) === null || _a === void 0 ? void 0 : _a.json) !== null && _b !== void 0 ? _b : defaultJsonContentTypes;
1416
- const xmlContentTypes = (_d = (_c = options.expectedContentTypes) === null || _c === void 0 ? void 0 : _c.xml) !== null && _d !== void 0 ? _d : defaultXmlContentTypes;
1417
- const parseXML = options.parseXML;
1418
- const serializerOptions = options.serializerOptions;
1419
- const updatedOptions = {
1420
- xml: {
1421
- rootName: (_e = serializerOptions === null || serializerOptions === void 0 ? void 0 : serializerOptions.xml.rootName) !== null && _e !== void 0 ? _e : "",
1422
- includeRoot: (_f = serializerOptions === null || serializerOptions === void 0 ? void 0 : serializerOptions.xml.includeRoot) !== null && _f !== void 0 ? _f : false,
1423
- xmlCharKey: (_g = serializerOptions === null || serializerOptions === void 0 ? void 0 : serializerOptions.xml.xmlCharKey) !== null && _g !== void 0 ? _g : XML_CHARKEY,
1424
- },
1425
- };
1426
- return {
1427
- name: deserializationPolicyName,
1428
- async sendRequest(request, next) {
1429
- const response = await next(request);
1430
- return deserializeResponseBody(jsonContentTypes, xmlContentTypes, response, updatedOptions, parseXML);
1431
- },
1432
- };
1433
- }
1434
- function getOperationResponseMap(parsedResponse) {
1435
- let result;
1436
- const request = parsedResponse.request;
1437
- const operationInfo = getOperationRequestInfo(request);
1438
- const operationSpec = operationInfo === null || operationInfo === void 0 ? void 0 : operationInfo.operationSpec;
1439
- if (operationSpec) {
1440
- if (!(operationInfo === null || operationInfo === void 0 ? void 0 : operationInfo.operationResponseGetter)) {
1441
- result = operationSpec.responses[parsedResponse.status];
1442
- }
1443
- else {
1444
- result = operationInfo === null || operationInfo === void 0 ? void 0 : operationInfo.operationResponseGetter(operationSpec, parsedResponse);
1445
- }
1446
- }
1447
- return result;
1448
- }
1449
- function shouldDeserializeResponse(parsedResponse) {
1450
- const request = parsedResponse.request;
1451
- const operationInfo = getOperationRequestInfo(request);
1452
- const shouldDeserialize = operationInfo === null || operationInfo === void 0 ? void 0 : operationInfo.shouldDeserialize;
1453
- let result;
1454
- if (shouldDeserialize === undefined) {
1455
- result = true;
1456
- }
1457
- else if (typeof shouldDeserialize === "boolean") {
1458
- result = shouldDeserialize;
1459
- }
1460
- else {
1461
- result = shouldDeserialize(parsedResponse);
1462
- }
1463
- return result;
1464
- }
1465
- async function deserializeResponseBody(jsonContentTypes, xmlContentTypes, response, options, parseXML) {
1466
- const parsedResponse = await parse(jsonContentTypes, xmlContentTypes, response, options, parseXML);
1467
- if (!shouldDeserializeResponse(parsedResponse)) {
1468
- return parsedResponse;
1469
- }
1470
- const operationInfo = getOperationRequestInfo(parsedResponse.request);
1471
- const operationSpec = operationInfo === null || operationInfo === void 0 ? void 0 : operationInfo.operationSpec;
1472
- if (!operationSpec || !operationSpec.responses) {
1473
- return parsedResponse;
1474
- }
1475
- const responseSpec = getOperationResponseMap(parsedResponse);
1476
- const { error, shouldReturnResponse } = handleErrorResponse(parsedResponse, operationSpec, responseSpec);
1477
- if (error) {
1478
- throw error;
1198
+ const responseSpec = getOperationResponseMap(parsedResponse);
1199
+ const { error, shouldReturnResponse } = handleErrorResponse(parsedResponse, operationSpec, responseSpec);
1200
+ if (error) {
1201
+ throw error;
1479
1202
  }
1480
1203
  else if (shouldReturnResponse) {
1481
1204
  return parsedResponse;
@@ -1626,6 +1349,43 @@ async function parse(jsonContentTypes, xmlContentTypes, operationResponse, opts,
1626
1349
  return operationResponse;
1627
1350
  }
1628
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
+
1629
1389
  // Copyright (c) Microsoft Corporation.
1630
1390
  /**
1631
1391
  * The programmatic identifier of the serializationPolicy.
@@ -1796,6 +1556,247 @@ function createClientPipeline(options = {}) {
1796
1556
  return pipeline;
1797
1557
  }
1798
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
+
1799
1800
  // Copyright (c) Microsoft Corporation.
1800
1801
  /**
1801
1802
  * Initializes a new instance of the ServiceClient.