perf(bundle): replace broad storage and utils imports

This commit is contained in:
2026-07-14 18:13:55 +08:00
parent e270be9bd9
commit 0033625866
85 changed files with 136 additions and 97 deletions
@@ -9,7 +9,7 @@ import { AuthRepository } from "@/data/repositories/auth_repository";
import type { AuthApi } from "@/data/services/api";
import type { IAuthStorage } from "@/data/storage/auth";
import type { IUserStorage } from "@/data/storage/user";
import { Result } from "@/utils";
import { Result } from "@/utils/result";
function createRepository(overrides: Partial<AuthApi>) {
const storage = {
@@ -8,7 +8,7 @@ import { AuthRepository } from "@/data/repositories/auth_repository";
import type { AuthApi } from "@/data/services/api";
import type { IAuthStorage } from "@/data/storage/auth";
import type { IUserStorage } from "@/data/storage/user";
import { Result } from "@/utils";
import { Result } from "@/utils/result";
function createRepository(input: {
api?: Partial<AuthApi>;
@@ -1,7 +1,7 @@
import { describe, expect, it, vi } from "vitest";
import { LoginStatus } from "@/data/dto/auth";
import { Result } from "@/utils";
import { Result } from "@/utils/result";
import { resolveChatCacheOwnerKey } from "../chat_cache_identity";
@@ -2,7 +2,7 @@ import { describe, expect, it, vi } from "vitest";
import { ChatMessage } from "@/data/dto/chat";
import { LocalMessage } from "@/data/storage/chat";
import { Result } from "@/utils";
import { Result } from "@/utils/result";
import { ChatLocalMessageStore } from "../chat_local_message_store";
@@ -1,6 +1,6 @@
import { afterEach, describe, expect, it, vi } from "vitest";
import { Result } from "@/utils";
import { Result } from "@/utils/result";
import { ChatMediaCacheCoordinator } from "../chat_media_cache_coordinator";
@@ -3,7 +3,7 @@ import { describe, expect, it, vi } from "vitest";
import { TipPaymentPlansResponse } from "@/data/dto/payment";
import { PaymentRepository } from "@/data/repositories/payment_repository";
import type { PaymentApi } from "@/data/services/api";
import { Result } from "@/utils";
import { Result } from "@/utils/result";
describe("PaymentRepository", () => {
it("adapts tip plans without caching them as subscription plans", async () => {
+5 -7
View File
@@ -19,13 +19,11 @@ import {
RegisterRequest,
} from "@/data/dto/auth";
import { User } from "@/data/dto/user";
import {
AppEnvUtil,
PlatformDetector,
Result,
Logger,
deviceIdentifier,
} from "@/utils";
import { AppEnvUtil } from "@/utils/app-env";
import { PlatformDetector } from "@/utils/platform-detect";
import { Result } from "@/utils/result";
import { Logger } from "@/utils/logger";
import { deviceIdentifier } from "@/utils/device_identifier";
import type { IAuthRepository } from "@/data/repositories/interfaces";
import { AuthStorage, type IAuthStorage } from "@/data/storage/auth";
import { UserStorage, type IUserStorage } from "@/data/storage/user";
+1 -1
View File
@@ -3,7 +3,7 @@
import { LoginStatus } from "@/data/dto/auth";
import { AuthStorage, type IAuthStorage } from "@/data/storage/auth";
import { UserStorage, type IUserStorage } from "@/data/storage/user";
import { Result, type Result as ResultT } from "@/utils";
import { Result, type Result as ResultT } from "@/utils/result";
export type ChatCacheIdentityResolver = () => Promise<ResultT<string>>;
@@ -3,7 +3,7 @@
import { ChatMessage } from "@/data/dto/chat";
import type { UnlockedPrivateMessageLocalPatch } from "@/data/repositories/interfaces";
import { LocalChatStorage, LocalMessage } from "@/data/storage/chat";
import { Result } from "@/utils";
import { Result } from "@/utils/result";
import {
resolveChatCacheOwnerKey,
@@ -6,7 +6,8 @@ import {
type LocalChatMediaRow,
} from "@/data/storage/chat";
import { requestBrowserPersistentStorageOnce } from "@/lib/browser/persistent_storage";
import { Logger, Result } from "@/utils";
import { Logger } from "@/utils/logger";
import { Result } from "@/utils/result";
import type {
CacheRemoteChatMediaInput,
ChatMediaLookupInput,
@@ -10,7 +10,7 @@ import {
} from "@/data/dto/chat";
import type { ChatApi } from "@/data/services/api";
import type { UnlockPrivateMessageInput } from "@/data/repositories/interfaces";
import { Result } from "@/utils";
import { Result } from "@/utils/result";
export class ChatRemoteDataSource {
constructor(private readonly api: ChatApi) {}
+1 -1
View File
@@ -20,7 +20,7 @@ import type {
UnlockPrivateMessageInput,
UnlockedPrivateMessageLocalPatch,
} from "@/data/repositories/interfaces";
import type { Result } from "@/utils";
import type { Result } from "@/utils/result";
import { ChatLocalMessageStore } from "./chat_local_message_store";
import { ChatMediaCacheCoordinator } from "./chat_media_cache_coordinator";
@@ -13,7 +13,7 @@
*
*/
import type { Result } from "@/utils";
import type { Result } from "@/utils/result";
import type {
GuestLoginResponse,
LoginStatus,
@@ -6,7 +6,7 @@
* 聚合聊天远程操作、身份隔离的本地历史,以及媒体缓存能力。
*/
import type { Result } from "@/utils";
import type { Result } from "@/utils/result";
import type {
ChatHistoryResponse,
ChatMediaKind,
@@ -9,7 +9,7 @@
*
*/
import type { Result } from "@/utils";
import type { Result } from "@/utils/result";
export interface IMetricsRepository {
/** 上报 PWA 事件。自动注入当前秒级时间戳。 */
@@ -4,7 +4,7 @@
* IUserRepository 接口
*/
import type { Result } from "@/utils";
import type { Result } from "@/utils/result";
import type {
User,
UserEntitlements,
+1 -1
View File
@@ -7,7 +7,7 @@
*/
import { MetricsApi, metricsApi } from "@/data/services/api";
import { AppEvent, PwaEvent } from "@/data/dto/metrics";
import { Result } from "@/utils";
import { Result } from "@/utils/result";
import type { IMetricsRepository } from "@/data/repositories/interfaces";
import { createLazySingleton } from "./lazy_singleton";
+1 -1
View File
@@ -4,7 +4,7 @@ import {
User,
UserEntitlements,
} from "@/data/dto/user";
import { Result } from "@/utils";
import { Result } from "@/utils/result";
import type { IUserRepository } from "@/data/repositories/interfaces";
import { createLazySingleton } from "./lazy_singleton";
@@ -3,7 +3,9 @@ import { createStorage } from "unstorage";
import memoryDriver from "unstorage/drivers/memory";
import { AuthStorage } from "@/data/storage/auth";
import { deviceIdentifier, Result, SpAsyncUtil } from "@/utils";
import { deviceIdentifier } from "@/utils/device_identifier";
import { Result } from "@/utils/result";
import { SpAsyncUtil } from "@/utils/storage";
import { ErrorCode } from "../api_result";
import { createHttpClient } from "../http_client";
+1 -1
View File
@@ -27,7 +27,7 @@ import {
} from "@/data/dto/auth";
import { User } from "@/data/dto/user";
import type { UserData } from "@/data/schemas/user/user";
import { Logger } from "@/utils";
import { Logger } from "@/utils/logger";
const log = new Logger("DataServicesApiAuthApi");
+2 -1
View File
@@ -12,7 +12,8 @@
* - 不需要 appId / appSecretaccessToken 自身就是凭证)
*/
import { FacebookUserData } from "@/data/dto/auth";
import { Logger, Result, toError } from "@/utils";
import { Logger } from "@/utils/logger";
import { Result, toError } from "@/utils/result";
const log = new Logger("FacebookGraph");
@@ -4,7 +4,7 @@ import memoryDriver from "unstorage/drivers/memory";
import { StorageKeys } from "@/data/storage/storage_keys";
import { runStorageMigrations } from "@/data/storage/storage_migration";
import { SpAsyncUtil } from "@/utils";
import { SpAsyncUtil } from "@/utils/storage";
describe("runStorageMigrations", () => {
beforeEach(() => {
+2 -1
View File
@@ -12,7 +12,8 @@
* PWA 对话框使用布尔标记;每日上报类方法仍使用 `yyyy-MM-dd` 字符串比对。
*/
import { Result, type Result as ResultT, SpAsyncUtil } from "@/utils";
import { Result, type Result as ResultT } from "@/utils/result";
import { SpAsyncUtil } from "@/utils/storage";
import { StorageKeys } from "../storage_keys";
export class AppStorage {
+2 -1
View File
@@ -1,7 +1,8 @@
"use client";
import { LoginStatus, type LoginStatus as LoginStatusT } from "@/data/dto/auth";
import { Result, type Result as ResultT, SpAsyncUtil } from "@/utils";
import { Result, type Result as ResultT } from "@/utils/result";
import { SpAsyncUtil } from "@/utils/storage";
import { StorageKeys } from "../storage_keys";
import type { IAuthStorage } from "./iauth_storage";
+1 -1
View File
@@ -10,7 +10,7 @@
* - 所有方法返回 `Promise<Result<T>>`,与 Dart `Future<Result<T>>` 对齐
*/
import type { Result } from "@/utils";
import type { Result } from "@/utils/result";
import type { LoginStatus } from "@/data/dto/auth";
export interface IAuthStorage {
@@ -1,6 +1,6 @@
"use client";
import { Result, type Result as ResultT } from "@/utils";
import { Result, type Result as ResultT } from "@/utils/result";
import type { ChatMediaKind } from "@/data/dto/chat";
import {
+1 -1
View File
@@ -9,7 +9,7 @@
* 登录用户及多个账号共享缓存。
*/
import { Result, type Result as ResultT } from "@/utils";
import { Result, type Result as ResultT } from "@/utils/result";
import { LocalChatDB } from "./local_chat_db";
import { LocalMessage } from "./local_message";
@@ -2,7 +2,7 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
import { createStorage } from "unstorage";
import memoryDriver from "unstorage/drivers/memory";
import { SessionAsyncUtil } from "@/utils";
import { SessionAsyncUtil } from "@/utils/session-storage";
import { NavigationStorage } from "../navigation_storage";
@@ -4,7 +4,8 @@ import { z } from "zod";
import { StorageKeys } from "@/data/storage/storage_keys";
import { ChatLockTypeSchema } from "@/data/schemas/chat";
import { Result, SessionAsyncUtil } from "@/utils";
import { Result } from "@/utils/result";
import { SessionAsyncUtil } from "@/utils/session-storage";
const MAX_AGE_MS = 30 * 60 * 1000;
@@ -4,7 +4,8 @@ import {
PaymentPlansResponseSchema,
type PaymentPlansResponseData,
} from "@/data/schemas/payment";
import { type Result as ResultT, SpAsyncUtil } from "@/utils";
import { type Result as ResultT } from "@/utils/result";
import { SpAsyncUtil } from "@/utils/storage";
import { StorageKeys } from "../storage_keys";
@@ -2,7 +2,8 @@
import { z } from "zod";
import { Result, type Result as ResultT, SpAsyncUtil } from "@/utils";
import { Result, type Result as ResultT } from "@/utils/result";
import { SpAsyncUtil } from "@/utils/storage";
import { StorageKeys } from "../storage_keys";
+2 -1
View File
@@ -1,6 +1,7 @@
"use client";
import { Result, type Result as ResultT, SpAsyncUtil } from "@/utils";
import { Result, type Result as ResultT } from "@/utils/result";
import { SpAsyncUtil } from "@/utils/storage";
import { StorageKeys } from "./storage_keys";
@@ -4,7 +4,7 @@ import memoryDriver from "unstorage/drivers/memory";
import { StorageKeys } from "@/data/storage/storage_keys";
import { UserStorage } from "@/data/storage/user/user_storage";
import { SpAsyncUtil } from "@/utils";
import { SpAsyncUtil } from "@/utils/storage";
describe("UserStorage", () => {
beforeEach(() => {
+1 -1
View File
@@ -11,7 +11,7 @@
* 当前需要的最小字段,避免把完整后端 profile 长期写入 localStorage。
*/
import type { Result } from "@/utils";
import type { Result } from "@/utils/result";
import type { UserEntitlementSnapshotData } from "@/data/schemas/user/user_entitlement_snapshot";
import type {
PersistedUserData,
+2 -1
View File
@@ -24,7 +24,8 @@ import {
type PersistedUserData,
type PersistedUserInput,
} from "@/data/schemas/user/persisted_user";
import { type Result as ResultT, SpAsyncUtil } from "@/utils";
import { type Result as ResultT } from "@/utils/result";
import { SpAsyncUtil } from "@/utils/storage";
import { StorageKeys } from "../storage_keys";
import type { IUserStorage } from "./iuser_storage";