t1y-sdk-js 5.0.1 → 5.0.3
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/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var le=Object.defineProperty;var Pt=Object.getOwnPropertyDescriptor;var Mt=Object.getOwnPropertyNames;var Ot=Object.prototype.hasOwnProperty;var Ke=t=>{throw TypeError(t)};var Ct=(t,e)=>{for(var n in e)le(t,n,{get:e[n],enumerable:!0})},It=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of Mt(e))!Ot.call(t,a)&&a!==n&&le(t,a,{get:()=>e[a],enumerable:!(r=Pt(e,a))||r.enumerable});return t};var qt=t=>It(le({},"__esModule",{value:!0}),t);var Nt=(t,e,n)=>e.has(t)||Ke("Cannot "+n);var We=(t,e,n)=>e.has(t)?Ke("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,n);var _=(t,e,n)=>(Nt(t,e,"access private method"),n);var Xt={};Ct(Xt,{Array:()=>Ne,Bigint:()=>Ce,Boolean:()=>Me,Date:()=>Ue,DateTime:()=>ke,Double:()=>qe,Empty:()=>He,Float:()=>Ie,Integer:()=>Oe,Map:()=>De,MapArray:()=>je,Nil:()=>_e,None:()=>Be,Null:()=>ve,ObjectID:()=>Se,T1Collection:()=>B,T1YError:()=>A,T1YOS:()=>V,TimeNow:()=>se,TimeNowUnix:()=>ie,TimeNowUnixNano:()=>ae,TimeNowWeekday:()=>ce,TimeNowWeekdayChinese:()=>ue,Timestamp:()=>Pe,UNDEFINED:()=>Fe,Undefined:()=>$e,ValidationError:()=>g,assertObjectID:()=>S,convertDateTypes:()=>C,createSignature:()=>Y,decryptAESGCM:()=>W,default:()=>Rt,encryptAESGCM:()=>K,formatTimestampsToLocal:()=>v,getMiniProgramAPI:()=>Q,getMiniProgramSubType:()=>z,getPlatformType:()=>q,getSafeTimestamp:()=>J,hmacSHA256Hex:()=>P,hmacSHA256HexAsync:()=>de,isAESGCMAvailable:()=>we,isNonEmptyArrayWithNonEmptyObjects:()=>I,isNonEmptyObject:()=>h,isPlainObject:()=>T,isWebCryptoAvailable:()=>Ae,resetPlatformDetection:()=>Te,sha256Hex:()=>F,sha256HexAsync:()=>ye,timeNow:()=>Ge,validateApiKey:()=>te,validateAppId:()=>ee,validateBaseUrl:()=>re,validateInitConfig:()=>H,validateSecretKey:()=>ne,verifyHmacSHA256:()=>G});module.exports=qt(Xt);var Ye="https://myapp.t1y.net";var Z="YYYY-MM-DD HH:mm:ss";var X=/^[0-9a-fA-F]{24}$/;var A=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}}},g=class extends Error{constructor(e){super(e),this.name="ValidationError"}};function ee(t){if(!Number.isInteger(t))throw new g("appId must be an integer");if(t<1001)throw new g(`appId must be >= ${1001}`)}function te(t){if(typeof t!="string")throw new g("apiKey must be a string");if(t.length!==32)throw new g(`apiKey must be exactly ${32} characters (got ${t.length})`)}function ne(t){if(typeof t!="string")throw new g("secretKey must be a string");if(t.length!==32)throw new g(`secretKey must be exactly ${32} characters (got ${t.length})`)}function re(t){if(!/^https?:\/\//.test(t))throw new g('baseUrl must start with "http://" or "https://"')}function H(t){if(t.baseUrl!==void 0&&re(t.baseUrl),ee(t.appId),te(t.apiKey),ne(t.secretKey),t.version!==void 0&&(!Number.isInteger(t.version)||t.version<0))throw new g("version must be a non-negative integer")}function S(t,e="ObjectID"){if(typeof t!="string")throw new g(`${e} must be a string`);if(!X.test(t))throw new g(`Invalid ${e} string: "${t}"`);return!0}function C(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=>C(e));if(t&&typeof t=="object"){let e={};for(let n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=C(t[n]));return e}return t}function h(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)&&Object.keys(t).length>0}function T(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function I(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 Ve(){try{if(typeof require<"u")return require}catch{}return null}function F(t){let e=Ve();if(e)try{return e("node:crypto").createHash("sha256").update(t).digest("hex")}catch{}let n=Dt(t);return $(n)}function $(t){return jt(t)}async function ye(t){let e=Ve();if(e)try{return e("node:crypto").createHash("sha256").update(t).digest("hex")}catch{}let n=new TextEncoder,r=await crypto.subtle.digest("SHA-256",n.encode(t));return Array.from(new Uint8Array(r)).map(a=>a.toString(16).padStart(2,"0")).join("")}function Dt(t){if(typeof TextEncoder<"u")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 a=t.charCodeAt(n),o=65536+((r&1023)<<10)+(a&1023);e.push(240|o>>18,128|o>>12&63,128|o>>6&63,128|o&63)}}return new Uint8Array(e)}function jt(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,a=(64-(n+9)%64)%64,o=n+1+a+8,c=new Uint8Array(o);c.set(t),c[n]=128;for(let s=0;s<8;s++)c[o-8+s]=Number(BigInt(r)>>BigInt((7-s)*8)&BigInt(255));let i=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225];for(let s=0;s<o;s+=64){let f=new Array(64);for(let d=0;d<16;d++)f[d]=c[s+d*4]<<24|c[s+d*4+1]<<16|c[s+d*4+2]<<8|c[s+d*4+3];for(let d=16;d<64;d++){let fe=(U(f[d-15],7)^U(f[d-15],18)^f[d-15]>>>3)>>>0,pe=(U(f[d-2],17)^U(f[d-2],19)^f[d-2]>>>10)>>>0;f[d]=f[d-16]+fe+f[d-7]+pe>>>0}let[p,u,l,m,y,w,R,x]=i;for(let d=0;d<64;d++){let fe=(U(y,6)^U(y,11)^U(y,25))>>>0,pe=(y&w^~y&R)>>>0,Le=x+fe+pe+e[d]+f[d]>>>0,St=(U(p,2)^U(p,13)^U(p,22))>>>0,Ut=(p&u^p&l^u&l)>>>0,kt=St+Ut>>>0;x=R,R=w,w=y,y=m+Le>>>0,m=l,l=u,u=p,p=Le+kt>>>0}i[0]=i[0]+p>>>0,i[1]=i[1]+u>>>0,i[2]=i[2]+l>>>0,i[3]=i[3]+m>>>0,i[4]=i[4]+y>>>0,i[5]=i[5]+w>>>0,i[6]=i[6]+R>>>0,i[7]=i[7]+x>>>0}return i.map(s=>s.toString(16).padStart(8,"0")).join("")}function U(t,e){return t>>>e|t<<32-e}function nt(){try{if(typeof require<"u")return require}catch{}return null}function P(t,e){let n=nt();if(n)try{return n("node:crypto").createHmac("sha256",t).update(e).digest("hex")}catch{}return Bt(t,e)}async function de(t,e){let n=nt();if(n)try{return n("node:crypto").createHmac("sha256",t).update(e).digest("hex")}catch{}let r=new TextEncoder,a=await crypto.subtle.importKey("raw",r.encode(t),{name:"HMAC",hash:"SHA-256"},!1,["sign"]),o=await crypto.subtle.sign("HMAC",a,r.encode(e));return Array.from(new Uint8Array(o)).map(c=>c.toString(16).padStart(2,"0")).join("")}function G(t,e,n){if(typeof n!="string")return!1;let r=P(t,e);return vt(r,n.toLowerCase())}function vt(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 Bt(t,e){let r=Xe(t),a=Xe(e);r.length>64&&(r=et($(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 i=Ze(o,c),s=new Uint8Array(64+a.length);s.set(i),s.set(a,64);let f=et($(s)),p=new Uint8Array(64);p.fill(92);let u=Ze(o,p),l=new Uint8Array(64+f.length);return l.set(u),l.set(f,64),$(l)}function Ze(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 Xe(t){if(typeof TextEncoder<"u")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 a=t.charCodeAt(n),o=65536+((r&1023)<<10)+(a&1023);e.push(240|o>>18,128|o>>12&63,128|o>>6&63,128|o&63)}}return new Uint8Array(e)}function et(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 L=[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],_t=[1,2,4,8,16,32,64,128,27,54];function ge(t){if(t.length!==32)throw new Error("AES-256 requires a 32-byte key");let e=8,n=14,a=4*(n+1),o=new Array(a);for(let i=0;i<e;i++)o[i]=t[4*i]<<24|t[4*i+1]<<16|t[4*i+2]<<8|t[4*i+3];for(let i=e;i<a;i++){let s=o[i-1];i%e===0?s=rt(Ht(s))^_t[Math.floor(i/e)-1]<<24:e>6&&i%e===4&&(s=rt(s)),o[i]=o[i-e]^s}let c=[];for(let i=0;i<=n;i++){let s=new Uint8Array(16);for(let f=0;f<4;f++){let p=o[i*4+f];s[4*f]=p>>>24&255,s[4*f+1]=p>>>16&255,s[4*f+2]=p>>>8&255,s[4*f+3]=p&255}c.push(s)}return c}function Ht(t){return(t<<8|t>>>24)>>>0}function rt(t){return(L[t>>>24&255]<<24|L[t>>>16&255]<<16|L[t>>>8&255]<<8|L[t&255]<<0)>>>0}function be(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;me(n,e[0]);for(let o=1;o<r;o++)ot(n),st(n),Ft(n),me(n,e[o]);ot(n),st(n),me(n,e[r]);let a=new Uint8Array(16);for(let o=0;o<4;o++)for(let c=0;c<4;c++)a[o*4+c]=n[c][o];return a}function ot(t){for(let e=0;e<4;e++)for(let n=0;n<4;n++)t[e][n]=L[t[e][n]]}function st(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 Ft(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]=M(2,n[0])^M(3,n[1])^n[2]^n[3],t[1][e]=n[0]^M(2,n[1])^M(3,n[2])^n[3],t[2][e]=n[0]^n[1]^M(2,n[2])^M(3,n[3]),t[3][e]=M(3,n[0])^n[1]^n[2]^M(2,n[3])}}function me(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 M(t,e){let n=0,r=t,a=e;for(let o=0;o<8;o++){a&1&&(n^=r);let c=r&128;r=r<<1&255,c&&(r^=27),a>>=1}return n}function oe(t,e,n){let r=ge(t),a=Math.ceil(n.length/16),o=new Uint8Array(n.length),c=new Uint8Array(e);for(let i=0;i<a;i++){let s=be(c,r),f=Math.min(16,n.length-i*16);for(let p=0;p<f;p++)o[i*16+p]=n[i*16+p]^s[p];he(c)}return o}function he(t){for(let e=15;e>=12;e--){let n=t[e]+1;if(t[e]=n&255,n<=255)break}}function it(t,e,n){let r=Math.floor(n/4294967296),a=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]=a>>>24&255,t[e+5]=a>>>16&255,t[e+6]=a>>>8&255,t[e+7]=a&255}function at(t,e,n){let a=Math.ceil(e.length/16),o=Math.ceil(n.length/16),c=a+o+1,i=new Uint8Array(16);for(let l=0;l<a;l++){let m=new Uint8Array(16),y=l*16,w=Math.min(16,e.length-y);for(let x=0;x<w;x++)m[x]=e[y+x];for(let x=0;x<16;x++)m[x]^=i[x];let R=xe(m,t);i.set(R)}for(let l=0;l<o;l++){let m=new Uint8Array(16),y=l*16,w=Math.min(16,n.length-y);for(let x=0;x<w;x++)m[x]=n[y+x];for(let x=0;x<16;x++)m[x]^=i[x];let R=xe(m,t);i.set(R)}let s=new Uint8Array(16),f=e.length*8,p=n.length*8;it(s,0,f),it(s,8,p);for(let l=0;l<16;l++)s[l]^=i[l];return xe(s,t)}function xe(t,e){let n=new Uint8Array(16),r=new Uint8Array(e);for(let a=0;a<16;a++)for(let o=0;o<8;o++){if(t[15-a]>>7-o&1)for(let i=0;i<16;i++)n[i]^=r[i];let c=r[15]&1;for(let i=15;i>0;i--)r[i]=r[i]>>1|(r[i-1]&1)<<7;r[0]=r[0]>>1,c&&(r[0]^=225)}return n}function ct(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 a=new Uint8Array(16);a.set(n),a[15]=1;let o=ge(e),c=new Uint8Array(16),i=be(c,o),s=new Uint8Array(16);s.set(n),s[15]=1;let f=new Uint8Array(s);he(f);let p=oe(e,f,t),u=at(i,r,p),l=oe(e,s,u),m=new Uint8Array(16);for(let y=0;y<16;y++)m[y]=u[y]^l[y];return{ciphertext:p,tag:m}}function ut(t,e,n,r,a=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=ge(n),c=new Uint8Array(16),i=be(c,o),s=new Uint8Array(16);s.set(r),s[15]=1;let f=at(i,a,t),p=oe(n,s,f),u=new Uint8Array(16);for(let y=0;y<16;y++)u[y]=f[y]^p[y];let l=0;for(let y=0;y<16;y++)l|=e[y]^u[y];if(l!==0)throw new Error("AES-256-GCM authentication failed: tag mismatch");let m=new Uint8Array(s);return he(m),oe(n,m,t)}function j(){try{if(typeof globalThis<"u"){if(typeof globalThis.crypto<"u"&&globalThis.crypto.subtle)return globalThis.crypto;try{let t=typeof require<"u"?require:null;if(t){let e=t("node:crypto");if(e?.webcrypto)return e.webcrypto}}catch{}}}catch{}return null}function we(){return!0}function Ae(){return j()!==null}var ft=16,pt=12;function $t(t){let e=j();if(e){let r=new Uint8Array(t);return e.getRandomValues(r),r}try{if(typeof wx<"u"&&typeof wx.getRandomValues=="function"){let r=new Uint8Array(t);return wx.getRandomValues(r),r}}catch{}let n=new Uint8Array(t);for(let r=0;r<t;r++)n[r]=Math.floor(Math.random()*256);return n}function N(t){let e="",n=t.byteLength;for(let r=0;r<n;r++)e+=String.fromCharCode(t[r]);return btoa(e)}function D(t){let e=atob(t),n=e.length,r=new Uint8Array(n);for(let a=0;a<n;a++)r[a]=e.charCodeAt(a);return r}async function Gt(t,e){let n=j();if(!n)throw new Error("Web Crypto API is not available");let r=await n.subtle.importKey("raw",e,"AES-GCM",!1,["encrypt"]),a=new Uint8Array(pt);n.getRandomValues(a);let o=new TextEncoder().encode(t),c=new Uint8Array(await n.subtle.encrypt({name:"AES-GCM",iv:a,tagLength:128},r,o)),i=c.slice(0,c.length-ft),s=c.slice(c.length-ft),f={n:N(a),j:N(i),t:N(s)};return JSON.stringify(f)}async function Lt(t,e){let n=j();if(!n)throw new Error("Web Crypto API is not available");let{n:r,j:a,t:o}=JSON.parse(t),c=D(r),i=D(a),s=D(o),f=new Uint8Array(i.length+s.length);f.set(i),f.set(s,i.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 Kt(t,e){let n=$t(pt),r=new TextEncoder().encode(t),{ciphertext:a,tag:o}=ct(r,e,n),c={n:N(n),j:N(a),t:N(o)};return JSON.stringify(c)}function Wt(t,e){let{n,j:r,t:a}=JSON.parse(t),o=D(n),c=D(r),i=D(a),s=ut(c,i,e,o);return new TextDecoder().decode(s)}async function K(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 j()?await Gt(t,e):Kt(t,e)}async function W(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 j()?await Lt(t,e):Wt(t,e)}function Y(t){let{method:e,pathAndQuery:n,body:r,appId:a,timestamp:o,secretKey:c}=t,i=F(r),s=[e.toUpperCase(),n,i,String(a),String(o)].join(`
|
|
2
|
-
`);return P(c,s)}function J(t){return String(Math.floor(Date.now()/1e3)+t)}function lt(t){return t.replace(/\/+$/,"")}function yt(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 Yt(t,e){let n=new Date(t);if(isNaN(n.getTime()))return t;let r=a=>String(a).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 v(t,e=Z){function n(r){if(Array.isArray(r))return r.map(n);if(r&&typeof r=="object"){let a={};for(let o in r)Object.prototype.hasOwnProperty.call(r,o)&&(o==="createdAt"||o==="updatedAt"?a[o]=Yt(r[o],e):a[o]=n(r[o]));return a}return r}return n(t)}async function dt(t,e,n,r){let a=t.headers["content-type"]||"",o,c=t.body;if(a.includes("application/json"))try{o=JSON.parse(c)}catch{o=c}else o=c;if(e&&o&&typeof o=="object"&&"j"in o)try{let s=await W(JSON.stringify(o),new TextEncoder().encode(n));try{o=JSON.parse(s)}catch{o=s}}catch(s){throw new A(400,"AES-256-GCM decryption failed",s instanceof Error?s.message:null)}let i=t.status>=200&&t.status<300;if(o&&typeof o=="object"&&"data"in o){let s=o;if(s.data=v(s.data,r),!i)throw new A(s.code||t.status,s.message||t.statusText,s.data);return s}if(!i)throw new A(t.status,t.statusText,o);return{code:0,message:"ok",data:v(o,r)}}function mt(t){if(t instanceof A)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 A(408,"Request timeout",null):new A(0,e,null)}throw new A(0,"Unknown error",t)}var b=null,E=null;function q(){if(b!==null)return b;if(typeof wx<"u"&&typeof wx.request=="function")return b="wx",b;if(typeof my<"u"&&typeof my.request=="function")return b="my",b;if(typeof window>"u"&&typeof document>"u"&&typeof global<"u"&&typeof global.require=="function")try{if(typeof require<"u"&&typeof require("@system.fetch")<"u")return b="hap",b}catch{}return typeof window<"u"&&typeof document<"u"?(b="h5",b):typeof process<"u"&&typeof process.versions<"u"&&typeof process.versions?.node<"u"?(b="nodejs",b):(b="unknown",b)}function z(){return E!==null?E:q()!=="wx"?(E="unknown",E):typeof tt<"u"&&typeof tt.request=="function"?(E="toutiao",E):typeof qq<"u"&&typeof qq.request=="function"?(E="qq",E):(E="wechat",E)}function Q(){let t=q();if(t==="my")return my;if(t!=="wx")return null;switch(z()){case"toutiao":return tt;case"qq":return qq;default:return wx}}function Te(){b=null,E=null}var Ee=async t=>{let{url:e,method:n,headers:r,body:a,signal:o}=t,c={method:n,headers:r,signal:o};a!==void 0&&n!=="GET"&&(c.body=a);let i=await fetch(e,c),s={};i.headers.forEach((p,u)=>{s[u.toLowerCase()]=p});let f=await i.text();return{status:i.status,statusText:i.statusText,headers:s,body:f}};var xt=async t=>{let e=Q();if(!e||typeof e.request!="function")throw new Error("Mini program request API is not available");let n=e.request,{url:r,method:a,headers:o,body:c,timeout:i}=t;return new Promise((s,f)=>{let p=n({url:r,method:a,header:o,data:c,timeout:i??3e5,dataType:"text",responseType:"text",success:u=>{let l={};if(u.header)for(let y of Object.keys(u.header))l[y.toLowerCase()]=u.header[y];let m;typeof u.data=="string"?m=u.data:u.data!==void 0&&u.data!==null?m=JSON.stringify(u.data):m="",s({status:u.statusCode,statusText:u.errMsg??"",headers:l,body:m})},fail:u=>{let l=u.errMsg??"Mini program request failed";l.includes("timeout")||l.includes("\u8D85\u65F6")?f(new Error("Request timeout")):f(new Error(l))}});if(t.signal){let u=()=>{typeof p.abort=="function"&&p.abort()};t.signal.addEventListener("abort",u,{once:!0})}})};var gt=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:a,headers:o,body:c,timeout:i}=t;return new Promise((s,f)=>{let p=n({url:r,method:a.toUpperCase(),headers:o,data:c!==void 0?c:void 0,timeout:i??3e5,dataType:"text",success:u=>{let l=u.status??u.statusCode??200,m={};if(u.headers)for(let w of Object.keys(u.headers))m[w.toLowerCase()]=u.headers[w];let y;typeof u.data=="string"?y=u.data:u.data!==void 0&&u.data!==null?y=JSON.stringify(u.data):y="",s({status:l,statusText:"",headers:m,body:y})},fail:u=>{let l=u.errorMessage??u.errMsg??`Alipay request failed (error: ${u.error})`;f(new Error(l))},complete:()=>{}});if(t.signal){let u=()=>{p&&typeof p.abort=="function"&&p.abort()};t.signal.addEventListener("abort",u,{once:!0})}})};function Jt(){try{return require("@system.fetch")}catch{return null}}var bt=async t=>{let e=Jt();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:a,body:o}=t;return new Promise((c,i)=>{e.fetch({url:n,method:r.toUpperCase(),header:a,data:o,responseType:"text",success:s=>{let f={};if(s.headers)for(let p of Object.keys(s.headers))f[p.toLowerCase()]=s.headers[p];c({status:s.code,statusText:"",headers:f,body:typeof s.data=="string"?s.data:JSON.stringify(s.data)})},fail:s=>{i(new Error(`Quick App request failed (code: ${s.code}, data: ${s.data})`))},complete:()=>{}})})};var O=null;function ht(){if(O!==null)return O;switch(q()){case"h5":case"nodejs":O=Ee;break;case"wx":O=xt;break;case"my":O=gt;break;case"hap":O=bt;break;default:if(typeof fetch=="function")O=Ee;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 O}async function Re(t,e){let{method:n,path:r,params:a,encryption:o,timeout:c}=e,i=lt(t.baseUrl),s=o??t.isSafeMode,f=new URL(i+r),p=C(a),u,l="";if(n!=="GET")if(s&&p!==void 0){let d=await K(JSON.stringify(p),new TextEncoder().encode(t.secretKey));u=d,l=d}else if(p!==void 0){let d=JSON.stringify(p);u=d,l=d}else l="";else p&&typeof p=="object"&&Object.keys(p).length>0&&yt(f,p);let m=Number(J(t.offset)),y=f.pathname+f.search,w=Y({method:n,pathAndQuery:y,body:l,appId:t.appId,timestamp:m,secretKey:t.secretKey}),R=ht(),x=c??3e5;try{let d=await R({url:f.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":w,"Content-Type":"application/json"},body:n!=="GET"?u:void 0,timeout:x});return await dt(d,s,t.secretKey,t.timeFormat)}catch(d){return mt(d)}}var B=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(!I(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(!T(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(!T(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},a={}){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(!T(a))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:a})}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(!T(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(!T(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 k,wt,At,Tt,Et,V=class{constructor(e){We(this,k);H(e),this.config={baseUrl:e.baseUrl??Ye,appId:e.appId,apiKey:e.apiKey,secretKey:e.secretKey,version:e.version??0,isSafeMode:e.isSafeMode??!1,timeFormat:e.timeFormat??Z,offset:e.offset??0},this.db={collection:n=>_(this,k,wt).call(this,n),toObjectID:n=>_(this,k,Tt).call(this,n),getCollections:()=>_(this,k,At).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{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}/${_(this,k,Et).call(this,e)}`,n,r)}async request(e,n,r,a){if(typeof n!="string")throw new TypeError("request path must be a string");return await Re(this.config,{method:e,path:n,params:r,encryption:a??this.config.isSafeMode})}assertObjectID(e,n="ObjectID"){return S(e,n)}isNonEmptyObject(e){return h(e)}isPlainObject(e){return T(e)}isNonEmptyArrayWithNonEmptyObjects(e){return I(e)}hmacSHA256(e,n){return P(e,n)}verifyHmacSHA256(e,n,r){return G(e,n,r)}};k=new WeakSet,wt=function(e){if(typeof e!="string")throw new TypeError("Collection name must be a string");return new B(this,e)},At=async function(){return await this.request("GET","/v5/schemas")},Tt=function(e){return S(e),`ObjectID('${e}')`},Et=function(e){let n=e.startsWith("/")?e.slice(1):e,r=n.indexOf("#"),a=r!==-1?n.slice(r):"",o=r!==-1?n.slice(0,r):n,c=o.indexOf("?"),i=c!==-1?o.slice(c):"",s=c!==-1?o.slice(0,c):o;return s.endsWith("/")?s=s+"index.jsc":s.endsWith(".jsc")||(s.endsWith(".js")?s=s.replace(/\.js$/,".jsc"):s=s+".jsc"),s+i+a};var Rt=V;function Se(t){if(!X.test(t))throw new Error(`Invalid ObjectID: "${t}" (must be 24 hex characters)`);return`ObjectID('${t}')`}function Ue(t){return`Date('${t}')`}function ke(t){return`DateTime('${t}')`}function Pe(t){return`Timestamp('${String(t)}')`}function Me(t){return`Boolean(${t})`}function Oe(t){return`Integer(${t})`}function Ce(t){return`Bigint(${Number(t)})`}function Ie(t){return`Float(${t})`}function qe(t){return`Double(${t})`}function Ne(t){return`Array(${JSON.stringify(t)})`}function De(t){return`Map(${JSON.stringify(t)})`}function je(t){return`Map[](${JSON.stringify(t)})`}var ve="Null",Be="None",_e="Nil",He="",Fe="UNDEFINED",$e="Undefined";var se="time.Now()",ie="time.Now().Unix()",ae="time.Now().UnixNano()",ce="time.Now().Weekday()",ue="time.Now().Weekday().Chinese()",Ge={Now:()=>se,NowUnix:()=>ie,NowUnixNano:()=>ae,NowWeekday:()=>ce,NowWeekdayChinese:()=>ue};0&&(module.exports={Array,Bigint,Boolean,Date,DateTime,Double,Empty,Float,Integer,Map,MapArray,Nil,None,Null,ObjectID,T1Collection,T1YError,T1YOS,TimeNow,TimeNowUnix,TimeNowUnixNano,TimeNowWeekday,TimeNowWeekdayChinese,Timestamp,UNDEFINED,Undefined,ValidationError,assertObjectID,convertDateTypes,createSignature,decryptAESGCM,encryptAESGCM,formatTimestampsToLocal,getMiniProgramAPI,getMiniProgramSubType,getPlatformType,getSafeTimestamp,hmacSHA256Hex,hmacSHA256HexAsync,isAESGCMAvailable,isNonEmptyArrayWithNonEmptyObjects,isNonEmptyObject,isPlainObject,isWebCryptoAvailable,resetPlatformDetection,sha256Hex,sha256HexAsync,timeNow,validateApiKey,validateAppId,validateBaseUrl,validateInitConfig,validateSecretKey,verifyHmacSHA256});
|
|
1
|
+
"use strict";var le=Object.defineProperty;var Mt=Object.getOwnPropertyDescriptor;var Ot=Object.getOwnPropertyNames;var Ct=Object.prototype.hasOwnProperty;var Ke=t=>{throw TypeError(t)};var It=(t,e)=>{for(var n in e)le(t,n,{get:e[n],enumerable:!0})},qt=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Ot(e))!Ct.call(t,i)&&i!==n&&le(t,i,{get:()=>e[i],enumerable:!(r=Mt(e,i))||r.enumerable});return t};var Nt=t=>qt(le({},"__esModule",{value:!0}),t);var Dt=(t,e,n)=>e.has(t)||Ke("Cannot "+n);var We=(t,e,n)=>e.has(t)?Ke("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,n);var _=(t,e,n)=>(Dt(t,e,"access private method"),n);var tn={};It(tn,{Array:()=>Ne,Bigint:()=>Ce,Boolean:()=>Me,Date:()=>Ue,DateTime:()=>ke,Double:()=>qe,Empty:()=>He,Float:()=>Ie,Integer:()=>Oe,Map:()=>De,MapArray:()=>je,Nil:()=>_e,None:()=>Be,Null:()=>ve,ObjectID:()=>Se,T1Collection:()=>B,T1YError:()=>T,T1YOS:()=>V,TimeNow:()=>se,TimeNowUnix:()=>ie,TimeNowUnixNano:()=>ae,TimeNowWeekday:()=>ce,TimeNowWeekdayChinese:()=>ue,Timestamp:()=>Pe,UNDEFINED:()=>$e,Undefined:()=>Fe,ValidationError:()=>b,assertObjectID:()=>S,convertDateTypes:()=>C,createSignature:()=>Y,decryptAESGCM:()=>W,default:()=>St,encryptAESGCM:()=>K,formatTimestampsToLocal:()=>v,getMiniProgramAPI:()=>z,getMiniProgramSubType:()=>Q,getPlatformType:()=>q,getSafeTimestamp:()=>J,hmacSHA256Hex:()=>P,hmacSHA256HexAsync:()=>de,isAESGCMAvailable:()=>we,isNonEmptyArrayWithNonEmptyObjects:()=>I,isNonEmptyObject:()=>w,isPlainObject:()=>E,isWebCryptoAvailable:()=>Ae,resetPlatformDetection:()=>Te,sha256Hex:()=>$,sha256HexAsync:()=>ye,timeNow:()=>Ge,validateApiKey:()=>te,validateAppId:()=>ee,validateBaseUrl:()=>re,validateInitConfig:()=>H,validateSecretKey:()=>ne,verifyHmacSHA256:()=>G});module.exports=Nt(tn);var Ye="https://myapp.t1y.net";var Z="YYYY-MM-DD HH:mm:ss";var X=/^[0-9a-fA-F]{24}$/;var T=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 ee(t){if(!Number.isInteger(t))throw new b("appId must be an integer");if(t<1001)throw new b(`appId must be >= ${1001}`)}function te(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 ne(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 re(t){if(!/^https?:\/\//.test(t))throw new b('baseUrl must start with "http://" or "https://"')}function H(t){if(t.baseUrl!==void 0&&re(t.baseUrl),ee(t.appId),te(t.apiKey),ne(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(!X.test(t))throw new b(`Invalid ${e} string: "${t}"`);return!0}function C(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=>C(e));if(t&&typeof t=="object"){let e={};for(let n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=C(t[n]));return e}return t}function w(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)&&Object.keys(t).length>0}function E(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function I(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 Ve(){try{if(typeof require!="undefined")return require}catch(t){}return null}function $(t){let e=Ve();if(e)try{return e("node:crypto").createHash("sha256").update(t).digest("hex")}catch(r){}let n=jt(t);return F(n)}function F(t){return Bt(t)}async function ye(t){let e=Ve();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 jt(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 vt(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 Bt(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,vt(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 fe=(U(f[d-15],7)^U(f[d-15],18)^f[d-15]>>>3)>>>0,pe=(U(f[d-2],17)^U(f[d-2],19)^f[d-2]>>>10)>>>0;f[d]=f[d-16]+fe+f[d-7]+pe>>>0}let[p,u,y,m,l,g,A,x]=s;for(let d=0;d<64;d++){let fe=(U(l,6)^U(l,11)^U(l,25))>>>0,pe=(l&g^~l&A)>>>0,Le=x+fe+pe+e[d]+f[d]>>>0,Ut=(U(p,2)^U(p,13)^U(p,22))>>>0,kt=(p&u^p&y^u&y)>>>0,Pt=Ut+kt>>>0;x=A,A=g,g=l,l=m+Le>>>0,m=y,y=u,u=p,p=Le+Pt>>>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 U(t,e){return t>>>e|t<<32-e}function nt(){try{if(typeof require!="undefined")return require}catch(t){}return null}function P(t,e){let n=nt();if(n)try{return n("node:crypto").createHmac("sha256",t).update(e).digest("hex")}catch(r){}return Ht(t,e)}async function de(t,e){let n=nt();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 G(t,e,n){if(typeof n!="string")return!1;let r=P(t,e);return _t(r,n.toLowerCase())}function _t(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 Ht(t,e){let r=Xe(t),i=Xe(e);r.length>64&&(r=et(F(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=Ze(o,c),a=new Uint8Array(64+i.length);a.set(s),a.set(i,64);let f=et(F(a)),p=new Uint8Array(64);p.fill(92);let u=Ze(o,p),y=new Uint8Array(64+f.length);return y.set(u),y.set(f,64),F(y)}function Ze(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 Xe(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 et(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 L=[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],$t=[1,2,4,8,16,32,64,128,27,54];function ge(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=rt(Ft(a))^$t[Math.floor(s/e)-1]<<24:e>6&&s%e===4&&(a=rt(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 Ft(t){return(t<<8|t>>>24)>>>0}function rt(t){return(L[t>>>24&255]<<24|L[t>>>16&255]<<16|L[t>>>8&255]<<8|L[t&255]<<0)>>>0}function be(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;me(n,e[0]);for(let o=1;o<r;o++)ot(n),st(n),Gt(n),me(n,e[o]);ot(n),st(n),me(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 ot(t){for(let e=0;e<4;e++)for(let n=0;n<4;n++)t[e][n]=L[t[e][n]]}function st(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 Gt(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]=M(2,n[0])^M(3,n[1])^n[2]^n[3],t[1][e]=n[0]^M(2,n[1])^M(3,n[2])^n[3],t[2][e]=n[0]^n[1]^M(2,n[2])^M(3,n[3]),t[3][e]=M(3,n[0])^n[1]^n[2]^M(2,n[3])}}function me(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 M(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 oe(t,e,n){let r=ge(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=be(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];he(c)}return o}function he(t){for(let e=15;e>=12;e--){let n=t[e]+1;if(t[e]=n&255,n<=255)break}}function it(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 at(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=xe(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=xe(m,t);s.set(A)}let a=new Uint8Array(16),f=e.length*8,p=n.length*8;it(a,0,f),it(a,8,p);for(let y=0;y<16;y++)a[y]^=s[y];return xe(a,t)}function xe(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 ct(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=ge(e),c=new Uint8Array(16),s=be(c,o),a=new Uint8Array(16);a.set(n),a[15]=1;let f=new Uint8Array(a);he(f);let p=oe(e,f,t),u=at(s,r,p),y=oe(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 ut(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=ge(n),c=new Uint8Array(16),s=be(c,o),a=new Uint8Array(16);a.set(r),a[15]=1;let f=at(s,i,t),p=oe(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 he(m),oe(n,m,t)}function j(){try{if(typeof globalThis!="undefined"){if(typeof globalThis.crypto!="undefined"&&globalThis.crypto.subtle)return globalThis.crypto;try{let t=typeof require!="undefined"?require:null;if(t){let e=t("node:crypto");if(e!=null&&e.webcrypto)return e.webcrypto}}catch(t){}}}catch(t){}return null}function we(){return!0}function Ae(){return j()!==null}var ft=16,pt=12;function Lt(t){let e=j();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 N(t){let e="",n=t.byteLength;for(let r=0;r<n;r++)e+=String.fromCharCode(t[r]);return btoa(e)}function D(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 Kt(t,e){let n=j();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(pt);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-ft),a=c.slice(c.length-ft),f={n:N(i),j:N(s),t:N(a)};return JSON.stringify(f)}async function Wt(t,e){let n=j();if(!n)throw new Error("Web Crypto API is not available");let{n:r,j:i,t:o}=JSON.parse(t),c=D(r),s=D(i),a=D(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 Yt(t,e){let n=Lt(pt),r=new TextEncoder().encode(t),{ciphertext:i,tag:o}=ct(r,e,n),c={n:N(n),j:N(i),t:N(o)};return JSON.stringify(c)}function Jt(t,e){let{n,j:r,t:i}=JSON.parse(t),o=D(n),c=D(r),s=D(i),a=ut(c,s,e,o);return new TextDecoder().decode(a)}async function K(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 j()?await Kt(t,e):Yt(t,e)}async function W(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 j()?await Wt(t,e):Jt(t,e)}function Y(t){let{method:e,pathAndQuery:n,body:r,appId:i,timestamp:o,secretKey:c}=t,s=$(r),a=[e.toUpperCase(),n,s,String(i),String(o)].join(`
|
|
2
|
+
`);return P(c,a)}function J(t){return String(Math.floor(Date.now()/1e3)+t)}function lt(t){return t.replace(/\/+$/,"")}function yt(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 dt(t){let e=t.indexOf("://");if(e===-1)return t;let n=t.indexOf("/",e+3);return n===-1?"/":t.substring(n)}function Qt(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 v(t,e=Z){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]=Qt(r[o],e):i[o]=n(r[o]));return i}return r}return n(t)}async function mt(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 W(JSON.stringify(o),new TextEncoder().encode(n));try{o=JSON.parse(a)}catch(f){o=a}}catch(a){throw new T(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=v(a.data,r),!s)throw new T(a.code||t.status,a.message||t.statusText,a.data);return a}if(!s)throw new T(t.status,t.statusText,o);return{code:0,message:"ok",data:v(o,r)}}function xt(t){if(t instanceof T)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 T(408,"Request timeout",null):new T(0,e,null)}throw new T(0,"Unknown error",t)}var h=null,R=null;function q(){var t;if(h!==null)return h;if(typeof wx!="undefined"&&typeof wx.request=="function")return h="wx",h;if(typeof my!="undefined"&&typeof my.request=="function")return h="my",h;if(typeof window=="undefined"&&typeof document=="undefined"&&typeof global!="undefined"&&typeof global.require=="function")try{if(typeof require!="undefined"&&typeof require("@system.fetch")!="undefined")return h="hap",h}catch(e){}return typeof window!="undefined"&&typeof document!="undefined"?(h="h5",h):typeof process!="undefined"&&typeof process.versions!="undefined"&&typeof((t=process.versions)==null?void 0:t.node)!="undefined"?(h="nodejs",h):(h="unknown",h)}function Q(){return R!==null?R:q()!=="wx"?(R="unknown",R):typeof tt!="undefined"&&typeof tt.request=="function"?(R="toutiao",R):typeof qq!="undefined"&&typeof qq.request=="function"?(R="qq",R):(R="wechat",R)}function z(){let t=q();if(t==="my")return my;if(t!=="wx")return null;switch(Q()){case"toutiao":return tt;case"qq":return qq;default:return wx}}function Te(){h=null,R=null}var Ee=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 gt=async t=>{let e=z();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 bt=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 zt(){try{return require("@system.fetch")}catch(t){return null}}var ht=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 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 O=null;function wt(){if(O!==null)return O;switch(q()){case"h5":case"nodejs":O=Ee;break;case"wx":O=gt;break;case"my":O=bt;break;case"hap":O=ht;break;default:if(typeof fetch=="function")O=Ee;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 O}async function Re(t,e){let{method:n,path:r,params:i,encryption:o,timeout:c}=e,s=lt(t.baseUrl),a=o!=null?o:t.isSafeMode,f=s+r,p=C(i),u,y="";if(n!=="GET")if(a&&p!==void 0){let d=await K(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=yt(p);d&&(f+=d)}let m=Number(J(t.offset)),l=dt(f),g=Y({method:n,pathAndQuery:l,body:y,appId:t.appId,timestamp:m,secretKey:t.secretKey}),A=wt(),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 mt(d,a,t.secretKey,t.timeFormat)}catch(d){return xt(d)}}var B=class{constructor(e,n){this.client=e,this.name=n}async insertOne(e){if(!w(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),!w(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(!w(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(!w(e))throw new TypeError("updateOne filter must be a non-empty plain object");if(!w(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(!w(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(!I(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(!E(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(!E(e))throw new TypeError("updateMany filter must be a plain object");if(!w(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),!w(r))throw new TypeError("find sort must be a non-empty plain object");if(!E(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(!E(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(!E(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 k,At,Tt,Et,Rt,V=class{constructor(e){We(this,k);var n,r,i,o,c;H(e),this.config={baseUrl:(n=e.baseUrl)!=null?n:Ye,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:Z,offset:(c=e.offset)!=null?c:0},this.db={collection:s=>_(this,k,At).call(this,s),toObjectID:s=>_(this,k,Et).call(this,s),getCollections:()=>_(this,k,Tt).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}/${_(this,k,Rt).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 Re(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 w(e)}isPlainObject(e){return E(e)}isNonEmptyArrayWithNonEmptyObjects(e){return I(e)}hmacSHA256(e,n){return P(e,n)}verifyHmacSHA256(e,n,r){return G(e,n,r)}};k=new WeakSet,At=function(e){if(typeof e!="string")throw new TypeError("Collection name must be a string");return new B(this,e)},Tt=async function(){return await this.request("GET","/v5/schemas")},Et=function(e){return S(e),`ObjectID('${e}')`},Rt=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 St=V;function Se(t){if(!X.test(t))throw new Error(`Invalid ObjectID: "${t}" (must be 24 hex characters)`);return`ObjectID('${t}')`}function Ue(t){return`Date('${t}')`}function ke(t){return`DateTime('${t}')`}function Pe(t){return`Timestamp('${String(t)}')`}function Me(t){return`Boolean(${t})`}function Oe(t){return`Integer(${t})`}function Ce(t){return`Bigint(${Number(t)})`}function Ie(t){return`Float(${t})`}function qe(t){return`Double(${t})`}function Ne(t){return`Array(${JSON.stringify(t)})`}function De(t){return`Map(${JSON.stringify(t)})`}function je(t){return`Map[](${JSON.stringify(t)})`}var ve="Null",Be="None",_e="Nil",He="",$e="UNDEFINED",Fe="Undefined";var se="time.Now()",ie="time.Now().Unix()",ae="time.Now().UnixNano()",ce="time.Now().Weekday()",ue="time.Now().Weekday().Chinese()",Ge={Now:()=>se,NowUnix:()=>ie,NowUnixNano:()=>ae,NowWeekday:()=>ce,NowWeekdayChinese:()=>ue};0&&(module.exports={Array,Bigint,Boolean,Date,DateTime,Double,Empty,Float,Integer,Map,MapArray,Nil,None,Null,ObjectID,T1Collection,T1YError,T1YOS,TimeNow,TimeNowUnix,TimeNowUnixNano,TimeNowWeekday,TimeNowWeekdayChinese,Timestamp,UNDEFINED,Undefined,ValidationError,assertObjectID,convertDateTypes,createSignature,decryptAESGCM,encryptAESGCM,formatTimestampsToLocal,getMiniProgramAPI,getMiniProgramSubType,getPlatformType,getSafeTimestamp,hmacSHA256Hex,hmacSHA256HexAsync,isAESGCMAvailable,isNonEmptyArrayWithNonEmptyObjects,isNonEmptyObject,isPlainObject,isWebCryptoAvailable,resetPlatformDetection,sha256Hex,sha256HexAsync,timeNow,validateApiKey,validateAppId,validateBaseUrl,validateInitConfig,validateSecretKey,verifyHmacSHA256});
|
|
3
3
|
//# sourceMappingURL=index.js.map
|