Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@curveball/core

Package Overview
Dependencies
Maintainers
3
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@curveball/core - npm Package Compare versions

Comparing version 0.10.0 to 0.11.0

dist/base-context.d.ts

8

changelog.md
Changelog
=========
0.11.0 (2020-02-26)
-------------------
* `Context` is no longer a class, it's an interface. It's default
implementation is now `BaseContext`. This allows plugins to modify the
interface and add new features.
0.10.0 (2020-01-05)

@@ -5,0 +13,0 @@ -------------------

6

dist/application.js

@@ -9,3 +9,3 @@ "use strict";

const http_1 = __importDefault(require("http"));
const context_1 = __importDefault(require("./context"));
const base_context_1 = __importDefault(require("./base-context"));
const memory_request_1 = __importDefault(require("./memory-request"));

@@ -110,3 +110,3 @@ const memory_response_1 = __importDefault(require("./memory-response"));

}
const context = new context_1.default(request, new memory_response_1.default());
const context = new base_context_1.default(request, new memory_response_1.default());
try {

@@ -137,3 +137,3 @@ await this.handle(context);

buildContextFromHttp(req, res) {
const context = new context_1.default(new request_1.default(req), new response_1.default(res));
const context = new base_context_1.default(new request_1.default(req), new response_1.default(res));
return context;

@@ -140,0 +140,0 @@ }

@@ -5,8 +5,3 @@ import { Middleware } from './application';

import Response from './response';
/**
* The Context object encapsulates a single HTTP request.
*
* It has references to the internal request and response object.
*/
export default class Context<ReqT = any, ResT = any> {
export default interface Context<ReqT = any, ResT = any> {
/**

@@ -32,3 +27,2 @@ * HTTP Request

};
constructor(req: Request, res: Response);
/**

@@ -39,3 +33,3 @@ * The Request path.

*/
get path(): string;
path: string;
/**

@@ -46,3 +40,3 @@ * HTTP method

*/
get method(): string;
method: string;
/**

@@ -53,3 +47,3 @@ * This object contains parsed query string parameters.

*/
get query(): {
query: {
[s: string]: string;

@@ -77,10 +71,4 @@ };

*/
get status(): number;
status: number;
/**
* Sets the HTTP response status code.
*
* This is a shortcut for response.status.
*/
set status(value: number);
/**
* Sends an informational (1xx status code) response.

@@ -87,0 +75,0 @@ *

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* The Context object encapsulates a single HTTP request.
*
* It has references to the internal request and response object.
*/
class Context {
constructor(req, res) {
this.request = req;
this.response = res;
this.state = {};
}
/**
* The Request path.
*
* Shortcut for request.path
*/
get path() {
return this.request.path;
}
/**
* HTTP method
*
* Shortcut for request.method
*/
get method() {
return this.request.method;
}
/**
* This object contains parsed query string parameters.
*
* This is a shortcut for request.query
*/
get query() {
return this.request.query;
}
/**
* accepts is used for negotation the Content-Type with a client.
*
* You can pass a content-type, or an array of content-types.
* The Content-Types you provide are a list of types your application
* supports.
*
* This function will then return the best possible type based on the Accept
* header.
*
* If no compatible types are found, this function returns null.
*
* This is a shortcut to request.accepts()
*/
accepts(...types) {
return this.request.accepts(...types);
}
/**
* HTTP status code.
*
* This is a shortcut for response.status
*/
get status() {
return this.response.status;
}
/**
* Sets the HTTP response status code.
*
* This is a shortcut for response.status.
*/
set status(value) {
this.response.status = value;
}
/**
* Sends an informational (1xx status code) response.
*
* This is a shortcut for response.sendInformational()
*/
sendInformational(status, headers) {
return this.response.sendInformational(status, headers);
}
/**
* Sends a HTTP/2 push.
*
* The passed middleware will be called with a new Context object specific
* for pushes.
*
* This is a shortcut for response.push()
*/
push(callback) {
return this.response.push(callback);
}
/**
* returns the ip address of the client that's trying to connect.
*
* If 'trustProxy' is set to true, it means the server is running behind a
* proxy, and the X-Forwarded-For header should be parsed instead.
*
* If there was no real HTTP client, this method will return null.
*/
ip(trustProxy = false) {
if (this.request.ip !== undefined) {
return this.request.ip(trustProxy);
}
return null;
}
/**
* redirect redirects the response with an optionally provided HTTP status
* code in the first position to the location provided in address. If no status
* is provided, 303 See Other is used.
*
* It is a wrapper method for the underlying Response.redirect function.
*
* @param {(string|number)} addrOrStatus if passed a string, the string will
* be used to set the Location header of the response object and the default status
* of 303 See Other will be used. If a number, an addressed must be passed in the second
* argument.
* @param {string} address If addrOrStatus is passed a status code, this value is
* set as the value of the response's Location header.
*/
redirect(addrOrStatus, address = '') {
if (typeof (addrOrStatus) === 'number') {
return this.response.redirect(addrOrStatus, address);
}
else {
return this.response.redirect(addrOrStatus);
}
}
}
exports.default = Context;
//# sourceMappingURL=context.js.map
import { default as Application, invokeMiddlewares, Middleware, middlewareCall } from './application';
import BaseContext from './base-context';
import Context from './context';

@@ -9,2 +10,2 @@ import Headers from './headers';

export default Application;
export { Application, Context, Headers, invokeMiddlewares, middlewareCall, Middleware, Request, Response, MemoryRequest, MemoryResponse, };
export { Application, BaseContext, Context, Headers, invokeMiddlewares, middlewareCall, Middleware, Request, Response, MemoryRequest, MemoryResponse, };

@@ -17,4 +17,4 @@ "use strict";

exports.middlewareCall = application_1.middlewareCall;
const context_1 = __importDefault(require("./context"));
exports.Context = context_1.default;
const base_context_1 = __importDefault(require("./base-context"));
exports.BaseContext = base_context_1.default;
const headers_1 = __importDefault(require("./headers"));

@@ -21,0 +21,0 @@ exports.Headers = headers_1.default;

@@ -9,3 +9,3 @@ "use strict";

const application_1 = require("../application");
const context_1 = __importDefault(require("../context"));
const base_context_1 = __importDefault(require("../base-context"));
const memory_request_1 = __importDefault(require("../memory-request"));

@@ -123,3 +123,3 @@ const memory_response_1 = __importDefault(require("../memory-response"));

}
const pushCtx = new context_1.default(new memory_request_1.default('GET', '|||DELIBERATELY_INVALID|||'), new memory_response_1.default());
const pushCtx = new base_context_1.default(new memory_request_1.default('GET', '|||DELIBERATELY_INVALID|||'), new memory_response_1.default());
await application_1.invokeMiddlewares(pushCtx, [callback]);

@@ -126,0 +126,0 @@ if (pushCtx.request.requestTarget === '|||DELIBERATELY_INVALID|||') {

{
"name": "@curveball/core",
"version": "0.10.0",
"version": "0.11.0",
"description": "Curveball is a framework writting in Typescript for Node.js",

@@ -13,3 +13,3 @@ "main": "dist/index.js",

"type": "git",
"url": "git+https://github.com/curveballjs/core.git"
"url": "git+https://github.com/curveball/core.git"
},

@@ -32,21 +32,21 @@ "files": [

"bugs": {
"url": "https://github.com/curveballjs/core/issues"
"url": "https://github.com/curveball/core/issues"
},
"homepage": "https://github.com/curveballjs/core#readme",
"homepage": "https://github.com/curveball/core#readme",
"devDependencies": {
"@types/accepts": "^1.3.5",
"@types/chai": "^4.2.7",
"@types/chai": "^4.2.9",
"@types/co-body": "0.0.3",
"@types/mocha": "^5.2.7",
"@types/node": "^10.17.11",
"@types/node-fetch": "^2.5.4",
"@types/sinon": "^7.5.1",
"@types/mocha": "^7.0.1",
"@types/node": "^10.17.16",
"@types/node-fetch": "^2.5.5",
"@types/sinon": "^7.5.2",
"chai": "^4.2.0",
"mocha": "^6.2.2",
"mocha": "^7.1.0",
"node-fetch": "^2.6.0",
"nyc": "^15.0.0",
"sinon": "^8.0.0",
"ts-node": "^8.5.4",
"tslint": "^5.20.1",
"typescript": "^3.7.4"
"sinon": "^9.0.0",
"ts-node": "^8.6.2",
"tslint": "^6.0.0",
"typescript": "^3.8.2"
},

@@ -53,0 +53,0 @@ "types": "dist/",

Curveball
=========
[![Greenkeeper badge](https://badges.greenkeeper.io/curveballjs/core.svg)](https://greenkeeper.io/)
Curveball is a framework for building web services in Node.js. It fullfills a

@@ -57,7 +55,7 @@ similar role to [Express][1] and it's heavily inspired by [Koa][2].

* [Router](https://github.com/curveballjs/router).
* [Body Parser](https://github.com/curveballjs/bodyparser).
* [Sessions](https://github.com/curveballjs/session).
* [Simple controllers - ideal for resource-oriented routing](https://github.com/curveballjs/controller).
* [Generating application/problem+json responses](https://github.com/curveballjs/problem).
* [Router](https://github.com/curveball/router).
* [Body Parser](https://github.com/curveball/bodyparser).
* [Sessions](https://github.com/curveball/session).
* [Simple controllers - ideal for resource-oriented routing](https://github.com/curveball/controller).
* [Generating application/problem+json responses](https://github.com/curveball/problem).

@@ -64,0 +62,0 @@ Project status

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc