Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/resources/scripts/api/definitions/index.d.ts
7461 views
1
import { MarkRequired } from 'ts-essentials';
2
import { FractalResponseData, FractalResponseList } from '../http';
3
4
export type UUID = string;
5
6
// eslint-disable-next-line @typescript-eslint/no-empty-interface
7
export interface Model {}
8
9
interface ModelWithRelationships extends Model {
10
relationships: Record<string, FractalResponseData | FractalResponseList | undefined>;
11
}
12
13
/**
14
* Allows a model to have optional relationships that are marked as being
15
* present in a given pathway. This allows different API calls to specify the
16
* "completeness" of a response object without having to make every API return
17
* the same information, or every piece of logic do explicit null checking.
18
*
19
* Example:
20
* >> const user: WithLoaded<User, 'servers'> = {};
21
* >> // "user.servers" is no longer potentially undefined.
22
*/
23
type WithLoaded<M extends ModelWithRelationships, R extends keyof M['relationships']> = M & {
24
relationships: MarkRequired<M['relationships'], R>;
25
};
26
27
/**
28
* Helper type that allows you to infer the type of an object by giving
29
* it the specific API request function with a return type. For example:
30
*
31
* type Egg = InferModel<typeof getEgg>;
32
*/
33
export type InferModel<T extends (...args: any) => any> = ReturnType<T> extends Promise<infer U> ? U : T;
34
35