@feathersjs/feathers 5.0.0-pre.1 → 5.0.0-pre.15

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.
Files changed (46) hide show
  1. package/CHANGELOG.md +182 -0
  2. package/LICENSE +1 -1
  3. package/lib/application.d.ts +19 -8
  4. package/lib/application.js +80 -78
  5. package/lib/application.js.map +1 -1
  6. package/lib/declarations.d.ts +207 -106
  7. package/lib/dependencies.d.ts +4 -0
  8. package/lib/dependencies.js +18 -0
  9. package/lib/dependencies.js.map +1 -0
  10. package/lib/events.d.ts +4 -4
  11. package/lib/events.js +16 -69
  12. package/lib/events.js.map +1 -1
  13. package/lib/hooks/index.d.ts +13 -2
  14. package/lib/hooks/index.js +84 -146
  15. package/lib/hooks/index.js.map +1 -1
  16. package/lib/hooks/regular.d.ts +12 -0
  17. package/lib/hooks/regular.js +169 -0
  18. package/lib/hooks/regular.js.map +1 -0
  19. package/lib/index.d.ts +9 -4
  20. package/lib/index.js +9 -12
  21. package/lib/index.js.map +1 -1
  22. package/lib/service.d.ts +21 -0
  23. package/lib/service.js +68 -0
  24. package/lib/service.js.map +1 -0
  25. package/lib/version.d.ts +1 -1
  26. package/lib/version.js +1 -1
  27. package/lib/version.js.map +1 -1
  28. package/package.json +12 -13
  29. package/readme.md +1 -77
  30. package/src/application.ts +115 -105
  31. package/src/declarations.ts +274 -121
  32. package/src/dependencies.ts +5 -0
  33. package/src/events.ts +18 -75
  34. package/src/hooks/index.ts +95 -150
  35. package/src/hooks/regular.ts +207 -0
  36. package/src/index.ts +10 -17
  37. package/src/service.ts +91 -0
  38. package/src/version.ts +1 -1
  39. package/lib/hooks/base.d.ts +0 -3
  40. package/lib/hooks/base.js +0 -29
  41. package/lib/hooks/base.js.map +0 -1
  42. package/lib/hooks/commons.d.ts +0 -20
  43. package/lib/hooks/commons.js +0 -298
  44. package/lib/hooks/commons.js.map +0 -1
  45. package/src/hooks/base.ts +0 -32
  46. package/src/hooks/commons.ts +0 -336
@@ -1,65 +1,206 @@
1
1
  /// <reference types="node" />
2
- import { EventEmitter } from 'events';
3
- import { NextFunction } from '@feathersjs/hooks';
2
+ import { EventEmitter, NextFunction, HookContext as BaseHookContext } from './dependencies';
3
+ declare type SelfOrArray<S> = S | S[];
4
+ declare type OptionalPick<T, K extends PropertyKey> = Pick<T, Extract<keyof T, K>>;
5
+ export type { NextFunction };
6
+ export interface Paginated<T> {
7
+ total: number;
8
+ limit: number;
9
+ skip: number;
10
+ data: T[];
11
+ }
12
+ export interface ServiceOptions {
13
+ events?: string[];
14
+ methods?: string[];
15
+ serviceEvents?: string[];
16
+ routeParams?: {
17
+ [key: string]: any;
18
+ };
19
+ }
20
+ export interface ServiceMethods<T = any, D = Partial<T>> {
21
+ find(params?: Params): Promise<T | T[]>;
22
+ get(id: Id, params?: Params): Promise<T>;
23
+ create(data: D, params?: Params): Promise<T>;
24
+ update(id: NullableId, data: D, params?: Params): Promise<T | T[]>;
25
+ patch(id: NullableId, data: D, params?: Params): Promise<T | T[]>;
26
+ remove(id: NullableId, params?: Params): Promise<T | T[]>;
27
+ setup(app: Application, path: string): Promise<void>;
28
+ }
29
+ export interface ServiceOverloads<T = any, D = Partial<T>> {
30
+ create?(data: D[], params?: Params): Promise<T[]>;
31
+ update?(id: Id, data: D, params?: Params): Promise<T>;
32
+ update?(id: null, data: D, params?: Params): Promise<T[]>;
33
+ patch?(id: Id, data: D, params?: Params): Promise<T>;
34
+ patch?(id: null, data: D, params?: Params): Promise<T[]>;
35
+ remove?(id: Id, params?: Params): Promise<T>;
36
+ remove?(id: null, params?: Params): Promise<T[]>;
37
+ }
38
+ export declare type Service<T = any, D = Partial<T>> = ServiceMethods<T, D> & ServiceOverloads<T, D>;
39
+ export declare type ServiceInterface<T = any, D = Partial<T>> = Partial<ServiceMethods<T, D>>;
40
+ export interface ServiceAddons<A = Application, S = Service> extends EventEmitter {
41
+ id?: string;
42
+ hooks(options: HookOptions<A, S>): this;
43
+ }
44
+ export interface ServiceHookOverloads<S> {
45
+ find(params: Params, context: HookContext): Promise<HookContext>;
46
+ get(id: Id, params: Params, context: HookContext): Promise<HookContext>;
47
+ create(data: ServiceGenericData<S> | ServiceGenericData<S>[], params: Params, context: HookContext): Promise<HookContext>;
48
+ update(id: NullableId, data: ServiceGenericData<S>, params: Params, context: HookContext): Promise<HookContext>;
49
+ patch(id: NullableId, data: ServiceGenericData<S>, params: Params, context: HookContext): Promise<HookContext>;
50
+ remove(id: NullableId, params: Params, context: HookContext): Promise<HookContext>;
51
+ }
52
+ export declare type FeathersService<A = FeathersApplication, S = Service> = S & ServiceAddons<A, S> & OptionalPick<ServiceHookOverloads<S>, keyof S>;
53
+ export declare type CustomMethods<T extends {
54
+ [key: string]: [any, any];
55
+ }> = {
56
+ [K in keyof T]: (data: T[K][0], params?: Params) => Promise<T[K][1]>;
57
+ };
58
+ export declare type ServiceMixin<A> = (service: FeathersService<A>, path: string, options: ServiceOptions) => void;
59
+ export declare type ServiceGenericType<S> = S extends ServiceInterface<infer T> ? T : any;
60
+ export declare type ServiceGenericData<S> = S extends ServiceInterface<infer _T, infer D> ? D : any;
61
+ export interface FeathersApplication<Services = any, Settings = any> {
62
+ /**
63
+ * The Feathers application version
64
+ */
65
+ version: string;
66
+ /**
67
+ * A list of callbacks that run when a new service is registered
68
+ */
69
+ mixins: ServiceMixin<Application<Services, Settings>>[];
70
+ /**
71
+ * The index of all services keyed by their path.
72
+ *
73
+ * __Important:__ Services should always be retrieved via `app.service('name')`
74
+ * not via `app.services`.
75
+ */
76
+ services: Services;
77
+ /**
78
+ * The application settings that can be used via
79
+ * `app.get` and `app.set`
80
+ */
81
+ settings: Settings;
82
+ /**
83
+ * A private-ish indicator if `app.setup()` has been called already
84
+ */
85
+ _isSetup: boolean;
86
+ /**
87
+ * Contains all registered application level hooks.
88
+ */
89
+ appHooks: HookMap<Application<Services, Settings>, any>;
90
+ /**
91
+ * Retrieve an application setting by name
92
+ *
93
+ * @param name The setting name
94
+ */
95
+ get<L extends keyof Settings & string>(name: L): Settings[L];
96
+ /**
97
+ * Set an application setting
98
+ *
99
+ * @param name The setting name
100
+ * @param value The setting value
101
+ */
102
+ set<L extends keyof Settings & string>(name: L, value: Settings[L]): this;
103
+ /**
104
+ * Runs a callback configure function with the current application instance.
105
+ *
106
+ * @param callback The callback `(app: Application) => {}` to run
107
+ */
108
+ configure(callback: (this: this, app: this) => void): this;
109
+ /**
110
+ * Returns a fallback service instance that will be registered
111
+ * when no service was found. Usually throws a `NotFound` error
112
+ * but also used to instantiate client side services.
113
+ *
114
+ * @param location The path of the service
115
+ */
116
+ defaultService(location: string): ServiceInterface;
117
+ /**
118
+ * Register a new service or a sub-app. When passed another
119
+ * Feathers application, all its services will be re-registered
120
+ * with the `path` prefix.
121
+ *
122
+ * @param path The path for the service to register
123
+ * @param service The service object to register or another
124
+ * Feathers application to use a sub-app under the `path` prefix.
125
+ * @param options The options for this service
126
+ */
127
+ use<L extends keyof Services & string>(path: L, service: keyof any extends keyof Services ? ServiceInterface | Application : Services[L], options?: ServiceOptions): this;
128
+ /**
129
+ * Get the Feathers service instance for a path. This will
130
+ * be the service originally registered with Feathers functionality
131
+ * like hooks and events added.
132
+ *
133
+ * @param path The name of the service.
134
+ */
135
+ service<L extends keyof Services & string>(path: L): FeathersService<this, keyof any extends keyof Services ? Service : Services[L]>;
136
+ setup(server?: any): Promise<this>;
137
+ /**
138
+ * Register application level hooks.
139
+ *
140
+ * @param map The application hook settings.
141
+ */
142
+ hooks(map: HookOptions<this, any>): this;
143
+ }
144
+ export interface Application<Services = any, Settings = any> extends FeathersApplication<Services, Settings>, EventEmitter {
145
+ }
4
146
  export declare type Id = number | string;
5
147
  export declare type NullableId = Id | null;
6
148
  export interface Query {
7
149
  [key: string]: any;
8
150
  }
9
- export interface AppSettings {
10
- [key: string]: any;
11
- }
12
151
  export interface Params {
13
152
  query?: Query;
14
153
  provider?: string;
15
154
  route?: {
16
- [key: string]: string;
155
+ [key: string]: any;
17
156
  };
18
157
  headers?: {
19
158
  [key: string]: any;
20
159
  };
21
160
  [key: string]: any;
22
161
  }
23
- export interface BaseApplication {
24
- version: string;
25
- mixins: ServiceMixin[];
26
- methods: string[];
27
- settings: AppSettings;
28
- providers: any[];
29
- defaultService: any;
30
- eventMappings: {
31
- [key: string]: string;
32
- };
33
- get(name: string): any;
34
- set(name: string, value: any): this;
35
- disable(name: string): this;
36
- disabled(name: string): boolean;
37
- enable(name: string): this;
38
- enabled(name: string): boolean;
39
- configure(callback: (this: this, app: this) => void): this;
40
- hooks(hooks: Partial<HooksObject>): this;
41
- setup(server?: any): this;
42
- service(location: string): Service<any>;
43
- use(path: string, service: Partial<ServiceMethods<any> & SetupMethod> | Application, options?: any): this;
44
- listen(port: number): any;
45
- }
46
- export interface Application<ServiceTypes = {}> extends EventEmitter, BaseApplication {
47
- services: keyof ServiceTypes extends never ? any : ServiceTypes;
48
- service<L extends keyof ServiceTypes>(location: L): ServiceTypes[L];
49
- service(location: string): keyof ServiceTypes extends never ? any : never;
162
+ export interface Http {
163
+ /**
164
+ * A writeable, optional property that allows to override the standard HTTP status
165
+ * code that should be returned.
166
+ */
167
+ statusCode?: number;
50
168
  }
51
- export declare type Hook<T = any, S = Service<T>> = (hook: HookContext<T, S>, next?: NextFunction) => (Promise<HookContext<T, S> | void> | HookContext<T, S> | void);
52
- export interface HookContext<T = any, S = Service<T>> {
169
+ export interface HookContext<A = Application, S = any> extends BaseHookContext<ServiceGenericType<S>> {
53
170
  /**
54
171
  * A read only property that contains the Feathers application object. This can be used to
55
172
  * retrieve other services (via context.app.service('name')) or configuration values.
56
173
  */
57
- readonly app: Application;
174
+ readonly app: A;
175
+ /**
176
+ * A read only property with the name of the service method (one of find, get,
177
+ * create, update, patch, remove).
178
+ */
179
+ readonly method: string;
180
+ /**
181
+ * A read only property and contains the service name (or path) without leading or
182
+ * trailing slashes.
183
+ */
184
+ readonly path: string;
185
+ /**
186
+ * A read only property and contains the service this hook currently runs on.
187
+ */
188
+ readonly service: S;
189
+ /**
190
+ * A read only property with the hook type (one of before, after or error).
191
+ * Will be `null` for asynchronous hooks.
192
+ */
193
+ readonly type: null | 'before' | 'after' | 'error';
194
+ /**
195
+ * The list of method arguments. Should not be modified, modify the
196
+ * `params`, `data` and `id` properties instead.
197
+ */
198
+ readonly arguments: any[];
58
199
  /**
59
200
  * A writeable property containing the data of a create, update and patch service
60
201
  * method call.
61
202
  */
62
- data?: T;
203
+ data?: ServiceGenericData<S>;
63
204
  /**
64
205
  * A writeable property with the error object that was thrown in a failed method call.
65
206
  * It is only available in error hooks.
@@ -70,22 +211,12 @@ export interface HookContext<T = any, S = Service<T>> {
70
211
  * method call. For remove, update and patch context.id can also be null when
71
212
  * modifying multiple entries. In all other cases it will be undefined.
72
213
  */
73
- id?: string | number;
74
- /**
75
- * A read only property with the name of the service method (one of find, get,
76
- * create, update, patch, remove).
77
- */
78
- readonly method: 'find' | 'get' | 'create' | 'update' | 'patch' | 'remove';
214
+ id?: Id;
79
215
  /**
80
216
  * A writeable property that contains the service method parameters (including
81
217
  * params.query).
82
218
  */
83
219
  params: Params;
84
- /**
85
- * A read only property and contains the service name (or path) without leading or
86
- * trailing slashes.
87
- */
88
- readonly path: string;
89
220
  /**
90
221
  * A writeable property containing the result of the successful service method call.
91
222
  * It is only available in after hooks.
@@ -95,74 +226,44 @@ export interface HookContext<T = any, S = Service<T>> {
95
226
  * - A before hook to skip the actual service method (database) call
96
227
  * - An error hook to swallow the error and return a result instead
97
228
  */
98
- result?: T;
99
- /**
100
- * A read only property and contains the service this hook currently runs on.
101
- */
102
- readonly service: S;
229
+ result?: ServiceGenericType<S>;
103
230
  /**
104
231
  * A writeable, optional property and contains a 'safe' version of the data that
105
232
  * should be sent to any client. If context.dispatch has not been set context.result
106
233
  * will be sent to the client instead.
107
234
  */
108
- dispatch?: T;
235
+ dispatch?: ServiceGenericType<S>;
109
236
  /**
110
237
  * A writeable, optional property that allows to override the standard HTTP status
111
238
  * code that should be returned.
239
+ *
240
+ * @deprecated Use `http.statusCode` instead.
112
241
  */
113
242
  statusCode?: number;
114
243
  /**
115
- * A read only property with the hook type (one of before, after or error).
244
+ * A writeable, optional property that contains options specific to HTTP transports.
116
245
  */
117
- readonly type: 'before' | 'after' | 'error';
118
- event?: string;
119
- arguments: any[];
120
- }
121
- export interface HookMap<T = any> {
122
- all: Hook<T> | Hook<T>[];
123
- find: Hook<T> | Hook<T>[];
124
- get: Hook<T> | Hook<T>[];
125
- create: Hook<T> | Hook<T>[];
126
- update: Hook<T> | Hook<T>[];
127
- patch: Hook<T> | Hook<T>[];
128
- remove: Hook<T> | Hook<T>[];
129
- }
130
- export interface HooksObject<T = any> {
131
- before: Partial<HookMap<T>> | Hook<T> | Hook<T>[];
132
- after: Partial<HookMap<T>> | Hook<T> | Hook<T>[];
133
- error: Partial<HookMap<T>> | Hook<T> | Hook<T>[];
134
- async?: Partial<HookMap<T>> | Hook<T> | Hook<T>[];
135
- finally?: Partial<HookMap<T>> | Hook<T> | Hook<T>[];
136
- }
137
- export interface ServiceMethods<T> {
138
- [key: string]: any;
139
- find(params?: Params): Promise<T | T[]>;
140
- get(id: Id, params?: Params): Promise<T>;
141
- create(data: Partial<T> | Partial<T>[], params?: Params): Promise<T | T[]>;
142
- update(id: NullableId, data: T, params?: Params): Promise<T | T[]>;
143
- patch(id: NullableId, data: Partial<T>, params?: Params): Promise<T | T[]>;
144
- remove(id: NullableId, params?: Params): Promise<T | T[]>;
145
- }
146
- export interface SetupMethod {
147
- setup(app: Application, path: string): void;
148
- }
149
- export interface ServiceOverloads<T> {
150
- create?(data: Partial<T>, params?: Params): Promise<T>;
151
- create?(data: Partial<T>[], params?: Params): Promise<T[]>;
152
- update?(id: Id, data: T, params?: Params): Promise<T>;
153
- update?(id: null, data: T, params?: Params): Promise<T[]>;
154
- patch?(id: Id, data: Partial<T>, params?: Params): Promise<T>;
155
- patch?(id: null, data: Partial<T>, params?: Params): Promise<T[]>;
156
- remove?(id: Id, params?: Params): Promise<T>;
157
- remove?(id: null, params?: Params): Promise<T[]>;
158
- }
159
- export interface ServiceAddons<T> extends EventEmitter {
160
- id?: any;
161
- _serviceEvents: string[];
162
- methods: {
163
- [method: string]: string[];
164
- };
165
- hooks(hooks: Partial<HooksObject<T>>): this;
246
+ http?: Http;
247
+ /**
248
+ * The event emitted by this method. Can be set to `null` to skip event emitting.
249
+ */
250
+ event: string | null;
166
251
  }
167
- export declare type Service<T> = ServiceOverloads<T> & ServiceAddons<T> & ServiceMethods<T>;
168
- export declare type ServiceMixin = (service: Service<any>, path: string, options?: any) => void;
252
+ export declare type RegularHookFunction<A = Application, S = Service> = (this: S, context: HookContext<A, S>) => (Promise<HookContext<Application, S> | void> | HookContext<Application, S> | void);
253
+ export declare type Hook<A = Application, S = Service> = RegularHookFunction<A, S>;
254
+ declare type RegularHookMethodMap<A, S> = {
255
+ [L in keyof S]?: SelfOrArray<RegularHookFunction<A, S>>;
256
+ } & {
257
+ all?: SelfOrArray<RegularHookFunction<A, S>>;
258
+ };
259
+ declare type RegularHookTypeMap<A, S> = SelfOrArray<RegularHookFunction<A, S>> | RegularHookMethodMap<A, S>;
260
+ export declare type RegularHookMap<A, S> = {
261
+ before?: RegularHookTypeMap<A, S>;
262
+ after?: RegularHookTypeMap<A, S>;
263
+ error?: RegularHookTypeMap<A, S>;
264
+ };
265
+ export declare type HookFunction<A = Application, S = Service> = (context: HookContext<A, S>, next: NextFunction) => Promise<void>;
266
+ export declare type HookMap<A, S> = {
267
+ [L in keyof S]?: HookFunction<A, S>[];
268
+ };
269
+ export declare type HookOptions<A, S> = HookMap<A, S> | HookFunction<A, S>[] | RegularHookMap<A, S>;
@@ -0,0 +1,4 @@
1
+ import { EventEmitter } from 'events';
2
+ export * from '@feathersjs/commons';
3
+ export * from '@feathersjs/hooks';
4
+ export { EventEmitter };
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.EventEmitter = void 0;
14
+ const events_1 = require("events");
15
+ Object.defineProperty(exports, "EventEmitter", { enumerable: true, get: function () { return events_1.EventEmitter; } });
16
+ __exportStar(require("@feathersjs/commons"), exports);
17
+ __exportStar(require("@feathersjs/hooks"), exports);
18
+ //# 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 { HookContext, Service, Application } from './declarations';
2
- export declare function eventHook(): (ctx: HookContext) => void;
3
- export declare function eventMixin(this: Application, service: Service<any>): void;
4
- export default function (): (app: any) => void;
1
+ import { NextFunction } from './dependencies';
2
+ import { HookContext, FeathersService } from './declarations';
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>>>;
package/lib/events.js CHANGED
@@ -1,82 +1,29 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.eventMixin = exports.eventHook = void 0;
7
- // @ts-ignore
8
- const uberproto_1 = __importDefault(require("uberproto"));
9
- const events_1 = require("events");
10
- // Returns a hook that emits service events. Should always be
11
- // used as the very last hook in the chain
12
- function eventHook() {
13
- return function (ctx) {
14
- const { app, service, method, event, type, result } = ctx;
15
- const eventName = event === null ? event : app.eventMappings[method];
16
- const isHookEvent = service._hookEvents && service._hookEvents.indexOf(eventName) !== -1;
17
- // If this event is not being sent yet and we are not in an error hook
18
- if (eventName && isHookEvent && type !== 'error') {
19
- const results = Array.isArray(result) ? result : [result];
20
- results.forEach(element => service.emit(eventName, element, ctx));
4
+ const dependencies_1 = require("./dependencies");
5
+ const service_1 = require("./service");
6
+ function eventHook(context, next) {
7
+ const { events } = (0, service_1.getServiceOptions)(context.self);
8
+ const defaultEvent = service_1.defaultEventMap[context.method] || null;
9
+ context.event = defaultEvent;
10
+ return next().then(() => {
11
+ // Send the event only if the service does not do so already (indicated in the `events` option)
12
+ // This is used for custom events and for client services receiving event from the server
13
+ if (typeof context.event === 'string' && !events.includes(context.event)) {
14
+ const results = Array.isArray(context.result) ? context.result : [context.result];
15
+ results.forEach(element => context.self.emit(context.event, element, context));
21
16
  }
22
- };
17
+ });
23
18
  }
24
19
  exports.eventHook = eventHook;
25
- // Mixin that turns a service into a Node event emitter
26
20
  function eventMixin(service) {
27
- if (service._serviceEvents) {
28
- return;
29
- }
30
- const app = this;
31
- // Indicates if the service is already an event emitter
32
21
  const isEmitter = typeof service.on === 'function' &&
33
22
  typeof service.emit === 'function';
34
- // If not, mix it in (the service is always an Uberproto object that has a .mixin)
35
- if (typeof service.mixin === 'function' && !isEmitter) {
36
- service.mixin(events_1.EventEmitter.prototype);
23
+ if (!isEmitter) {
24
+ Object.assign(service, dependencies_1.EventEmitter.prototype);
37
25
  }
38
- // Define non-enumerable properties of
39
- Object.defineProperties(service, {
40
- // A list of all events that this service sends
41
- _serviceEvents: {
42
- value: Array.isArray(service.events) ? service.events.slice() : []
43
- },
44
- // A list of events that should be handled through the event hooks
45
- _hookEvents: {
46
- value: []
47
- }
48
- });
49
- // `app.eventMappings` has the mapping from method name to event name
50
- Object.keys(app.eventMappings).forEach(method => {
51
- const event = app.eventMappings[method];
52
- const alreadyEmits = service._serviceEvents.indexOf(event) !== -1;
53
- // Add events for known methods to _serviceEvents and _hookEvents
54
- // if the service indicated it does not send it itself yet
55
- if (typeof service[method] === 'function' && !alreadyEmits) {
56
- service._serviceEvents.push(event);
57
- service._hookEvents.push(event);
58
- }
59
- });
26
+ return service;
60
27
  }
61
28
  exports.eventMixin = eventMixin;
62
- function default_1() {
63
- return function (app) {
64
- // Mappings from service method to event name
65
- Object.assign(app, {
66
- eventMappings: {
67
- create: 'created',
68
- update: 'updated',
69
- remove: 'removed',
70
- patch: 'patched'
71
- }
72
- });
73
- // Register the event hook
74
- // `finally` hooks always run last after `error` and `after` hooks
75
- app.hooks({ finally: eventHook() });
76
- // Make the app an event emitter
77
- uberproto_1.default.mixin(events_1.EventEmitter.prototype, app);
78
- app.mixins.push(eventMixin);
79
- };
80
- }
81
- exports.default = default_1;
82
29
  //# sourceMappingURL=events.js.map
package/lib/events.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"events.js","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":";;;;;;AAAA,aAAa;AACb,0DAA8B;AAC9B,mCAAsC;AAGtC,6DAA6D;AAC7D,0CAA0C;AAC1C,SAAgB,SAAS;IACvB,OAAO,UAAU,GAAgB;QAC/B,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC;QAE1D,MAAM,SAAS,GAAG,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAE,GAAW,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;QAC9E,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;QAEzF,sEAAsE;QACtE,IAAI,SAAS,IAAI,WA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IAEtE,OAAO,CAAC,KAAK,GAAG,YAAY,CAAC;IAE7B,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,CAAE,OAAO,CAAC,MAAM,CAAE,CAAC;YAEpF,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAE,OAAe,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;SACzF;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAfD,8BAeC;AAED,SAAgB,UAAU,CAAK,OAA2B;IACxD,MAAM,SAAS,GAAG,OAAO,OAAO,CAAC,EAAE,KAAK,UAAU;QAChD,OAAO,OAAO,CAAC,IAAI,KAAK,UAAU,CAAC;IAErC,IAAI,CAAC,SAAS,EAAE;QACd,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,2BAAY,CAAC,SAAS,CAAC,CAAC;KAChD;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AATD,gCASC"}
@@ -1,2 +1,13 @@
1
- export default function (): (app: any) => void;
2
- export declare function activateHooks(args: any[]): (fn: any) => any;
1
+ import { HookContextData, HookManager, Middleware } from '../dependencies';
2
+ import { Service, ServiceOptions, HookContext, FeathersService, Application } from '../declarations';
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>;
5
+ export declare class FeathersHookManager<A> extends HookManager {
6
+ app: A;
7
+ method: string;
8
+ constructor(app: A, method: string);
9
+ collectMiddleware(self: any, args: any[]): Middleware[];
10
+ initializeContext(self: any, args: any[], context: HookContext): import("@feathersjs/hooks/lib/base").HookContext<any, any>;
11
+ middleware(mw: Middleware[]): this;
12
+ }
13
+ export declare function hookMixin<A>(this: A, service: FeathersService<A>, path: string, options: ServiceOptions): FeathersService<A, Service<any, Partial<any>>>;