Introducing The Sweep: OX’s New Live Security Research Series
Register Now
Breaking: The 2026 Vulnpocalypse Hits PHP: Four Critical RCEs, but How Dangerous Are They?
Read the Report
Are you exposed? Connect your apps in minutes.
Scan your apps free

@lark-apaas/nestjs-datapaas

Latest version: v1.0.33-alpha.20261201023003

Overview

Last scanned
1 Dec 2026
Published
1 Dec 2026
npm package Publisher: aihao.0331, byted.lycoiref, bytedance-npm-team, chengshihao1, duanlikang_byte, fengtianran_byted, prgrmr_byte, xiaochuanzhang_byted, yanmingjiang, yuki-bytedance
87 Versions
29.6K Downloads

Scan summary

@lark-apaas/nestjs-datapaas was last scanned on 1 Dec 2026 at version 1.0.33-alpha.20261201023003. Risk score 0 of 100. No malicious behavior was detected.

  • Releases: 87 versions; the latest 5 were published within 2 days (30 Nov and 1 Dec 2026).
  • Findings: No rules fired in version 1.0.33-alpha.20261201023003.
  • Downloads: 29,564 downloads.

Versions

87 versions published
Versions and the rules that fired in each
VersionPublishedStatus
1.0.33-alpha.20261201023003 LATEST 1 Dec 2026 No rules fired
1.0.32 30 Nov 2026 No rules fired
1.0.32-alpha.20261130125410 30 Nov 2026 No rules fired
1.0.32-beta.0 30 Nov 2026 Not shown
1.0.32-alpha.20261130122756 30 Nov 2026 Not shown

No rules fired in 1.0.33-alpha.20261201023003

Findings

Findings for v1.0.33-alpha.20261201023003. The score is a capped sum of the weights of the rules that fired — not CVSS, not exploitability, and not a probability. It is not comparable across packages with different scan coverage.

The score describes 1.0.33-alpha.20261201023003; other versions have their own rules, not their own score.

README

The publisher’s own README, as collected from the registry.

DataPaas 数据库模块

基于 Drizzle ORM 封装的 PostgreSQL 数据库连接模块,提供连接池、请求上下文注入与事务等能力。

功能特性

  • 🚀 基于 Drizzle Postgres ORM 的高性能数据库操作
  • 🔄 自动在 pg session 执行层面注入 user_id 环境变量以无感支持 RLS 功能,数据库实例方法完全兼容 drizzle-orm/postgres-js
  • 🛡️ 连接池管理和健康检查
  • 🎯 NestJS 模块化集成
  • 🎨 装饰器支持,简化使用
  • 🔧 丰富的工具函数

安装依赖

npm install @lark-apaas/nestjs-datapaas

基本使用

Base 查询的 prepare

Base 数据源的带参数查询默认开启 postgres.js prepare,同一物理连接上的同一 SQL 可以复用 statement。事务、savepoint 和 reserve 客户端继承该设置;每次查询的身份设置仍照常执行。无参数查询(包括聚合的 SET LOCAL)保持原有协议,PG 数据源保持原有行为。

在 DataPaasModule.forRoot 或 forRootAsync 的配置中设置 basePrepare: false 可关闭这项默认行为。直接调用客户端 unsafe 时,显式传入的 { prepare: false } 也会保留。

1. 模块注册
方式 1:同步配置(forRoot)

适用于配置可以直接从环境变量或常量获取的场景:

import { Module } from '@nestjs/common';
import { DataPaasModule } from '@lark-apaas/nestjs-datapaas';

@Module({
  imports: [
    DataPaasModule.forRoot({
      // PostgreSQL 连接串,如:postgres://user:pass@host:port/dbname
      connectionString: process.env.DATABASE_URL!,
      schema: yourSchema,               // 可选,Drizzle schema
      logger: true,                     // 可选,启用日志
      timeout: 10000,                   // 可选,请求超时(ms)
      idleTimeout: 20,                  // 可选,空闲连接超时(s)
      connectionTimeout: 10,            // 可选,连接超时(s)
      ssl: false,                       // 可选,是否启用 SSL
      autoContext: true,                // 可选,为 SQL 执行自动设置 user_id 环境变量
    }),
  ],
})
export class AppModule {}
方式 2:异步配置(forRootAsync)

推荐使用,适用于需要从 ConfigModule 等异步配置源获取配置的场景:

import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { DataPaasModule } from '@lark-apaas/nestjs-datapaas';
import * as schema from './database/schema';

@Module({
  imports: [
    ConfigModule.forRoot({
      isGlobal: true,
    }),
    DataPaasModule.forRootAsync({
      imports: [ConfigModule],
      useFactory: async (configService: ConfigService) => ({
        connectionString: configService.get<string>('DATABASE_URL')!,
        schema,
        logger: configService.get<boolean>('DATABASE_LOGGER') || false,
        timeout: configService.get<number>('DATABASE_TIMEOUT') || 10000,
        maxConnections: configService.get<number>('DATABASE_MAX_CONNECTIONS') || 7,
        ssl: configService.get<boolean>('DATABASE_SSL') || false,
        autoContext: true,
      }),
      inject: [ConfigService],
    }),
  ],
})
export class AppModule {}

提示:

  • 使用 forRootAsync 时,配置会在应用启动时从 ConfigService 异步获取
  • 支持 useFactory、useClass 和 useExisting 三种配置方式
  • 详细的异步配置使用方法请参考 ASYNC_USAGE.md

注意: 新版本使用标准的 NestJS 依赖注入模式,所有服务都会自动初始化和管理。

2. 在服务/控制器中使用
import { Injectable, Inject } from '@nestjs/common';
import { 
  DataPaasDatabaseService,
  DrizzleDatabaseManager,
  Database,
  DatabaseManager,
  DatabaseService,
  DRIZZLE_DATABASE,
  type PostgresJsDatabase
} from '@lark-apaas/nestjs-datapaas';

@Injectable()
export class UserService {
  constructor(
    private readonly databaseService: DataPaasDatabaseService,
    private readonly databaseManager: DrizzleDatabaseManager,
    @Inject(DRIZZLE_DATABASE) private readonly db: PostgresJsDatabase,
  ) {}

  // 方式一:构造函数注入数据库实例
  async getUsersByCtor() {
    return this.db.select().from(users);
  }

  // 方式二:方法参数装饰器(请求上下文友好)
  async getUsers(@Database() db: PostgresJsDatabase) {
    return db.select().from(users);
  }

  // 使用装饰器注入数据库管理器
  async getConnectionStatus(@DatabaseManager() manager: DrizzleDatabaseManager) {
    return manager.getConnectionPoolStatus();
  }

  // 使用装饰器注入数据库服务
  async getHealthStatus(@DatabaseService() service: DataPaasDatabaseService) {
    return service.isConnected();
  }

  // 健康检查
  async checkHealth() {
    return this.databaseService.testConnection();
  }

  // 获取连接池状态
  async getPoolStatus() {
    return this.databaseManager.getConnectionPoolStatus();
  }
}
3. 多数据源

数据源由环境变量 MIAODA_DATASOURCE_CONF 决定,平台 PG(engine: pg)和 Base(engine: base)各 0 或 1 个,workspace 为数据源所在的 workspace:

{ "version": 1, "datasources": [
  { "workspace": "workspace_xxx", "engine": "pg",   "url": "postgresql://…?schema=workspace_xxx" },
  { "workspace": "workspace_yyy", "engine": "base", "url": "postgresql://…?schema=workspace_yyy" }
] }
  • 未设置 MIAODA_DATASOURCE_CONF 时,connectionString 作为唯一的平台 PG(存量行为)。
  • 每个数据源一个连接池,身份语句(SET LOCAL ROLE / app.*)按查询所用连接的数据源生成,ROLE 取自该数据源连接串的 schema 参数。
  • SQL 日志和查询 span 使用同一组模块名:平台 PG 为 data,Base 为 data-base。全栈应用开发环境分别显示 Database:PG 和 Database:Base。
  • 启用请求上下文中间件后,自动读取 req.headers['x-tt-logid'],将 SET LOCAL context.log_id = '<log_id>' 与身份语句合并为同一份 preSql,供 PG / Base 查询关联请求日志。缺失或空请求头不注入;并发请求分别保存各自的 log ID。
  • PG 和 Base 还会将请求头 x-tt-env、x-schedule-vdc 分别写入事务内的 context.tt_env、context.schedule_vdc。两个字段独立读取,去掉首尾空白后有值才注入。
  • 配置中没有的数据源注入未绑定占位:可以注入、构建查询,执行时抛 DataSourceUnboundException(503)。
import { BASE_DATABASE, PG_DATABASE, type BaseDatabase, type PostgresJsDatabase } from '@lark-apaas/nestjs-datapaas';

@Injectable()
export class CustomerService {
  constructor(
    @Inject(PG_DATABASE) private readonly db: PostgresJsDatabase,
    @Inject(BASE_DATABASE) private readonly base: BaseDatabase,
  ) {}
}

API 参考

DataPaasModule
forRoot(options)

同步配置方法。

参数:

  • connectionString: PostgreSQL 连接串(必填)
  • schema: Drizzle schema(可选)
  • logger: 是否启用日志(可选,默认 false)
  • timeout: 请求超时(ms,可选,默认 10000)
  • maxConnections: PG 和 Base 各自的连接池上限(可选,默认每池 7 条)
  • idleTimeout: 空闲连接超时(秒,可选,默认 20)
  • connectionTimeout: 连接超时(秒,可选,默认 10)
  • ssl: 是否启用 SSL(可选,默认 false)
  • autoContext: 是否为请求自动设置上下文(可选,默认 true)
forRootAsync(options)

异步配置方法,支持从 ConfigModule 等异步源获取配置。

参数:

  • imports: 需要导入的模块(例如 [ConfigModule])
  • inject: 工厂函数需要注入的依赖
  • useExisting: 已存在的配置 provider
  • useFactory: 工厂函数,返回配置对象
DataPaasModule.forRootAsync({
  imports: [ConfigModule],
  useFactory: (configService: ConfigService) => ({
    connectionString: configService.get('DATABASE_URL')!,
  }),
  inject: [ConfigService],
})
DataPaasDatabaseService
  • testConnection(): 测试数据库连接
  • isConnected(): 检查连接状态
  • getConnectionPoolStatus(): 获取连接池状态
装饰器
  • @Database(): 注入 Drizzle 数据库实例
常量 Token
  • PG_DATABASE: 平台 PG 的数据库实例
  • BASE_DATABASE: Base 数据源的数据库实例(类型 BaseDatabase)
  • DRIZZLE_DATABASE: 已废弃,与 PG_DATABASE 是同一个实例
工具函数
  • DatabaseUtils.safeExecute(): 安全执行数据库操作
  • DatabaseUtils.batchExecute(): 批量执行操作
  • DatabaseUtils.executeWithRetry(): 带重试的执行
  • DatabaseUtils.tableExists(): 检查表是否存在
  • DatabaseUtils.getTableStructure(): 获取表结构
  • DatabaseUtils.getDatabaseVersion(): 获取数据库版本
  • DatabaseUtils.getConnectionStats(): 获取连接统计
  • DatabaseUtils.healthCheck(): 健康检查

最佳实践

  1. 健康检查: 定期进行健康检查,监控连接状态
  2. 依赖注入: 充分利用 NestJS 的 DI 系统,避免手动创建服务实例

注意事项

  1. 尽量保证 DataPaasModule 第一个加载注册,避免 autoContext 功能在某些初始场景失效
  2. 应用层禁止安装 drizzle-orm 包,如果需要 drizzle-orm 的相关导出,可以直接从 @lark-apaas/nestjs-datapaas 导出,因为 drizzle-orm/postgres-js 已经被打了 git patch 以支持 autoContext 的功能,重新安装可能会引入非预期的 bug

OX Radar and Response Center

Find threats in your stack.

OX Radar can check high-priority threats, like critical package CVEs, against your context.

Each incident is marked Detected or Not Detected with a remediation plan and proof all tracked in the Response Center.

Where it’s listed

The probe returned only these fields for this server — auth requirement, protocol and tool list weren’t observed, so they’re not shown (never guessed).

  • npm @lark-apaas/nestjs-datapaas

References

The publisher’s own links, as the registry reports them. These are not sources for the assessment on this page.

Powered by Read the latest findings

Scan your whole stack

Group 1261154050 1
Group 1261154050
 

From OX Research Newsroom

The 2026 Vulnpocalypse Hits PHP: Four Critical RCEs, but How Dangerous Are They?
Vulnerability Insights

The 2026 Vulnpocalypse Hits PHP: Four Critical RCEs, but How Dangerous Are They?

Critical Apache HTTP Server Flaw Exposes Web Servers to RCE (1)
CVE

CVE-2026-119618: Critical Apache HTTP Server Flaw Exposes Web Servers to Remote Code Execution

Plug and Pray: Your AI Agents Are Taking Orders From Strangers
Research

Plug and Pray: Your AI Agents Are Taking Orders From Strangers

Frame 2085668439 (1)
Group 1261154229