@feathersjs/feathers 5.0.0-pre.20 → 5.0.0-pre.23

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 CHANGED
@@ -3,6 +3,40 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [5.0.0-pre.23](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.22...v5.0.0-pre.23) (2022-06-06)
7
+
8
+
9
+ ### Features
10
+
11
+ * **client:** Improve client side custom method support ([#2654](https://github.com/feathersjs/feathers/issues/2654)) ([c138acf](https://github.com/feathersjs/feathers/commit/c138acf50affbe6b66177d084d3c7a3e9220f09f))
12
+ * **core:** Rename async hooks to around hooks, allow usual registration format ([#2652](https://github.com/feathersjs/feathers/issues/2652)) ([2a485a0](https://github.com/feathersjs/feathers/commit/2a485a07929184261f27437fc0fdfe5a44694834))
13
+
14
+
15
+
16
+
17
+
18
+ # [5.0.0-pre.22](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.21...v5.0.0-pre.22) (2022-05-24)
19
+
20
+
21
+ ### Bug Fixes
22
+
23
+ * **schema:** Allows resolveData with different resolvers based on method ([#2644](https://github.com/feathersjs/feathers/issues/2644)) ([be71fa2](https://github.com/feathersjs/feathers/commit/be71fa2fe260e05b7dcc0d5f439e33f2e9ec2434))
24
+
25
+
26
+
27
+
28
+
29
+ # [5.0.0-pre.21](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.20...v5.0.0-pre.21) (2022-05-23)
30
+
31
+
32
+ ### Bug Fixes
33
+
34
+ * **core:** Do not throw missing method error for regular hook methods ([#2636](https://github.com/feathersjs/feathers/issues/2636)) ([afe9a3b](https://github.com/feathersjs/feathers/commit/afe9a3b3d49897eff045ee237ca2937a6b975291))
35
+
36
+
37
+
38
+
39
+
6
40
  # [5.0.0-pre.20](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.19...v5.0.0-pre.20) (2022-05-04)
7
41
 
8
42
 
@@ -1,14 +1,13 @@
1
1
  /// <reference types="node" />
2
- import { EventEmitter } from './dependencies';
3
- import { FeathersApplication, ServiceMixin, Service, ServiceOptions, ServiceInterface, Application, FeathersService, HookMap, ApplicationHookOptions } from './declarations';
2
+ import { EventEmitter } from 'events';
3
+ import { FeathersApplication, ServiceMixin, Service, ServiceOptions, ServiceInterface, Application, FeathersService, ApplicationHookOptions } from './declarations';
4
4
  export declare class Feathers<Services, Settings> extends EventEmitter implements FeathersApplication<Services, Settings> {
5
5
  services: Services;
6
6
  settings: Settings;
7
7
  mixins: ServiceMixin<Application<Services, Settings>>[];
8
8
  version: string;
9
9
  _isSetup: boolean;
10
- appHooks: HookMap<Application<Services, Settings>, any>;
11
- private regularHooks;
10
+ protected registerHooks: (this: any, allHooks: any) => any;
12
11
  constructor();
13
12
  get<L extends keyof Settings & string>(name: L): Settings[L];
14
13
  set<L extends keyof Settings & string>(name: L, value: Settings[L]): this;
@@ -5,32 +5,34 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Feathers = void 0;
7
7
  const version_1 = __importDefault(require("./version"));
8
- const dependencies_1 = require("./dependencies");
9
- const events_1 = require("./events");
10
- const index_1 = require("./hooks/index");
8
+ const events_1 = require("events");
9
+ const commons_1 = require("@feathersjs/commons");
10
+ const hooks_1 = require("@feathersjs/hooks");
11
+ const events_2 = require("./events");
12
+ const hooks_2 = require("./hooks");
11
13
  const service_1 = require("./service");
12
- const regular_1 = require("./hooks/regular");
13
- const debug = (0, dependencies_1.createDebug)('@feathersjs/feathers');
14
- class Feathers extends dependencies_1.EventEmitter {
14
+ const hooks_3 = require("./hooks");
15
+ const debug = (0, commons_1.createDebug)('@feathersjs/feathers');
16
+ class Feathers extends events_1.EventEmitter {
15
17
  constructor() {
16
18
  super();
17
19
  this.services = {};
18
20
  this.settings = {};
19
- this.mixins = [index_1.hookMixin, events_1.eventMixin];
21
+ this.mixins = [hooks_2.hookMixin, events_2.eventMixin];
20
22
  this.version = version_1.default;
21
23
  this._isSetup = false;
22
- this.appHooks = {
23
- [dependencies_1.HOOKS]: [events_1.eventHook]
24
- };
25
- this.regularHooks = (0, regular_1.enableRegularHooks)(this);
26
- (0, dependencies_1.hooks)(this, {
27
- setup: (0, dependencies_1.middleware)().params('server').props({
24
+ (0, hooks_1.hooks)(this, {
25
+ setup: (0, hooks_1.middleware)().params('server').props({
28
26
  app: this
29
27
  }),
30
- teardown: (0, dependencies_1.middleware)().params('server').props({
28
+ teardown: (0, hooks_1.middleware)().params('server').props({
31
29
  app: this
32
30
  })
33
31
  });
32
+ this.registerHooks = (0, hooks_3.enableHooks)(this);
33
+ this.registerHooks({
34
+ around: [events_2.eventHook]
35
+ });
34
36
  }
35
37
  get(name) {
36
38
  return this.settings[name];
@@ -47,7 +49,7 @@ class Feathers extends dependencies_1.EventEmitter {
47
49
  throw new Error(`Can not find service '${location}'`);
48
50
  }
49
51
  service(location) {
50
- const path = ((0, dependencies_1.stripSlashes)(location) || '/');
52
+ const path = ((0, commons_1.stripSlashes)(location) || '/');
51
53
  const current = this.services[path];
52
54
  if (typeof current === 'undefined') {
53
55
  this.use(path, this.defaultService(path));
@@ -59,11 +61,11 @@ class Feathers extends dependencies_1.EventEmitter {
59
61
  if (typeof path !== 'string') {
60
62
  throw new Error(`'${path}' is not a valid service path.`);
61
63
  }
62
- const location = ((0, dependencies_1.stripSlashes)(path) || '/');
64
+ const location = ((0, commons_1.stripSlashes)(path) || '/');
63
65
  const subApp = service;
64
66
  const isSubApp = typeof subApp.service === 'function' && subApp.services;
65
67
  if (isSubApp) {
66
- Object.keys(subApp.services).forEach(subPath => this.use(`${location}/${subPath}`, subApp.service(subPath)));
68
+ Object.keys(subApp.services).forEach((subPath) => this.use(`${location}/${subPath}`, subApp.service(subPath)));
67
69
  return this;
68
70
  }
69
71
  const protoService = (0, service_1.wrapService)(location, service, options);
@@ -75,7 +77,7 @@ class Feathers extends dependencies_1.EventEmitter {
75
77
  }
76
78
  debug(`Registering new service at \`${location}\``);
77
79
  // Add all the mixins
78
- this.mixins.forEach(fn => fn.call(this, protoService, location, serviceOptions));
80
+ this.mixins.forEach((fn) => fn.call(this, protoService, location, serviceOptions));
79
81
  this.services[location] = protoService;
80
82
  // If we ran setup already, set this service up explicitly, this will not `await`
81
83
  if (this._isSetup && typeof protoService.setup === 'function') {
@@ -86,45 +88,45 @@ class Feathers extends dependencies_1.EventEmitter {
86
88
  }
87
89
  hooks(hookMap) {
88
90
  const untypedMap = hookMap;
89
- if (untypedMap.before || untypedMap.after || untypedMap.error) {
90
- this.regularHooks(untypedMap);
91
+ if (untypedMap.before || untypedMap.after || untypedMap.error || untypedMap.around) {
92
+ // regular hooks for all service methods
93
+ this.registerHooks(untypedMap);
91
94
  }
92
95
  else if (untypedMap.setup || untypedMap.teardown) {
93
- (0, dependencies_1.hooks)(this, untypedMap);
94
- }
95
- else if (Array.isArray(hookMap)) {
96
- this.appHooks[dependencies_1.HOOKS].push(...hookMap);
96
+ // .setup and .teardown application hooks
97
+ (0, hooks_1.hooks)(this, untypedMap);
97
98
  }
98
99
  else {
99
- const methodHookMap = hookMap;
100
- Object.keys(methodHookMap).forEach(key => {
101
- const methodHooks = this.appHooks[key] || [];
102
- this.appHooks[key] = methodHooks.concat(methodHookMap[key]);
100
+ // Other registration formats are just `around` hooks
101
+ this.registerHooks({
102
+ around: untypedMap
103
103
  });
104
104
  }
105
105
  return this;
106
106
  }
107
107
  setup() {
108
108
  this._isSetup = true;
109
- return Object.keys(this.services).reduce((current, path) => current
110
- .then(() => {
109
+ return Object.keys(this.services)
110
+ .reduce((current, path) => current.then(() => {
111
111
  const service = this.service(path);
112
112
  if (typeof service.setup === 'function') {
113
113
  debug(`Setting up service for \`${path}\``);
114
114
  return service.setup(this, path);
115
115
  }
116
- }), Promise.resolve()).then(() => this);
116
+ }), Promise.resolve())
117
+ .then(() => this);
117
118
  }
118
119
  teardown() {
119
120
  this._isSetup = false;
120
- return Object.keys(this.services).reduce((current, path) => current
121
- .then(() => {
121
+ return Object.keys(this.services)
122
+ .reduce((current, path) => current.then(() => {
122
123
  const service = this.service(path);
123
124
  if (typeof service.teardown === 'function') {
124
125
  debug(`Tearing down service for \`${path}\``);
125
126
  return service.teardown(this, path);
126
127
  }
127
- }), Promise.resolve()).then(() => this);
128
+ }), Promise.resolve())
129
+ .then(() => this);
128
130
  }
129
131
  }
130
132
  exports.Feathers = Feathers;
@@ -1 +1 @@
1
- {"version":3,"file":"application.js","sourceRoot":"","sources":["../src/application.ts"],"names":[],"mappings":";;;;;;AAAA,wDAAgC;AAChC,iDAEwB;AACxB,qCAAiD;AACjD,yCAA0C;AAC1C,uCAA6E;AAY7E,6CAAqD;AAErD,MAAM,KAAK,GAAG,IAAA,0BAAW,EAAC,sBAAsB,CAAC,CAAC;AAElD,MAAa,QAA6B,SAAQ,2BAAY;IAY5D;QACE,KAAK,EAAE,CAAC;QAZV,aAAQ,GAAc,EAAe,CAAC;QACtC,aAAQ,GAAc,EAAe,CAAC;QACtC,WAAM,GAAoD,CAAE,iBAAS,EAAE,mBAAU,CAAE,CAAC;QACpF,YAAO,GAAW,iBAAO,CAAC;QAC1B,aAAQ,GAAG,KAAK,CAAC;QACjB,aAAQ,GAAkD;YACxD,CAAC,oBAAK,CAAC,EAAE,CAAG,kBAAiB,CAAE;SAChC,CAAC;QAMA,IAAI,CAAC,YAAY,GAAG,IAAA,4BAAkB,EAAC,IAAI,CAAC,CAAC;QAC7C,IAAA,oBAAK,EAAC,IAAI,EAAE;YACV,KAAK,EAAE,IAAA,yBAAU,GAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC;gBACzC,GAAG,EAAE,IAAI;aACV,CAAC;YACF,QAAQ,EAAE,IAAA,yBAAU,GAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC;gBAC5C,GAAG,EAAE,IAAI;aACV,CA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OAAO,CAAC,KAAK,KAAK,UAAU,EAAE;gBACvC,KAAK,CAAC,4BAA4B,IAAI,IAAI,CAAC,CAAA;gBAE3C,OAAO,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;aACjC;QACH,CAAC,CAAC,EACJ,OAAO,CAAC,OAAO,EAAE,CAClB;aACA,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAA;IACrB,CAAC;IAED,QAAQ;QACN,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAA;QAErB,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;aAC9B,MAAM,CACL,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,CAChB,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE;YAChB,MAAM,OAAO,GAAQ,IAAI,CAAC,OAAO,CAAC,IAAW,CAAC,CAAA;YAE9C,IAAI,OAAO,OAAO,CAAC,QAAQ,KAAK,UAAU,EAAE;gBAC1C,KAAK,CAAC,8BAA8B,IAAI,IAAI,CAAC,CAAA;gBAE7C,OAAO,OAAO,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;aACpC;QACH,CAAC,CAAC,EACJ,OAAO,CAAC,OAAO,EAAE,CAClB;aACA,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAA;IACrB,CAAC;CACF;AArKD,4BAqKC"}
@@ -1,5 +1,6 @@
1
1
  /// <reference types="node" />
2
- import { EventEmitter, NextFunction, HookContext as BaseHookContext } from './dependencies';
2
+ import { EventEmitter } from 'events';
3
+ import { NextFunction, HookContext as BaseHookContext } from '@feathersjs/hooks';
3
4
  declare type SelfOrArray<S> = S | S[];
4
5
  declare type OptionalPick<T, K extends PropertyKey> = Pick<T, Extract<keyof T, K>>;
5
6
  export type { NextFunction };
@@ -56,6 +57,7 @@ export declare type CustomMethods<T extends {
56
57
  }> = {
57
58
  [K in keyof T]: (data: T[K][0], params?: Params) => Promise<T[K][1]>;
58
59
  };
60
+ export declare type CustomMethod<T = any, R = T, P extends Params = Params> = (data: T, params?: P) => Promise<R>;
59
61
  export declare type ServiceMixin<A> = (service: FeathersService<A>, path: string, options: ServiceOptions) => void;
60
62
  export declare type ServiceGenericType<S> = S extends ServiceInterface<infer T> ? T : any;
61
63
  export declare type ServiceGenericData<S> = S extends ServiceInterface<infer _T, infer D> ? D : any;
@@ -85,10 +87,6 @@ export interface FeathersApplication<Services = any, Settings = any> {
85
87
  * A private-ish indicator if `app.setup()` has been called already
86
88
  */
87
89
  _isSetup: boolean;
88
- /**
89
- * Contains all registered application level hooks.
90
- */
91
- appHooks: HookMap<Application<Services, Settings>, any>;
92
90
  /**
93
91
  * Retrieve an application setting by name
94
92
  *
@@ -270,24 +268,27 @@ export interface HookContext<A = Application, S = any> extends BaseHookContext<S
270
268
  */
271
269
  event: string | null;
272
270
  }
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>>;
271
+ export declare type HookFunction<A = Application, S = Service> = (this: S, context: HookContext<A, S>) => Promise<HookContext<Application, S> | void> | HookContext<Application, S> | void;
272
+ export declare type Hook<A = Application, S = Service> = HookFunction<A, S>;
273
+ declare type HookMethodMap<A, S> = {
274
+ [L in keyof S]?: SelfOrArray<HookFunction<A, S>>;
277
275
  } & {
278
- all?: SelfOrArray<RegularHookFunction<A, S>>;
276
+ all?: SelfOrArray<HookFunction<A, S>>;
279
277
  };
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>;
278
+ declare type HookTypeMap<A, S> = SelfOrArray<HookFunction<A, S>> | HookMethodMap<A, S>;
279
+ export declare type AroundHookFunction<A = Application, S = Service> = (context: HookContext<A, S>, next: NextFunction) => Promise<void>;
280
+ export declare type AroundHookMap<A, S> = {
281
+ [L in keyof S]?: AroundHookFunction<A, S>[];
282
+ } & {
283
+ all?: AroundHookFunction<A, S>[];
285
284
  };
286
- export declare type HookFunction<A = Application, S = Service> = (context: HookContext<A, S>, next: NextFunction) => Promise<void>;
287
285
  export declare type HookMap<A, S> = {
288
- [L in keyof S]?: HookFunction<A, S>[];
286
+ around?: AroundHookMap<A, S>;
287
+ before?: HookTypeMap<A, S>;
288
+ after?: HookTypeMap<A, S>;
289
+ error?: HookTypeMap<A, S>;
289
290
  };
290
- export declare type HookOptions<A, S> = HookMap<A, S> | HookFunction<A, S>[] | RegularHookMap<A, S>;
291
+ export declare type HookOptions<A, S> = AroundHookMap<A, S> | AroundHookFunction<A, S>[] | HookMap<A, S>;
291
292
  export interface ApplicationHookContext<A = Application> extends BaseHookContext {
292
293
  app: A;
293
294
  server: any;
package/lib/events.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { NextFunction } from './dependencies';
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
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,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.eventMixin = exports.eventHook = void 0;
4
- const dependencies_1 = require("./dependencies");
4
+ const events_1 = require("events");
5
5
  const service_1 = require("./service");
6
6
  function eventHook(context, next) {
7
7
  const { events } = (0, service_1.getServiceOptions)(context.self);
@@ -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, dependencies_1.EventEmitter.prototype);
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,iDAA4D;AAE5D,uCAA+D;AAE/D,SAAgB,SAAS,CAAE,OAAoB,EAAE,IAAkB;IACjE,MAAM,EAAE,MAAM,EAAE,GAAG,IAAA,2BAAiB,EAAE,OAAe,CAAC,IAAI,CAAC,CAAC;IAC5D,MAAM,YAAY,GAAI,yBAAuB,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC;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,CAA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AAE,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,17 @@
1
+ import { HookContextData, HookManager, Middleware } from '@feathersjs/hooks';
2
+ import { Service, ServiceOptions, HookContext, FeathersService, HookMap, AroundHookFunction, HookFunction } from './declarations';
3
+ export declare function collectHooks(target: any, method: string): any;
4
+ export declare function convertHookData(input: any): {
5
+ [method: string]: HookFunction<import("./declarations").Application<any, any>, Service<any, Partial<any>, import("./declarations").Params<import("./declarations").Query>>>[] | AroundHookFunction<import("./declarations").Application<any, any>, Service<any, Partial<any>, import("./declarations").Params<import("./declarations").Query>>>[];
6
+ };
7
+ export declare function enableHooks(object: any, methods?: string[]): (this: any, input: HookMap<any, any>) => any;
8
+ export declare function createContext(service: Service, method: string, data?: HookContextData): HookContext<import("./declarations").Application<any, any>, any>;
9
+ export declare class FeathersHookManager<A> extends HookManager {
10
+ app: A;
11
+ method: string;
12
+ constructor(app: A, method: string);
13
+ collectMiddleware(self: any, args: any[]): Middleware[];
14
+ initializeContext(self: any, args: any[], context: HookContext): import("@feathersjs/hooks").HookContext<any, any>;
15
+ middleware(mw: Middleware[]): this;
16
+ }
17
+ 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.js ADDED
@@ -0,0 +1,169 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hookMixin = exports.FeathersHookManager = exports.createContext = exports.enableHooks = exports.convertHookData = exports.collectHooks = void 0;
4
+ const hooks_1 = require("@feathersjs/hooks");
5
+ const service_1 = require("./service");
6
+ function collectHooks(target, method) {
7
+ return target.__hooks.hooks[method] || [];
8
+ }
9
+ exports.collectHooks = collectHooks;
10
+ // Converts different hook registration formats into the
11
+ // same internal format
12
+ function convertHookData(input) {
13
+ const result = {};
14
+ if (Array.isArray(input)) {
15
+ result.all = input;
16
+ }
17
+ else if (typeof input !== 'object') {
18
+ result.all = [input];
19
+ }
20
+ else {
21
+ for (const key of Object.keys(input)) {
22
+ const value = input[key];
23
+ result[key] = Array.isArray(value) ? value : [value];
24
+ }
25
+ }
26
+ return result;
27
+ }
28
+ exports.convertHookData = convertHookData;
29
+ const types = ['before', 'after', 'error', 'around'];
30
+ const isType = (value) => types.includes(value);
31
+ const createMap = (input, methods) => {
32
+ const map = {};
33
+ Object.keys(input).forEach((type) => {
34
+ if (!isType(type)) {
35
+ throw new Error(`'${type}' is not a valid hook type`);
36
+ }
37
+ const data = convertHookData(input[type]);
38
+ Object.keys(data).forEach((method) => {
39
+ if (method !== 'all' && !methods.includes(method) && !service_1.defaultServiceMethods.includes(method)) {
40
+ throw new Error(`'${method}' is not a valid hook method`);
41
+ }
42
+ });
43
+ map[type] = data;
44
+ });
45
+ return map;
46
+ };
47
+ const updateStore = (store, map) => Object.keys(store.hooks).forEach((method) => {
48
+ Object.keys(map).forEach((key) => {
49
+ var _a;
50
+ const type = key;
51
+ const allHooks = map[type].all || [];
52
+ const methodHooks = map[type][method] || [];
53
+ if (allHooks.length || methodHooks.length) {
54
+ const list = [...allHooks, ...methodHooks];
55
+ const hooks = ((_a = store[type])[method] || (_a[method] = []));
56
+ hooks.push(...list);
57
+ }
58
+ });
59
+ const collected = (0, hooks_1.collect)({
60
+ before: store.before[method] || [],
61
+ after: store.after[method] || [],
62
+ error: store.error[method] || []
63
+ });
64
+ store.hooks[method] = [...(store.around[method] || []), collected];
65
+ });
66
+ // Add `.hooks` functionality to an object
67
+ function enableHooks(object, methods = service_1.defaultServiceMethods) {
68
+ const store = {
69
+ around: {},
70
+ before: {},
71
+ after: {},
72
+ error: {},
73
+ hooks: {}
74
+ };
75
+ for (const method of methods) {
76
+ store.hooks[method] = [];
77
+ }
78
+ Object.defineProperty(object, '__hooks', {
79
+ configurable: true,
80
+ value: store,
81
+ writable: true
82
+ });
83
+ return function registerHooks(input) {
84
+ const store = this.__hooks;
85
+ const map = createMap(input, methods);
86
+ updateStore(store, map);
87
+ return this;
88
+ };
89
+ }
90
+ exports.enableHooks = enableHooks;
91
+ function createContext(service, method, data = {}) {
92
+ const createContext = service[method].createContext;
93
+ if (typeof createContext !== 'function') {
94
+ throw new Error(`Can not create context for method ${method}`);
95
+ }
96
+ return createContext(data);
97
+ }
98
+ exports.createContext = createContext;
99
+ class FeathersHookManager extends hooks_1.HookManager {
100
+ constructor(app, method) {
101
+ super();
102
+ this.app = app;
103
+ this.method = method;
104
+ this._middleware = [];
105
+ }
106
+ collectMiddleware(self, args) {
107
+ const appHooks = collectHooks(this.app, this.method);
108
+ const middleware = super.collectMiddleware(self, args);
109
+ const methodHooks = collectHooks(self, this.method);
110
+ return [...appHooks, ...middleware, ...methodHooks];
111
+ }
112
+ initializeContext(self, args, context) {
113
+ const ctx = super.initializeContext(self, args, context);
114
+ ctx.params = ctx.params || {};
115
+ return ctx;
116
+ }
117
+ middleware(mw) {
118
+ this._middleware.push(...mw);
119
+ return this;
120
+ }
121
+ }
122
+ exports.FeathersHookManager = FeathersHookManager;
123
+ function hookMixin(service, path, options) {
124
+ if (typeof service.hooks === 'function') {
125
+ return service;
126
+ }
127
+ const hookMethods = (0, service_1.getHookMethods)(service, options);
128
+ const serviceMethodHooks = hookMethods.reduce((res, method) => {
129
+ const params = service_1.defaultServiceArguments[method] || ['data', 'params'];
130
+ res[method] = new FeathersHookManager(this, method).params(...params).props({
131
+ app: this,
132
+ path,
133
+ method,
134
+ service,
135
+ event: null,
136
+ type: null,
137
+ get statusCode() {
138
+ var _a;
139
+ return (_a = this.http) === null || _a === void 0 ? void 0 : _a.status;
140
+ },
141
+ set statusCode(value) {
142
+ this.http = this.http || {};
143
+ this.http.status = value;
144
+ }
145
+ });
146
+ return res;
147
+ }, {});
148
+ const registerHooks = enableHooks(service, hookMethods);
149
+ (0, hooks_1.hooks)(service, serviceMethodHooks);
150
+ service.hooks = function (hookOptions) {
151
+ if (hookOptions.before || hookOptions.after || hookOptions.error || hookOptions.around) {
152
+ return registerHooks.call(this, hookOptions);
153
+ }
154
+ if (Array.isArray(hookOptions)) {
155
+ return (0, hooks_1.hooks)(this, hookOptions);
156
+ }
157
+ Object.keys(hookOptions).forEach((method) => {
158
+ const manager = (0, hooks_1.getManager)(this[method]);
159
+ if (!(manager instanceof FeathersHookManager)) {
160
+ throw new Error(`Method ${method} is not a Feathers hooks enabled service method`);
161
+ }
162
+ manager.middleware(hookOptions[method]);
163
+ });
164
+ return this;
165
+ };
166
+ return service;
167
+ }
168
+ exports.hookMixin = hookMixin;
169
+ //# sourceMappingURL=hooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks.js","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":";;;AAAA,6CAQ0B;AAU1B,uCAA0F;AAE1F,SAAgB,YAAY,CAAC,MAAW,EAAE,MAAc;IACtD,OAAO,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,CAAA;AAC3C,CAAC;AAFD,oCAEC;AAED,wDAAwD;AACxD,uBAAuB;AACvB,SAAgB,eAAe,CAAC,KAAU;IACxC,MAAM,MAAM,GAAgE,EAAE,CAAA;IAE9E,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;QACxB,MAAM,CAAC,GAA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,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;YAC1C,MAAM,OAAO,GAAG,IAAA,kBAAU,EAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAA;YAExC,IAAI,CAAC,CAAC,OAAO,YAAY,mBAAmB,CAAC,EAAE;gBAC7C,MAAM,IAAI,KAAK,CAAC,UAAU,MAAM,iDAAiD,CAAC,CAAA;aACnF;YAED,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAA;QACzC,CAAC,CAAC,CAAA;QAEF,OAAO,IAAI,CAAA;IACb,CAAC,CAAA;IAED,OAAO,OAAO,CAAA;AAChB,CAAC;AAxDD,8BAwDC"}
package/lib/index.d.ts CHANGED
@@ -3,9 +3,9 @@ import { Feathers } from './application';
3
3
  import { Application } from './declarations';
4
4
  export declare function feathers<T = any, S = any>(): Application<T, S>;
5
5
  export declare namespace feathers {
6
- var setDebug: typeof import("@feathersjs/commons/lib/debug").setDebug;
6
+ var setDebug: typeof import("@feathersjs/commons").setDebug;
7
7
  }
8
8
  export { version, Feathers };
9
- export * from './hooks/index';
9
+ export * from './hooks';
10
10
  export * from './declarations';
11
11
  export * from './service';
package/lib/index.js CHANGED
@@ -18,7 +18,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
20
  exports.Feathers = exports.version = exports.feathers = void 0;
21
- const dependencies_1 = require("./dependencies");
21
+ const commons_1 = require("@feathersjs/commons");
22
22
  const version_1 = __importDefault(require("./version"));
23
23
  exports.version = version_1.default;
24
24
  const application_1 = require("./application");
@@ -27,8 +27,8 @@ function feathers() {
27
27
  return new application_1.Feathers();
28
28
  }
29
29
  exports.feathers = feathers;
30
- feathers.setDebug = dependencies_1.setDebug;
31
- __exportStar(require("./hooks/index"), exports);
30
+ feathers.setDebug = commons_1.setDebug;
31
+ __exportStar(require("./hooks"), exports);
32
32
  __exportStar(require("./declarations"), exports);
33
33
  __exportStar(require("./service"), exports);
34
34
  if (typeof module !== 'undefined') {
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,iDAA0C;AAC1C,wDAAgC;AAUvB,kBAVF,iBAAO,CAUE;AAThB,+CAAyC;AASvB,yFATT,sBAAQ,OASS;AAN1B,SAAgB,QAAQ;IACtB,OAAO,IAAI,sBAAQ,EAA6B,CAAC;AACnD,CAAC;AAFD,4BAEC;AAED,QAAQ,CAAC,QAAQ,GAAG,uBAAQ,CAAC;AAG7B,gDAA8B;AAC9B,iDAA+B;AAC/B,4CAA0B;AAE1B,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;IACjC,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;CAC1D"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,iDAA8C;AAE9C,wDAA+B;AAUtB,kBAVF,iBAAO,CAUE;AAThB,+CAAwC;AAStB,yFATT,sBAAQ,OASS;AAN1B,SAAgB,QAAQ;IACtB,OAAO,IAAI,sBAAQ,EAA6B,CAAA;AAClD,CAAC;AAFD,4BAEC;AAED,QAAQ,CAAC,QAAQ,GAAG,kBAAQ,CAAA;AAG5B,0CAAuB;AACvB,iDAA8B;AAC9B,4CAAyB;AAEzB,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;IACjC,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,OAAO,CAAC,CAAA;CACzD"}
package/lib/service.js CHANGED
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.wrapService = exports.getServiceOptions = exports.getHookMethods = exports.protectedMethods = exports.defaultEventMap = exports.defaultServiceMethods = exports.defaultServiceArguments = exports.SERVICE = void 0;
4
- const dependencies_1 = require("./dependencies");
5
- exports.SERVICE = (0, dependencies_1.createSymbol)('@feathersjs/service');
4
+ const events_1 = require("events");
5
+ const commons_1 = require("@feathersjs/commons");
6
+ exports.SERVICE = (0, commons_1.createSymbol)('@feathersjs/service');
6
7
  exports.defaultServiceArguments = {
7
8
  find: ['params'],
8
9
  get: ['id', 'params'],
@@ -19,20 +20,13 @@ exports.defaultEventMap = {
19
20
  remove: 'removed'
20
21
  };
21
22
  exports.protectedMethods = Object.keys(Object.prototype)
22
- .concat(Object.keys(dependencies_1.EventEmitter.prototype))
23
- .concat([
24
- 'all',
25
- 'before',
26
- 'after',
27
- 'error',
28
- 'hooks',
29
- 'setup',
30
- 'teardown',
31
- 'publish'
32
- ]);
23
+ .concat(Object.keys(events_1.EventEmitter.prototype))
24
+ .concat(['all', 'around', 'before', 'after', 'error', 'hooks', 'setup', 'teardown', 'publish']);
33
25
  function getHookMethods(service, options) {
34
26
  const { methods } = options;
35
- return exports.defaultServiceMethods.filter(m => typeof service[m] === 'function' && !methods.includes(m)).concat(methods);
27
+ return exports.defaultServiceMethods
28
+ .filter((m) => typeof service[m] === 'function' && !methods.includes(m))
29
+ .concat(methods);
36
30
  }
37
31
  exports.getHookMethods = getHookMethods;
38
32
  function getServiceOptions(service, options = {}) {
@@ -40,7 +34,7 @@ function getServiceOptions(service, options = {}) {
40
34
  if (existingOptions) {
41
35
  return existingOptions;
42
36
  }
43
- const { methods = exports.defaultServiceMethods.filter(method => typeof service[method] === 'function'), events = service.events || [] } = options;
37
+ const { methods = exports.defaultServiceMethods.filter((method) => typeof service[method] === 'function'), events = service.events || [] } = options;
44
38
  const { serviceEvents = Object.values(exports.defaultEventMap).concat(events) } = options;
45
39
  return {
46
40
  ...options,