/
StorageClient.ts
77 lines (69 loc) · 2.11 KB
/
StorageClient.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { StorageClientContext } from "./generated/src/storageClientContext";
import { Pipeline } from "./Pipeline";
import { escapeURLPath, getAccountNameFromUrl } from "./utils/utils.common";
import { SERVICE_VERSION } from "./utils/constants";
import { OperationTracingOptions } from "@azure/core-tracing";
/**
* An interface for options common to every remote operation.
*/
export interface CommonOptions {
tracingOptions?: OperationTracingOptions;
}
/**
* A StorageClient represents a base client class for ServiceClient, ContainerClient and etc.
*
* @export
* @class StorageClient
*/
export abstract class StorageClient {
/**
* URL string value.
*
* @type {string}
* @memberof StorageClient
*/
public readonly url: string;
public readonly accountName: string;
/**
* Request policy pipeline.
*
* @internal
* @ignore
* @type {Pipeline}
* @memberof StorageClient
*/
protected readonly pipeline: Pipeline;
/**
* StorageClient is a reference to protocol layer operations entry, which is
* generated by AutoRest generator.
*
* @protected
* @type {StorageClientContext}
* @memberof StorageClient
*/
protected readonly storageClientContext: StorageClientContext;
/**
* Creates an instance of StorageClient.
* @param {string} url
* @param {Pipeline} pipeline
* @memberof StorageClient
*/
protected constructor(url: string, pipeline: Pipeline) {
// URL should be encoded and only once, protocol layer shouldn't encode URL again
this.url = escapeURLPath(url);
this.accountName = getAccountNameFromUrl(url);
this.pipeline = pipeline;
this.storageClientContext = new StorageClientContext(
SERVICE_VERSION,
this.url,
pipeline.toServiceClientOptions()
);
// Remove the default content-type in generated code of StorageClientContext
const storageClientContext = this.storageClientContext as any;
if (storageClientContext.requestContentType) {
storageClientContext.requestContentType = undefined;
}
}
}