@open-kappa/myjson
Version:
A simple JSON management library.
114 lines (113 loc) • 3.55 kB
TypeScript
/**
* @brief Base class for all JSON objects.
*/
declare abstract class MyJson {
/**
* @brief Constructor.
* @param {boolean} isMandatory True if the object must appear in the
* hierarchy.
* @param {string} name The name of the object.
*/
constructor(isMandatory: boolean, name: string);
/**
* @brief Return the internal properties of the object.
* It uses a symbol to hide the properties to "usual" javascript methods.
* @private
* @return {MyJsonProperties} The object properties.
*/
private _getValidatorProperties;
/**
* @brief Throw a validation error.
* @protected
* @param {string} msg Te error message.
* @throws {Error} The error.
*/
protected _throwValidatorError(msg: string): void;
/**
* @brief Get if the object is mandatory.
* @return {boolean} True if it is mandatory.
*/
isMandatory(): boolean;
/**
* @brief Get if the object has been initialized.
* @return {boolean} True if initialized.
*/
isInitialized(): boolean;
/**
* @brief Set if the object has been initialized.
* @param {boolean} initialized True if initialized.
*/
protected _setInitialized(initialized: boolean): void;
/**
* @brief Get the name of this json object.
* @return {string} The name.
*/
getJsonName(): string;
/**
* @brief Get the lidt of constraints.
* @protected
* @return {Array<(ref: MyJson) => string>} The list of constraints.
*/
protected getConstraints(): Array<(ref: MyJson) => string>;
/**
* @brief Set the name of this json object.
* @protected
* @param {string} The name.
*/
setJsonName(name: string): void;
/**
* @brief Add a constraint which must hold to validate the JSON.
* The constraint takes a reference to this, and must return an empty string
* if satisfyed, a message otherwise.
* @param {foo: (ref: MyJson) => string} foo The constraint.
*/
addConstraint(foo: (ref: MyJson) => string): void;
protected checkConstraints(): void;
/**
* @brief Parse a JSON object.
* @param {any} json The JSON to parse.
* @throws {Error} If a validation error occurrs.
*/
parseJson(json: any): void;
/**
* @brief Clear the object content.
*/
clear(): void;
/**
* @brief Actual parse of a JSON object.
* @param {any} json The JSON to parse.
* @throws {Error} If a validation error occurrs.
*/
protected abstract parseJsonImpl(json: any): void;
/**
* @brief Clone this object.
* @return {MyJson} The copy.
*/
abstract clone(): MyJson;
/**
* @brief Check if two JSON objects are equals.
* @param {MyJson} other The other object of comparison.
* @return {boolean} True if they are equals.
*/
abstract isEqual(other: MyJson): boolean;
/**
* @brief Actual clear.
*/
protected abstract clearImpl(): void;
/**
* @brief Merge the two objects.
* @param {MyJson} other The other object to merge.
* @throws {Error} If the two objects cannot be merged.
*/
abstract merge(other: MyJson): void;
/**
* @brief Add a new child element.
* This is a build-time support method.
* @param {MyJson} element The child element.
* @return {MyJson} This.
* @throws {Error} If element cannot be added.
*/
abstract add(element: MyJson): MyJson;
}
export { MyJson };
export default MyJson;