Closed gwax closed 4 months ago
Latest commit: 90fef99c8342e117f337371a076343a5ea0871b2
The changes in this PR will be included in the next version bump.
Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR
The changes to src/lib/sveltekit-search-params.ts
significantly enhance the encoding and decoding capabilities of the ssp
object by introducing dedicated functions for different data types. This restructuring improves code clarity, modularity, and type safety, while also ensuring that users receive non-null values when default parameters are provided, addressing previous issues with nullable values.
File | Change Summary |
---|---|
src/lib/sveltekit-search-params.ts |
Restructured ssp object to use dedicated encoding/decoding functions, enhancing modularity and type safety. Updated queryParam function with new overloads for greater flexibility. |
.github/workflows/release.yml |
Upgraded pnpm/action-setup from v2 to v4 and pnpm version from 8 to 9 for improved workflow reliability. |
.github/workflows/run-tests.yml |
Updated indentation style and upgraded Node.js version from 18 to 20, along with pnpm/action-setup from v2 to v4. |
Objective | Addressed | Explanation |
---|---|---|
Value is nullable if default value is provided (#75) | β |
In fields so bright, we hop and play,
With new code changes here today!
Encodingβs clear, no more a mess,
Our queries now, they truly bless!
So letβs rejoice, with joy we bound,
For better code, weβve surely found! πβ¨
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?
Name | Link |
---|---|
Latest commit | 90fef99c8342e117f337371a076343a5ea0871b2 |
Latest deploy log | https://app.netlify.com/sites/sveltekit-search-params/deploys/66a64c663ed7c300081e0dde |
Deploy Preview | https://deploy-preview-87--sveltekit-search-params.netlify.app |
Preview on mobile | Toggle QR Code...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify site configuration.
Uh this is nice. I tried to do something like this for a long time and failed to do so. I will try to take a look today or tomorrow or else I will get to it on Monday, thanks for contributing
Yeah, getting types right is a challenge. I wasn't feeling up to figuring out how to make queryParameters
work right. I think this implementation is pretty straightforward, though it's pretty verbose to get ssp
to work right π€· .
It's a great library and it'll be nice to avoid casting my Writable<string | null>
to Writable<string>
.
Please let me know if there's anything that I can do or clarify to help with your review process.
Hey @gwax great work...i pushed a small fix for queryParam
that was defaulting to unknown when no encode and decode options was passed.
There's a typing problem with queryParameters
tho that i've yet to figure out how to solve so i'm pushing the fix to queryParam
in the meantime. If you have any idea how to fix this please go ahead.
const store: Writable<LooseAutocomplete<{
str: unknown;
num: number;
bools: boolean;
obj: {
str: string;
};
arr: number[];
lz: string;
}>>
this is the type that i'm getting back in ./playground/src/routes/queryparameters/+page.svelte
where the store is defined like so:
const store = queryParameters({
str: true,
num: ssp.number(),
bools: ssp.boolean(),
obj: ssp.object<{ str: string }>(),
arr: ssp.array<number>(),
lz: ssp.lz<string>(),
});
in theory the expected type for this should be
const store: Writable<LooseAutocomplete<{
str: string | null;
num: number | null;
bools: boolean | null;
obj: {
str: string;
} | null;
arr: number[] | null;
lz: string | null;
}>>
and obviously passing an option with a default should also work there. I'll try to see if i can figure ths out
Oh i'm actually an idiot: this was already like this in older versions...so no fault from you here sorry.
Let me see if i can make something work.
@gwax i actually did it (the types for queryParameters
were much simpler than what you did and it seems to work fine. Just need to check if this change in types is not a breaking change and then i'll merge and publish a new release. Thanks a lot!
This change modifies the return type of queryParam to be Writable instead of Writable<T | null> if options is included and specifies a defaultValue.
We additionally modify the various ssp helper functions to return Writable instead of Writable<T | null> when a default value is provided.
Fixes #75
Summary by CodeRabbit
New Features
queryParam
function with new overloads for more flexible usage.Improvements
defaultValue
is provided, enhancing module reliability.