@_tc/template-core 0.2.4 → 0.2.5

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/README.md CHANGED
@@ -12,7 +12,7 @@ pnpm add @_tc/template-core
12
12
 
13
13
  要求:
14
14
 
15
- - Node.js >= 18
15
+ - Node.js >= 22.13.0
16
16
  - pnpm >= 8
17
17
  - 使用内置前端时,需要安装 peer dependencies;完整清单以包内 `package.json` 的 `peerDependencies` 为准,包括 Koa、React、Vite、路由、状态、表单和 UI 相关依赖。
18
18
 
@@ -1 +1 @@
1
- Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var e=e=>globalThis[e],t=()=>globalThis,n=class{headers=new Map;constructor(e={}){Object.entries(e).forEach(([e,t])=>{this.set(e,t)})}forEach(e){this.headers.forEach((t,n)=>{e(t,n)})}has(e){return this.headers.has(this.normalizeName(e))}set(e,t){this.headers.set(this.normalizeName(e),t)}toRecord(){return Object.fromEntries(this.headers)}normalizeName(e){return e.toLowerCase()}},r=class{handlers=[];nextId=0;use(e,t){let n=this.nextId++;return this.handlers.push({id:n,fulfilled:e,rejected:t}),n}eject(e){let t=this.handlers.findIndex(t=>t.id===e);t!==-1&&this.handlers.splice(t,1)}clear(){this.handlers=[]}getHandlers(){return[...this.handlers]}};function i(t){let r=e(`Headers`);return r?new r(t):new n(t)}function a(e){return e instanceof n?e.toRecord():e}function o(t){let n=e(`URLSearchParams`);if(n){let e=new n;for(let[n,r]of Object.entries(t))r!=null&&e.append(n,String(r));return e.toString()}return Object.entries(t).filter(e=>e[1]!==void 0&&e[1]!==null).map(([e,t])=>`${encodeURIComponent(e)}=${encodeURIComponent(String(t))}`).join(`&`)}function s(e,t,n){let r=t?`${t.replace(/\/+$/,``)}/${e.replace(/^\/+/,``)}`:e;if(n){let e=o(n);e&&(r+=(r.includes(`?`)?`&`:`?`)+e)}return r}function c(e){let t={};return e.forEach((e,n)=>{t[n]=e}),t}function l(e,t){return{...t,...e,headers:{...t?.headers,...e.headers}}}function u(e){return Object.prototype.toString.call(e)===`[object Object]`}function d(t,n){let r=e(n);return typeof r==`function`&&t instanceof r}function f(e){return typeof e==`string`||e instanceof ArrayBuffer||ArrayBuffer.isView(e)?!0:d(e,`Blob`)||d(e,`FormData`)||d(e,`URLSearchParams`)||d(e,`ReadableStream`)}function p(e,t){return t?.length?t.reduce((e,t)=>t(e),e):e}function m(e,t,n){return n?(Array.isArray(n)?n:[n]).reduce((e,n)=>n(e,t),e):e}function h(){let t=e(`fetch`);if(!t)throw Error(`FetchAxios requires globalThis.fetch. Use Node.js 18+ or provide a fetch polyfill.`);return t}function g(){let t=e(`AbortController`);if(t)return new t}var _=class{defaults;interceptors={request:new r,response:new r};constructor(e={}){this.defaults=e}async request(e){let t=l(this.defaults,e);try{let e=await this.applyRequestInterceptors(t),n=await this._doRequest(e);return this.applyResponseInterceptors(n)}catch(e){return this.applyResponseErrorInterceptors(e)}}async applyRequestInterceptors(e){let t=e,n=this.interceptors.request.getHandlers().reverse();for(let e of n)if(e.fulfilled)try{t=await e.fulfilled(t)}catch(n){if(!e.rejected)throw n;t=await e.rejected(n)}return t}async applyResponseInterceptors(e){let t=e;for(let e of this.interceptors.response.getHandlers())e.fulfilled&&(t=await e.fulfilled(t));return t}async applyResponseErrorInterceptors(e){let t=e;for(let e of this.interceptors.response.getHandlers())if(e.rejected)try{return await e.rejected(t)}catch(e){t=e}throw t}async _doRequest(e){let{method:n=`GET`,baseURL:r,headers:o={},params:l,data:d,timeout:_,credentials:v,cache:y,redirect:b,referrer:x,referrerPolicy:S,transformRequest:C,transformResponse:w,validateStatus:T}=e,E=s(e.url??``,r,l),D=i(o),O=d;C&&(n===`POST`||n===`PUT`||n===`PATCH`)&&(O=m(d,D,C),(u(O)||Array.isArray(O))&&!D.has(`Content-Type`)&&D.set(`Content-Type`,`application/json`));let k={method:n,headers:a(D),credentials:v??`same-origin`,cache:y,redirect:b,referrer:x,referrerPolicy:S};O!==void 0&&n!==`GET`&&n!==`HEAD`&&(k.body=f(O)?O:JSON.stringify(O));let A=e.signal?void 0:g();k.signal=e.signal??A?.signal;let j;if(_){if(!A&&!e.signal)throw this.createError(Error(`FetchAxios timeout requires globalThis.AbortController.`),`ERR_ABORT_CONTROLLER_UNAVAILABLE`,e);let n=t();if(!n.setTimeout||!n.clearTimeout)throw this.createError(Error(`FetchAxios timeout requires globalThis.setTimeout and globalThis.clearTimeout.`),`ERR_TIMER_UNAVAILABLE`,e);j=n.setTimeout(()=>A?.abort(),_)}let M;try{M=await h()(E,k)}catch(n){throw j&&t().clearTimeout?.(j),this.createError(n instanceof Error?n:Error(String(n)),`ECONNABORTED`,e)}j&&t().clearTimeout?.(j);let N=c(M.headers),P={data:null,status:M.status,statusText:M.statusText,headers:N,config:e};if(!T||T(M.status)){let e=await M.text(),t=e?JSON.parse(e):null;return P.data=w?p(t,Array.isArray(w)?w:[w]):t,P}let F=M.body?await M.text():null;throw P.data=F?JSON.parse(F):null,this.createError(Error(`Request failed with status ${M.status}`),void 0,e,P)}createError(e,t,n,r){let i=e;return i.config=n,i.code=t,i.response=r,i.isAxiosError=!0,i}get(e,t){return this.request({...t,url:e,method:`GET`})}post(e,t,n){return this.request({...n,url:e,method:`POST`,data:t})}put(e,t,n){return this.request({...n,url:e,method:`PUT`,data:t})}patch(e,t,n){return this.request({...n,url:e,method:`PATCH`,data:t})}delete(e,t){return this.request({...t,url:e,method:`DELETE`})}head(e,t){return this.request({...t,url:e,method:`HEAD`})}options(e,t){return this.request({...t,url:e,method:`OPTIONS`})}},v=new _,y=e=>new _(e);exports.FetchAxios=_,exports.default=_,exports.axios=v,exports.createInstance=y;
1
+ Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var e=e=>globalThis[e],t=()=>globalThis,n=class{headers=new Map;constructor(e={}){Object.entries(e).forEach(([e,t])=>{this.set(e,t)})}forEach(e){this.headers.forEach((t,n)=>{e(t,n)})}has(e){return this.headers.has(this.normalizeName(e))}set(e,t){this.headers.set(this.normalizeName(e),t)}toRecord(){return Object.fromEntries(this.headers)}normalizeName(e){return e.toLowerCase()}},r=class{handlers=[];nextId=0;use(e,t){let n=this.nextId++;return this.handlers.push({id:n,fulfilled:e,rejected:t}),n}eject(e){let t=this.handlers.findIndex(t=>t.id===e);t!==-1&&this.handlers.splice(t,1)}clear(){this.handlers=[]}getHandlers(){return[...this.handlers]}};function i(t){let r=e(`Headers`);return r?new r(t):new n(t)}function a(e){return e instanceof n?e.toRecord():e}function o(t){let n=e(`URLSearchParams`);if(n){let e=new n;for(let[n,r]of Object.entries(t))r!=null&&e.append(n,String(r));return e.toString()}return Object.entries(t).filter(e=>e[1]!==void 0&&e[1]!==null).map(([e,t])=>`${encodeURIComponent(e)}=${encodeURIComponent(String(t))}`).join(`&`)}function s(e,t,n){let r=t?`${t.replace(/\/+$/,``)}/${e.replace(/^\/+/,``)}`:e;if(n){let e=o(n);e&&(r+=(r.includes(`?`)?`&`:`?`)+e)}return r}function c(e){let t={};return e.forEach((e,n)=>{t[n]=e}),t}function l(e,t){return{...t,...e,headers:{...t?.headers,...e.headers}}}function u(e){return Object.prototype.toString.call(e)===`[object Object]`}function d(t,n){let r=e(n);return typeof r==`function`&&t instanceof r}function f(e){return typeof e==`string`||e instanceof ArrayBuffer||ArrayBuffer.isView(e)?!0:d(e,`Blob`)||d(e,`FormData`)||d(e,`URLSearchParams`)||d(e,`ReadableStream`)}function p(e,t){return t?.length?t.reduce((e,t)=>t(e),e):e}function m(e,t,n){return n?(Array.isArray(n)?n:[n]).reduce((e,n)=>n(e,t),e):e}function h(){let t=e(`fetch`);if(!t)throw Error(`FetchAxios requires globalThis.fetch. Use a compatible Node.js runtime or provide a fetch polyfill.`);return t}function g(){let t=e(`AbortController`);if(t)return new t}var _=class{defaults;interceptors={request:new r,response:new r};constructor(e={}){this.defaults=e}async request(e){let t=l(this.defaults,e);try{let e=await this.applyRequestInterceptors(t),n=await this._doRequest(e);return this.applyResponseInterceptors(n)}catch(e){return this.applyResponseErrorInterceptors(e)}}async applyRequestInterceptors(e){let t=e,n=this.interceptors.request.getHandlers().reverse();for(let e of n)if(e.fulfilled)try{t=await e.fulfilled(t)}catch(n){if(!e.rejected)throw n;t=await e.rejected(n)}return t}async applyResponseInterceptors(e){let t=e;for(let e of this.interceptors.response.getHandlers())e.fulfilled&&(t=await e.fulfilled(t));return t}async applyResponseErrorInterceptors(e){let t=e;for(let e of this.interceptors.response.getHandlers())if(e.rejected)try{return await e.rejected(t)}catch(e){t=e}throw t}async _doRequest(e){let{method:n=`GET`,baseURL:r,headers:o={},params:l,data:d,timeout:_,credentials:v,cache:y,redirect:b,referrer:x,referrerPolicy:S,transformRequest:C,transformResponse:w,validateStatus:T}=e,E=s(e.url??``,r,l),D=i(o),O=d;C&&(n===`POST`||n===`PUT`||n===`PATCH`)&&(O=m(d,D,C),(u(O)||Array.isArray(O))&&!D.has(`Content-Type`)&&D.set(`Content-Type`,`application/json`));let k={method:n,headers:a(D),credentials:v??`same-origin`,cache:y,redirect:b,referrer:x,referrerPolicy:S};O!==void 0&&n!==`GET`&&n!==`HEAD`&&(k.body=f(O)?O:JSON.stringify(O));let A=e.signal?void 0:g();k.signal=e.signal??A?.signal;let j;if(_){if(!A&&!e.signal)throw this.createError(Error(`FetchAxios timeout requires globalThis.AbortController.`),`ERR_ABORT_CONTROLLER_UNAVAILABLE`,e);let n=t();if(!n.setTimeout||!n.clearTimeout)throw this.createError(Error(`FetchAxios timeout requires globalThis.setTimeout and globalThis.clearTimeout.`),`ERR_TIMER_UNAVAILABLE`,e);j=n.setTimeout(()=>A?.abort(),_)}let M;try{M=await h()(E,k)}catch(n){throw j&&t().clearTimeout?.(j),this.createError(n instanceof Error?n:Error(String(n)),`ECONNABORTED`,e)}j&&t().clearTimeout?.(j);let N=c(M.headers),P={data:null,status:M.status,statusText:M.statusText,headers:N,config:e};if(!T||T(M.status)){let e=await M.text(),t=e?JSON.parse(e):null;return P.data=w?p(t,Array.isArray(w)?w:[w]):t,P}let F=M.body?await M.text():null;throw P.data=F?JSON.parse(F):null,this.createError(Error(`Request failed with status ${M.status}`),void 0,e,P)}createError(e,t,n,r){let i=e;return i.config=n,i.code=t,i.response=r,i.isAxiosError=!0,i}get(e,t){return this.request({...t,url:e,method:`GET`})}post(e,t,n){return this.request({...n,url:e,method:`POST`,data:t})}put(e,t,n){return this.request({...n,url:e,method:`PUT`,data:t})}patch(e,t,n){return this.request({...n,url:e,method:`PATCH`,data:t})}delete(e,t){return this.request({...t,url:e,method:`DELETE`})}head(e,t){return this.request({...t,url:e,method:`HEAD`})}options(e,t){return this.request({...t,url:e,method:`OPTIONS`})}},v=new _,y=e=>new _(e);exports.FetchAxios=_,exports.default=_,exports.axios=v,exports.createInstance=y;
@@ -103,7 +103,7 @@ function m(e, t, n) {
103
103
  }
104
104
  function h() {
105
105
  let t = e("fetch");
106
- if (!t) throw Error("FetchAxios requires globalThis.fetch. Use Node.js 18+ or provide a fetch polyfill.");
106
+ if (!t) throw Error("FetchAxios requires globalThis.fetch. Use a compatible Node.js runtime or provide a fetch polyfill.");
107
107
  return t;
108
108
  }
109
109
  function g() {
@@ -118,7 +118,7 @@ function applyRequestTransformers(value, headers, transformers) {
118
118
  }
119
119
  function getFetch() {
120
120
  const fetchRef = getGlobalValue("fetch");
121
- if (!fetchRef) throw new Error("FetchAxios requires globalThis.fetch. Use Node.js 18+ or provide a fetch polyfill.");
121
+ if (!fetchRef) throw new Error("FetchAxios requires globalThis.fetch. Use a compatible Node.js runtime or provide a fetch polyfill.");
122
122
  return fetchRef;
123
123
  }
124
124
  function createAbortController() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@_tc/template-core",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
4
4
  "description": "A full-stack TypeScript admin framework powered by Koa, React, and Vite - monorepo root",
5
5
  "types": "./types/index.d.ts",
6
6
  "exports": {
@@ -101,7 +101,7 @@
101
101
  "author": "",
102
102
  "license": "ISC",
103
103
  "engines": {
104
- "node": ">=18.0.0",
104
+ "node": ">=22.13.0",
105
105
  "pnpm": ">=8.0.0"
106
106
  },
107
107
  "publishConfig": {