seedcord 0.18.2-next.0 → 0.19.0

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.
package/dist/cli.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { n as SEEDCORD_CONFIG_FILENAMES, t as version } from "./src-D2qnOxmN.mjs";
1
+ import { n as SEEDCORD_CONFIG_FILENAMES, t as version } from "./src-9h8MoxQN.mjs";
2
2
  import { createRequire } from "node:module";
3
3
  import { Command } from "@commander-js/extra-typings";
4
4
  import { LEVEL_COLOR, Logger, LoggerChannelRegistry } from "@seedcord/logger";
@@ -15,7 +15,7 @@ import { mkdir, readFile, readdir, writeFile } from "node:fs/promises";
15
15
  import { spawn } from "node:child_process";
16
16
  import { SeedcordBrand } from "@seedcord/types/internal";
17
17
  import { isTsOrJsFile } from "@seedcord/utils/node";
18
- import { ApplicationCommandOptionType, ApplicationCommandType, RESTJSONErrorCodes, Routes } from "discord-api-types/v10";
18
+ import { ApplicationCommandOptionType, ApplicationCommandType, InteractionContextType, RESTJSONErrorCodes, Routes } from "discord-api-types/v10";
19
19
  import { routeLeavesOf } from "@seedcord/utils/internal";
20
20
  import { DiscordAPIError, REST } from "@discordjs/rest";
21
21
  import { autocompleteMultiselect, cancel, confirm, intro, isCancel, log, multiselect, note, outro, select, spinner } from "@clack/prompts";
@@ -532,6 +532,10 @@ const KIND_BY_TYPE = {
532
532
  [ApplicationCommandOptionType.Mentionable]: "mentionable",
533
533
  [ApplicationCommandOptionType.Attachment]: "attachment"
534
534
  };
535
+ function cacheStateOf(contexts) {
536
+ if (!contexts || contexts.length === 0) return void 0;
537
+ return contexts.every((context) => context === InteractionContextType.Guild) ? "cached" : void 0;
538
+ }
535
539
  function mapEmojis(emojiConfig) {
536
540
  const emojis = {};
537
541
  for (const [key, value] of Object.entries(emojiConfig)) emojis[key] = Array.isArray(value) ? "tuple" : "string";
@@ -547,23 +551,25 @@ var AugmentationBuilder = class {
547
551
  const sourceByRoute = /* @__PURE__ */ new Map();
548
552
  const sourceByUserName = /* @__PURE__ */ new Map();
549
553
  const sourceByMessageName = /* @__PURE__ */ new Map();
554
+ const userMenus = /* @__PURE__ */ new Map();
555
+ const messageMenus = /* @__PURE__ */ new Map();
550
556
  for (const command of commands) {
551
557
  const { json } = command;
552
558
  switch (json.type) {
553
559
  case ApplicationCommandType.User:
554
- this.collectContextMenu("user", json, command.sourceFile, sourceByUserName);
560
+ this.collectContextMenu("user", json, command.sourceFile, sourceByUserName, userMenus);
555
561
  break;
556
562
  case ApplicationCommandType.Message:
557
- this.collectContextMenu("message", json, command.sourceFile, sourceByMessageName);
563
+ this.collectContextMenu("message", json, command.sourceFile, sourceByMessageName, messageMenus);
558
564
  break;
559
565
  case void 0:
560
566
  case ApplicationCommandType.ChatInput: this.collectSlash(json, command.sourceFile, slash, sourceByRoute);
561
567
  }
562
568
  }
563
- const userContextMenus = [...sourceByUserName.keys()];
564
- const messageContextMenus = [...sourceByMessageName.keys()];
569
+ const userContextMenus = Object.fromEntries(userMenus);
570
+ const messageContextMenus = Object.fromEntries(messageMenus);
565
571
  const emojis = mapEmojis(emojiConfig);
566
- this.logger.debug(`Generated ${Object.keys(slash).length} slash route(s), ${userContextMenus.length} user and ${messageContextMenus.length} message context-menu command(s), ${Object.keys(emojis).length} emoji(s)`);
572
+ this.logger.debug(`Generated ${Object.keys(slash).length} slash route(s), ${Object.keys(userContextMenus).length} user and ${Object.keys(messageContextMenus).length} message context-menu command(s), ${Object.keys(emojis).length} emoji(s)`);
567
573
  return {
568
574
  slash,
569
575
  userContextMenus,
@@ -573,6 +579,7 @@ var AugmentationBuilder = class {
573
579
  }
574
580
  collectSlash(json, sourceFile, slash, sourceByRoute) {
575
581
  this.warnEmptyGroups(json);
582
+ const cacheState = cacheStateOf(json.contexts);
576
583
  for (const leaf of routeLeavesOf(json)) {
577
584
  const firstFile = sourceByRoute.get(leaf.route);
578
585
  if (firstFile !== void 0) throw new SeedcordError(SeedcordErrorCode.CliCodegenDuplicateRoute, [
@@ -581,10 +588,13 @@ var AugmentationBuilder = class {
581
588
  sourceFile
582
589
  ]);
583
590
  sourceByRoute.set(leaf.route, sourceFile);
584
- slash[leaf.route] = this.mapOptions(leaf.options);
591
+ slash[leaf.route] = {
592
+ options: this.mapOptions(leaf.options),
593
+ cache: cacheState
594
+ };
585
595
  }
586
596
  }
587
- collectContextMenu(kind, json, sourceFile, sourceByName) {
597
+ collectContextMenu(kind, json, sourceFile, sourceByName, menus) {
588
598
  const firstFile = sourceByName.get(json.name);
589
599
  if (firstFile !== void 0) throw new SeedcordError(SeedcordErrorCode.CliCodegenDuplicateContextMenu, [
590
600
  kind,
@@ -593,6 +603,7 @@ var AugmentationBuilder = class {
593
603
  sourceFile
594
604
  ]);
595
605
  sourceByName.set(json.name, sourceFile);
606
+ menus.set(json.name, { cache: cacheStateOf(json.contexts) });
596
607
  }
597
608
  warnEmptyGroups(json) {
598
609
  for (const option of json.options ?? []) if (option.type === ApplicationCommandOptionType.SubcommandGroup && (option.options ?? []).length === 0) this.logger.warn(`Slash group \`${json.name}/${option.name}\` has no subcommands and will not deploy.`);
@@ -632,21 +643,28 @@ function renderAugmentation(registry, target, plugins) {
632
643
  const attached = plugins !== void 0 && keys.length > 0;
633
644
  const botImport = attached ? `import type ${BOT_BINDING} from '${escapeLiteral(plugins.specifier)}';\n\n` : "";
634
645
  const coreRows = attached ? ` interface Core {\n${renderPluginRows(keys)}\n }\n` : "";
635
- return `${`${BANNER}\n\n${botImport}// prettier-ignore\ndeclare module '${target}' {\n` + coreRows} interface SlashOptionRegistry {\n${renderSlashRows(registry.slash)}\n }\n interface UserContextMenuRegistry {\n${renderContextMenuRows(registry.userContextMenus)}\n }\n interface MessageContextMenuRegistry {\n${renderContextMenuRows(registry.messageContextMenus)}\n }\n interface EmojiMap {\n${renderEmojiRows(registry.emojis)}\n }\n}\n\nexport {};\n`;
646
+ return `${`${BANNER}\n\n${botImport}// prettier-ignore\ndeclare module '${target}' {\n` + coreRows} interface SlashRegistry {\n${renderSlashRows(registry.slash)}\n }\n interface UserContextMenuRegistry {\n${renderContextMenuRows(registry.userContextMenus)}\n }\n interface MessageContextMenuRegistry {\n${renderContextMenuRows(registry.messageContextMenus)}\n }\n interface EmojiMap {\n${renderEmojiRows(registry.emojis)}\n }\n}\n\nexport {};\n`;
636
647
  }
637
648
  function renderPluginRows(keys) {
638
649
  return keys.map((key) => ` ${renderKey(key)}: (typeof ${BOT_BINDING})['${escapeLiteral(key)}'];`).join("\n");
639
650
  }
640
651
  function renderSlashRows(tables) {
641
- return Object.entries(tables).sort(([first], [second]) => compare(first, second)).map(([route, options]) => ` ${renderKey(route)}: ${renderRow(options)};`).join("\n");
652
+ return Object.entries(tables).sort(([first], [second]) => compare(first, second)).map(([route, row]) => ` ${renderKey(route)}: ${renderRow(row)};`).join("\n");
642
653
  }
643
- function renderContextMenuRows(names) {
644
- return [...names].sort(compare).map((name) => ` ${renderKey(name)}: true;`).join("\n");
654
+ function renderContextMenuRows(menus) {
655
+ return Object.entries(menus).sort(([first], [second]) => compare(first, second)).map(([name, { cache }]) => ` ${renderKey(name)}: ${renderCacheRow(cache)};`).join("\n");
656
+ }
657
+ function renderCacheRow(cache) {
658
+ return `{ cache: ${cache === void 0 ? "undefined" : `'${cache}'`} }`;
645
659
  }
646
660
  function renderEmojiRows(emojis) {
647
661
  return Object.entries(emojis).sort(([first], [second]) => compare(first, second)).map(([key, kind]) => ` ${renderKey(key)}: '${kind === "tuple" ? "guild" : "application"}';`).join("\n");
648
662
  }
649
- function renderRow(options) {
663
+ function renderRow(row) {
664
+ const cache = row.cache === void 0 ? "undefined" : `'${row.cache}'`;
665
+ return `{ options: ${renderOptions(row.options)}; cache: ${cache} }`;
666
+ }
667
+ function renderOptions(options) {
650
668
  const entries = Object.entries(options);
651
669
  if (entries.length === 0) return "{}";
652
670
  return `{ ${entries.map(([name, opt]) => `${renderKey(name)}: ${renderOption(opt)}`).join("; ")} }`;