@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.
Files changed (179) 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/{lib/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/src/Component.js → dist/server.js} +2 -1
  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/Component.d.ts +0 -2
  47. package/lib/Component.js +0 -7
  48. package/lib/Sequence.d.ts +0 -14
  49. package/lib/Sequence.js +0 -58
  50. package/lib/application.d.ts +0 -52
  51. package/lib/application.js +0 -79
  52. package/lib/application.js.map +0 -1
  53. package/lib/component.js.map +0 -1
  54. package/lib/handlers/http.d.ts +0 -3
  55. package/lib/handlers/http.js +0 -13
  56. package/lib/handlers/http.js.map +0 -1
  57. package/lib/handlers/index.d.ts +0 -1
  58. package/lib/handlers/index.js +0 -11
  59. package/lib/handlers/index.js.map +0 -1
  60. package/lib/http-handler.d.ts +0 -16
  61. package/lib/http-handler.js +0 -62
  62. package/lib/http-handler.js.map +0 -1
  63. package/lib/index.d.ts +0 -16
  64. package/lib/index.js +0 -33
  65. package/lib/index.js.map +0 -1
  66. package/lib/internal-types.d.ts +0 -20
  67. package/lib/internal-types.js.map +0 -1
  68. package/lib/invoke.d.ts +0 -5
  69. package/lib/invoke.js +0 -30
  70. package/lib/parser.d.ts +0 -3
  71. package/lib/parser.js +0 -73
  72. package/lib/parser.js.map +0 -1
  73. package/lib/promisify.d.ts +0 -3
  74. package/lib/promisify.js +0 -34
  75. package/lib/promisify.js.map +0 -1
  76. package/lib/router/SwaggerRouter.d.ts +0 -39
  77. package/lib/router/SwaggerRouter.js +0 -205
  78. package/lib/router/metadata.d.ts +0 -12
  79. package/lib/router/metadata.js +0 -30
  80. package/lib/router/metadata.js.map +0 -1
  81. package/lib/router/routing-table.d.ts +0 -16
  82. package/lib/router/routing-table.js +0 -95
  83. package/lib/router/routing-table.js.map +0 -1
  84. package/lib/sequence.js.map +0 -1
  85. package/lib/server.d.ts +0 -23
  86. package/lib/server.js +0 -53
  87. package/lib/server.js.map +0 -1
  88. package/lib/src/Component.d.ts +0 -2
  89. package/lib/src/Component.js +0 -6
  90. package/lib/src/Sequence.d.ts +0 -6
  91. package/lib/src/Sequence.js +0 -26
  92. package/lib/src/application.d.ts +0 -27
  93. package/lib/src/application.js +0 -70
  94. package/lib/src/index.d.ts +0 -13
  95. package/lib/src/index.js +0 -29
  96. package/lib/src/invoke.d.ts +0 -5
  97. package/lib/src/invoke.js +0 -34
  98. package/lib/src/parser.d.ts +0 -3
  99. package/lib/src/parser.js +0 -72
  100. package/lib/src/promisify.d.ts +0 -3
  101. package/lib/src/promisify.js +0 -33
  102. package/lib/src/router/SwaggerRouter.d.ts +0 -53
  103. package/lib/src/router/SwaggerRouter.js +0 -101
  104. package/lib/src/router/metadata.d.ts +0 -13
  105. package/lib/src/router/metadata.js +0 -29
  106. package/lib/src/router/routing-table.d.ts +0 -13
  107. package/lib/src/router/routing-table.js +0 -83
  108. package/lib/src/server.d.ts +0 -17
  109. package/lib/src/server.js +0 -40
  110. package/lib/writer.d.ts +0 -4
  111. package/lib/writer.js +0 -24
  112. package/lib/writer.js.map +0 -1
  113. package/lib6/Component.d.ts +0 -2
  114. package/lib6/Component.js +0 -7
  115. package/lib6/Sequence.d.ts +0 -14
  116. package/lib6/Sequence.js +0 -68
  117. package/lib6/application.d.ts +0 -52
  118. package/lib6/application.js +0 -79
  119. package/lib6/application.js.map +0 -1
  120. package/lib6/component.js.map +0 -1
  121. package/lib6/handlers/http.d.ts +0 -3
  122. package/lib6/handlers/http.js +0 -21
  123. package/lib6/handlers/http.js.map +0 -1
  124. package/lib6/handlers/index.d.ts +0 -1
  125. package/lib6/handlers/index.js +0 -11
  126. package/lib6/handlers/index.js.map +0 -1
  127. package/lib6/http-handler.d.ts +0 -16
  128. package/lib6/http-handler.js +0 -72
  129. package/lib6/http-handler.js.map +0 -1
  130. package/lib6/index.d.ts +0 -16
  131. package/lib6/index.js +0 -33
  132. package/lib6/index.js.map +0 -1
  133. package/lib6/internal-types.d.ts +0 -20
  134. package/lib6/internal-types.js +0 -8
  135. package/lib6/internal-types.js.map +0 -1
  136. package/lib6/invoke.d.ts +0 -5
  137. package/lib6/invoke.js +0 -30
  138. package/lib6/parser.d.ts +0 -3
  139. package/lib6/parser.js +0 -83
  140. package/lib6/parser.js.map +0 -1
  141. package/lib6/promisify.d.ts +0 -3
  142. package/lib6/promisify.js +0 -34
  143. package/lib6/promisify.js.map +0 -1
  144. package/lib6/router/SwaggerRouter.d.ts +0 -39
  145. package/lib6/router/SwaggerRouter.js +0 -205
  146. package/lib6/router/metadata.d.ts +0 -12
  147. package/lib6/router/metadata.js +0 -30
  148. package/lib6/router/metadata.js.map +0 -1
  149. package/lib6/router/routing-table.d.ts +0 -16
  150. package/lib6/router/routing-table.js +0 -95
  151. package/lib6/router/routing-table.js.map +0 -1
  152. package/lib6/sequence.js.map +0 -1
  153. package/lib6/server.d.ts +0 -23
  154. package/lib6/server.js +0 -63
  155. package/lib6/server.js.map +0 -1
  156. package/lib6/src/Component.d.ts +0 -2
  157. package/lib6/src/Sequence.d.ts +0 -6
  158. package/lib6/src/Sequence.js +0 -36
  159. package/lib6/src/application.d.ts +0 -27
  160. package/lib6/src/application.js +0 -70
  161. package/lib6/src/index.d.ts +0 -13
  162. package/lib6/src/index.js +0 -29
  163. package/lib6/src/invoke.d.ts +0 -5
  164. package/lib6/src/invoke.js +0 -34
  165. package/lib6/src/parser.d.ts +0 -3
  166. package/lib6/src/parser.js +0 -82
  167. package/lib6/src/promisify.d.ts +0 -3
  168. package/lib6/src/promisify.js +0 -33
  169. package/lib6/src/router/SwaggerRouter.d.ts +0 -53
  170. package/lib6/src/router/SwaggerRouter.js +0 -101
  171. package/lib6/src/router/metadata.d.ts +0 -13
  172. package/lib6/src/router/metadata.js +0 -29
  173. package/lib6/src/router/routing-table.d.ts +0 -13
  174. package/lib6/src/router/routing-table.js +0 -83
  175. package/lib6/src/server.d.ts +0 -17
  176. package/lib6/src/server.js +0 -50
  177. package/lib6/writer.d.ts +0 -4
  178. package/lib6/writer.js +0 -24
  179. 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
- }
@@ -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;
@@ -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,GAAiC,EAAE,CAAC;IA4B9D,CAAC;IA1BC,kBAAkB,CAAC,UAA0B,EAAE,IAAiB;QAC9D,MAAM,CAAC,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,CAAC,IAAI,EAAE,6CAA6C,CAAC,CAAC;QAC1F,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,IAAI,C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AAM,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,UAAU,EAAE,IAAI,CAAC,CAAC;gBAC/D,KAAK,CAAC,kBAAkB,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC;gBAC1D,IAAI,CAAC,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;YACjC,CAAC;YAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;gBACb,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;YAChC,CAAC;QACH,CAAC;KAAA;IAED,YAAY,CAAC,QAAwB,EAAE,MAAuB;QAC5D,8BAAqB,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAC1C,CAAC;IAED,SAAS,CAAC,GAAmB,EAAE,GAAkB,EAAE,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;AAjCY,QAAQ;IAEhB,WAAA,gBAAM,CAAC,WAAW,CAAC,CAAA;IAEnB,WAAA,gBAAM,CAAC,cAAc,CAAC,CAAA;IAEtB,WAAA,gBAAM,CAAC,UAAU,CAAC,CAAA;;GANV,QAAQ,CAiCpB;AAjCY,4BAAQ"}
package/lib6/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/lib6/server.js DELETED
@@ -1,63 +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 http_1 = require("http");
17
- const debug = require('debug')('loopback:core:server');
18
- class Server extends context_1.Context {
19
- constructor(app, config = { port: 3000 }) {
20
- super();
21
- this.app = app;
22
- this.config = config;
23
- this.state = ServerState.cold;
24
- }
25
- start() {
26
- return __awaiter(this, void 0, void 0, function* () {
27
- this.state = ServerState.starting;
28
- const server = http_1.createServer((req, res) => this._handleRequest(req, res));
29
- server.listen(this.config.port);
30
- // FIXME(bajtos) The updated port number should be part of "status" object,
31
- // we shouldn't be changing original config IMO.
32
- // Consider exposing full base URL including http/https scheme prefix
33
- this.config.port = server.address().port;
34
- yield new Promise(resolve => server.once('listening', resolve));
35
- this.state = ServerState.listening;
36
- });
37
- }
38
- _handleRequest(req, res) {
39
- this.app.handleHttp(req, res).catch((err) => {
40
- this._onUnhandledError(req, res, err);
41
- });
42
- }
43
- _onUnhandledError(req, res, err) {
44
- if (!res.headersSent) {
45
- res.statusCode = 500;
46
- res.end();
47
- }
48
- // It's the responsibility of the Application to handle any errors.
49
- // If an unhandled error escaped, then something very wrong happened
50
- // and it's best to crash the process immediately.
51
- process.nextTick(() => { throw err; });
52
- }
53
- }
54
- exports.Server = Server;
55
- var ServerState;
56
- (function (ServerState) {
57
- ServerState[ServerState["cold"] = 0] = "cold";
58
- ServerState[ServerState["starting"] = 1] = "starting";
59
- ServerState[ServerState["listening"] = 2] = "listening";
60
- ServerState[ServerState["crashed"] = 3] = "crashed";
61
- ServerState[ServerState["stopped"] = 4] = "stopped";
62
- })(ServerState = exports.ServerState || (exports.ServerState = {}));
63
- //# sourceMappingURL=server.js.map
@@ -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,YAAmB,GAAgB,EAAS,SAAuB,EAAC,IAAI,EAAE,IAAI,EAAC;QAC7E,KAAK,EAAE,CAAC;QADS,QAAG,GAAH,GAAG,CAAa;QAAS,WAAM,GAAN,MAAM,CAA6B;QAE7E,IAAI,CAAC,KAAK,GAAG,WAAW,CAAC,IAAI,CAAC;IAChC,CAAC;IAEK,KAAK;;YACT,IAAI,CAAC,KAAK,GAAG,WAAW,CAAC,QAAQ,CAAC;YAElC,MAAM,MAAM,GAAG,mBAAY,CAAC,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,CAAC,cAAc,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;YACzE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YAEhC,2EAA2E;YAC3E,gDAAgD;YAChD,qEAAqE;YACrE,IAAI,CAAC,MAAM,CAAC,IAAI,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC;YAEzC,MAAM,IAAI,OAAO,CAAC,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC;YAChE,IAAI,CAAC,KAAK,GAAG,WAAW,CAAC,SAAS,CAAC;QACrC,CAAC;KAAA;IAES,cAAc,CAAC,GAAkB,EAAE,GAAmB;QAC9D,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,GAAU;YAC7C,IAAI,CAAC,iBAAiB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;QACxC,CAAC,CAAC,CAAC;IACL,CAAC;IAES,iBAAiB,CAAC,GAAkB,EAAE,GAAmB,EAAE,GAAU;QAC7E,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,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"}
@@ -1,2 +0,0 @@
1
- export interface Component {
2
- }
@@ -1,6 +0,0 @@
1
- /// <reference types="node" />
2
- import { Server } from './server';
3
- import { ServerRequest, ServerResponse } from 'http';
4
- export declare class Sequence {
5
- run(server: Server, req: ServerRequest, res: ServerResponse): Promise<void>;
6
- }
@@ -1,36 +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 SwaggerRouter_1 = require("./router/SwaggerRouter");
16
- const debug = require('debug')('loopback:Server');
17
- class Sequence {
18
- run(server, req, res) {
19
- return __awaiter(this, void 0, void 0, function* () {
20
- // TODO(bajtos) support hot-reloading of controllers
21
- // after the app started. The idea is to rebuild the SwaggerRouter
22
- // instance whenever a controller was added/deleted.
23
- const router = new SwaggerRouter_1.SwaggerRouter();
24
- const apps = server.find('applications.*');
25
- for (const appBinding of apps) {
26
- debug('Registering app controllers for %j', appBinding.key);
27
- const app = yield Promise.resolve(appBinding.getValue(server));
28
- app.mountControllers(router);
29
- }
30
- router.handler(req, res, () => {
31
- console.log('done');
32
- });
33
- });
34
- }
35
- }
36
- exports.Sequence = Sequence;
@@ -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
- }
@@ -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;
@@ -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';