Skip to content
Open
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
7 changes: 7 additions & 0 deletions .changeset/chilly-spiders-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"partywhen": patch
---

fix: require task payload to be seralizable over RPC

fixes #190
2 changes: 1 addition & 1 deletion packages/partywhen/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Server } from "partyserver";
export type RawTask = {
id: string;
description?: string | undefined;
payload?: Record<string, unknown> | undefined;
payload?: Record<string, Rpc.Serializable<unknown>> | undefined;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need Record here? Maybe this should just be Rpc.Serializable<unknown> ?

callback?: Callback | undefined;
} & (
| {
Expand Down
21 changes: 9 additions & 12 deletions packages/partywhen/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import { describe, expect, it } from "vitest";

import worker from ".";

type IsNever<T> = [T] extends [never] ? true : false;
type AssertNot<T extends false> = T;

function getStub(environment: typeof env) {
const id = environment.SCHEDULER.idFromName("example");
return environment.SCHEDULER.get(id);
Expand Down Expand Up @@ -46,6 +49,9 @@ describe("Hello World worker", () => {
time
});

// this will get a type error if scheduleTask returns `never`
type _ = AssertNot<IsNever<typeof task>>;

expect(task).toMatchInlineSnapshot(`
{
"callback": {
Expand Down Expand Up @@ -123,9 +129,8 @@ describe("Hello World worker", () => {
"test": "test",
},
"time": ${
// @ts-expect-error I'm bad at typescript
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
taskTime.toISOString()
await taskTime.toISOString()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed some type issues while I was here

},
"type": "delayed",
}
Expand Down Expand Up @@ -242,11 +247,7 @@ describe("Hello World worker", () => {
"payload": {
"test": "test",
},
"time": ${
// @ts-expect-error I'm bad at typescript
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
time.toISOString()
},
"time": ${await time.toISOString()},
"type": "no-schedule",
}
`);
Expand All @@ -268,11 +269,7 @@ describe("Hello World worker", () => {
"description": "test",
"id": "no-schedule-task-001",
"payload": "{"test":"test"}",
"time": ${Math.floor(
// @ts-expect-error I'm bad at typescript
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
time.getTime() / 1000
)},
"time": ${Math.floor((await time.getTime()) / 1000)},
"type": "no-schedule",
}
`);
Expand Down