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: function

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

  • 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
     }).fail(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: function

      Function called on success.

        • (schema: any): void
        • Parameters

          • schema: any

          Returns void

    • Optional errorCallback: ErrorCallback

      Function called on failure.

    Returns Promise<any>

    Promise

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

  • Returns an EntityType or a ComplexType given its name.

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

    or to throw an error if the type is not found

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

    Parameters

    • structuralTypeName: 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 EntityType | ComplexType

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

getEntityTypeNameForResourceName

  • getEntityTypeNameForResourceName(resourceName: string): any

getEntityTypes

getIncompleteNavigationProperties

  • getIncompleteNavigationProperties(): any[]

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, 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

      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): object
  • Dev Only - for use when creating a new MetadataParserAdapter

    Parameters

    • shortName: string
    • Optional ns: string

    Returns object

Static parseTypeName

  • parseTypeName(entityTypeName: string): object
  • Dev Only - for use when creating a new MetadataParserAdapter

    Parameters

    • entityTypeName: string

    Returns object

Generated using TypeDoc