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

aipexbase-cli

v1.0.2

Published

Command line tool for BaaS API - powered by aipexbase-js

Readme

aipexbase-cli

基于 aipexbase-js SDK 的 BaaS API 命令行工具,支持 Builder 模式的链式调用。

快速开始

1. 配置

# 配置 BaaS 服务地址和 API Key
baas config --base-url http://localhost:8080 --api-key your-api-key

# 查看当前配置
baas config --show

多租户支持

通过 -c 参数指定配置文件,可以在同一台机器上管理多个租户:

# 创建不同租户的配置文件
cat > tenant-a.json << 'EOF'
{
  "baseUrl": "https://tenant-a.example.com",
  "apiKey": "key-aaa"
}
EOF

cat > tenant-b.json << 'EOF'
{
  "baseUrl": "https://tenant-b.example.com",
  "apiKey": "key-bbb"
}
EOF

# 指定租户执行命令
baas -c tenant-a.json db list users
baas -c tenant-b.json db list users

# 指定租户登录(token 会写回对应的配置文件)
baas -c tenant-a.json login --account admin --password 123456

注意-c 是全局选项,必须放在子命令之前。

配置优先级

  1. -c 指定的配置文件(最高优先级)
  2. 当前目录配置: config.json
    {
      "baseUrl": "http://localhost:8080",
      "apiKey": "project-key"
    }
  3. 全局配置: ~/.baas/config.json

主要命令

配置管理

baas config --base-url <url> --api-key <key>  # 设置配置
baas config --manage-token <token>             # 设置管理API令牌
baas config --show                             # 查看配置

管理API操作

管理API提供了创建应用和创建表的能力,需要配置管理令牌(manageToken)进行身份验证。

配置管理令牌

方式一:在配置文件中添加 manageToken 字段

{
  "baseUrl": "http://localhost:8080",
  "manageToken": "your-manage-token"
}

方式二:通过 config 命令设置

baas -c config.json config --manage-token your-manage-token

方式三:通过命令行参数传递

baas -c config.json manage create-app --manage-token your-token ...

创建应用

baas -c config.json manage create-app \
  --name "我的应用" \
  --user-id "external_user_123"

参数说明:

  • --name: 应用名称(必填)
  • --user-id: 外部平台的用户ID(必填)

返回结果:

{
  "code": 0,
  "data": {
    "apiKey": "baas_xxxxxxxxxxxx",
    "appId": "baas_xxxxxxxxxxxx"
  },
  "message": "ok",
  "success": true
}

创建表

baas -c config.json manage create-table \
  --app-id "baas_xxxxxxxxxxxx" \
  --table-name "users" \
  --table-desc "用户表" \
  --columns '[
    {
      "columnName": "name",
      "columnType": "string",
      "columnComment": "用户名",
      "isNullable": true,
      "isPrimary": false,
      "isShow": true
    },
    {
      "columnName": "phone",
      "columnType": "phone",
      "columnComment": "手机号",
      "isNullable": true,
      "isPrimary": false,
      "isShow": true
    }
  ]'

参数说明:

  • --app-id: 应用ID(必填)
  • --table-name: 表名,只能包含字母、数字和下划线(必填)
  • --table-desc: 表描述(可选)
  • --columns: JSON格式的列定义数组(可选)

字段定义说明:

| 字段 | 说明 | 必填 | |------|------|------| | columnName | 字段名称,只能包含字母、数字和下划线 | 是 | | columnType | 字段类型(见下方支持的类型) | 是 | | columnComment | 字段描述 | 是 | | isNullable | 是否必填(true=必填,false=可空) | 否 | | isPrimary | 是否主键 | 否 | | isShow | 是否显示 | 否 | | referenceTableName | 关联表名(仅当 columnType 为 quote 时需要) | 否 |

支持的字段类型:

  • string - 字符串
  • number - 整数
  • text - 文本
  • decimal - 小数
  • boolean - 布尔值
  • date - 日期
  • datetime - 时间
  • images - 图片
  • files - 文件
  • videos - 视频
  • password - 密码
  • phone - 手机号
  • email - 邮箱
  • quote - 关联对象(需要指定 referenceTableName)

创建带关联的表示例:

baas -c config.json manage create-table \
  --app-id "baas_xxxxxxxxxxxx" \
  --table-name "orders" \
  --table-desc "订单表" \
  --columns '[
    {
      "columnName": "order_no",
      "columnType": "string",
      "columnComment": "订单号",
      "isNullable": true,
      "isPrimary": false,
      "isShow": true
    },
    {
      "columnName": "user_id",
      "columnType": "quote",
      "columnComment": "用户",
      "isNullable": true,
      "isPrimary": false,
      "isShow": true,
      "referenceTableName": "users"
    },
    {
      "columnName": "amount",
      "columnType": "decimal",
      "columnComment": "金额",
      "isNullable": true,
      "isPrimary": false,
      "isShow": true
    }
  ]'

认证

baas login --account <account> --password <password>  # 登录
baas logout                                           # 登出

数据库操作

# 查询
baas db list <table> [--where '<json>'] [--order <field:direction>]
baas db page <table> --page-num <num> --page-size <size>

# 插入
baas db insert <table> --data '<json>'

# 更新
baas db update <table> --where '<json>' --data '<json>'

# 删除
baas db delete <table> --where '<json>'

文件上传

baas upload <file>

# 示例
baas upload ./photo.png
baas -c tenant.json upload ./doc.pdf

通用模块执行

# 查看所有模块
baas modules

# 执行任意模块方法
baas exec <module> <method> -p '<json>'

Builder 模式说明

CLI 支持 aipexbase-js SDK 的 Builder 模式,自动将 JSON 参数映射到链式方法:

SDK 用法:

const result = await client.ai.chat()
    .text("你好")
    .prompt("你是一个助手")
    .conversationId("conv-123");

CLI 用法(等效):

baas exec ai chat -p '{
  "text": "你好",
  "prompt": "你是一个助手",
  "conversationId": "conv-123"
}'

参数会自动映射:{"key": "value"} => builder.key("value")

使用示例

数据查询

# 查询所有活跃用户
baas db list users --where '{"status": "active"}'

# 分页查询订单
baas db page orders --page-num 1 --page-size 20 --order created_at:desc

# 插入用户
baas db insert users --data '{"name": "张三", "email": "[email protected]"}'

# 更新用户状态
baas db update users --where '{"id": 123}' --data '{"status": "inactive"}'

AI 创作工作流

# 1. AI 对话生成创意
baas exec ai chat -p '{"text": "为智能手表写一个产品slogan"}'

# 2. 根据创意生成图片
baas exec ai textToImage -p '{"text": "智能手表广告图,科技感"}'

# 3. 生成配音
baas exec ai textToSpeech -p '{"text": "你的创意slogan"}'

# 4. 即梦文生图(高级)
baas exec ai jmTextToImage -p '{
  "prompt": "可爱的小猫",
  "scale": 0.5
}'

项目级配置

# 在项目目录创建本地配置
cd /path/to/your/project

cat > config.json << 'EOF'
{
  "baseUrl": "http://staging.example.com:8080",
  "apiKey": "project-specific-key"
}
EOF

# 现在在这个目录下运行命令会使用项目配置
baas config --show
baas db list users

项目结构

aipexbase-cli/
├── bin/
│   └── baas.js           # CLI 入口
├── lib/
│   ├── commands.js       # 命令处理器
│   ├── config.js         # 配置管理(支持本地/全局/多租户)
│   ├── client.js         # 客户端工厂
│   └── manage.js         # 管理API命令处理器
├── package.json
└── README.md