UNPKG

qb-field

Version:

A lightweight abstraction layer for Quick Base

156 lines (155 loc) 6.07 kB
import { QuickBase, QuickBaseOptions, QuickBaseRequest, QuickBaseResponseDeleteFields, QuickBaseResponseGetField, QuickBaseResponseGetFieldUsage } from 'quickbase'; export declare class QBField<CustomGetSet extends Object = Record<any, any>> { readonly CLASS_NAME = "QBField"; static readonly CLASS_NAME = "QBField"; static readonly VERSION: string; /** * The default settings of a `QuickBase` instance */ static defaults: QBFieldOptions; /** * An internal id (guid) used for tracking/managing object instances */ id: string; private _qb; private _tableId; private _fid; private _data; private _usage; constructor(options?: Partial<QBFieldOptions>); /** * This method clears the QBField instance of any trace of the existing field, but preserves defined connection settings. */ clear(): this; /** * This method deletes the field from QuickBase, then calls `.clear()`. */ delete({ requestOptions }?: QuickBaseRequest): Promise<QuickBaseResponseDeleteFields>; /** * Get an attribute value * * @param attribute Quick Base Field attribute name */ get(attribute: 'tableId'): string; get(attribute: 'fid'): number; get(attribute: 'id'): number; get(attribute: 'type'): string; get(attribute: 'addToForms'): boolean; get(attribute: 'usage'): QuickBaseResponseGetFieldUsage[0]['usage']; get<P extends keyof QuickBaseResponseGetField>(prop: P): QuickBaseResponseGetField[P]; get<P extends keyof CustomGetSet>(prop: P): CustomGetSet[P]; get<P extends string>(prop: P): P extends keyof QuickBaseResponseGetField ? QuickBaseResponseGetField[P] : (P extends keyof CustomGetSet ? CustomGetSet[P] : any); /** * Get the set QBField Field ID */ getFid(): number; /** * Get the set QBField Table ID */ getTableId(): string; getTempToken({ requestOptions }?: QuickBaseRequest): Promise<void>; /** * Get the Quick Base Field usage * * `.loadUsage()` must be called first */ getUsage(): QuickBaseResponseGetFieldUsage[0]['usage']; /** * Load the Quick Base Field attributes and permissions */ load({ requestOptions }?: QuickBaseRequest): Promise<QuickBaseResponseGetField>; /** * Load the Quick Base Field usage */ loadUsage({ requestOptions }?: QuickBaseRequest): Promise<QuickBaseResponseGetFieldUsage[0]['usage']>; /** * If a field id is not defined, this will execute the createField option. After a successful * createField, or if a field id was previously defined, this will execute an updateField. * * If `attributesToSave` is defined, then only configured attributes in this array will be saved. * * If this executes a createField, the newly assigned Field ID is automatically stored internally. * * After a successful save, all new attributes are available for use. * * @param attributesToSave Array of attributes to save */ save({ attributesToSave, requestOptions }?: QuickBaseRequest & { attributesToSave?: QBFieldAttributeSavable[]; }): Promise<QuickBaseResponseGetField>; /** * Sets the passed in `value` associated with the `attribute` argument. * * @param attribute Quick Base Field attribute name * @param value Attribute value */ set(attribute: 'tableId', value: string): this; set(attribute: 'fid', value: number): this; set(attribute: 'id', value: number): this; set(attribute: 'type', value: string): this; set(attribute: 'addToForms', value: boolean): this; set(attribute: 'usage', value: QuickBaseResponseGetFieldUsage[0]['usage']): this; set<P extends keyof QuickBaseResponseGetField>(prop: P, value: QuickBaseResponseGetField[P]): void; set<P extends keyof CustomGetSet>(prop: P, value: CustomGetSet[P]): void; set<P extends string>(prop: P, value: P extends keyof QuickBaseResponseGetField ? QuickBaseResponseGetField[P] : (P extends keyof CustomGetSet ? CustomGetSet[P] : any)): void; /** * Sets the defined Field ID * * An alias for `.set('id', 6)` and `.set('fid', 6)`. * * @param fid Quick Base Field ID */ setFid(fid: number): this; /** * Sets the defined Table ID * * An alias for `.set('tableId', 'xxxxxxxxx')`. * * @param tableId Quick Base Field Table ID */ setTableId(tableId: string): this; /** * Rebuild the QBField instance from serialized JSON * * @param json QBField serialized JSON */ fromJSON(json: string | QBFieldJSON): this; /** * Serialize the QBField instance into JSON */ toJSON(): QBFieldJSON; /** * Create a new QBField instance from serialized JSON * * @param json QBField serialized JSON */ static fromJSON(json: string | QBFieldJSON): QBField; /** * Test if a variable is a `qb-field` object * * @param obj A variable you'd like to test */ static IsQBField(obj: any): obj is QBField; /** * Returns a new QBField instance built off of `options`, that inherits configuration data from the passed in `attributes` argument. * * @param options QBField instance options * @param attributes Quick Base Field attribute data */ static NewField(options: Partial<QBFieldOptions>, attributes?: Partial<QuickBaseResponseGetField> & Record<any, any>): QBField; } export declare type QBFieldAttribute = keyof QuickBaseResponseGetField; export declare type QBFieldAttributeSavable = Exclude<QBFieldAttribute, 'usage' | 'type' | 'doesDataCopy' | 'fid'>; export declare type QBFieldOptions = { quickbase: QuickBaseOptions | QuickBase; tableId: string; fid: number; }; export declare type QBFieldJSON = { quickbase?: QuickBaseOptions; tableId: string; fid: number; id?: number; data?: Partial<QuickBaseResponseGetField> & Record<any, any>; usage?: QuickBaseResponseGetFieldUsage[0]['usage']; };