Skip to content

Conversation

PonomareVlad
Copy link

@PonomareVlad PonomareVlad commented May 22, 2025

new Queue(driver, name, {
    decodePayload: payload => payload,
    encodePayload: payload => payload,
})
Demo (before/after)

Снимок экрана 2025-05-22 в 23 06 29

Copy link
Owner

@thecodedrift thecodedrift left a comment

Choose a reason for hiding this comment

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

I'm all for this change. Do you mind adding a little bit of context for the bug or use case this PR addresses? It'll help other people if they had this issue also find the fix and what version they'll be needing.

static decodePayload<T>(s: string | null) {
return JSON.parse(s ?? "{}")._ as T;
static decodePayload<T>(s: string | null | unknown) {
return JSON.parse((s as string) ?? "{}")._ as T;
Copy link
Owner

Choose a reason for hiding this comment

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

This will probably need a try catch around it now, since non-strings really mess up the JSON.parse (it probably always needed one, but the addition of an unknown makes it way more likely to trigger this footgun)

Copy link
Owner

Choose a reason for hiding this comment

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

Can you catch & rethrow a useful error here? This way the default encoders set a good example

@PonomareVlad
Copy link
Author

PonomareVlad commented May 22, 2025

I'm all for this change. Do you mind adding a little bit of context for the bug or use case this PR addresses? It'll help other people if they had this issue also find the fix and what version they'll be needing.

Thank you for your feedback, I just want to offer a way to conveniently data serialization, which can be useful for MongoDB users (the ability to find a job by its payload)

new Queue(driver, name, {
    decodePayload: payload => payload,
    encodePayload: payload => payload,
})
Demo (before/after)

Снимок экрана 2025-05-22 в 23 06 29

@PonomareVlad
Copy link
Author

PonomareVlad commented May 22, 2025

@PonomareVlad PonomareVlad marked this pull request as ready for review May 22, 2025 23:25
@thecodedrift
Copy link
Owner

I think the approach you have here w/ instance based encode/decode is the correct way to do this. The tests are failing, but that is likely a "me" problem, because we haven't had to update the tooling and cut a release in a while.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants