import { EntityType, NavigationProperty } from './entity-metadata'; import { DataServiceAdapter, UriBuilderAdapter } from './interface-registry'; import { KeyMapping } from './entity-manager'; import { MappingContext } from './mapping-context'; /** Configuration info to be passed to the [[DataService]] constructor */ export interface DataServiceConfig { /** The serviceName for this DataService. **/ serviceName?: string; /** The adapter name for the [[IDataServiceAdapter]] to be used with this service. **/ adapterName?: string; /** The adapter name for the [[IUriBuilderAdapter]] to be used with this service. **/ uriBuilderName?: string; /** Whether the server can provide metadata for this service. **/ hasServerMetadata?: boolean; /** The [[JsonResultsAdapter]] used to process the results of any query against this DataService. **/ jsonResultsAdapter?: JsonResultsAdapter; /** Whether to use JSONP when performing a 'GET' request against this service. **/ useJsonp?: boolean; } /** A DataService instance is used to encapsulate the details of a single 'service'; this includes a serviceName, a dataService adapterInstance, and whether the service has server side metadata. You can construct an EntityManager with either a serviceName or a DataService instance, if you use a serviceName then a DataService is constructed for you. (It can also be set via the EntityManager.setProperties method). The same applies to the MetadataStore.fetchMetadata method, i.e. it takes either a serviceName or a DataService instance. Each metadataStore contains a list of DataServices, each accessible via its ‘serviceName’. ( see MetadataStore.getDataService and MetadataStore.addDataService). The ‘addDataService’ method is called internally anytime a MetadataStore.fetchMetadata call occurs with a new dataService ( or service name). **/ export declare class DataService { /** @hidden @internal */ _$typeName: string; /** The serviceName for this DataService. __Read Only__ **/ serviceName: string; /** The adapter name for the [[IDataServiceAdapter]] to be used with this service. __Read Only__ **/ adapterName: string; /** The [[IDataServiceAdapter]] implementation instance associated with this EntityManager. __Read Only__ **/ adapterInstance?: DataServiceAdapter; /** The adapter name for the [[IUriBuilderAdapter]] to be used with this service. __Read Only__ **/ uriBuilderName: string; /** The [[IUriBuilderAdapter]] implementation instance associated with this EntityManager. __Read Only__ **/ uriBuilder?: UriBuilderAdapter; /** Whether the server can provide metadata for this service. __Read Only__ **/ hasServerMetadata: boolean; /** The [[JsonResultsAdapter]] used to process the results of any query against this DataService. __Read Only__ **/ jsonResultsAdapter: JsonResultsAdapter; /** Whether to use JSONP when performing a 'GET' request against this service. __Read Only__ **/ useJsonp: boolean; /** DataService constructor > var dataService = new DataService({ > serviceName: altServiceName, > hasServerMetadata: false > }); > var metadataStore = new MetadataStore({ > namingConvention: NamingConvention.camelCase > }); > return new EntityManager({ > dataService: dataService, > metadataStore: metadataStore > }); @param config - A configuration object. **/ constructor(config?: DataServiceConfig); /** Returns a copy of this DataService with the specified properties applied. @param config - The configuration object to apply to create a new DataService. **/ using(config: DataServiceConfig): DataService; static resolve(dataServices: DataService[]): DataService; /** @hidden @internal */ static _normalizeServiceName(serviceName: string): string; /** */ toJSON(): Object; static fromJSON(json: any): DataService; /** Returns a url for this dataService with the specified suffix. This method handles dataService names either with or without trailing '/'s. If the suffix starts with "http" then it will be returned as-is. @method qualifyUrl @param suffix {String} The resulting url. @return {a Url string} **/ qualifyUrl(suffix: string): string; } export interface NodeMeta { entityType?: EntityType; nodeId?: string; nodeRefId?: string; ignore?: boolean; passThru?: boolean; extraMetadata?: any; } export interface NodeContext { nodeType: string; propertyName?: string; navigationProperty?: NavigationProperty; } /** Configuration info to be passed to the [[JsonResultsAdapter]] constructor */ export interface JsonResultsAdapterConfig { /** The name of this adapter. This name is used to uniquely identify and locate this instance when an 'exported' JsonResultsAdapter is later imported. */ name: string; /** A Function that is called once per query operation to extract the 'payload' from any json received over the wire. This method has a default implementation which to simply return the "results" property from any json returned as a result of executing the query. */ extractResults?: Function; /** A function that is called once per save operation to extract the entities from any json received over the wire. Must return an array. This method has a default implementation which simply returns the "entities" property from any json returned as a result of executing the save. */ extractSaveResults?: Function; /** A function that is called once per save operation to extract the key mappings from any json received over the wire. Must return an array. This method has a default implementation which simply returns the "keyMappings" property from any json returned as a result of executing the save. */ extractKeyMappings?: (data: {}) => KeyMapping[]; /** A function that is called once per save operation to extract any deleted keys from any json received over the wire. Must return an array. This method has a default implementation which simply returns an empty array. */ extractDeletedKeys?: (data: {}) => any[]; /** A visitor method that will be called on each node of the returned payload. */ visitNode?: (v: any, mc?: MappingContext, nodeContext?: NodeContext) => NodeMeta; } /** A JsonResultsAdapter instance is used to provide custom extraction and parsing logic on the json results returned by any web service. This facility makes it possible for breeze to talk to virtually any web service and return objects that will be first class 'breeze' citizens. **/ export declare class JsonResultsAdapter { /** @hidden @internal */ _$typeName: string; /** The name of this adapter. This name is used to uniquely identify and locate this instance when an 'exported' JsonResultsAdapter is later imported. */ name: string; /** A Function that is called once per query operation to extract the 'payload' from any json received over the wire. This method has a default implementation which simply returns the "results" property from any json returned as a result of executing the query. */ extractResults: Function; /** A function that is called once per save operation to extract the entities from any json received over the wire. Must return an array. This method has a default implementation which simply returns the "entities" property from any json returned as a result of executing the save. */ extractSaveResults: Function; /** A function that is called once per save operation to extract the key mappings from any json received over the wire. Must return an array. This method has a default implementation which simply returns the "keyMappings" property from any json returned as a result of executing the save. */ extractKeyMappings: (data: {}) => KeyMapping[]; /** A function that is called once per save operation to extract any deleted keys from any json received over the wire. Must return an array. This method has a default implementation which is to simply returns the "deletedKeys" property from any json returned as a result of executing the save. */ extractDeletedKeys?: (data: {}) => any[]; /** A visitor method that will be called on each node of the returned payload. */ visitNode: Function; /** JsonResultsAdapter constructor @example // var jsonResultsAdapter = new JsonResultsAdapter({ name: "test1e", extractResults: function(json) { return json.results; }, visitNode: function(node, mappingContext, nodeContext) { var entityType = normalizeTypeName(node.$type); var propertyName = nodeContext.propertyName; var ignore = propertyName && propertyName.substr(0, 1) === "$"; return { entityType: entityType, nodeId: node.$id, nodeRefId: node.$ref, ignore: ignore, passThru: false // default }; } }); var dataService = new DataService( { serviceName: "breeze/foo", jsonResultsAdapter: jsonResultsAdapter }); var entityManager = new EntityManager( { dataService: dataService }); @param config - A configuration object. **/ constructor(jsConfig: JsonResultsAdapterConfig); }