@accordproject/concerto-core
Version:
Core Implementation for the Concerto Modeling Language
127 lines (125 loc) • 5.41 kB
TypeScript
import type Factory = require('../factory');
import type ModelManager = require('../modelmanager');
import type Declaration = require('../introspect/declaration');
import type ClassDeclaration = require('../introspect/classdeclaration');
import type RelationshipDeclaration = require('../introspect/relationshipdeclaration');
import type MapDeclaration = require('../introspect/mapdeclaration');
import type Resource = require('../model/resource');
import Field = require('../introspect/field');
type Stack<T> = {
push(value: T, expectedType?: unknown): void;
pop(expectedType?: unknown): T;
peek?(expectedType?: unknown): T;
stack: T[];
};
type JsonPopulatorParameters = {
jsonStack: Stack<String | {
[key: string]: unknown;
$class: string;
} | {
[key: string]: unknown;
$class: string;
}[]>;
resourceStack: Stack<Resource>;
path?: Stack<string>;
factory: Factory;
modelManager: ModelManager;
acceptResourcesForRelationships?: boolean;
utcOffset?: number;
strictQualifiedDateTimes?: boolean;
};
type VisitorTarget = Declaration | Field | ClassDeclaration | MapDeclaration | RelationshipDeclaration;
/**
* Populates a Resource with data from a JSON object graph. The JSON objects
* should be the result of calling Serializer.toJSON and then JSON.parse.
* The parameters object should contain the keys
* 'stack' - the TypedStack of objects being processed. It should
* start with the root object from JSON.parse.
* 'factory' - the Factory instance to use for creating objects.
* 'modelManager' - the ModelManager instance to use to resolve classes
* @private
* @class
* @memberof module:concerto-core
*/
declare class JSONPopulator {
acceptResourcesForRelationships: boolean | undefined;
utcOffset: number;
strictQualifiedDateTimes: boolean;
/**
* Constructor.
* @param {boolean} [acceptResourcesForRelationships] Permit resources in the
* place of relationships, false by default.
* @param {boolean} [ergo] - Deprecated - This is a dummy parameter to avoid breaking any consumers. It will be removed in a future release.
* @param {number} [utcOffset] - UTC Offset for DateTime values.
* @param {boolean} [strictQualifiedDateTimes=true] - Only allow fully-qualified date-times with offsets.
*/
constructor(acceptResourcesForRelationships: any, ergo: any, utcOffset: any, strictQualifiedDateTimes: any);
/**
* Visitor design pattern
* @param {Object} thing - the object being visited
* @param {Object} parameters - the parameter
* @return {Object} the result of visiting or null
* @private
*/
visit(thing: VisitorTarget, parameters: JsonPopulatorParameters): any;
/**
* Visitor design pattern
* @param {ClassDeclaration} classDeclaration - the object being visited
* @param {Object} parameters - the parameter
* @return {Object} the result of visiting or null
* @private
*/
visitClassDeclaration(classDeclaration: ClassDeclaration, parameters: JsonPopulatorParameters): Resource;
/**
* Visitor design pattern
* @param {MapDeclaration} mapDeclaration - the object being visited
* @param {Object} parameters - the parameter
* @return {Object} the result of visiting or null
* @private
*/
visitMapDeclaration(mapDeclaration: MapDeclaration, parameters: JsonPopulatorParameters): Map<any, any>;
/**
* Visitor design pattern
* @param {MapDeclaration} mapDeclaration - the object being visited
* @param {Object} parameters - the parameter
* @param {Object} value - the key or value belonging to the Map Entry.
* @param {Object} type - the Type associated with the Key or Value Map Entry.
* @return {Object} value - the key or value belonging to the Map Entry.
* @private
*/
processMapType(mapDeclaration: any, parameters: JsonPopulatorParameters, value: any, type: any): any;
/**
* Visitor design pattern
* @param {Field} field - the object being visited
* @param {Object} parameters - the parameter
* @return {Object} the result of visiting or null
* @private
*/
visitField(field: any, parameters: JsonPopulatorParameters): any;
/**
*
* @param {Field} field - the field of the item being converted
* @param {Object} jsonItem - the JSON object of the item being converted
* @param {Object} parameters - the parameters
* @return {Object} - the populated object.
*/
convertItem(field: any, jsonItem: any, parameters: any): null;
/**
* Converts a primtive object to JSON text.
*
* @param {Field} field - the field declaration of the object
* @param {Object} json - the JSON object to convert to a Concerto Object
* @param {Object} parameters - the parameters
* @return {string} the text representation
*/
convertToObject(field: any, json: any, parameters: JsonPopulatorParameters): any;
/**
* Visitor design pattern
* @param {RelationshipDeclaration} relationshipDeclaration - the object being visited
* @param {Object} parameters - the parameter
* @return {Object} the result of visiting or null
* @private
*/
visitRelationshipDeclaration(relationshipDeclaration: any, parameters: JsonPopulatorParameters): any;
}
export = JSONPopulator;