@velajs/cloudflare 0.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.
Files changed (52) hide show
  1. package/README.md +372 -0
  2. package/dist/binding-ref.d.ts +15 -0
  3. package/dist/binding-ref.js +23 -0
  4. package/dist/cloudflare-application.d.ts +51 -0
  5. package/dist/cloudflare-application.js +77 -0
  6. package/dist/cloudflare-factory.d.ts +18 -0
  7. package/dist/cloudflare-factory.js +42 -0
  8. package/dist/decorators/env.d.ts +16 -0
  9. package/dist/decorators/env.js +22 -0
  10. package/dist/decorators/queue-consumer.d.ts +23 -0
  11. package/dist/decorators/queue-consumer.js +32 -0
  12. package/dist/decorators/scheduled.d.ts +20 -0
  13. package/dist/decorators/scheduled.js +29 -0
  14. package/dist/index.d.ts +27 -0
  15. package/dist/index.js +29 -0
  16. package/dist/modules/ai.module.d.ts +6 -0
  17. package/dist/modules/ai.module.js +31 -0
  18. package/dist/modules/d1.module.d.ts +6 -0
  19. package/dist/modules/d1.module.js +31 -0
  20. package/dist/modules/durable-object.module.d.ts +6 -0
  21. package/dist/modules/durable-object.module.js +31 -0
  22. package/dist/modules/hyperdrive.module.d.ts +6 -0
  23. package/dist/modules/hyperdrive.module.js +31 -0
  24. package/dist/modules/kv.module.d.ts +6 -0
  25. package/dist/modules/kv.module.js +31 -0
  26. package/dist/modules/queue.module.d.ts +6 -0
  27. package/dist/modules/queue.module.js +31 -0
  28. package/dist/modules/r2.module.d.ts +6 -0
  29. package/dist/modules/r2.module.js +31 -0
  30. package/dist/modules/vectorize.module.d.ts +6 -0
  31. package/dist/modules/vectorize.module.js +31 -0
  32. package/dist/services/ai.service.d.ts +16 -0
  33. package/dist/services/ai.service.js +36 -0
  34. package/dist/services/d1.service.d.ts +22 -0
  35. package/dist/services/d1.service.js +47 -0
  36. package/dist/services/durable-object.service.d.ts +24 -0
  37. package/dist/services/durable-object.service.js +48 -0
  38. package/dist/services/hyperdrive.service.d.ts +26 -0
  39. package/dist/services/hyperdrive.service.js +51 -0
  40. package/dist/services/kv.service.d.ts +24 -0
  41. package/dist/services/kv.service.js +48 -0
  42. package/dist/services/queue.service.d.ts +20 -0
  43. package/dist/services/queue.service.js +39 -0
  44. package/dist/services/r2.service.d.ts +18 -0
  45. package/dist/services/r2.service.js +48 -0
  46. package/dist/services/vectorize.service.d.ts +26 -0
  47. package/dist/services/vectorize.service.js +51 -0
  48. package/dist/tokens.d.ts +17 -0
  49. package/dist/tokens.js +18 -0
  50. package/dist/types.d.ts +13 -0
  51. package/dist/types.js +1 -0
  52. package/package.json +69 -0
@@ -0,0 +1,20 @@
1
+ export interface ScheduledMetadata {
2
+ cron: string;
3
+ methodName: string;
4
+ }
5
+ /**
6
+ * Marks a method as a scheduled (cron) handler.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * @Injectable()
11
+ * class WorkerService {
12
+ * @Scheduled('0 * * * *')
13
+ * async hourlyCron() {
14
+ * console.log('Running hourly');
15
+ * }
16
+ * }
17
+ * ```
18
+ */
19
+ export declare function Scheduled(cron: string): MethodDecorator;
20
+ export declare function getScheduledMetadata(target: object): ScheduledMetadata[];
@@ -0,0 +1,29 @@
1
+ import { defineMetadata, getMetadata } from "@velajs/vela";
2
+ const SCHEDULED_METADATA_KEY = 'cloudflare:scheduled';
3
+ /**
4
+ * Marks a method as a scheduled (cron) handler.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * @Injectable()
9
+ * class WorkerService {
10
+ * @Scheduled('0 * * * *')
11
+ * async hourlyCron() {
12
+ * console.log('Running hourly');
13
+ * }
14
+ * }
15
+ * ```
16
+ */ export function Scheduled(cron) {
17
+ return (target, propertyKey, _descriptor)=>{
18
+ const existing = getMetadata(SCHEDULED_METADATA_KEY, target.constructor) ?? [];
19
+ existing.push({
20
+ cron,
21
+ methodName: String(propertyKey)
22
+ });
23
+ defineMetadata(SCHEDULED_METADATA_KEY, existing, target.constructor);
24
+ };
25
+ }
26
+ export function getScheduledMetadata(target) {
27
+ const ctor = target.constructor ?? target;
28
+ return getMetadata(SCHEDULED_METADATA_KEY, ctor) ?? [];
29
+ }
@@ -0,0 +1,27 @@
1
+ export { CloudflareFactory } from './cloudflare-factory';
2
+ export { CloudflareApplication } from './cloudflare-application';
3
+ export { KVModule } from './modules/kv.module';
4
+ export { D1Module } from './modules/d1.module';
5
+ export { R2Module } from './modules/r2.module';
6
+ export { QueueModule } from './modules/queue.module';
7
+ export { DurableObjectModule } from './modules/durable-object.module';
8
+ export { AIModule } from './modules/ai.module';
9
+ export { VectorizeModule } from './modules/vectorize.module';
10
+ export { HyperdriveModule } from './modules/hyperdrive.module';
11
+ export { KVService } from './services/kv.service';
12
+ export { D1Service } from './services/d1.service';
13
+ export { R2Service } from './services/r2.service';
14
+ export { QueueService } from './services/queue.service';
15
+ export { DurableObjectService } from './services/durable-object.service';
16
+ export { AIService } from './services/ai.service';
17
+ export { VectorizeService } from './services/vectorize.service';
18
+ export { HyperdriveService } from './services/hyperdrive.service';
19
+ export { Env } from './decorators/env';
20
+ export { Scheduled } from './decorators/scheduled';
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
+ export type { CloudflareEnv, ScheduledRegistration, QueueRegistration } from './types';
26
+ export type { ScheduledMetadata } from './decorators/scheduled';
27
+ export type { QueueConsumerMetadata } from './decorators/queue-consumer';
package/dist/index.js ADDED
@@ -0,0 +1,29 @@
1
+ // Factory & Application
2
+ export { CloudflareFactory } from "./cloudflare-factory.js";
3
+ export { CloudflareApplication } from "./cloudflare-application.js";
4
+ // Modules
5
+ export { KVModule } from "./modules/kv.module.js";
6
+ export { D1Module } from "./modules/d1.module.js";
7
+ export { R2Module } from "./modules/r2.module.js";
8
+ export { QueueModule } from "./modules/queue.module.js";
9
+ export { DurableObjectModule } from "./modules/durable-object.module.js";
10
+ export { AIModule } from "./modules/ai.module.js";
11
+ export { VectorizeModule } from "./modules/vectorize.module.js";
12
+ export { HyperdriveModule } from "./modules/hyperdrive.module.js";
13
+ // Services
14
+ export { KVService } from "./services/kv.service.js";
15
+ export { D1Service } from "./services/d1.service.js";
16
+ export { R2Service } from "./services/r2.service.js";
17
+ export { QueueService } from "./services/queue.service.js";
18
+ export { DurableObjectService } from "./services/durable-object.service.js";
19
+ export { AIService } from "./services/ai.service.js";
20
+ export { VectorizeService } from "./services/vectorize.service.js";
21
+ export { HyperdriveService } from "./services/hyperdrive.service.js";
22
+ // Decorators
23
+ export { Env } from "./decorators/env.js";
24
+ export { Scheduled } from "./decorators/scheduled.js";
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";
@@ -0,0 +1,6 @@
1
+ import type { DynamicModule } from '@velajs/vela';
2
+ export declare class AIModule {
3
+ static forRoot(options: {
4
+ binding: string;
5
+ }): DynamicModule;
6
+ }
@@ -0,0 +1,31 @@
1
+ import { MetadataRegistry } from "@velajs/vela";
2
+ import { BindingRef } from "../binding-ref.js";
3
+ import { AI_BINDING_REF, bindingsRegistry } from "../tokens.js";
4
+ import { AIService } from "../services/ai.service.js";
5
+ export class AIModule {
6
+ static forRoot(options) {
7
+ const ref = new BindingRef(options.binding);
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
+ return {
21
+ module: moduleClass,
22
+ providers: [
23
+ {
24
+ token: AI_BINDING_REF,
25
+ useValue: ref
26
+ },
27
+ AIService
28
+ ]
29
+ };
30
+ }
31
+ }
@@ -0,0 +1,6 @@
1
+ import type { DynamicModule } from '@velajs/vela';
2
+ export declare class D1Module {
3
+ static forRoot(options: {
4
+ binding: string;
5
+ }): DynamicModule;
6
+ }
@@ -0,0 +1,31 @@
1
+ import { MetadataRegistry } from "@velajs/vela";
2
+ import { BindingRef } from "../binding-ref.js";
3
+ import { D1_BINDING_REF, bindingsRegistry } from "../tokens.js";
4
+ import { D1Service } from "../services/d1.service.js";
5
+ export class D1Module {
6
+ static forRoot(options) {
7
+ const ref = new BindingRef(options.binding);
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
+ return {
21
+ module: moduleClass,
22
+ providers: [
23
+ {
24
+ token: D1_BINDING_REF,
25
+ useValue: ref
26
+ },
27
+ D1Service
28
+ ]
29
+ };
30
+ }
31
+ }
@@ -0,0 +1,6 @@
1
+ import type { DynamicModule } from '@velajs/vela';
2
+ export declare class DurableObjectModule {
3
+ static forRoot(options: {
4
+ binding: string;
5
+ }): DynamicModule;
6
+ }
@@ -0,0 +1,31 @@
1
+ import { MetadataRegistry } from "@velajs/vela";
2
+ import { BindingRef } from "../binding-ref.js";
3
+ import { DO_BINDING_REF, bindingsRegistry } from "../tokens.js";
4
+ import { DurableObjectService } from "../services/durable-object.service.js";
5
+ export class DurableObjectModule {
6
+ static forRoot(options) {
7
+ const ref = new BindingRef(options.binding);
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
+ return {
21
+ module: moduleClass,
22
+ providers: [
23
+ {
24
+ token: DO_BINDING_REF,
25
+ useValue: ref
26
+ },
27
+ DurableObjectService
28
+ ]
29
+ };
30
+ }
31
+ }
@@ -0,0 +1,6 @@
1
+ import type { DynamicModule } from '@velajs/vela';
2
+ export declare class HyperdriveModule {
3
+ static forRoot(options: {
4
+ binding: string;
5
+ }): DynamicModule;
6
+ }
@@ -0,0 +1,31 @@
1
+ import { MetadataRegistry } from "@velajs/vela";
2
+ import { BindingRef } from "../binding-ref.js";
3
+ import { HYPERDRIVE_BINDING_REF, bindingsRegistry } from "../tokens.js";
4
+ import { HyperdriveService } from "../services/hyperdrive.service.js";
5
+ export class HyperdriveModule {
6
+ static forRoot(options) {
7
+ const ref = new BindingRef(options.binding);
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
+ return {
21
+ module: moduleClass,
22
+ providers: [
23
+ {
24
+ token: HYPERDRIVE_BINDING_REF,
25
+ useValue: ref
26
+ },
27
+ HyperdriveService
28
+ ]
29
+ };
30
+ }
31
+ }
@@ -0,0 +1,6 @@
1
+ import type { DynamicModule } from '@velajs/vela';
2
+ export declare class KVModule {
3
+ static forRoot(options: {
4
+ binding: string;
5
+ }): DynamicModule;
6
+ }
@@ -0,0 +1,31 @@
1
+ import { MetadataRegistry } from "@velajs/vela";
2
+ import { BindingRef } from "../binding-ref.js";
3
+ import { KV_BINDING_REF, bindingsRegistry } from "../tokens.js";
4
+ import { KVService } from "../services/kv.service.js";
5
+ export class KVModule {
6
+ static forRoot(options) {
7
+ const ref = new BindingRef(options.binding);
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
+ return {
21
+ module: moduleClass,
22
+ providers: [
23
+ {
24
+ token: KV_BINDING_REF,
25
+ useValue: ref
26
+ },
27
+ KVService
28
+ ]
29
+ };
30
+ }
31
+ }
@@ -0,0 +1,6 @@
1
+ import type { DynamicModule } from '@velajs/vela';
2
+ export declare class QueueModule {
3
+ static forRoot(options: {
4
+ binding: string;
5
+ }): DynamicModule;
6
+ }
@@ -0,0 +1,31 @@
1
+ import { MetadataRegistry } from "@velajs/vela";
2
+ import { BindingRef } from "../binding-ref.js";
3
+ import { QUEUE_BINDING_REF, bindingsRegistry } from "../tokens.js";
4
+ import { QueueService } from "../services/queue.service.js";
5
+ export class QueueModule {
6
+ static forRoot(options) {
7
+ const ref = new BindingRef(options.binding);
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
+ return {
21
+ module: moduleClass,
22
+ providers: [
23
+ {
24
+ token: QUEUE_BINDING_REF,
25
+ useValue: ref
26
+ },
27
+ QueueService
28
+ ]
29
+ };
30
+ }
31
+ }
@@ -0,0 +1,6 @@
1
+ import type { DynamicModule } from '@velajs/vela';
2
+ export declare class R2Module {
3
+ static forRoot(options: {
4
+ binding: string;
5
+ }): DynamicModule;
6
+ }
@@ -0,0 +1,31 @@
1
+ import { MetadataRegistry } from "@velajs/vela";
2
+ import { BindingRef } from "../binding-ref.js";
3
+ import { R2_BINDING_REF, bindingsRegistry } from "../tokens.js";
4
+ import { R2Service } from "../services/r2.service.js";
5
+ export class R2Module {
6
+ static forRoot(options) {
7
+ const ref = new BindingRef(options.binding);
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
+ return {
21
+ module: moduleClass,
22
+ providers: [
23
+ {
24
+ token: R2_BINDING_REF,
25
+ useValue: ref
26
+ },
27
+ R2Service
28
+ ]
29
+ };
30
+ }
31
+ }
@@ -0,0 +1,6 @@
1
+ import type { DynamicModule } from '@velajs/vela';
2
+ export declare class VectorizeModule {
3
+ static forRoot(options: {
4
+ binding: string;
5
+ }): DynamicModule;
6
+ }
@@ -0,0 +1,31 @@
1
+ import { MetadataRegistry } from "@velajs/vela";
2
+ import { BindingRef } from "../binding-ref.js";
3
+ import { VECTORIZE_BINDING_REF, bindingsRegistry } from "../tokens.js";
4
+ import { VectorizeService } from "../services/vectorize.service.js";
5
+ export class VectorizeModule {
6
+ static forRoot(options) {
7
+ const ref = new BindingRef(options.binding);
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
+ return {
21
+ module: moduleClass,
22
+ providers: [
23
+ {
24
+ token: VECTORIZE_BINDING_REF,
25
+ useValue: ref
26
+ },
27
+ VectorizeService
28
+ ]
29
+ };
30
+ }
31
+ }
@@ -0,0 +1,16 @@
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
+ export declare class AIService {
10
+ private ref;
11
+ constructor(ref: BindingRef);
12
+ /** Access the raw Ai binding directly. */
13
+ get binding(): AIBinding;
14
+ run(model: string, inputs: Record<string, unknown>, options?: Record<string, unknown>): Promise<unknown>;
15
+ }
16
+ export {};
@@ -0,0 +1,36 @@
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
+ /** Access the raw Ai binding directly. */ get binding() {
23
+ return this.ref.value;
24
+ }
25
+ run(model, inputs, options) {
26
+ return this.binding.run(model, inputs, options);
27
+ }
28
+ }
29
+ AIService = _ts_decorate([
30
+ Injectable(),
31
+ _ts_param(0, Inject(AI_BINDING_REF)),
32
+ _ts_metadata("design:type", Function),
33
+ _ts_metadata("design:paramtypes", [
34
+ typeof BindingRef === "undefined" ? Object : BindingRef
35
+ ])
36
+ ], AIService);
@@ -0,0 +1,22 @@
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
+ export declare class D1Service {
13
+ private ref;
14
+ constructor(ref: BindingRef);
15
+ /** Access the raw D1Database binding directly. */
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>;
21
+ }
22
+ export {};
@@ -0,0 +1,47 @@
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
+ /** Access the raw D1Database binding directly. */ get database() {
23
+ return this.ref.value;
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
+ }
40
+ D1Service = _ts_decorate([
41
+ Injectable(),
42
+ _ts_param(0, Inject(D1_BINDING_REF)),
43
+ _ts_metadata("design:type", Function),
44
+ _ts_metadata("design:paramtypes", [
45
+ typeof BindingRef === "undefined" ? Object : BindingRef
46
+ ])
47
+ ], D1Service);
@@ -0,0 +1,24 @@
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
+ export declare class DurableObjectService {
14
+ private ref;
15
+ constructor(ref: BindingRef);
16
+ /** Access the raw DurableObjectNamespace binding directly. */
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;
23
+ }
24
+ export {};
@@ -0,0 +1,48 @@
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
+ /** Access the raw DurableObjectNamespace binding directly. */ get namespace() {
23
+ return this.ref.value;
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
+ }
41
+ DurableObjectService = _ts_decorate([
42
+ Injectable(),
43
+ _ts_param(0, Inject(DO_BINDING_REF)),
44
+ _ts_metadata("design:type", Function),
45
+ _ts_metadata("design:paramtypes", [
46
+ typeof BindingRef === "undefined" ? Object : BindingRef
47
+ ])
48
+ ], DurableObjectService);
@@ -0,0 +1,26 @@
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
+ export declare class HyperdriveService {
15
+ private ref;
16
+ constructor(ref: BindingRef);
17
+ /** Access the raw Hyperdrive binding directly. */
18
+ get binding(): HyperdriveBinding;
19
+ get connectionString(): string;
20
+ get host(): string;
21
+ get port(): number;
22
+ get user(): string;
23
+ get password(): string;
24
+ get database(): string;
25
+ }
26
+ export {};