@hyperneutrino/djs-lite 1.7.1 → 1.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.ts +12 -4
  2. package/package.json +1 -1
package/index.ts CHANGED
@@ -46,6 +46,10 @@ type WrapperConfig<R extends Record<string, Handleable>> = {
46
46
  [K in keyof R]?: Wrapper<Handler<R[K]>>;
47
47
  };
48
48
 
49
+ function serialize(object: unknown) {
50
+ return JSON.stringify(object, (_, v) => (typeof v === "bigint" ? v.toString() : v));
51
+ }
52
+
49
53
  /**
50
54
  * This is the type of `config.wrappers` in {@link loadCommands}. This type is exported so that you can expose the wrappers upstream if you are making a library
51
55
  * surrounding this library.
@@ -315,7 +319,9 @@ async function loadSubcommandsAndGroups(directory: string) {
315
319
  * @param directory The relative path (from your execution point) containing your command handlers.
316
320
  * @param config Command-related configuration values.
317
321
  * @param config.guildId The ID of the guild to which to set the commands.
318
- * @param config.wrappers A set of wrappers which transform all handler functions for each handler type.
322
+ * @param config.wrappers A set of wrappers which transform all handler functions for each handler type. This wrapper will be called on each of your configured
323
+ * handlers of the relevant type and must return another handler (i.e. it is a function that transforms its input parameter, which is itself a handler
324
+ * function). This is like middleware; use this for things like error handling, logging, etc.
319
325
  * @returns `commands`, the loaded command data (an array of objects).
320
326
  * @returns `slashCommandHandlers`, the map from each slash command name to its handler.
321
327
  * @returns `userCommandHandlers`, the map from each user context menu command name to its handler.
@@ -365,12 +371,12 @@ export async function loadCommands(client: Client<true>, directory: string, conf
365
371
  const commandDataHasBeenUpdated = await fs
366
372
  .readFile(".cache/command-data.json")
367
373
  .then((buffer) => buffer.toString("utf-8"))
368
- .then((string) => JSON.stringify(commandData) !== string)
374
+ .then((string) => serialize(commandData) !== string)
369
375
  .catch(() => true);
370
376
 
371
377
  if (commandDataHasBeenUpdated) {
372
378
  await fs.mkdir(".cache", { recursive: true }).catch(() => null);
373
- await fs.writeFile(".cache/command-data.json", JSON.stringify(commandData)).catch(() => null);
379
+ await fs.writeFile(".cache/command-data.json", serialize(commandData)).catch(() => null);
374
380
 
375
381
  if (config?.guildId) {
376
382
  const testGuild = client.guilds.resolve(config.guildId);
@@ -410,7 +416,9 @@ export async function loadCommands(client: Client<true>, directory: string, conf
410
416
  * @param directory The relative path (from your execution point) containing your interaction handlers.
411
417
  * @param config Interaction-related configuration values.
412
418
  * @param config.argumentSeparator The separator used to split custom IDs. This defaults to `:`.
413
- * @param config.wrappers A set of wrappers which transform all handler functions for each handler type.
419
+ * @param config.wrappers A set of wrappers which transform all handler functions for each handler type. This wrapper will be called on each of your configured
420
+ * handlers of the relevant type and must return another handler (i.e. it is a function that transforms its input parameter, which is itself a handler
421
+ * function). This is like middleware; use this for things like error handling, logging, etc.
414
422
  * @returns `modalHandlers`, the map from each modal submit handler's configuration file path to its handler function.
415
423
  * @returns `buttonHandlers`, the map from each button handler's configuration file path to its handler function.
416
424
  * @returns `stringSelectMenuHandlers`, the map from each string select menu handler's file path to its handler function.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hyperneutrino/djs-lite",
3
3
  "private": false,
4
- "version": "1.7.1",
4
+ "version": "1.7.3",
5
5
  "module": "index.ts",
6
6
  "type": "module",
7
7
  "devDependencies": {