deserialize string-store snowflake to string

Hey! I just started using @sapphire/string-store, and it seems to make the most sense to store all discord IDs as snowflakes, as they take less space in the custom ID than the string (im pretty sure, right?), however, this means i now need to call .toString() on all the stored snowflakes to use them with the rest of my code (or refactor everything to use bigints instead) Is there some way to have .deserialize automatically turn bigints into strings? or is that functionality that would be worth adding?
14 Replies
SirH
SirH2mo ago
that sounds like it could be a nice-to-have for the library, but as of right now, the library is in a bit of a limbo as it will basically not work properly and my rewrite of it has been paused until whenever. so I'd recommend to not use it right now, unfortunately.
Sammy
SammyOP2mo ago
Ouuh really? whats wrong with it currently? seemed to work pretty well in the lil test i did
SirH
SirH2mo ago
it'll work a bit, but- you'll likely hit the issue eventually depending on what you're going for. I can't confirm exactly the full scope what will 100% not work other than the serializer makes the wrong assumption about how the data needs to serialized and create invalid UTF-8 characters that the API doesn't like.
Sammy
SammyOP2mo ago
ahhh i see, yeah i havent actually tested it with the api yet haha thats unfortunate, guess ill hold off for now :p
SirH
SirH2mo ago
sorry for the inconvenience, when it's resolved, there'll be an announcement about it
Sammy
SammyOP5w ago
No problem at all :) no need to apologize Oh btw, ill drop another small suggestion then if theres a rewrite coming sometime, i saw theres quite a few exported utility types already, but i think something like DataForCustomId would be nice to have, i ended up putting it together myself, but might be useful for others too:
import type { SchemaStore, UnwrapSchema } from "@sapphire/string-store";

export enum CustomIds {
Something,
}

export const store= new SchemaStore()

export type DataForCustomId<T extends CustomIds, Store> = Store extends SchemaStore<infer Schemas>
? T extends keyof Schemas
? UnwrapSchema<Schemas[T] & object>
: never
: never;

type Button<Id extends CustomIds> = {
custom_id: Id,
execute: (interaction: ..., data: DataForCustomId<Id, typeof store>) => ...
}
import type { SchemaStore, UnwrapSchema } from "@sapphire/string-store";

export enum CustomIds {
Something,
}

export const store= new SchemaStore()

export type DataForCustomId<T extends CustomIds, Store> = Store extends SchemaStore<infer Schemas>
? T extends keyof Schemas
? UnwrapSchema<Schemas[T] & object>
: never
: never;

type Button<Id extends CustomIds> = {
custom_id: Id,
execute: (interaction: ..., data: DataForCustomId<Id, typeof store>) => ...
}
Lets me define a button with a generic type and automatically have the deserialized data typed in my button, which is called from somewhere else No idea if its actually useful for anyone else, but who knows :) any help you'd need with this btw? Id be interested if possible :)
SirH
SirH5w ago
I'm rewriting it with the serialization/deserialization being done in Rust, so there's that, plus I'd like to use this as a learning journey for me, which is why there's a delay, because I had to take a pause to focus on some studies as I was having a bit of a block with what I was trying to do.
Sammy
SammyOP5w ago
ohh nice nice, like with node bindings?
SirH
SirH5w ago
yes
Sammy
SammyOP5w ago
interesting wouldnt that be annoying with having to build dependencies? or is it easy enough to just add prebuilt binaries?
SirH
SirH5w ago
wdym, are you asking if the user has to build it?
Sammy
SammyOP5w ago
yea like on the node side, i remember having issues with some packages that needed node gyp builds in the past
SirH
SirH5w ago
it'll be a prebuilt binary
Sammy
SammyOP5w ago
ahh nice also sounds like a fun learning journey :) ill wait till the announcement @SirH do you mind actually if i make a pr for a temporary fix in js? until youre done with a rust rewrite :) wait ill take this to #utilities-development , seems more appropriate

Did you find this page helpful?