Skip to content

breeze-client / ComplexType

Class: ComplexType ​

Defined in: src/metadata/entity-metadata.ts:2041

Container for all of the metadata about a specific type of Complex object.

ts
const complexType = new ComplexType({
    shortName: "address",
    namespace: "myAppNamespace"
});

Param ​

config

Configuration settings

Constructors ​

Constructor ​

new ComplexType(config): ComplexType

Defined in: src/metadata/entity-metadata.ts:2135

Creates a ComplexType from a ComplexTypeConfig. Add it to a MetadataStore with MetadataStore.addEntityType before using it.

Parameters ​

config ​

ComplexTypeConfig

Returns ​

ComplexType

Properties ​

addValidator ​

addValidator: (validator, property?) => void = EntityType.prototype.addValidator

Defined in: src/metadata/entity-metadata.ts:2107

See [EntityType.addValidator]

Adds either an entity or property level validator to this EntityType.

ts
// assume em1 is an EntityManager containing a number of existing entities.
const custType = em1.metadataStore.getAsEntityType("Customer");
const countryProp = custType.getProperty("country");
const valFn = (v: string | null) => v == null || v.startsWith("US");
const countryValidator = new Validator("countryIsUS", valFn,
    { displayName: "Country", messageTemplate: "'%displayName%' must start with 'US'" });
custType.addValidator(countryValidator, countryProp);

This is the same as adding an entity level validator via the 'validators' property of DataProperty or NavigationProperty

ts
countryProp.validators.push(countryValidator);

Entity level validators can also be added by omitting the 'property' parameter.

ts
custType.addValidator(someEntityLevelValidator);

or

ts
custType.validators.push(someEntityLevelValidator);

Parameters ​

validator ​

Validator

Validator to add.

property? ​

string | EntityProperty

Property to add this validator to. If omitted, the validator is assumed to be an entity level validator and is added to the EntityType's 'validators'.

Returns ​

void


complexProperties ​

complexProperties: DataProperty[]

Defined in: src/metadata/entity-metadata.ts:2060

The DataProperties for this ComplexType that contain instances of a ComplexType. Read Only


concurrencyProperties ​

concurrencyProperties: DataProperty[]

Defined in: src/metadata/entity-metadata.ts:2067

For polymorphic purpose only - always empty here


createInstance ​

createInstance: <T>(initialValues?) => T = EntityType.prototype.createEntity

Defined in: src/metadata/entity-metadata.ts:2105

Creates a new instance of this ComplexType, optionally setting the property values given in initialValues; the ComplexType counterpart of EntityType.createEntity.

ts
const locType = em1.metadataStore.getAsComplexType("Location");
const loc = locType.createInstance<Location>({ city: "Boston" });   // Location, unchecked

Creates a new entity of this type, detached: add it to a manager with EntityManager.addEntity, or use EntityManager.createEntity, which does both.

ts
// assume em1 is an EntityManager containing a number of existing entities.
const custType = em1.metadataStore.getAsEntityType("Customer");
const cust1 = custType.createEntity<Customer>({ companyName: "Acme" });   // Customer
em1.addEntity(cust1);

T is the type you expect back. Nothing checks it - an EntityType knows its metadata, not your class - and it defaults to any.

ts
const order = custType.createEntity<Order>();   // compiles, but creates a Customer

Type Parameters ​

T ​

T = any

Parameters ​

initialValues? ​

any

Property values to set immediately after creation.

Returns ​

T

The new entity.


custom? ​

optional custom?: any

Defined in: src/metadata/entity-metadata.ts:2088

A free form object that can be used to define any custom metadata for this ComplexType.


dataProperties ​

dataProperties: DataProperty[]

Defined in: src/metadata/entity-metadata.ts:2058

The DataProperties (see DataProperty associated with this ComplexType. Read Only


getCtor ​

getCtor: (forceRefresh) => () => StructuralObject = EntityType.prototype.getCtor

Defined in: src/metadata/entity-metadata.ts:2096

See EntityType.getCtor

Returns the constructor for this EntityType.

Parameters ​

forceRefresh? ​

boolean = false

Whether to ignore any cached version of this constructor. (default == false)

Returns ​

The constructor for this EntityType.

() => StructuralObject


getPropertiesOnPath ​

getPropertiesOnPath: object = EntityType.prototype.getPropertiesOnPath

Defined in: src/metadata/entity-metadata.ts:2115

Returns the properties along a . delimited property path, one per segment, or null if a segment is not found (unless throwIfNotFound is true, which throws instead). useServerName matches segments against nameOnServer when true, name when false, and either when null. Used by Breeze internally; applications normally use ComplexType.getProperty.


getProperty ​

getProperty: (propertyPath, throwIfNotFound?) => EntityProperty | null = EntityType.prototype.getProperty

Defined in: src/metadata/entity-metadata.ts:2110

Returns the DataProperty with the specified name, or null. Also accepts a . delimited path through nested complex properties. See EntityType.getProperty.

Returns either a DataProperty or a NavigationProperty with the specified name or null.

This method also accepts a '.' delimited property path and will return the 'property' at the end of the path.

ts
const custType = em1.metadataStore.getAsEntityType("Customer");
const companyNameProp = custType.getProperty("companyName");

This method can also walk a property path to return a property

ts
const orderDetailType = em1.metadataStore.getAsEntityType("OrderDetail");
const companyNameProp2 = orderDetailType.getProperty("order.customer.companyName");
// companyNameProp === companyNameProp2

Parameters ​

propertyPath ​

string

throwIfNotFound? ​

boolean = false

{Boolean} Whether to throw an exception if not found.

Returns ​

EntityProperty | null

A DataProperty or NavigationProperty or null if not found.


getPropertyNames ​

getPropertyNames: () => any[] = EntityType.prototype.getPropertyNames

Defined in: src/metadata/entity-metadata.ts:2117

Returns the names of all of this type's data properties.

Returns all of the property names ( for both dataProperties and navigationProperties) for this EntityType.

ts
// assume em1 is an EntityManager containing a number of existing entities.
const custType = em1.metadataStore.getAsEntityType("Customer");
const arrayOfPropNames = custType.getPropertyNames();

Returns ​

any[]


isComplexType ​

isComplexType: boolean = true

Defined in: src/metadata/entity-metadata.ts:2045

For polymorphic purpose only - always true here


keyProperties ​

keyProperties: DataProperty[]

Defined in: src/metadata/entity-metadata.ts:2079

Always empty: a ComplexType has no key. Present so that code can treat an EntityType and a ComplexType alike. Read Only


metadataStore ​

metadataStore: MetadataStore

Defined in: src/metadata/entity-metadata.ts:2048

The MetadataStore containing this ComplexType.


name ​

name: string

Defined in: src/metadata/entity-metadata.ts:2051

The fully qualifed name of this ComplexType. Read Only


namespace ​

namespace: string

Defined in: src/metadata/entity-metadata.ts:2056

The namespace for this ComplexType. Read Only


navigationProperties: DataProperty[]

Defined in: src/metadata/entity-metadata.ts:2075

Always empty: a ComplexType has no navigation properties. Present so that code can treat an EntityType and a ComplexType alike. Read Only


serializerFn? ​

optional serializerFn?: (prop, val) => any

Defined in: src/metadata/entity-metadata.ts:2085

A function that customizes how this type's data properties are serialized when an entity holding it is saved; see MetadataStore.serializerFn, which is used when this is not set. The constructor does not accept it: assign it directly.

Parameters ​

prop ​

EntityProperty

val ​

any

Returns ​

any


shortName ​

shortName: string

Defined in: src/metadata/entity-metadata.ts:2053

The short, unqualified, name for this ComplexType. Read Only


unmappedProperties ​

unmappedProperties: DataProperty[]

Defined in: src/metadata/entity-metadata.ts:2070

The DataProperties associated with this ComplexType that are not mapped to any backend datastore. These are effectively free standing properties. Read Only


validators ​

validators: Validator[]

Defined in: src/metadata/entity-metadata.ts:2065

The entity level validators associated with this ComplexType. Validators can be added and removed from this collection. Read Only


warnings ​

warnings: any[]

Defined in: src/metadata/entity-metadata.ts:2081

Not used by breeze-client 3, and never set on a ComplexType. See EntityType.warnings.

Methods ​

addProperty() ​

addProperty(dataProperty): void

Defined in: src/metadata/entity-metadata.ts:2206

Adds a DataProperty to this ComplexType.

ts
// assume addressType is a newly constructed ComplexType.
addressType.addProperty(new DataProperty({ name: "city", dataType: DataType.String }));

Parameters ​

dataProperty ​

DataProperty

Returns ​

void


getAllValidators() ​

getAllValidators(): Validator[]

Defined in: src/metadata/entity-metadata.ts:2185

Returns the type level validators for this ComplexType: its own ComplexType.validators array itself, not a copy, since ComplexTypes have no base types.

Returns ​

Validator[]


getProperties() ​

getProperties(): EntityProperty[]

Defined in: src/metadata/entity-metadata.ts:2213

Returns all of the properties of this ComplexType: its ComplexType.dataProperties array itself, not a copy.

Returns ​

EntityProperty[]


setProperties() ​

setProperties(config): void

Defined in: src/metadata/entity-metadata.ts:2176

General purpose property set method

ts
// assume em1 is an EntityManager
const locType = em1.metadataStore.getAsComplexType("Location");
locType.setProperties({
    custom: { foo: 7, bar: "test" }
});

Parameters ​

config ​

Custom config object

custom? ​

any

Returns ​

void


toJSON() ​

toJSON(): Object

Defined in: src/metadata/entity-metadata.ts:2220

Returns this type's metadata as a plain object in Breeze's native JSON metadata format, leaving out default values and empty arrays. JSON.stringify calls it when MetadataStore.exportMetadata serializes the store.

Returns ​

Object

Released under the MIT License.