-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Core] Cleanup types, remove unused types and enable marking a Resour…
…ce as protected
- Loading branch information
Showing
5 changed files
with
32 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@blizzard-api/core': patch | ||
--- | ||
|
||
Cleanup types, remove unused types and enable marking a Resource as protected |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,30 @@ | ||
import type { BlizzardNamespaces } from './namespace'; | ||
import type { ClientOptions } from './request'; | ||
|
||
export interface Resource<_Response = void> { | ||
/** | ||
* Represents a resource that can be requested from the Blizzard API | ||
* @param _Response The response type of the resource | ||
* @param ProtectedResource Whether the resource requires a token to be requested | ||
*/ | ||
export type Resource<_Response, ProtectedResource extends boolean = false> = { | ||
path: string; | ||
namespace?: BlizzardNamespaces; | ||
} | ||
export type ResourceResponse<T = unknown> = Promise<T>; | ||
} & (ProtectedResource extends true ? { token: string } : unknown); | ||
|
||
export type ResourceOptions<T = unknown> = Partial<ClientOptions> & T; | ||
/** | ||
* Represents the response of a resource | ||
* @param T The response type of the resource | ||
* @example | ||
* type response = ResourceResponse<{ id: number }>; | ||
* const response: response = Promise.resolve({ id: 1 }); | ||
* response.then((data) => console.log(data.id)); | ||
*/ | ||
export type ResourceResponse<T = unknown> = Promise<T>; | ||
|
||
export type ProtectedResourceOptions<T = unknown> = Partial<ClientOptions> & { token: string } & T; | ||
/** | ||
* Extracts the response type from a resource | ||
* @param Type The resource type | ||
* @returns The response type | ||
* @example | ||
* type extracted = ExtractResourceType<Resource<{ id: number }>>; | ||
*/ | ||
export type ExtractResourceType<Type> = Type extends Resource<infer R> ? R : never; |