@blued-core/bc-qconf
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

bc-qconf

封装基于 child_process 调用本地命令方式的 qconf 获取库。兼容现有大部分使用方式。并支持 ts 类型校验及类型提示。

使用方式

包含的 API 对应 qconf 命令的 getConf、getHost、getAllHost、getBatchKeys 以及拓展的 getRedisConf、getMysqlConf 内容。在 ts 语法下支持参数提示,可自动提示所配置的 key 名。

示例

import { BcQconf, QConfigs } from '@blued/bc-qconf';

const qconfs: QConfigs<'conf' | 'host' | 'allHost' | 'mysql' | 'redis'> = {
  conf: {
    qconf: '/blued/backend/umem/qconf_test_cc/test_content'
  },
  host: {
    qconf: '/blued/backend/umem/qconf_test_cc'
  },
  allHost: {
    qconf: '/blued/backend/umem/qconf_test_cc'
  },
  mysql: {
    qconf: '/blued/backend/umem/qconf_test_cc',
    database: 'blued',
    modelPath: '/abc',
  },
  redis: {
    qconf: '/blued/backend/umem/qconf_test_cc'
  }
}

const qc = new BcQconf(qConfs)

// 返回 path 本身的节点值。如:{"activity_id":316,"start_time":"20231208","end_time":"20231214"}
qc.getConf('conf')

// 返回 path 下第一个节点值为 0 的节点名称。如:100.100.100.100:90
qc.getHost('host')

// 返回 path 下所有节点值为 0 的节点名称。如:[ '100.100.100.100:90', '123.123.123.123:80' ]
qc.getAllHost('allHost')

// 返回 path 下所有节点名称。如:[ '100.100.100.100:90', '123.123.123.123:80', 'database', 'master', 'password', 'slave', 'test_content', 'username' ]
qc.getBatchKeys('allHost')

// 是 getHost 的 alias
qc.getApi('host')

// 返回 path 下所有节点名称。支持 password 参数
// 如:{ host: '100.100.100.100', port: '90', password: 'wo_is_pwd' }
qc.getRedisConf('redis')

// 以 mysql 配置形式返回值。
// 如:{
  master: { host: '111.111.111.111', port: '80' },
  slave: [
    { host: '120.120.120.120', port: '100' },
    { host: '121.121.121.121', port: '101' }
  ],
  username: 'chisecc',
  password: 'wo_is_pwd',
  database: 'blued',
  modelPath: '/abc'
}
qc.getMysqlConf('mysql')

配置参数

{
  // qconf 读取路径配置。注意:必须包含 qconf 属性
  configs: { [key: string]: { qconf: string, database?: string, modelPath?: string } },

  // 表示要读区的配置的源(一般不用配置,按本地配置走)。如:production 则读取线上配置
  // flag 的值对应,qconf 下配置文件 idc.conf 内的名称
  flag: string
}

Todo

Changelog

1.0.4 (2023-12-25)

  • feat: 调整 ts 语法定义,新增 QConfigs 对象定义类型

1.0.3 (2023-12-23)

  • fix: qc.getRedisConf() 在部分场景下异常

1.0.2 (2023-12-22)

  • feat: 新增 QconfError 错误类型
  • feat: 调整 spawnSync 命令执行时,错误处理逻辑

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i @blued-core/bc-qconf

      Weekly Downloads

      4

      Version

      1.0.5

      License

      ISC

      Unpacked Size

      9.87 kB

      Total Files

      4

      Last publish

      Collaborators

      • chisecc
      • jarvan8888
      • jiasm
      • ryli
      • nieweidong
      • fengcang2020