@tempoxyz/id 0.0.1 → 0.0.2

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 (120) hide show
  1. package/dist/app/server/.vite/manifest.json +65 -65
  2. package/dist/app/server/assets/Grant-D_tun0mF.js.map +1 -1
  3. package/dist/app/server/assets/authorize-DXYo-K2n-B-6vqhvc.js +56 -0
  4. package/dist/app/server/assets/authorize-DXYo-K2n-B-6vqhvc.js.map +1 -0
  5. package/dist/app/server/assets/core-FSS9-r35.js +56 -0
  6. package/dist/app/server/assets/core-FSS9-r35.js.map +1 -0
  7. package/dist/app/server/assets/default-u_dwuiYb-Bby14ucv.js +2 -0
  8. package/dist/app/server/assets/{default-u_dwuiYb-DOrMMcg9.js.map → default-u_dwuiYb-Bby14ucv.js.map} +1 -1
  9. package/dist/app/server/assets/{dist-CoH0hD1s.js → dist-B9KiBJYw.js} +2 -2
  10. package/dist/app/server/assets/{dist-CoH0hD1s.js.map → dist-B9KiBJYw.js.map} +1 -1
  11. package/dist/app/server/assets/{dist-DcICI3fd.js → dist-CU1NXSiz.js} +2 -2
  12. package/dist/app/server/assets/{dist-DcICI3fd.js.map → dist-CU1NXSiz.js.map} +1 -1
  13. package/dist/app/server/assets/dist-CetH4JSY.js +1 -0
  14. package/dist/app/server/assets/{effect-QlVUlMFu-mXPkuQTb.js → effect-QlVUlMFu-Cm-eTtaO.js} +2 -2
  15. package/dist/app/server/assets/{effect-QlVUlMFu-mXPkuQTb.js.map → effect-QlVUlMFu-Cm-eTtaO.js.map} +1 -1
  16. package/dist/app/server/assets/factory-g3i_Ffi5.js +5 -0
  17. package/dist/app/server/assets/{factory-dvoOlKer.js.map → factory-g3i_Ffi5.js.map} +1 -1
  18. package/dist/app/server/assets/get-id-field-BpOAoqqI.js +6 -0
  19. package/dist/app/server/assets/get-id-field-BpOAoqqI.js.map +1 -0
  20. package/dist/app/server/assets/{index-CLddUTqr-CC33CMvS.js → index-CLddUTqr-CmgkbWi9.js} +2 -2
  21. package/dist/app/server/assets/{index-CLddUTqr-CC33CMvS.js.map → index-CLddUTqr-CmgkbWi9.js.map} +1 -1
  22. package/dist/app/server/assets/{index-DZEfthgZ-Ec2MMQ_e.js → index-DZEfthgZ-BnPmps9O.js} +2 -2
  23. package/dist/app/server/assets/{index-DZEfthgZ-Ec2MMQ_e.js.map → index-DZEfthgZ-BnPmps9O.js.map} +1 -1
  24. package/dist/app/server/assets/kysely-adapter-B8VoPArC.js +1 -0
  25. package/dist/app/server/assets/{schema-check-oLqvHR8y.js → schema-check-Bgwl1v0_.js} +2 -2
  26. package/dist/app/server/assets/{schema-check-oLqvHR8y.js.map → schema-check-Bgwl1v0_.js.map} +1 -1
  27. package/dist/app/server/assets/{sury-CWZTCd75-CDaOS2oM.js → sury-CWZTCd75-Bd_PzqCV.js} +2 -2
  28. package/dist/app/server/assets/{sury-CWZTCd75-CDaOS2oM.js.map → sury-CWZTCd75-Bd_PzqCV.js.map} +1 -1
  29. package/dist/app/server/assets/{valibot--1zFm7rT-CIKoH3MS.js → valibot--1zFm7rT-Dd2aEhWG.js} +2 -2
  30. package/dist/app/server/assets/{valibot--1zFm7rT-CIKoH3MS.js.map → valibot--1zFm7rT-Dd2aEhWG.js.map} +1 -1
  31. package/dist/app/server/assets/{valibot-D_HTw1Gn-BdPyLkXt.js → valibot-D_HTw1Gn-C1l3va6F.js} +2 -2
  32. package/dist/app/server/assets/{valibot-D_HTw1Gn-BdPyLkXt.js.map → valibot-D_HTw1Gn-C1l3va6F.js.map} +1 -1
  33. package/dist/app/server/assets/{zod-Bwrt9trS-BezI5Gi1.js → zod-Bwrt9trS-Dry2w0in.js} +2 -2
  34. package/dist/app/server/assets/{zod-Bwrt9trS-BezI5Gi1.js.map → zod-Bwrt9trS-Dry2w0in.js.map} +1 -1
  35. package/dist/app/server/assets/{zod-DSgpEGAE-DZ7M_Q33.js → zod-DSgpEGAE-BZMP86UA.js} +2 -2
  36. package/dist/app/server/assets/{zod-DSgpEGAE-DZ7M_Q33.js.map → zod-DSgpEGAE-BZMP86UA.js.map} +1 -1
  37. package/dist/app/server/index.js +35 -35
  38. package/dist/app/server/index.js.map +1 -1
  39. package/dist/client/Auth.d.ts +1 -1
  40. package/dist/client/Auth.d.ts.map +1 -1
  41. package/dist/client/Auth.js.map +1 -1
  42. package/dist/client/Decorator.d.ts +3 -1
  43. package/dist/client/Decorator.d.ts.map +1 -1
  44. package/dist/client/Decorator.js +1 -0
  45. package/dist/client/Decorator.js.map +1 -1
  46. package/dist/client/actions/passkey.d.ts +63 -2
  47. package/dist/client/actions/passkey.d.ts.map +1 -1
  48. package/dist/client/actions/passkey.js +121 -3
  49. package/dist/client/actions/passkey.js.map +1 -1
  50. package/dist/internal/Apps.d.ts +14 -0
  51. package/dist/internal/Apps.d.ts.map +1 -1
  52. package/dist/internal/Apps.js +14 -2
  53. package/dist/internal/Apps.js.map +1 -1
  54. package/dist/internal/Auth.d.ts +7 -0
  55. package/dist/internal/Auth.d.ts.map +1 -1
  56. package/dist/internal/Auth.js +2 -1
  57. package/dist/internal/Auth.js.map +1 -1
  58. package/dist/internal/Authorize.d.ts.map +1 -1
  59. package/dist/internal/Authorize.js +13 -13
  60. package/dist/internal/Authorize.js.map +1 -1
  61. package/dist/internal/ErrorResponse.d.ts +5 -0
  62. package/dist/internal/ErrorResponse.d.ts.map +1 -1
  63. package/dist/internal/ErrorResponse.js +8 -0
  64. package/dist/internal/ErrorResponse.js.map +1 -1
  65. package/dist/internal/KeyAuthorization.d.ts.map +1 -1
  66. package/dist/internal/KeyAuthorization.js +28 -28
  67. package/dist/internal/KeyAuthorization.js.map +1 -1
  68. package/dist/internal/Owner.d.ts +16 -0
  69. package/dist/internal/Owner.d.ts.map +1 -1
  70. package/dist/internal/Owner.js.map +1 -1
  71. package/dist/internal/Passkey.d.ts +66 -4
  72. package/dist/internal/Passkey.d.ts.map +1 -1
  73. package/dist/internal/Passkey.js +66 -30
  74. package/dist/internal/Passkey.js.map +1 -1
  75. package/dist/internal/Privy.d.ts +27 -0
  76. package/dist/internal/Privy.d.ts.map +1 -1
  77. package/dist/internal/Privy.js +82 -0
  78. package/dist/internal/Privy.js.map +1 -1
  79. package/dist/internal/TempoAccount.d.ts +57 -0
  80. package/dist/internal/TempoAccount.d.ts.map +1 -1
  81. package/dist/internal/TempoAccount.js +118 -5
  82. package/dist/internal/TempoAccount.js.map +1 -1
  83. package/dist/internal/owners/Privy.d.ts.map +1 -1
  84. package/dist/internal/owners/Privy.js +11 -2
  85. package/dist/internal/owners/Privy.js.map +1 -1
  86. package/package.json +1 -1
  87. package/src/api/account.ts +140 -103
  88. package/src/api/authenticate.ts +48 -51
  89. package/src/api/authorize.ts +35 -36
  90. package/src/api/device.ts +20 -23
  91. package/src/api/health.ts +1 -2
  92. package/src/api/lib/AccountStep.ts +75 -0
  93. package/src/api/lib/Auth.ts +6 -0
  94. package/src/api/lib/Cors.ts +3 -0
  95. package/src/api/lib/KeySigner.ts +1 -1
  96. package/src/api/oauth.ts +23 -22
  97. package/src/client/Auth.ts +1 -0
  98. package/src/client/Decorator.ts +6 -1
  99. package/src/client/actions/passkey.ts +197 -3
  100. package/src/internal/Apps.ts +26 -2
  101. package/src/internal/Auth.ts +4 -0
  102. package/src/internal/Authorize.ts +13 -15
  103. package/src/internal/ErrorResponse.ts +10 -0
  104. package/src/internal/KeyAuthorization.ts +28 -31
  105. package/src/internal/OpenApi.ts +35 -0
  106. package/src/internal/Owner.ts +16 -0
  107. package/src/internal/Passkey.ts +99 -34
  108. package/src/internal/Privy.ts +128 -0
  109. package/src/internal/TempoAccount.ts +221 -7
  110. package/src/internal/owners/Privy.ts +19 -6
  111. package/dist/app/server/assets/authorize-DXYo-K2n-rmQQ42x1.js +0 -56
  112. package/dist/app/server/assets/authorize-DXYo-K2n-rmQQ42x1.js.map +0 -1
  113. package/dist/app/server/assets/core-BBrZXfrB.js +0 -56
  114. package/dist/app/server/assets/core-BBrZXfrB.js.map +0 -1
  115. package/dist/app/server/assets/default-u_dwuiYb-DOrMMcg9.js +0 -2
  116. package/dist/app/server/assets/dist-CR6FW-yS.js +0 -1
  117. package/dist/app/server/assets/factory-dvoOlKer.js +0 -5
  118. package/dist/app/server/assets/get-id-field-OwLpfjj2.js +0 -6
  119. package/dist/app/server/assets/get-id-field-OwLpfjj2.js.map +0 -1
  120. package/dist/app/server/assets/kysely-adapter-B8tQwTcu.js +0 -1
@@ -0,0 +1,2 @@
1
+ import{n as e}from"./index-CLddUTqr-CmgkbWi9.js";import"./dist-CetH4JSY.js";import{t}from"./convert-BIC8n32x.js";function n(){return async(n,r)=>t(await e(n,r.options),r)}export{n as default};
2
+ //# sourceMappingURL=default-u_dwuiYb-Bby14ucv.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"default-u_dwuiYb-DOrMMcg9.js","names":["toJsonSchema","getToOpenAPISchemaFn","convertToOpenAPISchema","schema","context"],"sources":["../../../../../node_modules/.pnpm/@standard-community+standard-openapi@0.2.10_@standard-community+standard-json@0.3.6_@st_178912a7edb02e19ee9f083d85fa0d1d/node_modules/@standard-community/standard-openapi/dist/default-u_dwuiYb.js"],"sourcesContent":["import { toJsonSchema } from '@standard-community/standard-json';\nimport { convertToOpenAPISchema } from './vendors/convert.js';\n\nfunction getToOpenAPISchemaFn() {\n return async (schema, context) => convertToOpenAPISchema(\n await toJsonSchema(schema, context.options),\n context\n );\n}\n\nexport { getToOpenAPISchemaFn as default };\n"],"ignoreList":[0],"mappings":"A,iHAGA,SAASC,GAAuB,CAC9B,OAAO,MAAO,EAAQ,IAAYC,EAChC,MAAMF,EAAaG,EAAQC,EAAQ,OAAO,EAC1CA,CACF,CACF,C"}
1
+ {"version":3,"file":"default-u_dwuiYb-Bby14ucv.js","names":["toJsonSchema","getToOpenAPISchemaFn","convertToOpenAPISchema","schema","context"],"sources":["../../../../../node_modules/.pnpm/@standard-community+standard-openapi@0.2.10_@standard-community+standard-json@0.3.6_@st_178912a7edb02e19ee9f083d85fa0d1d/node_modules/@standard-community/standard-openapi/dist/default-u_dwuiYb.js"],"sourcesContent":["import { toJsonSchema } from '@standard-community/standard-json';\nimport { convertToOpenAPISchema } from './vendors/convert.js';\n\nfunction getToOpenAPISchemaFn() {\n return async (schema, context) => convertToOpenAPISchema(\n await toJsonSchema(schema, context.options),\n context\n );\n}\n\nexport { getToOpenAPISchemaFn as default };\n"],"ignoreList":[0],"mappings":"A,iHAGA,SAASC,GAAuB,CAC9B,OAAO,MAAO,EAAQ,IAAYC,EAChC,MAAMF,EAAaG,EAAQC,EAAQ,OAAO,EAC1CA,CACF,CACF,C"}
@@ -1,4 +1,4 @@
1
- import{w as e,x as t}from"./get-id-field-OwLpfjj2.js";import{c as n,i as r,n as i,t as a,u as o}from"./schema-check-oLqvHR8y.js";import{t as s}from"./factory-dvoOlKer.js";import{$ as c,A as l,B as u,C as d,D as f,E as p,F as m,G as h,H as g,I as _,J as ee,K as v,L as te,M as ne,N as re,O as ie,P as ae,Q as y,R as oe,S as se,T as b,U as x,V as ce,W as S,X as le,Y as ue,Z as de,_ as fe,b as C,c as w,d as pe,et as me,f as T,g as he,h as ge,i as _e,it as E,j as ve,k as ye,l as D,m as be,nt as O,p as k,q as A,rt as xe,s as Se,tt as j,u as M,v as Ce,w as we,x as Te,y as Ee,z as De}from"./sqlite-introspector-DSCAP82F-Crx7Ny14.js";import{t as N}from"./compiled-query-Ds2NVcFT.js";import{n as Oe,r as ke,t as Ae}from"./sqlite-adapter-C_LAV4e3.js";var P=A({is(e){return e.kind===`AlterTableNode`},create(e){return A({kind:`AlterTableNode`,table:e})},cloneWithTableProps(e,t){return A({...e,...t})},cloneWithColumnAlteration(e,t){return A({...e,columnAlterations:e.columnAlterations?[...e.columnAlterations,t]:[t]})}}),F=A({is(e){return e.kind===`CreateIndexNode`},create(e){return A({kind:`CreateIndexNode`,name:v.create(e)})},cloneWith(e,t){return A({...e,...t})},cloneWithColumns(e,t){return A({...e,columns:[...e.columns||[],...t]})}}),je=A({is(e){return e.kind===`CreateSchemaNode`},create(e,t){return A({kind:`CreateSchemaNode`,schema:v.create(e),...t})},cloneWith(e,t){return A({...e,...t})}}),I=A({is(e){return e.kind===`DropIndexNode`},create(e,t){return A({kind:`DropIndexNode`,name:x.create(e),...t})},cloneWith(e,t){return A({...e,...t})}}),Me=A({is(e){return e.kind===`DropSchemaNode`},create(e,t){return A({kind:`DropSchemaNode`,schema:v.create(e),...t})},cloneWith(e,t){return A({...e,...t})}}),Ne=A({is(e){return e.kind===`DropTableNode`},create(e,t){return A({kind:`DropTableNode`,table:e,...t})},cloneWith(e,t){return A({...e,...t})}}),Pe=A({is(e){return e.kind===`AddColumnNode`},create(e){return A({kind:`AddColumnNode`,column:e})}}),L=A({is(e){return e.kind===`ColumnDefinitionNode`},create(e,t){return A({kind:`ColumnDefinitionNode`,column:u.create(e),dataType:t})},cloneWithFrontModifier(e,t){return A({...e,frontModifiers:e.frontModifiers?A([...e.frontModifiers,t]):[t]})},cloneWithEndModifier(e,t){return A({...e,endModifiers:e.endModifiers?A([...e.endModifiers,t]):[t]})},cloneWith(e,t){return A({...e,...t})}}),Fe=A({is(e){return e.kind===`DropColumnNode`},create(e){return A({kind:`DropColumnNode`,column:u.create(e)})},cloneWith(e,t){return A({...e,...t})}}),Ie=A({is(e){return e.kind===`RenameColumnNode`},create(e,t){return A({kind:`RenameColumnNode`,column:u.create(e),renameTo:u.create(t)})}}),Le=A({is(e){return e.kind===`CheckConstraintNode`},create(e,t){return A({kind:`CheckConstraintNode`,expression:e,name:t?v.create(t):void 0})}}),Re=A({cascade:!0,"no action":!0,restrict:!0,"set default":!0,"set null":!0});Object.keys(Re);var ze=A({is(e){return e.kind===`ReferencesNode`},create(e,t){return A({kind:`ReferencesNode`,table:e,columns:A([...t])})},cloneWithOnDelete(e,t){return A({...e,onDelete:t})},cloneWithOnUpdate(e,t){return A({...e,onUpdate:t})}});function Be(e){return O(e)&&Re[e]}function Ve(e){return ce(e)?e.toOperationNode():l.createImmediate(e)}var He=A({is(e){return e.kind===`GeneratedNode`},create(e){return A({kind:`GeneratedNode`,...e})},createWithExpression(e){return A({kind:`GeneratedNode`,always:!0,expression:e})},cloneWith(e,t){return A({...e,...t})}}),Ue=A({is(e){return e.kind===`DefaultValueNode`},create(e){return A({kind:`DefaultValueNode`,defaultValue:e})}});function We(e){if(Be(e))return e;throw Error(`invalid OnModifyForeignAction ${e}`)}var R=class e{#e;constructor(e){this.#e=e}autoIncrement(){return new e(L.cloneWith(this.#e,{autoIncrement:!0}))}identity(){return new e(L.cloneWith(this.#e,{identity:!0}))}primaryKey(){return new e(L.cloneWith(this.#e,{primaryKey:!0}))}references(t){let n=ae(t);if(!n.table||De.is(n.column))throw Error(`invalid call references('${t}'). The reference must have format table.column or schema.table.column`);return new e(L.cloneWith(this.#e,{references:ze.create(n.table,[n.column])}))}onDelete(t){if(!this.#e.references)throw Error(`on delete constraint can only be added for foreign keys`);return new e(L.cloneWith(this.#e,{references:ze.cloneWithOnDelete(this.#e.references,We(t))}))}onUpdate(t){if(!this.#e.references)throw Error(`on update constraint can only be added for foreign keys`);return new e(L.cloneWith(this.#e,{references:ze.cloneWithOnUpdate(this.#e.references,We(t))}))}unique(){return new e(L.cloneWith(this.#e,{unique:!0}))}notNull(){return new e(L.cloneWith(this.#e,{notNull:!0}))}unsigned(){return new e(L.cloneWith(this.#e,{unsigned:!0}))}defaultTo(t){return new e(L.cloneWith(this.#e,{defaultTo:Ue.create(Ve(t))}))}check(t){return new e(L.cloneWith(this.#e,{check:Le.create(t.toOperationNode())}))}generatedAlwaysAs(t){return new e(L.cloneWith(this.#e,{generated:He.createWithExpression(t.toOperationNode())}))}generatedAlwaysAsIdentity(){return new e(L.cloneWith(this.#e,{generated:He.create({identity:!0,always:!0})}))}generatedByDefaultAsIdentity(){return new e(L.cloneWith(this.#e,{generated:He.create({identity:!0,byDefault:!0})}))}stored(){if(!this.#e.generated)throw Error(`stored() can only be called after generatedAlwaysAs`);return new e(L.cloneWith(this.#e,{generated:He.cloneWith(this.#e.generated,{stored:!0})}))}modifyFront(t){return new e(L.cloneWithFrontModifier(this.#e,t.toOperationNode()))}nullsNotDistinct(){return new e(L.cloneWith(this.#e,{nullsNotDistinct:!0}))}ifNotExists(){return new e(L.cloneWith(this.#e,{ifNotExists:!0}))}modifyEnd(t){return new e(L.cloneWithEndModifier(this.#e,t.toOperationNode()))}$call(e){return e(this)}toOperationNode(){return this.#e}},Ge=A({is(e){return e.kind===`ModifyColumnNode`},create(e){return A({kind:`ModifyColumnNode`,column:e})}}),z=A({is(e){return e.kind===`ForeignKeyConstraintNode`},create(e,t,n,r){return A({kind:`ForeignKeyConstraintNode`,columns:e,references:ze.create(t,n),name:r?v.create(r):void 0})},cloneWith(e,t){return A({...e,...t})}}),Ke=class e{#e;constructor(e){this.#e=e}onDelete(t){return new e(z.cloneWith(this.#e,{onDelete:We(t)}))}onUpdate(t){return new e(z.cloneWith(this.#e,{onUpdate:We(t)}))}deferrable(){return new e(z.cloneWith(this.#e,{deferrable:!0}))}notDeferrable(){return new e(z.cloneWith(this.#e,{deferrable:!1}))}initiallyDeferred(){return new e(z.cloneWith(this.#e,{initiallyDeferred:!0}))}initiallyImmediate(){return new e(z.cloneWith(this.#e,{initiallyDeferred:!1}))}$call(e){return e(this)}toOperationNode(){return this.#e}},B=A({is(e){return e.kind===`AddConstraintNode`},create(e){return A({kind:`AddConstraintNode`,constraint:e})}}),V=A({is(e){return e.kind===`UniqueConstraintNode`},create(e,t,n){return O(e.at(0))&&(m("`UniqueConstraintNode.create(columns: string[], ...)` is deprecated - pass `ColumnNode[]` instead."),e=e.map(u.create)),A({kind:`UniqueConstraintNode`,columns:A(e),name:t?v.create(t):void 0,nullsNotDistinct:n})},cloneWith(e,t){return A({...e,...t})}}),H=A({is(e){return e.kind===`DropConstraintNode`},create(e){return A({kind:`DropConstraintNode`,constraintName:v.create(e)})},cloneWith(e,t){return A({...e,...t})}}),U=A({is(e){return e.kind===`AlterColumnNode`},create(e,t,n){return A({kind:`AlterColumnNode`,column:u.create(e),[t]:n})}}),qe=class{#e;constructor(e){this.#e=e}setDataType(e){return new W(U.create(this.#e,`dataType`,k(e)))}setDefault(e){return new W(U.create(this.#e,`setDefault`,Ve(e)))}dropDefault(){return new W(U.create(this.#e,`dropDefault`,!0))}setNotNull(){return new W(U.create(this.#e,`setNotNull`,!0))}dropNotNull(){return new W(U.create(this.#e,`dropNotNull`,!0))}$call(e){return e(this)}},W=class{#e;constructor(e){this.#e=e}toOperationNode(){return this.#e}},G=class{#e;constructor(e){this.#e=A(e)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(e){await this.#e.executor.executeQuery(this.compile(),e)}},Je=class e{#e;constructor(e){this.#e=A(e)}onDelete(t){return new e({...this.#e,constraintBuilder:this.#e.constraintBuilder.onDelete(t)})}onUpdate(t){return new e({...this.#e,constraintBuilder:this.#e.constraintBuilder.onUpdate(t)})}deferrable(){return new e({...this.#e,constraintBuilder:this.#e.constraintBuilder.deferrable()})}notDeferrable(){return new e({...this.#e,constraintBuilder:this.#e.constraintBuilder.notDeferrable()})}initiallyDeferred(){return new e({...this.#e,constraintBuilder:this.#e.constraintBuilder.initiallyDeferred()})}initiallyImmediate(){return new e({...this.#e,constraintBuilder:this.#e.constraintBuilder.initiallyImmediate()})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(P.cloneWithTableProps(this.#e.node,{addConstraint:B.create(this.#e.constraintBuilder.toOperationNode())}),this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(e){await this.#e.executor.executeQuery(this.compile(),e)}},Ye=class e{#e;constructor(e){this.#e=A(e)}ifExists(){return new e({...this.#e,node:P.cloneWithTableProps(this.#e.node,{dropConstraint:H.cloneWith(this.#e.node.dropConstraint,{ifExists:!0})})})}cascade(){return new e({...this.#e,node:P.cloneWithTableProps(this.#e.node,{dropConstraint:H.cloneWith(this.#e.node.dropConstraint,{modifier:`cascade`})})})}restrict(){return new e({...this.#e,node:P.cloneWithTableProps(this.#e.node,{dropConstraint:H.cloneWith(this.#e.node.dropConstraint,{modifier:`restrict`})})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(e){await this.#e.executor.executeQuery(this.compile(),e)}},K=A({is(e){return e.kind===`PrimaryKeyConstraintNode`},create(e,t){return A({kind:`PrimaryKeyConstraintNode`,columns:A(e.map(u.create)),name:t?v.create(t):void 0})},cloneWith(e,t){return A({...e,...t})}}),q=A({is(e){return e.kind===`AddIndexNode`},create(e){return A({kind:`AddIndexNode`,name:v.create(e)})},cloneWith(e,t){return A({...e,...t})},cloneWithColumns(e,t){return A({...e,columns:[...e.columns||[],...t]})}}),Xe=class e{#e;constructor(e){this.#e=A(e)}unique(){return new e({...this.#e,node:P.cloneWithTableProps(this.#e.node,{addIndex:q.cloneWith(this.#e.node.addIndex,{unique:!0})})})}column(t){return new e({...this.#e,node:P.cloneWithTableProps(this.#e.node,{addIndex:q.cloneWithColumns(this.#e.node.addIndex,[O(t)?re(t):t.toOperationNode()])})})}columns(t){return new e({...this.#e,node:P.cloneWithTableProps(this.#e.node,{addIndex:q.cloneWithColumns(this.#e.node.addIndex,t.map(e=>O(e)?re(e):e.toOperationNode()))})})}expression(t){return new e({...this.#e,node:P.cloneWithTableProps(this.#e.node,{addIndex:q.cloneWithColumns(this.#e.node.addIndex,[t.toOperationNode()])})})}using(t){return new e({...this.#e,node:P.cloneWithTableProps(this.#e.node,{addIndex:q.cloneWith(this.#e.node.addIndex,{using:_.createWithSql(t)})})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(e){await this.#e.executor.executeQuery(this.compile(),e)}},Ze=class e{#e;constructor(e){this.#e=e}nullsNotDistinct(){return new e(V.cloneWith(this.#e,{nullsNotDistinct:!0}))}deferrable(){return new e(V.cloneWith(this.#e,{deferrable:!0}))}notDeferrable(){return new e(V.cloneWith(this.#e,{deferrable:!1}))}initiallyDeferred(){return new e(V.cloneWith(this.#e,{initiallyDeferred:!0}))}initiallyImmediate(){return new e(V.cloneWith(this.#e,{initiallyDeferred:!1}))}$call(e){return e(this)}toOperationNode(){return this.#e}},Qe=class e{#e;constructor(e){this.#e=e}deferrable(){return new e(K.cloneWith(this.#e,{deferrable:!0}))}notDeferrable(){return new e(K.cloneWith(this.#e,{deferrable:!1}))}initiallyDeferred(){return new e(K.cloneWith(this.#e,{initiallyDeferred:!0}))}initiallyImmediate(){return new e(K.cloneWith(this.#e,{initiallyDeferred:!1}))}$call(e){return e(this)}toOperationNode(){return this.#e}},$e=class{#e;constructor(e){this.#e=e}$call(e){return e(this)}toOperationNode(){return this.#e}},et=A({is(e){return e.kind===`RenameConstraintNode`},create(e,t){return A({kind:`RenameConstraintNode`,oldName:v.create(e),newName:v.create(t)})}}),tt=class e{#e;constructor(e){this.#e=A({...e})}ifExists(){return new e({...this.#e,node:Fe.cloneWith(this.#e.node,{ifExists:!0})})}toOperationNode(){return this.#e.node}},nt=class{#e;constructor(e){this.#e=A(e)}renameTo(e){return new G({...this.#e,node:P.cloneWithTableProps(this.#e.node,{renameTo:M(e)})})}setSchema(e){return new G({...this.#e,node:P.cloneWithTableProps(this.#e.node,{setSchema:v.create(e)})})}alterColumn(e,t){let n=t(new qe(e));return new J({...this.#e,node:P.cloneWithColumnAlteration(this.#e.node,n.toOperationNode())})}dropColumn(e,t=E){let n=t(new tt({node:Fe.create(e)}));return new J({...this.#e,node:P.cloneWithColumnAlteration(this.#e.node,n.toOperationNode())})}renameColumn(e,t){return new J({...this.#e,node:P.cloneWithColumnAlteration(this.#e.node,Ie.create(e,t))})}addColumn(e,t,n=E){let r=n(new R(L.create(e,k(t))));return new J({...this.#e,node:P.cloneWithColumnAlteration(this.#e.node,Pe.create(r.toOperationNode()))})}modifyColumn(e,t,n=E){let r=n(new R(L.create(e,k(t))));return new J({...this.#e,node:P.cloneWithColumnAlteration(this.#e.node,Ge.create(r.toOperationNode()))})}addUniqueConstraint(e,t,n=E){let r=n(new Ze(V.create(t.map(e=>O(e)?u.create(e):T(e)),e)));return new G({...this.#e,node:P.cloneWithTableProps(this.#e.node,{addConstraint:B.create(r.toOperationNode())})})}addCheckConstraint(e,t,n=E){let r=n(new $e(Le.create(t.toOperationNode(),e)));return new G({...this.#e,node:P.cloneWithTableProps(this.#e.node,{addConstraint:B.create(r.toOperationNode())})})}addForeignKeyConstraint(e,t,n,r,i=E){let a=i(new Ke(z.create(t.map(u.create),M(n),r.map(u.create),e)));return new Je({...this.#e,constraintBuilder:a})}addPrimaryKeyConstraint(e,t,n=E){let r=n(new Qe(K.create(t,e)));return new G({...this.#e,node:P.cloneWithTableProps(this.#e.node,{addConstraint:B.create(r.toOperationNode())})})}dropConstraint(e){return new Ye({...this.#e,node:P.cloneWithTableProps(this.#e.node,{dropConstraint:H.create(e)})})}renameConstraint(e,t){return new Ye({...this.#e,node:P.cloneWithTableProps(this.#e.node,{renameConstraint:et.create(e,t)})})}addIndex(e){return new Xe({...this.#e,node:P.cloneWithTableProps(this.#e.node,{addIndex:q.create(e)})})}dropIndex(e){return new G({...this.#e,node:P.cloneWithTableProps(this.#e.node,{dropIndex:I.create(e)})})}$call(e){return e(this)}},J=class e{#e;constructor(e){this.#e=A(e)}alterColumn(t,n){let r=n(new qe(t));return new e({...this.#e,node:P.cloneWithColumnAlteration(this.#e.node,r.toOperationNode())})}dropColumn(t,n=E){let r=n(new tt({node:Fe.create(t)}));return new e({...this.#e,node:P.cloneWithColumnAlteration(this.#e.node,r.toOperationNode())})}renameColumn(t,n){return new e({...this.#e,node:P.cloneWithColumnAlteration(this.#e.node,Ie.create(t,n))})}addColumn(t,n,r=E){let i=r(new R(L.create(t,k(n))));return new e({...this.#e,node:P.cloneWithColumnAlteration(this.#e.node,Pe.create(i.toOperationNode()))})}modifyColumn(t,n,r=E){let i=r(new R(L.create(t,k(n))));return new e({...this.#e,node:P.cloneWithColumnAlteration(this.#e.node,Ge.create(i.toOperationNode()))})}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(e){await this.#e.executor.executeQuery(this.compile(),e)}},rt=class extends we{transformPrimitiveValueList(e){return ve.create(e.values.map(l.createImmediate))}transformValue(e){return l.createImmediate(e.value)}},it=class e{#e;constructor(e){this.#e=A(e)}ifNotExists(){return new e({...this.#e,node:F.cloneWith(this.#e.node,{ifNotExists:!0})})}unique(){return new e({...this.#e,node:F.cloneWith(this.#e.node,{unique:!0})})}nullsNotDistinct(){return new e({...this.#e,node:F.cloneWith(this.#e.node,{nullsNotDistinct:!0})})}on(t){return new e({...this.#e,node:F.cloneWith(this.#e.node,{table:M(t)})})}column(t){return new e({...this.#e,node:F.cloneWithColumns(this.#e.node,[O(t)?re(t):t.toOperationNode()])})}columns(t){return new e({...this.#e,node:F.cloneWithColumns(this.#e.node,t.map(e=>O(e)?re(e):e.toOperationNode()))})}expression(t){return new e({...this.#e,node:F.cloneWithColumns(this.#e.node,[t.toOperationNode()])})}using(t){return new e({...this.#e,node:F.cloneWith(this.#e.node,{using:_.createWithSql(t)})})}where(...t){let n=new rt;return new e({...this.#e,node:ie.cloneWithWhere(this.#e.node,n.transformNode(ye(t),this.#e.queryId))})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(e){await this.#e.executor.executeQuery(this.compile(),e)}},at=class e{#e;constructor(e){this.#e=A(e)}ifNotExists(){return new e({...this.#e,node:je.cloneWith(this.#e.node,{ifNotExists:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(e){await this.#e.executor.executeQuery(this.compile(),e)}};function ot(e){if(h.includes(e))return e;throw Error(`invalid OnCommitAction ${e}`)}var st=class e{#e;constructor(e){this.#e=e}using(t){return new e(q.cloneWith(this.#e,{using:_.createWithSql(t)}))}$call(e){return e(this)}toOperationNode(){return this.#e}},ct=class e{#e;constructor(e){this.#e=A(e)}temporary(){return new e({...this.#e,node:S.cloneWith(this.#e.node,{temporary:!0})})}onCommit(t){return new e({...this.#e,node:S.cloneWith(this.#e.node,{onCommit:ot(t)})})}ifNotExists(){return new e({...this.#e,node:S.cloneWith(this.#e.node,{ifNotExists:!0})})}addColumn(t,n,r=E){let i=r(new R(L.create(t,k(n))));return new e({...this.#e,node:S.cloneWithColumn(this.#e.node,i.toOperationNode())})}addPrimaryKeyConstraint(t,n,r=E){let i=r(new Qe(K.create(n,t)));return new e({...this.#e,node:S.cloneWithConstraint(this.#e.node,i.toOperationNode())})}addUniqueConstraint(t,n,r=E){let i=r(new Ze(V.create(n.map(e=>O(e)?u.create(e):T(e)),t)));return new e({...this.#e,node:S.cloneWithConstraint(this.#e.node,i.toOperationNode())})}addIndex(t,n,r=E){let i=r(new st(q.cloneWithColumns(q.create(t),n.map(e=>O(e)?u.create(e):T(e)))));return new e({...this.#e,node:S.cloneWithIndex(this.#e.node,i.toOperationNode())})}addCheckConstraint(t,n,r=E){let i=r(new $e(Le.create(n.toOperationNode(),t)));return new e({...this.#e,node:S.cloneWithConstraint(this.#e.node,i.toOperationNode())})}addForeignKeyConstraint(t,n,r,i,a=E){let o=a(new Ke(z.create(n.map(u.create),M(r),i.map(u.create),t)));return new e({...this.#e,node:S.cloneWithConstraint(this.#e.node,o.toOperationNode())})}modifyFront(t){return new e({...this.#e,node:S.cloneWithFrontModifier(this.#e.node,t.toOperationNode())})}modifyEnd(t){return new e({...this.#e,node:S.cloneWithEndModifier(this.#e.node,t.toOperationNode())})}as(t){return new e({...this.#e,node:S.cloneWith(this.#e.node,{selectQuery:T(t)})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(e){await this.#e.executor.executeQuery(this.compile(),e)}},lt=class e{#e;constructor(e){this.#e=A(e)}on(t){return new e({...this.#e,node:I.cloneWith(this.#e.node,{table:M(t)})})}ifExists(){return new e({...this.#e,node:I.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new e({...this.#e,node:I.cloneWith(this.#e.node,{cascade:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(e){await this.#e.executor.executeQuery(this.compile(),e)}},ut=class e{#e;constructor(e){this.#e=A(e)}ifExists(){return new e({...this.#e,node:Me.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new e({...this.#e,node:Me.cloneWith(this.#e.node,{cascade:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(e){await this.#e.executor.executeQuery(this.compile(),e)}},dt=class e{#e;constructor(e){this.#e=A(e)}temporary(){return new e({...this.#e,node:Ne.cloneWith(this.#e.node,{temporary:!0})})}ifExists(){return new e({...this.#e,node:Ne.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new e({...this.#e,node:Ne.cloneWith(this.#e.node,{cascade:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(e){await this.#e.executor.executeQuery(this.compile(),e)}},ft=class{#e=new rt;transformQuery(e){return this.#e.transformNode(e.node,e.queryId)}transformResult(e){return Promise.resolve(e.result)}},pt=class e{#e;constructor(e){this.#e=A(e)}temporary(){return new e({...this.#e,node:D.cloneWith(this.#e.node,{temporary:!0})})}materialized(){return new e({...this.#e,node:D.cloneWith(this.#e.node,{materialized:!0})})}ifNotExists(){return new e({...this.#e,node:D.cloneWith(this.#e.node,{ifNotExists:!0})})}orReplace(){return new e({...this.#e,node:D.cloneWith(this.#e.node,{orReplace:!0})})}columns(t){return new e({...this.#e,node:D.cloneWith(this.#e.node,{columns:t.map(ne)})})}as(t){let n=t.withPlugin(new ft).toOperationNode();return new e({...this.#e,node:D.cloneWith(this.#e.node,{as:n})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(e){await this.#e.executor.executeQuery(this.compile(),e)}},mt=A({is(e){return e.kind===`DropViewNode`},create(e){return A({kind:`DropViewNode`,name:x.create(e)})},cloneWith(e,t){return A({...e,...t})}}),ht=class e{#e;constructor(e){this.#e=A(e)}materialized(){return new e({...this.#e,node:mt.cloneWith(this.#e.node,{materialized:!0})})}ifExists(){return new e({...this.#e,node:mt.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new e({...this.#e,node:mt.cloneWith(this.#e.node,{cascade:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(e){await this.#e.executor.executeQuery(this.compile(),e)}},gt=A({is(e){return e.kind===`CreateTypeNode`},create(e){return A({kind:`CreateTypeNode`,name:e})},cloneWithEnum(e,t){return A({...e,enum:ve.create(t.map(l.createImmediate))})}}),_t=class e{#e;constructor(e){this.#e=A(e)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}asEnum(t){return new e({...this.#e,node:gt.cloneWithEnum(this.#e.node,t)})}$call(e){return e(this)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(e){await this.#e.executor.executeQuery(this.compile(),e)}},vt=A({is(e){return e.kind===`DropTypeNode`},create(e){return Array.isArray(e)||(e=[e]),A({kind:`DropTypeNode`,name:e[0],additionalNames:e.slice(1)})},cloneWith(e,t){return A({...e,...t})}}),yt=class e{#e;constructor(e){this.#e=A(e)}ifExists(){return new e({...this.#e,node:vt.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new e({...this.#e,node:vt.cloneWith(this.#e.node,{cascade:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(e){await this.#e.executor.executeQuery(this.compile(),e)}};function bt(e){if(e.includes(`.`)){let t=e.split(`.`).map(St);if(t.length===2)return x.createWithSchema(t[0],t[1]);throw Error(`invalid schemable identifier ${e}`)}return x.create(e)}function xt(e){return Array.isArray(e)||(e=[e]),e.map(bt)}function St(e){return e.trim()}var Ct=A({is(e){return e.kind===`RefreshMaterializedViewNode`},create(e){return A({kind:`RefreshMaterializedViewNode`,name:x.create(e)})},cloneWith(e,t){return A({...e,...t})}}),wt=class e{#e;constructor(e){this.#e=A(e)}concurrently(){return new e({...this.#e,node:Ct.cloneWith(this.#e.node,{concurrently:!0,withNoData:!1})})}withData(){return new e({...this.#e,node:Ct.cloneWith(this.#e.node,{withNoData:!1})})}withNoData(){return new e({...this.#e,node:Ct.cloneWith(this.#e.node,{withNoData:!0,concurrently:!1})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(e){await this.#e.executor.executeQuery(this.compile(),e)}},Y=A({is(e){return e.kind===`AlterTypeNode`},create(e){return A({kind:`AlterTypeNode`,name:e})},cloneWith(e,t){return A({...e,...t})}}),Tt=A({is(e){return e.kind===`AddValueNode`},create(e){return A({kind:`AddValueNode`,value:e})},cloneWith(e,t){return A({...e,...t})}}),Et=class{#e;constructor(e){this.#e=A(e)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(e){return await this.#e.executor.executeQuery(this.compile(),e)}},Dt,Ot=class extends Et{#e;constructor(e){super(e),this.#e=e}ifNotExists(){return new Dt({...this.#e,node:Y.cloneWith(this.#e.node,{addValue:Tt.cloneWith(this.#e.node.addValue,{ifNotExists:!0})})})}before(e){return this.#t(e,!0)}after(e){return this.#t(e,!1)}#t(e,t){return new Dt({...this.#e,node:Y.cloneWith(this.#e.node,{addValue:Tt.cloneWith(this.#e.node.addValue,{isBefore:t,neighborValue:l.createImmediate(e)})})})}};Dt=Ot;var kt=A({is(e){return e.kind===`RenameValueNode`},create(e,t){return A({kind:`RenameValueNode`,oldValue:e,newValue:t})}}),At=class{#e;constructor(e){this.#e=A(e)}addValue(e){return new Ot({...this.#e,node:Y.cloneWith(this.#e.node,{addValue:Tt.create(l.createImmediate(e))})})}renameTo(e){return new Et({...this.#e,node:Y.cloneWith(this.#e.node,{renameTo:v.create(e)})})}renameValue(e,t){return new Et({...this.#e,node:Y.cloneWith(this.#e.node,{renameValue:kt.create(l.createImmediate(e),l.createImmediate(t))})})}setSchema(e){return new Et({...this.#e,node:Y.cloneWith(this.#e.node,{setSchema:v.create(e)})})}},jt=class e{#e;constructor(e){this.#e=e}createTable(e){return new ct({queryId:b(),executor:this.#e,node:S.create(M(e))})}dropTable(e){return new dt({queryId:b(),executor:this.#e,node:Ne.create(M(e))})}createIndex(e){return new it({queryId:b(),executor:this.#e,node:F.create(e)})}dropIndex(e){return new lt({queryId:b(),executor:this.#e,node:I.create(e)})}createSchema(e){return new at({queryId:b(),executor:this.#e,node:je.create(e)})}dropSchema(e){return new ut({queryId:b(),executor:this.#e,node:Me.create(e)})}alterTable(e){return new nt({queryId:b(),executor:this.#e,node:P.create(M(e))})}createView(e){return new pt({queryId:b(),executor:this.#e,node:D.create(e)})}refreshMaterializedView(e){return new wt({queryId:b(),executor:this.#e,node:Ct.create(e)})}dropView(e){return new ht({queryId:b(),executor:this.#e,node:mt.create(e)})}createType(e){return new _t({queryId:b(),executor:this.#e,node:gt.create(bt(e))})}alterType(e){return new At({executor:this.#e,node:Y.create(bt(e)),queryId:b()})}dropType(e){return new yt({queryId:b(),executor:this.#e,node:vt.create(xt(e))})}withPlugin(t){return new e(this.#e.withPlugin(t))}withoutPlugins(){return new e(this.#e.withoutPlugins())}withSchema(t){return new e(this.#e.withPluginAtFront(new d(t)))}},Mt=class{ref(e){return new te(e)}table(e){return new pe(e)}},Nt=class{#e;constructor(e){this.#e=e}async provideConnection(e,t){let n=await this.#e.acquireConnection(t);try{return await e(n)}finally{await this.#e.releaseConnection(n,t)}}},Pt=class e extends Ce{#e;#t;#n;constructor(e,t,n,r=[]){super(r),this.#e=e,this.#t=t,this.#n=n}get adapter(){return this.#t}compileQuery(e,t){return this.#e.compileQuery(e,t)}provideConnection(e,t){return this.#n.provideConnection(e,t)}withPlugins(t){return new e(this.#e,this.#t,this.#n,[...this.plugins,...t])}withPlugin(t){return new e(this.#e,this.#t,this.#n,[...this.plugins,t])}withPluginAtFront(t){return new e(this.#e,this.#t,this.#n,[t,...this.plugins])}withConnectionProvider(t){return new e(this.#e,this.#t,t,[...this.plugins])}withoutPlugins(){return new e(this.#e,this.#t,this.#n,[])}};function Ft(){return typeof performance<`u`&&y(performance.now)?performance.now():Date.now()}var It=class{#e;#t;async obtainLock(){for(;this.#e;)await this.#e;this.#e=new Promise(e=>{this.#t=e})}releaseLock(){let e=this.#t;this.#e=void 0,this.#t=void 0,e?.()}},Lt=class{#e;#t;#n;#r;#i;#a=new WeakSet;#o;constructor(e,t,n){this.#e=e,this.#r=!1,this.#t=n,t.supportsMultipleConnections===!1&&(this.#o=new It)}async init(e){if(this.#i)throw Error(`driver has already been destroyed`);this.#n??=this.#e.init(e).then(()=>{this.#r=!0}).catch(e=>{throw this.#n=void 0,e}),await C(this.#n,e?.signal,`init`)}async acquireConnection(e){if(this.#i)throw Error(`driver has already been destroyed`);if(this.#r||await this.init(e),this.#o){let t=this.#o.obtainLock();await C(t,e?.signal,`acquireConnection:mutex`,()=>t.then(()=>this.#o?.releaseLock()))}let t=this.#e.acquireConnection(e),n=await C(t,e?.signal,`acquireConnection:acquire`,()=>t?.then(e=>this.releaseConnection(e).catch(Ee(`driver.releaseConnection`))).catch(Ee(`driver.acquireConnection`)));return this.#a.has(n)||(this.#s()&&this.#c(n),this.#a.add(n)),n}async releaseConnection(e,t){await this.#e.releaseConnection(e,t),this.#o?.releaseLock()}async beginTransaction(e,t){return await this.#e.beginTransaction(e,t)}async commitTransaction(e){return await this.#e.commitTransaction(e)}async rollbackTransaction(e){return await this.#e.rollbackTransaction(e)}async savepoint(e,t,n){if(this.#e.savepoint)return await this.#e.savepoint(e,t,n);throw Error("The `savepoint` method is not supported by this driver")}async rollbackToSavepoint(e,t,n){if(this.#e.rollbackToSavepoint)return await this.#e.rollbackToSavepoint(e,t,n);throw Error("The `rollbackToSavepoint` method is not supported by this driver")}async releaseSavepoint(e,t,n){if(this.#e.releaseSavepoint)return await this.#e.releaseSavepoint(e,t,n);throw Error("The `releaseSavepoint` method is not supported by this driver")}async destroy(e){this.#n&&(await C(this.#n,e?.signal,`destroy:initPromise`),this.#i??=this.#e.destroy(e).catch(e=>{throw this.#i=void 0,e}),await C(this.#i,e?.signal,`destroy`))}#s(){return this.#t.isLevelEnabled(`query`)||this.#t.isLevelEnabled(`error`)}#c(e){let t=e.executeQuery,n=e.streamQuery,r=this;e.executeQuery=async(n,i)=>{let a,o=Ft();try{return await t.call(e,n,i)}catch(e){throw a=e,await r.#l(e,n,o),e}finally{a||await r.#u(n,o)}},e.streamQuery=async function*(t,i,a){let o,s=Ft();try{for await(let r of n.call(e,t,i,a))yield r}catch(e){throw o=e,await r.#l(e,t,s),e}finally{o||await r.#u(t,s,!0)}}}async#l(e,t,n){await this.#t.error(()=>({level:`error`,error:e,query:t,queryDurationMillis:this.#d(n)}))}async#u(e,t,n=!1){await this.#t.query(()=>({level:`query`,isStream:n,query:e,queryDurationMillis:this.#d(t)}))}#d(e){return Ft()-e}},Rt=()=>{},zt=class{#e;#t;constructor(e){this.#e=e}async provideConnection(e){for(;this.#t;)await this.#t.catch(Rt);return this.#t=this.#n(e).finally(()=>{this.#t=void 0}),this.#t}async#n(e){return await e(this.#e)}},Bt=[`read only`,`read write`],Vt=[`read uncommitted`,`read committed`,`repeatable read`,`serializable`,`snapshot`];function Ht(e){if(e.accessMode&&!Bt.includes(e.accessMode))throw Error(`invalid transaction access mode ${e.accessMode}`);if(e.isolationLevel&&!Vt.includes(e.isolationLevel))throw Error(`invalid transaction isolation level ${e.isolationLevel}`)}A([`query`,`error`]);var Ut=class{#e;#t;constructor(e){y(e)?(this.#t=e,this.#e=A({query:!0,error:!0})):(this.#t=Wt,this.#e=A({query:e.includes(`query`),error:e.includes(`error`)}))}isLevelEnabled(e){return this.#e[e]}async query(e){this.#e.query&&await this.#t(e())}async error(e){this.#e.error&&await this.#t(e())}};function Wt(e){if(e.level===`query`){let t=`kysely:query:${e.isStream?`stream:`:``}`;console.log(`${t} ${e.query.sql}`),console.log(`${t} duration: ${e.queryDurationMillis.toFixed(1)}ms`)}else e.level===`error`&&(e.error instanceof Error?console.error(`kysely:error: ${e.error.stack??e.error.message}`):console.error(`kysely:error: ${JSON.stringify({error:e.error,query:e.query.sql,queryDurationMillis:e.queryDurationMillis})}`))}function Gt(e){return j(e)&&y(e.compile)}Symbol.asyncDispose??=Symbol(`Symbol.asyncDispose`);var Kt=class e extends fe{#e;constructor(e){let t,n;if(Jt(e))t={executor:e.executor},n={...e};else{let r=e.dialect,i=r.createDriver(),a=r.createQueryCompiler(),o=r.createAdapter(),s=new Lt(i,o,new Ut(e.log??[])),c=new Pt(a,o,new Nt(s),e.plugins??[]);t={executor:c},n={config:e,executor:c,dialect:r,driver:s}}super(t),this.#e=A(n)}get schema(){return new jt(this.#e.executor)}get dynamic(){return new Mt}get introspection(){return this.#e.dialect.createIntrospector(this.withoutPlugins())}case(e){return new be({node:ge.create(xe(e)?void 0:T(e))})}get fn(){return he()}transaction(){return new Xt({...this.#e})}startTransaction(){return new Zt({...this.#e})}connection(){return new Yt({...this.#e})}withPlugin(t){return new e({...this.#e,executor:this.#e.executor.withPlugin(t)})}withoutPlugins(){return new e({...this.#e,executor:this.#e.executor.withoutPlugins()})}withSchema(t){return new e({...this.#e,executor:this.#e.executor.withPluginAtFront(new d(t))})}$extendTables(){return new e({...this.#e})}$omitTables(){return new e({...this.#e})}$pickTables(){return new e({...this.#e})}withTables(){return this.$extendTables()}async destroy(){await this.#e.driver.destroy()}get isTransaction(){return!1}getExecutor(){return this.#e.executor}async executeQuery(e,t){let n=Gt(e)?e.compile():e;return await this.#e.executor.executeQuery(n,t)}async[Symbol.asyncDispose](){await this.destroy()}},qt=class e extends Kt{#e;constructor(e){super(e),this.#e=e}get isTransaction(){return!0}transaction(){throw Error(`calling the transaction method for a Transaction is not supported`)}startTransaction(){throw Error(`calling the controlled transaction method for a Transaction is not supported`)}connection(){throw Error(`calling the connection method for a Transaction is not supported`)}destroy(){throw Error(`calling the destroy method for a Transaction is not supported`)}withPlugin(t){return new e({...this.#e,executor:this.#e.executor.withPlugin(t)})}withoutPlugins(){return new e({...this.#e,executor:this.#e.executor.withoutPlugins()})}withSchema(t){return new e({...this.#e,executor:this.#e.executor.withPluginAtFront(new d(t))})}withTables(){return new e({...this.#e})}$extendTables(){return new e({...this.#e})}$omitTables(){return new e({...this.#e})}$pickTables(){return new e({...this.#e})}};function Jt(e){return j(e)&&j(e.config)&&j(e.driver)&&j(e.executor)&&j(e.dialect)}var Yt=class{#e;constructor(e){this.#e=A(e)}async execute(e,t){return this.#e.executor.provideConnection(async t=>{let n=this.#e.executor.withConnectionProvider(new zt(t));return await e(new Kt({...this.#e,executor:n}))},A({signal:t?.signal}))}},Xt=class e{#e;constructor(e){this.#e=A(e)}setAccessMode(t){return new e({...this.#e,accessMode:t})}setIsolationLevel(t){return new e({...this.#e,isolationLevel:t})}async execute(e){let{isolationLevel:t,accessMode:n,...r}=this.#e,i={isolationLevel:t,accessMode:n};return Ht(i),this.#e.executor.provideConnection(async t=>{let n={isCommitted:!1,isRolledBack:!1},a=new $t(this.#e.executor.withConnectionProvider(new zt(t)),n),o=new qt({...r,executor:a}),s=!1;try{await this.#e.driver.beginTransaction(t,i),s=!0;let r=await e(o);return await this.#e.driver.commitTransaction(t),n.isCommitted=!0,r}catch(e){throw s&&(await this.#e.driver.rollbackTransaction(t),n.isRolledBack=!0),e}})}},Zt=class e{#e;constructor(e){this.#e=A(e)}setAccessMode(t){return new e({...this.#e,accessMode:t})}setIsolationLevel(t){return new e({...this.#e,isolationLevel:t})}async execute(){let{isolationLevel:e,accessMode:t,...n}=this.#e,r={isolationLevel:e,accessMode:t};Ht(r);let i=await Te(this.#e.executor);return await this.#e.driver.beginTransaction(i.connection,r),new Qt({...n,connection:i,executor:this.#e.executor.withConnectionProvider(new zt(i.connection))})}},Qt=class e extends qt{#e;#t;#n;constructor(e){let t={isCommitted:!1,isRolledBack:!1};e={...e,executor:new $t(e.executor,t)};let{connection:n,...r}=e;super(r),this.#e=A(e),this.#n=t;let i=b();this.#t=t=>e.executor.compileQuery(t,i)}get isCommitted(){return this.#n.isCommitted}get isRolledBack(){return this.#n.isRolledBack}commit(){return Z(this.#n),new X(async()=>{await this.#e.driver.commitTransaction(this.#e.connection.connection),this.#n.isCommitted=!0,this.#e.connection.release()})}rollback(){return Z(this.#n),new X(async()=>{await this.#e.driver.rollbackTransaction(this.#e.connection.connection),this.#n.isRolledBack=!0,this.#e.connection.release()})}savepoint(t){return Z(this.#n),new X(async()=>(await this.#e.driver.savepoint?.(this.#e.connection.connection,t,this.#t),new e({...this.#e})))}rollbackToSavepoint(t){return Z(this.#n),new X(async()=>(await this.#e.driver.rollbackToSavepoint?.(this.#e.connection.connection,t,this.#t),new e({...this.#e})))}releaseSavepoint(t){return Z(this.#n),new X(async()=>(await this.#e.driver.releaseSavepoint?.(this.#e.connection.connection,t,this.#t),new e({...this.#e})))}withPlugin(t){return new e({...this.#e,executor:this.#e.executor.withPlugin(t)})}withoutPlugins(){return new e({...this.#e,executor:this.#e.executor.withoutPlugins()})}withSchema(t){return new e({...this.#e,executor:this.#e.executor.withPluginAtFront(new d(t))})}withTables(){return new e({...this.#e})}$extendTables(){return new e({...this.#e})}$omitTables(){return new e({...this.#e})}$pickTables(){return new e({...this.#e})}},X=class{#e;constructor(e){this.#e=e}async execute(){return await this.#e()}};function Z(e){if(e.isCommitted)throw Error(`Transaction is already committed`);if(e.isRolledBack)throw Error(`Transaction is already rolled back`)}var $t=class e{#e;#t;constructor(t,n){this.#e=t instanceof e?t.#e:t,this.#t=n}get adapter(){return this.#e.adapter}get plugins(){return this.#e.plugins}transformQuery(e,t){return this.#e.transformQuery(e,t)}compileQuery(e,t){return this.#e.compileQuery(e,t)}provideConnection(e,t){return this.#e.provideConnection(e,t)}executeQuery(e,t){return Z(this.#t),this.#e.executeQuery(e,t)}stream(e,t,n){return Z(this.#t),this.#e.stream(e,t,n)}withConnectionProvider(t){return new e(this.#e.withConnectionProvider(t),this.#t)}withPlugin(t){return new e(this.#e.withPlugin(t),this.#t)}withPlugins(t){return new e(this.#e.withPlugins(t),this.#t)}withPluginAtFront(t){return new e(this.#e.withPluginAtFront(t),this.#t)}withoutPlugins(){return new e(this.#e.withoutPlugins(),this.#t)}};function Q(e,t){return _.createWithChildren([_.createWithSql(`${e} `),v.create(t)])}var en=class{#e;#t;#n;constructor(e){this.#e=A({...e})}async init(e){this.#t=y(this.#e.database)?await this.#e.database(e):this.#e.database,this.#n=new tn(this.#t),this.#e.onCreateConnection&&await this.#e.onCreateConnection(this.#n,e)}async acquireConnection(){return this.#n}async beginTransaction(e){await e.executeQuery(N.raw(`begin`))}async commitTransaction(e){await e.executeQuery(N.raw(`commit`))}async rollbackTransaction(e){await e.executeQuery(N.raw(`rollback`))}async savepoint(e,t,n){await e.executeQuery(n(Q(`savepoint`,t),b()))}async rollbackToSavepoint(e,t,n){await e.executeQuery(n(Q(`rollback to`,t),b()))}async releaseSavepoint(e,t,n){await e.executeQuery(n(Q(`release`,t),b()))}async releaseConnection(){}async destroy(){this.#t?.close()}},tn=class{#e;constructor(e){this.#e=e}async executeQuery(e){let{sql:t,parameters:n}=e,r=this.#e.prepare(t);if(r.reader)return{rows:r.all(n)};let{changes:i,lastInsertRowid:a}=r.run(n);return{insertId:a==null?void 0:BigInt(a),numAffectedRows:i==null?void 0:BigInt(i),rows:[]}}async*streamQuery(e,t){let{sql:n,parameters:r,query:i}=e,a=this.#e.prepare(n);if(!f.is(i))throw Error(`Sqlite driver only supports streaming of select queries`);let o=a.iterate(r);for(let e of o)yield{rows:[e]}}},$=`kysely_migration`,nn=`kysely_migration_lock`;A({__noMigrations__:!0});var rn=class{#e;constructor(e){this.#e=e}async getSchemas(){return[]}async getTables(e={withInternalKyselyTables:!1}){return await this.#n(e)}#t(e,t){let n=e.selectFrom(`sqlite_master`).where(`type`,`in`,[`table`,`view`]).where(`name`,`not like`,`sqlite_%`).select([`name`,`sql`,`type`]).orderBy(`name`);return t.withInternalKyselyTables||(n=n.where(`name`,`!=`,$).where(`name`,`!=`,nn)),n}async#n(e){let t=await this.#t(this.#e,e).execute(),n=await this.#e.with(`table_list`,t=>this.#t(t,e)).selectFrom([`table_list as tl`,w`pragma_table_info(tl.name)`.as(`p`)]).select([`tl.name as table`,`p.cid`,`p.name`,`p.type`,`p.notnull`,`p.dflt_value`,`p.pk`]).orderBy(`tl.name`).orderBy(`p.cid`).execute(),r={};for(let e of n)r[e.table]??=[],r[e.table].push(e);return t.map(({name:e,sql:t,type:n})=>{let i=t?.split(/[\(\),]/)?.find(e=>e.toLowerCase().includes(`autoincrement`))?.trimStart()?.split(/\s+/)?.[0]?.replace(/["`]/g,``),a=r[e]??[];if(!i){let e=a.filter(e=>e.pk>0);e.length===1&&e[0].type.toLowerCase()===`integer`&&(i=e[0].name)}return{name:e,isView:n===`view`,isForeign:!1,columns:a.map(e=>({name:e.name,dataType:e.type,isNullable:!e.notnull,isAutoIncrementing:e.name===i,hasDefaultValue:e.dflt_value!=null,comment:void 0}))}})}},an=class{#e;constructor(e){this.#e=A({...e})}createDriver(){return new en(this.#e)}createQueryCompiler(){return new Oe}createAdapter(){return new Ae}createIntrospector(e){return new rn(e)}};function on(e,t){if(sn(e)&&t.stack){let n=t.stack.split(`
1
+ import{w as e,x as t}from"./get-id-field-BpOAoqqI.js";import{c as n,i as r,n as i,t as a,u as o}from"./schema-check-Bgwl1v0_.js";import{t as s}from"./factory-g3i_Ffi5.js";import{$ as c,A as l,B as u,C as d,D as f,E as p,F as m,G as h,H as g,I as _,J as ee,K as v,L as te,M as ne,N as re,O as ie,P as ae,Q as y,R as oe,S as se,T as b,U as x,V as ce,W as S,X as le,Y as ue,Z as de,_ as fe,b as C,c as w,d as pe,et as me,f as T,g as he,h as ge,i as _e,it as E,j as ve,k as ye,l as D,m as be,nt as O,p as k,q as A,rt as xe,s as Se,tt as j,u as M,v as Ce,w as we,x as Te,y as Ee,z as De}from"./sqlite-introspector-DSCAP82F-Crx7Ny14.js";import{t as N}from"./compiled-query-Ds2NVcFT.js";import{n as Oe,r as ke,t as Ae}from"./sqlite-adapter-C_LAV4e3.js";var P=A({is(e){return e.kind===`AlterTableNode`},create(e){return A({kind:`AlterTableNode`,table:e})},cloneWithTableProps(e,t){return A({...e,...t})},cloneWithColumnAlteration(e,t){return A({...e,columnAlterations:e.columnAlterations?[...e.columnAlterations,t]:[t]})}}),F=A({is(e){return e.kind===`CreateIndexNode`},create(e){return A({kind:`CreateIndexNode`,name:v.create(e)})},cloneWith(e,t){return A({...e,...t})},cloneWithColumns(e,t){return A({...e,columns:[...e.columns||[],...t]})}}),je=A({is(e){return e.kind===`CreateSchemaNode`},create(e,t){return A({kind:`CreateSchemaNode`,schema:v.create(e),...t})},cloneWith(e,t){return A({...e,...t})}}),I=A({is(e){return e.kind===`DropIndexNode`},create(e,t){return A({kind:`DropIndexNode`,name:x.create(e),...t})},cloneWith(e,t){return A({...e,...t})}}),Me=A({is(e){return e.kind===`DropSchemaNode`},create(e,t){return A({kind:`DropSchemaNode`,schema:v.create(e),...t})},cloneWith(e,t){return A({...e,...t})}}),Ne=A({is(e){return e.kind===`DropTableNode`},create(e,t){return A({kind:`DropTableNode`,table:e,...t})},cloneWith(e,t){return A({...e,...t})}}),Pe=A({is(e){return e.kind===`AddColumnNode`},create(e){return A({kind:`AddColumnNode`,column:e})}}),L=A({is(e){return e.kind===`ColumnDefinitionNode`},create(e,t){return A({kind:`ColumnDefinitionNode`,column:u.create(e),dataType:t})},cloneWithFrontModifier(e,t){return A({...e,frontModifiers:e.frontModifiers?A([...e.frontModifiers,t]):[t]})},cloneWithEndModifier(e,t){return A({...e,endModifiers:e.endModifiers?A([...e.endModifiers,t]):[t]})},cloneWith(e,t){return A({...e,...t})}}),Fe=A({is(e){return e.kind===`DropColumnNode`},create(e){return A({kind:`DropColumnNode`,column:u.create(e)})},cloneWith(e,t){return A({...e,...t})}}),Ie=A({is(e){return e.kind===`RenameColumnNode`},create(e,t){return A({kind:`RenameColumnNode`,column:u.create(e),renameTo:u.create(t)})}}),Le=A({is(e){return e.kind===`CheckConstraintNode`},create(e,t){return A({kind:`CheckConstraintNode`,expression:e,name:t?v.create(t):void 0})}}),Re=A({cascade:!0,"no action":!0,restrict:!0,"set default":!0,"set null":!0});Object.keys(Re);var ze=A({is(e){return e.kind===`ReferencesNode`},create(e,t){return A({kind:`ReferencesNode`,table:e,columns:A([...t])})},cloneWithOnDelete(e,t){return A({...e,onDelete:t})},cloneWithOnUpdate(e,t){return A({...e,onUpdate:t})}});function Be(e){return O(e)&&Re[e]}function Ve(e){return ce(e)?e.toOperationNode():l.createImmediate(e)}var He=A({is(e){return e.kind===`GeneratedNode`},create(e){return A({kind:`GeneratedNode`,...e})},createWithExpression(e){return A({kind:`GeneratedNode`,always:!0,expression:e})},cloneWith(e,t){return A({...e,...t})}}),Ue=A({is(e){return e.kind===`DefaultValueNode`},create(e){return A({kind:`DefaultValueNode`,defaultValue:e})}});function We(e){if(Be(e))return e;throw Error(`invalid OnModifyForeignAction ${e}`)}var R=class e{#e;constructor(e){this.#e=e}autoIncrement(){return new e(L.cloneWith(this.#e,{autoIncrement:!0}))}identity(){return new e(L.cloneWith(this.#e,{identity:!0}))}primaryKey(){return new e(L.cloneWith(this.#e,{primaryKey:!0}))}references(t){let n=ae(t);if(!n.table||De.is(n.column))throw Error(`invalid call references('${t}'). The reference must have format table.column or schema.table.column`);return new e(L.cloneWith(this.#e,{references:ze.create(n.table,[n.column])}))}onDelete(t){if(!this.#e.references)throw Error(`on delete constraint can only be added for foreign keys`);return new e(L.cloneWith(this.#e,{references:ze.cloneWithOnDelete(this.#e.references,We(t))}))}onUpdate(t){if(!this.#e.references)throw Error(`on update constraint can only be added for foreign keys`);return new e(L.cloneWith(this.#e,{references:ze.cloneWithOnUpdate(this.#e.references,We(t))}))}unique(){return new e(L.cloneWith(this.#e,{unique:!0}))}notNull(){return new e(L.cloneWith(this.#e,{notNull:!0}))}unsigned(){return new e(L.cloneWith(this.#e,{unsigned:!0}))}defaultTo(t){return new e(L.cloneWith(this.#e,{defaultTo:Ue.create(Ve(t))}))}check(t){return new e(L.cloneWith(this.#e,{check:Le.create(t.toOperationNode())}))}generatedAlwaysAs(t){return new e(L.cloneWith(this.#e,{generated:He.createWithExpression(t.toOperationNode())}))}generatedAlwaysAsIdentity(){return new e(L.cloneWith(this.#e,{generated:He.create({identity:!0,always:!0})}))}generatedByDefaultAsIdentity(){return new e(L.cloneWith(this.#e,{generated:He.create({identity:!0,byDefault:!0})}))}stored(){if(!this.#e.generated)throw Error(`stored() can only be called after generatedAlwaysAs`);return new e(L.cloneWith(this.#e,{generated:He.cloneWith(this.#e.generated,{stored:!0})}))}modifyFront(t){return new e(L.cloneWithFrontModifier(this.#e,t.toOperationNode()))}nullsNotDistinct(){return new e(L.cloneWith(this.#e,{nullsNotDistinct:!0}))}ifNotExists(){return new e(L.cloneWith(this.#e,{ifNotExists:!0}))}modifyEnd(t){return new e(L.cloneWithEndModifier(this.#e,t.toOperationNode()))}$call(e){return e(this)}toOperationNode(){return this.#e}},Ge=A({is(e){return e.kind===`ModifyColumnNode`},create(e){return A({kind:`ModifyColumnNode`,column:e})}}),z=A({is(e){return e.kind===`ForeignKeyConstraintNode`},create(e,t,n,r){return A({kind:`ForeignKeyConstraintNode`,columns:e,references:ze.create(t,n),name:r?v.create(r):void 0})},cloneWith(e,t){return A({...e,...t})}}),Ke=class e{#e;constructor(e){this.#e=e}onDelete(t){return new e(z.cloneWith(this.#e,{onDelete:We(t)}))}onUpdate(t){return new e(z.cloneWith(this.#e,{onUpdate:We(t)}))}deferrable(){return new e(z.cloneWith(this.#e,{deferrable:!0}))}notDeferrable(){return new e(z.cloneWith(this.#e,{deferrable:!1}))}initiallyDeferred(){return new e(z.cloneWith(this.#e,{initiallyDeferred:!0}))}initiallyImmediate(){return new e(z.cloneWith(this.#e,{initiallyDeferred:!1}))}$call(e){return e(this)}toOperationNode(){return this.#e}},B=A({is(e){return e.kind===`AddConstraintNode`},create(e){return A({kind:`AddConstraintNode`,constraint:e})}}),V=A({is(e){return e.kind===`UniqueConstraintNode`},create(e,t,n){return O(e.at(0))&&(m("`UniqueConstraintNode.create(columns: string[], ...)` is deprecated - pass `ColumnNode[]` instead."),e=e.map(u.create)),A({kind:`UniqueConstraintNode`,columns:A(e),name:t?v.create(t):void 0,nullsNotDistinct:n})},cloneWith(e,t){return A({...e,...t})}}),H=A({is(e){return e.kind===`DropConstraintNode`},create(e){return A({kind:`DropConstraintNode`,constraintName:v.create(e)})},cloneWith(e,t){return A({...e,...t})}}),U=A({is(e){return e.kind===`AlterColumnNode`},create(e,t,n){return A({kind:`AlterColumnNode`,column:u.create(e),[t]:n})}}),qe=class{#e;constructor(e){this.#e=e}setDataType(e){return new W(U.create(this.#e,`dataType`,k(e)))}setDefault(e){return new W(U.create(this.#e,`setDefault`,Ve(e)))}dropDefault(){return new W(U.create(this.#e,`dropDefault`,!0))}setNotNull(){return new W(U.create(this.#e,`setNotNull`,!0))}dropNotNull(){return new W(U.create(this.#e,`dropNotNull`,!0))}$call(e){return e(this)}},W=class{#e;constructor(e){this.#e=e}toOperationNode(){return this.#e}},G=class{#e;constructor(e){this.#e=A(e)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(e){await this.#e.executor.executeQuery(this.compile(),e)}},Je=class e{#e;constructor(e){this.#e=A(e)}onDelete(t){return new e({...this.#e,constraintBuilder:this.#e.constraintBuilder.onDelete(t)})}onUpdate(t){return new e({...this.#e,constraintBuilder:this.#e.constraintBuilder.onUpdate(t)})}deferrable(){return new e({...this.#e,constraintBuilder:this.#e.constraintBuilder.deferrable()})}notDeferrable(){return new e({...this.#e,constraintBuilder:this.#e.constraintBuilder.notDeferrable()})}initiallyDeferred(){return new e({...this.#e,constraintBuilder:this.#e.constraintBuilder.initiallyDeferred()})}initiallyImmediate(){return new e({...this.#e,constraintBuilder:this.#e.constraintBuilder.initiallyImmediate()})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(P.cloneWithTableProps(this.#e.node,{addConstraint:B.create(this.#e.constraintBuilder.toOperationNode())}),this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(e){await this.#e.executor.executeQuery(this.compile(),e)}},Ye=class e{#e;constructor(e){this.#e=A(e)}ifExists(){return new e({...this.#e,node:P.cloneWithTableProps(this.#e.node,{dropConstraint:H.cloneWith(this.#e.node.dropConstraint,{ifExists:!0})})})}cascade(){return new e({...this.#e,node:P.cloneWithTableProps(this.#e.node,{dropConstraint:H.cloneWith(this.#e.node.dropConstraint,{modifier:`cascade`})})})}restrict(){return new e({...this.#e,node:P.cloneWithTableProps(this.#e.node,{dropConstraint:H.cloneWith(this.#e.node.dropConstraint,{modifier:`restrict`})})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(e){await this.#e.executor.executeQuery(this.compile(),e)}},K=A({is(e){return e.kind===`PrimaryKeyConstraintNode`},create(e,t){return A({kind:`PrimaryKeyConstraintNode`,columns:A(e.map(u.create)),name:t?v.create(t):void 0})},cloneWith(e,t){return A({...e,...t})}}),q=A({is(e){return e.kind===`AddIndexNode`},create(e){return A({kind:`AddIndexNode`,name:v.create(e)})},cloneWith(e,t){return A({...e,...t})},cloneWithColumns(e,t){return A({...e,columns:[...e.columns||[],...t]})}}),Xe=class e{#e;constructor(e){this.#e=A(e)}unique(){return new e({...this.#e,node:P.cloneWithTableProps(this.#e.node,{addIndex:q.cloneWith(this.#e.node.addIndex,{unique:!0})})})}column(t){return new e({...this.#e,node:P.cloneWithTableProps(this.#e.node,{addIndex:q.cloneWithColumns(this.#e.node.addIndex,[O(t)?re(t):t.toOperationNode()])})})}columns(t){return new e({...this.#e,node:P.cloneWithTableProps(this.#e.node,{addIndex:q.cloneWithColumns(this.#e.node.addIndex,t.map(e=>O(e)?re(e):e.toOperationNode()))})})}expression(t){return new e({...this.#e,node:P.cloneWithTableProps(this.#e.node,{addIndex:q.cloneWithColumns(this.#e.node.addIndex,[t.toOperationNode()])})})}using(t){return new e({...this.#e,node:P.cloneWithTableProps(this.#e.node,{addIndex:q.cloneWith(this.#e.node.addIndex,{using:_.createWithSql(t)})})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(e){await this.#e.executor.executeQuery(this.compile(),e)}},Ze=class e{#e;constructor(e){this.#e=e}nullsNotDistinct(){return new e(V.cloneWith(this.#e,{nullsNotDistinct:!0}))}deferrable(){return new e(V.cloneWith(this.#e,{deferrable:!0}))}notDeferrable(){return new e(V.cloneWith(this.#e,{deferrable:!1}))}initiallyDeferred(){return new e(V.cloneWith(this.#e,{initiallyDeferred:!0}))}initiallyImmediate(){return new e(V.cloneWith(this.#e,{initiallyDeferred:!1}))}$call(e){return e(this)}toOperationNode(){return this.#e}},Qe=class e{#e;constructor(e){this.#e=e}deferrable(){return new e(K.cloneWith(this.#e,{deferrable:!0}))}notDeferrable(){return new e(K.cloneWith(this.#e,{deferrable:!1}))}initiallyDeferred(){return new e(K.cloneWith(this.#e,{initiallyDeferred:!0}))}initiallyImmediate(){return new e(K.cloneWith(this.#e,{initiallyDeferred:!1}))}$call(e){return e(this)}toOperationNode(){return this.#e}},$e=class{#e;constructor(e){this.#e=e}$call(e){return e(this)}toOperationNode(){return this.#e}},et=A({is(e){return e.kind===`RenameConstraintNode`},create(e,t){return A({kind:`RenameConstraintNode`,oldName:v.create(e),newName:v.create(t)})}}),tt=class e{#e;constructor(e){this.#e=A({...e})}ifExists(){return new e({...this.#e,node:Fe.cloneWith(this.#e.node,{ifExists:!0})})}toOperationNode(){return this.#e.node}},nt=class{#e;constructor(e){this.#e=A(e)}renameTo(e){return new G({...this.#e,node:P.cloneWithTableProps(this.#e.node,{renameTo:M(e)})})}setSchema(e){return new G({...this.#e,node:P.cloneWithTableProps(this.#e.node,{setSchema:v.create(e)})})}alterColumn(e,t){let n=t(new qe(e));return new J({...this.#e,node:P.cloneWithColumnAlteration(this.#e.node,n.toOperationNode())})}dropColumn(e,t=E){let n=t(new tt({node:Fe.create(e)}));return new J({...this.#e,node:P.cloneWithColumnAlteration(this.#e.node,n.toOperationNode())})}renameColumn(e,t){return new J({...this.#e,node:P.cloneWithColumnAlteration(this.#e.node,Ie.create(e,t))})}addColumn(e,t,n=E){let r=n(new R(L.create(e,k(t))));return new J({...this.#e,node:P.cloneWithColumnAlteration(this.#e.node,Pe.create(r.toOperationNode()))})}modifyColumn(e,t,n=E){let r=n(new R(L.create(e,k(t))));return new J({...this.#e,node:P.cloneWithColumnAlteration(this.#e.node,Ge.create(r.toOperationNode()))})}addUniqueConstraint(e,t,n=E){let r=n(new Ze(V.create(t.map(e=>O(e)?u.create(e):T(e)),e)));return new G({...this.#e,node:P.cloneWithTableProps(this.#e.node,{addConstraint:B.create(r.toOperationNode())})})}addCheckConstraint(e,t,n=E){let r=n(new $e(Le.create(t.toOperationNode(),e)));return new G({...this.#e,node:P.cloneWithTableProps(this.#e.node,{addConstraint:B.create(r.toOperationNode())})})}addForeignKeyConstraint(e,t,n,r,i=E){let a=i(new Ke(z.create(t.map(u.create),M(n),r.map(u.create),e)));return new Je({...this.#e,constraintBuilder:a})}addPrimaryKeyConstraint(e,t,n=E){let r=n(new Qe(K.create(t,e)));return new G({...this.#e,node:P.cloneWithTableProps(this.#e.node,{addConstraint:B.create(r.toOperationNode())})})}dropConstraint(e){return new Ye({...this.#e,node:P.cloneWithTableProps(this.#e.node,{dropConstraint:H.create(e)})})}renameConstraint(e,t){return new Ye({...this.#e,node:P.cloneWithTableProps(this.#e.node,{renameConstraint:et.create(e,t)})})}addIndex(e){return new Xe({...this.#e,node:P.cloneWithTableProps(this.#e.node,{addIndex:q.create(e)})})}dropIndex(e){return new G({...this.#e,node:P.cloneWithTableProps(this.#e.node,{dropIndex:I.create(e)})})}$call(e){return e(this)}},J=class e{#e;constructor(e){this.#e=A(e)}alterColumn(t,n){let r=n(new qe(t));return new e({...this.#e,node:P.cloneWithColumnAlteration(this.#e.node,r.toOperationNode())})}dropColumn(t,n=E){let r=n(new tt({node:Fe.create(t)}));return new e({...this.#e,node:P.cloneWithColumnAlteration(this.#e.node,r.toOperationNode())})}renameColumn(t,n){return new e({...this.#e,node:P.cloneWithColumnAlteration(this.#e.node,Ie.create(t,n))})}addColumn(t,n,r=E){let i=r(new R(L.create(t,k(n))));return new e({...this.#e,node:P.cloneWithColumnAlteration(this.#e.node,Pe.create(i.toOperationNode()))})}modifyColumn(t,n,r=E){let i=r(new R(L.create(t,k(n))));return new e({...this.#e,node:P.cloneWithColumnAlteration(this.#e.node,Ge.create(i.toOperationNode()))})}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(e){await this.#e.executor.executeQuery(this.compile(),e)}},rt=class extends we{transformPrimitiveValueList(e){return ve.create(e.values.map(l.createImmediate))}transformValue(e){return l.createImmediate(e.value)}},it=class e{#e;constructor(e){this.#e=A(e)}ifNotExists(){return new e({...this.#e,node:F.cloneWith(this.#e.node,{ifNotExists:!0})})}unique(){return new e({...this.#e,node:F.cloneWith(this.#e.node,{unique:!0})})}nullsNotDistinct(){return new e({...this.#e,node:F.cloneWith(this.#e.node,{nullsNotDistinct:!0})})}on(t){return new e({...this.#e,node:F.cloneWith(this.#e.node,{table:M(t)})})}column(t){return new e({...this.#e,node:F.cloneWithColumns(this.#e.node,[O(t)?re(t):t.toOperationNode()])})}columns(t){return new e({...this.#e,node:F.cloneWithColumns(this.#e.node,t.map(e=>O(e)?re(e):e.toOperationNode()))})}expression(t){return new e({...this.#e,node:F.cloneWithColumns(this.#e.node,[t.toOperationNode()])})}using(t){return new e({...this.#e,node:F.cloneWith(this.#e.node,{using:_.createWithSql(t)})})}where(...t){let n=new rt;return new e({...this.#e,node:ie.cloneWithWhere(this.#e.node,n.transformNode(ye(t),this.#e.queryId))})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(e){await this.#e.executor.executeQuery(this.compile(),e)}},at=class e{#e;constructor(e){this.#e=A(e)}ifNotExists(){return new e({...this.#e,node:je.cloneWith(this.#e.node,{ifNotExists:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(e){await this.#e.executor.executeQuery(this.compile(),e)}};function ot(e){if(h.includes(e))return e;throw Error(`invalid OnCommitAction ${e}`)}var st=class e{#e;constructor(e){this.#e=e}using(t){return new e(q.cloneWith(this.#e,{using:_.createWithSql(t)}))}$call(e){return e(this)}toOperationNode(){return this.#e}},ct=class e{#e;constructor(e){this.#e=A(e)}temporary(){return new e({...this.#e,node:S.cloneWith(this.#e.node,{temporary:!0})})}onCommit(t){return new e({...this.#e,node:S.cloneWith(this.#e.node,{onCommit:ot(t)})})}ifNotExists(){return new e({...this.#e,node:S.cloneWith(this.#e.node,{ifNotExists:!0})})}addColumn(t,n,r=E){let i=r(new R(L.create(t,k(n))));return new e({...this.#e,node:S.cloneWithColumn(this.#e.node,i.toOperationNode())})}addPrimaryKeyConstraint(t,n,r=E){let i=r(new Qe(K.create(n,t)));return new e({...this.#e,node:S.cloneWithConstraint(this.#e.node,i.toOperationNode())})}addUniqueConstraint(t,n,r=E){let i=r(new Ze(V.create(n.map(e=>O(e)?u.create(e):T(e)),t)));return new e({...this.#e,node:S.cloneWithConstraint(this.#e.node,i.toOperationNode())})}addIndex(t,n,r=E){let i=r(new st(q.cloneWithColumns(q.create(t),n.map(e=>O(e)?u.create(e):T(e)))));return new e({...this.#e,node:S.cloneWithIndex(this.#e.node,i.toOperationNode())})}addCheckConstraint(t,n,r=E){let i=r(new $e(Le.create(n.toOperationNode(),t)));return new e({...this.#e,node:S.cloneWithConstraint(this.#e.node,i.toOperationNode())})}addForeignKeyConstraint(t,n,r,i,a=E){let o=a(new Ke(z.create(n.map(u.create),M(r),i.map(u.create),t)));return new e({...this.#e,node:S.cloneWithConstraint(this.#e.node,o.toOperationNode())})}modifyFront(t){return new e({...this.#e,node:S.cloneWithFrontModifier(this.#e.node,t.toOperationNode())})}modifyEnd(t){return new e({...this.#e,node:S.cloneWithEndModifier(this.#e.node,t.toOperationNode())})}as(t){return new e({...this.#e,node:S.cloneWith(this.#e.node,{selectQuery:T(t)})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(e){await this.#e.executor.executeQuery(this.compile(),e)}},lt=class e{#e;constructor(e){this.#e=A(e)}on(t){return new e({...this.#e,node:I.cloneWith(this.#e.node,{table:M(t)})})}ifExists(){return new e({...this.#e,node:I.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new e({...this.#e,node:I.cloneWith(this.#e.node,{cascade:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(e){await this.#e.executor.executeQuery(this.compile(),e)}},ut=class e{#e;constructor(e){this.#e=A(e)}ifExists(){return new e({...this.#e,node:Me.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new e({...this.#e,node:Me.cloneWith(this.#e.node,{cascade:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(e){await this.#e.executor.executeQuery(this.compile(),e)}},dt=class e{#e;constructor(e){this.#e=A(e)}temporary(){return new e({...this.#e,node:Ne.cloneWith(this.#e.node,{temporary:!0})})}ifExists(){return new e({...this.#e,node:Ne.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new e({...this.#e,node:Ne.cloneWith(this.#e.node,{cascade:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(e){await this.#e.executor.executeQuery(this.compile(),e)}},ft=class{#e=new rt;transformQuery(e){return this.#e.transformNode(e.node,e.queryId)}transformResult(e){return Promise.resolve(e.result)}},pt=class e{#e;constructor(e){this.#e=A(e)}temporary(){return new e({...this.#e,node:D.cloneWith(this.#e.node,{temporary:!0})})}materialized(){return new e({...this.#e,node:D.cloneWith(this.#e.node,{materialized:!0})})}ifNotExists(){return new e({...this.#e,node:D.cloneWith(this.#e.node,{ifNotExists:!0})})}orReplace(){return new e({...this.#e,node:D.cloneWith(this.#e.node,{orReplace:!0})})}columns(t){return new e({...this.#e,node:D.cloneWith(this.#e.node,{columns:t.map(ne)})})}as(t){let n=t.withPlugin(new ft).toOperationNode();return new e({...this.#e,node:D.cloneWith(this.#e.node,{as:n})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(e){await this.#e.executor.executeQuery(this.compile(),e)}},mt=A({is(e){return e.kind===`DropViewNode`},create(e){return A({kind:`DropViewNode`,name:x.create(e)})},cloneWith(e,t){return A({...e,...t})}}),ht=class e{#e;constructor(e){this.#e=A(e)}materialized(){return new e({...this.#e,node:mt.cloneWith(this.#e.node,{materialized:!0})})}ifExists(){return new e({...this.#e,node:mt.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new e({...this.#e,node:mt.cloneWith(this.#e.node,{cascade:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(e){await this.#e.executor.executeQuery(this.compile(),e)}},gt=A({is(e){return e.kind===`CreateTypeNode`},create(e){return A({kind:`CreateTypeNode`,name:e})},cloneWithEnum(e,t){return A({...e,enum:ve.create(t.map(l.createImmediate))})}}),_t=class e{#e;constructor(e){this.#e=A(e)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}asEnum(t){return new e({...this.#e,node:gt.cloneWithEnum(this.#e.node,t)})}$call(e){return e(this)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(e){await this.#e.executor.executeQuery(this.compile(),e)}},vt=A({is(e){return e.kind===`DropTypeNode`},create(e){return Array.isArray(e)||(e=[e]),A({kind:`DropTypeNode`,name:e[0],additionalNames:e.slice(1)})},cloneWith(e,t){return A({...e,...t})}}),yt=class e{#e;constructor(e){this.#e=A(e)}ifExists(){return new e({...this.#e,node:vt.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new e({...this.#e,node:vt.cloneWith(this.#e.node,{cascade:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(e){await this.#e.executor.executeQuery(this.compile(),e)}};function bt(e){if(e.includes(`.`)){let t=e.split(`.`).map(St);if(t.length===2)return x.createWithSchema(t[0],t[1]);throw Error(`invalid schemable identifier ${e}`)}return x.create(e)}function xt(e){return Array.isArray(e)||(e=[e]),e.map(bt)}function St(e){return e.trim()}var Ct=A({is(e){return e.kind===`RefreshMaterializedViewNode`},create(e){return A({kind:`RefreshMaterializedViewNode`,name:x.create(e)})},cloneWith(e,t){return A({...e,...t})}}),wt=class e{#e;constructor(e){this.#e=A(e)}concurrently(){return new e({...this.#e,node:Ct.cloneWith(this.#e.node,{concurrently:!0,withNoData:!1})})}withData(){return new e({...this.#e,node:Ct.cloneWith(this.#e.node,{withNoData:!1})})}withNoData(){return new e({...this.#e,node:Ct.cloneWith(this.#e.node,{withNoData:!0,concurrently:!1})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(e){await this.#e.executor.executeQuery(this.compile(),e)}},Y=A({is(e){return e.kind===`AlterTypeNode`},create(e){return A({kind:`AlterTypeNode`,name:e})},cloneWith(e,t){return A({...e,...t})}}),Tt=A({is(e){return e.kind===`AddValueNode`},create(e){return A({kind:`AddValueNode`,value:e})},cloneWith(e,t){return A({...e,...t})}}),Et=class{#e;constructor(e){this.#e=A(e)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(e){return await this.#e.executor.executeQuery(this.compile(),e)}},Dt,Ot=class extends Et{#e;constructor(e){super(e),this.#e=e}ifNotExists(){return new Dt({...this.#e,node:Y.cloneWith(this.#e.node,{addValue:Tt.cloneWith(this.#e.node.addValue,{ifNotExists:!0})})})}before(e){return this.#t(e,!0)}after(e){return this.#t(e,!1)}#t(e,t){return new Dt({...this.#e,node:Y.cloneWith(this.#e.node,{addValue:Tt.cloneWith(this.#e.node.addValue,{isBefore:t,neighborValue:l.createImmediate(e)})})})}};Dt=Ot;var kt=A({is(e){return e.kind===`RenameValueNode`},create(e,t){return A({kind:`RenameValueNode`,oldValue:e,newValue:t})}}),At=class{#e;constructor(e){this.#e=A(e)}addValue(e){return new Ot({...this.#e,node:Y.cloneWith(this.#e.node,{addValue:Tt.create(l.createImmediate(e))})})}renameTo(e){return new Et({...this.#e,node:Y.cloneWith(this.#e.node,{renameTo:v.create(e)})})}renameValue(e,t){return new Et({...this.#e,node:Y.cloneWith(this.#e.node,{renameValue:kt.create(l.createImmediate(e),l.createImmediate(t))})})}setSchema(e){return new Et({...this.#e,node:Y.cloneWith(this.#e.node,{setSchema:v.create(e)})})}},jt=class e{#e;constructor(e){this.#e=e}createTable(e){return new ct({queryId:b(),executor:this.#e,node:S.create(M(e))})}dropTable(e){return new dt({queryId:b(),executor:this.#e,node:Ne.create(M(e))})}createIndex(e){return new it({queryId:b(),executor:this.#e,node:F.create(e)})}dropIndex(e){return new lt({queryId:b(),executor:this.#e,node:I.create(e)})}createSchema(e){return new at({queryId:b(),executor:this.#e,node:je.create(e)})}dropSchema(e){return new ut({queryId:b(),executor:this.#e,node:Me.create(e)})}alterTable(e){return new nt({queryId:b(),executor:this.#e,node:P.create(M(e))})}createView(e){return new pt({queryId:b(),executor:this.#e,node:D.create(e)})}refreshMaterializedView(e){return new wt({queryId:b(),executor:this.#e,node:Ct.create(e)})}dropView(e){return new ht({queryId:b(),executor:this.#e,node:mt.create(e)})}createType(e){return new _t({queryId:b(),executor:this.#e,node:gt.create(bt(e))})}alterType(e){return new At({executor:this.#e,node:Y.create(bt(e)),queryId:b()})}dropType(e){return new yt({queryId:b(),executor:this.#e,node:vt.create(xt(e))})}withPlugin(t){return new e(this.#e.withPlugin(t))}withoutPlugins(){return new e(this.#e.withoutPlugins())}withSchema(t){return new e(this.#e.withPluginAtFront(new d(t)))}},Mt=class{ref(e){return new te(e)}table(e){return new pe(e)}},Nt=class{#e;constructor(e){this.#e=e}async provideConnection(e,t){let n=await this.#e.acquireConnection(t);try{return await e(n)}finally{await this.#e.releaseConnection(n,t)}}},Pt=class e extends Ce{#e;#t;#n;constructor(e,t,n,r=[]){super(r),this.#e=e,this.#t=t,this.#n=n}get adapter(){return this.#t}compileQuery(e,t){return this.#e.compileQuery(e,t)}provideConnection(e,t){return this.#n.provideConnection(e,t)}withPlugins(t){return new e(this.#e,this.#t,this.#n,[...this.plugins,...t])}withPlugin(t){return new e(this.#e,this.#t,this.#n,[...this.plugins,t])}withPluginAtFront(t){return new e(this.#e,this.#t,this.#n,[t,...this.plugins])}withConnectionProvider(t){return new e(this.#e,this.#t,t,[...this.plugins])}withoutPlugins(){return new e(this.#e,this.#t,this.#n,[])}};function Ft(){return typeof performance<`u`&&y(performance.now)?performance.now():Date.now()}var It=class{#e;#t;async obtainLock(){for(;this.#e;)await this.#e;this.#e=new Promise(e=>{this.#t=e})}releaseLock(){let e=this.#t;this.#e=void 0,this.#t=void 0,e?.()}},Lt=class{#e;#t;#n;#r;#i;#a=new WeakSet;#o;constructor(e,t,n){this.#e=e,this.#r=!1,this.#t=n,t.supportsMultipleConnections===!1&&(this.#o=new It)}async init(e){if(this.#i)throw Error(`driver has already been destroyed`);this.#n??=this.#e.init(e).then(()=>{this.#r=!0}).catch(e=>{throw this.#n=void 0,e}),await C(this.#n,e?.signal,`init`)}async acquireConnection(e){if(this.#i)throw Error(`driver has already been destroyed`);if(this.#r||await this.init(e),this.#o){let t=this.#o.obtainLock();await C(t,e?.signal,`acquireConnection:mutex`,()=>t.then(()=>this.#o?.releaseLock()))}let t=this.#e.acquireConnection(e),n=await C(t,e?.signal,`acquireConnection:acquire`,()=>t?.then(e=>this.releaseConnection(e).catch(Ee(`driver.releaseConnection`))).catch(Ee(`driver.acquireConnection`)));return this.#a.has(n)||(this.#s()&&this.#c(n),this.#a.add(n)),n}async releaseConnection(e,t){await this.#e.releaseConnection(e,t),this.#o?.releaseLock()}async beginTransaction(e,t){return await this.#e.beginTransaction(e,t)}async commitTransaction(e){return await this.#e.commitTransaction(e)}async rollbackTransaction(e){return await this.#e.rollbackTransaction(e)}async savepoint(e,t,n){if(this.#e.savepoint)return await this.#e.savepoint(e,t,n);throw Error("The `savepoint` method is not supported by this driver")}async rollbackToSavepoint(e,t,n){if(this.#e.rollbackToSavepoint)return await this.#e.rollbackToSavepoint(e,t,n);throw Error("The `rollbackToSavepoint` method is not supported by this driver")}async releaseSavepoint(e,t,n){if(this.#e.releaseSavepoint)return await this.#e.releaseSavepoint(e,t,n);throw Error("The `releaseSavepoint` method is not supported by this driver")}async destroy(e){this.#n&&(await C(this.#n,e?.signal,`destroy:initPromise`),this.#i??=this.#e.destroy(e).catch(e=>{throw this.#i=void 0,e}),await C(this.#i,e?.signal,`destroy`))}#s(){return this.#t.isLevelEnabled(`query`)||this.#t.isLevelEnabled(`error`)}#c(e){let t=e.executeQuery,n=e.streamQuery,r=this;e.executeQuery=async(n,i)=>{let a,o=Ft();try{return await t.call(e,n,i)}catch(e){throw a=e,await r.#l(e,n,o),e}finally{a||await r.#u(n,o)}},e.streamQuery=async function*(t,i,a){let o,s=Ft();try{for await(let r of n.call(e,t,i,a))yield r}catch(e){throw o=e,await r.#l(e,t,s),e}finally{o||await r.#u(t,s,!0)}}}async#l(e,t,n){await this.#t.error(()=>({level:`error`,error:e,query:t,queryDurationMillis:this.#d(n)}))}async#u(e,t,n=!1){await this.#t.query(()=>({level:`query`,isStream:n,query:e,queryDurationMillis:this.#d(t)}))}#d(e){return Ft()-e}},Rt=()=>{},zt=class{#e;#t;constructor(e){this.#e=e}async provideConnection(e){for(;this.#t;)await this.#t.catch(Rt);return this.#t=this.#n(e).finally(()=>{this.#t=void 0}),this.#t}async#n(e){return await e(this.#e)}},Bt=[`read only`,`read write`],Vt=[`read uncommitted`,`read committed`,`repeatable read`,`serializable`,`snapshot`];function Ht(e){if(e.accessMode&&!Bt.includes(e.accessMode))throw Error(`invalid transaction access mode ${e.accessMode}`);if(e.isolationLevel&&!Vt.includes(e.isolationLevel))throw Error(`invalid transaction isolation level ${e.isolationLevel}`)}A([`query`,`error`]);var Ut=class{#e;#t;constructor(e){y(e)?(this.#t=e,this.#e=A({query:!0,error:!0})):(this.#t=Wt,this.#e=A({query:e.includes(`query`),error:e.includes(`error`)}))}isLevelEnabled(e){return this.#e[e]}async query(e){this.#e.query&&await this.#t(e())}async error(e){this.#e.error&&await this.#t(e())}};function Wt(e){if(e.level===`query`){let t=`kysely:query:${e.isStream?`stream:`:``}`;console.log(`${t} ${e.query.sql}`),console.log(`${t} duration: ${e.queryDurationMillis.toFixed(1)}ms`)}else e.level===`error`&&(e.error instanceof Error?console.error(`kysely:error: ${e.error.stack??e.error.message}`):console.error(`kysely:error: ${JSON.stringify({error:e.error,query:e.query.sql,queryDurationMillis:e.queryDurationMillis})}`))}function Gt(e){return j(e)&&y(e.compile)}Symbol.asyncDispose??=Symbol(`Symbol.asyncDispose`);var Kt=class e extends fe{#e;constructor(e){let t,n;if(Jt(e))t={executor:e.executor},n={...e};else{let r=e.dialect,i=r.createDriver(),a=r.createQueryCompiler(),o=r.createAdapter(),s=new Lt(i,o,new Ut(e.log??[])),c=new Pt(a,o,new Nt(s),e.plugins??[]);t={executor:c},n={config:e,executor:c,dialect:r,driver:s}}super(t),this.#e=A(n)}get schema(){return new jt(this.#e.executor)}get dynamic(){return new Mt}get introspection(){return this.#e.dialect.createIntrospector(this.withoutPlugins())}case(e){return new be({node:ge.create(xe(e)?void 0:T(e))})}get fn(){return he()}transaction(){return new Xt({...this.#e})}startTransaction(){return new Zt({...this.#e})}connection(){return new Yt({...this.#e})}withPlugin(t){return new e({...this.#e,executor:this.#e.executor.withPlugin(t)})}withoutPlugins(){return new e({...this.#e,executor:this.#e.executor.withoutPlugins()})}withSchema(t){return new e({...this.#e,executor:this.#e.executor.withPluginAtFront(new d(t))})}$extendTables(){return new e({...this.#e})}$omitTables(){return new e({...this.#e})}$pickTables(){return new e({...this.#e})}withTables(){return this.$extendTables()}async destroy(){await this.#e.driver.destroy()}get isTransaction(){return!1}getExecutor(){return this.#e.executor}async executeQuery(e,t){let n=Gt(e)?e.compile():e;return await this.#e.executor.executeQuery(n,t)}async[Symbol.asyncDispose](){await this.destroy()}},qt=class e extends Kt{#e;constructor(e){super(e),this.#e=e}get isTransaction(){return!0}transaction(){throw Error(`calling the transaction method for a Transaction is not supported`)}startTransaction(){throw Error(`calling the controlled transaction method for a Transaction is not supported`)}connection(){throw Error(`calling the connection method for a Transaction is not supported`)}destroy(){throw Error(`calling the destroy method for a Transaction is not supported`)}withPlugin(t){return new e({...this.#e,executor:this.#e.executor.withPlugin(t)})}withoutPlugins(){return new e({...this.#e,executor:this.#e.executor.withoutPlugins()})}withSchema(t){return new e({...this.#e,executor:this.#e.executor.withPluginAtFront(new d(t))})}withTables(){return new e({...this.#e})}$extendTables(){return new e({...this.#e})}$omitTables(){return new e({...this.#e})}$pickTables(){return new e({...this.#e})}};function Jt(e){return j(e)&&j(e.config)&&j(e.driver)&&j(e.executor)&&j(e.dialect)}var Yt=class{#e;constructor(e){this.#e=A(e)}async execute(e,t){return this.#e.executor.provideConnection(async t=>{let n=this.#e.executor.withConnectionProvider(new zt(t));return await e(new Kt({...this.#e,executor:n}))},A({signal:t?.signal}))}},Xt=class e{#e;constructor(e){this.#e=A(e)}setAccessMode(t){return new e({...this.#e,accessMode:t})}setIsolationLevel(t){return new e({...this.#e,isolationLevel:t})}async execute(e){let{isolationLevel:t,accessMode:n,...r}=this.#e,i={isolationLevel:t,accessMode:n};return Ht(i),this.#e.executor.provideConnection(async t=>{let n={isCommitted:!1,isRolledBack:!1},a=new $t(this.#e.executor.withConnectionProvider(new zt(t)),n),o=new qt({...r,executor:a}),s=!1;try{await this.#e.driver.beginTransaction(t,i),s=!0;let r=await e(o);return await this.#e.driver.commitTransaction(t),n.isCommitted=!0,r}catch(e){throw s&&(await this.#e.driver.rollbackTransaction(t),n.isRolledBack=!0),e}})}},Zt=class e{#e;constructor(e){this.#e=A(e)}setAccessMode(t){return new e({...this.#e,accessMode:t})}setIsolationLevel(t){return new e({...this.#e,isolationLevel:t})}async execute(){let{isolationLevel:e,accessMode:t,...n}=this.#e,r={isolationLevel:e,accessMode:t};Ht(r);let i=await Te(this.#e.executor);return await this.#e.driver.beginTransaction(i.connection,r),new Qt({...n,connection:i,executor:this.#e.executor.withConnectionProvider(new zt(i.connection))})}},Qt=class e extends qt{#e;#t;#n;constructor(e){let t={isCommitted:!1,isRolledBack:!1};e={...e,executor:new $t(e.executor,t)};let{connection:n,...r}=e;super(r),this.#e=A(e),this.#n=t;let i=b();this.#t=t=>e.executor.compileQuery(t,i)}get isCommitted(){return this.#n.isCommitted}get isRolledBack(){return this.#n.isRolledBack}commit(){return Z(this.#n),new X(async()=>{await this.#e.driver.commitTransaction(this.#e.connection.connection),this.#n.isCommitted=!0,this.#e.connection.release()})}rollback(){return Z(this.#n),new X(async()=>{await this.#e.driver.rollbackTransaction(this.#e.connection.connection),this.#n.isRolledBack=!0,this.#e.connection.release()})}savepoint(t){return Z(this.#n),new X(async()=>(await this.#e.driver.savepoint?.(this.#e.connection.connection,t,this.#t),new e({...this.#e})))}rollbackToSavepoint(t){return Z(this.#n),new X(async()=>(await this.#e.driver.rollbackToSavepoint?.(this.#e.connection.connection,t,this.#t),new e({...this.#e})))}releaseSavepoint(t){return Z(this.#n),new X(async()=>(await this.#e.driver.releaseSavepoint?.(this.#e.connection.connection,t,this.#t),new e({...this.#e})))}withPlugin(t){return new e({...this.#e,executor:this.#e.executor.withPlugin(t)})}withoutPlugins(){return new e({...this.#e,executor:this.#e.executor.withoutPlugins()})}withSchema(t){return new e({...this.#e,executor:this.#e.executor.withPluginAtFront(new d(t))})}withTables(){return new e({...this.#e})}$extendTables(){return new e({...this.#e})}$omitTables(){return new e({...this.#e})}$pickTables(){return new e({...this.#e})}},X=class{#e;constructor(e){this.#e=e}async execute(){return await this.#e()}};function Z(e){if(e.isCommitted)throw Error(`Transaction is already committed`);if(e.isRolledBack)throw Error(`Transaction is already rolled back`)}var $t=class e{#e;#t;constructor(t,n){this.#e=t instanceof e?t.#e:t,this.#t=n}get adapter(){return this.#e.adapter}get plugins(){return this.#e.plugins}transformQuery(e,t){return this.#e.transformQuery(e,t)}compileQuery(e,t){return this.#e.compileQuery(e,t)}provideConnection(e,t){return this.#e.provideConnection(e,t)}executeQuery(e,t){return Z(this.#t),this.#e.executeQuery(e,t)}stream(e,t,n){return Z(this.#t),this.#e.stream(e,t,n)}withConnectionProvider(t){return new e(this.#e.withConnectionProvider(t),this.#t)}withPlugin(t){return new e(this.#e.withPlugin(t),this.#t)}withPlugins(t){return new e(this.#e.withPlugins(t),this.#t)}withPluginAtFront(t){return new e(this.#e.withPluginAtFront(t),this.#t)}withoutPlugins(){return new e(this.#e.withoutPlugins(),this.#t)}};function Q(e,t){return _.createWithChildren([_.createWithSql(`${e} `),v.create(t)])}var en=class{#e;#t;#n;constructor(e){this.#e=A({...e})}async init(e){this.#t=y(this.#e.database)?await this.#e.database(e):this.#e.database,this.#n=new tn(this.#t),this.#e.onCreateConnection&&await this.#e.onCreateConnection(this.#n,e)}async acquireConnection(){return this.#n}async beginTransaction(e){await e.executeQuery(N.raw(`begin`))}async commitTransaction(e){await e.executeQuery(N.raw(`commit`))}async rollbackTransaction(e){await e.executeQuery(N.raw(`rollback`))}async savepoint(e,t,n){await e.executeQuery(n(Q(`savepoint`,t),b()))}async rollbackToSavepoint(e,t,n){await e.executeQuery(n(Q(`rollback to`,t),b()))}async releaseSavepoint(e,t,n){await e.executeQuery(n(Q(`release`,t),b()))}async releaseConnection(){}async destroy(){this.#t?.close()}},tn=class{#e;constructor(e){this.#e=e}async executeQuery(e){let{sql:t,parameters:n}=e,r=this.#e.prepare(t);if(r.reader)return{rows:r.all(n)};let{changes:i,lastInsertRowid:a}=r.run(n);return{insertId:a==null?void 0:BigInt(a),numAffectedRows:i==null?void 0:BigInt(i),rows:[]}}async*streamQuery(e,t){let{sql:n,parameters:r,query:i}=e,a=this.#e.prepare(n);if(!f.is(i))throw Error(`Sqlite driver only supports streaming of select queries`);let o=a.iterate(r);for(let e of o)yield{rows:[e]}}},$=`kysely_migration`,nn=`kysely_migration_lock`;A({__noMigrations__:!0});var rn=class{#e;constructor(e){this.#e=e}async getSchemas(){return[]}async getTables(e={withInternalKyselyTables:!1}){return await this.#n(e)}#t(e,t){let n=e.selectFrom(`sqlite_master`).where(`type`,`in`,[`table`,`view`]).where(`name`,`not like`,`sqlite_%`).select([`name`,`sql`,`type`]).orderBy(`name`);return t.withInternalKyselyTables||(n=n.where(`name`,`!=`,$).where(`name`,`!=`,nn)),n}async#n(e){let t=await this.#t(this.#e,e).execute(),n=await this.#e.with(`table_list`,t=>this.#t(t,e)).selectFrom([`table_list as tl`,w`pragma_table_info(tl.name)`.as(`p`)]).select([`tl.name as table`,`p.cid`,`p.name`,`p.type`,`p.notnull`,`p.dflt_value`,`p.pk`]).orderBy(`tl.name`).orderBy(`p.cid`).execute(),r={};for(let e of n)r[e.table]??=[],r[e.table].push(e);return t.map(({name:e,sql:t,type:n})=>{let i=t?.split(/[\(\),]/)?.find(e=>e.toLowerCase().includes(`autoincrement`))?.trimStart()?.split(/\s+/)?.[0]?.replace(/["`]/g,``),a=r[e]??[];if(!i){let e=a.filter(e=>e.pk>0);e.length===1&&e[0].type.toLowerCase()===`integer`&&(i=e[0].name)}return{name:e,isView:n===`view`,isForeign:!1,columns:a.map(e=>({name:e.name,dataType:e.type,isNullable:!e.notnull,isAutoIncrementing:e.name===i,hasDefaultValue:e.dflt_value!=null,comment:void 0}))}})}},an=class{#e;constructor(e){this.#e=A({...e})}createDriver(){return new en(this.#e)}createQueryCompiler(){return new Oe}createAdapter(){return new Ae}createIntrospector(e){return new rn(e)}};function on(e,t){if(sn(e)&&t.stack){let n=t.stack.split(`
2
2
  `).slice(1).join(`
3
3
  `);return e.stack+=`\n${n}`,e}return e}function sn(e){return j(e)&&O(e.stack)}var cn=Symbol(),ln=class{#e;#t=new WeakMap;#n;constructor(e){this.#e=A({...e})}async init(e){this.#n=y(this.#e.pool)?await this.#e.pool(e):this.#e.pool}async acquireConnection(e){let t=await this.#r(),n=this.#t.get(t);return n||(n=new dn(t,this.#e.controlConnection),this.#t.set(t,n),this.#e?.onCreateConnection&&await this.#e.onCreateConnection(n,e)),this.#e?.onReserveConnection&&await this.#e.onReserveConnection(n,e),n}async beginTransaction(e,t){if(t.isolationLevel||t.accessMode){let n=[];t.isolationLevel&&n.push(`isolation level ${t.isolationLevel}`),t.accessMode&&n.push(t.accessMode);let r=`set transaction ${n.join(`, `)}`;await e.executeQuery(N.raw(r))}await e.executeQuery(N.raw(`begin`))}async commitTransaction(e){await e.executeQuery(N.raw(`commit`))}async rollbackTransaction(e){await e.executeQuery(N.raw(`rollback`))}async savepoint(e,t,n){await e.executeQuery(n(Q(`savepoint`,t),b()))}async rollbackToSavepoint(e,t,n){await e.executeQuery(n(Q(`rollback to`,t),b()))}async releaseSavepoint(e,t,n){await e.executeQuery(n(Q(`release savepoint`,t),b()))}async releaseConnection(e){e[cn]()}async destroy(){return new Promise((e,t)=>{this.#n.end(n=>{n?t(n):e()})})}async#r(){return new Promise((e,t)=>{this.#n.getConnection(async(n,r)=>{n?t(n):e(r)})})}};function un(e){return j(e)&&`insertId`in e&&`affectedRows`in e}var dn=class{#e;#t;#n;#r;constructor(e,t){this.#e=e,this.#t=t}async cancelQuery(e){await this.#a(`kill query ${this.#n}`,e)}async collectSessionInfo(){if(this.#n)return;let{threadId:e}=this.#e;if(e!=null)this.#n=e;else{let[{cid:e}]=await this.#i(N.raw(`select connection_id() as cid`));this.#n=Number(e)}}async executeQuery(e){try{this.#r=e.queryId;let t=await this.#i(e);if(!un(t))return{rows:Array.isArray(t)?t:[]};let{insertId:n,affectedRows:r,changedRows:i}=t;return{insertId:n!=null&&n.toString()!==`0`?BigInt(n):void 0,numAffectedRows:r==null?void 0:BigInt(r),numChangedRows:i==null?void 0:BigInt(i),rows:[]}}catch(e){throw on(e,Error())}finally{this.#r=void 0}}async killSession(e){try{this.#e.destroy()}catch{}await this.#a(`kill connection ${this.#n}`,e)}async*streamQuery(e,t){this.#r=e.queryId;let n=this.#e.query(e.sql,e.parameters).stream({objectMode:!0});try{for await(let e of n)yield{rows:[e]}}catch(e){if(j(e)&&`code`in e&&e.code===`ERR_STREAM_PREMATURE_CLOSE`)return;throw e}finally{this.#r=void 0}}[cn](){this.#e.release()}#i(e){return new Promise((t,n)=>{this.#e.query(e.sql,e.parameters,(e,r)=>{e?n(e):t(r)})})}async#a(e,t){if(!this.#r)return;let{config:n}=this.#e,r=this.#r;if(!this.#t||!n)return await t(async t=>{r.queryId===this.#r?.queryId&&await t.executeQuery(N.raw(e,[]))});let{clientFlags:i,maxPacketSize:a,...o}=n,s=this.#t(o);try{await new Promise((t,n)=>{s.connect(i=>{if(i)return n(i);if(r.queryId!==this.#r?.queryId)return t();s.query(e,[],e=>{if(e)return n(e);t()})})})}finally{s.destroy()}}},fn=/[\\']/g,pn=/`/g,mn=/[\\'"]/g,hn=class extends Se{getCurrentParameterPlaceholder(){return`?`}getLeftExplainOptionsWrapper(){return``}getExplainOptionAssignment(){return`=`}getExplainOptionsDelimiter(){return` `}getRightExplainOptionsWrapper(){return``}getLeftIdentifierWrapper(){return pn.source}getRightIdentifierWrapper(){return pn.source}sanitizeIdentifier(e){return e.replace(pn,"``")}sanitizeStringLiteral(e){return e.replace(fn,e=>e===`\\`?`\\\\`:`''`)}sanitizeJSONPathMemberValue(e){return e.replace(mn,e=>e===`\\`?`\\\\\\\\`:e===`'`?`''`:`\\\\"`)}visitCreateIndex(e){this.append(`create `),e.unique&&this.append(`unique `),this.append(`index `),e.ifNotExists&&this.append(`if not exists `),this.visitNode(e.name),e.using&&(this.append(` using `),this.visitNode(e.using)),e.table&&(this.append(` on `),this.visitNode(e.table)),e.columns&&(this.append(` (`),this.compileList(e.columns),this.append(`)`)),e.where&&(this.append(` `),this.visitNode(e.where))}},gn=class{#e;constructor(e){this.#e=e}async getSchemas(){return(await this.#e.selectFrom(`information_schema.schemata`).select(`schema_name`).$castTo().execute()).map(e=>({name:e.SCHEMA_NAME}))}async getTables(e={withInternalKyselyTables:!1}){let t=this.#e.selectFrom(`information_schema.columns as columns`).innerJoin(`information_schema.tables as tables`,e=>e.onRef(`columns.TABLE_CATALOG`,`=`,`tables.TABLE_CATALOG`).onRef(`columns.TABLE_SCHEMA`,`=`,`tables.TABLE_SCHEMA`).onRef(`columns.TABLE_NAME`,`=`,`tables.TABLE_NAME`)).select([`columns.COLUMN_NAME`,`columns.COLUMN_DEFAULT`,`columns.TABLE_NAME`,`columns.TABLE_SCHEMA`,`tables.TABLE_TYPE`,`tables.ENGINE`,`columns.IS_NULLABLE`,`columns.DATA_TYPE`,`columns.EXTRA`,`columns.COLUMN_COMMENT`]).where(`columns.TABLE_SCHEMA`,`=`,w`database()`).orderBy(`columns.TABLE_NAME`).orderBy(`columns.ORDINAL_POSITION`).$castTo();e.withInternalKyselyTables||(t=t.where(`columns.TABLE_NAME`,`!=`,$).where(`columns.TABLE_NAME`,`!=`,nn));let n=await t.execute();return this.#t(n)}#t(e){return e.reduce((e,t)=>{let n=e.find(e=>e.name===t.TABLE_NAME);return n||(n=A({name:t.TABLE_NAME,isView:t.TABLE_TYPE===`VIEW`,isForeign:t.ENGINE===`FEDERATED`,schema:t.TABLE_SCHEMA,columns:[]}),e.push(n)),n.columns.push(A({name:t.COLUMN_NAME,dataType:t.DATA_TYPE,isNullable:t.IS_NULLABLE===`YES`,isAutoIncrementing:t.EXTRA.toLowerCase().includes(`auto_increment`),hasDefaultValue:t.COLUMN_DEFAULT!==null,comment:t.COLUMN_COMMENT===``?void 0:t.COLUMN_COMMENT})),e},[])}},_n=`ea586330-2c93-47c8-908d-981d9d270f9d`,vn=3600,yn=class extends ke{get supportsTransactionalDdl(){return!1}get supportsReturning(){return!1}async acquireMigrationLock(e,t){await w`select get_lock(${w.lit(_n)}, ${w.lit(vn)})`.execute(e)}async releaseMigrationLock(e,t){await w`select release_lock(${w.lit(_n)})`.execute(e)}},bn=class{#e;constructor(e){this.#e=e}createDriver(){return new ln(this.#e)}createQueryCompiler(){return new hn}createAdapter(){return new yn}createIntrospector(e){return new gn(e)}},xn=Symbol(),Sn=class{#e;#t=new WeakMap;#n;constructor(e){this.#e=A({...e})}async init(e){this.#n=y(this.#e.pool)?await this.#e.pool(e):this.#e.pool}async acquireConnection(e){let t=await this.#n.connect(),n=this.#t.get(t);return n||(n=new Cn(t,{controlClient:this.#e.controlClient||this.#n.Client,cursor:this.#e.cursor??null,poolOptions:this.#n.options}),this.#t.set(t,n),this.#e.onCreateConnection&&await this.#e.onCreateConnection(n,e)),this.#e.onReserveConnection&&await this.#e.onReserveConnection(n,e),n}async beginTransaction(e,t){let n=`begin`;(t.isolationLevel||t.accessMode)&&(n=`start transaction`,t.isolationLevel&&(n+=` isolation level ${t.isolationLevel}`),t.accessMode&&(n+=` ${t.accessMode}`)),await e.executeQuery(N.raw(n))}async commitTransaction(e){await e.executeQuery(N.raw(`commit`))}async rollbackTransaction(e){await e.executeQuery(N.raw(`rollback`))}async savepoint(e,t,n){await e.executeQuery(n(Q(`savepoint`,t),b()))}async rollbackToSavepoint(e,t,n){await e.executeQuery(n(Q(`rollback to`,t),b()))}async releaseSavepoint(e,t,n){await e.executeQuery(n(Q(`release`,t),b()))}async releaseConnection(e){e[xn]()}async destroy(){if(this.#n){let e=this.#n;this.#n=void 0,await e.end()}}},Cn=class{#e;#t;#n;#r;constructor(e,t){this.#e=e,this.#t=t}async cancelQuery(e){return await this.#i(`select pg_cancel_backend(${this.#r})`,e)}async collectSessionInfo(){if(this.#r)return;let{processID:e}=this.#e;if(e)this.#r=e;else{let{rows:[{pid:e}]}=await this.#e.query(`select pg_backend_pid() as pid`,[]);this.#r=Number(e)}}async executeQuery(e){try{this.#n=e.queryId;let{command:t,rowCount:n,rows:r}=await this.#e.query(e.sql,e.parameters);return{numAffectedRows:t===`INSERT`||t===`UPDATE`||t===`DELETE`||t===`MERGE`?BigInt(n):void 0,rows:r??[]}}catch(e){throw on(e,Error())}finally{this.#n=void 0}}async killSession(e){return await this.#i(`select pg_terminate_backend(${this.#r})`,e)}async*streamQuery(e,t){if(!this.#t.cursor)throw Error("`cursor` is not present in your postgres dialect config. It's required to make streaming work in postgres.");this.#n=e.queryId;let n=this.#e.query(new this.#t.cursor(e.sql,e.parameters.slice()));try{for(;;){let e=await n.read(t);if(e.length===0)break;yield{rows:e}}}finally{await n.close(),this.#n=void 0}}[xn](){this.#e.release()}async#i(e,t){if(!this.#n)return;let{controlClient:n,poolOptions:r}=this.#t,i=this.#n;if(!n)return await t(async t=>{i.queryId===this.#n?.queryId&&await t.executeQuery(N.raw(e,[]))});let a=new n({...r,password:`password`in r?r.password:void 0});try{if(await a.connect(),i.queryId!==this.#n.queryId)return;await a.query(e,[])}finally{a.end()}}},wn=class{#e;constructor(e){this.#e=e}async getSchemas(){return(await this.#e.selectFrom(`pg_catalog.pg_namespace`).select(`nspname`).$castTo().execute()).map(e=>({name:e.nspname}))}async getTables(e={withInternalKyselyTables:!1}){let t=this.#e.selectFrom(`pg_catalog.pg_attribute as a`).innerJoin(`pg_catalog.pg_class as c`,`a.attrelid`,`c.oid`).innerJoin(`pg_catalog.pg_namespace as ns`,`c.relnamespace`,`ns.oid`).innerJoin(`pg_catalog.pg_type as typ`,`a.atttypid`,`typ.oid`).innerJoin(`pg_catalog.pg_namespace as dtns`,`typ.typnamespace`,`dtns.oid`).select([`a.attname as column`,`a.attnotnull as not_null`,`a.atthasdef as has_default`,`c.relname as table`,`c.relkind as table_type`,`ns.nspname as schema`,`typ.typname as type`,`dtns.nspname as type_schema`,w`col_description(a.attrelid, a.attnum)`.as(`column_description`),w`pg_get_serial_sequence(quote_ident(ns.nspname) || '.' || quote_ident(c.relname), a.attname)`.as(`auto_incrementing`)]).where(`c.relkind`,`in`,[`r`,`v`,`p`,`f`]).where(`ns.nspname`,`!~`,`^pg_`).where(`ns.nspname`,`!=`,`information_schema`).where(`ns.nspname`,`!=`,`crdb_internal`).where(w`has_schema_privilege(ns.nspname, 'USAGE')`).where(`a.attnum`,`>=`,0).where(`a.attisdropped`,`!=`,!0).orderBy(`ns.nspname`).orderBy(`c.relname`).orderBy(`a.attnum`).$castTo();e.withInternalKyselyTables||(t=t.where(`c.relname`,`!=`,$).where(`c.relname`,`!=`,nn));let n=await t.execute();return this.#t(n)}#t(e){let t=[],n=new Map;for(let r of e){let e=n.get(r.schema);e||(e=new Map,n.set(r.schema,e));let i=e.get(r.table);i||(i=A({columns:[],isForeign:r.table_type===`f`,isView:r.table_type===`v`,name:r.table,schema:r.schema}),e.set(r.table,i),t.push(i)),i.columns.push(A({comment:r.column_description??void 0,dataType:r.type,dataTypeSchema:r.type_schema,hasDefaultValue:r.has_default,isAutoIncrementing:r.auto_incrementing!==null,isNullable:!r.not_null,name:r.column}))}return t}},Tn=/"/g,En=class extends Se{sanitizeIdentifier(e){return e.replace(Tn,`""`)}},Dn=BigInt(`3853314791062309107`),On=36e5,kn=class extends ke{get supportsTransactionalDdl(){return!0}get supportsReturning(){return!0}async acquireMigrationLock(e,t){await w`
4
4
  with set_timeout as (
@@ -12,4 +12,4 @@ import{w as e,x as t}from"./get-id-field-OwLpfjj2.js";import{c as n,i as r,n as
12
12
  `.execute(e.withoutPlugins())).rows[0]?.schemaName||`dbo`}async function rr(e,t){if(t===`postgres`)return(await w`
13
13
  SELECT pg_catalog.current_schemas(true)::text[] AS schemas
14
14
  `.execute(e.withoutPlugins())).rows[0]?.schemas??[];if(t===`mssql`)return[await nr(e),`dbo`]}async function ir(e,t,r){let i=$n(e,r);return t===`sqlite`?n(i,Qn(await _e(e,Object.entries(i).flatMap(([e,t])=>t.disableMigrations?[]:[e])))):e.connection().execute(async e=>{let r=await rr(e,t),a=Qn(await e.introspection.getTables());for(let[e,t]of Object.entries(i))t.schema===void 0&&r&&(t.schema=r.find(t=>a.some(n=>n.name===e&&n.schema===t))??``);return n(i,a)})}var ar=(t,n)=>{let c=null,l=!1,u=(t,r=!1)=>({getFieldName:i,schema:a,getDefaultFieldName:o,getDefaultModelName:s,getFieldAttributes:c,getModelName:u,options:d})=>{n?.type===`mysql`&&d.advanced?.database?.generateId===!1&&!l&&(l=!0,e.warn(`[Kysely Adapter] MySQL does not support INSERT...RETURNING. With generateId set to false, the adapter uses best-effort fallback strategies (unique columns, full-field match) to retrieve inserted rows. For reliable behavior, use Better Auth's default ID generation, a custom generateId function, or generateId: "serial" for auto-increment.`));let f=e=>{let t=[],n=[];if(e)for(let[r,i]of Object.entries(e)){let e=a[i.modelKey??s(r)]?.fields,[o,c]=r.includes(`.`)?r.split(`.`):[void 0,r];if(e){e.id={type:`string`};for(let[i,a]of Object.entries(e))t.push(w`${w.ref(`join_${c}`)}.${w.ref(a.fieldName||i)} as ${w.ref(`_joined_${c}_${a.fieldName||i}`)}`),n.push({joinModel:r,joinModelRef:c,fieldName:a.fieldName||i})}}return{allSelectsStr:n,allSelects:t}},p=async(o,s,c,l,u)=>{if(n?.type===`mysql`){if(u.length>0){let e=await s.executeTakeFirst();if(!e||Number(e.numUpdatedRows??0)===0)return null;let n=u.find(e=>e.field===`id`&&(e.operator===void 0||e.operator===`eq`)&&e.connector!==`OR`&&e.value!==void 0&&e.value!==null),r,a;if(o.id!==void 0&&o.id!==null)r=`id`,a=o.id;else if(n)r=`id`,a=n.value;else if(u[0]?.field)r=u[0].field,a=o[r]===void 0?u[0].value:o[r];else return null;return await t.selectFrom(c).selectAll().where(i({model:l,field:r}),a===null?`is`:`=`,a).limit(1).executeTakeFirst()}await s.execute();let n=async t=>{if(o.id)return await t.selectFrom(c).selectAll().where(i({model:l,field:`id`}),`=`,o.id).limit(1).executeTakeFirst();if(d.advanced?.database?.generateId===`serial`){let e=(await w`SELECT LAST_INSERT_ID() as id`.execute(t)).rows[0]?.id;if(e)return await t.selectFrom(c).selectAll().where(i({model:l,field:`id`}),`=`,e).limit(1).executeTakeFirst()}let n=a[l]?.fields;if(n)for(let[e,r]of Object.entries(n)){if(!r.unique)continue;let n=i({model:l,field:e}),a=o[n];if(a==null)continue;let s=await t.selectFrom(c).selectAll().where(n,`=`,a).limit(1).executeTakeFirst();if(s)return s}let r=t.selectFrom(c).selectAll(),s=!1;for(let[e,t]of Object.entries(o))t!==void 0&&(r=r.where(e,t===null?`is`:`=`,t),s=!0);if(s){let e=await r.limit(2).execute();if(e.length===1)return e[0]}return e.warn(`[Kysely Adapter] Unable to safely identify the inserted "${c}" row on MySQL. Enable Better Auth ID generation or use generateId: "serial" for reliable behavior.`),null};return r?n(t):t.transaction().execute(n)}return n?.type===`mssql`?await s.outputAll(`inserted`).executeTakeFirst():await s.returningAll().executeTakeFirst()};function m(e,t,r){if(!r)return{and:null,or:null};let a={and:[],or:[]};return r.forEach(r=>{let{field:o,value:s,operator:c=`eq`,connector:l=`AND`,mode:u=`sensitive`}=r,d=s,f=i({model:t,field:o}),p=u===`insensitive`&&(typeof d==`string`||Array.isArray(d)&&d.every(e=>typeof e==`string`)),m=t=>{let r=`${e}.${f}`;if(c.toLowerCase()===`in`){if(p){let{lhs:e,values:n}=Jn(r,Array.isArray(d)?d:[d]);return t(e,`in`,n)}return t(r,`in`,Array.isArray(d)?d:[d])}if(c.toLowerCase()===`not_in`){if(p){let{lhs:e,values:n}=Yn(r,Array.isArray(d)?d:[d]);return t(e,`not in`,n)}return t(r,`not in`,Array.isArray(d)?d:[d])}if(c===`contains`)return p&&typeof d==`string`?qn(r,`%${d}%`,n?.type):t(r,`like`,`%${d}%`);if(c===`starts_with`)return p&&typeof d==`string`?qn(r,`${d}%`,n?.type):t(r,`like`,`${d}%`);if(c===`ends_with`)return p&&typeof d==`string`?qn(r,`%${d}`,n?.type):t(r,`like`,`%${d}`);if(c===`eq`){if(d===null)return t(r,`is`,null);if(p&&typeof d==`string`){let{lhs:e,value:n}=Xn(r,d);return t(e,`=`,n)}return t(r,`=`,d)}if(c===`ne`){if(d===null)return t(r,`is not`,null);if(p&&typeof d==`string`){let{lhs:e,value:n}=Zn(r,d);return t(e,`<>`,n)}return t(r,`<>`,d)}return c===`gt`?t(r,`>`,d):c===`gte`?t(r,`>=`,d):c===`lt`?t(r,`<`,d):c===`lte`?t(r,`<=`,d):t(r,c,d)};l===`OR`?a.or.push(m):a.and.push(m)}),{and:a.and.length?a.and:null,or:a.or.length?a.or:null}}function h(e,t,n){if(!t||!e.length)return e;let r=new Map;for(let a of e){let e={},o={};for(let[e]of Object.entries(t))o[e]={};for(let[r,s]of Object.entries(a)){let a=String(r),c=!1;for(let{joinModel:e,fieldName:r,joinModelRef:l}of n)if(a===`_joined_${l}_${r}`||a===`_Joined${Un(l)}${Un(r)}`){o[e][i({model:t[e]?.modelKey??e,field:r})]=s,c=!0;break}c||(e[r]=s)}let s=e.id;if(!s)continue;if(!r.has(s)){let n={...e};for(let[e,r]of Object.entries(t))n[e]=r.relation===`one-to-one`?null:[];r.set(s,n)}let c=r.get(s);for(let[e,n]of Object.entries(t)){let t=n.relation===`one-to-one`,r=n.limit??100,a=o[e],s=a&&Object.keys(a).length>0&&Object.values(a).some(e=>e!=null);if(t)c[e]=s?a:null;else{let t=e;if(Array.isArray(c[t])&&s){if(c[t].length>=r)continue;let o=i({model:n.modelKey??e,field:`id`}),s=a[o];s?!c[t].some(e=>e[o]===s)&&c[t].length<r&&c[t].push(a):c[t].length<r&&c[t].push(a)}}}}let a=Array.from(r.values());for(let e of a)for(let[n,r]of Object.entries(t))if(r.relation!==`one-to-one`){let t=n;if(Array.isArray(e[t])){let n=r.limit??100;e[t].length>n&&(e[t]=e[t].slice(0,n))}}return a}return{async create({data:e,model:n,modelKey:r=n}){return await p(e,t.insertInto(n).values(e),n,r,[])},async findOne({model:e,modelKey:n=e,where:r,select:a,join:o}){let{and:s,or:c}=m(e,n,r),l=t.selectFrom(t=>{let r=t.selectFrom(e);return s&&(r=r.where(e=>e.and(s.map(t=>t(e))))),c&&(r=r.where(e=>e.or(c.map(t=>t(e))))),r=a?.length&&a.length>0?r.select(a.map(e=>i({model:n,field:e}))):r.selectAll(),r.as(`primary`)}).selectAll(`primary`);if(o)for(let[e,t]of Object.entries(o)){let[n,r]=e.includes(`.`)?e.split(`.`):[void 0,e];l=l.leftJoin(`${e} as join_${r}`,e=>e.onRef(`join_${r}.${t.on.to}`,`=`,`primary.${t.on.from}`))}let{allSelectsStr:u,allSelects:d}=f(o);l=l.select(d);let p=await l.execute();if(!p||!Array.isArray(p)||p.length===0)return null;let g=p[0];return o?h(p,o,u)[0]:g},async findMany({model:e,modelKey:r=e,where:a,limit:o,select:s,offset:c,sortBy:l,join:u}){let{and:d,or:p}=m(e,r,a),g=t.selectFrom(t=>{let a=t.selectFrom(e);return n?.type===`mssql`?c===void 0?o!==void 0&&(a=a.top(o)):(l||(a=a.orderBy(i({model:r,field:`id`}))),a=a.offset(c).fetch(o||100)):(o!==void 0&&(a=a.limit(o)),c!==void 0&&(a=a.offset(c))),l?.field&&(a=a.orderBy(`${i({model:r,field:l.field})}`,l.direction)),d&&(a=a.where(e=>e.and(d.map(t=>t(e))))),p&&(a=a.where(e=>e.or(p.map(t=>t(e))))),a=s?.length&&s.length>0?a.select(s.map(e=>i({model:r,field:e}))):a.selectAll(),a.as(`primary`)}).selectAll(`primary`);if(u)for(let[e,t]of Object.entries(u)){let[n,r]=e.includes(`.`)?e.split(`.`):[void 0,e];g=g.leftJoin(`${e} as join_${r}`,e=>e.onRef(`join_${r}.${t.on.to}`,`=`,`primary.${t.on.from}`))}let{allSelectsStr:_,allSelects:ee}=f(u);g=g.select(ee),l?.field&&(g=g.orderBy(`${i({model:r,field:l.field})}`,l.direction));let v=await g.execute();return v?u?h(v,u,_):v:[]},async update({model:e,modelKey:n=e,where:r,update:i}){if(r.length===0)return null;let{and:a,or:o}=m(e,n,r),s=t.updateTable(e).set(i);return a&&(s=s.where(e=>e.and(a.map(t=>t(e))))),o&&(s=s.where(e=>e.or(o.map(t=>t(e))))),await p(i,s,e,n,r)},async updateMany({model:e,modelKey:n=e,where:r,update:i}){let{and:a,or:o}=m(e,n,r),s=t.updateTable(e).set(i);a&&(s=s.where(e=>e.and(a.map(t=>t(e))))),o&&(s=s.where(e=>e.or(o.map(t=>t(e)))));let c=(await s.executeTakeFirst()).numUpdatedRows;return c>2**53-1?2**53-1:Number(c)},async count({model:e,modelKey:n=e,where:r}){let{and:i,or:a}=m(e,n,r),o=t.selectFrom(e).select(t.fn.count(`id`).as(`count`));i&&(o=o.where(e=>e.and(i.map(t=>t(e))))),a&&(o=o.where(e=>e.or(a.map(t=>t(e)))));let s=await o.execute();return typeof s[0].count==`number`?s[0].count:typeof s[0].count==`bigint`?Number(s[0].count):parseInt(s[0].count)},async delete({model:e,modelKey:n=e,where:r}){let{and:i,or:a}=m(e,n,r),o=t.deleteFrom(e);i&&(o=o.where(e=>e.and(i.map(t=>t(e))))),a&&(o=o.where(e=>e.or(a.map(t=>t(e))))),await o.execute()},async deleteMany({model:e,modelKey:n=e,where:r}){let{and:i,or:a}=m(e,n,r),o=t.deleteFrom(e);i&&(o=o.where(e=>e.and(i.map(t=>t(e))))),a&&(o=o.where(e=>e.or(a.map(t=>t(e)))));let s=(await o.executeTakeFirst()).numDeletedRows;return s>2**53-1?2**53-1:Number(s)},async consumeOne({model:e,modelKey:a=e,where:o}){let{and:s,or:c}=m(e,a,o),l=e=>(s&&(e=e.where(e=>e.and(s.map(t=>t(e))))),c&&(e=e.where(e=>e.or(c.map(t=>t(e))))),e),u=i({model:a,field:`id`}),d=async(t,r)=>{let i=r[u]??r.id;if(i==null)return null;let a=t.deleteFrom(e).where(`${e}.${u}`,`=`,i);if(n?.type===`mysql`){let e=await a.executeTakeFirst();return Number(e.numDeletedRows)>0?r:null}return n?.type===`mssql`?await a.outputAll(`deleted`).executeTakeFirst()??null:await a.returningAll().executeTakeFirst()??null},f=async e=>n?.type===`mssql`?await e.outputAll(`deleted`).executeTakeFirst()??null:await e.returningAll().executeTakeFirst()??null;if(n?.type===`mysql`){let n=async t=>{let n=await l(t.selectFrom(e).selectAll().forUpdate()).limit(1).executeTakeFirst();return n?d(t,n):null};return r?n(t):t.transaction().execute(n)}let p=l(t.selectFrom(e).select(`${e}.${u}`)),h=n?.type===`mssql`?p.top(1):p.limit(1);return f(l(t.deleteFrom(e).where(`${e}.${u}`,`in`,h)))},async incrementOne({model:e,modelKey:a=e,where:o,increment:s,set:c}){let{and:l,or:u}=m(e,a,o),d=e=>(l&&(e=e.where(e=>e.and(l.map(t=>t(e))))),u&&(e=e.where(e=>e.or(u.map(t=>t(e))))),e),f={...c??{}};for(let[e,t]of Object.entries(s))f[e]=w`${w.ref(e)} + ${t}`;let p=i({model:a,field:`id`});if(n?.type===`mysql`){let n=async t=>{let n=await d(t.selectFrom(e).select(`${e}.${p}`).forUpdate()).limit(1).executeTakeFirst();if(!n)return null;let r=n[p]??n.id;if(r==null)return null;let i=await d(t.updateTable(e).set(f)).where(`${e}.${p}`,`=`,r).executeTakeFirst();return Number(i.numUpdatedRows)===0?null:await t.selectFrom(e).selectAll().where(`${e}.${p}`,`=`,r).limit(1).executeTakeFirst()??null};return r?n(t):t.transaction().execute(n)}let h=d(t.selectFrom(e).select(`${e}.${p}`)),g=n?.type===`mssql`?h.top(1):h.limit(1),_=d(t.updateTable(e).set(f)).where(`${e}.${p}`,`in`,g);return n?.type===`mssql`?await _.outputAll(`inserted`).executeTakeFirst()??null:await _.returningAll().executeTakeFirst()??null},options:n}},d=null;d={config:{adapterId:`kysely`,adapterName:`Kysely Adapter`,usePlural:n?.usePlural,debugLogs:n?.debugLogs,supportsBooleans:!(n?.type===`sqlite`||n?.type===`mssql`||n?.type===`mysql`||!n?.type),supportsDates:!(n?.type===`sqlite`||n?.type===`mssql`||!n?.type),supportsJSON:n?.type===`postgres`,supportsArrays:!1,supportsUUIDs:n?.type===`postgres`,transaction:n?.transaction?e=>t.transaction().execute(t=>e(s({config:{...d.config,transaction:!1},adapter:u(t,!0)})(c))):!1},adapter:u(t)};let f=s(d);return e=>{c=e;let s=f(e);return r(s,i(()=>ir(t,n?.type,o(e,{usePlural:n?.usePlural})),`database`,e.database),{runtimeEnabled:a(e)}),s}};export{ar as a,tr as i,Wn as n,Qn as o,nr as r,$n as s,Kn as t};
15
- //# sourceMappingURL=dist-CoH0hD1s.js.map
15
+ //# sourceMappingURL=dist-B9KiBJYw.js.map