-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
85 changed files
with
1,744 additions
and
524 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ lerna-*.log | |
npm-*.log | ||
.DS_Store | ||
tsconfig.tsbuildinfo | ||
test.js |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
4 changes: 2 additions & 2 deletions
4
packages/app/src/Transport/Request/URLEncodedFormTransform.ts
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,8 @@ | ||
import {Promisify} from "@bunt/unit"; | ||
import {assert, ILogable, isFunction} from "@bunt/util"; | ||
import {IHeaders, IRequest, IRequestTransform, RequestTransformType, RouteResponse} from "../interfaces"; | ||
import {fromJsonRequest} from "./Request"; | ||
import {ResponderAbstract} from "./ResponderAbstract"; | ||
|
||
export abstract class RequestAbstract implements IRequest, ILogable<{ route: string }> { | ||
public abstract readonly route: string; | ||
public abstract readonly headers: IHeaders; | ||
/** | ||
* @deprecated see ResponderAbstract | ||
*/ | ||
export abstract class RequestAbstract extends ResponderAbstract { | ||
|
||
#complete = false; | ||
|
||
public get complete(): boolean { | ||
return this.#complete; | ||
} | ||
|
||
public async getBuffer(): Promise<Buffer> { | ||
const chunks: Buffer[] = []; | ||
const readableStream = await this.createReadableStream(); | ||
for await (const chunk of readableStream) { | ||
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk)); | ||
} | ||
|
||
return Buffer.concat(chunks); | ||
} | ||
|
||
public transform<T>(transformer: RequestTransformType<T>): Promise<T> { | ||
if (isFunction(transformer)) { | ||
return transformer(this); | ||
} | ||
|
||
return transformer.transform(this); | ||
} | ||
|
||
public async to<T>(transform: IRequestTransform<T>): Promise<T> { | ||
this.headers.assert("content-type", [transform.type].flat(1)); | ||
return transform(await this.getBuffer()); | ||
} | ||
|
||
public toObject<T = unknown>(): Promise<T> { | ||
return this.to<unknown>(fromJsonRequest) as Promise<T>; | ||
} | ||
|
||
public async respond(response: RouteResponse): Promise<void> { | ||
assert(!this.complete, `Response was already sent`); | ||
try { | ||
await this.write(response); | ||
} finally { | ||
this.#complete = true; | ||
} | ||
} | ||
|
||
public abstract validate(): boolean; | ||
|
||
public abstract createReadableStream(): Promisify<NodeJS.ReadableStream>; | ||
|
||
public getLogValue(): { route: string } { | ||
return {route: this.route}; | ||
} | ||
|
||
protected abstract write(response: RouteResponse): Promise<void>; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import {ILogable, isFunction, Promisify} from "@bunt/util"; | ||
import {Application} from "../Application"; | ||
import {IHeaders, IRequestMessage, IRequestTransform, RequestTransformType} from "../interfaces"; | ||
import {fromJsonRequest} from "./Request"; | ||
|
||
export abstract class RequestMessageAbstract implements IRequestMessage, ILogable<{ route: string }> { | ||
public abstract readonly route: string; | ||
public abstract readonly headers: IHeaders; | ||
|
||
public async getBuffer(): Promise<Buffer> { | ||
const chunks: Buffer[] = []; | ||
const readableStream = await this.createReadableStream(); | ||
for await (const chunk of readableStream) { | ||
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk)); | ||
} | ||
|
||
return Buffer.concat(chunks); | ||
} | ||
|
||
public transform<T>(transformer: RequestTransformType<T>): Promise<T> { | ||
if (isFunction(transformer)) { | ||
return transformer(this); | ||
} | ||
|
||
return transformer.transform(this); | ||
} | ||
|
||
public async to<T>(transform: IRequestTransform<T>): Promise<T> { | ||
this.headers.assert("content-type", [transform.type].flat(1)); | ||
return transform(await this.getBuffer()); | ||
} | ||
|
||
public toObject<T = unknown>(): Promise<T> { | ||
return this.to<unknown>(fromJsonRequest) as Promise<T>; | ||
} | ||
|
||
public abstract validate(app: Application): boolean; | ||
|
||
public abstract createReadableStream(): Promisify<NodeJS.ReadableStream>; | ||
|
||
public getLogValue(): { route: string } { | ||
return {route: this.route}; | ||
} | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import {assert} from "@bunt/util"; | ||
import {IResponder, RouteResponse} from "../interfaces"; | ||
import {RequestMessageAbstract} from "./RequestMessageAbstract"; | ||
|
||
export abstract class ResponderAbstract extends RequestMessageAbstract implements IResponder { | ||
#complete = false; | ||
|
||
public get complete(): boolean { | ||
return this.#complete; | ||
} | ||
|
||
public async respond(response: RouteResponse): Promise<void> { | ||
assert(!this.complete, `Response was already sent`); | ||
try { | ||
await this.write(response); | ||
} finally { | ||
this.#complete = true; | ||
} | ||
} | ||
|
||
protected abstract write(response: RouteResponse): Promise<void>; | ||
} |
This file contains 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
Oops, something went wrong.