1 | /**
|
2 | * This file is part of the @egodigital/egoose distribution.
|
3 | * Copyright (c) e.GO Digital GmbH, Aachen, Germany (https://www.e-go-digital.com/)
|
4 | *
|
5 | * @egodigital/egoose is free software: you can redistribute it and/or modify
|
6 | * it under the terms of the GNU Lesser General Public License as
|
7 | * published by the Free Software Foundation, version 3.
|
8 | *
|
9 | * @egodigital/egoose is distributed in the hope that it will be useful, but
|
10 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
12 | * Lesser General Public License for more details.
|
13 | *
|
14 | * You should have received a copy of the GNU Lesser General Public License
|
15 | * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16 | */
|
17 | /// <reference types="node" />
|
18 | import * as azureStorage from 'azure-storage';
|
19 | /**
|
20 | * Options for an 'AzureStorageClient'.
|
21 | */
|
22 | export interface AzureStorageClientOptions {
|
23 | /**
|
24 | * A custom function or string that provides the name of the underlying container.
|
25 | * If not defined, 'AZURE_STORAGE_CONTAINER' environment variable is used.
|
26 | *
|
27 | * @return {string|Function} The result with the container name or the container name as string.
|
28 | */
|
29 | blobContainerProvider?: string | (() => string | Promise<string>);
|
30 | /**
|
31 | * A custom function, which detects a MIME type by a blob name / path,
|
32 | *
|
33 | * @param {string} path The blob path / name.
|
34 | *
|
35 | * @return {string|Promise<string>} The result with the detected MIME type.
|
36 | */
|
37 | blobContentTypeDetector?: (path: string) => string | Promise<string>;
|
38 | /**
|
39 | * A custom function that provides the 'BlobService' instance to use.
|
40 | * If not defined, default settings from environment are used.
|
41 | *
|
42 | * @return {azureStorage.BlobService|Promise<azureStorage.BlobService>} The result with the service instance.
|
43 | */
|
44 | blobServiceProvider?: () => azureStorage.BlobService | Promise<azureStorage.BlobService>;
|
45 | /**
|
46 | * A custom function that resolves a full blob path.
|
47 | *
|
48 | * @param {string} path The input path.
|
49 | *
|
50 | * @return {string|Promise<string>} The result with the full path.
|
51 | */
|
52 | toFullBlobPath?: (path: string) => string | Promise<string>;
|
53 | /**
|
54 | * A custom function that creates a unique blob name.
|
55 | *
|
56 | * @param {string} path The input path / name of the blob.
|
57 | *
|
58 | * @return {string|Promise<string>} The result with a unique blob name / path.
|
59 | */
|
60 | uniqueBlobNameCreator?: (path: string) => string | Promise<string>;
|
61 | }
|
62 | /**
|
63 | * An async Azure Storage client.
|
64 | */
|
65 | export declare class AzureStorageClient {
|
66 | readonly options?: AzureStorageClientOptions;
|
67 | /**
|
68 | * Initializes a new instance of that class.
|
69 | *
|
70 | * @param {AzureStorageClientOptions} [options] The custom options.
|
71 | */
|
72 | constructor(options?: AzureStorageClientOptions);
|
73 | /**
|
74 | * Creates a new blob service instance, based on the underlying options.
|
75 | *
|
76 | * @return {Promise<azureStorage.BlobService>} The promise with the new instance.
|
77 | */
|
78 | createBlobService(): Promise<azureStorage.BlobService>;
|
79 | /**
|
80 | * Creates a new instance from environment settings.
|
81 | *
|
82 | * @return {AzureStorageClient} The new instance.
|
83 | */
|
84 | static fromEnvironment(): AzureStorageClient;
|
85 | /**
|
86 | * Tries to return information about a blob.
|
87 | *
|
88 | * @param {string} path The path / name of the blob to check.
|
89 | *
|
90 | * @return {Promise<false|azureStorage.BlobService.BlobResult>} The promise that contains the blob information or (false) if it does not exist.
|
91 | */
|
92 | getBlobInfo(path: string): Promise<false | azureStorage.BlobService.BlobResult>;
|
93 | private getContainer;
|
94 | /**
|
95 | * Loads a blob.
|
96 | *
|
97 | * @param {string} path The path / blob name.
|
98 | *
|
99 | * @return {Promise<Buffer>} The promises with the loaded data.
|
100 | */
|
101 | loadBlob(path: string): Promise<Buffer>;
|
102 | /**
|
103 | * Saves / uploads a blob.
|
104 | *
|
105 | * @param {string} path The path / name of the blob.
|
106 | * @param {any} data The data to upload / store.
|
107 | */
|
108 | saveBlob(path: string, data: any): Promise<void>;
|
109 | /**
|
110 | * Saves a blob with a unique name / path.
|
111 | *
|
112 | * @param {string} path The original path / name of the blob.
|
113 | * @param {any} data The data to store / save.
|
114 | *
|
115 | * @return {Promise<string>} The promise with the path / name of the stored blob.
|
116 | */
|
117 | saveUniqueBlob(path: string, data: any): Promise<string>;
|
118 | private toFullPath;
|
119 | }
|
120 | /**
|
121 | * Normalizes an Azure blob path.
|
122 | *
|
123 | * @param {string} p The input path.
|
124 | *
|
125 | * @return {string} The normalized path.
|
126 | */
|
127 | export declare function normalizeAzureBlobPath(p: string): string;
|