Skip to content

Commit

Permalink
fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
tlgimenes committed Feb 29, 2024
1 parent 2607098 commit 27db5f4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/realtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,8 @@ export class Realtime implements DurableObject {
"/volumes/:id/files/*": {
GET: async (req, { params }) => {
const { "0": path, id: volumeId } = params;
const withContent = new URL(req.url).searchParams.get("content") === "true";
const withContent =
new URL(req.url).searchParams.get("content") === "true";

const fs: Record<string, { content: string | null }> = {};
for (const key of await this.fs.readdir(path)) {
Expand Down
11 changes: 6 additions & 5 deletions src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ export type Route<TContext> =
| Handler<TContext>
| Record<string, Handler<TContext>>;

export type Routes<TContext> = Record<string, Route<TContext>>;
export type Routes<TContext = {}> = Record<string, Route<TContext>>;

/** O(n) router */
export const createRouter = <TContext>(
routes: Record<string, Route<TContext>>,
) => {
export const createRouter = <TContext = {}>(routes: Routes<TContext>) => {
const compiled = Object.entries(routes).map(([pathname, handler]) =>
[new URLPattern({ pathname }), handler] as const
);
Expand Down Expand Up @@ -44,4 +42,7 @@ export const createRouter = <TContext>(
};
};

export type Router = ReturnType<typeof createRouter>;
export type Router<TContext = {}> = (
request: Request,
ctx?: TContext,
) => Promise<Response>;

0 comments on commit 27db5f4

Please sign in to comment.