loopwind 0.17.0 → 0.18.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/dist/sdk/index.d.ts +2 -2
- package/dist/sdk/index.d.ts.map +1 -1
- package/dist/sdk/index.js +1 -1
- package/dist/sdk/index.js.map +1 -1
- package/dist/sdk/template.d.ts +97 -0
- package/dist/sdk/template.d.ts.map +1 -1
- package/dist/sdk/template.js +217 -0
- package/dist/sdk/template.js.map +1 -1
- package/examples/code-editor-templates.ts +173 -0
- package/examples/nextjs-template-import.ts +58 -0
- package/examples/visual-builder-templates.ts +336 -0
- package/package.json +3 -1
- package/test-jsx-support.mjs +120 -0
- package/test-sdk-user-templates.mjs +469 -0
- package/website/.astro/integrations/_inox-tools_astro-when/types.d.ts +1 -0
- package/website/.astro/types.d.ts +1 -0
- package/website/DEPLOYMENT.md +142 -0
- package/website/OG_IMAGES.md +141 -0
- package/website/astro.config.mjs +9 -1
- package/website/dist/.gitkeep +1 -0
- package/website/dist/_astro/agents.Yx-L_igG.css +1 -0
- package/website/dist/_routes.json +30 -0
- package/website/dist/_worker.js/_@astrojs-ssr-adapter.mjs +1033 -0
- package/website/dist/_worker.js/_astro-internal_middleware.mjs +40 -0
- package/website/dist/_worker.js/chunks/abap_BTmsHiP5.mjs +1 -0
- package/website/dist/_worker.js/chunks/actionscript-3_DmBelb1E.mjs +1 -0
- package/website/dist/_worker.js/chunks/ada_8-E0ahCN.mjs +1 -0
- package/website/dist/_worker.js/chunks/andromeeda_XI-CXx50.mjs +1 -0
- package/website/dist/_worker.js/chunks/angular-html_DKGh3gGH.mjs +1 -0
- package/website/dist/_worker.js/chunks/angular-ts_-qZGsJoA.mjs +1 -0
- package/website/dist/_worker.js/chunks/apache_ijTUt0Ee.mjs +1 -0
- package/website/dist/_worker.js/chunks/apex_agu1c6Sh.mjs +1 -0
- package/website/dist/_worker.js/chunks/apl_Bj2f7Art.mjs +1 -0
- package/website/dist/_worker.js/chunks/applescript_B_vXrOh3.mjs +1 -0
- package/website/dist/_worker.js/chunks/ara_DCEQ2rnh.mjs +1 -0
- package/website/dist/_worker.js/chunks/asciidoc_CGN_EkYS.mjs +1 -0
- package/website/dist/_worker.js/chunks/asm_BBWZgnDp.mjs +1 -0
- package/website/dist/_worker.js/chunks/astro/assets-service_j52rQLzU.mjs +721 -0
- package/website/dist/_worker.js/chunks/astro/server_Y5_QHO8v.mjs +2401 -0
- package/website/dist/_worker.js/chunks/astro-designed-error-pages_BNTLO-TA.mjs +542 -0
- package/website/dist/_worker.js/chunks/astro_Dr_hht3h.mjs +1 -0
- package/website/dist/_worker.js/chunks/aurora-x_9GHG8nSq.mjs +1 -0
- package/website/dist/_worker.js/chunks/awk_DHRvhXot.mjs +1 -0
- package/website/dist/_worker.js/chunks/ayu-dark_CcvqmEHE.mjs +1 -0
- package/website/dist/_worker.js/chunks/ballerina_C7SdeSZb.mjs +1 -0
- package/website/dist/_worker.js/chunks/bat_Dv4A3u45.mjs +1 -0
- package/website/dist/_worker.js/chunks/beancount_BfPf9Luv.mjs +1 -0
- package/website/dist/_worker.js/chunks/berry_B8rfM3lL.mjs +1 -0
- package/website/dist/_worker.js/chunks/bibtex_TcjYgtJM.mjs +1 -0
- package/website/dist/_worker.js/chunks/bicep_CrlFWCdN.mjs +1 -0
- package/website/dist/_worker.js/chunks/blade_lanKVYID.mjs +1 -0
- package/website/dist/_worker.js/chunks/bsl_BhppzXMB.mjs +1 -0
- package/website/dist/_worker.js/chunks/c_6FBALJTK.mjs +1 -0
- package/website/dist/_worker.js/chunks/cadence_2txU9LVE.mjs +1 -0
- package/website/dist/_worker.js/chunks/cairo_BkrFAIlP.mjs +1 -0
- package/website/dist/_worker.js/chunks/catppuccin-frappe_CkEqIYhU.mjs +1 -0
- package/website/dist/_worker.js/chunks/catppuccin-latte_DG4Gx_-v.mjs +1 -0
- package/website/dist/_worker.js/chunks/catppuccin-macchiato_Cwi3vCXf.mjs +1 -0
- package/website/dist/_worker.js/chunks/catppuccin-mocha_L9_OPlFX.mjs +1 -0
- package/website/dist/_worker.js/chunks/clarity_BEAe4Ulu.mjs +1 -0
- package/website/dist/_worker.js/chunks/clojure_VnUX6p2g.mjs +1 -0
- package/website/dist/_worker.js/chunks/cmake_0-SGkZEj.mjs +1 -0
- package/website/dist/_worker.js/chunks/cobol_92M_KGaE.mjs +1 -0
- package/website/dist/_worker.js/chunks/codeowners_CzMwskBv.mjs +1 -0
- package/website/dist/_worker.js/chunks/codeql_DWJZNHv1.mjs +1 -0
- package/website/dist/_worker.js/chunks/coffee_CQjKU2fh.mjs +1 -0
- package/website/dist/_worker.js/chunks/common-lisp_BBLWDpS5.mjs +1 -0
- package/website/dist/_worker.js/chunks/coq_hedRFV3D.mjs +1 -0
- package/website/dist/_worker.js/chunks/cpp_DlS1i6Zs.mjs +1 -0
- package/website/dist/_worker.js/chunks/crystal_D6n65fKV.mjs +1 -0
- package/website/dist/_worker.js/chunks/csharp_C6FCVFzc.mjs +1 -0
- package/website/dist/_worker.js/chunks/css_C5uJEgmJ.mjs +1 -0
- package/website/dist/_worker.js/chunks/csv_CtMYuuJl.mjs +1 -0
- package/website/dist/_worker.js/chunks/cue_BsPexqx6.mjs +1 -0
- package/website/dist/_worker.js/chunks/cypher_apzf6OBi.mjs +1 -0
- package/website/dist/_worker.js/chunks/d_DcvIRcgm.mjs +1 -0
- package/website/dist/_worker.js/chunks/dark-plus_C01ONtzj.mjs +1 -0
- package/website/dist/_worker.js/chunks/dart_WkzM5WrV.mjs +1 -0
- package/website/dist/_worker.js/chunks/dax_DjXAO5V4.mjs +1 -0
- package/website/dist/_worker.js/chunks/desktop_C92LCxdc.mjs +1 -0
- package/website/dist/_worker.js/chunks/diff_CVwM_9XJ.mjs +1 -0
- package/website/dist/_worker.js/chunks/docker_DPzgJf6Z.mjs +1 -0
- package/website/dist/_worker.js/chunks/dotenv_D_vgANvA.mjs +1 -0
- package/website/dist/_worker.js/chunks/dracula-soft_CLnUBwFm.mjs +1 -0
- package/website/dist/_worker.js/chunks/dracula_lBVpb6Lb.mjs +1 -0
- package/website/dist/_worker.js/chunks/dream-maker_DTLbzd_J.mjs +1 -0
- package/website/dist/_worker.js/chunks/edge_i54JYm3_.mjs +1 -0
- package/website/dist/_worker.js/chunks/elixir_BJCIjTu4.mjs +1 -0
- package/website/dist/_worker.js/chunks/elm_BbXD39-_.mjs +1 -0
- package/website/dist/_worker.js/chunks/emacs-lisp_pxa5cXaN.mjs +1 -0
- package/website/dist/_worker.js/chunks/erb_Ccjijeee.mjs +1 -0
- package/website/dist/_worker.js/chunks/erlang_B2VM_hi7.mjs +1 -0
- package/website/dist/_worker.js/chunks/everforest-dark_BxvIPBim.mjs +1 -0
- package/website/dist/_worker.js/chunks/everforest-light_B7VoyaJM.mjs +1 -0
- package/website/dist/_worker.js/chunks/fennel_D-uo7X6c.mjs +1 -0
- package/website/dist/_worker.js/chunks/fish_BjePoK3m.mjs +1 -0
- package/website/dist/_worker.js/chunks/fluent_C8fgkzLX.mjs +1 -0
- package/website/dist/_worker.js/chunks/fortran-fixed-form_D1pu5zrc.mjs +1 -0
- package/website/dist/_worker.js/chunks/fortran-free-form_CSGOhJD6.mjs +1 -0
- package/website/dist/_worker.js/chunks/fsharp_B0xy-A4Y.mjs +1 -0
- package/website/dist/_worker.js/chunks/gdresource_CWppjlHq.mjs +1 -0
- package/website/dist/_worker.js/chunks/gdscript_eQCHchcS.mjs +1 -0
- package/website/dist/_worker.js/chunks/gdshader_C4kxepX7.mjs +1 -0
- package/website/dist/_worker.js/chunks/genie_ACtQLcDW.mjs +1 -0
- package/website/dist/_worker.js/chunks/gherkin_BFp2uKUd.mjs +1 -0
- package/website/dist/_worker.js/chunks/git-commit_CLg9ZwMV.mjs +1 -0
- package/website/dist/_worker.js/chunks/git-rebase_DG8A80Nt.mjs +1 -0
- package/website/dist/_worker.js/chunks/github-dark-default_BI0EP2Kv.mjs +1 -0
- package/website/dist/_worker.js/chunks/github-dark-dimmed_a_NIC0Xb.mjs +1 -0
- package/website/dist/_worker.js/chunks/github-dark-high-contrast_jZGqT7hk.mjs +1 -0
- package/website/dist/_worker.js/chunks/github-dark_CHCDNd2O.mjs +1 -0
- package/website/dist/_worker.js/chunks/github-light-default_DRbOW5RG.mjs +1 -0
- package/website/dist/_worker.js/chunks/github-light-high-contrast_tn_kWutM.mjs +1 -0
- package/website/dist/_worker.js/chunks/github-light_D9brYzot.mjs +1 -0
- package/website/dist/_worker.js/chunks/gleam_Dmhu1oxW.mjs +1 -0
- package/website/dist/_worker.js/chunks/glimmer-js_BfZbXy8A.mjs +1 -0
- package/website/dist/_worker.js/chunks/glimmer-ts_B9QVICrD.mjs +1 -0
- package/website/dist/_worker.js/chunks/glsl_DD2PPwOs.mjs +1 -0
- package/website/dist/_worker.js/chunks/gnuplot_D2OYChUX.mjs +1 -0
- package/website/dist/_worker.js/chunks/go_DYGFTe3h.mjs +1 -0
- package/website/dist/_worker.js/chunks/graphql_B7XsT3nH.mjs +1 -0
- package/website/dist/_worker.js/chunks/groovy_BO12Uwkl.mjs +1 -0
- package/website/dist/_worker.js/chunks/hack_CB2_ztCP.mjs +1 -0
- package/website/dist/_worker.js/chunks/haml_CyfDcDD3.mjs +1 -0
- package/website/dist/_worker.js/chunks/handlebars_CfpxpWm2.mjs +1 -0
- package/website/dist/_worker.js/chunks/haskell_jUeC5uN5.mjs +1 -0
- package/website/dist/_worker.js/chunks/haxe_B6GxP1WB.mjs +1 -0
- package/website/dist/_worker.js/chunks/hcl_DwoHV2oh.mjs +1 -0
- package/website/dist/_worker.js/chunks/hjson_DV7cJRk4.mjs +1 -0
- package/website/dist/_worker.js/chunks/hlsl_BlFCscPI.mjs +1 -0
- package/website/dist/_worker.js/chunks/houston_COBFG1Mx.mjs +1 -0
- package/website/dist/_worker.js/chunks/html-derivative_C9pJ337h.mjs +1 -0
- package/website/dist/_worker.js/chunks/html_D1OkrZS5.mjs +1 -0
- package/website/dist/_worker.js/chunks/http_DIGXRqvJ.mjs +1 -0
- package/website/dist/_worker.js/chunks/hxml_DEwh9i-c.mjs +1 -0
- package/website/dist/_worker.js/chunks/hy_DDoIgW1K.mjs +1 -0
- package/website/dist/_worker.js/chunks/imba_B00zbHo4.mjs +1 -0
- package/website/dist/_worker.js/chunks/index_C1UTDwYg.mjs +1861 -0
- package/website/dist/_worker.js/chunks/ini_D7XQA_p8.mjs +1 -0
- package/website/dist/_worker.js/chunks/java_B9wdFd8K.mjs +1 -0
- package/website/dist/_worker.js/chunks/javascript_CLsPGOON.mjs +1 -0
- package/website/dist/_worker.js/chunks/jinja_jarBCAN1.mjs +1 -0
- package/website/dist/_worker.js/chunks/jison_oGg3J708.mjs +1 -0
- package/website/dist/_worker.js/chunks/json5_DlZ1Kyaa.mjs +1 -0
- package/website/dist/_worker.js/chunks/json_DaYk_FMp.mjs +1 -0
- package/website/dist/_worker.js/chunks/jsonc_DlwgfSDs.mjs +1 -0
- package/website/dist/_worker.js/chunks/jsonl_BbCCVaZF.mjs +1 -0
- package/website/dist/_worker.js/chunks/jsonnet_Dt-G75xe.mjs +1 -0
- package/website/dist/_worker.js/chunks/jssm_BtKFTj2A.mjs +1 -0
- package/website/dist/_worker.js/chunks/jsx_DDx_xAZ8.mjs +1 -0
- package/website/dist/_worker.js/chunks/julia_CK0lv68l.mjs +1 -0
- package/website/dist/_worker.js/chunks/kanagawa-dragon_BldAK3Oo.mjs +1 -0
- package/website/dist/_worker.js/chunks/kanagawa-lotus_DVM8FX9_.mjs +1 -0
- package/website/dist/_worker.js/chunks/kanagawa-wave_Dpih0AKP.mjs +1 -0
- package/website/dist/_worker.js/chunks/kotlin_kWneB9V_.mjs +1 -0
- package/website/dist/_worker.js/chunks/kusto_BKVATd95.mjs +1 -0
- package/website/dist/_worker.js/chunks/laserwave_BqatxsVl.mjs +1 -0
- package/website/dist/_worker.js/chunks/latex_LVDcGBbc.mjs +1 -0
- package/website/dist/_worker.js/chunks/lean_W7qo-5M2.mjs +1 -0
- package/website/dist/_worker.js/chunks/less_DFNwJnBH.mjs +1 -0
- package/website/dist/_worker.js/chunks/light-plus_Dp0AoWsO.mjs +1 -0
- package/website/dist/_worker.js/chunks/liquid_D24qs0pc.mjs +1 -0
- package/website/dist/_worker.js/chunks/log_IPWMXriF.mjs +1 -0
- package/website/dist/_worker.js/chunks/logo_C6KaatrQ.mjs +1 -0
- package/website/dist/_worker.js/chunks/lua_CwnEf-T7.mjs +1 -0
- package/website/dist/_worker.js/chunks/luau_Br3-CXjS.mjs +1 -0
- package/website/dist/_worker.js/chunks/make_UBNG-kOo.mjs +1 -0
- package/website/dist/_worker.js/chunks/markdown_C7mhJFCm.mjs +1 -0
- package/website/dist/_worker.js/chunks/marko_4tchUvI7.mjs +1 -0
- package/website/dist/_worker.js/chunks/material-theme-darker_SKtaNEPn.mjs +1 -0
- package/website/dist/_worker.js/chunks/material-theme-lighter_zOX_DZCH.mjs +1 -0
- package/website/dist/_worker.js/chunks/material-theme-ocean_BN9WbhdC.mjs +1 -0
- package/website/dist/_worker.js/chunks/material-theme-palenight_DT_covjH.mjs +1 -0
- package/website/dist/_worker.js/chunks/material-theme_6RpeM3kc.mjs +1 -0
- package/website/dist/_worker.js/chunks/matlab_DCOXsPKR.mjs +1 -0
- package/website/dist/_worker.js/chunks/mdc_B9gb2UFP.mjs +1 -0
- package/website/dist/_worker.js/chunks/mdx_DGU7Nu9u.mjs +1 -0
- package/website/dist/_worker.js/chunks/mermaid_B69URzsZ.mjs +1 -0
- package/website/dist/_worker.js/chunks/min-dark_BgxifOMI.mjs +1 -0
- package/website/dist/_worker.js/chunks/min-light_BrPjXxUp.mjs +1 -0
- package/website/dist/_worker.js/chunks/mipsasm_9U-4_t7k.mjs +1 -0
- package/website/dist/_worker.js/chunks/mojo_B0wt7ug3.mjs +1 -0
- package/website/dist/_worker.js/chunks/monokai_B6Pxpoyi.mjs +1 -0
- package/website/dist/_worker.js/chunks/move_1eid4CyR.mjs +1 -0
- package/website/dist/_worker.js/chunks/narrat_Ds6-p5JZ.mjs +1 -0
- package/website/dist/_worker.js/chunks/nextflow_v2N1Qlqa.mjs +1 -0
- package/website/dist/_worker.js/chunks/nginx_Bp9Ab2NH.mjs +1 -0
- package/website/dist/_worker.js/chunks/night-owl_CdwOw_sc.mjs +1 -0
- package/website/dist/_worker.js/chunks/nim_BXGDUe53.mjs +1 -0
- package/website/dist/_worker.js/chunks/nix_CUig1nJH.mjs +1 -0
- package/website/dist/_worker.js/chunks/noop-middleware_DlWGj5t5.mjs +10 -0
- package/website/dist/_worker.js/chunks/nord_SPoG1iae.mjs +1 -0
- package/website/dist/_worker.js/chunks/nushell_DJw1Lca8.mjs +1 -0
- package/website/dist/_worker.js/chunks/objective-c_Bktzl_CO.mjs +1 -0
- package/website/dist/_worker.js/chunks/objective-cpp_CP4DWdDp.mjs +1 -0
- package/website/dist/_worker.js/chunks/ocaml_CeEAs7bZ.mjs +1 -0
- package/website/dist/_worker.js/chunks/one-dark-pro_-hIwCNMi.mjs +1 -0
- package/website/dist/_worker.js/chunks/one-light_DSmYvJ05.mjs +1 -0
- package/website/dist/_worker.js/chunks/pascal_C-S_Ms_o.mjs +1 -0
- package/website/dist/_worker.js/chunks/perl_CKamvo15.mjs +1 -0
- package/website/dist/_worker.js/chunks/php_BlmcX_F3.mjs +1 -0
- package/website/dist/_worker.js/chunks/plastic_Ryt8tVoA.mjs +1 -0
- package/website/dist/_worker.js/chunks/plsql_Cb3v7cBj.mjs +1 -0
- package/website/dist/_worker.js/chunks/po_DZbdNRlo.mjs +1 -0
- package/website/dist/_worker.js/chunks/poimandres_bYmE3_5d.mjs +1 -0
- package/website/dist/_worker.js/chunks/polar_pJkMGwoW.mjs +1 -0
- package/website/dist/_worker.js/chunks/postcss_BAXSOKgk.mjs +1 -0
- package/website/dist/_worker.js/chunks/powerquery_oITMGN4x.mjs +1 -0
- package/website/dist/_worker.js/chunks/powershell_6306-xIF.mjs +1 -0
- package/website/dist/_worker.js/chunks/prisma_DSDxnZGz.mjs +1 -0
- package/website/dist/_worker.js/chunks/prolog_CxG7tjZR.mjs +1 -0
- package/website/dist/_worker.js/chunks/proto_CS9ByXm1.mjs +1 -0
- package/website/dist/_worker.js/chunks/pug_BMtLJo6U.mjs +1 -0
- package/website/dist/_worker.js/chunks/puppet_BfeeSzee.mjs +1 -0
- package/website/dist/_worker.js/chunks/purescript_BFfueNaH.mjs +1 -0
- package/website/dist/_worker.js/chunks/python_Cc4Faapv.mjs +1 -0
- package/website/dist/_worker.js/chunks/qml_C1CTJTK8.mjs +1 -0
- package/website/dist/_worker.js/chunks/qmldir_nG1KaqKR.mjs +1 -0
- package/website/dist/_worker.js/chunks/qss_Cncxk263.mjs +1 -0
- package/website/dist/_worker.js/chunks/r_ChR54Ihi.mjs +1 -0
- package/website/dist/_worker.js/chunks/racket_BDrhptDs.mjs +1 -0
- package/website/dist/_worker.js/chunks/raku_07OUHa0P.mjs +1 -0
- package/website/dist/_worker.js/chunks/razor_DIP3INLa.mjs +1 -0
- package/website/dist/_worker.js/chunks/red_DOPXfj-6.mjs +1 -0
- package/website/dist/_worker.js/chunks/reg_B64SwEDj.mjs +1 -0
- package/website/dist/_worker.js/chunks/regexp_ButFGoB5.mjs +1 -0
- package/website/dist/_worker.js/chunks/rel_BWJAWqZD.mjs +1 -0
- package/website/dist/_worker.js/chunks/riscv_79gXlbsF.mjs +1 -0
- package/website/dist/_worker.js/chunks/rose-pine-dawn_DHIjVGd3.mjs +1 -0
- package/website/dist/_worker.js/chunks/rose-pine-moon_t86aEbs0.mjs +1 -0
- package/website/dist/_worker.js/chunks/rose-pine_BHgrcDCs.mjs +1 -0
- package/website/dist/_worker.js/chunks/rst_D3F4Fcpj.mjs +1 -0
- package/website/dist/_worker.js/chunks/ruby_Cs7vM9iv.mjs +1 -0
- package/website/dist/_worker.js/chunks/rust_DpyRVatH.mjs +1 -0
- package/website/dist/_worker.js/chunks/sas_DW45xZXN.mjs +1 -0
- package/website/dist/_worker.js/chunks/sass_C6SiMwN_.mjs +1 -0
- package/website/dist/_worker.js/chunks/scala_DlZOjNZk.mjs +1 -0
- package/website/dist/_worker.js/chunks/scheme_D2ezSJXu.mjs +1 -0
- package/website/dist/_worker.js/chunks/scss_DG5Spjqu.mjs +1 -0
- package/website/dist/_worker.js/chunks/sdbl_ZCYaj4VN.mjs +1 -0
- package/website/dist/_worker.js/chunks/shaderlab_CAcRkg1_.mjs +1 -0
- package/website/dist/_worker.js/chunks/shellscript_BWwhkDVh.mjs +1 -0
- package/website/dist/_worker.js/chunks/shellsession_BfEA3juK.mjs +1 -0
- package/website/dist/_worker.js/chunks/slack-dark_CL3lSpCc.mjs +1 -0
- package/website/dist/_worker.js/chunks/slack-ochin_DdZKOQVh.mjs +1 -0
- package/website/dist/_worker.js/chunks/smalltalk_DgilzSui.mjs +1 -0
- package/website/dist/_worker.js/chunks/snazzy-light_eJU08Pz_.mjs +1 -0
- package/website/dist/_worker.js/chunks/solarized-dark_Dg_YQywx.mjs +1 -0
- package/website/dist/_worker.js/chunks/solarized-light_BnIsrA6p.mjs +1 -0
- package/website/dist/_worker.js/chunks/solidity_DkseH8pQ.mjs +1 -0
- package/website/dist/_worker.js/chunks/soy_DU7bOYoG.mjs +1 -0
- package/website/dist/_worker.js/chunks/sparql_BuI1DBDH.mjs +1 -0
- package/website/dist/_worker.js/chunks/splunk_B8Ha9Pkg.mjs +1 -0
- package/website/dist/_worker.js/chunks/sql_BniHwea5.mjs +1 -0
- package/website/dist/_worker.js/chunks/ssh-config_CkE1GuVe.mjs +1 -0
- package/website/dist/_worker.js/chunks/stata_Dtqpbd_l.mjs +1 -0
- package/website/dist/_worker.js/chunks/stylus_CXTtglzO.mjs +1 -0
- package/website/dist/_worker.js/chunks/svelte_BjWYcUCN.mjs +1 -0
- package/website/dist/_worker.js/chunks/swift_BzHql_rM.mjs +1 -0
- package/website/dist/_worker.js/chunks/synthwave-84_DLRNhxNA.mjs +1 -0
- package/website/dist/_worker.js/chunks/system-verilog_ChyInPph.mjs +1 -0
- package/website/dist/_worker.js/chunks/systemd_Bi9Qa2qD.mjs +1 -0
- package/website/dist/_worker.js/chunks/talonscript_B3sH_Y-V.mjs +1 -0
- package/website/dist/_worker.js/chunks/tasl_BJ5yipRs.mjs +1 -0
- package/website/dist/_worker.js/chunks/tcl_CoJQjNoP.mjs +1 -0
- package/website/dist/_worker.js/chunks/templ_CrU7Ffil.mjs +1 -0
- package/website/dist/_worker.js/chunks/terraform_DT9JSFpC.mjs +1 -0
- package/website/dist/_worker.js/chunks/tex_5PKu2yA0.mjs +1 -0
- package/website/dist/_worker.js/chunks/tokyo-night_Buo8OK7-.mjs +1 -0
- package/website/dist/_worker.js/chunks/toml_CPuXX3oc.mjs +1 -0
- package/website/dist/_worker.js/chunks/ts-tags_D0M_1VSH.mjs +1 -0
- package/website/dist/_worker.js/chunks/tsv_CuivVNot.mjs +1 -0
- package/website/dist/_worker.js/chunks/tsx_MkuGr8MY.mjs +1 -0
- package/website/dist/_worker.js/chunks/turtle_BqgEPK7f.mjs +1 -0
- package/website/dist/_worker.js/chunks/twig_r1G9rpYJ.mjs +1 -0
- package/website/dist/_worker.js/chunks/typescript_Au5buqzM.mjs +1 -0
- package/website/dist/_worker.js/chunks/typespec_47rhBK_z.mjs +1 -0
- package/website/dist/_worker.js/chunks/typst_BAtuQLh-.mjs +1 -0
- package/website/dist/_worker.js/chunks/v_BIvWImHg.mjs +1 -0
- package/website/dist/_worker.js/chunks/vala_DYEacj30.mjs +1 -0
- package/website/dist/_worker.js/chunks/vb_CikQuqGJ.mjs +1 -0
- package/website/dist/_worker.js/chunks/verilog_BQRENwI-.mjs +1 -0
- package/website/dist/_worker.js/chunks/vesper_DA0kvTmj.mjs +1 -0
- package/website/dist/_worker.js/chunks/vhdl_DHscJIyg.mjs +1 -0
- package/website/dist/_worker.js/chunks/viml_F2pvMwvG.mjs +1 -0
- package/website/dist/_worker.js/chunks/vitesse-black_D9tjNzd0.mjs +1 -0
- package/website/dist/_worker.js/chunks/vitesse-dark_Bnm5d0hd.mjs +1 -0
- package/website/dist/_worker.js/chunks/vitesse-light_CHwbyjNR.mjs +1 -0
- package/website/dist/_worker.js/chunks/vue-html_DyYtbbMK.mjs +1 -0
- package/website/dist/_worker.js/chunks/vue_DofN6juy.mjs +1 -0
- package/website/dist/_worker.js/chunks/vyper_CiR0m-OV.mjs +1 -0
- package/website/dist/_worker.js/chunks/wasm_CwIGgRGf.mjs +1 -0
- package/website/dist/_worker.js/chunks/wasm_jKWhg0J0.mjs +1 -0
- package/website/dist/_worker.js/chunks/wenyan_DKvVZKXW.mjs +1 -0
- package/website/dist/_worker.js/chunks/wgsl_BOWZY7yw.mjs +1 -0
- package/website/dist/_worker.js/chunks/wikitext_CXDhhHPy.mjs +1 -0
- package/website/dist/_worker.js/chunks/wolfram_ChkmGnW0.mjs +1 -0
- package/website/dist/_worker.js/chunks/xml_DXH3hHIu.mjs +1 -0
- package/website/dist/_worker.js/chunks/xsl_DuP2mFjg.mjs +1 -0
- package/website/dist/_worker.js/chunks/yaml_IGiEkTge.mjs +1 -0
- package/website/dist/_worker.js/chunks/zenscript_59iXGyNw.mjs +1 -0
- package/website/dist/_worker.js/chunks/zig_DKzb0zdT.mjs +1 -0
- package/website/dist/_worker.js/index.js +53 -0
- package/website/dist/_worker.js/manifest_BAAoOzaU.mjs +98 -0
- package/website/dist/_worker.js/pages/_image.astro.mjs +24 -0
- package/website/dist/_worker.js/pages/agents.astro.mjs +1 -0
- package/website/dist/_worker.js/pages/animation.astro.mjs +1 -0
- package/website/dist/_worker.js/pages/api/raw-markdown/_---path_.astro.mjs +44 -0
- package/website/dist/_worker.js/pages/config.astro.mjs +1 -0
- package/website/dist/_worker.js/pages/fonts.astro.mjs +1 -0
- package/website/dist/_worker.js/pages/getting-started.astro.mjs +1 -0
- package/website/dist/_worker.js/pages/helpers.astro.mjs +1 -0
- package/website/dist/_worker.js/pages/images.astro.mjs +1 -0
- package/website/dist/_worker.js/pages/index.astro.mjs +1 -0
- package/website/dist/_worker.js/pages/llm.txt.astro.mjs +1 -0
- package/website/dist/_worker.js/pages/preview.astro.mjs +1 -0
- package/website/dist/_worker.js/pages/sdk.astro.mjs +1 -0
- package/website/dist/_worker.js/pages/sitemap.xml.astro.mjs +1 -0
- package/website/dist/_worker.js/pages/styling.astro.mjs +1 -0
- package/website/dist/_worker.js/pages/templates.astro.mjs +1 -0
- package/website/dist/_worker.js/pages/video.astro.mjs +1 -0
- package/website/dist/_worker.js/renderers.mjs +57 -0
- package/website/dist/agents/index.html +3 -2
- package/website/dist/animation/index.html +402 -128
- package/website/dist/config/index.html +184 -0
- package/website/dist/fonts/index.html +56 -52
- package/website/dist/getting-started/index.html +107 -0
- package/website/dist/helpers/index.html +8 -8
- package/website/dist/images/index.html +50 -23
- package/website/dist/index.html +114 -148
- package/website/dist/llm.txt +751 -1055
- package/website/dist/preview/index.html +111 -0
- package/website/dist/robots.txt +35 -0
- package/website/dist/sdk/index.html +390 -52
- package/website/dist/sitemap.xml +76 -0
- package/website/dist/styling/index.html +10 -7
- package/website/dist/templates/index.html +11 -59
- package/website/dist/video/index.html +106 -537
- package/website/package-lock.json +1077 -17
- package/website/templates/og-image.tsx +61 -0
- package/website/dist/_astro/agents.I1-fN38o.css +0 -1
|
@@ -0,0 +1,1861 @@
|
|
|
1
|
+
globalThis.process ??= {}; globalThis.process.env ??= {};
|
|
2
|
+
import { g as appendForwardSlash, j as joinPaths, A as AstroError, i as i18nNoLocaleFoundInPath, R as ResponseSentError, h as MiddlewareNoDataOrNextCalled, k as MiddlewareNotAResponse, G as GetStaticPathsRequired, l as InvalidGetStaticPathsReturn, m as InvalidGetStaticPathsEntry, n as GetStaticPathsExpectedParams, o as GetStaticPathsInvalidRouteParam, t as trimSlashes, P as PageNumberParamNotFound, p as NoMatchingStaticPathFound, q as PrerenderDynamicEndpointPathCollide, r as ReservedSlotName, s as removeTrailingForwardSlash, u as RewriteWithBodyUsed, L as LocalsNotAnObject, v as PrerenderClientAddressNotAvailable, C as ClientAddressNotAvailable, S as StaticClientAddressNotAvailable, w as AstroResponseHeadersReassigned } from './astro/assets-service_j52rQLzU.mjs';
|
|
3
|
+
import { g as getActionQueryString, d as deserializeActionResult, D as DEFAULT_404_ROUTE } from './astro-designed-error-pages_BNTLO-TA.mjs';
|
|
4
|
+
import { R as REROUTE_DIRECTIVE_HEADER, D as DEFAULT_404_COMPONENT, a as renderSlotToString, r as renderJSX, b as chunkToString, i as isRenderInstruction, o as originPathnameSymbol, f as ROUTE_TYPE_HEADER, g as ASTRO_VERSION, h as clientLocalsSymbol, j as clientAddressSymbol, k as responseSentSymbol$1, l as renderPage, m as REWRITE_DIRECTIVE_HEADER_KEY, n as REWRITE_DIRECTIVE_HEADER_VALUE, p as renderEndpoint } from './astro/server_Y5_QHO8v.mjs';
|
|
5
|
+
|
|
6
|
+
const ACTION_API_CONTEXT_SYMBOL = Symbol.for("astro.actionAPIContext");
|
|
7
|
+
|
|
8
|
+
function hasActionPayload(locals) {
|
|
9
|
+
return "_actionPayload" in locals;
|
|
10
|
+
}
|
|
11
|
+
function createGetActionResult(locals) {
|
|
12
|
+
return (actionFn) => {
|
|
13
|
+
if (!hasActionPayload(locals) || actionFn.toString() !== getActionQueryString(locals._actionPayload.actionName)) {
|
|
14
|
+
return void 0;
|
|
15
|
+
}
|
|
16
|
+
return deserializeActionResult(locals._actionPayload.actionResult);
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function createCallAction(context) {
|
|
20
|
+
return (baseAction, input) => {
|
|
21
|
+
Reflect.set(context, ACTION_API_CONTEXT_SYMBOL, true);
|
|
22
|
+
const action = baseAction.bind(context);
|
|
23
|
+
return action(input);
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function shouldAppendForwardSlash(trailingSlash, buildFormat) {
|
|
28
|
+
switch (trailingSlash) {
|
|
29
|
+
case "always":
|
|
30
|
+
return true;
|
|
31
|
+
case "never":
|
|
32
|
+
return false;
|
|
33
|
+
case "ignore": {
|
|
34
|
+
switch (buildFormat) {
|
|
35
|
+
case "directory":
|
|
36
|
+
return true;
|
|
37
|
+
case "preserve":
|
|
38
|
+
case "file":
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function requestHasLocale(locales) {
|
|
46
|
+
return function(context) {
|
|
47
|
+
return pathHasLocale(context.url.pathname, locales);
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function requestIs404Or500(request, base = "") {
|
|
51
|
+
const url = new URL(request.url);
|
|
52
|
+
return url.pathname.startsWith(`${base}/404`) || url.pathname.startsWith(`${base}/500`);
|
|
53
|
+
}
|
|
54
|
+
function pathHasLocale(path, locales) {
|
|
55
|
+
const segments = path.split("/");
|
|
56
|
+
for (const segment of segments) {
|
|
57
|
+
for (const locale of locales) {
|
|
58
|
+
if (typeof locale === "string") {
|
|
59
|
+
if (normalizeTheLocale(segment) === normalizeTheLocale(locale)) {
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
} else if (segment === locale.path) {
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
function getPathByLocale(locale, locales) {
|
|
70
|
+
for (const loopLocale of locales) {
|
|
71
|
+
if (typeof loopLocale === "string") {
|
|
72
|
+
if (loopLocale === locale) {
|
|
73
|
+
return loopLocale;
|
|
74
|
+
}
|
|
75
|
+
} else {
|
|
76
|
+
for (const code of loopLocale.codes) {
|
|
77
|
+
if (code === locale) {
|
|
78
|
+
return loopLocale.path;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
throw new AstroError(i18nNoLocaleFoundInPath);
|
|
84
|
+
}
|
|
85
|
+
function normalizeTheLocale(locale) {
|
|
86
|
+
return locale.replaceAll("_", "-").toLowerCase();
|
|
87
|
+
}
|
|
88
|
+
function toCodes(locales) {
|
|
89
|
+
return locales.map((loopLocale) => {
|
|
90
|
+
if (typeof loopLocale === "string") {
|
|
91
|
+
return loopLocale;
|
|
92
|
+
} else {
|
|
93
|
+
return loopLocale.codes[0];
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
function redirectToDefaultLocale({
|
|
98
|
+
trailingSlash,
|
|
99
|
+
format,
|
|
100
|
+
base,
|
|
101
|
+
defaultLocale
|
|
102
|
+
}) {
|
|
103
|
+
return function(context, statusCode) {
|
|
104
|
+
if (shouldAppendForwardSlash(trailingSlash, format)) {
|
|
105
|
+
return context.redirect(`${appendForwardSlash(joinPaths(base, defaultLocale))}`, statusCode);
|
|
106
|
+
} else {
|
|
107
|
+
return context.redirect(`${joinPaths(base, defaultLocale)}`, statusCode);
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
function notFound({ base, locales }) {
|
|
112
|
+
return function(context, response) {
|
|
113
|
+
if (response?.headers.get(REROUTE_DIRECTIVE_HEADER) === "no") return response;
|
|
114
|
+
const url = context.url;
|
|
115
|
+
const isRoot = url.pathname === base + "/" || url.pathname === base;
|
|
116
|
+
if (!(isRoot || pathHasLocale(url.pathname, locales))) {
|
|
117
|
+
if (response) {
|
|
118
|
+
response.headers.set(REROUTE_DIRECTIVE_HEADER, "no");
|
|
119
|
+
return new Response(response.body, {
|
|
120
|
+
status: 404,
|
|
121
|
+
headers: response.headers
|
|
122
|
+
});
|
|
123
|
+
} else {
|
|
124
|
+
return new Response(null, {
|
|
125
|
+
status: 404,
|
|
126
|
+
headers: {
|
|
127
|
+
[REROUTE_DIRECTIVE_HEADER]: "no"
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return void 0;
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
function redirectToFallback({
|
|
136
|
+
fallback,
|
|
137
|
+
locales,
|
|
138
|
+
defaultLocale,
|
|
139
|
+
strategy,
|
|
140
|
+
base,
|
|
141
|
+
fallbackType
|
|
142
|
+
}) {
|
|
143
|
+
return async function(context, response) {
|
|
144
|
+
if (response.status >= 300 && fallback) {
|
|
145
|
+
const fallbackKeys = fallback ? Object.keys(fallback) : [];
|
|
146
|
+
const segments = context.url.pathname.split("/");
|
|
147
|
+
const urlLocale = segments.find((segment) => {
|
|
148
|
+
for (const locale of locales) {
|
|
149
|
+
if (typeof locale === "string") {
|
|
150
|
+
if (locale === segment) {
|
|
151
|
+
return true;
|
|
152
|
+
}
|
|
153
|
+
} else if (locale.path === segment) {
|
|
154
|
+
return true;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return false;
|
|
158
|
+
});
|
|
159
|
+
if (urlLocale && fallbackKeys.includes(urlLocale)) {
|
|
160
|
+
const fallbackLocale = fallback[urlLocale];
|
|
161
|
+
const pathFallbackLocale = getPathByLocale(fallbackLocale, locales);
|
|
162
|
+
let newPathname;
|
|
163
|
+
if (pathFallbackLocale === defaultLocale && strategy === "pathname-prefix-other-locales") {
|
|
164
|
+
if (context.url.pathname.includes(`${base}`)) {
|
|
165
|
+
newPathname = context.url.pathname.replace(`/${urlLocale}`, ``);
|
|
166
|
+
} else {
|
|
167
|
+
newPathname = context.url.pathname.replace(`/${urlLocale}`, `/`);
|
|
168
|
+
}
|
|
169
|
+
} else {
|
|
170
|
+
newPathname = context.url.pathname.replace(`/${urlLocale}`, `/${pathFallbackLocale}`);
|
|
171
|
+
}
|
|
172
|
+
if (fallbackType === "rewrite") {
|
|
173
|
+
return await context.rewrite(newPathname);
|
|
174
|
+
} else {
|
|
175
|
+
return context.redirect(newPathname);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return response;
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function parseLocale(header) {
|
|
184
|
+
if (header === "*") {
|
|
185
|
+
return [{ locale: header, qualityValue: void 0 }];
|
|
186
|
+
}
|
|
187
|
+
const result = [];
|
|
188
|
+
const localeValues = header.split(",").map((str) => str.trim());
|
|
189
|
+
for (const localeValue of localeValues) {
|
|
190
|
+
const split = localeValue.split(";").map((str) => str.trim());
|
|
191
|
+
const localeName = split[0];
|
|
192
|
+
const qualityValue = split[1];
|
|
193
|
+
if (!split) {
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
if (qualityValue && qualityValue.startsWith("q=")) {
|
|
197
|
+
const qualityValueAsFloat = Number.parseFloat(qualityValue.slice("q=".length));
|
|
198
|
+
if (Number.isNaN(qualityValueAsFloat) || qualityValueAsFloat > 1) {
|
|
199
|
+
result.push({
|
|
200
|
+
locale: localeName,
|
|
201
|
+
qualityValue: void 0
|
|
202
|
+
});
|
|
203
|
+
} else {
|
|
204
|
+
result.push({
|
|
205
|
+
locale: localeName,
|
|
206
|
+
qualityValue: qualityValueAsFloat
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
} else {
|
|
210
|
+
result.push({
|
|
211
|
+
locale: localeName,
|
|
212
|
+
qualityValue: void 0
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return result;
|
|
217
|
+
}
|
|
218
|
+
function sortAndFilterLocales(browserLocaleList, locales) {
|
|
219
|
+
const normalizedLocales = toCodes(locales).map(normalizeTheLocale);
|
|
220
|
+
return browserLocaleList.filter((browserLocale) => {
|
|
221
|
+
if (browserLocale.locale !== "*") {
|
|
222
|
+
return normalizedLocales.includes(normalizeTheLocale(browserLocale.locale));
|
|
223
|
+
}
|
|
224
|
+
return true;
|
|
225
|
+
}).sort((a, b) => {
|
|
226
|
+
if (a.qualityValue && b.qualityValue) {
|
|
227
|
+
return Math.sign(b.qualityValue - a.qualityValue);
|
|
228
|
+
}
|
|
229
|
+
return 0;
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
function computePreferredLocale(request, locales) {
|
|
233
|
+
const acceptHeader = request.headers.get("Accept-Language");
|
|
234
|
+
let result = void 0;
|
|
235
|
+
if (acceptHeader) {
|
|
236
|
+
const browserLocaleList = sortAndFilterLocales(parseLocale(acceptHeader), locales);
|
|
237
|
+
const firstResult = browserLocaleList.at(0);
|
|
238
|
+
if (firstResult && firstResult.locale !== "*") {
|
|
239
|
+
for (const currentLocale of locales) {
|
|
240
|
+
if (typeof currentLocale === "string") {
|
|
241
|
+
if (normalizeTheLocale(currentLocale) === normalizeTheLocale(firstResult.locale)) {
|
|
242
|
+
result = currentLocale;
|
|
243
|
+
}
|
|
244
|
+
} else {
|
|
245
|
+
for (const currentCode of currentLocale.codes) {
|
|
246
|
+
if (normalizeTheLocale(currentCode) === normalizeTheLocale(firstResult.locale)) {
|
|
247
|
+
result = currentLocale.path;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return result;
|
|
255
|
+
}
|
|
256
|
+
function computePreferredLocaleList(request, locales) {
|
|
257
|
+
const acceptHeader = request.headers.get("Accept-Language");
|
|
258
|
+
let result = [];
|
|
259
|
+
if (acceptHeader) {
|
|
260
|
+
const browserLocaleList = sortAndFilterLocales(parseLocale(acceptHeader), locales);
|
|
261
|
+
if (browserLocaleList.length === 1 && browserLocaleList.at(0).locale === "*") {
|
|
262
|
+
return locales.map((locale) => {
|
|
263
|
+
if (typeof locale === "string") {
|
|
264
|
+
return locale;
|
|
265
|
+
} else {
|
|
266
|
+
return locale.codes.at(0);
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
} else if (browserLocaleList.length > 0) {
|
|
270
|
+
for (const browserLocale of browserLocaleList) {
|
|
271
|
+
for (const loopLocale of locales) {
|
|
272
|
+
if (typeof loopLocale === "string") {
|
|
273
|
+
if (normalizeTheLocale(loopLocale) === normalizeTheLocale(browserLocale.locale)) {
|
|
274
|
+
result.push(loopLocale);
|
|
275
|
+
}
|
|
276
|
+
} else {
|
|
277
|
+
for (const code of loopLocale.codes) {
|
|
278
|
+
if (code === browserLocale.locale) {
|
|
279
|
+
result.push(loopLocale.path);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
return result;
|
|
288
|
+
}
|
|
289
|
+
function computeCurrentLocale(pathname, locales, defaultLocale) {
|
|
290
|
+
for (const segment of pathname.split("/")) {
|
|
291
|
+
for (const locale of locales) {
|
|
292
|
+
if (typeof locale === "string") {
|
|
293
|
+
if (!segment.includes(locale)) continue;
|
|
294
|
+
if (normalizeTheLocale(locale) === normalizeTheLocale(segment)) {
|
|
295
|
+
return locale;
|
|
296
|
+
}
|
|
297
|
+
} else {
|
|
298
|
+
if (locale.path === segment) {
|
|
299
|
+
return locale.codes.at(0);
|
|
300
|
+
} else {
|
|
301
|
+
for (const code of locale.codes) {
|
|
302
|
+
if (normalizeTheLocale(code) === normalizeTheLocale(segment)) {
|
|
303
|
+
return code;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
for (const locale of locales) {
|
|
311
|
+
if (typeof locale === "string") {
|
|
312
|
+
if (locale === defaultLocale) {
|
|
313
|
+
return locale;
|
|
314
|
+
}
|
|
315
|
+
} else {
|
|
316
|
+
if (locale.path === defaultLocale) {
|
|
317
|
+
return locale.codes.at(0);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/*!
|
|
324
|
+
* cookie
|
|
325
|
+
* Copyright(c) 2012-2014 Roman Shtylman
|
|
326
|
+
* Copyright(c) 2015 Douglas Christopher Wilson
|
|
327
|
+
* MIT Licensed
|
|
328
|
+
*/
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* Module exports.
|
|
332
|
+
* @public
|
|
333
|
+
*/
|
|
334
|
+
|
|
335
|
+
var parse_1 = parse;
|
|
336
|
+
var serialize_1 = serialize;
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* Module variables.
|
|
340
|
+
* @private
|
|
341
|
+
*/
|
|
342
|
+
|
|
343
|
+
var __toString = Object.prototype.toString;
|
|
344
|
+
var __hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* RegExp to match cookie-name in RFC 6265 sec 4.1.1
|
|
348
|
+
* This refers out to the obsoleted definition of token in RFC 2616 sec 2.2
|
|
349
|
+
* which has been replaced by the token definition in RFC 7230 appendix B.
|
|
350
|
+
*
|
|
351
|
+
* cookie-name = token
|
|
352
|
+
* token = 1*tchar
|
|
353
|
+
* tchar = "!" / "#" / "$" / "%" / "&" / "'" /
|
|
354
|
+
* "*" / "+" / "-" / "." / "^" / "_" /
|
|
355
|
+
* "`" / "|" / "~" / DIGIT / ALPHA
|
|
356
|
+
*/
|
|
357
|
+
|
|
358
|
+
var cookieNameRegExp = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* RegExp to match cookie-value in RFC 6265 sec 4.1.1
|
|
362
|
+
*
|
|
363
|
+
* cookie-value = *cookie-octet / ( DQUOTE *cookie-octet DQUOTE )
|
|
364
|
+
* cookie-octet = %x21 / %x23-2B / %x2D-3A / %x3C-5B / %x5D-7E
|
|
365
|
+
* ; US-ASCII characters excluding CTLs,
|
|
366
|
+
* ; whitespace DQUOTE, comma, semicolon,
|
|
367
|
+
* ; and backslash
|
|
368
|
+
*/
|
|
369
|
+
|
|
370
|
+
var cookieValueRegExp = /^("?)[\u0021\u0023-\u002B\u002D-\u003A\u003C-\u005B\u005D-\u007E]*\1$/;
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* RegExp to match domain-value in RFC 6265 sec 4.1.1
|
|
374
|
+
*
|
|
375
|
+
* domain-value = <subdomain>
|
|
376
|
+
* ; defined in [RFC1034], Section 3.5, as
|
|
377
|
+
* ; enhanced by [RFC1123], Section 2.1
|
|
378
|
+
* <subdomain> = <label> | <subdomain> "." <label>
|
|
379
|
+
* <label> = <let-dig> [ [ <ldh-str> ] <let-dig> ]
|
|
380
|
+
* Labels must be 63 characters or less.
|
|
381
|
+
* 'let-dig' not 'letter' in the first char, per RFC1123
|
|
382
|
+
* <ldh-str> = <let-dig-hyp> | <let-dig-hyp> <ldh-str>
|
|
383
|
+
* <let-dig-hyp> = <let-dig> | "-"
|
|
384
|
+
* <let-dig> = <letter> | <digit>
|
|
385
|
+
* <letter> = any one of the 52 alphabetic characters A through Z in
|
|
386
|
+
* upper case and a through z in lower case
|
|
387
|
+
* <digit> = any one of the ten digits 0 through 9
|
|
388
|
+
*
|
|
389
|
+
* Keep support for leading dot: https://github.com/jshttp/cookie/issues/173
|
|
390
|
+
*
|
|
391
|
+
* > (Note that a leading %x2E ("."), if present, is ignored even though that
|
|
392
|
+
* character is not permitted, but a trailing %x2E ("."), if present, will
|
|
393
|
+
* cause the user agent to ignore the attribute.)
|
|
394
|
+
*/
|
|
395
|
+
|
|
396
|
+
var domainValueRegExp = /^([.]?[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)([.][a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)*$/i;
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* RegExp to match path-value in RFC 6265 sec 4.1.1
|
|
400
|
+
*
|
|
401
|
+
* path-value = <any CHAR except CTLs or ";">
|
|
402
|
+
* CHAR = %x01-7F
|
|
403
|
+
* ; defined in RFC 5234 appendix B.1
|
|
404
|
+
*/
|
|
405
|
+
|
|
406
|
+
var pathValueRegExp = /^[\u0020-\u003A\u003D-\u007E]*$/;
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* Parse a cookie header.
|
|
410
|
+
*
|
|
411
|
+
* Parse the given cookie header string into an object
|
|
412
|
+
* The object has the various cookies as keys(names) => values
|
|
413
|
+
*
|
|
414
|
+
* @param {string} str
|
|
415
|
+
* @param {object} [opt]
|
|
416
|
+
* @return {object}
|
|
417
|
+
* @public
|
|
418
|
+
*/
|
|
419
|
+
|
|
420
|
+
function parse(str, opt) {
|
|
421
|
+
if (typeof str !== 'string') {
|
|
422
|
+
throw new TypeError('argument str must be a string');
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
var obj = {};
|
|
426
|
+
var len = str.length;
|
|
427
|
+
// RFC 6265 sec 4.1.1, RFC 2616 2.2 defines a cookie name consists of one char minimum, plus '='.
|
|
428
|
+
if (len < 2) return obj;
|
|
429
|
+
|
|
430
|
+
var dec = (opt && opt.decode) || decode;
|
|
431
|
+
var index = 0;
|
|
432
|
+
var eqIdx = 0;
|
|
433
|
+
var endIdx = 0;
|
|
434
|
+
|
|
435
|
+
do {
|
|
436
|
+
eqIdx = str.indexOf('=', index);
|
|
437
|
+
if (eqIdx === -1) break; // No more cookie pairs.
|
|
438
|
+
|
|
439
|
+
endIdx = str.indexOf(';', index);
|
|
440
|
+
|
|
441
|
+
if (endIdx === -1) {
|
|
442
|
+
endIdx = len;
|
|
443
|
+
} else if (eqIdx > endIdx) {
|
|
444
|
+
// backtrack on prior semicolon
|
|
445
|
+
index = str.lastIndexOf(';', eqIdx - 1) + 1;
|
|
446
|
+
continue;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
var keyStartIdx = startIndex(str, index, eqIdx);
|
|
450
|
+
var keyEndIdx = endIndex(str, eqIdx, keyStartIdx);
|
|
451
|
+
var key = str.slice(keyStartIdx, keyEndIdx);
|
|
452
|
+
|
|
453
|
+
// only assign once
|
|
454
|
+
if (!__hasOwnProperty.call(obj, key)) {
|
|
455
|
+
var valStartIdx = startIndex(str, eqIdx + 1, endIdx);
|
|
456
|
+
var valEndIdx = endIndex(str, endIdx, valStartIdx);
|
|
457
|
+
|
|
458
|
+
if (str.charCodeAt(valStartIdx) === 0x22 /* " */ && str.charCodeAt(valEndIdx - 1) === 0x22 /* " */) {
|
|
459
|
+
valStartIdx++;
|
|
460
|
+
valEndIdx--;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
var val = str.slice(valStartIdx, valEndIdx);
|
|
464
|
+
obj[key] = tryDecode(val, dec);
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
index = endIdx + 1;
|
|
468
|
+
} while (index < len);
|
|
469
|
+
|
|
470
|
+
return obj;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
function startIndex(str, index, max) {
|
|
474
|
+
do {
|
|
475
|
+
var code = str.charCodeAt(index);
|
|
476
|
+
if (code !== 0x20 /* */ && code !== 0x09 /* \t */) return index;
|
|
477
|
+
} while (++index < max);
|
|
478
|
+
return max;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
function endIndex(str, index, min) {
|
|
482
|
+
while (index > min) {
|
|
483
|
+
var code = str.charCodeAt(--index);
|
|
484
|
+
if (code !== 0x20 /* */ && code !== 0x09 /* \t */) return index + 1;
|
|
485
|
+
}
|
|
486
|
+
return min;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
/**
|
|
490
|
+
* Serialize data into a cookie header.
|
|
491
|
+
*
|
|
492
|
+
* Serialize a name value pair into a cookie string suitable for
|
|
493
|
+
* http headers. An optional options object specifies cookie parameters.
|
|
494
|
+
*
|
|
495
|
+
* serialize('foo', 'bar', { httpOnly: true })
|
|
496
|
+
* => "foo=bar; httpOnly"
|
|
497
|
+
*
|
|
498
|
+
* @param {string} name
|
|
499
|
+
* @param {string} val
|
|
500
|
+
* @param {object} [opt]
|
|
501
|
+
* @return {string}
|
|
502
|
+
* @public
|
|
503
|
+
*/
|
|
504
|
+
|
|
505
|
+
function serialize(name, val, opt) {
|
|
506
|
+
var enc = (opt && opt.encode) || encodeURIComponent;
|
|
507
|
+
|
|
508
|
+
if (typeof enc !== 'function') {
|
|
509
|
+
throw new TypeError('option encode is invalid');
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
if (!cookieNameRegExp.test(name)) {
|
|
513
|
+
throw new TypeError('argument name is invalid');
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
var value = enc(val);
|
|
517
|
+
|
|
518
|
+
if (!cookieValueRegExp.test(value)) {
|
|
519
|
+
throw new TypeError('argument val is invalid');
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
var str = name + '=' + value;
|
|
523
|
+
if (!opt) return str;
|
|
524
|
+
|
|
525
|
+
if (null != opt.maxAge) {
|
|
526
|
+
var maxAge = Math.floor(opt.maxAge);
|
|
527
|
+
|
|
528
|
+
if (!isFinite(maxAge)) {
|
|
529
|
+
throw new TypeError('option maxAge is invalid')
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
str += '; Max-Age=' + maxAge;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
if (opt.domain) {
|
|
536
|
+
if (!domainValueRegExp.test(opt.domain)) {
|
|
537
|
+
throw new TypeError('option domain is invalid');
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
str += '; Domain=' + opt.domain;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
if (opt.path) {
|
|
544
|
+
if (!pathValueRegExp.test(opt.path)) {
|
|
545
|
+
throw new TypeError('option path is invalid');
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
str += '; Path=' + opt.path;
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
if (opt.expires) {
|
|
552
|
+
var expires = opt.expires;
|
|
553
|
+
|
|
554
|
+
if (!isDate(expires) || isNaN(expires.valueOf())) {
|
|
555
|
+
throw new TypeError('option expires is invalid');
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
str += '; Expires=' + expires.toUTCString();
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
if (opt.httpOnly) {
|
|
562
|
+
str += '; HttpOnly';
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
if (opt.secure) {
|
|
566
|
+
str += '; Secure';
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
if (opt.partitioned) {
|
|
570
|
+
str += '; Partitioned';
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
if (opt.priority) {
|
|
574
|
+
var priority = typeof opt.priority === 'string'
|
|
575
|
+
? opt.priority.toLowerCase() : opt.priority;
|
|
576
|
+
|
|
577
|
+
switch (priority) {
|
|
578
|
+
case 'low':
|
|
579
|
+
str += '; Priority=Low';
|
|
580
|
+
break
|
|
581
|
+
case 'medium':
|
|
582
|
+
str += '; Priority=Medium';
|
|
583
|
+
break
|
|
584
|
+
case 'high':
|
|
585
|
+
str += '; Priority=High';
|
|
586
|
+
break
|
|
587
|
+
default:
|
|
588
|
+
throw new TypeError('option priority is invalid')
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
if (opt.sameSite) {
|
|
593
|
+
var sameSite = typeof opt.sameSite === 'string'
|
|
594
|
+
? opt.sameSite.toLowerCase() : opt.sameSite;
|
|
595
|
+
|
|
596
|
+
switch (sameSite) {
|
|
597
|
+
case true:
|
|
598
|
+
str += '; SameSite=Strict';
|
|
599
|
+
break;
|
|
600
|
+
case 'lax':
|
|
601
|
+
str += '; SameSite=Lax';
|
|
602
|
+
break;
|
|
603
|
+
case 'strict':
|
|
604
|
+
str += '; SameSite=Strict';
|
|
605
|
+
break;
|
|
606
|
+
case 'none':
|
|
607
|
+
str += '; SameSite=None';
|
|
608
|
+
break;
|
|
609
|
+
default:
|
|
610
|
+
throw new TypeError('option sameSite is invalid');
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
return str;
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
/**
|
|
618
|
+
* URL-decode string value. Optimized to skip native call when no %.
|
|
619
|
+
*
|
|
620
|
+
* @param {string} str
|
|
621
|
+
* @returns {string}
|
|
622
|
+
*/
|
|
623
|
+
|
|
624
|
+
function decode (str) {
|
|
625
|
+
return str.indexOf('%') !== -1
|
|
626
|
+
? decodeURIComponent(str)
|
|
627
|
+
: str
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
/**
|
|
631
|
+
* Determine if value is a Date.
|
|
632
|
+
*
|
|
633
|
+
* @param {*} val
|
|
634
|
+
* @private
|
|
635
|
+
*/
|
|
636
|
+
|
|
637
|
+
function isDate (val) {
|
|
638
|
+
return __toString.call(val) === '[object Date]';
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
/**
|
|
642
|
+
* Try decoding a string using a decoding function.
|
|
643
|
+
*
|
|
644
|
+
* @param {string} str
|
|
645
|
+
* @param {function} decode
|
|
646
|
+
* @private
|
|
647
|
+
*/
|
|
648
|
+
|
|
649
|
+
function tryDecode(str, decode) {
|
|
650
|
+
try {
|
|
651
|
+
return decode(str);
|
|
652
|
+
} catch (e) {
|
|
653
|
+
return str;
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
const DELETED_EXPIRATION = /* @__PURE__ */ new Date(0);
|
|
658
|
+
const DELETED_VALUE = "deleted";
|
|
659
|
+
const responseSentSymbol = Symbol.for("astro.responseSent");
|
|
660
|
+
class AstroCookie {
|
|
661
|
+
constructor(value) {
|
|
662
|
+
this.value = value;
|
|
663
|
+
}
|
|
664
|
+
json() {
|
|
665
|
+
if (this.value === void 0) {
|
|
666
|
+
throw new Error(`Cannot convert undefined to an object.`);
|
|
667
|
+
}
|
|
668
|
+
return JSON.parse(this.value);
|
|
669
|
+
}
|
|
670
|
+
number() {
|
|
671
|
+
return Number(this.value);
|
|
672
|
+
}
|
|
673
|
+
boolean() {
|
|
674
|
+
if (this.value === "false") return false;
|
|
675
|
+
if (this.value === "0") return false;
|
|
676
|
+
return Boolean(this.value);
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
class AstroCookies {
|
|
680
|
+
#request;
|
|
681
|
+
#requestValues;
|
|
682
|
+
#outgoing;
|
|
683
|
+
#consumed;
|
|
684
|
+
constructor(request) {
|
|
685
|
+
this.#request = request;
|
|
686
|
+
this.#requestValues = null;
|
|
687
|
+
this.#outgoing = null;
|
|
688
|
+
this.#consumed = false;
|
|
689
|
+
}
|
|
690
|
+
/**
|
|
691
|
+
* Astro.cookies.delete(key) is used to delete a cookie. Using this method will result
|
|
692
|
+
* in a Set-Cookie header added to the response.
|
|
693
|
+
* @param key The cookie to delete
|
|
694
|
+
* @param options Options related to this deletion, such as the path of the cookie.
|
|
695
|
+
*/
|
|
696
|
+
delete(key, options) {
|
|
697
|
+
const {
|
|
698
|
+
// @ts-expect-error
|
|
699
|
+
maxAge: _ignoredMaxAge,
|
|
700
|
+
// @ts-expect-error
|
|
701
|
+
expires: _ignoredExpires,
|
|
702
|
+
...sanitizedOptions
|
|
703
|
+
} = options || {};
|
|
704
|
+
const serializeOptions = {
|
|
705
|
+
expires: DELETED_EXPIRATION,
|
|
706
|
+
...sanitizedOptions
|
|
707
|
+
};
|
|
708
|
+
this.#ensureOutgoingMap().set(key, [
|
|
709
|
+
DELETED_VALUE,
|
|
710
|
+
serialize_1(key, DELETED_VALUE, serializeOptions),
|
|
711
|
+
false
|
|
712
|
+
]);
|
|
713
|
+
}
|
|
714
|
+
/**
|
|
715
|
+
* Astro.cookies.get(key) is used to get a cookie value. The cookie value is read from the
|
|
716
|
+
* request. If you have set a cookie via Astro.cookies.set(key, value), the value will be taken
|
|
717
|
+
* from that set call, overriding any values already part of the request.
|
|
718
|
+
* @param key The cookie to get.
|
|
719
|
+
* @returns An object containing the cookie value as well as convenience methods for converting its value.
|
|
720
|
+
*/
|
|
721
|
+
get(key, options = void 0) {
|
|
722
|
+
if (this.#outgoing?.has(key)) {
|
|
723
|
+
let [serializedValue, , isSetValue] = this.#outgoing.get(key);
|
|
724
|
+
if (isSetValue) {
|
|
725
|
+
return new AstroCookie(serializedValue);
|
|
726
|
+
} else {
|
|
727
|
+
return void 0;
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
const values = this.#ensureParsed(options);
|
|
731
|
+
if (key in values) {
|
|
732
|
+
const value = values[key];
|
|
733
|
+
return new AstroCookie(value);
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
/**
|
|
737
|
+
* Astro.cookies.has(key) returns a boolean indicating whether this cookie is either
|
|
738
|
+
* part of the initial request or set via Astro.cookies.set(key)
|
|
739
|
+
* @param key The cookie to check for.
|
|
740
|
+
* @returns
|
|
741
|
+
*/
|
|
742
|
+
has(key, options = void 0) {
|
|
743
|
+
if (this.#outgoing?.has(key)) {
|
|
744
|
+
let [, , isSetValue] = this.#outgoing.get(key);
|
|
745
|
+
return isSetValue;
|
|
746
|
+
}
|
|
747
|
+
const values = this.#ensureParsed(options);
|
|
748
|
+
return !!values[key];
|
|
749
|
+
}
|
|
750
|
+
/**
|
|
751
|
+
* Astro.cookies.set(key, value) is used to set a cookie's value. If provided
|
|
752
|
+
* an object it will be stringified via JSON.stringify(value). Additionally you
|
|
753
|
+
* can provide options customizing how this cookie will be set, such as setting httpOnly
|
|
754
|
+
* in order to prevent the cookie from being read in client-side JavaScript.
|
|
755
|
+
* @param key The name of the cookie to set.
|
|
756
|
+
* @param value A value, either a string or other primitive or an object.
|
|
757
|
+
* @param options Options for the cookie, such as the path and security settings.
|
|
758
|
+
*/
|
|
759
|
+
set(key, value, options) {
|
|
760
|
+
if (this.#consumed) {
|
|
761
|
+
const warning = new Error(
|
|
762
|
+
"Astro.cookies.set() was called after the cookies had already been sent to the browser.\nThis may have happened if this method was called in an imported component.\nPlease make sure that Astro.cookies.set() is only called in the frontmatter of the main page."
|
|
763
|
+
);
|
|
764
|
+
warning.name = "Warning";
|
|
765
|
+
console.warn(warning);
|
|
766
|
+
}
|
|
767
|
+
let serializedValue;
|
|
768
|
+
if (typeof value === "string") {
|
|
769
|
+
serializedValue = value;
|
|
770
|
+
} else {
|
|
771
|
+
let toStringValue = value.toString();
|
|
772
|
+
if (toStringValue === Object.prototype.toString.call(value)) {
|
|
773
|
+
serializedValue = JSON.stringify(value);
|
|
774
|
+
} else {
|
|
775
|
+
serializedValue = toStringValue;
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
const serializeOptions = {};
|
|
779
|
+
if (options) {
|
|
780
|
+
Object.assign(serializeOptions, options);
|
|
781
|
+
}
|
|
782
|
+
this.#ensureOutgoingMap().set(key, [
|
|
783
|
+
serializedValue,
|
|
784
|
+
serialize_1(key, serializedValue, serializeOptions),
|
|
785
|
+
true
|
|
786
|
+
]);
|
|
787
|
+
if (this.#request[responseSentSymbol]) {
|
|
788
|
+
throw new AstroError({
|
|
789
|
+
...ResponseSentError
|
|
790
|
+
});
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
/**
|
|
794
|
+
* Merges a new AstroCookies instance into the current instance. Any new cookies
|
|
795
|
+
* will be added to the current instance, overwriting any existing cookies with the same name.
|
|
796
|
+
*/
|
|
797
|
+
merge(cookies) {
|
|
798
|
+
const outgoing = cookies.#outgoing;
|
|
799
|
+
if (outgoing) {
|
|
800
|
+
for (const [key, value] of outgoing) {
|
|
801
|
+
this.#ensureOutgoingMap().set(key, value);
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
/**
|
|
806
|
+
* Astro.cookies.header() returns an iterator for the cookies that have previously
|
|
807
|
+
* been set by either Astro.cookies.set() or Astro.cookies.delete().
|
|
808
|
+
* This method is primarily used by adapters to set the header on outgoing responses.
|
|
809
|
+
* @returns
|
|
810
|
+
*/
|
|
811
|
+
*headers() {
|
|
812
|
+
if (this.#outgoing == null) return;
|
|
813
|
+
for (const [, value] of this.#outgoing) {
|
|
814
|
+
yield value[1];
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
/**
|
|
818
|
+
* Behaves the same as AstroCookies.prototype.headers(),
|
|
819
|
+
* but allows a warning when cookies are set after the instance is consumed.
|
|
820
|
+
*/
|
|
821
|
+
static consume(cookies) {
|
|
822
|
+
cookies.#consumed = true;
|
|
823
|
+
return cookies.headers();
|
|
824
|
+
}
|
|
825
|
+
#ensureParsed(options = void 0) {
|
|
826
|
+
if (!this.#requestValues) {
|
|
827
|
+
this.#parse(options);
|
|
828
|
+
}
|
|
829
|
+
if (!this.#requestValues) {
|
|
830
|
+
this.#requestValues = {};
|
|
831
|
+
}
|
|
832
|
+
return this.#requestValues;
|
|
833
|
+
}
|
|
834
|
+
#ensureOutgoingMap() {
|
|
835
|
+
if (!this.#outgoing) {
|
|
836
|
+
this.#outgoing = /* @__PURE__ */ new Map();
|
|
837
|
+
}
|
|
838
|
+
return this.#outgoing;
|
|
839
|
+
}
|
|
840
|
+
#parse(options = void 0) {
|
|
841
|
+
const raw = this.#request.headers.get("cookie");
|
|
842
|
+
if (!raw) {
|
|
843
|
+
return;
|
|
844
|
+
}
|
|
845
|
+
this.#requestValues = parse_1(raw, options);
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
const astroCookiesSymbol = Symbol.for("astro.cookies");
|
|
850
|
+
function attachCookiesToResponse(response, cookies) {
|
|
851
|
+
Reflect.set(response, astroCookiesSymbol, cookies);
|
|
852
|
+
}
|
|
853
|
+
function getCookiesFromResponse(response) {
|
|
854
|
+
let cookies = Reflect.get(response, astroCookiesSymbol);
|
|
855
|
+
if (cookies != null) {
|
|
856
|
+
return cookies;
|
|
857
|
+
} else {
|
|
858
|
+
return void 0;
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
function* getSetCookiesFromResponse(response) {
|
|
862
|
+
const cookies = getCookiesFromResponse(response);
|
|
863
|
+
if (!cookies) {
|
|
864
|
+
return [];
|
|
865
|
+
}
|
|
866
|
+
for (const headerValue of AstroCookies.consume(cookies)) {
|
|
867
|
+
yield headerValue;
|
|
868
|
+
}
|
|
869
|
+
return [];
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
async function callMiddleware(onRequest, apiContext, responseFunction) {
|
|
873
|
+
let nextCalled = false;
|
|
874
|
+
let responseFunctionPromise = void 0;
|
|
875
|
+
const next = async (payload) => {
|
|
876
|
+
nextCalled = true;
|
|
877
|
+
responseFunctionPromise = responseFunction(apiContext, payload);
|
|
878
|
+
return responseFunctionPromise;
|
|
879
|
+
};
|
|
880
|
+
let middlewarePromise = onRequest(apiContext, next);
|
|
881
|
+
return await Promise.resolve(middlewarePromise).then(async (value) => {
|
|
882
|
+
if (nextCalled) {
|
|
883
|
+
if (typeof value !== "undefined") {
|
|
884
|
+
if (value instanceof Response === false) {
|
|
885
|
+
throw new AstroError(MiddlewareNotAResponse);
|
|
886
|
+
}
|
|
887
|
+
return value;
|
|
888
|
+
} else {
|
|
889
|
+
if (responseFunctionPromise) {
|
|
890
|
+
return responseFunctionPromise;
|
|
891
|
+
} else {
|
|
892
|
+
throw new AstroError(MiddlewareNotAResponse);
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
} else if (typeof value === "undefined") {
|
|
896
|
+
throw new AstroError(MiddlewareNoDataOrNextCalled);
|
|
897
|
+
} else if (value instanceof Response === false) {
|
|
898
|
+
throw new AstroError(MiddlewareNotAResponse);
|
|
899
|
+
} else {
|
|
900
|
+
return value;
|
|
901
|
+
}
|
|
902
|
+
});
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
async function renderRedirect(renderContext) {
|
|
906
|
+
const {
|
|
907
|
+
request: { method },
|
|
908
|
+
routeData
|
|
909
|
+
} = renderContext;
|
|
910
|
+
const { redirect, redirectRoute } = routeData;
|
|
911
|
+
const status = redirectRoute && typeof redirect === "object" ? redirect.status : method === "GET" ? 301 : 308;
|
|
912
|
+
const headers = { location: encodeURI(redirectRouteGenerate(renderContext)) };
|
|
913
|
+
return new Response(null, { status, headers });
|
|
914
|
+
}
|
|
915
|
+
function redirectRouteGenerate(renderContext) {
|
|
916
|
+
const {
|
|
917
|
+
params,
|
|
918
|
+
routeData: { redirect, redirectRoute }
|
|
919
|
+
} = renderContext;
|
|
920
|
+
if (typeof redirectRoute !== "undefined") {
|
|
921
|
+
return redirectRoute?.generate(params) || redirectRoute?.pathname || "/";
|
|
922
|
+
} else if (typeof redirect === "string") {
|
|
923
|
+
let target = redirect;
|
|
924
|
+
for (const param of Object.keys(params)) {
|
|
925
|
+
const paramValue = params[param];
|
|
926
|
+
target = target.replace(`[${param}]`, paramValue).replace(`[...${param}]`, paramValue);
|
|
927
|
+
}
|
|
928
|
+
return target;
|
|
929
|
+
} else if (typeof redirect === "undefined") {
|
|
930
|
+
return "/";
|
|
931
|
+
}
|
|
932
|
+
return redirect.destination;
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
const VALID_PARAM_TYPES = ["string", "number", "undefined"];
|
|
936
|
+
function validateGetStaticPathsParameter([key, value], route) {
|
|
937
|
+
if (!VALID_PARAM_TYPES.includes(typeof value)) {
|
|
938
|
+
throw new AstroError({
|
|
939
|
+
...GetStaticPathsInvalidRouteParam,
|
|
940
|
+
message: GetStaticPathsInvalidRouteParam.message(key, value, typeof value),
|
|
941
|
+
location: {
|
|
942
|
+
file: route
|
|
943
|
+
}
|
|
944
|
+
});
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
function validateDynamicRouteModule(mod, {
|
|
948
|
+
ssr,
|
|
949
|
+
route
|
|
950
|
+
}) {
|
|
951
|
+
if ((!ssr || route.prerender) && !mod.getStaticPaths) {
|
|
952
|
+
throw new AstroError({
|
|
953
|
+
...GetStaticPathsRequired,
|
|
954
|
+
location: { file: route.component }
|
|
955
|
+
});
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
function validateGetStaticPathsResult(result, logger, route) {
|
|
959
|
+
if (!Array.isArray(result)) {
|
|
960
|
+
throw new AstroError({
|
|
961
|
+
...InvalidGetStaticPathsReturn,
|
|
962
|
+
message: InvalidGetStaticPathsReturn.message(typeof result),
|
|
963
|
+
location: {
|
|
964
|
+
file: route.component
|
|
965
|
+
}
|
|
966
|
+
});
|
|
967
|
+
}
|
|
968
|
+
result.forEach((pathObject) => {
|
|
969
|
+
if (typeof pathObject === "object" && Array.isArray(pathObject) || pathObject === null) {
|
|
970
|
+
throw new AstroError({
|
|
971
|
+
...InvalidGetStaticPathsEntry,
|
|
972
|
+
message: InvalidGetStaticPathsEntry.message(
|
|
973
|
+
Array.isArray(pathObject) ? "array" : typeof pathObject
|
|
974
|
+
)
|
|
975
|
+
});
|
|
976
|
+
}
|
|
977
|
+
if (pathObject.params === void 0 || pathObject.params === null || pathObject.params && Object.keys(pathObject.params).length === 0) {
|
|
978
|
+
throw new AstroError({
|
|
979
|
+
...GetStaticPathsExpectedParams,
|
|
980
|
+
location: {
|
|
981
|
+
file: route.component
|
|
982
|
+
}
|
|
983
|
+
});
|
|
984
|
+
}
|
|
985
|
+
for (const [key, val] of Object.entries(pathObject.params)) {
|
|
986
|
+
if (!(typeof val === "undefined" || typeof val === "string" || typeof val === "number")) {
|
|
987
|
+
logger.warn(
|
|
988
|
+
"router",
|
|
989
|
+
`getStaticPaths() returned an invalid path param: "${key}". A string, number or undefined value was expected, but got \`${JSON.stringify(
|
|
990
|
+
val
|
|
991
|
+
)}\`.`
|
|
992
|
+
);
|
|
993
|
+
}
|
|
994
|
+
if (typeof val === "string" && val === "") {
|
|
995
|
+
logger.warn(
|
|
996
|
+
"router",
|
|
997
|
+
`getStaticPaths() returned an invalid path param: "${key}". \`undefined\` expected for an optional param, but got empty string.`
|
|
998
|
+
);
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
});
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
function stringifyParams(params, route) {
|
|
1005
|
+
const validatedParams = Object.entries(params).reduce((acc, next) => {
|
|
1006
|
+
validateGetStaticPathsParameter(next, route.component);
|
|
1007
|
+
const [key, value] = next;
|
|
1008
|
+
if (value !== void 0) {
|
|
1009
|
+
acc[key] = typeof value === "string" ? trimSlashes(value) : value.toString();
|
|
1010
|
+
}
|
|
1011
|
+
return acc;
|
|
1012
|
+
}, {});
|
|
1013
|
+
return route.generate(validatedParams);
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
function generatePaginateFunction(routeMatch) {
|
|
1017
|
+
return function paginateUtility(data, args = {}) {
|
|
1018
|
+
let { pageSize: _pageSize, params: _params, props: _props } = args;
|
|
1019
|
+
const pageSize = _pageSize || 10;
|
|
1020
|
+
const paramName = "page";
|
|
1021
|
+
const additionalParams = _params || {};
|
|
1022
|
+
const additionalProps = _props || {};
|
|
1023
|
+
let includesFirstPageNumber;
|
|
1024
|
+
if (routeMatch.params.includes(`...${paramName}`)) {
|
|
1025
|
+
includesFirstPageNumber = false;
|
|
1026
|
+
} else if (routeMatch.params.includes(`${paramName}`)) {
|
|
1027
|
+
includesFirstPageNumber = true;
|
|
1028
|
+
} else {
|
|
1029
|
+
throw new AstroError({
|
|
1030
|
+
...PageNumberParamNotFound,
|
|
1031
|
+
message: PageNumberParamNotFound.message(paramName)
|
|
1032
|
+
});
|
|
1033
|
+
}
|
|
1034
|
+
const lastPage = Math.max(1, Math.ceil(data.length / pageSize));
|
|
1035
|
+
const result = [...Array(lastPage).keys()].map((num) => {
|
|
1036
|
+
const pageNum = num + 1;
|
|
1037
|
+
const start = pageSize === Infinity ? 0 : (pageNum - 1) * pageSize;
|
|
1038
|
+
const end = Math.min(start + pageSize, data.length);
|
|
1039
|
+
const params = {
|
|
1040
|
+
...additionalParams,
|
|
1041
|
+
[paramName]: includesFirstPageNumber || pageNum > 1 ? String(pageNum) : void 0
|
|
1042
|
+
};
|
|
1043
|
+
const current = correctIndexRoute(routeMatch.generate({ ...params }));
|
|
1044
|
+
const next = pageNum === lastPage ? void 0 : correctIndexRoute(routeMatch.generate({ ...params, page: String(pageNum + 1) }));
|
|
1045
|
+
const prev = pageNum === 1 ? void 0 : correctIndexRoute(
|
|
1046
|
+
routeMatch.generate({
|
|
1047
|
+
...params,
|
|
1048
|
+
page: !includesFirstPageNumber && pageNum - 1 === 1 ? void 0 : String(pageNum - 1)
|
|
1049
|
+
})
|
|
1050
|
+
);
|
|
1051
|
+
const first = pageNum === 1 ? void 0 : correctIndexRoute(
|
|
1052
|
+
routeMatch.generate({
|
|
1053
|
+
...params,
|
|
1054
|
+
page: includesFirstPageNumber ? "1" : void 0
|
|
1055
|
+
})
|
|
1056
|
+
);
|
|
1057
|
+
const last = pageNum === lastPage ? void 0 : correctIndexRoute(routeMatch.generate({ ...params, page: String(lastPage) }));
|
|
1058
|
+
return {
|
|
1059
|
+
params,
|
|
1060
|
+
props: {
|
|
1061
|
+
...additionalProps,
|
|
1062
|
+
page: {
|
|
1063
|
+
data: data.slice(start, end),
|
|
1064
|
+
start,
|
|
1065
|
+
end: end - 1,
|
|
1066
|
+
size: pageSize,
|
|
1067
|
+
total: data.length,
|
|
1068
|
+
currentPage: pageNum,
|
|
1069
|
+
lastPage,
|
|
1070
|
+
url: { current, next, prev, first, last }
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
};
|
|
1074
|
+
});
|
|
1075
|
+
return result;
|
|
1076
|
+
};
|
|
1077
|
+
}
|
|
1078
|
+
function correctIndexRoute(route) {
|
|
1079
|
+
if (route === "") {
|
|
1080
|
+
return "/";
|
|
1081
|
+
}
|
|
1082
|
+
return route;
|
|
1083
|
+
}
|
|
1084
|
+
|
|
1085
|
+
async function callGetStaticPaths({
|
|
1086
|
+
mod,
|
|
1087
|
+
route,
|
|
1088
|
+
routeCache,
|
|
1089
|
+
logger,
|
|
1090
|
+
ssr
|
|
1091
|
+
}) {
|
|
1092
|
+
const cached = routeCache.get(route);
|
|
1093
|
+
if (!mod) {
|
|
1094
|
+
throw new Error("This is an error caused by Astro and not your code. Please file an issue.");
|
|
1095
|
+
}
|
|
1096
|
+
if (cached?.staticPaths) {
|
|
1097
|
+
return cached.staticPaths;
|
|
1098
|
+
}
|
|
1099
|
+
validateDynamicRouteModule(mod, { ssr, route });
|
|
1100
|
+
if (ssr && !route.prerender) {
|
|
1101
|
+
const entry = Object.assign([], { keyed: /* @__PURE__ */ new Map() });
|
|
1102
|
+
routeCache.set(route, { ...cached, staticPaths: entry });
|
|
1103
|
+
return entry;
|
|
1104
|
+
}
|
|
1105
|
+
let staticPaths = [];
|
|
1106
|
+
if (!mod.getStaticPaths) {
|
|
1107
|
+
throw new Error("Unexpected Error.");
|
|
1108
|
+
}
|
|
1109
|
+
staticPaths = await mod.getStaticPaths({
|
|
1110
|
+
// Q: Why the cast?
|
|
1111
|
+
// A: So users downstream can have nicer typings, we have to make some sacrifice in our internal typings, which necessitate a cast here
|
|
1112
|
+
paginate: generatePaginateFunction(route)
|
|
1113
|
+
});
|
|
1114
|
+
validateGetStaticPathsResult(staticPaths, logger, route);
|
|
1115
|
+
const keyedStaticPaths = staticPaths;
|
|
1116
|
+
keyedStaticPaths.keyed = /* @__PURE__ */ new Map();
|
|
1117
|
+
for (const sp of keyedStaticPaths) {
|
|
1118
|
+
const paramsKey = stringifyParams(sp.params, route);
|
|
1119
|
+
keyedStaticPaths.keyed.set(paramsKey, sp);
|
|
1120
|
+
}
|
|
1121
|
+
routeCache.set(route, { ...cached, staticPaths: keyedStaticPaths });
|
|
1122
|
+
return keyedStaticPaths;
|
|
1123
|
+
}
|
|
1124
|
+
class RouteCache {
|
|
1125
|
+
logger;
|
|
1126
|
+
cache = {};
|
|
1127
|
+
mode;
|
|
1128
|
+
constructor(logger, mode = "production") {
|
|
1129
|
+
this.logger = logger;
|
|
1130
|
+
this.mode = mode;
|
|
1131
|
+
}
|
|
1132
|
+
/** Clear the cache. */
|
|
1133
|
+
clearAll() {
|
|
1134
|
+
this.cache = {};
|
|
1135
|
+
}
|
|
1136
|
+
set(route, entry) {
|
|
1137
|
+
const key = this.key(route);
|
|
1138
|
+
if (this.mode === "production" && this.cache[key]?.staticPaths) {
|
|
1139
|
+
this.logger.warn(null, `Internal Warning: route cache overwritten. (${key})`);
|
|
1140
|
+
}
|
|
1141
|
+
this.cache[key] = entry;
|
|
1142
|
+
}
|
|
1143
|
+
get(route) {
|
|
1144
|
+
return this.cache[this.key(route)];
|
|
1145
|
+
}
|
|
1146
|
+
key(route) {
|
|
1147
|
+
return `${route.route}_${route.component}`;
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
function findPathItemByKey(staticPaths, params, route, logger) {
|
|
1151
|
+
const paramsKey = stringifyParams(params, route);
|
|
1152
|
+
const matchedStaticPath = staticPaths.keyed.get(paramsKey);
|
|
1153
|
+
if (matchedStaticPath) {
|
|
1154
|
+
return matchedStaticPath;
|
|
1155
|
+
}
|
|
1156
|
+
logger.debug("router", `findPathItemByKey() - Unexpected cache miss looking for ${paramsKey}`);
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1159
|
+
function routeIsRedirect(route) {
|
|
1160
|
+
return route?.type === "redirect";
|
|
1161
|
+
}
|
|
1162
|
+
function routeIsFallback(route) {
|
|
1163
|
+
return route?.type === "fallback";
|
|
1164
|
+
}
|
|
1165
|
+
|
|
1166
|
+
async function getProps(opts) {
|
|
1167
|
+
const { logger, mod, routeData: route, routeCache, pathname, serverLike } = opts;
|
|
1168
|
+
if (!route || route.pathname) {
|
|
1169
|
+
return {};
|
|
1170
|
+
}
|
|
1171
|
+
if (routeIsRedirect(route) || routeIsFallback(route) || route.component === DEFAULT_404_COMPONENT) {
|
|
1172
|
+
return {};
|
|
1173
|
+
}
|
|
1174
|
+
const staticPaths = await callGetStaticPaths({
|
|
1175
|
+
mod,
|
|
1176
|
+
route,
|
|
1177
|
+
routeCache,
|
|
1178
|
+
logger,
|
|
1179
|
+
ssr: serverLike
|
|
1180
|
+
});
|
|
1181
|
+
const params = getParams(route, pathname);
|
|
1182
|
+
const matchedStaticPath = findPathItemByKey(staticPaths, params, route, logger);
|
|
1183
|
+
if (!matchedStaticPath && (serverLike ? route.prerender : true)) {
|
|
1184
|
+
throw new AstroError({
|
|
1185
|
+
...NoMatchingStaticPathFound,
|
|
1186
|
+
message: NoMatchingStaticPathFound.message(pathname),
|
|
1187
|
+
hint: NoMatchingStaticPathFound.hint([route.component])
|
|
1188
|
+
});
|
|
1189
|
+
}
|
|
1190
|
+
if (mod) {
|
|
1191
|
+
validatePrerenderEndpointCollision(route, mod, params);
|
|
1192
|
+
}
|
|
1193
|
+
const props = matchedStaticPath?.props ? { ...matchedStaticPath.props } : {};
|
|
1194
|
+
return props;
|
|
1195
|
+
}
|
|
1196
|
+
function getParams(route, pathname) {
|
|
1197
|
+
if (!route.params.length) return {};
|
|
1198
|
+
const paramsMatch = route.pattern.exec(decodeURIComponent(pathname));
|
|
1199
|
+
if (!paramsMatch) return {};
|
|
1200
|
+
const params = {};
|
|
1201
|
+
route.params.forEach((key, i) => {
|
|
1202
|
+
if (key.startsWith("...")) {
|
|
1203
|
+
params[key.slice(3)] = paramsMatch[i + 1] ? paramsMatch[i + 1] : void 0;
|
|
1204
|
+
} else {
|
|
1205
|
+
params[key] = paramsMatch[i + 1];
|
|
1206
|
+
}
|
|
1207
|
+
});
|
|
1208
|
+
return params;
|
|
1209
|
+
}
|
|
1210
|
+
function validatePrerenderEndpointCollision(route, mod, params) {
|
|
1211
|
+
if (route.type === "endpoint" && mod.getStaticPaths) {
|
|
1212
|
+
const lastSegment = route.segments[route.segments.length - 1];
|
|
1213
|
+
const paramValues = Object.values(params);
|
|
1214
|
+
const lastParam = paramValues[paramValues.length - 1];
|
|
1215
|
+
if (lastSegment.length === 1 && lastSegment[0].dynamic && lastParam === void 0) {
|
|
1216
|
+
throw new AstroError({
|
|
1217
|
+
...PrerenderDynamicEndpointPathCollide,
|
|
1218
|
+
message: PrerenderDynamicEndpointPathCollide.message(route.route),
|
|
1219
|
+
hint: PrerenderDynamicEndpointPathCollide.hint(route.component),
|
|
1220
|
+
location: {
|
|
1221
|
+
file: route.component
|
|
1222
|
+
}
|
|
1223
|
+
});
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
|
|
1228
|
+
function getFunctionExpression(slot) {
|
|
1229
|
+
if (!slot) return;
|
|
1230
|
+
const expressions = slot?.expressions?.filter((e) => isRenderInstruction(e) === false);
|
|
1231
|
+
if (expressions?.length !== 1) return;
|
|
1232
|
+
return expressions[0];
|
|
1233
|
+
}
|
|
1234
|
+
class Slots {
|
|
1235
|
+
#result;
|
|
1236
|
+
#slots;
|
|
1237
|
+
#logger;
|
|
1238
|
+
constructor(result, slots, logger) {
|
|
1239
|
+
this.#result = result;
|
|
1240
|
+
this.#slots = slots;
|
|
1241
|
+
this.#logger = logger;
|
|
1242
|
+
if (slots) {
|
|
1243
|
+
for (const key of Object.keys(slots)) {
|
|
1244
|
+
if (this[key] !== void 0) {
|
|
1245
|
+
throw new AstroError({
|
|
1246
|
+
...ReservedSlotName,
|
|
1247
|
+
message: ReservedSlotName.message(key)
|
|
1248
|
+
});
|
|
1249
|
+
}
|
|
1250
|
+
Object.defineProperty(this, key, {
|
|
1251
|
+
get() {
|
|
1252
|
+
return true;
|
|
1253
|
+
},
|
|
1254
|
+
enumerable: true
|
|
1255
|
+
});
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
has(name) {
|
|
1260
|
+
if (!this.#slots) return false;
|
|
1261
|
+
return Boolean(this.#slots[name]);
|
|
1262
|
+
}
|
|
1263
|
+
async render(name, args = []) {
|
|
1264
|
+
if (!this.#slots || !this.has(name)) return;
|
|
1265
|
+
const result = this.#result;
|
|
1266
|
+
if (!Array.isArray(args)) {
|
|
1267
|
+
this.#logger.warn(
|
|
1268
|
+
null,
|
|
1269
|
+
`Expected second parameter to be an array, received a ${typeof args}. If you're trying to pass an array as a single argument and getting unexpected results, make sure you're passing your array as a item of an array. Ex: Astro.slots.render('default', [["Hello", "World"]])`
|
|
1270
|
+
);
|
|
1271
|
+
} else if (args.length > 0) {
|
|
1272
|
+
const slotValue = this.#slots[name];
|
|
1273
|
+
const component = typeof slotValue === "function" ? await slotValue(result) : await slotValue;
|
|
1274
|
+
const expression = getFunctionExpression(component);
|
|
1275
|
+
if (expression) {
|
|
1276
|
+
const slot = async () => typeof expression === "function" ? expression(...args) : expression;
|
|
1277
|
+
return await renderSlotToString(result, slot).then((res) => {
|
|
1278
|
+
return res;
|
|
1279
|
+
});
|
|
1280
|
+
}
|
|
1281
|
+
if (typeof component === "function") {
|
|
1282
|
+
return await renderJSX(result, component(...args)).then(
|
|
1283
|
+
(res) => res != null ? String(res) : res
|
|
1284
|
+
);
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
const content = await renderSlotToString(result, this.#slots[name]);
|
|
1288
|
+
const outHTML = chunkToString(result, content);
|
|
1289
|
+
return outHTML;
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
|
|
1293
|
+
function matchRoute(pathname, manifest) {
|
|
1294
|
+
const decodedPathname = decodeURI(pathname);
|
|
1295
|
+
return manifest.routes.find((route) => {
|
|
1296
|
+
return route.pattern.test(decodedPathname) || route.fallbackRoutes.some((fallbackRoute) => fallbackRoute.pattern.test(decodedPathname));
|
|
1297
|
+
});
|
|
1298
|
+
}
|
|
1299
|
+
function isRoute404or500(route) {
|
|
1300
|
+
return route.pattern.test("/404") || route.pattern.test("/500");
|
|
1301
|
+
}
|
|
1302
|
+
|
|
1303
|
+
function findRouteToRewrite({
|
|
1304
|
+
payload,
|
|
1305
|
+
routes,
|
|
1306
|
+
request,
|
|
1307
|
+
trailingSlash,
|
|
1308
|
+
buildFormat,
|
|
1309
|
+
base
|
|
1310
|
+
}) {
|
|
1311
|
+
let newUrl = void 0;
|
|
1312
|
+
if (payload instanceof URL) {
|
|
1313
|
+
newUrl = payload;
|
|
1314
|
+
} else if (payload instanceof Request) {
|
|
1315
|
+
newUrl = new URL(payload.url);
|
|
1316
|
+
} else {
|
|
1317
|
+
newUrl = new URL(payload, new URL(request.url).origin);
|
|
1318
|
+
}
|
|
1319
|
+
let pathname = newUrl.pathname;
|
|
1320
|
+
if (base !== "/" && newUrl.pathname.startsWith(base)) {
|
|
1321
|
+
pathname = shouldAppendForwardSlash(trailingSlash, buildFormat) ? appendForwardSlash(newUrl.pathname) : removeTrailingForwardSlash(newUrl.pathname);
|
|
1322
|
+
pathname = pathname.slice(base.length);
|
|
1323
|
+
}
|
|
1324
|
+
let foundRoute;
|
|
1325
|
+
for (const route of routes) {
|
|
1326
|
+
if (route.pattern.test(decodeURI(pathname))) {
|
|
1327
|
+
foundRoute = route;
|
|
1328
|
+
break;
|
|
1329
|
+
}
|
|
1330
|
+
}
|
|
1331
|
+
if (foundRoute) {
|
|
1332
|
+
return {
|
|
1333
|
+
routeData: foundRoute,
|
|
1334
|
+
newUrl,
|
|
1335
|
+
pathname
|
|
1336
|
+
};
|
|
1337
|
+
} else {
|
|
1338
|
+
const custom404 = routes.find((route) => route.route === "/404");
|
|
1339
|
+
if (custom404) {
|
|
1340
|
+
return { routeData: custom404, newUrl, pathname };
|
|
1341
|
+
} else {
|
|
1342
|
+
return { routeData: DEFAULT_404_ROUTE, newUrl, pathname };
|
|
1343
|
+
}
|
|
1344
|
+
}
|
|
1345
|
+
}
|
|
1346
|
+
function copyRequest(newUrl, oldRequest) {
|
|
1347
|
+
if (oldRequest.bodyUsed) {
|
|
1348
|
+
throw new AstroError(RewriteWithBodyUsed);
|
|
1349
|
+
}
|
|
1350
|
+
return new Request(newUrl, {
|
|
1351
|
+
method: oldRequest.method,
|
|
1352
|
+
headers: oldRequest.headers,
|
|
1353
|
+
body: oldRequest.body,
|
|
1354
|
+
referrer: oldRequest.referrer,
|
|
1355
|
+
referrerPolicy: oldRequest.referrerPolicy,
|
|
1356
|
+
mode: oldRequest.mode,
|
|
1357
|
+
credentials: oldRequest.credentials,
|
|
1358
|
+
cache: oldRequest.cache,
|
|
1359
|
+
redirect: oldRequest.redirect,
|
|
1360
|
+
integrity: oldRequest.integrity,
|
|
1361
|
+
signal: oldRequest.signal,
|
|
1362
|
+
keepalive: oldRequest.keepalive,
|
|
1363
|
+
// https://fetch.spec.whatwg.org/#dom-request-duplex
|
|
1364
|
+
// @ts-expect-error It isn't part of the types, but undici accepts it and it allows to carry over the body to a new request
|
|
1365
|
+
duplex: "half"
|
|
1366
|
+
});
|
|
1367
|
+
}
|
|
1368
|
+
function setOriginPathname(request, pathname) {
|
|
1369
|
+
Reflect.set(request, originPathnameSymbol, encodeURIComponent(pathname));
|
|
1370
|
+
}
|
|
1371
|
+
|
|
1372
|
+
const apiContextRoutesSymbol = Symbol.for("context.routes");
|
|
1373
|
+
class RenderContext {
|
|
1374
|
+
constructor(pipeline, locals, middleware, pathname, request, routeData, status, cookies = new AstroCookies(request), params = getParams(routeData, pathname), url = new URL(request.url), props = {}, partial = void 0) {
|
|
1375
|
+
this.pipeline = pipeline;
|
|
1376
|
+
this.locals = locals;
|
|
1377
|
+
this.middleware = middleware;
|
|
1378
|
+
this.pathname = pathname;
|
|
1379
|
+
this.request = request;
|
|
1380
|
+
this.routeData = routeData;
|
|
1381
|
+
this.status = status;
|
|
1382
|
+
this.cookies = cookies;
|
|
1383
|
+
this.params = params;
|
|
1384
|
+
this.url = url;
|
|
1385
|
+
this.props = props;
|
|
1386
|
+
this.partial = partial;
|
|
1387
|
+
}
|
|
1388
|
+
/**
|
|
1389
|
+
* A flag that tells the render content if the rewriting was triggered
|
|
1390
|
+
*/
|
|
1391
|
+
isRewriting = false;
|
|
1392
|
+
/**
|
|
1393
|
+
* A safety net in case of loops
|
|
1394
|
+
*/
|
|
1395
|
+
counter = 0;
|
|
1396
|
+
static async create({
|
|
1397
|
+
locals = {},
|
|
1398
|
+
middleware,
|
|
1399
|
+
pathname,
|
|
1400
|
+
pipeline,
|
|
1401
|
+
request,
|
|
1402
|
+
routeData,
|
|
1403
|
+
status = 200,
|
|
1404
|
+
props,
|
|
1405
|
+
partial = void 0
|
|
1406
|
+
}) {
|
|
1407
|
+
const pipelineMiddleware = await pipeline.getMiddleware();
|
|
1408
|
+
setOriginPathname(request, pathname);
|
|
1409
|
+
return new RenderContext(
|
|
1410
|
+
pipeline,
|
|
1411
|
+
locals,
|
|
1412
|
+
sequence(...pipeline.internalMiddleware, middleware ?? pipelineMiddleware),
|
|
1413
|
+
pathname,
|
|
1414
|
+
request,
|
|
1415
|
+
routeData,
|
|
1416
|
+
status,
|
|
1417
|
+
void 0,
|
|
1418
|
+
void 0,
|
|
1419
|
+
void 0,
|
|
1420
|
+
props,
|
|
1421
|
+
partial
|
|
1422
|
+
);
|
|
1423
|
+
}
|
|
1424
|
+
/**
|
|
1425
|
+
* The main function of the RenderContext.
|
|
1426
|
+
*
|
|
1427
|
+
* Use this function to render any route known to Astro.
|
|
1428
|
+
* It attempts to render a route. A route can be a:
|
|
1429
|
+
*
|
|
1430
|
+
* - page
|
|
1431
|
+
* - redirect
|
|
1432
|
+
* - endpoint
|
|
1433
|
+
* - fallback
|
|
1434
|
+
*/
|
|
1435
|
+
async render(componentInstance, slots = {}) {
|
|
1436
|
+
const { cookies, middleware, pipeline } = this;
|
|
1437
|
+
const { logger, serverLike, streaming } = pipeline;
|
|
1438
|
+
const isPrerendered = !serverLike || this.routeData.prerender;
|
|
1439
|
+
const props = Object.keys(this.props).length > 0 ? this.props : await getProps({
|
|
1440
|
+
mod: componentInstance,
|
|
1441
|
+
routeData: this.routeData,
|
|
1442
|
+
routeCache: this.pipeline.routeCache,
|
|
1443
|
+
pathname: this.pathname,
|
|
1444
|
+
logger,
|
|
1445
|
+
serverLike
|
|
1446
|
+
});
|
|
1447
|
+
const apiContext = this.createAPIContext(props, isPrerendered);
|
|
1448
|
+
this.counter++;
|
|
1449
|
+
if (this.counter === 4) {
|
|
1450
|
+
return new Response("Loop Detected", {
|
|
1451
|
+
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/508
|
|
1452
|
+
status: 508,
|
|
1453
|
+
statusText: "Astro detected a loop where you tried to call the rewriting logic more than four times."
|
|
1454
|
+
});
|
|
1455
|
+
}
|
|
1456
|
+
const lastNext = async (ctx, payload) => {
|
|
1457
|
+
if (payload) {
|
|
1458
|
+
pipeline.logger.debug("router", "Called rewriting to:", payload);
|
|
1459
|
+
const {
|
|
1460
|
+
routeData,
|
|
1461
|
+
componentInstance: newComponent,
|
|
1462
|
+
pathname,
|
|
1463
|
+
newUrl
|
|
1464
|
+
} = await pipeline.tryRewrite(payload, this.request);
|
|
1465
|
+
this.routeData = routeData;
|
|
1466
|
+
componentInstance = newComponent;
|
|
1467
|
+
if (payload instanceof Request) {
|
|
1468
|
+
this.request = payload;
|
|
1469
|
+
} else {
|
|
1470
|
+
this.request = copyRequest(newUrl, this.request);
|
|
1471
|
+
}
|
|
1472
|
+
this.isRewriting = true;
|
|
1473
|
+
this.url = new URL(this.request.url);
|
|
1474
|
+
this.cookies = new AstroCookies(this.request);
|
|
1475
|
+
this.params = getParams(routeData, pathname);
|
|
1476
|
+
this.pathname = pathname;
|
|
1477
|
+
this.status = 200;
|
|
1478
|
+
}
|
|
1479
|
+
let response2;
|
|
1480
|
+
switch (this.routeData.type) {
|
|
1481
|
+
case "endpoint": {
|
|
1482
|
+
response2 = await renderEndpoint(componentInstance, ctx, serverLike, logger);
|
|
1483
|
+
break;
|
|
1484
|
+
}
|
|
1485
|
+
case "redirect":
|
|
1486
|
+
return renderRedirect(this);
|
|
1487
|
+
case "page": {
|
|
1488
|
+
const result = await this.createResult(componentInstance);
|
|
1489
|
+
try {
|
|
1490
|
+
response2 = await renderPage(
|
|
1491
|
+
result,
|
|
1492
|
+
componentInstance?.default,
|
|
1493
|
+
props,
|
|
1494
|
+
slots,
|
|
1495
|
+
streaming,
|
|
1496
|
+
this.routeData
|
|
1497
|
+
);
|
|
1498
|
+
} catch (e) {
|
|
1499
|
+
result.cancelled = true;
|
|
1500
|
+
throw e;
|
|
1501
|
+
}
|
|
1502
|
+
response2.headers.set(ROUTE_TYPE_HEADER, "page");
|
|
1503
|
+
if (this.routeData.route === "/404" || this.routeData.route === "/500") {
|
|
1504
|
+
response2.headers.set(REROUTE_DIRECTIVE_HEADER, "no");
|
|
1505
|
+
}
|
|
1506
|
+
if (this.isRewriting) {
|
|
1507
|
+
response2.headers.set(REWRITE_DIRECTIVE_HEADER_KEY, REWRITE_DIRECTIVE_HEADER_VALUE);
|
|
1508
|
+
}
|
|
1509
|
+
break;
|
|
1510
|
+
}
|
|
1511
|
+
case "fallback": {
|
|
1512
|
+
return new Response(null, { status: 500, headers: { [ROUTE_TYPE_HEADER]: "fallback" } });
|
|
1513
|
+
}
|
|
1514
|
+
}
|
|
1515
|
+
const responseCookies = getCookiesFromResponse(response2);
|
|
1516
|
+
if (responseCookies) {
|
|
1517
|
+
cookies.merge(responseCookies);
|
|
1518
|
+
}
|
|
1519
|
+
return response2;
|
|
1520
|
+
};
|
|
1521
|
+
const response = await callMiddleware(middleware, apiContext, lastNext);
|
|
1522
|
+
if (response.headers.get(ROUTE_TYPE_HEADER)) {
|
|
1523
|
+
response.headers.delete(ROUTE_TYPE_HEADER);
|
|
1524
|
+
}
|
|
1525
|
+
attachCookiesToResponse(response, cookies);
|
|
1526
|
+
return response;
|
|
1527
|
+
}
|
|
1528
|
+
createAPIContext(props, isPrerendered) {
|
|
1529
|
+
const context = this.createActionAPIContext();
|
|
1530
|
+
const redirect = (path, status = 302) => new Response(null, { status, headers: { Location: path } });
|
|
1531
|
+
Reflect.set(context, apiContextRoutesSymbol, this.pipeline);
|
|
1532
|
+
return Object.assign(context, {
|
|
1533
|
+
props,
|
|
1534
|
+
redirect,
|
|
1535
|
+
getActionResult: createGetActionResult(context.locals),
|
|
1536
|
+
callAction: createCallAction(context),
|
|
1537
|
+
// Used internally by Actions middleware.
|
|
1538
|
+
// TODO: discuss exposing this information from APIContext.
|
|
1539
|
+
// middleware runs on prerendered routes in the dev server,
|
|
1540
|
+
// so this is useful information to have.
|
|
1541
|
+
_isPrerendered: isPrerendered
|
|
1542
|
+
});
|
|
1543
|
+
}
|
|
1544
|
+
async #executeRewrite(reroutePayload) {
|
|
1545
|
+
this.pipeline.logger.debug("router", "Calling rewrite: ", reroutePayload);
|
|
1546
|
+
const { routeData, componentInstance, newUrl, pathname } = await this.pipeline.tryRewrite(
|
|
1547
|
+
reroutePayload,
|
|
1548
|
+
this.request
|
|
1549
|
+
);
|
|
1550
|
+
this.routeData = routeData;
|
|
1551
|
+
if (reroutePayload instanceof Request) {
|
|
1552
|
+
this.request = reroutePayload;
|
|
1553
|
+
} else {
|
|
1554
|
+
this.request = copyRequest(newUrl, this.request);
|
|
1555
|
+
}
|
|
1556
|
+
this.url = new URL(this.request.url);
|
|
1557
|
+
this.cookies = new AstroCookies(this.request);
|
|
1558
|
+
this.params = getParams(routeData, pathname);
|
|
1559
|
+
this.pathname = pathname;
|
|
1560
|
+
this.isRewriting = true;
|
|
1561
|
+
this.status = 200;
|
|
1562
|
+
return await this.render(componentInstance);
|
|
1563
|
+
}
|
|
1564
|
+
createActionAPIContext() {
|
|
1565
|
+
const renderContext = this;
|
|
1566
|
+
const { cookies, params, pipeline, url } = this;
|
|
1567
|
+
const generator = `Astro v${ASTRO_VERSION}`;
|
|
1568
|
+
const rewrite = async (reroutePayload) => {
|
|
1569
|
+
return await this.#executeRewrite(reroutePayload);
|
|
1570
|
+
};
|
|
1571
|
+
return {
|
|
1572
|
+
cookies,
|
|
1573
|
+
get clientAddress() {
|
|
1574
|
+
return renderContext.clientAddress();
|
|
1575
|
+
},
|
|
1576
|
+
get currentLocale() {
|
|
1577
|
+
return renderContext.computeCurrentLocale();
|
|
1578
|
+
},
|
|
1579
|
+
generator,
|
|
1580
|
+
get locals() {
|
|
1581
|
+
return renderContext.locals;
|
|
1582
|
+
},
|
|
1583
|
+
// TODO(breaking): disallow replacing the locals object
|
|
1584
|
+
set locals(val) {
|
|
1585
|
+
if (typeof val !== "object") {
|
|
1586
|
+
throw new AstroError(LocalsNotAnObject);
|
|
1587
|
+
} else {
|
|
1588
|
+
renderContext.locals = val;
|
|
1589
|
+
Reflect.set(this.request, clientLocalsSymbol, val);
|
|
1590
|
+
}
|
|
1591
|
+
},
|
|
1592
|
+
params,
|
|
1593
|
+
get preferredLocale() {
|
|
1594
|
+
return renderContext.computePreferredLocale();
|
|
1595
|
+
},
|
|
1596
|
+
get preferredLocaleList() {
|
|
1597
|
+
return renderContext.computePreferredLocaleList();
|
|
1598
|
+
},
|
|
1599
|
+
rewrite,
|
|
1600
|
+
request: this.request,
|
|
1601
|
+
site: pipeline.site,
|
|
1602
|
+
url
|
|
1603
|
+
};
|
|
1604
|
+
}
|
|
1605
|
+
async createResult(mod) {
|
|
1606
|
+
const { cookies, pathname, pipeline, routeData, status } = this;
|
|
1607
|
+
const { clientDirectives, inlinedScripts, compressHTML, manifest, renderers, resolve } = pipeline;
|
|
1608
|
+
const { links, scripts, styles } = await pipeline.headElements(routeData);
|
|
1609
|
+
const componentMetadata = await pipeline.componentMetadata(routeData) ?? manifest.componentMetadata;
|
|
1610
|
+
const headers = new Headers({ "Content-Type": "text/html" });
|
|
1611
|
+
const partial = typeof this.partial === "boolean" ? this.partial : Boolean(mod.partial);
|
|
1612
|
+
const response = {
|
|
1613
|
+
status,
|
|
1614
|
+
statusText: "OK",
|
|
1615
|
+
get headers() {
|
|
1616
|
+
return headers;
|
|
1617
|
+
},
|
|
1618
|
+
// Disallow `Astro.response.headers = new Headers`
|
|
1619
|
+
set headers(_) {
|
|
1620
|
+
throw new AstroError(AstroResponseHeadersReassigned);
|
|
1621
|
+
}
|
|
1622
|
+
};
|
|
1623
|
+
const actionResult = hasActionPayload(this.locals) ? deserializeActionResult(this.locals._actionPayload.actionResult) : void 0;
|
|
1624
|
+
const result = {
|
|
1625
|
+
base: manifest.base,
|
|
1626
|
+
cancelled: false,
|
|
1627
|
+
clientDirectives,
|
|
1628
|
+
inlinedScripts,
|
|
1629
|
+
componentMetadata,
|
|
1630
|
+
compressHTML,
|
|
1631
|
+
cookies,
|
|
1632
|
+
/** This function returns the `Astro` faux-global */
|
|
1633
|
+
createAstro: (astroGlobal, props, slots) => this.createAstro(result, astroGlobal, props, slots),
|
|
1634
|
+
links,
|
|
1635
|
+
params: this.params,
|
|
1636
|
+
partial,
|
|
1637
|
+
pathname,
|
|
1638
|
+
renderers,
|
|
1639
|
+
resolve,
|
|
1640
|
+
response,
|
|
1641
|
+
request: this.request,
|
|
1642
|
+
scripts,
|
|
1643
|
+
styles,
|
|
1644
|
+
actionResult,
|
|
1645
|
+
serverIslandNameMap: manifest.serverIslandNameMap ?? /* @__PURE__ */ new Map(),
|
|
1646
|
+
key: manifest.key,
|
|
1647
|
+
trailingSlash: manifest.trailingSlash,
|
|
1648
|
+
_metadata: {
|
|
1649
|
+
hasHydrationScript: false,
|
|
1650
|
+
rendererSpecificHydrationScripts: /* @__PURE__ */ new Set(),
|
|
1651
|
+
hasRenderedHead: false,
|
|
1652
|
+
renderedScripts: /* @__PURE__ */ new Set(),
|
|
1653
|
+
hasDirectives: /* @__PURE__ */ new Set(),
|
|
1654
|
+
headInTree: false,
|
|
1655
|
+
extraHead: [],
|
|
1656
|
+
propagators: /* @__PURE__ */ new Set()
|
|
1657
|
+
}
|
|
1658
|
+
};
|
|
1659
|
+
return result;
|
|
1660
|
+
}
|
|
1661
|
+
#astroPagePartial;
|
|
1662
|
+
/**
|
|
1663
|
+
* The Astro global is sourced in 3 different phases:
|
|
1664
|
+
* - **Static**: `.generator` and `.glob` is printed by the compiler, instantiated once per process per astro file
|
|
1665
|
+
* - **Page-level**: `.request`, `.cookies`, `.locals` etc. These remain the same for the duration of the request.
|
|
1666
|
+
* - **Component-level**: `.props`, `.slots`, and `.self` are unique to each _use_ of each component.
|
|
1667
|
+
*
|
|
1668
|
+
* The page level partial is used as the prototype of the user-visible `Astro` global object, which is instantiated once per use of a component.
|
|
1669
|
+
*/
|
|
1670
|
+
createAstro(result, astroStaticPartial, props, slotValues) {
|
|
1671
|
+
let astroPagePartial;
|
|
1672
|
+
if (this.isRewriting) {
|
|
1673
|
+
astroPagePartial = this.#astroPagePartial = this.createAstroPagePartial(
|
|
1674
|
+
result,
|
|
1675
|
+
astroStaticPartial
|
|
1676
|
+
);
|
|
1677
|
+
} else {
|
|
1678
|
+
astroPagePartial = this.#astroPagePartial ??= this.createAstroPagePartial(
|
|
1679
|
+
result,
|
|
1680
|
+
astroStaticPartial
|
|
1681
|
+
);
|
|
1682
|
+
}
|
|
1683
|
+
const astroComponentPartial = { props, self: null };
|
|
1684
|
+
const Astro = Object.assign(
|
|
1685
|
+
Object.create(astroPagePartial),
|
|
1686
|
+
astroComponentPartial
|
|
1687
|
+
);
|
|
1688
|
+
let _slots;
|
|
1689
|
+
Object.defineProperty(Astro, "slots", {
|
|
1690
|
+
get: () => {
|
|
1691
|
+
if (!_slots) {
|
|
1692
|
+
_slots = new Slots(
|
|
1693
|
+
result,
|
|
1694
|
+
slotValues,
|
|
1695
|
+
this.pipeline.logger
|
|
1696
|
+
);
|
|
1697
|
+
}
|
|
1698
|
+
return _slots;
|
|
1699
|
+
}
|
|
1700
|
+
});
|
|
1701
|
+
return Astro;
|
|
1702
|
+
}
|
|
1703
|
+
createAstroPagePartial(result, astroStaticPartial) {
|
|
1704
|
+
const renderContext = this;
|
|
1705
|
+
const { cookies, locals, params, pipeline, url } = this;
|
|
1706
|
+
const { response } = result;
|
|
1707
|
+
const redirect = (path, status = 302) => {
|
|
1708
|
+
if (this.request[responseSentSymbol$1]) {
|
|
1709
|
+
throw new AstroError({
|
|
1710
|
+
...ResponseSentError
|
|
1711
|
+
});
|
|
1712
|
+
}
|
|
1713
|
+
return new Response(null, { status, headers: { Location: path } });
|
|
1714
|
+
};
|
|
1715
|
+
const rewrite = async (reroutePayload) => {
|
|
1716
|
+
return await this.#executeRewrite(reroutePayload);
|
|
1717
|
+
};
|
|
1718
|
+
return {
|
|
1719
|
+
generator: astroStaticPartial.generator,
|
|
1720
|
+
glob: astroStaticPartial.glob,
|
|
1721
|
+
cookies,
|
|
1722
|
+
get clientAddress() {
|
|
1723
|
+
return renderContext.clientAddress();
|
|
1724
|
+
},
|
|
1725
|
+
get currentLocale() {
|
|
1726
|
+
return renderContext.computeCurrentLocale();
|
|
1727
|
+
},
|
|
1728
|
+
params,
|
|
1729
|
+
get preferredLocale() {
|
|
1730
|
+
return renderContext.computePreferredLocale();
|
|
1731
|
+
},
|
|
1732
|
+
get preferredLocaleList() {
|
|
1733
|
+
return renderContext.computePreferredLocaleList();
|
|
1734
|
+
},
|
|
1735
|
+
locals,
|
|
1736
|
+
redirect,
|
|
1737
|
+
rewrite,
|
|
1738
|
+
request: this.request,
|
|
1739
|
+
response,
|
|
1740
|
+
site: pipeline.site,
|
|
1741
|
+
getActionResult: createGetActionResult(locals),
|
|
1742
|
+
get callAction() {
|
|
1743
|
+
return createCallAction(this);
|
|
1744
|
+
},
|
|
1745
|
+
url
|
|
1746
|
+
};
|
|
1747
|
+
}
|
|
1748
|
+
clientAddress() {
|
|
1749
|
+
const { pipeline, request } = this;
|
|
1750
|
+
if (clientAddressSymbol in request) {
|
|
1751
|
+
return Reflect.get(request, clientAddressSymbol);
|
|
1752
|
+
}
|
|
1753
|
+
if (pipeline.serverLike) {
|
|
1754
|
+
if (request.body === null) {
|
|
1755
|
+
throw new AstroError(PrerenderClientAddressNotAvailable);
|
|
1756
|
+
}
|
|
1757
|
+
if (pipeline.adapterName) {
|
|
1758
|
+
throw new AstroError({
|
|
1759
|
+
...ClientAddressNotAvailable,
|
|
1760
|
+
message: ClientAddressNotAvailable.message(pipeline.adapterName)
|
|
1761
|
+
});
|
|
1762
|
+
}
|
|
1763
|
+
}
|
|
1764
|
+
throw new AstroError(StaticClientAddressNotAvailable);
|
|
1765
|
+
}
|
|
1766
|
+
/**
|
|
1767
|
+
* API Context may be created multiple times per request, i18n data needs to be computed only once.
|
|
1768
|
+
* So, it is computed and saved here on creation of the first APIContext and reused for later ones.
|
|
1769
|
+
*/
|
|
1770
|
+
#currentLocale;
|
|
1771
|
+
computeCurrentLocale() {
|
|
1772
|
+
const {
|
|
1773
|
+
url,
|
|
1774
|
+
pipeline: { i18n },
|
|
1775
|
+
routeData
|
|
1776
|
+
} = this;
|
|
1777
|
+
if (!i18n) return;
|
|
1778
|
+
const { defaultLocale, locales, strategy } = i18n;
|
|
1779
|
+
const fallbackTo = strategy === "pathname-prefix-other-locales" || strategy === "domains-prefix-other-locales" ? defaultLocale : void 0;
|
|
1780
|
+
if (this.#currentLocale) {
|
|
1781
|
+
return this.#currentLocale;
|
|
1782
|
+
}
|
|
1783
|
+
let computedLocale;
|
|
1784
|
+
const pathname = routeData.pathname && !isRoute404or500(routeData) ? routeData.pathname : url.pathname;
|
|
1785
|
+
computedLocale = computeCurrentLocale(pathname, locales, defaultLocale);
|
|
1786
|
+
this.#currentLocale = computedLocale ?? fallbackTo;
|
|
1787
|
+
return this.#currentLocale;
|
|
1788
|
+
}
|
|
1789
|
+
#preferredLocale;
|
|
1790
|
+
computePreferredLocale() {
|
|
1791
|
+
const {
|
|
1792
|
+
pipeline: { i18n },
|
|
1793
|
+
request
|
|
1794
|
+
} = this;
|
|
1795
|
+
if (!i18n) return;
|
|
1796
|
+
return this.#preferredLocale ??= computePreferredLocale(request, i18n.locales);
|
|
1797
|
+
}
|
|
1798
|
+
#preferredLocaleList;
|
|
1799
|
+
computePreferredLocaleList() {
|
|
1800
|
+
const {
|
|
1801
|
+
pipeline: { i18n },
|
|
1802
|
+
request
|
|
1803
|
+
} = this;
|
|
1804
|
+
if (!i18n) return;
|
|
1805
|
+
return this.#preferredLocaleList ??= computePreferredLocaleList(request, i18n.locales);
|
|
1806
|
+
}
|
|
1807
|
+
}
|
|
1808
|
+
|
|
1809
|
+
function sequence(...handlers) {
|
|
1810
|
+
const filtered = handlers.filter((h) => !!h);
|
|
1811
|
+
const length = filtered.length;
|
|
1812
|
+
if (!length) {
|
|
1813
|
+
return defineMiddleware((_context, next) => {
|
|
1814
|
+
return next();
|
|
1815
|
+
});
|
|
1816
|
+
}
|
|
1817
|
+
return defineMiddleware((context, next) => {
|
|
1818
|
+
let carriedPayload = void 0;
|
|
1819
|
+
return applyHandle(0, context);
|
|
1820
|
+
function applyHandle(i, handleContext) {
|
|
1821
|
+
const handle = filtered[i];
|
|
1822
|
+
const result = handle(handleContext, async (payload) => {
|
|
1823
|
+
if (i < length - 1) {
|
|
1824
|
+
if (payload) {
|
|
1825
|
+
let newRequest;
|
|
1826
|
+
if (payload instanceof Request) {
|
|
1827
|
+
newRequest = payload;
|
|
1828
|
+
} else if (payload instanceof URL) {
|
|
1829
|
+
newRequest = new Request(payload, handleContext.request);
|
|
1830
|
+
} else {
|
|
1831
|
+
newRequest = new Request(
|
|
1832
|
+
new URL(payload, handleContext.url.origin),
|
|
1833
|
+
handleContext.request
|
|
1834
|
+
);
|
|
1835
|
+
}
|
|
1836
|
+
const pipeline = Reflect.get(handleContext, apiContextRoutesSymbol);
|
|
1837
|
+
const { routeData, pathname } = await pipeline.tryRewrite(
|
|
1838
|
+
payload,
|
|
1839
|
+
handleContext.request
|
|
1840
|
+
);
|
|
1841
|
+
carriedPayload = payload;
|
|
1842
|
+
handleContext.request = newRequest;
|
|
1843
|
+
handleContext.url = new URL(newRequest.url);
|
|
1844
|
+
handleContext.cookies = new AstroCookies(newRequest);
|
|
1845
|
+
handleContext.params = getParams(routeData, pathname);
|
|
1846
|
+
}
|
|
1847
|
+
return applyHandle(i + 1, handleContext);
|
|
1848
|
+
} else {
|
|
1849
|
+
return next(payload ?? carriedPayload);
|
|
1850
|
+
}
|
|
1851
|
+
});
|
|
1852
|
+
return result;
|
|
1853
|
+
}
|
|
1854
|
+
});
|
|
1855
|
+
}
|
|
1856
|
+
|
|
1857
|
+
function defineMiddleware(fn) {
|
|
1858
|
+
return fn;
|
|
1859
|
+
}
|
|
1860
|
+
|
|
1861
|
+
export { RouteCache as R, redirectToFallback as a, redirectToDefaultLocale as b, requestHasLocale as c, normalizeTheLocale as d, defineMiddleware as e, findRouteToRewrite as f, RenderContext as g, getSetCookiesFromResponse as h, matchRoute as m, notFound as n, requestIs404Or500 as r, sequence as s };
|