@went.tf/discord-bot-framework 2.1.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.
@@ -1,7 +1,7 @@
1
1
  import { RESTPostAPIApplicationCommandsJSONBody } from 'discord-api-types/v10';
2
2
  import { NamedChatInputCommand, NamedContextMenuCommand, Registry } from '../interactions/registry.js';
3
3
  import { BaseInteractionContext } from '../interactions/types.js';
4
- import { CommandFileEntry } from './schema/index.js';
4
+ import { CommandsFile } from './schema/index.js';
5
5
  export type DescriptionResolver = (path: readonly string[]) => string | undefined;
6
6
  export type LocalizationResolver = (path: readonly string[]) => Record<string, string> | undefined;
7
7
  export interface BuildApplicationCommandsBodyOptions {
@@ -30,6 +30,11 @@ export interface BuildApplicationCommandsBodyRegistries<Ctx extends BaseInteract
30
30
  * expects from a validated commands.json array plus the bot's handler registries.
31
31
  * `commandsFile`'s own order drives the output order (not registry insertion order).
32
32
  *
33
+ * Accepts either root shape `commandsFileSchema` allows: a bare array, or that
34
+ * array wrapped as `{ $schema?, commands }` (the form that lets `commands.json`
35
+ * carry a real inline `$schema` property for editor autocomplete, since a bare
36
+ * array can't).
37
+ *
33
38
  * `type`/`contexts`/`integration_types`/`channel_types` may be authored in
34
39
  * commands.json as either Discord's raw numeric values or the friendlier
35
40
  * UPPER_SNAKE_CASE string aliases from `./schema/enum-maps.ts` - both forms
@@ -41,5 +46,5 @@ export interface BuildApplicationCommandsBodyRegistries<Ctx extends BaseInteract
41
46
  * every offender, same as a command/option left with no resolvable description. This
42
47
  * never silently sends an incomplete body to Discord's API.
43
48
  */
44
- export declare function buildApplicationCommandsBody<Ctx extends BaseInteractionContext>(commandsFile: readonly CommandFileEntry[], registries: BuildApplicationCommandsBodyRegistries<Ctx>, options?: BuildApplicationCommandsBodyOptions): RESTPostAPIApplicationCommandsJSONBody[];
49
+ export declare function buildApplicationCommandsBody<Ctx extends BaseInteractionContext>(commandsFileInput: CommandsFile, registries: BuildApplicationCommandsBodyRegistries<Ctx>, options?: BuildApplicationCommandsBodyOptions): RESTPostAPIApplicationCommandsJSONBody[];
45
50
  //# sourceMappingURL=build-application-commands-body.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"build-application-commands-body.d.ts","sourceRoot":"","sources":["../../src/commands/build-application-commands-body.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+B,sCAAsC,EAAE,MAAM,uBAAuB,CAAC;AAC5G,OAAO,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvG,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AASlE,OAAO,EAAuD,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAE1G,MAAM,MAAM,mBAAmB,GAAG,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,KAAK,MAAM,GAAG,SAAS,CAAC;AAClF,MAAM,MAAM,oBAAoB,GAAG,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,KAAK,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC;AAEnG,MAAM,WAAW,mCAAmC;IAClD,qFAAqF;IACrF,cAAc,CAAC,EAAE,OAAO,CAAC,sCAAsC,CAAC,CAAC;IACjE;;;;;;;OAOG;IACH,kBAAkB,CAAC,EAAE,mBAAmB,CAAC;IACzC,yFAAyF;IACzF,aAAa,CAAC,EAAE,oBAAoB,CAAC;IACrC,yFAAyF;IACzF,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;CAC7C;AAED,MAAM,WAAW,sCAAsC,CACrD,GAAG,SAAS,sBAAsB,EAClC,aAAa,SAAS,MAAM,GAAG,MAAM,EACrC,eAAe,SAAS,MAAM,GAAG,MAAM;IAEvC,SAAS,CAAC,EAAE,QAAQ,CAAC,aAAa,EAAE,qBAAqB,CAAC,GAAG,EAAE,aAAa,CAAC,CAAC,CAAC;IAC/E,WAAW,CAAC,EAAE,QAAQ,CAAC,eAAe,EAAE,uBAAuB,CAAC,GAAG,EAAE,eAAe,CAAC,CAAC,CAAC;CACxF;AAoFD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,4BAA4B,CAAC,GAAG,SAAS,sBAAsB,EAC7E,YAAY,EAAE,SAAS,gBAAgB,EAAE,EACzC,UAAU,EAAE,sCAAsC,CAAC,GAAG,CAAC,EACvD,OAAO,GAAE,mCAAwC,GAChD,sCAAsC,EAAE,CAoF1C"}
1
+ {"version":3,"file":"build-application-commands-body.d.ts","sourceRoot":"","sources":["../../src/commands/build-application-commands-body.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+B,sCAAsC,EAAE,MAAM,uBAAuB,CAAC;AAC5G,OAAO,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvG,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AASlE,OAAO,EAAuD,YAAY,EAA0B,MAAM,mBAAmB,CAAC;AAE9H,MAAM,MAAM,mBAAmB,GAAG,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,KAAK,MAAM,GAAG,SAAS,CAAC;AAClF,MAAM,MAAM,oBAAoB,GAAG,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,KAAK,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC;AAEnG,MAAM,WAAW,mCAAmC;IAClD,qFAAqF;IACrF,cAAc,CAAC,EAAE,OAAO,CAAC,sCAAsC,CAAC,CAAC;IACjE;;;;;;;OAOG;IACH,kBAAkB,CAAC,EAAE,mBAAmB,CAAC;IACzC,yFAAyF;IACzF,aAAa,CAAC,EAAE,oBAAoB,CAAC;IACrC,yFAAyF;IACzF,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;CAC7C;AAED,MAAM,WAAW,sCAAsC,CACrD,GAAG,SAAS,sBAAsB,EAClC,aAAa,SAAS,MAAM,GAAG,MAAM,EACrC,eAAe,SAAS,MAAM,GAAG,MAAM;IAEvC,SAAS,CAAC,EAAE,QAAQ,CAAC,aAAa,EAAE,qBAAqB,CAAC,GAAG,EAAE,aAAa,CAAC,CAAC,CAAC;IAC/E,WAAW,CAAC,EAAE,QAAQ,CAAC,eAAe,EAAE,uBAAuB,CAAC,GAAG,EAAE,eAAe,CAAC,CAAC,CAAC;CACxF;AAoFD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,4BAA4B,CAAC,GAAG,SAAS,sBAAsB,EAC7E,iBAAiB,EAAE,YAAY,EAC/B,UAAU,EAAE,sCAAsC,CAAC,GAAG,CAAC,EACvD,OAAO,GAAE,mCAAwC,GAChD,sCAAsC,EAAE,CAqF1C"}
@@ -1,4 +1,5 @@
1
1
  import { APPLICATION_COMMAND_OPTION_TYPE_MAP, APPLICATION_COMMAND_TYPE_MAP, APPLICATION_INTEGRATION_TYPE_MAP, CHANNEL_TYPE_MAP, INTERACTION_CONTEXT_TYPE_MAP, resolveEnumValue, } from './schema/enum-maps.js';
2
+ import { getCommandsFileEntries } from './schema/index.js';
2
3
  /**
3
4
  * True for both the numeric (`1`) and UPPER_SNAKE_CASE string (`'CHAT_INPUT'`)
4
5
  * form of a commands.json entry's `type` - commands.json accepts either, see
@@ -67,6 +68,11 @@ function formatValidationErrors(unmatchedFileEntries, unmatchedHandlers, missing
67
68
  * expects from a validated commands.json array plus the bot's handler registries.
68
69
  * `commandsFile`'s own order drives the output order (not registry insertion order).
69
70
  *
71
+ * Accepts either root shape `commandsFileSchema` allows: a bare array, or that
72
+ * array wrapped as `{ $schema?, commands }` (the form that lets `commands.json`
73
+ * carry a real inline `$schema` property for editor autocomplete, since a bare
74
+ * array can't).
75
+ *
70
76
  * `type`/`contexts`/`integration_types`/`channel_types` may be authored in
71
77
  * commands.json as either Discord's raw numeric values or the friendlier
72
78
  * UPPER_SNAKE_CASE string aliases from `./schema/enum-maps.ts` - both forms
@@ -78,8 +84,9 @@ function formatValidationErrors(unmatchedFileEntries, unmatchedHandlers, missing
78
84
  * every offender, same as a command/option left with no resolvable description. This
79
85
  * never silently sends an incomplete body to Discord's API.
80
86
  */
81
- export function buildApplicationCommandsBody(commandsFile, registries, options = {}) {
87
+ export function buildApplicationCommandsBody(commandsFileInput, registries, options = {}) {
82
88
  const { sharedMetadata = {}, resolveDescription, localizeNames, localizeDescriptions } = options;
89
+ const commandsFile = getCommandsFileEntries(commandsFileInput);
83
90
  const body = [];
84
91
  const unmatchedFileEntries = [];
85
92
  const missingDescriptions = [];
@@ -1 +1 @@
1
- {"version":3,"file":"build-application-commands-body.js","sourceRoot":"","sources":["../../src/commands/build-application-commands-body.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,mCAAmC,EACnC,4BAA4B,EAC5B,gCAAgC,EAChC,gBAAgB,EAChB,4BAA4B,EAC5B,gBAAgB,GACjB,MAAM,uBAAuB,CAAC;AAiC/B;;;;;GAKG;AACH,SAAS,eAAe,CAAC,IAAa;IACpC,OAAO,IAAI,KAAK,4BAA4B,CAAC,UAAU,IAAI,IAAI,KAAK,YAAY,CAAC;AACnF,CAAC;AAED,SAAS,wBAAwB,CAAC,OAAkD;IAClF,IAAI,CAAC,OAAO;QAAE,OAAO,OAAO,CAAC;IAC7B,OAAO,CAAC,GAAG,OAAO,CAAC;SAChB,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,UAAU,IAAI,CAAC,IAAI,CAAC,CAAC,QAAQ,KAAK,IAAI,CAAC,GAAG,MAAM,CAAC,UAAU,IAAI,CAAC,IAAI,CAAC,CAAC,QAAQ,KAAK,IAAI,CAAC,CAAC;SAC/G,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;QACd,IAAI,SAAS,IAAI,MAAM,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;YAC1C,OAAO,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,wBAAwB,CAAC,MAAM,CAAC,OAAO,CAAC,EAAiC,CAAC;QACzG,CAAC;QACD,OAAO,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C,EAAE,CAAC;aAC9B,CAAC,CAAC;QAC/C,CAAC;IACH,CAAC;IAED,MAAM,iBAAiB,GAAa,EAAE,CAAC;IACvC,KAAK,MAAM,IAAI,IAAI,UAAU,CAAC,SAAS,EAAE,KAAK,IAAI,EAAE,EAAE,CAAC;QACrD,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,IAAI,CAAC;YAAE,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAClE,CAAC;IACD,KAAK,MAAM,IAAI,IAAI,UAAU,CAAC,WAAW,EAAE,KAAK,IAAI,EAAE,EAAE,CAAC;QACvD,IAAI,CAAC,oBAAoB,CAAC,GAAG,CAAC,IAAI,CAAC;YAAE,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACpE,CAAC;IAED,IAAI,oBAAoB,CAAC,MAAM,IAAI,iBAAiB,CAAC,MAAM,IAAI,mBAAmB,CAAC,MAAM,EAAE,CAAC;QAC1F,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,oBAAoB,EAAE,iBAAiB,EAAE,mBAAmB,CAAC,CAAC,CAAC;IACxG,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
1
+ {"version":3,"file":"build-application-commands-body.js","sourceRoot":"","sources":["../../src/commands/build-application-commands-body.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,mCAAmC,EACnC,4BAA4B,EAC5B,gCAAgC,EAChC,gBAAgB,EAChB,4BAA4B,EAC5B,gBAAgB,GACjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAqE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAgC9H;;;;;GAKG;AACH,SAAS,eAAe,CAAC,IAAa;IACpC,OAAO,IAAI,KAAK,4BAA4B,CAAC,UAAU,IAAI,IAAI,KAAK,YAAY,CAAC;AACnF,CAAC;AAED,SAAS,wBAAwB,CAAC,OAAkD;IAClF,IAAI,CAAC,OAAO;QAAE,OAAO,OAAO,CAAC;IAC7B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AAC,CAAC,CAAC;IACxG,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -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
  }
@@ -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';
@@ -18,11 +19,52 @@ 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
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';
21
- export { applicationCommandTypeSchema, interactionContextTypeSchema, applicationIntegrationTypeSchema, channelTypeSchema, optionNameSchema, contextMenuNameSchema, applicationCommandOptionChoiceSchema, defaultMemberPermissionsSchema, applicationCommandLeafOptionSchema, applicationCommandSubcommandSchema, applicationCommandSubcommandGroupSchema, applicationCommandOptionSchema, chatInputCommandSchema, contextMenuCommandSchema, commandsFileSchema, };
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;
22
46
  /**
23
47
  * Registers every generic fragment this package ships onto a bot's own ajv
24
- * instance, so the bot's own composed commands.schema.json can `$ref` them
25
- * 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).
26
68
  */
27
69
  export declare function registerFrameworkSchemas(ajv: Ajv): void;
28
70
  export type ApplicationCommandOptionChoice = FromSchema<typeof applicationCommandOptionChoiceSchema>;
@@ -73,6 +115,17 @@ export type CommandFileEntry = ChatInputCommandFileEntry | ContextMenuCommandFil
73
115
  * during implementation. `commandsFileSchema` itself remains the runtime
74
116
  * source of truth for ajv validation; only its *type* derivation is composed
75
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.
76
124
  */
77
- 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[];
78
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,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAE,8BAA8B,EAAE,MAAM,wCAAwC,CAAC;AACxF,OAAO,EAAE,4BAA4B,EAAE,MAAM,sCAAsC,CAAC;AACpF,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAE3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,YAAY,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AAEzE,OAAO,EACL,4BAA4B,EAC5B,mCAAmC,EACnC,4BAA4B,EAC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AAO,gCAAgC,CAAC,CAAA;CAAE,CACpK,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,yBAAyB,GAAG,2BAA2B,CAAC;AAEvF;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,YAAY,GAAG,SAAS,gBAAgB,EAAE,GAAG;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,SAAS,gBAAgB,EAAE,CAAA;CAAE,CAAC;AAErH,kFAAkF;AAClF,wBAAgB,sBAAsB,CAAC,YAAY,EAAE,YAAY,GAAG,SAAS,gBAAgB,EAAE,CAK9F"}
@@ -7,6 +7,7 @@ import { applicationCommandTypeSchema } from './application-command-type.schema.
7
7
  import { applicationIntegrationTypeSchema } from './application-integration-type.schema.js';
8
8
  import { channelTypeSchema } from './channel-type.schema.js';
9
9
  import { chatInputCommandSchema } from './chat-input-command.schema.js';
10
+ import { commandFileEntrySchema } from './command-file-entry.schema.js';
10
11
  import { commandsFileSchema } from './commands-file.schema.js';
11
12
  import { contextMenuCommandSchema } from './context-menu-command.schema.js';
12
13
  import { contextMenuNameSchema } from './context-menu-name.schema.js';
@@ -15,7 +16,7 @@ import { interactionContextTypeSchema } from './interaction-context-type.schema.
15
16
  import { optionNameSchema } from './option-name.schema.js';
16
17
  export { parseCommandsFile } from './parse-commands-file.js';
17
18
  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';
18
- export { applicationCommandTypeSchema, interactionContextTypeSchema, applicationIntegrationTypeSchema, channelTypeSchema, optionNameSchema, contextMenuNameSchema, applicationCommandOptionChoiceSchema, defaultMemberPermissionsSchema, applicationCommandLeafOptionSchema, applicationCommandSubcommandSchema, applicationCommandSubcommandGroupSchema, applicationCommandOptionSchema, chatInputCommandSchema, contextMenuCommandSchema, commandsFileSchema, };
19
+ export { applicationCommandTypeSchema, interactionContextTypeSchema, applicationIntegrationTypeSchema, channelTypeSchema, optionNameSchema, contextMenuNameSchema, applicationCommandOptionChoiceSchema, defaultMemberPermissionsSchema, applicationCommandLeafOptionSchema, applicationCommandSubcommandSchema, applicationCommandSubcommandGroupSchema, applicationCommandOptionSchema, chatInputCommandSchema, contextMenuCommandSchema, commandFileEntrySchema, commandsFileSchema, };
19
20
  /** Every fragment this package ships, in an order safe to `ajv.addSchema()` sequentially. */
20
21
  const frameworkSchemas = [
21
22
  applicationCommandTypeSchema,
@@ -32,12 +33,76 @@ const frameworkSchemas = [
32
33
  applicationCommandOptionSchema,
33
34
  chatInputCommandSchema,
34
35
  contextMenuCommandSchema,
36
+ commandFileEntrySchema,
35
37
  commandsFileSchema,
36
38
  ];
39
+ const fragmentIdByFileName = new Map(frameworkSchemas.map((s) => [s.$id.split('/').pop(), s.$id]));
40
+ /**
41
+ * Rewrites a bot's own composed commands.schema.json, replacing any `$ref`
42
+ * that points at one of this package's fragments by a relative filesystem
43
+ * path (e.g. `"../node_modules/@went.tf/discord-bot-framework/build/commands/schema/chat-input-command.json"` -
44
+ * the form an editor can resolve for autocomplete) with that fragment's
45
+ * canonical `$id` (the form `registerFrameworkSchemas` registers, which ajv
46
+ * can actually resolve). Matched by filename alone, so it works regardless
47
+ * of how deep your own commands.schema.json sits relative to `node_modules`
48
+ * - you never need to get the exact `../` count "right" for ajv's sake, only
49
+ * for the editor's. `$ref`s that don't match a known fragment filename (e.g.
50
+ * your own `#/$defs/...` refs) are left untouched.
51
+ *
52
+ * Call this on the raw parsed schema before `ajv.compile()`, after
53
+ * `registerFrameworkSchemas(ajv)`:
54
+ *
55
+ * ```ts
56
+ * import myCommandsSchemaRaw from './commands.schema.json' with { type: 'json' };
57
+ * const myCommandsSchema = resolveCommandsSchemaRefs(myCommandsSchemaRaw);
58
+ * registerFrameworkSchemas(ajv);
59
+ * const validate = ajv.compile(myCommandsSchema);
60
+ * ```
61
+ */
62
+ export function resolveCommandsSchemaRefs(schema) {
63
+ return rewriteRefs(schema);
64
+ }
65
+ function rewriteRefs(node) {
66
+ if (Array.isArray(node)) {
67
+ return node.map(rewriteRefs);
68
+ }
69
+ if (node !== null && typeof node === 'object') {
70
+ const result = {};
71
+ for (const [key, value] of Object.entries(node)) {
72
+ if (key === '$ref' && typeof value === 'string') {
73
+ const fileName = value.split('/').pop();
74
+ result[key] = fragmentIdByFileName.get(fileName) ?? value;
75
+ }
76
+ else {
77
+ result[key] = rewriteRefs(value);
78
+ }
79
+ }
80
+ return result;
81
+ }
82
+ return node;
83
+ }
37
84
  /**
38
85
  * Registers every generic fragment this package ships onto a bot's own ajv
39
- * instance, so the bot's own composed commands.schema.json can `$ref` them
40
- * by `$id`. Call this before `ajv.compile()`-ing the bot's own schema.
86
+ * instance under its canonical `$id`, so the framework's own fragments can
87
+ * `$ref` each other. Call this before `ajv.compile()`-ing the bot's own
88
+ * schema, after passing that schema through `resolveCommandsSchemaRefs()`.
89
+ *
90
+ * A fragment's `$id` (e.g. `https://schema.went.tf/discord-bot-framework/chat-input-command.json`)
91
+ * is an opaque, never-fetched identifier - not a real filesystem location -
92
+ * so it's not something an editor (VS Code, JetBrains, ...) can resolve for
93
+ * autocomplete while you hand-edit commands.schema.json, and not something
94
+ * this package tries to make ajv resolve via real filesystem/URI math either
95
+ * (an earlier version of this function tried registering fragments under
96
+ * their real `file://` location for that purpose; confirmed broken for every
97
+ * pnpm install, not just local dev, because pnpm always symlinks packages
98
+ * from its `.pnpm` virtual store into `node_modules`, and Node's ESM loader
99
+ * resolves `import.meta.url` through that symlink to the real store path -
100
+ * a path a bot's own relative `$ref` can never independently compute).
101
+ * `resolveCommandsSchemaRefs()` is the actual fix: it rewrites a bot's own
102
+ * relative-path `$ref`s to the matching fragment's canonical `$id` by
103
+ * filename, sidestepping filesystem resolution for ajv entirely while
104
+ * leaving the human-facing JSON file itself untouched (still relative paths,
105
+ * for the editor).
41
106
  */
42
107
  export function registerFrameworkSchemas(ajv) {
43
108
  for (const schema of frameworkSchemas) {
@@ -46,4 +111,11 @@ export function registerFrameworkSchemas(ajv) {
46
111
  }
47
112
  }
48
113
  }
114
+ /** Normalizes either `CommandsFile` root shape down to the flat entries array. */
115
+ export function getCommandsFileEntries(commandsFile) {
116
+ if (Array.isArray(commandsFile)) {
117
+ return commandsFile;
118
+ }
119
+ return commandsFile.commands;
120
+ }
49
121
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/commands/schema/index.ts"],"names":[],"mappings":"AAEA,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,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAE,8BAA8B,EAAE,MAAM,wCAAwC,CAAC;AACxF,OAAO,EAAE,4BAA4B,EAAE,MAAM,sCAAsC,CAAC;AACpF,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAE3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAG7D,OAAO,EACL,4BAA4B,EAC5B,mCAAmC,EACnC,4BAA4B,EAC5B,gCAAgC,EAChC,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,4BAA4B,EAC5B,4BAA4B,EAC5B,gCAAgC,EAChC,iBAAiB,EACjB,gBAAgB,EAChB,qBAAqB,EACrB,oCAAoC,EACpC,8BAA8B,EAC9B,kCAAkC,EAClC,kCAAkC,EAClC,uCAAuC,EACvC,8BAA8B,EAC9B,sBAAsB,EACtB,wBAAwB,EACxB,kBAAkB,GACnB,CAAC;AAEF,6FAA6F;AAC7F,MAAM,gBAAgB,GAAG;IACvB,4BAA4B;IAC5B,4BAA4B;IAC5B,gCAAgC;IAChC,iBAAiB;IACjB,gBAAgB;IAChB,qBAAqB;IACrB,oCAAoC;IACpC,8BAA8B;IAC9B,kCAAkC;IAClC,kCAAkC;IAClC,uCAAuC;IACvC,8BAA8B;IAC9B,sBAAsB;IACtB,wBAAwB;IACxB,kBAAkB;CACV,CAAC;AAEX;;;;GAIG;AACH,MAAM,UAAU,wBAAwB,CAAC,GAAQ;IAC/C,KAAK,MAAM,MAAM,IAAI,gBAAgB,EAAE,CAAC;QACtC,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;YAC/B,GAAG,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QACxB,CAAC;IACH,CAAC;AACH,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/commands/schema/index.ts"],"names":[],"mappings":"AAEA,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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AI,CAAC;AACd,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,wBAAwB,CAAC,GAAQ;IAC/C,KAAK,MAAM,MAAM,IAAI,gBAAgB,EAAE,CAAC;QACtC,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;YAC/B,GAAG,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QACxB,CAAC;IACH,CAAC;AACH,CAAC;AA2ED,kFAAkF;AAClF,MAAM,UAAU,sBAAsB,CAAC,YAA0B;IAC/D,IAAI,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,CAAC;QAChC,OAAO,YAA2C,CAAC;IACrD,CAAC;IACD,OAAQ,YAA0D,CAAC,QAAQ,CAAC;AAC9E,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@went.tf/discord-bot-framework",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "description": "Shared framework for building Discord bots with discord.js: logging, env validation, interaction dispatch, API client, and optional Postgres/i18next helpers",
5
5
  "author": "WentTheFox <mail@went.tf> (https://github.com/WentTheFox)",
6
6
  "license": "MIT",