tressi
Version:
Deterministic load testing for API performance validation.
2 lines (1 loc) • 4.93 kB
JavaScript
import{R as S}from"./chunk-W6IDPYNF.js";import{a as u}from"./chunk-I4MTPUBM.js";var E=(t,r,e={})=>{let n=`${t}=${r}`;if(t.startsWith("__Secure-")&&!e.secure)throw new Error("__Secure- Cookie must have Secure attributes");if(t.startsWith("__Host-")){if(!e.secure)throw new Error("__Host- Cookie must have Secure attributes");if(e.path!=="/")throw new Error('__Host- Cookie must have Path attributes with "/"');if(e.domain)throw new Error("__Host- Cookie must not have Domain attributes")}for(let i of["domain","path"])if(e[i]&&/[;\r\n]/.test(e[i]))throw new Error(`${i} must not contain ";", "\\r", or "\\n"`);if(e&&typeof e.maxAge=="number"&&e.maxAge>=0){if(e.maxAge>3456e4)throw new Error("Cookies Max-Age SHOULD NOT be greater than 400 days (34560000 seconds) in duration.");n+=`; Max-Age=${e.maxAge|0}`}if(e.domain&&e.prefix!=="host"&&(n+=`; Domain=${e.domain}`),e.path&&(n+=`; Path=${e.path}`),e.expires){if(e.expires.getTime()-Date.now()>3456e7)throw new Error("Cookies Expires SHOULD NOT be greater than 400 days (34560000 seconds) in the future.");n+=`; Expires=${e.expires.toUTCString()}`}if(e.httpOnly&&(n+="; HttpOnly"),e.secure&&(n+="; Secure"),e.sameSite&&(n+=`; SameSite=${e.sameSite.charAt(0).toUpperCase()+e.sameSite.slice(1)}`),e.priority&&(n+=`; Priority=${e.priority.charAt(0).toUpperCase()+e.priority.slice(1)}`),e.partitioned){if(!e.secure)throw new Error("Partitioned Cookie must have Secure attributes");n+="; Partitioned"}return n},b=(t,r,e)=>(r=encodeURIComponent(r),E(t,r,e));var $=(t,r)=>(t=t.replace(/\/+$/,""),t=t+"/",r=r.replace(/^\/+/,""),t+r),m=(t,r)=>{for(let[e,n]of Object.entries(r)){let i=new RegExp("/:"+e+"(?:{[^/]+})?\\??");t=t.replace(i,n?`/${n}`:"")}return t},C=t=>{let r=new URLSearchParams;for(let[e,n]of Object.entries(t))if(n!==void 0)if(Array.isArray(n))for(let i of n)r.append(e,i);else r.set(e,n);return r},O=(t,r)=>{switch(r){case"ws":return t.replace(/^http/,"ws");case"http":return t.replace(/^ws/,"http")}},x=t=>/^https?:\/\/[^\/]+?\/index(?=\?|$)/.test(t)?t.replace(/\/index(?=\?|$)/,"/"):t.replace(/\/index(?=\?|$)/,"");function p(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function w(t,r){if(!p(t)&&!p(r))return r;let e=u({},t);for(let n in r){let i=r[n];p(e[n])&&p(i)?e[n]=w(e[n],i):e[n]=i}return e}var k=(t,r)=>new Proxy(()=>{},{get(n,i){if(!(typeof i!="string"||i==="then"))return k(t,[...r,i])},apply(n,i,o){return t({path:r,args:o})}}),U=class{url;method;buildSearchParams;queryParams=void 0;pathParams={};rBody;cType=void 0;constructor(t,r,e){this.url=t,this.method=r,this.buildSearchParams=e.buildSearchParams}fetch=async(t,r)=>{if(t){if(t.query&&(this.queryParams=this.buildSearchParams(t.query)),t.form){let a=new FormData;for(let[d,c]of Object.entries(t.form))if(c!==void 0)if(Array.isArray(c))for(let l of c)a.append(d,l);else a.append(d,c);this.rBody=a}t.json&&(this.rBody=JSON.stringify(t.json),this.cType="application/json"),t.param&&(this.pathParams=t.param)}let e=this.method.toUpperCase(),n=u(u({},t?.header),typeof r?.headers=="function"?await r.headers():r?.headers);if(t?.cookie){let a=[];for(let[d,c]of Object.entries(t.cookie))a.push(b(d,c,{path:"/"}));n.Cookie=a.join(",")}this.cType&&(n["Content-Type"]=this.cType);let i=new Headers(n??void 0),o=this.url;o=x(o),o=m(o,this.pathParams),this.queryParams&&(o=o+"?"+this.queryParams.toString()),e=this.method.toUpperCase();let f=!(e==="GET"||e==="HEAD");return(r?.fetch||fetch)(o,u({body:f?this.rBody:void 0,method:e,headers:i},r?.init))}},v=(t,r)=>k(function e(n){let i=r?.buildSearchParams??C,o=[...n.path],f=o.slice(-3).reverse();if(f[0]==="toString")return f[1]==="name"?f[2]||"":e.toString();if(f[0]==="valueOf")return f[1]==="name"?f[2]||"":e;let a="";if(/^\$/.test(f[0])){let s=o.pop();s&&(a=s.replace(/^\$/,""))}let d=o.join("/"),c=$(t,d);if(a==="url"||a==="path"){let s=c;return n.args[0]&&(n.args[0].param&&(s=m(c,n.args[0].param)),n.args[0].query&&(s=s+"?"+i(n.args[0].query).toString())),s=x(s),a==="url"?new URL(s):s.slice(t.replace(/\/+$/,"").length).replace(/^\/?/,"/")}if(a==="ws"){let s=O(n.args[0]&&n.args[0].param?m(c,n.args[0].param):c,"ws"),y=new URL(s),P=n.args[0]?.query;return P&&Object.entries(P).forEach(([h,g])=>{Array.isArray(g)?g.forEach(A=>y.searchParams.append(h,A)):y.searchParams.set(h,g)}),((...h)=>r?.webSocket!==void 0&&typeof r.webSocket=="function"?r.webSocket(...h):new WebSocket(...h))(y.toString())}let l=new U(c,a,{buildSearchParams:i});if(a){r??={};let s=w(r,u({},n.args[1]));return l.fetch(n.args[0],s)}return l},[]);var R=class t{client=v("/").api;async getTestStatus(){try{let r=await this.client.test.status.$get();if(!r.ok)throw new Error(`Failed to get test status: ${r.statusText}`);let e=await r.json();return e.isRunning&&"jobId"in e?{isRunning:!0,jobId:e.jobId}:{isRunning:!1}}catch{return{isRunning:!1}}}static \u0275fac=function(e){return new(e||t)};static \u0275prov=S({token:t,factory:t.\u0275fac,providedIn:"root"})};export{R as a};