Serializing string-store result inside another schema

I'm trying to re-work customId serialization in my framework, and my plan is to use string-store for this. One of the features in my framework is that you can make customIds that refer to commands, kind of like this:
class MyCommand extends Command {
public async execute(i: ChatInputInteraction, meta: Metadata) {
const bot = meta.getBot();
const customId = bot.getCommandManager().getCustomIdSerializer().serialize(this);
// reply with button or something that uses the customId
}

public executeComponent(i: ComponentInteraction) {
i.reply('Hello!')
}
}
class MyCommand extends Command {
public async execute(i: ChatInputInteraction, meta: Metadata) {
const bot = meta.getBot();
const customId = bot.getCommandManager().getCustomIdSerializer().serialize(this);
// reply with button or something that uses the customId
}

public executeComponent(i: ComponentInteraction) {
i.reply('Hello!')
}
}
The serializer and the router in the command manager then work together to properly route interactions to the #executeComponent() method. My problem comes from how to implement string-store's serialization for this. My main idea was to do something like this (on #execute()):
// data is passed as "extra" data, that the serializer doesn't care about what it actually is, it only knows it's a string
const data = store.serialize(/** data */);
const customId = bot.getCommandManager().getCustomIdSerializer().serialize(this, data);
// data is passed as "extra" data, that the serializer doesn't care about what it actually is, it only knows it's a string
const data = store.serialize(/** data */);
const customId = bot.getCommandManager().getCustomIdSerializer().serialize(this, data);
#executeComponent() would then accept an extra, optional parameter, which would be the user-provided data as a string, resolved from the customId. The way this would work is by making the customIdSerializer have a schema with a store like this:
new Schema(Id.Something).string('extraData').../** other data needed to actually resolve the command */;
new Schema(Id.Something).string('extraData').../** other data needed to actually resolve the command */;
The advantage of this is that the user isn't forced to use string-store, they can just pass anything and they'll receive it back. But then if they do use string-store, the user would be serializing the string, and then the framework would be serializing it again, and I wonder if that could cause issues (from my poor testing it doesn't look like it but I'm pretty much nobody compared to the actual maintainers, maybe there's edge cases). Maybe I'm overthinking it and there's a better way?
1 Reply
Favna
Favna3d ago
@kyra
Want results from more Discord servers?
Add your server