{"id":51053540,"url":"https://github.com/eersnington/cf-forklift","last_synced_at":"2026-06-22T19:04:05.470Z","repository":{"id":362816349,"uuid":"1260915487","full_name":"eersnington/cf-forklift","owner":"eersnington","description":"Structured parallelism for Cloudflare Workflows","archived":false,"fork":false,"pushed_at":"2026-06-06T02:52:54.000Z","size":33,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-06T04:21:42.621Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eersnington.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-06-06T02:50:15.000Z","updated_at":"2026-06-06T02:52:57.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/eersnington/cf-forklift","commit_stats":null,"previous_names":["eersnington/cf-forklift"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/eersnington/cf-forklift","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eersnington%2Fcf-forklift","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eersnington%2Fcf-forklift/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eersnington%2Fcf-forklift/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eersnington%2Fcf-forklift/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eersnington","download_url":"https://codeload.github.com/eersnington/cf-forklift/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eersnington%2Fcf-forklift/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34661710,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-22T02:00:06.391Z","response_time":106,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-06-22T19:04:05.389Z","updated_at":"2026-06-22T19:04:05.454Z","avatar_url":"https://github.com/eersnington.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# cf-forklift\n\nNetflix Conductor-style structured fork/join parallelism helpers for [Cloudflare Workflows](https://developers.cloudflare.com/workflows/).\n\n## Installation\n\n```bash\nnpm install cf-forklift\npnpm add cf-forklift\nbun add cf-forklift\n```\n\n## Usage\n\n```ts\nimport { withWorkflow } from \"cf-forklift\";\nimport {\n\tWorkflowEntrypoint,\n\ttype WorkflowEvent,\n\ttype WorkflowStep,\n} from \"cloudflare:workers\";\n\nexport class MerchantWorkflow extends WorkflowEntrypoint\u003c\n\tEnv,\n\t{ merchantId: string }\n\u003e {\n\tasync run(event: WorkflowEvent\u003c{ merchantId: string }\u003e, step: WorkflowStep) {\n\t\tconst workflow = withWorkflow(step);\n\n\t\tconst merchantId = event.payload.merchantId;\n\n\t\tconst verifyMerchant = workflow.fork(\"verify merchant\", {\n\t\t\tprofile: ({ step }) =\u003e\n\t\t\t\tstep.do(\"verify profile\", () =\u003e verifyProfile(merchantId)),\n\n\t\t\tbank: ({ step }) =\u003e\n\t\t\t\tstep.do(\"verify bank\", () =\u003e verifyBank(merchantId)),\n\n\t\t\trisk: ({ step }) =\u003e\n\t\t\t\tstep.do(\"screen risk\", () =\u003e screenRisk(merchantId)),\n\t\t});\n\n\t\tconst verification = await workflow.join.required(verifyMerchant);\n\n\t\tconst enrichMerchant = workflow.fork(\"enrich merchant\", {\n\t\t\twebsite: ({ step }) =\u003e\n\t\t\t\tstep.do(\"check website reputation\", () =\u003e checkWebsite(merchantId)),\n\n\t\t\tmarketplace: ({ step }) =\u003e\n\t\t\t\tstep.do(\"check marketplace footprint\", () =\u003e\n\t\t\t\t\tcheckMarketplace(merchantId)\n\t\t\t\t),\n\n\t\t\tsupport: ({ step }) =\u003e\n\t\t\t\tstep.do(\"check support profile\", () =\u003e\n\t\t\t\t\tcheckSupportProfile(merchantId)\n\t\t\t\t),\n\t\t});\n\n\t\tconst enrichment = await workflow.join.settled(enrichMerchant);\n\n\t\treturn {\n\t\t\tmerchantId,\n\t\t\tverification,\n\t\t\tenrichment,\n\t\t};\n\t}\n}\n```\n\n## API\n\n```ts\nconst workflow = withWorkflow(step, options?);\n```\n\nwithWorkflow Options\n```ts\ntype Options = {\n\tstepNameSeparator?: string;\n\tmarkers?: \"off\" | \"minimal\" | \"summary\";\n};\n```\n\n### Fork\n\nForks describe named branch work. They are lazy: branch functions do not start until the fork is passed to a join method.\n\n```ts\nconst fork = workflow.fork(\"verify merchant\", {\n\tprofile: ({ step }) =\u003e step.do(\"verify profile\", verifyProfile),\n\tbank: ({ step }) =\u003e step.do(\"verify bank\", verifyBank),\n});\n```\n\nBranch names become result keys and Cloudflare step-name path segments:\n\n```txt\nverify merchant / profile / verify profile\nverify merchant / bank / verify bank\n```\n\nBranch names must be unique within a fork.\n\nDynamic forks are for branches that come from runtime data. Here each account ID\nfrom the Workflow event becomes one branch:\n\n```ts\ntype ReportSummary = {\n\treportId: string;\n};\n\nconst accountIds = event.payload.accountIds;\nconst reports = workflow.fork\u003cReportSummary\u003e(\"generate reports\");\n\nfor (const accountId of accountIds) {\n\treports.branch(accountId, ({ step }) =\u003e\n\t\tstep.do(`generate report for ${accountId}`, () =\u003e\n\t\t\tgenerateReport(accountId)\n\t\t)\n\t);\n}\n\nconst outcomes = await workflow.join.settled(reports);\n\nfor (const accountId of accountIds) {\n\tconst outcome = outcomes[accountId];\n}\n```\n\nStatic branch records preserve exact result keys. Runtime string branch names return partial keyed records, so `outcomes.bank` is not guaranteed to exist unless `bank` was a static branch key.\n\n### Join\n\n`required` is for all-or-nothing branch work. It starts every branch, waits for every branch to settle, and returns keyed values only if every branch succeeds.\n\n```ts\nconst verification = await workflow.join.required(fork);\n```\n\nIf any branch fails or aborts, `required` throws `ForkJoinError` after draining all branch outcomes.\n\nUse cooperative abort when later sibling work should stop at checkpoints after the first branch failure:\n\n```ts\nawait workflow.join.required(fork, {\n\tabortOnFailure: \"cooperative\",\n});\n```\n\n`settled` is for best-effort branch work. It starts every branch, waits for every branch to settle, and returns keyed outcomes without throwing for branch failures.\n\n```ts\nconst outcomes = await workflow.join.settled(fork);\n\nif (outcomes.website.status === \"failure\") {\n\t// Continue with partial enrichment.\n}\n```\n\n## Supports Native Rollbacks\n\n```ts\nconst provision = workflow.fork(\"provision resources\", {\n\tresource: ({ step }) =\u003e\n\t\tstep.do(\n\t\t\t\"provision resource\",\n\t\t\tasync () =\u003e {\n\t\t\t\tconst resource = await provisionResource();\n\t\t\t\treturn { resourceId: resource.id };\n\t\t\t},\n\t\t\t{\n\t\t\t\trollback: async ({ output }) =\u003e {\n\t\t\t\t\tconst { resourceId } = output as { resourceId: string };\n\t\t\t\t\tawait deleteResource(resourceId);\n\t\t\t\t},\n\t\t\t\trollbackConfig: {\n\t\t\t\t\tretries: { limit: 3, delay: \"15 seconds\", backoff: \"linear\" },\n\t\t\t\t\ttimeout: \"2 minutes\",\n\t\t\t\t},\n\t\t\t}\n\t\t),\n});\n\nawait workflow.join.required(provision);\n```\n\nRegister native Cloudflare rollback handlers on branch `step.do` calls that complete side effects. Rollbacks compensate completed work if the Workflow later fails. Cooperative abort does not undo completed work.\n\n## Cooperative Abort\n\nRequired joins drain by default. If you want sibling branches to skip future work after one branch fails, opt into cooperative abort:\n\n```ts\nconst verifyMerchant = workflow.fork(\"verify merchant\", {\n\tbank: ({ step }) =\u003e\n\t\tstep.do(\"verify bank\", async () =\u003e {\n\t\t\tthrow new Error(\"bank failed\");\n\t\t}),\n\n\trisk: async ({ step, cancellation }) =\u003e {\n\t\tcancellation.throwIfRequested();\n\n\t\tawait step.do(\"risk check 1\", async () =\u003e \"ok\");\n\n\t\tcancellation.throwIfRequested();\n\n\t\treturn step.do(\n\t\t\t\"risk check 2\",\n\t\t\tasync () =\u003e createRiskDecision(),\n\t\t\t{\n\t\t\t\t// Register rollback for side effects that may have completed before the fork fails.\n\t\t\t\trollback: async ({ output }) =\u003e deleteRiskDecision(output),\n\t\t\t}\n\t\t);\n\t},\n});\n\nawait workflow.join.required(verifyMerchant, {\n\tabortOnFailure: \"cooperative\",\n});\n```\n\nCooperative abort is a branch checkpoint mechanism. It is useful when later branch work should be skipped after another branch has already failed.\n\nIt does not change Cloudflare runtime behavior:\n\n- Already-started `step.do`, `sleep`, `sleepUntil`, and `waitForEvent` calls still finish normally.\n- Branches only stop when they reach `cancellation.throwIfRequested()` or start a scoped Workflow primitive after abort was requested.\n- The required join still waits for every branch to settle before throwing `ForkJoinError`.\n- Use native rollback handlers for side effects that may complete before the fork fails.\n\n## How It Works\n\ncf-forklift wraps WorkflowStep and prefixes branch step names.\n\n```\nverify merchant / profile / verify profile\nverify merchant / bank / verify bank\nverify merchant / risk / screen risk\n```\n\nBranch names are part of the Cloudflare step name so different branches can safely use the same local step name.\n\n## Markers\n\nSummary markers are enabled by default. They add real Workflow steps around a fork/join:\n\n```\nverify merchant / fork\nverify merchant / profile / verify profile\nverify merchant / bank / verify bank\nverify merchant / join\n```\n\nThe fork marker returns:\n\n```ts\n{\n\ttype: \"fork\",\n\tname: \"verify merchant\",\n\tbranches: [\"profile\", \"bank\"],\n\tpolicy: \"required\",\n\tabortOnFailure: \"none\",\n}\n```\n\nThe join marker returns:\n\n```ts\n{\n\ttype: \"join\",\n\tname: \"verify merchant\",\n\tpolicy: \"required\",\n\tabortOnFailure: \"none\",\n\tstatus: \"success\",\n\tbranches: {\n\t\tprofile: \"success\",\n\t\tbank: \"success\",\n\t},\n}\n```\n\nUse `markers: \"minimal\"` for breadcrumb-only marker steps, or `markers: \"off\"` to disable marker steps.\n\nCloudflare still records primitive Workflow steps. cf-forklift adds structured naming, keyed outputs, and join policies in userland.\n\n## Behavior Guarantees\n\n- Forks are lazy; branches do not start until a join method is called.\n- `join.required(fork)` starts every branch, waits for every branch to settle, and throws `ForkJoinError` if any branch does not succeed.\n- `join.required(fork, { abortOnFailure: \"cooperative\" })` requests cooperative abort after the first branch failure and still drains all branches.\n- `join.settled(fork)` returns keyed `success`, `failure`, or `aborted` outcomes.\n- Marker steps are enabled by default with `markers: \"summary\"`; use `\"minimal\"` or `\"off\"` to reduce Workflow history entries.\n- Branch names must be unique within a fork because they become output keys.\n- Branch names and step names should be deterministic because they become Cloudflare step names.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feersnington%2Fcf-forklift","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feersnington%2Fcf-forklift","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feersnington%2Fcf-forklift/lists"}