@dunx/infra

中文文档
3.10.6发布于 2026/10/30MITTypeScriptES Module构建来源已验证近 30 天下载 3660

Database, Redis, queue, AMQP, schedule, storage, image and logging infrastructure for dunx. drizzle over bun:sqlite and Bun.SQL, bullmq over Bun.RedisClient, rabbitmq-client for RabbitMQ, plus Bun.file, Bun.Glob, Bun.S3Client, Bun.Image and @arkv/logger

原始使用文档
文档目录6 节
  1. Install
  2. The subpaths
  3. Usage
  4. Two conventions
  5. Verified against
  6. License

@dunx/infra

Infrastructure for dunx: databases, Redis/Valkey, caching, queues, message brokers, file storage, images, scheduling, email, pagination and logging. Eleven areas, one package.

Where Bun ships the primitive, the primitive is what runs: Bun.SQL, bun:sqlite, Bun.RedisClient, Bun.file, Bun.Glob, Bun.S3Client, Bun.Image, Bun.cron. No pg, no better-sqlite3, no ioredis, no @aws-sdk, no glob, no sharp.

Five areas integrate a mature library rather than hand-rolling one: /db over drizzle-orm, /queue over bullmq, /amqp over rabbitmq-client, /logger over @arkv/logger, and /email over whichever provider a subpath names.

The first three are optional peer dependencies, so an app using only /files installs none of them. @arkv/logger is first-party and a plain dependency. The first two drive a Bun API underneath; rabbitmq-client speaks a wire protocol Bun ships no client for, over node:net, which Bun implements natively.

Install

bun add @dunx/infra @dunx/core
# plus what the areas you use need
bun add drizzle-orm     # /db
bun add bullmq          # /queue
bun add rabbitmq-client # /amqp
bun add resend          # /email/resend
bun add nodemailer      # /email/smtp
bun add react @react-email/render # /email/react

The subpaths

The guide is canonical for every row; this table is the index.

SubpathWhat it isGuide
@dunx/infra/dbdrizzle over bun:sqlite and Bun.SQL, transactions, seeds, named and per-tenant data sources, query timingsDatabase
@dunx/infra/redisBun.RedisClient, named connections, pub/subDatabase
@dunx/infra/cacheCache over a memory, Redis or two-tier CacheStore, CacheMetricsCaching
@dunx/infra/queuebullmq over Bun.RedisClient: handlers, publisher, workerQueues
@dunx/infra/amqprabbitmq-client: @AmqpHandler, publisher, drained consumersMessage brokers
@dunx/infra/scheduleBun.cron and timers: @Cron, @Interval, @OnceOnBootScheduling
@dunx/infra/filesOne Storage contract over Bun.file and Bun.S3ClientFiles and images
@dunx/infra/emailOne EmailTransport contract, dry run, pacing, a renderer seam, and bunx dunx-email previewEmail
@dunx/infra/email/resendresendEmail
@dunx/infra/email/smtpnodemailerEmail
@dunx/infra/email/reactReact Email, as one TemplateRenderer among othersEmail
@dunx/infra/imagesAn immutable pipeline over Bun.ImageFiles and images
@dunx/infra/logger@arkv/logger bound to core's Logger contractLogging
@dunx/infra/paginationKeyset pagination: cursor codec, options parser, drizzle queryDatabase
@dunx/infra/pagination/cursorThe same codec and parser without the drizzle query, so it resolves with no drizzle installedDatabase

Usage

import { Module } from '@dunx/core';
import { DbModule, SqliteOptions } from '@dunx/infra/db';
import { RedisModule } from '@dunx/infra/redis';
import * as schema from './schema.js';

@Module({
  imports: [
    DbModule.forRoot(new SqliteOptions({ schema, filename: './app.db' })),
    // No url: Bun resolves $VALKEY_URL, then $REDIS_URL, then localhost.
    RedisModule.forRoot({ maxRetries: 0 }),
  ],
})
export class InfraModule {}

With OtelModule from @dunx/core/otel imported, /db, /redis, /queue and /amqp open OpenTelemetry spans; see Tracing.

Every area also has a forRootAsync, which is forRoot with a factory in front of it. It exists for the one thing a zero-argument function cannot do: inject, so the url or the filename can come off ConfigService.

Two conventions

Anything injectable by a constructor parameter is a runtime class, never an interface, because an interface erases and leaves nothing for @dunx/transform to record.

When dunx defines the contract, the token is an abstract class (Storage, DbConnection, ImagesOptions). Otherwise it is the library's own class (BunSQLiteDatabase, ContextStore). Three exports are token()s instead, because no class fits them: redisConnection(name), redisMetrics(name) and LoggerSettings.

If an area is in the root barrel at all, all of it is. /db, /queue, /amqp and /email are the four the barrel does not re-export: each reaches an optional peer through a static import, so exporting them would make drizzle-orm, ioredis, rabbitmq-client or resend hard requirements of import '@dunx/infra'. Reach them at their subpaths.

Within /email the split goes one level further. Each vendor import sits in the subpath that needs it and nowhere else: resend in /email/resend, nodemailer in /email/smtp, react and @react-email/render in /email/react.

So @dunx/infra/email loads with none of the four installed, and you can use its log and memory transports. The dunx-email bin loads a renderer with import() only when it needs one.

@dunx/infra's tests check which file may import each vendor, that the base subpath imports none of them, and that all four are marked optional.

Timing is off unless asked for. { metrics: true } is the last argument to DbModule, CacheModule, RedisModule and QueueModule, binding a QueryMetrics, CacheMetrics, RedisMetrics or QueueMetrics.

What each one measures:

SubpathTimed
/dbEvery query. dunx wraps the driver it creates, since drizzle's logger option does not report durations
/cacheHits and misses on the configured CacheStore, including one injected directly. A coalesced wrap counts as one read
/redisEvery command
/queuepublish(), and handlers run in this process. A background handler runs in a forked process and is not timed

See Metrics.

Verified against

Bun 1.4.2, drizzle-orm 0.45.2, bullmq 6.0.5, rabbitmq-client 5.0.8, resend 6.28.0, nodemailer 10.0.9 and @react-email/render 2.1.0. Bun's documentation is incomplete across every area here, so the behaviour was measured rather than read. The evidence is in docs/ARCHITECTURE.md and docs/bun-apis.md.

License

MIT

版本与发布记录

@dunx/infra 共发布 83 个版本,首次发布于 2026/08/02;过去 12 个月发布了 83 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
3.10.6latest2026/10/3014 天前
3.10.52026/10/2222 天前
3.10.42026/10/2024 天前
3.10.32026/10/1430 天前
3.10.22026/10/081 个月前
3.10.12026/09/261 个月前

关于 @dunx/infra 的常见问题

@dunx/infra 是什么?

Database, Redis, queue, AMQP, schedule, storage, image and logging infrastructure for dunx. drizzle over bun:sqlite and Bun.SQL, bullmq over Bun.RedisClient, rabbitmq-client for RabbitMQ, plus Bun.file, Bun.Glob, Bun.S3Client, Bun.Image and @arkv/logger

如何安装 @dunx/infra?

在项目目录运行 npm install @dunx/infra,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@dunx/core(^3.10.6)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。它还提供命令行工具 dunx-email,可以用 npx dunx-email 直接运行。

@dunx/infra 支持 TypeScript 吗?

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

@dunx/infra 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@dunx/infra 可以商用吗?

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

@dunx/infra 的下载量有多少?

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

@dunx/infra 还在维护吗?

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