t1y-sdk-js 5.0.2 → 5.0.4
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.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/dist/umd/t1y.min.js +2 -2
- package/package.json +1 -1
package/dist/umd/t1y.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var T1Y=(()=>{var _e=Object.defineProperty;var Ct=Object.getOwnPropertyDescriptor;var Nt=Object.getOwnPropertyNames;var It=Object.prototype.hasOwnProperty;var T=(t=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(t,{get:(e,n)=>(typeof require!="undefined"?require:e)[n]}):t)(function(t){if(typeof require!="undefined")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var qt=(t,e)=>{for(var n in e)_e(t,n,{get:e[n],enumerable:!0})},Dt=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Nt(e))!It.call(t,i)&&i!==n&&_e(t,i,{get:()=>e[i],enumerable:!(r=Ct(e,i))||r.enumerable});return t};var jt=t=>Dt(_e({},"__esModule",{value:!0}),t);var vt=(t,e,n)=>{if(!e.has(t))throw TypeError("Cannot "+n)};var z=(t,e,n)=>{if(e.has(t))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(t):e.set(t,n)};var Q=(t,e,n)=>(vt(t,e,"access private method"),n);var rn={};qt(rn,{Array:()=>Pe,Bigint:()=>Se,Boolean:()=>Ee,Date:()=>we,DateTime:()=>Ae,Double:()=>ke,Empty:()=>qe,Float:()=>Ue,Integer:()=>Re,Map:()=>Me,MapArray:()=>Oe,Nil:()=>Ie,None:()=>Ne,Null:()=>Ce,ObjectID:()=>he,T1Collection:()=>D,T1YError:()=>E,T1YOS:()=>J,TimeNow:()=>ne,TimeNowUnix:()=>re,TimeNowUnixNano:()=>oe,TimeNowWeekday:()=>se,TimeNowWeekdayChinese:()=>ie,Timestamp:()=>Te,UNDEFINED:()=>De,Undefined:()=>je,ValidationError:()=>b,assertObjectID:()=>S,convertDateTypes:()=>M,createSignature:()=>L,decryptAESGCM:()=>G,default:()=>kt,encryptAESGCM:()=>$,formatTimestampsToLocal:()=>q,getMiniProgramAPI:()=>Y,getMiniProgramSubType:()=>W,getPlatformType:()=>N,getSafeTimestamp:()=>K,hmacSHA256Hex:()=>P,hmacSHA256HexAsync:()=>fe,isAESGCMAvailable:()=>le,isNonEmptyArrayWithNonEmptyObjects:()=>O,isNonEmptyObject:()=>h,isPlainObject:()=>R,isWebCryptoAvailable:()=>ye,resetPlatformDetection:()=>me,sha256Hex:()=>v,sha256HexAsync:()=>ue,timeNow:()=>ve,validateApiKey:()=>Z,validateAppId:()=>V,validateInitConfig:()=>j,validateSecretKey:()=>X,verifyHmacSHA256:()=>B});var Qe="https://myapp.t1y.net";var ae="YYYY-MM-DD HH:mm:ss";var ce=/^[0-9a-fA-F]{24}$/;var E=class extends Error{constructor(e,n,r){super(n),this.name="T1YError",this.code=e,this.data=r}toJSON(){return{name:this.name,code:this.code,message:this.message,data:this.data}}},b=class extends Error{constructor(e){super(e),this.name="ValidationError"}};function V(t){if(!Number.isInteger(t))throw new b("appId must be an integer");if(t<1001)throw new b(`appId must be >= ${1001}`)}function Z(t){if(typeof t!="string")throw new b("apiKey must be a string");if(t.length!==32)throw new b(`apiKey must be exactly ${32} characters (got ${t.length})`)}function X(t){if(typeof t!="string")throw new b("secretKey must be a string");if(t.length!==32)throw new b(`secretKey must be exactly ${32} characters (got ${t.length})`)}function Fe(t){if(!/^https?:\/\//.test(t))throw new b('baseUrl must start with "http://" or "https://"')}function j(t){if(t.baseUrl!==void 0&&Fe(t.baseUrl),V(t.appId),Z(t.apiKey),X(t.secretKey),t.version!==void 0&&(!Number.isInteger(t.version)||t.version<0))throw new b("version must be a non-negative integer")}function S(t,e="ObjectID"){if(typeof t!="string")throw new b(`${e} must be a string`);if(!ce.test(t))throw new b(`Invalid ${e} string: "${t}"`);return!0}function M(t){if(t instanceof Date)return`Date('${t.toISOString()}')`;if(typeof t=="number"){let e=String(t);return/^\d{10,}$/.test(e)?`Timestamp('${e}')`:t}if(Array.isArray(t))return t.map(e=>M(e));if(t&&typeof t=="object"){let e={};for(let n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=M(t[n]));return e}return t}function h(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)&&Object.keys(t).length>0}function R(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function O(t){return!Array.isArray(t)||t.length===0?!1:t.every(e=>typeof e=="object"&&e!==null&&!Array.isArray(e)&&Object.keys(e).length>0)}function et(){try{if(typeof T!="undefined")return T}catch(t){}return null}function v(t){let e=et();if(e)try{return e("node:crypto").createHash("sha256").update(t).digest("hex")}catch(r){}let n=Bt(t);return ee(n)}function ee(t){return _t(t)}async function ue(t){let e=et();if(e)try{return e("node:crypto").createHash("sha256").update(t).digest("hex")}catch(i){}let n=new TextEncoder,r=await crypto.subtle.digest("SHA-256",n.encode(t));return Array.from(new Uint8Array(r)).map(i=>i.toString(16).padStart(2,"0")).join("")}function Bt(t){if(typeof TextEncoder!="undefined")return new TextEncoder().encode(t);let e=[];for(let n=0;n<t.length;n++){let r=t.charCodeAt(n);if(r<128)e.push(r);else if(r<2048)e.push(192|r>>6,128|r&63);else if(r<55296||r>=57344)e.push(224|r>>12,128|r>>6&63,128|r&63);else{n++;let i=t.charCodeAt(n),o=65536+((r&1023)<<10)+(i&1023);e.push(240|o>>18,128|o>>12&63,128|o>>6&63,128|o&63)}}return new Uint8Array(e)}function Ht(t,e,n){let r=Math.floor(n/4294967296),i=n%4294967296;t[e]=r>>>24&255,t[e+1]=r>>>16&255,t[e+2]=r>>>8&255,t[e+3]=r&255,t[e+4]=i>>>24&255,t[e+5]=i>>>16&255,t[e+6]=i>>>8&255,t[e+7]=i&255}function _t(t){let e=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],n=t.length,r=n*8,i=(64-(n+9)%64)%64,o=n+1+i+8,c=new Uint8Array(o);c.set(t),c[n]=128,Ht(c,o-8,r);let s=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225];for(let a=0;a<o;a+=64){let u=new Array(64);for(let d=0;d<16;d++)u[d]=c[a+d*4]<<24|c[a+d*4+1]<<16|c[a+d*4+2]<<8|c[a+d*4+3];for(let d=16;d<64;d++){let Be=(k(u[d-15],7)^k(u[d-15],18)^u[d-15]>>>3)>>>0,He=(k(u[d-2],17)^k(u[d-2],19)^u[d-2]>>>10)>>>0;u[d]=u[d-16]+Be+u[d-7]+He>>>0}let[p,f,y,m,l,g,A,x]=s;for(let d=0;d<64;d++){let Be=(k(l,6)^k(l,11)^k(l,25))>>>0,He=(l&g^~l&A)>>>0,ze=x+Be+He+e[d]+u[d]>>>0,Pt=(k(p,2)^k(p,13)^k(p,22))>>>0,Mt=(p&f^p&y^f&y)>>>0,Ot=Pt+Mt>>>0;x=A,A=g,g=l,l=m+ze>>>0,m=y,y=f,f=p,p=ze+Ot>>>0}s[0]=s[0]+p>>>0,s[1]=s[1]+f>>>0,s[2]=s[2]+y>>>0,s[3]=s[3]+m>>>0,s[4]=s[4]+l>>>0,s[5]=s[5]+g>>>0,s[6]=s[6]+A>>>0,s[7]=s[7]+x>>>0}return s.map(a=>a.toString(16).padStart(8,"0")).join("")}function k(t,e){return t>>>e|t<<32-e}function st(){try{if(typeof T!="undefined")return T}catch(t){}return null}function P(t,e){let n=st();if(n)try{return n("node:crypto").createHmac("sha256",t).update(e).digest("hex")}catch(r){}return $t(t,e)}async function fe(t,e){let n=st();if(n)try{return n("node:crypto").createHmac("sha256",t).update(e).digest("hex")}catch(c){}let r=new TextEncoder,i=await crypto.subtle.importKey("raw",r.encode(t),{name:"HMAC",hash:"SHA-256"},!1,["sign"]),o=await crypto.subtle.sign("HMAC",i,r.encode(e));return Array.from(new Uint8Array(o)).map(c=>c.toString(16).padStart(2,"0")).join("")}function B(t,e,n){if(typeof n!="string")return!1;let r=P(t,e);return Ft(r,n.toLowerCase())}function Ft(t,e){if(t.length!==e.length)return!1;let n=0;for(let r=0;r<t.length;r++)n|=t.charCodeAt(r)^e.charCodeAt(r);return n===0}function $t(t,e){let r=rt(t),i=rt(e);r.length>64&&(r=ot(ee(r)));let o=new Uint8Array(64);o.set(r.subarray(0,Math.min(r.length,64)));let c=new Uint8Array(64);c.fill(54);let s=nt(o,c),a=new Uint8Array(64+i.length);a.set(s),a.set(i,64);let u=ot(ee(a)),p=new Uint8Array(64);p.fill(92);let f=nt(o,p),y=new Uint8Array(64+u.length);return y.set(f),y.set(u,64),ee(y)}function nt(t,e){let n=new Uint8Array(t.length);for(let r=0;r<t.length;r++)n[r]=t[r]^e[r];return n}function rt(t){if(typeof TextEncoder!="undefined")return new TextEncoder().encode(t);let e=[];for(let n=0;n<t.length;n++){let r=t.charCodeAt(n);if(r<128)e.push(r);else if(r<2048)e.push(192|r>>6,128|r&63);else if(r<55296||r>=57344)e.push(224|r>>12,128|r>>6&63,128|r&63);else{n++;let i=t.charCodeAt(n),o=65536+((r&1023)<<10)+(i&1023);e.push(240|o>>18,128|o>>12&63,128|o>>6&63,128|o&63)}}return new Uint8Array(e)}function ot(t){let e=new Uint8Array(t.length/2);for(let n=0;n<t.length;n+=2)e[n/2]=parseInt(t.substring(n,n+2),16);return e}var te=[99,124,119,123,242,107,111,197,48,1,103,43,254,215,171,118,202,130,201,125,250,89,71,240,173,212,162,175,156,164,114,192,183,253,147,38,54,63,247,204,52,165,229,241,113,216,49,21,4,199,35,195,24,150,5,154,7,18,128,226,235,39,178,117,9,131,44,26,27,110,90,160,82,59,214,179,41,227,47,132,83,209,0,237,32,252,177,91,106,203,190,57,74,76,88,207,208,239,170,251,67,77,51,133,69,249,2,127,80,60,159,168,81,163,64,143,146,157,56,245,188,182,218,33,16,255,243,210,205,12,19,236,95,151,68,23,196,167,126,61,100,93,25,115,96,129,79,220,34,42,144,136,70,238,184,20,222,94,11,219,224,50,58,10,73,6,36,92,194,211,172,98,145,149,228,121,231,200,55,109,141,213,78,169,108,86,244,234,101,122,174,8,186,120,37,46,28,166,180,198,232,221,116,31,75,189,139,138,112,62,181,102,72,3,246,14,97,53,87,185,134,193,29,158,225,248,152,17,105,217,142,148,155,30,135,233,206,85,40,223,140,161,137,13,191,230,66,104,65,153,45,15,176,84,187,22],Gt=[1,2,4,8,16,32,64,128,27,54];function Le(t){if(t.length!==32)throw new Error("AES-256 requires a 32-byte key");let e=8,n=14,i=4*(n+1),o=new Array(i);for(let s=0;s<e;s++)o[s]=t[4*s]<<24|t[4*s+1]<<16|t[4*s+2]<<8|t[4*s+3];for(let s=e;s<i;s++){let a=o[s-1];s%e===0?a=it(Lt(a))^Gt[Math.floor(s/e)-1]<<24:e>6&&s%e===4&&(a=it(a)),o[s]=o[s-e]^a}let c=[];for(let s=0;s<=n;s++){let a=new Uint8Array(16);for(let u=0;u<4;u++){let p=o[s*4+u];a[4*u]=p>>>24&255,a[4*u+1]=p>>>16&255,a[4*u+2]=p>>>8&255,a[4*u+3]=p&255}c.push(a)}return c}function Lt(t){return(t<<8|t>>>24)>>>0}function it(t){return(te[t>>>24&255]<<24|te[t>>>16&255]<<16|te[t>>>8&255]<<8|te[t&255]<<0)>>>0}function Ke(t,e){if(t.length!==16)throw new Error("AES block must be exactly 16 bytes");let n=[[],[],[],[]];for(let o=0;o<4;o++)for(let c=0;c<4;c++)n[c][o]=t[o*4+c];let r=14;$e(n,e[0]);for(let o=1;o<r;o++)at(n),ct(n),Kt(n),$e(n,e[o]);at(n),ct(n),$e(n,e[r]);let i=new Uint8Array(16);for(let o=0;o<4;o++)for(let c=0;c<4;c++)i[o*4+c]=n[c][o];return i}function at(t){for(let e=0;e<4;e++)for(let n=0;n<4;n++)t[e][n]=te[t[e][n]]}function ct(t){for(let e=1;e<4;e++){let n=t[e];t[e]=[n[e%4],n[(e+1)%4],n[(e+2)%4],n[(e+3)%4]]}}function Kt(t){for(let e=0;e<4;e++){let n=[];for(let r=0;r<4;r++)n[r]=t[r][e];t[0][e]=C(2,n[0])^C(3,n[1])^n[2]^n[3],t[1][e]=n[0]^C(2,n[1])^C(3,n[2])^n[3],t[2][e]=n[0]^n[1]^C(2,n[2])^C(3,n[3]),t[3][e]=C(3,n[0])^n[1]^n[2]^C(2,n[3])}}function $e(t,e){for(let n=0;n<4;n++)for(let r=0;r<4;r++)t[r][n]=t[r][n]^e[n*4+r]}function C(t,e){let n=0,r=t,i=e;for(let o=0;o<8;o++){i&1&&(n^=r);let c=r&128;r=r<<1&255,c&&(r^=27),i>>=1}return n}function pe(t,e,n){let r=Le(t),i=Math.ceil(n.length/16),o=new Uint8Array(n.length),c=new Uint8Array(e);for(let s=0;s<i;s++){let a=Ke(c,r),u=Math.min(16,n.length-s*16);for(let p=0;p<u;p++)o[s*16+p]=n[s*16+p]^a[p];We(c)}return o}function We(t){for(let e=15;e>=12;e--){let n=t[e]+1;if(t[e]=n&255,n<=255)break}}function ut(t,e,n){let r=Math.floor(n/4294967296),i=n%4294967296;t[e]=r>>>24&255,t[e+1]=r>>>16&255,t[e+2]=r>>>8&255,t[e+3]=r&255,t[e+4]=i>>>24&255,t[e+5]=i>>>16&255,t[e+6]=i>>>8&255,t[e+7]=i&255}function ft(t,e,n){let i=Math.ceil(e.length/16),o=Math.ceil(n.length/16),c=i+o+1,s=new Uint8Array(16);for(let y=0;y<i;y++){let m=new Uint8Array(16),l=y*16,g=Math.min(16,e.length-l);for(let x=0;x<g;x++)m[x]=e[l+x];for(let x=0;x<16;x++)m[x]^=s[x];let A=Ge(m,t);s.set(A)}for(let y=0;y<o;y++){let m=new Uint8Array(16),l=y*16,g=Math.min(16,n.length-l);for(let x=0;x<g;x++)m[x]=n[l+x];for(let x=0;x<16;x++)m[x]^=s[x];let A=Ge(m,t);s.set(A)}let a=new Uint8Array(16),u=e.length*8,p=n.length*8;ut(a,0,u),ut(a,8,p);for(let y=0;y<16;y++)a[y]^=s[y];return Ge(a,t)}function Ge(t,e){let n=new Uint8Array(16),r=new Uint8Array(e);for(let i=0;i<16;i++)for(let o=0;o<8;o++){if(t[15-i]>>7-o&1)for(let s=0;s<16;s++)n[s]^=r[s];let c=r[15]&1;for(let s=15;s>0;s--)r[s]=r[s]>>1|(r[s-1]&1)<<7;r[0]=r[0]>>1,c&&(r[0]^=225)}return n}function pt(t,e,n,r=new Uint8Array(0)){if(e.length!==32)throw new Error("key length must be 32 bytes for AES-256-GCM");if(n.length!==12)throw new Error("nonce length must be 12 bytes for AES-256-GCM");let i=new Uint8Array(16);i.set(n),i[15]=1;let o=Le(e),c=new Uint8Array(16),s=Ke(c,o),a=new Uint8Array(16);a.set(n),a[15]=1;let u=new Uint8Array(a);We(u);let p=pe(e,u,t),f=ft(s,r,p),y=pe(e,a,f),m=new Uint8Array(16);for(let l=0;l<16;l++)m[l]=f[l]^y[l];return{ciphertext:p,tag:m}}function lt(t,e,n,r,i=new Uint8Array(0)){if(n.length!==32)throw new Error("key length must be 32 bytes for AES-256-GCM");if(r.length!==12)throw new Error("nonce length must be 12 bytes for AES-256-GCM");if(e.length!==16)throw new Error("tag length must be 16 bytes for AES-256-GCM");let o=Le(n),c=new Uint8Array(16),s=Ke(c,o),a=new Uint8Array(16);a.set(r),a[15]=1;let u=ft(s,i,t),p=pe(n,a,u),f=new Uint8Array(16);for(let l=0;l<16;l++)f[l]=u[l]^p[l];let y=0;for(let l=0;l<16;l++)y|=e[l]^f[l];if(y!==0)throw new Error("AES-256-GCM authentication failed: tag mismatch");let m=new Uint8Array(a);return We(m),pe(n,m,t)}function F(){try{if(typeof globalThis!="undefined"){if(typeof globalThis.crypto!="undefined"&&globalThis.crypto.subtle)return globalThis.crypto;try{let t=typeof T!="undefined"?T:null;if(t){let e=t("node:crypto");if(e!=null&&e.webcrypto)return e.webcrypto}}catch(t){}}}catch(t){}return null}function le(){return!0}function ye(){return F()!==null}var yt=16,mt=12;function Wt(t){let e=F();if(e){let r=new Uint8Array(t);return e.getRandomValues(r),r}try{if(typeof wx!="undefined"&&typeof wx.getRandomValues=="function"){let r=new Uint8Array(t);return wx.getRandomValues(r),r}}catch(r){}let n=new Uint8Array(t);for(let r=0;r<t;r++)n[r]=Math.floor(Math.random()*256);return n}function H(t){let e="",n=t.byteLength;for(let r=0;r<n;r++)e+=String.fromCharCode(t[r]);return btoa(e)}function _(t){let e=atob(t),n=e.length,r=new Uint8Array(n);for(let i=0;i<n;i++)r[i]=e.charCodeAt(i);return r}async function Yt(t,e){let n=F();if(!n)throw new Error("Web Crypto API is not available");let r=await n.subtle.importKey("raw",e,"AES-GCM",!1,["encrypt"]),i=new Uint8Array(mt);n.getRandomValues(i);let o=new TextEncoder().encode(t),c=new Uint8Array(await n.subtle.encrypt({name:"AES-GCM",iv:i,tagLength:128},r,o)),s=c.slice(0,c.length-yt),a=c.slice(c.length-yt),u={n:H(i),j:H(s),t:H(a)};return JSON.stringify(u)}async function Jt(t,e){let n=F();if(!n)throw new Error("Web Crypto API is not available");let{n:r,j:i,t:o}=JSON.parse(t),c=_(r),s=_(i),a=_(o),u=new Uint8Array(s.length+a.length);u.set(s),u.set(a,s.length);let p=await n.subtle.importKey("raw",e,"AES-GCM",!1,["decrypt"]),f=await n.subtle.decrypt({name:"AES-GCM",iv:c,tagLength:128},p,u);return new TextDecoder().decode(f)}function zt(t,e){let n=Wt(mt),r=new TextEncoder().encode(t),{ciphertext:i,tag:o}=pt(r,e,n),c={n:H(n),j:H(i),t:H(o)};return JSON.stringify(c)}function Qt(t,e){let{n,j:r,t:i}=JSON.parse(t),o=_(n),c=_(r),s=_(i),a=lt(c,s,e,o);return new TextDecoder().decode(a)}async function $(t,e){if(!(e instanceof Uint8Array))throw new Error("key must be Uint8Array");if(e.length!==32)throw new Error("key length must be 32 bytes for AES-256-GCM");return F()?await Yt(t,e):zt(t,e)}async function G(t,e){if(!(e instanceof Uint8Array))throw new Error("key must be Uint8Array");if(e.length!==32)throw new Error("key length must be 32 bytes for AES-256-GCM");return F()?await Jt(t,e):Qt(t,e)}function L(t){let{method:e,pathAndQuery:n,body:r,appId:i,timestamp:o,secretKey:c}=t,s=v(r),a=[e.toUpperCase(),n,s,String(i),String(o)].join(`
|
|
2
|
-
`);return P(c,a)}function K(t){return String(Math.floor(Date.now()/1e3)+t)}function dt(t){return t.replace(/\/+$/,"")}function xt(t,e){for(let n of Object.keys(e)){let r=e[n];r!=null&&t.searchParams.set(n,typeof r=="string"?r:JSON.stringify(r))}}function Vt(t,e){let n=new Date(t);if(isNaN(n.getTime()))return t;let r=i=>String(i).padStart(2,"0");return e.replace("YYYY",String(n.getFullYear())).replace("MM",r(n.getMonth()+1)).replace("DD",r(n.getDate())).replace("HH",r(n.getHours())).replace("mm",r(n.getMinutes())).replace("ss",r(n.getSeconds()))}function q(t,e=ae){function n(r){if(Array.isArray(r))return r.map(n);if(r&&typeof r=="object"){let i={};for(let o in r)Object.prototype.hasOwnProperty.call(r,o)&&(o==="createdAt"||o==="updatedAt"?i[o]=Vt(r[o],e):i[o]=n(r[o]));return i}return r}return n(t)}async function gt(t,e,n,r){let i=t.headers["content-type"]||"",o,c=t.body;if(i.includes("application/json"))try{o=JSON.parse(c)}catch(a){o=c}else o=c;if(e&&o&&typeof o=="object"&&"j"in o)try{let a=await G(JSON.stringify(o),new TextEncoder().encode(n));try{o=JSON.parse(a)}catch(u){o=a}}catch(a){throw new E(400,"AES-256-GCM decryption failed",a instanceof Error?a.message:null)}let s=t.status>=200&&t.status<300;if(o&&typeof o=="object"&&"data"in o){let a=o;if(a.data=q(a.data,r),!s)throw new E(a.code||t.status,a.message||t.statusText,a.data);return a}if(!s)throw new E(t.status,t.statusText,o);return{code:0,message:"ok",data:q(o,r)}}function bt(t){if(t instanceof E)throw t;if(t instanceof Error){let e=t.message||"Unknown error";throw e.includes("timeout")||e.includes("\u8D85\u65F6")||t.name==="AbortError"||e.includes("abort")?new E(408,"Request timeout",null):new E(0,e,null)}throw new E(0,"Unknown error",t)}var w=null,U=null;function N(){var t;if(w!==null)return w;if(typeof wx!="undefined"&&typeof wx.request=="function")return w="wx",w;if(typeof my!="undefined"&&typeof my.request=="function")return w="my",w;if(typeof window=="undefined"&&typeof document=="undefined"&&typeof global!="undefined"&&typeof global.require=="function")try{if(typeof T!="undefined"&&typeof T("@system.fetch")!="undefined")return w="hap",w}catch(e){}return typeof window!="undefined"&&typeof document!="undefined"?(w="h5",w):typeof process!="undefined"&&typeof process.versions!="undefined"&&typeof((t=process.versions)==null?void 0:t.node)!="undefined"?(w="nodejs",w):(w="unknown",w)}function W(){return U!==null?U:N()!=="wx"?(U="unknown",U):typeof tt!="undefined"&&typeof tt.request=="function"?(U="toutiao",U):typeof qq!="undefined"&&typeof qq.request=="function"?(U="qq",U):(U="wechat",U)}function Y(){let t=N();if(t==="my")return my;if(t!=="wx")return null;switch(W()){case"toutiao":return tt;case"qq":return qq;case"wechat":default:return wx}}function me(){w=null,U=null}var Ye=async t=>{let{url:e,method:n,headers:r,body:i,signal:o}=t,c={method:n,headers:r,signal:o};i!==void 0&&n!=="GET"&&(c.body=i);let s=await fetch(e,c),a={};s.headers.forEach((p,f)=>{a[f.toLowerCase()]=p});let u=await s.text();return{status:s.status,statusText:s.statusText,headers:a,body:u}};var ht=async t=>{let e=Y();if(!e||typeof e.request!="function")throw new Error("Mini program request API is not available");let n=e.request,{url:r,method:i,headers:o,body:c,timeout:s}=t;return new Promise((a,u)=>{let p=n({url:r,method:i,header:o,data:c,timeout:s!=null?s:3e5,dataType:"text",responseType:"text",success:f=>{var l;let y={};if(f.header)for(let g of Object.keys(f.header))y[g.toLowerCase()]=f.header[g];let m;typeof f.data=="string"?m=f.data:f.data!==void 0&&f.data!==null?m=JSON.stringify(f.data):m="",a({status:f.statusCode,statusText:(l=f.errMsg)!=null?l:"",headers:y,body:m})},fail:f=>{var m;let y=(m=f.errMsg)!=null?m:"Mini program request failed";y.includes("timeout")||y.includes("\u8D85\u65F6")?u(new Error("Request timeout")):u(new Error(y))}});if(t.signal){let f=()=>{typeof p.abort=="function"&&p.abort()};t.signal.addEventListener("abort",f,{once:!0})}})};var wt=async t=>{let e=my;if(!e||typeof e.request!="function")throw new Error("Alipay mini program request API (my.request) is not available");let n=e.request,{url:r,method:i,headers:o,body:c,timeout:s}=t;return new Promise((a,u)=>{let p=n({url:r,method:i.toUpperCase(),headers:o,data:c!==void 0?c:void 0,timeout:s!=null?s:3e5,dataType:"text",success:f=>{var g,A;let y=(A=(g=f.status)!=null?g:f.statusCode)!=null?A:200,m={};if(f.headers)for(let x of Object.keys(f.headers))m[x.toLowerCase()]=f.headers[x];let l;typeof f.data=="string"?l=f.data:f.data!==void 0&&f.data!==null?l=JSON.stringify(f.data):l="",a({status:y,statusText:"",headers:m,body:l})},fail:f=>{var m,l;let y=(l=(m=f.errorMessage)!=null?m:f.errMsg)!=null?l:`Alipay request failed (error: ${f.error})`;u(new Error(y))},complete:()=>{}});if(t.signal){let f=()=>{p&&typeof p.abort=="function"&&p.abort()};t.signal.addEventListener("abort",f,{once:!0})}})};function Zt(){try{return T("@system.fetch")}catch(t){return null}}var At=async t=>{let e=Zt();if(!e)throw new Error("Quick App fetch module (@system.fetch) is not available. Ensure you are running inside a Quick App environment.");let{url:n,method:r,headers:i,body:o}=t;return new Promise((c,s)=>{e.fetch({url:n,method:r.toUpperCase(),header:i,data:o,responseType:"text",success:a=>{let u={};if(a.headers)for(let p of Object.keys(a.headers))u[p.toLowerCase()]=a.headers[p];c({status:a.code,statusText:"",headers:u,body:typeof a.data=="string"?a.data:JSON.stringify(a.data)})},fail:a=>{s(new Error(`Quick App request failed (code: ${a.code}, data: ${a.data})`))},complete:()=>{}})})};var I=null;function Tt(){if(I!==null)return I;switch(N()){case"h5":case"nodejs":I=Ye;break;case"wx":I=ht;break;case"my":I=wt;break;case"hap":I=At;break;default:if(typeof fetch=="function")I=Ye;else throw new Error("Unable to determine platform request adapter. The current environment does not have `fetch`, `wx.request`, `my.request`, or `@system.fetch` available. Please ensure you are running in a supported environment: Web browser, Node.js 18+, WeChat/QQ/Alipay/Toutiao/Douyin Mini Program, or Quick App.");break}return I}async function Je(t,e){let{method:n,path:r,params:i,encryption:o,timeout:c}=e,s=dt(t.baseUrl),a=o!=null?o:t.isSafeMode,u=new URL(s+r),p=M(i),f,y="";if(n!=="GET")if(a&&p!==void 0){let d=await $(JSON.stringify(p),new TextEncoder().encode(t.secretKey));f=d,y=d}else if(p!==void 0){let d=JSON.stringify(p);f=d,y=d}else y="";else p&&typeof p=="object"&&Object.keys(p).length>0&&xt(u,p);let m=Number(K(t.offset)),l=u.pathname+u.search,g=L({method:n,pathAndQuery:l,body:y,appId:t.appId,timestamp:m,secretKey:t.secretKey}),A=Tt(),x=c!=null?c:3e5;try{let d=await A({url:u.toString(),method:n,headers:{"X-T1Y-Application-ID":String(t.appId),"X-T1Y-API-Key":t.apiKey,"X-T1Y-Safe-Timestamp":String(m),"X-T1Y-Safe-Sign":g,"Content-Type":"application/json"},body:n!=="GET"?f:void 0,timeout:x});return await gt(d,a,t.secretKey,t.timeFormat)}catch(d){return bt(d)}}var D=class{constructor(e,n){this.client=e,this.name=n}async insertOne(e){if(!h(e))throw new TypeError("insertOne data must be a non-empty plain object");return await this.client.request("POST",`/v5/classes/${this.name}`,e)}async deleteById(e){return S(e),await this.client.request("DELETE",`/v5/classes/${this.name}/${e}`)}async updateById(e,n){if(S(e),!h(n))throw new TypeError("update data must be a non-empty plain object");return await this.client.request("PUT",`/v5/classes/${this.name}/${e}`,n)}async findById(e){return S(e),await this.client.request("GET",`/v5/classes/${this.name}/${e}`)}async deleteOne(e){if(!h(e))throw new TypeError("deleteOne filter must be a non-empty plain object");return await this.client.request("DELETE",`/v5/classes/${this.name}/one`,e)}async updateOne(e,n){if(!h(e))throw new TypeError("updateOne filter must be a non-empty plain object");if(!h(n))throw new TypeError("updateOne body must be a non-empty plain object");return await this.client.request("PUT",`/v5/classes/${this.name}/one`,{filter:e,body:n})}async findOne(e){if(!h(e))throw new TypeError("findOne filter must be a non-empty plain object");return await this.client.request("POST",`/v5/classes/${this.name}/one`,e)}async insertMany(e){if(!O(e))throw new TypeError("insertMany dataList must be a non-empty array of non-empty plain objects");return await this.client.request("POST",`/v5/classes/${this.name}/many`,e)}async deleteMany(e){if(!R(e))throw new TypeError("deleteMany filter must be a plain object");return await this.client.request("DELETE",`/v5/classes/${this.name}/many`,e)}async updateMany(e,n){if(!R(e))throw new TypeError("updateMany filter must be a plain object");if(!h(n))throw new TypeError("updateMany body must be a non-empty plain object");return await this.client.request("PUT",`/v5/classes/${this.name}/many`,{filter:e,body:n})}async find(e=1,n=10,r={createdAt:-1},i={}){if(!Number.isInteger(e)||e<1)throw new TypeError("find page must be a positive integer");if(!Number.isInteger(n)||n<1)throw new TypeError("find size must be a positive integer");if(n>100&&(n=100),!h(r))throw new TypeError("find sort must be a non-empty plain object");if(!R(i))throw new TypeError("find filter must be a plain object");return await this.client.request("POST",`/v5/classes/${this.name}/find`,{page:e,size:n,sort:r,filter:i})}async aggregate(e){if(!Array.isArray(e))throw new TypeError("aggregate pipeline must be an array");return await this.client.request("POST",`/v5/classes/${this.name}/aggregate`,e)}async count(e={}){if(!R(e))throw new TypeError("count filter must be a plain object");return await this.client.request("POST",`/v5/classes/${this.name}/count`,e)}async distinct(e,n={}){if(typeof e!="string"||e.length===0)throw new TypeError("distinct fieldName must be a non-empty string");if(!R(n))throw new TypeError("distinct filter must be a plain object");return await this.client.request("POST",`/v5/classes/${this.name}/distinct/${encodeURIComponent(e)}`,n)}async create(){return await this.client.request("POST",`/v5/schemas/${encodeURIComponent(this.name)}`)}async clear(){return await this.client.request("PUT",`/v5/schemas/${encodeURIComponent(this.name)}`)}async drop(){return await this.client.request("DELETE",`/v5/schemas/${encodeURIComponent(this.name)}`)}};var de,Et,xe,Rt,ge,St,be,Ut,J=class{constructor(e){z(this,de);z(this,xe);z(this,ge);z(this,be);var n,r,i,o,c;j(e),this.config={baseUrl:(n=e.baseUrl)!=null?n:Qe,appId:e.appId,apiKey:e.apiKey,secretKey:e.secretKey,version:(r=e.version)!=null?r:0,isSafeMode:(i=e.isSafeMode)!=null?i:!1,timeFormat:(o=e.timeFormat)!=null?o:ae,offset:(c=e.offset)!=null?c:0},this.db={collection:s=>Q(this,de,Et).call(this,s),toObjectID:s=>Q(this,ge,St).call(this,s),getCollections:()=>Q(this,xe,Rt).call(this)}}async init(){try{let n=(await this.request("GET",`/init/${this.config.appId}`,void 0,!1)).data;this.config.isSafeMode=n.is_safe_mode,this.config.offset=n.unix-Math.floor(Date.now()/1e3)}catch(e){console.warn("Failed to get time offset from server, defaulting to 0. Error:",e),this.config.isSafeMode=!1,this.config.offset=0}}async getMeta(e){if(e!==void 0&&e!==""&&typeof e!="string")throw new TypeError("Meta field must be a string");let n=e?`?field=${encodeURIComponent(e)}`:"";return await this.request("GET",`/v5/meta${n}`)}async checkUpdate(){try{return(await this.request("GET","/v5/meta?field=version")).data.result>this.config.version}catch(e){return!1}}async callFunc(e,n=null,r){if(typeof e!="string")throw new TypeError("Function name must be a string");return await this.request("POST",`/${this.config.appId}/${Q(this,be,Ut).call(this,e)}`,n,r)}async request(e,n,r,i){if(typeof n!="string")throw new TypeError("request path must be a string");return await Je(this.config,{method:e,path:n,params:r,encryption:i!=null?i:this.config.isSafeMode})}assertObjectID(e,n="ObjectID"){return S(e,n)}isNonEmptyObject(e){return h(e)}isPlainObject(e){return R(e)}isNonEmptyArrayWithNonEmptyObjects(e){return O(e)}hmacSHA256(e,n){return P(e,n)}verifyHmacSHA256(e,n,r){return B(e,n,r)}};de=new WeakSet,Et=function(e){if(typeof e!="string")throw new TypeError("Collection name must be a string");return new D(this,e)},xe=new WeakSet,Rt=async function(){return await this.request("GET","/v5/schemas")},ge=new WeakSet,St=function(e){return S(e),`ObjectID('${e}')`},be=new WeakSet,Ut=function(e){let n=e.startsWith("/")?e.slice(1):e,r=n.indexOf("#"),i=r!==-1?n.slice(r):"",o=r!==-1?n.slice(0,r):n,c=o.indexOf("?"),s=c!==-1?o.slice(c):"",a=c!==-1?o.slice(0,c):o;return a.endsWith("/")?a=a+"index.jsc":a.endsWith(".jsc")||(a.endsWith(".js")?a=a.replace(/\.js$/,".jsc"):a=a+".jsc"),a+s+i};var kt=J;function he(t){if(!ce.test(t))throw new Error(`Invalid ObjectID: "${t}" (must be 24 hex characters)`);return`ObjectID('${t}')`}function we(t){return`Date('${t}')`}function Ae(t){return`DateTime('${t}')`}function Te(t){return`Timestamp('${String(t)}')`}function Ee(t){return`Boolean(${t})`}function Re(t){return`Integer(${t})`}function Se(t){return`Bigint(${Number(t)})`}function Ue(t){return`Float(${t})`}function ke(t){return`Double(${t})`}function Pe(t){return`Array(${JSON.stringify(t)})`}function Me(t){return`Map(${JSON.stringify(t)})`}function Oe(t){return`Map[](${JSON.stringify(t)})`}var Ce="Null",Ne="None",Ie="Nil",qe="",De="UNDEFINED",je="Undefined";var ne="time.Now()",re="time.Now().Unix()",oe="time.Now().UnixNano()",se="time.Now().Weekday()",ie="time.Now().Weekday().Chinese()",ve={Now:()=>ne,NowUnix:()=>re,NowUnixNano:()=>oe,NowWeekday:()=>se,NowWeekdayChinese:()=>ie};return jt(rn);})();
|
|
1
|
+
"use strict";var T1Y=(()=>{var _e=Object.defineProperty;var Nt=Object.getOwnPropertyDescriptor;var It=Object.getOwnPropertyNames;var qt=Object.prototype.hasOwnProperty;var T=(t=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(t,{get:(e,n)=>(typeof require!="undefined"?require:e)[n]}):t)(function(t){if(typeof require!="undefined")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var Dt=(t,e)=>{for(var n in e)_e(t,n,{get:e[n],enumerable:!0})},jt=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of It(e))!qt.call(t,i)&&i!==n&&_e(t,i,{get:()=>e[i],enumerable:!(r=Nt(e,i))||r.enumerable});return t};var vt=t=>jt(_e({},"__esModule",{value:!0}),t);var Bt=(t,e,n)=>{if(!e.has(t))throw TypeError("Cannot "+n)};var Q=(t,e,n)=>{if(e.has(t))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(t):e.set(t,n)};var z=(t,e,n)=>(Bt(t,e,"access private method"),n);var on={};Dt(on,{Array:()=>Pe,Bigint:()=>Se,Boolean:()=>Ee,Date:()=>we,DateTime:()=>Ae,Double:()=>ke,Empty:()=>qe,Float:()=>Ue,Integer:()=>Re,Map:()=>Me,MapArray:()=>Oe,Nil:()=>Ie,None:()=>Ne,Null:()=>Ce,ObjectID:()=>he,T1Collection:()=>D,T1YError:()=>E,T1YOS:()=>J,TimeNow:()=>ne,TimeNowUnix:()=>re,TimeNowUnixNano:()=>oe,TimeNowWeekday:()=>se,TimeNowWeekdayChinese:()=>ie,Timestamp:()=>Te,UNDEFINED:()=>De,Undefined:()=>je,ValidationError:()=>b,assertObjectID:()=>S,convertDateTypes:()=>M,createSignature:()=>L,decryptAESGCM:()=>G,default:()=>Pt,encryptAESGCM:()=>F,formatTimestampsToLocal:()=>q,getMiniProgramAPI:()=>Y,getMiniProgramSubType:()=>W,getPlatformType:()=>N,getSafeTimestamp:()=>K,hmacSHA256Hex:()=>P,hmacSHA256HexAsync:()=>fe,isAESGCMAvailable:()=>le,isNonEmptyArrayWithNonEmptyObjects:()=>O,isNonEmptyObject:()=>h,isPlainObject:()=>R,isWebCryptoAvailable:()=>ye,resetPlatformDetection:()=>de,sha256Hex:()=>v,sha256HexAsync:()=>ue,timeNow:()=>ve,validateApiKey:()=>Z,validateAppId:()=>V,validateInitConfig:()=>j,validateSecretKey:()=>X,verifyHmacSHA256:()=>B});var ze="https://myapp.t1y.net";var ae="YYYY-MM-DD HH:mm:ss";var ce=/^[0-9a-fA-F]{24}$/;var E=class extends Error{constructor(e,n,r){super(n),this.name="T1YError",this.code=e,this.data=r}toJSON(){return{name:this.name,code:this.code,message:this.message,data:this.data}}},b=class extends Error{constructor(e){super(e),this.name="ValidationError"}};function V(t){if(!Number.isInteger(t))throw new b("appId must be an integer");if(t<1001)throw new b(`appId must be >= ${1001}`)}function Z(t){if(typeof t!="string")throw new b("apiKey must be a string");if(t.length!==32)throw new b(`apiKey must be exactly ${32} characters (got ${t.length})`)}function X(t){if(typeof t!="string")throw new b("secretKey must be a string");if(t.length!==32)throw new b(`secretKey must be exactly ${32} characters (got ${t.length})`)}function $e(t){if(!/^https?:\/\//.test(t))throw new b('baseUrl must start with "http://" or "https://"')}function j(t){if(t.baseUrl!==void 0&&$e(t.baseUrl),V(t.appId),Z(t.apiKey),X(t.secretKey),t.version!==void 0&&(!Number.isInteger(t.version)||t.version<0))throw new b("version must be a non-negative integer")}function S(t,e="ObjectID"){if(typeof t!="string")throw new b(`${e} must be a string`);if(!ce.test(t))throw new b(`Invalid ${e} string: "${t}"`);return!0}function M(t){if(t instanceof Date)return`Date('${t.toISOString()}')`;if(typeof t=="number"){let e=String(t);return/^\d{10,}$/.test(e)?`Timestamp('${e}')`:t}if(Array.isArray(t))return t.map(e=>M(e));if(t&&typeof t=="object"){let e={};for(let n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=M(t[n]));return e}return t}function h(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)&&Object.keys(t).length>0}function R(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function O(t){return!Array.isArray(t)||t.length===0?!1:t.every(e=>typeof e=="object"&&e!==null&&!Array.isArray(e)&&Object.keys(e).length>0)}function et(){try{if(typeof T!="undefined")return T}catch(t){}return null}function v(t){let e=et();if(e)try{return e("node:crypto").createHash("sha256").update(t).digest("hex")}catch(r){}let n=Ht(t);return ee(n)}function ee(t){return $t(t)}async function ue(t){let e=et();if(e)try{return e("node:crypto").createHash("sha256").update(t).digest("hex")}catch(i){}let n=new TextEncoder,r=await crypto.subtle.digest("SHA-256",n.encode(t));return Array.from(new Uint8Array(r)).map(i=>i.toString(16).padStart(2,"0")).join("")}function Ht(t){if(typeof TextEncoder!="undefined")return new TextEncoder().encode(t);let e=[];for(let n=0;n<t.length;n++){let r=t.charCodeAt(n);if(r<128)e.push(r);else if(r<2048)e.push(192|r>>6,128|r&63);else if(r<55296||r>=57344)e.push(224|r>>12,128|r>>6&63,128|r&63);else{n++;let i=t.charCodeAt(n),o=65536+((r&1023)<<10)+(i&1023);e.push(240|o>>18,128|o>>12&63,128|o>>6&63,128|o&63)}}return new Uint8Array(e)}function _t(t,e,n){let r=Math.floor(n/4294967296),i=n%4294967296;t[e]=r>>>24&255,t[e+1]=r>>>16&255,t[e+2]=r>>>8&255,t[e+3]=r&255,t[e+4]=i>>>24&255,t[e+5]=i>>>16&255,t[e+6]=i>>>8&255,t[e+7]=i&255}function $t(t){let e=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],n=t.length,r=n*8,i=(64-(n+9)%64)%64,o=n+1+i+8,c=new Uint8Array(o);c.set(t),c[n]=128,_t(c,o-8,r);let s=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225];for(let a=0;a<o;a+=64){let f=new Array(64);for(let d=0;d<16;d++)f[d]=c[a+d*4]<<24|c[a+d*4+1]<<16|c[a+d*4+2]<<8|c[a+d*4+3];for(let d=16;d<64;d++){let Be=(k(f[d-15],7)^k(f[d-15],18)^f[d-15]>>>3)>>>0,He=(k(f[d-2],17)^k(f[d-2],19)^f[d-2]>>>10)>>>0;f[d]=f[d-16]+Be+f[d-7]+He>>>0}let[p,u,y,m,l,g,A,x]=s;for(let d=0;d<64;d++){let Be=(k(l,6)^k(l,11)^k(l,25))>>>0,He=(l&g^~l&A)>>>0,Qe=x+Be+He+e[d]+f[d]>>>0,Mt=(k(p,2)^k(p,13)^k(p,22))>>>0,Ot=(p&u^p&y^u&y)>>>0,Ct=Mt+Ot>>>0;x=A,A=g,g=l,l=m+Qe>>>0,m=y,y=u,u=p,p=Qe+Ct>>>0}s[0]=s[0]+p>>>0,s[1]=s[1]+u>>>0,s[2]=s[2]+y>>>0,s[3]=s[3]+m>>>0,s[4]=s[4]+l>>>0,s[5]=s[5]+g>>>0,s[6]=s[6]+A>>>0,s[7]=s[7]+x>>>0}return s.map(a=>a.toString(16).padStart(8,"0")).join("")}function k(t,e){return t>>>e|t<<32-e}function st(){try{if(typeof T!="undefined")return T}catch(t){}return null}function P(t,e){let n=st();if(n)try{return n("node:crypto").createHmac("sha256",t).update(e).digest("hex")}catch(r){}return Gt(t,e)}async function fe(t,e){let n=st();if(n)try{return n("node:crypto").createHmac("sha256",t).update(e).digest("hex")}catch(c){}let r=new TextEncoder,i=await crypto.subtle.importKey("raw",r.encode(t),{name:"HMAC",hash:"SHA-256"},!1,["sign"]),o=await crypto.subtle.sign("HMAC",i,r.encode(e));return Array.from(new Uint8Array(o)).map(c=>c.toString(16).padStart(2,"0")).join("")}function B(t,e,n){if(typeof n!="string")return!1;let r=P(t,e);return Ft(r,n.toLowerCase())}function Ft(t,e){if(t.length!==e.length)return!1;let n=0;for(let r=0;r<t.length;r++)n|=t.charCodeAt(r)^e.charCodeAt(r);return n===0}function Gt(t,e){let r=rt(t),i=rt(e);r.length>64&&(r=ot(ee(r)));let o=new Uint8Array(64);o.set(r.subarray(0,Math.min(r.length,64)));let c=new Uint8Array(64);c.fill(54);let s=nt(o,c),a=new Uint8Array(64+i.length);a.set(s),a.set(i,64);let f=ot(ee(a)),p=new Uint8Array(64);p.fill(92);let u=nt(o,p),y=new Uint8Array(64+f.length);return y.set(u),y.set(f,64),ee(y)}function nt(t,e){let n=new Uint8Array(t.length);for(let r=0;r<t.length;r++)n[r]=t[r]^e[r];return n}function rt(t){if(typeof TextEncoder!="undefined")return new TextEncoder().encode(t);let e=[];for(let n=0;n<t.length;n++){let r=t.charCodeAt(n);if(r<128)e.push(r);else if(r<2048)e.push(192|r>>6,128|r&63);else if(r<55296||r>=57344)e.push(224|r>>12,128|r>>6&63,128|r&63);else{n++;let i=t.charCodeAt(n),o=65536+((r&1023)<<10)+(i&1023);e.push(240|o>>18,128|o>>12&63,128|o>>6&63,128|o&63)}}return new Uint8Array(e)}function ot(t){let e=new Uint8Array(t.length/2);for(let n=0;n<t.length;n+=2)e[n/2]=parseInt(t.substring(n,n+2),16);return e}var te=[99,124,119,123,242,107,111,197,48,1,103,43,254,215,171,118,202,130,201,125,250,89,71,240,173,212,162,175,156,164,114,192,183,253,147,38,54,63,247,204,52,165,229,241,113,216,49,21,4,199,35,195,24,150,5,154,7,18,128,226,235,39,178,117,9,131,44,26,27,110,90,160,82,59,214,179,41,227,47,132,83,209,0,237,32,252,177,91,106,203,190,57,74,76,88,207,208,239,170,251,67,77,51,133,69,249,2,127,80,60,159,168,81,163,64,143,146,157,56,245,188,182,218,33,16,255,243,210,205,12,19,236,95,151,68,23,196,167,126,61,100,93,25,115,96,129,79,220,34,42,144,136,70,238,184,20,222,94,11,219,224,50,58,10,73,6,36,92,194,211,172,98,145,149,228,121,231,200,55,109,141,213,78,169,108,86,244,234,101,122,174,8,186,120,37,46,28,166,180,198,232,221,116,31,75,189,139,138,112,62,181,102,72,3,246,14,97,53,87,185,134,193,29,158,225,248,152,17,105,217,142,148,155,30,135,233,206,85,40,223,140,161,137,13,191,230,66,104,65,153,45,15,176,84,187,22],Lt=[1,2,4,8,16,32,64,128,27,54];function Le(t){if(t.length!==32)throw new Error("AES-256 requires a 32-byte key");let e=8,n=14,i=4*(n+1),o=new Array(i);for(let s=0;s<e;s++)o[s]=t[4*s]<<24|t[4*s+1]<<16|t[4*s+2]<<8|t[4*s+3];for(let s=e;s<i;s++){let a=o[s-1];s%e===0?a=it(Kt(a))^Lt[Math.floor(s/e)-1]<<24:e>6&&s%e===4&&(a=it(a)),o[s]=o[s-e]^a}let c=[];for(let s=0;s<=n;s++){let a=new Uint8Array(16);for(let f=0;f<4;f++){let p=o[s*4+f];a[4*f]=p>>>24&255,a[4*f+1]=p>>>16&255,a[4*f+2]=p>>>8&255,a[4*f+3]=p&255}c.push(a)}return c}function Kt(t){return(t<<8|t>>>24)>>>0}function it(t){return(te[t>>>24&255]<<24|te[t>>>16&255]<<16|te[t>>>8&255]<<8|te[t&255]<<0)>>>0}function Ke(t,e){if(t.length!==16)throw new Error("AES block must be exactly 16 bytes");let n=[[],[],[],[]];for(let o=0;o<4;o++)for(let c=0;c<4;c++)n[c][o]=t[o*4+c];let r=14;Fe(n,e[0]);for(let o=1;o<r;o++)at(n),ct(n),Wt(n),Fe(n,e[o]);at(n),ct(n),Fe(n,e[r]);let i=new Uint8Array(16);for(let o=0;o<4;o++)for(let c=0;c<4;c++)i[o*4+c]=n[c][o];return i}function at(t){for(let e=0;e<4;e++)for(let n=0;n<4;n++)t[e][n]=te[t[e][n]]}function ct(t){for(let e=1;e<4;e++){let n=t[e];t[e]=[n[e%4],n[(e+1)%4],n[(e+2)%4],n[(e+3)%4]]}}function Wt(t){for(let e=0;e<4;e++){let n=[];for(let r=0;r<4;r++)n[r]=t[r][e];t[0][e]=C(2,n[0])^C(3,n[1])^n[2]^n[3],t[1][e]=n[0]^C(2,n[1])^C(3,n[2])^n[3],t[2][e]=n[0]^n[1]^C(2,n[2])^C(3,n[3]),t[3][e]=C(3,n[0])^n[1]^n[2]^C(2,n[3])}}function Fe(t,e){for(let n=0;n<4;n++)for(let r=0;r<4;r++)t[r][n]=t[r][n]^e[n*4+r]}function C(t,e){let n=0,r=t,i=e;for(let o=0;o<8;o++){i&1&&(n^=r);let c=r&128;r=r<<1&255,c&&(r^=27),i>>=1}return n}function pe(t,e,n){let r=Le(t),i=Math.ceil(n.length/16),o=new Uint8Array(n.length),c=new Uint8Array(e);for(let s=0;s<i;s++){let a=Ke(c,r),f=Math.min(16,n.length-s*16);for(let p=0;p<f;p++)o[s*16+p]=n[s*16+p]^a[p];We(c)}return o}function We(t){for(let e=15;e>=12;e--){let n=t[e]+1;if(t[e]=n&255,n<=255)break}}function ut(t,e,n){let r=Math.floor(n/4294967296),i=n%4294967296;t[e]=r>>>24&255,t[e+1]=r>>>16&255,t[e+2]=r>>>8&255,t[e+3]=r&255,t[e+4]=i>>>24&255,t[e+5]=i>>>16&255,t[e+6]=i>>>8&255,t[e+7]=i&255}function ft(t,e,n){let i=Math.ceil(e.length/16),o=Math.ceil(n.length/16),c=i+o+1,s=new Uint8Array(16);for(let y=0;y<i;y++){let m=new Uint8Array(16),l=y*16,g=Math.min(16,e.length-l);for(let x=0;x<g;x++)m[x]=e[l+x];for(let x=0;x<16;x++)m[x]^=s[x];let A=Ge(m,t);s.set(A)}for(let y=0;y<o;y++){let m=new Uint8Array(16),l=y*16,g=Math.min(16,n.length-l);for(let x=0;x<g;x++)m[x]=n[l+x];for(let x=0;x<16;x++)m[x]^=s[x];let A=Ge(m,t);s.set(A)}let a=new Uint8Array(16),f=e.length*8,p=n.length*8;ut(a,0,f),ut(a,8,p);for(let y=0;y<16;y++)a[y]^=s[y];return Ge(a,t)}function Ge(t,e){let n=new Uint8Array(16),r=new Uint8Array(e);for(let i=0;i<16;i++)for(let o=0;o<8;o++){if(t[15-i]>>7-o&1)for(let s=0;s<16;s++)n[s]^=r[s];let c=r[15]&1;for(let s=15;s>0;s--)r[s]=r[s]>>1|(r[s-1]&1)<<7;r[0]=r[0]>>1,c&&(r[0]^=225)}return n}function pt(t,e,n,r=new Uint8Array(0)){if(e.length!==32)throw new Error("key length must be 32 bytes for AES-256-GCM");if(n.length!==12)throw new Error("nonce length must be 12 bytes for AES-256-GCM");let i=new Uint8Array(16);i.set(n),i[15]=1;let o=Le(e),c=new Uint8Array(16),s=Ke(c,o),a=new Uint8Array(16);a.set(n),a[15]=1;let f=new Uint8Array(a);We(f);let p=pe(e,f,t),u=ft(s,r,p),y=pe(e,a,u),m=new Uint8Array(16);for(let l=0;l<16;l++)m[l]=u[l]^y[l];return{ciphertext:p,tag:m}}function lt(t,e,n,r,i=new Uint8Array(0)){if(n.length!==32)throw new Error("key length must be 32 bytes for AES-256-GCM");if(r.length!==12)throw new Error("nonce length must be 12 bytes for AES-256-GCM");if(e.length!==16)throw new Error("tag length must be 16 bytes for AES-256-GCM");let o=Le(n),c=new Uint8Array(16),s=Ke(c,o),a=new Uint8Array(16);a.set(r),a[15]=1;let f=ft(s,i,t),p=pe(n,a,f),u=new Uint8Array(16);for(let l=0;l<16;l++)u[l]=f[l]^p[l];let y=0;for(let l=0;l<16;l++)y|=e[l]^u[l];if(y!==0)throw new Error("AES-256-GCM authentication failed: tag mismatch");let m=new Uint8Array(a);return We(m),pe(n,m,t)}function $(){try{if(typeof globalThis!="undefined"){if(typeof globalThis.crypto!="undefined"&&globalThis.crypto.subtle)return globalThis.crypto;try{let t=typeof T!="undefined"?T:null;if(t){let e=t("node:crypto");if(e!=null&&e.webcrypto)return e.webcrypto}}catch(t){}}}catch(t){}return null}function le(){return!0}function ye(){return $()!==null}var yt=16,dt=12;function Yt(t){let e=$();if(e){let r=new Uint8Array(t);return e.getRandomValues(r),r}try{if(typeof wx!="undefined"&&typeof wx.getRandomValues=="function"){let r=new Uint8Array(t);return wx.getRandomValues(r),r}}catch(r){}let n=new Uint8Array(t);for(let r=0;r<t;r++)n[r]=Math.floor(Math.random()*256);return n}function H(t){let e="",n=t.byteLength;for(let r=0;r<n;r++)e+=String.fromCharCode(t[r]);return btoa(e)}function _(t){let e=atob(t),n=e.length,r=new Uint8Array(n);for(let i=0;i<n;i++)r[i]=e.charCodeAt(i);return r}async function Jt(t,e){let n=$();if(!n)throw new Error("Web Crypto API is not available");let r=await n.subtle.importKey("raw",e,"AES-GCM",!1,["encrypt"]),i=new Uint8Array(dt);n.getRandomValues(i);let o=new TextEncoder().encode(t),c=new Uint8Array(await n.subtle.encrypt({name:"AES-GCM",iv:i,tagLength:128},r,o)),s=c.slice(0,c.length-yt),a=c.slice(c.length-yt),f={n:H(i),j:H(s),t:H(a)};return JSON.stringify(f)}async function Qt(t,e){let n=$();if(!n)throw new Error("Web Crypto API is not available");let{n:r,j:i,t:o}=JSON.parse(t),c=_(r),s=_(i),a=_(o),f=new Uint8Array(s.length+a.length);f.set(s),f.set(a,s.length);let p=await n.subtle.importKey("raw",e,"AES-GCM",!1,["decrypt"]),u=await n.subtle.decrypt({name:"AES-GCM",iv:c,tagLength:128},p,f);return new TextDecoder().decode(u)}function zt(t,e){let n=Yt(dt),r=new TextEncoder().encode(t),{ciphertext:i,tag:o}=pt(r,e,n),c={n:H(n),j:H(i),t:H(o)};return JSON.stringify(c)}function Vt(t,e){let{n,j:r,t:i}=JSON.parse(t),o=_(n),c=_(r),s=_(i),a=lt(c,s,e,o);return new TextDecoder().decode(a)}async function F(t,e){if(!(e instanceof Uint8Array))throw new Error("key must be Uint8Array");if(e.length!==32)throw new Error("key length must be 32 bytes for AES-256-GCM");return $()?await Jt(t,e):zt(t,e)}async function G(t,e){if(!(e instanceof Uint8Array))throw new Error("key must be Uint8Array");if(e.length!==32)throw new Error("key length must be 32 bytes for AES-256-GCM");return $()?await Qt(t,e):Vt(t,e)}function L(t){let{method:e,pathAndQuery:n,body:r,appId:i,timestamp:o,secretKey:c}=t,s=v(r),a=[e.toUpperCase(),n,s,String(i),String(o)].join(`
|
|
2
|
+
`);return P(c,a)}function K(t){return String(Math.floor(Date.now()/1e3)+t)}function mt(t){return t.replace(/\/+$/,"")}function xt(t){let e=[];for(let n of Object.keys(t)){let r=t[n];if(r==null)continue;let i=encodeURIComponent(n),o=encodeURIComponent(typeof r=="string"?r:JSON.stringify(r));e.push(`${i}=${o}`)}return e.length>0?`?${e.join("&")}`:""}function gt(t){let e=t.indexOf("://");if(e===-1)return t;let n=t.indexOf("/",e+3);return n===-1?"/":t.substring(n)}function Zt(t,e){let n=new Date(t);if(isNaN(n.getTime()))return t;let r=i=>String(i).padStart(2,"0");return e.replace("YYYY",String(n.getFullYear())).replace("MM",r(n.getMonth()+1)).replace("DD",r(n.getDate())).replace("HH",r(n.getHours())).replace("mm",r(n.getMinutes())).replace("ss",r(n.getSeconds()))}function q(t,e=ae){function n(r){if(Array.isArray(r))return r.map(n);if(r&&typeof r=="object"){let i={};for(let o in r)Object.prototype.hasOwnProperty.call(r,o)&&(o==="createdAt"||o==="updatedAt"?i[o]=Zt(r[o],e):i[o]=n(r[o]));return i}return r}return n(t)}async function bt(t,e,n,r){let i=t.headers["content-type"]||"",o,c=t.body;if(i.includes("application/json"))try{o=JSON.parse(c)}catch(a){o=c}else o=c;if(e&&o&&typeof o=="object"&&"j"in o)try{let a=await G(JSON.stringify(o),new TextEncoder().encode(n));try{o=JSON.parse(a)}catch(f){o=a}}catch(a){throw new E(400,"AES-256-GCM decryption failed",a instanceof Error?a.message:null)}let s=t.status>=200&&t.status<300;if(o&&typeof o=="object"&&"data"in o){let a=o;if(a.data=q(a.data,r),!s)throw new E(a.code||t.status,a.message||t.statusText,a.data);return a}if(!s)throw new E(t.status,t.statusText,o);return{code:0,message:"ok",data:q(o,r)}}function ht(t){if(t instanceof E)throw t;if(t instanceof Error){let e=t.message||"Unknown error";throw e.includes("timeout")||e.includes("\u8D85\u65F6")||t.name==="AbortError"||e.includes("abort")?new E(408,"Request timeout",null):new E(0,e,null)}throw new E(0,"Unknown error",t)}var w=null,U=null;function N(){var t;if(w!==null)return w;if(typeof wx!="undefined"&&typeof wx.request=="function")return w="wx",w;if(typeof my!="undefined"&&typeof my.request=="function")return w="my",w;if(typeof window=="undefined"&&typeof document=="undefined"&&typeof global!="undefined"&&typeof global.require=="function")try{if(typeof T!="undefined"&&typeof T("@system.fetch")!="undefined")return w="hap",w}catch(e){}return typeof window!="undefined"&&typeof document!="undefined"?(w="h5",w):typeof process!="undefined"&&typeof process.versions!="undefined"&&typeof((t=process.versions)==null?void 0:t.node)!="undefined"?(w="nodejs",w):(w="unknown",w)}function W(){return U!==null?U:N()!=="wx"?(U="unknown",U):typeof tt!="undefined"&&typeof tt.request=="function"?(U="toutiao",U):typeof qq!="undefined"&&typeof qq.request=="function"?(U="qq",U):(U="wechat",U)}function Y(){let t=N();if(t==="my")return my;if(t!=="wx")return null;switch(W()){case"toutiao":return tt;case"qq":return qq;case"wechat":default:return wx}}function de(){w=null,U=null}var Ye=async t=>{let{url:e,method:n,headers:r,body:i,signal:o}=t,c={method:n,headers:r,signal:o};i!==void 0&&n!=="GET"&&(c.body=i);let s=await fetch(e,c),a={};s.headers.forEach((p,u)=>{a[u.toLowerCase()]=p});let f=await s.text();return{status:s.status,statusText:s.statusText,headers:a,body:f}};var wt=async t=>{let e=Y();if(!e||typeof e.request!="function")throw new Error("Mini program request API is not available");let n=e.request,{url:r,method:i,headers:o,body:c,timeout:s}=t;return new Promise((a,f)=>{let p=n({url:r,method:i,header:o,data:c,timeout:s!=null?s:3e5,dataType:"text",responseType:"text",success:u=>{var l;let y={};if(u.header)for(let g of Object.keys(u.header))y[g.toLowerCase()]=u.header[g];let m;typeof u.data=="string"?m=u.data:u.data!==void 0&&u.data!==null?m=JSON.stringify(u.data):m="",a({status:u.statusCode,statusText:(l=u.errMsg)!=null?l:"",headers:y,body:m})},fail:u=>{var m;let y=(m=u.errMsg)!=null?m:"Mini program request failed";y.includes("timeout")||y.includes("\u8D85\u65F6")?f(new Error("Request timeout")):f(new Error(y))}});if(t.signal){let u=()=>{typeof p.abort=="function"&&p.abort()};t.signal.addEventListener("abort",u,{once:!0})}})};var At=async t=>{let e=my;if(!e||typeof e.request!="function")throw new Error("Alipay mini program request API (my.request) is not available");let n=e.request,{url:r,method:i,headers:o,body:c,timeout:s}=t;return new Promise((a,f)=>{let p=n({url:r,method:i.toUpperCase(),headers:o,data:c!==void 0?c:void 0,timeout:s!=null?s:3e5,dataType:"text",success:u=>{var g,A;let y=(A=(g=u.status)!=null?g:u.statusCode)!=null?A:200,m={};if(u.headers)for(let x of Object.keys(u.headers))m[x.toLowerCase()]=u.headers[x];let l;typeof u.data=="string"?l=u.data:u.data!==void 0&&u.data!==null?l=JSON.stringify(u.data):l="",a({status:y,statusText:"",headers:m,body:l})},fail:u=>{var m,l;let y=(l=(m=u.errorMessage)!=null?m:u.errMsg)!=null?l:`Alipay request failed (error: ${u.error})`;f(new Error(y))},complete:()=>{}});if(t.signal){let u=()=>{p&&typeof p.abort=="function"&&p.abort()};t.signal.addEventListener("abort",u,{once:!0})}})};function Xt(){try{return T("@system.fetch")}catch(t){return null}}var Tt=async t=>{let e=Xt();if(!e)throw new Error("Quick App fetch module (@system.fetch) is not available. Ensure you are running inside a Quick App environment.");let{url:n,method:r,headers:i,body:o}=t;return new Promise((c,s)=>{e.fetch({url:n,method:r.toUpperCase(),header:i,data:o,responseType:"text",success:a=>{let f={};if(a.headers)for(let p of Object.keys(a.headers))f[p.toLowerCase()]=a.headers[p];c({status:a.code,statusText:"",headers:f,body:typeof a.data=="string"?a.data:JSON.stringify(a.data)})},fail:a=>{s(new Error(`Quick App request failed (code: ${a.code}, data: ${a.data})`))},complete:()=>{}})})};var I=null;function Et(){if(I!==null)return I;switch(N()){case"h5":case"nodejs":I=Ye;break;case"wx":I=wt;break;case"my":I=At;break;case"hap":I=Tt;break;default:if(typeof fetch=="function")I=Ye;else throw new Error("Unable to determine platform request adapter. The current environment does not have `fetch`, `wx.request`, `my.request`, or `@system.fetch` available. Please ensure you are running in a supported environment: Web browser, Node.js 18+, WeChat/QQ/Alipay/Toutiao/Douyin Mini Program, or Quick App.");break}return I}async function Je(t,e){let{method:n,path:r,params:i,encryption:o,timeout:c}=e,s=mt(t.baseUrl),a=o!=null?o:t.isSafeMode,f=s+r,p=M(i),u,y="";if(n!=="GET")if(a&&p!==void 0){let d=await F(JSON.stringify(p),new TextEncoder().encode(t.secretKey));u=d,y=d}else if(p!==void 0){let d=JSON.stringify(p);u=d,y=d}else y="";else if(p&&typeof p=="object"&&Object.keys(p).length>0){let d=xt(p);d&&(f+=d)}let m=Number(K(t.offset)),l=gt(f),g=L({method:n,pathAndQuery:l,body:y,appId:t.appId,timestamp:m,secretKey:t.secretKey}),A=Et(),x=c!=null?c:3e5;try{let d=await A({url:f,method:n,headers:{"X-T1Y-Application-ID":String(t.appId),"X-T1Y-API-Key":t.apiKey,"X-T1Y-Safe-Timestamp":String(m),"X-T1Y-Safe-Sign":g,"Content-Type":"application/json"},body:n!=="GET"?u:void 0,timeout:x});return await bt(d,a,t.secretKey,t.timeFormat)}catch(d){return ht(d)}}var D=class{constructor(e,n){this.client=e,this.name=n}async insertOne(e){if(!h(e))throw new TypeError("insertOne data must be a non-empty plain object");return await this.client.request("POST",`/v5/classes/${this.name}`,e)}async deleteById(e){return S(e),await this.client.request("DELETE",`/v5/classes/${this.name}/${e}`)}async updateById(e,n){if(S(e),!h(n))throw new TypeError("update data must be a non-empty plain object");return await this.client.request("PUT",`/v5/classes/${this.name}/${e}`,n)}async findById(e){return S(e),await this.client.request("GET",`/v5/classes/${this.name}/${e}`)}async deleteOne(e){if(!h(e))throw new TypeError("deleteOne filter must be a non-empty plain object");return await this.client.request("DELETE",`/v5/classes/${this.name}/one`,e)}async updateOne(e,n){if(!h(e))throw new TypeError("updateOne filter must be a non-empty plain object");if(!h(n))throw new TypeError("updateOne body must be a non-empty plain object");return await this.client.request("PUT",`/v5/classes/${this.name}/one`,{filter:e,body:n})}async findOne(e){if(!h(e))throw new TypeError("findOne filter must be a non-empty plain object");return await this.client.request("POST",`/v5/classes/${this.name}/one`,e)}async insertMany(e){if(!O(e))throw new TypeError("insertMany dataList must be a non-empty array of non-empty plain objects");return await this.client.request("POST",`/v5/classes/${this.name}/many`,e)}async deleteMany(e){if(!R(e))throw new TypeError("deleteMany filter must be a plain object");return await this.client.request("DELETE",`/v5/classes/${this.name}/many`,e)}async updateMany(e,n){if(!R(e))throw new TypeError("updateMany filter must be a plain object");if(!h(n))throw new TypeError("updateMany body must be a non-empty plain object");return await this.client.request("PUT",`/v5/classes/${this.name}/many`,{filter:e,body:n})}async find(e=1,n=10,r={createdAt:-1},i={}){if(!Number.isInteger(e)||e<1)throw new TypeError("find page must be a positive integer");if(!Number.isInteger(n)||n<1)throw new TypeError("find size must be a positive integer");if(n>100&&(n=100),!h(r))throw new TypeError("find sort must be a non-empty plain object");if(!R(i))throw new TypeError("find filter must be a plain object");return await this.client.request("POST",`/v5/classes/${this.name}/find`,{page:e,size:n,sort:r,filter:i})}async aggregate(e){if(!Array.isArray(e))throw new TypeError("aggregate pipeline must be an array");return await this.client.request("POST",`/v5/classes/${this.name}/aggregate`,e)}async count(e={}){if(!R(e))throw new TypeError("count filter must be a plain object");return await this.client.request("POST",`/v5/classes/${this.name}/count`,e)}async distinct(e,n={}){if(typeof e!="string"||e.length===0)throw new TypeError("distinct fieldName must be a non-empty string");if(!R(n))throw new TypeError("distinct filter must be a plain object");return await this.client.request("POST",`/v5/classes/${this.name}/distinct/${encodeURIComponent(e)}`,n)}async create(){return await this.client.request("POST",`/v5/schemas/${encodeURIComponent(this.name)}`)}async clear(){return await this.client.request("PUT",`/v5/schemas/${encodeURIComponent(this.name)}`)}async drop(){return await this.client.request("DELETE",`/v5/schemas/${encodeURIComponent(this.name)}`)}};var me,Rt,xe,St,ge,Ut,be,kt,J=class{constructor(e){Q(this,me);Q(this,xe);Q(this,ge);Q(this,be);var n,r,i,o,c;j(e),this.config={baseUrl:(n=e.baseUrl)!=null?n:ze,appId:e.appId,apiKey:e.apiKey,secretKey:e.secretKey,version:(r=e.version)!=null?r:0,isSafeMode:(i=e.isSafeMode)!=null?i:!1,timeFormat:(o=e.timeFormat)!=null?o:ae,offset:(c=e.offset)!=null?c:0},this.db={collection:s=>z(this,me,Rt).call(this,s),toObjectID:s=>z(this,ge,Ut).call(this,s),getCollections:()=>z(this,xe,St).call(this)}}async init(){try{let n=(await this.request("GET",`/init/${this.config.appId}`,void 0,!1)).data;this.config.isSafeMode=n.is_safe_mode,this.config.offset=n.unix-Math.floor(Date.now()/1e3)}catch(e){console.warn("Failed to get time offset from server, defaulting to 0. Error:",e),this.config.isSafeMode=!1,this.config.offset=0}}async getMeta(e){if(e!==void 0&&e!==""&&typeof e!="string")throw new TypeError("Meta field must be a string");let n=e?`?field=${encodeURIComponent(e)}`:"";return await this.request("GET",`/v5/meta${n}`)}async checkUpdate(){try{return(await this.request("GET","/v5/meta?field=version")).data.result>this.config.version}catch(e){return!1}}async callFunc(e,n=null,r){if(typeof e!="string")throw new TypeError("Function name must be a string");return await this.request("POST",`/${this.config.appId}/${z(this,be,kt).call(this,e)}`,n,r)}async request(e,n,r,i){if(typeof n!="string")throw new TypeError("request path must be a string");return await Je(this.config,{method:e,path:n,params:r,encryption:i!=null?i:this.config.isSafeMode})}assertObjectID(e,n="ObjectID"){return S(e,n)}isNonEmptyObject(e){return h(e)}isPlainObject(e){return R(e)}isNonEmptyArrayWithNonEmptyObjects(e){return O(e)}hmacSHA256(e,n){return P(e,n)}verifyHmacSHA256(e,n,r){return B(e,n,r)}};me=new WeakSet,Rt=function(e){if(typeof e!="string")throw new TypeError("Collection name must be a string");return new D(this,e)},xe=new WeakSet,St=async function(){return await this.request("GET","/v5/schemas")},ge=new WeakSet,Ut=function(e){return S(e),`ObjectID('${e}')`},be=new WeakSet,kt=function(e){let n=e.startsWith("/")?e.slice(1):e,r=n.indexOf("#"),i=r!==-1?n.slice(r):"",o=r!==-1?n.slice(0,r):n,c=o.indexOf("?"),s=c!==-1?o.slice(c):"",a=c!==-1?o.slice(0,c):o;return a.endsWith("/")?a=a+"index.jsc":a.endsWith(".jsc")||(a.endsWith(".js")?a=a.replace(/\.js$/,".jsc"):a=a+".jsc"),a+s+i};var Pt=J;function he(t){if(!ce.test(t))throw new Error(`Invalid ObjectID: "${t}" (must be 24 hex characters)`);return`ObjectID('${t}')`}function we(t){return`Date('${t}')`}function Ae(t){return`DateTime('${t}')`}function Te(t){return`Timestamp('${String(t)}')`}function Ee(t){return`Boolean(${t})`}function Re(t){return`Integer(${t})`}function Se(t){return`Bigint(${Number(t)})`}function Ue(t){return`Float(${t})`}function ke(t){return`Double(${t})`}function Pe(t){return`Array(${JSON.stringify(t)})`}function Me(t){return`Map(${JSON.stringify(t)})`}function Oe(t){return`Map[](${JSON.stringify(t)})`}var Ce="Null",Ne="None",Ie="Nil",qe="",De="UNDEFINED",je="Undefined";var ne="time.Now()",re="time.Now().Unix()",oe="time.Now().UnixNano()",se="time.Now().Weekday()",ie="time.Now().Weekday().Chinese()",ve={Now:()=>ne,NowUnix:()=>re,NowUnixNano:()=>oe,NowWeekday:()=>se,NowWeekdayChinese:()=>ie};return vt(on);})();
|
package/package.json
CHANGED