@feathersjs/feathers 5.0.0-pre.9 → 5.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +262 -231
- package/LICENSE +1 -1
- package/{readme.md → README.md} +7 -8
- package/lib/application.d.ts +20 -15
- package/lib/application.js +83 -44
- package/lib/application.js.map +1 -1
- package/lib/declarations.d.ts +206 -82
- package/lib/events.d.ts +2 -2
- package/lib/events.js +5 -6
- package/lib/events.js.map +1 -1
- package/lib/hooks.d.ts +42 -0
- package/lib/hooks.js +176 -0
- package/lib/hooks.js.map +1 -0
- package/lib/index.d.ts +2 -2
- package/lib/index.js +8 -4
- package/lib/index.js.map +1 -1
- package/lib/service.d.ts +3 -1
- package/lib/service.js +27 -26
- package/lib/service.js.map +1 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/lib/version.js.map +1 -1
- package/package.json +17 -16
- package/src/application.ts +162 -101
- package/src/declarations.ts +287 -146
- package/src/events.ts +15 -15
- package/src/hooks.ts +234 -0
- package/src/index.ts +13 -12
- package/src/service.ts +38 -50
- package/src/version.ts +1 -1
- package/lib/dependencies.d.ts +0 -4
- package/lib/dependencies.js +0 -18
- package/lib/dependencies.js.map +0 -1
- package/lib/hooks/index.d.ts +0 -14
- package/lib/hooks/index.js +0 -84
- package/lib/hooks/index.js.map +0 -1
- package/lib/hooks/legacy.d.ts +0 -7
- package/lib/hooks/legacy.js +0 -114
- package/lib/hooks/legacy.js.map +0 -1
- package/src/dependencies.ts +0 -5
- package/src/hooks/index.ts +0 -109
- package/src/hooks/legacy.ts +0 -138
package/lib/declarations.d.ts
CHANGED
|
@@ -1,59 +1,131 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { EventEmitter
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import { EventEmitter } from 'events';
|
|
3
|
+
import { NextFunction, HookContext as BaseHookContext } from '@feathersjs/hooks';
|
|
4
|
+
type SelfOrArray<S> = S | S[];
|
|
5
|
+
type OptionalPick<T, K extends PropertyKey> = Pick<T, Extract<keyof T, K>>;
|
|
5
6
|
export type { NextFunction };
|
|
7
|
+
/**
|
|
8
|
+
* The object returned from `.find` call by standard database adapters
|
|
9
|
+
*/
|
|
6
10
|
export interface Paginated<T> {
|
|
7
11
|
total: number;
|
|
8
12
|
limit: number;
|
|
9
13
|
skip: number;
|
|
10
14
|
data: T[];
|
|
11
15
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export
|
|
37
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Options that can be passed when registering a service via `app.use(name, service, options)`
|
|
18
|
+
*/
|
|
19
|
+
export interface ServiceOptions<MethodTypes = string> {
|
|
20
|
+
/**
|
|
21
|
+
* A list of custom events that this service emits to clients
|
|
22
|
+
*/
|
|
23
|
+
events?: string[] | readonly string[];
|
|
24
|
+
/**
|
|
25
|
+
* A list of service methods that should be available __externally__ to clients
|
|
26
|
+
*/
|
|
27
|
+
methods?: MethodTypes[] | readonly MethodTypes[];
|
|
28
|
+
/**
|
|
29
|
+
* Provide a full list of events that this service should emit to clients.
|
|
30
|
+
* Unlike the `events` option, this will not be merged with the default events.
|
|
31
|
+
*/
|
|
32
|
+
serviceEvents?: string[] | readonly string[];
|
|
33
|
+
/**
|
|
34
|
+
* Initial data to always add as route params to this service.
|
|
35
|
+
*/
|
|
36
|
+
routeParams?: {
|
|
37
|
+
[key: string]: any;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export interface ClientService<Result = any, Data = Partial<Result>, PatchData = Data, FindResult = Paginated<Result>, P = Params> {
|
|
41
|
+
find(params?: P): Promise<FindResult>;
|
|
42
|
+
get(id: Id, params?: P): Promise<Result>;
|
|
43
|
+
create(data: Data[], params?: P): Promise<Result[]>;
|
|
44
|
+
create(data: Data, params?: P): Promise<Result>;
|
|
45
|
+
update(id: Id, data: Data, params?: P): Promise<Result>;
|
|
46
|
+
update(id: NullableId, data: Data, params?: P): Promise<Result | Result[]>;
|
|
47
|
+
update(id: null, data: Data, params?: P): Promise<Result[]>;
|
|
48
|
+
patch(id: NullableId, data: PatchData, params?: P): Promise<Result | Result[]>;
|
|
49
|
+
patch(id: Id, data: PatchData, params?: P): Promise<Result>;
|
|
50
|
+
patch(id: null, data: PatchData, params?: P): Promise<Result[]>;
|
|
51
|
+
remove(id: NullableId, params?: P): Promise<Result | Result[]>;
|
|
52
|
+
remove(id: Id, params?: P): Promise<Result>;
|
|
53
|
+
remove(id: null, params?: P): Promise<Result[]>;
|
|
54
|
+
}
|
|
55
|
+
export interface ServiceMethods<Result = any, Data = Partial<Result>, ServiceParams = Params, PatchData = Partial<Data>> {
|
|
56
|
+
find(params?: ServiceParams & {
|
|
57
|
+
paginate?: PaginationParams;
|
|
58
|
+
}): Promise<Result | Result[]>;
|
|
59
|
+
get(id: Id, params?: ServiceParams): Promise<Result>;
|
|
60
|
+
create(data: Data, params?: ServiceParams): Promise<Result>;
|
|
61
|
+
update(id: NullableId, data: Data, params?: ServiceParams): Promise<Result | Result[]>;
|
|
62
|
+
patch(id: NullableId, data: PatchData, params?: ServiceParams): Promise<Result | Result[]>;
|
|
63
|
+
remove(id: NullableId, params?: ServiceParams): Promise<Result | Result[]>;
|
|
64
|
+
setup?(app: Application, path: string): Promise<void>;
|
|
65
|
+
teardown?(app: Application, path: string): Promise<void>;
|
|
66
|
+
}
|
|
67
|
+
export interface ServiceOverloads<Result = any, Data = Partial<Result>, ServiceParams = Params, PatchData = Partial<Data>> {
|
|
68
|
+
create?(data: Data[], params?: ServiceParams): Promise<Result[]>;
|
|
69
|
+
update?(id: Id, data: Data, params?: ServiceParams): Promise<Result>;
|
|
70
|
+
update?(id: null, data: Data, params?: ServiceParams): Promise<Result[]>;
|
|
71
|
+
patch?(id: Id, data: PatchData, params?: ServiceParams): Promise<Result>;
|
|
72
|
+
patch?(id: null, data: PatchData, params?: ServiceParams): Promise<Result[]>;
|
|
73
|
+
remove?(id: Id, params?: ServiceParams): Promise<Result>;
|
|
74
|
+
remove?(id: null, params?: ServiceParams): Promise<Result[]>;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* A complete service interface. The `ServiceInterface` type should be preferred for customs service
|
|
78
|
+
* implementations
|
|
79
|
+
*/
|
|
80
|
+
export type Service<Result = any, Data = Partial<Result>, ServiceParams = Params, PatchData = Partial<Data>> = ServiceMethods<Result, Data, ServiceParams> & ServiceOverloads<Result, Data, ServiceParams, PatchData>;
|
|
81
|
+
/**
|
|
82
|
+
* The `Service` service interface but with none of the methods required.
|
|
83
|
+
*/
|
|
84
|
+
export type ServiceInterface<Result = any, Data = Partial<Result>, ServiceParams = Params, PatchData = Partial<Data>> = Partial<ServiceMethods<Result, Data, ServiceParams, PatchData>>;
|
|
85
|
+
export interface ServiceAddons<A = Application, S = Service> extends EventEmitter {
|
|
38
86
|
id?: string;
|
|
39
87
|
hooks(options: HookOptions<A, S>): this;
|
|
40
88
|
}
|
|
41
|
-
export interface ServiceHookOverloads<S> {
|
|
42
|
-
find(params:
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
89
|
+
export interface ServiceHookOverloads<S, P = Params> {
|
|
90
|
+
find(params: P & {
|
|
91
|
+
paginate?: PaginationParams;
|
|
92
|
+
}, context: HookContext): Promise<HookContext>;
|
|
93
|
+
get(id: Id, params: P, context: HookContext): Promise<HookContext>;
|
|
94
|
+
create(data: ServiceGenericData<S> | ServiceGenericData<S>[], params: P, context: HookContext): Promise<HookContext>;
|
|
95
|
+
update(id: NullableId, data: ServiceGenericData<S>, params: P, context: HookContext): Promise<HookContext>;
|
|
96
|
+
patch(id: NullableId, data: ServiceGenericData<S>, params: P, context: HookContext): Promise<HookContext>;
|
|
97
|
+
remove(id: NullableId, params: P, context: HookContext): Promise<HookContext>;
|
|
98
|
+
}
|
|
99
|
+
export type FeathersService<A = FeathersApplication, S = Service> = S & ServiceAddons<A, S> & OptionalPick<ServiceHookOverloads<S>, keyof S>;
|
|
100
|
+
export type CustomMethods<T extends {
|
|
101
|
+
[key: string]: [any, any];
|
|
102
|
+
}> = {
|
|
103
|
+
[K in keyof T]: (data: T[K][0], params?: Params) => Promise<T[K][1]>;
|
|
52
104
|
};
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
105
|
+
/**
|
|
106
|
+
* An interface usually use by transport clients that represents a e.g. HTTP or websocket
|
|
107
|
+
* connection that can be configured on the application.
|
|
108
|
+
*/
|
|
109
|
+
export type TransportConnection<Services = any> = {
|
|
110
|
+
(app: Application<Services>): void;
|
|
111
|
+
Service: any;
|
|
112
|
+
service: <L extends keyof Services & string>(name: L) => keyof any extends keyof Services ? ServiceInterface : Services[L];
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* A real-time connection object
|
|
116
|
+
*/
|
|
117
|
+
export interface RealTimeConnection {
|
|
118
|
+
[key: string]: any;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* The interface for a custom service method. Can e.g. be used to type client side services.
|
|
122
|
+
*/
|
|
123
|
+
export type CustomMethod<T = any, R = T, P extends Params = Params> = (data: T, params?: P) => Promise<R>;
|
|
124
|
+
export type ServiceMixin<A> = (service: FeathersService<A>, path: string, options: ServiceOptions) => void;
|
|
125
|
+
export type ServiceGenericType<S> = S extends ServiceInterface<infer T> ? T : any;
|
|
126
|
+
export type ServiceGenericData<S> = S extends ServiceInterface<infer _T, infer D> ? D : any;
|
|
127
|
+
export type ServiceGenericParams<S> = S extends ServiceInterface<infer _T, infer _D, infer P> ? P : any;
|
|
128
|
+
export interface FeathersApplication<Services = any, Settings = any> {
|
|
57
129
|
/**
|
|
58
130
|
* The Feathers application version
|
|
59
131
|
*/
|
|
@@ -61,40 +133,36 @@ export interface FeathersApplication<ServiceTypes = any, AppSettings = any> {
|
|
|
61
133
|
/**
|
|
62
134
|
* A list of callbacks that run when a new service is registered
|
|
63
135
|
*/
|
|
64
|
-
mixins: ServiceMixin<Application<
|
|
136
|
+
mixins: ServiceMixin<Application<Services, Settings>>[];
|
|
65
137
|
/**
|
|
66
138
|
* The index of all services keyed by their path.
|
|
67
139
|
*
|
|
68
140
|
* __Important:__ Services should always be retrieved via `app.service('name')`
|
|
69
141
|
* not via `app.services`.
|
|
70
142
|
*/
|
|
71
|
-
services:
|
|
143
|
+
services: Services;
|
|
72
144
|
/**
|
|
73
145
|
* The application settings that can be used via
|
|
74
146
|
* `app.get` and `app.set`
|
|
75
147
|
*/
|
|
76
|
-
settings:
|
|
148
|
+
settings: Settings;
|
|
77
149
|
/**
|
|
78
150
|
* A private-ish indicator if `app.setup()` has been called already
|
|
79
151
|
*/
|
|
80
152
|
_isSetup: boolean;
|
|
81
|
-
/**
|
|
82
|
-
* Contains all registered application level hooks.
|
|
83
|
-
*/
|
|
84
|
-
appHooks: HookMap<Application<ServiceTypes, AppSettings>, any>;
|
|
85
153
|
/**
|
|
86
154
|
* Retrieve an application setting by name
|
|
87
155
|
*
|
|
88
156
|
* @param name The setting name
|
|
89
157
|
*/
|
|
90
|
-
get<L extends keyof
|
|
158
|
+
get<L extends keyof Settings & string>(name: L): Settings[L];
|
|
91
159
|
/**
|
|
92
160
|
* Set an application setting
|
|
93
161
|
*
|
|
94
162
|
* @param name The setting name
|
|
95
163
|
* @param value The setting value
|
|
96
164
|
*/
|
|
97
|
-
set<L extends keyof
|
|
165
|
+
set<L extends keyof Settings & string>(name: L, value: Settings[L]): this;
|
|
98
166
|
/**
|
|
99
167
|
* Runs a callback configure function with the current application instance.
|
|
100
168
|
*
|
|
@@ -108,7 +176,7 @@ export interface FeathersApplication<ServiceTypes = any, AppSettings = any> {
|
|
|
108
176
|
*
|
|
109
177
|
* @param location The path of the service
|
|
110
178
|
*/
|
|
111
|
-
defaultService(location: string): ServiceInterface
|
|
179
|
+
defaultService(location: string): ServiceInterface;
|
|
112
180
|
/**
|
|
113
181
|
* Register a new service or a sub-app. When passed another
|
|
114
182
|
* Feathers application, all its services will be re-registered
|
|
@@ -119,7 +187,13 @@ export interface FeathersApplication<ServiceTypes = any, AppSettings = any> {
|
|
|
119
187
|
* Feathers application to use a sub-app under the `path` prefix.
|
|
120
188
|
* @param options The options for this service
|
|
121
189
|
*/
|
|
122
|
-
use<L extends keyof
|
|
190
|
+
use<L extends keyof Services & string>(path: L, service: keyof any extends keyof Services ? ServiceInterface | Application : Services[L], options?: ServiceOptions<keyof any extends keyof Services ? string : keyof Services[L]>): this;
|
|
191
|
+
/**
|
|
192
|
+
* Unregister an existing service.
|
|
193
|
+
*
|
|
194
|
+
* @param path The name of the service to unregister
|
|
195
|
+
*/
|
|
196
|
+
unuse<L extends keyof Services & string>(path: L): Promise<FeathersService<this, keyof any extends keyof Services ? Service : Services[L]>>;
|
|
123
197
|
/**
|
|
124
198
|
* Get the Feathers service instance for a path. This will
|
|
125
199
|
* be the service originally registered with Feathers functionality
|
|
@@ -127,33 +201,65 @@ export interface FeathersApplication<ServiceTypes = any, AppSettings = any> {
|
|
|
127
201
|
*
|
|
128
202
|
* @param path The name of the service.
|
|
129
203
|
*/
|
|
130
|
-
service<L extends keyof
|
|
204
|
+
service<L extends keyof Services & string>(path: L): FeathersService<this, keyof any extends keyof Services ? Service : Services[L]>;
|
|
205
|
+
/**
|
|
206
|
+
* Set up the application and call all services `.setup` method if available.
|
|
207
|
+
*
|
|
208
|
+
* @param server A server instance (optional)
|
|
209
|
+
*/
|
|
131
210
|
setup(server?: any): Promise<this>;
|
|
211
|
+
/**
|
|
212
|
+
* Tear down the application and call all services `.teardown` method if available.
|
|
213
|
+
*
|
|
214
|
+
* @param server A server instance (optional)
|
|
215
|
+
*/
|
|
216
|
+
teardown(server?: any): Promise<this>;
|
|
132
217
|
/**
|
|
133
218
|
* Register application level hooks.
|
|
134
219
|
*
|
|
135
220
|
* @param map The application hook settings.
|
|
136
221
|
*/
|
|
137
|
-
hooks(map:
|
|
222
|
+
hooks(map: ApplicationHookOptions<this>): this;
|
|
138
223
|
}
|
|
139
|
-
export interface Application<
|
|
224
|
+
export interface Application<Services = any, Settings = any> extends FeathersApplication<Services, Settings>, EventEmitter {
|
|
140
225
|
}
|
|
141
|
-
export
|
|
142
|
-
export
|
|
226
|
+
export type Id = number | string;
|
|
227
|
+
export type NullableId = Id | null;
|
|
143
228
|
export interface Query {
|
|
144
229
|
[key: string]: any;
|
|
145
230
|
}
|
|
146
|
-
export interface Params {
|
|
147
|
-
query?:
|
|
231
|
+
export interface Params<Q = Query> {
|
|
232
|
+
query?: Q;
|
|
148
233
|
provider?: string;
|
|
149
234
|
route?: {
|
|
150
|
-
[key: string]:
|
|
235
|
+
[key: string]: any;
|
|
151
236
|
};
|
|
152
237
|
headers?: {
|
|
153
238
|
[key: string]: any;
|
|
154
239
|
};
|
|
155
|
-
[key: string]: any;
|
|
156
240
|
}
|
|
241
|
+
export interface PaginationOptions {
|
|
242
|
+
default?: number;
|
|
243
|
+
max?: number;
|
|
244
|
+
}
|
|
245
|
+
export type PaginationParams = false | PaginationOptions;
|
|
246
|
+
export interface Http {
|
|
247
|
+
/**
|
|
248
|
+
* A writeable, optional property with status code override.
|
|
249
|
+
*/
|
|
250
|
+
status?: number;
|
|
251
|
+
/**
|
|
252
|
+
* A writeable, optional property with headers.
|
|
253
|
+
*/
|
|
254
|
+
headers?: {
|
|
255
|
+
[key: string]: string | string[];
|
|
256
|
+
};
|
|
257
|
+
/**
|
|
258
|
+
* A writeable, optional property with `Location` header's value.
|
|
259
|
+
*/
|
|
260
|
+
location?: string;
|
|
261
|
+
}
|
|
262
|
+
export type HookType = 'before' | 'after' | 'error' | 'around';
|
|
157
263
|
export interface HookContext<A = Application, S = any> extends BaseHookContext<ServiceGenericType<S>> {
|
|
158
264
|
/**
|
|
159
265
|
* A read only property that contains the Feathers application object. This can be used to
|
|
@@ -175,10 +281,9 @@ export interface HookContext<A = Application, S = any> extends BaseHookContext<S
|
|
|
175
281
|
*/
|
|
176
282
|
readonly service: S;
|
|
177
283
|
/**
|
|
178
|
-
* A read only property with the hook type (one of before, after or error).
|
|
179
|
-
* Will be `null` for asynchronous hooks.
|
|
284
|
+
* A read only property with the hook type (one of 'around', 'before', 'after' or 'error').
|
|
180
285
|
*/
|
|
181
|
-
readonly type:
|
|
286
|
+
readonly type: HookType;
|
|
182
287
|
/**
|
|
183
288
|
* The list of method arguments. Should not be modified, modify the
|
|
184
289
|
* `params`, `data` and `id` properties instead.
|
|
@@ -204,7 +309,7 @@ export interface HookContext<A = Application, S = any> extends BaseHookContext<S
|
|
|
204
309
|
* A writeable property that contains the service method parameters (including
|
|
205
310
|
* params.query).
|
|
206
311
|
*/
|
|
207
|
-
params:
|
|
312
|
+
params: ServiceGenericParams<S>;
|
|
208
313
|
/**
|
|
209
314
|
* A writeable property containing the result of the successful service method call.
|
|
210
315
|
* It is only available in after hooks.
|
|
@@ -224,28 +329,47 @@ export interface HookContext<A = Application, S = any> extends BaseHookContext<S
|
|
|
224
329
|
/**
|
|
225
330
|
* A writeable, optional property that allows to override the standard HTTP status
|
|
226
331
|
* code that should be returned.
|
|
332
|
+
*
|
|
333
|
+
* @deprecated Use `http.status` instead.
|
|
227
334
|
*/
|
|
228
335
|
statusCode?: number;
|
|
336
|
+
/**
|
|
337
|
+
* A writeable, optional property with options specific to HTTP transports.
|
|
338
|
+
*/
|
|
339
|
+
http?: Http;
|
|
229
340
|
/**
|
|
230
341
|
* The event emitted by this method. Can be set to `null` to skip event emitting.
|
|
231
342
|
*/
|
|
232
343
|
event: string | null;
|
|
233
344
|
}
|
|
234
|
-
export
|
|
235
|
-
export
|
|
236
|
-
|
|
237
|
-
[L in keyof S]?: SelfOrArray<
|
|
345
|
+
export type HookFunction<A = Application, S = Service> = (this: S, context: HookContext<A, S>) => Promise<HookContext<Application, S> | void> | HookContext<Application, S> | void;
|
|
346
|
+
export type Hook<A = Application, S = Service> = HookFunction<A, S>;
|
|
347
|
+
type HookMethodMap<A, S> = {
|
|
348
|
+
[L in keyof S]?: SelfOrArray<HookFunction<A, S>>;
|
|
238
349
|
} & {
|
|
239
|
-
all?: SelfOrArray<
|
|
350
|
+
all?: SelfOrArray<HookFunction<A, S>>;
|
|
240
351
|
};
|
|
241
|
-
|
|
242
|
-
export
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
352
|
+
type HookTypeMap<A, S> = SelfOrArray<HookFunction<A, S>> | HookMethodMap<A, S>;
|
|
353
|
+
export type AroundHookFunction<A = Application, S = Service> = (context: HookContext<A, S>, next: NextFunction) => Promise<void>;
|
|
354
|
+
export type AroundHookMap<A, S> = {
|
|
355
|
+
[L in keyof S]?: AroundHookFunction<A, S>[];
|
|
356
|
+
} & {
|
|
357
|
+
all?: AroundHookFunction<A, S>[];
|
|
246
358
|
};
|
|
247
|
-
export
|
|
248
|
-
|
|
249
|
-
|
|
359
|
+
export type HookMap<A, S> = {
|
|
360
|
+
around?: AroundHookMap<A, S>;
|
|
361
|
+
before?: HookTypeMap<A, S>;
|
|
362
|
+
after?: HookTypeMap<A, S>;
|
|
363
|
+
error?: HookTypeMap<A, S>;
|
|
364
|
+
};
|
|
365
|
+
export type HookOptions<A, S> = AroundHookMap<A, S> | AroundHookFunction<A, S>[] | HookMap<A, S>;
|
|
366
|
+
export interface ApplicationHookContext<A = Application> extends BaseHookContext {
|
|
367
|
+
app: A;
|
|
368
|
+
server: any;
|
|
369
|
+
}
|
|
370
|
+
export type ApplicationHookFunction<A> = (context: ApplicationHookContext<A>, next: NextFunction) => Promise<void>;
|
|
371
|
+
export type ApplicationHookMap<A> = {
|
|
372
|
+
setup?: ApplicationHookFunction<A>[];
|
|
373
|
+
teardown?: ApplicationHookFunction<A>[];
|
|
250
374
|
};
|
|
251
|
-
export
|
|
375
|
+
export type ApplicationHookOptions<A> = HookOptions<A, any> | ApplicationHookMap<A>;
|
package/lib/events.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NextFunction } from '
|
|
1
|
+
import { NextFunction } from '@feathersjs/hooks';
|
|
2
2
|
import { HookContext, FeathersService } from './declarations';
|
|
3
3
|
export declare function eventHook(context: HookContext, next: NextFunction): Promise<void>;
|
|
4
|
-
export declare function eventMixin<A>(service: FeathersService<A>): FeathersService<A, import("./declarations").Service<any, Partial<any
|
|
4
|
+
export declare function eventMixin<A>(service: FeathersService<A>): FeathersService<A, import("./declarations").Service<any, Partial<any>, import("./declarations").Params<import("./declarations").Query>, Partial<Partial<any>>>>;
|
package/lib/events.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.eventMixin = exports.eventHook = void 0;
|
|
4
|
-
const
|
|
4
|
+
const events_1 = require("events");
|
|
5
5
|
const service_1 = require("./service");
|
|
6
6
|
function eventHook(context, next) {
|
|
7
|
-
const { events } = service_1.getServiceOptions(context.self);
|
|
7
|
+
const { events } = (0, service_1.getServiceOptions)(context.self);
|
|
8
8
|
const defaultEvent = service_1.defaultEventMap[context.method] || null;
|
|
9
9
|
context.event = defaultEvent;
|
|
10
10
|
return next().then(() => {
|
|
@@ -12,16 +12,15 @@ function eventHook(context, next) {
|
|
|
12
12
|
// This is used for custom events and for client services receiving event from the server
|
|
13
13
|
if (typeof context.event === 'string' && !events.includes(context.event)) {
|
|
14
14
|
const results = Array.isArray(context.result) ? context.result : [context.result];
|
|
15
|
-
results.forEach(element => context.self.emit(context.event, element, context));
|
|
15
|
+
results.forEach((element) => context.self.emit(context.event, element, context));
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
19
|
exports.eventHook = eventHook;
|
|
20
20
|
function eventMixin(service) {
|
|
21
|
-
const isEmitter = typeof service.on === 'function' &&
|
|
22
|
-
typeof service.emit === 'function';
|
|
21
|
+
const isEmitter = typeof service.on === 'function' && typeof service.emit === 'function';
|
|
23
22
|
if (!isEmitter) {
|
|
24
|
-
Object.assign(service,
|
|
23
|
+
Object.assign(service, events_1.EventEmitter.prototype);
|
|
25
24
|
}
|
|
26
25
|
return service;
|
|
27
26
|
}
|
package/lib/events.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.js","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":";;;AAAA,mCAAqC;AAGrC,uCAA8D;AAE9D,SAAgB,SAAS,CAAC,OAAoB,EAAE,IAAkB;IAChE,MAAM,EAAE,MAAM,EAAE,GAAG,IAAA,2BAAiB,EAAE,OAAe,CAAC,IAAI,CAAC,CAAA;IAC3D,MAAM,YAAY,GAAI,yBAAuB,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,IAAI,CAAA;IAErE,OAAO,CAAC,KAAK,GAAG,YAAY,CAAA;IAE5B,OAAO,IAAI,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE;QACtB,+FAA+F;QAC/F,yFAAyF;QACzF,IAAI,OAAO,OAAO,CAAC,KAAK,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;YACxE,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;YAEjF,OAAO,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAE,OAAe,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAA;SAC1F;IACH,CAAC,CAAC,CAAA;AACJ,CAAC;AAfD,8BAeC;AAED,SAAgB,UAAU,CAAI,OAA2B;IACvD,MAAM,SAAS,GAAG,OAAO,OAAO,CAAC,EAAE,KAAK,UAAU,IAAI,OAAO,OAAO,CAAC,IAAI,KAAK,UAAU,CAAA;IAExF,IAAI,CAAC,SAAS,EAAE;QACd,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,qBAAY,CAAC,SAAS,CAAC,CAAA;KAC/C;IAED,OAAO,OAAO,CAAA;AAChB,CAAC;AARD,gCAQC"}
|
package/lib/hooks.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { HookContextData, HookManager, Middleware } from '@feathersjs/hooks';
|
|
2
|
+
import { Service, ServiceOptions, HookContext, FeathersService, HookMap, AroundHookFunction, HookFunction } from './declarations';
|
|
3
|
+
type HookStore = {
|
|
4
|
+
around: {
|
|
5
|
+
[method: string]: AroundHookFunction[];
|
|
6
|
+
};
|
|
7
|
+
before: {
|
|
8
|
+
[method: string]: HookFunction[];
|
|
9
|
+
};
|
|
10
|
+
after: {
|
|
11
|
+
[method: string]: HookFunction[];
|
|
12
|
+
};
|
|
13
|
+
error: {
|
|
14
|
+
[method: string]: HookFunction[];
|
|
15
|
+
};
|
|
16
|
+
collected: {
|
|
17
|
+
[method: string]: AroundHookFunction[];
|
|
18
|
+
};
|
|
19
|
+
collectedAll: {
|
|
20
|
+
before?: AroundHookFunction[];
|
|
21
|
+
after?: AroundHookFunction[];
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
type HookEnabled = {
|
|
25
|
+
__hooks: HookStore;
|
|
26
|
+
};
|
|
27
|
+
export declare function convertHookData(input: any): {
|
|
28
|
+
[method: string]: AroundHookFunction<import("./declarations").Application<any, any>, Service<any, Partial<any>, import("./declarations").Params<import("./declarations").Query>, Partial<Partial<any>>>>[] | HookFunction<import("./declarations").Application<any, any>, Service<any, Partial<any>, import("./declarations").Params<import("./declarations").Query>, Partial<Partial<any>>>>[];
|
|
29
|
+
};
|
|
30
|
+
export declare function collectHooks(target: HookEnabled, method: string): AroundHookFunction<import("./declarations").Application<any, any>, Service<any, Partial<any>, import("./declarations").Params<import("./declarations").Query>, Partial<Partial<any>>>>[];
|
|
31
|
+
export declare function enableHooks(object: any): (this: HookEnabled, input: HookMap<any, any>) => HookEnabled;
|
|
32
|
+
export declare function createContext(service: Service, method: string, data?: HookContextData): HookContext<import("./declarations").Application<any, any>, any>;
|
|
33
|
+
export declare class FeathersHookManager<A> extends HookManager {
|
|
34
|
+
app: A;
|
|
35
|
+
method: string;
|
|
36
|
+
constructor(app: A, method: string);
|
|
37
|
+
collectMiddleware(self: any, args: any[]): Middleware[];
|
|
38
|
+
initializeContext(self: any, args: any[], context: HookContext): import("@feathersjs/hooks").HookContext<any, any>;
|
|
39
|
+
middleware(mw: Middleware[]): this;
|
|
40
|
+
}
|
|
41
|
+
export declare function hookMixin<A>(this: A, service: FeathersService<A>, path: string, options: ServiceOptions): FeathersService<A, Service<any, Partial<any>, import("./declarations").Params<import("./declarations").Query>, Partial<Partial<any>>>>;
|
|
42
|
+
export {};
|