This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const parseRequest = (s: string): Request => { | |
const [firstLine, rest] = divideStringOn(s, '\r\n') | |
const [method, url, protocol] = firstLine.split(' ', 3) | |
const [headers, body] = divideStringOn(rest, '\r\n\r\n') | |
const parsedHeaders = headers.split('\r\n').reduce((map, header) => { | |
const [key, value] = divideStringOn(header, ': ') | |
return map.set(key, value) | |
}, new Map()) | |
return { protocol, method, url, headers: parsedHeaders, body } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export interface Request { | |
protocol: string | |
method: string | |
url: string | |
headers: Map<string, string> | |
body: string | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GET / HTTP/1.1 | |
Host: localhost:3000 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl 127.0.0.1:3000 | |
hello world% |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
net.createServer() | |
.listen(PORT, IP, BACKLOG) | |
.on('connection', socket => socket | |
.on('data', buffer => { | |
const request = buffer.toString() | |
socket.write('hello world') | |
socket.end() | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
net.createServer() | |
.listen(PORT, IP, BACKLOG) | |
.on('connection', socket => | |
console.log(`new connection from ${socket.remoteAddress}:${socket.remotePort}` | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as net from 'net' | |
const PORT = 3000 | |
const IP = '127.0.0.1' | |
const BACKLOG = 100 | |
net.createServer() | |
.listen(PORT, IP, BACKLOG) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(b: Fake<Blog>) => b.Id.equals(1).and(b.Title.includes('hello')) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fromArray<Blog>([ | |
{ Id: 1, Title: 'Blog 1' }, | |
{ Id: 2, Title: 'Blog 2' }, | |
{ Id: 3, Title: 'Blog 3' }, | |
]) | |
.where(b => b.Id.equals(1).and(b.Title.includes('hello'))) | |
.toArray() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fromArray = <T extends object>(a: Array<T>): IQueryable<T> => { | |
const exprs: Expr[] = [] | |
const value = [...a] | |
return { | |
where(predicate) { | |
exprs.push(predicate(builder()).GetExpr()) | |
return this | |
}, | |
toArray() { |