-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separate interface and implementation (#13)
* Separate interface and implementation for objects * Remove extra line
- Loading branch information
Showing
7 changed files
with
110 additions
and
65 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 |
---|---|---|
@@ -1,10 +1,6 @@ | ||
// Copyright 2021 Riki Singh Khorana. All rights reserved. MIT license. | ||
|
||
export { Kyuko } from "./kyuko.ts"; | ||
export type { | ||
KyukoMiddleware, | ||
KyukoRequest, | ||
KyukoRequestHandler, | ||
} from "./kyuko.ts"; | ||
|
||
export { KyukoResponse } from "./KyukoResponse.ts"; | ||
export { Kyuko } from "./src/Kyuko.ts"; | ||
export type { KyukoMiddleware, KyukoRequestHandler } from "./src/Kyuko.ts"; | ||
export type { KyukoRequest } from "./src/KyukoRequest.ts"; | ||
export type { KyukoResponse } from "./src/KyukoResponse.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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright 2021 Riki Singh Khorana. All rights reserved. MIT license. | ||
|
||
/// <reference path='./deploy.d.ts' /> | ||
|
||
/** | ||
* The request object that is handled in Kyuko applications. | ||
* Can be extended further for middlewares to populate the original `Request`. | ||
*/ | ||
export interface KyukoRequest extends Request { | ||
/** | ||
* Stores path parameters and their values in an object. | ||
*/ | ||
params: { | ||
[key: string]: string; | ||
}; | ||
|
||
/** | ||
* Stores query parameters and their values. | ||
* Note that a single key may map to multiple different values. | ||
*/ | ||
query: URLSearchParams; | ||
} | ||
|
||
/** | ||
* This class is instantiated when a fetch request is captured by a Kyuko application. | ||
* The instance is populated by the original request handed over from the event listener. | ||
*/ | ||
export class KyukoRequestImpl extends Request implements KyukoRequest { | ||
params: { [key: string]: string }; | ||
query: URLSearchParams; | ||
|
||
/** | ||
* Instantiates a `KyukoRequest` based on the original `fetchEvent` request. | ||
* @param fetchEvent The event that this request originated from. | ||
*/ | ||
constructor(fetchEvent: FetchEvent) { | ||
super(fetchEvent.request); | ||
this.params = {}; | ||
this.query = new URLSearchParams(); | ||
} | ||
} |
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,3 +1,5 @@ | ||
// Copyright 2021 Riki Singh Khorana. All rights reserved. MIT license. | ||
|
||
import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts"; | ||
import { RoutePathHandler } from "./RoutePathHandler.ts"; | ||
|
||
|
File renamed without changes.
File renamed without changes.