New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

curveball

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

curveball - npm Package Compare versions

Comparing version 0.1.2 to 0.2.0

14

changelog.md

@@ -0,1 +1,12 @@

0.2.0 (2018-06-25)
==================
* #19: Added `Request.rawBody()` method.
* #33: Added `Request.accept()` method.
* #35: Added `Request.type` and `Response.type`.
* #36: Added `Request.query`.
* #37: `Response.body` now has type `any`.
* #38: Added `Context.state`.
* #39: Added `Application.callback`.
0.1.2 (2018-06-24)

@@ -6,2 +17,3 @@ ==================

0.1.1 (2018-06-24)

@@ -12,2 +24,3 @@ ==================

0.1.0 (2018-06-24)

@@ -19,2 +32,3 @@ ==================

0.0.1 (2018-06-23)

@@ -21,0 +35,0 @@ ==================

@@ -20,5 +20,13 @@ /// <reference types="node" />

private callMiddleware;
/**
* Starts a HTTP server on the specified port.
*/
listen(port: number): http.Server;
/**
* This function is a callback that can be used for Node's http.Server,
* https.Server, or http2.Server.
*/
callback(req: http.IncomingMessage, res: http.ServerResponse): Promise<void>;
createContext(req: http.IncomingMessage, res: http.ServerResponse): Context;
}
export {};

50

dist/application.js

@@ -41,26 +41,34 @@ "use strict";

}
/**
* Starts a HTTP server on the specified port.
*/
listen(port) {
const server = http_1.default.createServer(async (req, res) => {
try {
const ctx = this.createContext(req, res);
await this.handle(ctx);
if (typeof ctx.response.body === 'string') {
res.write(ctx.response.body);
}
else {
throw new Error('Only strings are supported currently');
}
res.end();
const server = http_1.default.createServer(this.callback.bind(this));
return server.listen(port);
}
/**
* This function is a callback that can be used for Node's http.Server,
* https.Server, or http2.Server.
*/
async callback(req, res) {
try {
const ctx = this.createContext(req, res);
await this.handle(ctx);
if (typeof ctx.response.body === 'string') {
res.write(ctx.response.body);
}
catch (err) {
console.error(err);
res.statusCode = 500;
res.write('Uncaught exception');
res.end();
if (this.listenerCount('error')) {
this.emit('error', err);
}
else {
throw new Error('Only strings are supported currently');
}
});
return server.listen(port);
res.end();
}
catch (err) {
console.error(err);
res.statusCode = 500;
res.write('Uncaught exception');
res.end();
if (this.listenerCount('error')) {
this.emit('error', err);
}
}
}

@@ -67,0 +75,0 @@ createContext(req, res) {

import Request from './request';
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 {
/**
* HTTP Request
*/
request: Request;
/**
* HTTP Response
*/
response: Response;
/**
* State information.
*
* The state property can be used to store request-specific state
* information. It's used to pass information between middlewares.
*
* For example, and authentication middleware might set a username
* in this property for other middlewares to use.
*/
state: {
[s: string]: any;
};
constructor(req: Request, res: Response);
}
"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 {

@@ -7,2 +12,3 @@ constructor(req, res) {

this.response = res;
this.state = {};
}

@@ -9,0 +15,0 @@ }

@@ -19,2 +19,6 @@ /**

get(name: string): string | null;
/**
* Removes a HTTP header
*/
delete(name: string): void;
}

@@ -41,3 +45,7 @@ declare type HeadersObj = {

get(name: string): string | null;
/**
* Removes a HTTP header
*/
delete(name: string): void;
}
export default Headers;

@@ -43,2 +43,8 @@ "use strict";

}
/**
* Removes a HTTP header
*/
delete(name) {
this.store[name.toLowerCase()] = undefined;
}
}

@@ -45,0 +51,0 @@ exports.Headers = Headers;

@@ -6,9 +6,12 @@ /// <reference types="node" />

export declare class NodeRequest implements Request {
private inner;
constructor(inner: http.IncomingMessage);
/**
* List of HTTP Headers
*/
readonly headers: HeadersInterface;
headers: HeadersInterface;
/**
* Node.js Request object
*/
private inner;
constructor(inner: http.IncomingMessage);
/**
* path-part of the request.

@@ -54,3 +57,44 @@ *

body: any;
/**
* This function returns the request body.
*
* If encoding is not specified, this function returns a Buffer. If encoding
* is specified, it will return a string.
* This function returns the request body.
*
* If encoding is not specified, this function returns a Buffer. If encoding
* is specified, it will return a string.
*
* You can only call this function once. Most likely you'll want a single
* middleware that calls this function and then sets `body`.
*/
rawBody(encoding?: string, limit?: string): Promise<string>;
rawBody(encoding?: undefined, limit?: string): Promise<Buffer>;
/**
* This object contains parsed query parameters.
*/
readonly query: {
[s: string]: string;
};
/**
* Returns the value of the Content-Type header, with any additional
* parameters such as charset= removed.
*
* If there was no Content-Type header, an empty string will be returned.
*/
readonly type: string;
/**
* 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.
*/
accepts(...types: string[]): null | string;
}
export default NodeRequest;

@@ -8,17 +8,10 @@ "use strict";

const url_1 = __importDefault(require("url"));
const accepts_1 = __importDefault(require("accepts"));
const raw_body_1 = __importDefault(require("raw-body"));
class NodeRequest {
constructor(inner) {
this.inner = inner;
this.headers = new headers_1.Headers(this.inner.headers);
}
/**
* List of HTTP Headers
*/
get headers() {
/**
* We're using a type cast here because the @types/node definition is not
* as correct.
*/
return new headers_1.Headers(this.inner.headers);
}
/**
* path-part of the request.

@@ -65,2 +58,50 @@ *

}
rawBody(encoding, limit) {
const options = {};
if (limit) {
options.limit = limit;
}
if (encoding) {
options.encoding = encoding;
}
const length = this.headers.get('Content-Length');
if (length) {
options.length = length;
}
return raw_body_1.default(this.inner, options);
}
/**
* This object contains parsed query parameters.
*/
get query() {
return url_1.default.parse(this.requestTarget, true).query;
}
/**
* Returns the value of the Content-Type header, with any additional
* parameters such as charset= removed.
*
* If there was no Content-Type header, an empty string will be returned.
*/
get type() {
const type = this.headers.get('content-type');
if (!type)
return '';
return type.split(';')[0];
}
/**
* 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.
*/
accepts(...types) {
const result = accepts_1.default(this.inner).type(types);
return result === false ? null : result;
}
}

@@ -67,0 +108,0 @@ exports.NodeRequest = NodeRequest;

@@ -26,2 +26,6 @@ /// <reference types="node" />

get(name: string): string | null;
/**
* Removes a HTTP header
*/
delete(name: string): void;
}

@@ -43,3 +47,10 @@ export declare class NodeResponse implements Response {

body: null | object | string;
/**
* Returns the value of the Content-Type header, with any additional
* parameters such as charset= removed.
*
* If there was no Content-Type header, an empty string will be returned.
*/
readonly type: string;
}
export default NodeResponse;

@@ -41,2 +41,8 @@ "use strict";

}
/**
* Removes a HTTP header
*/
delete(name) {
this.inner.removeHeader(name);
}
}

@@ -59,2 +65,14 @@ class NodeResponse {

}
/**
* Returns the value of the Content-Type header, with any additional
* parameters such as charset= removed.
*
* If there was no Content-Type header, an empty string will be returned.
*/
get type() {
const type = this.headers.get('content-type');
if (!type)
return '';
return type.split(';')[0];
}
}

@@ -61,0 +79,0 @@ exports.NodeResponse = NodeResponse;

@@ -0,1 +1,2 @@

/// <reference types="node" />
import { HeadersInterface } from './headers';

@@ -51,3 +52,40 @@ /**

body: any;
/**
* This function returns the request body.
*
* If encoding is not specified, this function returns a Buffer. If encoding
* is specified, it will return a string.
*
* You can only call this function once. Most likely you'll want a single
* middleware that calls this function and then sets `body`.
*/
rawBody(encoding?: string, limit?: string): Promise<string>;
rawBody(encoding?: undefined, limit?: string): Promise<Buffer>;
/**
* This object contains parsed query parameters.
*/
readonly query: {
[s: string]: string;
};
/**
* Returns the value of the Content-Type header, with any additional
* parameters such as charset= removed.
*
* If there was no Content-Type header, an empty string will be returned.
*/
readonly type: string;
/**
* 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.
*/
accepts(...types: string[]): null | string;
}
export default Request;

@@ -17,4 +17,11 @@ import { HeadersInterface } from './headers';

*/
body: null | object | string;
body: any;
/**
* Returns the value of the Content-Type header, with any additional
* parameters such as charset= removed.
*
* If there was no Content-Type header, an empty string will be returned.
*/
readonly type: string;
}
export default Response;
{
"name": "curveball",
"version": "0.1.2",
"version": "0.2.0",
"description": "Curveball is a framework writting in Typescript for Node.js",

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

"devDependencies": {
"@types/accepts": "^1.3.5",
"@types/chai": "^4.1.4",
"@types/co-body": "0.0.3",
"@types/mocha": "^5.2.3",

@@ -51,3 +53,7 @@ "@types/node": "^10.3.5",

]
},
"dependencies": {
"accepts": "^1.3.5",
"raw-body": "^2.3.3"
}
}

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