@vef-framework/core 1.0.134 → 2.0.0

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.
Files changed (139) hide show
  1. package/README +15 -0
  2. package/dist/cjs/api/client.cjs +171 -0
  3. package/dist/cjs/api/constants.cjs +13 -0
  4. package/dist/cjs/api/helpers.cjs +12 -0
  5. package/dist/cjs/api/index.cjs +14 -0
  6. package/dist/cjs/auth/helpers.cjs +19 -0
  7. package/dist/cjs/auth/index.cjs +10 -0
  8. package/dist/cjs/common/index.cjs +3 -0
  9. package/dist/cjs/context/api-client.cjs +25 -0
  10. package/dist/cjs/context/app.cjs +15 -0
  11. package/dist/cjs/context/context-selector.cjs +65 -0
  12. package/dist/cjs/context/disabled.cjs +15 -0
  13. package/dist/cjs/context/index.cjs +19 -0
  14. package/dist/cjs/dnd/index.cjs +102 -0
  15. package/dist/cjs/http/client.cjs +445 -0
  16. package/dist/cjs/http/errors.cjs +23 -0
  17. package/dist/cjs/http/helpers.cjs +17 -0
  18. package/dist/cjs/http/index.cjs +17 -0
  19. package/dist/cjs/immer/index.cjs +40 -0
  20. package/dist/cjs/index.cjs +306 -0
  21. package/dist/cjs/motion/features.cjs +13 -0
  22. package/dist/cjs/motion/index.cjs +48 -0
  23. package/dist/cjs/motion/motion-provider.cjs +29 -0
  24. package/dist/cjs/query/constants.cjs +8 -0
  25. package/dist/cjs/query/helpers.cjs +67 -0
  26. package/dist/cjs/query/hooks.cjs +52 -0
  27. package/dist/cjs/query/index.cjs +20 -0
  28. package/dist/cjs/state/index.cjs +41 -0
  29. package/dist/cjs/state-machine/index.cjs +35 -0
  30. package/dist/cjs/store/bound.cjs +42 -0
  31. package/dist/cjs/store/index.cjs +20 -0
  32. package/dist/cjs/store/unbound.cjs +74 -0
  33. package/dist/cjs/store/use-deep.cjs +17 -0
  34. package/dist/es/api/client.js +167 -0
  35. package/dist/es/api/constants.js +8 -0
  36. package/dist/es/api/helpers.js +8 -0
  37. package/dist/es/api/index.js +4 -0
  38. package/dist/es/auth/helpers.js +15 -0
  39. package/dist/es/auth/index.js +2 -0
  40. package/dist/es/common/index.js +1 -0
  41. package/dist/es/context/api-client.js +20 -0
  42. package/dist/es/context/app.js +10 -0
  43. package/dist/es/context/context-selector.js +61 -0
  44. package/dist/es/context/disabled.js +10 -0
  45. package/dist/es/context/index.js +5 -0
  46. package/dist/es/dnd/index.js +7 -0
  47. package/dist/es/http/client.js +439 -0
  48. package/dist/es/http/errors.js +19 -0
  49. package/dist/es/http/helpers.js +12 -0
  50. package/dist/es/http/index.js +4 -0
  51. package/dist/es/immer/index.js +8 -0
  52. package/dist/es/index.js +43 -0
  53. package/dist/es/motion/features.js +2 -0
  54. package/dist/es/motion/index.js +5 -0
  55. package/dist/es/motion/motion-provider.js +25 -0
  56. package/dist/es/query/constants.js +4 -0
  57. package/dist/es/query/helpers.js +60 -0
  58. package/dist/es/query/hooks.js +27 -0
  59. package/dist/es/query/index.js +4 -0
  60. package/dist/es/state/index.js +2 -0
  61. package/dist/es/state-machine/index.js +12 -0
  62. package/dist/es/store/bound.js +37 -0
  63. package/dist/es/store/index.js +5 -0
  64. package/dist/es/store/unbound.js +70 -0
  65. package/dist/es/store/use-deep.js +13 -0
  66. package/dist/types/api/client.d.ts +75 -0
  67. package/dist/types/api/constants.d.ts +8 -0
  68. package/dist/types/api/helpers.d.ts +9 -0
  69. package/dist/types/api/index.d.ts +4 -0
  70. package/dist/types/api/types.d.ts +48 -0
  71. package/dist/types/auth/helpers.d.ts +11 -0
  72. package/dist/types/auth/index.d.ts +2 -0
  73. package/dist/types/auth/types.d.ts +1 -0
  74. package/dist/types/common/index.d.ts +1 -0
  75. package/dist/types/common/types.d.ts +95 -0
  76. package/dist/types/context/api-client.d.ts +18 -0
  77. package/dist/types/context/app.d.ts +4 -0
  78. package/dist/types/context/context-selector.d.ts +44 -0
  79. package/dist/types/context/disabled.d.ts +9 -0
  80. package/dist/types/context/index.d.ts +5 -0
  81. package/dist/types/context/types.d.ts +27 -0
  82. package/dist/types/dnd/index.d.ts +6 -0
  83. package/dist/types/http/client.d.ts +144 -0
  84. package/dist/types/http/errors.d.ts +14 -0
  85. package/dist/types/http/helpers.d.ts +17 -0
  86. package/dist/types/http/index.d.ts +4 -0
  87. package/dist/types/http/types.d.ts +101 -0
  88. package/dist/types/immer/index.d.ts +2 -0
  89. package/dist/types/index.d.ts +14 -0
  90. package/dist/types/motion/features.d.ts +1 -0
  91. package/dist/types/motion/index.d.ts +4 -0
  92. package/dist/types/motion/motion-provider.d.ts +5 -0
  93. package/dist/types/query/constants.d.ts +1 -0
  94. package/dist/types/query/helpers.d.ts +10 -0
  95. package/dist/types/query/hooks.d.ts +66 -0
  96. package/dist/types/query/index.d.ts +4 -0
  97. package/dist/types/query/types.d.ts +51 -0
  98. package/dist/types/state/index.d.ts +1 -0
  99. package/dist/types/state-machine/index.d.ts +14 -0
  100. package/dist/types/store/bound.d.ts +28 -0
  101. package/dist/types/store/index.d.ts +5 -0
  102. package/dist/types/store/types.d.ts +50 -0
  103. package/dist/types/store/unbound.d.ts +26 -0
  104. package/dist/types/store/use-deep.d.ts +7 -0
  105. package/package.json +59 -36
  106. package/README.md +0 -25
  107. package/cjs/api/api-client.cjs +0 -2
  108. package/cjs/api/api-context.cjs +0 -2
  109. package/cjs/api/index.cjs +0 -2
  110. package/cjs/api/query-client.cjs +0 -2
  111. package/cjs/api/request-client.cjs +0 -2
  112. package/cjs/auth/auth-context.cjs +0 -2
  113. package/cjs/auth/index.cjs +0 -2
  114. package/cjs/expr/compiler.cjs +0 -2
  115. package/cjs/expr/helpers.cjs +0 -2
  116. package/cjs/index.cjs +0 -2
  117. package/cjs/middleware/dispatcher.cjs +0 -2
  118. package/esm/api/api-client.js +0 -2
  119. package/esm/api/api-context.js +0 -2
  120. package/esm/api/index.js +0 -2
  121. package/esm/api/query-client.js +0 -2
  122. package/esm/api/request-client.js +0 -2
  123. package/esm/auth/auth-context.js +0 -2
  124. package/esm/auth/index.js +0 -2
  125. package/esm/expr/compiler.js +0 -2
  126. package/esm/expr/helpers.js +0 -2
  127. package/esm/index.js +0 -2
  128. package/esm/middleware/dispatcher.js +0 -2
  129. package/types/api/api-client.d.ts +0 -203
  130. package/types/api/api-context.d.ts +0 -167
  131. package/types/api/index.d.ts +0 -3
  132. package/types/api/query-client.d.ts +0 -27
  133. package/types/api/request-client.d.ts +0 -95
  134. package/types/auth/auth-context.d.ts +0 -29
  135. package/types/auth/index.d.ts +0 -1
  136. package/types/expr/compiler.d.ts +0 -35
  137. package/types/expr/helpers.d.ts +0 -58
  138. package/types/index.d.ts +0 -3
  139. package/types/middleware/dispatcher.d.ts +0 -22
@@ -1,2 +0,0 @@
1
- "use strict";
2
- "use strict";var l=require("@vef-framework/shared"),R=require("axios"),U=require("qs"),b=s=>{throw TypeError(s)},q=(s,a,e)=>a.has(s)||b("Cannot "+e),p=(s,a,e)=>(q(s,a,"read from private field"),e?e.call(s):a.get(s)),N=(s,a,e)=>a.has(s)?b("Cannot add the same private member more than once"):a instanceof WeakSet?a.add(s):a.set(s,e),M=(s,a,e,t)=>(q(s,a,"write to private field"),t?t.call(s,e):a.set(s,e),e),d;const E=/\{\w+\}/;class P{constructor(a){this.options=a,N(this,d);const{baseUrl:e,timeout:t,getAccessToken:m,successCode:u=0,unauthorizedCode:w=1e3,accessDeniedCode:i=1002,tokenExpiredCode:f=1001,onUnauthorized:g,onAccessDenied:h,onErrorMessage:j,onInfoMessage:k,onWarningMessage:C}=a;M(this,d,R.create({baseURL:e,timeout:t??1e3*30,headers:{"Content-Type":"application/json"},paramsSerializer:r=>U.stringify(r,{arrayFormat:"repeat",skipNulls:!0,charset:"utf-8"}),responseType:"json",validateStatus:()=>!0})),p(this,d).interceptors.request.use(r=>{const c=m?.();c&&(r.headers.Authorization=`Bearer ${c}`);const{url:o}=r;return o&&E.test(o)&&(r.url=o.replace(E,(n,y)=>{const v=r.params?.[y];if(l.isNullish(v))throw new Error(`Path parameter ${y} is nil`);return v})),r}),p(this,d).interceptors.response.use(async r=>{const{code:c,message:o}=r.data;if(c===u)return r;throw c===w?await g?.():c===f?(await k?.("登录已失效"),await g?.()):c===i?(await C?.(`${o},请联系管理员为您开通`),await h?.()):await C?.(o),new l.VefError(c,o)},r=>{if(r instanceof R.CanceledError)return Promise.reject(r);const{response:c,message:o}=r;if(c?.data){const n=`处理请求响应信息异常:${o??"无"}`;return Promise.reject(new l.VefError(c.status,n))}else{let n=o??(l.isString(r)?r:"");return n==="Network Error"?n="接口连接异常可能原因:网络不通或存在跨域问题。":n.includes("timeout")?n="接口请求超时":n.includes("Request failed with status code")?n=`接口状态码异常:${o.substring(o.length-3)}`:n="接口未知异常",j?.(n),Promise.reject(new l.VefError(-1,n))}})}async get(a,e){return(await p(this,d).get(a,{params:e?.params,headers:e?.headers,signal:e?.signal})).data}async post(a,e,t){return(await p(this,d).post(a,e,{params:t?.params,headers:t?.headers,signal:t?.signal})).data}async put(a,e,t){return(await p(this,d).put(a,e,{params:t?.params,headers:t?.headers,signal:t?.signal})).data}async delete(a,e){return(await p(this,d).delete(a,{params:e?.params,headers:e?.headers,signal:e?.signal})).data}async upload(a,e,t){return(await p(this,d).postForm(a,e,{params:t?.params,headers:t?.headers,signal:t?.signal,onUploadProgress:l.isFunction(t?.onProgress)?m=>{const u=m.lengthComputable?m.total??0:0,{loaded:w}=m,i=Math.round(w/u*100);t.onProgress?.(i)}:void 0})).data}async download(a,e){const{data:t,headers:m}=await p(this,d).get(a,{params:e?.params,headers:e?.headers,responseType:"blob",onDownloadProgress:l.isFunction(e?.onProgress)?i=>{const f=i.lengthComputable?i.total??0:0,{loaded:g}=i,h=Math.round(g/f*100);e.onProgress?.(h)}:void 0});let u=null;try{u=JSON.parse(await t.text())}catch{}if(u&&u.code!==0)throw new l.VefError(u.code,u.message);const w=m.get("content-disposition");if(l.isString(w)){const i=/filename[^;=\n]*=(?<name>(?<quote>['"]).*?\2|[^;\n]*)/.exec(w);if(i&&i.groups){const{name:f}=i.groups,g=decodeURIComponent(f),h=document.createElement("a");h.href=URL.createObjectURL(t),h.download=l.isFunction(e?.fileName)?e.fileName(g):e?.fileName??g,h.click(),URL.revokeObjectURL(h.href)}}}}d=new WeakMap;function S(s){return Object.freeze(new P(s))}exports.RequestClient=P,exports.createRequestClient=S;
@@ -1,2 +0,0 @@
1
- "use strict";
2
- "use strict";var n=require("@vef-framework/shared"),r=require("react");const u=r.createContext(null),o=({permissionChecker:e,children:s})=>{const i=r.useMemo(()=>({checkPermission:t=>e?n.isString(t)?e(t):e(t.key):!0}),[e]);return r.createElement(u.Provider,{value:i},s)};function c(){const e=r.useContext(u);if(e===null)throw new n.VefError(-1,"useAuthContext must be used within a AuthContextProvider");return e}exports.AuthContextProvider=o,exports.useAuthContext=c;
@@ -1,2 +0,0 @@
1
- "use strict";
2
- "use strict";var t=require("./auth-context.cjs");exports.AuthContextProvider=t.AuthContextProvider,exports.useAuthContext=t.useAuthContext;
@@ -1,2 +0,0 @@
1
- "use strict";
2
- "use strict";var N=require("./helpers.cjs");function L(Q){let W;const k=new Set,i=function(t,e){return typeof t=="function"?t(e):t},$=[{"&&":(t,e,n)=>i(t,n)&&i(e,n),"||":(t,e,n)=>i(t,n)||i(e,n)},{"===":(t,e,n)=>i(t,n)===i(e,n),"!==":(t,e,n)=>i(t,n)!==i(e,n),"==":(t,e,n)=>i(t,n)==i(e,n),"!=":(t,e,n)=>i(t,n)!=i(e,n),">=":(t,e,n)=>i(t,n)>=i(e,n),"<=":(t,e,n)=>i(t,n)<=i(e,n),">":(t,e,n)=>i(t,n)>i(e,n),"<":(t,e,n)=>i(t,n)<i(e,n)},{"+":(t,e,n)=>i(t,n)+i(e,n),"-":(t,e,n)=>i(t,n)-i(e,n)},{"*":(t,e,n)=>i(t,n)*i(e,n),"/":(t,e,n)=>i(t,n)/i(e,n),"%":(t,e,n)=>i(t,n)%i(e,n)}],w=$.reduce((t,e)=>t.concat(Object.keys(e)),[]),R=new Set(w.map(t=>t.charAt(0)));function S(t,e,n,a){const c=t.filter(r=>r.startsWith(e));return c.length?c.find(r=>a.length>=n+r.length&&a.substring(n,n+r.length)===r?r:!1):!1}function x(t,e,n=1){let a=n?e.substring(t+1).trim():e.substring(0,t).trim();if(!a.length)return-1;if(!n){const r=a.split("").reverse(),o=r.findIndex(s=>R.has(s));a=r.slice(o).join("")}const[c]=a;return $.findIndex(r=>{const o=Object.keys(r);return!!S(o,c,0,a)})}function T(t,e){let n="";const{length:a}=e;let c=0;for(let r=t;r<a;r++){const o=e.charAt(r);if(o==="(")c++;else if(o===")")c--;else if(c===0&&o===" ")continue;if(c===0&&S(w,o,r,e))return[n,r-1];n+=o}return[n,e.length-1]}function I(t,e=0){const n=$[e],{length:a}=t,c=Object.keys(n);let r=0,o=!1,s=null,u="",h=null,d,m,l="",g="",y="",C=0;const v=(f,b)=>{f?g+=b:u+=b};for(let f=0;f<a;f++)if(m=l,l=t.charAt(f),(l==="'"||l==='"')&&m!=="\\"&&(r===0&&!o||r&&!y)){r?y=l:o=l,v(r,l);continue}else if(o&&(l!==o||m==="\\")||y&&(l!==y||m==="\\")){v(r,l);continue}else if(o===l){o=!1,v(r,l);continue}else if(y===l){y=!1,v(r,l);continue}else{if(l===" ")continue;if(l==="(")r===0?C=f:g+=l,r++;else if(l===")")if(r--,r===0){const b=typeof u=="string"&&u.startsWith("$")?u:void 0,F=b&&t.charAt(f+1)===".";let A="";F&&([A,f]=T(f+2,t));const O=s?e:x(C,t,0),j=x(f,t);O===-1&&j===-1?(u=p(g,-1,b,A),typeof u=="string"&&(u=g)):s&&(O>=j||j===-1)&&e===O?(h=s.bind(null,p(g,-1,b,A)),s=null,u=""):j>O&&e===j?u=p(g,-1,b,A):u+=`(${g})${F?`.${A}`:""}`,g=""}else g+=l;else if(r===0&&(d=S(c,l,f,t))){f===0&&console.error(103,[d,t]),f+=d.length-1,f===t.length-1&&console.error(104,[d,t]),s?u&&(h=s.bind(null,p(u,e)),s=n[d].bind(null,h),u=""):h?(s=n[d].bind(null,p(h,e)),h=null):(s=n[d].bind(null,p(u,e)),u="");continue}else v(r,l)}return u&&s&&(s=s.bind(null,p(u,e))),s=!s&&h?h:s,!s&&u&&(s=(f,b)=>typeof f=="function"?f(b):f,s=s.bind(null,p(u,e))),!s&&!u&&console.error(105,t),s}function p(t,e,n,a){if(n){const c=p(n,$.length);let r,o=a?L(`$${a}`):!1;if(typeof c=="function"){const s=N.parseArgs(String(t)).map(u=>p(u,-1));return u=>{const h=c(u);return typeof h!="function"?(console.warn(150,n),h):(r=h(...s.map(d=>typeof d=="function"?d(u):d)),o&&(o=o.provide(d=>{const m=W(d);return d.reduce((l,g)=>{if(g===a||a?.startsWith(`${g}(`)){const y=N.getAt(r,g);l[g]=()=>y}else l[g]=m[g];return l},{})})),o?o():r)}}}else if(typeof t=="string"){if(t==="true")return!0;if(t==="false")return!1;if(t==="undefined")return;if(N.isQuotedString(t))return N.rmEscapes(t.substring(1,t.length-1));if(!Number.isNaN(+t))return Number(t);if(e<$.length-1)return I(t,e+1);if(t.startsWith("$")){const c=t.substring(1);return k.add(c),function(r){return c in r?r[c]():void 0}}return t}return t}const E=I(Q),z=Array.from(k);function q(t){return W=t,Object.assign(E.bind(null,t(z)),{provide:q})}return Object.assign(E,{provide:q})}exports.compile=L;
@@ -1,2 +0,0 @@
1
- "use strict";
2
- "use strict";function c(t,e){return Object.hasOwn(t,e)}function l(t,e){if(!t||typeof t!="object")return null;const n=e.split(".");let s=t;for(const r in n){const o=n[r];if(c(s,o)&&(s=s[o]),+r===n.length-1)return s;if(!s||typeof s!="object")return null}return null}function f(t){if(t[0]!=='"'&&t[0]!=="'"||t[0]!==t[t.length-1])return!1;const[e]=t;for(let n=1;n<t.length;n++)if(t[n]===e&&(n===1||t[n-1]!=="\\")&&n!==t.length-1)return!1;return!0}function h(t){const e=[];let n="",s=0,r="",o="";for(let i=0;i<t.length;i++){const u=t.charAt(i);u===r&&o!=="\\"?r="":(u==="'"||u==='"')&&!r&&o!=="\\"?r=u:u==="("&&!r?s++:u===")"&&!r&&s--,u===","&&!r&&s===0?(e.push(n),n=""):(u!==" "||r)&&(n+=u),o=u}return n&&e.push(n),e}function g(t){if(!t.length)return"";let e="",n="";for(let s=0;s<t.length;s++){const r=t.charAt(s);(r!=="\\"||n==="\\")&&(e+=r),n=r}return e}exports.getAt=l,exports.has=c,exports.isQuotedString=f,exports.parseArgs=h,exports.rmEscapes=g;
package/cjs/index.cjs DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- "use strict";require("./api/index.cjs"),require("./auth/index.cjs");var i=require("./expr/compiler.cjs"),e=require("./api/api-client.cjs"),u=require("@tanstack/react-query"),r=require("./api/api-context.cjs"),t=require("./auth/auth-context.cjs");exports.compile=i.compile,exports.ApiClient=e.ApiClient,exports.createApiClient=e.createApiClient,Object.defineProperty(exports,"useQueryErrorResetBoundary",{enumerable:!0,get:function(){return u.useQueryErrorResetBoundary}}),exports.ApiContextProvider=r.ApiContextProvider,exports.useApiContext=r.useApiContext,exports.AuthContextProvider=t.AuthContextProvider,exports.useAuthContext=t.useAuthContext;
@@ -1,2 +0,0 @@
1
- "use strict";
2
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});function r(){const e=[];let u=0;const s=t=>e.push(t),c=t=>{const n=e[u];return typeof n=="function"?n(t,i=>(u++,c(i))):(u=0,t)};return s.dispatch=c,s.unshift=t=>e.unshift(t),s.remove=t=>{const n=e.indexOf(t);n>-1&&e.splice(n,1)},s}exports.default=r;
@@ -1,2 +0,0 @@
1
- "use strict";
2
- import{useQuery as E,keepPreviousData as K,useSuspenseQuery as I,useMutation as R,useIsFetching as x,useIsMutating as C,QueryClientProvider as O}from"@tanstack/react-query";import{createElement as W}from"react";import{createQueryClient as j}from"./query-client.js";import{createRequestClient as z}from"./request-client.js";var L=Object.defineProperty,F=r=>{throw TypeError(r)},T=(r,e,i)=>e in r?L(r,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):r[e]=i,m=(r,e,i)=>T(r,typeof e!="symbol"?e+"":e,i),w=(r,e,i)=>e.has(r)||F("Cannot "+i),n=(r,e,i)=>(w(r,e,"read from private field"),i?i.call(r):e.get(r)),A=(r,e,i)=>e.has(r)?F("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(r):e.set(r,i),o=(r,e,i,t)=>(w(r,e,"write to private field"),t?t.call(r,i):e.set(r,i),i),f=(r,e,i)=>(w(r,e,"access private method"),i),c,y,D,h,g,k,M,P,q;class S{constructor(e){this.options=e,A(this,g),m(this,"useApiQuery"),m(this,"useSuspenseApiQuery"),m(this,"useApiMutation"),m(this,"useIsFetching"),m(this,"useIsMutating"),m(this,"QueryClientProvider"),A(this,c),A(this,y),A(this,D),A(this,h),o(this,c,j(e)),o(this,y,z(e)),o(this,D,{get:async(t,s)=>{const a=n(this,h);return o(this,h,void 0),await n(this,y).get(t,{...s,signal:a})},post:async(t,s,a)=>{const u=n(this,h);return o(this,h,void 0),await n(this,y).post(t,s,{...a,signal:u})},put:async(t,s,a)=>{const u=n(this,h);return o(this,h,void 0),await n(this,y).put(t,s,{...a,signal:u})},delete:async(t,s)=>{const a=n(this,h);return o(this,h,void 0),await n(this,y).delete(t,{...s,signal:a})},upload:async(t,s,a)=>{const u=n(this,h);return o(this,h,void 0),await n(this,y).upload(t,s,{...a,signal:u})},download:async(t,s)=>{const a=n(this,h);return o(this,h,void 0),await n(this,y).download(t,{...s,signal:a})}});const i=this;this.useApiQuery=function(t,s,a){var u;const{keepPreviousData:p,placeholderData:Q,initialData:l,...v}=a??{},d=E({queryKey:[t.key,s],queryFn:({signal:b})=>t(s,{signal:b}),select:f(i,g,k),placeholderData:Q??p===!0?K:void 0,initialData:l?{code:0,message:"ok",data:l}:void 0,...v});return f(u=i,g,P).call(u,d)},this.useSuspenseApiQuery=function(t,s,a){const{keepPreviousData:u,initialData:p,...Q}=a??{},{data:l,refetch:v}=I({queryKey:[t.key,s],queryFn:({signal:d})=>t(s,{signal:d}),select:f(i,g,k),initialData:p?{code:0,message:"ok",data:p}:void 0,...Q});return{data:l,refetch:f(this,g,M).call(this,v)}},this.useApiMutation=function(t){const{isPending:s,isIdle:a,isError:u,isSuccess:p,error:Q,data:l,mutateAsync:v}=R({mutationKey:[t.key],mutationFn:d=>t(d)});return{mutate:async d=>await v(d),isPending:s,isIdle:a,isError:u,isSuccess:p,message:l?.message,error:Q??void 0,data:l?.data}},this.useIsFetching=function(t,s){return x({queryKey:arguments.length>1?[t,s]:[t],type:"active",exact:!1})>0},this.useIsMutating=function(t){return C({mutationKey:[t],exact:!1})>0},this.QueryClientProvider=function({children:t}){return W(O,{client:n(i,c)},t)}}async fetchApiQuery(e,i,t){const{initialData:s,...a}=t??{};return(await n(this,c).fetchQuery({queryKey:[e.key,i],queryFn:({signal:u})=>e(i,{signal:u}),initialData:s?{code:0,message:"ok",data:s}:void 0,...a})).data}createQueryApi(e,i){const t=f(this,g,q).call(this,e,i);return t.useQuery=this.useApiQuery.bind(this,t),t.useSuspenseQuery=this.useSuspenseApiQuery.bind(this,t),t.fetchQuery=this.fetchApiQuery.bind(this,t),t.getQueryData=this.getApiQueryData.bind(this,e),t.getQueriesData=this.getApiQueriesData.bind(this,e),t.setQueryData=(s,a)=>this.setApiQueryData(s,e,a),t.ensureQueryData=this.ensureApiQueryData.bind(this,t),t.removeQueries=this.removeApiQueries.bind(this,e),t.invalidateQueries=this.invalidateApiQueries.bind(this,e),t.resetQueries=this.resetApiQueries.bind(this,e),t.refetchQueries=this.refetchApiQueries.bind(this,e),t.cancelQueries=this.cancelApiQueries.bind(this,e),t.isFetching=this.isFetching.bind(this,e),t.useIsFetching=this.useIsFetching.bind(void 0,e),Object.freeze(t)}createMutationApi(e,i,t=[]){const s=f(this,g,q).call(this,e,i);return s.relatedQueries=Object.freeze(t),s.useMutation=this.useApiMutation.bind(this,s),s.refetchRelatedQueries=function(){return Promise.all(t.map(a=>a.refetchQueries()))},s.invalidateRelatedQueries=function(){return Promise.all(t.map(a=>a.invalidateQueries()))},s.isMutating=this.isMutating.bind(this,e),s.useIsMutating=this.useIsMutating.bind(void 0,e),Object.freeze(s)}getApiQueryData(e,i){return n(this,c).getQueryData(arguments.length>1?[e,i]:[e])}getApiQueriesData(e,i){return n(this,c).getQueriesData({queryKey:arguments.length>1?[e,i]:[e],type:"active",exact:!1})}setApiQueryData(e,i,t){n(this,c).setQueryData(arguments.length>2?[i,t]:[i],e)}async ensureApiQueryData(e,i,t){const{initialData:s,...a}=t??{};return(await n(this,c).ensureQueryData({queryKey:[e.key,i],queryFn:({signal:u})=>e(i,{signal:u}),initialData:s?{code:0,message:"ok",data:s}:void 0,...a,revalidateIfStale:!0})).data}removeApiQueries(e,i){n(this,c).removeQueries({type:"all",exact:!1,queryKey:arguments.length>1?[e,i]:[e]})}invalidateApiQueries(e,i){return n(this,c).invalidateQueries({queryKey:arguments.length>1?[e,i]:[e],type:"all",exact:!1,stale:!1,refetchType:"active"},{throwOnError:!1,cancelRefetch:!1})}resetApiQueries(e,i){return n(this,c).resetQueries({queryKey:arguments.length>1?[e,i]:[e],type:"active",exact:!1},{cancelRefetch:!0,throwOnError:!1})}refetchApiQueries(e,i){return n(this,c).refetchQueries({queryKey:arguments.length>1?[e,i]:[e],type:"active",exact:!1},{throwOnError:!1,cancelRefetch:!1})}cancelApiQueries(e,i){return n(this,c).cancelQueries({queryKey:arguments.length>1?[e,i]:[e],type:"active",exact:!1},{revert:!0,silent:!0})}isFetching(e,i){return n(this,c).isFetching({queryKey:arguments.length>1?[e,i]:[e],type:"active",exact:!1})>0}isMutating(e){return n(this,c).isMutating({mutationKey:[e],exact:!1})>0}}c=new WeakMap,y=new WeakMap,D=new WeakMap,h=new WeakMap,g=new WeakSet,k=function(r){return r.data},M=function(r){return async e=>{const i=await r(e);return{isSuccess:i.isSuccess,isError:i.isError,error:i.error,data:i.data}}},P=function({isPending:r,isFetching:e,isLoading:i,isRefetching:t,isSuccess:s,isPlaceholderData:a,isError:u,isLoadingError:p,isRefetchError:Q,isStale:l,error:v,data:d,refetch:b}){return{isPending:r,isSuccess:s,isError:u,isLoadingError:p,isRefetchError:Q,isLoading:i,isFetching:e,isRefetching:t,isPlaceholderData:a,isStale:l,error:v??void 0,data:d,refetch:f(this,g,M).call(this,b)}},q=function(r,e){const i=e(n(this,D)),t=async(s,a)=>(o(this,h,a?.signal),await i(s));return t.key=r,t};function B(r){return Object.freeze(new S(r))}export{S as ApiClient,B as createApiClient};
@@ -1,2 +0,0 @@
1
- "use strict";
2
- import{VefError as g}from"@vef-framework/shared";import{createContext as l,useMemo as b,createElement as s,useContext as f}from"react";const o=l(null),h=({client:e,dataDictionaryApi:r,loginApi:n,logoutApi:u,fetchAuthenticatedUserApi:a,children:p})=>{const A=b(()=>{const c=e.createQueryApi("_vefStubQueryApi",()=>i=>Promise.resolve({code:0,message:"ok",data:i})),d=e.createQueryApi("_vefAsyncFnQueryApi",()=>async({args:i,fn:t})=>({code:0,message:"ok",data:await t(...i)})),Q=e.createMutationApi("_vefStubMutationApi",()=>i=>Promise.resolve({code:0,message:"ok",data:i})),y=e.createMutationApi("_vefAsyncFnMutationApi",()=>async({args:i,fn:t})=>({code:0,message:"ok",data:await t(...i)}));return Object.freeze({useApiQuery:e.useApiQuery,useSuspenseApiQuery:e.useSuspenseApiQuery,useApiMutation:e.useApiMutation,useIsFetching:e.useIsFetching,useIsMutating:e.useIsMutating,fetchApiQuery:e.fetchApiQuery.bind(e),createQueryApi:e.createQueryApi.bind(e),createMutationApi:e.createMutationApi.bind(e),getApiQueryData:e.getApiQueryData.bind(e),getApiQueriesData:e.getApiQueriesData.bind(e),setApiQueryData:e.setApiQueryData.bind(e),ensureApiQueryData:e.ensureApiQueryData.bind(e),removeApiQueries:e.removeApiQueries.bind(e),invalidateApiQueries:e.invalidateApiQueries.bind(e),resetApiQueries:e.resetApiQueries.bind(e),refetchApiQueries:e.refetchApiQueries.bind(e),cancelApiQueries:e.cancelApiQueries.bind(e),isFetching:e.isFetching.bind(e),isMutating:e.isMutating.bind(e),stubQueryApi:c,asyncFnQueryApi:d,stubMutationApi:Q,asyncFnMutationApi:y,dataDictionaryApi:r,loginApi:n,logoutApi:u,fetchAuthenticatedUserApi:a})},[e,r,n,u,a]);return s(o.Provider,{value:A},s(e.QueryClientProvider,{},p))};function m(){const e=f(o);if(e===null)throw new g(-1,"Api context not found: Please ensure useApiContext is called within an ApiContextProvider");return e}export{h as ApiContextProvider,m as useApiContext};
package/esm/api/index.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- import{ApiClient as t,createApiClient as o}from"./api-client.js";import{ApiContextProvider as p,useApiContext as n}from"./api-context.js";import{useQueryErrorResetBoundary as u}from"@tanstack/react-query";export{t as ApiClient,p as ApiContextProvider,o as createApiClient,n as useApiContext,u as useQueryErrorResetBoundary};
@@ -1,2 +0,0 @@
1
- "use strict";
2
- import{QueryClient as n}from"@tanstack/react-query";function o(e){const r=e?.staleTime??1/0,t=e?.gcTime??10*60*1e3;return new n({defaultOptions:{queries:{networkMode:"always",staleTime:r,gcTime:t,retry:!1,structuralSharing:!0,throwOnError:!1,refetchOnMount:!1,refetchOnReconnect:!0,refetchOnWindowFocus:!0},mutations:{networkMode:"always",gcTime:r,retry:!1,throwOnError:!1}}})}export{o as createQueryClient};
@@ -1,2 +0,0 @@
1
- "use strict";
2
- import{isNullish as q,VefError as f,isString as v,isFunction as y}from"@vef-framework/shared";import M,{CanceledError as T}from"axios";import x from"qs";var P=s=>{throw TypeError(s)},j=(s,a,e)=>a.has(s)||P("Cannot "+e),u=(s,a,e)=>(j(s,a,"read from private field"),e?e.call(s):a.get(s)),z=(s,a,e)=>a.has(s)?P("Cannot add the same private member more than once"):a instanceof WeakSet?a.add(s):a.set(s,e),L=(s,a,e,t)=>(j(s,a,"write to private field"),t?t.call(s,e):a.set(s,e),e),d;const k=/\{\w+\}/;class U{constructor(a){this.options=a,z(this,d);const{baseUrl:e,timeout:t,getAccessToken:h,successCode:l=0,unauthorizedCode:g=1e3,accessDeniedCode:i=1002,tokenExpiredCode:w=1001,onUnauthorized:m,onAccessDenied:p,onErrorMessage:E,onInfoMessage:N,onWarningMessage:C}=a;L(this,d,M.create({baseURL:e,timeout:t??1e3*30,headers:{"Content-Type":"application/json"},paramsSerializer:r=>x.stringify(r,{arrayFormat:"repeat",skipNulls:!0,charset:"utf-8"}),responseType:"json",validateStatus:()=>!0})),u(this,d).interceptors.request.use(r=>{const c=h?.();c&&(r.headers.Authorization=`Bearer ${c}`);const{url:o}=r;return o&&k.test(o)&&(r.url=o.replace(k,(n,b)=>{const R=r.params?.[b];if(q(R))throw new Error(`Path parameter ${b} is nil`);return R})),r}),u(this,d).interceptors.response.use(async r=>{const{code:c,message:o}=r.data;if(c===l)return r;throw c===g?await m?.():c===w?(await N?.("登录已失效"),await m?.()):c===i?(await C?.(`${o},请联系管理员为您开通`),await p?.()):await C?.(o),new f(c,o)},r=>{if(r instanceof T)return Promise.reject(r);const{response:c,message:o}=r;if(c?.data){const n=`处理请求响应信息异常:${o??"无"}`;return Promise.reject(new f(c.status,n))}else{let n=o??(v(r)?r:"");return n==="Network Error"?n="接口连接异常可能原因:网络不通或存在跨域问题。":n.includes("timeout")?n="接口请求超时":n.includes("Request failed with status code")?n=`接口状态码异常:${o.substring(o.length-3)}`:n="接口未知异常",E?.(n),Promise.reject(new f(-1,n))}})}async get(a,e){return(await u(this,d).get(a,{params:e?.params,headers:e?.headers,signal:e?.signal})).data}async post(a,e,t){return(await u(this,d).post(a,e,{params:t?.params,headers:t?.headers,signal:t?.signal})).data}async put(a,e,t){return(await u(this,d).put(a,e,{params:t?.params,headers:t?.headers,signal:t?.signal})).data}async delete(a,e){return(await u(this,d).delete(a,{params:e?.params,headers:e?.headers,signal:e?.signal})).data}async upload(a,e,t){return(await u(this,d).postForm(a,e,{params:t?.params,headers:t?.headers,signal:t?.signal,onUploadProgress:y(t?.onProgress)?h=>{const l=h.lengthComputable?h.total??0:0,{loaded:g}=h,i=Math.round(g/l*100);t.onProgress?.(i)}:void 0})).data}async download(a,e){const{data:t,headers:h}=await u(this,d).get(a,{params:e?.params,headers:e?.headers,responseType:"blob",onDownloadProgress:y(e?.onProgress)?i=>{const w=i.lengthComputable?i.total??0:0,{loaded:m}=i,p=Math.round(m/w*100);e.onProgress?.(p)}:void 0});let l=null;try{l=JSON.parse(await t.text())}catch{}if(l&&l.code!==0)throw new f(l.code,l.message);const g=h.get("content-disposition");if(v(g)){const i=/filename[^;=\n]*=(?<name>(?<quote>['"]).*?\2|[^;\n]*)/.exec(g);if(i&&i.groups){const{name:w}=i.groups,m=decodeURIComponent(w),p=document.createElement("a");p.href=URL.createObjectURL(t),p.download=y(e?.fileName)?e.fileName(m):e?.fileName??m,p.click(),URL.revokeObjectURL(p.href)}}}}d=new WeakMap;function O(s){return Object.freeze(new U(s))}export{U as RequestClient,O as createRequestClient};
@@ -1,2 +0,0 @@
1
- "use strict";
2
- import{isString as s,VefError as i}from"@vef-framework/shared";import{createContext as u,useMemo as c,createElement as h,useContext as m}from"react";const r=u(null),C=({permissionChecker:e,children:n})=>{const o=c(()=>({checkPermission:t=>e?s(t)?e(t):e(t.key):!0}),[e]);return h(r.Provider,{value:o},n)};function a(){const e=m(r);if(e===null)throw new i(-1,"useAuthContext must be used within a AuthContextProvider");return e}export{C as AuthContextProvider,a as useAuthContext};
package/esm/auth/index.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- import{AuthContextProvider as o,useAuthContext as r}from"./auth-context.js";export{o as AuthContextProvider,r as useAuthContext};
@@ -1,2 +0,0 @@
1
- "use strict";
2
- import{parseArgs as z,getAt as B,isQuotedString as D,rmEscapes as G}from"./helpers.js";function L(Q){let S;const W=new Set,i=function(t,e){return typeof t=="function"?t(e):t},$=[{"&&":(t,e,n)=>i(t,n)&&i(e,n),"||":(t,e,n)=>i(t,n)||i(e,n)},{"===":(t,e,n)=>i(t,n)===i(e,n),"!==":(t,e,n)=>i(t,n)!==i(e,n),"==":(t,e,n)=>i(t,n)==i(e,n),"!=":(t,e,n)=>i(t,n)!=i(e,n),">=":(t,e,n)=>i(t,n)>=i(e,n),"<=":(t,e,n)=>i(t,n)<=i(e,n),">":(t,e,n)=>i(t,n)>i(e,n),"<":(t,e,n)=>i(t,n)<i(e,n)},{"+":(t,e,n)=>i(t,n)+i(e,n),"-":(t,e,n)=>i(t,n)-i(e,n)},{"*":(t,e,n)=>i(t,n)*i(e,n),"/":(t,e,n)=>i(t,n)/i(e,n),"%":(t,e,n)=>i(t,n)%i(e,n)}],k=$.reduce((t,e)=>t.concat(Object.keys(e)),[]),R=new Set(k.map(t=>t.charAt(0)));function N(t,e,n,a){const c=t.filter(r=>r.startsWith(e));return c.length?c.find(r=>a.length>=n+r.length&&a.substring(n,n+r.length)===r?r:!1):!1}function w(t,e,n=1){let a=n?e.substring(t+1).trim():e.substring(0,t).trim();if(!a.length)return-1;if(!n){const r=a.split("").reverse(),l=r.findIndex(s=>R.has(s));a=r.slice(l).join("")}const[c]=a;return $.findIndex(r=>{const l=Object.keys(r);return!!N(l,c,0,a)})}function T(t,e){let n="";const{length:a}=e;let c=0;for(let r=t;r<a;r++){const l=e.charAt(r);if(l==="(")c++;else if(l===")")c--;else if(c===0&&l===" ")continue;if(c===0&&N(k,l,r,e))return[n,r-1];n+=l}return[n,e.length-1]}function x(t,e=0){const n=$[e],{length:a}=t,c=Object.keys(n);let r=0,l=!1,s=null,o="",h=null,d,m,u="",g="",y="",C=0;const A=(f,b)=>{f?g+=b:o+=b};for(let f=0;f<a;f++)if(m=u,u=t.charAt(f),(u==="'"||u==='"')&&m!=="\\"&&(r===0&&!l||r&&!y)){r?y=u:l=u,A(r,u);continue}else if(l&&(u!==l||m==="\\")||y&&(u!==y||m==="\\")){A(r,u);continue}else if(l===u){l=!1,A(r,u);continue}else if(y===u){y=!1,A(r,u);continue}else{if(u===" ")continue;if(u==="(")r===0?C=f:g+=u,r++;else if(u===")")if(r--,r===0){const b=typeof o=="string"&&o.startsWith("$")?o:void 0,F=b&&t.charAt(f+1)===".";let j="";F&&([j,f]=T(f+2,t));const O=s?e:w(C,t,0),v=w(f,t);O===-1&&v===-1?(o=p(g,-1,b,j),typeof o=="string"&&(o=g)):s&&(O>=v||v===-1)&&e===O?(h=s.bind(null,p(g,-1,b,j)),s=null,o=""):v>O&&e===v?o=p(g,-1,b,j):o+=`(${g})${F?`.${j}`:""}`,g=""}else g+=u;else if(r===0&&(d=N(c,u,f,t))){f===0&&console.error(103,[d,t]),f+=d.length-1,f===t.length-1&&console.error(104,[d,t]),s?o&&(h=s.bind(null,p(o,e)),s=n[d].bind(null,h),o=""):h?(s=n[d].bind(null,p(h,e)),h=null):(s=n[d].bind(null,p(o,e)),o="");continue}else A(r,u)}return o&&s&&(s=s.bind(null,p(o,e))),s=!s&&h?h:s,!s&&o&&(s=(f,b)=>typeof f=="function"?f(b):f,s=s.bind(null,p(o,e))),!s&&!o&&console.error(105,t),s}function p(t,e,n,a){if(n){const c=p(n,$.length);let r,l=a?L(`$${a}`):!1;if(typeof c=="function"){const s=z(String(t)).map(o=>p(o,-1));return o=>{const h=c(o);return typeof h!="function"?(console.warn(150,n),h):(r=h(...s.map(d=>typeof d=="function"?d(o):d)),l&&(l=l.provide(d=>{const m=S(d);return d.reduce((u,g)=>{if(g===a||a?.startsWith(`${g}(`)){const y=B(r,g);u[g]=()=>y}else u[g]=m[g];return u},{})})),l?l():r)}}}else if(typeof t=="string"){if(t==="true")return!0;if(t==="false")return!1;if(t==="undefined")return;if(D(t))return G(t.substring(1,t.length-1));if(!Number.isNaN(+t))return Number(t);if(e<$.length-1)return x(t,e+1);if(t.startsWith("$")){const c=t.substring(1);return W.add(c),function(r){return c in r?r[c]():void 0}}return t}return t}const I=x(Q),q=Array.from(W);function E(t){return S=t,Object.assign(I.bind(null,t(q)),{provide:E})}return Object.assign(I,{provide:E})}export{L as compile};
@@ -1,2 +0,0 @@
1
- "use strict";
2
- function i(t,u){return Object.hasOwn(t,u)}function s(t,u){if(!t||typeof t!="object")return null;const n=u.split(".");let o=t;for(const r in n){const l=n[r];if(i(o,l)&&(o=o[l]),+r===n.length-1)return o;if(!o||typeof o!="object")return null}return null}function f(t){if(t[0]!=='"'&&t[0]!=="'"||t[0]!==t[t.length-1])return!1;const[u]=t;for(let n=1;n<t.length;n++)if(t[n]===u&&(n===1||t[n-1]!=="\\")&&n!==t.length-1)return!1;return!0}function h(t){const u=[];let n="",o=0,r="",l="";for(let c=0;c<t.length;c++){const e=t.charAt(c);e===r&&l!=="\\"?r="":(e==="'"||e==='"')&&!r&&l!=="\\"?r=e:e==="("&&!r?o++:e===")"&&!r&&o--,e===","&&!r&&o===0?(u.push(n),n=""):(e!==" "||r)&&(n+=e),l=e}return n&&u.push(n),u}function g(t){if(!t.length)return"";let u="",n="";for(let o=0;o<t.length;o++){const r=t.charAt(o);(r!=="\\"||n==="\\")&&(u+=r),n=r}return u}export{s as getAt,i as has,f as isQuotedString,h as parseArgs,g as rmEscapes};
package/esm/index.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- import"./api/index.js";import"./auth/index.js";import{compile as i}from"./expr/compiler.js";import{ApiClient as x,createApiClient as m}from"./api/api-client.js";import{useQueryErrorResetBoundary as n}from"@tanstack/react-query";import{ApiContextProvider as A,useApiContext as C}from"./api/api-context.js";import{AuthContextProvider as c,useAuthContext as d}from"./auth/auth-context.js";export{x as ApiClient,A as ApiContextProvider,c as AuthContextProvider,i as compile,m as createApiClient,C as useApiContext,d as useAuthContext,n as useQueryErrorResetBoundary};
@@ -1,2 +0,0 @@
1
- "use strict";
2
- function u(){const n=[];let c=0;const e=t=>n.push(t),i=t=>{const s=n[c];return typeof s=="function"?s(t,o=>(c++,i(o))):(c=0,t)};return e.dispatch=i,e.unshift=t=>n.unshift(t),e.remove=t=>{const s=n.indexOf(t);s>-1&&n.splice(s,1)},e}export{u as default};
@@ -1,203 +0,0 @@
1
- import type { FetchQueryOptions as FetchReactQueryOptions, RefetchOptions, UseQueryOptions as UseReactQueryOptions } from "@tanstack/react-query";
2
- import type { Api, ApiResponse, BiMapperOptional1, ChildrenProps, Except, Mapper, MaybeUndefined, MutationApi, MutationResult, ObjectType, ObjectValue, QueryApi, QueryResult, SuspenseQueryResult, VefError } from "@vef-framework/shared";
3
- import type { FC } from "react";
4
- import type { QueryClientOptions } from "./query-client";
5
- import type { RequestClientOptions, RequestOptions } from "./request-client";
6
- /**
7
- * The request methods.
8
- */
9
- export interface RequestMethods<R = unknown> {
10
- get: <P extends ObjectType = ObjectValue, T = R>(url: string, options?: Except<RequestOptions<P>, "onProgress" | "signal">) => Promise<ApiResponse<T>>;
11
- post: <D, P extends ObjectType = ObjectValue, T = R>(url: string, data?: D, options?: Except<RequestOptions<P>, "onProgress" | "signal">) => Promise<ApiResponse<T>>;
12
- put: <D, P extends ObjectType = ObjectValue, T = R>(url: string, data?: D, options?: Except<RequestOptions<P>, "onProgress" | "signal">) => Promise<ApiResponse<T>>;
13
- delete: <P extends ObjectType = ObjectValue, T = R>(url: string, options?: Except<RequestOptions<P>, "onProgress" | "signal">) => Promise<ApiResponse<T>>;
14
- upload: <R = unknown, P extends ObjectType = ObjectValue>(url: string, data: FormData, options?: RequestOptions<P>) => Promise<ApiResponse<R>>;
15
- download: <P extends ObjectType = ObjectValue>(url: string, options?: RequestOptions<P> & {
16
- fileName?: string | Mapper<string, string>;
17
- }) => Promise<void>;
18
- }
19
- /**
20
- * The API client options.
21
- */
22
- export interface ApiClientOptions extends RequestClientOptions, QueryClientOptions {
23
- }
24
- /**
25
- * The query options.
26
- */
27
- export interface UseQueryOptions<R = unknown> extends Pick<UseReactQueryOptions<ApiResponse<R>, VefError, R>, "staleTime" | "enabled" | "placeholderData" | "refetchInterval" | "refetchIntervalInBackground" | "refetchOnMount" | "refetchOnWindowFocus"> {
28
- /**
29
- * Whether to keep the previous data.
30
- */
31
- keepPreviousData?: boolean;
32
- /**
33
- * The initial data.
34
- */
35
- initialData?: R;
36
- }
37
- /**
38
- * The fetch query options.
39
- */
40
- export interface FetchQueryOptions<R = unknown> extends Pick<FetchReactQueryOptions<ApiResponse<R>, VefError>, "queryKey" | "queryFn" | "staleTime"> {
41
- /**
42
- * The initial data.
43
- */
44
- initialData?: R;
45
- }
46
- export type { RefetchOptions };
47
- /**
48
- * The API client.
49
- */
50
- export declare class ApiClient {
51
- #private;
52
- readonly options: ApiClientOptions;
53
- /**
54
- * The useApiQuery hook.
55
- * These hook functions are doing this because React's Hooks cannot be used in class methods,
56
- * and this approach can bypass the check.
57
- */
58
- readonly useApiQuery: <T = unknown, R = unknown>(queryFn: Readonly<QueryApi<T, R>>, args: T, options?: UseQueryOptions<R>) => QueryResult<R>;
59
- /**
60
- * The useSuspenseApiQuery hook.
61
- */
62
- readonly useSuspenseApiQuery: <T = unknown, R = unknown>(queryFn: Readonly<QueryApi<T, R>>, args: T, options?: Except<UseQueryOptions<R>, "enabled" | "placeholderData">) => SuspenseQueryResult<R>;
63
- /**
64
- * The useApiMutation hook.
65
- * These hook functions are doing this because React's Hooks cannot be used in class methods,
66
- * and this approach can bypass the check.
67
- */
68
- readonly useApiMutation: <T = unknown, R = unknown>(mutationFn: Readonly<MutationApi<T, R>>) => MutationResult<T, R>;
69
- /**
70
- * The useIsFetching hook.
71
- */
72
- readonly useIsFetching: BiMapperOptional1<string, unknown, boolean>;
73
- /**
74
- * The useIsMutating hook.
75
- */
76
- readonly useIsMutating: Mapper<string, boolean>;
77
- /**
78
- * THe QueryClientProvider component.
79
- */
80
- readonly QueryClientProvider: FC<ChildrenProps>;
81
- /**
82
- * Create an API client.
83
- *
84
- * @param options - The options of the API client.
85
- */
86
- constructor(options: ApiClientOptions);
87
- /**
88
- * Fetch the API query.
89
- *
90
- * @param queryFn - The API function.
91
- * @param args - The arguments of the API.
92
- * @param options - The options of the API.
93
- * @returns The API query.
94
- */
95
- fetchApiQuery<T extends ObjectType = ObjectValue, R = unknown>(queryFn: Api<T, R>, args: T, options?: FetchQueryOptions<R>): Promise<R>;
96
- /**
97
- * Create a query API.
98
- *
99
- * @param key - The key of the API.
100
- * @param factory - The factory of the API function.
101
- * @returns The query API.
102
- */
103
- createQueryApi<T = unknown, R = unknown>(key: string, factory: Mapper<RequestMethods<R>, Mapper<T, Promise<ApiResponse<R>>>>): Readonly<QueryApi<T, R>>;
104
- /**
105
- * Create a mutation API.
106
- *
107
- * @param key - The key of the API.
108
- * @param factory - The factory of the API function.
109
- * @param relatedQueries - The related queries.
110
- * @returns The mutation API.
111
- */
112
- createMutationApi<T = unknown, R = unknown>(key: string, factory: Mapper<Except<RequestMethods<R>, "get">, Mapper<T, Promise<ApiResponse<R>>>>, relatedQueries?: Array<Readonly<QueryApi<any, any>>>): Readonly<MutationApi<T, R>>;
113
- /**
114
- * Get the API query data.
115
- *
116
- * @param apiKey - The key of the API.
117
- * @param args - The arguments of the API.
118
- * @returns The API query data.
119
- */
120
- getApiQueryData<T>(apiKey: string, args?: unknown): T | undefined;
121
- /**
122
- * Get the API queries data.
123
- *
124
- * @param apiKey - The key of the API.
125
- * @param args - The arguments of the API.
126
- * @returns The API queries data.
127
- */
128
- getApiQueriesData(apiKey: string, args?: unknown): [readonly unknown[], unknown][];
129
- /**
130
- * Set the API query data.
131
- *
132
- * @param data - The data.
133
- * @param apiKey - The key of the API.
134
- * @param args - The arguments of the API.
135
- */
136
- setApiQueryData<T>(data: MaybeUndefined<T | Mapper<MaybeUndefined<T>, MaybeUndefined<T>>>, apiKey: string, args?: unknown): void;
137
- /**
138
- * Ensure the API query data.
139
- *
140
- * @param queryFn - The API function.
141
- * @param args - The arguments of the API.
142
- * @param options - The options of the API.
143
- * @returns The API query data.
144
- */
145
- ensureApiQueryData<T extends ObjectType = ObjectValue, R = unknown>(queryFn: Api<T, R>, args: T, options?: FetchQueryOptions<R>): Promise<R>;
146
- /**
147
- * Remove the API queries.
148
- *
149
- * @param apiKey - The key of the API.
150
- * @param args - The arguments of the API.
151
- */
152
- removeApiQueries(apiKey: string, args?: unknown): void;
153
- /**
154
- * Invalidate the API queries.
155
- *
156
- * @param apiKey - The key of the API.
157
- * @param args - The arguments of the API.
158
- */
159
- invalidateApiQueries(apiKey: string, args?: unknown): Promise<void>;
160
- /**
161
- * Reset the API queries.
162
- *
163
- * @param apiKey - The key of the API.
164
- * @param args - The arguments of the API.
165
- */
166
- resetApiQueries(apiKey: string, args?: unknown): Promise<void>;
167
- /**
168
- * Refetch the API queries.
169
- *
170
- * @param apiKey - The key of the API.
171
- * @param args - The arguments of the API.
172
- */
173
- refetchApiQueries(apiKey: string, args?: unknown): Promise<void>;
174
- /**
175
- * Cancel the API queries.
176
- *
177
- * @param apiKey - The key of the API.
178
- * @param args - The arguments of the API.
179
- */
180
- cancelApiQueries(apiKey: string, args?: unknown): Promise<void>;
181
- /**
182
- * Check if the API query/queries is fetching.
183
- *
184
- * @param apiKey - The key of the API.
185
- * @param args - The arguments of the API.
186
- * @returns Whether the API query is fetching.
187
- */
188
- isFetching(apiKey: string, args?: unknown): boolean;
189
- /**
190
- * Check if the API mutation is mutating.
191
- *
192
- * @param apiKey - The key of the API.
193
- * @returns Whether the API mutation is mutating.
194
- */
195
- isMutating(apiKey: string): boolean;
196
- }
197
- /**
198
- * Create an API client.
199
- *
200
- * @param options - The options of the API client.
201
- * @returns The API client.
202
- */
203
- export declare function createApiClient(options: ApiClientOptions): Readonly<ApiClient>;
@@ -1,167 +0,0 @@
1
- import type { ChildrenProps, DataDictionaryApi, FetchAuthenticatedUserApi, LoginApi, LogoutApi, MutationApi, QueryApi } from "@vef-framework/shared";
2
- import type { FC } from "react";
3
- import type { ApiClient } from "./api-client";
4
- /**
5
- * The API context provider props.
6
- */
7
- export interface ApiContextProviderProps extends ChildrenProps {
8
- /**
9
- * The API client.
10
- */
11
- client: Readonly<ApiClient>;
12
- /**
13
- * The query API for the data dictionary.
14
- */
15
- dataDictionaryApi?: DataDictionaryApi;
16
- /**
17
- * The login API.
18
- */
19
- loginApi: LoginApi;
20
- /**
21
- * The logout API.
22
- */
23
- logoutApi: LogoutApi;
24
- /**
25
- * The fetch authenticated user API.
26
- */
27
- fetchAuthenticatedUserApi: FetchAuthenticatedUserApi;
28
- }
29
- /**
30
- * The API context.
31
- */
32
- export interface ApiContext {
33
- /**
34
- * The useApiQuery hook.
35
- */
36
- useApiQuery: ApiClient["useApiQuery"];
37
- /**
38
- * The useSuspenseApiQuery hook.
39
- */
40
- useSuspenseApiQuery: ApiClient["useSuspenseApiQuery"];
41
- /**
42
- * The useApiMutation hook.
43
- */
44
- useApiMutation: ApiClient["useApiMutation"];
45
- /**
46
- * The useIsFetching hook.
47
- */
48
- useIsFetching: ApiClient["useIsFetching"];
49
- /**
50
- * The useIsMutating hook.
51
- */
52
- useIsMutating: ApiClient["useIsMutating"];
53
- /**
54
- * The fetchApiQuery function.
55
- */
56
- fetchApiQuery: ApiClient["fetchApiQuery"];
57
- /**
58
- * The create query API function.
59
- */
60
- createQueryApi: ApiClient["createQueryApi"];
61
- /**
62
- * The create mutation API function.
63
- */
64
- createMutationApi: ApiClient["createMutationApi"];
65
- /**
66
- * The get query API data function.
67
- */
68
- getApiQueryData: ApiClient["getApiQueryData"];
69
- /**
70
- * The get query APIs data function.
71
- */
72
- getApiQueriesData: ApiClient["getApiQueriesData"];
73
- /**
74
- * The set query API data function.
75
- */
76
- setApiQueryData: ApiClient["setApiQueryData"];
77
- /**
78
- * The ensure query API data function.
79
- */
80
- ensureApiQueryData: ApiClient["ensureApiQueryData"];
81
- /**
82
- * The remove API queries function.
83
- */
84
- removeApiQueries: ApiClient["removeApiQueries"];
85
- /**
86
- * The invalidate API queries function.
87
- */
88
- invalidateApiQueries: ApiClient["invalidateApiQueries"];
89
- /**
90
- * The reset API queries function.
91
- */
92
- resetApiQueries: ApiClient["resetApiQueries"];
93
- /**
94
- * The refetch API queries function.
95
- */
96
- refetchApiQueries: ApiClient["refetchApiQueries"];
97
- /**
98
- * The cancel API queries function.
99
- */
100
- cancelApiQueries: ApiClient["cancelApiQueries"];
101
- /**
102
- * The is fetching function.
103
- */
104
- isFetching: ApiClient["isFetching"];
105
- /**
106
- * The is mutating function.
107
- */
108
- isMutating: ApiClient["isMutating"];
109
- /**
110
- * The stub query API.
111
- */
112
- stubQueryApi: Readonly<QueryApi<any, any>>;
113
- /**
114
- * The async function query API.
115
- */
116
- asyncFnQueryApi: Readonly<QueryApi<AsyncFnParams, any>>;
117
- /**
118
- * The stub mutation API.
119
- */
120
- stubMutationApi: Readonly<MutationApi<any, any>>;
121
- /**
122
- * The async function mutation API.
123
- */
124
- asyncFnMutationApi: Readonly<MutationApi<AsyncFnParams, any>>;
125
- /**
126
- * The query API for the data dictionary.
127
- */
128
- dataDictionaryApi?: DataDictionaryApi;
129
- /**
130
- * The login API.
131
- */
132
- loginApi: LoginApi;
133
- /**
134
- * The logout API.
135
- */
136
- logoutApi: LogoutApi;
137
- /**
138
- * The fetch authenticated user API.
139
- */
140
- fetchAuthenticatedUserApi: FetchAuthenticatedUserApi;
141
- }
142
- /**
143
- * The async function params.
144
- */
145
- export interface AsyncFnParams {
146
- /**
147
- * The key.
148
- */
149
- key: string;
150
- /**
151
- * The arguments.
152
- */
153
- args: any[];
154
- /**
155
- * The function.
156
- */
157
- fn: (...args: any[]) => Promise<any>;
158
- }
159
- /**
160
- * The API context provider.
161
- */
162
- declare const ApiContextProvider: FC<ApiContextProviderProps>;
163
- /**
164
- * The use API context hook.
165
- */
166
- declare function useApiContext(): Readonly<ApiContext>;
167
- export { ApiContextProvider, useApiContext, };
@@ -1,3 +0,0 @@
1
- export { ApiClient, createApiClient, type ApiClientOptions, type UseQueryOptions as QueryOptions, } from "./api-client";
2
- export * from "./api-context";
3
- export { useQueryErrorResetBoundary } from "@tanstack/react-query";
@@ -1,27 +0,0 @@
1
- import type { VefError } from "@vef-framework/shared";
2
- import { QueryClient } from "@tanstack/react-query";
3
- declare module "@tanstack/react-query" {
4
- interface Register {
5
- defaultError: VefError;
6
- }
7
- }
8
- /**
9
- * The query client options.
10
- */
11
- export interface QueryClientOptions {
12
- /**
13
- * The stale time of the query client.
14
- */
15
- staleTime?: number;
16
- /**
17
- * The garbage collection time of the query client.
18
- */
19
- gcTime?: number;
20
- }
21
- /**
22
- * Create a query client.
23
- *
24
- * @param options - The options of the query client.
25
- * @returns The query client.
26
- */
27
- export declare function createQueryClient(options?: QueryClientOptions): QueryClient;
@@ -1,95 +0,0 @@
1
- import type { ApiResponse, Consumer, Except, Mapper, MaybeNullish, MaybePromise, ObjectType, ObjectValue, Provider } from "@vef-framework/shared";
2
- import type { GenericAbortSignal } from "axios";
3
- /**
4
- * The request client options.
5
- */
6
- export interface RequestClientOptions {
7
- baseUrl: string;
8
- timeout?: number;
9
- getAccessToken?: () => MaybeNullish<string>;
10
- successCode?: number;
11
- unauthorizedCode?: number;
12
- accessDeniedCode?: number;
13
- tokenExpiredCode?: number;
14
- onUnauthorized?: Provider<MaybePromise<void>>;
15
- onAccessDenied?: Provider<MaybePromise<void>>;
16
- onErrorMessage?: Consumer<string>;
17
- onInfoMessage?: Consumer<string>;
18
- onWarningMessage?: Consumer<string>;
19
- }
20
- /**
21
- * The request options.
22
- */
23
- export interface RequestOptions<P extends ObjectType = ObjectValue> {
24
- signal?: GenericAbortSignal;
25
- params?: P;
26
- headers?: Record<string, string | string[]>;
27
- onProgress?: Consumer<number>;
28
- }
29
- /**
30
- * The request client.
31
- */
32
- export declare class RequestClient {
33
- #private;
34
- readonly options: RequestClientOptions;
35
- constructor(options: RequestClientOptions);
36
- /**
37
- * Perform a GET request.
38
- *
39
- * @param url - The url.
40
- * @param options - The request options.
41
- * @returns The response data promise.
42
- */
43
- get<P extends ObjectType = ObjectValue, R = unknown>(url: string, options?: Except<RequestOptions<P>, "onProgress">): Promise<ApiResponse<R>>;
44
- /**
45
- * Perform a POST request.
46
- *
47
- * @param url - The url.
48
- * @param data - The request data.
49
- * @param options - The request options.
50
- * @returns The response data promise.
51
- */
52
- post<D = ObjectValue, R = unknown, P extends ObjectType = ObjectValue>(url: string, data?: D, options?: Except<RequestOptions<P>, "onProgress">): Promise<ApiResponse<R>>;
53
- /**
54
- * Perform a PUT request.
55
- *
56
- * @param url - The url.
57
- * @param data - The request data.
58
- * @param options - The request options.
59
- * @returns The response data promise.
60
- */
61
- put<D = ObjectValue, R = unknown, P extends ObjectType = ObjectValue>(url: string, data?: D, options?: Except<RequestOptions<P>, "onProgress">): Promise<ApiResponse<R>>;
62
- /**
63
- * Perform a DELETE request.
64
- *
65
- * @param url - The url.
66
- * @param options - The request options.
67
- * @returns The response data promise.
68
- */
69
- delete<P extends ObjectType = ObjectValue, R = unknown>(url: string, options?: Except<RequestOptions<P>, "onProgress">): Promise<ApiResponse<R>>;
70
- /**
71
- * Perform a file upload request.
72
- *
73
- * @param url - The url.
74
- * @param data - The file data.
75
- * @param options - The request options.
76
- * @returns The response data promise.
77
- */
78
- upload<R = unknown, P extends ObjectType = ObjectValue>(url: string, data: FormData, options?: RequestOptions<P>): Promise<ApiResponse<R>>;
79
- /**
80
- * Perform a file download request.
81
- *
82
- * @param url - The url.
83
- * @param options - The request options.
84
- */
85
- download<P extends ObjectType = ObjectValue>(url: string, options?: RequestOptions<P> & {
86
- fileName?: string | Mapper<string, string>;
87
- }): Promise<void>;
88
- }
89
- /**
90
- * Create a request client.
91
- *
92
- * @param options - The options of the request client.
93
- * @returns The request client.
94
- */
95
- export declare function createRequestClient(options: RequestClientOptions): Readonly<RequestClient>;