Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(RESTPostAPIGuildChannelJSONBody): add default_auto_archive_duration prop #400

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 6 additions & 5 deletions deno/rest/v10/guild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ import type {
} from '../../payloads/v10/mod.ts';
import type {
AddUndefinedToPossiblyUndefinedPropertiesOfInterface,
DistributiveOmit,
DistributivePick,
Nullable,
StrictPartial,
StrictRequired,
UnionToIntersection,
} from '../../utils/internals.ts';

export interface APIGuildCreateOverwrite extends RESTPutAPIChannelPermissionJSONBody {
Expand All @@ -38,9 +39,9 @@ export interface APIGuildCreateOverwrite extends RESTPutAPIChannelPermissionJSON

export type APIGuildChannelResolvable = Exclude<APIChannel, APIDMChannel | APIGroupDMChannel>;
export type APIGuildCreatePartialChannel = StrictPartial<
Pick<
UnionToIntersection<APIGuildChannelResolvable>,
'type' | 'topic' | 'nsfw' | 'bitrate' | 'user_limit' | 'rate_limit_per_user'
DistributivePick<
APIGuildChannelResolvable,
'type' | 'topic' | 'nsfw' | 'bitrate' | 'user_limit' | 'rate_limit_per_user' | 'default_auto_archive_duration'
>
> &
AddUndefinedToPossiblyUndefinedPropertiesOfInterface<{
Expand Down Expand Up @@ -291,7 +292,7 @@ export type RESTGetAPIGuildChannelsResult = APIChannel[];
/**
* https://discord.com/developers/docs/resources/guild#create-guild-channel
*/
export type RESTPostAPIGuildChannelJSONBody = Omit<APIGuildCreatePartialChannel, 'id'>;
export type RESTPostAPIGuildChannelJSONBody = DistributiveOmit<APIGuildCreatePartialChannel, 'id'>;

/**
* https://discord.com/developers/docs/resources/guild#create-guild-channel
Expand Down
11 changes: 6 additions & 5 deletions deno/rest/v9/guild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ import type {
} from '../../payloads/v9/mod.ts';
import type {
AddUndefinedToPossiblyUndefinedPropertiesOfInterface,
DistributiveOmit,
DistributivePick,
Nullable,
StrictPartial,
StrictRequired,
UnionToIntersection,
} from '../../utils/internals.ts';

export interface APIGuildCreateOverwrite extends RESTPutAPIChannelPermissionJSONBody {
Expand All @@ -38,9 +39,9 @@ export interface APIGuildCreateOverwrite extends RESTPutAPIChannelPermissionJSON

export type APIGuildChannelResolvable = Exclude<APIChannel, APIDMChannel | APIGroupDMChannel>;
export type APIGuildCreatePartialChannel = StrictPartial<
Pick<
UnionToIntersection<APIGuildChannelResolvable>,
'type' | 'topic' | 'nsfw' | 'bitrate' | 'user_limit' | 'rate_limit_per_user'
DistributivePick<
APIGuildChannelResolvable,
'type' | 'topic' | 'nsfw' | 'bitrate' | 'user_limit' | 'rate_limit_per_user' | 'default_auto_archive_duration'
>
> &
AddUndefinedToPossiblyUndefinedPropertiesOfInterface<{
Expand Down Expand Up @@ -291,7 +292,7 @@ export type RESTGetAPIGuildChannelsResult = APIChannel[];
/**
* https://discord.com/developers/docs/resources/guild#create-guild-channel
*/
export type RESTPostAPIGuildChannelJSONBody = Omit<APIGuildCreatePartialChannel, 'id'>;
export type RESTPostAPIGuildChannelJSONBody = DistributiveOmit<APIGuildCreatePartialChannel, 'id'>;

/**
* https://discord.com/developers/docs/resources/guild#create-guild-channel
Expand Down
24 changes: 23 additions & 1 deletion deno/utils/internals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,26 @@ export type StrictPartial<Base> = AddUndefinedToPossiblyUndefinedPropertiesOfInt

export type StrictRequired<Base> = Required<{ [K in keyof Base]: Exclude<Base[K], undefined> }>;

export type UnionToIntersection<T> = (T extends any ? (x: T) => any : never) extends (x: infer R) => any ? R : never;
export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;

type Keys<T> = keyof T;
type DistributiveKeys<T> = T extends unknown ? Keys<T> : never;
/**
* Allows picking of keys from unions that are disjoint
*/
export type DistributivePick<T, K extends DistributiveKeys<T>> = T extends unknown
? keyof Pick_<T, K> extends never
? never
: { [P in keyof Pick_<T, K>]: Pick_<T, K>[P] }
: never;

type Pick_<T, K> = Pick<T, Extract<keyof T, K>>;

/**
* Allows omitting of keys from unions that are disjoint
*/
export type DistributiveOmit<T, K extends DistributiveKeys<T>> = T extends unknown
? { [P in keyof Omit_<T, K>]: Omit_<T, K>[P] }
: never;

type Omit_<T, K> = Omit<T, Extract<keyof T, K>>;
11 changes: 6 additions & 5 deletions rest/v10/guild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ import type {
} from '../../payloads/v10/index';
import type {
AddUndefinedToPossiblyUndefinedPropertiesOfInterface,
DistributiveOmit,
DistributivePick,
Nullable,
StrictPartial,
StrictRequired,
UnionToIntersection,
} from '../../utils/internals';

export interface APIGuildCreateOverwrite extends RESTPutAPIChannelPermissionJSONBody {
Expand All @@ -38,9 +39,9 @@ export interface APIGuildCreateOverwrite extends RESTPutAPIChannelPermissionJSON

export type APIGuildChannelResolvable = Exclude<APIChannel, APIDMChannel | APIGroupDMChannel>;
export type APIGuildCreatePartialChannel = StrictPartial<
Pick<
UnionToIntersection<APIGuildChannelResolvable>,
'type' | 'topic' | 'nsfw' | 'bitrate' | 'user_limit' | 'rate_limit_per_user'
DistributivePick<
APIGuildChannelResolvable,
'type' | 'topic' | 'nsfw' | 'bitrate' | 'user_limit' | 'rate_limit_per_user' | 'default_auto_archive_duration'
>
> &
AddUndefinedToPossiblyUndefinedPropertiesOfInterface<{
Expand Down Expand Up @@ -291,7 +292,7 @@ export type RESTGetAPIGuildChannelsResult = APIChannel[];
/**
* https://discord.com/developers/docs/resources/guild#create-guild-channel
*/
export type RESTPostAPIGuildChannelJSONBody = Omit<APIGuildCreatePartialChannel, 'id'>;
export type RESTPostAPIGuildChannelJSONBody = DistributiveOmit<APIGuildCreatePartialChannel, 'id'>;

/**
* https://discord.com/developers/docs/resources/guild#create-guild-channel
Expand Down
11 changes: 6 additions & 5 deletions rest/v9/guild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ import type {
} from '../../payloads/v9/index';
import type {
AddUndefinedToPossiblyUndefinedPropertiesOfInterface,
DistributiveOmit,
DistributivePick,
Nullable,
StrictPartial,
StrictRequired,
UnionToIntersection,
} from '../../utils/internals';

export interface APIGuildCreateOverwrite extends RESTPutAPIChannelPermissionJSONBody {
Expand All @@ -38,9 +39,9 @@ export interface APIGuildCreateOverwrite extends RESTPutAPIChannelPermissionJSON

export type APIGuildChannelResolvable = Exclude<APIChannel, APIDMChannel | APIGroupDMChannel>;
export type APIGuildCreatePartialChannel = StrictPartial<
Pick<
UnionToIntersection<APIGuildChannelResolvable>,
'type' | 'topic' | 'nsfw' | 'bitrate' | 'user_limit' | 'rate_limit_per_user'
DistributivePick<
APIGuildChannelResolvable,
'type' | 'topic' | 'nsfw' | 'bitrate' | 'user_limit' | 'rate_limit_per_user' | 'default_auto_archive_duration'
>
> &
AddUndefinedToPossiblyUndefinedPropertiesOfInterface<{
Expand Down Expand Up @@ -291,7 +292,7 @@ export type RESTGetAPIGuildChannelsResult = APIChannel[];
/**
* https://discord.com/developers/docs/resources/guild#create-guild-channel
*/
export type RESTPostAPIGuildChannelJSONBody = Omit<APIGuildCreatePartialChannel, 'id'>;
export type RESTPostAPIGuildChannelJSONBody = DistributiveOmit<APIGuildCreatePartialChannel, 'id'>;

/**
* https://discord.com/developers/docs/resources/guild#create-guild-channel
Expand Down
24 changes: 23 additions & 1 deletion utils/internals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,26 @@ export type StrictPartial<Base> = AddUndefinedToPossiblyUndefinedPropertiesOfInt

export type StrictRequired<Base> = Required<{ [K in keyof Base]: Exclude<Base[K], undefined> }>;

export type UnionToIntersection<T> = (T extends any ? (x: T) => any : never) extends (x: infer R) => any ? R : never;
export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;

type Keys<T> = keyof T;
type DistributiveKeys<T> = T extends unknown ? Keys<T> : never;
/**
* Allows picking of keys from unions that are disjoint
*/
export type DistributivePick<T, K extends DistributiveKeys<T>> = T extends unknown
? keyof Pick_<T, K> extends never
? never
: { [P in keyof Pick_<T, K>]: Pick_<T, K>[P] }
: never;

type Pick_<T, K> = Pick<T, Extract<keyof T, K>>;

/**
* Allows omitting of keys from unions that are disjoint
*/
export type DistributiveOmit<T, K extends DistributiveKeys<T>> = T extends unknown
? { [P in keyof Omit_<T, K>]: Omit_<T, K>[P] }
: never;

type Omit_<T, K> = Omit<T, Extract<keyof T, K>>;