@be-link/shield-for-tcb-node-sdk 1.0.4 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -40,18 +40,18 @@ export declare class ConfigServiceV2 extends BaseService implements ServiceV2.Co
|
|
|
40
40
|
*/
|
|
41
41
|
getConfigValue<T = any>(service: string, key: string, env?: string): Promise<T | null>;
|
|
42
42
|
/**
|
|
43
|
-
*
|
|
43
|
+
* 批量获取配置值
|
|
44
44
|
* @param service 服务名称
|
|
45
45
|
* @param keys 配置键列表(可选,不传则获取该服务所有配置)
|
|
46
46
|
* @param env 环境(可选)
|
|
47
|
-
* @returns
|
|
47
|
+
* @returns 配置值映射(服务端已自动解析类型)
|
|
48
48
|
*/
|
|
49
49
|
getConfigValues<T = any>(service: string, keys?: string[], env?: string): Promise<Record<string, T>>;
|
|
50
50
|
/**
|
|
51
51
|
* 获取指定服务的所有配置
|
|
52
52
|
* @param service 服务名称
|
|
53
53
|
* @param env 环境(可选)
|
|
54
|
-
* @returns
|
|
54
|
+
* @returns 该服务所有配置(Map<config_key, parsed_value> 格式)
|
|
55
55
|
*/
|
|
56
56
|
fetchAllConfigs<T = any>(service: string, env?: string): Promise<Record<string, T>>;
|
|
57
57
|
}
|
|
@@ -83,46 +83,23 @@ class ConfigServiceV2 extends BaseService_1.default {
|
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
/**
|
|
86
|
-
*
|
|
86
|
+
* 批量获取配置值
|
|
87
87
|
* @param service 服务名称
|
|
88
88
|
* @param keys 配置键列表(可选,不传则获取该服务所有配置)
|
|
89
89
|
* @param env 环境(可选)
|
|
90
|
-
* @returns
|
|
90
|
+
* @returns 配置值映射(服务端已自动解析类型)
|
|
91
91
|
*/
|
|
92
92
|
async getConfigValues(service, keys, env) {
|
|
93
|
-
|
|
94
|
-
const parsed = {};
|
|
95
|
-
for (const [key, item] of Object.entries(result)) {
|
|
96
|
-
switch (item.value_type) {
|
|
97
|
-
case 'number':
|
|
98
|
-
parsed[key] = Number(item.value);
|
|
99
|
-
break;
|
|
100
|
-
case 'boolean':
|
|
101
|
-
parsed[key] = (item.value === 'true' || item.value === '1');
|
|
102
|
-
break;
|
|
103
|
-
case 'object':
|
|
104
|
-
case 'array':
|
|
105
|
-
try {
|
|
106
|
-
parsed[key] = JSON.parse(item.value);
|
|
107
|
-
}
|
|
108
|
-
catch {
|
|
109
|
-
parsed[key] = item.value;
|
|
110
|
-
}
|
|
111
|
-
break;
|
|
112
|
-
default:
|
|
113
|
-
parsed[key] = item.value;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
return parsed;
|
|
93
|
+
return this.fetchConfigs({ service, keys, env });
|
|
117
94
|
}
|
|
118
95
|
/**
|
|
119
96
|
* 获取指定服务的所有配置
|
|
120
97
|
* @param service 服务名称
|
|
121
98
|
* @param env 环境(可选)
|
|
122
|
-
* @returns
|
|
99
|
+
* @returns 该服务所有配置(Map<config_key, parsed_value> 格式)
|
|
123
100
|
*/
|
|
124
101
|
async fetchAllConfigs(service, env) {
|
|
125
|
-
return this.
|
|
102
|
+
return this.fetchConfigs({ service, env });
|
|
126
103
|
}
|
|
127
104
|
}
|
|
128
105
|
exports.ConfigServiceV2 = ConfigServiceV2;
|
|
@@ -60,13 +60,10 @@ export declare namespace ServiceV2 {
|
|
|
60
60
|
}
|
|
61
61
|
/**
|
|
62
62
|
* 批量获取配置响应
|
|
63
|
+
* 返回 Map<config_key, parsed_value> 格式
|
|
64
|
+
* value 会自动解析:JSON 对象/数组会解析,其他返回原始字符串
|
|
63
65
|
*/
|
|
64
|
-
|
|
65
|
-
[key: string]: {
|
|
66
|
-
value: string;
|
|
67
|
-
value_type: 'string' | 'number' | 'boolean' | 'object' | 'array';
|
|
68
|
-
};
|
|
69
|
-
}
|
|
66
|
+
type FetchConfigsResponse = Record<string, any>;
|
|
70
67
|
/**
|
|
71
68
|
* 获取服务列表响应
|
|
72
69
|
*/
|