@jiggai/kitchen 0.4.2 → 0.4.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.
Files changed (64) hide show
  1. package/.next/BUILD_ID +1 -1
  2. package/.next/build-manifest.json +2 -2
  3. package/.next/prerender-manifest.json +3 -3
  4. package/.next/server/app/_global-error.html +2 -2
  5. package/.next/server/app/_global-error.rsc +1 -1
  6. package/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
  7. package/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  8. package/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  9. package/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  10. package/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  11. package/.next/server/app/_not-found.html +1 -1
  12. package/.next/server/app/_not-found.rsc +2 -2
  13. package/.next/server/app/_not-found.segments/_full.segment.rsc +2 -2
  14. package/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  15. package/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
  16. package/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  17. package/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  18. package/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  19. package/.next/server/app/channels.html +2 -2
  20. package/.next/server/app/channels.rsc +2 -2
  21. package/.next/server/app/channels.segments/_full.segment.rsc +2 -2
  22. package/.next/server/app/channels.segments/_head.segment.rsc +1 -1
  23. package/.next/server/app/channels.segments/_index.segment.rsc +1 -1
  24. package/.next/server/app/channels.segments/_tree.segment.rsc +1 -1
  25. package/.next/server/app/channels.segments/channels/__PAGE__.segment.rsc +1 -1
  26. package/.next/server/app/channels.segments/channels.segment.rsc +1 -1
  27. package/.next/server/app/goals/new.html +2 -2
  28. package/.next/server/app/goals/new.rsc +2 -2
  29. package/.next/server/app/goals/new.segments/_full.segment.rsc +2 -2
  30. package/.next/server/app/goals/new.segments/_head.segment.rsc +1 -1
  31. package/.next/server/app/goals/new.segments/_index.segment.rsc +1 -1
  32. package/.next/server/app/goals/new.segments/_tree.segment.rsc +1 -1
  33. package/.next/server/app/goals/new.segments/goals/new/__PAGE__.segment.rsc +1 -1
  34. package/.next/server/app/goals/new.segments/goals/new.segment.rsc +1 -1
  35. package/.next/server/app/goals/new.segments/goals.segment.rsc +1 -1
  36. package/.next/server/app/goals.html +1 -1
  37. package/.next/server/app/goals.rsc +2 -2
  38. package/.next/server/app/goals.segments/_full.segment.rsc +2 -2
  39. package/.next/server/app/goals.segments/_head.segment.rsc +1 -1
  40. package/.next/server/app/goals.segments/_index.segment.rsc +1 -1
  41. package/.next/server/app/goals.segments/_tree.segment.rsc +1 -1
  42. package/.next/server/app/goals.segments/goals/__PAGE__.segment.rsc +1 -1
  43. package/.next/server/app/goals.segments/goals.segment.rsc +1 -1
  44. package/.next/server/app/settings.html +1 -1
  45. package/.next/server/app/settings.rsc +2 -2
  46. package/.next/server/app/settings.segments/_full.segment.rsc +2 -2
  47. package/.next/server/app/settings.segments/_head.segment.rsc +1 -1
  48. package/.next/server/app/settings.segments/_index.segment.rsc +1 -1
  49. package/.next/server/app/settings.segments/_tree.segment.rsc +1 -1
  50. package/.next/server/app/settings.segments/settings/__PAGE__.segment.rsc +1 -1
  51. package/.next/server/app/settings.segments/settings.segment.rsc +1 -1
  52. package/.next/server/chunks/[root-of-the-server]__497e7a9d._.js +2 -2
  53. package/.next/server/chunks/[root-of-the-server]__497e7a9d._.js.map +1 -1
  54. package/.next/server/chunks/ssr/[root-of-the-server]__3b880807._.js +1 -1
  55. package/.next/server/chunks/ssr/[root-of-the-server]__3b880807._.js.map +1 -1
  56. package/.next/server/pages/404.html +1 -1
  57. package/.next/server/pages/500.html +2 -2
  58. package/.next/server/server-reference-manifest.js +1 -1
  59. package/.next/server/server-reference-manifest.json +1 -1
  60. package/openclaw.plugin.json +1 -1
  61. package/package.json +1 -1
  62. /package/.next/static/{YrhQe6JKLjXQk2SvUpwVM → VKFMk3pnq7Ap2maFSb7KP}/_buildManifest.js +0 -0
  63. /package/.next/static/{YrhQe6JKLjXQk2SvUpwVM → VKFMk3pnq7Ap2maFSb7KP}/_clientMiddlewareManifest.json +0 -0
  64. /package/.next/static/{YrhQe6JKLjXQk2SvUpwVM → VKFMk3pnq7Ap2maFSb7KP}/_ssgManifest.js +0 -0
@@ -11,12 +11,12 @@ params: ${t}`),this.query=e,this.params=t,this.cause=i,Error.captureStackTrace(t
11
11
  hash text NOT NULL,
12
12
  created_at numeric
13
13
  )
14
- `;await t.run(r);let n=(await t.values(ee`SELECT id, hash, created_at FROM ${ee.identifier(s)} ORDER BY created_at DESC LIMIT 1`))[0]??void 0;await t.transaction(async t=>{for(let i of e)if(!n||Number(n[2])<i.folderMillis){for(let e of i.sql)await t.run(ee.raw(e));await t.run(ee`INSERT INTO ${ee.identifier(s)} ("hash", "created_at") VALUES(${i.hash}, ${i.folderMillis})`)}})}}class sc{static [l]="TypedQueryBuilder";getSelectedFields(){return this._.selectedFields}}class sh{static [l]="QueryPromise";[Symbol.toStringTag]="QueryPromise";catch(e){return this.then(void 0,e)}finally(e){return this.then(t=>(e?.(),t),t=>{throw e?.(),t})}then(e,t){return this.execute().then(e,t)}}class sd{constructor(e,t){this.name=e,this.value=t}static [l]="SQLiteCheckBuilder";brand;build(e){return new sf(e,this)}}class sf{constructor(e,t){this.table=e,this.name=t.name,this.value=t.value}static [l]="SQLiteCheck";name;value}class sm{constructor(e,t){this.name=e,this.unique=t}static [l]="SQLiteIndexBuilderOn";on(...e){return new sg(this.name,e,this.unique)}}class sg{static [l]="SQLiteIndexBuilder";config;constructor(e,t,i){this.config={name:e,columns:t,unique:i,where:void 0}}where(e){return this.config.where=e,this}build(e){return new sp(this.config,e)}}class sp{static [l]="SQLiteIndex";config;constructor(e,t){this.config={...e,table:t}}}class sy{static [l]="SQLitePrimaryKeyBuilder";columns;name;constructor(e,t){this.columns=e,this.name=t}build(e){return new sb(e,this.columns,this.name)}}class sb{constructor(e,t,i){this.table=e,this.columns=t,this.name=i}static [l]="SQLitePrimaryKey";columns;name;getName(){return this.name??`${this.table[sn.Symbol.Name]}_${this.columns.map(e=>e.name).join("_")}_pk`}}function sS(e){return u(e,sn)?[`${e[w.Symbol.BaseName]}`]:u(e,R)?e._.usedTables??[]:u(e,Y)?e.usedTables??[]:[]}class sw{static [l]="SQLiteSelectBuilder";fields;session;dialect;withList;distinct;constructor(e){this.fields=e.fields,this.session=e.session,this.dialect=e.dialect,this.withList=e.withList,this.distinct=e.distinct}from(e){let t,i=!!this.fields;return t=this.fields?this.fields:u(e,R)?Object.fromEntries(Object.keys(e._.selectedFields).map(t=>[t,e[t]])):u(e,sa)?e[k].selectedFields:u(e,Y)?{}:e[w.Symbol.Columns],new sT({table:e,fields:t,isPartialSelect:i,session:this.session,dialect:this.dialect,withList:this.withList,distinct:this.distinct})}}class sv extends sc{static [l]="SQLiteSelectQueryBuilder";_;config;joinsNotNullableMap;tableName;isPartialSelect;session;dialect;cacheConfig=void 0;usedTables=new Set;constructor({table:e,fields:t,isPartialSelect:i,session:s,dialect:r,withList:n,distinct:a}){for(const o of(super(),this.config={withList:n,table:e,fields:{...t},distinct:a,setOperators:[]},this.isPartialSelect=i,this.session=s,this.dialect=r,this._={selectedFields:t,config:this.config},this.tableName=ej(e),this.joinsNotNullableMap="string"==typeof this.tableName?{[this.tableName]:!0}:{},sS(e)))this.usedTables.add(o)}getUsedTables(){return[...this.usedTables]}createJoin(e){return(t,i)=>{let s=this.tableName,r=ej(t);for(let e of sS(t))this.usedTables.add(e);if("string"==typeof r&&this.config.joins?.some(e=>e.alias===r))throw Error(`Alias "${r}" is already used in this query`);if(!this.isPartialSelect&&(1===Object.keys(this.joinsNotNullableMap).length&&"string"==typeof s&&(this.config.fields={[s]:this.config.fields}),"string"==typeof r&&!u(t,Y))){let e=u(t,R)?t._.selectedFields:u(t,ea)?t[k].selectedFields:t[w.Symbol.Columns];this.config.fields[r]=e}if("function"==typeof i&&(i=i(new Proxy(this.config.fields,new ib({sqlAliasedBehavior:"sql",sqlBehavior:"sql"})))),this.config.joins||(this.config.joins=[]),this.config.joins.push({on:i,table:t,joinType:e,alias:r}),"string"==typeof r)switch(e){case"left":this.joinsNotNullableMap[r]=!1;break;case"right":this.joinsNotNullableMap=Object.fromEntries(Object.entries(this.joinsNotNullableMap).map(([e])=>[e,!1])),this.joinsNotNullableMap[r]=!0;break;case"cross":case"inner":this.joinsNotNullableMap[r]=!0;break;case"full":this.joinsNotNullableMap=Object.fromEntries(Object.entries(this.joinsNotNullableMap).map(([e])=>[e,!1])),this.joinsNotNullableMap[r]=!1}return this}}leftJoin=this.createJoin("left");rightJoin=this.createJoin("right");innerJoin=this.createJoin("inner");fullJoin=this.createJoin("full");crossJoin=this.createJoin("cross");createSetOperator(e,t){return i=>{let s="function"==typeof i?i(sx()):i;if(!eF(this.getSelectedFields(),s.getSelectedFields()))throw Error("Set operator error (union / intersect / except): selected fields are not the same or are in a different order");return this.config.setOperators.push({type:e,isAll:t,rightSelect:s}),this}}union=this.createSetOperator("union",!1);unionAll=this.createSetOperator("union",!0);intersect=this.createSetOperator("intersect",!1);except=this.createSetOperator("except",!1);addSetOperators(e){return this.config.setOperators.push(...e),this}where(e){return"function"==typeof e&&(e=e(new Proxy(this.config.fields,new ib({sqlAliasedBehavior:"sql",sqlBehavior:"sql"})))),this.config.where=e,this}having(e){return"function"==typeof e&&(e=e(new Proxy(this.config.fields,new ib({sqlAliasedBehavior:"sql",sqlBehavior:"sql"})))),this.config.having=e,this}groupBy(...e){if("function"==typeof e[0]){let t=e[0](new Proxy(this.config.fields,new ib({sqlAliasedBehavior:"alias",sqlBehavior:"sql"})));this.config.groupBy=Array.isArray(t)?t:[t]}else this.config.groupBy=e;return this}orderBy(...e){if("function"==typeof e[0]){let t=e[0](new Proxy(this.config.fields,new ib({sqlAliasedBehavior:"alias",sqlBehavior:"sql"}))),i=Array.isArray(t)?t:[t];this.config.setOperators.length>0?this.config.setOperators.at(-1).orderBy=i:this.config.orderBy=i}else this.config.setOperators.length>0?this.config.setOperators.at(-1).orderBy=e:this.config.orderBy=e;return this}limit(e){return this.config.setOperators.length>0?this.config.setOperators.at(-1).limit=e:this.config.limit=e,this}offset(e){return this.config.setOperators.length>0?this.config.setOperators.at(-1).offset=e:this.config.offset=e,this}getSQL(){return this.dialect.buildSelectQuery(this.config)}toSQL(){let{typings:e,...t}=this.dialect.sqlToQuery(this.getSQL());return t}as(e){let t=[];if(t.push(...sS(this.config.table)),this.config.joins)for(let e of this.config.joins)t.push(...sS(e.table));return new Proxy(new R(this.getSQL(),this.config.fields,e,!1,[...new Set(t)]),new ib({alias:e,sqlAliasedBehavior:"alias",sqlBehavior:"error"}))}getSelectedFields(){return new Proxy(this.config.fields,new ib({alias:this.tableName,sqlAliasedBehavior:"alias",sqlBehavior:"error"}))}$dynamic(){return this}}class sT extends sv{static [l]="SQLiteSelect";_prepare(e=!0){if(!this.session)throw Error("Cannot execute a query on a query builder. Please use a database instance instead.");let t=eO(this.config.fields),i=this.session[e?"prepareOneTimeQuery":"prepareQuery"](this.dialect.sqlToQuery(this.getSQL()),t,"all",!0,void 0,{type:"select",tables:[...this.usedTables]},this.cacheConfig);return i.joinsNotNullableMap=this.joinsNotNullableMap,i}$withCache(e){return this.cacheConfig=void 0===e?{config:{},enable:!0,autoInvalidate:!0}:!1===e?{enable:!1}:{enable:!0,autoInvalidate:!0,...e},this}prepare(){return this._prepare(!1)}run=e=>this._prepare().run(e);all=e=>this._prepare().all(e);get=e=>this._prepare().get(e);values=e=>this._prepare().values(e);async execute(){return this.all()}}for(let e of[sh])for(let t of Object.getOwnPropertyNames(e.prototype))"constructor"!==t&&Object.defineProperty(sT.prototype,t,Object.getOwnPropertyDescriptor(e.prototype,t)||Object.create(null));function s$(e,t){return(i,s,...r)=>{let n=[s,...r].map(i=>({type:e,isAll:t,rightSelect:i}));for(let e of n)if(!eF(i.getSelectedFields(),e.rightSelect.getSelectedFields()))throw Error("Set operator error (union / intersect / except): selected fields are not the same or are in a different order");return i.addSetOperators(n)}}let sx=()=>({union:sQ,unionAll:sN,intersect:sP,except:sC}),sQ=s$("union",!1),sN=s$("union",!0),sP=s$("intersect",!1),sC=s$("except",!1);class sB{static [l]="SQLiteQueryBuilder";dialect;dialectConfig;constructor(e){this.dialect=u(e,so)?e:void 0,this.dialectConfig=u(e,so)?void 0:e}$with=(e,t)=>{let i=this;return{as:s=>("function"==typeof s&&(s=s(i)),new Proxy(new M(s.getSQL(),t??("getSelectedFields"in s?s.getSelectedFields()??{}:{}),e,!0),new ib({alias:e,sqlAliasedBehavior:"alias",sqlBehavior:"error"})))}};with(...e){let t=this;return{select:function(i){return new sw({fields:i??void 0,session:void 0,dialect:t.getDialect(),withList:e})},selectDistinct:function(i){return new sw({fields:i??void 0,session:void 0,dialect:t.getDialect(),withList:e,distinct:!0})}}}select(e){return new sw({fields:e??void 0,session:void 0,dialect:this.getDialect()})}selectDistinct(e){return new sw({fields:e??void 0,session:void 0,dialect:this.getDialect(),distinct:!0})}getDialect(){return this.dialect||(this.dialect=new sl(this.dialectConfig)),this.dialect}}class sL extends sh{constructor(e,t,i,s){super(),this.table=e,this.session=t,this.dialect=i,this.config={table:e,withList:s}}static [l]="SQLiteDelete";config;where(e){return this.config.where=e,this}orderBy(...e){if("function"==typeof e[0]){let t=e[0](new Proxy(this.config.table[w.Symbol.Columns],new ib({sqlAliasedBehavior:"alias",sqlBehavior:"sql"}))),i=Array.isArray(t)?t:[t];this.config.orderBy=i}else this.config.orderBy=e;return this}limit(e){return this.config.limit=e,this}returning(e=this.table[sn.Symbol.Columns]){return this.config.returning=eO(e),this}getSQL(){return this.dialect.buildDeleteQuery(this.config)}toSQL(){let{typings:e,...t}=this.dialect.sqlToQuery(this.getSQL());return t}_prepare(e=!0){return this.session[e?"prepareOneTimeQuery":"prepareQuery"](this.dialect.sqlToQuery(this.getSQL()),this.config.returning,this.config.returning?"all":"run",!0,void 0,{type:"delete",tables:sS(this.config.table)})}prepare(){return this._prepare(!1)}run=e=>this._prepare().run(e);all=e=>this._prepare().all(e);get=e=>this._prepare().get(e);values=e=>this._prepare().values(e);async execute(e){return this._prepare().execute(e)}$dynamic(){return this}}class sq{constructor(e,t,i,s){this.table=e,this.session=t,this.dialect=i,this.withList=s}static [l]="SQLiteInsertBuilder";values(e){if(0===(e=Array.isArray(e)?e:[e]).length)throw Error("values() must be called with at least one value");let t=e.map(e=>{let t={},i=this.table[w.Symbol.Columns];for(let s of Object.keys(e)){let r=e[s];t[s]=u(r,Y)?r:new Z(r,i[s])}return t});return new sD(this.table,t,this.session,this.dialect,this.withList)}select(e){let t="function"==typeof e?e(new sB):e;if(!u(t,Y)&&!eF(this.table[f],t._.selectedFields))throw Error("Insert select error: selected fields are not the same or are in a different order compared to the table definition");return new sD(this.table,t,this.session,this.dialect,this.withList,!0)}}class sD extends sh{constructor(e,t,i,s,r,n){super(),this.session=i,this.dialect=s,this.config={table:e,values:t,withList:r,select:n}}static [l]="SQLiteInsert";config;returning(e=this.config.table[sn.Symbol.Columns]){return this.config.returning=eO(e),this}onConflictDoNothing(e={}){if(this.config.onConflict||(this.config.onConflict=[]),void 0===e.target)this.config.onConflict.push(ee` on conflict do nothing`);else{let t=Array.isArray(e.target)?ee`${e.target}`:ee`${[e.target]}`,i=e.where?ee` where ${e.where}`:ee``;this.config.onConflict.push(ee` on conflict ${t} do nothing${i}`)}return this}onConflictDoUpdate(e){if(e.where&&(e.targetWhere||e.setWhere))throw Error('You cannot use both "where" and "targetWhere"/"setWhere" at the same time - "where" is deprecated, use "targetWhere" or "setWhere" instead.');this.config.onConflict||(this.config.onConflict=[]);let t=e.where?ee` where ${e.where}`:void 0,i=e.targetWhere?ee` where ${e.targetWhere}`:void 0,s=e.setWhere?ee` where ${e.setWhere}`:void 0,r=Array.isArray(e.target)?ee`${e.target}`:ee`${[e.target]}`,n=this.dialect.buildUpdateSet(this.config.table,eA(this.config.table,e.set));return this.config.onConflict.push(ee` on conflict ${r}${i} do update set ${n}${t}${s}`),this}getSQL(){return this.dialect.buildInsertQuery(this.config)}toSQL(){let{typings:e,...t}=this.dialect.sqlToQuery(this.getSQL());return t}_prepare(e=!0){return this.session[e?"prepareOneTimeQuery":"prepareQuery"](this.dialect.sqlToQuery(this.getSQL()),this.config.returning,this.config.returning?"all":"run",!0,void 0,{type:"insert",tables:sS(this.config.table)})}prepare(){return this._prepare(!1)}run=e=>this._prepare().run(e);all=e=>this._prepare().all(e);get=e=>this._prepare().get(e);values=e=>this._prepare().values(e);async execute(){return this.config.returning?this.all():this.run()}$dynamic(){return this}}class sO{constructor(e,t,i,s){this.table=e,this.session=t,this.dialect=i,this.withList=s}static [l]="SQLiteUpdateBuilder";set(e){return new sF(this.table,eA(this.table,e),this.session,this.dialect,this.withList)}}class sF extends sh{constructor(e,t,i,s,r){super(),this.session=i,this.dialect=s,this.config={set:t,table:e,withList:r,joins:[]}}static [l]="SQLiteUpdate";config;from(e){return this.config.from=e,this}createJoin(e){return(t,i)=>{let s=ej(t);if("string"==typeof s&&this.config.joins.some(e=>e.alias===s))throw Error(`Alias "${s}" is already used in this query`);if("function"==typeof i){let e=this.config.from?u(t,sn)?t[w.Symbol.Columns]:u(t,R)?t._.selectedFields:u(t,sa)?t[k].selectedFields:void 0:void 0;i=i(new Proxy(this.config.table[w.Symbol.Columns],new ib({sqlAliasedBehavior:"sql",sqlBehavior:"sql"})),e&&new Proxy(e,new ib({sqlAliasedBehavior:"sql",sqlBehavior:"sql"})))}return this.config.joins.push({on:i,table:t,joinType:e,alias:s}),this}}leftJoin=this.createJoin("left");rightJoin=this.createJoin("right");innerJoin=this.createJoin("inner");fullJoin=this.createJoin("full");where(e){return this.config.where=e,this}orderBy(...e){if("function"==typeof e[0]){let t=e[0](new Proxy(this.config.table[w.Symbol.Columns],new ib({sqlAliasedBehavior:"alias",sqlBehavior:"sql"}))),i=Array.isArray(t)?t:[t];this.config.orderBy=i}else this.config.orderBy=e;return this}limit(e){return this.config.limit=e,this}returning(e=this.config.table[sn.Symbol.Columns]){return this.config.returning=eO(e),this}getSQL(){return this.dialect.buildUpdateQuery(this.config)}toSQL(){let{typings:e,...t}=this.dialect.sqlToQuery(this.getSQL());return t}_prepare(e=!0){return this.session[e?"prepareOneTimeQuery":"prepareQuery"](this.dialect.sqlToQuery(this.getSQL()),this.config.returning,this.config.returning?"all":"run",!0,void 0,{type:"insert",tables:sS(this.config.table)})}prepare(){return this._prepare(!1)}run=e=>this._prepare().run(e);all=e=>this._prepare().all(e);get=e=>this._prepare().get(e);values=e=>this._prepare().values(e);async execute(){return this.config.returning?this.all():this.run()}$dynamic(){return this}}class sA extends Y{constructor(e){super(sA.buildEmbeddedCount(e.source,e.filters).queryChunks),this.params=e,this.session=e.session,this.sql=sA.buildCount(e.source,e.filters)}sql;static [l]="SQLiteCountBuilderAsync";[Symbol.toStringTag]="SQLiteCountBuilderAsync";session;static buildEmbeddedCount(e,t){return ee`(select count(*) from ${e}${ee.raw(" where ").if(t)}${t})`}static buildCount(e,t){return ee`select count(*) from ${e}${ee.raw(" where ").if(t)}${t}`}then(e,t){return Promise.resolve(this.session.count(this.sql)).then(e,t)}catch(e){return this.then(void 0,e)}finally(e){return this.then(t=>(e?.(),t),t=>{throw e?.(),t})}}class sj{constructor(e,t,i,s,r,n,a,o){this.mode=e,this.fullSchema=t,this.schema=i,this.tableNamesMap=s,this.table=r,this.tableConfig=n,this.dialect=a,this.session=o}static [l]="SQLiteAsyncRelationalQueryBuilder";findMany(e){return"sync"===this.mode?new s_(this.fullSchema,this.schema,this.tableNamesMap,this.table,this.tableConfig,this.dialect,this.session,e||{},"many"):new sI(this.fullSchema,this.schema,this.tableNamesMap,this.table,this.tableConfig,this.dialect,this.session,e||{},"many")}findFirst(e){return"sync"===this.mode?new s_(this.fullSchema,this.schema,this.tableNamesMap,this.table,this.tableConfig,this.dialect,this.session,e?{...e,limit:1}:{limit:1},"first"):new sI(this.fullSchema,this.schema,this.tableNamesMap,this.table,this.tableConfig,this.dialect,this.session,e?{...e,limit:1}:{limit:1},"first")}}class sI extends sh{constructor(e,t,i,s,r,n,a,o,l){super(),this.fullSchema=e,this.schema=t,this.tableNamesMap=i,this.table=s,this.tableConfig=r,this.dialect=n,this.session=a,this.config=o,this.mode=l}static [l]="SQLiteAsyncRelationalQuery";mode;getSQL(){return this.dialect.buildRelationalQuery({fullSchema:this.fullSchema,schema:this.schema,tableNamesMap:this.tableNamesMap,table:this.table,tableConfig:this.tableConfig,queryConfig:this.config,tableAlias:this.tableConfig.tsName}).sql}_prepare(e=!1){let{query:t,builtQuery:i}=this._toSQL();return this.session[e?"prepareOneTimeQuery":"prepareQuery"](i,void 0,"first"===this.mode?"get":"all",!0,(e,i)=>{let s=e.map(e=>(function e(t,i,s,r,n=e=>e){let a={};for(let[o,l]of r.entries())if(l.isJson){let r=i.relations[l.tsKey],c=s[o],h="string"==typeof c?JSON.parse(c):c;a[l.tsKey]=u(r,io)?h&&e(t,t[l.relationTableTsKey],h,l.selection,n):h.map(i=>e(t,t[l.relationTableTsKey],i,l.selection,n))}else{let e,t=n(s[o]),i=l.field;e=u(i,c)?i:u(i,Y)?i.decoder:i.sql.decoder,a[l.tsKey]=null===t?null:e.mapFromDriverValue(t)}return a})(this.schema,this.tableConfig,e,t.selection,i));return"first"===this.mode?s[0]:s})}prepare(){return this._prepare(!1)}_toSQL(){let e=this.dialect.buildRelationalQuery({fullSchema:this.fullSchema,schema:this.schema,tableNamesMap:this.tableNamesMap,table:this.table,tableConfig:this.tableConfig,queryConfig:this.config,tableAlias:this.tableConfig.tsName}),t=this.dialect.sqlToQuery(e.sql);return{query:e,builtQuery:t}}toSQL(){return this._toSQL().builtQuery}executeRaw(){return"first"===this.mode?this._prepare(!1).get():this._prepare(!1).all()}async execute(){return this.executeRaw()}}class s_ extends sI{static [l]="SQLiteSyncRelationalQuery";sync(){return this.executeRaw()}}class sV extends sh{constructor(e,t,i,s,r){super(),this.execute=e,this.getSQL=t,this.dialect=s,this.mapBatchResult=r,this.config={action:i}}static [l]="SQLiteRaw";config;getQuery(){return{...this.dialect.sqlToQuery(this.getSQL()),method:this.config.action}}mapResult(e,t){return t?this.mapBatchResult(e):e}_prepare(){return this}isResponseInArrayMode(){return!1}}class sE{constructor(e,t,i,s){this.resultKind=e,this.dialect=t,this.session=i,this._=s?{schema:s.schema,fullSchema:s.fullSchema,tableNamesMap:s.tableNamesMap}:{schema:void 0,fullSchema:{},tableNamesMap:{}},this.query={};const r=this.query;if(this._.schema)for(const[n,a]of Object.entries(this._.schema))r[n]=new sj(e,s.fullSchema,this._.schema,this._.tableNamesMap,s.fullSchema[n],a,t,i);this.$cache={invalidate:async e=>{}}}static [l]="BaseSQLiteDatabase";query;$with=(e,t)=>{let i=this;return{as:s=>("function"==typeof s&&(s=s(new sB(i.dialect))),new Proxy(new M(s.getSQL(),t??("getSelectedFields"in s?s.getSelectedFields()??{}:{}),e,!0),new ib({alias:e,sqlAliasedBehavior:"alias",sqlBehavior:"error"})))}};$count(e,t){return new sA({source:e,filters:t,session:this.session})}with(...e){let t=this;return{select:function(i){return new sw({fields:i??void 0,session:t.session,dialect:t.dialect,withList:e})},selectDistinct:function(i){return new sw({fields:i??void 0,session:t.session,dialect:t.dialect,withList:e,distinct:!0})},update:function(i){return new sO(i,t.session,t.dialect,e)},insert:function(i){return new sq(i,t.session,t.dialect,e)},delete:function(i){return new sL(i,t.session,t.dialect,e)}}}select(e){return new sw({fields:e??void 0,session:this.session,dialect:this.dialect})}selectDistinct(e){return new sw({fields:e??void 0,session:this.session,dialect:this.dialect,distinct:!0})}update(e){return new sO(e,this.session,this.dialect)}$cache;insert(e){return new sq(e,this.session,this.dialect)}delete(e){return new sL(e,this.session,this.dialect)}run(e){let t="string"==typeof e?ee.raw(e):e.getSQL();return"async"===this.resultKind?new sV(async()=>this.session.run(t),()=>t,"run",this.dialect,this.session.extractRawRunValueFromBatchResult.bind(this.session)):this.session.run(t)}all(e){let t="string"==typeof e?ee.raw(e):e.getSQL();return"async"===this.resultKind?new sV(async()=>this.session.all(t),()=>t,"all",this.dialect,this.session.extractRawAllValueFromBatchResult.bind(this.session)):this.session.all(t)}get(e){let t="string"==typeof e?ee.raw(e):e.getSQL();return"async"===this.resultKind?new sV(async()=>this.session.get(t),()=>t,"get",this.dialect,this.session.extractRawGetValueFromBatchResult.bind(this.session)):this.session.get(t)}values(e){let t="string"==typeof e?ee.raw(e):e.getSQL();return"async"===this.resultKind?new sV(async()=>this.session.values(t),()=>t,"values",this.dialect,this.session.extractRawValuesValueFromBatchResult.bind(this.session)):this.session.values(t)}transaction(e,t){return this.session.transaction(e,t)}}class sz{static [l]="Cache"}class sR extends sz{strategy(){return"all"}static [l]="NoopCache";async get(e){}async put(e,t,i,s){}async onMutate(e){}}async function sM(e,t){let i=`${e}-${JSON.stringify(t)}`,s=new TextEncoder().encode(i);return[...new Uint8Array(await crypto.subtle.digest("SHA-256",s))].map(e=>e.toString(16).padStart(2,"0")).join("")}class sU extends sh{constructor(e){super(),this.resultCb=e}static [l]="ExecuteResultSync";async execute(){return this.resultCb()}sync(){return this.resultCb()}}class sk{constructor(e,t,i,s,r,n){this.mode=e,this.executeMethod=t,this.query=i,this.cache=s,this.queryMetadata=r,this.cacheConfig=n,s&&"all"===s.strategy()&&void 0===n&&(this.cacheConfig={enable:!0,autoInvalidate:!0}),this.cacheConfig?.enable||(this.cacheConfig=void 0)}static [l]="PreparedQuery";joinsNotNullableMap;async queryWithCache(e,t,i){if(void 0===this.cache||u(this.cache,sR)||void 0===this.queryMetadata||this.cacheConfig&&!this.cacheConfig.enable)try{return await i()}catch(i){throw new ix(e,t,i)}if(("insert"===this.queryMetadata.type||"update"===this.queryMetadata.type||"delete"===this.queryMetadata.type)&&this.queryMetadata.tables.length>0)try{let[e]=await Promise.all([i(),this.cache.onMutate({tables:this.queryMetadata.tables})]);return e}catch(i){throw new ix(e,t,i)}if(!this.cacheConfig)try{return await i()}catch(i){throw new ix(e,t,i)}if("select"===this.queryMetadata.type){let s=await this.cache.get(this.cacheConfig.tag??await sM(e,t),this.queryMetadata.tables,void 0!==this.cacheConfig.tag,this.cacheConfig.autoInvalidate);if(void 0===s){let s;try{s=await i()}catch(i){throw new ix(e,t,i)}return await this.cache.put(this.cacheConfig.tag??await sM(e,t),s,this.cacheConfig.autoInvalidate?this.queryMetadata.tables:[],void 0!==this.cacheConfig.tag,this.cacheConfig.config),s}return s}try{return await i()}catch(i){throw new ix(e,t,i)}}getQuery(){return this.query}mapRunResult(e,t){return e}mapAllResult(e,t){throw Error("Not implemented")}mapGetResult(e,t){throw Error("Not implemented")}execute(e){return"async"===this.mode?this[this.executeMethod](e):new sU(()=>this[this.executeMethod](e))}mapResult(e,t){switch(this.executeMethod){case"run":return this.mapRunResult(e,t);case"all":return this.mapAllResult(e,t);case"get":return this.mapGetResult(e,t)}}}class sK{constructor(e){this.dialect=e}static [l]="SQLiteSession";prepareOneTimeQuery(e,t,i,s,r,n,a){return this.prepareQuery(e,t,i,s,r,n,a)}run(e){let t=this.dialect.sqlToQuery(e);try{return this.prepareOneTimeQuery(t,void 0,"run",!1).run()}catch(e){throw new i$({cause:e,message:`Failed to run the query '${t.sql}'`})}}extractRawRunValueFromBatchResult(e){return e}all(e){return this.prepareOneTimeQuery(this.dialect.sqlToQuery(e),void 0,"run",!1).all()}extractRawAllValueFromBatchResult(e){throw Error("Not implemented")}get(e){return this.prepareOneTimeQuery(this.dialect.sqlToQuery(e),void 0,"run",!1).get()}extractRawGetValueFromBatchResult(e){throw Error("Not implemented")}values(e){return this.prepareOneTimeQuery(this.dialect.sqlToQuery(e),void 0,"run",!1).values()}async count(e){return(await this.values(e))[0][0]}extractRawValuesValueFromBatchResult(e){throw Error("Not implemented")}}class sJ extends sE{constructor(e,t,i,s,r=0){super(e,t,i,s),this.schema=s,this.nestedIndex=r}static [l]="SQLiteTransaction";rollback(){throw new iQ}}class sW extends sK{constructor(e,t,i,s={}){super(t),this.client=e,this.schema=i,this.logger=s.logger??new eq,this.cache=s.cache??new sR}static [l]="BetterSQLiteSession";logger;cache;prepareQuery(e,t,i,s,r,n,a){return new sG(this.client.prepare(e.sql),e,this.logger,this.cache,n,a,t,i,s,r)}transaction(e,t={}){let i=new sY("sync",this.dialect,this,this.schema);return this.client.transaction(e)[t.behavior??"deferred"](i)}}class sY extends sJ{static [l]="BetterSQLiteTransaction";transaction(e){let t=`sp${this.nestedIndex}`,i=new sY("sync",this.dialect,this.session,this.schema,this.nestedIndex+1);this.session.run(ee.raw(`savepoint ${t}`));try{let s=e(i);return this.session.run(ee.raw(`release savepoint ${t}`)),s}catch(e){throw this.session.run(ee.raw(`rollback to savepoint ${t}`)),e}}}class sG extends sk{constructor(e,t,i,s,r,n,a,o,l,u){super("sync",o,t,s,r,n),this.stmt=e,this.logger=i,this.fields=a,this._isResponseInArrayMode=l,this.customResultMapper=u}static [l]="BetterSQLitePreparedQuery";run(e){let t=er(this.query.params,e??{});return this.logger.logQuery(this.query.sql,t),this.stmt.run(...t)}all(e){let{fields:t,joinsNotNullableMap:i,query:s,logger:r,stmt:n,customResultMapper:a}=this;if(!t&&!a){let t=er(s.params,e??{});return r.logQuery(s.sql,t),n.all(...t)}let o=this.values(e);return a?a(o):o.map(e=>eD(t,e,i))}get(e){let t=er(this.query.params,e??{});this.logger.logQuery(this.query.sql,t);let{fields:i,stmt:s,joinsNotNullableMap:r,customResultMapper:n}=this;if(!i&&!n)return s.get(...t);let a=s.raw().get(...t);if(a)return n?n([a]):eD(i,a,r)}values(e){let t=er(this.query.params,e??{});return this.logger.logQuery(this.query.sql,t),this.stmt.raw().all(...t)}isResponseInArrayMode(){return this._isResponseInArrayMode}}class sH extends sE{static [l]="BetterSQLite3Database"}function sX(e,t={}){let i,s,r=new sl({casing:t.casing});if(!0===t.logger?i=new eL:!1!==t.logger&&(i=t.logger),t.schema){let e=function(e,t){1===Object.keys(e).length&&"default"in e&&!u(e.default,w)&&(e=e.default);let i={},s={},r={};for(let[n,a]of Object.entries(e))if(u(a,w)){let e=v(a),t=s[e];for(let s of(i[e]=n,r[n]={tsName:n,dbName:a[w.Symbol.Name],schema:a[w.Symbol.Schema],columns:a[w.Symbol.Columns],relations:t?.relations??{},primaryKey:t?.primaryKey??[]},Object.values(a[w.Symbol.Columns])))s.primary&&r[n].primaryKey.push(s);let o=a[w.Symbol.ExtraConfigBuilder]?.(a[w.Symbol.ExtraConfigColumns]);if(o)for(let e of Object.values(o))u(e,ie)&&r[n].primaryKey.push(...e.columns)}else if(u(a,ia)){let e,n=v(a.table),o=i[n];for(let[i,l]of Object.entries(a.config(t(a.table))))if(o){let t=r[o];t.relations[i]=l,e&&t.primaryKey.push(...e)}else n in s||(s[n]={relations:{},primaryKey:e}),s[n].relations[i]=l}return{tables:r,tableNamesMap:i}}(t.schema,iu);s={fullSchema:t.schema,schema:e.tables,tableNamesMap:e.tableNamesMap}}let n=new sW(e,r,s,{logger:i}),a=new sH("sync",r,n,s);return a.$client=e,a}function sZ(...e){if(void 0===e[0]||"string"==typeof e[0])return sX(void 0===e[0]?new o.default:new o.default(e[0]),e[1]);if(function(e){if("object"!=typeof e||null===e||"Object"!==e.constructor.name)return!1;if("logger"in e){let t=typeof e.logger;return"boolean"===t||"object"===t&&"function"==typeof e.logger.logQuery||"undefined"===t}if("schema"in e){let t=typeof e.schema;return"object"===t||"undefined"===t}if("casing"in e){let t=typeof e.casing;return"string"===t||"undefined"===t}if("mode"in e)return"default"===e.mode&&"planetscale"===e.mode&&void 0===e.mode;if("connection"in e){let t=typeof e.connection;return"string"===t||"object"===t||"undefined"===t}if("client"in e){let t=typeof e.client;return"object"===t||"function"===t||"undefined"===t}return 0===Object.keys(e).length}(e[0])){let{connection:t,client:i,...s}=e[0];if(i)return sX(i,s);if("object"==typeof t){let{source:e,...i}=t;return sX(new o.default(e,i),s)}return sX(new o.default(t),s)}return sX(e[0],e[1])}(sZ||(sZ={})).mock=function(e){return sX({},e)};let s0=function(e,t,i,s,r=e){let n=new sn(e,void 0,r),a=Object.fromEntries(Object.entries("function"==typeof t?t({blob:iE,customType:iM,integer:iX,numeric:i5,real:i7,text:ss}):t).map(([e,t])=>{t.setName(e);let i=t.build(n);return n[sr].push(...t.buildForeignKeys(i,n)),[e,i]})),o=Object.assign(n,a);return o[w.Symbol.Columns]=a,o[w.Symbol.ExtraConfigColumns]=a,i&&(o[sn.Symbol.ExtraConfigBuilder]=i),o}("config",{key:ss("key").primaryKey(),value:ss("value"),updatedAt:ss("updated_at").default("CURRENT_TIMESTAMP")},void 0),s1=null;function s2(e,t){let i;if((0,r.existsSync)(e)){try{i=(0,r.readdirSync)(e)}catch{return}for(let s of i){let i=(0,n.join)(e,s);if(s.startsWith("@"))try{for(let e of(0,r.readdirSync)(i)){let s=(0,n.join)(i,e),r=s6(s);r&&!t.has(r.id)&&t.set(r.id,r)}}catch{}else{let e=s6(i);e&&!t.has(e.id)&&t.set(e.id,e)}}}}function s4(){if(s1)return s1;let e=new Map,t=(0,n.join)((0,a.homedir)(),".openclaw","kitchen","plugins");return s2((0,n.join)(t,"node_modules"),e),s2((0,n.resolve)("node_modules"),e),s1=e,e}function s6(e){try{let t=(0,n.join)(e,"package.json");if(!(0,r.existsSync)(t))return null;let i=JSON.parse((0,r.readFileSync)(t,"utf8")).kitchenPlugin;if(!i||"object"!=typeof i)return null;if(!i.id||!i.name||!Array.isArray(i.teamTypes))return console.warn(`Invalid Kitchen plugin manifest in ${e}`),null;let s=Array.isArray(i.tabs)?i.tabs:[];for(let t of s)if(t.bundle&&!(0,r.existsSync)((0,n.join)(e,t.bundle)))return console.warn(`Plugin ${i.id}: bundle not found at ${t.bundle}`),null;return{id:String(i.id),name:String(i.name),teamTypes:i.teamTypes,tabs:s.map(t=>({id:String(t.id||""),label:String(t.label||""),icon:String(t.icon||"folder"),bundle:(0,n.resolve)(e,String(t.bundle||""))})),apiRoutes:i.apiRoutes?(0,n.resolve)(e,String(i.apiRoutes)):void 0,migrations:i.migrations?(0,n.resolve)(e,String(i.migrations)):void 0}}catch(t){return console.warn(`Failed to load plugin manifest from ${e}:`,t),null}}function s5(t,i,s){let r=function(t){let i=(0,n.resolve)(process.env.HOME||".",".openclaw","kitchen","plugins",t),s=(0,n.join)(i,`${t}.db`);try{try{e.r(22734).mkdirSync(i,{recursive:!0})}catch{}}catch{}let r=new o.default(s),a=sZ(r,{schema:{config:s0}});return r.exec(`
14
+ `;await t.run(r);let n=(await t.values(ee`SELECT id, hash, created_at FROM ${ee.identifier(s)} ORDER BY created_at DESC LIMIT 1`))[0]??void 0;await t.transaction(async t=>{for(let i of e)if(!n||Number(n[2])<i.folderMillis){for(let e of i.sql)await t.run(ee.raw(e));await t.run(ee`INSERT INTO ${ee.identifier(s)} ("hash", "created_at") VALUES(${i.hash}, ${i.folderMillis})`)}})}}class sc{static [l]="TypedQueryBuilder";getSelectedFields(){return this._.selectedFields}}class sh{static [l]="QueryPromise";[Symbol.toStringTag]="QueryPromise";catch(e){return this.then(void 0,e)}finally(e){return this.then(t=>(e?.(),t),t=>{throw e?.(),t})}then(e,t){return this.execute().then(e,t)}}class sd{constructor(e,t){this.name=e,this.value=t}static [l]="SQLiteCheckBuilder";brand;build(e){return new sf(e,this)}}class sf{constructor(e,t){this.table=e,this.name=t.name,this.value=t.value}static [l]="SQLiteCheck";name;value}class sm{constructor(e,t){this.name=e,this.unique=t}static [l]="SQLiteIndexBuilderOn";on(...e){return new sg(this.name,e,this.unique)}}class sg{static [l]="SQLiteIndexBuilder";config;constructor(e,t,i){this.config={name:e,columns:t,unique:i,where:void 0}}where(e){return this.config.where=e,this}build(e){return new sp(this.config,e)}}class sp{static [l]="SQLiteIndex";config;constructor(e,t){this.config={...e,table:t}}}class sy{static [l]="SQLitePrimaryKeyBuilder";columns;name;constructor(e,t){this.columns=e,this.name=t}build(e){return new sb(e,this.columns,this.name)}}class sb{constructor(e,t,i){this.table=e,this.columns=t,this.name=i}static [l]="SQLitePrimaryKey";columns;name;getName(){return this.name??`${this.table[sn.Symbol.Name]}_${this.columns.map(e=>e.name).join("_")}_pk`}}function sS(e){return u(e,sn)?[`${e[w.Symbol.BaseName]}`]:u(e,R)?e._.usedTables??[]:u(e,Y)?e.usedTables??[]:[]}class sw{static [l]="SQLiteSelectBuilder";fields;session;dialect;withList;distinct;constructor(e){this.fields=e.fields,this.session=e.session,this.dialect=e.dialect,this.withList=e.withList,this.distinct=e.distinct}from(e){let t,i=!!this.fields;return t=this.fields?this.fields:u(e,R)?Object.fromEntries(Object.keys(e._.selectedFields).map(t=>[t,e[t]])):u(e,sa)?e[k].selectedFields:u(e,Y)?{}:e[w.Symbol.Columns],new sT({table:e,fields:t,isPartialSelect:i,session:this.session,dialect:this.dialect,withList:this.withList,distinct:this.distinct})}}class sv extends sc{static [l]="SQLiteSelectQueryBuilder";_;config;joinsNotNullableMap;tableName;isPartialSelect;session;dialect;cacheConfig=void 0;usedTables=new Set;constructor({table:e,fields:t,isPartialSelect:i,session:s,dialect:r,withList:n,distinct:a}){for(const o of(super(),this.config={withList:n,table:e,fields:{...t},distinct:a,setOperators:[]},this.isPartialSelect=i,this.session=s,this.dialect=r,this._={selectedFields:t,config:this.config},this.tableName=ej(e),this.joinsNotNullableMap="string"==typeof this.tableName?{[this.tableName]:!0}:{},sS(e)))this.usedTables.add(o)}getUsedTables(){return[...this.usedTables]}createJoin(e){return(t,i)=>{let s=this.tableName,r=ej(t);for(let e of sS(t))this.usedTables.add(e);if("string"==typeof r&&this.config.joins?.some(e=>e.alias===r))throw Error(`Alias "${r}" is already used in this query`);if(!this.isPartialSelect&&(1===Object.keys(this.joinsNotNullableMap).length&&"string"==typeof s&&(this.config.fields={[s]:this.config.fields}),"string"==typeof r&&!u(t,Y))){let e=u(t,R)?t._.selectedFields:u(t,ea)?t[k].selectedFields:t[w.Symbol.Columns];this.config.fields[r]=e}if("function"==typeof i&&(i=i(new Proxy(this.config.fields,new ib({sqlAliasedBehavior:"sql",sqlBehavior:"sql"})))),this.config.joins||(this.config.joins=[]),this.config.joins.push({on:i,table:t,joinType:e,alias:r}),"string"==typeof r)switch(e){case"left":this.joinsNotNullableMap[r]=!1;break;case"right":this.joinsNotNullableMap=Object.fromEntries(Object.entries(this.joinsNotNullableMap).map(([e])=>[e,!1])),this.joinsNotNullableMap[r]=!0;break;case"cross":case"inner":this.joinsNotNullableMap[r]=!0;break;case"full":this.joinsNotNullableMap=Object.fromEntries(Object.entries(this.joinsNotNullableMap).map(([e])=>[e,!1])),this.joinsNotNullableMap[r]=!1}return this}}leftJoin=this.createJoin("left");rightJoin=this.createJoin("right");innerJoin=this.createJoin("inner");fullJoin=this.createJoin("full");crossJoin=this.createJoin("cross");createSetOperator(e,t){return i=>{let s="function"==typeof i?i(sx()):i;if(!eF(this.getSelectedFields(),s.getSelectedFields()))throw Error("Set operator error (union / intersect / except): selected fields are not the same or are in a different order");return this.config.setOperators.push({type:e,isAll:t,rightSelect:s}),this}}union=this.createSetOperator("union",!1);unionAll=this.createSetOperator("union",!0);intersect=this.createSetOperator("intersect",!1);except=this.createSetOperator("except",!1);addSetOperators(e){return this.config.setOperators.push(...e),this}where(e){return"function"==typeof e&&(e=e(new Proxy(this.config.fields,new ib({sqlAliasedBehavior:"sql",sqlBehavior:"sql"})))),this.config.where=e,this}having(e){return"function"==typeof e&&(e=e(new Proxy(this.config.fields,new ib({sqlAliasedBehavior:"sql",sqlBehavior:"sql"})))),this.config.having=e,this}groupBy(...e){if("function"==typeof e[0]){let t=e[0](new Proxy(this.config.fields,new ib({sqlAliasedBehavior:"alias",sqlBehavior:"sql"})));this.config.groupBy=Array.isArray(t)?t:[t]}else this.config.groupBy=e;return this}orderBy(...e){if("function"==typeof e[0]){let t=e[0](new Proxy(this.config.fields,new ib({sqlAliasedBehavior:"alias",sqlBehavior:"sql"}))),i=Array.isArray(t)?t:[t];this.config.setOperators.length>0?this.config.setOperators.at(-1).orderBy=i:this.config.orderBy=i}else this.config.setOperators.length>0?this.config.setOperators.at(-1).orderBy=e:this.config.orderBy=e;return this}limit(e){return this.config.setOperators.length>0?this.config.setOperators.at(-1).limit=e:this.config.limit=e,this}offset(e){return this.config.setOperators.length>0?this.config.setOperators.at(-1).offset=e:this.config.offset=e,this}getSQL(){return this.dialect.buildSelectQuery(this.config)}toSQL(){let{typings:e,...t}=this.dialect.sqlToQuery(this.getSQL());return t}as(e){let t=[];if(t.push(...sS(this.config.table)),this.config.joins)for(let e of this.config.joins)t.push(...sS(e.table));return new Proxy(new R(this.getSQL(),this.config.fields,e,!1,[...new Set(t)]),new ib({alias:e,sqlAliasedBehavior:"alias",sqlBehavior:"error"}))}getSelectedFields(){return new Proxy(this.config.fields,new ib({alias:this.tableName,sqlAliasedBehavior:"alias",sqlBehavior:"error"}))}$dynamic(){return this}}class sT extends sv{static [l]="SQLiteSelect";_prepare(e=!0){if(!this.session)throw Error("Cannot execute a query on a query builder. Please use a database instance instead.");let t=eO(this.config.fields),i=this.session[e?"prepareOneTimeQuery":"prepareQuery"](this.dialect.sqlToQuery(this.getSQL()),t,"all",!0,void 0,{type:"select",tables:[...this.usedTables]},this.cacheConfig);return i.joinsNotNullableMap=this.joinsNotNullableMap,i}$withCache(e){return this.cacheConfig=void 0===e?{config:{},enable:!0,autoInvalidate:!0}:!1===e?{enable:!1}:{enable:!0,autoInvalidate:!0,...e},this}prepare(){return this._prepare(!1)}run=e=>this._prepare().run(e);all=e=>this._prepare().all(e);get=e=>this._prepare().get(e);values=e=>this._prepare().values(e);async execute(){return this.all()}}for(let e of[sh])for(let t of Object.getOwnPropertyNames(e.prototype))"constructor"!==t&&Object.defineProperty(sT.prototype,t,Object.getOwnPropertyDescriptor(e.prototype,t)||Object.create(null));function s$(e,t){return(i,s,...r)=>{let n=[s,...r].map(i=>({type:e,isAll:t,rightSelect:i}));for(let e of n)if(!eF(i.getSelectedFields(),e.rightSelect.getSelectedFields()))throw Error("Set operator error (union / intersect / except): selected fields are not the same or are in a different order");return i.addSetOperators(n)}}let sx=()=>({union:sQ,unionAll:sN,intersect:sP,except:sC}),sQ=s$("union",!1),sN=s$("union",!0),sP=s$("intersect",!1),sC=s$("except",!1);class sB{static [l]="SQLiteQueryBuilder";dialect;dialectConfig;constructor(e){this.dialect=u(e,so)?e:void 0,this.dialectConfig=u(e,so)?void 0:e}$with=(e,t)=>{let i=this;return{as:s=>("function"==typeof s&&(s=s(i)),new Proxy(new M(s.getSQL(),t??("getSelectedFields"in s?s.getSelectedFields()??{}:{}),e,!0),new ib({alias:e,sqlAliasedBehavior:"alias",sqlBehavior:"error"})))}};with(...e){let t=this;return{select:function(i){return new sw({fields:i??void 0,session:void 0,dialect:t.getDialect(),withList:e})},selectDistinct:function(i){return new sw({fields:i??void 0,session:void 0,dialect:t.getDialect(),withList:e,distinct:!0})}}}select(e){return new sw({fields:e??void 0,session:void 0,dialect:this.getDialect()})}selectDistinct(e){return new sw({fields:e??void 0,session:void 0,dialect:this.getDialect(),distinct:!0})}getDialect(){return this.dialect||(this.dialect=new sl(this.dialectConfig)),this.dialect}}class sL extends sh{constructor(e,t,i,s){super(),this.table=e,this.session=t,this.dialect=i,this.config={table:e,withList:s}}static [l]="SQLiteDelete";config;where(e){return this.config.where=e,this}orderBy(...e){if("function"==typeof e[0]){let t=e[0](new Proxy(this.config.table[w.Symbol.Columns],new ib({sqlAliasedBehavior:"alias",sqlBehavior:"sql"}))),i=Array.isArray(t)?t:[t];this.config.orderBy=i}else this.config.orderBy=e;return this}limit(e){return this.config.limit=e,this}returning(e=this.table[sn.Symbol.Columns]){return this.config.returning=eO(e),this}getSQL(){return this.dialect.buildDeleteQuery(this.config)}toSQL(){let{typings:e,...t}=this.dialect.sqlToQuery(this.getSQL());return t}_prepare(e=!0){return this.session[e?"prepareOneTimeQuery":"prepareQuery"](this.dialect.sqlToQuery(this.getSQL()),this.config.returning,this.config.returning?"all":"run",!0,void 0,{type:"delete",tables:sS(this.config.table)})}prepare(){return this._prepare(!1)}run=e=>this._prepare().run(e);all=e=>this._prepare().all(e);get=e=>this._prepare().get(e);values=e=>this._prepare().values(e);async execute(e){return this._prepare().execute(e)}$dynamic(){return this}}class sq{constructor(e,t,i,s){this.table=e,this.session=t,this.dialect=i,this.withList=s}static [l]="SQLiteInsertBuilder";values(e){if(0===(e=Array.isArray(e)?e:[e]).length)throw Error("values() must be called with at least one value");let t=e.map(e=>{let t={},i=this.table[w.Symbol.Columns];for(let s of Object.keys(e)){let r=e[s];t[s]=u(r,Y)?r:new Z(r,i[s])}return t});return new sD(this.table,t,this.session,this.dialect,this.withList)}select(e){let t="function"==typeof e?e(new sB):e;if(!u(t,Y)&&!eF(this.table[f],t._.selectedFields))throw Error("Insert select error: selected fields are not the same or are in a different order compared to the table definition");return new sD(this.table,t,this.session,this.dialect,this.withList,!0)}}class sD extends sh{constructor(e,t,i,s,r,n){super(),this.session=i,this.dialect=s,this.config={table:e,values:t,withList:r,select:n}}static [l]="SQLiteInsert";config;returning(e=this.config.table[sn.Symbol.Columns]){return this.config.returning=eO(e),this}onConflictDoNothing(e={}){if(this.config.onConflict||(this.config.onConflict=[]),void 0===e.target)this.config.onConflict.push(ee` on conflict do nothing`);else{let t=Array.isArray(e.target)?ee`${e.target}`:ee`${[e.target]}`,i=e.where?ee` where ${e.where}`:ee``;this.config.onConflict.push(ee` on conflict ${t} do nothing${i}`)}return this}onConflictDoUpdate(e){if(e.where&&(e.targetWhere||e.setWhere))throw Error('You cannot use both "where" and "targetWhere"/"setWhere" at the same time - "where" is deprecated, use "targetWhere" or "setWhere" instead.');this.config.onConflict||(this.config.onConflict=[]);let t=e.where?ee` where ${e.where}`:void 0,i=e.targetWhere?ee` where ${e.targetWhere}`:void 0,s=e.setWhere?ee` where ${e.setWhere}`:void 0,r=Array.isArray(e.target)?ee`${e.target}`:ee`${[e.target]}`,n=this.dialect.buildUpdateSet(this.config.table,eA(this.config.table,e.set));return this.config.onConflict.push(ee` on conflict ${r}${i} do update set ${n}${t}${s}`),this}getSQL(){return this.dialect.buildInsertQuery(this.config)}toSQL(){let{typings:e,...t}=this.dialect.sqlToQuery(this.getSQL());return t}_prepare(e=!0){return this.session[e?"prepareOneTimeQuery":"prepareQuery"](this.dialect.sqlToQuery(this.getSQL()),this.config.returning,this.config.returning?"all":"run",!0,void 0,{type:"insert",tables:sS(this.config.table)})}prepare(){return this._prepare(!1)}run=e=>this._prepare().run(e);all=e=>this._prepare().all(e);get=e=>this._prepare().get(e);values=e=>this._prepare().values(e);async execute(){return this.config.returning?this.all():this.run()}$dynamic(){return this}}class sO{constructor(e,t,i,s){this.table=e,this.session=t,this.dialect=i,this.withList=s}static [l]="SQLiteUpdateBuilder";set(e){return new sF(this.table,eA(this.table,e),this.session,this.dialect,this.withList)}}class sF extends sh{constructor(e,t,i,s,r){super(),this.session=i,this.dialect=s,this.config={set:t,table:e,withList:r,joins:[]}}static [l]="SQLiteUpdate";config;from(e){return this.config.from=e,this}createJoin(e){return(t,i)=>{let s=ej(t);if("string"==typeof s&&this.config.joins.some(e=>e.alias===s))throw Error(`Alias "${s}" is already used in this query`);if("function"==typeof i){let e=this.config.from?u(t,sn)?t[w.Symbol.Columns]:u(t,R)?t._.selectedFields:u(t,sa)?t[k].selectedFields:void 0:void 0;i=i(new Proxy(this.config.table[w.Symbol.Columns],new ib({sqlAliasedBehavior:"sql",sqlBehavior:"sql"})),e&&new Proxy(e,new ib({sqlAliasedBehavior:"sql",sqlBehavior:"sql"})))}return this.config.joins.push({on:i,table:t,joinType:e,alias:s}),this}}leftJoin=this.createJoin("left");rightJoin=this.createJoin("right");innerJoin=this.createJoin("inner");fullJoin=this.createJoin("full");where(e){return this.config.where=e,this}orderBy(...e){if("function"==typeof e[0]){let t=e[0](new Proxy(this.config.table[w.Symbol.Columns],new ib({sqlAliasedBehavior:"alias",sqlBehavior:"sql"}))),i=Array.isArray(t)?t:[t];this.config.orderBy=i}else this.config.orderBy=e;return this}limit(e){return this.config.limit=e,this}returning(e=this.config.table[sn.Symbol.Columns]){return this.config.returning=eO(e),this}getSQL(){return this.dialect.buildUpdateQuery(this.config)}toSQL(){let{typings:e,...t}=this.dialect.sqlToQuery(this.getSQL());return t}_prepare(e=!0){return this.session[e?"prepareOneTimeQuery":"prepareQuery"](this.dialect.sqlToQuery(this.getSQL()),this.config.returning,this.config.returning?"all":"run",!0,void 0,{type:"insert",tables:sS(this.config.table)})}prepare(){return this._prepare(!1)}run=e=>this._prepare().run(e);all=e=>this._prepare().all(e);get=e=>this._prepare().get(e);values=e=>this._prepare().values(e);async execute(){return this.config.returning?this.all():this.run()}$dynamic(){return this}}class sA extends Y{constructor(e){super(sA.buildEmbeddedCount(e.source,e.filters).queryChunks),this.params=e,this.session=e.session,this.sql=sA.buildCount(e.source,e.filters)}sql;static [l]="SQLiteCountBuilderAsync";[Symbol.toStringTag]="SQLiteCountBuilderAsync";session;static buildEmbeddedCount(e,t){return ee`(select count(*) from ${e}${ee.raw(" where ").if(t)}${t})`}static buildCount(e,t){return ee`select count(*) from ${e}${ee.raw(" where ").if(t)}${t}`}then(e,t){return Promise.resolve(this.session.count(this.sql)).then(e,t)}catch(e){return this.then(void 0,e)}finally(e){return this.then(t=>(e?.(),t),t=>{throw e?.(),t})}}class sj{constructor(e,t,i,s,r,n,a,o){this.mode=e,this.fullSchema=t,this.schema=i,this.tableNamesMap=s,this.table=r,this.tableConfig=n,this.dialect=a,this.session=o}static [l]="SQLiteAsyncRelationalQueryBuilder";findMany(e){return"sync"===this.mode?new s_(this.fullSchema,this.schema,this.tableNamesMap,this.table,this.tableConfig,this.dialect,this.session,e||{},"many"):new sI(this.fullSchema,this.schema,this.tableNamesMap,this.table,this.tableConfig,this.dialect,this.session,e||{},"many")}findFirst(e){return"sync"===this.mode?new s_(this.fullSchema,this.schema,this.tableNamesMap,this.table,this.tableConfig,this.dialect,this.session,e?{...e,limit:1}:{limit:1},"first"):new sI(this.fullSchema,this.schema,this.tableNamesMap,this.table,this.tableConfig,this.dialect,this.session,e?{...e,limit:1}:{limit:1},"first")}}class sI extends sh{constructor(e,t,i,s,r,n,a,o,l){super(),this.fullSchema=e,this.schema=t,this.tableNamesMap=i,this.table=s,this.tableConfig=r,this.dialect=n,this.session=a,this.config=o,this.mode=l}static [l]="SQLiteAsyncRelationalQuery";mode;getSQL(){return this.dialect.buildRelationalQuery({fullSchema:this.fullSchema,schema:this.schema,tableNamesMap:this.tableNamesMap,table:this.table,tableConfig:this.tableConfig,queryConfig:this.config,tableAlias:this.tableConfig.tsName}).sql}_prepare(e=!1){let{query:t,builtQuery:i}=this._toSQL();return this.session[e?"prepareOneTimeQuery":"prepareQuery"](i,void 0,"first"===this.mode?"get":"all",!0,(e,i)=>{let s=e.map(e=>(function e(t,i,s,r,n=e=>e){let a={};for(let[o,l]of r.entries())if(l.isJson){let r=i.relations[l.tsKey],c=s[o],h="string"==typeof c?JSON.parse(c):c;a[l.tsKey]=u(r,io)?h&&e(t,t[l.relationTableTsKey],h,l.selection,n):h.map(i=>e(t,t[l.relationTableTsKey],i,l.selection,n))}else{let e,t=n(s[o]),i=l.field;e=u(i,c)?i:u(i,Y)?i.decoder:i.sql.decoder,a[l.tsKey]=null===t?null:e.mapFromDriverValue(t)}return a})(this.schema,this.tableConfig,e,t.selection,i));return"first"===this.mode?s[0]:s})}prepare(){return this._prepare(!1)}_toSQL(){let e=this.dialect.buildRelationalQuery({fullSchema:this.fullSchema,schema:this.schema,tableNamesMap:this.tableNamesMap,table:this.table,tableConfig:this.tableConfig,queryConfig:this.config,tableAlias:this.tableConfig.tsName}),t=this.dialect.sqlToQuery(e.sql);return{query:e,builtQuery:t}}toSQL(){return this._toSQL().builtQuery}executeRaw(){return"first"===this.mode?this._prepare(!1).get():this._prepare(!1).all()}async execute(){return this.executeRaw()}}class s_ extends sI{static [l]="SQLiteSyncRelationalQuery";sync(){return this.executeRaw()}}class sV extends sh{constructor(e,t,i,s,r){super(),this.execute=e,this.getSQL=t,this.dialect=s,this.mapBatchResult=r,this.config={action:i}}static [l]="SQLiteRaw";config;getQuery(){return{...this.dialect.sqlToQuery(this.getSQL()),method:this.config.action}}mapResult(e,t){return t?this.mapBatchResult(e):e}_prepare(){return this}isResponseInArrayMode(){return!1}}class sE{constructor(e,t,i,s){this.resultKind=e,this.dialect=t,this.session=i,this._=s?{schema:s.schema,fullSchema:s.fullSchema,tableNamesMap:s.tableNamesMap}:{schema:void 0,fullSchema:{},tableNamesMap:{}},this.query={};const r=this.query;if(this._.schema)for(const[n,a]of Object.entries(this._.schema))r[n]=new sj(e,s.fullSchema,this._.schema,this._.tableNamesMap,s.fullSchema[n],a,t,i);this.$cache={invalidate:async e=>{}}}static [l]="BaseSQLiteDatabase";query;$with=(e,t)=>{let i=this;return{as:s=>("function"==typeof s&&(s=s(new sB(i.dialect))),new Proxy(new M(s.getSQL(),t??("getSelectedFields"in s?s.getSelectedFields()??{}:{}),e,!0),new ib({alias:e,sqlAliasedBehavior:"alias",sqlBehavior:"error"})))}};$count(e,t){return new sA({source:e,filters:t,session:this.session})}with(...e){let t=this;return{select:function(i){return new sw({fields:i??void 0,session:t.session,dialect:t.dialect,withList:e})},selectDistinct:function(i){return new sw({fields:i??void 0,session:t.session,dialect:t.dialect,withList:e,distinct:!0})},update:function(i){return new sO(i,t.session,t.dialect,e)},insert:function(i){return new sq(i,t.session,t.dialect,e)},delete:function(i){return new sL(i,t.session,t.dialect,e)}}}select(e){return new sw({fields:e??void 0,session:this.session,dialect:this.dialect})}selectDistinct(e){return new sw({fields:e??void 0,session:this.session,dialect:this.dialect,distinct:!0})}update(e){return new sO(e,this.session,this.dialect)}$cache;insert(e){return new sq(e,this.session,this.dialect)}delete(e){return new sL(e,this.session,this.dialect)}run(e){let t="string"==typeof e?ee.raw(e):e.getSQL();return"async"===this.resultKind?new sV(async()=>this.session.run(t),()=>t,"run",this.dialect,this.session.extractRawRunValueFromBatchResult.bind(this.session)):this.session.run(t)}all(e){let t="string"==typeof e?ee.raw(e):e.getSQL();return"async"===this.resultKind?new sV(async()=>this.session.all(t),()=>t,"all",this.dialect,this.session.extractRawAllValueFromBatchResult.bind(this.session)):this.session.all(t)}get(e){let t="string"==typeof e?ee.raw(e):e.getSQL();return"async"===this.resultKind?new sV(async()=>this.session.get(t),()=>t,"get",this.dialect,this.session.extractRawGetValueFromBatchResult.bind(this.session)):this.session.get(t)}values(e){let t="string"==typeof e?ee.raw(e):e.getSQL();return"async"===this.resultKind?new sV(async()=>this.session.values(t),()=>t,"values",this.dialect,this.session.extractRawValuesValueFromBatchResult.bind(this.session)):this.session.values(t)}transaction(e,t){return this.session.transaction(e,t)}}class sz{static [l]="Cache"}class sR extends sz{strategy(){return"all"}static [l]="NoopCache";async get(e){}async put(e,t,i,s){}async onMutate(e){}}async function sM(e,t){let i=`${e}-${JSON.stringify(t)}`,s=new TextEncoder().encode(i);return[...new Uint8Array(await crypto.subtle.digest("SHA-256",s))].map(e=>e.toString(16).padStart(2,"0")).join("")}class sU extends sh{constructor(e){super(),this.resultCb=e}static [l]="ExecuteResultSync";async execute(){return this.resultCb()}sync(){return this.resultCb()}}class sk{constructor(e,t,i,s,r,n){this.mode=e,this.executeMethod=t,this.query=i,this.cache=s,this.queryMetadata=r,this.cacheConfig=n,s&&"all"===s.strategy()&&void 0===n&&(this.cacheConfig={enable:!0,autoInvalidate:!0}),this.cacheConfig?.enable||(this.cacheConfig=void 0)}static [l]="PreparedQuery";joinsNotNullableMap;async queryWithCache(e,t,i){if(void 0===this.cache||u(this.cache,sR)||void 0===this.queryMetadata||this.cacheConfig&&!this.cacheConfig.enable)try{return await i()}catch(i){throw new ix(e,t,i)}if(("insert"===this.queryMetadata.type||"update"===this.queryMetadata.type||"delete"===this.queryMetadata.type)&&this.queryMetadata.tables.length>0)try{let[e]=await Promise.all([i(),this.cache.onMutate({tables:this.queryMetadata.tables})]);return e}catch(i){throw new ix(e,t,i)}if(!this.cacheConfig)try{return await i()}catch(i){throw new ix(e,t,i)}if("select"===this.queryMetadata.type){let s=await this.cache.get(this.cacheConfig.tag??await sM(e,t),this.queryMetadata.tables,void 0!==this.cacheConfig.tag,this.cacheConfig.autoInvalidate);if(void 0===s){let s;try{s=await i()}catch(i){throw new ix(e,t,i)}return await this.cache.put(this.cacheConfig.tag??await sM(e,t),s,this.cacheConfig.autoInvalidate?this.queryMetadata.tables:[],void 0!==this.cacheConfig.tag,this.cacheConfig.config),s}return s}try{return await i()}catch(i){throw new ix(e,t,i)}}getQuery(){return this.query}mapRunResult(e,t){return e}mapAllResult(e,t){throw Error("Not implemented")}mapGetResult(e,t){throw Error("Not implemented")}execute(e){return"async"===this.mode?this[this.executeMethod](e):new sU(()=>this[this.executeMethod](e))}mapResult(e,t){switch(this.executeMethod){case"run":return this.mapRunResult(e,t);case"all":return this.mapAllResult(e,t);case"get":return this.mapGetResult(e,t)}}}class sK{constructor(e){this.dialect=e}static [l]="SQLiteSession";prepareOneTimeQuery(e,t,i,s,r,n,a){return this.prepareQuery(e,t,i,s,r,n,a)}run(e){let t=this.dialect.sqlToQuery(e);try{return this.prepareOneTimeQuery(t,void 0,"run",!1).run()}catch(e){throw new i$({cause:e,message:`Failed to run the query '${t.sql}'`})}}extractRawRunValueFromBatchResult(e){return e}all(e){return this.prepareOneTimeQuery(this.dialect.sqlToQuery(e),void 0,"run",!1).all()}extractRawAllValueFromBatchResult(e){throw Error("Not implemented")}get(e){return this.prepareOneTimeQuery(this.dialect.sqlToQuery(e),void 0,"run",!1).get()}extractRawGetValueFromBatchResult(e){throw Error("Not implemented")}values(e){return this.prepareOneTimeQuery(this.dialect.sqlToQuery(e),void 0,"run",!1).values()}async count(e){return(await this.values(e))[0][0]}extractRawValuesValueFromBatchResult(e){throw Error("Not implemented")}}class sJ extends sE{constructor(e,t,i,s,r=0){super(e,t,i,s),this.schema=s,this.nestedIndex=r}static [l]="SQLiteTransaction";rollback(){throw new iQ}}class sW extends sK{constructor(e,t,i,s={}){super(t),this.client=e,this.schema=i,this.logger=s.logger??new eq,this.cache=s.cache??new sR}static [l]="BetterSQLiteSession";logger;cache;prepareQuery(e,t,i,s,r,n,a){return new sG(this.client.prepare(e.sql),e,this.logger,this.cache,n,a,t,i,s,r)}transaction(e,t={}){let i=new sY("sync",this.dialect,this,this.schema);return this.client.transaction(e)[t.behavior??"deferred"](i)}}class sY extends sJ{static [l]="BetterSQLiteTransaction";transaction(e){let t=`sp${this.nestedIndex}`,i=new sY("sync",this.dialect,this.session,this.schema,this.nestedIndex+1);this.session.run(ee.raw(`savepoint ${t}`));try{let s=e(i);return this.session.run(ee.raw(`release savepoint ${t}`)),s}catch(e){throw this.session.run(ee.raw(`rollback to savepoint ${t}`)),e}}}class sG extends sk{constructor(e,t,i,s,r,n,a,o,l,u){super("sync",o,t,s,r,n),this.stmt=e,this.logger=i,this.fields=a,this._isResponseInArrayMode=l,this.customResultMapper=u}static [l]="BetterSQLitePreparedQuery";run(e){let t=er(this.query.params,e??{});return this.logger.logQuery(this.query.sql,t),this.stmt.run(...t)}all(e){let{fields:t,joinsNotNullableMap:i,query:s,logger:r,stmt:n,customResultMapper:a}=this;if(!t&&!a){let t=er(s.params,e??{});return r.logQuery(s.sql,t),n.all(...t)}let o=this.values(e);return a?a(o):o.map(e=>eD(t,e,i))}get(e){let t=er(this.query.params,e??{});this.logger.logQuery(this.query.sql,t);let{fields:i,stmt:s,joinsNotNullableMap:r,customResultMapper:n}=this;if(!i&&!n)return s.get(...t);let a=s.raw().get(...t);if(a)return n?n([a]):eD(i,a,r)}values(e){let t=er(this.query.params,e??{});return this.logger.logQuery(this.query.sql,t),this.stmt.raw().all(...t)}isResponseInArrayMode(){return this._isResponseInArrayMode}}class sH extends sE{static [l]="BetterSQLite3Database"}function sX(e,t={}){let i,s,r=new sl({casing:t.casing});if(!0===t.logger?i=new eL:!1!==t.logger&&(i=t.logger),t.schema){let e=function(e,t){1===Object.keys(e).length&&"default"in e&&!u(e.default,w)&&(e=e.default);let i={},s={},r={};for(let[n,a]of Object.entries(e))if(u(a,w)){let e=v(a),t=s[e];for(let s of(i[e]=n,r[n]={tsName:n,dbName:a[w.Symbol.Name],schema:a[w.Symbol.Schema],columns:a[w.Symbol.Columns],relations:t?.relations??{},primaryKey:t?.primaryKey??[]},Object.values(a[w.Symbol.Columns])))s.primary&&r[n].primaryKey.push(s);let o=a[w.Symbol.ExtraConfigBuilder]?.(a[w.Symbol.ExtraConfigColumns]);if(o)for(let e of Object.values(o))u(e,ie)&&r[n].primaryKey.push(...e.columns)}else if(u(a,ia)){let e,n=v(a.table),o=i[n];for(let[i,l]of Object.entries(a.config(t(a.table))))if(o){let t=r[o];t.relations[i]=l,e&&t.primaryKey.push(...e)}else n in s||(s[n]={relations:{},primaryKey:e}),s[n].relations[i]=l}return{tables:r,tableNamesMap:i}}(t.schema,iu);s={fullSchema:t.schema,schema:e.tables,tableNamesMap:e.tableNamesMap}}let n=new sW(e,r,s,{logger:i}),a=new sH("sync",r,n,s);return a.$client=e,a}function sZ(...e){if(void 0===e[0]||"string"==typeof e[0])return sX(void 0===e[0]?new o.default:new o.default(e[0]),e[1]);if(function(e){if("object"!=typeof e||null===e||"Object"!==e.constructor.name)return!1;if("logger"in e){let t=typeof e.logger;return"boolean"===t||"object"===t&&"function"==typeof e.logger.logQuery||"undefined"===t}if("schema"in e){let t=typeof e.schema;return"object"===t||"undefined"===t}if("casing"in e){let t=typeof e.casing;return"string"===t||"undefined"===t}if("mode"in e)return"default"===e.mode&&"planetscale"===e.mode&&void 0===e.mode;if("connection"in e){let t=typeof e.connection;return"string"===t||"object"===t||"undefined"===t}if("client"in e){let t=typeof e.client;return"object"===t||"function"===t||"undefined"===t}return 0===Object.keys(e).length}(e[0])){let{connection:t,client:i,...s}=e[0];if(i)return sX(i,s);if("object"==typeof t){let{source:e,...i}=t;return sX(new o.default(e,i),s)}return sX(new o.default(t),s)}return sX(e[0],e[1])}(sZ||(sZ={})).mock=function(e){return sX({},e)};let s0=function(e,t,i,s,r=e){let n=new sn(e,void 0,r),a=Object.fromEntries(Object.entries("function"==typeof t?t({blob:iE,customType:iM,integer:iX,numeric:i5,real:i7,text:ss}):t).map(([e,t])=>{t.setName(e);let i=t.build(n);return n[sr].push(...t.buildForeignKeys(i,n)),[e,i]})),o=Object.assign(n,a);return o[w.Symbol.Columns]=a,o[w.Symbol.ExtraConfigColumns]=a,i&&(o[sn.Symbol.ExtraConfigBuilder]=i),o}("config",{key:ss("key").primaryKey(),value:ss("value"),updatedAt:ss("updated_at").default("CURRENT_TIMESTAMP")},void 0),s1=null;function s2(e,t){let i;if((0,r.existsSync)(e)){try{i=(0,r.readdirSync)(e)}catch{return}for(let s of i){let i=(0,n.join)(e,s);if(s.startsWith("@"))try{for(let e of(0,r.readdirSync)(i)){let s=(0,n.join)(i,e),r=s6(s);r&&!t.has(r.id)&&t.set(r.id,r)}}catch{}else{let e=s6(i);e&&!t.has(e.id)&&t.set(e.id,e)}}}}function s4(){if(s1)return s1;let e=new Map,t=(0,n.join)((0,a.homedir)(),".openclaw","kitchen","plugins");return s2((0,n.join)(t,"node_modules"),e),s2((0,n.resolve)("node_modules"),e),s1=e,e}function s6(e){try{let t=(0,n.join)(e,"package.json");if(!(0,r.existsSync)(t))return null;let i=JSON.parse((0,r.readFileSync)(t,"utf8")).kitchenPlugin;if(!i||"object"!=typeof i)return null;if(!i.id||!i.name||!Array.isArray(i.teamTypes))return console.warn(`Invalid Kitchen plugin manifest in ${e}`),null;let s=Array.isArray(i.tabs)?i.tabs:[];for(let t of s)if(t.bundle&&!(0,r.existsSync)((0,n.join)(e,t.bundle)))return console.warn(`Plugin ${i.id}: bundle not found at ${t.bundle}`),null;return{id:String(i.id),name:String(i.name),teamTypes:i.teamTypes,tabs:s.map(t=>({id:String(t.id||""),label:String(t.label||""),icon:String(t.icon||"folder"),bundle:(0,n.resolve)(e,String(t.bundle||""))})),apiRoutes:i.apiRoutes?(0,n.resolve)(e,String(i.apiRoutes)):void 0,migrations:i.migrations?(0,n.resolve)(e,String(i.migrations)):void 0}}catch(t){return console.warn(`Failed to load plugin manifest from ${e}:`,t),null}}function s5(t,i,s){let r=function(t){let i=(0,n.resolve)((0,a.homedir)(),".openclaw","kitchen","plugins",t),s=(0,n.join)(i,`${t}.db`);try{try{e.r(22734).mkdirSync(i,{recursive:!0})}catch{}}catch{}let r=new o.default(s),l=sZ(r,{schema:{config:s0}});return r.exec(`
15
15
  CREATE TABLE IF NOT EXISTS config (
16
16
  key TEXT PRIMARY KEY,
17
17
  value TEXT,
18
18
  updated_at TEXT DEFAULT CURRENT_TIMESTAMP
19
19
  )
20
- `),a}(t);return{db:r,teamDir:i,encrypt:t=>{let i=e.r(54799),r=i.pbkdf2Sync(s,"kitchen-plugin-salt",1e5,32,"sha256"),n=i.randomBytes(16),a=i.createCipher("aes-256-gcm",r);a.setAAD(n);let o=a.update(JSON.stringify(t),"utf8","base64");o+=a.final("base64");let l=a.getAuthTag();return Buffer.concat([n,l,Buffer.from(o,"base64")]).toString("base64")},decrypt:t=>{let i=e.r(54799),r=i.pbkdf2Sync(s,"kitchen-plugin-salt",1e5,32,"sha256"),n=Buffer.from(t,"base64"),a=n.subarray(0,16),o=n.subarray(16,32),l=n.subarray(32).toString("base64"),u=i.createDecipher("aes-256-gcm",r);u.setAAD(a),u.setAuthTag(o);let c=u.update(l,"base64","utf8");return JSON.parse(c+=u.final("utf8"))},registerCron:e=>{console.log(`Plugin ${t} registered cron:`,e)},getConfig:e=>{let t=r.select().from(s0).where(el(s0.key,e)).get();return t?.value||null},setConfig:(e,t)=>{r.insert(s0).values({key:e,value:t,updatedAt:new Date().toISOString()}).onConflictDoUpdate({target:s0.key,set:{value:t,updatedAt:new Date().toISOString()}})}}}function s3(e){return Array.from(s4().values()).filter(t=>t.teamTypes.includes(e))}e.s(["createPluginContext",()=>s5,"discoverKitchenPlugins",()=>s4,"getPluginsForTeamType",()=>s3],10353)}];
20
+ `),l}(t);return{db:r,teamDir:i,encrypt:t=>{let i=e.r(54799),r=i.pbkdf2Sync(s,"kitchen-plugin-salt",1e5,32,"sha256"),n=i.randomBytes(16),a=i.createCipher("aes-256-gcm",r);a.setAAD(n);let o=a.update(JSON.stringify(t),"utf8","base64");o+=a.final("base64");let l=a.getAuthTag();return Buffer.concat([n,l,Buffer.from(o,"base64")]).toString("base64")},decrypt:t=>{let i=e.r(54799),r=i.pbkdf2Sync(s,"kitchen-plugin-salt",1e5,32,"sha256"),n=Buffer.from(t,"base64"),a=n.subarray(0,16),o=n.subarray(16,32),l=n.subarray(32).toString("base64"),u=i.createDecipher("aes-256-gcm",r);u.setAAD(a),u.setAuthTag(o);let c=u.update(l,"base64","utf8");return JSON.parse(c+=u.final("utf8"))},registerCron:e=>{console.log(`Plugin ${t} registered cron:`,e)},getConfig:e=>{let t=r.select().from(s0).where(el(s0.key,e)).get();return t?.value||null},setConfig:(e,t)=>{r.insert(s0).values({key:e,value:t,updatedAt:new Date().toISOString()}).onConflictDoUpdate({target:s0.key,set:{value:t,updatedAt:new Date().toISOString()}})}}}function s3(e){return Array.from(s4().values()).filter(t=>t.teamTypes.includes(e))}e.s(["createPluginContext",()=>s5,"discoverKitchenPlugins",()=>s4,"getPluginsForTeamType",()=>s3],10353)}];
21
21
 
22
22
  //# sourceMappingURL=%5Broot-of-the-server%5D__497e7a9d._.js.map