@went.tf/discord-bot-framework 2.0.0 → 2.2.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.
Files changed (65) hide show
  1. package/README.md +113 -35
  2. package/build/.tsbuildinfo +1 -1
  3. package/build/commands/build-application-commands-body.d.ts +13 -2
  4. package/build/commands/build-application-commands-body.d.ts.map +1 -1
  5. package/build/commands/build-application-commands-body.js +42 -2
  6. package/build/commands/build-application-commands-body.js.map +1 -1
  7. package/build/commands/schema/application-command-leaf-option.schema.d.ts +9 -9
  8. package/build/commands/schema/application-command-leaf-option.schema.js +9 -9
  9. package/build/commands/schema/application-command-leaf-option.schema.js.map +1 -1
  10. package/build/commands/schema/application-command-leaf-option.schema.json +36 -9
  11. package/build/commands/schema/application-command-subcommand-group.schema.d.ts +1 -1
  12. package/build/commands/schema/application-command-subcommand-group.schema.js +1 -1
  13. package/build/commands/schema/application-command-subcommand-group.schema.js.map +1 -1
  14. package/build/commands/schema/application-command-subcommand-group.schema.json +4 -1
  15. package/build/commands/schema/application-command-subcommand.schema.d.ts +1 -1
  16. package/build/commands/schema/application-command-subcommand.schema.js +1 -1
  17. package/build/commands/schema/application-command-subcommand.schema.js.map +1 -1
  18. package/build/commands/schema/application-command-subcommand.schema.json +4 -1
  19. package/build/commands/schema/application-command-type.schema.d.ts +2 -2
  20. package/build/commands/schema/application-command-type.schema.d.ts.map +1 -1
  21. package/build/commands/schema/application-command-type.schema.js +2 -2
  22. package/build/commands/schema/application-command-type.schema.js.map +1 -1
  23. package/build/commands/schema/application-command-type.schema.json +5 -2
  24. package/build/commands/schema/application-integration-type.schema.d.ts +2 -2
  25. package/build/commands/schema/application-integration-type.schema.d.ts.map +1 -1
  26. package/build/commands/schema/application-integration-type.schema.js +2 -2
  27. package/build/commands/schema/application-integration-type.schema.js.map +1 -1
  28. package/build/commands/schema/application-integration-type.schema.json +4 -2
  29. package/build/commands/schema/channel-type.schema.d.ts +2 -2
  30. package/build/commands/schema/channel-type.schema.d.ts.map +1 -1
  31. package/build/commands/schema/channel-type.schema.js +6 -2
  32. package/build/commands/schema/channel-type.schema.js.map +1 -1
  33. package/build/commands/schema/channel-type.schema.json +12 -2
  34. package/build/commands/schema/chat-input-command.schema.d.ts +1 -1
  35. package/build/commands/schema/chat-input-command.schema.js +1 -1
  36. package/build/commands/schema/chat-input-command.schema.js.map +1 -1
  37. package/build/commands/schema/chat-input-command.schema.json +4 -1
  38. package/build/commands/schema/command-file-entry.schema.d.ts +16 -0
  39. package/build/commands/schema/command-file-entry.schema.d.ts.map +1 -0
  40. package/build/commands/schema/command-file-entry.schema.js +14 -0
  41. package/build/commands/schema/command-file-entry.schema.js.map +1 -0
  42. package/build/commands/schema/command-file-entry.schema.json +11 -0
  43. package/build/commands/schema/commands-file.schema.d.ts +38 -12
  44. package/build/commands/schema/commands-file.schema.d.ts.map +1 -1
  45. package/build/commands/schema/commands-file.schema.js +30 -10
  46. package/build/commands/schema/commands-file.schema.js.map +1 -1
  47. package/build/commands/schema/commands-file.schema.json +25 -10
  48. package/build/commands/schema/context-menu-command.schema.d.ts +1 -1
  49. package/build/commands/schema/context-menu-command.schema.js +1 -1
  50. package/build/commands/schema/context-menu-command.schema.js.map +1 -1
  51. package/build/commands/schema/context-menu-command.schema.json +3 -1
  52. package/build/commands/schema/enum-maps.d.ts +52 -0
  53. package/build/commands/schema/enum-maps.d.ts.map +1 -0
  54. package/build/commands/schema/enum-maps.js +54 -0
  55. package/build/commands/schema/enum-maps.js.map +1 -0
  56. package/build/commands/schema/index.d.ts +58 -4
  57. package/build/commands/schema/index.d.ts.map +1 -1
  58. package/build/commands/schema/index.js +76 -3
  59. package/build/commands/schema/index.js.map +1 -1
  60. package/build/commands/schema/interaction-context-type.schema.d.ts +2 -2
  61. package/build/commands/schema/interaction-context-type.schema.d.ts.map +1 -1
  62. package/build/commands/schema/interaction-context-type.schema.js +2 -2
  63. package/build/commands/schema/interaction-context-type.schema.js.map +1 -1
  64. package/build/commands/schema/interaction-context-type.schema.json +5 -2
  65. package/package.json +1 -1
@@ -1,6 +1,6 @@
1
1
  export declare const channelTypeSchema: {
2
2
  readonly $id: "https://schema.went.tf/discord-bot-framework/channel-type.json";
3
- readonly description: "ApplicationCommandOptionAllowedChannelType (discord-api-types): ChannelType excluding DM (1), GroupDM (3), GuildDirectory (14) - the subset Discord accepts in a Channel option's channel_types filter.";
4
- readonly enum: readonly [0, 2, 4, 5, 10, 11, 12, 13, 15, 16];
3
+ readonly description: "ApplicationCommandOptionAllowedChannelType (discord-api-types): ChannelType excluding DM (1), GroupDM (3), GuildDirectory (14) - the subset Discord accepts in a Channel option's channel_types filter. Both the numeric value and its UPPER_SNAKE_CASE string alias (see enum-maps.ts) are always valid.";
4
+ readonly enum: readonly [0, 2, 4, 5, 10, 11, 12, 13, 15, 16, "GUILD_TEXT", "GUILD_VOICE", "GUILD_CATEGORY", "GUILD_ANNOUNCEMENT", "ANNOUNCEMENT_THREAD", "PUBLIC_THREAD", "PRIVATE_THREAD", "GUILD_STAGE_VOICE", "GUILD_FORUM", "GUILD_MEDIA"];
5
5
  };
6
6
  //# sourceMappingURL=channel-type.schema.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"channel-type.schema.d.ts","sourceRoot":"","sources":["../../../src/commands/schema/channel-type.schema.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB;;;;CAKpB,CAAC"}
1
+ {"version":3,"file":"channel-type.schema.d.ts","sourceRoot":"","sources":["../../../src/commands/schema/channel-type.schema.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB;;;;CASpB,CAAC"}
@@ -1,6 +1,10 @@
1
1
  export const channelTypeSchema = {
2
2
  $id: 'https://schema.went.tf/discord-bot-framework/channel-type.json',
3
- description: 'ApplicationCommandOptionAllowedChannelType (discord-api-types): ChannelType excluding DM (1), GroupDM (3), GuildDirectory (14) - the subset Discord accepts in a Channel option\'s channel_types filter.',
4
- enum: [0, 2, 4, 5, 10, 11, 12, 13, 15, 16],
3
+ description: 'ApplicationCommandOptionAllowedChannelType (discord-api-types): ChannelType excluding DM (1), GroupDM (3), GuildDirectory (14) - the subset Discord accepts in a Channel option\'s channel_types filter. Both the numeric value and its UPPER_SNAKE_CASE string alias (see enum-maps.ts) are always valid.',
4
+ enum: [
5
+ 0, 2, 4, 5, 10, 11, 12, 13, 15, 16,
6
+ 'GUILD_TEXT', 'GUILD_VOICE', 'GUILD_CATEGORY', 'GUILD_ANNOUNCEMENT', 'ANNOUNCEMENT_THREAD',
7
+ 'PUBLIC_THREAD', 'PRIVATE_THREAD', 'GUILD_STAGE_VOICE', 'GUILD_FORUM', 'GUILD_MEDIA',
8
+ ],
5
9
  };
6
10
  //# sourceMappingURL=channel-type.schema.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"channel-type.schema.js","sourceRoot":"","sources":["../../../src/commands/schema/channel-type.schema.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,GAAG,EAAE,gEAAgE;IACrE,WAAW,EACT,0MAA0M;IAC5M,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC;CAClC,CAAC"}
1
+ {"version":3,"file":"channel-type.schema.js","sourceRoot":"","sources":["../../../src/commands/schema/channel-type.schema.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,GAAG,EAAE,gEAAgE;IACrE,WAAW,EACT,4SAA4S;IAC9S,IAAI,EAAE;QACJ,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE;QAClC,YAAY,EAAE,aAAa,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,qBAAqB;QAC1F,eAAe,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,aAAa,EAAE,aAAa;KACrF;CACO,CAAC"}
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$id": "https://schema.went.tf/discord-bot-framework/channel-type.json",
3
- "description": "ApplicationCommandOptionAllowedChannelType (discord-api-types): ChannelType excluding DM (1), GroupDM (3), GuildDirectory (14) - the subset Discord accepts in a Channel option's channel_types filter.",
3
+ "description": "ApplicationCommandOptionAllowedChannelType (discord-api-types): ChannelType excluding DM (1), GroupDM (3), GuildDirectory (14) - the subset Discord accepts in a Channel option's channel_types filter. Both the numeric value and its UPPER_SNAKE_CASE string alias (see enum-maps.ts) are always valid.",
4
4
  "enum": [
5
5
  0,
6
6
  2,
@@ -11,6 +11,16 @@
11
11
  12,
12
12
  13,
13
13
  15,
14
- 16
14
+ 16,
15
+ "GUILD_TEXT",
16
+ "GUILD_VOICE",
17
+ "GUILD_CATEGORY",
18
+ "GUILD_ANNOUNCEMENT",
19
+ "ANNOUNCEMENT_THREAD",
20
+ "PUBLIC_THREAD",
21
+ "PRIVATE_THREAD",
22
+ "GUILD_STAGE_VOICE",
23
+ "GUILD_FORUM",
24
+ "GUILD_MEDIA"
15
25
  ]
16
26
  }
@@ -4,7 +4,7 @@ export declare const chatInputCommandSchema: {
4
4
  readonly type: "object";
5
5
  readonly properties: {
6
6
  readonly type: {
7
- readonly const: 1;
7
+ readonly enum: readonly [1, "CHAT_INPUT"];
8
8
  };
9
9
  readonly name: {
10
10
  readonly $ref: "https://schema.went.tf/discord-bot-framework/option-name.json";
@@ -8,7 +8,7 @@ export const chatInputCommandSchema = {
8
8
  $id: 'https://schema.went.tf/discord-bot-framework/chat-input-command.json',
9
9
  type: 'object',
10
10
  properties: {
11
- type: { const: 1 },
11
+ type: { enum: [1, 'CHAT_INPUT'] },
12
12
  name: { $ref: optionNameSchema.$id },
13
13
  description: { type: 'string' },
14
14
  options: {
@@ -1 +1 @@
1
- {"version":3,"file":"chat-input-command.schema.js","sourceRoot":"","sources":["../../../src/commands/schema/chat-input-command.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAAE,MAAM,wCAAwC,CAAC;AACxF,OAAO,EAAE,gCAAgC,EAAE,MAAM,0CAA0C,CAAC;AAC5F,OAAO,EAAE,8BAA8B,EAAE,MAAM,wCAAwC,CAAC;AACxF,OAAO,EAAE,4BAA4B,EAAE,MAAM,sCAAsC,CAAC;AACpF,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAE3D,2GAA2G;AAC3G,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,GAAG,EAAE,sEAAsE;IAC3E,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACV,IAAI,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE;QAClB,IAAI,EAAE,EAAE,IAAI,EAAE,gBAAgB,CAAC,GAAG,EAAE;QACpC,WAAW,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QAC/B,OAAO,EAAE;YACP,IAAI,EAAE,OAAO;YACb,KAAK,EAAE,EAAE,IAAI,EAAE,8BAA8B,CAAC,GAAG,EAAE;SACpD;QACD,0BAA0B,EAAE,EAAE,IAAI,EAAE,8BAA8B,CAAC,GAAG,EAAE;QACxE,QAAQ,EAAE;YACR,IAAI,EAAE,OAAO;YACb,KAAK,EAAE,EAAE,IAAI,EAAE,4BAA4B,CAAC,GAAG,EAAE;YACjD,WAAW,EAAE,IAAI;SAClB;QACD,iBAAiB,EAAE;YACjB,IAAI,EAAE,OAAO;YACb,KAAK,EAAE,EAAE,IAAI,EAAE,gCAAgC,CAAC,GAAG,EAAE;YACrD,WAAW,EAAE,IAAI;SAClB;QACD,IAAI,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;KAC1B;IACD,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC;IAC1B,oBAAoB,EAAE,KAAK;CACnB,CAAC"}
1
+ {"version":3,"file":"chat-input-command.schema.js","sourceRoot":"","sources":["../../../src/commands/sch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"properties": {
5
5
  "type": {
6
- "const": 1
6
+ "enum": [
7
+ 1,
8
+ "CHAT_INPUT"
9
+ ]
7
10
  },
8
11
  "name": {
9
12
  "$ref": "https://schema.went.tf/discord-bot-framework/option-name.json"
@@ -0,0 +1,16 @@
1
+ /**
2
+ * One commands.json entry: a chat-input or context-menu command. Its own
3
+ * fragment (rather than staying inlined in commands-file.schema.ts) so both
4
+ * root shapes commands-file.schema.ts accepts (bare array, or `{ commands }`)
5
+ * can `$ref` the same single source of truth for "one entry" instead of
6
+ * duplicating the oneOf.
7
+ */
8
+ export declare const commandFileEntrySchema: {
9
+ readonly $id: "https://schema.went.tf/discord-bot-framework/command-file-entry.json";
10
+ readonly oneOf: readonly [{
11
+ readonly $ref: "https://schema.went.tf/discord-bot-framework/chat-input-command.json";
12
+ }, {
13
+ readonly $ref: "https://schema.went.tf/discord-bot-framework/context-menu-command.json";
14
+ }];
15
+ };
16
+ //# sourceMappingURL=command-file-entry.schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command-file-entry.schema.d.ts","sourceRoot":"","sources":["../../../src/commands/schema/command-file-entry.schema.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB;;;;;;;CAGzB,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { chatInputCommandSchema } from './chat-input-command.schema.js';
2
+ import { contextMenuCommandSchema } from './context-menu-command.schema.js';
3
+ /**
4
+ * One commands.json entry: a chat-input or context-menu command. Its own
5
+ * fragment (rather than staying inlined in commands-file.schema.ts) so both
6
+ * root shapes commands-file.schema.ts accepts (bare array, or `{ commands }`)
7
+ * can `$ref` the same single source of truth for "one entry" instead of
8
+ * duplicating the oneOf.
9
+ */
10
+ export const commandFileEntrySchema = {
11
+ $id: 'https://schema.went.tf/discord-bot-framework/command-file-entry.json',
12
+ oneOf: [{ $ref: chatInputCommandSchema.$id }, { $ref: contextMenuCommandSchema.$id }],
13
+ };
14
+ //# sourceMappingURL=command-file-entry.schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command-file-entry.schema.js","sourceRoot":"","sources":["../../../src/commands/schema/command-file-entry.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AACxE,OAAO,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAE5E;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,GAAG,EAAE,sEAAsE;IAC3E,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,sBAAsB,CAAC,GAAG,EAAE,EAAE,EAAE,IAAI,EAAE,wBAAwB,CAAC,GAAG,EAAE,CAAC;CAC7E,CAAC"}
@@ -0,0 +1,11 @@
1
+ {
2
+ "$id": "https://schema.went.tf/discord-bot-framework/command-file-entry.json",
3
+ "oneOf": [
4
+ {
5
+ "$ref": "https://schema.went.tf/discord-bot-framework/chat-input-command.json"
6
+ },
7
+ {
8
+ "$ref": "https://schema.went.tf/discord-bot-framework/context-menu-command.json"
9
+ }
10
+ ]
11
+ }
@@ -1,18 +1,44 @@
1
1
  /**
2
- * The framework's base whole-file fragment: a flat array mirroring Discord's
3
- * bulk-overwrite PUT body shape. Usable directly by bots with no extra
4
- * constraints, or as the thing a bot's own commands.schema composes over
5
- * (e.g. narrowing `name` to an enum of its actual command names) via allOf/$ref.
2
+ * The framework's base whole-file fragment: either a flat array mirroring
3
+ * Discord's bulk-overwrite PUT body shape directly, or that same array
4
+ * wrapped as `{ $schema?, commands }`. The wrapped form exists because a
5
+ * bare JSON array can never carry an inline `$schema` property - `$schema`
6
+ * is only valid on a JSON object - so editors (VS Code, JetBrains, ...) have
7
+ * no way to offer autocomplete/validation while hand-editing a bare-array
8
+ * commands.json. Wrapping it as an object lets `"$schema": "./commands.schema.json"`
9
+ * point straight at a bot's own composed schema file with zero extra editor
10
+ * config. Both forms are permanently supported - the bare array isn't going
11
+ * away, this is additive.
12
+ *
13
+ * Usable directly by bots with no extra constraints, or as the thing a bot's
14
+ * own commands.schema composes over (e.g. narrowing `name` to an enum of its
15
+ * actual command names) via allOf/$ref - see the README's `$defs`-based
16
+ * recipe for composing both the name-narrowing and the dual-root-shape at
17
+ * once, since a bot's own commands.schema.json is authored as plain JSON,
18
+ * not through this package's TS fragment-composition tooling.
6
19
  */
7
20
  export declare const commandsFileSchema: {
8
21
  readonly $id: "https://schema.went.tf/discord-bot-framework/commands-file.json";
9
- readonly type: "array";
10
- readonly items: {
11
- readonly oneOf: readonly [{
12
- readonly $ref: "https://schema.went.tf/discord-bot-framework/chat-input-command.json";
13
- }, {
14
- readonly $ref: "https://schema.went.tf/discord-bot-framework/context-menu-command.json";
15
- }];
16
- };
22
+ readonly oneOf: readonly [{
23
+ readonly type: "array";
24
+ readonly items: {
25
+ readonly $ref: "https://schema.went.tf/discord-bot-framework/command-file-entry.json";
26
+ };
27
+ }, {
28
+ readonly type: "object";
29
+ readonly properties: {
30
+ readonly $schema: {
31
+ readonly type: "string";
32
+ };
33
+ readonly commands: {
34
+ readonly type: "array";
35
+ readonly items: {
36
+ readonly $ref: "https://schema.went.tf/discord-bot-framework/command-file-entry.json";
37
+ };
38
+ };
39
+ };
40
+ readonly required: readonly ["commands"];
41
+ readonly additionalProperties: false;
42
+ }];
17
43
  };
18
44
  //# sourceMappingURL=commands-file.schema.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"commands-file.schema.d.ts","sourceRoot":"","sources":["../../../src/commands/schema/commands-file.schema.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB;;;;;;;;;;CAMrB,CAAC"}
1
+ {"version":3,"file":"commands-file.schema.d.ts","sourceRoot":"","sources":["../../../src/commands/schema/commands-file.schema.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;CAcrB,CAAC"}
@@ -1,16 +1,36 @@
1
- import { chatInputCommandSchema } from './chat-input-command.schema.js';
2
- import { contextMenuCommandSchema } from './context-menu-command.schema.js';
1
+ import { commandFileEntrySchema } from './command-file-entry.schema.js';
3
2
  /**
4
- * The framework's base whole-file fragment: a flat array mirroring Discord's
5
- * bulk-overwrite PUT body shape. Usable directly by bots with no extra
6
- * constraints, or as the thing a bot's own commands.schema composes over
7
- * (e.g. narrowing `name` to an enum of its actual command names) via allOf/$ref.
3
+ * The framework's base whole-file fragment: either a flat array mirroring
4
+ * Discord's bulk-overwrite PUT body shape directly, or that same array
5
+ * wrapped as `{ $schema?, commands }`. The wrapped form exists because a
6
+ * bare JSON array can never carry an inline `$schema` property - `$schema`
7
+ * is only valid on a JSON object - so editors (VS Code, JetBrains, ...) have
8
+ * no way to offer autocomplete/validation while hand-editing a bare-array
9
+ * commands.json. Wrapping it as an object lets `"$schema": "./commands.schema.json"`
10
+ * point straight at a bot's own composed schema file with zero extra editor
11
+ * config. Both forms are permanently supported - the bare array isn't going
12
+ * away, this is additive.
13
+ *
14
+ * Usable directly by bots with no extra constraints, or as the thing a bot's
15
+ * own commands.schema composes over (e.g. narrowing `name` to an enum of its
16
+ * actual command names) via allOf/$ref - see the README's `$defs`-based
17
+ * recipe for composing both the name-narrowing and the dual-root-shape at
18
+ * once, since a bot's own commands.schema.json is authored as plain JSON,
19
+ * not through this package's TS fragment-composition tooling.
8
20
  */
9
21
  export const commandsFileSchema = {
10
22
  $id: 'https://schema.went.tf/discord-bot-framework/commands-file.json',
11
- type: 'array',
12
- items: {
13
- oneOf: [{ $ref: chatInputCommandSchema.$id }, { $ref: contextMenuCommandSchema.$id }],
14
- },
23
+ oneOf: [
24
+ { type: 'array', items: { $ref: commandFileEntrySchema.$id } },
25
+ {
26
+ type: 'object',
27
+ properties: {
28
+ $schema: { type: 'string' },
29
+ commands: { type: 'array', items: { $ref: commandFileEntrySchema.$id } },
30
+ },
31
+ required: ['commands'],
32
+ additionalProperties: false,
33
+ },
34
+ ],
15
35
  };
16
36
  //# sourceMappingURL=commands-file.schema.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"commands-file.schema.js","sourceRoot":"","sources":["../../../src/commands/schema/commands-file.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AACxE,OAAO,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAE5E;;;;;GAKG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,GAAG,EAAE,iEAAiE;IACtE,IAAI,EAAE,OAAO;IACb,KAAK,EAAE;QACL,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,sBAAsB,CAAC,GAAG,EAAE,EAAE,EAAE,IAAI,EAAE,wBAAwB,CAAC,GAAG,EAAE,CAAC;KACtF;CACO,CAAC"}
1
+ {"version":3,"file":"commands-file.schema.js","sourceRoot":"","sources":["../../../src/commands/schema/commands-file.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AAExE;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,GAAG,EAAE,iEAAiE;IACtE,KAAK,EAAE;QACL,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,sBAAsB,CAAC,GAAG,EAAE,EAAE;QAC9D;YACE,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,OAAO,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;gBAC3B,QAAQ,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,sBAAsB,CAAC,GAAG,EAAE,EAAE;aACzE;YACD,QAAQ,EAAE,CAAC,UAAU,CAAC;YACtB,oBAAoB,EAAE,KAAK;SAC5B;KACF;CACO,CAAC"}
@@ -1,14 +1,29 @@
1
1
  {
2
2
  "$id": "https://schema.went.tf/discord-bot-framework/commands-file.json",
3
- "type": "array",
4
- "items": {
5
- "oneOf": [
6
- {
7
- "$ref": "https://schema.went.tf/discord-bot-framework/chat-input-command.json"
8
- },
9
- {
10
- "$ref": "https://schema.went.tf/discord-bot-framework/context-menu-command.json"
3
+ "oneOf": [
4
+ {
5
+ "type": "array",
6
+ "items": {
7
+ "$ref": "https://schema.went.tf/discord-bot-framework/command-file-entry.json"
11
8
  }
12
- ]
13
- }
9
+ },
10
+ {
11
+ "type": "object",
12
+ "properties": {
13
+ "$schema": {
14
+ "type": "string"
15
+ },
16
+ "commands": {
17
+ "type": "array",
18
+ "items": {
19
+ "$ref": "https://schema.went.tf/discord-bot-framework/command-file-entry.json"
20
+ }
21
+ }
22
+ },
23
+ "required": [
24
+ "commands"
25
+ ],
26
+ "additionalProperties": false
27
+ }
28
+ ]
14
29
  }
@@ -8,7 +8,7 @@ export declare const contextMenuCommandSchema: {
8
8
  readonly type: "object";
9
9
  readonly properties: {
10
10
  readonly type: {
11
- readonly enum: readonly [2, 3];
11
+ readonly enum: readonly [2, 3, "USER", "MESSAGE"];
12
12
  };
13
13
  readonly name: {
14
14
  readonly $ref: "https://schema.went.tf/discord-bot-framework/context-menu-name.json";
@@ -11,7 +11,7 @@ export const contextMenuCommandSchema = {
11
11
  $id: 'https://schema.went.tf/discord-bot-framework/context-menu-command.json',
12
12
  type: 'object',
13
13
  properties: {
14
- type: { enum: [2, 3] },
14
+ type: { enum: [2, 3, 'USER', 'MESSAGE'] },
15
15
  name: { $ref: contextMenuNameSchema.$id },
16
16
  default_member_permissions: { $ref: defaultMemberPermissionsSchema.$id },
17
17
  contexts: {
@@ -1 +1 @@
1
- {"version":3,"file":"context-menu-command.schema.js","sourceRoot":"","sources":["../../../src/commands/schema/context-menu-command.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gCAAgC,EAAE,MAAM,0CAA0C,CAAC;AAC5F,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAE,8BAA8B,EAAE,MAAM,wCAAwC,CAAC;AACxF,OAAO,EAAE,4BAA4B,EAAE,MAAM,sCAAsC,CAAC;AAEpF;;;;GAIG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG;IACtC,GAAG,EAAE,wEAAwE;IAC7E,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACV,IAAI,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE;QACtB,IAAI,EAAE,EAAE,IAAI,EAAE,qBAAqB,CAAC,GAAG,EAAE;QACzC,0BAA0B,EAAE,EAAE,IAAI,EAAE,8BAA8B,CAAC,GAAG,EAAE;QACxE,QAAQ,EAAE;YACR,IAAI,EAAE,OAAO;YACb,KAAK,EAAE,EAAE,IAAI,EAAE,4BAA4B,CAAC,GAAG,EAAE;YACjD,WAAW,EAAE,IAAI;SAClB;QACD,iBAAiB,EAAE;YACjB,IAAI,EAAE,OAAO;YACb,KAAK,EAAE,EAAE,IAAI,EAAE,gCAAgC,CAAC,GAAG,EAAE;YACrD,WAAW,EAAE,IAAI;SAClB;QACD,IAAI,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;KAC1B;IACD,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC;IAC1B,oBAAoB,EAAE,KAAK;CACnB,CAAC"}
1
+ {"version":3,"file":"context-menu-command.schema.js","sourceRoot":"","sources":["../../../src/commands/schema/context-menu-command.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gCAAgC,EAAE,MAAM,0CAA0C,CAAC;AAC5F,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAE,8BAA8B,EAAE,MAAM,wCAAwC,CAAC;AACxF,OAAO,EAAE,4BAA4B,EAAE,MAAM,sCAAsC,CAAC;AAEpF;;;;GAIG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG;IACtC,GAAG,EAAE,wEAAwE;IAC7E,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACV,IAAI,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE;QACzC,IAAI,EAAE,EAAE,IAAI,EAAE,qBAAqB,CAAC,GAAG,EAAE;QACzC,0BAA0B,EAAE,EAAE,IAAI,EAAE,8BAA8B,CAAC,GAAG,EAAE;QACxE,QAAQ,EAAE;YACR,IAAI,EAAE,OAAO;YACb,KAAK,EAAE,EAAE,IAAI,EAAE,4BAA4B,CAAC,GAAG,EAAE;YACjD,WAAW,EAAE,IAAI;SAClB;QACD,iBAAiB,EAAE;YACjB,IAAI,EAAE,OAAO;YACb,KAAK,EAAE,EAAE,IAAI,EAAE,gCAAgC,CAAC,GAAG,EAAE;YACrD,WAAW,EAAE,IAAI;SAClB;QACD,IAAI,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;KAC1B;IACD,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC;IAC1B,oBAAoB,EAAE,KAAK;CACnB,CAAC"}
@@ -5,7 +5,9 @@
5
5
  "type": {
6
6
  "enum": [
7
7
  2,
8
- 3
8
+ 3,
9
+ "USER",
10
+ "MESSAGE"
9
11
  ]
10
12
  },
11
13
  "name": {
@@ -0,0 +1,52 @@
1
+ import { ApplicationCommandOptionType, ApplicationCommandType, ApplicationIntegrationType, ChannelType, InteractionContextType } from 'discord-api-types/v10';
2
+ /**
3
+ * UPPER_SNAKE_CASE string aliases for Discord's numeric command/option enums,
4
+ * so commands.json authors don't have to memorize what `3` means. Sourced
5
+ * from discord-api-types' own enums (not hand-duplicated numbers) so these
6
+ * can never drift from the real values. Both the numeric and string form are
7
+ * always valid in commands.json - see `resolveEnumValue` - this is additive,
8
+ * not a replacement, specifically so it never needs to be a breaking change.
9
+ */
10
+ export declare const APPLICATION_COMMAND_TYPE_MAP: {
11
+ readonly CHAT_INPUT: ApplicationCommandType.ChatInput;
12
+ readonly USER: ApplicationCommandType.User;
13
+ readonly MESSAGE: ApplicationCommandType.Message;
14
+ };
15
+ export declare const APPLICATION_COMMAND_OPTION_TYPE_MAP: {
16
+ readonly SUBCOMMAND: ApplicationCommandOptionType.Subcommand;
17
+ readonly SUBCOMMAND_GROUP: ApplicationCommandOptionType.SubcommandGroup;
18
+ readonly STRING: ApplicationCommandOptionType.String;
19
+ readonly INTEGER: ApplicationCommandOptionType.Integer;
20
+ readonly BOOLEAN: ApplicationCommandOptionType.Boolean;
21
+ readonly USER: ApplicationCommandOptionType.User;
22
+ readonly CHANNEL: ApplicationCommandOptionType.Channel;
23
+ readonly ROLE: ApplicationCommandOptionType.Role;
24
+ readonly MENTIONABLE: ApplicationCommandOptionType.Mentionable;
25
+ readonly NUMBER: ApplicationCommandOptionType.Number;
26
+ readonly ATTACHMENT: ApplicationCommandOptionType.Attachment;
27
+ };
28
+ export declare const INTERACTION_CONTEXT_TYPE_MAP: {
29
+ readonly GUILD: InteractionContextType.Guild;
30
+ readonly BOT_DM: InteractionContextType.BotDM;
31
+ readonly PRIVATE_CHANNEL: InteractionContextType.PrivateChannel;
32
+ };
33
+ export declare const APPLICATION_INTEGRATION_TYPE_MAP: {
34
+ readonly GUILD_INSTALL: ApplicationIntegrationType.GuildInstall;
35
+ readonly USER_INSTALL: ApplicationIntegrationType.UserInstall;
36
+ };
37
+ /** Only the ChannelType subset Discord accepts in an option's channel_types filter - see channel-type.schema.ts. */
38
+ export declare const CHANNEL_TYPE_MAP: {
39
+ readonly GUILD_TEXT: ChannelType.GuildText;
40
+ readonly GUILD_VOICE: ChannelType.GuildVoice;
41
+ readonly GUILD_CATEGORY: ChannelType.GuildCategory;
42
+ readonly GUILD_ANNOUNCEMENT: ChannelType.GuildAnnouncement;
43
+ readonly ANNOUNCEMENT_THREAD: ChannelType.AnnouncementThread;
44
+ readonly PUBLIC_THREAD: ChannelType.PublicThread;
45
+ readonly PRIVATE_THREAD: ChannelType.PrivateThread;
46
+ readonly GUILD_STAGE_VOICE: ChannelType.GuildStageVoice;
47
+ readonly GUILD_FORUM: ChannelType.GuildForum;
48
+ readonly GUILD_MEDIA: ChannelType.GuildMedia;
49
+ };
50
+ /** Resolves either form (already-numeric, or an UPPER_SNAKE_CASE string alias) to the real numeric Discord value. */
51
+ export declare function resolveEnumValue<Map extends Record<string, number>>(map: Map, value: number | keyof Map): number;
52
+ //# sourceMappingURL=enum-maps.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enum-maps.d.ts","sourceRoot":"","sources":["../../../src/commands/schema/enum-maps.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,4BAA4B,EAC5B,sBAAsB,EACtB,0BAA0B,EAC1B,WAAW,EACX,sBAAsB,EACvB,MAAM,uBAAuB,CAAC;AAE/B;;;;;;;GAOG;AACH,eAAO,MAAM,4BAA4B;;;;CAI/B,CAAC;AAEX,eAAO,MAAM,mCAAmC;;;;;;;;;;;;CAYtC,CAAC;AAEX,eAAO,MAAM,4BAA4B;;;;CAI/B,CAAC;AAEX,eAAO,MAAM,gCAAgC;;;CAGnC,CAAC;AAEX,oHAAoH;AACpH,eAAO,MAAM,gBAAgB;;;;;;;;;;;CAWnB,CAAC;AAEX,qHAAqH;AACrH,wBAAgB,gBAAgB,CAAC,GAAG,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,GAAG,MAAM,CAEhH"}
@@ -0,0 +1,54 @@
1
+ import { ApplicationCommandOptionType, ApplicationCommandType, ApplicationIntegrationType, ChannelType, InteractionContextType, } from 'discord-api-types/v10';
2
+ /**
3
+ * UPPER_SNAKE_CASE string aliases for Discord's numeric command/option enums,
4
+ * so commands.json authors don't have to memorize what `3` means. Sourced
5
+ * from discord-api-types' own enums (not hand-duplicated numbers) so these
6
+ * can never drift from the real values. Both the numeric and string form are
7
+ * always valid in commands.json - see `resolveEnumValue` - this is additive,
8
+ * not a replacement, specifically so it never needs to be a breaking change.
9
+ */
10
+ export const APPLICATION_COMMAND_TYPE_MAP = {
11
+ CHAT_INPUT: ApplicationCommandType.ChatInput,
12
+ USER: ApplicationCommandType.User,
13
+ MESSAGE: ApplicationCommandType.Message,
14
+ };
15
+ export const APPLICATION_COMMAND_OPTION_TYPE_MAP = {
16
+ SUBCOMMAND: ApplicationCommandOptionType.Subcommand,
17
+ SUBCOMMAND_GROUP: ApplicationCommandOptionType.SubcommandGroup,
18
+ STRING: ApplicationCommandOptionType.String,
19
+ INTEGER: ApplicationCommandOptionType.Integer,
20
+ BOOLEAN: ApplicationCommandOptionType.Boolean,
21
+ USER: ApplicationCommandOptionType.User,
22
+ CHANNEL: ApplicationCommandOptionType.Channel,
23
+ ROLE: ApplicationCommandOptionType.Role,
24
+ MENTIONABLE: ApplicationCommandOptionType.Mentionable,
25
+ NUMBER: ApplicationCommandOptionType.Number,
26
+ ATTACHMENT: ApplicationCommandOptionType.Attachment,
27
+ };
28
+ export const INTERACTION_CONTEXT_TYPE_MAP = {
29
+ GUILD: InteractionContextType.Guild,
30
+ BOT_DM: InteractionContextType.BotDM,
31
+ PRIVATE_CHANNEL: InteractionContextType.PrivateChannel,
32
+ };
33
+ export const APPLICATION_INTEGRATION_TYPE_MAP = {
34
+ GUILD_INSTALL: ApplicationIntegrationType.GuildInstall,
35
+ USER_INSTALL: ApplicationIntegrationType.UserInstall,
36
+ };
37
+ /** Only the ChannelType subset Discord accepts in an option's channel_types filter - see channel-type.schema.ts. */
38
+ export const CHANNEL_TYPE_MAP = {
39
+ GUILD_TEXT: ChannelType.GuildText,
40
+ GUILD_VOICE: ChannelType.GuildVoice,
41
+ GUILD_CATEGORY: ChannelType.GuildCategory,
42
+ GUILD_ANNOUNCEMENT: ChannelType.GuildAnnouncement,
43
+ ANNOUNCEMENT_THREAD: ChannelType.AnnouncementThread,
44
+ PUBLIC_THREAD: ChannelType.PublicThread,
45
+ PRIVATE_THREAD: ChannelType.PrivateThread,
46
+ GUILD_STAGE_VOICE: ChannelType.GuildStageVoice,
47
+ GUILD_FORUM: ChannelType.GuildForum,
48
+ GUILD_MEDIA: ChannelType.GuildMedia,
49
+ };
50
+ /** Resolves either form (already-numeric, or an UPPER_SNAKE_CASE string alias) to the real numeric Discord value. */
51
+ export function resolveEnumValue(map, value) {
52
+ return typeof value === 'number' ? value : map[value];
53
+ }
54
+ //# sourceMappingURL=enum-maps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enum-maps.js","sourceRoot":"","sources":["../../../src/commands/schema/enum-maps.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,4BAA4B,EAC5B,sBAAsB,EACtB,0BAA0B,EAC1B,WAAW,EACX,sBAAsB,GACvB,MAAM,uBAAuB,CAAC;AAE/B;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG;IAC1C,UAAU,EAAE,sBAAsB,CAAC,SAAS;IAC5C,IAAI,EAAE,sBAAsB,CAAC,IAAI;IACjC,OAAO,EAAE,sBAAsB,CAAC,OAAO;CAC/B,CAAC;AAEX,MAAM,CAAC,MAAM,mCAAmC,GAAG;IACjD,UAAU,EAAE,4BAA4B,CAAC,UAAU;IACnD,gBAAgB,EAAE,4BAA4B,CAAC,eAAe;IAC9D,MAAM,EAAE,4BAA4B,CAAC,MAAM;IAC3C,OAAO,EAAE,4BAA4B,CAAC,OAAO;IAC7C,OAAO,EAAE,4BAA4B,CAAC,OAAO;IAC7C,IAAI,EAAE,4BAA4B,CAAC,IAAI;IACvC,OAAO,EAAE,4BAA4B,CAAC,OAAO;IAC7C,IAAI,EAAE,4BAA4B,CAAC,IAAI;IACvC,WAAW,EAAE,4BAA4B,CAAC,WAAW;IACrD,MAAM,EAAE,4BAA4B,CAAC,MAAM;IAC3C,UAAU,EAAE,4BAA4B,CAAC,UAAU;CAC3C,CAAC;AAEX,MAAM,CAAC,MAAM,4BAA4B,GAAG;IAC1C,KAAK,EAAE,sBAAsB,CAAC,KAAK;IACnC,MAAM,EAAE,sBAAsB,CAAC,KAAK;IACpC,eAAe,EAAE,sBAAsB,CAAC,cAAc;CAC9C,CAAC;AAEX,MAAM,CAAC,MAAM,gCAAgC,GAAG;IAC9C,aAAa,EAAE,0BAA0B,CAAC,YAAY;IACtD,YAAY,EAAE,0BAA0B,CAAC,WAAW;CAC5C,CAAC;AAEX,oHAAoH;AACpH,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,UAAU,EAAE,WAAW,CAAC,SAAS;IACjC,WAAW,EAAE,WAAW,CAAC,UAAU;IACnC,cAAc,EAAE,WAAW,CAAC,aAAa;IACzC,kBAAkB,EAAE,WAAW,CAAC,iBAAiB;IACjD,mBAAmB,EAAE,WAAW,CAAC,kBAAkB;IACnD,aAAa,EAAE,WAAW,CAAC,YAAY;IACvC,cAAc,EAAE,WAAW,CAAC,aAAa;IACzC,iBAAiB,EAAE,WAAW,CAAC,eAAe;IAC9C,WAAW,EAAE,WAAW,CAAC,UAAU;IACnC,WAAW,EAAE,WAAW,CAAC,UAAU;CAC3B,CAAC;AAEX,qHAAqH;AACrH,MAAM,UAAU,gBAAgB,CAAqC,GAAQ,EAAE,KAAyB;IACtG,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AACxD,CAAC"}
@@ -9,6 +9,7 @@ import { applicationCommandTypeSchema } from './application-command-type.schema.
9
9
  import { applicationIntegrationTypeSchema } from './application-integration-type.schema.js';
10
10
  import { channelTypeSchema } from './channel-type.schema.js';
11
11
  import { chatInputCommandSchema } from './chat-input-command.schema.js';
12
+ import { commandFileEntrySchema } from './command-file-entry.schema.js';
12
13
  import { commandsFileSchema } from './commands-file.schema.js';
13
14
  import { contextMenuCommandSchema } from './context-menu-command.schema.js';
14
15
  import { contextMenuNameSchema } from './context-menu-name.schema.js';
@@ -17,11 +18,53 @@ import { interactionContextTypeSchema } from './interaction-context-type.schema.
17
18
  import { optionNameSchema } from './option-name.schema.js';
18
19
  export { parseCommandsFile } from './parse-commands-file.js';
19
20
  export type { ParseCommandsFileOptions } from './parse-commands-file.js';
20
- export { applicationCommandTypeSchema, interactionContextTypeSchema, applicationIntegrationTypeSchema, channelTypeSchema, optionNameSchema, contextMenuNameSchema, applicationCommandOptionChoiceSchema, defaultMemberPermissionsSchema, applicationCommandLeafOptionSchema, applicationCommandSubcommandSchema, applicationCommandSubcommandGroupSchema, applicationCommandOptionSchema, chatInputCommandSchema, contextMenuCommandSchema, commandsFileSchema, };
21
+ export { APPLICATION_COMMAND_TYPE_MAP, APPLICATION_COMMAND_OPTION_TYPE_MAP, INTERACTION_CONTEXT_TYPE_MAP, APPLICATION_INTEGRATION_TYPE_MAP, CHANNEL_TYPE_MAP, resolveEnumValue, } from './enum-maps.js';
22
+ export { applicationCommandTypeSchema, interactionContextTypeSchema, applicationIntegrationTypeSchema, channelTypeSchema, optionNameSchema, contextMenuNameSchema, applicationCommandOptionChoiceSchema, defaultMemberPermissionsSchema, applicationCommandLeafOptionSchema, applicationCommandSubcommandSchema, applicationCommandSubcommandGroupSchema, applicationCommandOptionSchema, chatInputCommandSchema, contextMenuCommandSchema, commandFileEntrySchema, commandsFileSchema, };
23
+ /**
24
+ * Rewrites a bot's own composed commands.schema.json, replacing any `$ref`
25
+ * that points at one of this package's fragments by a relative filesystem
26
+ * path (e.g. `"../node_modules/@went.tf/discord-bot-framework/build/commands/schema/chat-input-command.json"` -
27
+ * the form an editor can resolve for autocomplete) with that fragment's
28
+ * canonical `$id` (the form `registerFrameworkSchemas` registers, which ajv
29
+ * can actually resolve). Matched by filename alone, so it works regardless
30
+ * of how deep your own commands.schema.json sits relative to `node_modules`
31
+ * - you never need to get the exact `../` count "right" for ajv's sake, only
32
+ * for the editor's. `$ref`s that don't match a known fragment filename (e.g.
33
+ * your own `#/$defs/...` refs) are left untouched.
34
+ *
35
+ * Call this on the raw parsed schema before `ajv.compile()`, after
36
+ * `registerFrameworkSchemas(ajv)`:
37
+ *
38
+ * ```ts
39
+ * import myCommandsSchemaRaw from './commands.schema.json' with { type: 'json' };
40
+ * const myCommandsSchema = resolveCommandsSchemaRefs(myCommandsSchemaRaw);
41
+ * registerFrameworkSchemas(ajv);
42
+ * const validate = ajv.compile(myCommandsSchema);
43
+ * ```
44
+ */
45
+ export declare function resolveCommandsSchemaRefs<T>(schema: T): T;
21
46
  /**
22
47
  * Registers every generic fragment this package ships onto a bot's own ajv
23
- * instance, so the bot's own composed commands.schema.json can `$ref` them
24
- * by `$id`. Call this before `ajv.compile()`-ing the bot's own schema.
48
+ * instance under its canonical `$id`, so the framework's own fragments can
49
+ * `$ref` each other. Call this before `ajv.compile()`-ing the bot's own
50
+ * schema, after passing that schema through `resolveCommandsSchemaRefs()`.
51
+ *
52
+ * A fragment's `$id` (e.g. `https://schema.went.tf/discord-bot-framework/chat-input-command.json`)
53
+ * is an opaque, never-fetched identifier - not a real filesystem location -
54
+ * so it's not something an editor (VS Code, JetBrains, ...) can resolve for
55
+ * autocomplete while you hand-edit commands.schema.json, and not something
56
+ * this package tries to make ajv resolve via real filesystem/URI math either
57
+ * (an earlier version of this function tried registering fragments under
58
+ * their real `file://` location for that purpose; confirmed broken for every
59
+ * pnpm install, not just local dev, because pnpm always symlinks packages
60
+ * from its `.pnpm` virtual store into `node_modules`, and Node's ESM loader
61
+ * resolves `import.meta.url` through that symlink to the real store path -
62
+ * a path a bot's own relative `$ref` can never independently compute).
63
+ * `resolveCommandsSchemaRefs()` is the actual fix: it rewrites a bot's own
64
+ * relative-path `$ref`s to the matching fragment's canonical `$id` by
65
+ * filename, sidestepping filesystem resolution for ajv entirely while
66
+ * leaving the human-facing JSON file itself untouched (still relative paths,
67
+ * for the editor).
25
68
  */
26
69
  export declare function registerFrameworkSchemas(ajv: Ajv): void;
27
70
  export type ApplicationCommandOptionChoice = FromSchema<typeof applicationCommandOptionChoiceSchema>;
@@ -72,6 +115,17 @@ export type CommandFileEntry = ChatInputCommandFileEntry | ContextMenuCommandFil
72
115
  * during implementation. `commandsFileSchema` itself remains the runtime
73
116
  * source of truth for ajv validation; only its *type* derivation is composed
74
117
  * this way.
118
+ *
119
+ * Either root shape `commandsFileSchema` accepts: a bare array (unchanged
120
+ * since the first release of this format), or that array wrapped as
121
+ * `{ $schema?, commands }` so the file's root is an object and can carry a
122
+ * real inline `$schema` property for editor autocomplete/validation - a bare
123
+ * JSON array can never do that, `$schema` is only ever valid on an object.
75
124
  */
76
- export type CommandsFile = readonly CommandFileEntry[];
125
+ export type CommandsFile = readonly CommandFileEntry[] | {
126
+ $schema?: string;
127
+ commands: readonly CommandFileEntry[];
128
+ };
129
+ /** Normalizes either `CommandsFile` root shape down to the flat entries array. */
130
+ export declare function getCommandsFileEntries(commandsFile: CommandsFile): readonly CommandFileEntry[];
77
131
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/commands/schema/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAC/B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,kCAAkC,EAAE,MAAM,6CAA6C,CAAC;AACjG,OAAO,EAAE,oCAAoC,EAAE,MAAM,+CAA+C,CAAC;AACrG,OAAO,EAAE,8BAA8B,EAAE,MAAM,wCAAwC,CAAC;AACxF,OAAO,EAAE,uCAAuC,EAAE,MAAM,kDAAkD,CAAC;AAC3G,OAAO,EAAE,kCAAkC,EAAE,MAAM,4CAA4C,CAAC;AAChG,OAAO,EAAE,4BAA4B,EAAE,MAAM,sCAAsC,CAAC;AACpF,OAAO,EAAE,gCAAgC,EAAE,MAAM,0CAA0C,CAAC;AAC5F,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AACxE,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,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