@basaltkit/storage-gcs 1.0.0 → 1.1.0

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2026 Machize Contributors
3
+ Copyright (c) 2026 Basalt Contributors
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,3 +1,9 @@
1
+ <p align="center">
2
+ <a href="https://basaltkit-docs.pages.dev">
3
+ <img src="https://basaltkit-docs.pages.dev/social-card.png" alt="Basalt" width="440">
4
+ </a>
5
+ </p>
6
+
1
7
  # @basaltkit/storage-gcs
2
8
 
3
9
  **Google Cloud Storage** driver for [`@basaltkit/storage`](https://www.npmjs.com/package/@basaltkit/storage): stores files on GCS without changing your app's code. You need this module when you run on Google Cloud and want GCS instead of S3 or local disk.
package/dist/index.d.ts CHANGED
@@ -1,7 +1,6 @@
1
- import { StorageDriver, PutOptions } from '@basaltkit/storage';
2
-
1
+ import { type TemporaryUrlOptions, type PutOptions, type StorageDriver } from '@basaltkit/storage';
3
2
  /** The subset of a `@google-cloud/storage` File this driver uses. */
4
- interface GcsFileLike {
3
+ export interface GcsFileLike {
5
4
  save(data: Buffer, options?: {
6
5
  contentType?: string;
7
6
  }): Promise<unknown>;
@@ -11,10 +10,11 @@ interface GcsFileLike {
11
10
  getSignedUrl(config: {
12
11
  action: 'read';
13
12
  expires: number;
13
+ responseDisposition?: string;
14
14
  }): Promise<[string]>;
15
15
  }
16
16
  /** The subset of a `@google-cloud/storage` Bucket this driver uses. */
17
- interface GcsBucketLike {
17
+ export interface GcsBucketLike {
18
18
  file(path: string): GcsFileLike;
19
19
  getFiles(options?: {
20
20
  prefix?: string;
@@ -22,7 +22,7 @@ interface GcsBucketLike {
22
22
  name: string;
23
23
  }[]]>;
24
24
  }
25
- interface GcsDriverOptions {
25
+ export interface GcsDriverOptions {
26
26
  bucket: string;
27
27
  projectId?: string;
28
28
  keyFilename?: string;
@@ -34,7 +34,7 @@ interface GcsDriverOptions {
34
34
  * `@google-cloud/storage` (an optional peer dependency) via an injectable
35
35
  * bucket, so its logic is unit-tested without touching GCS.
36
36
  */
37
- declare class GcsStorageDriver implements StorageDriver {
37
+ export declare class GcsStorageDriver implements StorageDriver {
38
38
  private readonly options;
39
39
  readonly name = "gcs";
40
40
  private bucketPromise;
@@ -44,9 +44,7 @@ declare class GcsStorageDriver implements StorageDriver {
44
44
  exists(path: string): Promise<boolean>;
45
45
  delete(path: string): Promise<boolean>;
46
46
  list(prefix: string): Promise<string[]>;
47
- temporaryUrl(path: string, expiresInMs: number): Promise<string>;
47
+ temporaryUrl(path: string, expiresInMs: number, options?: TemporaryUrlOptions): Promise<string>;
48
48
  disconnect(): Promise<void>;
49
49
  private bucket;
50
50
  }
51
-
52
- export { type GcsBucketLike, type GcsDriverOptions, type GcsFileLike, GcsStorageDriver };
package/dist/index.js CHANGED
@@ -1,60 +1,73 @@
1
- // src/index.ts
2
- import { StorageFileNotFoundError } from "@basaltkit/storage";
3
- var isNotFound = (error) => error?.code === 404;
4
- var GcsStorageDriver = class {
5
- constructor(options) {
6
- this.options = options;
7
- }
8
- options;
9
- name = "gcs";
10
- bucketPromise;
11
- async put(path, content, options) {
12
- const data = Buffer.isBuffer(content) ? content : Buffer.from(content);
13
- await (await this.bucket()).file(path).save(data, options?.contentType !== void 0 ? { contentType: options.contentType } : {});
14
- }
15
- async get(path) {
16
- try {
17
- const [buffer] = await (await this.bucket()).file(path).download();
18
- return buffer;
19
- } catch (error) {
20
- if (isNotFound(error)) throw new StorageFileNotFoundError(path);
21
- throw error;
22
- }
23
- }
24
- async exists(path) {
25
- const [exists] = await (await this.bucket()).file(path).exists();
26
- return exists;
27
- }
28
- async delete(path) {
29
- if (!await this.exists(path)) return false;
30
- await (await this.bucket()).file(path).delete();
31
- return true;
32
- }
33
- async list(prefix) {
34
- const [files] = await (await this.bucket()).getFiles({ prefix });
35
- return files.map((file) => file.name);
36
- }
37
- async temporaryUrl(path, expiresInMs) {
38
- const [url] = await (await this.bucket()).file(path).getSignedUrl({ action: "read", expires: Date.now() + expiresInMs });
39
- return url;
40
- }
41
- async disconnect() {
42
- }
43
- bucket() {
44
- if (!this.bucketPromise) {
45
- this.bucketPromise = this.options.client ? Promise.resolve(this.options.client) : (async () => {
46
- const specifier = "@google-cloud/storage";
47
- const mod = await import(specifier);
48
- const storage = new mod.Storage({
49
- ...this.options.projectId ? { projectId: this.options.projectId } : {},
50
- ...this.options.keyFilename ? { keyFilename: this.options.keyFilename } : {}
1
+ import { StorageFileNotFoundError } from '@basaltkit/storage';
2
+ const isNotFound = (error) => error?.code === 404;
3
+ /**
4
+ * Google Cloud Storage driver for `@basaltkit/storage`. Uses
5
+ * `@google-cloud/storage` (an optional peer dependency) via an injectable
6
+ * bucket, so its logic is unit-tested without touching GCS.
7
+ */
8
+ export class GcsStorageDriver {
9
+ options;
10
+ name = 'gcs';
11
+ bucketPromise;
12
+ constructor(options) {
13
+ this.options = options;
14
+ }
15
+ async put(path, content, options) {
16
+ const data = Buffer.isBuffer(content) ? content : Buffer.from(content);
17
+ await (await this.bucket())
18
+ .file(path)
19
+ .save(data, options?.contentType !== undefined ? { contentType: options.contentType } : {});
20
+ }
21
+ async get(path) {
22
+ try {
23
+ const [buffer] = await (await this.bucket()).file(path).download();
24
+ return buffer;
25
+ }
26
+ catch (error) {
27
+ if (isNotFound(error))
28
+ throw new StorageFileNotFoundError(path);
29
+ throw error;
30
+ }
31
+ }
32
+ async exists(path) {
33
+ const [exists] = await (await this.bucket()).file(path).exists();
34
+ return exists;
35
+ }
36
+ async delete(path) {
37
+ if (!(await this.exists(path)))
38
+ return false;
39
+ await (await this.bucket()).file(path).delete();
40
+ return true;
41
+ }
42
+ async list(prefix) {
43
+ const [files] = await (await this.bucket()).getFiles({ prefix });
44
+ return files.map((file) => file.name);
45
+ }
46
+ async temporaryUrl(path, expiresInMs, options) {
47
+ const [url] = await (await this.bucket()).file(path).getSignedUrl({
48
+ action: 'read',
49
+ expires: Date.now() + expiresInMs,
50
+ // Signed response header: uploaded HTML/SVG downloads instead of
51
+ // rendering on the storage origin ('attachment' is the Disk default).
52
+ responseDisposition: options?.disposition ?? 'attachment',
51
53
  });
52
- return storage.bucket(this.options.bucket);
53
- })();
54
- }
55
- return this.bucketPromise;
56
- }
57
- };
58
- export {
59
- GcsStorageDriver
60
- };
54
+ return url;
55
+ }
56
+ async disconnect() { }
57
+ bucket() {
58
+ if (!this.bucketPromise) {
59
+ this.bucketPromise = this.options.client
60
+ ? Promise.resolve(this.options.client)
61
+ : (async () => {
62
+ const specifier = '@google-cloud/storage';
63
+ const mod = (await import(specifier));
64
+ const storage = new mod.Storage({
65
+ ...(this.options.projectId ? { projectId: this.options.projectId } : {}),
66
+ ...(this.options.keyFilename ? { keyFilename: this.options.keyFilename } : {}),
67
+ });
68
+ return storage.bucket(this.options.bucket);
69
+ })();
70
+ }
71
+ return this.bucketPromise;
72
+ }
73
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@basaltkit/storage-gcs",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Google Cloud Storage driver for @basaltkit/storage — put/get/list/delete/signed URLs over @google-cloud/storage, with an injectable client for testing.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -14,16 +14,15 @@
14
14
  "dist"
15
15
  ],
16
16
  "dependencies": {
17
- "@basaltkit/storage": "^1.0.0"
17
+ "@basaltkit/storage": "^1.3.0"
18
18
  },
19
19
  "peerDependencies": {
20
20
  "@google-cloud/storage": "^7.0.0"
21
21
  },
22
22
  "devDependencies": {
23
- "@types/node": "^22.15.0",
24
- "tsup": "^8.4.0",
25
- "typescript": "^5.8.0",
26
- "vitest": "^3.1.0",
23
+ "@types/node": "^26.3.0",
24
+ "typescript": "^7.0.2",
25
+ "vitest": "^4.1.11",
27
26
  "@basaltkit/tsconfig": "^0.24.0"
28
27
  },
29
28
  "publishConfig": {
@@ -31,11 +30,11 @@
31
30
  },
32
31
  "repository": {
33
32
  "type": "git",
34
- "url": "git+https://github.com/Zebedeu/basalt.git",
33
+ "url": "git+https://github.com/basaltkit/basalt.git",
35
34
  "directory": "packages/storage-gcs"
36
35
  },
37
- "homepage": "https://github.com/Zebedeu/basalt/tree/main/packages/storage-gcs#readme",
38
- "bugs": "https://github.com/Zebedeu/basalt/issues",
36
+ "homepage": "https://github.com/basaltkit/basalt/tree/main/packages/storage-gcs#readme",
37
+ "bugs": "https://github.com/basaltkit/basalt/issues",
39
38
  "keywords": [
40
39
  "basalt",
41
40
  "typescript",
@@ -44,7 +43,7 @@
44
43
  "google-cloud"
45
44
  ],
46
45
  "scripts": {
47
- "build": "tsup src/index.ts --format esm --dts --clean",
46
+ "build": "tsc -p tsconfig.build.json",
48
47
  "test": "vitest run",
49
48
  "typecheck": "tsc --noEmit"
50
49
  }