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.14.0 to 0.14.1

8

dist/application.js

@@ -18,2 +18,3 @@ "use strict";

const ws_1 = __importDefault(require("ws"));
// eslint-disable-next-line @typescript-eslint/no-var-requires
const pkg = require('../package.json');

@@ -100,7 +101,6 @@ /**

await this.handle(ctx);
// @ts-ignore - not sure why this line fails
http_utils_1.sendBody(res, ctx.response.body);
}
catch (err) {
// tslint:disable:no-console
// eslint-disable-next-line no-console
console.error(err);

@@ -115,3 +115,3 @@ if (http_errors_1.isHttpError(err)) {

res.end(
// @ts-ignore
// @ts-expect-error string error let's ignore
'Uncaught exception. No middleware was defined to handle it. We got the following HTTP status: ' +

@@ -152,3 +152,3 @@ res.statusCode);

catch (err) {
// tslint:disable:no-console
// eslint-disable-next-line no-console
console.error(err);

@@ -155,0 +155,0 @@ if (this.listenerCount('error')) {

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

this.originalBody = body;
// @ts-ignore: Typescript doesn't like null here because it might be
// @ts-expect-error Typescript doesn't like null here because it might be
// incompatible with T, but we're ignoring it as it's a good default.

@@ -23,0 +23,0 @@ this.body = null;

@@ -14,4 +14,2 @@ "use strict";

this.status = 200;
// @ts-ignore: Typescript doesn't like null here because it might be
// incompatible with T, but we're ignoring it as it's a good default.
this.body = null;

@@ -18,0 +16,0 @@ }

@@ -16,3 +16,3 @@ /// <reference types="node" />

export declare function isHttp2Response(response: NodeHttpResponse): response is http2.Http2ServerResponse;
export declare function sendBody(res: NodeHttpResponse | http2.Http2Stream, body: Buffer | object | string | null): void;
export declare function sendBody(res: NodeHttpResponse | http2.Http2Stream, body: Buffer | Record<string, any> | string | null): void;
/**

@@ -19,0 +19,0 @@ * The HttpCallback is the function that is passed as a request listener to

@@ -17,3 +17,2 @@ "use strict";

if (body === null) {
// @ts-ignore - not sure why this line fails
res.end();

@@ -23,15 +22,15 @@ return;

else if (typeof body === 'string') {
// @ts-ignore - not sure why this line fails
// @ts-expect-error - not sure why this line fails
res.end(body);
}
else if (body instanceof Buffer) {
// @ts-ignore - not sure why this line fails
// @ts-expect-error - not sure why this line fails
res.end(body);
}
else if (body instanceof stream_1.default) {
// @ts-ignore - not sure why this line fails
// @ts-expect-error - not sure why this line fails
body.pipe(res);
}
else if (typeof body === 'object') {
// @ts-ignore - not sure why this line fails
// @ts-expect-error - not sure why this line fails
res.end(JSON.stringify(body));

@@ -38,0 +37,0 @@ }

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

this.inner = inner;
// @ts-ignore ignoring that headers might be undefined
// @ts-expect-error ignoring that headers might be undefined
this.headers = new headers_1.Headers(this.inner.headers);

@@ -17,0 +17,0 @@ }

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

getAll() {
// @ts-ignore typescript doesn't like that the getHeaders function can
// @ts-expect-error typescript doesn't like that the getHeaders function can
// have undefined values, so we're just ignoring that problem.

@@ -63,0 +63,0 @@ return this.inner.getHeaders();

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

this.inner = inner;
// @ts-ignore: Typescript doesn't like null here because it might be
// @ts-expect-error: Typescript doesn't like null here because it might be
// incompatible with T, but we're ignoring it as it's a good default.

@@ -101,3 +101,3 @@ this.body = null;

}
// @ts-ignore
// @ts-expect-error let's ignore this
const writeRaw = util_1.promisify(this.inner._writeRaw.bind(this.inner));

@@ -104,0 +104,0 @@ const message = `HTTP/1.1 ${status} ${http_1.default.STATUS_CODES[status]}\r\n${rawHeaders.join('')}\r\n`;

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

@@ -43,4 +43,6 @@ "main": "dist/index.js",

"@types/sinon": "^9.0.4",
"@types/ws": "^7.2.6",
"@typescript-eslint/eslint-plugin": "^3.6.1",
"@typescript-eslint/parser": "^3.6.1",
"chai": "^4.2.0",
"eslint": "^7.4.0",
"mocha": "^8.0.1",

@@ -51,3 +53,2 @@ "node-fetch": "^2.6.0",

"ts-node": "^8.10.2",
"tslint": "^6.1.2",
"typescript": "^3.9.6"

@@ -63,2 +64,3 @@ },

"@curveball/http-errors": "^0.3.0",
"@types/ws": "^7.2.6",
"accepts": "^1.3.7",

@@ -65,0 +67,0 @@ "raw-body": "^2.4.1",

@@ -14,2 +14,3 @@ Curveball

* Native support for HTTP/2, including easy access to HTTP/2 Push.
* Native, deeply integrated Websocket.
* Native support for modern HTTP features, such as [`103 Early Hints`][http-103].

@@ -58,3 +59,3 @@ * The ability to easily do internal sub-requests without having to do a real

* [Body Parser](https://github.com/curveball/bodyparser).
* [Controller](https://github.com/curveball/controller).
* [Controller][controller].
* [Access Logs](https://github.com/curveball/accesslog).

@@ -201,2 +202,45 @@ * [Sessions](https://github.com/curveball/session).

Websocket
---------
To get Websocket up and running, just run:
```typescript
app.listenWs(port);
```
This will start a websocket server on the specified port. Any incoming
Websocket connections will now *just work*.
If a Websocket connection was started, the `Context` object will now have a
`webSocket` property. This property is simply an instance of [Websocket][ws]
from the [ws][ws] NPM package.
Example usage:
```typescript
import { UpgradeRequired } from '@curveball/http-errors';
app.use( ctx => {
if (!ctx.webSocket) {
throw new UpgradeRequired('This endpoint only supports WebSocket');
}
ctx.webSocket.send('Hello');
ctx.webSocket.on('message', (msg) => {
console.log('Received %s', msg);
});
});
```
If you use typescript, install the `@types/ws` package to get all the correct
typings:
npm i -D @types/ws
The [Controller][controller] package also has built-in features to make this
even easier.
API

@@ -216,2 +260,3 @@ ---

* `listen(port: number)` - Run a HTTP server on the specified port.
* `listenWs(port: number)` - Start a websocket server on the specified port.
* `callback()` - The result of this function can be used as a requestListener

@@ -338,1 +383,3 @@ for node.js `http`, `https` and `http2` packages.

[http-103]: https://tools.ietf.org/html/rfc8297 "RFC8297: 103 Early Hints"
[ws]: https://github.com/websockets/ws
[controller]: https://github.com/curveball/controller

@@ -23,2 +23,3 @@ import { isHttpError } from '@curveball/http-errors';

// eslint-disable-next-line @typescript-eslint/no-var-requires
const pkg = require('../package.json');

@@ -141,7 +142,5 @@

await this.handle(ctx);
// @ts-ignore - not sure why this line fails
sendBody(res, ctx.response.body);
} catch (err) {
// tslint:disable:no-console
// eslint-disable-next-line no-console
console.error(err);

@@ -156,3 +155,3 @@

res.end(
// @ts-ignore
// @ts-expect-error string error let's ignore
'Uncaught exception. No middleware was defined to handle it. We got the following HTTP status: ' +

@@ -214,3 +213,3 @@ res.statusCode

} catch (err) {
// tslint:disable:no-console
// eslint-disable-next-line no-console
console.error(err);

@@ -217,0 +216,0 @@ if (this.listenerCount('error')) {

@@ -27,3 +27,3 @@ import { Readable } from 'stream';

this.originalBody = body;
// @ts-ignore: Typescript doesn't like null here because it might be
// @ts-expect-error Typescript doesn't like null here because it might be
// incompatible with T, but we're ignoring it as it's a good default.

@@ -39,3 +39,3 @@ this.body = null;

*/
private originalBody: Buffer|string|object|null;
private originalBody: Buffer|string|Record<string, any>|null;

@@ -42,0 +42,0 @@ /**

@@ -11,4 +11,2 @@ import { Headers } from './headers';

this.status = 200;
// @ts-ignore: Typescript doesn't like null here because it might be
// incompatible with T, but we're ignoring it as it's a good default.
this.body = null;

@@ -15,0 +13,0 @@

@@ -24,19 +24,18 @@ import http from 'http';

export function sendBody(res: NodeHttpResponse | http2.Http2Stream, body: Buffer | object | string | null) {
export function sendBody(res: NodeHttpResponse | http2.Http2Stream, body: Buffer | Record<string, any> | string | null) {
if (body === null) {
// @ts-ignore - not sure why this line fails
res.end();
return;
} else if (typeof body === 'string') {
// @ts-ignore - not sure why this line fails
// @ts-expect-error - not sure why this line fails
res.end(body);
} else if (body instanceof Buffer) {
// @ts-ignore - not sure why this line fails
// @ts-expect-error - not sure why this line fails
res.end(body);
} else if (body instanceof Readable) {
// @ts-ignore - not sure why this line fails
// @ts-expect-error - not sure why this line fails
body.pipe(res);
} else if (typeof body === 'object') {
// @ts-ignore - not sure why this line fails
// @ts-expect-error - not sure why this line fails
res.end(JSON.stringify(body));

@@ -43,0 +42,0 @@ } else {

import rawBody from 'raw-body';
import { Readable } from 'stream';
import { Headers, HeadersInterface } from '../headers';
import { Headers } from '../headers';
import Request from '../request';

@@ -18,3 +18,3 @@ import { NodeHttpRequest } from './http-utils';

this.inner = inner;
// @ts-ignore ignoring that headers might be undefined
// @ts-expect-error ignoring that headers might be undefined
this.headers = new Headers(this.inner.headers);

@@ -21,0 +21,0 @@

@@ -77,3 +77,3 @@ import { HeadersInterface, HeadersObject } from '../headers';

// @ts-ignore typescript doesn't like that the getHeaders function can
// @ts-expect-error typescript doesn't like that the getHeaders function can
// have undefined values, so we're just ignoring that problem.

@@ -80,0 +80,0 @@ return this.inner.getHeaders();

@@ -25,3 +25,3 @@ import http from 'http';

// @ts-ignore: Typescript doesn't like null here because it might be
// @ts-expect-error: Typescript doesn't like null here because it might be
// incompatible with T, but we're ignoring it as it's a good default.

@@ -124,3 +124,3 @@ this.body = null;

// @ts-ignore
// @ts-expect-error let's ignore this
const writeRaw = promisify(this.inner._writeRaw.bind(this.inner));

@@ -127,0 +127,0 @@ const message = `HTTP/1.1 ${status} ${http.STATUS_CODES[status]}\r\n${rawHeaders.join('')}\r\n`;

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

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