@azure-rest/core-client
Advanced tools
Comparing version 1.0.0-alpha.20220725.3 to 1.0.0-alpha.20220805.4
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
import { isTokenCredential } from "@azure/core-auth"; | ||
import { isCertificateCredential } from "./certificateCredential"; | ||
import { createDefaultPipeline } from "./clientHelpers"; | ||
@@ -80,5 +79,3 @@ import { sendRequest, sendRequestAsStream } from "./sendRequest"; | ||
function isCredential(param) { | ||
if (param.key !== undefined || | ||
isTokenCredential(param) || | ||
isCertificateCredential(param)) { | ||
if (param.key !== undefined || isTokenCredential(param)) { | ||
return true; | ||
@@ -85,0 +82,0 @@ } |
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
/** | ||
* Converts a string representing binary content into a Uint8Array | ||
*/ | ||
export function stringToBinaryArray(content) { | ||
const arr = new Uint8Array(content.length); | ||
for (let i = 0; i < content.length; i++) { | ||
arr[i] = content.charCodeAt(i); | ||
} | ||
return arr; | ||
} | ||
/** | ||
* Converts binary content to its string representation | ||
@@ -15,0 +5,0 @@ */ |
@@ -7,3 +7,2 @@ // Copyright (c) Microsoft Corporation. | ||
*/ | ||
export { isCertificateCredential } from "./certificateCredential"; | ||
export { createRestError } from "./restError"; | ||
@@ -10,0 +9,0 @@ export * from "./getClient"; |
@@ -6,3 +6,3 @@ // Copyright (c) Microsoft Corporation. | ||
import { isReadableStream } from "./helpers/isReadableStream"; | ||
import { binaryArrayToString, stringToBinaryArray } from "./helpers/getBinaryBody"; | ||
import { binaryArrayToString } from "./helpers/getBinaryBody"; | ||
/** | ||
@@ -22,3 +22,3 @@ * Helper function to send request used by the client | ||
const rawHeaders = response.headers.toJSON(); | ||
const parsedBody = getResponseBody(response, options); | ||
const parsedBody = getResponseBody(response); | ||
return { | ||
@@ -152,3 +152,3 @@ request, | ||
*/ | ||
function getResponseBody(response, requestOptions) { | ||
function getResponseBody(response) { | ||
var _a, _b; | ||
@@ -162,9 +162,2 @@ // Set the default response type | ||
} | ||
/** | ||
* If we know from options or from the content type that we are receiving binary content, | ||
* encode it into a UInt8Array | ||
*/ | ||
if (requestOptions.binaryResponse || isBinaryContentType(firstType)) { | ||
return stringToBinaryArray(bodyToParse); | ||
} | ||
// Default to "application/json" and fallback to string; | ||
@@ -196,14 +189,2 @@ try { | ||
} | ||
function isBinaryContentType(contentType) { | ||
return [ | ||
"application/octet-stream", | ||
"application/x-rdp", | ||
"image/bmp", | ||
"image/gif", | ||
"image/jpeg", | ||
"image/png", | ||
"application/pdf", | ||
"application/zip", | ||
].includes(contentType); | ||
} | ||
//# sourceMappingURL=sendRequest.js.map |
@@ -9,52 +9,3 @@ 'use strict'; | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
/** | ||
* Helper TypeGuard that checks if something is defined or not. | ||
* @param thing - Anything | ||
* @internal | ||
*/ | ||
function isDefined(thing) { | ||
return typeof thing !== "undefined" && thing !== null; | ||
} | ||
/** | ||
* Helper TypeGuard that checks if the input is an object with the specified properties. | ||
* @param thing - Anything. | ||
* @param properties - The name of the properties that should appear in the object. | ||
* @internal | ||
*/ | ||
function isObjectWithProperties(thing, properties) { | ||
if (!isDefined(thing) || typeof thing !== "object") { | ||
return false; | ||
} | ||
for (const property of properties) { | ||
if (!objectHasProperty(thing, property)) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
/** | ||
* Helper TypeGuard that checks if the input is an object with the specified property. | ||
* @param thing - Any object. | ||
* @param property - The name of the property that should appear in the object. | ||
* @internal | ||
*/ | ||
function objectHasProperty(thing, property) { | ||
return typeof thing === "object" && property in thing; | ||
} | ||
// Copyright (c) Microsoft Corporation. | ||
/** | ||
* Tests an object to determine whether it implements CertificateCredential. | ||
* | ||
* @param credential - The assumed CertificateCredential to be tested. | ||
*/ | ||
function isCertificateCredential(credential) { | ||
return (isObjectWithProperties(credential, ["certKey", "cert"]) && | ||
typeof credential.cert === "string" && | ||
typeof credential.certKey === "string"); | ||
} | ||
// Copyright (c) Microsoft Corporation. | ||
/** | ||
* Creates a rest error from a PathUnchecked response | ||
@@ -171,12 +122,2 @@ */ | ||
/** | ||
* Converts a string representing binary content into a Uint8Array | ||
*/ | ||
function stringToBinaryArray(content) { | ||
const arr = new Uint8Array(content.length); | ||
for (let i = 0; i < content.length; i++) { | ||
arr[i] = content.charCodeAt(i); | ||
} | ||
return arr; | ||
} | ||
/** | ||
* Converts binary content to its string representation | ||
@@ -207,3 +148,3 @@ */ | ||
const rawHeaders = response.headers.toJSON(); | ||
const parsedBody = getResponseBody(response, options); | ||
const parsedBody = getResponseBody(response); | ||
return { | ||
@@ -337,3 +278,3 @@ request, | ||
*/ | ||
function getResponseBody(response, requestOptions) { | ||
function getResponseBody(response) { | ||
var _a, _b; | ||
@@ -347,9 +288,2 @@ // Set the default response type | ||
} | ||
/** | ||
* If we know from options or from the content type that we are receiving binary content, | ||
* encode it into a UInt8Array | ||
*/ | ||
if (requestOptions.binaryResponse || isBinaryContentType(firstType)) { | ||
return stringToBinaryArray(bodyToParse); | ||
} | ||
// Default to "application/json" and fallback to string; | ||
@@ -381,14 +315,2 @@ try { | ||
} | ||
function isBinaryContentType(contentType) { | ||
return [ | ||
"application/octet-stream", | ||
"application/x-rdp", | ||
"image/bmp", | ||
"image/gif", | ||
"image/jpeg", | ||
"image/png", | ||
"application/pdf", | ||
"application/zip", | ||
].includes(contentType); | ||
} | ||
@@ -568,5 +490,3 @@ // Copyright (c) Microsoft Corporation. | ||
function isCredential(param) { | ||
if (param.key !== undefined || | ||
coreAuth.isTokenCredential(param) || | ||
isCertificateCredential(param)) { | ||
if (param.key !== undefined || coreAuth.isTokenCredential(param)) { | ||
return true; | ||
@@ -579,3 +499,2 @@ } | ||
exports.getClient = getClient; | ||
exports.isCertificateCredential = isCertificateCredential; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@azure-rest/core-client", | ||
"version": "1.0.0-alpha.20220725.3", | ||
"description": "Core library for interfacing with AutoRest rest level generated code", | ||
"version": "1.0.0-alpha.20220805.4", | ||
"description": "Core library for interfacing with Azure Rest Clients", | ||
"sdk-type": "client", | ||
@@ -6,0 +6,0 @@ "main": "dist/index.js", |
@@ -37,16 +37,2 @@ /** | ||
/** | ||
* Represents a certificate credential for authentication. | ||
*/ | ||
export declare interface CertificateCredential { | ||
/** | ||
* Certificate used to authenticate | ||
*/ | ||
cert: string; | ||
/** | ||
* Certificate key | ||
*/ | ||
certKey: string; | ||
} | ||
/** | ||
* Shape of a Rest Level Client | ||
@@ -178,9 +164,2 @@ */ | ||
/** | ||
* Tests an object to determine whether it implements CertificateCredential. | ||
* | ||
* @param credential - The assumed CertificateCredential to be tested. | ||
*/ | ||
export declare function isCertificateCredential(credential: unknown): credential is CertificateCredential; | ||
/** | ||
* Helper type used to detect parameters in a path template | ||
@@ -240,7 +219,2 @@ * text surrounded by \{\} will be considered a path parameter | ||
/** | ||
* With this property set to true, the response body will be returned | ||
* as a binary array UInt8Array | ||
*/ | ||
binaryResponse?: boolean; | ||
/** | ||
* Path parameters for custom the base url | ||
@@ -247,0 +221,0 @@ */ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
144549
32
1280