@defjs/core 0.0.0-test-002 → 0.0.0-test-003
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/{index.js → index.es.js} +19 -11
- package/index.es.min.js +1 -1
- package/package.json +1 -1
package/{index.js → index.es.js}
RENAMED
|
@@ -360,7 +360,6 @@ function defineRequest(method, endpoint) {
|
|
|
360
360
|
};
|
|
361
361
|
fn.withValidators = (value) => {
|
|
362
362
|
validators = value;
|
|
363
|
-
console.log(validators);
|
|
364
363
|
return fn;
|
|
365
364
|
};
|
|
366
365
|
fn.withTransformResponse = (value) => {
|
|
@@ -428,14 +427,24 @@ async function __fillRequestFromField(request, fieldOrFieldGroup, input) {
|
|
|
428
427
|
sp.set(key, serializeToString(value));
|
|
429
428
|
return sp;
|
|
430
429
|
}
|
|
430
|
+
function getValidValue(value, defaultValue) {
|
|
431
|
+
switch (true) {
|
|
432
|
+
case typeof value === "undefined":
|
|
433
|
+
return defaultValue;
|
|
434
|
+
case (typeof value === "object" && value === null):
|
|
435
|
+
return value;
|
|
436
|
+
default:
|
|
437
|
+
return value;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
431
440
|
if (isField(fieldOrFieldGroup)) {
|
|
432
441
|
let params;
|
|
433
442
|
let queryParams;
|
|
434
443
|
let headers;
|
|
435
444
|
let body = undefined;
|
|
436
|
-
const
|
|
445
|
+
const validValue = getValidValue(input, fieldOrFieldGroup());
|
|
437
446
|
const meta = __getFieldMetadata(fieldOrFieldGroup);
|
|
438
|
-
const err = await doValid([...meta.validators, ...meta.asyncValidator],
|
|
447
|
+
const err = await doValid([...meta.validators, ...meta.asyncValidator], validValue);
|
|
439
448
|
if (err) {
|
|
440
449
|
throw err;
|
|
441
450
|
}
|
|
@@ -445,40 +454,40 @@ async function __fillRequestFromField(request, fieldOrFieldGroup, input) {
|
|
|
445
454
|
if (!aliasName) {
|
|
446
455
|
throw ERR_NOT_SET_ALIAS;
|
|
447
456
|
}
|
|
448
|
-
queryParams = appendValue(new URLSearchParams, aliasName,
|
|
457
|
+
queryParams = appendValue(new URLSearchParams, aliasName, validValue);
|
|
449
458
|
break;
|
|
450
459
|
}
|
|
451
460
|
case 3 /* Param */: {
|
|
452
461
|
if (!aliasName) {
|
|
453
462
|
throw ERR_NOT_SET_ALIAS;
|
|
454
463
|
}
|
|
455
|
-
params = setValue(new Map, aliasName,
|
|
464
|
+
params = setValue(new Map, aliasName, validValue);
|
|
456
465
|
break;
|
|
457
466
|
}
|
|
458
467
|
case 4 /* Header */: {
|
|
459
468
|
if (!aliasName) {
|
|
460
469
|
throw ERR_NOT_SET_ALIAS;
|
|
461
470
|
}
|
|
462
|
-
headers = appendValue(new Headers, aliasName,
|
|
471
|
+
headers = appendValue(new Headers, aliasName, validValue);
|
|
463
472
|
break;
|
|
464
473
|
}
|
|
465
474
|
case 5 /* Form */: {
|
|
466
475
|
if (!aliasName) {
|
|
467
476
|
throw ERR_NOT_SET_ALIAS;
|
|
468
477
|
}
|
|
469
|
-
body = appendValue(new FormData, aliasName,
|
|
478
|
+
body = appendValue(new FormData, aliasName, validValue);
|
|
470
479
|
break;
|
|
471
480
|
}
|
|
472
481
|
case 7 /* UrlForm */: {
|
|
473
482
|
if (!aliasName) {
|
|
474
483
|
throw ERR_NOT_SET_ALIAS;
|
|
475
484
|
}
|
|
476
|
-
body = appendValue(new URLSearchParams, aliasName,
|
|
485
|
+
body = appendValue(new URLSearchParams, aliasName, validValue);
|
|
477
486
|
break;
|
|
478
487
|
}
|
|
479
488
|
case 1 /* Json */:
|
|
480
489
|
case 6 /* Body */:
|
|
481
|
-
body =
|
|
490
|
+
body = validValue;
|
|
482
491
|
break;
|
|
483
492
|
}
|
|
484
493
|
}
|
|
@@ -503,7 +512,7 @@ async function __fillRequestFromField(request, fieldOrFieldGroup, input) {
|
|
|
503
512
|
const meta = __getFieldMetadata(field3);
|
|
504
513
|
for (const [type, aliasName] of meta.alias) {
|
|
505
514
|
const valueKey = aliasName || propertyKey;
|
|
506
|
-
const value = input[propertyKey]
|
|
515
|
+
const value = getValidValue(input[propertyKey], field3());
|
|
507
516
|
const err = await doValid([...meta.validators, ...meta.asyncValidator], value);
|
|
508
517
|
if (err) {
|
|
509
518
|
throw err;
|
|
@@ -594,7 +603,6 @@ function __parseBody(params) {
|
|
|
594
603
|
if (text === "") {
|
|
595
604
|
return null;
|
|
596
605
|
}
|
|
597
|
-
console.log(text);
|
|
598
606
|
return JSON.parse(text);
|
|
599
607
|
}
|
|
600
608
|
case "text":
|
package/index.es.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var $=new Error("ERR_ABORTED"),K=new Error("ERR_TIMEOUT"),Ht=new Error("ERR_NETWORK"),y=new Error("ERR_NOT_FOUND_HANDLER"),W=new Error("ERR_OBSERVE"),h=new Error("ERR_NOT_SET_ALIAS"),X=new Error("ERR_UNSUPPORTED_FIELD_TYPE"),J=new Error("ERR_INVALID_CLIENT"),Q=new Error("ERR_NOT_FOUND_GLOBAL_CLIENT"),V=new Error("ERR_INVALID_HTTP_CONTEXT_TOKEN"),it=new Error("ERR_UNKNOWN");class _ extends Error{status;statusText;url;headers;ok;body;constructor(t){const n=t.status??0,r=t.statusText??"",o=n>=200&&n<300,s=t.headers??new Headers,c=t.url??null,i=t.body??null;let R;if(o)R=`Http failure during parsing for ${t.url||"(unknown url)"}`;else R=`Http failure response for ${t.url||"(unknown url)"}: ${t.status} ${t.statusText}`;super(R,{cause:t.error});super.name="HttpErrorResponse",this.statusText=r,this.url=c,this.headers=s,this.status=n,this.ok=o,this.body=i}}function Y(t){return Object.defineProperty(t,v,{value:t}),t}function j(t){return typeof t==="function"&&v in t}function Z(){const t=new Map;return{set(n,r){if(!j(n))throw V;return t.set(n,r),this},get(n){if(!j(n))throw V;if(!t.has(n))t.set(n,n());return t.get(n)},del(n){return t.delete(n),this},has(n){return t.has(n)},keys(){return t.keys()}}}var v=Symbol("HttpContextToken");function pt(t){const n={alias:new Map,validators:[],asyncValidator:[]},r=()=>t;return Object.defineProperty(r,G,{value:n}),r.withJson=(o)=>{return n.alias.set(1,o),r},r.withForm=(o)=>{return n.alias.set(5,o),r},r.withQuery=(o)=>{return n.alias.set(2,o),r},r.withParam=(o)=>{return n.alias.set(3,o),r},r.withHeader=(o)=>{return n.alias.set(4,o),r},r.withUrlForm=(o)=>{return n.alias.set(7,o),r},r.withBody=()=>{return n.alias.set(6,void 0),r},r.withValidators=(...o)=>{return n.validators=o,r},r.withAsyncValidators=(...o)=>{return n.asyncValidator=o,r},r}function S(t){return t[G]}function Rt(t,n){for(let r of t){const o=r(n);if(o)throw o}}async function ft(t,n){for(let r of t){const o=await r(n);if(o)throw o}}function O(t){return!!t&&typeof t==="function"&&G in t}function B(t){return!!t&&typeof t==="object"&&Object.entries(t).every(([,n])=>O(n))}var G=Symbol("field");var kt=void 0;var tt=()=>kt;function nt(t){return t.reduceRight((n,r)=>{return(o,s)=>r(o,(c)=>n(c,s))},(n,r)=>r(n))}function D(t){const n=t.status??0,r=t.statusText??"",o=t.url??"",s=t.headers??new Headers,c=t.body??null;return{status:n,statusText:r,url:o,headers:s,body:c}}function ot(t){switch(!0){case t instanceof FormData:case t instanceof Blob:case t instanceof ArrayBuffer:case t instanceof URLSearchParams:case typeof t==="string":return t;case typeof t==="object":case typeof t==="boolean":case typeof t==="number":case Array.isArray(t):return JSON.stringify(t);default:return null}}function xt(t){switch(!0){case t instanceof FormData:return"multipart/form-data";case t instanceof ArrayBuffer:return"application/octet-stream";case t instanceof Blob:return t.type||"application/octet-stream";case t instanceof URLSearchParams:return"application/x-www-form-urlencoded;charset=UTF-8";case typeof t==="string":return"text/plain";case(typeof t==="object"&&t!==null):case typeof t==="number":case typeof t==="boolean":return"application/json";default:return null}}function mt(t){if(O(t))return t();if(B(t)){const n={};for(let[r,o]of Object.entries(t))n[r]=o();return n}return}function Nt(t,n){let r=!1,o,s=[],c="json",i,R="body",e=!1,E=[],w;const T=()=>{let x,m,f;return{doRequest:async(...C)=>{let F,p;switch(C.length){case 1:{p=C[0];break}case 2:{F=C[0],p=C[1];break}}if(r&&!F)throw new Error("Because the request has input, the first argument must be the input value");if(E.length>0)for(let M of E)M(F);const k=p?.timeout||0;if(p?.abort)f=p.abort;else if(k>0)f=AbortSignal.timeout(k);const U=L(p?.client)?p.client:d(),l=z(U),u={host:l?.host,method:t,endpoint:n,queryParams:new URLSearchParams,headers:new Headers,body:void 0,withCredentials:e,responseType:c,context:i||Z(),observe:R,uploadProgress:x,downloadProgress:m,timeout:k,abort:f},q=p?.handler||l?.handler||tt();if(!q)throw y;if(r)await Ct(u,o,F);let I=await nt([...s])(u,q);if(typeof w==="function")try{I=D({...I,body:w(I)})}catch(M){throw new _({error:M})}switch(u.observe){case"body":return I.body;case"response":return I;default:throw W}},getInitValue:()=>mt(o),setUploadProgress:(C)=>{x=C},setDownloadProgress:(C)=>{m=C}}};return T.withField=(x)=>{return o=x,r=!0,T},T.withInterceptors=(x)=>{return s=x,T},T.withContext=(x)=>{return i=x,T},T.withCredentials=(x)=>{return e=x,T},T.withValidators=(x)=>{return E=x,console.log(E),T},T.withTransformResponse=(x)=>{return w=x,T},T.withObserve=(x)=>{return R=x,T},T.withResponseType=(x)=>{return c=x,T},T}function rt(t,n){return t.replace(/:([^\/]+)/g,(r,o)=>{return n.get(o)??"undefined"})}async function Ct(t,n,r){async function o(e,E){for(let w of e){const T=await w(E);if(T)return T}return}function s(e){return typeof e==="object"&&e!==null}function c(e){switch(!0){case Array.isArray(e):case(typeof e==="object"&&e!==null):return JSON.stringify(e);case(typeof e==="object"&&e===null):case typeof e==="boolean":case typeof e==="number":case typeof e==="string":return String(e);default:throw new Error("Unsupported value type")}}function i(e,E,w){if(Array.isArray(w))for(let T of w)e.append(E,c(T));else e.set(E,c(w));return e}function R(e,E,w){if(Array.isArray(w))for(let T of w)R(e,E,c(T));return e.set(E,c(w)),e}if(O(n)){let e,E,w,T=void 0;const x=r??n(),m=S(n),f=await o([...m.validators,...m.asyncValidator],x);if(f)throw f;for(let[N,H]of m.alias)switch(N){case 2:{if(!H)throw h;E=i(new URLSearchParams,H,x);break}case 3:{if(!H)throw h;e=R(new Map,H,x);break}case 4:{if(!H)throw h;w=i(new Headers,H,x);break}case 5:{if(!H)throw h;T=i(new FormData,H,x);break}case 7:{if(!H)throw h;T=i(new URLSearchParams,H,x);break}case 1:case 6:T=x;break}if(e)t.endpoint=rt(t.endpoint,e);t.queryParams=E,t.headers=w,t.body=T;return}if(B(n)&&s(r)){let e=new Map,E=new URLSearchParams,w=new Headers,T=new URLSearchParams,x=new FormData;const m={};let f=void 0,N;for(let[H,A]of Object.entries(n)){const g=S(A);for(let[C,F]of g.alias){const p=F||H,k=r[H]||A(),U=await o([...g.validators,...g.asyncValidator],k);if(U)throw U;switch(C){case 1:{Object.defineProperty(m,p,{value:k,writable:!0,enumerable:!0}),N=1;break}case 2:E=i(E,p,k);break;case 3:e=R(e,p,k);break;case 4:w=i(w,p,k);break;case 5:{x=i(x,p,k),N=5;break}case 7:{T=i(T,p,k),N=7;break}case 6:{f=k,N=6;break}}}}switch(t.endpoint=rt(t.endpoint,e),t.queryParams=E,t.headers=w,N){case 6:t.body=f;break;case 5:t.body=x;break;case 7:t.body=T;break;case 1:t.body=m;break}return}throw X}function et(t){const n=t.get("Content-Length");if(!n)return 0;const r=Number(n);if(isNaN(r))return 0;return r}function Tt(t){return t.get("Content-Type")||""}function ct(t){const{request:n,content:r,contentType:o}=t,s=n.responseType;if(!s)return null;switch(s){case"json":{const c=new TextDecoder().decode(r);if(c==="")return null;return console.log(c),JSON.parse(c)}case"text":return new TextDecoder().decode(r);case"blob":return new Blob([r],{type:o});case"arraybuffer":return r.buffer;default:return null}}function st(t,n){const r=new Uint8Array(n);let o=0;for(let s of t)r.set(s,o),o+=s.length;return r}function _t(t){const n=new URL(t.endpoint,t.host);if(t.queryParams)n.search=t.queryParams.toString();const r=t.headers??new Headers;if(!r.has("Content-Type")){const c=xt(t.body);if(c)r.set("Content-Type",c)}if(!r.has("Accept"))r.set("Accept","application/json, text/plain, */*");const o=t.withCredentials?"include":void 0,s=t.context?.get(Et)||{};return new Request(n,{...s,headers:r,method:t.method,body:ot(t.body),signal:t.abort,credentials:o})}async function b(t){const n=t.downloadProgress,r=_t(t);let o;try{o=await(globalThis||window).fetch(r)}catch(x){if(x instanceof DOMException)switch(!0){case(x.name==="AbortError"||x.code===x.ABORT_ERR):throw new _({error:$});case(x.name==="TimeoutError"||x.code===x.TIMEOUT_ERR):throw new _({error:K})}throw new _({error:x})}const{ok:s,headers:c,status:i,statusText:R,url:e}=o,E=et(c),w=Tt(c);let T=null;if(o.body){const x=[],m=o.body.getReader();let f=0;while(!0){const{done:H,value:A}=await m.read();if(H)break;x.push(A),f+=A.length,n?.({lengthComputable:E>0,loaded:f,total:E})}const N=st(x,f);try{T=ct({request:t,content:N,contentType:w})}catch(H){throw new _({error:H,status:i,statusText:R,headers:c,url:e})}}if(!s)throw new _({status:i,statusText:R,headers:c,url:e,body:T});return D({url:e,status:i,statusText:R,headers:c,body:T})}var Et=Y(()=>({}));function L(t){return typeof t==="object"&&t!==null&&P in t}function z(t){if(!L(t))throw J;return t[P]}function wt(t){const n={host:t.host,interceptors:t.interceptors??[],handler:t.handler||b};return{[P]:n}}function ht(t,n){const o={...z(t),...n};return{[P]:o}}function d(){if(!a)throw Q;return a}function At(t){a=t}function Ft(){a=void 0}function It(t){a=wt(t)}var P=Symbol("Client"),a;function Ot(t,n){let r=n?.encode;if(!r){const o=(globalThis||window).btoa;if(typeof o!=="function")throw new Error("BasicAuthInterceptor is not supported in this environment");r=(s)=>o(`${s.username}:${s.password}`)}return(o,s)=>{const c=o.headers||new Headers;return c.set("Authorization",`Basic ${r(t())}`),o.headers=c,s(o)}}var at=(t)=>{if(!t)return new Error("required");return null},gt=(t)=>{if(typeof t!=="boolean"||!t)return new Error("requiredTrue");return null},Ut=(t)=>{return(n)=>{if(typeof n!=="string")return new Error("invalid string");if(n.length<t)return new Error(`minLength ${t}`);return null}},Vt=(t)=>{return(n)=>{if(typeof n!=="string")return new Error("invalid string");if(n.length>t)return new Error(`maxLength ${t}`);return null}},Bt=(t)=>{return(n)=>{if(typeof n!=="number"||isNaN(n))return new Error("invalid number");if(n<t)return new Error(`minLength ${t}`);return null}},Dt=(t)=>{return(n)=>{if(typeof n!=="number"||isNaN(n))return new Error("invalid number");if(n>t)return new Error(`maxLength ${t}`);return null}},Lt=(t)=>{return(n)=>{if(typeof n!=="string")return new Error("invalid string");if(!t.test(n))return new Error("pattern");return null}};export{Rt as validatorField,At as setGlobalClient,Ft as restGlobalClient,gt as requiredTrue,at as required,Lt as pattern,Ut as minLength,Bt as min,Vt as maxLength,Dt as max,Y as makeHttpContextToken,Z as makeHttpContext,j as isHttpContextToken,B as isFieldGroup,O as isField,L as isClient,d as getGlobalClient,pt as field,b as fetchHandler,Nt as defineRequest,It as createGlobalClient,wt as createClient,ht as cloneClient,Ot as basicAuthInterceptor,ft as asyncValidatorField,_ as HttpErrorResponse,Et as FETCH_CONFIG_KEY,X as ERR_UNSUPPORTED_FIELD_TYPE,it as ERR_UNKNOWN,K as ERR_TIMEOUT,W as ERR_OBSERVE,h as ERR_NOT_SET_ALIAS,y as ERR_NOT_FOUND_HANDLER,Q as ERR_NOT_FOUND_GLOBAL_CLIENT,Ht as ERR_NETWORK,V as ERR_INVALID_HTTP_CONTEXT_TOKEN,J as ERR_INVALID_CLIENT,$ as ERR_ABORTED};
|
|
1
|
+
var W=new Error("ERR_ABORTED"),X=new Error("ERR_TIMEOUT"),Ht=new Error("ERR_NETWORK"),J=new Error("ERR_NOT_FOUND_HANDLER"),Q=new Error("ERR_OBSERVE"),F=new Error("ERR_NOT_SET_ALIAS"),j=new Error("ERR_UNSUPPORTED_FIELD_TYPE"),Y=new Error("ERR_INVALID_CLIENT"),Z=new Error("ERR_NOT_FOUND_GLOBAL_CLIENT"),D=new Error("ERR_INVALID_HTTP_CONTEXT_TOKEN"),it=new Error("ERR_UNKNOWN");class _ extends Error{status;statusText;url;headers;ok;body;constructor(t){const n=t.status??0,r=t.statusText??"",o=n>=200&&n<300,s=t.headers??new Headers,c=t.url??null,w=t.body??null;let p;if(o)p=`Http failure during parsing for ${t.url||"(unknown url)"}`;else p=`Http failure response for ${t.url||"(unknown url)"}: ${t.status} ${t.statusText}`;super(p,{cause:t.error});super.name="HttpErrorResponse",this.statusText=r,this.url=c,this.headers=s,this.status=n,this.ok=o,this.body=w}}function u(t){return Object.defineProperty(t,v,{value:t}),t}function a(t){return typeof t==="function"&&v in t}function G(){const t=new Map;return{set(n,r){if(!a(n))throw D;return t.set(n,r),this},get(n){if(!a(n))throw D;if(!t.has(n))t.set(n,n());return t.get(n)},del(n){return t.delete(n),this},has(n){return t.has(n)},keys(){return t.keys()}}}var v=Symbol("HttpContextToken");function pt(t){const n={alias:new Map,validators:[],asyncValidator:[]},r=()=>t;return Object.defineProperty(r,S,{value:n}),r.withJson=(o)=>{return n.alias.set(1,o),r},r.withForm=(o)=>{return n.alias.set(5,o),r},r.withQuery=(o)=>{return n.alias.set(2,o),r},r.withParam=(o)=>{return n.alias.set(3,o),r},r.withHeader=(o)=>{return n.alias.set(4,o),r},r.withUrlForm=(o)=>{return n.alias.set(7,o),r},r.withBody=()=>{return n.alias.set(6,void 0),r},r.withValidators=(...o)=>{return n.validators=o,r},r.withAsyncValidators=(...o)=>{return n.asyncValidator=o,r},r}function z(t){return t[S]}function ft(t,n){for(let r of t){const o=r(n);if(o)throw o}}async function Rt(t,n){for(let r of t){const o=await r(n);if(o)throw o}}function g(t){return!!t&&typeof t==="function"&&S in t}function L(t){return!!t&&typeof t==="object"&&Object.entries(t).every(([,n])=>g(n))}var S=Symbol("field");var kt=void 0;var tt=()=>kt;function nt(t){return t.reduceRight((n,r)=>{return(o,s)=>r(o,(c)=>n(c,s))},(n,r)=>r(n))}function V(t){const n=t.status??0,r=t.statusText??"",o=t.url??"",s=t.headers??new Headers,c=t.body??null;return{status:n,statusText:r,url:o,headers:s,body:c}}function ot(t){switch(!0){case t instanceof FormData:case t instanceof Blob:case t instanceof ArrayBuffer:case t instanceof URLSearchParams:case typeof t==="string":return t;case typeof t==="object":case typeof t==="boolean":case typeof t==="number":case Array.isArray(t):return JSON.stringify(t);default:return null}}function xt(t){switch(!0){case t instanceof FormData:return"multipart/form-data";case t instanceof ArrayBuffer:return"application/octet-stream";case t instanceof Blob:return t.type||"application/octet-stream";case t instanceof URLSearchParams:return"application/x-www-form-urlencoded;charset=UTF-8";case typeof t==="string":return"text/plain";case(typeof t==="object"&&t!==null):case typeof t==="number":case typeof t==="boolean":return"application/json";default:return null}}function mt(t){if(g(t))return t();if(L(t)){const n={};for(let[r,o]of Object.entries(t))n[r]=o();return n}return}function Nt(t,n){let r=!1,o,s=[],c="json",w,p="body",h=!1,T=[],E;const e=()=>{let x,i,f;return{doRequest:async(...k)=>{let I,m;switch(k.length){case 1:{m=k[0];break}case 2:{I=k[0],m=k[1];break}}if(r&&!I)throw new Error("Because the request has input, the first argument must be the input value");if(T.length>0)for(let y of T)y(I);const N=m?.timeout||0;if(m?.abort)f=m.abort;else if(N>0)f=AbortSignal.timeout(N);const C=P(m?.client)?m.client:d(),O=b(C),K={host:O?.host,method:t,endpoint:n,queryParams:new URLSearchParams,headers:new Headers,body:void 0,withCredentials:h,responseType:c,context:w||G(),observe:p,uploadProgress:x,downloadProgress:i,timeout:N,abort:f},q=m?.handler||O?.handler||tt();if(!q)throw J;if(r)await Ct(K,o,I);let U=await nt([...s])(K,q);if(typeof E==="function")try{U=V({...U,body:E(U)})}catch(y){throw new _({error:y})}switch(K.observe){case"body":return U.body;case"response":return U;default:throw Q}},getInitValue:()=>mt(o),setUploadProgress:(k)=>{x=k},setDownloadProgress:(k)=>{i=k}}};return e.withField=(x)=>{return o=x,r=!0,e},e.withInterceptors=(x)=>{return s=x,e},e.withContext=(x)=>{return w=x,e},e.withCredentials=(x)=>{return h=x,e},e.withValidators=(x)=>{return T=x,e},e.withTransformResponse=(x)=>{return E=x,e},e.withObserve=(x)=>{return p=x,e},e.withResponseType=(x)=>{return c=x,e},e}function rt(t,n){return t.replace(/:([^\/]+)/g,(r,o)=>{return n.get(o)??"undefined"})}async function Ct(t,n,r){async function o(T,E){for(let e of T){const x=await e(E);if(x)return x}return}function s(T){return typeof T==="object"&&T!==null}function c(T){switch(!0){case Array.isArray(T):case(typeof T==="object"&&T!==null):return JSON.stringify(T);case(typeof T==="object"&&T===null):case typeof T==="boolean":case typeof T==="number":case typeof T==="string":return String(T);default:throw new Error("Unsupported value type")}}function w(T,E,e){if(Array.isArray(e))for(let x of e)T.append(E,c(x));else T.set(E,c(e));return T}function p(T,E,e){if(Array.isArray(e))for(let x of e)p(T,E,c(x));return T.set(E,c(e)),T}function h(T,E){switch(!0){case typeof T==="undefined":return E;case(typeof T==="object"&&T===null):return T;default:return T}}if(g(n)){let T,E,e,x=void 0;const i=h(r,n()),f=z(n),A=await o([...f.validators,...f.asyncValidator],i);if(A)throw A;for(let[R,H]of f.alias)switch(R){case 2:{if(!H)throw F;E=w(new URLSearchParams,H,i);break}case 3:{if(!H)throw F;T=p(new Map,H,i);break}case 4:{if(!H)throw F;e=w(new Headers,H,i);break}case 5:{if(!H)throw F;x=w(new FormData,H,i);break}case 7:{if(!H)throw F;x=w(new URLSearchParams,H,i);break}case 1:case 6:x=i;break}if(T)t.endpoint=rt(t.endpoint,T);t.queryParams=E,t.headers=e,t.body=x;return}if(L(n)&&s(r)){let T=new Map,E=new URLSearchParams,e=new Headers,x=new URLSearchParams,i=new FormData;const f={};let A=void 0,R;for(let[H,$]of Object.entries(n)){const k=z($);for(let[I,m]of k.alias){const N=m||H,C=h(r[H],$()),O=await o([...k.validators,...k.asyncValidator],C);if(O)throw O;switch(I){case 1:{Object.defineProperty(f,N,{value:C,writable:!0,enumerable:!0}),R=1;break}case 2:E=w(E,N,C);break;case 3:T=p(T,N,C);break;case 4:e=w(e,N,C);break;case 5:{i=w(i,N,C),R=5;break}case 7:{x=w(x,N,C),R=7;break}case 6:{A=C,R=6;break}}}}switch(t.endpoint=rt(t.endpoint,T),t.queryParams=E,t.headers=e,R){case 6:t.body=A;break;case 5:t.body=i;break;case 7:t.body=x;break;case 1:t.body=f;break}return}throw j}function Tt(t){const n=t.get("Content-Length");if(!n)return 0;const r=Number(n);if(isNaN(r))return 0;return r}function et(t){return t.get("Content-Type")||""}function ct(t){const{request:n,content:r,contentType:o}=t,s=n.responseType;if(!s)return null;switch(s){case"json":{const c=new TextDecoder().decode(r);if(c==="")return null;return JSON.parse(c)}case"text":return new TextDecoder().decode(r);case"blob":return new Blob([r],{type:o});case"arraybuffer":return r.buffer;default:return null}}function st(t,n){const r=new Uint8Array(n);let o=0;for(let s of t)r.set(s,o),o+=s.length;return r}function _t(t){const n=new URL(t.endpoint,t.host);if(t.queryParams)n.search=t.queryParams.toString();const r=t.headers??new Headers;if(!r.has("Content-Type")){const c=xt(t.body);if(c)r.set("Content-Type",c)}if(!r.has("Accept"))r.set("Accept","application/json, text/plain, */*");const o=t.withCredentials?"include":void 0,s=t.context?.get(Et)||{};return new Request(n,{...s,headers:r,method:t.method,body:ot(t.body),signal:t.abort,credentials:o})}async function l(t){const n=t.downloadProgress,r=_t(t);let o;try{o=await(globalThis||window).fetch(r)}catch(x){if(x instanceof DOMException)switch(!0){case(x.name==="AbortError"||x.code===x.ABORT_ERR):throw new _({error:W});case(x.name==="TimeoutError"||x.code===x.TIMEOUT_ERR):throw new _({error:X})}throw new _({error:x})}const{ok:s,headers:c,status:w,statusText:p,url:h}=o,T=Tt(c),E=et(c);let e=null;if(o.body){const x=[],i=o.body.getReader();let f=0;while(!0){const{done:R,value:H}=await i.read();if(R)break;x.push(H),f+=H.length,n?.({lengthComputable:T>0,loaded:f,total:T})}const A=st(x,f);try{e=ct({request:t,content:A,contentType:E})}catch(R){throw new _({error:R,status:w,statusText:p,headers:c,url:h})}}if(!s)throw new _({status:w,statusText:p,headers:c,url:h,body:e});return V({url:h,status:w,statusText:p,headers:c,body:e})}var Et=u(()=>({}));function P(t){return typeof t==="object"&&t!==null&&M in t}function b(t){if(!P(t))throw Y;return t[M]}function wt(t){const n={host:t.host,interceptors:t.interceptors??[],handler:t.handler||l};return{[M]:n}}function ht(t,n){const o={...b(t),...n};return{[M]:o}}function d(){if(!B)throw Z;return B}function At(t){B=t}function Ft(){B=void 0}function It(t){B=wt(t)}var M=Symbol("Client"),B;function Ot(t,n){let r=n?.encode;if(!r){const o=(globalThis||window).btoa;if(typeof o!=="function")throw new Error("BasicAuthInterceptor is not supported in this environment");r=(s)=>o(`${s.username}:${s.password}`)}return(o,s)=>{const c=o.headers||new Headers;return c.set("Authorization",`Basic ${r(t())}`),o.headers=c,s(o)}}var Ut=(t)=>{if(!t)return new Error("required");return null},gt=(t)=>{if(typeof t!=="boolean"||!t)return new Error("requiredTrue");return null},Bt=(t)=>{return(n)=>{if(typeof n!=="string")return new Error("invalid string");if(n.length<t)return new Error(`minLength ${t}`);return null}},Dt=(t)=>{return(n)=>{if(typeof n!=="string")return new Error("invalid string");if(n.length>t)return new Error(`maxLength ${t}`);return null}},Lt=(t)=>{return(n)=>{if(typeof n!=="number"||isNaN(n))return new Error("invalid number");if(n<t)return new Error(`minLength ${t}`);return null}},Vt=(t)=>{return(n)=>{if(typeof n!=="number"||isNaN(n))return new Error("invalid number");if(n>t)return new Error(`maxLength ${t}`);return null}},Pt=(t)=>{return(n)=>{if(typeof n!=="string")return new Error("invalid string");if(!t.test(n))return new Error("pattern");return null}};export{ft as validatorField,At as setGlobalClient,Ft as restGlobalClient,gt as requiredTrue,Ut as required,Pt as pattern,Bt as minLength,Lt as min,Dt as maxLength,Vt as max,u as makeHttpContextToken,G as makeHttpContext,a as isHttpContextToken,L as isFieldGroup,g as isField,P as isClient,d as getGlobalClient,pt as field,l as fetchHandler,Nt as defineRequest,It as createGlobalClient,wt as createClient,ht as cloneClient,Ot as basicAuthInterceptor,Rt as asyncValidatorField,_ as HttpErrorResponse,Et as FETCH_CONFIG_KEY,j as ERR_UNSUPPORTED_FIELD_TYPE,it as ERR_UNKNOWN,X as ERR_TIMEOUT,Q as ERR_OBSERVE,F as ERR_NOT_SET_ALIAS,J as ERR_NOT_FOUND_HANDLER,Z as ERR_NOT_FOUND_GLOBAL_CLIENT,Ht as ERR_NETWORK,D as ERR_INVALID_HTTP_CONTEXT_TOKEN,Y as ERR_INVALID_CLIENT,W as ERR_ABORTED};
|