@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,527 @@
|
|
|
1
|
+
import { t as Acryl } from "../app-CM-rDcw6.js";
|
|
2
|
+
import { t as methodNotAllowed } from "../method-not-allowed-B3nMAp1f.js";
|
|
3
|
+
import { r as streamSSE } from "../streaming-CL2i3hX_.js";
|
|
4
|
+
import { a as loopbackOnly, o as pageAuthority } from "../loopback-only-0nTL30Zt.js";
|
|
5
|
+
import "../helpers-qmReU164.js";
|
|
6
|
+
import "../src-BycZ1HUQ.js";
|
|
7
|
+
import "../middleware-B8gJUDgl.js";
|
|
8
|
+
import { Service } from "@deepseek-ai/cordis";
|
|
9
|
+
//#region ../../../plugins/state/src/cell.ts
|
|
10
|
+
/** A writable cell. `report` receives anything a listener throws; one failing listener never blocks the others. */
|
|
11
|
+
function createCell(key, initial, report = () => void 0) {
|
|
12
|
+
let value = initial;
|
|
13
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
14
|
+
const set = (next) => {
|
|
15
|
+
if (Object.is(next, value)) return;
|
|
16
|
+
const previous = value;
|
|
17
|
+
value = next;
|
|
18
|
+
for (const listener of [...listeners]) try {
|
|
19
|
+
listener(next, previous);
|
|
20
|
+
} catch (error) {
|
|
21
|
+
report(error);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
return {
|
|
25
|
+
key,
|
|
26
|
+
get: () => value,
|
|
27
|
+
set,
|
|
28
|
+
update: (change) => {
|
|
29
|
+
set(change(value));
|
|
30
|
+
},
|
|
31
|
+
subscribe: (listener) => {
|
|
32
|
+
listeners.add(listener);
|
|
33
|
+
return () => {
|
|
34
|
+
listeners.delete(listener);
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* A read-only cell computed from other cells and recomputed whenever one of them changes. `dispose` detaches it from its
|
|
41
|
+
* inputs; after that it keeps its last value.
|
|
42
|
+
*/
|
|
43
|
+
function createDerived(key, inputs, compute, report = () => void 0) {
|
|
44
|
+
const read = () => compute(...inputs.map((input) => input.get()));
|
|
45
|
+
const inner = createCell(key, read(), report);
|
|
46
|
+
const stops = inputs.map((input) => input.subscribe(() => {
|
|
47
|
+
inner.set(read());
|
|
48
|
+
}));
|
|
49
|
+
return {
|
|
50
|
+
cell: {
|
|
51
|
+
key,
|
|
52
|
+
get: inner.get,
|
|
53
|
+
subscribe: inner.subscribe
|
|
54
|
+
},
|
|
55
|
+
dispose: () => {
|
|
56
|
+
for (const stop of stops) stop();
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
//#endregion
|
|
61
|
+
//#region ../../../plugins/state/src/client-source.ts
|
|
62
|
+
/**
|
|
63
|
+
* The browser module served at `/api/state/client.js`, kept as text so it travels with the plugin wherever the plugin goes (copied into an app as source, or bundled): there is
|
|
64
|
+
* no file to find at run time and no compiler needed to serve it. `String.raw` keeps every backslash as written, so what is below is the module exactly as the browser gets it.
|
|
65
|
+
* The code has no imports and uses no backtick or dollar-brace of its own.
|
|
66
|
+
*
|
|
67
|
+
* import { watch } from '/api/state/client.js'
|
|
68
|
+
* const stop = watch('tasks.count', (value) => { badge.textContent = String(value) })
|
|
69
|
+
*
|
|
70
|
+
* One WebSocket for the whole page carries every key; a WebSocket is not one of the browser's six connections per host, so a page that watches ten keys, in as many windows,
|
|
71
|
+
* leaves every one of them free for requests. Where the WebSocket cannot open (no `ws` package on the server, a proxy that does not upgrade), each key is followed by its
|
|
72
|
+
* event stream instead, with one console warning.
|
|
73
|
+
*/
|
|
74
|
+
const CLIENT_SOURCE = String.raw`// @acryldev/state: watch(key, onValue, onError?) follows a state key over one WebSocket for the page.
|
|
75
|
+
const HEARTBEAT_SILENCE_MS = 45000
|
|
76
|
+
const RETRY_MIN_MS = 250
|
|
77
|
+
const RETRY_MAX_MS = 10000
|
|
78
|
+
|
|
79
|
+
const here = import.meta.url
|
|
80
|
+
const watchers = new Map()
|
|
81
|
+
const latest = new Map()
|
|
82
|
+
const streams = new Map()
|
|
83
|
+
const complained = new Set()
|
|
84
|
+
let socket
|
|
85
|
+
let timer
|
|
86
|
+
let watchdog
|
|
87
|
+
let attempts = 0
|
|
88
|
+
let opened = false
|
|
89
|
+
let following = 'socket'
|
|
90
|
+
let suspended = false
|
|
91
|
+
let warnedStream = false
|
|
92
|
+
|
|
93
|
+
const socketUrl = () => {
|
|
94
|
+
const url = new URL('ws', here)
|
|
95
|
+
url.protocol = url.protocol === 'https:' ? 'wss:' : 'ws:'
|
|
96
|
+
return url.href
|
|
97
|
+
}
|
|
98
|
+
const streamUrl = (key) => new URL(encodeURIComponent(key) + '/events?json=1', here).href
|
|
99
|
+
|
|
100
|
+
const deliver = (key, text) => {
|
|
101
|
+
if (latest.get(key) === text) return
|
|
102
|
+
latest.set(key, text)
|
|
103
|
+
let value
|
|
104
|
+
try {
|
|
105
|
+
value = JSON.parse(text)
|
|
106
|
+
} catch {
|
|
107
|
+
return
|
|
108
|
+
}
|
|
109
|
+
for (const watcher of [...(watchers.get(key) ?? [])]) {
|
|
110
|
+
try {
|
|
111
|
+
watcher.onValue(value)
|
|
112
|
+
} catch (cause) {
|
|
113
|
+
console.error('@acryldev/state: a watcher of ' + key + ' threw', cause)
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const fail = (key, message) => {
|
|
119
|
+
const set = watchers.get(key)
|
|
120
|
+
if (set === undefined) return
|
|
121
|
+
let told = false
|
|
122
|
+
for (const watcher of [...set]) {
|
|
123
|
+
if (watcher.onError === undefined) continue
|
|
124
|
+
told = true
|
|
125
|
+
try {
|
|
126
|
+
watcher.onError(new Error(message))
|
|
127
|
+
} catch (cause) {
|
|
128
|
+
console.error('@acryldev/state: an error handler of ' + key + ' threw', cause)
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
if (!told && !complained.has(key)) {
|
|
132
|
+
complained.add(key)
|
|
133
|
+
console.warn('@acryldev/state: ' + key + ': ' + message)
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const send = (frame) => {
|
|
138
|
+
if (socket !== undefined && socket.readyState === 1) socket.send(JSON.stringify(frame))
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const arm = () => {
|
|
142
|
+
clearTimeout(watchdog)
|
|
143
|
+
watchdog = setTimeout(() => lost(socket), HEARTBEAT_SILENCE_MS)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const closeSocket = () => {
|
|
147
|
+
clearTimeout(watchdog)
|
|
148
|
+
const current = socket
|
|
149
|
+
socket = undefined
|
|
150
|
+
if (current === undefined) return
|
|
151
|
+
current.onopen = current.onmessage = current.onerror = current.onclose = null
|
|
152
|
+
try {
|
|
153
|
+
current.close(1000, 'page left')
|
|
154
|
+
} catch {
|
|
155
|
+
// Already closed.
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const closeStreams = () => {
|
|
160
|
+
for (const source of streams.values()) source.close()
|
|
161
|
+
streams.clear()
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const openStream = (key) => {
|
|
165
|
+
if (streams.has(key) || typeof EventSource === 'undefined') return
|
|
166
|
+
const source = new EventSource(streamUrl(key))
|
|
167
|
+
streams.set(key, source)
|
|
168
|
+
source.addEventListener('value', (event) => deliver(key, event.data))
|
|
169
|
+
source.onerror = () => {
|
|
170
|
+
// A network error is retried by the browser itself; a refusal (the key does not exist) ends the stream for good.
|
|
171
|
+
if (source.readyState === 2) {
|
|
172
|
+
streams.delete(key)
|
|
173
|
+
fail(key, 'the event stream was refused (no such state?)')
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const fallBack = () => {
|
|
179
|
+
following = 'stream'
|
|
180
|
+
if (!warnedStream) {
|
|
181
|
+
warnedStream = true
|
|
182
|
+
console.warn('@acryldev/state: the WebSocket did not open, so each key is followed by its own event stream (each holds one of the browser\'s six connections to this host)')
|
|
183
|
+
}
|
|
184
|
+
for (const key of watchers.keys()) openStream(key)
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// A socket that closes, errors or goes quiet: before it ever opened this is a server without WebSockets, so the streams take over; after, the server went away and the page tries again.
|
|
188
|
+
const lost = (which) => {
|
|
189
|
+
if (which !== socket) return
|
|
190
|
+
closeSocket()
|
|
191
|
+
if (watchers.size === 0 || suspended) return
|
|
192
|
+
if (!opened) {
|
|
193
|
+
fallBack()
|
|
194
|
+
return
|
|
195
|
+
}
|
|
196
|
+
const delay = Math.min(RETRY_MIN_MS * 2 ** attempts, RETRY_MAX_MS)
|
|
197
|
+
attempts += 1
|
|
198
|
+
clearTimeout(timer)
|
|
199
|
+
timer = setTimeout(connect, delay)
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const connect = () => {
|
|
203
|
+
clearTimeout(timer)
|
|
204
|
+
if (socket !== undefined || watchers.size === 0 || suspended || following !== 'socket') return
|
|
205
|
+
let made
|
|
206
|
+
try {
|
|
207
|
+
made = new WebSocket(socketUrl())
|
|
208
|
+
} catch {
|
|
209
|
+
fallBack()
|
|
210
|
+
return
|
|
211
|
+
}
|
|
212
|
+
socket = made
|
|
213
|
+
made.onopen = () => {
|
|
214
|
+
opened = true
|
|
215
|
+
attempts = 0
|
|
216
|
+
arm()
|
|
217
|
+
for (const key of watchers.keys()) send({ t: 'sub', key })
|
|
218
|
+
}
|
|
219
|
+
made.onmessage = (event) => {
|
|
220
|
+
if (made !== socket) return
|
|
221
|
+
arm()
|
|
222
|
+
let frame
|
|
223
|
+
try {
|
|
224
|
+
frame = JSON.parse(event.data)
|
|
225
|
+
} catch {
|
|
226
|
+
return
|
|
227
|
+
}
|
|
228
|
+
if (frame === null || typeof frame !== 'object' || typeof frame.key !== 'string') return
|
|
229
|
+
if (typeof frame.error === 'string') fail(frame.key, frame.error)
|
|
230
|
+
else deliver(frame.key, JSON.stringify(frame.value))
|
|
231
|
+
}
|
|
232
|
+
made.onerror = () => lost(made)
|
|
233
|
+
made.onclose = () => lost(made)
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const start = () => {
|
|
237
|
+
if (watchers.size === 0) return
|
|
238
|
+
if (following === 'stream') for (const key of watchers.keys()) openStream(key)
|
|
239
|
+
else connect()
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
if (typeof addEventListener === 'function') {
|
|
243
|
+
// A page in the back/forward cache keeps its connections open for as long as it is kept; let them go when the page is hidden for good, and open them again when it comes back.
|
|
244
|
+
addEventListener('pagehide', () => {
|
|
245
|
+
suspended = true
|
|
246
|
+
clearTimeout(timer)
|
|
247
|
+
closeSocket()
|
|
248
|
+
closeStreams()
|
|
249
|
+
})
|
|
250
|
+
addEventListener('pageshow', () => {
|
|
251
|
+
if (!suspended) return
|
|
252
|
+
suspended = false
|
|
253
|
+
start()
|
|
254
|
+
})
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// Follow the state key: onValue gets the value now and after every change, as the JSON value the server holds (a string stays a string). onError, when given, is told of a key that
|
|
258
|
+
// does not exist; without it the page console gets one warning. Returns the function that stops watching.
|
|
259
|
+
export function watch(key, onValue, onError) {
|
|
260
|
+
if (typeof key !== 'string' || key === '') throw new TypeError('watch(key, onValue): the key is a state key like "tasks.count"')
|
|
261
|
+
if (typeof onValue !== 'function') throw new TypeError('watch(key, onValue): onValue is a function')
|
|
262
|
+
const watcher = { onValue, onError }
|
|
263
|
+
let set = watchers.get(key)
|
|
264
|
+
const first = set === undefined
|
|
265
|
+
if (first) {
|
|
266
|
+
set = new Set()
|
|
267
|
+
watchers.set(key, set)
|
|
268
|
+
}
|
|
269
|
+
set.add(watcher)
|
|
270
|
+
complained.delete(key)
|
|
271
|
+
if (!first && latest.has(key)) {
|
|
272
|
+
const text = latest.get(key)
|
|
273
|
+
queueMicrotask(() => {
|
|
274
|
+
if (!set.has(watcher)) return
|
|
275
|
+
try {
|
|
276
|
+
onValue(JSON.parse(text))
|
|
277
|
+
} catch (cause) {
|
|
278
|
+
console.error('@acryldev/state: a watcher of ' + key + ' threw', cause)
|
|
279
|
+
}
|
|
280
|
+
})
|
|
281
|
+
}
|
|
282
|
+
if (first && !suspended) {
|
|
283
|
+
if (following === 'stream') openStream(key)
|
|
284
|
+
else if (socket === undefined) connect()
|
|
285
|
+
else send({ t: 'sub', key })
|
|
286
|
+
}
|
|
287
|
+
let stopped = false
|
|
288
|
+
return () => {
|
|
289
|
+
if (stopped) return
|
|
290
|
+
stopped = true
|
|
291
|
+
set.delete(watcher)
|
|
292
|
+
if (set.size > 0) return
|
|
293
|
+
watchers.delete(key)
|
|
294
|
+
latest.delete(key)
|
|
295
|
+
complained.delete(key)
|
|
296
|
+
streams.get(key)?.close()
|
|
297
|
+
streams.delete(key)
|
|
298
|
+
send({ t: 'unsub', key })
|
|
299
|
+
if (watchers.size === 0) {
|
|
300
|
+
clearTimeout(timer)
|
|
301
|
+
closeSocket()
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
`;
|
|
306
|
+
/** A refusal (403) unless the upgrade comes from this machine to this app, and from its own page when it comes from a page at all. */
|
|
307
|
+
function refuseStranger(c) {
|
|
308
|
+
const authority = pageAuthority(c);
|
|
309
|
+
if (authority === void 0) return c.json({ error: "request authority rejected" }, 403);
|
|
310
|
+
const origin = c.req.header("origin");
|
|
311
|
+
const site = c.req.header("sec-fetch-site");
|
|
312
|
+
if (origin !== void 0 && origin !== authority.origin || site !== void 0 && site !== "same-origin") return c.json({ error: "only this app's own page may follow its state" }, 403);
|
|
313
|
+
}
|
|
314
|
+
/** The route handler that upgrades and follows keys of `cells` for as long as the socket is open. */
|
|
315
|
+
function stateSocket(cells, options) {
|
|
316
|
+
const heartbeatMs = options.heartbeatMs ?? 15e3;
|
|
317
|
+
return options.upgrade(() => {
|
|
318
|
+
const following = /* @__PURE__ */ new Map();
|
|
319
|
+
let beat;
|
|
320
|
+
return {
|
|
321
|
+
onOpen(_event, ws) {
|
|
322
|
+
beat = setInterval(() => {
|
|
323
|
+
try {
|
|
324
|
+
ws.send(JSON.stringify({ t: "ping" }));
|
|
325
|
+
} catch {}
|
|
326
|
+
}, heartbeatMs);
|
|
327
|
+
beat.unref();
|
|
328
|
+
},
|
|
329
|
+
onMessage(event, ws) {
|
|
330
|
+
if (typeof event.data !== "string") return;
|
|
331
|
+
let message;
|
|
332
|
+
try {
|
|
333
|
+
message = JSON.parse(event.data);
|
|
334
|
+
} catch {
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
if (typeof message.key !== "string") return;
|
|
338
|
+
const key = message.key;
|
|
339
|
+
const tell = (frame) => {
|
|
340
|
+
try {
|
|
341
|
+
ws.send(JSON.stringify(frame));
|
|
342
|
+
} catch {}
|
|
343
|
+
};
|
|
344
|
+
const value = (current) => {
|
|
345
|
+
let text;
|
|
346
|
+
try {
|
|
347
|
+
text = JSON.stringify({
|
|
348
|
+
key,
|
|
349
|
+
value: current === void 0 ? null : current
|
|
350
|
+
});
|
|
351
|
+
} catch {
|
|
352
|
+
tell({
|
|
353
|
+
key,
|
|
354
|
+
error: "the value cannot be sent as JSON"
|
|
355
|
+
});
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
try {
|
|
359
|
+
ws.send(text);
|
|
360
|
+
} catch {}
|
|
361
|
+
};
|
|
362
|
+
if (message.t === "unsub") {
|
|
363
|
+
following.get(key)?.();
|
|
364
|
+
following.delete(key);
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
if (message.t !== "sub") return;
|
|
368
|
+
const cell = cells.find(key);
|
|
369
|
+
if (cell === void 0) {
|
|
370
|
+
tell({
|
|
371
|
+
key,
|
|
372
|
+
error: "no such state"
|
|
373
|
+
});
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
const known = following.has(key);
|
|
377
|
+
if (!known && following.size >= 256) {
|
|
378
|
+
tell({
|
|
379
|
+
key,
|
|
380
|
+
error: "too many keys on one socket"
|
|
381
|
+
});
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
if (known) {
|
|
385
|
+
value(cell.get());
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
value(cell.get());
|
|
389
|
+
following.set(key, cell.subscribe(value));
|
|
390
|
+
},
|
|
391
|
+
onClose() {
|
|
392
|
+
if (beat !== void 0) clearInterval(beat);
|
|
393
|
+
for (const stop of following.values()) stop();
|
|
394
|
+
following.clear();
|
|
395
|
+
}
|
|
396
|
+
};
|
|
397
|
+
}, { textOnly: true });
|
|
398
|
+
}
|
|
399
|
+
//#endregion
|
|
400
|
+
//#region ../../../plugins/state/src/service.ts
|
|
401
|
+
/**
|
|
402
|
+
* The ACRYL state service (`ctx.state`): observable cells owned by plugins. A cell created from a plugin's context is removed
|
|
403
|
+
* when that plugin unloads, so a surface never keeps a value alive for a plugin that is gone. In process the cells are read
|
|
404
|
+
* and subscribed to directly (the terminal UI); with a router present they are also readable as JSON and streamable as
|
|
405
|
+
* server-sent events (Web and Desktop), read-only: only the Host plugin that owns a cell writes it.
|
|
406
|
+
*/
|
|
407
|
+
const KEEP_ALIVE_MS = 15e3;
|
|
408
|
+
/** Stable Cordis plugin name, equal to the package name and the Loader row id. */
|
|
409
|
+
const name = "acryl-state";
|
|
410
|
+
const KEY_PATTERN = /^[a-z][a-z0-9-]*(\.[a-z][a-z0-9-]*)*$/;
|
|
411
|
+
/** Names under `/api/state` that are routes, not keys: a cell cannot be called by one. */
|
|
412
|
+
const RESERVED_KEYS = /* @__PURE__ */ new Set(["ws", "client.js"]);
|
|
413
|
+
var State = class extends Service {
|
|
414
|
+
cells = /* @__PURE__ */ new Map();
|
|
415
|
+
constructor(ctx) {
|
|
416
|
+
super(ctx, "state");
|
|
417
|
+
}
|
|
418
|
+
claim(key) {
|
|
419
|
+
if (!KEY_PATTERN.test(key)) throw new TypeError(`@acryldev/state: key "${key}" must be dotted lowercase words, like "market.sources"`);
|
|
420
|
+
if (RESERVED_KEYS.has(key)) throw new TypeError(`@acryldev/state: "${key}" is the name of a route under /api/state, choose another key`);
|
|
421
|
+
if (this.cells.has(key)) throw new Error(`@acryldev/state: key "${key}" is already in use`);
|
|
422
|
+
}
|
|
423
|
+
report = (error) => {
|
|
424
|
+
this.ctx.logger.error(`@acryldev/state: a subscriber failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
425
|
+
};
|
|
426
|
+
/** Create a writable cell owned by the calling plugin. The key must be new. */
|
|
427
|
+
cell(key, initial) {
|
|
428
|
+
this.claim(key);
|
|
429
|
+
const cell = createCell(key, initial, this.report);
|
|
430
|
+
this.cells.set(key, cell);
|
|
431
|
+
this.ctx.effect(() => () => {
|
|
432
|
+
this.cells.delete(key);
|
|
433
|
+
}, `@acryldev/state: cell ${key}`);
|
|
434
|
+
return cell;
|
|
435
|
+
}
|
|
436
|
+
/** Create a read-only cell computed from other cells, owned by the calling plugin. */
|
|
437
|
+
derive(key, inputs, compute) {
|
|
438
|
+
this.claim(key);
|
|
439
|
+
const derived = createDerived(key, inputs, compute, this.report);
|
|
440
|
+
this.cells.set(key, derived.cell);
|
|
441
|
+
this.ctx.effect(() => () => {
|
|
442
|
+
derived.dispose();
|
|
443
|
+
this.cells.delete(key);
|
|
444
|
+
}, `@acryldev/state: derived ${key}`);
|
|
445
|
+
return derived.cell;
|
|
446
|
+
}
|
|
447
|
+
/** A cell by key, if one is live. */
|
|
448
|
+
find(key) {
|
|
449
|
+
return this.cells.get(key);
|
|
450
|
+
}
|
|
451
|
+
keys() {
|
|
452
|
+
return [...this.cells.keys()].sort();
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* The current value of `key` as a server-sent event stream: the value now, then one event per change, until the client cancels or the router
|
|
456
|
+
* is disposed (both abort the stream). A comment line goes out every 15 seconds so proxies and browsers keep an idle stream open. A string value travels as it is; with `json`
|
|
457
|
+
* (the `?json=1` of the browser client) every value is JSON, so `"12"` and `12` can be told apart.
|
|
458
|
+
*/
|
|
459
|
+
stream(key, c, json = false) {
|
|
460
|
+
const cell = this.find(key);
|
|
461
|
+
if (cell === void 0) return void 0;
|
|
462
|
+
return streamSSE(c, async (stream) => {
|
|
463
|
+
const ended = new Promise((resolve) => {
|
|
464
|
+
stream.onAbort(resolve);
|
|
465
|
+
});
|
|
466
|
+
let queue = Promise.resolve();
|
|
467
|
+
const send = (value) => {
|
|
468
|
+
queue = queue.then(() => stream.writeSSE({
|
|
469
|
+
event: "value",
|
|
470
|
+
data: typeof value === "string" && !json ? value : JSON.stringify(value)
|
|
471
|
+
})).catch(() => {});
|
|
472
|
+
};
|
|
473
|
+
send(cell.get());
|
|
474
|
+
const unsubscribe = cell.subscribe(send);
|
|
475
|
+
const keepAlive = setInterval(() => {
|
|
476
|
+
queue = queue.then(() => stream.write(": keepalive\n\n")).catch(() => {});
|
|
477
|
+
}, KEEP_ALIVE_MS);
|
|
478
|
+
keepAlive.unref();
|
|
479
|
+
try {
|
|
480
|
+
await ended;
|
|
481
|
+
} finally {
|
|
482
|
+
clearInterval(keepAlive);
|
|
483
|
+
unsubscribe();
|
|
484
|
+
}
|
|
485
|
+
});
|
|
486
|
+
}
|
|
487
|
+
};
|
|
488
|
+
function apply(ctx) {
|
|
489
|
+
const state = new State(ctx);
|
|
490
|
+
ctx.inject(["router"], (inner) => {
|
|
491
|
+
const api = new Acryl();
|
|
492
|
+
let socket;
|
|
493
|
+
api.use(loopbackOnly({ inProcess: "allow" }), methodNotAllowed({ app: api })).get("/", (c) => c.json({ keys: state.keys() })).get("/client.js", (c) => c.body(CLIENT_SOURCE, 200, {
|
|
494
|
+
"content-type": "text/javascript; charset=utf-8",
|
|
495
|
+
"cache-control": "no-cache"
|
|
496
|
+
})).get("/ws", async (c, next) => {
|
|
497
|
+
const upgrade = socket;
|
|
498
|
+
if (upgrade === void 0) return c.json({ error: "this server does not upgrade to a WebSocket" }, 404);
|
|
499
|
+
const refusal = refuseStranger(c);
|
|
500
|
+
if (refusal !== void 0) return refusal;
|
|
501
|
+
return await upgrade(c, next);
|
|
502
|
+
}).get("/:key", (c) => {
|
|
503
|
+
const cell = state.find(c.req.param("key"));
|
|
504
|
+
return cell === void 0 ? c.json({ error: "no such state" }, 404) : c.json({
|
|
505
|
+
key: cell.key,
|
|
506
|
+
value: cell.get()
|
|
507
|
+
});
|
|
508
|
+
}).get("/:key/events", (c) => state.stream(c.req.param("key"), c, c.req.query("json") === "1") ?? c.json({ error: "no such state" }, 404));
|
|
509
|
+
inner.router.route("/api/state", api);
|
|
510
|
+
inner.inject(["nodeServer"], (withServer) => {
|
|
511
|
+
try {
|
|
512
|
+
const upgrade = withServer.nodeServer.upgrades();
|
|
513
|
+
socket = stateSocket(state, { upgrade });
|
|
514
|
+
withServer.effect(() => () => {
|
|
515
|
+
socket = void 0;
|
|
516
|
+
}, "@acryldev/state: the WebSocket route");
|
|
517
|
+
} catch (cause) {
|
|
518
|
+
ctx.logger.warn(`@acryldev/state: state is followed by event streams only (${cause instanceof Error ? cause.message : String(cause)})`);
|
|
519
|
+
}
|
|
520
|
+
});
|
|
521
|
+
inner.inject(["routerHttp"], (http) => {
|
|
522
|
+
http.routerHttp.mount("/api/state");
|
|
523
|
+
});
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
//#endregion
|
|
527
|
+
export { State, apply, createCell, createDerived, name };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import "./app-CM-rDcw6.js";
|
|
2
|
+
//#region ../../../plugins/router/src/core/index.ts
|
|
3
|
+
/**
|
|
4
|
+
* @module
|
|
5
|
+
*
|
|
6
|
+
* Acryl - Web Framework built on Web Standards
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { Acryl } from '@acryldev/blends'
|
|
11
|
+
* const app = new Acryl()
|
|
12
|
+
*
|
|
13
|
+
* app.get('/', (c) => c.text('Acryl!'))
|
|
14
|
+
*
|
|
15
|
+
* export default app
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
//#endregion
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
//#region ../../../plugins/router/src/core/middleware/cors/index.ts
|
|
2
|
+
/**
|
|
3
|
+
* CORS Middleware for Acryl.
|
|
4
|
+
*
|
|
5
|
+
*
|
|
6
|
+
* @param {CORSOptions} [options] - The options for the CORS middleware.
|
|
7
|
+
* @param {string | string[] | ((origin: string, c: Context) => Promise<string | undefined | null> | string | undefined | null)} [options.origin='*'] - The value of "Access-Control-Allow-Origin" CORS header.
|
|
8
|
+
* @param {string[] | ((origin: string, c: Context) => Promise<string[]> | string[])} [options.allowMethods=['GET', 'HEAD', 'PUT', 'POST', 'DELETE', 'PATCH', 'QUERY']] - The value of "Access-Control-Allow-Methods" CORS header.
|
|
9
|
+
* @param {string[]} [options.allowHeaders=[]] - The value of "Access-Control-Allow-Headers" CORS header.
|
|
10
|
+
* @param {number} [options.maxAge] - The value of "Access-Control-Max-Age" CORS header.
|
|
11
|
+
* @param {boolean} [options.credentials] - The value of "Access-Control-Allow-Credentials" CORS header.
|
|
12
|
+
* @param {string[]} [options.exposeHeaders=[]] - The value of "Access-Control-Expose-Headers" CORS header.
|
|
13
|
+
* @returns {MiddlewareHandler} The middleware handler function.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* const app = new Acryl()
|
|
18
|
+
*
|
|
19
|
+
* app.use('/api/*', cors())
|
|
20
|
+
* app.use(
|
|
21
|
+
* '/api2/*',
|
|
22
|
+
* cors({
|
|
23
|
+
* origin: 'http://example.com',
|
|
24
|
+
* allowHeaders: ['X-Custom-Header', 'Upgrade-Insecure-Requests'],
|
|
25
|
+
* allowMethods: ['POST', 'GET', 'OPTIONS'],
|
|
26
|
+
* exposeHeaders: ['Content-Length', 'X-Kuma-Revision'],
|
|
27
|
+
* maxAge: 600,
|
|
28
|
+
* credentials: true,
|
|
29
|
+
* })
|
|
30
|
+
* )
|
|
31
|
+
*
|
|
32
|
+
* app.all('/api/abc', (c) => {
|
|
33
|
+
* return c.json({ success: true })
|
|
34
|
+
* })
|
|
35
|
+
* app.all('/api2/abc', (c) => {
|
|
36
|
+
* return c.json({ success: true })
|
|
37
|
+
* })
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
const cors = (options) => {
|
|
41
|
+
const opts = {
|
|
42
|
+
origin: "*",
|
|
43
|
+
allowMethods: [
|
|
44
|
+
"GET",
|
|
45
|
+
"HEAD",
|
|
46
|
+
"PUT",
|
|
47
|
+
"POST",
|
|
48
|
+
"DELETE",
|
|
49
|
+
"PATCH",
|
|
50
|
+
"QUERY"
|
|
51
|
+
],
|
|
52
|
+
allowHeaders: [],
|
|
53
|
+
exposeHeaders: [],
|
|
54
|
+
...options
|
|
55
|
+
};
|
|
56
|
+
const exposeHeadersStr = opts.exposeHeaders?.length ? opts.exposeHeaders.join(",") : void 0;
|
|
57
|
+
const allowHeadersStr = opts.allowHeaders?.length ? opts.allowHeaders.join(",") : void 0;
|
|
58
|
+
const findAllowOrigin = ((optsOrigin) => {
|
|
59
|
+
if (typeof optsOrigin === "string") if (optsOrigin === "*") return () => optsOrigin;
|
|
60
|
+
else return (origin) => optsOrigin === origin ? origin : null;
|
|
61
|
+
else if (typeof optsOrigin === "function") return optsOrigin;
|
|
62
|
+
else return (origin) => optsOrigin.includes(origin) ? origin : null;
|
|
63
|
+
})(opts.origin);
|
|
64
|
+
const findAllowMethods = ((optsAllowMethods) => {
|
|
65
|
+
if (typeof optsAllowMethods === "function") return async (origin, c) => (await optsAllowMethods(origin, c)).join(",");
|
|
66
|
+
else if (Array.isArray(optsAllowMethods)) {
|
|
67
|
+
const methodsStr = optsAllowMethods.join(",");
|
|
68
|
+
return () => methodsStr;
|
|
69
|
+
} else return () => "";
|
|
70
|
+
})(opts.allowMethods);
|
|
71
|
+
return async function cors(c, next) {
|
|
72
|
+
function set(key, value) {
|
|
73
|
+
c.res.headers.set(key, value);
|
|
74
|
+
}
|
|
75
|
+
const allowOrigin = await findAllowOrigin(c.req.header("origin") || "", c);
|
|
76
|
+
if (allowOrigin) set("Access-Control-Allow-Origin", allowOrigin);
|
|
77
|
+
if (opts.credentials) set("Access-Control-Allow-Credentials", "true");
|
|
78
|
+
if (exposeHeadersStr) set("Access-Control-Expose-Headers", exposeHeadersStr);
|
|
79
|
+
if (c.req.method === "OPTIONS") {
|
|
80
|
+
if (opts.origin !== "*") c.res.headers.append("Vary", "Origin");
|
|
81
|
+
if (opts.maxAge != null) set("Access-Control-Max-Age", opts.maxAge.toString());
|
|
82
|
+
const allowMethods = await findAllowMethods(c.req.header("origin") || "", c);
|
|
83
|
+
if (allowMethods) set("Access-Control-Allow-Methods", allowMethods);
|
|
84
|
+
let headersStr = allowHeadersStr;
|
|
85
|
+
if (!headersStr) {
|
|
86
|
+
const requestHeaders = c.req.header("Access-Control-Request-Headers");
|
|
87
|
+
if (requestHeaders) headersStr = requestHeaders.split(",").map((h) => h.trim()).join(",");
|
|
88
|
+
}
|
|
89
|
+
if (headersStr) {
|
|
90
|
+
set("Access-Control-Allow-Headers", headersStr);
|
|
91
|
+
c.res.headers.append("Vary", "Access-Control-Request-Headers");
|
|
92
|
+
}
|
|
93
|
+
c.res.headers.delete("Content-Length");
|
|
94
|
+
c.res.headers.delete("Content-Type");
|
|
95
|
+
return new Response(null, {
|
|
96
|
+
headers: c.res.headers,
|
|
97
|
+
status: 204,
|
|
98
|
+
statusText: "No Content"
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
await next();
|
|
102
|
+
if (opts.origin !== "*") c.header("Vary", "Origin", { append: true });
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
//#endregion
|
|
106
|
+
export { cors as t };
|
package/lib/cors.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { L as MiddlewareHandler, t as Context } from "./context-Ca3uX_bh.js";
|
|
2
|
+
|
|
3
|
+
//#region ../../../plugins/router/src/core/middleware/cors/index.d.ts
|
|
4
|
+
type CORSOptions = {
|
|
5
|
+
origin?: string | string[] | ((origin: string, c: Context) => Promise<string | undefined | null> | string | undefined | null);
|
|
6
|
+
allowMethods?: string[] | ((origin: string, c: Context) => Promise<string[]> | string[]);
|
|
7
|
+
allowHeaders?: string[];
|
|
8
|
+
maxAge?: number;
|
|
9
|
+
credentials?: boolean;
|
|
10
|
+
exposeHeaders?: string[];
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* CORS Middleware for Acryl.
|
|
14
|
+
*
|
|
15
|
+
*
|
|
16
|
+
* @param {CORSOptions} [options] - The options for the CORS middleware.
|
|
17
|
+
* @param {string | string[] | ((origin: string, c: Context) => Promise<string | undefined | null> | string | undefined | null)} [options.origin='*'] - The value of "Access-Control-Allow-Origin" CORS header.
|
|
18
|
+
* @param {string[] | ((origin: string, c: Context) => Promise<string[]> | string[])} [options.allowMethods=['GET', 'HEAD', 'PUT', 'POST', 'DELETE', 'PATCH', 'QUERY']] - The value of "Access-Control-Allow-Methods" CORS header.
|
|
19
|
+
* @param {string[]} [options.allowHeaders=[]] - The value of "Access-Control-Allow-Headers" CORS header.
|
|
20
|
+
* @param {number} [options.maxAge] - The value of "Access-Control-Max-Age" CORS header.
|
|
21
|
+
* @param {boolean} [options.credentials] - The value of "Access-Control-Allow-Credentials" CORS header.
|
|
22
|
+
* @param {string[]} [options.exposeHeaders=[]] - The value of "Access-Control-Expose-Headers" CORS header.
|
|
23
|
+
* @returns {MiddlewareHandler} The middleware handler function.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* const app = new Acryl()
|
|
28
|
+
*
|
|
29
|
+
* app.use('/api/*', cors())
|
|
30
|
+
* app.use(
|
|
31
|
+
* '/api2/*',
|
|
32
|
+
* cors({
|
|
33
|
+
* origin: 'http://example.com',
|
|
34
|
+
* allowHeaders: ['X-Custom-Header', 'Upgrade-Insecure-Requests'],
|
|
35
|
+
* allowMethods: ['POST', 'GET', 'OPTIONS'],
|
|
36
|
+
* exposeHeaders: ['Content-Length', 'X-Kuma-Revision'],
|
|
37
|
+
* maxAge: 600,
|
|
38
|
+
* credentials: true,
|
|
39
|
+
* })
|
|
40
|
+
* )
|
|
41
|
+
*
|
|
42
|
+
* app.all('/api/abc', (c) => {
|
|
43
|
+
* return c.json({ success: true })
|
|
44
|
+
* })
|
|
45
|
+
* app.all('/api2/abc', (c) => {
|
|
46
|
+
* return c.json({ success: true })
|
|
47
|
+
* })
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
declare const cors: (options?: CORSOptions) => MiddlewareHandler;
|
|
51
|
+
//#endregion
|
|
52
|
+
export { cors };
|