Skip to content

Commit

Permalink
docs: added missing jsdocs
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeCheneler committed Feb 14, 2025
1 parent 006c138 commit 8333c28
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 4 deletions.
5 changes: 5 additions & 0 deletions app/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ export class MageContext {
return this._req;
}

/**
* Construct a new MageContext object
*
* @param args The arguments for the MageContext class
*/
public constructor(args: MageContextArgs) {
this._buildId = args.buildId;
this._req = args.req;
Expand Down
13 changes: 10 additions & 3 deletions app/mage-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import type { ClientErrorStatus, ServerErrorStatus } from "../status/mod.ts";
/**
* Error class for Mage errors, throw with a status code for it to be honored by Mage in the response.
*
* @param message - The error message
* @param status - The HTTP status code for the error
* @param options - Additional options for the error
* @param message The error message
* @param status The HTTP status code for the error, this will be honored by Mage in the response
* @param options Additional options for the error
*/
export class MageError extends Error {
private _status: ClientErrorStatus | ServerErrorStatus = 500;
Expand All @@ -17,6 +17,13 @@ export class MageError extends Error {
return this._status;
}

/**
* Construct a new MageError object
*
* @param message The error message
* @param status The HTTP status code for the error, this will be honored by Mage in the response
* @param options Additional options for the error
*/
constructor(
message: string,
status?: ClientErrorStatus | ServerErrorStatus,
Expand Down
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mage/app",
"version": "0.2.1",
"version": "0.2.2",
"license": "MIT",
"exports": {
".": "./app/mod.ts",
Expand Down
30 changes: 30 additions & 0 deletions status/status-utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
/**
* Informational status
*/
export type InfoStatus = 100 | 101 | 103;

/**
* Success status
*/
export type SuccessStatus =
| 200
| 201
Expand All @@ -12,8 +18,14 @@ export type SuccessStatus =
| 208
| 226;

/**
* Redirect status
*/
export type RedirectStatus = 301 | 302 | 303 | 307 | 308;

/**
* Client error status
*/
export type ClientErrorStatus =
| 400
| 401
Expand Down Expand Up @@ -45,6 +57,9 @@ export type ClientErrorStatus =
| 431
| 451;

/**
* Server error status
*/
export type ServerErrorStatus =
| 500
| 501
Expand All @@ -58,14 +73,24 @@ export type ServerErrorStatus =
| 510
| 511;

/**
* All status
*/
export type Status =
| InfoStatus
| SuccessStatus
| RedirectStatus
| ClientErrorStatus
| ServerErrorStatus;

/**
* Contentful status
*/
export type ContentfulStatus = Exclude<Status, 101 | 204 | 205 | 304>;

/**
* Contentless status
*/
export type ContentlessStatus = Exclude<Status, ContentfulStatus>;

const statusTextMap = {
Expand Down Expand Up @@ -134,6 +159,11 @@ const statusTextMap = {
511: "Network Authentication Required",
};

/**
* Get default status text for a status
* @param status The status
* @returns The status text
*/
export const statusText = (status: keyof typeof statusTextMap): string => {
return statusTextMap[status];
};

0 comments on commit 8333c28

Please sign in to comment.