Skip to content

Commit

Permalink
types: fix fetch options types
Browse files Browse the repository at this point in the history
  • Loading branch information
sdanialraza committed Oct 14, 2024
1 parent f8747dc commit 1d66e02
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
2 changes: 2 additions & 0 deletions packages/discord.js/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ exports.ReactionManager = require('./managers/ReactionManager');
exports.ReactionUserManager = require('./managers/ReactionUserManager');
exports.RoleManager = require('./managers/RoleManager');
exports.StageInstanceManager = require('./managers/StageInstanceManager');
exports.SubscriptionManager = require('./managers/SubscriptionManager');
exports.ThreadManager = require('./managers/ThreadManager');
exports.ThreadMemberManager = require('./managers/ThreadMemberManager');
exports.UserManager = require('./managers/UserManager');
Expand Down Expand Up @@ -193,6 +194,7 @@ exports.SKU = require('./structures/SKU').SKU;
exports.StringSelectMenuOptionBuilder = require('./structures/StringSelectMenuOptionBuilder');
exports.StageChannel = require('./structures/StageChannel');
exports.StageInstance = require('./structures/StageInstance').StageInstance;
exports.Subscription = require('./structures/Subscription');
exports.Sticker = require('./structures/Sticker').Sticker;
exports.StickerPack = require('./structures/StickerPack');
exports.Team = require('./structures/Team');
Expand Down
17 changes: 11 additions & 6 deletions packages/discord.js/src/managers/SubscriptionManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,33 @@ class SubscriptionManager extends CachedManager {
* @name SubscriptionManager#cache
*/

/**
* Options used to fetch a subscription
* @typedef {BaseFetchOptions} FetchSubscriptionOptions
* @property {SKUResolvable} sku The SKU to fetch the subscription for
* @property {Snowflake} subscriptionId The id of the subscription to fetch
*/

/**
* Options used to fetch subscriptions
* @typedef {Object} FetchSubscriptionsOptions
* @property {Snowflake} [after] Consider only subscriptions after this subscription id
* @property {Snowflake} [before] Consider only subscriptions before this subscription id
* @property {number} [limit=50] The maximum number of subscriptions to fetch
* @property {SKUResolvable} sku The SKU to fetch subscriptions for
* @property {Snowflake} [subscriptionId] The subscription id to fetch
* @property {UserResolvable} user The user to fetch entitlements for
* @property {boolean} [cache=true] Whether to cache the fetched subscriptions
* @property {Snowflake} [before] Consider only subscriptions before this subscription id
* @property {Snowflake} [after] Consider only subscriptions after this subscription id
* <warn>If both `before` and `after` are provided, only `before` is respected</warn>
*/

/**
* Fetches subscriptions for this application
* @param {FetchSubscriptionsOptions} [options={}] Options for fetching the subscriptions
* @param {FetchSubscriptionOptions|FetchSubscriptionsOptions} [options={}] Options for fetching the subscriptions
* @returns {Promise<Collection<Snowflake, Subscription>>}
*/
async fetch(options = {}) {
if (typeof options !== 'object') throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'options', 'object', true);

const { limit = 50, sku, subscriptionId, user, cache = true, before, after } = options;
const { after, before, cache = true, limit = 50, sku, subscriptionId, user } = options;

const skuId = resolveSKUId(sku);

Expand Down
15 changes: 8 additions & 7 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4094,22 +4094,23 @@ export class EntitlementManager extends CachedManager<Snowflake, Entitlement, En
public consume(entitlementId: Snowflake): Promise<void>;
}

export interface FetchSubscriptionOptions extends BaseFetchOptions {
sku: SKUResolvable;
subscriptionId: Snowflake;
}

export interface FetchSubscriptionsOptions {
after?: Snowflake;
before?: Snowflake;
limit?: number;
sku: SKUResolvable;
subscriptionId?: undefined;
user: UserResolvable;
cache?: boolean;
before?: Snowflake;
after?: Snowflake;
}

export class SubscriptionManager extends CachedManager<Snowflake, Subscription, SubscriptionResolvable> {
private constructor(client: Client<true>, iterable?: Iterable<APISubscription>);
public fetch(options: FetchSubscriptionOptions): Promise<Subscription>;
public fetch(options: FetchSubscriptionsOptions): Promise<Collection<Snowflake, Subscription>>;
public fetch(
options: Omit<FetchSubscriptionsOptions, 'subscriptionId'> & { subscriptionId: Snowflake },
): Promise<Subscription>;
}

export interface FetchGuildApplicationCommandFetchOptions extends Omit<FetchApplicationCommandOptions, 'guildId'> {}
Expand Down

0 comments on commit 1d66e02

Please sign in to comment.