@azure/core-client 1.4.0-alpha.20211123.3 → 1.4.0-alpha.20220106.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.
@@ -1 +1 @@
1
- {"version":3,"file":"urlHelpers.js","sourceRoot":"","sources":["../../src/urlHelpers.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,sCAAsC,EAAE,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EAAE,0BAA0B,EAAE,MAAM,oBAAoB,CAAC;AAEhE,MAAM,8BAA8B,GAA+C;IACjF,GAAG,EAAE,GAAG;IACR,GAAG,EAAE,GAAG;IACR,KAAK,EAAE,OAAO;IACd,GAAG,EAAE,IAAI;IACT,KAAK,EAAE,GAAG;CACX,CAAC;AAEF,MAAM,UAAU,aAAa,CAC3B,OAAe,EACf,aAA4B,EAC5B,kBAAsC,EACtC,cAAgD;IAEhD,MAAM,eAAe,GAAG,wBAAwB,CAC9C,aAAa,EACb,kBAAkB,EAClB,cAAc,CACf,CAAC;IAEF,IAAI,cAAc,GAAG,KAAK,CAAC;IAE3B,IAAI,UAAU,GAAG,UAAU,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;IACtD,IAAI,aAAa,CAAC,IAAI,EAAE;QACtB,MAAM,IAAI,GAAG,UAAU,CAAC,aAAa,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC;QAC7D,2DAA2D;QAC3D,2DAA2D;QAC3D,sBAAsB;QACtB,IAAI,aAAa,CAAC,IAAI,CAAC,EAAE;YACvB,UAAU,GAAG,IAAI,CAAC;YAClB,cAAc,GAAG,IAAI,CAAC;SACvB;aAAM;YACL,UAAU,GAAG,UAAU,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;SAC3C;KACF;IAED,MAAM,EAAE,WAAW,EAAE,cAAc,EAAE,GAAG,wBAAwB,CAC9D,aAAa,EACb,kBAAkB,EAClB,cAAc,CACf,CAAC;IACF;;;;;OAKG;IACH,UAAU,GAAG,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M,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IAC3E,OAAO,SAAS,CAAC,QAAQ,EAAE,CAAC;AAC9B,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\nimport { OperationSpec, OperationArguments, QueryCollectionFormat } from \"./interfaces\";\nimport { getOperationArgumentValueFromParameter } from \"./operationHelpers\";\nimport { getPathStringFromParameter } from \"./interfaceHelpers\";\n\nconst CollectionFormatToDelimiterMap: { [key in QueryCollectionFormat]: string } = {\n CSV: \",\",\n SSV: \" \",\n Multi: \"Multi\",\n TSV: \"\\t\",\n Pipes: \"|\"\n};\n\nexport function getRequestUrl(\n baseUri: string,\n operationSpec: OperationSpec,\n operationArguments: OperationArguments,\n fallbackObject: { [parameterName: string]: any }\n): string {\n const urlReplacements = calculateUrlReplacements(\n operationSpec,\n operationArguments,\n fallbackObject\n );\n\n let isAbsolutePath = false;\n\n let requestUrl = replaceAll(baseUri, urlReplacements);\n if (operationSpec.path) {\n const path = replaceAll(operationSpec.path, urlReplacements);\n // QUIRK: sometimes we get a path component like {nextLink}\n // which may be a fully formed URL. In that case, we should\n // ignore the baseUri.\n if (isAbsoluteUrl(path)) {\n requestUrl = path;\n isAbsolutePath = true;\n } else {\n requestUrl = appendPath(requestUrl, path);\n }\n }\n\n const { queryParams, sequenceParams } = calculateQueryParameters(\n operationSpec,\n operationArguments,\n fallbackObject\n );\n /**\n * Notice that this call sets the `noOverwrite` parameter to true if the `requestUrl`\n * is an absolute path. This ensures that existing query parameter values in `requestUrl`\n * do not get overwritten. On the other hand when `requestUrl` is not absolute path, it\n * is still being built so there is nothing to overwrite.\n */\n requestUrl = appendQueryParams(requestUrl, queryParams, sequenceParams, isAbsolutePath);\n\n return requestUrl;\n}\n\nfunction replaceAll(input: string, replacements: Map<string, string>): string {\n let result = input;\n for (const [searchValue, replaceValue] of replacements) {\n result = result.split(searchValue).join(replaceValue);\n }\n return result;\n}\n\nfunction calculateUrlReplacements(\n operationSpec: OperationSpec,\n operationArguments: OperationArguments,\n fallbackObject: { [parameterName: string]: any }\n): Map<string, string> {\n const result = new Map<string, string>();\n if (operationSpec.urlParameters?.length) {\n for (const urlParameter of operationSpec.urlParameters) {\n let urlParameterValue: string = getOperationArgumentValueFromParameter(\n operationArguments,\n urlParameter,\n fallbackObject\n );\n const parameterPathString = getPathStringFromParameter(urlParameter);\n urlParameterValue = operationSpec.serializer.serialize(\n urlParameter.mapper,\n urlParameterValue,\n parameterPathString\n );\n if (!urlParameter.skipEncoding) {\n urlParameterValue = encodeURIComponent(urlParameterValue);\n }\n result.set(\n `{${urlParameter.mapper.serializedName || parameterPathString}}`,\n urlParameterValue\n );\n }\n }\n return result;\n}\n\nfunction isAbsoluteUrl(url: string): boolean {\n return url.includes(\"://\");\n}\n\nfunction appendPath(url: string, pathToAppend?: string): string {\n if (!pathToAppend) {\n return url;\n }\n\n const parsedUrl = new URL(url);\n let newPath = parsedUrl.pathname;\n\n if (!newPath.endsWith(\"/\")) {\n newPath = `${newPath}/`;\n }\n\n if (pathToAppend.startsWith(\"/\")) {\n pathToAppend = pathToAppend.substring(1);\n }\n\n const searchStart = pathToAppend.indexOf(\"?\");\n if (searchStart !== -1) {\n const path = pathToAppend.substring(0, searchStart);\n const search = pathToAppend.substring(searchStart + 1);\n newPath = newPath + path;\n if (search) {\n parsedUrl.search = parsedUrl.search ? `${parsedUrl.search}&${search}` : search;\n }\n } else {\n newPath = newPath + pathToAppend;\n }\n\n parsedUrl.pathname = newPath;\n\n return parsedUrl.toString();\n}\n\nfunction calculateQueryParameters(\n operationSpec: OperationSpec,\n operationArguments: OperationArguments,\n fallbackObject: { [parameterName: string]: any }\n): {\n queryParams: Map<string, string | string[]>;\n sequenceParams: Set<string>;\n} {\n const result = new Map<string, string | string[]>();\n const sequenceParams: Set<string> = new Set<string>();\n\n if (operationSpec.queryParameters?.length) {\n for (const queryParameter of operationSpec.queryParameters) {\n if (queryParameter.mapper.type.name === \"Sequence\" && queryParameter.mapper.serializedName) {\n sequenceParams.add(queryParameter.mapper.serializedName);\n }\n let queryParameterValue: string | string[] = getOperationArgumentValueFromParameter(\n operationArguments,\n queryParameter,\n fallbackObject\n );\n if (\n (queryParameterValue !== undefined && queryParameterValue !== null) ||\n queryParameter.mapper.required\n ) {\n queryParameterValue = operationSpec.serializer.serialize(\n queryParameter.mapper,\n queryParameterValue,\n getPathStringFromParameter(queryParameter)\n );\n\n const delimiter = queryParameter.collectionFormat\n ? CollectionFormatToDelimiterMap[queryParameter.collectionFormat]\n : \"\";\n if (Array.isArray(queryParameterValue)) {\n // replace null and undefined\n queryParameterValue = queryParameterValue.map((item) => {\n if (item === null || item === undefined) {\n return \"\";\n }\n\n return item;\n });\n }\n if (queryParameter.collectionFormat === \"Multi\" && queryParameterValue.length === 0) {\n continue;\n } else if (\n Array.isArray(queryParameterValue) &&\n (queryParameter.collectionFormat === \"SSV\" || queryParameter.collectionFormat === \"TSV\")\n ) {\n queryParameterValue = queryParameterValue.join(delimiter);\n }\n if (!queryParameter.skipEncoding) {\n if (Array.isArray(queryParameterValue)) {\n queryParameterValue = queryParameterValue.map((item: string) => {\n return encodeURIComponent(item);\n });\n } else {\n queryParameterValue = encodeURIComponent(queryParameterValue);\n }\n }\n\n // Join pipes and CSV *after* encoding, or the server will be upset.\n if (\n Array.isArray(queryParameterValue) &&\n (queryParameter.collectionFormat === \"CSV\" || queryParameter.collectionFormat === \"Pipes\")\n ) {\n queryParameterValue = queryParameterValue.join(delimiter);\n }\n\n result.set(\n queryParameter.mapper.serializedName || getPathStringFromParameter(queryParameter),\n queryParameterValue\n );\n }\n }\n }\n return {\n queryParams: result,\n sequenceParams\n };\n}\n\nfunction simpleParseQueryParams(queryString: string): Map<string, string | string[] | undefined> {\n const result: Map<string, string | string[] | undefined> = new Map<\n string,\n string | string[] | undefined\n >();\n if (!queryString || queryString[0] !== \"?\") {\n return result;\n }\n\n // remove the leading ?\n queryString = queryString.slice(1);\n const pairs = queryString.split(\"&\");\n\n for (const pair of pairs) {\n const [name, value] = pair.split(\"=\", 2);\n const existingValue = result.get(name);\n if (existingValue) {\n if (Array.isArray(existingValue)) {\n existingValue.push(value);\n } else {\n result.set(name, [existingValue, value]);\n }\n } else {\n result.set(name, value);\n }\n }\n\n return result;\n}\n\n/** @internal */\nexport function appendQueryParams(\n url: string,\n queryParams: Map<string, string | string[]>,\n sequenceParams: Set<string>,\n noOverwrite: boolean = false\n): string {\n if (queryParams.size === 0) {\n return url;\n }\n\n const parsedUrl = new URL(url);\n\n // QUIRK: parsedUrl.searchParams will have their name/value pairs decoded, which\n // can change their meaning to the server, such as in the case of a SAS signature.\n // To avoid accidentally un-encoding a query param, we parse the key/values ourselves\n const combinedParams = simpleParseQueryParams(parsedUrl.search);\n\n for (const [name, value] of queryParams) {\n const existingValue = combinedParams.get(name);\n if (Array.isArray(existingValue)) {\n if (Array.isArray(value)) {\n existingValue.push(...value);\n const valueSet = new Set(existingValue);\n combinedParams.set(name, Array.from(valueSet));\n } else {\n existingValue.push(value);\n }\n } else if (existingValue) {\n if (Array.isArray(value)) {\n value.unshift(existingValue);\n } else if (sequenceParams.has(name)) {\n combinedParams.set(name, [existingValue, value]);\n }\n if (!noOverwrite) {\n combinedParams.set(name, value);\n }\n } else {\n combinedParams.set(name, value);\n }\n }\n\n const searchPieces: string[] = [];\n for (const [name, value] of combinedParams) {\n if (typeof value === \"string\") {\n searchPieces.push(`${name}=${value}`);\n } else if (Array.isArray(value)) {\n // QUIRK: If we get an array of values, include multiple key/value pairs\n for (const subValue of value) {\n searchPieces.push(`${name}=${subValue}`);\n }\n } else {\n searchPieces.push(`${name}=${value}`);\n }\n }\n\n // QUIRK: we have to set search manually as searchParams will encode comma when it shouldn't.\n parsedUrl.search = searchPieces.length ? `?${searchPieces.join(\"&\")}` : \"\";\n return parsedUrl.toString();\n}\n"]}
1
+ {"version":3,"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,CAAC;AAC9B,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\nimport { OperationSpec, OperationArguments, QueryCollectionFormat } from \"./interfaces\";\nimport { getOperationArgumentValueFromParameter } from \"./operationHelpers\";\nimport { getPathStringFromParameter } from \"./interfaceHelpers\";\n\nconst CollectionFormatToDelimiterMap: { [key in QueryCollectionFormat]: string } = {\n CSV: \",\",\n SSV: \" \",\n Multi: \"Multi\",\n TSV: \"\\t\",\n Pipes: \"|\",\n};\n\nexport function getRequestUrl(\n baseUri: string,\n operationSpec: OperationSpec,\n operationArguments: OperationArguments,\n fallbackObject: { [parameterName: string]: any }\n): string {\n const urlReplacements = calculateUrlReplacements(\n operationSpec,\n operationArguments,\n fallbackObject\n );\n\n let isAbsolutePath = false;\n\n let requestUrl = replaceAll(baseUri, urlReplacements);\n if (operationSpec.path) {\n const path = replaceAll(operationSpec.path, urlReplacements);\n // QUIRK: sometimes we get a path component like {nextLink}\n // which may be a fully formed URL. In that case, we should\n // ignore the baseUri.\n if (isAbsoluteUrl(path)) {\n requestUrl = path;\n isAbsolutePath = true;\n } else {\n requestUrl = appendPath(requestUrl, path);\n }\n }\n\n const { queryParams, sequenceParams } = calculateQueryParameters(\n operationSpec,\n operationArguments,\n fallbackObject\n );\n /**\n * Notice that this call sets the `noOverwrite` parameter to true if the `requestUrl`\n * is an absolute path. This ensures that existing query parameter values in `requestUrl`\n * do not get overwritten. On the other hand when `requestUrl` is not absolute path, it\n * is still being built so there is nothing to overwrite.\n */\n requestUrl = appendQueryParams(requestUrl, queryParams, sequenceParams, isAbsolutePath);\n\n return requestUrl;\n}\n\nfunction replaceAll(input: string, replacements: Map<string, string>): string {\n let result = input;\n for (const [searchValue, replaceValue] of replacements) {\n result = result.split(searchValue).join(replaceValue);\n }\n return result;\n}\n\nfunction calculateUrlReplacements(\n operationSpec: OperationSpec,\n operationArguments: OperationArguments,\n fallbackObject: { [parameterName: string]: any }\n): Map<string, string> {\n const result = new Map<string, string>();\n if (operationSpec.urlParameters?.length) {\n for (const urlParameter of operationSpec.urlParameters) {\n let urlParameterValue: string = getOperationArgumentValueFromParameter(\n operationArguments,\n urlParameter,\n fallbackObject\n );\n const parameterPathString = getPathStringFromParameter(urlParameter);\n urlParameterValue = operationSpec.serializer.serialize(\n urlParameter.mapper,\n urlParameterValue,\n parameterPathString\n );\n if (!urlParameter.skipEncoding) {\n urlParameterValue = encodeURIComponent(urlParameterValue);\n }\n result.set(\n `{${urlParameter.mapper.serializedName || parameterPathString}}`,\n urlParameterValue\n );\n }\n }\n return result;\n}\n\nfunction isAbsoluteUrl(url: string): boolean {\n return url.includes(\"://\");\n}\n\nfunction appendPath(url: string, pathToAppend?: string): string {\n if (!pathToAppend) {\n return url;\n }\n\n const parsedUrl = new URL(url);\n let newPath = parsedUrl.pathname;\n\n if (!newPath.endsWith(\"/\")) {\n newPath = `${newPath}/`;\n }\n\n if (pathToAppend.startsWith(\"/\")) {\n pathToAppend = pathToAppend.substring(1);\n }\n\n const searchStart = pathToAppend.indexOf(\"?\");\n if (searchStart !== -1) {\n const path = pathToAppend.substring(0, searchStart);\n const search = pathToAppend.substring(searchStart + 1);\n newPath = newPath + path;\n if (search) {\n parsedUrl.search = parsedUrl.search ? `${parsedUrl.search}&${search}` : search;\n }\n } else {\n newPath = newPath + pathToAppend;\n }\n\n parsedUrl.pathname = newPath;\n\n return parsedUrl.toString();\n}\n\nfunction calculateQueryParameters(\n operationSpec: OperationSpec,\n operationArguments: OperationArguments,\n fallbackObject: { [parameterName: string]: any }\n): {\n queryParams: Map<string, string | string[]>;\n sequenceParams: Set<string>;\n} {\n const result = new Map<string, string | string[]>();\n const sequenceParams: Set<string> = new Set<string>();\n\n if (operationSpec.queryParameters?.length) {\n for (const queryParameter of operationSpec.queryParameters) {\n if (queryParameter.mapper.type.name === \"Sequence\" && queryParameter.mapper.serializedName) {\n sequenceParams.add(queryParameter.mapper.serializedName);\n }\n let queryParameterValue: string | string[] = getOperationArgumentValueFromParameter(\n operationArguments,\n queryParameter,\n fallbackObject\n );\n if (\n (queryParameterValue !== undefined && queryParameterValue !== null) ||\n queryParameter.mapper.required\n ) {\n queryParameterValue = operationSpec.serializer.serialize(\n queryParameter.mapper,\n queryParameterValue,\n getPathStringFromParameter(queryParameter)\n );\n\n const delimiter = queryParameter.collectionFormat\n ? CollectionFormatToDelimiterMap[queryParameter.collectionFormat]\n : \"\";\n if (Array.isArray(queryParameterValue)) {\n // replace null and undefined\n queryParameterValue = queryParameterValue.map((item) => {\n if (item === null || item === undefined) {\n return \"\";\n }\n\n return item;\n });\n }\n if (queryParameter.collectionFormat === \"Multi\" && queryParameterValue.length === 0) {\n continue;\n } else if (\n Array.isArray(queryParameterValue) &&\n (queryParameter.collectionFormat === \"SSV\" || queryParameter.collectionFormat === \"TSV\")\n ) {\n queryParameterValue = queryParameterValue.join(delimiter);\n }\n if (!queryParameter.skipEncoding) {\n if (Array.isArray(queryParameterValue)) {\n queryParameterValue = queryParameterValue.map((item: string) => {\n return encodeURIComponent(item);\n });\n } else {\n queryParameterValue = encodeURIComponent(queryParameterValue);\n }\n }\n\n // Join pipes and CSV *after* encoding, or the server will be upset.\n if (\n Array.isArray(queryParameterValue) &&\n (queryParameter.collectionFormat === \"CSV\" || queryParameter.collectionFormat === \"Pipes\")\n ) {\n queryParameterValue = queryParameterValue.join(delimiter);\n }\n\n result.set(\n queryParameter.mapper.serializedName || getPathStringFromParameter(queryParameter),\n queryParameterValue\n );\n }\n }\n }\n return {\n queryParams: result,\n sequenceParams,\n };\n}\n\nfunction simpleParseQueryParams(queryString: string): Map<string, string | string[] | undefined> {\n const result: Map<string, string | string[] | undefined> = new Map<\n string,\n string | string[] | undefined\n >();\n if (!queryString || queryString[0] !== \"?\") {\n return result;\n }\n\n // remove the leading ?\n queryString = queryString.slice(1);\n const pairs = queryString.split(\"&\");\n\n for (const pair of pairs) {\n const [name, value] = pair.split(\"=\", 2);\n const existingValue = result.get(name);\n if (existingValue) {\n if (Array.isArray(existingValue)) {\n existingValue.push(value);\n } else {\n result.set(name, [existingValue, value]);\n }\n } else {\n result.set(name, value);\n }\n }\n\n return result;\n}\n\n/** @internal */\nexport function appendQueryParams(\n url: string,\n queryParams: Map<string, string | string[]>,\n sequenceParams: Set<string>,\n noOverwrite: boolean = false\n): string {\n if (queryParams.size === 0) {\n return url;\n }\n\n const parsedUrl = new URL(url);\n\n // QUIRK: parsedUrl.searchParams will have their name/value pairs decoded, which\n // can change their meaning to the server, such as in the case of a SAS signature.\n // To avoid accidentally un-encoding a query param, we parse the key/values ourselves\n const combinedParams = simpleParseQueryParams(parsedUrl.search);\n\n for (const [name, value] of queryParams) {\n const existingValue = combinedParams.get(name);\n if (Array.isArray(existingValue)) {\n if (Array.isArray(value)) {\n existingValue.push(...value);\n const valueSet = new Set(existingValue);\n combinedParams.set(name, Array.from(valueSet));\n } else {\n existingValue.push(value);\n }\n } else if (existingValue) {\n if (Array.isArray(value)) {\n value.unshift(existingValue);\n } else if (sequenceParams.has(name)) {\n combinedParams.set(name, [existingValue, value]);\n }\n if (!noOverwrite) {\n combinedParams.set(name, value);\n }\n } else {\n combinedParams.set(name, value);\n }\n }\n\n const searchPieces: string[] = [];\n for (const [name, value] of combinedParams) {\n if (typeof value === \"string\") {\n searchPieces.push(`${name}=${value}`);\n } else if (Array.isArray(value)) {\n // QUIRK: If we get an array of values, include multiple key/value pairs\n for (const subValue of value) {\n searchPieces.push(`${name}=${subValue}`);\n }\n } else {\n searchPieces.push(`${name}=${value}`);\n }\n }\n\n // QUIRK: we have to set search manually as searchParams will encode comma when it shouldn't.\n parsedUrl.search = searchPieces.length ? `?${searchPieces.join(\"&\")}` : \"\";\n return parsedUrl.toString();\n}\n"]}
@@ -109,7 +109,7 @@ export function flattenResponse(fullResponse, responseSpec) {
109
109
  body: fullResponse.parsedBody,
110
110
  headers: parsedHeaders,
111
111
  hasNullableType: isNullable,
112
- shouldWrapBody: isPrimitiveBody(fullResponse.parsedBody, expectedBodyTypeName)
112
+ shouldWrapBody: isPrimitiveBody(fullResponse.parsedBody, expectedBodyTypeName),
113
113
  });
114
114
  }
115
115
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAUlC;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,KAAc,EAAE,cAAuB;IACrE,OAAO,CACL,cAAc,KAAK,WAAW;QAC9B,cAAc,KAAK,YAAY;QAC/B,CAAC,OAAO,KAAK,KAAK,QAAQ;YACxB,OAAO,KAAK,KAAK,QAAQ;YACzB,OAAO,KAAK,KAAK,SAAS;YAC1B,CAAA,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,KAAK,CAAC,iEAAiE,CAAC;gBACtF,IAAI;YACN,KAAK,KAAK,SAAS;YACnB,KAAK,KAAK,IAAI,CAAC,CAClB,CAAC;AACJ,CAAC;AAED,MAAM,mBAAmB,GAAG,qKAAqK,CAAC;AAElM;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,KAAa;IACtC,OAAO,mBAAmB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AACzC,CAAC;AAED,MAAM,cAAc,GAAG,gFAAgF,CAAC;AAExG;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,OAAO,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACnC,CAAC;AAwBD;;;;;;;;;;GAUG;AACH,SAAS,sCAAsC,CAC7C,cAA0C;IAE1C,MAAM,sBAAsB,mCACvB,cAAc,CAAC,OAAO,GACtB,cAAc,CAAC,IAAI,CACvB,CAAC;IACF,IACE,cAAc,CAAC,eAAe;QAC9B,MAAM,CAAC,mBAAmB,CAAC,sBAAsB,CAAC,CAAC,MAAM,KAAK,CAAC,EAC/D;QACA,OAAO,cAAc,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,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M,aAAa,GACjB,MAAA,YAAY,CAAC,UAAU,mCAAM,EAA6C,CAAC;QAE7E,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,EAAE;YAC9C,IAAI,eAAe,CAAC,GAAG,CAAC,CAAC,cAAc,EAAE;gBACvC,aAAa,CAAC,GAAG,CAAC,GAAG,MAAA,YAAY,CAAC,UAAU,0CAAG,GAAG,CAAC,CAAC;aACrD;SACF;QAED,IAAI,aAAa,EAAE;YACjB,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,EAAE;gBAC5C,aAAa,CAAC,GAAG,CAAC,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;aACzC;SACF;QACD,OAAO,UAAU;YACf,CAAC,YAAY,CAAC,UAAU;YACxB,CAAC,aAAa;YACd,MAAM,CAAC,mBAAmB,CAAC,eAAe,CAAC,CAAC,MAAM,KAAK,CAAC;YACxD,CAAC,CAAC,IAAI;YACN,CAAC,CAAC,aAAa,CAAC;KACnB;IAED,OAAO,sCAAsC,CAAC;QAC5C,IAAI,EAAE,YAAY,CAAC,UAAU;QAC7B,OAAO,EAAE,aAAa;QACtB,eAAe,EAAE,UAAU;QAC3B,cAAc,EAAE,eAAe,CAAC,YAAY,CAAC,UAAU,EAAE,oBAAoB,CAAC;KAC/E,CAAC,CAAC;AACL,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { CompositeMapper, FullOperationResponse, OperationResponseMap } from \"./interfaces\";\n\n/**\n * The union of all possible types for a primitive response body.\n * @internal\n */\nexport type BodyPrimitive = number | string | boolean | Date | Uint8Array | undefined | null;\n\n/**\n * A type guard for a primitive response body.\n * @param value - Value to test\n *\n * @internal\n */\nexport function isPrimitiveBody(value: unknown, mapperTypeName?: string): value is BodyPrimitive {\n return (\n mapperTypeName !== \"Composite\" &&\n mapperTypeName !== \"Dictionary\" &&\n (typeof value === \"string\" ||\n typeof value === \"number\" ||\n typeof value === \"boolean\" ||\n mapperTypeName?.match(/^(Date|DateTime|DateTimeRfc1123|UnixTime|ByteArray|Base64Url)$/i) !==\n null ||\n value === undefined ||\n value === null)\n );\n}\n\nconst validateISODuration = /^(-|\\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/;\n\n/**\n * Returns true if the given string is in ISO 8601 format.\n * @param value - The value to be validated for ISO 8601 duration format.\n * @internal\n */\nexport function isDuration(value: string): boolean {\n return validateISODuration.test(value);\n}\n\nconst validUuidRegex = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/i;\n\n/**\n * Returns true if the provided uuid is valid.\n *\n * @param uuid - The uuid that needs to be validated.\n *\n * @internal\n */\nexport function isValidUuid(uuid: string): boolean {\n return validUuidRegex.test(uuid);\n}\n\n/**\n * Representation of parsed response headers and body coupled with information\n * about how to map them:\n * - whether the response body should be wrapped (typically if its type is primitive).\n * - whether the response is nullable so it can be null if the combination of\n * the headers and the body is empty.\n */\ninterface ResponseObjectWithMetadata {\n /** whether the mapper allows nullable body */\n hasNullableType: boolean;\n /** whether the response's body should be wrapped */\n shouldWrapBody: boolean;\n /** parsed headers of the response */\n headers:\n | {\n [key: string]: unknown;\n }\n | undefined;\n /** parsed body of the response */\n body: any;\n}\n\n/**\n * Maps the response as follows:\n * - wraps the response body if needed (typically if its type is primitive).\n * - returns null if the combination of the headers and the body is empty.\n * - otherwise, returns the combination of the headers and the body.\n *\n * @param responseObject - a representation of the parsed response\n * @returns the response that will be returned to the user which can be null and/or wrapped\n *\n * @internal\n */\nfunction handleNullableResponseAndWrappableBody(\n responseObject: ResponseObjectWithMetadata\n): unknown | null {\n const combinedHeadersAndBody = {\n ...responseObject.headers,\n ...responseObject.body\n };\n if (\n responseObject.hasNullableType &&\n Object.getOwnPropertyNames(combinedHeadersAndBody).length === 0\n ) {\n return responseObject.shouldWrapBody ? { body: null } : null;\n } else {\n return responseObject.shouldWrapBody\n ? {\n ...responseObject.headers,\n body: responseObject.body\n }\n : combinedHeadersAndBody;\n }\n}\n\n/**\n * Take a `FullOperationResponse` and turn it into a flat\n * response object to hand back to the consumer.\n * @param fullResponse - The processed response from the operation request\n * @param responseSpec - The response map from the OperationSpec\n *\n * @internal\n */\nexport function flattenResponse(\n fullResponse: FullOperationResponse,\n responseSpec: OperationResponseMap | undefined\n): unknown {\n const parsedHeaders = fullResponse.parsedHeaders;\n\n // head methods never have a body, but we return a boolean set to body property\n // to indicate presence/absence of the resource\n if (fullResponse.request.method === \"HEAD\") {\n return {\n ...parsedHeaders,\n body: fullResponse.parsedBody\n };\n }\n const bodyMapper = responseSpec && responseSpec.bodyMapper;\n const isNullable = Boolean(bodyMapper?.nullable);\n const expectedBodyTypeName = bodyMapper?.type.name;\n\n /** If the body is asked for, we look at the expected body type to handle it */\n if (expectedBodyTypeName === \"Stream\") {\n return {\n ...parsedHeaders,\n blobBody: fullResponse.blobBody,\n readableStreamBody: fullResponse.readableStreamBody\n };\n }\n\n const modelProperties =\n (expectedBodyTypeName === \"Composite\" &&\n (bodyMapper as CompositeMapper).type.modelProperties) ||\n {};\n const isPageableResponse = Object.keys(modelProperties).some(\n (k) => modelProperties[k].serializedName === \"\"\n );\n if (expectedBodyTypeName === \"Sequence\" || isPageableResponse) {\n const arrayResponse: { [key: string]: unknown } =\n fullResponse.parsedBody ?? (([] as unknown) as { [key: string]: unknown });\n\n for (const key of Object.keys(modelProperties)) {\n if (modelProperties[key].serializedName) {\n arrayResponse[key] = fullResponse.parsedBody?.[key];\n }\n }\n\n if (parsedHeaders) {\n for (const key of Object.keys(parsedHeaders)) {\n arrayResponse[key] = parsedHeaders[key];\n }\n }\n return isNullable &&\n !fullResponse.parsedBody &&\n !parsedHeaders &&\n Object.getOwnPropertyNames(modelProperties).length === 0\n ? null\n : arrayResponse;\n }\n\n return handleNullableResponseAndWrappableBody({\n body: fullResponse.parsedBody,\n headers: parsedHeaders,\n hasNullableType: isNullable,\n shouldWrapBody: isPrimitiveBody(fullResponse.parsedBody, expectedBodyTypeName)\n });\n}\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAUlC;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,KAAc,EAAE,cAAuB;IACrE,OAAO,CACL,cAAc,KAAK,WAAW;QAC9B,cAAc,KAAK,YAAY;QAC/B,CAAC,OAAO,KAAK,KAAK,QAAQ;YACxB,OAAO,KAAK,KAAK,QAAQ;YACzB,OAAO,KAAK,KAAK,SAAS;YAC1B,CAAA,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,KAAK,CAAC,iEAAiE,CAAC;gBACtF,IAAI;YACN,KAAK,KAAK,SAAS;YACnB,KAAK,KAAK,IAAI,CAAC,CAClB,CAAC;AACJ,CAAC;AAED,MAAM,mBAAmB,GACvB,qKAAqK,CAAC;AAExK;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,KAAa;IACtC,OAAO,mBAAmB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AACzC,CAAC;AAED,MAAM,cAAc,GAClB,gFAAgF,CAAC;AAEnF;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,OAAO,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACnC,CAAC;AAwBD;;;;;;;;;;GAUG;AACH,SAAS,sCAAsC,CAC7C,cAA0C;IAE1C,MAAM,sBAAsB,mCACvB,cAAc,CAAC,OAAO,GACtB,cAAc,CAAC,IAAI,CACvB,CAAC;IACF,IACE,cAAc,CAAC,eAAe;QAC9B,MAAM,CAAC,mBAAmB,CAA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e,CAAC,CAAC,CAAC,CAAC,cAAc,KAAK,EAAE,CAChD,CAAC;IACF,IAAI,oBAAoB,KAAK,UAAU,IAAI,kBAAkB,EAAE;QAC7D,MAAM,aAAa,GACjB,MAAA,YAAY,CAAC,UAAU,mCAAK,EAA4C,CAAC;QAE3E,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,EAAE;YAC9C,IAAI,eAAe,CAAC,GAAG,CAAC,CAAC,cAAc,EAAE;gBACvC,aAAa,CAAC,GAAG,CAAC,GAAG,MAAA,YAAY,CAAC,UAAU,0CAAG,GAAG,CAAC,CAAC;aACrD;SACF;QAED,IAAI,aAAa,EAAE;YACjB,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,EAAE;gBAC5C,aAAa,CAAC,GAAG,CAAC,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;aACzC;SACF;QACD,OAAO,UAAU;YACf,CAAC,YAAY,CAAC,UAAU;YACxB,CAAC,aAAa;YACd,MAAM,CAAC,mBAAmB,CAAC,eAAe,CAAC,CAAC,MAAM,KAAK,CAAC;YACxD,CAAC,CAAC,IAAI;YACN,CAAC,CAAC,aAAa,CAAC;KACnB;IAED,OAAO,sCAAsC,CAAC;QAC5C,IAAI,EAAE,YAAY,CAAC,UAAU;QAC7B,OAAO,EAAE,aAAa;QACtB,eAAe,EAAE,UAAU;QAC3B,cAAc,EAAE,eAAe,CAAC,YAAY,CAAC,UAAU,EAAE,oBAAoB,CAAC;KAC/E,CAAC,CAAC;AACL,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { CompositeMapper, FullOperationResponse, OperationResponseMap } from \"./interfaces\";\n\n/**\n * The union of all possible types for a primitive response body.\n * @internal\n */\nexport type BodyPrimitive = number | string | boolean | Date | Uint8Array | undefined | null;\n\n/**\n * A type guard for a primitive response body.\n * @param value - Value to test\n *\n * @internal\n */\nexport function isPrimitiveBody(value: unknown, mapperTypeName?: string): value is BodyPrimitive {\n return (\n mapperTypeName !== \"Composite\" &&\n mapperTypeName !== \"Dictionary\" &&\n (typeof value === \"string\" ||\n typeof value === \"number\" ||\n typeof value === \"boolean\" ||\n mapperTypeName?.match(/^(Date|DateTime|DateTimeRfc1123|UnixTime|ByteArray|Base64Url)$/i) !==\n null ||\n value === undefined ||\n value === null)\n );\n}\n\nconst validateISODuration =\n /^(-|\\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/;\n\n/**\n * Returns true if the given string is in ISO 8601 format.\n * @param value - The value to be validated for ISO 8601 duration format.\n * @internal\n */\nexport function isDuration(value: string): boolean {\n return validateISODuration.test(value);\n}\n\nconst validUuidRegex =\n /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/i;\n\n/**\n * Returns true if the provided uuid is valid.\n *\n * @param uuid - The uuid that needs to be validated.\n *\n * @internal\n */\nexport function isValidUuid(uuid: string): boolean {\n return validUuidRegex.test(uuid);\n}\n\n/**\n * Representation of parsed response headers and body coupled with information\n * about how to map them:\n * - whether the response body should be wrapped (typically if its type is primitive).\n * - whether the response is nullable so it can be null if the combination of\n * the headers and the body is empty.\n */\ninterface ResponseObjectWithMetadata {\n /** whether the mapper allows nullable body */\n hasNullableType: boolean;\n /** whether the response's body should be wrapped */\n shouldWrapBody: boolean;\n /** parsed headers of the response */\n headers:\n | {\n [key: string]: unknown;\n }\n | undefined;\n /** parsed body of the response */\n body: any;\n}\n\n/**\n * Maps the response as follows:\n * - wraps the response body if needed (typically if its type is primitive).\n * - returns null if the combination of the headers and the body is empty.\n * - otherwise, returns the combination of the headers and the body.\n *\n * @param responseObject - a representation of the parsed response\n * @returns the response that will be returned to the user which can be null and/or wrapped\n *\n * @internal\n */\nfunction handleNullableResponseAndWrappableBody(\n responseObject: ResponseObjectWithMetadata\n): unknown | null {\n const combinedHeadersAndBody = {\n ...responseObject.headers,\n ...responseObject.body,\n };\n if (\n responseObject.hasNullableType &&\n Object.getOwnPropertyNames(combinedHeadersAndBody).length === 0\n ) {\n return responseObject.shouldWrapBody ? { body: null } : null;\n } else {\n return responseObject.shouldWrapBody\n ? {\n ...responseObject.headers,\n body: responseObject.body,\n }\n : combinedHeadersAndBody;\n }\n}\n\n/**\n * Take a `FullOperationResponse` and turn it into a flat\n * response object to hand back to the consumer.\n * @param fullResponse - The processed response from the operation request\n * @param responseSpec - The response map from the OperationSpec\n *\n * @internal\n */\nexport function flattenResponse(\n fullResponse: FullOperationResponse,\n responseSpec: OperationResponseMap | undefined\n): unknown {\n const parsedHeaders = fullResponse.parsedHeaders;\n\n // head methods never have a body, but we return a boolean set to body property\n // to indicate presence/absence of the resource\n if (fullResponse.request.method === \"HEAD\") {\n return {\n ...parsedHeaders,\n body: fullResponse.parsedBody,\n };\n }\n const bodyMapper = responseSpec && responseSpec.bodyMapper;\n const isNullable = Boolean(bodyMapper?.nullable);\n const expectedBodyTypeName = bodyMapper?.type.name;\n\n /** If the body is asked for, we look at the expected body type to handle it */\n if (expectedBodyTypeName === \"Stream\") {\n return {\n ...parsedHeaders,\n blobBody: fullResponse.blobBody,\n readableStreamBody: fullResponse.readableStreamBody,\n };\n }\n\n const modelProperties =\n (expectedBodyTypeName === \"Composite\" &&\n (bodyMapper as CompositeMapper).type.modelProperties) ||\n {};\n const isPageableResponse = Object.keys(modelProperties).some(\n (k) => modelProperties[k].serializedName === \"\"\n );\n if (expectedBodyTypeName === \"Sequence\" || isPageableResponse) {\n const arrayResponse: { [key: string]: unknown } =\n fullResponse.parsedBody ?? ([] as unknown as { [key: string]: unknown });\n\n for (const key of Object.keys(modelProperties)) {\n if (modelProperties[key].serializedName) {\n arrayResponse[key] = fullResponse.parsedBody?.[key];\n }\n }\n\n if (parsedHeaders) {\n for (const key of Object.keys(parsedHeaders)) {\n arrayResponse[key] = parsedHeaders[key];\n }\n }\n return isNullable &&\n !fullResponse.parsedBody &&\n !parsedHeaders &&\n Object.getOwnPropertyNames(modelProperties).length === 0\n ? null\n : arrayResponse;\n }\n\n return handleNullableResponseAndWrappableBody({\n body: fullResponse.parsedBody,\n headers: parsedHeaders,\n hasNullableType: isNullable,\n shouldWrapBody: isPrimitiveBody(fullResponse.parsedBody, expectedBodyTypeName),\n });\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azure/core-client",
3
- "version": "1.4.0-alpha.20211123.3",
3
+ "version": "1.4.0-alpha.20220106.3",
4
4
  "description": "Core library for interfacing with AutoRest generated code",
5
5
  "sdk-type": "client",
6
6
  "main": "dist/index.js",
@@ -27,7 +27,6 @@
27
27
  "build": "npm run clean && tsc -p . && rollup -c 2>&1 && api-extractor run --local && npm run build:types",
28
28
  "check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
29
29
  "clean": "rimraf dist dist-* temp types *.tgz *.log",
30
- "docs": "typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src",
31
30
  "execute:samples": "echo skipped",
32
31
  "extract-api": "tsc -p . && api-extractor run --local",
33
32
  "format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"",
@@ -72,7 +71,7 @@
72
71
  "@azure/abort-controller": "^1.0.0",
73
72
  "@azure/core-asynciterator-polyfill": "^1.0.0",
74
73
  "@azure/core-auth": "^1.3.0",
75
- "@azure/core-rest-pipeline": "^1.1.0",
74
+ "@azure/core-rest-pipeline": ">=1.4.0-alpha <1.4.0-alphb",
76
75
  "@azure/core-tracing": "1.0.0-preview.13",
77
76
  "@azure/logger": "^1.0.0",
78
77
  "tslib": "^2.2.0"
@@ -103,14 +102,13 @@
103
102
  "karma-mocha-reporter": "^2.2.5",
104
103
  "karma-sourcemap-loader": "^0.3.8",
105
104
  "mocha": "^7.1.1",
106
- "mocha-junit-reporter": "^1.18.0",
107
- "prettier": "^1.16.4",
105
+ "mocha-junit-reporter": "^2.0.0",
106
+ "prettier": "^2.5.1",
108
107
  "rimraf": "^3.0.0",
109
108
  "rollup": "^1.16.3",
110
109
  "sinon": "^9.0.2",
111
110
  "ts-node": "^10.0.0",
112
111
  "typescript": "~4.2.0",
113
- "util": "^0.12.1",
114
- "typedoc": "0.15.2"
112
+ "util": "^0.12.1"
115
113
  }
116
114
  }
@@ -38,6 +38,9 @@ import { TransferProgressEvent } from '@azure/core-rest-pipeline';
38
38
  * ```
39
39
  */
40
40
  export declare function authorizeRequestOnClaimChallenge(onChallengeOptions: AuthorizeRequestOnChallengeOptions): Promise<boolean>;
41
+ /**
42
+ * The base definition of a mapper. Can be used for XML and plain JavaScript objects.
43
+ */
41
44
  export declare interface BaseMapper {
42
45
  /**
43
46
  * Name for the xml element
@@ -109,17 +112,46 @@ export declare interface CommonClientOptions extends PipelineOptions {
109
112
  */
110
113
  allowInsecureConnection?: boolean;
111
114
  }
115
+ /**
116
+ * A mapper composed of other mappers.
117
+ */
112
118
  export declare interface CompositeMapper extends BaseMapper {
119
+ /**
120
+ * The type descriptor of the `CompositeMapper`.
121
+ */
113
122
  type: CompositeMapperType;
114
123
  }
124
+ /**
125
+ * Helps build a mapper that describes how to map a set of properties of an object based on other mappers.
126
+ *
127
+ * Only one of the following properties should be present: `className`, `modelProperties` and `additionalProperties`.
128
+ */
115
129
  export declare interface CompositeMapperType {
130
+ /**
131
+ * Name of the composite mapper type.
132
+ */
116
133
  name: "Composite";
134
+ /**
135
+ * Use `className` to reference another type definition.
136
+ */
117
137
  className?: string;
138
+ /**
139
+ * Use `modelProperties` when the reference to the other type has been resolved.
140
+ */
118
141
  modelProperties?: {
119
142
  [propertyName: string]: Mapper;
120
143
  };
144
+ /**
145
+ * Used when a model has `additionalProperties: true`. Allows the generic processing of unnamed model properties on the response object.
146
+ */
121
147
  additionalProperties?: Mapper;
148
+ /**
149
+ * The name of the top-most parent scheme, the one that has no parents.
150
+ */
122
151
  uberParent?: string;
152
+ /**
153
+ * A polymorphic discriminator.
154
+ */
123
155
  polymorphicDiscriminator?: PolymorphicDiscriminator;
124
156
  }
125
157
  /**
@@ -179,19 +211,52 @@ export declare interface DeserializationPolicyOptions {
179
211
  */
180
212
  serializerOptions?: SerializerOptions;
181
213
  }
214
+ /**
215
+ * A mapper describing plain JavaScript objects used as key/value pairs.
216
+ */
182
217
  export declare interface DictionaryMapper extends BaseMapper {
218
+ /**
219
+ * The type descriptor of the `DictionaryMapper`.
220
+ */
183
221
  type: DictionaryMapperType;
222
+ /**
223
+ * Optionally, a prefix to add to the header collection.
224
+ */
184
225
  headerCollectionPrefix?: string;
185
226
  }
227
+ /**
228
+ * Helps build a mapper that describes how to parse a dictionary of mapped values.
229
+ */
186
230
  export declare interface DictionaryMapperType {
231
+ /**
232
+ * Name of the sequence type mapper.
233
+ */
187
234
  name: "Dictionary";
235
+ /**
236
+ * The mapper to use to map the value of each property in the dictionary.
237
+ */
188
238
  value: Mapper;
189
239
  }
240
+ /**
241
+ * A mapper describing an enum value.
242
+ */
190
243
  export declare interface EnumMapper extends BaseMapper {
244
+ /**
245
+ * The type descriptor of the `EnumMapper`.
246
+ */
191
247
  type: EnumMapperType;
192
248
  }
249
+ /**
250
+ * Helps build a mapper that describes how to parse an enum value.
251
+ */
193
252
  export declare interface EnumMapperType {
253
+ /**
254
+ * Name of the enum type mapper.
255
+ */
194
256
  name: "Enum";
257
+ /**
258
+ * Values allowed by this mapper.
259
+ */
195
260
  allowedValues: any[];
196
261
  }
197
262
  /**
@@ -236,20 +301,63 @@ export declare interface InternalClientPipelineOptions extends InternalPipelineO
236
301
  */
237
302
  serializationOptions?: SerializationPolicyOptions;
238
303
  }
304
+ /**
305
+ * Mappers are definitions of the data models used in the library.
306
+ * These data models are part of the Operation or Client definitions in the responses or parameters.
307
+ */
239
308
  export declare type Mapper = BaseMapper | CompositeMapper | SequenceMapper | DictionaryMapper | EnumMapper;
309
+ /**
310
+ * Description of various value constraints such as integer ranges and string regex.
311
+ */
240
312
  export declare interface MapperConstraints {
313
+ /**
314
+ * The value should be less than or equal to the `InclusiveMaximum` value.
315
+ */
241
316
  InclusiveMaximum?: number;
317
+ /**
318
+ * The value should be less than the `ExclusiveMaximum` value.
319
+ */
242
320
  ExclusiveMaximum?: number;
321
+ /**
322
+ * The value should be greater than or equal to the `InclusiveMinimum` value.
323
+ */
243
324
  InclusiveMinimum?: number;
325
+ /**
326
+ * The value should be greater than the `InclusiveMinimum` value.
327
+ */
244
328
  ExclusiveMinimum?: number;
329
+ /**
330
+ * The length should be smaller than the `MaxLength`.
331
+ */
245
332
  MaxLength?: number;
333
+ /**
334
+ * The length should be bigger than the `MinLength`.
335
+ */
246
336
  MinLength?: number;
337
+ /**
338
+ * The value must match the pattern.
339
+ */
247
340
  Pattern?: RegExp;
341
+ /**
342
+ * The value must contain fewer items than the MaxItems value.
343
+ */
248
344
  MaxItems?: number;
345
+ /**
346
+ * The value must contain more items than the `MinItems` value.
347
+ */
249
348
  MinItems?: number;
349
+ /**
350
+ * The value must contain only unique items.
351
+ */
250
352
  UniqueItems?: true;
353
+ /**
354
+ * The value should be exactly divisible by the `MultipleOf` value.
355
+ */
251
356
  MultipleOf?: number;
252
357
  }
358
+ /**
359
+ * Type of the mapper. Includes known mappers.
360
+ */
253
361
  export declare type MapperType = SimpleMapperType | CompositeMapperType | SequenceMapperType | DictionaryMapperType | EnumMapperType;
254
362
  /**
255
363
  * Known types of Mappers
@@ -500,9 +608,25 @@ export declare interface OperationURLParameter extends OperationParameter {
500
608
  export declare type ParameterPath = string | string[] | {
501
609
  [propertyName: string]: ParameterPath;
502
610
  };
611
+ /**
612
+ * Used to disambiguate discriminated type unions.
613
+ * For example, if response can have many shapes but also includes a 'kind' field (or similar),
614
+ * that field can be used to determine how to deserialize the response to the correct type.
615
+ */
503
616
  export declare interface PolymorphicDiscriminator {
617
+ /**
618
+ * Name of the discriminant property in the original JSON payload, e.g. `@odata.kind`.
619
+ */
504
620
  serializedName: string;
621
+ /**
622
+ * Name to use on the resulting object instead of the original property name.
623
+ * Useful since the JSON property could be difficult to work with.
624
+ * For example: For a field received as `@odata.kind`, the final object could instead include a property simply named `kind`.
625
+ */
505
626
  clientName: string;
627
+ /**
628
+ * It may contain any other property.
629
+ */
506
630
  [key: string]: string;
507
631
  }
508
632
  /**
@@ -515,11 +639,26 @@ export declare type QueryCollectionFormat = "CSV" | "SSV" | "TSV" | "Pipes" | "M
515
639
  * May be called multiple times.
516
640
  */
517
641
  export declare type RawResponseCallback = (rawResponse: FullOperationResponse, flatResponse: unknown) => void;
642
+ /**
643
+ * A mapper describing arrays.
644
+ */
518
645
  export declare interface SequenceMapper extends BaseMapper {
646
+ /**
647
+ * The type descriptor of the `SequenceMapper`.
648
+ */
519
649
  type: SequenceMapperType;
520
650
  }
651
+ /**
652
+ * Helps build a mapper that describes how to parse a sequence of mapped values.
653
+ */
521
654
  export declare interface SequenceMapperType {
655
+ /**
656
+ * Name of the sequence type mapper.
657
+ */
522
658
  name: "Sequence";
659
+ /**
660
+ * The mapper to use to map each one of the properties of the sequence.
661
+ */
523
662
  element: Mapper;
524
663
  }
525
664
  /**
@@ -546,16 +685,46 @@ export declare interface SerializationPolicyOptions {
546
685
  }
547
686
  /**
548
687
  * Used to map raw response objects to final shapes.
549
- * Mostly useful for unpacking/packing Dates and other encoded types that
550
- * are not intrinsic to JSON.
688
+ * Helps packing and unpacking Dates and other encoded types that are not intrinsic to JSON.
689
+ * Also allows pulling values from headers, as well as inserting default values and constants.
551
690
  */
552
691
  export declare interface Serializer {
692
+ /**
693
+ * The provided model mapper.
694
+ */
553
695
  readonly modelMappers: {
554
696
  [key: string]: any;
555
697
  };
698
+ /**
699
+ * Whether the contents are XML or not.
700
+ */
556
701
  readonly isXML: boolean;
702
+ /**
703
+ * Validates constraints, if any. This function will throw if the provided value does not respect those constraints.
704
+ * @param mapper - The definition of data models.
705
+ * @param value - The value.
706
+ * @param objectName - Name of the object. Used in the error messages.
707
+ */
557
708
  validateConstraints(mapper: Mapper, value: any, objectName: string): void;
709
+ /**
710
+ * Serialize the given object based on its metadata defined in the mapper.
711
+ *
712
+ * @param mapper - The mapper which defines the metadata of the serializable object.
713
+ * @param object - A valid Javascript object to be serialized.
714
+ * @param objectName - Name of the serialized object.
715
+ * @param options - additional options to deserialization.
716
+ * @returns A valid serialized Javascript object.
717
+ */
558
718
  serialize(mapper: Mapper, object: any, objectName?: string, options?: SerializerOptions): any;
719
+ /**
720
+ * Deserialize the given object based on its metadata defined in the mapper.
721
+ *
722
+ * @param mapper - The mapper which defines the metadata of the serializable object.
723
+ * @param responseBody - A valid Javascript entity to be deserialized.
724
+ * @param objectName - Name of the deserialized object.
725
+ * @param options - Controls behavior of XML parser and builder.
726
+ * @returns A valid deserialized Javascript object.
727
+ */
559
728
  deserialize(mapper: Mapper, responseBody: any, objectName: string, options?: SerializerOptions): any;
560
729
  }
561
730
  /**
@@ -638,7 +807,13 @@ export declare interface ServiceClientOptions extends CommonClientOptions {
638
807
  */
639
808
  pipeline?: Pipeline;
640
809
  }
810
+ /**
811
+ * The type of a simple mapper.
812
+ */
641
813
  export declare interface SimpleMapperType {
814
+ /**
815
+ * Name of the type of the property.
816
+ */
642
817
  name: "Base64Url" | "Boolean" | "ByteArray" | "Date" | "DateTime" | "DateTimeRfc1123" | "Object" | "Stream" | "String" | "TimeSpan" | "UnixTime" | "Uuid" | "Number" | "any";
643
818
  }
644
819
  /**