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

servie

Package Overview
Dependencies
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

servie - npm Package Compare versions

Comparing version 0.1.2 to 0.2.0

8

dist/index.d.ts

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

events: EventEmitter;
private _timeout;
private _body;

@@ -78,4 +77,2 @@ private _bodyUsed;

length: number | undefined;
_setTimeout(cb: () => void, ms: number): void;
clearTimeout(): void;
buffer(maxBufferSize?: number): Promise<Buffer | undefined>;

@@ -119,3 +116,2 @@ stream(): Readable;

abort(): boolean;
setTimeout(ms: number): void;
toJSON(): {

@@ -153,7 +149,5 @@ url: string;

export declare class Response extends Common implements ResponseOptions {
request: Request;
status: number | undefined;
statusText: string | undefined;
constructor(request: Request, options?: ResponseOptions);
setTimeout(ms: number): void;
constructor(options?: ResponseOptions);
toJSON(): {

@@ -160,0 +154,0 @@ status: number;

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

this.events.emit('finished');
this.clearTimeout();
}

@@ -315,10 +314,2 @@ },

});
Common.prototype._setTimeout = function (cb, ms) {
clearTimeout(this._timeout);
this._timeout = setTimeout(cb, ms);
};
Common.prototype.clearTimeout = function () {
clearTimeout(this._timeout);
this._timeout = undefined;
};
Common.prototype.buffer = function (maxBufferSize) {

@@ -468,13 +459,5 @@ if (maxBufferSize === void 0) { maxBufferSize = 1000 * 1000; }

this.events.emit('abort', this.error('Request aborted', 'EABORT', 444));
this.clearTimeout();
}
return abort;
};
Request.prototype.setTimeout = function (ms) {
var _this = this;
return this._setTimeout(function () {
_this.events.emit('error', _this.error('Request timeout', 'ETIMEOUT', 408));
_this.abort();
}, ms);
};
Request.prototype.toJSON = function () {

@@ -503,19 +486,9 @@ return {

__extends(Response, _super);
function Response(request, options) {
function Response(options) {
if (options === void 0) { options = {}; }
var _this = _super.call(this, options) || this;
_this.request = request;
_this.status = options.status;
_this.statusText = options.statusText;
// Emit a response event to listeners.
_this.request.events.emit('response', _this);
return _this;
}
Response.prototype.setTimeout = function (ms) {
var _this = this;
return this._setTimeout(function () {
_this.request.events.emit('error', _this.request.error('Response timeout', 'ETIMEOUT', 408));
_this.request.abort();
}, ms);
};
Response.prototype.toJSON = function () {

@@ -522,0 +495,0 @@ return {

10

dist/index.spec.js

@@ -21,9 +21,7 @@ "use strict";

it('should have a status', function () {
var req = new index_1.Request({ url: '/' });
var res = new index_1.Response(req, { status: 200 });
var res = new index_1.Response({ status: 200 });
expect(res.status).toBe(200);
});
it('should json encode body if a simple object', function () {
var req = new index_1.Request({ url: '/json' });
var res = new index_1.Response(req, { body: { foo: 'bar' } });
var res = new index_1.Response({ body: { foo: 'bar' } });
expect(res.headers.get('Content-Type')).toBe('application/json');

@@ -36,5 +34,5 @@ expect(res.body).toEqual('{\"foo\":\"bar\"}');

var req = new index_1.Request({ url: '/endpoint' });
var res = new index_1.Response(req, { status: 404 });
var res = new index_1.Response({ status: 404 });
var reqClone = new index_1.Request(req);
var resClone = new index_1.Response(res.request, res);
var resClone = new index_1.Response(res);
expect(req).not.toBe(reqClone);

@@ -41,0 +39,0 @@ expect(res).not.toBe(resClone);

{
"name": "servie",
"version": "0.1.2",
"version": "0.2.0",
"description": "Standard HTTP interfaces",

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

@@ -23,2 +23,3 @@ # ![Servie](https://cdn.rawgit.com/blakeembrey/node-servie/master/logo.svg)

* [`consolidate`](https://github.com/tj/consolidate.js) Template rendering
* [`get-body`](https://github.com/blakeembrey/node-get-body) General body parser for forms, JSON and text

@@ -42,7 +43,7 @@ ### `Common`

* `events` The request/response event emitter
* `headers` The submitted headers as a `Headers` instance
* `trailers` The submitted trailers as a `Headers` instance
* `body` The submitted body payload
* `bodyUsed` A boolean indicating where the body was read
* `events` An event emitter for listening to the request and response lifecycles
* `headers` The headers as a `Headers` instance
* `trailers` The trailers as a `Headers` instance
* `body` The request or response payload
* `bodyUsed` A boolean indicating whether the body has been read
* `type` A shorthand property for reading and writing the `Content-Type` header

@@ -59,12 +60,10 @@ * `length` A shorthand property for reading and writing `Content-Length` as a number

* `stream(): Readable` Read the body as a `Readable` stream
* `setTimeout(ms): void` Set a timeout on the request or response to be marked as finished
* `clearTimeout(ms): void` Clear a previous timeout
#### Events
* `headers` Emitted when the `headers` object becomes available
* `trailers` Emitted when the `trailers` object becomes available
* `started` Emitted when the request/response has started
* `finished` Emitted when the request/respone has finished
* `progress` Emitted when the `bytesTransferred` properties is incremented
* `headers` Emitted when the `headers` object is available
* `trailers` Emitted when the `trailers` object is available
* `started` Emitted when `started === true`
* `finished` Emitted when `finished === true`
* `progress` Emitted when `bytesTransferred` is incremented

@@ -109,3 +108,4 @@ ### `Request`

* `abort` Emitted when the request is aborted and MUST be handled by transport
* `error` Emitted when an out-of-band error occurs (e.g. abort or timeout) and MUST be handled by the transport
* `error` Emitted when an out-of-band error occurs (e.g. abort) and MUST be handled by the transport
* `response` Emitted when the response object is being handled

@@ -123,3 +123,3 @@ ### `Response`

```ts
const response = new Response(request, {})
const response = new Response({})
```

@@ -171,2 +171,11 @@

## Implementers
If you're building the transports for Servie, there are some life cycle events you need to be aware of and emit yourself:
1. Listen to the `error` event on `Request` for out-of-band errors and respond accordingly (e.g. app-level logging)
2. Listen to the `abort` event on `Request` to destroy the HTTP request
3. Set `started === true` and `finished === true` on `Request` and `Response`, as appropriate
4. Set `bytesTransferred` on `Request` and `Response` when monitoring HTTP transfer progress
## JavaScript

@@ -173,0 +182,0 @@

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