Skip to content

Commit 98e1a45

Browse files
committed
fix(core): queue reads from servers predating the version field parse as V1
A response without the discriminator has V1 semantics by definition, so the schema defaults it instead of failing the parse against an older server.
1 parent f493d0a commit 98e1a45

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

‎packages/core/src/v3/schemas/queues.ts‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,11 @@ const QueueItemCommon = {
4242
* concurrency limit (applied per key when runs pass a `concurrencyKey`, to the
4343
* whole queue when they don't) and its override state. V2 queues are only the
4444
* line runs wait in: concurrency is declared with the task `concurrency`
45-
* option and read or overridden through `concurrencyLimits`.
45+
* option and read or overridden through `concurrencyLimits`. A response from a
46+
* server that predates the discriminator has V1 semantics by definition, so a
47+
* missing `version` defaults to "V1" rather than failing the parse.
4648
*/
47-
export const QueueItem = z.discriminatedUnion("version", [
49+
const QueueItemUnion = z.discriminatedUnion("version", [
4850
z.object({
4951
...QueueItemCommon,
5052
version: z.literal("V1"),
@@ -70,7 +72,15 @@ export const QueueItem = z.discriminatedUnion("version", [
7072
}),
7173
]);
7274

73-
export type QueueItem = z.infer<typeof QueueItem>;
75+
export const QueueItem = z.preprocess(
76+
(value) =>
77+
value && typeof value === "object" && !("version" in value)
78+
? { ...value, version: "V1" }
79+
: value,
80+
QueueItemUnion
81+
);
82+
83+
export type QueueItem = z.infer<typeof QueueItemUnion>;
7484

7585
export const ListQueueOptions = z.object({
7686
/** The page number */

0 commit comments

Comments
 (0)