UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 4.05 kB
import{Cn as e}from"./openclaw-state-read-subsystem-Dwoo5bcz.mjs";import{p as t,u as n}from"./openclaw-state-read-sqlite-post-commit-CsXPYVOo.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,n){let r=e;return installStatementInvalidation(r),t(r[l]??=/* @__PURE__ */ new Set,n)}function registerNodeSqliteDisposeGuard(e,n){let r=e;return installStatementInvalidation(r),t(r[u]??=/* @__PURE__ */ new Set,n)}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,t,r,i,o){if(n(e))return i(e.prepare(t));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(t,r)){let n=e.prepare(t);return executeLeased(n,()=>disposeSqliteStatement(n))}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(t),f;if(d&&!u.active.has(d))u.statements.delete(t),u.statements.set(t,d),f=d;else if(f=e.prepare(t),!d&&u.candidates.delete(t)){if(u.statements.set(t,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(t),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(t)!==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};