import { RuleLike } from '@xh/hoist/data/validation/Types'; import { Rule } from './validation/Rule'; /** * Constructor arguments for a Hoist data package Field. */ export interface FieldSpec { /** Unique key representing this field. */ name: string; /** default `'auto` indicates no conversion.*/ type?: FieldType; /** * User-facing / longer name for display, defaults to `name` * transformed via `genDisplayName()` (e.g. 'myField' translates to 'My Field'). */ displayName?: string; /** Supplementary descriptive text for this field, for use in tooltips and other UI. */ description?: string; /** Value to be used for records with a null, or non-existent value. */ defaultValue?: any; /** True if this field is intended to be used for grouping. Defaults to false. */ isDimension?: boolean; /** Rules to apply to this field. */ rules?: RuleLike[]; /** * True to enable built-in XSS (cross-site scripting) protection to all incoming String values * using {@link https://github.com/cure53/DOMPurify | DOMPurify}. * * DOMPurify provides fast escaping of dangerous HTML, scripting, and other content that can be * used to execute XSS attacks, while allowing common and expected HTML and style tags. * * This feature does exact a minor performance penalty during data parsing, which can be * significant in aggregate for very large stores containing records with many `string` fields. * * For extra safety, apps which are open to potentially-untrusted users or display other * potentially dangerous string content can opt into this setting app-wide via * {@link AppSpec.enableXssProtection}. Field-level setting will override any app-level default. * * Note: this flag and its default behavior was changed as of Hoist v77 to be `false`, i.e. * Store-level XSS protection *disabled* by default, in keeping with Hoist's primary use-case: * building secured internal apps with large datasets and tight performance tolerances. */ enableXssProtection?: boolean; } /** * Metadata for an individual data field within a {@link StoreRecord}. * * @mcpHint metadata for a data field within a Store or Cube */ export declare class Field { get isField(): boolean; readonly name: string; readonly type: FieldType; readonly displayName: string; readonly description: string; readonly defaultValue: any; readonly isDimension: boolean; readonly rules: Rule[]; readonly enableXssProtection: boolean; constructor({ name, type, displayName, description, defaultValue, isDimension, rules, enableXssProtection }: FieldSpec); parseVal(val: any): any; isEqual(val1: any, val2: any): boolean; private processRuleSpecs; } /** * Parse a value according to a field type. * @param val - raw value to parse. * @param type - data type of the field to use for possible conversion. * @param defaultValue - typed value to return if `val` undefined or null. * @param enableXssProtection - true to enable XSS (cross-site scripting) protection. * See {@link FieldSpec.enableXssProtection} for additional details. * @returns resulting value, potentially parsed or cast as per type. */ export declare function parseFieldValue(val: any, type: FieldType, defaultValue?: any, enableXssProtection?: boolean): any; /** Data types for Fields used within Hoist Store Records and Cubes. */ export declare const FieldType: Readonly<{ TAGS: "tags"; AUTO: "auto"; BOOL: "bool"; DATE: "date"; INT: "int"; JSON: "json"; LOCAL_DATE: "localDate"; NUMBER: "number"; PWD: "pwd"; STRING: "string"; }>; export type FieldType = (typeof FieldType)[keyof typeof FieldType]; /** * @param fieldName - short name / code for a field. * @returns fieldName transformed into user-facing / longer name for display. */ export declare function genDisplayName(fieldName: string): string; /** Convenience function to return the name of a field from one of several common inputs. */ export declare function getFieldName(field: string | Field | FieldSpec): string;