@feathersjs/feathers 5.0.0-pre.3 → 5.0.0-pre.31

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/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
@@ -2,14 +2,11 @@
2
2
 
3
3
  ## A framework for real-time applications and REST APIs with JavaScript and TypeScript
4
4
 
5
- [![Greenkeeper badge](https://badges.greenkeeper.io/feathersjs/feathers.svg)](https://greenkeeper.io/)
6
5
  [![CI](https://github.com/feathersjs/feathers/workflows/CI/badge.svg)](https://github.com/feathersjs/feathers/actions?query=workflow%3ACI)
7
6
  [![Maintainability](https://api.codeclimate.com/v1/badges/cb5ec42a2d0cc1a47a02/maintainability)](https://codeclimate.com/github/feathersjs/feathers/maintainability)
8
7
  [![Test Coverage](https://api.codeclimate.com/v1/badges/cb5ec42a2d0cc1a47a02/test_coverage)](https://codeclimate.com/github/feathersjs/feathers/test_coverage)
9
8
  [![Download Status](https://img.shields.io/npm/dm/@feathersjs/feathers.svg?style=flat-square)](https://www.npmjs.com/package/@feathersjs/feathers)
10
-
11
- [![Slack Status](http://slack.feathersjs.com/badge.svg)](http://slack.feathersjs.com)
12
- [![Telegram Status](https://img.shields.io/badge/Telegram_RU_chat:-Feathers-216bc1.svg?style=flat)](https://t.me/featherjs)
9
+ [![Discord](https://badgen.net/badge/icon/discord?icon=discord&label)](https://discord.gg/qa8kez8QBx)
13
10
 
14
11
  Feathers is a lightweight web-framework for creating real-time applications and REST APIs using JavaScript or TypeScript.
15
12
 
@@ -35,6 +32,6 @@ The [Feathers docs](http://docs.feathersjs.com) are loaded with awesome stuff an
35
32
 
36
33
  ## License
37
34
 
38
- 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)
39
36
 
40
37
  Licensed under the [MIT license](LICENSE).
@@ -1,21 +1,26 @@
1
1
  /// <reference types="node" />
2
- import { EventEmitter } from './dependencies';
3
- import { FeathersApplication, ServiceMixin, Service, ServiceOptions, ServiceInterface, Application, HookOptions, FeathersService, HookMap } from './declarations';
4
- export declare class Feathers<ServiceTypes, AppSettings> extends EventEmitter implements FeathersApplication<ServiceTypes, AppSettings> {
5
- services: ServiceTypes;
6
- settings: AppSettings;
7
- mixins: ServiceMixin<Application<ServiceTypes, AppSettings>>[];
2
+ import { EventEmitter } from 'events';
3
+ import { FeathersApplication, ServiceMixin, Service, ServiceOptions, ServiceInterface, Application, FeathersService, ApplicationHookOptions } from './declarations';
4
+ export declare class Feathers<Services, Settings> extends EventEmitter implements FeathersApplication<Services, Settings> {
5
+ services: Services;
6
+ settings: Settings;
7
+ mixins: ServiceMixin<Application<Services, Settings>>[];
8
8
  version: string;
9
9
  _isSetup: boolean;
10
- appHooks: HookMap<Application<ServiceTypes, AppSettings>, any>;
11
- private legacyHooks;
10
+ protected registerHooks: (this: any, allHooks: any) => any;
12
11
  constructor();
13
- get<L extends keyof AppSettings & string>(name: L): AppSettings[L];
14
- set<L extends keyof AppSettings & string>(name: L, value: AppSettings[L]): this;
12
+ get<L extends keyof Settings & string>(name: L): Settings[L];
13
+ set<L extends keyof Settings & string>(name: L, value: Settings[L]): this;
15
14
  configure(callback: (this: this, app: this) => void): this;
16
- defaultService(location: string): ServiceInterface<any>;
17
- service<L extends keyof ServiceTypes & string>(location: L): FeathersService<this, keyof any extends keyof ServiceTypes ? Service<any> : ServiceTypes[L]>;
18
- use<L extends keyof ServiceTypes & string>(path: L, service: keyof any extends keyof ServiceTypes ? ServiceInterface<any> | Application : ServiceTypes[L], options?: ServiceOptions): this;
19
- hooks(hookMap: HookOptions<this, any>): any;
20
- setup(): Promise<this>;
15
+ defaultService(location: string): ServiceInterface;
16
+ service<L extends keyof Services & string>(location: L): FeathersService<this, keyof any extends keyof Services ? Service : Services[L]>;
17
+ protected _setup(): Promise<this>;
18
+ get setup(): () => Promise<this>;
19
+ set setup(value: () => Promise<this>);
20
+ protected _teardown(): Promise<this>;
21
+ get teardown(): () => Promise<this>;
22
+ set teardown(value: () => Promise<this>);
23
+ use<L extends keyof Services & string>(path: L, service: keyof any extends keyof Services ? ServiceInterface | Application : Services[L], options?: ServiceOptions): this;
24
+ unuse<L extends keyof Services & string>(location: L): Promise<FeathersService<this, keyof any extends keyof Services ? Service : Services[L]>>;
25
+ hooks(hookMap: ApplicationHookOptions<this>): this;
21
26
  }
@@ -5,24 +5,26 @@ 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 legacy_1 = require("./hooks/legacy");
13
- const debug = 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.legacyHooks = legacy_1.enableLegacyHooks(this);
24
+ this.registerHooks = (0, hooks_3.enableHooks)(this);
25
+ this.registerHooks({
26
+ around: [events_2.eventHook]
27
+ });
26
28
  }
27
29
  get(name) {
28
30
  return this.settings[name];
@@ -39,7 +41,7 @@ class Feathers extends dependencies_1.EventEmitter {
39
41
  throw new Error(`Can not find service '${location}'`);
40
42
  }
41
43
  service(location) {
42
- const path = (dependencies_1.stripSlashes(location) || '/');
44
+ const path = ((0, commons_1.stripSlashes)(location) || '/');
43
45
  const current = this.services[path];
44
46
  if (typeof current === 'undefined') {
45
47
  this.use(path, this.defaultService(path));
@@ -47,64 +49,106 @@ class Feathers extends dependencies_1.EventEmitter {
47
49
  }
48
50
  return current;
49
51
  }
52
+ _setup() {
53
+ this._isSetup = true;
54
+ return Object.keys(this.services)
55
+ .reduce((current, path) => current.then(() => {
56
+ const service = this.service(path);
57
+ if (typeof service.setup === 'function') {
58
+ debug(`Setting up service for \`${path}\``);
59
+ return service.setup(this, path);
60
+ }
61
+ }), Promise.resolve())
62
+ .then(() => this);
63
+ }
64
+ get setup() {
65
+ return this._setup;
66
+ }
67
+ set setup(value) {
68
+ this._setup = value[hooks_1.HOOKS]
69
+ ? value
70
+ : (0, hooks_1.hooks)(value, (0, hooks_1.middleware)().params('server').props({
71
+ app: this
72
+ }));
73
+ }
74
+ _teardown() {
75
+ this._isSetup = false;
76
+ return Object.keys(this.services)
77
+ .reduce((current, path) => current.then(() => {
78
+ const service = this.service(path);
79
+ if (typeof service.teardown === 'function') {
80
+ debug(`Tearing down service for \`${path}\``);
81
+ return service.teardown(this, path);
82
+ }
83
+ }), Promise.resolve())
84
+ .then(() => this);
85
+ }
86
+ get teardown() {
87
+ return this._teardown;
88
+ }
89
+ set teardown(value) {
90
+ this._teardown = value[hooks_1.HOOKS]
91
+ ? value
92
+ : (0, hooks_1.hooks)(value, (0, hooks_1.middleware)().params('server').props({
93
+ app: this
94
+ }));
95
+ }
50
96
  use(path, service, options) {
51
97
  if (typeof path !== 'string') {
52
98
  throw new Error(`'${path}' is not a valid service path.`);
53
99
  }
54
- const location = (dependencies_1.stripSlashes(path) || '/');
100
+ const location = ((0, commons_1.stripSlashes)(path) || '/');
55
101
  const subApp = service;
56
102
  const isSubApp = typeof subApp.service === 'function' && subApp.services;
57
103
  if (isSubApp) {
58
- Object.keys(subApp.services).forEach(subPath => this.use(`${location}/${subPath}`, subApp.service(subPath)));
104
+ Object.keys(subApp.services).forEach((subPath) => this.use(`${location}/${subPath}`, subApp.service(subPath)));
59
105
  return this;
60
106
  }
61
- const protoService = service_1.wrapService(location, service, options);
62
- const serviceOptions = service_1.getServiceOptions(service, options);
107
+ const protoService = (0, service_1.wrapService)(location, service, options);
108
+ const serviceOptions = (0, service_1.getServiceOptions)(protoService);
109
+ for (const name of service_1.protectedMethods) {
110
+ if (serviceOptions.methods.includes(name)) {
111
+ throw new Error(`'${name}' on service '${location}' is not allowed as a custom method name`);
112
+ }
113
+ }
63
114
  debug(`Registering new service at \`${location}\``);
64
115
  // Add all the mixins
65
- this.mixins.forEach(fn => fn.call(this, protoService, location, serviceOptions));
116
+ this.mixins.forEach((fn) => fn.call(this, protoService, location, serviceOptions));
117
+ this.services[location] = protoService;
66
118
  // If we ran setup already, set this service up explicitly, this will not `await`
67
119
  if (this._isSetup && typeof protoService.setup === 'function') {
68
120
  debug(`Setting up service for \`${location}\``);
69
121
  protoService.setup(this, location);
70
122
  }
71
- this.services[location] = protoService;
72
123
  return this;
73
124
  }
125
+ async unuse(location) {
126
+ const path = ((0, commons_1.stripSlashes)(location) || '/');
127
+ const service = this.services[path];
128
+ if (service && typeof service.teardown === 'function') {
129
+ await service.teardown(this, path);
130
+ }
131
+ delete this.services[path];
132
+ return service;
133
+ }
74
134
  hooks(hookMap) {
75
- const legacyMap = hookMap;
76
- if (legacyMap.before || legacyMap.after || legacyMap.error) {
77
- return this.legacyHooks(legacyMap);
135
+ const untypedMap = hookMap;
136
+ if (untypedMap.before || untypedMap.after || untypedMap.error || untypedMap.around) {
137
+ // regular hooks for all service methods
138
+ this.registerHooks(untypedMap);
78
139
  }
79
- if (Array.isArray(hookMap)) {
80
- this.appHooks[dependencies_1.HOOKS].push(...hookMap);
140
+ else if (untypedMap.setup || untypedMap.teardown) {
141
+ // .setup and .teardown application hooks
142
+ (0, hooks_1.hooks)(this, untypedMap);
81
143
  }
82
144
  else {
83
- const methodHookMap = hookMap;
84
- Object.keys(methodHookMap).forEach(key => {
85
- const methodHooks = this.appHooks[key] || [];
86
- this.appHooks[key] = methodHooks.concat(methodHookMap[key]);
145
+ // Other registration formats are just `around` hooks
146
+ this.registerHooks({
147
+ around: untypedMap
87
148
  });
88
149
  }
89
150
  return this;
90
151
  }
91
- setup() {
92
- let promise = Promise.resolve();
93
- // Setup each service (pass the app so that they can look up other services etc.)
94
- for (const path of Object.keys(this.services)) {
95
- promise = promise.then(() => {
96
- const service = this.service(path);
97
- if (typeof service.setup === 'function') {
98
- debug(`Setting up service for \`${path}\``);
99
- return service.setup(this, path);
100
- }
101
- });
102
- }
103
- return promise.then(() => {
104
- this._isSetup = true;
105
- return this;
106
- });
107
- }
108
152
  }
109
153
  exports.Feathers = Feathers;
110
154
  //# sourceMappingURL=application.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"application.js","sourceRoot":"","sources":["../src/application.ts"],"names":[],"mappings":";;;;;;AAAA,wDAAgC;AAChC,iDAEwB;AACxB,qCAAiD;AACjD,yCAA0C;AAC1C,uCAA2D;AAa3D,2CAAmD;AAEnD,MAAM,KAAK,GAAG,0BAAW,CAAC,sBAAsB,CAAC,CAAC;AAElD,MAAa,QAAoC,SAAQ,2BAAY;IAYnE;QACE,KAAK,EAAE,CAAC;QAZV,aAAQ,GAAkB,EAAmB,CAAC;QAC9C,aAAQ,GAAiB,EAAkB,CAAC;QAC5C,WAAM,GAA2D,CAAE,iBAAS,EAAE,mBAAU,CAAE,CAAC;QAC3F,YAAO,GAAW,iBAAO,CAAC;QAC1B,aAAQ,GAAG,KAAK,CAAC;QACjB,aAAQ,GAAyD;YAC/D,CAAC,oBAA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AAC,KAAK,CACT,QAAW;QAEX,MAAM,IAAI,GAAG,CAAC,IAAA,sBAAY,EAAC,QAAQ,CAAC,IAAI,GAAG,CAAM,CAAA;QACjD,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAY,CAAA;QAE9C,IAAI,OAAO,IAAI,OAAO,OAAO,CAAC,QAAQ,KAAK,UAAU,EAAE;YACrD,MAAM,OAAO,CAAC,QAAQ,CAAC,IAAW,EAAE,IAAI,CAAC,CAAA;SAC1C;QAED,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;QAE1B,OAAO,OAAc,CAAA;IACvB,CAAC;IAED,KAAK,CAAC,OAAqC;QACzC,MAAM,UAAU,GAAG,OAAc,CAAA;QAEjC,IAAI,UAAU,CAAC,MAAM,IAAI,UAAU,CAAC,KAAK,IAAI,UAAU,CAAC,KAAK,IAAI,UAAU,CAAC,MAAM,EAAE;YAClF,wCAAwC;YACxC,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,CAAA;SAC/B;aAAM,IAAI,UAAU,CAAC,KAAK,IAAI,UAAU,CAAC,QAAQ,EAAE;YAClD,yCAAyC;YACzC,IAAA,aAAK,EAAC,IAAI,EAAE,UAAU,CAAC,CAAA;SACxB;aAAM;YACL,qDAAqD;YACrD,IAAI,CAAC,aAAa,CAAC;gBACjB,MAAM,EAAE,UAAU;aACnB,CAAC,CAAA;SACH;QAED,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AA1MD,4BA0MC"}
@@ -1,53 +1,101 @@
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 };
7
+ /**
8
+ * The object returned from `.find` call by standard database adapters
9
+ */
10
+ export interface Paginated<T> {
11
+ total: number;
12
+ limit: number;
13
+ skip: number;
14
+ data: T[];
15
+ }
16
+ /**
17
+ * Options that can be passed when registering a service via `app.use(name, service, options)`
18
+ */
6
19
  export interface ServiceOptions {
7
- events?: string[];
8
- methods?: string[];
9
- serviceEvents?: string[];
20
+ events?: string[] | readonly string[];
21
+ methods?: string[] | readonly string[];
22
+ serviceEvents?: string[] | readonly string[];
23
+ routeParams?: {
24
+ [key: string]: any;
25
+ };
10
26
  }
11
- export interface ServiceMethods<T, D = Partial<T>> {
12
- find(params?: Params): Promise<T | T[]>;
13
- get(id: Id, params?: Params): Promise<T>;
14
- create(data: D, params?: Params): Promise<T>;
15
- update(id: NullableId, data: D, params?: Params): Promise<T | T[]>;
16
- patch(id: NullableId, data: D, params?: Params): Promise<T | T[]>;
17
- remove(id: NullableId, params?: Params): Promise<T | T[]>;
18
- setup(app: Application, path: string): Promise<void>;
27
+ export interface ClientService<Result = any, Data = Partial<Result>, PatchData = Data, FindResult = Paginated<Result>, P = Params> {
28
+ find(params?: P): Promise<FindResult>;
29
+ get(id: Id, params?: P): Promise<Result>;
30
+ create(data: Data[], params?: P): Promise<Result[]>;
31
+ create(data: Data, params?: P): Promise<Result>;
32
+ update(id: Id, data: Data, params?: P): Promise<Result>;
33
+ update(id: NullableId, data: Data, params?: P): Promise<Result | Result[]>;
34
+ update(id: null, data: Data, params?: P): Promise<Result[]>;
35
+ patch(id: NullableId, data: PatchData, params?: P): Promise<Result | Result[]>;
36
+ patch(id: Id, data: PatchData, params?: P): Promise<Result>;
37
+ patch(id: null, data: PatchData, params?: P): Promise<Result[]>;
38
+ remove(id: NullableId, params?: P): Promise<Result | Result[]>;
39
+ remove(id: Id, params?: P): Promise<Result>;
40
+ remove(id: null, params?: P): Promise<Result[]>;
19
41
  }
20
- export interface ServiceOverloads<T, D> {
21
- create?(data: D[], params?: Params): Promise<T[]>;
22
- update?(id: Id, data: D, params?: Params): Promise<T>;
23
- update?(id: null, data: D, params?: Params): Promise<T[]>;
24
- patch?(id: Id, data: D, params?: Params): Promise<T>;
25
- patch?(id: null, data: D, params?: Params): Promise<T[]>;
26
- remove?(id: Id, params?: Params): Promise<T>;
27
- remove?(id: null, params?: Params): Promise<T[]>;
42
+ export interface ServiceMethods<T = any, D = Partial<T>, P = Params> {
43
+ find(params?: P): Promise<T | T[]>;
44
+ get(id: Id, params?: P): Promise<T>;
45
+ create(data: D, params?: P): Promise<T>;
46
+ update(id: NullableId, data: D, params?: P): Promise<T | T[]>;
47
+ patch(id: NullableId, data: D, params?: P): Promise<T | T[]>;
48
+ remove(id: NullableId, params?: P): Promise<T | T[]>;
49
+ setup?(app: Application, path: string): Promise<void>;
50
+ teardown?(app: Application, path: string): Promise<void>;
28
51
  }
29
- export declare type Service<T, D = Partial<T>> = ServiceMethods<T, D> & ServiceOverloads<T, D>;
30
- export declare type ServiceInterface<T, D = Partial<T>> = Partial<ServiceMethods<T, D>>;
31
- export interface ServiceAddons<A = Application, S = Service<any, any>> extends EventEmitter {
52
+ export interface ServiceOverloads<T = any, D = Partial<T>, P = Params> {
53
+ create?(data: D[], params?: P): Promise<T[]>;
54
+ update?(id: Id, data: D, params?: P): Promise<T>;
55
+ update?(id: null, data: D, params?: P): Promise<T[]>;
56
+ patch?(id: Id, data: D, params?: P): Promise<T>;
57
+ patch?(id: null, data: D, params?: P): Promise<T[]>;
58
+ remove?(id: Id, params?: P): Promise<T>;
59
+ remove?(id: null, params?: P): Promise<T[]>;
60
+ }
61
+ export declare type Service<T = any, D = Partial<T>, P = Params> = ServiceMethods<T, D, P> & ServiceOverloads<T, D, P>;
62
+ export declare type ServiceInterface<T = any, D = Partial<T>, P = Params> = Partial<ServiceMethods<T, D, P>>;
63
+ export interface ServiceAddons<A = Application, S = Service> extends EventEmitter {
32
64
  id?: string;
33
65
  hooks(options: HookOptions<A, S>): this;
34
66
  }
35
- export interface ServiceHookOverloads<S> {
36
- find(params: Params, context: HookContext): Promise<HookContext>;
37
- get(id: Id, params: Params, context: HookContext): Promise<HookContext>;
38
- create(data: ServiceGenericData<S> | ServiceGenericData<S>[], params: Params, context: HookContext): Promise<HookContext>;
39
- update(id: NullableId, data: ServiceGenericData<S>, params: Params, context: HookContext): Promise<HookContext>;
40
- patch(id: NullableId, data: ServiceGenericData<S>, params: Params, context: HookContext): Promise<HookContext>;
41
- remove(id: NullableId, params: Params, context: HookContext): Promise<HookContext>;
67
+ export interface ServiceHookOverloads<S, P = Params> {
68
+ find(params: P, context: HookContext): Promise<HookContext>;
69
+ get(id: Id, params: P, context: HookContext): Promise<HookContext>;
70
+ create(data: ServiceGenericData<S> | ServiceGenericData<S>[], params: P, context: HookContext): Promise<HookContext>;
71
+ update(id: NullableId, data: ServiceGenericData<S>, params: P, context: HookContext): Promise<HookContext>;
72
+ patch(id: NullableId, data: ServiceGenericData<S>, params: P, context: HookContext): Promise<HookContext>;
73
+ remove(id: NullableId, params: P, context: HookContext): Promise<HookContext>;
42
74
  }
43
- export declare type FeathersService<A = FeathersApplication, S = Service<any>> = S & ServiceAddons<A, S> & OptionalPick<ServiceHookOverloads<S>, keyof S>;
44
- export declare type CustomMethod<Methods extends string> = {
45
- [k in Methods]: <X = any>(data: any, params?: Params) => Promise<X>;
75
+ export declare type FeathersService<A = FeathersApplication, S = Service> = S & ServiceAddons<A, S> & OptionalPick<ServiceHookOverloads<S>, keyof S>;
76
+ export declare type CustomMethods<T extends {
77
+ [key: string]: [any, any];
78
+ }> = {
79
+ [K in keyof T]: (data: T[K][0], params?: Params) => Promise<T[K][1]>;
80
+ };
81
+ /**
82
+ * An interface usually use by transport clients that represents a e.g. HTTP or websocket
83
+ * connection that can be configured on the application.
84
+ */
85
+ export declare type TransportConnection<Services = any> = {
86
+ (app: Application<Services>): void;
87
+ Service: any;
88
+ service: <L extends keyof Services & string>(name: L) => keyof any extends keyof Services ? ServiceInterface : Services[L];
46
89
  };
47
- export declare type ServiceMixin<A> = (service: FeathersService<A>, path: string, options?: ServiceOptions) => void;
90
+ /**
91
+ * The interface for a custom service method. Can e.g. be used to type client side services.
92
+ */
93
+ export declare type CustomMethod<T = any, R = T, P extends Params = Params> = (data: T, params?: P) => Promise<R>;
94
+ export declare type ServiceMixin<A> = (service: FeathersService<A>, path: string, options: ServiceOptions) => void;
48
95
  export declare type ServiceGenericType<S> = S extends ServiceInterface<infer T> ? T : any;
49
96
  export declare type ServiceGenericData<S> = S extends ServiceInterface<infer _T, infer D> ? D : any;
50
- export interface FeathersApplication<ServiceTypes = any, AppSettings = any> {
97
+ export declare type ServiceGenericParams<S> = S extends ServiceInterface<infer _T, infer _D, infer P> ? P : any;
98
+ export interface FeathersApplication<Services = any, Settings = any> {
51
99
  /**
52
100
  * The Feathers application version
53
101
  */
@@ -55,40 +103,36 @@ export interface FeathersApplication<ServiceTypes = any, AppSettings = any> {
55
103
  /**
56
104
  * A list of callbacks that run when a new service is registered
57
105
  */
58
- mixins: ServiceMixin<Application<ServiceTypes, AppSettings>>[];
106
+ mixins: ServiceMixin<Application<Services, Settings>>[];
59
107
  /**
60
108
  * The index of all services keyed by their path.
61
109
  *
62
110
  * __Important:__ Services should always be retrieved via `app.service('name')`
63
111
  * not via `app.services`.
64
112
  */
65
- services: ServiceTypes;
113
+ services: Services;
66
114
  /**
67
115
  * The application settings that can be used via
68
116
  * `app.get` and `app.set`
69
117
  */
70
- settings: AppSettings;
118
+ settings: Settings;
71
119
  /**
72
120
  * A private-ish indicator if `app.setup()` has been called already
73
121
  */
74
122
  _isSetup: boolean;
75
- /**
76
- * Contains all registered application level hooks.
77
- */
78
- appHooks: HookMap<Application<ServiceTypes, AppSettings>, any>;
79
123
  /**
80
124
  * Retrieve an application setting by name
81
125
  *
82
126
  * @param name The setting name
83
127
  */
84
- get<L extends keyof AppSettings & string>(name: L): AppSettings[L];
128
+ get<L extends keyof Settings & string>(name: L): Settings[L];
85
129
  /**
86
130
  * Set an application setting
87
131
  *
88
132
  * @param name The setting name
89
133
  * @param value The setting value
90
134
  */
91
- set<L extends keyof AppSettings & string>(name: L, value: AppSettings[L]): this;
135
+ set<L extends keyof Settings & string>(name: L, value: Settings[L]): this;
92
136
  /**
93
137
  * Runs a callback configure function with the current application instance.
94
138
  *
@@ -102,7 +146,7 @@ export interface FeathersApplication<ServiceTypes = any, AppSettings = any> {
102
146
  *
103
147
  * @param location The path of the service
104
148
  */
105
- defaultService(location: string): ServiceInterface<any>;
149
+ defaultService(location: string): ServiceInterface;
106
150
  /**
107
151
  * Register a new service or a sub-app. When passed another
108
152
  * Feathers application, all its services will be re-registered
@@ -113,7 +157,13 @@ export interface FeathersApplication<ServiceTypes = any, AppSettings = any> {
113
157
  * Feathers application to use a sub-app under the `path` prefix.
114
158
  * @param options The options for this service
115
159
  */
116
- use<L extends keyof ServiceTypes & string>(path: L, service: keyof any extends keyof ServiceTypes ? ServiceInterface<any> | Application : ServiceTypes[L], options?: ServiceOptions): this;
160
+ use<L extends keyof Services & string>(path: L, service: keyof any extends keyof Services ? ServiceInterface | Application : Services[L], options?: ServiceOptions): this;
161
+ /**
162
+ * Unregister an existing service.
163
+ *
164
+ * @param path The name of the service to unregister
165
+ */
166
+ unuse<L extends keyof Services & string>(path: L): Promise<FeathersService<this, keyof any extends keyof Services ? Service : Services[L]>>;
117
167
  /**
118
168
  * Get the Feathers service instance for a path. This will
119
169
  * be the service originally registered with Feathers functionality
@@ -121,32 +171,58 @@ export interface FeathersApplication<ServiceTypes = any, AppSettings = any> {
121
171
  *
122
172
  * @param path The name of the service.
123
173
  */
124
- service<L extends keyof ServiceTypes & string>(path: L): FeathersService<this, keyof any extends keyof ServiceTypes ? Service<any> : ServiceTypes[L]>;
174
+ service<L extends keyof Services & string>(path: L): FeathersService<this, keyof any extends keyof Services ? Service : Services[L]>;
175
+ /**
176
+ * Set up the application and call all services `.setup` method if available.
177
+ *
178
+ * @param server A server instance (optional)
179
+ */
125
180
  setup(server?: any): Promise<this>;
181
+ /**
182
+ * Tear down the application and call all services `.teardown` method if available.
183
+ *
184
+ * @param server A server instance (optional)
185
+ */
186
+ teardown(server?: any): Promise<this>;
126
187
  /**
127
188
  * Register application level hooks.
128
189
  *
129
190
  * @param map The application hook settings.
130
191
  */
131
- hooks(map: HookOptions<this, any>): this;
192
+ hooks(map: ApplicationHookOptions<this>): this;
132
193
  }
133
- export interface Application<ServiceTypes = any, AppSettings = any> extends FeathersApplication<ServiceTypes, AppSettings>, EventEmitter {
194
+ export interface Application<Services = any, Settings = any> extends FeathersApplication<Services, Settings>, EventEmitter {
134
195
  }
135
196
  export declare type Id = number | string;
136
197
  export declare type NullableId = Id | null;
137
198
  export interface Query {
138
199
  [key: string]: any;
139
200
  }
140
- export interface Params {
141
- query?: Query;
201
+ export interface Params<Q = Query> {
202
+ query?: Q;
142
203
  provider?: string;
143
204
  route?: {
144
- [key: string]: string;
205
+ [key: string]: any;
145
206
  };
146
207
  headers?: {
147
208
  [key: string]: any;
148
209
  };
149
- [key: string]: any;
210
+ }
211
+ export interface Http {
212
+ /**
213
+ * A writeable, optional property with status code override.
214
+ */
215
+ status?: number;
216
+ /**
217
+ * A writeable, optional property with headers.
218
+ */
219
+ headers?: {
220
+ [key: string]: string | string[];
221
+ };
222
+ /**
223
+ * A writeable, optional property with `Location` header's value.
224
+ */
225
+ location?: string;
150
226
  }
151
227
  export interface HookContext<A = Application, S = any> extends BaseHookContext<ServiceGenericType<S>> {
152
228
  /**
@@ -198,7 +274,7 @@ export interface HookContext<A = Application, S = any> extends BaseHookContext<S
198
274
  * A writeable property that contains the service method parameters (including
199
275
  * params.query).
200
276
  */
201
- params: Params;
277
+ params: ServiceGenericParams<S>;
202
278
  /**
203
279
  * A writeable property containing the result of the successful service method call.
204
280
  * It is only available in after hooks.
@@ -218,28 +294,47 @@ export interface HookContext<A = Application, S = any> extends BaseHookContext<S
218
294
  /**
219
295
  * A writeable, optional property that allows to override the standard HTTP status
220
296
  * code that should be returned.
297
+ *
298
+ * @deprecated Use `http.status` instead.
221
299
  */
222
300
  statusCode?: number;
301
+ /**
302
+ * A writeable, optional property with options specific to HTTP transports.
303
+ */
304
+ http?: Http;
223
305
  /**
224
306
  * The event emitted by this method. Can be set to `null` to skip event emitting.
225
307
  */
226
308
  event: string | null;
227
309
  }
228
- export declare type LegacyHookFunction<A = Application, S = Service<any, any>> = (this: S, context: HookContext<A, S>) => (Promise<HookContext<Application, S> | void> | HookContext<Application, S> | void);
229
- export declare type Hook<A = Application, S = Service<any, any>> = LegacyHookFunction<A, S>;
230
- declare type LegacyHookMethodMap<A, S> = {
231
- [L in keyof S]?: SelfOrArray<LegacyHookFunction<A, S>>;
310
+ export declare type HookFunction<A = Application, S = Service> = (this: S, context: HookContext<A, S>) => Promise<HookContext<Application, S> | void> | HookContext<Application, S> | void;
311
+ export declare type Hook<A = Application, S = Service> = HookFunction<A, S>;
312
+ declare type HookMethodMap<A, S> = {
313
+ [L in keyof S]?: SelfOrArray<HookFunction<A, S>>;
232
314
  } & {
233
- all?: SelfOrArray<LegacyHookFunction<A, S>>;
315
+ all?: SelfOrArray<HookFunction<A, S>>;
234
316
  };
235
- declare type LegacyHookTypeMap<A, S> = SelfOrArray<LegacyHookFunction<A, S>> | LegacyHookMethodMap<A, S>;
236
- export declare type LegacyHookMap<A, S> = {
237
- before?: LegacyHookTypeMap<A, S>;
238
- after?: LegacyHookTypeMap<A, S>;
239
- error?: LegacyHookTypeMap<A, S>;
317
+ declare type HookTypeMap<A, S> = SelfOrArray<HookFunction<A, S>> | HookMethodMap<A, S>;
318
+ export declare type AroundHookFunction<A = Application, S = Service> = (context: HookContext<A, S>, next: NextFunction) => Promise<void>;
319
+ export declare type AroundHookMap<A, S> = {
320
+ [L in keyof S]?: AroundHookFunction<A, S>[];
321
+ } & {
322
+ all?: AroundHookFunction<A, S>[];
240
323
  };
241
- export declare type HookFunction<A = Application, S = Service<any, any>> = (context: HookContext<A, S>, next: NextFunction) => Promise<void>;
242
324
  export declare type HookMap<A, S> = {
243
- [L in keyof S]?: HookFunction<A, S>[];
325
+ around?: AroundHookMap<A, S>;
326
+ before?: HookTypeMap<A, S>;
327
+ after?: HookTypeMap<A, S>;
328
+ error?: HookTypeMap<A, S>;
329
+ };
330
+ export declare type HookOptions<A, S> = AroundHookMap<A, S> | AroundHookFunction<A, S>[] | HookMap<A, S>;
331
+ export interface ApplicationHookContext<A = Application> extends BaseHookContext {
332
+ app: A;
333
+ server: any;
334
+ }
335
+ export declare type ApplicationHookFunction<A> = (context: ApplicationHookContext<A>, next: NextFunction) => Promise<void>;
336
+ export declare type ApplicationHookMap<A> = {
337
+ setup?: ApplicationHookFunction<A>[];
338
+ teardown?: ApplicationHookFunction<A>[];
244
339
  };
245
- export declare type HookOptions<A, S> = HookMap<A, S> | HookFunction<A, S>[] | LegacyHookMap<A, S>;
340
+ export declare type ApplicationHookOptions<A> = HookOptions<A, any> | ApplicationHookMap<A>;