@wild-framework/storage-auto 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 +28 -2
- package/dist/classify.d.ts +11 -0
- package/dist/classify.d.ts.map +1 -0
- package/dist/classify.js +16 -0
- package/dist/classify.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 +34 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +79 -0
- package/dist/provider.js.map +1 -0
- package/package.json +45 -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,29 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @wild-framework/storage-auto
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Env-driven storage provider for [Wild Framework](https://github.com/KhandaSoftware/wild-framework).
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @wild-framework/storage-auto
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
Register `StorageProvider` and set `STORAGE_DRIVER` to swap backends without touching app code:
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { StorageProvider } from "@wild-framework/storage-auto";
|
|
17
|
+
|
|
18
|
+
app.register(StorageProvider);
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
| `STORAGE_DRIVER` | Backend | Env vars |
|
|
22
|
+
| ---------------- | ------- | -------- |
|
|
23
|
+
| `s3` / `aws` | S3 | `AWS_BUCKET`, `AWS_REGION`, `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `AWS_ENDPOINT`, `AWS_PUBLIC_URL` |
|
|
24
|
+
| `gcs` / `gcp` | GCS | `GCS_BUCKET`, `GCS_PROJECT_ID`, `GCS_PUBLIC_URL` (+ `GOOGLE_APPLICATION_CREDENTIALS`) |
|
|
25
|
+
| unset / other | Local | `STORAGE_PATH` (default `./storage`) |
|
|
26
|
+
|
|
27
|
+
## License
|
|
28
|
+
|
|
29
|
+
MIT
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Which concrete storage backend a driver name maps to. */
|
|
2
|
+
export type StorageBackend = "s3" | "gcs" | "local";
|
|
3
|
+
/**
|
|
4
|
+
* Classify a `STORAGE_DRIVER` value.
|
|
5
|
+
*
|
|
6
|
+
* "s3" | "aws" → "s3"
|
|
7
|
+
* "gcs" | "gcp" | "google" → "gcs"
|
|
8
|
+
* anything else / undefined → "local"
|
|
9
|
+
*/
|
|
10
|
+
export declare function classifyStorageDriver(driver: string | undefined): StorageBackend;
|
|
11
|
+
//# sourceMappingURL=classify.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"classify.d.ts","sourceRoot":"","sources":["../src/classify.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,MAAM,MAAM,cAAc,GAAG,IAAI,GAAG,KAAK,GAAG,OAAO,CAAC;AAEpD;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,cAAc,CAKhF"}
|
package/dist/classify.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Classify a `STORAGE_DRIVER` value.
|
|
3
|
+
*
|
|
4
|
+
* "s3" | "aws" → "s3"
|
|
5
|
+
* "gcs" | "gcp" | "google" → "gcs"
|
|
6
|
+
* anything else / undefined → "local"
|
|
7
|
+
*/
|
|
8
|
+
export function classifyStorageDriver(driver) {
|
|
9
|
+
const d = driver?.trim().toLowerCase();
|
|
10
|
+
if (d === "s3" || d === "aws")
|
|
11
|
+
return "s3";
|
|
12
|
+
if (d === "gcs" || d === "gcp" || d === "google" || d === "google-cloud")
|
|
13
|
+
return "gcs";
|
|
14
|
+
return "local";
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=classify.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"classify.js","sourceRoot":"","sources":["../src/classify.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CAAC,MAA0B;IAC5D,MAAM,CAAC,GAAG,MAAM,EAAE,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IACvC,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,KAAK;QAAE,OAAO,IAAI,CAAC;IAC3C,IAAI,CAAC,KAAK,KAAK,IAAI,CAAC,KAAK,KAAK,IAAI,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,cAAc;QAAE,OAAO,KAAK,CAAC;IACvF,OAAO,OAAO,CAAC;AACnB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACtD,YAAY,EAAE,cAAc,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,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Provider, Application } from "@wild-framework/core";
|
|
2
|
+
/**
|
|
3
|
+
* Unified, env-driven storage provider.
|
|
4
|
+
*
|
|
5
|
+
* Selects a concrete driver from `STORAGE_DRIVER` and binds a `Storage`
|
|
6
|
+
* into the container. This is the "one provider to rule them all" —
|
|
7
|
+
* register it and set env vars to swap backends without touching app code:
|
|
8
|
+
*
|
|
9
|
+
* STORAGE_DRIVER=s3 → S3 (AWS_BUCKET, AWS_REGION, AWS_ACCESS_KEY_ID, …)
|
|
10
|
+
* STORAGE_DRIVER=gcs → GCS (GCS_BUCKET, GCS_PROJECT_ID, GOOGLE_APPLICATION_CREDENTIALS)
|
|
11
|
+
* (unset) → local (STORAGE_PATH, default "./storage")
|
|
12
|
+
*
|
|
13
|
+
* Static configuration (no-arg constructor requirement):
|
|
14
|
+
*
|
|
15
|
+
* ```ts
|
|
16
|
+
* StorageProvider.driver = "s3"; // optional — force a backend
|
|
17
|
+
* StorageProvider.basePath = "./uploads"; // local only
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* The explicit providers (`StorageProvider` from `@wild-framework/storage`,
|
|
21
|
+
* `S3StorageProvider`, `GcsStorageProvider`) remain available when you want
|
|
22
|
+
* to be explicit.
|
|
23
|
+
*/
|
|
24
|
+
export declare class StorageProvider implements Provider {
|
|
25
|
+
/** Force a backend; defaults to `STORAGE_DRIVER` (s3 | gcs | local). */
|
|
26
|
+
static driver: "s3" | "gcs" | "local" | undefined;
|
|
27
|
+
/** Local filesystem base path (local backend). Defaults to `STORAGE_PATH` or "./storage". */
|
|
28
|
+
static basePath: string;
|
|
29
|
+
private instance;
|
|
30
|
+
register(app: Application): void;
|
|
31
|
+
boot(): Promise<void>;
|
|
32
|
+
shutdown(): Promise<void>;
|
|
33
|
+
}
|
|
34
|
+
//# 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;AAOlE;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,eAAgB,YAAW,QAAQ;IAC5C,wEAAwE;IACxE,MAAM,CAAC,MAAM,EAAE,IAAI,GAAG,KAAK,GAAG,OAAO,GAAG,SAAS,CAAC;IAClD,6FAA6F;IAC7F,MAAM,CAAC,QAAQ,SAAe;IAE9B,OAAO,CAAC,QAAQ,CAAsE;IAEtF,QAAQ,CAAC,GAAG,EAAE,WAAW,GAAG,IAAI;IAwC1B,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAIrB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAGlC"}
|
package/dist/provider.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { Container } from "@wild-framework/container";
|
|
2
|
+
import { Storage, LocalStorageDriver } from "@wild-framework/storage";
|
|
3
|
+
import { S3StorageDriver } from "@wild-framework/storage-s3";
|
|
4
|
+
import { GcsStorageDriver } from "@wild-framework/storage-gcs";
|
|
5
|
+
import { classifyStorageDriver } from "./classify.js";
|
|
6
|
+
/**
|
|
7
|
+
* Unified, env-driven storage provider.
|
|
8
|
+
*
|
|
9
|
+
* Selects a concrete driver from `STORAGE_DRIVER` and binds a `Storage`
|
|
10
|
+
* into the container. This is the "one provider to rule them all" —
|
|
11
|
+
* register it and set env vars to swap backends without touching app code:
|
|
12
|
+
*
|
|
13
|
+
* STORAGE_DRIVER=s3 → S3 (AWS_BUCKET, AWS_REGION, AWS_ACCESS_KEY_ID, …)
|
|
14
|
+
* STORAGE_DRIVER=gcs → GCS (GCS_BUCKET, GCS_PROJECT_ID, GOOGLE_APPLICATION_CREDENTIALS)
|
|
15
|
+
* (unset) → local (STORAGE_PATH, default "./storage")
|
|
16
|
+
*
|
|
17
|
+
* Static configuration (no-arg constructor requirement):
|
|
18
|
+
*
|
|
19
|
+
* ```ts
|
|
20
|
+
* StorageProvider.driver = "s3"; // optional — force a backend
|
|
21
|
+
* StorageProvider.basePath = "./uploads"; // local only
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* The explicit providers (`StorageProvider` from `@wild-framework/storage`,
|
|
25
|
+
* `S3StorageProvider`, `GcsStorageProvider`) remain available when you want
|
|
26
|
+
* to be explicit.
|
|
27
|
+
*/
|
|
28
|
+
export class StorageProvider {
|
|
29
|
+
/** Force a backend; defaults to `STORAGE_DRIVER` (s3 | gcs | local). */
|
|
30
|
+
static driver;
|
|
31
|
+
/** Local filesystem base path (local backend). Defaults to `STORAGE_PATH` or "./storage". */
|
|
32
|
+
static basePath = "./storage";
|
|
33
|
+
instance;
|
|
34
|
+
register(app) {
|
|
35
|
+
const container = app.resolve(Container);
|
|
36
|
+
const backend = classifyStorageDriver(StorageProvider.driver ?? process.env.STORAGE_DRIVER);
|
|
37
|
+
let driver;
|
|
38
|
+
if (backend === "s3") {
|
|
39
|
+
driver = new S3StorageDriver({
|
|
40
|
+
bucket: process.env.AWS_BUCKET ?? "",
|
|
41
|
+
region: process.env.AWS_REGION ?? "",
|
|
42
|
+
credentials: process.env.AWS_ACCESS_KEY_ID
|
|
43
|
+
? {
|
|
44
|
+
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
|
|
45
|
+
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY ?? "",
|
|
46
|
+
}
|
|
47
|
+
: undefined,
|
|
48
|
+
endpoint: process.env.AWS_ENDPOINT,
|
|
49
|
+
// Custom S3-compatible endpoints (MinIO, s3mock, R2) need
|
|
50
|
+
// path-style addressing unless they explicitly support
|
|
51
|
+
// virtual-hosted style.
|
|
52
|
+
forcePathStyle: process.env.AWS_FORCE_PATH_STYLE === undefined
|
|
53
|
+
? !!process.env.AWS_ENDPOINT
|
|
54
|
+
: process.env.AWS_FORCE_PATH_STYLE === "true",
|
|
55
|
+
publicUrl: process.env.AWS_PUBLIC_URL,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
else if (backend === "gcs") {
|
|
59
|
+
driver = new GcsStorageDriver({
|
|
60
|
+
bucket: process.env.GCS_BUCKET ?? "",
|
|
61
|
+
projectId: process.env.GCS_PROJECT_ID,
|
|
62
|
+
apiEndpoint: process.env.GCS_ENDPOINT,
|
|
63
|
+
publicUrl: process.env.GCS_PUBLIC_URL,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
driver = new LocalStorageDriver(process.env.STORAGE_PATH ?? StorageProvider.basePath);
|
|
68
|
+
}
|
|
69
|
+
this.instance = driver;
|
|
70
|
+
container.singleton(Storage, () => new Storage(driver));
|
|
71
|
+
}
|
|
72
|
+
async boot() {
|
|
73
|
+
await this.instance?.connect();
|
|
74
|
+
}
|
|
75
|
+
async shutdown() {
|
|
76
|
+
await this.instance?.close();
|
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1
|
{
|
|
2
2
|
"name": "@wild-framework/storage-auto",
|
|
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": "Env-driven storage provider — auto-selects local, S3, or GCS from STORAGE_DRIVER.",
|
|
26
|
+
"keywords": [
|
|
27
|
+
"wild",
|
|
28
|
+
"framework",
|
|
29
|
+
"storage",
|
|
30
|
+
"files",
|
|
31
|
+
"s3",
|
|
32
|
+
"gcs",
|
|
33
|
+
"local",
|
|
34
|
+
"auto"
|
|
35
|
+
],
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@wild-framework/core": "0.2.2",
|
|
38
|
+
"@wild-framework/storage": "0.2.2",
|
|
39
|
+
"@wild-framework/container": "0.2.2",
|
|
40
|
+
"@wild-framework/storage-s3": "0.2.2",
|
|
41
|
+
"@wild-framework/storage-gcs": "0.2.2"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "tsc",
|
|
45
|
+
"clean": "rm -rf dist",
|
|
46
|
+
"test": "vitest run"
|
|
47
|
+
}
|
|
6
48
|
}
|