@barchart/common-js
Version:
Library of common JavaScript utilities
99 lines (98 loc) • 2.48 kB
TypeScript
/**
* @typedef {import('./Component.js').default} Component
* @typedef {import('./Field.js').default} Field
*/
/**
* A schema definition, can be used for serialization and deserialization.
*
* @public
*/
export default class Schema {
/**
* @param {string} name - The name of the schema
* @param {Field[]=} fields
* @param {Component[]=} components
* @param {boolean=} strict
*/
constructor(name: string, fields?: Field[] | undefined, components?: Component[] | undefined, strict?: boolean | undefined);
/**
* Accepts data and returns a new object which (should) conform to
* the schema.
*
* @public
* @param {object} data
* @returns {object}
*/
public format(data: object): object;
/**
* Name of the table.
*
* @public
* @returns {string}
*/
public get name(): string;
/**
* The fields of the table.
*
* @public
* @returns {Array<Field>}
*/
public get fields(): Array<Field>;
/**
* The components of the table.
*
* @public
* @returns {Array<Component>}
*/
public get components(): Array<Component>;
/**
* If true, only the explicitly defined fields and components will
* be serialized.
*
* @public
* @returns {boolean}
*/
public get strict(): boolean;
/**
* Returns true, if an object complies with the schema.
*
* @public
* @param {*} candidate
* @returns {boolean}
*/
public validate(candidate: any): boolean;
/**
* Returns an array of {@link Field} objects from the schema for which the
* candidate object does not comply with.
*
* @public
* @param {*} candidate
* @returns {Field[]}
*/
public getInvalidFields(candidate: any): Field[];
/**
* Generates a function suitable for use by {@link JSON.parse}.
*
* @public
* @returns {Function}
*/
public getReviver(): Function;
/**
* Returns a function that will generate a *new* reviver function
* (see {@link Schema#getReviver}).
*
* @public
* @returns {Function}
*/
public getReviverFactory(): Function;
/**
* Returns a string representation.
*
* @public
* @returns {string}
*/
public toString(): string;
#private;
}
export type Component = import("./Component.js").default;
export type Field = import("./Field.js").default;