@uni2c/graphqlapi4mp 1.0.7 → 1.0.8

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/dist/index.cjs CHANGED
@@ -29,7 +29,7 @@ var Z={};(Z.asn1===void 0||!Z.asn1)&&(Z.asn1={}),Z.asn1.ASN1Util=new function(){
29
29
  `;return e+=t.wordwrap(this.getPrivateBaseKeyB64())+`
30
30
  `,e+=`-----END RSA PRIVATE KEY-----`,e},t.prototype.getPublicKey=function(){var e=`-----BEGIN PUBLIC KEY-----
31
31
  `;return e+=t.wordwrap(this.getPublicBaseKeyB64())+`
32
- `,e+=`-----END PUBLIC KEY-----`,e},t.hasPublicKeyProperty=function(e){return e||={},e.hasOwnProperty(`n`)&&e.hasOwnProperty(`e`)},t.hasPrivateKeyProperty=function(e){return e||={},e.hasOwnProperty(`n`)&&e.hasOwnProperty(`e`)&&e.hasOwnProperty(`d`)&&e.hasOwnProperty(`p`)&&e.hasOwnProperty(`q`)&&e.hasOwnProperty(`dmp1`)&&e.hasOwnProperty(`dmq1`)&&e.hasOwnProperty(`coeff`)},t.prototype.parsePropertiesFrom=function(e){this.n=e.n,this.e=e.e,e.hasOwnProperty(`d`)&&(this.d=e.d,this.p=e.p,this.q=e.q,this.dmp1=e.dmp1,this.dmq1=e.dmq1,this.coeff=e.coeff)},t}(Ue),Ze=`3.2.1`,Qe=function(){function e(e){e===void 0&&(e={}),e||={},this.default_key_size=e.default_key_size?parseInt(e.default_key_size,10):1024,this.default_public_exponent=e.default_public_exponent||`010001`,this.log=e.log||!1,this.key=null}return e.prototype.setKey=function(e){this.log&&this.key&&console.warn(`A key was already set, overriding existing.`),this.key=new Xe(e)},e.prototype.setPrivateKey=function(e){this.setKey(e)},e.prototype.setPublicKey=function(e){this.setKey(e)},e.prototype.decrypt=function(e){try{return this.getKey().decrypt(_e(e))}catch{return!1}},e.prototype.encrypt=function(e){try{return N(this.getKey().encrypt(e))}catch{return!1}},e.prototype.encryptLong=function(e){try{return N(this.getKey().encryptLong(e))}catch{return!1}},e.prototype.decryptLong=function(e){try{return this.getKey().decryptLong(_e(e))}catch{return!1}},e.prototype.sign=function(e,t,n){try{return N(this.getKey().sign(e,t,n))}catch{return!1}},e.prototype.verify=function(e,t,n){try{return this.getKey().verify(e,_e(t),n)}catch{return!1}},e.prototype.getKey=function(e){if(!this.key){if(this.key=new Xe,e&&{}.toString.call(e)===`[object Function]`){this.key.generateAsync(this.default_key_size,this.default_public_exponent,e);return}this.key.generate(this.default_key_size,this.default_public_exponent)}return this.key},e.prototype.getPrivateKey=function(){return this.getKey().getPrivateKey()},e.prototype.getPrivateKeyB64=function(){return this.getKey().getPrivateBaseKeyB64()},e.prototype.getPublicKey=function(){return this.getKey().getPublicKey()},e.prototype.getPublicKeyB64=function(){return this.getKey().getPublicBaseKeyB64()},e.version=Ze,e}();const Q=globalThis,$e=new Qe;let $={};const et=()=>e(new Date().getTime()+pt(32));function tt(e){$=Object.assign({PROD:!1,VITE_SALT_KEY:``,VITE_PUBLIC_KEY:``},e),$e.setPublicKey($?.VITE_PUBLIC_KEY)}function nt(e){let t=encodeURIComponent(e),n=[];for(let e=0;e<t.length;e++)t.charCodeAt(e)===37?(n.push(parseInt(t.slice(e+1,e+3),16)),e+=2):n.push(t.charCodeAt(e));return new Uint8Array(n)}function rt(e){let t=``;for(let n=0;n<e.length;n++)t+=`%${e[n].toString(16).padStart(2,`0`)}`;return decodeURIComponent(t)}function it(e){let t=e.slice().buffer;if(Q.wx?.arrayBufferToBase64)return Q.wx.arrayBufferToBase64(t);if(Q.uni?.arrayBufferToBase64)return Q.uni.arrayBufferToBase64(t);let n=``;for(let t=0;t<e.length;t++)n+=String.fromCharCode(e[t]);return Q.btoa(n)}function at(e){if(Q.wx?.base64ToArrayBuffer)return new Uint8Array(Q.wx.base64ToArrayBuffer(e));if(Q.uni?.base64ToArrayBuffer)return new Uint8Array(Q.uni.base64ToArrayBuffer(e));let t=Q.atob(e),n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n}function ot(e,t){let n=nt(e),r=nt(t);if(n.length!==16||r.length!==16)throw Error(`AES-128 key 和 iv 必须都是 16 bytes`);return le(n,r)}function st(e,t,n){return it(ot(t,n).encrypt(nt(e)))}function ct(e,t,n){return rt(ot(t,n).decrypt(at(e)))}function lt(e,t){return{value:st(JSON.stringify(e),t.substring(0,16),t.substring(16)),key:$e.encrypt(t)}}function ut(e,t){if(e.data){e.data=ct(e.data,t.substring(0,16),t.substring(16));try{e.data=JSON.parse(e.data||`{}`)}catch(e){console.error(e)}}return e}function dt(e){if(typeof e==`string`)return ft(e);if(e&&typeof e==`object`){let t=[];for(let n of Object.keys(e))e[n]&&t.push(`${n}=${e[n]}`);return ft(t.join(`&`))}return``}function ft(t){return e(`${t.split(`&`).sort().join(`&`)}&key=${$?.VITE_SALT_KEY}`)}function pt(e){let t=``;for(;e--;)t+=`0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`[Math.floor(Math.random()*62)];return t}function mt(e){return it(nt(e))}function ht(e){return rt(at(e))}function gt(e,t){let n=JSON.parse(JSON.stringify(e)),r=dt(n.data.variables);return n.data.variables.sign=r,$?.PROD&&(n.data=lt(n.data,t)),n}const _t=Object.freeze(Object.create(null)),vt=e=>e===95||e>=65&&e<=90||e>=97&&e<=122,yt=e=>vt(e)||e>=48&&e<=57,bt=e=>e>=48&&e<=57,xt=Object.create(null);function St(e){let t=+(e.charCodeAt(0)===65279),n=e.length,r,i=Object.create(null),a=new Set([`String`,`Int`,`Float`,`Boolean`,`ID`]),o=new Set;function s(){for(;;){if(t>=n)return;let r=e.charCodeAt(t);if(r===32||r===9||r===10||r===13||r===44){t++;continue}if(r===35){for(;++t<n;){let n=e.charCodeAt(t);if(n===10||n===13)break}continue}if(r===34&&e.charCodeAt(t+1)===34&&e.charCodeAt(t+2)===34){for(t+=3;t<n;){if(e.charCodeAt(t)===34&&e.charCodeAt(t+1)===34&&e.charCodeAt(t+2)===34){t+=3;break}t+=e.charCodeAt(t)===92?2:1}continue}if(r===34){for(t++;t<n;){let n=e.charCodeAt(t++);if(n===92)t++;else if(n===34)break}return`\0s`}if(vt(r)){let r=t++;for(;t<n&&yt(e.charCodeAt(t));)t++;return e.slice(r,t)}if(bt(r)||r===45&&bt(e.charCodeAt(t+1))){for(t++;t<n;){let n=e.charCodeAt(t);if(bt(n)||n===46||n===101||n===69||n===43||n===45)t++;else break}return`\0n`}if(r===46&&e.charCodeAt(t+1)===46&&e.charCodeAt(t+2)===46)return t+=3,`...`;if(r===123||r===125||r===40||r===41||r===91||r===93||r===58||r===33||r===61||r===36||r===64||r===124||r===38)return t++,String.fromCharCode(r);t++}}let c=()=>r??=s(),l=()=>{let e=r??s();return r=void 0,e},u=e=>c()===e&&(l(),!0),d=e=>{let t=l();if(t!==e)throw Error(`parseSDL: expected "${e}", got "${t??`EOF`}"`)},f=()=>{let e=l();if(!e||e===`\0s`||e===`\0n`||!vt(e.charCodeAt(0)))throw Error(`parseSDL: expected NAME, got "${e??`EOF`}"`);return e};function p(){if(u(`[`)){let e=`[${p()}]`;return d(`]`),u(`!`)&&(e+=`!`),e}let e=f();return u(`!`)&&(e+=`!`),e}function m(){if(u(`[`)){for(;c()&&c()!==`]`;)m();d(`]`);return}if(u(`{`)){for(;c()&&c()!==`}`;)f(),d(`:`),m();d(`}`);return}l()}function h(){for(;u(`@`);){if(f(),!u(`(`))continue;let e=1;for(;e&&c();)u(`(`)?e++:u(`)`)?e--:l()}}function g(){if(!u(`(`))return _t;let e=Object.create(null);for(;c()&&c()!==`)`;){let t=f();d(`:`),e[t]=p(),u(`=`)&&m(),h()}return d(`)`),e}function _(){let e=Object.create(null);for(d(`{`);c()&&c()!==`}`;){let t=f(),n=g();d(`:`);let r=p();h(),e[t]={name:t,args:n,type:r}}return d(`}`),e}function v(){let e=f();if(u(`implements`))for(u(`&`);c()&&c()!==`{`;)l();h(),c()===`{`&&(i[e]={name:e,fields:_()})}function y(){a.add(f()),h()}function b(){if(o.add(f()),h(),u(`{`)){for(;c()&&c()!==`}`;)l(),h();d(`}`)}}for(;c();)switch(l()){case`type`:v();break;case`scalar`:y();break;case`enum`:b()}return{query:i.Query?.fields||{},mutation:i.Mutation?.fields||{},types:i,scalars:a,enums:o}}function Ct(e){let t=0,n=e.length,r=e.charCodeAt(0),i=e.charCodeAt(n-1);if(r!==91&&r!==33&&i!==93&&i!==33)return e;let a=xt[e];if(a)return a;for(;t<n;){let n=e.charCodeAt(t);if(n!==91&&n!==33)break;t++}for(;n>t;){let t=e.charCodeAt(n-1);if(t!==93&&t!==33)break;n--}let o=e.slice(t,n);return xt[e]=o,o}function wt(e,t,n={}){let r=e.types[Ct(t.type)];if(!r)return[];let i=[],a=r.fields;for(let t in a){let r=a[t],o=n[t];if(o!==!1){if(!e.types[Ct(r.type)]){i.push(t);continue}o!==void 0&&i.push({name:t,fields:wt(e,r,o===!0?{}:o)})}}return i}function Tt(e,t=` `){let n=``;for(let r of e){if(n&&(n+=`
33
- `),typeof r==`string`){n+=t+r;continue}let e=Tt(r.fields,t+` `);n+=e?`${t}${r.name} {\n${e}\n${t}}`:t+r.name}return n}function Et(e,t=`query`){let{name:n,args:r=_t,fields:i=[]}=e,a=``,o=``;for(let e in r)a&&(a+=`, `),a+=`$${e}: ${r[e]}`,o+=`${o?`
34
- `:``} ${e}: $${e}`;let s=Tt(i),c=`${t} ${n}`;return a&&(c+=`(${a})`),c+=` {\n ${n}`,o&&(c+=`(\n${o}\n )`),s&&(c+=` {\n${s}\n }`),c+`
35
- }`}function Dt(e,t){if(t==null)return t;switch(e){case`Int`:{let e=Number.parseInt(t,10);return Number.isNaN(e)?void 0:e}case`Float`:{let e=Number.parseFloat(t);return Number.isNaN(e)?void 0:e}case`Boolean`:return t===`false`||t===`0`?!1:!!t;case`String`:case`ID`:return String(t);case`JsonString`:return typeof t==`string`?t:JSON.stringify(t);default:return t}}function Ot(e,t=!1){if(t)return[];switch(e){case`Int`:return 0;case`Float`:return 0;case`Boolean`:return!1;case`String`:case`ID`:return``;case`JsonString`:return`{}`;default:return null}}function kt(e){return!!(e==null||e===``||Array.isArray(e)&&e.length===0)}function At(e={},t=_t,n=!0){if(!e||!t)return e;let r={};for(let i in e){let a=t[i];if(!a)continue;let o=e[i];if(n&&kt(o))continue;let s=a.endsWith(`!`),c=a.replace(/!$/,``),l=c.startsWith(`[`)&&c.endsWith(`]`),u=l?c.slice(1,-1).replace(/!$/,``):c,d=/\[.*!\]/.test(a);if(o===null){if(s){let e=Ot(u,l);(!n||!kt(e))&&(r[i]=e)}else n||(r[i]=null);continue}if(o!==void 0){if(l){let e=(Array.isArray(o)?o:typeof o==`string`?o.split(`,`).map(e=>e.trim()).filter(e=>e.length>0):[o]).map(e=>Dt(u,e)).filter(e=>d?e!=null:e!==void 0);if(n&&e.length===0)continue;(e.length>0||!s)&&(r[i]=e)}else{let e=Dt(u,o);if(e===void 0||n&&kt(e))continue;r[i]=e}}}return r}const jt=Et;exports.base64decode=ht,exports.base64encode=mt,exports.buildGraphQLQuery=Et,exports.buildQuery=jt,exports.buildSelectionFields=wt,exports.decodeData=ut,exports.decrypt=ct,exports.encodeData=lt,exports.encrypt=st,Object.defineProperty(exports,"env",{enumerable:!0,get:function(){return $}}),exports.formatVariables=At,exports.getSign=dt,exports.initPassword=et,exports.md5=e,exports.paramProcess=gt,exports.paramsStrSort=ft,exports.parseSDL=St,exports.randomString=pt,exports.setEnv=tt,exports.unwrapType=Ct;
32
+ `,e+=`-----END PUBLIC KEY-----`,e},t.hasPublicKeyProperty=function(e){return e||={},e.hasOwnProperty(`n`)&&e.hasOwnProperty(`e`)},t.hasPrivateKeyProperty=function(e){return e||={},e.hasOwnProperty(`n`)&&e.hasOwnProperty(`e`)&&e.hasOwnProperty(`d`)&&e.hasOwnProperty(`p`)&&e.hasOwnProperty(`q`)&&e.hasOwnProperty(`dmp1`)&&e.hasOwnProperty(`dmq1`)&&e.hasOwnProperty(`coeff`)},t.prototype.parsePropertiesFrom=function(e){this.n=e.n,this.e=e.e,e.hasOwnProperty(`d`)&&(this.d=e.d,this.p=e.p,this.q=e.q,this.dmp1=e.dmp1,this.dmq1=e.dmq1,this.coeff=e.coeff)},t}(Ue),Ze=`3.2.1`,Qe=function(){function e(e){e===void 0&&(e={}),e||={},this.default_key_size=e.default_key_size?parseInt(e.default_key_size,10):1024,this.default_public_exponent=e.default_public_exponent||`010001`,this.log=e.log||!1,this.key=null}return e.prototype.setKey=function(e){this.log&&this.key&&console.warn(`A key was already set, overriding existing.`),this.key=new Xe(e)},e.prototype.setPrivateKey=function(e){this.setKey(e)},e.prototype.setPublicKey=function(e){this.setKey(e)},e.prototype.decrypt=function(e){try{return this.getKey().decrypt(_e(e))}catch{return!1}},e.prototype.encrypt=function(e){try{return N(this.getKey().encrypt(e))}catch{return!1}},e.prototype.encryptLong=function(e){try{return N(this.getKey().encryptLong(e))}catch{return!1}},e.prototype.decryptLong=function(e){try{return this.getKey().decryptLong(_e(e))}catch{return!1}},e.prototype.sign=function(e,t,n){try{return N(this.getKey().sign(e,t,n))}catch{return!1}},e.prototype.verify=function(e,t,n){try{return this.getKey().verify(e,_e(t),n)}catch{return!1}},e.prototype.getKey=function(e){if(!this.key){if(this.key=new Xe,e&&{}.toString.call(e)===`[object Function]`){this.key.generateAsync(this.default_key_size,this.default_public_exponent,e);return}this.key.generate(this.default_key_size,this.default_public_exponent)}return this.key},e.prototype.getPrivateKey=function(){return this.getKey().getPrivateKey()},e.prototype.getPrivateKeyB64=function(){return this.getKey().getPrivateBaseKeyB64()},e.prototype.getPublicKey=function(){return this.getKey().getPublicKey()},e.prototype.getPublicKeyB64=function(){return this.getKey().getPublicBaseKeyB64()},e.version=Ze,e}();const Q=globalThis,$e=new Qe;let $={};const et=()=>e(new Date().getTime()+pt(32));function tt(e){$=Object.assign({PROD:!1,VITE_SALT_KEY:``,VITE_PUBLIC_KEY:``},e),$e.setPublicKey($?.VITE_PUBLIC_KEY)}function nt(e){let t=encodeURIComponent(e),n=[];for(let e=0;e<t.length;e++)t.charCodeAt(e)===37?(n.push(parseInt(t.slice(e+1,e+3),16)),e+=2):n.push(t.charCodeAt(e));return new Uint8Array(n)}function rt(e){let t=``;for(let n=0;n<e.length;n++)t+=`%${e[n].toString(16).padStart(2,`0`)}`;return decodeURIComponent(t)}function it(e){let t=e.slice().buffer;if(Q.wx?.arrayBufferToBase64)return Q.wx.arrayBufferToBase64(t);if(Q.uni?.arrayBufferToBase64)return Q.uni.arrayBufferToBase64(t);let n=``;for(let t=0;t<e.length;t++)n+=String.fromCharCode(e[t]);return Q.btoa(n)}function at(e){if(Q.wx?.base64ToArrayBuffer)return new Uint8Array(Q.wx.base64ToArrayBuffer(e));if(Q.uni?.base64ToArrayBuffer)return new Uint8Array(Q.uni.base64ToArrayBuffer(e));let t=Q.atob(e),n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n}function ot(e,t){let n=nt(e),r=nt(t);if(n.length!==16||r.length!==16)throw Error(`AES-128 key 和 iv 必须都是 16 bytes`);return le(n,r)}function st(e,t,n){return it(ot(t,n).encrypt(nt(e)))}function ct(e,t,n){return rt(ot(t,n).decrypt(at(e)))}function lt(e,t){return{value:st(JSON.stringify(e),t.substring(0,16),t.substring(16)),key:$e.encrypt(t)}}function ut(e,t){if(e.data){e.data=ct(e.data,t.substring(0,16),t.substring(16));try{e.data=JSON.parse(e.data||`{}`)}catch(e){console.error(e)}}return e}function dt(e){if(typeof e==`string`)return ft(e);if(e&&typeof e==`object`){let t=[];for(let n of Object.keys(e))e[n]&&t.push(`${n}=${e[n]}`);return ft(t.join(`&`))}return``}function ft(t){return e(`${t.split(`&`).sort().join(`&`)}&key=${$?.VITE_SALT_KEY}`)}function pt(e){let t=``;for(;e--;)t+=`0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`[Math.floor(Math.random()*62)];return t}function mt(e){return it(nt(e))}function ht(e){return rt(at(e))}function gt(e,t){let n=JSON.parse(JSON.stringify(e)),r=dt(n.data.variables);return n.data.variables.sign=r,$?.PROD&&(n.data=lt(n.data,t)),n}function _t(e,t,n){function r(e,t){if(typeof e!=`object`||!e||Array.isArray(e))return e;let n={...e};for(let r of Object.keys(e))Object.prototype.hasOwnProperty.call(t,r)&&(n[r]=i(e[r],t[r].type));return n}function i(e,t){if(e==null)return e;let a=t.endsWith(`!`)?t.slice(0,-1):t;if(a.startsWith(`[`)&&a.endsWith(`]`))return Array.isArray(e)?e.map(e=>i(e,a.slice(1,-1))):e;switch(a){case`JsonString`:if(typeof e!=`string`)return e;try{return JSON.parse(e)}catch{return e}case`Int`:case`Float`:{if(typeof e!=`number`&&typeof e!=`string`||typeof e==`string`&&e.trim()===``)return e;let t=Number(e);return Number.isFinite(t)&&(a!==`Int`||Number.isSafeInteger(t))?t:e}case`Boolean`:return e===`false`||e===`0`||e===0?!1:e===`true`||e===`1`||e===1||e;case`String`:case`ID`:return typeof e==`number`||typeof e==`boolean`?String(e):e;default:{let t=n?.types,i=t&&Object.prototype.hasOwnProperty.call(t,a)?t[a]:void 0;return i?r(e,i.fields):e}}}return e.map(e=>t?r(e,t):{...e})}const vt=Object.freeze(Object.create(null)),yt=e=>e===95||e>=65&&e<=90||e>=97&&e<=122,bt=e=>yt(e)||e>=48&&e<=57,xt=e=>e>=48&&e<=57,St=Object.create(null);function Ct(e){let t=+(e.charCodeAt(0)===65279),n=e.length,r,i=Object.create(null),a=new Set([`String`,`Int`,`Float`,`Boolean`,`ID`]),o=new Set;function s(){for(;;){if(t>=n)return;let r=e.charCodeAt(t);if(r===32||r===9||r===10||r===13||r===44){t++;continue}if(r===35){for(;++t<n;){let n=e.charCodeAt(t);if(n===10||n===13)break}continue}if(r===34&&e.charCodeAt(t+1)===34&&e.charCodeAt(t+2)===34){for(t+=3;t<n;){if(e.charCodeAt(t)===34&&e.charCodeAt(t+1)===34&&e.charCodeAt(t+2)===34){t+=3;break}t+=e.charCodeAt(t)===92?2:1}continue}if(r===34){for(t++;t<n;){let n=e.charCodeAt(t++);if(n===92)t++;else if(n===34)break}return`\0s`}if(yt(r)){let r=t++;for(;t<n&&bt(e.charCodeAt(t));)t++;return e.slice(r,t)}if(xt(r)||r===45&&xt(e.charCodeAt(t+1))){for(t++;t<n;){let n=e.charCodeAt(t);if(xt(n)||n===46||n===101||n===69||n===43||n===45)t++;else break}return`\0n`}if(r===46&&e.charCodeAt(t+1)===46&&e.charCodeAt(t+2)===46)return t+=3,`...`;if(r===123||r===125||r===40||r===41||r===91||r===93||r===58||r===33||r===61||r===36||r===64||r===124||r===38)return t++,String.fromCharCode(r);t++}}let c=()=>r??=s(),l=()=>{let e=r??s();return r=void 0,e},u=e=>c()===e&&(l(),!0),d=e=>{let t=l();if(t!==e)throw Error(`parseSDL: expected "${e}", got "${t??`EOF`}"`)},f=()=>{let e=l();if(!e||e===`\0s`||e===`\0n`||!yt(e.charCodeAt(0)))throw Error(`parseSDL: expected NAME, got "${e??`EOF`}"`);return e};function p(){if(u(`[`)){let e=`[${p()}]`;return d(`]`),u(`!`)&&(e+=`!`),e}let e=f();return u(`!`)&&(e+=`!`),e}function m(){if(u(`[`)){for(;c()&&c()!==`]`;)m();d(`]`);return}if(u(`{`)){for(;c()&&c()!==`}`;)f(),d(`:`),m();d(`}`);return}l()}function h(){for(;u(`@`);){if(f(),!u(`(`))continue;let e=1;for(;e&&c();)u(`(`)?e++:u(`)`)?e--:l()}}function g(){if(!u(`(`))return vt;let e=Object.create(null);for(;c()&&c()!==`)`;){let t=f();d(`:`),e[t]=p(),u(`=`)&&m(),h()}return d(`)`),e}function _(){let e=Object.create(null);for(d(`{`);c()&&c()!==`}`;){let t=f(),n=g();d(`:`);let r=p();h(),e[t]={name:t,args:n,type:r}}return d(`}`),e}function v(){let e=f();if(u(`implements`))for(u(`&`);c()&&c()!==`{`;)l();h(),c()===`{`&&(i[e]={name:e,fields:_()})}function y(){a.add(f()),h()}function b(){if(o.add(f()),h(),u(`{`)){for(;c()&&c()!==`}`;)l(),h();d(`}`)}}for(;c();)switch(l()){case`type`:v();break;case`scalar`:y();break;case`enum`:b()}return{query:i.Query?.fields||{},mutation:i.Mutation?.fields||{},types:i,scalars:a,enums:o}}function wt(e){let t=0,n=e.length,r=e.charCodeAt(0),i=e.charCodeAt(n-1);if(r!==91&&r!==33&&i!==93&&i!==33)return e;let a=St[e];if(a)return a;for(;t<n;){let n=e.charCodeAt(t);if(n!==91&&n!==33)break;t++}for(;n>t;){let t=e.charCodeAt(n-1);if(t!==93&&t!==33)break;n--}let o=e.slice(t,n);return St[e]=o,o}function Tt(e,t,n={}){let r=e.types[wt(t.type)];if(!r)return[];let i=[],a=r.fields;for(let t in a){let r=a[t],o=n[t];if(o!==!1){if(!e.types[wt(r.type)]){i.push(t);continue}o!==void 0&&i.push({name:t,fields:Tt(e,r,o===!0?{}:o)})}}return i}function Et(e,t=` `){let n=``;for(let r of e){if(n&&(n+=`
33
+ `),typeof r==`string`){n+=t+r;continue}let e=Et(r.fields,t+` `);n+=e?`${t}${r.name} {\n${e}\n${t}}`:t+r.name}return n}function Dt(e,t=`query`){let{name:n,args:r=vt,fields:i=[]}=e,a=``,o=``;for(let e in r)a&&(a+=`, `),a+=`$${e}: ${r[e]}`,o+=`${o?`
34
+ `:``} ${e}: $${e}`;let s=Et(i),c=`${t} ${n}`;return a&&(c+=`(${a})`),c+=` {\n ${n}`,o&&(c+=`(\n${o}\n )`),s&&(c+=` {\n${s}\n }`),c+`
35
+ }`}function Ot(e,t){if(t==null)return t;switch(e){case`Int`:{let e=Number.parseInt(t,10);return Number.isNaN(e)?void 0:e}case`Float`:{let e=Number.parseFloat(t);return Number.isNaN(e)?void 0:e}case`Boolean`:return t===`false`||t===`0`?!1:!!t;case`String`:case`ID`:return String(t);case`JsonString`:return typeof t==`string`?t:JSON.stringify(t);default:return t}}function kt(e,t=!1){if(t)return[];switch(e){case`Int`:return 0;case`Float`:return 0;case`Boolean`:return!1;case`String`:case`ID`:return``;case`JsonString`:return`{}`;default:return null}}function At(e){return!!(e==null||e===``||Array.isArray(e)&&e.length===0)}function jt(e={},t=vt,n=!0){if(!e||!t)return e;let r={};for(let i in e){let a=t[i];if(!a)continue;let o=e[i];if(n&&At(o))continue;let s=a.endsWith(`!`),c=a.replace(/!$/,``),l=c.startsWith(`[`)&&c.endsWith(`]`),u=l?c.slice(1,-1).replace(/!$/,``):c,d=/\[.*!\]/.test(a);if(o===null){if(s){let e=kt(u,l);(!n||!At(e))&&(r[i]=e)}else n||(r[i]=null);continue}if(o!==void 0){if(l){let e=(Array.isArray(o)?o:typeof o==`string`?o.split(`,`).map(e=>e.trim()).filter(e=>e.length>0):[o]).map(e=>Ot(u,e)).filter(e=>d?e!=null:e!==void 0);if(n&&e.length===0)continue;(e.length>0||!s)&&(r[i]=e)}else{let e=Ot(u,o);if(e===void 0||n&&At(e))continue;r[i]=e}}}return r}const Mt=Dt;exports.base64decode=ht,exports.base64encode=mt,exports.buildGraphQLQuery=Dt,exports.buildQuery=Mt,exports.buildSelectionFields=Tt,exports.decodeData=ut,exports.decrypt=ct,exports.encodeData=lt,exports.encrypt=st,Object.defineProperty(exports,"env",{enumerable:!0,get:function(){return $}}),exports.formatVariables=jt,exports.getSign=dt,exports.initPassword=et,exports.md5=e,exports.paramProcess=gt,exports.paramsStrSort=ft,exports.parseResponseOptimized=_t,exports.parseSDL=Ct,exports.randomString=pt,exports.setEnv=tt,exports.unwrapType=wt;
package/dist/index.mjs CHANGED
@@ -29,7 +29,7 @@ var Z={};(Z.asn1===void 0||!Z.asn1)&&(Z.asn1={}),Z.asn1.ASN1Util=new function(){
29
29
  `;return e+=t.wordwrap(this.getPrivateBaseKeyB64())+`
30
30
  `,e+=`-----END RSA PRIVATE KEY-----`,e},t.prototype.getPublicKey=function(){var e=`-----BEGIN PUBLIC KEY-----
31
31
  `;return e+=t.wordwrap(this.getPublicBaseKeyB64())+`
32
- `,e+=`-----END PUBLIC KEY-----`,e},t.hasPublicKeyProperty=function(e){return e||={},e.hasOwnProperty(`n`)&&e.hasOwnProperty(`e`)},t.hasPrivateKeyProperty=function(e){return e||={},e.hasOwnProperty(`n`)&&e.hasOwnProperty(`e`)&&e.hasOwnProperty(`d`)&&e.hasOwnProperty(`p`)&&e.hasOwnProperty(`q`)&&e.hasOwnProperty(`dmp1`)&&e.hasOwnProperty(`dmq1`)&&e.hasOwnProperty(`coeff`)},t.prototype.parsePropertiesFrom=function(e){this.n=e.n,this.e=e.e,e.hasOwnProperty(`d`)&&(this.d=e.d,this.p=e.p,this.q=e.q,this.dmp1=e.dmp1,this.dmq1=e.dmq1,this.coeff=e.coeff)},t}(Ue),Ze=`3.2.1`,Qe=function(){function e(e){e===void 0&&(e={}),e||={},this.default_key_size=e.default_key_size?parseInt(e.default_key_size,10):1024,this.default_public_exponent=e.default_public_exponent||`010001`,this.log=e.log||!1,this.key=null}return e.prototype.setKey=function(e){this.log&&this.key&&console.warn(`A key was already set, overriding existing.`),this.key=new Xe(e)},e.prototype.setPrivateKey=function(e){this.setKey(e)},e.prototype.setPublicKey=function(e){this.setKey(e)},e.prototype.decrypt=function(e){try{return this.getKey().decrypt(_e(e))}catch{return!1}},e.prototype.encrypt=function(e){try{return N(this.getKey().encrypt(e))}catch{return!1}},e.prototype.encryptLong=function(e){try{return N(this.getKey().encryptLong(e))}catch{return!1}},e.prototype.decryptLong=function(e){try{return this.getKey().decryptLong(_e(e))}catch{return!1}},e.prototype.sign=function(e,t,n){try{return N(this.getKey().sign(e,t,n))}catch{return!1}},e.prototype.verify=function(e,t,n){try{return this.getKey().verify(e,_e(t),n)}catch{return!1}},e.prototype.getKey=function(e){if(!this.key){if(this.key=new Xe,e&&{}.toString.call(e)===`[object Function]`){this.key.generateAsync(this.default_key_size,this.default_public_exponent,e);return}this.key.generate(this.default_key_size,this.default_public_exponent)}return this.key},e.prototype.getPrivateKey=function(){return this.getKey().getPrivateKey()},e.prototype.getPrivateKeyB64=function(){return this.getKey().getPrivateBaseKeyB64()},e.prototype.getPublicKey=function(){return this.getKey().getPublicKey()},e.prototype.getPublicKeyB64=function(){return this.getKey().getPublicBaseKeyB64()},e.version=Ze,e}();const Q=globalThis,$e=new Qe;let $={};const et=()=>e(new Date().getTime()+pt(32));function tt(e){$=Object.assign({PROD:!1,VITE_SALT_KEY:``,VITE_PUBLIC_KEY:``},e),$e.setPublicKey($?.VITE_PUBLIC_KEY)}function nt(e){let t=encodeURIComponent(e),n=[];for(let e=0;e<t.length;e++)t.charCodeAt(e)===37?(n.push(parseInt(t.slice(e+1,e+3),16)),e+=2):n.push(t.charCodeAt(e));return new Uint8Array(n)}function rt(e){let t=``;for(let n=0;n<e.length;n++)t+=`%${e[n].toString(16).padStart(2,`0`)}`;return decodeURIComponent(t)}function it(e){let t=e.slice().buffer;if(Q.wx?.arrayBufferToBase64)return Q.wx.arrayBufferToBase64(t);if(Q.uni?.arrayBufferToBase64)return Q.uni.arrayBufferToBase64(t);let n=``;for(let t=0;t<e.length;t++)n+=String.fromCharCode(e[t]);return Q.btoa(n)}function at(e){if(Q.wx?.base64ToArrayBuffer)return new Uint8Array(Q.wx.base64ToArrayBuffer(e));if(Q.uni?.base64ToArrayBuffer)return new Uint8Array(Q.uni.base64ToArrayBuffer(e));let t=Q.atob(e),n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n}function ot(e,t){let n=nt(e),r=nt(t);if(n.length!==16||r.length!==16)throw Error(`AES-128 key 和 iv 必须都是 16 bytes`);return le(n,r)}function st(e,t,n){return it(ot(t,n).encrypt(nt(e)))}function ct(e,t,n){return rt(ot(t,n).decrypt(at(e)))}function lt(e,t){return{value:st(JSON.stringify(e),t.substring(0,16),t.substring(16)),key:$e.encrypt(t)}}function ut(e,t){if(e.data){e.data=ct(e.data,t.substring(0,16),t.substring(16));try{e.data=JSON.parse(e.data||`{}`)}catch(e){console.error(e)}}return e}function dt(e){if(typeof e==`string`)return ft(e);if(e&&typeof e==`object`){let t=[];for(let n of Object.keys(e))e[n]&&t.push(`${n}=${e[n]}`);return ft(t.join(`&`))}return``}function ft(t){return e(`${t.split(`&`).sort().join(`&`)}&key=${$?.VITE_SALT_KEY}`)}function pt(e){let t=``;for(;e--;)t+=`0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`[Math.floor(Math.random()*62)];return t}function mt(e){return it(nt(e))}function ht(e){return rt(at(e))}function gt(e,t){let n=JSON.parse(JSON.stringify(e)),r=dt(n.data.variables);return n.data.variables.sign=r,$?.PROD&&(n.data=lt(n.data,t)),n}const _t=Object.freeze(Object.create(null)),vt=e=>e===95||e>=65&&e<=90||e>=97&&e<=122,yt=e=>vt(e)||e>=48&&e<=57,bt=e=>e>=48&&e<=57,xt=Object.create(null);function St(e){let t=+(e.charCodeAt(0)===65279),n=e.length,r,i=Object.create(null),a=new Set([`String`,`Int`,`Float`,`Boolean`,`ID`]),o=new Set;function s(){for(;;){if(t>=n)return;let r=e.charCodeAt(t);if(r===32||r===9||r===10||r===13||r===44){t++;continue}if(r===35){for(;++t<n;){let n=e.charCodeAt(t);if(n===10||n===13)break}continue}if(r===34&&e.charCodeAt(t+1)===34&&e.charCodeAt(t+2)===34){for(t+=3;t<n;){if(e.charCodeAt(t)===34&&e.charCodeAt(t+1)===34&&e.charCodeAt(t+2)===34){t+=3;break}t+=e.charCodeAt(t)===92?2:1}continue}if(r===34){for(t++;t<n;){let n=e.charCodeAt(t++);if(n===92)t++;else if(n===34)break}return`\0s`}if(vt(r)){let r=t++;for(;t<n&&yt(e.charCodeAt(t));)t++;return e.slice(r,t)}if(bt(r)||r===45&&bt(e.charCodeAt(t+1))){for(t++;t<n;){let n=e.charCodeAt(t);if(bt(n)||n===46||n===101||n===69||n===43||n===45)t++;else break}return`\0n`}if(r===46&&e.charCodeAt(t+1)===46&&e.charCodeAt(t+2)===46)return t+=3,`...`;if(r===123||r===125||r===40||r===41||r===91||r===93||r===58||r===33||r===61||r===36||r===64||r===124||r===38)return t++,String.fromCharCode(r);t++}}let c=()=>r??=s(),l=()=>{let e=r??s();return r=void 0,e},u=e=>c()===e&&(l(),!0),d=e=>{let t=l();if(t!==e)throw Error(`parseSDL: expected "${e}", got "${t??`EOF`}"`)},f=()=>{let e=l();if(!e||e===`\0s`||e===`\0n`||!vt(e.charCodeAt(0)))throw Error(`parseSDL: expected NAME, got "${e??`EOF`}"`);return e};function p(){if(u(`[`)){let e=`[${p()}]`;return d(`]`),u(`!`)&&(e+=`!`),e}let e=f();return u(`!`)&&(e+=`!`),e}function m(){if(u(`[`)){for(;c()&&c()!==`]`;)m();d(`]`);return}if(u(`{`)){for(;c()&&c()!==`}`;)f(),d(`:`),m();d(`}`);return}l()}function h(){for(;u(`@`);){if(f(),!u(`(`))continue;let e=1;for(;e&&c();)u(`(`)?e++:u(`)`)?e--:l()}}function g(){if(!u(`(`))return _t;let e=Object.create(null);for(;c()&&c()!==`)`;){let t=f();d(`:`),e[t]=p(),u(`=`)&&m(),h()}return d(`)`),e}function _(){let e=Object.create(null);for(d(`{`);c()&&c()!==`}`;){let t=f(),n=g();d(`:`);let r=p();h(),e[t]={name:t,args:n,type:r}}return d(`}`),e}function v(){let e=f();if(u(`implements`))for(u(`&`);c()&&c()!==`{`;)l();h(),c()===`{`&&(i[e]={name:e,fields:_()})}function y(){a.add(f()),h()}function b(){if(o.add(f()),h(),u(`{`)){for(;c()&&c()!==`}`;)l(),h();d(`}`)}}for(;c();)switch(l()){case`type`:v();break;case`scalar`:y();break;case`enum`:b()}return{query:i.Query?.fields||{},mutation:i.Mutation?.fields||{},types:i,scalars:a,enums:o}}function Ct(e){let t=0,n=e.length,r=e.charCodeAt(0),i=e.charCodeAt(n-1);if(r!==91&&r!==33&&i!==93&&i!==33)return e;let a=xt[e];if(a)return a;for(;t<n;){let n=e.charCodeAt(t);if(n!==91&&n!==33)break;t++}for(;n>t;){let t=e.charCodeAt(n-1);if(t!==93&&t!==33)break;n--}let o=e.slice(t,n);return xt[e]=o,o}function wt(e,t,n={}){let r=e.types[Ct(t.type)];if(!r)return[];let i=[],a=r.fields;for(let t in a){let r=a[t],o=n[t];if(o!==!1){if(!e.types[Ct(r.type)]){i.push(t);continue}o!==void 0&&i.push({name:t,fields:wt(e,r,o===!0?{}:o)})}}return i}function Tt(e,t=` `){let n=``;for(let r of e){if(n&&(n+=`
33
- `),typeof r==`string`){n+=t+r;continue}let e=Tt(r.fields,t+` `);n+=e?`${t}${r.name} {\n${e}\n${t}}`:t+r.name}return n}function Et(e,t=`query`){let{name:n,args:r=_t,fields:i=[]}=e,a=``,o=``;for(let e in r)a&&(a+=`, `),a+=`$${e}: ${r[e]}`,o+=`${o?`
34
- `:``} ${e}: $${e}`;let s=Tt(i),c=`${t} ${n}`;return a&&(c+=`(${a})`),c+=` {\n ${n}`,o&&(c+=`(\n${o}\n )`),s&&(c+=` {\n${s}\n }`),c+`
35
- }`}function Dt(e,t){if(t==null)return t;switch(e){case`Int`:{let e=Number.parseInt(t,10);return Number.isNaN(e)?void 0:e}case`Float`:{let e=Number.parseFloat(t);return Number.isNaN(e)?void 0:e}case`Boolean`:return t===`false`||t===`0`?!1:!!t;case`String`:case`ID`:return String(t);case`JsonString`:return typeof t==`string`?t:JSON.stringify(t);default:return t}}function Ot(e,t=!1){if(t)return[];switch(e){case`Int`:return 0;case`Float`:return 0;case`Boolean`:return!1;case`String`:case`ID`:return``;case`JsonString`:return`{}`;default:return null}}function kt(e){return!!(e==null||e===``||Array.isArray(e)&&e.length===0)}function At(e={},t=_t,n=!0){if(!e||!t)return e;let r={};for(let i in e){let a=t[i];if(!a)continue;let o=e[i];if(n&&kt(o))continue;let s=a.endsWith(`!`),c=a.replace(/!$/,``),l=c.startsWith(`[`)&&c.endsWith(`]`),u=l?c.slice(1,-1).replace(/!$/,``):c,d=/\[.*!\]/.test(a);if(o===null){if(s){let e=Ot(u,l);(!n||!kt(e))&&(r[i]=e)}else n||(r[i]=null);continue}if(o!==void 0){if(l){let e=(Array.isArray(o)?o:typeof o==`string`?o.split(`,`).map(e=>e.trim()).filter(e=>e.length>0):[o]).map(e=>Dt(u,e)).filter(e=>d?e!=null:e!==void 0);if(n&&e.length===0)continue;(e.length>0||!s)&&(r[i]=e)}else{let e=Dt(u,o);if(e===void 0||n&&kt(e))continue;r[i]=e}}}return r}const jt=Et;export{ht as base64decode,mt as base64encode,Et as buildGraphQLQuery,jt as buildQuery,wt as buildSelectionFields,ut as decodeData,ct as decrypt,lt as encodeData,st as encrypt,$ as env,At as formatVariables,dt as getSign,et as initPassword,e as md5,gt as paramProcess,ft as paramsStrSort,St as parseSDL,pt as randomString,tt as setEnv,Ct as unwrapType};
32
+ `,e+=`-----END PUBLIC KEY-----`,e},t.hasPublicKeyProperty=function(e){return e||={},e.hasOwnProperty(`n`)&&e.hasOwnProperty(`e`)},t.hasPrivateKeyProperty=function(e){return e||={},e.hasOwnProperty(`n`)&&e.hasOwnProperty(`e`)&&e.hasOwnProperty(`d`)&&e.hasOwnProperty(`p`)&&e.hasOwnProperty(`q`)&&e.hasOwnProperty(`dmp1`)&&e.hasOwnProperty(`dmq1`)&&e.hasOwnProperty(`coeff`)},t.prototype.parsePropertiesFrom=function(e){this.n=e.n,this.e=e.e,e.hasOwnProperty(`d`)&&(this.d=e.d,this.p=e.p,this.q=e.q,this.dmp1=e.dmp1,this.dmq1=e.dmq1,this.coeff=e.coeff)},t}(Ue),Ze=`3.2.1`,Qe=function(){function e(e){e===void 0&&(e={}),e||={},this.default_key_size=e.default_key_size?parseInt(e.default_key_size,10):1024,this.default_public_exponent=e.default_public_exponent||`010001`,this.log=e.log||!1,this.key=null}return e.prototype.setKey=function(e){this.log&&this.key&&console.warn(`A key was already set, overriding existing.`),this.key=new Xe(e)},e.prototype.setPrivateKey=function(e){this.setKey(e)},e.prototype.setPublicKey=function(e){this.setKey(e)},e.prototype.decrypt=function(e){try{return this.getKey().decrypt(_e(e))}catch{return!1}},e.prototype.encrypt=function(e){try{return N(this.getKey().encrypt(e))}catch{return!1}},e.prototype.encryptLong=function(e){try{return N(this.getKey().encryptLong(e))}catch{return!1}},e.prototype.decryptLong=function(e){try{return this.getKey().decryptLong(_e(e))}catch{return!1}},e.prototype.sign=function(e,t,n){try{return N(this.getKey().sign(e,t,n))}catch{return!1}},e.prototype.verify=function(e,t,n){try{return this.getKey().verify(e,_e(t),n)}catch{return!1}},e.prototype.getKey=function(e){if(!this.key){if(this.key=new Xe,e&&{}.toString.call(e)===`[object Function]`){this.key.generateAsync(this.default_key_size,this.default_public_exponent,e);return}this.key.generate(this.default_key_size,this.default_public_exponent)}return this.key},e.prototype.getPrivateKey=function(){return this.getKey().getPrivateKey()},e.prototype.getPrivateKeyB64=function(){return this.getKey().getPrivateBaseKeyB64()},e.prototype.getPublicKey=function(){return this.getKey().getPublicKey()},e.prototype.getPublicKeyB64=function(){return this.getKey().getPublicBaseKeyB64()},e.version=Ze,e}();const Q=globalThis,$e=new Qe;let $={};const et=()=>e(new Date().getTime()+pt(32));function tt(e){$=Object.assign({PROD:!1,VITE_SALT_KEY:``,VITE_PUBLIC_KEY:``},e),$e.setPublicKey($?.VITE_PUBLIC_KEY)}function nt(e){let t=encodeURIComponent(e),n=[];for(let e=0;e<t.length;e++)t.charCodeAt(e)===37?(n.push(parseInt(t.slice(e+1,e+3),16)),e+=2):n.push(t.charCodeAt(e));return new Uint8Array(n)}function rt(e){let t=``;for(let n=0;n<e.length;n++)t+=`%${e[n].toString(16).padStart(2,`0`)}`;return decodeURIComponent(t)}function it(e){let t=e.slice().buffer;if(Q.wx?.arrayBufferToBase64)return Q.wx.arrayBufferToBase64(t);if(Q.uni?.arrayBufferToBase64)return Q.uni.arrayBufferToBase64(t);let n=``;for(let t=0;t<e.length;t++)n+=String.fromCharCode(e[t]);return Q.btoa(n)}function at(e){if(Q.wx?.base64ToArrayBuffer)return new Uint8Array(Q.wx.base64ToArrayBuffer(e));if(Q.uni?.base64ToArrayBuffer)return new Uint8Array(Q.uni.base64ToArrayBuffer(e));let t=Q.atob(e),n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n}function ot(e,t){let n=nt(e),r=nt(t);if(n.length!==16||r.length!==16)throw Error(`AES-128 key 和 iv 必须都是 16 bytes`);return le(n,r)}function st(e,t,n){return it(ot(t,n).encrypt(nt(e)))}function ct(e,t,n){return rt(ot(t,n).decrypt(at(e)))}function lt(e,t){return{value:st(JSON.stringify(e),t.substring(0,16),t.substring(16)),key:$e.encrypt(t)}}function ut(e,t){if(e.data){e.data=ct(e.data,t.substring(0,16),t.substring(16));try{e.data=JSON.parse(e.data||`{}`)}catch(e){console.error(e)}}return e}function dt(e){if(typeof e==`string`)return ft(e);if(e&&typeof e==`object`){let t=[];for(let n of Object.keys(e))e[n]&&t.push(`${n}=${e[n]}`);return ft(t.join(`&`))}return``}function ft(t){return e(`${t.split(`&`).sort().join(`&`)}&key=${$?.VITE_SALT_KEY}`)}function pt(e){let t=``;for(;e--;)t+=`0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`[Math.floor(Math.random()*62)];return t}function mt(e){return it(nt(e))}function ht(e){return rt(at(e))}function gt(e,t){let n=JSON.parse(JSON.stringify(e)),r=dt(n.data.variables);return n.data.variables.sign=r,$?.PROD&&(n.data=lt(n.data,t)),n}function _t(e,t,n){function r(e,t){if(typeof e!=`object`||!e||Array.isArray(e))return e;let n={...e};for(let r of Object.keys(e))Object.prototype.hasOwnProperty.call(t,r)&&(n[r]=i(e[r],t[r].type));return n}function i(e,t){if(e==null)return e;let a=t.endsWith(`!`)?t.slice(0,-1):t;if(a.startsWith(`[`)&&a.endsWith(`]`))return Array.isArray(e)?e.map(e=>i(e,a.slice(1,-1))):e;switch(a){case`JsonString`:if(typeof e!=`string`)return e;try{return JSON.parse(e)}catch{return e}case`Int`:case`Float`:{if(typeof e!=`number`&&typeof e!=`string`||typeof e==`string`&&e.trim()===``)return e;let t=Number(e);return Number.isFinite(t)&&(a!==`Int`||Number.isSafeInteger(t))?t:e}case`Boolean`:return e===`false`||e===`0`||e===0?!1:e===`true`||e===`1`||e===1||e;case`String`:case`ID`:return typeof e==`number`||typeof e==`boolean`?String(e):e;default:{let t=n?.types,i=t&&Object.prototype.hasOwnProperty.call(t,a)?t[a]:void 0;return i?r(e,i.fields):e}}}return e.map(e=>t?r(e,t):{...e})}const vt=Object.freeze(Object.create(null)),yt=e=>e===95||e>=65&&e<=90||e>=97&&e<=122,bt=e=>yt(e)||e>=48&&e<=57,xt=e=>e>=48&&e<=57,St=Object.create(null);function Ct(e){let t=+(e.charCodeAt(0)===65279),n=e.length,r,i=Object.create(null),a=new Set([`String`,`Int`,`Float`,`Boolean`,`ID`]),o=new Set;function s(){for(;;){if(t>=n)return;let r=e.charCodeAt(t);if(r===32||r===9||r===10||r===13||r===44){t++;continue}if(r===35){for(;++t<n;){let n=e.charCodeAt(t);if(n===10||n===13)break}continue}if(r===34&&e.charCodeAt(t+1)===34&&e.charCodeAt(t+2)===34){for(t+=3;t<n;){if(e.charCodeAt(t)===34&&e.charCodeAt(t+1)===34&&e.charCodeAt(t+2)===34){t+=3;break}t+=e.charCodeAt(t)===92?2:1}continue}if(r===34){for(t++;t<n;){let n=e.charCodeAt(t++);if(n===92)t++;else if(n===34)break}return`\0s`}if(yt(r)){let r=t++;for(;t<n&&bt(e.charCodeAt(t));)t++;return e.slice(r,t)}if(xt(r)||r===45&&xt(e.charCodeAt(t+1))){for(t++;t<n;){let n=e.charCodeAt(t);if(xt(n)||n===46||n===101||n===69||n===43||n===45)t++;else break}return`\0n`}if(r===46&&e.charCodeAt(t+1)===46&&e.charCodeAt(t+2)===46)return t+=3,`...`;if(r===123||r===125||r===40||r===41||r===91||r===93||r===58||r===33||r===61||r===36||r===64||r===124||r===38)return t++,String.fromCharCode(r);t++}}let c=()=>r??=s(),l=()=>{let e=r??s();return r=void 0,e},u=e=>c()===e&&(l(),!0),d=e=>{let t=l();if(t!==e)throw Error(`parseSDL: expected "${e}", got "${t??`EOF`}"`)},f=()=>{let e=l();if(!e||e===`\0s`||e===`\0n`||!yt(e.charCodeAt(0)))throw Error(`parseSDL: expected NAME, got "${e??`EOF`}"`);return e};function p(){if(u(`[`)){let e=`[${p()}]`;return d(`]`),u(`!`)&&(e+=`!`),e}let e=f();return u(`!`)&&(e+=`!`),e}function m(){if(u(`[`)){for(;c()&&c()!==`]`;)m();d(`]`);return}if(u(`{`)){for(;c()&&c()!==`}`;)f(),d(`:`),m();d(`}`);return}l()}function h(){for(;u(`@`);){if(f(),!u(`(`))continue;let e=1;for(;e&&c();)u(`(`)?e++:u(`)`)?e--:l()}}function g(){if(!u(`(`))return vt;let e=Object.create(null);for(;c()&&c()!==`)`;){let t=f();d(`:`),e[t]=p(),u(`=`)&&m(),h()}return d(`)`),e}function _(){let e=Object.create(null);for(d(`{`);c()&&c()!==`}`;){let t=f(),n=g();d(`:`);let r=p();h(),e[t]={name:t,args:n,type:r}}return d(`}`),e}function v(){let e=f();if(u(`implements`))for(u(`&`);c()&&c()!==`{`;)l();h(),c()===`{`&&(i[e]={name:e,fields:_()})}function y(){a.add(f()),h()}function b(){if(o.add(f()),h(),u(`{`)){for(;c()&&c()!==`}`;)l(),h();d(`}`)}}for(;c();)switch(l()){case`type`:v();break;case`scalar`:y();break;case`enum`:b()}return{query:i.Query?.fields||{},mutation:i.Mutation?.fields||{},types:i,scalars:a,enums:o}}function wt(e){let t=0,n=e.length,r=e.charCodeAt(0),i=e.charCodeAt(n-1);if(r!==91&&r!==33&&i!==93&&i!==33)return e;let a=St[e];if(a)return a;for(;t<n;){let n=e.charCodeAt(t);if(n!==91&&n!==33)break;t++}for(;n>t;){let t=e.charCodeAt(n-1);if(t!==93&&t!==33)break;n--}let o=e.slice(t,n);return St[e]=o,o}function Tt(e,t,n={}){let r=e.types[wt(t.type)];if(!r)return[];let i=[],a=r.fields;for(let t in a){let r=a[t],o=n[t];if(o!==!1){if(!e.types[wt(r.type)]){i.push(t);continue}o!==void 0&&i.push({name:t,fields:Tt(e,r,o===!0?{}:o)})}}return i}function Et(e,t=` `){let n=``;for(let r of e){if(n&&(n+=`
33
+ `),typeof r==`string`){n+=t+r;continue}let e=Et(r.fields,t+` `);n+=e?`${t}${r.name} {\n${e}\n${t}}`:t+r.name}return n}function Dt(e,t=`query`){let{name:n,args:r=vt,fields:i=[]}=e,a=``,o=``;for(let e in r)a&&(a+=`, `),a+=`$${e}: ${r[e]}`,o+=`${o?`
34
+ `:``} ${e}: $${e}`;let s=Et(i),c=`${t} ${n}`;return a&&(c+=`(${a})`),c+=` {\n ${n}`,o&&(c+=`(\n${o}\n )`),s&&(c+=` {\n${s}\n }`),c+`
35
+ }`}function Ot(e,t){if(t==null)return t;switch(e){case`Int`:{let e=Number.parseInt(t,10);return Number.isNaN(e)?void 0:e}case`Float`:{let e=Number.parseFloat(t);return Number.isNaN(e)?void 0:e}case`Boolean`:return t===`false`||t===`0`?!1:!!t;case`String`:case`ID`:return String(t);case`JsonString`:return typeof t==`string`?t:JSON.stringify(t);default:return t}}function kt(e,t=!1){if(t)return[];switch(e){case`Int`:return 0;case`Float`:return 0;case`Boolean`:return!1;case`String`:case`ID`:return``;case`JsonString`:return`{}`;default:return null}}function At(e){return!!(e==null||e===``||Array.isArray(e)&&e.length===0)}function jt(e={},t=vt,n=!0){if(!e||!t)return e;let r={};for(let i in e){let a=t[i];if(!a)continue;let o=e[i];if(n&&At(o))continue;let s=a.endsWith(`!`),c=a.replace(/!$/,``),l=c.startsWith(`[`)&&c.endsWith(`]`),u=l?c.slice(1,-1).replace(/!$/,``):c,d=/\[.*!\]/.test(a);if(o===null){if(s){let e=kt(u,l);(!n||!At(e))&&(r[i]=e)}else n||(r[i]=null);continue}if(o!==void 0){if(l){let e=(Array.isArray(o)?o:typeof o==`string`?o.split(`,`).map(e=>e.trim()).filter(e=>e.length>0):[o]).map(e=>Ot(u,e)).filter(e=>d?e!=null:e!==void 0);if(n&&e.length===0)continue;(e.length>0||!s)&&(r[i]=e)}else{let e=Ot(u,o);if(e===void 0||n&&At(e))continue;r[i]=e}}}return r}const Mt=Dt;export{ht as base64decode,mt as base64encode,Dt as buildGraphQLQuery,Mt as buildQuery,Tt as buildSelectionFields,ut as decodeData,ct as decrypt,lt as encodeData,st as encrypt,$ as env,jt as formatVariables,dt as getSign,et as initPassword,e as md5,gt as paramProcess,ft as paramsStrSort,_t as parseResponseOptimized,Ct as parseSDL,pt as randomString,tt as setEnv,wt as unwrapType};
@@ -1,3 +1,4 @@
1
+ import type { SchemaMeta, SchemaType } from './index';
1
2
  export { md5 } from './md5';
2
3
  export declare let env: any;
3
4
  /** 生成指定长度的随机字母数字字符串。 */
@@ -26,3 +27,15 @@ export declare function base64encode(code: string): string;
26
27
  export declare function base64decode(code: string): string;
27
28
  /** 参数处理。 */
28
29
  export declare function paramProcess(param: any, password: string): any;
30
+ /**
31
+ * 按 SDL 字段类型格式化响应数组,返回新数组,不修改原数据。
32
+ * @param data 接口返回的记录数组(不是整个响应对象)
33
+ * @param fields schema.types?.['类型名']?.fields;未找到定义时保持原样
34
+ * @param schema 可选的 schema,用于递归格式化对象字段及对象数组
35
+ *
36
+ * JsonString 字符串通过 JSON.parse 还原,已解析值和无效 JSON 保持原样。
37
+ * 支持 Int/Float/Boolean/String/ID、非空修饰符及多层数组;
38
+ * 空值、缺失字段、未知字段和其他自定义标量保持原样,不补默认值。
39
+ * @example parseResponseOptimized(data, schema.types?.['User']?.fields, schema)
40
+ */
41
+ export declare function parseResponseOptimized(data: readonly Record<string, any>[], fields: SchemaType['fields'] | undefined, schema?: Pick<SchemaMeta, 'types'>): Record<string, any>[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uni2c/graphqlapi4mp",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "Lightweight GraphQL SDL parser and query builder for TypeScript, Node.js, browsers, and mini programs.",
5
5
  "keywords": [
6
6
  "graphql",