@bodar/totallylazy
Advanced tools
Comparing version 0.145.29 to 0.146.30
85
bin.js
@@ -11,4 +11,26 @@ "use strict"; | ||
BinHandler.prototype.handle = function (request) { | ||
return pattern_1.match(request, pattern_1.case_(_1.get('/get'), this.get), pattern_1.case_(_1.post('/post'), this.post), pattern_1.case_({ method: 'GET', uri: pattern_1.regex(/\/stream-bytes\/(\d+)/) }, this.streamBytes), pattern_1.default_(this.notFound)); | ||
return pattern_1.match(request, pattern_1.case_(_1.get('/get'), this.get.bind(this)), pattern_1.case_(_1.post('/post'), this.post.bind(this)), pattern_1.case_(_1.put('/put'), this.put.bind(this)), pattern_1.case_(_1.patch('/patch'), this.patch.bind(this)), pattern_1.case_(_1.delete_('/delete'), this.delete_.bind(this)), pattern_1.case_({ method: 'GET', uri: pattern_1.regex(/\/stream-bytes\/(\d+)/) }, this.streamBytes), pattern_1.default_(this.notFound)); | ||
}; | ||
BinHandler.prototype.responseBody = function (_a) { | ||
var headers = _a.headers, body = _a.body; | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var data, _b; | ||
return tslib_1.__generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
if (!_1.isBody(body)) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, body.text()]; | ||
case 1: | ||
_b = _c.sent(); | ||
return [3 /*break*/, 3]; | ||
case 2: | ||
_b = ""; | ||
_c.label = 3; | ||
case 3: | ||
data = _b; | ||
return [2 /*return*/, JSON.stringify({ data: data, headers: headers })]; | ||
} | ||
}); | ||
}); | ||
}; | ||
BinHandler.prototype.get = function (request) { | ||
@@ -21,15 +43,12 @@ return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
}; | ||
BinHandler.prototype.post = function (_a) { | ||
var body = _a.body; | ||
BinHandler.prototype.post = function (request) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var data; | ||
return tslib_1.__generator(this, function (_b) { | ||
switch (_b.label) { | ||
var _a, _b; | ||
return tslib_1.__generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
if (!_1.isBody(body)) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, body.text()]; | ||
case 1: | ||
data = _b.sent(); | ||
return [2 /*return*/, _1.ok({}, JSON.stringify({ data: data }))]; | ||
case 2: return [2 /*return*/, _1.ok()]; | ||
_a = _1.ok; | ||
_b = [{}]; | ||
return [4 /*yield*/, this.responseBody(request)]; | ||
case 1: return [2 /*return*/, _a.apply(void 0, _b.concat([_c.sent()]))]; | ||
} | ||
@@ -39,2 +58,44 @@ }); | ||
}; | ||
BinHandler.prototype.put = function (request) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var _a, _b; | ||
return tslib_1.__generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
_a = _1.ok; | ||
_b = [{}]; | ||
return [4 /*yield*/, this.responseBody(request)]; | ||
case 1: return [2 /*return*/, _a.apply(void 0, _b.concat([_c.sent()]))]; | ||
} | ||
}); | ||
}); | ||
}; | ||
BinHandler.prototype.patch = function (request) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var _a, _b; | ||
return tslib_1.__generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
_a = _1.ok; | ||
_b = [{}]; | ||
return [4 /*yield*/, this.responseBody(request)]; | ||
case 1: return [2 /*return*/, _a.apply(void 0, _b.concat([_c.sent()]))]; | ||
} | ||
}); | ||
}); | ||
}; | ||
BinHandler.prototype.delete_ = function (request) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var _a, _b; | ||
return tslib_1.__generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
_a = _1.ok; | ||
_b = [{}]; | ||
return [4 /*yield*/, this.responseBody(request)]; | ||
case 1: return [2 /*return*/, _a.apply(void 0, _b.concat([_c.sent()]))]; | ||
} | ||
}); | ||
}); | ||
}; | ||
BinHandler.prototype.streamBytes = function (_a) { | ||
@@ -41,0 +102,0 @@ var _b = tslib_1.__read(_a.uri, 1), size = _b[0]; |
36
bin.ts
@@ -1,2 +0,2 @@ | ||
import {Body, Chunk, get, Handler, isBody, notFound, ok, post, Request, Response} from "."; | ||
import {Body, Chunk, delete_, get, Handler, isBody, notFound, ok, patch, post, put, Request, Response} from "."; | ||
import {match, case_, default_, Matched, regex} from "../pattern"; | ||
@@ -8,4 +8,7 @@ import {repeat} from "../sequence"; | ||
return match(request, | ||
case_(get('/get'), this.get), | ||
case_(post('/post'), this.post), | ||
case_(get('/get'), this.get.bind(this)), | ||
case_(post('/post'), this.post.bind(this)), | ||
case_(put('/put'), this.put.bind(this)), | ||
case_(patch('/patch'), this.patch.bind(this)), | ||
case_(delete_('/delete'), this.delete_.bind(this)), | ||
case_({method: 'GET', uri: regex(/\/stream-bytes\/(\d+)/)}, this.streamBytes), | ||
@@ -15,2 +18,7 @@ default_(this.notFound)); | ||
async responseBody({headers, body}: Matched<Request>): Promise<string> { | ||
const data = isBody(body) ? await body.text() : ""; | ||
return JSON.stringify({data, headers}); | ||
} | ||
async get(request: Matched<Request>) { | ||
@@ -20,10 +28,18 @@ return ok(); | ||
async post({body}: Matched<Request>) { | ||
if (isBody(body)) { | ||
const data = await body.text(); | ||
return ok({}, JSON.stringify({data})); | ||
} | ||
return ok(); | ||
async post(request: Matched<Request>) { | ||
return ok({}, await this.responseBody(request)); | ||
} | ||
async put(request: Matched<Request>) { | ||
return ok({}, await this.responseBody(request)); | ||
} | ||
async patch(request: Matched<Request>) { | ||
return ok({}, await this.responseBody(request)); | ||
} | ||
async delete_(request: Matched<Request>) { | ||
return ok({}, await this.responseBody(request)); | ||
} | ||
async streamBytes({uri: [size]}: Matched<Request>) { | ||
@@ -66,5 +82,5 @@ return ok({}, new ByteBody(randomBytes(size))); | ||
async * [Symbol.asyncIterator](): AsyncIterator<Chunk> { | ||
async* [Symbol.asyncIterator](): AsyncIterator<Chunk> { | ||
yield new ByteChunk(this.value); | ||
} | ||
} |
@@ -68,2 +68,61 @@ "use strict"; | ||
}); | ||
it("supports PUT", function () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var body, response, text; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
body = "Hello"; | ||
return [4 /*yield*/, this.handler.handle(_1.put('/put', { 'Content-Length': String(body.length) }, body))]; | ||
case 1: | ||
response = _a.sent(); | ||
chai_1.assert.equal(response.status, 200); | ||
return [4 /*yield*/, response.body.text()]; | ||
case 2: | ||
text = _a.sent(); | ||
chai_1.assert.equal(JSON.parse(text).data, body); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}); | ||
it("supports PATCH", function () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var body, response, text; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
body = "Hello"; | ||
return [4 /*yield*/, this.handler.handle(_1.patch('/patch', { 'Content-Length': String(body.length) }, body))]; | ||
case 1: | ||
response = _a.sent(); | ||
chai_1.assert.equal(response.status, 200); | ||
return [4 /*yield*/, response.body.text()]; | ||
case 2: | ||
text = _a.sent(); | ||
chai_1.assert.equal(JSON.parse(text).data, body); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}); | ||
it("supports DELETE", function () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var response, json, _a, _b; | ||
return tslib_1.__generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: return [4 /*yield*/, this.handler.handle(_1.delete_('/delete', { Accept: "application/json" }))]; | ||
case 1: | ||
response = _c.sent(); | ||
chai_1.assert.equal(response.status, 200); | ||
_b = (_a = JSON).parse; | ||
return [4 /*yield*/, response.body.text()]; | ||
case 2: | ||
json = _b.apply(_a, [_c.sent()]); | ||
chai_1.assert.equal(json.headers.Accept, "application/json"); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}); | ||
it("supports chunked encoding", function () { | ||
@@ -70,0 +129,0 @@ return tslib_1.__awaiter(this, void 0, void 0, function () { |
import {assert} from 'chai'; | ||
import {get, Handler, HostHandler, post} from "."; | ||
import {delete_, get, Handler, HostHandler, patch, post, put} from "."; | ||
@@ -20,10 +20,36 @@ export function handlerContract(factory: () => Promise<Handler>, host = Promise.resolve("eu.httpbin.org")) { | ||
it("supports POST", async function () { | ||
let body = "Hello"; | ||
const body = "Hello"; | ||
const response = await this.handler.handle(post('/post', {'Content-Length': String(body.length)}, body)); | ||
assert.equal(response.status, 200); | ||
let text = await response.body.text(); | ||
const text = await response.body.text(); | ||
assert.equal(JSON.parse(text).data, body); | ||
}); | ||
it("supports PUT", async function () { | ||
const body = "Hello"; | ||
const response = await this.handler.handle(put('/put', {'Content-Length': String(body.length)}, body)); | ||
assert.equal(response.status, 200); | ||
const text = await response.body.text(); | ||
assert.equal(JSON.parse(text).data, body); | ||
}); | ||
it("supports PATCH", async function () { | ||
const body = "Hello"; | ||
const response = await this.handler.handle(patch('/patch', {'Content-Length': String(body.length)}, body)); | ||
assert.equal(response.status, 200); | ||
const text = await response.body.text(); | ||
assert.equal(JSON.parse(text).data, body); | ||
}); | ||
it("supports DELETE", async function () { | ||
const response = await this.handler.handle(delete_('/delete', {Accept: "application/json"})); | ||
assert.equal(response.status, 200); | ||
const json = JSON.parse(await response.body.text()); | ||
assert.equal(json.headers.Accept, "application/json"); | ||
}); | ||
it("supports chunked encoding", async function () { | ||
@@ -30,0 +56,0 @@ const response = await this.handler.handle(get('/stream-bytes/10')); |
@@ -11,4 +11,26 @@ "use strict"; | ||
BinHandler.prototype.handle = function (request) { | ||
return pattern_1.match(request, pattern_1.case_(_1.get('/get'), this.get), pattern_1.case_(_1.post('/post'), this.post), pattern_1.case_({ method: 'GET', uri: pattern_1.regex(/\/stream-bytes\/(\d+)/) }, this.streamBytes), pattern_1.default_(this.notFound)); | ||
return pattern_1.match(request, pattern_1.case_(_1.get('/get'), this.get.bind(this)), pattern_1.case_(_1.post('/post'), this.post.bind(this)), pattern_1.case_(_1.put('/put'), this.put.bind(this)), pattern_1.case_(_1.patch('/patch'), this.patch.bind(this)), pattern_1.case_(_1.delete_('/delete'), this.delete_.bind(this)), pattern_1.case_({ method: 'GET', uri: pattern_1.regex(/\/stream-bytes\/(\d+)/) }, this.streamBytes), pattern_1.default_(this.notFound)); | ||
}; | ||
BinHandler.prototype.responseBody = function (_a) { | ||
var headers = _a.headers, body = _a.body; | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var data, _b; | ||
return tslib_1.__generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
if (!_1.isBody(body)) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, body.text()]; | ||
case 1: | ||
_b = _c.sent(); | ||
return [3 /*break*/, 3]; | ||
case 2: | ||
_b = ""; | ||
_c.label = 3; | ||
case 3: | ||
data = _b; | ||
return [2 /*return*/, JSON.stringify({ data: data, headers: headers })]; | ||
} | ||
}); | ||
}); | ||
}; | ||
BinHandler.prototype.get = function (request) { | ||
@@ -21,15 +43,12 @@ return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
}; | ||
BinHandler.prototype.post = function (_a) { | ||
var body = _a.body; | ||
BinHandler.prototype.post = function (request) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var data; | ||
return tslib_1.__generator(this, function (_b) { | ||
switch (_b.label) { | ||
var _a, _b; | ||
return tslib_1.__generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
if (!_1.isBody(body)) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, body.text()]; | ||
case 1: | ||
data = _b.sent(); | ||
return [2 /*return*/, _1.ok({}, JSON.stringify({ data: data }))]; | ||
case 2: return [2 /*return*/, _1.ok()]; | ||
_a = _1.ok; | ||
_b = [{}]; | ||
return [4 /*yield*/, this.responseBody(request)]; | ||
case 1: return [2 /*return*/, _a.apply(void 0, _b.concat([_c.sent()]))]; | ||
} | ||
@@ -39,2 +58,44 @@ }); | ||
}; | ||
BinHandler.prototype.put = function (request) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var _a, _b; | ||
return tslib_1.__generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
_a = _1.ok; | ||
_b = [{}]; | ||
return [4 /*yield*/, this.responseBody(request)]; | ||
case 1: return [2 /*return*/, _a.apply(void 0, _b.concat([_c.sent()]))]; | ||
} | ||
}); | ||
}); | ||
}; | ||
BinHandler.prototype.patch = function (request) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var _a, _b; | ||
return tslib_1.__generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
_a = _1.ok; | ||
_b = [{}]; | ||
return [4 /*yield*/, this.responseBody(request)]; | ||
case 1: return [2 /*return*/, _a.apply(void 0, _b.concat([_c.sent()]))]; | ||
} | ||
}); | ||
}); | ||
}; | ||
BinHandler.prototype.delete_ = function (request) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var _a, _b; | ||
return tslib_1.__generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
_a = _1.ok; | ||
_b = [{}]; | ||
return [4 /*yield*/, this.responseBody(request)]; | ||
case 1: return [2 /*return*/, _a.apply(void 0, _b.concat([_c.sent()]))]; | ||
} | ||
}); | ||
}); | ||
}; | ||
BinHandler.prototype.streamBytes = function (_a) { | ||
@@ -41,0 +102,0 @@ var _b = tslib_1.__read(_a.uri, 1), size = _b[0]; |
@@ -1,2 +0,2 @@ | ||
import {Body, Chunk, get, Handler, isBody, notFound, ok, post, Request, Response} from "."; | ||
import {Body, Chunk, delete_, get, Handler, isBody, notFound, ok, patch, post, put, Request, Response} from "."; | ||
import {match, case_, default_, Matched, regex} from "../pattern"; | ||
@@ -8,4 +8,7 @@ import {repeat} from "../sequence"; | ||
return match(request, | ||
case_(get('/get'), this.get), | ||
case_(post('/post'), this.post), | ||
case_(get('/get'), this.get.bind(this)), | ||
case_(post('/post'), this.post.bind(this)), | ||
case_(put('/put'), this.put.bind(this)), | ||
case_(patch('/patch'), this.patch.bind(this)), | ||
case_(delete_('/delete'), this.delete_.bind(this)), | ||
case_({method: 'GET', uri: regex(/\/stream-bytes\/(\d+)/)}, this.streamBytes), | ||
@@ -15,2 +18,7 @@ default_(this.notFound)); | ||
async responseBody({headers, body}: Matched<Request>): Promise<string> { | ||
const data = isBody(body) ? await body.text() : ""; | ||
return JSON.stringify({data, headers}); | ||
} | ||
async get(request: Matched<Request>) { | ||
@@ -20,10 +28,18 @@ return ok(); | ||
async post({body}: Matched<Request>) { | ||
if (isBody(body)) { | ||
const data = await body.text(); | ||
return ok({}, JSON.stringify({data})); | ||
} | ||
return ok(); | ||
async post(request: Matched<Request>) { | ||
return ok({}, await this.responseBody(request)); | ||
} | ||
async put(request: Matched<Request>) { | ||
return ok({}, await this.responseBody(request)); | ||
} | ||
async patch(request: Matched<Request>) { | ||
return ok({}, await this.responseBody(request)); | ||
} | ||
async delete_(request: Matched<Request>) { | ||
return ok({}, await this.responseBody(request)); | ||
} | ||
async streamBytes({uri: [size]}: Matched<Request>) { | ||
@@ -66,5 +82,5 @@ return ok({}, new ByteBody(randomBytes(size))); | ||
async * [Symbol.asyncIterator](): AsyncIterator<Chunk> { | ||
async* [Symbol.asyncIterator](): AsyncIterator<Chunk> { | ||
yield new ByteChunk(this.value); | ||
} | ||
} |
@@ -68,2 +68,61 @@ "use strict"; | ||
}); | ||
it("supports PUT", function () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var body, response, text; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
body = "Hello"; | ||
return [4 /*yield*/, this.handler.handle(_1.put('/put', { 'Content-Length': String(body.length) }, body))]; | ||
case 1: | ||
response = _a.sent(); | ||
chai_1.assert.equal(response.status, 200); | ||
return [4 /*yield*/, response.body.text()]; | ||
case 2: | ||
text = _a.sent(); | ||
chai_1.assert.equal(JSON.parse(text).data, body); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}); | ||
it("supports PATCH", function () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var body, response, text; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
body = "Hello"; | ||
return [4 /*yield*/, this.handler.handle(_1.patch('/patch', { 'Content-Length': String(body.length) }, body))]; | ||
case 1: | ||
response = _a.sent(); | ||
chai_1.assert.equal(response.status, 200); | ||
return [4 /*yield*/, response.body.text()]; | ||
case 2: | ||
text = _a.sent(); | ||
chai_1.assert.equal(JSON.parse(text).data, body); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}); | ||
it("supports DELETE", function () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var response, json, _a, _b; | ||
return tslib_1.__generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: return [4 /*yield*/, this.handler.handle(_1.delete_('/delete', { Accept: "application/json" }))]; | ||
case 1: | ||
response = _c.sent(); | ||
chai_1.assert.equal(response.status, 200); | ||
_b = (_a = JSON).parse; | ||
return [4 /*yield*/, response.body.text()]; | ||
case 2: | ||
json = _b.apply(_a, [_c.sent()]); | ||
chai_1.assert.equal(json.headers.Accept, "application/json"); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}); | ||
it("supports chunked encoding", function () { | ||
@@ -70,0 +129,0 @@ return tslib_1.__awaiter(this, void 0, void 0, function () { |
import {assert} from 'chai'; | ||
import {get, Handler, HostHandler, post} from "."; | ||
import {delete_, get, Handler, HostHandler, patch, post, put} from "."; | ||
@@ -20,10 +20,36 @@ export function handlerContract(factory: () => Promise<Handler>, host = Promise.resolve("eu.httpbin.org")) { | ||
it("supports POST", async function () { | ||
let body = "Hello"; | ||
const body = "Hello"; | ||
const response = await this.handler.handle(post('/post', {'Content-Length': String(body.length)}, body)); | ||
assert.equal(response.status, 200); | ||
let text = await response.body.text(); | ||
const text = await response.body.text(); | ||
assert.equal(JSON.parse(text).data, body); | ||
}); | ||
it("supports PUT", async function () { | ||
const body = "Hello"; | ||
const response = await this.handler.handle(put('/put', {'Content-Length': String(body.length)}, body)); | ||
assert.equal(response.status, 200); | ||
const text = await response.body.text(); | ||
assert.equal(JSON.parse(text).data, body); | ||
}); | ||
it("supports PATCH", async function () { | ||
const body = "Hello"; | ||
const response = await this.handler.handle(patch('/patch', {'Content-Length': String(body.length)}, body)); | ||
assert.equal(response.status, 200); | ||
const text = await response.body.text(); | ||
assert.equal(JSON.parse(text).data, body); | ||
}); | ||
it("supports DELETE", async function () { | ||
const response = await this.handler.handle(delete_('/delete', {Accept: "application/json"})); | ||
assert.equal(response.status, 200); | ||
const json = JSON.parse(await response.body.text()); | ||
assert.equal(json.headers.Accept, "application/json"); | ||
}); | ||
it("supports chunked encoding", async function () { | ||
@@ -30,0 +56,0 @@ const response = await this.handler.handle(get('/stream-bytes/10')); |
@@ -57,2 +57,14 @@ "use strict"; | ||
exports.post = post; | ||
function put(uri, headers, body) { | ||
return request("PUT", uri, headers, body); | ||
} | ||
exports.put = put; | ||
function patch(uri, headers, body) { | ||
return request("PATCH", uri, headers, body); | ||
} | ||
exports.patch = patch; | ||
function delete_(uri, headers) { | ||
return request("DELETE", uri, headers); | ||
} | ||
exports.delete_ = delete_; | ||
function response(status, headers, body) { | ||
@@ -59,0 +71,0 @@ return { status: status, headers: headers || {}, body: typeof body == 'string' ? new StringBody(body) : body }; |
@@ -98,2 +98,14 @@ if (typeof Symbol.asyncIterator == 'undefined') { | ||
export function put(uri: Uri | string, headers?: Headers, body?: string | Body): Request { | ||
return request("PUT", uri, headers, body); | ||
} | ||
export function patch(uri: Uri | string, headers?: Headers, body?: string | Body): Request { | ||
return request("PATCH", uri, headers, body); | ||
} | ||
export function delete_(uri: Uri | string, headers?: Headers): Request { | ||
return request("DELETE", uri, headers); | ||
} | ||
export interface Response extends Message { | ||
@@ -100,0 +112,0 @@ readonly status: number, |
@@ -41,4 +41,11 @@ "use strict"; | ||
exports.ClientHandler = ClientHandler; | ||
function headers(rawHeaders) { | ||
if (rawHeaders.length == 0) | ||
return {}; | ||
var _a = tslib_1.__read(rawHeaders), name = _a[0], value = _a[1], remainder = _a.slice(2); | ||
return tslib_1.__assign((_b = {}, _b[name] = value, _b), headers(remainder)); | ||
var _b; | ||
} | ||
exports.adapter = function (handler) { return function (nodeRequest, nodeResponse) { | ||
var req = _1.request(nodeRequest.method || "", nodeRequest.url || "", nodeRequest.headers, new MessageBody(nodeRequest)); | ||
var req = _1.request(nodeRequest.method || "", nodeRequest.url || "", headers(nodeRequest.rawHeaders), new MessageBody(nodeRequest)); | ||
(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
@@ -45,0 +52,0 @@ var response, h, name_1, value, text, e_1, _a, _b, value, e_2_1, e_2, _c; |
@@ -36,6 +36,12 @@ import {Body, Chunk, Handler, Header, Headers, host, isBody, Request, request, Response, Server, Uri} from "."; | ||
function headers(rawHeaders: string[]):Headers { | ||
if(rawHeaders.length == 0) return {}; | ||
const [name, value, ...remainder] = rawHeaders; | ||
return {[name]:value, ...headers(remainder)}; | ||
} | ||
export const adapter = (handler:Handler) => (nodeRequest: IncomingMessage, nodeResponse: ServerResponse) => { | ||
let req = request(nodeRequest.method || "", | ||
const req = request(nodeRequest.method || "", | ||
nodeRequest.url || "", | ||
nodeRequest.headers as Headers, | ||
headers(nodeRequest.rawHeaders), | ||
new MessageBody(nodeRequest)); | ||
@@ -46,3 +52,3 @@ | ||
nodeResponse.statusCode = response.status; | ||
for (let h in response.headers) { | ||
for (const h in response.headers) { | ||
const name = h as Header; | ||
@@ -49,0 +55,0 @@ const value = response.headers[name]; |
12
index.js
@@ -57,2 +57,14 @@ "use strict"; | ||
exports.post = post; | ||
function put(uri, headers, body) { | ||
return request("PUT", uri, headers, body); | ||
} | ||
exports.put = put; | ||
function patch(uri, headers, body) { | ||
return request("PATCH", uri, headers, body); | ||
} | ||
exports.patch = patch; | ||
function delete_(uri, headers) { | ||
return request("DELETE", uri, headers); | ||
} | ||
exports.delete_ = delete_; | ||
function response(status, headers, body) { | ||
@@ -59,0 +71,0 @@ return { status: status, headers: headers || {}, body: typeof body == 'string' ? new StringBody(body) : body }; |
12
index.ts
@@ -98,2 +98,14 @@ if (typeof Symbol.asyncIterator == 'undefined') { | ||
export function put(uri: Uri | string, headers?: Headers, body?: string | Body): Request { | ||
return request("PUT", uri, headers, body); | ||
} | ||
export function patch(uri: Uri | string, headers?: Headers, body?: string | Body): Request { | ||
return request("PATCH", uri, headers, body); | ||
} | ||
export function delete_(uri: Uri | string, headers?: Headers): Request { | ||
return request("DELETE", uri, headers); | ||
} | ||
export interface Response extends Message { | ||
@@ -100,0 +112,0 @@ readonly status: number, |
@@ -1,1 +0,1 @@ | ||
{"name":"@bodar/totallylazy","version":"0.145.29","description":"Totallylazy","repository":"git@github.com:bodar/totallylazy.js.git","author":"Daniel Worthington-Bodart <dan@bodar.com>","license":"Apache-2.0","private":false,"scripts":{"build":"ts-node build.ts"},"dependencies":{"@types/node":"^9.4.6","@types/text-encoding":"^0.0.32"},"devDependencies":{"@types/chai":"^4.1.2","@types/mocha":"^2.2.48","@types/puppeteer":"^1.3.2","chai":"^4.1.2","fuse-box":"^3.1.3","mocha":"^5.0.0","mocha-headless-chrome":"^1.8.2","ts-node":"^4.1.0","typescript":"^2.7.2","uglify-es":"^3.3.10","uglify-js":"^3.3.10"},"optionalDependencies":{"http-shutdown":"^1.2.0","text-encoding":"^0.6.4"}} | ||
{"name":"@bodar/totallylazy","version":"0.146.30","description":"Totallylazy","repository":"git@github.com:bodar/totallylazy.js.git","author":"Daniel Worthington-Bodart <dan@bodar.com>","license":"Apache-2.0","private":false,"scripts":{"build":"ts-node build.ts"},"dependencies":{"@types/node":"^9.4.6","@types/text-encoding":"^0.0.32"},"devDependencies":{"@types/chai":"^4.1.2","@types/mocha":"^2.2.48","@types/puppeteer":"^1.3.2","chai":"^4.1.2","fuse-box":"^3.1.3","mocha":"^5.0.0","mocha-headless-chrome":"^1.8.2","ts-node":"^4.1.0","typescript":"^2.7.2","uglify-es":"^3.3.10","uglify-js":"^3.3.10"},"optionalDependencies":{"http-shutdown":"^1.2.0","text-encoding":"^0.6.4"}} |
@@ -23,3 +23,3 @@ export function match<T, R>(instance: T, ...matchers: Matcher<T, R>[]): R { | ||
export class CaseMatcher<T, R> implements Matcher<T, R> { | ||
constructor(private pattern: Pattern<T>, private handler: (instance: Matched<T>) => R) { | ||
constructor(private pattern: Pattern<T>, private handler: (instance: Matched<T>) => R,) { | ||
} | ||
@@ -26,0 +26,0 @@ |
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 too big to display
Sorry, the diff of this file is not supported yet
1817949
27438