Skip to content

Commit

Permalink
feat: typed state
Browse files Browse the repository at this point in the history
  • Loading branch information
Seb Ringrose authored and Seb Ringrose committed Dec 24, 2024
1 parent 2cabff4 commit 378829d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 8 deletions.
6 changes: 1 addition & 5 deletions example/simpleAuth/app.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import * as Peko from "../../mod.ts"; // "https://deno.land/x/peko/mod.ts"

const html = String;
const router = new Peko.HttpRouter<{
username: string | undefined
}>({
username: undefined
});
const router = new Peko.HttpRouter();
const crypto = new Peko.Crypto("SUPER_SECRET_KEY_123"); // <-- replace from env
const user = {
// <-- replace with db / auth provider query
Expand Down
2 changes: 1 addition & 1 deletion lib/routers/_Router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class BaseRouter<
Route = BaseRoute<S>;

constructor(
public state: S,
public state?: S,
public middleware: Middleware<S>[] = [],
public routes: R[] = [] // <- use this as a hashmap for routes
) {}
Expand Down
4 changes: 2 additions & 2 deletions lib/routers/httpRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ export class HttpRoute<S extends object = object> extends BaseRoute<S> {
}

export class HttpRouter<
S extends object = object,
S extends object,
Config extends HttpRouteConfig<S> = HttpRouteConfig<S>,
R extends HttpRoute<S> = HttpRoute<S>
> extends BaseRouter<S, Config, R> {
Route = HttpRoute<S>;

constructor(public state: S, public middleware: Middleware[] = [], public routes: R[] = []) {
constructor(public state?: S, public middleware: Middleware[] = [], public routes: R[] = []) {
super(state, middleware, routes);
}

Expand Down

0 comments on commit 378829d

Please sign in to comment.