diff --git a/.changeset/chilly-spiders-prove.md b/.changeset/chilly-spiders-prove.md new file mode 100644 index 00000000..7f5f89df --- /dev/null +++ b/.changeset/chilly-spiders-prove.md @@ -0,0 +1,7 @@ +--- +"partywhen": patch +--- + +fix: require task payload to be seralizable over RPC + +fixes #190 diff --git a/packages/partywhen/src/index.ts b/packages/partywhen/src/index.ts index cf47a8b0..ba9e2945 100644 --- a/packages/partywhen/src/index.ts +++ b/packages/partywhen/src/index.ts @@ -4,7 +4,7 @@ import { Server } from "partyserver"; export type RawTask = { id: string; description?: string | undefined; - payload?: Record | undefined; + payload?: Record> | undefined; callback?: Callback | undefined; } & ( | { diff --git a/packages/partywhen/tests/index.test.ts b/packages/partywhen/tests/index.test.ts index ec5ced4e..1a685b9a 100644 --- a/packages/partywhen/tests/index.test.ts +++ b/packages/partywhen/tests/index.test.ts @@ -8,6 +8,9 @@ import { describe, expect, it } from "vitest"; import worker from "."; +type IsNever = [T] extends [never] ? true : false; +type AssertNot = T; + function getStub(environment: typeof env) { const id = environment.SCHEDULER.idFromName("example"); return environment.SCHEDULER.get(id); @@ -46,6 +49,9 @@ describe("Hello World worker", () => { time }); + // this will get a type error if scheduleTask returns `never` + type _ = AssertNot>; + expect(task).toMatchInlineSnapshot(` { "callback": { @@ -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() }, "type": "delayed", } @@ -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", } `); @@ -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", } `);