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 🙏

© 2026 – Pkg Stats / Ryan Hefner

dayubase-js

v1.1.4

Published

DayuBase BaaS JavaScript SDK — supports Web and WeChat Mini Programs

Readme

DayuBase JS SDK

一个简洁易用的 BaaS (Backend as a Service) JavaScript SDK,提供项目管理、应用管理、数据库操作和自定义 API 调用功能。采用 Project-App 两级架构,支持完整的前后端一体化开发工作流。

特性

  • 🔐 用户认证 - 登录、注册、登出和用户信息管理
  • 📊 数据库操作 - 支持链式调用的 CRUD 操作
  • 📁 项目管理 - 创建、查询、更新和删除项目
  • 🚀 应用管理 - 在项目下创建和管理应用,支持导入/导出/复制
  • 🔌 自定义 API - 灵活的 API 调用接口
  • 🎯 链式调用 - 优雅的 API 设计,支持流式编程
  • 🔑 自动 Token 管理 - 自动存储和管理用户认证 Token
  • 📦 多格式支持 - 同时支持 CommonJS 和 ES Module

安装

npm install dayubase-js

快速开始

初始化客户端

import { createClient } from 'dayubase-js';

const client = createClient({
  baseUrl: 'https://your-api-endpoint.com',
  apiKey: 'your-api-key'
});

API 文档

认证模块 (Auth)

登录

支持用户名、手机号或邮箱登录:

// 使用手机号登录
const result = await client.auth.login({
  phone: '13800138000',
  password: 'your-password'
});

// 使用邮箱登录
const result = await client.auth.login({
  email: '[email protected]',
  password: 'your-password'
});

// 使用用户名登录
const result = await client.auth.login({
  user_name: 'username',
  password: 'your-password'
});

注册

const result = await client.auth.register({
  user_name: 'newuser',
  phone: '13800138000',
  email: '[email protected]',
  password: 'your-password',
  // 其他自定义字段.这里与DayuBase管理后台是否开发登录有关联。
});

获取用户信息

const user = await client.auth.getUser();

项目管理模块 (Project)

分页查询项目列表

const result = await client.project.page({
  current: 1,
  pageSize: 10,
  projectName: '关键词搜索'  // 可选
});

创建项目

const result = await client.project.create({
  projectName: '我的项目',
  description: '项目描述'
});

获取项目概览

const result = await client.project.overview('project-id');

更新项目

const result = await client.project.update('project-id', {
  projectName: '新项目名',
  description: '新描述'
});

删除项目

const result = await client.project.delete('project-id');

应用管理模块 (App)

分页查询应用列表

const result = await client.app.page({
  projectId: 'project-id',  // 必填:所属项目ID
  current: 1,
  pageSize: 10,
  name: '关键词搜索'  // 可选
});

创建应用

const result = await client.app.create({
  projectId: 'project-id',
  name: '我的应用',
  description: '应用描述'
});

获取应用概览

const result = await client.app.overview('app-id');

更新应用

const result = await client.app.update('app-id', {
  appName: '新应用名',
  description: '新描述'
});

删除应用

const result = await client.app.delete('app-id');

回收应用

const result = await client.app.recycle('app-id', {
  appId: 'app-id'
});

复制应用

const result = await client.app.copy('app-id');

导出应用

const result = await client.app.export('app-id');
// 返回应用配置数据,可用于备份或迁移

导入应用

const result = await client.app.import({
  projectId: 'target-project-id',  // 目标项目ID
  ...appConfigData  // 导出的应用配置
});

获取登录信息

const result = await client.app.getLoginInfo('app-id', 'relevance-id');

登出

await client.auth.logout();

手动设置 Token

client.setToken('your-auth-token');

数据库模块 (DB)

数据库模块提供了丰富的链式查询接口。

查询数据

列表查询
// 简单查询
const result = await client.db
  .from('users')
  .list();

// 带过滤条件
const result = await client.db
  .from('users')
  .list()
  .eq('status', 'active')
  .gt('age', 18);

// 排序
const result = await client.db
  .from('users')
  .list()
  .order('created_at', 'desc');
分页查询
const result = await client.db
  .from('users')
  .page()
  .page(1, 20)  // 页码,每页数量
  .eq('status', 'active');
获取单条数据
const result = await client.db
  .from('users')
  .get()
  .eq('id', 123);

过滤条件

支持多种过滤操作符:

// 等于
.eq('field', value)

// 不等于
.neq('field', value)

// 大于
.gt('field', value)

// 大于等于
.gte('field', value)

// 小于
.lt('field', value)

// 小于等于
.lte('field', value)

// 在范围内
.in('field', [value1, value2, value3])

// 在区间内
.between('field', [min, max])

OR 条件查询

const result = await client.db
  .from('users')
  .list()
  .eq('status', 'active')
  .or((q) => {
    q.eq('role', 'admin')
     .eq('role', 'moderator');
  });

排序

// 升序
.order('created_at', 'asc')

// 降序
.order('created_at', 'desc')

// 对象形式
.order('created_at', { ascending: true })
.order('created_at', { direction: 'desc' })

插入数据

const result = await client.db
  .from('users')
  .insert()
  .values({
    name: 'John Doe',
    email: '[email protected]',
    age: 25
  });

更新数据

const result = await client.db
  .from('users')
  .update()
  .set({
    status: 'inactive'
  })
  .eq('id', 123);

删除数据

const result = await client.db
  .from('users')
  .delete()
  .eq('id', 123);

API 模块

用于调用自定义 API 接口。

基本调用

const result = await client.api
  .call('yourApiName')
  .param('key1', 'value1')
  .param('key2', 'value2');

批量设置参数

const result = await client.api
  .call('yourApiName')
  .params({
    key1: 'value1',
    key2: 'value2',
    key3: 'value3'
  });

自定义请求头

const result = await client.api
  .call('yourApiName')
  .header('X-Custom-Header', 'value')
  .params({ data: 'value' });

// 批量设置请求头
const result = await client.api
  .call('yourApiName')
  .headers({
    'X-Custom-Header-1': 'value1',
    'X-Custom-Header-2': 'value2'
  })
  .params({ data: 'value' });

完整示例

import { createClient } from 'dayubase-js';

// 初始化客户端
const client = createClient({
  baseUrl: 'https://your-api-endpoint.com',
  apiKey: 'your-api-key'
});

// 用户登录
async function login() {
  try {
    const result = await client.auth.login({
      phone: '13800138000',
      password: 'password123'
    });
    
    if (result.success) {
      console.log('登录成功!');
    }
  } catch (error) {
    console.error('登录失败:', error);
  }
}

// 查询用户列表
async function getUserList() {
  try {
    const result = await client.db
      .from('users')
      .page()
      .page(1, 20)
      .eq('status', 'active')
      .gte('age', 18)
      .order('created_at', 'desc');
    
    console.log('用户列表:', result);
  } catch (error) {
    console.error('查询失败:', error);
  }
}

// 创建新用户
async function createUser() {
  try {
    const result = await client.db
      .from('users')
      .insert()
      .values({
        name: 'John Doe',
        email: '[email protected]',
        age: 25,
        status: 'active'
      });
    
    console.log('用户创建成功:', result);
  } catch (error) {
    console.error('创建失败:', error);
  }
}

// 调用自定义 API
async function callCustomApi() {
  try {
    const result = await client.api
      .call('sendEmail')
      .params({
        to: '[email protected]',
        subject: 'Hello',
        body: 'Welcome to our service!'
      });
    
    console.log('API 调用成功:', result);
  } catch (error) {
    console.error('API 调用失败:', error);
  }
}

// 项目管理示例
async function projectExample() {
  try {
    // 创建项目
    const project = await client.project.create({
      projectName: '电商平台',
      description: '企业级电商解决方案'
    });
    console.log('项目创建成功:', project);

    // 查询项目列表
    const projects = await client.project.page({
      current: 1,
      pageSize: 10
    });
    console.log('项目列表:', projects);

    // 获取项目概览
    const overview = await client.project.overview(project.data.projectId);
    console.log('项目概览:', overview);
  } catch (error) {
    console.error('项目操作失败:', error);
  }
}

// 应用管理示例
async function appExample() {
  try {
    const projectId = 'your-project-id';

    // 创建应用
    const app = await client.app.create({
      projectId: projectId,
      name: '用户服务',
      description: '处理用户注册、登录等业务'
    });
    console.log('应用创建成功:', app);

    // 查询项目下的应用列表
    const apps = await client.app.page({
      projectId: projectId,
      current: 1,
      pageSize: 10
    });
    console.log('应用列表:', apps);

    // 导出应用配置
    const exportData = await client.app.export(app.data.appId);
    console.log('应用配置:', exportData);

    // 复制应用
    const copiedApp = await client.app.copy(app.data.appId);
    console.log('应用复制成功:', copiedApp);
  } catch (error) {
    console.error('应用操作失败:', error);
  }
}

// 完整的项目-应用工作流
async function completeWorkflow() {
  try {
    // 1. 创建项目
    const project = await client.project.create({
      projectName: '社区论坛',
      description: '在线社区讨论平台'
    });
    const projectId = project.data.projectId;
    console.log('项目创建成功:', projectId);

    // 2. 在项目中创建多个应用
    const userApp = await client.app.create({
      projectId: projectId,
      name: '用户中心',
      description: '用户管理和认证'
    });
    console.log('用户中心应用创建成功');

    const postApp = await client.app.create({
      projectId: projectId,
      name: '帖子服务',
      description: '帖子发布和管理'
    });
    console.log('帖子服务应用创建成功');

    // 3. 在用户中心应用中创建数据表
    await client.db
      .from('users')
      .insert()
      .values({
        username: 'admin',
        email: '[email protected]',
        role: 'administrator'
      });
    console.log('管理员用户创建成功');

    // 4. 查询应用列表
    const apps = await client.app.page({
      projectId: projectId,
      pageSize: 100
    });
    console.log(`项目下共有 ${apps.data.total} 个应用`);

  } catch (error) {
    console.error('工作流执行失败:', error);
  }
}

开发

本地开发

# 安装依赖
npm install

# 构建项目
npm run build

项目结构

dayubase-js/
├── src/
│   ├── client.js          # 核心客户端
│   ├── index.js           # 入口文件
│   └── modules/
│       ├── auth.js        # 认证模块
│       ├── db.js          # 数据库模块
│       ├── api.js         # API 模块
│       ├── project.js     # 项目管理模块
│       ├── app.js         # 应用管理模块
│       └── ai.js          # AI 模块(开发中)
├── dist/                  # 构建输出
│   ├── index.cjs.js      # CommonJS 格式
│   └── index.esm.js      # ES Module 格式
├── package.json
├── rollup.config.mjs
└── README.md

技术栈

  • 构建工具: Rollup
  • 模块格式: CommonJS & ES Module
  • 代码压缩: Terser

License

ISC

贡献

欢迎提交 Issue 和 Pull Request!