Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .changeset/dependabot-update-8797.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"miniflare": patch
---

chore: update dependencies of "miniflare" package

The following dependency versions have been updated:

| Dependency | From | To |
| ------------------------- | ------------- | ------------- |
| workerd | 1.20250404.0 | 1.20250405.0 |
| @cloudflare/workers-types | ^4.20250404.0 | ^4.20250405.0 |
5 changes: 5 additions & 0 deletions .changeset/sweet-clocks-take.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cloudflare/workflows-shared": patch
---

Add `waitForEvent` and `sendEvent` support for local dev
2 changes: 1 addition & 1 deletion fixtures/additional-modules/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"devDependencies": {
"@cloudflare/workers-tsconfig": "workspace:*",
"@cloudflare/workers-types": "^4.20250404.0",
"@cloudflare/workers-types": "^4.20250405.0",
"typescript": "catalog:default",
"undici": "catalog:default",
"vitest": "catalog:default",
Expand Down
2 changes: 1 addition & 1 deletion fixtures/asset-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"devDependencies": {
"@cloudflare/vitest-pool-workers": "workspace:*",
"@cloudflare/workers-tsconfig": "workspace:*",
"@cloudflare/workers-types": "^4.20250404.0",
"@cloudflare/workers-types": "^4.20250405.0",
"run-script-os": "^1.1.6",
"typescript": "catalog:default",
"undici": "catalog:default",
Expand Down
2 changes: 1 addition & 1 deletion fixtures/d1-read-replication-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"devDependencies": {
"@cloudflare/workers-tsconfig": "workspace:*",
"@cloudflare/workers-types": "^4.20250404.0",
"@cloudflare/workers-types": "^4.20250405.0",
"typescript": "catalog:default",
"undici": "catalog:default",
"vitest": "catalog:default",
Expand Down
2 changes: 1 addition & 1 deletion fixtures/d1-worker-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"devDependencies": {
"@cloudflare/workers-tsconfig": "workspace:*",
"@cloudflare/workers-types": "^4.20250404.0",
"@cloudflare/workers-types": "^4.20250405.0",
"typescript": "catalog:default",
"undici": "catalog:default",
"vitest": "catalog:default",
Expand Down
2 changes: 1 addition & 1 deletion fixtures/get-platform-proxy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"devDependencies": {
"@cloudflare/workers-tsconfig": "workspace:*",
"@cloudflare/workers-types": "^4.20250404.0",
"@cloudflare/workers-types": "^4.20250405.0",
"typescript": "catalog:default",
"undici": "catalog:default",
"vitest": "catalog:default",
Expand Down
2 changes: 1 addition & 1 deletion fixtures/local-mode-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
"devDependencies": {
"@cloudflare/workers-tsconfig": "workspace:*",
"@cloudflare/workers-types": "^4.20250404.0",
"@cloudflare/workers-types": "^4.20250405.0",
"@types/node": "catalog:default",
"buffer": "^6.0.3",
"typescript": "catalog:default",
Expand Down
2 changes: 1 addition & 1 deletion fixtures/node-app-pages/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"devDependencies": {
"@cloudflare/workers-tsconfig": "workspace:*",
"@cloudflare/workers-types": "^4.20250404.0",
"@cloudflare/workers-types": "^4.20250405.0",
"typescript": "catalog:default",
"undici": "catalog:default",
"vitest": "catalog:default",
Expand Down
2 changes: 1 addition & 1 deletion fixtures/nodejs-als-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"devDependencies": {
"@cloudflare/workers-tsconfig": "workspace:*",
"@cloudflare/workers-types": "^4.20250404.0",
"@cloudflare/workers-types": "^4.20250405.0",
"undici": "catalog:default",
"vitest": "catalog:default",
"wrangler": "workspace:*"
Expand Down
2 changes: 1 addition & 1 deletion fixtures/nodejs-hybrid-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"devDependencies": {
"@cloudflare/workers-tsconfig": "workspace:*",
"@cloudflare/workers-types": "^4.20250404.0",
"@cloudflare/workers-types": "^4.20250405.0",
"@types/pg": "^8.11.2",
"pg": "8.11.3",
"pg-cloudflare": "^1.1.1",
Expand Down
2 changes: 1 addition & 1 deletion fixtures/pages-dev-proxy-with-script/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"devDependencies": {
"@cloudflare/workers-tsconfig": "workspace:*",
"@cloudflare/workers-types": "^4.20250404.0",
"@cloudflare/workers-types": "^4.20250405.0",
"typescript": "catalog:default",
"undici": "catalog:default",
"vitest": "catalog:default",
Expand Down
2 changes: 1 addition & 1 deletion fixtures/pages-functions-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"devDependencies": {
"@cloudflare/workers-tsconfig": "workspace:*",
"@cloudflare/workers-types": "^4.20250404.0",
"@cloudflare/workers-types": "^4.20250405.0",
"pages-plugin-example": "workspace:*",
"typescript": "catalog:default",
"undici": "catalog:default",
Expand Down
2 changes: 1 addition & 1 deletion fixtures/pages-functions-with-routes-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"devDependencies": {
"@cloudflare/workers-tsconfig": "workspace:*",
"@cloudflare/workers-types": "^4.20250404.0",
"@cloudflare/workers-types": "^4.20250405.0",
"typescript": "catalog:default",
"undici": "catalog:default",
"vitest": "catalog:default",
Expand Down
2 changes: 1 addition & 1 deletion fixtures/pages-plugin-mounted-on-root-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"devDependencies": {
"@cloudflare/workers-tsconfig": "workspace:*",
"@cloudflare/workers-types": "^4.20250404.0",
"@cloudflare/workers-types": "^4.20250405.0",
"pages-plugin-example": "workspace:*",
"typescript": "catalog:default",
"undici": "catalog:default",
Expand Down
2 changes: 1 addition & 1 deletion fixtures/pages-simple-assets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"devDependencies": {
"@cloudflare/workers-tsconfig": "workspace:*",
"@cloudflare/workers-types": "^4.20250404.0",
"@cloudflare/workers-types": "^4.20250405.0",
"typescript": "catalog:default",
"undici": "catalog:default",
"vitest": "catalog:default",
Expand Down
2 changes: 1 addition & 1 deletion fixtures/vitest-pool-workers-examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"devDependencies": {
"@cloudflare/vitest-pool-workers": "workspace:*",
"@cloudflare/workers-types": "^4.20250404.0",
"@cloudflare/workers-types": "^4.20250405.0",
"@microlabs/otel-cf-workers": "1.0.0-rc.45",
"@types/node": "catalog:default",
"discord-api-types": "0.37.98",
Expand Down
2 changes: 1 addition & 1 deletion fixtures/wildcard-modules/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"devDependencies": {
"@cloudflare/workers-tsconfig": "workspace:*",
"@cloudflare/workers-types": "^4.20250404.0",
"@cloudflare/workers-types": "^4.20250405.0",
"undici": "^5.28.4",
"wrangler": "workspace:*"
},
Expand Down
2 changes: 1 addition & 1 deletion fixtures/worker-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"start": "wrangler dev"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20250404.0",
"@cloudflare/workers-types": "^4.20250405.0",
"wrangler": "workspace:*"
},
"volta": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"devDependencies": {
"@cloudflare/workers-tsconfig": "workspace:*",
"@cloudflare/workers-types": "^4.20250404.0",
"@cloudflare/workers-types": "^4.20250405.0",
"typescript": "catalog:default",
"undici": "catalog:default",
"vitest": "catalog:default",
Expand Down
2 changes: 1 addition & 1 deletion fixtures/workers-with-assets-only/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"devDependencies": {
"@cloudflare/workers-tsconfig": "workspace:*",
"@cloudflare/workers-types": "^4.20250404.0",
"@cloudflare/workers-types": "^4.20250405.0",
"typescript": "catalog:default",
"undici": "catalog:default",
"vitest": "catalog:default",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"devDependencies": {
"@cloudflare/workers-tsconfig": "workspace:*",
"@cloudflare/workers-types": "^4.20250404.0",
"@cloudflare/workers-types": "^4.20250405.0",
"typescript": "catalog:default",
"undici": "catalog:default",
"vitest": "catalog:default",
Expand Down
2 changes: 1 addition & 1 deletion fixtures/workers-with-assets-spa/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"devDependencies": {
"@cloudflare/workers-tsconfig": "workspace:*",
"@cloudflare/workers-types": "^4.20250404.0",
"@cloudflare/workers-types": "^4.20250405.0",
"@types/jest-image-snapshot": "^6.4.0",
"@types/node": "catalog:default",
"jest-image-snapshot": "^6.4.0",
Expand Down
2 changes: 1 addition & 1 deletion fixtures/workers-with-assets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"devDependencies": {
"@cloudflare/workers-tsconfig": "workspace:*",
"@cloudflare/workers-types": "^4.20250404.0",
"@cloudflare/workers-types": "^4.20250405.0",
"typescript": "catalog:default",
"undici": "catalog:default",
"vitest": "catalog:default",
Expand Down
2 changes: 1 addition & 1 deletion fixtures/workflow-multiple/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"test:ci": "vitest run"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20250404.0",
"@cloudflare/workers-types": "^4.20250405.0",
"typescript": "catalog:default",
"undici": "catalog:default",
"vitest": "catalog:default",
Expand Down
3 changes: 2 additions & 1 deletion fixtures/workflow/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"test:ci": "vitest run"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20250404.0",
"@cloudflare/workers-tsconfig": "workspace:*",
"@cloudflare/workers-types": "^4.20250405.0",
"typescript": "catalog:default",
"undici": "catalog:default",
"vitest": "catalog:default",
Expand Down
43 changes: 43 additions & 0 deletions fixtures/workflow/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
WorkerEntrypoint,
WorkflowBackoff,
WorkflowEntrypoint,
WorkflowEvent,
WorkflowStep,
Expand Down Expand Up @@ -31,8 +32,33 @@ export class Demo extends WorkflowEntrypoint<{}, Params> {
}
}

export class Demo2 extends WorkflowEntrypoint<{}, Params> {
async run(event: WorkflowEvent<Params>, step: WorkflowStep) {
const { timestamp, payload } = event;

const result = await step.do("First step", async function () {
return {
output: "First step result",
};
});

await step.waitForEvent("event-1 provider", {
type: "event-1",
});

const result2 = await step.do("Second step", async function () {
return {
output: "Second step result",
};
});

return payload ?? "no-payload";
}
}

type Env = {
WORKFLOW: Workflow;
WORKFLOW2: Workflow;
};
export default class extends WorkerEntrypoint<Env> {
async fetch(req: Request) {
Expand All @@ -43,6 +69,7 @@ export default class extends WorkerEntrypoint<Env> {
return new Response(null, { status: 404 });
}

console.log(url.pathname);
let handle: WorkflowInstance;
if (url.pathname === "/createBatch") {
// creates two instances
Expand All @@ -57,6 +84,22 @@ export default class extends WorkerEntrypoint<Env> {
} else {
handle = await this.env.WORKFLOW.create({ id });
}
} else if (url.pathname === "/createDemo2") {
console.log("I'm here", id);
if (id === null) {
handle = await this.env.WORKFLOW2.create();
} else {
handle = await this.env.WORKFLOW2.create({ id });
}
} else if (url.pathname === "/sendEvent") {
handle = await this.env.WORKFLOW2.get(id);

await handle.sendEvent({
type: "event-1",
payload: await req.json(),
});
} else if (url.pathname === "/get2") {
handle = await this.env.WORKFLOW2.get(id);
} else {
handle = await this.env.WORKFLOW.get(id);
}
Expand Down
39 changes: 38 additions & 1 deletion fixtures/workflow/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ describe("Workflows", () => {
await stop?.();
});

async function fetchJson(url: string) {
async function fetchJson(url: string, body?: unknown, method?: string) {
const response = await fetch(url, {
headers: {
"MF-Disable-Pretty-Error": "1",
},
method: method ?? "GET",
body: body !== undefined ? JSON.stringify(body) : undefined,
});
const text = await response.text();

Expand Down Expand Up @@ -136,4 +138,39 @@ describe("Workflows", () => {
),
]);
});

test("waitForEvent should work", async ({ expect }) => {
await fetchJson(`http://${ip}:${port}/createDemo2?workflowName=something`);

await fetchJson(
`http://${ip}:${port}/sendEvent?workflowName=something`,
{ event: true },
"POST"
);

await vi.waitFor(
async () => {
await expect(
fetchJson(`http://${ip}:${port}/get2?workflowName=something`)
).resolves.toMatchInlineSnapshot(`
{
"__LOCAL_DEV_STEP_OUTPUTS": [
{
"output": "First step result",
},
{
"event": true,
},
{
"output": "Second step result",
},
],
"output": {},
"status": "complete",
}
`);
},
{ timeout: 5000 }
);
});
});
6 changes: 6 additions & 0 deletions fixtures/workflow/wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@ compatibility_date = "2024-10-22"
binding = "WORKFLOW"
name = "my-workflow"
class_name = "Demo"


[[workflows]]
binding = "WORKFLOW2"
name = "my-workflow2"
class_name = "Demo2"
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "^2.28.0",
"@changesets/parse": "^0.4.0",
"@cloudflare/workers-types": "^4.20250404.0",
"@cloudflare/workers-types": "^4.20250405.0",
"@ianvs/prettier-plugin-sort-imports": "4.2.1",
"@manypkg/cli": "^0.23.0",
"@types/node": "catalog:default",
Expand Down
2 changes: 1 addition & 1 deletion packages/create-cloudflare/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"@cloudflare/mock-npm-registry": "workspace:*",
"@cloudflare/vite-plugin": "workspace:*",
"@cloudflare/workers-tsconfig": "workspace:*",
"@cloudflare/workers-types": "^4.20250404.0",
"@cloudflare/workers-types": "^4.20250405.0",
"@iarna/toml": "^3.0.0",
"@types/command-exists": "^1.2.0",
"@types/cross-spawn": "^6.0.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/edge-preview-authenticated-proxy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"devDependencies": {
"@cloudflare/eslint-config-worker": "workspace:*",
"@cloudflare/workers-types": "^4.20250404.0",
"@cloudflare/workers-types": "^4.20250405.0",
"@types/cookie": "^0.6.0",
"cookie": "^0.7.2",
"promjs": "^0.4.2",
Expand Down
Loading
Loading