ovr 0.0.1 → 0.1.0

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.
@@ -0,0 +1,140 @@
1
+ import { mergeAsyncIterables } from "./merge-async-iterables.js";
2
+ // https://developer.mozilla.org/en-US/docs/Glossary/Void_element#self-closing_tags
3
+ const voidElements = new Set([
4
+ "area",
5
+ "base",
6
+ "br",
7
+ "col",
8
+ "embed",
9
+ "hr",
10
+ "img",
11
+ "input",
12
+ "link",
13
+ "meta",
14
+ "source",
15
+ "track",
16
+ "wbr",
17
+ ]);
18
+ /**
19
+ * The main function of the jsx transform cycle, each time jsx is encountered
20
+ * it is passed into this function to be resolved.
21
+ *
22
+ * @param tag string or function that refers to the component or element type
23
+ * @param props object containing all the properties and attributes passed to the element or component
24
+ * @returns an async generator that yields parts of HTML
25
+ */
26
+ export const jsx = async function* (tag, props) {
27
+ if (typeof tag === "function") {
28
+ yield* toGenerator(tag(props));
29
+ }
30
+ else {
31
+ // element
32
+ const { children, ...attrs } = props;
33
+ let attrStr = "";
34
+ for (let key in attrs) {
35
+ const value = attrs[key];
36
+ if (key === "className")
37
+ key = "class";
38
+ else if (key === "htmlFor")
39
+ key = "for";
40
+ if (value === true) {
41
+ // just put the key without the value
42
+ attrStr += ` ${key}`;
43
+ }
44
+ else if (typeof value === "string" ||
45
+ typeof value === "number" ||
46
+ typeof value === "bigint") {
47
+ attrStr += ` ${key}=${JSON.stringify(value)}`;
48
+ }
49
+ // otherwise, don't include the attribute
50
+ }
51
+ yield `<${tag}${attrStr}>`;
52
+ if (voidElements.has(tag))
53
+ return;
54
+ if (children)
55
+ yield* toGenerator(children);
56
+ yield `</${tag}>`;
57
+ }
58
+ };
59
+ /**
60
+ * jsx requires a `Fragment` export to resolve <></>
61
+ *
62
+ * @param props containing `children` to render
63
+ * @returns async generator that yields concatenated children
64
+ */
65
+ export async function* Fragment(props = {}) {
66
+ yield* toGenerator(props.children);
67
+ }
68
+ /**
69
+ * @param element
70
+ * @returns async generator that yields concatenated children
71
+ */
72
+ export async function* toGenerator(element) {
73
+ if (typeof element === "function")
74
+ element = element();
75
+ if (element instanceof Promise)
76
+ element = await element;
77
+ // undefined, null, or false should render ""
78
+ if (element == null || element === false)
79
+ return;
80
+ if (typeof element === "object") {
81
+ if (Symbol.asyncIterator in element) {
82
+ for await (const children of element)
83
+ yield* toGenerator(children);
84
+ }
85
+ else if (Symbol.iterator in element) {
86
+ const generators = [];
87
+ for (const children of element)
88
+ generators.push(toGenerator(children));
89
+ const queue = new Array(generators.length).fill("");
90
+ const completed = new Set();
91
+ let current = 0;
92
+ for await (const { index, value, done } of mergeAsyncIterables(generators)) {
93
+ if (done) {
94
+ completed.add(index);
95
+ if (index === current) {
96
+ while (++current < generators.length) {
97
+ if (queue[current]) {
98
+ // yield whatever is in the next queue even if it hasn't completed yet
99
+ yield queue[current];
100
+ queue[current] = "";
101
+ }
102
+ // if it hasn't completed, stop iterating to the next
103
+ if (!completed.has(current))
104
+ break;
105
+ }
106
+ }
107
+ }
108
+ else if (index === current) {
109
+ yield value; // stream the current value directly
110
+ }
111
+ else {
112
+ queue[index] += value; // queue the value for later
113
+ }
114
+ }
115
+ yield queue.join(""); // clear the queue
116
+ }
117
+ else {
118
+ yield JSON.stringify(element); // avoids things like [object Object]
119
+ }
120
+ }
121
+ else {
122
+ yield String(element); // primitive
123
+ }
124
+ }
125
+ /**
126
+ * Converts a `JSX.Element` into its fully concatenated string representation.
127
+ *
128
+ * > [!WARNING]
129
+ * >
130
+ * > This negates streaming benefits and buffers the result into a string.
131
+ *
132
+ * @param element
133
+ * @returns A promise that resolves to the concatenated string.
134
+ */
135
+ export const toString = async (element) => {
136
+ let buffer = "";
137
+ for await (const value of toGenerator(element))
138
+ buffer += value;
139
+ return buffer;
140
+ };
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @param iterables `AsyncIterable` array to merge into one
3
+ */
4
+ export declare function mergeAsyncIterables<T>(iterables: AsyncIterable<T>[]): AsyncGenerator<{
5
+ index: number;
6
+ done: true;
7
+ value?: undefined;
8
+ } | {
9
+ index: number;
10
+ value: T;
11
+ done: false;
12
+ }, void, unknown>;
@@ -0,0 +1,39 @@
1
+ class IterableHandler {
2
+ index;
3
+ iterator;
4
+ promise;
5
+ constructor(index, iterable) {
6
+ this.index = index;
7
+ this.iterator = iterable[Symbol.asyncIterator]();
8
+ this.promise = this.next();
9
+ }
10
+ next() {
11
+ return (this.promise = this.iterator.next().then((result) => ({
12
+ result,
13
+ handler: this,
14
+ })));
15
+ }
16
+ }
17
+ function* getPromises(handlers) {
18
+ for (const handler of handlers)
19
+ yield handler.promise;
20
+ }
21
+ /**
22
+ * @param iterables `AsyncIterable` array to merge into one
23
+ */
24
+ export async function* mergeAsyncIterables(iterables) {
25
+ const handlers = new Set();
26
+ for (let i = 0; i < iterables.length; i++)
27
+ handlers.add(new IterableHandler(i, iterables[i]));
28
+ while (handlers.size) {
29
+ const { result, handler } = await Promise.race(getPromises(handlers));
30
+ if (result.done) {
31
+ handlers.delete(handler);
32
+ yield { index: handler.index, done: true };
33
+ }
34
+ else {
35
+ yield { index: handler.index, value: result.value, done: false };
36
+ handler.next();
37
+ }
38
+ }
39
+ }
@@ -0,0 +1 @@
1
+ export { jsx, jsx as jsxs, jsx as jsxDEV, Fragment, toGenerator, toString, type FC, type JSX, } from "./jsx/index.js";
@@ -0,0 +1 @@
1
+ export { jsx, jsx as jsxs, jsx as jsxDEV, Fragment, toGenerator, toString, } from "./jsx/index.js";
@@ -0,0 +1 @@
1
+ export { jsx, jsx as jsxs, jsx as jsxDEV, Fragment, toGenerator, toString, type FC, type JSX, } from "./jsx/index.js";
@@ -0,0 +1 @@
1
+ export { jsx, jsx as jsxs, jsx as jsxDEV, Fragment, toGenerator, toString, } from "./jsx/index.js";
@@ -0,0 +1,142 @@
1
+ import { type JSX } from "../jsx/index.js";
2
+ import type { Route } from "../trie/index.js";
3
+ import type { Middleware, Params, TrailingSlash, UnmatchedContext } from "./index.js";
4
+ type Layout = (props: {
5
+ children: JSX.Element;
6
+ }) => JSX.Element;
7
+ export declare class Context<State, P extends Params> {
8
+ #private;
9
+ /** [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Request) */
10
+ req: Request;
11
+ /** [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/URL) */
12
+ url: URL;
13
+ /**
14
+ * `state` returned from `config.start`, possibly modified by previous middleware.
15
+ *
16
+ * @default null
17
+ */
18
+ state: State;
19
+ /**
20
+ * Route pattern parameters
21
+ *
22
+ * Given the route pattern `/posts/:slug` is added, a request made to
23
+ * `/posts/my-post` creates a `params` object `{ slug: "my-post" }`.
24
+ *
25
+ * @example { slug: "my-post" }
26
+ */
27
+ params: P;
28
+ /** The matched `Route` instance. */
29
+ route: Route<Middleware<State, P>[]>;
30
+ /** [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Response/Response#body) */
31
+ body: BodyInit | null;
32
+ /** [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status) */
33
+ status?: number;
34
+ /** [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Headers) */
35
+ headers: Headers;
36
+ /**
37
+ * Base HTML to inject the `head` and `page` elements into.
38
+ *
39
+ * @default
40
+ *
41
+ * ```html
42
+ * <!doctype html><html><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"></head><body></body></html>
43
+ * ```
44
+ */
45
+ base: string;
46
+ /**
47
+ * Assign a handler to run when an `Error` is thrown.
48
+ *
49
+ * If not set, `Error` will be thrown. This might be desired
50
+ * if your server already includes error handling. Set in `config.start`
51
+ * to handle errors globally.
52
+ *
53
+ * @default null
54
+ */
55
+ error: ((context: UnmatchedContext<State, Params>, error: unknown) => any) | null;
56
+ constructor(req: Request, url: URL, trailingSlash: TrailingSlash);
57
+ /**
58
+ * Middleware to run when no `body` or `status` has been set on the `context`.
59
+ * Set to a new function to override the default.
60
+ *
61
+ * @default
62
+ *
63
+ * ```ts
64
+ * () => this.html("Not found", 404)
65
+ * ```
66
+ */
67
+ notFound(_context: UnmatchedContext<State, P>): any;
68
+ /**
69
+ * Mirrors `new Response()` constructor, set values with one function.
70
+ *
71
+ * @param body Response BodyInit
72
+ * @param init Enhanced ResponseInit
73
+ */
74
+ res(body: BodyInit | null, init?: {
75
+ /**
76
+ * [HTTP response status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status)
77
+ *
78
+ * @default 200
79
+ */
80
+ status?: number;
81
+ /** [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Headers) */
82
+ headers?: HeadersInit;
83
+ }): void;
84
+ /**
85
+ * Creates an HTML response.
86
+ *
87
+ * @param body HTML body
88
+ * @param status [HTTP response status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status)
89
+ */
90
+ html(body: BodyInit | null, status?: number): void;
91
+ /**
92
+ * Creates a JSON response.
93
+ *
94
+ * @param data passed into JSON.stringify to create the body
95
+ * @param status [HTTP response status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status)
96
+ */
97
+ json(data: any, status?: number): void;
98
+ /**
99
+ * Creates a plain text response.
100
+ *
101
+ * @param body response body
102
+ * @param status [HTTP response status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status)
103
+ */
104
+ text(body: BodyInit, status?: number): void;
105
+ /**
106
+ * Creates a redirect response.
107
+ *
108
+ * @param location redirect `Location` header
109
+ * @param status defaults to [`302`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/302)
110
+ */
111
+ redirect(location: string | URL, status?: 301 | 302 | 303 | 307 | 308): void;
112
+ /**
113
+ * @param Element `JSX.Element` to add to the head
114
+ */
115
+ head(...Element: JSX.Element[]): void;
116
+ /**
117
+ * @param Layout `Layout`(s) for the `Page` to be passed into before being injected into the `<body>`
118
+ */
119
+ layout(...Layout: Layout[]): void;
120
+ /**
121
+ * Creates an HTML response based on the `head` elements, `Layout`(s), and `Page` provided.
122
+ *
123
+ * @param Page `JSX.Element` to inject into the `<body>`
124
+ * @param status [HTTP response status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status)
125
+ */
126
+ page(Page: JSX.Element, status?: number): void;
127
+ /**
128
+ * Generates an etag from a hash of the string provided.
129
+ * If the etag matches, sets the response to not modified.
130
+ *
131
+ * [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ETag)
132
+ *
133
+ * @param s string to hash
134
+ * @returns `true` if the etag matches, `false` otherwise
135
+ */
136
+ etag(s: string): boolean;
137
+ /**
138
+ * @returns the constructed `Response`
139
+ */
140
+ build(): Response;
141
+ }
142
+ export {};
@@ -0,0 +1,222 @@
1
+ import { toGenerator } from "../jsx/index.js";
2
+ class TagNotFound extends Error {
3
+ constructor(tag) {
4
+ super(`No closing ${tag} tag found`);
5
+ this.name = "TagNotFound";
6
+ }
7
+ }
8
+ export class Context {
9
+ /** [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Request) */
10
+ req;
11
+ /** [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/URL) */
12
+ url;
13
+ /**
14
+ * `state` returned from `config.start`, possibly modified by previous middleware.
15
+ *
16
+ * @default null
17
+ */
18
+ state = null;
19
+ /**
20
+ * Route pattern parameters
21
+ *
22
+ * Given the route pattern `/posts/:slug` is added, a request made to
23
+ * `/posts/my-post` creates a `params` object `{ slug: "my-post" }`.
24
+ *
25
+ * @example { slug: "my-post" }
26
+ */
27
+ params = {}; // set after match
28
+ /** The matched `Route` instance. */
29
+ route = undefined; // set after match
30
+ /** [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Response/Response#body) */
31
+ body = null;
32
+ /** [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status) */
33
+ status;
34
+ /** [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Headers) */
35
+ headers = new Headers();
36
+ /**
37
+ * Base HTML to inject the `head` and `page` elements into.
38
+ *
39
+ * @default
40
+ *
41
+ * ```html
42
+ * <!doctype html><html><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"></head><body></body></html>
43
+ * ```
44
+ */
45
+ base = '<!doctype html><html><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"></head><body></body></html>';
46
+ /**
47
+ * Assign a handler to run when an `Error` is thrown.
48
+ *
49
+ * If not set, `Error` will be thrown. This might be desired
50
+ * if your server already includes error handling. Set in `config.start`
51
+ * to handle errors globally.
52
+ *
53
+ * @default null
54
+ */
55
+ error = null;
56
+ #layouts = [];
57
+ #headElements = [];
58
+ #trailingSlash;
59
+ constructor(req, url, trailingSlash) {
60
+ this.req = req;
61
+ this.url = url;
62
+ this.#trailingSlash = trailingSlash;
63
+ }
64
+ /**
65
+ * Middleware to run when no `body` or `status` has been set on the `context`.
66
+ * Set to a new function to override the default.
67
+ *
68
+ * @default
69
+ *
70
+ * ```ts
71
+ * () => this.html("Not found", 404)
72
+ * ```
73
+ */
74
+ notFound(_context) {
75
+ this.html("Not found", 404);
76
+ }
77
+ /**
78
+ * Mirrors `new Response()` constructor, set values with one function.
79
+ *
80
+ * @param body Response BodyInit
81
+ * @param init Enhanced ResponseInit
82
+ */
83
+ res(body, init) {
84
+ this.body = body;
85
+ this.status = init?.status ?? 200;
86
+ if (init?.headers) {
87
+ for (const [name, value] of new Headers(init.headers)) {
88
+ this.headers.append(name, value);
89
+ }
90
+ }
91
+ }
92
+ /**
93
+ * Creates an HTML response.
94
+ *
95
+ * @param body HTML body
96
+ * @param status [HTTP response status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status)
97
+ */
98
+ html(body, status) {
99
+ this.res(body, {
100
+ status,
101
+ headers: { "content-type": "text/html; charset=utf-8" },
102
+ });
103
+ }
104
+ /**
105
+ * Creates a JSON response.
106
+ *
107
+ * @param data passed into JSON.stringify to create the body
108
+ * @param status [HTTP response status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status)
109
+ */
110
+ json(data, status) {
111
+ this.res(JSON.stringify(data), {
112
+ status,
113
+ headers: { "content-type": "application/json" },
114
+ });
115
+ }
116
+ /**
117
+ * Creates a plain text response.
118
+ *
119
+ * @param body response body
120
+ * @param status [HTTP response status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status)
121
+ */
122
+ text(body, status) {
123
+ this.res(body, { status, headers: { "content-type": "text/html" } });
124
+ }
125
+ /**
126
+ * Creates a redirect response.
127
+ *
128
+ * @param location redirect `Location` header
129
+ * @param status defaults to [`302`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/302)
130
+ */
131
+ redirect(location, status = 302) {
132
+ this.headers.set("location", location.toString());
133
+ this.status = status;
134
+ }
135
+ /**
136
+ * @param Element `JSX.Element` to add to the head
137
+ */
138
+ head(...Element) {
139
+ this.#headElements.push(...Element);
140
+ }
141
+ /**
142
+ * @param Layout `Layout`(s) for the `Page` to be passed into before being injected into the `<body>`
143
+ */
144
+ layout(...Layout) {
145
+ this.#layouts.push(...Layout);
146
+ }
147
+ /**
148
+ * Creates an HTML response based on the `head` elements, `Layout`(s), and `Page` provided.
149
+ *
150
+ * @param Page `JSX.Element` to inject into the `<body>`
151
+ * @param status [HTTP response status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status)
152
+ */
153
+ page(Page, status) {
154
+ for (let i = this.#layouts.length - 1; i >= 0; i--)
155
+ Page = this.#layouts[i]({ children: Page });
156
+ const headClose = "</head>";
157
+ const bodyClose = "</body>";
158
+ const elements = this.base.split(headClose);
159
+ if (!elements[1])
160
+ throw new TagNotFound(headClose);
161
+ elements.splice(1, 0, this.#headElements, headClose);
162
+ const bodyParts = elements[3].split(bodyClose);
163
+ if (!bodyParts[1])
164
+ throw new TagNotFound(bodyClose);
165
+ elements[3] = bodyParts[0];
166
+ elements.push(Page, bodyClose + bodyParts[1]);
167
+ this.html(new ReadableStream({
168
+ start: async (c) => {
169
+ for await (const value of toGenerator(elements))
170
+ c.enqueue(value);
171
+ c.close();
172
+ },
173
+ }).pipeThrough(new TextEncoderStream()), status);
174
+ }
175
+ /**
176
+ * Generates an etag from a hash of the string provided.
177
+ * If the etag matches, sets the response to not modified.
178
+ *
179
+ * [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ETag)
180
+ *
181
+ * @param s string to hash
182
+ * @returns `true` if the etag matches, `false` otherwise
183
+ */
184
+ etag(s) {
185
+ // Fast hashing algorithm http://www.cse.yorku.ca/~oz/hash.html
186
+ // Adapted from SvelteKit https://github.com/sveltejs/kit/blob/25d459104814b0c2dc6b4cf73b680378a29d8200/packages/kit/src/runtime/hash.js
187
+ let hash = 5381;
188
+ let i = s.length;
189
+ while (i)
190
+ hash = (hash * 33) ^ s.charCodeAt(--i);
191
+ const etag = `"${(hash >>> 0).toString(36)}"`;
192
+ this.headers.set("etag", etag);
193
+ if (this.req.headers.get("if-none-match") === etag) {
194
+ this.body = null;
195
+ this.status = 304;
196
+ return true;
197
+ }
198
+ return false;
199
+ }
200
+ /**
201
+ * @returns the constructed `Response`
202
+ */
203
+ build() {
204
+ if ((!this.status || this.status === 404) &&
205
+ this.#trailingSlash !== "ignore") {
206
+ const last = this.url.pathname.at(-1);
207
+ if (this.#trailingSlash === "always" && last !== "/") {
208
+ this.url.pathname += "/";
209
+ this.redirect(this.url, 308);
210
+ }
211
+ else if (this.#trailingSlash === "never" &&
212
+ this.url.pathname !== "/" &&
213
+ last === "/") {
214
+ this.url.pathname = this.url.pathname.slice(0, -1);
215
+ this.redirect(this.url, 308);
216
+ }
217
+ }
218
+ if (!this.body && !this.status)
219
+ this.notFound(this);
220
+ return new Response(this.body, this);
221
+ }
222
+ }
@@ -0,0 +1,91 @@
1
+ import { Context } from "./context.js";
2
+ export type Params = Record<string, string>;
3
+ export type UnmatchedContext<State, P extends Params> = Omit<Context<State, P>, "route"> & Partial<Pick<Context<State, P>, "route">>;
4
+ export type Start<State> = (context: Omit<UnmatchedContext<any, Params>, "state" | "route" | "params">) => State;
5
+ export type Middleware<State = null, P extends Params = Params> = (context: Context<State, P>, next: () => Promise<void>) => any;
6
+ export type TrailingSlash = "always" | "never" | "ignore";
7
+ type Method = "GET" | "HEAD" | "POST" | "PUT" | "DELETE" | "CONNECT" | "OPTIONS" | "TRACE" | "PATCH" | (string & {});
8
+ type ExtractParams<Pattern extends string = string> = Pattern extends `${infer _Start}:${infer Param}/${infer Rest}` ? {
9
+ [k in Param | keyof ExtractParams<Rest>]: string;
10
+ } : Pattern extends `${infer _Start}:${infer Param}` ? {
11
+ [k in Param]: string;
12
+ } : Pattern extends `${infer _Rest}*` ? {
13
+ "*": string;
14
+ } : {};
15
+ type ExtractMultiParams<Patterns extends string[]> = Patterns extends [
16
+ infer First extends string,
17
+ ...infer Rest extends string[]
18
+ ] ? Rest["length"] extends 0 ? ExtractParams<First> : ExtractParams<First> | ExtractMultiParams<Rest> : never;
19
+ export declare class Router<State = null> {
20
+ #private;
21
+ constructor(config?: {
22
+ /**
23
+ * - `"never"` - Not found requests with a trailing slash will be redirected to the same path without a trailing slash
24
+ * - `"always"` - Not found requests without a trailing slash will be redirected to the same path with a trailing slash
25
+ * - `"ignore"` - no redirects (not recommended, bad for SEO)
26
+ *
27
+ * [Trailing Slash for Frameworks by Bjorn Lu](https://bjornlu.com/blog/trailing-slash-for-frameworks)
28
+ *
29
+ * @default "never"
30
+ */
31
+ trailingSlash?: TrailingSlash;
32
+ /**
33
+ * Runs before middleware, return a value to set the initial state.
34
+ *
35
+ * @param context request context
36
+ * @returns any state to access in middleware
37
+ * @default null
38
+ */
39
+ start?: Start<State>;
40
+ });
41
+ /**
42
+ * @param method HTTP method
43
+ * @param pattern route pattern
44
+ * @param middleware
45
+ * @returns the router instance
46
+ */
47
+ on<Pattern extends string>(method: Method, pattern: Pattern, ...middleware: Middleware<State, ExtractParams<Pattern>>[]): this;
48
+ /**
49
+ * @param method HTTP method
50
+ * @param patterns array of route patterns
51
+ * @param middleware
52
+ * @returns the router instance
53
+ */
54
+ on<Patterns extends string[]>(method: Method, patterns: [...Patterns], ...middleware: Middleware<State, ExtractMultiParams<Patterns>>[]): this;
55
+ /**
56
+ * @param pattern route pattern
57
+ * @param middleware
58
+ * @returns the router instance
59
+ */
60
+ get<Pattern extends string>(pattern: Pattern, ...middleware: Middleware<State, ExtractParams<Pattern>>[]): this;
61
+ /**
62
+ * @param patterns array of route patterns
63
+ * @param middleware
64
+ * @returns the router instance
65
+ */
66
+ get<Patterns extends string[]>(patterns: [...Patterns], ...middleware: Middleware<State, ExtractMultiParams<Patterns>>[]): this;
67
+ /**
68
+ * @param pattern route pattern
69
+ * @param middleware
70
+ * @returns the router instance
71
+ */
72
+ post<Pattern extends string>(pattern: Pattern, ...middleware: Middleware<State, ExtractParams<Pattern>>[]): this;
73
+ /**
74
+ * @param patterns array of route patterns
75
+ * @param middleware
76
+ * @returns the router instance
77
+ */
78
+ post<Patterns extends string[]>(patterns: [...Patterns], ...middleware: Middleware<State, ExtractMultiParams<Patterns>>[]): this;
79
+ /**
80
+ * @param basePattern pattern to mount the router to, each route will begin with this base
81
+ * @param router sub-router to mount
82
+ * @returns the base router instance
83
+ */
84
+ mount(basePattern: string, router: Router<State>): this;
85
+ /**
86
+ * @param req [`Request` Reference](https://developer.mozilla.org/en-US/docs/Web/API/Request)
87
+ * @returns [`Response` Reference](https://developer.mozilla.org/en-US/docs/Web/API/Response)
88
+ */
89
+ fetch(req: Request): Promise<Response>;
90
+ }
91
+ export {};