@carddb/browser

中文文档
0.5.8发布于 2026/07/28MITTypeScriptESM + CJS近 30 天下载 4943

CardDB client for browsers

原始使用文档
文档目录6 节
  1. Installation
  2. Quick Start
  3. BrowserCache
  4. Bundle Size
  5. Full Documentation
  6. License

@carddb/browser

CardDB client for browsers.

Installation

npm install @carddb/browser
# or
bun add @carddb/browser

Quick Start

import { CardDBClient, BrowserCache, gte, ilike } from '@carddb/browser'

const client = new CardDBClient({
  publishableKey: 'carddb_pk_xxx...', // Browser-safe public key
  cache: new BrowserCache(), // Optional localStorage-based caching
  defaultPublisher: 'pokemon',
  defaultGame: 'tcg',
})

// Search for cards with filtering
const cards = await client.records.search({
  datasetKey: 'cards',
  filter: (f) => f.where('hp', gte(100)).where('name', ilike('%pikachu%')),
})

// Iterate through all results (auto-paginates)
for await (const card of cards) {
  console.log(card.data.name)
}

Use accessToken instead of publishableKey for user-authorized OAuth deck workflows. secretKey is server-only and the browser client rejects it at construction time. The browser client also rejects legacy apiKey because it is ambiguous and can accidentally expose a secret key; use publishableKey explicitly for public browser reads.

Publisher management helpers such as games.create, records.upsertBatch, imports.run, exports.run, and files.requestUpload require a server-side secret credential and should be called from @carddb/node in a trusted backend, not directly from browser code. Keep content pipelines, source URL imports, uploaded file imports, bulk deletes, and exports on the server side.

const client = new CardDBClient({
  accessToken: oauthAccessToken,
})

const decks = await client.decks.listMine()
const updated = await client.decks.updateMetadata(deck.id, {
  expectedDraftRevision: deck.draftRevision,
  title: 'Updated title',
})

BrowserCache

Browser-based cache using localStorage or sessionStorage:

import { BrowserCache } from '@carddb/browser'

// localStorage (default, persistent across sessions)
const persistentCache = new BrowserCache()

// sessionStorage (cleared when tab closes)
const sessionCache = new BrowserCache({ storage: 'sessionStorage' })

// Custom key prefix (default: 'carddb:')
const customCache = new BrowserCache({ prefix: 'myapp:carddb:' })

// Use with client
const client = new CardDBClient({
  cache: persistentCache,
  cacheTtl: 300, // 5 minutes default
  cacheTtls: {
    publishers: 3600, // 1 hour for publishers
    records: 60, // 1 minute for records
  },
})

// Manual cache management
cache.cleanup() // Remove expired entries
cache.clear() // Clear all CardDB entries
cache.size // Number of cached entries

Bundle Size

The browser package is optimized for minimal bundle size. Tree-shaking is fully supported.

Full Documentation

See the main README for complete documentation.

License

MIT

版本与发布记录

@carddb/browser 共发布 21 个版本,首次发布于 2026/04/28;过去 12 个月发布了 21 个版本。

版本发布日期距今
0.5.8latest2026/07/283 个月前
0.5.72026/07/253 个月前
0.5.62026/07/173 个月前
0.5.52026/07/104 个月前
0.5.12026/07/094 个月前
0.5.02026/07/074 个月前

关于 @carddb/browser 的常见问题

@carddb/browser 是什么?

CardDB client for browsers

如何安装 @carddb/browser?

在项目目录运行 npm install @carddb/browser,或使用 pnpm add / yarn add / bun add。

@carddb/browser 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@carddb/browser 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@carddb/browser 可以商用吗?

@carddb/browser 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@carddb/browser 的下载量有多少?

根据 npm 官方下载统计,@carddb/browser 在 2026/10/09 – 2026/11/07 这 30 天内被下载 4,943 次,日均约 165 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@carddb/browser 还在维护吗?

最新版本 0.5.8 发布于 2026/07/28(3 个月前);至今共发布 21 个版本,其中过去 12 个月发布了 21 个;首次发布于 2026/04/28。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。