UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 4.09 kB
import{i as e}from"./transcript-global-singleton-DIJgobpU.mjs";import{n as t}from"./transcript-sql-connection-CRz-dHXM.mjs";import{u as n}from"./transcript-sqlite-post-commit-BDZjIt2B.mjs";const{kyselyByDatabase:r,queryErrorHandlerByDatabase:i}=e(Symbol.for(`openclaw.sqliteKyselyCacheState`),()=>({kyselyByDatabase:/* @__PURE__ */ new WeakMap,queryErrorHandlerByDatabase:/* @__PURE__ */ new WeakMap})),a=Symbol.for(`openclaw.kyselySyncStatementCache`),o=Symbol.for(`openclaw.kyselySyncStatementInvalidation`),s=Symbol.for(`openclaw.kyselySyncStatementCacheEnabled`),c=Symbol.for(`openclaw.kyselySyncAuthorizerActive`),l=Symbol.for(`openclaw.sqliteDisposeCallbacks`),u=Symbol.for(`openclaw.sqliteDisposeGuards`),d=65536;function disposeSqliteStatement(e){e[Symbol.dispose]?.()}function clearStatementCache(e){let t=e[a];if(delete e[a],t)for(let e of t.statements.values())t.active.has(e)||disposeSqliteStatement(e)}function registerNodeSqliteDisposeCallback(e,t){let r=e;return installStatementInvalidation(r),n(r[l]??=/* @__PURE__ */ new Set,t)}function registerNodeSqliteDisposeGuard(e,t){let r=e;return installStatementInvalidation(r),n(r[u]??=/* @__PURE__ */ new Set,t)}function assertNodeSqliteDisposalAllowed(e){for(let t of e[u]??[])t()}function disposeNodeSqliteDependents(e,t=`close`){assertNodeSqliteDisposalAllowed(e);for(let n of e[l]??[])n(t)}function registerNodeSqliteKyselyQueryErrorHandler(e,t){i.set(e,t)}function clearNodeSqliteKyselyCacheForDatabase(e){clearStatementCache(e),r.delete(e),i.delete(e)}function installStatementInvalidation(e){if(!e[o]){if(typeof e.setAuthorizer==`function`){let t=e.setAuthorizer.bind(e);Object.defineProperty(e,"setAuthorizer",{configurable:!0,writable:!0,value(e){t(e),this[c]=e!==null,clearStatementCache(this)}})}if(typeof e.deserialize==`function`){let t=e.deserialize.bind(e);Object.defineProperty(e,"deserialize",{configurable:!0,writable:!0,value(...e){disposeNodeSqliteDependents(this,`replace`);try{t(...e)}finally{clearStatementCache(this)}}})}for(let t of[`close`,Symbol.dispose])if(typeof e[t]==`function`){let n=e[t].bind(e);Object.defineProperty(e,t,{configurable:!0,writable:!0,value(){return disposeNodeSqliteDependents(this),clearNodeSqliteKyselyCacheForDatabase(this),n()}})}Object.defineProperty(e,o,{configurable:!0,value:!0})}}function enableNodeSqliteKyselyStatementCache(e){let t=e;installStatementInvalidation(t),t[s]=!0}function queryFitsStatementCache(e,t){let n=Buffer.byteLength(e);if(n>d)return!1;for(let e of t){if(typeof e==`string`){if(e.length>d-n)return!1;n+=Buffer.byteLength(e)}else ArrayBuffer.isView(e)&&(n+=e.byteLength);if(n>d)return!1}return!0}function executeWithCachedStatement(e,n,r,i,o){if(t(e))return i(e.prepare(n));let l=e,executeLeased=(e,t)=>{if(o){try{o(t)}catch(e){throw t(),e}return i(e)}try{return i(e)}finally{t()}};if(!l[s]||l[c]||!queryFitsStatementCache(n,r)){let t=e.prepare(n);return executeLeased(t,()=>disposeSqliteStatement(t))}let u=l[a];u||(u={statements:/* @__PURE__ */ new Map,candidates:/* @__PURE__ */ new Set,active:/* @__PURE__ */ new WeakSet},Object.defineProperty(l,a,{configurable:!0,value:u}));let d=u.statements.get(n),f;if(d&&!u.active.has(d))u.statements.delete(n),u.statements.set(n,d),f=d;else if(f=e.prepare(n),!d&&u.candidates.delete(n)){if(u.statements.set(n,f),u.statements.size>64){let e=u.statements.entries().next().value;u.statements.delete(e[0]),u.active.has(e[1])||disposeSqliteStatement(e[1])}}else if(!d&&(u.candidates.add(n),u.candidates.size>64)){let e=u.candidates.values().next().value;e!==void 0&&u.candidates.delete(e)}return u.active.add(f),executeLeased(f,()=>{u.active.delete(f),(l[a]!==u||u.statements.get(n)!==f)&&disposeSqliteStatement(f)})}export{enableNodeSqliteKyselyStatementCache as a,r as c,registerNodeSqliteDisposeGuard as d,registerNodeSqliteKyselyQueryErrorHandler as f,disposeSqliteStatement as i,i as l,clearNodeSqliteKyselyCacheForDatabase as n,executeWithCachedStatement as o,disposeNodeSqliteDependents as r,installStatementInvalidation as s,assertNodeSqliteDisposalAllowed as t,registerNodeSqliteDisposeCallback as u};