1 | import { OpaqueToken } from '@angular/core';
|
2 | import { Connection, Headers, Request, Response, ResponseOptions, URLSearchParams } from '@angular/http';
|
3 | import 'rxjs/add/operator/delay';
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | export declare const SEED_DATA: OpaqueToken;
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | export interface InMemoryDbService {
|
14 | |
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | createDb(): {};
|
23 | }
|
24 |
|
25 |
|
26 |
|
27 | export interface InMemoryBackendConfigArgs {
|
28 | |
29 |
|
30 |
|
31 | defaultResponseOptions?: ResponseOptions;
|
32 | |
33 |
|
34 |
|
35 | delay?: number;
|
36 | |
37 |
|
38 |
|
39 | delete404?: boolean;
|
40 | |
41 |
|
42 |
|
43 | host?: string;
|
44 | |
45 |
|
46 |
|
47 | rootPath?: string;
|
48 | }
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 | export declare class InMemoryBackendConfig implements InMemoryBackendConfigArgs {
|
55 | constructor(config?: InMemoryBackendConfigArgs);
|
56 | }
|
57 | /**
|
58 | * Interface for object w/ info about the current request url
|
59 | * extracted from an Http Request
|
60 | */
|
61 | export interface ReqInfo {
|
62 | req: Request;
|
63 | base: string;
|
64 | collection: any[];
|
65 | collectionName: string;
|
66 | headers: Headers;
|
67 | id: any;
|
68 | query: URLSearchParams;
|
69 | resourceUrl: string;
|
70 | }
|
71 | export declare const isSuccess: (status: number) => boolean;
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 | export declare class InMemoryBackendService {
|
102 | private seedData;
|
103 | protected config: InMemoryBackendConfigArgs;
|
104 | protected db: {};
|
105 | constructor(seedData: InMemoryDbService, config: InMemoryBackendConfigArgs);
|
106 | createConnection(req: Request): Connection;
|
107 | /**
|
108 | * Process Request and return an Http Response object
|
109 | * in the manner of a RESTy web api.
|
110 | *
|
111 | * Expect URI pattern in the form :base/:collectionName/:id?
|
112 | * Examples:
|
113 | * // for store with a 'characters' collection
|
114 | * GET api/characters // all characters
|
115 | * GET api/characters/42 // the character with id=42
|
116 | * GET api/characters?name=^j // 'j' is a regex; returns characters whose name contains 'j' or 'J'
|
117 | * GET api/characters.json/42 // ignores the ".json"
|
118 | *
|
119 | * POST commands/resetDb // resets the "database"
|
120 | */
|
121 | protected handleRequest(req: Request): Response;
|
122 | /**
|
123 | * Apply query/search parameters as a filter over the collection
|
124 | * This impl only supports RegExp queries on string properties of the collection
|
125 | * ANDs the conditions together
|
126 | */
|
127 | protected applyQuery(collection: any[], query: URLSearchParams): any[];
|
128 | protected clone(data: any): any;
|
129 | /**
|
130 | * When the `base`="commands", the `collectionName` is the command
|
131 | * Example URLs:
|
132 | * commands/resetdb // Reset the "database" to its original state
|
133 | * commands/config (GET) // Return this service's config object
|
134 | * commands/config (!GET) // Update the config (e.g. delay)
|
135 | *
|
136 | * Usage:
|
137 | * http.post('commands/resetdb', null);
|
138 | * http.get('commands/config');
|
139 | * http.post('commands/config', '{"delay":1000}');
|
140 | */
|
141 | protected commands(reqInfo: ReqInfo): ResponseOptions;
|
142 | protected createErrorResponse(status: number, message: string): ResponseOptions;
|
143 | protected delete({id, collection, collectionName, headers}: ReqInfo): ResponseOptions;
|
144 | protected findById(collection: any[], id: number | string): any;
|
145 | protected genId(collection: any): any;
|
146 | protected get({id, query, collection, collectionName, headers}: ReqInfo): ResponseOptions;
|
147 | protected getLocation(href: string): HTMLAnchorElement;
|
148 | protected indexOf(collection: any[], id: number): number;
|
149 | protected parseId(collection: {
|
150 | id: any;
|
151 | }[], id: string): any;
|
152 | protected parseUrl(url: string): {
|
153 | base: string;
|
154 | id: string;
|
155 | collectionName: string;
|
156 | resourceUrl: string;
|
157 | query: URLSearchParams;
|
158 | };
|
159 | protected post({collection, headers, id, req, resourceUrl}: ReqInfo): ResponseOptions;
|
160 | protected put({id, collection, collectionName, headers, req}: ReqInfo): ResponseOptions;
|
161 | protected removeById(collection: any[], id: number): boolean;
|
162 | |
163 |
|
164 |
|
165 | protected resetDb(): void;
|
166 | protected setStatusText(options: ResponseOptions): ResponseOptions;
|
167 | }
|