@directus/storage-driver-azure 9.26.0 → 10.0.1
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.
- package/dist/index.d.ts +29 -0
- package/license +107 -0
- package/package.json +8 -9
- package/dist/index.test.js +0 -373
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
import type { Driver, Range } from '@directus/storage';
|
|
3
|
+
import type { Readable } from 'node:stream';
|
|
4
|
+
export type DriverAzureConfig = {
|
|
5
|
+
containerName: string;
|
|
6
|
+
accountName: string;
|
|
7
|
+
accountKey: string;
|
|
8
|
+
root?: string;
|
|
9
|
+
endpoint?: string;
|
|
10
|
+
};
|
|
11
|
+
export declare class DriverAzure implements Driver {
|
|
12
|
+
private containerClient;
|
|
13
|
+
private signedCredentials;
|
|
14
|
+
private root;
|
|
15
|
+
constructor(config: DriverAzureConfig);
|
|
16
|
+
private fullPath;
|
|
17
|
+
read(filepath: string, range?: Range): Promise<Readable>;
|
|
18
|
+
write(filepath: string, content: Readable, type?: string): Promise<void>;
|
|
19
|
+
delete(filepath: string): Promise<void>;
|
|
20
|
+
stat(filepath: string): Promise<{
|
|
21
|
+
size: number;
|
|
22
|
+
modified: Date;
|
|
23
|
+
}>;
|
|
24
|
+
exists(filepath: string): Promise<boolean>;
|
|
25
|
+
move(src: string, dest: string): Promise<void>;
|
|
26
|
+
copy(src: string, dest: string): Promise<void>;
|
|
27
|
+
list(prefix?: string): AsyncGenerator<string, void, unknown>;
|
|
28
|
+
}
|
|
29
|
+
export default DriverAzure;
|
package/license
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
Licensor: Monospace, Inc.
|
|
2
|
+
|
|
3
|
+
Licensed Work: Directus
|
|
4
|
+
The Licensed Work is Copyright © 2023 Monospace, Inc.
|
|
5
|
+
|
|
6
|
+
Additional Use Grant: You may use the Licensed Work in production as long as
|
|
7
|
+
your Total Finances do not exceed US $5,000,000 for the
|
|
8
|
+
most recent 12-month period, provided that Monospace, Inc.
|
|
9
|
+
will not be liable to you in any way, including for any
|
|
10
|
+
damages, including general, special, incidental or
|
|
11
|
+
consequential damages, arising out of such use.
|
|
12
|
+
|
|
13
|
+
References to: “Total Finances” mean the largest of your
|
|
14
|
+
aggregate gross revenues, entire budget, and/or funding
|
|
15
|
+
(no matter the source); “you” and “your” include (without
|
|
16
|
+
limitation) any individual or entity agreeing to these
|
|
17
|
+
terms and any affiliates of such individual or entity; and
|
|
18
|
+
“production” mean any use other than (i) development of
|
|
19
|
+
(including evaluation of the Licensed Work), debugging, or
|
|
20
|
+
testing your offerings, or (ii) making the Licensed Work
|
|
21
|
+
available standalone in unmodified object code form.
|
|
22
|
+
|
|
23
|
+
Change Date: Three years from release date
|
|
24
|
+
|
|
25
|
+
Change License: GNU General Public License (GPL) v3
|
|
26
|
+
|
|
27
|
+
For information about alternative licensing arrangements, please visit
|
|
28
|
+
https://directus.io/pricing.
|
|
29
|
+
|
|
30
|
+
--------------------------------------------------------------------------------
|
|
31
|
+
|
|
32
|
+
Business Source License 1.1
|
|
33
|
+
|
|
34
|
+
Terms
|
|
35
|
+
|
|
36
|
+
The Licensor hereby grants you the right to copy, modify, create derivative
|
|
37
|
+
works, redistribute, and make non-production use of the Licensed Work. The
|
|
38
|
+
Licensor may make an Additional Use Grant, above, permitting limited production
|
|
39
|
+
use.
|
|
40
|
+
|
|
41
|
+
Effective on the Change Date, or the fourth anniversary of the first publicly
|
|
42
|
+
available distribution of a specific version of the Licensed Work under this
|
|
43
|
+
License, whichever comes first, the Licensor hereby grants you rights under the
|
|
44
|
+
terms of the Change License, and the rights granted in the paragraph above
|
|
45
|
+
terminate.
|
|
46
|
+
|
|
47
|
+
If your use of the Licensed Work does not comply with the requirements currently
|
|
48
|
+
in effect as described in this License, you must purchase a commercial license
|
|
49
|
+
from the Licensor, its affiliated entities, or authorized resellers, or you must
|
|
50
|
+
refrain from using the Licensed Work.
|
|
51
|
+
|
|
52
|
+
All copies of the original and modified Licensed Work, and derivative works of
|
|
53
|
+
the Licensed Work, are subject to this License. This License applies separately
|
|
54
|
+
for each version of the Licensed Work and the Change Date may vary for each
|
|
55
|
+
version of the Licensed Work released by Licensor.
|
|
56
|
+
|
|
57
|
+
You must conspicuously display this License on each original or modified copy of
|
|
58
|
+
the Licensed Work. If you receive the Licensed Work in original or modified form
|
|
59
|
+
from a third party, the terms and conditions set forth in this License apply to
|
|
60
|
+
your use of that work.
|
|
61
|
+
|
|
62
|
+
Any use of the Licensed Work in violation of this License will automatically
|
|
63
|
+
terminate your rights under this License for the current and all other versions
|
|
64
|
+
of the Licensed Work.
|
|
65
|
+
|
|
66
|
+
This License does not grant you any right in any trademark or logo of Licensor
|
|
67
|
+
or its affiliates (provided that you may use a trademark or logo of Licensor as
|
|
68
|
+
expressly required by this License).
|
|
69
|
+
|
|
70
|
+
TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON AN
|
|
71
|
+
“AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, EXPRESS
|
|
72
|
+
OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF MERCHANTABILITY,
|
|
73
|
+
FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND TITLE.
|
|
74
|
+
|
|
75
|
+
MariaDB hereby grants you permission to use this License’s text to license your
|
|
76
|
+
works, and to refer to it using the trademark “Business Source License”, as long
|
|
77
|
+
as you comply with the Covenants of Licensor below.
|
|
78
|
+
|
|
79
|
+
Covenants of Licensor
|
|
80
|
+
|
|
81
|
+
In consideration of the right to use this License’s text and the “Business
|
|
82
|
+
Source License” name and trademark, Licensor covenants to MariaDB, and to all
|
|
83
|
+
other recipients of the licensed work to be provided by Licensor:
|
|
84
|
+
|
|
85
|
+
1. To specify as the Change License the GPL Version 2.0 or any later version,
|
|
86
|
+
or a license that is compatible with GPL Version 2.0 or a later version,
|
|
87
|
+
where “compatible” means that software provided under the Change License can
|
|
88
|
+
be included in a program with software provided under GPL Version 2.0 or a
|
|
89
|
+
later version. Licensor may specify additional Change Licenses without
|
|
90
|
+
limitation.
|
|
91
|
+
|
|
92
|
+
2. To either: (a) specify an additional grant of rights to use that does not
|
|
93
|
+
impose any additional restriction on the right granted in this License, as
|
|
94
|
+
the Additional Use Grant; or (b) insert the text “None”.
|
|
95
|
+
|
|
96
|
+
3. To specify a Change Date.
|
|
97
|
+
|
|
98
|
+
4. Not to modify this License in any other way.
|
|
99
|
+
|
|
100
|
+
Notice
|
|
101
|
+
|
|
102
|
+
The Business Source License (this document, or the "License") is not an Open
|
|
103
|
+
Source license. However, the Licensed Work will eventually be made available
|
|
104
|
+
under an Open Source License, as stated in this License.
|
|
105
|
+
|
|
106
|
+
License text copyright © 2023 MariaDB plc, All Rights Reserved.
|
|
107
|
+
“Business Source License” is a trademark of MariaDB plc.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@directus/storage-driver-azure",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "10.0.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Azure file storage abstraction for `@directus/storage`",
|
|
6
6
|
"repository": {
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"directory": "packages/storage-driver-azure"
|
|
10
10
|
},
|
|
11
11
|
"funding": "https://github.com/directus/directus?sponsor=1",
|
|
12
|
-
"license": "
|
|
12
|
+
"license": "BUSL-1.1",
|
|
13
13
|
"author": "Rijk van Zanten <rijkvanzanten@me.com>",
|
|
14
14
|
"exports": {
|
|
15
15
|
".": "./dist/index.js",
|
|
@@ -17,26 +17,25 @@
|
|
|
17
17
|
},
|
|
18
18
|
"main": "dist/index.js",
|
|
19
19
|
"files": [
|
|
20
|
-
"dist"
|
|
21
|
-
"!**/*.d.ts?(.map)"
|
|
20
|
+
"dist"
|
|
22
21
|
],
|
|
23
22
|
"publishConfig": {
|
|
24
23
|
"access": "public"
|
|
25
24
|
},
|
|
26
25
|
"dependencies": {
|
|
27
26
|
"@azure/storage-blob": "12.14.0",
|
|
28
|
-
"@directus/storage": "
|
|
29
|
-
"@directus/utils": "
|
|
27
|
+
"@directus/storage": "10.0.1",
|
|
28
|
+
"@directus/utils": "10.0.1"
|
|
30
29
|
},
|
|
31
30
|
"devDependencies": {
|
|
32
31
|
"@directus/tsconfig": "0.0.7",
|
|
33
32
|
"@ngneat/falso": "6.4.0",
|
|
34
|
-
"@vitest/coverage-c8": "0.
|
|
33
|
+
"@vitest/coverage-c8": "0.31.0",
|
|
35
34
|
"typescript": "5.0.4",
|
|
36
|
-
"vitest": "0.
|
|
35
|
+
"vitest": "0.31.0"
|
|
37
36
|
},
|
|
38
37
|
"scripts": {
|
|
39
|
-
"build": "tsc --
|
|
38
|
+
"build": "tsc --project tsconfig.prod.json",
|
|
40
39
|
"dev": "tsc --watch",
|
|
41
40
|
"test": "vitest --watch=false"
|
|
42
41
|
}
|
package/dist/index.test.js
DELETED
|
@@ -1,373 +0,0 @@
|
|
|
1
|
-
import { BlobServiceClient, StorageSharedKeyCredential } from '@azure/storage-blob';
|
|
2
|
-
import { normalizePath } from '@directus/utils';
|
|
3
|
-
import { isReadableStream } from '@directus/utils/node';
|
|
4
|
-
import { join } from 'node:path';
|
|
5
|
-
import { PassThrough } from 'node:stream';
|
|
6
|
-
import { afterEach, describe, expect, test, vi, beforeEach } from 'vitest';
|
|
7
|
-
import { DriverAzure } from './index.js';
|
|
8
|
-
import { randAlphaNumeric, randDirectoryPath, randDomainName, randFilePath, randGitBranch as randContainer, randNumber, randPastDate, randWord, randText, randFileType, randUrl, randGitShortSha as randUnique, } from '@ngneat/falso';
|
|
9
|
-
vi.mock('@directus/utils/node');
|
|
10
|
-
vi.mock('@directus/utils');
|
|
11
|
-
vi.mock('@azure/storage-blob');
|
|
12
|
-
vi.mock('node:path');
|
|
13
|
-
let sample;
|
|
14
|
-
let driver;
|
|
15
|
-
beforeEach(() => {
|
|
16
|
-
sample = {
|
|
17
|
-
config: {
|
|
18
|
-
containerName: randContainer(),
|
|
19
|
-
accountName: randWord(),
|
|
20
|
-
accountKey: randAlphaNumeric({ length: 40 }).join(''),
|
|
21
|
-
root: randDirectoryPath(),
|
|
22
|
-
endpoint: `https://${randDomainName()}`,
|
|
23
|
-
},
|
|
24
|
-
path: {
|
|
25
|
-
input: randUnique() + randFilePath(),
|
|
26
|
-
inputFull: randUnique() + randFilePath(),
|
|
27
|
-
src: randUnique() + randFilePath(),
|
|
28
|
-
srcFull: randUnique() + randFilePath(),
|
|
29
|
-
dest: randUnique() + randFilePath(),
|
|
30
|
-
destFull: randUnique() + randFilePath(),
|
|
31
|
-
},
|
|
32
|
-
range: {
|
|
33
|
-
start: randNumber(),
|
|
34
|
-
end: randNumber(),
|
|
35
|
-
},
|
|
36
|
-
stream: new PassThrough(),
|
|
37
|
-
text: randText(),
|
|
38
|
-
file: {
|
|
39
|
-
type: randFileType(),
|
|
40
|
-
size: randNumber(),
|
|
41
|
-
modified: randPastDate(),
|
|
42
|
-
},
|
|
43
|
-
};
|
|
44
|
-
driver = new DriverAzure({
|
|
45
|
-
containerName: sample.config.containerName,
|
|
46
|
-
accountKey: sample.config.accountKey,
|
|
47
|
-
accountName: sample.config.accountName,
|
|
48
|
-
});
|
|
49
|
-
driver['fullPath'] = vi.fn().mockImplementation((input) => {
|
|
50
|
-
if (input === sample.path.src)
|
|
51
|
-
return sample.path.srcFull;
|
|
52
|
-
if (input === sample.path.dest)
|
|
53
|
-
return sample.path.destFull;
|
|
54
|
-
if (input === sample.path.input)
|
|
55
|
-
return sample.path.inputFull;
|
|
56
|
-
return '';
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
afterEach(() => {
|
|
60
|
-
vi.resetAllMocks();
|
|
61
|
-
});
|
|
62
|
-
describe('#constructor', () => {
|
|
63
|
-
test('Creates signed credentials', () => {
|
|
64
|
-
expect(StorageSharedKeyCredential).toHaveBeenCalledWith(sample.config.accountName, sample.config.accountKey);
|
|
65
|
-
expect(driver['signedCredentials']).toBeInstanceOf(StorageSharedKeyCredential);
|
|
66
|
-
});
|
|
67
|
-
test('Creates blob service client and sets containerClient', () => {
|
|
68
|
-
const mockSignedCredentials = {};
|
|
69
|
-
vi.mocked(StorageSharedKeyCredential).mockReturnValueOnce(mockSignedCredentials);
|
|
70
|
-
const mockContainerClient = {};
|
|
71
|
-
const mockBlobServiceClient = {
|
|
72
|
-
getContainerClient: vi.fn().mockReturnValue(mockContainerClient),
|
|
73
|
-
};
|
|
74
|
-
vi.mocked(BlobServiceClient).mockReturnValue(mockBlobServiceClient);
|
|
75
|
-
const driver = new DriverAzure({
|
|
76
|
-
containerName: sample.config.containerName,
|
|
77
|
-
accountName: sample.config.accountName,
|
|
78
|
-
accountKey: sample.config.accountKey,
|
|
79
|
-
});
|
|
80
|
-
expect(BlobServiceClient).toHaveBeenCalledWith(`https://${sample.config.accountName}.blob.core.windows.net`, mockSignedCredentials);
|
|
81
|
-
expect(mockBlobServiceClient.getContainerClient).toHaveBeenCalledWith(sample.config.containerName);
|
|
82
|
-
expect(driver['containerClient']).toBe(mockContainerClient);
|
|
83
|
-
});
|
|
84
|
-
test('Allows overriding endpoint with optional setting', () => {
|
|
85
|
-
test('Creates blob service client and sets containerClient', () => {
|
|
86
|
-
const mockSignedCredentials = {};
|
|
87
|
-
vi.mocked(StorageSharedKeyCredential).mockReturnValueOnce(mockSignedCredentials);
|
|
88
|
-
const mockContainerClient = {};
|
|
89
|
-
const mockBlobServiceClient = {
|
|
90
|
-
getContainerClient: vi.fn().mockReturnValue(mockContainerClient),
|
|
91
|
-
};
|
|
92
|
-
vi.mocked(BlobServiceClient).mockReturnValue(mockBlobServiceClient);
|
|
93
|
-
const driver = new DriverAzure({
|
|
94
|
-
containerName: sample.config.containerName,
|
|
95
|
-
accountName: sample.config.accountName,
|
|
96
|
-
accountKey: sample.config.accountKey,
|
|
97
|
-
endpoint: sample.config.endpoint,
|
|
98
|
-
});
|
|
99
|
-
expect(BlobServiceClient).toHaveBeenCalledWith(sample.config.endpoint, mockSignedCredentials);
|
|
100
|
-
expect(mockBlobServiceClient.getContainerClient).toHaveBeenCalledWith(sample.config.containerName);
|
|
101
|
-
expect(driver['containerClient']).toBe(mockContainerClient);
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
test('Defaults root path to empty string', () => {
|
|
105
|
-
expect(driver['root']).toBe('');
|
|
106
|
-
});
|
|
107
|
-
test('Normalizes config path when root is given', () => {
|
|
108
|
-
vi.mocked(normalizePath).mockReturnValue(sample.path.inputFull);
|
|
109
|
-
new DriverAzure({
|
|
110
|
-
containerName: sample.config.containerName,
|
|
111
|
-
accountName: sample.config.accountName,
|
|
112
|
-
accountKey: sample.config.accountKey,
|
|
113
|
-
root: sample.path.input,
|
|
114
|
-
});
|
|
115
|
-
expect(normalizePath).toHaveBeenCalledWith(sample.path.input, { removeLeading: true });
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
describe('#fullPath', () => {
|
|
119
|
-
test('Returns normalized joined path', () => {
|
|
120
|
-
vi.mocked(join).mockReturnValue(sample.path.inputFull);
|
|
121
|
-
vi.mocked(normalizePath).mockReturnValue(sample.path.inputFull);
|
|
122
|
-
const driver = new DriverAzure({
|
|
123
|
-
containerName: sample.config.containerName,
|
|
124
|
-
accountName: sample.config.accountName,
|
|
125
|
-
accountKey: sample.config.accountKey,
|
|
126
|
-
});
|
|
127
|
-
driver['root'] = sample.config.root;
|
|
128
|
-
const result = driver['fullPath'](sample.path.input);
|
|
129
|
-
expect(join).toHaveBeenCalledWith(sample.config.root, sample.path.input);
|
|
130
|
-
expect(normalizePath).toHaveBeenCalledWith(sample.path.inputFull);
|
|
131
|
-
expect(result).toBe(sample.path.inputFull);
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
describe('#read', () => {
|
|
135
|
-
let mockDownload;
|
|
136
|
-
beforeEach(async () => {
|
|
137
|
-
mockDownload = vi.fn().mockResolvedValue({ readableStreamBody: sample.stream });
|
|
138
|
-
const mockBlobClient = vi.fn().mockReturnValue({
|
|
139
|
-
download: mockDownload,
|
|
140
|
-
});
|
|
141
|
-
driver['containerClient'] = {
|
|
142
|
-
getBlobClient: mockBlobClient,
|
|
143
|
-
};
|
|
144
|
-
});
|
|
145
|
-
test('Uses blobClient at full path', async () => {
|
|
146
|
-
await driver.read(sample.path.input);
|
|
147
|
-
expect(driver['fullPath']).toHaveBeenCalledWith(sample.path.input);
|
|
148
|
-
expect(driver['containerClient'].getBlobClient).toHaveBeenCalledWith(sample.path.inputFull);
|
|
149
|
-
});
|
|
150
|
-
test('Calls download with undefined undefined when no range is passed', async () => {
|
|
151
|
-
await driver.read(sample.path.input);
|
|
152
|
-
expect(mockDownload).toHaveBeenCalledWith(undefined, undefined);
|
|
153
|
-
});
|
|
154
|
-
test('Calls download with offset if start range is provided', async () => {
|
|
155
|
-
await driver.read(sample.path.input, { start: sample.range.start });
|
|
156
|
-
expect(mockDownload).toHaveBeenCalledWith(sample.range.start, undefined);
|
|
157
|
-
});
|
|
158
|
-
test('Calls download with count if end range is provided', async () => {
|
|
159
|
-
await driver.read(sample.path.input, { end: sample.range.end });
|
|
160
|
-
expect(mockDownload).toHaveBeenCalledWith(undefined, sample.range.end);
|
|
161
|
-
});
|
|
162
|
-
test('Calls download with offset and count if start and end ranges are provided', async () => {
|
|
163
|
-
await driver.read(sample.path.input, sample.range);
|
|
164
|
-
expect(mockDownload).toHaveBeenCalledWith(sample.range.start, sample.range.end - sample.range.start);
|
|
165
|
-
});
|
|
166
|
-
test('Throws error when no readable stream is returned', async () => {
|
|
167
|
-
mockDownload.mockResolvedValue({ readableStreamBody: undefined });
|
|
168
|
-
try {
|
|
169
|
-
await driver.read(sample.path.input);
|
|
170
|
-
}
|
|
171
|
-
catch (err) {
|
|
172
|
-
expect(err).toBeInstanceOf(Error);
|
|
173
|
-
expect(err.message).toBe(`No stream returned for file "${sample.path.input}"`);
|
|
174
|
-
}
|
|
175
|
-
});
|
|
176
|
-
});
|
|
177
|
-
describe('#write', () => {
|
|
178
|
-
let mockUploadStream;
|
|
179
|
-
let mockBlockBlobClient;
|
|
180
|
-
beforeEach(() => {
|
|
181
|
-
mockUploadStream = vi.fn();
|
|
182
|
-
mockBlockBlobClient = vi.fn().mockReturnValue({
|
|
183
|
-
uploadStream: mockUploadStream,
|
|
184
|
-
});
|
|
185
|
-
driver['containerClient'] = {
|
|
186
|
-
getBlockBlobClient: mockBlockBlobClient,
|
|
187
|
-
};
|
|
188
|
-
vi.mocked(isReadableStream).mockReturnValue(true);
|
|
189
|
-
});
|
|
190
|
-
test('Gets BlockBlobClient for file path', async () => {
|
|
191
|
-
await driver.write(sample.path.input, sample.stream);
|
|
192
|
-
expect(mockBlockBlobClient).toHaveBeenCalledWith(sample.path.inputFull);
|
|
193
|
-
});
|
|
194
|
-
test('Uploads stream through uploadStream', async () => {
|
|
195
|
-
await driver.write(sample.path.input, sample.stream);
|
|
196
|
-
expect(mockUploadStream).toHaveBeenCalledWith(sample.stream, undefined, undefined, {
|
|
197
|
-
blobHTTPHeaders: { blobContentType: 'application/octet-stream' },
|
|
198
|
-
});
|
|
199
|
-
});
|
|
200
|
-
test('Allows optional mime type to be set', async () => {
|
|
201
|
-
await driver.write(sample.path.input, sample.stream, sample.file.type);
|
|
202
|
-
expect(mockUploadStream).toHaveBeenCalledWith(sample.stream, undefined, undefined, {
|
|
203
|
-
blobHTTPHeaders: { blobContentType: sample.file.type },
|
|
204
|
-
});
|
|
205
|
-
});
|
|
206
|
-
});
|
|
207
|
-
describe('#delete', () => {
|
|
208
|
-
let mockDeleteIfExists;
|
|
209
|
-
beforeEach(() => {
|
|
210
|
-
mockDeleteIfExists = vi.fn().mockResolvedValue(true);
|
|
211
|
-
const mockBlockBlobClient = vi.fn().mockReturnValue({
|
|
212
|
-
deleteIfExists: mockDeleteIfExists,
|
|
213
|
-
});
|
|
214
|
-
driver['containerClient'] = {
|
|
215
|
-
getBlockBlobClient: mockBlockBlobClient,
|
|
216
|
-
};
|
|
217
|
-
});
|
|
218
|
-
test('Uses blobClient at full path', async () => {
|
|
219
|
-
await driver.delete(sample.path.input);
|
|
220
|
-
expect(driver['fullPath']).toHaveBeenCalledWith(sample.path.input);
|
|
221
|
-
expect(driver['containerClient'].getBlockBlobClient).toHaveBeenCalledWith(sample.path.inputFull);
|
|
222
|
-
});
|
|
223
|
-
test('Returns delete result', async () => {
|
|
224
|
-
await driver.delete(sample.path.input);
|
|
225
|
-
expect(mockDeleteIfExists).toHaveBeenCalled();
|
|
226
|
-
});
|
|
227
|
-
});
|
|
228
|
-
describe('#stat', () => {
|
|
229
|
-
beforeEach(() => {
|
|
230
|
-
const mockGetProperties = vi.fn().mockReturnValue({
|
|
231
|
-
contentLength: sample.file.size,
|
|
232
|
-
lastModified: sample.file.modified,
|
|
233
|
-
});
|
|
234
|
-
const mockBlobClient = vi.fn().mockReturnValue({
|
|
235
|
-
getProperties: mockGetProperties,
|
|
236
|
-
});
|
|
237
|
-
driver['containerClient'] = {
|
|
238
|
-
getBlobClient: mockBlobClient,
|
|
239
|
-
};
|
|
240
|
-
});
|
|
241
|
-
test('Uses blobClient at full path', async () => {
|
|
242
|
-
await driver.stat(sample.path.input);
|
|
243
|
-
expect(driver['fullPath']).toHaveBeenCalledWith(sample.path.input);
|
|
244
|
-
expect(driver['containerClient'].getBlobClient).toHaveBeenCalledWith(sample.path.inputFull);
|
|
245
|
-
});
|
|
246
|
-
test('Returns contentLength/lastModified as size/modified from getProperties', async () => {
|
|
247
|
-
const result = await driver.stat(sample.path.input);
|
|
248
|
-
expect(result).toStrictEqual({
|
|
249
|
-
size: sample.file.size,
|
|
250
|
-
modified: sample.file.modified,
|
|
251
|
-
});
|
|
252
|
-
});
|
|
253
|
-
});
|
|
254
|
-
describe('#exists', () => {
|
|
255
|
-
let mockExists;
|
|
256
|
-
beforeEach(() => {
|
|
257
|
-
mockExists = vi.fn().mockResolvedValue(true);
|
|
258
|
-
const mockBlockBlobClient = vi.fn().mockReturnValue({
|
|
259
|
-
exists: mockExists,
|
|
260
|
-
});
|
|
261
|
-
driver['containerClient'] = {
|
|
262
|
-
getBlockBlobClient: mockBlockBlobClient,
|
|
263
|
-
};
|
|
264
|
-
});
|
|
265
|
-
test('Uses blobClient at full path', async () => {
|
|
266
|
-
await driver.exists(sample.path.input);
|
|
267
|
-
expect(driver['fullPath']).toHaveBeenCalledWith(sample.path.input);
|
|
268
|
-
expect(driver['containerClient'].getBlockBlobClient).toHaveBeenCalledWith(sample.path.inputFull);
|
|
269
|
-
});
|
|
270
|
-
test('Returns exists result', async () => {
|
|
271
|
-
const result = await driver.exists(sample.path.input);
|
|
272
|
-
expect(mockExists).toHaveBeenCalled();
|
|
273
|
-
expect(result).toBe(true);
|
|
274
|
-
});
|
|
275
|
-
});
|
|
276
|
-
describe('#move', () => {
|
|
277
|
-
let mockDeleteIfExists;
|
|
278
|
-
let mockBlockBlobClient;
|
|
279
|
-
beforeEach(() => {
|
|
280
|
-
mockDeleteIfExists = vi.fn();
|
|
281
|
-
mockBlockBlobClient = vi.fn().mockReturnValue({
|
|
282
|
-
deleteIfExists: mockDeleteIfExists,
|
|
283
|
-
});
|
|
284
|
-
driver['containerClient'] = {
|
|
285
|
-
getBlockBlobClient: mockBlockBlobClient,
|
|
286
|
-
};
|
|
287
|
-
driver.copy = vi.fn();
|
|
288
|
-
});
|
|
289
|
-
test('Calls #copy with src and dest', async () => {
|
|
290
|
-
await driver.move(sample.path.src, sample.path.dest);
|
|
291
|
-
expect(driver.copy).toHaveBeenCalledWith(sample.path.src, sample.path.dest);
|
|
292
|
-
});
|
|
293
|
-
test('Deletes src file after copy is completed', async () => {
|
|
294
|
-
await driver.move(sample.path.src, sample.path.dest);
|
|
295
|
-
expect(driver['fullPath']).toHaveBeenCalledWith(sample.path.src);
|
|
296
|
-
expect(mockBlockBlobClient).toHaveBeenCalledWith(sample.path.srcFull);
|
|
297
|
-
expect(mockDeleteIfExists).toHaveBeenCalledOnce();
|
|
298
|
-
});
|
|
299
|
-
});
|
|
300
|
-
describe('#copy', () => {
|
|
301
|
-
let mockPollUntilDone;
|
|
302
|
-
let mockBeginCopyFromUrl;
|
|
303
|
-
let mockBlockBlobClient;
|
|
304
|
-
let mockUrl;
|
|
305
|
-
beforeEach(() => {
|
|
306
|
-
mockPollUntilDone = vi.fn();
|
|
307
|
-
mockBeginCopyFromUrl = vi.fn().mockResolvedValue({
|
|
308
|
-
pollUntilDone: mockPollUntilDone,
|
|
309
|
-
});
|
|
310
|
-
mockUrl = randUrl();
|
|
311
|
-
mockBlockBlobClient = vi
|
|
312
|
-
.fn()
|
|
313
|
-
.mockReturnValueOnce({
|
|
314
|
-
url: mockUrl,
|
|
315
|
-
})
|
|
316
|
-
.mockReturnValueOnce({
|
|
317
|
-
beginCopyFromURL: mockBeginCopyFromUrl,
|
|
318
|
-
});
|
|
319
|
-
driver['containerClient'] = {
|
|
320
|
-
getBlockBlobClient: mockBlockBlobClient,
|
|
321
|
-
};
|
|
322
|
-
});
|
|
323
|
-
test('Gets BlockBlobClient for src and dest', async () => {
|
|
324
|
-
await driver.copy(sample.path.src, sample.path.dest);
|
|
325
|
-
expect(driver['fullPath']).toHaveBeenCalledTimes(2);
|
|
326
|
-
expect(driver['fullPath']).toHaveBeenCalledWith(sample.path.src);
|
|
327
|
-
expect(driver['fullPath']).toHaveBeenCalledWith(sample.path.dest);
|
|
328
|
-
expect(mockBlockBlobClient).toHaveBeenCalledTimes(2);
|
|
329
|
-
expect(mockBlockBlobClient).toHaveBeenCalledWith(sample.path.srcFull);
|
|
330
|
-
expect(mockBlockBlobClient).toHaveBeenCalledWith(sample.path.destFull);
|
|
331
|
-
});
|
|
332
|
-
test('Calls beginCopyFromUrl with source url', async () => {
|
|
333
|
-
await driver.copy(sample.path.src, sample.path.dest);
|
|
334
|
-
expect(mockBeginCopyFromUrl).toHaveBeenCalledOnce();
|
|
335
|
-
expect(mockBeginCopyFromUrl).toHaveBeenCalledWith(mockUrl);
|
|
336
|
-
});
|
|
337
|
-
test('Waits for the polling to be done', async () => {
|
|
338
|
-
await driver.copy(sample.path.src, sample.path.dest);
|
|
339
|
-
expect(mockPollUntilDone).toHaveBeenCalledOnce();
|
|
340
|
-
});
|
|
341
|
-
});
|
|
342
|
-
describe('#list', () => {
|
|
343
|
-
let mockListBlobsFlat;
|
|
344
|
-
beforeEach(() => {
|
|
345
|
-
mockListBlobsFlat = vi.fn().mockReturnValue([]);
|
|
346
|
-
driver['containerClient'] = {
|
|
347
|
-
listBlobsFlat: mockListBlobsFlat,
|
|
348
|
-
};
|
|
349
|
-
});
|
|
350
|
-
test('Uses listBlobsFlat at default empty path', async () => {
|
|
351
|
-
await driver.list().next();
|
|
352
|
-
expect(driver['fullPath']).toHaveBeenCalledWith('');
|
|
353
|
-
expect(mockListBlobsFlat).toHaveBeenCalledWith({
|
|
354
|
-
prefix: '',
|
|
355
|
-
});
|
|
356
|
-
});
|
|
357
|
-
test('Allows for optional prefix', async () => {
|
|
358
|
-
await driver.list(sample.path.input).next();
|
|
359
|
-
expect(driver['fullPath']).toHaveBeenCalledWith(sample.path.input);
|
|
360
|
-
expect(mockListBlobsFlat).toHaveBeenCalledWith({
|
|
361
|
-
prefix: sample.path.inputFull,
|
|
362
|
-
});
|
|
363
|
-
});
|
|
364
|
-
test('Returns blob.name for each returned blob', async () => {
|
|
365
|
-
const mockFile = randFilePath();
|
|
366
|
-
mockListBlobsFlat.mockReturnValue([{ name: mockFile }]);
|
|
367
|
-
const output = [];
|
|
368
|
-
for await (const filepath of driver.list()) {
|
|
369
|
-
output.push(filepath);
|
|
370
|
-
}
|
|
371
|
-
expect(output).toStrictEqual([mockFile]);
|
|
372
|
-
});
|
|
373
|
-
});
|