@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
package/lib/Sequence.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="http-errors" />
|
|
3
|
-
import { ServerRequest, ServerResponse } from 'http';
|
|
4
|
-
import { FindRoute, InvokeMethod, LogError, OperationRetval, ParsedRequest } from './internal-types';
|
|
5
|
-
import { HttpError } from 'http-errors';
|
|
6
|
-
export declare class Sequence {
|
|
7
|
-
protected findRoute: FindRoute;
|
|
8
|
-
protected invoke: InvokeMethod;
|
|
9
|
-
protected logError: LogError;
|
|
10
|
-
constructor(findRoute: FindRoute, invoke: InvokeMethod, logError: LogError);
|
|
11
|
-
run(req: ParsedRequest, res: ServerResponse): Promise<void>;
|
|
12
|
-
sendResponse(response: ServerResponse, result: OperationRetval): void;
|
|
13
|
-
sendError(res: ServerResponse, req: ServerRequest, err: HttpError): void;
|
|
14
|
-
}
|
package/lib/Sequence.js
DELETED
|
@@ -1,58 +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
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
7
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
9
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
10
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
11
|
-
};
|
|
12
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
13
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
14
|
-
};
|
|
15
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
16
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
17
|
-
};
|
|
18
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
const debug = require('debug')('loopback:core:sequence');
|
|
20
|
-
const context_1 = require("@loopback/context");
|
|
21
|
-
const parser_1 = require("./parser");
|
|
22
|
-
const writer_1 = require("./writer");
|
|
23
|
-
let Sequence = class Sequence {
|
|
24
|
-
constructor(findRoute, invoke, logError) {
|
|
25
|
-
this.findRoute = findRoute;
|
|
26
|
-
this.invoke = invoke;
|
|
27
|
-
this.logError = logError;
|
|
28
|
-
}
|
|
29
|
-
async run(req, res) {
|
|
30
|
-
try {
|
|
31
|
-
const { controller, methodName, spec, pathParams } = this.findRoute(req);
|
|
32
|
-
const args = await parser_1.parseOperationArgs(req, spec, pathParams);
|
|
33
|
-
const result = await this.invoke(controller, methodName, args);
|
|
34
|
-
debug('%s.%s() result -', controller, methodName, result);
|
|
35
|
-
this.sendResponse(res, result);
|
|
36
|
-
}
|
|
37
|
-
catch (err) {
|
|
38
|
-
this.sendError(res, req, err);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
sendResponse(response, result) {
|
|
42
|
-
writer_1.writeResultToResponse(response, result);
|
|
43
|
-
}
|
|
44
|
-
sendError(res, req, err) {
|
|
45
|
-
const statusCode = err.statusCode || err.status || 500;
|
|
46
|
-
res.statusCode = statusCode;
|
|
47
|
-
res.end();
|
|
48
|
-
this.logError(err, statusCode, req);
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
Sequence = __decorate([
|
|
52
|
-
__param(0, context_1.inject('findRoute')),
|
|
53
|
-
__param(1, context_1.inject('invokeMethod')),
|
|
54
|
-
__param(2, context_1.inject('logError')),
|
|
55
|
-
__metadata("design:paramtypes", [Function, Function, Function])
|
|
56
|
-
], Sequence);
|
|
57
|
-
exports.Sequence = Sequence;
|
|
58
|
-
//# sourceMappingURL=sequence.js.map
|
package/lib/application.d.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { Binding, Context, Constructor } from '@loopback/context';
|
|
3
|
-
import { Component } from '.';
|
|
4
|
-
import { ServerRequest, ServerResponse } from 'http';
|
|
5
|
-
import { HttpHandler } from './http-handler';
|
|
6
|
-
import { Sequence } from './sequence';
|
|
7
|
-
export declare class Application extends Context {
|
|
8
|
-
options: ApplicationOptions;
|
|
9
|
-
/**
|
|
10
|
-
* Handle incoming HTTP(S) request by invoking the corresponding
|
|
11
|
-
* Controller method via the configured Sequence.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
*
|
|
15
|
-
* ```ts
|
|
16
|
-
* const app = new Application();
|
|
17
|
-
* // setup controllers, etc.
|
|
18
|
-
*
|
|
19
|
-
* const server = http.createServer(app.handleHttp);
|
|
20
|
-
* server.listen(3000);
|
|
21
|
-
* ```
|
|
22
|
-
*
|
|
23
|
-
* @param req The request.
|
|
24
|
-
* @param res The response.
|
|
25
|
-
*/
|
|
26
|
-
handleHttp: (req: ServerRequest, res: ServerResponse) => Promise<void>;
|
|
27
|
-
protected _httpHandler: HttpHandler;
|
|
28
|
-
constructor(options?: ApplicationOptions);
|
|
29
|
-
protected _bindSequence(): void;
|
|
30
|
-
protected _handleHttpRequest(request: ServerRequest, response: ServerResponse): Promise<void>;
|
|
31
|
-
protected _setupHandlerIfNeeded(): void;
|
|
32
|
-
/**
|
|
33
|
-
* Register a controller class with this application.
|
|
34
|
-
*
|
|
35
|
-
* @param controllerCtor {Function} The controller class (constructor function).
|
|
36
|
-
* @return {Binding} The newly created binding, you can use the reference to further
|
|
37
|
-
* modify the binding, e.g. lock the value to prevent further modifications.
|
|
38
|
-
*
|
|
39
|
-
* ```ts
|
|
40
|
-
* @spec(apiSpec)
|
|
41
|
-
* class MyController {
|
|
42
|
-
* }
|
|
43
|
-
* app.controller(MyController).lock();
|
|
44
|
-
* ```
|
|
45
|
-
*/
|
|
46
|
-
controller<T>(controllerCtor: Constructor<T>): Binding;
|
|
47
|
-
protected _logError(err: Error, statusCode: number, req: ServerRequest): void;
|
|
48
|
-
}
|
|
49
|
-
export interface ApplicationOptions {
|
|
50
|
-
components?: Array<Constructor<Component>>;
|
|
51
|
-
sequence?: Constructor<Sequence>;
|
|
52
|
-
}
|
package/lib/application.js
DELETED
|
@@ -1,79 +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 http_handler_1 = require("./http-handler");
|
|
10
|
-
const sequence_1 = require("./sequence");
|
|
11
|
-
const debug = require('debug')('loopback:core:application');
|
|
12
|
-
class Application extends context_1.Context {
|
|
13
|
-
constructor(options) {
|
|
14
|
-
super();
|
|
15
|
-
this.options = options;
|
|
16
|
-
if (options && options.components) {
|
|
17
|
-
for (const component of options.components) {
|
|
18
|
-
// TODO(superkhau): Need to figure a way around this hack,
|
|
19
|
-
// `componentClassName.constructor.name` + `componentClassName.name`
|
|
20
|
-
// doesn't work
|
|
21
|
-
const componentClassName = component.toString().split(' ')[1];
|
|
22
|
-
this.bind(`component.${componentClassName}`).toClass(component);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
this._bindSequence();
|
|
26
|
-
this.handleHttp = (req, res) => this._handleHttpRequest(req, res);
|
|
27
|
-
this.bind('logError').to(this._logError.bind(this));
|
|
28
|
-
}
|
|
29
|
-
_bindSequence() {
|
|
30
|
-
// TODO(bajtos, ritch, superkhau) figure out how to integrate this single
|
|
31
|
-
// sequence with custom sequences contributed by components
|
|
32
|
-
const sequence = this.options && this.options.sequence ?
|
|
33
|
-
this.options.sequence :
|
|
34
|
-
sequence_1.Sequence;
|
|
35
|
-
this.bind('sequence').toClass(sequence);
|
|
36
|
-
}
|
|
37
|
-
_handleHttpRequest(request, response) {
|
|
38
|
-
this._setupHandlerIfNeeded();
|
|
39
|
-
return this._httpHandler.handleRequest(request, response);
|
|
40
|
-
}
|
|
41
|
-
_setupHandlerIfNeeded() {
|
|
42
|
-
// TODO(bajtos) support hot-reloading of controllers
|
|
43
|
-
// after the app started. The idea is to rebuild the HttpHandler
|
|
44
|
-
// instance whenever a controller was added/deleted.
|
|
45
|
-
if (this._httpHandler)
|
|
46
|
-
return;
|
|
47
|
-
this._httpHandler = new http_handler_1.HttpHandler(this);
|
|
48
|
-
for (const b of this.find('controllers.*')) {
|
|
49
|
-
const ctor = b.valueConstructor;
|
|
50
|
-
if (!ctor) {
|
|
51
|
-
throw new Error(`The controller ${b.key} was not bound via .toClass()`);
|
|
52
|
-
}
|
|
53
|
-
const apiSpec = metadata_1.getApiSpec(ctor);
|
|
54
|
-
this._httpHandler.registerController(b.key, apiSpec);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Register a controller class with this application.
|
|
59
|
-
*
|
|
60
|
-
* @param controllerCtor {Function} The controller class (constructor function).
|
|
61
|
-
* @return {Binding} The newly created binding, you can use the reference to further
|
|
62
|
-
* modify the binding, e.g. lock the value to prevent further modifications.
|
|
63
|
-
*
|
|
64
|
-
* ```ts
|
|
65
|
-
* @spec(apiSpec)
|
|
66
|
-
* class MyController {
|
|
67
|
-
* }
|
|
68
|
-
* app.controller(MyController).lock();
|
|
69
|
-
* ```
|
|
70
|
-
*/
|
|
71
|
-
controller(controllerCtor) {
|
|
72
|
-
return this.bind('controllers.' + controllerCtor.name).toClass(controllerCtor);
|
|
73
|
-
}
|
|
74
|
-
_logError(err, statusCode, req) {
|
|
75
|
-
console.error('Unhandled error in %s %s: %s %s', req.method, req.url, statusCode, err.stack || err);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
exports.Application = Application;
|
|
79
|
-
//# sourceMappingURL=application.js.map
|
package/lib/application.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"application.js","sourceRoot":"","sources":["../src/application.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,8BAA8B;AAC9B,+CAA+C;AAC/C,gEAAgE;;AAEhE,+CAAgE;AAGhE,gDAA6C;AAC7C,iDAA2C;AAC3C,yCAAoC;AAEpC,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,2BAA2B,CAAC,CAAC;AAE5D,iBAAyB,SAAQ,iBAAO;IAsBtC,YAAmB,OAA4B;QAC7C,KAAK,EAAE,CAAC;QADS,YAAO,GAAP,OAAO,CAAqB;QAG7C,EAAE,CAAC,CAAC,OAAO,IAAI,OAAO,CAAC,UAAU,CAA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9B,IAAI,CAAC,YAAY,GAAG,IAAI,0BAAW,CAAC,IAAI,CAAC,CAAC;QAC1C,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;YAC3C,MAAM,IAAI,GAAG,CAAC,CAAC,gBAAgB,CAAC;YAChC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;gBACV,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC,GAAG,+BAA+B,CAAC,CAAC;YAC1E,CAAC;YACD,MAAM,OAAO,GAAG,qBAAU,CAAC,IAAI,CAAC,CAAC;YACjC,IAAI,CAAC,YAAY,CAAC,kBAAkB,CAAC,CAAC,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QACvD,CAAC;IACH,CAAC;IAED;;;;;;;;;;;;;OAaG;IACI,UAAU,CAAI,cAA8B;QACjD,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;IACjF,CAAC;IAES,SAAS,CAAC,GAAU,EAAE,UAAkB,EAAE,GAAkB;QACpE,OAAO,CAAC,KAAK,CAAC,iCAAiC,EAC7C,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,EAAE,UAAU,EAAE,GAAG,CAAC,KAAK,IAAI,GAAG,CAAC,CAAC;IACvD,CAAC;CACF;AAhGD,kCAgGC"}
|
package/lib/component.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"component.js","sourceRoot":"","sources":["../src/component.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,8BAA8B;AAC9B,+CAA+C;AAC/C,gEAAgE"}
|
package/lib/handlers/http.d.ts
DELETED
package/lib/handlers/http.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright IBM Corp. 2017. All Rights Reserved.
|
|
3
|
-
// Node module: loopback
|
|
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
|
-
function httpHandler(app) {
|
|
8
|
-
return async (req, res) => {
|
|
9
|
-
await app.handleHttp(req, res);
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
exports.httpHandler = httpHandler;
|
|
13
|
-
//# sourceMappingURL=http.js.map
|
package/lib/handlers/http.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/handlers/http.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,wBAAwB;AACxB,+CAA+C;AAC/C,gEAAgE;;AAMhE,qBAA4B,GAAgB;IAC1C,MAAM,CAAC,KAAK,EAAE,GAAkB,EAAE,GAAmB;QACnD,MAAM,GAAG,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACjC,CAAC,CAAC;AACJ,CAAC;AAJD,kCAIC"}
|
package/lib/handlers/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './http';
|
package/lib/handlers/index.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright IBM Corp. 2017. All Rights Reserved.
|
|
3
|
-
// Node module: loopback
|
|
4
|
-
// This file is licensed under the MIT License.
|
|
5
|
-
// License text available at https://opensource.org/licenses/MIT
|
|
6
|
-
function __export(m) {
|
|
7
|
-
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
|
8
|
-
}
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
__export(require("./http"));
|
|
11
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/handlers/index.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,wBAAwB;AACxB,+CAA+C;AAC/C,gEAAgE;;;;;AAEhE,4BAAuB"}
|
package/lib/http-handler.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { Context } from '@loopback/context';
|
|
3
|
-
import { OpenApiSpec } from '@loopback/openapi-spec';
|
|
4
|
-
import { ServerRequest, ServerResponse } from 'http';
|
|
5
|
-
import { RoutingTable } from './router/routing-table';
|
|
6
|
-
export declare class HttpHandler {
|
|
7
|
-
protected _rootContext: Context;
|
|
8
|
-
protected _routes: RoutingTable<string>;
|
|
9
|
-
handleRequest: (request: ServerRequest, response: ServerResponse) => Promise<void>;
|
|
10
|
-
constructor(_rootContext: Context);
|
|
11
|
-
registerController(name: string, spec: OpenApiSpec): void;
|
|
12
|
-
protected _handleRequest(request: ServerRequest, response: ServerResponse): Promise<void>;
|
|
13
|
-
protected _createRequestContext(req: ServerRequest, res: ServerResponse): Context;
|
|
14
|
-
protected _bindFindRoute(context: Context): void;
|
|
15
|
-
protected _bindInvokeMethod(context: Context): void;
|
|
16
|
-
}
|
package/lib/http-handler.js
DELETED
|
@@ -1,62 +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 HttpErrors = require("http-errors");
|
|
9
|
-
const routing_table_1 = require("./router/routing-table");
|
|
10
|
-
const debug = require('debug')('loopback:core:http-handler');
|
|
11
|
-
class HttpHandler {
|
|
12
|
-
constructor(_rootContext) {
|
|
13
|
-
this._rootContext = _rootContext;
|
|
14
|
-
this._routes = new routing_table_1.RoutingTable();
|
|
15
|
-
this.handleRequest = (req, res) => this._handleRequest(req, res);
|
|
16
|
-
}
|
|
17
|
-
registerController(name, spec) {
|
|
18
|
-
this._routes.registerController(name, spec);
|
|
19
|
-
}
|
|
20
|
-
async _handleRequest(request, response) {
|
|
21
|
-
const parsedRequest = routing_table_1.parseRequestUrl(request);
|
|
22
|
-
const requestContext = this._createRequestContext(request, response);
|
|
23
|
-
this._bindFindRoute(requestContext);
|
|
24
|
-
this._bindInvokeMethod(requestContext);
|
|
25
|
-
const sequence = await requestContext.get('sequence');
|
|
26
|
-
return sequence.run(parsedRequest, response);
|
|
27
|
-
}
|
|
28
|
-
_createRequestContext(req, res) {
|
|
29
|
-
const requestContext = new context_1.Context(this._rootContext);
|
|
30
|
-
requestContext.bind('http.request').to(req);
|
|
31
|
-
requestContext.bind('http.response').to(res);
|
|
32
|
-
return requestContext;
|
|
33
|
-
}
|
|
34
|
-
_bindFindRoute(context) {
|
|
35
|
-
context.bind('findRoute').toDynamicValue(() => {
|
|
36
|
-
return (request) => {
|
|
37
|
-
const req = context.getSync('http.request');
|
|
38
|
-
const found = this._routes.find(req);
|
|
39
|
-
if (!found)
|
|
40
|
-
throw new HttpErrors.NotFound(`Endpoint "${req.method} ${req.path}" not found.`);
|
|
41
|
-
// bind routing information to context
|
|
42
|
-
const ctor = context.getBinding(found.controller).valueConstructor;
|
|
43
|
-
if (!ctor)
|
|
44
|
-
throw new Error(`The controller ${found.controller} was not bound via .toClass()`);
|
|
45
|
-
context.bind('controller.current.ctor').to(ctor);
|
|
46
|
-
context.bind('controller.current.operation').to(found.methodName);
|
|
47
|
-
return found;
|
|
48
|
-
};
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
_bindInvokeMethod(context) {
|
|
52
|
-
context.bind('invokeMethod').toDynamicValue(() => {
|
|
53
|
-
return async (controllerName, method, args) => {
|
|
54
|
-
const controller = await context.get(controllerName);
|
|
55
|
-
const result = await controller[method](...args);
|
|
56
|
-
return result;
|
|
57
|
-
};
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
exports.HttpHandler = HttpHandler;
|
|
62
|
-
//# sourceMappingURL=http-handler.js.map
|
package/lib/http-handler.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"http-handler.js","sourceRoot":"","sources":["../src/http-handler.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,8BAA8B;AAC9B,+CAA+C;AAC/C,gEAAgE;;AAEhE,+CAA0C;AAI1C,0CAA0C;AAG1C,0DAAqE;AAQrE,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,4BAA4B,CAAC,CAAC;AAE7D;IAKE,YAAsB,YAAqB;QAArB,iBAAY,GAAZ,YAAY,CAAS;QAJjC,YAAO,GAAyB,IAAI,4BAAY,EAAU,CAAC;QAKnE,IAAI,CAAC,aAAa,GAAG,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,CAAC,cAAc,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACnE,CAAC;IAED,kBAAkB,CAAC,IAAY,EAAE,IAAiB;QAChD,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC9C,CAAC;IAES,KAAK,CAAC,cAAc,CAAC,OAAsB,EAAE,QAAwB;QAC7E,MAAM,aAAa,GAAkB,+BAAe,CAAC,OAAO,CAAC,CAAC;QAC9D,MAAM,cAAc,GAAG,IAAI,CAAC,qBAAqB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;QAErE,IAAI,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC;QACpC,IAAI,CAAC,iBAAiB,CAAC,cAAc,CAAC,CAAC;QAEvC,MAAM,QAAQ,GAAa,MAAM,cAAc,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QAChE,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC;IAC/C,CAAC;IAES,qBAAqB,CAAC,GAAkB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AO,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,cAAc,CAAC;YAC1C,MAAM,CAAC,KAAK,EAAE,cAAsB,EAAE,MAAc,EAAE,IAAmB;gBACvE,MAAM,UAAU,GAAmC,MAAM,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;gBACrF,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;gBACjD,MAAM,CAAC,MAAM,CAAC;YAChB,CAAC,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AA5DD,kCA4DC"}
|
package/lib/index.d.ts
DELETED
|
@@ -1,16 +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 { ParsedRequest, OperationRetval, FindRoute, InvokeMethod, LogError, OperationArgs } from './internal-types';
|
|
12
|
-
export { parseOperationArgs } from './parser';
|
|
13
|
-
export { parseRequestUrl } from './router/routing-table';
|
|
14
|
-
export { RoutingTable, ResolvedRoute } from './router/routing-table';
|
|
15
|
-
export { HttpHandler } from './http-handler';
|
|
16
|
-
export { writeResultToResponse } from './writer';
|
package/lib/index.js
DELETED
|
@@ -1,33 +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
|
-
var parser_1 = require("./parser");
|
|
24
|
-
exports.parseOperationArgs = parser_1.parseOperationArgs;
|
|
25
|
-
var routing_table_1 = require("./router/routing-table");
|
|
26
|
-
exports.parseRequestUrl = routing_table_1.parseRequestUrl;
|
|
27
|
-
var routing_table_2 = require("./router/routing-table");
|
|
28
|
-
exports.RoutingTable = routing_table_2.RoutingTable;
|
|
29
|
-
var http_handler_1 = require("./http-handler");
|
|
30
|
-
exports.HttpHandler = http_handler_1.HttpHandler;
|
|
31
|
-
var writer_1 = require("./writer");
|
|
32
|
-
exports.writeResultToResponse = writer_1.writeResultToResponse;
|
|
33
|
-
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,8BAA8B;AAC9B,+CAA+C;AAC/C,gEAAgE;;AAEhE,uBAAuB;AACvB,6CAA0C;AAAlC,oCAAA,WAAW,CAAA;AAEnB,8CAAsC;AAA9B,yBAAA,GAAG,CAAA;AACX,uCAAoC;AAA5B,8BAAA,QAAQ,CAAA;AAChB,mCAA2D;AAAnD,0BAAA,MAAM,CAAA;AAAgB,+BAAA,WAAW,CAAA;AAEzC,wBAAwB;AACxB,6CAAyC;AAAjC,2BAAA,MAAM,CAAA;AAMd,sDAAsD;AACtD,0CAA0C;AAGlC,gCAAU;AAWlB,mCAA4C;AAApC,sCAAA,kBAAkB,CAAA;AAC1B,wDAAuD;AAA/C,0CAAA,eAAe,CAAA;AACvB,wDAAmE;AAA3D,uCAAA,YAAY,CAAA;AACpB,+CAA2C;AAAnC,qCAAA,WAAW,CAAA;AACnB,mCAA+C;AAAvC,yCAAA,qBAAqB,CAAA"}
|
package/lib/internal-types.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { ServerRequest } from 'http';
|
|
3
|
-
import { ResolvedRoute } from './router/routing-table';
|
|
4
|
-
export interface ParsedRequest extends ServerRequest {
|
|
5
|
-
path: string;
|
|
6
|
-
query: {
|
|
7
|
-
[key: string]: string;
|
|
8
|
-
};
|
|
9
|
-
url: string;
|
|
10
|
-
pathname: string;
|
|
11
|
-
method: string;
|
|
12
|
-
}
|
|
13
|
-
export declare type FindRoute = (request: ParsedRequest) => ResolvedRoute<string>;
|
|
14
|
-
export declare type InvokeMethod = (controller: string, method: string, args: OperationArgs) => Promise<OperationRetval>;
|
|
15
|
-
export declare type LogError = (err: Error, statusCode: number, request: ServerRequest) => void;
|
|
16
|
-
export declare type PathParameterValues = {
|
|
17
|
-
[key: string]: any;
|
|
18
|
-
};
|
|
19
|
-
export declare type OperationArgs = any[];
|
|
20
|
-
export declare type OperationRetval = any;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"internal-types.js","sourceRoot":"","sources":["../src/internal-types.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,8BAA8B;AAC9B,+CAA+C;AAC/C,gEAAgE;;AAwBhE,uBAAuB"}
|
package/lib/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;
|
package/lib/invoke.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 debug = require('debug')('loopback:invoker');
|
|
8
|
-
// tslint:enable:no-any
|
|
9
|
-
function invoke(controller, operationName, args, response, next) {
|
|
10
|
-
debug('invoke %s with arguments', operationName, args);
|
|
11
|
-
// TODO(bajtos) support sync operations that return the value directly (no Promise)
|
|
12
|
-
controller[operationName](...args).then(function onSuccess(result) {
|
|
13
|
-
debug('%s() result -', operationName, result);
|
|
14
|
-
// TODO(bajtos) handle non-string results via JSON.stringify
|
|
15
|
-
if (result) {
|
|
16
|
-
// TODO(ritch) remove this, should be configurable
|
|
17
|
-
response.setHeader('Content-Type', 'application/json');
|
|
18
|
-
// TODO(bajtos) handle errors - JSON.stringify can throw
|
|
19
|
-
if (typeof result === 'object')
|
|
20
|
-
result = JSON.stringify(result);
|
|
21
|
-
response.write(result);
|
|
22
|
-
}
|
|
23
|
-
response.end();
|
|
24
|
-
// Do not call next(), the request was handled.
|
|
25
|
-
}, function onError(err) {
|
|
26
|
-
debug('%s() failed - ', operationName, err.stack || err);
|
|
27
|
-
next(err);
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
exports.invoke = invoke;
|
package/lib/parser.d.ts
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { OperationObject } from '@loopback/openapi-spec';
|
|
2
|
-
import { OperationArgs, ParsedRequest, PathParameterValues } from './internal-types';
|
|
3
|
-
export declare function parseOperationArgs(request: ParsedRequest, operationSpec: OperationObject, pathParams: PathParameterValues): Promise<OperationArgs>;
|
package/lib/parser.js
DELETED
|
@@ -1,73 +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 _1 = require("./");
|
|
8
|
-
const promisify_1 = require("./promisify");
|
|
9
|
-
const jsonBody = require('body/json');
|
|
10
|
-
// tslint:enable:no-any
|
|
11
|
-
const parseJsonBody = promisify_1.promisify(jsonBody);
|
|
12
|
-
async function parseOperationArgs(request, operationSpec, pathParams) {
|
|
13
|
-
const args = [];
|
|
14
|
-
const body = await loadRequestBodyIfNeeded(operationSpec, request);
|
|
15
|
-
return buildOperationArguments(operationSpec, request, pathParams, body);
|
|
16
|
-
}
|
|
17
|
-
exports.parseOperationArgs = parseOperationArgs;
|
|
18
|
-
function loadRequestBodyIfNeeded(operationSpec, request) {
|
|
19
|
-
if (!hasArgumentsFromBody(operationSpec))
|
|
20
|
-
return Promise.resolve();
|
|
21
|
-
const contentType = request.headers['content-type'];
|
|
22
|
-
if (contentType && !/json/.test(contentType)) {
|
|
23
|
-
const err = new _1.HttpErrors.UnsupportedMediaType(`Content-type ${contentType} is not supported.`);
|
|
24
|
-
return Promise.reject(err);
|
|
25
|
-
}
|
|
26
|
-
return parseJsonBody(request).catch((err) => {
|
|
27
|
-
err.statusCode = 400;
|
|
28
|
-
return Promise.reject(err);
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
function hasArgumentsFromBody(operationSpec) {
|
|
32
|
-
if (!operationSpec.parameters || !operationSpec.parameters.length)
|
|
33
|
-
return false;
|
|
34
|
-
for (const paramSpec of operationSpec.parameters) {
|
|
35
|
-
if ('$ref' in paramSpec)
|
|
36
|
-
continue;
|
|
37
|
-
const source = paramSpec.in;
|
|
38
|
-
if (source === 'formData' || source === 'body')
|
|
39
|
-
return true;
|
|
40
|
-
}
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
function buildOperationArguments(operationSpec, request, pathParams, body) {
|
|
44
|
-
const args = [];
|
|
45
|
-
for (const paramSpec of operationSpec.parameters || []) {
|
|
46
|
-
if ('$ref' in paramSpec) {
|
|
47
|
-
// TODO(bajtos) implement $ref parameters
|
|
48
|
-
throw new Error('$ref parameters are not supported yet.');
|
|
49
|
-
}
|
|
50
|
-
const spec = paramSpec;
|
|
51
|
-
switch (spec.in) {
|
|
52
|
-
case 'query':
|
|
53
|
-
args.push(request.query[spec.name]);
|
|
54
|
-
break;
|
|
55
|
-
case 'path':
|
|
56
|
-
args.push(pathParams[spec.name]);
|
|
57
|
-
break;
|
|
58
|
-
case 'header':
|
|
59
|
-
args.push(request.headers[spec.name.toLowerCase()]);
|
|
60
|
-
break;
|
|
61
|
-
case 'formData':
|
|
62
|
-
args.push(body ? body[spec.name] : undefined);
|
|
63
|
-
break;
|
|
64
|
-
case 'body':
|
|
65
|
-
args.push(body);
|
|
66
|
-
break;
|
|
67
|
-
default:
|
|
68
|
-
throw new _1.HttpErrors.NotImplemented('Parameters with "in: ' + spec.in + '" are not supported yet.');
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
return args;
|
|
72
|
-
}
|
|
73
|
-
//# sourceMappingURL=parser.js.map
|
package/lib/parser.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parser.js","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,8BAA8B;AAC9B,+CAA+C;AAC/C,gEAAgE;;AAGhE,yBAA8B;AAE9B,2CAAsC;AAUtC,MAAM,QAAQ,GAAe,OAAO,CAAC,WAAW,CAAC,CAAC;AAIlD,uBAAuB;AAEvB,MA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;YACR,KAAK,MAAM;gBACT,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBAChB,KAAK,CAAC;YACR;gBACE,MAAM,IAAI,aAAU,CAAC,cAAc,CACjC,uBAAuB,GAAG,IAAI,CAAC,EAAE,GAAG,0BAA0B,CAAC,CAAC;QACtE,CAAC;IACH,CAAC;IACD,MAAM,CAAC,IAAI,CAAC;AACd,CAAC"}
|
package/lib/promisify.d.ts
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
export declare function promisify<T>(func: (callback: (err: any, result: T) => void) => void): () => Promise<T>;
|
|
2
|
-
export declare function promisify<T, A1>(func: (arg1: A1, callback: (err: any, result: T) => void) => void): (arg1: A1) => Promise<T>;
|
|
3
|
-
export declare function promisify<T, A1, A2>(func: (arg1: A1, arg2: A2, callback: (err: any, result: T) => void) => void): (arg1: A1, arg2: A2) => Promise<T>;
|
package/lib/promisify.js
DELETED
|
@@ -1,34 +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
|
-
// TODO(bajtos) Move this file to a standalone module, or find an existing
|
|
8
|
-
// npm module that we could use instead. Just make sure the existing
|
|
9
|
-
// module is using native utils.promisify() when available.
|
|
10
|
-
// tslint:disable:no-any
|
|
11
|
-
const util = require("util");
|
|
12
|
-
const nativePromisify = util.promisify;
|
|
13
|
-
function promisify(func) {
|
|
14
|
-
if (nativePromisify)
|
|
15
|
-
return nativePromisify(func);
|
|
16
|
-
// The simplest implementation of Promisify
|
|
17
|
-
return (...args) => {
|
|
18
|
-
return new Promise((resolve, reject) => {
|
|
19
|
-
try {
|
|
20
|
-
func(...args, (err, result) => {
|
|
21
|
-
if (err)
|
|
22
|
-
reject(err);
|
|
23
|
-
else
|
|
24
|
-
resolve(result);
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
catch (err) {
|
|
28
|
-
reject(err);
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
exports.promisify = promisify;
|
|
34
|
-
//# sourceMappingURL=promisify.js.map
|
package/lib/promisify.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"promisify.js","sourceRoot":"","sources":["../src/promisify.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,8BAA8B;AAC9B,+CAA+C;AAC/C,gEAAgE;;AAEhE,0EAA0E;AAC1E,oEAAoE;AACpE,2DAA2D;AAE3D,wBAAwB;AAExB,6BAA6B;AAE7B,MAAM,eAAe,GAAI,IAAY,CAAC,SAAS,CAAC;AAMhD,mBAA6B,IAA8B;IACzD,EAAE,CAAC,CAAC,eAAe,CAAC;QAClB,MAAM,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IAE/B,2CAA2C;IAC3C,MAAM,CAAC,CAAC,GAAG,IAAI;QACb,MAAM,CAAC,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM;YACjC,IAAI,CAAC;gBACH,IAAI,CAAC,GAAG,IAAI,EAAE,CAAC,GAAS,EAAE,MAAY;oBACpC,EAAE,CAAC,CAAC,GAAG,CAAC;wBAAC,MAAM,CAAC,GAAG,CAAC,CAAC;oBACrB,IAAI;wBAAC,OAAO,CAAC,MAAM,CAAC,CAAC;gBACvB,CAAC,CAAC,CAAC;YACL,CAAC;YAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;gBACb,MAAM,CAAC,GAAG,CAAC,CAAC;YACd,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAjBD,8BAiBC"}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { ServerRequest as Request, ServerResponse as Response } from 'http';
|
|
3
|
-
import { OpenApiSpec } from '@loopback/openapi-spec';
|
|
4
|
-
export declare type HandlerCallback = (err?: Error | string) => void;
|
|
5
|
-
export declare type RequestHandler = (req: Request, res: Response, cb?: HandlerCallback) => void;
|
|
6
|
-
export declare type ControllerFactory = (request: Request, response: Response, operationName: string) => Object;
|
|
7
|
-
/**
|
|
8
|
-
* SwaggerRouter - an express-compatible Router using OpenAPI/Swagger
|
|
9
|
-
* to define routes and input parameters
|
|
10
|
-
*/
|
|
11
|
-
export declare class SwaggerRouter {
|
|
12
|
-
/**
|
|
13
|
-
* The function handling incoming requests.
|
|
14
|
-
* Pass it Node.js HttpServer or register it
|
|
15
|
-
* as Express.js middleware.
|
|
16
|
-
*
|
|
17
|
-
* @param req {http.ServerRequest} The incoming request.
|
|
18
|
-
* @param res {http.ServerResponse} The response object.
|
|
19
|
-
* @param [cb] {Function} The callback to call when handling failed with an error,
|
|
20
|
-
* or when there is no endpoint registered to handle the request URL.
|
|
21
|
-
*/
|
|
22
|
-
readonly handler: RequestHandler;
|
|
23
|
-
private readonly _endpoints;
|
|
24
|
-
constructor();
|
|
25
|
-
/**
|
|
26
|
-
* Register a controller. The controller should be
|
|
27
|
-
* a regular ES6/TS class, use @api decorator to describe
|
|
28
|
-
* the REST API implemented by the controller.
|
|
29
|
-
* TODO(bajtos) How to support ES6 where decorators are not available?
|
|
30
|
-
*
|
|
31
|
-
* @param controllerCtor {ControllerFactory} A factory function accepting (Request, Response) arguments
|
|
32
|
-
* and returning the Controller instance to use.
|
|
33
|
-
* @param spec {OpenApiSpec} The Swagger specification describing the methods provided by this controller.
|
|
34
|
-
*/
|
|
35
|
-
controller(factory: ControllerFactory, spec: OpenApiSpec): void;
|
|
36
|
-
private _handleRequest(request, response, next);
|
|
37
|
-
private _finalHandler(req, res, err?);
|
|
38
|
-
logError(req: Request, statusCode: number, err: Error | string): void;
|
|
39
|
-
}
|