Skip to content

Commit

Permalink
feat(RESTPostAPIGuildChannelJSONBody): add default_auto_archive prop (
Browse files Browse the repository at this point in the history
  • Loading branch information
suneettipirneni committed Apr 15, 2022
1 parent e428085 commit 6a192b1
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 22 deletions.
11 changes: 6 additions & 5 deletions deno/rest/v10/guild.ts
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
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
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
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
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
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>>;

0 comments on commit 6a192b1

Please sign in to comment.