1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | import { BehaviorSubject } from 'rxjs';
|
9 | import { HttpBackend } from '@angular/common/http';
|
10 | import { HttpEvent } from '@angular/common/http';
|
11 | import { HttpHeaders } from '@angular/common/http';
|
12 | import { HttpRequest } from '@angular/common/http';
|
13 | import { HttpResponse } from '@angular/common/http';
|
14 | import { HttpXhrBackend } from '@angular/common/http';
|
15 | import * as i0 from '@angular/core';
|
16 | import { ModuleWithProviders } from '@angular/core';
|
17 | import { Observable } from 'rxjs';
|
18 | import { Type } from '@angular/core';
|
19 | import { XhrFactory } from '@angular/common';
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | export declare abstract class BackendService {
|
29 | protected inMemDbService: InMemoryDbService;
|
30 | protected config: InMemoryBackendConfigArgs;
|
31 | protected db: {
|
32 | [key: string]: any;
|
33 | };
|
34 | protected dbReadySubject: BehaviorSubject<boolean> | undefined;
|
35 | private passThruBackend;
|
36 | protected requestInfoUtils: RequestInfoUtilities;
|
37 | constructor(inMemDbService: InMemoryDbService, config?: InMemoryBackendConfigArgs);
|
38 | protected get dbReady(): Observable<boolean>;
|
39 | /**
|
40 | * Process Request and return an Observable of Http Response object
|
41 | * in the manner of a RESTy web api.
|
42 | *
|
43 | * Expect URI pattern in the form :base/:collectionName/:id?
|
44 | * Examples:
|
45 | * // for store with a 'customers' collection
|
46 | * GET api/customers // all customers
|
47 | * GET api/customers/42 // the character with id=42
|
48 | * GET api/customers?name=^j // 'j' is a regex; returns customers whose name starts with 'j' or
|
49 | * 'J' GET api/customers.json/42 // ignores the ".json"
|
50 | *
|
51 | * Also accepts direct commands to the service in which the last segment of the apiBase is the
|
52 | * word "commands" Examples: POST commands/resetDb, GET/POST commands/config - get or (re)set the
|
53 | * config
|
54 | *
|
55 | * HTTP overrides:
|
56 | * If the injected inMemDbService defines an HTTP method (lowercase)
|
57 | * The request is forwarded to that method as in
|
58 | * `inMemDbService.get(requestInfo)`
|
59 | * which must return either an Observable of the response type
|
60 | * for this http library or null|undefined (which means "keep processing").
|
61 | */
|
62 | protected handleRequest(req: RequestCore): Observable<any>;
|
63 | protected handleRequest_(req: RequestCore): Observable<any>;
|
64 | /**
|
65 | * Add configured delay to response observable unless delay === 0
|
66 | */
|
67 | protected addDelay(response: Observable<any>): Observable<any>;
|
68 | /**
|
69 | * Apply query/search parameters as a filter over the collection
|
70 | * This impl only supports RegExp queries on string properties of the collection
|
71 | * ANDs the conditions together
|
72 | */
|
73 | protected applyQuery(collection: any[], query: Map<string, string[]>): any[];
|
74 | /**
|
75 | * Get a method from the `InMemoryDbService` (if it exists), bound to that service
|
76 | */
|
77 | protected bind<T extends Function>(methodName: string): T | undefined;
|
78 | protected bodify(data: any): any;
|
79 | protected clone(data: any): any;
|
80 | protected collectionHandler(reqInfo: RequestInfo_2): ResponseOptions;
|
81 | /**
|
82 | * Commands reconfigure the in-memory web api service or extract information from it.
|
83 | * Commands ignore the latency delay and respond ASAP.
|
84 | *
|
85 | * When the last segment of the `apiBase` path is "commands",
|
86 | * the `collectionName` is the command.
|
87 | *
|
88 | * Example URLs:
|
89 | * commands/resetdb (POST) // Reset the "database" to its original state
|
90 | * commands/config (GET) // Return this service's config object
|
91 | * commands/config (POST) // Update the config (e.g. the delay)
|
92 | *
|
93 | * Usage:
|
94 | * http.post('commands/resetdb', undefined);
|
95 | * http.get('commands/config');
|
96 | * http.post('commands/config', '{"delay":1000}');
|
97 | */
|
98 | protected commands(reqInfo: RequestInfo_2): Observable<any>;
|
99 | protected createErrorResponseOptions(url: string, status: number, message: string): ResponseOptions;
|
100 | /**
|
101 | * Create standard HTTP headers object from hash map of header strings
|
102 | * @param headers
|
103 | */
|
104 | protected abstract createHeaders(headers: {
|
105 | [index: string]: string;
|
106 | }): HttpHeaders;
|
107 | /**
|
108 | * create the function that passes unhandled requests through to the "real" backend.
|
109 | */
|
110 | protected abstract createPassThruBackend(): PassThruBackend;
|
111 | /**
|
112 | * return a search map from a location query/search string
|
113 | */
|
114 | protected abstract createQueryMap(search: string): Map<string, string[]>;
|
115 | /**
|
116 | * Create a cold response Observable from a factory for ResponseOptions
|
117 | * @param resOptionsFactory - creates ResponseOptions when observable is subscribed
|
118 | * @param withDelay - if true (default), add simulated latency delay from configuration
|
119 | */
|
120 | protected createResponse$(resOptionsFactory: () => ResponseOptions, withDelay?: boolean): Observable<any>;
|
121 | /**
|
122 | * Create a Response observable from ResponseOptions observable.
|
123 | */
|
124 | protected abstract createResponse$fromResponseOptions$(resOptions$: Observable<ResponseOptions>): Observable<any>;
|
125 | /**
|
126 | * Create a cold Observable of ResponseOptions.
|
127 | * @param resOptionsFactory - creates ResponseOptions when observable is subscribed
|
128 | */
|
129 | protected createResponseOptions$(resOptionsFactory: () => ResponseOptions): Observable<ResponseOptions>;
|
130 | protected delete({ collection, collectionName, headers, id, url }: RequestInfo_2): ResponseOptions;
|
131 | /**
|
132 | * Find first instance of item in collection by `item.id`
|
133 | * @param collection
|
134 | * @param id
|
135 | */
|
136 | protected findById<T extends {
|
137 | id: any;
|
138 | }>(collection: T[], id: any): T | undefined;
|
139 | |
140 |
|
141 |
|
142 |
|
143 |
|
144 |
|
145 | protected genId<T extends {
|
146 | id: any;
|
147 | }>(collection: T[], collectionName: string): any;
|
148 | |
149 |
|
150 |
|
151 |
|
152 |
|
153 |
|
154 | protected genIdDefault<T extends {
|
155 | id: any;
|
156 | }>(collection: T[], collectionName: string): any;
|
157 | protected get({ collection, collectionName, headers, id, query, url, }: RequestInfo_2): ResponseOptions;
|
158 |
|
159 | protected abstract getJsonBody(req: any): any;
|
160 | |
161 |
|
162 |
|
163 | protected getLocation(url: string): UriInfo;
|
164 | |
165 |
|
166 |
|
167 |
|
168 | protected getPassThruBackend(): PassThruBackend;
|
169 | |
170 |
|
171 |
|
172 |
|
173 | protected getRequestInfoUtils(): RequestInfoUtilities;
|
174 | |
175 |
|
176 |
|
177 |
|
178 |
|
179 |
|
180 | protected abstract getRequestMethod(req: any): string;
|
181 | protected indexOf(collection: any[], id: number): number;
|
182 |
|
183 | protected parseId(collection: any[], collectionName: string, id: string): any;
|
184 | |
185 |
|
186 |
|
187 |
|
188 | protected isCollectionIdNumeric<T extends {
|
189 | id: any;
|
190 | }>(collection: T[], collectionName: string): boolean;
|
191 | |
192 |
|
193 |
|
194 |
|
195 |
|
196 |
|
197 |
|
198 |
|
199 |
|
200 |
|
201 |
|
202 |
|
203 |
|
204 |
|
205 |
|
206 |
|
207 |
|
208 |
|
209 | protected parseRequestUrl(url: string): ParsedRequestUrl;
|
210 | protected post({ collection, collectionName, headers, id, req, resourceUrl, url, }: RequestInfo_2): ResponseOptions;
|
211 | protected put({ collection, collectionName, headers, id, req, url }: RequestInfo_2): ResponseOptions;
|
212 | protected removeById(collection: any[], id: number): boolean;
|
213 | |
214 |
|
215 |
|
216 |
|
217 | protected resetDb(reqInfo?: RequestInfo_2): Observable<boolean>;
|
218 | }
|
219 |
|
220 |
|
221 |
|
222 |
|
223 | export declare function getStatusText(code: number): string;
|
224 |
|
225 |
|
226 |
|
227 |
|
228 |
|
229 |
|
230 |
|
231 |
|
232 |
|
233 |
|
234 |
|
235 |
|
236 |
|
237 |
|
238 |
|
239 |
|
240 |
|
241 |
|
242 |
|
243 |
|
244 |
|
245 |
|
246 |
|
247 |
|
248 |
|
249 |
|
250 |
|
251 |
|
252 | export declare class HttpClientBackendService extends BackendService implements HttpBackend {
|
253 | private xhrFactory;
|
254 | constructor(inMemDbService: InMemoryDbService, config: InMemoryBackendConfigArgs, xhrFactory: XhrFactory);
|
255 | handle(req: HttpRequest<any>): Observable<HttpEvent<any>>;
|
256 | protected getJsonBody(req: HttpRequest<any>): any;
|
257 | protected getRequestMethod(req: HttpRequest<any>): string;
|
258 | protected createHeaders(headers: {
|
259 | [index: string]: string;
|
260 | }): HttpHeaders;
|
261 | protected createQueryMap(search: string): Map<string, string[]>;
|
262 | protected createResponse$fromResponseOptions$(resOptions$: Observable<ResponseOptions>): Observable<HttpResponse<any>>;
|
263 | protected createPassThruBackend(): HttpXhrBackend;
|
264 | static ɵfac: i0.ɵɵFactoryDeclaration<HttpClientBackendService, [null, { optional: true; }, null]>;
|
265 | static ɵprov: i0.ɵɵInjectableDeclaration<HttpClientBackendService>;
|
266 | }
|
267 |
|
268 | export declare function httpClientInMemBackendServiceFactory(dbService: InMemoryDbService, options: InMemoryBackendConfig, xhrFactory: XhrFactory): HttpBackend;
|
269 |
|
270 | export declare class HttpClientInMemoryWebApiModule {
|
271 | |
272 |
|
273 |
|
274 |
|
275 |
|
276 |
|
277 |
|
278 |
|
279 |
|
280 |
|
281 |
|
282 |
|
283 |
|
284 |
|
285 |
|
286 |
|
287 |
|
288 |
|
289 | static forRoot(dbCreator: Type<InMemoryDbService>, options?: InMemoryBackendConfigArgs): ModuleWithProviders<HttpClientInMemoryWebApiModule>;
|
290 | |
291 |
|
292 |
|
293 |
|
294 |
|
295 |
|
296 | static forFeature(dbCreator: Type<InMemoryDbService>, options?: InMemoryBackendConfigArgs): ModuleWithProviders<HttpClientInMemoryWebApiModule>;
|
297 | static ɵfac: i0.ɵɵFactoryDeclaration<HttpClientInMemoryWebApiModule, never>;
|
298 | static ɵmod: i0.ɵɵNgModuleDeclaration<HttpClientInMemoryWebApiModule, never, never, never>;
|
299 | static ɵinj: i0.ɵɵInjectorDeclaration<HttpClientInMemoryWebApiModule>;
|
300 | }
|
301 |
|
302 |
|
303 |
|
304 |
|
305 |
|
306 |
|
307 |
|
308 |
|
309 |
|
310 | export declare class InMemoryBackendConfig implements InMemoryBackendConfigArgs {
|
311 | constructor(config?: InMemoryBackendConfigArgs);
|
312 | static ɵfac: i0.ɵɵFactoryDeclaration<InMemoryBackendConfig, never>;
|
313 | static ɵprov: i0.ɵɵInjectableDeclaration<InMemoryBackendConfig>;
|
314 | }
|
315 |
|
316 | /**
|
317 | * Interface for InMemoryBackend configuration options
|
318 | */
|
319 | export declare abstract class InMemoryBackendConfigArgs {
|
320 | |
321 |
|
322 |
|
323 |
|
324 | apiBase?: string;
|
325 | |
326 |
|
327 |
|
328 | caseSensitiveSearch?: boolean;
|
329 | |
330 |
|
331 |
|
332 |
|
333 | dataEncapsulation?: boolean;
|
334 | |
335 |
|
336 |
|
337 | delay?: number;
|
338 | |
339 |
|
340 |
|
341 | delete404?: boolean;
|
342 | |
343 |
|
344 |
|
345 | host?: string;
|
346 | |
347 |
|
348 |
|
349 | passThruUnknownUrl?: boolean;
|
350 | |
351 |
|
352 |
|
353 | post204?: boolean;
|
354 | |
355 |
|
356 |
|
357 | post409?: boolean;
|
358 | |
359 |
|
360 |
|
361 | put204?: boolean;
|
362 | |
363 |
|
364 |
|
365 | put404?: boolean;
|
366 | |
367 |
|
368 |
|
369 | rootPath?: string;
|
370 | }
|
371 |
|
372 |
|
373 |
|
374 |
|
375 |
|
376 |
|
377 |
|
378 |
|
379 |
|
380 |
|
381 |
|
382 | export declare abstract class InMemoryDbService {
|
383 | |
384 |
|
385 |
|
386 |
|
387 |
|
388 |
|
389 |
|
390 |
|
391 |
|
392 |
|
393 |
|
394 |
|
395 |
|
396 |
|
397 |
|
398 | abstract createDb(reqInfo?: RequestInfo_2): {} | Observable<{}> | Promise<{}>;
|
399 | }
|
400 |
|
401 | export declare class InMemoryWebApiModule {
|
402 | |
403 |
|
404 |
|
405 |
|
406 |
|
407 |
|
408 |
|
409 |
|
410 |
|
411 |
|
412 |
|
413 |
|
414 |
|
415 |
|
416 |
|
417 |
|
418 |
|
419 |
|
420 | static forRoot(dbCreator: Type<InMemoryDbService>, options?: InMemoryBackendConfigArgs): ModuleWithProviders<InMemoryWebApiModule>;
|
421 | |
422 |
|
423 |
|
424 |
|
425 |
|
426 |
|
427 | static forFeature(dbCreator: Type<InMemoryDbService>, options?: InMemoryBackendConfigArgs): ModuleWithProviders<InMemoryWebApiModule>;
|
428 | static ɵfac: i0.ɵɵFactoryDeclaration<InMemoryWebApiModule, never>;
|
429 | static ɵmod: i0.ɵɵNgModuleDeclaration<InMemoryWebApiModule, never, never, never>;
|
430 | static ɵinj: i0.ɵɵInjectorDeclaration<InMemoryWebApiModule>;
|
431 | }
|
432 |
|
433 |
|
434 |
|
435 |
|
436 | export declare function isSuccess(status: number): boolean;
|
437 |
|
438 |
|
439 |
|
440 |
|
441 |
|
442 |
|
443 |
|
444 |
|
445 |
|
446 |
|
447 |
|
448 | export declare interface ParsedRequestUrl {
|
449 | apiBase: string;
|
450 | collectionName: string;
|
451 | id: string;
|
452 | query: Map<string, string[]>;
|
453 | resourceUrl: string;
|
454 | }
|
455 |
|
456 |
|
457 | export declare function parseUri(str: string): UriInfo;
|
458 |
|
459 | export declare interface PassThruBackend {
|
460 | |
461 |
|
462 |
|
463 |
|
464 | handle(req: any): Observable<any>;
|
465 | }
|
466 |
|
467 | export declare function removeTrailingSlash(path: string): string;
|
468 |
|
469 |
|
470 |
|
471 |
|
472 | export declare interface RequestCore {
|
473 | url: string;
|
474 | urlWithParams?: string;
|
475 | }
|
476 |
|
477 |
|
478 |
|
479 |
|
480 |
|
481 |
|
482 | declare interface RequestInfo_2 {
|
483 | req: RequestCore;
|
484 | apiBase: string;
|
485 | collectionName: string;
|
486 | collection: any;
|
487 | headers: HttpHeaders;
|
488 | method: string;
|
489 | id: any;
|
490 | query: Map<string, string[]>;
|
491 | resourceUrl: string;
|
492 | url: string;
|
493 | utils: RequestInfoUtilities;
|
494 | }
|
495 | export { RequestInfo_2 as RequestInfo }
|
496 |
|
497 |
|
498 |
|
499 |
|
500 |
|
501 | export declare interface RequestInfoUtilities {
|
502 | |
503 |
|
504 |
|
505 |
|
506 |
|
507 |
|
508 | createResponse$: (resOptionsFactory: () => ResponseOptions) => Observable<any>;
|
509 | |
510 |
|
511 |
|
512 |
|
513 |
|
514 | findById<T extends {
|
515 | id: any;
|
516 | }>(collection: T[], id: any): T | undefined;
|
517 |
|
518 | getConfig(): InMemoryBackendConfigArgs;
|
519 |
|
520 | getDb(): {};
|
521 |
|
522 | getJsonBody(req: any): any;
|
523 |
|
524 | getLocation(url: string): UriInfo;
|
525 |
|
526 | getPassThruBackend(): PassThruBackend;
|
527 | |
528 |
|
529 |
|
530 | isCollectionIdNumeric<T extends {
|
531 | id: any;
|
532 | }>(collection: T[], collectionName: string): boolean;
|
533 | |
534 |
|
535 |
|
536 |
|
537 | parseRequestUrl(url: string): ParsedRequestUrl;
|
538 | }
|
539 |
|
540 |
|
541 |
|
542 |
|
543 |
|
544 | export declare type ResponseInterceptor = (res: ResponseOptions, ri: RequestInfo_2) => ResponseOptions;
|
545 |
|
546 | export declare interface ResponseOptions {
|
547 | |
548 |
|
549 |
|
550 | body?: string | Object | ArrayBuffer | Blob;
|
551 | |
552 |
|
553 |
|
554 | headers?: HttpHeaders;
|
555 | |
556 |
|
557 |
|
558 |
|
559 | status?: number;
|
560 | |
561 |
|
562 |
|
563 | statusText?: string;
|
564 | |
565 |
|
566 |
|
567 | url?: string;
|
568 | }
|
569 |
|
570 |
|
571 | export declare const STATUS: {
|
572 | CONTINUE: number;
|
573 | SWITCHING_PROTOCOLS: number;
|
574 | OK: number;
|
575 | CREATED: number;
|
576 | ACCEPTED: number;
|
577 | NON_AUTHORITATIVE_INFORMATION: number;
|
578 | NO_CONTENT: number;
|
579 | RESET_CONTENT: number;
|
580 | PARTIAL_CONTENT: number;
|
581 | MULTIPLE_CHOICES: number;
|
582 | MOVED_PERMANTENTLY: number;
|
583 | FOUND: number;
|
584 | SEE_OTHER: number;
|
585 | NOT_MODIFIED: number;
|
586 | USE_PROXY: number;
|
587 | TEMPORARY_REDIRECT: number;
|
588 | BAD_REQUEST: number;
|
589 | UNAUTHORIZED: number;
|
590 | PAYMENT_REQUIRED: number;
|
591 | FORBIDDEN: number;
|
592 | NOT_FOUND: number;
|
593 | METHOD_NOT_ALLOWED: number;
|
594 | NOT_ACCEPTABLE: number;
|
595 | PROXY_AUTHENTICATION_REQUIRED: number;
|
596 | REQUEST_TIMEOUT: number;
|
597 | CONFLICT: number;
|
598 | GONE: number;
|
599 | LENGTH_REQUIRED: number;
|
600 | PRECONDITION_FAILED: number;
|
601 | PAYLOAD_TO_LARGE: number;
|
602 | URI_TOO_LONG: number;
|
603 | UNSUPPORTED_MEDIA_TYPE: number;
|
604 | RANGE_NOT_SATISFIABLE: number;
|
605 | EXPECTATION_FAILED: number;
|
606 | IM_A_TEAPOT: number;
|
607 | UPGRADE_REQUIRED: number;
|
608 | INTERNAL_SERVER_ERROR: number;
|
609 | NOT_IMPLEMENTED: number;
|
610 | BAD_GATEWAY: number;
|
611 | SERVICE_UNAVAILABLE: number;
|
612 | GATEWAY_TIMEOUT: number;
|
613 | HTTP_VERSION_NOT_SUPPORTED: number;
|
614 | PROCESSING: number;
|
615 | MULTI_STATUS: number;
|
616 | IM_USED: number;
|
617 | PERMANENT_REDIRECT: number;
|
618 | UNPROCESSABLE_ENTRY: number;
|
619 | LOCKED: number;
|
620 | FAILED_DEPENDENCY: number;
|
621 | PRECONDITION_REQUIRED: number;
|
622 | TOO_MANY_REQUESTS: number;
|
623 | REQUEST_HEADER_FIELDS_TOO_LARGE: number;
|
624 | UNAVAILABLE_FOR_LEGAL_REASONS: number;
|
625 | VARIANT_ALSO_NEGOTIATES: number;
|
626 | INSUFFICIENT_STORAGE: number;
|
627 | NETWORK_AUTHENTICATION_REQUIRED: number;
|
628 | };
|
629 |
|
630 | export declare const STATUS_CODE_INFO: {
|
631 | [key: string]: {
|
632 | code: number;
|
633 | text: string;
|
634 | description: string;
|
635 | spec_title: string;
|
636 | spec_href: string;
|
637 | };
|
638 | };
|
639 |
|
640 |
|
641 | export declare interface UriInfo {
|
642 | source: string;
|
643 | protocol: string;
|
644 | authority: string;
|
645 | userInfo: string;
|
646 | user: string;
|
647 | password: string;
|
648 | host: string;
|
649 | port: string;
|
650 | relative: string;
|
651 | path: string;
|
652 | directory: string;
|
653 | file: string;
|
654 | query: string;
|
655 | anchor: string;
|
656 | }
|
657 |
|
658 | export { }
|