effect-cf 0.29.0 → 0.31.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/src/Vitest.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Effect-native helpers for tests running in Cloudflare's Vitest Workers pool.
2
+ * Effect-native helpers for tests running in Cloudflare's Workers Vitest plugin.
3
3
  *
4
4
  * Import this module through the `effect-cf/vitest` subpath. It is intended to
5
5
  * run inside the Workers test runtime, where `cloudflare:test` is available.
@@ -37,7 +37,7 @@ import type { WorkflowInstanceStatusName } from "./WorkflowBinding";
37
37
  const currentEnv: WorkerEnv = env;
38
38
 
39
39
  /**
40
- * Provides the Workers pool environment as both {@link WorkerEnvironment} and
40
+ * Provides the Workers test environment as both {@link WorkerEnvironment} and
41
41
  * the active Effect `ConfigProvider`.
42
42
  */
43
43
  export const layer: Layer.Layer<WorkerEnvironment> = Layer.mergeAll(
@@ -134,7 +134,7 @@ type PagesEventContextInitData<Context> =
134
134
  : { readonly data: Data }
135
135
  : never;
136
136
 
137
- /** Initialization accepted by Pool Workers for a Pages Function. */
137
+ /** Initialization accepted by the Workers Vitest plugin for a Pages Function. */
138
138
  export type PagesEventContextInit<Function extends AnyPagesFunction> = PagesEventContextInitBase &
139
139
  PagesEventContextInitParams<Parameters<Function>[0]> &
140
140
  PagesEventContextInitData<Parameters<Function>[0]>;
@@ -162,14 +162,14 @@ interface QueueWorker {
162
162
  queue(batch: globalThis.MessageBatch): Promise<void>;
163
163
  }
164
164
 
165
- /** Input message accepted by Pool Workers' `createMessageBatch` helper. */
165
+ /** Input message accepted by the Workers Vitest plugin's `createMessageBatch` helper. */
166
166
  export type QueueMessage<Body> = {
167
167
  readonly id: string;
168
168
  readonly timestamp: Date;
169
169
  readonly attempts: number;
170
170
  } & ({ readonly body: Body } | { readonly serializedBody: ArrayBuffer | ArrayBufferView });
171
171
 
172
- /** Acknowledgement and retry result returned by Pool Workers. */
172
+ /** Acknowledgement and retry result returned by the Workers Vitest plugin. */
173
173
  export type QueueResult = Awaited<ReturnType<typeof getQueueResult>>;
174
174
 
175
175
  /** Result of invoking a queue consumer through {@link queue}. */
@@ -180,7 +180,7 @@ export interface QueueRunResult<Body> {
180
180
 
181
181
  /**
182
182
  * Invokes an Effect-backed queue consumer, drains its `waitUntil` work, and
183
- * returns Pool Workers' acknowledgement and retry result.
183
+ * returns the Workers Vitest plugin's acknowledgement and retry result.
184
184
  */
185
185
  export const queue = Effect.fn("effect-cf/vitest/queue")(function* <
186
186
  Body,
@@ -280,7 +280,7 @@ export const evictAllDurableObjects = Effect.fn("effect-cf/vitest/evictAllDurabl
280
280
  },
281
281
  );
282
282
 
283
- /** A D1 migration accepted by Pool Workers. */
283
+ /** A D1 migration accepted by the Workers Vitest plugin. */
284
284
  export interface D1Migration {
285
285
  readonly name: string;
286
286
  readonly queries: ReadonlyArray<string>;
@@ -310,7 +310,7 @@ export interface SecretsStoreSecret {
310
310
  readonly metadata?: { readonly uuid: string };
311
311
  }
312
312
 
313
- /** Effect-native wrapper around Pool Workers' Secrets Store admin API. */
313
+ /** Effect-native wrapper around the Workers Vitest plugin's Secrets Store admin API. */
314
314
  export interface SecretsStoreAdmin {
315
315
  readonly raw: NativeSecretsStoreAdmin;
316
316
  readonly create: (value: string) => Effect.Effect<string>;
@@ -445,7 +445,7 @@ const runWorkflowModifier = Effect.fnUntraced(function* <A, E, R>(
445
445
  }
446
446
 
447
447
  if (callbackExit === undefined) {
448
- throw new Error("Pool Workers did not invoke the Workflow modifier callback");
448
+ throw new Error("The Workers Vitest plugin did not invoke the Workflow modifier callback");
449
449
  }
450
450
 
451
451
  return callbackExit;
package/src/Worker.ts CHANGED
@@ -46,6 +46,8 @@ export interface WorkerContextService {
46
46
  options?: Omit<WorkerContextWaitUntilOptions<E, R2>, "mode">,
47
47
  ): Effect.Effect<void, never, R | R2>;
48
48
  readonly passThroughOnException: Effect.Effect<void>;
49
+ /** Abort the current stateless Worker invocation (`ExecutionContext.abort`). */
50
+ abort(reason?: string): Effect.Effect<void>;
49
51
  }
50
52
 
51
53
  /**
@@ -3,7 +3,9 @@ import type {
3
3
  Workflow as CloudflareWorkflow,
4
4
  WorkflowInstance as CloudflareWorkflowInstance,
5
5
  WorkflowInstanceCreateOptions as CloudflareWorkflowInstanceCreateOptions,
6
+ WorkflowInstanceLocationHint as CloudflareWorkflowInstanceLocationHint,
6
7
  WorkflowInstanceRestartOptions as CloudflareWorkflowInstanceRestartOptions,
8
+ WorkflowInstanceTerminateOptions as CloudflareWorkflowInstanceTerminateOptions,
7
9
  } from "@cloudflare/workers-types";
8
10
  import { type Context, Data, Effect, Option, Predicate, Schema as S } from "effect";
9
11
 
@@ -23,6 +25,8 @@ export type WorkflowInstanceCreateBatchOptions<Payload, EncodedPayload = unknown
23
25
  >;
24
26
 
25
27
  export type WorkflowInstanceRestartOptions = CloudflareWorkflowInstanceRestartOptions;
28
+ export type WorkflowInstanceTerminateOptions = CloudflareWorkflowInstanceTerminateOptions;
29
+ export type WorkflowInstanceLocationHint = CloudflareWorkflowInstanceLocationHint;
26
30
 
27
31
  export type WorkflowInstanceStatusName = CloudflareInstanceStatus["status"];
28
32
 
@@ -40,10 +44,13 @@ export interface WorkflowInstance<Result> {
40
44
  readonly id: string;
41
45
  readonly pause: Effect.Effect<void, WorkflowOperationError>;
42
46
  readonly resume: Effect.Effect<void, WorkflowOperationError>;
43
- readonly terminate: Effect.Effect<void, WorkflowOperationError>;
47
+ readonly terminate: (
48
+ options?: WorkflowInstanceTerminateOptions,
49
+ ) => Effect.Effect<void, WorkflowOperationError>;
44
50
  readonly restart: (
45
51
  options?: WorkflowInstanceRestartOptions,
46
52
  ) => Effect.Effect<void, WorkflowOperationError>;
53
+ readonly delete: Effect.Effect<void, WorkflowOperationError>;
47
54
  readonly status: Effect.Effect<
48
55
  WorkflowInstanceStatus<Result>,
49
56
  WorkflowOperationError | WorkflowResultDecodeError
@@ -165,8 +172,9 @@ export const makeClient = <
165
172
  id: raw.id,
166
173
  pause: operation("pause", () => raw.pause()),
167
174
  resume: operation("resume", () => raw.resume()),
168
- terminate: operation("terminate", () => raw.terminate()),
175
+ terminate: (options) => operation("terminate", () => raw.terminate(options)),
169
176
  restart: (options) => operation("restart", () => raw.restart(options)),
177
+ delete: operation("delete", () => raw.delete()),
170
178
  status: operation("status", () => raw.status()).pipe(
171
179
  Effect.flatMap((status) =>
172
180
  Effect.gen(function* () {
@@ -101,5 +101,6 @@ export const fromExecutionContext = (
101
101
  options?: Omit<WorkerContextWaitUntilOptions<E, R2>, "mode">,
102
102
  ) => schedule(effect, options, "propagate"),
103
103
  passThroughOnException: Effect.sync(() => ctx.passThroughOnException()),
104
+ abort: (reason?: string) => Effect.sync(() => ctx.abort(reason)),
104
105
  };
105
106
  };