@loopback/core
Advanced tools
Comparing version 4.0.0-alpha.8 to 4.0.0-alpha.9
@@ -35,5 +35,7 @@ /// <reference types="node" /> | ||
* | ||
* @param controllerCtor {Function} The controller class (constructor function). | ||
* @return {Binding} The newly created binding, you can use the reference to further | ||
* modify the binding, e.g. lock the value to prevent further modifications. | ||
* @param controllerCtor {Function} The controller class | ||
* (constructor function). | ||
* @return {Binding} The newly created binding, you can use the reference to | ||
* further modify the binding, e.g. lock the value to prevent further | ||
* modifications. | ||
* | ||
@@ -40,0 +42,0 @@ * ```ts |
@@ -32,5 +32,5 @@ "use strict"; | ||
// sequence with custom sequences contributed by components | ||
const sequence = this.options && this.options.sequence ? | ||
this.options.sequence : | ||
sequence_1.Sequence; | ||
const sequence = this.options && this.options.sequence | ||
? this.options.sequence | ||
: sequence_1.Sequence; | ||
this.bind('sequence').toClass(sequence); | ||
@@ -61,5 +61,7 @@ } | ||
* | ||
* @param controllerCtor {Function} The controller class (constructor function). | ||
* @return {Binding} The newly created binding, you can use the reference to further | ||
* modify the binding, e.g. lock the value to prevent further modifications. | ||
* @param controllerCtor {Function} The controller class | ||
* (constructor function). | ||
* @return {Binding} The newly created binding, you can use the reference to | ||
* further modify the binding, e.g. lock the value to prevent further | ||
* modifications. | ||
* | ||
@@ -66,0 +68,0 @@ * ```ts |
@@ -17,1 +17,2 @@ export { Application } from './application'; | ||
export { writeResultToResponse } from './writer'; | ||
export * from './keys'; |
@@ -6,2 +6,5 @@ "use strict"; | ||
// License text available at https://opensource.org/licenses/MIT | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -34,2 +37,3 @@ // package dependencies | ||
exports.writeResultToResponse = writer_1.writeResultToResponse; | ||
__export(require("./keys")); | ||
//# sourceMappingURL=index.js.map |
@@ -14,2 +14,11 @@ /// <reference types="node" /> | ||
export declare type FindRoute = (request: ParsedRequest) => ResolvedRoute<string>; | ||
/** | ||
* Invokes a method defined in the Application Controller | ||
* | ||
* @param controller Name of end-user's application controller | ||
* class which defines the methods. | ||
* @param method Method name in application controller class | ||
* @param args Operation arguments for the method | ||
* @returns OperationRetval Result from method invocation | ||
*/ | ||
export declare type InvokeMethod = (controller: string, method: string, args: OperationArgs) => Promise<OperationRetval>; | ||
@@ -16,0 +25,0 @@ export declare type LogError = (err: Error, statusCode: number, request: ServerRequest) => void; |
import { OperationObject } from '@loopback/openapi-spec'; | ||
import { OperationArgs, ParsedRequest, PathParameterValues } from './internal-types'; | ||
/** | ||
* Parses the request to derive arguments to be passed in for the Application | ||
* controller method | ||
* | ||
* @param request Incoming HTTP request | ||
* @param operationSpec Swagger spec defined in the controller | ||
* @param pathParams Path parameters in incoming HTTP request | ||
*/ | ||
export declare function parseOperationArgs(request: ParsedRequest, operationSpec: OperationObject, pathParams: PathParameterValues): Promise<OperationArgs>; |
@@ -12,2 +12,25 @@ "use strict"; | ||
const parseJsonBody = promisify_1.promisify(jsonBody); | ||
/** | ||
* Get the content-type header value from the request | ||
* @param req Http request | ||
*/ | ||
function getContentType(req) { | ||
const val = req.headers['content-type']; | ||
if (typeof val === 'string') { | ||
return val; | ||
} | ||
else if (Array.isArray(val)) { | ||
// Assume only one value is present | ||
return val[0]; | ||
} | ||
return undefined; | ||
} | ||
/** | ||
* Parses the request to derive arguments to be passed in for the Application | ||
* controller method | ||
* | ||
* @param request Incoming HTTP request | ||
* @param operationSpec Swagger spec defined in the controller | ||
* @param pathParams Path parameters in incoming HTTP request | ||
*/ | ||
async function parseOperationArgs(request, operationSpec, pathParams) { | ||
@@ -22,3 +45,3 @@ const args = []; | ||
return Promise.resolve(); | ||
const contentType = request.headers['content-type']; | ||
const contentType = getContentType(request); | ||
if (contentType && !/json/.test(contentType)) { | ||
@@ -25,0 +48,0 @@ const err = new _1.HttpErrors.UnsupportedMediaType(`Content-type ${contentType} is not supported.`); |
@@ -37,3 +37,5 @@ "use strict"; | ||
// TODO(bajtos) handle the case where opSpec.parameters contains $ref | ||
debug(' %s %s -> %s(%s)', verb, path, opSpec['x-operation-name'], (opSpec.parameters || []).map(p => p.name).join(', ')); | ||
debug(' %s %s -> %s(%s)', verb, path, opSpec['x-operation-name'], (opSpec.parameters || []) | ||
.map(p => p.name) | ||
.join(', ')); | ||
this._routes.push(new RouteEntry(path, verb, opSpec, controller)); | ||
@@ -40,0 +42,0 @@ } |
@@ -21,8 +21,17 @@ "use strict"; | ||
server.listen(this.config.port); | ||
// FIXME(bajtos) The updated port number should be part of "status" object, | ||
// we shouldn't be changing original config IMO. | ||
// Consider exposing full base URL including http/https scheme prefix | ||
this.config.port = server.address().port; | ||
await new Promise(resolve => server.once('listening', resolve)); | ||
this.state = ServerState.listening; | ||
return new Promise((resolve, reject) => { | ||
server.once('listening', () => { | ||
// FIXME(bajtos) The updated port number should be part of "status" | ||
// object, we shouldn't be changing original config IMO. | ||
// Consider exposing full base URL including http/https scheme prefix | ||
try { | ||
this.config.port = server.address().port; | ||
this.state = ServerState.listening; | ||
resolve(); | ||
} | ||
catch (err) { | ||
reject(err); | ||
} | ||
}); | ||
}); | ||
} | ||
@@ -42,3 +51,5 @@ _handleRequest(req, res) { | ||
// and it's best to crash the process immediately. | ||
process.nextTick(() => { throw err; }); | ||
process.nextTick(() => { | ||
throw err; | ||
}); | ||
} | ||
@@ -45,0 +56,0 @@ } |
/// <reference types="node" /> | ||
import { ServerResponse as Response } from 'http'; | ||
import { OperationRetval } from './internal-types'; | ||
/** | ||
* Writes the result from Application controller method | ||
* into the HTTP response | ||
* | ||
* @param response HTTP Response | ||
* @param result Result from the API to write into HTTP Response | ||
*/ | ||
export declare function writeResultToResponse(response: Response, result: OperationRetval): void; |
@@ -7,3 +7,13 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function writeResultToResponse(response, // not needed and responsibility should be in the sequence.send | ||
/** | ||
* Writes the result from Application controller method | ||
* into the HTTP response | ||
* | ||
* @param response HTTP Response | ||
* @param result Result from the API to write into HTTP Response | ||
*/ | ||
function writeResultToResponse( | ||
// not needed and responsibility should be in the sequence.send | ||
response, | ||
// result returned back from invoking controller method | ||
result) { | ||
@@ -10,0 +20,0 @@ if (result) { |
@@ -35,5 +35,7 @@ /// <reference types="node" /> | ||
* | ||
* @param controllerCtor {Function} The controller class (constructor function). | ||
* @return {Binding} The newly created binding, you can use the reference to further | ||
* modify the binding, e.g. lock the value to prevent further modifications. | ||
* @param controllerCtor {Function} The controller class | ||
* (constructor function). | ||
* @return {Binding} The newly created binding, you can use the reference to | ||
* further modify the binding, e.g. lock the value to prevent further | ||
* modifications. | ||
* | ||
@@ -40,0 +42,0 @@ * ```ts |
@@ -32,5 +32,5 @@ "use strict"; | ||
// sequence with custom sequences contributed by components | ||
const sequence = this.options && this.options.sequence ? | ||
this.options.sequence : | ||
sequence_1.Sequence; | ||
const sequence = this.options && this.options.sequence | ||
? this.options.sequence | ||
: sequence_1.Sequence; | ||
this.bind('sequence').toClass(sequence); | ||
@@ -61,5 +61,7 @@ } | ||
* | ||
* @param controllerCtor {Function} The controller class (constructor function). | ||
* @return {Binding} The newly created binding, you can use the reference to further | ||
* modify the binding, e.g. lock the value to prevent further modifications. | ||
* @param controllerCtor {Function} The controller class | ||
* (constructor function). | ||
* @return {Binding} The newly created binding, you can use the reference to | ||
* further modify the binding, e.g. lock the value to prevent further | ||
* modifications. | ||
* | ||
@@ -66,0 +68,0 @@ * ```ts |
@@ -17,1 +17,2 @@ export { Application } from './application'; | ||
export { writeResultToResponse } from './writer'; | ||
export * from './keys'; |
@@ -6,2 +6,5 @@ "use strict"; | ||
// License text available at https://opensource.org/licenses/MIT | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -34,2 +37,3 @@ // package dependencies | ||
exports.writeResultToResponse = writer_1.writeResultToResponse; | ||
__export(require("./keys")); | ||
//# sourceMappingURL=index.js.map |
@@ -14,2 +14,11 @@ /// <reference types="node" /> | ||
export declare type FindRoute = (request: ParsedRequest) => ResolvedRoute<string>; | ||
/** | ||
* Invokes a method defined in the Application Controller | ||
* | ||
* @param controller Name of end-user's application controller | ||
* class which defines the methods. | ||
* @param method Method name in application controller class | ||
* @param args Operation arguments for the method | ||
* @returns OperationRetval Result from method invocation | ||
*/ | ||
export declare type InvokeMethod = (controller: string, method: string, args: OperationArgs) => Promise<OperationRetval>; | ||
@@ -16,0 +25,0 @@ export declare type LogError = (err: Error, statusCode: number, request: ServerRequest) => void; |
import { OperationObject } from '@loopback/openapi-spec'; | ||
import { OperationArgs, ParsedRequest, PathParameterValues } from './internal-types'; | ||
/** | ||
* Parses the request to derive arguments to be passed in for the Application | ||
* controller method | ||
* | ||
* @param request Incoming HTTP request | ||
* @param operationSpec Swagger spec defined in the controller | ||
* @param pathParams Path parameters in incoming HTTP request | ||
*/ | ||
export declare function parseOperationArgs(request: ParsedRequest, operationSpec: OperationObject, pathParams: PathParameterValues): Promise<OperationArgs>; |
@@ -20,2 +20,25 @@ "use strict"; | ||
const parseJsonBody = promisify_1.promisify(jsonBody); | ||
/** | ||
* Get the content-type header value from the request | ||
* @param req Http request | ||
*/ | ||
function getContentType(req) { | ||
const val = req.headers['content-type']; | ||
if (typeof val === 'string') { | ||
return val; | ||
} | ||
else if (Array.isArray(val)) { | ||
// Assume only one value is present | ||
return val[0]; | ||
} | ||
return undefined; | ||
} | ||
/** | ||
* Parses the request to derive arguments to be passed in for the Application | ||
* controller method | ||
* | ||
* @param request Incoming HTTP request | ||
* @param operationSpec Swagger spec defined in the controller | ||
* @param pathParams Path parameters in incoming HTTP request | ||
*/ | ||
function parseOperationArgs(request, operationSpec, pathParams) { | ||
@@ -32,3 +55,3 @@ return __awaiter(this, void 0, void 0, function* () { | ||
return Promise.resolve(); | ||
const contentType = request.headers['content-type']; | ||
const contentType = getContentType(request); | ||
if (contentType && !/json/.test(contentType)) { | ||
@@ -35,0 +58,0 @@ const err = new _1.HttpErrors.UnsupportedMediaType(`Content-type ${contentType} is not supported.`); |
@@ -37,3 +37,5 @@ "use strict"; | ||
// TODO(bajtos) handle the case where opSpec.parameters contains $ref | ||
debug(' %s %s -> %s(%s)', verb, path, opSpec['x-operation-name'], (opSpec.parameters || []).map(p => p.name).join(', ')); | ||
debug(' %s %s -> %s(%s)', verb, path, opSpec['x-operation-name'], (opSpec.parameters || []) | ||
.map(p => p.name) | ||
.join(', ')); | ||
this._routes.push(new RouteEntry(path, verb, opSpec, controller)); | ||
@@ -40,0 +42,0 @@ } |
@@ -30,8 +30,17 @@ "use strict"; | ||
server.listen(this.config.port); | ||
// FIXME(bajtos) The updated port number should be part of "status" object, | ||
// we shouldn't be changing original config IMO. | ||
// Consider exposing full base URL including http/https scheme prefix | ||
this.config.port = server.address().port; | ||
yield new Promise(resolve => server.once('listening', resolve)); | ||
this.state = ServerState.listening; | ||
return new Promise((resolve, reject) => { | ||
server.once('listening', () => { | ||
// FIXME(bajtos) The updated port number should be part of "status" | ||
// object, we shouldn't be changing original config IMO. | ||
// Consider exposing full base URL including http/https scheme prefix | ||
try { | ||
this.config.port = server.address().port; | ||
this.state = ServerState.listening; | ||
resolve(); | ||
} | ||
catch (err) { | ||
reject(err); | ||
} | ||
}); | ||
}); | ||
}); | ||
@@ -52,3 +61,5 @@ } | ||
// and it's best to crash the process immediately. | ||
process.nextTick(() => { throw err; }); | ||
process.nextTick(() => { | ||
throw err; | ||
}); | ||
} | ||
@@ -55,0 +66,0 @@ } |
/// <reference types="node" /> | ||
import { ServerResponse as Response } from 'http'; | ||
import { OperationRetval } from './internal-types'; | ||
/** | ||
* Writes the result from Application controller method | ||
* into the HTTP response | ||
* | ||
* @param response HTTP Response | ||
* @param result Result from the API to write into HTTP Response | ||
*/ | ||
export declare function writeResultToResponse(response: Response, result: OperationRetval): void; |
@@ -7,3 +7,13 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function writeResultToResponse(response, // not needed and responsibility should be in the sequence.send | ||
/** | ||
* Writes the result from Application controller method | ||
* into the HTTP response | ||
* | ||
* @param response HTTP Response | ||
* @param result Result from the API to write into HTTP Response | ||
*/ | ||
function writeResultToResponse( | ||
// not needed and responsibility should be in the sequence.send | ||
response, | ||
// result returned back from invoking controller method | ||
result) { | ||
@@ -10,0 +20,0 @@ if (result) { |
{ | ||
"name": "@loopback/core", | ||
"version": "4.0.0-alpha.8", | ||
"version": "4.0.0-alpha.9", | ||
"description": "", | ||
@@ -21,4 +21,4 @@ "scripts": { | ||
"dependencies": { | ||
"@loopback/context": "^4.0.0-alpha.7", | ||
"@loopback/openapi-spec": "^4.0.0-alpha.5", | ||
"@loopback/context": "^4.0.0-alpha.9", | ||
"@loopback/openapi-spec": "^4.0.0-alpha.6", | ||
"@types/bluebird": "^3.5.2", | ||
@@ -33,4 +33,4 @@ "@types/http-errors": "^1.5.34", | ||
"devDependencies": { | ||
"@loopback/openapi-spec-builder": "^4.0.0-alpha.3", | ||
"@loopback/testlab": "^4.0.0-alpha.4", | ||
"@loopback/openapi-spec-builder": "^4.0.0-alpha.4", | ||
"@loopback/testlab": "^4.0.0-alpha.5", | ||
"mocha": "^3.2.0", | ||
@@ -37,0 +37,0 @@ "typescript": "^2.3.2" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7
114089
82
1869