cfw-utils 0.0.1 → 0.0.2

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 CHANGED
@@ -1,8 +1,11 @@
1
- # Cloudflare Workers Utilities
1
+ # cfw-utils
2
2
 
3
- A set of utility functions for Cloudflare Workers.
3
+ [![npm version](https://img.shields.io/npm/v/cfw-utils.svg)](https://www.npmjs.com/package/cfw-utils)
4
+ [![license](https://img.shields.io/npm/l/cfw-utils.svg)](https://github.com/h4ckedneko/cfw-utils/blob/main/LICENSE)
4
5
 
5
- ## Installation
6
+ A set of utility functions for working with Cloudflare Workers platform.
7
+
8
+ ## Install
6
9
 
7
10
  ```bash
8
11
  npm install cfw-utils
@@ -20,17 +23,19 @@ Alternatively, you can also just copy and paste the utilities in [src/utils](src
20
23
 
21
24
  ## Usage
22
25
 
23
- ### configureStep()
26
+ ### Workflows Utilities
27
+
28
+ #### `configureStep` and `runStep`
24
29
 
25
- A reusable step runner for Cloudflare Workflows. Simplifies running workflow steps with shared default configuration and centralized error handling.
30
+ Simplifies running workflow steps with shared default configuration and centralized error handling.
26
31
 
27
- #### Features
32
+ ##### Features
28
33
 
29
- - **Default config** - Apply consistent timeout, retries, or other settings across all steps
30
- - **Error handling** - Automatically execute cleanup logic when any step fails
34
+ - **Default Config** - Apply your timeout and retries config across all steps (can be overridden per step)
35
+ - **Error Handling** - Automatically execute cleanup logic when any step fails
31
36
  - **Familiar API** - Mirrors Cloudflare's `step.do` signature
32
37
 
33
- #### Example
38
+ ##### Example
34
39
 
35
40
  ```typescript
36
41
  export class Workflow extends WorkflowEntrypoint<Env, Params> {
@@ -45,7 +50,7 @@ export class Workflow extends WorkflowEntrypoint<Env, Params> {
45
50
  },
46
51
  timeout: "5 minutes",
47
52
  },
48
- // Cleanup logic executed when any step fails.
53
+ // Cleanup logic invoked when any step fails.
49
54
  onError: async (error) => {
50
55
  await setAsFailed();
51
56
  console.error(error);
package/dist/index.cjs CHANGED
@@ -26,14 +26,15 @@ function configureStep(step, options = {}) {
26
26
  async function runStep(name, configOrCallback, maybeCallback) {
27
27
  const config = typeof configOrCallback === "function" ? {} : configOrCallback;
28
28
  const callback = typeof configOrCallback === "function" ? configOrCallback : maybeCallback;
29
+ const { defaultConfig, onError } = options;
29
30
  const run = () => step.do(name, {
30
- ...options.defaultConfig,
31
+ ...defaultConfig,
31
32
  ...config
32
33
  }, callback);
33
- if (options.onError) try {
34
+ if (onError) try {
34
35
  return await run();
35
36
  } catch (error) {
36
- await step.do(`handle error for: ${name}`, () => options.onError(error));
37
+ await step.do(`handle error for: ${name}`, () => onError(error));
37
38
  }
38
39
  return await run();
39
40
  }
package/dist/index.d.cts CHANGED
@@ -2,7 +2,7 @@ import { WorkflowStep, WorkflowStepConfig, WorkflowStepContext } from "cloudflar
2
2
 
3
3
  //#region src/utils/workflow.d.ts
4
4
  type ConfigureStepOptions = {
5
- defaultConfig?: WorkflowStepConfig;
5
+ /** Default config applied to all steps, can be overridden per step. */defaultConfig?: WorkflowStepConfig; /** Cleanup callback invoked when any step fails. This runs inside a step. */
6
6
  onError?: (error: unknown) => Promise<void>;
7
7
  };
8
8
  /**
package/dist/index.d.mts CHANGED
@@ -2,7 +2,7 @@ import { WorkflowStep, WorkflowStepConfig, WorkflowStepContext } from "cloudflar
2
2
 
3
3
  //#region src/utils/workflow.d.ts
4
4
  type ConfigureStepOptions = {
5
- defaultConfig?: WorkflowStepConfig;
5
+ /** Default config applied to all steps, can be overridden per step. */defaultConfig?: WorkflowStepConfig; /** Cleanup callback invoked when any step fails. This runs inside a step. */
6
6
  onError?: (error: unknown) => Promise<void>;
7
7
  };
8
8
  /**
package/dist/index.mjs CHANGED
@@ -25,14 +25,15 @@ function configureStep(step, options = {}) {
25
25
  async function runStep(name, configOrCallback, maybeCallback) {
26
26
  const config = typeof configOrCallback === "function" ? {} : configOrCallback;
27
27
  const callback = typeof configOrCallback === "function" ? configOrCallback : maybeCallback;
28
+ const { defaultConfig, onError } = options;
28
29
  const run = () => step.do(name, {
29
- ...options.defaultConfig,
30
+ ...defaultConfig,
30
31
  ...config
31
32
  }, callback);
32
- if (options.onError) try {
33
+ if (onError) try {
33
34
  return await run();
34
35
  } catch (error) {
35
- await step.do(`handle error for: ${name}`, () => options.onError(error));
36
+ await step.do(`handle error for: ${name}`, () => onError(error));
36
37
  }
37
38
  return await run();
38
39
  }
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "cfw-utils",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "A set of utility functions for Cloudflare Workers.",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
8
- "url": "git+https://github.com/h4ckedneko/cfwutils.git"
8
+ "url": "git+https://github.com/h4ckedneko/cfw-utils.git"
9
9
  },
10
10
  "type": "module",
11
11
  "main": "./dist/index.cjs",