amis-model-design
Version:
amis模型设计器
144 lines (143 loc) • 7.02 kB
TypeScript
import qs from 'qs';
import { Api, FieldItem, ModelItem, RelationShipItem, ExtraField, SelectField, FeatType } from '../type';
import type { Manager } from './Manager';
import type { ApiObject } from 'amis-core';
import type { ModelStore } from './ModelStore';
export declare const normalizeField: (field: FieldItem, model: ModelItem) => FieldItem;
/**
* 将可观察类型转换为 JavaScript 类型
* @param source - 输入值
* @returns JavaScript 类型
*/
export declare const toJS: <T = any>(source: any) => T;
export declare function camelize(str: string): string;
export declare function lcfirst(str: string): string;
export declare function isRelationship(target: any): target is RelationShipItem;
export declare function convertRelationshipToPlacehoderFieldItem(item: RelationShipItem | FieldItem, model: ModelItem): FieldItem;
export declare function createSubFields(field: FieldItem, relation: RelationShipItem, fields: Array<FieldItem>): {
parentId: string;
parentKey: string;
parentName: string;
parentModelKey: string;
parentModelName: string;
id?: string | undefined;
name: string;
key: string;
type: string;
length?: number | undefined;
isRequired?: boolean | undefined;
isNullable?: boolean | undefined;
isBuiltIn?: boolean | undefined;
relationId?: string | undefined;
relation?: RelationShipItem | undefined;
isPrimayKey?: boolean | undefined;
isPrimaryKey?: boolean | undefined;
isGenerated?: boolean | undefined;
isForeignKey?: boolean | undefined;
isUnique?: boolean | undefined;
modified?: boolean | undefined;
isArray?: boolean | undefined;
defaultValue?: any;
defaultValueMode?: "static" | "null" | "expression" | "current_user" | undefined;
comment?: string | undefined;
isCreateDate?: boolean | undefined;
isUpdateDate?: boolean | undefined;
isDeleteDate?: boolean | undefined;
isCreateUser?: boolean | undefined;
isUpdateUser?: boolean | undefined;
isDeleteUser?: boolean | undefined;
isOrderNumber?: boolean | undefined;
isTreeParentId?: boolean | undefined;
isTreePath?: boolean | undefined;
isTenantId?: boolean | undefined;
isAutoCreated?: boolean | undefined;
referencedColumnName?: string | undefined;
validations?: {
[rule: string]: any;
} | undefined;
validationErrors?: {
[rule: string]: string;
} | undefined;
raw?: Record<string, any> | undefined;
}[];
export declare function convertTitleTplToFormula(tpl: string): string;
export declare function formulaAppendVariableNamespace(formula: string, prefix: string): string;
export declare function getFieldFrontendOptions(field: FieldItem, relation?: RelationShipItem): {
[x: number]: any;
};
/**
* relation 可能有些默认设置,比如默认展示是啥的,这里把这些默认设置合并到字段上
* 否则页面设计器回显的时候,展示不了默认设置的东西
* @param item
* @returns
*/
export declare function modelFieldToSchemaField(item: FieldItem): FieldItem;
export declare function findInJSON<T = any>(json: any, finder: (value: any, key: string | number, host: Object | null) => boolean, ignore?: (value: any, key: string | number, host: Object | null) => boolean, deepFirst?: boolean): T | undefined;
export declare function arrayRemove<T>(list: Array<T>, value: T | ((value: T, index: number, obj: T[]) => unknown)): T | undefined;
export declare function arrayFindFrom<T>(list: Array<T>, predicate: (value: T, index: number, obj: T[]) => unknown, fromIndex: number): T | undefined;
export declare function createObject(superProps?: {
[propName: string]: any;
}, props?: {
[propName: string]: any;
}, properties?: any): object;
export declare function makeClassnames(ns?: string): (...classes: any[]) => string;
export declare const uuidv4: () => string;
export declare function normalizeApi(api: Api, defaultMethod?: string): ApiObject;
export declare function qsstringify(data: any, options?: any, keepEmptyArray?: boolean): string;
export declare function qsparse(data: string, options?: any): qs.ParsedQs;
export declare function normalizeApiWithQuery(api: Api): (ApiObject & {
strategy?: "restful" | "jsonql" | undefined;
}) | import("../type").JSONQLAPI;
export declare function collectVariables(strOrAst: string | Object, execMode?: boolean): Array<string>;
/**
* 生成 8 位随机数字。
*
* @return {string} 8位随机数字
*/
export declare function guid(): string;
export declare function generateSchemaID(): string;
export declare function i18n(key: string, data?: any): string;
export declare function setI18nHandler(handler: (key: string, data?: any) => string): void;
/** 是否为系统字段 */
export declare const isSystemField: (field: FieldItem) => boolean | undefined;
export declare function asyncJSONValueMap(json: any, mapper: (value: any, key: string | number, host: Object, stack: Array<Object>) => any, stack?: Array<Object>): Promise<any>;
/**
* parentKey + fieldKey 拼接
*/
export declare const normalizeSchemaName: (field: ExtraField, fallback: string) => string;
/**
* modelName + fieldName 拼接
*/
export declare const normalizeSchemaLabel: (field: ExtraField, fallback?: string) => string;
/** API配置中的select字段结构 */
export declare const normalizeAPISelectField: (field: ExtraField, masterModelId: string) => SelectField;
/** 提取字段支持的功能范围,返回给前端使用 */
export declare const normalizeFieldSPScope: (field: FieldItem, model: ModelStore) => {
viewable: boolean;
insertable: boolean;
updateable: boolean;
filterable: boolean;
searchable: boolean;
removable: boolean;
};
/** 根据当前功能场景过滤可用字段 */
export declare const filterFieldItemByFeat: (field: FieldItem, model: ModelStore, feat?: FeatType) => boolean;
/** 根据当前功能场景过滤可用字段, 和filterFieldItemByFeat的区别是主要用于前端已经解析的字段 */
export declare const filterFieldByFeat: (field: ExtraField, feat: FeatType) => boolean;
/** 转为为前端使用的字段结构 */
export declare const normalizeField2FE: (fields: ExtraField[], model: ModelStore, manager: Manager, options: {
defaultChecked?: boolean | undefined;
/** 是否返回ConditionBuilder的相关信息 */
enableCB?: boolean | undefined;
feat?: FeatType | FeatType[] | undefined;
/** 是否排除本表字段 */
excludeSelf?: boolean | undefined;
/** 过滤函数 */
filterFn?: ((field: ExtraField) => boolean) | undefined;
/** 映射函数 */
mapperFn?: ((field: ExtraField) => ExtraField) | undefined;
}) => Promise<ExtraField[]>;
export declare function JSONPipeOut(obj: any, filterHiddenProps?: boolean | ((key: string, prop: any) => boolean)): any;
export declare function cleanUndefined(obj: any): any;
export declare const classnames: (...classes: any[]) => string;
export declare function isModelFieldSame(left: any, right: any): boolean;