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
@@ -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/trailing-slash/index.d.ts
4
4
  type TrimTrailingSlashOptions = {
@@ -1,8 +1,8 @@
1
- import { $ as Acryl, J as Schema, K as ResponseFormat, N as KnownResponseFormat, g as Endpoint, x as ExtractSchema } from "./context-Bm7rI-oK.js";
1
+ import { $ as Acryl, J as Schema, K as ResponseFormat, N as KnownResponseFormat, g as Endpoint, x as ExtractSchema } from "./context-B5Y1lLha.js";
2
2
  import { i as METHOD_NAME_ALL_LOWERCASE, n as METHODS } from "./router-CvUxUTOq.js";
3
3
  import { c as StatusCode, l as SuccessStatusCode } from "./http-status-DaAwGAFL.js";
4
- import { s as HasRequiredKeys } from "./types-CwrQjlaM.js";
5
- import { t as Acryl$1 } from "./app-CmAYW1Al.js";
4
+ import { s as HasRequiredKeys } from "./types-D9DEXMjE.js";
5
+ import { t as Acryl$1 } from "./app-BdrVHBlJ.js";
6
6
 
7
7
  //#region ../../plugins/acryl-router/src/core/client/types.d.ts
8
8
  /**
@@ -62,6 +62,8 @@ type StringLiteralUnion<T> = T | (string & Record<never, never>);
62
62
  type BufferSource = ArrayBufferView<ArrayBuffer> | ArrayBuffer;
63
63
  /** A Web Crypto key, named from the runtime's own `crypto` so the public types do not need the DOM library. */
64
64
  type CryptoKey = Awaited<ReturnType<typeof crypto.subtle.importKey>>;
65
+ /** What the Web `Headers` constructor accepts, named from the runtime's own `Headers` so the public types do not need the DOM library. */
66
+ type HeadersInit = NonNullable<ConstructorParameters<typeof Headers>[0]>;
65
67
  /** How a WebSocket hands binary data to `onmessage`; declared here so the public types do not need the DOM library. */
66
68
  type BinaryType = 'arraybuffer' | 'blob';
67
69
  /** The members of a WebSocket `message` event the helpers hand out (the Web `MessageEvent`, whose Node global is not generic); declared here so the public types do not need the DOM library. */
@@ -102,4 +104,4 @@ interface JsonWebKey {
102
104
  y?: string;
103
105
  }
104
106
  //#endregion
105
- export { SimplifyDeepArray as C, Simplify as S, UnionToIntersection as T, JsonWebKey as _, Equal as a, RemoveBlankRecord as b, IfAnyThenEmptyObject as c, IsAny as d, JSONArray as f, JSONValue as g, JSONPrimitive as h, CryptoKey as i, InterfaceToType as l, JSONParsed as m, BufferSource as n, Expect as o, JSONObject as p, CloseEvent as r, HasRequiredKeys as s, BinaryType as t, InvalidJSONValue as u, MessageEvent as v, StringLiteralUnion as w, RequiredKeysOf as x, NotEqual as y };
107
+ export { Simplify as C, UnionToIntersection as E, RequiredKeysOf as S, StringLiteralUnion as T, JSONValue as _, Equal as a, NotEqual as b, HeadersInit as c, InvalidJSONValue as d, IsAny as f, JSONPrimitive as g, JSONParsed as h, CryptoKey as i, IfAnyThenEmptyObject as l, JSONObject as m, BufferSource as n, Expect as o, JSONArray as p, CloseEvent as r, HasRequiredKeys as s, BinaryType as t, InterfaceToType as u, JsonWebKey as v, SimplifyDeepArray as w, RemoveBlankRecord as x, MessageEvent as y };
@@ -1,4 +1,4 @@
1
- import { t as Context } from "./context-Bm7rI-oK.js";
1
+ import { t as Context } from "./context-B5Y1lLha.js";
2
2
 
3
3
  //#region ../../plugins/acryl-router/src/core/helper/conninfo/types.d.ts
4
4
  type AddressType = 'IPv6' | 'IPv4' | undefined;
package/lib/types.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { A as Input, B as NotFoundResponse, C as FetchEventLike, D as Handler, E as HTTPResponseError, F as MergeSchemaPath, G as RemoveQuestion, H as ParamKeyToRecord, I as MiddlewareHandler, J as Schema, K as ResponseFormat, L as MiddlewareHandlerInterface, M as IntersectNonAnyTypes, N as KnownResponseFormat, O as HandlerInterface, P as MergePath, Q as Variables, R as Next, S as ExtractSchemaForStatusCode, T as H, U as ParamKeys, V as OnHandlerInterface, W as ParsedFormValue, X as TypedResponse, Y as ToSchema, Z as ValidationTargets, _ as Env, b as ExtractInput, d as AddParam, f as Bindings, g as Endpoint, h as BlankSchema, j as InputToDataByTarget, k as HandlerResponse, m as BlankInput, p as BlankEnv, q as RouterRoute, v as ErrorHandler, w as FormValue, x as ExtractSchema, y as ExtractHandlerResponse, z as NotFoundHandler } from "./context-Bm7rI-oK.js";
1
+ import { A as Input, B as NotFoundResponse, C as FetchEventLike, D as Handler, E as HTTPResponseError, F as MergeSchemaPath, G as RemoveQuestion, H as ParamKeyToRecord, I as MiddlewareHandler, J as Schema, K as ResponseFormat, L as MiddlewareHandlerInterface, M as IntersectNonAnyTypes, N as KnownResponseFormat, O as HandlerInterface, P as MergePath, Q as Variables, R as Next, S as ExtractSchemaForStatusCode, T as H, U as ParamKeys, V as OnHandlerInterface, W as ParsedFormValue, X as TypedResponse, Y as ToSchema, Z as ValidationTargets, _ as Env, b as ExtractInput, d as AddParam, f as Bindings, g as Endpoint, h as BlankSchema, j as InputToDataByTarget, k as HandlerResponse, m as BlankInput, p as BlankEnv, q as RouterRoute, v as ErrorHandler, w as FormValue, x as ExtractSchema, y as ExtractHandlerResponse, z as NotFoundHandler } from "./context-B5Y1lLha.js";
2
2
  export { AddParam, Bindings, BlankEnv, BlankInput, BlankSchema, Endpoint, Env, ErrorHandler, ExtractHandlerResponse, ExtractInput, ExtractSchema, ExtractSchemaForStatusCode, FetchEventLike, FormValue, H, HTTPResponseError, Handler, HandlerInterface, HandlerResponse, Input, InputToDataByTarget, IntersectNonAnyTypes, KnownResponseFormat, MergePath, MergeSchemaPath, MiddlewareHandler, MiddlewareHandlerInterface, Next, NotFoundHandler, NotFoundResponse, OnHandlerInterface, ParamKeyToRecord, ParamKeys, ParsedFormValue, RemoveQuestion, ResponseFormat, RouterRoute, Schema, ToSchema, TypedResponse, ValidationTargets, Variables };
@@ -1,2 +1,2 @@
1
- import { c as BodyData, l as ParseBodyOptions, u as parseBody } from "../context-Bm7rI-oK.js";
1
+ import { c as BodyData, l as ParseBodyOptions, u as parseBody } from "../context-B5Y1lLha.js";
2
2
  export { BodyData, ParseBodyOptions, parseBody };
@@ -1,2 +1,2 @@
1
- import { a as SignedCookie, c as serialize, i as CookiePrefixOptions, l as serializeSigned, n as CookieConstraint, o as parse, r as CookieOptions, s as parseSigned, t as Cookie } from "../cookie-ClMaKDQf.js";
1
+ import { a as SignedCookie, c as serialize, i as CookiePrefixOptions, l as serializeSigned, n as CookieConstraint, o as parse, r as CookieOptions, s as parseSigned, t as Cookie } from "../cookie-D9_nQbsM.js";
2
2
  export { Cookie, CookieConstraint, CookieOptions, CookiePrefixOptions, SignedCookie, parse, parseSigned, serialize, serializeSigned };
@@ -1,4 +1,4 @@
1
- import { g as JSONValue } from "../types-CwrQjlaM.js";
1
+ import { _ as JSONValue } from "../types-D9DEXMjE.js";
2
2
 
3
3
  //#region ../../plugins/acryl-router/src/core/utils/crypto.d.ts
4
4
  type Algorithm = {
@@ -1,4 +1,4 @@
1
- import { t as AddressType } from "../types-CDO6I3B0.js";
1
+ import { t as AddressType } from "../types-ZM9gIiKh.js";
2
2
 
3
3
  //#region ../../plugins/acryl-router/src/core/utils/ipaddr.d.ts
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { a as SignatureKey, c as SignatureAlgorithm, i as AcrylJsonWebKey, n as VerifyOptions, r as VerifyOptionsWithAlg, s as AsymmetricAlgorithm, t as TokenHeader } from "../jwt-Dg493Tai.js";
1
+ import { a as SignatureKey, c as SignatureAlgorithm, i as AcrylJsonWebKey, n as VerifyOptions, r as VerifyOptionsWithAlg, s as AsymmetricAlgorithm, t as TokenHeader } from "../jwt-BA65QhnJ.js";
2
2
  import { t as JWTPayload } from "../types-DR95J00T.js";
3
3
 
4
4
  //#region ../../plugins/acryl-router/src/core/utils/jwt/index.d.ts
@@ -1,2 +1,2 @@
1
- import { C as SimplifyDeepArray, S as Simplify, T as UnionToIntersection, _ as JsonWebKey, a as Equal, b as RemoveBlankRecord, c as IfAnyThenEmptyObject, d as IsAny, f as JSONArray, g as JSONValue, h as JSONPrimitive, i as CryptoKey, l as InterfaceToType, m as JSONParsed, n as BufferSource, o as Expect, p as JSONObject, r as CloseEvent, s as HasRequiredKeys, t as BinaryType, u as InvalidJSONValue, v as MessageEvent, w as StringLiteralUnion, x as RequiredKeysOf, y as NotEqual } from "../types-CwrQjlaM.js";
2
- export { BinaryType, BufferSource, CloseEvent, CryptoKey, Equal, Expect, HasRequiredKeys, IfAnyThenEmptyObject, InterfaceToType, InvalidJSONValue, IsAny, JSONArray, JSONObject, JSONParsed, JSONPrimitive, JSONValue, JsonWebKey, MessageEvent, NotEqual, RemoveBlankRecord, RequiredKeysOf, Simplify, SimplifyDeepArray, StringLiteralUnion, UnionToIntersection };
1
+ import { C as Simplify, E as UnionToIntersection, S as RequiredKeysOf, T as StringLiteralUnion, _ as JSONValue, a as Equal, b as NotEqual, c as HeadersInit, d as InvalidJSONValue, f as IsAny, g as JSONPrimitive, h as JSONParsed, i as CryptoKey, l as IfAnyThenEmptyObject, m as JSONObject, n as BufferSource, o as Expect, p as JSONArray, r as CloseEvent, s as HasRequiredKeys, t as BinaryType, u as InterfaceToType, v as JsonWebKey, w as SimplifyDeepArray, x as RemoveBlankRecord, y as MessageEvent } from "../types-D9DEXMjE.js";
2
+ export { BinaryType, BufferSource, CloseEvent, CryptoKey, Equal, Expect, HasRequiredKeys, HeadersInit, IfAnyThenEmptyObject, InterfaceToType, InvalidJSONValue, IsAny, JSONArray, JSONObject, JSONParsed, JSONPrimitive, JSONValue, JsonWebKey, MessageEvent, NotEqual, RemoveBlankRecord, RequiredKeysOf, Simplify, SimplifyDeepArray, StringLiteralUnion, UnionToIntersection };
@@ -1,5 +1,5 @@
1
- import { I as MiddlewareHandler, W as ParsedFormValue, X as TypedResponse, Z as ValidationTargets, _ as Env, t as Context, w as FormValue } from "./context-Bm7rI-oK.js";
2
- import { T as UnionToIntersection } from "./types-CwrQjlaM.js";
1
+ import { I as MiddlewareHandler, W as ParsedFormValue, X as TypedResponse, Z as ValidationTargets, _ as Env, t as Context, w as FormValue } from "./context-B5Y1lLha.js";
2
+ import { E as UnionToIntersection } from "./types-D9DEXMjE.js";
3
3
 
4
4
  //#region ../../plugins/acryl-router/src/core/validator/utils.d.ts
5
5
  /**
package/lib/ws.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as WSEvents, c as WebSocketHelperDefineContext, d as defineWebSocketHelper, i as WSContextInit, l as WebSocketHelperDefineHandler, n as UpgradeWebSocket, o as WSMessageReceive, r as WSContext, s as WSReadyState, t as SendOptions, u as createWSMessageEvent } from "./index-UTBmM3GX.js";
1
+ import { a as WSEvents, c as WebSocketHelperDefineContext, d as defineWebSocketHelper, i as WSContextInit, l as WebSocketHelperDefineHandler, n as UpgradeWebSocket, o as WSMessageReceive, r as WSContext, s as WSReadyState, t as SendOptions, u as createWSMessageEvent } from "./index-Kqou8Fjh.js";
2
2
  export { SendOptions, UpgradeWebSocket, WSContext, WSContextInit, WSEvents, WSMessageReceive, WSReadyState, WebSocketHelperDefineContext, WebSocketHelperDefineHandler, createWSMessageEvent, defineWebSocketHelper };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "acrylblends",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "description": "The Acryl web framework (import { Acryl } from \"acrylblends\") and the acrylblends command that scaffolds Cordis apps.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -30,6 +30,14 @@
30
30
  "types": "./lib/http-exception.d.ts",
31
31
  "default": "./lib/http-exception.js"
32
32
  },
33
+ "./tiny": {
34
+ "types": "./lib/tiny.d.ts",
35
+ "default": "./lib/tiny.js"
36
+ },
37
+ "./quick": {
38
+ "types": "./lib/quick.d.ts",
39
+ "default": "./lib/quick.js"
40
+ },
33
41
  "./basic-auth": {
34
42
  "types": "./lib/basic-auth.d.ts",
35
43
  "default": "./lib/basic-auth.js"
@@ -42,6 +50,10 @@
42
50
  "types": "./lib/body-limit.d.ts",
43
51
  "default": "./lib/body-limit.js"
44
52
  },
53
+ "./cache": {
54
+ "types": "./lib/cache.d.ts",
55
+ "default": "./lib/cache.js"
56
+ },
45
57
  "./combine": {
46
58
  "types": "./lib/combine.d.ts",
47
59
  "default": "./lib/combine.js"
@@ -94,6 +106,10 @@
94
106
  "types": "./lib/method-override.d.ts",
95
107
  "default": "./lib/method-override.js"
96
108
  },
109
+ "./mount": {
110
+ "types": "./lib/mount.d.ts",
111
+ "default": "./lib/mount.js"
112
+ },
97
113
  "./powered-by": {
98
114
  "types": "./lib/powered-by.d.ts",
99
115
  "default": "./lib/powered-by.js"
@@ -138,6 +154,10 @@
138
154
  "types": "./lib/cookie.d.ts",
139
155
  "default": "./lib/cookie.js"
140
156
  },
157
+ "./dev": {
158
+ "types": "./lib/dev.d.ts",
159
+ "default": "./lib/dev.js"
160
+ },
141
161
  "./factory": {
142
162
  "types": "./lib/factory.d.ts",
143
163
  "default": "./lib/factory.js"
@@ -146,6 +166,10 @@
146
166
  "types": "./lib/html.d.ts",
147
167
  "default": "./lib/html.js"
148
168
  },
169
+ "./proxy": {
170
+ "types": "./lib/proxy.d.ts",
171
+ "default": "./lib/proxy.js"
172
+ },
149
173
  "./route": {
150
174
  "types": "./lib/route.d.ts",
151
175
  "default": "./lib/route.js"
@@ -2,7 +2,7 @@
2
2
  "source": {
3
3
  "repo": "acryldev/acryl",
4
4
  "path": "plugins/acryl-inspect",
5
- "commit": "5743482e4199ded676a77f594bce15fd4aa0ca2f"
5
+ "commit": "0174cb01625bfd32d0162ad56179c582f353321e"
6
6
  },
7
7
  "vendored": [
8
8
  "src",
@@ -2,7 +2,7 @@
2
2
  "source": {
3
3
  "repo": "acryldev/acryl",
4
4
  "path": "plugins/acryl-node-server",
5
- "commit": "5743482e4199ded676a77f594bce15fd4aa0ca2f"
5
+ "commit": "0174cb01625bfd32d0162ad56179c582f353321e"
6
6
  },
7
7
  "vendored": [
8
8
  "src",
@@ -0,0 +1,181 @@
1
+ import { getRouterName, inspectRoutes, showRoutes } from './index.ts'
2
+ import { Acryl } from '../../app.ts'
3
+ import { RegExpRouter } from '../../router/reg-exp-router/index.ts'
4
+ import type { Handler, MiddlewareHandler } from '../../types.ts'
5
+
6
+ const namedMiddleware: MiddlewareHandler = (_, next) => next()
7
+ const namedHandler: Handler = (c) => c.text('hi')
8
+ const app = new Acryl()
9
+ .use('*', (_c, next) => next())
10
+ .get(
11
+ '/',
12
+ (_, next) => next(),
13
+ (c) => c.text('hi')
14
+ )
15
+ .get('/named', namedMiddleware, namedHandler)
16
+ .post('/', (c) => c.text('hi'))
17
+ .put('/', (c) => c.text('hi'))
18
+ .patch('/', (c) => c.text('hi'))
19
+ .delete('/', (c) => c.text('hi'))
20
+ .options('/', (c) => c.text('hi'))
21
+ .get('/static', () => new Response('hi'))
22
+
23
+ describe('inspectRoutes()', () => {
24
+ it('should return correct data', async () => {
25
+ expect(inspectRoutes(app)).toEqual([
26
+ { path: '/*', method: 'ALL', name: '[middleware]', isMiddleware: true },
27
+ { path: '/', method: 'GET', name: '[middleware]', isMiddleware: true },
28
+ { path: '/', method: 'GET', name: '[handler]', isMiddleware: false },
29
+ { path: '/named', method: 'GET', name: 'namedMiddleware', isMiddleware: true },
30
+ { path: '/named', method: 'GET', name: 'namedHandler', isMiddleware: false },
31
+ { path: '/', method: 'POST', name: '[handler]', isMiddleware: false },
32
+ { path: '/', method: 'PUT', name: '[handler]', isMiddleware: false },
33
+ { path: '/', method: 'PATCH', name: '[handler]', isMiddleware: false },
34
+ { path: '/', method: 'DELETE', name: '[handler]', isMiddleware: false },
35
+ { path: '/', method: 'OPTIONS', name: '[handler]', isMiddleware: false },
36
+ { path: '/static', method: 'GET', name: '[handler]', isMiddleware: false },
37
+ ])
38
+ })
39
+
40
+ it('should return [handler] also for sub app', async () => {
41
+ const subApp = new Acryl()
42
+
43
+ subApp.get('/', (c) => c.json(0))
44
+ subApp.onError((_, c) => c.json(0))
45
+
46
+ const mainApp = new Acryl()
47
+ mainApp.route('/', subApp)
48
+ expect(inspectRoutes(mainApp)).toEqual([
49
+ {
50
+ isMiddleware: false,
51
+ method: 'GET',
52
+ name: '[handler]',
53
+ path: '/',
54
+ },
55
+ ])
56
+ })
57
+ })
58
+
59
+ describe('showRoutes()', () => {
60
+ let logs: string[] = []
61
+
62
+ let originalLog: typeof console.log
63
+ beforeAll(() => {
64
+ originalLog = console.log
65
+ console.log = (...args) => logs.push(...args)
66
+ })
67
+ afterAll(() => {
68
+ console.log = originalLog
69
+ })
70
+
71
+ beforeEach(() => {
72
+ logs = []
73
+ })
74
+ it('should render simple output', async () => {
75
+ showRoutes(app)
76
+ expect(logs).toEqual([
77
+ '\x1b[32mGET\x1b[0m /',
78
+ '\x1b[32mGET\x1b[0m /named',
79
+ '\x1b[32mPOST\x1b[0m /',
80
+ '\x1b[32mPUT\x1b[0m /',
81
+ '\x1b[32mPATCH\x1b[0m /',
82
+ '\x1b[32mDELETE\x1b[0m /',
83
+ '\x1b[32mOPTIONS\x1b[0m /',
84
+ '\x1b[32mGET\x1b[0m /static',
85
+ ])
86
+ })
87
+
88
+ it('should render output includes handlers and middlewares', async () => {
89
+ showRoutes(app, { verbose: true })
90
+ expect(logs).toEqual([
91
+ '\x1b[32mALL\x1b[0m /*',
92
+ ' [middleware]',
93
+ '\x1b[32mGET\x1b[0m /',
94
+ ' [middleware]',
95
+ ' [handler]',
96
+ '\x1b[32mGET\x1b[0m /named',
97
+ ' namedMiddleware',
98
+ ' namedHandler',
99
+ '\x1b[32mPOST\x1b[0m /',
100
+ ' [handler]',
101
+ '\x1b[32mPUT\x1b[0m /',
102
+ ' [handler]',
103
+ '\x1b[32mPATCH\x1b[0m /',
104
+ ' [handler]',
105
+ '\x1b[32mDELETE\x1b[0m /',
106
+ ' [handler]',
107
+ '\x1b[32mOPTIONS\x1b[0m /',
108
+ ' [handler]',
109
+ '\x1b[32mGET\x1b[0m /static',
110
+ ' [handler]',
111
+ ])
112
+ })
113
+
114
+ it('should render not colorized output', async () => {
115
+ showRoutes(app, { colorize: false })
116
+ expect(logs).toEqual([
117
+ 'GET /',
118
+ 'GET /named',
119
+ 'POST /',
120
+ 'PUT /',
121
+ 'PATCH /',
122
+ 'DELETE /',
123
+ 'OPTIONS /',
124
+ 'GET /static',
125
+ ])
126
+ })
127
+ })
128
+
129
+ describe('showRoutes() in NO_COLOR', () => {
130
+ let logs: string[] = []
131
+
132
+ let originalLog: typeof console.log
133
+ beforeAll(() => {
134
+ vi.stubEnv('NO_COLOR', '1')
135
+ originalLog = console.log
136
+ console.log = (...args) => logs.push(...args)
137
+ })
138
+ afterAll(() => {
139
+ vi.unstubAllEnvs()
140
+ console.log = originalLog
141
+ })
142
+
143
+ beforeEach(() => {
144
+ logs = []
145
+ })
146
+ it('should render not colorized output', async () => {
147
+ showRoutes(app)
148
+ expect(logs).toEqual([
149
+ 'GET /',
150
+ 'GET /named',
151
+ 'POST /',
152
+ 'PUT /',
153
+ 'PATCH /',
154
+ 'DELETE /',
155
+ 'OPTIONS /',
156
+ 'GET /static',
157
+ ])
158
+ })
159
+ it('should render colorized output if colorize: true', async () => {
160
+ showRoutes(app, { colorize: true })
161
+ expect(logs).toEqual([
162
+ '\x1b[32mGET\x1b[0m /',
163
+ '\x1b[32mGET\x1b[0m /named',
164
+ '\x1b[32mPOST\x1b[0m /',
165
+ '\x1b[32mPUT\x1b[0m /',
166
+ '\x1b[32mPATCH\x1b[0m /',
167
+ '\x1b[32mDELETE\x1b[0m /',
168
+ '\x1b[32mOPTIONS\x1b[0m /',
169
+ '\x1b[32mGET\x1b[0m /static',
170
+ ])
171
+ })
172
+ })
173
+
174
+ describe('getRouterName()', () => {
175
+ it('Should return the correct router name', async () => {
176
+ const app = new Acryl({
177
+ router: new RegExpRouter(),
178
+ })
179
+ expect(getRouterName(app)).toBe('RegExpRouter')
180
+ })
181
+ })
@@ -0,0 +1,79 @@
1
+ /**
2
+ * @module
3
+ * Dev Helper for Acryl.
4
+ */
5
+
6
+ import type { Acryl } from '../../app.ts'
7
+ import type { Env, RouterRoute } from '../../types.ts'
8
+ import { getColorEnabled } from '../../utils/color.ts'
9
+ import { findTargetHandler, isMiddleware } from '../../utils/handler.ts'
10
+
11
+ interface ShowRoutesOptions {
12
+ verbose?: boolean
13
+ colorize?: boolean
14
+ }
15
+
16
+ interface RouteData {
17
+ path: string
18
+ method: string
19
+ name: string
20
+ isMiddleware: boolean
21
+ }
22
+
23
+ const handlerName = (handler: Function): string => {
24
+ return handler.name || (isMiddleware(handler) ? '[middleware]' : '[handler]')
25
+ }
26
+
27
+ export const inspectRoutes = <E extends Env>(acryl: Acryl<E>): RouteData[] => {
28
+ return acryl.routes.map(({ path, method, handler }: RouterRoute) => {
29
+ const targetHandler = findTargetHandler(handler)
30
+ return {
31
+ path,
32
+ method,
33
+ name: handlerName(targetHandler),
34
+ isMiddleware: isMiddleware(targetHandler),
35
+ }
36
+ })
37
+ }
38
+
39
+ export const showRoutes = <E extends Env>(acryl: Acryl<E>, opts?: ShowRoutesOptions): void => {
40
+ const colorEnabled = opts?.colorize ?? getColorEnabled()
41
+ const routeData: Record<string, RouteData[]> = {}
42
+ let maxMethodLength = 0
43
+ let maxPathLength = 0
44
+
45
+ inspectRoutes(acryl)
46
+ .filter(({ isMiddleware }) => opts?.verbose || !isMiddleware)
47
+ .map((route) => {
48
+ const key = `${route.method}-${route.path}`
49
+ ;(routeData[key] ||= []).push(route)
50
+ if (routeData[key].length > 1) {
51
+ return
52
+ }
53
+ maxMethodLength = Math.max(maxMethodLength, route.method.length)
54
+ maxPathLength = Math.max(maxPathLength, route.path.length)
55
+ return { method: route.method, path: route.path, routes: routeData[key] }
56
+ })
57
+ .forEach((data) => {
58
+ if (!data) {
59
+ return
60
+ }
61
+ const { method, path, routes } = data
62
+
63
+ const methodStr = colorEnabled ? `\x1b[32m${method}\x1b[0m` : method
64
+ console.log(`${methodStr} ${' '.repeat(maxMethodLength - method.length)} ${path}`)
65
+
66
+ if (!opts?.verbose) {
67
+ return
68
+ }
69
+
70
+ routes.forEach(({ name }) => {
71
+ console.log(`${' '.repeat(maxMethodLength + 3)} ${name}`)
72
+ })
73
+ })
74
+ }
75
+
76
+ export const getRouterName = <E extends Env>(app: Acryl<E>): string => {
77
+ app.router.match('GET', '/')
78
+ return app.router.name
79
+ }