@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/CHANGELOG.md +240 -208
- package/LICENSE +1 -1
- package/{readme.md → README.md} +2 -5
- package/lib/application.d.ts +20 -15
- package/lib/application.js +88 -44
- package/lib/application.js.map +1 -1
- package/lib/declarations.d.ts +162 -67
- package/lib/events.d.ts +2 -2
- package/lib/events.js +5 -6
- package/lib/events.js.map +1 -1
- package/lib/hooks.d.ts +38 -0
- package/lib/hooks.js +157 -0
- package/lib/hooks.js.map +1 -0
- package/lib/index.d.ts +2 -2
- package/lib/index.js +8 -4
- package/lib/index.js.map +1 -1
- package/lib/service.d.ts +1 -0
- package/lib/service.js +17 -8
- package/lib/service.js.map +1 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/lib/version.js.map +1 -1
- package/package.json +17 -16
- package/src/application.ts +166 -99
- package/src/declarations.ts +231 -138
- package/src/events.ts +15 -15
- package/src/hooks.ts +215 -0
- package/src/index.ts +13 -12
- package/src/service.ts +34 -38
- package/src/version.ts +1 -1
- package/lib/dependencies.d.ts +0 -4
- package/lib/dependencies.js +0 -18
- package/lib/dependencies.js.map +0 -1
- package/lib/hooks/index.d.ts +0 -14
- package/lib/hooks/index.js +0 -84
- package/lib/hooks/index.js.map +0 -1
- package/lib/hooks/legacy.d.ts +0 -7
- package/lib/hooks/legacy.js +0 -114
- package/lib/hooks/legacy.js.map +0 -1
- package/src/dependencies.ts +0 -5
- package/src/hooks/index.ts +0 -109
- package/src/hooks/legacy.ts +0 -138
package/LICENSE
CHANGED
package/{readme.md → README.md}
RENAMED
|
@@ -2,14 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
## A framework for real-time applications and REST APIs with JavaScript and TypeScript
|
|
4
4
|
|
|
5
|
-
[](https://greenkeeper.io/)
|
|
6
5
|
[](https://github.com/feathersjs/feathers/actions?query=workflow%3ACI)
|
|
7
6
|
[](https://codeclimate.com/github/feathersjs/feathers/maintainability)
|
|
8
7
|
[](https://codeclimate.com/github/feathersjs/feathers/test_coverage)
|
|
9
8
|
[](https://www.npmjs.com/package/@feathersjs/feathers)
|
|
10
|
-
|
|
11
|
-
[](http://slack.feathersjs.com)
|
|
12
|
-
[](https://t.me/featherjs)
|
|
9
|
+
[](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)
|
|
35
|
+
Copyright (c) 2022 [Feathers contributors](https://github.com/feathersjs/feathers/graphs/contributors)
|
|
39
36
|
|
|
40
37
|
Licensed under the [MIT license](LICENSE).
|
package/lib/application.d.ts
CHANGED
|
@@ -1,21 +1,26 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { EventEmitter } from '
|
|
3
|
-
import { FeathersApplication, ServiceMixin, Service, ServiceOptions, ServiceInterface, Application,
|
|
4
|
-
export declare class Feathers<
|
|
5
|
-
services:
|
|
6
|
-
settings:
|
|
7
|
-
mixins: ServiceMixin<Application<
|
|
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
|
-
|
|
11
|
-
private legacyHooks;
|
|
10
|
+
protected registerHooks: (this: any, allHooks: any) => any;
|
|
12
11
|
constructor();
|
|
13
|
-
get<L extends keyof
|
|
14
|
-
set<L extends keyof
|
|
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
|
|
17
|
-
service<L extends keyof
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
setup(
|
|
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
|
}
|
package/lib/application.js
CHANGED
|
@@ -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
|
|
9
|
-
const
|
|
10
|
-
const
|
|
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
|
|
13
|
-
const debug =
|
|
14
|
-
class Feathers extends
|
|
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 = [
|
|
21
|
+
this.mixins = [hooks_2.hookMixin, events_2.eventMixin];
|
|
20
22
|
this.version = version_1.default;
|
|
21
23
|
this._isSetup = false;
|
|
22
|
-
this.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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 = (
|
|
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 = (
|
|
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(
|
|
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
|
|
76
|
-
if (
|
|
77
|
-
|
|
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 (
|
|
80
|
-
|
|
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
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
package/lib/application.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"application.js","sourceRoot":"","sources":["../src/application.ts"],"names":[],"mappings":";;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"application.js","sourceRoot":"","sources":["../src/application.ts"],"names":[],"mappings":";;;;;;AAAA,wDAA+B;AAC/B,mCAAqC;AACrC,iDAA+D;AAC/D,6CAA4D;AAC5D,qCAAgD;AAChD,mCAAmC;AACnC,uCAA4E;AAW5E,mCAAqC;AAErC,MAAM,KAAK,GAAG,IAAA,qBAAW,EAAC,sBAAsB,CAAC,CAAA;AAEjD,MAAa,QACX,SAAQ,qBAAY;IAWpB;QACE,KAAK,EAAE,CAAA;QATT,aAAQ,GAAa,EAAc,CAAA;QAC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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"}
|
package/lib/declarations.d.ts
CHANGED
|
@@ -1,53 +1,101 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { EventEmitter
|
|
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
|
|
12
|
-
find(params?:
|
|
13
|
-
get(id: Id, params?:
|
|
14
|
-
create(data:
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
patch
|
|
26
|
-
remove
|
|
27
|
-
|
|
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
|
|
30
|
-
|
|
31
|
-
|
|
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:
|
|
37
|
-
get(id: Id, params:
|
|
38
|
-
create(data: ServiceGenericData<S> | ServiceGenericData<S>[], params:
|
|
39
|
-
update(id: NullableId, data: ServiceGenericData<S>, params:
|
|
40
|
-
patch(id: NullableId, data: ServiceGenericData<S>, params:
|
|
41
|
-
remove(id: NullableId, params:
|
|
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
|
|
44
|
-
export declare type
|
|
45
|
-
[
|
|
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
|
-
|
|
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
|
|
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<
|
|
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:
|
|
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:
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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:
|
|
192
|
+
hooks(map: ApplicationHookOptions<this>): this;
|
|
132
193
|
}
|
|
133
|
-
export interface Application<
|
|
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?:
|
|
201
|
+
export interface Params<Q = Query> {
|
|
202
|
+
query?: Q;
|
|
142
203
|
provider?: string;
|
|
143
204
|
route?: {
|
|
144
|
-
[key: string]:
|
|
205
|
+
[key: string]: any;
|
|
145
206
|
};
|
|
146
207
|
headers?: {
|
|
147
208
|
[key: string]: any;
|
|
148
209
|
};
|
|
149
|
-
|
|
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:
|
|
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
|
|
229
|
-
export declare type Hook<A = Application, S = Service
|
|
230
|
-
declare type
|
|
231
|
-
[L in keyof S]?: SelfOrArray<
|
|
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<
|
|
315
|
+
all?: SelfOrArray<HookFunction<A, S>>;
|
|
234
316
|
};
|
|
235
|
-
declare type
|
|
236
|
-
export declare type
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
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
|
-
|
|
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
|
|
340
|
+
export declare type ApplicationHookOptions<A> = HookOptions<A, any> | ApplicationHookMap<A>;
|