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

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,45 @@
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.18](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.17...v5.0.0-pre.18) (2022-04-11)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **core:** Ensure that dynamically registered services are always set up ([#2593](https://github.com/feathersjs/feathers/issues/2593)) ([27cc7d0](https://github.com/feathersjs/feathers/commit/27cc7d08321861cd69e6b66e1fdfa43c50664820))
12
+
13
+
14
+ ### Features
15
+
16
+ * **authentication:** Add setup method for auth strategies ([#1611](https://github.com/feathersjs/feathers/issues/1611)) ([a3c3581](https://github.com/feathersjs/feathers/commit/a3c35814dccdbbf6de96f04f60b226ce206c6dbe))
17
+ * **core:** Add app.setup and app.teardown hook support ([#2585](https://github.com/feathersjs/feathers/issues/2585)) ([ae4ebee](https://github.com/feathersjs/feathers/commit/ae4ebee5d39957651473007c4d3adb210160e040))
18
+ * **core:** Add app.teardown functionality ([#2570](https://github.com/feathersjs/feathers/issues/2570)) ([fcdf524](https://github.com/feathersjs/feathers/commit/fcdf524ae1995bb59265d39f12e98b7794bed023))
19
+ * **core:** Finalize app.teardown() functionality ([#2584](https://github.com/feathersjs/feathers/issues/2584)) ([1a166f3](https://github.com/feathersjs/feathers/commit/1a166f3ded811ecacf0ae8cb67880bc9fa2eeafa))
20
+ * **transport-commons:** add `context.http.response` ([#2524](https://github.com/feathersjs/feathers/issues/2524)) ([5bc9d44](https://github.com/feathersjs/feathers/commit/5bc9d447043c2e2b742c73ed28ecf3b3264dd9e5))
21
+
22
+
23
+
24
+
25
+
26
+ # [5.0.0-pre.17](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.16...v5.0.0-pre.17) (2022-02-15)
27
+
28
+ **Note:** Version bump only for package @feathersjs/feathers
29
+
30
+
31
+
32
+
33
+
34
+ # [5.0.0-pre.16](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.15...v5.0.0-pre.16) (2022-01-12)
35
+
36
+
37
+ ### Features
38
+
39
+ * **express, koa:** make transports similar ([#2486](https://github.com/feathersjs/feathers/issues/2486)) ([26aa937](https://github.com/feathersjs/feathers/commit/26aa937c114fb8596dfefc599b1f53cead69c159))
40
+
41
+
42
+
43
+
44
+
6
45
  # [5.0.0-pre.15](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.14...v5.0.0-pre.15) (2021-11-27)
7
46
 
8
47
 
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2021 Feathers
3
+ Copyright (c) 2022 Feathers
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -6,6 +6,7 @@
6
6
  [![Maintainability](https://api.codeclimate.com/v1/badges/cb5ec42a2d0cc1a47a02/maintainability)](https://codeclimate.com/github/feathersjs/feathers/maintainability)
7
7
  [![Test Coverage](https://api.codeclimate.com/v1/badges/cb5ec42a2d0cc1a47a02/test_coverage)](https://codeclimate.com/github/feathersjs/feathers/test_coverage)
8
8
  [![Download Status](https://img.shields.io/npm/dm/@feathersjs/feathers.svg?style=flat-square)](https://www.npmjs.com/package/@feathersjs/feathers)
9
+ [![Discord](https://badgen.net/badge/icon/discord?icon=discord&label)](https://discord.gg/qa8kez8QBx)
9
10
 
10
11
  Feathers is a lightweight web-framework for creating real-time applications and REST APIs using JavaScript or TypeScript.
11
12
 
@@ -31,6 +32,6 @@ The [Feathers docs](http://docs.feathersjs.com) are loaded with awesome stuff an
31
32
 
32
33
  ## License
33
34
 
34
- Copyright (c) 2021 [Feathers contributors](https://github.com/feathersjs/feathers/graphs/contributors)
35
+ Copyright (c) 2022 [Feathers contributors](https://github.com/feathersjs/feathers/graphs/contributors)
35
36
 
36
37
  Licensed under the [MIT license](LICENSE).
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import { EventEmitter } from './dependencies';
3
- import { FeathersApplication, ServiceMixin, Service, ServiceOptions, ServiceInterface, Application, HookOptions, FeathersService, HookMap } from './declarations';
3
+ import { FeathersApplication, ServiceMixin, Service, ServiceOptions, ServiceInterface, Application, FeathersService, HookMap, 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;
@@ -16,6 +16,7 @@ export declare class Feathers<Services, Settings> extends EventEmitter implement
16
16
  defaultService(location: string): ServiceInterface;
17
17
  service<L extends keyof Services & string>(location: L): FeathersService<this, keyof any extends keyof Services ? Service : Services[L]>;
18
18
  use<L extends keyof Services & string>(path: L, service: keyof any extends keyof Services ? ServiceInterface | Application : Services[L], options?: ServiceOptions): this;
19
- hooks(hookMap: HookOptions<this, any>): any;
19
+ hooks(hookMap: ApplicationHookOptions<this>): this;
20
20
  setup(): Promise<this>;
21
+ teardown(): Promise<this>;
21
22
  }
@@ -23,6 +23,14 @@ class Feathers extends dependencies_1.EventEmitter {
23
23
  [dependencies_1.HOOKS]: [events_1.eventHook]
24
24
  };
25
25
  this.regularHooks = (0, regular_1.enableRegularHooks)(this);
26
+ (0, dependencies_1.hooks)(this, {
27
+ setup: (0, dependencies_1.middleware)().params('server').props({
28
+ app: this
29
+ }),
30
+ teardown: (0, dependencies_1.middleware)().params('server').props({
31
+ app: this
32
+ })
33
+ });
26
34
  }
27
35
  get(name) {
28
36
  return this.settings[name];
@@ -59,7 +67,7 @@ class Feathers extends dependencies_1.EventEmitter {
59
67
  return this;
60
68
  }
61
69
  const protoService = (0, service_1.wrapService)(location, service, options);
62
- const serviceOptions = (0, service_1.getServiceOptions)(service, options);
70
+ const serviceOptions = (0, service_1.getServiceOptions)(protoService);
63
71
  for (const name of service_1.protectedMethods) {
64
72
  if (serviceOptions.methods.includes(name)) {
65
73
  throw new Error(`'${name}' on service '${location}' is not allowed as a custom method name`);
@@ -68,20 +76,23 @@ class Feathers extends dependencies_1.EventEmitter {
68
76
  debug(`Registering new service at \`${location}\``);
69
77
  // Add all the mixins
70
78
  this.mixins.forEach(fn => fn.call(this, protoService, location, serviceOptions));
79
+ this.services[location] = protoService;
71
80
  // If we ran setup already, set this service up explicitly, this will not `await`
72
81
  if (this._isSetup && typeof protoService.setup === 'function') {
73
82
  debug(`Setting up service for \`${location}\``);
74
83
  protoService.setup(this, location);
75
84
  }
76
- this.services[location] = protoService;
77
85
  return this;
78
86
  }
79
87
  hooks(hookMap) {
80
- const regularMap = hookMap;
81
- if (regularMap.before || regularMap.after || regularMap.error) {
82
- return this.regularHooks(regularMap);
88
+ const untypedMap = hookMap;
89
+ if (untypedMap.before || untypedMap.after || untypedMap.error) {
90
+ this.regularHooks(untypedMap);
83
91
  }
84
- if (Array.isArray(hookMap)) {
92
+ else if (untypedMap.setup || untypedMap.teardown) {
93
+ (0, dependencies_1.hooks)(this, untypedMap);
94
+ }
95
+ else if (Array.isArray(hookMap)) {
85
96
  this.appHooks[dependencies_1.HOOKS].push(...hookMap);
86
97
  }
87
98
  else {
@@ -94,21 +105,26 @@ class Feathers extends dependencies_1.EventEmitter {
94
105
  return this;
95
106
  }
96
107
  setup() {
97
- let promise = Promise.resolve();
98
- // Setup each service (pass the app so that they can look up other services etc.)
99
- for (const path of Object.keys(this.services)) {
100
- promise = promise.then(() => {
101
- const service = this.service(path);
102
- if (typeof service.setup === 'function') {
103
- debug(`Setting up service for \`${path}\``);
104
- return service.setup(this, path);
105
- }
106
- });
107
- }
108
- return promise.then(() => {
109
- this._isSetup = true;
110
- return this;
111
- });
108
+ this._isSetup = true;
109
+ return Object.keys(this.services).reduce((current, path) => current
110
+ .then(() => {
111
+ const service = this.service(path);
112
+ if (typeof service.setup === 'function') {
113
+ debug(`Setting up service for \`${path}\``);
114
+ return service.setup(this, path);
115
+ }
116
+ }), Promise.resolve()).then(() => this);
117
+ }
118
+ teardown() {
119
+ this._isSetup = false;
120
+ return Object.keys(this.services).reduce((current, path) => current
121
+ .then(() => {
122
+ const service = this.service(path);
123
+ if (typeof service.teardown === 'function') {
124
+ debug(`Tearing down service for \`${path}\``);
125
+ return service.teardown(this, path);
126
+ }
127
+ }), Promise.resolve()).then(() => this);
112
128
  }
113
129
  }
114
130
  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;AAa7E,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;IAC/C,CAAC;IAED,GAAG,CAAqC,IAAO;QAC7C,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;IAED,GAAG,CAAqC,IAAO,EAAE,KAAkB;QACjE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;QAC5B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,SAAS,CAAE,QAAyC;QAClD,QAAQ,CAAC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EAAE;gBAC1C,KAAK,CAAC,8BAA8B,IAAI,IAAI,CAAC,CAAC;gBAE9C,OAAO,OAAO,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;aACrC;QACH,CAAC,CAAC,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAA;IAC3C,CAAC;CACF;AA3JD,4BA2JC"}
@@ -25,6 +25,7 @@ export interface ServiceMethods<T = any, D = Partial<T>> {
25
25
  patch(id: NullableId, data: D, params?: Params): Promise<T | T[]>;
26
26
  remove(id: NullableId, params?: Params): Promise<T | T[]>;
27
27
  setup(app: Application, path: string): Promise<void>;
28
+ teardown(app: Application, path: string): Promise<void>;
28
29
  }
29
30
  export interface ServiceOverloads<T = any, D = Partial<T>> {
30
31
  create?(data: D[], params?: Params): Promise<T[]>;
@@ -133,13 +134,24 @@ export interface FeathersApplication<Services = any, Settings = any> {
133
134
  * @param path The name of the service.
134
135
  */
135
136
  service<L extends keyof Services & string>(path: L): FeathersService<this, keyof any extends keyof Services ? Service : Services[L]>;
137
+ /**
138
+ * Set up the application and call all services `.setup` method if available.
139
+ *
140
+ * @param server A server instance (optional)
141
+ */
136
142
  setup(server?: any): Promise<this>;
143
+ /**
144
+ * Tear down the application and call all services `.teardown` method if available.
145
+ *
146
+ * @param server A server instance (optional)
147
+ */
148
+ teardown(server?: any): Promise<this>;
137
149
  /**
138
150
  * Register application level hooks.
139
151
  *
140
152
  * @param map The application hook settings.
141
153
  */
142
- hooks(map: HookOptions<this, any>): this;
154
+ hooks(map: ApplicationHookOptions<this>): this;
143
155
  }
144
156
  export interface Application<Services = any, Settings = any> extends FeathersApplication<Services, Settings>, EventEmitter {
145
157
  }
@@ -161,10 +173,19 @@ export interface Params {
161
173
  }
162
174
  export interface Http {
163
175
  /**
164
- * A writeable, optional property that allows to override the standard HTTP status
165
- * code that should be returned.
176
+ * A writeable, optional property with status code override.
166
177
  */
167
- statusCode?: number;
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;
168
189
  }
169
190
  export interface HookContext<A = Application, S = any> extends BaseHookContext<ServiceGenericType<S>> {
170
191
  /**
@@ -237,11 +258,11 @@ export interface HookContext<A = Application, S = any> extends BaseHookContext<S
237
258
  * A writeable, optional property that allows to override the standard HTTP status
238
259
  * code that should be returned.
239
260
  *
240
- * @deprecated Use `http.statusCode` instead.
261
+ * @deprecated Use `http.status` instead.
241
262
  */
242
263
  statusCode?: number;
243
264
  /**
244
- * A writeable, optional property that contains options specific to HTTP transports.
265
+ * A writeable, optional property with options specific to HTTP transports.
245
266
  */
246
267
  http?: Http;
247
268
  /**
@@ -267,3 +288,13 @@ export declare type HookMap<A, S> = {
267
288
  [L in keyof S]?: HookFunction<A, S>[];
268
289
  };
269
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>;
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1 +1 @@
1
- {"version":3,"file":"dependencies.js","sourceRoot":"","sources":["../src/dependencies.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,mCAAsC;AAI7B,6FAJA,qBAAY,OAIA;AAHrB,sDAAoC;AACpC,oDAAkC"}
1
+ {"version":3,"file":"dependencies.js","sourceRoot":"","sources":["../src/dependencies.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,mCAAsC;AAI7B,6FAJA,qBAAY,OAIA;AAHrB,sDAAoC;AACpC,oDAAkC"}
@@ -7,7 +7,7 @@ export declare class FeathersHookManager<A> extends HookManager {
7
7
  method: string;
8
8
  constructor(app: A, method: string);
9
9
  collectMiddleware(self: any, args: any[]): Middleware[];
10
- initializeContext(self: any, args: any[], context: HookContext): import("@feathersjs/hooks/lib/base").HookContext<any, any>;
10
+ initializeContext(self: any, args: any[], context: HookContext): import("@feathersjs/hooks/types/base").HookContext<any, any>;
11
11
  middleware(mw: Middleware[]): this;
12
12
  }
13
13
  export declare function hookMixin<A>(this: A, service: FeathersService<A>, path: string, options: ServiceOptions): FeathersService<A, Service<any, Partial<any>>>;
@@ -64,10 +64,10 @@ function hookMixin(service, path, options) {
64
64
  type: null,
65
65
  get statusCode() {
66
66
  var _a;
67
- return (_a = this.http) === null || _a === void 0 ? void 0 : _a.statusCode;
67
+ return (_a = this.http) === null || _a === void 0 ? void 0 : _a.status;
68
68
  },
69
69
  set statusCode(value) {
70
- (this.http || (this.http = {})).statusCode = value;
70
+ (this.http || (this.http = {})).status = value;
71
71
  }
72
72
  });
73
73
  return res;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":";;;AAAA,kDAEyB;AAIzB,wCAAqE;AACrE,uCAGmB;AAEnB,qCAO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
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
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,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"}
package/lib/service.js CHANGED
@@ -27,6 +27,7 @@ exports.protectedMethods = Object.keys(Object.prototype)
27
27
  'error',
28
28
  'hooks',
29
29
  'setup',
30
+ 'teardown',
30
31
  'publish'
31
32
  ]);
32
33
  function getHookMethods(service, options) {
@@ -1 +1 @@
1
- {"version":3,"file":"service.js","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":";;;AAAA,iDAA4D;AAG/C,QAAA,OAAO,GAAG,IAAA,2BAAY,EAAC,qBAAqB,CAAC,CAAC;AAE9C,QAAA,uBAAuB,GAAG;IACrC,IAAI,EAAE,CAAE,QAAQ,CAAE;IAClB,GAAG,EAAE,CAAE,IAAI,EAAE,QAAQ,CAAE;IACvB,MAAM,EAAE,CAAE,MAAM,EAAE,QAAQ,CAAE;IAC5B,MAAM,EAAE,CAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAE;IAClC,KAAK,EAAE,CAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAE;IACjC,MAAM,EAAE,CAAE,IAAI,EAAE,QAAQ,CAAE;CAC3B,CAAA;AAEY,QAAA,qBAAqB,GAAG,MAAM,CAAC,IAAI,CAAC,+BAAuB,CAAC,CAAC;AAE7D,QAAA,eAAe,GAAG;IAC7B,MAAM,EAAE,SAAS;IACjB,MAAM,EAAE,SAAS;IACjB,KAAK,EAAE,SAAS;IAChB,MAAM,EAAE,SAAS;CAClB,CAAA;AAEY,QAAA,gBAAgB,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC;KAC1D,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,2BAAY,CAAC,SAAS,CAAC,CAAC;KAC3C,MAAM,CAAC;IACN,KAAK;IACL,QAAQ;IACR,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,S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OAAO,CAAC,CAAC;IAE3D,IAAI,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,MAAM,KAAK,CAAC,IAAI,OAAO,OAAO,CAAC,KAAK,KAAK,UAAU,EAAE;QAC3F,MAAM,IAAI,KAAK,CAAC,4CAA4C,QAAQ,IAAI,CAAC,CAAC;KAC3E;IAED,MAAM,CAAC,cAAc,CAAC,YAAY,EAAE,eAAO,EAAE;QAC3C,KAAK,EAAE,cAAc;KACtB,CAAC,CAAC;IAEH,OAAO,YAAY,CAAC;AACtB,CAAC;AApBD,kCAoBC"}
package/lib/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- declare const _default: "5.0.0-pre.15";
1
+ declare const _default: "5.0.0-pre.18";
2
2
  export default _default;
package/lib/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = '5.0.0-pre.15';
3
+ exports.default = '5.0.0-pre.18';
4
4
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@feathersjs/feathers",
3
3
  "description": "A framework for real-time applications and REST API with JavaScript and TypeScript",
4
- "version": "5.0.0-pre.15",
4
+ "version": "5.0.0-pre.18",
5
5
  "homepage": "http://feathersjs.com",
6
6
  "repository": {
7
7
  "type": "git",
8
- "url": "git://github.com/feathersjs/feathers.git"
8
+ "url": "git://github.com/feathersjs/feathers.git",
9
+ "directory": "packages/feathers"
9
10
  },
10
11
  "keywords": [
11
12
  "feathers",
@@ -47,8 +48,7 @@
47
48
  "version": "npm run write-version",
48
49
  "publish": "npm run reset-version",
49
50
  "compile": "shx rm -rf lib/ && tsc",
50
- "test": "npm run compile && npm run mocha",
51
- "mocha": "mocha --config ../../.mocharc.json --recursive test/"
51
+ "test": "mocha --config ../../.mocharc.json --recursive test/"
52
52
  },
53
53
  "engines": {
54
54
  "node": ">= 12"
@@ -57,17 +57,17 @@
57
57
  "access": "public"
58
58
  },
59
59
  "dependencies": {
60
- "@feathersjs/commons": "^5.0.0-pre.15",
61
- "@feathersjs/hooks": "^0.6.5",
60
+ "@feathersjs/commons": "^5.0.0-pre.18",
61
+ "@feathersjs/hooks": "^0.7.3",
62
62
  "events": "^3.3.0"
63
63
  },
64
64
  "devDependencies": {
65
- "@types/mocha": "^9.0.0",
66
- "@types/node": "^16.11.6",
67
- "mocha": "^9.1.3",
68
- "shx": "^0.3.3",
69
- "ts-node": "^10.4.0",
70
- "typescript": "^4.4.4"
65
+ "@types/mocha": "^9.1.0",
66
+ "@types/node": "^17.0.23",
67
+ "mocha": "^9.2.2",
68
+ "shx": "^0.3.4",
69
+ "ts-node": "^10.7.0",
70
+ "typescript": "^4.6.3"
71
71
  },
72
- "gitHead": "8008bf4f8529a2a40b6a2f976c1f43ae13675693"
72
+ "gitHead": "c0b7b67d872dcd6b6d94e4587f21332c8a519b50"
73
73
  }
@@ -1,6 +1,6 @@
1
1
  import version from './version';
2
2
  import {
3
- EventEmitter, stripSlashes, createDebug, HOOKS
3
+ EventEmitter, stripSlashes, createDebug, HOOKS, hooks, middleware
4
4
  } from './dependencies';
5
5
  import { eventHook, eventMixin } from './events';
6
6
  import { hookMixin } from './hooks/index';
@@ -12,10 +12,9 @@ import {
12
12
  ServiceOptions,
13
13
  ServiceInterface,
14
14
  Application,
15
- HookOptions,
16
15
  FeathersService,
17
16
  HookMap,
18
- RegularHookMap
17
+ ApplicationHookOptions
19
18
  } from './declarations';
20
19
  import { enableRegularHooks } from './hooks/regular';
21
20
 
@@ -36,6 +35,14 @@ export class Feathers<Services, Settings> extends EventEmitter implements Feathe
36
35
  constructor () {
37
36
  super();
38
37
  this.regularHooks = enableRegularHooks(this);
38
+ hooks(this, {
39
+ setup: middleware().params('server').props({
40
+ app: this
41
+ }),
42
+ teardown: middleware().params('server').props({
43
+ app: this
44
+ })
45
+ });
39
46
  }
40
47
 
41
48
  get<L extends keyof Settings & string> (name: L): Settings[L] {
@@ -93,7 +100,7 @@ export class Feathers<Services, Settings> extends EventEmitter implements Feathe
93
100
  }
94
101
 
95
102
  const protoService = wrapService(location, service, options);
96
- const serviceOptions = getServiceOptions(service, options);
103
+ const serviceOptions = getServiceOptions(protoService);
97
104
 
98
105
  for (const name of protectedMethods) {
99
106
  if (serviceOptions.methods.includes(name)) {
@@ -106,25 +113,25 @@ export class Feathers<Services, Settings> extends EventEmitter implements Feathe
106
113
  // Add all the mixins
107
114
  this.mixins.forEach(fn => fn.call(this, protoService, location, serviceOptions));
108
115
 
116
+ this.services[location] = protoService;
117
+
109
118
  // If we ran setup already, set this service up explicitly, this will not `await`
110
119
  if (this._isSetup && typeof protoService.setup === 'function') {
111
120
  debug(`Setting up service for \`${location}\``);
112
121
  protoService.setup(this, location);
113
122
  }
114
123
 
115
- this.services[location] = protoService;
116
-
117
124
  return this;
118
125
  }
119
126
 
120
- hooks (hookMap: HookOptions<this, any>) {
121
- const regularMap = hookMap as RegularHookMap<this, any>;
127
+ hooks (hookMap: ApplicationHookOptions<this>) {
128
+ const untypedMap = hookMap as any;
122
129
 
123
- if (regularMap.before || regularMap.after || regularMap.error) {
124
- return this.regularHooks(regularMap);
125
- }
126
-
127
- if (Array.isArray(hookMap)) {
130
+ if (untypedMap.before || untypedMap.after || untypedMap.error) {
131
+ this.regularHooks(untypedMap);
132
+ } else if (untypedMap.setup || untypedMap.teardown) {
133
+ hooks(this, untypedMap);
134
+ } else if (Array.isArray(hookMap)) {
128
135
  this.appHooks[HOOKS].push(...hookMap as any);
129
136
  } else {
130
137
  const methodHookMap = hookMap as HookMap<Application<Services, Settings>, any>;
@@ -140,11 +147,10 @@ export class Feathers<Services, Settings> extends EventEmitter implements Feathe
140
147
  }
141
148
 
142
149
  setup () {
143
- let promise = Promise.resolve();
150
+ this._isSetup = true;
144
151
 
145
- // Setup each service (pass the app so that they can look up other services etc.)
146
- for (const path of Object.keys(this.services)) {
147
- promise = promise.then(() => {
152
+ return Object.keys(this.services).reduce((current, path) => current
153
+ .then(() => {
148
154
  const service: any = this.service(path as any);
149
155
 
150
156
  if (typeof service.setup === 'function') {
@@ -152,12 +158,21 @@ export class Feathers<Services, Settings> extends EventEmitter implements Feathe
152
158
 
153
159
  return service.setup(this, path);
154
160
  }
155
- });
156
- }
161
+ }), Promise.resolve()).then(() => this);
162
+ }
157
163
 
158
- return promise.then(() => {
159
- this._isSetup = true;
160
- return this;
161
- });
164
+ teardown () {
165
+ this._isSetup = false;
166
+
167
+ return Object.keys(this.services).reduce((current, path) => current
168
+ .then(() => {
169
+ const service: any = this.service(path as any);
170
+
171
+ if (typeof service.teardown === 'function') {
172
+ debug(`Tearing down service for \`${path}\``);
173
+
174
+ return service.teardown(this, path);
175
+ }
176
+ }), Promise.resolve()).then(() => this)
162
177
  }
163
178
  }
@@ -35,6 +35,8 @@ export interface ServiceMethods<T = any, D = Partial<T>> {
35
35
  remove (id: NullableId, params?: Params): Promise<T | T[]>;
36
36
 
37
37
  setup (app: Application, path: string): Promise<void>;
38
+
39
+ teardown (app: Application, path: string): Promise<void>;
38
40
  }
39
41
 
40
42
  export interface ServiceOverloads<T = any, D = Partial<T>> {
@@ -209,14 +211,26 @@ export interface FeathersApplication<Services = any, Settings = any> {
209
211
  path: L
210
212
  ): FeathersService<this, keyof any extends keyof Services ? Service : Services[L]>;
211
213
 
214
+ /**
215
+ * Set up the application and call all services `.setup` method if available.
216
+ *
217
+ * @param server A server instance (optional)
218
+ */
212
219
  setup (server?: any): Promise<this>;
213
220
 
221
+ /**
222
+ * Tear down the application and call all services `.teardown` method if available.
223
+ *
224
+ * @param server A server instance (optional)
225
+ */
226
+ teardown (server?: any): Promise<this>;
227
+
214
228
  /**
215
229
  * Register application level hooks.
216
230
  *
217
231
  * @param map The application hook settings.
218
232
  */
219
- hooks (map: HookOptions<this, any>): this;
233
+ hooks (map: ApplicationHookOptions<this>): this;
220
234
  }
221
235
 
222
236
  // This needs to be an interface instead of a type
@@ -242,10 +256,17 @@ export interface Params {
242
256
 
243
257
  export interface Http {
244
258
  /**
245
- * A writeable, optional property that allows to override the standard HTTP status
246
- * code that should be returned.
259
+ * A writeable, optional property with status code override.
247
260
  */
248
- statusCode?: number;
261
+ status?: number;
262
+ /**
263
+ * A writeable, optional property with headers.
264
+ */
265
+ headers?: { [key: string]: string | string[] };
266
+ /**
267
+ * A writeable, optional property with `Location` header's value.
268
+ */
269
+ location?: string;
249
270
  }
250
271
 
251
272
  export interface HookContext<A = Application, S = any> extends BaseHookContext<ServiceGenericType<S>> {
@@ -319,11 +340,11 @@ export interface HookContext<A = Application, S = any> extends BaseHookContext<S
319
340
  * A writeable, optional property that allows to override the standard HTTP status
320
341
  * code that should be returned.
321
342
  *
322
- * @deprecated Use `http.statusCode` instead.
343
+ * @deprecated Use `http.status` instead.
323
344
  */
324
345
  statusCode?: number;
325
346
  /**
326
- * A writeable, optional property that contains options specific to HTTP transports.
347
+ * A writeable, optional property with options specific to HTTP transports.
327
348
  */
328
349
  http?: Http;
329
350
  /**
@@ -361,3 +382,18 @@ export type HookMap<A, S> = {
361
382
 
362
383
  export type HookOptions<A, S> =
363
384
  HookMap<A, S> | HookFunction<A, S>[] | RegularHookMap<A, S>;
385
+
386
+ export interface ApplicationHookContext<A = Application> extends BaseHookContext {
387
+ app: A;
388
+ server: any;
389
+ }
390
+
391
+ export type ApplicationHookFunction<A> =
392
+ (context: ApplicationHookContext<A>, next: NextFunction) => Promise<void>;
393
+
394
+ export type ApplicationHookMap<A> = {
395
+ setup?: ApplicationHookFunction<A>[],
396
+ teardown?: ApplicationHookFunction<A>[]
397
+ }
398
+
399
+ export type ApplicationHookOptions<A> = HookOptions<A, any> | ApplicationHookMap<A>
@@ -81,11 +81,11 @@ export function hookMixin<A> (
81
81
  service,
82
82
  event: null,
83
83
  type: null,
84
- get statusCode() {
85
- return this.http?.statusCode;
84
+ get statusCode () {
85
+ return this.http?.status;
86
86
  },
87
- set statusCode(value: number) {
88
- (this.http ||= {}).statusCode = value;
87
+ set statusCode (value: number) {
88
+ (this.http ||= {}).status = value;
89
89
  }
90
90
  });
91
91
 
package/src/service.ts CHANGED
@@ -30,6 +30,7 @@ export const protectedMethods = Object.keys(Object.prototype)
30
30
  'error',
31
31
  'hooks',
32
32
  'setup',
33
+ 'teardown',
33
34
  'publish'
34
35
  ]);
35
36
 
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export default '5.0.0-pre.15';
1
+ export default '5.0.0-pre.18';