# @blued-core/qconf

> 基于 qconf 的简易封装。

Latest version **1.0.4** (published 2020-07-02) · ISC license · 0 weekly downloads

## Install

```sh
npm install @blued-core/qconf
pnpm add @blued-core/qconf
yarn add @blued-core/qconf
bun add @blued-core/qconf
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2020-07-02 |
| First published | 2019-04-12 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 15.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | fengcang2020, jiasm, nieweidong, ryli |

## Links

- npm: https://www.npmjs.com/package/@blued-core/qconf
- Repository: https://github.com/bluedapp/node-util-qconf
- Homepage: https://github.com/bluedapp/node-util-qconf#readme
- Issues: https://github.com/bluedapp/node-util-qconf/issues
- npm.io page: https://npm.io/package/@blued-core/qconf

## Dependencies (1)

- [node-qconf](https://npm.io/package/node-qconf.md) ^0.4.2

## Recent versions

- 1.0.4 (latest) — 2020-07-02
- 2.0.2 (next) — 2019-12-02
- 0.1.0 — 2020-07-02
- 1.0.3 — 2020-06-10
- 0.0.7 — 2020-06-10
- 2.0.1 — 2019-11-25
- 2.0.0 — 2019-11-25
- 1.0.2 — 2019-08-02
- 1.0.1 — 2019-07-29
- 1.0.0 — 2019-07-29
- 0.0.8 — 2019-07-09
- 0.0.6 — 2019-05-05
- 0.0.5 — 2019-04-25
- 0.0.4 — 2019-04-15
- 0.0.3 — 2019-04-15
- … 1 more at https://npm.io/package/@blued-core/qconf/versions

## README

# blued-qconf

基于 qconf 的简易封装。

```bash
npm install @blued-core/qconf
```

## Usage

__目前除`mysql`配置以外，其余结构都可以简写为`key: value`，而不需要`key: { qconf: value }`。__  

```typescript
import { Qconf } from '@blued/qconf'

const configs = {
  mysqlConf: {
    qconf: 'XXX',     // qconf 路径 ⚠️ 无需包涵 /master /slave 的字眼
    database: 'XXX',  // optional 数据库 database
    modelPath: 'XXX', // optional sequelize 模型路径
  },
  redisConf: {
    qconf: 'XXX',     // qconf 路径
  },
  normalHost: {
    qconf: 'XXX',     // qconf 路径
  },
  normalConf: 'XXX',     // qconf 路径
  redisStringConf: 'XXX',
  normalStringHost: 'XXX',
  normalStringConf: 'XXX'
}

const qconf = new Qconf(config)

// 可选的 flag 参数用于使用不同环境下的配置文件
qconf.flag = 'production'

qconf.getConf('mysqlConf')
```

> 除了 MySQL 相关的配置外，其他的都可以直接简写为`key: value` 而不需要携带 `qconf` 属性。

## API

### getConf/getHost

> 获取一个`key`所对应的`conf`，`key`必须存在于实例化`qconf`时传入的`configs`。  
> 如不存在则会抛出异常`can not found conf with key: [key]`。 

```typescript
qconf.getConf('key') // => string
qconf.getHost('key') // => string
```

### getQconfHost/getQconfConf/getQconfAllHost

> 根据`qconf`路径获取对应的参数  

```typescript
qconf.getQconfConf('/qconf/xxx/key')        // => string
qconf.getQconfHost('/qconf/xxx/key')        // => string
qconf.getQconfAllHost('/qconf/xxx/key')     // => string[]
```

### getRedisConf

> 根据传入的`key`获取 redis 配置

```typescript
qconf.getRedisConf('key') // => { host: 'XXX', port: '1234' }
```

### getMysqlConf

> 根据传入的`key`获取 mysql 配置

```typescript
qconf.getMysqlConf('key')

// 返回值如下
{
  masterHost: 'XXX',              // 主库地址
  slaveHost: ['XXX', 'XXX'],      // 从库地址
  username: 'XXX',                // 用户名
  password: 'XXX',                // 密码
  database: 'XXX' || undefined,   // 数据库
  modelPath: 'XXX' || undefined,  // sequelize 对应的模型地址
}
```

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