@velajs/cloudflare 1.0.0 → 1.1.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/README.md +38 -20
- package/dist/binding-ref.d.ts +1 -8
- package/dist/binding-ref.js +5 -9
- package/dist/cloudflare-application.d.ts +3 -3
- package/dist/cloudflare-application.js +24 -17
- package/dist/cloudflare-factory.d.ts +2 -2
- package/dist/cloudflare-factory.js +23 -4
- package/dist/index.d.ts +0 -3
- package/dist/index.js +0 -4
- package/dist/modules/ai.module.d.ts +1 -6
- package/dist/modules/ai.module.js +7 -23
- package/dist/modules/create-binding-module.d.ts +14 -0
- package/dist/modules/create-binding-module.js +26 -0
- package/dist/modules/d1.module.d.ts +1 -6
- package/dist/modules/d1.module.js +7 -23
- package/dist/modules/durable-object.module.d.ts +1 -6
- package/dist/modules/durable-object.module.js +7 -23
- package/dist/modules/hyperdrive.module.d.ts +1 -6
- package/dist/modules/hyperdrive.module.js +7 -23
- package/dist/modules/kv.module.d.ts +1 -6
- package/dist/modules/kv.module.js +7 -23
- package/dist/modules/queue.module.d.ts +1 -6
- package/dist/modules/queue.module.js +7 -23
- package/dist/modules/r2.module.d.ts +1 -6
- package/dist/modules/r2.module.js +7 -23
- package/dist/modules/vectorize.module.d.ts +1 -6
- package/dist/modules/vectorize.module.js +7 -23
- package/dist/services/ai.service.d.ts +2 -12
- package/dist/services/ai.service.js +1 -4
- package/dist/services/d1.service.d.ts +2 -18
- package/dist/services/d1.service.js +1 -15
- package/dist/services/durable-object.service.d.ts +2 -20
- package/dist/services/durable-object.service.js +1 -16
- package/dist/services/hyperdrive.service.d.ts +2 -16
- package/dist/services/hyperdrive.service.js +1 -1
- package/dist/services/kv.service.d.ts +5 -18
- package/dist/services/kv.service.js +1 -16
- package/dist/services/queue.service.d.ts +3 -17
- package/dist/services/queue.service.js +1 -7
- package/dist/services/r2.service.d.ts +2 -14
- package/dist/services/r2.service.js +1 -16
- package/dist/services/vectorize.service.d.ts +2 -22
- package/dist/services/vectorize.service.js +1 -19
- package/dist/tokens.d.ts +0 -7
- package/dist/tokens.js +1 -9
- package/package.json +19 -13
package/README.md
CHANGED
|
@@ -10,6 +10,24 @@ Cloudflare Workers integration for the [Vela](https://github.com/velajs/vela) fr
|
|
|
10
10
|
|
|
11
11
|
```bash
|
|
12
12
|
pnpm add @velajs/cloudflare @velajs/vela hono
|
|
13
|
+
pnpm add -D @cloudflare/workers-types
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
`@cloudflare/workers-types` is a required peer (types-only — zero runtime cost). It's what gives `KVNamespace`, `D1Database`, `R2Bucket`, `Queue`, `DurableObjectNamespace`, `Ai`, `VectorizeIndex`, and `Hyperdrive` their proper types when you reach into the underlying binding.
|
|
17
|
+
|
|
18
|
+
## Service shape
|
|
19
|
+
|
|
20
|
+
Every service is a thin typed wrapper around its Cloudflare binding. Use the accessor (`.namespace`, `.database`, `.bucket`, `.queue`, `.binding`, `.index`) to call the binding's methods directly — full `@cloudflare/workers-types` autocomplete, no shim layer in between.
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
class KVService { readonly namespace: KVNamespace; }
|
|
24
|
+
class D1Service { readonly database: D1Database; }
|
|
25
|
+
class R2Service { readonly bucket: R2Bucket; }
|
|
26
|
+
class QueueService<T> { readonly queue: Queue<T>; }
|
|
27
|
+
class DurableObjectService { readonly namespace: DurableObjectNamespace; }
|
|
28
|
+
class AIService { readonly binding: Ai; }
|
|
29
|
+
class VectorizeService { readonly index: VectorizeIndex; }
|
|
30
|
+
class HyperdriveService { readonly binding: Hyperdrive; }
|
|
13
31
|
```
|
|
14
32
|
|
|
15
33
|
## Quick Start
|
|
@@ -26,11 +44,11 @@ class UserService {
|
|
|
26
44
|
) {}
|
|
27
45
|
|
|
28
46
|
async findById(id: string) {
|
|
29
|
-
const cached = await this.kv.get(`user:${id}`);
|
|
47
|
+
const cached = await this.kv.namespace.get(`user:${id}`);
|
|
30
48
|
if (cached) return JSON.parse(cached as string);
|
|
31
49
|
|
|
32
|
-
const user = await this.d1.prepare('SELECT * FROM users WHERE id = ?').bind(id).first();
|
|
33
|
-
if (user) await this.kv.put(`user:${id}`, JSON.stringify(user));
|
|
50
|
+
const user = await this.d1.database.prepare('SELECT * FROM users WHERE id = ?').bind(id).first();
|
|
51
|
+
if (user) await this.kv.namespace.put(`user:${id}`, JSON.stringify(user));
|
|
34
52
|
return user;
|
|
35
53
|
}
|
|
36
54
|
}
|
|
@@ -97,10 +115,10 @@ class AppModule {}
|
|
|
97
115
|
class CacheService {
|
|
98
116
|
constructor(private kv: KVService) {}
|
|
99
117
|
|
|
100
|
-
async get(key: string) { return this.kv.get(key); }
|
|
101
|
-
async set(key: string, value: string) { return this.kv.put(key, value); }
|
|
102
|
-
async remove(key: string) { return this.kv.delete(key); }
|
|
103
|
-
async keys() { return this.kv.list(); }
|
|
118
|
+
async get(key: string) { return this.kv.namespace.get(key); }
|
|
119
|
+
async set(key: string, value: string) { return this.kv.namespace.put(key, value); }
|
|
120
|
+
async remove(key: string) { return this.kv.namespace.delete(key); }
|
|
121
|
+
async keys() { return this.kv.namespace.list(); }
|
|
104
122
|
}
|
|
105
123
|
```
|
|
106
124
|
|
|
@@ -117,11 +135,11 @@ class PostService {
|
|
|
117
135
|
constructor(private d1: D1Service) {}
|
|
118
136
|
|
|
119
137
|
async findAll() {
|
|
120
|
-
return this.d1.prepare('SELECT * FROM posts').all();
|
|
138
|
+
return this.d1.database.prepare('SELECT * FROM posts').all();
|
|
121
139
|
}
|
|
122
140
|
|
|
123
141
|
async create(title: string) {
|
|
124
|
-
return this.d1.prepare('INSERT INTO posts (title) VALUES (?)').bind(title).run();
|
|
142
|
+
return this.d1.database.prepare('INSERT INTO posts (title) VALUES (?)').bind(title).run();
|
|
125
143
|
}
|
|
126
144
|
}
|
|
127
145
|
```
|
|
@@ -138,9 +156,9 @@ class AppModule {}
|
|
|
138
156
|
class StorageService {
|
|
139
157
|
constructor(private r2: R2Service) {}
|
|
140
158
|
|
|
141
|
-
async upload(key: string, data: string) { return this.r2.put(key, data); }
|
|
142
|
-
async download(key: string) { return this.r2.get(key); }
|
|
143
|
-
async remove(key: string) { return this.r2.delete(key); }
|
|
159
|
+
async upload(key: string, data: string) { return this.r2.bucket.put(key, data); }
|
|
160
|
+
async download(key: string) { return this.r2.bucket.get(key); }
|
|
161
|
+
async remove(key: string) { return this.r2.bucket.delete(key); }
|
|
144
162
|
}
|
|
145
163
|
```
|
|
146
164
|
|
|
@@ -157,7 +175,7 @@ class NotificationService {
|
|
|
157
175
|
constructor(private queue: QueueService) {}
|
|
158
176
|
|
|
159
177
|
async sendEmail(to: string, subject: string) {
|
|
160
|
-
await this.queue.send({ to, subject });
|
|
178
|
+
await this.queue.queue.send({ to, subject });
|
|
161
179
|
}
|
|
162
180
|
}
|
|
163
181
|
```
|
|
@@ -175,8 +193,8 @@ class CounterService {
|
|
|
175
193
|
constructor(private doNs: DurableObjectService) {}
|
|
176
194
|
|
|
177
195
|
async increment(name: string) {
|
|
178
|
-
const id = this.doNs.idFromName(name);
|
|
179
|
-
const stub = this.doNs.get(id);
|
|
196
|
+
const id = this.doNs.namespace.idFromName(name);
|
|
197
|
+
const stub = this.doNs.namespace.get(id);
|
|
180
198
|
return (stub as any).fetch('/increment');
|
|
181
199
|
}
|
|
182
200
|
}
|
|
@@ -195,7 +213,7 @@ class ChatService {
|
|
|
195
213
|
constructor(private ai: AIService) {}
|
|
196
214
|
|
|
197
215
|
async chat(prompt: string) {
|
|
198
|
-
return this.ai.run('@cf/meta/llama-3.1-8b-instruct', {
|
|
216
|
+
return this.ai.binding.run('@cf/meta/llama-3.1-8b-instruct', {
|
|
199
217
|
messages: [{ role: 'user', content: prompt }],
|
|
200
218
|
});
|
|
201
219
|
}
|
|
@@ -215,11 +233,11 @@ class SearchService {
|
|
|
215
233
|
constructor(private vectorize: VectorizeService) {}
|
|
216
234
|
|
|
217
235
|
async search(vector: number[]) {
|
|
218
|
-
return this.vectorize.query(vector, { topK: 10 });
|
|
236
|
+
return this.vectorize.index.query(vector, { topK: 10 });
|
|
219
237
|
}
|
|
220
238
|
|
|
221
239
|
async addVectors(vectors: unknown[]) {
|
|
222
|
-
return this.vectorize.upsert(vectors);
|
|
240
|
+
return this.vectorize.index.upsert(vectors);
|
|
223
241
|
}
|
|
224
242
|
}
|
|
225
243
|
```
|
|
@@ -237,11 +255,11 @@ class DbService {
|
|
|
237
255
|
constructor(private hd: HyperdriveService) {}
|
|
238
256
|
|
|
239
257
|
getConnectionString() {
|
|
240
|
-
return this.hd.connectionString;
|
|
258
|
+
return this.hd.binding.connectionString;
|
|
241
259
|
}
|
|
242
260
|
|
|
243
261
|
getConfig() {
|
|
244
|
-
return { host: this.hd.host, port: this.hd.port, database: this.hd.database };
|
|
262
|
+
return { host: this.hd.binding.host, port: this.hd.binding.port, database: this.hd.binding.database };
|
|
245
263
|
}
|
|
246
264
|
}
|
|
247
265
|
```
|
package/dist/binding-ref.d.ts
CHANGED
|
@@ -1,15 +1,8 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Mutable holder for a Cloudflare binding value.
|
|
3
|
-
*
|
|
4
|
-
* Created by each module's `forRoot()` and populated by
|
|
5
|
-
* `createCloudflareApp`'s one-time middleware on the first request.
|
|
6
|
-
* Services access the binding lazily via `.value`.
|
|
7
|
-
*/
|
|
8
1
|
export declare class BindingRef<T = unknown> {
|
|
9
2
|
readonly bindingName: string;
|
|
10
3
|
private _value;
|
|
11
4
|
constructor(bindingName: string);
|
|
12
5
|
get value(): T;
|
|
13
6
|
/** @internal — called by createCloudflareApp middleware */
|
|
14
|
-
_initialize(value:
|
|
7
|
+
_initialize(value: T): void;
|
|
15
8
|
}
|
package/dist/binding-ref.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* `createCloudflareApp`'s one-time middleware on the first request.
|
|
6
|
-
* Services access the binding lazily via `.value`.
|
|
7
|
-
*/ export class BindingRef {
|
|
1
|
+
// Mutable holder for a Cloudflare binding value. Created by each module's
|
|
2
|
+
// forRoot() and populated by createCloudflareApp's one-time middleware on
|
|
3
|
+
// the first request. Services access the binding lazily via .value.
|
|
4
|
+
export class BindingRef {
|
|
8
5
|
bindingName;
|
|
9
6
|
_value;
|
|
10
7
|
constructor(bindingName){
|
|
@@ -16,8 +13,7 @@
|
|
|
16
13
|
}
|
|
17
14
|
return this._value;
|
|
18
15
|
}
|
|
19
|
-
/** @internal — called by createCloudflareApp middleware */
|
|
20
|
-
_initialize(value) {
|
|
16
|
+
/** @internal — called by createCloudflareApp middleware */ _initialize(value) {
|
|
21
17
|
this._value = value;
|
|
22
18
|
}
|
|
23
19
|
}
|
|
@@ -4,7 +4,8 @@ import type { CloudflareEnv } from './types';
|
|
|
4
4
|
/**
|
|
5
5
|
* Wraps VelaApplication with Cloudflare-specific handlers:
|
|
6
6
|
* - `fetch` — HTTP request handler (from Hono)
|
|
7
|
-
* - `scheduled` — Cron trigger handler (matches `@Scheduled()` decorators
|
|
7
|
+
* - `scheduled` — Cron trigger handler (matches `@Scheduled()` decorators
|
|
8
|
+
* AND vela's own `@Cron()` jobs)
|
|
8
9
|
* - `queue` — Queue consumer handler (matches `@QueueConsumer()` decorators)
|
|
9
10
|
*
|
|
10
11
|
* @example
|
|
@@ -28,7 +29,7 @@ export declare class CloudflareApplication {
|
|
|
28
29
|
scanInstances(instances: unknown[]): void;
|
|
29
30
|
/**
|
|
30
31
|
* Handle Cloudflare scheduled (cron) events.
|
|
31
|
-
* Matches the event's cron expression to `@Scheduled()` handlers.
|
|
32
|
+
* Matches the event's cron expression to `@Scheduled()` and vela `@Cron()` handlers.
|
|
32
33
|
*/
|
|
33
34
|
scheduled(event: {
|
|
34
35
|
cron: string;
|
|
@@ -46,6 +47,5 @@ export declare class CloudflareApplication {
|
|
|
46
47
|
}, env: CloudflareEnv, ctx: {
|
|
47
48
|
waitUntil: (promise: Promise<unknown>) => void;
|
|
48
49
|
}): Promise<void>;
|
|
49
|
-
/** Gracefully shut down the application. */
|
|
50
50
|
close(signal?: string): Promise<void>;
|
|
51
51
|
}
|
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import { CRON_METADATA, getMetadata } from "@velajs/vela";
|
|
2
2
|
import { getScheduledMetadata } from "./decorators/scheduled.js";
|
|
3
3
|
import { getQueueConsumerMetadata } from "./decorators/queue-consumer.js";
|
|
4
|
+
function invoke(instance, methodName, args) {
|
|
5
|
+
const method = instance[methodName];
|
|
6
|
+
if (typeof method !== 'function') {
|
|
7
|
+
throw new Error(`Method '${methodName}' is not a function on ${instance.constructor.name}`);
|
|
8
|
+
}
|
|
9
|
+
return method.apply(instance, args);
|
|
10
|
+
}
|
|
4
11
|
/**
|
|
5
12
|
* Wraps VelaApplication with Cloudflare-specific handlers:
|
|
6
13
|
* - `fetch` — HTTP request handler (from Hono)
|
|
7
|
-
* - `scheduled` — Cron trigger handler (matches `@Scheduled()` decorators
|
|
14
|
+
* - `scheduled` — Cron trigger handler (matches `@Scheduled()` decorators
|
|
15
|
+
* AND vela's own `@Cron()` jobs)
|
|
8
16
|
* - `queue` — Queue consumer handler (matches `@QueueConsumer()` decorators)
|
|
9
17
|
*
|
|
10
18
|
* @example
|
|
@@ -32,14 +40,14 @@ import { getQueueConsumerMetadata } from "./decorators/queue-consumer.js";
|
|
|
32
40
|
/** @internal — scans instances for @Scheduled, @Cron, and @QueueConsumer metadata */ scanInstances(instances) {
|
|
33
41
|
for (const instance of instances){
|
|
34
42
|
if (!instance || typeof instance !== 'object') continue;
|
|
35
|
-
const
|
|
36
|
-
for (const meta of scheduledMeta){
|
|
43
|
+
for (const meta of getScheduledMetadata(instance)){
|
|
37
44
|
this.scheduledHandlers.push({
|
|
38
45
|
instance,
|
|
39
46
|
methodName: meta.methodName,
|
|
40
47
|
cron: meta.cron
|
|
41
48
|
});
|
|
42
49
|
}
|
|
50
|
+
// vela's @Cron jobs run via the same Workers cron trigger.
|
|
43
51
|
const cronMeta = getMetadata(CRON_METADATA, instance.constructor) ?? [];
|
|
44
52
|
for (const meta of cronMeta){
|
|
45
53
|
this.scheduledHandlers.push({
|
|
@@ -48,8 +56,7 @@ import { getQueueConsumerMetadata } from "./decorators/queue-consumer.js";
|
|
|
48
56
|
cron: meta.expression
|
|
49
57
|
});
|
|
50
58
|
}
|
|
51
|
-
const
|
|
52
|
-
for (const meta of queueMeta){
|
|
59
|
+
for (const meta of getQueueConsumerMetadata(instance)){
|
|
53
60
|
this.queueConsumers.push({
|
|
54
61
|
instance,
|
|
55
62
|
methodName: meta.methodName,
|
|
@@ -60,27 +67,27 @@ import { getQueueConsumerMetadata } from "./decorators/queue-consumer.js";
|
|
|
60
67
|
}
|
|
61
68
|
/**
|
|
62
69
|
* Handle Cloudflare scheduled (cron) events.
|
|
63
|
-
* Matches the event's cron expression to `@Scheduled()` handlers.
|
|
70
|
+
* Matches the event's cron expression to `@Scheduled()` and vela `@Cron()` handlers.
|
|
64
71
|
*/ async scheduled(event, env, ctx) {
|
|
65
72
|
const matching = this.scheduledHandlers.filter((h)=>h.cron === event.cron);
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
73
|
+
await Promise.all(matching.map((h)=>invoke(h.instance, h.methodName, [
|
|
74
|
+
event,
|
|
75
|
+
env,
|
|
76
|
+
ctx
|
|
77
|
+
])));
|
|
71
78
|
}
|
|
72
79
|
/**
|
|
73
80
|
* Handle Cloudflare Queue consumer events.
|
|
74
81
|
* Matches the batch queue name to `@QueueConsumer()` handlers.
|
|
75
82
|
*/ async queue(batch, env, ctx) {
|
|
76
83
|
const matching = this.queueConsumers.filter((h)=>h.queueName === batch.queue);
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
84
|
+
await Promise.all(matching.map((h)=>invoke(h.instance, h.methodName, [
|
|
85
|
+
batch,
|
|
86
|
+
env,
|
|
87
|
+
ctx
|
|
88
|
+
])));
|
|
82
89
|
}
|
|
83
|
-
|
|
90
|
+
async close(signal) {
|
|
84
91
|
return this.app.close(signal);
|
|
85
92
|
}
|
|
86
93
|
}
|
|
@@ -3,8 +3,8 @@ import { CloudflareApplication } from './cloudflare-application';
|
|
|
3
3
|
/**
|
|
4
4
|
* Create a Cloudflare Workers application.
|
|
5
5
|
*
|
|
6
|
-
* Sets up a one-time Hono middleware that captures `c.env` on the
|
|
7
|
-
*
|
|
6
|
+
* Sets up a one-time Hono middleware that captures `c.env` on the first
|
|
7
|
+
* request and initializes all configured binding refs.
|
|
8
8
|
*
|
|
9
9
|
* @example
|
|
10
10
|
* ```ts
|
|
@@ -1,11 +1,28 @@
|
|
|
1
1
|
import { VelaFactory } from "@velajs/vela";
|
|
2
|
+
import { BindingRef } from "./binding-ref.js";
|
|
2
3
|
import { CloudflareApplication } from "./cloudflare-application.js";
|
|
3
|
-
|
|
4
|
+
// Walks every provider registered in the container and pulls out the
|
|
5
|
+
// BindingRef instances. Replaces the old module-level `bindingsRegistry`
|
|
6
|
+
// global so two CloudflareApplication instances in one process don't
|
|
7
|
+
// share state.
|
|
8
|
+
function collectBindingRefs(container) {
|
|
9
|
+
const refs = [];
|
|
10
|
+
for (const token of container.getTokens()){
|
|
11
|
+
let value;
|
|
12
|
+
try {
|
|
13
|
+
value = container.resolve(token);
|
|
14
|
+
} catch {
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
if (value instanceof BindingRef) refs.push(value);
|
|
18
|
+
}
|
|
19
|
+
return refs;
|
|
20
|
+
}
|
|
4
21
|
/**
|
|
5
22
|
* Create a Cloudflare Workers application.
|
|
6
23
|
*
|
|
7
|
-
* Sets up a one-time Hono middleware that captures `c.env` on the
|
|
8
|
-
*
|
|
24
|
+
* Sets up a one-time Hono middleware that captures `c.env` on the first
|
|
25
|
+
* request and initializes all configured binding refs.
|
|
9
26
|
*
|
|
10
27
|
* @example
|
|
11
28
|
* ```ts
|
|
@@ -14,13 +31,14 @@ import { bindingsRegistry } from "./tokens.js";
|
|
|
14
31
|
* ```
|
|
15
32
|
*/ export async function createCloudflareApp(rootModule) {
|
|
16
33
|
let initialized = false;
|
|
34
|
+
let refs;
|
|
17
35
|
const velaApp = await VelaFactory.create(rootModule, {
|
|
18
36
|
middleware: [
|
|
19
37
|
async (c, next)=>{
|
|
20
38
|
if (!initialized) {
|
|
21
39
|
initialized = true;
|
|
22
40
|
const env = c.env ?? {};
|
|
23
|
-
for (const ref of
|
|
41
|
+
for (const ref of refs){
|
|
24
42
|
ref._initialize(env[ref.bindingName]);
|
|
25
43
|
}
|
|
26
44
|
}
|
|
@@ -28,6 +46,7 @@ import { bindingsRegistry } from "./tokens.js";
|
|
|
28
46
|
}
|
|
29
47
|
]
|
|
30
48
|
});
|
|
49
|
+
refs = collectBindingRefs(velaApp.getContainer());
|
|
31
50
|
const cfApp = new CloudflareApplication(velaApp);
|
|
32
51
|
cfApp.scanInstances(velaApp.getInstances());
|
|
33
52
|
return cfApp;
|
package/dist/index.d.ts
CHANGED
|
@@ -19,9 +19,6 @@ export { HyperdriveService } from './services/hyperdrive.service';
|
|
|
19
19
|
export { Env } from './decorators/env';
|
|
20
20
|
export { Scheduled } from './decorators/scheduled';
|
|
21
21
|
export { QueueConsumer } from './decorators/queue-consumer';
|
|
22
|
-
export { BindingRef } from './binding-ref';
|
|
23
|
-
export { bindingsRegistry, clearBindingsRegistry } from './tokens';
|
|
24
|
-
export { KV_BINDING_REF, D1_BINDING_REF, R2_BINDING_REF, QUEUE_BINDING_REF, DO_BINDING_REF, AI_BINDING_REF, VECTORIZE_BINDING_REF, HYPERDRIVE_BINDING_REF, } from './tokens';
|
|
25
22
|
export type { CloudflareEnv, ScheduledRegistration, QueueRegistration } from './types';
|
|
26
23
|
export type { ScheduledMetadata } from './decorators/scheduled';
|
|
27
24
|
export type { QueueConsumerMetadata } from './decorators/queue-consumer';
|
package/dist/index.js
CHANGED
|
@@ -23,7 +23,3 @@ export { HyperdriveService } from "./services/hyperdrive.service.js";
|
|
|
23
23
|
export { Env } from "./decorators/env.js";
|
|
24
24
|
export { Scheduled } from "./decorators/scheduled.js";
|
|
25
25
|
export { QueueConsumer } from "./decorators/queue-consumer.js";
|
|
26
|
-
// Internals (for advanced usage / testing)
|
|
27
|
-
export { BindingRef } from "./binding-ref.js";
|
|
28
|
-
export { bindingsRegistry, clearBindingsRegistry } from "./tokens.js";
|
|
29
|
-
export { KV_BINDING_REF, D1_BINDING_REF, R2_BINDING_REF, QUEUE_BINDING_REF, DO_BINDING_REF, AI_BINDING_REF, VECTORIZE_BINDING_REF, HYPERDRIVE_BINDING_REF } from "./tokens.js";
|
|
@@ -1,24 +1,8 @@
|
|
|
1
|
-
import { createModuleRef } from "@velajs/vela";
|
|
2
|
-
import { BindingRef } from "../binding-ref.js";
|
|
3
|
-
import { AI_BINDING_REF, bindingsRegistry } from "../tokens.js";
|
|
4
1
|
import { AIService } from "../services/ai.service.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
{
|
|
13
|
-
provide: AI_BINDING_REF,
|
|
14
|
-
useValue: ref
|
|
15
|
-
},
|
|
16
|
-
AIService
|
|
17
|
-
],
|
|
18
|
-
exports: [
|
|
19
|
-
AIService,
|
|
20
|
-
AI_BINDING_REF
|
|
21
|
-
]
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
}
|
|
2
|
+
import { AI_BINDING_REF } from "../tokens.js";
|
|
3
|
+
import { createBindingModule } from "./create-binding-module.js";
|
|
4
|
+
export const AIModule = createBindingModule({
|
|
5
|
+
name: 'AI',
|
|
6
|
+
serviceClass: AIService,
|
|
7
|
+
bindingRefToken: AI_BINDING_REF
|
|
8
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type DynamicModule, type InjectionToken, type Type } from '@velajs/vela';
|
|
2
|
+
import { BindingRef } from '../binding-ref';
|
|
3
|
+
interface CreateBindingModuleOptions<TService> {
|
|
4
|
+
name: string;
|
|
5
|
+
serviceClass: Type<TService>;
|
|
6
|
+
bindingRefToken: InjectionToken<BindingRef>;
|
|
7
|
+
}
|
|
8
|
+
export interface BindingModuleStatic {
|
|
9
|
+
forRoot(options: {
|
|
10
|
+
binding: string;
|
|
11
|
+
}): DynamicModule;
|
|
12
|
+
}
|
|
13
|
+
export declare function createBindingModule<TService>(opts: CreateBindingModuleOptions<TService>): BindingModuleStatic;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { createModuleRef } from "@velajs/vela";
|
|
2
|
+
import { BindingRef } from "../binding-ref.js";
|
|
3
|
+
// Single factory for every Cloudflare binding module (KV, D1, R2, ...).
|
|
4
|
+
// Each binding module is just a bag of (token, service); this generates
|
|
5
|
+
// the canonical forRoot() shape for them.
|
|
6
|
+
export function createBindingModule(opts) {
|
|
7
|
+
return {
|
|
8
|
+
forRoot ({ binding }) {
|
|
9
|
+
const ref = new BindingRef(binding);
|
|
10
|
+
return {
|
|
11
|
+
module: createModuleRef(`${opts.name}Module_${binding}`),
|
|
12
|
+
providers: [
|
|
13
|
+
{
|
|
14
|
+
provide: opts.bindingRefToken,
|
|
15
|
+
useValue: ref
|
|
16
|
+
},
|
|
17
|
+
opts.serviceClass
|
|
18
|
+
],
|
|
19
|
+
exports: [
|
|
20
|
+
opts.serviceClass,
|
|
21
|
+
opts.bindingRefToken
|
|
22
|
+
]
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
@@ -1,24 +1,8 @@
|
|
|
1
|
-
import { createModuleRef } from "@velajs/vela";
|
|
2
|
-
import { BindingRef } from "../binding-ref.js";
|
|
3
|
-
import { D1_BINDING_REF, bindingsRegistry } from "../tokens.js";
|
|
4
1
|
import { D1Service } from "../services/d1.service.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
{
|
|
13
|
-
provide: D1_BINDING_REF,
|
|
14
|
-
useValue: ref
|
|
15
|
-
},
|
|
16
|
-
D1Service
|
|
17
|
-
],
|
|
18
|
-
exports: [
|
|
19
|
-
D1Service,
|
|
20
|
-
D1_BINDING_REF
|
|
21
|
-
]
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
}
|
|
2
|
+
import { D1_BINDING_REF } from "../tokens.js";
|
|
3
|
+
import { createBindingModule } from "./create-binding-module.js";
|
|
4
|
+
export const D1Module = createBindingModule({
|
|
5
|
+
name: 'D1',
|
|
6
|
+
serviceClass: D1Service,
|
|
7
|
+
bindingRefToken: D1_BINDING_REF
|
|
8
|
+
});
|
|
@@ -1,24 +1,8 @@
|
|
|
1
|
-
import { createModuleRef } from "@velajs/vela";
|
|
2
|
-
import { BindingRef } from "../binding-ref.js";
|
|
3
|
-
import { DO_BINDING_REF, bindingsRegistry } from "../tokens.js";
|
|
4
1
|
import { DurableObjectService } from "../services/durable-object.service.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
{
|
|
13
|
-
provide: DO_BINDING_REF,
|
|
14
|
-
useValue: ref
|
|
15
|
-
},
|
|
16
|
-
DurableObjectService
|
|
17
|
-
],
|
|
18
|
-
exports: [
|
|
19
|
-
DurableObjectService,
|
|
20
|
-
DO_BINDING_REF
|
|
21
|
-
]
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
}
|
|
2
|
+
import { DO_BINDING_REF } from "../tokens.js";
|
|
3
|
+
import { createBindingModule } from "./create-binding-module.js";
|
|
4
|
+
export const DurableObjectModule = createBindingModule({
|
|
5
|
+
name: 'DurableObject',
|
|
6
|
+
serviceClass: DurableObjectService,
|
|
7
|
+
bindingRefToken: DO_BINDING_REF
|
|
8
|
+
});
|
|
@@ -1,24 +1,8 @@
|
|
|
1
|
-
import { createModuleRef } from "@velajs/vela";
|
|
2
|
-
import { BindingRef } from "../binding-ref.js";
|
|
3
|
-
import { HYPERDRIVE_BINDING_REF, bindingsRegistry } from "../tokens.js";
|
|
4
1
|
import { HyperdriveService } from "../services/hyperdrive.service.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
{
|
|
13
|
-
provide: HYPERDRIVE_BINDING_REF,
|
|
14
|
-
useValue: ref
|
|
15
|
-
},
|
|
16
|
-
HyperdriveService
|
|
17
|
-
],
|
|
18
|
-
exports: [
|
|
19
|
-
HyperdriveService,
|
|
20
|
-
HYPERDRIVE_BINDING_REF
|
|
21
|
-
]
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
}
|
|
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,24 +1,8 @@
|
|
|
1
|
-
import { createModuleRef } from "@velajs/vela";
|
|
2
|
-
import { BindingRef } from "../binding-ref.js";
|
|
3
|
-
import { KV_BINDING_REF, bindingsRegistry } from "../tokens.js";
|
|
4
1
|
import { KVService } from "../services/kv.service.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
{
|
|
13
|
-
provide: KV_BINDING_REF,
|
|
14
|
-
useValue: ref
|
|
15
|
-
},
|
|
16
|
-
KVService
|
|
17
|
-
],
|
|
18
|
-
exports: [
|
|
19
|
-
KVService,
|
|
20
|
-
KV_BINDING_REF
|
|
21
|
-
]
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
}
|
|
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,24 +1,8 @@
|
|
|
1
|
-
import { createModuleRef } from "@velajs/vela";
|
|
2
|
-
import { BindingRef } from "../binding-ref.js";
|
|
3
|
-
import { QUEUE_BINDING_REF, bindingsRegistry } from "../tokens.js";
|
|
4
1
|
import { QueueService } from "../services/queue.service.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
{
|
|
13
|
-
provide: QUEUE_BINDING_REF,
|
|
14
|
-
useValue: ref
|
|
15
|
-
},
|
|
16
|
-
QueueService
|
|
17
|
-
],
|
|
18
|
-
exports: [
|
|
19
|
-
QueueService,
|
|
20
|
-
QUEUE_BINDING_REF
|
|
21
|
-
]
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
}
|
|
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,24 +1,8 @@
|
|
|
1
|
-
import { createModuleRef } from "@velajs/vela";
|
|
2
|
-
import { BindingRef } from "../binding-ref.js";
|
|
3
|
-
import { R2_BINDING_REF, bindingsRegistry } from "../tokens.js";
|
|
4
1
|
import { R2Service } from "../services/r2.service.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
{
|
|
13
|
-
provide: R2_BINDING_REF,
|
|
14
|
-
useValue: ref
|
|
15
|
-
},
|
|
16
|
-
R2Service
|
|
17
|
-
],
|
|
18
|
-
exports: [
|
|
19
|
-
R2Service,
|
|
20
|
-
R2_BINDING_REF
|
|
21
|
-
]
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
}
|
|
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,24 +1,8 @@
|
|
|
1
|
-
import { createModuleRef } from "@velajs/vela";
|
|
2
|
-
import { BindingRef } from "../binding-ref.js";
|
|
3
|
-
import { VECTORIZE_BINDING_REF, bindingsRegistry } from "../tokens.js";
|
|
4
1
|
import { VectorizeService } from "../services/vectorize.service.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
{
|
|
13
|
-
provide: VECTORIZE_BINDING_REF,
|
|
14
|
-
useValue: ref
|
|
15
|
-
},
|
|
16
|
-
VectorizeService
|
|
17
|
-
],
|
|
18
|
-
exports: [
|
|
19
|
-
VectorizeService,
|
|
20
|
-
VECTORIZE_BINDING_REF
|
|
21
|
-
]
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
}
|
|
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,16 +1,6 @@
|
|
|
1
1
|
import type { BindingRef } from '../binding-ref';
|
|
2
|
-
type AIBinding = {
|
|
3
|
-
run: Function;
|
|
4
|
-
} & Record<string, any>;
|
|
5
|
-
/**
|
|
6
|
-
* Wrapper around Cloudflare Workers AI binding.
|
|
7
|
-
* Injected via `AIModule.forRoot({ binding: 'AI' })`.
|
|
8
|
-
*/
|
|
9
2
|
export declare class AIService {
|
|
10
3
|
private ref;
|
|
11
|
-
constructor(ref: BindingRef);
|
|
12
|
-
|
|
13
|
-
get binding(): AIBinding;
|
|
14
|
-
run(model: string, inputs: Record<string, unknown>, options?: Record<string, unknown>): Promise<unknown>;
|
|
4
|
+
constructor(ref: BindingRef<Ai>);
|
|
5
|
+
get binding(): Ai;
|
|
15
6
|
}
|
|
16
|
-
export {};
|
|
@@ -19,12 +19,9 @@ export class AIService {
|
|
|
19
19
|
constructor(ref){
|
|
20
20
|
this.ref = ref;
|
|
21
21
|
}
|
|
22
|
-
|
|
22
|
+
get binding() {
|
|
23
23
|
return this.ref.value;
|
|
24
24
|
}
|
|
25
|
-
run(model, inputs, options) {
|
|
26
|
-
return this.binding.run(model, inputs, options);
|
|
27
|
-
}
|
|
28
25
|
}
|
|
29
26
|
AIService = _ts_decorate([
|
|
30
27
|
Injectable(),
|
|
@@ -1,22 +1,6 @@
|
|
|
1
1
|
import type { BindingRef } from '../binding-ref';
|
|
2
|
-
type D1Binding = {
|
|
3
|
-
prepare: Function;
|
|
4
|
-
batch: Function;
|
|
5
|
-
exec: Function;
|
|
6
|
-
dump: Function;
|
|
7
|
-
} & Record<string, any>;
|
|
8
|
-
/**
|
|
9
|
-
* Wrapper around Cloudflare D1 Database.
|
|
10
|
-
* Injected via `D1Module.forRoot({ binding: 'DB' })`.
|
|
11
|
-
*/
|
|
12
2
|
export declare class D1Service {
|
|
13
3
|
private ref;
|
|
14
|
-
constructor(ref: BindingRef);
|
|
15
|
-
|
|
16
|
-
get database(): D1Binding;
|
|
17
|
-
prepare(query: string): any;
|
|
18
|
-
batch(statements: unknown[]): Promise<any[]>;
|
|
19
|
-
exec(query: string): Promise<unknown>;
|
|
20
|
-
dump(): Promise<ArrayBuffer>;
|
|
4
|
+
constructor(ref: BindingRef<D1Database>);
|
|
5
|
+
get database(): D1Database;
|
|
21
6
|
}
|
|
22
|
-
export {};
|
|
@@ -19,23 +19,9 @@ export class D1Service {
|
|
|
19
19
|
constructor(ref){
|
|
20
20
|
this.ref = ref;
|
|
21
21
|
}
|
|
22
|
-
|
|
22
|
+
get database() {
|
|
23
23
|
return this.ref.value;
|
|
24
24
|
}
|
|
25
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
26
|
-
prepare(query) {
|
|
27
|
-
return this.database.prepare(query);
|
|
28
|
-
}
|
|
29
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
30
|
-
batch(statements) {
|
|
31
|
-
return this.database.batch(statements);
|
|
32
|
-
}
|
|
33
|
-
exec(query) {
|
|
34
|
-
return this.database.exec(query);
|
|
35
|
-
}
|
|
36
|
-
dump() {
|
|
37
|
-
return this.database.dump();
|
|
38
|
-
}
|
|
39
25
|
}
|
|
40
26
|
D1Service = _ts_decorate([
|
|
41
27
|
Injectable(),
|
|
@@ -1,24 +1,6 @@
|
|
|
1
1
|
import type { BindingRef } from '../binding-ref';
|
|
2
|
-
type DOBinding = {
|
|
3
|
-
newUniqueId: Function;
|
|
4
|
-
idFromName: Function;
|
|
5
|
-
idFromString: Function;
|
|
6
|
-
get: Function;
|
|
7
|
-
jurisdiction: Function;
|
|
8
|
-
} & Record<string, any>;
|
|
9
|
-
/**
|
|
10
|
-
* Wrapper around Cloudflare DurableObjectNamespace.
|
|
11
|
-
* Injected via `DurableObjectModule.forRoot({ binding: 'COUNTER' })`.
|
|
12
|
-
*/
|
|
13
2
|
export declare class DurableObjectService {
|
|
14
3
|
private ref;
|
|
15
|
-
constructor(ref: BindingRef);
|
|
16
|
-
|
|
17
|
-
get namespace(): DOBinding;
|
|
18
|
-
newUniqueId(options?: Record<string, unknown>): unknown;
|
|
19
|
-
idFromName(name: string): unknown;
|
|
20
|
-
idFromString(hexStr: string): unknown;
|
|
21
|
-
get(id: unknown): unknown;
|
|
22
|
-
jurisdiction(name: string): unknown;
|
|
4
|
+
constructor(ref: BindingRef<DurableObjectNamespace>);
|
|
5
|
+
get namespace(): DurableObjectNamespace;
|
|
23
6
|
}
|
|
24
|
-
export {};
|
|
@@ -19,24 +19,9 @@ export class DurableObjectService {
|
|
|
19
19
|
constructor(ref){
|
|
20
20
|
this.ref = ref;
|
|
21
21
|
}
|
|
22
|
-
|
|
22
|
+
get namespace() {
|
|
23
23
|
return this.ref.value;
|
|
24
24
|
}
|
|
25
|
-
newUniqueId(options) {
|
|
26
|
-
return this.namespace.newUniqueId(options);
|
|
27
|
-
}
|
|
28
|
-
idFromName(name) {
|
|
29
|
-
return this.namespace.idFromName(name);
|
|
30
|
-
}
|
|
31
|
-
idFromString(hexStr) {
|
|
32
|
-
return this.namespace.idFromString(hexStr);
|
|
33
|
-
}
|
|
34
|
-
get(id) {
|
|
35
|
-
return this.namespace.get(id);
|
|
36
|
-
}
|
|
37
|
-
jurisdiction(name) {
|
|
38
|
-
return this.namespace.jurisdiction(name);
|
|
39
|
-
}
|
|
40
25
|
}
|
|
41
26
|
DurableObjectService = _ts_decorate([
|
|
42
27
|
Injectable(),
|
|
@@ -1,21 +1,8 @@
|
|
|
1
1
|
import type { BindingRef } from '../binding-ref';
|
|
2
|
-
type HyperdriveBinding = {
|
|
3
|
-
connectionString: string;
|
|
4
|
-
host: string;
|
|
5
|
-
port: number;
|
|
6
|
-
user: string;
|
|
7
|
-
password: string;
|
|
8
|
-
database: string;
|
|
9
|
-
} & Record<string, any>;
|
|
10
|
-
/**
|
|
11
|
-
* Wrapper around Cloudflare Hyperdrive binding.
|
|
12
|
-
* Injected via `HyperdriveModule.forRoot({ binding: 'POSTGRES' })`.
|
|
13
|
-
*/
|
|
14
2
|
export declare class HyperdriveService {
|
|
15
3
|
private ref;
|
|
16
|
-
constructor(ref: BindingRef);
|
|
17
|
-
|
|
18
|
-
get binding(): HyperdriveBinding;
|
|
4
|
+
constructor(ref: BindingRef<Hyperdrive>);
|
|
5
|
+
get binding(): Hyperdrive;
|
|
19
6
|
get connectionString(): string;
|
|
20
7
|
get host(): string;
|
|
21
8
|
get port(): number;
|
|
@@ -23,4 +10,3 @@ export declare class HyperdriveService {
|
|
|
23
10
|
get password(): string;
|
|
24
11
|
get database(): string;
|
|
25
12
|
}
|
|
26
|
-
export {};
|
|
@@ -1,24 +1,11 @@
|
|
|
1
1
|
import type { BindingRef } from '../binding-ref';
|
|
2
|
-
type KVBinding = {
|
|
3
|
-
get: Function;
|
|
4
|
-
getWithMetadata: Function;
|
|
5
|
-
put: Function;
|
|
6
|
-
delete: Function;
|
|
7
|
-
list: Function;
|
|
8
|
-
} & Record<string, any>;
|
|
9
2
|
/**
|
|
10
|
-
* Wrapper around Cloudflare KV
|
|
11
|
-
*
|
|
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`.
|
|
12
6
|
*/
|
|
13
7
|
export declare class KVService {
|
|
14
8
|
private ref;
|
|
15
|
-
constructor(ref: BindingRef);
|
|
16
|
-
|
|
17
|
-
get namespace(): KVBinding;
|
|
18
|
-
get(key: string, typeOrOptions?: string | Record<string, unknown>): Promise<unknown>;
|
|
19
|
-
getWithMetadata(key: string, typeOrOptions?: string | Record<string, unknown>): Promise<unknown>;
|
|
20
|
-
put(key: string, value: string | ArrayBuffer | ReadableStream, options?: Record<string, unknown>): Promise<void>;
|
|
21
|
-
delete(key: string): Promise<void>;
|
|
22
|
-
list(options?: Record<string, unknown>): Promise<unknown>;
|
|
9
|
+
constructor(ref: BindingRef<KVNamespace>);
|
|
10
|
+
get namespace(): KVNamespace;
|
|
23
11
|
}
|
|
24
|
-
export {};
|
|
@@ -19,24 +19,9 @@ export class KVService {
|
|
|
19
19
|
constructor(ref){
|
|
20
20
|
this.ref = ref;
|
|
21
21
|
}
|
|
22
|
-
|
|
22
|
+
get namespace() {
|
|
23
23
|
return this.ref.value;
|
|
24
24
|
}
|
|
25
|
-
get(key, typeOrOptions) {
|
|
26
|
-
return this.namespace.get(key, typeOrOptions);
|
|
27
|
-
}
|
|
28
|
-
getWithMetadata(key, typeOrOptions) {
|
|
29
|
-
return this.namespace.getWithMetadata(key, typeOrOptions);
|
|
30
|
-
}
|
|
31
|
-
put(key, value, options) {
|
|
32
|
-
return this.namespace.put(key, value, options);
|
|
33
|
-
}
|
|
34
|
-
delete(key) {
|
|
35
|
-
return this.namespace.delete(key);
|
|
36
|
-
}
|
|
37
|
-
list(options) {
|
|
38
|
-
return this.namespace.list(options);
|
|
39
|
-
}
|
|
40
25
|
}
|
|
41
26
|
KVService = _ts_decorate([
|
|
42
27
|
Injectable(),
|
|
@@ -1,20 +1,6 @@
|
|
|
1
1
|
import type { BindingRef } from '../binding-ref';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Wrapper around Cloudflare Queue (producer side).
|
|
5
|
-
* Injected via `QueueModule.forRoot({ binding: 'MY_QUEUE' })`.
|
|
6
|
-
*
|
|
7
|
-
* For consuming messages, use the `@QueueConsumer()` decorator.
|
|
8
|
-
*/
|
|
9
|
-
export declare class QueueService {
|
|
2
|
+
export declare class QueueService<Body = unknown> {
|
|
10
3
|
private ref;
|
|
11
|
-
constructor(ref: BindingRef);
|
|
12
|
-
|
|
13
|
-
get queue(): QueueBinding;
|
|
14
|
-
send(message: unknown, options?: Record<string, unknown>): Promise<void>;
|
|
15
|
-
sendBatch(messages: Iterable<{
|
|
16
|
-
body: unknown;
|
|
17
|
-
[key: string]: unknown;
|
|
18
|
-
}>, options?: Record<string, unknown>): Promise<void>;
|
|
4
|
+
constructor(ref: BindingRef<Queue<Body>>);
|
|
5
|
+
get queue(): Queue<Body>;
|
|
19
6
|
}
|
|
20
|
-
export {};
|
|
@@ -19,15 +19,9 @@ export class QueueService {
|
|
|
19
19
|
constructor(ref){
|
|
20
20
|
this.ref = ref;
|
|
21
21
|
}
|
|
22
|
-
|
|
22
|
+
get queue() {
|
|
23
23
|
return this.ref.value;
|
|
24
24
|
}
|
|
25
|
-
send(message, options) {
|
|
26
|
-
return this.queue.send(message, options);
|
|
27
|
-
}
|
|
28
|
-
sendBatch(messages, options) {
|
|
29
|
-
return this.queue.sendBatch(messages, options);
|
|
30
|
-
}
|
|
31
25
|
}
|
|
32
26
|
QueueService = _ts_decorate([
|
|
33
27
|
Injectable(),
|
|
@@ -1,18 +1,6 @@
|
|
|
1
1
|
import type { BindingRef } from '../binding-ref';
|
|
2
|
-
type R2Binding = Record<string, any>;
|
|
3
|
-
/**
|
|
4
|
-
* Wrapper around Cloudflare R2 Bucket.
|
|
5
|
-
* Injected via `R2Module.forRoot({ binding: 'ASSETS' })`.
|
|
6
|
-
*/
|
|
7
2
|
export declare class R2Service {
|
|
8
3
|
private ref;
|
|
9
|
-
constructor(ref: BindingRef);
|
|
10
|
-
|
|
11
|
-
get bucket(): R2Binding;
|
|
12
|
-
get(key: string, options?: Record<string, unknown>): Promise<unknown>;
|
|
13
|
-
head(key: string): Promise<unknown>;
|
|
14
|
-
put(key: string, value: ReadableStream | ArrayBuffer | ArrayBufferView | string | null | Blob, options?: Record<string, unknown>): Promise<unknown>;
|
|
15
|
-
delete(keys: string | string[]): Promise<void>;
|
|
16
|
-
list(options?: Record<string, unknown>): Promise<unknown>;
|
|
4
|
+
constructor(ref: BindingRef<R2Bucket>);
|
|
5
|
+
get bucket(): R2Bucket;
|
|
17
6
|
}
|
|
18
|
-
export {};
|
|
@@ -19,24 +19,9 @@ export class R2Service {
|
|
|
19
19
|
constructor(ref){
|
|
20
20
|
this.ref = ref;
|
|
21
21
|
}
|
|
22
|
-
|
|
22
|
+
get bucket() {
|
|
23
23
|
return this.ref.value;
|
|
24
24
|
}
|
|
25
|
-
get(key, options) {
|
|
26
|
-
return this.bucket.get(key, options);
|
|
27
|
-
}
|
|
28
|
-
head(key) {
|
|
29
|
-
return this.bucket.head(key);
|
|
30
|
-
}
|
|
31
|
-
put(key, value, options) {
|
|
32
|
-
return this.bucket.put(key, value, options);
|
|
33
|
-
}
|
|
34
|
-
delete(keys) {
|
|
35
|
-
return this.bucket.delete(keys);
|
|
36
|
-
}
|
|
37
|
-
list(options) {
|
|
38
|
-
return this.bucket.list(options);
|
|
39
|
-
}
|
|
40
25
|
}
|
|
41
26
|
R2Service = _ts_decorate([
|
|
42
27
|
Injectable(),
|
|
@@ -1,26 +1,6 @@
|
|
|
1
1
|
import type { BindingRef } from '../binding-ref';
|
|
2
|
-
type VectorizeBinding = {
|
|
3
|
-
query: Function;
|
|
4
|
-
insert: Function;
|
|
5
|
-
upsert: Function;
|
|
6
|
-
getByIds: Function;
|
|
7
|
-
deleteByIds: Function;
|
|
8
|
-
describe: Function;
|
|
9
|
-
} & Record<string, any>;
|
|
10
|
-
/**
|
|
11
|
-
* Wrapper around Cloudflare Vectorize Index.
|
|
12
|
-
* Injected via `VectorizeModule.forRoot({ binding: 'EMBEDDINGS' })`.
|
|
13
|
-
*/
|
|
14
2
|
export declare class VectorizeService {
|
|
15
3
|
private ref;
|
|
16
|
-
constructor(ref: BindingRef);
|
|
17
|
-
|
|
18
|
-
get index(): VectorizeBinding;
|
|
19
|
-
query(vector: number[], options?: Record<string, unknown>): Promise<unknown>;
|
|
20
|
-
insert(vectors: unknown[]): Promise<unknown>;
|
|
21
|
-
upsert(vectors: unknown[]): Promise<unknown>;
|
|
22
|
-
getByIds(ids: string[]): Promise<unknown>;
|
|
23
|
-
deleteByIds(ids: string[]): Promise<unknown>;
|
|
24
|
-
describe(): Promise<unknown>;
|
|
4
|
+
constructor(ref: BindingRef<VectorizeIndex>);
|
|
5
|
+
get index(): VectorizeIndex;
|
|
25
6
|
}
|
|
26
|
-
export {};
|
|
@@ -19,27 +19,9 @@ export class VectorizeService {
|
|
|
19
19
|
constructor(ref){
|
|
20
20
|
this.ref = ref;
|
|
21
21
|
}
|
|
22
|
-
|
|
22
|
+
get index() {
|
|
23
23
|
return this.ref.value;
|
|
24
24
|
}
|
|
25
|
-
query(vector, options) {
|
|
26
|
-
return this.index.query(vector, options);
|
|
27
|
-
}
|
|
28
|
-
insert(vectors) {
|
|
29
|
-
return this.index.insert(vectors);
|
|
30
|
-
}
|
|
31
|
-
upsert(vectors) {
|
|
32
|
-
return this.index.upsert(vectors);
|
|
33
|
-
}
|
|
34
|
-
getByIds(ids) {
|
|
35
|
-
return this.index.getByIds(ids);
|
|
36
|
-
}
|
|
37
|
-
deleteByIds(ids) {
|
|
38
|
-
return this.index.deleteByIds(ids);
|
|
39
|
-
}
|
|
40
|
-
describe() {
|
|
41
|
-
return this.index.describe();
|
|
42
|
-
}
|
|
43
25
|
}
|
|
44
26
|
VectorizeService = _ts_decorate([
|
|
45
27
|
Injectable(),
|
package/dist/tokens.d.ts
CHANGED
|
@@ -8,10 +8,3 @@ export declare const DO_BINDING_REF: InjectionToken<BindingRef<unknown>>;
|
|
|
8
8
|
export declare const AI_BINDING_REF: InjectionToken<BindingRef<unknown>>;
|
|
9
9
|
export declare const VECTORIZE_BINDING_REF: InjectionToken<BindingRef<unknown>>;
|
|
10
10
|
export declare const HYPERDRIVE_BINDING_REF: InjectionToken<BindingRef<unknown>>;
|
|
11
|
-
/**
|
|
12
|
-
* Global registry of binding refs to initialize on first request.
|
|
13
|
-
* Each module's `forRoot()` pushes its BindingRef here.
|
|
14
|
-
* createCloudflareApp reads from this to populate bindings.
|
|
15
|
-
*/
|
|
16
|
-
export declare const bindingsRegistry: BindingRef[];
|
|
17
|
-
export declare function clearBindingsRegistry(): void;
|
package/dist/tokens.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { InjectionToken } from "@velajs/vela";
|
|
2
|
-
//
|
|
2
|
+
// Tokens for binding refs — used by services to receive the binding value.
|
|
3
3
|
export const KV_BINDING_REF = new InjectionToken('CF_KV_BINDING_REF');
|
|
4
4
|
export const D1_BINDING_REF = new InjectionToken('CF_D1_BINDING_REF');
|
|
5
5
|
export const R2_BINDING_REF = new InjectionToken('CF_R2_BINDING_REF');
|
|
@@ -8,11 +8,3 @@ export const DO_BINDING_REF = new InjectionToken('CF_DO_BINDING_REF');
|
|
|
8
8
|
export const AI_BINDING_REF = new InjectionToken('CF_AI_BINDING_REF');
|
|
9
9
|
export const VECTORIZE_BINDING_REF = new InjectionToken('CF_VECTORIZE_BINDING_REF');
|
|
10
10
|
export const HYPERDRIVE_BINDING_REF = new InjectionToken('CF_HYPERDRIVE_BINDING_REF');
|
|
11
|
-
/**
|
|
12
|
-
* Global registry of binding refs to initialize on first request.
|
|
13
|
-
* Each module's `forRoot()` pushes its BindingRef here.
|
|
14
|
-
* createCloudflareApp reads from this to populate bindings.
|
|
15
|
-
*/ export const bindingsRegistry = [];
|
|
16
|
-
export function clearBindingsRegistry() {
|
|
17
|
-
bindingsRegistry.length = 0;
|
|
18
|
-
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@velajs/cloudflare",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Cloudflare Workers integration for Vela framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -17,6 +17,13 @@
|
|
|
17
17
|
"LICENSE",
|
|
18
18
|
"CHANGELOG.md"
|
|
19
19
|
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "rm -rf dist && swc src -d dist --strip-leading-paths && tsc --emitDeclarationOnly",
|
|
22
|
+
"test": "vitest run",
|
|
23
|
+
"typecheck": "tsc --noEmit",
|
|
24
|
+
"prepare": "swc src -d dist --strip-leading-paths && tsc --emitDeclarationOnly",
|
|
25
|
+
"prepublishOnly": "pnpm run typecheck && pnpm test"
|
|
26
|
+
},
|
|
20
27
|
"sideEffects": false,
|
|
21
28
|
"keywords": [
|
|
22
29
|
"vela",
|
|
@@ -44,26 +51,25 @@
|
|
|
44
51
|
"node": ">=20"
|
|
45
52
|
},
|
|
46
53
|
"peerDependencies": {
|
|
47
|
-
"@
|
|
54
|
+
"@cloudflare/workers-types": ">=4",
|
|
55
|
+
"@velajs/vela": ">=1.1.0",
|
|
48
56
|
"hono": ">=4"
|
|
49
57
|
},
|
|
50
|
-
"peerDependenciesMeta": {
|
|
51
|
-
"@velajs/vela": {
|
|
52
|
-
"optional": true
|
|
53
|
-
}
|
|
54
|
-
},
|
|
55
58
|
"devDependencies": {
|
|
59
|
+
"@cloudflare/workers-types": "^4",
|
|
56
60
|
"@swc/cli": "^0.8.0",
|
|
57
61
|
"@swc/core": "^1.15.11",
|
|
58
|
-
"@velajs/vela": "^1.
|
|
62
|
+
"@velajs/vela": "^1.1.0",
|
|
59
63
|
"hono": "^4",
|
|
60
64
|
"typescript": "^5",
|
|
61
65
|
"unplugin-swc": "^1.5.9",
|
|
62
66
|
"vitest": "^4.0.18"
|
|
63
67
|
},
|
|
64
|
-
"
|
|
65
|
-
|
|
66
|
-
"
|
|
67
|
-
|
|
68
|
+
"packageManager": "pnpm@10.20.0",
|
|
69
|
+
"pnpm": {
|
|
70
|
+
"onlyBuiltDependencies": [
|
|
71
|
+
"@swc/core",
|
|
72
|
+
"esbuild"
|
|
73
|
+
]
|
|
68
74
|
}
|
|
69
|
-
}
|
|
75
|
+
}
|