Skip to content

Commit

Permalink
Add API for manual parsing of callback data
Browse files Browse the repository at this point in the history
  • Loading branch information
deptyped committed Mar 5, 2023
1 parent b83561d commit 19c1340
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/callback-data-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ class CallbackDataRegistry<T> {
return this.registry.get(id.toString())!.pack(data);
}

parse<I extends keyof T>(id: I, packedData: string): CallbackData<T[I]> {
if (!this.registry.has(id.toString())) {
throw new Error(
`Callback data with ID "${id.toString()}" does not exist`,
);
}

return this.registry.get(id.toString())!.unpack(packedData) as CallbackData<
T[I]
>;
}

regex<I extends keyof T>(id: I, clause?: FilterClause<T[I]>) {
if (!this.registry.has(id.toString())) {
throw new Error(
Expand Down

0 comments on commit 19c1340

Please sign in to comment.