rljson
Version:
Define and manage relational data structures in JSON
63 lines (62 loc) • 1.88 kB
TypeScript
import { JsonHash } from 'gg-json-hash';
export declare class Rljson {
data: Rltables;
dataIndexed: Rltables;
jsonJash: JsonHash;
constructor({ data, dataIndexed: dataIndexed }: RljsonConstructorParams);
static fromJson(data: Record<string, any>, options?: Partial<FromJsonOptions>): Rljson;
static empty(): Rljson;
addData(addedData: Rltables, options?: Partial<AddDataOptions>): Rljson;
tableIndexed(table: string): Rltables;
table(table: string): Rltables;
hasTable(table: string): boolean;
createTable(table: string): Rljson;
items({ table, where }: QueryOptions): Rlmap[];
row(table: string, hash: string): Rlmap;
addRow(table: string, item: Rlmap): void;
value({ table, itemHash, followLink }: GetValue): any;
select(table: string, columns: string[]): Array<Array<any>>;
hash({ table, index }: HashOptions): string;
ls(): string[];
checkLinks(): void;
static get example(): Rljson;
static get exampleWithLink(): Rljson;
static get exampleWithDeepLink(): Rljson;
static checkTableNames(data: Rltables): void;
static checkTableName(str: string): void;
private _checkData;
private _toMap;
}
export interface Rlmap {
[key: string]: any;
_hash?: string;
}
export interface Rltables {
[key: string]: Rlmap;
_hash?: any;
}
export interface RljsonConstructorParams {
data: Rltables;
dataIndexed: Rltables;
}
export interface QueryOptions {
table: string;
where: (item: Rlmap) => boolean;
}
export interface GetValue {
table: string;
itemHash: string;
followLink?: string[];
}
export interface HashOptions {
table: string;
index: number;
}
export interface FromJsonOptions {
validateHashes: boolean;
updateHashes: boolean;
}
export interface AddDataOptions {
validateHashes: boolean;
updateHashes: boolean;
}