acrylblends 0.6.0 → 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.
Files changed (128) hide show
  1. package/README.md +8 -6
  2. package/dist/index.d.ts +2 -0
  3. package/dist/index.js +13 -1
  4. package/dist/index.js.map +1 -1
  5. package/docs/framework/UPSTREAM.md +1 -1
  6. package/docs/framework/api/presets.md +0 -3
  7. package/docs/framework/cordis/acryl-in-a-cordis-app.md +3 -0
  8. package/docs/framework/getting-started/basic.md +4 -4
  9. package/docs/framework/guides/jsx.md +1 -1
  10. package/docs/framework/guides/middleware.md +1 -1
  11. package/docs/framework/helpers/cookie.md +1 -1
  12. package/docs/framework/helpers/dev.md +0 -3
  13. package/docs/framework/helpers/jwt.md +1 -1
  14. package/docs/framework/helpers/proxy.md +0 -3
  15. package/docs/framework/middleware/builtin/basic-auth.md +6 -6
  16. package/docs/framework/middleware/builtin/cache.md +0 -3
  17. package/docs/framework/middleware/builtin/combine.md +1 -1
  18. package/docs/framework/middleware/builtin/ip-restriction.md +1 -1
  19. package/docs/framework/middleware/builtin/logger.md +1 -1
  20. package/docs/framework/middleware/builtin/mount.md +0 -3
  21. package/docs/framework/upstream.json +2 -2
  22. package/lib/accepts.d.ts +1 -1
  23. package/lib/acryl-base.d.ts +1 -1
  24. package/lib/adapter.d.ts +1 -1
  25. package/lib/{app-CmAYW1Al.d.ts → app-BdrVHBlJ.d.ts} +1 -1
  26. package/lib/basic-auth.d.ts +1 -1
  27. package/lib/bearer-auth.d.ts +1 -1
  28. package/lib/body-limit.d.ts +1 -1
  29. package/lib/cache.d.ts +43 -0
  30. package/lib/cache.js +169 -0
  31. package/lib/client.d.ts +2 -2
  32. package/lib/combine.d.ts +1 -1
  33. package/lib/compress.d.ts +1 -1
  34. package/lib/conninfo.d.ts +2 -2
  35. package/lib/{context-Bm7rI-oK.d.ts → context-B5Y1lLha.d.ts} +1 -1
  36. package/lib/context-storage.d.ts +1 -1
  37. package/lib/{cookie-ClMaKDQf.d.ts → cookie-D9_nQbsM.d.ts} +1 -1
  38. package/lib/cookie.d.ts +3 -3
  39. package/lib/cors.d.ts +1 -1
  40. package/lib/csrf.d.ts +1 -1
  41. package/lib/dev.d.ts +19 -0
  42. package/lib/dev.js +50 -0
  43. package/lib/etag.d.ts +1 -1
  44. package/lib/factory.d.ts +2 -2
  45. package/lib/{index-B-3F4wt2.d.ts → index-DtEoak1i.d.ts} +2 -2
  46. package/lib/{index-UTBmM3GX.d.ts → index-Kqou8Fjh.d.ts} +2 -2
  47. package/lib/{index-oOClm_Xk.d.ts → index-m12zcmph.d.ts} +3 -3
  48. package/lib/index.d.ts +4 -4
  49. package/lib/ip-restriction.d.ts +2 -2
  50. package/lib/jwk.d.ts +4 -4
  51. package/lib/{jwt-Dg493Tai.d.ts → jwt-BA65QhnJ.d.ts} +1 -1
  52. package/lib/jwt.d.ts +4 -4
  53. package/lib/language.d.ts +1 -1
  54. package/lib/linear-router-C3FPib6h.js +96 -0
  55. package/lib/logger.d.ts +1 -1
  56. package/lib/loopback-only.d.ts +1 -1
  57. package/lib/method-not-allowed.d.ts +2 -2
  58. package/lib/method-override.d.ts +2 -2
  59. package/lib/mount.d.ts +44 -0
  60. package/lib/mount.js +67 -0
  61. package/lib/node-server/conninfo.d.ts +1 -1
  62. package/lib/node-server/serve-static.d.ts +1 -1
  63. package/lib/node-server.d.ts +1 -1
  64. package/lib/pattern-router-HZxjDGEQ.js +41 -0
  65. package/lib/powered-by.d.ts +1 -1
  66. package/lib/pretty-json.d.ts +1 -1
  67. package/lib/proxy.d.ts +72 -0
  68. package/lib/proxy.js +121 -0
  69. package/lib/quick.d.ts +8 -0
  70. package/lib/quick.js +17 -0
  71. package/lib/request-id.d.ts +1 -1
  72. package/lib/request.d.ts +1 -1
  73. package/lib/route.d.ts +1 -1
  74. package/lib/router/linear-router.js +1 -95
  75. package/lib/router/pattern-router.js +1 -40
  76. package/lib/schema-validator.d.ts +1 -1
  77. package/lib/secure-headers.d.ts +1 -1
  78. package/lib/serve-static.d.ts +1 -1
  79. package/lib/streaming.d.ts +1 -1
  80. package/lib/testing.d.ts +4 -4
  81. package/lib/timeout.d.ts +1 -1
  82. package/lib/timing.d.ts +1 -1
  83. package/lib/tiny.d.ts +8 -0
  84. package/lib/tiny.js +15 -0
  85. package/lib/trailing-slash.d.ts +1 -1
  86. package/lib/{types-CHesD1KG.d.ts → types-Bd29gh2o.d.ts} +3 -3
  87. package/lib/{types-CwrQjlaM.d.ts → types-D9DEXMjE.d.ts} +3 -1
  88. package/lib/{types-CDO6I3B0.d.ts → types-ZM9gIiKh.d.ts} +1 -1
  89. package/lib/types.d.ts +1 -1
  90. package/lib/utils/body.d.ts +1 -1
  91. package/lib/utils/cookie.d.ts +1 -1
  92. package/lib/utils/crypto.d.ts +1 -1
  93. package/lib/utils/ipaddr.d.ts +1 -1
  94. package/lib/utils/jwt.d.ts +1 -1
  95. package/lib/utils/types.d.ts +2 -2
  96. package/lib/validator.d.ts +2 -2
  97. package/lib/ws.d.ts +1 -1
  98. package/package.json +25 -1
  99. package/plugins/acryl-inspect/upstream.json +1 -1
  100. package/plugins/acryl-node-server/upstream.json +1 -1
  101. package/plugins/acryl-router/src/core/helper/dev/index.test.ts +181 -0
  102. package/plugins/acryl-router/src/core/helper/dev/index.ts +79 -0
  103. package/plugins/acryl-router/src/core/helper/proxy/index.test.ts +356 -0
  104. package/plugins/acryl-router/src/core/helper/proxy/index.ts +203 -0
  105. package/plugins/acryl-router/src/core/middleware/cache/index.test.ts +1211 -0
  106. package/plugins/acryl-router/src/core/middleware/cache/index.ts +323 -0
  107. package/plugins/acryl-router/src/core/middleware/mount/index.test.ts +334 -0
  108. package/plugins/acryl-router/src/core/middleware/mount/index.ts +108 -0
  109. package/plugins/acryl-router/src/core/preset/quick.test.ts +42 -0
  110. package/plugins/acryl-router/src/core/preset/quick.ts +24 -0
  111. package/plugins/acryl-router/src/core/preset/tiny.test.ts +42 -0
  112. package/plugins/acryl-router/src/core/preset/tiny.ts +20 -0
  113. package/plugins/acryl-router/src/core/utils/types.ts +3 -0
  114. package/plugins/acryl-router/src/helpers/index.ts +2 -0
  115. package/plugins/acryl-router/src/middleware/index.ts +2 -0
  116. package/plugins/acryl-router/src/service.ts +22 -5
  117. package/plugins/acryl-router/upstream.json +2 -2
  118. package/plugins/acryl-router-http/upstream.json +1 -1
  119. package/plugins/acryl-state/upstream.json +1 -1
  120. package/plugins/desktop/upstream.json +1 -1
  121. package/plugins/desktop-web/main.ts +92 -0
  122. package/plugins/desktop-web/plugin.json +17 -0
  123. package/plugins/desktop-web/shutdown.ts +177 -0
  124. package/plugins/desktop-web/upstream.json +12 -0
  125. package/plugins/desktop-web/user-data.ts +38 -0
  126. package/plugins/desktop-web/window.ts +29 -0
  127. package/plugins/tsconfig.json +2 -0
  128. package/templates/todo/upstream.json +1 -1
package/lib/cache.d.ts ADDED
@@ -0,0 +1,43 @@
1
+ import { I as MiddlewareHandler, t as Context } from "./context-B5Y1lLha.js";
2
+ import { c as StatusCode } from "./http-status-DaAwGAFL.js";
3
+
4
+ //#region ../../plugins/acryl-router/src/core/middleware/cache/index.d.ts
5
+ /**
6
+ * Cache Middleware for Acryl.
7
+ *
8
+ *
9
+ * @param {Object} options - The options for the cache middleware.
10
+ * @param {string | Function} options.cacheName - The name of the cache. Can be used to store multiple caches with different identifiers.
11
+ * @param {boolean} [options.wait=false] - A boolean indicating if Acryl should wait for the Promise of the `cache.put` function to resolve before continuing with the request. Required to be true for the Deno environment.
12
+ * @param {string} [options.cacheControl] - A string of directives for the `Cache-Control` header.
13
+ * @param {string | string[]} [options.vary] - Adds the configured request headers to the cache key variants and sets the `Vary` header in the response. If the original response header already contains a `Vary` header, the values are merged, removing any duplicates.
14
+ * @param {Function} [options.keyGenerator] - Generates keys for every request in the `cacheName` store. This can be used to cache data based on request parameters or context parameters. QUERY keys additionally include a digest of the request content and its representation metadata.
15
+ * @param {number} [options.maxQueryBodySize=65536] - The maximum QUERY request body size in bytes that can be cached. Larger QUERY requests bypass the cache.
16
+ * @param {number[]} [options.cacheableStatusCodes=[200]] - An array of status codes that can be cached.
17
+ * @param {Function | false} [options.onCacheNotAvailable] - A callback invoked with the reason when `globalThis.caches` is not available or QUERY caching cannot use Web Crypto. By default, the reason is logged to the console. Set to `false` to suppress the log, or provide a custom function.
18
+ * @returns {MiddlewareHandler} The middleware handler function.
19
+ * @throws {Error} If the `vary` option includes "*".
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * app.use(
24
+ * '*',
25
+ * cache({
26
+ * cacheName: 'my-app',
27
+ * cacheControl: 'max-age=3600',
28
+ * })
29
+ * )
30
+ * ```
31
+ */
32
+ declare const cache: (options: {
33
+ cacheName: string | ((c: Context) => Promise<string> | string);
34
+ wait?: boolean;
35
+ cacheControl?: string;
36
+ vary?: string | string[];
37
+ keyGenerator?: (c: Context) => Promise<string> | string;
38
+ maxQueryBodySize?: number;
39
+ cacheableStatusCodes?: StatusCode[];
40
+ onCacheNotAvailable?: ((reason: string) => void) | false;
41
+ }) => MiddlewareHandler;
42
+ //#endregion
43
+ export { cache };
package/lib/cache.js ADDED
@@ -0,0 +1,169 @@
1
+ import { sha256 } from "./utils/crypto.js";
2
+ import { cloneRawRequest } from "./request.js";
3
+ //#region ../../plugins/acryl-router/src/core/middleware/cache/index.ts
4
+ /**
5
+ * status codes that can be cached by default.
6
+ */
7
+ const defaultCacheableStatusCodes = [200];
8
+ const defaultMaxQueryBodySize = 64 * 1024;
9
+ const cacheKeyPath = "/.acryl-router/cache";
10
+ const cacheKeyParameter = "__hono_cache_key";
11
+ const cacheMethodKeyParameter = "__hono_cache_method";
12
+ const queryDigestKeyParameter = "__hono_query_digest";
13
+ const cacheVaryKeyParameter = "__hono_cache_vary";
14
+ const queryRepresentationMetadataHeaders = [
15
+ "content-type",
16
+ "content-encoding",
17
+ "content-language",
18
+ "content-location"
19
+ ];
20
+ const shouldSkipCacheControl = (cacheControl) => !!cacheControl && /(?:^|,\s*)(?:private|no-(?:store|cache))(?:\s*(?:=|,|$))/i.test(cacheControl);
21
+ const parseVaryDirectives = (vary) => {
22
+ if (vary == null) return [];
23
+ return (Array.isArray(vary) ? vary : vary.split(",")).map((directive) => directive.trim().toLowerCase()).filter(Boolean);
24
+ };
25
+ const createCacheKey = (key, requestUrl, request, varyHeaders) => {
26
+ const url = new URL(cacheKeyPath, requestUrl);
27
+ url.searchParams.append(cacheKeyParameter, key);
28
+ url.searchParams.append(cacheMethodKeyParameter, request.method);
29
+ if (request.method === "QUERY") url.searchParams.append(queryDigestKeyParameter, request.digest);
30
+ for (const header of varyHeaders) url.searchParams.append(cacheVaryKeyParameter, JSON.stringify(header));
31
+ return url.href;
32
+ };
33
+ const shouldSkipCache = (res, optionsVaryDirectives, responseVary) => responseVary.length && (!optionsVaryDirectives || responseVary.some((name) => !optionsVaryDirectives.has(name))) || shouldSkipCacheControl(res.headers.get("Cache-Control")) || res.headers.has("Set-Cookie");
34
+ const reportCacheNotAvailable = (onCacheNotAvailable, reason) => {
35
+ if (onCacheNotAvailable === false) {} else if (onCacheNotAvailable) onCacheNotAvailable(reason);
36
+ else console.log(reason);
37
+ };
38
+ const createQueryDigest = async (c, maxQueryBodySize) => {
39
+ if (!globalThis.crypto?.subtle) return;
40
+ if (c.req.raw.bodyUsed && Object.keys(c.req.bodyCache)[0] === "formData") return;
41
+ try {
42
+ const requestHeaders = c.req.raw.headers;
43
+ const metadata = new TextEncoder().encode(JSON.stringify(queryRepresentationMetadataHeaders.map((header) => [header, requestHeaders.get(header)])));
44
+ const body = (await cloneRawRequest(c.req)).body;
45
+ const chunks = [];
46
+ let bodySize = 0;
47
+ if (body) {
48
+ const reader = body.getReader();
49
+ for (;;) {
50
+ const { done, value } = await reader.read();
51
+ if (done) break;
52
+ bodySize += value.byteLength;
53
+ if (bodySize > maxQueryBodySize) {
54
+ reader.cancel().catch(() => {});
55
+ return;
56
+ }
57
+ chunks.push(value);
58
+ }
59
+ }
60
+ const data = new Uint8Array(metadata.byteLength + bodySize);
61
+ data.set(metadata);
62
+ let offset = metadata.byteLength;
63
+ for (const chunk of chunks) {
64
+ data.set(chunk, offset);
65
+ offset += chunk.byteLength;
66
+ }
67
+ return await sha256(data) ?? void 0;
68
+ } catch {
69
+ return;
70
+ }
71
+ };
72
+ /**
73
+ * Cache Middleware for Acryl.
74
+ *
75
+ *
76
+ * @param {Object} options - The options for the cache middleware.
77
+ * @param {string | Function} options.cacheName - The name of the cache. Can be used to store multiple caches with different identifiers.
78
+ * @param {boolean} [options.wait=false] - A boolean indicating if Acryl should wait for the Promise of the `cache.put` function to resolve before continuing with the request. Required to be true for the Deno environment.
79
+ * @param {string} [options.cacheControl] - A string of directives for the `Cache-Control` header.
80
+ * @param {string | string[]} [options.vary] - Adds the configured request headers to the cache key variants and sets the `Vary` header in the response. If the original response header already contains a `Vary` header, the values are merged, removing any duplicates.
81
+ * @param {Function} [options.keyGenerator] - Generates keys for every request in the `cacheName` store. This can be used to cache data based on request parameters or context parameters. QUERY keys additionally include a digest of the request content and its representation metadata.
82
+ * @param {number} [options.maxQueryBodySize=65536] - The maximum QUERY request body size in bytes that can be cached. Larger QUERY requests bypass the cache.
83
+ * @param {number[]} [options.cacheableStatusCodes=[200]] - An array of status codes that can be cached.
84
+ * @param {Function | false} [options.onCacheNotAvailable] - A callback invoked with the reason when `globalThis.caches` is not available or QUERY caching cannot use Web Crypto. By default, the reason is logged to the console. Set to `false` to suppress the log, or provide a custom function.
85
+ * @returns {MiddlewareHandler} The middleware handler function.
86
+ * @throws {Error} If the `vary` option includes "*".
87
+ *
88
+ * @example
89
+ * ```ts
90
+ * app.use(
91
+ * '*',
92
+ * cache({
93
+ * cacheName: 'my-app',
94
+ * cacheControl: 'max-age=3600',
95
+ * })
96
+ * )
97
+ * ```
98
+ */
99
+ const cache = (options) => {
100
+ if (!globalThis.caches) {
101
+ reportCacheNotAvailable(options.onCacheNotAvailable, "Cache Middleware is not enabled because caches is not defined.");
102
+ return async (_c, next) => await next();
103
+ }
104
+ if (!globalThis.crypto?.subtle) reportCacheNotAvailable(options.onCacheNotAvailable, "Cache Middleware cannot cache QUERY requests because Web Crypto is not available.");
105
+ if (options.wait === void 0) options.wait = false;
106
+ const cacheControlDirectives = options.cacheControl?.split(",").map((directive) => directive.toLowerCase());
107
+ const optionsVaryList = parseVaryDirectives(options.vary);
108
+ const varyDirectives = optionsVaryList.length ? new Set(optionsVaryList) : void 0;
109
+ if (varyDirectives?.has("*")) throw new Error("Middleware vary configuration cannot include \"*\", as it disallows effective caching.");
110
+ const cacheableStatusCodes = new Set(options.cacheableStatusCodes ?? defaultCacheableStatusCodes);
111
+ const maxQueryBodySize = options.maxQueryBodySize ?? defaultMaxQueryBodySize;
112
+ const addHeader = (c, responseVary) => {
113
+ if (cacheControlDirectives) {
114
+ const existingDirectives = c.res.headers.get("Cache-Control")?.split(",").map((d) => d.trim().split("=", 1)[0].toLowerCase()) ?? [];
115
+ for (const directive of cacheControlDirectives) {
116
+ let [name, value] = directive.trim().split("=", 2);
117
+ name = name.toLowerCase();
118
+ if (!existingDirectives.includes(name)) c.header("Cache-Control", `${name}${value ? `=${value}` : ""}`, { append: true });
119
+ }
120
+ }
121
+ if (varyDirectives) if (responseVary.length === 0) c.header("Vary", Array.from(varyDirectives).join(", "));
122
+ else {
123
+ const merged = new Set(varyDirectives);
124
+ for (const directive of responseVary) merged.add(directive);
125
+ if (merged.has("*")) c.header("Vary", "*");
126
+ else c.header("Vary", Array.from(merged).join(", "));
127
+ }
128
+ };
129
+ return async function cache(c, next) {
130
+ if (c.req.method !== "GET" && c.req.method !== "QUERY" || c.req.raw.headers.has("Authorization")) {
131
+ await next();
132
+ return;
133
+ }
134
+ let cacheKeyRequest = { method: "GET" };
135
+ if (c.req.method === "QUERY") {
136
+ const digest = await createQueryDigest(c, maxQueryBodySize);
137
+ if (digest === void 0) {
138
+ await next();
139
+ return;
140
+ }
141
+ cacheKeyRequest = {
142
+ method: "QUERY",
143
+ digest
144
+ };
145
+ }
146
+ let key = c.req.url;
147
+ if (options.keyGenerator) key = await options.keyGenerator(c);
148
+ const varyHeaders = [];
149
+ if (varyDirectives) for (const directive of varyDirectives) {
150
+ const value = c.req.raw.headers.get(directive) ?? "";
151
+ varyHeaders.push([directive, value]);
152
+ }
153
+ key = createCacheKey(key, c.req.url, cacheKeyRequest, varyHeaders);
154
+ const cacheName = typeof options.cacheName === "function" ? await options.cacheName(c) : options.cacheName;
155
+ const cache = await caches.open(cacheName);
156
+ const response = await cache.match(key);
157
+ if (response) return new Response(response.body, response);
158
+ await next();
159
+ if (!cacheableStatusCodes.has(c.res.status)) return;
160
+ const responseVary = parseVaryDirectives(c.res.headers.get("Vary"));
161
+ addHeader(c, responseVary);
162
+ if (shouldSkipCache(c.res, varyDirectives, responseVary)) return;
163
+ const res = c.res.clone();
164
+ if (options.wait) await cache.put(key, res);
165
+ else c.executionCtx.waitUntil(cache.put(key, res));
166
+ };
167
+ };
168
+ //#endregion
169
+ export { cache };
package/lib/client.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { a as ClientResponse, c as InferRequestType, i as ClientRequestOptions, l as InferResponseType, o as Fetch, r as ClientRequest, t as ApplyGlobalResponse, u as PickResponseByStatusCode } from "./types-CHesD1KG.js";
2
- import { n as DetailedError, r as hc, t as parseResponse } from "./index-oOClm_Xk.js";
1
+ import { a as ClientResponse, c as InferRequestType, i as ClientRequestOptions, l as InferResponseType, o as Fetch, r as ClientRequest, t as ApplyGlobalResponse, u as PickResponseByStatusCode } from "./types-Bd29gh2o.js";
2
+ import { n as DetailedError, r as hc, t as parseResponse } from "./index-m12zcmph.js";
3
3
  export { type ApplyGlobalResponse, type ClientRequest, type ClientRequestOptions, type ClientResponse, DetailedError, type Fetch, type InferRequestType, type InferResponseType, type PickResponseByStatusCode, hc, parseResponse };
package/lib/combine.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { I as MiddlewareHandler, t as Context } from "./context-Bm7rI-oK.js";
1
+ import { I as MiddlewareHandler, t as Context } from "./context-B5Y1lLha.js";
2
2
 
3
3
  //#region ../../plugins/acryl-router/src/core/middleware/combine/index.d.ts
4
4
  type Condition = (c: Context) => boolean;
package/lib/compress.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { I as MiddlewareHandler } from "./context-Bm7rI-oK.js";
1
+ import { I as MiddlewareHandler } from "./context-B5Y1lLha.js";
2
2
  import { COMPRESSIBLE_CONTENT_TYPE_REGEX } from "./utils/compress.js";
3
3
 
4
4
  //#region ../../plugins/acryl-router/src/core/middleware/compress/index.d.ts
package/lib/conninfo.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { t as Context } from "./context-Bm7rI-oK.js";
2
- import { i as NetAddrInfo, n as ConnInfo, r as GetConnInfo, t as AddressType } from "./types-CDO6I3B0.js";
1
+ import { t as Context } from "./context-B5Y1lLha.js";
2
+ import { i as NetAddrInfo, n as ConnInfo, r as GetConnInfo, t as AddressType } from "./types-ZM9gIiKh.js";
3
3
 
4
4
  //#region ../../plugins/acryl-router/src/connection.d.ts
5
5
  /** An in-process caller (the terminal UI, a test) passes nothing, so a handler that needs a trusted peer must refuse an empty one. */
@@ -1,7 +1,7 @@
1
1
  import { c as Result, l as Router } from "./router-CvUxUTOq.js";
2
2
  import { i as ResponseHeader, n as CustomHeader, r as RequestHeader } from "./headers-tu2YYN8T.js";
3
3
  import { c as StatusCode, n as ContentfulStatusCode, o as RedirectStatusCode } from "./http-status-DaAwGAFL.js";
4
- import { S as Simplify, T as UnionToIntersection, b as RemoveBlankRecord, c as IfAnyThenEmptyObject, d as IsAny, g as JSONValue, m as JSONParsed, u as InvalidJSONValue } from "./types-CwrQjlaM.js";
4
+ import { C as Simplify, E as UnionToIntersection, _ as JSONValue, d as InvalidJSONValue, f as IsAny, h as JSONParsed, l as IfAnyThenEmptyObject, x as RemoveBlankRecord } from "./types-D9DEXMjE.js";
5
5
  import { t as BaseMime } from "./mime-BQOYHl-l.js";
6
6
 
7
7
  //#region ../../plugins/acryl-router/src/core/request/constants.d.ts
@@ -1,4 +1,4 @@
1
- import { I as MiddlewareHandler, _ as Env, t as Context } from "./context-Bm7rI-oK.js";
1
+ import { I as MiddlewareHandler, _ as Env, t as Context } from "./context-B5Y1lLha.js";
2
2
 
3
3
  //#region ../../plugins/acryl-router/src/core/middleware/context-storage/index.d.ts
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { n as BufferSource } from "./types-CwrQjlaM.js";
1
+ import { n as BufferSource } from "./types-D9DEXMjE.js";
2
2
 
3
3
  //#region ../../plugins/acryl-router/src/core/utils/cookie.d.ts
4
4
  type Cookie = Record<string, string>;
package/lib/cookie.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { t as Context } from "./context-Bm7rI-oK.js";
2
- import { n as BufferSource } from "./types-CwrQjlaM.js";
3
- import { a as SignedCookie, i as CookiePrefixOptions, r as CookieOptions, t as Cookie } from "./cookie-ClMaKDQf.js";
1
+ import { t as Context } from "./context-B5Y1lLha.js";
2
+ import { n as BufferSource } from "./types-D9DEXMjE.js";
3
+ import { a as SignedCookie, i as CookiePrefixOptions, r as CookieOptions, t as Cookie } from "./cookie-D9_nQbsM.js";
4
4
 
5
5
  //#region ../../plugins/acryl-router/src/core/helper/cookie/index.d.ts
6
6
  interface GetCookie {
package/lib/cors.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { I as MiddlewareHandler, t as Context } from "./context-Bm7rI-oK.js";
1
+ import { I as MiddlewareHandler, t as Context } from "./context-B5Y1lLha.js";
2
2
 
3
3
  //#region ../../plugins/acryl-router/src/core/middleware/cors/index.d.ts
4
4
  type CORSOptions = {
package/lib/csrf.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { I as MiddlewareHandler, t as Context } from "./context-Bm7rI-oK.js";
1
+ import { I as MiddlewareHandler, t as Context } from "./context-B5Y1lLha.js";
2
2
 
3
3
  //#region ../../plugins/acryl-router/src/core/middleware/csrf/index.d.ts
4
4
  type IsAllowedOriginHandler = (origin: string, context: Context) => boolean | Promise<boolean>;
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
@@ -1,4 +1,4 @@
1
- import { I as MiddlewareHandler } from "./context-Bm7rI-oK.js";
1
+ import { I as MiddlewareHandler } from "./context-B5Y1lLha.js";
2
2
 
3
3
  //#region ../../plugins/acryl-router/src/core/middleware/etag/index.d.ts
4
4
  type ETagOptions = {
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-Bm7rI-oK.js";
2
- import { t as Acryl } from "./app-CmAYW1Al.js";
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-Bm7rI-oK.js";
2
- import { t as Acryl } from "./app-CmAYW1Al.js";
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-Bm7rI-oK.js";
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, v as MessageEvent } from "./types-CwrQjlaM.js";
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 { T as UnionToIntersection } from "./types-CwrQjlaM.js";
3
- import { t as Acryl } from "./app-CmAYW1Al.js";
4
- import { a as ClientResponse, i as ClientRequestOptions, n as Client, s as FilterClientResponseByStatusCode } from "./types-CHesD1KG.js";
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-Bm7rI-oK.js";
2
- import { t as Acryl } from "./app-CmAYW1Al.js";
3
- import { c as InferRequestType, i as ClientRequestOptions, l as InferResponseType } from "./types-CHesD1KG.js";
4
- import { n as AppRequest, t as App } from "./index-B-3F4wt2.js";
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 };
@@ -1,5 +1,5 @@
1
- import { I as MiddlewareHandler, t as Context } from "./context-Bm7rI-oK.js";
2
- import { r as GetConnInfo, t as AddressType } from "./types-CDO6I3B0.js";
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-Bm7rI-oK.js";
2
- import { n as BufferSource } from "./types-CwrQjlaM.js";
3
- import { i as CookiePrefixOptions } from "./cookie-ClMaKDQf.js";
4
- import { i as AcrylJsonWebKey, n as VerifyOptions, s as AsymmetricAlgorithm } from "./jwt-Dg493Tai.js";
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
  /**
@@ -1,4 +1,4 @@
1
- import { _ as JsonWebKey, i as CryptoKey } from "./types-CwrQjlaM.js";
1
+ import { i as CryptoKey, v as JsonWebKey } from "./types-D9DEXMjE.js";
2
2
 
3
3
  //#region ../../plugins/acryl-router/src/core/utils/jwt/jwa.d.ts
4
4
  /**
package/lib/jwt.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { I as MiddlewareHandler } from "./context-Bm7rI-oK.js";
2
- import { n as BufferSource } from "./types-CwrQjlaM.js";
3
- import { i as CookiePrefixOptions } from "./cookie-ClMaKDQf.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-Dg493Tai.js";
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-Bm7rI-oK.js";
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
@@ -1,4 +1,4 @@
1
- import { I as MiddlewareHandler } from "./context-Bm7rI-oK.js";
1
+ import { I as MiddlewareHandler } from "./context-B5Y1lLha.js";
2
2
 
3
3
  //#region ../../plugins/acryl-router/src/core/middleware/logger/index.d.ts
4
4
  type PrintFunc = (str: string, ...rest: string[]) => void;
@@ -1,4 +1,4 @@
1
- import { I as MiddlewareHandler, t as Context } from "./context-Bm7rI-oK.js";
1
+ import { I as MiddlewareHandler, t as Context } from "./context-B5Y1lLha.js";
2
2
 
3
3
  //#region ../../plugins/acryl-router/src/middleware/loopback-only.d.ts
4
4
  interface LoopbackOptions {
@@ -1,5 +1,5 @@
1
- import { I as MiddlewareHandler, _ as Env, t as Context } from "./context-Bm7rI-oK.js";
2
- import { t as Acryl } from "./app-CmAYW1Al.js";
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>;
@@ -1,5 +1,5 @@
1
- import { I as MiddlewareHandler } from "./context-Bm7rI-oK.js";
2
- import { t as Acryl } from "./app-CmAYW1Al.js";
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 = {