1 |
|
2 |
|
3 | import { EventEmitter } from 'events';
|
4 | import * as http from 'http';
|
5 |
|
6 | declare const createApplication: Feathers;
|
7 | export = createApplication;
|
8 |
|
9 | interface Feathers {
|
10 | <T = any>(): createApplication.Application<T>;
|
11 | readonly ACTIVATE_HOOKS: unique symbol;
|
12 | version: string;
|
13 | default: Feathers;
|
14 |
|
15 |
|
16 | }
|
17 |
|
18 | declare namespace createApplication {
|
19 | type Id = number | string;
|
20 | type NullableId = Id | null;
|
21 |
|
22 | interface Query {
|
23 | [key: string]: any;
|
24 | }
|
25 |
|
26 | interface PaginationOptions {
|
27 | default: number;
|
28 | max: number;
|
29 | }
|
30 |
|
31 | type ClientSideParams = Pick<Params, 'query' | 'paginate'>;
|
32 | type ServerSideParams = Params;
|
33 |
|
34 | interface Params {
|
35 | query?: Query;
|
36 | paginate?: false | Pick<PaginationOptions, 'max'>;
|
37 | provider?: string;
|
38 | route?: {[key: string]: string};
|
39 | headers?: {[key: string]: any};
|
40 |
|
41 | [key: string]: any;
|
42 | }
|
43 |
|
44 | interface Paginated<T> {
|
45 | total: number;
|
46 | limit: number;
|
47 | skip: number;
|
48 | data: T[];
|
49 | }
|
50 |
|
51 |
|
52 | type Hook<T = any, S = Service<T>> = (hook: HookContext<T, S>) => (Promise<HookContext<T, S> | void> | HookContext<T, S> | void);
|
53 |
|
54 | interface HookContext<T = any, S = Service<T>> {
|
55 | |
56 |
|
57 |
|
58 |
|
59 | readonly app: Application;
|
60 | |
61 |
|
62 |
|
63 |
|
64 | data?: T;
|
65 | |
66 |
|
67 |
|
68 |
|
69 | error?: any;
|
70 | |
71 |
|
72 |
|
73 |
|
74 |
|
75 | id?: string | number;
|
76 | |
77 |
|
78 |
|
79 |
|
80 | readonly method: string;
|
81 | |
82 |
|
83 |
|
84 |
|
85 | params: Params;
|
86 | |
87 |
|
88 |
|
89 |
|
90 | readonly path: string;
|
91 | |
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 | result?: T;
|
101 | |
102 |
|
103 |
|
104 | readonly service: S;
|
105 | |
106 |
|
107 |
|
108 |
|
109 |
|
110 | dispatch?: T;
|
111 | |
112 |
|
113 |
|
114 |
|
115 | statusCode?: number;
|
116 | |
117 |
|
118 |
|
119 | readonly type: 'before' | 'after' | 'error';
|
120 | }
|
121 |
|
122 | interface HookMap {
|
123 | all: Hook | Hook[];
|
124 | find: Hook | Hook[];
|
125 | get: Hook | Hook[];
|
126 | create: Hook | Hook[];
|
127 | update: Hook | Hook[];
|
128 | patch: Hook | Hook[];
|
129 | remove: Hook | Hook[];
|
130 | }
|
131 |
|
132 | interface HooksObject {
|
133 | before: Partial<HookMap> | Hook | Hook[];
|
134 | after: Partial<HookMap> | Hook | Hook[];
|
135 | error: Partial<HookMap> | Hook | Hook[];
|
136 | finally?: Partial<HookMap> | Hook | Hook[];
|
137 | }
|
138 |
|
139 | interface ServiceMethods<T> {
|
140 | [key: string]: any;
|
141 |
|
142 | find (params?: Params): Promise<T | T[] | Paginated<T>>;
|
143 |
|
144 | get (id: Id, params?: Params): Promise<T>;
|
145 |
|
146 | create (data: Partial<T> | Array<Partial<T>>, params?: Params): Promise<T | T[]>;
|
147 |
|
148 | update (id: NullableId, data: T, params?: Params): Promise<T | T[]>;
|
149 |
|
150 | patch (id: NullableId, data: Partial<T>, params?: Params): Promise<T | T[]>;
|
151 |
|
152 | remove (id: NullableId, params?: Params): Promise<T | T[]>;
|
153 | }
|
154 |
|
155 | interface SetupMethod {
|
156 | setup (app: Application, path: string): void;
|
157 | }
|
158 |
|
159 | interface ServiceOverloads<T> {
|
160 | create? (data: Partial<T>, params?: Params): Promise<T>;
|
161 |
|
162 | create? (data: Array<Partial<T>>, params?: Params): Promise<T[]>;
|
163 |
|
164 | update? (id: Id, data: T, params?: Params): Promise<T>;
|
165 |
|
166 | update? (id: null, data: T, params?: Params): Promise<T[]>;
|
167 |
|
168 | patch? (id: Id, data: Partial<T>, params?: Params): Promise<T>;
|
169 |
|
170 | patch? (id: null, data: Partial<T>, params?: Params): Promise<T[]>;
|
171 |
|
172 | remove? (id: Id, params?: Params): Promise<T>;
|
173 |
|
174 | remove? (id: null, params?: Params): Promise<T[]>;
|
175 | }
|
176 |
|
177 | interface ServiceAddons<T> extends EventEmitter {
|
178 | id?: any;
|
179 | _serviceEvents: string[];
|
180 | methods: {[method: string]: string[]};
|
181 | hooks (hooks: Partial<HooksObject>): this;
|
182 | }
|
183 |
|
184 | type Service<T> = ServiceOverloads<T> & ServiceAddons<T> & ServiceMethods<T>;
|
185 |
|
186 | type ServiceMixin = (service: Service<any>, path: string) => void;
|
187 |
|
188 | interface Application<ServiceTypes = {}> extends EventEmitter {
|
189 | version: string;
|
190 |
|
191 | services: keyof ServiceTypes extends never ? any : ServiceTypes;
|
192 |
|
193 | mixins: ServiceMixin[];
|
194 |
|
195 | methods: string[];
|
196 |
|
197 | get (name: string): any;
|
198 |
|
199 | set (name: string, value: any): this;
|
200 |
|
201 | disable (name: string): this;
|
202 |
|
203 | disabled (name: string): boolean;
|
204 |
|
205 | enable (name: string): this;
|
206 |
|
207 | enabled (name: string): boolean;
|
208 |
|
209 | configure (callback: (this: this, app: this) => void): this;
|
210 |
|
211 | hooks (hooks: Partial<HooksObject>): this;
|
212 |
|
213 | setup (server?: any): this;
|
214 |
|
215 | service<L extends keyof ServiceTypes> (location: L): ServiceTypes[L];
|
216 |
|
217 | service (location: string): keyof ServiceTypes extends never ? any : never;
|
218 |
|
219 | use (path: string, service: Partial<ServiceMethods<any> & SetupMethod> | Application, options?: any): this;
|
220 |
|
221 | listen (port: number): http.Server;
|
222 | }
|
223 | }
|