@arms/rum-core 0.0.39 → 0.1.1
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.
- package/es/index.d.ts +3 -0
- package/es/index.js +3 -0
- package/es/model/client.d.ts +2 -1
- package/es/model/client.js +2 -2
- package/es/model/configManager.d.ts +58 -0
- package/es/model/configManager.js +177 -0
- package/es/model/context.d.ts +3 -1
- package/es/model/context.js +13 -2
- package/es/model/reporter.d.ts +2 -4
- package/es/model/reporter.js +53 -11
- package/es/model/shell.d.ts +1 -15
- package/es/model/shell.js +62 -52
- package/es/types/client.d.ts +60 -8
- package/es/types/client.js +6 -1
- package/es/types/config.d.ts +49 -0
- package/es/types/config.js +1 -0
- package/es/types/rum-event.d.ts +2 -0
- package/es/utils/base.d.ts +4 -4
- package/es/utils/base.js +70 -42
- package/es/utils/combineConfig.js +89 -101
- package/es/utils/match.d.ts +6 -0
- package/es/utils/match.js +34 -0
- package/es/utils/trace.d.ts +5 -1
- package/es/utils/url.d.ts +2 -0
- package/es/utils/url.js +61 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +21 -0
- package/lib/model/client.d.ts +2 -1
- package/lib/model/client.js +2 -2
- package/lib/model/configManager.d.ts +58 -0
- package/lib/model/configManager.js +182 -0
- package/lib/model/context.d.ts +3 -1
- package/lib/model/context.js +13 -2
- package/lib/model/reporter.d.ts +2 -4
- package/lib/model/reporter.js +54 -11
- package/lib/model/shell.d.ts +1 -15
- package/lib/model/shell.js +61 -53
- package/lib/types/client.d.ts +60 -8
- package/lib/types/client.js +5 -1
- package/lib/types/config.d.ts +49 -0
- package/lib/types/config.js +3 -0
- package/lib/types/rum-event.d.ts +2 -0
- package/lib/utils/base.d.ts +4 -4
- package/lib/utils/base.js +71 -43
- package/lib/utils/combineConfig.js +90 -107
- package/lib/utils/match.d.ts +6 -0
- package/lib/utils/match.js +35 -0
- package/lib/utils/trace.d.ts +5 -1
- package/lib/utils/url.d.ts +2 -0
- package/lib/utils/url.js +65 -0
- package/package.json +2 -2
- package/es/utils/combineConfig.d.ts +0 -15
- package/lib/utils/combineConfig.d.ts +0 -15
package/es/types/client.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { IProcessor } from './processor';
|
|
|
3
3
|
import { IReporter } from './reporter';
|
|
4
4
|
import { RumEvent, RumEventBundle, IViewData } from './rum-event';
|
|
5
5
|
import { MatchOption } from "../utils/match";
|
|
6
|
+
import { IConfigManager } from "./config";
|
|
6
7
|
export declare enum EventType {
|
|
7
8
|
/**
|
|
8
9
|
* 收集数据
|
|
@@ -35,6 +36,12 @@ export interface SessionConfig {
|
|
|
35
36
|
overtime?: number;
|
|
36
37
|
storage?: string;
|
|
37
38
|
}
|
|
39
|
+
export interface IReportConfig {
|
|
40
|
+
flushTime?: number;
|
|
41
|
+
maxEventCount?: number;
|
|
42
|
+
maxRetryCount?: number;
|
|
43
|
+
retryDelay?: number;
|
|
44
|
+
}
|
|
38
45
|
export interface IRumSession {
|
|
39
46
|
init(ctx: IContext): void;
|
|
40
47
|
sessionConfig: SessionConfig;
|
|
@@ -46,11 +53,54 @@ export interface IRumSession {
|
|
|
46
53
|
getUserId: () => string;
|
|
47
54
|
getBaseEvent: () => any;
|
|
48
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* 远端监控配置接口
|
|
58
|
+
* @remarks 用于控制RUM数据采集的远程配置策略
|
|
59
|
+
*/
|
|
60
|
+
export interface IRemoteConfig {
|
|
61
|
+
/**
|
|
62
|
+
* 是否启用远端配置 (default: false)
|
|
63
|
+
* @example true - 开启云端配置动态管控
|
|
64
|
+
*/
|
|
65
|
+
enable?: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* 配置服务器URL (required when enable=true)
|
|
68
|
+
* @format URL
|
|
69
|
+
*/
|
|
70
|
+
url?: string;
|
|
71
|
+
/**
|
|
72
|
+
* 配置获取策略模式 (default: 'launch-first')
|
|
73
|
+
* @enum
|
|
74
|
+
* - 'launch-first': 启动优先模式,先使用本地配置快速启动,异步获取最新配置
|
|
75
|
+
* - 'remote-first': 云端优先模式,阻塞等待云端配置,超时后降级到本地
|
|
76
|
+
*/
|
|
77
|
+
mode?: 'launch-first' | 'remote-first';
|
|
78
|
+
/**
|
|
79
|
+
* 配置缓存有效期(单位:毫秒,默认:3600000/1小时)
|
|
80
|
+
* @remarks 控制本地配置缓存刷新频率,超时后重新请求云端配置
|
|
81
|
+
* @example 1800000 - 30分钟更新一次配置
|
|
82
|
+
*/
|
|
83
|
+
cacheTimeout?: number;
|
|
84
|
+
/**
|
|
85
|
+
* 配置远程配置拉取Region,兼容 0.0.x 版本远端配置
|
|
86
|
+
* @remarks 拉取远端配置地域
|
|
87
|
+
* @example cn-hangzhou 国内主要地区
|
|
88
|
+
*/
|
|
89
|
+
region?: string;
|
|
90
|
+
[key: string]: unknown;
|
|
91
|
+
}
|
|
92
|
+
export interface ICollectorConfig {
|
|
93
|
+
name: string;
|
|
94
|
+
enable?: boolean;
|
|
95
|
+
sampling?: number;
|
|
96
|
+
filters?: MatchOption[];
|
|
97
|
+
[key: string]: unknown;
|
|
98
|
+
}
|
|
49
99
|
export interface IClient {
|
|
50
100
|
/**
|
|
51
101
|
* 初始化
|
|
52
102
|
*/
|
|
53
|
-
init: (configuration: IConfiguration, rumSession?: IRumSession) => void;
|
|
103
|
+
init: (configuration: IConfiguration, rumSession?: IRumSession, configManager?: IConfigManager) => void;
|
|
54
104
|
/**
|
|
55
105
|
* 业务自定义上传数据
|
|
56
106
|
*/
|
|
@@ -81,10 +131,15 @@ export interface IClient {
|
|
|
81
131
|
useReporter(reporter: IReporter): void;
|
|
82
132
|
}
|
|
83
133
|
export interface IConfiguration {
|
|
134
|
+
/**
|
|
135
|
+
* 是否开启SDK
|
|
136
|
+
*/
|
|
137
|
+
enable?: boolean;
|
|
84
138
|
/**
|
|
85
139
|
* 项目 id
|
|
140
|
+
* v0.0.40开始,不强依赖该参数,通过Endpoint获取 service_id 确定应用
|
|
86
141
|
*/
|
|
87
|
-
pid
|
|
142
|
+
pid?: string;
|
|
88
143
|
/**
|
|
89
144
|
* 应用环境
|
|
90
145
|
*/
|
|
@@ -125,15 +180,12 @@ export interface IConfiguration {
|
|
|
125
180
|
/**
|
|
126
181
|
* reporter 发送节奏配置
|
|
127
182
|
*/
|
|
128
|
-
reportConfig?:
|
|
129
|
-
flushTime?: number;
|
|
130
|
-
maxEventCount?: number;
|
|
131
|
-
};
|
|
183
|
+
reportConfig?: IReportConfig;
|
|
132
184
|
/**
|
|
133
185
|
* 配置下发
|
|
134
186
|
* - 运行时动态配置更新,根据端侧特点来做定制化配置
|
|
135
187
|
*/
|
|
136
|
-
remoteConfig?: Boolean;
|
|
188
|
+
remoteConfig?: IRemoteConfig | Boolean;
|
|
137
189
|
/**
|
|
138
190
|
* session config
|
|
139
191
|
*/
|
|
@@ -142,7 +194,7 @@ export interface IConfiguration {
|
|
|
142
194
|
* 各个 collector config
|
|
143
195
|
*/
|
|
144
196
|
collectors?: {
|
|
145
|
-
[key: string]: boolean;
|
|
197
|
+
[key: string]: boolean | ICollectorConfig;
|
|
146
198
|
};
|
|
147
199
|
/**
|
|
148
200
|
* 事件过滤器配置
|
package/es/types/client.js
CHANGED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { IConfiguration } from './client';
|
|
2
|
+
export interface ICacheConfiguration {
|
|
3
|
+
/**
|
|
4
|
+
* 时间戳
|
|
5
|
+
*/
|
|
6
|
+
timestamp: number;
|
|
7
|
+
/**
|
|
8
|
+
* 内容
|
|
9
|
+
*/
|
|
10
|
+
content: any;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* 配置管理器接口
|
|
14
|
+
* 统一管理配置的获取、存储、合并等操作
|
|
15
|
+
*/
|
|
16
|
+
export interface IConfigManager {
|
|
17
|
+
/**
|
|
18
|
+
* 初始化配置管理器
|
|
19
|
+
* @param config 初始配置
|
|
20
|
+
*/
|
|
21
|
+
init(config: IConfiguration): Promise<void> | void;
|
|
22
|
+
/**
|
|
23
|
+
* 获取配置
|
|
24
|
+
* @returns 配置数据
|
|
25
|
+
*/
|
|
26
|
+
getConfig(): Promise<IConfiguration> | any;
|
|
27
|
+
/**
|
|
28
|
+
* 更新配置
|
|
29
|
+
* @param config 新配置
|
|
30
|
+
*/
|
|
31
|
+
setConfig(config: Partial<IConfiguration>): Promise<void> | void;
|
|
32
|
+
/**
|
|
33
|
+
* 抽象方法:获取远程配置
|
|
34
|
+
* 各平台需要实现此方法来适配不同的网络请求方式
|
|
35
|
+
* @param config 当前配置
|
|
36
|
+
*/
|
|
37
|
+
fetchRemoteCfg(config: IConfiguration): Promise<any>;
|
|
38
|
+
/**
|
|
39
|
+
* 合并配置
|
|
40
|
+
* @param baseConfig 基础配置
|
|
41
|
+
* @param remoteConfig 远程配置
|
|
42
|
+
* @returns 合并后的配置
|
|
43
|
+
*/
|
|
44
|
+
mergeRemoteCfg(baseConfig: IConfiguration, remoteConfig: any): IConfiguration | null;
|
|
45
|
+
/**
|
|
46
|
+
* 销毁配置管理器
|
|
47
|
+
*/
|
|
48
|
+
destroy(): void;
|
|
49
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/es/types/rum-event.d.ts
CHANGED
package/es/utils/base.d.ts
CHANGED
|
@@ -53,8 +53,8 @@ export declare function getType(obj: any): any;
|
|
|
53
53
|
*/
|
|
54
54
|
export declare function transStrToReg(str: string): string | RegExp;
|
|
55
55
|
/**
|
|
56
|
-
*
|
|
57
|
-
* @param
|
|
58
|
-
* @
|
|
56
|
+
* 解析正则表达式字符串,支持 /pattern/flags 格式
|
|
57
|
+
* @param str 正则表达式字符串,如 "/a/ig" 或 "a"
|
|
58
|
+
* @returns RegExp 对象
|
|
59
59
|
*/
|
|
60
|
-
export declare function
|
|
60
|
+
export declare function parseRegExpString(str: string): RegExp;
|
package/es/utils/base.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { isFunction } from "./is";
|
|
2
2
|
|
|
3
|
-
// 插值前缀
|
|
4
|
-
var PRE_SUF_FIX = '__';
|
|
5
3
|
// 类型匹配正则
|
|
6
4
|
var TYPE_REG = /^\[object ([a-z]*)\]$/;
|
|
7
5
|
|
|
@@ -13,8 +11,7 @@ export function interceptFunction(target, name, callback, isPrototype) {
|
|
|
13
11
|
isPrototype = false;
|
|
14
12
|
}
|
|
15
13
|
var registeredMethod = target[name];
|
|
16
|
-
|
|
17
|
-
target[name] = function () {
|
|
14
|
+
var proxyMethod = function proxyMethod() {
|
|
18
15
|
var ctx = isPrototype ? this : target;
|
|
19
16
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
20
17
|
args[_key] = arguments[_key];
|
|
@@ -24,17 +21,19 @@ export function interceptFunction(target, name, callback, isPrototype) {
|
|
|
24
21
|
return registeredMethod.apply(ctx, args);
|
|
25
22
|
}
|
|
26
23
|
};
|
|
24
|
+
proxyMethod._rum_intercepted = registeredMethod;
|
|
25
|
+
target[name] = proxyMethod;
|
|
27
26
|
}
|
|
28
27
|
|
|
29
28
|
/**
|
|
30
29
|
* 还原函数
|
|
31
30
|
*/
|
|
32
31
|
export function restoreFunction(target, name) {
|
|
33
|
-
var
|
|
34
|
-
if (
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
var proxyMethod = target[name];
|
|
33
|
+
if (isFunction(proxyMethod)) return;
|
|
34
|
+
var originalMethod = proxyMethod._rum_intercepted;
|
|
35
|
+
if (isFunction(originalMethod)) return;
|
|
36
|
+
target[name] = originalMethod;
|
|
38
37
|
}
|
|
39
38
|
|
|
40
39
|
/**
|
|
@@ -175,42 +174,71 @@ export function transStrToReg(str) {
|
|
|
175
174
|
return str;
|
|
176
175
|
}
|
|
177
176
|
|
|
177
|
+
// /**
|
|
178
|
+
// *
|
|
179
|
+
// * @param config 配置
|
|
180
|
+
// * @param keys 需要转换的字段
|
|
181
|
+
// */
|
|
182
|
+
// export function toRegFormat(config: any, keys: any[]) {
|
|
183
|
+
// if (getType(keys) === 'string') {
|
|
184
|
+
// keys = [keys];
|
|
185
|
+
// }
|
|
186
|
+
// for (let i = 0, len = keys.length; i < len; i++) {
|
|
187
|
+
// const paths = keys[i].split('.');
|
|
188
|
+
// const lastIndex = paths.length - 1;
|
|
189
|
+
// if (!config) break;
|
|
190
|
+
// let tmp = config;
|
|
191
|
+
// for (let j = 0, jlen = paths.length; j < jlen; j++) {
|
|
192
|
+
// if (paths[j] === '[]') {
|
|
193
|
+
// if (getType(tmp) === 'array') {
|
|
194
|
+
// let lastPath = paths.splice(j + 1);
|
|
195
|
+
// lastPath = lastPath.join('.');
|
|
196
|
+
// for (let x = 0, xlen = tmp.length; x < xlen; x++) {
|
|
197
|
+
// toRegFormat(tmp[x], lastPath);
|
|
198
|
+
// }
|
|
199
|
+
// }
|
|
200
|
+
// break;
|
|
201
|
+
// }
|
|
202
|
+
// // 最后一层了,需要往前一层才能修改对象
|
|
203
|
+
// if (lastIndex === j && getType(tmp[paths[j]]) === 'string') {
|
|
204
|
+
// tmp[paths[j]] = transStrToReg(tmp[paths[j]]);
|
|
205
|
+
// break;
|
|
206
|
+
// }
|
|
207
|
+
// tmp = tmp[paths[j]];
|
|
208
|
+
// if (!tmp) break;
|
|
209
|
+
// }
|
|
210
|
+
// if (!tmp || getType(tmp) !== 'array') continue;
|
|
211
|
+
// for (let j = 0, jlen = tmp.length; j < jlen; j++) {
|
|
212
|
+
// tmp[j] = transStrToReg(tmp[j]);
|
|
213
|
+
// }
|
|
214
|
+
// }
|
|
215
|
+
// }
|
|
216
|
+
|
|
178
217
|
/**
|
|
179
|
-
*
|
|
180
|
-
* @param
|
|
181
|
-
* @
|
|
218
|
+
* 解析正则表达式字符串,支持 /pattern/flags 格式
|
|
219
|
+
* @param str 正则表达式字符串,如 "/a/ig" 或 "a"
|
|
220
|
+
* @returns RegExp 对象
|
|
182
221
|
*/
|
|
183
|
-
export function
|
|
184
|
-
if (
|
|
185
|
-
|
|
222
|
+
export function parseRegExpString(str) {
|
|
223
|
+
if (typeof str !== 'string') {
|
|
224
|
+
throw new TypeError('input must be a string');
|
|
186
225
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
var
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
toRegFormat(tmp[x], lastPath);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
break;
|
|
202
|
-
}
|
|
203
|
-
// 最后一层了,需要往前一层才能修改对象
|
|
204
|
-
if (lastIndex === j && getType(tmp[paths[j]]) === 'string') {
|
|
205
|
-
tmp[paths[j]] = transStrToReg(tmp[paths[j]]);
|
|
206
|
-
break;
|
|
207
|
-
}
|
|
208
|
-
tmp = tmp[paths[j]];
|
|
209
|
-
if (!tmp) break;
|
|
210
|
-
}
|
|
211
|
-
if (!tmp || getType(tmp) !== 'array') continue;
|
|
212
|
-
for (var _j = 0, _jlen = tmp.length; _j < _jlen; _j++) {
|
|
213
|
-
tmp[_j] = transStrToReg(tmp[_j]);
|
|
226
|
+
|
|
227
|
+
// 检查是否是 /pattern/flags 格式
|
|
228
|
+
if (str.length > 2 && str[0] === '/') {
|
|
229
|
+
// 从后往前找最后一个 /,作为分隔符
|
|
230
|
+
var lastSlashIndex = str.lastIndexOf('/');
|
|
231
|
+
if (lastSlashIndex > 0) {
|
|
232
|
+
// 提取 pattern(第一个 / 和最后一个 / 之间的内容)
|
|
233
|
+
var pattern = str.substring(1, lastSlashIndex);
|
|
234
|
+
// 提取 flags(最后一个 / 之后的内容)
|
|
235
|
+
var flags = str.substring(lastSlashIndex + 1);
|
|
236
|
+
return new RegExp(pattern, flags);
|
|
214
237
|
}
|
|
238
|
+
// 如果只有一个 /,当作 /pattern/ 格式处理(无 flags)
|
|
239
|
+
return new RegExp(str.substring(1, str.length - 1));
|
|
215
240
|
}
|
|
241
|
+
|
|
242
|
+
// 如果不是 /pattern/flags 格式,直接作为 pattern 使用
|
|
243
|
+
return new RegExp(str);
|
|
216
244
|
}
|
|
@@ -1,101 +1,89 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
// 需要检查是否需要字符串格式化为正则的配置路径
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
if (!remoteConfig) return null;
|
|
91
|
-
if (getType(oldConfig) !== 'object' || getType(remoteConfig) !== 'object') return null;
|
|
92
|
-
var config = _extends({}, oldConfig);
|
|
93
|
-
// 先检查远程配置的,是否有需要将字符串格式化为正则的
|
|
94
|
-
toRegFormat(remoteConfig, REG_FORMAT_PATHS);
|
|
95
|
-
// 执行覆盖
|
|
96
|
-
doCover(config, remoteConfig);
|
|
97
|
-
// 执行补充
|
|
98
|
-
doSupplement(config, remoteConfig);
|
|
99
|
-
return config;
|
|
100
|
-
}
|
|
101
|
-
export default combineConfig;
|
|
1
|
+
// import{ getType, toRegFormat} from './base';
|
|
2
|
+
//
|
|
3
|
+
//
|
|
4
|
+
// // 需要检查是否需要字符串格式化为正则的配置路径
|
|
5
|
+
// const REG_FORMAT_PATHS = [
|
|
6
|
+
// 'filters.exception',
|
|
7
|
+
// 'filters.resource',
|
|
8
|
+
// 'tracing.allowedUrls.[].match'
|
|
9
|
+
// ];
|
|
10
|
+
//
|
|
11
|
+
// export function isRemoteConfigEnable(config: any) {
|
|
12
|
+
// return config.remoteConfig === true ||
|
|
13
|
+
// (config.remoteConfig && config.remoteConfig.enable !== false);
|
|
14
|
+
// }
|
|
15
|
+
//
|
|
16
|
+
// /**
|
|
17
|
+
// *
|
|
18
|
+
// * @param config
|
|
19
|
+
// * @returns
|
|
20
|
+
// */
|
|
21
|
+
// export function getRemoteConfigUrl(config: any){
|
|
22
|
+
// if(config.remoteConfig && config.remoteConfig.url) {
|
|
23
|
+
// return config.remoteConfig.url;
|
|
24
|
+
// }
|
|
25
|
+
// const sereis = config.pid.split('@');
|
|
26
|
+
// if(!sereis || sereis.length<2) return;
|
|
27
|
+
// const timestamp = Date.now();
|
|
28
|
+
// return `//${sereis[0]}-sdk.rum.aliyuncs.com/config/${config.remoteConfig.region || 'cn-hangzhou'}/${sereis[1]}?t=${timestamp}`;
|
|
29
|
+
// }
|
|
30
|
+
//
|
|
31
|
+
// /**
|
|
32
|
+
// *
|
|
33
|
+
// * @param oldConfig
|
|
34
|
+
// * @param remoteConfig
|
|
35
|
+
// */
|
|
36
|
+
// function doCover(oldConfig: any ={}, remoteConfig: any ={}){
|
|
37
|
+
// for(const key in oldConfig) {
|
|
38
|
+
// if(key === 'pid' || key === 'endpoint') continue;
|
|
39
|
+
// if(remoteConfig?.[key] === undefined) continue;
|
|
40
|
+
// const oldV = oldConfig[key];
|
|
41
|
+
// const newV = remoteConfig?.[key];
|
|
42
|
+
// if(getType(oldV) === 'object' && getType(newV) === 'object') {
|
|
43
|
+
// doCover(oldV, newV);
|
|
44
|
+
// } else {
|
|
45
|
+
// oldConfig[key] = newV;
|
|
46
|
+
// }
|
|
47
|
+
// }
|
|
48
|
+
// }
|
|
49
|
+
//
|
|
50
|
+
// /**
|
|
51
|
+
// *
|
|
52
|
+
// * @param oldConfig
|
|
53
|
+
// * @param remoteConfig
|
|
54
|
+
// */
|
|
55
|
+
// function doSupplement(oldConfig: any ={}, remoteConfig: any ={}) {
|
|
56
|
+
// for(const key in remoteConfig) {
|
|
57
|
+
// if(oldConfig?.[key] === undefined) {
|
|
58
|
+
// oldConfig[key] = remoteConfig[key];
|
|
59
|
+
// } else {
|
|
60
|
+
// const oldV = oldConfig[key];
|
|
61
|
+
// const newV = remoteConfig[key];
|
|
62
|
+
// if(getType(oldV) === 'object' && getType(newV) === 'object') {
|
|
63
|
+
// doSupplement(oldV, newV);
|
|
64
|
+
// }
|
|
65
|
+
// }
|
|
66
|
+
// }
|
|
67
|
+
// }
|
|
68
|
+
//
|
|
69
|
+
// /**
|
|
70
|
+
// *
|
|
71
|
+
// * @param oldConfig
|
|
72
|
+
// * @param remoteConfig
|
|
73
|
+
// * @returns config
|
|
74
|
+
// */
|
|
75
|
+
// function combineConfig(oldConfig={}, remoteConfig=null) {
|
|
76
|
+
// if(!remoteConfig) return null;
|
|
77
|
+
// if(getType(oldConfig) !== 'object' || getType(remoteConfig) !== 'object') return null;
|
|
78
|
+
// const config = {...oldConfig};
|
|
79
|
+
// // 先检查远程配置的,是否有需要将字符串格式化为正则的
|
|
80
|
+
// toRegFormat(remoteConfig, REG_FORMAT_PATHS);
|
|
81
|
+
// // 执行覆盖
|
|
82
|
+
// doCover(config, remoteConfig);
|
|
83
|
+
// // 执行补充
|
|
84
|
+
// doSupplement(config, remoteConfig);
|
|
85
|
+
// return config;
|
|
86
|
+
// }
|
|
87
|
+
//
|
|
88
|
+
//
|
|
89
|
+
// export default combineConfig;
|
package/es/utils/match.d.ts
CHANGED
|
@@ -5,3 +5,9 @@ export declare function isMatchOption(item: unknown): item is MatchOption;
|
|
|
5
5
|
*/
|
|
6
6
|
export declare function matchList(list: MatchOption[], value: string, useStartsWith?: boolean, options?: unknown): boolean;
|
|
7
7
|
export declare function urlMatch(url: string, list?: MatchOption | MatchOption[]): boolean;
|
|
8
|
+
export interface IRule {
|
|
9
|
+
match: string;
|
|
10
|
+
match_exp: string;
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
}
|
|
13
|
+
export declare function parseRule2Match(rule: IRule | MatchOption): MatchOption;
|
package/es/utils/match.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { isArray, isFunction, isRegExp, isString } from "./is";
|
|
2
2
|
import { startsWith } from "./polyfills";
|
|
3
|
+
import { parseRegExpString } from "./base";
|
|
3
4
|
export function isMatchOption(item) {
|
|
4
5
|
return isString(item) || isFunction(item) || isRegExp(item);
|
|
5
6
|
}
|
|
@@ -37,4 +38,37 @@ export function urlMatch(url, list) {
|
|
|
37
38
|
} catch (e) {
|
|
38
39
|
return false;
|
|
39
40
|
}
|
|
41
|
+
}
|
|
42
|
+
export function parseRule2Match(rule) {
|
|
43
|
+
if (isMatchOption(rule)) {
|
|
44
|
+
return rule;
|
|
45
|
+
}
|
|
46
|
+
var match;
|
|
47
|
+
switch (rule.match_exp) {
|
|
48
|
+
case 'equals':
|
|
49
|
+
match = function match(value) {
|
|
50
|
+
return value === rule.match;
|
|
51
|
+
};
|
|
52
|
+
break;
|
|
53
|
+
case 'not_equals':
|
|
54
|
+
match = function match(value) {
|
|
55
|
+
return value !== rule.match;
|
|
56
|
+
};
|
|
57
|
+
break;
|
|
58
|
+
case 'regex':
|
|
59
|
+
match = parseRegExpString(rule.match);
|
|
60
|
+
break;
|
|
61
|
+
case 'includes':
|
|
62
|
+
match = function match(value) {
|
|
63
|
+
return value.includes(rule.match);
|
|
64
|
+
};
|
|
65
|
+
break;
|
|
66
|
+
case 'starts_with':
|
|
67
|
+
default:
|
|
68
|
+
match = function match(value) {
|
|
69
|
+
return startsWith(value, rule.match);
|
|
70
|
+
};
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
return match;
|
|
40
74
|
}
|
package/es/utils/trace.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { MatchOption } from "./match";
|
|
2
2
|
export type PropagatorType = 'tracecontext' | 'b3' | 'b3multi' | 'jaeger' | 'sw8';
|
|
3
3
|
export type TraceOption = {
|
|
4
|
+
enable?: boolean;
|
|
5
|
+
sampling?: number;
|
|
4
6
|
match: MatchOption;
|
|
5
|
-
propagatorTypes
|
|
7
|
+
propagatorTypes?: PropagatorType[];
|
|
8
|
+
baggage?: boolean;
|
|
9
|
+
tracestate?: boolean;
|
|
6
10
|
};
|
|
7
11
|
export declare function isTraceOption(option: any): option is TraceOption;
|
|
8
12
|
export interface ITracingOption {
|