@acryldev/blends 0.0.0-stage → 1.7.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 +424 -2
- package/bin/acrylblends.js +12 -0
- package/dist/index.d.ts +231 -0
- package/dist/index.js +4505 -0
- package/dist/index.js.map +1 -0
- package/lib/accept-B13wFRkc.js +193 -0
- package/lib/accepts-BN4uue4T.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 +2 -0
- package/lib/adapter-Wt9Ntyhx.js +37 -0
- package/lib/adapter.d.ts +12 -0
- package/lib/adapter.js +2 -0
- package/lib/app-CM-rDcw6.js +26 -0
- package/lib/app-DGqSNBSd.d.ts +21 -0
- package/lib/app-base-BwplqlWX.js +332 -0
- package/lib/audit-B2H3sUfg.d.ts +136 -0
- package/lib/base-N-QVQhMZ.d.ts +783 -0
- package/lib/base-kl8P-za0.js +722 -0
- package/lib/basic-auth-ByZGvWGz.js +95 -0
- package/lib/basic-auth-CzulvSad.js +20 -0
- package/lib/basic-auth.d.ts +72 -0
- package/lib/basic-auth.js +2 -0
- package/lib/bearer-auth-CfR6YNqy.js +94 -0
- package/lib/bearer-auth.d.ts +89 -0
- package/lib/bearer-auth.js +2 -0
- package/lib/body-BQ-J23GI.js +94 -0
- package/lib/body-limit-DyO82Wes.js +66 -0
- package/lib/body-limit.d.ts +42 -0
- package/lib/body-limit.js +2 -0
- package/lib/browser/client.js +307 -0
- package/lib/browser/jsx-dom.js +1432 -0
- package/lib/browser/read-sse.js +84 -0
- package/lib/buffer-CWpxJrvI.js +51 -0
- package/lib/bun.d.ts +75 -0
- package/lib/bun.js +134 -0
- package/lib/cache-DllEV7kz.js +169 -0
- package/lib/cache.d.ts +43 -0
- package/lib/cache.js +2 -0
- package/lib/cell-wEBQA3d0.d.ts +32 -0
- package/lib/client-BMFCUlHG.js +143 -0
- package/lib/client-modules-ChLgW0l9.js +267 -0
- package/lib/client.d.ts +3 -0
- package/lib/client.js +3 -0
- package/lib/color-C26GR4OI.js +37 -0
- package/lib/combine-rXRCRMJx.js +137 -0
- package/lib/combine.d.ts +85 -0
- package/lib/combine.js +2 -0
- package/lib/common-CaqP5LIh.d.ts +46 -0
- package/lib/components-BZ8vBk_7.js +268 -0
- package/lib/components-Cq4hcRbo.js +24 -0
- package/lib/compose-DbuvN1rE.js +50 -0
- package/lib/compress-C7QjZM5f.js +11 -0
- package/lib/compress-CdDuP9-S.d.ts +11 -0
- package/lib/compress-T36YxGla.js +79 -0
- package/lib/compress.d.ts +38 -0
- package/lib/compress.js +3 -0
- package/lib/concurrent-B7z-2cwF.js +30 -0
- package/lib/connection-CzRPq1RP.d.ts +25 -0
- package/lib/connection-DLPx5pxD.js +24 -0
- package/lib/conninfo-BbxlV2HK.d.ts +11 -0
- package/lib/conninfo-CNYXEtnA.js +19 -0
- package/lib/conninfo.d.ts +3 -0
- package/lib/conninfo.js +2 -0
- package/lib/constants-D914mQY7.js +7 -0
- package/lib/constants-nJj4XhwC.js +4 -0
- package/lib/constants-vv1oZD_p.js +9 -0
- package/lib/context-BVI2RzT7.js +365 -0
- package/lib/context-Ca3uX_bh.d.ts +1234 -0
- package/lib/context-Dre4P1UW.d.ts +250 -0
- package/lib/context-storage-ClUlVtCZ.js +52 -0
- package/lib/context-storage.d.ts +38 -0
- package/lib/context-storage.js +2 -0
- package/lib/cookie-BqeGZ43j.d.ts +40 -0
- package/lib/cookie-DktnJ0tJ.js +82 -0
- package/lib/cookie-uMH6wAF3.js +125 -0
- package/lib/cookie.d.ts +24 -0
- package/lib/cookie.js +2 -0
- package/lib/cordis/db-sqlite.d.ts +56 -0
- package/lib/cordis/db-sqlite.js +66 -0
- package/lib/cordis/db.d.ts +8 -0
- package/lib/cordis/db.js +1 -0
- package/lib/cordis/door.d.ts +404 -0
- package/lib/cordis/door.js +1812 -0
- package/lib/cordis/inspect.d.ts +77 -0
- package/lib/cordis/inspect.js +149 -0
- package/lib/cordis/kv-db.d.ts +16 -0
- package/lib/cordis/kv-db.js +18 -0
- package/lib/cordis/kv-json.d.ts +16 -0
- package/lib/cordis/kv-json.js +52 -0
- package/lib/cordis/kv.d.ts +8 -0
- package/lib/cordis/kv.js +1 -0
- package/lib/cordis/node-server.d.ts +155 -0
- package/lib/cordis/node-server.js +4 -0
- package/lib/cordis/router-http.d.ts +85 -0
- package/lib/cordis/router-http.js +206 -0
- package/lib/cordis/router.d.ts +7 -0
- package/lib/cordis/router.js +6 -0
- package/lib/cordis/state/react.d.ts +6 -0
- package/lib/cordis/state/react.js +11 -0
- package/lib/cordis/state.d.ts +34 -0
- package/lib/cordis/state.js +527 -0
- package/lib/core-4oDBzv4Q.js +19 -0
- package/lib/cors-C0qqZ-O-.js +106 -0
- package/lib/cors.d.ts +52 -0
- package/lib/cors.js +2 -0
- package/lib/crypto-ciSjk9n3.js +34 -0
- package/lib/csrf-rMr2nM2c.js +101 -0
- package/lib/csrf.d.ts +75 -0
- package/lib/csrf.js +2 -0
- package/lib/css-Bd6tj88A.js +320 -0
- package/lib/css-CLgKjBuO.js +134 -0
- package/lib/css.d.ts +82 -0
- package/lib/css.js +3 -0
- package/lib/database-CyKvumAn.d.ts +44 -0
- package/lib/db/conformance.d.ts +15 -0
- package/lib/db/conformance.js +279 -0
- package/lib/db/sqlite.d.ts +3 -0
- package/lib/db/sqlite.js +2 -0
- package/lib/db.d.ts +3 -0
- package/lib/db.js +2 -0
- package/lib/dev-h25puJmg.js +50 -0
- package/lib/dev.d.ts +19 -0
- package/lib/dev.js +2 -0
- package/lib/dom-MsnhZjjn.js +74 -0
- package/lib/door/host.d.ts +24 -0
- package/lib/door/host.js +2 -0
- package/lib/door/page.d.ts +160 -0
- package/lib/door/page.js +1257 -0
- package/lib/door/protocol.d.ts +2 -0
- package/lib/door/protocol.js +2 -0
- package/lib/drivers.d.ts +77 -0
- package/lib/drivers.js +16 -0
- package/lib/encode-BbgU91Gc.js +33 -0
- package/lib/etag-DevxEjyU.js +135 -0
- package/lib/etag.d.ts +40 -0
- package/lib/etag.js +2 -0
- package/lib/factory-d6WBwm2j.js +30 -0
- package/lib/factory.d.ts +35 -0
- package/lib/factory.js +2 -0
- package/lib/handler-DXCHa3NV.js +12 -0
- package/lib/headers-DbujLUIi.d.ts +11 -0
- package/lib/helpers-qmReU164.js +5 -0
- package/lib/hooks-Bs7lFRjW.js +762 -0
- package/lib/html-1jTa7KN1.js +103 -0
- package/lib/html-CNr9FLdV.d.ts +46 -0
- package/lib/html-CoWdxS1u.js +31 -0
- package/lib/html.d.ts +3 -0
- package/lib/html.js +3 -0
- package/lib/http-exception-BKMYq4x6.js +54 -0
- package/lib/http-exception-Cm8QD9Fl.d.ts +57 -0
- package/lib/http-exception.d.ts +2 -0
- package/lib/http-exception.js +2 -0
- package/lib/http-status-uBFmbzzM.d.ts +35 -0
- package/lib/index-B_g6ECnm.d.ts +57 -0
- package/lib/index-BaOiJMWK.d.ts +31 -0
- package/lib/index-C5RhEyXO.d.ts +45 -0
- package/lib/index-C8xOqNUW.d.ts +71 -0
- package/lib/index-D1HlwHSL.d.ts +129 -0
- package/lib/index-DUYLk7OD.d.ts +44 -0
- package/lib/index-DYBSr8yW.d.ts +156 -0
- package/lib/index-Dv4qFsro.d.ts +94 -0
- package/lib/index-jdWVs88B.d.ts +6 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.js +4 -0
- package/lib/ip-restriction-C4TZKPKl.js +166 -0
- package/lib/ip-restriction.d.ts +68 -0
- package/lib/ip-restriction.js +2 -0
- package/lib/ipaddr-CTeN6kNw.js +238 -0
- package/lib/jsx/dom/client.d.ts +30 -0
- package/lib/jsx/dom/client.js +49 -0
- package/lib/jsx/dom/css.d.ts +84 -0
- package/lib/jsx/dom/css.js +2 -0
- package/lib/jsx/dom/jsx-dev-runtime.d.ts +3 -0
- package/lib/jsx/dom/jsx-dev-runtime.js +2 -0
- package/lib/jsx/dom/jsx-runtime.d.ts +3 -0
- package/lib/jsx/dom/jsx-runtime.js +3 -0
- package/lib/jsx/dom/server.d.ts +105 -0
- package/lib/jsx/dom/server.js +37 -0
- package/lib/jsx/dom.d.ts +5 -0
- package/lib/jsx/dom.js +6 -0
- package/lib/jsx/jsx-dev-runtime.d.ts +3 -0
- package/lib/jsx/jsx-dev-runtime.js +3 -0
- package/lib/jsx/jsx-runtime.d.ts +10 -0
- package/lib/jsx/jsx-runtime.js +30 -0
- package/lib/jsx/streaming.d.ts +2 -0
- package/lib/jsx/streaming.js +2 -0
- package/lib/jsx-C5-YJG0l.js +47 -0
- package/lib/jsx-dev-runtime-CPsrmbgy.d.ts +7 -0
- package/lib/jsx-dev-runtime-Cs-uV30u.js +14 -0
- package/lib/jsx-dev-runtime-DK4z4RD3.js +354 -0
- package/lib/jsx-dev-runtime-DSQ8vSCY.d.ts +6 -0
- package/lib/jsx-renderer-B2wHa9Y8.js +99 -0
- package/lib/jsx-renderer.d.ts +75 -0
- package/lib/jsx-renderer.js +2 -0
- package/lib/jsx-runtime-BVVgDSdq.d.ts +1 -0
- package/lib/jsx-runtime-brX0UliB.js +2 -0
- package/lib/jsx.d.ts +3 -0
- package/lib/jsx.js +6 -0
- package/lib/jwk-BbiXIYhg.js +117 -0
- package/lib/jwk.d.ts +52 -0
- package/lib/jwk.js +2 -0
- package/lib/jwt-BCS5hH1O.d.ts +51 -0
- package/lib/jwt-Culfq-8m.js +403 -0
- package/lib/jwt-DaOoWaF3.js +115 -0
- package/lib/jwt.d.ts +72 -0
- package/lib/jwt.js +3 -0
- package/lib/kv/conformance.d.ts +17 -0
- package/lib/kv/conformance.js +313 -0
- package/lib/kv/db.d.ts +3 -0
- package/lib/kv/db.js +2 -0
- package/lib/kv/json.d.ts +3 -0
- package/lib/kv/json.js +2 -0
- package/lib/kv-Kv6J9zqu.d.ts +39 -0
- package/lib/kv.d.ts +3 -0
- package/lib/kv.js +2 -0
- package/lib/language-anRiLd9a.js +198 -0
- package/lib/language.d.ts +88 -0
- package/lib/language.js +2 -0
- package/lib/linear-router-BUrYQxcv.js +96 -0
- package/lib/logger-CLvaB463.js +54 -0
- package/lib/logger.d.ts +22 -0
- package/lib/logger.js +2 -0
- package/lib/loopback-only-0nTL30Zt.js +131 -0
- package/lib/loopback-only.d.ts +73 -0
- package/lib/loopback-only.js +2 -0
- package/lib/method-not-allowed-B3nMAp1f.js +82 -0
- package/lib/method-not-allowed.d.ts +47 -0
- package/lib/method-not-allowed.js +2 -0
- package/lib/method-override-Dhd_EJD9.js +103 -0
- package/lib/method-override.d.ts +46 -0
- package/lib/method-override.js +2 -0
- package/lib/middleware-B8gJUDgl.js +12 -0
- package/lib/mime-B9GbsqnN.d.ts +72 -0
- package/lib/mime-C-r9WxjH.js +77 -0
- package/lib/mount-RGiNYj2l.js +67 -0
- package/lib/mount.d.ts +44 -0
- package/lib/mount.js +2 -0
- package/lib/node-server/conninfo.d.ts +2 -0
- package/lib/node-server/conninfo.js +2 -0
- package/lib/node-server/register.d.ts +1 -0
- package/lib/node-server/register.js +59 -0
- package/lib/node-server/serve-static.d.ts +2 -0
- package/lib/node-server/serve-static.js +2 -0
- package/lib/node-server.d.ts +134 -0
- package/lib/node-server.js +5 -0
- package/lib/open-BC_BGIQt.d.ts +12 -0
- package/lib/open-BpnCtiKf.js +224 -0
- package/lib/open-CEE2hyrs.d.ts +11 -0
- package/lib/open-CwA_ZiPl.js +57 -0
- package/lib/open-DFt0lT26.js +197 -0
- package/lib/open-DXxlFxS0.d.ts +27 -0
- package/lib/pattern-router-DlkDNR9e.js +41 -0
- package/lib/powered-by-B9ufDvKH.js +24 -0
- package/lib/powered-by.d.ts +28 -0
- package/lib/powered-by.js +2 -0
- package/lib/pretty-json-B_5MzYgk.js +39 -0
- package/lib/pretty-json.d.ts +40 -0
- package/lib/pretty-json.js +2 -0
- package/lib/protocol-8HjYa5OX.js +217 -0
- package/lib/protocol-DdQgl224.d.ts +160 -0
- package/lib/proxy-C02n8qaX.js +121 -0
- package/lib/proxy.d.ts +72 -0
- package/lib/proxy.js +2 -0
- package/lib/quick.d.ts +8 -0
- package/lib/quick.js +17 -0
- package/lib/read-sse.d.ts +33 -0
- package/lib/read-sse.js +84 -0
- package/lib/reg-exp-router-DT_H6W_j.js +363 -0
- package/lib/request-PoZjfrb4.js +323 -0
- package/lib/request-id-CWyCgzyD.js +34 -0
- package/lib/request-id.d.ts +45 -0
- package/lib/request-id.js +2 -0
- package/lib/request.d.ts +2 -0
- package/lib/request.js +2 -0
- package/lib/route-D1WQ4cOh.js +126 -0
- package/lib/route.d.ts +78 -0
- package/lib/route.js +2 -0
- package/lib/router/linear-router.d.ts +11 -0
- package/lib/router/linear-router.js +2 -0
- package/lib/router/pattern-router.d.ts +11 -0
- package/lib/router/pattern-router.js +2 -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-0TlTAMdt.d.ts +99 -0
- package/lib/router-wWGf3FlK.js +35 -0
- package/lib/router.d.ts +2 -0
- package/lib/router.js +2 -0
- package/lib/schema-validator-DGAFbTcN.js +22 -0
- package/lib/schema-validator.d.ts +54 -0
- package/lib/schema-validator.js +2 -0
- package/lib/secure-headers-eLrZcjSr.js +163 -0
- package/lib/secure-headers.d.ts +125 -0
- package/lib/secure-headers.js +2 -0
- package/lib/serve-static-D97E4ERX.d.ts +18 -0
- package/lib/serve-static-YoUetEZ8.js +212 -0
- package/lib/serve-static-cnLZvaYu.js +77 -0
- package/lib/serve-static.d.ts +2 -0
- package/lib/serve-static.js +2 -0
- package/lib/smart-router-BF56Yf23.js +49 -0
- package/lib/snapshot-text-Cyl69OKv.js +597 -0
- package/lib/src-6T1gCSq3.js +427 -0
- package/lib/src-BycZ1HUQ.js +407 -0
- package/lib/src-CZ1JoBaO.js +90 -0
- package/lib/src-C_00jcuj.js +85 -0
- package/lib/ssg-D_StqyTO.js +389 -0
- package/lib/ssg.d.ts +2 -0
- package/lib/ssg.js +2 -0
- package/lib/stream-CJ_0BMG2.js +88 -0
- package/lib/stream-Oxo9JHC6.d.ts +34 -0
- package/lib/streaming-CL2i3hX_.js +96 -0
- package/lib/streaming.d.ts +23 -0
- package/lib/streaming.js +2 -0
- package/lib/testing-DnLmBGle.js +17 -0
- package/lib/testing.d.ts +10 -0
- package/lib/testing.js +2 -0
- package/lib/timeout-Bib1sxFc.js +42 -0
- package/lib/timeout.d.ts +30 -0
- package/lib/timeout.js +2 -0
- package/lib/timing-CkkBmV23.js +183 -0
- package/lib/timing.d.ts +130 -0
- package/lib/timing.js +2 -0
- package/lib/tiny.d.ts +8 -0
- package/lib/tiny.js +15 -0
- package/lib/trailing-slash-qJLAJrAH.js +85 -0
- package/lib/trailing-slash.d.ts +91 -0
- package/lib/trailing-slash.js +2 -0
- package/lib/transpile-Bc6rZPK-.js +105 -0
- package/lib/trie-router-DhF3wn5_.js +146 -0
- package/lib/types-Zy1OzMX7.d.ts +29 -0
- package/lib/types-akvg9vbH.d.ts +40 -0
- package/lib/types-cu7acft5.d.ts +195 -0
- package/lib/types-nO2Jov17.d.ts +114 -0
- package/lib/types.d.ts +2 -0
- package/lib/types.js +4 -0
- package/lib/upgrade-hub-7og-sHcQ.d.ts +138 -0
- package/lib/upgrade-hub-B4hca91Y.js +1554 -0
- package/lib/url-Cyyh7Fiw.js +197 -0
- package/lib/utils/accept.d.ts +9 -0
- package/lib/utils/accept.js +2 -0
- package/lib/utils/basic-auth.d.ts +8 -0
- package/lib/utils/basic-auth.js +2 -0
- package/lib/utils/body.d.ts +2 -0
- package/lib/utils/body.js +2 -0
- package/lib/utils/buffer.d.ts +19 -0
- package/lib/utils/buffer.js +2 -0
- package/lib/utils/color.d.ts +24 -0
- package/lib/utils/color.js +2 -0
- package/lib/utils/compress.d.ts +2 -0
- package/lib/utils/compress.js +2 -0
- package/lib/utils/concurrent.d.ts +17 -0
- package/lib/utils/concurrent.js +2 -0
- package/lib/utils/constants.d.ts +7 -0
- package/lib/utils/constants.js +2 -0
- package/lib/utils/cookie.d.ts +2 -0
- package/lib/utils/cookie.js +2 -0
- package/lib/utils/crypto.d.ts +14 -0
- package/lib/utils/crypto.js +2 -0
- package/lib/utils/encode.d.ts +11 -0
- package/lib/utils/encode.js +2 -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 +2 -0
- package/lib/utils/headers.d.ts +2 -0
- package/lib/utils/headers.js +1 -0
- package/lib/utils/html.d.ts +2 -0
- package/lib/utils/html.js +2 -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 +2 -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 +2 -0
- package/lib/utils/stream.d.ts +2 -0
- package/lib/utils/stream.js +2 -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 +2 -0
- package/lib/utils-CYdUlhw1.js +125 -0
- package/lib/utils-CnUrxRO-.js +4 -0
- package/lib/validator-DkpCsiJC.js +65 -0
- package/lib/validator.d.ts +42 -0
- package/lib/validator.js +2 -0
- package/lib/vitest-binding-CctNu3jT.d.ts +15 -0
- package/lib/vitest-binding-CrH7rKg2.js +17 -0
- package/lib/websocket-Cy4jtqHv.js +56 -0
- package/lib/ws.d.ts +2 -0
- package/lib/ws.js +2 -0
- package/package.json +463 -3
- package/shared/AGENTS.core.md +84 -0
- package/shared/DEFAULTS.md +49 -0
- package/shared/library-history-versions.json +48 -0
- package/shared/library-history.json +786 -0
- package/shared/skills/acryl-add-ui/SKILL.md +19 -0
- package/shared/skills/acryl-app/SKILL.md +13 -0
- package/shared/skills/acryl-build-plugin/SKILL.md +22 -0
- package/shared/skills/acryl-change-plugin/SKILL.md +14 -0
- package/shared/skills/acryl-diagnose-plugin/SKILL.md +13 -0
- package/shared/skills/acryl-fix-plugin/SKILL.md +13 -0
- package/shared/skills/acryl-remove-plugin/SKILL.md +12 -0
- package/shared/skills/acryl-share-plugin/SKILL.md +16 -0
- package/shared/skills/cordis-plugin/SKILL.md +26 -0
- package/templates/agent/.gitattributes +2 -0
- package/templates/agent/AGENTS.md +20 -0
- package/templates/agent/Dockerfile +15 -0
- package/templates/agent/README.md +52 -0
- package/templates/agent/blend.yaml +71 -0
- package/templates/agent/dockerignore +3 -0
- package/templates/agent/gitignore +6 -0
- package/templates/agent/package.json +31 -0
- package/templates/agent/src/app.ts +293 -0
- package/templates/agent/src/frame.ts +17 -0
- package/templates/agent/src/main.ts +27 -0
- package/templates/agent/src/routes.ts +163 -0
- package/templates/agent/template.json +22 -0
- package/templates/agent/test/agent.test.ts +51 -0
- package/templates/agent/test/app.test.ts +270 -0
- package/templates/agent/test/builder.test.ts +210 -0
- package/templates/agent/test/model.test.ts +94 -0
- package/templates/agent/tsconfig.json +68 -0
- package/templates/blank/.gitattributes +2 -0
- package/templates/blank/AGENTS.md +6 -0
- package/templates/blank/README.md +26 -0
- package/templates/blank/blend.yaml +37 -0
- package/templates/blank/gitignore +6 -0
- package/templates/blank/package.json +31 -0
- package/templates/blank/src/about.tsx +14 -0
- package/templates/blank/src/app.ts +160 -0
- package/templates/blank/src/door.ts +7 -0
- package/templates/blank/src/first-page.ts +5 -0
- package/templates/blank/src/frame.ts +17 -0
- package/templates/blank/src/main.ts +20 -0
- package/templates/blank/src/routes.ts +79 -0
- package/templates/blank/template.json +15 -0
- package/templates/blank/test/app.test.ts +177 -0
- package/templates/blank/tsconfig.json +19 -0
- package/templates/chat/.gitattributes +2 -0
- package/templates/chat/AGENTS.md +16 -0
- package/templates/chat/blend.yaml +36 -0
- package/templates/chat/gitignore +9 -0
- package/templates/chat/migrations/001-chat.sql +12 -0
- package/templates/chat/package.json +35 -0
- package/templates/chat/src/access.ts +110 -0
- package/templates/chat/src/app.ts +165 -0
- package/templates/chat/src/chat-app.ts +120 -0
- package/templates/chat/src/client/chat.tsx +117 -0
- package/templates/chat/src/client/tsconfig.json +26 -0
- package/templates/chat/src/db.ts +43 -0
- package/templates/chat/src/door.ts +7 -0
- package/templates/chat/src/frame.ts +17 -0
- package/templates/chat/src/llm.ts +48 -0
- package/templates/chat/src/main.ts +23 -0
- package/templates/chat/src/page.tsx +42 -0
- package/templates/chat/src/routes.ts +29 -0
- package/templates/chat/src/runtime.ts +23 -0
- package/templates/chat/template.json +15 -0
- package/templates/chat/test/chat.test.ts +322 -0
- package/templates/chat/test/server.test.ts +92 -0
- package/templates/chat/tsconfig.json +20 -0
- package/templates/nodejs/.gitattributes +2 -0
- package/templates/nodejs/AGENTS.md +9 -0
- package/templates/nodejs/blend.yaml +33 -0
- package/templates/nodejs/gitignore +6 -0
- package/templates/nodejs/package.json +32 -0
- package/templates/nodejs/src/app.ts +158 -0
- package/templates/nodejs/src/client/counter.tsx +12 -0
- package/templates/nodejs/src/client/tsconfig.json +26 -0
- package/templates/nodejs/src/door.ts +7 -0
- package/templates/nodejs/src/frame.ts +17 -0
- package/templates/nodejs/src/main.ts +20 -0
- package/templates/nodejs/src/page.tsx +29 -0
- package/templates/nodejs/src/routes.ts +59 -0
- package/templates/nodejs/template.json +14 -0
- package/templates/nodejs/test/app.test.ts +112 -0
- package/templates/nodejs/test/server.test.ts +97 -0
- package/templates/nodejs/tsconfig.json +20 -0
- package/templates/notes/.gitattributes +2 -0
- package/templates/notes/AGENTS.md +26 -0
- package/templates/notes/blend.yaml +36 -0
- package/templates/notes/gitignore +9 -0
- package/templates/notes/migrations/001-notes.sql +18 -0
- package/templates/notes/package.json +35 -0
- package/templates/notes/src/app.ts +165 -0
- package/templates/notes/src/auth.ts +57 -0
- package/templates/notes/src/client/counter.tsx +21 -0
- package/templates/notes/src/client/tsconfig.json +26 -0
- package/templates/notes/src/db.ts +50 -0
- package/templates/notes/src/door.ts +7 -0
- package/templates/notes/src/frame.ts +17 -0
- package/templates/notes/src/main.ts +23 -0
- package/templates/notes/src/notes-app.ts +212 -0
- package/templates/notes/src/routes.ts +21 -0
- package/templates/notes/src/runtime.ts +23 -0
- package/templates/notes/src/schema.ts +38 -0
- package/templates/notes/src/views.tsx +145 -0
- package/templates/notes/template.json +15 -0
- package/templates/notes/test/notes.test.ts +318 -0
- package/templates/notes/test/server.test.ts +92 -0
- package/templates/notes/tsconfig.json +20 -0
- package/templates/todo/.gitattributes +2 -0
- package/templates/todo/AGENTS.md +5 -0
- package/templates/todo/README.md +27 -0
- package/templates/todo/blend.yaml +28 -0
- package/templates/todo/gitignore +6 -0
- package/templates/todo/package.json +31 -0
- package/templates/todo/src/app.ts +145 -0
- package/templates/todo/src/door.ts +7 -0
- package/templates/todo/src/frame.ts +17 -0
- package/templates/todo/src/main.ts +21 -0
- package/templates/todo/src/page.ts +35 -0
- package/templates/todo/src/todo.ts +137 -0
- package/templates/todo/template.json +14 -0
- package/templates/todo/test/todo.test.ts +228 -0
- package/templates/todo/tsconfig.json +19 -0
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
import { t as HTTPException } from "./http-exception-BKMYq4x6.js";
|
|
2
|
+
import { l as mergePath } from "./url-Cyyh7Fiw.js";
|
|
3
|
+
import { t as COMPOSED_HANDLER } from "./constants-D914mQY7.js";
|
|
4
|
+
import { t as TrieRouter } from "./trie-router-DhF3wn5_.js";
|
|
5
|
+
import { t as Acryl } from "./app-CM-rDcw6.js";
|
|
6
|
+
import "./core-4oDBzv4Q.js";
|
|
7
|
+
import "./connection-DLPx5pxD.js";
|
|
8
|
+
import { appendFileSync } from "node:fs";
|
|
9
|
+
import { tmpdir } from "node:os";
|
|
10
|
+
import { Service } from "@deepseek-ai/cordis";
|
|
11
|
+
import z from "@deepseek-ai/schemastery";
|
|
12
|
+
//#region ../../../plugins/router/src/service.ts
|
|
13
|
+
/**
|
|
14
|
+
* The ACRYL router service (`ctx.router`): plugin-owned `Acryl` mounts on Web-standard Request and Response.
|
|
15
|
+
*
|
|
16
|
+
* A plugin builds an ordinary `Acryl` and mounts it with `ctx.router.route(path, app)` from its own context, so the mount disappears when that
|
|
17
|
+
* plugin unloads. `fetch(request)` runs a request in process: Web and Desktop serve it behind HTTP through an adapter, the terminal UI calls
|
|
18
|
+
* it directly, so one handler serves every surface without opening a socket. Disposal refuses new requests, aborts in-flight ones, ends any
|
|
19
|
+
* response body still streaming and waits for all of it to settle.
|
|
20
|
+
*/
|
|
21
|
+
const DEFAULT_DISPOSE_GRACE_MS = 2e3;
|
|
22
|
+
/** How long disposal waits for the flights it had to abort after the drain, before it continues without them. */
|
|
23
|
+
const ABORT_SETTLE_MS = 300;
|
|
24
|
+
/** Set by ACRYL_ROUTER_TRACE=1: append request-signal lifecycle lines to ACRYL_ROUTER_TRACE_FILE (the CI artifact) - diagnostics for the abort-reaches-handler defect. */
|
|
25
|
+
const traceFile = () => process.env.ACRYL_ROUTER_TRACE_FILE ?? `${tmpdir()}/acryl-router-trace.log`;
|
|
26
|
+
const trace = (line) => {
|
|
27
|
+
if (process.env.ACRYL_ROUTER_TRACE !== "1") return;
|
|
28
|
+
try {
|
|
29
|
+
appendFileSync(traceFile(), `${String(Date.now())} [${String(process.pid)}] ${line}\n`);
|
|
30
|
+
} catch {}
|
|
31
|
+
};
|
|
32
|
+
let flightSeq = 0;
|
|
33
|
+
const SIGNAL_TAG = Symbol.for("acryl.router.signalTag");
|
|
34
|
+
const tagOf = (signal) => {
|
|
35
|
+
if (signal === void 0) return "none";
|
|
36
|
+
const tag = signal[SIGNAL_TAG];
|
|
37
|
+
return typeof tag === "string" ? tag : "untagged";
|
|
38
|
+
};
|
|
39
|
+
const tagSignal = (signal, tag) => {
|
|
40
|
+
try {
|
|
41
|
+
signal[SIGNAL_TAG] = tag;
|
|
42
|
+
} catch {}
|
|
43
|
+
};
|
|
44
|
+
/** Every field has a default, so a caller passes only what it changes: `ctx.plugin(plugin, { ... })` takes the partial shape. */
|
|
45
|
+
const Config = z.object({
|
|
46
|
+
trailingSlash: z.union(["strict", "ignore"]).default("strict").description("Whether `/a` and `/a/` are different paths."),
|
|
47
|
+
disposeGraceMs: z.number().min(0).default(DEFAULT_DISPOSE_GRACE_MS).description("How long disposal waits for aborted requests, their response bodies and their waitUntil tasks before it gives up on them.")
|
|
48
|
+
});
|
|
49
|
+
/** Stable Cordis plugin name, equal to the package name and the Loader row id. */
|
|
50
|
+
const name = "acryl-router";
|
|
51
|
+
/** The core's `app.route` with a structural app: at run time it reads only the routes and the app's own error handler. */
|
|
52
|
+
const copyRoutes = (app) => new Acryl().route("/", app);
|
|
53
|
+
/** Wait for `tasks`, including any added while waiting (a stream may register more after the handler returned). */
|
|
54
|
+
async function drain(tasks) {
|
|
55
|
+
let seen = 0;
|
|
56
|
+
while (seen < tasks.length) {
|
|
57
|
+
const batch = tasks.slice(seen);
|
|
58
|
+
seen = tasks.length;
|
|
59
|
+
await Promise.allSettled(batch);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
var Router = class extends Service {
|
|
63
|
+
/** Everything that changes after construction, kept in one object so the service's live state is in one place. */
|
|
64
|
+
state = {
|
|
65
|
+
mounts: /* @__PURE__ */ new Set(),
|
|
66
|
+
wrappers: /* @__PURE__ */ new Set(),
|
|
67
|
+
errorHandler: void 0,
|
|
68
|
+
notFoundHandler: void 0,
|
|
69
|
+
composed: void 0,
|
|
70
|
+
closing: false
|
|
71
|
+
};
|
|
72
|
+
flights = /* @__PURE__ */ new Set();
|
|
73
|
+
/** The flight of each request the router dispatched, keyed by the request its handlers see as `c.req.raw`. */
|
|
74
|
+
flightOf = /* @__PURE__ */ new WeakMap();
|
|
75
|
+
strict;
|
|
76
|
+
graceMs;
|
|
77
|
+
logError;
|
|
78
|
+
constructor(ctx, config = {}) {
|
|
79
|
+
super(ctx, "router");
|
|
80
|
+
const { trailingSlash = "strict", disposeGraceMs = DEFAULT_DISPOSE_GRACE_MS } = config;
|
|
81
|
+
this.strict = trailingSlash === "strict";
|
|
82
|
+
this.graceMs = disposeGraceMs;
|
|
83
|
+
this.logError = (error, c) => {
|
|
84
|
+
if (error instanceof HTTPException) return error.getResponse();
|
|
85
|
+
if (c.req.raw.signal.aborted) return new Response("Client Closed Request", { status: 499 });
|
|
86
|
+
ctx.logger.error(`@acryldev/router: handler failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
87
|
+
return c.text("Internal Server Error", 500);
|
|
88
|
+
};
|
|
89
|
+
ctx.effect(() => async () => {
|
|
90
|
+
this.state.closing = true;
|
|
91
|
+
await this.drain();
|
|
92
|
+
}, "@acryldev/router: drain in-flight requests, then abort what is left");
|
|
93
|
+
}
|
|
94
|
+
/** Registrations currently held (mounts, and the router-wide error and not-found handlers); a leak check for reload tests. */
|
|
95
|
+
get size() {
|
|
96
|
+
return this.state.mounts.size + (this.state.errorHandler === void 0 ? 0 : 1) + (this.state.notFoundHandler === void 0 ? 0 : 1);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Serve `app` under `path` (`'/'` for its own paths as they are). The mount belongs to the calling plugin and goes away when it unloads;
|
|
100
|
+
* the returned function removes it sooner. Mounts are composed in the order they were made. Like the core's own `app.route`, the routes
|
|
101
|
+
* are copied now: one the app registers after this call is not served (mount again, or finish the app first).
|
|
102
|
+
*/
|
|
103
|
+
route(path, app) {
|
|
104
|
+
const mount = this.snapshot(path, app);
|
|
105
|
+
this.state.mounts.add(mount);
|
|
106
|
+
this.state.composed = void 0;
|
|
107
|
+
const remove = () => {
|
|
108
|
+
if (!this.state.mounts.delete(mount)) return Promise.resolve();
|
|
109
|
+
this.state.composed = void 0;
|
|
110
|
+
return this.drainFlights([...this.flights].filter((flight) => (flight.running.get(mount) ?? 0) > 0 || flight.producer === mount), `removing ${path}`);
|
|
111
|
+
};
|
|
112
|
+
const served = new Set(app.routes.map((route) => `${route.method} ${mergePath(path, route.path)}`));
|
|
113
|
+
const owner = this.ctx;
|
|
114
|
+
owner.effect(function* () {
|
|
115
|
+
for (const route of served) yield owner.effect(() => () => {}, `@acryldev/router: serves ${route}`);
|
|
116
|
+
yield remove;
|
|
117
|
+
}, `@acryldev/router: route ${path}`);
|
|
118
|
+
return () => {
|
|
119
|
+
remove();
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* 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,
|
|
124
|
+
* 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
|
|
125
|
+
* outside all mounts, in the order wrappers were added, and goes away when the calling plugin unloads or when the returned function is called.
|
|
126
|
+
*/
|
|
127
|
+
wrap(middleware) {
|
|
128
|
+
this.state.wrappers.add(middleware);
|
|
129
|
+
this.state.composed = void 0;
|
|
130
|
+
const remove = () => {
|
|
131
|
+
if (this.state.wrappers.delete(middleware)) this.state.composed = void 0;
|
|
132
|
+
};
|
|
133
|
+
this.ctx.effect(() => remove, "@acryldev/router: wrapper");
|
|
134
|
+
return remove;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* 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
|
|
138
|
+
* 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.
|
|
139
|
+
*/
|
|
140
|
+
snapshot(path, app) {
|
|
141
|
+
const copy = copyRoutes(app);
|
|
142
|
+
const tagged = new Acryl();
|
|
143
|
+
const mount = {
|
|
144
|
+
path,
|
|
145
|
+
app: tagged
|
|
146
|
+
};
|
|
147
|
+
for (const route of copy.routes) {
|
|
148
|
+
const inner = route.handler;
|
|
149
|
+
const handler = async (c, next) => {
|
|
150
|
+
const flight = this.flightOf.get(c.req.raw);
|
|
151
|
+
if (flight === void 0) return inner(c, next);
|
|
152
|
+
trace(`handler ${flight.tag} requestTag=${tagOf(c.req.raw.signal)} innerTag=${tagOf(flight.inner.signal)} sameSignal=${String(c.req.raw.signal === flight.inner.signal)} aborted=${String(c.req.raw.signal.aborted)}`);
|
|
153
|
+
let calledNext = false;
|
|
154
|
+
flight.running.set(mount, (flight.running.get(mount) ?? 0) + 1);
|
|
155
|
+
try {
|
|
156
|
+
const result = await inner(c, () => {
|
|
157
|
+
calledNext = true;
|
|
158
|
+
return next();
|
|
159
|
+
});
|
|
160
|
+
if (!calledNext && result instanceof Response) flight.producer = mount;
|
|
161
|
+
return result;
|
|
162
|
+
} finally {
|
|
163
|
+
flight.running.set(mount, (flight.running.get(mount) ?? 1) - 1);
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
handler[COMPOSED_HANDLER] = inner;
|
|
167
|
+
tagged.on(route.method, route.path, handler);
|
|
168
|
+
const registered = tagged.routes.at(-1);
|
|
169
|
+
if (registered !== void 0) registered.basePath = route.basePath;
|
|
170
|
+
}
|
|
171
|
+
return mount;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* The router's own disposal: let the flights already in flight finish within `disposeGraceMs` - a save being written when the app stops must not be cut
|
|
175
|
+
* by the router beneath it - then abort what is left and settle it for a moment, so disposal does not wait a second full grace on code that ignores
|
|
176
|
+
* its abort signal.
|
|
177
|
+
*/
|
|
178
|
+
async drain() {
|
|
179
|
+
await this.drainFlights([...this.flights], "disposal");
|
|
180
|
+
}
|
|
181
|
+
/** The one draining rule: let `flights` finish inside the grace, then abort and settle what is left. */
|
|
182
|
+
async drainFlights(flights, why) {
|
|
183
|
+
trace(`drain ${why} chosen=[${flights.map((flight) => flight.tag).join(", ")}]`);
|
|
184
|
+
if (flights.length === 0) return;
|
|
185
|
+
if (await this.settledWithin(flights, this.graceMs)) {
|
|
186
|
+
trace(`drain ${why} settled inside the grace`);
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
const left = flights.filter((flight) => this.flights.has(flight));
|
|
190
|
+
trace(`drain ${why} grace over left=[${left.map((flight) => flight.tag).join(", ")}]`);
|
|
191
|
+
if (left.length > 0) await this.end(left, why, ABORT_SETTLE_MS);
|
|
192
|
+
}
|
|
193
|
+
/** Resolve true when every flight settled inside `ms`, false at the deadline. */
|
|
194
|
+
async settledWithin(flights, ms) {
|
|
195
|
+
let timer;
|
|
196
|
+
const gaveUp = new Promise((resolve) => {
|
|
197
|
+
timer = setTimeout(() => {
|
|
198
|
+
resolve(false);
|
|
199
|
+
}, ms);
|
|
200
|
+
});
|
|
201
|
+
const outcome = await Promise.race([Promise.allSettled(flights.map((flight) => flight.settled)).then(() => true), gaveUp]);
|
|
202
|
+
clearTimeout(timer);
|
|
203
|
+
return outcome;
|
|
204
|
+
}
|
|
205
|
+
/** Abort `flights`, cut their bodies short and wait for them to settle, at most `settleMs`. */
|
|
206
|
+
async end(flights, why, settleMs = this.graceMs) {
|
|
207
|
+
if (flights.length === 0) return;
|
|
208
|
+
for (const flight of flights) {
|
|
209
|
+
trace(`abort ${flight.tag} before=${String(flight.controller.signal.aborted)}`);
|
|
210
|
+
flight.controller.abort();
|
|
211
|
+
trace(`abort ${flight.tag} after=${String(flight.controller.signal.aborted)} innerAborted=${String(flight.inner.signal.aborted)}`);
|
|
212
|
+
queueMicrotask(() => {
|
|
213
|
+
trace(`post-abort ${flight.tag} innerAborted=${String(flight.inner.signal.aborted)}`);
|
|
214
|
+
});
|
|
215
|
+
flight.endBody();
|
|
216
|
+
}
|
|
217
|
+
if (await this.settledWithin(flights, settleMs)) return;
|
|
218
|
+
this.ctx.logger.warn(`@acryldev/router: ${String(flights.length)} request(s) did not finish ${String(settleMs)} ms after abort (${why}); continued without them`);
|
|
219
|
+
}
|
|
220
|
+
/** Turn errors no mounted app handled into responses. One handler per router; the calling plugin owns it. */
|
|
221
|
+
onError(handler) {
|
|
222
|
+
if (this.state.errorHandler !== void 0) throw new Error("router: an error handler is already registered");
|
|
223
|
+
this.state.errorHandler = handler;
|
|
224
|
+
this.state.composed = void 0;
|
|
225
|
+
const remove = () => {
|
|
226
|
+
if (this.state.errorHandler !== handler) return;
|
|
227
|
+
this.state.errorHandler = void 0;
|
|
228
|
+
this.state.composed = void 0;
|
|
229
|
+
};
|
|
230
|
+
this.ctx.effect(() => remove, "@acryldev/router: onError");
|
|
231
|
+
return remove;
|
|
232
|
+
}
|
|
233
|
+
/** Answer requests no route claimed. One handler per router; the calling plugin owns it. */
|
|
234
|
+
notFound(handler) {
|
|
235
|
+
if (this.state.notFoundHandler !== void 0) throw new Error("router: a not-found handler is already registered");
|
|
236
|
+
this.state.notFoundHandler = handler;
|
|
237
|
+
this.state.composed = void 0;
|
|
238
|
+
const remove = () => {
|
|
239
|
+
if (this.state.notFoundHandler !== handler) return;
|
|
240
|
+
this.state.notFoundHandler = void 0;
|
|
241
|
+
this.state.composed = void 0;
|
|
242
|
+
};
|
|
243
|
+
this.ctx.effect(() => remove, "@acryldev/router: notFound");
|
|
244
|
+
return remove;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Call the router the way a test calls an app: a path or URL string, a `URL` or a `Request`, with the usual init.
|
|
248
|
+
* A relative path is resolved against `http://localhost`.
|
|
249
|
+
*/
|
|
250
|
+
request(input, init, connection) {
|
|
251
|
+
const request = input instanceof Request ? input : new Request(new URL(String(input), "http://localhost"), init);
|
|
252
|
+
return this.fetch(request, connection);
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Run a request in process. Never throws: failures become a 500, a disposed router answers 503. `connection` describes the transport
|
|
256
|
+
* (an HTTP adapter passes the socket's peer address and local port); an in-process caller omits it. Handlers read it with
|
|
257
|
+
* `connectionOf(c)`, abort with `c.req.raw.signal` and keep the request in flight with `c.executionCtx.waitUntil(task)`.
|
|
258
|
+
* `bindings` is an object an adapter hands to the handler as `c.env` (an upgrade request's socket hooks, for `upgradeWebSocket`); `connection` is added to it.
|
|
259
|
+
*/
|
|
260
|
+
fetch(request, connection = {}, bindings) {
|
|
261
|
+
if (this.state.closing) return Promise.resolve(new Response("Service Unavailable", {
|
|
262
|
+
status: 503,
|
|
263
|
+
headers: { connection: "close" }
|
|
264
|
+
}));
|
|
265
|
+
const controller = new AbortController();
|
|
266
|
+
const forward = () => controller.abort();
|
|
267
|
+
if (request.signal.aborted) controller.abort();
|
|
268
|
+
else request.signal.addEventListener("abort", forward, { once: true });
|
|
269
|
+
const tasks = [];
|
|
270
|
+
const executionCtx = {
|
|
271
|
+
waitUntil: (task) => {
|
|
272
|
+
tasks.push(task);
|
|
273
|
+
},
|
|
274
|
+
passThroughOnException: () => {},
|
|
275
|
+
props: {}
|
|
276
|
+
};
|
|
277
|
+
const env = bindings === void 0 ? { connection } : Object.assign(bindings, { connection });
|
|
278
|
+
let bodyDone = Promise.resolve();
|
|
279
|
+
let endBody = () => {};
|
|
280
|
+
let resolveSettled;
|
|
281
|
+
const tag = `f${String(++flightSeq)}`;
|
|
282
|
+
const inner = new Request(request, { signal: controller.signal });
|
|
283
|
+
tagSignal(inner.signal, tag);
|
|
284
|
+
const flight = {
|
|
285
|
+
controller,
|
|
286
|
+
inner,
|
|
287
|
+
tag,
|
|
288
|
+
running: /* @__PURE__ */ new Map(),
|
|
289
|
+
producer: void 0,
|
|
290
|
+
endBody: () => {
|
|
291
|
+
endBody();
|
|
292
|
+
},
|
|
293
|
+
settled: new Promise((resolve) => {
|
|
294
|
+
resolveSettled = resolve;
|
|
295
|
+
})
|
|
296
|
+
};
|
|
297
|
+
trace(`create ${tag} ${request.method} ${new URL(request.url).pathname}`);
|
|
298
|
+
this.flightOf.set(inner, flight);
|
|
299
|
+
const response = this.dispatch(inner, env, executionCtx).then((raw) => {
|
|
300
|
+
const tracked = this.track(raw);
|
|
301
|
+
bodyDone = tracked.done;
|
|
302
|
+
endBody = tracked.end;
|
|
303
|
+
if (controller.signal.aborted) tracked.end();
|
|
304
|
+
return tracked.response;
|
|
305
|
+
});
|
|
306
|
+
const settled = response.then(async () => {
|
|
307
|
+
await bodyDone;
|
|
308
|
+
await drain(tasks);
|
|
309
|
+
});
|
|
310
|
+
resolveSettled(settled);
|
|
311
|
+
this.flights.add(flight);
|
|
312
|
+
settled.finally(() => {
|
|
313
|
+
request.signal.removeEventListener("abort", forward);
|
|
314
|
+
this.flights.delete(flight);
|
|
315
|
+
});
|
|
316
|
+
return response;
|
|
317
|
+
}
|
|
318
|
+
async dispatch(request, env, executionCtx) {
|
|
319
|
+
try {
|
|
320
|
+
return await this.app().fetch(request, env, executionCtx);
|
|
321
|
+
} catch (error) {
|
|
322
|
+
this.ctx.logger.error(`@acryldev/router: request failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
323
|
+
return new Response("Internal Server Error", { status: 500 });
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
app() {
|
|
327
|
+
if (this.state.composed !== void 0) return this.state.composed;
|
|
328
|
+
const root = new Acryl({
|
|
329
|
+
strict: this.strict,
|
|
330
|
+
router: new TrieRouter()
|
|
331
|
+
});
|
|
332
|
+
for (const wrapper of this.state.wrappers) root.use("*", wrapper);
|
|
333
|
+
for (const mount of this.state.mounts) root.route(mount.path, mount.app);
|
|
334
|
+
root.onError(this.state.errorHandler ?? this.logError);
|
|
335
|
+
if (this.state.notFoundHandler !== void 0) root.notFound(this.state.notFoundHandler);
|
|
336
|
+
this.state.composed = root;
|
|
337
|
+
return root;
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Hand the caller a body the router can end. Reading it passes the handler's chunks through; disposal cancels the handler's stream (which runs
|
|
341
|
+
* the stream helpers' own abort cleanup) and closes the caller's side, so a stream never outlives the plugin that served it.
|
|
342
|
+
*/
|
|
343
|
+
track(response) {
|
|
344
|
+
const source = response.body;
|
|
345
|
+
if (source === null) return {
|
|
346
|
+
response,
|
|
347
|
+
done: Promise.resolve(),
|
|
348
|
+
end: () => {}
|
|
349
|
+
};
|
|
350
|
+
const reader = source.getReader();
|
|
351
|
+
let finish;
|
|
352
|
+
const done = new Promise((resolve) => {
|
|
353
|
+
finish = resolve;
|
|
354
|
+
});
|
|
355
|
+
let ended = false;
|
|
356
|
+
let sink;
|
|
357
|
+
const end = () => {
|
|
358
|
+
if (ended) return;
|
|
359
|
+
ended = true;
|
|
360
|
+
finish();
|
|
361
|
+
};
|
|
362
|
+
const endEarly = () => {
|
|
363
|
+
if (ended) return;
|
|
364
|
+
reader.cancel(/* @__PURE__ */ new Error("@acryldev/router: disposed")).catch(() => {});
|
|
365
|
+
try {
|
|
366
|
+
sink?.close();
|
|
367
|
+
} catch {}
|
|
368
|
+
end();
|
|
369
|
+
};
|
|
370
|
+
const body = new ReadableStream({
|
|
371
|
+
start: (controller) => {
|
|
372
|
+
sink = controller;
|
|
373
|
+
},
|
|
374
|
+
pull: async (controller) => {
|
|
375
|
+
try {
|
|
376
|
+
const chunk = await reader.read();
|
|
377
|
+
if (ended) return;
|
|
378
|
+
if (chunk.done) {
|
|
379
|
+
controller.close();
|
|
380
|
+
end();
|
|
381
|
+
} else controller.enqueue(chunk.value);
|
|
382
|
+
} catch (error) {
|
|
383
|
+
if (!ended) controller.error(error);
|
|
384
|
+
end();
|
|
385
|
+
}
|
|
386
|
+
},
|
|
387
|
+
cancel: async (reason) => {
|
|
388
|
+
end();
|
|
389
|
+
await reader.cancel(reason);
|
|
390
|
+
}
|
|
391
|
+
});
|
|
392
|
+
return {
|
|
393
|
+
response: new Response(body, {
|
|
394
|
+
status: response.status,
|
|
395
|
+
statusText: response.statusText,
|
|
396
|
+
headers: response.headers
|
|
397
|
+
}),
|
|
398
|
+
done,
|
|
399
|
+
end: endEarly
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
};
|
|
403
|
+
function apply(ctx, config = {}) {
|
|
404
|
+
new Router(ctx, config);
|
|
405
|
+
}
|
|
406
|
+
//#endregion
|
|
407
|
+
export { name as i, Router as n, apply as r, Config as t };
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
//#region ../../../plugins/kv/src/check.ts
|
|
2
|
+
/**
|
|
3
|
+
* What every `kv` provider checks the same way, so a bad call fails alike on a file and on SQL: the key, the value, and the order of keys.
|
|
4
|
+
*/
|
|
5
|
+
/** A key is a non-empty string. */
|
|
6
|
+
function checkKey(key) {
|
|
7
|
+
if (typeof key !== "string" || key === "") throw new TypeError(`a kv key is a non-empty string, got ${typeof key === "string" ? "an empty string" : typeof key}`);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The JSON text of a value. `undefined`, functions, symbols, bigints, circular structures and non-finite numbers (which JSON would turn
|
|
11
|
+
* into `null`) are refused with a `TypeError`; nothing is stored for them.
|
|
12
|
+
*/
|
|
13
|
+
function encodeValue(value) {
|
|
14
|
+
const text = JSON.stringify(value, (_key, part) => {
|
|
15
|
+
if (typeof part === "number" && !Number.isFinite(part)) throw new TypeError(`a kv value is JSON; ${String(part)} is not`);
|
|
16
|
+
return part;
|
|
17
|
+
});
|
|
18
|
+
if (text === void 0) throw new TypeError(`a kv value is JSON; ${typeof value} is not`);
|
|
19
|
+
return text;
|
|
20
|
+
}
|
|
21
|
+
/** The value of stored JSON text: a new copy each time, so changing what `get` returned changes nothing stored. */
|
|
22
|
+
function decodeValue(text) {
|
|
23
|
+
return JSON.parse(text);
|
|
24
|
+
}
|
|
25
|
+
/** Order two keys by code point (the order of UTF-8 bytes, which SQLite's binary collation and Postgres' "C" collation give too). */
|
|
26
|
+
function compareKeys(a, b) {
|
|
27
|
+
if (a === b) return 0;
|
|
28
|
+
const rank = (unit) => unit >= 55296 ? unit >= 57344 ? unit - 2048 : unit + 8192 : unit;
|
|
29
|
+
const length = Math.min(a.length, b.length);
|
|
30
|
+
for (let index = 0; index < length; index += 1) {
|
|
31
|
+
const difference = rank(a.charCodeAt(index)) - rank(b.charCodeAt(index));
|
|
32
|
+
if (difference !== 0) return difference;
|
|
33
|
+
}
|
|
34
|
+
return a.length - b.length;
|
|
35
|
+
}
|
|
36
|
+
/** The number of code points in a string (what SQL's `substr` counts). */
|
|
37
|
+
function codePoints(text) {
|
|
38
|
+
let count = 0;
|
|
39
|
+
for (const _ of text) count += 1;
|
|
40
|
+
return count;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Call an `update` callback and check what it returns: the callback is synchronous, so a promise (an `async` function the types should have
|
|
44
|
+
* refused) is rejected with a message that says what to do, instead of being stored as `{}`.
|
|
45
|
+
*/
|
|
46
|
+
function runChange(change, current) {
|
|
47
|
+
const next = change(current);
|
|
48
|
+
if (typeof next === "object" && next !== null && typeof next.then === "function") throw new TypeError("the callback of kv.update is synchronous and returned a promise: read what you need first (await kv.get), then update with a plain function");
|
|
49
|
+
return next;
|
|
50
|
+
}
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region ../../../plugins/kv/src/copy.ts
|
|
53
|
+
/**
|
|
54
|
+
* Copy every key of one store into another: the import when an app moves from a JSON file to SQL (the file opened with
|
|
55
|
+
* `@acryldev/kv-json` is the source, `kvOnDb` the target). The source is not changed.
|
|
56
|
+
* @throws when the target has a key the source has and `overwrite` is not set; nothing is written then.
|
|
57
|
+
*/
|
|
58
|
+
async function copyKv(source, target, options = {}) {
|
|
59
|
+
const keys = await source.list(options.prefix);
|
|
60
|
+
const existing = new Set(await target.list(options.prefix));
|
|
61
|
+
const shared = keys.filter((key) => existing.has(key));
|
|
62
|
+
if (shared.length > 0 && options.overwrite !== true) {
|
|
63
|
+
const shown = shared.slice(0, 5).map((key) => JSON.stringify(key)).join(", ");
|
|
64
|
+
throw new Error(`copyKv: the target already has ${shared.length} of these keys (${shown}${shared.length > 5 ? ", ..." : ""}); pass overwrite to replace them`);
|
|
65
|
+
}
|
|
66
|
+
let copied = 0;
|
|
67
|
+
for (const key of keys) {
|
|
68
|
+
const value = await source.get(key);
|
|
69
|
+
if (value === void 0) continue;
|
|
70
|
+
await target.set(key, value);
|
|
71
|
+
copied += 1;
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
copied,
|
|
75
|
+
overwritten: shared.length
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
//#endregion
|
|
79
|
+
//#region ../../../plugins/kv/src/index.ts
|
|
80
|
+
/**
|
|
81
|
+
* The `kv` port: named JSON documents for an app too small for SQL, whichever provider serves it (`@acryldev/kv-json` for one file,
|
|
82
|
+
* `@acryldev/kv-db` over the `db` port). Plain code opens a store with a provider's `openKv`; a Cordis plugin declares `inject: ['kv']`, imports
|
|
83
|
+
* `@acryldev/kv/cordis` for the `ctx.kv` type, and never imports a provider.
|
|
84
|
+
*
|
|
85
|
+
* This entry imports nothing from Cordis, at runtime or in its types.
|
|
86
|
+
*/
|
|
87
|
+
/** The service name every `kv` provider registers. */
|
|
88
|
+
const KV_SERVICE = "kv";
|
|
89
|
+
//#endregion
|
|
90
|
+
export { compareKeys as a, runChange as c, codePoints as i, copyKv as n, decodeValue as o, checkKey as r, encodeValue as s, KV_SERVICE as t };
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { readFile, readdir } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
//#region ../../../plugins/db/src/facade/schema.ts
|
|
5
|
+
/** Validate a prefix before using it as part of a SQL identifier. */
|
|
6
|
+
function validateSchemaPrefix(prefix) {
|
|
7
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(prefix)) throw new Error(`Invalid SQL schema prefix ${JSON.stringify(prefix)}`);
|
|
8
|
+
if (prefix.toLowerCase().startsWith("sqlite_")) throw new Error(`SQL schema prefix ${JSON.stringify(prefix)} is reserved`);
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region ../../../plugins/db/src/facade/migrations.ts
|
|
12
|
+
/**
|
|
13
|
+
* Apply all pending migrations atomically, tracking their version in the named metadata table.
|
|
14
|
+
*
|
|
15
|
+
* The bookkeeping SQL runs unchanged on SQLite and Postgres: no `STRICT` table, `ON CONFLICT DO NOTHING`
|
|
16
|
+
* instead of `INSERT OR IGNORE`, and the version written as a checked integer rather than a binding,
|
|
17
|
+
* since the two dialects spell placeholders differently.
|
|
18
|
+
*/
|
|
19
|
+
async function applyMigrations(database, migrations, options) {
|
|
20
|
+
const { table } = options;
|
|
21
|
+
validateSchemaPrefix(table);
|
|
22
|
+
for (let index = 0; index < migrations.length; index++) if (migrations[index]?.version !== index + 1) throw new Error("Migrations must have contiguous versions starting at 1");
|
|
23
|
+
await database.transaction(async (transaction) => {
|
|
24
|
+
await transaction.exec(`CREATE TABLE IF NOT EXISTS ${table} (
|
|
25
|
+
singleton INTEGER PRIMARY KEY CHECK (singleton = 1),
|
|
26
|
+
version INTEGER NOT NULL CHECK (version >= 0)
|
|
27
|
+
)`);
|
|
28
|
+
await transaction.exec(`INSERT INTO ${table} (singleton, version) VALUES (1, 0) ON CONFLICT DO NOTHING`);
|
|
29
|
+
const row = await transaction.get(`SELECT version FROM ${table} WHERE singleton = 1`);
|
|
30
|
+
if (row === void 0) throw new Error("Schema metadata is missing");
|
|
31
|
+
const storedVersion = Number(row.version);
|
|
32
|
+
const currentVersion = migrations.at(-1)?.version ?? 0;
|
|
33
|
+
if (storedVersion > currentVersion) throw new Error(`Schema version ${storedVersion} is newer than supported version ${currentVersion}`);
|
|
34
|
+
for (const migration of migrations) {
|
|
35
|
+
if (migration.version <= storedVersion) continue;
|
|
36
|
+
for (const statement of migration.statements) await transaction.exec(statement);
|
|
37
|
+
await transaction.exec(`UPDATE ${table} SET version = ${String(migration.version)} WHERE singleton = 1`);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region ../../../plugins/db/src/migration-files.ts
|
|
43
|
+
/**
|
|
44
|
+
* An app's migrations as numbered SQL files: `migrations/001-notes.sql`, `002-tags.sql`, ... Each file is one migration, run as one
|
|
45
|
+
* `exec` (so it may hold several statements), numbered from 1 with no gaps.
|
|
46
|
+
*/
|
|
47
|
+
const FILE = /^(\d+)-[a-z0-9][a-z0-9-]*\.sql$/u;
|
|
48
|
+
/**
|
|
49
|
+
* Read every `NNN-name.sql` file of a folder, in number order.
|
|
50
|
+
* @throws when a `.sql` file is not named `NNN-name.sql`, or the numbers do not run 1, 2, 3, ... without gaps or repeats.
|
|
51
|
+
*/
|
|
52
|
+
async function readMigrationFiles(folder) {
|
|
53
|
+
const dir = typeof folder === "string" ? folder : fileURLToPath(folder);
|
|
54
|
+
const numbered = (await readdir(dir)).filter((name) => name.endsWith(".sql")).sort().map((name) => {
|
|
55
|
+
const match = FILE.exec(name);
|
|
56
|
+
if (match?.[1] === void 0) throw new Error(`@acryldev/db: migration file ${name} in ${dir} must be named NNN-name.sql, like 001-notes.sql`);
|
|
57
|
+
return {
|
|
58
|
+
name,
|
|
59
|
+
version: Number(match[1])
|
|
60
|
+
};
|
|
61
|
+
}).sort((a, b) => a.version - b.version);
|
|
62
|
+
numbered.forEach((file, index) => {
|
|
63
|
+
if (file.version !== index + 1) throw new Error(`@acryldev/db: migration ${file.name} in ${dir} should be number ${String(index + 1)}; the files must be numbered 1, 2, 3, ... with no gaps or repeats`);
|
|
64
|
+
});
|
|
65
|
+
return Promise.all(numbered.map(async (file) => ({
|
|
66
|
+
version: file.version,
|
|
67
|
+
statements: [await readFile(join(dir, file.name), "utf8")]
|
|
68
|
+
})));
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
71
|
+
//#region ../../../plugins/db/src/index.ts
|
|
72
|
+
/**
|
|
73
|
+
* The `db` port: what an app's code sees of its relational database, whichever provider (`@acryldev/db-sqlite`, `@acryldev/db-postgres`) serves
|
|
74
|
+
* it. Plain code (an acrylblends app) opens a database with a provider's `openDb`; a Cordis plugin declares `inject: ['db']`, imports
|
|
75
|
+
* `@acryldev/db/cordis` for the `ctx.db` type, and never imports a driver.
|
|
76
|
+
*
|
|
77
|
+
* Bindings are positional `?` placeholders on every provider; a provider whose database spells them differently translates them.
|
|
78
|
+
* This entry imports nothing from Cordis, at runtime or in its types.
|
|
79
|
+
*/
|
|
80
|
+
/** The service name every `db` provider registers. */
|
|
81
|
+
const DB_SERVICE = "db";
|
|
82
|
+
/** The table that records an app's migration version. */
|
|
83
|
+
const MIGRATIONS_TABLE = "_migrations";
|
|
84
|
+
//#endregion
|
|
85
|
+
export { validateSchemaPrefix as a, applyMigrations as i, MIGRATIONS_TABLE as n, readMigrationFiles as r, DB_SERVICE as t };
|