bakit 2.0.0-alpha.8 → 2.0.0-alpha.9

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/index.d.ts CHANGED
@@ -109,54 +109,27 @@ declare const BaseParamSchema: z.ZodObject<{
109
109
  description: z.ZodOptional<z.ZodString>;
110
110
  required: z.ZodDefault<z.ZodBoolean>;
111
111
  }, z.core.$strip>;
112
- declare const StringParamSchema: z.ZodPipe<z.ZodObject<{
112
+ declare const StringParamSchema: z.ZodObject<{
113
113
  name: z.ZodString;
114
114
  description: z.ZodOptional<z.ZodString>;
115
115
  required: z.ZodDefault<z.ZodBoolean>;
116
116
  maxLength: z.ZodOptional<z.ZodNumber>;
117
117
  minLength: z.ZodOptional<z.ZodNumber>;
118
- }, z.core.$strip>, z.ZodTransform<{
119
- name: string;
120
- required: boolean;
121
- description?: string | undefined;
122
- maxLength?: number | undefined;
123
- minLength?: number | undefined;
124
- } & {
125
- description: string;
126
- }, {
127
- name: string;
128
- required: boolean;
129
- description?: string | undefined;
130
- maxLength?: number | undefined;
131
- minLength?: number | undefined;
132
- }>>;
133
- declare const NumberParamSchema: z.ZodPipe<z.ZodObject<{
118
+ }, z.core.$strip>;
119
+ declare const NumberParamSchema: z.ZodObject<{
134
120
  name: z.ZodString;
135
121
  description: z.ZodOptional<z.ZodString>;
136
122
  required: z.ZodDefault<z.ZodBoolean>;
137
123
  maxValue: z.ZodOptional<z.ZodNumber>;
138
124
  minValue: z.ZodOptional<z.ZodNumber>;
139
- }, z.core.$strip>, z.ZodTransform<{
140
- name: string;
141
- required: boolean;
142
- description?: string | undefined;
143
- maxValue?: number | undefined;
144
- minValue?: number | undefined;
145
- } & {
146
- description: string;
147
- }, {
148
- name: string;
149
- required: boolean;
150
- description?: string | undefined;
151
- maxValue?: number | undefined;
152
- minValue?: number | undefined;
153
- }>>;
125
+ }, z.core.$strip>;
154
126
  type BaseParamOptions = z.input<typeof BaseParamSchema>;
155
127
  type StringOptions = z.input<typeof StringParamSchema>;
156
128
  type NumberOptions = z.input<typeof NumberParamSchema>;
157
129
 
158
130
  type ParamResolvedOutputType<OutputType, Required extends boolean = true> = Required extends true ? OutputType : OutputType | null;
159
131
  declare abstract class BaseParam<Options extends BaseParamOptions, OutputType, Required extends boolean = true> {
132
+ private schema;
160
133
  options: Options & {
161
134
  required: Required;
162
135
  };
@@ -169,7 +142,7 @@ declare abstract class BaseParam<Options extends BaseParamOptions, OutputType, R
169
142
  * @internal
170
143
  */
171
144
  readonly _type: Required extends true ? OutputType : OutputType | null;
172
- constructor(options: Options);
145
+ constructor(options: Options, schema: z$1.ZodObject);
173
146
  protected setOption(key: keyof Options, value: any): this;
174
147
  name(value: string): this;
175
148
  description(value: string): this;
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { GatewayIntentBits, Events, Client, IntentsBitField, Collection, SlashCommandBuilder, SlashCommandStringOption, SlashCommandNumberOption, ChatInputCommandInteraction, Message } from 'discord.js';
2
- import z3, { z } from 'zod';
2
+ import z4, { z } from 'zod';
3
3
  import glob from 'tiny-glob';
4
4
  import { createJiti } from 'jiti';
5
5
  import { inspect } from 'util';
@@ -330,6 +330,17 @@ var HookState = /* @__PURE__ */ ((HookState2) => (HookState2.Pre = "PRE", HookSt
330
330
  }
331
331
  }
332
332
  };
333
+ var ParamUserType = /* @__PURE__ */ ((ParamUserType2) => (ParamUserType2.Bot = "bot", ParamUserType2.Normal = "normal", ParamUserType2.Any = "any", ParamUserType2))(ParamUserType || {}), BaseParamSchema = z.object({
334
+ name: z.string(),
335
+ description: z.string().optional(),
336
+ required: z.boolean().default(true)
337
+ }), StringParamSchema = BaseParamSchema.extend({
338
+ maxLength: z.number().min(1).optional(),
339
+ minLength: z.number().min(1).optional()
340
+ }), NumberParamSchema = BaseParamSchema.extend({
341
+ maxValue: z.number().optional(),
342
+ minValue: z.number().optional()
343
+ });
333
344
 
334
345
  // src/errors/BakitError.ts
335
346
  var BakitError = class extends Error {
@@ -349,13 +360,24 @@ var ArgumentError = class extends BakitError {
349
360
 
350
361
  // src/base/command/param/Param.ts
351
362
  var BaseParam = class {
352
- options;
353
- constructor(options) {
354
- this.options = { ...options, required: options.required ?? true };
363
+ constructor(options, schema) {
364
+ this.schema = schema;
365
+ let parsed = schema.parse({
366
+ ...options,
367
+ description: options.description ?? options.name
368
+ });
369
+ this.options = parsed;
355
370
  }
371
+ options;
356
372
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
357
373
  setOption(key, value) {
358
- return value === null ? delete this.options[key] : this.options[key] = value, this;
374
+ if (value === null)
375
+ return delete this.options[key], this;
376
+ let fieldValidator = this.schema.shape[key];
377
+ if (!fieldValidator)
378
+ return this.options[key] = value, this;
379
+ let parsedValue = fieldValidator.parse(value);
380
+ return this.options[key] = parsedValue, this;
359
381
  }
360
382
  name(value) {
361
383
  return this.setOption("name", value);
@@ -381,7 +403,7 @@ var BaseParam = class {
381
403
  }
382
404
  }, StringParam = class extends BaseParam {
383
405
  constructor(options) {
384
- super(BaseParam.getOptions(options));
406
+ super(BaseParam.getOptions(options), StringParamSchema);
385
407
  }
386
408
  required(value) {
387
409
  return super.required(value);
@@ -419,7 +441,7 @@ var BaseParam = class {
419
441
  }
420
442
  }, NumberParam = class extends BaseParam {
421
443
  constructor(options) {
422
- super(BaseParam.getOptions(options));
444
+ super(BaseParam.getOptions(options), NumberParamSchema);
423
445
  }
424
446
  required(value) {
425
447
  return super.required(value);
@@ -564,9 +586,9 @@ var CommandManager = class extends BaseClientManager {
564
586
  return this.commands.get(name);
565
587
  }
566
588
  };
567
- var ListenerOptionsSchema = z3.object({
568
- name: z3.enum(Events),
569
- once: z3.boolean().default(false)
589
+ var ListenerOptionsSchema = z4.object({
590
+ name: z4.enum(Events),
591
+ once: z4.boolean().default(false)
570
592
  }), Listener = class extends LifecycleManager {
571
593
  options;
572
594
  constructor(options) {
@@ -679,20 +701,6 @@ var BakitClient2 = class extends Client {
679
701
  return `${this.constructor.name} {}`;
680
702
  }
681
703
  };
682
- var ParamUserType = /* @__PURE__ */ ((ParamUserType2) => (ParamUserType2.Bot = "bot", ParamUserType2.Normal = "normal", ParamUserType2.Any = "any", ParamUserType2))(ParamUserType || {}), BaseParamSchema = z.object({
683
- name: z.string(),
684
- description: z.string().optional(),
685
- required: z.boolean().default(true)
686
- }), withDefaultDescription = (data) => ({
687
- ...data,
688
- description: data.description ?? `${data.name}`
689
- }), StringParamSchema = BaseParamSchema.extend({
690
- maxLength: z.number().min(1).optional(),
691
- minLength: z.number().min(1).optional()
692
- }).transform(withDefaultDescription), NumberParamSchema = BaseParamSchema.extend({
693
- maxValue: z.number().optional(),
694
- minValue: z.number().optional()
695
- }).transform(withDefaultDescription);
696
704
 
697
705
  // src/base/command/param/Params.ts
698
706
  function createFactory(ctor) {
@@ -776,7 +784,7 @@ var ProjectCacheManager = class {
776
784
  async write(path, data) {
777
785
  let fullPath = join(this.rootDir, path), dir = dirname(fullPath);
778
786
  await mkdir(dir, { recursive: true });
779
- let content = typeof data == "string" ? data : JSON.stringify(data, null, 2);
787
+ let content = typeof data == "string" ? data : JSON.stringify(data);
780
788
  await writeFile(fullPath, content, "utf-8");
781
789
  }
782
790
  async read(path) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bakit",
3
- "version": "2.0.0-alpha.8",
3
+ "version": "2.0.0-alpha.9",
4
4
  "description": "A framework for discord.js",
5
5
  "type": "module",
6
6
  "types": "./dist/index.d.ts",