Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AjaxObservable.d.ts 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. import { Observable } from '../../Observable';
  2. import { Subscriber } from '../../Subscriber';
  3. import { TeardownLogic } from '../../types';
  4. export interface AjaxRequest {
  5. url?: string;
  6. body?: any;
  7. user?: string;
  8. async?: boolean;
  9. method?: string;
  10. headers?: Object;
  11. timeout?: number;
  12. password?: string;
  13. hasContent?: boolean;
  14. crossDomain?: boolean;
  15. withCredentials?: boolean;
  16. createXHR?: () => XMLHttpRequest;
  17. progressSubscriber?: Subscriber<any>;
  18. responseType?: string;
  19. }
  20. export interface AjaxCreationMethod {
  21. (urlOrRequest: string | AjaxRequest): Observable<AjaxResponse>;
  22. get(url: string, headers?: Object): Observable<AjaxResponse>;
  23. post(url: string, body?: any, headers?: Object): Observable<AjaxResponse>;
  24. put(url: string, body?: any, headers?: Object): Observable<AjaxResponse>;
  25. patch(url: string, body?: any, headers?: Object): Observable<AjaxResponse>;
  26. delete(url: string, headers?: Object): Observable<AjaxResponse>;
  27. getJSON<T>(url: string, headers?: Object): Observable<T>;
  28. }
  29. export declare function ajaxGet(url: string, headers?: Object): AjaxObservable<AjaxResponse>;
  30. export declare function ajaxPost(url: string, body?: any, headers?: Object): Observable<AjaxResponse>;
  31. export declare function ajaxDelete(url: string, headers?: Object): Observable<AjaxResponse>;
  32. export declare function ajaxPut(url: string, body?: any, headers?: Object): Observable<AjaxResponse>;
  33. export declare function ajaxPatch(url: string, body?: any, headers?: Object): Observable<AjaxResponse>;
  34. export declare function ajaxGetJSON<T>(url: string, headers?: Object): Observable<T>;
  35. /**
  36. * We need this JSDoc comment for affecting ESDoc.
  37. * @extends {Ignored}
  38. * @hide true
  39. */
  40. export declare class AjaxObservable<T> extends Observable<T> {
  41. /**
  42. * Creates an observable for an Ajax request with either a request object with
  43. * url, headers, etc or a string for a URL.
  44. *
  45. * ## Example
  46. * ```javascript
  47. * source = Rx.Observable.ajax('/products');
  48. * source = Rx.Observable.ajax({ url: 'products', method: 'GET' });
  49. * ```
  50. *
  51. * @param {string|Object} request Can be one of the following:
  52. * A string of the URL to make the Ajax call.
  53. * An object with the following properties
  54. * - url: URL of the request
  55. * - body: The body of the request
  56. * - method: Method of the request, such as GET, POST, PUT, PATCH, DELETE
  57. * - async: Whether the request is async
  58. * - headers: Optional headers
  59. * - crossDomain: true if a cross domain request, else false
  60. * - createXHR: a function to override if you need to use an alternate
  61. * XMLHttpRequest implementation.
  62. * - resultSelector: a function to use to alter the output value type of
  63. * the Observable. Gets {@link AjaxResponse} as an argument.
  64. * @return {Observable} An observable sequence containing the XMLHttpRequest.
  65. * @static true
  66. * @name ajax
  67. * @owner Observable
  68. * @nocollapse
  69. */
  70. static create: AjaxCreationMethod;
  71. private request;
  72. constructor(urlOrRequest: string | AjaxRequest);
  73. /** @deprecated This is an internal implementation detail, do not use. */
  74. _subscribe(subscriber: Subscriber<T>): TeardownLogic;
  75. }
  76. /**
  77. * We need this JSDoc comment for affecting ESDoc.
  78. * @ignore
  79. * @extends {Ignored}
  80. */
  81. export declare class AjaxSubscriber<T> extends Subscriber<Event> {
  82. request: AjaxRequest;
  83. private xhr;
  84. private done;
  85. constructor(destination: Subscriber<T>, request: AjaxRequest);
  86. next(e: Event): void;
  87. private send;
  88. private serializeBody;
  89. private setHeaders;
  90. private setupEvents;
  91. unsubscribe(): void;
  92. }
  93. /**
  94. * A normalized AJAX response.
  95. *
  96. * @see {@link ajax}
  97. *
  98. * @class AjaxResponse
  99. */
  100. export declare class AjaxResponse {
  101. originalEvent: Event;
  102. xhr: XMLHttpRequest;
  103. request: AjaxRequest;
  104. /** @type {number} The HTTP status code */
  105. status: number;
  106. /** @type {string|ArrayBuffer|Document|object|any} The response data */
  107. response: any;
  108. /** @type {string} The raw responseText */
  109. responseText: string;
  110. /** @type {string} The responseType (e.g. 'json', 'arraybuffer', or 'xml') */
  111. responseType: string;
  112. constructor(originalEvent: Event, xhr: XMLHttpRequest, request: AjaxRequest);
  113. }
  114. export declare type AjaxErrorNames = 'AjaxError' | 'AjaxTimeoutError';
  115. /**
  116. * A normalized AJAX error.
  117. *
  118. * @see {@link ajax}
  119. *
  120. * @class AjaxError
  121. */
  122. export interface AjaxError extends Error {
  123. /** @type {XMLHttpRequest} The XHR instance associated with the error */
  124. xhr: XMLHttpRequest;
  125. /** @type {AjaxRequest} The AjaxRequest associated with the error */
  126. request: AjaxRequest;
  127. /** @type {number} The HTTP status code */
  128. status: number;
  129. /** @type {string} The responseType (e.g. 'json', 'arraybuffer', or 'xml') */
  130. responseType: string;
  131. /** @type {string|ArrayBuffer|Document|object|any} The response data */
  132. response: any;
  133. }
  134. export interface AjaxErrorCtor {
  135. new (message: string, xhr: XMLHttpRequest, request: AjaxRequest): AjaxError;
  136. }
  137. export declare const AjaxError: AjaxErrorCtor;
  138. export interface AjaxTimeoutError extends AjaxError {
  139. }
  140. export interface AjaxTimeoutErrorCtor {
  141. new (xhr: XMLHttpRequest, request: AjaxRequest): AjaxTimeoutError;
  142. }
  143. /**
  144. * @see {@link ajax}
  145. *
  146. * @class AjaxTimeoutError
  147. */
  148. export declare const AjaxTimeoutError: AjaxTimeoutErrorCtor;