Skip to content

Commit 53207ab

Browse files
committed
Add base model layout from V2 for frontend
1 parent 634b80e commit 53207ab

File tree

8 files changed

+51
-0
lines changed

8 files changed

+51
-0
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
"style-loader": "^1.2.1",
9898
"svg-url-loader": "^6.0.0",
9999
"terser-webpack-plugin": "^3.0.6",
100+
"ts-essentials": "^9.1.2",
100101
"twin.macro": "^2.0.7",
101102
"typescript": "^4.2.4",
102103
"webpack": "^4.43.0",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { MarkRequired } from 'ts-essentials';
2+
3+
export type UUID = string;
4+
5+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
6+
export interface Model {}
7+
8+
interface ModelWithRelationships extends Model {
9+
relationships: Record<string, unknown>;
10+
}
11+
12+
/**
13+
* Allows a model to have optional relationships that are marked as being
14+
* present in a given pathway. This allows different API calls to specify the
15+
* "completeness" of a response object without having to make every API return
16+
* the same information, or every piece of logic do explicit null checking.
17+
*
18+
* Example:
19+
* >> const user: WithLoaded<User, 'servers'> = {};
20+
* >> // "user.servers" is no longer potentially undefined.
21+
*/
22+
type WithLoaded<M extends ModelWithRelationships, R extends keyof M['relationships']> = M & {
23+
relationships: MarkRequired<M['relationships'], R>;
24+
}
25+
26+
/**
27+
* Helper type that allows you to infer the type of an object by giving
28+
* it the specific API request function with a return type. For example:
29+
*
30+
* type Egg = InferModel<typeof getEgg>;
31+
*/
32+
export type InferModel<T extends (...args: any) => any> = ReturnType<T> extends Promise<infer U> ? U : T;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './models.d';
2+
export { default as Transformers, MetaTransformers } from './transformers';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// empty export
2+
export type _T = string;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export default class Transformers {
2+
}
3+
4+
export class MetaTransformers {
5+
}

tsconfig.json

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
"@/*": [
2323
"./resources/scripts/*"
2424
],
25+
"@definitions/*": [
26+
"./resources/scripts/api/definitions/*"
27+
],
2528
"@feature/*": [
2629
"./resources/scripts/components/server/features/*"
2730
]

webpack.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ module.exports = {
6060
extensions: ['.ts', '.tsx', '.js', '.json'],
6161
alias: {
6262
'@': path.join(__dirname, '/resources/scripts'),
63+
'@definitions': path.join(__dirname, '/resources/scripts/api/definitions'),
6364
'@feature': path.join(__dirname, '/resources/scripts/components/server/features'),
6465
},
6566
symlinks: false,

yarn.lock

+5
Original file line numberDiff line numberDiff line change
@@ -7481,6 +7481,11 @@ tryer@^1.0.1:
74817481
resolved "https://registry.yarnpkg.com/tryer/-/tryer-1.0.1.tgz#f2c85406800b9b0f74c9f7465b81eaad241252f8"
74827482
integrity sha512-c3zayb8/kWWpycWYg87P71E1S1ZL6b6IJxfb5fvsUgsf0S2MVGaDhDXXjDMpdCpfWXqptc+4mXwmiy1ypXqRAA==
74837483

7484+
ts-essentials@^9.1.2:
7485+
version "9.1.2"
7486+
resolved "https://registry.yarnpkg.com/ts-essentials/-/ts-essentials-9.1.2.tgz#46db6944b73b4cd603f3d959ef1123c16ba56f59"
7487+
integrity sha512-EaSmXsAhEiirrTY1Oaa7TSpei9dzuCuFPmjKRJRPamERYtfaGS8/KpOSbjergLz/Y76/aZlV9i/krgzsuWEBbg==
7488+
74847489
ts-toolbelt@^8.0.7:
74857490
version "8.0.7"
74867491
resolved "https://registry.yarnpkg.com/ts-toolbelt/-/ts-toolbelt-8.0.7.tgz#4dad2928831a811ee17dbdab6eb1919fc0a295bf"

0 commit comments

Comments
 (0)