@feathersjs/express 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
package/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # @feathersjs/express
2
2
 
3
3
  [![CI](https://github.com/feathersjs/feathers/workflows/CI/badge.svg)](https://github.com/feathersjs/feathers/actions?query=workflow%3ACI)
4
- [![Dependency Status](https://img.shields.io/david/feathersjs/feathers.svg?style=flat-square&path=packages/express)](https://david-dm.org/feathersjs/feathers?path=packages/express)
5
4
  [![Download Status](https://img.shields.io/npm/dm/@feathersjs/express.svg?style=flat-square)](https://www.npmjs.com/package/@feathersjs/express)
5
+ [![Discord](https://badgen.net/badge/icon/discord?icon=discord&label)](https://discord.gg/qa8kez8QBx)
6
6
 
7
7
  > Feathers Express framework bindings and REST provider
8
8
 
@@ -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) 2021 [Feathers contributors](https://github.com/feathersjs/feathers/graphs/contributors)
21
+ Copyright (c) 2022 [Feathers contributors](https://github.com/feathersjs/feathers/graphs/contributors)
22
22
 
23
23
  Licensed under the [MIT license](LICENSE).
@@ -1,8 +1,7 @@
1
- import { NextFunction, RequestHandler } from 'express';
2
- declare type StrategyOptions = {
1
+ import { RequestHandler } from 'express';
2
+ export declare type AuthenticationSettings = {
3
3
  service?: string;
4
- strategies: string[];
4
+ strategies?: string[];
5
5
  };
6
- export declare function parseAuthentication(settings?: any): RequestHandler;
7
- export declare function authenticate(_settings: string | StrategyOptions, ..._strategies: string[]): (_req: Request, _res: Response, next: NextFunction) => void;
8
- export {};
6
+ export declare function parseAuthentication(settings?: AuthenticationSettings): RequestHandler;
7
+ export declare function authenticate(settings: string | AuthenticationSettings, ...strategies: string[]): RequestHandler;
@@ -2,55 +2,44 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.authenticate = exports.parseAuthentication = void 0;
4
4
  const commons_1 = require("@feathersjs/commons");
5
- const lodash_1 = require("lodash");
6
- const debug = commons_1.createDebug('@feathersjs/express/authentication');
7
- const normalizeStrategy = (_settings, ..._strategies) => typeof _settings === 'string'
8
- ? { strategies: lodash_1.flatten([_settings, ..._strategies]) }
9
- : _settings;
5
+ const authentication_1 = require("@feathersjs/authentication");
6
+ const debug = (0, commons_1.createDebug)('@feathersjs/express/authentication');
7
+ const toHandler = (func) => {
8
+ return (req, res, next) => func(req, res, next).catch((error) => next(error));
9
+ };
10
10
  function parseAuthentication(settings = {}) {
11
- return function (req, res, next) {
11
+ return toHandler(async (req, res, next) => {
12
+ var _a;
12
13
  const app = req.app;
13
- const service = app.defaultAuthentication ? app.defaultAuthentication(settings.service) : null;
14
- if (service === null) {
14
+ const service = (_a = app.defaultAuthentication) === null || _a === void 0 ? void 0 : _a.call(app, settings.service);
15
+ if (!service) {
15
16
  return next();
16
17
  }
17
18
  const config = service.configuration;
18
- const authStrategies = config.parseStrategies || config.authStrategies || [];
19
+ const authStrategies = settings.strategies || config.parseStrategies || config.authStrategies || [];
19
20
  if (authStrategies.length === 0) {
20
21
  debug('No `authStrategies` or `parseStrategies` found in authentication configuration');
21
22
  return next();
22
23
  }
23
- service.parse(req, res, ...authStrategies)
24
- .then((authentication) => {
25
- if (authentication) {
26
- debug('Parsed authentication from HTTP header', authentication);
27
- lodash_1.merge(req, {
28
- authentication,
29
- feathers: { authentication }
30
- });
31
- }
32
- next();
33
- }).catch(next);
34
- };
24
+ const authentication = await service.parse(req, res, ...authStrategies);
25
+ if (authentication) {
26
+ debug('Parsed authentication from HTTP header', authentication);
27
+ req.feathers = { ...req.feathers, authentication };
28
+ }
29
+ return next();
30
+ });
35
31
  }
36
32
  exports.parseAuthentication = parseAuthentication;
37
- function authenticate(_settings, ..._strategies) {
38
- const settings = normalizeStrategy(_settings, ..._strategies);
39
- if (!Array.isArray(settings.strategies) || settings.strategies.length === 0) {
40
- throw new Error('\'authenticate\' middleware requires at least one strategy name');
41
- }
42
- return (_req, _res, next) => {
43
- const req = _req;
44
- const { app, authentication } = req;
45
- const service = app.defaultAuthentication(settings.service);
46
- debug('Authenticating with Express middleware and strategies', settings.strategies);
47
- service.authenticate(authentication, req.feathers, ...settings.strategies)
48
- .then((authResult) => {
49
- debug('Merging request with', authResult);
50
- lodash_1.merge(req, authResult);
51
- next();
52
- }).catch(next);
53
- };
33
+ function authenticate(settings, ...strategies) {
34
+ const hook = (0, authentication_1.authenticate)(settings, ...strategies);
35
+ return toHandler(async (req, _res, next) => {
36
+ const app = req.app;
37
+ const params = req.feathers;
38
+ const context = { app, params };
39
+ await hook(context);
40
+ req.feathers = context.params;
41
+ return next();
42
+ });
54
43
  }
55
44
  exports.authenticate = authenticate;
56
45
  //# sourceMappingURL=authentication.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"authentication.js","sourceRoot":"","sources":["../src/authentication.ts"],"names":[],"mappings":";;;AAAA,iDAAkD;AAClD,mCAAwC;AAGxC,MAAM,KAAK,GAAG,qBAAW,CAAC,oCAAoC,CAAC,CAAC;AAOhE,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,GAAG,WAAW,CAAE,CAAC,EAAE;IACxD,CAAC,CAAC,SAAS,CAAC;AAEhB,SAAgB,mBAAmB,CAAE,WAAgB,EAAE;IACrD,OAAO,UAAU,GAAG,EAAE,GAAG,EAAE,IAAI;QAC7B,MAAM,GAAG,GAAG,GAAG,C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EnB,GAAG,CAAC,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAA;QAE7B,OAAO,IAAI,EAAE,CAAA;IACf,CAAC,CAAC,CAAA;AACJ,CAAC;AAjBD,oCAiBC"}
@@ -1,39 +1,44 @@
1
1
  /// <reference types="node" />
2
2
  import http from 'http';
3
3
  import express, { Express } from 'express';
4
- import { Application as FeathersApplication, Params as FeathersParams, HookContext, ServiceMethods, ServiceInterface } from '@feathersjs/feathers';
5
- interface ExpressUseHandler<T, ServiceTypes> {
6
- <L extends keyof ServiceTypes & string>(path: L, ...middlewareOrService: (Express | express.RequestHandler | (keyof any extends keyof ServiceTypes ? ServiceInterface<any> : ServiceTypes[L]))[]): T;
4
+ import { Application as FeathersApplication, Params as FeathersParams, HookContext, ServiceMethods, ServiceInterface, RouteLookup } from '@feathersjs/feathers';
5
+ interface ExpressUseHandler<T, Services> {
6
+ <L extends keyof Services & string>(path: L, ...middlewareOrService: (Express | express.RequestHandler | express.RequestHandler[] | (keyof any extends keyof Services ? ServiceInterface : Services[L]))[]): T;
7
7
  (path: string | RegExp, ...expressHandlers: express.RequestHandler[]): T;
8
8
  (...expressHandlers: express.RequestHandler[]): T;
9
9
  (handler: Express | express.ErrorRequestHandler): T;
10
10
  }
11
- export interface ExpressOverrides<ServiceTypes> {
11
+ export interface ExpressOverrides<Services> {
12
12
  listen(port: number, hostname: string, backlog: number, callback?: () => void): Promise<http.Server>;
13
13
  listen(port: number, hostname: string, callback?: () => void): Promise<http.Server>;
14
14
  listen(port: number | string | any, callback?: () => void): Promise<http.Server>;
15
15
  listen(callback?: () => void): Promise<http.Server>;
16
- use: ExpressUseHandler<this, ServiceTypes>;
16
+ use: ExpressUseHandler<this, Services>;
17
+ server?: http.Server;
17
18
  }
18
- export declare type Application<ServiceTypes = any, AppSettings = any> = Omit<Express, 'listen' | 'use'> & FeathersApplication<ServiceTypes, AppSettings> & ExpressOverrides<ServiceTypes>;
19
+ export declare type Application<Services = any, Settings = any> = Omit<Express, 'listen' | 'use' | 'get' | 'set'> & FeathersApplication<Services, Settings> & ExpressOverrides<Services>;
19
20
  declare module '@feathersjs/feathers/lib/declarations' {
20
21
  interface ServiceOptions {
21
- middleware?: {
22
- before: express.RequestHandler[];
23
- after: express.RequestHandler[];
22
+ express?: {
23
+ before?: express.RequestHandler[];
24
+ after?: express.RequestHandler[];
25
+ composed?: express.RequestHandler;
24
26
  };
25
27
  }
26
28
  }
27
29
  declare module 'express-serve-static-core' {
28
30
  interface Request {
29
- feathers?: Partial<FeathersParams>;
31
+ feathers?: Partial<FeathersParams> & {
32
+ [key: string]: any;
33
+ };
34
+ lookup?: RouteLookup;
30
35
  }
31
36
  interface Response {
32
37
  data?: any;
33
38
  hook?: HookContext;
34
39
  }
35
40
  interface IRouterMatcher<T> {
36
- <P extends Params = ParamsDictionary, ResBody = any, ReqBody = any>(path: PathParams, ...handlers: (RequestHandler<P, ResBody, ReqBody> | Partial<ServiceMethods<any, any>> | Application)[]): T;
41
+ <P extends Params = ParamsDictionary, ResBody = any, ReqBody = any>(path: PathParams, ...handlers: (RequestHandler<P, ResBody, ReqBody> | Partial<ServiceMethods> | Application)[]): T;
37
42
  }
38
43
  }
39
44
  export {};
package/lib/handlers.js CHANGED
@@ -45,9 +45,11 @@ function errorHandler(_options = {}) {
45
45
  }
46
46
  if (error.type !== 'FeathersError') {
47
47
  const oldError = error;
48
- error = oldError.errors ? new errors_1.GeneralError(oldError.message, {
49
- errors: oldError.errors
50
- }) : new errors_1.GeneralError(oldError.message);
48
+ error = oldError.errors
49
+ ? new errors_1.GeneralError(oldError.message, {
50
+ errors: oldError.errors
51
+ })
52
+ : new errors_1.GeneralError(oldError.message);
51
53
  if (oldError.stack) {
52
54
  error.stack = oldError.stack;
53
55
  }
@@ -1 +1 @@
1
- {"version":3,"file":"handlers.js","sourceRoot":"","sources":["../src/handlers.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AACxB,+CAA4D;AAG5D,MAAM,QAAQ,GAAG;IACf,MAA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IAAI,EAAE,CAAA;QAExC,iCAAiC;QACjC,IAAI,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE;YACxE,SAAS,CAAC,kBAAkB,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAA;SACrD;aAAM,IAAI,OAAO,CAAC,IAAI,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;YACjG,SAAS,CAAC,WAAW,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAA;SAC9C;aAAM;YACL,0CAA0C;YAC1C,SAAS,CAAC,kBAAkB,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAA;SACrD;IACH,CAAC,CAAA;AACH,CAAC;AAzGD,oCAyGC"}
package/lib/index.d.ts CHANGED
@@ -1,9 +1,10 @@
1
- import express, { Express, static as _static, json, raw, text, urlencoded, query } from 'express';
1
+ import { Express } from 'express';
2
2
  import { Application as FeathersApplication } from '@feathersjs/feathers';
3
- import { Application } from './declarations';
4
- import { errorHandler, notFound } from './handlers';
5
- import { parseAuthentication, authenticate } from './authentication';
6
- export { _static as static, json, raw, text, urlencoded, query, errorHandler, notFound, express as original, authenticate, parseAuthentication };
7
- export * from './rest';
8
- export * from './declarations';
3
+ import cors from 'cors';
4
+ import { rest, RestOptions, formatter } from './rest';
5
+ import { errorHandler, notFound, ErrorHandlerOptions } from './handlers';
6
+ import { Application, ExpressOverrides } from './declarations';
7
+ import { AuthenticationSettings, authenticate, parseAuthentication } from './authentication';
8
+ import { default as original, static as serveStatic, json, raw, text, urlencoded, query } from 'express';
9
+ export { original, serveStatic, serveStatic as static, json, raw, text, urlencoded, query, rest, RestOptions, formatter, errorHandler, notFound, Application, ErrorHandlerOptions, ExpressOverrides, AuthenticationSettings, parseAuthentication, authenticate, cors };
9
10
  export default function feathersExpress<S = any, C = any>(feathersApp?: FeathersApplication<S, C>, expressApp?: Express): Application<S, C>;
package/lib/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -18,49 +22,47 @@ var __importStar = (this && this.__importStar) || function (mod) {
18
22
  __setModuleDefault(result, mod);
19
23
  return result;
20
24
  };
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
- };
24
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
25
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
26
- return new (P || (P = Promise))(function (resolve, reject) {
27
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
28
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
29
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
30
- step((generator = generator.apply(thisArg, _arguments || [])).next());
31
- });
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
32
27
  };
33
28
  Object.defineProperty(exports, "__esModule", { value: true });
34
- exports.parseAuthentication = exports.authenticate = exports.original = exports.notFound = exports.errorHandler = exports.query = exports.urlencoded = exports.text = exports.raw = exports.json = exports.static = void 0;
35
- const express_1 = __importStar(require("express"));
36
- exports.original = express_1.default;
37
- Object.defineProperty(exports, "static", { enumerable: true, get: function () { return express_1.static; } });
38
- Object.defineProperty(exports, "json", { enumerable: true, get: function () { return express_1.json; } });
39
- Object.defineProperty(exports, "raw", { enumerable: true, get: function () { return express_1.raw; } });
40
- Object.defineProperty(exports, "text", { enumerable: true, get: function () { return express_1.text; } });
41
- Object.defineProperty(exports, "urlencoded", { enumerable: true, get: function () { return express_1.urlencoded; } });
42
- Object.defineProperty(exports, "query", { enumerable: true, get: function () { return express_1.query; } });
29
+ exports.cors = exports.authenticate = exports.parseAuthentication = exports.notFound = exports.errorHandler = exports.formatter = exports.rest = exports.query = exports.urlencoded = exports.text = exports.raw = exports.json = exports.static = exports.serveStatic = exports.original = void 0;
30
+ const express_1 = __importDefault(require("express"));
43
31
  const feathers_1 = require("@feathersjs/feathers");
32
+ const transport_commons_1 = require("@feathersjs/transport-commons");
44
33
  const commons_1 = require("@feathersjs/commons");
34
+ const cors_1 = __importDefault(require("cors"));
35
+ exports.cors = cors_1.default;
36
+ const rest_1 = require("./rest");
37
+ Object.defineProperty(exports, "rest", { enumerable: true, get: function () { return rest_1.rest; } });
38
+ Object.defineProperty(exports, "formatter", { enumerable: true, get: function () { return rest_1.formatter; } });
45
39
  const handlers_1 = require("./handlers");
46
40
  Object.defineProperty(exports, "errorHandler", { enumerable: true, get: function () { return handlers_1.errorHandler; } });
47
41
  Object.defineProperty(exports, "notFound", { enumerable: true, get: function () { return handlers_1.notFound; } });
48
42
  const authentication_1 = require("./authentication");
49
- Object.defineProperty(exports, "parseAuthentication", { enumerable: true, get: function () { return authentication_1.parseAuthentication; } });
50
43
  Object.defineProperty(exports, "authenticate", { enumerable: true, get: function () { return authentication_1.authenticate; } });
51
- __exportStar(require("./rest"), exports);
52
- __exportStar(require("./declarations"), exports);
53
- const debug = commons_1.createDebug('@feathersjs/express');
54
- function feathersExpress(feathersApp, expressApp = express_1.default()) {
44
+ Object.defineProperty(exports, "parseAuthentication", { enumerable: true, get: function () { return authentication_1.parseAuthentication; } });
45
+ const express_2 = __importStar(require("express"));
46
+ Object.defineProperty(exports, "original", { enumerable: true, get: function () { return express_2.default; } });
47
+ Object.defineProperty(exports, "serveStatic", { enumerable: true, get: function () { return express_2.static; } });
48
+ Object.defineProperty(exports, "static", { enumerable: true, get: function () { return express_2.static; } });
49
+ Object.defineProperty(exports, "json", { enumerable: true, get: function () { return express_2.json; } });
50
+ Object.defineProperty(exports, "raw", { enumerable: true, get: function () { return express_2.raw; } });
51
+ Object.defineProperty(exports, "text", { enumerable: true, get: function () { return express_2.text; } });
52
+ Object.defineProperty(exports, "urlencoded", { enumerable: true, get: function () { return express_2.urlencoded; } });
53
+ Object.defineProperty(exports, "query", { enumerable: true, get: function () { return express_2.query; } });
54
+ const debug = (0, commons_1.createDebug)('@feathersjs/express');
55
+ function feathersExpress(feathersApp, expressApp = (0, express_1.default)()) {
55
56
  if (!feathersApp) {
56
57
  return expressApp;
57
58
  }
58
59
  if (typeof feathersApp.setup !== 'function') {
59
60
  throw new Error('@feathersjs/express requires a valid Feathers application instance');
60
61
  }
61
- const { use, listen } = expressApp;
62
- // A mixin that provides the extended functionality
63
- const mixin = {
62
+ const app = expressApp;
63
+ const { use: expressUse, listen: expressListen } = expressApp;
64
+ const { use: feathersUse, teardown: feathersTeardown } = feathersApp;
65
+ Object.assign(app, {
64
66
  use(location, ...rest) {
65
67
  let service;
66
68
  let options = {};
@@ -71,7 +73,7 @@ function feathersExpress(feathersApp, expressApp = express_1.default()) {
71
73
  else if (!service) {
72
74
  service = arg;
73
75
  }
74
- else if (arg.methods || arg.events) {
76
+ else if (arg.methods || arg.events || arg.express || arg.koa) {
75
77
  options = arg;
76
78
  }
77
79
  else {
@@ -82,37 +84,59 @@ function feathersExpress(feathersApp, expressApp = express_1.default()) {
82
84
  before: [],
83
85
  after: []
84
86
  });
85
- const hasMethod = (methods) => methods.some(name => (service && typeof service[name] === 'function'));
87
+ const hasMethod = (methods) => methods.some((name) => service && typeof service[name] === 'function');
86
88
  // Check for service (any object with at least one service method)
87
89
  if (hasMethod(['handle', 'set']) || !hasMethod(feathers_1.defaultServiceMethods)) {
88
90
  debug('Passing app.use call to Express app');
89
- return use.call(this, location, ...rest);
91
+ return expressUse.call(this, location, ...rest);
90
92
  }
91
93
  debug('Registering service with middleware', middleware);
92
94
  // Since this is a service, call Feathers `.use`
93
- feathersApp.use.call(this, location, service, Object.assign(Object.assign({}, options), { middleware }));
95
+ feathersUse.call(this, location, service, {
96
+ express: middleware,
97
+ ...options
98
+ });
94
99
  return this;
95
100
  },
96
- listen(...args) {
97
- return __awaiter(this, void 0, void 0, function* () {
98
- const server = listen.call(this, ...args);
99
- yield this.setup(server);
100
- debug('Feathers application listening');
101
- return server;
102
- });
101
+ async listen(...args) {
102
+ const server = expressListen.call(this, ...args);
103
+ this.server = server;
104
+ await this.setup(server);
105
+ debug('Feathers application listening');
106
+ return server;
103
107
  }
108
+ });
109
+ const appDescriptors = {
110
+ ...Object.getOwnPropertyDescriptors(Object.getPrototypeOf(app)),
111
+ ...Object.getOwnPropertyDescriptors(app)
112
+ };
113
+ const newDescriptors = {
114
+ ...Object.getOwnPropertyDescriptors(Object.getPrototypeOf(feathersApp)),
115
+ ...Object.getOwnPropertyDescriptors(feathersApp)
104
116
  };
105
- const feathersDescriptors = Object.assign(Object.assign({}, Object.getOwnPropertyDescriptors(Object.getPrototypeOf(feathersApp))), Object.getOwnPropertyDescriptors(feathersApp));
106
117
  // Copy all non-existing properties (including non-enumerables)
107
118
  // that don't already exist on the Express app
108
- Object.keys(feathersDescriptors).forEach(prop => {
109
- const feathersProp = feathersDescriptors[prop];
110
- const expressProp = Object.getOwnPropertyDescriptor(expressApp, prop);
111
- if (expressProp === undefined && feathersProp !== undefined) {
112
- Object.defineProperty(expressApp, prop, feathersProp);
119
+ Object.keys(newDescriptors).forEach((prop) => {
120
+ const appProp = appDescriptors[prop];
121
+ const newProp = newDescriptors[prop];
122
+ if (appProp === undefined && newProp !== undefined) {
123
+ Object.defineProperty(expressApp, prop, newProp);
113
124
  }
114
125
  });
115
- return Object.assign(expressApp, mixin);
126
+ // Assign teardown and setup which will also make sure that hooks are initialized
127
+ app.setup = feathersApp.setup;
128
+ app.teardown = async function teardown(server) {
129
+ return feathersTeardown.call(this, server).then(() => new Promise((resolve, reject) => {
130
+ if (this.server) {
131
+ this.server.close((e) => (e ? reject(e) : resolve(this)));
132
+ }
133
+ else {
134
+ resolve(this);
135
+ }
136
+ }));
137
+ };
138
+ app.configure((0, transport_commons_1.routing)());
139
+ return app;
116
140
  }
117
141
  exports.default = feathersExpress;
118
142
  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,mDAEiB;AAYoB,mBAd9B,iBAAO,CAc+B;AADhC,uFAZQ,gBAAO,OAYT;AAAE,qFAZS,cAAI,OAYT;AAAE,oFAZS,aAAG,OAYT;AAAE,qFAZS,cAAI,OAYT;AAAE,2FAZS,oBAAU,OAYT;AAAE,sFAZS,eAAK,OAYT;AAVvD,mDAE8B;AAC9B,iDAAkD;AAGlD,yCAAoD;AAKlD,6FALO,uBAAY,OAKP;AAAE,yFALO,mBAAQ,OAKP;AAJxB,qDAAqE;AAKrD,oGALP,oCAAmB,OAKO;AAAjC,6FAL4B,6BAAY,OAK5B;AAGd,yCAAuB;AACvB,iDAA+B;AAE/B,MAAM,KAAK,GAAG,qBAAW,CAAC,qBAAqB,CAAC,CAAC;AAEjD,SAAwB,eAAe,CAAoB,WAAuC,EAAE,aAAsB,iBAAO,EAAE;IACjI,IAAI,CAAC,WAAW,EAAE;QAChB,OAAO,UAAiB,CAAC;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AAG,cAAc,CAAC,IAAI,CAAC,CAAA;QAEpC,IAAI,OAAO,KAAK,SAAS,IAAI,OAAO,KAAK,SAAS,EAAE;YAClD,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA;SACjD;IACH,CAAC,CAAC,CAAA;IAEF,iFAAiF;IACjF,GAAG,CAAC,KAAK,GAAG,WAAW,CAAC,KAAY,CAAA;IACpC,GAAG,CAAC,QAAQ,GAAG,KAAK,UAAU,QAAQ,CAAC,MAAY;QACjD,OAAO,gBAAgB,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,IAAI,CAC7C,GAAG,EAAE,CACH,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC9B,IAAI,IAAI,CAAC,MAAM,EAAE;gBACf,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;aAC1D;iBAAM;gBACL,OAAO,CAAC,IAAI,CAAC,CAAA;aACd;QACH,CAAC,CAAC,CACL,CAAA;IACH,CAAC,CAAA;IAED,GAAG,CAAC,SAAS,CAAC,IAAA,2BAAO,GAAS,CAAC,CAAA;IAE/B,OAAO,GAAG,CAAA;AACZ,CAAC;AA5GD,kCA4GC;AAED,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;IACjC,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,eAAe,EAAE,MAAM,CAAC,OAAO,CAAC,CAAA;CAChE"}
package/lib/rest.d.ts CHANGED
@@ -1,21 +1,9 @@
1
- import { HookContext } from '@feathersjs/hooks';
2
- import { NullableId, Params } from '@feathersjs/feathers';
3
- import { Request, Response, NextFunction, RequestHandler } from 'express';
4
- export declare const METHOD_HEADER = "x-service-method";
5
- export interface ServiceParams {
6
- id: NullableId;
7
- data: any;
8
- params: Params;
9
- }
10
- export declare type ServiceCallback = (req: Request, res: Response, options: ServiceParams) => Promise<HookContext | any>;
11
- export declare const statusCodes: {
12
- created: number;
13
- noContent: number;
14
- methodNotAllowed: number;
15
- success: number;
1
+ import { RequestHandler } from 'express';
2
+ import { AuthenticationSettings } from './authentication';
3
+ import { Application } from './declarations';
4
+ export declare const formatter: RequestHandler;
5
+ export declare type RestOptions = {
6
+ formatter?: RequestHandler;
7
+ authentication?: AuthenticationSettings;
16
8
  };
17
- export declare const feathersParams: (req: Request, _res: Response, next: NextFunction) => void;
18
- export declare const formatter: (_req: Request, res: Response, next: NextFunction) => void;
19
- export declare const serviceMiddleware: (callback: ServiceCallback) => (req: Request, res: Response, next: NextFunction) => Promise<void>;
20
- export declare const serviceMethodHandler: (service: any, methodName: string, getArgs: (opts: ServiceParams) => any[], headerOverride?: string) => (req: Request, res: Response, next: NextFunction) => Promise<void>;
21
- export declare function rest(handler?: RequestHandler): (this: any, app: any) => void;
9
+ export declare const rest: (options?: RestOptions | RequestHandler) => (app: Application) => void;