@djvlc/contracts-types 1.8.0 → 1.8.2
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.mts +306 -218
- package/dist/index.d.ts +306 -218
- package/dist/index.js +120 -31
- package/dist/index.mjs +116 -25
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -641,7 +641,7 @@ interface PageConfig {
|
|
|
641
641
|
* 页面级状态定义
|
|
642
642
|
*
|
|
643
643
|
* @description
|
|
644
|
-
*
|
|
644
|
+
* 状态管理采用扁平化设计,所有状态集中在页面级。
|
|
645
645
|
* 组件通过表达式引用状态:{ type: "state", value: "userInfo.name" }
|
|
646
646
|
*/
|
|
647
647
|
interface PageState {
|
|
@@ -825,22 +825,110 @@ interface ExpressionValidationWarning {
|
|
|
825
825
|
|
|
826
826
|
/**
|
|
827
827
|
* 表达式系统类型
|
|
828
|
+
*
|
|
829
|
+
* @description
|
|
830
|
+
* 表达式是低代码平台的核心能力之一,用于实现数据绑定和动态计算。
|
|
831
|
+
*
|
|
832
|
+
* 核心设计:
|
|
833
|
+
* - 命名一致性:表达式类型 'local'、依赖前缀 'local'、上下文字段 'local' 完全一致
|
|
834
|
+
* - meta.dependencies 格式统一(都使用 prefix.path 格式)
|
|
835
|
+
* - 泛型版本 ExpressionContextTyped 支持精确类型提示
|
|
836
|
+
* - 所有上下文类型使用 DeepReadonly 包装(防止引擎意外修改)
|
|
828
837
|
*/
|
|
829
838
|
|
|
839
|
+
/**
|
|
840
|
+
* 依赖路径前缀
|
|
841
|
+
*
|
|
842
|
+
* @description
|
|
843
|
+
* 用于 meta.dependencies 的统一格式:`${PREFIX}.${path}`
|
|
844
|
+
* 确保静态校验时能准确识别依赖来源。
|
|
845
|
+
*/
|
|
846
|
+
declare const DEPENDENCY_PREFIX: {
|
|
847
|
+
/** 页面状态依赖前缀 */
|
|
848
|
+
readonly STATE: "state";
|
|
849
|
+
/** 数据绑定依赖前缀 */
|
|
850
|
+
readonly BINDING: "binding";
|
|
851
|
+
/** 局部变量依赖前缀 */
|
|
852
|
+
readonly LOCAL: "local";
|
|
853
|
+
/** 组件属性依赖前缀 */
|
|
854
|
+
readonly PROPS: "props";
|
|
855
|
+
/** 事件上下文依赖前缀 */
|
|
856
|
+
readonly EVENT: "event";
|
|
857
|
+
};
|
|
858
|
+
/**
|
|
859
|
+
* 依赖路径前缀类型
|
|
860
|
+
*/
|
|
861
|
+
type DependencyPrefix = (typeof DEPENDENCY_PREFIX)[keyof typeof DEPENDENCY_PREFIX];
|
|
830
862
|
/**
|
|
831
863
|
* 表达式类型
|
|
832
864
|
*
|
|
833
865
|
* @description
|
|
834
|
-
*
|
|
835
|
-
* -
|
|
836
|
-
* -
|
|
837
|
-
* -
|
|
838
|
-
* -
|
|
866
|
+
* 支持的表达式类型:
|
|
867
|
+
* - state: 页面状态引用
|
|
868
|
+
* - binding: 数据绑定结果引用
|
|
869
|
+
* - local: 局部变量引用(循环变量、事件参数等)
|
|
870
|
+
* - template: 模板字符串插值
|
|
871
|
+
* - computed: 计算表达式
|
|
872
|
+
*/
|
|
873
|
+
type ExpressionType = 'state' | 'binding' | 'local' | 'template' | 'computed';
|
|
874
|
+
/**
|
|
875
|
+
* 表达式依赖项
|
|
876
|
+
*
|
|
877
|
+
* @description
|
|
878
|
+
* 统一格式的依赖路径,格式为 `${prefix}.${path}`
|
|
879
|
+
* 例如:'state.count'、'binding.userList.0.name'、'local.item.id'
|
|
880
|
+
*
|
|
881
|
+
* @example
|
|
882
|
+
* ```typescript
|
|
883
|
+
* const deps: ExpressionDependency[] = [
|
|
884
|
+
* 'state.count', // 页面状态
|
|
885
|
+
* 'binding.users.0.name', // 数据绑定结果
|
|
886
|
+
* 'local.item.price', // 循环变量
|
|
887
|
+
* 'event.payload.id', // 事件参数
|
|
888
|
+
* ];
|
|
889
|
+
* ```
|
|
890
|
+
*/
|
|
891
|
+
type ExpressionDependency = `${DependencyPrefix}.${string}`;
|
|
892
|
+
/**
|
|
893
|
+
* 创建类型安全的依赖路径
|
|
894
|
+
*
|
|
895
|
+
* @description
|
|
896
|
+
* 避免在代码中频繁使用 `as ExpressionDependency` 强转。
|
|
897
|
+
* 提供类型安全的依赖路径创建方式。
|
|
898
|
+
*
|
|
899
|
+
* @example
|
|
900
|
+
* ```typescript
|
|
901
|
+
* dep('state', 'count') // => 'state.count'
|
|
902
|
+
* dep('binding', 'users.0.name') // => 'binding.users.0.name'
|
|
903
|
+
* dep('local', 'item.id') // => 'local.item.id'
|
|
904
|
+
* ```
|
|
905
|
+
*/
|
|
906
|
+
declare function dep(prefix: DependencyPrefix, path: string): ExpressionDependency;
|
|
907
|
+
/**
|
|
908
|
+
* 表达式元数据
|
|
839
909
|
*
|
|
840
|
-
*
|
|
841
|
-
*
|
|
910
|
+
* @description
|
|
911
|
+
* 用于发布期静态校验和依赖追踪。
|
|
912
|
+
* 所有依赖路径都使用统一的 `prefix.path` 格式。
|
|
842
913
|
*/
|
|
843
|
-
|
|
914
|
+
interface ExpressionMeta {
|
|
915
|
+
/**
|
|
916
|
+
* 引用的依赖路径
|
|
917
|
+
*
|
|
918
|
+
* @description
|
|
919
|
+
* 统一格式:`${type}.${path}`
|
|
920
|
+
* - state.xxx - 页面状态
|
|
921
|
+
* - binding.xxx - 数据绑定结果
|
|
922
|
+
* - local.xxx - 局部变量(循环/事件)
|
|
923
|
+
* - props.xxx - 组件属性
|
|
924
|
+
* - event.xxx - 事件上下文
|
|
925
|
+
*/
|
|
926
|
+
dependencies?: ExpressionDependency[];
|
|
927
|
+
/** 期望的返回类型 */
|
|
928
|
+
returnType?: 'string' | 'number' | 'boolean' | 'array' | 'object' | 'any';
|
|
929
|
+
/** 是否为纯表达式(无副作用) */
|
|
930
|
+
pure?: boolean;
|
|
931
|
+
}
|
|
844
932
|
/**
|
|
845
933
|
* 表达式定义
|
|
846
934
|
*
|
|
@@ -856,83 +944,27 @@ interface Expression {
|
|
|
856
944
|
/** 默认值(表达式执行失败时使用) */
|
|
857
945
|
fallback?: JsonValue;
|
|
858
946
|
/** 表达式元数据(用于发布期校验) */
|
|
859
|
-
meta?:
|
|
860
|
-
/** 引用的字段路径 */
|
|
861
|
-
dependencies?: string[];
|
|
862
|
-
/** 期望的返回类型 */
|
|
863
|
-
returnType?: string;
|
|
864
|
-
};
|
|
947
|
+
meta?: ExpressionMeta;
|
|
865
948
|
}
|
|
866
949
|
/**
|
|
867
|
-
*
|
|
950
|
+
* 深度只读类型
|
|
868
951
|
*
|
|
869
952
|
* @description
|
|
870
|
-
*
|
|
871
|
-
*
|
|
872
|
-
*
|
|
873
|
-
* 使用场景:
|
|
874
|
-
* - Runtime 表达式求值
|
|
875
|
-
* - 编辑器表达式预览
|
|
876
|
-
* - 表达式校验与调试
|
|
877
|
-
*
|
|
878
|
-
* @example
|
|
879
|
-
* ```typescript
|
|
880
|
-
* const ctx: ExpressionContext = {
|
|
881
|
-
* state: { count: 0, userInfo: { name: 'Alice' } },
|
|
882
|
-
* binding: { userList: [{ id: 1, name: 'Bob' }] },
|
|
883
|
-
* context: { item: { id: 1, name: 'Bob' }, index: 0 },
|
|
884
|
-
* };
|
|
885
|
-
*
|
|
886
|
-
* // 求值 { type: 'state', value: 'userInfo.name' } => 'Alice'
|
|
887
|
-
* // 求值 { type: 'context', value: 'item.name' } => 'Bob'
|
|
888
|
-
* ```
|
|
953
|
+
* 将对象及其所有嵌套属性标记为只读,
|
|
954
|
+
* 防止表达式引擎在求值过程中意外修改上下文。
|
|
955
|
+
* 函数类型保持原样(不变成 object)。
|
|
889
956
|
*/
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
*
|
|
894
|
-
* @description
|
|
895
|
-
* 对应 PageState.fields 的运行时值。
|
|
896
|
-
* 表达式通过 { type: 'state', value: 'fieldName.path' } 访问。
|
|
897
|
-
*/
|
|
898
|
-
state: Record<string, unknown>;
|
|
899
|
-
/**
|
|
900
|
-
* 数据绑定结果
|
|
901
|
-
*
|
|
902
|
-
* @description
|
|
903
|
-
* 对应 DataBinding 查询的返回数据,按 bindingId 组织。
|
|
904
|
-
* 表达式通过 { type: 'binding', value: 'bindingId.path' } 访问。
|
|
905
|
-
*/
|
|
906
|
-
binding: Record<string, unknown>;
|
|
907
|
-
/**
|
|
908
|
-
* 局部上下文
|
|
909
|
-
*
|
|
910
|
-
* @description
|
|
911
|
-
* 包含循环变量、事件参数等临时作用域数据。
|
|
912
|
-
* 表达式通过 { type: 'context', value: 'item.path' } 访问。
|
|
913
|
-
*/
|
|
914
|
-
context: ExpressionLocalContext;
|
|
915
|
-
/**
|
|
916
|
-
* 组件属性(可选)
|
|
917
|
-
*
|
|
918
|
-
* @description
|
|
919
|
-
* 当前组件的 props 值,供组件内部表达式访问。
|
|
920
|
-
* 通常在组件内部求值时提供。
|
|
921
|
-
*/
|
|
922
|
-
props?: Record<string, unknown>;
|
|
923
|
-
/**
|
|
924
|
-
* 当前事件(可选)
|
|
925
|
-
*
|
|
926
|
-
* @description
|
|
927
|
-
* 事件处理器执行时的事件对象。
|
|
928
|
-
* 仅在事件处理链中可用。
|
|
929
|
-
*/
|
|
930
|
-
event?: ExpressionEventContext;
|
|
931
|
-
}
|
|
957
|
+
type DeepReadonly<T> = T extends (...args: unknown[]) => unknown ? T : T extends (infer U)[] ? ReadonlyArray<DeepReadonly<U>> : T extends object ? {
|
|
958
|
+
readonly [K in keyof T]: DeepReadonly<T[K]>;
|
|
959
|
+
} : T;
|
|
932
960
|
/**
|
|
933
|
-
*
|
|
961
|
+
* 局部变量(循环变量、事件参数等)
|
|
962
|
+
*
|
|
963
|
+
* @description
|
|
964
|
+
* 命名与表达式类型 'local' 和依赖前缀 'local' 保持一致,
|
|
965
|
+
* 避免引擎实现时的命名混淆。
|
|
934
966
|
*/
|
|
935
|
-
interface
|
|
967
|
+
interface ExpressionLocal {
|
|
936
968
|
/**
|
|
937
969
|
* 循环项(loop.itemName 指定的变量名)
|
|
938
970
|
*
|
|
@@ -973,6 +1005,107 @@ interface ExpressionEventContext {
|
|
|
973
1005
|
keyCode?: number;
|
|
974
1006
|
};
|
|
975
1007
|
}
|
|
1008
|
+
/**
|
|
1009
|
+
* 表达式求值上下文(泛型版本)
|
|
1010
|
+
*
|
|
1011
|
+
* @description
|
|
1012
|
+
* 支持精确类型提示的表达式上下文。
|
|
1013
|
+
* 业务层可以通过泛型参数指定具体的状态、绑定、属性类型。
|
|
1014
|
+
*
|
|
1015
|
+
* @template TState - 页面状态类型
|
|
1016
|
+
* @template TBinding - 数据绑定结果类型
|
|
1017
|
+
* @template TProps - 组件属性类型
|
|
1018
|
+
* @template TLocal - 局部变量类型
|
|
1019
|
+
*
|
|
1020
|
+
* @example
|
|
1021
|
+
* ```typescript
|
|
1022
|
+
* interface MyState {
|
|
1023
|
+
* count: number;
|
|
1024
|
+
* userInfo: { name: string; age: number };
|
|
1025
|
+
* }
|
|
1026
|
+
*
|
|
1027
|
+
* interface MyBinding {
|
|
1028
|
+
* userList: Array<{ id: string; name: string }>;
|
|
1029
|
+
* }
|
|
1030
|
+
*
|
|
1031
|
+
* const ctx: ExpressionContextTyped<MyState, MyBinding> = {
|
|
1032
|
+
* state: { count: 0, userInfo: { name: 'Alice', age: 25 } },
|
|
1033
|
+
* binding: { userList: [{ id: '1', name: 'Bob' }] },
|
|
1034
|
+
* local: { item: { id: '1', name: 'Bob' }, index: 0 },
|
|
1035
|
+
* };
|
|
1036
|
+
*
|
|
1037
|
+
* // ctx.state.userInfo.name 有类型提示
|
|
1038
|
+
* ```
|
|
1039
|
+
*/
|
|
1040
|
+
interface ExpressionContextTyped<TState extends Record<string, unknown> = Record<string, unknown>, TBinding extends Record<string, unknown> = Record<string, unknown>, TProps extends Record<string, unknown> = Record<string, unknown>, TLocal extends ExpressionLocal = ExpressionLocal> {
|
|
1041
|
+
/**
|
|
1042
|
+
* 页面状态(只读)
|
|
1043
|
+
*
|
|
1044
|
+
* @description
|
|
1045
|
+
* 对应 PageState.fields 的运行时值。
|
|
1046
|
+
* 表达式通过 { type: 'state', value: 'fieldName.path' } 访问。
|
|
1047
|
+
*/
|
|
1048
|
+
readonly state: DeepReadonly<TState>;
|
|
1049
|
+
/**
|
|
1050
|
+
* 数据绑定结果(只读)
|
|
1051
|
+
*
|
|
1052
|
+
* @description
|
|
1053
|
+
* 对应 DataBinding 查询的返回数据,按 bindingId 组织。
|
|
1054
|
+
* 表达式通过 { type: 'binding', value: 'bindingId.path' } 访问。
|
|
1055
|
+
*/
|
|
1056
|
+
readonly binding: DeepReadonly<TBinding>;
|
|
1057
|
+
/**
|
|
1058
|
+
* 局部变量(只读)
|
|
1059
|
+
*
|
|
1060
|
+
* @description
|
|
1061
|
+
* 包含循环变量、事件参数等临时作用域数据。
|
|
1062
|
+
* 字段名与表达式类型 'local' 和依赖前缀 'local' 保持一致。
|
|
1063
|
+
* 表达式通过 { type: 'local', value: 'item.path' } 访问。
|
|
1064
|
+
*/
|
|
1065
|
+
readonly local: DeepReadonly<TLocal>;
|
|
1066
|
+
/**
|
|
1067
|
+
* 组件属性(只读,可选)
|
|
1068
|
+
*
|
|
1069
|
+
* @description
|
|
1070
|
+
* 当前组件的 props 值,供组件内部表达式访问。
|
|
1071
|
+
* 通常在组件内部求值时提供。
|
|
1072
|
+
*/
|
|
1073
|
+
readonly props?: DeepReadonly<TProps>;
|
|
1074
|
+
/**
|
|
1075
|
+
* 当前事件(只读,可选)
|
|
1076
|
+
*
|
|
1077
|
+
* @description
|
|
1078
|
+
* 事件处理器执行时的事件对象。
|
|
1079
|
+
* 仅在事件处理链中可用。
|
|
1080
|
+
*/
|
|
1081
|
+
readonly event?: DeepReadonly<ExpressionEventContext>;
|
|
1082
|
+
}
|
|
1083
|
+
/**
|
|
1084
|
+
* 表达式求值上下文(基础版本)
|
|
1085
|
+
*
|
|
1086
|
+
* @description
|
|
1087
|
+
* 表达式引擎在求值时可访问的上下文对象。
|
|
1088
|
+
* 所有动态表达式(state/binding/local/template/computed)都从此上下文获取数据。
|
|
1089
|
+
*
|
|
1090
|
+
* 使用场景:
|
|
1091
|
+
* - Runtime 表达式求值
|
|
1092
|
+
* - 编辑器表达式预览
|
|
1093
|
+
* - 表达式校验与调试
|
|
1094
|
+
*
|
|
1095
|
+
* @example
|
|
1096
|
+
* ```typescript
|
|
1097
|
+
* const ctx: ExpressionContext = {
|
|
1098
|
+
* state: { count: 0, userInfo: { name: 'Alice' } },
|
|
1099
|
+
* binding: { userList: [{ id: 1, name: 'Bob' }] },
|
|
1100
|
+
* local: { item: { id: 1, name: 'Bob' }, index: 0 },
|
|
1101
|
+
* };
|
|
1102
|
+
*
|
|
1103
|
+
* // 求值 { type: 'state', value: 'userInfo.name' } => 'Alice'
|
|
1104
|
+
* // 求值 { type: 'local', value: 'item.name' } => 'Bob'
|
|
1105
|
+
* ```
|
|
1106
|
+
*/
|
|
1107
|
+
interface ExpressionContext extends ExpressionContextTyped<Record<string, unknown>, Record<string, unknown>, Record<string, unknown>, ExpressionLocal> {
|
|
1108
|
+
}
|
|
976
1109
|
/**
|
|
977
1110
|
* 任意值或表达式
|
|
978
1111
|
*
|
|
@@ -983,55 +1116,94 @@ interface ExpressionEventContext {
|
|
|
983
1116
|
type AnyValueOrExpression = Expression | string | number | boolean | null | AnyValueOrExpression[] | {
|
|
984
1117
|
[key: string]: AnyValueOrExpression;
|
|
985
1118
|
};
|
|
986
|
-
/**
|
|
987
|
-
* 属性值类型(兼容旧版本)
|
|
988
|
-
* @deprecated 使用 AnyValueOrExpression 代替
|
|
989
|
-
*/
|
|
990
|
-
type PropValue = AnyValueOrExpression;
|
|
991
1119
|
/**
|
|
992
1120
|
* 创建空的表达式上下文
|
|
993
1121
|
*
|
|
994
1122
|
* @description
|
|
995
1123
|
* 用于初始化表达式求值环境,所有字段都有合理的默认值。
|
|
996
1124
|
*/
|
|
997
|
-
declare function createExpressionContext(partial?: Partial<
|
|
1125
|
+
declare function createExpressionContext(partial?: Partial<{
|
|
1126
|
+
state: Record<string, unknown>;
|
|
1127
|
+
binding: Record<string, unknown>;
|
|
1128
|
+
local: ExpressionLocal;
|
|
1129
|
+
props: Record<string, unknown>;
|
|
1130
|
+
event: ExpressionEventContext;
|
|
1131
|
+
}>): ExpressionContext;
|
|
998
1132
|
/**
|
|
999
|
-
*
|
|
1133
|
+
* 创建带循环变量的局部变量
|
|
1000
1134
|
*
|
|
1001
1135
|
* @param item - 当前循环项
|
|
1002
1136
|
* @param index - 当前循环索引
|
|
1003
1137
|
* @param extras - 额外的局部变量(如嵌套循环)
|
|
1004
1138
|
*/
|
|
1005
|
-
declare function
|
|
1006
|
-
/**
|
|
1007
|
-
* 创建字面量表达式
|
|
1008
|
-
* @deprecated V2 版本移除 literal 表达式类型,静态值请直接使用原始类型
|
|
1009
|
-
*
|
|
1010
|
-
* @example
|
|
1011
|
-
* // 旧方式(V1)
|
|
1012
|
-
* props: { title: literal("Hello") }
|
|
1013
|
-
*
|
|
1014
|
-
* // 新方式(V2)
|
|
1015
|
-
* props: { title: "Hello" }
|
|
1016
|
-
*/
|
|
1017
|
-
declare function literal(value: JsonValue): JsonValue;
|
|
1139
|
+
declare function createLoopLocal(item: unknown, index: number, extras?: Record<string, unknown>): ExpressionLocal;
|
|
1018
1140
|
/**
|
|
1019
1141
|
* 创建状态引用表达式
|
|
1020
1142
|
*/
|
|
1021
1143
|
declare function stateRef(path: string, fallback?: JsonValue): Expression;
|
|
1022
1144
|
/**
|
|
1023
1145
|
* 创建数据绑定结果引用表达式
|
|
1146
|
+
*
|
|
1147
|
+
* @throws 如果 bindingId 包含非法字符(如 '.')
|
|
1024
1148
|
*/
|
|
1025
1149
|
declare function bindingRef(bindingId: string, path: string, fallback?: JsonValue): Expression;
|
|
1026
1150
|
/**
|
|
1027
|
-
*
|
|
1151
|
+
* 创建局部变量引用表达式
|
|
1152
|
+
*
|
|
1153
|
+
* @description
|
|
1154
|
+
* 用于引用循环变量、事件参数等局部作用域数据。
|
|
1155
|
+
*
|
|
1156
|
+
* @example
|
|
1157
|
+
* ```typescript
|
|
1158
|
+
* // 在循环中引用当前项
|
|
1159
|
+
* localRef('item.name')
|
|
1160
|
+
* // => { type: 'local', value: 'item.name', meta: { dependencies: ['local.item.name'] } }
|
|
1161
|
+
* ```
|
|
1028
1162
|
*/
|
|
1029
|
-
declare function
|
|
1163
|
+
declare function localRef(path: string, fallback?: JsonValue): Expression;
|
|
1164
|
+
/**
|
|
1165
|
+
* 模板解析模式
|
|
1166
|
+
*
|
|
1167
|
+
* @description
|
|
1168
|
+
* - 'strict': 严格模式,无前缀变量会抛出错误
|
|
1169
|
+
*/
|
|
1170
|
+
type TemplateParseMode = 'strict';
|
|
1030
1171
|
/**
|
|
1031
|
-
*
|
|
1032
|
-
* @deprecated 使用 bindingRef 代替
|
|
1172
|
+
* 模板解析错误
|
|
1033
1173
|
*/
|
|
1034
|
-
declare
|
|
1174
|
+
declare class TemplateParseError extends Error {
|
|
1175
|
+
readonly bareVariables: string[];
|
|
1176
|
+
readonly expression: string;
|
|
1177
|
+
constructor(message: string, bareVariables: string[], expression: string);
|
|
1178
|
+
}
|
|
1179
|
+
/**
|
|
1180
|
+
* 创建模板表达式
|
|
1181
|
+
*
|
|
1182
|
+
* @description
|
|
1183
|
+
* 模板中的变量引用会自动解析并提取依赖。
|
|
1184
|
+
* 变量必须使用完整前缀(state./binding./local./props./event.)
|
|
1185
|
+
*
|
|
1186
|
+
* @throws {TemplateParseError} 检测到无前缀变量(如 ${count} 应改为 ${state.count})
|
|
1187
|
+
*
|
|
1188
|
+
* @example
|
|
1189
|
+
* ```typescript
|
|
1190
|
+
* // 使用完整路径
|
|
1191
|
+
* template("Hello, ${state.userName}!")
|
|
1192
|
+
* // => dependencies: ['state.userName']
|
|
1193
|
+
*
|
|
1194
|
+
* // 数组索引访问
|
|
1195
|
+
* template("First user: ${binding.users[0].name}")
|
|
1196
|
+
* // => dependencies: ['binding.users[0].name']
|
|
1197
|
+
*
|
|
1198
|
+
* // 表达式中提取多个变量
|
|
1199
|
+
* template("Total: ${state.count + state.offset}")
|
|
1200
|
+
* // => dependencies: ['state.count', 'state.offset']
|
|
1201
|
+
*
|
|
1202
|
+
* // 错误示例(会抛出 TemplateParseError)
|
|
1203
|
+
* template("Count: ${count}") // ❌ 应使用 ${state.count}
|
|
1204
|
+
* ```
|
|
1205
|
+
*/
|
|
1206
|
+
declare function template(templateString: string, fallback?: JsonValue): Expression;
|
|
1035
1207
|
|
|
1036
1208
|
/**
|
|
1037
1209
|
* 数据绑定类型
|
|
@@ -1067,7 +1239,7 @@ interface DataBindingErrorConfig {
|
|
|
1067
1239
|
* 数据绑定配置
|
|
1068
1240
|
*
|
|
1069
1241
|
* @description
|
|
1070
|
-
*
|
|
1242
|
+
* 数据绑定集中在页面级管理。
|
|
1071
1243
|
* targetState 为必填字段,绑定结果会写入对应的状态字段。
|
|
1072
1244
|
*/
|
|
1073
1245
|
interface DataBinding {
|
|
@@ -1108,8 +1280,8 @@ interface DataBinding {
|
|
|
1108
1280
|
* 内置动作类型
|
|
1109
1281
|
*
|
|
1110
1282
|
* @description
|
|
1111
|
-
*
|
|
1112
|
-
* copyToClipboard、scrollTo
|
|
1283
|
+
* 预置的简单动作类型,不需要通过 ActionDefinition 定义。
|
|
1284
|
+
* copyToClipboard、scrollTo 等复杂操作通过自定义 Action 实现。
|
|
1113
1285
|
*/
|
|
1114
1286
|
type BuiltinActionType = 'setState' | 'navigate' | 'openDialog' | 'closeDialog' | 'showToast' | 'showLoading' | 'hideLoading' | 'refreshData' | 'track';
|
|
1115
1287
|
/**
|
|
@@ -1132,16 +1304,12 @@ interface ActionPolicy {
|
|
|
1132
1304
|
* 动作引用
|
|
1133
1305
|
*
|
|
1134
1306
|
* @description
|
|
1135
|
-
*
|
|
1136
|
-
*
|
|
1137
|
-
* - 新增 id 用于追踪
|
|
1138
|
-
* - 新增 policy 用于超时、重试、幂等控制
|
|
1139
|
-
* - 新增 condition 用于条件执行
|
|
1140
|
-
* - 新增 async 用于并行/串行控制
|
|
1307
|
+
* 定义一个动作的执行配置,必须指定 actionDefinitionVersionId 或 builtinAction 之一。
|
|
1308
|
+
* 支持超时、重试、幂等控制、条件执行、并行/串行控制等能力。
|
|
1141
1309
|
*/
|
|
1142
1310
|
interface ActionRef {
|
|
1143
|
-
/** 动作唯一 ID
|
|
1144
|
-
id
|
|
1311
|
+
/** 动作唯一 ID(用于全链路追踪,必填) */
|
|
1312
|
+
id: string;
|
|
1145
1313
|
/** 动作别名(用于调试) */
|
|
1146
1314
|
alias?: string;
|
|
1147
1315
|
/** 动作定义版本 ID(引用 ActionDefinition) */
|
|
@@ -1209,7 +1377,7 @@ interface EventHandler {
|
|
|
1209
1377
|
* 页面生命周期钩子
|
|
1210
1378
|
*
|
|
1211
1379
|
* @description
|
|
1212
|
-
*
|
|
1380
|
+
* 定义页面级生命周期事件。
|
|
1213
1381
|
* onScroll、onResize 通过组件内部或扩展实现。
|
|
1214
1382
|
*/
|
|
1215
1383
|
interface PageLifecycle {
|
|
@@ -1260,8 +1428,7 @@ interface LayoutConfig extends LayoutValues {
|
|
|
1260
1428
|
* 节点样式配置
|
|
1261
1429
|
*
|
|
1262
1430
|
* @description
|
|
1263
|
-
*
|
|
1264
|
-
* V2 版本移除了 responsive,响应式通过 condition 或 CSS 层面处理。
|
|
1431
|
+
* 组件节点的样式配置,响应式通过 condition 或 CSS 层面处理。
|
|
1265
1432
|
*/
|
|
1266
1433
|
interface NodeStyleConfig {
|
|
1267
1434
|
/** 内联样式(支持表达式) */
|
|
@@ -1286,14 +1453,12 @@ interface LoopConfig {
|
|
|
1286
1453
|
* 组件节点(组件树的基本单元)
|
|
1287
1454
|
*
|
|
1288
1455
|
* @description
|
|
1289
|
-
*
|
|
1290
|
-
* -
|
|
1291
|
-
* -
|
|
1292
|
-
* -
|
|
1293
|
-
* -
|
|
1294
|
-
* -
|
|
1295
|
-
* - 新增 slotName(声明当前节点所属插槽)
|
|
1296
|
-
* - props 支持表达式类型
|
|
1456
|
+
* 定义组件树中的基本渲染单元:
|
|
1457
|
+
* - 状态管理在页面级统一管理
|
|
1458
|
+
* - 数据绑定集中在 pageSchema.dataBindings
|
|
1459
|
+
* - 支持 layout(画布式自由定位)
|
|
1460
|
+
* - 支持 slots(具名插槽)
|
|
1461
|
+
* - props 支持静态值或表达式
|
|
1297
1462
|
*/
|
|
1298
1463
|
interface ComponentNode {
|
|
1299
1464
|
/** 节点唯一 ID(页面内唯一) */
|
|
@@ -1310,11 +1475,6 @@ interface ComponentNode {
|
|
|
1310
1475
|
style?: NodeStyleConfig;
|
|
1311
1476
|
/** 布局配置(画布式自由定位) */
|
|
1312
1477
|
layout?: LayoutConfig;
|
|
1313
|
-
/**
|
|
1314
|
-
* 默认子节点(向后兼容)
|
|
1315
|
-
* @deprecated 建议使用 slots.default 代替
|
|
1316
|
-
*/
|
|
1317
|
-
children?: ComponentNode[];
|
|
1318
1478
|
/**
|
|
1319
1479
|
* 具名插槽(推荐使用)
|
|
1320
1480
|
* @description
|
|
@@ -1375,7 +1535,7 @@ declare const CURRENT_SCHEMA_VERSION = "2.0.0";
|
|
|
1375
1535
|
/**
|
|
1376
1536
|
* Schema 版本类型
|
|
1377
1537
|
*/
|
|
1378
|
-
type SchemaVersion = typeof CURRENT_SCHEMA_VERSION
|
|
1538
|
+
type SchemaVersion = typeof CURRENT_SCHEMA_VERSION;
|
|
1379
1539
|
/**
|
|
1380
1540
|
* 页面 Schema Runtime Core(不可变版本的核心结构)
|
|
1381
1541
|
*
|
|
@@ -2378,41 +2538,6 @@ interface PageResolveWithSnapshotResponse extends PageResolveResponse {
|
|
|
2378
2538
|
/** 完整的页面快照(CDN 失败时使用) */
|
|
2379
2539
|
snapshot: PageSnapshotJson;
|
|
2380
2540
|
}
|
|
2381
|
-
/**
|
|
2382
|
-
* 页面解析响应(旧版本)
|
|
2383
|
-
* @deprecated 使用 PageResolveResponse 代替
|
|
2384
|
-
*/
|
|
2385
|
-
interface LegacyPageResolveResponse {
|
|
2386
|
-
/** 页面版本 ID */
|
|
2387
|
-
pageVersionId: UniqueId;
|
|
2388
|
-
/** 页面 Schema */
|
|
2389
|
-
schema: PageSchema;
|
|
2390
|
-
/** 组件清单 */
|
|
2391
|
-
manifest: Manifest;
|
|
2392
|
-
/** 运行时配置 */
|
|
2393
|
-
runtimeConfig: RuntimeConfig;
|
|
2394
|
-
/** 预加载的数据 */
|
|
2395
|
-
preloadedData?: Record<string, JsonValue>;
|
|
2396
|
-
}
|
|
2397
|
-
/**
|
|
2398
|
-
* 运行时配置(旧版本)
|
|
2399
|
-
* @deprecated 使用 OpsConfig 代替
|
|
2400
|
-
*/
|
|
2401
|
-
interface RuntimeConfig {
|
|
2402
|
-
/** 推荐的运行时版本 */
|
|
2403
|
-
runtimeVersion: SemVer;
|
|
2404
|
-
/** CDN 基础 URL */
|
|
2405
|
-
cdnBaseUrl: string;
|
|
2406
|
-
/** 被阻断的组件列表 */
|
|
2407
|
-
blockedComponents: string[];
|
|
2408
|
-
/** Kill Switch 状态 */
|
|
2409
|
-
killSwitch?: {
|
|
2410
|
-
enabled: boolean;
|
|
2411
|
-
message?: string;
|
|
2412
|
-
};
|
|
2413
|
-
/** 功能开关 */
|
|
2414
|
-
features?: Record<string, boolean>;
|
|
2415
|
-
}
|
|
2416
2541
|
|
|
2417
2542
|
/**
|
|
2418
2543
|
* 属性 Schema 类型定义
|
|
@@ -2421,9 +2546,8 @@ interface RuntimeConfig {
|
|
|
2421
2546
|
* 属性 Schema(JSON Schema 子集 + 编辑器扩展)
|
|
2422
2547
|
*
|
|
2423
2548
|
* @description
|
|
2424
|
-
*
|
|
2425
|
-
*
|
|
2426
|
-
* - 如需允许额外属性,需显式设置 additionalProperties: true
|
|
2549
|
+
* additionalProperties 默认为 false(严格模式)。
|
|
2550
|
+
* 如需允许额外属性,需显式设置 additionalProperties: true。
|
|
2427
2551
|
*/
|
|
2428
2552
|
interface PropsSchema {
|
|
2429
2553
|
/** Schema 类型(固定为 object) */
|
|
@@ -2439,7 +2563,6 @@ interface PropsSchema {
|
|
|
2439
2563
|
/**
|
|
2440
2564
|
* 是否允许未知属性
|
|
2441
2565
|
* @default false
|
|
2442
|
-
* @description V2 版本默认 false(严格模式)
|
|
2443
2566
|
*/
|
|
2444
2567
|
additionalProperties?: boolean;
|
|
2445
2568
|
}
|
|
@@ -2464,8 +2587,7 @@ interface PropGroup {
|
|
|
2464
2587
|
* 属性定义(扩展 JSON Schema)
|
|
2465
2588
|
*
|
|
2466
2589
|
* @description
|
|
2467
|
-
*
|
|
2468
|
-
* - object 类型的 additionalProperties 默认为 false
|
|
2590
|
+
* object 类型的 additionalProperties 默认为 false。
|
|
2469
2591
|
*/
|
|
2470
2592
|
interface PropDefinition {
|
|
2471
2593
|
/** 属性类型 */
|
|
@@ -2513,7 +2635,6 @@ interface PropDefinition {
|
|
|
2513
2635
|
/**
|
|
2514
2636
|
* 额外属性定义
|
|
2515
2637
|
* @default false
|
|
2516
|
-
* @description V2 版本默认 false(严格模式)
|
|
2517
2638
|
*/
|
|
2518
2639
|
additionalProperties?: boolean | PropDefinition;
|
|
2519
2640
|
/** 编辑器组件类型 */
|
|
@@ -2945,16 +3066,11 @@ type MethodCategory = 'lifecycle' | 'data' | 'display' | 'scroll' | 'custom';
|
|
|
2945
3066
|
*/
|
|
2946
3067
|
declare const CURRENT_COMPONENT_META_VERSION: SemVer;
|
|
2947
3068
|
/**
|
|
2948
|
-
* 组件元数据
|
|
3069
|
+
* 组件元数据
|
|
2949
3070
|
*
|
|
2950
3071
|
* @description
|
|
2951
|
-
*
|
|
2952
|
-
*
|
|
2953
|
-
* - 新增 style 样式配置(包含隔离策略)
|
|
2954
|
-
* - 新增 slots 插槽声明(组件嵌套能力)
|
|
2955
|
-
* - 新增 methods 方法声明(命令式 API)
|
|
2956
|
-
* - PropsSchema.additionalProperties 默认 false
|
|
2957
|
-
* - PropDefinition.additionalProperties(object 类型)默认 false
|
|
3072
|
+
* 定义组件的完整元数据,包括属性 Schema、事件声明、能力声明、兼容性信息等。
|
|
3073
|
+
* PropsSchema 和 PropDefinition 的 additionalProperties 默认为 false(严格模式)。
|
|
2958
3074
|
*/
|
|
2959
3075
|
interface ComponentMeta {
|
|
2960
3076
|
/** 规格版本号 */
|
|
@@ -3567,19 +3683,11 @@ interface RetryPolicy {
|
|
|
3567
3683
|
*/
|
|
3568
3684
|
declare const CURRENT_ACTION_SPEC_VERSION: SemVer;
|
|
3569
3685
|
/**
|
|
3570
|
-
* 动作规格(ActionSpec)
|
|
3686
|
+
* 动作规格(ActionSpec)
|
|
3571
3687
|
*
|
|
3572
3688
|
* @description
|
|
3573
|
-
*
|
|
3574
|
-
*
|
|
3575
|
-
* V2 版本变化:
|
|
3576
|
-
* - 新增 specVersion 字段
|
|
3577
|
-
* - timeout → timeoutMs(单位明确化)
|
|
3578
|
-
* - keyTtl → keyTtlSeconds(单位明确化)
|
|
3579
|
-
* - window → windowSeconds(单位明确化)
|
|
3580
|
-
* - initialDelay → initialDelayMs(单位明确化)
|
|
3581
|
-
* - maxDelay → maxDelayMs(单位明确化)
|
|
3582
|
-
* - errorMapping key 必须符合 ^[A-Z][A-Z0-9_]{2,63}$ 格式
|
|
3689
|
+
* 定义动作的完整行为规范,包括参数校验、幂等规则、频控、风控等。
|
|
3690
|
+
* 时间相关字段均使用明确单位后缀(Ms/Seconds)。
|
|
3583
3691
|
*/
|
|
3584
3692
|
interface ActionSpec {
|
|
3585
3693
|
/** 规格版本号 */
|
|
@@ -4100,15 +4208,11 @@ interface FallbackCondition {
|
|
|
4100
4208
|
*/
|
|
4101
4209
|
declare const CURRENT_DATA_QUERY_SPEC_VERSION: SemVer;
|
|
4102
4210
|
/**
|
|
4103
|
-
* 数据查询规格
|
|
4211
|
+
* 数据查询规格
|
|
4104
4212
|
*
|
|
4105
4213
|
* @description
|
|
4106
|
-
*
|
|
4107
|
-
*
|
|
4108
|
-
* - 移除顶层 sourceType(通过 sourceConfig.type 区分)
|
|
4109
|
-
* - timeout → timeoutMs(单位明确化)
|
|
4110
|
-
* - cache.ttl → cache.ttlSeconds(单位明确化)
|
|
4111
|
-
* - cache.staleMaxAge → cache.staleMaxAgeSeconds(单位明确化)
|
|
4214
|
+
* 定义数据查询的完整行为规范,包括数据源、字段裁剪、脱敏、缓存等。
|
|
4215
|
+
* 时间相关字段均使用明确单位后缀(Ms/Seconds)。
|
|
4112
4216
|
*/
|
|
4113
4217
|
interface DataQuerySpec {
|
|
4114
4218
|
/** 规格版本号 */
|
|
@@ -4902,26 +5006,10 @@ interface VersionDiff {
|
|
|
4902
5006
|
/**
|
|
4903
5007
|
* 包版本号
|
|
4904
5008
|
*/
|
|
4905
|
-
declare const VERSION = "2.
|
|
5009
|
+
declare const VERSION = "2.0.0";
|
|
4906
5010
|
/**
|
|
4907
5011
|
* 协议版本号
|
|
4908
5012
|
*/
|
|
4909
5013
|
declare const PROTOCOL_VERSION = "2.0.0";
|
|
4910
|
-
/**
|
|
4911
|
-
* PageSchema 当前版本
|
|
4912
|
-
*/
|
|
4913
|
-
declare const PAGE_SCHEMA_VERSION = "2.0.0";
|
|
4914
|
-
/**
|
|
4915
|
-
* ComponentMeta 当前版本
|
|
4916
|
-
*/
|
|
4917
|
-
declare const COMPONENT_META_SCHEMA_VERSION = "2.0.0";
|
|
4918
|
-
/**
|
|
4919
|
-
* ActionSpec 当前版本
|
|
4920
|
-
*/
|
|
4921
|
-
declare const ACTION_SPEC_VERSION = "2.0.0";
|
|
4922
|
-
/**
|
|
4923
|
-
* DataQuerySpec 当前版本
|
|
4924
|
-
*/
|
|
4925
|
-
declare const DATA_QUERY_SPEC_VERSION = "2.0.0";
|
|
4926
5014
|
|
|
4927
|
-
export { type ABTestRolloutConfig,
|
|
5015
|
+
export { type ABTestRolloutConfig, ALLOWED_FUNCTION_NAMES, ALL_BUILTIN_FUNCTIONS, ARRAY_FUNCTIONS, type ActionClientContext, type ActionDefinition, type ActionDefinitionVersion, type ActionExecuteRequest, type ActionExecuteResponse, type ActionExecutor, type ActionPolicy, type ActionRef, type ActionResult, type ActionSheetItem, type ActionSheetOptions, type ActionSheetResult, type ActionSpec, ActionType, type Activity, type ActivityPrecondition, type ActivityRule, type ActivityStatus, type ActivityType, type AggregationDataSourceConfig, type AggregationQueryItem, type AnyValueOrExpression, type ApiErrorDetail, type ApiErrorResponse, type ApiResponse, type ApiSuccessResponse, type AppContext, AuditAction, type AuditConfig, type AuditLogEntry, type BackgroundConfig, type BaseActivityRule, type BlacklistRolloutConfig, type BlockedComponentInfo, type BlockedComponentItem, type BootstrapConfig, type BrowserCompat, type BuiltinActionType, CURRENT_ACTION_SPEC_VERSION, CURRENT_COMPONENT_META_VERSION, CURRENT_DATA_QUERY_SPEC_VERSION, CURRENT_SCHEMA_VERSION, type CacheConfig, type CacheLevel, type CanaryHealthCheck, type CanaryRolloutConfig, type CanaryStage, type CanvasType, type CapabilityDeclaration, type CapabilityName, type ChangeLog, type ChangeLogItem, type ClaimActivityRule, type ClaimPrize, type ClaimRecord, type ClaimState, type ClipboardApi, type CompatInfo, type Component, type ComponentCategory, type ComponentContext, type ComponentDependency, type ComponentIntegrity, type ComponentMeta, type ComponentNode, type ComponentQueryParams, type ComponentRegisterRequest, type ComponentStatus, type ComponentStatusChangeRequest, type ComponentVersion, type ConfirmOptions, type ConsecutiveReward, type CreateManifestRequest, type CreatePreviewTokenRequest, type CumulativeReward, DATE_FUNCTIONS, DEFAULT_EXPRESSION_VALIDATION_CONFIG, DEPENDENCY_PREFIX, type DataBinding, type DataBindingErrorConfig, type DataLoadStrategy, type DataQueryDefinition, type DataQueryDefinitionVersion, type DataQueryRequest, type DataQueryResponse, type DataQuerySpec, type DataSourceConfig, type DataSourceType, type DatabaseDataSourceConfig, type DeepReadonly, type DefinitionVersionDigest, type DefinitionsDigest, type DependencyPrefix, type DialogOptions, type DialogResult, type DjvlcError, type EditorComponent, type Environment, ErrorCategory, ErrorCode, ErrorCodeToHttpStatus, type ErrorMapping, ErrorMessages, type EventDeclaration, type EventHandler, type ExecutorContext, type ExecutorResult, type Expression, type ExpressionContext, type ExpressionContextTyped, type ExpressionDependency, type ExpressionEventContext, type ExpressionFunctionCategory, type ExpressionFunctionDefinition, type ExpressionLocal, type ExpressionMeta, type ExpressionType, type ExpressionValidationConfig, type ExpressionValidationError, type ExpressionValidationResult, type ExpressionValidationWarning, FORMAT_FUNCTIONS, type FallbackCondition, type FallbackConfig, type FeatureCondition, type FeatureRolloutConfig, type FieldPermission, type FieldPolicy, type FieldTransform, type FileIntegrity, type FunctionParamDefinition, type GraphQLDataSourceConfig, type HostApi, type HttpDataSourceConfig, type HttpRetryConfig, type I18nDetectionStrategy, type ISODateTime, type IdempotencyKeyStrategy, type IdempotencyRule, type IntegrityHash, type InternalDataSourceConfig, type InventoryConfig, type JsonObject, type JsonValue, type KillSwitchItem, LOGIC_FUNCTIONS, type LayoutConfig, type LayoutValues, type LoopConfig, type LotteryActivityRule, type LotteryCost, type LotteryPrize, type LotteryState, type Manifest, type ManifestEntry, type ManifestItem, type ManifestValidationError, type ManifestValidationResult, type ManifestValidationWarning, type MaskingConfig, type MaskingRule, type MaskingType, type MethodCategory, type MethodDeclaration, type MethodParam, NUMBER_FUNCTIONS, type NavigateOptions, type NodeStyleConfig, type OperatorInfo, type OpsConfig, type OrderByItem, PROTOCOL_VERSION, type PageAssetsJson, type PageBehaviorConfig, type PageConfig, type PageDraft, type PageI18nConfig, type PageIntegrityJson, type PageLayoutConfig, type PageLifecycle, type PageManifest, type PageMeta, type PageResolveRequest, type PageResolveResponse, type PageResolveWithSnapshotResponse, type PageSEO, type PageSchema, type PageSnapshotJson, type PageSnapshotManifest, type PageSnapshotMeta, type PageSnapshotPage, type PageState, PageStatus, type PageStatusType, type PageStylesConfig, type PageVersion, type PaginatedResponse, type PaginationMeta, type PaginationParams, type ParamPermission, type ParticipationLimit, type PercentageRolloutConfig, type PityConfig, type Precondition, type PreconditionType, type PreviewImageOptions, type PreviewToken, type PreviewTokenValidationResult, type ProbabilityConfig, type PropDefinition, type PropFormat, type PropGroup, type PropType, type PropsSchema, type PublishCdnConfig, PublishChannel, type PublishConfig, type PublishEnvironment, type PublishNotificationConfig, type PublishRecord, type PublishRolloutConfig, PublishStatus, type QueryPermissions, type RateLimitDimension, type RateLimitItem, type RateLimitRule, type RequestContext, type ResolvedManifest, type ResponsiveBreakpoints, type RetryPolicy, type RiskControlConfig, type RolloutConfig, type RolloutMatchRequest, type RolloutMatchResult, type RolloutStrategy, type RolloutStrategyConfig, type RolloutStrategyType, type RuntimeContext, type RuntimeSpec, type SHAIntegrity, STRING_FUNCTIONS, type ScanCodeResult, type SchemaVersion, type SemVer, type ShareOptions, type ShareResult, type SigninActivityRule, type SigninRecord, type SigninRewardRecord, type SigninState, type SlotCategory, type SlotDeclaration, type SnapshotComponentEntry, type StateFieldDefinition, type StorageApi, type StorageOptions, type StyleConfig, type StyleIsolation, TemplateParseError, type TemplateParseMode, type ThemeConfig, type TimeWindowRolloutConfig, type ToastOptions, type TrackEvent, type URLString, UTILITY_FUNCTIONS, type UniqueId, type UpsertRolloutRequest, type UserActivityState, type UserContext, VERSION, type ValidationRule, type VersionDiff, type VersionInfo, VersionStatus, type VersionStatusType, type ViewportConfig, type WhitelistRolloutConfig, bindingRef, createDjvlcError, createExpressionContext, createLoopLocal, dep, isDjvlcError, localRef, stateRef, template };
|