Skip to content

Commit

Permalink
v0.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Thesephi committed Mar 3, 2024
1 parent 8bb23c9 commit 590cb3f
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## [0.1.1] - 2024-03-03

### Added

- initial release
2 changes: 1 addition & 1 deletion jsr.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dklab/oak-routing-ctrl",
"version": "0.1.0",
"version": "0.1.1",
"exports": {
".": "./mod.ts"
}
Expand Down
3 changes: 3 additions & 0 deletions src/Controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ export abstract class BaseController {

export type Controller = new () => BaseController;

/**
* Decorator that should be used on the Controller Class
*/
export const Controller =
(pathPrefix: string = "") =>
(target: Controller, context: ClassDecoratorContext) => {
Expand Down
5 changes: 5 additions & 0 deletions src/ControllerActionArgs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { debug } from "./utils/logger.ts";
import { Context, RouteContext } from "../deps.ts";

/**
* Decorator that should be used on the Controller Class Method
* when we need to refer to request body, params, etc. in the
* method body
*/
export const ControllerActionArgs =
(...desirableParams: string[]) =>
(target: Function, context: ClassMethodDecoratorContext): any => {
Expand Down
4 changes: 4 additions & 0 deletions src/Delete.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { debug } from "./utils/logger.ts";
import { register } from "./Store.ts";

/**
* Decorator that should be used on the Controller Class Method
* for DELETE endpoints
*/
export const Delete =
(path: string = "") =>
(target: Function, context: ClassMethodDecoratorContext) => {
Expand Down
4 changes: 4 additions & 0 deletions src/Get.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { debug } from "./utils/logger.ts";
import { register } from "./Store.ts";

/**
* Decorator that should be used on the Controller Class Method
* for GET endpoints
*/
export const Get =
(path: string = "") =>
(target: Function, context: ClassMethodDecoratorContext) => {
Expand Down
4 changes: 4 additions & 0 deletions src/Post.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { debug } from "./utils/logger.ts";
import { register } from "./Store.ts";

/**
* Decorator that should be used on the Controller Class Method
* for POST endpoints
*/
export const Post =
(path: string = "") =>
(target: Function, context: ClassMethodDecoratorContext) => {
Expand Down
4 changes: 4 additions & 0 deletions src/Put.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { debug } from "./utils/logger.ts";
import { register } from "./Store.ts";

/**
* Decorator that should be used on the Controller Class Method
* for PUT endpoints
*/
export const Put =
(path: string = "") =>
(target: Function, context: ClassMemberDecoratorContext) => {
Expand Down
4 changes: 4 additions & 0 deletions src/Store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ type SupportedVerb = "get" | "post" | "put" | "delete" | "patch";

export const store: Map<string, Map<SupportedVerb, string>> = new Map();

/**
* internal library helper method, used to keep track of the declared
* handler functions and their corresponding HTTP methods and paths
*/
export const register = (
verb: SupportedVerb,
path: string,
Expand Down
4 changes: 4 additions & 0 deletions src/useOakServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import { store } from "./Store.ts";

const oakRouter: Router = new Router({});

/**
* entry method to supercharge an `oak` application with routing-controllers -like
* capabilities (i.e. Controller Class and Method Decorators)
*/
export const useOakServer = (
app: Application,
Controllers: Controller[],
Expand Down
4 changes: 4 additions & 0 deletions src/utils/logger.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* proxies to `console.debug` but acts as a no-op unless the `DEBUG`
* env var is declared
*/
export const debug = (...data: any[]): void => {
if (Deno.env.get("DEBUG")) {
console.debug(...data);
Expand Down

0 comments on commit 590cb3f

Please sign in to comment.