@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,17 +0,0 @@
|
|
|
1
|
-
import type { DynamicModule } from '@velajs/vela';
|
|
2
|
-
/**
|
|
3
|
-
* Provides {@link EnvService} GLOBALLY so any module's provider factories can
|
|
4
|
-
* `inject: [EnvService]`. Register once on the root module:
|
|
5
|
-
*
|
|
6
|
-
* ```ts
|
|
7
|
-
* @Module({ imports: [EnvModule.forRoot(), AuthModule.forRootAsync({ ... })] })
|
|
8
|
-
* class AppModule {}
|
|
9
|
-
* ```
|
|
10
|
-
*
|
|
11
|
-
* The {@link EnvRef} it provides is collected and initialized by
|
|
12
|
-
* createCloudflareApp's binding-init middleware on the first request (the
|
|
13
|
-
* factory passes it the full `env`, not a single binding).
|
|
14
|
-
*/
|
|
15
|
-
export declare class EnvModule {
|
|
16
|
-
static forRoot(): DynamicModule;
|
|
17
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { EnvRef } from "../env-ref.js";
|
|
2
|
-
import { EnvService } from "../services/env.service.js";
|
|
3
|
-
import { ENV_REF } from "../tokens.js";
|
|
4
|
-
/**
|
|
5
|
-
* Provides {@link EnvService} GLOBALLY so any module's provider factories can
|
|
6
|
-
* `inject: [EnvService]`. Register once on the root module:
|
|
7
|
-
*
|
|
8
|
-
* ```ts
|
|
9
|
-
* @Module({ imports: [EnvModule.forRoot(), AuthModule.forRootAsync({ ... })] })
|
|
10
|
-
* class AppModule {}
|
|
11
|
-
* ```
|
|
12
|
-
*
|
|
13
|
-
* The {@link EnvRef} it provides is collected and initialized by
|
|
14
|
-
* createCloudflareApp's binding-init middleware on the first request (the
|
|
15
|
-
* factory passes it the full `env`, not a single binding).
|
|
16
|
-
*/ export class EnvModule {
|
|
17
|
-
static forRoot() {
|
|
18
|
-
const ref = new EnvRef();
|
|
19
|
-
return {
|
|
20
|
-
module: EnvModule,
|
|
21
|
-
global: true,
|
|
22
|
-
providers: [
|
|
23
|
-
{
|
|
24
|
-
provide: ENV_REF,
|
|
25
|
-
useValue: ref
|
|
26
|
-
},
|
|
27
|
-
EnvService
|
|
28
|
-
],
|
|
29
|
-
exports: [
|
|
30
|
-
EnvService,
|
|
31
|
-
ENV_REF
|
|
32
|
-
]
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const HyperdriveModule: import("./create-binding-module").BindingModuleStatic;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { HyperdriveService } from "../services/hyperdrive.service.js";
|
|
2
|
-
import { HYPERDRIVE_BINDING_REF } from "../tokens.js";
|
|
3
|
-
import { createBindingModule } from "./create-binding-module.js";
|
|
4
|
-
export const HyperdriveModule = createBindingModule({
|
|
5
|
-
name: 'Hyperdrive',
|
|
6
|
-
serviceClass: HyperdriveService,
|
|
7
|
-
bindingRefToken: HYPERDRIVE_BINDING_REF
|
|
8
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const KVModule: import("./create-binding-module").BindingModuleStatic;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { KVService } from "../services/kv.service.js";
|
|
2
|
-
import { KV_BINDING_REF } from "../tokens.js";
|
|
3
|
-
import { createBindingModule } from "./create-binding-module.js";
|
|
4
|
-
export const KVModule = createBindingModule({
|
|
5
|
-
name: 'KV',
|
|
6
|
-
serviceClass: KVService,
|
|
7
|
-
bindingRefToken: KV_BINDING_REF
|
|
8
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const QueueModule: import("./create-binding-module").BindingModuleStatic;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { QueueService } from "../services/queue.service.js";
|
|
2
|
-
import { QUEUE_BINDING_REF } from "../tokens.js";
|
|
3
|
-
import { createBindingModule } from "./create-binding-module.js";
|
|
4
|
-
export const QueueModule = createBindingModule({
|
|
5
|
-
name: 'Queue',
|
|
6
|
-
serviceClass: QueueService,
|
|
7
|
-
bindingRefToken: QUEUE_BINDING_REF
|
|
8
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const R2Module: import("./create-binding-module").BindingModuleStatic;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { R2Service } from "../services/r2.service.js";
|
|
2
|
-
import { R2_BINDING_REF } from "../tokens.js";
|
|
3
|
-
import { createBindingModule } from "./create-binding-module.js";
|
|
4
|
-
export const R2Module = createBindingModule({
|
|
5
|
-
name: 'R2',
|
|
6
|
-
serviceClass: R2Service,
|
|
7
|
-
bindingRefToken: R2_BINDING_REF
|
|
8
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const VectorizeModule: import("./create-binding-module").BindingModuleStatic;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { VectorizeService } from "../services/vectorize.service.js";
|
|
2
|
-
import { VECTORIZE_BINDING_REF } from "../tokens.js";
|
|
3
|
-
import { createBindingModule } from "./create-binding-module.js";
|
|
4
|
-
export const VectorizeModule = createBindingModule({
|
|
5
|
-
name: 'Vectorize',
|
|
6
|
-
serviceClass: VectorizeService,
|
|
7
|
-
bindingRefToken: VECTORIZE_BINDING_REF
|
|
8
|
-
});
|
|
@@ -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 { AI_BINDING_REF } from "../tokens.js";
|
|
17
|
-
export class AIService {
|
|
18
|
-
ref;
|
|
19
|
-
constructor(ref){
|
|
20
|
-
this.ref = ref;
|
|
21
|
-
}
|
|
22
|
-
get binding() {
|
|
23
|
-
return this.ref.value;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
AIService = _ts_decorate([
|
|
27
|
-
Injectable(),
|
|
28
|
-
_ts_param(0, Inject(AI_BINDING_REF)),
|
|
29
|
-
_ts_metadata("design:type", Function),
|
|
30
|
-
_ts_metadata("design:paramtypes", [
|
|
31
|
-
typeof BindingRef === "undefined" ? Object : BindingRef
|
|
32
|
-
])
|
|
33
|
-
], AIService);
|
|
@@ -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 { D1_BINDING_REF } from "../tokens.js";
|
|
17
|
-
export class D1Service {
|
|
18
|
-
ref;
|
|
19
|
-
constructor(ref){
|
|
20
|
-
this.ref = ref;
|
|
21
|
-
}
|
|
22
|
-
get database() {
|
|
23
|
-
return this.ref.value;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
D1Service = _ts_decorate([
|
|
27
|
-
Injectable(),
|
|
28
|
-
_ts_param(0, Inject(D1_BINDING_REF)),
|
|
29
|
-
_ts_metadata("design:type", Function),
|
|
30
|
-
_ts_metadata("design:paramtypes", [
|
|
31
|
-
typeof BindingRef === "undefined" ? Object : BindingRef
|
|
32
|
-
])
|
|
33
|
-
], D1Service);
|
|
@@ -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 { DO_BINDING_REF } from "../tokens.js";
|
|
17
|
-
export class DurableObjectService {
|
|
18
|
-
ref;
|
|
19
|
-
constructor(ref){
|
|
20
|
-
this.ref = ref;
|
|
21
|
-
}
|
|
22
|
-
get namespace() {
|
|
23
|
-
return this.ref.value;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
DurableObjectService = _ts_decorate([
|
|
27
|
-
Injectable(),
|
|
28
|
-
_ts_param(0, Inject(DO_BINDING_REF)),
|
|
29
|
-
_ts_metadata("design:type", Function),
|
|
30
|
-
_ts_metadata("design:paramtypes", [
|
|
31
|
-
typeof BindingRef === "undefined" ? Object : BindingRef
|
|
32
|
-
])
|
|
33
|
-
], DurableObjectService);
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type { EnvRef } from '../env-ref';
|
|
2
|
-
/**
|
|
3
|
-
* Injectable access to the full Cloudflare Worker `env` (bindings + vars +
|
|
4
|
-
* secrets).
|
|
5
|
-
*
|
|
6
|
-
* The per-binding services (`D1Service`, `KVService`, …) each expose a single
|
|
7
|
-
* binding, and the `@Env()` param decorator only works inside a request-scoped
|
|
8
|
-
* controller handler. `EnvService` fills the gap: it can be injected into
|
|
9
|
-
* PROVIDER FACTORIES — e.g. `SomeModule.forRootAsync({ inject: [EnvService] })`
|
|
10
|
-
* — so a factory can read secrets/origins without reaching for the request.
|
|
11
|
-
*
|
|
12
|
-
* Reads are lazy. `env` only exists per request, so a factory (which runs at
|
|
13
|
-
* bootstrap) must capture the `EnvService` and read inside its callback:
|
|
14
|
-
*
|
|
15
|
-
* ```ts
|
|
16
|
-
* AuthModule.forRootAsync({
|
|
17
|
-
* inject: [EnvService],
|
|
18
|
-
* useFactory: (env: EnvService) => buildAuth(() => env.get<string>('AUTH_SECRET')),
|
|
19
|
-
* });
|
|
20
|
-
* ```
|
|
21
|
-
*
|
|
22
|
-
* Reading eagerly at bootstrap (`env.get(...)` before any request) throws.
|
|
23
|
-
*/
|
|
24
|
-
export declare class EnvService {
|
|
25
|
-
private ref;
|
|
26
|
-
constructor(ref: EnvRef);
|
|
27
|
-
/** The full env record. Throws if read before the first request. */
|
|
28
|
-
get env(): Record<string, unknown>;
|
|
29
|
-
/** Read a single env entry (binding, var, or secret) by name. */
|
|
30
|
-
get<T = unknown>(key: string): T | undefined;
|
|
31
|
-
}
|
|
@@ -1,36 +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 { ENV_REF } from "../tokens.js";
|
|
17
|
-
export class EnvService {
|
|
18
|
-
ref;
|
|
19
|
-
constructor(ref){
|
|
20
|
-
this.ref = ref;
|
|
21
|
-
}
|
|
22
|
-
/** The full env record. Throws if read before the first request. */ get env() {
|
|
23
|
-
return this.ref.value;
|
|
24
|
-
}
|
|
25
|
-
/** Read a single env entry (binding, var, or secret) by name. */ get(key) {
|
|
26
|
-
return this.ref.value[key];
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
EnvService = _ts_decorate([
|
|
30
|
-
Injectable(),
|
|
31
|
-
_ts_param(0, Inject(ENV_REF)),
|
|
32
|
-
_ts_metadata("design:type", Function),
|
|
33
|
-
_ts_metadata("design:paramtypes", [
|
|
34
|
-
typeof EnvRef === "undefined" ? Object : EnvRef
|
|
35
|
-
])
|
|
36
|
-
], EnvService);
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import type { FeatureFlagDriver, FlagContext } from '@velajs/feature-flags';
|
|
2
|
-
/**
|
|
3
|
-
* The subset of a Cloudflare **Flagship** binding this driver evaluates against
|
|
4
|
-
* — the four typed value methods. The binding itself returns the supplied
|
|
5
|
-
* `defaultValue` on evaluation errors; transport-level failures reject and are
|
|
6
|
-
* left to propagate (never-throw is the service layer's job, not the driver's).
|
|
7
|
-
*
|
|
8
|
-
* @see https://developers.cloudflare.com/flagship/binding/
|
|
9
|
-
*/
|
|
10
|
-
export interface FlagshipBinding {
|
|
11
|
-
getBooleanValue(key: string, defaultValue: boolean, context?: FlagContext): Promise<boolean>;
|
|
12
|
-
getStringValue(key: string, defaultValue: string, context?: FlagContext): Promise<string>;
|
|
13
|
-
getNumberValue(key: string, defaultValue: number, context?: FlagContext): Promise<number>;
|
|
14
|
-
getObjectValue<T extends object>(key: string, defaultValue: T, context?: FlagContext): Promise<T>;
|
|
15
|
-
}
|
|
16
|
-
export interface FlagshipFlagDriverOptions {
|
|
17
|
-
/** Driver name used for `use(name)` / default-driver selection. Default `"flagship"`. */
|
|
18
|
-
name?: string;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* {@link FeatureFlagDriver} backed by a Cloudflare Flagship binding.
|
|
22
|
-
*
|
|
23
|
-
* A thin, honest wrapper: each contract method maps 1:1 onto the binding's
|
|
24
|
-
* corresponding value method, forwarding the caller's `fallback` (the binding's
|
|
25
|
-
* `defaultValue`) and evaluation context. The binding resolves the fallback on
|
|
26
|
-
* evaluation errors; anything the binding *rejects* with (e.g. a `remote: true`
|
|
27
|
-
* dev-proxy tunnel dropping) propagates — `@velajs/feature-flags`'s service owns
|
|
28
|
-
* the never-throw guarantee.
|
|
29
|
-
*
|
|
30
|
-
* The binding only exists per request in a Worker, so pass a lazy accessor when
|
|
31
|
-
* wiring from a bootstrap factory (mirroring how {@link EnvService} reads are
|
|
32
|
-
* deferred); a resolved binding may be passed directly in tests.
|
|
33
|
-
*
|
|
34
|
-
* ```ts
|
|
35
|
-
* FeatureFlagsModule.forRootAsync({
|
|
36
|
-
* inject: [EnvService],
|
|
37
|
-
* useFactory: (env: EnvService) => ({
|
|
38
|
-
* drivers: [flagshipFlagDriver(() => env.get<FlagshipBinding>('FLAGS')!)],
|
|
39
|
-
* }),
|
|
40
|
-
* });
|
|
41
|
-
* ```
|
|
42
|
-
*
|
|
43
|
-
* Evaluation ergonomics (the 1:1 binding-method mapping) are ported from the
|
|
44
|
-
* Stratal feature-flags service (MIT, © Temitayo Fadojutimi), reshaped as a
|
|
45
|
-
* bare driver.
|
|
46
|
-
*/
|
|
47
|
-
export declare class FlagshipFlagDriver implements FeatureFlagDriver {
|
|
48
|
-
readonly name: string;
|
|
49
|
-
private readonly resolve;
|
|
50
|
-
constructor(binding: FlagshipBinding | (() => FlagshipBinding), options?: FlagshipFlagDriverOptions);
|
|
51
|
-
getBoolean(key: string, fallback: boolean, ctx?: FlagContext): Promise<boolean>;
|
|
52
|
-
getString(key: string, fallback: string, ctx?: FlagContext): Promise<string>;
|
|
53
|
-
getNumber(key: string, fallback: number, ctx?: FlagContext): Promise<number>;
|
|
54
|
-
getObject<T extends object>(key: string, fallback: T, ctx?: FlagContext): Promise<T>;
|
|
55
|
-
}
|
|
56
|
-
/** Convenience factory for {@link FlagshipFlagDriver}. */
|
|
57
|
-
export declare function flagshipFlagDriver(binding: FlagshipBinding | (() => FlagshipBinding), options?: FlagshipFlagDriverOptions): FlagshipFlagDriver;
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* {@link FeatureFlagDriver} backed by a Cloudflare Flagship binding.
|
|
3
|
-
*
|
|
4
|
-
* A thin, honest wrapper: each contract method maps 1:1 onto the binding's
|
|
5
|
-
* corresponding value method, forwarding the caller's `fallback` (the binding's
|
|
6
|
-
* `defaultValue`) and evaluation context. The binding resolves the fallback on
|
|
7
|
-
* evaluation errors; anything the binding *rejects* with (e.g. a `remote: true`
|
|
8
|
-
* dev-proxy tunnel dropping) propagates — `@velajs/feature-flags`'s service owns
|
|
9
|
-
* the never-throw guarantee.
|
|
10
|
-
*
|
|
11
|
-
* The binding only exists per request in a Worker, so pass a lazy accessor when
|
|
12
|
-
* wiring from a bootstrap factory (mirroring how {@link EnvService} reads are
|
|
13
|
-
* deferred); a resolved binding may be passed directly in tests.
|
|
14
|
-
*
|
|
15
|
-
* ```ts
|
|
16
|
-
* FeatureFlagsModule.forRootAsync({
|
|
17
|
-
* inject: [EnvService],
|
|
18
|
-
* useFactory: (env: EnvService) => ({
|
|
19
|
-
* drivers: [flagshipFlagDriver(() => env.get<FlagshipBinding>('FLAGS')!)],
|
|
20
|
-
* }),
|
|
21
|
-
* });
|
|
22
|
-
* ```
|
|
23
|
-
*
|
|
24
|
-
* Evaluation ergonomics (the 1:1 binding-method mapping) are ported from the
|
|
25
|
-
* Stratal feature-flags service (MIT, © Temitayo Fadojutimi), reshaped as a
|
|
26
|
-
* bare driver.
|
|
27
|
-
*/ export class FlagshipFlagDriver {
|
|
28
|
-
name;
|
|
29
|
-
resolve;
|
|
30
|
-
constructor(binding, options = {}){
|
|
31
|
-
this.resolve = typeof binding === 'function' ? binding : ()=>binding;
|
|
32
|
-
this.name = options.name ?? 'flagship';
|
|
33
|
-
}
|
|
34
|
-
getBoolean(key, fallback, ctx) {
|
|
35
|
-
return this.resolve().getBooleanValue(key, fallback, ctx);
|
|
36
|
-
}
|
|
37
|
-
getString(key, fallback, ctx) {
|
|
38
|
-
return this.resolve().getStringValue(key, fallback, ctx);
|
|
39
|
-
}
|
|
40
|
-
getNumber(key, fallback, ctx) {
|
|
41
|
-
return this.resolve().getNumberValue(key, fallback, ctx);
|
|
42
|
-
}
|
|
43
|
-
getObject(key, fallback, ctx) {
|
|
44
|
-
return this.resolve().getObjectValue(key, fallback, ctx);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
/** Convenience factory for {@link FlagshipFlagDriver}. */ export function flagshipFlagDriver(binding, options) {
|
|
48
|
-
return new FlagshipFlagDriver(binding, options);
|
|
49
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { BindingRef } from '../binding-ref';
|
|
2
|
-
export declare class HyperdriveService {
|
|
3
|
-
private ref;
|
|
4
|
-
constructor(ref: BindingRef<Hyperdrive>);
|
|
5
|
-
get binding(): Hyperdrive;
|
|
6
|
-
get connectionString(): string;
|
|
7
|
-
get host(): string;
|
|
8
|
-
get port(): number;
|
|
9
|
-
get user(): string;
|
|
10
|
-
get password(): string;
|
|
11
|
-
get database(): string;
|
|
12
|
-
}
|
|
@@ -1,51 +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 { HYPERDRIVE_BINDING_REF } from "../tokens.js";
|
|
17
|
-
export class HyperdriveService {
|
|
18
|
-
ref;
|
|
19
|
-
constructor(ref){
|
|
20
|
-
this.ref = ref;
|
|
21
|
-
}
|
|
22
|
-
get binding() {
|
|
23
|
-
return this.ref.value;
|
|
24
|
-
}
|
|
25
|
-
get connectionString() {
|
|
26
|
-
return this.binding.connectionString;
|
|
27
|
-
}
|
|
28
|
-
get host() {
|
|
29
|
-
return this.binding.host;
|
|
30
|
-
}
|
|
31
|
-
get port() {
|
|
32
|
-
return this.binding.port;
|
|
33
|
-
}
|
|
34
|
-
get user() {
|
|
35
|
-
return this.binding.user;
|
|
36
|
-
}
|
|
37
|
-
get password() {
|
|
38
|
-
return this.binding.password;
|
|
39
|
-
}
|
|
40
|
-
get database() {
|
|
41
|
-
return this.binding.database;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
HyperdriveService = _ts_decorate([
|
|
45
|
-
Injectable(),
|
|
46
|
-
_ts_param(0, Inject(HYPERDRIVE_BINDING_REF)),
|
|
47
|
-
_ts_metadata("design:type", Function),
|
|
48
|
-
_ts_metadata("design:paramtypes", [
|
|
49
|
-
typeof BindingRef === "undefined" ? Object : BindingRef
|
|
50
|
-
])
|
|
51
|
-
], HyperdriveService);
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { type AsyncCacheStore } from '@velajs/vela';
|
|
2
|
-
import { KVService } from './kv.service';
|
|
3
|
-
/**
|
|
4
|
-
* Cloudflare KV-backed {@link CacheStore}. Values are JSON-encoded. Intended as
|
|
5
|
-
* the slow tier under a `TieredCacheStore` (memory L1 → KV L2), but usable
|
|
6
|
-
* standalone as `CacheModule.forRootAsync({ inject: [KVService], useFactory: (kv) => ({ store: new KVCacheStore(kv) }) })`.
|
|
7
|
-
*
|
|
8
|
-
* Note: Cloudflare KV requires `expirationTtl >= 60s`, so sub-minute TTLs are
|
|
9
|
-
* clamped up. Keep short TTLs on the memory tier; use KV for longer-lived entries.
|
|
10
|
-
*/
|
|
11
|
-
export declare class KVCacheStore implements AsyncCacheStore {
|
|
12
|
-
private readonly kv;
|
|
13
|
-
constructor(kv: KVService);
|
|
14
|
-
private get ns();
|
|
15
|
-
get<T = unknown>(key: string): Promise<T | undefined>;
|
|
16
|
-
set<T = unknown>(key: string, value: T, ttl?: number): Promise<void>;
|
|
17
|
-
del(key: string): Promise<void>;
|
|
18
|
-
clear(): Promise<void>;
|
|
19
|
-
}
|
|
@@ -1,58 +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 KVCacheStore {
|
|
18
|
-
kv;
|
|
19
|
-
constructor(kv){
|
|
20
|
-
this.kv = kv;
|
|
21
|
-
}
|
|
22
|
-
get ns() {
|
|
23
|
-
return this.kv.namespace;
|
|
24
|
-
}
|
|
25
|
-
async get(key) {
|
|
26
|
-
const value = await this.ns.get(key, 'json');
|
|
27
|
-
return value === null ? undefined : value;
|
|
28
|
-
}
|
|
29
|
-
async set(key, value, ttl) {
|
|
30
|
-
// KV enforces a 60s minimum expirationTtl; clamp up. Omit for no-TTL.
|
|
31
|
-
const options = ttl !== undefined ? {
|
|
32
|
-
expirationTtl: Math.max(60, Math.floor(ttl))
|
|
33
|
-
} : undefined;
|
|
34
|
-
await this.ns.put(key, JSON.stringify(value), options);
|
|
35
|
-
}
|
|
36
|
-
async del(key) {
|
|
37
|
-
await this.ns.delete(key);
|
|
38
|
-
}
|
|
39
|
-
async clear() {
|
|
40
|
-
// KV has no native clear — page through and delete. Best-effort.
|
|
41
|
-
let cursor;
|
|
42
|
-
do {
|
|
43
|
-
const list = await this.ns.list(cursor ? {
|
|
44
|
-
cursor
|
|
45
|
-
} : undefined);
|
|
46
|
-
await Promise.all(list.keys.map((entry)=>this.ns.delete(entry.name)));
|
|
47
|
-
cursor = list.list_complete ? undefined : list.cursor;
|
|
48
|
-
}while (cursor)
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
KVCacheStore = _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
|
-
])
|
|
58
|
-
], KVCacheStore);
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import type { FeatureFlagDriver, FlagContext } from '@velajs/feature-flags';
|
|
2
|
-
import { KVService } from './kv.service';
|
|
3
|
-
export interface KvFlagDriverOptions {
|
|
4
|
-
/** Driver name used for `use(name)` / default-driver selection. Default `"kv"`. */
|
|
5
|
-
name?: string;
|
|
6
|
-
/** Prefix prepended to every flag key before the KV read. Default `""` (none). */
|
|
7
|
-
prefix?: string;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Cloudflare KV-backed {@link FeatureFlagDriver}. Flags are stored as JSON
|
|
11
|
-
* values under an optional key prefix and read with `get(key, 'json')`. Reads
|
|
12
|
-
* are type-checked against the requested type: a missing key or a value of the
|
|
13
|
-
* wrong JSON type returns the caller's `fallback`. KV has no targeting, so the
|
|
14
|
-
* evaluation context is ignored.
|
|
15
|
-
*
|
|
16
|
-
* The driver stays honest — it does **not** swallow errors. A KV failure (or a
|
|
17
|
-
* `SyntaxError` from a malformed stored value) propagates; the never-throw
|
|
18
|
-
* guarantee lives in `@velajs/feature-flags`'s service layer.
|
|
19
|
-
*
|
|
20
|
-
* Placed like {@link KVCacheStore}: construct it in a wiring factory over a
|
|
21
|
-
* resolved {@link KVService}.
|
|
22
|
-
*
|
|
23
|
-
* ```ts
|
|
24
|
-
* FeatureFlagsModule.forRootAsync({
|
|
25
|
-
* inject: [KVService],
|
|
26
|
-
* useFactory: (kv: KVService) => ({ drivers: [new KvFlagDriver(kv, { prefix: 'flag:' })] }),
|
|
27
|
-
* });
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
export declare class KvFlagDriver implements FeatureFlagDriver {
|
|
31
|
-
private readonly kv;
|
|
32
|
-
readonly name: string;
|
|
33
|
-
private readonly prefix;
|
|
34
|
-
constructor(kv: KVService, options?: KvFlagDriverOptions);
|
|
35
|
-
private get ns();
|
|
36
|
-
getBoolean(key: string, fallback: boolean, _ctx?: FlagContext): Promise<boolean>;
|
|
37
|
-
getString(key: string, fallback: string, _ctx?: FlagContext): Promise<string>;
|
|
38
|
-
getNumber(key: string, fallback: number, _ctx?: FlagContext): Promise<number>;
|
|
39
|
-
getObject<T extends object>(key: string, fallback: T, _ctx?: FlagContext): Promise<T>;
|
|
40
|
-
/**
|
|
41
|
-
* Reads and JSON-parses the (prefixed) key, returning the parsed value only
|
|
42
|
-
* when `matches` accepts its type; otherwise the caller's fallback. A missing
|
|
43
|
-
* key reads as `null` → fallback. Read/parse errors are left to propagate.
|
|
44
|
-
*/
|
|
45
|
-
private read;
|
|
46
|
-
}
|
|
47
|
-
/** Convenience factory for {@link KvFlagDriver}. */
|
|
48
|
-
export declare function kvFlagDriver(kv: KVService, options?: KvFlagDriverOptions): KvFlagDriver;
|