mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Add Patch Support (#23591)
* add patch support * docs and cleanup * one more doc
This commit is contained in:
@@ -16,7 +16,8 @@ export enum HttpMethod {
|
|||||||
GET = 'get',
|
GET = 'get',
|
||||||
POST = 'post',
|
POST = 'post',
|
||||||
PUT = 'put',
|
PUT = 'put',
|
||||||
DELETE = 'delete'
|
DELETE = 'delete',
|
||||||
|
PATCH = 'patch'
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum HttpStatus {
|
export enum HttpStatus {
|
||||||
@@ -118,6 +119,23 @@ export class HttpClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Http Patch request
|
||||||
|
* @param url
|
||||||
|
* @param options
|
||||||
|
*/
|
||||||
|
async sendPatchRequestAsync<T>(
|
||||||
|
url: string,
|
||||||
|
options?: NetworkRequestOptions,
|
||||||
|
cancellationToken?: number
|
||||||
|
): Promise<AzureNetworkResponse<T>> {
|
||||||
|
if (this.proxyUrl) {
|
||||||
|
return networkRequestViaProxy(url, this.proxyUrl, HttpMethod.PATCH, options, this.customAgentOptions as http.AgentOptions, cancellationToken);
|
||||||
|
} else {
|
||||||
|
return networkRequestViaHttps(url, HttpMethod.PATCH, options, this.customAgentOptions as https.AgentOptions, cancellationToken);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const networkRequestViaProxy = <T>(
|
const networkRequestViaProxy = <T>(
|
||||||
@@ -270,6 +288,7 @@ const networkRequestViaHttps = <T>(
|
|||||||
): Promise<AzureNetworkResponse<T>> => {
|
): Promise<AzureNetworkResponse<T>> => {
|
||||||
const isPostRequest = httpMethod === HttpMethod.POST;
|
const isPostRequest = httpMethod === HttpMethod.POST;
|
||||||
const isPutRequest = httpMethod === HttpMethod.PUT;
|
const isPutRequest = httpMethod === HttpMethod.PUT;
|
||||||
|
const isPatchRequest = httpMethod === HttpMethod.PATCH;
|
||||||
// Note: Text Encoder is necessary here because otherwise it was not able to handle Chinese characters in table names.
|
// Note: Text Encoder is necessary here because otherwise it was not able to handle Chinese characters in table names.
|
||||||
const body = (new TextEncoder()).encode(options?.body || '');
|
const body = (new TextEncoder()).encode(options?.body || '');
|
||||||
const url = new URL(urlString);
|
const url = new URL(urlString);
|
||||||
@@ -288,7 +307,7 @@ const networkRequestViaHttps = <T>(
|
|||||||
customOptions.agent = new https.Agent(agentOptions);
|
customOptions.agent = new https.Agent(agentOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isPostRequest || isPutRequest) {
|
if (isPostRequest || isPutRequest || isPatchRequest) {
|
||||||
// needed for post request to work
|
// needed for post request to work
|
||||||
customOptions.headers = {
|
customOptions.headers = {
|
||||||
...customOptions.headers,
|
...customOptions.headers,
|
||||||
@@ -306,7 +325,7 @@ const networkRequestViaHttps = <T>(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isPostRequest || isPutRequest) {
|
if (isPostRequest || isPutRequest || isPatchRequest) {
|
||||||
request.write(body);
|
request.write(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -446,8 +446,8 @@ export async function getSelectedSubscriptions(appContext: AppContext, account?:
|
|||||||
* @param account The azure account used to acquire access token
|
* @param account The azure account used to acquire access token
|
||||||
* @param subscription The subscription under azure account where the service will perform operations.
|
* @param subscription The subscription under azure account where the service will perform operations.
|
||||||
* @param path The path for the service starting from '/subscription/..'. See https://docs.microsoft.com/rest/api/azure/.
|
* @param path The path for the service starting from '/subscription/..'. See https://docs.microsoft.com/rest/api/azure/.
|
||||||
* @param requestType Http request method. Currently GET, PUT, POST and DELETE methods are supported.
|
* @param requestType Http request method. Currently GET, PUT, POST, DELETE, and PATCH methods are supported.
|
||||||
* @param requestBody Optional request body to be used in PUT and POST requests.
|
* @param requestBody Optional request body to be used in PUT, POST, AND PATCH requests.
|
||||||
* @param ignoreErrors When this flag is set the method will not throw any runtime or service errors and will return the errors in errors array.
|
* @param ignoreErrors When this flag is set the method will not throw any runtime or service errors and will return the errors in errors array.
|
||||||
* @param host Use this to override the host. The default host is https://management.azure.com
|
* @param host Use this to override the host. The default host is https://management.azure.com
|
||||||
* @param requestHeaders Provide additional request headers
|
* @param requestHeaders Provide additional request headers
|
||||||
@@ -545,6 +545,9 @@ export async function makeHttpRequest<B>(
|
|||||||
headers: reqHeaders
|
headers: reqHeaders
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case HttpRequestMethod.PATCH:
|
||||||
|
response = await httpClient.sendPatchRequestAsync<B | ErrorResponseBodyWithError>(requestUrl, networkRequestOptions);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
const error = new Error(`Unknown RequestType "${requestType}"`);
|
const error = new Error(`Unknown RequestType "${requestType}"`);
|
||||||
if (!ignoreErrors) {
|
if (!ignoreErrors) {
|
||||||
|
|||||||
7
extensions/azurecore/src/azurecore.d.ts
vendored
7
extensions/azurecore/src/azurecore.d.ts
vendored
@@ -274,7 +274,8 @@ declare module 'azurecore' {
|
|||||||
GET,
|
GET,
|
||||||
PUT,
|
PUT,
|
||||||
POST,
|
POST,
|
||||||
DELETE
|
DELETE,
|
||||||
|
PATCH
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -314,8 +315,8 @@ declare module 'azurecore' {
|
|||||||
* @param account The azure account used to acquire access token
|
* @param account The azure account used to acquire access token
|
||||||
* @param subscription The subscription under azure account where the service will perform operations.
|
* @param subscription The subscription under azure account where the service will perform operations.
|
||||||
* @param path The path for the service starting from '/subscription/..'. See https://docs.microsoft.com/rest/api/azure/.
|
* @param path The path for the service starting from '/subscription/..'. See https://docs.microsoft.com/rest/api/azure/.
|
||||||
* @param requestType Http request method. Currently GET, PUT, POST and DELETE methods are supported.
|
* @param requestType Http request method. Currently GET, PUT, POST, DELETE, and PATCH methods are supported.
|
||||||
* @param requestBody Optional request body to be used in PUT and POST requests.
|
* @param requestBody Optional request body to be used in PUT, POST, and PATCH requests.
|
||||||
* @param ignoreErrors When this flag is set the method will not throw any runtime or service errors and will return the errors in errors array.
|
* @param ignoreErrors When this flag is set the method will not throw any runtime or service errors and will return the errors in errors array.
|
||||||
* @param host Use this to override the host. The default host is https://management.azure.com
|
* @param host Use this to override the host. The default host is https://management.azure.com
|
||||||
* @param requestHeaders Provide additional request headers
|
* @param requestHeaders Provide additional request headers
|
||||||
|
|||||||
Reference in New Issue
Block a user