forked from RiseUP/riseup-squad18
147 lines
3.7 KiB
TypeScript
147 lines
3.7 KiB
TypeScript
interface PaginationData<T> {
|
|
total: number;
|
|
list: T[];
|
|
}
|
|
|
|
interface Entity extends Record<string, any> {
|
|
id: string;
|
|
}
|
|
declare class EntityClient {
|
|
#private;
|
|
readonly entityName: string;
|
|
constructor(lumi: LumiClient, entityName: string);
|
|
/** 查询文档列表 */
|
|
list({ filter, sort, limit, skip }?: {
|
|
filter?: any;
|
|
sort?: Record<string, 1 | -1>;
|
|
limit?: number;
|
|
skip?: number;
|
|
}): Promise<PaginationData<Entity>>;
|
|
/** 获取单个文档 */
|
|
get(id: string): Promise<Entity | null>;
|
|
/** 创建文档 */
|
|
create(data: Record<string, any>): Promise<Entity>;
|
|
/** 批量创建文档 */
|
|
createMany(data: Record<string, any>[]): Promise<Entity[]>;
|
|
/** 更新文档 */
|
|
update(id: string, data: Record<string, any>): Promise<Entity>;
|
|
/** 删除文档 */
|
|
delete(id: string): Promise<void>;
|
|
/** 批量删除文档 */
|
|
deleteMany(ids: string[]): Promise<void>;
|
|
private uri;
|
|
}
|
|
|
|
declare class EntitiesClient {
|
|
#private;
|
|
[key: string]: EntityClient;
|
|
constructor(lumi: LumiClient);
|
|
}
|
|
|
|
declare class EmailTool {
|
|
#private;
|
|
constructor(lumi: LumiClient);
|
|
/** 发送邮件 */
|
|
send({ to, subject, fromName, html, text, replyTo, scheduledAt }: {
|
|
to: string | string[];
|
|
subject: string;
|
|
fromName?: string;
|
|
html?: string;
|
|
text?: string;
|
|
replyTo?: string | string[];
|
|
scheduledAt?: string;
|
|
}): Promise<void>;
|
|
}
|
|
|
|
interface UploadItem {
|
|
fileName: string;
|
|
fileUrl?: string;
|
|
uploadError?: string;
|
|
}
|
|
declare class FileTool {
|
|
#private;
|
|
constructor(lumi: LumiClient);
|
|
/** 上传文件 */
|
|
upload(files: File[]): Promise<UploadItem[]>;
|
|
/** 批量删除文件 */
|
|
delete(fileUrls: string[]): Promise<void>;
|
|
}
|
|
|
|
declare class ToolsClient {
|
|
#private;
|
|
email: EmailTool;
|
|
file: FileTool;
|
|
constructor(lumi: LumiClient);
|
|
}
|
|
|
|
interface LumiClientConfig {
|
|
projectId: string;
|
|
apiBaseUrl: string;
|
|
authOrigin: string;
|
|
}
|
|
declare class LumiClient {
|
|
config: LumiClientConfig;
|
|
auth: LumiAuthClient;
|
|
entities: EntitiesClient;
|
|
tools: ToolsClient;
|
|
constructor(config: LumiClientConfig);
|
|
}
|
|
declare function createClient(config: LumiClientConfig): LumiClient;
|
|
|
|
declare enum MessageType {
|
|
READY = "lumi-ready",
|
|
INIT = "lumi-init",
|
|
SIGN_IN = "lumi-sign-in"
|
|
}
|
|
|
|
interface User {
|
|
userId: string;
|
|
email: string;
|
|
userName: string;
|
|
createdTime: string;
|
|
}
|
|
interface MessageSignInData {
|
|
projectId: string;
|
|
accessToken: string;
|
|
user: User;
|
|
}
|
|
type MessageDataReceive = {
|
|
type: MessageType.READY;
|
|
} | {
|
|
type: MessageType.SIGN_IN;
|
|
data: MessageSignInData;
|
|
};
|
|
interface MessageInitData {
|
|
projectId: string;
|
|
icon: string | null;
|
|
title: string | null;
|
|
}
|
|
interface MessageDataSend {
|
|
type: MessageType.INIT;
|
|
data: MessageInitData;
|
|
}
|
|
declare class LumiAuthClient {
|
|
#private;
|
|
constructor(lumi: LumiClient);
|
|
/** 访问令牌 */
|
|
get accessToken(): string | null;
|
|
set accessToken(accessToken: string | null);
|
|
/** 用户 */
|
|
get user(): User | null;
|
|
set user(user: User | null);
|
|
get isAuthenticated(): boolean;
|
|
/** 登录 */
|
|
signIn(): Promise<MessageSignInData>;
|
|
/** 退出登录 */
|
|
signOut(): void;
|
|
/** 获取当前用户 */
|
|
refreshUser(): Promise<User>;
|
|
/** 监听登录状态变化 */
|
|
onAuthChange(callback: (args: {
|
|
isAuthenticated: boolean;
|
|
user: User | null;
|
|
}) => void): () => void;
|
|
}
|
|
|
|
export { EmailTool, EntitiesClient, type Entity, EntityClient, FileTool, LumiAuthClient, LumiClient, type LumiClientConfig, type MessageDataReceive, type MessageDataSend, type MessageInitData, type MessageSignInData, ToolsClient, type UploadItem, type User, createClient };
|