Skip to content

Commit

Permalink
Updated JSDoc
Browse files Browse the repository at this point in the history
  • Loading branch information
duart38 committed Aug 17, 2020
1 parent af9f1c1 commit 87fddc3
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 2 deletions.
9 changes: 9 additions & 0 deletions actions/decoding.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { HTTPModelMethod } from '../interfaces/model.ts';

/**
* Get the query parameters attached to a url in a json object
* @param url
*/
export function getUrlParams(url: string): object {
var vars: any = {};
var hashes = url.split('?')[1];
Expand All @@ -13,6 +17,11 @@ export function getUrlParams(url: string): object {
return vars || {};
}

/**
* Helper method that reads the config and determines wether it should convert the body or pass it on as is (unit8array)
* @param config
* @param body
*/
export async function decodeBody(
config: HTTPModelMethod,
body: Deno.Reader
Expand Down
8 changes: 8 additions & 0 deletions actions/loadConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ import { HTTPModelMethod, SOCKETModelMethod } from '../interfaces/model.ts';
import { print } from './logging.ts';
import { Verbosity } from '../enums/verbosity.ts';

/**
* Loads the configuration method of a particular model.
* NOTE: This method does not load the whole models file but only a section of it
* @param model
* @param method
* @param req
* @param connectionType
*/
export async function loadConfiguration(
model: string,
method: string,
Expand Down
20 changes: 19 additions & 1 deletion actions/respond.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { HTTPModelMethod } from '../interfaces/model.ts';
import { ServerRequest } from "https://deno.land/std/http/server.ts";
import { Status } from "https://deno.land/std/http/http_status.ts";import { discardUnknownHeaders } from './filtering.ts';

/**
* Construct headers based on configuration
* @param req
* @param HTTPModelMethod
*/
export function constructHeaders(req: any, HTTPModelMethod: HTTPModelMethod): Headers {
let headers = <Headers>req.headers;
headers.delete('Content-Length');
Expand All @@ -12,7 +18,10 @@ export function constructHeaders(req: any, HTTPModelMethod: HTTPModelMethod): He
});
return headers;
}

/**
* Default headers to handle with requests like OPTIONS
* @param req
*/
export function defaultHeaders(req: any) {
let headers = <Headers>req.headers;
headers.delete('Content-Length');
Expand All @@ -21,6 +30,10 @@ export function defaultHeaders(req: any) {
headers.append('Allow', 'OPTIONS, GET, HEAD, POST, PUT, DELETE');
return headers;
}
/**
* Converts the type Header to an object representation (plays nice with axiod)
* @param headers
*/
export function headersToObject(headers: Headers): object{
let arr: any = {};
headers.forEach((val, key)=>{
Expand All @@ -29,6 +42,11 @@ export function headersToObject(headers: Headers): object{
return arr;
}

/**
* Helper method to respond with an error code.
* @param req
* @param status
*/
export function respondError(req: ServerRequest, status: Status){
req.respond({status})
}
4 changes: 4 additions & 0 deletions components/fileWatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ export class Watcher {
}
}

/**
* Get the observable value attached to this instance.
* @see https://github.com/duart38/Observe
*/
public getObservable(): Observe<string> {
return this.hash;
}
Expand Down
4 changes: 4 additions & 0 deletions components/httpServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ export default class httpServer {
}
}

/**
* The first entry point for an incoming request.
* @param req
*/
private async handleRequest(req: ServerRequest) {

try{
Expand Down
3 changes: 3 additions & 0 deletions enums/connectionTypes.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* Types of connection this server takes
*/
export enum Connection {
HTTP = "HTTP",
SOCKET = "SOCKET",
Expand Down
4 changes: 3 additions & 1 deletion enums/httpTypes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/**
* Types of HTTP method (e.g GET, POST)
*/
export enum HTTP {
GET = "GET",
POST = "POST",
// TODO.
}
4 changes: 4 additions & 0 deletions enums/verbosity.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* Dictates how much is printed to the console. Higher = more.
* WARNING: higher verbosity levels WILL impact performance.
*/
export enum Verbosity {
SILENT, // nothing is printed
LOW, // prints when a request is received and it's method
Expand Down

0 comments on commit 87fddc3

Please sign in to comment.