web-dc-api 0.1.18 → 0.1.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -0,0 +1,47 @@
1
+ web-dc-api 是一个去中心化 Web 开发 SDK。使用逻辑如下:
2
+
3
+ ## 1. 初始化与生命周期 (Lifecycle)
4
+
5
+ **应用入口 (App.tsx) 必须遵循以下严格流程**:
6
+
7
+ 1. **Login**: const [info, err] = await dc.auth.accountLoginWithWallet();
8
+ 2. **DB Init**: 登录成功后,**必须**立刻初始化 ThreadDB。
9
+ - 定义集合: const collections = [{ name: "coll_name", schema: { type: "object", properties: { ... }, required: ["_id"] } }];
10
+ - 调用: const [, initErr] = await dc.initUserDB(collections, "1.0.0", false);
11
+ 3. **State**: 登录成功后,调用 saveAccountInfo(info) 更新 Context 状态。
12
+ 4. **严格约束**: 在 UI 描述和文案中,**必须**将其称为 **"登录" (Login)** 或 **"进入应用"**。
13
+ 5. **禁止**: 严禁在 UI 按钮或描述中使用 "连接钱包" (Connect Wallet) 或 "钱包登录" 等字样,避免给用户造成金融操作的误解。
14
+
15
+ ## 2. 基础环境
16
+
17
+ - **Hook**: 仅在 .tsx 组件中使用 import { useDC } from "/src/contexts/DCContext.tsx"。
18
+ - **Instance**: const { getDC, dcStatus, saveAccountInfo } = useDC(); const dc = await getDC();
19
+
20
+ ## 3. 数据存储 (根据分析结果选择)
21
+
22
+ ### A. ThreadDB (私有/同步) - 适用于: 笔记, 草稿, 设置
23
+
24
+ - **API**:
25
+ - dc.db.create(dc.dbThreadId, "coll", jsonStr) -> [id, err]
26
+ - dc.db.find(dc.dbThreadId, "coll", jsonQuery) -> [listJson, err] (Sort: {sort: {fieldPath: "x", desc: true}})
27
+ - dc.db.save(dc.dbThreadId, "coll", jsonPatch) -> [err]
28
+ - dc.db.delete(dc.dbThreadId, "coll", id)
29
+
30
+ ### B. KeyValueDB (共享/Serverless) - 适用于: 社交, 电商, 公共配置
31
+
32
+ - **核心**: 基于 Entity + Repository 模式。
33
+ - **Entity**: 继承 BaseEntity。
34
+ - @Entity({ name: "keyvalue_xxx_pub" }) (公开) 或 keyvalue_xxx (私有)。
35
+ - @Column({ type: "..." })
36
+ - @Index({ name: "idx_x", fields: ["f1", "f2"] }) (支持复合索引)
37
+ - **Service**: 注入 constructor(dc: DC, db: KeyValueDB)。
38
+ - 获取 Store: dc.keyValue.getStore(appId, "topic_name", APPThemeConfig.appThemeAuthor)
39
+ - 初始化 Repo: this.repo = new EntityRepository(EntityClass, dc.keyValue, db)
40
+ - **Repository API**: save(entity), findById(id), findByIndex(key, val), query(cond), deleteById(id)。
41
+ - **注意**: 不支持 SQL。复合索引值必须用 composeCompositeIndexValue([v1, v2]) 生成。
42
+
43
+ ## 4. 功能模块
44
+
45
+ - **File**: dc.file.addFile(file, "", onProg) -> [cid], dc.file.getFile(cid, "")
46
+ - **AI Proxy**: dc.aiproxy.DoAIProxyCall({signal}, reqBody, false, callback)
47
+ - **Message**: dc.message.sendMsgToUserBox (发), dc.message.getMsgFromUserBox (收)