@wild-framework/storage-gcs 0.0.0-stage → 0.2.2
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 +21 -0
- package/README.md +40 -2
- package/dist/driver.d.ts +45 -0
- package/dist/driver.d.ts.map +1 -0
- package/dist/driver.js +84 -0
- package/dist/driver.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/provider.d.ts +33 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +51 -0
- package/dist/provider.js.map +1 -0
- package/package.json +43 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Wild Framework contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,41 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @wild-framework/storage-gcs
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Google Cloud Storage driver for [Wild Framework](https://github.com/KhandaSoftware/wild-framework)'s storage package.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @wild-framework/storage-gcs
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { GcsStorageProvider } from "@wild-framework/storage-gcs";
|
|
15
|
+
|
|
16
|
+
GcsStorageProvider.bucket = process.env.GCS_BUCKET;
|
|
17
|
+
GcsStorageProvider.projectId = process.env.GCS_PROJECT_ID;
|
|
18
|
+
// Credentials are read from GOOGLE_APPLICATION_CREDENTIALS by default.
|
|
19
|
+
|
|
20
|
+
app.register(GcsStorageProvider);
|
|
21
|
+
// … storage is now GCS-backed, resolved via app.resolve(Storage)
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
- Set `publicUrl` to serve public objects directly; otherwise `storage.url(key, { expiresIn })` returns a **signed** URL.
|
|
25
|
+
- Provide `credentials` (JSON) or `keyFilename` to authenticate explicitly.
|
|
26
|
+
|
|
27
|
+
## Integration test
|
|
28
|
+
|
|
29
|
+
Point it at `fake-gcs-server` (or real GCS):
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
GCS_ENDPOINT=http://localhost:4443 \
|
|
33
|
+
GCS_BUCKET=wild-it GCS_PROJECT_ID=test \
|
|
34
|
+
pnpm --filter @wild-framework/storage-gcs test
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Skips automatically when the env vars are not set.
|
|
38
|
+
|
|
39
|
+
## License
|
|
40
|
+
|
|
41
|
+
MIT
|
package/dist/driver.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { StorageDriver, PutOptions, UrlOptions } from "@wild-framework/storage";
|
|
2
|
+
import { Storage as GoogleCloudStorage } from "@google-cloud/storage";
|
|
3
|
+
/**
|
|
4
|
+
* Configuration for the Google Cloud Storage driver.
|
|
5
|
+
*/
|
|
6
|
+
export interface GcsStorageConfig {
|
|
7
|
+
/** GCS bucket name. */
|
|
8
|
+
bucket: string;
|
|
9
|
+
/** GCP project id. */
|
|
10
|
+
projectId?: string;
|
|
11
|
+
/** Service-account credentials (JSON). Mutually exclusive with `keyFilename`. */
|
|
12
|
+
credentials?: Record<string, unknown>;
|
|
13
|
+
/** Path to a service-account key file. Mutually exclusive with `credentials`. */
|
|
14
|
+
keyFilename?: string;
|
|
15
|
+
/** Custom API endpoint — for the GCS emulator (`fake-gcs-server`). */
|
|
16
|
+
apiEndpoint?: string;
|
|
17
|
+
/** Base URL for public objects. When set, `url()` returns `${publicUrl}/${key}`. */
|
|
18
|
+
publicUrl?: string;
|
|
19
|
+
/** Default expiry (seconds) for signed URLs when `url()` is called with no `expiresIn`. */
|
|
20
|
+
signedUrlExpiresIn?: number;
|
|
21
|
+
/** A pre-built client — for advanced use or tests. */
|
|
22
|
+
client?: GoogleCloudStorage;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Google Cloud Storage driver implementing `StorageDriver`.
|
|
26
|
+
*
|
|
27
|
+
* Backed by `@google-cloud/storage`. The client is lazy — `connect()`
|
|
28
|
+
* materialises it so bad config fails early (done by `GcsStorageProvider`).
|
|
29
|
+
*/
|
|
30
|
+
export declare class GcsStorageDriver implements StorageDriver {
|
|
31
|
+
private config;
|
|
32
|
+
private client;
|
|
33
|
+
constructor(config: GcsStorageConfig);
|
|
34
|
+
connect(): Promise<void>;
|
|
35
|
+
close(): Promise<void>;
|
|
36
|
+
put(path: string, contents: Buffer | string, options?: PutOptions): Promise<string>;
|
|
37
|
+
get(path: string): Promise<Buffer>;
|
|
38
|
+
delete(path: string): Promise<void>;
|
|
39
|
+
exists(path: string): Promise<boolean>;
|
|
40
|
+
url(path: string, options?: UrlOptions): Promise<string>;
|
|
41
|
+
private file;
|
|
42
|
+
private normalizeKey;
|
|
43
|
+
private requireClient;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=driver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"driver.d.ts","sourceRoot":"","sources":["../src/driver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrF,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAEtE;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC7B,uBAAuB;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,sBAAsB;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iFAAiF;IACjF,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACtC,iFAAiF;IACjF,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,sEAAsE;IACtE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,oFAAoF;IACpF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,2FAA2F;IAC3F,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,sDAAsD;IACtD,MAAM,CAAC,EAAE,kBAAkB,CAAC;CAC/B;AAED;;;;;GAKG;AACH,qBAAa,gBAAiB,YAAW,aAAa;IAGtC,OAAO,CAAC,MAAM;IAF1B,OAAO,CAAC,MAAM,CAAmC;gBAE7B,MAAM,EAAE,gBAAgB;IAMtC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAIxB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAKtB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC;IAWnF,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAKlC,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAInC,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAKtC,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC;IAmB9D,OAAO,CAAC,IAAI;IAIZ,OAAO,CAAC,YAAY;IAIpB,OAAO,CAAC,aAAa;CAaxB"}
|
package/dist/driver.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { Storage as GoogleCloudStorage } from "@google-cloud/storage";
|
|
2
|
+
/**
|
|
3
|
+
* Google Cloud Storage driver implementing `StorageDriver`.
|
|
4
|
+
*
|
|
5
|
+
* Backed by `@google-cloud/storage`. The client is lazy — `connect()`
|
|
6
|
+
* materialises it so bad config fails early (done by `GcsStorageProvider`).
|
|
7
|
+
*/
|
|
8
|
+
export class GcsStorageDriver {
|
|
9
|
+
config;
|
|
10
|
+
client = null;
|
|
11
|
+
constructor(config) {
|
|
12
|
+
this.config = config;
|
|
13
|
+
if (!config.bucket) {
|
|
14
|
+
throw new Error("GcsStorageDriver requires a bucket.");
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
async connect() {
|
|
18
|
+
this.requireClient(); // materialise so config errors surface at boot
|
|
19
|
+
}
|
|
20
|
+
async close() {
|
|
21
|
+
// The GCS client holds no persistent connection to close.
|
|
22
|
+
this.client = null;
|
|
23
|
+
}
|
|
24
|
+
async put(path, contents, options) {
|
|
25
|
+
const file = this.file(path);
|
|
26
|
+
// Single-shot upload — the Buffer-based API has no stream to resume.
|
|
27
|
+
await file.save(contents, {
|
|
28
|
+
resumable: false,
|
|
29
|
+
contentType: options?.contentType,
|
|
30
|
+
...(options?.metadata ? { metadata: { metadata: options.metadata } } : {}),
|
|
31
|
+
});
|
|
32
|
+
return path;
|
|
33
|
+
}
|
|
34
|
+
async get(path) {
|
|
35
|
+
const [contents] = await this.file(path).download();
|
|
36
|
+
return contents;
|
|
37
|
+
}
|
|
38
|
+
async delete(path) {
|
|
39
|
+
await this.file(path).delete();
|
|
40
|
+
}
|
|
41
|
+
async exists(path) {
|
|
42
|
+
const [exists] = await this.file(path).exists();
|
|
43
|
+
return exists;
|
|
44
|
+
}
|
|
45
|
+
async url(path, options) {
|
|
46
|
+
const key = this.normalizeKey(path);
|
|
47
|
+
if (this.config.publicUrl) {
|
|
48
|
+
return joinUrl(this.config.publicUrl, key);
|
|
49
|
+
}
|
|
50
|
+
if (options?.expiresIn !== undefined || this.config.signedUrlExpiresIn !== undefined) {
|
|
51
|
+
const expiresIn = options?.expiresIn ?? this.config.signedUrlExpiresIn ?? 3600;
|
|
52
|
+
const [signed] = await this.file(key).getSignedUrl({
|
|
53
|
+
action: "read",
|
|
54
|
+
expires: Date.now() + expiresIn * 1000,
|
|
55
|
+
});
|
|
56
|
+
return signed;
|
|
57
|
+
}
|
|
58
|
+
return `https://storage.googleapis.com/${this.config.bucket}/${key}`;
|
|
59
|
+
}
|
|
60
|
+
file(path) {
|
|
61
|
+
return this.requireClient().bucket(this.config.bucket).file(this.normalizeKey(path));
|
|
62
|
+
}
|
|
63
|
+
normalizeKey(path) {
|
|
64
|
+
return path.replace(/^\/+/, "");
|
|
65
|
+
}
|
|
66
|
+
requireClient() {
|
|
67
|
+
if (!this.client) {
|
|
68
|
+
this.client =
|
|
69
|
+
this.config.client ??
|
|
70
|
+
new GoogleCloudStorage({
|
|
71
|
+
projectId: this.config.projectId,
|
|
72
|
+
credentials: this.config.credentials,
|
|
73
|
+
keyFilename: this.config.keyFilename,
|
|
74
|
+
apiEndpoint: this.config.apiEndpoint,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
return this.client;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/** Join a base URL and a key without producing double slashes. */
|
|
81
|
+
function joinUrl(base, key) {
|
|
82
|
+
return `${base.replace(/\/+$/, "")}/${key.replace(/^\/+/, "")}`;
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=driver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"driver.js","sourceRoot":"","sources":["../src/driver.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAwBtE;;;;;GAKG;AACH,MAAM,OAAO,gBAAgB;IAGL;IAFZ,MAAM,GAA8B,IAAI,CAAC;IAEjD,YAAoB,MAAwB;QAAxB,WAAM,GAAN,MAAM,CAAkB;QACxC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;QAC3D,CAAC;IACL,CAAC;IAED,KAAK,CAAC,OAAO;QACT,IAAI,CAAC,aAAa,EAAE,CAAC,CAAC,+CAA+C;IACzE,CAAC;IAED,KAAK,CAAC,KAAK;QACP,0DAA0D;QAC1D,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;IACvB,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,IAAY,EAAE,QAAyB,EAAE,OAAoB;QACnE,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC7B,qEAAqE;QACrE,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;YACtB,SAAS,EAAE,KAAK;YAChB,WAAW,EAAE,OAAO,EAAE,WAAW;YACjC,GAAG,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,C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AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Provider, Application } from "@wild-framework/core";
|
|
2
|
+
/**
|
|
3
|
+
* Registers a Google Cloud Storage-backed storage with the application.
|
|
4
|
+
*
|
|
5
|
+
* Static configuration (no-arg constructor requirement):
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* GcsStorageProvider.bucket = "my-bucket";
|
|
9
|
+
* GcsStorageProvider.projectId = process.env.GCS_PROJECT_ID;
|
|
10
|
+
* // credentials come from GOOGLE_APPLICATION_CREDENTIALS by default
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* Materialises the client on boot (fail-fast on bad config).
|
|
14
|
+
*/
|
|
15
|
+
export declare class GcsStorageProvider implements Provider {
|
|
16
|
+
/** GCS bucket name. */
|
|
17
|
+
static bucket: string | undefined;
|
|
18
|
+
/** GCP project id. */
|
|
19
|
+
static projectId: string | undefined;
|
|
20
|
+
/** Service-account credentials (JSON). */
|
|
21
|
+
static credentials: Record<string, unknown> | undefined;
|
|
22
|
+
/** Path to a service-account key file. */
|
|
23
|
+
static keyFilename: string | undefined;
|
|
24
|
+
/** Base URL for public objects. */
|
|
25
|
+
static publicUrl: string | undefined;
|
|
26
|
+
/** Default expiry (seconds) for signed URLs. */
|
|
27
|
+
static signedUrlExpiresIn: number | undefined;
|
|
28
|
+
private driver;
|
|
29
|
+
register(app: Application): void;
|
|
30
|
+
boot(): Promise<void>;
|
|
31
|
+
shutdown(): Promise<void>;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAKlE;;;;;;;;;;;;GAYG;AACH,qBAAa,kBAAmB,YAAW,QAAQ;IAC/C,uBAAuB;IACvB,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,sBAAsB;IACtB,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IACrC,0CAA0C;IAC1C,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;IACxD,0CAA0C;IAC1C,MAAM,CAAC,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IACvC,mCAAmC;IACnC,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IACrC,gDAAgD;IAChD,MAAM,CAAC,kBAAkB,EAAE,MAAM,GAAG,SAAS,CAAC;IAE9C,OAAO,CAAC,MAAM,CAA+B;IAE7C,QAAQ,CAAC,GAAG,EAAE,WAAW,GAAG,IAAI;IAgB1B,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAIrB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAGlC"}
|
package/dist/provider.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Container } from "@wild-framework/container";
|
|
2
|
+
import { Storage } from "@wild-framework/storage";
|
|
3
|
+
import { GcsStorageDriver } from "./driver.js";
|
|
4
|
+
/**
|
|
5
|
+
* Registers a Google Cloud Storage-backed storage with the application.
|
|
6
|
+
*
|
|
7
|
+
* Static configuration (no-arg constructor requirement):
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* GcsStorageProvider.bucket = "my-bucket";
|
|
11
|
+
* GcsStorageProvider.projectId = process.env.GCS_PROJECT_ID;
|
|
12
|
+
* // credentials come from GOOGLE_APPLICATION_CREDENTIALS by default
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* Materialises the client on boot (fail-fast on bad config).
|
|
16
|
+
*/
|
|
17
|
+
export class GcsStorageProvider {
|
|
18
|
+
/** GCS bucket name. */
|
|
19
|
+
static bucket;
|
|
20
|
+
/** GCP project id. */
|
|
21
|
+
static projectId;
|
|
22
|
+
/** Service-account credentials (JSON). */
|
|
23
|
+
static credentials;
|
|
24
|
+
/** Path to a service-account key file. */
|
|
25
|
+
static keyFilename;
|
|
26
|
+
/** Base URL for public objects. */
|
|
27
|
+
static publicUrl;
|
|
28
|
+
/** Default expiry (seconds) for signed URLs. */
|
|
29
|
+
static signedUrlExpiresIn;
|
|
30
|
+
driver;
|
|
31
|
+
register(app) {
|
|
32
|
+
const container = app.resolve(Container);
|
|
33
|
+
const driver = new GcsStorageDriver({
|
|
34
|
+
bucket: GcsStorageProvider.bucket ?? "",
|
|
35
|
+
projectId: GcsStorageProvider.projectId,
|
|
36
|
+
credentials: GcsStorageProvider.credentials,
|
|
37
|
+
keyFilename: GcsStorageProvider.keyFilename,
|
|
38
|
+
publicUrl: GcsStorageProvider.publicUrl,
|
|
39
|
+
signedUrlExpiresIn: GcsStorageProvider.signedUrlExpiresIn,
|
|
40
|
+
});
|
|
41
|
+
this.driver = driver;
|
|
42
|
+
container.singleton(Storage, () => new Storage(driver));
|
|
43
|
+
}
|
|
44
|
+
async boot() {
|
|
45
|
+
await this.driver?.connect();
|
|
46
|
+
}
|
|
47
|
+
async shutdown() {
|
|
48
|
+
await this.driver?.close();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,O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 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wild-framework/storage-gcs",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.2.2",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public"
|
|
18
|
+
},
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"author": "Sphah",
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/Khandasoftware/wild-framework.git"
|
|
24
|
+
},
|
|
25
|
+
"description": "Google Cloud Storage driver for Wild Framework's storage package.",
|
|
26
|
+
"keywords": [
|
|
27
|
+
"wild",
|
|
28
|
+
"framework",
|
|
29
|
+
"storage",
|
|
30
|
+
"files",
|
|
31
|
+
"gcs",
|
|
32
|
+
"google",
|
|
33
|
+
"gcp"
|
|
34
|
+
],
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@google-cloud/storage": "^7.15.0",
|
|
37
|
+
"@wild-framework/core": "0.2.2",
|
|
38
|
+
"@wild-framework/container": "0.2.2",
|
|
39
|
+
"@wild-framework/storage": "0.2.2"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "tsc",
|
|
43
|
+
"clean": "rm -rf dist",
|
|
44
|
+
"test": "vitest run"
|
|
45
|
+
}
|
|
6
46
|
}
|