# bpframework

> Web framework like java springboot and springcloud

Latest version **0.4.3** (published 2026-07-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install bpframework
pnpm add bpframework
yarn add bpframework
bun add bpframework
```

## Health

**Score 55/100 (C)** — status: active.

Positive: has types; no vulnerabilities; high maintenance score.

Warnings: low downloads; no esm support; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.4.3 |
| Published | 2026-07-14 |
| First published | 2020-11-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=8 |
| Dependencies | 8 |
| Unpacked size | 512.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Maintainers | brainpoint |
| Keywords | java, spring, springboot, springcloud, annotation, validation, controller, service, feign, feignClient, PathVariable, RequestBody, RequestMapping, postmapping, getmapping, RequestParam, restcontroller, request, service, autowired |

## Links

- npm: https://www.npmjs.com/package/bpframework
- Repository: https://github.com/bpcloud/bpframework
- Homepage: https://github.com/bpcloud/bpframework#readme
- Issues: https://github.com/bpcloud/bpframework/issues
- npm.io page: https://npm.io/package/bpframework

## Dependencies (8)

- [cron](https://npm.io/package/cron.md) ^1.8.2
- [febs](https://npm.io/package/febs.md) ^1.2.10
- [yaml](https://npm.io/package/yaml.md) ^1.10.0
- [nacos](https://npm.io/package/nacos.md) ^2.0.0
- [amqplib](https://npm.io/package/amqplib.md) ^0.8.0
- [reflect-metadata](https://npm.io/package/reflect-metadata.md) ^0.1.13
- [cloud-config-client](https://npm.io/package/cloud-config-client.md) ^1.5.2
- [@bpframework/middleware-koa-bodyparser](https://npm.io/package/@bpframework/middleware-koa-bodyparser.md) 0.0.3

## Alternatives

- [@luma.gl/experimental](https://npm.io/package/@luma.gl/experimental.md) — 77.1K weekly downloads
- [persona-harness](https://npm.io/package/persona-harness.md) — 4.7K weekly downloads
- [@tsparticles/effect-bubble](https://npm.io/package/@tsparticles/effect-bubble.md) — 4.6K weekly downloads
- [f3d](https://npm.io/package/f3d.md) — 730 weekly downloads
- [spark-html-motion](https://npm.io/package/spark-html-motion.md) — 298 weekly downloads

## Recent versions

- 0.4.3 (latest) — 2026-07-14
- 0.4.2 — 2025-04-05
- 0.4.1 — 2025-04-02
- 0.4.0 — 2025-04-02
- 0.3.30 — 2025-04-01
- 0.3.29 — 2025-03-15
- 0.3.28 — 2025-03-13
- 0.3.27 — 2025-03-13
- 0.3.26 — 2025-02-18
- 0.3.25 — 2025-02-12
- 0.3.24 — 2025-01-20
- 0.3.23 — 2022-03-14
- 0.3.22 — 2022-03-14
- 0.3.21 — 2022-01-24
- 0.3.20 — 2022-01-24
- … 87 more at https://npm.io/package/bpframework/versions

## README

<font color=red>This project is still in development</font>

- [Setup.](#setup)
- [Example.](#example)
- [Feature.](#feature)
- [Configure.](#configure)
  - [@FindMicroserviceConfigure](#findmicroserviceconfigure)
  - [@RestControllerConfigure](#restcontrollerconfigure)
  - [@IgnoreRestLogger](#ignorerestlogger)
  - [@RequestConditional](#requestconditional)
  - [@FeignClientConfigure](#feignclientconfigure)
  - [@Value](#value)
- [Middleware.](#middleware)
- [Event Listener.](#event-listener)
  - [@ContextRefreshedEventListener](#contextrefreshedeventlistener)
  - [@RefreshRemoteEventListener](#refreshremoteeventlistener)
  - [@InstanceRegisteredEventListener](#instanceregisteredeventlistener)
- [Scheduling](#scheduling)
  - [@Scheduled](#scheduled)
- [Bean](#bean)
  - [@Service](#service)
  - [@Bean](#bean-1)
  - [@Autowired](#autowired)
  - [@Value](#value-1)

## Setup.

use cli to create a project.

```bash
npm i bpframework-cli -g
```

create a project.

```bash
bpframework init
```

## Example.

see directory [./examples](./examples)

## Feature.

| feature     | supports                           |
| ----------- | ---------------------------------- |
| config      | bootstrap.yml<br>SpringCloudConfig |
| discovery   | nacos                              |
| scheduling  | @Scheduled                         |
| api routers | @RestController                    |

## Configure.

The appropriate configuration is required to enable the corresponding feature: [config](./config.md)

| name                                                    | description                           |
| ------------------------------------------------------- | ------------------------------------- |
| [FindMicroserviceConfigure](#findmicroserviceconfigure) | 定义自定义的服务发现处理方法          |
| [FeignClientConfigure](#feignclientconfigure)           | 定义FeignClient的默认headers等信息    |
| [RestControllerConfigure](#restcontrollerconfigure)     | 定义RestController的默认headers等信息 |


### @FindMicroserviceConfigure

By default, nacos is used to find micro-service; You can customize it by `@FindMicroserviceConfigure`.

```js
@Service()
class Configure {
  @FindMicroserviceConfigure
  async onFindMicroservice(serviceName: string, excludeHost: string): Promise<ServiceInfo> {
    return {
      ip,
      port,
      serviceName,
      metadata,
    }
  }
}
```

### @RestControllerConfigure

定义RestController的默认headers等信息, 使用如下方式.

```js
@Service()
class Configure {
  @RestControllerConfigure
  onConfigure(): bp.RestControllerConfigureInfo {
    return {
      defaultHeaders: {'content-type': 'application/json;charset=utf-8'},
    }
  }
}
```

### @IgnoreRestLogger

用于忽略rest请求的日志, 使用如下方式.

```js
@RestController({ path: '/api' })
class Rest {
  @IgnoreRestLogger
  @RequestMapping({ path: '/url', method: RequestMethod.GET })
  async request(
    @RestObject obj: RestObjectTypeRest<koa.Context> // or RestObjectType
  ): Promise<ListRolesRequest> {
    ...
  }
}
```

### @RequestConditional

用于判断rest请求是否执行

```js
type RequestMatchFunction = (restObjec: RestObjectType<any> | RestObjectTypeFeign<any>) => Promise<boolean>;
/**
 * @desc 当match函数返回false时，不继续执行请求.
 * 
 * @returns {MethodDecorator}
 */
export function RequestConditional(match: RequestMatchFunction): MethodDecorator;
```

实例

```js
@RestController({ path: '/api' })
class Rest {
  @RequestConditional(async (restObject:RestObjectType<any>):Promise<boolean> => {
    return false;
  })
  @RequestMapping({ path: '/url', method: RequestMethod.GET })
  async request(
    @RestObject obj: RestObjectTypeRest<koa.Context> // or RestObjectType
  ): Promise<ListRolesRequest> {
    // 将不执行.
  }
}
```

### @FeignClientConfigure

定义FeignClient的默认headers等信息, 使用如下方式.

```js
@Service()
class Configure {
  @FeignClientConfigure
  onConfigure(): bp.FeignClientConfigureInfo {
    return {
      defaultHeaders: {'content-type': 'application/json;charset=utf-8'},
      /**
       * 对每次请求后接收的消息进行过滤.
       */
      filterResponseCallback: (data: FeignClientFilterResponseData) => {
        
      },
      /**
       * Processing the data of the request.
       */
      filterRequestCallback: (data: FeignClientFilterRequestData, feignData: FeignDataType) => {

      }
    }
  }
}
```

### @Value

使用 @Value 注解设置初始值或获取配置值.

```js
@Service()
class Demo {
  @Value("Miss A")
  teacher1Name: string; // will set to 'Miss A'

  @Value("${teacherName2}")
  teacher2Name: string; // will set to config value "teacherName2"

  @Value("${teacherName3:defaultName}")
  teacher3Name: string; // will set to 'defaultName' if config value "teacherName3" isn't existed.
}
```

## Middleware.

see https://github.com/bpcloud/middleware.git

## Event Listener.

| name                                                                | description                                 |
| ------------------------------------------------------------------- | ------------------------------------------- |
| [ContextRefreshedEventListener](#ContextRefreshedEventListener)     | 本地配置加载完成, 系统service对象初始化完成 |
| [RefreshRemoteEventListener](#RefreshRemoteEventListener)           | 远程配置动态刷新事件                        |
| [InstanceRegisteredEventListener](#InstanceRegisteredEventListener) | 实例注册到注册中心后的事件                  |

### @ContextRefreshedEventListener

本地配置加载完成, 系统service对象初始化完成.

```js
@Service()
class ApplicationEvent {
  @ContextRefreshedEventListener
  async onContextRefreshed(ev:ContextRefreshedEvent):void {

  }
}
```

### @RefreshRemoteEventListener

远程配置动态刷新事件.

```js
@Service()
class ApplicationEvent {
  @RefreshRemoteEventListener
  async onRefreshRemote(ev:RefreshRemoteEvent):void {

  }
}
```

### @InstanceRegisteredEventListener

实例注册到注册中心后的事件.

```js
@Service()
class ApplicationEvent {
  @InstanceRegisteredEventListener
  async onInstanceRegistered(ev:InstanceRegisteredEvent):void {
    
  }
}
```

## Scheduling

### @Scheduled

全局启动scheduled

```js
global.__enableScheduled = true;
```

使用此注解可以开启一个定时任务.

```js
@Service()
class Demo {
  @Scheduled({cron:'* * * * * *'})
  async onTick(): Promise<false|void> {
    return false; // 返回false则表明停止此task.
  }
}
```

- Start task:  当类实例被创建后, task即按照时间间隔运行
- Stop task: 当@Scheduled修饰的方法明确返回false时, task将停止

## Bean

### @Service

可以使用此注解实例化对象

```js

/**
 * 加载所有的bean, 并进行实例化等操作.
 */
export function finishBeans(): Promise<void>;

/**
* @desc 获得已装配完的指定类型的service.
*/
export function getServiceInstances(key: any): ServiceInstanceType;

/**
 * 无需等待执行 finishBeans().
 * 
 * @returns {ClassDecorator}
 */
export function ImmediatelyService(name: string): ClassDecorator;
export function ImmediatelyService(cfg?: { singleton?: boolean, name?: string }): ClassDecorator;

/**
 * @desc 表明指定的类为Service类.
 * 
 * 定义为Service的类, 在源文件被引用后, 单例bean将会自动在全局创建一个实例.
 * 
 * @description 
 *  `Service` 与 `Bean` 都是延迟注入类型; 需要在 `finishBeans()` 方法调用之后才能够生效.
 *  需实现立即生效类型使用 `ImmediatelyService`
 * 
 * @param cfg.singleton 是否为单例; (默认单例)
 * @param cfg.name      使用名称注入; 如不使用名称,则使用类型注入.
 *
 * @returns {ClassDecorator}
 */
export function Service(name: string): ClassDecorator;
export function Service(cfg?: { singleton?: boolean, name?: string }): ClassDecorator;
```

示例：

```js
/**
 * 在app初始化完成后将自动实例化.
 */
@Service()
class Example {
  constructor() {}
}

/**
 * 立即自动实例化.
 */
@ImmediatelyService()
class Example {
  constructor() {}
}
```

### @Bean

```js

/**
 * @desc 表明指定的属性为Bean.
 * 
 * <Bean修饰的方法不允许带参数, 并且返回的类型作为注入对象的类型.>
 * 定义为Bean, 在源文件被引用后, 单例bean将会自动在全局创建一个实例.
 * 
 * @description 
 *  `Service` 与 `Bean` 都是延迟注入类型; 需要在 `finishBeans()` 方法调用之后才能够生效.
 *  需实现立即生效类型使用 `ImmediatelyService`
 * 
 * @param cfg.singleton 是否为单例; (默认单例)
 * @param cfg.name      使用名称注入; 如不使用名称,则使用方法名注入.
 * 
 * @example
 * 
 * ﹫Service()
 * class {
 *       ﹫Bean() 
 *       foo(): Object { 
 *           return {};
 *       }
 * 
 *       ﹫Autowired('foo')
 *       private obj: Object;
 * }
 * @returns {PropertyDecorator}
 */
export function Bean(name: string): MethodDecorator;
export function Bean(cfg?: { singleton?: boolean, name?: string }): MethodDecorator;
```


### @Autowired


```js
/**
 * @desc 表明指定的属性可以自动装载指定的Service实例.
 * 
 * @example
 *  ﹫Autowired(ClassA)
 *  obj: ClassA;  // will to auto create object.
 * 
 * @returns {PropertyDecorator}
 */
export function Autowired(type: Function|string): PropertyDecorator;
```

### @Value

```js
/**
 * @desc 表明指定的属性可以自动装载指定的值.
 * @description 无需添加 RefreshScope 注解; 在配置刷新时会自动变更值.
 * @example
 *   ﹫Service()
 *   class Demo {
 *     ﹫Value("Miss A")
 *     teacher1Name: string; // will set to 'Miss A'
 * 
 *     ﹫Value("${teacherName2}")
 *     teacher2Name: string; // will set to config value "teacherName2"
 * 
 *     ﹫Value("${teacherName3:defaultName}")
 *     teacher3Name: string; // will set to 'defaultName' if config value "teacherName3" isn't existed.
 *   }
 * 
 * @returns {PropertyDecorator}
 */

export function Value(value: any): PropertyDecorator;
```

---
_Source: https://npm.io/package/bpframework · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
