@feathersjs/express 5.0.0-pre.1 → 5.0.0-pre.15

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,173 @@
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.15](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.14...v5.0.0-pre.15) (2021-11-27)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * missing express types for Request, Response ([#2498](https://github.com/feathersjs/feathers/issues/2498)) ([ee67131](https://github.com/feathersjs/feathers/commit/ee67131bbaa24c54d3d781bdf8820015759ac488))
12
+ * **typescript:** Overall typing improvements ([#2478](https://github.com/feathersjs/feathers/issues/2478)) ([b8eb804](https://github.com/feathersjs/feathers/commit/b8eb804158556d9651a8607e3c3fda15e0bfd110))
13
+
14
+
15
+ ### Features
16
+
17
+ * **core:** add `context.http` and move `statusCode` there ([#2496](https://github.com/feathersjs/feathers/issues/2496)) ([b701bf7](https://github.com/feathersjs/feathers/commit/b701bf77fb83048aa1dffa492b3d77dd53f7b72b))
18
+ * **core:** Improve legacy hooks integration ([08c8b40](https://github.com/feathersjs/feathers/commit/08c8b40999bf3889c61a4d4fad97a2c4f78bafc9))
19
+
20
+
21
+
22
+
23
+
24
+ # [5.0.0-pre.14](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.13...v5.0.0-pre.14) (2021-10-13)
25
+
26
+ **Note:** Version bump only for package @feathersjs/express
27
+
28
+
29
+
30
+
31
+
32
+ # [5.0.0-pre.13](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.12...v5.0.0-pre.13) (2021-10-13)
33
+
34
+ **Note:** Version bump only for package @feathersjs/express
35
+
36
+
37
+
38
+
39
+
40
+ # [5.0.0-pre.12](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.11...v5.0.0-pre.12) (2021-10-12)
41
+
42
+ **Note:** Version bump only for package @feathersjs/express
43
+
44
+
45
+
46
+
47
+
48
+ # [5.0.0-pre.11](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.10...v5.0.0-pre.11) (2021-10-06)
49
+
50
+ **Note:** Version bump only for package @feathersjs/express
51
+
52
+
53
+
54
+
55
+
56
+ # [5.0.0-pre.10](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.9...v5.0.0-pre.10) (2021-09-19)
57
+
58
+ **Note:** Version bump only for package @feathersjs/express
59
+
60
+
61
+
62
+
63
+
64
+ # [5.0.0-pre.9](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.8...v5.0.0-pre.9) (2021-08-09)
65
+
66
+ **Note:** Version bump only for package @feathersjs/express
67
+
68
+
69
+
70
+
71
+
72
+ # [5.0.0-pre.8](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.7...v5.0.0-pre.8) (2021-08-09)
73
+
74
+ **Note:** Version bump only for package @feathersjs/express
75
+
76
+
77
+
78
+
79
+
80
+ # [5.0.0-pre.7](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.6...v5.0.0-pre.7) (2021-08-09)
81
+
82
+ **Note:** Version bump only for package @feathersjs/express
83
+
84
+
85
+
86
+
87
+
88
+ # [5.0.0-pre.6](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.5...v5.0.0-pre.6) (2021-08-08)
89
+
90
+ **Note:** Version bump only for package @feathersjs/express
91
+
92
+
93
+
94
+
95
+
96
+ # [5.0.0-pre.5](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.4...v5.0.0-pre.5) (2021-06-23)
97
+
98
+ **Note:** Version bump only for package @feathersjs/express
99
+
100
+
101
+
102
+
103
+
104
+ # [5.0.0-pre.4](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.3...v5.0.0-pre.4) (2021-05-13)
105
+
106
+
107
+ ### Features
108
+
109
+ * **koa:** KoaJS transport adapter ([#2315](https://github.com/feathersjs/feathers/issues/2315)) ([2554b57](https://github.com/feathersjs/feathers/commit/2554b57cf05731df58feeba9c12faab18e442107))
110
+
111
+
112
+
113
+
114
+
115
+ # [5.0.0-pre.3](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.2...v5.0.0-pre.3) (2021-04-21)
116
+
117
+
118
+ ### Bug Fixes
119
+
120
+ * **typescript:** Improve TypeScript backwards compatibility ([#2310](https://github.com/feathersjs/feathers/issues/2310)) ([f33be73](https://github.com/feathersjs/feathers/commit/f33be73fc46a533efb15df9aab0658e3240d3897))
121
+
122
+
123
+ ### Features
124
+
125
+ * **dependencies:** Remove direct debug dependency ([#2296](https://github.com/feathersjs/feathers/issues/2296)) ([501d416](https://github.com/feathersjs/feathers/commit/501d4164d30c6a126906dc640cdfdc82207ba34a))
126
+
127
+
128
+
129
+
130
+
131
+ # [5.0.0-pre.2](https://github.com/feathersjs/feathers/compare/v5.0.0-beta.1...v5.0.0-pre.2) (2021-04-06)
132
+
133
+ **Note:** Version bump only for package @feathersjs/express
134
+
135
+
136
+
137
+
138
+
139
+ # [5.0.0-beta.1](https://github.com/feathersjs/feathers/compare/v5.0.0-beta.0...v5.0.0-beta.1) (2021-04-03)
140
+
141
+ **Note:** Version bump only for package @feathersjs/express
142
+
143
+
144
+
145
+
146
+
147
+ # [5.0.0-beta.0](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.1...v5.0.0-beta.0) (2021-03-28)
148
+
149
+
150
+ ### Bug Fixes
151
+
152
+ * Resolve some type problems ([#2260](https://github.com/feathersjs/feathers/issues/2260)) ([a3d75fa](https://github.com/feathersjs/feathers/commit/a3d75fa29490e8a19412a12bc993ee7bb573068f))
153
+ * Update Grant usage and other dependencies ([#2264](https://github.com/feathersjs/feathers/issues/2264)) ([7b0f8fa](https://github.com/feathersjs/feathers/commit/7b0f8fad252419ed0ad0bf259cdf3104d322ab60))
154
+
155
+
156
+ ### Features
157
+
158
+ * **core:** Public custom service methods ([#2270](https://github.com/feathersjs/feathers/issues/2270)) ([e65abfb](https://github.com/feathersjs/feathers/commit/e65abfb5388df6c19a11c565cf1076a29f32668d))
159
+ * Application service types default to any ([#1566](https://github.com/feathersjs/feathers/issues/1566)) ([d93ba9a](https://github.com/feathersjs/feathers/commit/d93ba9a17edd20d3397bb00f4f6e82e804e42ed6))
160
+ * Feathers v5 core refactoring and features ([#2255](https://github.com/feathersjs/feathers/issues/2255)) ([2dafb7c](https://github.com/feathersjs/feathers/commit/2dafb7ce14ba57406aeec13d10ca45b1e709bee9))
161
+ * **core:** Remove Uberproto ([#2178](https://github.com/feathersjs/feathers/issues/2178)) ([ddf8821](https://github.com/feathersjs/feathers/commit/ddf8821f53317e6a378657f7d66acb03a037ee47))
162
+
163
+
164
+ ### BREAKING CHANGES
165
+
166
+ * **core:** Services no longer extend Uberproto objects and
167
+ `service.mixin()` is no longer available.
168
+
169
+
170
+
171
+
172
+
6
173
  # [5.0.0-pre.1](https://github.com/feathersjs/feathers/compare/v4.5.11...v5.0.0-pre.1) (2020-12-17)
7
174
 
8
175
 
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2020 Feathers
3
+ Copyright (c) 2021 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
package/README.md CHANGED
@@ -18,6 +18,6 @@ Refer to the [Feathers Express API documentation](https://docs.feathersjs.com/ap
18
18
 
19
19
  ## License
20
20
 
21
- Copyright (c) 2019 [Feathers contributors](https://github.com/feathersjs/client/graphs/contributors)
21
+ Copyright (c) 2021 [Feathers contributors](https://github.com/feathersjs/feathers/graphs/contributors)
22
22
 
23
23
  Licensed under the [MIT license](LICENSE).
@@ -1,4 +1,4 @@
1
- import { NextFunction, RequestHandler } from 'express';
1
+ import { NextFunction, RequestHandler, Request, Response } from 'express';
2
2
  declare type StrategyOptions = {
3
3
  service?: string;
4
4
  strategies: string[];
@@ -1,14 +1,11 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.authenticate = exports.parseAuthentication = void 0;
7
- const debug_1 = __importDefault(require("debug"));
4
+ const commons_1 = require("@feathersjs/commons");
8
5
  const lodash_1 = require("lodash");
9
- const debug = debug_1.default('@feathersjs/express/authentication');
6
+ const debug = (0, commons_1.createDebug)('@feathersjs/express/authentication');
10
7
  const normalizeStrategy = (_settings, ..._strategies) => typeof _settings === 'string'
11
- ? { strategies: lodash_1.flatten([_settings, ..._strategies]) }
8
+ ? { strategies: (0, lodash_1.flatten)([_settings, ..._strategies]) }
12
9
  : _settings;
13
10
  function parseAuthentication(settings = {}) {
14
11
  return function (req, res, next) {
@@ -27,7 +24,7 @@ function parseAuthentication(settings = {}) {
27
24
  .then((authentication) => {
28
25
  if (authentication) {
29
26
  debug('Parsed authentication from HTTP header', authentication);
30
- lodash_1.merge(req, {
27
+ (0, lodash_1.merge)(req, {
31
28
  authentication,
32
29
  feathers: { authentication }
33
30
  });
@@ -50,7 +47,7 @@ function authenticate(_settings, ..._strategies) {
50
47
  service.authenticate(authentication, req.feathers, ...settings.strategies)
51
48
  .then((authResult) => {
52
49
  debug('Merging request with', authResult);
53
- lodash_1.merge(req, authResult);
50
+ (0, lodash_1.merge)(req, authResult);
54
51
  next();
55
52
  }).catch(next);
56
53
  };
@@ -1 +1 @@
1
- {"version":3,"file":"authentication.js","sourceRoot":"","sources":["../src/authentication.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,mCAAwC;AAGxC,MAAM,KAAK,GAAG,eAAK,CAAC,oCAAoC,CAAC,CAAC;AAO1D,MAAM,iBAAiB,GAAG,CAAC,SAAiC,EAAE,GAAG,WAAqB,EAAE,EAAE,CACxF,OAAO,SAAS,KAAK,QAAQ;IAC3B,CAAC,CAAC,EAAE,UAAU,EAAE,gBAAO,CAAC,CAAE,SAAS,EAAE,GA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U,CAAC,IAAI,QAAQ,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE;QAC3E,MAAM,IAAI,KAAK,CAAC,iEAAiE,CAAC,CAAC;KACpF;IAED,OAAO,CAAC,IAAa,EAAE,IAAc,EAAE,IAAkB,EAAE,EAAE;QAC3D,MAAM,GAAG,GAAG,IAAW,CAAC;QACxB,MAAM,EAAE,GAAG,EAAE,cAAc,EAAE,GAAG,GAAG,CAAC;QACpC,MAAM,OAAO,GAAG,GAAG,CAAC,qBAAqB,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QAE5D,KAAK,CAAC,uDAAuD,EAAE,QAAQ,CAAC,UAAU,CAAC,CAAC;QAEpF,OAAO,CAAC,YAAY,CAAC,cAAc,EAAE,GAAG,CAAC,QAAQ,EAAE,GAAG,QAAQ,CAAC,UAAU,CAAC;aACvE,IAAI,CAAC,CAAC,UAAe,EAAE,EAAE;YACxB,KAAK,CAAC,sBAAsB,EAAE,UAAU,CAAC,CAAC;YAC1C,IAAA,cAAK,EAAC,GAAG,EAAE,UAAU,CAAC,CAAC;YAEvB,IAAI,EAAE,CAAC;QACT,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACnB,CAAC,CAAC;AACJ,CAAC;AAtBD,oCAsBC"}
@@ -0,0 +1,39 @@
1
+ /// <reference types="node" />
2
+ import http from 'http';
3
+ import express, { Express } from 'express';
4
+ import { Application as FeathersApplication, Params as FeathersParams, HookContext, ServiceMethods, ServiceInterface } from '@feathersjs/feathers';
5
+ interface ExpressUseHandler<T, Services> {
6
+ <L extends keyof Services & string>(path: L, ...middlewareOrService: (Express | express.RequestHandler | (keyof any extends keyof Services ? ServiceInterface : Services[L]))[]): T;
7
+ (path: string | RegExp, ...expressHandlers: express.RequestHandler[]): T;
8
+ (...expressHandlers: express.RequestHandler[]): T;
9
+ (handler: Express | express.ErrorRequestHandler): T;
10
+ }
11
+ export interface ExpressOverrides<Services> {
12
+ listen(port: number, hostname: string, backlog: number, callback?: () => void): Promise<http.Server>;
13
+ listen(port: number, hostname: string, callback?: () => void): Promise<http.Server>;
14
+ listen(port: number | string | any, callback?: () => void): Promise<http.Server>;
15
+ listen(callback?: () => void): Promise<http.Server>;
16
+ use: ExpressUseHandler<this, Services>;
17
+ }
18
+ export declare type Application<Services = any, Settings = any> = Omit<Express, 'listen' | 'use'> & FeathersApplication<Services, Settings> & ExpressOverrides<Services>;
19
+ declare module '@feathersjs/feathers/lib/declarations' {
20
+ interface ServiceOptions {
21
+ middleware?: {
22
+ before: express.RequestHandler[];
23
+ after: express.RequestHandler[];
24
+ };
25
+ }
26
+ }
27
+ declare module 'express-serve-static-core' {
28
+ interface Request {
29
+ feathers?: Partial<FeathersParams>;
30
+ }
31
+ interface Response {
32
+ data?: any;
33
+ hook?: HookContext;
34
+ }
35
+ interface IRouterMatcher<T> {
36
+ <P extends Params = ParamsDictionary, ResBody = any, ReqBody = any>(path: PathParams, ...handlers: (RequestHandler<P, ResBody, ReqBody> | Partial<ServiceMethods> | Application)[]): T;
37
+ }
38
+ }
39
+ export {};
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=declarations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"declarations.js","sourceRoot":"","sources":["../src/declarations.ts"],"names":[],"mappings":""}
package/lib/index.d.ts CHANGED
@@ -1,21 +1,9 @@
1
1
  import express, { Express, static as _static, json, raw, text, urlencoded, query } from 'express';
2
- import { Application as FeathersApplication, Params as FeathersParams, HookContext, ServiceMethods, SetupMethod } from '@feathersjs/feathers';
2
+ import { Application as FeathersApplication } from '@feathersjs/feathers';
3
+ import { Application } from './declarations';
3
4
  import { errorHandler, notFound } from './handlers';
4
- import { rest } from './rest';
5
5
  import { parseAuthentication, authenticate } from './authentication';
6
- export { _static as static, json, raw, text, urlencoded, query, errorHandler, notFound, rest, express as original, authenticate, parseAuthentication };
7
- declare module 'express-serve-static-core' {
8
- interface Request {
9
- feathers?: Partial<FeathersParams>;
10
- }
11
- interface Response {
12
- data?: any;
13
- hook?: HookContext;
14
- }
15
- type FeathersService = Partial<ServiceMethods<any> & SetupMethod>;
16
- interface IRouterMatcher<T> {
17
- <P extends Params = ParamsDictionary, ResBody = any, ReqBody = any>(path: PathParams, ...handlers: (RequestHandler<P, ResBody, ReqBody> | FeathersService | Application)[]): T;
18
- }
19
- }
20
- export declare type Application<T = any> = Express & FeathersApplication<T>;
21
- export default function feathersExpress<T = any>(feathersApp?: FeathersApplication, expressApp?: Express): Application<T>;
6
+ export { _static as serveStatic, _static as static, json, raw, text, urlencoded, query, errorHandler, notFound, express as original, authenticate, parseAuthentication };
7
+ export * from './rest';
8
+ export * from './declarations';
9
+ export default function feathersExpress<S = any, C = any>(feathersApp?: FeathersApplication<S, C>, expressApp?: Express): Application<S, C>;
package/lib/index.js CHANGED
@@ -18,53 +18,54 @@ var __importStar = (this && this.__importStar) || function (mod) {
18
18
  __setModuleDefault(result, mod);
19
19
  return result;
20
20
  };
21
- var __importDefault = (this && this.__importDefault) || function (mod) {
22
- return (mod && mod.__esModule) ? mod : { "default": mod };
21
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
22
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
23
23
  };
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.parseAuthentication = exports.authenticate = exports.original = exports.rest = exports.notFound = exports.errorHandler = exports.query = exports.urlencoded = exports.text = exports.raw = exports.json = exports.static = void 0;
26
- // @ts-ignore
27
- const uberproto_1 = __importDefault(require("uberproto"));
25
+ exports.parseAuthentication = exports.authenticate = exports.original = exports.notFound = exports.errorHandler = exports.query = exports.urlencoded = exports.text = exports.raw = exports.json = exports.static = exports.serveStatic = void 0;
28
26
  const express_1 = __importStar(require("express"));
29
27
  exports.original = express_1.default;
28
+ Object.defineProperty(exports, "serveStatic", { enumerable: true, get: function () { return express_1.static; } });
30
29
  Object.defineProperty(exports, "static", { enumerable: true, get: function () { return express_1.static; } });
31
30
  Object.defineProperty(exports, "json", { enumerable: true, get: function () { return express_1.json; } });
32
31
  Object.defineProperty(exports, "raw", { enumerable: true, get: function () { return express_1.raw; } });
33
32
  Object.defineProperty(exports, "text", { enumerable: true, get: function () { return express_1.text; } });
34
33
  Object.defineProperty(exports, "urlencoded", { enumerable: true, get: function () { return express_1.urlencoded; } });
35
34
  Object.defineProperty(exports, "query", { enumerable: true, get: function () { return express_1.query; } });
36
- const debug_1 = __importDefault(require("debug"));
35
+ const feathers_1 = require("@feathersjs/feathers");
36
+ const commons_1 = require("@feathersjs/commons");
37
37
  const handlers_1 = require("./handlers");
38
38
  Object.defineProperty(exports, "errorHandler", { enumerable: true, get: function () { return handlers_1.errorHandler; } });
39
39
  Object.defineProperty(exports, "notFound", { enumerable: true, get: function () { return handlers_1.notFound; } });
40
- const rest_1 = require("./rest");
41
- Object.defineProperty(exports, "rest", { enumerable: true, get: function () { return rest_1.rest; } });
42
40
  const authentication_1 = require("./authentication");
43
41
  Object.defineProperty(exports, "parseAuthentication", { enumerable: true, get: function () { return authentication_1.parseAuthentication; } });
44
42
  Object.defineProperty(exports, "authenticate", { enumerable: true, get: function () { return authentication_1.authenticate; } });
45
- const debug = debug_1.default('@feathersjs/express');
46
- function feathersExpress(feathersApp, expressApp = express_1.default()) {
43
+ __exportStar(require("./rest"), exports);
44
+ __exportStar(require("./declarations"), exports);
45
+ const debug = (0, commons_1.createDebug)('@feathersjs/express');
46
+ function feathersExpress(feathersApp, expressApp = (0, express_1.default)()) {
47
47
  if (!feathersApp) {
48
48
  return expressApp;
49
49
  }
50
50
  if (typeof feathersApp.setup !== 'function') {
51
51
  throw new Error('@feathersjs/express requires a valid Feathers application instance');
52
52
  }
53
- if (!feathersApp.version || feathersApp.version < '3.0.0') {
54
- throw new Error(`@feathersjs/express requires an instance of a Feathers application version 3.x or later (got ${feathersApp.version || 'unknown'})`);
55
- }
56
- // An Uberproto mixin that provides the extended functionality
53
+ const { use, listen } = expressApp;
54
+ // A mixin that provides the extended functionality
57
55
  const mixin = {
58
- use(location) {
56
+ use(location, ...rest) {
59
57
  let service;
60
- const middleware = Array.from(arguments).slice(1)
61
- .reduce(function (middleware, arg) {
58
+ let options = {};
59
+ const middleware = rest.reduce(function (middleware, arg) {
62
60
  if (typeof arg === 'function' || Array.isArray(arg)) {
63
61
  middleware[service ? 'after' : 'before'].push(arg);
64
62
  }
65
63
  else if (!service) {
66
64
  service = arg;
67
65
  }
66
+ else if (arg.methods || arg.events) {
67
+ options = arg;
68
+ }
68
69
  else {
69
70
  throw new Error('Invalid options passed to app.use');
70
71
  }
@@ -75,32 +76,39 @@ function feathersExpress(feathersApp, expressApp = express_1.default()) {
75
76
  });
76
77
  const hasMethod = (methods) => methods.some(name => (service && typeof service[name] === 'function'));
77
78
  // Check for service (any object with at least one service method)
78
- if (hasMethod(['handle', 'set']) || !hasMethod(this.methods.concat('setup'))) {
79
+ if (hasMethod(['handle', 'set']) || !hasMethod(feathers_1.defaultServiceMethods)) {
79
80
  debug('Passing app.use call to Express app');
80
- return this._super.apply(this, arguments);
81
+ return use.call(this, location, ...rest);
81
82
  }
82
83
  debug('Registering service with middleware', middleware);
83
84
  // Since this is a service, call Feathers `.use`
84
- feathersApp.use.call(this, location, service, { middleware });
85
+ feathersApp.use.call(this, location, service, {
86
+ ...options,
87
+ middleware
88
+ });
85
89
  return this;
86
90
  },
87
- listen() {
88
- const server = this._super.apply(this, arguments);
89
- this.setup(server);
91
+ async listen(...args) {
92
+ const server = listen.call(this, ...args);
93
+ await this.setup(server);
90
94
  debug('Feathers application listening');
91
95
  return server;
92
96
  }
93
97
  };
98
+ const feathersDescriptors = {
99
+ ...Object.getOwnPropertyDescriptors(Object.getPrototypeOf(feathersApp)),
100
+ ...Object.getOwnPropertyDescriptors(feathersApp)
101
+ };
94
102
  // Copy all non-existing properties (including non-enumerables)
95
103
  // that don't already exist on the Express app
96
- Object.getOwnPropertyNames(feathersApp).forEach(prop => {
97
- const feathersProp = Object.getOwnPropertyDescriptor(feathersApp, prop);
104
+ Object.keys(feathersDescriptors).forEach(prop => {
105
+ const feathersProp = feathersDescriptors[prop];
98
106
  const expressProp = Object.getOwnPropertyDescriptor(expressApp, prop);
99
107
  if (expressProp === undefined && feathersProp !== undefined) {
100
108
  Object.defineProperty(expressApp, prop, feathersProp);
101
109
  }
102
110
  });
103
- return uberproto_1.default.mixin(mixin, expressApp);
111
+ return Object.assign(expressApp, mixin);
104
112
  }
105
113
  exports.default = feathersExpress;
106
114
  if (typeof module !== 'undefined') {
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,aAAa;AACb,0DAA8B;AAC9B,mDAAkG;AAavD,mBAbpC,iBAAO,CAaqC;AADtC,uFAZwB,gBAAO,OAYzB;AAAE,qFAZyB,cAAI,OAYzB;AAAE,oFAZyB,aAAG,OAYzB;AAAE,qFAZyB,cAAI,OAYzB;AAAE,2FAZyB,oBAAU,OAYzB;AAAE,sFAZyB,eAAK,OAYzB;AAXvD,kDAA0B;AAM1B,yCAAoD;AAMlD,6FANO,uBAAY,OAMP;AAAE,yFANO,mBAAQ,OAMP;AALxB,iCAA8B;AAKJ,qFALjB,WAAI,OAKiB;AAJ9B,qDAAqE;AAKrD,oGALP,oCAAmB,OAKO;AAAjC,6FAL4B,6BAAY,OAK5B;AAGd,MAAM,KAAK,GAAG,eAAK,CAAC,qBAAqB,CAAC,CAAC;AAyB3C,SAAwB,eAAe,CAAW,WAAiC,EAAE,aAAsB,iBAAO,EAAE;IAClH,IAAI,CAAC,WAAW,EAAE;QAChB,OAAO,UAAiB,CAAC;KAC1B;IAED,IAAI,OAAO,WAAW,CAAC,KAAK,KAAK,UAAU,EAAE;QAC3C,MAAM,IAAI,KAAK,CAAC,oEAAoE,CAAC,CAAC;KACvF;IA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AAM,CAAC,CAAC;YACzB,KAAK,CAAC,gCAAgC,CAAC,CAAC;YAExC,OAAO,MAAM,CAAC;QAChB,CAAC;KACF,CAAC;IAEF,MAAM,mBAAmB,GAAG;QAC1B,GAAG,MAAM,CAAC,yBAAyB,CAAC,MAAM,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC;QACvE,GAAG,MAAM,CAAC,yBAAyB,CAAC,WAAW,CAAC;KACjD,CAAC;IAEF,+DAA+D;IAC/D,8CAA8C;IAC9C,MAAM,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;QAC9C,MAAM,YAAY,GAAG,mBAAmB,CAAC,IAAI,CAAC,CAAC;QAC/C,MAAM,WAAW,GAAG,MAAM,CAAC,wBAAwB,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;QAEtE,IAAI,WAAW,KAAK,SAAS,IAAI,YAAY,KAAK,SAAS,EAAE;YAC3D,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC;SACvD;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;AAC1C,CAAC;AA/ED,kCA+EC;AAED,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;IACjC,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,eAAe,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;CACjE"}
package/lib/rest.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ import { http } from '@feathersjs/transport-commons';
2
+ import { HookContext } from '@feathersjs/feathers';
3
+ import { Request, Response, NextFunction, RequestHandler } from 'express';
4
+ export declare type ServiceCallback = (req: Request, res: Response, options: http.ServiceParams) => Promise<HookContext>;
5
+ export declare const feathersParams: (req: Request, _res: Response, next: NextFunction) => void;
6
+ export declare const formatter: (_req: Request, res: Response, next: NextFunction) => void;
7
+ export declare const serviceMiddleware: (callback: ServiceCallback) => (req: Request, res: Response, next: NextFunction) => Promise<void>;
8
+ export declare const serviceMethodHandler: (service: any, methodName: string, getArgs: (opts: http.ServiceParams) => any[], headerOverride?: string) => (req: Request, res: Response, next: NextFunction) => Promise<void>;
9
+ export declare function rest(handler?: RequestHandler): (this: any, app: any) => void;
package/lib/rest.js ADDED
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.rest = exports.serviceMethodHandler = exports.serviceMiddleware = exports.formatter = exports.feathersParams = void 0;
4
+ const errors_1 = require("@feathersjs/errors");
5
+ const commons_1 = require("@feathersjs/commons");
6
+ const transport_commons_1 = require("@feathersjs/transport-commons");
7
+ const feathers_1 = require("@feathersjs/feathers");
8
+ const express_1 = require("express");
9
+ const authentication_1 = require("./authentication");
10
+ const debug = (0, commons_1.createDebug)('@feathersjs/express/rest');
11
+ const feathersParams = (req, _res, next) => {
12
+ req.feathers = {
13
+ ...req.feathers,
14
+ provider: 'rest',
15
+ headers: req.headers
16
+ };
17
+ next();
18
+ };
19
+ exports.feathersParams = feathersParams;
20
+ const formatter = (_req, res, next) => {
21
+ if (res.data === undefined) {
22
+ return next();
23
+ }
24
+ res.format({
25
+ 'application/json'() {
26
+ res.json(res.data);
27
+ }
28
+ });
29
+ };
30
+ exports.formatter = formatter;
31
+ const serviceMiddleware = (callback) => async (req, res, next) => {
32
+ debug(`Running service middleware for '${req.url}'`);
33
+ try {
34
+ const { query, body: data } = req;
35
+ const { __feathersId: id = null, ...route } = req.params;
36
+ const params = { query, route, ...req.feathers };
37
+ const context = await callback(req, res, { id, data, params });
38
+ const result = transport_commons_1.http.getData(context);
39
+ res.data = result;
40
+ res.status(transport_commons_1.http.getStatusCode(context, result));
41
+ next();
42
+ }
43
+ catch (error) {
44
+ next(error);
45
+ }
46
+ };
47
+ exports.serviceMiddleware = serviceMiddleware;
48
+ const serviceMethodHandler = (service, methodName, getArgs, headerOverride) => (0, exports.serviceMiddleware)(async (req, res, options) => {
49
+ const methodOverride = typeof headerOverride === 'string' && req.headers[headerOverride];
50
+ const method = methodOverride ? methodOverride : methodName;
51
+ const { methods } = (0, feathers_1.getServiceOptions)(service);
52
+ if (!methods.includes(method) || feathers_1.defaultServiceMethods.includes(methodOverride)) {
53
+ res.status(transport_commons_1.http.statusCodes.methodNotAllowed);
54
+ throw new errors_1.MethodNotAllowed(`Method \`${method}\` is not supported by this endpoint.`);
55
+ }
56
+ const args = getArgs(options);
57
+ const context = (0, feathers_1.createContext)(service, method, { http: {} });
58
+ res.hook = context;
59
+ return service[method](...args, context);
60
+ });
61
+ exports.serviceMethodHandler = serviceMethodHandler;
62
+ function rest(handler = exports.formatter) {
63
+ return function (app) {
64
+ if (typeof app.route !== 'function') {
65
+ throw new Error('@feathersjs/express/rest needs an Express compatible app.');
66
+ }
67
+ app.use(exports.feathersParams);
68
+ app.use((0, authentication_1.parseAuthentication)());
69
+ // Register the REST provider
70
+ app.mixins.push(function (service, path, options) {
71
+ const { middleware: { before = [] } } = options;
72
+ let { middleware: { after = [] } } = options;
73
+ if (typeof handler === 'function') {
74
+ after = after.concat(handler);
75
+ }
76
+ const baseUri = `/${path}`;
77
+ const find = (0, exports.serviceMethodHandler)(service, 'find', transport_commons_1.http.argumentsFor.find);
78
+ const get = (0, exports.serviceMethodHandler)(service, 'get', transport_commons_1.http.argumentsFor.get);
79
+ const create = (0, exports.serviceMethodHandler)(service, 'create', transport_commons_1.http.argumentsFor.create, transport_commons_1.http.METHOD_HEADER);
80
+ const update = (0, exports.serviceMethodHandler)(service, 'update', transport_commons_1.http.argumentsFor.update);
81
+ const patch = (0, exports.serviceMethodHandler)(service, 'patch', transport_commons_1.http.argumentsFor.patch);
82
+ const remove = (0, exports.serviceMethodHandler)(service, 'remove', transport_commons_1.http.argumentsFor.remove);
83
+ debug(`Adding REST provider for service \`${path}\` at base route \`${baseUri}\``);
84
+ const idRoute = '/:__feathersId';
85
+ const serviceRouter = (0, express_1.Router)({ mergeParams: true })
86
+ .get('/', find)
87
+ .post('/', create)
88
+ .get(idRoute, get)
89
+ .put('/', update)
90
+ .put(idRoute, update)
91
+ .patch('/', patch)
92
+ .patch(idRoute, patch)
93
+ .delete('/', remove)
94
+ .delete(idRoute, remove);
95
+ app.use(baseUri, ...before, serviceRouter, ...after);
96
+ });
97
+ };
98
+ }
99
+ exports.rest = rest;
100
+ //# sourceMappingURL=rest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rest.js","sourceRoot":"","sources":["../src/rest.ts"],"names":[],"mappings":";;;AAAA,+CAAsD;AACtD,iDAAkD;AAClD,qEAAqD;AACrD,mDAA4G;AAC5G,qCAAkF;AAElF,qDAAuD;AAEvD,MAAM,KAAK,GAAG,IAAA,qBAAW,EAAC,0BAA0B,CAAC,CAAC;AAI/C,MAAM,cAAc,GAAG,CAAC,GAAY,EAAE,IAAc,EAAE,IAAkB,EAAE,EAAE;IACjF,GAAG,CAAC,QAAQ,GAAG;QACb,GAAG,GAAG,CAAC,QAAQ;QACf,QAAQ,EAAE,MAAM;QAChB,OAAO,EAAE,GAAG,CAAC,OAAO;KACrB,CAAC;IACF,IAAI,EAAE,CAAC;AACT,CAAC,CAAA;AAPY,QAAA,cAAc,kBAO1B;AAEM,MAAM,SAAS,GAAG,CAAC,IAAa,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE;IAC5E,IAAI,GAAG,CAAC,IAAI,KAAK,SAAS,EAAE;QAC1B,OAAO,IAAI,EAAE,CAAC;KACf;IAED,GAAG,CAAC,MAAM,CAAC;QACT,kBAAkB;YAChB,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACrB,CAAC;KACF,CAAC,CAAC;AACL,CAAC,CAAA;AAVY,QAAA,SAAS,aAUrB;AAGM,MAAM,iBAAiB,GAAG,CAAC,QAAyB,EAAE,EAAE,CAC7D,KAAK,EAAE,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE;IACxD,KAAK,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