npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

web-dc-api

v0.1.22

Published

web相关的dcapi

Downloads

2,769

Readme

web-dc-api 是一个去中心化 Web 开发 SDK。使用逻辑如下:

1. 初始化与生命周期 (Lifecycle)

应用入口 (App.tsx) 必须遵循以下严格流程:

  1. Login: const [info, err] = await dc.auth.accountLoginWithWallet();
  2. DB Init: 登录成功后,必须立刻初始化 ThreadDB。
    • 定义集合: const collections = [{ name: "coll_name", schema: { type: "object", properties: { ... }, required: ["_id"] } }];
    • 调用: const [, initErr] = await dc.initUserDB(collections, "1.0.0", false);
  3. State: 登录成功后,调用 saveAccountInfo(info) 更新 Context 状态。
  4. 严格约束: 在 UI 描述和文案中,必须将其称为 "登录" (Login)"进入应用"
  5. 禁止: 严禁在 UI 按钮或描述中使用 "连接钱包" (Connect Wallet) 或 "钱包登录" 等字样,避免给用户造成金融操作的误解。

2. 基础环境

  • Hook: 仅在 .tsx 组件中使用 import { useDC } from "/src/contexts/DCContext.tsx"。
  • Instance: const { getDC, dcStatus, saveAccountInfo } = useDC(); const dc = await getDC();

3. 数据存储 (根据分析结果选择)

A. ThreadDB (私有/同步) - 适用于: 笔记, 草稿, 设置

  • API:
    • dc.db.create(dc.dbThreadId, "coll", jsonStr) -> [id, err]
    • dc.db.find(dc.dbThreadId, "coll", jsonQuery) -> [listJson, err] (Sort: {sort: {fieldPath: "x", desc: true}})
    • dc.db.save(dc.dbThreadId, "coll", jsonPatch) -> [err]
    • dc.db.delete(dc.dbThreadId, "coll", id)

B. KeyValueDB (共享/Serverless) - 适用于: 社交, 电商, 公共配置

  • 核心: 基于 Entity + Repository 模式。
  • Entity: 继承 BaseEntity。
    • @Entity({ name: "keyvalue_xxx_pub" }) (公开) 或 keyvalue_xxx (私有)。
    • @Column({ type: "..." })
    • @Index({ name: "idx_x", fields: ["f1", "f2"] }) (支持复合索引)
  • Service: 注入 constructor(dc: DC, db: KeyValueDB)。
    • 获取 Store: dc.keyValue.getStore(appId, "topic_name", APPThemeConfig.appThemeAuthor)
    • 初始化 Repo: this.repo = new EntityRepository(EntityClass, dc.keyValue, db)
  • Repository API: save(entity), findById(id), findByIndex(key, val), query(cond), deleteById(id)。
    • 注意: 不支持 SQL。复合索引值必须用 composeCompositeIndexValue([v1, v2]) 生成。

4. 功能模块

  • File: dc.file.addFile(file, "", onProg) -> [cid], dc.file.getFile(cid, "")
  • AI Proxy: dc.aiproxy.DoAIProxyCall({signal}, reqBody, false, callback)
  • Message: dc.message.sendMsgToUserBox (发), dc.message.getMsgFromUserBox (收)