viborm 1.3.0 → 1.3.1

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 (82) hide show
  1. package/dist/{builder-Df24l2Bd.mjs → builder-s1ySUuMb.mjs} +2 -2
  2. package/dist/{builder-Df24l2Bd.mjs.map → builder-s1ySUuMb.mjs.map} +1 -1
  3. package/dist/bun-sql.mjs +1 -1
  4. package/dist/bun-sqlite.mjs +1 -1
  5. package/dist/cache/cloudflare-kv.mjs +1 -1
  6. package/dist/cache/memory.mjs +1 -1
  7. package/dist/cache.mjs +1 -1
  8. package/dist/chain-7qiFSE8J.mjs +2 -0
  9. package/dist/chain-7qiFSE8J.mjs.map +1 -0
  10. package/dist/cli.mjs +1 -1
  11. package/dist/{client-_WKrPNmm.mjs → client-6YgGlXzN.mjs} +2 -2
  12. package/dist/{client-_WKrPNmm.mjs.map → client-6YgGlXzN.mjs.map} +1 -1
  13. package/dist/{client-DM1UHfYG.mjs → client-BgJ7Faln.mjs} +2 -2
  14. package/dist/{client-DM1UHfYG.mjs.map → client-BgJ7Faln.mjs.map} +1 -1
  15. package/dist/client.mjs +1 -1
  16. package/dist/config.mjs +1 -1
  17. package/dist/{controls-Da-efekX.mjs → controls-KQ85SWfT.mjs} +2 -2
  18. package/dist/{controls-Da-efekX.mjs.map → controls-KQ85SWfT.mjs.map} +1 -1
  19. package/dist/d1.mjs +1 -1
  20. package/dist/{driver-CPD0Xxw2.mjs → driver-vn-9CN0y.mjs} +2 -2
  21. package/dist/{driver-CPD0Xxw2.mjs.map → driver-vn-9CN0y.mjs.map} +1 -1
  22. package/dist/every-CcpKWCVo.mjs +2 -0
  23. package/dist/{every-1pKZteeB.mjs.map → every-CcpKWCVo.mjs.map} +1 -1
  24. package/dist/{hydration-DsyHNSDS.mjs → hydration-BsPZI4jE.mjs} +2 -2
  25. package/dist/{hydration-DsyHNSDS.mjs.map → hydration-BsPZI4jE.mjs.map} +1 -1
  26. package/dist/{identifier-conversion-DaZ9yNpv.mjs → identifier-conversion-BneQiLxQ.mjs} +2 -2
  27. package/dist/{identifier-conversion-DaZ9yNpv.mjs.map → identifier-conversion-BneQiLxQ.mjs.map} +1 -1
  28. package/dist/index.mjs +1 -1
  29. package/dist/instrumentation.mjs +1 -1
  30. package/dist/{key-D_kagnFv.mjs → key-D9LtHxVK.mjs} +2 -2
  31. package/dist/{key-D_kagnFv.mjs.map → key-D9LtHxVK.mjs.map} +1 -1
  32. package/dist/{libsql-DFAoHXrI.mjs → libsql-BlSBYwd_.mjs} +2 -2
  33. package/dist/{libsql-DFAoHXrI.mjs.map → libsql-BlSBYwd_.mjs.map} +1 -1
  34. package/dist/libsql.mjs +1 -1
  35. package/dist/{memory-GTWgeDNY.mjs → memory-C0k-_S_n.mjs} +2 -2
  36. package/dist/{memory-GTWgeDNY.mjs.map → memory-C0k-_S_n.mjs.map} +1 -1
  37. package/dist/migrations/mysql.mjs +1 -1
  38. package/dist/migrations/postgres.mjs +1 -1
  39. package/dist/migrations/sqlite.mjs +1 -1
  40. package/dist/migrations/tenant.mjs +1 -1
  41. package/dist/migrations.mjs +1 -1
  42. package/dist/{mysql-xChEivOe.mjs → mysql-DOLHwIM_.mjs} +2 -2
  43. package/dist/{mysql-xChEivOe.mjs.map → mysql-DOLHwIM_.mjs.map} +1 -1
  44. package/dist/mysql2.mjs +1 -1
  45. package/dist/neon-http.mjs +1 -1
  46. package/dist/permissions.mjs +1 -1
  47. package/dist/permissions.mjs.map +1 -1
  48. package/dist/pg.mjs +1 -1
  49. package/dist/pglite.mjs +1 -1
  50. package/dist/planetscale.mjs +1 -1
  51. package/dist/{postgres-BqAxDWTQ.mjs → postgres-DQVSTqVm.mjs} +2 -2
  52. package/dist/{postgres-BqAxDWTQ.mjs.map → postgres-DQVSTqVm.mjs.map} +1 -1
  53. package/dist/postgres.mjs +1 -1
  54. package/dist/{result-shape-CDgX_vzn.mjs → result-shape-B6yWtnx_.mjs} +2 -2
  55. package/dist/{result-shape-CDgX_vzn.mjs.map → result-shape-B6yWtnx_.mjs.map} +1 -1
  56. package/dist/{scalar-S8yMvdmx.mjs → scalar-CpEwuJvn.mjs} +2 -2
  57. package/dist/{scalar-S8yMvdmx.mjs.map → scalar-CpEwuJvn.mjs.map} +1 -1
  58. package/dist/schema/json.mjs +1 -1
  59. package/dist/{schema-9N9jQlVL.mjs → schema-BnzGHn7k.mjs} +2 -2
  60. package/dist/{schema-9N9jQlVL.mjs.map → schema-BnzGHn7k.mjs.map} +1 -1
  61. package/dist/{schema-introspection-CyXKReK1.mjs → schema-introspection-DZsdP6bi.mjs} +2 -2
  62. package/dist/{schema-introspection-CyXKReK1.mjs.map → schema-introspection-DZsdP6bi.mjs.map} +1 -1
  63. package/dist/schema.mjs +1 -1
  64. package/dist/sqlite3.mjs +1 -1
  65. package/dist/{to-many-C1PuFIpf.mjs → to-many-C5RMZl05.mjs} +2 -2
  66. package/dist/{to-many-C1PuFIpf.mjs.map → to-many-C5RMZl05.mjs.map} +1 -1
  67. package/dist/{utils-CtFUE8UN.mjs → utils-C3r4gO3Y.mjs} +2 -2
  68. package/dist/{utils-CtFUE8UN.mjs.map → utils-C3r4gO3Y.mjs.map} +1 -1
  69. package/dist/v-DtLdBQYg.mjs +2 -0
  70. package/dist/v-DtLdBQYg.mjs.map +1 -0
  71. package/dist/validation.mjs +1 -1
  72. package/dist/{validator-DgffZq9C.mjs → validator-CVSrhn0u.mjs} +2 -2
  73. package/dist/{validator-DgffZq9C.mjs.map → validator-CVSrhn0u.mjs.map} +1 -1
  74. package/dist/version-C8QLCt1n.mjs +2 -0
  75. package/dist/{version-CXuJzC-q.mjs.map → version-C8QLCt1n.mjs.map} +1 -1
  76. package/package.json +16 -15
  77. package/dist/chain-C7c1YTXD.mjs +0 -2
  78. package/dist/chain-C7c1YTXD.mjs.map +0 -1
  79. package/dist/every-1pKZteeB.mjs +0 -2
  80. package/dist/v-CYTUI0H5.mjs +0 -2
  81. package/dist/v-CYTUI0H5.mjs.map +0 -1
  82. package/dist/version-CXuJzC-q.mjs +0 -2
package/dist/postgres.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import{n as e}from"./chunk-BuuaeEvq.mjs";import{n as t}from"./base-D3m1S7Uc.mjs";import{d as n,l as r,r as i}from"./error-mapping-C9WgitPi.mjs";import{r as a}from"./validation-BamBwne9.mjs";import{n as o}from"./suppressed-failure-Bdo2aK81.mjs";import{s}from"./execution-context-rJXTRVrJ.mjs";import{n as c}from"./client-_WKrPNmm.mjs";import{i as l,t as u}from"./pinned-session-BTplL3iZ.mjs";import{c as d,d as f,f as p,i as m,o as h,s as g,t as _,u as v}from"./driver-B9fIori_.mjs";import{t as y}from"./postgres-result-KyBKBNJr.mjs";import{t as b}from"./postgres-adapter-CGthb5yh.mjs";import x from"postgres";const S={timestamp:{to:1114,from:[1082,1114,1184],serialize:e=>e instanceof Date?e.toISOString():String(e),parse:e=>e},json:{to:114,from:[114,3802],serialize:e=>typeof e==`string`?e:JSON.stringify(e),parse:e=>JSON.parse(e)}};function encodeListParameters(e){return e.map(e=>Array.isArray(e)?`{${e.map(e=>e===null?`NULL`:`"${String(e).replace(/\\/g,`\\\\`).replace(/"/g,`\\"`)}"`).join(`,`)}}`:e)}const withVibormTypes=(e={})=>({...e,types:{...S,...e.types}}),C={client:!0,options:!0,pgvector:!0,postgis:!0,sharedRelationBodies:!0,databaseUrl:!0,namespace:!0,migrationSessionAttestation:!0},isTransaction=e=>`savepoint`in e;var PostgresDriver=class extends _{maxBindParametersPerStatement=65533;driverOptions;suppliedClient;constructor(e={}){super(`postgresql`,`postgres`);let t=f(e);this.driverOptions={databaseUrl:e.databaseUrl,options:{...e.options}},this.suppliedClient=e.client;let{host:n,hostname:r}=this.driverOptions.options??{};if(g(`postgres`,e,!!(this.suppliedClient||n||r)),this.suppliedClient){for(let e of[1082,1114,1184])if(this.suppliedClient.options?.parsers[e]!==S.timestamp?.parse)throw new a(`A supplied postgres.js client must use VibORM temporal parsers; construct postgres(url, { types: vibormTypes }).`,{meta:{driver:`postgres`,operation:`configuration`}});this.client=this.suppliedClient}b(this,t,e),h(this,`migrationSessionAttestation`,v(e))}migrationSessionEndpoints(){let{databaseUrl:e,options:t}=this.driverOptions;return[e,t?.host,t?.hostname,...this.suppliedClient?.options.host??[]]}async initClient(){if(this.suppliedClient!==void 0)return this.suppliedClient;let{databaseUrl:e,options:t}=this.driverOptions;return e?x(p(e),withVibormTypes(t)):x(withVibormTypes(t))}async closeClient(e){e!==this.suppliedClient&&await e.end()}async execute(e,t,n,r){return this.executeQuery(e,t,encodeListParameters(n),r,`execute`)}async executeRaw(e,t,n,r){return this.executeQuery(e,t,n,r,`executeRaw`)}async executeQuery(e,t,n,r,i){let a=r?.operation??i,o=await e.unsafe(t,n,{prepare:this.driverOptions.options?.prepare===!0});return{rows:o,rowCount:y(o.count,o.command,o,{provider:`postgres`,operation:a})}}transactionOptionSupport(){return{isolationLevel:`post-begin`,timeout:!0,maxWait:`unsupported`,maxWaitReason:`postgres.js acquires the connection inside client.begin(), which VibORM cannot observe or bound — the wait would be unbounded no matter what maxWait said`}}async transaction(e,t,i,a){if(isTransaction(e))throw r(this.driverName);return n({run:async t=>{let n=!1;try{return await e.begin(e=>(n=!0,t(e)))}catch(t){throw!n&&this.isConnectionFailure(t)&&await this.recoverFailedBegin(e,t,a?.maxWaitMs??5e3),t}},callback:t,phases:s(i),close:async()=>void 0})}isConnectionFailure(e){let n=i(e,{driverName:this.driverName,dialect:this.dialect});return n.code===t.CONNECTION_FAILED||n.code===t.CONNECTION_TIMEOUT}async recoverFailedBegin(e,t,n){let r=Date.now()+n;for(let n=0;n<2;n++){let n=r-Date.now();if(n<=0)break;try{(await m(()=>e.reserve(),e=>e.release(),n,{driverName:this.driverName,form:`callback`})).release();return}catch(e){if(o(t,e),!this.isConnectionFailure(e))break}}}async pinnedSession(){let e=await this.getClient({operation:`pinnedSession`});if(isTransaction(e))throw r(this.driverName);let t=await e.reserve();return{session:t,release:(n,r)=>l({driverName:this.driverName,discard:n,lost:r,reset:()=>t.unsafe(`SELECT pg_advisory_unlock_all()`),release:()=>t.release(),closeOwnedTransport:e===this.suppliedClient?void 0:async()=>{this.client=null,this.initPromise=null,await e.end({timeout:u/1e3})}})}}};function createClient(e){d(e,`postgres`,C);let{client:t,options:n={},pgvector:r,postgis:i,databaseUrl:a}=e,o=f(e),s=v(e);return c(e,new PostgresDriver({client:t,options:n,...Object.hasOwn(e,`databaseUrl`)?{databaseUrl:a}:{},pgvector:r,postgis:i,sharedRelationBodies:e.sharedRelationBodies,namespace:o,migrationSessionAttestation:s}))}export{PostgresDriver,createClient,S as vibormTypes};
1
+ import{n as e}from"./chunk-BuuaeEvq.mjs";import{n as t}from"./base-D3m1S7Uc.mjs";import{d as n,l as r,r as i}from"./error-mapping-C9WgitPi.mjs";import{r as a}from"./validation-BamBwne9.mjs";import{n as o}from"./suppressed-failure-Bdo2aK81.mjs";import{s}from"./execution-context-rJXTRVrJ.mjs";import{n as c}from"./client-6YgGlXzN.mjs";import{i as l,t as u}from"./pinned-session-BTplL3iZ.mjs";import{c as d,d as f,f as p,i as m,o as h,s as g,t as _,u as v}from"./driver-B9fIori_.mjs";import{t as y}from"./postgres-result-KyBKBNJr.mjs";import{t as b}from"./postgres-adapter-CGthb5yh.mjs";import x from"postgres";const S={timestamp:{to:1114,from:[1082,1114,1184],serialize:e=>e instanceof Date?e.toISOString():String(e),parse:e=>e},json:{to:114,from:[114,3802],serialize:e=>typeof e==`string`?e:JSON.stringify(e),parse:e=>JSON.parse(e)}};function encodeListParameters(e){return e.map(e=>Array.isArray(e)?`{${e.map(e=>e===null?`NULL`:`"${String(e).replace(/\\/g,`\\\\`).replace(/"/g,`\\"`)}"`).join(`,`)}}`:e)}const withVibormTypes=(e={})=>({...e,types:{...S,...e.types}}),C={client:!0,options:!0,pgvector:!0,postgis:!0,sharedRelationBodies:!0,databaseUrl:!0,namespace:!0,migrationSessionAttestation:!0},isTransaction=e=>`savepoint`in e;var PostgresDriver=class extends _{maxBindParametersPerStatement=65533;driverOptions;suppliedClient;constructor(e={}){super(`postgresql`,`postgres`);let t=f(e);this.driverOptions={databaseUrl:e.databaseUrl,options:{...e.options}},this.suppliedClient=e.client;let{host:n,hostname:r}=this.driverOptions.options??{};if(g(`postgres`,e,!!(this.suppliedClient||n||r)),this.suppliedClient){for(let e of[1082,1114,1184])if(this.suppliedClient.options?.parsers[e]!==S.timestamp?.parse)throw new a(`A supplied postgres.js client must use VibORM temporal parsers; construct postgres(url, { types: vibormTypes }).`,{meta:{driver:`postgres`,operation:`configuration`}});this.client=this.suppliedClient}b(this,t,e),h(this,`migrationSessionAttestation`,v(e))}migrationSessionEndpoints(){let{databaseUrl:e,options:t}=this.driverOptions;return[e,t?.host,t?.hostname,...this.suppliedClient?.options.host??[]]}async initClient(){if(this.suppliedClient!==void 0)return this.suppliedClient;let{databaseUrl:e,options:t}=this.driverOptions;return e?x(p(e),withVibormTypes(t)):x(withVibormTypes(t))}async closeClient(e){e!==this.suppliedClient&&await e.end()}async execute(e,t,n,r){return this.executeQuery(e,t,encodeListParameters(n),r,`execute`)}async executeRaw(e,t,n,r){return this.executeQuery(e,t,n,r,`executeRaw`)}async executeQuery(e,t,n,r,i){let a=r?.operation??i,o=await e.unsafe(t,n,{prepare:this.driverOptions.options?.prepare===!0});return{rows:o,rowCount:y(o.count,o.command,o,{provider:`postgres`,operation:a})}}transactionOptionSupport(){return{isolationLevel:`post-begin`,timeout:!0,maxWait:`unsupported`,maxWaitReason:`postgres.js acquires the connection inside client.begin(), which VibORM cannot observe or bound — the wait would be unbounded no matter what maxWait said`}}async transaction(e,t,i,a){if(isTransaction(e))throw r(this.driverName);return n({run:async t=>{let n=!1;try{return await e.begin(e=>(n=!0,t(e)))}catch(t){throw!n&&this.isConnectionFailure(t)&&await this.recoverFailedBegin(e,t,a?.maxWaitMs??5e3),t}},callback:t,phases:s(i),close:async()=>void 0})}isConnectionFailure(e){let n=i(e,{driverName:this.driverName,dialect:this.dialect});return n.code===t.CONNECTION_FAILED||n.code===t.CONNECTION_TIMEOUT}async recoverFailedBegin(e,t,n){let r=Date.now()+n;for(let n=0;n<2;n++){let n=r-Date.now();if(n<=0)break;try{(await m(()=>e.reserve(),e=>e.release(),n,{driverName:this.driverName,form:`callback`})).release();return}catch(e){if(o(t,e),!this.isConnectionFailure(e))break}}}async pinnedSession(){let e=await this.getClient({operation:`pinnedSession`});if(isTransaction(e))throw r(this.driverName);let t=await e.reserve();return{session:t,release:(n,r)=>l({driverName:this.driverName,discard:n,lost:r,reset:()=>t.unsafe(`SELECT pg_advisory_unlock_all()`),release:()=>t.release(),closeOwnedTransport:e===this.suppliedClient?void 0:async()=>{this.client=null,this.initPromise=null,await e.end({timeout:u/1e3})}})}}};function createClient(e){d(e,`postgres`,C);let{client:t,options:n={},pgvector:r,postgis:i,databaseUrl:a}=e,o=f(e),s=v(e);return c(e,new PostgresDriver({client:t,options:n,...Object.hasOwn(e,`databaseUrl`)?{databaseUrl:a}:{},pgvector:r,postgis:i,sharedRelationBodies:e.sharedRelationBodies,namespace:o,migrationSessionAttestation:s}))}export{PostgresDriver,createClient,S as vibormTypes};
2
2
  //# sourceMappingURL=postgres.mjs.map
@@ -1,2 +1,2 @@
1
- import{n as e}from"./chunk-BuuaeEvq.mjs";import{i as t,o as n}from"./value-guards-CK9guf2Z.mjs";import{b as r,c as i,r as a,t as o,u as s,v as c}from"./controls-Da-efekX.mjs";import{a as l,i as u,p as d,r as f}from"./chain-C7c1YTXD.mjs";import{S as p,t as m}from"./base-D3m1S7Uc.mjs";import{a as h,h as g,r as _}from"./error-mapping-C9WgitPi.mjs";import{d as v,f as y,p as b,y as x}from"./validation-BamBwne9.mjs";import{t as S}from"./transaction-4dfqals6.mjs";import{t as C}from"./sql-Bhxq9arK.mjs";import{o as w,s as T}from"./builder-Df24l2Bd.mjs";import{t as E}from"./types-C5Oxz9yp.mjs";import{i as D,t as O}from"./observation-Co72iCd1.mjs";import{a as k,o as A,r as j}from"./execution-context-rJXTRVrJ.mjs";import{n as M}from"./transaction-operation-CU1zlxiG.mjs";import{t as N}from"./result-parsing-8wEK3GY1.mjs";const P=new WeakMap,F=new WeakMap;function executePreparedQuery(e,t,n,r,i,a,o){return(e===void 0||t===void 0||t.length===0)&&o===void 0?n():!r&&o===void 0&&e!==void 0&&t!==void 0&&t.length>0?runCompiledQueryInterceptors(e,t,n,discardReadWriteOutcomeRegistration,a?.readCommitCertainty,a?.reportAdmissionFailure):executeInterceptedQuery(e,t,n,r,i,a,o)}function discardReadWriteOutcomeRegistration(){}async function executeInterceptedQuery(e,t,n,r,i,a,o){let s=o===void 0?[]:[o];o!==void 0&&i?.stage(o);let captureWriteOutcome=e=>{s.push(e),i?.stage(e)},c=0,l,u=!1,publish=async e=>{if(i){if(s.length===0||u)return;u=!0,i.confirm(s);return}c+=1,l=e,s.length!==0&&await publishWriteOutcomes(s,{certainty:e})},d=Object.freeze({committed:()=>publish(`committed`),mayHaveCommitted:()=>publish(`may-have-committed`)}),executeChild=async()=>{try{let e=await n(d);return r&&(i!==void 0||c===0)&&await publish(`committed`),e}catch(e){throw i&&!u&&i.discard(s),e}};try{return e===void 0||t===void 0||t.length===0?await executeChild():await runCompiledQueryInterceptors(e,t,executeChild,captureWriteOutcome,()=>l??a?.readCommitCertainty?.(),a?.reportAdmissionFailure)}catch(e){throw i&&!u&&i.discard(s),e}}function runCompiledQueryInterceptors(e,t,n,r,i,a){return t===void 0||t.length===0?n():runInterceptorAt(e,t,0,n,r,i,a)}function runInterceptorAt(e,t,n,r,i,a,o){let s=t[n];return s===void 0?r():runOneInterceptor(e,s,()=>runInterceptorAt(e,t,n+1,r,i,a,o),i,a,o)}async function runOneInterceptor(e,n,r,i,a,o){let s=!0,c,l=!1,u=!0,d,recordProtocolFailure=t=>{if(d)return d;let r=interceptorError(n.extension,e,t);return d=r,o?.(r),r},proceed=()=>{if(!s)throw recordProtocolFailure(`called proceed more than once`);if(l)throw recordProtocolFailure(`called proceed after its handler settled`);u=!1,s=!1;let e=startChild(r);return c=settle(e),e},onWriteOutcome=e=>{if(!t(e))throw recordProtocolFailure(`registered a non-function write-outcome listener`);if(!u||l)throw recordProtocolFailure(`registered a write-outcome listener after proceed`);i(Object.freeze({extension:n.extension,listener:e}))},f=exposeHandlerContext(e,proceed,onWriteOutcome,n.controls),p;try{p=Promise.resolve(Reflect.apply(n.handler,void 0,[f]))}catch(e){p=Promise.reject(e)}let m=await settle(p);l=!0,u=!1;let h=m.status===`fulfilled`?m:{...m,failure:d!==void 0&&m.reason===d?d:interceptorFailure(n.extension,e,m.reason,a?.())};if(c!==void 0&&h.status===`rejected`&&h.reason!==d&&o?.(h.failure),c===void 0){if(d)throw d;if(h.status===`rejected`)throw h.failure;if(requiresProceed(e))throw interceptorError(n.extension,e,`completed without proceed`);return h.value}let g=await c;if(g.status===`rejected`){let e=selectExtensionFailures(d,h,g);throw e?retainSuppressedFailures(g.reason,e):g.reason}let _=selectExtensionFailures(d,h,g);return _&&throwExtensionFailures(_),h.value}function selectExtensionFailures(e,t,n){if(e&&n.status===`rejected`&&n.reason===e)return;if(t.status!==`rejected`||e!==void 0&&t.reason===e||n.status===`rejected`&&t.reason===n.reason)return e?[e]:void 0;let r=t.failure;return e?[e,r]:[r]}function exposeHandlerContext(e,t,n,r){return Object.freeze({mode:e.mode,kind:e.kind,model:e.model,operation:e.operation,input:e.input,...e.kind===`model`&&r!==void 0?{controls:a(e.controls,r)}:{},proceed:t,onWriteOutcome:n})}function startChild(e){try{return Promise.resolve(e())}catch(e){return Promise.reject(e)}}async function settle(e){try{return{status:`fulfilled`,value:await e}}catch(e){return{status:`rejected`,reason:e}}}function requiresProceed(e){return e.mode===`array`||e.kind!==`model`||!s(e.operation)}function interceptorFailure(e,t,n,r){return p(n)?n:interceptorError(e,t,`failed`,Error(`Query interceptor rejected with a non-Error value`),r)}function interceptorError(e,t,n,r,i){let a=`Extension "${e}" query handler for ${describeOperation(t)} ${n}.`,o={method:`query`,model:t.model,operation:String(t.operation),...i===void 0?{}:{commitCertainty:i}};return r?new b(a,{cause:r,meta:o}):new b(a,{meta:o})}function describeOperation(e){return e.kind===`model`?`${e.model}.${e.operation}`:e.operation}function throwExtensionFailures(e){let t=e[0];throw e.length===1?t:AggregateError(e,`Query interceptor protocol and handler both failed.`,{cause:t})}function retainSuppressedFailures(e,t){let n=AggregateError([e,...t],`Query execution and extension post-work both failed.`,{cause:e});return P.set(n,e),n}function decomposeQueryCoordinationFailure(e){if(!(e instanceof AggregateError)||!P.has(e))return;let t=P.get(e);if(!(e.cause!==t||e.errors[0]!==t))return Object.freeze({child:t,postWork:Object.freeze(e.errors.slice(1))})}var TransactionWriteOutcomes=class{#e=[];stage(e){for(let t of this.#e)if(t.registration===e)return;this.#e.push({registration:e,state:`pending`})}confirm(e){this.#t(e,`confirmed`)}discard(e){this.#t(e,`discarded`)}discardAll(){for(let e of this.#e)e.state=`discarded`}promoteTo(e){for(let t of this.#e)t.state===`confirmed`&&e.#e.push({...t}),t.state=`discarded`}publishCommitted(){return this.publish(`committed`)}async publish(e){let t=[];for(let e of this.#e)e.state===`confirmed`&&t.push(e.registration),e.state=`discarded`;await publishWriteOutcomes(t,{certainty:e})}#t(e,t){for(let n of this.#e)n.state===`pending`&&e.includes(n.registration)&&(n.state=t)}};async function publishWriteOutcomes(e,t){let n;for(let r of e)try{await r.listener(t)}catch(e){let i=p(e)?e:void 0,a=r.failurePolicy===`boundary-owned`&&i!==void 0?i:new b(`Extension "${r.extension}" write-outcome listener failed after ${t.certainty}.`,{cause:i??Error(`Write-outcome listener rejected with a non-Error value`),meta:{method:`onWriteOutcome`,commitCertainty:t.certainty}});(n??=[]).push(a)}if(n===void 0)return;let[r]=n;if(n.length===1)throw r;let i=AggregateError(n,`Multiple extension write-outcome listeners failed.`,{cause:r});throw F.set(i,n),i}function decomposeWriteOutcomePublicationFailure(e){return e instanceof AggregateError?F.get(e)??[e]:[e]}function createOperationExecutionContext(e,t,n){let r=O(n)?.diagnostics?.includeCallsite===!0?Error(`VibORM operation created here`).stack:void 0;return j({model:e,operation:t},createCorrelationId,n,r)}function createPendingOperationContext(e,t,n,r,i){return Object.freeze({clientId:n,scopeId:r,attribution:createOperationExecutionContext(e,t,i)})}function withOperationErrorContext(e,t){let n=k(e);if(n===void 0)return t();let r=O(A(e))?.diagnostics,annotate=t=>{throw t instanceof m?h(t,{forceContext:!1,driverName:typeof t.meta.driver==`string`?t.meta.driver:`unknown`,model:e.model,operation:e.operation,correlationId:e.correlationId,callsite:n,diagnostics:r}):t};try{return t().catch(annotate)}catch(e){return Promise.reject().catch(()=>annotate(e))}}function createPendingOperationInstrumentationFacts(e,t,n,r,i,a,o){return createOperationInstrumentationFacts(e,t,n,r,i,a,o)}function createRawOperationInstrumentationFacts(e,t,n){return createOperationInstrumentationFacts(e,t,void 0,n,n,void 0,!1)}function createOperationInstrumentationFacts(e,t,n,i,a,o,s){let c=O(A(t));if(c?.observesLifecycle===!0)return()=>Object.freeze({kind:`operation`,context:t,identity:d(e),model:n,requestedOperation:i,operation:a,collection:o,complete(e){let n=s?r().readCacheExecutionOutcomes(t):void 0,{failure:i}=e,a=e.status===`failure`&&c.wants(`error-log`)&&isUnloggedError(i)?i:void 0,o=e.status===`failure`&&i instanceof Error&&c.wants(`operation`)?i:void 0;if(!(n===void 0&&a===void 0&&o===void 0))return Object.freeze({kind:`operation`,endedAt:Date.now(),...n===void 0?{}:{readCacheOutcomes:n},...(a??o)===void 0?{}:{failure:a??o},...a===void 0?{skipLog:!0}:{}})}})}async function observeTransactionBatchPhase(e,t,n){let r=O(A(e))?.diagnostics;try{return await n()}catch(n){throw _(n,{driverName:t.driverName,dialect:t.dialect,model:e.model,operation:e.operation,correlationId:e.correlationId,callsite:k(e),diagnostics:r,forceContext:!0})}}function createCorrelationId(){return typeof globalThis.crypto?.randomUUID==`function`?globalThis.crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`}function isUnloggedError(e){return e instanceof Error&&!g(e)}function captureExecution(e){try{return e()}catch(e){return Promise.reject(e)}}var PendingExecution=class{#e=null;#t=null;#n=!1;#r;#i;constructor(e,t){this.#r=e,this.#i=t}executeDefault(e){if(this.#t!==null&&this.#t!==`default`)throw v.alreadyExecutedWithDriver(this.#r,this.#i);return this.#e||=(this.#t=`default`,captureExecution(e)),this.#e}executeWith(e,t){if(this.#n)throw v.alreadyExecutedWithDriver(this.#r,this.#i);if(this.#t===`default`)throw v.alreadyExecutedDefault(this.#r,this.#i);if(this.#t!==null&&this.#t!==e)throw v.differentDriverConflict(this.#r,this.#i);return this.#e||=(this.#t=e,captureExecution(t)),this.#e}reserveWith(e){if(this.#t===`default`)throw v.alreadyExecutedDefault(this.#r,this.#i);if(this.#t!==null)throw this.#t===e?v.alreadyExecutedWithDriver(this.#r,this.#i):v.differentDriverConflict(this.#r,this.#i);this.#t=e,this.#n=!0}executeReserved(e){return this.#e||=captureExecution(e),this.#e}};const I=Object.freeze({accessor:opaqueInspectionValue(`accessor`),function:opaqueInspectionValue(`function`),unsupported:opaqueInspectionValue(`unsupported`)}),L=Object.getOwnPropertyDescriptor(C.prototype,`strings`)?.get,R=Object.getOwnPropertyDescriptor(C.prototype,`values`)?.get;function opaqueInspectionValue(e){let t=Object.create(null);return t.opaque=e,Object.freeze(t)}function snapshotQueryInput(e){return snapshotOwn(e,new Map,!1)}function snapshotOwn(e,t,n){let r=n?[]:Object.create(null);t.set(e,r);let i;try{i=Reflect.ownKeys(e)}catch{return t.set(e,I.unsupported),I.unsupported}for(let a of i){let i;try{i=Object.getOwnPropertyDescriptor(e,a)}catch{return t.set(e,I.unsupported),I.unsupported}if(i!==void 0){if(n&&a===`length`){Object.defineProperty(r,a,i);continue}i.enumerable&&Object.defineProperty(r,a,{configurable:!1,enumerable:!0,value:`value`in i?snapshotValue(i.value,t):I.accessor,writable:!1})}}return Object.freeze(r)}function snapshotValue(e,t){if(typeof e==`function`)return I.function;if(typeof e!=`object`||!e)return e;if(t.has(e))return t.get(e);try{if(Array.isArray(e))return snapshotOwn(e,t,!0);let r=Object.getPrototypeOf(e);if(r===C.prototype&&e instanceof C)return snapshotSql(e,t);if(r===Date.prototype&&e instanceof Date){let n=Object.freeze(new Date(Date.prototype.getTime.call(e)));return t.set(e,n),n}if(e instanceof Uint8Array){let n=new Uint8Array(e);return t.set(e,n),n}if(r===ArrayBuffer.prototype&&e instanceof ArrayBuffer){let n=e.slice(0);return t.set(e,n),n}if(r===Map.prototype&&e instanceof Map){let n=new Map;return t.set(e,n),Map.prototype.forEach.call(e,(e,r)=>{n.set(snapshotValue(r,t),snapshotValue(e,t))}),n}if(r===Set.prototype&&e instanceof Set){let n=new Set;return t.set(e,n),Set.prototype.forEach.call(e,e=>{n.add(snapshotValue(e,t))}),n}if(ArrayBuffer.isView(e)){let n=structuredClone(e);return t.set(e,n),n}if((r===Object.prototype||r===null)&&n(e))return snapshotOwn(e,t,!1)}catch{}return t.set(e,I.unsupported),I.unsupported}function snapshotSql(e,t){if(!(L&&R))throw TypeError(`Sql inspection getters are unavailable`);let n=Reflect.apply(L,e,[]),r=Reflect.apply(R,e,[]),i=Array(n.length);for(let e=0;e<n.length;e+=1){let t=Object.getOwnPropertyDescriptor(n,e);if(!(t&&`value`in t&&typeof t.value==`string`))throw TypeError(`Sql inspection strings are not plain data values`);i[e]=t.value}let a=Array(r.length),o=new C(i,a);t.set(e,o);for(let e=0;e<r.length;e+=1){let n=Object.getOwnPropertyDescriptor(r,e);a[e]=n&&`value`in n?snapshotValue(n.value,t):I.accessor}o.toStatement(`?`),o.toStatement(`$n`),o.toStatement(`:n`);for(let e of Reflect.ownKeys(o)){let t=Reflect.get(o,e);typeof t==`object`&&t&&Object.freeze(t)}return Object.freeze(o),o}const z=Symbol.for(`viborm.pendingOperation`);let attachPendingCacheExecutionFriend,readPendingCacheResultFriend;function combineWriteNotifications(e,t){return e===void 0?t:t===void 0||t===e?e:async()=>{let n=!1,r;try{await e()}catch(e){n=!0,r=e}try{await t()}catch(e){throw n?x(r,e,`Write publication callbacks both failed.`):e}if(n)throw r}}const B=Object.freeze({});let createPendingOperationFriend,V;var H=class PendingOperation{[Symbol.toStringTag]=`Promise`;[z]=!0;#e;#t;#n;#r;#i;#a;#o;#s;#c;#l;#u;#d;#f=!1;#p;#m;#h;#g;#_;#v=!1;static{createPendingOperationFriend=(e,t,n,r,i,a,o)=>new PendingOperation(B,e,t,n,r,i,void 0,void 0,a===void 0?void 0:{prepare:a,status:`pending`},void 0,o),attachPendingCacheExecutionFriend=(e,t)=>e.#F(t),readPendingCacheResultFriend=e=>({get args(){return e.cacheKeyArgs()},get controls(){return e.#y(),e.#l?.controls},get codec(){return e.#T()},executionContext:e.#e.attribution}),V=Object.freeze({clientId:e=>e.#e.clientId,scopeId:e=>e.#e.scopeId,model:e=>e.#i,operation:e=>e.#a,context:e=>e.#e.attribution,requiresInterception:e=>{let t=String(e.#o.originalOperation),n=u(e.#t.extensionChain,`request`,e.#i,t),r=n!==void 0&&n.length>0&&(e.#t.extensionChain?.observe.length??0)>0,i=u(e.#t.extensionChain,`query`,e.#i,t);return r||i!==void 0&&i.length>0||e.#u!==void 0},prepareAdmission:(e,t=`input`)=>{e.#C(),t===`plan`&&e.#S()},stagePackageWriteOutcomes:(e,t)=>{let n=e.#b();n!==void 0&&t.stage(n)},startInterception:(e,t,n,r)=>{let i=String(e.#o.originalOperation),a=u(e.#t.extensionChain,`query`,e.#i,i),o=e.#C(),c=e.#b();return(a===void 0||a.length===0)&&c===void 0?t():executePreparedQuery(a===void 0||a.length===0?void 0:e.#w(`array`,o),a,t,!s(i),n,r,c)},executeCore:(e,t,n)=>e.#s.executeReserved(()=>e.#M(t,n?.committed,n?.mayHaveCommitted)),isWrite:e=>!s(String(e.#o.originalOperation)),hasObservation:e=>(e.#t.extensionChain?.observe.length??0)>0,observe:(e,t,n)=>{let r=e.#t.extensionChain?.observe;return r===void 0||r.length===0?t():D(r,String(e.#o.originalOperation),e.#i,t,n,e.#D())},reserveWith:(e,t)=>{e.#s.reserveWith(t)},executeWith:(e,t)=>{let n=e.#t.extensionChain?.observe;return n===void 0||n.length===0?e.#s.executeWith(t,()=>e.#M(t)):e.#s.executeWith(t,()=>D(n,String(e.#o.originalOperation),e.#i,()=>e.#M(t),()=>e.#m===void 0?void 0:{commitCertainty:e.#m},e.#D()))},prepare:e=>e.#S()?.queries[0],prepareBatch:e=>e.#x().prepareBatch(e.#e.attribution),parseResult:(e,t)=>{let n=e.#S();if(!n)throw new y(`Operation '${e.#a}' on model '${e.#i}' publishes no single driver result to parse.`);return n.parseResult([t])},observeBatchPhase:(e,t,n)=>observeTransactionBatchPhase(e.#e.attribution,t,n)}),M(PendingOperation.prototype,e=>#e in e,V),Object.freeze(PendingOperation.prototype)}constructor(e,t,n,r,i,a,o,s,c,l,u){if(e!==B)throw new S;this.#t=t,this.#n=n,this.#r=i,this.#c=s,this.#l=c,this.#u=u,this.#p=l,this.#h=t.route;let d=r.endsWith(`OrThrow`);this.#a=d?r.slice(0,-7):r,this.#i=n[`~`].names.ts??`unknown`,this.#s=new PendingExecution(this.#i,this.#a),this.#o=Object.freeze({...a,throwIfNotFound:d||a?.throwIfNotFound,originalOperation:a?.originalOperation??r}),this.#e=o??createPendingOperationContext(this.#i,this.#a,t.clientId,t.scopeId,t.extensionChain),Object.freeze(this)}#y(){let e=this.#l;if(e===void 0)return this.#r;if(e.status===`success`&&e.args)return e.args;if(e.status===`failure`)throw e.error;try{let t=f(this.#t.extensionChain,this.#i,String(this.#o.originalOperation)),n=t.length===0?void 0:o(this.#i,this.#a,this.#r,t,this.#t.bound),r=e.prepare(n?.args??this.#r,n?.controls);return e.args=r,e.controls=n?.controls,e.status=`success`,r}catch(t){throw e.error=t,e.status=`failure`,t}}#b(){return this.#f?this.#d:(this.#d=this.#u?.(this.#e.attribution,this.#l?.controls),this.#f=!0,this.#d)}#x(){let e=this.#p?.routed;if(e)return e;if(this.#g)return this.#g;if(!i.has(this.#a))throw new y(`Unknown operation '${this.#a}' on model '${this.#i}'. Known operations: ${[...i].sort().join(`, `)}.`);let t=this.#y(),n=this.#t.extensionChain?.callRows,r=this.#h.operation(this.#n,String(this.#o.originalOperation),t,n&&l(n,this.#i,this.#l?.controls));return this.#g=r,this.#p&&(this.#p.routed=r),r}#S(){if(this.#v)return this.#_;let e=this.#x().prepareSingle(this.#e.attribution);return this.#_=e?.queries.length===1?e:void 0,this.#v=!0,this.#_}#C(){return this.#x().preparedArgs}#w(e,t){let n=this.#l?.controls;return Object.freeze({mode:e,kind:`model`,model:this.#i,operation:String(this.#o.originalOperation),input:snapshotQueryInput(t),...n===void 0?{}:{controls:n}})}#T(){return this.#x().cacheResultCodec()}#E(){return this.#s.executeDefault(()=>{let e=this.#t.extensionChain?.observe;return e===void 0||e.length===0?this.#O():D(e,String(this.#o.originalOperation),this.#i,()=>this.#O(),()=>this.#m===void 0?void 0:{commitCertainty:this.#m},this.#D())})}#D(){return createPendingOperationInstrumentationFacts(this.#t.driver,this.#e.attribution,this.#i,String(this.#o.originalOperation),String(this.#a),this.#n[`~`].names.sql??this.#i,c(this.#o))}#O(e,t,n){return withOperationErrorContext(this.#e.attribution,()=>this.#k(e,t,n))}#k(e,t,n){let r=this.#j(`committed`),i=this.#j(`may-have-committed`),a=String(this.#o.originalOperation),o=u(this.#t.extensionChain,`query`,this.#i,a);return(o===void 0||o.length===0)&&this.#u===void 0?this.#M(e,combineWriteNotifications(t,r),combineWriteNotifications(n,i)):this.#A(o,a,r,i,e,t,n)}#A(e,t,n,r,i,a,o){let c;try{c=this.#C()}catch(e){return Promise.reject(e)}let l=this.#b();return(e===void 0||e.length===0)&&l===void 0?this.#M(i,combineWriteNotifications(a,n),combineWriteNotifications(o,r)):executePreparedQuery(e===void 0||e.length===0?void 0:this.#w(this.#t.transactionWriteOutcomes?`transaction`:`direct`,c),e,e=>this.#M(i,combineWriteNotifications(a,combineWriteNotifications(e?.committed,n)),combineWriteNotifications(o,combineWriteNotifications(e?.mayHaveCommitted,r))),!s(t),this.#t.transactionWriteOutcomes,void 0,l)}#j(e){if(!(this.#t.transactionWriteOutcomes!==void 0||(this.#t.extensionChain?.observe.length??0)===0))return async()=>{(e===`committed`||this.#m===void 0)&&(this.#m=e)}}#M(e,t,n){return this.#c?this.#c(e,t,n):this.#N(e,t,n)}#N(e,t,n){let r;try{r=this.#x()}catch(e){return Promise.reject(e)}return r.execute({committedWriteSegment:t,context:this.#e.attribution,driverOverride:e,engineDriver:this.#t.driver,isWrite:!s(String(this.#o.originalOperation)),writeMayBeVisible:n})}getArgs(){return this.#r}cacheKeyArgs(){let e=this.#P();if(!e)throw new y(`Operation '${this.#a}' on model '${this.#i}' exposes no validated payload to key a cache entry on.`);return e}#P(){if(s(this.#a))return this.#x().preparedArgs}buildStatement(){return this.#x().buildStatement()}#F(e){let t=this.#p??={routed:this.#g},deferredExecution=(t,n,r)=>e((e,i,a)=>this.#M(e??t,combineWriteNotifications(i,n),combineWriteNotifications(a,r)),t);return new PendingOperation(B,this.#t,this.#n,this.#a,this.#r,this.#o,this.#e,deferredExecution,this.#l,t,this.#u)}then(e,t){return this.#E().then(e,t)}catch(e){return this.#E().catch(e)}finally(e){return this.#E().finally(e)}};function createPendingOperation(e,t,n,r,i,a,o){return createPendingOperationFriend(e,t,n,r,i,a,o)}function attachPendingCacheExecution(e,t){return attachPendingCacheExecutionFriend(e,t)}function readPendingCacheResult(e){return readPendingCacheResultFriend(e)}function isPendingOperation(e){return typeof e==`object`&&!!e&&z in e&&e[z]===!0}const U=`0viborm_distance`,W=`0viborm_relation_counts`,G=`0viborm_empty_row`,gateResultKey=e=>`0viborm_gate:${e}`,K=`0viborm_cursor_`,q=`0viborm_orphans`;function getAggregateResultKey(e){return`0viborm_aggregate:${e.slice(1)}`}function getAggregateResultName(e){switch(e){case`0viborm_aggregate:count`:return`_count`;case`0viborm_aggregate:avg`:return`_avg`;case`0viborm_aggregate:sum`:return`_sum`;case`0viborm_aggregate:min`:return`_min`;case`0viborm_aggregate:max`:return`_max`;default:return}}function getGroupByFields(e){let t=Array.isArray(e)?e.filter(e=>typeof e==`string`):typeof e==`string`?[e]:[];if(new Set(t).size!==t.length)throw new y(`GroupBy operation does not allow duplicate fields in 'by'`);return t}const J=new Set([`findFirst`,`findMany`,`findUnique`,`create`,`createManyAndReturn`,`update`,`updateManyAndReturn`,`delete`,`deleteManyAndReturn`,`upsert`]),Y=`Distance select supports only one _distance field per select.`;function selectedArm(e,t,r){let i=n(e)?e:void 0;if(!t)return getOwnValue(i,r)??!0;let a=getOwnValue(i,`only`);if(Array.isArray(a)&&!a.includes(r))return;let o=getOwnValue(i,`variants`);return(n(o)?getOwnValue(o,r):void 0)??!0}const X=[`_count`,`_avg`,`_sum`,`_min`,`_max`];function getOwnValue(e,t){return e&&Object.hasOwn(e,t)?e[t]:void 0}function createShape(e,t=new Map,n=new Map,r=new Set,i=new Map,a){if(new Set(e).size!==e.length)throw new y(`The requested result shape contains colliding output columns.`);return{carrier:`rows`,rawKeys:e,...a?{distanceScalar:a}:{},relations:t,polymorphic:i,aggregates:n,relationCounts:r}}function selectedEntries(e){return n(e)?Object.entries(e).filter(([,e])=>e!==!1&&e!==void 0):[]}function getNestedSelection(e){if(!n(e))return{};let t={},r=getOwnValue(e,`select`),i=getOwnValue(e,`include`);return n(r)&&(t.select=r),n(i)&&(t.include=i),t}function buildModelShape(e,t,r){let i=[],a=new Map,o=new Map,s=e[`~`].state.scalars,c=e[`~`].state.relations,l=getOwnValue(t,`select`),u=getOwnValue(t,`include`),d=n(l)?l:void 0,f=n(u)?u:void 0,p=!1,m;if(d)for(let[e,t]of Object.entries(d)){let r=getOwnValue(s,e);if(r){if(t===!0){i.push(e);continue}if(n(t)&&Object.hasOwn(t,`_distance`)){if(p)throw new y(Y);p=!0,m=r,i.push(U)}}}else for(let t of T(e))i.push(t);addSelectedRelations(e,c,d,i,a,r),addSelectedPolymorphicRelations(e,d,i,o,r),addSelectedRelations(e,c,f,i,a,r),addSelectedPolymorphicRelations(e,f,i,o,r);let h=[getOwnValue(d,`_count`),getOwnValue(f,`_count`)],g=new Set;for(let e of h){if(!n(e))continue;let t=getOwnValue(e,`select`);if(n(t))for(let[e]of selectedEntries(t)){let t=getOwnValue(c,e);if(!t)continue;let n=t[`~`].state;E(n)&&n.cardinality!==`many`||g.add(e)}}return g.size>0&&i.push(W),i.length===0&&i.push(G),createShape(i,a,new Map,g,o,m)}function admittedRecurrence(e){if(n(e))return getOwnValue(e,`recurse`)}function addSelectedRelations(e,t,n,r,i,a){for(let[o,s]of selectedEntries(n)){let n=getOwnValue(t,o);if(!n||E(n[`~`].state))continue;let c=n[`~`].settleTarget();r.push(o);let l=buildModelShape(c,getNestedSelection(s),a),u=a.get(e)?.get(o),d=admittedRecurrence(s);i.set(o,{model:c,shape:l,cardinality:n[`~`].state.cardinality,optional:u!==void 0&&w(u),...d?{recurrence:d}:{}})}}function addSelectedPolymorphicRelations(e,t,n,r,i){let a=e[`~`].state.relations;for(let[o,s]of selectedEntries(t)){let t=getOwnValue(a,o);if(!t)continue;let c=t[`~`].state;if(!E(c))continue;let l=c.cardinality===`many`,u=new Map;for(let e of Object.keys(c.target.entries)){let n=selectedArm(s,l,e);if(n===void 0)continue;let r=t[`~`].settleTarget(e);u.set(e,{model:r,shape:buildModelShape(r,getNestedSelection(n),i)})}n.push(o);let d=i.get(e)?.get(o);r.set(o,{cardinality:c.cardinality,optional:d!==void 0&&w(d),variants:u})}}function buildAggregateShape(e,t=[]){let n=[...t],r=new Set(t),i=new Map;for(let t of X){let a=getOwnValue(e,t);if(a===void 0||a===!1)continue;let o;if(!(t===`_count`&&a===!0)){let e=selectedEntries(a);if(e.length===0)continue;o=new Set(e.map(([e])=>e))}if(r.has(t))throw new y(`GroupBy cannot return both grouped scalar '${t}' and aggregate '${t}' in one result.`);let s=getAggregateResultKey(t);n.push(s),r.add(t),i.set(s,{...o?{fields:o}:{}})}return createShape(n,new Map,i)}function buildCountShape(e){let t=selectedEntries(getOwnValue(e,`select`)).map(([e])=>e);return{...createShape(t.length===0?[N]:t),carrier:`count`}}function buildExpectedResultShape(e,t,n,r){if(t===`count`)return buildCountShape(n);if(t===`exist`)return{...createShape([N]),carrier:`existence`};if(t===`aggregate`)return buildAggregateShape(n);if(t===`groupBy`)return buildAggregateShape(n,getGroupByFields(getOwnValue(n,`by`)));if(J.has(t))return buildModelShape(e,n,r)}export{decomposeQueryCoordinationFailure as C,TransactionWriteOutcomes as S,executePreparedQuery as T,PendingExecution as _,U as a,observeTransactionBatchPhase as b,W as c,H as d,attachPendingCacheExecution as f,snapshotQueryInput as g,readPendingCacheResult as h,K as i,gateResultKey as l,isPendingOperation as m,buildExpectedResultShape as n,G as o,createPendingOperation as p,selectedArm as r,q as s,Y as t,getAggregateResultName as u,createOperationExecutionContext as v,decomposeWriteOutcomePublicationFailure as w,withOperationErrorContext as x,createRawOperationInstrumentationFacts as y};
2
- //# sourceMappingURL=result-shape-CDgX_vzn.mjs.map
1
+ import{n as e}from"./chunk-BuuaeEvq.mjs";import{i as t,o as n}from"./value-guards-CK9guf2Z.mjs";import{b as r,c as i,r as a,t as o,u as s,v as c}from"./controls-KQ85SWfT.mjs";import{a as l,i as u,p as d,r as f}from"./chain-7qiFSE8J.mjs";import{S as p,t as m}from"./base-D3m1S7Uc.mjs";import{a as h,h as g,r as _}from"./error-mapping-C9WgitPi.mjs";import{d as v,f as y,p as b,y as x}from"./validation-BamBwne9.mjs";import{t as S}from"./transaction-4dfqals6.mjs";import{t as C}from"./sql-Bhxq9arK.mjs";import{o as w,s as T}from"./builder-s1ySUuMb.mjs";import{t as E}from"./types-C5Oxz9yp.mjs";import{i as D,t as O}from"./observation-Co72iCd1.mjs";import{a as k,o as A,r as j}from"./execution-context-rJXTRVrJ.mjs";import{n as M}from"./transaction-operation-CU1zlxiG.mjs";import{t as N}from"./result-parsing-8wEK3GY1.mjs";const P=new WeakMap,F=new WeakMap;function executePreparedQuery(e,t,n,r,i,a,o){return(e===void 0||t===void 0||t.length===0)&&o===void 0?n():!r&&o===void 0&&e!==void 0&&t!==void 0&&t.length>0?runCompiledQueryInterceptors(e,t,n,discardReadWriteOutcomeRegistration,a?.readCommitCertainty,a?.reportAdmissionFailure):executeInterceptedQuery(e,t,n,r,i,a,o)}function discardReadWriteOutcomeRegistration(){}async function executeInterceptedQuery(e,t,n,r,i,a,o){let s=o===void 0?[]:[o];o!==void 0&&i?.stage(o);let captureWriteOutcome=e=>{s.push(e),i?.stage(e)},c=0,l,u=!1,publish=async e=>{if(i){if(s.length===0||u)return;u=!0,i.confirm(s);return}c+=1,l=e,s.length!==0&&await publishWriteOutcomes(s,{certainty:e})},d=Object.freeze({committed:()=>publish(`committed`),mayHaveCommitted:()=>publish(`may-have-committed`)}),executeChild=async()=>{try{let e=await n(d);return r&&(i!==void 0||c===0)&&await publish(`committed`),e}catch(e){throw i&&!u&&i.discard(s),e}};try{return e===void 0||t===void 0||t.length===0?await executeChild():await runCompiledQueryInterceptors(e,t,executeChild,captureWriteOutcome,()=>l??a?.readCommitCertainty?.(),a?.reportAdmissionFailure)}catch(e){throw i&&!u&&i.discard(s),e}}function runCompiledQueryInterceptors(e,t,n,r,i,a){return t===void 0||t.length===0?n():runInterceptorAt(e,t,0,n,r,i,a)}function runInterceptorAt(e,t,n,r,i,a,o){let s=t[n];return s===void 0?r():runOneInterceptor(e,s,()=>runInterceptorAt(e,t,n+1,r,i,a,o),i,a,o)}async function runOneInterceptor(e,n,r,i,a,o){let s=!0,c,l=!1,u=!0,d,recordProtocolFailure=t=>{if(d)return d;let r=interceptorError(n.extension,e,t);return d=r,o?.(r),r},proceed=()=>{if(!s)throw recordProtocolFailure(`called proceed more than once`);if(l)throw recordProtocolFailure(`called proceed after its handler settled`);u=!1,s=!1;let e=startChild(r);return c=settle(e),e},onWriteOutcome=e=>{if(!t(e))throw recordProtocolFailure(`registered a non-function write-outcome listener`);if(!u||l)throw recordProtocolFailure(`registered a write-outcome listener after proceed`);i(Object.freeze({extension:n.extension,listener:e}))},f=exposeHandlerContext(e,proceed,onWriteOutcome,n.controls),p;try{p=Promise.resolve(Reflect.apply(n.handler,void 0,[f]))}catch(e){p=Promise.reject(e)}let m=await settle(p);l=!0,u=!1;let h=m.status===`fulfilled`?m:{...m,failure:d!==void 0&&m.reason===d?d:interceptorFailure(n.extension,e,m.reason,a?.())};if(c!==void 0&&h.status===`rejected`&&h.reason!==d&&o?.(h.failure),c===void 0){if(d)throw d;if(h.status===`rejected`)throw h.failure;if(requiresProceed(e))throw interceptorError(n.extension,e,`completed without proceed`);return h.value}let g=await c;if(g.status===`rejected`){let e=selectExtensionFailures(d,h,g);throw e?retainSuppressedFailures(g.reason,e):g.reason}let _=selectExtensionFailures(d,h,g);return _&&throwExtensionFailures(_),h.value}function selectExtensionFailures(e,t,n){if(e&&n.status===`rejected`&&n.reason===e)return;if(t.status!==`rejected`||e!==void 0&&t.reason===e||n.status===`rejected`&&t.reason===n.reason)return e?[e]:void 0;let r=t.failure;return e?[e,r]:[r]}function exposeHandlerContext(e,t,n,r){return Object.freeze({mode:e.mode,kind:e.kind,model:e.model,operation:e.operation,input:e.input,...e.kind===`model`&&r!==void 0?{controls:a(e.controls,r)}:{},proceed:t,onWriteOutcome:n})}function startChild(e){try{return Promise.resolve(e())}catch(e){return Promise.reject(e)}}async function settle(e){try{return{status:`fulfilled`,value:await e}}catch(e){return{status:`rejected`,reason:e}}}function requiresProceed(e){return e.mode===`array`||e.kind!==`model`||!s(e.operation)}function interceptorFailure(e,t,n,r){return p(n)?n:interceptorError(e,t,`failed`,Error(`Query interceptor rejected with a non-Error value`),r)}function interceptorError(e,t,n,r,i){let a=`Extension "${e}" query handler for ${describeOperation(t)} ${n}.`,o={method:`query`,model:t.model,operation:String(t.operation),...i===void 0?{}:{commitCertainty:i}};return r?new b(a,{cause:r,meta:o}):new b(a,{meta:o})}function describeOperation(e){return e.kind===`model`?`${e.model}.${e.operation}`:e.operation}function throwExtensionFailures(e){let t=e[0];throw e.length===1?t:AggregateError(e,`Query interceptor protocol and handler both failed.`,{cause:t})}function retainSuppressedFailures(e,t){let n=AggregateError([e,...t],`Query execution and extension post-work both failed.`,{cause:e});return P.set(n,e),n}function decomposeQueryCoordinationFailure(e){if(!(e instanceof AggregateError)||!P.has(e))return;let t=P.get(e);if(!(e.cause!==t||e.errors[0]!==t))return Object.freeze({child:t,postWork:Object.freeze(e.errors.slice(1))})}var TransactionWriteOutcomes=class{#e=[];stage(e){for(let t of this.#e)if(t.registration===e)return;this.#e.push({registration:e,state:`pending`})}confirm(e){this.#t(e,`confirmed`)}discard(e){this.#t(e,`discarded`)}discardAll(){for(let e of this.#e)e.state=`discarded`}promoteTo(e){for(let t of this.#e)t.state===`confirmed`&&e.#e.push({...t}),t.state=`discarded`}publishCommitted(){return this.publish(`committed`)}async publish(e){let t=[];for(let e of this.#e)e.state===`confirmed`&&t.push(e.registration),e.state=`discarded`;await publishWriteOutcomes(t,{certainty:e})}#t(e,t){for(let n of this.#e)n.state===`pending`&&e.includes(n.registration)&&(n.state=t)}};async function publishWriteOutcomes(e,t){let n;for(let r of e)try{await r.listener(t)}catch(e){let i=p(e)?e:void 0,a=r.failurePolicy===`boundary-owned`&&i!==void 0?i:new b(`Extension "${r.extension}" write-outcome listener failed after ${t.certainty}.`,{cause:i??Error(`Write-outcome listener rejected with a non-Error value`),meta:{method:`onWriteOutcome`,commitCertainty:t.certainty}});(n??=[]).push(a)}if(n===void 0)return;let[r]=n;if(n.length===1)throw r;let i=AggregateError(n,`Multiple extension write-outcome listeners failed.`,{cause:r});throw F.set(i,n),i}function decomposeWriteOutcomePublicationFailure(e){return e instanceof AggregateError?F.get(e)??[e]:[e]}function createOperationExecutionContext(e,t,n){let r=O(n)?.diagnostics?.includeCallsite===!0?Error(`VibORM operation created here`).stack:void 0;return j({model:e,operation:t},createCorrelationId,n,r)}function createPendingOperationContext(e,t,n,r,i){return Object.freeze({clientId:n,scopeId:r,attribution:createOperationExecutionContext(e,t,i)})}function withOperationErrorContext(e,t){let n=k(e);if(n===void 0)return t();let r=O(A(e))?.diagnostics,annotate=t=>{throw t instanceof m?h(t,{forceContext:!1,driverName:typeof t.meta.driver==`string`?t.meta.driver:`unknown`,model:e.model,operation:e.operation,correlationId:e.correlationId,callsite:n,diagnostics:r}):t};try{return t().catch(annotate)}catch(e){return Promise.reject().catch(()=>annotate(e))}}function createPendingOperationInstrumentationFacts(e,t,n,r,i,a,o){return createOperationInstrumentationFacts(e,t,n,r,i,a,o)}function createRawOperationInstrumentationFacts(e,t,n){return createOperationInstrumentationFacts(e,t,void 0,n,n,void 0,!1)}function createOperationInstrumentationFacts(e,t,n,i,a,o,s){let c=O(A(t));if(c?.observesLifecycle===!0)return()=>Object.freeze({kind:`operation`,context:t,identity:d(e),model:n,requestedOperation:i,operation:a,collection:o,complete(e){let n=s?r().readCacheExecutionOutcomes(t):void 0,{failure:i}=e,a=e.status===`failure`&&c.wants(`error-log`)&&isUnloggedError(i)?i:void 0,o=e.status===`failure`&&i instanceof Error&&c.wants(`operation`)?i:void 0;if(!(n===void 0&&a===void 0&&o===void 0))return Object.freeze({kind:`operation`,endedAt:Date.now(),...n===void 0?{}:{readCacheOutcomes:n},...(a??o)===void 0?{}:{failure:a??o},...a===void 0?{skipLog:!0}:{}})}})}async function observeTransactionBatchPhase(e,t,n){let r=O(A(e))?.diagnostics;try{return await n()}catch(n){throw _(n,{driverName:t.driverName,dialect:t.dialect,model:e.model,operation:e.operation,correlationId:e.correlationId,callsite:k(e),diagnostics:r,forceContext:!0})}}function createCorrelationId(){return typeof globalThis.crypto?.randomUUID==`function`?globalThis.crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`}function isUnloggedError(e){return e instanceof Error&&!g(e)}function captureExecution(e){try{return e()}catch(e){return Promise.reject(e)}}var PendingExecution=class{#e=null;#t=null;#n=!1;#r;#i;constructor(e,t){this.#r=e,this.#i=t}executeDefault(e){if(this.#t!==null&&this.#t!==`default`)throw v.alreadyExecutedWithDriver(this.#r,this.#i);return this.#e||=(this.#t=`default`,captureExecution(e)),this.#e}executeWith(e,t){if(this.#n)throw v.alreadyExecutedWithDriver(this.#r,this.#i);if(this.#t===`default`)throw v.alreadyExecutedDefault(this.#r,this.#i);if(this.#t!==null&&this.#t!==e)throw v.differentDriverConflict(this.#r,this.#i);return this.#e||=(this.#t=e,captureExecution(t)),this.#e}reserveWith(e){if(this.#t===`default`)throw v.alreadyExecutedDefault(this.#r,this.#i);if(this.#t!==null)throw this.#t===e?v.alreadyExecutedWithDriver(this.#r,this.#i):v.differentDriverConflict(this.#r,this.#i);this.#t=e,this.#n=!0}executeReserved(e){return this.#e||=captureExecution(e),this.#e}};const I=Object.freeze({accessor:opaqueInspectionValue(`accessor`),function:opaqueInspectionValue(`function`),unsupported:opaqueInspectionValue(`unsupported`)}),L=Object.getOwnPropertyDescriptor(C.prototype,`strings`)?.get,R=Object.getOwnPropertyDescriptor(C.prototype,`values`)?.get;function opaqueInspectionValue(e){let t=Object.create(null);return t.opaque=e,Object.freeze(t)}function snapshotQueryInput(e){return snapshotOwn(e,new Map,!1)}function snapshotOwn(e,t,n){let r=n?[]:Object.create(null);t.set(e,r);let i;try{i=Reflect.ownKeys(e)}catch{return t.set(e,I.unsupported),I.unsupported}for(let a of i){let i;try{i=Object.getOwnPropertyDescriptor(e,a)}catch{return t.set(e,I.unsupported),I.unsupported}if(i!==void 0){if(n&&a===`length`){Object.defineProperty(r,a,i);continue}i.enumerable&&Object.defineProperty(r,a,{configurable:!1,enumerable:!0,value:`value`in i?snapshotValue(i.value,t):I.accessor,writable:!1})}}return Object.freeze(r)}function snapshotValue(e,t){if(typeof e==`function`)return I.function;if(typeof e!=`object`||!e)return e;if(t.has(e))return t.get(e);try{if(Array.isArray(e))return snapshotOwn(e,t,!0);let r=Object.getPrototypeOf(e);if(r===C.prototype&&e instanceof C)return snapshotSql(e,t);if(r===Date.prototype&&e instanceof Date){let n=Object.freeze(new Date(Date.prototype.getTime.call(e)));return t.set(e,n),n}if(e instanceof Uint8Array){let n=new Uint8Array(e);return t.set(e,n),n}if(r===ArrayBuffer.prototype&&e instanceof ArrayBuffer){let n=e.slice(0);return t.set(e,n),n}if(r===Map.prototype&&e instanceof Map){let n=new Map;return t.set(e,n),Map.prototype.forEach.call(e,(e,r)=>{n.set(snapshotValue(r,t),snapshotValue(e,t))}),n}if(r===Set.prototype&&e instanceof Set){let n=new Set;return t.set(e,n),Set.prototype.forEach.call(e,e=>{n.add(snapshotValue(e,t))}),n}if(ArrayBuffer.isView(e)){let n=structuredClone(e);return t.set(e,n),n}if((r===Object.prototype||r===null)&&n(e))return snapshotOwn(e,t,!1)}catch{}return t.set(e,I.unsupported),I.unsupported}function snapshotSql(e,t){if(!(L&&R))throw TypeError(`Sql inspection getters are unavailable`);let n=Reflect.apply(L,e,[]),r=Reflect.apply(R,e,[]),i=Array(n.length);for(let e=0;e<n.length;e+=1){let t=Object.getOwnPropertyDescriptor(n,e);if(!(t&&`value`in t&&typeof t.value==`string`))throw TypeError(`Sql inspection strings are not plain data values`);i[e]=t.value}let a=Array(r.length),o=new C(i,a);t.set(e,o);for(let e=0;e<r.length;e+=1){let n=Object.getOwnPropertyDescriptor(r,e);a[e]=n&&`value`in n?snapshotValue(n.value,t):I.accessor}o.toStatement(`?`),o.toStatement(`$n`),o.toStatement(`:n`);for(let e of Reflect.ownKeys(o)){let t=Reflect.get(o,e);typeof t==`object`&&t&&Object.freeze(t)}return Object.freeze(o),o}const z=Symbol.for(`viborm.pendingOperation`);let attachPendingCacheExecutionFriend,readPendingCacheResultFriend;function combineWriteNotifications(e,t){return e===void 0?t:t===void 0||t===e?e:async()=>{let n=!1,r;try{await e()}catch(e){n=!0,r=e}try{await t()}catch(e){throw n?x(r,e,`Write publication callbacks both failed.`):e}if(n)throw r}}const B=Object.freeze({});let createPendingOperationFriend,V;var H=class PendingOperation{[Symbol.toStringTag]=`Promise`;[z]=!0;#e;#t;#n;#r;#i;#a;#o;#s;#c;#l;#u;#d;#f=!1;#p;#m;#h;#g;#_;#v=!1;static{createPendingOperationFriend=(e,t,n,r,i,a,o)=>new PendingOperation(B,e,t,n,r,i,void 0,void 0,a===void 0?void 0:{prepare:a,status:`pending`},void 0,o),attachPendingCacheExecutionFriend=(e,t)=>e.#F(t),readPendingCacheResultFriend=e=>({get args(){return e.cacheKeyArgs()},get controls(){return e.#y(),e.#l?.controls},get codec(){return e.#T()},executionContext:e.#e.attribution}),V=Object.freeze({clientId:e=>e.#e.clientId,scopeId:e=>e.#e.scopeId,model:e=>e.#i,operation:e=>e.#a,context:e=>e.#e.attribution,requiresInterception:e=>{let t=String(e.#o.originalOperation),n=u(e.#t.extensionChain,`request`,e.#i,t),r=n!==void 0&&n.length>0&&(e.#t.extensionChain?.observe.length??0)>0,i=u(e.#t.extensionChain,`query`,e.#i,t);return r||i!==void 0&&i.length>0||e.#u!==void 0},prepareAdmission:(e,t=`input`)=>{e.#C(),t===`plan`&&e.#S()},stagePackageWriteOutcomes:(e,t)=>{let n=e.#b();n!==void 0&&t.stage(n)},startInterception:(e,t,n,r)=>{let i=String(e.#o.originalOperation),a=u(e.#t.extensionChain,`query`,e.#i,i),o=e.#C(),c=e.#b();return(a===void 0||a.length===0)&&c===void 0?t():executePreparedQuery(a===void 0||a.length===0?void 0:e.#w(`array`,o),a,t,!s(i),n,r,c)},executeCore:(e,t,n)=>e.#s.executeReserved(()=>e.#M(t,n?.committed,n?.mayHaveCommitted)),isWrite:e=>!s(String(e.#o.originalOperation)),hasObservation:e=>(e.#t.extensionChain?.observe.length??0)>0,observe:(e,t,n)=>{let r=e.#t.extensionChain?.observe;return r===void 0||r.length===0?t():D(r,String(e.#o.originalOperation),e.#i,t,n,e.#D())},reserveWith:(e,t)=>{e.#s.reserveWith(t)},executeWith:(e,t)=>{let n=e.#t.extensionChain?.observe;return n===void 0||n.length===0?e.#s.executeWith(t,()=>e.#M(t)):e.#s.executeWith(t,()=>D(n,String(e.#o.originalOperation),e.#i,()=>e.#M(t),()=>e.#m===void 0?void 0:{commitCertainty:e.#m},e.#D()))},prepare:e=>e.#S()?.queries[0],prepareBatch:e=>e.#x().prepareBatch(e.#e.attribution),parseResult:(e,t)=>{let n=e.#S();if(!n)throw new y(`Operation '${e.#a}' on model '${e.#i}' publishes no single driver result to parse.`);return n.parseResult([t])},observeBatchPhase:(e,t,n)=>observeTransactionBatchPhase(e.#e.attribution,t,n)}),M(PendingOperation.prototype,e=>#e in e,V),Object.freeze(PendingOperation.prototype)}constructor(e,t,n,r,i,a,o,s,c,l,u){if(e!==B)throw new S;this.#t=t,this.#n=n,this.#r=i,this.#c=s,this.#l=c,this.#u=u,this.#p=l,this.#h=t.route;let d=r.endsWith(`OrThrow`);this.#a=d?r.slice(0,-7):r,this.#i=n[`~`].names.ts??`unknown`,this.#s=new PendingExecution(this.#i,this.#a),this.#o=Object.freeze({...a,throwIfNotFound:d||a?.throwIfNotFound,originalOperation:a?.originalOperation??r}),this.#e=o??createPendingOperationContext(this.#i,this.#a,t.clientId,t.scopeId,t.extensionChain),Object.freeze(this)}#y(){let e=this.#l;if(e===void 0)return this.#r;if(e.status===`success`&&e.args)return e.args;if(e.status===`failure`)throw e.error;try{let t=f(this.#t.extensionChain,this.#i,String(this.#o.originalOperation)),n=t.length===0?void 0:o(this.#i,this.#a,this.#r,t,this.#t.bound),r=e.prepare(n?.args??this.#r,n?.controls);return e.args=r,e.controls=n?.controls,e.status=`success`,r}catch(t){throw e.error=t,e.status=`failure`,t}}#b(){return this.#f?this.#d:(this.#d=this.#u?.(this.#e.attribution,this.#l?.controls),this.#f=!0,this.#d)}#x(){let e=this.#p?.routed;if(e)return e;if(this.#g)return this.#g;if(!i.has(this.#a))throw new y(`Unknown operation '${this.#a}' on model '${this.#i}'. Known operations: ${[...i].sort().join(`, `)}.`);let t=this.#y(),n=this.#t.extensionChain?.callRows,r=this.#h.operation(this.#n,String(this.#o.originalOperation),t,n&&l(n,this.#i,this.#l?.controls));return this.#g=r,this.#p&&(this.#p.routed=r),r}#S(){if(this.#v)return this.#_;let e=this.#x().prepareSingle(this.#e.attribution);return this.#_=e?.queries.length===1?e:void 0,this.#v=!0,this.#_}#C(){return this.#x().preparedArgs}#w(e,t){let n=this.#l?.controls;return Object.freeze({mode:e,kind:`model`,model:this.#i,operation:String(this.#o.originalOperation),input:snapshotQueryInput(t),...n===void 0?{}:{controls:n}})}#T(){return this.#x().cacheResultCodec()}#E(){return this.#s.executeDefault(()=>{let e=this.#t.extensionChain?.observe;return e===void 0||e.length===0?this.#O():D(e,String(this.#o.originalOperation),this.#i,()=>this.#O(),()=>this.#m===void 0?void 0:{commitCertainty:this.#m},this.#D())})}#D(){return createPendingOperationInstrumentationFacts(this.#t.driver,this.#e.attribution,this.#i,String(this.#o.originalOperation),String(this.#a),this.#n[`~`].names.sql??this.#i,c(this.#o))}#O(e,t,n){return withOperationErrorContext(this.#e.attribution,()=>this.#k(e,t,n))}#k(e,t,n){let r=this.#j(`committed`),i=this.#j(`may-have-committed`),a=String(this.#o.originalOperation),o=u(this.#t.extensionChain,`query`,this.#i,a);return(o===void 0||o.length===0)&&this.#u===void 0?this.#M(e,combineWriteNotifications(t,r),combineWriteNotifications(n,i)):this.#A(o,a,r,i,e,t,n)}#A(e,t,n,r,i,a,o){let c;try{c=this.#C()}catch(e){return Promise.reject(e)}let l=this.#b();return(e===void 0||e.length===0)&&l===void 0?this.#M(i,combineWriteNotifications(a,n),combineWriteNotifications(o,r)):executePreparedQuery(e===void 0||e.length===0?void 0:this.#w(this.#t.transactionWriteOutcomes?`transaction`:`direct`,c),e,e=>this.#M(i,combineWriteNotifications(a,combineWriteNotifications(e?.committed,n)),combineWriteNotifications(o,combineWriteNotifications(e?.mayHaveCommitted,r))),!s(t),this.#t.transactionWriteOutcomes,void 0,l)}#j(e){if(!(this.#t.transactionWriteOutcomes!==void 0||(this.#t.extensionChain?.observe.length??0)===0))return async()=>{(e===`committed`||this.#m===void 0)&&(this.#m=e)}}#M(e,t,n){return this.#c?this.#c(e,t,n):this.#N(e,t,n)}#N(e,t,n){let r;try{r=this.#x()}catch(e){return Promise.reject(e)}return r.execute({committedWriteSegment:t,context:this.#e.attribution,driverOverride:e,engineDriver:this.#t.driver,isWrite:!s(String(this.#o.originalOperation)),writeMayBeVisible:n})}getArgs(){return this.#r}cacheKeyArgs(){let e=this.#P();if(!e)throw new y(`Operation '${this.#a}' on model '${this.#i}' exposes no validated payload to key a cache entry on.`);return e}#P(){if(s(this.#a))return this.#x().preparedArgs}buildStatement(){return this.#x().buildStatement()}#F(e){let t=this.#p??={routed:this.#g},deferredExecution=(t,n,r)=>e((e,i,a)=>this.#M(e??t,combineWriteNotifications(i,n),combineWriteNotifications(a,r)),t);return new PendingOperation(B,this.#t,this.#n,this.#a,this.#r,this.#o,this.#e,deferredExecution,this.#l,t,this.#u)}then(e,t){return this.#E().then(e,t)}catch(e){return this.#E().catch(e)}finally(e){return this.#E().finally(e)}};function createPendingOperation(e,t,n,r,i,a,o){return createPendingOperationFriend(e,t,n,r,i,a,o)}function attachPendingCacheExecution(e,t){return attachPendingCacheExecutionFriend(e,t)}function readPendingCacheResult(e){return readPendingCacheResultFriend(e)}function isPendingOperation(e){return typeof e==`object`&&!!e&&z in e&&e[z]===!0}const U=`0viborm_distance`,W=`0viborm_relation_counts`,G=`0viborm_empty_row`,gateResultKey=e=>`0viborm_gate:${e}`,K=`0viborm_cursor_`,q=`0viborm_orphans`;function getAggregateResultKey(e){return`0viborm_aggregate:${e.slice(1)}`}function getAggregateResultName(e){switch(e){case`0viborm_aggregate:count`:return`_count`;case`0viborm_aggregate:avg`:return`_avg`;case`0viborm_aggregate:sum`:return`_sum`;case`0viborm_aggregate:min`:return`_min`;case`0viborm_aggregate:max`:return`_max`;default:return}}function getGroupByFields(e){let t=Array.isArray(e)?e.filter(e=>typeof e==`string`):typeof e==`string`?[e]:[];if(new Set(t).size!==t.length)throw new y(`GroupBy operation does not allow duplicate fields in 'by'`);return t}const J=new Set([`findFirst`,`findMany`,`findUnique`,`create`,`createManyAndReturn`,`update`,`updateManyAndReturn`,`delete`,`deleteManyAndReturn`,`upsert`]),Y=`Distance select supports only one _distance field per select.`;function selectedArm(e,t,r){let i=n(e)?e:void 0;if(!t)return getOwnValue(i,r)??!0;let a=getOwnValue(i,`only`);if(Array.isArray(a)&&!a.includes(r))return;let o=getOwnValue(i,`variants`);return(n(o)?getOwnValue(o,r):void 0)??!0}const X=[`_count`,`_avg`,`_sum`,`_min`,`_max`];function getOwnValue(e,t){return e&&Object.hasOwn(e,t)?e[t]:void 0}function createShape(e,t=new Map,n=new Map,r=new Set,i=new Map,a){if(new Set(e).size!==e.length)throw new y(`The requested result shape contains colliding output columns.`);return{carrier:`rows`,rawKeys:e,...a?{distanceScalar:a}:{},relations:t,polymorphic:i,aggregates:n,relationCounts:r}}function selectedEntries(e){return n(e)?Object.entries(e).filter(([,e])=>e!==!1&&e!==void 0):[]}function getNestedSelection(e){if(!n(e))return{};let t={},r=getOwnValue(e,`select`),i=getOwnValue(e,`include`);return n(r)&&(t.select=r),n(i)&&(t.include=i),t}function buildModelShape(e,t,r){let i=[],a=new Map,o=new Map,s=e[`~`].state.scalars,c=e[`~`].state.relations,l=getOwnValue(t,`select`),u=getOwnValue(t,`include`),d=n(l)?l:void 0,f=n(u)?u:void 0,p=!1,m;if(d)for(let[e,t]of Object.entries(d)){let r=getOwnValue(s,e);if(r){if(t===!0){i.push(e);continue}if(n(t)&&Object.hasOwn(t,`_distance`)){if(p)throw new y(Y);p=!0,m=r,i.push(U)}}}else for(let t of T(e))i.push(t);addSelectedRelations(e,c,d,i,a,r),addSelectedPolymorphicRelations(e,d,i,o,r),addSelectedRelations(e,c,f,i,a,r),addSelectedPolymorphicRelations(e,f,i,o,r);let h=[getOwnValue(d,`_count`),getOwnValue(f,`_count`)],g=new Set;for(let e of h){if(!n(e))continue;let t=getOwnValue(e,`select`);if(n(t))for(let[e]of selectedEntries(t)){let t=getOwnValue(c,e);if(!t)continue;let n=t[`~`].state;E(n)&&n.cardinality!==`many`||g.add(e)}}return g.size>0&&i.push(W),i.length===0&&i.push(G),createShape(i,a,new Map,g,o,m)}function admittedRecurrence(e){if(n(e))return getOwnValue(e,`recurse`)}function addSelectedRelations(e,t,n,r,i,a){for(let[o,s]of selectedEntries(n)){let n=getOwnValue(t,o);if(!n||E(n[`~`].state))continue;let c=n[`~`].settleTarget();r.push(o);let l=buildModelShape(c,getNestedSelection(s),a),u=a.get(e)?.get(o),d=admittedRecurrence(s);i.set(o,{model:c,shape:l,cardinality:n[`~`].state.cardinality,optional:u!==void 0&&w(u),...d?{recurrence:d}:{}})}}function addSelectedPolymorphicRelations(e,t,n,r,i){let a=e[`~`].state.relations;for(let[o,s]of selectedEntries(t)){let t=getOwnValue(a,o);if(!t)continue;let c=t[`~`].state;if(!E(c))continue;let l=c.cardinality===`many`,u=new Map;for(let e of Object.keys(c.target.entries)){let n=selectedArm(s,l,e);if(n===void 0)continue;let r=t[`~`].settleTarget(e);u.set(e,{model:r,shape:buildModelShape(r,getNestedSelection(n),i)})}n.push(o);let d=i.get(e)?.get(o);r.set(o,{cardinality:c.cardinality,optional:d!==void 0&&w(d),variants:u})}}function buildAggregateShape(e,t=[]){let n=[...t],r=new Set(t),i=new Map;for(let t of X){let a=getOwnValue(e,t);if(a===void 0||a===!1)continue;let o;if(!(t===`_count`&&a===!0)){let e=selectedEntries(a);if(e.length===0)continue;o=new Set(e.map(([e])=>e))}if(r.has(t))throw new y(`GroupBy cannot return both grouped scalar '${t}' and aggregate '${t}' in one result.`);let s=getAggregateResultKey(t);n.push(s),r.add(t),i.set(s,{...o?{fields:o}:{}})}return createShape(n,new Map,i)}function buildCountShape(e){let t=selectedEntries(getOwnValue(e,`select`)).map(([e])=>e);return{...createShape(t.length===0?[N]:t),carrier:`count`}}function buildExpectedResultShape(e,t,n,r){if(t===`count`)return buildCountShape(n);if(t===`exist`)return{...createShape([N]),carrier:`existence`};if(t===`aggregate`)return buildAggregateShape(n);if(t===`groupBy`)return buildAggregateShape(n,getGroupByFields(getOwnValue(n,`by`)));if(J.has(t))return buildModelShape(e,n,r)}export{decomposeQueryCoordinationFailure as C,TransactionWriteOutcomes as S,executePreparedQuery as T,PendingExecution as _,U as a,observeTransactionBatchPhase as b,W as c,H as d,attachPendingCacheExecution as f,snapshotQueryInput as g,readPendingCacheResult as h,K as i,gateResultKey as l,isPendingOperation as m,buildExpectedResultShape as n,G as o,createPendingOperation as p,selectedArm as r,q as s,Y as t,getAggregateResultName as u,createOperationExecutionContext as v,decomposeWriteOutcomePublicationFailure as w,withOperationErrorContext as x,createRawOperationInstrumentationFacts as y};
2
+ //# sourceMappingURL=result-shape-B6yWtnx_.mjs.map