JezK
Edit File: loader-circle-Df9wuB8c.js
import{A as e,D as t,E as n,T as r,k as i,w as a,x as o}from"./index-ep0C0hKG.js";import{p as s}from"./SiteLayout-DURY82eZ.js";function c(e){if(Array.isArray(e))return e.flatMap(e=>c(e));if(typeof e!=`string`)return[];let t=[],n=0,r,i,a,o,s,l=()=>{for(;n<e.length&&/\s/.test(e.charAt(n));)n+=1;return n<e.length},u=()=>(i=e.charAt(n),i!==`=`&&i!==`;`&&i!==`,`);for(;n<e.length;){for(r=n,s=!1;l();)if(i=e.charAt(n),i===`,`){for(a=n,n+=1,l(),o=n;n<e.length&&u();)n+=1;n<e.length&&e.charAt(n)===`=`?(s=!0,n=o,t.push(e.slice(r,a)),r=n):n=a+1}else n+=1;(!s||n>=e.length)&&t.push(e.slice(r))}return t}function l(e){return e instanceof Headers?e:Array.isArray(e)||typeof e==`object`?new Headers(e):null}function u(...e){return e.reduce((e,t)=>{let n=l(t);if(!n)return e;for(let[t,r]of n.entries())t===`set-cookie`?c(r).forEach(t=>e.append(`set-cookie`,t)):e.set(t,r);return e},new Headers)}var d=e(i(),1);function f(e){let t=o();return d.useCallback(async(...n)=>{try{let t=await e(...n);if(a(t))throw t;return t}catch(e){if(a(e))return e.options._fromLocation=t.stores.location.get(),t.navigate(t.resolveRedirect(e).options);throw e}},[t,e])}function p(e){return e!==`__proto__`&&e!==`constructor`&&e!==`prototype`}function m(e,t){let n=Object.create(null);if(e)for(let t of Object.keys(e))p(t)&&(n[t]=e[t]);if(t&&typeof t==`object`)for(let e of Object.keys(t))p(e)&&(n[e]=t[e]);return n}function h(e){if(!e)return Object.create(null);let t=Object.create(null);for(let n of Object.keys(e))p(n)&&(t[n]=e[n]);return t}var g=()=>{throw Error(`createServerOnlyFn() functions can only be called on the server!`)},_=(e,n)=>{let i=n||e||{};i.method===void 0&&(i.method=`GET`);let a=e=>_(void 0,{...i,validator:e,inputValidator:e});return Object.assign(e=>_(void 0,{...i,...e}),{options:i,middleware:e=>{let n=[...i.middleware||[]];e.map(e=>{t in e?e.options.middleware&&n.push(...e.options.middleware):n.push(e)});let r=_(void 0,{...i,middleware:n});return r[t]=!0,r},validator:a,inputValidator:a,handler:(...e)=>{let[t,n]=e,a={...i,extractedFn:t,serverFn:n},o=[...a.middleware||[],x(a)];return t.method=i.method,Object.assign(async e=>{let n=await v(o,`client`,{...t,...a,data:e?.data,headers:e?.headers,signal:e?.signal,fetch:e?.fetch,context:h()}),i=r(n.error);if(i)throw i;if(n.error)throw n.error;return n.result},{...t,method:i.method,__executeServer:async e=>{let n=g(),r=n.contextAfterGlobalMiddlewares;return await v(o,`server`,{...t,...e,serverFnMeta:t.serverFnMeta,context:m(e.context,r),request:n.request}).then(e=>({result:e.result,error:e.error,context:e.sendContext}))}})}})};async function v(e,t,r){let i=y([...n()?.functionMiddleware||[],...e]);if(t===`server`){let e=g({throwIfNotFound:!1});e?.executedRequestMiddlewares&&(i=i.filter(t=>!e.executedRequestMiddlewares.has(t)))}let o=async e=>{let n=i.shift();if(!n)return e;try{let r=`validator`in n.options?n.options.validator:void 0;!r&&`inputValidator`in n.options&&(r=n.options.inputValidator),r&&t===`server`&&(e.data=await b(r,e.data));let i;if(t===`client`?`client`in n.options&&(i=n.options.client):`server`in n.options&&(i=n.options.server),i){let t=async(t={})=>{let n=await o({...e,...t,context:m(e.context,t.context),sendContext:m(e.sendContext,t.sendContext),headers:u(e.headers,t.headers),_callSiteFetch:e._callSiteFetch,fetch:e._callSiteFetch??t.fetch??e.fetch,result:t.result===void 0?t instanceof Response?t:e.result:t.result,error:t.error??e.error});if(n.error)throw n.error;return n},n=await i({...e,next:t});if(a(n))return{...e,error:n};if(n instanceof Response)return{...e,result:n};if(!n)throw Error(`User middleware returned undefined. You must call next() or return a result in your middlewares.`);return n}return o(e)}catch(t){return{...e,error:t}}};return o({...r,headers:r.headers||{},sendContext:r.sendContext||{},context:r.context||h(),_callSiteFetch:r.fetch})}function y(e,t=100){let n=new Set,r=[],i=(e,a)=>{if(a>t)throw Error(`Middleware nesting depth exceeded maximum of ${t}. Check for circular references.`);e.forEach(e=>{e.options.middleware&&i(e.options.middleware,a+1),n.has(e)||(n.add(e),r.push(e))})};return i(e,0),r}async function b(e,t){if(e==null)return{};if(`~standard`in e){let n=await e[`~standard`].validate(t);if(n.issues)throw Error(JSON.stringify(n.issues,void 0,2));return n.value}if(`parse`in e)return e.parse(t);if(typeof e==`function`)return e(t);throw Error(`Invalid validator type!`)}function x(e){return{"~types":void 0,options:{inputValidator:e.validator??e.inputValidator,client:async({next:t,sendContext:n,fetch:r,...i})=>{let a={...i,context:n,fetch:r};return t(await e.extractedFn?.(a))},server:async({next:t,...n})=>{let r=await e.serverFn?.(n);return t({...n,result:r})}}}}var S=s(`loader-circle`,[[`path`,{d:`M21 12a9 9 0 1 1-6.219-8.56`,key:`13zald`}]]);export{_ as n,f as r,S as t};