Add base model layout from V2 for frontend
This commit is contained in:
parent
634b80ed42
commit
53207abcb3
8 changed files with 51 additions and 0 deletions
32
resources/scripts/api/definitions/index.d.ts
vendored
Normal file
32
resources/scripts/api/definitions/index.d.ts
vendored
Normal file
|
@ -0,0 +1,32 @@
|
|||
import { MarkRequired } from 'ts-essentials';
|
||||
|
||||
export type UUID = string;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
||||
export interface Model {}
|
||||
|
||||
interface ModelWithRelationships extends Model {
|
||||
relationships: Record<string, unknown>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows a model to have optional relationships that are marked as being
|
||||
* present in a given pathway. This allows different API calls to specify the
|
||||
* "completeness" of a response object without having to make every API return
|
||||
* the same information, or every piece of logic do explicit null checking.
|
||||
*
|
||||
* Example:
|
||||
* >> const user: WithLoaded<User, 'servers'> = {};
|
||||
* >> // "user.servers" is no longer potentially undefined.
|
||||
*/
|
||||
type WithLoaded<M extends ModelWithRelationships, R extends keyof M['relationships']> = M & {
|
||||
relationships: MarkRequired<M['relationships'], R>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper type that allows you to infer the type of an object by giving
|
||||
* it the specific API request function with a return type. For example:
|
||||
*
|
||||
* type Egg = InferModel<typeof getEgg>;
|
||||
*/
|
||||
export type InferModel<T extends (...args: any) => any> = ReturnType<T> extends Promise<infer U> ? U : T;
|
2
resources/scripts/api/definitions/user/index.ts
Normal file
2
resources/scripts/api/definitions/user/index.ts
Normal file
|
@ -0,0 +1,2 @@
|
|||
export * from './models.d';
|
||||
export { default as Transformers, MetaTransformers } from './transformers';
|
2
resources/scripts/api/definitions/user/models.d.ts
vendored
Normal file
2
resources/scripts/api/definitions/user/models.d.ts
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
// empty export
|
||||
export type _T = string;
|
5
resources/scripts/api/definitions/user/transformers.ts
Normal file
5
resources/scripts/api/definitions/user/transformers.ts
Normal file
|
@ -0,0 +1,5 @@
|
|||
export default class Transformers {
|
||||
}
|
||||
|
||||
export class MetaTransformers {
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue