@loopback/core 4.0.0-alpha.8 → 4.0.1
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 +25 -0
- package/README.md +77 -2
- package/dist/application.d.ts +341 -0
- package/dist/application.js +554 -0
- package/dist/application.js.map +1 -0
- package/dist/component.d.ts +80 -0
- package/dist/component.js +59 -0
- package/dist/component.js.map +1 -0
- package/dist/extension-point.d.ts +121 -0
- package/dist/extension-point.js +227 -0
- package/dist/extension-point.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -0
- package/dist/keys.d.ts +97 -0
- package/dist/keys.js +109 -0
- package/dist/keys.js.map +1 -0
- package/dist/lifecycle-registry.d.ts +91 -0
- package/dist/lifecycle-registry.js +191 -0
- package/dist/lifecycle-registry.js.map +1 -0
- package/dist/lifecycle.d.ts +47 -0
- package/dist/lifecycle.js +56 -0
- package/dist/lifecycle.js.map +1 -0
- package/dist/mixin-target.d.ts +60 -0
- package/{lib/internal-types.js → dist/mixin-target.js} +2 -3
- package/dist/mixin-target.js.map +1 -0
- package/dist/server.d.ts +16 -0
- package/{lib6/src/Component.js → dist/server.js} +2 -1
- package/dist/server.js.map +1 -0
- package/dist/service.d.ts +63 -0
- package/dist/service.js +151 -0
- package/dist/service.js.map +1 -0
- package/package.json +39 -37
- package/src/application.ts +719 -0
- package/src/component.ts +155 -0
- package/src/extension-point.ts +312 -0
- package/src/index.ts +29 -0
- package/src/keys.ts +144 -0
- package/src/lifecycle-registry.ts +268 -0
- package/src/lifecycle.ts +90 -0
- package/src/mixin-target.ts +69 -0
- package/src/server.ts +22 -0
- package/src/service.ts +211 -0
- package/index.d.ts +0 -6
- package/index.js +0 -9
- package/lib/Component.d.ts +0 -2
- package/lib/Component.js +0 -7
- package/lib/Sequence.d.ts +0 -14
- package/lib/Sequence.js +0 -58
- package/lib/application.d.ts +0 -52
- package/lib/application.js +0 -79
- package/lib/application.js.map +0 -1
- package/lib/component.js.map +0 -1
- package/lib/handlers/http.d.ts +0 -3
- package/lib/handlers/http.js +0 -13
- package/lib/handlers/http.js.map +0 -1
- package/lib/handlers/index.d.ts +0 -1
- package/lib/handlers/index.js +0 -11
- package/lib/handlers/index.js.map +0 -1
- package/lib/http-handler.d.ts +0 -16
- package/lib/http-handler.js +0 -62
- package/lib/http-handler.js.map +0 -1
- package/lib/index.d.ts +0 -16
- package/lib/index.js +0 -33
- package/lib/index.js.map +0 -1
- package/lib/internal-types.d.ts +0 -20
- package/lib/internal-types.js.map +0 -1
- package/lib/invoke.d.ts +0 -5
- package/lib/invoke.js +0 -30
- package/lib/parser.d.ts +0 -3
- package/lib/parser.js +0 -73
- package/lib/parser.js.map +0 -1
- package/lib/promisify.d.ts +0 -3
- package/lib/promisify.js +0 -34
- package/lib/promisify.js.map +0 -1
- package/lib/router/SwaggerRouter.d.ts +0 -39
- package/lib/router/SwaggerRouter.js +0 -205
- package/lib/router/metadata.d.ts +0 -12
- package/lib/router/metadata.js +0 -30
- package/lib/router/metadata.js.map +0 -1
- package/lib/router/routing-table.d.ts +0 -16
- package/lib/router/routing-table.js +0 -95
- package/lib/router/routing-table.js.map +0 -1
- package/lib/sequence.js.map +0 -1
- package/lib/server.d.ts +0 -23
- package/lib/server.js +0 -53
- package/lib/server.js.map +0 -1
- package/lib/src/Component.d.ts +0 -2
- package/lib/src/Component.js +0 -6
- package/lib/src/Sequence.d.ts +0 -6
- package/lib/src/Sequence.js +0 -26
- package/lib/src/application.d.ts +0 -27
- package/lib/src/application.js +0 -70
- package/lib/src/index.d.ts +0 -13
- package/lib/src/index.js +0 -29
- package/lib/src/invoke.d.ts +0 -5
- package/lib/src/invoke.js +0 -34
- package/lib/src/parser.d.ts +0 -3
- package/lib/src/parser.js +0 -72
- package/lib/src/promisify.d.ts +0 -3
- package/lib/src/promisify.js +0 -33
- package/lib/src/router/SwaggerRouter.d.ts +0 -53
- package/lib/src/router/SwaggerRouter.js +0 -101
- package/lib/src/router/metadata.d.ts +0 -13
- package/lib/src/router/metadata.js +0 -29
- package/lib/src/router/routing-table.d.ts +0 -13
- package/lib/src/router/routing-table.js +0 -83
- package/lib/src/server.d.ts +0 -17
- package/lib/src/server.js +0 -40
- package/lib/writer.d.ts +0 -4
- package/lib/writer.js +0 -24
- package/lib/writer.js.map +0 -1
- package/lib6/Component.d.ts +0 -2
- package/lib6/Component.js +0 -7
- package/lib6/Sequence.d.ts +0 -14
- package/lib6/Sequence.js +0 -68
- package/lib6/application.d.ts +0 -52
- package/lib6/application.js +0 -79
- package/lib6/application.js.map +0 -1
- package/lib6/component.js.map +0 -1
- package/lib6/handlers/http.d.ts +0 -3
- package/lib6/handlers/http.js +0 -21
- package/lib6/handlers/http.js.map +0 -1
- package/lib6/handlers/index.d.ts +0 -1
- package/lib6/handlers/index.js +0 -11
- package/lib6/handlers/index.js.map +0 -1
- package/lib6/http-handler.d.ts +0 -16
- package/lib6/http-handler.js +0 -72
- package/lib6/http-handler.js.map +0 -1
- package/lib6/index.d.ts +0 -16
- package/lib6/index.js +0 -33
- package/lib6/index.js.map +0 -1
- package/lib6/internal-types.d.ts +0 -20
- package/lib6/internal-types.js +0 -8
- package/lib6/internal-types.js.map +0 -1
- package/lib6/invoke.d.ts +0 -5
- package/lib6/invoke.js +0 -30
- package/lib6/parser.d.ts +0 -3
- package/lib6/parser.js +0 -83
- package/lib6/parser.js.map +0 -1
- package/lib6/promisify.d.ts +0 -3
- package/lib6/promisify.js +0 -34
- package/lib6/promisify.js.map +0 -1
- package/lib6/router/SwaggerRouter.d.ts +0 -39
- package/lib6/router/SwaggerRouter.js +0 -205
- package/lib6/router/metadata.d.ts +0 -12
- package/lib6/router/metadata.js +0 -30
- package/lib6/router/metadata.js.map +0 -1
- package/lib6/router/routing-table.d.ts +0 -16
- package/lib6/router/routing-table.js +0 -95
- package/lib6/router/routing-table.js.map +0 -1
- package/lib6/sequence.js.map +0 -1
- package/lib6/server.d.ts +0 -23
- package/lib6/server.js +0 -63
- package/lib6/server.js.map +0 -1
- package/lib6/src/Component.d.ts +0 -2
- package/lib6/src/Sequence.d.ts +0 -6
- package/lib6/src/Sequence.js +0 -36
- package/lib6/src/application.d.ts +0 -27
- package/lib6/src/application.js +0 -70
- package/lib6/src/index.d.ts +0 -13
- package/lib6/src/index.js +0 -29
- package/lib6/src/invoke.d.ts +0 -5
- package/lib6/src/invoke.js +0 -34
- package/lib6/src/parser.d.ts +0 -3
- package/lib6/src/parser.js +0 -82
- package/lib6/src/promisify.d.ts +0 -3
- package/lib6/src/promisify.js +0 -33
- package/lib6/src/router/SwaggerRouter.d.ts +0 -53
- package/lib6/src/router/SwaggerRouter.js +0 -101
- package/lib6/src/router/metadata.d.ts +0 -13
- package/lib6/src/router/metadata.js +0 -29
- package/lib6/src/router/routing-table.d.ts +0 -13
- package/lib6/src/router/routing-table.js +0 -83
- package/lib6/src/server.d.ts +0 -17
- package/lib6/src/server.js +0 -50
- package/lib6/writer.d.ts +0 -4
- package/lib6/writer.js +0 -24
- package/lib6/writer.js.map +0 -1
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright IBM Corp. 2017. All Rights Reserved.
|
|
3
|
-
// Node module: @loopback/core
|
|
4
|
-
// This file is licensed under the MIT License.
|
|
5
|
-
// License text available at https://opensource.org/licenses/MIT
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
const invoke_1 = require("../invoke");
|
|
8
|
-
const assert = require("assert");
|
|
9
|
-
const url = require("url");
|
|
10
|
-
const pathToRegexp = require("path-to-regexp");
|
|
11
|
-
const Promise = require("bluebird");
|
|
12
|
-
const debug = require('debug')('loopback:SwaggerRouter');
|
|
13
|
-
const jsonBody = require('body/json');
|
|
14
|
-
// tslint:enable:no-any
|
|
15
|
-
const parseJsonBody = Promise.promisify(jsonBody);
|
|
16
|
-
/**
|
|
17
|
-
* SwaggerRouter - an express-compatible Router using OpenAPI/Swagger
|
|
18
|
-
* to define routes and input parameters
|
|
19
|
-
*/
|
|
20
|
-
class SwaggerRouter {
|
|
21
|
-
constructor() {
|
|
22
|
-
this._endpoints = [];
|
|
23
|
-
// NOTE(bajtos) It is important to use an arrow function here to allow
|
|
24
|
-
// users to pass "router.handler" around as a regular function,
|
|
25
|
-
// e.g. http.createServer(router.handler)
|
|
26
|
-
this.handler = (req, res, callback) => {
|
|
27
|
-
this._handleRequest(req, res, (err) => {
|
|
28
|
-
if (callback)
|
|
29
|
-
callback(err);
|
|
30
|
-
else
|
|
31
|
-
this._finalHandler(req, res, err);
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Register a controller. The controller should be
|
|
37
|
-
* a regular ES6/TS class, use @api decorator to describe
|
|
38
|
-
* the REST API implemented by the controller.
|
|
39
|
-
* TODO(bajtos) How to support ES6 where decorators are not available?
|
|
40
|
-
*
|
|
41
|
-
* @param controllerCtor {ControllerFactory} A factory function accepting (Request, Response) arguments
|
|
42
|
-
* and returning the Controller instance to use.
|
|
43
|
-
* @param spec {OpenApiSpec} The Swagger specification describing the methods provided by this controller.
|
|
44
|
-
*/
|
|
45
|
-
controller(factory, spec) {
|
|
46
|
-
assert(typeof factory === 'function', 'Controller factory must be a function.');
|
|
47
|
-
assert(typeof spec === 'object' && !!spec, 'API speciification must be a non-null object');
|
|
48
|
-
if (!spec.paths || !Object.keys(spec.paths).length) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
debug('Registering Controller with API', spec);
|
|
52
|
-
for (const path in spec.paths) {
|
|
53
|
-
for (const verb in spec.paths[path]) {
|
|
54
|
-
const opSpec = spec.paths[path][verb];
|
|
55
|
-
// TODO(bajtos) handle the case where opSpec.parameters contains $ref
|
|
56
|
-
debug(' %s %s -> %s(%s)', verb, path, opSpec['x-operation-name'], (opSpec.parameters || []).map(p => p.name).join(', '));
|
|
57
|
-
this._endpoints.push(new Endpoint(path, verb, opSpec, factory));
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
_handleRequest(request, response, next) {
|
|
62
|
-
// TODO(bajtos) The following parsing can be skipped when the router
|
|
63
|
-
// is mounted on an express app
|
|
64
|
-
const parsedRequest = request;
|
|
65
|
-
const parsedUrl = url.parse(parsedRequest.url, true);
|
|
66
|
-
parsedRequest.path = parsedUrl.pathname || '/';
|
|
67
|
-
parsedRequest.query = parsedUrl.query;
|
|
68
|
-
debug('Handle request "%s %s"', request.method, parsedRequest.path);
|
|
69
|
-
let endpointIx = 0;
|
|
70
|
-
const tryNextEndpoint = (err) => {
|
|
71
|
-
if (err) {
|
|
72
|
-
next(err);
|
|
73
|
-
}
|
|
74
|
-
else if (endpointIx >= this._endpoints.length) {
|
|
75
|
-
next();
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
this._endpoints[endpointIx++].handle(parsedRequest, response, tryNextEndpoint);
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
tryNextEndpoint();
|
|
82
|
-
}
|
|
83
|
-
_finalHandler(req, res, err) {
|
|
84
|
-
// TODO(bajtos) cover this final handler by tests
|
|
85
|
-
// TODO(bajtos) make the error-handling strategy configurable (e.g. via strong-error-handler)
|
|
86
|
-
if (err) {
|
|
87
|
-
res.statusCode = err.statusCode || err.status || 500;
|
|
88
|
-
this.logError(req, res.statusCode, err);
|
|
89
|
-
res.end();
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
this.logError(req, 404, 'Not found.');
|
|
93
|
-
res.statusCode = 404;
|
|
94
|
-
res.write(req.url + ' not found.\n');
|
|
95
|
-
res.end();
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
logError(req, statusCode, err) {
|
|
99
|
-
console.error('Unhandled error in %s %s: %s %s', req.method, req.url, statusCode, err.stack || err);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
exports.SwaggerRouter = SwaggerRouter;
|
|
103
|
-
class Endpoint {
|
|
104
|
-
constructor(path, verb, _spec, _controllerFactory) {
|
|
105
|
-
this._spec = _spec;
|
|
106
|
-
this._controllerFactory = _controllerFactory;
|
|
107
|
-
this._verb = verb.toLowerCase();
|
|
108
|
-
// In Swagger, path parameters are wrapped in `{}`.
|
|
109
|
-
// In Express.js, path parameters are prefixed with `:`
|
|
110
|
-
path = path.replace(/{([^}]*)}(\/|$)/g, ':$1$2');
|
|
111
|
-
this._pathRegexp = pathToRegexp(path, [], { strict: false, end: true });
|
|
112
|
-
}
|
|
113
|
-
handle(request, response, next) {
|
|
114
|
-
debug('trying endpoint', this);
|
|
115
|
-
if (this._verb !== request.method.toLowerCase()) {
|
|
116
|
-
debug(' -> next (verb mismatch)');
|
|
117
|
-
next();
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
const match = this._pathRegexp.exec(request.path);
|
|
121
|
-
if (!match) {
|
|
122
|
-
debug(' -> next (path mismatch)');
|
|
123
|
-
next();
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
const pathParams = Object.create(null);
|
|
127
|
-
for (const ix in this._pathRegexp.keys) {
|
|
128
|
-
const key = this._pathRegexp.keys[ix];
|
|
129
|
-
const matchIndex = +ix + 1;
|
|
130
|
-
pathParams[key.name] = match[matchIndex];
|
|
131
|
-
}
|
|
132
|
-
const operationName = this._spec['x-operation-name'];
|
|
133
|
-
Promise.resolve(this._controllerFactory(request, response, operationName))
|
|
134
|
-
.then(controller => {
|
|
135
|
-
loadRequestBodyIfNeeded(this._spec, request)
|
|
136
|
-
.then(body => buildOperationArguments(this._spec, request, pathParams, body))
|
|
137
|
-
.then(args => {
|
|
138
|
-
invoke_1.invoke(controller, operationName, args, response, next);
|
|
139
|
-
}, err => {
|
|
140
|
-
debug('Cannot parse arguments of operation %s: %s', operationName, err.stack || err);
|
|
141
|
-
next(err);
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
function loadRequestBodyIfNeeded(operationSpec, request) {
|
|
147
|
-
if (!hasArgumentsFromBody(operationSpec))
|
|
148
|
-
return Promise.resolve();
|
|
149
|
-
const contentType = request.headers['content-type'];
|
|
150
|
-
if (contentType && !/json/.test(contentType)) {
|
|
151
|
-
const err = createHttpError(415, `Content-type ${contentType} is not supported.`);
|
|
152
|
-
return Promise.reject(err);
|
|
153
|
-
}
|
|
154
|
-
return parseJsonBody(request).catch((err) => {
|
|
155
|
-
err.statusCode = 400;
|
|
156
|
-
return Promise.reject(err);
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
function hasArgumentsFromBody(operationSpec) {
|
|
160
|
-
if (!operationSpec.parameters || !operationSpec.parameters.length)
|
|
161
|
-
return false;
|
|
162
|
-
for (const paramSpec of operationSpec.parameters) {
|
|
163
|
-
if ('$ref' in paramSpec)
|
|
164
|
-
continue;
|
|
165
|
-
const source = paramSpec.in;
|
|
166
|
-
if (source === 'formData' || source === 'body')
|
|
167
|
-
return true;
|
|
168
|
-
}
|
|
169
|
-
return false;
|
|
170
|
-
}
|
|
171
|
-
function buildOperationArguments(operationSpec, request, pathParams, body) {
|
|
172
|
-
const args = [];
|
|
173
|
-
for (const paramSpec of operationSpec.parameters || []) {
|
|
174
|
-
if ('$ref' in paramSpec) {
|
|
175
|
-
// TODO(bajtos) implement $ref parameters
|
|
176
|
-
throw new Error('$ref parameters are not supported yet.');
|
|
177
|
-
}
|
|
178
|
-
const spec = paramSpec;
|
|
179
|
-
switch (spec.in) {
|
|
180
|
-
case 'query':
|
|
181
|
-
args.push(request.query[spec.name]);
|
|
182
|
-
break;
|
|
183
|
-
case 'path':
|
|
184
|
-
args.push(pathParams[spec.name]);
|
|
185
|
-
break;
|
|
186
|
-
case 'header':
|
|
187
|
-
args.push(request.headers[spec.name.toLowerCase()]);
|
|
188
|
-
break;
|
|
189
|
-
case 'formData':
|
|
190
|
-
args.push(body ? body[spec.name] : undefined);
|
|
191
|
-
break;
|
|
192
|
-
case 'body':
|
|
193
|
-
args.push(body);
|
|
194
|
-
break;
|
|
195
|
-
default:
|
|
196
|
-
throw createHttpError(501, 'Parameters with "in: ' + spec.in + '" are not supported yet.');
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
return args;
|
|
200
|
-
}
|
|
201
|
-
function createHttpError(statusCode, message) {
|
|
202
|
-
const err = new Error(message);
|
|
203
|
-
err.statusCode = statusCode;
|
|
204
|
-
return err;
|
|
205
|
-
}
|
package/lib/router/metadata.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { OpenApiSpec } from '@loopback/openapi-spec';
|
|
2
|
-
/**
|
|
3
|
-
* Decorate the given Controller constructor with metadata describing
|
|
4
|
-
* the HTTP/REST API the Controller implements/provides.
|
|
5
|
-
*
|
|
6
|
-
* @param {OpenApiSpec} spec OpenAPI specification describing the endpoints
|
|
7
|
-
* handled by this controller
|
|
8
|
-
*
|
|
9
|
-
* @decorator
|
|
10
|
-
*/
|
|
11
|
-
export declare function api(spec: OpenApiSpec): (constructor: Function) => void;
|
|
12
|
-
export declare function getApiSpec(constructor: Function): OpenApiSpec;
|
package/lib/router/metadata.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright IBM Corp. 2017. All Rights Reserved.
|
|
3
|
-
// Node module: @loopback/core
|
|
4
|
-
// This file is licensed under the MIT License.
|
|
5
|
-
// License text available at https://opensource.org/licenses/MIT
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
const assert = require("assert");
|
|
8
|
-
const context_1 = require("@loopback/context");
|
|
9
|
-
/**
|
|
10
|
-
* Decorate the given Controller constructor with metadata describing
|
|
11
|
-
* the HTTP/REST API the Controller implements/provides.
|
|
12
|
-
*
|
|
13
|
-
* @param {OpenApiSpec} spec OpenAPI specification describing the endpoints
|
|
14
|
-
* handled by this controller
|
|
15
|
-
*
|
|
16
|
-
* @decorator
|
|
17
|
-
*/
|
|
18
|
-
function api(spec) {
|
|
19
|
-
return function (constructor) {
|
|
20
|
-
assert(typeof constructor === 'function', 'The @api decorator can be applied to constructors only.');
|
|
21
|
-
context_1.Reflector.defineMetadata('loopback:api-spec', spec, constructor);
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
exports.api = api;
|
|
25
|
-
// TODO(bajtos) Add unit-tests
|
|
26
|
-
function getApiSpec(constructor) {
|
|
27
|
-
return context_1.Reflector.getMetadata('loopback:api-spec', constructor);
|
|
28
|
-
}
|
|
29
|
-
exports.getApiSpec = getApiSpec;
|
|
30
|
-
//# sourceMappingURL=metadata.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"metadata.js","sourceRoot":"","sources":["../../src/router/metadata.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,8BAA8B;AAC9B,+CAA+C;AAC/C,gEAAgE;;AAEhE,iCAAiC;AACjC,+CAA8C;AAI9C;;;;;;;;GAQG;AACH,aAAoB,IAAiB;IACnC,MAAM,CAAC,UAAS,WAAqB;QACnC,MAAM,CAAC,OAAO,WAAW,KAAK,UAAU,EACvC,yDAAyD,CAAC,CAAC;QAC5D,mBAAS,CAAC,cAAc,CAAC,mBAAmB,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC;IACnE,CAAC,CAAC;AACJ,CAAC;AAND,kBAMC;AAED,8BAA8B;AAC9B,oBAA2B,WAAqB;IAC9C,MAAM,CAAC,mBAAS,CAAC,WAAW,CAAC,mBAAmB,EAAE,WAAW,CAAC,CAAC;AACjE,CAAC;AAFD,gCAEC"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { OpenApiSpec, OperationObject } from '@loopback/openapi-spec';
|
|
3
|
-
import { ServerRequest } from 'http';
|
|
4
|
-
import { ParsedRequest, PathParameterValues } from '../internal-types';
|
|
5
|
-
export declare function parseRequestUrl(request: ServerRequest): ParsedRequest;
|
|
6
|
-
export declare class RoutingTable<ControllerType> {
|
|
7
|
-
private readonly _routes;
|
|
8
|
-
registerController(controller: ControllerType, spec: OpenApiSpec): void;
|
|
9
|
-
find(request: ParsedRequest): ResolvedRoute<ControllerType> | undefined;
|
|
10
|
-
}
|
|
11
|
-
export interface ResolvedRoute<ControllerType> {
|
|
12
|
-
readonly controller: ControllerType;
|
|
13
|
-
readonly methodName: string;
|
|
14
|
-
readonly spec: OperationObject;
|
|
15
|
-
readonly pathParams: PathParameterValues;
|
|
16
|
-
}
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright IBM Corp. 2017. All Rights Reserved.
|
|
3
|
-
// Node module: @loopback/core
|
|
4
|
-
// This file is licensed under the MIT License.
|
|
5
|
-
// License text available at https://opensource.org/licenses/MIT
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
const assert = require("assert");
|
|
8
|
-
const url = require("url");
|
|
9
|
-
const debug = require('debug')('loopback:core:routing-table');
|
|
10
|
-
// TODO(bajtos) Refactor this code to use Trie-based lookup,
|
|
11
|
-
// e.g. via wayfarer/trie or find-my-way
|
|
12
|
-
const pathToRegexp = require("path-to-regexp");
|
|
13
|
-
function parseRequestUrl(request) {
|
|
14
|
-
// TODO(bajtos) The following parsing can be skipped when the router
|
|
15
|
-
// is mounted on an express app
|
|
16
|
-
const parsedRequest = request;
|
|
17
|
-
const parsedUrl = url.parse(parsedRequest.url, true);
|
|
18
|
-
parsedRequest.path = parsedUrl.pathname || '/';
|
|
19
|
-
parsedRequest.query = parsedUrl.query;
|
|
20
|
-
return parsedRequest;
|
|
21
|
-
}
|
|
22
|
-
exports.parseRequestUrl = parseRequestUrl;
|
|
23
|
-
class RoutingTable {
|
|
24
|
-
constructor() {
|
|
25
|
-
this._routes = [];
|
|
26
|
-
}
|
|
27
|
-
registerController(controller, spec) {
|
|
28
|
-
assert(typeof spec === 'object' && !!spec, 'API specification must be a non-null object');
|
|
29
|
-
if (!spec.paths || !Object.keys(spec.paths).length) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
debug('Registering Controller with API', spec);
|
|
33
|
-
for (const path in spec.paths) {
|
|
34
|
-
for (const verb in spec.paths[path]) {
|
|
35
|
-
const opSpec = spec.paths[path][verb];
|
|
36
|
-
// TODO(bajtos) handle the case where opSpec.parameters contains $ref
|
|
37
|
-
debug(' %s %s -> %s(%s)', verb, path, opSpec['x-operation-name'], (opSpec.parameters || []).map(p => p.name).join(', '));
|
|
38
|
-
this._routes.push(new RouteEntry(path, verb, opSpec, controller));
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
find(request) {
|
|
43
|
-
for (const entry of this._routes) {
|
|
44
|
-
const match = entry.match(request);
|
|
45
|
-
if (match)
|
|
46
|
-
return match;
|
|
47
|
-
}
|
|
48
|
-
return undefined;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
exports.RoutingTable = RoutingTable;
|
|
52
|
-
class RouteEntry {
|
|
53
|
-
constructor(path, verb, _spec, _controller) {
|
|
54
|
-
this._spec = _spec;
|
|
55
|
-
this._controller = _controller;
|
|
56
|
-
this._verb = verb.toLowerCase();
|
|
57
|
-
// In Swagger, path parameters are wrapped in `{}`.
|
|
58
|
-
// In Express.js, path parameters are prefixed with `:`
|
|
59
|
-
path = path.replace(/{([^}]*)}(\/|$)/g, ':$1$2');
|
|
60
|
-
this._pathRegexp = pathToRegexp(path, [], { strict: false, end: true });
|
|
61
|
-
}
|
|
62
|
-
match(request) {
|
|
63
|
-
debug('trying endpoint', this);
|
|
64
|
-
if (this._verb !== request.method.toLowerCase()) {
|
|
65
|
-
debug(' -> verb mismatch');
|
|
66
|
-
return undefined;
|
|
67
|
-
}
|
|
68
|
-
const match = this._pathRegexp.exec(request.path);
|
|
69
|
-
if (!match) {
|
|
70
|
-
debug(' -> path mismatch');
|
|
71
|
-
return undefined;
|
|
72
|
-
}
|
|
73
|
-
const pathParams = this._buildPathParams(match);
|
|
74
|
-
debug(' -> found with params: %j', pathParams);
|
|
75
|
-
return this._createResolvedRoute(pathParams);
|
|
76
|
-
}
|
|
77
|
-
_createResolvedRoute(pathParams) {
|
|
78
|
-
return {
|
|
79
|
-
controller: this._controller,
|
|
80
|
-
methodName: this._spec['x-operation-name'],
|
|
81
|
-
spec: this._spec,
|
|
82
|
-
pathParams: pathParams,
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
_buildPathParams(pathMatch) {
|
|
86
|
-
const pathParams = Object.create(null);
|
|
87
|
-
for (const ix in this._pathRegexp.keys) {
|
|
88
|
-
const key = this._pathRegexp.keys[ix];
|
|
89
|
-
const matchIndex = +ix + 1;
|
|
90
|
-
pathParams[key.name] = pathMatch[matchIndex];
|
|
91
|
-
}
|
|
92
|
-
return pathParams;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
//# sourceMappingURL=routing-table.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"routing-table.js","sourceRoot":"","sources":["../../src/router/routing-table.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,8BAA8B;AAC9B,+CAA+C;AAC/C,gEAAgE;;AAchE,iCAAiC;AACjC,2BAA2B;AAC3B,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,6BAA6B,CAAC,CAAC;AAE9D,4DAA4D;AAC5D,wCAAwC;AACxC,+CAA+C;AAE/C,yBAAgC,OAAsB;IACpD,oEAAoE;IACpE,+BAA+B;IAC/B,MAAM,aAAa,GAAG,OAAwB,CAAC;IAC/C,MAAM,SAAS,GAAG,GAAG,CAAC,KAAK,CAAC,aAAa,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IACrD,aAAa,CAAC,IAAI,GAAG,SAAS,CAAC,QAAQ,IAAI,GAAG,CAAC;IAC/C,aAAa,CAAC,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC;IACtC,MAAM,CAAC,aAAa,CAAC;AACvB,CAAC;AARD,0CAQC;AAED;IAAA;QACmB,YAAO,GAA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d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { Application } from './application';
|
|
3
|
-
import { Context } from '@loopback/context';
|
|
4
|
-
import { ServerRequest, ServerResponse } from 'http';
|
|
5
|
-
export declare class Server extends Context {
|
|
6
|
-
app: Application;
|
|
7
|
-
config: ServerConfig;
|
|
8
|
-
state: ServerState;
|
|
9
|
-
constructor(app: Application, config?: ServerConfig);
|
|
10
|
-
start(): Promise<void>;
|
|
11
|
-
protected _handleRequest(req: ServerRequest, res: ServerResponse): void;
|
|
12
|
-
protected _onUnhandledError(req: ServerRequest, res: ServerResponse, err: Error): void;
|
|
13
|
-
}
|
|
14
|
-
export interface ServerConfig {
|
|
15
|
-
port: number;
|
|
16
|
-
}
|
|
17
|
-
export declare enum ServerState {
|
|
18
|
-
cold = 0,
|
|
19
|
-
starting = 1,
|
|
20
|
-
listening = 2,
|
|
21
|
-
crashed = 3,
|
|
22
|
-
stopped = 4,
|
|
23
|
-
}
|
package/lib/server.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright IBM Corp. 2017. All Rights Reserved.
|
|
3
|
-
// Node module: @loopback/core
|
|
4
|
-
// This file is licensed under the MIT License.
|
|
5
|
-
// License text available at https://opensource.org/licenses/MIT
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
const context_1 = require("@loopback/context");
|
|
8
|
-
const http_1 = require("http");
|
|
9
|
-
const debug = require('debug')('loopback:core:server');
|
|
10
|
-
class Server extends context_1.Context {
|
|
11
|
-
constructor(app, config = { port: 3000 }) {
|
|
12
|
-
super();
|
|
13
|
-
this.app = app;
|
|
14
|
-
this.config = config;
|
|
15
|
-
this.state = ServerState.cold;
|
|
16
|
-
}
|
|
17
|
-
async start() {
|
|
18
|
-
this.state = ServerState.starting;
|
|
19
|
-
const server = http_1.createServer((req, res) => this._handleRequest(req, res));
|
|
20
|
-
server.listen(this.config.port);
|
|
21
|
-
// FIXME(bajtos) The updated port number should be part of "status" object,
|
|
22
|
-
// we shouldn't be changing original config IMO.
|
|
23
|
-
// Consider exposing full base URL including http/https scheme prefix
|
|
24
|
-
this.config.port = server.address().port;
|
|
25
|
-
await new Promise(resolve => server.once('listening', resolve));
|
|
26
|
-
this.state = ServerState.listening;
|
|
27
|
-
}
|
|
28
|
-
_handleRequest(req, res) {
|
|
29
|
-
this.app.handleHttp(req, res).catch((err) => {
|
|
30
|
-
this._onUnhandledError(req, res, err);
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
_onUnhandledError(req, res, err) {
|
|
34
|
-
if (!res.headersSent) {
|
|
35
|
-
res.statusCode = 500;
|
|
36
|
-
res.end();
|
|
37
|
-
}
|
|
38
|
-
// It's the responsibility of the Application to handle any errors.
|
|
39
|
-
// If an unhandled error escaped, then something very wrong happened
|
|
40
|
-
// and it's best to crash the process immediately.
|
|
41
|
-
process.nextTick(() => { throw err; });
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
exports.Server = Server;
|
|
45
|
-
var ServerState;
|
|
46
|
-
(function (ServerState) {
|
|
47
|
-
ServerState[ServerState["cold"] = 0] = "cold";
|
|
48
|
-
ServerState[ServerState["starting"] = 1] = "starting";
|
|
49
|
-
ServerState[ServerState["listening"] = 2] = "listening";
|
|
50
|
-
ServerState[ServerState["crashed"] = 3] = "crashed";
|
|
51
|
-
ServerState[ServerState["stopped"] = 4] = "stopped";
|
|
52
|
-
})(ServerState = exports.ServerState || (exports.ServerState = {}));
|
|
53
|
-
//# sourceMappingURL=server.js.map
|
package/lib/server.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,8BAA8B;AAC9B,+CAA+C;AAC/C,gEAAgE;;AAGhE,+CAA0C;AAC1C,+BAAiE;AAEjE,MAAM,KAAK,GAAG,OAAO,C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ACrB,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC;YACrB,GAAG,CAAC,GAAG,EAAE,CAAC;QACZ,CAAC;QAED,mEAAmE;QACnE,oEAAoE;QACpE,kDAAkD;QAClD,OAAO,CAAC,QAAQ,CAAC,QAAQ,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACzC,CAAC;CACF;AAxCD,wBAwCC;AAMD,IAAY,WAMX;AAND,WAAY,WAAW;IACrB,6CAAI,CAAA;IACJ,qDAAQ,CAAA;IACR,uDAAS,CAAA;IACT,mDAAO,CAAA;IACP,mDAAO,CAAA;AACT,CAAC,EANW,WAAW,GAAX,mBAAW,KAAX,mBAAW,QAMtB"}
|
package/lib/src/Component.d.ts
DELETED
package/lib/src/Component.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright IBM Corp. 2017. All Rights Reserved.
|
|
3
|
-
// Node module: @loopback/core
|
|
4
|
-
// This file is licensed under the MIT License.
|
|
5
|
-
// License text available at https://opensource.org/licenses/MIT
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
package/lib/src/Sequence.d.ts
DELETED
package/lib/src/Sequence.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright IBM Corp. 2017. All Rights Reserved.
|
|
3
|
-
// Node module: @loopback/core
|
|
4
|
-
// This file is licensed under the MIT License.
|
|
5
|
-
// License text available at https://opensource.org/licenses/MIT
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
const SwaggerRouter_1 = require("./router/SwaggerRouter");
|
|
8
|
-
const debug = require('debug')('loopback:Server');
|
|
9
|
-
class Sequence {
|
|
10
|
-
async run(server, req, res) {
|
|
11
|
-
// TODO(bajtos) support hot-reloading of controllers
|
|
12
|
-
// after the app started. The idea is to rebuild the SwaggerRouter
|
|
13
|
-
// instance whenever a controller was added/deleted.
|
|
14
|
-
const router = new SwaggerRouter_1.SwaggerRouter();
|
|
15
|
-
const apps = server.find('applications.*');
|
|
16
|
-
for (const appBinding of apps) {
|
|
17
|
-
debug('Registering app controllers for %j', appBinding.key);
|
|
18
|
-
const app = await Promise.resolve(appBinding.getValue(server));
|
|
19
|
-
app.mountControllers(router);
|
|
20
|
-
}
|
|
21
|
-
router.handler(req, res, () => {
|
|
22
|
-
console.log('done');
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
exports.Sequence = Sequence;
|
package/lib/src/application.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { Binding, Context, Constructor } from '@loopback/context';
|
|
2
|
-
import { Component, Sequence } from '.';
|
|
3
|
-
import { SwaggerRouter } from './router/SwaggerRouter';
|
|
4
|
-
export declare class Application extends Context {
|
|
5
|
-
appConfig: AppConfig;
|
|
6
|
-
constructor(appConfig?: AppConfig);
|
|
7
|
-
mountControllers(router: SwaggerRouter): void;
|
|
8
|
-
/**
|
|
9
|
-
* Register a controller class with this application.
|
|
10
|
-
*
|
|
11
|
-
* @param controllerCtor {Function} The controller class (constructor function).
|
|
12
|
-
* @return {Binding} The newly created binding, you can use the reference to further
|
|
13
|
-
* modify the binding, e.g. lock the value to prevent further modifications.
|
|
14
|
-
*
|
|
15
|
-
* ```ts
|
|
16
|
-
* @spec(apiSpec)
|
|
17
|
-
* class MyController {
|
|
18
|
-
* }
|
|
19
|
-
* app.controller(MyController).lock();
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
controller<T>(controllerCtor: Constructor<T>): Binding;
|
|
23
|
-
}
|
|
24
|
-
export interface AppConfig {
|
|
25
|
-
components: Array<Constructor<Component>>;
|
|
26
|
-
sequences: Array<Constructor<Sequence>>;
|
|
27
|
-
}
|
package/lib/src/application.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright IBM Corp. 2017. All Rights Reserved.
|
|
3
|
-
// Node module: @loopback/core
|
|
4
|
-
// This file is licensed under the MIT License.
|
|
5
|
-
// License text available at https://opensource.org/licenses/MIT
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
const context_1 = require("@loopback/context");
|
|
8
|
-
const metadata_1 = require("./router/metadata");
|
|
9
|
-
const debug = require('debug')('loopback:Application');
|
|
10
|
-
class Application extends context_1.Context {
|
|
11
|
-
constructor(appConfig) {
|
|
12
|
-
super();
|
|
13
|
-
this.appConfig = appConfig;
|
|
14
|
-
if (appConfig && appConfig.components) {
|
|
15
|
-
for (const component of appConfig.components) {
|
|
16
|
-
// TODO(superkhau): Need to figure a way around this hack,
|
|
17
|
-
// `componentClassName.constructor.name` + `componentClassName.name`
|
|
18
|
-
// doesn't work
|
|
19
|
-
const componentClassName = component.toString().split(' ')[1];
|
|
20
|
-
this.bind(`component.${componentClassName}`).toClass(component);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
if (appConfig && appConfig.sequences) {
|
|
24
|
-
for (const sequence of appConfig.sequences) {
|
|
25
|
-
// TODO(superkhau): Need to figure a way around this hack,
|
|
26
|
-
// `componentClassName.constructor.name` + `componentClassName.name`
|
|
27
|
-
// doesn't work
|
|
28
|
-
const sequenceClassName = sequence.toString().split(' ')[1];
|
|
29
|
-
this.bind(`sequence.${sequenceClassName}`).toClass(sequence);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
mountControllers(router) {
|
|
34
|
-
this.find('controllers.*').forEach(b => {
|
|
35
|
-
debug('mounting controller %j', b.key);
|
|
36
|
-
const ctor = b.valueConstructor;
|
|
37
|
-
if (!ctor) {
|
|
38
|
-
throw new Error(`The controller ${b.key} was not bound via .toClass()`);
|
|
39
|
-
}
|
|
40
|
-
const ctorFactory = (req, res, operationName) => {
|
|
41
|
-
const requestContext = new context_1.Context(this);
|
|
42
|
-
requestContext.bind('controller.current.ctor').to(ctor);
|
|
43
|
-
requestContext.bind('controller.current.operation').to(operationName);
|
|
44
|
-
requestContext.bind('http.request').to(req);
|
|
45
|
-
requestContext.bind('http.response').to(res);
|
|
46
|
-
return requestContext.get(b.key);
|
|
47
|
-
};
|
|
48
|
-
const apiSpec = metadata_1.getApiSpec(ctor);
|
|
49
|
-
router.controller(ctorFactory, apiSpec);
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Register a controller class with this application.
|
|
54
|
-
*
|
|
55
|
-
* @param controllerCtor {Function} The controller class (constructor function).
|
|
56
|
-
* @return {Binding} The newly created binding, you can use the reference to further
|
|
57
|
-
* modify the binding, e.g. lock the value to prevent further modifications.
|
|
58
|
-
*
|
|
59
|
-
* ```ts
|
|
60
|
-
* @spec(apiSpec)
|
|
61
|
-
* class MyController {
|
|
62
|
-
* }
|
|
63
|
-
* app.controller(MyController).lock();
|
|
64
|
-
* ```
|
|
65
|
-
*/
|
|
66
|
-
controller(controllerCtor) {
|
|
67
|
-
return this.bind('controllers.' + controllerCtor.name).toClass(controllerCtor);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
exports.Application = Application;
|
package/lib/src/index.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export { Application } from './application';
|
|
2
|
-
export { Component } from './Component';
|
|
3
|
-
export { api } from './router/metadata';
|
|
4
|
-
export { Sequence } from './Sequence';
|
|
5
|
-
export { Server, ServerConfig, ServerState } from './server';
|
|
6
|
-
export { inject } from '@loopback/context';
|
|
7
|
-
export * from '@loopback/openapi-spec';
|
|
8
|
-
export { ServerRequest, ServerResponse } from 'http';
|
|
9
|
-
import * as HttpErrors from 'http-errors';
|
|
10
|
-
export { HttpErrors };
|
|
11
|
-
export { parseOperationArgs } from './parser';
|
|
12
|
-
export { ParsedRequest, parseRequestUrl } from './router/SwaggerRouter';
|
|
13
|
-
export { RoutingTable, ResolvedRoute } from './router/routing-table';
|
package/lib/src/index.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright IBM Corp. 2017. All Rights Reserved.
|
|
3
|
-
// Node module: @loopback/core
|
|
4
|
-
// This file is licensed under the MIT License.
|
|
5
|
-
// License text available at https://opensource.org/licenses/MIT
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
// package dependencies
|
|
8
|
-
var application_1 = require("./application");
|
|
9
|
-
exports.Application = application_1.Application;
|
|
10
|
-
var metadata_1 = require("./router/metadata");
|
|
11
|
-
exports.api = metadata_1.api;
|
|
12
|
-
var Sequence_1 = require("./Sequence");
|
|
13
|
-
exports.Sequence = Sequence_1.Sequence;
|
|
14
|
-
var server_1 = require("./server");
|
|
15
|
-
exports.Server = server_1.Server;
|
|
16
|
-
exports.ServerState = server_1.ServerState;
|
|
17
|
-
// loopback dependencies
|
|
18
|
-
var context_1 = require("@loopback/context");
|
|
19
|
-
exports.inject = context_1.inject;
|
|
20
|
-
// import all errors from external http-errors package
|
|
21
|
-
const HttpErrors = require("http-errors");
|
|
22
|
-
exports.HttpErrors = HttpErrors;
|
|
23
|
-
// internals used by unit-tests
|
|
24
|
-
var parser_1 = require("./parser");
|
|
25
|
-
exports.parseOperationArgs = parser_1.parseOperationArgs;
|
|
26
|
-
var SwaggerRouter_1 = require("./router/SwaggerRouter");
|
|
27
|
-
exports.parseRequestUrl = SwaggerRouter_1.parseRequestUrl;
|
|
28
|
-
var routing_table_1 = require("./router/routing-table");
|
|
29
|
-
exports.RoutingTable = routing_table_1.RoutingTable;
|
package/lib/src/invoke.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { ServerResponse as Response } from 'http';
|
|
3
|
-
import { HandlerCallback } from './router/SwaggerRouter';
|
|
4
|
-
export declare type OperationArgs = any[];
|
|
5
|
-
export declare function invoke(controller: Object, operationName: string, args: OperationArgs, response: Response, next: HandlerCallback): void;
|