@feathersjs/feathers 5.0.0-pre.2 → 5.0.0-pre.20
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 +198 -0
- package/LICENSE +1 -1
- package/{readme.md → README.md} +2 -5
- package/lib/application.d.ts +15 -14
- package/lib/application.js +55 -37
- package/lib/application.js.map +1 -1
- package/lib/declarations.d.ts +116 -61
- package/lib/dependencies.d.ts +4 -0
- package/lib/dependencies.js +22 -0
- package/lib/dependencies.js.map +1 -0
- package/lib/events.d.ts +2 -2
- package/lib/events.js +3 -3
- package/lib/events.js.map +1 -1
- package/lib/hooks/index.d.ts +5 -6
- package/lib/hooks/index.js +30 -18
- package/lib/hooks/index.js.map +1 -1
- package/lib/hooks/regular.d.ts +12 -0
- package/lib/hooks/regular.js +169 -0
- package/lib/hooks/regular.js.map +1 -0
- package/lib/index.d.ts +4 -1
- package/lib/index.js +8 -2
- package/lib/index.js.map +1 -1
- package/lib/service.d.ts +1 -0
- package/lib/service.js +20 -5
- 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 +13 -14
- package/src/application.ts +67 -48
- package/src/declarations.ts +128 -69
- package/src/dependencies.ts +5 -0
- package/src/events.ts +3 -5
- package/src/hooks/index.ts +33 -16
- package/src/hooks/regular.ts +207 -0
- package/src/index.ts +4 -3
- package/src/service.ts +15 -3
- package/src/version.ts +1 -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/hooks/legacy.ts +0 -138
package/lib/declarations.d.ts
CHANGED
|
@@ -1,54 +1,66 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { EventEmitter } from '
|
|
3
|
-
import { NextFunction, HookContext as BaseHookContext } from '@feathersjs/hooks';
|
|
2
|
+
import { EventEmitter, NextFunction, HookContext as BaseHookContext } from './dependencies';
|
|
4
3
|
declare type SelfOrArray<S> = S | S[];
|
|
5
4
|
declare type OptionalPick<T, K extends PropertyKey> = Pick<T, Extract<keyof T, K>>;
|
|
6
|
-
export { NextFunction };
|
|
5
|
+
export type { NextFunction };
|
|
6
|
+
export interface Paginated<T> {
|
|
7
|
+
total: number;
|
|
8
|
+
limit: number;
|
|
9
|
+
skip: number;
|
|
10
|
+
data: T[];
|
|
11
|
+
}
|
|
7
12
|
export interface ServiceOptions {
|
|
8
13
|
events?: string[];
|
|
9
14
|
methods?: string[];
|
|
10
15
|
serviceEvents?: string[];
|
|
16
|
+
routeParams?: {
|
|
17
|
+
[key: string]: any;
|
|
18
|
+
};
|
|
11
19
|
}
|
|
12
|
-
export interface ServiceMethods<T, D = Partial<T
|
|
13
|
-
find(params?:
|
|
14
|
-
get(id: Id, params?:
|
|
15
|
-
create(data: D, params?:
|
|
16
|
-
update(id: NullableId, data: D, params?:
|
|
17
|
-
patch(id: NullableId, data: D, params?:
|
|
18
|
-
remove(id: NullableId, params?:
|
|
19
|
-
setup(app: Application, path: string): Promise<void>;
|
|
20
|
+
export interface ServiceMethods<T = any, D = Partial<T>, P = Params> {
|
|
21
|
+
find(params?: P): Promise<T | T[]>;
|
|
22
|
+
get(id: Id, params?: P): Promise<T>;
|
|
23
|
+
create(data: D, params?: P): Promise<T>;
|
|
24
|
+
update(id: NullableId, data: D, params?: P): Promise<T | T[]>;
|
|
25
|
+
patch(id: NullableId, data: D, params?: P): Promise<T | T[]>;
|
|
26
|
+
remove(id: NullableId, params?: P): Promise<T | T[]>;
|
|
27
|
+
setup?(app: Application, path: string): Promise<void>;
|
|
28
|
+
teardown?(app: Application, path: string): Promise<void>;
|
|
20
29
|
}
|
|
21
|
-
export interface ServiceOverloads<T, D> {
|
|
22
|
-
create?(data: D[], params?:
|
|
23
|
-
update?(id: Id, data: D, params?:
|
|
24
|
-
update?(id: null, data: D, params?:
|
|
25
|
-
patch?(id: Id, data: D, params?:
|
|
26
|
-
patch?(id: null, data: D, params?:
|
|
27
|
-
remove?(id: Id, params?:
|
|
28
|
-
remove?(id: null, params?:
|
|
30
|
+
export interface ServiceOverloads<T = any, D = Partial<T>, P = Params> {
|
|
31
|
+
create?(data: D[], params?: P): Promise<T[]>;
|
|
32
|
+
update?(id: Id, data: D, params?: P): Promise<T>;
|
|
33
|
+
update?(id: null, data: D, params?: P): Promise<T[]>;
|
|
34
|
+
patch?(id: Id, data: D, params?: P): Promise<T>;
|
|
35
|
+
patch?(id: null, data: D, params?: P): Promise<T[]>;
|
|
36
|
+
remove?(id: Id, params?: P): Promise<T>;
|
|
37
|
+
remove?(id: null, params?: P): Promise<T[]>;
|
|
29
38
|
}
|
|
30
|
-
export declare type Service<T, D = Partial<T
|
|
31
|
-
export declare type ServiceInterface<T, D = Partial<T
|
|
32
|
-
export interface ServiceAddons<A, S> extends EventEmitter {
|
|
39
|
+
export declare type Service<T = any, D = Partial<T>, P = Params> = ServiceMethods<T, D, P> & ServiceOverloads<T, D, P>;
|
|
40
|
+
export declare type ServiceInterface<T = any, D = Partial<T>, P = Params> = Partial<ServiceMethods<T, D, P>>;
|
|
41
|
+
export interface ServiceAddons<A = Application, S = Service> extends EventEmitter {
|
|
33
42
|
id?: string;
|
|
34
43
|
hooks(options: HookOptions<A, S>): this;
|
|
35
44
|
}
|
|
36
|
-
export interface ServiceHookOverloads<S> {
|
|
37
|
-
find(params:
|
|
38
|
-
get(id: Id, params:
|
|
39
|
-
create(data: ServiceGenericData<S> | ServiceGenericData<S>[], params:
|
|
40
|
-
update(id: NullableId, data: ServiceGenericData<S>, params:
|
|
41
|
-
patch(id: NullableId, data: ServiceGenericData<S>, params:
|
|
42
|
-
remove(id: NullableId, params:
|
|
45
|
+
export interface ServiceHookOverloads<S, P = Params> {
|
|
46
|
+
find(params: P, context: HookContext): Promise<HookContext>;
|
|
47
|
+
get(id: Id, params: P, context: HookContext): Promise<HookContext>;
|
|
48
|
+
create(data: ServiceGenericData<S> | ServiceGenericData<S>[], params: P, context: HookContext): Promise<HookContext>;
|
|
49
|
+
update(id: NullableId, data: ServiceGenericData<S>, params: P, context: HookContext): Promise<HookContext>;
|
|
50
|
+
patch(id: NullableId, data: ServiceGenericData<S>, params: P, context: HookContext): Promise<HookContext>;
|
|
51
|
+
remove(id: NullableId, params: P, context: HookContext): Promise<HookContext>;
|
|
43
52
|
}
|
|
44
|
-
export declare type FeathersService<A = FeathersApplication, S = Service
|
|
45
|
-
export declare type
|
|
46
|
-
[
|
|
53
|
+
export declare type FeathersService<A = FeathersApplication, S = Service> = S & ServiceAddons<A, S> & OptionalPick<ServiceHookOverloads<S>, keyof S>;
|
|
54
|
+
export declare type CustomMethods<T extends {
|
|
55
|
+
[key: string]: [any, any];
|
|
56
|
+
}> = {
|
|
57
|
+
[K in keyof T]: (data: T[K][0], params?: Params) => Promise<T[K][1]>;
|
|
47
58
|
};
|
|
48
|
-
export declare type ServiceMixin<A> = (service: FeathersService<A>, path: string, options
|
|
59
|
+
export declare type ServiceMixin<A> = (service: FeathersService<A>, path: string, options: ServiceOptions) => void;
|
|
49
60
|
export declare type ServiceGenericType<S> = S extends ServiceInterface<infer T> ? T : any;
|
|
50
61
|
export declare type ServiceGenericData<S> = S extends ServiceInterface<infer _T, infer D> ? D : any;
|
|
51
|
-
export
|
|
62
|
+
export declare type ServiceGenericParams<S> = S extends ServiceInterface<infer _T, infer _D, infer P> ? P : any;
|
|
63
|
+
export interface FeathersApplication<Services = any, Settings = any> {
|
|
52
64
|
/**
|
|
53
65
|
* The Feathers application version
|
|
54
66
|
*/
|
|
@@ -56,19 +68,19 @@ export interface FeathersApplication<ServiceTypes = any, AppSettings = any> {
|
|
|
56
68
|
/**
|
|
57
69
|
* A list of callbacks that run when a new service is registered
|
|
58
70
|
*/
|
|
59
|
-
mixins: ServiceMixin<Application<
|
|
71
|
+
mixins: ServiceMixin<Application<Services, Settings>>[];
|
|
60
72
|
/**
|
|
61
73
|
* The index of all services keyed by their path.
|
|
62
74
|
*
|
|
63
75
|
* __Important:__ Services should always be retrieved via `app.service('name')`
|
|
64
76
|
* not via `app.services`.
|
|
65
77
|
*/
|
|
66
|
-
services:
|
|
78
|
+
services: Services;
|
|
67
79
|
/**
|
|
68
80
|
* The application settings that can be used via
|
|
69
81
|
* `app.get` and `app.set`
|
|
70
82
|
*/
|
|
71
|
-
settings:
|
|
83
|
+
settings: Settings;
|
|
72
84
|
/**
|
|
73
85
|
* A private-ish indicator if `app.setup()` has been called already
|
|
74
86
|
*/
|
|
@@ -76,20 +88,20 @@ export interface FeathersApplication<ServiceTypes = any, AppSettings = any> {
|
|
|
76
88
|
/**
|
|
77
89
|
* Contains all registered application level hooks.
|
|
78
90
|
*/
|
|
79
|
-
appHooks: HookMap<Application<
|
|
91
|
+
appHooks: HookMap<Application<Services, Settings>, any>;
|
|
80
92
|
/**
|
|
81
93
|
* Retrieve an application setting by name
|
|
82
94
|
*
|
|
83
95
|
* @param name The setting name
|
|
84
96
|
*/
|
|
85
|
-
get<L extends keyof
|
|
97
|
+
get<L extends keyof Settings & string>(name: L): Settings[L];
|
|
86
98
|
/**
|
|
87
99
|
* Set an application setting
|
|
88
100
|
*
|
|
89
101
|
* @param name The setting name
|
|
90
102
|
* @param value The setting value
|
|
91
103
|
*/
|
|
92
|
-
set<L extends keyof
|
|
104
|
+
set<L extends keyof Settings & string>(name: L, value: Settings[L]): this;
|
|
93
105
|
/**
|
|
94
106
|
* Runs a callback configure function with the current application instance.
|
|
95
107
|
*
|
|
@@ -103,7 +115,7 @@ export interface FeathersApplication<ServiceTypes = any, AppSettings = any> {
|
|
|
103
115
|
*
|
|
104
116
|
* @param location The path of the service
|
|
105
117
|
*/
|
|
106
|
-
defaultService(location: string): ServiceInterface
|
|
118
|
+
defaultService(location: string): ServiceInterface;
|
|
107
119
|
/**
|
|
108
120
|
* Register a new service or a sub-app. When passed another
|
|
109
121
|
* Feathers application, all its services will be re-registered
|
|
@@ -114,7 +126,7 @@ export interface FeathersApplication<ServiceTypes = any, AppSettings = any> {
|
|
|
114
126
|
* Feathers application to use a sub-app under the `path` prefix.
|
|
115
127
|
* @param options The options for this service
|
|
116
128
|
*/
|
|
117
|
-
use<L extends keyof
|
|
129
|
+
use<L extends keyof Services & string>(path: L, service: keyof any extends keyof Services ? ServiceInterface | Application : Services[L], options?: ServiceOptions): this;
|
|
118
130
|
/**
|
|
119
131
|
* Get the Feathers service instance for a path. This will
|
|
120
132
|
* be the service originally registered with Feathers functionality
|
|
@@ -122,32 +134,58 @@ export interface FeathersApplication<ServiceTypes = any, AppSettings = any> {
|
|
|
122
134
|
*
|
|
123
135
|
* @param path The name of the service.
|
|
124
136
|
*/
|
|
125
|
-
service<L extends keyof
|
|
137
|
+
service<L extends keyof Services & string>(path: L): FeathersService<this, keyof any extends keyof Services ? Service : Services[L]>;
|
|
138
|
+
/**
|
|
139
|
+
* Set up the application and call all services `.setup` method if available.
|
|
140
|
+
*
|
|
141
|
+
* @param server A server instance (optional)
|
|
142
|
+
*/
|
|
126
143
|
setup(server?: any): Promise<this>;
|
|
144
|
+
/**
|
|
145
|
+
* Tear down the application and call all services `.teardown` method if available.
|
|
146
|
+
*
|
|
147
|
+
* @param server A server instance (optional)
|
|
148
|
+
*/
|
|
149
|
+
teardown(server?: any): Promise<this>;
|
|
127
150
|
/**
|
|
128
151
|
* Register application level hooks.
|
|
129
152
|
*
|
|
130
153
|
* @param map The application hook settings.
|
|
131
154
|
*/
|
|
132
|
-
hooks(map:
|
|
155
|
+
hooks(map: ApplicationHookOptions<this>): this;
|
|
133
156
|
}
|
|
134
|
-
export interface Application<
|
|
157
|
+
export interface Application<Services = any, Settings = any> extends FeathersApplication<Services, Settings>, EventEmitter {
|
|
135
158
|
}
|
|
136
159
|
export declare type Id = number | string;
|
|
137
160
|
export declare type NullableId = Id | null;
|
|
138
161
|
export interface Query {
|
|
139
162
|
[key: string]: any;
|
|
140
163
|
}
|
|
141
|
-
export interface Params {
|
|
142
|
-
query?:
|
|
164
|
+
export interface Params<Q = Query> {
|
|
165
|
+
query?: Q;
|
|
143
166
|
provider?: string;
|
|
144
167
|
route?: {
|
|
145
|
-
[key: string]:
|
|
168
|
+
[key: string]: any;
|
|
146
169
|
};
|
|
147
170
|
headers?: {
|
|
148
171
|
[key: string]: any;
|
|
149
172
|
};
|
|
150
|
-
|
|
173
|
+
}
|
|
174
|
+
export interface Http {
|
|
175
|
+
/**
|
|
176
|
+
* A writeable, optional property with status code override.
|
|
177
|
+
*/
|
|
178
|
+
status?: number;
|
|
179
|
+
/**
|
|
180
|
+
* A writeable, optional property with headers.
|
|
181
|
+
*/
|
|
182
|
+
headers?: {
|
|
183
|
+
[key: string]: string | string[];
|
|
184
|
+
};
|
|
185
|
+
/**
|
|
186
|
+
* A writeable, optional property with `Location` header's value.
|
|
187
|
+
*/
|
|
188
|
+
location?: string;
|
|
151
189
|
}
|
|
152
190
|
export interface HookContext<A = Application, S = any> extends BaseHookContext<ServiceGenericType<S>> {
|
|
153
191
|
/**
|
|
@@ -199,7 +237,7 @@ export interface HookContext<A = Application, S = any> extends BaseHookContext<S
|
|
|
199
237
|
* A writeable property that contains the service method parameters (including
|
|
200
238
|
* params.query).
|
|
201
239
|
*/
|
|
202
|
-
params:
|
|
240
|
+
params: ServiceGenericParams<S>;
|
|
203
241
|
/**
|
|
204
242
|
* A writeable property containing the result of the successful service method call.
|
|
205
243
|
* It is only available in after hooks.
|
|
@@ -219,27 +257,44 @@ export interface HookContext<A = Application, S = any> extends BaseHookContext<S
|
|
|
219
257
|
/**
|
|
220
258
|
* A writeable, optional property that allows to override the standard HTTP status
|
|
221
259
|
* code that should be returned.
|
|
260
|
+
*
|
|
261
|
+
* @deprecated Use `http.status` instead.
|
|
222
262
|
*/
|
|
223
263
|
statusCode?: number;
|
|
264
|
+
/**
|
|
265
|
+
* A writeable, optional property with options specific to HTTP transports.
|
|
266
|
+
*/
|
|
267
|
+
http?: Http;
|
|
224
268
|
/**
|
|
225
269
|
* The event emitted by this method. Can be set to `null` to skip event emitting.
|
|
226
270
|
*/
|
|
227
271
|
event: string | null;
|
|
228
272
|
}
|
|
229
|
-
export declare type
|
|
230
|
-
declare type
|
|
231
|
-
|
|
273
|
+
export declare type RegularHookFunction<A = Application, S = Service> = (this: S, context: HookContext<A, S>) => (Promise<HookContext<Application, S> | void> | HookContext<Application, S> | void);
|
|
274
|
+
export declare type Hook<A = Application, S = Service> = RegularHookFunction<A, S>;
|
|
275
|
+
declare type RegularHookMethodMap<A, S> = {
|
|
276
|
+
[L in keyof S]?: SelfOrArray<RegularHookFunction<A, S>>;
|
|
232
277
|
} & {
|
|
233
|
-
all?: SelfOrArray<
|
|
278
|
+
all?: SelfOrArray<RegularHookFunction<A, S>>;
|
|
234
279
|
};
|
|
235
|
-
declare type
|
|
236
|
-
export declare type
|
|
237
|
-
before?:
|
|
238
|
-
after?:
|
|
239
|
-
error?:
|
|
280
|
+
declare type RegularHookTypeMap<A, S> = SelfOrArray<RegularHookFunction<A, S>> | RegularHookMethodMap<A, S>;
|
|
281
|
+
export declare type RegularHookMap<A, S> = {
|
|
282
|
+
before?: RegularHookTypeMap<A, S>;
|
|
283
|
+
after?: RegularHookTypeMap<A, S>;
|
|
284
|
+
error?: RegularHookTypeMap<A, S>;
|
|
240
285
|
};
|
|
241
|
-
export declare type HookFunction<A = Application, S = Service
|
|
286
|
+
export declare type HookFunction<A = Application, S = Service> = (context: HookContext<A, S>, next: NextFunction) => Promise<void>;
|
|
242
287
|
export declare type HookMap<A, S> = {
|
|
243
288
|
[L in keyof S]?: HookFunction<A, S>[];
|
|
244
289
|
};
|
|
245
|
-
export declare type HookOptions<A, S> = HookMap<A, S> | HookFunction<A, S>[] |
|
|
290
|
+
export declare type HookOptions<A, S> = HookMap<A, S> | HookFunction<A, S>[] | RegularHookMap<A, S>;
|
|
291
|
+
export interface ApplicationHookContext<A = Application> extends BaseHookContext {
|
|
292
|
+
app: A;
|
|
293
|
+
server: any;
|
|
294
|
+
}
|
|
295
|
+
export declare type ApplicationHookFunction<A> = (context: ApplicationHookContext<A>, next: NextFunction) => Promise<void>;
|
|
296
|
+
export declare type ApplicationHookMap<A> = {
|
|
297
|
+
setup?: ApplicationHookFunction<A>[];
|
|
298
|
+
teardown?: ApplicationHookFunction<A>[];
|
|
299
|
+
};
|
|
300
|
+
export declare type ApplicationHookOptions<A> = HookOptions<A, any> | ApplicationHookMap<A>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.EventEmitter = void 0;
|
|
18
|
+
const events_1 = require("events");
|
|
19
|
+
Object.defineProperty(exports, "EventEmitter", { enumerable: true, get: function () { return events_1.EventEmitter; } });
|
|
20
|
+
__exportStar(require("@feathersjs/commons"), exports);
|
|
21
|
+
__exportStar(require("@feathersjs/hooks"), exports);
|
|
22
|
+
//# sourceMappingURL=dependencies.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dependencies.js","sourceRoot":"","sources":["../src/dependencies.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,mCAAsC;AAI7B,6FAJA,qBAAY,OAIA;AAHrB,sDAAoC;AACpC,oDAAkC"}
|
package/lib/events.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NextFunction } from '
|
|
1
|
+
import { NextFunction } from './dependencies';
|
|
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>>>;
|
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 dependencies_1 = require("./dependencies");
|
|
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(() => {
|
|
@@ -21,7 +21,7 @@ function eventMixin(service) {
|
|
|
21
21
|
const isEmitter = typeof service.on === 'function' &&
|
|
22
22
|
typeof service.emit === 'function';
|
|
23
23
|
if (!isEmitter) {
|
|
24
|
-
Object.assign(service,
|
|
24
|
+
Object.assign(service, dependencies_1.EventEmitter.prototype);
|
|
25
25
|
}
|
|
26
26
|
return service;
|
|
27
27
|
}
|
package/lib/events.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.js","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"","s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@
|
|
|
1
|
-
import { HookContextData, HookManager, Middleware } from '
|
|
1
|
+
import { HookContextData, HookManager, Middleware } from '../dependencies';
|
|
2
2
|
import { Service, ServiceOptions, HookContext, FeathersService, Application } from '../declarations';
|
|
3
|
-
|
|
4
|
-
export
|
|
5
|
-
export declare function createContext(service: Service<any>, method: string, data?: HookContextData): HookContext<Application<any, any>, any>;
|
|
3
|
+
export { fromBeforeHook, fromBeforeHooks, fromAfterHook, fromAfterHooks, fromErrorHook, fromErrorHooks } from './regular';
|
|
4
|
+
export declare function createContext(service: Service, method: string, data?: HookContextData): HookContext<Application<any, any>, any>;
|
|
6
5
|
export declare class FeathersHookManager<A> extends HookManager {
|
|
7
6
|
app: A;
|
|
8
7
|
method: string;
|
|
9
8
|
constructor(app: A, method: string);
|
|
10
9
|
collectMiddleware(self: any, args: any[]): Middleware[];
|
|
11
|
-
initializeContext(self: any, args: any[], context: HookContext): import("@feathersjs/hooks").HookContext<any, any>;
|
|
10
|
+
initializeContext(self: any, args: any[], context: HookContext): import("@feathersjs/hooks/types/base").HookContext<any, any>;
|
|
12
11
|
middleware(mw: Middleware[]): this;
|
|
13
12
|
}
|
|
14
|
-
export declare function hookMixin<A>(this: A, service: FeathersService<A>, path: string, options: ServiceOptions): FeathersService<A, Service<any, Partial<any>>>;
|
|
13
|
+
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>>>;
|
package/lib/hooks/index.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.hookMixin = exports.FeathersHookManager = exports.createContext = exports.fromErrorHooks = exports.
|
|
4
|
-
const
|
|
3
|
+
exports.hookMixin = exports.FeathersHookManager = exports.createContext = exports.fromErrorHooks = exports.fromErrorHook = exports.fromAfterHooks = exports.fromAfterHook = exports.fromBeforeHooks = exports.fromBeforeHook = void 0;
|
|
4
|
+
const dependencies_1 = require("../dependencies");
|
|
5
5
|
const service_1 = require("../service");
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
Object.defineProperty(exports, "fromBeforeHook", { enumerable: true, get: function () { return
|
|
9
|
-
Object.defineProperty(exports, "
|
|
6
|
+
const regular_1 = require("./regular");
|
|
7
|
+
var regular_2 = require("./regular");
|
|
8
|
+
Object.defineProperty(exports, "fromBeforeHook", { enumerable: true, get: function () { return regular_2.fromBeforeHook; } });
|
|
9
|
+
Object.defineProperty(exports, "fromBeforeHooks", { enumerable: true, get: function () { return regular_2.fromBeforeHooks; } });
|
|
10
|
+
Object.defineProperty(exports, "fromAfterHook", { enumerable: true, get: function () { return regular_2.fromAfterHook; } });
|
|
11
|
+
Object.defineProperty(exports, "fromAfterHooks", { enumerable: true, get: function () { return regular_2.fromAfterHooks; } });
|
|
12
|
+
Object.defineProperty(exports, "fromErrorHook", { enumerable: true, get: function () { return regular_2.fromErrorHook; } });
|
|
13
|
+
Object.defineProperty(exports, "fromErrorHooks", { enumerable: true, get: function () { return regular_2.fromErrorHooks; } });
|
|
10
14
|
function createContext(service, method, data = {}) {
|
|
11
15
|
const createContext = service[method].createContext;
|
|
12
16
|
if (typeof createContext !== 'function') {
|
|
@@ -15,7 +19,7 @@ function createContext(service, method, data = {}) {
|
|
|
15
19
|
return createContext(data);
|
|
16
20
|
}
|
|
17
21
|
exports.createContext = createContext;
|
|
18
|
-
class FeathersHookManager extends
|
|
22
|
+
class FeathersHookManager extends dependencies_1.HookManager {
|
|
19
23
|
constructor(app, method) {
|
|
20
24
|
super();
|
|
21
25
|
this.app = app;
|
|
@@ -24,11 +28,11 @@ class FeathersHookManager extends hooks_1.HookManager {
|
|
|
24
28
|
}
|
|
25
29
|
collectMiddleware(self, args) {
|
|
26
30
|
const app = this.app;
|
|
27
|
-
const appHooks = app.appHooks[
|
|
28
|
-
const
|
|
31
|
+
const appHooks = app.appHooks[dependencies_1.HOOKS].concat(app.appHooks[this.method] || []);
|
|
32
|
+
const regularAppHooks = (0, regular_1.collectRegularHooks)(this.app, this.method);
|
|
29
33
|
const middleware = super.collectMiddleware(self, args);
|
|
30
|
-
const
|
|
31
|
-
return [...appHooks, ...
|
|
34
|
+
const regularHooks = (0, regular_1.collectRegularHooks)(self, this.method);
|
|
35
|
+
return [...appHooks, ...regularAppHooks, ...middleware, ...regularHooks];
|
|
32
36
|
}
|
|
33
37
|
initializeContext(self, args, context) {
|
|
34
38
|
const ctx = super.initializeContext(self, args, context);
|
|
@@ -46,7 +50,8 @@ function hookMixin(service, path, options) {
|
|
|
46
50
|
return service;
|
|
47
51
|
}
|
|
48
52
|
const app = this;
|
|
49
|
-
const
|
|
53
|
+
const hookMethods = (0, service_1.getHookMethods)(service, options);
|
|
54
|
+
const serviceMethodHooks = hookMethods.reduce((res, method) => {
|
|
50
55
|
const params = service_1.defaultServiceArguments[method] || ['data', 'params'];
|
|
51
56
|
res[method] = new FeathersHookManager(app, method)
|
|
52
57
|
.params(...params)
|
|
@@ -56,21 +61,28 @@ function hookMixin(service, path, options) {
|
|
|
56
61
|
method,
|
|
57
62
|
service,
|
|
58
63
|
event: null,
|
|
59
|
-
type: null
|
|
64
|
+
type: null,
|
|
65
|
+
get statusCode() {
|
|
66
|
+
var _a;
|
|
67
|
+
return (_a = this.http) === null || _a === void 0 ? void 0 : _a.status;
|
|
68
|
+
},
|
|
69
|
+
set statusCode(value) {
|
|
70
|
+
(this.http || (this.http = {})).status = value;
|
|
71
|
+
}
|
|
60
72
|
});
|
|
61
73
|
return res;
|
|
62
74
|
}, {});
|
|
63
|
-
const
|
|
64
|
-
|
|
75
|
+
const handleRegularHooks = (0, regular_1.enableRegularHooks)(service, hookMethods);
|
|
76
|
+
(0, dependencies_1.hooks)(service, serviceMethodHooks);
|
|
65
77
|
service.hooks = function (hookOptions) {
|
|
66
78
|
if (hookOptions.before || hookOptions.after || hookOptions.error) {
|
|
67
|
-
return
|
|
79
|
+
return handleRegularHooks.call(this, hookOptions);
|
|
68
80
|
}
|
|
69
81
|
if (Array.isArray(hookOptions)) {
|
|
70
|
-
return
|
|
82
|
+
return (0, dependencies_1.hooks)(this, hookOptions);
|
|
71
83
|
}
|
|
72
84
|
Object.keys(hookOptions).forEach(method => {
|
|
73
|
-
const manager =
|
|
85
|
+
const manager = (0, dependencies_1.getManager)(this[method]);
|
|
74
86
|
if (!(manager instanceof FeathersHookManager)) {
|
|
75
87
|
throw new Error(`Method ${method} is not a Feathers hooks enabled service method`);
|
|
76
88
|
}
|
package/lib/hooks/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":";;;AAAA,kDAEyB;AAIzB,wCAAqE;AACrE,uCAGmB;AAEnB,qCAOmB;AANjB,yGAAA,cAAc,OAAA;AACd,0GAAA,eAAe,OAAA;AACf,wGAAA,aAAa,OAAA;AACb,yGAAA,cAAc,OAAA;AACd,wGAAA,aAAa,OAAA;AACb,yGAAA,cAAc,OAAA;AAGhB,SAAgB,aAAa,CAAE,OAAgB,EAAE,MAAc,EAAE,OAAwB,EAAE;IACzF,MAAM,aAAa,GAAI,OAAe,CAAC,MAAM,CAAC,CAAC,aAAa,CAAC;IAE7D,IAAI,OAAO,aAAa,KAAK,UAAU,EAAE;QACvC,MAAM,IAAI,KAAK,CAAC,qCAAqC,MAAM,EAAE,CAAC,CAAC;KAChE;IAED,OAAO,aAAa,CAAC,IAAI,CAAgB,CAAC;AAC5C,CAAC;AARD,sCAQC;AAED,MAAa,mBAAuB,SAAQ,0BAAW;IACrD,YAAoB,GAAM,EAAS,MAAc;QAC/C,KAAK,EAAE,CAAC;QADU,QAAG,GAAH,GAAG,CAAG;QAAS,WAAM,GAAN,MAAM,CAAQ;QAE/C,IAAI,CAAC,WA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AC,CAAC;SACjC;QAED,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;YACxC,MAAM,OAAO,GAAG,IAAA,yBAAU,EAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;YAEzC,IAAI,CAAC,CAAC,OAAO,YAAY,mBAAmB,CAAC,EAAE;gBAC7C,MAAM,IAAI,KAAK,CAAC,UAAU,MAAM,iDAAiD,CAAC,CAAC;aACpF;YAED,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;QAC1C,CAAC,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC;IACd,CAAC,CAAA;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AA5DD,8BA4DC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { HookFunction, RegularHookFunction, RegularHookMap } from '../declarations';
|
|
2
|
+
export declare function fromBeforeHook<A, S>(hook: RegularHookFunction<A, S>): HookFunction<A, S>;
|
|
3
|
+
export declare function fromAfterHook<A, S>(hook: RegularHookFunction<A, S>): HookFunction<A, S>;
|
|
4
|
+
export declare function fromErrorHook<A, S>(hook: RegularHookFunction<A, S>): HookFunction<A, S>;
|
|
5
|
+
export declare function fromBeforeHooks<A, S>(hooks: RegularHookFunction<A, S>[]): HookFunction<unknown, unknown>;
|
|
6
|
+
export declare function fromAfterHooks<A, S>(hooks: RegularHookFunction<A, S>[]): HookFunction<unknown, unknown>;
|
|
7
|
+
export declare function fromErrorHooks<A, S>(hooks: RegularHookFunction<A, S>[]): HookFunction<unknown, unknown>;
|
|
8
|
+
export declare function collectRegularHooks(target: any, method: string): any;
|
|
9
|
+
export declare function convertHookData(input: any): {
|
|
10
|
+
[method: string]: RegularHookFunction<import("../declarations").Application<any, any>, import("../declarations").Service<any, Partial<any>, import("../declarations").Params<import("../declarations").Query>>>[];
|
|
11
|
+
};
|
|
12
|
+
export declare function enableRegularHooks(object: any, methods?: string[]): (this: any, input: RegularHookMap<any, any>) => any;
|