module.exports=[287920,t=>{"use strict";var e=t.i(689960),a=t.i(380488);async function n(t,i=null){let r=await (0,a.getAdapter)(),u=(0,e.v4)(),o=new Date().toISOString();return r.run("INSERT INTO rateLimits(id, userId, packageId, rtpMinute, rtpDay, tokenLimitMonthly, creditLimit, maxConcurrent, created_at, updated_at) VALUES(?, ?, ?, 100, 100000, 1000000, 5.0, 5, ?, ?)",[u,t,i,o,o]),{id:u,userId:t,packageId:i,rtpMinute:100,rtpDay:1e5,tokenLimitMonthly:1e6,creditLimit:5,maxConcurrent:5}}async function i(t){var e;return(e=(await (0,a.getAdapter)()).get("SELECT * FROM rateLimits WHERE userId = ?",[t]))?{id:e.id,userId:e.userId,packageId:e.packageId,rtpMinute:e.rtpMinute,rtpDay:e.rtpDay,tokenLimitMonthly:e.tokenLimitMonthly,creditLimit:e.creditLimit,maxConcurrent:e.maxConcurrent,created_at:e.created_at,updated_at:e.updated_at}:null}async function r(t,e){let n=await (0,a.getAdapter)(),i=new Date().toISOString(),r=[],u=[];for(let[t,a]of Object.entries(e))["packageId","rtpMinute","rtpDay","tokenLimitMonthly","creditLimit","maxConcurrent"].includes(t)&&(r.push(`${t} = ?`),u.push(a));0!==r.length&&(r.push("updated_at = ?"),u.push(i),u.push(t),n.run(`UPDATE rateLimits SET ${r.join(", ")} WHERE userId = ?`,u))}async function u(t){let e=await (0,a.getAdapter)(),n=new Date,i=new Date(n.getFullYear(),n.getMonth(),1).toISOString(),r=e.get(`SELECT COALESCE(SUM(uh.promptTokens), 0) + COALESCE(SUM(uh.completionTokens), 0) as totalTokens
     FROM usageHistory uh
     INNER JOIN apiKeys ak ON uh.apiKey = ak.key
     WHERE ak.userId = ? AND uh.timestamp >= ?`,[t,i]);return r&&r.totalTokens||0}async function o(t){let e=await (0,a.getAdapter)(),n=new Date,i=new Date(n.getFullYear(),n.getMonth(),1).toISOString(),r=e.get(`SELECT COALESCE(SUM(uh.cost), 0) as totalCost
     FROM usageHistory uh
     INNER JOIN apiKeys ak ON uh.apiKey = ak.key
     WHERE ak.userId = ? AND uh.timestamp >= ?`,[t,i]);return r&&r.totalCost||0}t.s(["createDefaults",0,n,"getByUserId",0,i,"getMonthlyCost",0,o,"getMonthlyTokens",0,u,"updateLimits",0,r])}];

//# sourceMappingURL=src_lib_db_repos_rateLimitRepo_0txes3z.js.map