import { Type } from '@angular/core'; import { HttpClient, HttpRequest, HttpResponse } from '@angular/common/http'; import { ResourceModel } from './resource-model'; import { ResourceConfigurationOptions } from './resource-configuration-options'; import { ResourceActionOptions } from './resource-action-options'; import { ResourceInstance } from './resource-instance'; import { ResourceActionMethod } from './resource-action-method'; import { PhantomGenerator } from './phantom-generator/phantom-generator'; import { ResourceRegistry } from './resource-registry'; import { ResourceCache } from '../cache/resource-cache'; import * as i0 from "@angular/core"; /** * Type alias for a `ResourceInstance` enriched with `ResourceModel` properties. */ export declare type ResourceModelObject = ResourceModel; /** * Type alias for a `ResourceInstance` list enriched with `ResourceModel` properties. */ export declare type ResourceModelList = ResourceModel; /** * Type alias for a result objects of resource action methods. */ export declare type ResourceModelResult = ResourceModelObject & ResourceModelList; /** * Base class for resources without any resource actions defined. */ export declare abstract class ResourceBase { protected registry: ResourceRegistry; protected http: HttpClient; /** * Map of action methods. Populated by the `@ResourceAction` decorator. Used to create the * resource action methods on `ResourceModel` objects. * @type {Map} */ protected actionMethods: Map; /** * Singleton instance of the configured phantom ID generator class. * @type {PhantomGenerator} */ protected phantomGenerator: PhantomGenerator; /** * Singleton instance of the configured cache class. * @type {ResourceCache} */ protected cache: ResourceCache; constructor(registry: ResourceRegistry, http: HttpClient); /** * Binds the given resource instance to the resource. * @param {T} obj Resource instance * @returns {T} The given resource instance bound to the resource */ bind(obj: T): ResourceModel; /** * Gets the resource configurations. This method is just a stub method and will be replaced by the * `ResourceConfiguration` decorator. * @returns {ResourceConfigurationOptions} */ getOptions(): ResourceConfigurationOptions; /** * Register an resource action method for the resource. This is usually done by the `@ResourceAction` * decorator. * @param {string} name Name of the resource action. * @param {Function} fn Function of the resource action. */ registerActionMethod(name: string, fn: Function): void; /** * Gets the phantom ID generator class instance. * @returns {PhantomGenerator} */ getPhantomGenerator(): PhantomGenerator; /** * Gets the cache class instance. * @returns {ResourceCache} */ getCache(): ResourceCache; /** * Creates a resource model from the given payload. * @param {object} payload Payload for the created object * @param {Type} instanceClass Class to instantiate (defaults to `instanceClass` on `options`) * @returns {ResourceModelObject} */ protected makeResourceModel(payload: object, instanceClass?: Type): ResourceModelObject; /** * Creates a resource model list from the given payload list. * @param payload * @returns {ResourceModelList} */ protected makeResourceModelList(payload: any[]): ResourceModelList; /** * Processes the request for a resource. Builds the query from the given query data and the payload from the given * payload data. Executes the request according to the given action options and the configuration on the * resource itself. Will call the success callback if everything went fine and call the error callback in case * of an failure. * @param query Query data. * @param payload Payload data. * @param {Function} success Success callback function. * @param {Function} error Error callback function. * @param {ResourceActionOptions} actionOptions Options for the action to execute. * @returns {ResourceModel} */ protected executeResourceAction(query: any, payload: any, success: Function, error: Function, actionOptions: ResourceActionOptions): ResourceModelResult; /** * Executes the given request and contributes the result to the given resource model object. * @param {ResourceModelResult} obj The object that should hold the result data. * @param {HttpRequest} request The request to execute. * @param {ResourceActionOptions} actionOptions Configuration options of the resource action. * @returns {ResourceModelResult} */ protected executeResourceActionRequest(obj: ResourceModelResult, request: HttpRequest, actionOptions: ResourceActionOptions): ResourceModelResult; /** * Contributes the core attributes for a resource model object to the given object. Returns the given * object with the type assurance of a `ResourceModelResult` object. * @param obj Object to contribute resource model properties to. * @returns {ResourceModelResult} */ protected contributeResourceModelProperties(obj: any): ResourceModelResult; /** * Contributes the http attributes (request and response) for a resource model object to the given object. Returns * the given object with the type assurance of a `ResourceModelResult` object. * @param obj Object to contribute resource model properties to. * @param {HttpRequest} request Request instance to contribute. * @param {HttpResponse} response Response instance to contribute. * @returns {ResourceModelResult} */ protected contributeResourceModelRequestResponseProperties(obj: any, request?: HttpRequest, response?: HttpResponse): ResourceModelResult; /** * Contributes the list attributes (e.g. `totalAttr`) to the resource model object. Returns the given object with * the type assurance of a `ResourceModelResult` object. * @param obj Object to contribute resource model list properties to. * @param {number} total The value of the `totalAttr` */ protected contributeResourceModelListProperties(obj: any, total?: number): ResourceModelResult; /** * Processes the object or list response depending on the type of the given body. If it is a list * this method will invoke `processListResponse` and if it is an object this method will * invoke `processObjectResponse`. Will do nothing if the expected response type on the `actionOptions` is not * set to "json". * @param {ResourceModelResult} result The result list that should contain the data. * @param {HttpRequest} request Request instance to contribute. * @param {HttpResponse} response Response instance to contribute. * @param {ResourceActionOptions} actionOptions The resource action configuration. * @returns {ResourceModelResult} */ protected processResponse(result: ResourceModelResult, request: HttpRequest, response: HttpResponse, actionOptions: ResourceActionOptions): ResourceModelResult; /** * Processes the list response, meaning that it iterates through the JSON list in the response, and * pushes each item as resource model object on the result list. * @param {ResourceModelResult} result The result list that should contain the data. * @param {HttpRequest} request Request instance to contribute. * @param {HttpResponse} response Response instance to contribute. * @param {ResourceActionOptions} actionOptions The resource action configuration. * @returns {ResourceModelResult} */ protected processListResponse(result: ResourceModelResult, request: HttpRequest, response: HttpResponse, actionOptions: ResourceActionOptions): ResourceModelResult; /** * Processes the object response, meaning that it checks if the response was a valid object response and * contributes the response data to the result object. * @param {ResourceModelResult} result The result list that should contain the data. * @param {HttpRequest} request Request instance to contribute. * @param {HttpResponse} response Response instance to contribute. * @param {ResourceActionOptions} actionOptions The resource action configuration. * @returns {ResourceModelResult} */ protected processObjectResponse(result: ResourceModelResult, _request: HttpRequest, response: HttpResponse, actionOptions: ResourceActionOptions): ResourceModelResult; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵprov: i0.ɵɵInjectableDeclaration; } /** * Resource class that most of the application specific resource classes will inherit from. Has a reasonable set * of resource actions predefined. You may want to override these in order to customize their behaviour. If you do * not want any predefined actions, consider inheriting from `ResourceBase` instead. */ export declare abstract class Resource extends ResourceBase { /** * Creates a resource instance with the given payload. * @param {object} payload Payload for the instance. * @returns {ResourceModel} */ create(payload?: object): ResourceModel; query: ResourceActionMethod; get: ResourceActionMethod; save: ResourceActionMethod; update: ResourceActionMethod; remove: ResourceActionMethod; static ɵfac: i0.ɵɵFactoryDeclaration, never>; static ɵprov: i0.ɵɵInjectableDeclaration>; } /** * Exception that is thrown when a `Resource` method is used that needs the resource instance to be set up, before * it is actually set up. */ export declare class ResourceNeedsOptionsError extends Error { } /** * Exception that is thrown when a `Resource` method is used that needs the resource instance to be set up, before * it is actually set up. */ export declare class ResourceUnexpectedResponseError extends Error { } /** * Decorator that marks a method on `Resource` classes that needs the resource instance to be set up before it * is called. * @constructor */ export declare function NeedsOptions(): (_target: ResourceBase, _: string, descriptor: PropertyDescriptor) => PropertyDescriptor;