@velajs/cloudflare 1.9.0 → 1.10.1
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/CHANGELOG.md +8 -3
- package/dist/index.d.ts +805 -39
- package/dist/index.js +1645 -37
- package/dist/index.js.map +1 -0
- package/package.json +55 -41
- package/dist/binding-ref.d.ts +0 -8
- package/dist/binding-ref.js +0 -19
- package/dist/cloudflare-application.d.ts +0 -125
- package/dist/cloudflare-application.js +0 -186
- package/dist/cloudflare-factory.d.ts +0 -88
- package/dist/cloudflare-factory.js +0 -101
- package/dist/decorators/env.d.ts +0 -16
- package/dist/decorators/env.js +0 -22
- package/dist/decorators/queue-consumer.d.ts +0 -23
- package/dist/decorators/queue-consumer.js +0 -40
- package/dist/decorators/scheduled.d.ts +0 -20
- package/dist/decorators/scheduled.js +0 -36
- package/dist/env-ref.d.ts +0 -10
- package/dist/env-ref.js +0 -13
- package/dist/modules/ai.module.d.ts +0 -1
- package/dist/modules/ai.module.js +0 -8
- package/dist/modules/create-binding-module.d.ts +0 -14
- package/dist/modules/create-binding-module.js +0 -42
- package/dist/modules/d1.module.d.ts +0 -1
- package/dist/modules/d1.module.js +0 -8
- package/dist/modules/durable-object.module.d.ts +0 -1
- package/dist/modules/durable-object.module.js +0 -8
- package/dist/modules/env.module.d.ts +0 -17
- package/dist/modules/env.module.js +0 -35
- package/dist/modules/hyperdrive.module.d.ts +0 -1
- package/dist/modules/hyperdrive.module.js +0 -8
- package/dist/modules/kv.module.d.ts +0 -1
- package/dist/modules/kv.module.js +0 -8
- package/dist/modules/queue.module.d.ts +0 -1
- package/dist/modules/queue.module.js +0 -8
- package/dist/modules/r2.module.d.ts +0 -1
- package/dist/modules/r2.module.js +0 -8
- package/dist/modules/vectorize.module.d.ts +0 -1
- package/dist/modules/vectorize.module.js +0 -8
- package/dist/services/ai.service.d.ts +0 -6
- package/dist/services/ai.service.js +0 -33
- package/dist/services/d1.service.d.ts +0 -6
- package/dist/services/d1.service.js +0 -33
- package/dist/services/durable-object.service.d.ts +0 -6
- package/dist/services/durable-object.service.js +0 -33
- package/dist/services/env.service.d.ts +0 -31
- package/dist/services/env.service.js +0 -36
- package/dist/services/flagship-flag.driver.d.ts +0 -57
- package/dist/services/flagship-flag.driver.js +0 -49
- package/dist/services/hyperdrive.service.d.ts +0 -12
- package/dist/services/hyperdrive.service.js +0 -51
- package/dist/services/kv-cache.store.d.ts +0 -19
- package/dist/services/kv-cache.store.js +0 -58
- package/dist/services/kv-flag.driver.d.ts +0 -48
- package/dist/services/kv-flag.driver.js +0 -62
- package/dist/services/kv.service.d.ts +0 -11
- package/dist/services/kv.service.js +0 -33
- package/dist/services/queue.service.d.ts +0 -6
- package/dist/services/queue.service.js +0 -33
- package/dist/services/r2.service.d.ts +0 -6
- package/dist/services/r2.service.js +0 -33
- package/dist/services/vectorize.service.d.ts +0 -6
- package/dist/services/vectorize.service.js +0 -33
- package/dist/storage/index.d.ts +0 -7
- package/dist/storage/index.js +0 -6
- package/dist/storage/r2-storage.driver.d.ts +0 -19
- package/dist/storage/r2-storage.driver.js +0 -61
- package/dist/storage/storage-manager.service.d.ts +0 -16
- package/dist/storage/storage-manager.service.js +0 -56
- package/dist/storage/storage.controller.d.ts +0 -16
- package/dist/storage/storage.controller.js +0 -88
- package/dist/storage/storage.module.d.ts +0 -7
- package/dist/storage/storage.module.js +0 -37
- package/dist/storage/storage.service.d.ts +0 -20
- package/dist/storage/storage.service.js +0 -78
- package/dist/storage/storage.tokens.d.ts +0 -3
- package/dist/storage/storage.tokens.js +0 -2
- package/dist/storage/storage.types.d.ts +0 -17
- package/dist/storage/storage.types.js +0 -1
- package/dist/tokens.d.ts +0 -12
- package/dist/tokens.js +0 -12
- package/dist/types.d.ts +0 -13
- package/dist/types.js +0 -1
- package/dist/websocket/broadcast.d.ts +0 -15
- package/dist/websocket/broadcast.js +0 -26
- package/dist/websocket/cf-room-registry.d.ts +0 -23
- package/dist/websocket/cf-room-registry.js +0 -65
- package/dist/websocket/cf-ws-client.d.ts +0 -28
- package/dist/websocket/cf-ws-client.js +0 -83
- package/dist/websocket/cloudflare-websocket.module.d.ts +0 -11
- package/dist/websocket/cloudflare-websocket.module.js +0 -27
- package/dist/websocket/do-bootstrap.d.ts +0 -21
- package/dist/websocket/do-bootstrap.js +0 -50
- package/dist/websocket/do-state.d.ts +0 -25
- package/dist/websocket/do-state.js +0 -4
- package/dist/websocket/do-websocket-host.d.ts +0 -28
- package/dist/websocket/do-websocket-host.js +0 -69
- package/dist/websocket/index.d.ts +0 -13
- package/dist/websocket/index.js +0 -13
- package/dist/websocket/room-id.d.ts +0 -6
- package/dist/websocket/room-id.js +0 -12
- package/dist/websocket/websocket-routing.d.ts +0 -14
- package/dist/websocket/websocket-routing.js +0 -45
- package/dist/websocket/websocket.durable-object.d.ts +0 -15
- package/dist/websocket/websocket.durable-object.js +0 -72
- package/dist/websocket/ws-server-holder.d.ts +0 -16
- package/dist/websocket/ws-server-holder.js +0 -34
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
}
|
|
7
|
-
function _ts_metadata(k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
}
|
|
10
|
-
function _ts_param(paramIndex, decorator) {
|
|
11
|
-
return function(target, key) {
|
|
12
|
-
decorator(target, key, paramIndex);
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
import { Inject, Injectable } from "@velajs/vela";
|
|
16
|
-
import { KVService } from "./kv.service.js";
|
|
17
|
-
export class KvFlagDriver {
|
|
18
|
-
kv;
|
|
19
|
-
name;
|
|
20
|
-
prefix;
|
|
21
|
-
constructor(kv, options = {}){
|
|
22
|
-
this.kv = kv;
|
|
23
|
-
this.name = options.name ?? 'kv';
|
|
24
|
-
this.prefix = options.prefix ?? '';
|
|
25
|
-
}
|
|
26
|
-
get ns() {
|
|
27
|
-
return this.kv.namespace;
|
|
28
|
-
}
|
|
29
|
-
getBoolean(key, fallback, _ctx) {
|
|
30
|
-
return this.read(key, fallback, (v)=>typeof v === 'boolean');
|
|
31
|
-
}
|
|
32
|
-
getString(key, fallback, _ctx) {
|
|
33
|
-
return this.read(key, fallback, (v)=>typeof v === 'string');
|
|
34
|
-
}
|
|
35
|
-
getNumber(key, fallback, _ctx) {
|
|
36
|
-
return this.read(key, fallback, (v)=>typeof v === 'number');
|
|
37
|
-
}
|
|
38
|
-
getObject(key, fallback, _ctx) {
|
|
39
|
-
return this.read(key, fallback, (v)=>typeof v === 'object' && v !== null);
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Reads and JSON-parses the (prefixed) key, returning the parsed value only
|
|
43
|
-
* when `matches` accepts its type; otherwise the caller's fallback. A missing
|
|
44
|
-
* key reads as `null` → fallback. Read/parse errors are left to propagate.
|
|
45
|
-
*/ async read(key, fallback, matches) {
|
|
46
|
-
const value = await this.ns.get(this.prefix + key, 'json');
|
|
47
|
-
if (value === null || value === undefined) return fallback;
|
|
48
|
-
return matches(value) ? value : fallback;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
KvFlagDriver = _ts_decorate([
|
|
52
|
-
Injectable(),
|
|
53
|
-
_ts_param(0, Inject(KVService)),
|
|
54
|
-
_ts_metadata("design:type", Function),
|
|
55
|
-
_ts_metadata("design:paramtypes", [
|
|
56
|
-
typeof KVService === "undefined" ? Object : KVService,
|
|
57
|
-
typeof KvFlagDriverOptions === "undefined" ? Object : KvFlagDriverOptions
|
|
58
|
-
])
|
|
59
|
-
], KvFlagDriver);
|
|
60
|
-
/** Convenience factory for {@link KvFlagDriver}. */ export function kvFlagDriver(kv, options) {
|
|
61
|
-
return new KvFlagDriver(kv, options);
|
|
62
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { BindingRef } from '../binding-ref';
|
|
2
|
-
/**
|
|
3
|
-
* Wrapper around a Cloudflare KV namespace binding.
|
|
4
|
-
* Use `kv.namespace.get(...)`, `kv.namespace.put(...)`, etc. — the namespace
|
|
5
|
-
* is the standard @cloudflare/workers-types `KVNamespace`.
|
|
6
|
-
*/
|
|
7
|
-
export declare class KVService {
|
|
8
|
-
private ref;
|
|
9
|
-
constructor(ref: BindingRef<KVNamespace>);
|
|
10
|
-
get namespace(): KVNamespace;
|
|
11
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
}
|
|
7
|
-
function _ts_metadata(k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
}
|
|
10
|
-
function _ts_param(paramIndex, decorator) {
|
|
11
|
-
return function(target, key) {
|
|
12
|
-
decorator(target, key, paramIndex);
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
import { Injectable, Inject } from "@velajs/vela";
|
|
16
|
-
import { KV_BINDING_REF } from "../tokens.js";
|
|
17
|
-
export class KVService {
|
|
18
|
-
ref;
|
|
19
|
-
constructor(ref){
|
|
20
|
-
this.ref = ref;
|
|
21
|
-
}
|
|
22
|
-
get namespace() {
|
|
23
|
-
return this.ref.value;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
KVService = _ts_decorate([
|
|
27
|
-
Injectable(),
|
|
28
|
-
_ts_param(0, Inject(KV_BINDING_REF)),
|
|
29
|
-
_ts_metadata("design:type", Function),
|
|
30
|
-
_ts_metadata("design:paramtypes", [
|
|
31
|
-
typeof BindingRef === "undefined" ? Object : BindingRef
|
|
32
|
-
])
|
|
33
|
-
], KVService);
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
}
|
|
7
|
-
function _ts_metadata(k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
}
|
|
10
|
-
function _ts_param(paramIndex, decorator) {
|
|
11
|
-
return function(target, key) {
|
|
12
|
-
decorator(target, key, paramIndex);
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
import { Injectable, Inject } from "@velajs/vela";
|
|
16
|
-
import { QUEUE_BINDING_REF } from "../tokens.js";
|
|
17
|
-
export class QueueService {
|
|
18
|
-
ref;
|
|
19
|
-
constructor(ref){
|
|
20
|
-
this.ref = ref;
|
|
21
|
-
}
|
|
22
|
-
get queue() {
|
|
23
|
-
return this.ref.value;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
QueueService = _ts_decorate([
|
|
27
|
-
Injectable(),
|
|
28
|
-
_ts_param(0, Inject(QUEUE_BINDING_REF)),
|
|
29
|
-
_ts_metadata("design:type", Function),
|
|
30
|
-
_ts_metadata("design:paramtypes", [
|
|
31
|
-
typeof BindingRef === "undefined" ? Object : BindingRef
|
|
32
|
-
])
|
|
33
|
-
], QueueService);
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
}
|
|
7
|
-
function _ts_metadata(k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
}
|
|
10
|
-
function _ts_param(paramIndex, decorator) {
|
|
11
|
-
return function(target, key) {
|
|
12
|
-
decorator(target, key, paramIndex);
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
import { Injectable, Inject } from "@velajs/vela";
|
|
16
|
-
import { R2_BINDING_REF } from "../tokens.js";
|
|
17
|
-
export class R2Service {
|
|
18
|
-
ref;
|
|
19
|
-
constructor(ref){
|
|
20
|
-
this.ref = ref;
|
|
21
|
-
}
|
|
22
|
-
get bucket() {
|
|
23
|
-
return this.ref.value;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
R2Service = _ts_decorate([
|
|
27
|
-
Injectable(),
|
|
28
|
-
_ts_param(0, Inject(R2_BINDING_REF)),
|
|
29
|
-
_ts_metadata("design:type", Function),
|
|
30
|
-
_ts_metadata("design:paramtypes", [
|
|
31
|
-
typeof BindingRef === "undefined" ? Object : BindingRef
|
|
32
|
-
])
|
|
33
|
-
], R2Service);
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
}
|
|
7
|
-
function _ts_metadata(k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
}
|
|
10
|
-
function _ts_param(paramIndex, decorator) {
|
|
11
|
-
return function(target, key) {
|
|
12
|
-
decorator(target, key, paramIndex);
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
import { Injectable, Inject } from "@velajs/vela";
|
|
16
|
-
import { VECTORIZE_BINDING_REF } from "../tokens.js";
|
|
17
|
-
export class VectorizeService {
|
|
18
|
-
ref;
|
|
19
|
-
constructor(ref){
|
|
20
|
-
this.ref = ref;
|
|
21
|
-
}
|
|
22
|
-
get index() {
|
|
23
|
-
return this.ref.value;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
VectorizeService = _ts_decorate([
|
|
27
|
-
Injectable(),
|
|
28
|
-
_ts_param(0, Inject(VECTORIZE_BINDING_REF)),
|
|
29
|
-
_ts_metadata("design:type", Function),
|
|
30
|
-
_ts_metadata("design:paramtypes", [
|
|
31
|
-
typeof BindingRef === "undefined" ? Object : BindingRef
|
|
32
|
-
])
|
|
33
|
-
], VectorizeService);
|
package/dist/storage/index.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export { StorageModule } from './storage.module';
|
|
2
|
-
export { StorageService } from './storage.service';
|
|
3
|
-
export { StorageManagerService } from './storage-manager.service';
|
|
4
|
-
export { StorageController } from './storage.controller';
|
|
5
|
-
export { R2StorageDriver } from './r2-storage.driver';
|
|
6
|
-
export { STORAGE_OPTIONS } from './storage.tokens';
|
|
7
|
-
export type { StorageModuleOptions, DiskConfig, PresignedUrlConfig } from './storage.types';
|
package/dist/storage/index.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export { StorageModule } from "./storage.module.js";
|
|
2
|
-
export { StorageService } from "./storage.service.js";
|
|
3
|
-
export { StorageManagerService } from "./storage-manager.service.js";
|
|
4
|
-
export { StorageController } from "./storage.controller.js";
|
|
5
|
-
export { R2StorageDriver } from "./r2-storage.driver.js";
|
|
6
|
-
export { STORAGE_OPTIONS } from "./storage.tokens.js";
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { type DownloadResult, type PresignedUrlResult, type PresignMethod, type StorageBody, type StorageDriver, type UploadOptions, type UploadResult } from '@velajs/vela/storage';
|
|
2
|
-
/** Base path of the StorageController presign-proxy route. */
|
|
3
|
-
export declare const STORAGE_ROUTE_BASE = "/storage";
|
|
4
|
-
export interface R2StorageDriverConfig {
|
|
5
|
-
disk: string;
|
|
6
|
-
bucket: R2Bucket;
|
|
7
|
-
/** HMAC secret for presigned URLs (typically env.APP_SECRET). */
|
|
8
|
-
secret?: string;
|
|
9
|
-
}
|
|
10
|
-
/** {@link StorageDriver} over a Cloudflare R2 bucket. */
|
|
11
|
-
export declare class R2StorageDriver implements StorageDriver {
|
|
12
|
-
private readonly config;
|
|
13
|
-
constructor(config: R2StorageDriverConfig);
|
|
14
|
-
upload(body: StorageBody, path: string, options: UploadOptions): Promise<UploadResult>;
|
|
15
|
-
download(path: string): Promise<DownloadResult>;
|
|
16
|
-
delete(path: string): Promise<void>;
|
|
17
|
-
exists(path: string): Promise<boolean>;
|
|
18
|
-
getPresignedUrl(path: string, method: PresignMethod, expiresIn: number): Promise<PresignedUrlResult>;
|
|
19
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { signUrl } from "@velajs/vela/storage";
|
|
2
|
-
/** Base path of the StorageController presign-proxy route. */ export const STORAGE_ROUTE_BASE = '/storage';
|
|
3
|
-
/** {@link StorageDriver} over a Cloudflare R2 bucket. */ export class R2StorageDriver {
|
|
4
|
-
config;
|
|
5
|
-
constructor(config){
|
|
6
|
-
this.config = config;
|
|
7
|
-
}
|
|
8
|
-
async upload(body, path, options) {
|
|
9
|
-
await this.config.bucket.put(path, body, {
|
|
10
|
-
httpMetadata: options.mimeType ? {
|
|
11
|
-
contentType: options.mimeType
|
|
12
|
-
} : undefined,
|
|
13
|
-
customMetadata: options.metadata
|
|
14
|
-
});
|
|
15
|
-
return {
|
|
16
|
-
path,
|
|
17
|
-
disk: this.config.disk,
|
|
18
|
-
size: options.size,
|
|
19
|
-
mimeType: options.mimeType ?? 'application/octet-stream',
|
|
20
|
-
uploadedAt: new Date()
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
async download(path) {
|
|
24
|
-
const obj = await this.config.bucket.get(path);
|
|
25
|
-
if (!obj) throw new Error(`Storage object not found at "${path}".`);
|
|
26
|
-
return {
|
|
27
|
-
toStream: ()=>obj.body,
|
|
28
|
-
toArrayBuffer: ()=>obj.arrayBuffer(),
|
|
29
|
-
toText: ()=>obj.text(),
|
|
30
|
-
contentType: obj.httpMetadata?.contentType ?? 'application/octet-stream',
|
|
31
|
-
size: obj.size,
|
|
32
|
-
metadata: obj.customMetadata
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
async delete(path) {
|
|
36
|
-
await this.config.bucket.delete(path);
|
|
37
|
-
}
|
|
38
|
-
async exists(path) {
|
|
39
|
-
return await this.config.bucket.head(path) !== null;
|
|
40
|
-
}
|
|
41
|
-
async getPresignedUrl(path, method, expiresIn) {
|
|
42
|
-
if (!this.config.secret) {
|
|
43
|
-
throw new Error('A signing secret is required for presigned URLs (set APP_SECRET).');
|
|
44
|
-
}
|
|
45
|
-
// Defend the direct-driver path too: a non-finite/non-positive expiry would
|
|
46
|
-
// make signUrl omit `expires`, yielding a never-expiring URL.
|
|
47
|
-
if (!Number.isFinite(expiresIn) || expiresIn <= 0) {
|
|
48
|
-
throw new Error(`Invalid presigned URL expiry: ${expiresIn}s (must be a positive number).`);
|
|
49
|
-
}
|
|
50
|
-
const routePath = `${STORAGE_ROUTE_BASE}/${this.config.disk}/${path}`;
|
|
51
|
-
const url = await signUrl(`${routePath}?method=${method}`, this.config.secret, {
|
|
52
|
-
expiresIn
|
|
53
|
-
});
|
|
54
|
-
return {
|
|
55
|
-
url,
|
|
56
|
-
method,
|
|
57
|
-
expiresIn,
|
|
58
|
-
expiresAt: new Date(Date.now() + expiresIn * 1000)
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { EnvService } from '../services/env.service';
|
|
2
|
-
import { R2StorageDriver } from './r2-storage.driver';
|
|
3
|
-
import type { DiskConfig, StorageModuleOptions } from './storage.types';
|
|
4
|
-
/**
|
|
5
|
-
* Resolves R2 buckets by binding NAME (via {@link EnvService}) so multiple disks
|
|
6
|
-
* coexist without registering N R2Modules. Drivers are created per call — cheap,
|
|
7
|
-
* and avoids caching a per-request env value on this singleton.
|
|
8
|
-
*/
|
|
9
|
-
export declare class StorageManagerService {
|
|
10
|
-
private readonly options;
|
|
11
|
-
private readonly env;
|
|
12
|
-
constructor(options: StorageModuleOptions, env: EnvService);
|
|
13
|
-
hasDisk(disk: string): boolean;
|
|
14
|
-
getDiskConfig(disk: string): DiskConfig;
|
|
15
|
-
getDriver(disk: string): R2StorageDriver;
|
|
16
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
}
|
|
7
|
-
function _ts_metadata(k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
}
|
|
10
|
-
function _ts_param(paramIndex, decorator) {
|
|
11
|
-
return function(target, key) {
|
|
12
|
-
decorator(target, key, paramIndex);
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
import { Inject, Injectable } from "@velajs/vela";
|
|
16
|
-
import { EnvService } from "../services/env.service.js";
|
|
17
|
-
import { R2StorageDriver } from "./r2-storage.driver.js";
|
|
18
|
-
import { STORAGE_OPTIONS } from "./storage.tokens.js";
|
|
19
|
-
export class StorageManagerService {
|
|
20
|
-
options;
|
|
21
|
-
env;
|
|
22
|
-
constructor(options, env){
|
|
23
|
-
this.options = options;
|
|
24
|
-
this.env = env;
|
|
25
|
-
}
|
|
26
|
-
hasDisk(disk) {
|
|
27
|
-
return this.options.disks.some((d)=>d.disk === disk);
|
|
28
|
-
}
|
|
29
|
-
getDiskConfig(disk) {
|
|
30
|
-
const config = this.options.disks.find((d)=>d.disk === disk);
|
|
31
|
-
if (!config) throw new Error(`Storage disk "${disk}" is not configured.`);
|
|
32
|
-
return config;
|
|
33
|
-
}
|
|
34
|
-
getDriver(disk) {
|
|
35
|
-
const config = this.getDiskConfig(disk);
|
|
36
|
-
const bucket = this.env.get(config.binding);
|
|
37
|
-
if (!bucket) {
|
|
38
|
-
throw new Error(`R2 binding "${config.binding}" for disk "${disk}" was not found in env.`);
|
|
39
|
-
}
|
|
40
|
-
return new R2StorageDriver({
|
|
41
|
-
disk,
|
|
42
|
-
bucket,
|
|
43
|
-
secret: this.env.get('APP_SECRET')
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
StorageManagerService = _ts_decorate([
|
|
48
|
-
Injectable(),
|
|
49
|
-
_ts_param(0, Inject(STORAGE_OPTIONS)),
|
|
50
|
-
_ts_param(1, Inject(EnvService)),
|
|
51
|
-
_ts_metadata("design:type", Function),
|
|
52
|
-
_ts_metadata("design:paramtypes", [
|
|
53
|
-
typeof StorageModuleOptions === "undefined" ? Object : StorageModuleOptions,
|
|
54
|
-
typeof EnvService === "undefined" ? Object : EnvService
|
|
55
|
-
])
|
|
56
|
-
], StorageManagerService);
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { Context } from 'hono';
|
|
2
|
-
import { EnvService } from '../services/env.service';
|
|
3
|
-
import { StorageManagerService } from './storage-manager.service';
|
|
4
|
-
/**
|
|
5
|
-
* Presign-proxy: serves objects for HMAC-signed URLs produced by
|
|
6
|
-
* `StorageService.url()`. R2 has no native presign, so a signed URL points here;
|
|
7
|
-
* this route verifies the signature (+expiry) before streaming the object.
|
|
8
|
-
* The wildcard is the FULL object path (root already applied at sign time), so
|
|
9
|
-
* it is passed straight to the driver.
|
|
10
|
-
*/
|
|
11
|
-
export declare class StorageController {
|
|
12
|
-
private readonly manager;
|
|
13
|
-
private readonly env;
|
|
14
|
-
constructor(manager: StorageManagerService, env: EnvService);
|
|
15
|
-
download(c: Context): Promise<Response>;
|
|
16
|
-
}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
}
|
|
7
|
-
function _ts_metadata(k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
}
|
|
10
|
-
function _ts_param(paramIndex, decorator) {
|
|
11
|
-
return function(target, key) {
|
|
12
|
-
decorator(target, key, paramIndex);
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
import { Controller, Get, Inject, Req } from "@velajs/vela";
|
|
16
|
-
import { verifySignedUrl } from "@velajs/vela/storage";
|
|
17
|
-
import { EnvService } from "../services/env.service.js";
|
|
18
|
-
import { StorageManagerService } from "./storage-manager.service.js";
|
|
19
|
-
export class StorageController {
|
|
20
|
-
manager;
|
|
21
|
-
env;
|
|
22
|
-
constructor(manager, env){
|
|
23
|
-
this.manager = manager;
|
|
24
|
-
this.env = env;
|
|
25
|
-
}
|
|
26
|
-
async download(c) {
|
|
27
|
-
const secret = this.env.get('APP_SECRET');
|
|
28
|
-
if (!secret) return new Response('Storage signing is not configured', {
|
|
29
|
-
status: 500
|
|
30
|
-
});
|
|
31
|
-
const disk = c.req.param('disk');
|
|
32
|
-
if (!disk || !this.manager.hasDisk(disk)) return new Response('Unknown disk', {
|
|
33
|
-
status: 404
|
|
34
|
-
});
|
|
35
|
-
if (!await verifySignedUrl(c.req.url, secret)) {
|
|
36
|
-
return new Response('Invalid or expired URL', {
|
|
37
|
-
status: 403
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
// Enforce the signed `method` scope: this proxy only serves reads, so a URL
|
|
41
|
-
// scoped to PUT/DELETE/HEAD must NOT be honored as a GET (it would over-grant
|
|
42
|
-
// read access relative to the token's intended scope). The param is part of
|
|
43
|
-
// the signed payload, so it is trustworthy once the signature verifies.
|
|
44
|
-
const url = new URL(c.req.url);
|
|
45
|
-
if ((url.searchParams.get('method') ?? 'GET') !== 'GET') {
|
|
46
|
-
return new Response('URL is not scoped for reads', {
|
|
47
|
-
status: 403
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
// The object key is everything after `/storage/:disk/` (Hono doesn't expose
|
|
51
|
-
// the `*` wildcard via param()). The key already includes the disk root.
|
|
52
|
-
const { pathname } = url;
|
|
53
|
-
const prefix = `/storage/${disk}/`;
|
|
54
|
-
const idx = pathname.indexOf(prefix);
|
|
55
|
-
const fullPath = idx >= 0 ? decodeURIComponent(pathname.slice(idx + prefix.length)) : '';
|
|
56
|
-
try {
|
|
57
|
-
const result = await this.manager.getDriver(disk).download(fullPath);
|
|
58
|
-
return new Response(result.toStream(), {
|
|
59
|
-
headers: {
|
|
60
|
-
'content-type': result.contentType
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
} catch {
|
|
64
|
-
return new Response('Not found', {
|
|
65
|
-
status: 404
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
_ts_decorate([
|
|
71
|
-
Get('/:disk/*'),
|
|
72
|
-
_ts_param(0, Req()),
|
|
73
|
-
_ts_metadata("design:type", Function),
|
|
74
|
-
_ts_metadata("design:paramtypes", [
|
|
75
|
-
typeof Context === "undefined" ? Object : Context
|
|
76
|
-
]),
|
|
77
|
-
_ts_metadata("design:returntype", Promise)
|
|
78
|
-
], StorageController.prototype, "download", null);
|
|
79
|
-
StorageController = _ts_decorate([
|
|
80
|
-
Controller('storage'),
|
|
81
|
-
_ts_param(0, Inject(StorageManagerService)),
|
|
82
|
-
_ts_param(1, Inject(EnvService)),
|
|
83
|
-
_ts_metadata("design:type", Function),
|
|
84
|
-
_ts_metadata("design:paramtypes", [
|
|
85
|
-
typeof StorageManagerService === "undefined" ? Object : StorageManagerService,
|
|
86
|
-
typeof EnvService === "undefined" ? Object : EnvService
|
|
87
|
-
])
|
|
88
|
-
], StorageController);
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { StorageModuleOptions } from './storage.types';
|
|
2
|
-
declare const ConfigurableModuleClass: import("@velajs/vela").ConfigurableModuleClassType<StorageModuleOptions, "forRoot", "create", {
|
|
3
|
-
isGlobal?: boolean;
|
|
4
|
-
}>;
|
|
5
|
-
export declare class StorageModule extends ConfigurableModuleClass {
|
|
6
|
-
}
|
|
7
|
-
export {};
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
}
|
|
7
|
-
import { ConfigurableModuleBuilder, Module } from "@velajs/vela";
|
|
8
|
-
import { EnvModule } from "../modules/env.module.js";
|
|
9
|
-
import { StorageController } from "./storage.controller.js";
|
|
10
|
-
import { StorageManagerService } from "./storage-manager.service.js";
|
|
11
|
-
import { StorageService } from "./storage.service.js";
|
|
12
|
-
import { STORAGE_OPTIONS } from "./storage.tokens.js";
|
|
13
|
-
const { ConfigurableModuleClass } = new ConfigurableModuleBuilder({
|
|
14
|
-
moduleName: 'Storage',
|
|
15
|
-
optionsInjectionToken: STORAGE_OPTIONS
|
|
16
|
-
}).build();
|
|
17
|
-
export class StorageModule extends ConfigurableModuleClass {
|
|
18
|
-
}
|
|
19
|
-
StorageModule = _ts_decorate([
|
|
20
|
-
Module({
|
|
21
|
-
imports: [
|
|
22
|
-
EnvModule.forRoot()
|
|
23
|
-
],
|
|
24
|
-
providers: [
|
|
25
|
-
StorageManagerService,
|
|
26
|
-
StorageService
|
|
27
|
-
],
|
|
28
|
-
controllers: [
|
|
29
|
-
StorageController
|
|
30
|
-
],
|
|
31
|
-
exports: [
|
|
32
|
-
StorageService,
|
|
33
|
-
StorageManagerService,
|
|
34
|
-
STORAGE_OPTIONS
|
|
35
|
-
]
|
|
36
|
-
})
|
|
37
|
-
], StorageModule);
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { type DownloadResult, type PresignedUrlResult, type PresignMethod, type StorageBody, type UploadOptions, type UploadResult } from '@velajs/vela/storage';
|
|
2
|
-
import { StorageManagerService } from './storage-manager.service';
|
|
3
|
-
import type { StorageModuleOptions } from './storage.types';
|
|
4
|
-
/**
|
|
5
|
-
* Multi-disk storage facade. Applies each disk's (templated) root, resolves the
|
|
6
|
-
* driver, and validates presign expiry. Injectable anywhere via `StorageService`.
|
|
7
|
-
*/
|
|
8
|
-
export declare class StorageService {
|
|
9
|
-
private readonly options;
|
|
10
|
-
private readonly manager;
|
|
11
|
-
constructor(options: StorageModuleOptions, manager: StorageManagerService);
|
|
12
|
-
put(relativePath: string, body: StorageBody, options?: UploadOptions, disk?: string): Promise<UploadResult>;
|
|
13
|
-
get(relativePath: string, disk?: string): Promise<DownloadResult>;
|
|
14
|
-
delete(relativePath: string, disk?: string): Promise<void>;
|
|
15
|
-
exists(relativePath: string, disk?: string): Promise<boolean>;
|
|
16
|
-
url(relativePath: string, method?: PresignMethod, expiresIn?: number, disk?: string): Promise<PresignedUrlResult>;
|
|
17
|
-
private resolveDisk;
|
|
18
|
-
private fullPath;
|
|
19
|
-
private validateExpiry;
|
|
20
|
-
}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
}
|
|
7
|
-
function _ts_metadata(k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
}
|
|
10
|
-
function _ts_param(paramIndex, decorator) {
|
|
11
|
-
return function(target, key) {
|
|
12
|
-
decorator(target, key, paramIndex);
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
import { Inject, Injectable } from "@velajs/vela";
|
|
16
|
-
import { joinStoragePath } from "@velajs/vela/storage";
|
|
17
|
-
import { StorageManagerService } from "./storage-manager.service.js";
|
|
18
|
-
import { STORAGE_OPTIONS } from "./storage.tokens.js";
|
|
19
|
-
const DEFAULT_PRESIGN = {
|
|
20
|
-
defaultExpiry: 3600,
|
|
21
|
-
maxExpiry: 86400
|
|
22
|
-
};
|
|
23
|
-
export class StorageService {
|
|
24
|
-
options;
|
|
25
|
-
manager;
|
|
26
|
-
constructor(options, manager){
|
|
27
|
-
this.options = options;
|
|
28
|
-
this.manager = manager;
|
|
29
|
-
}
|
|
30
|
-
put(relativePath, body, options = {}, disk) {
|
|
31
|
-
const name = this.resolveDisk(disk);
|
|
32
|
-
return this.manager.getDriver(name).upload(body, this.fullPath(relativePath, name), options);
|
|
33
|
-
}
|
|
34
|
-
get(relativePath, disk) {
|
|
35
|
-
const name = this.resolveDisk(disk);
|
|
36
|
-
return this.manager.getDriver(name).download(this.fullPath(relativePath, name));
|
|
37
|
-
}
|
|
38
|
-
delete(relativePath, disk) {
|
|
39
|
-
const name = this.resolveDisk(disk);
|
|
40
|
-
return this.manager.getDriver(name).delete(this.fullPath(relativePath, name));
|
|
41
|
-
}
|
|
42
|
-
exists(relativePath, disk) {
|
|
43
|
-
const name = this.resolveDisk(disk);
|
|
44
|
-
return this.manager.getDriver(name).exists(this.fullPath(relativePath, name));
|
|
45
|
-
}
|
|
46
|
-
url(relativePath, method = 'GET', expiresIn, disk) {
|
|
47
|
-
const name = this.resolveDisk(disk);
|
|
48
|
-
return this.manager.getDriver(name).getPresignedUrl(this.fullPath(relativePath, name), method, this.validateExpiry(expiresIn));
|
|
49
|
-
}
|
|
50
|
-
resolveDisk(disk) {
|
|
51
|
-
const name = disk ?? this.options.defaultDisk;
|
|
52
|
-
if (!this.manager.hasDisk(name)) throw new Error(`Storage disk "${name}" is not configured.`);
|
|
53
|
-
return name;
|
|
54
|
-
}
|
|
55
|
-
fullPath(relativePath, disk) {
|
|
56
|
-
return joinStoragePath(this.manager.getDiskConfig(disk).root, relativePath);
|
|
57
|
-
}
|
|
58
|
-
validateExpiry(expiresIn) {
|
|
59
|
-
const cfg = this.options.presignedUrl ?? DEFAULT_PRESIGN;
|
|
60
|
-
const value = expiresIn ?? cfg.defaultExpiry;
|
|
61
|
-
// `Number.isFinite` rejects NaN — otherwise `NaN < 1 || NaN > max` is false,
|
|
62
|
-
// NaN slips through, signUrl omits `expires`, and the URL never expires.
|
|
63
|
-
if (!Number.isFinite(value) || value < 1 || value > cfg.maxExpiry) {
|
|
64
|
-
throw new Error(`Presigned URL expiry ${value}s is out of range (1–${cfg.maxExpiry}s).`);
|
|
65
|
-
}
|
|
66
|
-
return value;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
StorageService = _ts_decorate([
|
|
70
|
-
Injectable(),
|
|
71
|
-
_ts_param(0, Inject(STORAGE_OPTIONS)),
|
|
72
|
-
_ts_param(1, Inject(StorageManagerService)),
|
|
73
|
-
_ts_metadata("design:type", Function),
|
|
74
|
-
_ts_metadata("design:paramtypes", [
|
|
75
|
-
typeof StorageModuleOptions === "undefined" ? Object : StorageModuleOptions,
|
|
76
|
-
typeof StorageManagerService === "undefined" ? Object : StorageManagerService
|
|
77
|
-
])
|
|
78
|
-
], StorageService);
|