calabasas 0.3.2 → 0.3.4

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/config.d.ts CHANGED
@@ -9,12 +9,32 @@ export type SyncConfig = {
9
9
  };
10
10
 
11
11
  export type EventConfig = {
12
- [eventType: string]: true | string[];
12
+ [eventType: string]: true;
13
+ };
14
+
15
+ export type CommandOptionType = "string" | "integer" | "number" | "boolean" | "user" | "channel" | "role" | "mentionable" | "attachment";
16
+
17
+ export type CommandOption = {
18
+ name: string;
19
+ description: string;
20
+ type: CommandOptionType;
21
+ required?: boolean;
22
+ choices?: Array<{ name: string; value: string | number }>;
23
+ autocomplete?: boolean;
24
+ };
25
+
26
+ export type CommandDefinition = {
27
+ description: string;
28
+ options?: CommandOption[];
29
+ subcommands?: Record<string, { description: string; options?: CommandOption[] }>;
30
+ defaultMemberPermissions?: string;
31
+ dmPermission?: boolean;
13
32
  };
14
33
 
15
34
  export type CalabasasConfig = {
16
35
  sync?: SyncConfig;
17
36
  events?: EventConfig;
37
+ commands?: Record<string, CommandDefinition>;
18
38
  };
19
39
 
20
40
  /**
@@ -30,7 +50,20 @@ export type CalabasasConfig = {
30
50
  * channels: true,
31
51
  * },
32
52
  * events: {
33
- * messageCreate: ["id", "content", "author"],
53
+ * messageCreate: true,
54
+ * interactionCreate: true,
55
+ * },
56
+ * commands: {
57
+ * ping: {
58
+ * description: "Check bot latency",
59
+ * },
60
+ * ban: {
61
+ * description: "Ban a user",
62
+ * options: [
63
+ * { name: "user", type: "user", description: "User to ban", required: true },
64
+ * { name: "reason", type: "string", description: "Ban reason" },
65
+ * ],
66
+ * },
34
67
  * },
35
68
  * });
36
69
  * ```
package/dist/index.js CHANGED
@@ -3146,10 +3146,73 @@ function validatorToType(validator) {
3146
3146
  }
3147
3147
  return "unknown";
3148
3148
  }
3149
- function generateHandlersCode(eventNames) {
3150
- const screamingEvents = eventNames.map(toScreamingSnake);
3151
- const hasInteraction = eventNames.includes("interactionCreate");
3152
- const interactionResponseTypes = hasInteraction ? `
3149
+ function generateInteractionTypes() {
3150
+ return `
3151
+ // Interaction data types — discriminated by interaction type
3152
+ export type ApplicationCommandOption = {
3153
+ name: string;
3154
+ type: number;
3155
+ value?: string | number | boolean;
3156
+ options?: ApplicationCommandOption[];
3157
+ focused?: boolean;
3158
+ };
3159
+
3160
+ /** Data for slash commands, user commands, and message commands (type 2) */
3161
+ export type ApplicationCommandData = {
3162
+ id: string;
3163
+ name: string;
3164
+ type: 1 | 2 | 3;
3165
+ options?: ApplicationCommandOption[];
3166
+ resolved?: Record<string, unknown>;
3167
+ guildId?: string;
3168
+ targetId?: string;
3169
+ };
3170
+
3171
+ /** Data for buttons, select menus, and other message components (type 3) */
3172
+ export type MessageComponentData = {
3173
+ custom_id: string;
3174
+ component_type: number;
3175
+ values?: string[];
3176
+ resolved?: Record<string, unknown>;
3177
+ };
3178
+
3179
+ /** Data for autocomplete interactions (type 4) */
3180
+ export type AutocompleteData = {
3181
+ id: string;
3182
+ name: string;
3183
+ type: 1 | 2 | 3;
3184
+ options?: ApplicationCommandOption[];
3185
+ };
3186
+
3187
+ /** Data for modal form submissions (type 5) */
3188
+ export type ModalSubmitData = {
3189
+ custom_id: string;
3190
+ components: Array<{
3191
+ type: number;
3192
+ components: Array<{
3193
+ type: number;
3194
+ custom_id: string;
3195
+ value: string;
3196
+ }>;
3197
+ }>;
3198
+ };
3199
+
3200
+ type InteractionBase = {
3201
+ id: string;
3202
+ applicationId: string;
3203
+ guildId?: string;
3204
+ channelId?: string;
3205
+ member?: Record<string, unknown>;
3206
+ user?: { id: string; username: string; discriminator: string; avatar?: string };
3207
+ token: string;
3208
+ };
3209
+
3210
+ export type InteractionCreateEvent =
3211
+ | (InteractionBase & { type: 2; data: ApplicationCommandData })
3212
+ | (InteractionBase & { type: 3; data: MessageComponentData })
3213
+ | (InteractionBase & { type: 4; data: AutocompleteData })
3214
+ | (InteractionBase & { type: 5; data: ModalSubmitData });
3215
+
3153
3216
  // Interaction response types
3154
3217
  export type InteractionResponse = {
3155
3218
  content?: string;
@@ -3162,7 +3225,12 @@ export type InteractionResponse = {
3162
3225
  export type AutocompleteResponse = {
3163
3226
  choices: Array<{ name: string; value: string | number }>;
3164
3227
  };
3165
- ` : "";
3228
+ `;
3229
+ }
3230
+ function generateHandlersCode(eventNames) {
3231
+ const screamingEvents = eventNames.map(toScreamingSnake);
3232
+ const hasInteraction = eventNames.includes("interactionCreate");
3233
+ const interactionResponseTypes = hasInteraction ? generateInteractionTypes() : "";
3166
3234
  const handlerReturnType = (name) => {
3167
3235
  if (name === "interactionCreate") {
3168
3236
  return `Promise<InteractionResponse | AutocompleteResponse | void>`;
@@ -3203,7 +3271,7 @@ ${eventNames.map((name) => `const ${name}Validator = ${generateValidatorForEvent
3203
3271
  `)}
3204
3272
 
3205
3273
  // Event type definitions
3206
- ${eventNames.map((name) => `export type ${name.charAt(0).toUpperCase() + name.slice(1)}Event = ${generateTypeForEvent(name)};`).join(`
3274
+ ${eventNames.filter((name) => name !== "interactionCreate").map((name) => `export type ${name.charAt(0).toUpperCase() + name.slice(1)}Event = ${generateTypeForEvent(name)};`).join(`
3207
3275
 
3208
3276
  `)}
3209
3277
  ${interactionResponseTypes}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "calabasas",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
4
4
  "description": "CLI for Calabasas - Discord Gateway as a Service for Convex",
5
5
  "type": "module",
6
6
  "bin": {