@feathersjs/feathers 5.0.0-pre.6 → 5.0.0
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 +265 -212
- package/LICENSE +1 -1
- package/{readme.md → README.md} +7 -12
- 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 +193 -78
- 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 +281 -147
- 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,127 @@
|
|
|
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
|
+
* 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[]>;
|
|
16
54
|
}
|
|
17
|
-
export interface ServiceMethods<
|
|
18
|
-
find(params?:
|
|
19
|
-
get(id: Id, params?:
|
|
20
|
-
create(data:
|
|
21
|
-
update(id: NullableId, data:
|
|
22
|
-
patch(id: NullableId, data:
|
|
23
|
-
remove(id: NullableId, params?:
|
|
24
|
-
setup(app: Application, path: string): Promise<void>;
|
|
55
|
+
export interface ServiceMethods<Result = any, Data = Partial<Result>, ServiceParams = Params, PatchData = Partial<Data>> {
|
|
56
|
+
find(params?: ServiceParams): Promise<Result | Result[]>;
|
|
57
|
+
get(id: Id, params?: ServiceParams): Promise<Result>;
|
|
58
|
+
create(data: Data, params?: ServiceParams): Promise<Result>;
|
|
59
|
+
update(id: NullableId, data: Data, params?: ServiceParams): Promise<Result | Result[]>;
|
|
60
|
+
patch(id: NullableId, data: PatchData, params?: ServiceParams): Promise<Result | Result[]>;
|
|
61
|
+
remove(id: NullableId, params?: ServiceParams): Promise<Result | Result[]>;
|
|
62
|
+
setup?(app: Application, path: string): Promise<void>;
|
|
63
|
+
teardown?(app: Application, path: string): Promise<void>;
|
|
25
64
|
}
|
|
26
|
-
export interface ServiceOverloads<
|
|
27
|
-
create?(data:
|
|
28
|
-
update?(id: Id, data:
|
|
29
|
-
update?(id: null, data:
|
|
30
|
-
patch?(id: Id, data:
|
|
31
|
-
patch?(id: null, data:
|
|
32
|
-
remove?(id: Id, params?:
|
|
33
|
-
remove?(id: null, params?:
|
|
65
|
+
export interface ServiceOverloads<Result = any, Data = Partial<Result>, ServiceParams = Params, PatchData = Partial<Data>> {
|
|
66
|
+
create?(data: Data[], params?: ServiceParams): Promise<Result[]>;
|
|
67
|
+
update?(id: Id, data: Data, params?: ServiceParams): Promise<Result>;
|
|
68
|
+
update?(id: null, data: Data, params?: ServiceParams): Promise<Result[]>;
|
|
69
|
+
patch?(id: Id, data: PatchData, params?: ServiceParams): Promise<Result>;
|
|
70
|
+
patch?(id: null, data: PatchData, params?: ServiceParams): Promise<Result[]>;
|
|
71
|
+
remove?(id: Id, params?: ServiceParams): Promise<Result>;
|
|
72
|
+
remove?(id: null, params?: ServiceParams): Promise<Result[]>;
|
|
34
73
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
74
|
+
/**
|
|
75
|
+
* A complete service interface. The `ServiceInterface` type should be preferred for customs service
|
|
76
|
+
* implementations
|
|
77
|
+
*/
|
|
78
|
+
export type Service<Result = any, Data = Partial<Result>, ServiceParams = Params, PatchData = Partial<Data>> = ServiceMethods<Result, Data, ServiceParams> & ServiceOverloads<Result, Data, ServiceParams, PatchData>;
|
|
79
|
+
/**
|
|
80
|
+
* The `Service` service interface but with none of the methods required.
|
|
81
|
+
*/
|
|
82
|
+
export type ServiceInterface<Result = any, Data = Partial<Result>, ServiceParams = Params, PatchData = Partial<Data>> = Partial<ServiceMethods<Result, Data, ServiceParams, PatchData>>;
|
|
83
|
+
export interface ServiceAddons<A = Application, S = Service> extends EventEmitter {
|
|
38
84
|
id?: string;
|
|
39
85
|
hooks(options: HookOptions<A, S>): this;
|
|
40
86
|
}
|
|
41
|
-
export interface ServiceHookOverloads<S> {
|
|
42
|
-
find(params:
|
|
43
|
-
get(id: Id, params:
|
|
44
|
-
create(data: ServiceGenericData<S> | ServiceGenericData<S>[], params:
|
|
45
|
-
update(id: NullableId, data: ServiceGenericData<S>, params:
|
|
46
|
-
patch(id: NullableId, data: ServiceGenericData<S>, params:
|
|
47
|
-
remove(id: NullableId, params:
|
|
87
|
+
export interface ServiceHookOverloads<S, P = Params> {
|
|
88
|
+
find(params: P, context: HookContext): Promise<HookContext>;
|
|
89
|
+
get(id: Id, params: P, context: HookContext): Promise<HookContext>;
|
|
90
|
+
create(data: ServiceGenericData<S> | ServiceGenericData<S>[], params: P, context: HookContext): Promise<HookContext>;
|
|
91
|
+
update(id: NullableId, data: ServiceGenericData<S>, params: P, context: HookContext): Promise<HookContext>;
|
|
92
|
+
patch(id: NullableId, data: ServiceGenericData<S>, params: P, context: HookContext): Promise<HookContext>;
|
|
93
|
+
remove(id: NullableId, params: P, context: HookContext): Promise<HookContext>;
|
|
48
94
|
}
|
|
49
|
-
export
|
|
50
|
-
export
|
|
51
|
-
[
|
|
95
|
+
export type FeathersService<A = FeathersApplication, S = Service> = S & ServiceAddons<A, S> & OptionalPick<ServiceHookOverloads<S>, keyof S>;
|
|
96
|
+
export type CustomMethods<T extends {
|
|
97
|
+
[key: string]: [any, any];
|
|
98
|
+
}> = {
|
|
99
|
+
[K in keyof T]: (data: T[K][0], params?: Params) => Promise<T[K][1]>;
|
|
52
100
|
};
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
101
|
+
/**
|
|
102
|
+
* An interface usually use by transport clients that represents a e.g. HTTP or websocket
|
|
103
|
+
* connection that can be configured on the application.
|
|
104
|
+
*/
|
|
105
|
+
export type TransportConnection<Services = any> = {
|
|
106
|
+
(app: Application<Services>): void;
|
|
107
|
+
Service: any;
|
|
108
|
+
service: <L extends keyof Services & string>(name: L) => keyof any extends keyof Services ? ServiceInterface : Services[L];
|
|
109
|
+
};
|
|
110
|
+
/**
|
|
111
|
+
* A real-time connection object
|
|
112
|
+
*/
|
|
113
|
+
export interface RealTimeConnection {
|
|
114
|
+
[key: string]: any;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* The interface for a custom service method. Can e.g. be used to type client side services.
|
|
118
|
+
*/
|
|
119
|
+
export type CustomMethod<T = any, R = T, P extends Params = Params> = (data: T, params?: P) => Promise<R>;
|
|
120
|
+
export type ServiceMixin<A> = (service: FeathersService<A>, path: string, options: ServiceOptions) => void;
|
|
121
|
+
export type ServiceGenericType<S> = S extends ServiceInterface<infer T> ? T : any;
|
|
122
|
+
export type ServiceGenericData<S> = S extends ServiceInterface<infer _T, infer D> ? D : any;
|
|
123
|
+
export type ServiceGenericParams<S> = S extends ServiceInterface<infer _T, infer _D, infer P> ? P : any;
|
|
124
|
+
export interface FeathersApplication<Services = any, Settings = any> {
|
|
57
125
|
/**
|
|
58
126
|
* The Feathers application version
|
|
59
127
|
*/
|
|
@@ -61,40 +129,36 @@ export interface FeathersApplication<ServiceTypes = any, AppSettings = any> {
|
|
|
61
129
|
/**
|
|
62
130
|
* A list of callbacks that run when a new service is registered
|
|
63
131
|
*/
|
|
64
|
-
mixins: ServiceMixin<Application<
|
|
132
|
+
mixins: ServiceMixin<Application<Services, Settings>>[];
|
|
65
133
|
/**
|
|
66
134
|
* The index of all services keyed by their path.
|
|
67
135
|
*
|
|
68
136
|
* __Important:__ Services should always be retrieved via `app.service('name')`
|
|
69
137
|
* not via `app.services`.
|
|
70
138
|
*/
|
|
71
|
-
services:
|
|
139
|
+
services: Services;
|
|
72
140
|
/**
|
|
73
141
|
* The application settings that can be used via
|
|
74
142
|
* `app.get` and `app.set`
|
|
75
143
|
*/
|
|
76
|
-
settings:
|
|
144
|
+
settings: Settings;
|
|
77
145
|
/**
|
|
78
146
|
* A private-ish indicator if `app.setup()` has been called already
|
|
79
147
|
*/
|
|
80
148
|
_isSetup: boolean;
|
|
81
|
-
/**
|
|
82
|
-
* Contains all registered application level hooks.
|
|
83
|
-
*/
|
|
84
|
-
appHooks: HookMap<Application<ServiceTypes, AppSettings>, any>;
|
|
85
149
|
/**
|
|
86
150
|
* Retrieve an application setting by name
|
|
87
151
|
*
|
|
88
152
|
* @param name The setting name
|
|
89
153
|
*/
|
|
90
|
-
get<L extends keyof
|
|
154
|
+
get<L extends keyof Settings & string>(name: L): Settings[L];
|
|
91
155
|
/**
|
|
92
156
|
* Set an application setting
|
|
93
157
|
*
|
|
94
158
|
* @param name The setting name
|
|
95
159
|
* @param value The setting value
|
|
96
160
|
*/
|
|
97
|
-
set<L extends keyof
|
|
161
|
+
set<L extends keyof Settings & string>(name: L, value: Settings[L]): this;
|
|
98
162
|
/**
|
|
99
163
|
* Runs a callback configure function with the current application instance.
|
|
100
164
|
*
|
|
@@ -108,7 +172,7 @@ export interface FeathersApplication<ServiceTypes = any, AppSettings = any> {
|
|
|
108
172
|
*
|
|
109
173
|
* @param location The path of the service
|
|
110
174
|
*/
|
|
111
|
-
defaultService(location: string): ServiceInterface
|
|
175
|
+
defaultService(location: string): ServiceInterface;
|
|
112
176
|
/**
|
|
113
177
|
* Register a new service or a sub-app. When passed another
|
|
114
178
|
* Feathers application, all its services will be re-registered
|
|
@@ -119,7 +183,13 @@ export interface FeathersApplication<ServiceTypes = any, AppSettings = any> {
|
|
|
119
183
|
* Feathers application to use a sub-app under the `path` prefix.
|
|
120
184
|
* @param options The options for this service
|
|
121
185
|
*/
|
|
122
|
-
use<L extends keyof
|
|
186
|
+
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;
|
|
187
|
+
/**
|
|
188
|
+
* Unregister an existing service.
|
|
189
|
+
*
|
|
190
|
+
* @param path The name of the service to unregister
|
|
191
|
+
*/
|
|
192
|
+
unuse<L extends keyof Services & string>(path: L): Promise<FeathersService<this, keyof any extends keyof Services ? Service : Services[L]>>;
|
|
123
193
|
/**
|
|
124
194
|
* Get the Feathers service instance for a path. This will
|
|
125
195
|
* be the service originally registered with Feathers functionality
|
|
@@ -127,33 +197,60 @@ export interface FeathersApplication<ServiceTypes = any, AppSettings = any> {
|
|
|
127
197
|
*
|
|
128
198
|
* @param path The name of the service.
|
|
129
199
|
*/
|
|
130
|
-
service<L extends keyof
|
|
200
|
+
service<L extends keyof Services & string>(path: L): FeathersService<this, keyof any extends keyof Services ? Service : Services[L]>;
|
|
201
|
+
/**
|
|
202
|
+
* Set up the application and call all services `.setup` method if available.
|
|
203
|
+
*
|
|
204
|
+
* @param server A server instance (optional)
|
|
205
|
+
*/
|
|
131
206
|
setup(server?: any): Promise<this>;
|
|
207
|
+
/**
|
|
208
|
+
* Tear down the application and call all services `.teardown` method if available.
|
|
209
|
+
*
|
|
210
|
+
* @param server A server instance (optional)
|
|
211
|
+
*/
|
|
212
|
+
teardown(server?: any): Promise<this>;
|
|
132
213
|
/**
|
|
133
214
|
* Register application level hooks.
|
|
134
215
|
*
|
|
135
216
|
* @param map The application hook settings.
|
|
136
217
|
*/
|
|
137
|
-
hooks(map:
|
|
218
|
+
hooks(map: ApplicationHookOptions<this>): this;
|
|
138
219
|
}
|
|
139
|
-
export interface Application<
|
|
220
|
+
export interface Application<Services = any, Settings = any> extends FeathersApplication<Services, Settings>, EventEmitter {
|
|
140
221
|
}
|
|
141
|
-
export
|
|
142
|
-
export
|
|
222
|
+
export type Id = number | string;
|
|
223
|
+
export type NullableId = Id | null;
|
|
143
224
|
export interface Query {
|
|
144
225
|
[key: string]: any;
|
|
145
226
|
}
|
|
146
|
-
export interface Params {
|
|
147
|
-
query?:
|
|
227
|
+
export interface Params<Q = Query> {
|
|
228
|
+
query?: Q;
|
|
148
229
|
provider?: string;
|
|
149
230
|
route?: {
|
|
150
|
-
[key: string]:
|
|
231
|
+
[key: string]: any;
|
|
151
232
|
};
|
|
152
233
|
headers?: {
|
|
153
234
|
[key: string]: any;
|
|
154
235
|
};
|
|
155
|
-
[key: string]: any;
|
|
156
236
|
}
|
|
237
|
+
export interface Http {
|
|
238
|
+
/**
|
|
239
|
+
* A writeable, optional property with status code override.
|
|
240
|
+
*/
|
|
241
|
+
status?: number;
|
|
242
|
+
/**
|
|
243
|
+
* A writeable, optional property with headers.
|
|
244
|
+
*/
|
|
245
|
+
headers?: {
|
|
246
|
+
[key: string]: string | string[];
|
|
247
|
+
};
|
|
248
|
+
/**
|
|
249
|
+
* A writeable, optional property with `Location` header's value.
|
|
250
|
+
*/
|
|
251
|
+
location?: string;
|
|
252
|
+
}
|
|
253
|
+
export type HookType = 'before' | 'after' | 'error' | 'around';
|
|
157
254
|
export interface HookContext<A = Application, S = any> extends BaseHookContext<ServiceGenericType<S>> {
|
|
158
255
|
/**
|
|
159
256
|
* A read only property that contains the Feathers application object. This can be used to
|
|
@@ -175,10 +272,9 @@ export interface HookContext<A = Application, S = any> extends BaseHookContext<S
|
|
|
175
272
|
*/
|
|
176
273
|
readonly service: S;
|
|
177
274
|
/**
|
|
178
|
-
* A read only property with the hook type (one of before, after or error).
|
|
179
|
-
* Will be `null` for asynchronous hooks.
|
|
275
|
+
* A read only property with the hook type (one of 'around', 'before', 'after' or 'error').
|
|
180
276
|
*/
|
|
181
|
-
readonly type:
|
|
277
|
+
readonly type: HookType;
|
|
182
278
|
/**
|
|
183
279
|
* The list of method arguments. Should not be modified, modify the
|
|
184
280
|
* `params`, `data` and `id` properties instead.
|
|
@@ -204,7 +300,7 @@ export interface HookContext<A = Application, S = any> extends BaseHookContext<S
|
|
|
204
300
|
* A writeable property that contains the service method parameters (including
|
|
205
301
|
* params.query).
|
|
206
302
|
*/
|
|
207
|
-
params:
|
|
303
|
+
params: ServiceGenericParams<S>;
|
|
208
304
|
/**
|
|
209
305
|
* A writeable property containing the result of the successful service method call.
|
|
210
306
|
* It is only available in after hooks.
|
|
@@ -224,28 +320,47 @@ export interface HookContext<A = Application, S = any> extends BaseHookContext<S
|
|
|
224
320
|
/**
|
|
225
321
|
* A writeable, optional property that allows to override the standard HTTP status
|
|
226
322
|
* code that should be returned.
|
|
323
|
+
*
|
|
324
|
+
* @deprecated Use `http.status` instead.
|
|
227
325
|
*/
|
|
228
326
|
statusCode?: number;
|
|
327
|
+
/**
|
|
328
|
+
* A writeable, optional property with options specific to HTTP transports.
|
|
329
|
+
*/
|
|
330
|
+
http?: Http;
|
|
229
331
|
/**
|
|
230
332
|
* The event emitted by this method. Can be set to `null` to skip event emitting.
|
|
231
333
|
*/
|
|
232
334
|
event: string | null;
|
|
233
335
|
}
|
|
234
|
-
export
|
|
235
|
-
export
|
|
236
|
-
|
|
237
|
-
[L in keyof S]?: SelfOrArray<
|
|
336
|
+
export type HookFunction<A = Application, S = Service> = (this: S, context: HookContext<A, S>) => Promise<HookContext<Application, S> | void> | HookContext<Application, S> | void;
|
|
337
|
+
export type Hook<A = Application, S = Service> = HookFunction<A, S>;
|
|
338
|
+
type HookMethodMap<A, S> = {
|
|
339
|
+
[L in keyof S]?: SelfOrArray<HookFunction<A, S>>;
|
|
238
340
|
} & {
|
|
239
|
-
all?: SelfOrArray<
|
|
341
|
+
all?: SelfOrArray<HookFunction<A, S>>;
|
|
240
342
|
};
|
|
241
|
-
|
|
242
|
-
export
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
343
|
+
type HookTypeMap<A, S> = SelfOrArray<HookFunction<A, S>> | HookMethodMap<A, S>;
|
|
344
|
+
export type AroundHookFunction<A = Application, S = Service> = (context: HookContext<A, S>, next: NextFunction) => Promise<void>;
|
|
345
|
+
export type AroundHookMap<A, S> = {
|
|
346
|
+
[L in keyof S]?: AroundHookFunction<A, S>[];
|
|
347
|
+
} & {
|
|
348
|
+
all?: AroundHookFunction<A, S>[];
|
|
246
349
|
};
|
|
247
|
-
export
|
|
248
|
-
|
|
249
|
-
|
|
350
|
+
export type HookMap<A, S> = {
|
|
351
|
+
around?: AroundHookMap<A, S>;
|
|
352
|
+
before?: HookTypeMap<A, S>;
|
|
353
|
+
after?: HookTypeMap<A, S>;
|
|
354
|
+
error?: HookTypeMap<A, S>;
|
|
355
|
+
};
|
|
356
|
+
export type HookOptions<A, S> = AroundHookMap<A, S> | AroundHookFunction<A, S>[] | HookMap<A, S>;
|
|
357
|
+
export interface ApplicationHookContext<A = Application> extends BaseHookContext {
|
|
358
|
+
app: A;
|
|
359
|
+
server: any;
|
|
360
|
+
}
|
|
361
|
+
export type ApplicationHookFunction<A> = (context: ApplicationHookContext<A>, next: NextFunction) => Promise<void>;
|
|
362
|
+
export type ApplicationHookMap<A> = {
|
|
363
|
+
setup?: ApplicationHookFunction<A>[];
|
|
364
|
+
teardown?: ApplicationHookFunction<A>[];
|
|
250
365
|
};
|
|
251
|
-
export
|
|
366
|
+
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 {};
|