acrylblends 0.4.1 → 0.5.1
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/LICENSE +73 -0
- package/README.md +325 -0
- package/docs/framework/README.md +51 -51
- package/docs/framework/UPSTREAM.md +1 -1
- package/docs/framework/agents/index.md +24 -0
- package/docs/framework/api/acryl.md +259 -0
- package/docs/framework/api/context.md +527 -0
- package/docs/framework/api/exception.md +80 -0
- package/docs/framework/api/index.md +12 -0
- package/docs/framework/api/presets.md +65 -0
- package/docs/framework/api/request.md +396 -0
- package/docs/framework/api/routing.md +303 -0
- package/docs/framework/{api-summary.md → api/summary.md} +19 -17
- package/docs/framework/concepts/benchmarks.md +26 -0
- package/docs/framework/concepts/developer-experience.md +5 -0
- package/docs/framework/concepts/middleware.md +21 -0
- package/docs/framework/concepts/motivation.md +14 -0
- package/docs/framework/concepts/routers.md +63 -0
- package/docs/framework/concepts/stacks.md +235 -0
- package/docs/framework/concepts/web-standard.md +37 -0
- package/docs/framework/{getting-started.md → cordis/acryl-in-a-cordis-app.md} +16 -16
- package/docs/framework/{concepts.md → cordis/concepts.md} +2 -2
- package/docs/framework/cordis/middleware.md +8 -0
- package/docs/framework/{migration-from-0-3.md → cordis/migration-from-0-3.md} +16 -13
- package/docs/framework/cordis/migration-from-0-4.md +14 -0
- package/docs/framework/{migration-from-dsh-webserver.md → cordis/migration-from-dsh-webserver.md} +13 -7
- package/docs/framework/{routing.md → cordis/mounting.md} +5 -108
- package/docs/framework/{node-server.md → cordis/node-server.md} +4 -4
- package/docs/framework/{surfaces.md → cordis/surfaces.md} +2 -2
- package/docs/framework/cordis/transport-and-cancellation.md +57 -0
- package/docs/framework/{validation.md → cordis/validation.md} +9 -9
- package/docs/framework/getting-started/basic.md +196 -0
- package/docs/framework/getting-started/bun.md +221 -0
- package/docs/framework/getting-started/nodejs.md +344 -0
- package/docs/framework/getting-started/other-runtimes.md +23 -0
- package/docs/framework/guides/best-practices.md +231 -0
- package/docs/framework/guides/create-acrylblends.md +79 -0
- package/docs/framework/guides/examples.md +3 -0
- package/docs/framework/guides/faq.md +19 -0
- package/docs/framework/guides/helpers.md +33 -0
- package/docs/framework/guides/jsx-dom.md +299 -0
- package/docs/framework/guides/jsx.md +440 -0
- package/docs/framework/guides/middleware.md +253 -0
- package/docs/framework/guides/rpc.md +886 -0
- package/docs/framework/guides/testing.md +133 -0
- package/docs/framework/guides/validation.md +383 -0
- package/docs/framework/helpers/accepts.md +60 -0
- package/docs/framework/helpers/adapter.md +87 -0
- package/docs/framework/helpers/conninfo.md +112 -0
- package/docs/framework/helpers/cookie.md +232 -0
- package/docs/framework/helpers/css.md +285 -0
- package/docs/framework/helpers/dev.md +67 -0
- package/docs/framework/helpers/factory.md +180 -0
- package/docs/framework/helpers/html.md +123 -0
- package/docs/framework/helpers/jwt.md +184 -0
- package/docs/framework/helpers/proxy.md +118 -0
- package/docs/framework/helpers/route.md +143 -0
- package/docs/framework/helpers/ssg.md +393 -0
- package/docs/framework/helpers/streaming.md +119 -0
- package/docs/framework/helpers/testing.md +101 -0
- package/docs/framework/helpers/websocket.md +215 -0
- package/docs/framework/middleware/builtin/basic-auth.md +165 -0
- package/docs/framework/middleware/builtin/bearer-auth.md +138 -0
- package/docs/framework/middleware/builtin/body-limit.md +71 -0
- package/docs/framework/middleware/builtin/cache.md +122 -0
- package/docs/framework/middleware/builtin/combine.md +94 -0
- package/docs/framework/middleware/builtin/compress.md +59 -0
- package/docs/framework/middleware/builtin/context-storage.md +78 -0
- package/docs/framework/middleware/builtin/cors.md +135 -0
- package/docs/framework/middleware/builtin/csrf.md +105 -0
- package/docs/framework/middleware/builtin/etag.md +54 -0
- package/docs/framework/middleware/builtin/ip-restriction.md +69 -0
- package/docs/framework/middleware/builtin/jsx-renderer.md +286 -0
- package/docs/framework/middleware/builtin/jwk.md +192 -0
- package/docs/framework/middleware/builtin/jwt.md +145 -0
- package/docs/framework/middleware/builtin/language.md +232 -0
- package/docs/framework/middleware/builtin/logger.md +74 -0
- package/docs/framework/middleware/builtin/loopback-only.md +31 -0
- package/docs/framework/middleware/builtin/method-not-allowed.md +48 -0
- package/docs/framework/middleware/builtin/method-override.md +80 -0
- package/docs/framework/middleware/builtin/mount.md +106 -0
- package/docs/framework/middleware/builtin/pretty-json.md +53 -0
- package/docs/framework/middleware/builtin/request-id.md +94 -0
- package/docs/framework/middleware/builtin/secure-headers.md +247 -0
- package/docs/framework/middleware/builtin/timeout.md +98 -0
- package/docs/framework/middleware/builtin/timing.md +101 -0
- package/docs/framework/middleware/builtin/trailing-slash.md +74 -0
- package/docs/framework/middleware/third-party.md +4 -0
- package/docs/framework/upstream.json +3 -3
- package/lib/accepts-XBuZPVRI.js +52 -0
- package/lib/accepts.d.ts +33 -0
- package/lib/accepts.js +2 -0
- package/lib/acryl-base.d.ts +2 -0
- package/lib/acryl-base.js +332 -0
- package/lib/adapter.d.ts +12 -0
- package/lib/adapter.js +37 -0
- package/lib/app-BM0rTCp7.js +26 -0
- package/lib/app-CmAYW1Al.d.ts +21 -0
- package/lib/basic-auth.d.ts +72 -0
- package/lib/basic-auth.js +95 -0
- package/lib/bearer-auth.d.ts +89 -0
- package/lib/bearer-auth.js +94 -0
- package/lib/body-limit.d.ts +42 -0
- package/lib/body-limit.js +66 -0
- package/lib/client-BHTr318g.js +266 -0
- package/lib/client.d.ts +3 -0
- package/lib/client.js +2 -0
- package/lib/combine.d.ts +85 -0
- package/lib/combine.js +137 -0
- package/lib/compose-BuW2B6PZ.js +50 -0
- package/lib/compress.d.ts +38 -0
- package/lib/compress.js +79 -0
- package/lib/connection-C7xgP1hP.js +24 -0
- package/lib/conninfo.d.ts +25 -0
- package/lib/conninfo.js +2 -0
- package/lib/constants-Dy7ZvN1H.js +4 -0
- package/lib/context-Bm7rI-oK.d.ts +1234 -0
- package/lib/context-DDO0cfuP.js +365 -0
- package/lib/context-storage.d.ts +38 -0
- package/lib/context-storage.js +52 -0
- package/lib/cookie-ClMaKDQf.d.ts +40 -0
- package/lib/cookie.d.ts +24 -0
- package/lib/cookie.js +82 -0
- package/lib/cors.d.ts +52 -0
- package/lib/cors.js +106 -0
- package/lib/csrf.d.ts +75 -0
- package/lib/csrf.js +101 -0
- package/lib/etag.d.ts +40 -0
- package/lib/etag.js +135 -0
- package/lib/factory.d.ts +35 -0
- package/lib/factory.js +30 -0
- package/lib/headers-tu2YYN8T.d.ts +11 -0
- package/lib/html.d.ts +6 -0
- package/lib/html.js +31 -0
- package/lib/http-exception.d.ts +57 -0
- package/lib/http-exception.js +54 -0
- package/lib/http-status-DaAwGAFL.d.ts +35 -0
- package/lib/index-B-3F4wt2.d.ts +12 -0
- package/lib/index-UTBmM3GX.d.ts +68 -0
- package/lib/index-oOClm_Xk.d.ts +45 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.js +28 -0
- package/lib/ip-restriction.d.ts +68 -0
- package/lib/ip-restriction.js +166 -0
- package/lib/jwk.d.ts +52 -0
- package/lib/jwk.js +117 -0
- package/lib/jwt-BGJBw5AF.js +403 -0
- package/lib/jwt-Dg493Tai.d.ts +51 -0
- package/lib/jwt.d.ts +72 -0
- package/lib/jwt.js +115 -0
- package/lib/language.d.ts +88 -0
- package/lib/language.js +198 -0
- package/lib/logger.d.ts +22 -0
- package/lib/logger.js +54 -0
- package/lib/loopback-only.d.ts +45 -0
- package/lib/loopback-only.js +90 -0
- package/lib/method-not-allowed.d.ts +47 -0
- package/lib/method-not-allowed.js +82 -0
- package/lib/method-override.d.ts +46 -0
- package/lib/method-override.js +103 -0
- package/lib/mime-BQOYHl-l.d.ts +72 -0
- package/lib/node-server/conninfo.d.ts +11 -0
- package/lib/node-server/conninfo.js +19 -0
- package/lib/node-server/serve-static.d.ts +19 -0
- package/lib/node-server/serve-static.js +2 -0
- package/lib/node-server.d.ts +103 -0
- package/lib/node-server.js +1325 -0
- package/lib/powered-by.d.ts +28 -0
- package/lib/powered-by.js +24 -0
- package/lib/pretty-json.d.ts +40 -0
- package/lib/pretty-json.js +39 -0
- package/lib/reg-exp-router-DC1R3qoY.js +363 -0
- package/lib/request-id.d.ts +45 -0
- package/lib/request-id.js +34 -0
- package/lib/request.d.ts +2 -0
- package/lib/request.js +323 -0
- package/lib/route.d.ts +78 -0
- package/lib/route.js +126 -0
- package/lib/router/linear-router.d.ts +11 -0
- package/lib/router/linear-router.js +96 -0
- package/lib/router/pattern-router.d.ts +11 -0
- package/lib/router/pattern-router.js +41 -0
- package/lib/router/reg-exp-router.d.ts +35 -0
- package/lib/router/reg-exp-router.js +2 -0
- package/lib/router/smart-router.d.ts +15 -0
- package/lib/router/smart-router.js +2 -0
- package/lib/router/trie-router.d.ts +11 -0
- package/lib/router/trie-router.js +2 -0
- package/lib/router-CvUxUTOq.d.ts +99 -0
- package/lib/router.d.ts +2 -0
- package/lib/router.js +35 -0
- package/lib/schema-validator.d.ts +28 -0
- package/lib/schema-validator.js +22 -0
- package/lib/secure-headers.d.ts +125 -0
- package/lib/secure-headers.js +163 -0
- package/lib/serve-static-Dw_m6KxR.js +213 -0
- package/lib/serve-static.d.ts +31 -0
- package/lib/serve-static.js +77 -0
- package/lib/smart-router-C5CZ5XSM.js +49 -0
- package/lib/stream-CPdqZ0Fp.d.ts +34 -0
- package/lib/streaming-DHST3Scg.js +96 -0
- package/lib/streaming.d.ts +23 -0
- package/lib/streaming.js +2 -0
- package/lib/testing.d.ts +10 -0
- package/lib/testing.js +17 -0
- package/lib/timeout.d.ts +30 -0
- package/lib/timeout.js +42 -0
- package/lib/timing.d.ts +130 -0
- package/lib/timing.js +183 -0
- package/lib/trailing-slash.d.ts +91 -0
- package/lib/trailing-slash.js +85 -0
- package/lib/trie-router-CfFbapzL.js +146 -0
- package/lib/types-CDO6I3B0.d.ts +40 -0
- package/lib/types-CHesD1KG.d.ts +195 -0
- package/lib/types-CwrQjlaM.d.ts +105 -0
- package/lib/types-DR95J00T.d.ts +29 -0
- package/lib/types.d.ts +2 -0
- package/lib/types.js +4 -0
- package/lib/utils/accept.d.ts +9 -0
- package/lib/utils/accept.js +193 -0
- package/lib/utils/basic-auth.d.ts +8 -0
- package/lib/utils/basic-auth.js +20 -0
- package/lib/utils/body.d.ts +2 -0
- package/lib/utils/body.js +94 -0
- package/lib/utils/buffer.d.ts +19 -0
- package/lib/utils/buffer.js +51 -0
- package/lib/utils/color.d.ts +24 -0
- package/lib/utils/color.js +37 -0
- package/lib/utils/compress.d.ts +11 -0
- package/lib/utils/compress.js +11 -0
- package/lib/utils/concurrent.d.ts +17 -0
- package/lib/utils/concurrent.js +30 -0
- package/lib/utils/constants.d.ts +7 -0
- package/lib/utils/constants.js +7 -0
- package/lib/utils/cookie.d.ts +2 -0
- package/lib/utils/cookie.js +125 -0
- package/lib/utils/crypto.d.ts +14 -0
- package/lib/utils/crypto.js +34 -0
- package/lib/utils/encode.d.ts +11 -0
- package/lib/utils/encode.js +33 -0
- package/lib/utils/filepath.d.ts +14 -0
- package/lib/utils/filepath.js +25 -0
- package/lib/utils/handler.d.ts +9 -0
- package/lib/utils/handler.js +12 -0
- package/lib/utils/headers.d.ts +2 -0
- package/lib/utils/headers.js +1 -0
- package/lib/utils/html.d.ts +46 -0
- package/lib/utils/html.js +103 -0
- package/lib/utils/http-status.d.ts +2 -0
- package/lib/utils/http-status.js +1 -0
- package/lib/utils/ipaddr.d.ts +56 -0
- package/lib/utils/ipaddr.js +238 -0
- package/lib/utils/jwt.d.ts +24 -0
- package/lib/utils/jwt.js +2 -0
- package/lib/utils/mime.d.ts +2 -0
- package/lib/utils/mime.js +77 -0
- package/lib/utils/stream.d.ts +2 -0
- package/lib/utils/stream.js +88 -0
- package/lib/utils/types.d.ts +2 -0
- package/lib/utils/types.js +1 -0
- package/lib/utils/url.d.ts +46 -0
- package/lib/utils/url.js +197 -0
- package/lib/utils-dw8lxqjL.js +4 -0
- package/lib/validator-D84mq-dO.js +65 -0
- package/lib/validator.d.ts +42 -0
- package/lib/validator.js +2 -0
- package/lib/ws.d.ts +2 -0
- package/lib/ws.js +53 -0
- package/package.json +312 -14
- package/plugins/acryl-inspect/src/service.ts +2 -2
- package/plugins/acryl-inspect/tests/service.spec.ts +3 -3
- package/plugins/acryl-inspect/upstream.json +2 -2
- package/plugins/acryl-node-server/tests/adapter/app.ts +2 -2
- package/plugins/acryl-node-server/tests/adapter/assets/static/acryl.html +1 -1
- package/plugins/acryl-node-server/tests/adapter/assets/static/index.html +1 -1
- package/plugins/acryl-node-server/tests/adapter/conninfo.test.ts +2 -2
- package/plugins/acryl-node-server/tests/adapter/content-length.test.ts +4 -4
- package/plugins/acryl-node-server/tests/adapter/early-hints.test.ts +5 -5
- package/plugins/acryl-node-server/tests/adapter/request-client-disconnect.test.ts +2 -2
- package/plugins/acryl-node-server/tests/adapter/serve-static.test.ts +20 -20
- package/plugins/acryl-node-server/tests/adapter/server-socket.test.ts +2 -2
- package/plugins/acryl-node-server/tests/adapter/server.test.ts +60 -50
- package/plugins/acryl-node-server/tests/adapter/utils/response.test.ts +4 -4
- package/plugins/acryl-node-server/tests/adapter/websocket.test.ts +9 -9
- package/plugins/acryl-node-server/tests/server.spec.ts +6 -6
- package/plugins/acryl-node-server/upstream.json +2 -2
- package/plugins/acryl-router/src/client.ts +1 -1
- package/plugins/acryl-router/src/connection.ts +2 -2
- package/plugins/acryl-router/src/core/app-base.ts +29 -29
- package/plugins/acryl-router/src/core/app.test.ts +175 -175
- package/plugins/acryl-router/src/core/app.ts +8 -8
- package/plugins/acryl-router/src/core/client/client.test.ts +76 -76
- package/plugins/acryl-router/src/core/client/client.ts +2 -2
- package/plugins/acryl-router/src/core/client/fetch-result-please.ts +1 -1
- package/plugins/acryl-router/src/core/client/index.ts +1 -1
- package/plugins/acryl-router/src/core/client/types.test.ts +6 -6
- package/plugins/acryl-router/src/core/client/types.ts +16 -16
- package/plugins/acryl-router/src/core/client/utils.test.ts +2 -2
- package/plugins/acryl-router/src/core/context.test.ts +4 -4
- package/plugins/acryl-router/src/core/context.ts +6 -6
- package/plugins/acryl-router/src/core/helper/accepts/accepts.test.ts +3 -3
- package/plugins/acryl-router/src/core/helper/accepts/index.ts +1 -1
- package/plugins/acryl-router/src/core/helper/adapter/index.test.ts +6 -6
- package/plugins/acryl-router/src/core/helper/adapter/index.ts +1 -1
- package/plugins/acryl-router/src/core/helper/conninfo/index.ts +1 -1
- package/plugins/acryl-router/src/core/helper/cookie/index.test.ts +8 -8
- package/plugins/acryl-router/src/core/helper/cookie/index.ts +1 -1
- package/plugins/acryl-router/src/core/helper/factory/index.test.ts +9 -9
- package/plugins/acryl-router/src/core/helper/factory/index.ts +10 -10
- package/plugins/acryl-router/src/core/helper/html/index.test.ts +4 -4
- package/plugins/acryl-router/src/core/helper/html/index.ts +1 -1
- package/plugins/acryl-router/src/core/helper/route/index.test.ts +7 -7
- package/plugins/acryl-router/src/core/helper/route/index.ts +8 -8
- package/plugins/acryl-router/src/core/helper/streaming/index.ts +1 -1
- package/plugins/acryl-router/src/core/helper/testing/index.test.ts +6 -6
- package/plugins/acryl-router/src/core/helper/testing/index.ts +4 -4
- package/plugins/acryl-router/src/core/helper/websocket/index.ts +2 -1
- package/plugins/acryl-router/src/core/http-exception.ts +1 -1
- package/plugins/acryl-router/src/core/index.ts +9 -9
- package/plugins/acryl-router/src/core/middleware/basic-auth/index.test.ts +6 -6
- package/plugins/acryl-router/src/core/middleware/basic-auth/index.ts +3 -3
- package/plugins/acryl-router/src/core/middleware/bearer-auth/index.test.ts +5 -5
- package/plugins/acryl-router/src/core/middleware/bearer-auth/index.ts +3 -3
- package/plugins/acryl-router/src/core/middleware/body-limit/index.test.ts +6 -6
- package/plugins/acryl-router/src/core/middleware/body-limit/index.ts +3 -3
- package/plugins/acryl-router/src/core/middleware/combine/index.test.ts +9 -9
- package/plugins/acryl-router/src/core/middleware/combine/index.ts +7 -7
- package/plugins/acryl-router/src/core/middleware/compress/index.test.ts +9 -9
- package/plugins/acryl-router/src/core/middleware/compress/index.ts +3 -3
- package/plugins/acryl-router/src/core/middleware/context-storage/index.test.ts +5 -5
- package/plugins/acryl-router/src/core/middleware/context-storage/index.ts +4 -4
- package/plugins/acryl-router/src/core/middleware/cors/index.test.ts +7 -7
- package/plugins/acryl-router/src/core/middleware/cors/index.ts +3 -3
- package/plugins/acryl-router/src/core/middleware/csrf/index.test.ts +10 -10
- package/plugins/acryl-router/src/core/middleware/csrf/index.ts +3 -3
- package/plugins/acryl-router/src/core/middleware/etag/index.test.ts +42 -42
- package/plugins/acryl-router/src/core/middleware/etag/index.ts +4 -4
- package/plugins/acryl-router/src/core/middleware/ip-restriction/index.test.ts +4 -4
- package/plugins/acryl-router/src/core/middleware/ip-restriction/index.ts +6 -6
- package/plugins/acryl-router/src/core/middleware/jwk/index.test.ts +16 -16
- package/plugins/acryl-router/src/core/middleware/jwk/jwk.ts +7 -6
- package/plugins/acryl-router/src/core/middleware/jwt/index.test.ts +16 -16
- package/plugins/acryl-router/src/core/middleware/jwt/jwt.ts +4 -3
- package/plugins/acryl-router/src/core/middleware/language/index.test.ts +3 -3
- package/plugins/acryl-router/src/core/middleware/language/language.ts +3 -3
- package/plugins/acryl-router/src/core/middleware/logger/index.test.ts +5 -5
- package/plugins/acryl-router/src/core/middleware/logger/index.ts +4 -4
- package/plugins/acryl-router/src/core/middleware/method-not-allowed/index.test.ts +24 -24
- package/plugins/acryl-router/src/core/middleware/method-not-allowed/index.ts +8 -8
- package/plugins/acryl-router/src/core/middleware/method-override/index.test.ts +5 -5
- package/plugins/acryl-router/src/core/middleware/method-override/index.ts +6 -6
- package/plugins/acryl-router/src/core/middleware/powered-by/index.test.ts +4 -4
- package/plugins/acryl-router/src/core/middleware/powered-by/index.ts +6 -6
- package/plugins/acryl-router/src/core/middleware/pretty-json/index.test.ts +30 -30
- package/plugins/acryl-router/src/core/middleware/pretty-json/index.ts +4 -4
- package/plugins/acryl-router/src/core/middleware/request-id/index.test.ts +15 -15
- package/plugins/acryl-router/src/core/middleware/request-id/request-id.ts +3 -3
- package/plugins/acryl-router/src/core/middleware/secure-headers/index.test.ts +35 -35
- package/plugins/acryl-router/src/core/middleware/secure-headers/secure-headers.ts +3 -3
- package/plugins/acryl-router/src/core/middleware/serve-static/index.test.ts +23 -23
- package/plugins/acryl-router/src/core/middleware/serve-static/index.ts +1 -1
- package/plugins/acryl-router/src/core/middleware/timeout/index.test.ts +2 -2
- package/plugins/acryl-router/src/core/middleware/timeout/index.ts +3 -3
- package/plugins/acryl-router/src/core/middleware/timing/index.test.ts +14 -14
- package/plugins/acryl-router/src/core/middleware/timing/timing.ts +3 -3
- package/plugins/acryl-router/src/core/middleware/trailing-slash/index.test.ts +7 -7
- package/plugins/acryl-router/src/core/middleware/trailing-slash/index.ts +7 -7
- package/plugins/acryl-router/src/core/request.test.ts +42 -42
- package/plugins/acryl-router/src/core/request.ts +6 -6
- package/plugins/acryl-router/src/core/router/linear-router/index.ts +1 -1
- package/plugins/acryl-router/src/core/router/pattern-router/index.ts +1 -1
- package/plugins/acryl-router/src/core/router/reg-exp-router/index.ts +1 -1
- package/plugins/acryl-router/src/core/router/smart-router/index.ts +1 -1
- package/plugins/acryl-router/src/core/router/trie-router/index.ts +1 -1
- package/plugins/acryl-router/src/core/types.test.ts +115 -115
- package/plugins/acryl-router/src/core/types.ts +72 -72
- package/plugins/acryl-router/src/core/utils/body.ts +8 -8
- package/plugins/acryl-router/src/core/utils/html.ts +1 -1
- package/plugins/acryl-router/src/core/utils/jwt/jws.ts +3 -3
- package/plugins/acryl-router/src/core/utils/jwt/jwt.test.ts +2 -2
- package/plugins/acryl-router/src/core/utils/jwt/jwt.ts +3 -3
- package/plugins/acryl-router/src/core/utils/jwt/types.ts +1 -1
- package/plugins/acryl-router/src/core/utils/types.ts +42 -0
- package/plugins/acryl-router/src/core/utils/url.test.ts +2 -2
- package/plugins/acryl-router/src/core/validator/index.ts +1 -1
- package/plugins/acryl-router/src/core/validator/validator.test.ts +28 -28
- package/plugins/acryl-router/src/deprecated.ts +15 -0
- package/plugins/acryl-router/src/index.ts +3 -2
- package/plugins/acryl-router/src/service.ts +10 -10
- package/plugins/acryl-router/tests/docs-examples.spec.ts +11 -11
- package/plugins/acryl-router/tests/live-install.spec.ts +2 -2
- package/plugins/acryl-router/tests/loader.spec.ts +3 -3
- package/plugins/acryl-router/tests/loopback-only.spec.ts +4 -4
- package/plugins/acryl-router/tests/no-dom/consumer.ts +11 -0
- package/plugins/acryl-router/tests/no-dom/tsconfig.json +13 -0
- package/plugins/acryl-router/tests/service.spec.ts +23 -23
- package/plugins/acryl-router/upstream.json +3 -3
- package/plugins/acryl-router-http/tests/adapter.spec.ts +3 -3
- package/plugins/acryl-router-http/tests/surfaces.spec.ts +2 -2
- package/plugins/acryl-router-http/upstream.json +2 -2
- package/plugins/acryl-state/src/service.ts +2 -2
- package/plugins/acryl-state/upstream.json +2 -2
- package/plugins/builder/script.ts +2 -2
- package/plugins/extensions/resolve.ts +70 -10
- package/plugins/openai/prompt.ts +5 -5
- package/shared/AGENTS.core.md +16 -9
- package/templates/agent/src/routes.ts +2 -2
- package/templates/agent/test/model.test.ts +2 -2
- package/templates/agent/tsconfig.json +40 -0
- package/templates/blank/src/routes.ts +2 -2
- package/templates/todo/src/todo.ts +2 -2
- package/templates/todo/upstream.json +2 -2
- package/docs/framework/context.md +0 -129
- package/docs/framework/helpers.md +0 -118
- package/docs/framework/middleware.md +0 -154
- package/docs/framework/request.md +0 -106
- /package/docs/framework/{plugin-lifecycle.md → cordis/plugin-lifecycle.md} +0 -0
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {
|
|
1
|
+
import { AcrylBase } from './app-base.ts'
|
|
2
|
+
import type { AcrylOptions } from './app-base.ts'
|
|
3
3
|
import { RegExpRouter } from './router/reg-exp-router/index.ts'
|
|
4
4
|
import { SmartRouter } from './router/smart-router/index.ts'
|
|
5
5
|
import { TrieRouter } from './router/trie-router/index.ts'
|
|
6
6
|
import type { BlankEnv, BlankSchema, Env, Schema } from './types.ts'
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
* The
|
|
9
|
+
* The Acryl class extends the functionality of the AcrylBase class.
|
|
10
10
|
* It sets up routing and allows for custom options to be passed.
|
|
11
11
|
*
|
|
12
12
|
* @template E - The environment type.
|
|
13
13
|
* @template S - The schema type.
|
|
14
14
|
* @template BasePath - The base path type.
|
|
15
15
|
*/
|
|
16
|
-
export class
|
|
16
|
+
export class Acryl<
|
|
17
17
|
E extends Env = BlankEnv,
|
|
18
18
|
S extends Schema = BlankSchema,
|
|
19
19
|
BasePath extends string = '/',
|
|
20
|
-
> extends
|
|
20
|
+
> extends AcrylBase<E, S, BasePath> {
|
|
21
21
|
/**
|
|
22
|
-
* Creates an instance of the
|
|
22
|
+
* Creates an instance of the Acryl class.
|
|
23
23
|
*
|
|
24
|
-
* @param options - Optional configuration options for the
|
|
24
|
+
* @param options - Optional configuration options for the Acryl instance.
|
|
25
25
|
*/
|
|
26
|
-
constructor(options:
|
|
26
|
+
constructor(options: AcrylOptions<E> = {}) {
|
|
27
27
|
super(options)
|
|
28
28
|
this.router =
|
|
29
29
|
options.router ??
|
|
@@ -5,7 +5,7 @@ import { HttpResponse, http } from 'msw'
|
|
|
5
5
|
import { setupServer } from 'msw/node'
|
|
6
6
|
import { expectTypeOf, vi } from 'vitest'
|
|
7
7
|
import { defineWebSocketHelper } from '../helper/websocket/index.ts'
|
|
8
|
-
import {
|
|
8
|
+
import { Acryl } from '../app.ts'
|
|
9
9
|
import { parse } from '../utils/cookie.ts'
|
|
10
10
|
import type { Equal, Expect, JSONValue, SimplifyDeepArray } from '../utils/types.ts'
|
|
11
11
|
import { validator } from '../validator/index.ts'
|
|
@@ -32,7 +32,7 @@ class SafeBigInt {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
describe('Basic - JSON', () => {
|
|
35
|
-
const app = new
|
|
35
|
+
const app = new Acryl()
|
|
36
36
|
|
|
37
37
|
const route = app
|
|
38
38
|
.post(
|
|
@@ -58,7 +58,7 @@ describe('Basic - JSON', () => {
|
|
|
58
58
|
success: true,
|
|
59
59
|
message: 'dummy',
|
|
60
60
|
requestContentType: 'dummy',
|
|
61
|
-
|
|
61
|
+
requestAcryl: 'dummy',
|
|
62
62
|
requestMessage: 'dummy',
|
|
63
63
|
requestBody: {
|
|
64
64
|
id: 123,
|
|
@@ -78,14 +78,14 @@ describe('Basic - JSON', () => {
|
|
|
78
78
|
const server = setupServer(
|
|
79
79
|
http.post('http://localhost/posts', async ({ request }) => {
|
|
80
80
|
const requestContentType = request.headers.get('content-type')
|
|
81
|
-
const
|
|
81
|
+
const requestAcryl = request.headers.get('x-acryl')
|
|
82
82
|
const requestMessage = request.headers.get('x-message')
|
|
83
83
|
const requestBody = await request.json()
|
|
84
84
|
const payload = {
|
|
85
85
|
message: 'Hello!',
|
|
86
86
|
success: true,
|
|
87
87
|
requestContentType,
|
|
88
|
-
|
|
88
|
+
requestAcryl,
|
|
89
89
|
requestMessage,
|
|
90
90
|
requestBody,
|
|
91
91
|
}
|
|
@@ -128,7 +128,7 @@ describe('Basic - JSON', () => {
|
|
|
128
128
|
|
|
129
129
|
const payload = {
|
|
130
130
|
id: 123,
|
|
131
|
-
title: 'Hello!
|
|
131
|
+
title: 'Hello! Acryl!',
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
const client = hc<AppType>('http://localhost', { headers: { 'x-acryl': 'acryl' } })
|
|
@@ -152,7 +152,7 @@ describe('Basic - JSON', () => {
|
|
|
152
152
|
expect(data.success).toBe(true)
|
|
153
153
|
expect(data.message).toBe('Hello!')
|
|
154
154
|
expect(data.requestContentType).toBe('application/json')
|
|
155
|
-
expect(data.
|
|
155
|
+
expect(data.requestAcryl).toBe('acryl')
|
|
156
156
|
expect(data.requestMessage).toBe('foobar')
|
|
157
157
|
expect(data.requestBody).toEqual(payload)
|
|
158
158
|
})
|
|
@@ -199,7 +199,7 @@ describe('Basic - JSON', () => {
|
|
|
199
199
|
})
|
|
200
200
|
|
|
201
201
|
it('Should have correct types - primitives', async () => {
|
|
202
|
-
const app = new
|
|
202
|
+
const app = new Acryl()
|
|
203
203
|
const route = app
|
|
204
204
|
.get('/api/string', (c) => c.json('a-string'))
|
|
205
205
|
.get('/api/number', (c) => c.json(37))
|
|
@@ -232,7 +232,7 @@ describe('Basic - JSON', () => {
|
|
|
232
232
|
})
|
|
233
233
|
|
|
234
234
|
describe('Basic - query, queries, form, path params, header and cookie', () => {
|
|
235
|
-
const app = new
|
|
235
|
+
const app = new Acryl()
|
|
236
236
|
|
|
237
237
|
const route = app
|
|
238
238
|
.get(
|
|
@@ -387,15 +387,15 @@ describe('Basic - query, queries, form, path params, header and cookie', () => {
|
|
|
387
387
|
})
|
|
388
388
|
|
|
389
389
|
describe('Basic - $url()', () => {
|
|
390
|
-
const api = new
|
|
391
|
-
const content = new
|
|
390
|
+
const api = new Acryl().get('/', (c) => c.text('API')).get('/posts/:id', (c) => c.text('Post'))
|
|
391
|
+
const content = new Acryl().get(
|
|
392
392
|
'/search',
|
|
393
393
|
validator('query', () => {
|
|
394
394
|
return { page: '1', limit: '10' }
|
|
395
395
|
}),
|
|
396
396
|
(c) => c.text('Search')
|
|
397
397
|
)
|
|
398
|
-
const app = new
|
|
398
|
+
const app = new Acryl()
|
|
399
399
|
.get('/', (c) => c.text('Index'))
|
|
400
400
|
.route('/api', api)
|
|
401
401
|
.route('/content', content)
|
|
@@ -525,7 +525,7 @@ describe('Form - Undefined Values', () => {
|
|
|
525
525
|
})
|
|
526
526
|
|
|
527
527
|
describe('Form arrays containing undefined', () => {
|
|
528
|
-
const app = new
|
|
528
|
+
const app = new Acryl().post(
|
|
529
529
|
'/',
|
|
530
530
|
validator('form', () => ({}) as { tag: (string | undefined)[] | undefined }),
|
|
531
531
|
async (c) => {
|
|
@@ -557,7 +557,7 @@ describe('Form arrays containing undefined', () => {
|
|
|
557
557
|
})
|
|
558
558
|
|
|
559
559
|
describe('Optional header and cookie values', () => {
|
|
560
|
-
const app = new
|
|
560
|
+
const app = new Acryl().get(
|
|
561
561
|
'/',
|
|
562
562
|
validator('header', () => {
|
|
563
563
|
return {} as {
|
|
@@ -603,7 +603,7 @@ describe('Optional header and cookie values', () => {
|
|
|
603
603
|
})
|
|
604
604
|
|
|
605
605
|
it('Should not send a Cookie header if all cookie values are undefined', async () => {
|
|
606
|
-
const app = new
|
|
606
|
+
const app = new Acryl().get(
|
|
607
607
|
'/',
|
|
608
608
|
validator('cookie', () => {
|
|
609
609
|
return {} as {
|
|
@@ -626,7 +626,7 @@ describe('Optional header and cookie values', () => {
|
|
|
626
626
|
})
|
|
627
627
|
|
|
628
628
|
describe('Infer the response/request type', () => {
|
|
629
|
-
const app = new
|
|
629
|
+
const app = new Acryl()
|
|
630
630
|
const route = app.get(
|
|
631
631
|
'/',
|
|
632
632
|
validator('query', () => {
|
|
@@ -768,8 +768,8 @@ describe('Merge path with `app.route()`', () => {
|
|
|
768
768
|
}
|
|
769
769
|
|
|
770
770
|
it('Should have correct types', async () => {
|
|
771
|
-
const api = new
|
|
772
|
-
const app = new
|
|
771
|
+
const api = new Acryl<Env>().get('/search', (c) => c.json({ ok: true }))
|
|
772
|
+
const app = new Acryl<Env>().route('/api', api)
|
|
773
773
|
type AppType = typeof app
|
|
774
774
|
const client = hc<AppType>('http://localhost')
|
|
775
775
|
const res = await client.api.search.$get()
|
|
@@ -779,7 +779,7 @@ describe('Merge path with `app.route()`', () => {
|
|
|
779
779
|
})
|
|
780
780
|
|
|
781
781
|
it('Should have correct types - basePath() then get()', async () => {
|
|
782
|
-
const base = new
|
|
782
|
+
const base = new Acryl<Env>().basePath('/api')
|
|
783
783
|
const app = base.get('/search', (c) => c.json({ ok: true }))
|
|
784
784
|
type AppType = typeof app
|
|
785
785
|
const client = hc<AppType>('http://localhost')
|
|
@@ -790,8 +790,8 @@ describe('Merge path with `app.route()`', () => {
|
|
|
790
790
|
})
|
|
791
791
|
|
|
792
792
|
it('Should have correct types - basePath(), route(), get()', async () => {
|
|
793
|
-
const book = new
|
|
794
|
-
const app = new
|
|
793
|
+
const book = new Acryl().get('/', (c) => c.json({ ok: true }))
|
|
794
|
+
const app = new Acryl().basePath('/v1').route('/book', book)
|
|
795
795
|
type AppType = typeof app
|
|
796
796
|
const client = hc<AppType>('http://localhost')
|
|
797
797
|
const res = await client.v1.book.$get()
|
|
@@ -806,7 +806,7 @@ describe('Merge path with `app.route()`', () => {
|
|
|
806
806
|
okUndefined?: boolean
|
|
807
807
|
}
|
|
808
808
|
const result: Result = { ok: true }
|
|
809
|
-
const base = new
|
|
809
|
+
const base = new Acryl<Env>().basePath('/api')
|
|
810
810
|
const app = base.get('/search', (c) => c.json(result))
|
|
811
811
|
type AppType = typeof app
|
|
812
812
|
const client = hc<AppType>('http://localhost')
|
|
@@ -840,7 +840,7 @@ describe('Merge path with `app.route()`', () => {
|
|
|
840
840
|
type Results = Result[]
|
|
841
841
|
|
|
842
842
|
const results: Results = [{ ok: true }]
|
|
843
|
-
const base = new
|
|
843
|
+
const base = new Acryl<Env>().basePath('/api')
|
|
844
844
|
const app = base.get('/searchArray', (c) => c.json(results))
|
|
845
845
|
type AppType = typeof app
|
|
846
846
|
const client = hc<AppType>('http://localhost')
|
|
@@ -865,7 +865,7 @@ describe('Merge path with `app.route()`', () => {
|
|
|
865
865
|
})
|
|
866
866
|
|
|
867
867
|
it('Should allow a Date object and return it as a string', async () => {
|
|
868
|
-
const app = new
|
|
868
|
+
const app = new Acryl()
|
|
869
869
|
const route = app.get('/api/foo', (c) => c.json({ datetime: new Date() }))
|
|
870
870
|
type AppType = typeof route
|
|
871
871
|
const client = hc<AppType>('http://localhost')
|
|
@@ -875,10 +875,10 @@ describe('Merge path with `app.route()`', () => {
|
|
|
875
875
|
})
|
|
876
876
|
|
|
877
877
|
describe('Multiple endpoints', () => {
|
|
878
|
-
const api = new
|
|
878
|
+
const api = new Acryl()
|
|
879
879
|
.get('/foo', (c) => c.json({ foo: '' }))
|
|
880
880
|
.post('/bar', (c) => c.json({ bar: 0 }))
|
|
881
|
-
const app = new
|
|
881
|
+
const app = new Acryl().route('/api', api)
|
|
882
882
|
type AppType = typeof app
|
|
883
883
|
const client = hc<typeof app>('http://localhost')
|
|
884
884
|
|
|
@@ -904,12 +904,12 @@ describe('Merge path with `app.route()`', () => {
|
|
|
904
904
|
})
|
|
905
905
|
|
|
906
906
|
describe('With a blank path', () => {
|
|
907
|
-
const app = new
|
|
907
|
+
const app = new Acryl().basePath('/api/v1')
|
|
908
908
|
const routes = app.route(
|
|
909
909
|
'/me',
|
|
910
|
-
new
|
|
910
|
+
new Acryl().route(
|
|
911
911
|
'',
|
|
912
|
-
new
|
|
912
|
+
new Acryl().get('', async (c) => {
|
|
913
913
|
return c.json({ name: 'acryl' })
|
|
914
914
|
})
|
|
915
915
|
)
|
|
@@ -929,12 +929,12 @@ describe('Merge path with `app.route()`', () => {
|
|
|
929
929
|
})
|
|
930
930
|
|
|
931
931
|
describe('With endpoint pathname', () => {
|
|
932
|
-
const app = new
|
|
932
|
+
const app = new Acryl().basePath('/api/v1')
|
|
933
933
|
const routes = app.route(
|
|
934
934
|
'/me',
|
|
935
|
-
new
|
|
935
|
+
new Acryl().route(
|
|
936
936
|
'',
|
|
937
|
-
new
|
|
937
|
+
new Acryl().get('', async (c) => {
|
|
938
938
|
return c.json({ name: 'acryl' })
|
|
939
939
|
})
|
|
940
940
|
)
|
|
@@ -958,8 +958,8 @@ describe('Use custom fetch method', () => {
|
|
|
958
958
|
it('Should call the custom fetch method when provided', async () => {
|
|
959
959
|
const fetchMock = vi.fn()
|
|
960
960
|
|
|
961
|
-
const api = new
|
|
962
|
-
const app = new
|
|
961
|
+
const api = new Acryl().get('/search', (c) => c.json({ ok: true }))
|
|
962
|
+
const app = new Acryl().route('/api', api)
|
|
963
963
|
type AppType = typeof app
|
|
964
964
|
const client = hc<AppType>('http://localhost', { fetch: fetchMock })
|
|
965
965
|
await client.api.search.$get()
|
|
@@ -971,8 +971,8 @@ describe('Use custom fetch method', () => {
|
|
|
971
971
|
const returnValue = new Response(null, { status: 200 })
|
|
972
972
|
fetchMock.mockReturnValueOnce(returnValue)
|
|
973
973
|
|
|
974
|
-
const api = new
|
|
975
|
-
const app = new
|
|
974
|
+
const api = new Acryl().get('/search', (c) => c.json({ ok: true }))
|
|
975
|
+
const app = new Acryl().route('/api', api)
|
|
976
976
|
type AppType = typeof app
|
|
977
977
|
const client = hc<AppType>('http://localhost', { fetch: fetchMock })
|
|
978
978
|
const res = await client.api.search.$get()
|
|
@@ -983,7 +983,7 @@ describe('Use custom fetch method', () => {
|
|
|
983
983
|
|
|
984
984
|
describe('Use custom fetch (app.request) method', () => {
|
|
985
985
|
it('Should return Response from app request method', async () => {
|
|
986
|
-
const app = new
|
|
986
|
+
const app = new Acryl().get('/search', (c) => c.json({ ok: true }))
|
|
987
987
|
type AppType = typeof app
|
|
988
988
|
const client = hc<AppType>('', { fetch: app.request })
|
|
989
989
|
const res = await client.search.$get()
|
|
@@ -991,7 +991,7 @@ describe('Use custom fetch (app.request) method', () => {
|
|
|
991
991
|
})
|
|
992
992
|
|
|
993
993
|
it.each([false, 0, '', null])('Should send falsy JSON value: %j', async (json) => {
|
|
994
|
-
const app = new
|
|
994
|
+
const app = new Acryl().post(
|
|
995
995
|
'/json',
|
|
996
996
|
validator('json', (value) => value as boolean | number | string | null),
|
|
997
997
|
(c) => c.json(c.req.valid('json'))
|
|
@@ -1007,7 +1007,7 @@ describe('Use custom fetch (app.request) method', () => {
|
|
|
1007
1007
|
|
|
1008
1008
|
describe('Optional parameters in JSON response', () => {
|
|
1009
1009
|
it('Should return the correct type', async () => {
|
|
1010
|
-
const app = new
|
|
1010
|
+
const app = new Acryl().get('/', (c) => {
|
|
1011
1011
|
return c.json({ message: 'foo' } as { message?: string })
|
|
1012
1012
|
})
|
|
1013
1013
|
type AppType = typeof app
|
|
@@ -1022,7 +1022,7 @@ describe('Optional parameters in JSON response', () => {
|
|
|
1022
1022
|
|
|
1023
1023
|
describe('ClientResponse<T>.json() returns a Union type correctly', () => {
|
|
1024
1024
|
const condition = () => true
|
|
1025
|
-
const app = new
|
|
1025
|
+
const app = new Acryl().get('/', async (c) => {
|
|
1026
1026
|
const ok = condition()
|
|
1027
1027
|
if (ok) {
|
|
1028
1028
|
return c.json({ data: 'foo' })
|
|
@@ -1040,7 +1040,7 @@ describe('ClientResponse<T>.json() returns a Union type correctly', () => {
|
|
|
1040
1040
|
|
|
1041
1041
|
describe('Response with different status codes', () => {
|
|
1042
1042
|
const condition = () => true
|
|
1043
|
-
const app = new
|
|
1043
|
+
const app = new Acryl().get('/', async (c) => {
|
|
1044
1044
|
const ok = condition()
|
|
1045
1045
|
if (ok) {
|
|
1046
1046
|
return c.json({ data: 'foo' }, 200)
|
|
@@ -1094,7 +1094,7 @@ describe('Response with different status codes', () => {
|
|
|
1094
1094
|
|
|
1095
1095
|
describe('Infer the response type with different status codes', () => {
|
|
1096
1096
|
const condition = () => true
|
|
1097
|
-
const app = new
|
|
1097
|
+
const app = new Acryl().get('/', async (c) => {
|
|
1098
1098
|
const ok = condition()
|
|
1099
1099
|
if (ok) {
|
|
1100
1100
|
return c.json({ data: 'foo' }, 200)
|
|
@@ -1134,7 +1134,7 @@ describe('Infer the response type with different status codes', () => {
|
|
|
1134
1134
|
})
|
|
1135
1135
|
|
|
1136
1136
|
describe('Infer the response types from middlewares', () => {
|
|
1137
|
-
const app = new
|
|
1137
|
+
const app = new Acryl()
|
|
1138
1138
|
.get(
|
|
1139
1139
|
'/',
|
|
1140
1140
|
validator('query', (input, c) => {
|
|
@@ -1243,7 +1243,7 @@ const pathname = <T extends URL | string>(value: T): string =>
|
|
|
1243
1243
|
value instanceof URL ? value.pathname : value
|
|
1244
1244
|
|
|
1245
1245
|
describe.each(['$path', '$url'] as const)('%s() with a param option', (cmd) => {
|
|
1246
|
-
const app = new
|
|
1246
|
+
const app = new Acryl()
|
|
1247
1247
|
.get('/posts/:id/comments', (c) => c.json({ ok: true }))
|
|
1248
1248
|
.get('/something/:firstId/:secondId/:version?', (c) => c.json({ ok: true }))
|
|
1249
1249
|
.get('/docs/:page', (c) => c.json({ ok: true }))
|
|
@@ -1316,7 +1316,7 @@ describe.each(['$path', '$url'] as const)('%s() with a param option', (cmd) => {
|
|
|
1316
1316
|
})
|
|
1317
1317
|
|
|
1318
1318
|
describe('$url() / $path() with a query option', () => {
|
|
1319
|
-
const app = new
|
|
1319
|
+
const app = new Acryl()
|
|
1320
1320
|
.get(
|
|
1321
1321
|
'/posts',
|
|
1322
1322
|
validator('query', () => {
|
|
@@ -1378,12 +1378,12 @@ describe('Client can be awaited', () => {
|
|
|
1378
1378
|
})
|
|
1379
1379
|
|
|
1380
1380
|
describe('Dynamic headers', () => {
|
|
1381
|
-
const app = new
|
|
1381
|
+
const app = new Acryl()
|
|
1382
1382
|
|
|
1383
1383
|
const route = app.post('/posts', (c) => {
|
|
1384
1384
|
return c.json({
|
|
1385
1385
|
requestDynamic: 'dummy',
|
|
1386
|
-
|
|
1386
|
+
requestAcryl: 'dummy',
|
|
1387
1387
|
})
|
|
1388
1388
|
})
|
|
1389
1389
|
|
|
@@ -1392,10 +1392,10 @@ describe('Dynamic headers', () => {
|
|
|
1392
1392
|
const server = setupServer(
|
|
1393
1393
|
http.post('http://localhost/posts', async ({ request }) => {
|
|
1394
1394
|
const requestDynamic = request.headers.get('x-dynamic')
|
|
1395
|
-
const
|
|
1395
|
+
const requestAcryl = request.headers.get('x-acryl')
|
|
1396
1396
|
const payload = {
|
|
1397
1397
|
requestDynamic,
|
|
1398
|
-
|
|
1398
|
+
requestAcryl,
|
|
1399
1399
|
}
|
|
1400
1400
|
return HttpResponse.json(payload)
|
|
1401
1401
|
})
|
|
@@ -1440,7 +1440,7 @@ describe('Dynamic headers', () => {
|
|
|
1440
1440
|
|
|
1441
1441
|
expect(res.ok).toBe(true)
|
|
1442
1442
|
const data = await res.json()
|
|
1443
|
-
expect(data.
|
|
1443
|
+
expect(data.requestAcryl).toEqual('acryl')
|
|
1444
1444
|
expect(data.requestDynamic).toEqual('request')
|
|
1445
1445
|
})
|
|
1446
1446
|
|
|
@@ -1456,7 +1456,7 @@ describe('Dynamic headers', () => {
|
|
|
1456
1456
|
|
|
1457
1457
|
expect(res.ok).toBe(true)
|
|
1458
1458
|
const data = await res.json()
|
|
1459
|
-
expect(data.
|
|
1459
|
+
expect(data.requestAcryl).toEqual('acryl')
|
|
1460
1460
|
expect(data.requestDynamic).toEqual('request')
|
|
1461
1461
|
})
|
|
1462
1462
|
|
|
@@ -1472,7 +1472,7 @@ describe('Dynamic headers', () => {
|
|
|
1472
1472
|
|
|
1473
1473
|
expect(res.ok).toBe(true)
|
|
1474
1474
|
const data = await res.json()
|
|
1475
|
-
expect(data.
|
|
1475
|
+
expect(data.requestAcryl).toEqual('acryl')
|
|
1476
1476
|
expect(data.requestDynamic).toEqual('request')
|
|
1477
1477
|
})
|
|
1478
1478
|
|
|
@@ -1485,12 +1485,12 @@ describe('Dynamic headers', () => {
|
|
|
1485
1485
|
|
|
1486
1486
|
expect(res.ok).toBe(true)
|
|
1487
1487
|
const data = await res.json()
|
|
1488
|
-
expect(data.
|
|
1488
|
+
expect(data.requestAcryl).toEqual('request')
|
|
1489
1489
|
})
|
|
1490
1490
|
})
|
|
1491
1491
|
|
|
1492
1492
|
describe('RequestInit work as expected', () => {
|
|
1493
|
-
const app = new
|
|
1493
|
+
const app = new Acryl()
|
|
1494
1494
|
|
|
1495
1495
|
const route = app
|
|
1496
1496
|
.get('/credentials', (c) => {
|
|
@@ -1583,7 +1583,7 @@ describe('RequestInit work as expected', () => {
|
|
|
1583
1583
|
})
|
|
1584
1584
|
|
|
1585
1585
|
describe('WebSocket URL Protocol Translation', () => {
|
|
1586
|
-
const app = new
|
|
1586
|
+
const app = new Acryl()
|
|
1587
1587
|
const route = app.get(
|
|
1588
1588
|
'/',
|
|
1589
1589
|
upgradeWebSocket((c) => ({
|
|
@@ -1637,7 +1637,7 @@ describe('WebSocket URL Protocol Translation', () => {
|
|
|
1637
1637
|
})
|
|
1638
1638
|
|
|
1639
1639
|
it('Preserves an index path parameter value', async () => {
|
|
1640
|
-
const dynamicRoute = new
|
|
1640
|
+
const dynamicRoute = new Acryl().get(
|
|
1641
1641
|
'/:id',
|
|
1642
1642
|
upgradeWebSocket(() => ({}))
|
|
1643
1643
|
)
|
|
@@ -1650,7 +1650,7 @@ describe('WebSocket URL Protocol Translation', () => {
|
|
|
1650
1650
|
})
|
|
1651
1651
|
|
|
1652
1652
|
describe('WebSocket URL Protocol Translation with Query Parameters', () => {
|
|
1653
|
-
const app = new
|
|
1653
|
+
const app = new Acryl()
|
|
1654
1654
|
const route = app.get(
|
|
1655
1655
|
'/',
|
|
1656
1656
|
upgradeWebSocket((c) => ({
|
|
@@ -1749,7 +1749,7 @@ describe('Client can be console.log in react native', () => {
|
|
|
1749
1749
|
})
|
|
1750
1750
|
|
|
1751
1751
|
describe('Text response', () => {
|
|
1752
|
-
const text = 'My name is
|
|
1752
|
+
const text = 'My name is Acryl'
|
|
1753
1753
|
const obj = { ok: true }
|
|
1754
1754
|
const server = setupServer(
|
|
1755
1755
|
http.get('http://localhost/about/me', async () => {
|
|
@@ -1764,7 +1764,7 @@ describe('Text response', () => {
|
|
|
1764
1764
|
afterEach(() => server.resetHandlers())
|
|
1765
1765
|
afterAll(() => server.close())
|
|
1766
1766
|
|
|
1767
|
-
const app = new
|
|
1767
|
+
const app = new Acryl().get('/about/me', (c) => c.text(text)).get('/api', (c) => c.json(obj))
|
|
1768
1768
|
const client = hc<typeof app>('http://localhost/')
|
|
1769
1769
|
|
|
1770
1770
|
it('Should be never with res.json() - /about/me', async () => {
|
|
@@ -1777,7 +1777,7 @@ describe('Text response', () => {
|
|
|
1777
1777
|
it('Should be "Hello, World!" with res.text() - /about/me', async () => {
|
|
1778
1778
|
const res = await client.about.me.$get()
|
|
1779
1779
|
const data = await res.text()
|
|
1780
|
-
expectTypeOf(data).toEqualTypeOf<'My name is
|
|
1780
|
+
expectTypeOf(data).toEqualTypeOf<'My name is Acryl'>()
|
|
1781
1781
|
expect(data).toBe(text)
|
|
1782
1782
|
})
|
|
1783
1783
|
|
|
@@ -1804,7 +1804,7 @@ describe('Redirect response - only types', () => {
|
|
|
1804
1804
|
afterAll(() => server.close())
|
|
1805
1805
|
|
|
1806
1806
|
const condition = () => true
|
|
1807
|
-
const app = new
|
|
1807
|
+
const app = new Acryl().get('/', async (c) => {
|
|
1808
1808
|
const ok = condition()
|
|
1809
1809
|
const temporary = condition()
|
|
1810
1810
|
if (ok) {
|
|
@@ -1847,7 +1847,7 @@ describe('Redirect response - only types', () => {
|
|
|
1847
1847
|
})
|
|
1848
1848
|
|
|
1849
1849
|
describe('WebSocket Provider Integration', () => {
|
|
1850
|
-
const app = new
|
|
1850
|
+
const app = new Acryl()
|
|
1851
1851
|
const route = app.get(
|
|
1852
1852
|
'/',
|
|
1853
1853
|
upgradeWebSocket((c) => ({
|
|
@@ -1898,7 +1898,7 @@ describe('WebSocket Provider Integration', () => {
|
|
|
1898
1898
|
describe('Query arrays containing undefined', () => {
|
|
1899
1899
|
// A validator whose query field is an optional union gives the client an input
|
|
1900
1900
|
// type of `(string | undefined)[] | undefined`, so this compiles with no cast.
|
|
1901
|
-
const app = new
|
|
1901
|
+
const app = new Acryl().get(
|
|
1902
1902
|
'/search',
|
|
1903
1903
|
validator('query', () => ({}) as { tag: (string | undefined)[] | undefined }),
|
|
1904
1904
|
(c) => c.json({ ok: true })
|
|
@@ -1921,7 +1921,7 @@ describe('Query arrays containing undefined', () => {
|
|
|
1921
1921
|
})
|
|
1922
1922
|
|
|
1923
1923
|
describe('Empty serialized query', () => {
|
|
1924
|
-
const app = new
|
|
1924
|
+
const app = new Acryl().get(
|
|
1925
1925
|
'/search',
|
|
1926
1926
|
validator('query', () => ({}) as { q?: string }),
|
|
1927
1927
|
(c) => c.json({ ok: true })
|
|
@@ -1981,7 +1981,7 @@ describe('Empty serialized query', () => {
|
|
|
1981
1981
|
})
|
|
1982
1982
|
|
|
1983
1983
|
describe('Custom buildSearchParams', () => {
|
|
1984
|
-
const app = new
|
|
1984
|
+
const app = new Acryl()
|
|
1985
1985
|
const route = app.get(
|
|
1986
1986
|
'/search',
|
|
1987
1987
|
validator('query', () => {
|
|
@@ -2112,7 +2112,7 @@ describe('ApplyGlobalResponse Type Helper', () => {
|
|
|
2112
2112
|
|
|
2113
2113
|
it('Should add global error response types to all routes', () => {
|
|
2114
2114
|
// Use explicit status codes for proper type narrowing
|
|
2115
|
-
const app = new
|
|
2115
|
+
const app = new Acryl().get('/api/users', (c) => c.json({ users: ['alice', 'bob'] }, 200))
|
|
2116
2116
|
|
|
2117
2117
|
// Apply global error responses with new object syntax
|
|
2118
2118
|
type AppWithGlobalErrors = ApplyGlobalResponse<
|
|
@@ -2134,7 +2134,7 @@ describe('ApplyGlobalResponse Type Helper', () => {
|
|
|
2134
2134
|
})
|
|
2135
2135
|
|
|
2136
2136
|
it('Should support multiple global error status codes', async () => {
|
|
2137
|
-
const app = new
|
|
2137
|
+
const app = new Acryl()
|
|
2138
2138
|
.get('/api/users', (c) => c.json({ users: ['alice', 'bob'] }, 200))
|
|
2139
2139
|
.get('/api/unauthorized', (c) =>
|
|
2140
2140
|
c.json({ error: 'Unauthorized', message: 'Please login' }, 401)
|
|
@@ -2171,9 +2171,9 @@ describe('ApplyGlobalResponse Type Helper', () => {
|
|
|
2171
2171
|
})
|
|
2172
2172
|
|
|
2173
2173
|
it('Should work with onError handler pattern', () => {
|
|
2174
|
-
// Simulating typical
|
|
2174
|
+
// Simulating typical Acryl app with onError handler
|
|
2175
2175
|
// Use explicit status code for proper type narrowing
|
|
2176
|
-
const app = new
|
|
2176
|
+
const app = new Acryl().get('/api/users', (c) => c.json({ users: ['alice', 'bob'] }, 200))
|
|
2177
2177
|
|
|
2178
2178
|
// In real app: app.onError((err, c) => c.json({ error: err.message }, 500))
|
|
2179
2179
|
type AppWithOnError = ApplyGlobalResponse<
|
|
@@ -2194,8 +2194,8 @@ describe('ApplyGlobalResponse Type Helper', () => {
|
|
|
2194
2194
|
})
|
|
2195
2195
|
|
|
2196
2196
|
it('Should keep route() paths when global responses are applied', () => {
|
|
2197
|
-
const users = new
|
|
2198
|
-
const app = new
|
|
2197
|
+
const users = new Acryl().get('/users', (c) => c.json({ users: ['alice', 'bob'] }, 200))
|
|
2198
|
+
const app = new Acryl().route('/api', users)
|
|
2199
2199
|
|
|
2200
2200
|
type AppWithGlobalErrors = ApplyGlobalResponse<
|
|
2201
2201
|
typeof app,
|
|
@@ -2216,7 +2216,7 @@ describe('ApplyGlobalResponse Type Helper', () => {
|
|
|
2216
2216
|
|
|
2217
2217
|
describe('PickResponseByStatusCode Type Helper', () => {
|
|
2218
2218
|
it('Should keep only specified status code responses', () => {
|
|
2219
|
-
const app = new
|
|
2219
|
+
const app = new Acryl().get('/api/users', (c) => {
|
|
2220
2220
|
try {
|
|
2221
2221
|
return c.json({ users: ['alice', 'bob'] }, 200)
|
|
2222
2222
|
} catch {
|
|
@@ -2239,7 +2239,7 @@ describe('PickResponseByStatusCode Type Helper', () => {
|
|
|
2239
2239
|
})
|
|
2240
2240
|
|
|
2241
2241
|
it('Should work with ApplyGlobalResponse', () => {
|
|
2242
|
-
const app = new
|
|
2242
|
+
const app = new Acryl().get('/api/users', (c) => {
|
|
2243
2243
|
try {
|
|
2244
2244
|
return c.json({ users: ['alice', 'bob'] }, 200)
|
|
2245
2245
|
} catch {
|
|
@@ -2266,14 +2266,14 @@ describe('PickResponseByStatusCode Type Helper', () => {
|
|
|
2266
2266
|
})
|
|
2267
2267
|
|
|
2268
2268
|
it('Should work with route() paths', () => {
|
|
2269
|
-
const users = new
|
|
2269
|
+
const users = new Acryl().get('/users', (c) => {
|
|
2270
2270
|
try {
|
|
2271
2271
|
return c.json({ users: ['alice', 'bob'] }, 200)
|
|
2272
2272
|
} catch {
|
|
2273
2273
|
return c.json({ error: 'error' }, 500)
|
|
2274
2274
|
}
|
|
2275
2275
|
})
|
|
2276
|
-
const app = new
|
|
2276
|
+
const app = new Acryl().route('/api', users)
|
|
2277
2277
|
|
|
2278
2278
|
type AppSuccessOnly = PickResponseByStatusCode<typeof app, 200>
|
|
2279
2279
|
|
|
@@ -2286,7 +2286,7 @@ describe('PickResponseByStatusCode Type Helper', () => {
|
|
|
2286
2286
|
})
|
|
2287
2287
|
|
|
2288
2288
|
it('Should pick multiple status codes', () => {
|
|
2289
|
-
const app = new
|
|
2289
|
+
const app = new Acryl().get('/api/users', (c) => {
|
|
2290
2290
|
try {
|
|
2291
2291
|
return c.json({ users: ['alice', 'bob'] }, 200)
|
|
2292
2292
|
} catch {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Acryl } from '../app.ts'
|
|
2
2
|
import type { FormValue, ValidationTargets } from '../types.ts'
|
|
3
3
|
import { serialize } from '../utils/cookie.ts'
|
|
4
4
|
import type { UnionToIntersection } from '../utils/types.ts'
|
|
@@ -148,7 +148,7 @@ class ClientRequestImpl {
|
|
|
148
148
|
}
|
|
149
149
|
|
|
150
150
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
151
|
-
export const hc = <T extends
|
|
151
|
+
export const hc = <T extends Acryl<any, any, any>, Prefix extends string = string>(
|
|
152
152
|
baseUrl: Prefix,
|
|
153
153
|
options?: ClientRequestOptions
|
|
154
154
|
) =>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @description This file is a modified version of `fetch-result-please` (`ofetch`), minimalized and adapted to
|
|
2
|
+
* @description This file is a modified version of `fetch-result-please` (`ofetch`), minimalized and adapted to Acryl's custom needs.
|
|
3
3
|
*
|
|
4
4
|
* @link https://www.npmjs.com/package/fetch-result-please
|
|
5
5
|
*/
|