acrylblends 0.6.1 → 0.6.3
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 +11 -6
- package/docs/framework/README.md +3 -2
- 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 +9 -0
- package/docs/framework/getting-started/basic.md +5 -4
- package/docs/framework/getting-started/desktop.md +41 -0
- package/docs/framework/guides/jsx-dom.md +0 -3
- package/docs/framework/guides/jsx.md +1 -4
- package/docs/framework/guides/middleware.md +1 -1
- package/docs/framework/helpers/cookie.md +1 -1
- package/docs/framework/helpers/css.md +0 -3
- 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 +3 -3
- 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-wFwpg-bt.d.ts} +1 -1
- package/lib/base-BpQy2Rk7.d.ts +783 -0
- package/lib/base-ddiVmiE7.js +721 -0
- 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/common-D8Z4JRCw.d.ts +46 -0
- package/lib/components-Ce5FRyHU.js +268 -0
- package/lib/components-DYZdxJIJ.js +24 -0
- package/lib/compress.d.ts +1 -1
- package/lib/conninfo.d.ts +2 -2
- package/lib/constants-BR9jM9BC.js +9 -0
- package/lib/{context-Bm7rI-oK.d.ts → context-DVQBjuns.d.ts} +1 -1
- package/lib/context-DxFdY_un.d.ts +250 -0
- package/lib/context-storage.d.ts +1 -1
- package/lib/{cookie-ClMaKDQf.d.ts → cookie-CCelEqky.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/css-D2jb7X8b.js +320 -0
- package/lib/css.d.ts +82 -0
- package/lib/css.js +134 -0
- 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/hooks-Bq5q9IMl.js +762 -0
- package/lib/html-SllAe0YT.d.ts +46 -0
- package/lib/html.d.ts +1 -1
- package/lib/index-C850MeBA.d.ts +94 -0
- package/lib/{index-oOClm_Xk.d.ts → index-CUTfU69R.d.ts} +3 -3
- package/lib/{index-B-3F4wt2.d.ts → index-Cqcdluyn.d.ts} +2 -2
- package/lib/{index-UTBmM3GX.d.ts → index-CsvB-F9j.d.ts} +2 -2
- package/lib/index.d.ts +4 -4
- package/lib/ip-restriction.d.ts +2 -2
- package/lib/jsx/dom/client.d.ts +30 -0
- package/lib/jsx/dom/client.js +49 -0
- package/lib/jsx/dom/css.d.ts +84 -0
- package/lib/jsx/dom/css.js +2 -0
- package/lib/jsx/dom/jsx-dev-runtime.d.ts +3 -0
- package/lib/jsx/dom/jsx-dev-runtime.js +2 -0
- package/lib/jsx/dom/jsx-runtime.d.ts +3 -0
- package/lib/jsx/dom/jsx-runtime.js +2 -0
- package/lib/jsx/dom/server.d.ts +105 -0
- package/lib/jsx/dom/server.js +37 -0
- package/lib/jsx/dom.d.ts +5 -0
- package/lib/jsx/dom.js +74 -0
- package/lib/jsx/jsx-dev-runtime.d.ts +6 -0
- package/lib/jsx/jsx-dev-runtime.js +14 -0
- package/lib/jsx/jsx-runtime.d.ts +10 -0
- package/lib/jsx/jsx-runtime.js +30 -0
- package/lib/jsx/streaming.d.ts +2 -0
- package/lib/jsx/streaming.js +2 -0
- package/lib/jsx-dev-runtime-B22O-Npk.d.ts +7 -0
- package/lib/jsx-dev-runtime-kAhR_4C7.js +354 -0
- package/lib/jsx-runtime-BVVgDSdq.d.ts +1 -0
- package/lib/jsx.d.ts +3 -0
- package/lib/jsx.js +47 -0
- package/lib/jwk.d.ts +4 -4
- package/lib/{jwt-Dg493Tai.d.ts → jwt-BARhotDz.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/serve-static.js +1 -1
- package/lib/node-server.d.ts +1 -1
- package/lib/node-server.js +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-Dw_m6KxR.js → serve-static-Cw23shXv.js} +1 -0
- 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-CQiGmsWW.d.ts} +3 -3
- package/lib/{types-CwrQjlaM.d.ts → types-Lqx5BxQF.d.ts} +10 -1
- package/lib/{types-CDO6I3B0.d.ts → types-nEL8VPDC.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/html.d.ts +1 -45
- 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 +69 -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/css/common.case.test.tsx +506 -0
- package/plugins/acryl-router/src/core/helper/css/common.ts +337 -0
- package/plugins/acryl-router/src/core/helper/css/index.test.tsx +678 -0
- package/plugins/acryl-router/src/core/helper/css/index.ts +262 -0
- 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/helper/streaming/sse.test.tsx +557 -0
- package/plugins/acryl-router/src/core/jsx/base.test.tsx +97 -0
- package/plugins/acryl-router/src/core/jsx/base.ts +490 -0
- package/plugins/acryl-router/src/core/jsx/children.test.ts +52 -0
- package/plugins/acryl-router/src/core/jsx/children.ts +20 -0
- package/plugins/acryl-router/src/core/jsx/components.test.tsx +936 -0
- package/plugins/acryl-router/src/core/jsx/components.ts +257 -0
- package/plugins/acryl-router/src/core/jsx/constants.ts +6 -0
- package/plugins/acryl-router/src/core/jsx/context-isolation.test.ts +655 -0
- package/plugins/acryl-router/src/core/jsx/context.ts +266 -0
- package/plugins/acryl-router/src/core/jsx/dom/client.test.tsx +128 -0
- package/plugins/acryl-router/src/core/jsx/dom/client.ts +89 -0
- package/plugins/acryl-router/src/core/jsx/dom/components.test.tsx +330 -0
- package/plugins/acryl-router/src/core/jsx/dom/components.ts +39 -0
- package/plugins/acryl-router/src/core/jsx/dom/context.test.tsx +184 -0
- package/plugins/acryl-router/src/core/jsx/dom/context.ts +52 -0
- package/plugins/acryl-router/src/core/jsx/dom/css.test.tsx +149 -0
- package/plugins/acryl-router/src/core/jsx/dom/css.ts +263 -0
- package/plugins/acryl-router/src/core/jsx/dom/hooks/index.test.tsx +172 -0
- package/plugins/acryl-router/src/core/jsx/dom/hooks/index.ts +91 -0
- package/plugins/acryl-router/src/core/jsx/dom/index.test.tsx +3681 -0
- package/plugins/acryl-router/src/core/jsx/dom/index.ts +170 -0
- package/plugins/acryl-router/src/core/jsx/dom/intrinsic-element/components.test.tsx +1344 -0
- package/plugins/acryl-router/src/core/jsx/dom/intrinsic-element/components.ts +438 -0
- package/plugins/acryl-router/src/core/jsx/dom/jsx-dev-runtime.ts +23 -0
- package/plugins/acryl-router/src/core/jsx/dom/jsx-runtime.ts +8 -0
- package/plugins/acryl-router/src/core/jsx/dom/render.ts +879 -0
- package/plugins/acryl-router/src/core/jsx/dom/server.test.tsx +199 -0
- package/plugins/acryl-router/src/core/jsx/dom/server.ts +76 -0
- package/plugins/acryl-router/src/core/jsx/dom/utils.ts +7 -0
- package/plugins/acryl-router/src/core/jsx/hooks/dom.test.tsx +859 -0
- package/plugins/acryl-router/src/core/jsx/hooks/index.ts +437 -0
- package/plugins/acryl-router/src/core/jsx/hooks/string.test.tsx +40 -0
- package/plugins/acryl-router/src/core/jsx/index.test.tsx +1744 -0
- package/plugins/acryl-router/src/core/jsx/index.ts +115 -0
- package/plugins/acryl-router/src/core/jsx/intrinsic-element/common.ts +23 -0
- package/plugins/acryl-router/src/core/jsx/intrinsic-element/components.test.tsx +666 -0
- package/plugins/acryl-router/src/core/jsx/intrinsic-element/components.ts +210 -0
- package/plugins/acryl-router/src/core/jsx/intrinsic-elements.ts +938 -0
- package/plugins/acryl-router/src/core/jsx/jsx-dev-runtime.ts +26 -0
- package/plugins/acryl-router/src/core/jsx/jsx-runtime.test.tsx +85 -0
- package/plugins/acryl-router/src/core/jsx/jsx-runtime.ts +51 -0
- package/plugins/acryl-router/src/core/jsx/streaming.test.tsx +1281 -0
- package/plugins/acryl-router/src/core/jsx/streaming.ts +231 -0
- package/plugins/acryl-router/src/core/jsx/types.ts +41 -0
- package/plugins/acryl-router/src/core/jsx/utils.test.ts +366 -0
- package/plugins/acryl-router/src/core/jsx/utils.ts +202 -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 +9 -0
- package/plugins/acryl-router/src/helpers/index.ts +3 -0
- package/plugins/acryl-router/src/middleware/index.ts +2 -0
- package/plugins/acryl-router/src/service.ts +22 -5
- package/plugins/acryl-router/tests/jsx.spec.tsx +63 -0
- package/plugins/acryl-router/upstream.json +3 -3
- 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/plugins/save/plugin.json +1 -1
- package/templates/todo/upstream.json +1 -1
package/lib/basic-auth.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-DVQBjuns.js";
|
|
2
2
|
|
|
3
3
|
//#region ../../plugins/acryl-router/src/core/middleware/basic-auth/index.d.ts
|
|
4
4
|
type MessageFunction = (c: Context) => string | object | Promise<string | object>;
|
package/lib/bearer-auth.d.ts
CHANGED
|
@@ -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-DVQBjuns.js";
|
|
2
2
|
|
|
3
3
|
//#region ../../plugins/acryl-router/src/core/middleware/bearer-auth/index.d.ts
|
|
4
4
|
type MessageFunction = (c: Context) => string | object | Promise<string | object>;
|
package/lib/body-limit.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-DVQBjuns.js";
|
|
2
2
|
|
|
3
3
|
//#region ../../plugins/acryl-router/src/core/middleware/body-limit/index.d.ts
|
|
4
4
|
type OnError = (c: Context) => Response | Promise<Response>;
|
package/lib/cache.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { I as MiddlewareHandler, t as Context } from "./context-DVQBjuns.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-
|
|
2
|
-
import { n as DetailedError, r as hc, t as parseResponse } from "./index-
|
|
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-CQiGmsWW.js";
|
|
2
|
+
import { n as DetailedError, r as hc, t as parseResponse } from "./index-CUTfU69R.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-
|
|
1
|
+
import { I as MiddlewareHandler, t as Context } from "./context-DVQBjuns.js";
|
|
2
2
|
|
|
3
3
|
//#region ../../plugins/acryl-router/src/core/middleware/combine/index.d.ts
|
|
4
4
|
type Condition = (c: Context) => boolean;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
//#region ../../plugins/acryl-router/src/core/helper/css/common.d.ts
|
|
2
|
+
declare const SELECTOR: unique symbol;
|
|
3
|
+
declare const CLASS_NAME: unique symbol;
|
|
4
|
+
declare const STYLE_STRING: unique symbol;
|
|
5
|
+
declare const SELECTORS: unique symbol;
|
|
6
|
+
declare const EXTERNAL_CLASS_NAMES: unique symbol;
|
|
7
|
+
declare const CSS_ESCAPED: unique symbol;
|
|
8
|
+
interface CssClassName {
|
|
9
|
+
[SELECTOR]: string;
|
|
10
|
+
[CLASS_NAME]: string;
|
|
11
|
+
[STYLE_STRING]: string;
|
|
12
|
+
[SELECTORS]: CssClassName[];
|
|
13
|
+
[EXTERNAL_CLASS_NAMES]: string[];
|
|
14
|
+
}
|
|
15
|
+
interface CssEscapedString {
|
|
16
|
+
[CSS_ESCAPED]: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* @experimental
|
|
20
|
+
* `rawCssString` is an experimental feature.
|
|
21
|
+
* The API might be changed.
|
|
22
|
+
*/
|
|
23
|
+
declare const rawCssString: (value: string) => CssEscapedString;
|
|
24
|
+
type CssVariableBasicType = CssClassName | CssEscapedString | string | number | boolean | null | undefined;
|
|
25
|
+
type CssVariableAsyncType = Promise<CssVariableBasicType>;
|
|
26
|
+
type CssVariableArrayType = (CssVariableBasicType | CssVariableAsyncType)[];
|
|
27
|
+
type CssVariableType = CssVariableBasicType | CssVariableAsyncType | CssVariableArrayType;
|
|
28
|
+
/**
|
|
29
|
+
* A function that customizes generated CSS class names.
|
|
30
|
+
*
|
|
31
|
+
* @param hash - The default hash-based class name (e.g. `css-1234567890`)
|
|
32
|
+
* @param label - The comment label extracted from the CSS template, may be empty.
|
|
33
|
+
* Whitespace is trimmed and inner spaces are replaced with hyphens.
|
|
34
|
+
* @param styleString - The minified CSS style string
|
|
35
|
+
* @returns The custom class name to use. Must be a safe CSS identifier;
|
|
36
|
+
* otherwise, the default hash is used as a fallback.
|
|
37
|
+
*/
|
|
38
|
+
type ClassNameSlug = (hash: string, label: string, styleString: string) => string;
|
|
39
|
+
/**
|
|
40
|
+
* A callback function called when an invalid slug is returned from ClassNameSlug.
|
|
41
|
+
*
|
|
42
|
+
* @param slug - The invalid slug
|
|
43
|
+
*/
|
|
44
|
+
type OnInvalidSlug = (slug: string) => void;
|
|
45
|
+
//#endregion
|
|
46
|
+
export { rawCssString as a, OnInvalidSlug as i, CssClassName as n, CssVariableType as r, ClassNameSlug as t };
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import { C as captureRenderContext, E as useContext, d as renderUntrustedObject, i as isUntrustedObject, n as JSXNode, o as jsx, t as Fragment, u as renderChildren, w as createContext } from "./base-ddiVmiE7.js";
|
|
2
|
+
import { HtmlEscapedCallbackPhase, raw, resolveCallback } from "./utils/html.js";
|
|
3
|
+
import { a as DOM_STASH, i as DOM_RENDERER } from "./constants-BR9jM9BC.js";
|
|
4
|
+
import { x as buildDataStack } from "./hooks-Bq5q9IMl.js";
|
|
5
|
+
import { n as Suspense$1, t as ErrorBoundary$1 } from "./components-DYZdxJIJ.js";
|
|
6
|
+
//#region ../../plugins/acryl-router/src/core/jsx/streaming.ts
|
|
7
|
+
/**
|
|
8
|
+
* @module
|
|
9
|
+
* This module enables JSX to supports streaming Response.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Used to specify nonce for scripts generated by `Suspense` and `ErrorBoundary`.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* <StreamingContext.Provider value={{ scriptNonce: 'test-nonce' }}>
|
|
17
|
+
* <Suspense fallback={<p>Loading...</p>}>
|
|
18
|
+
* <Content />
|
|
19
|
+
* </Suspense>
|
|
20
|
+
* </StreamingContext.Provider>
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
const StreamingContext = createContext(null);
|
|
24
|
+
let suspenseCounter = 0;
|
|
25
|
+
const serializeBoundaryChild = (child) => typeof child === "string" || Array.isArray(child) ? renderChildren([child]) : child == null || typeof child === "boolean" ? "" : isUntrustedObject(child) ? renderUntrustedObject(child) : child.toString();
|
|
26
|
+
/**
|
|
27
|
+
* @experimental
|
|
28
|
+
* `Suspense` is an experimental feature.
|
|
29
|
+
* The API might be changed.
|
|
30
|
+
*/
|
|
31
|
+
const Suspense = async ({ children, fallback }) => {
|
|
32
|
+
if (!Array.isArray(children)) children = [children];
|
|
33
|
+
const nonce = useContext(StreamingContext)?.scriptNonce;
|
|
34
|
+
let resArray = [];
|
|
35
|
+
const stackNode = { [DOM_STASH]: [0, []] };
|
|
36
|
+
const popNodeStack = () => {
|
|
37
|
+
buildDataStack.pop();
|
|
38
|
+
};
|
|
39
|
+
try {
|
|
40
|
+
stackNode[DOM_STASH][0] = 0;
|
|
41
|
+
buildDataStack.push([[], stackNode]);
|
|
42
|
+
resArray = children.map(serializeBoundaryChild);
|
|
43
|
+
} catch (e) {
|
|
44
|
+
if (e instanceof Promise) {
|
|
45
|
+
const resume = captureRenderContext();
|
|
46
|
+
resArray = [e.then(() => resume(() => {
|
|
47
|
+
stackNode[DOM_STASH][0] = 0;
|
|
48
|
+
buildDataStack.push([[], stackNode]);
|
|
49
|
+
return childrenToString(children).finally(popNodeStack);
|
|
50
|
+
}))];
|
|
51
|
+
} else throw e;
|
|
52
|
+
} finally {
|
|
53
|
+
popNodeStack();
|
|
54
|
+
}
|
|
55
|
+
if (resArray.some((res) => res instanceof Promise)) {
|
|
56
|
+
const index = suspenseCounter++;
|
|
57
|
+
const fallbackStr = await (typeof fallback === "string" || Array.isArray(fallback) ? renderChildren([fallback]) : isUntrustedObject(fallback) ? renderUntrustedObject(fallback) : fallback.toString());
|
|
58
|
+
return raw(`<template id="H:${index}"></template>${fallbackStr}<!--/$-->`, [...fallbackStr.callbacks || [], ({ phase, buffer, context }) => {
|
|
59
|
+
if (phase === HtmlEscapedCallbackPhase.BeforeStream) return;
|
|
60
|
+
return Promise.all(resArray).then(async (htmlArray) => {
|
|
61
|
+
htmlArray = htmlArray.flat();
|
|
62
|
+
const content = htmlArray.join("");
|
|
63
|
+
if (buffer) buffer[0] = buffer[0].replace(new RegExp(`<template id="H:${index}"></template>.*?<!--/\\$-->`, "s"), () => content);
|
|
64
|
+
let html = buffer ? "" : `<template data-acryl-target="H:${index}">${content}</template><script${nonce ? ` nonce="${nonce}"` : ""}>
|
|
65
|
+
((d,c,n) => {
|
|
66
|
+
c=d.currentScript.previousSibling
|
|
67
|
+
d=d.getElementById('H:${index}')
|
|
68
|
+
if(!d)return
|
|
69
|
+
do{n=d.nextSibling;n.remove()}while(n.nodeType!=8||n.nodeValue!='/$')
|
|
70
|
+
d.replaceWith(c.content)
|
|
71
|
+
})(document)
|
|
72
|
+
<\/script>`;
|
|
73
|
+
const callbacks = htmlArray.map((html) => html.callbacks || []).flat();
|
|
74
|
+
if (!callbacks.length) return html;
|
|
75
|
+
if (phase === HtmlEscapedCallbackPhase.Stream) html = await resolveCallback(html, HtmlEscapedCallbackPhase.BeforeStream, true, context);
|
|
76
|
+
return raw(html, callbacks);
|
|
77
|
+
});
|
|
78
|
+
}]);
|
|
79
|
+
} else return raw(resArray.join(""));
|
|
80
|
+
};
|
|
81
|
+
Suspense[DOM_RENDERER] = Suspense$1;
|
|
82
|
+
const textEncoder = new TextEncoder();
|
|
83
|
+
/**
|
|
84
|
+
* @experimental
|
|
85
|
+
* `renderToReadableStream()` is an experimental feature.
|
|
86
|
+
* The API might be changed.
|
|
87
|
+
*/
|
|
88
|
+
const renderToReadableStream = (content, onError = console.trace) => {
|
|
89
|
+
let cancelled = false;
|
|
90
|
+
return new ReadableStream({
|
|
91
|
+
async start(controller) {
|
|
92
|
+
try {
|
|
93
|
+
if (content instanceof JSXNode) content = content.toString();
|
|
94
|
+
const context = typeof content === "object" ? content : {};
|
|
95
|
+
const resolved = await resolveCallback(content, HtmlEscapedCallbackPhase.BeforeStream, true, context);
|
|
96
|
+
if (!cancelled) controller.enqueue(textEncoder.encode(resolved));
|
|
97
|
+
let resolvedCount = 0;
|
|
98
|
+
const callbacks = [];
|
|
99
|
+
const then = (promise) => {
|
|
100
|
+
callbacks.push(promise.catch((err) => {
|
|
101
|
+
console.log(err);
|
|
102
|
+
onError(err);
|
|
103
|
+
return "";
|
|
104
|
+
}).then(async (res) => {
|
|
105
|
+
res = await resolveCallback(res, HtmlEscapedCallbackPhase.BeforeStream, true, context);
|
|
106
|
+
res.callbacks?.map((c) => c({
|
|
107
|
+
phase: HtmlEscapedCallbackPhase.Stream,
|
|
108
|
+
context
|
|
109
|
+
})).filter(Boolean).forEach(then);
|
|
110
|
+
resolvedCount++;
|
|
111
|
+
if (!cancelled) controller.enqueue(textEncoder.encode(res));
|
|
112
|
+
}));
|
|
113
|
+
};
|
|
114
|
+
resolved.callbacks?.map((c) => c({
|
|
115
|
+
phase: HtmlEscapedCallbackPhase.Stream,
|
|
116
|
+
context
|
|
117
|
+
})).filter(Boolean).forEach(then);
|
|
118
|
+
while (resolvedCount !== callbacks.length) await Promise.all(callbacks);
|
|
119
|
+
} catch (e) {
|
|
120
|
+
onError(e);
|
|
121
|
+
}
|
|
122
|
+
if (!cancelled) controller.close();
|
|
123
|
+
},
|
|
124
|
+
cancel() {
|
|
125
|
+
cancelled = true;
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
};
|
|
129
|
+
//#endregion
|
|
130
|
+
//#region ../../plugins/acryl-router/src/core/jsx/components.ts
|
|
131
|
+
let errorBoundaryCounter = 0;
|
|
132
|
+
const childrenToString = async (children) => {
|
|
133
|
+
try {
|
|
134
|
+
return children.flat().map(resolveChildEarly);
|
|
135
|
+
} catch (e) {
|
|
136
|
+
if (e instanceof Promise) {
|
|
137
|
+
const resume = captureRenderContext();
|
|
138
|
+
await e;
|
|
139
|
+
return resume(() => childrenToString(children));
|
|
140
|
+
} else throw e;
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
const resolveChildEarly = (child) => {
|
|
144
|
+
if (child == null || typeof child === "boolean") return "";
|
|
145
|
+
else if (typeof child === "string" || Array.isArray(child)) return renderChildren([child]);
|
|
146
|
+
else if (isUntrustedObject(child)) return renderUntrustedObject(child);
|
|
147
|
+
else {
|
|
148
|
+
const str = child.toString();
|
|
149
|
+
return str instanceof Promise ? str : raw(str);
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
/**
|
|
153
|
+
* @experimental
|
|
154
|
+
* `ErrorBoundary` is an experimental feature.
|
|
155
|
+
* The API might be changed.
|
|
156
|
+
*/
|
|
157
|
+
const ErrorBoundary = async ({ children, fallback, fallbackRender, onError }) => {
|
|
158
|
+
if (!children) return raw("");
|
|
159
|
+
if (!Array.isArray(children)) children = [children];
|
|
160
|
+
const nonce = useContext(StreamingContext)?.scriptNonce;
|
|
161
|
+
let resume;
|
|
162
|
+
const getResume = () => resume ||= captureRenderContext();
|
|
163
|
+
let fallbackStrPromise;
|
|
164
|
+
const resolveFallbackStr = () => fallbackStrPromise ||= (async () => {
|
|
165
|
+
const awaitedFallback = await fallback;
|
|
166
|
+
if (awaitedFallback === null || awaitedFallback === void 0) return;
|
|
167
|
+
if (typeof awaitedFallback === "string" || Array.isArray(awaitedFallback)) return getResume()(() => renderChildren([awaitedFallback]));
|
|
168
|
+
if (isUntrustedObject(awaitedFallback)) return getResume()(() => renderUntrustedObject(awaitedFallback));
|
|
169
|
+
const fallbackResult = await getResume()(() => awaitedFallback.toString());
|
|
170
|
+
return raw(fallbackResult, fallbackResult.callbacks || awaitedFallback.callbacks);
|
|
171
|
+
})();
|
|
172
|
+
const renderFallback = async (error) => {
|
|
173
|
+
const fallbackStr = await resolveFallbackStr();
|
|
174
|
+
return getResume()(async () => {
|
|
175
|
+
onError?.(error);
|
|
176
|
+
const fallbackRes = fallbackStr !== void 0 ? fallbackStr : fallbackRender && jsx(Fragment, {}, fallbackRender(error)) || "";
|
|
177
|
+
const fallbackResString = await Fragment({ children: fallbackRes }).toString();
|
|
178
|
+
return raw(fallbackResString, fallbackResString.callbacks || fallbackRes.callbacks);
|
|
179
|
+
});
|
|
180
|
+
};
|
|
181
|
+
let resArray = [];
|
|
182
|
+
try {
|
|
183
|
+
resArray = children.map(resolveChildEarly);
|
|
184
|
+
} catch (e) {
|
|
185
|
+
const resume = getResume();
|
|
186
|
+
if (e instanceof Promise) resArray = [e.then(() => resume(() => childrenToString(children))).catch((e) => renderFallback(e))];
|
|
187
|
+
else resArray = [await renderFallback(e)];
|
|
188
|
+
}
|
|
189
|
+
if (resArray.some((res) => res instanceof Promise)) {
|
|
190
|
+
getResume();
|
|
191
|
+
const index = errorBoundaryCounter++;
|
|
192
|
+
const replaceRe = RegExp(`(<template id="E:${index}"></template>)(.*?)(<!--E:${index}-->)`, "s");
|
|
193
|
+
let caught = false;
|
|
194
|
+
const catchCallback = async ({ error, buffer }) => {
|
|
195
|
+
if (caught) return "";
|
|
196
|
+
caught = true;
|
|
197
|
+
const fallbackResString = await renderFallback(error);
|
|
198
|
+
const fallbackCallbacks = fallbackResString.callbacks;
|
|
199
|
+
if (buffer) {
|
|
200
|
+
buffer[0] = buffer[0].replace(replaceRe, () => fallbackResString);
|
|
201
|
+
return fallbackCallbacks?.length ? raw("", fallbackCallbacks) : "";
|
|
202
|
+
}
|
|
203
|
+
return raw(`<template data-acryl-target="E:${index}">${fallbackResString}</template><script>
|
|
204
|
+
((d,c,n) => {
|
|
205
|
+
c=d.currentScript.previousSibling
|
|
206
|
+
d=d.getElementById('E:${index}')
|
|
207
|
+
if(!d)return
|
|
208
|
+
do{n=d.nextSibling;n.remove()}while(n.nodeType!=8||n.nodeValue!='E:${index}')
|
|
209
|
+
d.replaceWith(c.content)
|
|
210
|
+
})(document)
|
|
211
|
+
<\/script>`, fallbackCallbacks);
|
|
212
|
+
};
|
|
213
|
+
let error;
|
|
214
|
+
const promiseAll = Promise.all(resArray).catch((e) => error = e);
|
|
215
|
+
return raw(`<template id="E:${index}"></template><!--E:${index}-->`, [({ phase, buffer, context }) => {
|
|
216
|
+
if (phase === HtmlEscapedCallbackPhase.BeforeStream) return;
|
|
217
|
+
return promiseAll.then(async (htmlArray) => {
|
|
218
|
+
if (error) throw error;
|
|
219
|
+
htmlArray = htmlArray.flat();
|
|
220
|
+
const content = htmlArray.join("");
|
|
221
|
+
let html = buffer ? "" : `<template data-acryl-target="E:${index}">${content}</template><script${nonce ? ` nonce="${nonce}"` : ""}>
|
|
222
|
+
((d,c) => {
|
|
223
|
+
c=d.currentScript.previousSibling
|
|
224
|
+
d=d.getElementById('E:${index}')
|
|
225
|
+
if(!d)return
|
|
226
|
+
d.parentElement.insertBefore(c.content,d.nextSibling)
|
|
227
|
+
})(document)
|
|
228
|
+
<\/script>`;
|
|
229
|
+
if (htmlArray.every((html) => !html.callbacks?.length)) {
|
|
230
|
+
if (buffer) buffer[0] = buffer[0].replace(replaceRe, () => content);
|
|
231
|
+
return html;
|
|
232
|
+
}
|
|
233
|
+
if (buffer) buffer[0] = buffer[0].replace(replaceRe, (_all, pre, _, post) => `${pre}${content}${post}`);
|
|
234
|
+
const callbacks = htmlArray.map((html) => html.callbacks || []).flat();
|
|
235
|
+
if (phase === HtmlEscapedCallbackPhase.Stream) html = await resolveCallback(html, HtmlEscapedCallbackPhase.BeforeStream, true, context);
|
|
236
|
+
let resolvedCount = 0;
|
|
237
|
+
const promises = callbacks.map((c) => (...args) => c(...args)?.then((content) => {
|
|
238
|
+
resolvedCount++;
|
|
239
|
+
if (buffer) {
|
|
240
|
+
if (resolvedCount === callbacks.length) buffer[0] = buffer[0].replace(replaceRe, (_all, _pre, content) => content);
|
|
241
|
+
buffer[0] += content;
|
|
242
|
+
return raw("", content.callbacks);
|
|
243
|
+
}
|
|
244
|
+
return raw(content + (resolvedCount !== callbacks.length ? "" : `<script>
|
|
245
|
+
((d,c,n) => {
|
|
246
|
+
d=d.getElementById('E:${index}')
|
|
247
|
+
if(!d)return
|
|
248
|
+
n=d.nextSibling
|
|
249
|
+
while(n.nodeType!=8||n.nodeValue!='E:${index}'){n=n.nextSibling}
|
|
250
|
+
n.remove()
|
|
251
|
+
d.remove()
|
|
252
|
+
})(document)
|
|
253
|
+
<\/script>`), content.callbacks);
|
|
254
|
+
}).catch((error) => catchCallback({
|
|
255
|
+
error,
|
|
256
|
+
buffer
|
|
257
|
+
})));
|
|
258
|
+
return raw(html, promises);
|
|
259
|
+
}).catch((error) => catchCallback({
|
|
260
|
+
error,
|
|
261
|
+
buffer
|
|
262
|
+
}));
|
|
263
|
+
}]);
|
|
264
|
+
} else return Fragment({ children: resArray });
|
|
265
|
+
};
|
|
266
|
+
ErrorBoundary[DOM_RENDERER] = ErrorBoundary$1;
|
|
267
|
+
//#endregion
|
|
268
|
+
export { renderToReadableStream as i, StreamingContext as n, Suspense as r, ErrorBoundary as t };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { t as DOM_ERROR_HANDLER } from "./constants-BR9jM9BC.js";
|
|
2
|
+
import { t as Fragment } from "./jsx-dev-runtime-kAhR_4C7.js";
|
|
3
|
+
import "./jsx/dom/jsx-runtime.js";
|
|
4
|
+
//#region ../../plugins/acryl-router/src/core/jsx/dom/components.ts
|
|
5
|
+
const ErrorBoundary = (({ children, fallback, fallbackRender, onError }) => {
|
|
6
|
+
const res = Fragment({ children });
|
|
7
|
+
res[DOM_ERROR_HANDLER] = (err) => {
|
|
8
|
+
if (err instanceof Promise) throw err;
|
|
9
|
+
onError?.(err);
|
|
10
|
+
return fallbackRender?.(err) || fallback;
|
|
11
|
+
};
|
|
12
|
+
return res;
|
|
13
|
+
});
|
|
14
|
+
const Suspense = (({ children, fallback }) => {
|
|
15
|
+
const res = Fragment({ children });
|
|
16
|
+
res[DOM_ERROR_HANDLER] = (err, retry) => {
|
|
17
|
+
if (!(err instanceof Promise)) throw err;
|
|
18
|
+
err.finally(retry);
|
|
19
|
+
return fallback;
|
|
20
|
+
};
|
|
21
|
+
return res;
|
|
22
|
+
});
|
|
23
|
+
//#endregion
|
|
24
|
+
export { Suspense as n, ErrorBoundary as t };
|
package/lib/compress.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { I as MiddlewareHandler } from "./context-
|
|
1
|
+
import { I as MiddlewareHandler } from "./context-DVQBjuns.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-
|
|
2
|
-
import { i as NetAddrInfo, n as ConnInfo, r as GetConnInfo, t as AddressType } from "./types-
|
|
1
|
+
import { t as Context } from "./context-DVQBjuns.js";
|
|
2
|
+
import { i as NetAddrInfo, n as ConnInfo, r as GetConnInfo, t as AddressType } from "./types-nEL8VPDC.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. */
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region ../../plugins/acryl-router/src/core/jsx/constants.ts
|
|
2
|
+
const DOM_RENDERER = Symbol("RENDERER");
|
|
3
|
+
const DOM_ERROR_HANDLER = Symbol("ERROR_HANDLER");
|
|
4
|
+
const DOM_STASH = Symbol("STASH");
|
|
5
|
+
const DOM_INTERNAL_TAG = Symbol("INTERNAL");
|
|
6
|
+
const DOM_MEMO = Symbol("MEMO");
|
|
7
|
+
const PERMALINK = Symbol("PERMALINK");
|
|
8
|
+
//#endregion
|
|
9
|
+
export { DOM_STASH as a, DOM_RENDERER as i, DOM_INTERNAL_TAG as n, PERMALINK as o, DOM_MEMO as r, DOM_ERROR_HANDLER as t };
|
|
@@ -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 {
|
|
4
|
+
import { D as UnionToIntersection, S as RemoveBlankRecord, f as InvalidJSONValue, g as JSONParsed, p as IsAny, u as IfAnyThenEmptyObject, v as JSONValue, w as Simplify } from "./types-Lqx5BxQF.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
|