refactor(data): move dto and schemas out of services directory
This commit is contained in:
+8
-11
@@ -1,19 +1,16 @@
|
|||||||
{
|
{
|
||||||
"directory": [
|
"directory": [
|
||||||
"./src/data/repositories",
|
"./src/data/repositories",
|
||||||
"./src/data/services",
|
|
||||||
"./src/data/services/api",
|
"./src/data/services/api",
|
||||||
"./src/data/services/auth",
|
"./src/data/services/auth",
|
||||||
"./src/data/services/dto",
|
"./src/data/dto/auth",
|
||||||
"./src/data/services/dto/auth",
|
"./src/data/dto/chat",
|
||||||
"./src/data/services/dto/chat",
|
"./src/data/dto/metrics",
|
||||||
"./src/data/services/dto/metrics",
|
"./src/data/dto/user",
|
||||||
"./src/data/services/dto/user",
|
"./src/data/schemas/auth",
|
||||||
"./src/data/services/schemas",
|
"./src/data/schemas/chat",
|
||||||
"./src/data/services/schemas/auth",
|
"./src/data/schemas/metrics",
|
||||||
"./src/data/services/schemas/chat",
|
"./src/data/schemas/user",
|
||||||
"./src/data/services/schemas/metrics",
|
|
||||||
"./src/data/services/schemas/user",
|
|
||||||
"./src/data/storage/app",
|
"./src/data/storage/app",
|
||||||
"./src/data/storage/auth",
|
"./src/data/storage/auth",
|
||||||
"./src/data/storage/chat",
|
"./src/data/storage/chat",
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
/**
|
||||||
|
* @file Automatically generated by barrelsby.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export * from "./auth-back-button";
|
||||||
|
export * from "./dialog";
|
||||||
|
export * from "./loading-indicator";
|
||||||
|
export * from "./mobile-shell";
|
||||||
|
export * from "./settings-section";
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
/**
|
||||||
|
* @file Automatically generated by barrelsby.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export * from "./auth-divider";
|
||||||
|
export * from "./auth-email-panel";
|
||||||
|
export * from "./auth-error-message";
|
||||||
|
export * from "./auth-facebook-panel";
|
||||||
|
export * from "./auth-legal-text";
|
||||||
|
export * from "./auth-other-options-dialog";
|
||||||
|
export * from "./auth-panel";
|
||||||
|
export * from "./auth-primary-button";
|
||||||
|
export * from "./auth-screen";
|
||||||
|
export * from "./auth-social-button";
|
||||||
|
export * from "./auth-social-buttons";
|
||||||
|
export * from "./auth-text-field";
|
||||||
|
export * from "./auth-validators";
|
||||||
|
export * from "./email-login-form";
|
||||||
|
export * from "./email-register-form";
|
||||||
|
export * from "./google-sign-in-button";
|
||||||
|
export * from "./__tests__/auth-validators.test";
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
/**
|
||||||
|
* @file Automatically generated by barrelsby.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export * from "./chat-screen";
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
/**
|
||||||
|
* @file Automatically generated by barrelsby.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export * from "./sidebar-screen";
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
/**
|
||||||
|
* @file Automatically generated by barrelsby.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export * from "./splash-background";
|
||||||
|
export * from "./splash-button";
|
||||||
|
export * from "./splash-content";
|
||||||
|
export * from "./splash-loading";
|
||||||
|
export * from "./splash-logo";
|
||||||
|
export * from "./splash-progress";
|
||||||
|
export * from "./splash-screen";
|
||||||
+1
-1
@@ -5,7 +5,7 @@ import {
|
|||||||
AppleLoginRequestSchema,
|
AppleLoginRequestSchema,
|
||||||
type AppleLoginRequestInput,
|
type AppleLoginRequestInput,
|
||||||
type AppleLoginRequestData,
|
type AppleLoginRequestData,
|
||||||
} from "@/data/services/schemas/auth/apple_login_request";
|
} from "@/data/schemas/auth/apple_login_request";
|
||||||
|
|
||||||
export class AppleLoginRequest {
|
export class AppleLoginRequest {
|
||||||
declare readonly identityToken: string;
|
declare readonly identityToken: string;
|
||||||
+1
-1
@@ -5,7 +5,7 @@ import {
|
|||||||
FacebookLoginRequestSchema,
|
FacebookLoginRequestSchema,
|
||||||
type FacebookLoginRequestInput,
|
type FacebookLoginRequestInput,
|
||||||
type FacebookLoginRequestData,
|
type FacebookLoginRequestData,
|
||||||
} from "@/data/services/schemas/auth/facebook_login_request";
|
} from "@/data/schemas/auth/facebook_login_request";
|
||||||
|
|
||||||
export class FacebookLoginRequest {
|
export class FacebookLoginRequest {
|
||||||
declare readonly accessToken: string;
|
declare readonly accessToken: string;
|
||||||
+1
-1
@@ -7,7 +7,7 @@ import {
|
|||||||
FacebookUserDataSchema,
|
FacebookUserDataSchema,
|
||||||
type FacebookUserDataInput,
|
type FacebookUserDataInput,
|
||||||
type FacebookUserDataData,
|
type FacebookUserDataData,
|
||||||
} from "@/data/services/schemas/auth/facebook_user_data";
|
} from "@/data/schemas/auth/facebook_user_data";
|
||||||
|
|
||||||
export class FacebookUserData {
|
export class FacebookUserData {
|
||||||
declare readonly id: string | null;
|
declare readonly id: string | null;
|
||||||
+1
-1
@@ -5,7 +5,7 @@ import {
|
|||||||
FbIdLoginRequestSchema,
|
FbIdLoginRequestSchema,
|
||||||
type FbIdLoginRequestInput,
|
type FbIdLoginRequestInput,
|
||||||
type FbIdLoginRequestData,
|
type FbIdLoginRequestData,
|
||||||
} from "@/data/services/schemas/auth/fb_id_login_request";
|
} from "@/data/schemas/auth/fb_id_login_request";
|
||||||
|
|
||||||
export class FbIdLoginRequest {
|
export class FbIdLoginRequest {
|
||||||
declare readonly fbId: string;
|
declare readonly fbId: string;
|
||||||
+1
-1
@@ -5,7 +5,7 @@ import {
|
|||||||
GoogleLoginRequestSchema,
|
GoogleLoginRequestSchema,
|
||||||
type GoogleLoginRequestInput,
|
type GoogleLoginRequestInput,
|
||||||
type GoogleLoginRequestData,
|
type GoogleLoginRequestData,
|
||||||
} from "@/data/services/schemas/auth/google_login_request";
|
} from "@/data/schemas/auth/google_login_request";
|
||||||
|
|
||||||
export class GoogleLoginRequest {
|
export class GoogleLoginRequest {
|
||||||
declare readonly idToken: string;
|
declare readonly idToken: string;
|
||||||
+1
-1
@@ -5,7 +5,7 @@ import {
|
|||||||
GuestLoginRequestSchema,
|
GuestLoginRequestSchema,
|
||||||
type GuestLoginRequestInput,
|
type GuestLoginRequestInput,
|
||||||
type GuestLoginRequestData,
|
type GuestLoginRequestData,
|
||||||
} from "@/data/services/schemas/auth/guest_login_request";
|
} from "@/data/schemas/auth/guest_login_request";
|
||||||
|
|
||||||
export class GuestLoginRequest {
|
export class GuestLoginRequest {
|
||||||
declare readonly deviceId: string;
|
declare readonly deviceId: string;
|
||||||
+1
-1
@@ -5,7 +5,7 @@ import {
|
|||||||
GuestLoginResponseSchema,
|
GuestLoginResponseSchema,
|
||||||
type GuestLoginResponseInput,
|
type GuestLoginResponseInput,
|
||||||
type GuestLoginResponseData,
|
type GuestLoginResponseData,
|
||||||
} from "@/data/services/schemas/auth/guest_login_response";
|
} from "@/data/schemas/auth/guest_login_response";
|
||||||
import { User } from "@/data/dto/user/user";
|
import { User } from "@/data/dto/user/user";
|
||||||
|
|
||||||
export class GuestLoginResponse {
|
export class GuestLoginResponse {
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
/**
|
||||||
|
* @file Automatically generated by barrelsby.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export * from "./apple_login_request";
|
||||||
|
export * from "./facebook_login_request";
|
||||||
|
export * from "./facebook_user_data";
|
||||||
|
export * from "./fb_id_login_request";
|
||||||
|
export * from "./google_login_request";
|
||||||
|
export * from "./guest_login_request";
|
||||||
|
export * from "./guest_login_response";
|
||||||
|
export * from "./login_request";
|
||||||
|
export * from "./login_response";
|
||||||
|
export * from "./logout_response";
|
||||||
|
export * from "./refresh_token_request";
|
||||||
|
export * from "./refresh_token_response";
|
||||||
|
export * from "./register_request";
|
||||||
|
export * from "./send_code_request";
|
||||||
@@ -5,7 +5,7 @@ import {
|
|||||||
LoginRequestSchema,
|
LoginRequestSchema,
|
||||||
type LoginRequestInput,
|
type LoginRequestInput,
|
||||||
type LoginRequestData,
|
type LoginRequestData,
|
||||||
} from "@/data/services/schemas/auth/login_request";
|
} from "@/data/schemas/auth/login_request";
|
||||||
|
|
||||||
export class LoginRequest {
|
export class LoginRequest {
|
||||||
declare readonly email: string;
|
declare readonly email: string;
|
||||||
@@ -5,7 +5,7 @@ import {
|
|||||||
LoginResponseSchema,
|
LoginResponseSchema,
|
||||||
type LoginResponseInput,
|
type LoginResponseInput,
|
||||||
type LoginResponseData,
|
type LoginResponseData,
|
||||||
} from "@/data/services/schemas/auth/login_response";
|
} from "@/data/schemas/auth/login_response";
|
||||||
import { User } from "@/data/dto/user/user";
|
import { User } from "@/data/dto/user/user";
|
||||||
|
|
||||||
export class LoginResponse {
|
export class LoginResponse {
|
||||||
+1
-1
@@ -5,7 +5,7 @@ import {
|
|||||||
LogoutResponseSchema,
|
LogoutResponseSchema,
|
||||||
type LogoutResponseInput,
|
type LogoutResponseInput,
|
||||||
type LogoutResponseData,
|
type LogoutResponseData,
|
||||||
} from "@/data/services/schemas/auth/logout_response";
|
} from "@/data/schemas/auth/logout_response";
|
||||||
|
|
||||||
export class LogoutResponse {
|
export class LogoutResponse {
|
||||||
declare readonly success: boolean;
|
declare readonly success: boolean;
|
||||||
+1
-1
@@ -5,7 +5,7 @@ import {
|
|||||||
RefreshTokenRequestSchema,
|
RefreshTokenRequestSchema,
|
||||||
type RefreshTokenRequestInput,
|
type RefreshTokenRequestInput,
|
||||||
type RefreshTokenRequestData,
|
type RefreshTokenRequestData,
|
||||||
} from "@/data/services/schemas/auth/refresh_token_request";
|
} from "@/data/schemas/auth/refresh_token_request";
|
||||||
|
|
||||||
export class RefreshTokenRequest {
|
export class RefreshTokenRequest {
|
||||||
declare readonly refreshToken: string;
|
declare readonly refreshToken: string;
|
||||||
+1
-1
@@ -5,7 +5,7 @@ import {
|
|||||||
RefreshTokenResponseSchema,
|
RefreshTokenResponseSchema,
|
||||||
type RefreshTokenResponseInput,
|
type RefreshTokenResponseInput,
|
||||||
type RefreshTokenResponseData,
|
type RefreshTokenResponseData,
|
||||||
} from "@/data/services/schemas/auth/refresh_token_response";
|
} from "@/data/schemas/auth/refresh_token_response";
|
||||||
|
|
||||||
export class RefreshTokenResponse {
|
export class RefreshTokenResponse {
|
||||||
declare readonly token: string;
|
declare readonly token: string;
|
||||||
+1
-1
@@ -5,7 +5,7 @@ import {
|
|||||||
RegisterRequestSchema,
|
RegisterRequestSchema,
|
||||||
type RegisterRequestInput,
|
type RegisterRequestInput,
|
||||||
type RegisterRequestData,
|
type RegisterRequestData,
|
||||||
} from "@/data/services/schemas/auth/register_request";
|
} from "@/data/schemas/auth/register_request";
|
||||||
|
|
||||||
export class RegisterRequest {
|
export class RegisterRequest {
|
||||||
declare readonly username: string;
|
declare readonly username: string;
|
||||||
+1
-1
@@ -5,7 +5,7 @@ import {
|
|||||||
SendCodeRequestSchema,
|
SendCodeRequestSchema,
|
||||||
type SendCodeRequestInput,
|
type SendCodeRequestInput,
|
||||||
type SendCodeRequestData,
|
type SendCodeRequestData,
|
||||||
} from "@/data/services/schemas/auth/send_code_request";
|
} from "@/data/schemas/auth/send_code_request";
|
||||||
|
|
||||||
export class SendCodeRequest {
|
export class SendCodeRequest {
|
||||||
declare readonly email: string;
|
declare readonly email: string;
|
||||||
+1
-1
@@ -5,7 +5,7 @@ import {
|
|||||||
ChatHistoryResponseSchema,
|
ChatHistoryResponseSchema,
|
||||||
type ChatHistoryResponseInput,
|
type ChatHistoryResponseInput,
|
||||||
type ChatHistoryResponseData,
|
type ChatHistoryResponseData,
|
||||||
} from "@/data/services/schemas/chat/chat_history_response";
|
} from "@/data/schemas/chat/chat_history_response";
|
||||||
import { ChatMessage } from "./chat_message";
|
import { ChatMessage } from "./chat_message";
|
||||||
|
|
||||||
export class ChatHistoryResponse {
|
export class ChatHistoryResponse {
|
||||||
@@ -5,7 +5,7 @@ import {
|
|||||||
ChatMessageSchema,
|
ChatMessageSchema,
|
||||||
type ChatMessageInput,
|
type ChatMessageInput,
|
||||||
type ChatMessageData,
|
type ChatMessageData,
|
||||||
} from "@/data/services/schemas/chat/chat_message";
|
} from "@/data/schemas/chat/chat_message";
|
||||||
|
|
||||||
export class ChatMessage {
|
export class ChatMessage {
|
||||||
declare readonly role: string;
|
declare readonly role: string;
|
||||||
+1
-1
@@ -5,7 +5,7 @@ import {
|
|||||||
ChatSendResponseSchema,
|
ChatSendResponseSchema,
|
||||||
type ChatSendResponseInput,
|
type ChatSendResponseInput,
|
||||||
type ChatSendResponseData,
|
type ChatSendResponseData,
|
||||||
} from "@/data/services/schemas/chat/chat_send_response";
|
} from "@/data/schemas/chat/chat_send_response";
|
||||||
|
|
||||||
export class ChatSendResponse {
|
export class ChatSendResponse {
|
||||||
declare readonly mode: string;
|
declare readonly mode: string;
|
||||||
@@ -5,7 +5,7 @@ import {
|
|||||||
ChatSyncDataSchema,
|
ChatSyncDataSchema,
|
||||||
type ChatSyncDataInput,
|
type ChatSyncDataInput,
|
||||||
type ChatSyncDataData,
|
type ChatSyncDataData,
|
||||||
} from "@/data/services/schemas/chat/chat_sync_data";
|
} from "@/data/schemas/chat/chat_sync_data";
|
||||||
|
|
||||||
export class ChatSyncData {
|
export class ChatSyncData {
|
||||||
declare readonly syncedCount: number;
|
declare readonly syncedCount: number;
|
||||||
+1
-1
@@ -5,7 +5,7 @@ import {
|
|||||||
ChatSyncRequestSchema,
|
ChatSyncRequestSchema,
|
||||||
type ChatSyncRequestInput,
|
type ChatSyncRequestInput,
|
||||||
type ChatSyncRequestData,
|
type ChatSyncRequestData,
|
||||||
} from "@/data/services/schemas/chat/chat_sync_request";
|
} from "@/data/schemas/chat/chat_sync_request";
|
||||||
import { SyncMessage } from "./sync_message";
|
import { SyncMessage } from "./sync_message";
|
||||||
|
|
||||||
export class ChatSyncRequest {
|
export class ChatSyncRequest {
|
||||||
+1
-1
@@ -5,7 +5,7 @@ import {
|
|||||||
GuestChatQuotaSchema,
|
GuestChatQuotaSchema,
|
||||||
type GuestChatQuotaInput,
|
type GuestChatQuotaInput,
|
||||||
type GuestChatQuotaData,
|
type GuestChatQuotaData,
|
||||||
} from "@/data/services/schemas/chat/guest_chat_quota";
|
} from "@/data/schemas/chat/guest_chat_quota";
|
||||||
|
|
||||||
export class GuestChatQuota {
|
export class GuestChatQuota {
|
||||||
// 静态常量
|
// 静态常量
|
||||||
+1
-1
@@ -5,7 +5,7 @@ import {
|
|||||||
ImageUploadResponseSchema,
|
ImageUploadResponseSchema,
|
||||||
type ImageUploadResponseInput,
|
type ImageUploadResponseInput,
|
||||||
type ImageUploadResponseData,
|
type ImageUploadResponseData,
|
||||||
} from "@/data/services/schemas/chat/image_upload_response";
|
} from "@/data/schemas/chat/image_upload_response";
|
||||||
|
|
||||||
export class ImageUploadResponse {
|
export class ImageUploadResponse {
|
||||||
declare readonly success: boolean;
|
declare readonly success: boolean;
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
/**
|
||||||
|
* @file Automatically generated by barrelsby.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export * from "./chat_history_response";
|
||||||
|
export * from "./chat_message";
|
||||||
|
export * from "./chat_send_response";
|
||||||
|
export * from "./chat_sync_data";
|
||||||
|
export * from "./chat_sync_request";
|
||||||
|
export * from "./guest_chat_quota";
|
||||||
|
export * from "./image_upload_response";
|
||||||
|
export * from "./send_message_request";
|
||||||
|
export * from "./stt_data";
|
||||||
|
export * from "./sync_message";
|
||||||
+1
-1
@@ -5,7 +5,7 @@ import {
|
|||||||
SendMessageRequestSchema,
|
SendMessageRequestSchema,
|
||||||
type SendMessageRequestInput,
|
type SendMessageRequestInput,
|
||||||
type SendMessageRequestData,
|
type SendMessageRequestData,
|
||||||
} from "@/data/services/schemas/chat/send_message_request";
|
} from "@/data/schemas/chat/send_message_request";
|
||||||
|
|
||||||
export class SendMessageRequest {
|
export class SendMessageRequest {
|
||||||
declare readonly message: string;
|
declare readonly message: string;
|
||||||
@@ -5,7 +5,7 @@ import {
|
|||||||
SttDataSchema,
|
SttDataSchema,
|
||||||
type SttDataInput,
|
type SttDataInput,
|
||||||
type SttDataData,
|
type SttDataData,
|
||||||
} from "@/data/services/schemas/chat/stt_data";
|
} from "@/data/schemas/chat/stt_data";
|
||||||
|
|
||||||
export class SttData {
|
export class SttData {
|
||||||
declare readonly text: string;
|
declare readonly text: string;
|
||||||
@@ -5,7 +5,7 @@ import {
|
|||||||
SyncMessageSchema,
|
SyncMessageSchema,
|
||||||
type SyncMessageInput,
|
type SyncMessageInput,
|
||||||
type SyncMessageData,
|
type SyncMessageData,
|
||||||
} from "@/data/services/schemas/chat/sync_message";
|
} from "@/data/schemas/chat/sync_message";
|
||||||
|
|
||||||
export class SyncMessage {
|
export class SyncMessage {
|
||||||
declare readonly role: string;
|
declare readonly role: string;
|
||||||
@@ -5,7 +5,7 @@ import {
|
|||||||
AppEventSchema,
|
AppEventSchema,
|
||||||
type AppEventInput,
|
type AppEventInput,
|
||||||
type AppEventData,
|
type AppEventData,
|
||||||
} from "@/data/services/schemas/metrics/app_event";
|
} from "@/data/schemas/metrics/app_event";
|
||||||
|
|
||||||
export class AppEvent {
|
export class AppEvent {
|
||||||
declare readonly userId: string;
|
declare readonly userId: string;
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
/**
|
||||||
|
* @file Automatically generated by barrelsby.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export * from "./app_event";
|
||||||
|
export * from "./pwa_event";
|
||||||
@@ -5,7 +5,7 @@ import {
|
|||||||
PwaEventSchema,
|
PwaEventSchema,
|
||||||
type PwaEventInput,
|
type PwaEventInput,
|
||||||
type PwaEventData,
|
type PwaEventData,
|
||||||
} from "@/data/services/schemas/metrics/pwa_event";
|
} from "@/data/schemas/metrics/pwa_event";
|
||||||
|
|
||||||
export class PwaEvent {
|
export class PwaEvent {
|
||||||
declare readonly deviceId: string;
|
declare readonly deviceId: string;
|
||||||
@@ -5,7 +5,7 @@ import {
|
|||||||
AvatarDataSchema,
|
AvatarDataSchema,
|
||||||
type AvatarDataInput,
|
type AvatarDataInput,
|
||||||
type AvatarDataData,
|
type AvatarDataData,
|
||||||
} from "@/data/services/schemas/user/avatar_data";
|
} from "@/data/schemas/user/avatar_data";
|
||||||
|
|
||||||
export class AvatarData {
|
export class AvatarData {
|
||||||
declare readonly avatarUrl: string;
|
declare readonly avatarUrl: string;
|
||||||
@@ -5,7 +5,7 @@ import {
|
|||||||
CreditsDataSchema,
|
CreditsDataSchema,
|
||||||
type CreditsDataInput,
|
type CreditsDataInput,
|
||||||
type CreditsDataData,
|
type CreditsDataData,
|
||||||
} from "@/data/services/schemas/user/credits_data";
|
} from "@/data/schemas/user/credits_data";
|
||||||
|
|
||||||
export class CreditsData {
|
export class CreditsData {
|
||||||
declare readonly userId: string;
|
declare readonly userId: string;
|
||||||
+1
-1
@@ -5,7 +5,7 @@ import {
|
|||||||
CreditsHistoryDataSchema,
|
CreditsHistoryDataSchema,
|
||||||
type CreditsHistoryDataInput,
|
type CreditsHistoryDataInput,
|
||||||
type CreditsHistoryDataData,
|
type CreditsHistoryDataData,
|
||||||
} from "@/data/services/schemas/user/credits_history_data";
|
} from "@/data/schemas/user/credits_history_data";
|
||||||
|
|
||||||
export class CreditsHistoryData {
|
export class CreditsHistoryData {
|
||||||
declare readonly records: Record<string, unknown>[];
|
declare readonly records: Record<string, unknown>[];
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
/**
|
||||||
|
* @file Automatically generated by barrelsby.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export * from "./avatar_data";
|
||||||
|
export * from "./credits_data";
|
||||||
|
export * from "./credits_history_data";
|
||||||
|
export * from "./personality_traits";
|
||||||
|
export * from "./recent_memory";
|
||||||
|
export * from "./update_profile_request";
|
||||||
|
export * from "./user";
|
||||||
|
export * from "./user_stats_response";
|
||||||
+1
-1
@@ -5,7 +5,7 @@ import {
|
|||||||
PersonalityTraitsSchema,
|
PersonalityTraitsSchema,
|
||||||
type PersonalityTraitsInput,
|
type PersonalityTraitsInput,
|
||||||
type PersonalityTraitsData,
|
type PersonalityTraitsData,
|
||||||
} from "@/data/services/schemas/user/personality_traits";
|
} from "@/data/schemas/user/personality_traits";
|
||||||
|
|
||||||
export class PersonalityTraits {
|
export class PersonalityTraits {
|
||||||
declare readonly cheerful: number;
|
declare readonly cheerful: number;
|
||||||
@@ -5,7 +5,7 @@ import {
|
|||||||
RecentMemorySchema,
|
RecentMemorySchema,
|
||||||
type RecentMemoryInput,
|
type RecentMemoryInput,
|
||||||
type RecentMemoryData,
|
type RecentMemoryData,
|
||||||
} from "@/data/services/schemas/user/recent_memory";
|
} from "@/data/schemas/user/recent_memory";
|
||||||
|
|
||||||
export class RecentMemory {
|
export class RecentMemory {
|
||||||
declare readonly type: string;
|
declare readonly type: string;
|
||||||
+1
-1
@@ -5,7 +5,7 @@ import {
|
|||||||
UpdateProfileRequestSchema,
|
UpdateProfileRequestSchema,
|
||||||
type UpdateProfileRequestInput,
|
type UpdateProfileRequestInput,
|
||||||
type UpdateProfileRequestData,
|
type UpdateProfileRequestData,
|
||||||
} from "@/data/services/schemas/user/update_profile_request";
|
} from "@/data/schemas/user/update_profile_request";
|
||||||
|
|
||||||
export class UpdateProfileRequest {
|
export class UpdateProfileRequest {
|
||||||
declare readonly username: string;
|
declare readonly username: string;
|
||||||
@@ -5,7 +5,7 @@ import {
|
|||||||
UserSchema,
|
UserSchema,
|
||||||
type UserInput,
|
type UserInput,
|
||||||
type UserData,
|
type UserData,
|
||||||
} from "@/data/services/schemas/user/user";
|
} from "@/data/schemas/user/user";
|
||||||
import { PersonalityTraits } from "./personality_traits";
|
import { PersonalityTraits } from "./personality_traits";
|
||||||
|
|
||||||
export class User {
|
export class User {
|
||||||
+1
-1
@@ -5,7 +5,7 @@ import {
|
|||||||
UserStatsResponseSchema,
|
UserStatsResponseSchema,
|
||||||
type UserStatsResponseInput,
|
type UserStatsResponseInput,
|
||||||
type UserStatsResponseData,
|
type UserStatsResponseData,
|
||||||
} from "@/data/services/schemas/user/user_stats_response";
|
} from "@/data/schemas/user/user_stats_response";
|
||||||
import { PersonalityTraits } from "./personality_traits";
|
import { PersonalityTraits } from "./personality_traits";
|
||||||
import { RecentMemory } from "./recent_memory";
|
import { RecentMemory } from "./recent_memory";
|
||||||
|
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
/**
|
||||||
|
* @file Automatically generated by barrelsby.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export * from "./apple_login_request";
|
||||||
|
export * from "./facebook_login_request";
|
||||||
|
export * from "./facebook_user_data";
|
||||||
|
export * from "./fb_id_login_request";
|
||||||
|
export * from "./google_login_request";
|
||||||
|
export * from "./guest_login_request";
|
||||||
|
export * from "./guest_login_response";
|
||||||
|
export * from "./login_request";
|
||||||
|
export * from "./login_response";
|
||||||
|
export * from "./logout_response";
|
||||||
|
export * from "./refresh_token_request";
|
||||||
|
export * from "./refresh_token_response";
|
||||||
|
export * from "./register_request";
|
||||||
|
export * from "./send_code_request";
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
/**
|
||||||
|
* @file Automatically generated by barrelsby.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export * from "./chat_history_response";
|
||||||
|
export * from "./chat_message";
|
||||||
|
export * from "./chat_send_response";
|
||||||
|
export * from "./chat_sync_data";
|
||||||
|
export * from "./chat_sync_request";
|
||||||
|
export * from "./guest_chat_quota";
|
||||||
|
export * from "./image_upload_response";
|
||||||
|
export * from "./send_message_request";
|
||||||
|
export * from "./stt_data";
|
||||||
|
export * from "./sync_message";
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
/**
|
||||||
|
* @file Automatically generated by barrelsby.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export * from "./app_event";
|
||||||
|
export * from "./pwa_event";
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
/**
|
||||||
|
* @file Automatically generated by barrelsby.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export * from "./avatar_data";
|
||||||
|
export * from "./credits_data";
|
||||||
|
export * from "./credits_history_data";
|
||||||
|
export * from "./personality_traits";
|
||||||
|
export * from "./recent_memory";
|
||||||
|
export * from "./update_profile_request";
|
||||||
|
export * from "./user";
|
||||||
|
export * from "./user_stats_response";
|
||||||
@@ -21,7 +21,7 @@ import { RefreshTokenResponse } from "@/data/dto/auth/refresh_token_response";
|
|||||||
import { RegisterRequest } from "@/data/dto/auth/register_request";
|
import { RegisterRequest } from "@/data/dto/auth/register_request";
|
||||||
import { SendCodeRequest } from "@/data/dto/auth/send_code_request";
|
import { SendCodeRequest } from "@/data/dto/auth/send_code_request";
|
||||||
import { User } from "@/data/dto/user/user";
|
import { User } from "@/data/dto/user/user";
|
||||||
import type { UserData } from "@/data/services/schemas/user/user";
|
import type { UserData } from "@/data/schemas/user/user";
|
||||||
|
|
||||||
export class AuthApi {
|
export class AuthApi {
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
/**
|
||||||
|
* @file Automatically generated by barrelsby.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export * from "./api_path";
|
||||||
|
export * from "./api_result";
|
||||||
|
export * from "./auth_api";
|
||||||
|
export * from "./chat_api";
|
||||||
|
export * from "./http_client";
|
||||||
|
export * from "./metrics_api";
|
||||||
|
export * from "./response_helper";
|
||||||
|
export * from "./user_api";
|
||||||
|
export * from "./config/api_config";
|
||||||
|
export * from "./interceptor/auth_refresh_interceptor";
|
||||||
|
export * from "./interceptor/logging_interceptor";
|
||||||
|
export * from "./interceptor/token_interceptor";
|
||||||
@@ -12,7 +12,7 @@ import { CreditsHistoryData } from "@/data/dto/user/credits_history_data";
|
|||||||
import { UpdateProfileRequest } from "@/data/dto/user/update_profile_request";
|
import { UpdateProfileRequest } from "@/data/dto/user/update_profile_request";
|
||||||
import { User } from "@/data/dto/user/user";
|
import { User } from "@/data/dto/user/user";
|
||||||
import { UserStatsResponse } from "@/data/dto/user/user_stats_response";
|
import { UserStatsResponse } from "@/data/dto/user/user_stats_response";
|
||||||
import type { UserData } from "@/data/services/schemas/user/user";
|
import type { UserData } from "@/data/schemas/user/user";
|
||||||
|
|
||||||
export class UserApi {
|
export class UserApi {
|
||||||
/**
|
/**
|
||||||
|
|||||||
+68
-68
@@ -22,71 +22,71 @@ export * from "./auth/initialize_facebook_auth";
|
|||||||
export * from "./auth/initialize_google_auth";
|
export * from "./auth/initialize_google_auth";
|
||||||
export * from "./auth/mock_auth_platform";
|
export * from "./auth/mock_auth_platform";
|
||||||
export * from "./auth/web_auth_platform";
|
export * from "./auth/web_auth_platform";
|
||||||
export * from "./dto/auth/apple_login_request";
|
export * from "../dto/auth/apple_login_request";
|
||||||
export * from "./dto/auth/facebook_login_request";
|
export * from "../dto/auth/facebook_login_request";
|
||||||
export * from "./dto/auth/facebook_user_data";
|
export * from "../dto/auth/facebook_user_data";
|
||||||
export * from "./dto/auth/fb_id_login_request";
|
export * from "../dto/auth/fb_id_login_request";
|
||||||
export * from "./dto/auth/google_login_request";
|
export * from "../dto/auth/google_login_request";
|
||||||
export * from "./dto/auth/guest_login_request";
|
export * from "../dto/auth/guest_login_request";
|
||||||
export * from "./dto/auth/guest_login_response";
|
export * from "../dto/auth/guest_login_response";
|
||||||
export * from "./dto/auth/login_request";
|
export * from "../dto/auth/login_request";
|
||||||
export * from "./dto/auth/login_response";
|
export * from "../dto/auth/login_response";
|
||||||
export * from "./dto/auth/logout_response";
|
export * from "../dto/auth/logout_response";
|
||||||
export * from "./dto/auth/refresh_token_request";
|
export * from "../dto/auth/refresh_token_request";
|
||||||
export * from "./dto/auth/refresh_token_response";
|
export * from "../dto/auth/refresh_token_response";
|
||||||
export * from "./dto/auth/register_request";
|
export * from "../dto/auth/register_request";
|
||||||
export * from "./dto/auth/send_code_request";
|
export * from "../dto/auth/send_code_request";
|
||||||
export * from "./dto/chat/chat_history_response";
|
export * from "../dto/chat/chat_history_response";
|
||||||
export * from "./dto/chat/chat_message";
|
export * from "../dto/chat/chat_message";
|
||||||
export * from "./dto/chat/chat_send_response";
|
export * from "../dto/chat/chat_send_response";
|
||||||
export * from "./dto/chat/chat_sync_data";
|
export * from "../dto/chat/chat_sync_data";
|
||||||
export * from "./dto/chat/chat_sync_request";
|
export * from "../dto/chat/chat_sync_request";
|
||||||
export * from "./dto/chat/guest_chat_quota";
|
export * from "../dto/chat/guest_chat_quota";
|
||||||
export * from "./dto/chat/image_upload_response";
|
export * from "../dto/chat/image_upload_response";
|
||||||
export * from "./dto/chat/send_message_request";
|
export * from "../dto/chat/send_message_request";
|
||||||
export * from "./dto/chat/stt_data";
|
export * from "../dto/chat/stt_data";
|
||||||
export * from "./dto/chat/sync_message";
|
export * from "../dto/chat/sync_message";
|
||||||
export * from "./dto/metrics/app_event";
|
export * from "../dto/metrics/app_event";
|
||||||
export * from "./dto/metrics/pwa_event";
|
export * from "../dto/metrics/pwa_event";
|
||||||
export * from "./dto/user/avatar_data";
|
export * from "../dto/user/avatar_data";
|
||||||
export * from "./dto/user/credits_data";
|
export * from "../dto/user/credits_data";
|
||||||
export * from "./dto/user/credits_history_data";
|
export * from "../dto/user/credits_history_data";
|
||||||
export * from "./dto/user/personality_traits";
|
export * from "../dto/user/personality_traits";
|
||||||
export * from "./dto/user/recent_memory";
|
export * from "../dto/user/recent_memory";
|
||||||
export * from "./dto/user/update_profile_request";
|
export * from "../dto/user/update_profile_request";
|
||||||
export * from "./dto/user/user";
|
export * from "../dto/user/user";
|
||||||
export * from "./dto/user/user_stats_response";
|
export * from "../dto/user/user_stats_response";
|
||||||
export * from "./schemas/auth/apple_login_request";
|
export * from "../schemas/auth/apple_login_request";
|
||||||
export * from "./schemas/auth/facebook_login_request";
|
export * from "../schemas/auth/facebook_login_request";
|
||||||
export * from "./schemas/auth/facebook_user_data";
|
export * from "../schemas/auth/facebook_user_data";
|
||||||
export * from "./schemas/auth/fb_id_login_request";
|
export * from "../schemas/auth/fb_id_login_request";
|
||||||
export * from "./schemas/auth/google_login_request";
|
export * from "../schemas/auth/google_login_request";
|
||||||
export * from "./schemas/auth/guest_login_request";
|
export * from "../schemas/auth/guest_login_request";
|
||||||
export * from "./schemas/auth/guest_login_response";
|
export * from "../schemas/auth/guest_login_response";
|
||||||
export * from "./schemas/auth/login_request";
|
export * from "../schemas/auth/login_request";
|
||||||
export * from "./schemas/auth/login_response";
|
export * from "../schemas/auth/login_response";
|
||||||
export * from "./schemas/auth/logout_response";
|
export * from "../schemas/auth/logout_response";
|
||||||
export * from "./schemas/auth/refresh_token_request";
|
export * from "../schemas/auth/refresh_token_request";
|
||||||
export * from "./schemas/auth/refresh_token_response";
|
export * from "../schemas/auth/refresh_token_response";
|
||||||
export * from "./schemas/auth/register_request";
|
export * from "../schemas/auth/register_request";
|
||||||
export * from "./schemas/auth/send_code_request";
|
export * from "../schemas/auth/send_code_request";
|
||||||
export * from "./schemas/chat/chat_history_response";
|
export * from "../schemas/chat/chat_history_response";
|
||||||
export * from "./schemas/chat/chat_message";
|
export * from "../schemas/chat/chat_message";
|
||||||
export * from "./schemas/chat/chat_send_response";
|
export * from "../schemas/chat/chat_send_response";
|
||||||
export * from "./schemas/chat/chat_sync_data";
|
export * from "../schemas/chat/chat_sync_data";
|
||||||
export * from "./schemas/chat/chat_sync_request";
|
export * from "../schemas/chat/chat_sync_request";
|
||||||
export * from "./schemas/chat/guest_chat_quota";
|
export * from "../schemas/chat/guest_chat_quota";
|
||||||
export * from "./schemas/chat/image_upload_response";
|
export * from "../schemas/chat/image_upload_response";
|
||||||
export * from "./schemas/chat/send_message_request";
|
export * from "../schemas/chat/send_message_request";
|
||||||
export * from "./schemas/chat/stt_data";
|
export * from "../schemas/chat/stt_data";
|
||||||
export * from "./schemas/chat/sync_message";
|
export * from "../schemas/chat/sync_message";
|
||||||
export * from "./schemas/metrics/app_event";
|
export * from "../schemas/metrics/app_event";
|
||||||
export * from "./schemas/metrics/pwa_event";
|
export * from "../schemas/metrics/pwa_event";
|
||||||
export * from "./schemas/user/avatar_data";
|
export * from "../schemas/user/avatar_data";
|
||||||
export * from "./schemas/user/credits_data";
|
export * from "../schemas/user/credits_data";
|
||||||
export * from "./schemas/user/credits_history_data";
|
export * from "../schemas/user/credits_history_data";
|
||||||
export * from "./schemas/user/personality_traits";
|
export * from "../schemas/user/personality_traits";
|
||||||
export * from "./schemas/user/recent_memory";
|
export * from "../schemas/user/recent_memory";
|
||||||
export * from "./schemas/user/update_profile_request";
|
export * from "../schemas/user/update_profile_request";
|
||||||
export * from "./schemas/user/user";
|
export * from "../schemas/user/user";
|
||||||
export * from "./schemas/user/user_stats_response";
|
export * from "../schemas/user/user_stats_response";
|
||||||
|
|||||||
@@ -1,118 +0,0 @@
|
|||||||
/**
|
|
||||||
* Auth 存储 - localStorage 包装
|
|
||||||
*
|
|
||||||
* 存储登录 token、刷新 token、游客 token、设备 ID。
|
|
||||||
* 原始 Dart: lib/data/services/storage/auth_storage.dart
|
|
||||||
*
|
|
||||||
* 注:localStorage 仅在浏览器环境可用;
|
|
||||||
* 在 Server Components 中调用会抛错,应仅在 Client Components 或拦截器中使用。
|
|
||||||
*/
|
|
||||||
|
|
||||||
const STORAGE_KEYS = {
|
|
||||||
loginToken: "cozsweet.loginToken",
|
|
||||||
refreshToken: "cozsweet.refreshToken",
|
|
||||||
guestToken: "cozsweet.guestToken",
|
|
||||||
deviceId: "cozsweet.deviceId",
|
|
||||||
} as const;
|
|
||||||
|
|
||||||
function getStorage(): Storage | null {
|
|
||||||
if (typeof window === "undefined") return null;
|
|
||||||
try {
|
|
||||||
return window.localStorage;
|
|
||||||
} catch {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class AuthStorage {
|
|
||||||
// ============ 登录 Token ============
|
|
||||||
|
|
||||||
getLoginToken(): string | null {
|
|
||||||
return getStorage()?.getItem(STORAGE_KEYS.loginToken) ?? null;
|
|
||||||
}
|
|
||||||
|
|
||||||
setLoginToken(token: string): void {
|
|
||||||
getStorage()?.setItem(STORAGE_KEYS.loginToken, token);
|
|
||||||
}
|
|
||||||
|
|
||||||
removeLoginToken(): void {
|
|
||||||
getStorage()?.removeItem(STORAGE_KEYS.loginToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ============ 刷新 Token ============
|
|
||||||
|
|
||||||
getRefreshToken(): string | null {
|
|
||||||
return getStorage()?.getItem(STORAGE_KEYS.refreshToken) ?? null;
|
|
||||||
}
|
|
||||||
|
|
||||||
setRefreshToken(token: string): void {
|
|
||||||
getStorage()?.setItem(STORAGE_KEYS.refreshToken, token);
|
|
||||||
}
|
|
||||||
|
|
||||||
removeRefreshToken(): void {
|
|
||||||
getStorage()?.removeItem(STORAGE_KEYS.refreshToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ============ 游客 Token ============
|
|
||||||
|
|
||||||
getGuestToken(): string | null {
|
|
||||||
return getStorage()?.getItem(STORAGE_KEYS.guestToken) ?? null;
|
|
||||||
}
|
|
||||||
|
|
||||||
setGuestToken(token: string): void {
|
|
||||||
getStorage()?.setItem(STORAGE_KEYS.guestToken, token);
|
|
||||||
}
|
|
||||||
|
|
||||||
removeGuestToken(): void {
|
|
||||||
getStorage()?.removeItem(STORAGE_KEYS.guestToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ============ 设备 ID ============
|
|
||||||
|
|
||||||
getDeviceId(): string | null {
|
|
||||||
return getStorage()?.getItem(STORAGE_KEYS.deviceId) ?? null;
|
|
||||||
}
|
|
||||||
|
|
||||||
setDeviceId(deviceId: string): void {
|
|
||||||
getStorage()?.setItem(STORAGE_KEYS.deviceId, deviceId);
|
|
||||||
}
|
|
||||||
|
|
||||||
removeDeviceId(): void {
|
|
||||||
getStorage()?.removeItem(STORAGE_KEYS.deviceId);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ============ 复合操作 ============
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否有登录 token
|
|
||||||
*/
|
|
||||||
hasLoginToken(): boolean {
|
|
||||||
const token = this.getLoginToken();
|
|
||||||
return token !== null && token.length > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取认证 token(优先登录 token,其次游客 token)
|
|
||||||
*/
|
|
||||||
getAuthToken(): string | null {
|
|
||||||
const loginToken = this.getLoginToken();
|
|
||||||
if (loginToken !== null && loginToken.length > 0) return loginToken;
|
|
||||||
const guestToken = this.getGuestToken();
|
|
||||||
if (guestToken !== null && guestToken.length > 0) return guestToken;
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 清除所有 auth 数据(登录/刷新/游客 token)
|
|
||||||
*/
|
|
||||||
clearAuthData(): void {
|
|
||||||
this.removeLoginToken();
|
|
||||||
this.removeRefreshToken();
|
|
||||||
this.removeGuestToken();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 全局单例
|
|
||||||
*/
|
|
||||||
export const authStorage = new AuthStorage();
|
|
||||||
@@ -1,123 +0,0 @@
|
|||||||
"use client";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* localStorage 通用包装
|
|
||||||
*
|
|
||||||
* 设计要点:
|
|
||||||
* 1. 全部方法返回 `Promise<Result<T>>`,与 `LocalChatStorage`(Dexie/异步)保持签名一致,
|
|
||||||
* 调用方可以统一 `await` 而不必关心底层是同步还是异步。
|
|
||||||
* 2. 三重 SSR 保护:
|
|
||||||
* - 文件顶 `"use client"` 指令
|
|
||||||
* - 构造时探测 `typeof window`,服务端拿不到 `window.localStorage` 时存 `null`
|
|
||||||
* - 每次调用入口再做可用性检查,避免运行时炸
|
|
||||||
* 3. 测试友好:构造函数接受可选 `Storage` 注入,单例可通过 `_resetForTests` 重置。
|
|
||||||
* 4. `getString` 把空串视作 `null`(对齐 Dart `SpAsyncUtil.getString` 行为)。
|
|
||||||
* 5. `getJson` / `setJson` 在边界做 Zod 校验,读写都走 schema。
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { type ZodType } from "zod";
|
|
||||||
import { Result, type Result as ResultT } from "@/utils/result";
|
|
||||||
|
|
||||||
const SSR_ERROR_MSG =
|
|
||||||
"localStorage is not available in this environment (SSR or non-browser)";
|
|
||||||
|
|
||||||
export class LocalStorage {
|
|
||||||
private readonly storage: Storage | null;
|
|
||||||
private static _instance: LocalStorage | null = null;
|
|
||||||
|
|
||||||
constructor(storage?: Storage | null) {
|
|
||||||
this.storage =
|
|
||||||
storage !== undefined
|
|
||||||
? storage
|
|
||||||
: typeof window !== "undefined"
|
|
||||||
? window.localStorage
|
|
||||||
: null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 全局单例(仅在浏览器环境有效)。 */
|
|
||||||
static getInstance(): LocalStorage {
|
|
||||||
if (!LocalStorage._instance) {
|
|
||||||
LocalStorage._instance = new LocalStorage();
|
|
||||||
}
|
|
||||||
return LocalStorage._instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @internal 测试用:重置单例以便每个测试用例拿到独立实例。 */
|
|
||||||
static _resetForTests(): void {
|
|
||||||
LocalStorage._instance = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private isAvailable(): boolean {
|
|
||||||
return this.storage !== null;
|
|
||||||
}
|
|
||||||
|
|
||||||
async getString(key: string): Promise<ResultT<string | null>> {
|
|
||||||
if (!this.isAvailable()) return Result.err(new Error(SSR_ERROR_MSG));
|
|
||||||
try {
|
|
||||||
const v = this.storage!.getItem(key);
|
|
||||||
if (v === null || v === "") return Result.ok(null);
|
|
||||||
return Result.ok(v);
|
|
||||||
} catch (e) {
|
|
||||||
return Result.err(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async setString(key: string, value: string): Promise<ResultT<void>> {
|
|
||||||
if (!this.isAvailable()) return Result.err(new Error(SSR_ERROR_MSG));
|
|
||||||
try {
|
|
||||||
this.storage!.setItem(key, value);
|
|
||||||
return Result.ok(undefined);
|
|
||||||
} catch (e) {
|
|
||||||
return Result.err(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async getJson<T>(key: string, schema: ZodType<T>): Promise<ResultT<T | null>> {
|
|
||||||
const r = await this.getString(key);
|
|
||||||
if (!r.success) return Result.err(r.error);
|
|
||||||
if (r.data === null) {
|
|
||||||
const value: T | null = null;
|
|
||||||
return Result.ok(value);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
const parsed = schema.parse(JSON.parse(r.data));
|
|
||||||
return Result.ok(parsed);
|
|
||||||
} catch (e) {
|
|
||||||
return Result.err(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async setJson<T>(
|
|
||||||
key: string,
|
|
||||||
value: T,
|
|
||||||
schema?: ZodType<T>,
|
|
||||||
): Promise<ResultT<void>> {
|
|
||||||
if (!this.isAvailable()) return Result.err(new Error(SSR_ERROR_MSG));
|
|
||||||
try {
|
|
||||||
const validated = schema ? schema.parse(value) : value;
|
|
||||||
this.storage!.setItem(key, JSON.stringify(validated));
|
|
||||||
return Result.ok(undefined);
|
|
||||||
} catch (e) {
|
|
||||||
return Result.err(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async remove(key: string): Promise<ResultT<void>> {
|
|
||||||
if (!this.isAvailable()) return Result.err(new Error(SSR_ERROR_MSG));
|
|
||||||
try {
|
|
||||||
this.storage!.removeItem(key);
|
|
||||||
return Result.ok(undefined);
|
|
||||||
} catch (e) {
|
|
||||||
return Result.err(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async has(key: string): Promise<ResultT<boolean>> {
|
|
||||||
if (!this.isAvailable()) return Result.err(new Error(SSR_ERROR_MSG));
|
|
||||||
try {
|
|
||||||
return Result.ok(this.storage!.getItem(key) !== null);
|
|
||||||
} catch (e) {
|
|
||||||
return Result.err(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user