File size: 1,117 Bytes
31e8457
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
 * @since 1.0.0
 */
import * as internal from "./internal/router.js"

/**
 * @since 1.0.0
 * @category models
 */
export interface RouterConfig {
  readonly ignoreTrailingSlash: boolean
  readonly ignoreDuplicateSlashes: boolean
  readonly caseSensitive: boolean
  readonly maxParamLength: number
}

/**
 * @since 1.0.0
 * @category models
 */
export type PathInput = `/${string}` | "*"

/**
 * @since 1.0.0
 * @category models
 */
export interface Router<A> {
  readonly on: (
    method: string | Iterable<string>,
    path: PathInput,
    handler: A,
  ) => void
  readonly all: (path: PathInput, handler: A) => void
  readonly find: (method: string, url: string) => FindResult<A> | undefined
  readonly has: (method: string, url: string) => boolean
}

/**
 * @since 1.0.0
 * @category models
 */
export interface FindResult<A> {
  readonly handler: A
  readonly params: Record<string, string | undefined>
  readonly searchParams: Record<string, string | Array<string>>
}

/**
 * @since 1.0.0
 * @category constructors
 */
export const make: <A>(options?: Partial<RouterConfig>) => Router<A> =
  internal.make