/* eslint-disable no-extra-semi */ /* eslint-disable @typescript-eslint/no-redundant-type-constituents, @typescript-eslint/no-empty-object-type */ import {List as ImmList, Map as ImmMap, OrderedMap as ImmOMap} from "immutable"; import {ElementType, ReactElement, Factory} from "react"; import moment from "moment"; import type { Moment, MomentInput } from "moment"; import type { i18n } from "i18next"; export type { Moment, MomentInput }; export type ImmutableList = ImmList; export type ImmutableMap = ImmMap; export type ImmutableOMap = ImmOMap; export type AnyImmutable = ImmutableList | ImmutableMap | ImmutableOMap; export type SqlDialect = "BigQuery" | "PostgreSQL" | "MySQL"; //////////////// // common ///////////////// type ReactKey = string | number; interface ReactAttributes { key?: ReactKey | null | undefined; } export type FactoryFnWithoutPropsWithContext = (this: CTX, ctx: CTX) => F; export type FnWithContextAndProps = (this: CTX, props: P, ctx?: CTX) => R; export type FactoryWithContext = (this: CTX, props: ReactAttributes & P, ctx?: CTX) => ReactElement

; export type RenderedReactElement = ReactElement | string; export type SerializedFunction = JsonLogicFunction | string; export type SerializableType = SER extends true ? T | SerializedFunction : T; type AnyObject = Record; type Empty = null | undefined; export type ImmutablePath = ImmutableList; export type IdPath = Array | ImmutablePath; // should be used in actions only type Optional = { [P in keyof T]?: T[P]; }; type PickDeprecated = { /** * @deprecated */ [P in K]: T[P]; }; export type PartialPartial = { // eslint-disable-next-line @typescript-eslint/no-wrapper-object-types [P in keyof T]?: T[P] extends Object ? Partial : T[P]; }; type OptionalBy = Omit & Partial>; type TypedMap = Record; // You can not use a union for types on a key, but can define overloaded accessors of different types. // Key can be a string OR number type TypedKeyMap = { [key: string]: T; [key: number]: T; }; interface ObjectToImmOMap

extends ImmutableOMap { get(name: K): P[K]; get(name: string): any; } export type AsyncListValues = Array; // for export/import export type MongoValue = any; export type MongoQueryObject = Record; export type ElasticQueryType = string; export type ElasticQueryObject = Record; export type SqlOutLogic = Record; // OutLogic in packages/sql/modules/import/types.ts export type JsonLogicResult = { logic?: JsonLogicTree; data?: Record; errors?: Array; } type SingleKeyObject = { [K in string]: T } & { length?: never }; export type JsonLogicFunction = SingleKeyObject | JsonLogicValue>; export type JsonLogicTree = JsonLogicFunction; export type JsonLogicValue = any; export type JsonLogicField = { "var": string }; export interface SpelRawValue { type: string; children?: SpelRawValue[]; val?: RuleValue; methodName?: string; args?: SpelRawValue[]; obj?: SpelRawValue[]; isVar?: boolean; cls: string[]; } export interface ConfigContextUtils { SqlString: ExportUtils["SqlString"]; sqlEmptyValue: ExportUtils["sqlEmptyValue"]; spelFixList: SpelUtils["spelFixList"]; wrapWithBrackets: ExportUtils["wrapWithBrackets"]; stringifyForDisplay: ExportUtils["stringifyForDisplay"]; mongoEmptyValue: MongoUtils["mongoEmptyValue"]; spelEscape: SpelUtils["spelEscape"]; moment: OtherUtils["moment"]; escapeRegExp: OtherUtils["escapeRegExp"]; getTitleInListValues: ListUtils["getTitleInListValues"]; } export interface ConfigContext { utils: ConfigContextUtils; W: TypedMap>; O: TypedMap>; components?: TypedMap>; [key: string]: any; } export type FlatItemPosition = { caseNo: number | null; globalNoByType: number; indexPath: number[]; globalLeafNo?: number; globalGroupNo?: number; }; export type FlatItem = { node: ImmutableItem; index: number; // index in `flat` id: string; path: string[]; type: ItemType; parent: string | null; parentType: ItemType | null; children: string[] | null; caseId: string | null; caseNo: number | null; prev: string | null; next: string | null; lev: number; // depth level isLeaf: boolean; // is atomic rule OR rule inside rule_group isAtomicRule: boolean; // is atomic (rule or rule_group, but not rules inside rule_group) isLocked: boolean; // vertical height: number; // visible height _height: number; // real height (incl. collapsed) top: number | null; // null if inside collapsed bottom: number | null; // null if inside collapsed // object with numbers indicating # of item in tree position?: FlatItemPosition; // for any group depth?: number; // children of rule_group are not counted, collapsed are not counted // for case only isDefaultCase?: boolean; atomicRulesCountInCase?: number; // unused _top: number; collapsed: boolean; /** * @deprecated use isLeaf instead */ leaf: boolean; }; export type FlatTree = { items: TypedMap; flat: string[]; // ids of all items in top-to-bottom order cases: string[]; // ids of cases }; //////////////// // query value ///////////////// // tip: Date is stored as string export type SimpleValue = boolean | number | string | Array | undefined | null; type AnyValue = any; export type RuleValue = SimpleValue | FuncValue | AnyValue; // tip: multiselect value is stored as Array, not ImmutableList export type RuleValueI = SimpleValue | FuncValueI | AnyValue; export type FieldPath = string; export interface FuncArgValue { value: V; valueSrc?: ValueSource; } export type FuncArgValueI = ObjectToImmOMap>; export interface FuncValue { func: string; args: TypedMap>; } export type FuncValueI = ObjectToImmOMap<{ func: string; args: ImmutableOMap; }>; export type FieldValue = FieldPath | FuncValue; export type FieldValueI = FieldPath | FuncValueI; export type AnyFieldValue = FieldValue | FieldValueI; export type ValueSource = "value" | "field" | "func" | "const"; export type FieldSource = "field" | "func"; export type RuleGroupMode = "struct" | "some" | "array"; export type ItemType = "group" | "rule_group" | "rule" | "case_group" | "switch_group"; // note: these preperties types are used for actions export type AnyRuleProperties = RuleProperties | RuleGroupExtProperties | RuleGroupProperties; export type AnyGroupProperties = GroupProperties | SwitchGroupProperties | CaseGroupProperties; export type ItemProperties = AnyRuleProperties | GroupProperties; interface ExtraActionProperties { // note: id can pre-generated for actions addRule, addGroup id?: string; } interface BasicItemProperties { isLocked?: boolean; } export type OperatorOptions = Record; export type OperatorOptionsI = ImmMap; export interface RuleProperties extends BasicItemProperties { field: FieldValue | Empty; fieldSrc?: FieldSource; fieldType?: string; fieldError?: string | Empty; operator: string | Empty; value: Array; valueSrc?: Array; valueType?: Array; valueError?: Array; operatorOptions?: OperatorOptions | Empty; } export interface RuleGroupExtProperties extends RuleProperties { field: FieldPath | Empty; // tip: field can be only string, not func mode: RuleGroupMode; conjunction?: string; not?: boolean; } export interface RuleGroupProperties extends BasicItemProperties { field: FieldPath | Empty; // tip: field can be only string, not func mode?: RuleGroupMode; } export interface GroupProperties extends BasicItemProperties { conjunction: string; not?: boolean; } export interface SwitchGroupProperties extends BasicItemProperties { // todo: any properties here? } export interface CaseGroupProperties extends BasicItemProperties { value?: Array; valueSrc?: Array; valueType?: Array; valueError?: Array; field?: string; // todo: only "!case_value" ? } ////// interface _RulePropertiesI extends Omit { field: FieldValueI | Empty; value: ImmutableList; valueSrc?: ImmutableList; valueType?: ImmutableList; valueError?: ImmutableList; operatorOptions?: OperatorOptionsI; } interface _CaseGroupPropertiesI extends Omit { field?: string | Empty; // todo: only "!case_value" ? value?: ImmutableList; valueSrc?: ImmutableList; valueType?: ImmutableList; valueError?: ImmutableList; } // correct unions interface _RuleGroupExtPropertiesI extends Pick, Omit<_RulePropertiesI, "field"> {} interface _AnyRulePropertiesI extends Optional<_RulePropertiesI>, Optional> {} interface _ItemPropertiesI extends _AnyRulePropertiesI, Optional> {} interface _ItemOrCasePropertiesI extends Omit<_ItemPropertiesI, "field">, Optional<_CaseGroupPropertiesI> {} interface _GroupOrSwitchPropertiesI extends Optional, Optional {} export interface BasicItemPropertiesI

extends ObjectToImmOMap

{} export interface ImmutableRuleProperties

extends BasicItemPropertiesI

{} export interface ImmutableRuleGroupProperties

extends BasicItemPropertiesI

{} export interface ImmutableRuleGroupExtProperties

extends ImmutableRuleProperties

{} export interface ImmutableGroupProperties

extends BasicItemPropertiesI

{} export interface ImmutableSwitchGroupProperties

extends BasicItemPropertiesI

{} export interface ImmutableCaseGroupProperties

extends BasicItemPropertiesI

{} // correct unions export interface ImmutableAnyRuleProperties

extends BasicItemPropertiesI

{} export interface ImmutableItemProperties

extends BasicItemPropertiesI

{} export interface ImmutableItemOrCaseProperties

extends BasicItemPropertiesI

{} export interface ImmutableGroupOrSwitchProperties

extends BasicItemPropertiesI

{} ////// export interface JsonBasicItem { type: ItemType; id?: string; } export interface JsonRule extends Omit { type: "rule"; properties: RuleProperties; } // OldJson.. are types with `children1` as object instead of array (discouraged) // `children1` as object can be used for import or export with children1AsArray = false export interface OldJsonSwitchGroup extends JsonBasicItem { type: "switch_group"; children1?: {[id: string]: OldJsonCaseGroup} | OldJsonCaseGroup[]; properties?: SwitchGroupProperties; } export interface OldJsonCaseGroup extends JsonBasicItem { type: "case_group"; children1?: {[id: string]: OldJsonItem} | OldJsonItem[]; properties?: CaseGroupProperties; } export interface OldJsonGroup extends JsonBasicItem { type: "group"; children1?: {[id: string]: OldJsonItem} | OldJsonItem[]; properties?: GroupProperties; } export interface OldJsonRuleGroup extends JsonBasicItem { type: "rule_group"; children1?: {[id: string]: JsonRule} | JsonRule[]; properties?: RuleGroupProperties; } export interface OldJsonRuleGroupExt extends JsonBasicItem { type: "rule_group"; children1?: {[id: string]: JsonRule} | JsonRule[]; properties?: RuleGroupExtProperties; } export type OldJsonAnyRule = JsonRule|OldJsonRuleGroup|OldJsonRuleGroupExt; export type OldJsonItem = OldJsonGroup|OldJsonAnyRule; export type OldJsonTree = OldJsonGroup|OldJsonSwitchGroup; // Json.. (in comparison with OldJson..) are types with `children1` as array (default) // Used as default for export with children1AsArray = true export interface JsonSwitchGroup extends OldJsonSwitchGroup { children1?: JsonCaseGroup[]; } export interface JsonCaseGroup extends OldJsonCaseGroup { children1?: JsonItem[]; } export interface JsonGroup extends OldJsonGroup { children1?: JsonItem[]; } export interface JsonRuleGroup extends OldJsonRuleGroup { children1?: JsonRule[]; } export interface JsonRuleGroupExt extends OldJsonRuleGroupExt { children1?: JsonRule[]; } export type JsonAnyRule = JsonRule|JsonRuleGroup|JsonRuleGroupExt; export type JsonItem = JsonGroup|JsonAnyRule; export type JsonTree = JsonGroup|JsonSwitchGroup; //// interface _BasicItemI { type: ItemType; id: string; } interface _RuleI extends _BasicItemI { type: "rule"; properties: ImmutableRuleProperties; } interface _GroupI extends _BasicItemI { type: "group"; children1?: ImmOMap; properties: ImmutableGroupProperties; } interface _RuleGroupI extends _BasicItemI { type: "rule_group"; children1?: ImmOMap; properties: ImmutableRuleGroupProperties; } interface _RuleGroupExtI extends _BasicItemI { type: "rule_group"; children1?: ImmOMap; properties: ImmutableRuleGroupExtProperties; } interface _SwitchGroupI extends _BasicItemI { type: "switch_group"; children1?: ImmOMap; properties: ImmutableSwitchGroupProperties; } interface _CaseGroupI extends _BasicItemI { type: "case_group"; children1?: ImmOMap; properties: ImmutableCaseGroupProperties; } // Fix unions manially: type _OmitI = Omit; // type _AnyRuleI = _RuleI | _RuleGroupI | _RuleGroupExtI; interface _AnyRuleI extends _OmitI<_RuleI> { type: "rule" | "rule_group"; properties: ImmutableAnyRuleProperties; children1?: ImmOMap; } // type _ItemI = _GroupI | _AnyRuleI; export interface _ItemI extends _OmitI<_GroupI>, _OmitI<_AnyRuleI> { type: "rule" | "rule_group" | "group"; properties: ImmutableItemProperties; children1?: ImmOMap; } // type _ItemOrCaseI = _ItemI | _CaseGroupI; interface _ItemOrCaseI extends _OmitI<_ItemI>, _OmitI<_CaseGroupI> { type: "rule" | "rule_group" | "group" | "case_group"; properties: ImmutableItemOrCaseProperties; children1?: ImmOMap; } // type _TreeI = _GroupI | _SwitchGroupI; export interface _TreeI extends _OmitI<_GroupI>, _OmitI<_SwitchGroupI> { type: "group" | "switch_group"; children1?: ImmOMap>; properties: ImmutableGroupOrSwitchProperties; } export interface ImmutableBasicItem

extends ObjectToImmOMap

{} export interface ImmutableRule

extends ImmutableBasicItem

{} export interface ImmutableGroup

extends ImmutableBasicItem

{} export interface ImmutableRuleGroup

extends ImmutableBasicItem

{} export interface ImmutableRuleGroupExt

extends ImmutableBasicItem

{} export interface ImmutableSwitchGroup

extends ImmutableBasicItem

{} export interface ImmutableCaseGroup

extends ImmutableBasicItem

{} export interface ImmutableAnyRule

extends ImmutableBasicItem

{} export interface ImmutableItem

extends ImmutableBasicItem

{} export interface ImmutableTree

extends ImmutableBasicItem

{} //////////////// // Utils ///////////////// /** * @deprecated */ export interface SpelConcatPart { value: string; type: "property" | "variable" | "const"; } type SpelConcatParts = SpelConcatPart[]; interface SpelConcatCaseValue { valueType: "case_value"; value: SpelConcatNormalValue[]; } interface SpelConcatNormalValue { value: string; valueType: string; valueSrc: "value" | "field"; isVariable?: boolean; } type SpelConcatValue = SpelConcatNormalValue | SpelConcatCaseValue; export interface Translatable { key: string; args?: null | Record; } export interface ValidationError extends Translatable { // translated message str?: string; side?: "lhs" | "rhs" | "op"; delta?: number; // 0, 1, -1 for range, undefined for "lhs" fixed?: boolean; fixedFrom?: any; fixedTo?: any; } export interface ValidationItemErrors { path: Array; errors: ValidationError[]; itemStr?: string; itemPosition?: FlatItemPosition & Pick & { isDeleted: boolean; }; itemPositionStr?: string; } export type ValidationErrors = ValidationItemErrors[]; export interface SanitizeResult { fixedTree: ImmutableTree; fixedErrors: ValidationErrors; nonFixedErrors: ValidationErrors; allErrors: ValidationErrors; } export interface SanitizeOptions extends ValidationTranslateOptions { removeEmptyGroups?: boolean; // default: true removeEmptyRules?: boolean; // default: true removeIncompleteRules?: boolean; // default: true forceFix?: boolean; // default: false } export interface ValidationTranslateOptions { translateErrors?: boolean; // default: true includeItemsPositions?: boolean; // default: true includeStringifiedItems?: boolean; // default: true stringifyItemsUserFriendly?: boolean; // default: true stringifyFixedItems?: boolean; // default: false (stringify item with error) } export interface ValidationOptions extends ValidationTranslateOptions { } interface Validation { sanitizeTree(tree: ImmutableTree, config: Config, options?: SanitizeOptions): SanitizeResult; validateTree(tree: ImmutableTree, config: Config, options?: ValidationOptions): ValidationErrors; isValidTree(tree: ImmutableTree, config: Config): boolean; getTreeBadFields(tree: ImmutableTree, config: Config): Array; translateValidation(tr: Translatable): string; translateValidation(key: Translatable["key"], args?: Translatable["args"]): string; /** * @deprecated Use Utils.Validation.sanitizeTree() instead */ checkTree(tree: ImmutableTree, config: Config): ImmutableTree; } interface Import { // tree getTree(tree: ImmutableTree, light?: boolean, children1AsArray?: boolean): JsonTree; getTree(tree: ImmutableTree, light: boolean, children1AsArray: false): OldJsonTree; loadTree(jsonTree: JsonTree): ImmutableTree; loadTree(jsonTree: OldJsonTree): ImmutableTree; isImmutableTree(tree: any): boolean; isTree(tree: any): boolean; // is JsonTree ? isJsonLogic(value: any): boolean; jsToImmutable(value: any): AnyImmutable; // jsonlogic loadFromJsonLogic(logicTree: JsonLogicTree | undefined, config: Config): ImmutableTree | undefined; _loadFromJsonLogic(logicTree: JsonLogicTree | undefined, config: Config): [ImmutableTree | undefined, Array]; // spel loadFromSpel(spelStr: string, config: Config): [ImmutableTree | undefined, Array]; } interface Export { jsonLogicFormat(tree: ImmutableTree, config: Config): JsonLogicResult; /** * @deprecated */ queryBuilderFormat(tree: ImmutableTree, config: Config): Record | undefined; queryString(tree: ImmutableTree, config: Config, isForDisplay?: boolean, isDebugMode?: boolean): string | undefined; sqlFormat(tree: ImmutableTree, config: Config): string | undefined; _sqlFormat(tree: ImmutableTree, config: Config): [string | undefined, Array]; spelFormat(tree: ImmutableTree, config: Config): string | undefined; _spelFormat(tree: ImmutableTree, config: Config): [string | undefined, Array]; mongodbFormat(tree: ImmutableTree, config: Config): MongoQueryObject | undefined; _mongodbFormat(tree: ImmutableTree, config: Config): [MongoQueryObject | undefined, Array]; elasticSearchFormat(tree: ImmutableTree, config: Config, syntax?: "ES_6_SYNTAX" | "ES_7_SYNTAX"): ElasticQueryObject | undefined; } interface Autocomplete { simulateAsyncFetch(all: ListValues, pageSize?: number, delay?: number): AsyncFetchListValuesFn; getListValue(value: string | number, listValues: ListValues): ListItem; // get by value // internal mergeListValues(oldValues: ListItems, newValues: ListItems, toStart?: boolean): ListItems; listValueToOption(listItem: ListItem): ListOptionUi; } interface ConfigUtils { areConfigsSame(config1: Config, config2: Config): boolean; compressConfig(config: Config, baseConfig: Config): ZipConfig; decompressConfig(zipConfig: ZipConfig, baseConfig: Config, ctx?: ConfigContext): Config; compileConfig(config: Config): Config; extendConfig(config: Config, configId?: string, canCompile?: boolean): Config; getFieldConfig(config: Config, field: AnyFieldValue): FieldConfig | null; getFieldParts(field: AnyFieldValue, config?: Config): string[]; getFieldPathParts(field: AnyFieldValue, config: Config): string[]; getFuncConfig(config: Config, func: string): Func | null; getFuncArgConfig(config: Config, func: string, arg: string): FuncArg | null; getOperatorConfig(config: Config, operator: string, field?: AnyFieldValue): Operator | null; getFieldWidgetConfig(config: Config, field: AnyFieldValue, operator: string, widget?: string, valueStr?: ValueSource): Widget | null; isJSX(jsx: any): boolean; isDirtyJSX(jsx: any): boolean; cleanJSX(jsx: any): any; applyJsonLogic: JsonLogicUtils["applyJsonLogic"]; iterateFuncs(config: Config): Iterable<[funcPath: string, funcConfig: Func]>; iterateFields(config: Config): Iterable<[fieldPath: string, fieldConfig: Field, fieldKey: string]>; } interface DefaultUtils { getDefaultField(config: Config, canGetFirst?: boolean, parentRuleGroupField?: string): FieldValueI | null; getDefaultSubField(config: Config, parentRuleGroupField?: string): FieldValueI | null; getDefaultFieldSrc(config: Config, canGetFirst?: boolean): string; getDefaultOperator(config: Config, field: Field, canGetFirst?: boolean): string; defaultRule(id: string, config: Config): Record; defaultRoot(config: Config, canAddDefaultRule?: boolean): ImmutableGroup; defaultItemProperties(config: Config, item: JsonItem): ImmutableItemProperties; defaultGroupProperties(config: Config, groupFieldConfig?: FieldValueOrConfig): ImmutableGroupProperties; defaultRuleProperties(config: Config, parentRuleGroupField?: string, item?: JsonItem, canUseDefaultFieldAndOp?: boolean, canGetFirst?: boolean): ImmutableRuleProperties; /** * @deprecated Use defaultGroupConjunction() instead */ defaultConjunction(config: Config): string; defaultOperatorOptions(config: Config, operator: string, field: Field): OperatorOptionsI | null; defaultGroupConjunction(config: Config, groupFieldConfig?: FieldValueOrConfig): string; // createListWithOneElement(el: TItem): ImmutableList; // createListFromArray(array: TItem[]): ImmutableList; } interface ExportUtils extends PickDeprecated, PickDeprecated { wrapWithBrackets(val?: string): string; sqlEmptyValue(fieldDef?: Field): string; SqlString: { trim(val?: string): string; escape(val?: string): string; escapeLike(val?: string, any_start?: boolean, any_end?: boolean, sqlDialect?: SqlDialect): string; unescapeLike(val?: string, sqlDialect?: SqlDialect): string; }, stringifyForDisplay(val: any): string; } interface ListUtils { getTitleInListValues(listValues: ListValues, value: string | number): string; getListValue(value: string | number, listValues: ListValues): ListItem; // get by value searchListValue(search: string, listValues: ListValues): ListItem; // search by value and title listValuesToArray(listValues: ListValues): ListItems; // normalize toListValue(value: string | number | ListItem, title?: string): ListItem | undefined; // create makeCustomListValue(value: string | number): ListItem; // create mapListValues(listValues : ListValues, mapFn: (item: ListItem | undefined) => T | null) : T[]; } interface TreeUtils { jsToImmutable(value: any): AnyImmutable; immutableToJs(imm: AnyImmutable): any; isImmutable(value: any): boolean; toImmutableList(path: string[]): ImmutablePath; getItemByPath(tree: ImmutableTree, path: IdPath): ImmutableItem | undefined; expandTreePath(path: ImmutablePath, ...suffix: string[]): ImmutablePath; expandTreeSubpath(path: ImmutablePath, ...suffix: string[]): ImmutablePath; fixEmptyGroupsInTree(tree: ImmutableTree): ImmutableTree; fixPathsInTree(tree: ImmutableTree): ImmutableTree; getFlatTree(tree: ImmutableTree, config?: Config): FlatTree; getTotalReordableNodesCountInTree(tree: ImmutableTree): number; getTotalRulesCountInTree(tree: ImmutableTree): number; isEmptyTree(tree: ImmutableTree): boolean; // case mode getSwitchValues(tree: ImmutableTree): Array; } interface MongoUtils { mongoEmptyValue(fieldDef?: Field): string; mongoFieldEscape(fieldName: string): string; mongoFieldUnescape(fieldName: string): string; } interface JsonLogicUtils { applyJsonLogic(logic: JsonLogicValue, data?: any): any; addJsonLogicOperation(name: string, operation: (...args: any[]) => JsonLogicValue, jl?: any): void; customJsonLogicOperations: TypedMap<(...args: any[]) => JsonLogicValue>; addRequiredJsonLogicOperations(jl?: any): void; } interface SpelUtils { spelFixList(listStr: string): string; spelEscape(val: any): string; /** * @deprecated */ spelFormatConcat(parts: SpelConcatParts): string; /** * @deprecated */ spelImportConcat(val: SpelConcatValue): [SpelConcatParts | undefined, Array]; } interface MixSymbols { /** * Symbols: * _v?: T | undefined; * _type?: string; * _canCreate?: boolean; * _canChangeType?: boolean; * _arrayMergeMode?: "join" | "joinMissing" | "joinRespectOrder" | "overwrite" | "merge"; */ [key: symbol]: boolean | string | T; } type MixObject> = { [P in keyof T]?: MixType; } & { [P in Exclude]: any; } & MixSymbols; type MixArray> = (T /* & MixinSymbols */); // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type type _Opt = T extends Function ? T : T extends Array ? T : T extends Record ? Partial : T; type Opt = _Opt>; // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type type _MixType = T extends Function ? T : T extends Array ? MixArray : T extends Record ? MixObject : Opt; export type MixType = _MixType>; interface OtherUtils { logger: typeof console; clone(obj: any): any; moment: typeof moment; uuid(): string; mergeArraysSmart(arr1: any[], arr2: any[]): any[]; setIn( obj: O, path: string[], newValue: T | undefined | ((old: T) => T), options?: { canCreate?: boolean, canIgnore?: boolean, canChangeType?: boolean, } ): O; mergeIn( obj: Record, mixin: MixType>, options?: { canCreate?: boolean, canChangeType?: boolean, deepCopyObj?: boolean, arrayMergeMode?: "join" | "joinMissing" | "joinRespectOrder" | "overwrite" | "merge", } ): Record; deepFreeze(obj: any): any; deepEqual(a: any, b: any): boolean; shallowEqual(a: any, b: any, deep?: boolean): boolean; mergeArraysSmart(a: string[], b: string[]): string[]; isJsonCompatible(tpl: object, target: object, bag: Record): boolean; // mutates bag isJsonLogic(value: any): boolean; isJSX(jsx: any): boolean; isDirtyJSX(jsx: any): boolean; cleanJSX(jsx: any): any; escapeRegExp(str: string): string; //applyToJS(imm: any): any; // same as immutableToJs isImmutable(value: any): boolean; toImmutableList(path: string[]): ImmutablePath; isTruthy(value: T | false | null | undefined): value is T; } export interface Utils extends Import, Export, Pick, Pick, PickDeprecated, PickDeprecated, PickDeprecated { Import: Import; Export: Export; Autocomplete: Autocomplete; Validation: Validation; ConfigUtils: ConfigUtils; DefaultUtils: DefaultUtils; ExportUtils: ExportUtils; MongoUtils: MongoUtils; JsonLogicUtils: JsonLogicUtils; SpelUtils: SpelUtils; ListUtils: ListUtils; TreeUtils: TreeUtils; OtherUtils: OtherUtils; i18n: i18n; } ///////////////// // Config ///////////////// export interface Config { conjunctions: Conjunctions; operators: Operators; widgets: Widgets; types: Types; settings: Settings; fields: Fields; funcs?: Funcs; ctx: ConfigContext; } export type ZipConfig = Omit; export type ConfigMixinExt = MixType; export interface ConfigMixin { conjunctions?: Record>; operators?: Record>>; widgets?: Record>>; types?: Record>; settings?: PartialPartial; fields?: Record>; funcs?: Record>; ctx?: PartialPartial; } ///////////////// // Actions ///////////////// type Placement = "after" | "before" | "append" | "prepend"; type ActionType = string | "ADD_RULE" | "REMOVE_RULE" | "ADD_GROUP" | "ADD_CASE_GROUP" | "REMOVE_GROUP" | "REMOVE_GROUP_CHILDREN" | "SET_NOT" | "SET_LOCK" | "SET_CONJUNCTION" | "SET_FIELD" | "SET_FIELD_SRC" | "SET_OPERATOR" | "SET_VALUE" | "SET_VALUE_SRC" | "SET_OPERATOR_OPTION" | "MOVE_ITEM"; interface BaseAction { type: ActionType; id?: string; // for ADD_RULE, ADD_GROUP - id of new item path?: string[]; // for all except MOVE_ITEM (for ADD_RULE/ADD_GROUP it's parent path) conjunction?: string; not?: boolean; lock?: boolean; field?: string; operator?: string; delta?: number; // for SET_VALUE value?: SimpleValue; valueType?: string; srcKey?: ValueSource; name?: string; // for SET_OPERATOR_OPTION fromPath?: string[]; // for MOVE_ITEM toPath?: string[]; // for MOVE_ITEM placement?: Placement; // for MOVE_ITEM properties?: TypedMap; // for ADD_RULE, ADD_GROUP } export interface InputAction extends BaseAction { config: Config; } export interface ActionMeta extends BaseAction { affectedField?: string; // gets field name from `path` (or `field` for first SET_FIELD) } export interface Actions { // tip: children will be converted to immutable ordered map in `_addChildren1` addRule(path: IdPath, properties?: AnyRuleProperties & ExtraActionProperties, type?: ItemType, children?: Array): undefined; removeRule(path: IdPath): undefined; addGroup(path: IdPath, properties?: AnyGroupProperties & ExtraActionProperties, children?: Array): undefined; removeGroup(path: IdPath): undefined; setNot(path: IdPath, not: boolean): undefined; setLock(path: IdPath, lock: boolean): undefined; setConjunction(path: IdPath, conjunction: string): undefined; setField(path: IdPath, field: FieldValueI): undefined; // todo: try to support FieldValue - apply jsToImmutable() just like for `defaultField` setFieldSrc(path: IdPath, fieldSrc: FieldSource): undefined; setOperator(path: IdPath, operator: string): undefined; setValue(path: IdPath, delta: number, value: RuleValueI, valueType: string): undefined; // todo: try to support RuleValue setFuncValue(path: IdPath, delta: number, parentFuncs: Array<[string, string]>, argKey: string | null, value: SimpleValue, valueType: string | "!valueSrc"): undefined; setValueSrc(path: IdPath, delta: number, valueSrc: ValueSource): undefined; setOperatorOption(path: IdPath, name: string, value: SimpleValue): undefined; moveItem(fromPath: IdPath, toPath: IdPath, placement: Placement): undefined; setTree(tree: ImmutableTree): undefined; } interface TreeState { tree: ImmutableTree; __lastAction?: ActionMeta; } type TreeReducer = (state?: TreeState, action?: InputAction) => TreeState; type TreeStore = (config: Config, tree?: ImmutableTree) => TreeReducer; export interface TreeActions { tree: { setTree(config: Config, tree: ImmutableTree): InputAction; addRule(config: Config, path: IdPath, properties?: AnyRuleProperties, type?: ItemType, children?: Array): InputAction; removeRule(config: Config, path: IdPath): InputAction; addDefaultCaseGroup(config: Config, path: IdPath, properties?: CaseGroupProperties, children?: Array): InputAction; addCaseGroup(config: Config, path: IdPath, properties?: CaseGroupProperties, children?: Array): InputAction; addGroup(config: Config, path: IdPath, properties?: GroupProperties, children?: Array): InputAction; removeGroup(config: Config, path: IdPath): InputAction; moveItem(config: Config, fromPath: IdPath, toPath: IdPath, placement: Placement): InputAction; }; group: { setConjunction(config: Config, path: IdPath, conjunction: string): InputAction; setNot(config: Config, path: IdPath, not: boolean): InputAction; setLock(config: Config, path: IdPath, lock: boolean): InputAction; }; rule: { setField(config: Config, path: IdPath, field: FieldValueI): InputAction; // todo: try to support FieldValue setFieldSrc(config: Config, path: IdPath, fieldSrc: FieldSource): InputAction; setOperator(config: Config, path: IdPath, operator: string): InputAction; setValue(config: Config, path: IdPath, delta: number, value: RuleValueI, valueType: string): InputAction; // todo: try to support RuleValue setValueSrc(config: Config, path: IdPath, delta: number, valueSrc: ValueSource): InputAction; setOperatorOption(config: Config, path: IdPath, name: string, value: SimpleValue): InputAction; setFuncValue(config: Config, path: IdPath, delta: number, parentFuncs: Array<[string, string]>, argKey: string | null, value: SimpleValue, valueType: string | "!valueSrc"): InputAction; }; } ///////////////// // WidgetProps // @ui ///////////////// interface AbstractWidgetProps { placeholder: string; label?: string; field: FieldValueI; fieldDefinition: Field; fieldSrc: FieldSource; fieldType?: string; fieldError?: string | Empty; parentField?: string; parentFuncs?: Array<[string, string]> | Empty; // array of [funcKey, argKey] operator: string; config: C; delta?: number; customProps?: AnyObject; readonly?: boolean; id?: string; // id of rule groupId?: string; // id of parent group widgetId?: string; // unique id of widget isLHS?: boolean; isSpecialRange?: boolean; isFuncArg?: boolean; // tip: setFuncValue prop exists, but is internal } interface BaseWidgetProps extends AbstractWidgetProps { value: V | Empty; setValue(val: V | Empty, asyncListValues?: AsyncListValues): void; valueError?: string | Empty; errorMessage?: string | Empty; // fieldError or valueError } interface RangeWidgetProps extends AbstractWidgetProps { value: Array; setValue(val: Array, asyncListValues?: AsyncListValues): void; placeholders: Array; textSeparators: Array; valueError?: Array; errorMessage?: Array; // same as valueError } // BaseWidgetProps | RangeWidgetProps interface RangeableWidgetProps extends AbstractWidgetProps { value: V | Empty | Array; setValue(val: V | Empty | Array, asyncListValues?: AsyncListValues): void; placeholders?: Array; textSeparators?: Array; valueError?: string | Empty | Array; errorMessage?: string | Empty | Array; // fieldError or valueError } export type WidgetProps = RangeableWidgetProps & FieldSettings; export type TextWidgetProps = BaseWidgetProps & TextFieldSettings; export type DateTimeWidgetProps = RangeableWidgetProps & DateTimeFieldSettings; export type BooleanWidgetProps = BaseWidgetProps & BooleanFieldSettings; export type NumberWidgetProps = RangeableWidgetProps & NumberFieldSettings; export type RangeSliderWidgetProps = RangeableWidgetProps & NumberFieldSettings; export type PriceWidgetProps = BaseWidgetProps & PriceFieldSettings; export type SelectWidgetProps = BaseWidgetProps & SelectFieldSettings; export type MultiSelectWidgetProps = BaseWidgetProps & MultiSelectFieldSettings; export type TreeSelectWidgetProps = BaseWidgetProps & TreeSelectFieldSettings; export type TreeMultiSelectWidgetProps = BaseWidgetProps & TreeMultiSelectFieldSettings; /** * @deprecated */ export type CaseValueWidgetProps = BaseWidgetProps & CaseValueFieldSettings; ///////////////// // FieldProps // @ui ///////////////// type FieldItemSearchableKey = "key" | "path" | "label" | "altLabel" | "tooltip" | "grouplabel"; export type FieldItem = { items?: FieldItems; key: string; path?: string; // field path with separator label: string; fullLabel?: string; altLabel?: string; // label2 tooltip?: string; disabled?: boolean; grouplabel?: string; matchesType?: boolean; } type FieldItems = FieldItem[]; export interface FieldProps { items: FieldItems; selectedFieldSrc?: FieldSource; setField(field: FieldPath): void; errorText?: string; selectedKey: string | Empty; selectedKeys?: Array | Empty; selectedPath?: Array | Empty; selectedLabel?: string | Empty; selectedAltLabel?: string | Empty; selectedFullLabel?: string | Empty; config?: C; customProps?: AnyObject; placeholder?: string; selectedOpts?: {tooltip?: string}; readonly?: boolean; id?: string; // id of rule groupId?: string; // id of parent group } ///////////////// // Widgets ///////////////// type SpelImportValue = (this: ConfigContext, val: any, wgtDef?: Widget, args?: TypedMap) => [any, string[] | string | undefined]; type JsonLogicImportValue = (this: ConfigContext, val: any, wgtDef?: Widget, args?: TypedMap) => any | undefined; // can throw // tip: for multiselect widget `val` is Array, and return type is also Array type FormatValue = (this: ConfigContext, val: RuleValue, fieldDef: Field, wgtDef: Widget, isForDisplay: boolean, op: string, opDef: Operator, rightFieldDef?: Field) => string | string[]; type SqlFormatValue = (this: ConfigContext, val: RuleValue, fieldDef: Field, wgtDef: Widget, op: string, opDef: Operator, rightFieldDef?: Field, sqlDialect?: SqlDialect) => string | string[]; type SpelFormatValue = (this: ConfigContext, val: RuleValue, fieldDef: Field, wgtDef: Widget, op: string, opDef: Operator, rightFieldDef?: Field) => string | string[]; type MongoFormatValue = (this: ConfigContext, val: RuleValue, fieldDef: Field, wgtDef: Widget, op: string, opDef: Operator) => MongoValue; type JsonLogicFormatValue = (this: ConfigContext, val: RuleValue, fieldDef: Field, wgtDef: Widget, op: string, opDef: Operator) => JsonLogicValue; type ElasticSearchFormatValue = (this: ConfigContext, queryType: ElasticQueryType, val: RuleValue, op: string, field: FieldPath, config: Config) => ElasticQueryObject | null; export type ValidateValue = (this: ConfigContext, val: V, fieldSettings: FieldSettings, op: string, opDef: Operator, rightFieldDef?: Field) => boolean | string | { error: string | {key: string, args?: Record}, fixedValue?: V } | null; export interface BaseWidget> { type: string; // Used for validation. Can be one of JS types (typeof) or "array" jsType?: string; valueSrc?: ValueSource; valuePlaceholder?: string; valueLabel?: string; fullWidth?: boolean; formatValue?: SerializableType; sqlFormatValue?: SerializableType; spelFormatValue?: SerializableType; spelImportFuncs?: Array; spelImportValue?: SerializableType; sqlImport?: SerializableType; mongoFormatValue?: SerializableType; elasticSearchFormatValue?: SerializableType; hideOperator?: boolean; operatorInlineLabel?: string; jsonLogic?: SerializableType; jsonLogicImport?: SerializableType; //obsolete: validateValue?: SerializableType; //@ui factory: SerializableType>; customProps?: AnyObject; } export interface RangeableWidget> extends BaseWidget { singleWidget?: string; valueLabels?: Array; } interface BaseFieldWidget> { valuePlaceholder?: string; valueLabel?: string; formatValue?: SerializableType; // with rightFieldDef sqlFormatValue?: SerializableType; // with rightFieldDef spelFormatValue?: SerializableType; // with rightFieldDef //obsolete: validateValue?: SerializableType; //@ui customProps?: AnyObject; factory: SerializableType>; } export interface FieldWidget> extends BaseFieldWidget { valueSrc: "field"; } export interface FuncWidget> extends BaseFieldWidget { valueSrc: "func"; } export type TextWidget> = BaseWidget & TextFieldSettings; export type DateTimeWidget> = RangeableWidget & DateTimeFieldSettings; export type BooleanWidget> = BaseWidget & BooleanFieldSettings; export type NumberWidget> = RangeableWidget & NumberFieldSettings; export type RangeSliderWidget> = RangeableWidget & NumberFieldSettings; export type PriceWidget> = BaseWidget & PriceFieldSettings; export type SelectWidget> = BaseWidget & SelectFieldSettings; export type MultiSelectWidget> = BaseWidget & MultiSelectFieldSettings; export type TreeSelectWidget> = BaseWidget & TreeSelectFieldSettings; export type TreeMultiSelectWidget> = BaseWidget & TreeMultiSelectFieldSettings; /** * @deprecated */ export type CaseValueWidget> = BaseWidget & CaseValueFieldSettings; export type TypedWidget = TextWidget | DateTimeWidget | BooleanWidget | NumberWidget | RangeSliderWidget | PriceWidget | SelectWidget | MultiSelectWidget | TreeSelectWidget | TreeMultiSelectWidget | CaseValueWidget; export type Widget = FieldWidget | FuncWidget | TypedWidget | RangeableWidget | BaseWidget; export type Widgets = TypedMap>; ///////////////// // Conjunctions ///////////////// type FormatConj = (this: ConfigContext, children: ImmutableList, conj: string, not: boolean, isForDisplay?: boolean) => string; type SqlFormatConj = (this: ConfigContext, children: ImmutableList, conj: string, not: boolean) => string; type SpelFormatConj = (this: ConfigContext, children: ImmutableList, conj: string, not: boolean, omitBrackets?: boolean) => string; export interface Conjunction { label: string; formatConj: SerializableType; sqlFormatConj: SerializableType; spelFormatConj: SerializableType; mongoConj: string; jsonLogicConj?: string; sqlConj?: string; spelConj?: string; spelConjs?: string[]; reversedConj?: string; } export type Conjunctions = TypedMap; ///////////////// // ConjsProps // @ui ///////////////// export interface ConjunctionOption { id: string; key: string; label: string; checked: boolean; } export interface ConjsProps { id: string; readonly?: boolean; disabled?: boolean; selectedConjunction?: string; setConjunction: { (conj: string): void; isDummyFn?: boolean; }; conjunctionOptions?: TypedMap; config?: Config; not: boolean; setNot(not: boolean): void; showNot?: boolean; notLabel?: string; } ///////////////// // Operators ///////////////// // tip: for multiselect widget `vals` is always Array, for between/proximity op `vals` can be Array or ImmutableList (only for sql, simple string - TODO: onvert to []) type FormatOperator = (this: ConfigContext, field: FieldPath, op: string, vals: string | string[] | ImmutableList, valueSrc?: ValueSource, valueType?: string, opDef?: Operator, operatorOptions?: OperatorOptionsI, isForDisplay?: boolean, fieldDef?: Field) => string | undefined; type MongoFormatOperator = (this: ConfigContext, field: FieldPath, op: string, vals: MongoValue | Array, not?: boolean, useExpr?: boolean, valueSrc?: ValueSource, valueType?: string, opDef?: Operator, operatorOptions?: OperatorOptionsI, fieldDef?: Field) => MongoQueryObject | undefined; type SqlFormatOperator = (this: ConfigContext, field: FieldPath, op: string, vals: string | string[] | ImmutableList, valueSrc?: ValueSource, valueType?: string, opDef?: Operator, operatorOptions?: OperatorOptionsI, fieldDef?: Field) => string | undefined; type SpelFormatOperator = (this: ConfigContext, field: FieldPath, op: string, vals: string | string[], valueSrc?: ValueSource, valueType?: string, opDef?: Operator, operatorOptions?: OperatorOptionsI, fieldDef?: Field) => string | undefined; type JsonLogicFormatOperator = (this: ConfigContext, field: JsonLogicField, op: string, vals: JsonLogicValue | Array, opDef?: Operator, operatorOptions?: OperatorOptionsI, fieldDef?: Field, expectedType?: string, settings?: Settings) => JsonLogicTree | undefined; type ElasticFormatQueryType = (this: ConfigContext, valueType: string) => ElasticQueryType; interface ProximityConfig { optionLabel: string; optionTextBefore: string; optionPlaceholder: string; minProximity: number; maxProximity: number; defaults: { proximity: number; }; customProps?: AnyObject; } export interface ProximityProps extends ProximityConfig { options: ImmutableMap; setOption: (key: string, value: any) => void; config: C; } export interface ProximityOptions> extends ProximityConfig { //@ui factory?: SerializableType>; } export interface BaseOperator { label: string; reversedOp?: string; isNotOp?: boolean; cardinality?: number; formatOp?: SerializableType; labelForFormat?: string; mongoFormatOp?: SerializableType; sqlOp?: string; sqlOps?: string[]; sqlImport?: SerializableType; sqlFormatOp?: SerializableType; spelOp?: string; spelOps?: string[]; spelFormatOp?: SerializableType; jsonLogic?: string | SerializableType; jsonLogic2?: string; jsonLogicOps?: string[]; _jsonLogicIsExclamationOp?: boolean; elasticSearchQueryType?: ElasticQueryType | SerializableType; valueSources?: Array; valueTypes?: Array; } export interface UnaryOperator extends BaseOperator { //cardinality: 0; } export interface BinaryOperator extends BaseOperator { //cardinality: 1; } export interface Operator2 extends BaseOperator { //cardinality: 2; textSeparators: Array; valueLabels: Array; isSpecialRange?: boolean; } export interface OperatorProximity extends Operator2 { options: ProximityOptions>; } export type Operator = UnaryOperator | BinaryOperator | Operator2 | OperatorProximity; export type Operators = TypedMap>; ///////////////// // Types ///////////////// interface WidgetConfigForType { widgetProps?: Optional; opProps?: Record>; operators?: Array; defaultOperator?: string; valueLabel?: string; valuePlaceholder?: string; } export interface Type { valueSources?: Array; defaultOperator?: string; widgets: TypedMap; mainWidget?: string; excludeOperators?: Array; mainWidgetProps?: Optional; } export type Types = TypedMap; ///////////////// // Fields ///////////////// export interface ListItem { value: string | number; title?: string; disabled?: boolean; isCustom?: boolean; isHidden?: boolean; groupTitle?: string; renderTitle?: string; // internal for MUI } type ListItemSearchableKey = "title" | "value" | "groupTitle"; export interface ListOptionUi extends ListItem { specialValue?: string; } export type ListItems = Array; export interface TreeItem extends ListItem { children?: Array; parent?: any; disabled?: boolean; selectable?: boolean; disableCheckbox?: boolean; checkable?: boolean; path?: Array; } export type TreeData = Array; export type ListValues = TypedMap | TypedKeyMap | Array | Array; export interface AsyncFetchListValuesResult { values: ListItems; hasMore?: boolean; } /* searchOrValues can be a search string or array of exact values */ export type AsyncFetchListValuesFn = (this: ConfigContext | void, searchOrValues: string | Array | null, offset?: number) => Promise; export interface BasicFieldSettings { validateValue?: SerializableType>; valuePlaceholder?: string; } export interface TextFieldSettings extends BasicFieldSettings { maxLength?: number; maxRows?: number; } export interface NumberFieldSettings extends BasicFieldSettings { min?: number; max?: number; step?: number; marks?: {[mark: number]: RenderedReactElement}; } export interface PriceFieldSettings extends NumberFieldSettings { thousandsGroupStyle?: string; thousandSeparator?: string; decimalSeparator?: string; decimalScale?: number; prefix?: string; suffix?: string; allowLeadingZeros?: boolean; fixedDecimalScale?: boolean; allowNegative?: boolean; //todo: add to NumberFieldSettings instead } export interface DateTimeFieldSettings extends BasicFieldSettings { timeFormat?: string; dateFormat?: string; valueFormat?: string; use12Hours?: boolean; useKeyboard?: boolean; // obsolete } export interface SelectFieldSettings extends BasicFieldSettings { listValues?: ListValues; allowCustomValues?: boolean; showSearch?: boolean; searchPlaceholder?: string; showCheckboxes?: boolean; asyncFetch?: SerializableType; useLoadMore?: boolean; useAsyncSearch?: boolean; forceAsyncSearch?: boolean; fetchSelectedValuesOnInit?: boolean; } export interface MultiSelectFieldSettings extends SelectFieldSettings { } export interface TreeSelectFieldSettings extends BasicFieldSettings { treeValues?: TreeData; treeExpandAll?: boolean; treeSelectOnlyLeafs?: boolean; } export interface TreeMultiSelectFieldSettings extends TreeSelectFieldSettings { } export interface BooleanFieldSettings extends BasicFieldSettings { labelYes?: RenderedReactElement; labelNo?: RenderedReactElement; } /** * @deprecated */ export interface CaseValueFieldSettings extends BasicFieldSettings { } // tip: use RuleValue here, TS can't determine correct types in `validateValue` export type FieldSettings = NumberFieldSettings | PriceFieldSettings | DateTimeFieldSettings | SelectFieldSettings | MultiSelectFieldSettings | TreeSelectFieldSettings | TreeMultiSelectFieldSettings | BooleanFieldSettings | TextFieldSettings | BasicFieldSettings; type FieldTypeInConfig = string | "!struct" | "!group"; interface BaseField { type: FieldTypeInConfig; label?: string; tooltip?: string; } interface BaseSimpleField extends BaseField { type: string; preferWidgets?: Array; valueSources?: Array; funcs?: Array; tableName?: string; // legacy: PR #18, PR #20 fieldName?: string; jsonLogicVar?: string; fieldSettings?: FS; defaultValue?: RuleValue; widgets?: TypedMap; mainWidgetProps?: Optional; hideForSelect?: boolean; hideForCompare?: boolean; //obsolete - moved to FieldSettings listValues?: ListValues; allowCustomValues?: boolean; isSpelVariable?: boolean; } interface SimpleField extends BaseSimpleField { label2?: string; operators?: Array; defaultOperator?: string; excludeOperators?: Array; } interface FieldStruct extends BaseField { type: "!struct"; subfields: Fields; isSpelMap?: boolean; } interface FieldGroup> extends BaseField { type: "!group"; subfields: Fields; mode: RuleGroupMode; isSpelArray?: boolean; isSpelItemMap?: boolean; defaultField?: FieldPath; fieldSettings?: FS; } interface FieldGroupExt> extends BaseField { type: "!group"; subfields: Fields; mode: "array"; operators?: Array; defaultOperator?: string; defaultField?: FieldPath; fieldSettings?: FS; initialEmptyWhere?: boolean; showNot?: boolean; conjunctions?: Array; defaultConjunction?: string; maxNesting?: number; maxNumberOfRules?: number; canRegroup?: boolean; canReorder?: boolean; isSpelArray?: boolean; isSpelItemMap?: boolean; } export type Field = SimpleField; export type FieldOrGroup = FieldStruct | FieldGroup | FieldGroupExt | Field; export type Fields = TypedMap; export type FieldConfig = Field | Func; export type FieldValueOrConfig = FieldConfig | AnyFieldValue | null; export type FieldConfigExt = Field & Type; export type FuncConfigExt = Func & Type; export type NumberField = SimpleField; export type PriceField = SimpleField; export type DateTimeField = SimpleField; export type SelectField = SimpleField; export type MultiSelectField = SimpleField; export type TreeSelectField = SimpleField; export type TreeMultiSelectField = SimpleField; export type BooleanField = SimpleField; export type TextField = SimpleField; ///////////////// // Settings ///////////////// type SpelFieldMeta = { key: string; parent: "map" | "class" | "[class]" | "[map]" | null; isSpelVariable?: boolean; }; type ValueSourcesInfo = {[vs in ValueSource]?: {label: string, widget?: string}}; type ChangeFieldStrategy = "default" | "keep" | "first" | "none"; type FormatReverse = (this: ConfigContext, q: string, op: string, reversedOp: string, operatorDefinition: Operator, revOperatorDefinition: Operator, isForDisplay: boolean) => string; type SqlFormatReverse = (this: ConfigContext, q: string) => string; type SpelFormatReverse = (this: ConfigContext, q: string) => string; type FormatField = (this: ConfigContext, field: FieldPath, parts: Array, label2: string, fieldDefinition: Field, config: Config, isForDisplay: boolean) => string; type FormatSpelField = (this: ConfigContext, field: FieldPath, parentField: FieldPath | null, parts: Array, partsExt: Array, fieldDefinition: Field, config: Config) => string; type CanCompareFieldWithField = (this: ConfigContext, leftField: FieldPath, leftFieldConfig: Field, rightField: FieldPath, rightFieldConfig: Field, op: string) => boolean; type FormatAggr = (this: ConfigContext, whereStr: string, aggrField: FieldPath, operator: string, value: string | ImmutableList, valueSrc: ValueSource, valueType: string, opDef: Operator, operatorOptions: OperatorOptionsI, isForDisplay: boolean, aggrFieldDef: Field) => string; export interface LocaleTranslations { valueLabel?: string; valuePlaceholder?: string; fieldLabel?: string; operatorLabel?: string; fieldPlaceholder?: string; funcPlaceholder?: string; funcLabel?: string; operatorPlaceholder?: string; lockLabel?: string; lockedLabel?: string; deleteLabel?: string; addGroupLabel?: string; addCaseLabel?: string; addDefaultCaseLabel?: string; defaultCaseLabel?: string; addRuleLabel?: string; addSubRuleLabel?: string; addSubGroupLabel?: string; delGroupLabel?: string; notLabel?: string; fieldSourcesPopupTitle?: string; valueSourcesPopupTitle?: string; removeRuleConfirmOptions?: { title?: string; okText?: string; okType?: string; cancelText?: string; }; removeGroupConfirmOptions?: { title?: string; okText?: string; okType?: string; cancelText?: string; }; loadMoreLabel?: string; loadingMoreLabel?: string; typeToSearchLabel?: string; loadingLabel?: string; notFoundLabel?: string; } export interface LocaleSettings extends LocaleTranslations { locale?: { moment?: string; antd?: Record; material?: Record; mui?: Record; }; } export interface BehaviourSettings { reverseOperatorsForNot?: boolean; canShortMongoQuery?: boolean; fixJsonLogicDateCompareOp?: boolean; defaultField?: AnyFieldValue; defaultOperator?: string; defaultConjunction?: string; fieldSources?: Array; valueSourcesInfo?: ValueSourcesInfo; canCompareFieldWithField?: SerializableType; canReorder?: boolean; canRegroup?: boolean; canRegroupCases?: boolean; showNot?: boolean; showLock?: boolean; canDeleteLocked?: boolean; maxNesting?: number; setOpOnChangeField: Array; clearValueOnChangeField?: boolean; clearValueOnChangeOp?: boolean; canLeaveEmptyGroup?: boolean; canLeaveEmptyCase?: boolean; shouldCreateEmptyGroup?: boolean; forceShowConj?: boolean; immutableGroupsMode?: boolean; immutableFieldsMode?: boolean; immutableOpsMode?: boolean; immutableValuesMode?: boolean; maxNumberOfRules?: number; maxNumberOfCases?: number; showErrorMessage?: boolean; convertableWidgets?: TypedMap>; exportPreserveGroups?: boolean; removeEmptyGroupsOnLoad?: boolean; removeEmptyRulesOnLoad?: boolean; removeIncompleteRulesOnLoad?: boolean; removeInvalidMultiSelectValuesOnLoad?: boolean; groupOperators?: Array; useConfigCompress?: boolean; keepInputOnChangeFieldSrc?: boolean; fieldItemKeysForSearch?: FieldItemSearchableKey[]; listKeysForSearch?: ListItemSearchableKey[]; sqlDialect?: SqlDialect; } export interface OtherSettings { caseValueField?: Field; fieldSeparator?: string; fieldSeparatorDisplay?: string; formatReverse?: SerializableType; sqlFormatReverse?: SerializableType; spelFormatReverse?: SerializableType; formatField?: SerializableType; formatSpelField?: SerializableType; formatAggr?: SerializableType; } export interface Settings extends LocaleSettings, BehaviourSettings, OtherSettings { } ///////////////// // Funcs ///////////////// export type SqlFormatFunc = (this: ConfigContext, formattedArgs: TypedMap, sqlDialect?: SqlDialect) => string; export type SqlImportFunc = (this: ConfigContext, sql: SqlOutLogic, wgtDef?: Widget, sqlDialect?: SqlDialect) => Record | undefined; // can throw, should return {func?, args: {}} or {operator?, children: []} export type FormatFunc = (this: ConfigContext, formattedArgs: TypedMap, isForDisplay: boolean) => string; export type MongoFormatFunc = (this: ConfigContext, formattedArgs: TypedMap) => MongoValue; export type JsonLogicFormatFunc = (this: ConfigContext, formattedArgs: TypedMap) => JsonLogicTree; export type JsonLogicImportFunc = (this: ConfigContext, val: JsonLogicValue) => Array | undefined; // can throw export type SpelImportFunc = (this: ConfigContext, spel: SpelRawValue) => Record | undefined; // can throw export type SpelFormatFunc = (this: ConfigContext, formattedArgs: TypedMap) => string; interface FuncGroup extends BaseField { type: "!struct"; subfields: TypedMap; } // todo: uses `returnType` instead of `type` for now, but should be revisited to use `type` export interface Func extends Omit { returnType: string; args: TypedMap; sqlFunc?: string; spelFunc?: string; mongoFunc?: string; mongoArgsAsObject?: boolean; jsonLogic?: string | SerializableType; // Deprecated! // Calling methods on objects was remvoed in JsonLogic 2.x // https://github.com/jwadhams/json-logic-js/issues/86 jsonLogicIsMethod?: boolean; jsonLogicImport?: SerializableType; spelImport?: SerializableType; formatFunc?: SerializableType; sqlFormatFunc?: SerializableType; sqlImport?: SerializableType; mongoFormatFunc?: SerializableType; renderBrackets?: Array; renderSeps?: Array; spelFormatFunc?: SerializableType; allowSelfNesting?: boolean; } export interface FuncArg extends BaseSimpleField { isOptional?: boolean; showPrefix?: boolean; } export type FuncOrGroup = Func | FuncGroup; export type Funcs = TypedMap; ///////////////// // CoreConfig ///////////////// export interface CoreOperators extends Operators { equal: BinaryOperator; not_equal: BinaryOperator; less: BinaryOperator; less_or_equal: BinaryOperator; greater: BinaryOperator; greater_or_equal: BinaryOperator; like: BinaryOperator; not_like: BinaryOperator; starts_with: BinaryOperator; ends_with: BinaryOperator; between: Operator2; not_between: Operator2; is_null: UnaryOperator; is_not_null: UnaryOperator; is_empty: UnaryOperator; is_not_empty: UnaryOperator; select_equals: BinaryOperator; select_not_equals: BinaryOperator; select_any_in: BinaryOperator; select_not_any_in: BinaryOperator; multiselect_contains: BinaryOperator; multiselect_not_contains: BinaryOperator; multiselect_equals: BinaryOperator; multiselect_not_equals: BinaryOperator; proximity: OperatorProximity; } export interface CoreConjunctions extends Conjunctions { AND: Conjunction; OR: Conjunction; } export interface CoreWidgets extends Widgets { text: TextWidget; textarea: TextWidget; number: NumberWidget; slider: NumberWidget; price: PriceWidget; rangeslider: RangeSliderWidget; select: SelectWidget; multiselect: MultiSelectWidget; treeselect: TreeSelectWidget; treemultiselect: TreeMultiSelectWidget; date: DateTimeWidget; time: DateTimeWidget; datetime: DateTimeWidget; boolean: BooleanWidget; field: FieldWidget; func: FuncWidget; /** * @deprecated */ case_value: CaseValueWidget; } export interface CoreTypes extends Types { text: Type; number: Type; date: Type; time: Type; datetime: Type; select: Type; multiselect: Type; treeselect: Type; treemultiselect: Type; boolean: Type; case_value: Type; } export interface CoreConfig extends Config { conjunctions: CoreConjunctions; operators: CoreOperators; widgets: CoreWidgets; types: CoreTypes; settings: Settings; ctx: ConfigContext; } ///////////////// export declare const Utils: Utils; export declare const CoreConfig: CoreConfig; export declare const BasicFuncs: Funcs; export declare const TreeStore: TreeStore; export declare const TreeActions: TreeActions; export declare const Immutable: any;