acrylblends 0.6.1 → 0.6.2
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/README.md +8 -6
- package/docs/framework/UPSTREAM.md +1 -1
- package/docs/framework/api/presets.md +0 -3
- package/docs/framework/cordis/acryl-in-a-cordis-app.md +3 -0
- package/docs/framework/getting-started/basic.md +4 -4
- package/docs/framework/guides/jsx.md +1 -1
- package/docs/framework/guides/middleware.md +1 -1
- package/docs/framework/helpers/cookie.md +1 -1
- package/docs/framework/helpers/dev.md +0 -3
- package/docs/framework/helpers/jwt.md +1 -1
- package/docs/framework/helpers/proxy.md +0 -3
- package/docs/framework/middleware/builtin/basic-auth.md +6 -6
- package/docs/framework/middleware/builtin/cache.md +0 -3
- package/docs/framework/middleware/builtin/combine.md +1 -1
- package/docs/framework/middleware/builtin/ip-restriction.md +1 -1
- package/docs/framework/middleware/builtin/logger.md +1 -1
- package/docs/framework/middleware/builtin/mount.md +0 -3
- package/docs/framework/upstream.json +2 -2
- package/lib/accepts.d.ts +1 -1
- package/lib/acryl-base.d.ts +1 -1
- package/lib/adapter.d.ts +1 -1
- package/lib/{app-CmAYW1Al.d.ts → app-BdrVHBlJ.d.ts} +1 -1
- package/lib/basic-auth.d.ts +1 -1
- package/lib/bearer-auth.d.ts +1 -1
- package/lib/body-limit.d.ts +1 -1
- package/lib/cache.d.ts +43 -0
- package/lib/cache.js +169 -0
- package/lib/client.d.ts +2 -2
- package/lib/combine.d.ts +1 -1
- package/lib/compress.d.ts +1 -1
- package/lib/conninfo.d.ts +2 -2
- package/lib/{context-Bm7rI-oK.d.ts → context-B5Y1lLha.d.ts} +1 -1
- package/lib/context-storage.d.ts +1 -1
- package/lib/{cookie-ClMaKDQf.d.ts → cookie-D9_nQbsM.d.ts} +1 -1
- package/lib/cookie.d.ts +3 -3
- package/lib/cors.d.ts +1 -1
- package/lib/csrf.d.ts +1 -1
- package/lib/dev.d.ts +19 -0
- package/lib/dev.js +50 -0
- package/lib/etag.d.ts +1 -1
- package/lib/factory.d.ts +2 -2
- package/lib/{index-B-3F4wt2.d.ts → index-DtEoak1i.d.ts} +2 -2
- package/lib/{index-UTBmM3GX.d.ts → index-Kqou8Fjh.d.ts} +2 -2
- package/lib/{index-oOClm_Xk.d.ts → index-m12zcmph.d.ts} +3 -3
- package/lib/index.d.ts +4 -4
- package/lib/ip-restriction.d.ts +2 -2
- package/lib/jwk.d.ts +4 -4
- package/lib/{jwt-Dg493Tai.d.ts → jwt-BA65QhnJ.d.ts} +1 -1
- package/lib/jwt.d.ts +4 -4
- package/lib/language.d.ts +1 -1
- package/lib/linear-router-C3FPib6h.js +96 -0
- package/lib/logger.d.ts +1 -1
- package/lib/loopback-only.d.ts +1 -1
- package/lib/method-not-allowed.d.ts +2 -2
- package/lib/method-override.d.ts +2 -2
- package/lib/mount.d.ts +44 -0
- package/lib/mount.js +67 -0
- package/lib/node-server/conninfo.d.ts +1 -1
- package/lib/node-server/serve-static.d.ts +1 -1
- package/lib/node-server.d.ts +1 -1
- package/lib/pattern-router-HZxjDGEQ.js +41 -0
- package/lib/powered-by.d.ts +1 -1
- package/lib/pretty-json.d.ts +1 -1
- package/lib/proxy.d.ts +72 -0
- package/lib/proxy.js +121 -0
- package/lib/quick.d.ts +8 -0
- package/lib/quick.js +17 -0
- package/lib/request-id.d.ts +1 -1
- package/lib/request.d.ts +1 -1
- package/lib/route.d.ts +1 -1
- package/lib/router/linear-router.js +1 -95
- package/lib/router/pattern-router.js +1 -40
- package/lib/schema-validator.d.ts +1 -1
- package/lib/secure-headers.d.ts +1 -1
- package/lib/serve-static.d.ts +1 -1
- package/lib/streaming.d.ts +1 -1
- package/lib/testing.d.ts +4 -4
- package/lib/timeout.d.ts +1 -1
- package/lib/timing.d.ts +1 -1
- package/lib/tiny.d.ts +8 -0
- package/lib/tiny.js +15 -0
- package/lib/trailing-slash.d.ts +1 -1
- package/lib/{types-CHesD1KG.d.ts → types-Bd29gh2o.d.ts} +3 -3
- package/lib/{types-CwrQjlaM.d.ts → types-D9DEXMjE.d.ts} +3 -1
- package/lib/{types-CDO6I3B0.d.ts → types-ZM9gIiKh.d.ts} +1 -1
- package/lib/types.d.ts +1 -1
- package/lib/utils/body.d.ts +1 -1
- package/lib/utils/cookie.d.ts +1 -1
- package/lib/utils/crypto.d.ts +1 -1
- package/lib/utils/ipaddr.d.ts +1 -1
- package/lib/utils/jwt.d.ts +1 -1
- package/lib/utils/types.d.ts +2 -2
- package/lib/validator.d.ts +2 -2
- package/lib/ws.d.ts +1 -1
- package/package.json +25 -1
- package/plugins/acryl-inspect/upstream.json +1 -1
- package/plugins/acryl-node-server/upstream.json +1 -1
- package/plugins/acryl-router/src/core/helper/dev/index.test.ts +181 -0
- package/plugins/acryl-router/src/core/helper/dev/index.ts +79 -0
- package/plugins/acryl-router/src/core/helper/proxy/index.test.ts +356 -0
- package/plugins/acryl-router/src/core/helper/proxy/index.ts +203 -0
- package/plugins/acryl-router/src/core/middleware/cache/index.test.ts +1211 -0
- package/plugins/acryl-router/src/core/middleware/cache/index.ts +323 -0
- package/plugins/acryl-router/src/core/middleware/mount/index.test.ts +334 -0
- package/plugins/acryl-router/src/core/middleware/mount/index.ts +108 -0
- package/plugins/acryl-router/src/core/preset/quick.test.ts +42 -0
- package/plugins/acryl-router/src/core/preset/quick.ts +24 -0
- package/plugins/acryl-router/src/core/preset/tiny.test.ts +42 -0
- package/plugins/acryl-router/src/core/preset/tiny.ts +20 -0
- package/plugins/acryl-router/src/core/utils/types.ts +3 -0
- package/plugins/acryl-router/src/helpers/index.ts +2 -0
- package/plugins/acryl-router/src/middleware/index.ts +2 -0
- package/plugins/acryl-router/src/service.ts +22 -5
- package/plugins/acryl-router/upstream.json +2 -2
- package/plugins/acryl-router-http/upstream.json +1 -1
- package/plugins/acryl-state/upstream.json +1 -1
- package/plugins/desktop/upstream.json +1 -1
- package/plugins/desktop-web/upstream.json +1 -1
- package/templates/todo/upstream.json +1 -1
package/lib/dev.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { _ as Env } from "./context-B5Y1lLha.js";
|
|
2
|
+
import { t as Acryl } from "./app-BdrVHBlJ.js";
|
|
3
|
+
|
|
4
|
+
//#region ../../plugins/acryl-router/src/core/helper/dev/index.d.ts
|
|
5
|
+
interface ShowRoutesOptions {
|
|
6
|
+
verbose?: boolean;
|
|
7
|
+
colorize?: boolean;
|
|
8
|
+
}
|
|
9
|
+
interface RouteData {
|
|
10
|
+
path: string;
|
|
11
|
+
method: string;
|
|
12
|
+
name: string;
|
|
13
|
+
isMiddleware: boolean;
|
|
14
|
+
}
|
|
15
|
+
declare const inspectRoutes: <E extends Env>(acryl: Acryl<E>) => RouteData[];
|
|
16
|
+
declare const showRoutes: <E extends Env>(acryl: Acryl<E>, opts?: ShowRoutesOptions) => void;
|
|
17
|
+
declare const getRouterName: <E extends Env>(app: Acryl<E>) => string;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { getRouterName, inspectRoutes, showRoutes };
|
package/lib/dev.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { getColorEnabled } from "./utils/color.js";
|
|
2
|
+
import { findTargetHandler, isMiddleware } from "./utils/handler.js";
|
|
3
|
+
//#region ../../plugins/acryl-router/src/core/helper/dev/index.ts
|
|
4
|
+
const handlerName = (handler) => {
|
|
5
|
+
return handler.name || (isMiddleware(handler) ? "[middleware]" : "[handler]");
|
|
6
|
+
};
|
|
7
|
+
const inspectRoutes = (acryl) => {
|
|
8
|
+
return acryl.routes.map(({ path, method, handler }) => {
|
|
9
|
+
const targetHandler = findTargetHandler(handler);
|
|
10
|
+
return {
|
|
11
|
+
path,
|
|
12
|
+
method,
|
|
13
|
+
name: handlerName(targetHandler),
|
|
14
|
+
isMiddleware: isMiddleware(targetHandler)
|
|
15
|
+
};
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
const showRoutes = (acryl, opts) => {
|
|
19
|
+
const colorEnabled = opts?.colorize ?? getColorEnabled();
|
|
20
|
+
const routeData = {};
|
|
21
|
+
let maxMethodLength = 0;
|
|
22
|
+
let maxPathLength = 0;
|
|
23
|
+
inspectRoutes(acryl).filter(({ isMiddleware }) => opts?.verbose || !isMiddleware).map((route) => {
|
|
24
|
+
const key = `${route.method}-${route.path}`;
|
|
25
|
+
(routeData[key] ||= []).push(route);
|
|
26
|
+
if (routeData[key].length > 1) return;
|
|
27
|
+
maxMethodLength = Math.max(maxMethodLength, route.method.length);
|
|
28
|
+
maxPathLength = Math.max(maxPathLength, route.path.length);
|
|
29
|
+
return {
|
|
30
|
+
method: route.method,
|
|
31
|
+
path: route.path,
|
|
32
|
+
routes: routeData[key]
|
|
33
|
+
};
|
|
34
|
+
}).forEach((data) => {
|
|
35
|
+
if (!data) return;
|
|
36
|
+
const { method, path, routes } = data;
|
|
37
|
+
const methodStr = colorEnabled ? `\x1b[32m${method}\x1b[0m` : method;
|
|
38
|
+
console.log(`${methodStr} ${" ".repeat(maxMethodLength - method.length)} ${path}`);
|
|
39
|
+
if (!opts?.verbose) return;
|
|
40
|
+
routes.forEach(({ name }) => {
|
|
41
|
+
console.log(`${" ".repeat(maxMethodLength + 3)} ${name}`);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
const getRouterName = (app) => {
|
|
46
|
+
app.router.match("GET", "/");
|
|
47
|
+
return app.router.name;
|
|
48
|
+
};
|
|
49
|
+
//#endregion
|
|
50
|
+
export { getRouterName, inspectRoutes, showRoutes };
|
package/lib/etag.d.ts
CHANGED
package/lib/factory.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { A as Input, I as MiddlewareHandler, M as IntersectNonAnyTypes, T as H, _ as Env, et as AcrylOptions, k as HandlerResponse } from "./context-
|
|
2
|
-
import { t as Acryl } from "./app-
|
|
1
|
+
import { A as Input, I as MiddlewareHandler, M as IntersectNonAnyTypes, T as H, _ as Env, et as AcrylOptions, k as HandlerResponse } from "./context-B5Y1lLha.js";
|
|
2
|
+
import { t as Acryl } from "./app-BdrVHBlJ.js";
|
|
3
3
|
|
|
4
4
|
//#region ../../plugins/acryl-router/src/core/helper/factory/index.d.ts
|
|
5
5
|
type InitApp<E extends Env = Env> = (app: Acryl<E>) => void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { A as Input, J as Schema, _ as Env, h as BlankSchema, o as AcrylRequest, p as BlankEnv } from "./context-
|
|
2
|
-
import { t as Acryl } from "./app-
|
|
1
|
+
import { A as Input, J as Schema, _ as Env, h as BlankSchema, o as AcrylRequest, p as BlankEnv } from "./context-B5Y1lLha.js";
|
|
2
|
+
import { t as Acryl } from "./app-BdrVHBlJ.js";
|
|
3
3
|
|
|
4
4
|
//#region ../../plugins/acryl-router/src/deprecated.d.ts
|
|
5
5
|
/** @deprecated Use `Acryl` (`new Acryl()`); `App` is the 0.4 name and goes away in the next release. */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { I as MiddlewareHandler, X as TypedResponse, t as Context } from "./context-
|
|
1
|
+
import { I as MiddlewareHandler, X as TypedResponse, t as Context } from "./context-B5Y1lLha.js";
|
|
2
2
|
import { c as StatusCode } from "./http-status-DaAwGAFL.js";
|
|
3
|
-
import { r as CloseEvent, t as BinaryType,
|
|
3
|
+
import { r as CloseEvent, t as BinaryType, y as MessageEvent } from "./types-D9DEXMjE.js";
|
|
4
4
|
|
|
5
5
|
//#region ../../plugins/acryl-router/src/core/helper/websocket/index.d.ts
|
|
6
6
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { n as ContentfulStatusCode, s as ServerErrorStatusCode, t as ClientErrorStatusCode } from "./http-status-DaAwGAFL.js";
|
|
2
|
-
import {
|
|
3
|
-
import { t as Acryl } from "./app-
|
|
4
|
-
import { a as ClientResponse, i as ClientRequestOptions, n as Client, s as FilterClientResponseByStatusCode } from "./types-
|
|
2
|
+
import { E as UnionToIntersection } from "./types-D9DEXMjE.js";
|
|
3
|
+
import { t as Acryl } from "./app-BdrVHBlJ.js";
|
|
4
|
+
import { a as ClientResponse, i as ClientRequestOptions, n as Client, s as FilterClientResponseByStatusCode } from "./types-Bd29gh2o.js";
|
|
5
5
|
|
|
6
6
|
//#region ../../plugins/acryl-router/src/core/client/client.d.ts
|
|
7
7
|
declare const hc: <T extends Acryl<any, any, any>, Prefix extends string = string>(baseUrl: Prefix, options?: ClientRequestOptions) => UnionToIntersection<Client<T, Prefix>>;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { A as Input, B as NotFoundResponse, D as Handler, I as MiddlewareHandler, J as Schema, R as Next, X as TypedResponse, Y as ToSchema, Z as ValidationTargets, _ as Env, a as ExecutionContext, n as ContextRenderer, o as AcrylRequest, r as ContextVariableMap, t as Context, v as ErrorHandler, z as NotFoundHandler } from "./context-
|
|
2
|
-
import { t as Acryl } from "./app-
|
|
3
|
-
import { c as InferRequestType, i as ClientRequestOptions, l as InferResponseType } from "./types-
|
|
4
|
-
import { n as AppRequest, t as App } from "./index-
|
|
1
|
+
import { A as Input, B as NotFoundResponse, D as Handler, I as MiddlewareHandler, J as Schema, R as Next, X as TypedResponse, Y as ToSchema, Z as ValidationTargets, _ as Env, a as ExecutionContext, n as ContextRenderer, o as AcrylRequest, r as ContextVariableMap, t as Context, v as ErrorHandler, z as NotFoundHandler } from "./context-B5Y1lLha.js";
|
|
2
|
+
import { t as Acryl } from "./app-BdrVHBlJ.js";
|
|
3
|
+
import { c as InferRequestType, i as ClientRequestOptions, l as InferResponseType } from "./types-Bd29gh2o.js";
|
|
4
|
+
import { n as AppRequest, t as App } from "./index-DtEoak1i.js";
|
|
5
5
|
export { Acryl, type AcrylRequest, App, type AppRequest, type ClientRequestOptions, Context, type ContextRenderer, type ContextVariableMap, type Env, type ErrorHandler, type ExecutionContext, type Handler, type InferRequestType, type InferResponseType, type Input, type MiddlewareHandler, type Next, type NotFoundHandler, type NotFoundResponse, type Schema, type ToSchema, type TypedResponse, type ValidationTargets };
|
package/lib/ip-restriction.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { I as MiddlewareHandler, t as Context } from "./context-
|
|
2
|
-
import { r as GetConnInfo, t as AddressType } from "./types-
|
|
1
|
+
import { I as MiddlewareHandler, t as Context } from "./context-B5Y1lLha.js";
|
|
2
|
+
import { r as GetConnInfo, t as AddressType } from "./types-ZM9gIiKh.js";
|
|
3
3
|
|
|
4
4
|
//#region ../../plugins/acryl-router/src/core/middleware/ip-restriction/index.d.ts
|
|
5
5
|
/**
|
package/lib/jwk.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { I as MiddlewareHandler, t as Context } from "./context-
|
|
2
|
-
import { n as BufferSource } from "./types-
|
|
3
|
-
import { i as CookiePrefixOptions } from "./cookie-
|
|
4
|
-
import { i as AcrylJsonWebKey, n as VerifyOptions, s as AsymmetricAlgorithm } from "./jwt-
|
|
1
|
+
import { I as MiddlewareHandler, t as Context } from "./context-B5Y1lLha.js";
|
|
2
|
+
import { n as BufferSource } from "./types-D9DEXMjE.js";
|
|
3
|
+
import { i as CookiePrefixOptions } from "./cookie-D9_nQbsM.js";
|
|
4
|
+
import { i as AcrylJsonWebKey, n as VerifyOptions, s as AsymmetricAlgorithm } from "./jwt-BA65QhnJ.js";
|
|
5
5
|
|
|
6
6
|
//#region ../../plugins/acryl-router/src/core/middleware/jwk/jwk.d.ts
|
|
7
7
|
/**
|
package/lib/jwt.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { I as MiddlewareHandler } from "./context-
|
|
2
|
-
import { n as BufferSource } from "./types-
|
|
3
|
-
import { i as CookiePrefixOptions } from "./cookie-
|
|
4
|
-
import { a as SignatureKey, c as SignatureAlgorithm, i as AcrylJsonWebKey, n as VerifyOptions, o as AlgorithmTypes, r as VerifyOptionsWithAlg, s as AsymmetricAlgorithm, t as TokenHeader } from "./jwt-
|
|
1
|
+
import { I as MiddlewareHandler } from "./context-B5Y1lLha.js";
|
|
2
|
+
import { n as BufferSource } from "./types-D9DEXMjE.js";
|
|
3
|
+
import { i as CookiePrefixOptions } from "./cookie-D9_nQbsM.js";
|
|
4
|
+
import { a as SignatureKey, c as SignatureAlgorithm, i as AcrylJsonWebKey, n as VerifyOptions, o as AlgorithmTypes, r as VerifyOptionsWithAlg, s as AsymmetricAlgorithm, t as TokenHeader } from "./jwt-BA65QhnJ.js";
|
|
5
5
|
import { t as JWTPayload } from "./types-DR95J00T.js";
|
|
6
6
|
|
|
7
7
|
//#region ../../plugins/acryl-router/src/core/middleware/jwt/jwt.d.ts
|
package/lib/language.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { I as MiddlewareHandler, t as Context } from "./context-
|
|
1
|
+
import { I as MiddlewareHandler, t as Context } from "./context-B5Y1lLha.js";
|
|
2
2
|
|
|
3
3
|
//#region ../../plugins/acryl-router/src/core/middleware/language/language.d.ts
|
|
4
4
|
type DetectorType = 'path' | 'querystring' | 'cookie' | 'header';
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { checkOptionalParameter } from "./utils/url.js";
|
|
2
|
+
import { UnsupportedPathError } from "./router.js";
|
|
3
|
+
//#region ../../plugins/acryl-router/src/core/router/linear-router/router.ts
|
|
4
|
+
const emptyParams = Object.create(null);
|
|
5
|
+
const splitPathRe = /\/(:\w+(?:{(?:(?:{[\d,]+})|[^}])+})?)|\/[^\/\?]+|(\?)/g;
|
|
6
|
+
const splitByStarRe = /\*/;
|
|
7
|
+
var LinearRouter = class {
|
|
8
|
+
name = "LinearRouter";
|
|
9
|
+
#routes = [];
|
|
10
|
+
add(method, path, handler) {
|
|
11
|
+
for (let i = 0, paths = checkOptionalParameter(path) || [path], len = paths.length; i < len; i++) this.#routes.push([
|
|
12
|
+
method,
|
|
13
|
+
paths[i],
|
|
14
|
+
handler
|
|
15
|
+
]);
|
|
16
|
+
}
|
|
17
|
+
match(method, path) {
|
|
18
|
+
const handlers = [];
|
|
19
|
+
ROUTES_LOOP: for (let i = 0, len = this.#routes.length; i < len; i++) {
|
|
20
|
+
const [routeMethod, routePath, handler] = this.#routes[i];
|
|
21
|
+
if (routeMethod === method || routeMethod === "ALL") {
|
|
22
|
+
if (routePath === "*" || routePath === "/*") {
|
|
23
|
+
handlers.push([handler, emptyParams]);
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
const hasStar = routePath.indexOf("*") !== -1;
|
|
27
|
+
const hasLabel = routePath.indexOf(":") !== -1;
|
|
28
|
+
if (!hasStar && !hasLabel) {
|
|
29
|
+
if (routePath === path || routePath + "/" === path) handlers.push([handler, emptyParams]);
|
|
30
|
+
} else if (hasStar && !hasLabel) {
|
|
31
|
+
const endsWithStar = routePath.charCodeAt(routePath.length - 1) === 42;
|
|
32
|
+
const endsWithSlashStar = routePath.endsWith("/*");
|
|
33
|
+
const parts = (endsWithStar ? routePath.slice(0, endsWithSlashStar ? -2 : -1) : routePath).split(splitByStarRe);
|
|
34
|
+
const lastIndex = parts.length - 1;
|
|
35
|
+
for (let j = 0, pos = 0, len = parts.length; j < len; j++) {
|
|
36
|
+
const part = parts[j];
|
|
37
|
+
if (path.indexOf(part, pos) !== pos) continue ROUTES_LOOP;
|
|
38
|
+
pos += part.length;
|
|
39
|
+
if (j === lastIndex) {
|
|
40
|
+
if (endsWithSlashStar) {
|
|
41
|
+
if (pos !== path.length && path.charCodeAt(pos) !== 47) continue ROUTES_LOOP;
|
|
42
|
+
} else if (!endsWithStar && pos !== path.length && !(pos === path.length - 1 && path.charCodeAt(pos) === 47)) continue ROUTES_LOOP;
|
|
43
|
+
} else {
|
|
44
|
+
const index = path.indexOf("/", pos);
|
|
45
|
+
if (index === -1) continue ROUTES_LOOP;
|
|
46
|
+
pos = index;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
handlers.push([handler, emptyParams]);
|
|
50
|
+
} else if (hasLabel && !hasStar) {
|
|
51
|
+
const params = Object.create(null);
|
|
52
|
+
const parts = routePath.match(splitPathRe);
|
|
53
|
+
const lastIndex = parts.length - 1;
|
|
54
|
+
for (let j = 0, pos = 0, len = parts.length; j < len; j++) {
|
|
55
|
+
if (pos === -1 || pos >= path.length) continue ROUTES_LOOP;
|
|
56
|
+
const part = parts[j];
|
|
57
|
+
if (part.charCodeAt(1) === 58) {
|
|
58
|
+
if (path.charCodeAt(pos) !== 47) continue ROUTES_LOOP;
|
|
59
|
+
let name = part.slice(2);
|
|
60
|
+
let value;
|
|
61
|
+
if (name.charCodeAt(name.length - 1) === 125) {
|
|
62
|
+
const openBracePos = name.indexOf("{");
|
|
63
|
+
const next = parts[j + 1];
|
|
64
|
+
const lookahead = next && next[1] !== ":" && next[1] !== "*" ? `(?=${next})` : "";
|
|
65
|
+
const pattern = name.slice(openBracePos + 1, -1) + lookahead;
|
|
66
|
+
const restPath = path.slice(pos + 1);
|
|
67
|
+
const match = new RegExp(pattern, "d").exec(restPath);
|
|
68
|
+
if (!match || match.indices[0][0] !== 0 || match.indices[0][1] === 0) continue ROUTES_LOOP;
|
|
69
|
+
name = name.slice(0, openBracePos);
|
|
70
|
+
value = restPath.slice(...match.indices[0]);
|
|
71
|
+
pos += match.indices[0][1] + 1;
|
|
72
|
+
} else {
|
|
73
|
+
let endValuePos = path.indexOf("/", pos + 1);
|
|
74
|
+
if (endValuePos === -1) endValuePos = path.length;
|
|
75
|
+
if (endValuePos === pos + 1) continue ROUTES_LOOP;
|
|
76
|
+
value = path.slice(pos + 1, endValuePos);
|
|
77
|
+
pos = endValuePos;
|
|
78
|
+
}
|
|
79
|
+
params[name] ||= value;
|
|
80
|
+
} else {
|
|
81
|
+
if (path.indexOf(part, pos) !== pos) continue ROUTES_LOOP;
|
|
82
|
+
pos += part.length;
|
|
83
|
+
}
|
|
84
|
+
if (j === lastIndex) {
|
|
85
|
+
if (pos !== path.length && !(pos === path.length - 1 && path.charCodeAt(pos) === 47)) continue ROUTES_LOOP;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
handlers.push([handler, params]);
|
|
89
|
+
} else if (hasLabel && hasStar) throw new UnsupportedPathError();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return [handlers];
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
//#endregion
|
|
96
|
+
export { LinearRouter as t };
|
package/lib/logger.d.ts
CHANGED
package/lib/loopback-only.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { I as MiddlewareHandler, _ as Env, t as Context } from "./context-
|
|
2
|
-
import { t as Acryl } from "./app-
|
|
1
|
+
import { I as MiddlewareHandler, _ as Env, t as Context } from "./context-B5Y1lLha.js";
|
|
2
|
+
import { t as Acryl } from "./app-BdrVHBlJ.js";
|
|
3
3
|
|
|
4
4
|
//#region ../../plugins/acryl-router/src/core/middleware/method-not-allowed/index.d.ts
|
|
5
5
|
type MethodNotAllowedHandler<E extends Env> = (c: Context<E>, allowedMethods: string[]) => Response | Promise<Response>;
|
package/lib/method-override.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { I as MiddlewareHandler } from "./context-
|
|
2
|
-
import { t as Acryl } from "./app-
|
|
1
|
+
import { I as MiddlewareHandler } from "./context-B5Y1lLha.js";
|
|
2
|
+
import { t as Acryl } from "./app-BdrVHBlJ.js";
|
|
3
3
|
|
|
4
4
|
//#region ../../plugins/acryl-router/src/core/middleware/method-override/index.d.ts
|
|
5
5
|
type MethodOverrideOptions = {
|
package/lib/mount.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { I as MiddlewareHandler, t as Context } from "./context-B5Y1lLha.js";
|
|
2
|
+
|
|
3
|
+
//#region ../../plugins/acryl-router/src/core/middleware/mount/index.d.ts
|
|
4
|
+
type ApplicationHandler = (request: Request, ...args: any) => Response | Promise<Response>;
|
|
5
|
+
type MountOptionHandler = (c: Context) => unknown;
|
|
6
|
+
type MountReplaceRequest = (originalRequest: Request) => Request;
|
|
7
|
+
type MountOptions = MountOptionHandler | {
|
|
8
|
+
optionHandler?: MountOptionHandler;
|
|
9
|
+
replaceRequest?: MountReplaceRequest | false;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* `mount()` allows you to mount applications built with other frameworks into your Acryl application.
|
|
13
|
+
*
|
|
14
|
+
*
|
|
15
|
+
* @param {Function} applicationHandler - other Request Handler
|
|
16
|
+
* @param {MountOptions} [options] - options of `mount()`
|
|
17
|
+
* @returns {MiddlewareHandler} handler to register with `app.all()`
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* import { Router as IttyRouter } from 'itty-router'
|
|
22
|
+
* import { Acryl } from 'acrylblends'
|
|
23
|
+
* import { mount } from 'acrylblends/mount'
|
|
24
|
+
* // Create itty-router application
|
|
25
|
+
* const ittyRouter = IttyRouter()
|
|
26
|
+
* // GET /itty-router/hello
|
|
27
|
+
* ittyRouter.get('/hello', () => new Response('Hello from itty-router'))
|
|
28
|
+
*
|
|
29
|
+
* const app = new Acryl()
|
|
30
|
+
* app.all('/itty-router/*', mount(ittyRouter.handle))
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* const app = new Acryl()
|
|
36
|
+
* // Send the request to another application without modification.
|
|
37
|
+
* app.all('/app/*', mount(anotherApp, {
|
|
38
|
+
* replaceRequest: (req) => req,
|
|
39
|
+
* }))
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
declare const mount: (applicationHandler: ApplicationHandler, options?: MountOptions) => MiddlewareHandler;
|
|
43
|
+
//#endregion
|
|
44
|
+
export { type ApplicationHandler, type MountOptionHandler, type MountOptions, type MountReplaceRequest, mount };
|
package/lib/mount.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { routePath } from "./route.js";
|
|
2
|
+
//#region ../../plugins/acryl-router/src/core/middleware/mount/index.ts
|
|
3
|
+
const defaultReplaceRequest = (c) => {
|
|
4
|
+
const pathPrefix = routePath(c).replace(/\/\*$/, "");
|
|
5
|
+
const url = new URL(c.req.raw.url);
|
|
6
|
+
url.pathname = c.req.path.slice(pathPrefix.length) || "/";
|
|
7
|
+
return new Request(url, c.req.raw);
|
|
8
|
+
};
|
|
9
|
+
const defaultGetOptions = (c) => {
|
|
10
|
+
let executionContext = void 0;
|
|
11
|
+
try {
|
|
12
|
+
executionContext = c.executionCtx;
|
|
13
|
+
} catch {}
|
|
14
|
+
return [c.env, executionContext];
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* `mount()` allows you to mount applications built with other frameworks into your Acryl application.
|
|
18
|
+
*
|
|
19
|
+
*
|
|
20
|
+
* @param {Function} applicationHandler - other Request Handler
|
|
21
|
+
* @param {MountOptions} [options] - options of `mount()`
|
|
22
|
+
* @returns {MiddlewareHandler} handler to register with `app.all()`
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* import { Router as IttyRouter } from 'itty-router'
|
|
27
|
+
* import { Acryl } from 'acrylblends'
|
|
28
|
+
* import { mount } from 'acrylblends/mount'
|
|
29
|
+
* // Create itty-router application
|
|
30
|
+
* const ittyRouter = IttyRouter()
|
|
31
|
+
* // GET /itty-router/hello
|
|
32
|
+
* ittyRouter.get('/hello', () => new Response('Hello from itty-router'))
|
|
33
|
+
*
|
|
34
|
+
* const app = new Acryl()
|
|
35
|
+
* app.all('/itty-router/*', mount(ittyRouter.handle))
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* const app = new Acryl()
|
|
41
|
+
* // Send the request to another application without modification.
|
|
42
|
+
* app.all('/app/*', mount(anotherApp, {
|
|
43
|
+
* replaceRequest: (req) => req,
|
|
44
|
+
* }))
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
const mount = (applicationHandler, options) => {
|
|
48
|
+
let replaceRequest;
|
|
49
|
+
let optionHandler;
|
|
50
|
+
if (options) if (typeof options === "function") optionHandler = options;
|
|
51
|
+
else {
|
|
52
|
+
optionHandler = options.optionHandler;
|
|
53
|
+
if (options.replaceRequest === false) replaceRequest = (request) => request;
|
|
54
|
+
else replaceRequest = options.replaceRequest;
|
|
55
|
+
}
|
|
56
|
+
const getOptions = optionHandler ? (c) => {
|
|
57
|
+
const options = optionHandler(c);
|
|
58
|
+
return Array.isArray(options) ? options : [options];
|
|
59
|
+
} : defaultGetOptions;
|
|
60
|
+
return async (c, next) => {
|
|
61
|
+
const res = await applicationHandler(replaceRequest ? replaceRequest(c.req.raw) : defaultReplaceRequest(c), ...getOptions(c));
|
|
62
|
+
if (res) return res;
|
|
63
|
+
await next();
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
//#endregion
|
|
67
|
+
export { mount };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { I as MiddlewareHandler, _ as Env, t as Context } from "../context-
|
|
1
|
+
import { I as MiddlewareHandler, _ as Env, t as Context } from "../context-B5Y1lLha.js";
|
|
2
2
|
|
|
3
3
|
//#region ../../plugins/acryl-node-server/src/adapter/serve-static.d.ts
|
|
4
4
|
type ServeStaticOptions<E extends Env = Env> = {
|
package/lib/node-server.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as UpgradeWebSocket } from "./index-
|
|
1
|
+
import { n as UpgradeWebSocket } from "./index-Kqou8Fjh.js";
|
|
2
2
|
import { ServeStaticOptions, serveStatic } from "./node-server/serve-static.js";
|
|
3
3
|
import { getConnInfo } from "./node-server/conninfo.js";
|
|
4
4
|
import { AddressInfo } from "node:net";
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { UnsupportedPathError } from "./router.js";
|
|
2
|
+
//#region ../../plugins/acryl-router/src/core/router/pattern-router/router.ts
|
|
3
|
+
const emptyParams = Object.create(null);
|
|
4
|
+
var PatternRouter = class {
|
|
5
|
+
name = "PatternRouter";
|
|
6
|
+
#routes = [];
|
|
7
|
+
add(method, path, handler) {
|
|
8
|
+
const suffix = path.endsWith("/*") ? "(?:$|/)" : path.endsWith("*") ? "" : "/?$";
|
|
9
|
+
path = path.replace(/\*$/, "");
|
|
10
|
+
if (path.at(-1) === "?") {
|
|
11
|
+
path = path.slice(0, -1);
|
|
12
|
+
this.add(method, path.replace(/\/[^/]+$/, ""), handler);
|
|
13
|
+
}
|
|
14
|
+
const parts = (path.match(/\/?(:\w+(?:{(?:(?:{[\d,]+})|[^}])+})?)|\/?[^\/\?]+/g) || []).map((part) => {
|
|
15
|
+
const match = part.match(/^\/:([^{]+)(?:{(.*)})?/);
|
|
16
|
+
return match ? `/(?<${match[1]}>${match[2] || "[^/]+"})` : part === "/*" ? "/[^/]+" : part.replace(/[.\\+*[^\]$()]/g, "\\$&");
|
|
17
|
+
});
|
|
18
|
+
try {
|
|
19
|
+
this.#routes.push([
|
|
20
|
+
new RegExp(`^${parts.join("")}${suffix}`),
|
|
21
|
+
method,
|
|
22
|
+
handler
|
|
23
|
+
]);
|
|
24
|
+
} catch {
|
|
25
|
+
throw new UnsupportedPathError();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
match(method, path) {
|
|
29
|
+
const handlers = [];
|
|
30
|
+
for (let i = 0, len = this.#routes.length; i < len; i++) {
|
|
31
|
+
const [pattern, routeMethod, handler] = this.#routes[i];
|
|
32
|
+
if (routeMethod === method || routeMethod === "ALL") {
|
|
33
|
+
const match = pattern.exec(path);
|
|
34
|
+
if (match) handlers.push([handler, match.groups || emptyParams]);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return [handlers];
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
//#endregion
|
|
41
|
+
export { PatternRouter as t };
|
package/lib/powered-by.d.ts
CHANGED
package/lib/pretty-json.d.ts
CHANGED
package/lib/proxy.d.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { r as RequestHeader } from "./headers-tu2YYN8T.js";
|
|
2
|
+
import { c as HeadersInit } from "./types-D9DEXMjE.js";
|
|
3
|
+
|
|
4
|
+
//#region ../../plugins/acryl-router/src/core/helper/proxy/index.d.ts
|
|
5
|
+
interface ProxyRequestInit extends Omit<RequestInit, 'headers'> {
|
|
6
|
+
raw?: Request;
|
|
7
|
+
headers?: HeadersInit | [string, string][] | Record<RequestHeader, string | undefined> | Record<string, string | undefined>;
|
|
8
|
+
customFetch?: (request: Request) => Promise<Response>;
|
|
9
|
+
/**
|
|
10
|
+
* Enable strict RFC 9110 compliance for Connection header processing.
|
|
11
|
+
*
|
|
12
|
+
* - `false` (default): Ignores Connection header to prevent potential
|
|
13
|
+
* Hop-by-Hop Header Injection attacks. Recommended for untrusted clients.
|
|
14
|
+
* - `true`: Processes Connection header per RFC 9110 and removes listed headers.
|
|
15
|
+
* Only use in trusted environments.
|
|
16
|
+
*
|
|
17
|
+
* @default false
|
|
18
|
+
* @see https://datatracker.ietf.org/doc/html/rfc9110#section-7.6.1
|
|
19
|
+
*/
|
|
20
|
+
strictConnectionProcessing?: boolean;
|
|
21
|
+
}
|
|
22
|
+
interface ProxyFetch {
|
|
23
|
+
(input: string | URL | Request, init?: ProxyRequestInit): Promise<Response>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Fetch API wrapper for proxy.
|
|
27
|
+
* The parameters and return value are the same as for `fetch` (except for the proxy-specific options).
|
|
28
|
+
*
|
|
29
|
+
* The "Accept-Encoding" header is replaced with an encoding that the current runtime can handle.
|
|
30
|
+
* Unnecessary response headers are deleted and a Response object is returned that can be returned
|
|
31
|
+
* as is as a response from the handler.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* app.get('/proxy/:path', (c) => {
|
|
36
|
+
* return proxy(`http://${originServer}/${c.req.param('path')}`, {
|
|
37
|
+
* headers: {
|
|
38
|
+
* ...c.req.header(), // optional, specify only when forwarding all the request data (including credentials) is necessary.
|
|
39
|
+
* 'X-Forwarded-For': '127.0.0.1',
|
|
40
|
+
* 'X-Forwarded-Host': c.req.header('host'),
|
|
41
|
+
* Authorization: undefined, // do not propagate request headers contained in c.req.header('Authorization')
|
|
42
|
+
* },
|
|
43
|
+
* }).then((res) => {
|
|
44
|
+
* res.headers.delete('Set-Cookie')
|
|
45
|
+
* return res
|
|
46
|
+
* })
|
|
47
|
+
* })
|
|
48
|
+
*
|
|
49
|
+
* app.all('/proxy/:path', (c) => {
|
|
50
|
+
* return proxy(`http://${originServer}/${c.req.param('path')}`, {
|
|
51
|
+
* ...c.req, // optional, specify only when forwarding all the request data (including credentials) is necessary.
|
|
52
|
+
* headers: {
|
|
53
|
+
* ...c.req.header(),
|
|
54
|
+
* 'X-Forwarded-For': '127.0.0.1',
|
|
55
|
+
* 'X-Forwarded-Host': c.req.header('host'),
|
|
56
|
+
* Authorization: undefined, // do not propagate request headers contained in c.req.header('Authorization')
|
|
57
|
+
* },
|
|
58
|
+
* })
|
|
59
|
+
* })
|
|
60
|
+
*
|
|
61
|
+
* // Strict RFC compliance mode (use only in trusted environments)
|
|
62
|
+
* app.get('/internal-proxy/:path', (c) => {
|
|
63
|
+
* return proxy(`http://${internalServer}/${c.req.param('path')}`, {
|
|
64
|
+
* ...c.req,
|
|
65
|
+
* strictConnectionProcessing: true,
|
|
66
|
+
* })
|
|
67
|
+
* })
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
declare const proxy: ProxyFetch;
|
|
71
|
+
//#endregion
|
|
72
|
+
export { proxy };
|