@loopback/core 4.0.0-alpha.9 → 4.0.2

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.
Files changed (121) hide show
  1. package/LICENSE +25 -0
  2. package/README.md +77 -2
  3. package/dist/application.d.ts +341 -0
  4. package/dist/application.js +554 -0
  5. package/dist/application.js.map +1 -0
  6. package/dist/component.d.ts +80 -0
  7. package/dist/component.js +59 -0
  8. package/dist/component.js.map +1 -0
  9. package/dist/extension-point.d.ts +121 -0
  10. package/dist/extension-point.js +227 -0
  11. package/dist/extension-point.js.map +1 -0
  12. package/dist/index.d.ts +21 -0
  13. package/dist/index.js +31 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/keys.d.ts +97 -0
  16. package/dist/keys.js +109 -0
  17. package/dist/keys.js.map +1 -0
  18. package/dist/lifecycle-registry.d.ts +91 -0
  19. package/dist/lifecycle-registry.js +191 -0
  20. package/dist/lifecycle-registry.js.map +1 -0
  21. package/dist/lifecycle.d.ts +47 -0
  22. package/dist/lifecycle.js +56 -0
  23. package/dist/lifecycle.js.map +1 -0
  24. package/dist/mixin-target.d.ts +60 -0
  25. package/{lib6/internal-types.js → dist/mixin-target.js} +2 -3
  26. package/dist/mixin-target.js.map +1 -0
  27. package/dist/server.d.ts +16 -0
  28. package/{lib6/component.js → dist/server.js} +2 -2
  29. package/dist/server.js.map +1 -0
  30. package/dist/service.d.ts +63 -0
  31. package/dist/service.js +151 -0
  32. package/dist/service.js.map +1 -0
  33. package/package.json +39 -37
  34. package/src/application.ts +719 -0
  35. package/src/component.ts +155 -0
  36. package/src/extension-point.ts +312 -0
  37. package/src/index.ts +29 -0
  38. package/src/keys.ts +144 -0
  39. package/src/lifecycle-registry.ts +268 -0
  40. package/src/lifecycle.ts +90 -0
  41. package/src/mixin-target.ts +69 -0
  42. package/src/server.ts +22 -0
  43. package/src/service.ts +211 -0
  44. package/index.d.ts +0 -6
  45. package/index.js +0 -9
  46. package/lib/application.d.ts +0 -54
  47. package/lib/application.js +0 -81
  48. package/lib/application.js.map +0 -1
  49. package/lib/component.d.ts +0 -2
  50. package/lib/component.js +0 -7
  51. package/lib/component.js.map +0 -1
  52. package/lib/http-handler.d.ts +0 -16
  53. package/lib/http-handler.js +0 -62
  54. package/lib/http-handler.js.map +0 -1
  55. package/lib/index.d.ts +0 -17
  56. package/lib/index.js +0 -37
  57. package/lib/index.js.map +0 -1
  58. package/lib/internal-types.d.ts +0 -29
  59. package/lib/internal-types.js +0 -8
  60. package/lib/internal-types.js.map +0 -1
  61. package/lib/keys.d.ts +0 -7
  62. package/lib/keys.js +0 -16
  63. package/lib/keys.js.map +0 -1
  64. package/lib/parser.d.ts +0 -11
  65. package/lib/parser.js +0 -96
  66. package/lib/parser.js.map +0 -1
  67. package/lib/promisify.d.ts +0 -3
  68. package/lib/promisify.js +0 -34
  69. package/lib/promisify.js.map +0 -1
  70. package/lib/router/metadata.d.ts +0 -12
  71. package/lib/router/metadata.js +0 -30
  72. package/lib/router/metadata.js.map +0 -1
  73. package/lib/router/routing-table.d.ts +0 -16
  74. package/lib/router/routing-table.js +0 -97
  75. package/lib/router/routing-table.js.map +0 -1
  76. package/lib/sequence.d.ts +0 -55
  77. package/lib/sequence.js +0 -99
  78. package/lib/sequence.js.map +0 -1
  79. package/lib/server.d.ts +0 -23
  80. package/lib/server.js +0 -64
  81. package/lib/server.js.map +0 -1
  82. package/lib/writer.d.ts +0 -11
  83. package/lib/writer.js +0 -34
  84. package/lib/writer.js.map +0 -1
  85. package/lib6/application.d.ts +0 -54
  86. package/lib6/application.js +0 -81
  87. package/lib6/application.js.map +0 -1
  88. package/lib6/component.d.ts +0 -2
  89. package/lib6/component.js.map +0 -1
  90. package/lib6/http-handler.d.ts +0 -16
  91. package/lib6/http-handler.js +0 -72
  92. package/lib6/http-handler.js.map +0 -1
  93. package/lib6/index.d.ts +0 -17
  94. package/lib6/index.js +0 -37
  95. package/lib6/index.js.map +0 -1
  96. package/lib6/internal-types.d.ts +0 -29
  97. package/lib6/internal-types.js.map +0 -1
  98. package/lib6/keys.d.ts +0 -7
  99. package/lib6/keys.js +0 -16
  100. package/lib6/keys.js.map +0 -1
  101. package/lib6/parser.d.ts +0 -11
  102. package/lib6/parser.js +0 -106
  103. package/lib6/parser.js.map +0 -1
  104. package/lib6/promisify.d.ts +0 -3
  105. package/lib6/promisify.js +0 -34
  106. package/lib6/promisify.js.map +0 -1
  107. package/lib6/router/metadata.d.ts +0 -12
  108. package/lib6/router/metadata.js +0 -30
  109. package/lib6/router/metadata.js.map +0 -1
  110. package/lib6/router/routing-table.d.ts +0 -16
  111. package/lib6/router/routing-table.js +0 -97
  112. package/lib6/router/routing-table.js.map +0 -1
  113. package/lib6/sequence.d.ts +0 -55
  114. package/lib6/sequence.js +0 -109
  115. package/lib6/sequence.js.map +0 -1
  116. package/lib6/server.d.ts +0 -23
  117. package/lib6/server.js +0 -74
  118. package/lib6/server.js.map +0 -1
  119. package/lib6/writer.d.ts +0 -11
  120. package/lib6/writer.js +0 -34
  121. package/lib6/writer.js.map +0 -1
@@ -1,97 +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 || [])
38
- .map(p => p.name)
39
- .join(', '));
40
- this._routes.push(new RouteEntry(path, verb, opSpec, controller));
41
- }
42
- }
43
- }
44
- find(request) {
45
- for (const entry of this._routes) {
46
- const match = entry.match(request);
47
- if (match)
48
- return match;
49
- }
50
- return undefined;
51
- }
52
- }
53
- exports.RoutingTable = RoutingTable;
54
- class RouteEntry {
55
- constructor(path, verb, _spec, _controller) {
56
- this._spec = _spec;
57
- this._controller = _controller;
58
- this._verb = verb.toLowerCase();
59
- // In Swagger, path parameters are wrapped in `{}`.
60
- // In Express.js, path parameters are prefixed with `:`
61
- path = path.replace(/{([^}]*)}(\/|$)/g, ':$1$2');
62
- this._pathRegexp = pathToRegexp(path, [], { strict: false, end: true });
63
- }
64
- match(request) {
65
- debug('trying endpoint', this);
66
- if (this._verb !== request.method.toLowerCase()) {
67
- debug(' -> verb mismatch');
68
- return undefined;
69
- }
70
- const match = this._pathRegexp.exec(request.path);
71
- if (!match) {
72
- debug(' -> path mismatch');
73
- return undefined;
74
- }
75
- const pathParams = this._buildPathParams(match);
76
- debug(' -> found with params: %j', pathParams);
77
- return this._createResolvedRoute(pathParams);
78
- }
79
- _createResolvedRoute(pathParams) {
80
- return {
81
- controller: this._controller,
82
- methodName: this._spec['x-operation-name'],
83
- spec: this._spec,
84
- pathParams: pathParams,
85
- };
86
- }
87
- _buildPathParams(pathMatch) {
88
- const pathParams = Object.create(null);
89
- for (const ix in this._pathRegexp.keys) {
90
- const key = this._pathRegexp.keys[ix];
91
- const matchIndex = +ix + 1;
92
- pathParams[key.name] = pathMatch[matchIndex];
93
- }
94
- return pathParams;
95
- }
96
- }
97
- //# 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;;AAWhE,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,GAAiC,EAAE,CAAC;IAsC9D,CAAC;IApCC,kBAAkB,CAAC,UAA0B,EAAE,IAAiB;QAC9D,MAAM,CACJ,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,CAAC,IAAI,EAClC,6CAA6C,CAC9C,CAAC;QACF,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;YACnD,MAAM,CAAC;QACT,CAAC;QAED,KAAK,CAAC,iCAAiC,EAAE,IAAI,CAAC,CAAC;QAE/C,GAAG,CAAC,CAAC,MAAM,IAAI,IAAI,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AAM,GAAG,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACtC,MAAM,UAAU,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;YAC3B,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC,UAAU,CAAC,CAAC;QAC/C,CAAC;QACD,MAAM,CAAC,UAAU,CAAC;IACpB,CAAC;CACF"}
package/lib/sequence.d.ts DELETED
@@ -1,55 +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
- /**
7
- * The default implementation of Sequence.
8
- *
9
- * This class implements default Sequence for the LoopBack framework.
10
- * Default sequence is used if user hasn't defined their own Sequence
11
- * for their application.
12
- *
13
- * Sequence constructor() and run() methods are invoked from [[http-handler]]
14
- * when the API request comes in. User defines APIs in their Application
15
- * Controller class.
16
- *
17
- * User can bind their own Sequence to app as shown below
18
- * ```ts
19
- * app.bind('sequence').toClass(MySequence);
20
- * ```
21
- */
22
- export declare class Sequence {
23
- protected findRoute: FindRoute;
24
- protected invoke: InvokeMethod;
25
- protected logError: LogError;
26
- /**
27
- * Constructor: Injects findRoute, invokeMethod & logError
28
- * methods as promises.
29
- *
30
- * @param findRoute Finds the appropriate controller method,
31
- * spec and args for invocation
32
- * @param invoke Invokes the method
33
- * @param logError Logs error
34
- */
35
- constructor(findRoute: FindRoute, invoke: InvokeMethod, logError: LogError);
36
- /**
37
- * Runs the default sequence. Given a request and response, running the
38
- * sequence will produce a response or an error.
39
- *
40
- * Default sequence executes these steps
41
- * - Finds the appropriate controller method, swagger spec
42
- * and args for invocation
43
- * - Parses HTTP request to get API argument list
44
- * - Invokes the API which is defined in the Application Controller
45
- * - Writes the result from API into the HTTP response
46
- * - Error is caught and logged using 'logError' if any of the above steps
47
- * in the sequence fails with an error.
48
- * @param req Parsed incoming HTTP request
49
- * @param res HTTP server response with result from Application controller
50
- * method invocation
51
- */
52
- run(req: ParsedRequest, res: ServerResponse): Promise<void>;
53
- sendResponse(response: ServerResponse, result: OperationRetval): void;
54
- sendError(res: ServerResponse, req: ServerRequest, err: HttpError): void;
55
- }
package/lib/sequence.js DELETED
@@ -1,99 +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
- /**
24
- * The default implementation of Sequence.
25
- *
26
- * This class implements default Sequence for the LoopBack framework.
27
- * Default sequence is used if user hasn't defined their own Sequence
28
- * for their application.
29
- *
30
- * Sequence constructor() and run() methods are invoked from [[http-handler]]
31
- * when the API request comes in. User defines APIs in their Application
32
- * Controller class.
33
- *
34
- * User can bind their own Sequence to app as shown below
35
- * ```ts
36
- * app.bind('sequence').toClass(MySequence);
37
- * ```
38
- */
39
- let Sequence = class Sequence {
40
- /**
41
- * Constructor: Injects findRoute, invokeMethod & logError
42
- * methods as promises.
43
- *
44
- * @param findRoute Finds the appropriate controller method,
45
- * spec and args for invocation
46
- * @param invoke Invokes the method
47
- * @param logError Logs error
48
- */
49
- constructor(findRoute, invoke, logError) {
50
- this.findRoute = findRoute;
51
- this.invoke = invoke;
52
- this.logError = logError;
53
- }
54
- /**
55
- * Runs the default sequence. Given a request and response, running the
56
- * sequence will produce a response or an error.
57
- *
58
- * Default sequence executes these steps
59
- * - Finds the appropriate controller method, swagger spec
60
- * and args for invocation
61
- * - Parses HTTP request to get API argument list
62
- * - Invokes the API which is defined in the Application Controller
63
- * - Writes the result from API into the HTTP response
64
- * - Error is caught and logged using 'logError' if any of the above steps
65
- * in the sequence fails with an error.
66
- * @param req Parsed incoming HTTP request
67
- * @param res HTTP server response with result from Application controller
68
- * method invocation
69
- */
70
- async run(req, res) {
71
- try {
72
- const { controller, methodName, spec, pathParams } = this.findRoute(req);
73
- const args = await parser_1.parseOperationArgs(req, spec, pathParams);
74
- const result = await this.invoke(controller, methodName, args);
75
- debug('%s.%s() result -', controller, methodName, result);
76
- this.sendResponse(res, result);
77
- }
78
- catch (err) {
79
- this.sendError(res, req, err);
80
- }
81
- }
82
- sendResponse(response, result) {
83
- writer_1.writeResultToResponse(response, result);
84
- }
85
- sendError(res, req, err) {
86
- const statusCode = err.statusCode || err.status || 500;
87
- res.statusCode = statusCode;
88
- res.end();
89
- this.logError(err, statusCode, req);
90
- }
91
- };
92
- Sequence = __decorate([
93
- __param(0, context_1.inject('findRoute')),
94
- __param(1, context_1.inject('invokeMethod')),
95
- __param(2, context_1.inject('logError')),
96
- __metadata("design:paramtypes", [Function, Function, Function])
97
- ], Sequence);
98
- exports.Sequence = Sequence;
99
- //# sourceMappingURL=sequence.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sequence.js","sourceRoot":"","sources":["../src/sequence.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,8BA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,GAAc;QAC/D,MAAM,UAAU,GAAG,GAAG,CAAC,UAAU,IAAI,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC;QACvD,GAAG,CAAC,UAAU,GAAG,UAAU,CAAC;QAC5B,GAAG,CAAC,GAAG,EAAE,CAAC;QAEV,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,UAAU,EAAE,GAAG,CAAC,CAAC;IACtC,CAAC;CACF,CAAA;AAxDY,QAAQ;IAWhB,WAAA,gBAAM,CAAC,WAAW,CAAC,CAAA;IACnB,WAAA,gBAAM,CAAC,cAAc,CAAC,CAAA;IACtB,WAAA,gBAAM,CAAC,UAAU,CAAC,CAAA;;GAbV,QAAQ,CAwDpB;AAxDY,4BAAQ"}
package/lib/server.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,64 +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
- return new Promise((resolve, reject) => {
22
- server.once('listening', () => {
23
- // FIXME(bajtos) The updated port number should be part of "status"
24
- // object, we shouldn't be changing original config IMO.
25
- // Consider exposing full base URL including http/https scheme prefix
26
- try {
27
- this.config.port = server.address().port;
28
- this.state = ServerState.listening;
29
- resolve();
30
- }
31
- catch (err) {
32
- reject(err);
33
- }
34
- });
35
- });
36
- }
37
- _handleRequest(req, res) {
38
- this.app.handleHttp(req, res).catch((err) => {
39
- this._onUnhandledError(req, res, err);
40
- });
41
- }
42
- _onUnhandledError(req, res, err) {
43
- if (!res.headersSent) {
44
- res.statusCode = 500;
45
- res.end();
46
- }
47
- // It's the responsibility of the Application to handle any errors.
48
- // If an unhandled error escaped, then something very wrong happened
49
- // and it's best to crash the process immediately.
50
- process.nextTick(() => {
51
- throw err;
52
- });
53
- }
54
- }
55
- exports.Server = Server;
56
- var ServerState;
57
- (function (ServerState) {
58
- ServerState[ServerState["cold"] = 0] = "cold";
59
- ServerState[ServerState["starting"] = 1] = "starting";
60
- ServerState[ServerState["listening"] = 2] = "listening";
61
- ServerState[ServerState["crashed"] = 3] = "crashed";
62
- ServerState[ServerState["stopped"] = 4] = "stopped";
63
- })(ServerState = exports.ServerState || (exports.ServerState = {}));
64
- //# 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,CAAC,OAAO,CAAC,CAAC,sBAAsB,CAAC,CAAC;AAEvD,YAAoB,SAAQ,iBAAO;IAGjC,YACS,GAAgB,EAChB,SAAuB,EAAC,IAAI,EAAE,IA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,GAAU;QAEV,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC;YACrB,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;YACf,MAAM,GAAG,CAAC;QACZ,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAzDD,wBAyDC;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/writer.d.ts DELETED
@@ -1,11 +0,0 @@
1
- /// <reference types="node" />
2
- import { ServerResponse as Response } from 'http';
3
- import { OperationRetval } from './internal-types';
4
- /**
5
- * Writes the result from Application controller method
6
- * into the HTTP response
7
- *
8
- * @param response HTTP Response
9
- * @param result Result from the API to write into HTTP Response
10
- */
11
- export declare function writeResultToResponse(response: Response, result: OperationRetval): void;
package/lib/writer.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
- /**
8
- * Writes the result from Application controller method
9
- * into the HTTP response
10
- *
11
- * @param response HTTP Response
12
- * @param result Result from the API to write into HTTP Response
13
- */
14
- function writeResultToResponse(
15
- // not needed and responsibility should be in the sequence.send
16
- response,
17
- // result returned back from invoking controller method
18
- result) {
19
- if (result) {
20
- if (typeof result === 'object') {
21
- // TODO(ritch) remove this, should be configurable
22
- response.setHeader('Content-Type', 'application/json');
23
- // TODO(bajtos) handle errors - JSON.stringify can throw
24
- result = JSON.stringify(result);
25
- }
26
- else if (typeof result === 'string') {
27
- response.setHeader('Content-Type', 'text/plain');
28
- }
29
- response.write(result);
30
- }
31
- response.end();
32
- }
33
- exports.writeResultToResponse = writeResultToResponse;
34
- //# sourceMappingURL=writer.js.map
package/lib/writer.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"writer.js","sourceRoot":"","sources":["../src/writer.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,8BAA8B;AAC9B,+CAA+C;AAC/C,gEAAgE;;AAIhE;;;;;;GAMG;AACH;IACE,+DAA+D;IAC/D,QAAkB;IAClB,uDAAuD;IACvD,MAAuB;IAEvB,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;QACX,EAAE,CAAC,CAAC,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC;YAC/B,kDAAkD;YAClD,QAAQ,CAAC,SAAS,CAAC,cAAc,EAAE,kBAAkB,CAAC,CAAC;YACvD,wDAAwD;YACxD,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QAClC,CAAC;QAAC,IAAI,CAAC,EAAE,CAAC,CAAC,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC;YACtC,QAAQ,CAAC,SAAS,CAAC,cAAc,EAAE,YAAY,CAAC,CAAC;QACnD,CAAC;QACD,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IACzB,CAAC;IACD,QAAQ,CAAC,GAAG,EAAE,CAAC;AACjB,CAAC;AAlBD,sDAkBC"}
@@ -1,54 +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
36
- * (constructor function).
37
- * @return {Binding} The newly created binding, you can use the reference to
38
- * further modify the binding, e.g. lock the value to prevent further
39
- * modifications.
40
- *
41
- * ```ts
42
- * @spec(apiSpec)
43
- * class MyController {
44
- * }
45
- * app.controller(MyController).lock();
46
- * ```
47
- */
48
- controller<T>(controllerCtor: Constructor<T>): Binding;
49
- protected _logError(err: Error, statusCode: number, req: ServerRequest): void;
50
- }
51
- export interface ApplicationOptions {
52
- components?: Array<Constructor<Component>>;
53
- sequence?: Constructor<Sequence>;
54
- }
@@ -1,81 +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
61
- * (constructor function).
62
- * @return {Binding} The newly created binding, you can use the reference to
63
- * further modify the binding, e.g. lock the value to prevent further
64
- * modifications.
65
- *
66
- * ```ts
67
- * @spec(apiSpec)
68
- * class MyController {
69
- * }
70
- * app.controller(MyController).lock();
71
- * ```
72
- */
73
- controller(controllerCtor) {
74
- return this.bind('controllers.' + controllerCtor.name).toClass(controllerCtor);
75
- }
76
- _logError(err, statusCode, req) {
77
- console.error('Unhandled error in %s %s: %s %s', req.method, req.url, statusCode, err.stack || err);
78
- }
79
- }
80
- exports.Application = Application;
81
- //# sourceMappingURL=application.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"application.js","sourceRoot":"","sources":["../src/application.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,8BAA8B;AAC9B,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;CACF;AAhHD,kCAgHC"}
@@ -1,2 +0,0 @@
1
- export interface Component {
2
- }
@@ -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"}
@@ -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
- }
@@ -1,72 +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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
7
- return new (P || (P = Promise))(function (resolve, reject) {
8
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
9
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
10
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
11
- step((generator = generator.apply(thisArg, _arguments || [])).next());
12
- });
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const context_1 = require("@loopback/context");
16
- const HttpErrors = require("http-errors");
17
- const routing_table_1 = require("./router/routing-table");
18
- const debug = require('debug')('loopback:core:http-handler');
19
- class HttpHandler {
20
- constructor(_rootContext) {
21
- this._rootContext = _rootContext;
22
- this._routes = new routing_table_1.RoutingTable();
23
- this.handleRequest = (req, res) => this._handleRequest(req, res);
24
- }
25
- registerController(name, spec) {
26
- this._routes.registerController(name, spec);
27
- }
28
- _handleRequest(request, response) {
29
- return __awaiter(this, void 0, void 0, function* () {
30
- const parsedRequest = routing_table_1.parseRequestUrl(request);
31
- const requestContext = this._createRequestContext(request, response);
32
- this._bindFindRoute(requestContext);
33
- this._bindInvokeMethod(requestContext);
34
- const sequence = yield requestContext.get('sequence');
35
- return sequence.run(parsedRequest, response);
36
- });
37
- }
38
- _createRequestContext(req, res) {
39
- const requestContext = new context_1.Context(this._rootContext);
40
- requestContext.bind('http.request').to(req);
41
- requestContext.bind('http.response').to(res);
42
- return requestContext;
43
- }
44
- _bindFindRoute(context) {
45
- context.bind('findRoute').toDynamicValue(() => {
46
- return (request) => {
47
- const req = context.getSync('http.request');
48
- const found = this._routes.find(req);
49
- if (!found)
50
- throw new HttpErrors.NotFound(`Endpoint "${req.method} ${req.path}" not found.`);
51
- // bind routing information to context
52
- const ctor = context.getBinding(found.controller).valueConstructor;
53
- if (!ctor)
54
- throw new Error(`The controller ${found.controller} was not bound via .toClass()`);
55
- context.bind('controller.current.ctor').to(ctor);
56
- context.bind('controller.current.operation').to(found.methodName);
57
- return found;
58
- };
59
- });
60
- }
61
- _bindInvokeMethod(context) {
62
- context.bind('invokeMethod').toDynamicValue(() => {
63
- return (controllerName, method, args) => __awaiter(this, void 0, void 0, function* () {
64
- const controller = yield context.get(controllerName);
65
- const result = yield controller[method](...args);
66
- return result;
67
- });
68
- });
69
- }
70
- }
71
- exports.HttpHandler = HttpHandler;
72
- //# sourceMappingURL=http-handler.js.map