@odata2ts/odata2ts
Version:
Flexible generator to produce various TypeScript artefacts (from simple model interfaces to complete odata clients) from OData metadata files
110 lines (109 loc) • 4.52 kB
TypeScript
import { MappedConverterChains } from "@odata2ts/converter-runtime";
import { ODataTypesV2, ODataTypesV4 } from "@odata2ts/odata-core";
import { ActionImportType, ComplexType, EntityContainerModel, EntitySetType, EntityType, EnumType, FunctionImportType, ModelType, ODataVersion, OperationType, PropertyModel, SingletonType } from "./DataTypeModel.js";
import { ValidationError } from "./validation/NameValidator.js";
export interface ProjectFiles {
model: string;
qObject: string;
service: string;
}
/**
* Each namespace is represented as tuple: 1. the namespace 2. the alias, if any.
*/
export type NamespaceWithAlias = [string, string?];
export declare function withNamespace(ns: string, name: string): string;
export declare class DataModel {
private version;
private readonly converters;
private nameValidation;
private models;
/**
* Stores unbound operations by their fully qualified name.
* @private
*/
private unboundOperationTypes;
/**
* Stores operations bound to an entity type by the fully qualified name of the binding entity, e.g.
* "Trippin.Person".
* @private
*/
private entityBoundOperationTypes;
/**
* Stores operations bound to an entity collection by the fully qualified name of the binding entity, e.g.
* "Trippin.Person".
* @private
*/
private entityCollectionBoundOperationTypes;
/**
* Stores own type definitions which map to primitive types.
* @private
*/
private typeDefinitions;
private readonly namespace2Alias;
private aliases;
private container;
constructor(namespaces: Array<NamespaceWithAlias>, version: ODataVersion, converters?: MappedConverterChains);
/**
* OData version: 2.0 or 4.0.
* @returns
*/
getODataVersion(): ODataVersion;
isV2(): boolean;
isV4(): boolean;
private retrieveType;
private addAlias;
addTypeDefinition(namespace: string, name: string, type: string): void;
getPrimitiveType(fqName: string): string | undefined;
getModel(fqName: string): EntityType | ComplexType | EnumType | undefined;
getModelTypes(): Array<ModelType>;
addEntityType(namespace: string, name: string, model: Omit<EntityType, "dataType">): void;
/**
* Get a specific model by its fully qualified name.
*
* @param fqName the fully qualified name of the entity
* @returns the model type
*/
getEntityType(fqName: string): EntityType;
/**
* Retrieve all known EntityType models from the EDMX model.
*
* @returns list of model types
*/
getEntityTypes(): EntityType[];
addComplexType(namespace: string, name: string, model: Omit<ComplexType, "dataType">): void;
/**
* Get a specific model by its fully qualified name.
*
* @param fqName the final model name that is generated
* @returns the model type
*/
getComplexType(fqName: string): ComplexType;
/**
* Retrieve all known ComplexType models from the EDMX model.
*
* @returns list of model types
*/
getComplexTypes(): ComplexType[];
addEnum(namespace: string, name: string, type: Omit<EnumType, "dataType">): void;
/**
* Get list of all known enums, i.e. EnumType nodes from the EDMX model.
* @returns list of enum types
*/
getEnums(): EnumType[];
addUnboundOperationType(namespace: string, operationType: OperationType): void;
getUnboundOperationTypes(): Array<OperationType>;
getUnboundOperationType(fqOpName: string): OperationType | undefined;
addBoundOperationType(namespace: string, bindingProp: PropertyModel, operationType: OperationType): void;
getEntityTypeOperations(fqEntityName: string): Array<OperationType>;
getEntitySetOperations(fqEntityName: string): Array<OperationType>;
getAllEntityOperations(fqEntityName: string): Array<OperationType>;
addAction(fqName: string, action: ActionImportType): void;
addFunction(fqName: string, func: FunctionImportType): void;
addSingleton(fqName: string, singleton: SingletonType): void;
addEntitySet(fqName: string, entitySet: EntitySetType): void;
getEntityContainer(): EntityContainerModel;
getConverter(dataType: ODataTypesV2 | ODataTypesV4 | string): import("@odata2ts/converter-runtime").ValueConverterChain | undefined;
private sortModelsByInheritance;
setNameValidation(map: Map<string, ValidationError[]>): void;
getNameValidation(): Map<string, ValidationError[]>;
}