@directus/storage-driver-azure 12.0.8 → 12.0.9

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 CHANGED
@@ -1,40 +1,41 @@
1
- import { TusDriver } from '@directus/storage';
2
- import { ReadOptions, ChunkedUploadContext } from '@directus/types';
3
- import { Readable } from 'node:stream';
1
+ import { TusDriver } from "@directus/storage";
2
+ import { ChunkedUploadContext, ReadOptions } from "@directus/types";
3
+ import { Readable } from "node:stream";
4
4
 
5
+ //#region src/index.d.ts
5
6
  type DriverAzureConfig = {
6
- containerName: string;
7
- accountName: string;
8
- accountKey: string;
9
- root?: string;
10
- endpoint?: string;
11
- tus?: {
12
- enabled: boolean;
13
- chunkSize?: number;
14
- };
7
+ containerName: string;
8
+ accountName: string;
9
+ accountKey: string;
10
+ root?: string;
11
+ endpoint?: string;
12
+ tus?: {
13
+ enabled: boolean;
14
+ chunkSize?: number;
15
+ };
15
16
  };
16
17
  declare class DriverAzure implements TusDriver {
17
- private containerClient;
18
- private signedCredentials;
19
- private root;
20
- constructor(config: DriverAzureConfig);
21
- private fullPath;
22
- read(filepath: string, options?: ReadOptions): Promise<Readable>;
23
- write(filepath: string, content: Readable, type?: string): Promise<void>;
24
- delete(filepath: string): Promise<void>;
25
- stat(filepath: string): Promise<{
26
- size: number;
27
- modified: Date;
28
- }>;
29
- exists(filepath: string): Promise<boolean>;
30
- move(src: string, dest: string): Promise<void>;
31
- copy(src: string, dest: string): Promise<void>;
32
- list(prefix?: string): AsyncGenerator<string, void, unknown>;
33
- get tusExtensions(): string[];
34
- createChunkedUpload(filepath: string, context: ChunkedUploadContext): Promise<ChunkedUploadContext>;
35
- writeChunk(filepath: string, content: Readable, offset: number, _context: ChunkedUploadContext): Promise<number>;
36
- finishChunkedUpload(_filepath: string, _context: ChunkedUploadContext): Promise<void>;
37
- deleteChunkedUpload(filepath: string, _context: ChunkedUploadContext): Promise<void>;
18
+ private containerClient;
19
+ private signedCredentials;
20
+ private root;
21
+ constructor(config: DriverAzureConfig);
22
+ private fullPath;
23
+ read(filepath: string, options?: ReadOptions): Promise<Readable>;
24
+ write(filepath: string, content: Readable, type?: string): Promise<void>;
25
+ delete(filepath: string): Promise<void>;
26
+ stat(filepath: string): Promise<{
27
+ size: number;
28
+ modified: Date;
29
+ }>;
30
+ exists(filepath: string): Promise<boolean>;
31
+ move(src: string, dest: string): Promise<void>;
32
+ copy(src: string, dest: string): Promise<void>;
33
+ list(prefix?: string): AsyncGenerator<string, void, unknown>;
34
+ get tusExtensions(): string[];
35
+ createChunkedUpload(filepath: string, context: ChunkedUploadContext): Promise<ChunkedUploadContext>;
36
+ writeChunk(filepath: string, content: Readable, offset: number, _context: ChunkedUploadContext): Promise<number>;
37
+ finishChunkedUpload(_filepath: string, _context: ChunkedUploadContext): Promise<void>;
38
+ deleteChunkedUpload(filepath: string, _context: ChunkedUploadContext): Promise<void>;
38
39
  }
39
-
40
- export { DriverAzure, type DriverAzureConfig, DriverAzure as default };
40
+ //#endregion
41
+ export { DriverAzure, DriverAzure as default, DriverAzureConfig };
package/dist/index.js CHANGED
@@ -1,103 +1,87 @@
1
- // src/index.ts
2
1
  import { BlobServiceClient, StorageSharedKeyCredential } from "@azure/storage-blob";
3
2
  import { normalizePath } from "@directus/utils";
4
- import { join } from "path";
5
- import { finished } from "stream/promises";
6
- var MAXIMUM_CHUNK_SIZE = 104857600;
3
+ import { join } from "node:path";
4
+ import { finished } from "node:stream/promises";
5
+
6
+ //#region src/index.ts
7
+ const MAXIMUM_CHUNK_SIZE = 104857600;
7
8
  var DriverAzure = class {
8
- containerClient;
9
- signedCredentials;
10
- root;
11
- constructor(config) {
12
- this.signedCredentials = new StorageSharedKeyCredential(config.accountName, config.accountKey);
13
- const client = new BlobServiceClient(
14
- config.endpoint ?? `https://${config.accountName}.blob.core.windows.net`,
15
- this.signedCredentials
16
- );
17
- this.containerClient = client.getContainerClient(config.containerName);
18
- this.root = config.root ? normalizePath(config.root, { removeLeading: true }) : "";
19
- if (config.tus?.enabled && config.tus.chunkSize && config.tus.chunkSize > MAXIMUM_CHUNK_SIZE) {
20
- throw new Error("Invalid chunkSize provided");
21
- }
22
- }
23
- fullPath(filepath) {
24
- return normalizePath(join(this.root, filepath));
25
- }
26
- async read(filepath, options) {
27
- const { range } = options || {};
28
- const { readableStreamBody } = await this.containerClient.getBlobClient(this.fullPath(filepath)).download(range?.start, range?.end ? range.end - (range.start || 0) + 1 : void 0);
29
- if (!readableStreamBody) {
30
- throw new Error(`No stream returned for file "${filepath}"`);
31
- }
32
- return readableStreamBody;
33
- }
34
- async write(filepath, content, type = "application/octet-stream") {
35
- const blockBlobClient = this.containerClient.getBlockBlobClient(this.fullPath(filepath));
36
- await blockBlobClient.uploadStream(content, void 0, void 0, {
37
- blobHTTPHeaders: { blobContentType: type }
38
- });
39
- }
40
- async delete(filepath) {
41
- await this.containerClient.getBlockBlobClient(this.fullPath(filepath)).deleteIfExists();
42
- }
43
- async stat(filepath) {
44
- const props = await this.containerClient.getBlobClient(this.fullPath(filepath)).getProperties();
45
- return {
46
- size: props.contentLength,
47
- modified: props.lastModified
48
- };
49
- }
50
- async exists(filepath) {
51
- return await this.containerClient.getBlockBlobClient(this.fullPath(filepath)).exists();
52
- }
53
- async move(src, dest) {
54
- await this.copy(src, dest);
55
- await this.containerClient.getBlockBlobClient(this.fullPath(src)).deleteIfExists();
56
- }
57
- async copy(src, dest) {
58
- const source = this.containerClient.getBlockBlobClient(this.fullPath(src));
59
- const target = this.containerClient.getBlockBlobClient(this.fullPath(dest));
60
- const poller = await target.beginCopyFromURL(source.url);
61
- await poller.pollUntilDone();
62
- }
63
- async *list(prefix = "") {
64
- const blobs = this.containerClient.listBlobsFlat({
65
- prefix: this.fullPath(prefix)
66
- });
67
- for await (const blob of blobs) {
68
- yield blob.name.substring(this.root.length);
69
- }
70
- }
71
- get tusExtensions() {
72
- return ["creation", "termination", "expiration"];
73
- }
74
- async createChunkedUpload(filepath, context) {
75
- await this.containerClient.getAppendBlobClient(this.fullPath(filepath)).createIfNotExists();
76
- return context;
77
- }
78
- async writeChunk(filepath, content, offset, _context) {
79
- const client = this.containerClient.getAppendBlobClient(this.fullPath(filepath));
80
- let bytesUploaded = offset || 0;
81
- const chunks = [];
82
- content.on("data", (chunk2) => {
83
- bytesUploaded += chunk2.length;
84
- chunks.push(chunk2);
85
- });
86
- await finished(content);
87
- const chunk = Buffer.concat(chunks);
88
- if (chunk.length > 0) {
89
- await client.appendBlock(chunk, chunk.length);
90
- }
91
- return bytesUploaded;
92
- }
93
- async finishChunkedUpload(_filepath, _context) {
94
- }
95
- async deleteChunkedUpload(filepath, _context) {
96
- await this.delete(filepath);
97
- }
98
- };
99
- var index_default = DriverAzure;
100
- export {
101
- DriverAzure,
102
- index_default as default
9
+ containerClient;
10
+ signedCredentials;
11
+ root;
12
+ constructor(config) {
13
+ this.signedCredentials = new StorageSharedKeyCredential(config.accountName, config.accountKey);
14
+ this.containerClient = new BlobServiceClient(config.endpoint ?? `https://${config.accountName}.blob.core.windows.net`, this.signedCredentials).getContainerClient(config.containerName);
15
+ this.root = config.root ? normalizePath(config.root, { removeLeading: true }) : "";
16
+ if (config.tus?.enabled && config.tus.chunkSize && config.tus.chunkSize > MAXIMUM_CHUNK_SIZE) throw new Error("Invalid chunkSize provided");
17
+ }
18
+ fullPath(filepath) {
19
+ return normalizePath(join(this.root, filepath));
20
+ }
21
+ async read(filepath, options) {
22
+ const { range } = options || {};
23
+ const { readableStreamBody } = await this.containerClient.getBlobClient(this.fullPath(filepath)).download(range?.start, range?.end ? range.end - (range.start || 0) + 1 : void 0);
24
+ if (!readableStreamBody) throw new Error(`No stream returned for file "${filepath}"`);
25
+ return readableStreamBody;
26
+ }
27
+ async write(filepath, content, type = "application/octet-stream") {
28
+ await this.containerClient.getBlockBlobClient(this.fullPath(filepath)).uploadStream(content, void 0, void 0, { blobHTTPHeaders: { blobContentType: type } });
29
+ }
30
+ async delete(filepath) {
31
+ await this.containerClient.getBlockBlobClient(this.fullPath(filepath)).deleteIfExists();
32
+ }
33
+ async stat(filepath) {
34
+ const props = await this.containerClient.getBlobClient(this.fullPath(filepath)).getProperties();
35
+ return {
36
+ size: props.contentLength,
37
+ modified: props.lastModified
38
+ };
39
+ }
40
+ async exists(filepath) {
41
+ return await this.containerClient.getBlockBlobClient(this.fullPath(filepath)).exists();
42
+ }
43
+ async move(src, dest) {
44
+ await this.copy(src, dest);
45
+ await this.containerClient.getBlockBlobClient(this.fullPath(src)).deleteIfExists();
46
+ }
47
+ async copy(src, dest) {
48
+ const source = this.containerClient.getBlockBlobClient(this.fullPath(src));
49
+ await (await this.containerClient.getBlockBlobClient(this.fullPath(dest)).beginCopyFromURL(source.url)).pollUntilDone();
50
+ }
51
+ async *list(prefix = "") {
52
+ const blobs = this.containerClient.listBlobsFlat({ prefix: this.fullPath(prefix) });
53
+ for await (const blob of blobs) yield blob.name.substring(this.root.length);
54
+ }
55
+ get tusExtensions() {
56
+ return [
57
+ "creation",
58
+ "termination",
59
+ "expiration"
60
+ ];
61
+ }
62
+ async createChunkedUpload(filepath, context) {
63
+ await this.containerClient.getAppendBlobClient(this.fullPath(filepath)).createIfNotExists();
64
+ return context;
65
+ }
66
+ async writeChunk(filepath, content, offset, _context) {
67
+ const client = this.containerClient.getAppendBlobClient(this.fullPath(filepath));
68
+ let bytesUploaded = offset || 0;
69
+ const chunks = [];
70
+ content.on("data", (chunk$1) => {
71
+ bytesUploaded += chunk$1.length;
72
+ chunks.push(chunk$1);
73
+ });
74
+ await finished(content);
75
+ const chunk = Buffer.concat(chunks);
76
+ if (chunk.length > 0) await client.appendBlock(chunk, chunk.length);
77
+ return bytesUploaded;
78
+ }
79
+ async finishChunkedUpload(_filepath, _context) {}
80
+ async deleteChunkedUpload(filepath, _context) {
81
+ await this.delete(filepath);
82
+ }
103
83
  };
84
+ var src_default = DriverAzure;
85
+
86
+ //#endregion
87
+ export { DriverAzure, src_default as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@directus/storage-driver-azure",
3
- "version": "12.0.8",
3
+ "version": "12.0.9",
4
4
  "description": "Azure file storage abstraction for `@directus/storage`",
5
5
  "homepage": "https://directus.io",
6
6
  "repository": {
@@ -22,21 +22,21 @@
22
22
  ],
23
23
  "dependencies": {
24
24
  "@azure/storage-blob": "12.28.0",
25
- "@directus/storage": "12.0.1",
26
- "@directus/utils": "13.0.9"
25
+ "@directus/storage": "12.0.2",
26
+ "@directus/utils": "13.0.10"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@directus/tsconfig": "3.0.0",
30
30
  "@ngneat/falso": "8.0.2",
31
31
  "@vitest/coverage-v8": "3.2.4",
32
- "tsup": "8.5.0",
32
+ "tsdown": "0.14.2",
33
33
  "typescript": "5.8.3",
34
34
  "vitest": "3.2.4",
35
- "@directus/types": "13.2.1"
35
+ "@directus/types": "13.2.3"
36
36
  },
37
37
  "scripts": {
38
- "build": "tsup src/index.ts --format=esm --dts",
39
- "dev": "tsup src/index.ts --format=esm --dts --watch",
38
+ "build": "tsdown src/index.ts --dts",
39
+ "dev": "tsdown src/index.ts --dts --watch",
40
40
  "test": "vitest run",
41
41
  "test:coverage": "vitest run --coverage"
42
42
  }