acrylblends 1.0.3 → 1.0.5
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/docs/framework/agents/index.md +6 -4
- package/docs/framework/workshop/README.md +3 -3
- package/docs/framework/workshop/facilitator.md +1 -0
- package/lib/accept-CNNHu4Cf.js +193 -0
- package/lib/{accepts-XBuZPVRI.js → accepts-Btq83xPd.js} +1 -1
- package/lib/accepts.js +1 -1
- package/lib/acryl-base.js +1 -331
- package/lib/adapter-CaZ6FZUU.js +37 -0
- package/lib/adapter.js +1 -36
- package/lib/{app-BM0rTCp7.js → app-CQcGWjrk.js} +4 -4
- package/lib/app-base-CpRMZL4v.js +332 -0
- package/lib/{audit-BXnYsLge.d.ts → audit-D5z9uwOP.d.ts} +14 -1
- package/lib/{base-NSN_SNv-.js → base-D_6kfOr-.js} +1 -1
- package/lib/basic-auth-C0HTRpXh.js +20 -0
- package/lib/basic-auth-DFLflXNe.js +95 -0
- package/lib/basic-auth.js +1 -94
- package/lib/bearer-auth-Cwxt-vgS.js +94 -0
- package/lib/bearer-auth.js +1 -93
- package/lib/body-D7f4e7w_.js +94 -0
- package/lib/body-limit-WmIjWRLt.js +66 -0
- package/lib/body-limit.js +1 -65
- package/lib/buffer-CkEOJCcY.js +51 -0
- package/lib/bun.js +3 -3
- package/lib/cache-B0bHH7s5.js +169 -0
- package/lib/cache.js +1 -168
- package/lib/{client-DDLXwhBo.js → client-BrMFnMEd.js} +1 -1
- package/lib/{client-modules-CLvWOjbd.js → client-modules-drj4mjhj.js} +4 -4
- package/lib/client.js +1 -1
- package/lib/color-COa3DplO.js +37 -0
- package/lib/combine-TWuGdcbC.js +137 -0
- package/lib/combine.js +1 -136
- package/lib/{components-cEW3ovK0.js → components-B2ka9Ax1.js} +4 -4
- package/lib/{components-JXVm45kK.js → components-PVXwaOaC.js} +2 -2
- package/lib/compress-BzWqsHF1.js +79 -0
- package/lib/compress-C-9vK4B2.d.ts +11 -0
- package/lib/compress-DCyrrQ5D.js +11 -0
- package/lib/compress.d.ts +1 -1
- package/lib/compress.js +2 -78
- package/lib/concurrent-DrF3d2c-.js +30 -0
- package/lib/conninfo-BCROmdnf.d.ts +11 -0
- package/lib/conninfo-CWJwieh4.js +19 -0
- package/lib/constants-CBSEudrb.js +7 -0
- package/lib/{context-DDO0cfuP.js → context-CkOh7Ygv.js} +2 -2
- package/lib/context-storage-iuPoI_CR.js +52 -0
- package/lib/context-storage.js +1 -51
- package/lib/cookie-B1LlkzOe.js +125 -0
- package/lib/cookie-BHIduy2T.js +82 -0
- package/lib/cookie.js +1 -81
- package/lib/cordis/db-sqlite.d.ts +1 -1
- package/lib/cordis/door.d.ts +17 -3
- package/lib/cordis/door.js +123 -16
- package/lib/cordis/inspect.js +4 -4
- package/lib/cordis/kv-db.d.ts +1 -1
- package/lib/cordis/kv-db.js +1 -1
- package/lib/cordis/kv-json.d.ts +1 -1
- package/lib/cordis/kv-json.js +1 -1
- package/lib/cordis/node-server.d.ts +1 -1
- package/lib/cordis/node-server.js +3 -116
- package/lib/cordis/router-http.d.ts +1 -1
- package/lib/cordis/router-http.js +2 -2
- package/lib/cordis/router.d.ts +1 -1
- package/lib/cordis/router.js +4 -4
- package/lib/cordis/state.js +7 -7
- package/lib/{core-CaY8XDZ6.js → core-BOu1jYua.js} +1 -1
- package/lib/cors-CbAQ-8qU.js +106 -0
- package/lib/cors.js +1 -105
- package/lib/crypto-iVP-N-tS.js +34 -0
- package/lib/csrf-DqqOZtgy.js +101 -0
- package/lib/csrf.js +1 -100
- package/lib/css-C5CPVMvM.js +134 -0
- package/lib/css.js +2 -133
- package/lib/db/sqlite.d.ts +1 -25
- package/lib/dev-CLgu-JRe.js +50 -0
- package/lib/dev.js +1 -49
- package/lib/dom-YjND9Jt3.js +74 -0
- package/lib/door/host.d.ts +2 -2
- package/lib/door/host.js +1 -1
- package/lib/door/page.d.ts +12 -1
- package/lib/door/page.js +22 -1
- package/lib/door/protocol.d.ts +2 -2
- package/lib/door/protocol.js +2 -197
- package/lib/encode-BhbNLrjp.js +33 -0
- package/lib/factory-CLdSf-xS.js +30 -0
- package/lib/factory.js +1 -29
- package/lib/handler-C0wZ0KwO.js +12 -0
- package/lib/helpers-BEjcdbgw.js +5 -0
- package/lib/{hooks-w72iLeFR.js → hooks-CfC07ri0.js} +1 -1
- package/lib/html-CgNa89xw.js +31 -0
- package/lib/html-DGExBFNg.js +103 -0
- package/lib/html.d.ts +2 -5
- package/lib/html.js +2 -30
- package/lib/http-exception-MjWkT89V.js +54 -0
- package/lib/http-exception.js +1 -53
- package/lib/{index-D4nVR3wu.d.ts → index-DMOtA-NJ.d.ts} +7 -1
- package/lib/index-dAzQsJG9.d.ts +6 -0
- package/lib/index.js +3 -3
- package/lib/ip-restriction-jKtKCRM_.js +166 -0
- package/lib/ip-restriction.js +1 -165
- package/lib/ipaddr-DCoIo528.js +238 -0
- package/lib/jsx/dom/client.js +1 -1
- package/lib/jsx/dom/jsx-dev-runtime.js +1 -1
- package/lib/jsx/dom/jsx-runtime.js +2 -1
- package/lib/jsx/dom/server.js +3 -3
- package/lib/jsx/dom.js +5 -73
- package/lib/jsx/jsx-dev-runtime.d.ts +2 -5
- package/lib/jsx/jsx-dev-runtime.js +2 -13
- package/lib/jsx/jsx-runtime.d.ts +2 -2
- package/lib/jsx/jsx-runtime.js +4 -4
- package/lib/jsx/streaming.js +1 -1
- package/lib/jsx-CUQgttxU.js +47 -0
- package/lib/jsx-dev-runtime-B4WTyq8r.js +14 -0
- package/lib/{jsx-dev-runtime-CWLRA2F3.js → jsx-dev-runtime-BLfA-EhI.js} +2 -2
- package/lib/jsx-dev-runtime-CGt4kNYr.d.ts +6 -0
- package/lib/jsx-renderer-CfifM4hT.js +99 -0
- package/lib/jsx-renderer.js +1 -98
- package/lib/jsx-runtime-COCRWBJ9.js +2 -0
- package/lib/jsx.js +5 -46
- package/lib/{jwk-LkzeoaU8.js → jwk-CDPpYQpD.js} +3 -3
- package/lib/jwk.js +1 -1
- package/lib/{jwt-BGJBw5AF.js → jwt-BXoIA2fQ.js} +2 -2
- package/lib/{jwt-CskdhEW9.js → jwt-lyS4Q3mT.js} +3 -3
- package/lib/jwt.js +2 -2
- package/lib/kv/db.d.ts +1 -10
- package/lib/kv/db.js +1 -56
- package/lib/kv/json.d.ts +1 -9
- package/lib/kv/json.js +1 -223
- package/lib/{language-D9a4zqvn.js → language-DeGRtLJt.js} +2 -2
- package/lib/language.js +1 -1
- package/lib/{linear-router-C3FPib6h.js → linear-router-CmZn_JLV.js} +2 -2
- package/lib/logger-Ckxu8diz.js +54 -0
- package/lib/logger.js +1 -53
- package/lib/loopback-only-BbasoF7R.js +90 -0
- package/lib/loopback-only.js +1 -89
- package/lib/method-not-allowed-TO2_hnfl.js +82 -0
- package/lib/method-not-allowed.js +1 -81
- package/lib/method-override-DnZKfJbV.js +103 -0
- package/lib/method-override.js +1 -102
- package/lib/middleware-BfG_fp8P.js +12 -0
- package/lib/mime-BnScXkQn.js +77 -0
- package/lib/mount-QkK_3NtJ.js +67 -0
- package/lib/mount.js +1 -66
- package/lib/node-server/conninfo.d.ts +1 -10
- package/lib/node-server/conninfo.js +1 -18
- package/lib/node-server/register.js +25 -2
- package/lib/node-server/serve-static.d.ts +1 -17
- package/lib/node-server/serve-static.js +1 -1
- package/lib/node-server.d.ts +2 -2
- package/lib/node-server.js +4 -4
- package/lib/open-BqK4D2Wn.d.ts +11 -0
- package/lib/open-But9E2rL.js +57 -0
- package/lib/open-CULVJgOc.d.ts +12 -0
- package/lib/open-Dp4sxspc.js +224 -0
- package/lib/open-T7kgbO2O.d.ts +27 -0
- package/lib/{pattern-router-HZxjDGEQ.js → pattern-router-CJBecJBd.js} +1 -1
- package/lib/powered-by-CXQNjNIX.js +24 -0
- package/lib/powered-by.js +1 -23
- package/lib/pretty-json-CeC1yvYt.js +39 -0
- package/lib/pretty-json.js +1 -38
- package/lib/{protocol-BizVt4J6.d.ts → protocol-C37gPePD.d.ts} +9 -2
- package/lib/protocol-Dt0AZBOz.js +213 -0
- package/lib/proxy-C2w_mH7k.js +121 -0
- package/lib/proxy.js +1 -120
- package/lib/quick.js +4 -4
- package/lib/{reg-exp-router-DC1R3qoY.js → reg-exp-router-C_WV84eV.js} +2 -2
- package/lib/request-DvMgGtlW.js +323 -0
- package/lib/request.js +1 -322
- package/lib/route-D8m-a2I1.js +126 -0
- package/lib/route.js +1 -125
- package/lib/router/linear-router.js +1 -1
- package/lib/router/pattern-router.js +1 -1
- package/lib/router/reg-exp-router.js +1 -1
- package/lib/router/smart-router.js +1 -1
- package/lib/router/trie-router.js +1 -1
- package/lib/router-Be_o6nFu.js +35 -0
- package/lib/router.js +1 -34
- package/lib/schema-validator-EK3cUUCt.js +22 -0
- package/lib/schema-validator.js +1 -21
- package/lib/{secure-headers-mP3j6Hm6.js → secure-headers-C5ZOcXqk.js} +1 -1
- package/lib/secure-headers.js +1 -1
- package/lib/serve-static-B7sqnftW.d.ts +18 -0
- package/lib/{serve-static-3uo_9rjF.js → serve-static-C1Nkj_xB.js} +2 -2
- package/lib/{serve-static-Cp5adzGo.js → serve-static-EiJf1zkO.js} +4 -4
- package/lib/serve-static.js +1 -1
- package/lib/{smart-router-C5CZ5XSM.js → smart-router-BjxkDQCE.js} +1 -1
- package/lib/{snapshot-text-DmE0YfeZ.js → snapshot-text-Bbx43mN0.js} +57 -9
- package/lib/{src-2Z4mJg0x.js → src-BTBm4OPD.js} +22 -6
- package/lib/src-LX0E4ec4.js +117 -0
- package/lib/{ssg-BwjcA-Ge.js → ssg-BEl7MHqg.js} +5 -5
- package/lib/ssg.js +1 -1
- package/lib/stream-CzM_SHkq.js +88 -0
- package/lib/{streaming-DHST3Scg.js → streaming-BlDaph8U.js} +3 -3
- package/lib/streaming.js +1 -1
- package/lib/{test-websocket-D8WWqE5G.js → test-websocket-BLeEvybj.js} +2 -2
- package/lib/testing-BQx5T_UX.js +17 -0
- package/lib/testing.js +1 -16
- package/lib/timeout-FeqZ9A-0.js +42 -0
- package/lib/timeout.js +1 -41
- package/lib/tiny.js +2 -2
- package/lib/trailing-slash-DwTx-1sk.js +85 -0
- package/lib/trailing-slash.js +1 -84
- package/lib/{trie-router-CfFbapzL.js → trie-router-JydLKUa2.js} +2 -2
- package/lib/url-BPh4d6j-.js +197 -0
- package/lib/utils/accept.js +1 -192
- package/lib/utils/basic-auth.js +1 -19
- package/lib/utils/body.js +1 -93
- package/lib/utils/buffer.js +1 -50
- package/lib/utils/color.js +1 -36
- package/lib/utils/compress.d.ts +1 -10
- package/lib/utils/compress.js +1 -10
- package/lib/utils/concurrent.js +1 -29
- package/lib/utils/constants.js +1 -6
- package/lib/utils/cookie.js +1 -124
- package/lib/utils/crypto.js +1 -33
- package/lib/utils/encode.js +1 -32
- package/lib/utils/handler.js +1 -11
- package/lib/utils/html.js +1 -102
- package/lib/utils/ipaddr.js +1 -237
- package/lib/utils/jwt.js +1 -1
- package/lib/utils/mime.js +1 -76
- package/lib/utils/stream.js +1 -87
- package/lib/utils/url.js +1 -196
- package/lib/{validator-D84mq-dO.js → validator-Btiyt5VJ.js} +3 -3
- package/lib/validator.js +1 -1
- package/lib/websocket-DsyBIKVA.js +56 -0
- package/lib/ws.js +1 -55
- package/package.json +1 -1
- package/plugins/acryl-door/src/cli/acryl.ts +5 -3
- package/plugins/acryl-door/src/host/channel.ts +36 -0
- package/plugins/acryl-door/src/host/chat-tools.ts +2 -0
- package/plugins/acryl-door/src/host/door.ts +44 -5
- package/plugins/acryl-door/src/host/shim.ts +23 -0
- package/plugins/acryl-door/src/host/verbs.ts +4 -3
- package/plugins/acryl-door/src/index.ts +39 -3
- package/plugins/acryl-door/src/page/driver/driver.ts +22 -1
- package/plugins/acryl-door/src/page/protocol.ts +13 -2
- package/plugins/acryl-node-server/src/register.ts +29 -2
- package/plugins/acryl-router/src/service.ts +19 -1
- package/plugins/agent/model.ts +6 -1
- package/plugins/agent/tools.ts +12 -2
- package/plugins/agent-panel/client/describe.ts +44 -0
- package/plugins/agent-panel/client/main.ts +67 -35
- package/plugins/agent-panel/index.ts +137 -35
- package/plugins/desktop/attach.ts +72 -0
- package/plugins/desktop/main.ts +17 -4
- package/plugins/extensions/index.ts +3 -4
- package/plugins/extensions/stage.ts +33 -5
- package/plugins/openai/index.ts +1 -1
- package/shared/DEFAULTS.md +4 -0
- package/templates/agent/AGENTS.md +2 -0
- package/templates/agent/blend.yaml +4 -1
- package/templates/agent/src/app.ts +2 -0
- package/templates/agent/src/routes.ts +1 -1
- package/templates/agent/template.json +1 -0
- package/templates/agent/test/builder.test.ts +26 -21
- package/lib/helpers-CvTauQT5.js +0 -5
- package/lib/middleware-CPQ8himN.js +0 -12
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { t as GET_MATCH_RESULT } from "./constants-Dy7ZvN1H.js";
|
|
2
|
+
import { a as getPattern, d as splitRoutingPath } from "./url-BPh4d6j-.js";
|
|
3
|
+
//#region ../../plugins/acryl-router/src/core/helper/route/index.ts
|
|
4
|
+
/**
|
|
5
|
+
* Get matched routes in the handler
|
|
6
|
+
*
|
|
7
|
+
* @param {Context} c - The context object
|
|
8
|
+
* @returns An array of matched routes
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { matchedRoutes } from 'acrylblends/route'
|
|
13
|
+
*
|
|
14
|
+
* app.use('*', async function logger(c, next) {
|
|
15
|
+
* await next()
|
|
16
|
+
* matchedRoutes(c).forEach(({ handler, method, path }, i) => {
|
|
17
|
+
* const name = handler.name || (handler.length < 2 ? '[handler]' : '[middleware]')
|
|
18
|
+
* console.log(
|
|
19
|
+
* method,
|
|
20
|
+
* ' ',
|
|
21
|
+
* path,
|
|
22
|
+
* ' '.repeat(Math.max(10 - path.length, 0)),
|
|
23
|
+
* name,
|
|
24
|
+
* i === c.req.routeIndex ? '<- respond from here' : ''
|
|
25
|
+
* )
|
|
26
|
+
* })
|
|
27
|
+
* })
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
const matchedRoutes = (c) => c.req[GET_MATCH_RESULT][0].map(([[, route]]) => route);
|
|
31
|
+
/**
|
|
32
|
+
* Get the route path registered within the handler
|
|
33
|
+
*
|
|
34
|
+
* @param {Context} c - The context object
|
|
35
|
+
* @param {number} index - The index of the route from which to retrieve the path, similar to Array.prototype.at(), where a negative number is the index counted from the end of the matching route. Defaults to the current route index.
|
|
36
|
+
* @returns The route path registered within the handler
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* import { routePath } from 'acrylblends/route'
|
|
41
|
+
*
|
|
42
|
+
* app.use('*', (c, next) => {
|
|
43
|
+
* console.log(routePath(c)) // '*'
|
|
44
|
+
* console.log(routePath(c, -1)) // '/posts/:id'
|
|
45
|
+
* return next()
|
|
46
|
+
* })
|
|
47
|
+
*
|
|
48
|
+
* app.get('/posts/:id', (c) => {
|
|
49
|
+
* return c.text(routePath(c)) // '/posts/:id'
|
|
50
|
+
* })
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
const routePath = (c, index) => matchedRoutes(c).at(index ?? c.req.routeIndex)?.path ?? "";
|
|
54
|
+
/**
|
|
55
|
+
* Get the basePath of the as-is route specified by routing.
|
|
56
|
+
*
|
|
57
|
+
* @param {Context} c - The context object
|
|
58
|
+
* @param {number} index - The index of the route from which to retrieve the path, similar to Array.prototype.at(), where a negative number is the index counted from the end of the matching route. Defaults to the current route index.
|
|
59
|
+
* @returns The basePath of the as-is route specified by routing.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* import { baseRoutePath } from 'acrylblends/route'
|
|
64
|
+
*
|
|
65
|
+
* const app = new Acryl()
|
|
66
|
+
*
|
|
67
|
+
* const subApp = new Acryl()
|
|
68
|
+
* subApp.get('/posts/:id', (c) => {
|
|
69
|
+
* return c.text(baseRoutePath(c)) // '/:sub'
|
|
70
|
+
* })
|
|
71
|
+
*
|
|
72
|
+
* app.route('/:sub', subApp)
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
const baseRoutePath = (c, index) => matchedRoutes(c).at(index ?? c.req.routeIndex)?.basePath ?? "";
|
|
76
|
+
/**
|
|
77
|
+
* Get the basePath with embedded parameters
|
|
78
|
+
*
|
|
79
|
+
* @param {Context} c - The context object
|
|
80
|
+
* @param {number} index - The index of the route from which to retrieve the path, similar to Array.prototype.at(), where a negative number is the index counted from the end of the matching route. Defaults to the current route index.
|
|
81
|
+
* @returns The basePath with embedded parameters.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```ts
|
|
85
|
+
* import { basePath } from 'acrylblends/route'
|
|
86
|
+
*
|
|
87
|
+
* const app = new Acryl()
|
|
88
|
+
*
|
|
89
|
+
* const subApp = new Acryl()
|
|
90
|
+
* subApp.get('/posts/:id', (c) => {
|
|
91
|
+
* return c.text(basePath(c)) // '/requested-sub-app-path'
|
|
92
|
+
* })
|
|
93
|
+
*
|
|
94
|
+
* app.route('/:sub', subApp)
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
const basePathCacheMap = /* @__PURE__ */ new WeakMap();
|
|
98
|
+
const basePath = (c, index) => {
|
|
99
|
+
index ??= c.req.routeIndex;
|
|
100
|
+
const cache = basePathCacheMap.get(c) || [];
|
|
101
|
+
if (typeof cache[index] === "string") return cache[index];
|
|
102
|
+
let result;
|
|
103
|
+
const rp = baseRoutePath(c, index);
|
|
104
|
+
if (!/[:*]/.test(rp)) result = rp;
|
|
105
|
+
else {
|
|
106
|
+
const paths = splitRoutingPath(rp);
|
|
107
|
+
const reqPath = c.req.path;
|
|
108
|
+
let basePathLength = 0;
|
|
109
|
+
for (let i = 0, len = paths.length; i < len; i++) {
|
|
110
|
+
const pattern = getPattern(paths[i], paths[i + 1]);
|
|
111
|
+
if (pattern) {
|
|
112
|
+
const re = pattern[2] === true || pattern === "*" ? /[^\/]+/ : pattern[2];
|
|
113
|
+
const restPath = reqPath.substring(basePathLength + 1);
|
|
114
|
+
const segment = restPath.split("/", 1)[0];
|
|
115
|
+
basePathLength += (restPath.match(re)?.[0] ?? (re.test(segment) ? segment : "")).length;
|
|
116
|
+
} else basePathLength += paths[i].length;
|
|
117
|
+
basePathLength += 1;
|
|
118
|
+
}
|
|
119
|
+
result = reqPath.substring(0, basePathLength);
|
|
120
|
+
}
|
|
121
|
+
cache[index] = result;
|
|
122
|
+
basePathCacheMap.set(c, cache);
|
|
123
|
+
return result;
|
|
124
|
+
};
|
|
125
|
+
//#endregion
|
|
126
|
+
export { routePath as i, baseRoutePath as n, matchedRoutes as r, basePath as t };
|
package/lib/route.js
CHANGED
|
@@ -1,126 +1,2 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
import { getPattern, splitRoutingPath } from "./utils/url.js";
|
|
3
|
-
//#region ../../plugins/acryl-router/src/core/helper/route/index.ts
|
|
4
|
-
/**
|
|
5
|
-
* Get matched routes in the handler
|
|
6
|
-
*
|
|
7
|
-
* @param {Context} c - The context object
|
|
8
|
-
* @returns An array of matched routes
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```ts
|
|
12
|
-
* import { matchedRoutes } from 'acrylblends/route'
|
|
13
|
-
*
|
|
14
|
-
* app.use('*', async function logger(c, next) {
|
|
15
|
-
* await next()
|
|
16
|
-
* matchedRoutes(c).forEach(({ handler, method, path }, i) => {
|
|
17
|
-
* const name = handler.name || (handler.length < 2 ? '[handler]' : '[middleware]')
|
|
18
|
-
* console.log(
|
|
19
|
-
* method,
|
|
20
|
-
* ' ',
|
|
21
|
-
* path,
|
|
22
|
-
* ' '.repeat(Math.max(10 - path.length, 0)),
|
|
23
|
-
* name,
|
|
24
|
-
* i === c.req.routeIndex ? '<- respond from here' : ''
|
|
25
|
-
* )
|
|
26
|
-
* })
|
|
27
|
-
* })
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
const matchedRoutes = (c) => c.req[GET_MATCH_RESULT][0].map(([[, route]]) => route);
|
|
31
|
-
/**
|
|
32
|
-
* Get the route path registered within the handler
|
|
33
|
-
*
|
|
34
|
-
* @param {Context} c - The context object
|
|
35
|
-
* @param {number} index - The index of the route from which to retrieve the path, similar to Array.prototype.at(), where a negative number is the index counted from the end of the matching route. Defaults to the current route index.
|
|
36
|
-
* @returns The route path registered within the handler
|
|
37
|
-
*
|
|
38
|
-
* @example
|
|
39
|
-
* ```ts
|
|
40
|
-
* import { routePath } from 'acrylblends/route'
|
|
41
|
-
*
|
|
42
|
-
* app.use('*', (c, next) => {
|
|
43
|
-
* console.log(routePath(c)) // '*'
|
|
44
|
-
* console.log(routePath(c, -1)) // '/posts/:id'
|
|
45
|
-
* return next()
|
|
46
|
-
* })
|
|
47
|
-
*
|
|
48
|
-
* app.get('/posts/:id', (c) => {
|
|
49
|
-
* return c.text(routePath(c)) // '/posts/:id'
|
|
50
|
-
* })
|
|
51
|
-
* ```
|
|
52
|
-
*/
|
|
53
|
-
const routePath = (c, index) => matchedRoutes(c).at(index ?? c.req.routeIndex)?.path ?? "";
|
|
54
|
-
/**
|
|
55
|
-
* Get the basePath of the as-is route specified by routing.
|
|
56
|
-
*
|
|
57
|
-
* @param {Context} c - The context object
|
|
58
|
-
* @param {number} index - The index of the route from which to retrieve the path, similar to Array.prototype.at(), where a negative number is the index counted from the end of the matching route. Defaults to the current route index.
|
|
59
|
-
* @returns The basePath of the as-is route specified by routing.
|
|
60
|
-
*
|
|
61
|
-
* @example
|
|
62
|
-
* ```ts
|
|
63
|
-
* import { baseRoutePath } from 'acrylblends/route'
|
|
64
|
-
*
|
|
65
|
-
* const app = new Acryl()
|
|
66
|
-
*
|
|
67
|
-
* const subApp = new Acryl()
|
|
68
|
-
* subApp.get('/posts/:id', (c) => {
|
|
69
|
-
* return c.text(baseRoutePath(c)) // '/:sub'
|
|
70
|
-
* })
|
|
71
|
-
*
|
|
72
|
-
* app.route('/:sub', subApp)
|
|
73
|
-
* ```
|
|
74
|
-
*/
|
|
75
|
-
const baseRoutePath = (c, index) => matchedRoutes(c).at(index ?? c.req.routeIndex)?.basePath ?? "";
|
|
76
|
-
/**
|
|
77
|
-
* Get the basePath with embedded parameters
|
|
78
|
-
*
|
|
79
|
-
* @param {Context} c - The context object
|
|
80
|
-
* @param {number} index - The index of the route from which to retrieve the path, similar to Array.prototype.at(), where a negative number is the index counted from the end of the matching route. Defaults to the current route index.
|
|
81
|
-
* @returns The basePath with embedded parameters.
|
|
82
|
-
*
|
|
83
|
-
* @example
|
|
84
|
-
* ```ts
|
|
85
|
-
* import { basePath } from 'acrylblends/route'
|
|
86
|
-
*
|
|
87
|
-
* const app = new Acryl()
|
|
88
|
-
*
|
|
89
|
-
* const subApp = new Acryl()
|
|
90
|
-
* subApp.get('/posts/:id', (c) => {
|
|
91
|
-
* return c.text(basePath(c)) // '/requested-sub-app-path'
|
|
92
|
-
* })
|
|
93
|
-
*
|
|
94
|
-
* app.route('/:sub', subApp)
|
|
95
|
-
* ```
|
|
96
|
-
*/
|
|
97
|
-
const basePathCacheMap = /* @__PURE__ */ new WeakMap();
|
|
98
|
-
const basePath = (c, index) => {
|
|
99
|
-
index ??= c.req.routeIndex;
|
|
100
|
-
const cache = basePathCacheMap.get(c) || [];
|
|
101
|
-
if (typeof cache[index] === "string") return cache[index];
|
|
102
|
-
let result;
|
|
103
|
-
const rp = baseRoutePath(c, index);
|
|
104
|
-
if (!/[:*]/.test(rp)) result = rp;
|
|
105
|
-
else {
|
|
106
|
-
const paths = splitRoutingPath(rp);
|
|
107
|
-
const reqPath = c.req.path;
|
|
108
|
-
let basePathLength = 0;
|
|
109
|
-
for (let i = 0, len = paths.length; i < len; i++) {
|
|
110
|
-
const pattern = getPattern(paths[i], paths[i + 1]);
|
|
111
|
-
if (pattern) {
|
|
112
|
-
const re = pattern[2] === true || pattern === "*" ? /[^\/]+/ : pattern[2];
|
|
113
|
-
const restPath = reqPath.substring(basePathLength + 1);
|
|
114
|
-
const segment = restPath.split("/", 1)[0];
|
|
115
|
-
basePathLength += (restPath.match(re)?.[0] ?? (re.test(segment) ? segment : "")).length;
|
|
116
|
-
} else basePathLength += paths[i].length;
|
|
117
|
-
basePathLength += 1;
|
|
118
|
-
}
|
|
119
|
-
result = reqPath.substring(0, basePathLength);
|
|
120
|
-
}
|
|
121
|
-
cache[index] = result;
|
|
122
|
-
basePathCacheMap.set(c, cache);
|
|
123
|
-
return result;
|
|
124
|
-
};
|
|
125
|
-
//#endregion
|
|
1
|
+
import { i as routePath, n as baseRoutePath, r as matchedRoutes, t as basePath } from "./route-D8m-a2I1.js";
|
|
126
2
|
export { basePath, baseRoutePath, matchedRoutes, routePath };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as LinearRouter } from "../linear-router-
|
|
1
|
+
import { t as LinearRouter } from "../linear-router-CmZn_JLV.js";
|
|
2
2
|
export { LinearRouter };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as PatternRouter } from "../pattern-router-
|
|
1
|
+
import { t as PatternRouter } from "../pattern-router-CJBecJBd.js";
|
|
2
2
|
export { PatternRouter };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { i as RegExpRouter, n as buildInitParams, r as serializeInitParams, t as PreparedRegExpRouter } from "../reg-exp-router-
|
|
1
|
+
import { i as RegExpRouter, n as buildInitParams, r as serializeInitParams, t as PreparedRegExpRouter } from "../reg-exp-router-C_WV84eV.js";
|
|
2
2
|
export { PreparedRegExpRouter, RegExpRouter, buildInitParams, serializeInitParams };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as SmartRouter } from "../smart-router-
|
|
1
|
+
import { t as SmartRouter } from "../smart-router-BjxkDQCE.js";
|
|
2
2
|
export { SmartRouter };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as TrieRouter } from "../trie-router-
|
|
1
|
+
import { t as TrieRouter } from "../trie-router-JydLKUa2.js";
|
|
2
2
|
export { TrieRouter };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
//#region ../../plugins/acryl-router/src/core/router.ts
|
|
2
|
+
/**
|
|
3
|
+
* @module
|
|
4
|
+
* This module provides types definitions and variables for the routers.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Constant representing all HTTP methods in uppercase.
|
|
8
|
+
*/
|
|
9
|
+
const METHOD_NAME_ALL = "ALL";
|
|
10
|
+
/**
|
|
11
|
+
* Constant representing all HTTP methods in lowercase.
|
|
12
|
+
*/
|
|
13
|
+
const METHOD_NAME_ALL_LOWERCASE = "all";
|
|
14
|
+
/**
|
|
15
|
+
* Array of supported HTTP methods.
|
|
16
|
+
*/
|
|
17
|
+
const METHODS = [
|
|
18
|
+
"get",
|
|
19
|
+
"post",
|
|
20
|
+
"put",
|
|
21
|
+
"delete",
|
|
22
|
+
"options",
|
|
23
|
+
"patch",
|
|
24
|
+
"query"
|
|
25
|
+
];
|
|
26
|
+
/**
|
|
27
|
+
* Error message indicating that a route cannot be added because the matcher is already built.
|
|
28
|
+
*/
|
|
29
|
+
const MESSAGE_MATCHER_IS_ALREADY_BUILT = "Can not add a route since the matcher is already built.";
|
|
30
|
+
/**
|
|
31
|
+
* Error class representing an unsupported path error.
|
|
32
|
+
*/
|
|
33
|
+
var UnsupportedPathError = class extends Error {};
|
|
34
|
+
//#endregion
|
|
35
|
+
export { UnsupportedPathError as a, METHOD_NAME_ALL_LOWERCASE as i, METHODS as n, METHOD_NAME_ALL as r, MESSAGE_MATCHER_IS_ALREADY_BUILT as t };
|
package/lib/router.js
CHANGED
|
@@ -1,35 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* @module
|
|
4
|
-
* This module provides types definitions and variables for the routers.
|
|
5
|
-
*/
|
|
6
|
-
/**
|
|
7
|
-
* Constant representing all HTTP methods in uppercase.
|
|
8
|
-
*/
|
|
9
|
-
const METHOD_NAME_ALL = "ALL";
|
|
10
|
-
/**
|
|
11
|
-
* Constant representing all HTTP methods in lowercase.
|
|
12
|
-
*/
|
|
13
|
-
const METHOD_NAME_ALL_LOWERCASE = "all";
|
|
14
|
-
/**
|
|
15
|
-
* Array of supported HTTP methods.
|
|
16
|
-
*/
|
|
17
|
-
const METHODS = [
|
|
18
|
-
"get",
|
|
19
|
-
"post",
|
|
20
|
-
"put",
|
|
21
|
-
"delete",
|
|
22
|
-
"options",
|
|
23
|
-
"patch",
|
|
24
|
-
"query"
|
|
25
|
-
];
|
|
26
|
-
/**
|
|
27
|
-
* Error message indicating that a route cannot be added because the matcher is already built.
|
|
28
|
-
*/
|
|
29
|
-
const MESSAGE_MATCHER_IS_ALREADY_BUILT = "Can not add a route since the matcher is already built.";
|
|
30
|
-
/**
|
|
31
|
-
* Error class representing an unsupported path error.
|
|
32
|
-
*/
|
|
33
|
-
var UnsupportedPathError = class extends Error {};
|
|
34
|
-
//#endregion
|
|
1
|
+
import { a as UnsupportedPathError, i as METHOD_NAME_ALL_LOWERCASE, n as METHODS, r as METHOD_NAME_ALL, t as MESSAGE_MATCHER_IS_ALREADY_BUILT } from "./router-Be_o6nFu.js";
|
|
35
2
|
export { MESSAGE_MATCHER_IS_ALREADY_BUILT, METHODS, METHOD_NAME_ALL, METHOD_NAME_ALL_LOWERCASE, UnsupportedPathError };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { t as validator } from "./validator-Btiyt5VJ.js";
|
|
2
|
+
//#region ../../plugins/acryl-router/src/helpers/schema-validator.ts
|
|
3
|
+
const pathOf = (path) => (path ?? []).map((part) => String(typeof part === "object" ? part.key : part)).join(".");
|
|
4
|
+
/**
|
|
5
|
+
* The core `validator` driven by a Standard Schema. A failure answers 400 with `{ error, issues }`; success makes the parsed value the
|
|
6
|
+
* handler's `c.req.valid(target)`, typed by the schema's output.
|
|
7
|
+
*/
|
|
8
|
+
function schemaValidator(target, schema) {
|
|
9
|
+
return validator(target, async (value, c) => {
|
|
10
|
+
const result = await schema["~standard"].validate(value);
|
|
11
|
+
if (result.issues !== void 0) return c.json({
|
|
12
|
+
error: `invalid ${target}`,
|
|
13
|
+
issues: result.issues.map((issue) => ({
|
|
14
|
+
message: issue.message,
|
|
15
|
+
path: pathOf(issue.path)
|
|
16
|
+
}))
|
|
17
|
+
}, 400);
|
|
18
|
+
return result.value;
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
export { schemaValidator as t };
|
package/lib/schema-validator.js
CHANGED
|
@@ -1,22 +1,2 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
//#region ../../plugins/acryl-router/src/helpers/schema-validator.ts
|
|
3
|
-
const pathOf = (path) => (path ?? []).map((part) => String(typeof part === "object" ? part.key : part)).join(".");
|
|
4
|
-
/**
|
|
5
|
-
* The core `validator` driven by a Standard Schema. A failure answers 400 with `{ error, issues }`; success makes the parsed value the
|
|
6
|
-
* handler's `c.req.valid(target)`, typed by the schema's output.
|
|
7
|
-
*/
|
|
8
|
-
function schemaValidator(target, schema) {
|
|
9
|
-
return validator(target, async (value, c) => {
|
|
10
|
-
const result = await schema["~standard"].validate(value);
|
|
11
|
-
if (result.issues !== void 0) return c.json({
|
|
12
|
-
error: `invalid ${target}`,
|
|
13
|
-
issues: result.issues.map((issue) => ({
|
|
14
|
-
message: issue.message,
|
|
15
|
-
path: pathOf(issue.path)
|
|
16
|
-
}))
|
|
17
|
-
}, 400);
|
|
18
|
-
return result.value;
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
//#endregion
|
|
1
|
+
import { t as schemaValidator } from "./schema-validator-EK3cUUCt.js";
|
|
22
2
|
export { schemaValidator };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { encodeBase64 } from "./
|
|
1
|
+
import { r as encodeBase64 } from "./encode-BhbNLrjp.js";
|
|
2
2
|
//#region ../../plugins/acryl-router/src/core/middleware/secure-headers/secure-headers.ts
|
|
3
3
|
const HEADERS_MAP = {
|
|
4
4
|
crossOriginEmbedderPolicy: ["Cross-Origin-Embedder-Policy", "require-corp"],
|
package/lib/secure-headers.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as secureHeaders, t as NONCE } from "./secure-headers-
|
|
1
|
+
import { n as secureHeaders, t as NONCE } from "./secure-headers-C5ZOcXqk.js";
|
|
2
2
|
export { NONCE, secureHeaders };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { L as MiddlewareHandler, t as Context, v as Env } from "./context-DS3fYyG-.js";
|
|
2
|
+
//#region ../../plugins/acryl-node-server/src/adapter/serve-static.d.ts
|
|
3
|
+
type ServeStaticOptions<E extends Env = Env> = {
|
|
4
|
+
/**
|
|
5
|
+
* Root path. Relative path is based on current working directory from which the app was started.
|
|
6
|
+
*/
|
|
7
|
+
root?: string;
|
|
8
|
+
path?: string;
|
|
9
|
+
index?: string;
|
|
10
|
+
precompressed?: boolean; /** Allow percent signs in the routed request path. Defaults to false. */
|
|
11
|
+
allowPercentInPath?: boolean;
|
|
12
|
+
rewriteRequestPath?: (path: string, c: Context<E>) => string;
|
|
13
|
+
onFound?: (path: string, c: Context<E>) => void | Promise<void>;
|
|
14
|
+
onNotFound?: (path: string, c: Context<E>) => void | Promise<void>;
|
|
15
|
+
};
|
|
16
|
+
declare const serveStatic: <E extends Env = any>(options?: ServeStaticOptions<E>) => MiddlewareHandler<E>;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { serveStatic as n, ServeStaticOptions as t };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { getMimeType } from "./
|
|
2
|
-
import "./helpers-
|
|
1
|
+
import { r as getMimeType } from "./mime-BnScXkQn.js";
|
|
2
|
+
import "./helpers-BEjcdbgw.js";
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import { Readable } from "node:stream";
|
|
5
5
|
import { createReadStream, existsSync, statSync } from "node:fs";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { tryDecodeURI } from "./
|
|
2
|
-
import { parseAccept } from "./
|
|
3
|
-
import { COMPRESSIBLE_CONTENT_TYPE_REGEX } from "./
|
|
4
|
-
import { getMimeType } from "./
|
|
1
|
+
import { p as tryDecodeURI } from "./url-BPh4d6j-.js";
|
|
2
|
+
import { t as parseAccept } from "./accept-CNNHu4Cf.js";
|
|
3
|
+
import { t as COMPRESSIBLE_CONTENT_TYPE_REGEX } from "./compress-DCyrrQ5D.js";
|
|
4
|
+
import { r as getMimeType } from "./mime-BnScXkQn.js";
|
|
5
5
|
//#region ../../plugins/acryl-router/src/core/middleware/serve-static/path.ts
|
|
6
6
|
/**
|
|
7
7
|
* `defaultJoin` does not support Windows paths and always uses `/` separators.
|
package/lib/serve-static.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as serveStatic } from "./serve-static-
|
|
1
|
+
import { t as serveStatic } from "./serve-static-EiJf1zkO.js";
|
|
2
2
|
export { serveStatic };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as UnsupportedPathError, t as MESSAGE_MATCHER_IS_ALREADY_BUILT } from "./router-Be_o6nFu.js";
|
|
2
2
|
//#region ../../plugins/acryl-router/src/core/router/smart-router/router.ts
|
|
3
3
|
var SmartRouter = class {
|
|
4
4
|
name = "SmartRouter";
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { t as Acryl } from "./app-
|
|
2
|
-
import { bodyLimit } from "./body-limit.js";
|
|
3
|
-
import { methodNotAllowed } from "./method-not-allowed.js";
|
|
4
|
-
import { r as streamSSE } from "./streaming-
|
|
5
|
-
import {
|
|
6
|
-
import "./helpers-
|
|
7
|
-
import { UiControlError, WINDOW_ID
|
|
8
|
-
import "./src-
|
|
9
|
-
import "./middleware-
|
|
1
|
+
import { t as Acryl } from "./app-CQcGWjrk.js";
|
|
2
|
+
import { t as bodyLimit } from "./body-limit-WmIjWRLt.js";
|
|
3
|
+
import { t as methodNotAllowed } from "./method-not-allowed-TO2_hnfl.js";
|
|
4
|
+
import { r as streamSSE } from "./streaming-BlDaph8U.js";
|
|
5
|
+
import { i as loopbackOnly, r as loopbackAuthority } from "./loopback-only-BbasoF7R.js";
|
|
6
|
+
import "./helpers-BEjcdbgw.js";
|
|
7
|
+
import { d as parseChannelToHost, l as UiControlError, u as WINDOW_ID } from "./protocol-Dt0AZBOz.js";
|
|
8
|
+
import "./src-BTBm4OPD.js";
|
|
9
|
+
import "./middleware-BfG_fp8P.js";
|
|
10
10
|
import { dirname, join } from "node:path";
|
|
11
11
|
import { closeSync, mkdirSync, openSync, readFileSync, renameSync, statSync, writeSync } from "node:fs";
|
|
12
12
|
import { timingSafeEqual } from "node:crypto";
|
|
@@ -26,6 +26,8 @@ var UiChannel = class {
|
|
|
26
26
|
nextId = 1;
|
|
27
27
|
clock = 0;
|
|
28
28
|
closed = false;
|
|
29
|
+
/** Callers waiting for a page to (re)connect: each is told once, by the next stream that attaches. */
|
|
30
|
+
attachWaiters = /* @__PURE__ */ new Set();
|
|
29
31
|
/**
|
|
30
32
|
* Register a page's stream. A stream already open for the same window is closed first, and its calls settle as `disconnected`.
|
|
31
33
|
* @returns the function to call when this stream ends.
|
|
@@ -40,6 +42,7 @@ var UiChannel = class {
|
|
|
40
42
|
lastActive: ++this.clock
|
|
41
43
|
};
|
|
42
44
|
this.connections.set(windowId, connection);
|
|
45
|
+
for (const waiter of [...this.attachWaiters]) waiter();
|
|
43
46
|
return () => {
|
|
44
47
|
if (this.connections.get(windowId) === connection) this.drop(connection, false);
|
|
45
48
|
};
|
|
@@ -110,6 +113,51 @@ var UiChannel = class {
|
|
|
110
113
|
}
|
|
111
114
|
});
|
|
112
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* A promise for the next time a page connects (a page that reloaded or moved opens a new stream). Ask for it BEFORE the call that makes the page leave, or a fast page is missed.
|
|
118
|
+
* @returns whether a page connected within `timeoutMs`.
|
|
119
|
+
*/
|
|
120
|
+
expectAttach(timeoutMs, count = 1) {
|
|
121
|
+
return new Promise((resolve) => {
|
|
122
|
+
let left = count;
|
|
123
|
+
const done = (value) => {
|
|
124
|
+
clearTimeout(timer);
|
|
125
|
+
this.attachWaiters.delete(waiter);
|
|
126
|
+
resolve(value);
|
|
127
|
+
};
|
|
128
|
+
const waiter = () => {
|
|
129
|
+
left -= 1;
|
|
130
|
+
if (left <= 0) done(true);
|
|
131
|
+
};
|
|
132
|
+
const timer = setTimeout(() => {
|
|
133
|
+
done(false);
|
|
134
|
+
}, timeoutMs);
|
|
135
|
+
this.attachWaiters.add(waiter);
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Ask every connected page to reload (the app just changed under them) and wait, up to `timeoutMs`, for them to come back. Best effort: a page that does not come back
|
|
140
|
+
* (it was closed, or it moved to a page without the door) is not an error here.
|
|
141
|
+
* @returns how many pages were asked.
|
|
142
|
+
*/
|
|
143
|
+
async reloadAll(timeoutMs = 8e3) {
|
|
144
|
+
const targets = this.byRecency();
|
|
145
|
+
if (this.closed || targets.length === 0) return 0;
|
|
146
|
+
const back = this.expectAttach(timeoutMs, targets.length);
|
|
147
|
+
for (const target of targets) {
|
|
148
|
+
const id = this.nextId;
|
|
149
|
+
this.nextId += 1;
|
|
150
|
+
try {
|
|
151
|
+
target.stream.send(JSON.stringify({
|
|
152
|
+
t: "call",
|
|
153
|
+
id,
|
|
154
|
+
request: { op: "reload" }
|
|
155
|
+
}));
|
|
156
|
+
} catch {}
|
|
157
|
+
}
|
|
158
|
+
await back;
|
|
159
|
+
return targets.length;
|
|
160
|
+
}
|
|
113
161
|
/** Close every page's stream and settle every pending call as `unloaded`. */
|
|
114
162
|
close() {
|
|
115
163
|
this.closed = true;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { HTTPException } from "./http-exception.js";
|
|
2
|
-
import { mergePath } from "./
|
|
3
|
-
import { COMPOSED_HANDLER } from "./
|
|
4
|
-
import { t as TrieRouter } from "./trie-router-
|
|
5
|
-
import { t as Acryl } from "./app-
|
|
6
|
-
import "./core-
|
|
1
|
+
import { t as HTTPException } from "./http-exception-MjWkT89V.js";
|
|
2
|
+
import { l as mergePath } from "./url-BPh4d6j-.js";
|
|
3
|
+
import { t as COMPOSED_HANDLER } from "./constants-CBSEudrb.js";
|
|
4
|
+
import { t as TrieRouter } from "./trie-router-JydLKUa2.js";
|
|
5
|
+
import { t as Acryl } from "./app-CQcGWjrk.js";
|
|
6
|
+
import "./core-BOu1jYua.js";
|
|
7
7
|
import "./connection-C7xgP1hP.js";
|
|
8
8
|
import { Service } from "@deepseek-ai/cordis";
|
|
9
9
|
import z from "@deepseek-ai/schemastery";
|
|
@@ -39,6 +39,7 @@ var Router = class extends Service {
|
|
|
39
39
|
/** Everything that changes after construction, kept in one object so the service's live state is in one place. */
|
|
40
40
|
state = {
|
|
41
41
|
mounts: /* @__PURE__ */ new Set(),
|
|
42
|
+
wrappers: /* @__PURE__ */ new Set(),
|
|
42
43
|
errorHandler: void 0,
|
|
43
44
|
notFoundHandler: void 0,
|
|
44
45
|
composed: void 0,
|
|
@@ -95,6 +96,20 @@ var Router = class extends Service {
|
|
|
95
96
|
};
|
|
96
97
|
}
|
|
97
98
|
/**
|
|
99
|
+
* Run `middleware` around every request the router serves, whenever the plugin that asks was mounted: a middleware in a plain mount wraps only the routes mounted after it,
|
|
100
|
+
* which is the wrong tool for a plugin that must see every page (the door adds its script to each HTML response, the pages of a plugin that loaded earlier included). It goes
|
|
101
|
+
* outside all mounts, in the order wrappers were added, and goes away when the calling plugin unloads or when the returned function is called.
|
|
102
|
+
*/
|
|
103
|
+
wrap(middleware) {
|
|
104
|
+
this.state.wrappers.add(middleware);
|
|
105
|
+
this.state.composed = void 0;
|
|
106
|
+
const remove = () => {
|
|
107
|
+
if (this.state.wrappers.delete(middleware)) this.state.composed = void 0;
|
|
108
|
+
};
|
|
109
|
+
this.ctx.effect(() => remove, "acryl-router: wrapper");
|
|
110
|
+
return remove;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
98
113
|
* The mount's own copy of `app`'s routes as they are now (like the core's `app.route`), each handler wrapped so the router knows which
|
|
99
114
|
* mount's code a request is in. The core's `app.route` runs first so a sub-app's own `onError` still applies to its routes.
|
|
100
115
|
*/
|
|
@@ -251,6 +266,7 @@ var Router = class extends Service {
|
|
|
251
266
|
strict: this.strict,
|
|
252
267
|
router: new TrieRouter()
|
|
253
268
|
});
|
|
269
|
+
for (const wrapper of this.state.wrappers) root.use("*", wrapper);
|
|
254
270
|
for (const mount of this.state.mounts) root.route(mount.path, mount.app);
|
|
255
271
|
root.onError(this.state.errorHandler ?? this.logError);
|
|
256
272
|
if (this.state.notFoundHandler !== void 0) root.notFound(this.state.notFoundHandler);
|