UNPKG

prisma

Version:

Prisma is an open-source database toolkit. It includes a JavaScript/TypeScript ORM for Node.js, migrations and a modern GUI to view and edit the data in your database. You can use Prisma in new projects or add it to an existing one.

1 lines • 281 kB
var e=Object.defineProperty,t=Object.defineProperties,s=Object.getOwnPropertyDescriptors,i=Object.getOwnPropertySymbols,a=Object.prototype.hasOwnProperty,n=Object.prototype.propertyIsEnumerable,r=(t,s,i)=>s in t?e(t,s,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[s]=i,l=(e,t)=>{for(var s in t||(t={}))a.call(t,s)&&r(e,s,t[s]);if(i)for(var s of i(t))n.call(t,s)&&r(e,s,t[s]);return e},o=(e,i)=>t(e,s(i)),d=("undefined"!=typeof require&&require,(e,t)=>{var s={};for(var r in e)a.call(e,r)&&t.indexOf(r)<0&&(s[r]=e[r]);if(null!=e&&i)for(var r of i(e))t.indexOf(r)<0&&n.call(e,r)&&(s[r]=e[r]);return s});import{l as c,o as h,a as p,b as u,u as m,c as g,d as v,e as f,v as y,t as I,f as C,r as w,w as b,g as E,h as x,i as _,R as S,j as N,k as L,m as R,n as M,A as O,p as A,F as k}from"./vendor.js";var D=Object.defineProperty,T=Object.getOwnPropertyDescriptor;"undefined"!=typeof require&&require;var P=(e,t,s,i)=>{for(var a,n=i>1?void 0:i?T(t,s):t,r=e.length-1;r>=0;r--)(a=e[r])&&(n=(i?a(t,s,n):a(n))||n);return i&&n&&D(t,s,n),n};class V{constructor(){var e;this.transport={type:"http",url:`${window.location.origin}/api`},this.electron=!1,this.platform=(null==(e=window.meta)?void 0:e.platform)||"unknown",this.updates=!1,this.readonly=!1}async update(e){var t;c.exports.has(e,"transport")&&(this.transport=e.transport,this.electron="electron"===(null==(t=e.transport)?void 0:t.type)),c.exports.has(e,"electron")&&(this.electron=e.electron),c.exports.has(e,"platform")&&(this.platform=e.platform),c.exports.has(e,"updates")&&(this.updates=e.updates),c.exports.has(e,"readonly")&&(this.readonly=e.readonly)}}P([h],V.prototype,"transport",2),P([h],V.prototype,"electron",2),P([h],V.prototype,"platform",2),P([h],V.prototype,"updates",2),P([h],V.prototype,"readonly",2),P([p],V.prototype,"update",1);var j=new V;function F(e,t,s,i){Object.defineProperty(e,t,{get:s,set:i,enumerable:!0,configurable:!0})}var q={};F(q,"deserializeRPCMessage",(()=>H)),F(q,"serializeRPCMessage",(()=>B));function B(e){return JSON.stringify(e,((e,t)=>"bigint"==typeof t?"PrismaBigInt::"+t:"Buffer"===(null==t?void 0:t.type)&&Array.isArray(null==t?void 0:t.data)?"PrismaBytes::"+u.Buffer.from(t.data).toString("base64"):t))}function H(e){return JSON.parse(e,((e,t)=>"string"==typeof t&&t.startsWith("PrismaBigInt::")?BigInt(t.substr("PrismaBigInt::".length)):"string"==typeof t&&t.startsWith("PrismaBytes::")?t.substr("PrismaBytes::".length):t))}class Z{constructor(e){this.requestIdCounter=0,this.baseUrl=e}request(e){const t=new URL(this.baseUrl);return t.search=window.location.search,new Promise(((s,i)=>{const a=this.requestIdCounter;fetch(t.toString(),{method:"POST",headers:{"Content-Type":"application/json"},body:B({requestId:a,channel:e.channel,action:e.action,payload:e.payload})}).then((async e=>{if(200===e.status){const t=H(await e.text());return s(t.payload)}return console.error("Non-200 Status Code in HTTPTransport.send. Body:",e.body),i({message:`Error in HTTP Request (Status: ${e.status})`,stack:JSON.stringify(e.body,null,2)})})).catch((e=>(console.error("Unable to communicate with backend: ",e),i({message:"Unable to communicate with Prisma Client. Is Studio still running? You may need to restart it using `npx prisma studio`",stack:e})))),this.requestIdCounter++}))}}class z{constructor(){this.requestIdCounter=0}async request(e){if(!window.ipc)return Promise.reject();const t=this.requestIdCounter;this.requestIdCounter++;return H(await window.ipc.request({requestId:t,channel:e.channel,action:e.action,payload:e.payload})).payload}}class U{constructor(e){this.path=e.path,this.code=e.code,this.type=e.type,this.message=e.message,this.stack=e.stack,this.context=e.context||null,this.nativeError=e.nativeError}}const $=({path:e,message:t,code:s,type:i,stack:a,context:n,nativeError:r})=>{const l=new U({path:e,message:t,code:s,type:i,stack:a,context:n||null,nativeError:r});return console.error(`[${e}] ${t}`,n),console.error(r),l};class J{constructor(e,t){this.cursor=()=>this.db.transaction(this.storeName).store.openCursor(),this.transaction=e=>this.db.transaction(this.storeName,e),this.getAll=async({projectId:e}={})=>{const t=await this.db.getAllFromIndex(this.storeName,"createdAt");return e?t.filter((t=>t.projectId===e)):t},this.create=async e=>{try{await this.db.put(this.storeName,o(l({},e),{createdAt:(new Date).toISOString(),updatedAt:(new Date).toISOString()}))}catch(t){console.log("Error during PersistenceItem.create",t,this.storeName)}},this.update=async(e,t)=>{try{const t=await this.db.get(this.storeName,e);await this.db.put(this.storeName,o(l({},t),{updatedAt:(new Date).toISOString()}))}catch(s){console.log("Error during PersistenceItem.update",s,this.storeName)}},this.delete=async e=>{try{await this.db.delete(this.storeName,e)}catch(t){console.log("Error during PersistenceItem.delete",t,this.storeName)}},this.clear=async()=>{try{await this.db.clear(this.storeName)}catch(e){console.log("Error during PersistenceItem.clear",e,this.storeName)}},this.storeName=e,this.db=t}}const W=(e,t,s)=>{const i=a=>a===e.length?s&&s():t(e[a],(()=>i(a+1)));return i(0)};const K=[(e,t,s)=>(e.createObjectStore("projects",{keyPath:"id"}),e.createObjectStore("openTabs",{keyPath:"id"}),e.createObjectStore("sessions",{keyPath:"id"}),e.createObjectStore("scripts",{keyPath:"id"}),s()),(e,t,s)=>(e.createObjectStore("models",{keyPath:"id"}),e.createObjectStore("fields",{keyPath:"id"}),e.createObjectStore("enums",{keyPath:"id"}),s()),(e,t,s)=>{const i=t.objectStore("sessions"),a=t.objectStore("scripts"),n=i.getAll();n.onsuccess=()=>{const e=a.getAll();e.onsuccess=()=>{const t=n.result,r=e.result;W(t,((e,t)=>{const s=r.find((t=>t.id===e.scriptId));s?i.put(o(l({},e),{lastSavedHash:s.lastSavedHash||""})).onsuccess=t:e.lastSavedHash=""}),(()=>{W(r,((e,t)=>{delete e.lastSavedHash,a.put(e).onsuccess=t}),(()=>s()))}))}}},(e,t,s)=>{e.createObjectStore("tabs",{keyPath:"id"});const i=t.objectStore("openTabs"),a=t.objectStore("tabs"),n=i.getAll();n.onsuccess=()=>{const t=n.result;W(t,((e,t)=>{if(!e.sessionId)return t();e.preview=!1,a.put(e).onsuccess=t}),(()=>(e.deleteObjectStore("openTabs"),s())))}},(e,t,s)=>{const i=t.objectStore("tabs"),a=t.objectStore("projects"),n=i.getAll();n.onsuccess=()=>{const e=a.getAll();e.onsuccess=()=>{const t=n.result,i=e.result;W(i,((e,s)=>{e.tabOrder=t.filter((t=>t.projectId===e.id)).map((e=>e.id)),a.put(e).onsuccess=s}),(()=>s()))}}},(e,t,s)=>{const i=["tabs","sessions","scripts","models","fields","enums"],a={};W(i,((e,s)=>{const i=t.objectStore(e).getAll();i.onsuccess=()=>{a[e]=i.result,s()}}),(()=>{W(i,((s,i)=>{e.deleteObjectStore(s),e.createObjectStore(s,{keyPath:["id","projectId"]});const n=a[s];W(n,((e,i)=>{t.objectStore(s).put(e).onsuccess=i}),(()=>i()))}),(()=>(e.createObjectStore("actions",{keyPath:["id","projectId"]}),s())))}))},(e,t,s)=>{const i=t.objectStore("projects"),a=i.getAll();a.onsuccess=()=>{const e=a.result;W(e,((e,t)=>{e.theme="light",i.put(e).onsuccess=t}),(()=>s()))}},(e,t,s)=>{const i=t.objectStore("sessions"),a=t.objectStore("scripts"),n=i.getAll();n.onsuccess=()=>{const e=n.result;W(e,((e,t)=>{e.type=e.scriptId?"script":"fallback",i.put(e).onsuccess=t}),(()=>{const e=a.getAll();e.onsuccess=()=>{const t=e.result;W(t,((e,t)=>{e.generated=!1,a.put(e).onsuccess=t}),(()=>s()))}}))}},(e,t,s)=>{const i=t.objectStore("scripts"),a=i.getAll();a.onsuccess=()=>{const e=a.result;W(e,((e,t)=>{e.frozen=e.generated,delete e.generated,i.put(e).onsuccess=t}),(()=>s()))}},(e,t,s)=>(e.deleteObjectStore("models"),e.deleteObjectStore("fields"),e.deleteObjectStore("enums"),s()),(e,t,s)=>{const i=t.objectStore("projects");i.createIndex("createdAt","createdAt"),i.createIndex("updatedAt","updatedAt");const a=t.objectStore("actions");a.createIndex("createdAt","createdAt"),a.createIndex("updatedAt","updatedAt");const n=t.objectStore("scripts");n.createIndex("createdAt","createdAt"),n.createIndex("updatedAt","updatedAt");const r=t.objectStore("sessions");r.createIndex("createdAt","createdAt"),r.createIndex("updatedAt","updatedAt");const l=t.objectStore("tabs");l.createIndex("createdAt","createdAt"),l.createIndex("updatedAt","updatedAt");const o=i.getAll();return o.onsuccess=()=>{const e=o.result;W(e,((e,t)=>{delete e.tabOrder,e.createdAt=(new Date).toISOString(),e.updatedAt=(new Date).toISOString(),i.put(e).onsuccess=t}),(()=>{W([a,n,r,l],((e,t)=>{const s=e.getAll();s.onsuccess=()=>{const i=s.result;W(i,((t,s)=>{t.createdAt=(new Date).toISOString(),t.updatedAt=(new Date).toISOString(),e.put(t).onsuccess=s}),(()=>t()))}}),(()=>s()))}))},s()},(e,t,s)=>{const i=t.objectStore("projects");i.deleteIndex("createdAt"),i.createIndex("createdAt",["id","createdAt"]),i.deleteIndex("updatedAt"),i.createIndex("updatedAt",["id","updatedAt"]);const a=t.objectStore("actions");a.deleteIndex("createdAt"),a.createIndex("createdAt",["id","projectId","createdAt"]),a.deleteIndex("updatedAt"),a.createIndex("updatedAt",["id","projectId","updatedAt"]);const n=t.objectStore("scripts");n.deleteIndex("createdAt"),n.createIndex("createdAt",["id","projectId","createdAt"]),n.deleteIndex("updatedAt"),n.createIndex("updatedAt",["id","projectId","updatedAt"]);const r=t.objectStore("sessions");r.deleteIndex("createdAt"),r.createIndex("createdAt",["id","projectId","createdAt"]),r.deleteIndex("updatedAt"),r.createIndex("updatedAt",["id","projectId","updatedAt"]);const l=t.objectStore("tabs");return l.deleteIndex("createdAt"),l.createIndex("createdAt",["id","projectId","createdAt"]),l.deleteIndex("updatedAt"),l.createIndex("updatedAt",["id","projectId","updatedAt"]),s()},(e,t,s)=>{const i=t.objectStore("scripts"),a=i.getAll();a.onsuccess=()=>{const e=a.result;W(e,((e,t)=>{e.where=e.where.map((e=>(e.fieldIds=[e.fieldId],delete e.fieldId,e))),i.put(e).onsuccess=t}),(()=>s()))}}],Q=(e,t,s,i)=>{console.log("------Starting IndexedDB migration------");const a=m(i);W(K.slice(t),((t,s)=>t(e,a,s)),(()=>console.log("------IndexedDB migration complete------")))};var G=new class{constructor(){this.databaseName="Prisma Studio",this.indexedDBVersion=13,this.databaseInstance=null,this.projectId="",this.ready=!1,this.init=async({projectId:e})=>{try{this.projectId=e,this.databaseInstance=await g(this.databaseName,this.indexedDBVersion,{upgrade:Q}),this.projects=new J("projects",this.databaseInstance),this.tabs=new J("tabs",this.databaseInstance),this.sessions=new J("sessions",this.databaseInstance),this.scripts=new J("scripts",this.databaseInstance),this.actions=new J("actions",this.databaseInstance),this.ready=!0}catch(t){throw $({path:"PersistenceStore.init",message:"Unable to init PersistenceStore",nativeError:t})}},this.save=(e,t)=>new Promise((async(s,i)=>{if(!this.ready)throw $({path:"PersistenceStore.save",message:"PersistenceStore is not ready to receive `save` operations yet",context:{tableName:e,value:t}});try{switch(e){case"sessions":await this.sessions.create(t);break;case"scripts":await this.scripts.create(t);break;case"tabs":await this.tabs.create(t);break;case"projects":await this.projects.create(t);break;case"actions":await this.actions.create(t)}s()}catch(a){i(a)}})),this.load=async e=>new Promise((async(t,s)=>{if(!this.ready)throw $({path:"PersistenceStore.load",message:"PersistenceStore is not ready to receive `load` operations yet",context:{tableName:e}});try{switch(e){case"projects":return t(await this.projects.getAll());default:return t(await this[e].getAll({projectId:this.projectId}))}}catch(i){return s(i)}})),this.remove=async(e,t)=>new Promise((async(s,i)=>{if(!this.ready)throw $({path:"PersistenceStore.remove",message:"PersistenceStore is not ready to receive `remove` operations yet",context:{tableName:e,id:t}});try{switch(e){case"projects":return await this[e].delete(t),s();default:return await this[e].delete([t,this.projectId]),s()}}catch(a){return i(a)}})),this.clear=async e=>new Promise((async(t,s)=>{if(!this.ready)throw $({path:"PersistenceStore.clear",message:"PersistenceStore is not ready to receive `clear` operations yet",context:{tableName:e}});try{return await this[e].clear(),t()}catch(i){return s(i)}})),this.clearAll=async()=>{var e;null==(e=this.databaseInstance)||e.close(),await v(this.databaseName)}}},Y=Object.defineProperty,X=Object.getOwnPropertyDescriptor;"undefined"!=typeof require&&require;var ee=(e,t,s,i)=>{for(var a,n=i>1?void 0:i?X(t,s):t,r=e.length-1;r>=0;r--)(a=e[r])&&(n=(i?a(t,s,n):a(n))||n);return i&&n&&Y(t,s,n),n};class te{constructor(e,{idbTableName:t}={}){this.idbTableName=null,this.members={},this.type=e,this.idbTableName=null!=t?t:null}get values(){return this.members}get size(){return Object.keys(this.members).length}async restore(){if(this.idbTableName){(await G.load(this.idbTableName)).forEach((e=>{e?this.add(e,{skipPersist:!0}):console.warn("Attempt to restore a null member from IndexedDB, ignoring",{member:e,idbTableName:this.idbTableName})}))}return Promise.resolve()}get(e){return e&&this.members[e]||null}add(e,{skipPersist:t=!1}={}){let s;if(e.id||(e.id=y()),this.members[e.id])s=this.members[e.id],s.update(e,{skipPersist:t});else{s=new(0,this.type)(e),s.idbTableName=this.idbTableName,this.members[e.id]=s,!t&&this.idbTableName&&G.save(this.idbTableName,s.serialize())}return s}remove(e){const t=this.members[e];return t&&delete this.members[e],this.idbTableName&&G.remove(this.idbTableName,e),t}clear(){this.members={},this.idbTableName&&G.clear(this.idbTableName)}toJS(){return I(this)}}ee([h],te.prototype,"type",2),ee([h],te.prototype,"idbTableName",2),ee([h],te.prototype,"members",2),ee([f],te.prototype,"values",1),ee([f],te.prototype,"size",1),ee([p],te.prototype,"restore",1),ee([p],te.prototype,"add",1),ee([p],te.prototype,"remove",1),ee([p],te.prototype,"clear",1),ee([p],te.prototype,"toJS",1);var se=Object.defineProperty,ie=Object.getOwnPropertyDescriptor;"undefined"!=typeof require&&require;var ae=(e,t,s,i)=>{for(var a,n=i>1?void 0:i?ie(t,s):t,r=e.length-1;r>=0;r--)(a=e[r])&&(n=(i?a(t,s,n):a(n))||n);return i&&n&&se(t,s,n),n};class ne{constructor(e){this.forceUpdate=async()=>{await G.save(this.idbTableName,this.serialize())},this.id=e.id}update(e,{skipPersist:t=!1}={}){if(!t&&this.idbTableName){const t=this.serialize(),s=Object.keys(t),i=Object.keys(e);new Set([...s,...i]).size!==s.length+i.length&&this.forceUpdate()}}serialize(){}}ae([h],ne.prototype,"id",2),ae([h],ne.prototype,"idbTableName",2),ae([p],ne.prototype,"update",1),ae([p],ne.prototype,"forceUpdate",2);var re=Object.defineProperty,le=Object.getOwnPropertyDescriptor;"undefined"!=typeof require&&require;var oe=(e,t,s,i)=>{for(var a,n=i>1?void 0:i?le(t,s):t,r=e.length-1;r>=0;r--)(a=e[r])&&(n=(i?a(t,s,n):a(n))||n);return i&&n&&re(t,s,n),n};class de{constructor(){const e=window.matchMedia("(prefers-color-scheme: dark)");let t=localStorage.getItem("theme");this.theme=t||(e.matches?"dark":"light"),window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",(e=>this.apply(e.matches?"dark":"light")))}apply(e){this.theme=e;const t=window.matchMedia("(prefers-color-scheme: dark)");t.matches&&"light"===this.theme||!t.matches&&"dark"===this.theme?localStorage.setItem("theme",this.theme):localStorage.removeItem("theme")}hydrate(e){this.apply(e)}}oe([h],de.prototype,"theme",2),oe([p],de.prototype,"apply",1),oe([p],de.prototype,"hydrate",1);var ce=new de;var he=Object.defineProperty,pe=Object.getOwnPropertyDescriptor;"undefined"!=typeof require&&require;var ue=(e,t,s,i)=>{for(var a,n=i>1?void 0:i?pe(t,s):t,r=e.length-1;r>=0;r--)(a=e[r])&&(n=(i?a(t,s,n):a(n))||n);return i&&n&&he(t,s,n),n};class me extends ne{constructor(e){super(e),this.id=e.id,this.name=e.name,this.values=e.values}update(e,t={}){c.exports.has(e,"name")&&(this.name=e.name),c.exports.has(e,"values")&&(this.values=e.values),super.update(e,t)}}ue([h],me.prototype,"id",2),ue([h],me.prototype,"name",2),ue([h],me.prototype,"values",2),ue([p],me.prototype,"update",1);var ge=Object.defineProperty,ve=Object.getOwnPropertyDescriptor;"undefined"!=typeof require&&require;class fe extends te{constructor(){super(me),this.getByName=e=>this.get(e)}add(e,t={}){return super.add(l({id:e.name},e),t)}}((e,t,s,i)=>{for(var a,n=i>1?void 0:i?ve(t,s):t,r=e.length-1;r>=0;r--)(a=e[r])&&(n=(i?a(t,s,n):a(n))||n);i&&n&&ge(t,s,n)})([p],fe.prototype,"add",1);var ye=new fe,Ie=Object.defineProperty,Ce=Object.getOwnPropertyDescriptor;"undefined"!=typeof require&&require;var we=(e,t,s,i)=>{for(var a,n=i>1?void 0:i?Ce(t,s):t,r=e.length-1;r>=0;r--)(a=e[r])&&(n=(i?a(t,s,n):a(n))||n);return i&&n&&Ie(t,s,n),n};class be extends ne{constructor(e){if(super(e),this.id=e.id,this.modelId=e.modelId,this.name=e.name,this.type=e.type,this.kind=e.kind,"Json"===this.type&&"string"==typeof e.default)try{this.default=JSON.parse(e.default)}catch(t){this.default=e.default}else if("BigInt"===this.type&&"string"==typeof e.default)try{this.default=BigInt(e.default)}catch(t){this.default=e.default}else this.default=e.default;this.isId=e.isId,this.isUnique=e.isUnique,this.isRequired=e.isRequired,this.isList=e.isList,this.isReadOnly=e.isReadOnly,this.isUpdatedAt=e.isUpdatedAt,this.relationName=e.relationName,this.relationFromFieldNames=e.relationFromFieldNames,this.relationToFieldNames=e.relationToFieldNames}get model(){return ke.get(this.modelId)}get isScalar(){return"scalar"===this.kind&&!this.isEnum}get isString(){return"String"===this.type}get isInt(){return"Int"===this.type}get isBigInt(){return"BigInt"===this.type}get isFloat(){return"Float"===this.type}get isDecimal(){return"Decimal"===this.type}get isBoolean(){return"Boolean"===this.type}get isDateTime(){return"DateTime"===this.type}get isJson(){return"Json"===this.type}get isBytes(){return"Bytes"===this.type}get isEnum(){return!!this.typeAsEnum}get isRelation(){return"object"===this.kind}get isPartOfRelation(){return null!==this.relationItIsPartOf}get relationItIsPartOf(){return this.model&&this.model.fields.find((e=>e.isRelation&&e.relationFromFieldNames.includes(this.name)))||null}get isSortable(){return this.isScalar&&!this.isList||this.isEnum&&!this.isList}get isFunctionDefault(){return"string"!=typeof this.default&&"number"!=typeof this.default&&"boolean"!=typeof this.default&&"bigint"!=typeof this.default&&!c.exports.isArray(this.default)}get defaultAsString(){return this.isList?"[]":this.default?"string"==typeof this.default||"number"==typeof this.default||"boolean"==typeof this.default?`${this.default}`:"bigint"==typeof this.default||c.exports.isArray(this.default)?this.default.toString():c.exports.isObject(this.default)?`${this.default.name}()`:"":""}get placeholder(){return this.isList?"[]":this.isString?"Value":this.isInt||this.isFloat||this.isBigInt||this.isDecimal?"1337":this.isBoolean?"false":this.isDateTime?(new Date).toISOString():this.isJson?"{}":this.isEnum?this.typeAsEnum.values[0]:this.isRelation?"ID":"Value"}get typeAsModel(){return this.isRelation?ke.getByName(this.type):null}get typeAsEnum(){return ye.getByName(this.type)}get typeAsLabel(){let e=this.type;const t=this.typeAsModel;return t&&(e=t.name),this.isList?e+="[]":this.isRequired||(e+="?"),e}get lowestValidValue(){if(this.isList)return[];if(!this.isRequired)return null;if(this.isString)return"";if(this.isInt||this.isFloat||this.isDecimal)return 0;if(this.isBigInt)return BigInt(0);if(this.isBoolean)return!1;if(this.isDateTime)return new Date(0).toISOString();if(this.isJson)return{};if(this.isEnum){if(!this.typeAsEnum)throw $({path:"Field.lowestValidValue",message:"Invalid type of field: enum",context:{fieldId:this.id,type:this.type}});return this.typeAsEnum.values[0]}return null}update(e,t={}){c.exports.has(e,"default")&&(this.default=e.default),c.exports.has(e,"isId")&&(this.isId=e.isId),c.exports.has(e,"isUnique")&&(this.isUnique=e.isUnique),c.exports.has(e,"isRequired")&&(this.isRequired=e.isRequired),c.exports.has(e,"isList")&&(this.isList=e.isList),c.exports.has(e,"isReadOnly")&&(this.isReadOnly=e.isReadOnly),c.exports.has(e,"isUpdatedAt")&&(this.isUpdatedAt=e.isUpdatedAt),super.update(e,t)}}we([h],be.prototype,"id",2),we([h],be.prototype,"modelId",2),we([h],be.prototype,"name",2),we([h],be.prototype,"type",2),we([h],be.prototype,"kind",2),we([h],be.prototype,"default",2),we([h],be.prototype,"isId",2),we([h],be.prototype,"isUnique",2),we([h],be.prototype,"isRequired",2),we([h],be.prototype,"isList",2),we([h],be.prototype,"isReadOnly",2),we([h],be.prototype,"isUpdatedAt",2),we([h],be.prototype,"relationName",2),we([h],be.prototype,"relationFromFieldNames",2),we([h],be.prototype,"relationToFieldNames",2),we([f],be.prototype,"model",1),we([f],be.prototype,"isScalar",1),we([f],be.prototype,"isString",1),we([f],be.prototype,"isInt",1),we([f],be.prototype,"isBigInt",1),we([f],be.prototype,"isFloat",1),we([f],be.prototype,"isDecimal",1),we([f],be.prototype,"isBoolean",1),we([f],be.prototype,"isDateTime",1),we([f],be.prototype,"isJson",1),we([f],be.prototype,"isBytes",1),we([f],be.prototype,"isEnum",1),we([f],be.prototype,"isRelation",1),we([f],be.prototype,"isPartOfRelation",1),we([f],be.prototype,"relationItIsPartOf",1),we([f],be.prototype,"isSortable",1),we([f],be.prototype,"isFunctionDefault",1),we([f],be.prototype,"defaultAsString",1),we([f],be.prototype,"placeholder",1),we([f],be.prototype,"typeAsModel",1),we([f],be.prototype,"typeAsEnum",1),we([f],be.prototype,"typeAsLabel",1),we([f],be.prototype,"lowestValidValue",1),we([p],be.prototype,"update",1);const Ee=(e,t)=>`${e}.${t}`;var xe=new class extends te{constructor(){super(be)}getByName(e,t){return this.get(Ee(t,e))}};const _e=({modelId:e})=>{const t=ke.get(e);if(!t)throw $({path:"getCountQuery",message:"Invalid modelId",context:{modelId:e}});return`prisma.${t.prismaQueryNamespace}.count()`};var Se=Object.defineProperty,Ne=Object.getOwnPropertyDescriptor;"undefined"!=typeof require&&require;var Le=(e,t,s,i)=>{for(var a,n=i>1?void 0:i?Ne(t,s):t,r=e.length-1;r>=0;r--)(a=e[r])&&(n=(i?a(t,s,n):a(n))||n);return i&&n&&Se(t,s,n),n};class Re extends ne{constructor(e){super(e),this.getFieldByName=e=>xe.getByName(e,this.id),this.runCountQuery=async()=>{try{const{error:e,data:t}=await window.transport.request({channel:"prisma",action:"clientRequest",payload:{data:{schemaHash:Ds.activeProject.schemaHash,query:_e({modelId:this.id})}}});if(e||!t)throw e;if(Array.isArray(t))throw new Error(`Malformed response for \`count\` query: ${JSON.stringify(t,null,2)} `);const s=parseInt(t.response);this.update({count:s})}catch(e){console.log("Count request failed for model:",this.name,e),this.update({count:0})}},this.id=e.id,this.dbName=e.dbName,this.name=e.name,this.plural=e.plural,this.count=null,this.fieldIds=e.fieldIds||[],this.idFieldIds=e.idFieldIds||[],this.uniqueFieldIds=e.uniqueFieldIds||[]}get fields(){return this.fieldIds.map((e=>{const t=xe.get(e);if(!t)throw $({path:"Model.field",message:"Invalid fieldId",context:{fieldId:e}});return t}))}get uniqueIdentifiers(){if(this.idField)return[this.idField];if(this.compoundIdFields.length>0)return this.compoundIdFields;const e=this.uniqueFields&&this.uniqueFields[0];if(e)return[e];if(this.compoundUniqueFields.length>0)return this.compoundUniqueFields;throw $({path:"ModelStore.uniqueIdentifiers",message:"Unable to resolve unique identifiers for model",context:{modelId:this.id}})}get idField(){return this.fields.find((e=>e.isId))||null}get uniqueFields(){return this.fields.filter((e=>e.isUnique))}get compoundIdFields(){return this.idFieldIds.map((e=>{const t=xe.get(e);if(!t)throw $({path:"Model.compoundIdFields",message:"Invalid fieldId in idFieldIds",context:{fieldId:e}});return t}))}get compoundUniqueFields(){return this.uniqueFieldIds.map((e=>{const t=xe.get(e);if(!t)throw $({path:"Model.uniqueIdentifiers",message:"Invalid fieldId in uniqueFieldIds",context:{fieldId:e}});return t}))}get prismaQueryNamespace(){return this.name.charAt(0).toLowerCase()+this.name.slice(1)}update(e,t={}){c.exports.has(e,"name")&&(this.name=e.name),c.exports.has(e,"plural")&&(this.plural=e.plural),c.exports.has(e,"count")&&(this.count=e.count),c.exports.has(e,"fieldIds")&&(this.fieldIds=e.fieldIds),c.exports.has(e,"idFieldIds")&&(this.idFieldIds=e.idFieldIds),c.exports.has(e,"uniqueFieldIds")&&(this.uniqueFieldIds=e.uniqueFieldIds),super.update(e,t)}}Le([h],Re.prototype,"id",2),Le([h],Re.prototype,"dbName",2),Le([h],Re.prototype,"name",2),Le([h],Re.prototype,"plural",2),Le([h],Re.prototype,"count",2),Le([h],Re.prototype,"fieldIds",2),Le([h],Re.prototype,"idFieldIds",2),Le([h],Re.prototype,"uniqueFieldIds",2),Le([f],Re.prototype,"fields",1),Le([f],Re.prototype,"uniqueIdentifiers",1),Le([f],Re.prototype,"idField",1),Le([f],Re.prototype,"uniqueFields",1),Le([f],Re.prototype,"compoundIdFields",1),Le([f],Re.prototype,"compoundUniqueFields",1),Le([f],Re.prototype,"prismaQueryNamespace",1),Le([p],Re.prototype,"runCountQuery",2),Le([p],Re.prototype,"update",1);var Me=Object.defineProperty,Oe=Object.getOwnPropertyDescriptor;"undefined"!=typeof require&&require;class Ae extends te{constructor(){super(Re)}add(e,t={}){const s=e.name;return super.add(o(l({},e),{id:s}),t)}getByName(e){return this.get(e)}}((e,t,s,i)=>{for(var a,n=i>1?void 0:i?Oe(t,s):t,r=e.length-1;r>=0;r--)(a=e[r])&&(n=(i?a(t,s,n):a(n))||n);i&&n&&Me(t,s,n)})([p],Ae.prototype,"add",1);var ke=new Ae;const De=(e,t)=>{if(null==t)throw $({path:"getRecordId",message:"Invalid recordValue",context:{modelId:e,recordValue:t}});const s=ke.get(e);if(!s)throw $({path:"getRecordId",message:"Invalid modelId",context:{modelId:e}});let i=`${e}::`;return i+=s.uniqueIdentifiers.map((e=>null===t[e.name]?"null":void 0===t[e.name]?"undefined":t[e.name])).join(","),i};var Te=Object.defineProperty,Pe=Object.getOwnPropertyDescriptor;"undefined"!=typeof require&&require;var Ve=(e,t,s,i)=>{for(var a,n=i>1?void 0:i?Pe(t,s):t,r=e.length-1;r>=0;r--)(a=e[r])&&(n=(i?a(t,s,n):a(n))||n);return i&&n&&Te(t,s,n),n};class je{constructor(){this.updateError=(e={})=>{c.exports.has(e,"visible")&&(this.error.visible=e.visible)},this.updateActions=(e={})=>{c.exports.has(e,"visible")&&(this.actions.visible=e.visible)},this.error={visible:!1},this.actions={visible:!1}}}Ve([h],je.prototype,"error",2),Ve([h],je.prototype,"actions",2),Ve([p],je.prototype,"updateError",2),Ve([p],je.prototype,"updateActions",2);var Fe=new je,qe=Object.defineProperty,Be=Object.getOwnPropertyDescriptor;"undefined"!=typeof require&&require;class He{send(e){window.transport.request({channel:"telemetry",action:"send",payload:{data:{command:e.command,commandDetails:JSON.stringify(e.commandDetails),commandContext:JSON.stringify({model_count:ke.size})}}})}}((e,t,s,i)=>{for(var a,n=i>1?void 0:i?Be(t,s):t,r=e.length-1;r>=0;r--)(a=e[r])&&(n=(i?a(t,s,n):a(n))||n);i&&n&&qe(t,s,n)})([p],He.prototype,"send",1);var Ze=new He,ze=Object.defineProperty,Ue=Object.getOwnPropertyDescriptor;"undefined"!=typeof require&&require;var $e=(e,t,s,i)=>{for(var a,n=i>1?void 0:i?Ue(t,s):t,r=e.length-1;r>=0;r--)(a=e[r])&&(n=(i?a(t,s,n):a(n))||n);return i&&n&&ze(t,s,n),n};class Je{constructor(){this.type="fatal",this.description=null,this.dump=null}update(e){this.type=e.type,this.description=e.description,this.dump=e.dump,Ze.send({command:"error_throw",commandDetails:{type:this.type,description:this.description}})}}$e([h],Je.prototype,"type",2),$e([h],Je.prototype,"description",2),$e([h],Je.prototype,"dump",2),$e([p],Je.prototype,"update",1);var We=new Je;function Ke(e){return Array(2*e).fill(" ").join("")}function Qe(e,t=1){return void 0===e?"undefined":null===e?"null":e instanceof Date||e instanceof C.Buffer||e instanceof Uint8Array||"object"!=typeof e?"string"==typeof(s=e)?`"${s.replace(/"/g,'\\"').replace(/'/g,"\\'")}"`:"bigint"==typeof s?`BigInt(${s})`:s instanceof Date?`"${s.toISOString()}"`:s instanceof C.Buffer?`Buffer.from("${s.toString("base64")}", "base64")`:s instanceof Uint8Array?`Buffer.from("${C.Buffer.from(s).toString("base64")}", "base64")`:`${s}`:Array.isArray(e)?["[",e.map((e=>[Ke(t),Qe(e,t+1),","].join(""))).join("\n"),Ke(t-1)+"]"].join("\n"):["{",Object.entries(e).map((([e,s])=>[Ke(t),e,": ",Qe(s,t+1),","].join(""))).join("\n"),Ke(t-1)+"}"].join("\n");var s}const Ge=e=>{const t=[];return e.filter((e=>"delete"===e.type)).forEach((s=>{if(!s.record)throw $({path:"prismaQueriesFromActions._delete",message:"Unrecognized Record in Action",context:{action:s.serialize()}});const i=s.record.model,a={where:tt(s)};t.push([`prisma.${i.prismaQueryNamespace}.delete(`,`${Qe(a)}`,")"].join("\n")),e=e.filter((e=>s.id!==e.id&&s.recordId!==e.recordId))})),{actions:e,requests:t}},Ye=e=>{const t=[];return e.filter((e=>"create"===e.type)).forEach((s=>{if(!s.record)throw $({path:"prismaQueriesFromActions._create",message:"Unrecognized Record in Action",context:{action:s.serialize()}});const i=s.record.model,a={data:{},select:et(s)},n=e.find((e=>"update"===e.type&&e.sessionId===s.sessionId&&e.recordId===s.recordId));n&&(a.data=it(n),a.select=l(l({},a.select),et(n))),t.push([`prisma.${i.prismaQueryNamespace}.create(`,`${Qe(a)}`,")"].join("\n")),e=e.filter((e=>e.id!==(null==n?void 0:n.id)&&s.id!==e.id))})),{actions:e,requests:t}},Xe=e=>{const t=[];return e.filter((e=>"update"===e.type)).forEach((s=>{if(!s.record)throw $({path:"prismaQueriesFromActions._update",message:"Unrecognized Record in Action",context:{action:s.serialize()}});const i=s.record.model,a={where:tt(s),data:st(s),select:et(s)};t.push([`prisma.${i.prismaQueryNamespace}.update(`,`${Qe(a)}`,")"].join("\n")),e=e.filter((e=>s.id!==e.id))})),{actions:e,requests:t}},et=e=>{if(!e.record)throw $({path:"prismaQueriesFromActions._getRequestSelectArgument",message:"Unrecognized Record in Action",context:{action:e.serialize()}});const t=e.record.model.uniqueIdentifiers.reduce(((e,t)=>(e[t.name]=!0,e)),{});return"create"===e.type||"delete"===e.type?t:Object.keys(e.value).reduce(((e,t)=>(e[t]=!0,e)),t)},tt=e=>{if(!e.record)throw $({path:"prismaQueriesFromActions._getRequestWhereArgument",message:"Unrecognized Record in Action",context:{action:e.serialize()}});const t=e.record.model.uniqueIdentifiers,s=t.map((e=>e.name)).join("_"),i=t.reduce(((t,s)=>(t[s.name]=e.record.valueInDB[s.name],t)),{});return 1===t.length?i:{[s]:i}},st=e=>{if(!e.record)throw $({path:"prismaQueriesFromActions._getUpdateRequestDataArgument",message:"Unrecognized Record in Action",context:{action:e.serialize()}});const t=e.record.model;return Object.keys(e.value).reduce(((s,i)=>{const a=t.getFieldByName(i),n=e.value[i];if(!a)throw $({path:"prismaQueriesFromActions._getUpdateRequestDataArgument",message:"Malformed field in action",context:{action:e.serialize()}});if(a.isReadOnly)return s;if(void 0===n)return s;if(a.isScalar&&a.isList||a.isEnum&&a.isList)s[i]={set:n};else if(a.isScalar||a.isEnum)s[i]=n;else if(a.isList&&a.isRelation){if(!a.typeAsModel)throw $({path:"prismaQueriesFromActions._getUpdateRequestDataArgument",message:"Invalid field type",context:{field:a.serialize()}});const t=(e.record.valueInDB[i]||[]).map((e=>De(a.typeAsModel.id,e))),r=n.map((e=>De(a.typeAsModel.id,e))),l=c.exports.difference(r,t),o=c.exports.difference(t,r);s[i]={},c.exports.isEmpty(l)||(s[i].connect=l.map(((e,t)=>{const s=Jt.get(e)||Jt.add({id:e,modelId:a.typeAsModel.id,value:n[t]}),i=s.model.uniqueIdentifiers,r=i.map((e=>e.name)).join("_"),l=i.reduce(((e,t)=>(e[t.name]=s.valueInDB[t.name],e)),{});return 1===i.length?l:{[r]:l}}))),c.exports.isEmpty(o)||(s[i].disconnect=o.map(((t,s)=>{const i=Jt.get(t);if(!i)throw $({path:"prismaQueriesFromActions._getUpdateRequestDataArgument",message:"Attempting to disconnect a non-existent record",context:{action:e.serialize(),index:s}});const a=i.model.uniqueIdentifiers,n=a.map((e=>e.name)).join("_"),r=a.reduce(((e,t)=>(e[t.name]=i.valueInDB[t.name],e)),{});return 1===a.length?r:{[n]:r}})))}else if(a.isRelation)if(null===n)s[i]={disconnect:!0};else{if(!a.typeAsModel)throw $({path:"prismaQueriesFromActions._getUpdateRequestDataArgument",message:"Invalid field type",context:{field:a.serialize()}});const e=De(a.typeAsModel.id,n),t=Jt.get(e)||Jt.add({id:e,modelId:a.typeAsModel.id,value:n}),r=t.model.uniqueIdentifiers,l=r.map((e=>e.name)).join("_"),o=r.reduce(((e,s)=>(e[s.name]=t.valueInDB[s.name],e)),{});1===r.length?s[i]={connect:o}:s[i]={connect:{[l]:o}}}return s}),{})},it=e=>{const t=st(e);return Object.keys(t).forEach((s=>{if(!e.record)throw $({path:"prismaQueriesFromActions._getCreateRequestDataArgument",message:"Unrecognized Record in Action",context:{action:e.serialize()}});const i=e.record.model.getFieldByName(s);if(!i)throw $({path:"prismaQueriesFromActions._getUpdateRequestDataArgument",message:"Malformed field in action",context:{action:e.serialize()}});i.isRelation&&!i.isList&&t[s].disconnect&&delete t[s],i.isRelation&&i.isList&&t[s].disconnect&&delete t[s].disconnect})),t};var at=Object.defineProperty,nt=Object.getOwnPropertyDescriptor;"undefined"!=typeof require&&require;var rt=(e,t,s,i)=>{for(var a,n=i>1?void 0:i?nt(t,s):t,r=e.length-1;r>=0;r--)(a=e[r])&&(n=(i?a(t,s,n):a(n))||n);return i&&n&&at(t,s,n),n};class lt{constructor(e){this.update=e=>{c.exports.has(e,"selectedRecordIds")&&(this.selectedRecordIds=e.selectedRecordIds)},this.sessionId=e.sessionId,this.selectedRecordIds=[]}get session(){return _t.get(this.sessionId)}get maxRows(){var e,t;return(null==(t=null==(e=this.session)?void 0:e.script)?void 0:t.recordIds.length)||0}get maxColumns(){var e,t;return(null==(t=null==(e=this.session)?void 0:e.script)?void 0:t.fieldIds.length)||0}get selectedRecords(){return this.selectedRecordIds.map((e=>Jt.get(e)))}}rt([h],lt.prototype,"sessionId",2),rt([h],lt.prototype,"selectedRecordIds",2),rt([f],lt.prototype,"session",1),rt([f],lt.prototype,"maxRows",1),rt([f],lt.prototype,"maxColumns",1),rt([f],lt.prototype,"selectedRecords",1),rt([p],lt.prototype,"update",2);const ot=(e,t)=>{const s=e.split("::"),i=Number(s[0].slice(1,-1));if(isNaN(i))throw $({path:"parseTreePath",message:"Invalid tree path: Failed to parse segment as index",context:{path:e,recordIdx:i}});const a=Jt.get(t[i]);if(!a)throw $({path:"parseTreePath",message:"Invalid tree path: Invalid record index",context:{path:e,recordIdx:i}});return s.slice(1).reduce((({model:t,field:s,index:i,record:a,value:n,arraySliceIndices:r},l)=>{var o,d,c,h,p,u;if(l.startsWith("[")&&l.endsWith("]"))if(s=null,i=Number(l.slice(1,-1)),isNaN(i)){const e=l.slice(1,-1).split("-");r=[Number(e[0]),Number(e[1])],i=null,a=null,n=n.slice(r[0],r[1]+1)}else if(t){const c=De(t.id,n[i]);if(!c)throw $({path:"parseTreePath",message:"Invalid tree path: Failed to parse tree path segment as array",context:{path:e,fieldName:l,recordId:c,accumulator:{model:t,field:s,index:i,record:a,value:n,arraySliceIndices:r}}});n=null!=(d=null==(a=null!=(o=Jt.get(c))?o:null)?void 0:a.value)?d:null}else a=null,n=null!=(c=n[i])?c:null;else{if(!t)throw $({path:"parseTreePath",message:"Invalid tree path: Failed to parse tree path segment as field name",context:{path:e,fieldName:l,accumulator:{model:t,field:s,index:i,record:a,value:n,arraySliceIndices:r}}});if(!(s=t.getFieldByName(l)))throw $({path:"parseTreePath",message:"Invalid field name",context:{path:e,fieldName:l,accumulator:{model:t,field:s,index:i,record:a,value:n,arraySliceIndices:r}}});if(t=null!=(h=s.typeAsModel)?h:null,i=null,a=null,n=n[l],r=null,!s.isScalar&&!s.isEnum&&!Array.isArray(n)&&null!=n){const o=t&&De(t.id,n);if(!o)throw $({path:"parseTreePath",message:"Invalid tree path: Failed to parse tree path segment as relation",context:{path:e,fieldName:l,recordId:o,accumulator:{model:t,field:s,index:i,record:a,value:n,arraySliceIndices:r}}});n=null!=(u=null==(a=null!=(p=Jt.get(o))?p:null)?void 0:a.value)?u:null}}return{model:t,field:s,index:i,record:a,value:n,arraySliceIndices:r}}),{model:a.model,field:null,index:null,record:a,value:a.value,arraySliceIndices:null})};var dt=Object.defineProperty,ct=Object.getOwnPropertyDescriptor;"undefined"!=typeof require&&require;var ht=(e,t,s,i)=>{for(var a,n=i>1?void 0:i?ct(t,s):t,r=e.length-1;r>=0;r--)(a=e[r])&&(n=(i?a(t,s,n):a(n))||n);return i&&n&&dt(t,s,n),n};class pt{constructor(e){this.selectionOrder=[],this.isExpanded=e=>this.expandedPaths.includes(e),this.select=e=>{this.activePath=e},this.move=(e,t)=>{0===this.selectionOrder.length&&this.setSelectionOrder();const s=this.selectionOrder.findIndex((e=>e===this.activePath));let i;switch(t){case"up":i=this.selectionOrder[s-e];break;case"down":i=this.selectionOrder[s+e]}this.activePath=i||"[0]"},this.expand=()=>{var e,t;if(this.isExpanded(this.activePath))return;if(!(null==(e=this.session)?void 0:e.script))throw $({path:"SessionSelectionTree.expand",message:"Unable to resolve recordIds",context:{sessionId:this.sessionId,scriptId:null==(t=this.session)?void 0:t.scriptId}});const{record:s,value:i,field:a}=ot(this.activePath,this.session.script.recordIds);null!=i&&((null==a?void 0:a.isList)||!(null==a?void 0:a.isScalar)&&!(null==a?void 0:a.isEnum))&&0!==(null==i?void 0:i.length)&&(this.expandedPaths.push(this.activePath),this.setSelectionOrder(),s&&s.fetchRelations())},this.collapse=()=>{this.expandedPaths=this.expandedPaths.filter((e=>!e.startsWith(this.activePath))),this.setSelectionOrder()},this.update=e=>{c.exports.has(e,"isEditing")&&(this.isEditing=e.isEditing)},this.reset=()=>{this.isEditing=!1},this.sessionId=e.sessionId,this.isEditing=e.isEditing,this.activePath="",this.expandedPaths=[]}get session(){return _t.get(this.sessionId)}jumpToParent(){const e=this.activePath.split("::").slice(0,-1).join("::");""!=e&&(this.activePath=e)}setSelectionOrder(){var e,t;if(!(null==(e=this.session)?void 0:e.script))throw $({path:"SessionSelectionTree.setSelectionOrder",message:"Unable to resolve recordIds",context:{sessionId:this.sessionId,scriptId:null==(t=this.session)?void 0:t.scriptId}});const{recordIds:s}=this.session.script;let i=s.map(((e,t)=>`[${t}]`));this.expandedPaths.forEach((e=>{const{value:t,model:a}=ot(e,s),n=i.findIndex((t=>t===e)),r=[];if(r.push(i[n]),Array.isArray(t))if(t.length<=100)r.push(...Array.from({length:t.length}).map(((t,s)=>`${e}::[${s}]`)));else{const s=Math.floor(t.length/100);r.push(...Array.from({length:s}).map(((t,s)=>`${e}::[${100*s}-${100*(s+1)-1}]`))),t.length%100!=0&&r.push(`${e}::[${100*s}-${100*s+t.length%100-1}]`)}else null!==t&&a&&r.push(...a.fields.map((t=>`${e}::${t.name}`)));i=[...i.slice(0,n),...r,...i.slice(n+1)]})),this.selectionOrder=i}}ht([h],pt.prototype,"sessionId",2),ht([h],pt.prototype,"isEditing",2),ht([h],pt.prototype,"activePath",2),ht([h],pt.prototype,"expandedPaths",2),ht([h],pt.prototype,"selectionOrder",2),ht([f],pt.prototype,"session",1),ht([p],pt.prototype,"select",2),ht([p],pt.prototype,"move",2),ht([p],pt.prototype,"expand",2),ht([p],pt.prototype,"collapse",2),ht([p],pt.prototype,"jumpToParent",1),ht([p],pt.prototype,"setSelectionOrder",1),ht([p],pt.prototype,"update",2),ht([p],pt.prototype,"reset",2);var ut=Object.defineProperty,mt=Object.getOwnPropertyDescriptor;"undefined"!=typeof require&&require;var gt=(e,t,s,i)=>{for(var a,n=i>1?void 0:i?mt(t,s):t,r=e.length-1;r>=0;r--)(a=e[r])&&(n=(i?a(t,s,n):a(n))||n);return i&&n&&ut(t,s,n),n};class vt{constructor(e){this.table=new lt(e.table),this.tree=new pt(e.tree)}}gt([h],vt.prototype,"table",2),gt([h],vt.prototype,"tree",2);var ft=Object.defineProperty,yt=Object.getOwnPropertyDescriptor;"undefined"!=typeof require&&require;var It=(e,t,s,i)=>{for(var a,n=i>1?void 0:i?yt(t,s):t,r=e.length-1;r>=0;r--)(a=e[r])&&(n=(i?a(t,s,n):a(n))||n);return i&&n&&ft(t,s,n),n};class Ct extends ne{constructor(e){var t,s;super(e),this.createUncommittedRecord=()=>{if(!this.isScript)return;const e=jt.add({type:"create",recordId:null,sessionId:this.id,value:{modelId:this.script.modelId}});jt.add({type:"update",recordId:e.recordId,sessionId:this.id,value:this.script.model.fields.reduce(((e,t)=>(t.isId?e[t.name]=void 0:void 0!==t.default?t.isFunctionDefault?e[t.name]=void 0:e[t.name]=t.default:t.isUpdatedAt?e[t.name]=(new Date).toISOString():!t.isScalar&&!t.isEnum||t.isPartOfRelation?t.isRelation&&t.isList?e[t.name]=t.lowestValidValue:e[t.name]=void 0:e[t.name]=t.lowestValidValue,e)),{})})},this.update=(e,t={})=>{c.exports.has(e,"lastSavedHash")&&(this.lastSavedHash=e.lastSavedHash),super.update(e,t)},this.serialize=()=>({projectId:Ds.activeProjectId,id:this.id,type:this.type,lastSavedHash:this.lastSavedHash,scriptId:this.scriptId}),this.id=e.id,this.type=e.type,this.scriptId=null!=(t=e.scriptId)?t:null,this.lastSavedHash=null!=(s=e.lastSavedHash)?s:this.hash,this.selection=new vt({table:{sessionId:this.id,selectedRecordIds:[]},tree:{sessionId:this.id,isEditing:!1}})}get script(){if(!this.isScript)throw $({path:"Session.script",message:"Invalid `get` call to script: Session is not a `script` type",context:{type:this.type,scriptId:this.scriptId}});const e=vs.get(this.scriptId);if(!e)throw $({path:"Session.script",message:"Invalid scriptId in session",context:{type:this.type,scriptId:this.scriptId}});return e}get name(){return this.isScript?this.script.model.name:"Session Name"}get isScript(){return"script"===this.type}get isModelList(){return"model-list"===this.type}get isDirty(){return this.isScript?!this.script.frozen&&(null===this.script.name||(!!Object.values(jt.values).filter((e=>e.sessionId===this.id))||null!==this.script.name&&this.lastSavedHash!==this.hash)):this.lastSavedHash!==this.hash}get hash(){return this.isScript?this.script.hash:""}forceSave(){this.isDirty&&this.update({lastSavedHash:this.hash})}discardChanges(){if(this.isScript)try{const{code:e,modelId:t,where:s,fieldIds:i,sortFieldId:a,sortOrder:n}=JSON.parse(this.lastSavedHash);this.script.update({code:e,modelId:t,where:s,fieldIds:i,sort:{fieldId:a,order:n}})}catch(e){console.log("Could not restore session",e)}}}It([h],Ct.prototype,"id",2),It([h],Ct.prototype,"type",2),It([h],Ct.prototype,"scriptId",2),It([h],Ct.prototype,"lastSavedHash",2),It([f],Ct.prototype,"script",1),It([f],Ct.prototype,"name",1),It([f],Ct.prototype,"isScript",1),It([f],Ct.prototype,"isModelList",1),It([f],Ct.prototype,"isDirty",1),It([f],Ct.prototype,"hash",1),It([p],Ct.prototype,"createUncommittedRecord",2),It([p],Ct.prototype,"forceSave",1),It([p],Ct.prototype,"discardChanges",1),It([p],Ct.prototype,"update",2);var wt=Object.defineProperty,bt=Object.getOwnPropertyDescriptor;"undefined"!=typeof require&&require;var Et=(e,t,s,i)=>{for(var a,n=i>1?void 0:i?bt(t,s):t,r=e.length-1;r>=0;r--)(a=e[r])&&(n=(i?a(t,s,n):a(n))||n);return i&&n&&wt(t,s,n),n};class xt extends te{constructor(){super(Ct,{idbTableName:"sessions"}),this.findOrCreate=({scriptId:e})=>Object.values(this.values).find((t=>t.scriptId===e))||this.add({type:"script",scriptId:e,lastSavedHash:null}),this.remove=e=>{const t=super.remove(e);return Object.values(jt.values).forEach((t=>{t.sessionId===e&&jt.remove(t.id)})),t}}}Et([p],xt.prototype,"findOrCreate",2),Et([p],xt.prototype,"remove",2);var _t=new xt;const St=(e,t)=>e.isList?Array.isArray(t)?t.every((t=>e.isEnum?!Nt(e,t):e.isRelation?!Lt(e,t):!Rt(e,t)))?void 0:"Every value in this list must be valid":"Value must be a list":e.isEnum?Nt(e,t):e.isRelation?Lt(e,t):Rt(e,t),Nt=(e,t)=>{if(!e.isRequired&&c.exports.isNil(t))return;if(void 0===t&&void 0!==e.default)return;const s=e.typeAsEnum;return s&&s.values.includes(t)?void 0:"Value must be an Enum variant"},Lt=(e,t)=>{if(!e.isRequired&&c.exports.isNil(t))return;if(e.isRequired&&!t)return"Required fields must not be `null`";return e.typeAsModel?void 0:`Value must be a ${e.type} identifier`},Rt=(e,t)=>{if((void 0!==t||void 0===e.default)&&(e.isList||e.isRequired||!c.exports.isNil(t)))return e.isRequired&&c.exports.isNil(t)?"Required fields must not be `null`":e.isString&&"string"!=typeof t?"Value must be a String":!e.isInt||"number"==typeof t&&!isNaN(t)&&Number.isInteger(t)?e.isFloat&&("number"!=typeof t||isNaN(t))?"Value must be a Float":e.isBigInt&&"bigint"!=typeof t?"Value must be a valid BigInt":e.isBoolean&&"boolean"!=typeof t?"Value must be a Boolean":e.isDateTime&&isNaN(new Date(String(t)))?"Value must be a valid DateTime":e.isJson&&"object"!=typeof t?"Value must be a valid Json":void 0:"Value must be an Integer"};var Mt=Object.defineProperty,Ot=Object.getOwnPropertyDescriptor;"undefined"!=typeof require&&require;var At=(e,t,s,i)=>{for(var a,n=i>1?void 0:i?Ot(t,s):t,r=e.length-1;r>=0;r--)(a=e[r])&&(n=(i?a(t,s,n):a(n))||n);return i&&n&&Mt(t,s,n),n};class kt extends ne{constructor(e){if(super(e),this.serialize=()=>({projectId:Ds.activeProjectId,id:this.id,type:this.type,recordId:this.recordId,sessionId:this.sessionId,value:I(this.value)}),this.id=e.id,this.sessionId=e.sessionId,this.type=e.type,this.value=e.value,"create"===this.type){const t=`tmp--${this.id}`,s=e.value.modelId;Jt.add({id:t,modelId:s,value:{}}),this.recordId=t}else this.recordId=e.recordId}get record(){return this.recordId?Jt.get(this.recordId):null}get session(){return _t.get(this.sessionId)}get isValid(){return(e=>{const t=jt.get(e);if(!t)throw $({path:"isActionValid",message:"Invalid action",context:{actionId:e}});const s=Jt.get(t.recordId);if(!s)return!1;const i=s.model;if(!i)return!1;const a=Object.keys(t.value);switch(t.type){case"create":return!!ke.get(t.value.modelId);case"delete":return!!Jt.get(t.recordId);case"update":return a.every((e=>{const s=i.getFieldByName(e),a=t.value[e];return!!s&&!St(s,a)}));default:return!1}})(this.id)}update(e,t={}){c.exports.has(e,"recordId")&&(this.recordId=e.recordId),c.exports.has(e,"sessionId")&&(this.sessionId=e.sessionId),c.exports.has(e,"value")&&(this.value=e.value),super.update(e,t)}}At([h],kt.prototype,"id",2),At([h],kt.prototype,"recordId",2),At([h],kt.prototype,"sessionId",2),At([h],kt.prototype,"type",2),At([h],kt.prototype,"value",2),At([f],kt.prototype,"record",1),At([f],kt.prototype,"session",1),At([f],kt.prototype,"isValid",1),At([p],kt.prototype,"update",1);var Dt=Object.defineProperty,Tt=Object.getOwnPropertyDescriptor;"undefined"!=typeof require&&require;var Pt=(e,t,s,i)=>{for(var a,n=i>1?void 0:i?Tt(t,s):t,r=e.length-1;r>=0;r--)(a=e[r])&&(n=(i?a(t,s,n):a(n))||n);return i&&n&&Dt(t,s,n),n};class Vt extends te{constructor(){super(kt,{idbTableName:"actions"}),this.committing=!1,this.add=(e,t={})=>{var s;const i=super.add(e,t);return this.consolidate(),this.actions.length>0&&(null==(s=_s.activeTab)||s.update({preview:!1}),Fe.updateActions({visible:!0})),i},this.remove=e=>{const t=super.remove(e);return 0===this.actions.length&&Fe.updateActions({visible:!1}),t},this.commit=async()=>{var e,t;if(this.invalidActions.length>0)return console.error("Commit failed: Some actions are invalid",this.invalidActions),We.update({type:"fatal",description:"Failed to commit changes because some actions are invalid",dump:`Invalid actions: \n${JSON.stringify(this.invalidActions,null,2)}`}),void Fe.updateError({visible:!0});if(!(null==(t=null==(e=_s.activeTab)?void 0:e.session)?void 0:t.isScript))return;const s=this.actions;let i=[];try{i=(e=>{const t=e.map((e=>jt.get(e))),s=[Ge,Ye,Xe].reduce(((e,t)=>{const s=t(e.actions);return e.actions=s.actions,e.requests.push(...s.requests),e}),{actions:t,requests:[]});return s.actions.length>0&&console.warn("All actions were not processed. Pending actions: ",JSON.stringify(I(s.actions),null,2)),s.requests})(s.map((e=>e.id))),console.log("Committing actions: ",i)}catch(a){throw console.error("Commit failed: Unable to generate Prisma Client requests",a),We.update({type:"fatal",description:"An unexpected error occurred while saving your changes",dump:`Message: ${a.message}\n`}),Fe.updateError({visible:!0}),a}w((()=>this.committing=!0));try{const{error:e}=await window.transport.request({channel:"prisma",action:"clientRequest",payload:{data:{schemaHash:Ds.activeProject.schemaHash,query:`prisma.$transaction([ ${i.join(",")} ])`}}});if(e)throw e;this.actions.filter((e=>"create"===e.type)).forEach((e=>{var t;return null==(t=e.record)?void 0:t.model.update({count:(e.record.model.count||0)+1})})),this.actions.filter((e=>"delete"===e.type)).forEach((e=>{var t;return null==(t=e.record)?void 0:t.model.update({count:(e.record.model.count||0)-1})})),this.discard(),_s.activeTab.session.isScript&&await _s.activeTab.session.script.run(),w((()=>this.committing=!1))}catch(a){w((()=>this.committing=!1));const e=_s.activeTab.session.script.model;if("PrismaClientSchemaDriftedError"===a.type)We.update({type:"schemaDrift",description:"Your source Prisma Schema has changed. Please reload Studio to continue. Your changes will be saved.",dump:""});else if("PrismaClientRustPanicError"===a.type||"PrismaClientUnknownRequestError"===a.type)We.update({type:"fatal",description:`An unexpected error occurred while saving your changes to the \`${e.name}\` table`,dump:`Message: ${a.message}\n\nQuery: \n${i[0]}\n`});else{const e=`Type: ${a.type}\nMessage: ${a.message}\n\nCode: ${a.code}\n\nQuery:\n${i[0]}\n`;We.update({type:"client",description:`Failed to commit changes: ${a.message}`,dump:e})}throw Fe.updateError({visible:!0}),a}},this.discard=()=>{const e=[...this.actions];for(let t=0;t<e.length;t++)this.remove(e[t].id);Fe.updateActions({visible:!1})},this.consolidate=()=>{const e=Object.values(this.values).map((e=>e.id)),t=new Set,s=(i,a)=>{const n=this.get(i);if(!n)return;const r=e.findIndex(((e,t)=>{if(t<=a)return!1;const s=this.get(e);return!!s&&(s.sessionId===n.sessionId&&s.recordId===n.recordId&&s.type===n.type)}));if(-1===r)return;const o=this.get(e[r]);return o?(n.update({value:l(l({},n.value),o.value)}),t.add(e[r]),e.splice(r,1),s(i,a)):void 0};e.forEach(s);e.forEach((s=>{const i=this.get(s);i&&"delete"===i.type&&e.forEach((e=>{var a;const n=this.get(e);n&&(n&&"delete"!==n.type&&n.recordId===i.recordId&&t.add(e),(null==(a=n.record)?void 0:a.isCommitted)||t.add(s))}))})),t.forEach((e=>this.remove(e)))}}get actions(){return Object.values(this.values).filter((e=>{var t;return e.sessionId===(null==(t=_s.activeTab)?void 0:t.sessionId)}))}get invalidActions(){return this.actions.filter((e=>!e.isValid))}}Pt([h],Vt.prototype,"committing",2),Pt([f],Vt.prototype,"actions",1),Pt([f],Vt.prototype,"invalidActions",1),Pt([p],Vt.prototype,"add",2),Pt([p],Vt.prototype,"remove",2),Pt([p],Vt.prototype,"commit",2),Pt([p],Vt.prototype,"discard",2),Pt([p],Vt.prototype,"consolidate",2);var jt=new Vt;const