@flatfile/records
Version:
Record management utilities for Flatfile
94 lines (93 loc) • 3.18 kB
TypeScript
import * as util from "util";
import { FlatfileTypes, SimpleRecord } from "./RecordUtils";
type CastingMethod = "str" | "defStr" | "bool" | "num" | "date";
export declare class FlatfileRecord<T extends Record<string, any> = Record<string, any>> {
data: Readonly<Partial<T>>;
private _changes;
private _errs;
private _metadata;
private _deleted;
private _tempId?;
private _info;
private _warns;
constructor(data: Readonly<Partial<T>>, dirty?: boolean);
get id(): string | NonNullable<Partial<T>[string]> | undefined;
get meta(): Record<string, any>;
get slug(): Partial<T>[string];
get sheetId(): Partial<T>[string];
getLinks(key?: string): any;
set(key: string, value: any): this | undefined;
flag(key: string): void;
unflag(key: string): void;
get(key: string): any;
has(key: string): boolean;
hasAny(...keys: string[]): boolean;
hasAll(...keys: string[]): boolean;
isEmpty(key: string): boolean;
keys(options?: {
omit?: string[];
pick?: string[];
}): string[];
keysWithData(props?: {
exclude?: Array<string | string[]>;
}): string[];
intersects(item: FlatfileRecord, keys: string[]): boolean;
hash(...keys: string[]): string;
isDirty(key?: string): boolean;
eachOfKeysPresent(keys: string[], callback: (key: string, value: any) => void): void;
isDeleted(): boolean;
delete(): void;
str(key: string): string | undefined;
defStr(key: string): string;
bool(key: string): boolean;
num(key: string): number;
date(key: string): Date | null;
pick(...keys: string[]): Record<string, any>;
err(key: string, msg: string): this;
values(castAs?: CastingMethod): any;
entries(): any[][];
merge(item: FlatfileRecord, props?: {
overwrite?: boolean;
}): this;
hasConflict(b: FlatfileRecord, keys?: string[]): boolean;
toJSON(): Readonly<Partial<T>> & {
[k: string]: any;
};
toSimpleRecord(): SimpleRecord;
[util.inspect.custom](): string;
copy(props?: {
mixin?: FlatfileRecord;
select?: string[];
slug?: string;
sheetId?: string;
}): FlatfileRecord<Record<string, any>>;
commit(): void;
changeset(): {
[k: string]: any;
};
/**
* @deprecated use .err() instead
*/
addError(key: string, msg: string): this;
hasError(...keys: string[]): boolean;
errorFields(...keys: string[]): string[];
errorIf(key: string, cb: (val: any) => any, err: string): void;
info(key: string, msg: string): this;
/**
* @deprecated use .info() instead
*/
addComment(key: string, msg: string): this;
/**
* @deprecated use .info() instead
*/
addInfo(key: string, msg: string): this;
warn(key: string, msg: string): this;
/**
* @deprecated use .warn() instead
*/
addWarning(key: string, msg: string): this;
setReadOnly(key: string): void;
setConfig(setter: (config: FlatfileTypes["RecordConfig"]) => FlatfileTypes["RecordConfig"]): void;
setFieldConfig(key: string, newConfig: FlatfileTypes["CellConfig"]): void;
}
export {};