import { DataServiceAdapter, AjaxAdapter, AjaxConfig, ChangeRequestInterceptorCtor, ChangeRequestInterceptor } from '../config/interface-registry.js'; import { MappingContext } from '../query/mapping-context.js'; import { DataService, JsonResultsAdapter } from '../metadata/data-service.js'; import { HttpResponse, SaveContext, SaveBundle, ServerError, SaveResult, QueryResult } from '../manager/entity-manager.js'; import { MetadataStore } from '../metadata/entity-metadata.js'; /** For use by breeze plugin authors only. The class is used as the base class for most {@link DataServiceAdapter} implementations @adapter (see {@link DataServiceAdapter}) @hidden */ export declare abstract class AbstractDataServiceAdapter implements DataServiceAdapter { /** The name of this adapter. */ name: string; /** * The ajax adapter requests go through: the registered default if there is one, otherwise * a built-in one that uses `config.fetch`. * @deprecated Make requests with `_ajax`, and supply the transport with * `configureBreeze({ fetch })`. */ ajaxImpl: AjaxAdapter; checkForRecomposition(interfaceInitializedArgs: any): void; initialize(): void; /** * Sends one request. Resolves with the response, or rejects with a `ServerError`. * * Subclasses should make their requests through this method rather than through * `ajaxImpl`, whose callback-shaped contract is kept only for compatibility. This is the * only place in the class that deals in success/error callbacks. */ protected _ajax(config: Omit, errorMessagePrefix?: string, prepareResponse?: (httpResponse: HttpResponse) => void): Promise; fetchMetadata(metadataStore: MetadataStore, dataService: DataService): Promise; /** Execute the query in the mappingContext. */ executeQuery(mappingContext: MappingContext): Promise; /** Set up ajax parameters for query GET. This puts the query into the request querystring, in whatever syntax the UriBuilder produces. */ _makeQueryGetParams(mappingContext: MappingContext): { type: string; url: string; params: Object; dataType: string; crossDomain: boolean; }; /** Set up ajax parameters for query POST. This put the query into the request body as JSON. */ _makeQueryPostParams(mappingContext: MappingContext): { type: string; url: string; params: Object; dataType: string; processData: boolean; contentType: string; data: string; crossDomain: boolean; }; saveChanges(saveContext: SaveContext, saveBundle: SaveBundle): Promise; /** Abstract method that needs to be overwritten in any concrete DataServiceAdapter subclass. The return value from this method should be a serializable object that will be sent to the server after calling JSON.stringify on it. */ _prepareSaveBundle(saveContext: SaveContext, saveBundle: SaveBundle): any; /** Returns a constructor function for a "ChangeRequestInterceptor" that can tweak the saveBundle both as it is built and when it is completed by a concrete DataServiceAdapater. Initialized with a default, no-op implementation that developers can replace with a substantive implementation that changes the individual entity change requests or aspects of the entire 'saveBundle' without having to write their own DataService adapters. ```ts let adapter = breeze.config.getAdapterInstance('dataService'); adapter.changeRequestInterceptor = function (saveContext, saveBundle) { this.getRequest = function (request, entity, index) { // alter the request that the adapter prepared for this entity // based on the entity, saveContext, and saveBundle // e.g., add a custom header or prune the originalValuesMap return request; }; this.done = function (requests) { // alter the array of requests representing the entire change-set // based on the saveContext and saveBundle }; } ``` @param saveContext - The BreezeJS "context" for the save operation. @param saveBundle - Contains the array of entities-to-be-saved (AKA, the entity change-set). @returns Constructor for a "ChangeRequestInterceptor". */ changeRequestInterceptor: ChangeRequestInterceptorCtor; /** * Creates the change request interceptor for one save, from `changeRequestInterceptor`. * Call it at the start of `_prepareSaveBundle`, pass each entity's request through its * `getRequest`, and pass the finished array to its `done`. * * Falls back to a no-op interceptor when `changeRequestInterceptor` is not set. If the * interceptor it creates has `oneTime` set, the adapter goes back to the no-op * interceptor afterwards, so only this save is intercepted. * @throws if the interceptor has no `getRequest` or `done` method. */ protected _createChangeRequestInterceptor(saveContext: SaveContext, saveBundle: SaveBundle): ChangeRequestInterceptor; /** Abstract method that needs to be overwritten in any concrete DataServiceAdapter sublclass. This method needs to take the result returned the server and convert it into an ISaveResult. */ _prepareSaveResult(saveContext: SaveContext, data: any): SaveResult; /** Utility method that may be used in any concrete DataServiceAdapter sublclass to handle any http connection issues. For an error with status 0 - the request got no response - it says in the message that the server could not be reached, keeping any message the transport gave. An aborted request is left alone. `makeHttpError` already applies it. */ static _catchNoConnectionError(err: ServerError): void; /** * Builds the Breeze error for a failed HTTP response: an `Error` carrying `status`, * `statusText`, `url`, `body` and `httpResponse`, whose message comes from the response * body (a .NET exception, or `{ message, errors }`). For a save, it also carries the * server's per-entity `entityErrors`, if `httpResponse.saveContext` is set. * * `_ajax` uses it for every failed request. Call it when your adapter makes a request some * other way, then throw or reject with the result. * @param httpResponse - The failed response. * @param messagePrefix - Put at the start of the message, followed by "; ". */ static makeHttpError(httpResponse: HttpResponse, messagePrefix?: string): ServerError; jsonResultsAdapter: JsonResultsAdapter; }