/** @module @airtable/blocks/models: Field */ /** */ import { AggregatorKey } from "../types/aggregators"; import Sdk from "../sdk"; import { PermissionCheckResult, UpdateFieldOptionsOpts } from "../types/mutations"; import { FieldData, FieldType, FieldOptions, FieldConfig } from "../types/field"; import { ObjectValues, FlowAnyObject } from "../private_utils"; import AbstractModel from "./abstract_model"; import { Aggregator } from "./create_aggregators"; import Table from "./table"; declare const WatchableFieldKeys: Readonly<{ name: "name"; type: "type"; options: "options"; isComputed: "isComputed"; description: "description"; }>; /** * All the watchable keys in a field. * - `name` * - `type` * - `options` * - `isComputed` * - `description` */ export declare type WatchableFieldKey = ObjectValues; /** * Model class representing a field in a table. * * @example * ```js * import {base} from '@airtable/blocks'; * * const table = base.getTableByName('Table 1'); * const field = table.getFieldByName('Name'); * console.log('The type of this field is', field.type); * ``` * @docsPath models/Field */ declare class Field extends AbstractModel { /** @internal */ static _className: string; /** @internal */ static _isWatchableKey(key: string): boolean; /** @internal */ _parentTable: Table; /** * @internal */ constructor(sdk: Sdk, parentTable: Table, fieldId: string); /** * @internal */ get _dataOrNullIfDeleted(): FieldData | null; /** * The table that this field belongs to. Should never change because fields aren't moved between tables. * * @internal (since we may not be able to return parent model instances in the immutable models world) * @example * ```js * const field = myTable.getFieldByName('Name'); * console.log(field.parentTable.id === myTable.id); * // => true * ``` */ get parentTable(): Table; /** * The name of the field. Can be watched. * * @example * ```js * console.log(myField.name); * // => 'Name' * ``` */ get name(): string; /** * The type of the field. Can be watched. * * @example * ```js * console.log(myField.type); * // => 'singleLineText' * ``` */ get type(): FieldType; /** * The configuration options of the field. The structure of the field's * options depend on the field's type. `null` if the field has no options. * Can be watched. * * @see {@link FieldType} * @example * ```js * import {FieldType} from '@airtable/blocks/models'; * * if (myField.type === FieldType.CURRENCY) { * console.log(myField.options.symbol); * // => '$' * } * ``` */ get options(): FieldOptions | null; /** * The type and options of the field to make type narrowing `FieldOptions` easier. * * @see {@link FieldConfig} * @example * const fieldConfig = field.config; * if (fieldConfig.type === FieldType.SINGLE_SELECT) { * return fieldConfig.options.choices; * } else if (fieldConfig.type === FieldType.MULTIPLE_LOOKUP_VALUES && fieldConfig.options.isValid) { * if (fieldConfig.options.result.type === FieldType.SINGLE_SELECT) { * return fieldConfig.options.result.options.choices; * } * } * return DEFAULT_CHOICES; */ get config(): FieldConfig; /** * Checks whether the current user has permission to perform the given options update. * * Accepts partial input, in the same format as {@link updateOptionsAsync}. * * Returns `{hasPermission: true}` if the current user can update the specified record, * `{hasPermission: false, reasonDisplayString: string}` otherwise. `reasonDisplayString` may be * used to display an error message to the user. * * @param options new options for the field * * @example * ```js * const updateFieldCheckResult = field.checkPermissionsForUpdateOptions(); * * if (!updateFieldCheckResult.hasPermission) { * alert(updateFieldCheckResult.reasonDisplayString); * } * ``` */ checkPermissionsForUpdateOptions(options?: FieldOptions): PermissionCheckResult; /** * An alias for `checkPermissionsForUpdateOptions(options).hasPermission`. * * Checks whether the current user has permission to perform the options update. * * Accepts partial input, in the same format as {@link updateOptionsAsync}. * * @param options new options for the field * * @example * ```js * const canUpdateField = field.hasPermissionToUpdateOptions(); * * if (!canUpdateField) { * alert('not allowed!'); * } * ``` */ hasPermissionToUpdateOptions(options?: FieldOptions): boolean; /** * Updates the options for this field. * * Throws an error if the user does not have permission to update the field, if invalid * options are provided, if this field has no writable options, or if updates to this field * type is not supported. * * Refer to {@link FieldType} for supported field types, the write format for options, and * other specifics for certain field types. * * This action is asynchronous. Unlike updates to cell values, updates to field options are * **not** applied optimistically locally. You must `await` the returned promise before * relying on the change in your app. * * Optionally, you can pass an `opts` object as the second argument. See {@link UpdateFieldOptionsOpts} * for available options. * * @param options new options for the field * @param opts optional options to affect the behavior of the update * * @example * ```js * async function addChoiceToSelectField(selectField, nameForNewOption) { * const updatedOptions = { * choices: [ * ...selectField.options.choices, * {name: nameForNewOption}, * ] * }; * * if (selectField.hasPermissionToUpdateOptions(updatedOptions)) { * await selectField.updateOptionsAsync(updatedOptions); * } * } * ``` */ updateOptionsAsync(options: FieldOptions, opts?: UpdateFieldOptionsOpts): Promise; /** * `true` if this field is computed, `false` otherwise. A field is * "computed" if it's value is not set by user input (e.g. autoNumber, formula, * etc.). Can be watched * * @example * ```js * console.log(mySingleLineTextField.isComputed); * // => false * console.log(myAutoNumberField.isComputed); * // => true * ``` */ get isComputed(): boolean; /** * `true` if this field is its parent table's primary field, `false` otherwise. * Should never change because the primary field of a table cannot change. */ get isPrimaryField(): boolean; /** * The description of the field, if it has one. Can be watched. * * @example * ```js * console.log(myField.description); * // => 'This is my field' * ``` */ get description(): string | null; /** * A list of available aggregators given this field's configuration. * * @example * ```js * const fieldAggregators = myField.availableAggregators; * ``` */ get availableAggregators(): Array; /** * Checks if the given aggregator is available for this field. * * @param aggregator The aggregator object or aggregator key. * @example * ```js * import {aggregators} from '@airtable/blocks/models'; * const aggregator = aggregators.totalAttachmentSize; * * // Using an aggregator object * console.log(myAttachmentField.isAggregatorAvailable(aggregator)); * // => true * * // Using an aggregator key * console.log(myTextField.isAggregatorAvailable('totalAttachmentSize')); * // => false * ``` */ isAggregatorAvailable(aggregator: Aggregator | AggregatorKey): boolean; /** * Attempt to parse a given string and return a valid cell value for the field's current config. * Returns `null` if unable to parse the given string. * * @param string The string to parse. * @example * ```js * const inputString = '42'; * const cellValue = myNumberField.convertStringToCellValue(inputString); * console.log(cellValue === 42); * // => true * ``` */ convertStringToCellValue(string: string): unknown; /** * @internal */ __triggerOnChangeForDirtyPaths(dirtyPaths: FlowAnyObject): void; } export default Field;