/** @module @airtable/blocks/models: Field */ /** */ import { AggregatorKey } from '../types/aggregators'; import { PermissionCheckResult, UpdateFieldOptionsOpts } from '../types/mutations'; import { FieldData, FieldType, FieldOptions, FieldConfig } from '../types/field'; import { ObjectValues } from '../private_utils'; import { FieldTypeConfig } from '../types/airtable_interface'; import AbstractModel from './abstract_model'; import { Aggregator } from './create_aggregators'; declare const WatchableFieldKeys: Readonly<{ name: "name"; type: "type"; options: "options"; isComputed: "isComputed"; description: "description"; isFieldSynced: "isFieldSynced"; }>; /** * All the watchable keys in a field. * - `name` * - `type` * - `options` * - `isComputed` * - `description` */ export 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 { /** * 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; _getCachedConfigFromFieldTypeProvider(): FieldTypeConfig; _clearCachedConfig(): void; /** * 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 field, * `{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 extension. * * 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; /** * Checks whether the current user has permission to perform the given name update. * * Accepts partial input, in the same format as {@link updateNameAsync}. * * Returns `{hasPermission: true}` if the current user can update the specified field, * `{hasPermission: false, reasonDisplayString: string}` otherwise. `reasonDisplayString` may be * used to display an error message to the user. * * @param name new name for the field * * @example * ```js * const updateFieldCheckResult = field.checkPermissionsForUpdateName(); * * if (!updateFieldCheckResult.hasPermission) { * alert(updateFieldCheckResult.reasonDisplayString); * } * ``` */ checkPermissionsForUpdateName(name?: string): PermissionCheckResult; /** * An alias for `checkPermissionsForUpdateName(options).hasPermission`. * * Checks whether the current user has permission to perform the name update. * * Accepts partial input, in the same format as {@link updateNameAsync}. * * @param name new name for the field * * @example * ```js * const canUpdateField = field.hasPermissionToUpdateName(); * * if (!canUpdateField) { * alert('not allowed!'); * } * ``` */ hasPermissionToUpdateName(name?: string): boolean; /** * Updates the name for this field. * * Throws an error if the user does not have permission to update the field, or if an invalid * name is provided. * * This action is asynchronous. Unlike updates to cell values, updates to field name are * **not** applied optimistically locally. You must `await` the returned promise before * relying on the change in your extension. * * @param name new name for the field * * @example * ```js * await myTextField.updateNameAsync('My New Name'); * ``` */ updateNameAsync(name: string): Promise; /** * Checks whether the current user has permission to perform the given description update. * * Accepts partial input, in the same format as {@link updateDescriptionAsync}. * * Returns `{hasPermission: true}` if the current user can update the specified field, * `{hasPermission: false, reasonDisplayString: string}` otherwise. `reasonDisplayString` may be * used to display an error message to the user. * * @param description new description for the field * * @example * ```js * const updateFieldCheckResult = field.checkPermissionsForUpdateDescription(); * * if (!updateFieldCheckResult.hasPermission) { * alert(updateFieldCheckResult.reasonDisplayString); * } * ``` */ checkPermissionsForUpdateDescription(description?: string | null): PermissionCheckResult; /** * An alias for `checkPermissionsForUpdateDescription(options).hasPermission`. * * Checks whether the current user has permission to perform the description update. * * Accepts partial input, in the same format as {@link updateDescriptionAsync}. * * @param description new description for the field * * @example * ```js * const canUpdateField = field.hasPermissionToUpdateDescription(); * * if (!canUpdateField) { * alert('not allowed!'); * } * ``` */ hasPermissionToUpdateDescription(description?: string | null): boolean; /** * Updates the description for this field. * * To remove an existing description, pass `''` as the new description. * `null` is also accepted and will be coerced to `''` for consistency with field creation. * * Throws an error if the user does not have permission to update the field, or if an invalid * description is provided. * * This action is asynchronous. Unlike updates to cell values, updates to field descriptions are * **not** applied optimistically locally. You must `await` the returned promise before * relying on the change in your extension. * * @param description new description for the field * * @example * ```js * await myTextField.updateDescriptionAsync('This is a text field'); * ``` */ updateDescriptionAsync(description: string | null): Promise; /** * `true` if this field is synced, `false` otherwise. A field is * "synced" if it's source is from another airtable base or external data source * like Google Calendar, Jira, etc.. * * @hidden */ get isFieldSynced(): boolean; /** * `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; } export default Field; //# sourceMappingURL=field.d.ts.map