@sapphire/decorators 4.3.9-next.45331ed.0 → 4.3.9-next.63e15eb.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,240 @@
1
- export * from './base-decorators';
2
- export * from './djs-decorators';
3
- export * from './piece-decorators';
4
- export * from './utils';
5
- //# sourceMappingURL=index.d.ts.map
1
+ import { PermissionResolvable } from 'discord.js';
2
+ import { Piece } from '@sapphire/framework';
3
+ import { Container } from '@sapphire/pieces';
4
+
5
+ /**
6
+ * Decorator that sets the enumerable property of a class field to the desired value.
7
+ * @param value Whether the property should be enumerable or not
8
+ */
9
+ declare function Enumerable(value: boolean): (target: unknown, key: string) => void;
10
+ /**
11
+ * Decorator that sets the enumerable property of a class method to the desired value.
12
+ * @param value Whether the method should be enumerable or not
13
+ */
14
+ declare function EnumerableMethod(value: boolean): MethodDecorator;
15
+
16
+ /**
17
+ * The function precondition interface.
18
+ */
19
+ interface FunctionPrecondition {
20
+ /**
21
+ * The arguments passed to the function or class' method.
22
+ */
23
+ (...args: any[]): boolean | Promise<boolean>;
24
+ }
25
+ /**
26
+ * The fallback interface, this is called when the function precondition returns or resolves with a falsy value.
27
+ */
28
+ interface FunctionFallback {
29
+ /**
30
+ * The arguments passed to the function or class' method.
31
+ */
32
+ (...args: any[]): unknown;
33
+ }
34
+ /**
35
+ * Utility to make a method decorator with lighter syntax and inferred types.
36
+ *
37
+ * ```typescript
38
+ * // Enumerable function
39
+ * function enumerableMethod(value: boolean) {
40
+ * return createMethodDecorator((_target, _propertyKey, descriptor) => {
41
+ * descriptor.enumerable = value;
42
+ * });
43
+ * }
44
+ * ```
45
+ * @param fn The method to decorate
46
+ */
47
+ declare function createMethodDecorator(fn: MethodDecorator): MethodDecorator;
48
+ /**
49
+ * Utility to make a class decorator with lighter syntax and inferred types.
50
+ * @param fn The class to decorate
51
+ * @see {@link ApplyOptions}
52
+ */
53
+ declare function createClassDecorator<TFunction extends (...args: any[]) => void>(fn: TFunction): ClassDecorator;
54
+ /**
55
+ * Utility to make function preconditions.
56
+ *
57
+ * ```typescript
58
+ * // No fallback (returns undefined)
59
+ * function requireGuild(value: number) {
60
+ * return createFunctionPrecondition((message: Message) =>
61
+ * message.guild !== null
62
+ * );
63
+ * }
64
+ *
65
+ * // With fallback
66
+ * function requireGuild(
67
+ * value: number,
68
+ * fallback: () => unknown = () => undefined
69
+ * ) {
70
+ * return createFunctionPrecondition(
71
+ * (message: Message) => message.guild !== null,
72
+ * fallback
73
+ * );
74
+ * }
75
+ * ```
76
+ * @since 1.0.0
77
+ * @param precondition The function that defines whether or not the function should be run, returning the returned value from fallback
78
+ * @param fallback The fallback value that defines what the method should return in case the precondition fails
79
+ */
80
+ declare function createFunctionPrecondition(precondition: FunctionPrecondition, fallback?: FunctionFallback): MethodDecorator;
81
+ /**
82
+ * Creates a new proxy to efficiently add properties to class without creating subclasses
83
+ * @param target The constructor of the class to modify
84
+ * @param handler The handler function to modify the constructor behavior for the target
85
+ * @hidden
86
+ */
87
+ declare function createProxy<T extends object>(target: T, handler: Omit<ProxyHandler<T>, 'get'>): T;
88
+
89
+ declare enum DecoratorIdentifiers {
90
+ RequiresClientPermissionsGuildOnly = "requiresClientPermissionsGuildOnly",
91
+ RequiresClientPermissionsMissingPermissions = "requiresClientPermissionsMissingPermissions",
92
+ RequiresUserPermissionsGuildOnly = "requiresUserPermissionsGuildOnly",
93
+ RequiresUserPermissionsMissingPermissions = "requiresUserPermissionsMissingPermissions"
94
+ }
95
+ /**
96
+ * Allows you to set permissions required for individual methods. This is particularly useful for subcommands that require specific permissions.
97
+ * @remark This decorator applies to the client that is to execute the command. For setting permissions required user of the command see {@link RequiresUserPermissions}
98
+ * @remark This decorator makes the decorated function asynchronous, so any result should be `await`ed.
99
+ * @param permissionsResolvable Permissions that the method should have.
100
+ * @example
101
+ * ```typescript
102
+ * import { ApplyOptions, RequiresClientPermissions } from '@sapphire/decorators';
103
+ * import { SubCommandPluginCommand, SubCommandPluginCommandOptions } from '@sapphire/plugin-subcommands';
104
+ * import type { Message } from 'discord.js';
105
+ *
106
+ * (at)ApplyOptions<SubCommandPluginCommandOptions>({
107
+ * aliases: ['cws'],
108
+ * description: 'A basic command with some subcommands',
109
+ * subCommands: ['add', 'remove', 'reset', { input: 'show', default: true }]
110
+ * })
111
+ * export default class extends SubCommandPluginCommand {
112
+ * // Anyone should be able to view the result, but not modify
113
+ * public async show(message: Message) {
114
+ * return message.channel.send('Showing!');
115
+ * }
116
+ *
117
+ * (at)RequiresClientPermissions('BAN_MEMBERS') // This subcommand requires the client to be able to ban members.
118
+ * public async add(message: Message) {
119
+ * return message.channel.send('Adding!');
120
+ * }
121
+ *
122
+ * (at)RequiresClientPermissions('BAN_MEMBERS') // This subcommand requires the client to be able to ban members.
123
+ * public async remove(message: Message) {
124
+ * return message.channel.send('Removing!');
125
+ * }
126
+ *
127
+ * (at)RequiresClientPermissions('BAN_MEMBERS') // This subcommand requires the client to be able to ban members.
128
+ * public async reset(message: Message) {
129
+ * return message.channel.send('Resetting!');
130
+ * }
131
+ * }
132
+ * ```
133
+ */
134
+ declare const RequiresClientPermissions: (...permissionsResolvable: PermissionResolvable[]) => MethodDecorator;
135
+ /**
136
+ * Allows you to set permissions required for individual methods. This is particularly useful for subcommands that require specific permissions.
137
+ * @remark This decorator applies to the user of the command. For setting permissions required for the client see {@link RequiresClientPermissions}
138
+ * @remark This decorator makes the decorated function asynchronous, so any result should be `await`ed.
139
+ * @param permissionsResolvable Permissions that the method should have.
140
+ * @example
141
+ * ```typescript
142
+ * import { ApplyOptions, RequiresUserPermissions } from '@sapphire/decorators';
143
+ * import { SubCommandPluginCommand, SubCommandPluginCommandOptions } from '@sapphire/plugin-subcommands';
144
+ * import type { Message } from 'discord.js';
145
+ *
146
+ * (at)ApplyOptions<SubCommandPluginCommandOptions>({
147
+ * aliases: ['cws'],
148
+ * description: 'A basic command with some subcommands',
149
+ * subCommands: ['add', 'remove', 'reset', { input: 'show', default: true }]
150
+ * })
151
+ * export default class extends SubCommandPluginCommand {
152
+ * // Anyone should be able to view the result, but not modify
153
+ * public async show(message: Message) {
154
+ * return message.channel.send('Showing!');
155
+ * }
156
+ *
157
+ * (at)RequiresUserPermissions('BAN_MEMBERS') // This subcommand requires the user of the command to be able to ban members.
158
+ * public async add(message: Message) {
159
+ * return message.channel.send('Adding!');
160
+ * }
161
+ *
162
+ * (at)RequiresUserPermissions('BAN_MEMBERS') // This subcommand requires the user of the command to be able to ban members.
163
+ * public async remove(message: Message) {
164
+ * return message.channel.send('Removing!');
165
+ * }
166
+ *
167
+ * (at)RequiresUserPermissions('BAN_MEMBERS') // This subcommand requires the user of the command to be able to ban members.
168
+ * public async reset(message: Message) {
169
+ * return message.channel.send('Resetting!');
170
+ * }
171
+ * }
172
+ * ```
173
+ */
174
+ declare const RequiresUserPermissions: (...permissionsResolvable: PermissionResolvable[]) => MethodDecorator;
175
+ /**
176
+ * Requires the message to be run in a guild context, this decorator requires the first argument to be a `Message` instance
177
+ * @since 1.0.0
178
+ * @param fallback The fallback value passed to `createFunctionInhibitor`
179
+ */
180
+ declare function RequiresGuildContext(fallback?: FunctionFallback): MethodDecorator;
181
+ /**
182
+ * Requires the message to be run in a dm context, this decorator requires the first argument to be a `Message` instance
183
+ * @since 1.0.0
184
+ * @param fallback The fallback value passed to `createFunctionInhibitor`
185
+ */
186
+ declare function RequiresDMContext(fallback?: FunctionFallback): MethodDecorator;
187
+
188
+ /**
189
+ * Decorator function that applies given options to any Sapphire piece
190
+ * @param options The options to pass to the piece constructor
191
+ * @example
192
+ * ```typescript
193
+ * import { ApplyOptions } from '@sapphire/decorators';
194
+ * import { Command } from '@sapphire/framework';
195
+ * import type { Message } from 'discord.js';
196
+ *
197
+ * @ApplyOptions<Command.Options>({
198
+ * description: 'ping pong',
199
+ * enabled: true
200
+ * })
201
+ * export class UserCommand extends Command {
202
+ * public override async messageRun(message: Message) {
203
+ * const msg = await message.channel.send('Ping?');
204
+ *
205
+ * return msg.edit(
206
+ * `Pong! Client Latency ${Math.round(this.container.client.ws.ping)}ms. API Latency ${msg.createdTimestamp - message.createdTimestamp}ms.`
207
+ * );
208
+ * }
209
+ * }
210
+ * ```
211
+ * @example
212
+ * ```typescript
213
+ * import { ApplyOptions } from '@sapphire/decorators';
214
+ * import { Listener } from '@sapphire/framework';
215
+ * import { GatewayDispatchEvents, GatewayMessageDeleteDispatch } from 'discord-api-types/v9';
216
+ *
217
+ * @ApplyOptions<Listener.Options>(({ container }) => ({
218
+ * description: 'Handle Raw Message Delete events',
219
+ * emitter: container.client.ws,
220
+ * event: GatewayDispatchEvents.MessageDelete
221
+ * }))
222
+ * export class UserListener extends Listener {
223
+ * public override run(data: GatewayMessageDeleteDispatch['d']): void {
224
+ * if (!data.guild_id) return;
225
+ *
226
+ * const guild = this.container.client.guilds.cache.get(data.guild_id);
227
+ * if (!guild || !guild.channels.cache.has(data.channel_id)) return;
228
+ *
229
+ * // Do something with the data
230
+ * }
231
+ * }
232
+ * ```
233
+ */
234
+ declare function ApplyOptions<T extends Piece.Options>(optionsOrFn: T | ((parameters: ApplyOptionsCallbackParameters) => T)): ClassDecorator;
235
+ interface ApplyOptionsCallbackParameters {
236
+ container: Container;
237
+ context: Piece.Context;
238
+ }
239
+
240
+ export { ApplyOptions, ApplyOptionsCallbackParameters, DecoratorIdentifiers, Enumerable, EnumerableMethod, FunctionFallback, FunctionPrecondition, RequiresClientPermissions, RequiresDMContext, RequiresGuildContext, RequiresUserPermissions, createClassDecorator, createFunctionPrecondition, createMethodDecorator, createProxy };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sapphire/decorators",
3
- "version": "4.3.9-next.45331ed.0",
3
+ "version": "4.3.9-next.63e15eb.0",
4
4
  "description": "Useful TypeScript decorators for Sapphire Framework Discord bots",
5
5
  "author": "@sapphire",
6
6
  "license": "MIT",
@@ -16,7 +16,7 @@
16
16
  "scripts": {
17
17
  "test": "vitest run",
18
18
  "lint": "eslint src tests --ext ts --fix -c ../../.eslintrc",
19
- "build": "tsup && tsc -b src",
19
+ "build": "tsup",
20
20
  "prepack": "yarn build",
21
21
  "bump": "cliff-jumper",
22
22
  "check-update": "cliff-jumper --dry-run"
@@ -25,13 +25,13 @@
25
25
  "tslib": "^2.4.0"
26
26
  },
27
27
  "devDependencies": {
28
- "@favware/cliff-jumper": "^1.8.5",
28
+ "@favware/cliff-jumper": "^1.8.6",
29
29
  "@sapphire/discord-utilities": "^2.11.5",
30
30
  "@sapphire/discord.js-utilities": "^4.11.3",
31
31
  "@sapphire/ratelimits": "^2.4.4",
32
- "@sapphire/result": "^2.0.1",
33
- "@sapphire/utilities": "^3.7.0",
34
- "tsup": "^6.1.3",
32
+ "@sapphire/result": "^2.3.3",
33
+ "@sapphire/utilities": "^3.9.0",
34
+ "tsup": "^6.2.1",
35
35
  "typescript": "^4.7.4"
36
36
  },
37
37
  "repository": {
@@ -1,11 +0,0 @@
1
- /**
2
- * Decorator that sets the enumerable property of a class field to the desired value.
3
- * @param value Whether the property should be enumerable or not
4
- */
5
- export declare function Enumerable(value: boolean): (target: unknown, key: string) => void;
6
- /**
7
- * Decorator that sets the enumerable property of a class method to the desired value.
8
- * @param value Whether the method should be enumerable or not
9
- */
10
- export declare function EnumerableMethod(value: boolean): MethodDecorator;
11
- //# sourceMappingURL=base-decorators.d.ts.map
@@ -1,101 +0,0 @@
1
- import { PermissionResolvable } from 'discord.js';
2
- import { FunctionFallback } from './utils';
3
- export declare enum DecoratorIdentifiers {
4
- RequiresClientPermissionsGuildOnly = "requiresClientPermissionsGuildOnly",
5
- RequiresClientPermissionsMissingPermissions = "requiresClientPermissionsMissingPermissions",
6
- RequiresUserPermissionsGuildOnly = "requiresUserPermissionsGuildOnly",
7
- RequiresUserPermissionsMissingPermissions = "requiresUserPermissionsMissingPermissions"
8
- }
9
- /**
10
- * Allows you to set permissions required for individual methods. This is particularly useful for subcommands that require specific permissions.
11
- * @remark This decorator applies to the client that is to execute the command. For setting permissions required user of the command see {@link RequiresUserPermissions}
12
- * @remark This decorator makes the decorated function asynchronous, so any result should be `await`ed.
13
- * @param permissionsResolvable Permissions that the method should have.
14
- * @example
15
- * ```typescript
16
- * import { ApplyOptions, RequiresClientPermissions } from '@sapphire/decorators';
17
- * import { SubCommandPluginCommand, SubCommandPluginCommandOptions } from '@sapphire/plugin-subcommands';
18
- * import type { Message } from 'discord.js';
19
- *
20
- * (at)ApplyOptions<SubCommandPluginCommandOptions>({
21
- * aliases: ['cws'],
22
- * description: 'A basic command with some subcommands',
23
- * subCommands: ['add', 'remove', 'reset', { input: 'show', default: true }]
24
- * })
25
- * export default class extends SubCommandPluginCommand {
26
- * // Anyone should be able to view the result, but not modify
27
- * public async show(message: Message) {
28
- * return message.channel.send('Showing!');
29
- * }
30
- *
31
- * (at)RequiresClientPermissions('BAN_MEMBERS') // This subcommand requires the client to be able to ban members.
32
- * public async add(message: Message) {
33
- * return message.channel.send('Adding!');
34
- * }
35
- *
36
- * (at)RequiresClientPermissions('BAN_MEMBERS') // This subcommand requires the client to be able to ban members.
37
- * public async remove(message: Message) {
38
- * return message.channel.send('Removing!');
39
- * }
40
- *
41
- * (at)RequiresClientPermissions('BAN_MEMBERS') // This subcommand requires the client to be able to ban members.
42
- * public async reset(message: Message) {
43
- * return message.channel.send('Resetting!');
44
- * }
45
- * }
46
- * ```
47
- */
48
- export declare const RequiresClientPermissions: (...permissionsResolvable: PermissionResolvable[]) => MethodDecorator;
49
- /**
50
- * Allows you to set permissions required for individual methods. This is particularly useful for subcommands that require specific permissions.
51
- * @remark This decorator applies to the user of the command. For setting permissions required for the client see {@link RequiresClientPermissions}
52
- * @remark This decorator makes the decorated function asynchronous, so any result should be `await`ed.
53
- * @param permissionsResolvable Permissions that the method should have.
54
- * @example
55
- * ```typescript
56
- * import { ApplyOptions, RequiresUserPermissions } from '@sapphire/decorators';
57
- * import { SubCommandPluginCommand, SubCommandPluginCommandOptions } from '@sapphire/plugin-subcommands';
58
- * import type { Message } from 'discord.js';
59
- *
60
- * (at)ApplyOptions<SubCommandPluginCommandOptions>({
61
- * aliases: ['cws'],
62
- * description: 'A basic command with some subcommands',
63
- * subCommands: ['add', 'remove', 'reset', { input: 'show', default: true }]
64
- * })
65
- * export default class extends SubCommandPluginCommand {
66
- * // Anyone should be able to view the result, but not modify
67
- * public async show(message: Message) {
68
- * return message.channel.send('Showing!');
69
- * }
70
- *
71
- * (at)RequiresUserPermissions('BAN_MEMBERS') // This subcommand requires the user of the command to be able to ban members.
72
- * public async add(message: Message) {
73
- * return message.channel.send('Adding!');
74
- * }
75
- *
76
- * (at)RequiresUserPermissions('BAN_MEMBERS') // This subcommand requires the user of the command to be able to ban members.
77
- * public async remove(message: Message) {
78
- * return message.channel.send('Removing!');
79
- * }
80
- *
81
- * (at)RequiresUserPermissions('BAN_MEMBERS') // This subcommand requires the user of the command to be able to ban members.
82
- * public async reset(message: Message) {
83
- * return message.channel.send('Resetting!');
84
- * }
85
- * }
86
- * ```
87
- */
88
- export declare const RequiresUserPermissions: (...permissionsResolvable: PermissionResolvable[]) => MethodDecorator;
89
- /**
90
- * Requires the message to be run in a guild context, this decorator requires the first argument to be a `Message` instance
91
- * @since 1.0.0
92
- * @param fallback The fallback value passed to `createFunctionInhibitor`
93
- */
94
- export declare function RequiresGuildContext(fallback?: FunctionFallback): MethodDecorator;
95
- /**
96
- * Requires the message to be run in a dm context, this decorator requires the first argument to be a `Message` instance
97
- * @since 1.0.0
98
- * @param fallback The fallback value passed to `createFunctionInhibitor`
99
- */
100
- export declare function RequiresDMContext(fallback?: FunctionFallback): MethodDecorator;
101
- //# sourceMappingURL=djs-decorators.d.ts.map
@@ -1,54 +0,0 @@
1
- import { type Piece } from '@sapphire/framework';
2
- import type { Container } from '@sapphire/pieces';
3
- /**
4
- * Decorator function that applies given options to any Sapphire piece
5
- * @param options The options to pass to the piece constructor
6
- * @example
7
- * ```typescript
8
- * import { ApplyOptions } from '@sapphire/decorators';
9
- * import { Command } from '@sapphire/framework';
10
- * import type { Message } from 'discord.js';
11
- *
12
- * @ApplyOptions<Command.Options>({
13
- * description: 'ping pong',
14
- * enabled: true
15
- * })
16
- * export class UserCommand extends Command {
17
- * public override async messageRun(message: Message) {
18
- * const msg = await message.channel.send('Ping?');
19
- *
20
- * return msg.edit(
21
- * `Pong! Client Latency ${Math.round(this.container.client.ws.ping)}ms. API Latency ${msg.createdTimestamp - message.createdTimestamp}ms.`
22
- * );
23
- * }
24
- * }
25
- * ```
26
- * @example
27
- * ```typescript
28
- * import { ApplyOptions } from '@sapphire/decorators';
29
- * import { Listener } from '@sapphire/framework';
30
- * import { GatewayDispatchEvents, GatewayMessageDeleteDispatch } from 'discord-api-types/v9';
31
- *
32
- * @ApplyOptions<Listener.Options>(({ container }) => ({
33
- * description: 'Handle Raw Message Delete events',
34
- * emitter: container.client.ws,
35
- * event: GatewayDispatchEvents.MessageDelete
36
- * }))
37
- * export class UserListener extends Listener {
38
- * public override run(data: GatewayMessageDeleteDispatch['d']): void {
39
- * if (!data.guild_id) return;
40
- *
41
- * const guild = this.container.client.guilds.cache.get(data.guild_id);
42
- * if (!guild || !guild.channels.cache.has(data.channel_id)) return;
43
- *
44
- * // Do something with the data
45
- * }
46
- * }
47
- * ```
48
- */
49
- export declare function ApplyOptions<T extends Piece.Options>(optionsOrFn: T | ((parameters: ApplyOptionsCallbackParameters) => T)): ClassDecorator;
50
- export interface ApplyOptionsCallbackParameters {
51
- container: Container;
52
- context: Piece.Context;
53
- }
54
- //# sourceMappingURL=piece-decorators.d.ts.map
package/dist/utils.d.ts DELETED
@@ -1,73 +0,0 @@
1
- /**
2
- * The function precondition interface.
3
- */
4
- export interface FunctionPrecondition {
5
- /**
6
- * The arguments passed to the function or class' method.
7
- */
8
- (...args: any[]): boolean | Promise<boolean>;
9
- }
10
- /**
11
- * The fallback interface, this is called when the function precondition returns or resolves with a falsy value.
12
- */
13
- export interface FunctionFallback {
14
- /**
15
- * The arguments passed to the function or class' method.
16
- */
17
- (...args: any[]): unknown;
18
- }
19
- /**
20
- * Utility to make a method decorator with lighter syntax and inferred types.
21
- *
22
- * ```typescript
23
- * // Enumerable function
24
- * function enumerableMethod(value: boolean) {
25
- * return createMethodDecorator((_target, _propertyKey, descriptor) => {
26
- * descriptor.enumerable = value;
27
- * });
28
- * }
29
- * ```
30
- * @param fn The method to decorate
31
- */
32
- export declare function createMethodDecorator(fn: MethodDecorator): MethodDecorator;
33
- /**
34
- * Utility to make a class decorator with lighter syntax and inferred types.
35
- * @param fn The class to decorate
36
- * @see {@link ApplyOptions}
37
- */
38
- export declare function createClassDecorator<TFunction extends (...args: any[]) => void>(fn: TFunction): ClassDecorator;
39
- /**
40
- * Utility to make function preconditions.
41
- *
42
- * ```typescript
43
- * // No fallback (returns undefined)
44
- * function requireGuild(value: number) {
45
- * return createFunctionPrecondition((message: Message) =>
46
- * message.guild !== null
47
- * );
48
- * }
49
- *
50
- * // With fallback
51
- * function requireGuild(
52
- * value: number,
53
- * fallback: () => unknown = () => undefined
54
- * ) {
55
- * return createFunctionPrecondition(
56
- * (message: Message) => message.guild !== null,
57
- * fallback
58
- * );
59
- * }
60
- * ```
61
- * @since 1.0.0
62
- * @param precondition The function that defines whether or not the function should be run, returning the returned value from fallback
63
- * @param fallback The fallback value that defines what the method should return in case the precondition fails
64
- */
65
- export declare function createFunctionPrecondition(precondition: FunctionPrecondition, fallback?: FunctionFallback): MethodDecorator;
66
- /**
67
- * Creates a new proxy to efficiently add properties to class without creating subclasses
68
- * @param target The constructor of the class to modify
69
- * @param handler The handler function to modify the constructor behavior for the target
70
- * @hidden
71
- */
72
- export declare function createProxy<T extends object>(target: T, handler: Omit<ProxyHandler<T>, 'get'>): T;
73
- //# sourceMappingURL=utils.d.ts.map