@rhythmjs/router 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,13 +4,24 @@ import { DeriveMiddleware, Middleware } from "@rhythmjs/rhythm/types";
4
4
  export interface RhythmRouterContext {
5
5
  readonly params: Readonly<Record<string, string>>;
6
6
  }
7
+ export type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
7
8
  export interface RhythmRouterOptions {
8
9
  prefix?: string;
9
10
  }
11
+ export type RouterEntry = {
12
+ readonly kind: "middleware";
13
+ readonly fn: Middleware<any>;
14
+ } | {
15
+ readonly kind: "route";
16
+ readonly method: HttpMethod;
17
+ readonly path: string;
18
+ readonly handlers: readonly Middleware<any>[];
19
+ };
10
20
  type RouteHandler<TContext> = Middleware<TContext & RhythmRouterContext>;
11
21
  export declare class RhythmRouter<TContext extends RhythmHttpContext = RhythmHttpContext> {
12
22
  #private;
13
23
  constructor(options?: RhythmRouterOptions);
24
+ get entries(): readonly RouterEntry[];
14
25
  use<TExtra extends object>(fn: DeriveMiddleware<TContext, TExtra>): RhythmRouter<TContext & TExtra>;
15
26
  use(fn: Middleware<TContext>): this;
16
27
  get<TExtra extends object>(path: string, middleware: DeriveMiddleware<TContext & RhythmRouterContext, TExtra>, ...handlers: RouteHandler<TContext & TExtra>[]): this;
@@ -10,6 +10,9 @@ var RhythmRouter = class {
10
10
  get #prefix() {
11
11
  return this.#options.prefix ?? "";
12
12
  }
13
+ get entries() {
14
+ return [...this.#entries];
15
+ }
13
16
  use(fn) {
14
17
  if (typeof fn !== "function") throw new TypeError("middleware must be a function!");
15
18
  this.#entries.push({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rhythmjs/router",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "description": "Radix-tree HTTP router for the Rhythm middleware kernel, with Bun, Node, and Deno adapters.",
5
5
  "homepage": "https://rhythm.js.org/router",
6
6
  "license": "ISC",
@@ -49,7 +49,7 @@
49
49
  "access": "public"
50
50
  },
51
51
  "dependencies": {
52
- "@rhythmjs/rhythm": "0.0.5"
52
+ "@rhythmjs/rhythm": "0.0.6"
53
53
  },
54
54
  "devDependencies": {
55
55
  "@types/node": "^26.6.3",