Options
All
  • Public
  • Public/Protected
  • All
Menu

Class MetadataStore

An instance of the MetadataStore contains all of the metadata about a collection of EntityType's. MetadataStores may be shared across EntityManager's. If an EntityManager is created without an explicit MetadataStore, the MetadataStore from the MetadataStore.defaultInstance property will be used.

dynamic

Hierarchy

  • MetadataStore

Index

Constructors

constructor

  • Constructs a new MetadataStore.

    let ms = new MetadataStore();
    

    The store can then be associated with an EntityManager

    let entityManager = new EntityManager( {
        serviceName: "breeze/NorthwindIBModel",
        metadataStore: ms
    });
    

    or for an existing EntityManager

    // Assume em1 is an existing EntityManager em1.setProperties( { metadataStore: ms });

    Parameters

    • Optional config: MetadataStoreConfig

      Configuration settings .

      • namingConvention - (default=NamingConvention.defaultInstance) NamingConvention to be used in mapping property names between client and server. Uses the NamingConvention.defaultInstance if not specified.
      • localQueryComparisonOptions - (default=LocalQueryComparisonOptions.defaultInstance) The LocalQueryComparisonOptions to be used when performing "local queries" in order to match the semantics of queries against a remote service.
      • serializerFn - A function that is used to mediate the serialization of instances of this type.

    Returns MetadataStore

Events

metadataFetched

An BreezeEvent that fires after a MetadataStore has completed fetching metadata from a remote service.

eventargs

-

  • metadataStore - The MetadataStore into which the metadata was fetched.
  • dataService - The DataService that metadata was fetched from.
  • rawMetadata - {Object} The raw metadata returned from the service. (It will have already been processed by this point).
     let ms = myEntityManager.metadataStore;
     ms.metadataFetched.subscribe(function(args) {
         let metadataStore = args.metadataStore;
         let dataService = args.dataService;
     });
    

Properties

dataServices

dataServices: DataService[]

localQueryComparisonOptions

localQueryComparisonOptions: LocalQueryComparisonOptions

The LocalQueryComparisonOptions associated with this MetadataStore. Read Only

name

name: string

namingConvention

namingConvention: NamingConvention

The NamingConvention associated with this MetadataStore. Read Only

Optional serializerFn

serializerFn: (prop: EntityProperty, val: any) => any

Type declaration

Static metadataVersion

metadataVersion: string = "1.0.5"

The version of any MetadataStores created by this class

Static normalizeTypeName

normalizeTypeName: any = core.memoize(function (rawTypeName: string) {return rawTypeName && MetadataStore.parseTypeName(rawTypeName).typeName;})

Methods

addDataService

  • addDataService(dataService: DataService, shouldOverwrite?: boolean): void
  • Adds a DataService to this MetadataStore. If a DataService with the same serviceName is already in the MetadataStore an exception will be thrown.

    Parameters

    • dataService: DataService

      The DataService to add

    • Optional shouldOverwrite: boolean

      (default=false) Permit overwrite of existing DataService rather than throw exception

    Returns void

addEntityType

exportMetadata

  • exportMetadata(): string
  • Exports this MetadataStore to a serialized string appropriate for local storage. This operation is also called internally when exporting an EntityManager.

     // assume ms is a previously created MetadataStore
     let metadataAsString = ms.exportMetadata();
     window.localStorage.setItem("metadata", metadataAsString);
     // and later, usually in a different session imported
     let metadataFromStorage = window.localStorage.getItem("metadata");
     let newMetadataStore = new MetadataStore();
     newMetadataStore.importMetadata(metadataFromStorage);
    

    Returns string

    A serialized version of this MetadataStore that may be stored locally and later restored.

fetchMetadata

  • fetchMetadata(dataService: string | DataService, callback?: (schema: any) => void, errorCallback?: ErrorCallback): Promise<any>
  • Fetches the metadata for a specified 'service'. This method is automatically called internally by an EntityManager before its first query against a new service. Async

    Usually you will not actually process the results of a fetchMetadata call directly, but will instead ask for the metadata from the EntityManager after the fetchMetadata call returns.

     let ms = new MetadataStore();
     // or more commonly
     // let ms = anEntityManager.metadataStore;
     ms.fetchMetadata("breeze/NorthwindIBModel").then(function(rawMetadata) {
           // do something with the metadata
     }).catch(function(exception) {
         // handle exception here
     });
    

    Parameters

    • dataService: string | DataService

      Either a DataService or just the name of the DataService to fetch metadata for.

    • Optional callback: (schema: any) => void

      Function called on success.

        • (schema: any): void
        • Parameters

          • schema: any

          Returns void

    • Optional errorCallback: ErrorCallback

      Function called on failure.

    Returns Promise<any>

    Promise

getAsComplexType

  • getAsComplexType(typeName: string, okIfNotFound?: boolean): ComplexType
  • Returns an EntityType or null given its name.

     // assume em1 is a preexisting EntityManager
     let locType = em1.metadataStore.getAsComplexType("Location");
    

    or to throw an error if the type is not found

     let badType = em1.metadataStore.getAsComplexType("Foo", false);
     // badType will not get set and an exception will be thrown.
    

    Parameters

    • typeName: string
    • Default value okIfNotFound: boolean = false

      (default=false) Whether to throw an error if the specified EntityType is not found.

    Returns ComplexType

    The EntityType. ComplexType or 'null' if not not found.

getAsEntityType

  • getAsEntityType(typeName: string, okIfNotFound?: boolean): EntityType
  • Returns an EntityType or null given its name.

     // assume em1 is a preexisting EntityManager
     let odType = em1.metadataStore.getAsEntityType("OrderDetail");
    

    or to throw an error if the type is not found

     let badType = em1.metadataStore.getAsEntityType("Foo", false);
     // badType will not get set and an exception will be thrown.
    

    Parameters

    • typeName: string
    • Default value okIfNotFound: boolean = false

      (default=false) Whether to throw an error if the specified EntityType is not found.

    Returns EntityType

    The EntityType. ComplexType or 'null' if not not found.

getDataService

  • Returns the DataService for a specified service name

     // Assume em1 is an existing EntityManager.
     let ds = em1.metadataStore.getDataService("breeze/NorthwindIBModel");
     let adapterName = ds.adapterName; // may be null
    

    Parameters

    • serviceName: string

      The service name.

    Returns DataService

    The DataService with the specified name.

getEntityType

  • getEntityType(typeName: string, okIfNotFound?: boolean): StructuralType
  • Returns an EntityType or a ComplexType given its name.

    deprecated

    Replaced by getStructuralType but ... it is probably more usefull to call either getAsEntityType or getAsComplexType instead

    Parameters

    • typeName: string

      Either the fully qualified name or a short name may be used. If a short name is specified and multiple types share that same short name an exception will be thrown.

    • Default value okIfNotFound: boolean = false

      (default=false) Whether to throw an error if the specified EntityType is not found.

    Returns StructuralType

    The EntityType. ComplexType or 'null' if not not found.

getEntityTypeNameForResourceName

  • getEntityTypeNameForResourceName(resourceName: string): any

getEntityTypes

getIncompleteNavigationProperties

  • getIncompleteNavigationProperties(): any[]

getStructuralType

  • getStructuralType(typeName: string, okIfNotFound?: boolean): StructuralType
  • Returns an EntityType or a ComplexType given its name.

     // assume em1 is a preexisting EntityManager
     let odType = em1.metadataStore.getStructuralType("OrderDetail");
    

    or to throw an error if the type is not found

     let badType = em1.metadataStore.getStructuralType("Foo", false);
     // badType will not get set and an exception will be thrown.
    
    deprecated

    Preferably use either getAsEntityType or getAsComplexType. Get

    Parameters

    • typeName: string

      Either the fully qualified name or a short name may be used. If a short name is specified and multiple types share that same short name an exception will be thrown.

    • Default value okIfNotFound: boolean = false

      (default=false) Whether to throw an error if the specified EntityType is not found.

    Returns StructuralType

    The EntityType. ComplexType or 'null' if not not found.

hasMetadataFor

  • hasMetadataFor(serviceName: string): boolean
  • Returns whether Metadata has been retrieved for a specified service name.

     // Assume em1 is an existing EntityManager.
     if (!em1.metadataStore.hasMetadataFor("breeze/NorthwindIBModel"))) {
         // do something interesting
     }
    

    Parameters

    • serviceName: string

      The service name.

    Returns boolean

    Whether metadata has already been retrieved for the specified service name.

importMetadata

  • importMetadata(exportedMetadata: string | Object, allowMerge?: boolean): MetadataStore
  • Imports a previously exported serialized MetadataStore into this MetadataStore.

     // assume ms is a previously created MetadataStore
     let metadataAsString = ms.exportMetadata();
     window.localStorage.setItem("metadata", metadataAsString);
     // and later, usually in a different session
     let metadataFromStorage = window.localStorage.getItem("metadata");
     let newMetadataStore = new MetadataStore();
     newMetadataStore.importMetadata(metadataFromStorage);
    
    chainable

    Parameters

    • exportedMetadata: string | Object

      A previously exported MetadataStore.

    • Default value allowMerge: boolean = false

      Allows custom metadata to be merged into existing metadata types.

    Returns MetadataStore

    This MetadataStore.

isEmpty

  • isEmpty(): boolean
  • Returns whether this MetadataStore contains any metadata yet.

     // assume em1 is a preexisting EntityManager;
     if (em1.metadataStore.isEmpty()) {
         // do something interesting
     }
    

    Returns boolean

registerEntityTypeCtor

  • registerEntityTypeCtor(structuralTypeName: string, aCtor?: any, initFn?: Function | string, noTrackingFn?: Function): void
  • Provides a mechanism to register a 'custom' constructor to be used when creating new instances of the specified entity type. If this call is not made, a default constructor is created for the entity as needed. This call may be made before or after the corresponding EntityType has been discovered via Metadata discovery.

     let Customer = function () {
             this.miscData = "asdf";
         };
     Customer.prototype.doFoo() {
             ...
         }
     // assume em1 is a preexisting EntityManager;
     em1.metadataStore.registerEntityTypeCtor("Customer", Customer);
     // any queries or EntityType.create calls from this point on will call the Customer constructor
     // registered above.
    

    Parameters

    • structuralTypeName: string

      The name of the EntityType or ComplexType.

    • Optional aCtor: any

      The constructor for this EntityType or ComplexType; may be null if all you want to do is set the next parameter.

    • Optional initFn: Function | string

      A function or the name of a function on the entity that is to be executed immediately after the entity has been created and populated with any initial values. Called with 'initFn(entity)'

    • Optional noTrackingFn: Function

      A function that is executed immediately after a noTracking entity has been created and whose return value will be used in place of the noTracking entity.

    Returns void

setEntityTypeForResourceName

  • setEntityTypeForResourceName(resourceName: string, entityTypeOrName: EntityType | string): void
  • Associates a resourceName with an entityType.

    This method is only needed in those cases where multiple resources return the same entityType. In this case Metadata discovery will only determine a single resource name for each entityType.

    Parameters

    • resourceName: string

      The resource name

    • entityTypeOrName: EntityType | string

      If passing a string either the fully qualified name or a short name may be used. If a short name is specified and multiple types share that same short name an exception will be thrown. If the entityType has not yet been discovered then a fully qualified name must be used.

    Returns void

setProperties

  • General purpose property set method

    // assume em1 is an EntityManager containing a number of existing entities.
    em1.metadataStore.setProperties( {
        version: "6.1.3",
        serializerFn: function(prop, value) {
        return (prop.isUnmapped) ? undefined : value;
        }
    )};
    

    Parameters

    Returns void

trackUnmappedType

  • trackUnmappedType(entityCtor: any, interceptor: any): void
  • Used to register a constructor for an EntityType that is not known via standard Metadata discovery; i.e. an unmapped type.

    Parameters

    • entityCtor: any

      The constructor function for the 'unmapped' type.

    • interceptor: any

      An interceptor function

    Returns void

Static importMetadata

  • Creates a new MetadataStore from a previously exported serialized MetadataStore

     // assume ms is a previously created MetadataStore
     let metadataAsString = ms.exportMetadata();
     window.localStorage.setItem("metadata", metadataAsString);
     // and later, usually in a different session
     let metadataFromStorage = window.localStorage.getItem("metadata");
     let newMetadataStore = MetadataStore.importMetadata(metadataFromStorage);
    

    Parameters

    • exportedString: string

      A previously exported MetadataStore.

    Returns MetadataStore

    A new MetadataStore.

Static makeTypeHash

  • makeTypeHash(shortName: string, ns?: string): { namespace: string; shortTypeName: string; typeName: string }
  • Dev Only - for use when creating a new MetadataParserAdapter

    Parameters

    • shortName: string
    • Optional ns: string

    Returns { namespace: string; shortTypeName: string; typeName: string }

    • namespace: string
    • shortTypeName: string
    • typeName: string

Static parseTypeName

  • parseTypeName(entityTypeName: string): { namespace: string; shortTypeName: string; typeName: string }
  • Dev Only - for use when creating a new MetadataParserAdapter

    Parameters

    • entityTypeName: string

    Returns { namespace: string; shortTypeName: string; typeName: string }

    • namespace: string
    • shortTypeName: string
    • typeName: string

Generated using TypeDoc