@feathersjs/koa 5.0.0-pre.21 → 5.0.0-pre.24
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 +28 -0
- package/lib/authentication.js.map +1 -1
- package/lib/declarations.js.map +1 -1
- package/lib/handlers.js +6 -3
- package/lib/handlers.js.map +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.js +7 -6
- package/lib/index.js.map +1 -1
- package/lib/rest.js +1 -0
- package/lib/rest.js.map +1 -1
- package/package.json +13 -13
- package/src/authentication.ts +30 -30
- package/src/declarations.ts +19 -18
- package/src/handlers.ts +13 -11
- package/src/index.ts +54 -51
- package/src/rest.ts +58 -57
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,34 @@
|
|
|
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.24](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.23...v5.0.0-pre.24) (2022-06-21)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **cli:** Add support for JavaScript to the new CLI ([#2668](https://github.com/feathersjs/feathers/issues/2668)) ([ebac587](https://github.com/feathersjs/feathers/commit/ebac587f7d00dc7607c3f546352d79f79b89a5d4))
|
|
12
|
+
* **cli:** Initial Feathers v5 CLI and Pinion generator ([#2578](https://github.com/feathersjs/feathers/issues/2578)) ([7f59ae7](https://github.com/feathersjs/feathers/commit/7f59ae7f1471895ba8a82aa4702f1a23f71b7682))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
# [5.0.0-pre.23](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.22...v5.0.0-pre.23) (2022-06-06)
|
|
19
|
+
|
|
20
|
+
**Note:** Version bump only for package @feathersjs/koa
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
# [5.0.0-pre.22](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.21...v5.0.0-pre.22) (2022-05-24)
|
|
27
|
+
|
|
28
|
+
**Note:** Version bump only for package @feathersjs/koa
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
6
34
|
# [5.0.0-pre.21](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.20...v5.0.0-pre.21) (2022-05-23)
|
|
7
35
|
|
|
8
36
|
**Note:** Version bump only for package @feathersjs/koa
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authentication.js","sourceRoot":"","sources":["../src/authentication.ts"],"names":[],"mappings":";;;AACA,
|
|
1
|
+
{"version":3,"file":"authentication.js","sourceRoot":"","sources":["../src/authentication.ts"],"names":[],"mappings":";;;AACA,iDAAiD;AACjD,+DAA6E;AAI7E,MAAM,KAAK,GAAG,IAAA,qBAAW,EAAC,gCAAgC,CAAC,CAAA;AAO3D,SAAgB,mBAAmB,CAAC,WAAmC,EAAE;IACvE,OAAO,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;;QACzB,MAAM,GAAG,GAAG,GAAG,CAAC,GAAG,CAAA;QACnB,MAAM,OAAO,GAAG,MAAA,GAAG,CAAC,qBAAqB,oDAAG,QAAQ,CAAC,OAAO,CAAC,CAAA;QAE7D,IAAI,CAAC,OAAO,EAAE;YACZ,OAAO,IAAI,EAAE,CAAA;SACd;QAED,MAAM,MAAM,GAAG,OAAO,CAAC,aAAa,CAAA;QACpC,MAAM,cAAc,GAAG,QAAQ,CAAC,UAAU,IAAI,MAAM,CAAC,eAAe,IAAI,MAAM,CAAC,cAAc,IAAI,EAAE,CAAA;QAEnG,IAAI,cAAc,CAAC,MAAM,KAAK,CAAC,EAAE;YAC/B,KAAK,CAAC,gFAAgF,CAAC,CAAA;YACvF,OAAO,IAAI,EAAE,CAAA;SACd;QAED,MAAM,cAAc,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,GAAG,cAAc,CAAC,CAAA;QAE/E,IAAI,cAAc,EAAE;YAClB,KAAK,CAAC,wCAAwC,EAAE,cAAc,CAAC,CAAA;YAC/D,GAAG,CAAC,QAAQ,GAAG,EAAE,GAAG,GAAG,CAAC,QAAQ,EAAE,cAAc,EAAE,CAAA;SACnD;QAED,OAAO,IAAI,EAAE,CAAA;IACf,CAAC,CAAA;AACH,CAAC;AA1BD,kDA0BC;AAED,SAAgB,YAAY,CAAC,QAAyC,EAAE,GAAG,UAAoB;IAC7F,MAAM,IAAI,GAAG,IAAA,6BAAgB,EAAC,QAAQ,EAAE,GAAG,UAAU,CAAC,CAAA;IAEtD,OAAO,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QACzB,MAAM,GAAG,GAAG,GAAG,CAAC,GAAkB,CAAA;QAClC,MAAM,MAAM,GAAG,GAAG,CAAC,QAAQ,CAAA;QAC3B,MAAM,OAAO,GAAG,EAAE,GAAG,EAAE,MAAM,EAAiB,CAAA;QAE9C,MAAM,IAAI,CAAC,OAAO,CAAC,CAAA;QAEnB,GAAG,CAAC,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAA;QAE7B,OAAO,IAAI,EAAE,CAAA;IACf,CAAC,CAAA;AACH,CAAC;AAdD,oCAcC"}
|
package/lib/declarations.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"declarations.js","sourceRoot":"","sources":["../src/declarations.ts"],"names":[],"mappings":";;AAGA,
|
|
1
|
+
{"version":3,"file":"declarations.js","sourceRoot":"","sources":["../src/declarations.ts"],"names":[],"mappings":";;AAGA,sCAAmC"}
|
package/lib/handlers.js
CHANGED
|
@@ -11,9 +11,12 @@ const errorHandler = () => async (ctx, next) => {
|
|
|
11
11
|
}
|
|
12
12
|
catch (error) {
|
|
13
13
|
ctx.response.status = error.code || 500;
|
|
14
|
-
ctx.body =
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
ctx.body =
|
|
15
|
+
typeof error.toJSON === 'function'
|
|
16
|
+
? error.toJSON()
|
|
17
|
+
: {
|
|
18
|
+
message: error.message
|
|
19
|
+
};
|
|
17
20
|
}
|
|
18
21
|
};
|
|
19
22
|
exports.errorHandler = errorHandler;
|
package/lib/handlers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handlers.js","sourceRoot":"","sources":["../src/handlers.ts"],"names":[],"mappings":";;;AAAA,+
|
|
1
|
+
{"version":3,"file":"handlers.js","sourceRoot":"","sources":["../src/handlers.ts"],"names":[],"mappings":";;;AAAA,+CAA6C;AAGtC,MAAM,YAAY,GAAG,GAAG,EAAE,CAAC,KAAK,EAAE,GAAuB,EAAE,IAAwB,EAAE,EAAE;IAC5F,IAAI;QACF,MAAM,IAAI,EAAE,CAAA;QAEZ,IAAI,GAAG,CAAC,IAAI,KAAK,SAAS,EAAE;YAC1B,MAAM,IAAI,iBAAQ,CAAC,WAAW,CAAC,CAAA;SAChC;KACF;IAAC,OAAO,KAAU,EAAE;QACnB,GAAG,CAAC,QAAQ,CAAC,MAAM,GAAG,KAAK,CAAC,IAAI,IAAI,GAAG,CAAA;QACvC,GAAG,CAAC,IAAI;YACN,OAAO,KAAK,CAAC,MAAM,KAAK,UAAU;gBAChC,CAAC,CAAC,KAAK,CAAC,MAAM,EAAE;gBAChB,CAAC,CAAC;oBACE,OAAO,EAAE,KAAK,CAAC,OAAO;iBACvB,CAAA;KACR;AACH,CAAC,CAAA;AAhBY,QAAA,YAAY,gBAgBxB"}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import Koa from 'koa';
|
|
2
2
|
import { Application as FeathersApplication } from '@feathersjs/feathers';
|
|
3
|
+
import bodyParser from 'koa-bodyparser';
|
|
3
4
|
import { Application } from './declarations';
|
|
4
|
-
export {
|
|
5
|
-
export { default as bodyParser } from 'koa-bodyparser';
|
|
5
|
+
export { Koa, bodyParser };
|
|
6
6
|
export * from './authentication';
|
|
7
7
|
export * from './declarations';
|
|
8
8
|
export * from './handlers';
|
package/lib/index.js
CHANGED
|
@@ -19,13 +19,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
20
|
exports.koa = exports.bodyParser = exports.Koa = void 0;
|
|
21
21
|
const koa_1 = __importDefault(require("koa"));
|
|
22
|
+
exports.Koa = koa_1.default;
|
|
22
23
|
const koa_qs_1 = __importDefault(require("koa-qs"));
|
|
23
24
|
const transport_commons_1 = require("@feathersjs/transport-commons");
|
|
24
25
|
const commons_1 = require("@feathersjs/commons");
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
var koa_bodyparser_1 = require("koa-bodyparser");
|
|
28
|
-
Object.defineProperty(exports, "bodyParser", { enumerable: true, get: function () { return __importDefault(koa_bodyparser_1).default; } });
|
|
26
|
+
const koa_bodyparser_1 = __importDefault(require("koa-bodyparser"));
|
|
27
|
+
exports.bodyParser = koa_bodyparser_1.default;
|
|
29
28
|
__exportStar(require("./authentication"), exports);
|
|
30
29
|
__exportStar(require("./declarations"), exports);
|
|
31
30
|
__exportStar(require("./handlers"), exports);
|
|
@@ -56,7 +55,9 @@ function koa(feathersApp, koaApp = new koa_1.default()) {
|
|
|
56
55
|
return server;
|
|
57
56
|
},
|
|
58
57
|
async teardown(server) {
|
|
59
|
-
return feathersTeardown
|
|
58
|
+
return feathersTeardown
|
|
59
|
+
.call(this, server)
|
|
60
|
+
.then(() => new Promise((resolve, reject) => this.server.close((e) => (e ? reject(e) : resolve(this)))));
|
|
60
61
|
}
|
|
61
62
|
});
|
|
62
63
|
const appDescriptors = {
|
|
@@ -69,7 +70,7 @@ function koa(feathersApp, koaApp = new koa_1.default()) {
|
|
|
69
70
|
};
|
|
70
71
|
// Copy all non-existing properties (including non-enumerables)
|
|
71
72
|
// that don't already exist on the Express app
|
|
72
|
-
Object.keys(newDescriptors).forEach(prop => {
|
|
73
|
+
Object.keys(newDescriptors).forEach((prop) => {
|
|
73
74
|
const appProp = appDescriptors[prop];
|
|
74
75
|
const newProp = newDescriptors[prop];
|
|
75
76
|
if (appProp === undefined && newProp !== undefined) {
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,8CAAqB;AAQZ,cARF,aAAG,CAQE;AAPZ,oDAA0B;AAE1B,qEAAuD;AACvD,iDAAiD;AACjD,oEAAuC;AAGzB,qBAHP,wBAAU,CAGO;AACxB,mDAAgC;AAChC,iDAA8B;AAC9B,6CAA0B;AAC1B,yCAAsB;AAEtB,MAAM,KAAK,GAAG,IAAA,qBAAW,EAAC,iBAAiB,CAAC,CAAA;AAE5C,SAAgB,GAAG,CACjB,WAAuC,EACvC,SAAc,IAAI,aAAG,EAAE;IAEvB,IAAI,CAAC,WAAW,EAAE;QAChB,OAAO,MAAa,CAAA;KACrB;IAED,IAAI,OAAO,WAAW,CAAC,KAAK,KAAK,UAAU,EAAE;QAC3C,MAAM,IAAI,KAAK,CAAC,gEAAgE,CAAC,CAAA;KAClF;IAED,MAAM,GAAG,GAAG,WAAuC,CAAA;IACnD,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,MAAM,CAAA;IACjD,MAAM,EAAE,GAAG,EAAE,WAAW,EAAE,QAAQ,EAAE,gBAAgB,EAAE,GAAG,WAAW,CAAA;IAEpE,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE;QACjB,GAAG,CAAC,QAAiC,EAAE,GAAG,IAAW;YACnD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AG,MAAM,CAAC,yBAAyB,CAAC,MAAM,CAAC;KAC5C,CAAA;IAED,+DAA+D;IAC/D,8CAA8C;IAC9C,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QAC3C,MAAM,OAAO,GAAG,cAAc,CAAC,IAAI,CAAC,CAAA;QACpC,MAAM,OAAO,GAAG,cAAc,CAAC,IAAI,CAAC,CAAA;QAEpC,IAAI,OAAO,KAAK,SAAS,IAAI,OAAO,KAAK,SAAS,EAAE;YAClD,MAAM,CAAC,cAAc,CAAC,GAAG,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA;SAC1C;IACH,CAAC,CAAC,CAAA;IAEF,IAAA,gBAAK,EAAC,GAAU,CAAC,CAAA;IAEjB,GAAG,CAAC,SAAS,CAAC,IAAA,2BAAO,GAAS,CAAC,CAAA;IAC/B,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE;QACpB,GAAG,CAAC,QAAQ,GAAG,EAAE,GAAG,GAAG,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAA;QACpD,OAAO,IAAI,EAAE,CAAA;IACf,CAAC,CAAC,CAAA;IAEF,OAAO,GAAG,CAAA;AACZ,CAAC;AAzED,kBAyEC"}
|
package/lib/rest.js
CHANGED
package/lib/rest.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rest.js","sourceRoot":"","sources":["../src/rest.ts"],"names":[],"mappings":";;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"rest.js","sourceRoot":"","sources":["../src/rest.ts"],"names":[],"mappings":";;;;;;AAAA,8DAAiC;AACjC,qEAAoD;AACpD,iDAAiD;AACjD,mDAA8F;AAC9F,+CAAqD;AAGrD,qDAA8E;AAE9E,MAAM,KAAK,GAAG,IAAA,qBAAW,EAAC,sBAAsB,CAAC,CAAA;AAEjD,MAAM,iBAAiB,GAAG,GAAe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",
|
|
3
3
|
"description": "Feathers KoaJS framework bindings and REST provider",
|
|
4
|
-
"version": "5.0.0-pre.
|
|
4
|
+
"version": "5.0.0-pre.24",
|
|
5
5
|
"homepage": "https://feathersjs.com",
|
|
6
6
|
"main": "lib/",
|
|
7
7
|
"types": "lib/",
|
|
@@ -48,10 +48,10 @@
|
|
|
48
48
|
"access": "public"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@feathersjs/authentication": "^5.0.0-pre.
|
|
52
|
-
"@feathersjs/commons": "^5.0.0-pre.
|
|
53
|
-
"@feathersjs/errors": "^5.0.0-pre.
|
|
54
|
-
"@feathersjs/transport-commons": "^5.0.0-pre.
|
|
51
|
+
"@feathersjs/authentication": "^5.0.0-pre.24",
|
|
52
|
+
"@feathersjs/commons": "^5.0.0-pre.24",
|
|
53
|
+
"@feathersjs/errors": "^5.0.0-pre.24",
|
|
54
|
+
"@feathersjs/transport-commons": "^5.0.0-pre.24",
|
|
55
55
|
"@types/koa": "^2.13.4",
|
|
56
56
|
"@types/koa-bodyparser": "^4.3.7",
|
|
57
57
|
"@types/koa-qs": "^2.0.0",
|
|
@@ -61,18 +61,18 @@
|
|
|
61
61
|
"koa-qs": "^3.0.0"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
|
-
"@feathersjs/authentication-local": "^5.0.0-pre.
|
|
65
|
-
"@feathersjs/feathers": "^5.0.0-pre.
|
|
66
|
-
"@feathersjs/memory": "^5.0.0-pre.
|
|
67
|
-
"@feathersjs/tests": "^5.0.0-pre.
|
|
64
|
+
"@feathersjs/authentication-local": "^5.0.0-pre.24",
|
|
65
|
+
"@feathersjs/feathers": "^5.0.0-pre.24",
|
|
66
|
+
"@feathersjs/memory": "^5.0.0-pre.24",
|
|
67
|
+
"@feathersjs/tests": "^5.0.0-pre.24",
|
|
68
68
|
"@types/koa-compose": "^3.2.5",
|
|
69
69
|
"@types/mocha": "^9.1.1",
|
|
70
|
-
"@types/node": "^17.0.
|
|
70
|
+
"@types/node": "^17.0.40",
|
|
71
71
|
"axios": "^0.27.2",
|
|
72
72
|
"mocha": "^10.0.0",
|
|
73
73
|
"shx": "^0.3.4",
|
|
74
|
-
"ts-node": "^10.
|
|
75
|
-
"typescript": "^4.
|
|
74
|
+
"ts-node": "^10.8.1",
|
|
75
|
+
"typescript": "^4.7.3"
|
|
76
76
|
},
|
|
77
|
-
"gitHead": "
|
|
77
|
+
"gitHead": "72779fa2938f43d7b345b6861ff0035481a07de3"
|
|
78
78
|
}
|
package/src/authentication.ts
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
import { Application, HookContext } from '@feathersjs/feathers'
|
|
2
|
-
import { createDebug } from '@feathersjs/commons'
|
|
3
|
-
import { authenticate as AuthenticateHook } from '@feathersjs/authentication'
|
|
1
|
+
import { Application, HookContext } from '@feathersjs/feathers'
|
|
2
|
+
import { createDebug } from '@feathersjs/commons'
|
|
3
|
+
import { authenticate as AuthenticateHook } from '@feathersjs/authentication'
|
|
4
4
|
|
|
5
|
-
import { Middleware } from './declarations'
|
|
5
|
+
import { Middleware } from './declarations'
|
|
6
6
|
|
|
7
|
-
const debug = createDebug('@feathersjs/koa/authentication')
|
|
7
|
+
const debug = createDebug('@feathersjs/koa/authentication')
|
|
8
8
|
|
|
9
9
|
export type AuthenticationSettings = {
|
|
10
|
-
service?: string
|
|
11
|
-
strategies?: string[]
|
|
12
|
-
}
|
|
10
|
+
service?: string
|
|
11
|
+
strategies?: string[]
|
|
12
|
+
}
|
|
13
13
|
|
|
14
|
-
export function parseAuthentication
|
|
14
|
+
export function parseAuthentication(settings: AuthenticationSettings = {}): Middleware {
|
|
15
15
|
return async (ctx, next) => {
|
|
16
|
-
const app = ctx.app
|
|
17
|
-
const service = app.defaultAuthentication?.(settings.service)
|
|
16
|
+
const app = ctx.app
|
|
17
|
+
const service = app.defaultAuthentication?.(settings.service)
|
|
18
18
|
|
|
19
19
|
if (!service) {
|
|
20
|
-
return next()
|
|
20
|
+
return next()
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
const config = service.configuration
|
|
24
|
-
const authStrategies = settings.strategies || config.parseStrategies || config.authStrategies || []
|
|
23
|
+
const config = service.configuration
|
|
24
|
+
const authStrategies = settings.strategies || config.parseStrategies || config.authStrategies || []
|
|
25
25
|
|
|
26
26
|
if (authStrategies.length === 0) {
|
|
27
|
-
debug('No `authStrategies` or `parseStrategies` found in authentication configuration')
|
|
28
|
-
return next()
|
|
27
|
+
debug('No `authStrategies` or `parseStrategies` found in authentication configuration')
|
|
28
|
+
return next()
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
const authentication = await service.parse(ctx.req, ctx.res, ...authStrategies)
|
|
31
|
+
const authentication = await service.parse(ctx.req, ctx.res, ...authStrategies)
|
|
32
32
|
|
|
33
33
|
if (authentication) {
|
|
34
|
-
debug('Parsed authentication from HTTP header', authentication)
|
|
35
|
-
ctx.feathers = { ...ctx.feathers, authentication }
|
|
34
|
+
debug('Parsed authentication from HTTP header', authentication)
|
|
35
|
+
ctx.feathers = { ...ctx.feathers, authentication }
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
return next()
|
|
39
|
-
}
|
|
38
|
+
return next()
|
|
39
|
+
}
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
export function authenticate
|
|
43
|
-
const hook = AuthenticateHook(settings, ...strategies)
|
|
42
|
+
export function authenticate(settings: string | AuthenticationSettings, ...strategies: string[]): Middleware {
|
|
43
|
+
const hook = AuthenticateHook(settings, ...strategies)
|
|
44
44
|
|
|
45
45
|
return async (ctx, next) => {
|
|
46
|
-
const app = ctx.app as Application
|
|
47
|
-
const params = ctx.feathers
|
|
48
|
-
const context = { app, params } as HookContext
|
|
46
|
+
const app = ctx.app as Application
|
|
47
|
+
const params = ctx.feathers
|
|
48
|
+
const context = { app, params } as HookContext
|
|
49
49
|
|
|
50
|
-
await hook(context)
|
|
50
|
+
await hook(context)
|
|
51
51
|
|
|
52
|
-
ctx.feathers = context.params
|
|
52
|
+
ctx.feathers = context.params
|
|
53
53
|
|
|
54
|
-
return next()
|
|
55
|
-
}
|
|
54
|
+
return next()
|
|
55
|
+
}
|
|
56
56
|
}
|
package/src/declarations.ts
CHANGED
|
@@ -1,36 +1,37 @@
|
|
|
1
|
-
import Koa, { Next } from 'koa'
|
|
2
|
-
import { Server } from 'http'
|
|
3
|
-
import { Application as FeathersApplication, HookContext, Params, RouteLookup } from '@feathersjs/feathers'
|
|
4
|
-
import '@feathersjs/authentication'
|
|
1
|
+
import Koa, { Next } from 'koa'
|
|
2
|
+
import { Server } from 'http'
|
|
3
|
+
import { Application as FeathersApplication, HookContext, Params, RouteLookup } from '@feathersjs/feathers'
|
|
4
|
+
import '@feathersjs/authentication'
|
|
5
5
|
|
|
6
6
|
export type ApplicationAddons = {
|
|
7
|
-
server: Server
|
|
8
|
-
listen
|
|
7
|
+
server: Server
|
|
8
|
+
listen(port?: number, ...args: any[]): Promise<Server>
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
export type Application<T = any, C = any> =
|
|
12
|
-
|
|
11
|
+
export type Application<T = any, C = any> = Omit<Koa, 'listen'> &
|
|
12
|
+
FeathersApplication<T, C> &
|
|
13
|
+
ApplicationAddons
|
|
13
14
|
|
|
14
15
|
export type FeathersKoaContext<A = Application> = Koa.Context & {
|
|
15
|
-
app: A
|
|
16
|
-
}
|
|
16
|
+
app: A
|
|
17
|
+
}
|
|
17
18
|
|
|
18
|
-
export type Middleware<A = Application> = (context: FeathersKoaContext<A>, next: Next) => any
|
|
19
|
+
export type Middleware<A = Application> = (context: FeathersKoaContext<A>, next: Next) => any
|
|
19
20
|
|
|
20
21
|
declare module '@feathersjs/feathers/lib/declarations' {
|
|
21
22
|
interface ServiceOptions {
|
|
22
23
|
koa?: {
|
|
23
|
-
before?: Middleware[]
|
|
24
|
-
after?: Middleware[]
|
|
25
|
-
composed?: Middleware
|
|
26
|
-
}
|
|
24
|
+
before?: Middleware[]
|
|
25
|
+
after?: Middleware[]
|
|
26
|
+
composed?: Middleware
|
|
27
|
+
}
|
|
27
28
|
}
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
declare module 'koa' {
|
|
31
32
|
interface ExtendableContext {
|
|
32
|
-
feathers?: Partial<Params
|
|
33
|
-
lookup?: RouteLookup
|
|
34
|
-
hook?: HookContext
|
|
33
|
+
feathers?: Partial<Params>
|
|
34
|
+
lookup?: RouteLookup
|
|
35
|
+
hook?: HookContext
|
|
35
36
|
}
|
|
36
37
|
}
|
package/src/handlers.ts
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
import { NotFound } from '@feathersjs/errors'
|
|
2
|
-
import { FeathersKoaContext } from './declarations'
|
|
1
|
+
import { NotFound } from '@feathersjs/errors'
|
|
2
|
+
import { FeathersKoaContext } from './declarations'
|
|
3
3
|
|
|
4
4
|
export const errorHandler = () => async (ctx: FeathersKoaContext, next: () => Promise<any>) => {
|
|
5
5
|
try {
|
|
6
|
-
await next()
|
|
6
|
+
await next()
|
|
7
7
|
|
|
8
|
-
if(ctx.body === undefined) {
|
|
9
|
-
throw new NotFound('Not Found')
|
|
8
|
+
if (ctx.body === undefined) {
|
|
9
|
+
throw new NotFound('Not Found')
|
|
10
10
|
}
|
|
11
|
-
|
|
12
11
|
} catch (error: any) {
|
|
13
|
-
ctx.response.status = error.code || 500
|
|
14
|
-
ctx.body =
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
ctx.response.status = error.code || 500
|
|
13
|
+
ctx.body =
|
|
14
|
+
typeof error.toJSON === 'function'
|
|
15
|
+
? error.toJSON()
|
|
16
|
+
: {
|
|
17
|
+
message: error.message
|
|
18
|
+
}
|
|
17
19
|
}
|
|
18
|
-
}
|
|
20
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,87 +1,90 @@
|
|
|
1
|
-
import Koa from 'koa'
|
|
2
|
-
import koaQs from 'koa-qs'
|
|
3
|
-
import { Application as FeathersApplication } from '@feathersjs/feathers'
|
|
4
|
-
import { routing } from '@feathersjs/transport-commons'
|
|
5
|
-
import { createDebug } from '@feathersjs/commons'
|
|
6
|
-
|
|
7
|
-
import { Application } from './declarations'
|
|
8
|
-
|
|
9
|
-
export {
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
export * from './
|
|
13
|
-
export * from './
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
1
|
+
import Koa from 'koa'
|
|
2
|
+
import koaQs from 'koa-qs'
|
|
3
|
+
import { Application as FeathersApplication } from '@feathersjs/feathers'
|
|
4
|
+
import { routing } from '@feathersjs/transport-commons'
|
|
5
|
+
import { createDebug } from '@feathersjs/commons'
|
|
6
|
+
import bodyParser from 'koa-bodyparser'
|
|
7
|
+
import { Application } from './declarations'
|
|
8
|
+
|
|
9
|
+
export { Koa, bodyParser }
|
|
10
|
+
export * from './authentication'
|
|
11
|
+
export * from './declarations'
|
|
12
|
+
export * from './handlers'
|
|
13
|
+
export * from './rest'
|
|
14
|
+
|
|
15
|
+
const debug = createDebug('@feathersjs/koa')
|
|
16
|
+
|
|
17
|
+
export function koa<S = any, C = any>(
|
|
18
|
+
feathersApp?: FeathersApplication<S, C>,
|
|
19
|
+
koaApp: Koa = new Koa()
|
|
20
|
+
): Application<S, C> {
|
|
20
21
|
if (!feathersApp) {
|
|
21
|
-
return koaApp as any
|
|
22
|
+
return koaApp as any
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
if (typeof feathersApp.setup !== 'function') {
|
|
25
|
-
throw new Error('@feathersjs/koa requires a valid Feathers application instance')
|
|
26
|
+
throw new Error('@feathersjs/koa requires a valid Feathers application instance')
|
|
26
27
|
}
|
|
27
28
|
|
|
28
|
-
const app = feathersApp as any as Application<S, C
|
|
29
|
-
const { listen: koaListen, use: koaUse } = koaApp
|
|
30
|
-
const { use: feathersUse, teardown: feathersTeardown } = feathersApp
|
|
29
|
+
const app = feathersApp as any as Application<S, C>
|
|
30
|
+
const { listen: koaListen, use: koaUse } = koaApp
|
|
31
|
+
const { use: feathersUse, teardown: feathersTeardown } = feathersApp
|
|
31
32
|
|
|
32
33
|
Object.assign(app, {
|
|
33
|
-
use
|
|
34
|
+
use(location: string | Koa.Middleware, ...args: any[]) {
|
|
34
35
|
if (typeof location === 'string') {
|
|
35
|
-
return (feathersUse as any).call(this, location, ...args)
|
|
36
|
+
return (feathersUse as any).call(this, location, ...args)
|
|
36
37
|
}
|
|
37
38
|
|
|
38
|
-
return koaUse.call(this, location)
|
|
39
|
+
return koaUse.call(this, location)
|
|
39
40
|
},
|
|
40
41
|
|
|
41
|
-
async listen
|
|
42
|
-
const server = koaListen.call(this, port, ...args)
|
|
42
|
+
async listen(port?: number, ...args: any[]) {
|
|
43
|
+
const server = koaListen.call(this, port, ...args)
|
|
43
44
|
|
|
44
|
-
this.server = server
|
|
45
|
-
await this.setup(server)
|
|
46
|
-
debug('Feathers application listening')
|
|
45
|
+
this.server = server
|
|
46
|
+
await this.setup(server)
|
|
47
|
+
debug('Feathers application listening')
|
|
47
48
|
|
|
48
|
-
return server
|
|
49
|
+
return server
|
|
49
50
|
},
|
|
50
51
|
|
|
51
|
-
async teardown
|
|
52
|
-
return feathersTeardown
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
async teardown(server?: any) {
|
|
53
|
+
return feathersTeardown
|
|
54
|
+
.call(this, server)
|
|
55
|
+
.then(
|
|
56
|
+
() => new Promise((resolve, reject) => this.server.close((e) => (e ? reject(e) : resolve(this))))
|
|
57
|
+
)
|
|
55
58
|
}
|
|
56
|
-
} as Application)
|
|
59
|
+
} as Application)
|
|
57
60
|
|
|
58
61
|
const appDescriptors = {
|
|
59
62
|
...Object.getOwnPropertyDescriptors(Object.getPrototypeOf(app)),
|
|
60
63
|
...Object.getOwnPropertyDescriptors(app)
|
|
61
|
-
}
|
|
64
|
+
}
|
|
62
65
|
const newDescriptors = {
|
|
63
66
|
...Object.getOwnPropertyDescriptors(Object.getPrototypeOf(koaApp)),
|
|
64
67
|
...Object.getOwnPropertyDescriptors(koaApp)
|
|
65
|
-
}
|
|
68
|
+
}
|
|
66
69
|
|
|
67
70
|
// Copy all non-existing properties (including non-enumerables)
|
|
68
71
|
// that don't already exist on the Express app
|
|
69
|
-
Object.keys(newDescriptors).forEach(prop => {
|
|
70
|
-
const appProp = appDescriptors[prop]
|
|
71
|
-
const newProp = newDescriptors[prop]
|
|
72
|
+
Object.keys(newDescriptors).forEach((prop) => {
|
|
73
|
+
const appProp = appDescriptors[prop]
|
|
74
|
+
const newProp = newDescriptors[prop]
|
|
72
75
|
|
|
73
76
|
if (appProp === undefined && newProp !== undefined) {
|
|
74
|
-
Object.defineProperty(app, prop, newProp)
|
|
77
|
+
Object.defineProperty(app, prop, newProp)
|
|
75
78
|
}
|
|
76
|
-
})
|
|
79
|
+
})
|
|
77
80
|
|
|
78
|
-
koaQs(app as any)
|
|
81
|
+
koaQs(app as any)
|
|
79
82
|
|
|
80
|
-
app.configure(routing() as any)
|
|
83
|
+
app.configure(routing() as any)
|
|
81
84
|
app.use((ctx, next) => {
|
|
82
|
-
ctx.feathers = { ...ctx.feathers, provider: 'rest' }
|
|
83
|
-
return next()
|
|
84
|
-
})
|
|
85
|
+
ctx.feathers = { ...ctx.feathers, provider: 'rest' }
|
|
86
|
+
return next()
|
|
87
|
+
})
|
|
85
88
|
|
|
86
|
-
return app
|
|
89
|
+
return app
|
|
87
90
|
}
|
package/src/rest.ts
CHANGED
|
@@ -1,92 +1,93 @@
|
|
|
1
|
-
import compose from 'koa-compose'
|
|
2
|
-
import { http } from '@feathersjs/transport-commons'
|
|
3
|
-
import { createDebug } from '@feathersjs/commons'
|
|
4
|
-
import { getServiceOptions, defaultServiceMethods, createContext } from '@feathersjs/feathers'
|
|
5
|
-
import { MethodNotAllowed } from '@feathersjs/errors'
|
|
1
|
+
import compose from 'koa-compose'
|
|
2
|
+
import { http } from '@feathersjs/transport-commons'
|
|
3
|
+
import { createDebug } from '@feathersjs/commons'
|
|
4
|
+
import { getServiceOptions, defaultServiceMethods, createContext } from '@feathersjs/feathers'
|
|
5
|
+
import { MethodNotAllowed } from '@feathersjs/errors'
|
|
6
6
|
|
|
7
|
-
import { Application, Middleware } from './declarations'
|
|
8
|
-
import { AuthenticationSettings, parseAuthentication } from './authentication'
|
|
7
|
+
import { Application, Middleware } from './declarations'
|
|
8
|
+
import { AuthenticationSettings, parseAuthentication } from './authentication'
|
|
9
9
|
|
|
10
|
-
const debug = createDebug('@feathersjs/koa/rest')
|
|
10
|
+
const debug = createDebug('@feathersjs/koa/rest')
|
|
11
11
|
|
|
12
12
|
const serviceMiddleware = (): Middleware => {
|
|
13
13
|
return async (ctx, next) => {
|
|
14
|
-
const { query, headers, path, body: data, method: httpMethod } = ctx.request
|
|
15
|
-
const methodOverride = ctx.request.headers[http.METHOD_HEADER] as string | undefined
|
|
14
|
+
const { query, headers, path, body: data, method: httpMethod } = ctx.request
|
|
15
|
+
const methodOverride = ctx.request.headers[http.METHOD_HEADER] as string | undefined
|
|
16
16
|
|
|
17
|
-
const { service, params: { __id: id = null, ...route } = {} } = ctx.lookup
|
|
18
|
-
const method = http.getServiceMethod(httpMethod, id, methodOverride)
|
|
19
|
-
const { methods } = getServiceOptions(service)
|
|
17
|
+
const { service, params: { __id: id = null, ...route } = {} } = ctx.lookup!
|
|
18
|
+
const method = http.getServiceMethod(httpMethod, id, methodOverride)
|
|
19
|
+
const { methods } = getServiceOptions(service)
|
|
20
20
|
|
|
21
|
-
debug(`Found service for path ${path}, attempting to run '${method}' service method`)
|
|
21
|
+
debug(`Found service for path ${path}, attempting to run '${method}' service method`)
|
|
22
22
|
|
|
23
23
|
if (!methods.includes(method) || defaultServiceMethods.includes(methodOverride)) {
|
|
24
|
-
const error = new MethodNotAllowed(`Method \`${method}\` is not supported by this endpoint.`)
|
|
25
|
-
ctx.response.status = error.code
|
|
26
|
-
throw error
|
|
24
|
+
const error = new MethodNotAllowed(`Method \`${method}\` is not supported by this endpoint.`)
|
|
25
|
+
ctx.response.status = error.code
|
|
26
|
+
throw error
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
const createArguments = http.argumentsFor[method as 'get'] || http.argumentsFor.default
|
|
30
|
-
const params = { query, headers, route, ...ctx.feathers }
|
|
31
|
-
const args = createArguments({ id, data, params })
|
|
32
|
-
const contextBase = createContext(service, method, { http: {} })
|
|
33
|
-
ctx.hook = contextBase
|
|
29
|
+
const createArguments = http.argumentsFor[method as 'get'] || http.argumentsFor.default
|
|
30
|
+
const params = { query, headers, route, ...ctx.feathers }
|
|
31
|
+
const args = createArguments({ id, data, params })
|
|
32
|
+
const contextBase = createContext(service, method, { http: {} })
|
|
33
|
+
ctx.hook = contextBase
|
|
34
34
|
|
|
35
|
-
const context = await (service as any)[method](...args, contextBase)
|
|
36
|
-
ctx.hook = context
|
|
35
|
+
const context = await (service as any)[method](...args, contextBase)
|
|
36
|
+
ctx.hook = context
|
|
37
37
|
|
|
38
|
-
const response = http.getResponse(context)
|
|
39
|
-
ctx.status = response.status
|
|
40
|
-
ctx.set(response.headers)
|
|
41
|
-
ctx.body = response.body
|
|
38
|
+
const response = http.getResponse(context)
|
|
39
|
+
ctx.status = response.status
|
|
40
|
+
ctx.set(response.headers)
|
|
41
|
+
ctx.body = response.body
|
|
42
42
|
|
|
43
|
-
return next()
|
|
44
|
-
}
|
|
45
|
-
}
|
|
43
|
+
return next()
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
46
|
|
|
47
47
|
const servicesMiddleware = (): Middleware => {
|
|
48
48
|
return async (ctx, next) => {
|
|
49
|
-
const app = ctx.app
|
|
50
|
-
const lookup = app.lookup(ctx.request.path)
|
|
49
|
+
const app = ctx.app
|
|
50
|
+
const lookup = app.lookup(ctx.request.path)
|
|
51
51
|
|
|
52
52
|
if (!lookup) {
|
|
53
|
-
return next()
|
|
53
|
+
return next()
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
ctx.lookup = lookup
|
|
56
|
+
ctx.lookup = lookup
|
|
57
57
|
|
|
58
|
-
const options = getServiceOptions(lookup.service)
|
|
59
|
-
const middleware = options.koa
|
|
58
|
+
const options = getServiceOptions(lookup.service)
|
|
59
|
+
const middleware = options.koa.composed
|
|
60
60
|
|
|
61
|
-
return middleware(ctx, next)
|
|
62
|
-
}
|
|
63
|
-
}
|
|
61
|
+
return middleware(ctx, next)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
64
|
|
|
65
|
-
|
|
65
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
66
|
+
export const formatter: Middleware = (_ctx, _next) => {}
|
|
66
67
|
|
|
67
68
|
export type RestOptions = {
|
|
68
|
-
formatter?: Middleware
|
|
69
|
-
authentication?: AuthenticationSettings
|
|
70
|
-
}
|
|
69
|
+
formatter?: Middleware
|
|
70
|
+
authentication?: AuthenticationSettings
|
|
71
|
+
}
|
|
71
72
|
|
|
72
73
|
export const rest = (options?: RestOptions | Middleware) => {
|
|
73
|
-
options = typeof options === 'function' ? { formatter: options } : options || {}
|
|
74
|
+
options = typeof options === 'function' ? { formatter: options } : options || {}
|
|
74
75
|
|
|
75
|
-
const formatterMiddleware = options.formatter || formatter
|
|
76
|
-
const authenticationOptions = options.authentication
|
|
76
|
+
const formatterMiddleware = options.formatter || formatter
|
|
77
|
+
const authenticationOptions = options.authentication
|
|
77
78
|
|
|
78
79
|
return (app: Application) => {
|
|
79
|
-
app.use(parseAuthentication(authenticationOptions))
|
|
80
|
-
app.use(servicesMiddleware())
|
|
80
|
+
app.use(parseAuthentication(authenticationOptions))
|
|
81
|
+
app.use(servicesMiddleware())
|
|
81
82
|
|
|
82
83
|
app.mixins.push((_service, _path, options) => {
|
|
83
|
-
const { koa: { before = [], after = [] } = {} } = options
|
|
84
|
+
const { koa: { before = [], after = [] } = {} } = options
|
|
84
85
|
|
|
85
|
-
const middlewares = [].concat(before, serviceMiddleware(), after, formatterMiddleware)
|
|
86
|
-
const middleware = compose(middlewares)
|
|
86
|
+
const middlewares = [].concat(before, serviceMiddleware(), after, formatterMiddleware)
|
|
87
|
+
const middleware = compose(middlewares)
|
|
87
88
|
|
|
88
|
-
options.koa ||= {}
|
|
89
|
-
options.koa.composed = middleware
|
|
90
|
-
})
|
|
91
|
-
}
|
|
92
|
-
}
|
|
89
|
+
options.koa ||= {}
|
|
90
|
+
options.koa.composed = middleware
|
|
91
|
+
})
|
|
92
|
+
}
|
|
93
|
+
}
|