From 87fddc3784115d171f691ae69aac4c0b32eda2c7 Mon Sep 17 00:00:00 2001 From: duart38 Date: Mon, 17 Aug 2020 14:19:32 +0200 Subject: [PATCH] Updated JSDoc --- actions/decoding.ts | 9 +++++++++ actions/loadConfiguration.ts | 8 ++++++++ actions/respond.ts | 20 +++++++++++++++++++- components/fileWatcher.ts | 4 ++++ components/httpServer.ts | 4 ++++ enums/connectionTypes.ts | 3 +++ enums/httpTypes.ts | 4 +++- enums/verbosity.ts | 4 ++++ 8 files changed, 54 insertions(+), 2 deletions(-) diff --git a/actions/decoding.ts b/actions/decoding.ts index 08dfbeb..3e17830 100644 --- a/actions/decoding.ts +++ b/actions/decoding.ts @@ -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]; @@ -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 diff --git a/actions/loadConfiguration.ts b/actions/loadConfiguration.ts index a662817..847d1fb 100644 --- a/actions/loadConfiguration.ts +++ b/actions/loadConfiguration.ts @@ -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, diff --git a/actions/respond.ts b/actions/respond.ts index 6f6ec9a..113cfdf 100644 --- a/actions/respond.ts +++ b/actions/respond.ts @@ -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 = req.headers; headers.delete('Content-Length'); @@ -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 = req.headers; headers.delete('Content-Length'); @@ -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)=>{ @@ -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}) } \ No newline at end of file diff --git a/components/fileWatcher.ts b/components/fileWatcher.ts index d99e70b..d68ddcc 100644 --- a/components/fileWatcher.ts +++ b/components/fileWatcher.ts @@ -33,6 +33,10 @@ export class Watcher { } } + /** + * Get the observable value attached to this instance. + * @see https://github.com/duart38/Observe + */ public getObservable(): Observe { return this.hash; } diff --git a/components/httpServer.ts b/components/httpServer.ts index 737946b..e501a40 100644 --- a/components/httpServer.ts +++ b/components/httpServer.ts @@ -76,6 +76,10 @@ export default class httpServer { } } + /** + * The first entry point for an incoming request. + * @param req + */ private async handleRequest(req: ServerRequest) { try{ diff --git a/enums/connectionTypes.ts b/enums/connectionTypes.ts index c280f19..ce4a194 100644 --- a/enums/connectionTypes.ts +++ b/enums/connectionTypes.ts @@ -1,3 +1,6 @@ +/** + * Types of connection this server takes + */ export enum Connection { HTTP = "HTTP", SOCKET = "SOCKET", diff --git a/enums/httpTypes.ts b/enums/httpTypes.ts index e10c43b..5f2d2ab 100644 --- a/enums/httpTypes.ts +++ b/enums/httpTypes.ts @@ -1,5 +1,7 @@ +/** + * Types of HTTP method (e.g GET, POST) + */ export enum HTTP { GET = "GET", POST = "POST", - // TODO. } diff --git a/enums/verbosity.ts b/enums/verbosity.ts index d3cde28..7bf40a5 100644 --- a/enums/verbosity.ts +++ b/enums/verbosity.ts @@ -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