@velajs/cloudflare 1.31.0 → 1.33.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 (68) hide show
  1. package/CHANGELOG.md +85 -0
  2. package/README.md +154 -10
  3. package/dist/bindings.js +17 -1
  4. package/dist/bindings.js.map +1 -1
  5. package/dist/{cloudflare-factory-eGiet0mg.d.ts → cloudflare-application-CXDy9C1R.d.ts} +9 -98
  6. package/dist/cloudflare-application.js +8 -0
  7. package/dist/cloudflare-application.js.map +1 -1
  8. package/dist/cloudflare-factory-CuFNUJJD.d.ts +241 -0
  9. package/dist/cloudflare-factory.js +153 -20
  10. package/dist/cloudflare-factory.js.map +1 -1
  11. package/dist/durable-object/boot.js +76 -0
  12. package/dist/durable-object/boot.js.map +1 -0
  13. package/dist/durable-object/host-dispatch.js +134 -0
  14. package/dist/durable-object/host-dispatch.js.map +1 -0
  15. package/dist/durable-object/host-methods.js +47 -0
  16. package/dist/durable-object/host-methods.js.map +1 -0
  17. package/dist/durable-object/tokens.js +17 -0
  18. package/dist/durable-object/tokens.js.map +1 -0
  19. package/dist/durable-object/vela-durable-object.js +121 -0
  20. package/dist/durable-object/vela-durable-object.js.map +1 -0
  21. package/dist/durable-objects.d.ts +131 -9
  22. package/dist/durable-objects.js +3 -1
  23. package/dist/email/email-dispatch.js +65 -0
  24. package/dist/email/email-dispatch.js.map +1 -0
  25. package/dist/email/on-email.js +57 -0
  26. package/dist/email/on-email.js.map +1 -0
  27. package/dist/email.d.ts +51 -0
  28. package/dist/email.js +3 -0
  29. package/dist/entrypoint/vela-entrypoint.js +160 -0
  30. package/dist/entrypoint/vela-entrypoint.js.map +1 -0
  31. package/dist/entrypoints.d.ts +93 -0
  32. package/dist/entrypoints.js +2 -0
  33. package/dist/host/host-invoker.js +276 -0
  34. package/dist/host/host-invoker.js.map +1 -0
  35. package/dist/host/host-members.js +73 -0
  36. package/dist/host/host-members.js.map +1 -0
  37. package/dist/host-members-DECj_4yz.d.ts +13 -0
  38. package/dist/index.d.ts +74 -13
  39. package/dist/index.js +4 -3
  40. package/dist/root-module.js +19 -0
  41. package/dist/root-module.js.map +1 -0
  42. package/dist/rpc/entrypoint-error.js +145 -0
  43. package/dist/rpc/entrypoint-error.js.map +1 -0
  44. package/dist/services/kv-cache.store.js +4 -4
  45. package/dist/services/kv-cache.store.js.map +1 -1
  46. package/dist/tail/on-tail.js +46 -0
  47. package/dist/tail/on-tail.js.map +1 -0
  48. package/dist/tail/tail-dispatch.js +67 -0
  49. package/dist/tail/tail-dispatch.js.map +1 -0
  50. package/dist/tail.d.ts +39 -0
  51. package/dist/tail.js +2 -0
  52. package/dist/testing.d.ts +55 -3
  53. package/dist/testing.js +78 -1
  54. package/dist/testing.js.map +1 -1
  55. package/dist/websocket/binding-gateways.js +1 -1
  56. package/dist/websocket/binding-gateways.js.map +1 -1
  57. package/dist/websocket/do-bootstrap.js +40 -37
  58. package/dist/websocket/do-bootstrap.js.map +1 -1
  59. package/dist/websocket/websocket.durable-object.js +37 -8
  60. package/dist/websocket/websocket.durable-object.js.map +1 -1
  61. package/dist/worker-events.js +49 -0
  62. package/dist/worker-events.js.map +1 -0
  63. package/dist/workflow/vela-workflow.js +104 -0
  64. package/dist/workflow/vela-workflow.js.map +1 -0
  65. package/dist/workflows.d.ts +82 -0
  66. package/dist/workflows.js +2 -0
  67. package/package.json +23 -7
  68. package/dist/root-module-C23bUwt_.d.ts +0 -11
@@ -0,0 +1,82 @@
1
+ import "./vela-env-DFvyoNT3.js";
2
+ import { a as CloudflareApp } from "./cloudflare-factory-CuFNUJJD.js";
3
+ import { WorkflowEntrypoint, WorkflowEvent, WorkflowStep } from "cloudflare:workers";
4
+ import { Type, VelaEnv } from "@velajs/vela";
5
+ import { EntrypointExecutionContext } from "@velajs/vela/module-kit";
6
+ //#region src/workflow/vela-workflow.d.ts
7
+ /**
8
+ * A class `VelaWorkflow()` runs: an `@Injectable()` whose
9
+ * `run(event, step)` is the Workflow's body, typed with the params in
10
+ * `event.payload`.
11
+ */
12
+ interface WorkflowHost {
13
+ run(event: never, step: never): unknown;
14
+ }
15
+ /**
16
+ * The params a Workflow takes: the `event.payload` type of its host's
17
+ * `run(event, step)`, or of the `run` of a class from `VelaWorkflow()`.
18
+ * `workflow<WorkflowParams<SignupWorkflow>>({ binding })` types the binding
19
+ * that creates its instances.
20
+ */
21
+ type WorkflowParams<Target> = Target extends (abstract new (...args: never[]) => infer Instance) ? WorkflowParams<Instance> : Target extends {
22
+ run(event: infer Event, ...rest: never[]): unknown;
23
+ } ? Event extends {
24
+ readonly payload: infer Payload;
25
+ } ? Payload : unknown : never;
26
+ /** What a Workflow host's `run(event, step)` resolves to: the instance's output. */
27
+ type WorkflowOutput<Host extends WorkflowHost> = Awaited<ReturnType<Host['run']>>;
28
+ /** The ExecutionContext guards, interceptors and filters receive around a Workflow run. */
29
+ type WorkflowExecutionContext = EntrypointExecutionContext<'cf:workflow'>;
30
+ /**
31
+ * The class `VelaWorkflow(app, Host)` returns: export a named subclass of it,
32
+ * matching the Wrangler `workflows` entry's `class_name`. It also carries its
33
+ * `CloudflareWorkflowDescriptor` under the static `CLOUDFLARE_WORKFLOW` key,
34
+ * for tools.
35
+ */
36
+ type VelaWorkflowClass<Host extends WorkflowHost> = new (ctx: ExecutionContext, env: VelaEnv) => {
37
+ run(event: Readonly<WorkflowEvent<WorkflowParams<Host>>>, step: WorkflowStep): Promise<WorkflowOutput<Host>>;
38
+ } & WorkflowEntrypoint<VelaEnv, WorkflowParams<Host>>;
39
+ /**
40
+ * A Workflow class (a `WorkflowEntrypoint`) whose `run(event, step)` is the
41
+ * `run` method of `host`, an `@Injectable()` class, resolved in the Worker's
42
+ * application for the run's environment: the same application the app's
43
+ * Worker handlers use. The host is added to the root module's providers, so
44
+ * it injects `ENV` and what the root module can see. Export a named subclass
45
+ * matching the Wrangler `class_name`:
46
+ *
47
+ * ```ts
48
+ * @Injectable()
49
+ * export class SignupWorkflowHost {
50
+ * constructor(private readonly users: UsersService) {}
51
+ *
52
+ * async run(event: WorkflowEvent<{ email: string }>, step: WorkflowStep) {
53
+ * const user = await step.do('create user', () => this.users.create(event.payload.email));
54
+ * await step.sleep('grace period', '1 day');
55
+ * return step.do('send welcome', () => this.users.welcome(user.id));
56
+ * }
57
+ * }
58
+ * export class SignupWorkflow extends VelaWorkflow(app, SignupWorkflowHost) {}
59
+ * // Worker code: await env.SIGNUP_WORKFLOW.create({ params: { email } })
60
+ * ```
61
+ *
62
+ * - Each run executes in its own execution scope, so request-scoped providers
63
+ * are built per run, through the host's scoped guards, interceptors and
64
+ * exception filters (`getType()` is `'cf:workflow'`, `getPayload()` the
65
+ * event). The engine may run `run()` again for the same instance (after a
66
+ * sleep, an event or an eviction), replaying completed steps from their
67
+ * stored results: each call is a new run.
68
+ * - `event` and `step` are the platform's own objects, passed through
69
+ * untouched, so `step.do`, `step.sleep` and `step.waitForEvent` keep their
70
+ * retry and replay semantics.
71
+ * - A failure is reported (`edge: 'workflow'`) and rethrown as it is, so the
72
+ * engine applies its own semantics, including `NonRetryableError`. A scoped
73
+ * exception filter that catches it settles the run with what it returns.
74
+ * - The engine's own interruptions (an `Error('Aborting engine: ...')` that a
75
+ * step rejects with when the instance is paused, restarted or terminated)
76
+ * are not failures: they pass through unreported, and no filter sees them.
77
+ * - `host` must declare `run` on its prototype; a host whose prototype
78
+ * defines `then()` is rejected, since an instance would be a thenable.
79
+ */
80
+ export declare function VelaWorkflow<Host extends WorkflowHost>(app: CloudflareApp, host: Type<Host>): VelaWorkflowClass<Host>;
81
+ //#endregion
82
+ export type { VelaWorkflowClass, WorkflowExecutionContext, WorkflowHost, WorkflowOutput, WorkflowParams };
@@ -0,0 +1,2 @@
1
+ import { VelaWorkflow } from "./workflow/vela-workflow.js";
2
+ export { VelaWorkflow };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@velajs/cloudflare",
3
- "version": "1.31.0",
3
+ "version": "1.33.0",
4
4
  "description": "Cloudflare Workers integration for Vela framework",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -44,6 +44,14 @@
44
44
  "types": "./dist/durable-objects.d.ts",
45
45
  "import": "./dist/durable-objects.js"
46
46
  },
47
+ "./email": {
48
+ "types": "./dist/email.d.ts",
49
+ "import": "./dist/email.js"
50
+ },
51
+ "./entrypoints": {
52
+ "types": "./dist/entrypoints.d.ts",
53
+ "import": "./dist/entrypoints.js"
54
+ },
47
55
  "./queues": {
48
56
  "types": "./dist/queues.d.ts",
49
57
  "import": "./dist/queues.js"
@@ -52,9 +60,17 @@
52
60
  "types": "./dist/storage.d.ts",
53
61
  "import": "./dist/storage.js"
54
62
  },
63
+ "./tail": {
64
+ "types": "./dist/tail.d.ts",
65
+ "import": "./dist/tail.js"
66
+ },
55
67
  "./testing": {
56
68
  "types": "./dist/testing.d.ts",
57
69
  "import": "./dist/testing.js"
70
+ },
71
+ "./workflows": {
72
+ "types": "./dist/workflows.d.ts",
73
+ "import": "./dist/workflows.js"
58
74
  }
59
75
  },
60
76
  "publishConfig": {
@@ -76,17 +92,17 @@
76
92
  "vitest": "4.1.11",
77
93
  "zod": "^3.25.76",
78
94
  "@velajs/feature-flags": "1.31.0",
79
- "@velajs/storage": "1.31.0",
80
- "@velajs/testing": "1.31.0",
81
- "@velajs/vela": "1.31.0"
95
+ "@velajs/storage": "1.33.0",
96
+ "@velajs/testing": "1.33.0",
97
+ "@velajs/vela": "1.33.0"
82
98
  },
83
99
  "peerDependencies": {
84
100
  "@cloudflare/workers-types": ">=4",
85
101
  "hono": ">=4",
86
102
  "@velajs/feature-flags": "^1.31.0",
87
- "@velajs/storage": "^1.31.0",
88
- "@velajs/testing": "^1.31.0",
89
- "@velajs/vela": "^1.31.0"
103
+ "@velajs/storage": "^1.33.0",
104
+ "@velajs/vela": "^1.33.0",
105
+ "@velajs/testing": "^1.33.0"
90
106
  },
91
107
  "peerDependenciesMeta": {
92
108
  "@velajs/feature-flags": {
@@ -1,11 +0,0 @@
1
- import { DynamicModule, Type } from "@velajs/vela";
2
- //#region src/root-module.d.ts
3
- /**
4
- * The root a Worker or Durable Object is built from: a module class or a
5
- * `DynamicModule`, declared once at module scope. Configuration that needs
6
- * bindings belongs in providers and `forRootAsync({ inject: [ENV] })`
7
- * factories, which run for each application with that application's ENV.
8
- */
9
- type CloudflareRoot = Type | DynamicModule;
10
- //#endregion
11
- export { CloudflareRoot as t };