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,37 @@
|
||||
/**
|
||||
* Apple 登录请求
|
||||
* 原始 Dart: AppleLoginRequest (lib/data/models/auth/auth_request.dart)
|
||||
*/
|
||||
export class AppleLoginRequest {
|
||||
readonly identityToken: string;
|
||||
readonly platform: string;
|
||||
|
||||
constructor(params: { identityToken: string; platform: string }) {
|
||||
this.identityToken = params.identityToken;
|
||||
this.platform = params.platform;
|
||||
Object.freeze(this);
|
||||
}
|
||||
|
||||
toJson(): Record<string, unknown> {
|
||||
return {
|
||||
identityToken: this.identityToken,
|
||||
platform: this.platform,
|
||||
};
|
||||
}
|
||||
|
||||
static fromJson(json: Record<string, unknown>): AppleLoginRequest {
|
||||
const requireString = (key: string): string => {
|
||||
const v = json[key];
|
||||
if (typeof v !== "string") {
|
||||
throw new Error(
|
||||
`AppleLoginRequest.${key} is required and must be a string`
|
||||
);
|
||||
}
|
||||
return v;
|
||||
};
|
||||
return new AppleLoginRequest({
|
||||
identityToken: requireString("identityToken"),
|
||||
platform: requireString("platform"),
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* Facebook 登录请求
|
||||
* 原始 Dart: FacebookLoginRequest (lib/data/models/auth/auth_request.dart)
|
||||
*
|
||||
* 注:原始 Dart 中 `guestId` 为 `String?`,按"全部非空"约定统一兜底为空串。
|
||||
*/
|
||||
export class FacebookLoginRequest {
|
||||
readonly accessToken: string;
|
||||
readonly platform: string;
|
||||
readonly guestId: string;
|
||||
|
||||
constructor(params: {
|
||||
accessToken: string;
|
||||
platform: string;
|
||||
guestId?: string;
|
||||
}) {
|
||||
this.accessToken = params.accessToken;
|
||||
this.platform = params.platform;
|
||||
this.guestId = params.guestId ?? "";
|
||||
Object.freeze(this);
|
||||
}
|
||||
|
||||
toJson(): Record<string, unknown> {
|
||||
return {
|
||||
accessToken: this.accessToken,
|
||||
platform: this.platform,
|
||||
guestId: this.guestId,
|
||||
};
|
||||
}
|
||||
|
||||
static fromJson(json: Record<string, unknown>): FacebookLoginRequest {
|
||||
const requireString = (key: string): string => {
|
||||
const v = json[key];
|
||||
if (typeof v !== "string") {
|
||||
throw new Error(
|
||||
`FacebookLoginRequest.${key} is required and must be a string`
|
||||
);
|
||||
}
|
||||
return v;
|
||||
};
|
||||
return new FacebookLoginRequest({
|
||||
accessToken: requireString("accessToken"),
|
||||
platform: requireString("platform"),
|
||||
guestId: typeof json.guestId === "string" ? json.guestId : undefined,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Facebook ID 登录请求
|
||||
* 原始 Dart: FbIdLoginRequest (lib/data/models/auth/auth_request.dart)
|
||||
*
|
||||
* 注:原始 Dart 中 `avatarUrl` 为 `String?`,按"全部非空"约定统一兜底为空串。
|
||||
*/
|
||||
export class FbIdLoginRequest {
|
||||
readonly fbId: string;
|
||||
readonly avatarUrl: string;
|
||||
|
||||
constructor(params: { fbId: string; avatarUrl?: string }) {
|
||||
this.fbId = params.fbId;
|
||||
this.avatarUrl = params.avatarUrl ?? "";
|
||||
Object.freeze(this);
|
||||
}
|
||||
|
||||
toJson(): Record<string, unknown> {
|
||||
return {
|
||||
fbId: this.fbId,
|
||||
avatarUrl: this.avatarUrl,
|
||||
};
|
||||
}
|
||||
|
||||
static fromJson(json: Record<string, unknown>): FbIdLoginRequest {
|
||||
const fbId = json.fbId;
|
||||
if (typeof fbId !== "string") {
|
||||
throw new Error(
|
||||
"FbIdLoginRequest.fbId is required and must be a string"
|
||||
);
|
||||
}
|
||||
return new FbIdLoginRequest({
|
||||
fbId,
|
||||
avatarUrl:
|
||||
typeof json.avatarUrl === "string" ? json.avatarUrl : undefined,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* Google 登录请求
|
||||
* 原始 Dart: GoogleLoginRequest (lib/data/models/auth/auth_request.dart)
|
||||
*
|
||||
* 注:原始 Dart 中 `guestId` 为 `String?`,按"全部非空"约定统一兜底为空串。
|
||||
*/
|
||||
export class GoogleLoginRequest {
|
||||
readonly idToken: string;
|
||||
readonly platform: string;
|
||||
readonly guestId: string;
|
||||
|
||||
constructor(params: {
|
||||
idToken: string;
|
||||
platform: string;
|
||||
guestId?: string;
|
||||
}) {
|
||||
this.idToken = params.idToken;
|
||||
this.platform = params.platform;
|
||||
this.guestId = params.guestId ?? "";
|
||||
Object.freeze(this);
|
||||
}
|
||||
|
||||
toJson(): Record<string, unknown> {
|
||||
return {
|
||||
idToken: this.idToken,
|
||||
platform: this.platform,
|
||||
guestId: this.guestId,
|
||||
};
|
||||
}
|
||||
|
||||
static fromJson(json: Record<string, unknown>): GoogleLoginRequest {
|
||||
const requireString = (key: string): string => {
|
||||
const v = json[key];
|
||||
if (typeof v !== "string") {
|
||||
throw new Error(
|
||||
`GoogleLoginRequest.${key} is required and must be a string`
|
||||
);
|
||||
}
|
||||
return v;
|
||||
};
|
||||
return new GoogleLoginRequest({
|
||||
idToken: requireString("idToken"),
|
||||
platform: requireString("platform"),
|
||||
guestId: typeof json.guestId === "string" ? json.guestId : undefined,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* 游客登录请求
|
||||
* 原始 Dart: GuestLoginRequest (lib/data/models/auth/auth_request.dart)
|
||||
*/
|
||||
export class GuestLoginRequest {
|
||||
readonly deviceId: string;
|
||||
|
||||
constructor(params: { deviceId: string }) {
|
||||
this.deviceId = params.deviceId;
|
||||
Object.freeze(this);
|
||||
}
|
||||
|
||||
toJson(): Record<string, unknown> {
|
||||
return { deviceId: this.deviceId };
|
||||
}
|
||||
|
||||
static fromJson(json: Record<string, unknown>): GuestLoginRequest {
|
||||
const deviceId = json.deviceId;
|
||||
if (typeof deviceId !== "string") {
|
||||
throw new Error(
|
||||
"GuestLoginRequest.deviceId is required and must be a string"
|
||||
);
|
||||
}
|
||||
return new GuestLoginRequest({ deviceId });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/**
|
||||
* 游客登录响应
|
||||
* 原始 Dart: GuestLoginResponse (lib/data/models/auth/auth_response.dart)
|
||||
*
|
||||
* 注:原始 Dart 中 `user` 为 `User?`,按"全部非空"约定兜底为默认 User 实例
|
||||
* (id/username 为空串,使用方可通过 user.id === "" 判定无用户数据)。
|
||||
*/
|
||||
import { User } from "../user/user";
|
||||
|
||||
export class GuestLoginResponse {
|
||||
readonly token: string;
|
||||
readonly deviceId: string;
|
||||
readonly userId: string;
|
||||
readonly isDeviceUser: boolean;
|
||||
readonly expiresIn: number;
|
||||
readonly user: User;
|
||||
|
||||
constructor(params: {
|
||||
token: string;
|
||||
deviceId: string;
|
||||
userId: string;
|
||||
isDeviceUser?: boolean;
|
||||
expiresIn?: number;
|
||||
user?: User;
|
||||
}) {
|
||||
this.token = params.token;
|
||||
this.deviceId = params.deviceId;
|
||||
this.userId = params.userId;
|
||||
this.isDeviceUser = params.isDeviceUser ?? true;
|
||||
this.expiresIn = params.expiresIn ?? 2592000;
|
||||
this.user = params.user ?? new User({ id: "", username: "" });
|
||||
Object.freeze(this);
|
||||
}
|
||||
|
||||
toJson(): Record<string, unknown> {
|
||||
return {
|
||||
token: this.token,
|
||||
deviceId: this.deviceId,
|
||||
userId: this.userId,
|
||||
isDeviceUser: this.isDeviceUser,
|
||||
expiresIn: this.expiresIn,
|
||||
user: this.user.toJson(),
|
||||
};
|
||||
}
|
||||
|
||||
static fromJson(json: Record<string, unknown>): GuestLoginResponse {
|
||||
const requireString = (key: string): string => {
|
||||
const v = json[key];
|
||||
if (typeof v !== "string") {
|
||||
throw new Error(
|
||||
`GuestLoginResponse.${key} is required and must be a string`
|
||||
);
|
||||
}
|
||||
return v;
|
||||
};
|
||||
const userJson = json.user;
|
||||
const user: User =
|
||||
typeof userJson === "object" && userJson !== null
|
||||
? User.fromJson(userJson as Record<string, unknown>)
|
||||
: new User({ id: "", username: "" });
|
||||
return new GuestLoginResponse({
|
||||
token: requireString("token"),
|
||||
deviceId: requireString("deviceId"),
|
||||
userId: requireString("userId"),
|
||||
isDeviceUser:
|
||||
typeof json.isDeviceUser === "boolean"
|
||||
? json.isDeviceUser
|
||||
: undefined,
|
||||
expiresIn: typeof json.expiresIn === "number" ? json.expiresIn : undefined,
|
||||
user,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// auth 子目录 barrel export
|
||||
export { AppleLoginRequest } from "./apple_login_request";
|
||||
export { FbIdLoginRequest } from "./fb_id_login_request";
|
||||
export { FacebookLoginRequest } from "./facebook_login_request";
|
||||
export { GoogleLoginRequest } from "./google_login_request";
|
||||
export { GuestLoginRequest } from "./guest_login_request";
|
||||
export { GuestLoginResponse } from "./guest_login_response";
|
||||
export { LoginRequest } from "./login_request";
|
||||
export { LoginResponse } from "./login_response";
|
||||
export { LogoutResponse } from "./logout_response";
|
||||
export { RefreshTokenRequest } from "./refresh_token_request";
|
||||
export { RefreshTokenResponse } from "./refresh_token_response";
|
||||
export { RegisterRequest } from "./register_request";
|
||||
export { SendCodeRequest } from "./send_code_request";
|
||||
@@ -0,0 +1,58 @@
|
||||
/**
|
||||
* 登录请求 - 支持用户名或邮箱登录
|
||||
* 原始 Dart: LoginRequest (lib/data/models/auth/auth_request.dart)
|
||||
*
|
||||
* 注:原始 Dart 中 `email`/`username`/`guestId` 为 `String?`,按"全部非空"约定统一兜底为空串。
|
||||
* 后端校验 email 与 username 至少传入一个。
|
||||
*/
|
||||
export class LoginRequest {
|
||||
readonly email: string;
|
||||
readonly username: string;
|
||||
readonly password: string;
|
||||
readonly platform: string;
|
||||
readonly guestId: string;
|
||||
|
||||
constructor(params: {
|
||||
email?: string;
|
||||
username?: string;
|
||||
password: string;
|
||||
platform: string;
|
||||
guestId?: string;
|
||||
}) {
|
||||
this.email = params.email ?? "";
|
||||
this.username = params.username ?? "";
|
||||
this.password = params.password;
|
||||
this.platform = params.platform;
|
||||
this.guestId = params.guestId ?? "";
|
||||
Object.freeze(this);
|
||||
}
|
||||
|
||||
toJson(): Record<string, unknown> {
|
||||
return {
|
||||
email: this.email,
|
||||
username: this.username,
|
||||
password: this.password,
|
||||
platform: this.platform,
|
||||
guestId: this.guestId,
|
||||
};
|
||||
}
|
||||
|
||||
static fromJson(json: Record<string, unknown>): LoginRequest {
|
||||
const requireString = (key: string): string => {
|
||||
const v = json[key];
|
||||
if (typeof v !== "string") {
|
||||
throw new Error(
|
||||
`LoginRequest.${key} is required and must be a string`
|
||||
);
|
||||
}
|
||||
return v;
|
||||
};
|
||||
return new LoginRequest({
|
||||
email: typeof json.email === "string" ? json.email : undefined,
|
||||
username: typeof json.username === "string" ? json.username : undefined,
|
||||
password: requireString("password"),
|
||||
platform: requireString("platform"),
|
||||
guestId: typeof json.guestId === "string" ? json.guestId : undefined,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* 退出登录响应
|
||||
* 原始 Dart: LogoutResponse (lib/data/models/auth/auth_response.dart)
|
||||
*/
|
||||
export class LogoutResponse {
|
||||
readonly success: boolean;
|
||||
|
||||
constructor(params: { success?: boolean }) {
|
||||
this.success = params.success ?? true;
|
||||
Object.freeze(this);
|
||||
}
|
||||
|
||||
toJson(): Record<string, unknown> {
|
||||
return { success: this.success };
|
||||
}
|
||||
|
||||
static fromJson(json: Record<string, unknown>): LogoutResponse {
|
||||
return new LogoutResponse({
|
||||
success: typeof json.success === "boolean" ? json.success : undefined,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* 刷新 Token 请求
|
||||
* 原始 Dart: RefreshTokenRequest (lib/data/models/auth/auth_request.dart)
|
||||
*/
|
||||
export class RefreshTokenRequest {
|
||||
readonly refreshToken: string;
|
||||
|
||||
constructor(params: { refreshToken: string }) {
|
||||
this.refreshToken = params.refreshToken;
|
||||
Object.freeze(this);
|
||||
}
|
||||
|
||||
toJson(): Record<string, unknown> {
|
||||
return { refreshToken: this.refreshToken };
|
||||
}
|
||||
|
||||
static fromJson(json: Record<string, unknown>): RefreshTokenRequest {
|
||||
const refreshToken = json.refreshToken;
|
||||
if (typeof refreshToken !== "string") {
|
||||
throw new Error(
|
||||
"RefreshTokenRequest.refreshToken is required and must be a string"
|
||||
);
|
||||
}
|
||||
return new RefreshTokenRequest({ refreshToken });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* 刷新 Token 响应
|
||||
* 原始 Dart: RefreshTokenResponse (lib/data/models/auth/auth_response.dart)
|
||||
*/
|
||||
export class RefreshTokenResponse {
|
||||
readonly token: string;
|
||||
readonly refreshToken: string;
|
||||
readonly userId: string;
|
||||
|
||||
constructor(params: {
|
||||
token: string;
|
||||
refreshToken: string;
|
||||
userId: string;
|
||||
}) {
|
||||
this.token = params.token;
|
||||
this.refreshToken = params.refreshToken;
|
||||
this.userId = params.userId;
|
||||
Object.freeze(this);
|
||||
}
|
||||
|
||||
toJson(): Record<string, unknown> {
|
||||
return {
|
||||
token: this.token,
|
||||
refreshToken: this.refreshToken,
|
||||
userId: this.userId,
|
||||
};
|
||||
}
|
||||
|
||||
static fromJson(json: Record<string, unknown>): RefreshTokenResponse {
|
||||
const requireString = (key: string): string => {
|
||||
const v = json[key];
|
||||
if (typeof v !== "string") {
|
||||
throw new Error(
|
||||
`RefreshTokenResponse.${key} is required and must be a string`
|
||||
);
|
||||
}
|
||||
return v;
|
||||
};
|
||||
return new RefreshTokenResponse({
|
||||
token: requireString("token"),
|
||||
refreshToken: requireString("refreshToken"),
|
||||
userId: requireString("userId"),
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/**
|
||||
* 注册请求
|
||||
* 原始 Dart: RegisterRequest (lib/data/models/auth/auth_request.dart)
|
||||
*
|
||||
* 注:原始 Dart 中 `guestId` 为 `String?`,按"全部非空"约定统一兜底为空串。
|
||||
*/
|
||||
export class RegisterRequest {
|
||||
readonly username: string;
|
||||
readonly email: string;
|
||||
readonly password: string;
|
||||
readonly platform: string;
|
||||
readonly guestId: string;
|
||||
|
||||
constructor(params: {
|
||||
username: string;
|
||||
email: string;
|
||||
password: string;
|
||||
platform: string;
|
||||
guestId?: string;
|
||||
}) {
|
||||
this.username = params.username;
|
||||
this.email = params.email;
|
||||
this.password = params.password;
|
||||
this.platform = params.platform;
|
||||
this.guestId = params.guestId ?? "";
|
||||
Object.freeze(this);
|
||||
}
|
||||
|
||||
toJson(): Record<string, unknown> {
|
||||
return {
|
||||
username: this.username,
|
||||
email: this.email,
|
||||
password: this.password,
|
||||
platform: this.platform,
|
||||
guestId: this.guestId,
|
||||
};
|
||||
}
|
||||
|
||||
static fromJson(json: Record<string, unknown>): RegisterRequest {
|
||||
const requireString = (key: string): string => {
|
||||
const v = json[key];
|
||||
if (typeof v !== "string") {
|
||||
throw new Error(
|
||||
`RegisterRequest.${key} is required and must be a string`
|
||||
);
|
||||
}
|
||||
return v;
|
||||
};
|
||||
return new RegisterRequest({
|
||||
username: requireString("username"),
|
||||
email: requireString("email"),
|
||||
password: requireString("password"),
|
||||
platform: requireString("platform"),
|
||||
guestId: typeof json.guestId === "string" ? json.guestId : undefined,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* 发送验证码请求
|
||||
* 原始 Dart: SendCodeRequest (lib/data/models/auth/auth_request.dart)
|
||||
*/
|
||||
export class SendCodeRequest {
|
||||
readonly email: string;
|
||||
|
||||
constructor(params: { email: string }) {
|
||||
this.email = params.email;
|
||||
Object.freeze(this);
|
||||
}
|
||||
|
||||
toJson(): Record<string, unknown> {
|
||||
return { email: this.email };
|
||||
}
|
||||
|
||||
static fromJson(json: Record<string, unknown>): SendCodeRequest {
|
||||
const email = json.email;
|
||||
if (typeof email !== "string") {
|
||||
throw new Error(
|
||||
"SendCodeRequest.email is required and must be a string"
|
||||
);
|
||||
}
|
||||
return new SendCodeRequest({ email });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user