@tripsnek/tmf
Version:
TypeScript Modeling Framework - A TypeScript port of the Eclipse Modeling Framework (EMF)
94 lines • 3.47 kB
TypeScript
import { EObject } from '../metamodel/eobject';
import { EClass } from '../metamodel/eclass';
import { EPackage } from '../metamodel/epackage';
import { EStructuralFeature } from '../metamodel/estructural-feature';
import { EAttribute } from '../metamodel/eattribute';
/**
* Utilities for converting between EObjects and JSON. Usage:
*
* (1) TJson.makeJson(EObject) - converts an EObject to JSON.
* (2) TJson.makeEObject(json) - deserializes EObject encoded with (1).
* (3) TJson.makeJsonArray(EObject[]) - converts an array of EObjects to a JSON Array.
* (4) TJson.makeEObjectArray(json) - converts a JSON Array to an array of EObjects.
*
* You may also configure which EClasses are eligible for conversion with
* 'addPackages(EPackage[])' and 'setPackages(EPackage[])'.
*
*/
export declare class TJson {
static JSON_FIELD_TYPESCRIPT_TYPE: string;
static packages: EPackage[];
static setPackages(packages: EPackage[]): void;
static addPackages(packages: EPackage[]): void;
static getPackages(): EPackage[];
private static warnIfNotInitialized;
/**
* Converts a TMF EObject to JSON.
*
* @param obj
*/
static makeJson(obj: EObject): any;
/**
* Converts an object in JSON Object into a TMF EObject.
* Creates proxy objects for unresolved non-containment references.
*
* @param json
* @return
*/
static makeEObject(jsonObj: any): EObject | undefined;
/**
* Creates a proxy object for an unresolved reference and sets it on the source object.
*
* @param ref The unresolved serialized reference
* @param idsToObjs Map of all resolved objects
*/
private static createAndSetProxy;
/**
* Creates a proxy EObject for an unresolved reference.
*
* @param fullId The full ID of the target object (format: "ClassName_actualId")
* @param reference The reference feature to determine the target EClass
* @returns A proxy EObject or undefined if creation failed
*/
private static createProxy;
/**
* Converts a TMF EObject array to JSON array.
*
* @param obj
*/
static makeJsonArray(objs: EObject[]): any[];
/**
* Converts an object in JSON Array into am array of TMF EObjects.
*
* @param json
* @return
*/
static makeEObjectArray(jsonArray: any[]): EObject[];
private static jsonToEObject;
private static deserializeReferencedObjects;
private static deserializeSingleValuedReference;
private static deserializeManyValuedReference;
protected static eObjectToJsonAux(obj: EObject, serializedSoFar: Map<EObject, any>, attributesOnly: boolean): any;
private static referencesToJson;
private static manyValuedReferenceToJson;
private static singleValuedRefToJson;
private static attributesToJson;
/**
* Converts a primitive value (or a Date) for use inside JSON.
*
* @param val
* @return
*/
static primitiveValueToJson(attr: EAttribute, val: any): any;
static getJsonFieldName(feature: EStructuralFeature): string;
static eClassByNameCaseInsensitive(objectType: string, pkg: EPackage): EClass;
/**
* Sets all primitive (EAttribute) values on the eobject, given a
* JSONObject with the same fields.
*
* @param propsObj
* @param eObj
*/
static setPrimitiveValuesOnJson(propsObj: any, eObj: EObject): void;
}
//# sourceMappingURL=tjson.d.ts.map