@wolfstar/decorators 0.1.1 → 0.1.2-next-20261007161851

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/README.md CHANGED
@@ -103,16 +103,17 @@ export class UserCommand extends Command {
103
103
 
104
104
  When the check fails, a `PreconditionError` is thrown, identified by `Identifiers.PreconditionUserPermissions` or
105
105
  `Identifiers.PreconditionClientPermissions`, with `context: { missing, missingNames }` describing the missing
106
- permissions. Errors thrown from a command are emitted as `commandError` (and as `interactionHandlerError` for
107
- interaction handlers), which is the idiomatic place to turn them into a user-facing reply:
106
+ permissions. A `PreconditionError` is a `UserError`, so the client emits it as `chatInputCommandDenied` or
107
+ `contextMenuCommandDenied` (and as `interactionHandlerDenied` for interaction handlers) instead of `commandError`, which
108
+ is the idiomatic place to turn it into a user-facing reply. `commandError` only receives unexpected errors:
108
109
 
109
110
  ```typescript
110
111
  import { ApplyOptions } from '@wolfstar/decorators';
111
- import { Identifiers, Listener, PreconditionError, type ClientEventCommandContext } from '@wolfstar/http-framework';
112
+ import { Identifiers, Listener, PreconditionError, type ClientEventCommandContext, type UserError } from '@wolfstar/http-framework';
112
113
 
113
- @ApplyOptions<Listener.Options>({ emitter: 'client', event: 'commandError' })
114
+ @ApplyOptions<Listener.Options>({ emitter: 'client', event: 'chatInputCommandDenied' })
114
115
  export class UserListener extends Listener {
115
- public run(error: unknown, context: ClientEventCommandContext) {
116
+ public run(error: UserError, context: ClientEventCommandContext) {
116
117
  if (
117
118
  error instanceof PreconditionError &&
118
119
  (error.identifier === Identifiers.PreconditionUserPermissions || error.identifier === Identifiers.PreconditionClientPermissions)
@@ -126,6 +127,8 @@ export class UserListener extends Listener {
126
127
 
127
128
  Notes on the semantics:
128
129
 
130
+ - Before `@wolfstar/http-framework` 6.3.0 this error reached `commandError`. A listener on that event that handles
131
+ `PreconditionError` must move to the `*Denied` events (see the framework's README).
129
132
  - Members with `Administrator` implicitly satisfy every check.
130
133
  - `RequiresUserPermissions` passes for interactions received outside of a guild, since there are no guild permissions to
131
134
  check. Combine it with `RequiresGuildContext` when the method must be guild-only.
@@ -144,8 +144,9 @@ export declare function RequiresDMContext(fallback?: ContextFallback): MethodDec
144
144
  * the interaction was sent from, as reported by the interaction's `app_permissions` field.
145
145
  *
146
146
  * @remarks When the fallback is omitted, a {@linkcode PreconditionError} identified by
147
- * {@linkcode Identifiers.PreconditionClientPermissions} is thrown, which the client emits as `commandError` (or
148
- * `interactionHandlerError`) for a `Listener` to turn into a user-facing reply.
147
+ * {@linkcode Identifiers.PreconditionClientPermissions} is thrown, which the client emits as `chatInputCommandDenied` or
148
+ * `contextMenuCommandDenied` (or `interactionHandlerDenied`), not as `commandError`, for a `Listener` to turn into a
149
+ * user-facing reply.
149
150
  * @param permissions The permissions the application must have.
150
151
  * @returns A method decorator.
151
152
  * @example
@@ -170,8 +171,9 @@ export declare function RequiresClientPermissions(...permissions: PermissionReso
170
171
  * @remarks Interactions received outside of a guild carry no member permissions, so the check passes for them. Pair
171
172
  * this decorator with {@linkcode RequiresGuildContext} when the method must also be guild-only.
172
173
  * @remarks When the fallback is omitted, a {@linkcode PreconditionError} identified by
173
- * {@linkcode Identifiers.PreconditionUserPermissions} is thrown, which the client emits as `commandError` (or
174
- * `interactionHandlerError`) for a `Listener` to turn into a user-facing reply.
174
+ * {@linkcode Identifiers.PreconditionUserPermissions} is thrown, which the client emits as `chatInputCommandDenied` or
175
+ * `contextMenuCommandDenied` (or `interactionHandlerDenied`), not as `commandError`, for a `Listener` to turn into a
176
+ * user-facing reply.
175
177
  * @param permissions The permissions the invoking user must have.
176
178
  * @returns A method decorator.
177
179
  * @example
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/ApplyOptions.ts","../../src/Enumerable.ts","../../src/RequiresContext.ts","../../src/RequiresPermissions.ts","../../src/utils.ts"],"mappings":";;;;;;YAOY,iBAAiB,gBAAgB,eAAe,qBAAqB,SAAS,oBAAoB,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAkCxG,aAAa,gBAAgB,eAAe,cAC3D,aAAa,YAAY,SAAS,uBAAuB,WACvD;;;;;;;;;;;;;;;;;;;;;;;;;;;wBCnBa,WAAW,kBAAc,iBACjB;;;;;;;;;;;;;;;;;;;wBAiCR,iBAAiB,kBAAc,kBACtB,cAAc,YAAc;;;;;;YCrDzC,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;wBAwBlB,qBAAqB,WAAU,kBAAoC;;;;;;;;;;;;;;;;;;;;;;;;wBA2BnE,kBAAkB,WAAU,kBAAoC;;;;;;;;;;;;;;;;;;;;;;;;;;wBCXhE,6BAA6B,aAAa,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;wBA+CnE,2BAA2B,aAAa,yBAAyB;;;;;;;;;;;;;;;;;;;;wBC5EjE,sBAAsB,sBAAsB,yBAAyB,IAAI,YAAY;;;;;;;;;;;wBAcrF,qBAAqB,sBAAsB,yBAAyB,IAAI,YAAY;;;;;;;;wBAWpF,YAAY,kBAAkB,QAAQ,GAAG,SAAS,KAAK,aAAa,aAAa;;;;;;;;;;;;;;;;;;;;;wBA8BjF,2BACf,kBAAkB,0BAA0B,kBAC5C,eAAc,0BACZ"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/ApplyOptions.ts","../../src/Enumerable.ts","../../src/RequiresContext.ts","../../src/RequiresPermissions.ts","../../src/utils.ts"],"mappings":";;;;;;YAOY,iBAAiB,gBAAgB,eAAe,qBAAqB,SAAS,oBAAoB,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAkCxG,aAAa,gBAAgB,eAAe,cAC3D,aAAa,YAAY,SAAS,uBAAuB,WACvD;;;;;;;;;;;;;;;;;;;;;;;;;;;wBCnBa,WAAW,kBAAc,iBACjB;;;;;;;;;;;;;;;;;;;wBAiCR,iBAAiB,kBAAc,kBACtB,cAAc,YAAc;;;;;;YCrDzC,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;wBAwBlB,qBAAqB,WAAU,kBAAoC;;;;;;;;;;;;;;;;;;;;;;;;wBA2BnE,kBAAkB,WAAU,kBAAoC;;;;;;;;;;;;;;;;;;;;;;;;;;;wBCVhE,6BAA6B,aAAa,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAgDnE,2BAA2B,aAAa,yBAAyB;;;;;;;;;;;;;;;;;;;;wBC9EjE,sBAAsB,sBAAsB,yBAAyB,IAAI,YAAY;;;;;;;;;;;wBAcrF,qBAAqB,sBAAsB,yBAAyB,IAAI,YAAY;;;;;;;;wBAWpF,YAAY,kBAAkB,QAAQ,GAAG,SAAS,KAAK,aAAa,aAAa;;;;;;;;;;;;;;;;;;;;;wBA8BjF,2BACf,kBAAkB,0BAA0B,kBAC5C,eAAc,0BACZ"}
package/dist/esm/index.js CHANGED
@@ -259,8 +259,9 @@ function getUserPermissions(interaction) {
259
259
  * the interaction was sent from, as reported by the interaction's `app_permissions` field.
260
260
  *
261
261
  * @remarks When the fallback is omitted, a {@linkcode PreconditionError} identified by
262
- * {@linkcode Identifiers.PreconditionClientPermissions} is thrown, which the client emits as `commandError` (or
263
- * `interactionHandlerError`) for a `Listener` to turn into a user-facing reply.
262
+ * {@linkcode Identifiers.PreconditionClientPermissions} is thrown, which the client emits as `chatInputCommandDenied` or
263
+ * `contextMenuCommandDenied` (or `interactionHandlerDenied`), not as `commandError`, for a `Listener` to turn into a
264
+ * user-facing reply.
264
265
  * @param permissions The permissions the application must have.
265
266
  * @returns A method decorator.
266
267
  * @example
@@ -303,8 +304,9 @@ function RequiresClientPermissions(...permissions) {
303
304
  * @remarks Interactions received outside of a guild carry no member permissions, so the check passes for them. Pair
304
305
  * this decorator with {@linkcode RequiresGuildContext} when the method must also be guild-only.
305
306
  * @remarks When the fallback is omitted, a {@linkcode PreconditionError} identified by
306
- * {@linkcode Identifiers.PreconditionUserPermissions} is thrown, which the client emits as `commandError` (or
307
- * `interactionHandlerError`) for a `Listener` to turn into a user-facing reply.
307
+ * {@linkcode Identifiers.PreconditionUserPermissions} is thrown, which the client emits as `chatInputCommandDenied` or
308
+ * `contextMenuCommandDenied` (or `interactionHandlerDenied`), not as `commandError`, for a `Listener` to turn into a
309
+ * user-facing reply.
308
310
  * @param permissions The permissions the invoking user must have.
309
311
  * @returns A method decorator.
310
312
  * @example
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/utils.ts","../../src/ApplyOptions.ts","../../src/Enumerable.ts","../../src/RequiresContext.ts","../../src/RequiresPermissions.ts"],"sourcesContent":["/**\n * Utility to make a method decorator from a function.\n *\n * @remarks The decorator is returned with the signature it was given, rather than widened to `MethodDecorator`, so a\n * decorator built on top of this keeps whatever constraint it declares on its target.\n * @param fn The method to decorate.\n * @returns The decorator.\n * @example\n * ```typescript\n * // Enumerable function that will not append the property to the prototype:\n * function enumerableMethod(value: boolean) {\n * \treturn createMethodDecorator((_target: unknown, _propertyKey: string, descriptor: PropertyDescriptor) => {\n * \t\tdescriptor.enumerable = value;\n * \t});\n * }\n * ```\n */\nexport function createMethodDecorator<TFunction extends (...args: any[]) => unknown>(fn: TFunction): TFunction {\n\treturn fn;\n}\n\n/**\n * Utility to make a class decorator from a function.\n *\n * @remarks The decorator is returned with the signature it was given, rather than widened to `ClassDecorator`, so a\n * decorator built on top of this keeps whatever constraint it declares on its target, such as only accepting a\n * `Command` subclass.\n * @param fn The class to decorate.\n * @returns The decorator.\n * @see {@linkcode ApplyOptions}\n */\nexport function createClassDecorator<TFunction extends (...args: any[]) => unknown>(fn: TFunction): TFunction {\n\treturn fn;\n}\n\n/**\n * Creates a new proxy to efficiently add properties to a class without creating subclasses.\n *\n * @param target The constructor of the class to modify.\n * @param handler The handler function to modify the constructor behavior for the target.\n * @returns The proxy.\n */\nexport function createProxy<T extends object>(target: T, handler: Omit<ProxyHandler<T>, 'get'>): T {\n\treturn new Proxy(target, {\n\t\t...handler,\n\t\tget: (proxyTarget, property) => {\n\t\t\tconst value = Reflect.get(proxyTarget, property);\n\t\t\treturn typeof value === 'function' ? (...args: readonly unknown[]) => value.apply(proxyTarget, args) : value;\n\t\t}\n\t});\n}\n\n/**\n * Utility to make a method decorator with lighter syntax and inferred types.\n *\n * @remarks The decorated method is replaced by an `async` one, so it always returns a `Promise`, even when both the\n * precondition and the original method are synchronous.\n * @param precondition The predicate to run before the decorated method. It receives the same arguments as the method\n * and is called with the same `this`.\n * @param fallback The fallback to run when the precondition is not met. Defaults to a no-op returning `undefined`.\n * @returns The decorator.\n * @example\n * ```typescript\n * import { createFunctionPrecondition } from '@wolfstar/decorators';\n * import type { Command } from '@wolfstar/http-framework';\n *\n * const RequiresOwner = createFunctionPrecondition(\n * \t(interaction: Command.ChatInputInteraction) => interaction.user.id === process.env.OWNER_ID,\n * \t(interaction: Command.ChatInputInteraction) => interaction.reply({ content: 'Owner only.' })\n * );\n * ```\n */\nexport function createFunctionPrecondition(\n\tprecondition: (...args: any[]) => boolean | Promise<boolean>,\n\tfallback: (...args: any[]) => unknown = () => undefined\n): MethodDecorator {\n\treturn createMethodDecorator((_target: unknown, _propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n\t\tconst method = descriptor.value;\n\t\tif (!method) throw new Error('Function preconditions require a [[value]].');\n\t\tif (typeof method !== 'function') throw new Error('Function preconditions can only be applied to functions.');\n\n\t\tdescriptor.value = async function value(this: unknown, ...args: any[]) {\n\t\t\treturn (await precondition.apply(this, args)) ? method.apply(this, args) : fallback.apply(this, args);\n\t\t};\n\t}) as MethodDecorator;\n}\n","import type { LoaderPieceContext, PieceOptions } from '@wolfstar/http-framework';\nimport { createClassDecorator, createProxy } from './utils.js';\n\n/**\n * The constructor signature shared by every `Piece` of `@wolfstar/http-framework`, such as `Command`, `Listener`, and\n * `InteractionHandler`.\n */\nexport type PieceConstructor<Options extends PieceOptions = PieceOptions> = new (context: LoaderPieceContext, options?: Options) => unknown;\n\n/**\n * Decorator that sets the options of a `Piece`, such as a `Command`, a `Listener`, or an `InteractionHandler`.\n *\n * @remarks The options are merged on top of the ones the piece was constructed with, so a piece that also passes\n * options through `super(context, options)` will have the decorator's values win on conflicting keys.\n * @remarks Apply this decorator above (outside of) any other class decorator that keys metadata by class identity,\n * such as `RegisterCommand` from `@wolfstar/http-framework` — as in the example below. This decorator returns a `Proxy` wrapping the class,\n * so a decorator applied above it (running after it, and therefore registering against the proxy) would register\n * metadata that instances constructed from the exported class — whose `.constructor` still resolves to the original,\n * unproxied class — can never be looked up by.\n * @param optionsOrFn The options to pass to the piece's constructor, or a function that builds them from the loader\n * context.\n * @returns A class decorator.\n * @example\n * ```typescript\n * import { ApplyOptions } from '@wolfstar/decorators';\n * import { Command, RegisterCommand } from '@wolfstar/http-framework';\n *\n * (at)ApplyOptions<Command.Options>({ name: 'ping', enabled: true })\n * (at)RegisterCommand({ name: 'ping', description: 'A simple ping pong command' })\n * export class UserCommand extends Command {\n * \tpublic override chatInputRun(interaction: Command.ChatInputInteraction) {\n * \t\treturn interaction.reply({ content: 'Pong!' });\n * \t}\n * }\n * ```\n * @example\n * ```typescript\n * (at)ApplyOptions<Command.Options>(({ name }) => ({ name: name.toLowerCase() }))\n * export class UserCommand extends Command {}\n * ```\n */\nexport function ApplyOptions<Options extends PieceOptions = PieceOptions>(\n\toptionsOrFn: Options | ((context: LoaderPieceContext) => Options)\n): ClassDecorator {\n\treturn createClassDecorator((target: PieceConstructor<Options>) =>\n\t\tcreateProxy(target, {\n\t\t\tconstruct: (ctor, [context, baseOptions]: [LoaderPieceContext, Options | undefined], newTarget) =>\n\t\t\t\tReflect.construct(\n\t\t\t\t\tctor,\n\t\t\t\t\t[\n\t\t\t\t\t\tcontext,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t...baseOptions,\n\t\t\t\t\t\t\t...(typeof optionsOrFn === 'function' ? optionsOrFn(context) : optionsOrFn)\n\t\t\t\t\t\t}\n\t\t\t\t\t],\n\t\t\t\t\tnewTarget\n\t\t\t\t) as object\n\t\t})\n\t) as ClassDecorator;\n}\n","/**\n * Decorator that sets the `enumerable` property of a class field to the given value.\n *\n * @remarks The decorator installs a setter on the prototype, which is bypassed by the `Object.defineProperty` call\n * that `useDefineForClassFields` (enabled by `@sapphire/ts-config`, and the default from `ES2022` onwards) emits for\n * class fields. Mark the field as `declare` so no field definition is emitted, and assign it in the constructor.\n * @param value Whether the property should be enumerable or not.\n * @returns A property decorator.\n * @example\n * ```typescript\n * import { Enumerable } from '@wolfstar/decorators';\n * import { Command } from '@wolfstar/http-framework';\n *\n * export class UserCommand extends Command {\n * \t(at)Enumerable(false)\n * \tdeclare public cache: Map<string, string>;\n *\n * \tpublic constructor(context: Command.LoaderContext, options: Command.Options) {\n * \t\tsuper(context, options);\n * \t\tthis.cache = new Map();\n * \t}\n * }\n * ```\n */\nexport function Enumerable(value: boolean) {\n\treturn (target: unknown, key: string) => {\n\t\tReflect.defineProperty(target as object, key, {\n\t\t\tenumerable: value,\n\t\t\tset(this: unknown, val: unknown) {\n\t\t\t\tReflect.defineProperty(this as object, key, {\n\t\t\t\t\tconfigurable: true,\n\t\t\t\t\tenumerable: value,\n\t\t\t\t\tvalue: val,\n\t\t\t\t\twritable: true\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\t};\n}\n\n/**\n * Decorator that sets the `enumerable` property of a class method to the given value.\n *\n * @param value Whether the method should be enumerable or not.\n * @returns A method decorator.\n * @example\n * ```typescript\n * import { EnumerableMethod } from '@wolfstar/decorators';\n * import { Command } from '@wolfstar/http-framework';\n *\n * export class UserCommand extends Command {\n * \t(at)EnumerableMethod(true)\n * \tpublic getCacheKey(id: string) {\n * \t\treturn `user:${id}`;\n * \t}\n * }\n * ```\n */\nexport function EnumerableMethod(value: boolean) {\n\treturn (_target: unknown, _key: string, descriptor: PropertyDescriptor) => {\n\t\tdescriptor.enumerable = value;\n\t};\n}\n","import type { BaseInteraction } from '@wolfstar/http-framework';\nimport { createFunctionPrecondition } from './utils.js';\n\n/**\n * The fallback invoked when a context precondition is not met. It receives the same arguments as the decorated method.\n */\nexport type ContextFallback = (...args: any[]) => unknown;\n\n/**\n * Decorator that only runs the decorated method when the interaction was received from a guild.\n *\n * @param fallback The fallback to run when the interaction did not come from a guild. Defaults to a no-op, which\n * silently skips the method.\n * @returns A method decorator.\n * @example\n * ```typescript\n * import { RequiresGuildContext } from '@wolfstar/decorators';\n * import { Command, RegisterCommand } from '@wolfstar/http-framework';\n *\n * (at)RegisterCommand({ name: 'kick', description: 'Kicks a member' })\n * export class UserCommand extends Command {\n * \t(at)RequiresGuildContext((interaction: Command.ChatInputInteraction) =>\n * \t\tinteraction.reply({ content: 'This command can only be used in a server.' })\n * \t)\n * \tpublic override chatInputRun(interaction: Command.ChatInputInteraction) {\n * \t\treturn interaction.reply({ content: `Hello from ${interaction.guildId}!` });\n * \t}\n * }\n * ```\n */\nexport function RequiresGuildContext(fallback: ContextFallback = () => undefined): MethodDecorator {\n\treturn createFunctionPrecondition((interaction: BaseInteraction) => interaction.inGuild(), fallback);\n}\n\n/**\n * Decorator that only runs the decorated method when the interaction was **not** received from a guild, that is, from a\n * DM or from a user-installed app context.\n *\n * @param fallback The fallback to run when the interaction came from a guild. Defaults to a no-op, which silently skips\n * the method.\n * @returns A method decorator.\n * @example\n * ```typescript\n * import { RequiresDMContext } from '@wolfstar/decorators';\n * import { Command, RegisterCommand } from '@wolfstar/http-framework';\n *\n * (at)RegisterCommand({ name: 'private', description: 'Only usable outside of servers' })\n * export class UserCommand extends Command {\n * \t(at)RequiresDMContext((interaction: Command.ChatInputInteraction) =>\n * \t\tinteraction.reply({ content: 'This command cannot be used in a server.' })\n * \t)\n * \tpublic override chatInputRun(interaction: Command.ChatInputInteraction) {\n * \t\treturn interaction.reply({ content: 'Hello!' });\n * \t}\n * }\n * ```\n */\nexport function RequiresDMContext(fallback: ContextFallback = () => undefined): MethodDecorator {\n\treturn createFunctionPrecondition((interaction: BaseInteraction) => !interaction.inGuild(), fallback);\n}\n","import {\n\tgetMissingPermissions,\n\tIdentifiers,\n\tPreconditionError,\n\tresolvePermissions,\n\ttoPermissionNames,\n\ttype BaseInteraction,\n\ttype PermissionResolvable\n} from '@wolfstar/http-framework';\nimport { createFunctionPrecondition } from './utils.js';\n\n/**\n * Reads the permissions the invoking user has in the channel the interaction was sent from.\n *\n * @param interaction The interaction to read from.\n * @returns The bitfield of the user's permissions, or `null` when the interaction did not come from a guild and there\n * are therefore no guild permissions to check.\n */\nfunction getUserPermissions(interaction: BaseInteraction): bigint | null {\n\tconst permissions = interaction.member?.permissions;\n\treturn permissions === undefined ? null : BigInt(permissions);\n}\n\n/**\n * Decorator that only runs the decorated method when the application has all of the given permissions in the channel\n * the interaction was sent from, as reported by the interaction's `app_permissions` field.\n *\n * @remarks When the fallback is omitted, a {@linkcode PreconditionError} identified by\n * {@linkcode Identifiers.PreconditionClientPermissions} is thrown, which the client emits as `commandError` (or\n * `interactionHandlerError`) for a `Listener` to turn into a user-facing reply.\n * @param permissions The permissions the application must have.\n * @returns A method decorator.\n * @example\n * ```typescript\n * import { RequiresClientPermissions } from '@wolfstar/decorators';\n * import { Command, RegisterCommand } from '@wolfstar/http-framework';\n *\n * (at)RegisterCommand({ name: 'purge', description: 'Deletes messages' })\n * export class UserCommand extends Command {\n * \t(at)RequiresClientPermissions('ManageMessages')\n * \tpublic override chatInputRun(interaction: Command.ChatInputInteraction) {\n * \t\treturn interaction.reply({ content: 'Purging!' });\n * \t}\n * }\n * ```\n */\nexport function RequiresClientPermissions(...permissions: PermissionResolvable[]): MethodDecorator {\n\tconst required = resolvePermissions(permissions);\n\treturn createFunctionPrecondition(\n\t\t(interaction: BaseInteraction) => {\n\t\t\tconst granted = interaction.applicationPermissions;\n\t\t\t// `app_permissions` is always sent by Discord, but the field is optional in the typings; when it is absent\n\t\t\t// there is nothing to check against, so the method is allowed to run.\n\t\t\treturn granted === undefined || getMissingPermissions(granted, required) === 0n;\n\t\t},\n\t\t(interaction: BaseInteraction) => {\n\t\t\tconst missing = getMissingPermissions(interaction.applicationPermissions ?? 0n, required);\n\t\t\tconst missingNames = toPermissionNames(missing);\n\t\t\tthrow new PreconditionError({\n\t\t\t\tprecondition: 'ClientPermissions',\n\t\t\t\tidentifier: Identifiers.PreconditionClientPermissions,\n\t\t\t\tmessage: `Sorry, but I am not allowed to do that. I am missing the permissions: ${missingNames.join(', ')}`,\n\t\t\t\tcontext: { missing, missingNames }\n\t\t\t});\n\t\t}\n\t);\n}\n\n/**\n * Decorator that only runs the decorated method when the invoking user has all of the given permissions in the channel\n * the interaction was sent from.\n *\n * @remarks Interactions received outside of a guild carry no member permissions, so the check passes for them. Pair\n * this decorator with {@linkcode RequiresGuildContext} when the method must also be guild-only.\n * @remarks When the fallback is omitted, a {@linkcode PreconditionError} identified by\n * {@linkcode Identifiers.PreconditionUserPermissions} is thrown, which the client emits as `commandError` (or\n * `interactionHandlerError`) for a `Listener` to turn into a user-facing reply.\n * @param permissions The permissions the invoking user must have.\n * @returns A method decorator.\n * @example\n * ```typescript\n * import { RequiresUserPermissions } from '@wolfstar/decorators';\n * import { Command, RegisterCommand } from '@wolfstar/http-framework';\n *\n * (at)RegisterCommand({ name: 'ban', description: 'Bans a member' })\n * export class UserCommand extends Command {\n * \t(at)RequiresUserPermissions('BanMembers')\n * \tpublic override chatInputRun(interaction: Command.ChatInputInteraction) {\n * \t\treturn interaction.reply({ content: 'Banned!' });\n * \t}\n * }\n * ```\n */\nexport function RequiresUserPermissions(...permissions: PermissionResolvable[]): MethodDecorator {\n\tconst required = resolvePermissions(permissions);\n\treturn createFunctionPrecondition(\n\t\t(interaction: BaseInteraction) => {\n\t\t\tconst granted = getUserPermissions(interaction);\n\t\t\treturn granted === null || getMissingPermissions(granted, required) === 0n;\n\t\t},\n\t\t(interaction: BaseInteraction) => {\n\t\t\tconst missing = getMissingPermissions(getUserPermissions(interaction) ?? 0n, required);\n\t\t\tconst missingNames = toPermissionNames(missing);\n\t\t\tthrow new PreconditionError({\n\t\t\t\tprecondition: 'UserPermissions',\n\t\t\t\tidentifier: Identifiers.PreconditionUserPermissions,\n\t\t\t\tmessage: `Sorry, but you are not allowed to do that. You are missing the permissions: ${missingNames.join(', ')}`,\n\t\t\t\tcontext: { missing, missingNames }\n\t\t\t});\n\t\t}\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAiBA,SAAgB,sBAAqE,IAA0B;CAC9G,OAAO;AACR;;;;;;;;;;;AAYA,SAAgB,qBAAoE,IAA0B;CAC7G,OAAO;AACR;;;;;;;;AASA,SAAgB,YAA8B,QAAW,SAA0C;CAClG,OAAO,IAAI,MAAM,QAAQ;EACxB,GAAG;EACH,MAAM,aAAa,aAAa;GAC/B,MAAM,QAAQ,QAAQ,IAAI,aAAa,QAAQ;GAC/C,OAAO,OAAO,UAAU,cAAc,GAAG,SAA6B,MAAM,MAAM,aAAa,IAAI,IAAI;EACxG;CACD,CAAC;AACF;;;;;;;;;;;;;;;;;;;;;AAsBA,SAAgB,2BACf,cACA,iBAA8C,QAC5B;CAClB,OAAO,uBAAuB,SAAkB,cAA+B,eAAmC;EACjH,MAAM,SAAS,WAAW;EAC1B,IAAI,CAAC,QAAQ,MAAM,IAAI,MAAM,6CAA6C;EAC1E,IAAI,OAAO,WAAW,YAAY,MAAM,IAAI,MAAM,0DAA0D;EAE5G,WAAW,QAAQ,eAAe,MAAqB,GAAG,MAAa;GACtE,OAAQ,MAAM,aAAa,MAAM,MAAM,IAAI,IAAK,OAAO,MAAM,MAAM,IAAI,IAAI,SAAS,MAAM,MAAM,IAAI;EACrG;CACD,CAAC;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AC5CA,SAAgB,aACf,aACiB;CACjB,OAAO,sBAAsB,WAC5B,YAAY,QAAQ,EACnB,YAAY,MAAM,CAAC,SAAS,cAAyD,cACpF,QAAQ,UACP,MACA,CACC,SACA;EACC,GAAG;EACH,GAAI,OAAO,gBAAgB,aAAa,YAAY,OAAO,IAAI;CAChE,CACD,GACA,SACD,EACF,CAAC,CACF;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACpCA,SAAgB,WAAW,OAAgB;CAC1C,QAAQ,QAAiB,QAAgB;EACxC,QAAQ,eAAe,QAAkB,KAAK;GAC7C,YAAY;GACZ,IAAmB,KAAc;IAChC,QAAQ,eAAe,MAAgB,KAAK;KAC3C,cAAc;KACd,YAAY;KACZ,OAAO;KACP,UAAU;IACX,CAAC;GACF;EACD,CAAC;CACF;AACD;;;;;;;;;;;;;;;;;;;AAoBA,SAAgB,iBAAiB,OAAgB;CAChD,QAAQ,SAAkB,MAAc,eAAmC;EAC1E,WAAW,aAAa;CACzB;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;AChCA,SAAgB,qBAAqB,iBAAkC,QAA4B;CAClG,OAAO,4BAA4B,gBAAiC,YAAY,QAAQ,GAAG,QAAQ;AACpG;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,SAAgB,kBAAkB,iBAAkC,QAA4B;CAC/F,OAAO,4BAA4B,gBAAiC,CAAC,YAAY,QAAQ,GAAG,QAAQ;AACrG;;;;;;;;;;;ACzCA,SAAS,mBAAmB,aAA6C;CACxE,MAAM,cAAc,YAAY,QAAQ;CACxC,OAAO,gBAAgB,SAAY,OAAO,OAAO,WAAW;AAC7D;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,SAAgB,0BAA0B,GAAG,aAAsD;CAClG,MAAM,WAAW,mBAAmB,WAAW;CAC/C,OAAO,4BACL,gBAAiC;EACjC,MAAM,UAAU,YAAY;EAG5B,OAAO,YAAY,UAAa,sBAAsB,SAAS,QAAQ,MAAM;CAC9E,IACC,gBAAiC;EACjC,MAAM,UAAU,sBAAsB,YAAY,0BAA0B,IAAI,QAAQ;EACxF,MAAM,eAAe,kBAAkB,OAAO;EAC9C,MAAM,IAAI,kBAAkB;GAC3B,cAAc;GACd,YAAY,YAAY;GACxB,SAAS,yEAAyE,aAAa,KAAK,IAAI;GACxG,SAAS;IAAE;IAAS;GAAa;EAClC,CAAC;CACF,CACD;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,SAAgB,wBAAwB,GAAG,aAAsD;CAChG,MAAM,WAAW,mBAAmB,WAAW;CAC/C,OAAO,4BACL,gBAAiC;EACjC,MAAM,UAAU,mBAAmB,WAAW;EAC9C,OAAO,YAAY,QAAQ,sBAAsB,SAAS,QAAQ,MAAM;CACzE,IACC,gBAAiC;EACjC,MAAM,UAAU,sBAAsB,mBAAmB,WAAW,KAAK,IAAI,QAAQ;EACrF,MAAM,eAAe,kBAAkB,OAAO;EAC9C,MAAM,IAAI,kBAAkB;GAC3B,cAAc;GACd,YAAY,YAAY;GACxB,SAAS,+EAA+E,aAAa,KAAK,IAAI;GAC9G,SAAS;IAAE;IAAS;GAAa;EAClC,CAAC;CACF,CACD;AACD"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/utils.ts","../../src/ApplyOptions.ts","../../src/Enumerable.ts","../../src/RequiresContext.ts","../../src/RequiresPermissions.ts"],"sourcesContent":["/**\n * Utility to make a method decorator from a function.\n *\n * @remarks The decorator is returned with the signature it was given, rather than widened to `MethodDecorator`, so a\n * decorator built on top of this keeps whatever constraint it declares on its target.\n * @param fn The method to decorate.\n * @returns The decorator.\n * @example\n * ```typescript\n * // Enumerable function that will not append the property to the prototype:\n * function enumerableMethod(value: boolean) {\n * \treturn createMethodDecorator((_target: unknown, _propertyKey: string, descriptor: PropertyDescriptor) => {\n * \t\tdescriptor.enumerable = value;\n * \t});\n * }\n * ```\n */\nexport function createMethodDecorator<TFunction extends (...args: any[]) => unknown>(fn: TFunction): TFunction {\n\treturn fn;\n}\n\n/**\n * Utility to make a class decorator from a function.\n *\n * @remarks The decorator is returned with the signature it was given, rather than widened to `ClassDecorator`, so a\n * decorator built on top of this keeps whatever constraint it declares on its target, such as only accepting a\n * `Command` subclass.\n * @param fn The class to decorate.\n * @returns The decorator.\n * @see {@linkcode ApplyOptions}\n */\nexport function createClassDecorator<TFunction extends (...args: any[]) => unknown>(fn: TFunction): TFunction {\n\treturn fn;\n}\n\n/**\n * Creates a new proxy to efficiently add properties to a class without creating subclasses.\n *\n * @param target The constructor of the class to modify.\n * @param handler The handler function to modify the constructor behavior for the target.\n * @returns The proxy.\n */\nexport function createProxy<T extends object>(target: T, handler: Omit<ProxyHandler<T>, 'get'>): T {\n\treturn new Proxy(target, {\n\t\t...handler,\n\t\tget: (proxyTarget, property) => {\n\t\t\tconst value = Reflect.get(proxyTarget, property);\n\t\t\treturn typeof value === 'function' ? (...args: readonly unknown[]) => value.apply(proxyTarget, args) : value;\n\t\t}\n\t});\n}\n\n/**\n * Utility to make a method decorator with lighter syntax and inferred types.\n *\n * @remarks The decorated method is replaced by an `async` one, so it always returns a `Promise`, even when both the\n * precondition and the original method are synchronous.\n * @param precondition The predicate to run before the decorated method. It receives the same arguments as the method\n * and is called with the same `this`.\n * @param fallback The fallback to run when the precondition is not met. Defaults to a no-op returning `undefined`.\n * @returns The decorator.\n * @example\n * ```typescript\n * import { createFunctionPrecondition } from '@wolfstar/decorators';\n * import type { Command } from '@wolfstar/http-framework';\n *\n * const RequiresOwner = createFunctionPrecondition(\n * \t(interaction: Command.ChatInputInteraction) => interaction.user.id === process.env.OWNER_ID,\n * \t(interaction: Command.ChatInputInteraction) => interaction.reply({ content: 'Owner only.' })\n * );\n * ```\n */\nexport function createFunctionPrecondition(\n\tprecondition: (...args: any[]) => boolean | Promise<boolean>,\n\tfallback: (...args: any[]) => unknown = () => undefined\n): MethodDecorator {\n\treturn createMethodDecorator((_target: unknown, _propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n\t\tconst method = descriptor.value;\n\t\tif (!method) throw new Error('Function preconditions require a [[value]].');\n\t\tif (typeof method !== 'function') throw new Error('Function preconditions can only be applied to functions.');\n\n\t\tdescriptor.value = async function value(this: unknown, ...args: any[]) {\n\t\t\treturn (await precondition.apply(this, args)) ? method.apply(this, args) : fallback.apply(this, args);\n\t\t};\n\t}) as MethodDecorator;\n}\n","import type { LoaderPieceContext, PieceOptions } from '@wolfstar/http-framework';\nimport { createClassDecorator, createProxy } from './utils.js';\n\n/**\n * The constructor signature shared by every `Piece` of `@wolfstar/http-framework`, such as `Command`, `Listener`, and\n * `InteractionHandler`.\n */\nexport type PieceConstructor<Options extends PieceOptions = PieceOptions> = new (context: LoaderPieceContext, options?: Options) => unknown;\n\n/**\n * Decorator that sets the options of a `Piece`, such as a `Command`, a `Listener`, or an `InteractionHandler`.\n *\n * @remarks The options are merged on top of the ones the piece was constructed with, so a piece that also passes\n * options through `super(context, options)` will have the decorator's values win on conflicting keys.\n * @remarks Apply this decorator above (outside of) any other class decorator that keys metadata by class identity,\n * such as `RegisterCommand` from `@wolfstar/http-framework` — as in the example below. This decorator returns a `Proxy` wrapping the class,\n * so a decorator applied above it (running after it, and therefore registering against the proxy) would register\n * metadata that instances constructed from the exported class — whose `.constructor` still resolves to the original,\n * unproxied class — can never be looked up by.\n * @param optionsOrFn The options to pass to the piece's constructor, or a function that builds them from the loader\n * context.\n * @returns A class decorator.\n * @example\n * ```typescript\n * import { ApplyOptions } from '@wolfstar/decorators';\n * import { Command, RegisterCommand } from '@wolfstar/http-framework';\n *\n * (at)ApplyOptions<Command.Options>({ name: 'ping', enabled: true })\n * (at)RegisterCommand({ name: 'ping', description: 'A simple ping pong command' })\n * export class UserCommand extends Command {\n * \tpublic override chatInputRun(interaction: Command.ChatInputInteraction) {\n * \t\treturn interaction.reply({ content: 'Pong!' });\n * \t}\n * }\n * ```\n * @example\n * ```typescript\n * (at)ApplyOptions<Command.Options>(({ name }) => ({ name: name.toLowerCase() }))\n * export class UserCommand extends Command {}\n * ```\n */\nexport function ApplyOptions<Options extends PieceOptions = PieceOptions>(\n\toptionsOrFn: Options | ((context: LoaderPieceContext) => Options)\n): ClassDecorator {\n\treturn createClassDecorator((target: PieceConstructor<Options>) =>\n\t\tcreateProxy(target, {\n\t\t\tconstruct: (ctor, [context, baseOptions]: [LoaderPieceContext, Options | undefined], newTarget) =>\n\t\t\t\tReflect.construct(\n\t\t\t\t\tctor,\n\t\t\t\t\t[\n\t\t\t\t\t\tcontext,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t...baseOptions,\n\t\t\t\t\t\t\t...(typeof optionsOrFn === 'function' ? optionsOrFn(context) : optionsOrFn)\n\t\t\t\t\t\t}\n\t\t\t\t\t],\n\t\t\t\t\tnewTarget\n\t\t\t\t) as object\n\t\t})\n\t) as ClassDecorator;\n}\n","/**\n * Decorator that sets the `enumerable` property of a class field to the given value.\n *\n * @remarks The decorator installs a setter on the prototype, which is bypassed by the `Object.defineProperty` call\n * that `useDefineForClassFields` (enabled by `@sapphire/ts-config`, and the default from `ES2022` onwards) emits for\n * class fields. Mark the field as `declare` so no field definition is emitted, and assign it in the constructor.\n * @param value Whether the property should be enumerable or not.\n * @returns A property decorator.\n * @example\n * ```typescript\n * import { Enumerable } from '@wolfstar/decorators';\n * import { Command } from '@wolfstar/http-framework';\n *\n * export class UserCommand extends Command {\n * \t(at)Enumerable(false)\n * \tdeclare public cache: Map<string, string>;\n *\n * \tpublic constructor(context: Command.LoaderContext, options: Command.Options) {\n * \t\tsuper(context, options);\n * \t\tthis.cache = new Map();\n * \t}\n * }\n * ```\n */\nexport function Enumerable(value: boolean) {\n\treturn (target: unknown, key: string) => {\n\t\tReflect.defineProperty(target as object, key, {\n\t\t\tenumerable: value,\n\t\t\tset(this: unknown, val: unknown) {\n\t\t\t\tReflect.defineProperty(this as object, key, {\n\t\t\t\t\tconfigurable: true,\n\t\t\t\t\tenumerable: value,\n\t\t\t\t\tvalue: val,\n\t\t\t\t\twritable: true\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\t};\n}\n\n/**\n * Decorator that sets the `enumerable` property of a class method to the given value.\n *\n * @param value Whether the method should be enumerable or not.\n * @returns A method decorator.\n * @example\n * ```typescript\n * import { EnumerableMethod } from '@wolfstar/decorators';\n * import { Command } from '@wolfstar/http-framework';\n *\n * export class UserCommand extends Command {\n * \t(at)EnumerableMethod(true)\n * \tpublic getCacheKey(id: string) {\n * \t\treturn `user:${id}`;\n * \t}\n * }\n * ```\n */\nexport function EnumerableMethod(value: boolean) {\n\treturn (_target: unknown, _key: string, descriptor: PropertyDescriptor) => {\n\t\tdescriptor.enumerable = value;\n\t};\n}\n","import type { BaseInteraction } from '@wolfstar/http-framework';\nimport { createFunctionPrecondition } from './utils.js';\n\n/**\n * The fallback invoked when a context precondition is not met. It receives the same arguments as the decorated method.\n */\nexport type ContextFallback = (...args: any[]) => unknown;\n\n/**\n * Decorator that only runs the decorated method when the interaction was received from a guild.\n *\n * @param fallback The fallback to run when the interaction did not come from a guild. Defaults to a no-op, which\n * silently skips the method.\n * @returns A method decorator.\n * @example\n * ```typescript\n * import { RequiresGuildContext } from '@wolfstar/decorators';\n * import { Command, RegisterCommand } from '@wolfstar/http-framework';\n *\n * (at)RegisterCommand({ name: 'kick', description: 'Kicks a member' })\n * export class UserCommand extends Command {\n * \t(at)RequiresGuildContext((interaction: Command.ChatInputInteraction) =>\n * \t\tinteraction.reply({ content: 'This command can only be used in a server.' })\n * \t)\n * \tpublic override chatInputRun(interaction: Command.ChatInputInteraction) {\n * \t\treturn interaction.reply({ content: `Hello from ${interaction.guildId}!` });\n * \t}\n * }\n * ```\n */\nexport function RequiresGuildContext(fallback: ContextFallback = () => undefined): MethodDecorator {\n\treturn createFunctionPrecondition((interaction: BaseInteraction) => interaction.inGuild(), fallback);\n}\n\n/**\n * Decorator that only runs the decorated method when the interaction was **not** received from a guild, that is, from a\n * DM or from a user-installed app context.\n *\n * @param fallback The fallback to run when the interaction came from a guild. Defaults to a no-op, which silently skips\n * the method.\n * @returns A method decorator.\n * @example\n * ```typescript\n * import { RequiresDMContext } from '@wolfstar/decorators';\n * import { Command, RegisterCommand } from '@wolfstar/http-framework';\n *\n * (at)RegisterCommand({ name: 'private', description: 'Only usable outside of servers' })\n * export class UserCommand extends Command {\n * \t(at)RequiresDMContext((interaction: Command.ChatInputInteraction) =>\n * \t\tinteraction.reply({ content: 'This command cannot be used in a server.' })\n * \t)\n * \tpublic override chatInputRun(interaction: Command.ChatInputInteraction) {\n * \t\treturn interaction.reply({ content: 'Hello!' });\n * \t}\n * }\n * ```\n */\nexport function RequiresDMContext(fallback: ContextFallback = () => undefined): MethodDecorator {\n\treturn createFunctionPrecondition((interaction: BaseInteraction) => !interaction.inGuild(), fallback);\n}\n","import {\n\tgetMissingPermissions,\n\tIdentifiers,\n\tPreconditionError,\n\tresolvePermissions,\n\ttoPermissionNames,\n\ttype BaseInteraction,\n\ttype PermissionResolvable\n} from '@wolfstar/http-framework';\nimport { createFunctionPrecondition } from './utils.js';\n\n/**\n * Reads the permissions the invoking user has in the channel the interaction was sent from.\n *\n * @param interaction The interaction to read from.\n * @returns The bitfield of the user's permissions, or `null` when the interaction did not come from a guild and there\n * are therefore no guild permissions to check.\n */\nfunction getUserPermissions(interaction: BaseInteraction): bigint | null {\n\tconst permissions = interaction.member?.permissions;\n\treturn permissions === undefined ? null : BigInt(permissions);\n}\n\n/**\n * Decorator that only runs the decorated method when the application has all of the given permissions in the channel\n * the interaction was sent from, as reported by the interaction's `app_permissions` field.\n *\n * @remarks When the fallback is omitted, a {@linkcode PreconditionError} identified by\n * {@linkcode Identifiers.PreconditionClientPermissions} is thrown, which the client emits as `chatInputCommandDenied` or\n * `contextMenuCommandDenied` (or `interactionHandlerDenied`), not as `commandError`, for a `Listener` to turn into a\n * user-facing reply.\n * @param permissions The permissions the application must have.\n * @returns A method decorator.\n * @example\n * ```typescript\n * import { RequiresClientPermissions } from '@wolfstar/decorators';\n * import { Command, RegisterCommand } from '@wolfstar/http-framework';\n *\n * (at)RegisterCommand({ name: 'purge', description: 'Deletes messages' })\n * export class UserCommand extends Command {\n * \t(at)RequiresClientPermissions('ManageMessages')\n * \tpublic override chatInputRun(interaction: Command.ChatInputInteraction) {\n * \t\treturn interaction.reply({ content: 'Purging!' });\n * \t}\n * }\n * ```\n */\nexport function RequiresClientPermissions(...permissions: PermissionResolvable[]): MethodDecorator {\n\tconst required = resolvePermissions(permissions);\n\treturn createFunctionPrecondition(\n\t\t(interaction: BaseInteraction) => {\n\t\t\tconst granted = interaction.applicationPermissions;\n\t\t\t// `app_permissions` is always sent by Discord, but the field is optional in the typings; when it is absent\n\t\t\t// there is nothing to check against, so the method is allowed to run.\n\t\t\treturn granted === undefined || getMissingPermissions(granted, required) === 0n;\n\t\t},\n\t\t(interaction: BaseInteraction) => {\n\t\t\tconst missing = getMissingPermissions(interaction.applicationPermissions ?? 0n, required);\n\t\t\tconst missingNames = toPermissionNames(missing);\n\t\t\tthrow new PreconditionError({\n\t\t\t\tprecondition: 'ClientPermissions',\n\t\t\t\tidentifier: Identifiers.PreconditionClientPermissions,\n\t\t\t\tmessage: `Sorry, but I am not allowed to do that. I am missing the permissions: ${missingNames.join(', ')}`,\n\t\t\t\tcontext: { missing, missingNames }\n\t\t\t});\n\t\t}\n\t);\n}\n\n/**\n * Decorator that only runs the decorated method when the invoking user has all of the given permissions in the channel\n * the interaction was sent from.\n *\n * @remarks Interactions received outside of a guild carry no member permissions, so the check passes for them. Pair\n * this decorator with {@linkcode RequiresGuildContext} when the method must also be guild-only.\n * @remarks When the fallback is omitted, a {@linkcode PreconditionError} identified by\n * {@linkcode Identifiers.PreconditionUserPermissions} is thrown, which the client emits as `chatInputCommandDenied` or\n * `contextMenuCommandDenied` (or `interactionHandlerDenied`), not as `commandError`, for a `Listener` to turn into a\n * user-facing reply.\n * @param permissions The permissions the invoking user must have.\n * @returns A method decorator.\n * @example\n * ```typescript\n * import { RequiresUserPermissions } from '@wolfstar/decorators';\n * import { Command, RegisterCommand } from '@wolfstar/http-framework';\n *\n * (at)RegisterCommand({ name: 'ban', description: 'Bans a member' })\n * export class UserCommand extends Command {\n * \t(at)RequiresUserPermissions('BanMembers')\n * \tpublic override chatInputRun(interaction: Command.ChatInputInteraction) {\n * \t\treturn interaction.reply({ content: 'Banned!' });\n * \t}\n * }\n * ```\n */\nexport function RequiresUserPermissions(...permissions: PermissionResolvable[]): MethodDecorator {\n\tconst required = resolvePermissions(permissions);\n\treturn createFunctionPrecondition(\n\t\t(interaction: BaseInteraction) => {\n\t\t\tconst granted = getUserPermissions(interaction);\n\t\t\treturn granted === null || getMissingPermissions(granted, required) === 0n;\n\t\t},\n\t\t(interaction: BaseInteraction) => {\n\t\t\tconst missing = getMissingPermissions(getUserPermissions(interaction) ?? 0n, required);\n\t\t\tconst missingNames = toPermissionNames(missing);\n\t\t\tthrow new PreconditionError({\n\t\t\t\tprecondition: 'UserPermissions',\n\t\t\t\tidentifier: Identifiers.PreconditionUserPermissions,\n\t\t\t\tmessage: `Sorry, but you are not allowed to do that. You are missing the permissions: ${missingNames.join(', ')}`,\n\t\t\t\tcontext: { missing, missingNames }\n\t\t\t});\n\t\t}\n\t);\n}\n"],"mappings":"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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wolfstar/decorators",
3
- "version": "0.1.1",
3
+ "version": "0.1.2-next-20261007161851",
4
4
  "description": "Useful TypeScript decorators for @wolfstar/http-framework",
5
5
  "keywords": [
6
6
  "decorators",
@@ -45,7 +45,7 @@
45
45
  },
46
46
  "devDependencies": {
47
47
  "@vitest/coverage-v8": "^5.0.3",
48
- "@wolfstar/http-framework": "^6.2.2-next-20261007152629",
48
+ "@wolfstar/http-framework": "^6.3.0-next-20261007161851",
49
49
  "discord-api-types": "^0.38.8",
50
50
  "golar": "^0.1.10",
51
51
  "tsdown": "^0.23.0",
@@ -53,7 +53,7 @@
53
53
  "vitest": "^5.0.3"
54
54
  },
55
55
  "peerDependencies": {
56
- "@wolfstar/http-framework": "^6.2.2-next-20261007152629"
56
+ "@wolfstar/http-framework": "^6.3.0-next-20261007161851"
57
57
  },
58
58
  "engines": {
59
59
  "node": ">=20"