@formvk/schema 0.0.0-stage → 0.1.0
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/index.d.ts +778 -0
- package/dist/index.js +1034 -0
- package/dist/index.js.map +1 -0
- package/package.json +23 -3
- package/src/__tests__/compiler.spec.ts +334 -0
- package/src/__tests__/create-schema.spec.ts +83 -0
- package/src/__tests__/expression.spec.ts +174 -0
- package/src/__tests__/fragment-types.spec.ts +576 -0
- package/src/__tests__/fragment.spec.ts +380 -0
- package/src/__tests__/schema.spec.ts +325 -0
- package/src/__tests__/server-validate.spec.ts +135 -0
- package/src/__tests__/shared.spec.ts +28 -0
- package/src/__tests__/transformer.spec.ts +531 -0
- package/src/__tests__/traverse.spec.ts +77 -0
- package/src/compiler.ts +123 -0
- package/src/create-schema.ts +42 -0
- package/src/expression.ts +355 -0
- package/src/fragment-types.ts +497 -0
- package/src/fragment.ts +229 -0
- package/src/index.ts +6 -0
- package/src/patches.ts +22 -0
- package/src/schema.ts +307 -0
- package/src/shared.ts +226 -0
- package/src/transformer.ts +251 -0
- package/src/types.ts +295 -0
- package/tsconfig.build.json +9 -0
- package/tsconfig.json +4 -0
- package/vite.config.ts +19 -0
- package/README.md +0 -3
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,778 @@
|
|
|
1
|
+
import { ArrayField } from '@formvk/core';
|
|
2
|
+
import { autorun } from '@formvk/reactive';
|
|
3
|
+
import { Field } from '@formvk/core';
|
|
4
|
+
import { FieldValidator } from '@formvk/core';
|
|
5
|
+
import { Form } from '@formvk/core';
|
|
6
|
+
import { FormPathPattern } from '@formvk/core';
|
|
7
|
+
import { GeneralField } from '@formvk/core';
|
|
8
|
+
import { IFieldFactoryProps } from '@formvk/core';
|
|
9
|
+
import { IGeneralFieldState } from '@formvk/core';
|
|
10
|
+
import { ObjectField } from '@formvk/core';
|
|
11
|
+
import { VoidField } from '@formvk/core';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 组件入参通用形态:分类 map 中已声明的组件名 | 任意字符串组件名 | 组件引用(函数或对象组件)。
|
|
15
|
+
* field / void / array 组件与 decorator 的取值约束共用本类型,分类语义由传入的 F / V / A map 承载。
|
|
16
|
+
* 注意:object 成员不校验组件具体形状(跨 Vue 选项式 / 函数组件的宽松约束),非组件对象也能通过类型检查,
|
|
17
|
+
* 其合法性最终交给渲染层 h() 兜底。
|
|
18
|
+
*/
|
|
19
|
+
export declare type AnyComponent<Map extends FragmentPropsMap> = ComponentName<Map> | (string & {}) | ((...args: any[]) => any) | object;
|
|
20
|
+
|
|
21
|
+
export declare type Args = '$args' | '$event' | ExpressionFnOptions | (string & {});
|
|
22
|
+
|
|
23
|
+
export declare interface ArrayFragment<A extends FragmentPropsMap, V extends FragmentPropsMap, Scope extends object = {}, DefaultDecorator extends AnyComponent<V> = ComponentName<V>> {
|
|
24
|
+
/**
|
|
25
|
+
* 无泛型调用:从 items creator 推断数组项类型。
|
|
26
|
+
* 约束限定为 creator,避免显式泛型调用(第一个泛型是 Item 类型)误选本 overload。
|
|
27
|
+
*/
|
|
28
|
+
<Items extends SchemaCreator<any>, Component extends AnyComponent<A> = ComponentName<A>, Decorator extends AnyComponent<V> = DefaultDecorator>(items: Items, schema?: ArraySchema<A, V, Component, Decorator, SchemaCreatorValue<Items>[], TRecordOfItem<SchemaCreatorValue<Items>>, Scope>): SchemaCreator<SchemaCreatorValue<Items>[], any, SchemaCreatorValue<Items>, SchemaCreatorValue<Items>[]>;
|
|
29
|
+
/**
|
|
30
|
+
* 显式声明数组项类型与字段级 Scope:
|
|
31
|
+
* - items 中的子级 creator 值类型收敛为 Item
|
|
32
|
+
* - 子级未显式声明 Scope 时继承 FieldScope
|
|
33
|
+
* 数组自身位于父级容器中,`$record` 无法从 items 推断,默认 any,可通过第三个泛型显式声明。
|
|
34
|
+
*/
|
|
35
|
+
<Item = any, FieldScope extends object = Scope, Record extends object = any, Component extends AnyComponent<A> = ComponentName<A>, Decorator extends AnyComponent<V> = DefaultDecorator>(items: SchemaCreator<Item, FieldScope> | ISchema, schema?: ArraySchema<A, V, Component, Decorator, Item[], Record, FieldScope>): SchemaCreator<Item[], FieldScope, Record>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export declare interface ArrayFragmentItem<A extends FragmentPropsMap, V extends FragmentPropsMap, K extends ComponentName<A>, Scope extends object = {}, DefaultDecorator extends AnyComponent<V> = ComponentName<V>> {
|
|
39
|
+
/**
|
|
40
|
+
* 无泛型调用:从 items creator 推断数组项类型。
|
|
41
|
+
*/
|
|
42
|
+
<Items extends SchemaCreator<any>, Decorator extends AnyComponent<V> = DefaultDecorator>(items: Items, schema?: Omit<ArraySchema<A, V, K, Decorator, SchemaCreatorValue<Items>[], TRecordOfItem<SchemaCreatorValue<Items>>, Scope>, 'component'>): SchemaCreator<SchemaCreatorValue<Items>[], any, SchemaCreatorValue<Items>, SchemaCreatorValue<Items>[]>;
|
|
43
|
+
/**
|
|
44
|
+
* 显式声明数组项类型与字段级 Scope,items 中的子级自动继承。
|
|
45
|
+
*/
|
|
46
|
+
<Item = any, FieldScope extends object = Scope, Record extends object = any, Decorator extends AnyComponent<V> = DefaultDecorator>(items: SchemaCreator<Item, FieldScope> | ISchema, schema?: Omit<ArraySchema<A, V, K, Decorator, Item[], Record, FieldScope>, 'component'>): SchemaCreator<Item[], FieldScope, Record>;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export declare type ArrayFragmentMapping<A extends FragmentPropsMap, V extends FragmentPropsMap, Scope extends object = {}, DefaultDecorator extends AnyComponent<V> = ComponentName<V>> = {
|
|
50
|
+
[K in ComponentName<A>]: ArrayFragmentItem<A, V, K, Scope, DefaultDecorator>;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export declare type ArraySchema<A extends FragmentPropsMap, V extends FragmentPropsMap, Component extends AnyComponent<A> = ComponentName<A>, Decorator extends AnyComponent<V> = ComponentName<V>, Value extends any[] = any[], IRecord extends object = any, Scope extends object = {}, IValues extends object = any> = Omit<ISchema, SchemaOverrideKeys | 'items' | 'properties'> & {
|
|
54
|
+
component?: Component | SchemaExpression;
|
|
55
|
+
componentProps?: ExpressionProps<TComponentProps<A, Component>>;
|
|
56
|
+
decorator?: Decorator | SchemaExpression;
|
|
57
|
+
decoratorProps?: ExpressionProps<TComponentProps<V, Decorator>>;
|
|
58
|
+
properties?: SchemaPropertiesInput;
|
|
59
|
+
reactions?: SchemaReactions<ArrayField<Value, TComponentProps<A, Component>, TComponentProps<V, Decorator>, IRecord>, Scope, IRecord, IValues>;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
declare type ComponentName<Map> = [Map] extends [never] ? never : keyof Map & string;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* 返回一个对象的表达式主要方便于类型推导
|
|
66
|
+
* @param expression 对象表达式 如 'obj'
|
|
67
|
+
* @example
|
|
68
|
+
* const objExp = createExpression<{ a: number; b: () => string,'1b': string }>('obj')
|
|
69
|
+
* objExp.a // {{obj.a}}
|
|
70
|
+
* objExp['1b'] // {{obj['1b']}}
|
|
71
|
+
* objExp.fn.b() // {{function __b() {} return obj.b()}}
|
|
72
|
+
* objExp.fn.b('$args') // {{function __b(...$args) {} return obj.b(...$args)}}
|
|
73
|
+
* objExp.fn.b('$event') // {{function __b($event) {} return obj.b($event)}}
|
|
74
|
+
* objExp.fn.b('$self', '$event') // {{function __b($event) {} return obj.b($self, $event)}}
|
|
75
|
+
* objExp.fn.b('$self', '$args') // {{function __b(...$args) {} return obj.b($self, ...$args)}}
|
|
76
|
+
*/
|
|
77
|
+
export declare function createExpression<T extends object>(expression: string): Expression<T>;
|
|
78
|
+
|
|
79
|
+
export declare function createExpressionFn<T>(expression: string): Expression<T>['fn'];
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* 底层 schema 构造器。
|
|
83
|
+
* 默认不内置任何 patch,组件 props 类型由 F / V / A 三个独立 map 注入。
|
|
84
|
+
*/
|
|
85
|
+
export declare function createFragment<F extends FragmentPropsMap = {}, V extends FragmentPropsMap = {}, A extends FragmentPropsMap = {}, Scope extends object = {}, DefaultDecorator extends AnyComponent<V> = AnyComponent<V>>(options?: FragmentOptions<V, DefaultDecorator>): Fragment<F, V, A, Scope, DefaultDecorator>;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* 对象 schema 快捷组装器。
|
|
89
|
+
* 默认不内置任何 patch,creator 使用传入的 patches 展开。
|
|
90
|
+
*/
|
|
91
|
+
export declare function createSchema<Properties extends Record<string, unknown>, IValues extends SchemaPropertiesValues<Properties>>(properties: Properties & ValidateSchemaProperties<Properties>, patches?: SchemaPatchInput | SchemaPatchInput[]): ISchema & {
|
|
92
|
+
_$types$_: [IValues];
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* 显式 overload 的调用守卫:第一个类型参数默认 never,未显式提供时参数类型为 never,
|
|
97
|
+
* 使调用落到后面的推断 overload;显式提供泛型时还原为真实入参类型。
|
|
98
|
+
*/
|
|
99
|
+
declare type ExplicitTypeArgGuard<T, Context> = [T] extends [never] ? never : Context;
|
|
100
|
+
|
|
101
|
+
export declare type Expression<T> = IExpressionStr<T, true> & {
|
|
102
|
+
/**
|
|
103
|
+
* 返回其中函数表达式集合
|
|
104
|
+
* $args 表示函数的参数集合
|
|
105
|
+
* $event 表示函数的第一个参数
|
|
106
|
+
* $args 和 $event 不能同时传入
|
|
107
|
+
* @example
|
|
108
|
+
* objExp.fn.b('$args') // {{function __b(...$args) {} return obj.b(...$args)}}
|
|
109
|
+
* objExp.fn.b('$event') // {{function __b($event) {} return obj.b($event)}}
|
|
110
|
+
* objExp.fn.b('$self') // {{function __b() {} return obj.b($self)}}
|
|
111
|
+
* // 不可以同时传入 $args 和 $event
|
|
112
|
+
* objExp.fn.b('$args', '$event') // Error
|
|
113
|
+
* objExp.fn.b('$args', '$self') // {{function __b(...$args) {} return obj.b(...$args, $self)}}
|
|
114
|
+
* objExp.fn.b('$event', '$self') // {{function __b($event) {} return obj.b($event, $self)}}
|
|
115
|
+
*/
|
|
116
|
+
fn: IExpressionFn<T>;
|
|
117
|
+
/**
|
|
118
|
+
* 返回其中属性表达式集合
|
|
119
|
+
* @example
|
|
120
|
+
* objExp.exp.a // obj.a
|
|
121
|
+
* objExp.exp['a.b'] // obj['a.b']
|
|
122
|
+
* objExp.exp.a.b.c // obj.a.b.c
|
|
123
|
+
*/
|
|
124
|
+
exp: IExpressionStr<T, false>;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
export declare interface ExpressionFnOptions {
|
|
128
|
+
/**
|
|
129
|
+
* 是否展开参数
|
|
130
|
+
* @default true
|
|
131
|
+
* @example
|
|
132
|
+
* objExp.fn.b('$args', { expand: false }) // {{function __b($args) {} return obj.b($args)}}
|
|
133
|
+
* objExp.fn.b('$args', { expand: true }) // {{function __b(...$args) {} return obj.b(...$args)}}
|
|
134
|
+
*/
|
|
135
|
+
expand?: boolean;
|
|
136
|
+
/**
|
|
137
|
+
* 函数体
|
|
138
|
+
* @example
|
|
139
|
+
* objExp.fn.b('$args', 'title', { body: 'var title = $self.title' })
|
|
140
|
+
* `{{function __b(...$args) {
|
|
141
|
+
* var title = $self.title;
|
|
142
|
+
* return obj.b(...$args, title)
|
|
143
|
+
* }}}`
|
|
144
|
+
*/
|
|
145
|
+
body?: string;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* 组件/装饰器 props 的表达式类型:递归地把每个叶子扩展为「原类型 | 表达式」,整体也允许直接传表达式。
|
|
150
|
+
* 运行时 compiler 会编译 componentProps / decoratorProps 内任意层级的 `{{...}}` 字符串叶子。
|
|
151
|
+
*
|
|
152
|
+
* 与 Stringify 的区别:对象分支采用同态映射,保留原 key 的可选/必填修饰符
|
|
153
|
+
* (Stringify 会把所有 key 变可选),避免含必填 props 的组件接口被意外放宽。
|
|
154
|
+
*/
|
|
155
|
+
export declare type ExpressionProps<P> = P extends (...args: any[]) => any ? SchemaExpression | P : P extends object ? SchemaExpression | {
|
|
156
|
+
[K in keyof P]: ExpressionProps<P[K]>;
|
|
157
|
+
} : SchemaExpression | P;
|
|
158
|
+
|
|
159
|
+
declare class ExpressionStr<IsExp extends boolean, Result extends (IsExp extends true ? SchemaExpression : string & {}) = IsExp extends true ? SchemaExpression : string> {
|
|
160
|
+
private expression;
|
|
161
|
+
private isExp;
|
|
162
|
+
constructor(expression: string, isExp?: IsExp);
|
|
163
|
+
getExpression(str: string): Result;
|
|
164
|
+
/**
|
|
165
|
+
* 等于
|
|
166
|
+
* @example
|
|
167
|
+
* objExp.exp.a.eq(1) // obj.a === 1
|
|
168
|
+
* objExp.exp.a.b.c.eq('1') // obj.a.b.c === "1"
|
|
169
|
+
* objExp.exp.a.b.c.eq('$values.d', true) // obj.a.b.c === $values.d
|
|
170
|
+
*/
|
|
171
|
+
eq(str: any, exp?: boolean): Result;
|
|
172
|
+
/**
|
|
173
|
+
* 不等于
|
|
174
|
+
* @example
|
|
175
|
+
* objExp.exp.a.neq(1) // obj.a !== 1
|
|
176
|
+
* objExp.exp.a.neq('$values.b', true) // obj.a !== $values.b
|
|
177
|
+
*/
|
|
178
|
+
neq(str: any, exp?: boolean): Result;
|
|
179
|
+
/**
|
|
180
|
+
* 大于
|
|
181
|
+
* @example
|
|
182
|
+
* objExp.exp.a.gt('1') // obj.a > 1
|
|
183
|
+
* objExp.exp.a.b.c.gt('1') // obj.a.b.c > 1
|
|
184
|
+
*/
|
|
185
|
+
gt(str: any, exp?: boolean): Result;
|
|
186
|
+
/**
|
|
187
|
+
* @example
|
|
188
|
+
* objExp.exp.a.gte('1') // obj.a >= 1
|
|
189
|
+
* objExp.exp.a.b.c.gte('1') // obj.a.b.c >= 1
|
|
190
|
+
*/
|
|
191
|
+
gte(str: any, exp?: boolean): Result;
|
|
192
|
+
/**
|
|
193
|
+
* 小于
|
|
194
|
+
* @example
|
|
195
|
+
* objExp.exp.a.lt('1') // obj.a < 1
|
|
196
|
+
* objExp.exp.a.b.c.lt('1') // obj.a.b.c < 1
|
|
197
|
+
*/
|
|
198
|
+
lt(str: any, exp?: boolean): Result;
|
|
199
|
+
/**
|
|
200
|
+
* 小于等于
|
|
201
|
+
* @example
|
|
202
|
+
* objExp.exp.a.lte(1) // obj.a <= 1
|
|
203
|
+
* objExp.exp.a.b.c.lte('$values.d', true) // obj.a.b.c <= $values.d
|
|
204
|
+
*/
|
|
205
|
+
lte(str: any, exp?: boolean): Result;
|
|
206
|
+
/**
|
|
207
|
+
* 与
|
|
208
|
+
* @example
|
|
209
|
+
* objExp.exp.a.and('1') // obj.a && 1
|
|
210
|
+
*/
|
|
211
|
+
and(str: any, exp?: boolean): Result;
|
|
212
|
+
/**
|
|
213
|
+
* 或
|
|
214
|
+
* @example
|
|
215
|
+
* objExp.exp.a.or(1) // obj.a || 1
|
|
216
|
+
* objExp.exp.a.b.c.or('1') // obj.a.b.c || '1'
|
|
217
|
+
* objExp.exp.a.or('1 || 2', true) // obj.a || 1 || 2
|
|
218
|
+
* objExp.exp.a.or({b: 1}) // obj.a || {"b": 1}
|
|
219
|
+
*/
|
|
220
|
+
or(str: any, exp?: boolean): Result;
|
|
221
|
+
/**
|
|
222
|
+
* 取反
|
|
223
|
+
* @example
|
|
224
|
+
* objExp.exp.a.not() // !obj.a
|
|
225
|
+
* objExp.exp.a.b.c.not() // !obj.a.b.c
|
|
226
|
+
*/
|
|
227
|
+
not(): Result;
|
|
228
|
+
/**
|
|
229
|
+
* 取bool值
|
|
230
|
+
* @example
|
|
231
|
+
* objExp.exp.a.bool() // !!obj.a
|
|
232
|
+
* objExp.exp.a.b.c.bool() // !!obj.a.b.c
|
|
233
|
+
*/
|
|
234
|
+
bool(): Result;
|
|
235
|
+
/**
|
|
236
|
+
* 三元表达式
|
|
237
|
+
* @example
|
|
238
|
+
* objExp.exp.a.ter(1, 2) // obj.a ? 1 : 2
|
|
239
|
+
* objExp.exp.a.b.c.ter('1', '2') // obj.a.b.c ? "1" : "2"
|
|
240
|
+
* objExp.exp.a.ter("obj.a", "abj.b", true) // obj.a ? obj.a : abj.b
|
|
241
|
+
*/
|
|
242
|
+
ter(a: any, b: any, exp?: boolean): Result;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export declare interface FieldFragment<F extends FragmentPropsMap, V extends FragmentPropsMap, Scope extends object = {}, DefaultDecorator extends AnyComponent<V> = ComponentName<V>> {
|
|
246
|
+
<Value = string>(): SchemaCreator<Value | undefined, Scope>;
|
|
247
|
+
<Value = string, Component extends AnyComponent<F> = ComponentName<F>, Decorator extends AnyComponent<V> = DefaultDecorator, FieldScope extends object = Scope, IRecord extends object = any, IValues extends object = any>(schema: FieldSchema<F, V, Component, Decorator, Value, IRecord, FieldScope, IValues> & {
|
|
248
|
+
required: true;
|
|
249
|
+
}): SchemaCreator<Value, FieldScope, IRecord, IValues>;
|
|
250
|
+
<Value = string, Component extends AnyComponent<F> = ComponentName<F>, Decorator extends AnyComponent<V> = DefaultDecorator, FieldScope extends object = Scope, IRecord extends object = any, IValues extends object = any>(schema: FieldSchema<F, V, Component, Decorator, Value, IRecord, FieldScope, IValues>): SchemaCreator<Value | undefined, FieldScope, IRecord, IValues>;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
export declare interface FieldFragmentItem<F extends FragmentPropsMap, V extends FragmentPropsMap, K extends ComponentName<F>, Scope extends object = {}, DefaultDecorator extends AnyComponent<V> = ComponentName<V>> {
|
|
254
|
+
<Value = string, Decorator extends AnyComponent<V> = DefaultDecorator, FieldScope extends object = Scope, IRecord extends object = any, IValues extends object = any>(schema: Omit<FieldSchema<F, V, K, Decorator, Value, IRecord, FieldScope, IValues>, 'component'> & {
|
|
255
|
+
required: true;
|
|
256
|
+
}): SchemaCreator<Value, FieldScope, IRecord, IValues>;
|
|
257
|
+
<Value = string, Decorator extends AnyComponent<V> = DefaultDecorator, FieldScope extends object = Scope, IRecord extends object = any, IValues extends object = any>(schema?: Omit<FieldSchema<F, V, K, Decorator, Value, IRecord, FieldScope, IValues>, 'component'>): SchemaCreator<Value | undefined, FieldScope, IRecord, IValues>;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export declare type FieldFragmentMapping<F extends FragmentPropsMap, V extends FragmentPropsMap, Scope extends object = {}, DefaultDecorator extends AnyComponent<V> = ComponentName<V>> = {
|
|
261
|
+
[K in ComponentName<F>]: FieldFragmentItem<F, V, K, Scope, DefaultDecorator>;
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
export declare type FieldSchema<F extends FragmentPropsMap, V extends FragmentPropsMap, Component extends AnyComponent<F> = ComponentName<F>, Decorator extends AnyComponent<V> = ComponentName<V>, Value = any, IRecord extends object = any, Scope extends object = {}, IValues extends object = any> = Omit<ISchema, SchemaOverrideKeys> & {
|
|
265
|
+
component?: Component | SchemaExpression;
|
|
266
|
+
componentProps?: ExpressionProps<TComponentProps<F, Component>>;
|
|
267
|
+
decorator?: Decorator | SchemaExpression;
|
|
268
|
+
decoratorProps?: ExpressionProps<TComponentProps<V, Decorator>>;
|
|
269
|
+
reactions?: SchemaReactions<Field<Value, TComponentProps<F, Component>, TComponentProps<V, Decorator>, IRecord>, Scope, IRecord, IValues>;
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
export declare type Fragment<F extends FragmentPropsMap = {}, V extends FragmentPropsMap = {}, A extends FragmentPropsMap = {}, Scope extends object = {}, DefaultDecorator extends AnyComponent<V> = ComponentName<V>> = FragmentBase<F, V, A, Scope, DefaultDecorator> & FieldFragmentMapping<F, V, Scope, DefaultDecorator> & VoidFragmentMapping<V, Scope, DefaultDecorator> & ArrayFragmentMapping<A, V, Scope, DefaultDecorator>;
|
|
273
|
+
|
|
274
|
+
export declare interface FragmentBase<F extends FragmentPropsMap, V extends FragmentPropsMap, A extends FragmentPropsMap, Scope extends object = {}, DefaultDecorator extends AnyComponent<V> = ComponentName<V>> {
|
|
275
|
+
Field: FieldFragment<F, V, Scope, DefaultDecorator>;
|
|
276
|
+
Object: ObjectFragment<V, Scope, DefaultDecorator>;
|
|
277
|
+
Array: ArrayFragment<A, V, Scope, DefaultDecorator>;
|
|
278
|
+
Void: VoidFragment<V, Scope, DefaultDecorator>;
|
|
279
|
+
transform: (schema?: ISchema) => ISchema;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
export declare interface FragmentOptions<V extends FragmentPropsMap = {}, DefaultDecorator extends AnyComponent<V> = AnyComponent<V>> {
|
|
283
|
+
patches?: SchemaPatchInput | SchemaPatchInput[];
|
|
284
|
+
/** 动态组件中按 void 处理的组件名,其余未声明组件按 field 处理 */
|
|
285
|
+
voidComponentNames?: string[];
|
|
286
|
+
/** 动态组件中按 array 处理的组件名 */
|
|
287
|
+
arrayComponentNames?: string[];
|
|
288
|
+
/**
|
|
289
|
+
* 默认装饰器:string 字段声明了 title 且未显式设置 decorator 时自动补上。
|
|
290
|
+
* 与 formily-pro 的 defaultDecoratorPatch 语义一致,object / void / array 不生效。
|
|
291
|
+
* 指定 createFragment 的第五个泛型后,decoratorProps 会按该装饰器收窄。
|
|
292
|
+
*/
|
|
293
|
+
defaultDecorator?: DefaultDecorator;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* 三个独立的组件 props map,泛型顺序与运行时分类通道一致:
|
|
298
|
+
* - F:数据字段组件(string / number 等,也是动态组件的默认分类)
|
|
299
|
+
* - V:无值组件(void 字段、object 字段、decorator)
|
|
300
|
+
* - A:数组组件(array 字段)
|
|
301
|
+
*/
|
|
302
|
+
export declare type FragmentPropsMap = Record<string, any>;
|
|
303
|
+
|
|
304
|
+
export declare function getExpression(expression: string, key: string): string;
|
|
305
|
+
|
|
306
|
+
export declare type IExpressionFn<T> = {
|
|
307
|
+
[K in keyof T]-?: T[K] extends (...args: any[]) => any ? (args?: Args, ..._args: Args[]) => SchemaExpression : T[K] extends object ? IExpressionFn<T[K]> : never;
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
export declare type IExpressionStr<T, IsExp extends boolean> = T extends object ? {
|
|
311
|
+
[K in keyof T]-?: ExpressionStr<IsExp> & (NonNullable<T[K]> & {}) & IExpressionStr<T[K], IsExp>;
|
|
312
|
+
} : NonNullable<T>;
|
|
313
|
+
|
|
314
|
+
export declare interface IFieldStateSetterOptions {
|
|
315
|
+
field: GeneralField;
|
|
316
|
+
target?: FormPathPattern;
|
|
317
|
+
request: ISchemaFieldUpdateRequest;
|
|
318
|
+
runner?: string;
|
|
319
|
+
scope?: Record<string, any>;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* 标准 JSON Schema 字段保持小驼峰;formily 的 `x-*` 扩展字段统一去掉 x 前缀并使用小驼峰,
|
|
324
|
+
* 例如 `x-component` -> `component`、`x-component-props` -> `componentProps`。
|
|
325
|
+
* 第三方自定义扩展字段使用 `xKey` 形式,例如 `xCustomThing`。
|
|
326
|
+
*
|
|
327
|
+
* 注意:`pattern` 表示字段交互模式(editable / readOnly / disabled / readPretty),
|
|
328
|
+
* 不再承担标准 JSON Schema 中正则校验的语义,正则校验请使用 `validator`。
|
|
329
|
+
*/
|
|
330
|
+
export declare interface ISchema extends ISchemaBase {
|
|
331
|
+
version?: string;
|
|
332
|
+
name?: SchemaKey;
|
|
333
|
+
default?: any;
|
|
334
|
+
readOnly?: Stringify<boolean>;
|
|
335
|
+
writeOnly?: Stringify<boolean>;
|
|
336
|
+
type?: SchemaTypes;
|
|
337
|
+
enum?: Stringify<SchemaEnum>;
|
|
338
|
+
const?: any;
|
|
339
|
+
multipleOf?: Stringify<number>;
|
|
340
|
+
maximum?: Stringify<number>;
|
|
341
|
+
exclusiveMaximum?: Stringify<number>;
|
|
342
|
+
minimum?: Stringify<number>;
|
|
343
|
+
exclusiveMinimum?: Stringify<number>;
|
|
344
|
+
maxLength?: Stringify<number>;
|
|
345
|
+
minLength?: Stringify<number>;
|
|
346
|
+
pattern?: Stringify<string>;
|
|
347
|
+
maxItems?: Stringify<number>;
|
|
348
|
+
minItems?: Stringify<number>;
|
|
349
|
+
uniqueItems?: Stringify<boolean>;
|
|
350
|
+
maxProperties?: Stringify<number>;
|
|
351
|
+
minProperties?: Stringify<number>;
|
|
352
|
+
required?: Stringify<string[] | boolean | string>;
|
|
353
|
+
format?: Stringify<string>;
|
|
354
|
+
$ref?: string;
|
|
355
|
+
$namespace?: string;
|
|
356
|
+
/** 嵌套 JSON Schema 描述 */
|
|
357
|
+
definitions?: SchemaProperties;
|
|
358
|
+
properties?: SchemaProperties;
|
|
359
|
+
items?: SchemaItems;
|
|
360
|
+
additionalItems?: ISchema;
|
|
361
|
+
patternProperties?: SchemaProperties;
|
|
362
|
+
additionalProperties?: ISchema;
|
|
363
|
+
/** 字段值 */
|
|
364
|
+
value?: any;
|
|
365
|
+
/** 校验器,叶子规则同样支持 `{{...}}` 表达式 */
|
|
366
|
+
validator?: Stringify<FieldValidator>;
|
|
367
|
+
/**
|
|
368
|
+
* 装饰器引用,支持组件名字符串 / 组件引用 / `{{...}}` 表达式(求值结果为组件名或组件引用)。
|
|
369
|
+
* 结构化创建请使用 createFragment 获得按组件 map 收窄的严格类型。
|
|
370
|
+
*/
|
|
371
|
+
decorator?: any;
|
|
372
|
+
/** 装饰器属性,任意层级的字符串叶子支持 `{{...}}` 表达式 */
|
|
373
|
+
decoratorProps?: any;
|
|
374
|
+
/**
|
|
375
|
+
* 组件引用,支持组件名字符串 / 组件引用 / `{{...}}` 表达式(求值结果为组件名或组件引用)。
|
|
376
|
+
* 结构化创建请使用 createFragment 获得按组件 map 收窄的严格类型。
|
|
377
|
+
*/
|
|
378
|
+
component?: any;
|
|
379
|
+
/** 组件属性,任意层级的字符串叶子支持 `{{...}}` 表达式 */
|
|
380
|
+
componentProps?: any;
|
|
381
|
+
/** 组件响应器 */
|
|
382
|
+
reactions?: SchemaReactions;
|
|
383
|
+
/** 指定不做表达式编译的字段 */
|
|
384
|
+
compileOmitted?: string[];
|
|
385
|
+
slotNode?: Slot;
|
|
386
|
+
/** 渲染到父组件的具名插槽 */
|
|
387
|
+
slot?: string;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* 所有 schema 节点共享的基础字段。
|
|
392
|
+
* 业务可通过 `interface MySchema extends ISchemaBase` 或声明合并扩展字段。
|
|
393
|
+
*/
|
|
394
|
+
export declare interface ISchemaBase {
|
|
395
|
+
title?: Stringify<string>;
|
|
396
|
+
description?: Stringify<string>;
|
|
397
|
+
editable?: Stringify<boolean>;
|
|
398
|
+
disabled?: Stringify<boolean>;
|
|
399
|
+
readPretty?: Stringify<boolean>;
|
|
400
|
+
visible?: Stringify<boolean>;
|
|
401
|
+
hidden?: Stringify<boolean>;
|
|
402
|
+
display?: Stringify<'visible' | 'hidden' | 'none'>;
|
|
403
|
+
data?: any;
|
|
404
|
+
index?: number;
|
|
405
|
+
content?: any;
|
|
406
|
+
/** 第三方自定义扩展字段,使用 xKey 形式 */
|
|
407
|
+
[key: `x${string}`]: any;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
export declare interface ISchemaFieldUpdateRequest {
|
|
411
|
+
state?: Stringify<IGeneralFieldState>;
|
|
412
|
+
schema?: ISchema;
|
|
413
|
+
run?: string;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* scope 输入:运行时允许传入任意自定义字段。
|
|
418
|
+
* 需要类型推断时请使用 createFragment 的 Scope 泛型或 TScope。
|
|
419
|
+
*/
|
|
420
|
+
export declare interface ISchemaTransformerOptions<Scope extends object = Record<string, any>> {
|
|
421
|
+
scope?: Scope;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* reactions / expressions 中内置的字段上下文
|
|
426
|
+
*/
|
|
427
|
+
export declare interface IScopeBase<Field extends GeneralField = GeneralField, IRecord extends object = any, IValues extends object = any> extends IScopeDefault {
|
|
428
|
+
/** 当前字段 */
|
|
429
|
+
$self: Field;
|
|
430
|
+
/** 当前表单 */
|
|
431
|
+
$form: Form<IValues>;
|
|
432
|
+
/** 表单值 */
|
|
433
|
+
$values: IValues;
|
|
434
|
+
/** 当前字段在数组中的下标 */
|
|
435
|
+
$index: number;
|
|
436
|
+
/** 父级记录 */
|
|
437
|
+
$record: IRecord & {
|
|
438
|
+
$lookup: any;
|
|
439
|
+
$index: number;
|
|
440
|
+
};
|
|
441
|
+
/** 父级记录数组 */
|
|
442
|
+
$records: IRecord[];
|
|
443
|
+
/** 设置当前字段的组件属性 */
|
|
444
|
+
$props: Field['setComponentProps'];
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* 全局 scope 扩展点。
|
|
449
|
+
* 可通过声明合并全局扩展,所有未显式传入 Scope 泛型的位置都会继承:
|
|
450
|
+
*
|
|
451
|
+
* declare module '@formvk/schema' {
|
|
452
|
+
* interface IScopeContext {
|
|
453
|
+
* $myApi: MyApi
|
|
454
|
+
* }
|
|
455
|
+
* }
|
|
456
|
+
*/
|
|
457
|
+
export declare interface IScopeContext {
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* reactions / expressions 中内置的动态能力
|
|
462
|
+
*/
|
|
463
|
+
export declare interface IScopeDefault {
|
|
464
|
+
/** 等同 autorun,追踪回调中的响应式依赖 */
|
|
465
|
+
$effect: typeof autorun;
|
|
466
|
+
/** 立即执行回调并返回结果 */
|
|
467
|
+
$memo: <T>(callback: () => T) => T;
|
|
468
|
+
/** 将对象转换为 observable */
|
|
469
|
+
$observable: <T extends object>(target: T) => T;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
export declare interface ObjectFragment<V extends FragmentPropsMap, Scope extends object = {}, DefaultDecorator extends AnyComponent<V> = ComponentName<V>> {
|
|
473
|
+
/**
|
|
474
|
+
* 显式声明对象值类型与字段级 Scope,properties 中的子级自动继承:
|
|
475
|
+
* - 子级 creator 的值类型与 `$record` 由 Value 收敛
|
|
476
|
+
* - 子级未显式声明 Scope 时继承 FieldScope
|
|
477
|
+
* 对象自身位于父级容器中,`$record` 无法从 properties 推断,默认 any,可通过第三个泛型显式声明。
|
|
478
|
+
* Value 默认 never 配合 Guard,保证不传泛型时由下方的推断 overload 接管。
|
|
479
|
+
*/
|
|
480
|
+
<Value extends object = never, FieldScope extends object = Scope, Record extends object = any, Component extends AnyComponent<V> = ComponentName<V>, Decorator extends AnyComponent<V> = DefaultDecorator>(properties: ExplicitTypeArgGuard<Value, SchemaPropertiesContext<Value, FieldScope>>, schema?: ObjectSchema<V, Component, Decorator, Value, Record, FieldScope>): SchemaCreator<Value, FieldScope, Record>;
|
|
481
|
+
<Properties extends Record<string, unknown>, Component extends AnyComponent<V> = ComponentName<V>, Decorator extends AnyComponent<V> = DefaultDecorator>(properties: Properties & ValidateSchemaProperties<Properties>, schema?: ObjectSchema<V, Component, Decorator, SchemaPropertiesValues<Properties>, any, Scope>): SchemaCreator<SchemaPropertiesValues<Properties>, any, SchemaPropertiesValues<Properties>, SchemaPropertiesValues<Properties>>;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
export declare type ObjectSchema<V extends FragmentPropsMap, Component extends AnyComponent<V> = ComponentName<V>, Decorator extends AnyComponent<V> = ComponentName<V>, Value extends object = any, IRecord extends object = any, Scope extends object = {}, IValues extends object = any> = Omit<ISchema, SchemaOverrideKeys | 'properties'> & {
|
|
485
|
+
component?: Component | SchemaExpression;
|
|
486
|
+
componentProps?: ExpressionProps<TComponentProps<V, Component>>;
|
|
487
|
+
decorator?: Decorator | SchemaExpression;
|
|
488
|
+
decoratorProps?: ExpressionProps<TComponentProps<V, Decorator>>;
|
|
489
|
+
properties?: SchemaPropertiesInput;
|
|
490
|
+
reactions?: SchemaReactions<ObjectField<Value, TComponentProps<V, Component>, TComponentProps<V, Decorator>, IRecord>, Scope, IRecord, IValues>;
|
|
491
|
+
};
|
|
492
|
+
|
|
493
|
+
declare function registerCompiler(compiler: (expression: string, scope: any) => any): void;
|
|
494
|
+
|
|
495
|
+
declare function registerPatches(...args: SchemaPatch[]): void;
|
|
496
|
+
|
|
497
|
+
export declare class Schema implements ISchema {
|
|
498
|
+
parent?: Schema;
|
|
499
|
+
root?: Schema;
|
|
500
|
+
name?: SchemaKey;
|
|
501
|
+
title?: ISchema['title'];
|
|
502
|
+
description?: ISchema['description'];
|
|
503
|
+
default?: any;
|
|
504
|
+
readOnly?: ISchema['readOnly'];
|
|
505
|
+
writeOnly?: ISchema['writeOnly'];
|
|
506
|
+
type?: SchemaTypes;
|
|
507
|
+
enum?: SchemaEnum;
|
|
508
|
+
const?: any;
|
|
509
|
+
multipleOf?: ISchema['multipleOf'];
|
|
510
|
+
exclusiveMaximum?: ISchema['exclusiveMaximum'];
|
|
511
|
+
maximum?: ISchema['maximum'];
|
|
512
|
+
exclusiveMinimum?: ISchema['exclusiveMinimum'];
|
|
513
|
+
minimum?: ISchema['minimum'];
|
|
514
|
+
maxLength?: ISchema['maxLength'];
|
|
515
|
+
minLength?: ISchema['minLength'];
|
|
516
|
+
pattern?: ISchema['pattern'];
|
|
517
|
+
maxItems?: ISchema['maxItems'];
|
|
518
|
+
minItems?: ISchema['minItems'];
|
|
519
|
+
uniqueItems?: ISchema['uniqueItems'];
|
|
520
|
+
maxProperties?: ISchema['maxProperties'];
|
|
521
|
+
minProperties?: ISchema['minProperties'];
|
|
522
|
+
required?: ISchema['required'];
|
|
523
|
+
format?: ISchema['format'];
|
|
524
|
+
$ref?: string;
|
|
525
|
+
$namespace?: string;
|
|
526
|
+
/** 嵌套 JSON Schema 描述 */
|
|
527
|
+
definitions?: Record<string, Schema>;
|
|
528
|
+
properties?: Record<string, Schema>;
|
|
529
|
+
items?: Schema | Schema[];
|
|
530
|
+
additionalItems?: Schema;
|
|
531
|
+
patternProperties?: Record<string, Schema>;
|
|
532
|
+
additionalProperties?: Schema;
|
|
533
|
+
/** 字段值 */
|
|
534
|
+
value?: any;
|
|
535
|
+
/** 顺序描述 */
|
|
536
|
+
index?: number;
|
|
537
|
+
/** 展示状态 */
|
|
538
|
+
display?: ISchema['display'];
|
|
539
|
+
/** 校验器 */
|
|
540
|
+
validator?: ISchema['validator'];
|
|
541
|
+
/** 装饰器 */
|
|
542
|
+
decorator?: any;
|
|
543
|
+
/** 装饰器属性 */
|
|
544
|
+
decoratorProps?: any;
|
|
545
|
+
/** 组件 */
|
|
546
|
+
component?: any;
|
|
547
|
+
/** 组件属性 */
|
|
548
|
+
componentProps?: any;
|
|
549
|
+
/** 组件响应器 */
|
|
550
|
+
reactions?: SchemaReactions;
|
|
551
|
+
/** 内容 */
|
|
552
|
+
content?: any;
|
|
553
|
+
data?: any;
|
|
554
|
+
visible?: boolean;
|
|
555
|
+
hidden?: boolean;
|
|
556
|
+
disabled?: boolean;
|
|
557
|
+
editable?: boolean;
|
|
558
|
+
readPretty?: boolean;
|
|
559
|
+
compileOmitted?: string[];
|
|
560
|
+
slotNode?: Slot;
|
|
561
|
+
/** 渲染到父组件的具名插槽 */
|
|
562
|
+
slot?: string;
|
|
563
|
+
/** 第三方自定义扩展字段,使用 xKey 形式 */
|
|
564
|
+
[key: `x${string}`]: any;
|
|
565
|
+
_isJSONSchemaObject: boolean;
|
|
566
|
+
version: string;
|
|
567
|
+
constructor(json: ISchema, parent?: Schema);
|
|
568
|
+
addProperty: (key: SchemaKey, schema: ISchema) => Schema;
|
|
569
|
+
removeProperty: (key: SchemaKey) => Schema | undefined;
|
|
570
|
+
setProperties: (properties: SchemaProperties) => this;
|
|
571
|
+
addPatternProperty: (key: SchemaKey, schema: ISchema) => Schema | undefined;
|
|
572
|
+
removePatternProperty: (key: SchemaKey) => Schema | undefined;
|
|
573
|
+
setPatternProperties: (properties: SchemaProperties) => this;
|
|
574
|
+
setAdditionalProperties: (properties: ISchema) => Schema | undefined;
|
|
575
|
+
setItems: (schema: ISchema | ISchema[]) => Schema | Schema[] | undefined;
|
|
576
|
+
setAdditionalItems: (items: ISchema) => Schema | undefined;
|
|
577
|
+
findDefinitions: (ref: string) => any;
|
|
578
|
+
mapProperties: <T>(callback?: (schema: Schema, key: SchemaKey, index: number) => T) => T[];
|
|
579
|
+
mapPatternProperties: <T>(callback?: (schema: Schema, key: SchemaKey, index: number) => T) => T[];
|
|
580
|
+
reduceProperties: <P, R>(callback?: (buffer: P, schema: Schema, key: SchemaKey, index: number) => R, predicate?: P) => R;
|
|
581
|
+
reducePatternProperties: <P, R>(callback?: (buffer: P, schema: Schema, key: SchemaKey, index: number) => R, predicate?: P) => R;
|
|
582
|
+
compile: (scope?: any) => Schema;
|
|
583
|
+
fromJSON: (json: ISchema) => Schema;
|
|
584
|
+
toJSON: (recursion?: boolean) => ISchema;
|
|
585
|
+
toFieldProps: (options?: ISchemaTransformerOptions) => IFieldFactoryProps<any, any>;
|
|
586
|
+
static getOrderProperties: (schema?: ISchema, propertiesName?: keyof ISchema) => {
|
|
587
|
+
schema: any;
|
|
588
|
+
key: string;
|
|
589
|
+
}[];
|
|
590
|
+
static compile: (expression: any, scope?: any) => any;
|
|
591
|
+
static shallowCompile: (expression: any, scope?: any) => any;
|
|
592
|
+
static isSchemaInstance: (value: any) => value is Schema;
|
|
593
|
+
static registerCompiler: typeof registerCompiler;
|
|
594
|
+
static registerPatches: typeof registerPatches;
|
|
595
|
+
static silent: typeof silent;
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
export declare type SchemaComponents = Record<string, any>;
|
|
599
|
+
|
|
600
|
+
export declare interface SchemaCreator<Value = any, IScope = any, IRecord extends object = any, IValues = any> {
|
|
601
|
+
(patches?: SchemaPatchInput | SchemaPatchInput[]): ISchema;
|
|
602
|
+
/** 仅用于类型标记,请勿使用 */
|
|
603
|
+
_$types$_: [Value, IRecord, IScope, IValues];
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
/**
|
|
607
|
+
* 结构化的 creator 约束。
|
|
608
|
+
* 这里刻意不写成 `SchemaCreator<any>`,避免调用处把 Value 泛型从上下文中推导成 any。
|
|
609
|
+
*/
|
|
610
|
+
export declare type SchemaCreatorLike = ((patches?: SchemaPatchInput | SchemaPatchInput[]) => ISchema) & {
|
|
611
|
+
_$types$_: any[];
|
|
612
|
+
};
|
|
613
|
+
|
|
614
|
+
export declare type SchemaCreatorValue<T> = T extends SchemaCreator<infer Value, any, any, any> ? Value : any;
|
|
615
|
+
|
|
616
|
+
export declare type SchemaEffectTypes = 'onFieldInit' | 'onFieldMount' | 'onFieldUnmount' | 'onFieldValueChange' | 'onFieldInputValueChange' | 'onFieldInitialValueChange' | 'onFieldValidateStart' | 'onFieldValidateEnd' | 'onFieldValidateFailed' | 'onFieldValidateSuccess';
|
|
617
|
+
|
|
618
|
+
export declare type SchemaEnum = Array<string | number | boolean | {
|
|
619
|
+
label?: string;
|
|
620
|
+
value?: any;
|
|
621
|
+
[key: string]: any;
|
|
622
|
+
} | {
|
|
623
|
+
key?: any;
|
|
624
|
+
title?: string;
|
|
625
|
+
[key: string]: any;
|
|
626
|
+
}>;
|
|
627
|
+
|
|
628
|
+
export declare type SchemaExpression = `{{${string}}}`;
|
|
629
|
+
|
|
630
|
+
export declare type SchemaItems = ISchema | ISchema[];
|
|
631
|
+
|
|
632
|
+
export declare type SchemaKey = string | number;
|
|
633
|
+
|
|
634
|
+
/** 四类 Schema 统一重写的 ISchema 键:节点类型、组件/装饰器引用及其 props、reactions;各 Schema 再按结构追加自身专有键 */
|
|
635
|
+
declare type SchemaOverrideKeys = 'type' | 'component' | 'componentProps' | 'decorator' | 'decoratorProps' | 'reactions';
|
|
636
|
+
|
|
637
|
+
export declare type SchemaPatch = (schema: ISchema) => ISchema;
|
|
638
|
+
|
|
639
|
+
/** 支持 `{ pre: true, patch }` 形式的 patch,pre 会提前执行 */
|
|
640
|
+
export declare type SchemaPatchInput = SchemaPatch | {
|
|
641
|
+
pre?: boolean;
|
|
642
|
+
patch: SchemaPatch;
|
|
643
|
+
};
|
|
644
|
+
|
|
645
|
+
export declare type SchemaProperties = Record<string, ISchema>;
|
|
646
|
+
|
|
647
|
+
/**
|
|
648
|
+
* 父级声明类型的 properties 上下文。
|
|
649
|
+
* - Record 中声明的 key 会收敛子级 creator 的值类型与 reactions 的 `$record`
|
|
650
|
+
* - 未在 Record 中声明的 key 只允许 void 字段,用于布局等不产生值的节点
|
|
651
|
+
* - 子级未显式声明 Scope 时自动继承父级 Scope
|
|
652
|
+
*
|
|
653
|
+
* 这里刻意使用非 homomorphic 的映射类型(`Extract<keyof IRecord, string | number>`),
|
|
654
|
+
* 避免 TS 从子级 creator 反向推断父级 Record,保证显式声明的类型优先。
|
|
655
|
+
*/
|
|
656
|
+
export declare type SchemaPropertiesContext<IRecord extends object = any, Scope extends object = {}, IValues extends object = any> = {
|
|
657
|
+
[K in Extract<keyof IRecord, string | number>]?: SchemaCreator<IRecord[K], Scope, IRecord, IValues> | ISchema | null | undefined;
|
|
658
|
+
} | {
|
|
659
|
+
[key: string]: VoidSchemaCreator<IRecord, Scope, IValues> | ISchema | null | undefined;
|
|
660
|
+
};
|
|
661
|
+
|
|
662
|
+
/** properties 输入:creator / 已展开 ISchema / 空值 */
|
|
663
|
+
export declare type SchemaPropertiesInput = Record<string, SchemaCreatorLike | ISchema | null | undefined>;
|
|
664
|
+
|
|
665
|
+
export declare type SchemaPropertiesValues<P extends Record<string, any>> = {
|
|
666
|
+
[K in keyof P]?: P[K] extends SchemaCreator<infer Value, any, any, any> ? Value : any;
|
|
667
|
+
};
|
|
668
|
+
|
|
669
|
+
export declare type SchemaReaction<Field extends GeneralField = GeneralField, Scope extends object = {}, IRecord extends object = any, IValues extends object = any> = {
|
|
670
|
+
dependencies?: Array<string | {
|
|
671
|
+
name?: string;
|
|
672
|
+
type?: string;
|
|
673
|
+
source?: string;
|
|
674
|
+
property?: string;
|
|
675
|
+
}> | Record<string, string>;
|
|
676
|
+
when?: string | boolean;
|
|
677
|
+
target?: string;
|
|
678
|
+
effects?: (SchemaEffectTypes | (string & {}))[];
|
|
679
|
+
fulfill?: {
|
|
680
|
+
state?: Stringify<IGeneralFieldState>;
|
|
681
|
+
schema?: ISchema;
|
|
682
|
+
run?: string;
|
|
683
|
+
};
|
|
684
|
+
otherwise?: {
|
|
685
|
+
state?: Stringify<IGeneralFieldState>;
|
|
686
|
+
schema?: ISchema;
|
|
687
|
+
run?: string;
|
|
688
|
+
};
|
|
689
|
+
[key: string]: any;
|
|
690
|
+
} | ((field: Field, scope: TScope<Scope, Field, IRecord, IValues>) => void);
|
|
691
|
+
|
|
692
|
+
export declare type SchemaReactions<Field extends GeneralField = GeneralField, Scope extends object = {}, IRecord extends object = any, IValues extends object = any> = SchemaReaction<Field, Scope, IRecord, IValues> | SchemaReaction<Field, Scope, IRecord, IValues>[];
|
|
693
|
+
|
|
694
|
+
export declare type SchemaTypes = 'string' | 'object' | 'array' | 'number' | 'boolean' | 'void' | 'date' | 'datetime' | (string & {});
|
|
695
|
+
|
|
696
|
+
declare function silent(value?: boolean): void;
|
|
697
|
+
|
|
698
|
+
export declare type Slot = {
|
|
699
|
+
target: string;
|
|
700
|
+
isRenderProp?: boolean;
|
|
701
|
+
};
|
|
702
|
+
|
|
703
|
+
/**
|
|
704
|
+
* 递归地把类型 P 的叶子扩展为「原类型 | 表达式」。
|
|
705
|
+
* 参考 formily-pro TStringify:
|
|
706
|
+
* - 函数:SchemaExpression | P
|
|
707
|
+
* - 数组:Stringify<Item>[] | SchemaExpression
|
|
708
|
+
* - 对象:逐 key 递归
|
|
709
|
+
* - 标量:SchemaExpression | P
|
|
710
|
+
*/
|
|
711
|
+
export declare type Stringify<P> = P extends (...args: any[]) => any ? SchemaExpression | P : P extends readonly any[] ? Stringify<P[number]>[] | SchemaExpression : P extends object ? {
|
|
712
|
+
[K in keyof P]?: Stringify<P[K]>;
|
|
713
|
+
} : SchemaExpression | P;
|
|
714
|
+
|
|
715
|
+
declare type TComponentProps<Map, Component> = [Component] extends [never] ? Record<string, unknown> : Component extends string ? [Map] extends [never] ? Record<string, unknown> : Component extends keyof Map ? Map[Component] : Record<string, unknown> : TPropsOfComponent<Component>;
|
|
716
|
+
|
|
717
|
+
/**
|
|
718
|
+
* 从组件类型提取 props;Vue 从 `$props`、类组件从构造函数首参、函数组件从入参提取。
|
|
719
|
+
* 无法识别组件形状时退回 `Record<string, unknown>`:保持对象可赋值、但不再放行任意属性运算(any 会污染下游)。
|
|
720
|
+
* 与 vue 包 ComponentProps 的差异:vue 侧只服务 Vue 组件,识别失败退化为 never(严格);
|
|
721
|
+
* 本类型需兼容跨框架的任意组件引用,识别失败只能退化为宽松 record。
|
|
722
|
+
*/
|
|
723
|
+
export declare type TPropsOfComponent<Component> = Component extends abstract new (...args: any) => {
|
|
724
|
+
$props: infer Props;
|
|
725
|
+
} ? Props : Component extends abstract new (props: infer Props, ...args: any[]) => any ? Props : Component extends (props: infer Props, ...args: any[]) => any ? Props : Record<string, unknown>;
|
|
726
|
+
|
|
727
|
+
/** 数组项可作为 record 类型时直接使用,基础类型退回 any(与核心 ArrayField 的 IRecord 约束一致) */
|
|
728
|
+
declare type TRecordOfItem<Item> = Item extends object ? Item : any;
|
|
729
|
+
|
|
730
|
+
/**
|
|
731
|
+
* 组合内置 scope、全局扩展与自定义 scope
|
|
732
|
+
*/
|
|
733
|
+
export declare type TScope<Scope extends object = {}, Field extends GeneralField = GeneralField, IRecord extends object = any, IValues extends object = any> = IScopeBase<Field, IRecord, IValues> & IScopeContext & Scope;
|
|
734
|
+
|
|
735
|
+
/**
|
|
736
|
+
* 校验 properties 的取值。
|
|
737
|
+
* 参数类型使用 `Properties & ValidateSchemaProperties<Properties>`,
|
|
738
|
+
* 既保留 creator 的 Value 推导,又能约束非法取值。
|
|
739
|
+
*/
|
|
740
|
+
export declare type ValidateSchemaProperties<P> = {
|
|
741
|
+
[K in keyof P]: P[K] extends SchemaCreatorLike | ISchema | null | undefined ? P[K] : never;
|
|
742
|
+
};
|
|
743
|
+
|
|
744
|
+
export declare interface VoidFragment<V extends FragmentPropsMap, Scope extends object = {}, DefaultDecorator extends AnyComponent<V> = ComponentName<V>> {
|
|
745
|
+
/**
|
|
746
|
+
* 显式声明记录类型与字段级 Scope,properties 中的子级自动继承:
|
|
747
|
+
* - 子级 reactions 的 `$record` 收敛为 Record
|
|
748
|
+
* - 子级未显式声明 Scope 时继承 FieldScope
|
|
749
|
+
* Record 默认 never 配合 Guard,保证不传泛型时由下方的推断 overload 接管。
|
|
750
|
+
*/
|
|
751
|
+
<Record extends object = never, FieldScope extends object = Scope, Component extends AnyComponent<V> = ComponentName<V>, Decorator extends AnyComponent<V> = DefaultDecorator>(properties: ExplicitTypeArgGuard<Record, SchemaPropertiesContext<Record, FieldScope>>, schema?: VoidSchema<V, Component, Decorator, Record, FieldScope>): VoidSchemaCreator<Record, FieldScope>;
|
|
752
|
+
<Properties extends Record<string, unknown>, Component extends AnyComponent<V> = ComponentName<V>, Decorator extends AnyComponent<V> = DefaultDecorator>(properties: Properties & ValidateSchemaProperties<Properties>, schema?: VoidSchema<V, Component, Decorator, any, Scope>): VoidSchemaCreator<SchemaPropertiesValues<Properties>, any, SchemaPropertiesValues<Properties>>;
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
export declare interface VoidFragmentItem<V extends FragmentPropsMap, K extends ComponentName<V>, Scope extends object = {}, DefaultDecorator extends AnyComponent<V> = ComponentName<V>> {
|
|
756
|
+
<Value = any, Decorator extends AnyComponent<V> = DefaultDecorator, FieldScope extends object = Scope, IRecord extends object = any>(schema?: Omit<VoidSchema<V, K, Decorator, IRecord, FieldScope>, 'type' | 'component'>): VoidSchemaCreator<IRecord, FieldScope, Value>;
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
export declare type VoidFragmentMapping<V extends FragmentPropsMap, Scope extends object = {}, DefaultDecorator extends AnyComponent<V> = ComponentName<V>> = {
|
|
760
|
+
[K in ComponentName<V>]: VoidFragmentItem<V, K, Scope, DefaultDecorator>;
|
|
761
|
+
};
|
|
762
|
+
|
|
763
|
+
export declare type VoidSchema<V extends FragmentPropsMap, Component extends AnyComponent<V> = ComponentName<V>, Decorator extends AnyComponent<V> = ComponentName<V>, IRecord extends object = any, Scope extends object = {}, IValues extends object = any> = Omit<ISchema, SchemaOverrideKeys | 'properties'> & {
|
|
764
|
+
component?: Component | SchemaExpression;
|
|
765
|
+
componentProps?: ExpressionProps<TComponentProps<V, Component>>;
|
|
766
|
+
decorator?: Decorator | SchemaExpression;
|
|
767
|
+
decoratorProps?: ExpressionProps<TComponentProps<V, Decorator>>;
|
|
768
|
+
properties?: SchemaPropertiesInput;
|
|
769
|
+
reactions?: SchemaReactions<VoidField<TComponentProps<V, Component>, TComponentProps<V, Decorator>, IRecord>, Scope, IRecord, IValues>;
|
|
770
|
+
};
|
|
771
|
+
|
|
772
|
+
export declare interface VoidSchemaCreator<IRecord extends object = any, IScope = any, IValues = any> {
|
|
773
|
+
(patches?: SchemaPatchInput | SchemaPatchInput[]): ISchema;
|
|
774
|
+
/** 仅用于类型标记,请勿使用 */
|
|
775
|
+
_$types$_: [IRecord, IScope, IValues];
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
export { }
|