hono 4.4.3 → 4.4.4
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.
- package/dist/adapter/cloudflare-workers/index.js +2 -0
- package/dist/cjs/adapter/cloudflare-workers/index.js +3 -0
- package/dist/cjs/context.js +2 -2
- package/dist/cjs/helper/conninfo/types.js +16 -0
- package/dist/cjs/hono-base.js +3 -4
- package/dist/cjs/jsx/utils.js +4 -0
- package/dist/cjs/middleware/serve-static/index.js +5 -3
- package/dist/cjs/utils/filepath.js +1 -1
- package/dist/context.js +2 -2
- package/dist/helper/conninfo/types.js +0 -0
- package/dist/hono-base.js +3 -4
- package/dist/jsx/utils.js +4 -0
- package/dist/middleware/serve-static/index.js +5 -3
- package/dist/types/adapter/cloudflare-workers/index.d.ts +1 -0
- package/dist/types/context.d.ts +12 -5
- package/dist/types/helper/conninfo/index.d.ts +1 -36
- package/dist/types/helper/conninfo/types.d.ts +36 -0
- package/dist/types/jsx/utils.d.ts +6 -0
- package/dist/types/types.d.ts +11 -8
- package/dist/types/utils/types.d.ts +10 -3
- package/dist/utils/filepath.js +1 -1
- package/package.json +1 -1
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// src/adapter/cloudflare-workers/index.ts
|
|
2
2
|
import { serveStatic } from "./serve-static-module.js";
|
|
3
3
|
import { upgradeWebSocket } from "./websocket.js";
|
|
4
|
+
import { getConnInfo } from "./conninfo.js";
|
|
4
5
|
export {
|
|
6
|
+
getConnInfo,
|
|
5
7
|
serveStatic,
|
|
6
8
|
upgradeWebSocket
|
|
7
9
|
};
|
|
@@ -18,14 +18,17 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var cloudflare_workers_exports = {};
|
|
20
20
|
__export(cloudflare_workers_exports, {
|
|
21
|
+
getConnInfo: () => import_conninfo.getConnInfo,
|
|
21
22
|
serveStatic: () => import_serve_static_module.serveStatic,
|
|
22
23
|
upgradeWebSocket: () => import_websocket.upgradeWebSocket
|
|
23
24
|
});
|
|
24
25
|
module.exports = __toCommonJS(cloudflare_workers_exports);
|
|
25
26
|
var import_serve_static_module = require("./serve-static-module");
|
|
26
27
|
var import_websocket = require("./websocket");
|
|
28
|
+
var import_conninfo = require("./conninfo");
|
|
27
29
|
// Annotate the CommonJS export names for ESM import in node:
|
|
28
30
|
0 && (module.exports = {
|
|
31
|
+
getConnInfo,
|
|
29
32
|
serveStatic,
|
|
30
33
|
upgradeWebSocket
|
|
31
34
|
});
|
package/dist/cjs/context.js
CHANGED
|
@@ -232,10 +232,10 @@ class Context {
|
|
|
232
232
|
}
|
|
233
233
|
return typeof arg === "number" ? this.newResponse(html, arg, headers) : this.newResponse(html, arg);
|
|
234
234
|
};
|
|
235
|
-
redirect = (location, status
|
|
235
|
+
redirect = (location, status) => {
|
|
236
236
|
this.#headers ??= new Headers();
|
|
237
237
|
this.#headers.set("Location", location);
|
|
238
|
-
return this.newResponse(null, status);
|
|
238
|
+
return this.newResponse(null, status ?? 302);
|
|
239
239
|
};
|
|
240
240
|
notFound = () => {
|
|
241
241
|
return this.notFoundHandler(this);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var types_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(types_exports);
|
package/dist/cjs/hono-base.js
CHANGED
|
@@ -24,7 +24,6 @@ __export(hono_base_exports, {
|
|
|
24
24
|
module.exports = __toCommonJS(hono_base_exports);
|
|
25
25
|
var import_compose = require("./compose");
|
|
26
26
|
var import_context = require("./context");
|
|
27
|
-
var import_http_exception = require("./http-exception");
|
|
28
27
|
var import_request = require("./request");
|
|
29
28
|
var import_router = require("./router");
|
|
30
29
|
var import_url = require("./utils/url");
|
|
@@ -33,7 +32,7 @@ const notFoundHandler = (c) => {
|
|
|
33
32
|
return c.text("404 Not Found", 404);
|
|
34
33
|
};
|
|
35
34
|
const errorHandler = (err, c) => {
|
|
36
|
-
if (
|
|
35
|
+
if ("getResponse" in err) {
|
|
37
36
|
return err.getResponse();
|
|
38
37
|
}
|
|
39
38
|
console.error(err);
|
|
@@ -221,7 +220,7 @@ class Hono {
|
|
|
221
220
|
}
|
|
222
221
|
return res instanceof Promise ? res.then(
|
|
223
222
|
(resolved) => resolved || (c.finalized ? c.res : this.notFoundHandler(c))
|
|
224
|
-
).catch((err) => this.handleError(err, c)) : res;
|
|
223
|
+
).catch((err) => this.handleError(err, c)) : res ?? this.notFoundHandler(c);
|
|
225
224
|
}
|
|
226
225
|
const composed = (0, import_compose.compose)(matchResult[0], this.errorHandler, this.notFoundHandler);
|
|
227
226
|
return (async () => {
|
|
@@ -229,7 +228,7 @@ class Hono {
|
|
|
229
228
|
const context = await composed(c);
|
|
230
229
|
if (!context.finalized) {
|
|
231
230
|
throw new Error(
|
|
232
|
-
"Context is not finalized.
|
|
231
|
+
"Context is not finalized. Did you forget to return a Response object or `await next()`?"
|
|
233
232
|
);
|
|
234
233
|
}
|
|
235
234
|
return context.res;
|
package/dist/cjs/jsx/utils.js
CHANGED
|
@@ -27,6 +27,10 @@ const normalizeIntrinsicElementProps = (props) => {
|
|
|
27
27
|
props["class"] = props["className"];
|
|
28
28
|
delete props["className"];
|
|
29
29
|
}
|
|
30
|
+
if (props && "htmlFor" in props) {
|
|
31
|
+
props["for"] = props["htmlFor"];
|
|
32
|
+
delete props["htmlFor"];
|
|
33
|
+
}
|
|
30
34
|
};
|
|
31
35
|
const styleObjectForEach = (style, fn) => {
|
|
32
36
|
for (const [k, v] of Object.entries(style)) {
|
|
@@ -55,9 +55,11 @@ const serveStatic = (options) => {
|
|
|
55
55
|
return await next();
|
|
56
56
|
}
|
|
57
57
|
pathWithOutDefaultDocument = pathResolve(pathWithOutDefaultDocument);
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
if (pathWithOutDefaultDocument !== path) {
|
|
59
|
+
content = await getContent(pathWithOutDefaultDocument, c);
|
|
60
|
+
if (content) {
|
|
61
|
+
path = pathWithOutDefaultDocument;
|
|
62
|
+
}
|
|
61
63
|
}
|
|
62
64
|
}
|
|
63
65
|
if (content instanceof Response) {
|
|
@@ -27,7 +27,7 @@ const getFilePath = (options) => {
|
|
|
27
27
|
const defaultDocument = options.defaultDocument || "index.html";
|
|
28
28
|
if (filename.endsWith("/")) {
|
|
29
29
|
filename = filename.concat(defaultDocument);
|
|
30
|
-
} else if (!filename.match(/\.[a-zA-Z0-
|
|
30
|
+
} else if (!filename.match(/\.[a-zA-Z0-9_-]+$/)) {
|
|
31
31
|
filename = filename.concat("/" + defaultDocument);
|
|
32
32
|
}
|
|
33
33
|
const path = getFilePathWithoutDefaultDocument({
|
package/dist/context.js
CHANGED
|
@@ -209,10 +209,10 @@ var Context = class {
|
|
|
209
209
|
}
|
|
210
210
|
return typeof arg === "number" ? this.newResponse(html, arg, headers) : this.newResponse(html, arg);
|
|
211
211
|
};
|
|
212
|
-
redirect = (location, status
|
|
212
|
+
redirect = (location, status) => {
|
|
213
213
|
this.#headers ??= new Headers();
|
|
214
214
|
this.#headers.set("Location", location);
|
|
215
|
-
return this.newResponse(null, status);
|
|
215
|
+
return this.newResponse(null, status ?? 302);
|
|
216
216
|
};
|
|
217
217
|
notFound = () => {
|
|
218
218
|
return this.notFoundHandler(this);
|
|
File without changes
|
package/dist/hono-base.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// src/hono-base.ts
|
|
2
2
|
import { compose } from "./compose.js";
|
|
3
3
|
import { Context } from "./context.js";
|
|
4
|
-
import { HTTPException } from "./http-exception.js";
|
|
5
4
|
import { HonoRequest } from "./request.js";
|
|
6
5
|
import { METHODS, METHOD_NAME_ALL, METHOD_NAME_ALL_LOWERCASE } from "./router.js";
|
|
7
6
|
import { getPath, getPathNoStrict, mergePath } from "./utils/url.js";
|
|
@@ -10,7 +9,7 @@ var notFoundHandler = (c) => {
|
|
|
10
9
|
return c.text("404 Not Found", 404);
|
|
11
10
|
};
|
|
12
11
|
var errorHandler = (err, c) => {
|
|
13
|
-
if (
|
|
12
|
+
if ("getResponse" in err) {
|
|
14
13
|
return err.getResponse();
|
|
15
14
|
}
|
|
16
15
|
console.error(err);
|
|
@@ -198,7 +197,7 @@ var Hono = class {
|
|
|
198
197
|
}
|
|
199
198
|
return res instanceof Promise ? res.then(
|
|
200
199
|
(resolved) => resolved || (c.finalized ? c.res : this.notFoundHandler(c))
|
|
201
|
-
).catch((err) => this.handleError(err, c)) : res;
|
|
200
|
+
).catch((err) => this.handleError(err, c)) : res ?? this.notFoundHandler(c);
|
|
202
201
|
}
|
|
203
202
|
const composed = compose(matchResult[0], this.errorHandler, this.notFoundHandler);
|
|
204
203
|
return (async () => {
|
|
@@ -206,7 +205,7 @@ var Hono = class {
|
|
|
206
205
|
const context = await composed(c);
|
|
207
206
|
if (!context.finalized) {
|
|
208
207
|
throw new Error(
|
|
209
|
-
"Context is not finalized.
|
|
208
|
+
"Context is not finalized. Did you forget to return a Response object or `await next()`?"
|
|
210
209
|
);
|
|
211
210
|
}
|
|
212
211
|
return context.res;
|
package/dist/jsx/utils.js
CHANGED
|
@@ -4,6 +4,10 @@ var normalizeIntrinsicElementProps = (props) => {
|
|
|
4
4
|
props["class"] = props["className"];
|
|
5
5
|
delete props["className"];
|
|
6
6
|
}
|
|
7
|
+
if (props && "htmlFor" in props) {
|
|
8
|
+
props["for"] = props["htmlFor"];
|
|
9
|
+
delete props["htmlFor"];
|
|
10
|
+
}
|
|
7
11
|
};
|
|
8
12
|
var styleObjectForEach = (style, fn) => {
|
|
9
13
|
for (const [k, v] of Object.entries(style)) {
|
|
@@ -33,9 +33,11 @@ var serveStatic = (options) => {
|
|
|
33
33
|
return await next();
|
|
34
34
|
}
|
|
35
35
|
pathWithOutDefaultDocument = pathResolve(pathWithOutDefaultDocument);
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
if (pathWithOutDefaultDocument !== path) {
|
|
37
|
+
content = await getContent(pathWithOutDefaultDocument, c);
|
|
38
|
+
if (content) {
|
|
39
|
+
path = pathWithOutDefaultDocument;
|
|
40
|
+
}
|
|
39
41
|
}
|
|
40
42
|
}
|
|
41
43
|
if (content instanceof Response) {
|
package/dist/types/context.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { HonoRequest } from './request';
|
|
2
2
|
import type { Env, FetchEventLike, Input, NotFoundHandler, TypedResponse } from './types';
|
|
3
3
|
import type { RedirectStatusCode, StatusCode } from './utils/http-status';
|
|
4
|
-
import type { IsAny, JSONParsed, JSONValue,
|
|
4
|
+
import type { IsAny, JSONParsed, JSONValue, SimplifyDeepArray } from './utils/types';
|
|
5
5
|
type HeaderRecord = Record<string, string | string[]>;
|
|
6
6
|
/**
|
|
7
7
|
* Data type can be a string, ArrayBuffer, or ReadableStream.
|
|
@@ -109,12 +109,19 @@ interface TextRespond {
|
|
|
109
109
|
* @param {U} [status] - An optional status code for the response.
|
|
110
110
|
* @param {HeaderRecord} [headers] - An optional record of headers to include in the response.
|
|
111
111
|
*
|
|
112
|
-
* @returns {
|
|
112
|
+
* @returns {JSONRespondReturn<T, U>} - The response after rendering the JSON object, typed with the provided object and status code types.
|
|
113
113
|
*/
|
|
114
114
|
interface JSONRespond {
|
|
115
|
-
<T extends JSONValue |
|
|
116
|
-
<T extends JSONValue |
|
|
115
|
+
<T extends JSONValue | SimplifyDeepArray<unknown>, U extends StatusCode>(object: T, status?: U, headers?: HeaderRecord): JSONRespondReturn<T, U>;
|
|
116
|
+
<T extends JSONValue | SimplifyDeepArray<unknown>, U extends StatusCode>(object: T, init?: ResponseInit): JSONRespondReturn<T, U>;
|
|
117
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* @template T - The type of the JSON value or simplified unknown type.
|
|
120
|
+
* @template U - The type of the status code.
|
|
121
|
+
*
|
|
122
|
+
* @returns {Response & TypedResponse<SimplifyDeepArray<T> extends JSONValue ? (JSONValue extends SimplifyDeepArray<T> ? never : JSONParsed<T>) : never, U, 'json'>} - The response after rendering the JSON object, typed with the provided object and status code types.
|
|
123
|
+
*/
|
|
124
|
+
type JSONRespondReturn<T extends JSONValue | SimplifyDeepArray<unknown>, U extends StatusCode> = Response & TypedResponse<SimplifyDeepArray<T> extends JSONValue ? JSONValue extends SimplifyDeepArray<T> ? never : JSONParsed<T> : never, U, 'json'>;
|
|
118
125
|
/**
|
|
119
126
|
* Interface representing a function that responds with HTML content.
|
|
120
127
|
*
|
|
@@ -401,7 +408,7 @@ export declare class Context<E extends Env = any, P extends string = any, I exte
|
|
|
401
408
|
* })
|
|
402
409
|
* ```
|
|
403
410
|
*/
|
|
404
|
-
redirect: (location: string, status?:
|
|
411
|
+
redirect: <T extends RedirectStatusCode = 302>(location: string, status?: T | undefined) => Response & TypedResponse<undefined, T, "redirect">;
|
|
405
412
|
/**
|
|
406
413
|
* `.notFound()` can return the Not Found Response.
|
|
407
414
|
*
|
|
@@ -2,39 +2,4 @@
|
|
|
2
2
|
* @module
|
|
3
3
|
* ConnInfo Helper for Hono.
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
|
-
export type AddressType = 'IPv6' | 'IPv4' | 'unknown';
|
|
7
|
-
export type NetAddrInfo = {
|
|
8
|
-
/**
|
|
9
|
-
* Transport protocol type
|
|
10
|
-
*/
|
|
11
|
-
transport?: 'tcp' | 'udp';
|
|
12
|
-
/**
|
|
13
|
-
* Transport port number
|
|
14
|
-
*/
|
|
15
|
-
port?: number;
|
|
16
|
-
address?: string;
|
|
17
|
-
addressType?: AddressType;
|
|
18
|
-
} & ({
|
|
19
|
-
/**
|
|
20
|
-
* Host name such as IP Addr
|
|
21
|
-
*/
|
|
22
|
-
address: string;
|
|
23
|
-
/**
|
|
24
|
-
* Host name type
|
|
25
|
-
*/
|
|
26
|
-
addressType: AddressType;
|
|
27
|
-
} | {});
|
|
28
|
-
/**
|
|
29
|
-
* HTTP Connection infomation
|
|
30
|
-
*/
|
|
31
|
-
export interface ConnInfo {
|
|
32
|
-
/**
|
|
33
|
-
* Remote infomation
|
|
34
|
-
*/
|
|
35
|
-
remote: NetAddrInfo;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Helper type
|
|
39
|
-
*/
|
|
40
|
-
export type GetConnInfo = (c: Context) => ConnInfo;
|
|
5
|
+
export type { AddressType, NetAddrInfo, ConnInfo, GetConnInfo } from './types';
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Context } from '../../context';
|
|
2
|
+
export type AddressType = 'IPv6' | 'IPv4' | 'unknown';
|
|
3
|
+
export type NetAddrInfo = {
|
|
4
|
+
/**
|
|
5
|
+
* Transport protocol type
|
|
6
|
+
*/
|
|
7
|
+
transport?: 'tcp' | 'udp';
|
|
8
|
+
/**
|
|
9
|
+
* Transport port number
|
|
10
|
+
*/
|
|
11
|
+
port?: number;
|
|
12
|
+
address?: string;
|
|
13
|
+
addressType?: AddressType;
|
|
14
|
+
} & ({
|
|
15
|
+
/**
|
|
16
|
+
* Host name such as IP Addr
|
|
17
|
+
*/
|
|
18
|
+
address: string;
|
|
19
|
+
/**
|
|
20
|
+
* Host name type
|
|
21
|
+
*/
|
|
22
|
+
addressType: AddressType;
|
|
23
|
+
} | {});
|
|
24
|
+
/**
|
|
25
|
+
* HTTP Connection infomation
|
|
26
|
+
*/
|
|
27
|
+
export interface ConnInfo {
|
|
28
|
+
/**
|
|
29
|
+
* Remote infomation
|
|
30
|
+
*/
|
|
31
|
+
remote: NetAddrInfo;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Helper type
|
|
35
|
+
*/
|
|
36
|
+
export type GetConnInfo = (c: Context) => ConnInfo;
|
|
@@ -1,2 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalizes intrinsic element properties by converting JSX element properties
|
|
3
|
+
* to their corresponding HTML attributes.
|
|
4
|
+
*
|
|
5
|
+
* @param props - JSX element properties.
|
|
6
|
+
*/
|
|
1
7
|
export declare const normalizeIntrinsicElementProps: (props: Record<string, unknown>) => void;
|
|
2
8
|
export declare const styleObjectForEach: (style: Record<string, string | number>, fn: (key: string, value: string | null) => void) => void;
|
package/dist/types/types.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import type { Context } from './context';
|
|
6
6
|
import type { Hono } from './hono';
|
|
7
7
|
import type { StatusCode } from './utils/http-status';
|
|
8
|
-
import type { IfAnyThenEmptyObject, IsAny, JSONValue,
|
|
8
|
+
import type { IfAnyThenEmptyObject, IsAny, JSONValue, RemoveBlankRecord, Simplify, UnionToIntersection } from './utils/types';
|
|
9
9
|
export type Bindings = Record<string, unknown>;
|
|
10
10
|
export type Variables = Record<string, unknown>;
|
|
11
11
|
export type BlankEnv = {};
|
|
@@ -32,7 +32,10 @@ export type Handler<E extends Env = any, P extends string = any, I extends Input
|
|
|
32
32
|
export type MiddlewareHandler<E extends Env = any, P extends string = string, I extends Input = {}> = (c: Context<E, P, I>, next: Next) => Promise<Response | void>;
|
|
33
33
|
export type H<E extends Env = any, P extends string = any, I extends Input = BlankInput, R extends HandlerResponse<any> = any> = Handler<E, P, I, R> | MiddlewareHandler<E, P, I>;
|
|
34
34
|
export type NotFoundHandler<E extends Env = any> = (c: Context<E>) => Response | Promise<Response>;
|
|
35
|
-
export
|
|
35
|
+
export interface HTTPResponseError extends Error {
|
|
36
|
+
getResponse: () => Response;
|
|
37
|
+
}
|
|
38
|
+
export type ErrorHandler<E extends Env = any> = (err: Error | HTTPResponseError, c: Context<E>) => Response | Promise<Response>;
|
|
36
39
|
export interface HandlerInterface<E extends Env = Env, M extends string = string, S extends Schema = BlankSchema, BasePath extends string = '/'> {
|
|
37
40
|
<P extends string = ExtractKey<S> extends never ? BasePath : ExtractKey<S>, I extends Input = BlankInput, R extends HandlerResponse<any> = any, E2 extends Env = E>(handler: H<E2, P, I, R>): Hono<IntersectNonAnyTypes<[E, E2]>, S & ToSchema<M, P, I, MergeTypedResponse<R>>, BasePath>;
|
|
38
41
|
<P extends string, MergedPath extends MergePath<BasePath, P> = MergePath<BasePath, P>, R extends HandlerResponse<any> = any, I extends Input = BlankInput, E2 extends Env = E>(path: P, handler: H<E2, MergedPath, I, R>): Hono<IntersectNonAnyTypes<[E, E2]>, S & ToSchema<M, MergePath<BasePath, P>, I, MergeTypedResponse<R>>, BasePath>;
|
|
@@ -367,7 +370,7 @@ export interface OnHandlerInterface<E extends Env = Env, S extends Schema = Blan
|
|
|
367
370
|
<I extends Input = BlankInput, R extends HandlerResponse<any> = any>(methods: string | string[], paths: string[], ...handlers: H<E, any, I, R>[]): Hono<E, S & ToSchema<string, string, I, MergeTypedResponse<R>>, BasePath>;
|
|
368
371
|
}
|
|
369
372
|
type ExtractKey<S> = S extends Record<infer Key, unknown> ? Key extends string ? Key : never : string;
|
|
370
|
-
export type ToSchema<M extends string, P extends string, I extends Input | Input['in'], RorO> =
|
|
373
|
+
export type ToSchema<M extends string, P extends string, I extends Input | Input['in'], RorO> = Simplify<{
|
|
371
374
|
[K in P]: {
|
|
372
375
|
[K2 in M as AddDollar<K2>]: Simplify<{
|
|
373
376
|
input: AddParam<ExtractInput<I>, P>;
|
|
@@ -409,7 +412,7 @@ type ExtractParams<Path extends string> = string extends Path ? Record<string, s
|
|
|
409
412
|
type FlattenIfIntersect<T> = T extends infer O ? {
|
|
410
413
|
[K in keyof O]: O[K];
|
|
411
414
|
} : never;
|
|
412
|
-
export type MergeSchemaPath<OrigSchema extends Schema, SubPath extends string> =
|
|
415
|
+
export type MergeSchemaPath<OrigSchema extends Schema, SubPath extends string> = Simplify<{
|
|
413
416
|
[P in keyof OrigSchema as MergePath<SubPath, P & string>]: {
|
|
414
417
|
[M in keyof OrigSchema[P]]: MergeEndpointParamsWithPath<OrigSchema[P][M], SubPath>;
|
|
415
418
|
};
|
|
@@ -442,12 +445,12 @@ export type AddParam<I, P extends string> = ParamKeys<P> extends never ? I : I e
|
|
|
442
445
|
};
|
|
443
446
|
type AddDollar<T extends string> = `$${Lowercase<T>}`;
|
|
444
447
|
export type MergePath<A extends string, B extends string> = B extends '' ? MergePath<A, '/'> : A extends '' ? B : A extends '/' ? B : A extends `${infer P}/` ? B extends `/${infer Q}` ? `${P}/${Q}` : `${P}/${B}` : B extends `/${infer Q}` ? Q extends '' ? A : `${A}/${Q}` : `${A}/${B}`;
|
|
445
|
-
export type KnownResponseFormat = 'json' | 'text';
|
|
448
|
+
export type KnownResponseFormat = 'json' | 'text' | 'redirect';
|
|
446
449
|
export type ResponseFormat = KnownResponseFormat | string;
|
|
447
450
|
export type TypedResponse<T = unknown, U extends StatusCode = StatusCode, F extends ResponseFormat = T extends string ? 'text' : T extends JSONValue ? 'json' : ResponseFormat> = {
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
+
_data: T;
|
|
452
|
+
_status: U;
|
|
453
|
+
_format: F;
|
|
451
454
|
};
|
|
452
455
|
type MergeTypedResponse<T> = T extends Promise<infer T2> ? T2 extends TypedResponse ? T2 : TypedResponse : T extends TypedResponse ? T : TypedResponse;
|
|
453
456
|
export type ValidationTargets = {
|
|
@@ -19,9 +19,19 @@ export type JSONParsed<T> = T extends {
|
|
|
19
19
|
} ? (() => J) extends () => JSONObject ? J : JSONParsed<J> : T extends JSONPrimitive ? T : T extends Array<infer U> ? Array<JSONParsed<U>> : T extends object ? {
|
|
20
20
|
[K in keyof T]: JSONParsed<T[K]>;
|
|
21
21
|
} : never;
|
|
22
|
+
/**
|
|
23
|
+
* Useful to flatten the type output to improve type hints shown in editors. And also to transform an interface into a type to aide with assignability.
|
|
24
|
+
* @copyright from sindresorhus/type-fest
|
|
25
|
+
*/
|
|
22
26
|
export type Simplify<T> = {
|
|
23
27
|
[KeyType in keyof T]: T[KeyType];
|
|
24
28
|
} & {};
|
|
29
|
+
/**
|
|
30
|
+
* A simple extension of Simplify that will deeply traverse array elements.
|
|
31
|
+
*/
|
|
32
|
+
export type SimplifyDeepArray<T> = T extends any[] ? {
|
|
33
|
+
[E in keyof T]: SimplifyDeepArray<T[E]>;
|
|
34
|
+
} : Simplify<T>;
|
|
25
35
|
export type InterfaceToType<T> = T extends Function ? T : {
|
|
26
36
|
[K in keyof T]: InterfaceToType<T[K]>;
|
|
27
37
|
};
|
|
@@ -30,6 +40,3 @@ export type RequiredKeysOf<BaseType extends object> = Exclude<{
|
|
|
30
40
|
}[keyof BaseType], undefined>;
|
|
31
41
|
export type HasRequiredKeys<BaseType extends object> = RequiredKeysOf<BaseType> extends never ? false : true;
|
|
32
42
|
export type IsAny<T> = boolean extends (T extends never ? true : false) ? true : false;
|
|
33
|
-
export type Prettify<T> = {
|
|
34
|
-
[K in keyof T]: T[K];
|
|
35
|
-
} & {};
|
package/dist/utils/filepath.js
CHANGED
|
@@ -4,7 +4,7 @@ var getFilePath = (options) => {
|
|
|
4
4
|
const defaultDocument = options.defaultDocument || "index.html";
|
|
5
5
|
if (filename.endsWith("/")) {
|
|
6
6
|
filename = filename.concat(defaultDocument);
|
|
7
|
-
} else if (!filename.match(/\.[a-zA-Z0-
|
|
7
|
+
} else if (!filename.match(/\.[a-zA-Z0-9_-]+$/)) {
|
|
8
8
|
filename = filename.concat("/" + defaultDocument);
|
|
9
9
|
}
|
|
10
10
|
const path = getFilePathWithoutDefaultDocument({
|