/** @module @airtable/blocks/models: Record */ /** */ import { Color } from '../colors'; import Sdk from '../sdk'; import { RecordData } from '../types/record'; import { FieldId } from '../types/field'; import { ViewId } from '../types/view'; import { ObjectValues, FlowAnyObject } from '../private_utils'; import AbstractModel from './abstract_model'; import Field from './field'; import ObjectPool from './object_pool'; import Table from './table'; import View from './view'; import { RecordQueryResultOpts } from './record_query_result'; import LinkedRecordsQueryResult from './linked_records_query_result'; import RecordStore from './record_store'; declare const WatchableRecordKeys: Readonly<{ name: "name"; commentCount: "commentCount"; cellValues: "cellValues"; }>; /** * Any key within record that can be watched: * - `'name'` * - `'commentCount'` * - `'cellValues'` * - `'cellValueInField:' + someFieldId` * - `'colorInView:' + someViewId` */ declare type WatchableRecordKey = ObjectValues | string; /** * Model class representing a record in a table. * * Do not instantiate. You can get instances of this class by calling `table.selectRecords` * or `view.selectRecords` and using the resulting {@link RecordQueryResult}. * * @docsPath models/Record */ declare class Record extends AbstractModel { /** @internal */ static _className: string; /** @internal */ static _isWatchableKey(key: string): boolean; /** @internal */ _parentRecordStore: RecordStore; /** @internal */ _parentTable: Table; /** @internal */ __linkedRecordsQueryResultPool: ObjectPool; /** * @internal */ constructor(sdk: Sdk, parentRecordStore: RecordStore, parentTable: Table, recordId: string); /** * @internal */ get _dataOrNullIfDeleted(): RecordData | null; /** * The table that this record belongs to. Should never change because records aren't moved between tables. * * @internal (since we may not be able to return parent model instances in the immutable models world) * @example * ```js * import {useRecords} from '@airtable/blocks/ui'; * const records = useRecords(myTable); * console.log(records[0].parentTable.id === myTable.id); * // => true * ``` */ get parentTable(): Table; /** * @internal */ _getFieldMatching(fieldOrFieldIdOrFieldName: Field | string): Field; /** * @internal */ _getViewMatching(viewOrViewIdOrViewName: View | string): View; /** * @internal * * For use when we need the raw public API cell value. Specifically makes a difference * for lookup fields, where we translate the format to a blocks-specific format in getCellValue. * That format is incompatible with fieldTypeProvider methods, which expect the public API * format - use _getRawCellValue instead. */ _getRawCellValue(field: Field): unknown; /** * Gets the cell value of the given field for this record. * * @param fieldOrFieldIdOrFieldName The field (or field ID or field name) whose cell value you'd like to get. * @example * ```js * const cellValue = myRecord.getCellValue(mySingleLineTextField); * console.log(cellValue); * // => 'cell value' * ``` */ getCellValue(fieldOrFieldIdOrFieldName: Field | FieldId | string): unknown; /** * Gets the cell value of the given field for this record, formatted as a `string`. * * @param fieldOrFieldIdOrFieldName The field (or field ID or field name) whose cell value you'd like to get. * @example * ```js * const stringValue = myRecord.getCellValueAsString(myNumberField); * console.log(stringValue); * // => '42' * ``` */ getCellValueAsString(fieldOrFieldIdOrFieldName: Field | FieldId | string): string; /** * Returns a URL that is suitable for rendering an attachment on the current client. * The URL that is returned will only work for the current user. * * @param attachmentId The ID of the attachment. * @param attachmentUrl The attachment's URL (which is not suitable for rendering on the client). * @example * ```js * import React from 'react'; * * function RecordAttachments(props) { * const {record, attachmentField} = props; * const attachmentCellValue = record.getCellValue(attachmentField); * if (attachmentCellValue === null) { * return null; * } * return ( *
* {attachmentCellValue.map(attachmentObj => { * const clientUrl = * record.getAttachmentClientUrlFromCellValueUrl( * attachmentObj.id, * attachmentObj.url * ); * return ( * * ); * })} *
* ); * } * ``` */ getAttachmentClientUrlFromCellValueUrl(attachmentId: string, attachmentUrl: string): string; /** * Gets the color of this record in a given view, or null if the record has no color in that * view. * * Can be watched with the 'colorInView:${ViewId}' key. * * @param viewOrViewIdOrViewName The view (or view ID or view name) to use for record coloring. */ getColorInView(viewOrViewIdOrViewName: View | ViewId | string): Color | null; /** * Gets the CSS hex string for this record in a given view, or null if the record has no color * in that view. * * Can be watched with the 'colorInView:${ViewId}' key. * * @param viewOrViewIdOrViewName The view (or view ID or view name) to use for record coloring. */ getColorHexInView(viewOrViewIdOrViewName: View | string): string | null; /** * Select records referenced in a `multipleRecordLinks` cell value. Returns a query result * containing the records in the given `multipleRecordLinks` field. * See {@link RecordQueryResult} for more. * * @param fieldOrFieldIdOrFieldName The `multipleRecordLinks` field (or field ID or field name) to use. * @param opts Options for the query, such as sorts and fields. */ selectLinkedRecordsFromCell(fieldOrFieldIdOrFieldName: Field | FieldId | string, opts?: RecordQueryResultOpts): LinkedRecordsQueryResult; /** * Select and load records referenced in a `multipleRecordLinks` cell value. Returns a query result * promise containing the records in the given `multipleRecordLinks` field. * See {@link RecordQueryResult} for more. * * Remember to call `queryResult.unloadData` once you're finished with the query. * * @param fieldOrFieldIdOrFieldName The `multipleRecordLinks` field (or field ID or field name) to use. * @param opts Options for the query, such as sorts and fields. */ selectLinkedRecordsFromCellAsync(fieldOrFieldIdOrFieldName: Field | FieldId | string, opts?: RecordQueryResultOpts): Promise; /** * The URL for the record. You can visit this URL in the browser to be taken to the record in the Airtable UI. * * @example * ```js * console.log(myRecord.url); * // => 'https://airtable.com/tblxxxxxxxxxxxxxx/recxxxxxxxxxxxxxx' * ``` */ get url(): string; /** * The primary cell value in this record, formatted as a `string`. * * @example * ```js * console.log(myRecord.name); * // => '42' * ``` */ get name(): string; /** * The number of comments on this record. * * @example * ```js * const commentCount = myRecord.commentCount; * const isSingular = commentCount === 1; * console.log( * `This record has ${commentCount} comment${isSingular ? '' : 's'}` * ); * ``` */ get commentCount(): number; /** * The created time of this record. * * @example * ```js * console.log(` * This record was created at ${myRecord.createdTime.toISOString()} * `); * ``` */ get createdTime(): Date; /** * @internal */ __triggerOnChangeForDirtyPaths(dirtyPaths: FlowAnyObject): void; /** * @internal */ __triggerOnChangeForRecordColorInViewId(viewId: string): void; } export default Record;