@feathersjs/feathers 5.0.0-pre.10

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.
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.enableLegacyHooks = exports.convertHookData = exports.collectLegacyHooks = exports.fromErrorHooks = exports.fromAfterHook = exports.fromBeforeHook = void 0;
4
+ const dependencies_1 = require("../dependencies");
5
+ const { each } = dependencies_1._;
6
+ function fromBeforeHook(hook) {
7
+ return (context, next) => {
8
+ context.type = 'before';
9
+ return Promise.resolve(hook.call(context.self, context)).then(() => {
10
+ context.type = null;
11
+ return next();
12
+ });
13
+ };
14
+ }
15
+ exports.fromBeforeHook = fromBeforeHook;
16
+ function fromAfterHook(hook) {
17
+ return (context, next) => {
18
+ return next().then(() => {
19
+ context.type = 'after';
20
+ return hook.call(context.self, context);
21
+ }).then(() => {
22
+ context.type = null;
23
+ });
24
+ };
25
+ }
26
+ exports.fromAfterHook = fromAfterHook;
27
+ function fromErrorHooks(hooks) {
28
+ return (context, next) => {
29
+ return next().catch((error) => {
30
+ let promise = Promise.resolve();
31
+ context.original = { ...context };
32
+ context.error = error;
33
+ context.type = 'error';
34
+ delete context.result;
35
+ for (const hook of hooks) {
36
+ promise = promise.then(() => hook.call(context.self, context));
37
+ }
38
+ return promise.then(() => {
39
+ context.type = null;
40
+ if (context.result === undefined) {
41
+ throw context.error;
42
+ }
43
+ });
44
+ });
45
+ };
46
+ }
47
+ exports.fromErrorHooks = fromErrorHooks;
48
+ function collectLegacyHooks(target, method) {
49
+ const { before: { [method]: before = [] }, after: { [method]: after = [] }, error: { [method]: error = [] } } = target.__hooks;
50
+ const beforeHooks = before;
51
+ const afterHooks = [...after].reverse();
52
+ const errorHook = fromErrorHooks(error);
53
+ return [errorHook, ...beforeHooks, ...afterHooks];
54
+ }
55
+ exports.collectLegacyHooks = collectLegacyHooks;
56
+ // Converts different hook registration formats into the
57
+ // same internal format
58
+ function convertHookData(obj) {
59
+ let hook = {};
60
+ if (Array.isArray(obj)) {
61
+ hook = { all: obj };
62
+ }
63
+ else if (typeof obj !== 'object') {
64
+ hook = { all: [obj] };
65
+ }
66
+ else {
67
+ each(obj, function (value, key) {
68
+ hook[key] = !Array.isArray(value) ? [value] : value;
69
+ });
70
+ }
71
+ return hook;
72
+ }
73
+ exports.convertHookData = convertHookData;
74
+ // Add `.hooks` functionality to an object
75
+ function enableLegacyHooks(obj, methods = ['find', 'get', 'create', 'update', 'patch', 'remove'], types = ['before', 'after', 'error']) {
76
+ const hookData = {};
77
+ types.forEach(type => {
78
+ // Initialize properties where hook functions are stored
79
+ hookData[type] = {};
80
+ });
81
+ // Add non-enumerable `__hooks` property to the object
82
+ Object.defineProperty(obj, '__hooks', {
83
+ configurable: true,
84
+ value: hookData,
85
+ writable: true
86
+ });
87
+ return function legacyHooks(allHooks) {
88
+ each(allHooks, (current, type) => {
89
+ if (!this.__hooks[type]) {
90
+ throw new Error(`'${type}' is not a valid hook type`);
91
+ }
92
+ const hooks = convertHookData(current);
93
+ each(hooks, (_value, method) => {
94
+ if (method !== 'all' && methods.indexOf(method) === -1) {
95
+ throw new Error(`'${method}' is not a valid hook method`);
96
+ }
97
+ });
98
+ methods.forEach(method => {
99
+ let currentHooks = [...(hooks.all || []), ...(hooks[method] || [])];
100
+ this.__hooks[type][method] = this.__hooks[type][method] || [];
101
+ if (type === 'before') {
102
+ currentHooks = currentHooks.map(fromBeforeHook);
103
+ }
104
+ if (type === 'after') {
105
+ currentHooks = currentHooks.map(fromAfterHook);
106
+ }
107
+ this.__hooks[type][method].push(...currentHooks);
108
+ });
109
+ });
110
+ return this;
111
+ };
112
+ }
113
+ exports.enableLegacyHooks = enableLegacyHooks;
114
+ //# sourceMappingURL=legacy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"legacy.js","sourceRoot":"","sources":["../../src/hooks/legacy.ts"],"names":[],"mappings":";;;AAAA,kDAAoC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AAC;YAEvC,IAAI,CAAC,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE;gBAC7B,IAAI,MAAM,KAAK,KAAK,IAAI,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE;oBACtD,MAAM,IAAI,KAAK,CAAC,IAAI,MAAM,8BAA8B,CAAC,CAAC;iBAC3D;YACH,CAAC,CAAC,CAAC;YAEH,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;gBACvB,IAAI,YAAY,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,IAAI,EAAE,CAAC,EAAE,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;gBAEpE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;gBAE9D,IAAI,IAAI,KAAK,QAAQ,EAAE;oBACrB,YAAY,GAAG,YAAY,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;iBACjD;gBAED,IAAI,IAAI,KAAK,OAAO,EAAE;oBACpB,YAAY,GAAG,YAAY,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;iBAChD;gBAED,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,YAAY,CAAC,CAAC;YACnD,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC;IACd,CAAC,CAAA;AACH,CAAC;AApDD,8CAoDC"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ import version from './version';
2
+ import { Feathers } from './application';
3
+ import { Application } from './declarations';
4
+ export declare function feathers<T = any, S = any>(): Application<T, S>;
5
+ export declare namespace feathers {
6
+ var setDebug: typeof import("@feathersjs/commons/lib/debug").setDebug;
7
+ }
8
+ export { version, Feathers };
9
+ export * from './hooks/index';
10
+ export * from './declarations';
11
+ export * from './service';
package/lib/index.js ADDED
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ var __importDefault = (this && this.__importDefault) || function (mod) {
13
+ return (mod && mod.__esModule) ? mod : { "default": mod };
14
+ };
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.Feathers = exports.version = exports.feathers = void 0;
17
+ const dependencies_1 = require("./dependencies");
18
+ const version_1 = __importDefault(require("./version"));
19
+ exports.version = version_1.default;
20
+ const application_1 = require("./application");
21
+ Object.defineProperty(exports, "Feathers", { enumerable: true, get: function () { return application_1.Feathers; } });
22
+ function feathers() {
23
+ return new application_1.Feathers();
24
+ }
25
+ exports.feathers = feathers;
26
+ feathers.setDebug = dependencies_1.setDebug;
27
+ __exportStar(require("./hooks/index"), exports);
28
+ __exportStar(require("./declarations"), exports);
29
+ __exportStar(require("./service"), exports);
30
+ if (typeof module !== 'undefined') {
31
+ module.exports = Object.assign(feathers, module.exports);
32
+ }
33
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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"}
@@ -0,0 +1,21 @@
1
+ import { ServiceOptions } from './declarations';
2
+ export declare const SERVICE: string | symbol;
3
+ export declare const defaultServiceArguments: {
4
+ find: string[];
5
+ get: string[];
6
+ create: string[];
7
+ update: string[];
8
+ patch: string[];
9
+ remove: string[];
10
+ };
11
+ export declare const defaultServiceMethods: string[];
12
+ export declare const defaultEventMap: {
13
+ create: string;
14
+ update: string;
15
+ patch: string;
16
+ remove: string;
17
+ };
18
+ export declare const protectedMethods: string[];
19
+ export declare function getHookMethods(service: any, options: ServiceOptions): string[];
20
+ export declare function getServiceOptions(service: any, options?: ServiceOptions): ServiceOptions;
21
+ export declare function wrapService(location: string, service: any, options: ServiceOptions): any;
package/lib/service.js ADDED
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.wrapService = exports.getServiceOptions = exports.getHookMethods = exports.protectedMethods = exports.defaultEventMap = exports.defaultServiceMethods = exports.defaultServiceArguments = exports.SERVICE = void 0;
4
+ const dependencies_1 = require("./dependencies");
5
+ exports.SERVICE = (0, dependencies_1.createSymbol)('@feathersjs/service');
6
+ exports.defaultServiceArguments = {
7
+ find: ['params'],
8
+ get: ['id', 'params'],
9
+ create: ['data', 'params'],
10
+ update: ['id', 'data', 'params'],
11
+ patch: ['id', 'data', 'params'],
12
+ remove: ['id', 'params']
13
+ };
14
+ exports.defaultServiceMethods = Object.keys(exports.defaultServiceArguments);
15
+ exports.defaultEventMap = {
16
+ create: 'created',
17
+ update: 'updated',
18
+ patch: 'patched',
19
+ remove: 'removed'
20
+ };
21
+ exports.protectedMethods = Object.keys(Object.prototype)
22
+ .concat(Object.keys(dependencies_1.EventEmitter.prototype))
23
+ .concat([
24
+ 'before',
25
+ 'after',
26
+ 'error',
27
+ 'hooks',
28
+ 'setup',
29
+ 'publish'
30
+ ]);
31
+ function getHookMethods(service, options) {
32
+ const { methods } = options;
33
+ return exports.defaultServiceMethods.filter(m => typeof service[m] === 'function' && !methods.includes(m)).concat(methods);
34
+ }
35
+ exports.getHookMethods = getHookMethods;
36
+ function getServiceOptions(service, options = {}) {
37
+ const existingOptions = service[exports.SERVICE];
38
+ if (existingOptions) {
39
+ return existingOptions;
40
+ }
41
+ const { methods = exports.defaultServiceMethods.filter(method => typeof service[method] === 'function'), events = service.events || [] } = options;
42
+ const { serviceEvents = Object.values(exports.defaultEventMap).concat(events) } = options;
43
+ return {
44
+ ...options,
45
+ events,
46
+ methods,
47
+ serviceEvents
48
+ };
49
+ }
50
+ exports.getServiceOptions = getServiceOptions;
51
+ function wrapService(location, service, options) {
52
+ // Do nothing if this is already an initialized
53
+ if (service[exports.SERVICE]) {
54
+ return service;
55
+ }
56
+ const protoService = Object.create(service);
57
+ const serviceOptions = getServiceOptions(service, options);
58
+ if (Object.keys(serviceOptions.methods).length === 0 && typeof service.setup !== 'function') {
59
+ throw new Error(`Invalid service object passed for path \`${location}\``);
60
+ }
61
+ Object.defineProperty(protoService, exports.SERVICE, {
62
+ value: serviceOptions
63
+ });
64
+ return protoService;
65
+ }
66
+ exports.wrapService = wrapService;
67
+ //# sourceMappingURL=service.js.map
@@ -0,0 +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,E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MAAM,CAAC,MAAM,CAAC,EAAE,CAC9C,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,UAAU,CACtC,EACD,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,EAAE,EAC9B,GAAG,OAAO,CAAC;IACZ,MAAM,EACJ,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC,uBAAe,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,EAC9D,GAAG,OAAO,CAAC;IAEZ,OAAO;QACL,GAAG,OAAO;QACV,MAAM;QACN,OAAO;QACP,aAAa;KACd,CAAC;AACJ,CAAC;AAzBD,8CAyBC;AAED,SAAgB,WAAW,CACzB,QAAgB,EAAE,OAAY,EAAE,OAAuB;IAEvD,+CAA+C;IAC/C,IAAI,OAAO,CAAC,eAAO,CAAC,EAAE;QACpB,OAAO,OAAO,CAAC;KAChB;IAED,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC5C,MAAM,cAAc,GAAG,iBAAiB,CAAC,OAAO,EAAE,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"}
@@ -0,0 +1,2 @@
1
+ declare const _default: "5.0.0-pre.10";
2
+ export default _default;
package/lib/version.js ADDED
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = '5.0.0-pre.10';
4
+ //# sourceMappingURL=version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":";;AAAA,kBAAe,cAAc,CAAC"}
package/package.json ADDED
@@ -0,0 +1,73 @@
1
+ {
2
+ "name": "@feathersjs/feathers",
3
+ "description": "A framework for real-time applications and REST API with JavaScript and TypeScript",
4
+ "version": "5.0.0-pre.10",
5
+ "homepage": "http://feathersjs.com",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git://github.com/feathersjs/feathers.git"
9
+ },
10
+ "keywords": [
11
+ "feathers",
12
+ "REST",
13
+ "socket.io",
14
+ "realtime"
15
+ ],
16
+ "main": "lib/",
17
+ "types": "lib/",
18
+ "author": {
19
+ "name": "Feathers contributors",
20
+ "email": "hello@feathersjs.com",
21
+ "url": "https://feathersjs.com"
22
+ },
23
+ "license": "MIT",
24
+ "funding": {
25
+ "type": "github",
26
+ "url": "https://github.com/sponsors/daffl"
27
+ },
28
+ "bugs": {
29
+ "url": "https://github.com/feathersjs/feathers/issues"
30
+ },
31
+ "directories": {
32
+ "lib": "lib"
33
+ },
34
+ "files": [
35
+ "CHANGELOG.md",
36
+ "LICENSE",
37
+ "README.md",
38
+ "src/**",
39
+ "lib/**",
40
+ "*.d.ts",
41
+ "*.js"
42
+ ],
43
+ "scripts": {
44
+ "write-version": "node -e \"console.log('export default \\'' + require('./package.json').version + '\\';')\" > src/version.ts",
45
+ "reset-version": "node -e \"console.log('export default \\'development\\';')\" > src/version.ts",
46
+ "prepublish": "npm run compile",
47
+ "version": "npm run write-version",
48
+ "publish": "npm run reset-version",
49
+ "compile": "shx rm -rf lib/ && tsc",
50
+ "test": "npm run compile && npm run mocha",
51
+ "mocha": "mocha --config ../../.mocharc.json --recursive test/"
52
+ },
53
+ "engines": {
54
+ "node": ">= 12"
55
+ },
56
+ "publishConfig": {
57
+ "access": "public"
58
+ },
59
+ "dependencies": {
60
+ "@feathersjs/commons": "^5.0.0-pre.10",
61
+ "@feathersjs/hooks": "^0.6.5",
62
+ "events": "^3.3.0"
63
+ },
64
+ "devDependencies": {
65
+ "@types/mocha": "^9.0.0",
66
+ "@types/node": "^16.9.4",
67
+ "mocha": "^9.1.1",
68
+ "shx": "^0.3.3",
69
+ "ts-node": "^10.2.1",
70
+ "typescript": "^4.4.3"
71
+ },
72
+ "gitHead": "a9f7865cce8db2305b7c0d2ef4a165c2724034ef"
73
+ }
package/readme.md ADDED
@@ -0,0 +1,36 @@
1
+ <img style="width: 100%; max-width: 400px;" src="http://feathersjs.com/img/feathers-logo-wide.png" alt="Feathers logo">
2
+
3
+ ## A framework for real-time applications and REST APIs with JavaScript and TypeScript
4
+
5
+ [![CI](https://github.com/feathersjs/feathers/workflows/CI/badge.svg)](https://github.com/feathersjs/feathers/actions?query=workflow%3ACI)
6
+ [![Maintainability](https://api.codeclimate.com/v1/badges/cb5ec42a2d0cc1a47a02/maintainability)](https://codeclimate.com/github/feathersjs/feathers/maintainability)
7
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/cb5ec42a2d0cc1a47a02/test_coverage)](https://codeclimate.com/github/feathersjs/feathers/test_coverage)
8
+ [![Download Status](https://img.shields.io/npm/dm/@feathersjs/feathers.svg?style=flat-square)](https://www.npmjs.com/package/@feathersjs/feathers)
9
+
10
+ Feathers is a lightweight web-framework for creating real-time applications and REST APIs using JavaScript or TypeScript.
11
+
12
+ Feathers can interact with any backend technology, supports over a dozen databases and works with any frontend technology like React, VueJS, Angular, React Native, Android or iOS.
13
+
14
+ ## Getting started
15
+
16
+ You can build your first real-time and REST API in just 4 commands:
17
+
18
+ ```bash
19
+ $ npm install -g @feathersjs/cli
20
+ $ mkdir my-new-app
21
+ $ cd my-new-app/
22
+ $ feathers generate app
23
+ $ npm start
24
+ ```
25
+
26
+ To learn more about Feathers visit the website at [feathersjs.com](http://feathersjs.com) or jump right into [the Feathers guides](http://docs.feathersjs.com/guides).
27
+
28
+ ## Documentation
29
+
30
+ The [Feathers docs](http://docs.feathersjs.com) are loaded with awesome stuff and tell you every thing you need to know about using and configuring Feathers.
31
+
32
+ ## License
33
+
34
+ Copyright (c) 2021 [Feathers contributors](https://github.com/feathersjs/feathers/graphs/contributors)
35
+
36
+ Licensed under the [MIT license](LICENSE).
@@ -0,0 +1,163 @@
1
+ import version from './version';
2
+ import {
3
+ EventEmitter, stripSlashes, createDebug, HOOKS
4
+ } from './dependencies';
5
+ import { eventHook, eventMixin } from './events';
6
+ import { hookMixin } from './hooks/index';
7
+ import { wrapService, getServiceOptions, protectedMethods } from './service';
8
+ import {
9
+ FeathersApplication,
10
+ ServiceMixin,
11
+ Service,
12
+ ServiceOptions,
13
+ ServiceInterface,
14
+ Application,
15
+ HookOptions,
16
+ FeathersService,
17
+ HookMap,
18
+ LegacyHookMap
19
+ } from './declarations';
20
+ import { enableLegacyHooks } from './hooks/legacy';
21
+
22
+ const debug = createDebug('@feathersjs/feathers');
23
+
24
+ export class Feathers<ServiceTypes, AppSettings> extends EventEmitter implements FeathersApplication<ServiceTypes, AppSettings> {
25
+ services: ServiceTypes = ({} as ServiceTypes);
26
+ settings: AppSettings = ({} as AppSettings);
27
+ mixins: ServiceMixin<Application<ServiceTypes, AppSettings>>[] = [ hookMixin, eventMixin ];
28
+ version: string = version;
29
+ _isSetup = false;
30
+ appHooks: HookMap<Application<ServiceTypes, AppSettings>, any> = {
31
+ [HOOKS]: [ (eventHook as any) ]
32
+ };
33
+
34
+ private legacyHooks: (this: any, allHooks: any) => any;
35
+
36
+ constructor () {
37
+ super();
38
+ this.legacyHooks = enableLegacyHooks(this);
39
+ }
40
+
41
+ get<L extends keyof AppSettings & string> (name: L): AppSettings[L] {
42
+ return this.settings[name];
43
+ }
44
+
45
+ set<L extends keyof AppSettings & string> (name: L, value: AppSettings[L]) {
46
+ this.settings[name] = value;
47
+ return this;
48
+ }
49
+
50
+ configure (callback: (this: this, app: this) => void) {
51
+ callback.call(this, this);
52
+
53
+ return this;
54
+ }
55
+
56
+ defaultService (location: string): ServiceInterface<any> {
57
+ throw new Error(`Can not find service '${location}'`);
58
+ }
59
+
60
+ service<L extends keyof ServiceTypes & string> (
61
+ location: L
62
+ ): FeathersService<this, keyof any extends keyof ServiceTypes ? Service<any> : ServiceTypes[L]> {
63
+ const path = (stripSlashes(location) || '/') as L;
64
+ const current = this.services[path];
65
+
66
+ if (typeof current === 'undefined') {
67
+ this.use(path, this.defaultService(path) as any);
68
+ return this.service(path);
69
+ }
70
+
71
+ return current as any;
72
+ }
73
+
74
+ use<L extends keyof ServiceTypes & string> (
75
+ path: L,
76
+ service: keyof any extends keyof ServiceTypes ? ServiceInterface<any> | Application : ServiceTypes[L],
77
+ options?: ServiceOptions
78
+ ): this {
79
+ if (typeof path !== 'string') {
80
+ throw new Error(`'${path}' is not a valid service path.`);
81
+ }
82
+
83
+ const location = (stripSlashes(path) || '/') as L;
84
+ const subApp = service as Application;
85
+ const isSubApp = typeof subApp.service === 'function' && subApp.services;
86
+
87
+ if (isSubApp) {
88
+ Object.keys(subApp.services).forEach(subPath =>
89
+ this.use(`${location}/${subPath}` as any, subApp.service(subPath) as any)
90
+ );
91
+
92
+ return this;
93
+ }
94
+
95
+ const protoService = wrapService(location, service, options);
96
+ const serviceOptions = getServiceOptions(service, options);
97
+
98
+ for (const name of protectedMethods) {
99
+ if (serviceOptions.methods.includes(name)) {
100
+ throw new Error(`'${name}' on service '${location}' is not allowed as a custom method name`);
101
+ }
102
+ }
103
+
104
+ debug(`Registering new service at \`${location}\``);
105
+
106
+ // Add all the mixins
107
+ this.mixins.forEach(fn => fn.call(this, protoService, location, serviceOptions));
108
+
109
+ // If we ran setup already, set this service up explicitly, this will not `await`
110
+ if (this._isSetup && typeof protoService.setup === 'function') {
111
+ debug(`Setting up service for \`${location}\``);
112
+ protoService.setup(this, location);
113
+ }
114
+
115
+ this.services[location] = protoService;
116
+
117
+ return this;
118
+ }
119
+
120
+ hooks (hookMap: HookOptions<this, any>) {
121
+ const legacyMap = hookMap as LegacyHookMap<this, any>;
122
+
123
+ if (legacyMap.before || legacyMap.after || legacyMap.error) {
124
+ return this.legacyHooks(legacyMap);
125
+ }
126
+
127
+ if (Array.isArray(hookMap)) {
128
+ this.appHooks[HOOKS].push(...hookMap as any);
129
+ } else {
130
+ const methodHookMap = hookMap as HookMap<Application<ServiceTypes, AppSettings>, any>;
131
+
132
+ Object.keys(methodHookMap).forEach(key => {
133
+ const methodHooks = this.appHooks[key] || [];
134
+
135
+ this.appHooks[key] = methodHooks.concat(methodHookMap[key]);
136
+ });
137
+ }
138
+
139
+ return this;
140
+ }
141
+
142
+ setup () {
143
+ let promise = Promise.resolve();
144
+
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(() => {
148
+ const service: any = this.service(path as any);
149
+
150
+ if (typeof service.setup === 'function') {
151
+ debug(`Setting up service for \`${path}\``);
152
+
153
+ return service.setup(this, path);
154
+ }
155
+ });
156
+ }
157
+
158
+ return promise.then(() => {
159
+ this._isSetup = true;
160
+ return this;
161
+ });
162
+ }
163
+ }