@anov/cic-standard-sdk 0.0.10 → 0.0.12
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/dist/cic-sdk.cjs.js +7 -7
- package/dist/cic-sdk.es.js +2489 -2396
- package/dist/cic-sdk.umd.js +7 -7
- package/dist/sdk/generators/common.d.ts +64 -19
- package/dist/types/variables.d.ts +10 -12
- package/package.json +1 -1
|
@@ -1,40 +1,85 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 生成器通用工具与类型
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* 原则:
|
|
4
|
+
* 1. 严格模式默认不做隐式容错
|
|
5
|
+
* 2. 仅在 defaults 显式提供时才补齐默认值
|
|
6
|
+
* 3. 校验错误必须可定位、可去重、可排序
|
|
7
|
+
* 4. 校验 discriminated union 类型时,discriminator 字段必须为必填字段
|
|
5
8
|
*/
|
|
6
|
-
|
|
7
|
-
ok:
|
|
9
|
+
type Ok<T> = {
|
|
10
|
+
ok: true;
|
|
8
11
|
value?: T;
|
|
9
|
-
errors?: FormattedError[];
|
|
10
12
|
};
|
|
13
|
+
type Err = {
|
|
14
|
+
ok: false;
|
|
15
|
+
errors: FormattedError[];
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* 校验结果
|
|
19
|
+
* - ok: 校验成功,value 为校验后的值
|
|
20
|
+
* - err: 校验失败,errors 为校验错误列表
|
|
21
|
+
*/
|
|
22
|
+
export type Result<T> = Ok<T> | Err;
|
|
11
23
|
export type CreateOptions<T = any> = {
|
|
12
24
|
defaults?: Partial<T>;
|
|
13
25
|
generateId?: boolean;
|
|
14
26
|
strict?: boolean;
|
|
15
27
|
};
|
|
28
|
+
/**
|
|
29
|
+
* 格式化校验错误
|
|
30
|
+
* - path:错误路径,如 `$.name`
|
|
31
|
+
* - message:错误描述
|
|
32
|
+
* - keyword:校验关键字,如 `required`
|
|
33
|
+
* - params:校验参数,如 `{ missingProperty: 'name' }`
|
|
34
|
+
*/
|
|
16
35
|
export type FormattedError = {
|
|
17
36
|
path: string;
|
|
18
37
|
message: string;
|
|
19
38
|
keyword?: string;
|
|
20
39
|
params?: Record<string, any>;
|
|
21
40
|
};
|
|
22
|
-
/**
|
|
23
|
-
|
|
41
|
+
/**
|
|
42
|
+
* AJV校验器接口
|
|
43
|
+
* - 校验函数:接收未知值,返回是否校验通过
|
|
44
|
+
* - errors:校验失败时的错误列表
|
|
45
|
+
*/
|
|
46
|
+
export interface Validator<T = any> {
|
|
47
|
+
(data: unknown): data is T;
|
|
48
|
+
errors?: any[];
|
|
49
|
+
}
|
|
50
|
+
/** 将值规范为数组(仅接受数组,其它视为缺失) */
|
|
51
|
+
export declare const ensureArray: <T>(v: unknown) => T[];
|
|
24
52
|
/** 判断为有限正数 */
|
|
25
|
-
export declare const isPositive: (n:
|
|
26
|
-
/** 生成
|
|
27
|
-
export declare const uuid: () =>
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
53
|
+
export declare const isPositive: (n: unknown) => n is number;
|
|
54
|
+
/** 生成 UUID */
|
|
55
|
+
export declare const uuid: () => string;
|
|
56
|
+
/**
|
|
57
|
+
* 格式化 AJV 校验错误
|
|
58
|
+
* - 转换为标准格式
|
|
59
|
+
* - 去重
|
|
60
|
+
* - 排序
|
|
61
|
+
*/
|
|
62
|
+
export declare const formatAjvErrors: (errs?: any[]) => FormattedError[];
|
|
63
|
+
/** 仅对缺失字段应用默认值(浅合并) */
|
|
64
|
+
export declare const applyDefaults: <T>(target: any, defaults?: Partial<T>) => T;
|
|
31
65
|
/** 在已格式化错误上追加路径前缀 */
|
|
32
66
|
export declare const prefixErrors: (prefix: string, errors?: FormattedError[]) => FormattedError[];
|
|
33
|
-
/** 安全解析 JSON
|
|
67
|
+
/** 安全解析 JSON 文本 */
|
|
34
68
|
export declare const safeParseJSON: (text: string) => Result<any>;
|
|
35
|
-
/**
|
|
69
|
+
/** 缺失必填字段错误 */
|
|
36
70
|
export declare const missingRequiredErrors: (keys: string[]) => FormattedError[];
|
|
37
|
-
/**
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
71
|
+
/**
|
|
72
|
+
* 校验 discriminated union 类型
|
|
73
|
+
* - 校验 discriminator 字段
|
|
74
|
+
* - 根据 discriminator 调用相应 validator
|
|
75
|
+
* - 格式化 AJV 校验错误
|
|
76
|
+
*/
|
|
77
|
+
export declare const validateDiscriminated: (input: unknown, base: Validator, branches: Record<string, Validator>, key: string) => Result<null>;
|
|
78
|
+
/**
|
|
79
|
+
* 创建 discriminated union 类型
|
|
80
|
+
* - 校验 discriminator 字段
|
|
81
|
+
* - 根据 discriminator 调用相应 validator
|
|
82
|
+
* - 格式化 AJV 校验错误
|
|
83
|
+
*/
|
|
84
|
+
export declare const createDiscriminated: <T>(input: unknown, options: CreateOptions | undefined, normalize: (x: unknown, o?: CreateOptions) => any, base: Validator, branches: Record<string, Validator>, key: string, missingKeys?: string[]) => Result<T>;
|
|
85
|
+
export {};
|
|
@@ -1,47 +1,45 @@
|
|
|
1
1
|
/** 变量类型枚举,限定变量的基础类型:字符串、数字、布尔、数组、对象和函数。 */
|
|
2
2
|
export type VariableType = 'string' | 'number' | 'boolean' | 'array' | 'object' | 'function';
|
|
3
|
+
export interface VariableBase {
|
|
4
|
+
description?: string;
|
|
5
|
+
extensions?: Record<string, unknown>;
|
|
6
|
+
}
|
|
3
7
|
/** 字符串变量,包含当前值与默认值,可选描述。 */
|
|
4
|
-
export interface StringVariable {
|
|
8
|
+
export interface StringVariable extends VariableBase {
|
|
5
9
|
type: 'string';
|
|
6
10
|
value: string;
|
|
7
11
|
default: string;
|
|
8
|
-
description?: string;
|
|
9
12
|
}
|
|
10
13
|
/** 数字变量,包含当前值与默认值,可选描述。 */
|
|
11
|
-
export interface NumberVariable {
|
|
14
|
+
export interface NumberVariable extends VariableBase {
|
|
12
15
|
type: 'number';
|
|
13
16
|
value: number;
|
|
14
17
|
default: number;
|
|
15
|
-
description?: string;
|
|
16
18
|
}
|
|
17
19
|
/** 布尔变量,包含当前值与默认值,可选描述。 */
|
|
18
|
-
export interface BooleanVariable {
|
|
20
|
+
export interface BooleanVariable extends VariableBase {
|
|
19
21
|
type: 'boolean';
|
|
20
22
|
value: boolean;
|
|
21
23
|
default: boolean;
|
|
22
|
-
description?: string;
|
|
23
24
|
}
|
|
24
25
|
/** 数组变量,元素类型不做限制,包含当前值与默认值,可选描述。 */
|
|
25
|
-
export interface ArrayVariable {
|
|
26
|
+
export interface ArrayVariable extends VariableBase {
|
|
26
27
|
type: 'array';
|
|
27
28
|
value: unknown[];
|
|
28
29
|
default: unknown[];
|
|
29
|
-
description?: string;
|
|
30
30
|
}
|
|
31
31
|
/** 函数变量,以字符串保存函数实现;支持 `args` 指定入参名列表。 */
|
|
32
|
-
export interface FunctionVariable {
|
|
32
|
+
export interface FunctionVariable extends VariableBase {
|
|
33
33
|
type: 'function';
|
|
34
34
|
value: string;
|
|
35
35
|
default: string;
|
|
36
|
-
description?: string;
|
|
37
36
|
args?: string[];
|
|
38
37
|
}
|
|
39
38
|
/** 对象变量,键到变量的映射;支持递归嵌套。 */
|
|
40
|
-
export interface ObjectVariable {
|
|
39
|
+
export interface ObjectVariable extends VariableBase {
|
|
41
40
|
type: 'object';
|
|
42
41
|
value: Record<string, Variable>;
|
|
43
42
|
default: Record<string, Variable>;
|
|
44
|
-
description?: string;
|
|
45
43
|
}
|
|
46
44
|
/** 变量联合类型,涵盖五类变量定义。 */
|
|
47
45
|
export type Variable = StringVariable | NumberVariable | BooleanVariable | ArrayVariable | FunctionVariable | ObjectVariable;
|