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 • 297 kB
JavaScript
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=(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{m as c,l as h,o as p,a as u,u as m,b as g,d as v,c as f,v as y,t as I,e as C,w,r as b,f as E,g as _,h as x,i as S,R as N,j as L,k as R,n as O,p as M,q as k,s as D,A,x as T,F as P,y as V}from"./vendor.js";var j=Object.defineProperty,F=Object.getOwnPropertyDescriptor,B=(e,t,s,i)=>{for(var a,n=i>1?void 0:i?F(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&&j(t,s,n),n};class H{constructor(){this.transport={type:"http",url:`${window.location.origin}/api`},this.updates=!1,this.readonly=!1,c(this)}async update(e){h.exports.has(e,"transport")&&(this.transport=e.transport),h.exports.has(e,"updates")&&(this.updates=e.updates),h.exports.has(e,"readonly")&&(this.readonly=e.readonly)}}B([p],H.prototype,"transport",2),B([p],H.prototype,"updates",2),B([p],H.prototype,"readonly",2),B([u],H.prototype,"update",1);var q=new H;class Z{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 U=({path:e,message:t,code:s,type:i,stack:a,context:n,nativeError:r})=>{const l=new Z({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},z=(e,t,s)=>{const i=a=>a===e.length?s&&s():t(e[a],(()=>i(a+1)));return i(0)};const $=[(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;z(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=""}),(()=>{z(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;z(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;z(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={};z(i,((e,s)=>{const i=t.objectStore(e).getAll();i.onsuccess=()=>{a[e]=i.result,s()}}),(()=>{z(i,((s,i)=>{e.deleteObjectStore(s),e.createObjectStore(s,{keyPath:["id","projectId"]});const n=a[s];z(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;z(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;z(e,((e,t)=>{e.type=e.scriptId?"script":"fallback",i.put(e).onsuccess=t}),(()=>{const e=a.getAll();e.onsuccess=()=>{const t=e.result;z(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;z(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;z(e,((e,t)=>{delete e.tabOrder,e.createdAt=(new Date).toISOString(),e.updatedAt=(new Date).toISOString(),i.put(e).onsuccess=t}),(()=>{z([a,n,r,l],((e,t)=>{const s=e.getAll();s.onsuccess=()=>{const i=s.result;z(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;z(e,((e,t)=>{e.where=e.where.map((e=>(e.fieldIds=[e.fieldId],delete e.fieldId,e))),i.put(e).onsuccess=t}),(()=>s()))}}],J=(e,t,s,i)=>{console.log("------Starting IndexedDB migration------");const a=m(i);z($.slice(t),((t,s)=>t(e,a,s)),(()=>console.log("------IndexedDB migration complete------")))};class W{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}}var K=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:J}),this.projects=new W("projects",this.databaseInstance),this.tabs=new W("tabs",this.databaseInstance),this.sessions=new W("sessions",this.databaseInstance),this.scripts=new W("scripts",this.databaseInstance),this.actions=new W("actions",this.databaseInstance),this.ready=!0}catch(t){throw U({path:"PersistenceStore.init",message:"Unable to init PersistenceStore",nativeError:t})}},this.save=(e,t)=>new Promise((async(s,i)=>{if(!this.ready)throw U({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 U({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 U({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 U({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)}}},G=Object.defineProperty,Q=Object.getOwnPropertyDescriptor,Y=(e,t,s,i)=>{for(var a,n=i>1?void 0:i?Q(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&&G(t,s,n),n};class X{constructor(e,{idbTableName:t}={}){this.idbTableName=null,this.members={},this.type=e,this.idbTableName=null!=t?t:null,c(this)}get values(){return this.members}get size(){return Object.keys(this.members).length}async restore(){if(this.idbTableName){(await K.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&&K.save(this.idbTableName,s.serialize())}return s}remove(e){const t=this.members[e];return t&&delete this.members[e],this.idbTableName&&K.remove(this.idbTableName,e),t}clear(){this.members={},this.idbTableName&&K.clear(this.idbTableName)}toJS(){return I(this)}}Y([p],X.prototype,"idbTableName",2),Y([p],X.prototype,"members",2),Y([f],X.prototype,"values",1),Y([f],X.prototype,"size",1),Y([u],X.prototype,"restore",1),Y([u],X.prototype,"add",1),Y([u],X.prototype,"remove",1),Y([u],X.prototype,"clear",1),Y([u],X.prototype,"toJS",1);var ee=Object.defineProperty,te=Object.getOwnPropertyDescriptor,se=(e,t,s,i)=>{for(var a,n=i>1?void 0:i?te(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&&ee(t,s,n),n};class ie{constructor(e){this.forceUpdate=async()=>{await K.save(this.idbTableName,this.serialize())},this.id=e.id,this.idbTableName=null,c(this)}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(){}}se([p],ie.prototype,"id",2),se([p],ie.prototype,"idbTableName",2),se([u],ie.prototype,"update",1),se([u],ie.prototype,"forceUpdate",2);const ae=(e,t)=>`${e}.${t}`;var ne=Object.defineProperty,re=Object.getOwnPropertyDescriptor,le=(e,t,s,i)=>{for(var a,n=i>1?void 0:i?re(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&&ne(t,s,n),n};class oe extends ie{constructor(e){super(e),this.id=e.id,this.name=e.name,this.values=e.values,c(this)}update(e,t={}){h.exports.has(e,"name")&&(this.name=e.name),h.exports.has(e,"values")&&(this.values=e.values),super.update(e,t)}}le([C],oe.prototype,"id",2),le([p],oe.prototype,"name",2),le([p],oe.prototype,"values",2),le([C],oe.prototype,"update",1);var de=Object.defineProperty,ce=Object.getOwnPropertyDescriptor;class he extends X{constructor(){super(oe),this.getByName=e=>this.get(e),c(this)}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?ce(t,s):t,r=e.length-1;r>=0;r--)(a=e[r])&&(n=(i?a(t,s,n):a(n))||n);i&&n&&de(t,s,n)})([C],he.prototype,"add",1);var pe=new he,ue=Object.defineProperty,me=Object.getOwnPropertyDescriptor,ge=(e,t,s,i)=>{for(var a,n=i>1?void 0:i?me(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&&ue(t,s,n),n};class ve extends ie{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,c(this)}get model(){return ds.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 isScalarListRelation(){return this.isScalar&&this.isList&&this.isPartOfRelation||!1}get isScalarListTwoWayMNRelation(){var e;if(this.isScalarListRelation){const t=(null==(e=this.model)?void 0:e.name)||null;if(!t)return!1;const s=this.relationItIsPartOf;if(!s)return!1;const i=ds.getByName(s.type);if(!i)return!1;const a=i.fields.find((e=>e.type===t));if(!a)return!1;const n=a.relationFromFieldNames[0],r=i.getFieldByName(n);if(!r)return!1;if(r.isScalarListRelation)return!0}return!1}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&&!h.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||h.exports.isArray(this.default)?this.default.toString():h.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?ds.getByName(this.type):null}get typeAsEnum(){return pe.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 U({path:"Field.lowestValidValue",message:"Invalid type of field: enum",context:{fieldId:this.id,type:this.type}});return this.typeAsEnum.values[0]}return null}get getRelationIDFieldName(){if(!this.isRelation)return null;const e=ds.getByName(this.type);return e&&e.idField?e.idField.name:null}update(e,t={}){h.exports.has(e,"default")&&(this.default=e.default),h.exports.has(e,"isId")&&(this.isId=e.isId),h.exports.has(e,"isUnique")&&(this.isUnique=e.isUnique),h.exports.has(e,"isRequired")&&(this.isRequired=e.isRequired),h.exports.has(e,"isList")&&(this.isList=e.isList),h.exports.has(e,"isReadOnly")&&(this.isReadOnly=e.isReadOnly),h.exports.has(e,"isUpdatedAt")&&(this.isUpdatedAt=e.isUpdatedAt),super.update(e,t)}}ge([C],ve.prototype,"id",2),ge([p],ve.prototype,"modelId",2),ge([p],ve.prototype,"name",2),ge([p],ve.prototype,"type",2),ge([p],ve.prototype,"kind",2),ge([p],ve.prototype,"default",2),ge([p],ve.prototype,"isId",2),ge([p],ve.prototype,"isUnique",2),ge([p],ve.prototype,"isRequired",2),ge([p],ve.prototype,"isList",2),ge([p],ve.prototype,"isReadOnly",2),ge([p],ve.prototype,"isUpdatedAt",2),ge([p],ve.prototype,"relationName",2),ge([p],ve.prototype,"relationFromFieldNames",2),ge([p],ve.prototype,"relationToFieldNames",2),ge([f],ve.prototype,"model",1),ge([f],ve.prototype,"isScalar",1),ge([f],ve.prototype,"isString",1),ge([f],ve.prototype,"isInt",1),ge([f],ve.prototype,"isBigInt",1),ge([f],ve.prototype,"isFloat",1),ge([f],ve.prototype,"isDecimal",1),ge([f],ve.prototype,"isBoolean",1),ge([f],ve.prototype,"isDateTime",1),ge([f],ve.prototype,"isJson",1),ge([f],ve.prototype,"isBytes",1),ge([f],ve.prototype,"isEnum",1),ge([f],ve.prototype,"isRelation",1),ge([f],ve.prototype,"isScalarListRelation",1),ge([f],ve.prototype,"isScalarListTwoWayMNRelation",1),ge([f],ve.prototype,"isPartOfRelation",1),ge([f],ve.prototype,"relationItIsPartOf",1),ge([f],ve.prototype,"isSortable",1),ge([f],ve.prototype,"isFunctionDefault",1),ge([f],ve.prototype,"defaultAsString",1),ge([f],ve.prototype,"placeholder",1),ge([f],ve.prototype,"typeAsModel",1),ge([f],ve.prototype,"typeAsEnum",1),ge([f],ve.prototype,"typeAsLabel",1),ge([f],ve.prototype,"lowestValidValue",1),ge([f],ve.prototype,"getRelationIDFieldName",1),ge([C],ve.prototype,"update",1);var fe=new class extends X{constructor(){super(ve)}getByName(e,t){return this.get(ae(t,e))}},ye=Object.defineProperty,Ie=Object.getOwnPropertyDescriptor,Ce=(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&&ye(t,s,n),n};const we=class{constructor(){this.previousError={type:null},this.updateError=(e={})=>{h.exports.has(e,"visible")&&(this.error.visible=e.visible)},this.updateActions=(e={})=>{h.exports.has(e,"visible")&&(this.actions.visible=e.visible)},this.setPreviousError=e=>{this.previousError=e,localStorage.setItem(we.previousErrorLocalStorageKey,JSON.stringify(e))},this.error={visible:!1};const e=localStorage.getItem(we.previousErrorLocalStorageKey);e&&(this.previousError=JSON.parse(e)),this.actions={visible:!1},c(this)}};let be=we;be.previousErrorLocalStorageKey="previousError",Ce([p],be.prototype,"error",2),Ce([p],be.prototype,"actions",2),Ce([p],be.prototype,"previousError",2),Ce([u],be.prototype,"updateError",2),Ce([u],be.prototype,"updateActions",2),Ce([u],be.prototype,"setPreviousError",2);var Ee=new be;const _e=(e,t)=>{if(null==t)throw U({path:"getRecordId",message:"Invalid recordValue",context:{modelId:e,recordValue:t}});const s=ds.get(e);if(!s)throw U({path:"getRecordId",message:"Invalid modelId",context:{modelId:e}});let i=`${e}::`;return i+=s.uniqueIdentifier.fields.map((e=>null===t[e.name]?"null":void 0===t[e.name]?"undefined":t[e.name])).join(","),i};var xe=Object.defineProperty,Se=Object.getOwnPropertyDescriptor,Ne=(e,t,s,i)=>{for(var a,n=i>1?void 0:i?Se(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&&xe(t,s,n),n};class Le{constructor(e){this.update=e=>{h.exports.has(e,"selectedRecordIds")&&(this.selectedRecordIds=e.selectedRecordIds)},this.sessionId=e.sessionId,this.selectedRecordIds=[],c(this)}get session(){return $e.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=>dt.get(e)))}}Ne([p],Le.prototype,"sessionId",2),Ne([p],Le.prototype,"selectedRecordIds",2),Ne([f],Le.prototype,"session",1),Ne([f],Le.prototype,"maxRows",1),Ne([f],Le.prototype,"maxColumns",1),Ne([f],Le.prototype,"selectedRecords",1),Ne([u],Le.prototype,"update",2);const Re=(e,t)=>{const s=e.split("::"),i=Number(s[0].slice(1,-1));if(isNaN(i))throw U({path:"parseTreePath",message:"Invalid tree path: Failed to parse segment as index",context:{path:e,recordIdx:i}});const a=dt.get(t[i]);if(!a)throw U({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=_e(t.id,n[i]);if(!c)throw U({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=dt.get(c))?o:null)?void 0:a.value)?d:null}else a=null,n=null!=(c=n[i])?c:null;else{if(!t)throw U({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 U({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&&_e(t.id,n);if(!o)throw U({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=dt.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 Oe=Object.defineProperty,Me=Object.getOwnPropertyDescriptor,ke=(e,t,s,i)=>{for(var a,n=i>1?void 0:i?Me(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&&Oe(t,s,n),n};class De{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 U({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}=Re(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=>{h.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=[],c(this)}get session(){return $e.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 U({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}=Re(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}}ke([p],De.prototype,"sessionId",2),ke([p],De.prototype,"isEditing",2),ke([p],De.prototype,"activePath",2),ke([p],De.prototype,"expandedPaths",2),ke([p],De.prototype,"selectionOrder",2),ke([f],De.prototype,"session",1),ke([u],De.prototype,"select",2),ke([u],De.prototype,"move",2),ke([u],De.prototype,"expand",2),ke([u],De.prototype,"collapse",2),ke([u],De.prototype,"jumpToParent",1),ke([u],De.prototype,"setSelectionOrder",1),ke([u],De.prototype,"update",2),ke([u],De.prototype,"reset",2);var Ae=Object.defineProperty,Te=Object.getOwnPropertyDescriptor,Pe=(e,t,s,i)=>{for(var a,n=i>1?void 0:i?Te(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&&Ae(t,s,n),n};class Ve{constructor(e){this.table=new Le(e.table),this.tree=new De(e.tree),c(this)}}Pe([p],Ve.prototype,"table",2),Pe([p],Ve.prototype,"tree",2);var je=Object.defineProperty,Fe=Object.getOwnPropertyDescriptor,Be=(e,t,s,i)=>{for(var a,n=i>1?void 0:i?Fe(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&&je(t,s,n),n};class He extends ie{constructor(e){var t,s;super(e),this.createUncommittedRecord=()=>{if(!this.isScript)return;const e=Os.add({type:"create",recordId:null,sessionId:this.id,value:{modelId:this.script.modelId}});Os.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={})=>{h.exports.has(e,"lastSavedHash")&&(this.lastSavedHash=e.lastSavedHash),super.update(e,t)},this.serialize=()=>({projectId:es.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,c(this),this.selection=new Ve({table:{sessionId:this.id,selectedRecordIds:[]},tree:{sessionId:this.id,isEditing:!1}})}get script(){if(!this.isScript)throw U({path:"Session.script",message:"Invalid `get` call to script: Session is not a `script` type",context:{type:this.type,scriptId:this.scriptId}});const e=Mt.get(this.scriptId);if(!e)throw U({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(Os.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)}}}Be([C],He.prototype,"id",2),Be([p],He.prototype,"scriptId",2),Be([p],He.prototype,"lastSavedHash",2),Be([f],He.prototype,"script",1),Be([f],He.prototype,"name",1),Be([f],He.prototype,"isScript",1),Be([f],He.prototype,"isModelList",1),Be([f],He.prototype,"isDirty",1),Be([f],He.prototype,"hash",1),Be([u],He.prototype,"createUncommittedRecord",2),Be([u],He.prototype,"forceSave",1),Be([u],He.prototype,"discardChanges",1),Be([C],He.prototype,"update",2);var qe=Object.defineProperty,Ze=Object.getOwnPropertyDescriptor,Ue=(e,t,s,i)=>{for(var a,n=i>1?void 0:i?Ze(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&&qe(t,s,n),n};class ze extends X{constructor(){super(He,{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(Os.values).forEach((t=>{t.sessionId===e&&Os.remove(t.id)})),t},c(this)}}Ue([u],ze.prototype,"findOrCreate",2),Ue([C],ze.prototype,"remove",2);var $e=new ze;const Je=(e,t)=>e.isList?Array.isArray(t)?t.every((t=>e.isEnum?!We(e,t):e.isRelation?!Ke(e,t):!Ge(e,t)))?void 0:"Every value in this list must be valid":"Value must be a list":e.isEnum?We(e,t):e.isRelation?Ke(e,t):Ge(e,t),We=(e,t)=>{if(!e.isRequired&&h.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"},Ke=(e,t)=>{if(!e.isRequired&&h.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`},Ge=(e,t)=>{if((void 0!==t||void 0===e.default)&&(e.isList||e.isRequired||!h.exports.isNil(t)))return e.isRequired&&h.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 Qe=Object.defineProperty,Ye=Object.getOwnPropertyDescriptor,Xe=(e,t,s,i)=>{for(var a,n=i>1?void 0:i?Ye(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&&Qe(t,s,n),n};class et extends ie{constructor(e){if(super(e),this.serialize=()=>({projectId:es.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,c(this),"create"===this.type){const t=`tmp--${this.id}`,s=e.value.modelId;dt.add({id:t,modelId:s,value:{}}),this.recordId=t}else this.recordId=e.recordId}get record(){return this.recordId?dt.get(this.recordId):null}get session(){return $e.get(this.sessionId)}get isValid(){return(e=>{const t=Os.get(e);if(!t)throw U({path:"isActionValid",message:"Invalid action",context:{actionId:e}});const s=dt.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!!ds.get(t.value.modelId);case"delete":return!!dt.get(t.recordId);case"update":return a.every((e=>{const s=i.getFieldByName(e),a=t.value[e];return!!s&&!Je(s,a)}));default:return!1}})(this.id)}update(e,t={}){h.exports.has(e,"recordId")&&(this.recordId=e.recordId),h.exports.has(e,"sessionId")&&(this.sessionId=e.sessionId),h.exports.has(e,"value")&&(this.value=e.value),super.update(e,t)}}Xe([C],et.prototype,"id",2),Xe([p],et.prototype,"recordId",2),Xe([p],et.prototype,"sessionId",2),Xe([p],et.prototype,"type",2),Xe([p],et.prototype,"value",2),Xe([f],et.prototype,"record",1),Xe([f],et.prototype,"session",1),Xe([f],et.prototype,"isValid",1),Xe([C],et.prototype,"update",1);const tt=async e=>{var t,s;console.log("Running query: ",e);let{error:i,data:a}=await window.transport.request({channel:"prisma",action:"clientRequest",payload:{data:l({schemaHash:es.activeProject.schemaHash},e)}});if(i)throw U({path:"runQuery",code:i.code,type:i.type,stack:i.stack,message:`Error in Prisma Client request: \n\n${i.message}`,context:{code:e,error:i}});if(!a)throw U({path:"runQuery",message:`Malformed response from Prisma Client: \n\n${a}`,context:{code:e}});const n=ds.get(e.modelName);if(!n)throw U({path:"runQuery",message:"Unrecognized Model",context:{code:e,response:a}});const r=Object.entries((null==(t=e.args)?void 0:t.select)||(null==(s=e.args)?void 0:s.include)||{}).filter((([e,t])=>!!t)).map((([e])=>{var t;return null==(t=fe.getByName(n.id,e))?void 0:t.id})).filter((e=>!!e));if(!a)return Promise.resolve({modelId:n.id,fieldIds:r,recordIds:[]});Array.isArray(a)||(a=[a]);const o=a.map((e=>dt.add({modelId:n.id,value:e}).id));return{modelId:n.id,fieldIds:r,recordIds:o}};var st=Object.defineProperty,it=Object.getOwnPropertyDescriptor,at=(e,t,s,i)=>{for(var a,n=i>1?void 0:i?it(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&&st(t,s,n),n};class nt extends ie{constructor(e){super(e),this.fetchRelations=async()=>{try{if(!this.isCommitted)return;await tt((e=>{const t=dt.get(e);if(!t)throw U({path:"getFindOneQuery",message:"Invalid recordId",context:{recordId:e}});const s=t.model,i=s.uniqueIdentifier,a=i.name,n=i.fields.reduce(((e,s)=>(e[s.name]=t.value[s.name],e)),{});let r;return r=1===i.fields.length?n:{[`${a}`]:n},{modelName:s.name,operation:"findUnique",args:{where:r,select:s.fields.reduce(((e,t)=>(e[t.name]=!0,e)),{})}}})(this.id))}catch(e){ys.update({type:"client",description:"Unable to fetch record",dump:e.message}),Ee.updateError({visible:!0})}},this.id=e.id,this.valueInDB=e.value||{},this.modelId=e.modelId,c(this)}get model(){let e=ds.get(this.modelId);if(!e)throw U({path:"Record.model",message:"Invalid modelId",context:{modelId:this.modelId}});return e}get value(){const e=Os.actions.filter((e=>e.recordId===this.id&&"update"===e.type));if(0==e.length)return this.valueInDB;const t=e[0];return this.model.fields.reduce(((e,s)=>void 0===t.value[s.name]?(e[s.name]=this.valueInDB[s.name],e):(e[s.name]=t.value[s.name],e)),{})}get isCommitted(){return!this.id.startsWith("tmp-")}get dirtyFieldNames(){if(!this.isCommitted)return this.model.fields.map((e=>e.name));const e=Os.actions.filter((e=>{var t;return e.sessionId===(null==(t=Bt.activeTab)?void 0:t.sessionId)&&e.recordId===this.id})).reduce(((e,t)=>(Object.keys(t.value).forEach((t=>{e.add(t)})),e)),new Set);return Array.from(e)}get invalidFields(){return Object.keys(this.value).map((e=>{const t=this.model.getFieldByName(e);if(!t)return;const s=Je(t,this.value[e]);return s?{field:t,reason:s}:void 0})).filter((e=>!!e))}update(e,t={}){h.exports.has(e,"value")&&(this.valueInDB=l(l({},this.valueInDB),e.value)),super.update(e,t)}}at([C],nt.prototype,"id",2),at([p],nt.prototype,"modelId",2),at([p],nt.prototype,"valueInDB",2),at([f],nt.prototype,"model",1),at([f],nt.prototype,"value",1),at([f],nt.prototype,"isCommitted",1),at([f],nt.prototype,"dirtyFieldNames",1),at([f],nt.prototype,"invalidFields",1),at([C],nt.prototype,"update",1),at([u],nt.prototype,"fetchRelations",2);var rt=Object.defineProperty,lt=Object.getOwnPropertyDescriptor;class ot extends X{constructor(){super(nt),c(this)}add(e,t={}){var s;const i=null!=(s=e.id)?s:_e(e.modelId,e.value);if(!i)throw U({path:"RecordStore.add",message:"Unable to determine ID for record to create",context:{record:e}});const a=super.add(l({id:i},e));return Object.keys(e.value).forEach((s=>{var i;const n=a.model.getFieldByName(s);if(!n)throw U({path:"RecordStore.add",message:"Invalid field name",context:{fieldName:s,recordValue:e.value}});if(!n.isRelation)return;const r=null==(i=n.typeAsModel)?void 0:i.id;if(!r)throw U({path:"RecordStore.add",message:"Unable to create related records",context:{fieldId:n.id,type:n.type}});if(n.isList)e.value[s].map((e=>{const s=_e(r,e);!this.get(s)&&e&&this.add({modelId:r,value:e},t)}));else if(null!==e.value[s]){const i=_e(r,e.value[s]);!this.get(i)&&e.value[s]&&this.add({modelId:r,value:e.value[s]},t)}})),a}}((e,t,s,i)=>{for(var a,n=i>1?void 0:i?lt(t,s):t,r=e.length-1;r>=0;r--)(a=e[r])&&(n=(i?a(t,s,n):a(n))||n);i&&n&&rt(t,s,n)})([C],ot.prototype,"add",1);var dt=new ot;const ct=e=>Array.from(new Set(e)),ht=({modelId:e,where:t,fieldIds:s,sort:i,pagination:a})=>{const n=ds.get(e);if(!n)throw U({path:"getFindManyQuery",message:"Invalid modelId",context:{modelId:e}});const r={};if(t&&(null==t?void 0:t.size)>0&&(r.where={AND:Object.values(t.values).reduce(((e,t)=>{var s,i,a,n,r,l,o,d,c;if(!t.enabled||!t.isValid)return e;if(!h.exports.first(t.fields)||!h.exports.last(t.fields))return e;"in"===t.operation||"notIn"===t.operation?t.value=JSON.parse(t.value||"[]"):!(null==(s=h.exports.last(t.fields))?void 0:s.isInt)&&!(null==(i=h.exports.last(t.fields))?void 0:i.isFloat)||(null==(a=h.exports.last(t.fields))?void 0:a.isList)?(null==(n=h.exports.last(t.fields))?void 0:n.isBoolean)&&!(null==(r=h.exports.last(t.fields))?void 0:r.isList)?t.value=Boolean("false"!==t.value&&t.value):(null==(l=h.exports.last(t.fields))?void 0:l.isDateTime)&&!(null==(o=h.exports.last(t.fields))?void 0:o.isList)?t.value=new Date(t.value).toISOString():(null==(d=h.exports.last(t.fields))?void 0:d.isBigInt)&&!(null==(c=h.exports.last(t.fields))?void 0:c.isList)&&(t.value=BigInt(t.value)):t.value=Number(t.value);let p={[`${t.operation}`]:t.value};return"isNull"===t.operation?p={equals:null}:"isNotNull"===t.operation&&(p={not:{equals:null}}),h.exports.last(t.fields).isList&&(p={some:p}),t.fields.length>1&&(p={[`${h.exports.last(t.fields).name}`]:p}),h.exports.first(t.fields).isList&&(p={some:p}),e.push({[h.exports.first(t.fields).name]:p}),e}),[])}),(null==i?void 0:i.fieldId)&&(null==i?void 0:i.order)){const e=fe.get(i.fieldId);if(!e)throw U({path:"getFindManyQuery",message:"Invalid sort fieldId",context:{sort:i}});r.orderBy=[{[`${e.name}`]:i.order}]}void 0!==(null==a?void 0:a.take)&&null!==a.take&&(r.take=Number(a.take)),void 0!==(null==a?void 0:a.skip)&&null!==a.skip&&(r.skip=Number(a.skip)),s=s?ct([].concat(n.uniqueIdentifier.fields.map((e=>e.id)),s)):n.fieldIds;const l=((e,t)=>t.slice().sort(((t,s)=>e.fieldIds.findIndex((e=>e===t))-e.fieldIds.findIndex((e=>e===s)))))(n,s).map((e=>fe.get(e)));return r.select=l.reduce(((e,t)=>{if(!t)return e;if(t.isList&&t.isRelation){const s=t.getRelationIDFieldName;e[t.name]=!s||{select:{[s]:!0}}}else e[t.name]=!0;return e}),{}),{modelName:n.name,operation:"findMany",args:r}};var pt=Object.defineProperty,ut=Object.getOwnPropertyDescriptor,mt=(e,t,s,i)=>{for(var a,n=i>1?void 0:i?ut(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&&pt(t,s,n),n};class gt{constructor(e){this.take=e.take,this.skip=e.skip,c(this)}update(e={}){h.exports.has(e,"take")&&(this.take=e.take),h.exports.has(e,"skip")&&(this.skip=e.skip)}reset(){this.update({take:100,skip:0})}}mt([p],gt.prototype,"take",2),mt([p],gt.prototype,"skip",2),mt([u],gt.prototype,"update",1),mt([u],gt.prototype,"reset",1);var vt=Object.defineProperty,ft=Object.getOwnPropertyDescriptor,yt=(e,t,s,i)=>{for(var a,n=i>1?void 0:i?ft(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&&vt(t,s,n),n};class It{constructor(e){this.fieldId=e.fieldId,this.order=e.order,c(this)}get field(){return fe.get(this.fieldId)}update(e={}){h.exports.has(e,"fieldId")&&(this.fieldId=e.fieldId),h.exports.has(e,"order")&&(this.order=e.order)}reset(){this.update({fieldId:null,order:"asc"})}}yt([p],It.prototype,"fieldId",2),yt([p],It.prototype,"order",2),yt([f],It.prototype,"field",1),yt([u],It.prototype,"update",1),yt([u],It.prototype,"reset",1);const Ct=(e,t)=>{if(!e.isScalar)return!1;if(e.isString)return"string"==typeof t;if(e.isInt||e.isFloat||e.isDecimal)return""!==t&&!isNaN(Number(t));if(e.isBigInt)try{return""!==t&&!!BigInt(t)}catch(s){return!1}if(e.isBoolean)return"true"===t||"false"===t;if(e.isDateTime)return!isNaN(new Date(t));if(e.isJson)try{return!!JSON.parse(t)}catch(s){return!1}return!!e.isBytes&&"string"==typeof t},wt=(e,t)=>!!e.isEnum&&e.typeAsEnum.values.includes(t);var bt=Object.defineProperty,Et=Object.getOwnPropertyDescriptor,_t=(e,t,s,i)=>{for(var a,n=i>1?void 0:i?Et(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&&bt(t,s,n),n};class xt extends ie{constructor(e){super(e),this.update=(e,t)=>{h.exports.has(e,"fieldIds")&&(this.fieldIds=e.fieldIds),h.exports.has(e,"operation")&&(this.operation=e.operation),h.exports.has(e,"value")&&(this.value=e.value),h.exports.has(e,"enabled")&&(this.enabled=e.enabled),this.script.update({where:[]}),super.update(e,t)},this.serialize=()=>({id:String(this.id),fieldIds:[...this.fieldIds],operation:String(this.operation),value:this.value,scriptId:String(this.scriptId),enabled:this.enabled}),this.id=e.id,this.fieldIds=e.fieldIds,this.operation=e.operation||this.supportedOperations[0],this.value=e.value,this.scriptId=e.scriptId,this.enabled=e.enabled||!0,c(this)}get fields(){return this.fieldIds.map((e=>{const t=fe.get(e);if(!t)throw U({path:"ScriptWhereItem.fields",message:"Invalid fieldId",context:{fieldId:e}});return t}))}get script(){const e=Mt.get(this.scriptId);if(!e)throw U({path:"ScriptWhereItem.script",message:"Invalid scriptId",context:{scriptId:this.scriptId}});return e}get supportedOperations(){const e=h.exports.last(this.fields);if(!e)return[];let t;if(e.isRequired&&e.isString)t="StringFilter";else if(!e.isRequired&&e.isString)t="StringNullableFilter";else if(e.isRequired&&e.isInt)t="IntFilter";else if(!e.isRequired&&e.isInt)t="IntNullableFilter";else if(e.isRequired&&e.isFloat)t="FloatFilter";else if(!e.isRequired&&e.isFloat)t="FloatNullableFilter";else if(e.isRequired&&e.isBigInt)t="BigIntFilter";else if(!e.isRequired&&e.isBigInt)t="BigIntNullableFilter";else if(e.isRequired&&e.isDecimal)t="DecimalFilter";else if(!e.isRequired&&e.isDecimal)t="DecimalNullableFilter";else if(e.isRequired&&e.isBoolean)t="BoolFilter";else if(!e.isRequired&&e.isBoolean)t="BoolNullableFilter";else if(e.isRequired&&e.isDateTime)t="DateTimeFilter";else if(!e.isRequired&&e.isDateTime)t="DateTimeNullableFilter";else if(e.isRequired&&e.isJson)t="JsonFilter";else if(!e.isRequired&&e.isJson)t="JsonNullableFilter";else if(e.isRequired&&e.isBytes)t="BytesFilter";else if(!e.isRequired&&e.isBytes)t="BytesNullableFilter";else if(e.isRequired&&e.isEnum)t=`Enum${e.type}Filter`;else if(!e.isRequired&&e.isEnum)t=`Enum${e.type}NullableFilter`;else{if(!e.isRelation)throw U({path:"ScriptWhere.supportedOperations",message:"Unsupported field for `where` filter",context:{fields:this.fields.map((e=>null==e?void 0:e.serialize()))}});t=`${e.type}WhereInput`}const s=Ms.inputObjectTypes.get(t);if(!s)throw U({path:"ScriptWhere.supportedOperations",message:"Could not find appropriate InputType for this field type. This should never happen.",context:{inputTypeName:t,fields:this.fields.map((e=>null==e?void 0:e.serialize()))}});const i=s.fields.map((e=>e.name)).filter((e=>"mode"!==e));return e.isRequired||e.isRelation?i:i.concat(["isNull","isNotNull"])}get isValid(){return(e=>{var t,s,i,a,n,r;if(!e.enabled)return!0;if(!h.exports.last(e.fields))return!1;if(!e.operation)return!1;if(!(null==(t=h.exports.last(e.fields))?void 0:t.isScalar)&&!(null==(s=h.exports.last(e.fields))?void 0:s.isEnum))return!1;if(e.fields.length>1&&!(null==(i=h.exports.first(e.fields))?void 0:i.isRelation))return!1;if(["isNull","isNotNull"].includes(e.operation)&&(void 0===e.value||null===e.value))return!0;if((null==(a=h.exports.last(e.fields))?void 0:a.isRequired)&&(void 0===e.value||null===e.value))return!1;if(void 0===e.value||null===e.value)return!1;if(["in","notIn"].includes(e.operation))try{const t=JSON.parse(e.value);return Array.isArray(t)&&t.every((t=>{var s,i;return(null==(s=h.exports.last(e.fields))?void 0:s.isScalar)?Ct(h.exports.last(e.fields),t):!!(null==(i=h.exports.last(e.fields))?void 0:i.isEnum)&&wt(h.exports.last(e.fields),t)}))}catch(l){return!1}return!!e.supportedOperations.includes(e.operation)&&((null==(n=h.exports.last(e.fields))?void 0:n.isScalar)?Ct(h.exports.last(e.fields),e.value):!(null==(r=h.exports.last(e.fields))?void 0:r.isEnum)||wt(h.exports.last(e.fields),e.value))})(this)}getFilterableFieldsAtIndex(e){if(e>=this.fieldIds.length)throw U({path:"ScriptWhere.getFilterableFieldsAtIndex",message:"Index is out of range",context:{fieldIds:this.fieldIds,index:e}});if(0===e)return this.script.model.fields.filter((e=>e.isScalar&&!e.isList||e.isEnum&&!e.isList||e.isRelation));if(1===e){return fe.get(this.fieldIds[e-1]).typeAsModel.fields.filter((e=>e.isScalar&&!e.isList||e.isEnum&&!e.isList))}return[]}}_t([C],xt.prototype,"id",2),_t([p],xt.prototype,"fieldIds",2),_t([p],xt.prototype,"operation",2),_t([p],xt.prototype,"value",2),_t([p],xt.prototype,"scriptId",2),_t([p],xt.prototype,"enabled",2),_t([f],xt.prototype,"fields",1),_t([f],xt.prototype,"script",1),_t([f],xt.prototype,"supportedOperations",1),_t([f],xt.prototype,"isValid",1),_t([C],xt.prototype,"update",2);class St extends X{constructor({modelId:e,scriptId:t}){super(xt),this.serialize=()=>Object.values(this.values).map((e=>e.serialize())),this.modelId=e,this.scriptId=t,c(this)}get model(){let e=ds.get(this.modelId);if(!e)throw U({path:"ScriptWhere.model",message:"Invalid modelId",context:{modelId:this.modelId}});return e}get script(){return Mt.get(this.scriptId)}add(e,t){var s;const i=super.add(o(l({},e),{scriptId:this.scriptId}),t);return null==(s=this.script)||s.update({where:[]},t),i}}_t([p],St.prototype,"modelId",2),_t([p],St.prototype,"scriptId",2),_t([f],St.prototype,"model",1),_t([f],St.prototype,"script",1),_t([C],St.prototype,"add",1);var Nt=Object.defineProperty,Lt=Object.getOwnPropertyDescriptor,Rt=(e,t,s,i)=>{for(var a,n=i>1?void 0:i?Lt(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&&Nt(t,s,n),n};class Ot extends ie{constructor(e){var t,s,i,a,n,r,l,o;super(e),this.run=async()=>{if(!this.model)throw U({path:"Script.run",message:"Invalid modelId",context:{modelId:this.modelId}});this.update({running:!0}),Ee.updateError({visible:!1});const e=this.frozen||"visual"===this.inputMode?ht({modelId:this.modelId,where:this.where,sort:this.sort,pagination:this.pagination}):this.code;try{const[,{recordIds:t,modelId:s,fieldIds:i}]=await Promise.all([this.model.runCountQuery(),tt(e)]);this.update({recordIds:t}),"visual"===this.inputMode&&this.update({code:e}),"code"===this.inputMode&&this.update({modelId:s,fieldIds:i}),Ee.previousError.type&&Ee.setPreviousError({type:null})}catch(t){"PrismaClientSchemaDriftedError"===t.type?ys.update({type:"schemaDrift",description:"Your source Prisma Schema has changed. Please reload Studio to continue. Your changes will be saved.",dump:""}):ys.update({type:"client",description:"Unable to run script",dump:`Message: ${t.message}\n \nQuery:\n${JSON.stringify({modelName:e.modelName,operation:e.operation,args:e.args},null,2)}\n `}),Ee.updateError({visible:!0})}finally{this.update({running:!1})}},this.loadMore=async()=>{if(this.__recordIds.length>=(this.model.count||0)||"code"===this.inputMode)return[];this.update({running:!0});const e=ht({modelId:this.modelId,where:this.where,sort:this.sort,pagination:{take:100,skip:this.pagination.skip+this.__recordIds.length}});try{const{recordIds:t}=await tt(e),s=ct([...this.__recordIds,...t]);return this.update({running:!1,recordIds:s,pagination:{take:s.length}}),t.map((e=>dt.get(e))).filter((e=>!!e))}catch(t){throw this.update({running:!1}),console.log(t.type),"PrismaClientSchemaDriftedError"===t.type?ys.update({type:"schemaDrift",description:"Your source Prisma Schema has changed. Please reload Studio to continue. Your changes will be saved.",dump:""}):ys.update({type:"client",description:"Unable to fetch paginated records",dump:`Message: ${t.message}\n \nStack: ${t.stack}\n \nQuery:\n${JSON.stringify(e,null,2)}\n `}),Ee.updateError({visible:!0}),U({path:"Script.loadMore",message:"Unable to fetch next page of records",context:{take:this.pagination.take,skip:this.pagination.skip,lastFetchedRecordId:h.exports.last(this.__recordIds)},nativeError:t})}},this.update=(e,t={})=>{h.exports.has(e,"name")&&(this.name=e.name),h.exports.has(e,"frozen")&&(this.frozen=e.frozen),h.exports.has(e,"modelId")&&(this.modelId=e.modelId),h.exports.has(e,"fieldIds")&&(this.fieldIds=e.fieldIds),h.exports.has(e,"inputMode")&&(this.inputMode=e.inputMode),h.exports.has(e,"viewMode")&&(this.viewMode=e.viewMode),h.exports.has(e,"sort")&&this.sort.update(e.sort),h.exports.has(e,"pagination")&&this.pagination.update(e.pagination),h.exports.has(e,"code")&&(this.code="string"==typeof e.code?JSON.parse(e.code):e.code),h.exports.has(e,"recordIds")&&(t