@velajs/cloudflare 0.1.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -0
- package/README.md +14 -19
- package/dist/binding-ref.d.ts +2 -2
- package/dist/binding-ref.js +3 -3
- package/dist/cloudflare-application.d.ts +3 -3
- package/dist/cloudflare-application.js +11 -2
- package/dist/cloudflare-factory.d.ts +3 -6
- package/dist/cloudflare-factory.js +14 -22
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/modules/ai.module.d.ts +1 -1
- package/dist/modules/ai.module.js +7 -14
- package/dist/modules/d1.module.d.ts +1 -1
- package/dist/modules/d1.module.js +7 -14
- package/dist/modules/durable-object.module.d.ts +1 -1
- package/dist/modules/durable-object.module.js +7 -14
- package/dist/modules/hyperdrive.module.d.ts +1 -1
- package/dist/modules/hyperdrive.module.js +7 -14
- package/dist/modules/kv.module.d.ts +1 -1
- package/dist/modules/kv.module.js +7 -14
- package/dist/modules/queue.module.d.ts +1 -1
- package/dist/modules/queue.module.js +7 -14
- package/dist/modules/r2.module.d.ts +1 -1
- package/dist/modules/r2.module.js +7 -14
- package/dist/modules/vectorize.module.d.ts +1 -1
- package/dist/modules/vectorize.module.js +7 -14
- package/dist/tokens.d.ts +1 -1
- package/dist/tokens.js +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.2.0 (2026-04-28)
|
|
4
|
+
|
|
5
|
+
### Breaking changes
|
|
6
|
+
|
|
7
|
+
- **`CloudflareFactory` renamed to `createCloudflareApp`.** The factory object exposed exactly one method (`.create`) and was a thin wrapper around `VelaFactory`. Replaced with a plain async function:
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
// before
|
|
11
|
+
import { CloudflareFactory } from '@velajs/cloudflare';
|
|
12
|
+
const app = await CloudflareFactory.create(AppModule);
|
|
13
|
+
|
|
14
|
+
// after
|
|
15
|
+
import { createCloudflareApp } from '@velajs/cloudflare';
|
|
16
|
+
const app = await createCloudflareApp(AppModule);
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### New
|
|
20
|
+
|
|
21
|
+
- `CloudflareApplication.scheduled()` now also dispatches `@Cron('expr')` jobs from `@velajs/vela`. Use either the cloudflare-specific `@Scheduled()` decorator or the framework's `@Cron()` decorator — both are matched against the incoming cron event.
|
|
22
|
+
|
|
23
|
+
### Compatibility
|
|
24
|
+
|
|
25
|
+
- Requires `@velajs/vela` ≥ 1.0.0 for the `@Cron` integration. The schedule split in vela 0.10 makes its `ScheduleModule` metadata-only, which lets edge platforms drive cron via their native triggers.
|
|
26
|
+
|
|
27
|
+
## 0.1.0 (2026-04-13)
|
|
28
|
+
|
|
29
|
+
Initial release.
|
package/README.md
CHANGED
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
# @velajs/cloudflare
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/@velajs/cloudflare)
|
|
4
|
+
[](https://github.com/velajs/cloudflare/actions/workflows/ci.yml)
|
|
5
|
+
[](https://github.com/velajs/cloudflare/blob/main/LICENSE)
|
|
6
|
+
|
|
3
7
|
Cloudflare Workers integration for the [Vela](https://github.com/velajs/vela) framework. NestJS-style per-service modules for KV, D1, R2, Queues, Durable Objects, Workers AI, Vectorize, and Hyperdrive.
|
|
4
8
|
|
|
5
9
|
## Install
|
|
6
10
|
|
|
7
11
|
```bash
|
|
8
|
-
|
|
12
|
+
pnpm add @velajs/cloudflare @velajs/vela hono
|
|
9
13
|
```
|
|
10
14
|
|
|
11
15
|
## Quick Start
|
|
12
16
|
|
|
13
17
|
```ts
|
|
14
18
|
import { Controller, Get, Module, Injectable, Param } from '@velajs/vela';
|
|
15
|
-
import { CloudflareFactory, KVModule, D1Module } from '@velajs/cloudflare';
|
|
16
|
-
import type { KVService, D1Service } from '@velajs/cloudflare';
|
|
19
|
+
import { CloudflareFactory, KVModule, KVService, D1Module, D1Service } from '@velajs/cloudflare';
|
|
17
20
|
|
|
18
21
|
@Injectable()
|
|
19
22
|
class UserService {
|
|
@@ -85,8 +88,7 @@ Each module follows the same pattern: `XModule.forRoot({ binding: 'NAME' })` ret
|
|
|
85
88
|
### KVModule
|
|
86
89
|
|
|
87
90
|
```ts
|
|
88
|
-
import { KVModule } from '@velajs/cloudflare';
|
|
89
|
-
import type { KVService } from '@velajs/cloudflare';
|
|
91
|
+
import { KVModule, KVService } from '@velajs/cloudflare';
|
|
90
92
|
|
|
91
93
|
@Module({ imports: [KVModule.forRoot({ binding: 'MY_KV' })] })
|
|
92
94
|
class AppModule {}
|
|
@@ -105,8 +107,7 @@ class CacheService {
|
|
|
105
107
|
### D1Module
|
|
106
108
|
|
|
107
109
|
```ts
|
|
108
|
-
import { D1Module } from '@velajs/cloudflare';
|
|
109
|
-
import type { D1Service } from '@velajs/cloudflare';
|
|
110
|
+
import { D1Module, D1Service } from '@velajs/cloudflare';
|
|
110
111
|
|
|
111
112
|
@Module({ imports: [D1Module.forRoot({ binding: 'DB' })] })
|
|
112
113
|
class AppModule {}
|
|
@@ -128,8 +129,7 @@ class PostService {
|
|
|
128
129
|
### R2Module
|
|
129
130
|
|
|
130
131
|
```ts
|
|
131
|
-
import { R2Module } from '@velajs/cloudflare';
|
|
132
|
-
import type { R2Service } from '@velajs/cloudflare';
|
|
132
|
+
import { R2Module, R2Service } from '@velajs/cloudflare';
|
|
133
133
|
|
|
134
134
|
@Module({ imports: [R2Module.forRoot({ binding: 'ASSETS' })] })
|
|
135
135
|
class AppModule {}
|
|
@@ -147,8 +147,7 @@ class StorageService {
|
|
|
147
147
|
### QueueModule
|
|
148
148
|
|
|
149
149
|
```ts
|
|
150
|
-
import { QueueModule } from '@velajs/cloudflare';
|
|
151
|
-
import type { QueueService } from '@velajs/cloudflare';
|
|
150
|
+
import { QueueModule, QueueService } from '@velajs/cloudflare';
|
|
152
151
|
|
|
153
152
|
@Module({ imports: [QueueModule.forRoot({ binding: 'EMAIL_QUEUE' })] })
|
|
154
153
|
class AppModule {}
|
|
@@ -166,8 +165,7 @@ class NotificationService {
|
|
|
166
165
|
### DurableObjectModule
|
|
167
166
|
|
|
168
167
|
```ts
|
|
169
|
-
import { DurableObjectModule } from '@velajs/cloudflare';
|
|
170
|
-
import type { DurableObjectService } from '@velajs/cloudflare';
|
|
168
|
+
import { DurableObjectModule, DurableObjectService } from '@velajs/cloudflare';
|
|
171
169
|
|
|
172
170
|
@Module({ imports: [DurableObjectModule.forRoot({ binding: 'COUNTER' })] })
|
|
173
171
|
class AppModule {}
|
|
@@ -187,8 +185,7 @@ class CounterService {
|
|
|
187
185
|
### AIModule
|
|
188
186
|
|
|
189
187
|
```ts
|
|
190
|
-
import { AIModule } from '@velajs/cloudflare';
|
|
191
|
-
import type { AIService } from '@velajs/cloudflare';
|
|
188
|
+
import { AIModule, AIService } from '@velajs/cloudflare';
|
|
192
189
|
|
|
193
190
|
@Module({ imports: [AIModule.forRoot({ binding: 'AI' })] })
|
|
194
191
|
class AppModule {}
|
|
@@ -208,8 +205,7 @@ class ChatService {
|
|
|
208
205
|
### VectorizeModule
|
|
209
206
|
|
|
210
207
|
```ts
|
|
211
|
-
import { VectorizeModule } from '@velajs/cloudflare';
|
|
212
|
-
import type { VectorizeService } from '@velajs/cloudflare';
|
|
208
|
+
import { VectorizeModule, VectorizeService } from '@velajs/cloudflare';
|
|
213
209
|
|
|
214
210
|
@Module({ imports: [VectorizeModule.forRoot({ binding: 'EMBEDDINGS' })] })
|
|
215
211
|
class AppModule {}
|
|
@@ -231,8 +227,7 @@ class SearchService {
|
|
|
231
227
|
### HyperdriveModule
|
|
232
228
|
|
|
233
229
|
```ts
|
|
234
|
-
import { HyperdriveModule } from '@velajs/cloudflare';
|
|
235
|
-
import type { HyperdriveService } from '@velajs/cloudflare';
|
|
230
|
+
import { HyperdriveModule, HyperdriveService } from '@velajs/cloudflare';
|
|
236
231
|
|
|
237
232
|
@Module({ imports: [HyperdriveModule.forRoot({ binding: 'POSTGRES' })] })
|
|
238
233
|
class AppModule {}
|
package/dist/binding-ref.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Mutable holder for a Cloudflare binding value.
|
|
3
3
|
*
|
|
4
4
|
* Created by each module's `forRoot()` and populated by
|
|
5
|
-
*
|
|
5
|
+
* `createCloudflareApp`'s one-time middleware on the first request.
|
|
6
6
|
* Services access the binding lazily via `.value`.
|
|
7
7
|
*/
|
|
8
8
|
export declare class BindingRef<T = unknown> {
|
|
@@ -10,6 +10,6 @@ export declare class BindingRef<T = unknown> {
|
|
|
10
10
|
private _value;
|
|
11
11
|
constructor(bindingName: string);
|
|
12
12
|
get value(): T;
|
|
13
|
-
/** @internal — called by
|
|
13
|
+
/** @internal — called by createCloudflareApp middleware */
|
|
14
14
|
_initialize(value: any): void;
|
|
15
15
|
}
|
package/dist/binding-ref.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Mutable holder for a Cloudflare binding value.
|
|
3
3
|
*
|
|
4
4
|
* Created by each module's `forRoot()` and populated by
|
|
5
|
-
*
|
|
5
|
+
* `createCloudflareApp`'s one-time middleware on the first request.
|
|
6
6
|
* Services access the binding lazily via `.value`.
|
|
7
7
|
*/ export class BindingRef {
|
|
8
8
|
bindingName;
|
|
@@ -12,11 +12,11 @@
|
|
|
12
12
|
}
|
|
13
13
|
get value() {
|
|
14
14
|
if (this._value === undefined) {
|
|
15
|
-
throw new Error(`Cloudflare binding '${this.bindingName}' not initialized. ` + `Ensure
|
|
15
|
+
throw new Error(`Cloudflare binding '${this.bindingName}' not initialized. ` + `Ensure createCloudflareApp() is used and a request has been made.`);
|
|
16
16
|
}
|
|
17
17
|
return this._value;
|
|
18
18
|
}
|
|
19
|
-
/** @internal — called by
|
|
19
|
+
/** @internal — called by createCloudflareApp middleware */ // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
20
20
|
_initialize(value) {
|
|
21
21
|
this._value = value;
|
|
22
22
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Hono } from 'hono';
|
|
2
|
-
import type
|
|
2
|
+
import { type VelaApplication } from '@velajs/vela';
|
|
3
3
|
import type { CloudflareEnv } from './types';
|
|
4
4
|
/**
|
|
5
5
|
* Wraps VelaApplication with Cloudflare-specific handlers:
|
|
@@ -9,7 +9,7 @@ import type { CloudflareEnv } from './types';
|
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
11
11
|
* ```ts
|
|
12
|
-
* const app = await
|
|
12
|
+
* const app = await createCloudflareApp(AppModule);
|
|
13
13
|
* export default {
|
|
14
14
|
* fetch: app.fetch,
|
|
15
15
|
* scheduled: app.scheduled.bind(app),
|
|
@@ -24,7 +24,7 @@ export declare class CloudflareApplication {
|
|
|
24
24
|
constructor(app: VelaApplication);
|
|
25
25
|
get fetch(): Hono['fetch'];
|
|
26
26
|
getHonoApp(): Hono;
|
|
27
|
-
/** @internal — scans instances for @Scheduled and @QueueConsumer metadata */
|
|
27
|
+
/** @internal — scans instances for @Scheduled, @Cron, and @QueueConsumer metadata */
|
|
28
28
|
scanInstances(instances: unknown[]): void;
|
|
29
29
|
/**
|
|
30
30
|
* Handle Cloudflare scheduled (cron) events.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CRON_METADATA, getMetadata } from "@velajs/vela";
|
|
1
2
|
import { getScheduledMetadata } from "./decorators/scheduled.js";
|
|
2
3
|
import { getQueueConsumerMetadata } from "./decorators/queue-consumer.js";
|
|
3
4
|
/**
|
|
@@ -8,7 +9,7 @@ import { getQueueConsumerMetadata } from "./decorators/queue-consumer.js";
|
|
|
8
9
|
*
|
|
9
10
|
* @example
|
|
10
11
|
* ```ts
|
|
11
|
-
* const app = await
|
|
12
|
+
* const app = await createCloudflareApp(AppModule);
|
|
12
13
|
* export default {
|
|
13
14
|
* fetch: app.fetch,
|
|
14
15
|
* scheduled: app.scheduled.bind(app),
|
|
@@ -28,7 +29,7 @@ import { getQueueConsumerMetadata } from "./decorators/queue-consumer.js";
|
|
|
28
29
|
getHonoApp() {
|
|
29
30
|
return this.app.getHonoApp();
|
|
30
31
|
}
|
|
31
|
-
/** @internal — scans instances for @Scheduled and @QueueConsumer metadata */ scanInstances(instances) {
|
|
32
|
+
/** @internal — scans instances for @Scheduled, @Cron, and @QueueConsumer metadata */ scanInstances(instances) {
|
|
32
33
|
for (const instance of instances){
|
|
33
34
|
if (!instance || typeof instance !== 'object') continue;
|
|
34
35
|
const scheduledMeta = getScheduledMetadata(instance);
|
|
@@ -39,6 +40,14 @@ import { getQueueConsumerMetadata } from "./decorators/queue-consumer.js";
|
|
|
39
40
|
cron: meta.cron
|
|
40
41
|
});
|
|
41
42
|
}
|
|
43
|
+
const cronMeta = getMetadata(CRON_METADATA, instance.constructor) ?? [];
|
|
44
|
+
for (const meta of cronMeta){
|
|
45
|
+
this.scheduledHandlers.push({
|
|
46
|
+
instance,
|
|
47
|
+
methodName: meta.methodName,
|
|
48
|
+
cron: meta.expression
|
|
49
|
+
});
|
|
50
|
+
}
|
|
42
51
|
const queueMeta = getQueueConsumerMetadata(instance);
|
|
43
52
|
for (const meta of queueMeta){
|
|
44
53
|
this.queueConsumers.push({
|
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
import type { Type } from '@velajs/vela';
|
|
2
2
|
import { CloudflareApplication } from './cloudflare-application';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
* Replaces `VelaFactory.create()` for Cloudflare apps.
|
|
4
|
+
* Create a Cloudflare Workers application.
|
|
6
5
|
*
|
|
7
6
|
* Sets up a one-time Hono middleware that captures `c.env` on the
|
|
8
7
|
* first request and initializes all configured binding refs.
|
|
9
8
|
*
|
|
10
9
|
* @example
|
|
11
10
|
* ```ts
|
|
12
|
-
* const app = await
|
|
11
|
+
* const app = await createCloudflareApp(AppModule);
|
|
13
12
|
* export default app; // has .fetch, .scheduled, .queue
|
|
14
13
|
* ```
|
|
15
14
|
*/
|
|
16
|
-
export declare
|
|
17
|
-
create(rootModule: Type): Promise<CloudflareApplication>;
|
|
18
|
-
};
|
|
15
|
+
export declare function createCloudflareApp(rootModule: Type): Promise<CloudflareApplication>;
|
|
@@ -2,41 +2,33 @@ import { VelaFactory } from "@velajs/vela";
|
|
|
2
2
|
import { CloudflareApplication } from "./cloudflare-application.js";
|
|
3
3
|
import { bindingsRegistry } from "./tokens.js";
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
* Replaces `VelaFactory.create()` for Cloudflare apps.
|
|
5
|
+
* Create a Cloudflare Workers application.
|
|
7
6
|
*
|
|
8
7
|
* Sets up a one-time Hono middleware that captures `c.env` on the
|
|
9
8
|
* first request and initializes all configured binding refs.
|
|
10
9
|
*
|
|
11
10
|
* @example
|
|
12
11
|
* ```ts
|
|
13
|
-
* const app = await
|
|
12
|
+
* const app = await createCloudflareApp(AppModule);
|
|
14
13
|
* export default app; // has .fetch, .scheduled, .queue
|
|
15
14
|
* ```
|
|
16
|
-
*/ export
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
// Registered via useGlobalMiddleware so it persists across rebuilds.
|
|
22
|
-
let initialized = false;
|
|
23
|
-
velaApp.useGlobalMiddleware({
|
|
24
|
-
use: async (c, next)=>{
|
|
15
|
+
*/ export async function createCloudflareApp(rootModule) {
|
|
16
|
+
let initialized = false;
|
|
17
|
+
const velaApp = await VelaFactory.create(rootModule, {
|
|
18
|
+
middleware: [
|
|
19
|
+
async (c, next)=>{
|
|
25
20
|
if (!initialized) {
|
|
26
21
|
initialized = true;
|
|
27
|
-
const
|
|
28
|
-
const env = ctx.env ?? {};
|
|
22
|
+
const env = c.env ?? {};
|
|
29
23
|
for (const ref of bindingsRegistry){
|
|
30
24
|
ref._initialize(env[ref.bindingName]);
|
|
31
25
|
}
|
|
32
26
|
}
|
|
33
27
|
await next();
|
|
34
28
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
};
|
|
29
|
+
]
|
|
30
|
+
});
|
|
31
|
+
const cfApp = new CloudflareApplication(velaApp);
|
|
32
|
+
cfApp.scanInstances(velaApp.getInstances());
|
|
33
|
+
return cfApp;
|
|
34
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { createCloudflareApp } from './cloudflare-factory';
|
|
2
2
|
export { CloudflareApplication } from './cloudflare-application';
|
|
3
3
|
export { KVModule } from './modules/kv.module';
|
|
4
4
|
export { D1Module } from './modules/d1.module';
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Factory & Application
|
|
2
|
-
export {
|
|
2
|
+
export { createCloudflareApp } from "./cloudflare-factory.js";
|
|
3
3
|
export { CloudflareApplication } from "./cloudflare-application.js";
|
|
4
4
|
// Modules
|
|
5
5
|
export { KVModule } from "./modules/kv.module.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createModuleRef } from "@velajs/vela";
|
|
2
2
|
import { BindingRef } from "../binding-ref.js";
|
|
3
3
|
import { AI_BINDING_REF, bindingsRegistry } from "../tokens.js";
|
|
4
4
|
import { AIService } from "../services/ai.service.js";
|
|
@@ -6,25 +6,18 @@ export class AIModule {
|
|
|
6
6
|
static forRoot(options) {
|
|
7
7
|
const ref = new BindingRef(options.binding);
|
|
8
8
|
bindingsRegistry.push(ref);
|
|
9
|
-
const moduleClass = class AIDynamicModule {
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(moduleClass, 'name', {
|
|
12
|
-
value: `AIModule_${options.binding}`
|
|
13
|
-
});
|
|
14
|
-
MetadataRegistry.setModuleOptions(moduleClass, {
|
|
15
|
-
exports: [
|
|
16
|
-
AIService,
|
|
17
|
-
AI_BINDING_REF
|
|
18
|
-
]
|
|
19
|
-
});
|
|
20
9
|
return {
|
|
21
|
-
module:
|
|
10
|
+
module: createModuleRef(`AIModule_${options.binding}`),
|
|
22
11
|
providers: [
|
|
23
12
|
{
|
|
24
|
-
|
|
13
|
+
provide: AI_BINDING_REF,
|
|
25
14
|
useValue: ref
|
|
26
15
|
},
|
|
27
16
|
AIService
|
|
17
|
+
],
|
|
18
|
+
exports: [
|
|
19
|
+
AIService,
|
|
20
|
+
AI_BINDING_REF
|
|
28
21
|
]
|
|
29
22
|
};
|
|
30
23
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createModuleRef } from "@velajs/vela";
|
|
2
2
|
import { BindingRef } from "../binding-ref.js";
|
|
3
3
|
import { D1_BINDING_REF, bindingsRegistry } from "../tokens.js";
|
|
4
4
|
import { D1Service } from "../services/d1.service.js";
|
|
@@ -6,25 +6,18 @@ export class D1Module {
|
|
|
6
6
|
static forRoot(options) {
|
|
7
7
|
const ref = new BindingRef(options.binding);
|
|
8
8
|
bindingsRegistry.push(ref);
|
|
9
|
-
const moduleClass = class D1DynamicModule {
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(moduleClass, 'name', {
|
|
12
|
-
value: `D1Module_${options.binding}`
|
|
13
|
-
});
|
|
14
|
-
MetadataRegistry.setModuleOptions(moduleClass, {
|
|
15
|
-
exports: [
|
|
16
|
-
D1Service,
|
|
17
|
-
D1_BINDING_REF
|
|
18
|
-
]
|
|
19
|
-
});
|
|
20
9
|
return {
|
|
21
|
-
module:
|
|
10
|
+
module: createModuleRef(`D1Module_${options.binding}`),
|
|
22
11
|
providers: [
|
|
23
12
|
{
|
|
24
|
-
|
|
13
|
+
provide: D1_BINDING_REF,
|
|
25
14
|
useValue: ref
|
|
26
15
|
},
|
|
27
16
|
D1Service
|
|
17
|
+
],
|
|
18
|
+
exports: [
|
|
19
|
+
D1Service,
|
|
20
|
+
D1_BINDING_REF
|
|
28
21
|
]
|
|
29
22
|
};
|
|
30
23
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createModuleRef } from "@velajs/vela";
|
|
2
2
|
import { BindingRef } from "../binding-ref.js";
|
|
3
3
|
import { DO_BINDING_REF, bindingsRegistry } from "../tokens.js";
|
|
4
4
|
import { DurableObjectService } from "../services/durable-object.service.js";
|
|
@@ -6,25 +6,18 @@ export class DurableObjectModule {
|
|
|
6
6
|
static forRoot(options) {
|
|
7
7
|
const ref = new BindingRef(options.binding);
|
|
8
8
|
bindingsRegistry.push(ref);
|
|
9
|
-
const moduleClass = class DurableObjectDynamicModule {
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(moduleClass, 'name', {
|
|
12
|
-
value: `DurableObjectModule_${options.binding}`
|
|
13
|
-
});
|
|
14
|
-
MetadataRegistry.setModuleOptions(moduleClass, {
|
|
15
|
-
exports: [
|
|
16
|
-
DurableObjectService,
|
|
17
|
-
DO_BINDING_REF
|
|
18
|
-
]
|
|
19
|
-
});
|
|
20
9
|
return {
|
|
21
|
-
module:
|
|
10
|
+
module: createModuleRef(`DurableObjectModule_${options.binding}`),
|
|
22
11
|
providers: [
|
|
23
12
|
{
|
|
24
|
-
|
|
13
|
+
provide: DO_BINDING_REF,
|
|
25
14
|
useValue: ref
|
|
26
15
|
},
|
|
27
16
|
DurableObjectService
|
|
17
|
+
],
|
|
18
|
+
exports: [
|
|
19
|
+
DurableObjectService,
|
|
20
|
+
DO_BINDING_REF
|
|
28
21
|
]
|
|
29
22
|
};
|
|
30
23
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createModuleRef } from "@velajs/vela";
|
|
2
2
|
import { BindingRef } from "../binding-ref.js";
|
|
3
3
|
import { HYPERDRIVE_BINDING_REF, bindingsRegistry } from "../tokens.js";
|
|
4
4
|
import { HyperdriveService } from "../services/hyperdrive.service.js";
|
|
@@ -6,25 +6,18 @@ export class HyperdriveModule {
|
|
|
6
6
|
static forRoot(options) {
|
|
7
7
|
const ref = new BindingRef(options.binding);
|
|
8
8
|
bindingsRegistry.push(ref);
|
|
9
|
-
const moduleClass = class HyperdriveDynamicModule {
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(moduleClass, 'name', {
|
|
12
|
-
value: `HyperdriveModule_${options.binding}`
|
|
13
|
-
});
|
|
14
|
-
MetadataRegistry.setModuleOptions(moduleClass, {
|
|
15
|
-
exports: [
|
|
16
|
-
HyperdriveService,
|
|
17
|
-
HYPERDRIVE_BINDING_REF
|
|
18
|
-
]
|
|
19
|
-
});
|
|
20
9
|
return {
|
|
21
|
-
module:
|
|
10
|
+
module: createModuleRef(`HyperdriveModule_${options.binding}`),
|
|
22
11
|
providers: [
|
|
23
12
|
{
|
|
24
|
-
|
|
13
|
+
provide: HYPERDRIVE_BINDING_REF,
|
|
25
14
|
useValue: ref
|
|
26
15
|
},
|
|
27
16
|
HyperdriveService
|
|
17
|
+
],
|
|
18
|
+
exports: [
|
|
19
|
+
HyperdriveService,
|
|
20
|
+
HYPERDRIVE_BINDING_REF
|
|
28
21
|
]
|
|
29
22
|
};
|
|
30
23
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createModuleRef } from "@velajs/vela";
|
|
2
2
|
import { BindingRef } from "../binding-ref.js";
|
|
3
3
|
import { KV_BINDING_REF, bindingsRegistry } from "../tokens.js";
|
|
4
4
|
import { KVService } from "../services/kv.service.js";
|
|
@@ -6,25 +6,18 @@ export class KVModule {
|
|
|
6
6
|
static forRoot(options) {
|
|
7
7
|
const ref = new BindingRef(options.binding);
|
|
8
8
|
bindingsRegistry.push(ref);
|
|
9
|
-
const moduleClass = class KVDynamicModule {
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(moduleClass, 'name', {
|
|
12
|
-
value: `KVModule_${options.binding}`
|
|
13
|
-
});
|
|
14
|
-
MetadataRegistry.setModuleOptions(moduleClass, {
|
|
15
|
-
exports: [
|
|
16
|
-
KVService,
|
|
17
|
-
KV_BINDING_REF
|
|
18
|
-
]
|
|
19
|
-
});
|
|
20
9
|
return {
|
|
21
|
-
module:
|
|
10
|
+
module: createModuleRef(`KVModule_${options.binding}`),
|
|
22
11
|
providers: [
|
|
23
12
|
{
|
|
24
|
-
|
|
13
|
+
provide: KV_BINDING_REF,
|
|
25
14
|
useValue: ref
|
|
26
15
|
},
|
|
27
16
|
KVService
|
|
17
|
+
],
|
|
18
|
+
exports: [
|
|
19
|
+
KVService,
|
|
20
|
+
KV_BINDING_REF
|
|
28
21
|
]
|
|
29
22
|
};
|
|
30
23
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createModuleRef } from "@velajs/vela";
|
|
2
2
|
import { BindingRef } from "../binding-ref.js";
|
|
3
3
|
import { QUEUE_BINDING_REF, bindingsRegistry } from "../tokens.js";
|
|
4
4
|
import { QueueService } from "../services/queue.service.js";
|
|
@@ -6,25 +6,18 @@ export class QueueModule {
|
|
|
6
6
|
static forRoot(options) {
|
|
7
7
|
const ref = new BindingRef(options.binding);
|
|
8
8
|
bindingsRegistry.push(ref);
|
|
9
|
-
const moduleClass = class QueueDynamicModule {
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(moduleClass, 'name', {
|
|
12
|
-
value: `QueueModule_${options.binding}`
|
|
13
|
-
});
|
|
14
|
-
MetadataRegistry.setModuleOptions(moduleClass, {
|
|
15
|
-
exports: [
|
|
16
|
-
QueueService,
|
|
17
|
-
QUEUE_BINDING_REF
|
|
18
|
-
]
|
|
19
|
-
});
|
|
20
9
|
return {
|
|
21
|
-
module:
|
|
10
|
+
module: createModuleRef(`QueueModule_${options.binding}`),
|
|
22
11
|
providers: [
|
|
23
12
|
{
|
|
24
|
-
|
|
13
|
+
provide: QUEUE_BINDING_REF,
|
|
25
14
|
useValue: ref
|
|
26
15
|
},
|
|
27
16
|
QueueService
|
|
17
|
+
],
|
|
18
|
+
exports: [
|
|
19
|
+
QueueService,
|
|
20
|
+
QUEUE_BINDING_REF
|
|
28
21
|
]
|
|
29
22
|
};
|
|
30
23
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createModuleRef } from "@velajs/vela";
|
|
2
2
|
import { BindingRef } from "../binding-ref.js";
|
|
3
3
|
import { R2_BINDING_REF, bindingsRegistry } from "../tokens.js";
|
|
4
4
|
import { R2Service } from "../services/r2.service.js";
|
|
@@ -6,25 +6,18 @@ export class R2Module {
|
|
|
6
6
|
static forRoot(options) {
|
|
7
7
|
const ref = new BindingRef(options.binding);
|
|
8
8
|
bindingsRegistry.push(ref);
|
|
9
|
-
const moduleClass = class R2DynamicModule {
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(moduleClass, 'name', {
|
|
12
|
-
value: `R2Module_${options.binding}`
|
|
13
|
-
});
|
|
14
|
-
MetadataRegistry.setModuleOptions(moduleClass, {
|
|
15
|
-
exports: [
|
|
16
|
-
R2Service,
|
|
17
|
-
R2_BINDING_REF
|
|
18
|
-
]
|
|
19
|
-
});
|
|
20
9
|
return {
|
|
21
|
-
module:
|
|
10
|
+
module: createModuleRef(`R2Module_${options.binding}`),
|
|
22
11
|
providers: [
|
|
23
12
|
{
|
|
24
|
-
|
|
13
|
+
provide: R2_BINDING_REF,
|
|
25
14
|
useValue: ref
|
|
26
15
|
},
|
|
27
16
|
R2Service
|
|
17
|
+
],
|
|
18
|
+
exports: [
|
|
19
|
+
R2Service,
|
|
20
|
+
R2_BINDING_REF
|
|
28
21
|
]
|
|
29
22
|
};
|
|
30
23
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createModuleRef } from "@velajs/vela";
|
|
2
2
|
import { BindingRef } from "../binding-ref.js";
|
|
3
3
|
import { VECTORIZE_BINDING_REF, bindingsRegistry } from "../tokens.js";
|
|
4
4
|
import { VectorizeService } from "../services/vectorize.service.js";
|
|
@@ -6,25 +6,18 @@ export class VectorizeModule {
|
|
|
6
6
|
static forRoot(options) {
|
|
7
7
|
const ref = new BindingRef(options.binding);
|
|
8
8
|
bindingsRegistry.push(ref);
|
|
9
|
-
const moduleClass = class VectorizeDynamicModule {
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(moduleClass, 'name', {
|
|
12
|
-
value: `VectorizeModule_${options.binding}`
|
|
13
|
-
});
|
|
14
|
-
MetadataRegistry.setModuleOptions(moduleClass, {
|
|
15
|
-
exports: [
|
|
16
|
-
VectorizeService,
|
|
17
|
-
VECTORIZE_BINDING_REF
|
|
18
|
-
]
|
|
19
|
-
});
|
|
20
9
|
return {
|
|
21
|
-
module:
|
|
10
|
+
module: createModuleRef(`VectorizeModule_${options.binding}`),
|
|
22
11
|
providers: [
|
|
23
12
|
{
|
|
24
|
-
|
|
13
|
+
provide: VECTORIZE_BINDING_REF,
|
|
25
14
|
useValue: ref
|
|
26
15
|
},
|
|
27
16
|
VectorizeService
|
|
17
|
+
],
|
|
18
|
+
exports: [
|
|
19
|
+
VectorizeService,
|
|
20
|
+
VECTORIZE_BINDING_REF
|
|
28
21
|
]
|
|
29
22
|
};
|
|
30
23
|
}
|
package/dist/tokens.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export declare const HYPERDRIVE_BINDING_REF: InjectionToken<BindingRef<unknown>>
|
|
|
11
11
|
/**
|
|
12
12
|
* Global registry of binding refs to initialize on first request.
|
|
13
13
|
* Each module's `forRoot()` pushes its BindingRef here.
|
|
14
|
-
*
|
|
14
|
+
* createCloudflareApp reads from this to populate bindings.
|
|
15
15
|
*/
|
|
16
16
|
export declare const bindingsRegistry: BindingRef[];
|
|
17
17
|
export declare function clearBindingsRegistry(): void;
|
package/dist/tokens.js
CHANGED
|
@@ -11,7 +11,7 @@ export const HYPERDRIVE_BINDING_REF = new InjectionToken('CF_HYPERDRIVE_BINDING_
|
|
|
11
11
|
/**
|
|
12
12
|
* Global registry of binding refs to initialize on first request.
|
|
13
13
|
* Each module's `forRoot()` pushes its BindingRef here.
|
|
14
|
-
*
|
|
14
|
+
* createCloudflareApp reads from this to populate bindings.
|
|
15
15
|
*/ export const bindingsRegistry = [];
|
|
16
16
|
export function clearBindingsRegistry() {
|
|
17
17
|
bindingsRegistry.length = 0;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@velajs/cloudflare",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Cloudflare Workers integration for Vela framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"node": ">=20"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
|
-
"@velajs/vela": ">=
|
|
47
|
+
"@velajs/vela": ">=1.0.0",
|
|
48
48
|
"hono": ">=4"
|
|
49
49
|
},
|
|
50
50
|
"peerDependenciesMeta": {
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@swc/cli": "^0.8.0",
|
|
57
57
|
"@swc/core": "^1.15.11",
|
|
58
|
-
"@velajs/vela": "^0.
|
|
58
|
+
"@velajs/vela": "^1.0.0",
|
|
59
59
|
"hono": "^4",
|
|
60
60
|
"typescript": "^5",
|
|
61
61
|
"unplugin-swc": "^1.5.9",
|