feat: setup barrelsby for automatic barrel file generation
Add barrelsby as a dev dependency with a `generate-barrels` npm script and a `barrelesby.json` config targeting `./src`. This automates creation of barrel/index files to simplify imports across the project.
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* 登录响应
|
||||
* 原始 Dart: LoginResponse (lib/data/models/auth/auth_response.dart)
|
||||
*/
|
||||
import { User } from "../user/user";
|
||||
|
||||
export class LoginResponse {
|
||||
readonly user: User;
|
||||
readonly token: string;
|
||||
readonly refreshToken: string;
|
||||
|
||||
constructor(params: { user: User; token: string; refreshToken?: string }) {
|
||||
this.user = params.user;
|
||||
this.token = params.token;
|
||||
this.refreshToken = params.refreshToken ?? "";
|
||||
Object.freeze(this);
|
||||
}
|
||||
|
||||
toJson(): Record<string, unknown> {
|
||||
return {
|
||||
user: this.user.toJson(),
|
||||
token: this.token,
|
||||
refreshToken: this.refreshToken,
|
||||
};
|
||||
}
|
||||
|
||||
static fromJson(json: Record<string, unknown>): LoginResponse {
|
||||
const token = json.token;
|
||||
if (typeof token !== "string") {
|
||||
throw new Error("LoginResponse.token is required and must be a string");
|
||||
}
|
||||
const userJson = json.user;
|
||||
if (typeof userJson !== "object" || userJson === null) {
|
||||
throw new Error("LoginResponse.user is required and must be an object");
|
||||
}
|
||||
return new LoginResponse({
|
||||
user: User.fromJson(userJson as Record<string, unknown>),
|
||||
token,
|
||||
refreshToken:
|
||||
typeof json.refreshToken === "string" ? json.refreshToken : undefined,
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user