@directus/storage-driver-gcs 10.0.10 → 10.0.12

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,12 +1,12 @@
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 DriverGCSConfig = {
1
+ import { Driver, Range } from '@directus/storage';
2
+ import { Readable } from 'node:stream';
3
+
4
+ type DriverGCSConfig = {
5
5
  root?: string;
6
6
  bucket: string;
7
7
  apiEndpoint?: string;
8
8
  };
9
- export declare class DriverGCS implements Driver {
9
+ declare class DriverGCS implements Driver {
10
10
  private root;
11
11
  private bucket;
12
12
  constructor(config: DriverGCSConfig);
@@ -24,4 +24,5 @@ export declare class DriverGCS implements Driver {
24
24
  copy(src: string, dest: string): Promise<void>;
25
25
  list(prefix?: string): AsyncGenerator<string, void, unknown>;
26
26
  }
27
- export default DriverGCS;
27
+
28
+ export { DriverGCS, DriverGCSConfig, DriverGCS as default };
package/dist/index.js CHANGED
@@ -1,64 +1,69 @@
1
- import { normalizePath } from '@directus/utils';
2
- import { Storage } from '@google-cloud/storage';
3
- import { join } from 'node:path';
4
- import { pipeline } from 'node:stream/promises';
5
- export class DriverGCS {
6
- root;
7
- bucket;
8
- constructor(config) {
9
- const { bucket, root, ...storageOptions } = config;
10
- this.root = root ? normalizePath(root, { removeLeading: true }) : '';
11
- const storage = new Storage(storageOptions);
12
- this.bucket = storage.bucket(bucket);
1
+ // src/index.ts
2
+ import { normalizePath } from "@directus/utils";
3
+ import { Storage } from "@google-cloud/storage";
4
+ import { join } from "path";
5
+ import { pipeline } from "stream/promises";
6
+ var DriverGCS = class {
7
+ root;
8
+ bucket;
9
+ constructor(config) {
10
+ const { bucket, root, ...storageOptions } = config;
11
+ this.root = root ? normalizePath(root, { removeLeading: true }) : "";
12
+ const storage = new Storage(storageOptions);
13
+ this.bucket = storage.bucket(bucket);
14
+ }
15
+ fullPath(filepath) {
16
+ return normalizePath(join(this.root, filepath));
17
+ }
18
+ file(filepath) {
19
+ return this.bucket.file(filepath);
20
+ }
21
+ async read(filepath, range) {
22
+ const options = {};
23
+ if (range?.start)
24
+ options.start = range.start;
25
+ if (range?.end)
26
+ options.end = range.end;
27
+ return this.file(this.fullPath(filepath)).createReadStream(options);
28
+ }
29
+ async write(filepath, content) {
30
+ const file = this.file(this.fullPath(filepath));
31
+ const stream = file.createWriteStream({ resumable: false });
32
+ await pipeline(content, stream);
33
+ }
34
+ async delete(filepath) {
35
+ await this.file(this.fullPath(filepath)).delete();
36
+ }
37
+ async stat(filepath) {
38
+ const [{ size, updated }] = await this.file(this.fullPath(filepath)).getMetadata();
39
+ return { size, modified: updated };
40
+ }
41
+ async exists(filepath) {
42
+ return (await this.file(this.fullPath(filepath)).exists())[0];
43
+ }
44
+ async move(src, dest) {
45
+ await this.file(this.fullPath(src)).move(this.file(this.fullPath(dest)));
46
+ }
47
+ async copy(src, dest) {
48
+ await this.file(this.fullPath(src)).copy(this.file(this.fullPath(dest)));
49
+ }
50
+ async *list(prefix = "") {
51
+ let query = {
52
+ prefix: this.fullPath(prefix),
53
+ autoPaginate: false,
54
+ maxResults: 500
55
+ };
56
+ while (query) {
57
+ const [files, nextQuery] = await this.bucket.getFiles(query);
58
+ for (const file of files) {
59
+ yield file.name.substring(this.root.length);
60
+ }
61
+ query = nextQuery;
13
62
  }
14
- fullPath(filepath) {
15
- return normalizePath(join(this.root, filepath));
16
- }
17
- file(filepath) {
18
- return this.bucket.file(filepath);
19
- }
20
- async read(filepath, range) {
21
- const options = {};
22
- if (range?.start)
23
- options.start = range.start;
24
- if (range?.end)
25
- options.end = range.end;
26
- return this.file(this.fullPath(filepath)).createReadStream(options);
27
- }
28
- async write(filepath, content) {
29
- const file = this.file(this.fullPath(filepath));
30
- const stream = file.createWriteStream({ resumable: false });
31
- await pipeline(content, stream);
32
- }
33
- async delete(filepath) {
34
- await this.file(this.fullPath(filepath)).delete();
35
- }
36
- async stat(filepath) {
37
- const [{ size, updated }] = await this.file(this.fullPath(filepath)).getMetadata();
38
- return { size, modified: updated };
39
- }
40
- async exists(filepath) {
41
- return (await this.file(this.fullPath(filepath)).exists())[0];
42
- }
43
- async move(src, dest) {
44
- await this.file(this.fullPath(src)).move(this.file(this.fullPath(dest)));
45
- }
46
- async copy(src, dest) {
47
- await this.file(this.fullPath(src)).copy(this.file(this.fullPath(dest)));
48
- }
49
- async *list(prefix = '') {
50
- let query = {
51
- prefix: this.fullPath(prefix),
52
- autoPaginate: false,
53
- maxResults: 500,
54
- };
55
- while (query) {
56
- const [files, nextQuery] = await this.bucket.getFiles(query);
57
- for (const file of files) {
58
- yield file.name.substring(this.root.length);
59
- }
60
- query = nextQuery;
61
- }
62
- }
63
- }
64
- export default DriverGCS;
63
+ }
64
+ };
65
+ var src_default = DriverGCS;
66
+ export {
67
+ DriverGCS,
68
+ src_default as default
69
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@directus/storage-driver-gcs",
3
- "version": "10.0.10",
3
+ "version": "10.0.12",
4
4
  "description": "GCS file storage abstraction for `@directus/storage`",
5
5
  "homepage": "https://directus.io",
6
6
  "repository": {
@@ -22,19 +22,20 @@
22
22
  ],
23
23
  "dependencies": {
24
24
  "@google-cloud/storage": "6.10.1",
25
- "@directus/storage": "10.0.5",
26
- "@directus/utils": "10.0.10"
25
+ "@directus/storage": "10.0.6",
26
+ "@directus/utils": "11.0.0"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@ngneat/falso": "6.4.0",
30
30
  "@vitest/coverage-c8": "0.31.1",
31
- "typescript": "5.0.4",
31
+ "tsup": "7.2.0",
32
+ "typescript": "5.2.2",
32
33
  "vitest": "0.31.1",
33
- "@directus/tsconfig": "1.0.0"
34
+ "@directus/tsconfig": "1.0.1"
34
35
  },
35
36
  "scripts": {
36
- "build": "tsc --project tsconfig.prod.json",
37
- "dev": "tsc --watch",
37
+ "build": "tsup src/index.ts --format=esm --dts",
38
+ "dev": "tsup src/index.ts --format=esm --dts --watch",
38
39
  "test": "vitest --watch=false"
39
40
  }
40
41
  }