Skip to content

Commit e75589b

Browse files
committed
fix: require task payload to be seralizable over RPC
fixes #190
1 parent c13b1ee commit e75589b

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

packages/partywhen/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Server } from "partyserver";
44
export type RawTask = {
55
id: string;
66
description?: string | undefined;
7-
payload?: Record<string, unknown> | undefined;
7+
payload?: Record<string, Rpc.Serializable<unknown>> | undefined;
88
callback?: Callback | undefined;
99
} & (
1010
| {

packages/partywhen/tests/index.test.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import { describe, expect, it } from "vitest";
88

99
import worker from ".";
1010

11+
type IsNever<T> = [T] extends [never] ? true : false;
12+
type AssertNot<T extends false> = T;
13+
1114
function getStub(environment: typeof env) {
1215
const id = environment.SCHEDULER.idFromName("example");
1316
return environment.SCHEDULER.get(id);
@@ -46,6 +49,9 @@ describe("Hello World worker", () => {
4649
time
4750
});
4851

52+
// this will get a type error if scheduleTask returns `never`
53+
type _ = AssertNot<IsNever<typeof task>>;
54+
4955
expect(task).toMatchInlineSnapshot(`
5056
{
5157
"callback": {
@@ -123,9 +129,8 @@ describe("Hello World worker", () => {
123129
"test": "test",
124130
},
125131
"time": ${
126-
// @ts-expect-error I'm bad at typescript
127132
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
128-
taskTime.toISOString()
133+
await taskTime.toISOString()
129134
},
130135
"type": "delayed",
131136
}
@@ -242,11 +247,7 @@ describe("Hello World worker", () => {
242247
"payload": {
243248
"test": "test",
244249
},
245-
"time": ${
246-
// @ts-expect-error I'm bad at typescript
247-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
248-
time.toISOString()
249-
},
250+
"time": ${await time.toISOString()},
250251
"type": "no-schedule",
251252
}
252253
`);
@@ -268,11 +269,7 @@ describe("Hello World worker", () => {
268269
"description": "test",
269270
"id": "no-schedule-task-001",
270271
"payload": "{"test":"test"}",
271-
"time": ${Math.floor(
272-
// @ts-expect-error I'm bad at typescript
273-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
274-
time.getTime() / 1000
275-
)},
272+
"time": ${Math.floor((await time.getTime()) / 1000)},
276273
"type": "no-schedule",
277274
}
278275
`);

0 commit comments

Comments
 (0)