@elyx-code/project-logic-tree 0.0.6213 → 0.0.6214

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -21,28 +21,28 @@ WHERE
21
21
  AND Employee.manager IS NOT NULL
22
22
  OR (Employee.manager = User.identifier AND User.identifier IS NOT NULL)
23
23
  ORDER BY Employee.startDate DESC, Employee.department ASC
24
- LIMIT 10 OFFSET 0;`,w6={id:"find-companies-with-multiple-employees-and-bank-account-search-parent-ref-id",type:n.GenericReference,entityId:ce,version:"1",entityType:n.Project},C6={id:"find-companies-with-multiple-employees-and-bank-account-search-companies-list-output-declaration-parent-ref-id",type:n.GenericReference,entityId:"find-companies-with-multiple-employees-and-bank-account",version:"1",entityType:n.Search},WR={id:"find-companies-with-multiple-employees-and-bank-account-search-companies-list-output-declaration-id",type:n.ValueDescriptor,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,name:"companies",description:"List of companies with multiple employees and an existing bank account",defaultValue:null,dataType:null,required:!0,parentRelationType:N.FixedReturns,index:0,parent:C6},V6={id:"find-companies-with-multiple-employees-and-bank-account-search-companies-list-output-parent-ref-id",type:n.GenericReference,entityId:"find-companies-with-multiple-employees-and-bank-account",version:"1",entityType:n.Search},B6={id:"find-companies-with-multiple-employees-and-bank-account-search-companies-list-output-id",type:n.OutputMap,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,defaultValue:null,declaration:WR,writesValues:[],index:0,parent:V6},_6={id:"find-companies-with-multiple-employees-and-bank-account",type:n.Search,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,name:"Find companies with multiple employees and a bank account",description:"This search statement finds companies with multiple employees and an existing bank account",inputsDeclarations:[],outputsDeclarations:[WR],inputs:[],outputs:[B6],query:P6,successCalls:[],errorCalls:[],error:null,calledByError:[],calledByEntry:[],calledBySuccess:[],x:0,y:0,parent:w6},M6={type:n.GenericReference,id:"employee-mapped-dto-manager-input-map-reads-value-ref-id",version:"1",entityType:n.OutputMap,entityId:NR},N6={type:n.GenericReference,id:"employee-mapped-dto-manager-output-map-parent-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:Si},zR={id:C9,type:n.InputMap,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,declaration:null,name:"manager_id",description:null,defaultValue:null,index:4,readsValue:M6,parent:N6},L6={type:n.GenericReference,id:"employee-mapped-dto-department-input-map-reads-value-ref-id",version:"1",entityType:n.OutputMap,entityId:_R},U6={type:n.GenericReference,id:"employee-mapped-dto-department-output-map-parent-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:Si},YR={id:w9,type:n.InputMap,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,declaration:null,name:"department_name",description:null,defaultValue:null,index:3,readsValue:L6,parent:U6},g6={type:n.GenericReference,id:"employee-mapped-dto-birth-date-input-map-reads-value-ref-id",version:"1",entityType:n.OutputMap,entityId:BR},j6={type:n.GenericReference,id:"employee-mapped-dto-birth-date-output-map-parent-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:Si},HR={id:P9,type:n.InputMap,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,declaration:null,name:"birth_date",description:null,defaultValue:null,index:2,readsValue:g6,parent:j6},$6={type:n.GenericReference,id:"employee-mapped-dto-id-output-map-reads-value-ref-id",version:"1",entityType:n.OutputMap,entityId:VR},G6={type:n.GenericReference,id:"employee-mapped-dto-id-output-map-parent-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:Si},KR={id:O9,type:n.InputMap,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,declaration:null,name:"id",description:"The ID of the employee",defaultValue:null,index:1,readsValue:$6,parent:G6},F6={type:n.GenericReference,id:"employee-mapped-dto-requester-id-output-map-reads-value-ref-id",version:"1",entityType:n.OutputMap,entityId:LR},x6={type:n.GenericReference,id:"employee-mapped-dto-requester-id-output-map-parent-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:Si},XR={id:D9,type:n.InputMap,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,declaration:null,name:"requester_id",description:"The ID of the current user making the request",defaultValue:null,index:0,readsValue:F6,parent:x6},k6={type:n.GenericReference,id:"manager-variable-id-output-map-parent-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:tp},S6={id:NR,type:n.OutputMap,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,declaration:pi.properties[0],defaultValue:null,index:0,writesValues:[zR],parent:k6},Z6={type:n.GenericReference,id:"manager-variable-data-type-parent-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:tp},q6={like:!1,inferred:!1,id:"manager-variable-data-type-id",type:n.DataType,parentRelationType:null,options:null,implementationChooseOne:!1,andChildrenGroup:null,orChildrenGroup:null,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,entity:Ei,asType:!1,isList:!1,parent:Z6},J6={type:n.GenericReference,id:"manager-variable-reads-value-ref-id",version:"1",entityType:n.OutputMap,entityId:MR},W6={type:n.GenericReference,id:"manager-variable-parent-ref-id",version:"1",entityType:n.Project,entityId:ce},QR={constant:!0,required:!0,id:tp,type:n.VariableDeclaration,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,name:"Manager",dataType:q6,description:"A variable holding an inherited manager for testing purposes",defaultValue:null,calledByError:[],calledByEntry:[],calledBySuccess:[],successCalls:[],errorCalls:[],readsValue:J6,writesValues:[],inputs:[],outputs:[S6],internalCalls:[],parent:W6,x:0,y:0},z6={type:n.GenericReference,id:"random-company-employee-manager-output-map-parent-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:us},Y6={id:MR,type:n.OutputMap,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,defaultValue:null,declaration:Ei.properties[2],index:3,writesValues:[QR],parent:z6},H6={type:n.GenericReference,id:"random-company-employee-department-output-map-parent-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:us},K6={id:_R,type:n.OutputMap,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,defaultValue:null,declaration:Ei.properties[0],index:2,writesValues:[YR],parent:H6},X6={type:n.GenericReference,id:"random-company-employee-birth-date-output-map-parent-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:us},Q6={id:BR,type:n.OutputMap,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,defaultValue:null,declaration:Wt.properties[1],index:1,writesValues:[HR],parent:X6},e3={type:n.GenericReference,id:"random-company-employee-id-output-map-parent-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:us},t3={id:VR,type:n.OutputMap,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,defaultValue:null,declaration:pi.properties[0],index:0,writesValues:[KR],parent:e3},i3={type:n.GenericReference,id:"random-company-employee-test-variable-data-type-parent-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:us},r3={like:!1,inferred:!1,id:"random-company-employee-test-variable-data-type-id",type:n.DataType,parentRelationType:null,options:null,implementationChooseOne:!1,andChildrenGroup:null,orChildrenGroup:null,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,entity:Ei,asType:!1,isList:!1,parent:i3},n3={type:n.GenericReference,id:"random-company-employee-test-variable-parent-ref-id",version:"1",entityType:n.Project,entityId:ce},s3={constant:!0,required:!0,id:us,type:n.VariableDeclaration,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,name:"Company employee",dataType:r3,description:"A variable holding a random company employee for testing purposes",defaultValue:null,calledByError:[],calledByEntry:[],calledBySuccess:[],successCalls:[],errorCalls:[],readsValue:null,writesValues:[],inputs:[],outputs:[t3,Q6,K6,Y6],internalCalls:[],parent:n3,x:0,y:0},a3={type:n.GenericReference,id:"employee-mapped-dto-variable-instance-now-timestamp-input-map-default-value-parent-ref-id",version:"1",entityType:n.InputMap,entityId:UR},o3={type:n.LiteralValue,id:"employee-mapped-dto-variable-instance-now-timestamp-input-map-default-value-id",name:L.Date,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,valueAsTypeList:null,valueAsTypeSingle:null,value:null,autogeneration:{type:vt.CurrentDateAndTime,rangeStart:null,rangeEnd:null},parent:a3},l3={type:n.GenericReference,id:"employee-mapped-dto-variable-instance-now-timestamp-input-map-parent-ref-id",version:"1",entityType:n.VariableInstance,entityId:bn},d3={id:UR,type:n.InputMap,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,declaration:null,name:"now",description:"The current timestamp when the operation is executed",defaultValue:o3,index:5,readsValue:null,parent:l3},u3={type:n.GenericReference,id:"employee-mapped-dto-variable-instance-decl-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:Si},p3={type:n.GenericReference,id:"employee-mapped-dto-variable-instance-called-by-success-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:Si},c3={type:n.GenericReference,id:"employee-mapped-dto-variable-instance-parent-ref-id",version:"1",entityType:n.Project,entityId:ce},f3={id:bn,type:n.VariableInstance,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,defaultValue:null,declaration:u3,calledByError:[],calledByEntry:[],calledBySuccess:[p3],successCalls:[rp,SR,gR],errorCalls:[],readsValue:null,writesValues:[kR],inputs:[d3],outputs:[],internalCalls:[],parent:c3,x:0,y:0},y3={type:n.GenericReference,id:"employee-mapped-dto-variable-parent-ref-id",version:"1",entityType:n.Project,entityId:ce},h3={constant:!0,required:!0,id:Si,type:n.VariableDeclaration,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,name:"Employee DTO",dataType:null,description:"A variable holding the data of a mapped employee DTO",defaultValue:null,calledByError:[],calledByEntry:[],calledBySuccess:[],successCalls:[rp,f3],errorCalls:[],readsValue:null,writesValues:[GR],inputs:[XR,KR,HR,YR,zR],outputs:[],internalCalls:[],parent:y3,x:0,y:0},m3={type:n.GenericReference,id:"0e63e617-f9d3-42e8-bde0-1bb0b1df7034",version:"1",entityType:n.VariableDeclaration,entityId:KE},v3={like:!1,inferred:!1,id:"e75645ce-d3df-4f07-a897-ae9ef4d917fd",type:n.DataType,parentRelationType:null,options:null,implementationChooseOne:!1,andChildrenGroup:null,orChildrenGroup:null,entity:Au,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,asType:!1,isList:!1,parent:m3},T3={type:n.GenericReference,id:"e92a8ff5-3fef-4e0c-8d8f-92c930b2890b",version:"1",entityType:n.Project,entityId:ce},eD={constant:!0,required:!0,id:KE,type:n.VariableDeclaration,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,name:"Current user",description:"The user that is currently logged in",defaultValue:null,dataType:v3,inputs:[],outputs:[],calledByError:[],calledByEntry:[],calledBySuccess:[],successCalls:[],errorCalls:[],x:0,y:0,readsValue:null,writesValues:[],internalCalls:[],parent:T3},I3={type:n.GenericReference,id:"manager-variable-id-output-map-parent-ref-id",version:"1",entityType:n.VariableInstance,entityId:CR},E3={id:LR,type:n.OutputMap,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,defaultValue:null,declaration:pi.properties[0],index:0,writesValues:[XR],parent:I3},A3={type:n.GenericReference,id:"global-user-instance-parent-ref-id",version:"1",entityType:n.Project,entityId:ce},b3={id:CR,type:n.VariableInstance,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,defaultValue:null,declaration:eD,calledByError:[],calledByEntry:[],calledBySuccess:[],successCalls:[],errorCalls:[],readsValue:null,writesValues:[],inputs:[],outputs:[E3],internalCalls:[],parent:A3,x:0,y:0},R3={type:n.GenericReference,id:"is-test-environment-variable-dcl-datatype-parent-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:"is-test-environment-variable-dcl-id"},D3={type:n.GenericReference,id:"is-test-environment-variable-dcl-datatype-default-value-parent-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:"is-test-environment-variable-dcl-id"},O3={like:!1,inferred:!1,id:"is-test-environment-variable-dcl-datatype-id",type:n.DataType,parentRelationType:null,options:null,implementationChooseOne:!1,andChildrenGroup:null,orChildrenGroup:null,entity:er,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,asType:!1,isList:!1,parent:R3},P3={type:n.GenericReference,id:"is-test-environment-variable-dcl-main-project-ref-id",version:"1",entityType:n.Project,entityId:ce},tD={constant:!0,required:!0,id:"is-test-environment-variable-dcl-id",type:n.VariableDeclaration,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,name:"Is test envrioment",description:"Indicates whether the current environment is a test environment or not.",defaultValue:{id:"is-test-environment-variable-dcl-datatype-default-value-id",name:L.Boolean,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,value:null,type:n.LiteralValue,autogeneration:{type:vt.Random,rangeStart:null,rangeEnd:null},valueAsTypeList:null,valueAsTypeSingle:null,parent:D3},dataType:O3,inputs:[],outputs:[],calledByError:[],calledByEntry:[],calledBySuccess:[],successCalls:[],errorCalls:[],x:0,y:0,readsValue:null,writesValues:[],internalCalls:[],parent:P3},w3={type:n.GenericReference,id:"is-test-environment-variable-instance-parent-ref-id",version:"1",entityType:n.Project,entityId:ce},C3={id:"is-test-environment-variable-instance-id",type:n.VariableInstance,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,defaultValue:null,declaration:tD,calledByError:[],calledByEntry:[],calledBySuccess:[],successCalls:[],errorCalls:[],readsValue:null,writesValues:[],inputs:[],outputs:[],internalCalls:[],parent:w3,x:0,y:0},lp={type:n.Project,id:ce,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,name:"Mocked project to compile",description:"This project is used to test all sorts of features and edge cases. It is not meant to be used in production. Or to have any functionality that makes sense",projects:[v9],entities:[Eu,pi,Au,Wt,dj,Ei,Zo,yA,hA,rs,kU,Ai,gg,Iu,rB,Wg,FU],functions:[gx,jA,$u,qx,ek,YA,Gu,Ou,f9,DA,Sk],events:[kj],variableDeclarations:[tD,eD,Zu,s3,QR,h3],variableInstances:[C3,b3],conditions:[],operations:[os],functionCalls:[k2,Q$],loops:[O6,rp,SR,h6,gR],searches:[_6]};var iD={exports:{}};(function(r,a){(function(e,t){r.exports=t()})(OC,function(){var e=1e3,t=6e4,i=36e5,s="millisecond",l="second",o="minute",d="hour",u="day",y="week",c="month",I="quarter",E="year",O="date",P="Invalid Date",V=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,M=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,G={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),ordinal:function(me){var ie=["th","st","nd","rd"],Y=me%100;return"["+me+(ie[(Y-20)%10]||ie[Y]||ie[0])+"]"}},B=function(me,ie,Y){var ue=String(me);return!ue||ue.length>=ie?me:""+Array(ie+1-ue.length).join(Y)+me},$={s:B,z:function(me){var ie=-me.utcOffset(),Y=Math.abs(ie),ue=Math.floor(Y/60),ee=Y%60;return(ie<=0?"+":"-")+B(ue,2,"0")+":"+B(ee,2,"0")},m:function me(ie,Y){if(ie.date()<Y.date())return-me(Y,ie);var ue=12*(Y.year()-ie.year())+(Y.month()-ie.month()),ee=ie.clone().add(ue,c),je=Y-ee<0,$e=ie.clone().add(ue+(je?-1:1),c);return+(-(ue+(Y-ee)/(je?ee-$e:$e-ee))||0)},a:function(me){return me<0?Math.ceil(me)||0:Math.floor(me)},p:function(me){return{M:c,y:E,w:y,d:u,D:O,h:d,m:o,s:l,ms:s,Q:I}[me]||String(me||"").toLowerCase().replace(/s$/,"")},u:function(me){return me===void 0}},Z="en",J={};J[Z]=G;var te="$isDayjsObject",fe=function(me){return me instanceof ei||!(!me||!me[te])},Ie=function me(ie,Y,ue){var ee;if(!ie)return Z;if(typeof ie=="string"){var je=ie.toLowerCase();J[je]&&(ee=je),Y&&(J[je]=Y,ee=je);var $e=ie.split("-");if(!ee&&$e.length>1)return me($e[0])}else{var ft=ie.name;J[ft]=ie,ee=ft}return!ue&&ee&&(Z=ee),ee||!ue&&Z},X=function(me,ie){if(fe(me))return me.clone();var Y=typeof ie=="object"?ie:{};return Y.date=me,Y.args=arguments,new ei(Y)},le=$;le.l=Ie,le.i=fe,le.w=function(me,ie){return X(me,{locale:ie.$L,utc:ie.$u,x:ie.$x,$offset:ie.$offset})};var ei=function(){function me(Y){this.$L=Ie(Y.locale,null,!0),this.parse(Y),this.$x=this.$x||Y.x||{},this[te]=!0}var ie=me.prototype;return ie.parse=function(Y){this.$d=function(ue){var ee=ue.date,je=ue.utc;if(ee===null)return new Date(NaN);if(le.u(ee))return new Date;if(ee instanceof Date)return new Date(ee);if(typeof ee=="string"&&!/Z$/i.test(ee)){var $e=ee.match(V);if($e){var ft=$e[2]-1||0,bt=($e[7]||"0").substring(0,3);return je?new Date(Date.UTC($e[1],ft,$e[3]||1,$e[4]||0,$e[5]||0,$e[6]||0,bt)):new Date($e[1],ft,$e[3]||1,$e[4]||0,$e[5]||0,$e[6]||0,bt)}}return new Date(ee)}(Y),this.init()},ie.init=function(){var Y=this.$d;this.$y=Y.getFullYear(),this.$M=Y.getMonth(),this.$D=Y.getDate(),this.$W=Y.getDay(),this.$H=Y.getHours(),this.$m=Y.getMinutes(),this.$s=Y.getSeconds(),this.$ms=Y.getMilliseconds()},ie.$utils=function(){return le},ie.isValid=function(){return this.$d.toString()!==P},ie.isSame=function(Y,ue){var ee=X(Y);return this.startOf(ue)<=ee&&ee<=this.endOf(ue)},ie.isAfter=function(Y,ue){return X(Y)<this.startOf(ue)},ie.isBefore=function(Y,ue){return this.endOf(ue)<X(Y)},ie.$g=function(Y,ue,ee){return le.u(Y)?this[ue]:this.set(ee,Y)},ie.unix=function(){return Math.floor(this.valueOf()/1e3)},ie.valueOf=function(){return this.$d.getTime()},ie.startOf=function(Y,ue){var ee=this,je=!!le.u(ue)||ue,$e=le.p(Y),ft=function(jn,li){var sn=le.w(ee.$u?Date.UTC(ee.$y,li,jn):new Date(ee.$y,li,jn),ee);return je?sn:sn.endOf(u)},bt=function(jn,li){return le.w(ee.toDate()[jn].apply(ee.toDate("s"),(je?[0,0,0,0]:[23,59,59,999]).slice(li)),ee)},Bt=this.$W,Zt=this.$M,Di=this.$D,ws="set"+(this.$u?"UTC":"");switch($e){case E:return je?ft(1,0):ft(31,11);case c:return je?ft(1,Zt):ft(0,Zt+1);case y:var gn=this.$locale().weekStart||0,xa=(Bt<gn?Bt+7:Bt)-gn;return ft(je?Di-xa:Di+(6-xa),Zt);case u:case O:return bt(ws+"Hours",0);case d:return bt(ws+"Minutes",1);case o:return bt(ws+"Seconds",2);case l:return bt(ws+"Milliseconds",3);default:return this.clone()}},ie.endOf=function(Y){return this.startOf(Y,!1)},ie.$set=function(Y,ue){var ee,je=le.p(Y),$e="set"+(this.$u?"UTC":""),ft=(ee={},ee[u]=$e+"Date",ee[O]=$e+"Date",ee[c]=$e+"Month",ee[E]=$e+"FullYear",ee[d]=$e+"Hours",ee[o]=$e+"Minutes",ee[l]=$e+"Seconds",ee[s]=$e+"Milliseconds",ee)[je],bt=je===u?this.$D+(ue-this.$W):ue;if(je===c||je===E){var Bt=this.clone().set(O,1);Bt.$d[ft](bt),Bt.init(),this.$d=Bt.set(O,Math.min(this.$D,Bt.daysInMonth())).$d}else ft&&this.$d[ft](bt);return this.init(),this},ie.set=function(Y,ue){return this.clone().$set(Y,ue)},ie.get=function(Y){return this[le.p(Y)]()},ie.add=function(Y,ue){var ee,je=this;Y=Number(Y);var $e=le.p(ue),ft=function(Zt){var Di=X(je);return le.w(Di.date(Di.date()+Math.round(Zt*Y)),je)};if($e===c)return this.set(c,this.$M+Y);if($e===E)return this.set(E,this.$y+Y);if($e===u)return ft(1);if($e===y)return ft(7);var bt=(ee={},ee[o]=t,ee[d]=i,ee[l]=e,ee)[$e]||1,Bt=this.$d.getTime()+Y*bt;return le.w(Bt,this)},ie.subtract=function(Y,ue){return this.add(-1*Y,ue)},ie.format=function(Y){var ue=this,ee=this.$locale();if(!this.isValid())return ee.invalidDate||P;var je=Y||"YYYY-MM-DDTHH:mm:ssZ",$e=le.z(this),ft=this.$H,bt=this.$m,Bt=this.$M,Zt=ee.weekdays,Di=ee.months,ws=ee.meridiem,gn=function(li,sn,ka,ld){return li&&(li[sn]||li(ue,je))||ka[sn].slice(0,ld)},xa=function(li){return le.s(ft%12||12,li,"0")},jn=ws||function(li,sn,ka){var ld=li<12?"AM":"PM";return ka?ld.toLowerCase():ld};return je.replace(M,function(li,sn){return sn||function(ka){switch(ka){case"YY":return String(ue.$y).slice(-2);case"YYYY":return le.s(ue.$y,4,"0");case"M":return Bt+1;case"MM":return le.s(Bt+1,2,"0");case"MMM":return gn(ee.monthsShort,Bt,Di,3);case"MMMM":return gn(Di,Bt);case"D":return ue.$D;case"DD":return le.s(ue.$D,2,"0");case"d":return String(ue.$W);case"dd":return gn(ee.weekdaysMin,ue.$W,Zt,2);case"ddd":return gn(ee.weekdaysShort,ue.$W,Zt,3);case"dddd":return Zt[ue.$W];case"H":return String(ft);case"HH":return le.s(ft,2,"0");case"h":return xa(1);case"hh":return xa(2);case"a":return jn(ft,bt,!0);case"A":return jn(ft,bt,!1);case"m":return String(bt);case"mm":return le.s(bt,2,"0");case"s":return String(ue.$s);case"ss":return le.s(ue.$s,2,"0");case"SSS":return le.s(ue.$ms,3,"0");case"Z":return $e}return null}(li)||$e.replace(":","")})},ie.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},ie.diff=function(Y,ue,ee){var je,$e=this,ft=le.p(ue),bt=X(Y),Bt=(bt.utcOffset()-this.utcOffset())*t,Zt=this-bt,Di=function(){return le.m($e,bt)};switch(ft){case E:je=Di()/12;break;case c:je=Di();break;case I:je=Di()/3;break;case y:je=(Zt-Bt)/6048e5;break;case u:je=(Zt-Bt)/864e5;break;case d:je=Zt/i;break;case o:je=Zt/t;break;case l:je=Zt/e;break;default:je=Zt}return ee?je:le.a(je)},ie.daysInMonth=function(){return this.endOf(c).$D},ie.$locale=function(){return J[this.$L]},ie.locale=function(Y,ue){if(!Y)return this.$L;var ee=this.clone(),je=Ie(Y,ue,!0);return je&&(ee.$L=je),ee},ie.clone=function(){return le.w(this.$d,this)},ie.toDate=function(){return new Date(this.valueOf())},ie.toJSON=function(){return this.isValid()?this.toISOString():null},ie.toISOString=function(){return this.$d.toISOString()},ie.toString=function(){return this.$d.toUTCString()},me}(),Xi=ei.prototype;return X.prototype=Xi,[["$ms",s],["$s",l],["$m",o],["$H",d],["$W",u],["$M",c],["$y",E],["$D",O]].forEach(function(me){Xi[me[1]]=function(ie){return this.$g(ie,me[0],me[1])}}),X.extend=function(me,ie){return me.$i||(me(ie,ei,X),me.$i=!0),X},X.locale=Ie,X.isDayjs=fe,X.unix=function(me){return X(1e3*me)},X.en=J[Z],X.Ls=J,X.p={},X})})(iD);var V3=iD.exports;const T=CE(V3);var D=(r=>(r.Error="error",r.Warning="warning",r))(D||{}),j=(r=>(r.InvalidObjectStructure="invalid-object-structure",r.NameNotUniqueInScope="name-not-unique-in-scope",r.EmptyName="empty-name",r.MissingCaller="missing-caller",r.PropertyOverwritesOtherSiblingWithSameName="property-overwrites-other-sibling-with-same-name",r.PropertyOverwritesOtherSiblingWithSameImplementation="property-overwrites-other-sibling-with-same-name",r.PropertyOverwritesOtherImplementedEntitysPropertyWithSameName="property-overwrites-other-implemented-entitys-property-with-same-name",r.PropertyOverwritesOtherImplementedEntitysPropertyWithSameImplementation="property-overwrites-other-implemented-entitys-property-with-same-name",r.PropertyOverwritesOtherExtendedEntitysPropertyWithSameImplementation="property-overwrites-other-extended-entitys-property-with-same-name",r.PropertyOverwritesOtherExtendedEntitysPropertyWithSameName="property-overwrites-other-extended-entitys-property-with-same-name",r.PropertyOverwritesBasePropertyWithSameName="property-overwrites-base-property-with-same-name",r.PropertyOverwritesBasePropertyWithSameImplementation="property-overwrites-base-property-with-same-name",r.MethodOverwritesOtherSiblingWithSameName="method-overwrites-other-sibling-with-same-name",r.MethodOverwritesOtherSiblingWithSameImplementation="method-overwrites-other-sibling-with-same-name",r.MethodOverwritesOtherImplementedEntitysMethodWithSameName="method-overwrites-other-implemented-entitys-method-with-same-name",r.MethodOverwritesOtherImplementedEntitysMethodWithSameImplementation="method-overwrites-other-implemented-entitys-method-with-same-name",r.MethodOverwritesOtherExtendedEntitysMethodWithSameImplementation="method-overwrites-other-extended-entitys-method-with-same-name",r.MethodOverwritesOtherExtendedEntitysMethodWithSameName="method-overwrites-other-extended-entitys-method-with-same-name",r.MethodOverwritesBaseMethodWithSameName="method-overwrites-base-method-with-same-name",r.MethodOverwritesBaseMethodWithSameImplementation="method-overwrites-base-method-with-same-name",r.LoopBodyFunctionOverwrite="loop-body-function-overwrite",r.NoOverlapWithImplementedSignature="no-overlap-with-implemented-signature",r.ReaderWriterIncompatibleDataType="reader-writer-incompatible-data-type",r.UnreachableEntity="unreachable-entity",r.InternalCallParentMissingDataType="internal-call-parent-missing-data-type",r.InternalCallParentDeclarationEntityInvalidType="internal-call-parent-declaration-entity-invalid-type",r.InternalCallDeclarationNotFoundInParentDatatypeEntity="internal-call-declaration-not-found-in-parent-datatype-entity",r.InternalCallDeclarationIsNotFunctionDeclaration="internal-call-declaration-is-not-function-declaration",r.InternalCallDeclarationNotInParentDatatypeEntity="internal-call-declaration-not-in-parent-datatype-entity",r))(j||{}),R=(r=>(r.RootReference="root-reference",r.ReferencedEntityNotFound="referenced-entity-not-found",r.EntityIdNotUnique="entity-id-not-unique",r.BuiltInEntityGenerated="built-in-entity-generated",r.BuiltInEntityUpdated="built-in-entity-updated",r.BuiltInEntityDeleted="built-in-entity-deleted",r.UnknownEntityType="unknown-entity-type",r.MissingTypeProperty="missing-type-property",r.MissingIdProperty="missing-id-property",r.BuiltInEntityParent="built-in-entity-parent",r.InvalidBuiltInEntityReference="invalid-built-in-entity-reference",r.RecommendedImplementAbstractEntityAction="recommended-implement-abstract-entity-action",r.RecommendedImplementOperationAction="recommended-implement-operation-action",r.RecommendedImplementFunctionCallAction="recommended-implement-function-call-action",r.RecommendedImplementVariableDeclarationAction="recommended-implement-variable-declaration-action",r.RecommendedImplementVariableInstanceAction="recommended-implement-variable-instance-action",r.RecommendedImplementConditionAction="recommended-implement-condition-action",r.InvalidReferenceObjectStructure="invalid-reference-object-structure",r.ContainsSingleButShouldBeReferenceList="contains-single-but-should-be-reference-list",r.ContainsListButShouldReferenceSingle="contains-list-but-should-reference-single",r.InvalidParentReference="invalid-parent-reference",r.InvalidImplementsReference="invalid-implements-reference",r.InvalidExtendsReference="invalid-extends-reference",r.InvalidGenerationActionPayload="invalid-generation-action-payload",r.InvalidReference="invalid-reference",r.InvalidInternalCallParentRelation="invalid-internal-call-parent-relation",r.InvalidUpdateEntityOperation="invalid-update-entity-operation",r.NewEntityWouldOverriteExisting="new-entity-would-overrite-existing",r.InvalidDownstreamPropertyOverride="invalid-downstream-property-override",r.UnrecognizedProperty="unrecognized-property",r.SelfReference="self-reference",r.DuplicateReference="duplicate-reference",r.CallerWithIncompatibleScope="caller-with-incompatible-scope",r.InvalidFunctionDeclarationForFunctionCall="invalid-function-declaration-for-function-call",r.InvalidInputMapDeclaration="invalid-input-map-declaration",r.InvalidActionDescriptorForOperation="invalid-action-descriptor-for-operation",r.InvalidActionDescriptorForCondition="invalid-action-descriptor-for-condition",r.InvalidActionDescriptorForLoop="invalid-action-descriptor-for-loop",r.InvalidInmutablePropertyOverride="invalid-inmutable-property-override",r.OutputOverwrite="output-overwrite",r.InputOverwrite="input-overwrite",r.IncompatibleScope="incompatible-scope",r.InvalidParentUpdate="invalid-parent-update",r.NonInteractiveEntityReferenced="non-interactive-entity-referenced",r.InvalidParentRelationType="invalid-parent-relation-type",r))(R||{}),F=(r=>(r.NoPrimaryKeyProperty="no-primary-key-property",r.ScopeWithoutLogic="scope-without-logic",r.AbstractEntityImplements="abstract-entity-implements",r.ImplementsIncompatibleEntities="implements-incompatible-entities",r.ExtendsIncompatibleEntities="extends-incompatible-entities",r.NonAbstractExtendingAbstractEntity="non-abstract-extending-abstract-entity",r.AbstractExtendingNonAbstractEntity="abstract-extending-non-abstract-entity",r.NonStaticExtendingStaticEntity="non-static-extending-static-entity",r.StaticExtendingNonStaticEntity="static-extending-non-static-entity",r.StaticImplementingNonStaticEntity="static-implementing-non-static-entity",r.NonStaticImplementingStaticEntity="non-static-implementing-static-entity",r.ImplementingNonAbstractEntity="implementing-non-abstract-entity",r.ExtendingNonInteractiveEntity="extending-non-interactive-entity",r.AbstractEntityWithNonAbstractMethods="abstract-entity-with-non-abstract-methods",r.AbstractEntityWithNonAbstractProperties="abstract-entity-with-non-abstract-properties",r.StaticEntityWithNonStaticProperties="static-entity-with-non-static-properties",r.NonStaticPropertyInStaticEntity="non-static-property-in-static-entity",r.AbstractPropertyInNonAbstractEntity="abstract-property-in-non-abstract-entity",r.AbstractMethodInNonAbstractEntity="abstract-method-in-non-abstract-entity",r.IncorrectEntityImplementation="incorrect-entity-implementation",r.IncorrectMethodImplementation="incorrect-method-implementation",r.IncorrectPropertyImplementation="incorrect-property-implementation",r.PropertyImplementsNonAbstact="property-implements-non-abstract",r.NonStaticPropertyImplementsStatic="non-static-property-implements-static",r.StaticPropertyImplementsNonStatic="static-property-implements-non-static",r.PropertyImplementsIncompatibleType="property-implements-incompatible-type",r.MissingPropertyImplementation="missing-property-implementation",r.MissingMethodImplementation="missing-method-implementation",r.NoProperties="no-properties",r.ReadingFromIncompatibleType="reading-from-incompatible-type",r.WritingToIncompatibleType="writing-to-incompatible-type",r.InvalidPropertiesCombination="invalid-properties-combination",r.DisconnectedCallableEntity="disconnected-callable-entity",r.VariableReadsValueAndInternalCall="variable-reads-value-and-internal-call",r.VariableWritesValuesAndInternalCall="variable-writes-values-and-internal-call",r.VariableHasInputsAndInternalCall="variable-has-inputs-and-internal-calls",r.VariableHasOutputsAndInternalCall="variable-has-outputs-and-internal-call",r.VariableIsCalledAndHasInternalCall="variable-is-called-and-has-internal-call",r.VariableCallsOthersAndHasInternalCall="variable-calls-others-and-has-internal-call",r))(F||{});class w{constructor(a){f(this,"id");f(this,"message");f(this,"issue");f(this,"severity");f(this,"code");this.id=a.id,this.message=a.message,this.issue=a.issue,this.severity=a.severity,this.code=a.code}toEntityError(a){return this.code in j?new it({id:this.id,message:this.message,issue:this.issue,severity:this.severity,code:this.code,entity:a}):null}}class it{constructor(a){f(this,"id");f(this,"message");f(this,"issue");f(this,"severity");f(this,"code");f(this,"entity");f(this,"firstRelationship");f(this,"secondRelationship");this.id=a.id,this.message=a.message,this.issue=a.issue,this.severity=a.severity,this.code=a.code,this.entity=a.entity,this.firstRelationship=a.firstRelationship,this.secondRelationship=a.secondRelationship}clone(){return new it({id:this.id,message:this.message,issue:this.issue,severity:this.severity,code:this.code,entity:this.entity,firstRelationship:this.firstRelationship,secondRelationship:this.secondRelationship})}}function B3(r){const a=new Set;return r.filter(e=>a.has(e.id)?!1:(a.add(e.id),!0))}function de(r){const a=r.entity.errors.find(t=>t.id===r.id);return a?{new:!1,error:a}:{new:!0,error:new it(r)}}function _3(r,a){const e=new Map;return r.forEach(t=>{e.set(t.id,t)}),a.forEach(t=>{e.set(t.id,t)}),Array.from(e.values())}function He(r,a){const e=[];return a.forEach(t=>{const i=r.find(s=>s.id===t.id);i?e.push(i):e.push(t)}),e}const ca=v.union([v.string(),v.number(),v.boolean(),v.date()]),rD=v.enum([vt.CurrentDateAndTime,vt.Random,vt.Unique]),nl=v.object({type:rD,rangeStart:ca.nullable(),rangeEnd:ca.nullable()}),fa=nl.extend({type:v.literal(vt.Random),rangeStart:ca,rangeEnd:ca}),dp=nl.extend({type:v.literal(vt.Unique),rangeStart:v.null(),rangeEnd:v.null()}),nD=nl.extend({type:v.literal(vt.CurrentDateAndTime),rangeStart:v.null(),rangeEnd:v.null()}),sl=fa.extend({rangeStart:v.number().nullable(),rangeEnd:v.number().nullable()}),sD=sl.extend({rangeStart:v.number(),rangeEnd:v.null()}),aD=sl.extend({rangeStart:v.null(),rangeEnd:v.number()}),oD=sl.extend({rangeStart:v.number(),rangeEnd:v.number()}),al=fa.extend({rangeStart:v.number().nullable(),rangeEnd:v.number().nullable()}),lD=al.extend({rangeStart:v.number(),rangeEnd:v.null()}),dD=al.extend({rangeStart:v.null(),rangeEnd:v.number()}),uD=al.extend({rangeStart:v.number(),rangeEnd:v.number()}),ol=fa.extend({rangeStart:v.date().nullable(),rangeEnd:v.date().nullable()}),pD=ol.extend({rangeStart:v.date(),rangeEnd:v.null()}),cD=ol.extend({rangeStart:v.null(),rangeEnd:v.date()}),fD=ol.extend({rangeStart:v.date(),rangeEnd:v.date()}),up=fa.extend({rangeStart:v.null(),rangeEnd:v.null()}),pp=v.union([lD,dD,uD]),cp=v.union([sD,aD,oD]),fp=v.union([pD,cD,fD,nD]),yp=v.union([pp,cp,fp,dp,up]);function ya(){return v.union([v.object({type:v.literal(n.ValueDescriptor)}),v.record(v.string(),v.any())])}function yD(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.ValueDescriptor)})}function hp(){return v.object({id:v.string(),type:v.literal(n.ValueDescriptor),name:v.string(),required:v.boolean()})}function M3(){return hp().merge(v.object({version:v.number(),index:v.number()}))}function N3(){return hp().merge(v.object({}))}function L3(){return v.object({dataType:Pn(),parent:Dn()})}function U3(){return M3().merge(L3())}function ll(){return v.union([v.object({type:v.literal(n.PrimitiveEntity)}),v.record(v.string(),v.any())])}function dl(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.PrimitiveEntity)})}function ul(){return v.object({id:v.string(),type:v.literal(n.PrimitiveEntity),name:v.string(),description:v.string().nullable(),static:v.boolean(),abstract:v.boolean()})}function g3(){return ul().merge(v.object({version:v.number()}))}function j3(){return ul().merge(v.object({}))}function $3(){return v.object({properties:v.array(Rn()),methods:v.array(fi()),abstractMethods:v.array(Zi()),extends:v.array(v.union([ll(),ps()]))})}function G3(){return g3().merge($3())}function Rn(){return v.union([v.object({type:v.literal(n.Property)}),v.record(v.string(),v.any())])}function hD(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.Property)})}function mp(){return v.object({id:v.string(),type:v.literal(n.Property),name:v.string(),description:v.string().nullable(),private:v.boolean(),static:v.boolean(),required:v.boolean(),abstract:v.boolean()})}function F3(){return mp().merge(v.object({version:v.number(),index:v.number()}))}function x3(){return mp().merge(v.object({}))}function k3(){return v.object({dataType:Pn(),implements:Rn().nullable(),parent:v.union([Vn(),dl(),pl()])})}function S3(){return F3().merge(k3())}function Z3(){return v.enum([z.CRON_JOB,z.EXECUTION,z.HTTP_ENDPOINT,z.PERSISTED_ENTITY,z.RELATIONAL_DATABASE])}function ps(){return v.union([v.object({type:v.literal(n.BuiltInBaseEntity)}),v.record(v.string(),v.any())])}function pl(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.BuiltInBaseEntity)})}function vp(){return v.object({id:v.string(),version:v.number(),type:v.literal(n.BuiltInBaseEntity),name:Z3(),description:v.string().nullable(),abstract:v.boolean(),static:v.boolean()})}function q3(){return vp()}function J3(){return vp().merge(v.object({}))}function W3(){return v.object({properties:v.array(Rn()),methods:v.array(fi()),abstractMethods:v.array(Zi()),extends:v.array(v.union([ps(),ll()]))})}function z3(){return q3().merge(W3())}function Zi(){return v.union([v.object({type:v.literal(n.ActionDescriptor)}),v.record(v.string(),v.any())])}function Dn(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.ActionDescriptor)})}function cl(){return v.object({id:v.string(),type:v.literal(n.ActionDescriptor),name:v.string(),description:v.string().nullable()})}function Y3(){return cl().merge(v.object({version:v.number()}))}function H3(){return cl().merge(v.object({}))}function K3(){return v.object({inputs:v.array(ya()),outputs:v.array(ya()),parent:v.union([ii(),Vn(),pl(),dl()]).nullable()})}function mD(){return Y3().merge(K3())}function cs(){return v.union([v.object({type:v.literal(n.Loop)}),v.record(v.string(),v.any())])}function qi(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.Loop)})}function vD(){return v.object({id:v.string(),type:v.literal(n.Loop)})}function X3(){return vD().merge(v.object({version:v.number(),x:v.number(),y:v.number()}))}function Q3(){return vD().merge(v.object({declaration:v.union([v.string(),fi()])}))}function e5(){return v.object({calledBySuccess:v.array(rt()),calledByError:v.array(rt()),calledByEntry:v.array(Rt()),declaration:Zi(),inputs:v.array(Vi()),outputs:v.array(Ht()),outputsDeclarations:v.array(ya()),successCalls:v.array(Pt()),errorCalls:v.array(Pt()),error:Ht(),body:fi(),parent:v.union([fr(),ii()]),breakStatements:v.array(ms()),continueStatements:v.array(fs())})}function t5(){return X3().merge(e5())}function fs(){return v.union([v.object({type:v.literal(n.ContinueStatement)}),v.record(v.string(),v.any())])}function ys(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.ContinueStatement)})}function Tp(){return v.object({id:v.string(),type:v.literal(n.ContinueStatement)})}function i5(){return Tp().merge(v.object({version:v.number(),x:v.number(),y:v.number()}))}function r5(){return Tp().merge(v.object({}))}function n5(){return v.object({calledBySuccess:v.array(rt()),calledByError:v.array(rt()),calledByEntry:v.array(Rt()),outputs:v.array(ur()),throws:v.optional(ur()),parent:qi()})}function s5(){return i5().merge(n5())}function On(){return v.union([v.object({type:v.literal(n.ReturnStatement)}),v.record(v.string(),v.any())])}function hs(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.ReturnStatement)})}function Ip(){return v.object({id:v.string(),type:v.literal(n.ReturnStatement)})}function a5(){return Ip().merge(v.object({version:v.number(),x:v.number(),y:v.number()}))}function o5(){return Ip().merge(v.object({}))}function l5(){return v.object({calledBySuccess:v.array(rt()),calledByError:v.array(rt()),calledByEntry:v.array(Rt()),outputs:v.array(ur()),throws:v.optional(ur()),parent:fr()})}function d5(){return a5().merge(l5())}function ur(){return v.union([v.object({type:v.literal(n.ReturnDeclaration)}),v.record(v.string(),v.any())])}function TD(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.ReturnDeclaration)})}function Ep(){return v.object({id:v.string(),type:v.literal(n.ReturnDeclaration),name:v.string(),description:v.string().nullable(),isError:v.boolean()})}function u5(){return Ep().merge(v.object({version:v.number(),index:v.number()}))}function p5(){return Ep().merge(v.object({}))}function c5(){return v.object({dataType:Pn().nullable(),readsValue:Ea().nullable(),parent:v.union([hs(),Dn(),pr(),ys()])})}function f5(){return u5().merge(c5())}function ms(){return v.union([v.object({type:v.literal(n.BreakStatement)}),v.record(v.string(),v.any())])}function pr(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.BreakStatement)})}function Ap(){return v.object({id:v.string(),type:v.literal(n.BreakStatement)})}function y5(){return Ap().merge(v.object({version:v.number(),x:v.number(),y:v.number()}))}function h5(){return Ap().merge(v.object({}))}function m5(){return v.object({calledBySuccess:v.array(rt()),calledByError:v.array(rt()),calledByEntry:v.array(Rt()),outputs:v.array(ur()),throws:v.optional(ur()),parent:qi()})}function v5(){return y5().merge(m5())}function Ht(){return v.union([v.object({type:v.literal(n.OutputMap)}),v.record(v.string(),v.any())])}function bp(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.OutputMap)})}function Rp(){return v.object({id:v.string(),type:v.literal(n.OutputMap)})}function T5(){return Rp().merge(v.object({version:v.number(),index:v.number()}))}function I5(){return Rp().merge(v.object({}))}function E5(){return v.object({writesValues:v.array(cr()),declaration:v.union([ur(),Rn()]),parent:v.union([rt(),qi(),pr()])})}function A5(){return T5().merge(E5())}function vs(){return v.union([v.object({type:v.literal(n.FunctionCall)}),v.record(v.string(),v.any())])}function ha(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.FunctionCall)})}function Dp(){return v.object({id:v.string(),type:v.literal(n.FunctionCall)})}function b5(){return Dp().merge(v.object({version:v.number(),x:v.number(),y:v.number()}))}function R5(){return Dp().merge(v.object({}))}function D5(){return v.object({successCalls:v.array(Pt()),errorCalls:v.array(Pt()),calledBySuccess:v.array(rt()),calledByError:v.array(rt()),calledByEntry:v.array(Rt()),writesValues:v.array(cr()),declaration:fi(),inputs:v.array(Vi()),outputs:v.array(Ht()),error:v.optional(Ht()),parent:v.union([fr(),ii()])})}function O5(){return b5().merge(D5())}function P5(){return v.enum([yt.Equal,yt.NotEqual,yt.MoreThan,yt.MoreThanOrEqual,yt.LessThan,yt.LessThanOrEqual,yt.And,yt.Or,vi.Empty,vi.NotEmpty])}function ma(){return v.union([v.object({type:v.literal(n.Condition)}),v.record(v.string(),v.any())])}function fl(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.Condition)})}function Op(){return v.object({id:v.string(),type:v.literal(n.Condition)})}function w5(){return Op().merge(v.object({version:v.number(),x:v.number(),y:v.number()}))}function C5(){return Op().merge(v.object({}))}function V5(){return v.object({successCalls:v.array(Pt()),errorCalls:v.array(Pt()),calledBySuccess:v.array(rt()),calledByError:v.array(rt()),calledByEntry:v.array(Rt()),leftValue:Vi(),rightValue:Vi().nullable(),operator:P5(),parent:v.union([fr(),ii()])})}function B5(){return w5().merge(V5())}function va(){return v.union([v.object({type:v.literal(n.Search)}),v.record(v.string(),v.any())])}function Ta(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.Search)})}function Pp(){return v.object({id:v.string(),type:v.literal(n.Search),name:v.string(),query:v.any(),description:v.string().nullable()})}function _5(){return Pp().merge(v.object({version:v.number(),x:v.number(),y:v.number()}))}function M5(){return Pp().merge(v.object({}))}function N5(){return v.object({successCalls:v.array(Pt()),errorCalls:v.array(Pt()),calledBySuccess:v.array(rt()),calledByError:v.array(rt()),calledByEntry:v.array(Rt()),inputsDeclarations:v.array(Cn()),inputs:v.array(Vi()),outputsDeclarations:v.array(ya()),outputs:v.array(Ht()),parent:v.union([fr(),ii()]),error:Ht().nullable()})}function L5(){return _5().merge(N5())}function Ia(){return v.union([v.object({type:v.literal(n.InternalCall)}),v.record(v.string(),v.any())])}function wp(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.InternalCall)})}function Cp(){return v.object({id:v.string(),type:v.literal(n.InternalCall),index:v.number()})}function U5(){return Cp().merge(v.object({version:v.number(),index:v.number()}))}function g5(){return Cp().merge(v.object({declaration:v.union([v.string(),fi()])}))}function j5(){return v.object({successCalls:v.array(Pt()),errorCalls:v.array(Pt()),calledBySuccess:v.array(rt()),calledByError:v.array(rt()),calledByEntry:v.array(Rt()),writesValues:v.array(cr()),declaration:fi(),inputs:v.array(Vi()),outputs:v.array(Ht()),parent:_r(),error:v.optional(Ht())})}function $5(){return U5().merge(j5())}function Vi(){return v.union([v.object({type:v.literal(n.InputMap)}),v.record(v.string(),v.any())])}function yl(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.InputMap)})}function Vp(){return v.object({id:v.string(),type:v.literal(n.InputMap),name:v.string().nullable().optional(),description:v.string().nullable().optional()})}function G5(){return Vp().merge(v.object({version:v.number(),index:v.number()}))}function F5(){return Vp().merge(v.object({}))}function x5(){return v.object({defaultValue:Bp().nullable(),declaration:v.union([Cn(),Rn()]).nullable(),readsValue:Ea().nullable(),parent:v.union([rt(),yl(),qi(),pr()])})}function k5(){return G5().merge(x5())}function Ts(){return v.union([v.object({type:v.literal(n.Operation)}),v.record(v.string(),v.any())])}function Is(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.Operation)})}function hl(){return v.object({id:v.string(),type:v.literal(n.Operation)})}function S5(){return hl().merge(v.object({version:v.number(),x:v.number(),y:v.number()}))}function Z5(){return hl().merge(v.object({}))}function q5(){return hl().merge(v.object({successCalls:v.array(Pt()),errorCalls:v.array(Pt()),calledBySuccess:v.array(rt()),calledByError:v.array(rt()),calledByEntry:v.array(Rt()),writesValues:v.array(cr()),declaration:Zi(),inputs:v.array(Vi()),outputs:v.array(Ht()),error:v.array(Ht()),parent:v.union([fr(),ii()])}))}function J5(){return S5().merge(q5())}function ml(){return v.union([v.string(),v.number(),v.boolean(),v.null(),v.date()])}function ID(){return v.record(v.string(),ml())}function W5(){return v.array(v.union([ml(),ID()]))}function ED(){return v.union([ml(),ID(),W5()])}function AD(){return v.union([ml(),ED()])}function bD(){return v.enum([L.String,L.Number,L.Boolean,L.Null,L.Date,L.KeyValue,L.Enum,L.File,L.UUID,L.EntityTemplate,L.ActionDescriptor])}function RD(){return v.union([Vn(),Is(),Aa()])}function z5(){return v.object({id:v.string(),name:bD(),type:v.literal(n.LiteralValue),value:AD(),autogeneration:yp.nullable()})}function Y5(){return z5().merge(v.object({}))}function Bi(){return v.object({id:v.string(),version:v.number(),name:bD(),type:v.literal(n.LiteralValue),value:AD(),valueAsTypeList:v.array(RD()).nullable(),valueAsTypeSingle:RD().nullable(),autogeneration:yp.nullable(),parent:v.union([_p(),yl()])})}function H5(){return Bi().extend({name:v.literal(L.String),value:v.string(),autogeneration:pp.nullable()})}function K5(){return Bi().extend({name:v.literal(L.Number),value:v.number(),autogeneration:cp.nullable()})}function X5(){return Bi().extend({name:v.literal(L.Boolean),value:v.boolean(),autogeneration:up.nullable()})}function Q5(){return Bi().extend({name:v.literal(L.Null),value:v.null(),autogeneration:v.null()})}function eS(){return Bi().extend({name:v.literal(L.Date),value:v.date(),autogeneration:fp.nullable()})}function tS(){return Bi().extend({name:v.literal(L.KeyValue),value:ED(),autogeneration:v.null()})}function iS(){return Bi().extend({name:v.literal(L.Enum),value:v.string(),autogeneration:v.null()})}function rS(){return Bi().extend({name:v.literal(L.File),value:v.string(),autogeneration:v.null()})}function nS(){return Bi().extend({name:v.literal(L.UUID),value:v.string(),autogeneration:dp.nullable()})}function sS(){return Bi().extend({name:v.literal(L.EntityTemplate),value:Vn(),autogeneration:v.null()})}function aS(){return Bi().extend({name:v.literal(L.ActionDescriptor),value:Aa(),autogeneration:v.null()})}function Bp(){return v.union([H5(),K5(),X5(),Q5(),eS(),tS(),iS(),rS(),nS(),sS(),aS()])}function Pn(){return v.union([v.object({type:v.literal(n.DataType)}),v.record(v.string(),v.any())])}function _p(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.DataType)})}function Mp(){return v.object({id:v.string(),type:v.literal(n.DataType),isNullable:v.boolean(),isList:v.boolean(),constant:v.boolean(),asType:v.boolean(),options:v.array(v.string()).optional()})}function oS(){return Mp().merge(v.object({version:v.number()}))}function lS(){return Mp().merge(v.object({}))}function dS(){return v.object({defaultValue:Bp().nullable(),entity:v.union([Es(),ps(),ll(),Zi()]).nullable(),parent:v.union([hD(),PD(),yD()])})}function uS(){return oS().merge(dS())}function Np(){return v.union([v.object({type:v.literal(n.VariableDeclaration)}),v.record(v.string(),v.any())])}function pS(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.VariableDeclaration)})}function Lp(){return v.object({id:v.string(),type:v.literal(n.VariableDeclaration),name:v.string(),description:v.string().nullable()})}function cS(){return Lp().merge(v.object({version:v.number(),x:v.number(),y:v.number()}))}function fS(){return Lp().merge(v.object({}))}function yS(){return v.object({dataType:Pn().nullable(),readsValue:Ea().nullable(),writesValues:v.array(cr()),inputs:v.array(Vi()),outputs:v.array(Ht()),successCalls:v.array(Pt()),errorCalls:v.array(Pt()),internalCalls:v.array(Ia()),calledBySuccess:v.array(rt()),calledByError:v.array(rt()),calledByEntry:v.array(Rt()),parent:v.union([fr(),ii()])})}function hS(){return cS().merge(yS())}function DD(){return v.union([v.object({type:v.literal(n.VariableInstance)}),v.record(v.string(),v.any())])}function mS(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.VariableInstance)})}function Up(){return v.object({id:v.string(),type:v.literal(n.VariableInstance)})}function vS(){return Up().merge(v.object({version:v.number(),x:v.number(),y:v.number()}))}function TS(){return Up().merge(v.object({}))}function IS(){return v.object({declaration:Np(),dataType:Pn().nullable(),readsValue:Ea().nullable(),writesValues:v.array(cr()),inputs:v.array(Vi()),outputs:v.array(Ht()),successCalls:v.array(Pt()),errorCalls:v.array(Pt()),internalCalls:v.array(Ia()),calledBySuccess:v.array(rt()),calledByError:v.array(rt()),calledByEntry:v.array(Rt()),parent:v.union([fr(),ii()])})}function ES(){return vS().merge(IS())}function gp(){return v.union([v.object({type:v.literal(n.InstalledProject)}),v.record(v.string(),v.any())])}function vl(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.InstalledProject)})}function AS(){return v.object({id:v.string(),type:v.literal(n.InstalledProject)})}function bS(){return v.object({version:v.number(),x:v.number(),y:v.number()})}function RS(){return v.object({})}function DS(){return v.object({implements:ii(),description:v.string().nullable(),functions:v.array(fi()),events:v.array(jp()),parent:ii()})}function OS(){return bS().merge(DS())}function jp(){return v.union([v.object({type:v.literal(n.GlobalEvent)}),v.record(v.string(),v.any())])}function PS(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.GlobalEvent)})}function Tl(){return v.object({id:v.string(),type:v.literal(n.GlobalEvent),name:v.string(),collapsed:v.boolean()})}function wS(){return Tl().merge(v.object({version:v.number(),x:v.number(),y:v.number()}))}function CS(){return Tl().merge(v.object({}))}function VS(){return Tl().merge(v.object({returnStatements:v.array(On()),implements:v.array(mD()),inputs:v.array(Cn()),calls:v.array(Pt()),parent:v.union([ii(),vl()])}))}function BS(){return wS().merge(VS())}function wn(){return v.union([Np(),DD()])}function _r(){return v.union([pS(),mS()])}function cr(){return v.union([wn(),Vi(),ur()])}function OD(){return v.union([_r(),yl(),TD()])}function Ea(){return v.union([wn(),Cn(),Ht(),Ts(),Ia(),vs()])}function _S(){return v.union([_r(),$p(),bp(),Is(),wp(),ha()])}function MS(){return v.union([Cn(),Ht(),cr()])}function PD(){return v.union([$p(),bp(),OD()])}function Il(){return jp()}function El(){return PS()}function Al(){return v.union([Ts(),vs(),ma(),va(),wn(),Ia(),cs()])}function rt(){return v.union([Is(),ha(),fl(),Ta(),_r(),wp(),qi()])}function bl(){return v.union([Ts(),vs(),ma(),va(),wn(),cs()])}function Rl(){return v.union([Is(),ha(),fl(),Ta(),_r(),qi()])}function wD(){return v.union([Al(),On(),ms(),fs()])}function Pt(){return v.union([rt(),hs(),pr(),ys()])}function CD(){return v.union([bl(),On(),ms(),fs()])}function VD(){return v.union([Rl(),hs(),pr(),ys()])}function Mr(){return v.union([fi(),Il()])}function Rt(){return v.union([Aa(),El()])}function NS(){return v.union([Al(),Mr()])}function LS(){return v.union([rt(),Rt()])}function US(){return v.union([bl(),Mr()])}function gS(){return v.union([Rl(),Rt()])}function jS(){return v.union([wD(),Mr()])}function $S(){return v.union([Pt(),Rt()])}function GS(){return v.union([CD(),Mr()])}function FS(){return v.union([VD(),Rt()])}function xS(){return v.union([Mr(),cs()])}function fr(){return v.union([Rt(),qi()])}function kS(){return v.union([Al(),Mr()])}function SS(){return v.union([rt(),Rt()])}function ZS(){return v.union([bl(),Mr()])}function qS(){return v.union([Rl(),Rt()])}function JS(){return v.union([On(),ms(),fs()])}function WS(){return v.union([hs(),pr(),ys()])}function zS(){return v.union([ps(),aZ(),gp(),Es(),fi(),Il(),wn(),Vi(),Ht(),ma(),Ts(),vs(),ur(),Cn(),ll(),Pn(),Rn(),Zi(),On(),fs(),ms(),cs(),va(),Zi(),Zi(),ya(),Ia()])}function YS(){return v.union([pl(),ii(),vl(),Vn(),Aa(),El(),_r(),yl(),bp(),fl(),Is(),ha(),TD(),$p(),dl(),_p(),hD(),Dn(),hs(),ys(),pr(),qi(),Ta(),Dn(),Dn(),yD(),wp()])}function HS(){return v.union([gp(),Es(),fi(),Il(),wn(),ma(),Ts(),vs(),On(),fs(),ms(),cs(),va()])}function KS(){return v.union([vl(),Vn(),Aa(),El(),_r(),fl(),Is(),ha(),hs(),ys(),pr(),qi(),Ta()])}function Cn(){return v.union([v.object({type:v.literal(n.ArgumentDeclaration)}),v.record(v.string(),v.any())])}function $p(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.ArgumentDeclaration)})}function Gp(){return v.object({id:v.string(),type:v.literal(n.ArgumentDeclaration)})}function XS(){return Gp().merge(v.object({version:v.number(),x:v.number(),y:v.number()}))}function QS(){return Gp().merge(v.object({}))}function eZ(){return v.object({dataType:Pn().nullable(),writesValues:v.array(cr()),parent:v.union([Rt(),Dn(),Dn(),Ta(),pr()])})}function tZ(){return XS().merge(eZ())}function fi(){return v.union([v.object({type:v.literal(n.FunctionDeclaration)}),v.record(v.string(),v.any())])}function Aa(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.FunctionDeclaration)})}function Fp(){return v.object({id:v.string(),type:v.literal(n.FunctionDeclaration),name:v.string(),description:v.string().nullable()})}function iZ(){return Fp().merge(v.object({version:v.number(),x:v.number(),y:v.number(),index:v.number().nullable()}))}function rZ(){return Fp()}function nZ(){return v.object({inputs:v.array(Cn()),implements:Zi().nullable(),returnStatements:v.array(On()),parent:v.union([ii(),vl(),Vn(),qi(),pl(),dl()])})}function sZ(){return iZ().merge(nZ())}function aZ(){return v.union([v.object({type:v.literal(n.Project)}),v.record(v.string(),v.any())])}function ii(){return v.object({entityType:v.literal(n.Project),entityId:v.string(),id:v.string(),type:v.literal(n.GenericReference)})}function xp(){return v.object({id:v.string(),type:v.literal(n.Project),name:v.string(),description:v.string().nullable()})}function oZ(){return xp().merge(v.object({version:v.number()}))}function lZ(){return xp()}function dZ(){return v.object({entities:v.array(Es()),functions:v.array(fi()),events:v.array(jp()),projects:v.array(gp()),variableDeclarations:v.array(Np()),variableInstances:v.array(DD()),conditions:v.array(ma()),operations:v.array(Ts()),functionCalls:v.array(vs()),loops:v.array(cs()),searches:v.array(va())})}function uZ(){return oZ().merge(dZ())}function Es(){return v.union([v.object({type:v.literal(n.DefinitionEntity)}),v.record(v.string(),v.any())])}function Vn(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.DefinitionEntity)})}function kp(){return v.object({id:v.string(),type:v.literal(n.DefinitionEntity),name:v.string(),description:v.string().nullable(),static:v.boolean(),abstract:v.boolean()})}function pZ(){return kp().merge(v.object({version:v.number(),x:v.number(),y:v.number()}))}function cZ(){return kp().merge(v.object({}))}function fZ(){return v.union([ii(),_p()])}function yZ(){return v.object({properties:v.array(Rn()),methods:v.array(fi()),abstractMethods:v.array(Zi()),extends:v.array(v.union([Es(),ps()])),implements:v.array(v.union([Es(),ps()])),parent:fZ()})}function hZ(){return pZ().merge(yZ())}function mZ(r){return r instanceof Error&&r.name==="ZodError"&&"issues"in r&&Array.isArray(r.issues)}var vZ=class extends Error{constructor(a,e){super(a,e);f(this,"name");f(this,"details");this.name="ZodValidationError",this.details=TZ(e)}toString(){return this.message}};function TZ(r){if(r){const a=r.cause;if(mZ(a))return a.issues}return[]}function IZ(r){return r.length!==0}var EZ=/[$_\p{ID_Start}][$\u200c\u200d\p{ID_Continue}]*/u;function AZ(r){return r.length===1?r[0].toString():r.reduce((a,e)=>{if(typeof e=="number")return a+"["+e.toString()+"]";if(e.includes('"'))return a+'["'+bZ(e)+'"]';if(!EZ.test(e))return a+'["'+e+'"]';const t=a.length===0?"":".";return a+t+e},"")}function bZ(r){return r.replace(/"/g,'\\"')}var RZ="; ",DZ=99,BD="Validation error",OZ=": ",PZ=", or ";function wZ(r={}){const{issueSeparator:a=RZ,unionSeparator:e=PZ,prefixSeparator:t=OZ,prefix:i=BD,includePath:s=!0,maxIssuesInMessage:l=DZ}=r;return o=>{const d=o.slice(0,l).map(u=>Dl({issue:u,issueSeparator:a,unionSeparator:e,includePath:s})).join(a);return CZ(d,i,t)}}function Dl(r){const{issue:a,issueSeparator:e,unionSeparator:t,includePath:i}=r;if(a.code===S.invalid_union)return a.unionErrors.reduce((s,l)=>{const o=l.issues.map(d=>Dl({issue:d,issueSeparator:e,unionSeparator:t,includePath:i})).join(e);return s.includes(o)||s.push(o),s},[]).join(t);if(a.code===S.invalid_arguments)return[a.message,...a.argumentsError.issues.map(s=>Dl({issue:s,issueSeparator:e,unionSeparator:t,includePath:i}))].join(e);if(a.code===S.invalid_return_type)return[a.message,...a.returnTypeError.issues.map(s=>Dl({issue:s,issueSeparator:e,unionSeparator:t,includePath:i}))].join(e);if(i&&IZ(a.path)){if(a.path.length===1){const s=a.path[0];if(typeof s=="number")return`${a.message} at index ${s}`}return`${a.message} at "${AZ(a.path)}"`}return a.message}function CZ(r,a,e){return a!==null?r.length>0?[a,r].join(e):a:r.length>0?r:BD}function VZ(r,a={}){const t=BZ(a)([r]);return new vZ(t,{cause:new ti([r])})}function BZ(r){return"messageBuilder"in r?r.messageBuilder:wZ(r)}var _D="1.13.7",MD=typeof self=="object"&&self.self===self&&self||typeof global=="object"&&global.global===global&&global||Function("return this")()||{},Ol=Array.prototype,Sp=Object.prototype,ND=typeof Symbol<"u"?Symbol.prototype:null,_Z=Ol.push,ba=Ol.slice,Ra=Sp.toString,MZ=Sp.hasOwnProperty,LD=typeof ArrayBuffer<"u",NZ=typeof DataView<"u",LZ=Array.isArray,UD=Object.keys,gD=Object.create,jD=LD&&ArrayBuffer.isView,UZ=isNaN,gZ=isFinite,$D=!{toString:null}.propertyIsEnumerable("toString"),GD=["valueOf","isPrototypeOf","toString","propertyIsEnumerable","hasOwnProperty","toLocaleString"],jZ=Math.pow(2,53)-1;function ri(r,a){return a=a==null?r.length-1:+a,function(){for(var e=Math.max(arguments.length-a,0),t=Array(e),i=0;i<e;i++)t[i]=arguments[i+a];switch(a){case 0:return r.call(this,t);case 1:return r.call(this,arguments[0],t);case 2:return r.call(this,arguments[0],arguments[1],t)}var s=Array(a+1);for(i=0;i<a;i++)s[i]=arguments[i];return s[a]=t,r.apply(this,s)}}function Nr(r){var a=typeof r;return a==="function"||a==="object"&&!!r}function $Z(r){return r===null}function FD(r){return r===void 0}function xD(r){return r===!0||r===!1||Ra.call(r)==="[object Boolean]"}function GZ(r){return!!(r&&r.nodeType===1)}function Ft(r){var a="[object "+r+"]";return function(e){return Ra.call(e)===a}}const Zp=Ft("String"),kD=Ft("Number"),FZ=Ft("Date"),xZ=Ft("RegExp"),kZ=Ft("Error"),SD=Ft("Symbol"),ZD=Ft("ArrayBuffer");var qD=Ft("Function"),SZ=MD.document&&MD.document.childNodes;typeof/./!="function"&&typeof Int8Array!="object"&&typeof SZ!="function"&&(qD=function(r){return typeof r=="function"||!1});const Kt=qD,JD=Ft("Object");var WD=NZ&&(!/\[native code\]/.test(String(DataView))||JD(new DataView(new ArrayBuffer(8)))),qp=typeof Map<"u"&&JD(new Map),ZZ=Ft("DataView");function qZ(r){return r!=null&&Kt(r.getInt8)&&ZD(r.buffer)}const Pl=WD?qZ:ZZ,Bn=LZ||Ft("Array");function Lr(r,a){return r!=null&&MZ.call(r,a)}var Jp=Ft("Arguments");(function(){Jp(arguments)||(Jp=function(r){return Lr(r,"callee")})})();const Wp=Jp;function JZ(r){return!SD(r)&&gZ(r)&&!isNaN(parseFloat(r))}function zD(r){return kD(r)&&UZ(r)}function YD(r){return function(){return r}}function HD(r){return function(a){var e=r(a);return typeof e=="number"&&e>=0&&e<=jZ}}function KD(r){return function(a){return a==null?void 0:a[r]}}const wl=KD("byteLength"),WZ=HD(wl);var zZ=/\[object ((I|Ui)nt(8|16|32)|Float(32|64)|Uint8Clamped|Big(I|Ui)nt64)Array\]/;function YZ(r){return jD?jD(r)&&!Pl(r):WZ(r)&&zZ.test(Ra.call(r))}const XD=LD?YZ:YD(!1),ni=KD("length");function HZ(r){for(var a={},e=r.length,t=0;t<e;++t)a[r[t]]=!0;return{contains:function(i){return a[i]===!0},push:function(i){return a[i]=!0,r.push(i)}}}function QD(r,a){a=HZ(a);var e=GD.length,t=r.constructor,i=Kt(t)&&t.prototype||Sp,s="constructor";for(Lr(r,s)&&!a.contains(s)&&a.push(s);e--;)s=GD[e],s in r&&r[s]!==i[s]&&!a.contains(s)&&a.push(s)}function Vt(r){if(!Nr(r))return[];if(UD)return UD(r);var a=[];for(var e in r)Lr(r,e)&&a.push(e);return $D&&QD(r,a),a}function Da(r){if(r==null)return!0;var a=ni(r);return typeof a=="number"&&(Bn(r)||Zp(r)||Wp(r))?a===0:ni(Vt(r))===0}function eO(r,a){var e=Vt(a),t=e.length;if(r==null)return!t;for(var i=Object(r),s=0;s<t;s++){var l=e[s];if(a[l]!==i[l]||!(l in i))return!1}return!0}function Ke(r){if(r instanceof Ke)return r;if(!(this instanceof Ke))return new Ke(r);this._wrapped=r}Ke.VERSION=_D,Ke.prototype.value=function(){return this._wrapped},Ke.prototype.valueOf=Ke.prototype.toJSON=Ke.prototype.value,Ke.prototype.toString=function(){return String(this._wrapped)};function tO(r){return new Uint8Array(r.buffer||r,r.byteOffset||0,wl(r))}var iO="[object DataView]";function zp(r,a,e,t){if(r===a)return r!==0||1/r===1/a;if(r==null||a==null)return!1;if(r!==r)return a!==a;var i=typeof r;return i!=="function"&&i!=="object"&&typeof a!="object"?!1:rO(r,a,e,t)}function rO(r,a,e,t){r instanceof Ke&&(r=r._wrapped),a instanceof Ke&&(a=a._wrapped);var i=Ra.call(r);if(i!==Ra.call(a))return!1;if(WD&&i=="[object Object]"&&Pl(r)){if(!Pl(a))return!1;i=iO}switch(i){case"[object RegExp]":case"[object String]":return""+r==""+a;case"[object Number]":return+r!=+r?+a!=+a:+r==0?1/+r===1/a:+r==+a;case"[object Date]":case"[object Boolean]":return+r==+a;case"[object Symbol]":return ND.valueOf.call(r)===ND.valueOf.call(a);case"[object ArrayBuffer]":case iO:return rO(tO(r),tO(a),e,t)}var s=i==="[object Array]";if(!s&&XD(r)){var l=wl(r);if(l!==wl(a))return!1;if(r.buffer===a.buffer&&r.byteOffset===a.byteOffset)return!0;s=!0}if(!s){if(typeof r!="object"||typeof a!="object")return!1;var o=r.constructor,d=a.constructor;if(o!==d&&!(Kt(o)&&o instanceof o&&Kt(d)&&d instanceof d)&&"constructor"in r&&"constructor"in a)return!1}e=e||[],t=t||[];for(var u=e.length;u--;)if(e[u]===r)return t[u]===a;if(e.push(r),t.push(a),s){if(u=r.length,u!==a.length)return!1;for(;u--;)if(!zp(r[u],a[u],e,t))return!1}else{var y=Vt(r),c;if(u=y.length,Vt(a).length!==u)return!1;for(;u--;)if(c=y[u],!(Lr(a,c)&&zp(r[c],a[c],e,t)))return!1}return e.pop(),t.pop(),!0}function KZ(r,a){return zp(r,a)}function Oa(r){if(!Nr(r))return[];var a=[];for(var e in r)a.push(e);return $D&&QD(r,a),a}function Yp(r){var a=ni(r);return function(e){if(e==null)return!1;var t=Oa(e);if(ni(t))return!1;for(var i=0;i<a;i++)if(!Kt(e[r[i]]))return!1;return r!==aO||!Kt(e[Hp])}}var Hp="forEach",nO="has",Kp=["clear","delete"],sO=["get",nO,"set"],XZ=Kp.concat(Hp,sO),aO=Kp.concat(sO),QZ=["add"].concat(Kp,Hp,nO);const e7=qp?Yp(XZ):Ft("Map"),t7=qp?Yp(aO):Ft("WeakMap"),i7=qp?Yp(QZ):Ft("Set"),r7=Ft("WeakSet");function As(r){for(var a=Vt(r),e=a.length,t=Array(e),i=0;i<e;i++)t[i]=r[a[i]];return t}function n7(r){for(var a=Vt(r),e=a.length,t=Array(e),i=0;i<e;i++)t[i]=[a[i],r[a[i]]];return t}function oO(r){for(var a={},e=Vt(r),t=0,i=e.length;t<i;t++)a[r[e[t]]]=e[t];return a}function Xp(r){var a=[];for(var e in r)Kt(r[e])&&a.push(e);return a.sort()}function Qp(r,a){return function(e){var t=arguments.length;if(a&&(e=Object(e)),t<2||e==null)return e;for(var i=1;i<t;i++)for(var s=arguments[i],l=r(s),o=l.length,d=0;d<o;d++){var u=l[d];(!a||e[u]===void 0)&&(e[u]=s[u])}return e}}const lO=Qp(Oa),Cl=Qp(Vt),dO=Qp(Oa,!0);function s7(){return function(){}}function uO(r){if(!Nr(r))return{};if(gD)return gD(r);var a=s7();a.prototype=r;var e=new a;return a.prototype=null,e}function a7(r,a){var e=uO(r);return a&&Cl(e,a),e}function o7(r){return Nr(r)?Bn(r)?r.slice():lO({},r):r}function l7(r,a){return a(r),r}function pO(r){return Bn(r)?r:[r]}Ke.toPath=pO;function Pa(r){return Ke.toPath(r)}function ec(r,a){for(var e=a.length,t=0;t<e;t++){if(r==null)return;r=r[a[t]]}return e?r:void 0}function cO(r,a,e){var t=ec(r,Pa(a));return FD(t)?e:t}function d7(r,a){a=Pa(a);for(var e=a.length,t=0;t<e;t++){var i=a[t];if(!Lr(r,i))return!1;r=r[i]}return!!e}function tc(r){return r}function wa(r){return r=Cl({},r),function(a){return eO(a,r)}}function ic(r){return r=Pa(r),function(a){return ec(a,r)}}function Ca(r,a,e){if(a===void 0)return r;switch(e??3){case 1:return function(t){return r.call(a,t)};case 3:return function(t,i,s){return r.call(a,t,i,s)};case 4:return function(t,i,s,l){return r.call(a,t,i,s,l)}}return function(){return r.apply(a,arguments)}}function fO(r,a,e){return r==null?tc:Kt(r)?Ca(r,a,e):Nr(r)&&!Bn(r)?wa(r):ic(r)}function rc(r,a){return fO(r,a,1/0)}Ke.iteratee=rc;function si(r,a,e){return Ke.iteratee!==rc?Ke.iteratee(r,a):fO(r,a,e)}function u7(r,a,e){a=si(a,e);for(var t=Vt(r),i=t.length,s={},l=0;l<i;l++){var o=t[l];s[o]=a(r[o],o,r)}return s}function yO(){}function p7(r){return r==null?yO:function(a){return cO(r,a)}}function c7(r,a,e){var t=Array(Math.max(0,r));a=Ca(a,e,1);for(var i=0;i<r;i++)t[i]=a(i);return t}function nc(r,a){return a==null&&(a=r,r=0),r+Math.floor(Math.random()*(a-r+1))}const Va=Date.now||function(){return new Date().getTime()};function hO(r){var a=function(s){return r[s]},e="(?:"+Vt(r).join("|")+")",t=RegExp(e),i=RegExp(e,"g");return function(s){return s=s==null?"":""+s,t.test(s)?s.replace(i,a):s}}const mO={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;","`":"&#x60;"},f7=hO(mO),y7=oO(mO),h7=hO(y7),m7=Ke.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var sc=/(.)^/,v7={"'":"'","\\":"\\","\r":"r","\n":"n","\u2028":"u2028","\u2029":"u2029"},T7=/\\|'|\r|\n|\u2028|\u2029/g;function I7(r){return"\\"+v7[r]}var E7=/^\s*(\w|\$)+\s*$/;function A7(r,a,e){!a&&e&&(a=e),a=dO({},a,Ke.templateSettings);var t=RegExp([(a.escape||sc).source,(a.interpolate||sc).source,(a.evaluate||sc).source].join("|")+"|$","g"),i=0,s="__p+='";r.replace(t,function(u,y,c,I,E){return s+=r.slice(i,E).replace(T7,I7),i=E+u.length,y?s+=`'+
24
+ LIMIT 10 OFFSET 0;`,w6={id:"find-companies-with-multiple-employees-and-bank-account-search-parent-ref-id",type:n.GenericReference,entityId:ce,version:"1",entityType:n.Project},C6={id:"find-companies-with-multiple-employees-and-bank-account-search-companies-list-output-declaration-parent-ref-id",type:n.GenericReference,entityId:"find-companies-with-multiple-employees-and-bank-account",version:"1",entityType:n.Search},WR={id:"find-companies-with-multiple-employees-and-bank-account-search-companies-list-output-declaration-id",type:n.ValueDescriptor,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,name:"companies",description:"List of companies with multiple employees and an existing bank account",defaultValue:null,dataType:null,required:!0,parentRelationType:N.FixedReturns,index:0,parent:C6},V6={id:"find-companies-with-multiple-employees-and-bank-account-search-companies-list-output-parent-ref-id",type:n.GenericReference,entityId:"find-companies-with-multiple-employees-and-bank-account",version:"1",entityType:n.Search},B6={id:"find-companies-with-multiple-employees-and-bank-account-search-companies-list-output-id",type:n.OutputMap,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,defaultValue:null,declaration:WR,writesValues:[],index:0,parent:V6},_6={id:"find-companies-with-multiple-employees-and-bank-account",type:n.Search,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,name:"Find companies with multiple employees and a bank account",description:"This search statement finds companies with multiple employees and an existing bank account",inputsDeclarations:[],outputsDeclarations:[WR],inputs:[],outputs:[B6],query:P6,successCalls:[],errorCalls:[],error:null,calledByError:[],calledByEntry:[],calledBySuccess:[],x:0,y:0,parent:w6},M6={type:n.GenericReference,id:"employee-mapped-dto-manager-input-map-reads-value-ref-id",version:"1",entityType:n.OutputMap,entityId:NR},N6={type:n.GenericReference,id:"employee-mapped-dto-manager-output-map-parent-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:Si},zR={id:C9,type:n.InputMap,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,declaration:null,name:"manager_id",description:null,defaultValue:null,index:4,readsValue:M6,parent:N6},L6={type:n.GenericReference,id:"employee-mapped-dto-department-input-map-reads-value-ref-id",version:"1",entityType:n.OutputMap,entityId:_R},U6={type:n.GenericReference,id:"employee-mapped-dto-department-output-map-parent-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:Si},YR={id:w9,type:n.InputMap,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,declaration:null,name:"department_name",description:null,defaultValue:null,index:3,readsValue:L6,parent:U6},g6={type:n.GenericReference,id:"employee-mapped-dto-birth-date-input-map-reads-value-ref-id",version:"1",entityType:n.OutputMap,entityId:BR},j6={type:n.GenericReference,id:"employee-mapped-dto-birth-date-output-map-parent-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:Si},HR={id:P9,type:n.InputMap,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,declaration:null,name:"birth_date",description:null,defaultValue:null,index:2,readsValue:g6,parent:j6},$6={type:n.GenericReference,id:"employee-mapped-dto-id-output-map-reads-value-ref-id",version:"1",entityType:n.OutputMap,entityId:VR},G6={type:n.GenericReference,id:"employee-mapped-dto-id-output-map-parent-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:Si},KR={id:O9,type:n.InputMap,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,declaration:null,name:"id",description:"The ID of the employee",defaultValue:null,index:1,readsValue:$6,parent:G6},F6={type:n.GenericReference,id:"employee-mapped-dto-requester-id-output-map-reads-value-ref-id",version:"1",entityType:n.OutputMap,entityId:LR},x6={type:n.GenericReference,id:"employee-mapped-dto-requester-id-output-map-parent-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:Si},XR={id:D9,type:n.InputMap,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,declaration:null,name:"requester_id",description:"The ID of the current user making the request",defaultValue:null,index:0,readsValue:F6,parent:x6},k6={type:n.GenericReference,id:"manager-variable-id-output-map-parent-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:tp},S6={id:NR,type:n.OutputMap,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,declaration:pi.properties[0],defaultValue:null,index:0,writesValues:[zR],parent:k6},Z6={type:n.GenericReference,id:"manager-variable-data-type-parent-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:tp},q6={like:!1,inferred:!1,id:"manager-variable-data-type-id",type:n.DataType,parentRelationType:null,options:null,implementationChooseOne:!1,andChildrenGroup:null,orChildrenGroup:null,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,entity:Ei,asType:!1,isList:!1,parent:Z6},J6={type:n.GenericReference,id:"manager-variable-reads-value-ref-id",version:"1",entityType:n.OutputMap,entityId:MR},W6={type:n.GenericReference,id:"manager-variable-parent-ref-id",version:"1",entityType:n.Project,entityId:ce},QR={constant:!0,required:!0,id:tp,type:n.VariableDeclaration,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,name:"Manager",dataType:q6,description:"A variable holding an inherited manager for testing purposes",defaultValue:null,calledByError:[],calledByEntry:[],calledBySuccess:[],successCalls:[],errorCalls:[],readsValue:J6,writesValues:[],inputs:[],outputs:[S6],internalCalls:[],parent:W6,x:0,y:0},z6={type:n.GenericReference,id:"random-company-employee-manager-output-map-parent-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:us},Y6={id:MR,type:n.OutputMap,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,defaultValue:null,declaration:Ei.properties[2],index:3,writesValues:[QR],parent:z6},H6={type:n.GenericReference,id:"random-company-employee-department-output-map-parent-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:us},K6={id:_R,type:n.OutputMap,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,defaultValue:null,declaration:Ei.properties[0],index:2,writesValues:[YR],parent:H6},X6={type:n.GenericReference,id:"random-company-employee-birth-date-output-map-parent-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:us},Q6={id:BR,type:n.OutputMap,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,defaultValue:null,declaration:Wt.properties[1],index:1,writesValues:[HR],parent:X6},e3={type:n.GenericReference,id:"random-company-employee-id-output-map-parent-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:us},t3={id:VR,type:n.OutputMap,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,defaultValue:null,declaration:pi.properties[0],index:0,writesValues:[KR],parent:e3},i3={type:n.GenericReference,id:"random-company-employee-test-variable-data-type-parent-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:us},r3={like:!1,inferred:!1,id:"random-company-employee-test-variable-data-type-id",type:n.DataType,parentRelationType:null,options:null,implementationChooseOne:!1,andChildrenGroup:null,orChildrenGroup:null,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,entity:Ei,asType:!1,isList:!1,parent:i3},n3={type:n.GenericReference,id:"random-company-employee-test-variable-parent-ref-id",version:"1",entityType:n.Project,entityId:ce},s3={constant:!0,required:!0,id:us,type:n.VariableDeclaration,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,name:"Company employee",dataType:r3,description:"A variable holding a random company employee for testing purposes",defaultValue:null,calledByError:[],calledByEntry:[],calledBySuccess:[],successCalls:[],errorCalls:[],readsValue:null,writesValues:[],inputs:[],outputs:[t3,Q6,K6,Y6],internalCalls:[],parent:n3,x:0,y:0},a3={type:n.GenericReference,id:"employee-mapped-dto-variable-instance-now-timestamp-input-map-default-value-parent-ref-id",version:"1",entityType:n.InputMap,entityId:UR},o3={type:n.LiteralValue,id:"employee-mapped-dto-variable-instance-now-timestamp-input-map-default-value-id",name:L.Date,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,valueAsTypeList:null,valueAsTypeSingle:null,value:null,autogeneration:{type:vt.CurrentDateAndTime,rangeStart:null,rangeEnd:null},parent:a3},l3={type:n.GenericReference,id:"employee-mapped-dto-variable-instance-now-timestamp-input-map-parent-ref-id",version:"1",entityType:n.VariableInstance,entityId:bn},d3={id:UR,type:n.InputMap,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,declaration:null,name:"now",description:"The current timestamp when the operation is executed",defaultValue:o3,index:5,readsValue:null,parent:l3},u3={type:n.GenericReference,id:"employee-mapped-dto-variable-instance-decl-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:Si},p3={type:n.GenericReference,id:"employee-mapped-dto-variable-instance-called-by-success-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:Si},c3={type:n.GenericReference,id:"employee-mapped-dto-variable-instance-parent-ref-id",version:"1",entityType:n.Project,entityId:ce},f3={id:bn,type:n.VariableInstance,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,defaultValue:null,declaration:u3,calledByError:[],calledByEntry:[],calledBySuccess:[p3],successCalls:[rp,SR,gR],errorCalls:[],readsValue:null,writesValues:[kR],inputs:[d3],outputs:[],internalCalls:[],parent:c3,x:0,y:0},y3={type:n.GenericReference,id:"employee-mapped-dto-variable-parent-ref-id",version:"1",entityType:n.Project,entityId:ce},h3={constant:!0,required:!0,id:Si,type:n.VariableDeclaration,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,name:"Employee DTO",dataType:null,description:"A variable holding the data of a mapped employee DTO",defaultValue:null,calledByError:[],calledByEntry:[],calledBySuccess:[],successCalls:[rp,f3],errorCalls:[],readsValue:null,writesValues:[GR],inputs:[XR,KR,HR,YR,zR],outputs:[],internalCalls:[],parent:y3,x:0,y:0},m3={type:n.GenericReference,id:"0e63e617-f9d3-42e8-bde0-1bb0b1df7034",version:"1",entityType:n.VariableDeclaration,entityId:KE},v3={like:!1,inferred:!1,id:"e75645ce-d3df-4f07-a897-ae9ef4d917fd",type:n.DataType,parentRelationType:null,options:null,implementationChooseOne:!1,andChildrenGroup:null,orChildrenGroup:null,entity:Au,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,asType:!1,isList:!1,parent:m3},T3={type:n.GenericReference,id:"e92a8ff5-3fef-4e0c-8d8f-92c930b2890b",version:"1",entityType:n.Project,entityId:ce},eD={constant:!0,required:!0,id:KE,type:n.VariableDeclaration,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,name:"Current user",description:"The user that is currently logged in",defaultValue:null,dataType:v3,inputs:[],outputs:[],calledByError:[],calledByEntry:[],calledBySuccess:[],successCalls:[],errorCalls:[],x:0,y:0,readsValue:null,writesValues:[],internalCalls:[],parent:T3},I3={type:n.GenericReference,id:"manager-variable-id-output-map-parent-ref-id",version:"1",entityType:n.VariableInstance,entityId:CR},E3={id:LR,type:n.OutputMap,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,defaultValue:null,declaration:pi.properties[0],index:0,writesValues:[XR],parent:I3},A3={type:n.GenericReference,id:"global-user-instance-parent-ref-id",version:"1",entityType:n.Project,entityId:ce},b3={id:CR,type:n.VariableInstance,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,defaultValue:null,declaration:eD,calledByError:[],calledByEntry:[],calledBySuccess:[],successCalls:[],errorCalls:[],readsValue:null,writesValues:[],inputs:[],outputs:[E3],internalCalls:[],parent:A3,x:0,y:0},R3={type:n.GenericReference,id:"is-test-environment-variable-dcl-datatype-parent-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:"is-test-environment-variable-dcl-id"},D3={type:n.GenericReference,id:"is-test-environment-variable-dcl-datatype-default-value-parent-ref-id",version:"1",entityType:n.VariableDeclaration,entityId:"is-test-environment-variable-dcl-id"},O3={like:!1,inferred:!1,id:"is-test-environment-variable-dcl-datatype-id",type:n.DataType,parentRelationType:null,options:null,implementationChooseOne:!1,andChildrenGroup:null,orChildrenGroup:null,entity:er,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,asType:!1,isList:!1,parent:R3},P3={type:n.GenericReference,id:"is-test-environment-variable-dcl-main-project-ref-id",version:"1",entityType:n.Project,entityId:ce},tD={constant:!0,required:!0,id:"is-test-environment-variable-dcl-id",type:n.VariableDeclaration,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,name:"Is test envrioment",description:"Indicates whether the current environment is a test environment or not.",defaultValue:{id:"is-test-environment-variable-dcl-datatype-default-value-id",name:L.Boolean,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,value:null,type:n.LiteralValue,autogeneration:{type:vt.Random,rangeStart:null,rangeEnd:null},valueAsTypeList:null,valueAsTypeSingle:null,parent:D3},dataType:O3,inputs:[],outputs:[],calledByError:[],calledByEntry:[],calledBySuccess:[],successCalls:[],errorCalls:[],x:0,y:0,readsValue:null,writesValues:[],internalCalls:[],parent:P3},w3={type:n.GenericReference,id:"is-test-environment-variable-instance-parent-ref-id",version:"1",entityType:n.Project,entityId:ce},C3={id:"is-test-environment-variable-instance-id",type:n.VariableInstance,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,defaultValue:null,declaration:tD,calledByError:[],calledByEntry:[],calledBySuccess:[],successCalls:[],errorCalls:[],readsValue:null,writesValues:[],inputs:[],outputs:[],internalCalls:[],parent:w3,x:0,y:0},lp={type:n.Project,id:ce,version:"1",createdAt:"2024-01-01T00:00:00.000Z",author:"1",previousVersion:null,deleted:!1,name:"Mocked project to compile",description:"This project is used to test all sorts of features and edge cases. It is not meant to be used in production. Or to have any functionality that makes sense",projects:[v9],entities:[Eu,pi,Au,Wt,dj,Ei,Zo,yA,hA,rs,kU,Ai,gg,Iu,rB,Wg,FU],functions:[gx,jA,$u,qx,ek,YA,Gu,Ou,f9,DA,Sk],events:[kj],variableDeclarations:[tD,eD,Zu,s3,QR,h3],variableInstances:[C3,b3],conditions:[],operations:[os],functionCalls:[k2,Q$],loops:[O6,rp,SR,h6,gR],searches:[_6]};var iD={exports:{}};(function(r,a){(function(e,t){r.exports=t()})(OC,function(){var e=1e3,t=6e4,i=36e5,s="millisecond",l="second",o="minute",d="hour",u="day",y="week",c="month",I="quarter",E="year",O="date",P="Invalid Date",V=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,M=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,G={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),ordinal:function(me){var ie=["th","st","nd","rd"],Y=me%100;return"["+me+(ie[(Y-20)%10]||ie[Y]||ie[0])+"]"}},B=function(me,ie,Y){var ue=String(me);return!ue||ue.length>=ie?me:""+Array(ie+1-ue.length).join(Y)+me},$={s:B,z:function(me){var ie=-me.utcOffset(),Y=Math.abs(ie),ue=Math.floor(Y/60),ee=Y%60;return(ie<=0?"+":"-")+B(ue,2,"0")+":"+B(ee,2,"0")},m:function me(ie,Y){if(ie.date()<Y.date())return-me(Y,ie);var ue=12*(Y.year()-ie.year())+(Y.month()-ie.month()),ee=ie.clone().add(ue,c),je=Y-ee<0,$e=ie.clone().add(ue+(je?-1:1),c);return+(-(ue+(Y-ee)/(je?ee-$e:$e-ee))||0)},a:function(me){return me<0?Math.ceil(me)||0:Math.floor(me)},p:function(me){return{M:c,y:E,w:y,d:u,D:O,h:d,m:o,s:l,ms:s,Q:I}[me]||String(me||"").toLowerCase().replace(/s$/,"")},u:function(me){return me===void 0}},Z="en",J={};J[Z]=G;var te="$isDayjsObject",fe=function(me){return me instanceof ei||!(!me||!me[te])},Ie=function me(ie,Y,ue){var ee;if(!ie)return Z;if(typeof ie=="string"){var je=ie.toLowerCase();J[je]&&(ee=je),Y&&(J[je]=Y,ee=je);var $e=ie.split("-");if(!ee&&$e.length>1)return me($e[0])}else{var ft=ie.name;J[ft]=ie,ee=ft}return!ue&&ee&&(Z=ee),ee||!ue&&Z},X=function(me,ie){if(fe(me))return me.clone();var Y=typeof ie=="object"?ie:{};return Y.date=me,Y.args=arguments,new ei(Y)},le=$;le.l=Ie,le.i=fe,le.w=function(me,ie){return X(me,{locale:ie.$L,utc:ie.$u,x:ie.$x,$offset:ie.$offset})};var ei=function(){function me(Y){this.$L=Ie(Y.locale,null,!0),this.parse(Y),this.$x=this.$x||Y.x||{},this[te]=!0}var ie=me.prototype;return ie.parse=function(Y){this.$d=function(ue){var ee=ue.date,je=ue.utc;if(ee===null)return new Date(NaN);if(le.u(ee))return new Date;if(ee instanceof Date)return new Date(ee);if(typeof ee=="string"&&!/Z$/i.test(ee)){var $e=ee.match(V);if($e){var ft=$e[2]-1||0,bt=($e[7]||"0").substring(0,3);return je?new Date(Date.UTC($e[1],ft,$e[3]||1,$e[4]||0,$e[5]||0,$e[6]||0,bt)):new Date($e[1],ft,$e[3]||1,$e[4]||0,$e[5]||0,$e[6]||0,bt)}}return new Date(ee)}(Y),this.init()},ie.init=function(){var Y=this.$d;this.$y=Y.getFullYear(),this.$M=Y.getMonth(),this.$D=Y.getDate(),this.$W=Y.getDay(),this.$H=Y.getHours(),this.$m=Y.getMinutes(),this.$s=Y.getSeconds(),this.$ms=Y.getMilliseconds()},ie.$utils=function(){return le},ie.isValid=function(){return this.$d.toString()!==P},ie.isSame=function(Y,ue){var ee=X(Y);return this.startOf(ue)<=ee&&ee<=this.endOf(ue)},ie.isAfter=function(Y,ue){return X(Y)<this.startOf(ue)},ie.isBefore=function(Y,ue){return this.endOf(ue)<X(Y)},ie.$g=function(Y,ue,ee){return le.u(Y)?this[ue]:this.set(ee,Y)},ie.unix=function(){return Math.floor(this.valueOf()/1e3)},ie.valueOf=function(){return this.$d.getTime()},ie.startOf=function(Y,ue){var ee=this,je=!!le.u(ue)||ue,$e=le.p(Y),ft=function(jn,li){var sn=le.w(ee.$u?Date.UTC(ee.$y,li,jn):new Date(ee.$y,li,jn),ee);return je?sn:sn.endOf(u)},bt=function(jn,li){return le.w(ee.toDate()[jn].apply(ee.toDate("s"),(je?[0,0,0,0]:[23,59,59,999]).slice(li)),ee)},Bt=this.$W,Zt=this.$M,Di=this.$D,ws="set"+(this.$u?"UTC":"");switch($e){case E:return je?ft(1,0):ft(31,11);case c:return je?ft(1,Zt):ft(0,Zt+1);case y:var gn=this.$locale().weekStart||0,xa=(Bt<gn?Bt+7:Bt)-gn;return ft(je?Di-xa:Di+(6-xa),Zt);case u:case O:return bt(ws+"Hours",0);case d:return bt(ws+"Minutes",1);case o:return bt(ws+"Seconds",2);case l:return bt(ws+"Milliseconds",3);default:return this.clone()}},ie.endOf=function(Y){return this.startOf(Y,!1)},ie.$set=function(Y,ue){var ee,je=le.p(Y),$e="set"+(this.$u?"UTC":""),ft=(ee={},ee[u]=$e+"Date",ee[O]=$e+"Date",ee[c]=$e+"Month",ee[E]=$e+"FullYear",ee[d]=$e+"Hours",ee[o]=$e+"Minutes",ee[l]=$e+"Seconds",ee[s]=$e+"Milliseconds",ee)[je],bt=je===u?this.$D+(ue-this.$W):ue;if(je===c||je===E){var Bt=this.clone().set(O,1);Bt.$d[ft](bt),Bt.init(),this.$d=Bt.set(O,Math.min(this.$D,Bt.daysInMonth())).$d}else ft&&this.$d[ft](bt);return this.init(),this},ie.set=function(Y,ue){return this.clone().$set(Y,ue)},ie.get=function(Y){return this[le.p(Y)]()},ie.add=function(Y,ue){var ee,je=this;Y=Number(Y);var $e=le.p(ue),ft=function(Zt){var Di=X(je);return le.w(Di.date(Di.date()+Math.round(Zt*Y)),je)};if($e===c)return this.set(c,this.$M+Y);if($e===E)return this.set(E,this.$y+Y);if($e===u)return ft(1);if($e===y)return ft(7);var bt=(ee={},ee[o]=t,ee[d]=i,ee[l]=e,ee)[$e]||1,Bt=this.$d.getTime()+Y*bt;return le.w(Bt,this)},ie.subtract=function(Y,ue){return this.add(-1*Y,ue)},ie.format=function(Y){var ue=this,ee=this.$locale();if(!this.isValid())return ee.invalidDate||P;var je=Y||"YYYY-MM-DDTHH:mm:ssZ",$e=le.z(this),ft=this.$H,bt=this.$m,Bt=this.$M,Zt=ee.weekdays,Di=ee.months,ws=ee.meridiem,gn=function(li,sn,ka,ld){return li&&(li[sn]||li(ue,je))||ka[sn].slice(0,ld)},xa=function(li){return le.s(ft%12||12,li,"0")},jn=ws||function(li,sn,ka){var ld=li<12?"AM":"PM";return ka?ld.toLowerCase():ld};return je.replace(M,function(li,sn){return sn||function(ka){switch(ka){case"YY":return String(ue.$y).slice(-2);case"YYYY":return le.s(ue.$y,4,"0");case"M":return Bt+1;case"MM":return le.s(Bt+1,2,"0");case"MMM":return gn(ee.monthsShort,Bt,Di,3);case"MMMM":return gn(Di,Bt);case"D":return ue.$D;case"DD":return le.s(ue.$D,2,"0");case"d":return String(ue.$W);case"dd":return gn(ee.weekdaysMin,ue.$W,Zt,2);case"ddd":return gn(ee.weekdaysShort,ue.$W,Zt,3);case"dddd":return Zt[ue.$W];case"H":return String(ft);case"HH":return le.s(ft,2,"0");case"h":return xa(1);case"hh":return xa(2);case"a":return jn(ft,bt,!0);case"A":return jn(ft,bt,!1);case"m":return String(bt);case"mm":return le.s(bt,2,"0");case"s":return String(ue.$s);case"ss":return le.s(ue.$s,2,"0");case"SSS":return le.s(ue.$ms,3,"0");case"Z":return $e}return null}(li)||$e.replace(":","")})},ie.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},ie.diff=function(Y,ue,ee){var je,$e=this,ft=le.p(ue),bt=X(Y),Bt=(bt.utcOffset()-this.utcOffset())*t,Zt=this-bt,Di=function(){return le.m($e,bt)};switch(ft){case E:je=Di()/12;break;case c:je=Di();break;case I:je=Di()/3;break;case y:je=(Zt-Bt)/6048e5;break;case u:je=(Zt-Bt)/864e5;break;case d:je=Zt/i;break;case o:je=Zt/t;break;case l:je=Zt/e;break;default:je=Zt}return ee?je:le.a(je)},ie.daysInMonth=function(){return this.endOf(c).$D},ie.$locale=function(){return J[this.$L]},ie.locale=function(Y,ue){if(!Y)return this.$L;var ee=this.clone(),je=Ie(Y,ue,!0);return je&&(ee.$L=je),ee},ie.clone=function(){return le.w(this.$d,this)},ie.toDate=function(){return new Date(this.valueOf())},ie.toJSON=function(){return this.isValid()?this.toISOString():null},ie.toISOString=function(){return this.$d.toISOString()},ie.toString=function(){return this.$d.toUTCString()},me}(),Xi=ei.prototype;return X.prototype=Xi,[["$ms",s],["$s",l],["$m",o],["$H",d],["$W",u],["$M",c],["$y",E],["$D",O]].forEach(function(me){Xi[me[1]]=function(ie){return this.$g(ie,me[0],me[1])}}),X.extend=function(me,ie){return me.$i||(me(ie,ei,X),me.$i=!0),X},X.locale=Ie,X.isDayjs=fe,X.unix=function(me){return X(1e3*me)},X.en=J[Z],X.Ls=J,X.p={},X})})(iD);var V3=iD.exports;const T=CE(V3);var D=(r=>(r.Error="error",r.Warning="warning",r))(D||{}),j=(r=>(r.InvalidObjectStructure="invalid-object-structure",r.NameNotUniqueInScope="name-not-unique-in-scope",r.EmptyName="empty-name",r.MissingCaller="missing-caller",r.PropertyOverwritesOtherSiblingWithSameName="property-overwrites-other-sibling-with-same-name",r.PropertyOverwritesOtherSiblingWithSameImplementation="property-overwrites-other-sibling-with-same-name",r.PropertyOverwritesOtherImplementedEntitysPropertyWithSameName="property-overwrites-other-implemented-entitys-property-with-same-name",r.PropertyOverwritesOtherImplementedEntitysPropertyWithSameImplementation="property-overwrites-other-implemented-entitys-property-with-same-name",r.PropertyOverwritesOtherExtendedEntitysPropertyWithSameImplementation="property-overwrites-other-extended-entitys-property-with-same-name",r.PropertyOverwritesOtherExtendedEntitysPropertyWithSameName="property-overwrites-other-extended-entitys-property-with-same-name",r.PropertyOverwritesBasePropertyWithSameName="property-overwrites-base-property-with-same-name",r.PropertyOverwritesBasePropertyWithSameImplementation="property-overwrites-base-property-with-same-name",r.MethodOverwritesOtherSiblingWithSameName="method-overwrites-other-sibling-with-same-name",r.MethodOverwritesOtherSiblingWithSameImplementation="method-overwrites-other-sibling-with-same-name",r.MethodOverwritesOtherImplementedEntitysMethodWithSameName="method-overwrites-other-implemented-entitys-method-with-same-name",r.MethodOverwritesOtherImplementedEntitysMethodWithSameImplementation="method-overwrites-other-implemented-entitys-method-with-same-name",r.MethodOverwritesOtherExtendedEntitysMethodWithSameImplementation="method-overwrites-other-extended-entitys-method-with-same-name",r.MethodOverwritesOtherExtendedEntitysMethodWithSameName="method-overwrites-other-extended-entitys-method-with-same-name",r.MethodOverwritesBaseMethodWithSameName="method-overwrites-base-method-with-same-name",r.MethodOverwritesBaseMethodWithSameImplementation="method-overwrites-base-method-with-same-name",r.LoopBodyFunctionOverwrite="loop-body-function-overwrite",r.NoOverlapWithImplementedSignature="no-overlap-with-implemented-signature",r.ReaderWriterIncompatibleDataType="reader-writer-incompatible-data-type",r.UnreachableEntity="unreachable-entity",r.InternalCallParentMissingDataType="internal-call-parent-missing-data-type",r.InternalCallParentDeclarationEntityInvalidType="internal-call-parent-declaration-entity-invalid-type",r.InternalCallDeclarationNotFoundInParentDatatypeEntity="internal-call-declaration-not-found-in-parent-datatype-entity",r.InternalCallDeclarationIsNotFunctionDeclaration="internal-call-declaration-is-not-function-declaration",r.InternalCallDeclarationNotInParentDatatypeEntity="internal-call-declaration-not-in-parent-datatype-entity",r))(j||{}),R=(r=>(r.RootReference="root-reference",r.ReferencedEntityNotFound="referenced-entity-not-found",r.EntityIdNotUnique="entity-id-not-unique",r.BuiltInEntityGenerated="built-in-entity-generated",r.BuiltInEntityUpdated="built-in-entity-updated",r.BuiltInEntityDeleted="built-in-entity-deleted",r.UnknownEntityType="unknown-entity-type",r.MissingTypeProperty="missing-type-property",r.MissingIdProperty="missing-id-property",r.BuiltInEntityParent="built-in-entity-parent",r.InvalidBuiltInEntityReference="invalid-built-in-entity-reference",r.RecommendedImplementAbstractEntityAction="recommended-implement-abstract-entity-action",r.RecommendedImplementOperationAction="recommended-implement-operation-action",r.RecommendedImplementFunctionCallAction="recommended-implement-function-call-action",r.RecommendedImplementVariableDeclarationAction="recommended-implement-variable-declaration-action",r.RecommendedImplementVariableInstanceAction="recommended-implement-variable-instance-action",r.RecommendedImplementConditionAction="recommended-implement-condition-action",r.InvalidReferenceObjectStructure="invalid-reference-object-structure",r.ContainsSingleButShouldBeReferenceList="contains-single-but-should-be-reference-list",r.ContainsListButShouldReferenceSingle="contains-list-but-should-reference-single",r.InvalidParentReference="invalid-parent-reference",r.InvalidImplementsReference="invalid-implements-reference",r.InvalidExtendsReference="invalid-extends-reference",r.InvalidGenerationActionPayload="invalid-generation-action-payload",r.InvalidReference="invalid-reference",r.InvalidInternalCallParentRelation="invalid-internal-call-parent-relation",r.InvalidUpdateEntityOperation="invalid-update-entity-operation",r.NewEntityWouldOverriteExisting="new-entity-would-overrite-existing",r.InvalidDownstreamPropertyOverride="invalid-downstream-property-override",r.UnrecognizedProperty="unrecognized-property",r.SelfReference="self-reference",r.DuplicateReference="duplicate-reference",r.CallerWithIncompatibleScope="caller-with-incompatible-scope",r.InvalidFunctionDeclarationForFunctionCall="invalid-function-declaration-for-function-call",r.InvalidInputMapDeclaration="invalid-input-map-declaration",r.InvalidActionDescriptorForOperation="invalid-action-descriptor-for-operation",r.InvalidActionDescriptorForCondition="invalid-action-descriptor-for-condition",r.InvalidActionDescriptorForLoop="invalid-action-descriptor-for-loop",r.InvalidInmutablePropertyOverride="invalid-inmutable-property-override",r.OutputOverwrite="output-overwrite",r.InputOverwrite="input-overwrite",r.IncompatibleScope="incompatible-scope",r.InvalidParentUpdate="invalid-parent-update",r.NonInteractiveEntityReferenced="non-interactive-entity-referenced",r.InvalidParentRelationType="invalid-parent-relation-type",r))(R||{}),F=(r=>(r.NoPrimaryKeyProperty="no-primary-key-property",r.ScopeWithoutLogic="scope-without-logic",r.AbstractEntityImplements="abstract-entity-implements",r.ImplementsIncompatibleEntities="implements-incompatible-entities",r.ExtendsIncompatibleEntities="extends-incompatible-entities",r.NonAbstractExtendingAbstractEntity="non-abstract-extending-abstract-entity",r.AbstractExtendingNonAbstractEntity="abstract-extending-non-abstract-entity",r.NonStaticExtendingStaticEntity="non-static-extending-static-entity",r.StaticExtendingNonStaticEntity="static-extending-non-static-entity",r.StaticImplementingNonStaticEntity="static-implementing-non-static-entity",r.NonStaticImplementingStaticEntity="non-static-implementing-static-entity",r.ImplementingNonAbstractEntity="implementing-non-abstract-entity",r.ExtendingNonInteractiveEntity="extending-non-interactive-entity",r.AbstractEntityWithNonAbstractMethods="abstract-entity-with-non-abstract-methods",r.AbstractEntityWithNonAbstractProperties="abstract-entity-with-non-abstract-properties",r.StaticEntityWithNonStaticProperties="static-entity-with-non-static-properties",r.NonStaticPropertyInStaticEntity="non-static-property-in-static-entity",r.AbstractPropertyInNonAbstractEntity="abstract-property-in-non-abstract-entity",r.AbstractMethodInNonAbstractEntity="abstract-method-in-non-abstract-entity",r.IncorrectEntityImplementation="incorrect-entity-implementation",r.IncorrectMethodImplementation="incorrect-method-implementation",r.IncorrectPropertyImplementation="incorrect-property-implementation",r.PropertyImplementsNonAbstact="property-implements-non-abstract",r.NonStaticPropertyImplementsStatic="non-static-property-implements-static",r.StaticPropertyImplementsNonStatic="static-property-implements-non-static",r.PropertyImplementsIncompatibleType="property-implements-incompatible-type",r.MissingPropertyImplementation="missing-property-implementation",r.MissingMethodImplementation="missing-method-implementation",r.NoProperties="no-properties",r.ReadingFromIncompatibleType="reading-from-incompatible-type",r.WritingToIncompatibleType="writing-to-incompatible-type",r.InvalidPropertiesCombination="invalid-properties-combination",r.DisconnectedCallableEntity="disconnected-callable-entity",r.VariableReadsValueAndInternalCall="variable-reads-value-and-internal-call",r.VariableWritesValuesAndInternalCall="variable-writes-values-and-internal-call",r.VariableHasInputsAndInternalCall="variable-has-inputs-and-internal-calls",r.VariableHasOutputsAndInternalCall="variable-has-outputs-and-internal-call",r.VariableIsCalledAndHasInternalCall="variable-is-called-and-has-internal-call",r.VariableCallsOthersAndHasInternalCall="variable-calls-others-and-has-internal-call",r))(F||{});class w{constructor(a){f(this,"id");f(this,"message");f(this,"issue");f(this,"severity");f(this,"code");this.id=a.id,this.message=a.message,this.issue=a.issue,this.severity=a.severity,this.code=a.code}toEntityError(a){return this.code in j?new it({id:this.id,message:this.message,issue:this.issue,severity:this.severity,code:this.code,entity:a}):null}}class it{constructor(a){f(this,"id");f(this,"message");f(this,"issue");f(this,"severity");f(this,"code");f(this,"entity");f(this,"firstRelationship");f(this,"secondRelationship");this.id=a.id,this.message=a.message,this.issue=a.issue,this.severity=a.severity,this.code=a.code,this.entity=a.entity,this.firstRelationship=a.firstRelationship,this.secondRelationship=a.secondRelationship}clone(){return new it({id:this.id,message:this.message,issue:this.issue,severity:this.severity,code:this.code,entity:this.entity,firstRelationship:this.firstRelationship,secondRelationship:this.secondRelationship})}}function B3(r){const a=new Set;return r.filter(e=>a.has(e.id)?!1:(a.add(e.id),!0))}function de(r){const a=r.entity.errors.find(t=>t.id===r.id);return a?{new:!1,error:a}:{new:!0,error:new it(r)}}function _3(r,a){const e=new Map;return r.forEach(t=>{e.set(t.id,t)}),a.forEach(t=>{e.set(t.id,t)}),Array.from(e.values())}function He(r,a){const e=[];return a.forEach(t=>{const i=r.find(s=>s.id===t.id);i?e.push(i):e.push(t)}),e}const ca=v.union([v.string(),v.number(),v.boolean(),v.date()]),rD=v.enum([vt.CurrentDateAndTime,vt.Random,vt.Unique]),nl=v.object({type:rD,rangeStart:ca.nullable(),rangeEnd:ca.nullable()}),fa=nl.extend({type:v.literal(vt.Random),rangeStart:ca,rangeEnd:ca}),dp=nl.extend({type:v.literal(vt.Unique),rangeStart:v.null(),rangeEnd:v.null()}),nD=nl.extend({type:v.literal(vt.CurrentDateAndTime),rangeStart:v.null(),rangeEnd:v.null()}),sl=fa.extend({rangeStart:v.number().nullable(),rangeEnd:v.number().nullable()}),sD=sl.extend({rangeStart:v.number(),rangeEnd:v.null()}),aD=sl.extend({rangeStart:v.null(),rangeEnd:v.number()}),oD=sl.extend({rangeStart:v.number(),rangeEnd:v.number()}),al=fa.extend({rangeStart:v.number().nullable(),rangeEnd:v.number().nullable()}),lD=al.extend({rangeStart:v.number(),rangeEnd:v.null()}),dD=al.extend({rangeStart:v.null(),rangeEnd:v.number()}),uD=al.extend({rangeStart:v.number(),rangeEnd:v.number()}),ol=fa.extend({rangeStart:v.date().nullable(),rangeEnd:v.date().nullable()}),pD=ol.extend({rangeStart:v.date(),rangeEnd:v.null()}),cD=ol.extend({rangeStart:v.null(),rangeEnd:v.date()}),fD=ol.extend({rangeStart:v.date(),rangeEnd:v.date()}),up=fa.extend({rangeStart:v.null(),rangeEnd:v.null()}),pp=v.union([lD,dD,uD]),cp=v.union([sD,aD,oD]),fp=v.union([pD,cD,fD,nD]),yp=v.union([pp,cp,fp,dp,up]);function ya(){return v.union([v.object({type:v.literal(n.ValueDescriptor)}),v.record(v.string(),v.any())])}function yD(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.ValueDescriptor)})}function hp(){return v.object({id:v.string(),type:v.literal(n.ValueDescriptor),name:v.string(),required:v.boolean()})}function M3(){return hp().merge(v.object({version:v.number(),index:v.number()}))}function N3(){return hp().merge(v.object({}))}function L3(){return v.object({dataType:Pn(),parent:Dn()})}function U3(){return M3().merge(L3())}function ll(){return v.union([v.object({type:v.literal(n.PrimitiveEntity)}),v.record(v.string(),v.any())])}function dl(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.PrimitiveEntity)})}function ul(){return v.object({id:v.string(),type:v.literal(n.PrimitiveEntity),name:v.string(),description:v.string().nullable(),static:v.boolean(),abstract:v.boolean()})}function g3(){return ul().merge(v.object({version:v.number()}))}function j3(){return ul().merge(v.object({}))}function $3(){return v.object({properties:v.array(Rn()),methods:v.array(fi()),abstractMethods:v.array(Zi()),extends:v.array(v.union([ll(),ps()]))})}function G3(){return g3().merge($3())}function Rn(){return v.union([v.object({type:v.literal(n.Property)}),v.record(v.string(),v.any())])}function hD(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.Property)})}function mp(){return v.object({id:v.string(),type:v.literal(n.Property),name:v.string(),description:v.string().nullable(),private:v.boolean(),static:v.boolean(),required:v.boolean(),abstract:v.boolean()})}function F3(){return mp().merge(v.object({version:v.number(),index:v.number()}))}function x3(){return mp().merge(v.object({}))}function k3(){return v.object({dataType:Pn(),implements:Rn().nullable(),parent:v.union([Vn(),dl(),pl()])})}function S3(){return F3().merge(k3())}function Z3(){return v.enum([z.CRON_JOB,z.EXECUTION,z.HTTP_ENDPOINT,z.PERSISTED_ENTITY,z.RELATIONAL_DATABASE])}function ps(){return v.union([v.object({type:v.literal(n.BuiltInBaseEntity)}),v.record(v.string(),v.any())])}function pl(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.BuiltInBaseEntity)})}function vp(){return v.object({id:v.string(),version:v.number(),type:v.literal(n.BuiltInBaseEntity),name:Z3(),description:v.string().nullable(),abstract:v.boolean(),static:v.boolean()})}function q3(){return vp()}function J3(){return vp().merge(v.object({}))}function W3(){return v.object({properties:v.array(Rn()),methods:v.array(fi()),abstractMethods:v.array(Zi()),extends:v.array(v.union([ps(),ll()]))})}function z3(){return q3().merge(W3())}function Zi(){return v.union([v.object({type:v.literal(n.ActionDescriptor)}),v.record(v.string(),v.any())])}function Dn(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.ActionDescriptor)})}function cl(){return v.object({id:v.string(),type:v.literal(n.ActionDescriptor),name:v.string(),description:v.string().nullable()})}function Y3(){return cl().merge(v.object({version:v.number()}))}function H3(){return cl().merge(v.object({}))}function K3(){return v.object({inputs:v.array(ya()),outputs:v.array(ya()),parent:v.union([ii(),Vn(),pl(),dl()]).nullable()})}function mD(){return Y3().merge(K3())}function cs(){return v.union([v.object({type:v.literal(n.Loop)}),v.record(v.string(),v.any())])}function qi(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.Loop)})}function vD(){return v.object({id:v.string(),type:v.literal(n.Loop)})}function X3(){return vD().merge(v.object({version:v.number(),x:v.number(),y:v.number()}))}function Q3(){return vD().merge(v.object({declaration:v.union([v.string(),fi()])}))}function e5(){return v.object({calledBySuccess:v.array(rt()),calledByError:v.array(rt()),calledByEntry:v.array(Rt()),declaration:Zi(),inputs:v.array(Vi()),outputs:v.array(Ht()),outputsDeclarations:v.array(ya()),successCalls:v.array(Pt()),errorCalls:v.array(Pt()),error:Ht(),body:fi(),parent:v.union([fr(),ii()]),breakStatements:v.array(ms()),continueStatements:v.array(fs())})}function t5(){return X3().merge(e5())}function fs(){return v.union([v.object({type:v.literal(n.ContinueStatement)}),v.record(v.string(),v.any())])}function ys(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.ContinueStatement)})}function Tp(){return v.object({id:v.string(),type:v.literal(n.ContinueStatement)})}function i5(){return Tp().merge(v.object({version:v.number(),x:v.number(),y:v.number()}))}function r5(){return Tp().merge(v.object({}))}function n5(){return v.object({calledBySuccess:v.array(rt()),calledByError:v.array(rt()),calledByEntry:v.array(Rt()),outputs:v.array(ur()),throws:v.optional(ur()),parent:qi()})}function s5(){return i5().merge(n5())}function On(){return v.union([v.object({type:v.literal(n.ReturnStatement)}),v.record(v.string(),v.any())])}function hs(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.ReturnStatement)})}function Ip(){return v.object({id:v.string(),type:v.literal(n.ReturnStatement)})}function a5(){return Ip().merge(v.object({version:v.number(),x:v.number(),y:v.number()}))}function o5(){return Ip().merge(v.object({}))}function l5(){return v.object({calledBySuccess:v.array(rt()),calledByError:v.array(rt()),calledByEntry:v.array(Rt()),outputs:v.array(ur()),throws:v.optional(ur()),parent:fr()})}function d5(){return a5().merge(l5())}function ur(){return v.union([v.object({type:v.literal(n.ReturnDeclaration)}),v.record(v.string(),v.any())])}function TD(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.ReturnDeclaration)})}function Ep(){return v.object({id:v.string(),type:v.literal(n.ReturnDeclaration),name:v.string(),description:v.string().nullable(),isError:v.boolean()})}function u5(){return Ep().merge(v.object({version:v.number(),index:v.number()}))}function p5(){return Ep().merge(v.object({}))}function c5(){return v.object({dataType:Pn().nullable(),readsValue:Ea().nullable(),parent:v.union([hs(),Dn(),pr(),ys()])})}function f5(){return u5().merge(c5())}function ms(){return v.union([v.object({type:v.literal(n.BreakStatement)}),v.record(v.string(),v.any())])}function pr(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.BreakStatement)})}function Ap(){return v.object({id:v.string(),type:v.literal(n.BreakStatement)})}function y5(){return Ap().merge(v.object({version:v.number(),x:v.number(),y:v.number()}))}function h5(){return Ap().merge(v.object({}))}function m5(){return v.object({calledBySuccess:v.array(rt()),calledByError:v.array(rt()),calledByEntry:v.array(Rt()),outputs:v.array(ur()),throws:v.optional(ur()),parent:qi()})}function v5(){return y5().merge(m5())}function Ht(){return v.union([v.object({type:v.literal(n.OutputMap)}),v.record(v.string(),v.any())])}function bp(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.OutputMap)})}function Rp(){return v.object({id:v.string(),type:v.literal(n.OutputMap)})}function T5(){return Rp().merge(v.object({version:v.number(),index:v.number()}))}function I5(){return Rp().merge(v.object({}))}function E5(){return v.object({writesValues:v.array(cr()),declaration:v.union([ur(),Rn()]),parent:v.union([rt(),qi(),pr()])})}function A5(){return T5().merge(E5())}function vs(){return v.union([v.object({type:v.literal(n.FunctionCall)}),v.record(v.string(),v.any())])}function ha(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.FunctionCall)})}function Dp(){return v.object({id:v.string(),type:v.literal(n.FunctionCall)})}function b5(){return Dp().merge(v.object({version:v.number(),x:v.number(),y:v.number()}))}function R5(){return Dp().merge(v.object({}))}function D5(){return v.object({successCalls:v.array(Pt()),errorCalls:v.array(Pt()),calledBySuccess:v.array(rt()),calledByError:v.array(rt()),calledByEntry:v.array(Rt()),writesValues:v.array(cr()),declaration:fi(),inputs:v.array(Vi()),outputs:v.array(Ht()),error:v.optional(Ht()),parent:v.union([fr(),ii()])})}function O5(){return b5().merge(D5())}function P5(){return v.enum([yt.Equal,yt.NotEqual,yt.MoreThan,yt.MoreThanOrEqual,yt.LessThan,yt.LessThanOrEqual,yt.And,yt.Or,vi.Empty,vi.NotEmpty])}function ma(){return v.union([v.object({type:v.literal(n.Condition)}),v.record(v.string(),v.any())])}function fl(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.Condition)})}function Op(){return v.object({id:v.string(),type:v.literal(n.Condition)})}function w5(){return Op().merge(v.object({version:v.number(),x:v.number(),y:v.number()}))}function C5(){return Op().merge(v.object({}))}function V5(){return v.object({successCalls:v.array(Pt()),errorCalls:v.array(Pt()),calledBySuccess:v.array(rt()),calledByError:v.array(rt()),calledByEntry:v.array(Rt()),leftValue:Vi(),rightValue:Vi().nullable(),operator:P5(),parent:v.union([fr(),ii()])})}function B5(){return w5().merge(V5())}function va(){return v.union([v.object({type:v.literal(n.Search)}),v.record(v.string(),v.any())])}function Ta(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.Search)})}function Pp(){return v.object({id:v.string(),type:v.literal(n.Search),name:v.string(),query:v.any(),description:v.string().nullable()})}function _5(){return Pp().merge(v.object({version:v.number(),x:v.number(),y:v.number()}))}function M5(){return Pp().merge(v.object({}))}function N5(){return v.object({successCalls:v.array(Pt()),errorCalls:v.array(Pt()),calledBySuccess:v.array(rt()),calledByError:v.array(rt()),calledByEntry:v.array(Rt()),inputsDeclarations:v.array(Cn()),inputs:v.array(Vi()),outputsDeclarations:v.array(ya()),outputs:v.array(Ht()),parent:v.union([fr(),ii()]),error:Ht().nullable()})}function L5(){return _5().merge(N5())}function Ia(){return v.union([v.object({type:v.literal(n.InternalCall)}),v.record(v.string(),v.any())])}function wp(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.InternalCall)})}function Cp(){return v.object({id:v.string(),type:v.literal(n.InternalCall),index:v.number()})}function U5(){return Cp().merge(v.object({version:v.number(),index:v.number()}))}function g5(){return Cp().merge(v.object({declaration:v.union([v.string(),fi()])}))}function j5(){return v.object({successCalls:v.array(Pt()),errorCalls:v.array(Pt()),calledBySuccess:v.array(rt()),calledByError:v.array(rt()),calledByEntry:v.array(Rt()),writesValues:v.array(cr()),declaration:fi(),inputs:v.array(Vi()),outputs:v.array(Ht()),parent:_r(),error:v.optional(Ht())})}function $5(){return U5().merge(j5())}function Vi(){return v.union([v.object({type:v.literal(n.InputMap)}),v.record(v.string(),v.any())])}function yl(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.InputMap)})}function Vp(){return v.object({id:v.string(),type:v.literal(n.InputMap),name:v.string().nullable().optional(),description:v.string().nullable().optional()})}function G5(){return Vp().merge(v.object({version:v.number(),index:v.number()}))}function F5(){return Vp().merge(v.object({}))}function x5(){return v.object({defaultValue:Bp().nullable(),declaration:v.union([Cn(),Rn()]).nullable(),readsValue:Ea().nullable(),parent:v.union([rt(),yl(),qi(),pr()])})}function k5(){return G5().merge(x5())}function Ts(){return v.union([v.object({type:v.literal(n.Operation)}),v.record(v.string(),v.any())])}function Is(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.Operation)})}function hl(){return v.object({id:v.string(),type:v.literal(n.Operation)})}function S5(){return hl().merge(v.object({version:v.number(),x:v.number(),y:v.number()}))}function Z5(){return hl().merge(v.object({}))}function q5(){return hl().merge(v.object({successCalls:v.array(Pt()),errorCalls:v.array(Pt()),calledBySuccess:v.array(rt()),calledByError:v.array(rt()),calledByEntry:v.array(Rt()),writesValues:v.array(cr()),declaration:Zi(),inputs:v.array(Vi()),outputs:v.array(Ht()),error:v.array(Ht()),parent:v.union([fr(),ii()])}))}function J5(){return S5().merge(q5())}function ml(){return v.union([v.string(),v.number(),v.boolean(),v.null(),v.date()])}function ID(){return v.record(v.string(),ml())}function W5(){return v.array(v.union([ml(),ID()]))}function ED(){return v.union([ml(),ID(),W5()])}function AD(){return v.union([ml(),ED()])}function bD(){return v.enum([L.String,L.Number,L.Boolean,L.Null,L.Date,L.KeyValue,L.Enum,L.File,L.UUID,L.EntityTemplate,L.ActionDescriptor])}function RD(){return v.union([Vn(),Is(),Aa()])}function z5(){return v.object({id:v.string(),name:bD(),type:v.literal(n.LiteralValue),value:AD(),autogeneration:yp.nullable()})}function Y5(){return z5().merge(v.object({}))}function Bi(){return v.object({id:v.string(),version:v.number(),name:bD(),type:v.literal(n.LiteralValue),value:AD(),valueAsTypeList:v.array(RD()).nullable(),valueAsTypeSingle:RD().nullable(),autogeneration:yp.nullable(),parent:v.union([_p(),yl()])})}function H5(){return Bi().extend({name:v.literal(L.String),value:v.string(),autogeneration:pp.nullable()})}function K5(){return Bi().extend({name:v.literal(L.Number),value:v.number(),autogeneration:cp.nullable()})}function X5(){return Bi().extend({name:v.literal(L.Boolean),value:v.boolean(),autogeneration:up.nullable()})}function Q5(){return Bi().extend({name:v.literal(L.Null),value:v.null(),autogeneration:v.null()})}function eS(){return Bi().extend({name:v.literal(L.Date),value:v.date(),autogeneration:fp.nullable()})}function tS(){return Bi().extend({name:v.literal(L.KeyValue),value:ED(),autogeneration:v.null()})}function iS(){return Bi().extend({name:v.literal(L.Enum),value:v.string(),autogeneration:v.null()})}function rS(){return Bi().extend({name:v.literal(L.File),value:v.string(),autogeneration:v.null()})}function nS(){return Bi().extend({name:v.literal(L.UUID),value:v.string(),autogeneration:dp.nullable()})}function sS(){return Bi().extend({name:v.literal(L.EntityTemplate),value:Vn(),autogeneration:v.null()})}function aS(){return Bi().extend({name:v.literal(L.ActionDescriptor),value:Aa(),autogeneration:v.null()})}function Bp(){return v.union([H5(),K5(),X5(),Q5(),eS(),tS(),iS(),rS(),nS(),sS(),aS()])}function Pn(){return v.union([v.object({type:v.literal(n.DataType)}),v.record(v.string(),v.any())])}function _p(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.DataType)})}function Mp(){return v.object({id:v.string(),type:v.literal(n.DataType),isNullable:v.boolean(),isList:v.boolean(),constant:v.boolean(),asType:v.boolean(),options:v.array(v.string()).optional()})}function oS(){return Mp().merge(v.object({version:v.number()}))}function lS(){return Mp().merge(v.object({}))}function dS(){return v.object({defaultValue:Bp().nullable(),entity:v.union([Es(),ps(),ll(),Zi()]).nullable(),parent:v.union([hD(),PD(),yD()])})}function uS(){return oS().merge(dS())}function Np(){return v.union([v.object({type:v.literal(n.VariableDeclaration)}),v.record(v.string(),v.any())])}function pS(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.VariableDeclaration)})}function Lp(){return v.object({id:v.string(),type:v.literal(n.VariableDeclaration),name:v.string(),description:v.string().nullable()})}function cS(){return Lp().merge(v.object({version:v.number(),x:v.number(),y:v.number()}))}function fS(){return Lp().merge(v.object({}))}function yS(){return v.object({dataType:Pn().nullable(),readsValue:Ea().nullable(),writesValues:v.array(cr()),inputs:v.array(Vi()),outputs:v.array(Ht()),successCalls:v.array(Pt()),errorCalls:v.array(Pt()),internalCalls:v.array(Ia()),calledBySuccess:v.array(rt()),calledByError:v.array(rt()),calledByEntry:v.array(Rt()),parent:v.union([fr(),ii()])})}function hS(){return cS().merge(yS())}function DD(){return v.union([v.object({type:v.literal(n.VariableInstance)}),v.record(v.string(),v.any())])}function mS(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.VariableInstance)})}function Up(){return v.object({id:v.string(),type:v.literal(n.VariableInstance)})}function vS(){return Up().merge(v.object({version:v.number(),x:v.number(),y:v.number()}))}function TS(){return Up().merge(v.object({}))}function IS(){return v.object({declaration:Np(),dataType:Pn().nullable(),readsValue:Ea().nullable(),writesValues:v.array(cr()),inputs:v.array(Vi()),outputs:v.array(Ht()),successCalls:v.array(Pt()),errorCalls:v.array(Pt()),internalCalls:v.array(Ia()),calledBySuccess:v.array(rt()),calledByError:v.array(rt()),calledByEntry:v.array(Rt()),parent:v.union([fr(),ii()])})}function ES(){return vS().merge(IS())}function gp(){return v.union([v.object({type:v.literal(n.InstalledProject)}),v.record(v.string(),v.any())])}function vl(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.InstalledProject)})}function AS(){return v.object({id:v.string(),type:v.literal(n.InstalledProject)})}function bS(){return v.object({version:v.number(),x:v.number(),y:v.number()})}function RS(){return v.object({})}function DS(){return v.object({implements:ii(),description:v.string().nullable(),functions:v.array(fi()),events:v.array(jp()),parent:ii()})}function OS(){return bS().merge(DS())}function jp(){return v.union([v.object({type:v.literal(n.GlobalEvent)}),v.record(v.string(),v.any())])}function PS(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.GlobalEvent)})}function Tl(){return v.object({id:v.string(),type:v.literal(n.GlobalEvent),name:v.string(),collapsed:v.boolean()})}function wS(){return Tl().merge(v.object({version:v.number(),x:v.number(),y:v.number()}))}function CS(){return Tl().merge(v.object({}))}function VS(){return Tl().merge(v.object({returnStatements:v.array(On()),implements:v.array(mD()),inputs:v.array(Cn()),calls:v.array(Pt()),parent:v.union([ii(),vl()])}))}function BS(){return wS().merge(VS())}function wn(){return v.union([Np(),DD()])}function _r(){return v.union([pS(),mS()])}function cr(){return v.union([wn(),Vi(),ur()])}function OD(){return v.union([_r(),yl(),TD()])}function Ea(){return v.union([wn(),Cn(),Ht(),Ts(),Ia(),vs()])}function _S(){return v.union([_r(),$p(),bp(),Is(),wp(),ha()])}function MS(){return v.union([Cn(),Ht(),cr()])}function PD(){return v.union([$p(),bp(),OD()])}function Il(){return jp()}function El(){return PS()}function Al(){return v.union([Ts(),vs(),ma(),va(),wn(),Ia(),cs()])}function rt(){return v.union([Is(),ha(),fl(),Ta(),_r(),wp(),qi()])}function bl(){return v.union([Ts(),vs(),ma(),va(),wn(),cs()])}function Rl(){return v.union([Is(),ha(),fl(),Ta(),_r(),qi()])}function wD(){return v.union([Al(),On(),ms(),fs()])}function Pt(){return v.union([rt(),hs(),pr(),ys()])}function CD(){return v.union([bl(),On(),ms(),fs()])}function VD(){return v.union([Rl(),hs(),pr(),ys()])}function Mr(){return v.union([fi(),Il()])}function Rt(){return v.union([Aa(),El()])}function NS(){return v.union([Al(),Mr()])}function LS(){return v.union([rt(),Rt()])}function US(){return v.union([bl(),Mr()])}function gS(){return v.union([Rl(),Rt()])}function jS(){return v.union([wD(),Mr()])}function $S(){return v.union([Pt(),Rt()])}function GS(){return v.union([CD(),Mr()])}function FS(){return v.union([VD(),Rt()])}function xS(){return v.union([Mr(),cs()])}function fr(){return v.union([Rt(),qi()])}function kS(){return v.union([Al(),Mr()])}function SS(){return v.union([rt(),Rt()])}function ZS(){return v.union([bl(),Mr()])}function qS(){return v.union([Rl(),Rt()])}function JS(){return v.union([On(),ms(),fs()])}function WS(){return v.union([hs(),pr(),ys()])}function zS(){return v.union([ps(),aZ(),gp(),Es(),fi(),Il(),wn(),Vi(),Ht(),ma(),Ts(),vs(),ur(),Cn(),ll(),Pn(),Rn(),Zi(),On(),fs(),ms(),cs(),va(),Zi(),Zi(),ya(),Ia()])}function YS(){return v.union([pl(),ii(),vl(),Vn(),Aa(),El(),_r(),yl(),bp(),fl(),Is(),ha(),TD(),$p(),dl(),_p(),hD(),Dn(),hs(),ys(),pr(),qi(),Ta(),Dn(),Dn(),yD(),wp()])}function HS(){return v.union([gp(),Es(),fi(),Il(),wn(),ma(),Ts(),vs(),On(),fs(),ms(),cs(),va()])}function KS(){return v.union([vl(),Vn(),Aa(),El(),_r(),fl(),Is(),ha(),hs(),ys(),pr(),qi(),Ta()])}function Cn(){return v.union([v.object({type:v.literal(n.ArgumentDeclaration)}),v.record(v.string(),v.any())])}function $p(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.ArgumentDeclaration)})}function Gp(){return v.object({id:v.string(),type:v.literal(n.ArgumentDeclaration)})}function XS(){return Gp().merge(v.object({version:v.number(),x:v.number(),y:v.number()}))}function QS(){return Gp().merge(v.object({}))}function eZ(){return v.object({dataType:Pn().nullable(),writesValues:v.array(cr()),parent:v.union([Rt(),Dn(),Dn(),Ta(),pr()])})}function tZ(){return XS().merge(eZ())}function fi(){return v.union([v.object({type:v.literal(n.FunctionDeclaration)}),v.record(v.string(),v.any())])}function Aa(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.FunctionDeclaration)})}function Fp(){return v.object({id:v.string(),type:v.literal(n.FunctionDeclaration),name:v.string(),description:v.string().nullable()})}function iZ(){return Fp().merge(v.object({version:v.number(),x:v.number(),y:v.number(),index:v.number().nullable()}))}function rZ(){return Fp()}function nZ(){return v.object({inputs:v.array(Cn()),implements:Zi().nullable(),returnStatements:v.array(On()),parent:v.union([ii(),vl(),Vn(),qi(),pl(),dl()])})}function sZ(){return iZ().merge(nZ())}function aZ(){return v.union([v.object({type:v.literal(n.Project)}),v.record(v.string(),v.any())])}function ii(){return v.object({entityType:v.literal(n.Project),entityId:v.string(),id:v.string(),type:v.literal(n.GenericReference)})}function xp(){return v.object({id:v.string(),type:v.literal(n.Project),name:v.string(),description:v.string().nullable()})}function oZ(){return xp().merge(v.object({version:v.number()}))}function lZ(){return xp()}function dZ(){return v.object({entities:v.array(Es()),functions:v.array(fi()),events:v.array(jp()),projects:v.array(gp()),variableDeclarations:v.array(Np()),variableInstances:v.array(DD()),conditions:v.array(ma()),operations:v.array(Ts()),functionCalls:v.array(vs()),loops:v.array(cs()),searches:v.array(va())})}function uZ(){return oZ().merge(dZ())}function Es(){return v.union([v.object({type:v.literal(n.DefinitionEntity)}),v.record(v.string(),v.any())])}function Vn(){return v.object({id:v.string(),type:v.literal(n.GenericReference),entityId:v.string(),entityType:v.literal(n.DefinitionEntity)})}function kp(){return v.object({id:v.string(),type:v.literal(n.DefinitionEntity),name:v.string(),description:v.string().nullable(),static:v.boolean(),abstract:v.boolean()})}function pZ(){return kp().merge(v.object({version:v.number(),x:v.number(),y:v.number()}))}function cZ(){return kp().merge(v.object({}))}function fZ(){return v.union([ii(),_p()])}function yZ(){return v.object({properties:v.array(Rn()),methods:v.array(fi()),abstractMethods:v.array(Zi()),extends:v.array(v.union([Es(),ps()])),implements:v.array(v.union([Es(),ps()])),parent:fZ()})}function hZ(){return pZ().merge(yZ())}function mZ(r){return r instanceof Error&&r.name==="ZodError"&&"issues"in r&&Array.isArray(r.issues)}var vZ=class extends Error{constructor(a,e){super(a,e);f(this,"name");f(this,"details");this.name="ZodValidationError",this.details=TZ(e)}toString(){return this.message}};function TZ(r){if(r){const a=r.cause;if(mZ(a))return a.issues}return[]}function IZ(r){return r.length!==0}var EZ=/[$_\p{ID_Start}][$\u200c\u200d\p{ID_Continue}]*/u;function AZ(r){return r.length===1?r[0].toString():r.reduce((a,e)=>{if(typeof e=="number")return a+"["+e.toString()+"]";if(e.includes('"'))return a+'["'+bZ(e)+'"]';if(!EZ.test(e))return a+'["'+e+'"]';const t=a.length===0?"":".";return a+t+e},"")}function bZ(r){return r.replace(/"/g,'\\"')}var RZ="; ",DZ=99,BD="Validation error",OZ=": ",PZ=", or ";function wZ(r={}){const{issueSeparator:a=RZ,unionSeparator:e=PZ,prefixSeparator:t=OZ,prefix:i=BD,includePath:s=!0,maxIssuesInMessage:l=DZ}=r;return o=>{const d=o.slice(0,l).map(u=>Dl({issue:u,issueSeparator:a,unionSeparator:e,includePath:s})).join(a);return CZ(d,i,t)}}function Dl(r){const{issue:a,issueSeparator:e,unionSeparator:t,includePath:i}=r;if(a.code===S.invalid_union)return a.unionErrors.reduce((s,l)=>{const o=l.issues.map(d=>Dl({issue:d,issueSeparator:e,unionSeparator:t,includePath:i})).join(e);return s.includes(o)||s.push(o),s},[]).join(t);if(a.code===S.invalid_arguments)return[a.message,...a.argumentsError.issues.map(s=>Dl({issue:s,issueSeparator:e,unionSeparator:t,includePath:i}))].join(e);if(a.code===S.invalid_return_type)return[a.message,...a.returnTypeError.issues.map(s=>Dl({issue:s,issueSeparator:e,unionSeparator:t,includePath:i}))].join(e);if(i&&IZ(a.path)){if(a.path.length===1){const s=a.path[0];if(typeof s=="number")return`${a.message} at index ${s}`}return`${a.message} at "${AZ(a.path)}"`}return a.message}function CZ(r,a,e){return a!==null?r.length>0?[a,r].join(e):a:r.length>0?r:BD}function VZ(r,a={}){const t=BZ(a)([r]);return new vZ(t,{cause:new ti([r])})}function BZ(r){return"messageBuilder"in r?r.messageBuilder:wZ(r)}var _D="1.13.7",MD=typeof self=="object"&&self.self===self&&self||typeof global=="object"&&global.global===global&&global||Function("return this")()||{},Ol=Array.prototype,Sp=Object.prototype,ND=typeof Symbol<"u"?Symbol.prototype:null,_Z=Ol.push,ba=Ol.slice,Ra=Sp.toString,MZ=Sp.hasOwnProperty,LD=typeof ArrayBuffer<"u",NZ=typeof DataView<"u",LZ=Array.isArray,UD=Object.keys,gD=Object.create,jD=LD&&ArrayBuffer.isView,UZ=isNaN,gZ=isFinite,$D=!{toString:null}.propertyIsEnumerable("toString"),GD=["valueOf","isPrototypeOf","toString","propertyIsEnumerable","hasOwnProperty","toLocaleString"],jZ=Math.pow(2,53)-1;function ri(r,a){return a=a==null?r.length-1:+a,function(){for(var e=Math.max(arguments.length-a,0),t=Array(e),i=0;i<e;i++)t[i]=arguments[i+a];switch(a){case 0:return r.call(this,t);case 1:return r.call(this,arguments[0],t);case 2:return r.call(this,arguments[0],arguments[1],t)}var s=Array(a+1);for(i=0;i<a;i++)s[i]=arguments[i];return s[a]=t,r.apply(this,s)}}function Nr(r){var a=typeof r;return a==="function"||a==="object"&&!!r}function $Z(r){return r===null}function FD(r){return r===void 0}function xD(r){return r===!0||r===!1||Ra.call(r)==="[object Boolean]"}function GZ(r){return!!(r&&r.nodeType===1)}function Ft(r){var a="[object "+r+"]";return function(e){return Ra.call(e)===a}}const Zp=Ft("String"),kD=Ft("Number"),FZ=Ft("Date"),xZ=Ft("RegExp"),kZ=Ft("Error"),SD=Ft("Symbol"),ZD=Ft("ArrayBuffer");var qD=Ft("Function"),SZ=MD.document&&MD.document.childNodes;typeof/./!="function"&&typeof Int8Array!="object"&&typeof SZ!="function"&&(qD=function(r){return typeof r=="function"||!1});const Kt=qD,JD=Ft("Object");var WD=NZ&&(!/\[native code\]/.test(String(DataView))||JD(new DataView(new ArrayBuffer(8)))),qp=typeof Map<"u"&&JD(new Map),ZZ=Ft("DataView");function qZ(r){return r!=null&&Kt(r.getInt8)&&ZD(r.buffer)}const Pl=WD?qZ:ZZ,Bn=LZ||Ft("Array");function Lr(r,a){return r!=null&&MZ.call(r,a)}var Jp=Ft("Arguments");(function(){Jp(arguments)||(Jp=function(r){return Lr(r,"callee")})})();const Wp=Jp;function JZ(r){return!SD(r)&&gZ(r)&&!isNaN(parseFloat(r))}function zD(r){return kD(r)&&UZ(r)}function YD(r){return function(){return r}}function HD(r){return function(a){var e=r(a);return typeof e=="number"&&e>=0&&e<=jZ}}function KD(r){return function(a){return a==null?void 0:a[r]}}const wl=KD("byteLength"),WZ=HD(wl);var zZ=/\[object ((I|Ui)nt(8|16|32)|Float(32|64)|Uint8Clamped|Big(I|Ui)nt64)Array\]/;function YZ(r){return jD?jD(r)&&!Pl(r):WZ(r)&&zZ.test(Ra.call(r))}const XD=LD?YZ:YD(!1),ni=KD("length");function HZ(r){for(var a={},e=r.length,t=0;t<e;++t)a[r[t]]=!0;return{contains:function(i){return a[i]===!0},push:function(i){return a[i]=!0,r.push(i)}}}function QD(r,a){a=HZ(a);var e=GD.length,t=r.constructor,i=Kt(t)&&t.prototype||Sp,s="constructor";for(Lr(r,s)&&!a.contains(s)&&a.push(s);e--;)s=GD[e],s in r&&r[s]!==i[s]&&!a.contains(s)&&a.push(s)}function Vt(r){if(!Nr(r))return[];if(UD)return UD(r);var a=[];for(var e in r)Lr(r,e)&&a.push(e);return $D&&QD(r,a),a}function Da(r){if(r==null)return!0;var a=ni(r);return typeof a=="number"&&(Bn(r)||Zp(r)||Wp(r))?a===0:ni(Vt(r))===0}function eO(r,a){var e=Vt(a),t=e.length;if(r==null)return!t;for(var i=Object(r),s=0;s<t;s++){var l=e[s];if(a[l]!==i[l]||!(l in i))return!1}return!0}function Ke(r){if(r instanceof Ke)return r;if(!(this instanceof Ke))return new Ke(r);this._wrapped=r}Ke.VERSION=_D,Ke.prototype.value=function(){return this._wrapped},Ke.prototype.valueOf=Ke.prototype.toJSON=Ke.prototype.value,Ke.prototype.toString=function(){return String(this._wrapped)};function tO(r){return new Uint8Array(r.buffer||r,r.byteOffset||0,wl(r))}var iO="[object DataView]";function zp(r,a,e,t){if(r===a)return r!==0||1/r===1/a;if(r==null||a==null)return!1;if(r!==r)return a!==a;var i=typeof r;return i!=="function"&&i!=="object"&&typeof a!="object"?!1:rO(r,a,e,t)}function rO(r,a,e,t){r instanceof Ke&&(r=r._wrapped),a instanceof Ke&&(a=a._wrapped);var i=Ra.call(r);if(i!==Ra.call(a))return!1;if(WD&&i=="[object Object]"&&Pl(r)){if(!Pl(a))return!1;i=iO}switch(i){case"[object RegExp]":case"[object String]":return""+r==""+a;case"[object Number]":return+r!=+r?+a!=+a:+r==0?1/+r===1/a:+r==+a;case"[object Date]":case"[object Boolean]":return+r==+a;case"[object Symbol]":return ND.valueOf.call(r)===ND.valueOf.call(a);case"[object ArrayBuffer]":case iO:return rO(tO(r),tO(a),e,t)}var s=i==="[object Array]";if(!s&&XD(r)){var l=wl(r);if(l!==wl(a))return!1;if(r.buffer===a.buffer&&r.byteOffset===a.byteOffset)return!0;s=!0}if(!s){if(typeof r!="object"||typeof a!="object")return!1;var o=r.constructor,d=a.constructor;if(o!==d&&!(Kt(o)&&o instanceof o&&Kt(d)&&d instanceof d)&&"constructor"in r&&"constructor"in a)return!1}e=e||[],t=t||[];for(var u=e.length;u--;)if(e[u]===r)return t[u]===a;if(e.push(r),t.push(a),s){if(u=r.length,u!==a.length)return!1;for(;u--;)if(!zp(r[u],a[u],e,t))return!1}else{var y=Vt(r),c;if(u=y.length,Vt(a).length!==u)return!1;for(;u--;)if(c=y[u],!(Lr(a,c)&&zp(r[c],a[c],e,t)))return!1}return e.pop(),t.pop(),!0}function KZ(r,a){return zp(r,a)}function Oa(r){if(!Nr(r))return[];var a=[];for(var e in r)a.push(e);return $D&&QD(r,a),a}function Yp(r){var a=ni(r);return function(e){if(e==null)return!1;var t=Oa(e);if(ni(t))return!1;for(var i=0;i<a;i++)if(!Kt(e[r[i]]))return!1;return r!==aO||!Kt(e[Hp])}}var Hp="forEach",nO="has",Kp=["clear","delete"],sO=["get",nO,"set"],XZ=Kp.concat(Hp,sO),aO=Kp.concat(sO),QZ=["add"].concat(Kp,Hp,nO);const eq=qp?Yp(XZ):Ft("Map"),tq=qp?Yp(aO):Ft("WeakMap"),iq=qp?Yp(QZ):Ft("Set"),rq=Ft("WeakSet");function As(r){for(var a=Vt(r),e=a.length,t=Array(e),i=0;i<e;i++)t[i]=r[a[i]];return t}function nq(r){for(var a=Vt(r),e=a.length,t=Array(e),i=0;i<e;i++)t[i]=[a[i],r[a[i]]];return t}function oO(r){for(var a={},e=Vt(r),t=0,i=e.length;t<i;t++)a[r[e[t]]]=e[t];return a}function Xp(r){var a=[];for(var e in r)Kt(r[e])&&a.push(e);return a.sort()}function Qp(r,a){return function(e){var t=arguments.length;if(a&&(e=Object(e)),t<2||e==null)return e;for(var i=1;i<t;i++)for(var s=arguments[i],l=r(s),o=l.length,d=0;d<o;d++){var u=l[d];(!a||e[u]===void 0)&&(e[u]=s[u])}return e}}const lO=Qp(Oa),Cl=Qp(Vt),dO=Qp(Oa,!0);function sq(){return function(){}}function uO(r){if(!Nr(r))return{};if(gD)return gD(r);var a=sq();a.prototype=r;var e=new a;return a.prototype=null,e}function aq(r,a){var e=uO(r);return a&&Cl(e,a),e}function oq(r){return Nr(r)?Bn(r)?r.slice():lO({},r):r}function lq(r,a){return a(r),r}function pO(r){return Bn(r)?r:[r]}Ke.toPath=pO;function Pa(r){return Ke.toPath(r)}function ec(r,a){for(var e=a.length,t=0;t<e;t++){if(r==null)return;r=r[a[t]]}return e?r:void 0}function cO(r,a,e){var t=ec(r,Pa(a));return FD(t)?e:t}function dq(r,a){a=Pa(a);for(var e=a.length,t=0;t<e;t++){var i=a[t];if(!Lr(r,i))return!1;r=r[i]}return!!e}function tc(r){return r}function wa(r){return r=Cl({},r),function(a){return eO(a,r)}}function ic(r){return r=Pa(r),function(a){return ec(a,r)}}function Ca(r,a,e){if(a===void 0)return r;switch(e??3){case 1:return function(t){return r.call(a,t)};case 3:return function(t,i,s){return r.call(a,t,i,s)};case 4:return function(t,i,s,l){return r.call(a,t,i,s,l)}}return function(){return r.apply(a,arguments)}}function fO(r,a,e){return r==null?tc:Kt(r)?Ca(r,a,e):Nr(r)&&!Bn(r)?wa(r):ic(r)}function rc(r,a){return fO(r,a,1/0)}Ke.iteratee=rc;function si(r,a,e){return Ke.iteratee!==rc?Ke.iteratee(r,a):fO(r,a,e)}function uq(r,a,e){a=si(a,e);for(var t=Vt(r),i=t.length,s={},l=0;l<i;l++){var o=t[l];s[o]=a(r[o],o,r)}return s}function yO(){}function pq(r){return r==null?yO:function(a){return cO(r,a)}}function cq(r,a,e){var t=Array(Math.max(0,r));a=Ca(a,e,1);for(var i=0;i<r;i++)t[i]=a(i);return t}function nc(r,a){return a==null&&(a=r,r=0),r+Math.floor(Math.random()*(a-r+1))}const Va=Date.now||function(){return new Date().getTime()};function hO(r){var a=function(s){return r[s]},e="(?:"+Vt(r).join("|")+")",t=RegExp(e),i=RegExp(e,"g");return function(s){return s=s==null?"":""+s,t.test(s)?s.replace(i,a):s}}const mO={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;","`":"&#x60;"},fq=hO(mO),yq=oO(mO),hq=hO(yq),mq=Ke.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var sc=/(.)^/,vq={"'":"'","\\":"\\","\r":"r","\n":"n","\u2028":"u2028","\u2029":"u2029"},Tq=/\\|'|\r|\n|\u2028|\u2029/g;function Iq(r){return"\\"+vq[r]}var Eq=/^\s*(\w|\$)+\s*$/;function Aq(r,a,e){!a&&e&&(a=e),a=dO({},a,Ke.templateSettings);var t=RegExp([(a.escape||sc).source,(a.interpolate||sc).source,(a.evaluate||sc).source].join("|")+"|$","g"),i=0,s="__p+='";r.replace(t,function(u,y,c,I,E){return s+=r.slice(i,E).replace(Tq,Iq),i=E+u.length,y?s+=`'+
25
25
  ((__t=(`+y+`))==null?'':_.escape(__t))+
26
26
  '`:c?s+=`'+
27
27
  ((__t=(`+c+`))==null?'':__t)+
28
28
  '`:I&&(s+=`';
29
29
  `+I+`
30
30
  __p+='`),u}),s+=`';
31
- `;var l=a.variable;if(l){if(!E7.test(l))throw new Error("variable is not a bare identifier: "+l)}else s=`with(obj||{}){
31
+ `;var l=a.variable;if(l){if(!Eq.test(l))throw new Error("variable is not a bare identifier: "+l)}else s=`with(obj||{}){
32
32
  `+s+`}
33
33
  `,l="obj";s=`var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};
34
34
  `+s+`return __p;
35
35
  `;var o;try{o=new Function(l,"_",s)}catch(u){throw u.source=s,u}var d=function(u){return o.call(this,u,Ke)};return d.source="function("+l+`){
36
- `+s+"}",d}function b7(r,a,e){a=Pa(a);var t=a.length;if(!t)return Kt(e)?e.call(r):e;for(var i=0;i<t;i++){var s=r==null?void 0:r[a[i]];s===void 0&&(s=e,i=t),r=Kt(s)?s.call(r):s}return r}var R7=0;function D7(r){var a=++R7+"";return r?r+a:a}function O7(r){var a=Ke(r);return a._chain=!0,a}function vO(r,a,e,t,i){if(!(t instanceof a))return r.apply(e,i);var s=uO(r.prototype),l=r.apply(s,i);return Nr(l)?l:s}var bs=ri(function(r,a){var e=bs.placeholder,t=function(){for(var i=0,s=a.length,l=Array(s),o=0;o<s;o++)l[o]=a[o]===e?arguments[i++]:a[o];for(;i<arguments.length;)l.push(arguments[i++]);return vO(r,t,this,this,l)};return t});bs.placeholder=Ke;const TO=ri(function(r,a,e){if(!Kt(r))throw new TypeError("Bind must be called on a function");var t=ri(function(i){return vO(r,t,a,this,e.concat(i))});return t}),yi=HD(ni);function _n(r,a,e,t){if(t=t||[],!a&&a!==0)a=1/0;else if(a<=0)return t.concat(r);for(var i=t.length,s=0,l=ni(r);s<l;s++){var o=r[s];if(yi(o)&&(Bn(o)||Wp(o)))if(a>1)_n(o,a-1,e,t),i=t.length;else for(var d=0,u=o.length;d<u;)t[i++]=o[d++];else e||(t[i++]=o)}return t}const P7=ri(function(r,a){a=_n(a,!1,!1);var e=a.length;if(e<1)throw new Error("bindAll must be passed function names");for(;e--;){var t=a[e];r[t]=TO(r[t],r)}return r});function w7(r,a){var e=function(t){var i=e.cache,s=""+(a?a.apply(this,arguments):t);return Lr(i,s)||(i[s]=r.apply(this,arguments)),i[s]};return e.cache={},e}const IO=ri(function(r,a,e){return setTimeout(function(){return r.apply(null,e)},a)}),C7=bs(IO,Ke,1);function V7(r,a,e){var t,i,s,l,o=0;e||(e={});var d=function(){o=e.leading===!1?0:Va(),t=null,l=r.apply(i,s),t||(i=s=null)},u=function(){var y=Va();!o&&e.leading===!1&&(o=y);var c=a-(y-o);return i=this,s=arguments,c<=0||c>a?(t&&(clearTimeout(t),t=null),o=y,l=r.apply(i,s),t||(i=s=null)):!t&&e.trailing!==!1&&(t=setTimeout(d,c)),l};return u.cancel=function(){clearTimeout(t),o=0,t=i=s=null},u}function B7(r,a,e){var t,i,s,l,o,d=function(){var y=Va()-i;a>y?t=setTimeout(d,a-y):(t=null,e||(l=r.apply(o,s)),t||(s=o=null))},u=ri(function(y){return o=this,s=y,i=Va(),t||(t=setTimeout(d,a),e&&(l=r.apply(o,s))),l});return u.cancel=function(){clearTimeout(t),t=s=o=null},u}function _7(r,a){return bs(a,r)}function ac(r){return function(){return!r.apply(this,arguments)}}function M7(){var r=arguments,a=r.length-1;return function(){for(var e=a,t=r[a].apply(this,arguments);e--;)t=r[e].call(this,t);return t}}function N7(r,a){return function(){if(--r<1)return a.apply(this,arguments)}}function EO(r,a){var e;return function(){return--r>0&&(e=a.apply(this,arguments)),r<=1&&(a=null),e}}const L7=bs(EO,2);function AO(r,a,e){a=si(a,e);for(var t=Vt(r),i,s=0,l=t.length;s<l;s++)if(i=t[s],a(r[i],i,r))return i}function bO(r){return function(a,e,t){e=si(e,t);for(var i=ni(a),s=r>0?0:i-1;s>=0&&s<i;s+=r)if(e(a[s],s,a))return s;return-1}}const oc=bO(1),RO=bO(-1);function DO(r,a,e,t){e=si(e,t,1);for(var i=e(a),s=0,l=ni(r);s<l;){var o=Math.floor((s+l)/2);e(r[o])<i?s=o+1:l=o}return s}function OO(r,a,e){return function(t,i,s){var l=0,o=ni(t);if(typeof s=="number")r>0?l=s>=0?s:Math.max(s+o,l):o=s>=0?Math.min(s+1,o):s+o+1;else if(e&&s&&o)return s=e(t,i),t[s]===i?s:-1;if(i!==i)return s=a(ba.call(t,l,o),zD),s>=0?s+l:-1;for(s=r>0?l:o-1;s>=0&&s<o;s+=r)if(t[s]===i)return s;return-1}}const PO=OO(1,oc,DO),U7=OO(-1,RO);function lc(r,a,e){var t=yi(r)?oc:AO,i=t(r,a,e);if(i!==void 0&&i!==-1)return r[i]}function g7(r,a){return lc(r,wa(a))}function yr(r,a,e){a=Ca(a,e);var t,i;if(yi(r))for(t=0,i=r.length;t<i;t++)a(r[t],t,r);else{var s=Vt(r);for(t=0,i=s.length;t<i;t++)a(r[s[t]],s[t],r)}return r}function Mn(r,a,e){a=si(a,e);for(var t=!yi(r)&&Vt(r),i=(t||r).length,s=Array(i),l=0;l<i;l++){var o=t?t[l]:l;s[l]=a(r[o],o,r)}return s}function wO(r){var a=function(e,t,i,s){var l=!yi(e)&&Vt(e),o=(l||e).length,d=r>0?0:o-1;for(s||(i=e[l?l[d]:d],d+=r);d>=0&&d<o;d+=r){var u=l?l[d]:d;i=t(i,e[u],u,e)}return i};return function(e,t,i,s){var l=arguments.length>=3;return a(e,Ca(t,s,4),i,l)}}const dc=wO(1),CO=wO(-1);function Rs(r,a,e){var t=[];return a=si(a,e),yr(r,function(i,s,l){a(i,s,l)&&t.push(i)}),t}function j7(r,a,e){return Rs(r,ac(si(a)),e)}function VO(r,a,e){a=si(a,e);for(var t=!yi(r)&&Vt(r),i=(t||r).length,s=0;s<i;s++){var l=t?t[s]:s;if(!a(r[l],l,r))return!1}return!0}function BO(r,a,e){a=si(a,e);for(var t=!yi(r)&&Vt(r),i=(t||r).length,s=0;s<i;s++){var l=t?t[s]:s;if(a(r[l],l,r))return!0}return!1}function hr(r,a,e,t){return yi(r)||(r=As(r)),(typeof e!="number"||t)&&(e=0),PO(r,a,e)>=0}const $7=ri(function(r,a,e){var t,i;return Kt(a)?i=a:(a=Pa(a),t=a.slice(0,-1),a=a[a.length-1]),Mn(r,function(s){var l=i;if(!l){if(t&&t.length&&(s=ec(s,t)),s==null)return;l=s[a]}return l==null?l:l.apply(s,e)})});function uc(r,a){return Mn(r,ic(a))}function G7(r,a){return Rs(r,wa(a))}function _O(r,a,e){var t=-1/0,i=-1/0,s,l;if(a==null||typeof a=="number"&&typeof r[0]!="object"&&r!=null){r=yi(r)?r:As(r);for(var o=0,d=r.length;o<d;o++)s=r[o],s!=null&&s>t&&(t=s)}else a=si(a,e),yr(r,function(u,y,c){l=a(u,y,c),(l>i||l===-1/0&&t===-1/0)&&(t=u,i=l)});return t}function F7(r,a,e){var t=1/0,i=1/0,s,l;if(a==null||typeof a=="number"&&typeof r[0]!="object"&&r!=null){r=yi(r)?r:As(r);for(var o=0,d=r.length;o<d;o++)s=r[o],s!=null&&s<t&&(t=s)}else a=si(a,e),yr(r,function(u,y,c){l=a(u,y,c),(l<i||l===1/0&&t===1/0)&&(t=u,i=l)});return t}var x7=/[^\ud800-\udfff]|[\ud800-\udbff][\udc00-\udfff]|[\ud800-\udfff]/g;function MO(r){return r?Bn(r)?ba.call(r):Zp(r)?r.match(x7):yi(r)?Mn(r,tc):As(r):[]}function NO(r,a,e){if(a==null||e)return yi(r)||(r=As(r)),r[nc(r.length-1)];var t=MO(r),i=ni(t);a=Math.max(Math.min(a,i),0);for(var s=i-1,l=0;l<a;l++){var o=nc(l,s),d=t[l];t[l]=t[o],t[o]=d}return t.slice(0,a)}function k7(r){return NO(r,1/0)}function S7(r,a,e){var t=0;return a=si(a,e),uc(Mn(r,function(i,s,l){return{value:i,index:t++,criteria:a(i,s,l)}}).sort(function(i,s){var l=i.criteria,o=s.criteria;if(l!==o){if(l>o||l===void 0)return 1;if(l<o||o===void 0)return-1}return i.index-s.index}),"value")}function Vl(r,a){return function(e,t,i){var s=a?[[],[]]:{};return t=si(t,i),yr(e,function(l,o){var d=t(l,o,e);r(s,l,d)}),s}}const Z7=Vl(function(r,a,e){Lr(r,e)?r[e].push(a):r[e]=[a]}),q7=Vl(function(r,a,e){r[e]=a}),J7=Vl(function(r,a,e){Lr(r,e)?r[e]++:r[e]=1}),W7=Vl(function(r,a,e){r[e?0:1].push(a)},!0);function z7(r){return r==null?0:yi(r)?r.length:Vt(r).length}function Y7(r,a,e){return a in e}const LO=ri(function(r,a){var e={},t=a[0];if(r==null)return e;Kt(t)?(a.length>1&&(t=Ca(t,a[1])),a=Oa(r)):(t=Y7,a=_n(a,!1,!1),r=Object(r));for(var i=0,s=a.length;i<s;i++){var l=a[i],o=r[l];t(o,l,r)&&(e[l]=o)}return e}),H7=ri(function(r,a){var e=a[0],t;return Kt(e)?(e=ac(e),a.length>1&&(t=a[1])):(a=Mn(_n(a,!1,!1),String),e=function(i,s){return!hr(a,s)}),LO(r,e,t)});function UO(r,a,e){return ba.call(r,0,Math.max(0,r.length-(a==null||e?1:a)))}function pc(r,a,e){return r==null||r.length<1?a==null||e?void 0:[]:a==null||e?r[0]:UO(r,r.length-a)}function Bl(r,a,e){return ba.call(r,a==null||e?1:a)}function K7(r,a,e){return r==null||r.length<1?a==null||e?void 0:[]:a==null||e?r[r.length-1]:Bl(r,Math.max(0,r.length-a))}function X7(r){return Rs(r,Boolean)}function Q7(r,a){return _n(r,a,!1)}const gO=ri(function(r,a){return a=_n(a,!0,!0),Rs(r,function(e){return!hr(a,e)})}),eq=ri(function(r,a){return gO(r,a)});function cc(r,a,e,t){xD(a)||(t=e,e=a,a=!1),e!=null&&(e=si(e,t));for(var i=[],s=[],l=0,o=ni(r);l<o;l++){var d=r[l],u=e?e(d,l,r):d;a&&!e?((!l||s!==u)&&i.push(d),s=u):e?hr(s,u)||(s.push(u),i.push(d)):hr(i,d)||i.push(d)}return i}const tq=ri(function(r){return cc(_n(r,!0,!0))});function iq(r){for(var a=[],e=arguments.length,t=0,i=ni(r);t<i;t++){var s=r[t];if(!hr(a,s)){var l;for(l=1;l<e&&hr(arguments[l],s);l++);l===e&&a.push(s)}}return a}function fc(r){for(var a=r&&_O(r,ni).length||0,e=Array(a),t=0;t<a;t++)e[t]=uc(r,t);return e}const rq=ri(fc);function nq(r,a){for(var e={},t=0,i=ni(r);t<i;t++)a?e[r[t]]=a[t]:e[r[t][0]]=r[t][1];return e}function sq(r,a,e){a==null&&(a=r||0,r=0),e||(e=a<r?-1:1);for(var t=Math.max(Math.ceil((a-r)/e),0),i=Array(t),s=0;s<t;s++,r+=e)i[s]=r;return i}function aq(r,a){if(a==null||a<1)return[];for(var e=[],t=0,i=r.length;t<i;)e.push(ba.call(r,t,t+=a));return e}function yc(r,a){return r._chain?Ke(a).chain():a}function jO(r){return yr(Xp(r),function(a){var e=Ke[a]=r[a];Ke.prototype[a]=function(){var t=[this._wrapped];return _Z.apply(t,arguments),yc(this,e.apply(Ke,t))}}),Ke}yr(["pop","push","reverse","shift","sort","splice","unshift"],function(r){var a=Ol[r];Ke.prototype[r]=function(){var e=this._wrapped;return e!=null&&(a.apply(e,arguments),(r==="shift"||r==="splice")&&e.length===0&&delete e[0]),yc(this,e)}}),yr(["concat","join","slice"],function(r){var a=Ol[r];Ke.prototype[r]=function(){var e=this._wrapped;return e!=null&&(e=a.apply(e,arguments)),yc(this,e)}});var $O=jO(Object.freeze(Object.defineProperty({__proto__:null,VERSION:_D,after:N7,all:VO,allKeys:Oa,any:BO,assign:Cl,before:EO,bind:TO,bindAll:P7,chain:O7,chunk:aq,clone:o7,collect:Mn,compact:X7,compose:M7,constant:YD,contains:hr,countBy:J7,create:a7,debounce:B7,default:Ke,defaults:dO,defer:C7,delay:IO,detect:lc,difference:gO,drop:Bl,each:yr,escape:f7,every:VO,extend:lO,extendOwn:Cl,filter:Rs,find:lc,findIndex:oc,findKey:AO,findLastIndex:RO,findWhere:g7,first:pc,flatten:Q7,foldl:dc,foldr:CO,forEach:yr,functions:Xp,get:cO,groupBy:Z7,has:d7,head:pc,identity:tc,include:hr,includes:hr,indexBy:q7,indexOf:PO,initial:UO,inject:dc,intersection:iq,invert:oO,invoke:$7,isArguments:Wp,isArray:Bn,isArrayBuffer:ZD,isBoolean:xD,isDataView:Pl,isDate:FZ,isElement:GZ,isEmpty:Da,isEqual:KZ,isError:kZ,isFinite:JZ,isFunction:Kt,isMap:e7,isMatch:eO,isNaN:zD,isNull:$Z,isNumber:kD,isObject:Nr,isRegExp:xZ,isSet:i7,isString:Zp,isSymbol:SD,isTypedArray:XD,isUndefined:FD,isWeakMap:t7,isWeakSet:r7,iteratee:rc,keys:Vt,last:K7,lastIndexOf:U7,map:Mn,mapObject:u7,matcher:wa,matches:wa,max:_O,memoize:w7,methods:Xp,min:F7,mixin:jO,negate:ac,noop:yO,now:Va,object:nq,omit:H7,once:L7,pairs:n7,partial:bs,partition:W7,pick:LO,pluck:uc,property:ic,propertyOf:p7,random:nc,range:sq,reduce:dc,reduceRight:CO,reject:j7,rest:Bl,restArguments:ri,result:b7,sample:NO,select:Rs,shuffle:k7,size:z7,some:BO,sortBy:S7,sortedIndex:DO,tail:Bl,take:pc,tap:l7,template:A7,templateSettings:m7,throttle:V7,times:c7,toArray:MO,toPath:pO,transpose:fc,unescape:h7,union:tq,uniq:cc,unique:cc,uniqueId:D7,unzip:fc,values:As,where:G7,without:eq,wrap:_7,zip:rq},Symbol.toStringTag,{value:"Module"})));$O._=$O;function xt(r){return r.charAt(0).toUpperCase()+r.slice(1)}function _l(r){return r.charAt(0).toLowerCase()+r.slice(1)}function GO(r,a){if(r.type!==n.Property||a.type!==n.Property)throw new Error(`Expected property entities for comparison. But got ${r.type} and ${a.type}.`);return r===a||r.id===a.id?!0:r.name!==a.name||r.static!==a.static||r.abstract!==a.abstract?!1:Ri(r.dataType,a.dataType).compatible}function FO(r,a){if(r.type!==n.DefinitionEntity||a.type!==n.DefinitionEntity)throw new Error(`Expected definition entities for comparison. But got ${r.type} and ${a.type}.`);if(r===a||r.id===a.id)return!0;if(r.properties.length!==a.properties.length)return!1;let e=[...a.properties];const t=[];for(let i=0;i<r.properties.length;i++){const s=r.properties[i];e.find(o=>{const d=GO(s,o);return d&&(e=e.filter(u=>u.id!==o.id)),d})||t.push(s)}return!(t.length>0)}var bi=(r=>(r.BothUnconstrained="both-unconstrained",r.AConstraintBUnconstrained="a-constraint-b-unconstrained",r.BConstraintAUnconstrained="b-constraint-a-unconstrained",r.Same="same",r.AIsListBIsNot="a-is-list-b-is-not",r.BIsListAIsNot="b-is-list-a-is-not",r.AIsNullableBIsNot="a-is-nullable-b-is-not",r.BIsNullableAIsNot="b-is-nullable-a-is-not",r.AIsTemplateBIsNot="a-is-template-b-is-not",r.BIsTemplateAIsNot="b-is-template-a-is-not",r.BothUntyped="both-untyped",r.AIsUntypedBIsNot="a-is-untyped-b-is-not",r.BIsUntypedAIsNot="b-is-untyped-a-is-not",r.TypeEntityMismatch="type-entity-mismatch",r.SameDefinitionEntities="same-definition-entities",r.CompatibleDefinitionEntities="compatible-definition-entities",r.IncompatibleDefinitionEntities="incompatible-definition-entities",r.SamePrimitiveEntities="same-primitive-entities",r.IncompatiblePrimitiveEntities="incompatible-primitive-entities",r.SameBuiltInBaseEntities="same-built-in-base-entities",r.IncompatibleBuiltInBaseEntities="incompatible-built-in-base-entities",r.CheckUnknown="check-unknown",r))(bi||{});function Ri(r,a){var e,t,i,s,l,o,d,u,y,c,I;if(r&&r.type!==n.DataType||a&&a.type!==n.DataType)throw new Error(`Expected data-type entities for comparison. But got ${r==null?void 0:r.type} and ${a==null?void 0:a.type}.`);if(r===null&&a===null)return{compatible:!0,type:"both-unconstrained"};if(r===null)return{compatible:!0,type:"a-constraint-b-unconstrained"};if(a===null)return{compatible:!0,type:"b-constraint-a-unconstrained"};if(r===a)return{compatible:!0,type:"same"};if(r.id===a.id)return{compatible:!0,type:"same"};if(r.isList!==a.isList)return{compatible:!1,type:r.isList?"a-is-list-b-is-not":"b-is-list-a-is-not"};if(r.asType!==a.asType)return{compatible:!1,type:r.asType?"a-is-template-b-is-not":"b-is-template-a-is-not"};if(!r.entity&&a.entity)return{compatible:!0,type:"a-is-untyped-b-is-not"};if(r.entity&&!a.entity)return{compatible:!0,type:"b-is-untyped-a-is-not"};if(!r.entity&&!a.entity)return{compatible:!0,type:"both-untyped"};if(((e=r.entity)==null?void 0:e.type)!==((t=a.entity)==null?void 0:t.type))return{compatible:!1,type:"type-entity-mismatch"};if(((i=r.entity)==null?void 0:i.type)===n.DefinitionEntity){if(((s=r.entity)==null?void 0:s.id)===((l=a.entity)==null?void 0:l.id))return{compatible:!0,type:"same-definition-entities"};const E=FO(r.entity,a.entity);return{compatible:E,type:E?"compatible-definition-entities":"incompatible-definition-entities"}}return((o=r.entity)==null?void 0:o.type)===n.PrimitiveEntity?((d=r.entity)==null?void 0:d.id)===((u=a.entity)==null?void 0:u.id)?{compatible:!0,type:"same-primitive-entities"}:{compatible:!1,type:"incompatible-primitive-entities"}:((y=r.entity)==null?void 0:y.type)===n.BuiltInBaseEntity?((c=r.entity)==null?void 0:c.id)===((I=a.entity)==null?void 0:I.id)?{compatible:!0,type:"same-built-in-base-entities"}:{compatible:!1,type:"incompatible-built-in-base-entities"}:{compatible:!1,type:"check-unknown"}}function oq(r,a){const e=r.project.builtInBaseEntities.find(s=>s.id===z.EXECUTION),t={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,isList:!1,isNullable:!1,andChildrenGroup:null,orChildrenGroup:null,asType:!1,entity:null,constant:!1,defaultValue:null,parent:null},i=C(t,r.project);return i.inferred=!0,a==null||a.add(i,A.Added),i.metaSync(t,a),i.setParent(r,a),i.entity=e,i}function xO(r,a=null){return r.dataType?r.dataType:null}function hc(r,a=null){var t;const e=(t=r.declaration)==null?void 0:t.getDataType(a);return e&&e.isResolved?e:r.readsValue?Ji(r.readsValue,a):null}function mc(r,a=null){return r.dataType&&!r.dataType.inferred&&r.dataType.isResolved?r.dataType:r.readsValue?Ji(r.readsValue,a):null}function kO(r,a=null){return Ji(r.declaration,a)}function SO(r,a=null){return r.dataType&&!r.dataType.inferred?r.dataType:r.dataType&&r.dataType.inferred||!r.dataType?(r.inferDataTypeAndSyncInstancesInputsAndOutputs(a),r.dataType):null}function vc(r,a=null){var e;return((e=r.declaration)==null?void 0:e.dataType)||null}function ZO(r,a=null){return(r==null?void 0:r.dataType)||null}function qO(r,a=null){return(r==null?void 0:r.dataType)||null}function Ji(r,a=null){switch(r.type){case n.VariableDeclaration:return SO(r,a);case n.ArgumentDeclaration:return xO(r,a);case n.ReturnDeclaration:return mc(r,a);case n.VariableInstance:return kO(r,a);case n.InputMap:return hc(r,a);case n.OutputMap:return vc(r,a);case n.Property:return ZO(r,a);case n.ValueDescriptor:return qO(r,a);default:throw new Error(`Cannot infer data type from entity of type ${r.type}.`)}}function Ml(r,a=null){switch(r.type){case n.ArgumentDeclaration:return r.getDataType(a);case n.InputMap:return r.getDataType(a);case n.VariableDeclaration:return r.getDataType(a);case n.VariableInstance:return r.getDataType(a);case n.OutputMap:return r.getDataType(a);case n.ReturnDeclaration:return r.getDataType(a);case n.Property:return r.getDataType(a);case n.ValueDescriptor:return r.getDataType(a);default:return null}}function _(r){if(r){let a=null;return typeof r=="string"?a=r:r.entityId?a=r.entityId:r.type!==n.GenericReference&&(a=r.id),a}return null}function Nn(r){return r.declaration||r}function lq(r){return r.type===n.VariableDeclaration?r.parent===r.project?"global-declaration":"local-declaration":r.declaration.parent===r.project?"global-instance":"local-instance"}function Tc(r,a){const e=[];if(r.type===n.Project)e.push(...r.variableDeclarations);else{const i=Xt(qe(r)).filter(s=>s.type===n.VariableDeclaration);e.push(...i),r.parent&&(dt.includes(r.parent.type)||r.parent.type===n.Project)&&e.push(...Tc(r.parent))}return e}function dq(r){return r.split(/[\s-]+/).filter(t=>t.length>0).map((t,i)=>i===0?t.toLowerCase():t[0].toUpperCase()+t.slice(1).toLowerCase()).join("")}function uq(r){return r.split(/[\s-]+/).filter(t=>t.length>0).map(t=>t[0].toUpperCase()+t.slice(1).toLowerCase()).join("")}function JO(r){var a;return(a=r.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g))==null?void 0:a.map(e=>e.toLowerCase()).join("-")}function Nl(r){return JO(r).toLowerCase()}function Ll(r){var a,e;if(!r)return"Any data type";if(!r.entity){const t=r.isList;if(!((a=r.andChildrenGroup)!=null&&a.length)&&!((e=r.orChildrenGroup)!=null&&e.length))return t?"List of an any data type":"Any data type";let i="",s=!1,l=!1;return(r.andChildrenGroup||[]).forEach(o=>{const d=Ll(o),u=_l(d);s&&(i+=" and "),o.isGroup?i+="("+u+")":s?i+=u:i+=d,s=!0,l=!0}),(r.orChildrenGroup||[]).forEach(o=>{const d=Ll(o),u=_l(d);s&&(l&&(i+=","),i+=" or "),o.isGroup?i+="("+u+")":s?i+=u:i+=d,s=!0}),i}if(r.entity.type===n.PrimitiveEntity){let t=r.entity.name;switch(r.entity.name){case L.String:t="Text";break;case L.KeyValue:t="Data structure";break}return r.isList?`List of ${t}s`:`${t.slice(0,1).toUpperCase()}${t.slice(1)}`}else if(r.entity.type===n.DefinitionEntity){const t=x(r.entity,r.project);return r.isList?`List of ${t} entities`:t.slice(0,1).toUpperCase()+t.slice(1)}else if(r.entity.type===n.BuiltInBaseEntity){const t=zO(r.entity);return r.isList?`List of ${t} entities`:t.slice(0,1).toUpperCase()+t.slice(1)}else return r.isList?`List of ${r.entity.name} entities`:`${r.entity.name.slice(0,1).toUpperCase()+r.entity.name.slice(1)} entity`}function pq(r){if(!r)return"Any data type";const a=r.getDataType(null);return Ll(a)}function Ul(r){switch(r.declaration.id){case yt.Equal:return"is equal to";case yt.NotEqual:return"is not equal to";case yt.MoreThan:return"is greater than";case yt.MoreThanOrEqual:return"is greater than or equal to";case yt.LessThan:return"is less than";case yt.LessThanOrEqual:return"is less than or equal to";case yt.And:return"and";case yt.Or:return"or";case vi.Empty:return"is empty";case vi.NotEmpty:return"is not empty"}}function WO(r){return r.includes(z.HTTP_ENDPOINT)?"HTTP endpoint":r.includes(z.PERSISTED_ENTITY)?"Persisted entity":r.includes(z.CRON_JOB)?"Scheduled execution":r.includes(z.RELATIONAL_DATABASE)?"Relational database":"Entity"}function zO(r){switch(r.name){case z.HTTP_ENDPOINT:return"HTTP endpoint";case z.PERSISTED_ENTITY:return"Persisted entity";case z.CRON_JOB:return"Scheduled execution";case z.RELATIONAL_DATABASE:return"Relational database"}return"Entity"}function cq(r){const a=Qc(r);if(!a){const e=Xc(r);return e.includes(z.HTTP_ENDPOINT)?"HTTP endpoint":e.includes(z.PERSISTED_ENTITY)?"Persisted entity":e.includes(z.CRON_JOB)?"Scheduled execution":e.includes(z.RELATIONAL_DATABASE)?"Relational database":x(r,r.project)+" entity"}return x(a,r.project)+" entity"}function YO(r){let a="Find ";return r.outputsDeclarations.forEach((e,t)=>{const i=Ml(e,null),s=_l(i&&i.entity?x(i.entity,r.project):"unstructured data");t===0?a+=`${s} `:t===r.outputsDeclarations.length-1?a+=`and ${s} `:a+=`, ${s} `}),a}function HO(r){switch(r.name){case L.String:return"Text";case L.Number:return"Number";case L.Boolean:return"Boolean";case L.KeyValue:return"Data structure";case L.UUID:return"Unique identifier";case L.Date:return"Date";case L.EntityTemplate:return"Entity as template";case L.Enum:return"Enumeration";case L.File:return"File";case L.Null:return"Empty";case L.ActionDescriptor:return"Action descriptor";case L.Untyped:return"Untyped";default:return r.name}}function KO(r){switch(r.id){case Q.List:return"Loop over list items";case Q.ManualFlow:return"Manual flow control loop";case Q.ObjectKeys:return"Loop over object keys";case Q.ObjectValues:return"Loop over object values";case Q.Counted:return"Loop given number of times";case Q.String:return"Loop over text characters";case et.Addition:return"Sum numbers";case et.Subtraction:return"Subtract numbers";case et.Multiplication:return"Multiply numbers";case et.Division:return"Divide numbers";case et.Remainder:return"Get remainder of numbers";case et.Exponentiation:return"Get exponent of numbers";case Ee.AddIndex:return"Add at index position";case Ee.DeleteFirst:return"Delete first character";case Ee.DeleteLast:return"Delete last character";case Ee.DeleteIndex:return"Delete at index position";case Ee.Join:return"Join texts";case Ee.ReplaceAllMatches:return"Replace all matches";case Ee.ReplaceFirst:return"Replace first match";case Ee.ReplaceLast:return"Replace last match";case Ee.Split:return"Split text";case Ee.ReplaceIndex:return"Replace at index position";case Ee.ReplaceSingleMatch:return"Replace single match";case Ee.GetFirst:return"Get first character";case Ee.GetLast:return"Get last character";case Ee.GetIndex:return"Get at index position";case Ee.Append:return"Add at the end";case Ee.Prepend:return"Add at the start";case Xe.Wait:return"Wait";case Xe.Parallel:return"Run in parallel";case Xe.Sequential:return"Run in sequence";case _t.HttpRequest:return"HTTP request";case Qe.CreateNewInstance:return"Create new copy of entity";case he.AddIndex:return"Add item at index position";case he.DeleteFirst:return"Delete first item";case he.DeleteLast:return"Delete last item";case he.DeleteIndex:return"Delete item at index position";case he.Join:return"Join lists";case he.ReplaceAllMatches:return"Replace all matches";case he.ReplaceFirst:return"Replace first match";case he.ReplaceLast:return"Replace last match";case he.Split:return"Split list";case he.ReplaceIndex:return"Replace at index position";case he.ReplaceSingleMatch:return"Replace single match";case he.GetFirst:return"Get first item";case he.GetLast:return"Get last item";case he.GetIndex:return"Get item at index position";case he.Append:return"Add item at the end";case he.Prepend:return"Add item at the start";case Qi.PROJECT_PUBLICATION_COMPLETED:return"Project publication completed";default:return(r.name.slice(0,1).toUpperCase()+r.name.slice(1)).replaceAll("-"," ")}}function x(r,a){var e;if(n.FunctionDeclaration===r.type){const t=r.name;if(Object.values(di).includes(t))switch(t){case di.AbortExecution:return"Abort execution";case di.DeletePersistedEntity:return"Delete persisted entity";case di.SoftDeletePersistedEntity:return"Soft delete persisted entity";default:return xt(r.type).replaceAll("-"," ")}return t}if(n.BuiltInBaseEntity===r.type)return WO([r.name]);if(df.includes(r.type)&&r.type!==n.ActionDescriptor)return r.name;switch(r.type){case n.Search:return YO(r);case n.GlobalEvent:return r.implements?x(r.implements,a):xt(r.type).replaceAll("-"," ");case n.Operation:case n.InternalCall:case n.Loop:const t=mi(r.declaration,a);return x(t,a);case n.ActionDescriptor:return KO(r);case n.BreakStatement:const i=mi(r.parent,a);return`Stop loop ${x(i,a)}`;case n.ContinueStatement:const s=mi(r.parent,a);return`Execute next iteration of ${x(s,a)}`;case n.FunctionCall:return mi(r.declaration,a).name;case n.Condition:{const o=r;if((e=r.inputs)!=null&&e.length){const d=x(o.inputs[0],o.project);if(o.inputs[1]){const u=o.inputs[1].declaration.name;return`If ${d} ${Ul(o)} ${u}`}return`If ${d} ${Ul(o)}`}else return`If ${Ul(o)}`}case n.ReturnStatement:{const o=mi(r.parent,a);return`Output of ${x(o,a)}`}case n.InputMap:if(r.declaration){const o=mi(r.declaration,a);return x(o,a)||""}else return r.name||"";case n.VariableInstance:{const o=mi(r.declaration,a);return x(o,a)||""}case n.OutputMap:if(r.declaration){const o=mi(r.declaration,a);return(o==null?void 0:o.name)||""}else return"";case n.PrimitiveEntity:case n.LiteralValue:return HO(r);default:return xt(r.type).replaceAll("-"," ")}}function Ic(r,a){const e=[];r.name||e.push(new w({id:`${r.id}--${j.EmptyName}`,message:`Entity with id "${r.id}" and type "${r.type}" has an empty name. Please provide a 'name' string.`,severity:D.Error,code:j.EmptyName,issue:null}));const t=a.entities.filter(i=>i.name===r.name);return t.length&&e.push(new w({id:`${r.id}--${j.NameNotUniqueInScope}`,message:`Entity with id "${r.id}" and type "${r.type}" has a name "${r.name}" that is not unique in the project. Entity with id "${t[0].id}" has the same name.
36
+ `+s+"}",d}function bq(r,a,e){a=Pa(a);var t=a.length;if(!t)return Kt(e)?e.call(r):e;for(var i=0;i<t;i++){var s=r==null?void 0:r[a[i]];s===void 0&&(s=e,i=t),r=Kt(s)?s.call(r):s}return r}var Rq=0;function Dq(r){var a=++Rq+"";return r?r+a:a}function Oq(r){var a=Ke(r);return a._chain=!0,a}function vO(r,a,e,t,i){if(!(t instanceof a))return r.apply(e,i);var s=uO(r.prototype),l=r.apply(s,i);return Nr(l)?l:s}var bs=ri(function(r,a){var e=bs.placeholder,t=function(){for(var i=0,s=a.length,l=Array(s),o=0;o<s;o++)l[o]=a[o]===e?arguments[i++]:a[o];for(;i<arguments.length;)l.push(arguments[i++]);return vO(r,t,this,this,l)};return t});bs.placeholder=Ke;const TO=ri(function(r,a,e){if(!Kt(r))throw new TypeError("Bind must be called on a function");var t=ri(function(i){return vO(r,t,a,this,e.concat(i))});return t}),yi=HD(ni);function _n(r,a,e,t){if(t=t||[],!a&&a!==0)a=1/0;else if(a<=0)return t.concat(r);for(var i=t.length,s=0,l=ni(r);s<l;s++){var o=r[s];if(yi(o)&&(Bn(o)||Wp(o)))if(a>1)_n(o,a-1,e,t),i=t.length;else for(var d=0,u=o.length;d<u;)t[i++]=o[d++];else e||(t[i++]=o)}return t}const Pq=ri(function(r,a){a=_n(a,!1,!1);var e=a.length;if(e<1)throw new Error("bindAll must be passed function names");for(;e--;){var t=a[e];r[t]=TO(r[t],r)}return r});function wq(r,a){var e=function(t){var i=e.cache,s=""+(a?a.apply(this,arguments):t);return Lr(i,s)||(i[s]=r.apply(this,arguments)),i[s]};return e.cache={},e}const IO=ri(function(r,a,e){return setTimeout(function(){return r.apply(null,e)},a)}),Cq=bs(IO,Ke,1);function Vq(r,a,e){var t,i,s,l,o=0;e||(e={});var d=function(){o=e.leading===!1?0:Va(),t=null,l=r.apply(i,s),t||(i=s=null)},u=function(){var y=Va();!o&&e.leading===!1&&(o=y);var c=a-(y-o);return i=this,s=arguments,c<=0||c>a?(t&&(clearTimeout(t),t=null),o=y,l=r.apply(i,s),t||(i=s=null)):!t&&e.trailing!==!1&&(t=setTimeout(d,c)),l};return u.cancel=function(){clearTimeout(t),o=0,t=i=s=null},u}function Bq(r,a,e){var t,i,s,l,o,d=function(){var y=Va()-i;a>y?t=setTimeout(d,a-y):(t=null,e||(l=r.apply(o,s)),t||(s=o=null))},u=ri(function(y){return o=this,s=y,i=Va(),t||(t=setTimeout(d,a),e&&(l=r.apply(o,s))),l});return u.cancel=function(){clearTimeout(t),t=s=o=null},u}function _q(r,a){return bs(a,r)}function ac(r){return function(){return!r.apply(this,arguments)}}function Mq(){var r=arguments,a=r.length-1;return function(){for(var e=a,t=r[a].apply(this,arguments);e--;)t=r[e].call(this,t);return t}}function Nq(r,a){return function(){if(--r<1)return a.apply(this,arguments)}}function EO(r,a){var e;return function(){return--r>0&&(e=a.apply(this,arguments)),r<=1&&(a=null),e}}const Lq=bs(EO,2);function AO(r,a,e){a=si(a,e);for(var t=Vt(r),i,s=0,l=t.length;s<l;s++)if(i=t[s],a(r[i],i,r))return i}function bO(r){return function(a,e,t){e=si(e,t);for(var i=ni(a),s=r>0?0:i-1;s>=0&&s<i;s+=r)if(e(a[s],s,a))return s;return-1}}const oc=bO(1),RO=bO(-1);function DO(r,a,e,t){e=si(e,t,1);for(var i=e(a),s=0,l=ni(r);s<l;){var o=Math.floor((s+l)/2);e(r[o])<i?s=o+1:l=o}return s}function OO(r,a,e){return function(t,i,s){var l=0,o=ni(t);if(typeof s=="number")r>0?l=s>=0?s:Math.max(s+o,l):o=s>=0?Math.min(s+1,o):s+o+1;else if(e&&s&&o)return s=e(t,i),t[s]===i?s:-1;if(i!==i)return s=a(ba.call(t,l,o),zD),s>=0?s+l:-1;for(s=r>0?l:o-1;s>=0&&s<o;s+=r)if(t[s]===i)return s;return-1}}const PO=OO(1,oc,DO),Uq=OO(-1,RO);function lc(r,a,e){var t=yi(r)?oc:AO,i=t(r,a,e);if(i!==void 0&&i!==-1)return r[i]}function gq(r,a){return lc(r,wa(a))}function yr(r,a,e){a=Ca(a,e);var t,i;if(yi(r))for(t=0,i=r.length;t<i;t++)a(r[t],t,r);else{var s=Vt(r);for(t=0,i=s.length;t<i;t++)a(r[s[t]],s[t],r)}return r}function Mn(r,a,e){a=si(a,e);for(var t=!yi(r)&&Vt(r),i=(t||r).length,s=Array(i),l=0;l<i;l++){var o=t?t[l]:l;s[l]=a(r[o],o,r)}return s}function wO(r){var a=function(e,t,i,s){var l=!yi(e)&&Vt(e),o=(l||e).length,d=r>0?0:o-1;for(s||(i=e[l?l[d]:d],d+=r);d>=0&&d<o;d+=r){var u=l?l[d]:d;i=t(i,e[u],u,e)}return i};return function(e,t,i,s){var l=arguments.length>=3;return a(e,Ca(t,s,4),i,l)}}const dc=wO(1),CO=wO(-1);function Rs(r,a,e){var t=[];return a=si(a,e),yr(r,function(i,s,l){a(i,s,l)&&t.push(i)}),t}function jq(r,a,e){return Rs(r,ac(si(a)),e)}function VO(r,a,e){a=si(a,e);for(var t=!yi(r)&&Vt(r),i=(t||r).length,s=0;s<i;s++){var l=t?t[s]:s;if(!a(r[l],l,r))return!1}return!0}function BO(r,a,e){a=si(a,e);for(var t=!yi(r)&&Vt(r),i=(t||r).length,s=0;s<i;s++){var l=t?t[s]:s;if(a(r[l],l,r))return!0}return!1}function hr(r,a,e,t){return yi(r)||(r=As(r)),(typeof e!="number"||t)&&(e=0),PO(r,a,e)>=0}const $q=ri(function(r,a,e){var t,i;return Kt(a)?i=a:(a=Pa(a),t=a.slice(0,-1),a=a[a.length-1]),Mn(r,function(s){var l=i;if(!l){if(t&&t.length&&(s=ec(s,t)),s==null)return;l=s[a]}return l==null?l:l.apply(s,e)})});function uc(r,a){return Mn(r,ic(a))}function Gq(r,a){return Rs(r,wa(a))}function _O(r,a,e){var t=-1/0,i=-1/0,s,l;if(a==null||typeof a=="number"&&typeof r[0]!="object"&&r!=null){r=yi(r)?r:As(r);for(var o=0,d=r.length;o<d;o++)s=r[o],s!=null&&s>t&&(t=s)}else a=si(a,e),yr(r,function(u,y,c){l=a(u,y,c),(l>i||l===-1/0&&t===-1/0)&&(t=u,i=l)});return t}function Fq(r,a,e){var t=1/0,i=1/0,s,l;if(a==null||typeof a=="number"&&typeof r[0]!="object"&&r!=null){r=yi(r)?r:As(r);for(var o=0,d=r.length;o<d;o++)s=r[o],s!=null&&s<t&&(t=s)}else a=si(a,e),yr(r,function(u,y,c){l=a(u,y,c),(l<i||l===1/0&&t===1/0)&&(t=u,i=l)});return t}var xq=/[^\ud800-\udfff]|[\ud800-\udbff][\udc00-\udfff]|[\ud800-\udfff]/g;function MO(r){return r?Bn(r)?ba.call(r):Zp(r)?r.match(xq):yi(r)?Mn(r,tc):As(r):[]}function NO(r,a,e){if(a==null||e)return yi(r)||(r=As(r)),r[nc(r.length-1)];var t=MO(r),i=ni(t);a=Math.max(Math.min(a,i),0);for(var s=i-1,l=0;l<a;l++){var o=nc(l,s),d=t[l];t[l]=t[o],t[o]=d}return t.slice(0,a)}function kq(r){return NO(r,1/0)}function Sq(r,a,e){var t=0;return a=si(a,e),uc(Mn(r,function(i,s,l){return{value:i,index:t++,criteria:a(i,s,l)}}).sort(function(i,s){var l=i.criteria,o=s.criteria;if(l!==o){if(l>o||l===void 0)return 1;if(l<o||o===void 0)return-1}return i.index-s.index}),"value")}function Vl(r,a){return function(e,t,i){var s=a?[[],[]]:{};return t=si(t,i),yr(e,function(l,o){var d=t(l,o,e);r(s,l,d)}),s}}const Zq=Vl(function(r,a,e){Lr(r,e)?r[e].push(a):r[e]=[a]}),qq=Vl(function(r,a,e){r[e]=a}),Jq=Vl(function(r,a,e){Lr(r,e)?r[e]++:r[e]=1}),Wq=Vl(function(r,a,e){r[e?0:1].push(a)},!0);function zq(r){return r==null?0:yi(r)?r.length:Vt(r).length}function Yq(r,a,e){return a in e}const LO=ri(function(r,a){var e={},t=a[0];if(r==null)return e;Kt(t)?(a.length>1&&(t=Ca(t,a[1])),a=Oa(r)):(t=Yq,a=_n(a,!1,!1),r=Object(r));for(var i=0,s=a.length;i<s;i++){var l=a[i],o=r[l];t(o,l,r)&&(e[l]=o)}return e}),Hq=ri(function(r,a){var e=a[0],t;return Kt(e)?(e=ac(e),a.length>1&&(t=a[1])):(a=Mn(_n(a,!1,!1),String),e=function(i,s){return!hr(a,s)}),LO(r,e,t)});function UO(r,a,e){return ba.call(r,0,Math.max(0,r.length-(a==null||e?1:a)))}function pc(r,a,e){return r==null||r.length<1?a==null||e?void 0:[]:a==null||e?r[0]:UO(r,r.length-a)}function Bl(r,a,e){return ba.call(r,a==null||e?1:a)}function Kq(r,a,e){return r==null||r.length<1?a==null||e?void 0:[]:a==null||e?r[r.length-1]:Bl(r,Math.max(0,r.length-a))}function Xq(r){return Rs(r,Boolean)}function Qq(r,a){return _n(r,a,!1)}const gO=ri(function(r,a){return a=_n(a,!0,!0),Rs(r,function(e){return!hr(a,e)})}),e7=ri(function(r,a){return gO(r,a)});function cc(r,a,e,t){xD(a)||(t=e,e=a,a=!1),e!=null&&(e=si(e,t));for(var i=[],s=[],l=0,o=ni(r);l<o;l++){var d=r[l],u=e?e(d,l,r):d;a&&!e?((!l||s!==u)&&i.push(d),s=u):e?hr(s,u)||(s.push(u),i.push(d)):hr(i,d)||i.push(d)}return i}const t7=ri(function(r){return cc(_n(r,!0,!0))});function i7(r){for(var a=[],e=arguments.length,t=0,i=ni(r);t<i;t++){var s=r[t];if(!hr(a,s)){var l;for(l=1;l<e&&hr(arguments[l],s);l++);l===e&&a.push(s)}}return a}function fc(r){for(var a=r&&_O(r,ni).length||0,e=Array(a),t=0;t<a;t++)e[t]=uc(r,t);return e}const r7=ri(fc);function n7(r,a){for(var e={},t=0,i=ni(r);t<i;t++)a?e[r[t]]=a[t]:e[r[t][0]]=r[t][1];return e}function s7(r,a,e){a==null&&(a=r||0,r=0),e||(e=a<r?-1:1);for(var t=Math.max(Math.ceil((a-r)/e),0),i=Array(t),s=0;s<t;s++,r+=e)i[s]=r;return i}function a7(r,a){if(a==null||a<1)return[];for(var e=[],t=0,i=r.length;t<i;)e.push(ba.call(r,t,t+=a));return e}function yc(r,a){return r._chain?Ke(a).chain():a}function jO(r){return yr(Xp(r),function(a){var e=Ke[a]=r[a];Ke.prototype[a]=function(){var t=[this._wrapped];return _Z.apply(t,arguments),yc(this,e.apply(Ke,t))}}),Ke}yr(["pop","push","reverse","shift","sort","splice","unshift"],function(r){var a=Ol[r];Ke.prototype[r]=function(){var e=this._wrapped;return e!=null&&(a.apply(e,arguments),(r==="shift"||r==="splice")&&e.length===0&&delete e[0]),yc(this,e)}}),yr(["concat","join","slice"],function(r){var a=Ol[r];Ke.prototype[r]=function(){var e=this._wrapped;return e!=null&&(e=a.apply(e,arguments)),yc(this,e)}});var $O=jO(Object.freeze(Object.defineProperty({__proto__:null,VERSION:_D,after:Nq,all:VO,allKeys:Oa,any:BO,assign:Cl,before:EO,bind:TO,bindAll:Pq,chain:Oq,chunk:a7,clone:oq,collect:Mn,compact:Xq,compose:Mq,constant:YD,contains:hr,countBy:Jq,create:aq,debounce:Bq,default:Ke,defaults:dO,defer:Cq,delay:IO,detect:lc,difference:gO,drop:Bl,each:yr,escape:fq,every:VO,extend:lO,extendOwn:Cl,filter:Rs,find:lc,findIndex:oc,findKey:AO,findLastIndex:RO,findWhere:gq,first:pc,flatten:Qq,foldl:dc,foldr:CO,forEach:yr,functions:Xp,get:cO,groupBy:Zq,has:dq,head:pc,identity:tc,include:hr,includes:hr,indexBy:qq,indexOf:PO,initial:UO,inject:dc,intersection:i7,invert:oO,invoke:$q,isArguments:Wp,isArray:Bn,isArrayBuffer:ZD,isBoolean:xD,isDataView:Pl,isDate:FZ,isElement:GZ,isEmpty:Da,isEqual:KZ,isError:kZ,isFinite:JZ,isFunction:Kt,isMap:eq,isMatch:eO,isNaN:zD,isNull:$Z,isNumber:kD,isObject:Nr,isRegExp:xZ,isSet:iq,isString:Zp,isSymbol:SD,isTypedArray:XD,isUndefined:FD,isWeakMap:tq,isWeakSet:rq,iteratee:rc,keys:Vt,last:Kq,lastIndexOf:Uq,map:Mn,mapObject:uq,matcher:wa,matches:wa,max:_O,memoize:wq,methods:Xp,min:Fq,mixin:jO,negate:ac,noop:yO,now:Va,object:n7,omit:Hq,once:Lq,pairs:nq,partial:bs,partition:Wq,pick:LO,pluck:uc,property:ic,propertyOf:pq,random:nc,range:s7,reduce:dc,reduceRight:CO,reject:jq,rest:Bl,restArguments:ri,result:bq,sample:NO,select:Rs,shuffle:kq,size:zq,some:BO,sortBy:Sq,sortedIndex:DO,tail:Bl,take:pc,tap:lq,template:Aq,templateSettings:mq,throttle:Vq,times:cq,toArray:MO,toPath:pO,transpose:fc,unescape:hq,union:t7,uniq:cc,unique:cc,uniqueId:Dq,unzip:fc,values:As,where:Gq,without:e7,wrap:_q,zip:r7},Symbol.toStringTag,{value:"Module"})));$O._=$O;function xt(r){return r.charAt(0).toUpperCase()+r.slice(1)}function _l(r){return r.charAt(0).toLowerCase()+r.slice(1)}function GO(r,a){if(r.type!==n.Property||a.type!==n.Property)throw new Error(`Expected property entities for comparison. But got ${r.type} and ${a.type}.`);return r===a||r.id===a.id?!0:r.name!==a.name||r.static!==a.static||r.abstract!==a.abstract?!1:Ri(r.dataType,a.dataType).compatible}function FO(r,a){if(r.type!==n.DefinitionEntity||a.type!==n.DefinitionEntity)throw new Error(`Expected definition entities for comparison. But got ${r.type} and ${a.type}.`);if(r===a||r.id===a.id)return!0;if(r.properties.length!==a.properties.length)return!1;let e=[...a.properties];const t=[];for(let i=0;i<r.properties.length;i++){const s=r.properties[i];e.find(o=>{const d=GO(s,o);return d&&(e=e.filter(u=>u.id!==o.id)),d})||t.push(s)}return!(t.length>0)}var bi=(r=>(r.BothUnconstrained="both-unconstrained",r.AConstraintBUnconstrained="a-constraint-b-unconstrained",r.BConstraintAUnconstrained="b-constraint-a-unconstrained",r.Same="same",r.AIsListBIsNot="a-is-list-b-is-not",r.BIsListAIsNot="b-is-list-a-is-not",r.AIsNullableBIsNot="a-is-nullable-b-is-not",r.BIsNullableAIsNot="b-is-nullable-a-is-not",r.AIsTemplateBIsNot="a-is-template-b-is-not",r.BIsTemplateAIsNot="b-is-template-a-is-not",r.BothUntyped="both-untyped",r.AIsUntypedBIsNot="a-is-untyped-b-is-not",r.BIsUntypedAIsNot="b-is-untyped-a-is-not",r.TypeEntityMismatch="type-entity-mismatch",r.SameDefinitionEntities="same-definition-entities",r.CompatibleDefinitionEntities="compatible-definition-entities",r.IncompatibleDefinitionEntities="incompatible-definition-entities",r.SamePrimitiveEntities="same-primitive-entities",r.IncompatiblePrimitiveEntities="incompatible-primitive-entities",r.SameBuiltInBaseEntities="same-built-in-base-entities",r.IncompatibleBuiltInBaseEntities="incompatible-built-in-base-entities",r.CheckUnknown="check-unknown",r))(bi||{});function Ri(r,a){var e,t,i,s,l,o,d,u,y,c,I;if(r&&r.type!==n.DataType||a&&a.type!==n.DataType)throw new Error(`Expected data-type entities for comparison. But got ${r==null?void 0:r.type} and ${a==null?void 0:a.type}.`);if(r===null&&a===null)return{compatible:!0,type:"both-unconstrained"};if(r===null)return{compatible:!0,type:"a-constraint-b-unconstrained"};if(a===null)return{compatible:!0,type:"b-constraint-a-unconstrained"};if(r===a)return{compatible:!0,type:"same"};if(r.id===a.id)return{compatible:!0,type:"same"};if(r.isList!==a.isList)return{compatible:!1,type:r.isList?"a-is-list-b-is-not":"b-is-list-a-is-not"};if(r.asType!==a.asType)return{compatible:!1,type:r.asType?"a-is-template-b-is-not":"b-is-template-a-is-not"};if(!r.entity&&a.entity)return{compatible:!0,type:"a-is-untyped-b-is-not"};if(r.entity&&!a.entity)return{compatible:!0,type:"b-is-untyped-a-is-not"};if(!r.entity&&!a.entity)return{compatible:!0,type:"both-untyped"};if(((e=r.entity)==null?void 0:e.type)!==((t=a.entity)==null?void 0:t.type))return{compatible:!1,type:"type-entity-mismatch"};if(((i=r.entity)==null?void 0:i.type)===n.DefinitionEntity){if(((s=r.entity)==null?void 0:s.id)===((l=a.entity)==null?void 0:l.id))return{compatible:!0,type:"same-definition-entities"};const E=FO(r.entity,a.entity);return{compatible:E,type:E?"compatible-definition-entities":"incompatible-definition-entities"}}return((o=r.entity)==null?void 0:o.type)===n.PrimitiveEntity?((d=r.entity)==null?void 0:d.id)===((u=a.entity)==null?void 0:u.id)?{compatible:!0,type:"same-primitive-entities"}:{compatible:!1,type:"incompatible-primitive-entities"}:((y=r.entity)==null?void 0:y.type)===n.BuiltInBaseEntity?((c=r.entity)==null?void 0:c.id)===((I=a.entity)==null?void 0:I.id)?{compatible:!0,type:"same-built-in-base-entities"}:{compatible:!1,type:"incompatible-built-in-base-entities"}:{compatible:!1,type:"check-unknown"}}function o7(r,a){const e=r.project.builtInBaseEntities.find(s=>s.id===z.EXECUTION),t={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,isList:!1,isNullable:!1,andChildrenGroup:null,orChildrenGroup:null,asType:!1,entity:null,constant:!1,defaultValue:null,parent:null},i=C(t,r.project);return i.inferred=!0,a==null||a.add(i,A.Added),i.metaSync(t,a),i.setParent(r,a),i.entity=e,i}function xO(r,a=null){return r.dataType?r.dataType:null}function hc(r,a=null){var t;const e=(t=r.declaration)==null?void 0:t.getDataType(a);return e&&e.isResolved?e:r.readsValue?Ji(r.readsValue,a):null}function mc(r,a=null){return r.dataType&&!r.dataType.inferred&&r.dataType.isResolved?r.dataType:r.readsValue?Ji(r.readsValue,a):null}function kO(r,a=null){return Ji(r.declaration,a)}function SO(r,a=null){return r.dataType&&!r.dataType.inferred?r.dataType:r.dataType&&r.dataType.inferred||!r.dataType?(r.inferDataTypeAndSyncInstancesInputsAndOutputs(a),r.dataType):null}function vc(r,a=null){var e;return((e=r.declaration)==null?void 0:e.dataType)||null}function ZO(r,a=null){return(r==null?void 0:r.dataType)||null}function qO(r,a=null){return(r==null?void 0:r.dataType)||null}function Ji(r,a=null){switch(r.type){case n.VariableDeclaration:return SO(r,a);case n.ArgumentDeclaration:return xO(r,a);case n.ReturnDeclaration:return mc(r,a);case n.VariableInstance:return kO(r,a);case n.InputMap:return hc(r,a);case n.OutputMap:return vc(r,a);case n.Property:return ZO(r,a);case n.ValueDescriptor:return qO(r,a);default:throw new Error(`Cannot infer data type from entity of type ${r.type}.`)}}function Ml(r,a=null){switch(r.type){case n.ArgumentDeclaration:return r.getDataType(a);case n.InputMap:return r.getDataType(a);case n.VariableDeclaration:return r.getDataType(a);case n.VariableInstance:return r.getDataType(a);case n.OutputMap:return r.getDataType(a);case n.ReturnDeclaration:return r.getDataType(a);case n.Property:return r.getDataType(a);case n.ValueDescriptor:return r.getDataType(a);default:return null}}function _(r){if(r){let a=null;return typeof r=="string"?a=r:r.entityId?a=r.entityId:r.type!==n.GenericReference&&(a=r.id),a}return null}function Nn(r){return r.declaration||r}function l7(r){return r.type===n.VariableDeclaration?r.parent===r.project?"global-declaration":"local-declaration":r.declaration.parent===r.project?"global-instance":"local-instance"}function Tc(r,a){const e=[];if(r.type===n.Project)e.push(...r.variableDeclarations);else{const i=Xt(qe(r)).filter(s=>s.type===n.VariableDeclaration);e.push(...i),r.parent&&(dt.includes(r.parent.type)||r.parent.type===n.Project)&&e.push(...Tc(r.parent))}return e}function d7(r){return r.split(/[\s-]+/).filter(t=>t.length>0).map((t,i)=>i===0?t.toLowerCase():t[0].toUpperCase()+t.slice(1).toLowerCase()).join("")}function u7(r){return r.split(/[\s-]+/).filter(t=>t.length>0).map(t=>t[0].toUpperCase()+t.slice(1).toLowerCase()).join("")}function JO(r){var a;return(a=r.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g))==null?void 0:a.map(e=>e.toLowerCase()).join("-")}function Nl(r){return JO(r).toLowerCase()}function Ll(r){var a,e;if(!r)return"Any data type";if(!r.entity){const t=r.isList;if(!((a=r.andChildrenGroup)!=null&&a.length)&&!((e=r.orChildrenGroup)!=null&&e.length))return t?"List of an any data type":"Any data type";let i="",s=!1,l=!1;return(r.andChildrenGroup||[]).forEach(o=>{const d=Ll(o),u=_l(d);s&&(i+=" and "),o.isGroup?i+="("+u+")":s?i+=u:i+=d,s=!0,l=!0}),(r.orChildrenGroup||[]).forEach(o=>{const d=Ll(o),u=_l(d);s&&(l&&(i+=","),i+=" or "),o.isGroup?i+="("+u+")":s?i+=u:i+=d,s=!0}),i}if(r.entity.type===n.PrimitiveEntity){let t=r.entity.name;switch(r.entity.name){case L.String:t="Text";break;case L.KeyValue:t="Data structure";break}return r.isList?`List of ${t}s`:`${t.slice(0,1).toUpperCase()}${t.slice(1)}`}else if(r.entity.type===n.DefinitionEntity){const t=x(r.entity,r.project);return r.isList?`List of ${t} entities`:t.slice(0,1).toUpperCase()+t.slice(1)}else if(r.entity.type===n.BuiltInBaseEntity){const t=zO(r.entity);return r.isList?`List of ${t} entities`:t.slice(0,1).toUpperCase()+t.slice(1)}else return r.isList?`List of ${r.entity.name} entities`:`${r.entity.name.slice(0,1).toUpperCase()+r.entity.name.slice(1)} entity`}function p7(r){if(!r)return"Any data type";const a=r.getDataType(null);return Ll(a)}function Ul(r){switch(r.declaration.id){case yt.Equal:return"is equal to";case yt.NotEqual:return"is not equal to";case yt.MoreThan:return"is greater than";case yt.MoreThanOrEqual:return"is greater than or equal to";case yt.LessThan:return"is less than";case yt.LessThanOrEqual:return"is less than or equal to";case yt.And:return"and";case yt.Or:return"or";case vi.Empty:return"is empty";case vi.NotEmpty:return"is not empty"}}function WO(r){return r.includes(z.HTTP_ENDPOINT)?"HTTP endpoint":r.includes(z.PERSISTED_ENTITY)?"Persisted entity":r.includes(z.CRON_JOB)?"Scheduled execution":r.includes(z.RELATIONAL_DATABASE)?"Relational database":"Entity"}function zO(r){switch(r.name){case z.HTTP_ENDPOINT:return"HTTP endpoint";case z.PERSISTED_ENTITY:return"Persisted entity";case z.CRON_JOB:return"Scheduled execution";case z.RELATIONAL_DATABASE:return"Relational database"}return"Entity"}function c7(r){const a=Qc(r);if(!a){const e=Xc(r);return e.includes(z.HTTP_ENDPOINT)?"HTTP endpoint":e.includes(z.PERSISTED_ENTITY)?"Persisted entity":e.includes(z.CRON_JOB)?"Scheduled execution":e.includes(z.RELATIONAL_DATABASE)?"Relational database":x(r,r.project)+" entity"}return x(a,r.project)+" entity"}function YO(r){let a="Find ";return r.outputsDeclarations.forEach((e,t)=>{const i=Ml(e,null),s=_l(i&&i.entity?x(i.entity,r.project):"unstructured data");t===0?a+=`${s} `:t===r.outputsDeclarations.length-1?a+=`and ${s} `:a+=`, ${s} `}),a}function HO(r){switch(r.name){case L.String:return"Text";case L.Number:return"Number";case L.Boolean:return"Boolean";case L.KeyValue:return"Data structure";case L.UUID:return"Unique identifier";case L.Date:return"Date";case L.EntityTemplate:return"Entity as template";case L.Enum:return"Enumeration";case L.File:return"File";case L.Null:return"Empty";case L.ActionDescriptor:return"Action descriptor";case L.Untyped:return"Untyped";default:return r.name}}function KO(r){switch(r.id){case Q.List:return"Loop over list items";case Q.ManualFlow:return"Manual flow control loop";case Q.ObjectKeys:return"Loop over object keys";case Q.ObjectValues:return"Loop over object values";case Q.Counted:return"Loop given number of times";case Q.String:return"Loop over text characters";case et.Addition:return"Sum numbers";case et.Subtraction:return"Subtract numbers";case et.Multiplication:return"Multiply numbers";case et.Division:return"Divide numbers";case et.Remainder:return"Get remainder of numbers";case et.Exponentiation:return"Get exponent of numbers";case Ee.AddIndex:return"Add at index position";case Ee.DeleteFirst:return"Delete first character";case Ee.DeleteLast:return"Delete last character";case Ee.DeleteIndex:return"Delete at index position";case Ee.Join:return"Join texts";case Ee.ReplaceAllMatches:return"Replace all matches";case Ee.ReplaceFirst:return"Replace first match";case Ee.ReplaceLast:return"Replace last match";case Ee.Split:return"Split text";case Ee.ReplaceIndex:return"Replace at index position";case Ee.ReplaceSingleMatch:return"Replace single match";case Ee.GetFirst:return"Get first character";case Ee.GetLast:return"Get last character";case Ee.GetIndex:return"Get at index position";case Ee.Append:return"Add at the end";case Ee.Prepend:return"Add at the start";case Xe.Wait:return"Wait";case Xe.Parallel:return"Run in parallel";case Xe.Sequential:return"Run in sequence";case _t.HttpRequest:return"HTTP request";case Qe.CreateNewInstance:return"Create new copy of entity";case he.AddIndex:return"Add item at index position";case he.DeleteFirst:return"Delete first item";case he.DeleteLast:return"Delete last item";case he.DeleteIndex:return"Delete item at index position";case he.Join:return"Join lists";case he.ReplaceAllMatches:return"Replace all matches";case he.ReplaceFirst:return"Replace first match";case he.ReplaceLast:return"Replace last match";case he.Split:return"Split list";case he.ReplaceIndex:return"Replace at index position";case he.ReplaceSingleMatch:return"Replace single match";case he.GetFirst:return"Get first item";case he.GetLast:return"Get last item";case he.GetIndex:return"Get item at index position";case he.Append:return"Add item at the end";case he.Prepend:return"Add item at the start";case Qi.PROJECT_PUBLICATION_COMPLETED:return"Project publication completed";default:return(r.name.slice(0,1).toUpperCase()+r.name.slice(1)).replaceAll("-"," ")}}function x(r,a){var e;if(n.FunctionDeclaration===r.type){const t=r.name;if(Object.values(di).includes(t))switch(t){case di.AbortExecution:return"Abort execution";case di.DeletePersistedEntity:return"Delete persisted entity";case di.SoftDeletePersistedEntity:return"Soft delete persisted entity";default:return xt(r.type).replaceAll("-"," ")}return t}if(n.BuiltInBaseEntity===r.type)return WO([r.name]);if(df.includes(r.type)&&r.type!==n.ActionDescriptor)return r.name;switch(r.type){case n.Search:return YO(r);case n.GlobalEvent:return r.implements?x(r.implements,a):xt(r.type).replaceAll("-"," ");case n.Operation:case n.InternalCall:case n.Loop:const t=mi(r.declaration,a);return x(t,a);case n.ActionDescriptor:return KO(r);case n.BreakStatement:const i=mi(r.parent,a);return`Stop loop ${x(i,a)}`;case n.ContinueStatement:const s=mi(r.parent,a);return`Execute next iteration of ${x(s,a)}`;case n.FunctionCall:return mi(r.declaration,a).name;case n.Condition:{const o=r;if((e=r.inputs)!=null&&e.length){const d=x(o.inputs[0],o.project);if(o.inputs[1]){const u=o.inputs[1].declaration.name;return`If ${d} ${Ul(o)} ${u}`}return`If ${d} ${Ul(o)}`}else return`If ${Ul(o)}`}case n.ReturnStatement:{const o=mi(r.parent,a);return`Output of ${x(o,a)}`}case n.InputMap:if(r.declaration){const o=mi(r.declaration,a);return x(o,a)||""}else return r.name||"";case n.VariableInstance:{const o=mi(r.declaration,a);return x(o,a)||""}case n.OutputMap:if(r.declaration){const o=mi(r.declaration,a);return(o==null?void 0:o.name)||""}else return"";case n.PrimitiveEntity:case n.LiteralValue:return HO(r);default:return xt(r.type).replaceAll("-"," ")}}function Ic(r,a){const e=[];r.name||e.push(new w({id:`${r.id}--${j.EmptyName}`,message:`Entity with id "${r.id}" and type "${r.type}" has an empty name. Please provide a 'name' string.`,severity:D.Error,code:j.EmptyName,issue:null}));const t=a.entities.filter(i=>i.name===r.name);return t.length&&e.push(new w({id:`${r.id}--${j.NameNotUniqueInScope}`,message:`Entity with id "${r.id}" and type "${r.type}" has a name "${r.name}" that is not unique in the project. Entity with id "${t[0].id}" has the same name.
37
37
  Please provide a unique 'name' string.`,severity:D.Error,code:j.NameNotUniqueInScope,issue:null})),e}function Ec(r,a){const e=[];r.name||e.push(new w({id:`${r.id}--${j.EmptyName}`,message:`Entity with id "${r.id}" and type "${r.type}" has an empty name. Please provide a 'name' string.`,severity:D.Error,code:j.EmptyName,issue:null}));const t=r.parent?_(r.parent):null;let i=a;t&&(i=a.get(t));const s=[];i.type===n.DefinitionEntity?s.push(...i.methods.map(o=>o)):i.type===n.Project?s.push(...i.functions.map(o=>o)):i.type===n.Loop?i.body&&s.push(i.body):i.type===n.InstalledProject&&s.push(...i.functions.map(o=>o));const l=s.filter(o=>o.name===r.name);return l.length&&e.push(new w({id:`${r.id}--${j.NameNotUniqueInScope}`,message:`Entity with id "${r.id}" and type "${r.type}" has a name "${r.name}" that is not unique in ${i.type===n.Project?"the globally declared project scope":"its parent entity"}. Entity with id "${l[0].id}" has the same name.
38
38
  Please provide a unique 'name' string.`,severity:D.Error,code:j.NameNotUniqueInScope,issue:null})),e}function Ac(r,a){const e=[];r.name||e.push(new w({id:`${r.id}--${j.EmptyName}`,message:`Entity with id "${r.id}" and type "${r.type}" has an empty name. Please provide a 'name' string.`,severity:D.Error,code:j.EmptyName,issue:null}));const t=r.parent&&mi(r.parent,a)||a;if(!t)e.push(new w({id:`${r.id}--parent-reference--${R.ReferencedEntityNotFound}`,message:`The entity with id '${r.parent}' that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,severity:D.Error,code:R.ReferencedEntityNotFound,issue:null}));else{const s=Tc(t).filter(l=>l.name===r.name);s.length&&e.push(new w({id:`${r.id}--${j.NameNotUniqueInScope}`,message:`Entity with id "${r.id}" and type "${r.type}" has a name "${r.name}" that is not unique in its scope or higher scopes. Entity with id "${s[0].id}" has the same name.
39
39
  Please provide a unique 'name' string.`,severity:D.Error,code:j.NameNotUniqueInScope,issue:null}))}return e}function bc(r,a){const e=[];r.name||e.push(new w({id:`${r.id}--${j.EmptyName}`,message:`Entity with id "${r.id}" and type "${r.type}" has an empty name. Please provide a 'name' string.`,severity:D.Error,code:j.EmptyName,issue:null}));const t=_(r.parent);if(!t)e.push(new w({id:`${r.id}--parent-reference--${R.InvalidReferenceObjectStructure}`,message:`Reference object at 'parent' property for entity with id "${r.id}" and type "${r.type}" is not a valid reference. A reference needs to be a 'id' string of an existing entity in the project.`,severity:D.Error,code:R.InvalidReferenceObjectStructure,issue:null}));else{const i=a.get(t);if(!i)e.push(new w({id:`${r.id}--parent-reference--${R.ReferencedEntityNotFound}`,message:`The entity with id '${t}' that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,severity:D.Error,code:R.ReferencedEntityNotFound,issue:null}));else{const l=i.properties.filter(o=>o.name===r.name);l.length&&e.push(new w({id:`${r.id}--${j.NameNotUniqueInScope}`,message:`Entity with id "${r.id}" and type "${r.type}" has a name "${r.name}" that is not unique among all properties in the parent entity. Entity with id "${l[0].id}" has the same name.
40
40
  Please provide a unique 'name' string.`,severity:D.Error,code:j.NameNotUniqueInScope,issue:null}))}}return e}function Rc(r,a){const e=[];r.name||e.push(new w({id:`${r.id}--${j.EmptyName}`,message:`Entity with id "${r.id}" and type "${r.type}" has an empty name. Please provide a 'name' string.`,severity:D.Error,code:j.EmptyName,issue:null}));const t=_(r.parent);if(!t)e.push(new w({id:`${r.id}--parent-reference--${R.InvalidReferenceObjectStructure}`,message:`Reference object at 'parent' property for entity with id "${r.id}" and type "${r.type}" is not a valid reference. A reference needs to be a 'id' string of an existing entity in the project.`,severity:D.Error,code:R.InvalidReferenceObjectStructure,issue:null}));else{const i=a.get(t);if(!i)e.push(new w({id:`${r.id}--parent-reference--${R.ReferencedEntityNotFound}`,message:`The entity with id '${t}' that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,severity:D.Error,code:R.ReferencedEntityNotFound,issue:null}));else{const l=Yc(i).filter(o=>o.name===r.name);l.length&&e.push(new w({id:`${r.id}--${j.NameNotUniqueInScope}`,message:`Entity with id "${r.id}" and type "${r.type}" has a name "${r.name}" that is not unique among all inputs declared in the parent entity. Entity with id "${l[0].id}" has the same name.
41
41
  Please provide a unique 'name' string.`,severity:D.Error,code:j.NameNotUniqueInScope,issue:null}))}}return e}function Dc(r,a){const e=[];r.name||e.push(new w({id:`${r.id}--${j.EmptyName}`,message:`Entity with id "${r.id}" and type "${r.type}" has an empty name. Please provide a 'name' string.`,severity:D.Error,code:j.EmptyName,issue:null}));const t=_(r.parent);if(!t)e.push(new w({id:`${r.id}--parent-reference--${R.InvalidReferenceObjectStructure}`,message:`Reference object at 'parent' property for entity with id "${r.id}" and type "${r.type}" is not a valid reference. A reference needs to be a 'id' string of an existing entity in the project.`,severity:D.Error,code:R.InvalidReferenceObjectStructure,issue:null}));else{const i=a.get(t);if(!i)e.push(new w({id:`${r.id}--parent-reference--${R.ReferencedEntityNotFound}`,message:`The entity with id '${t}' that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,severity:D.Error,code:R.ReferencedEntityNotFound,issue:null}));else{const l=SP(i).filter(o=>o.name===r.name);l.length&&e.push(new w({id:`${r.id}--${j.NameNotUniqueInScope}`,message:`Entity with id "${r.id}" and type "${r.type}" has a name "${r.name}" that is not unique among all outputs declared in the parent entity. Entity with id "${l[0].id}" has the same name.
42
- Please provide a unique 'name' string.`,severity:D.Error,code:j.NameNotUniqueInScope,issue:null}))}}return e}function fq(r,a){switch(r.type){case n.DefinitionEntity:return Ic(r,a);case n.FunctionDeclaration:return Ec(r,a);case n.VariableDeclaration:return Ac(r,a);case n.Property:return bc(r,a);case n.ArgumentDeclaration:return Rc(r,a);case n.ReturnDeclaration:return Dc(r,a);default:return[]}}function XO(r,a,e){const i=`${Nl(r)}-${a}-id`;return e.instances[i]?m.UUID.uuid():i}function Oc(r,a){let e="",t=null;if(r.parent){const s=a.get(r.parent);s&&(t=s)}let i="";return t&&(i=`${Nl(x(t,a))}-`),e=`${i}${Nl(x(r,a))}-id`,a.instances[e]?m.UUID.uuid():e}function ht(r,a,e="uuid"){return e==="semantic"?XO(x(r,a),r.type,a):m.UUID.uuid()}function QO(r){var l;const a=S3(),e=r.toJSON();a.safeParse(e).success;const i=e1(r);(l=r.dataType)==null||l.validate();const s=[...i];if(r.id==="80c86e1b-caca-4ba5-9b1f-38f72d10e4a3"){const o=de({id:`${r.id}--${F.PropertyImplementsNonAbstact}`,message:`Property "${x(r,r.project)}" with id "${r.id}" implements a non-abstract property "${x(r,r.project)}" with id "${r.id}".`,issue:null,severity:D.Error,code:F.PropertyImplementsNonAbstact,entity:r});s.push(o.error)}return s}function e1(r){const a=[];if(!r.implements)return a;const e=r.implements;if(!e.abstract){const i=de({id:`${r.id}--${F.PropertyImplementsNonAbstact}`,message:`Property "${x(r,r.project)}" with id "${r.id}" implements a non-abstract property "${x(e,r.project)}" with id "${e.id}".`,issue:null,severity:D.Error,code:F.PropertyImplementsNonAbstact,entity:r});a.push(i.error)}if(r.static&&!e.static){const i=de({id:`${r.id}--${F.NonStaticPropertyImplementsStatic}`,message:`Static property "${x(r,r.project)}" with id "${r.id}" implements a non-static property "${x(e,r.project)}" with id "${e.id}".`,issue:null,severity:D.Error,code:F.NonStaticPropertyImplementsStatic,entity:r});a.push(i.error)}if(!r.static&&e.static){const i=de({id:`${r.id}--${F.StaticPropertyImplementsNonStatic}`,message:`Non-static property "${x(r,r.project)}" with id "${r.id}" implements a static property "${x(e,r.project)}" with id "${e.id}".`,issue:null,severity:D.Error,code:F.StaticPropertyImplementsNonStatic,entity:r});a.push(i.error)}if(!Ri(r.dataType,e.dataType)){const i=de({id:`${r.id}--${F.PropertyImplementsIncompatibleType}`,message:`Property "${x(r,r.project)}" with id "${r.id}" implements a property "${x(e,r.project)}" with id "${e.id}" that has an incompatible data type.`,issue:null,severity:D.Error,code:F.PropertyImplementsIncompatibleType,entity:r});a.push(i.error)}return He(r.errors,a)}const yq=Object.freeze(Object.defineProperty({__proto__:null,validate:QO,validateImplementation:e1},Symbol.toStringTag,{value:"Module"}));function hq(r,a){const e=[];if(r.parent){const i=a.get(r.parent);if(!i)e.push(new w({id:`${r.id}--${r.parent}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", is referencing an entity with id "${r.parent}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}));else{const s=rn(i);if(s){const l=i!==s?`The entity of type '${r.type}' with id '${r.id}' have 'parent' with id '${r.parent}' because the entity belongs to a built-in '${s.type}' entity with id '${s.id}' (${x(s,i.project)}) higher up in the tree.`:`The entity of type '${r.type}' with id '${r.id}' have 'parent' with id '${r.parent}' because it is a built-in entity of type ${s.type}.`;e.push(new w({id:`${r.id}--${R.InvalidBuiltInEntityReference}`,code:R.InvalidBuiltInEntityReference,severity:D.Error,message:l,issue:null}))}else if(![n.DefinitionEntity].includes(i.type))e.push(new w({id:`${r.id}--${r.parent}--${R.InvalidParentReference}`,code:R.InvalidParentReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a parent reference that isn't pointing to an entity of type 'definition-entity'.`,issue:null}));else{const o=kt(i).filter(d=>!d.interactive);if(o.length){let d=o.length>1?`The entity of type '${r.type}' with id '${r.id}' can't be added to the 'parent' entity with id '${i.id}' because it extends or implements multiple '${n.BuiltInBaseEntity}' entities that are non-interactive ("${ne(o.map(u=>x(u,u.project)),'", "','" and "')}").`:`The entity of type '${r.type}' with id '${r.id}' can't be added to the 'parent' entity with id '${i.id}' because it extends or implements a '${n.BuiltInBaseEntity}' entity that is non-interactive ("${x(o[0],o[0].project)}").`;d+=`
43
- ${Qr}`,e.push(new w({id:`${r.id}--${R.NonInteractiveEntityReferenced}`,code:R.NonInteractiveEntityReferenced,severity:D.Error,message:d,issue:null}))}else if(r.implements){const d=a.get(r.implements);if(r.id===r.implements)return e.push(new w({id:`${r.id}--${r.implements}--${R.SelfReference}`,code:R.SelfReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a reference to itself at 'implements'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null})),e;if(!d)e.push(new w({id:`${r.id}--${r.implements}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", is referencing an entity with id "${r.implements}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}));else{const u=i.properties.find(y=>{var c;return((c=y.implements)==null?void 0:c.id)===r.implements});u?e.push(new w({id:`${r.id}--${j.PropertyOverwritesOtherSiblingWithSameImplementation}`,code:j.PropertyOverwritesOtherSiblingWithSameImplementation,severity:D.Error,message:`The property with id "${r.id}" is trying to implement the property with id "${r.implements}", but the parent entity already has a property with id '${u.id}' that implements the same base property.`,issue:null})):[n.Property].includes(d.type)?d.abstract||e.push(new w({id:`${r.id}--${r.implements}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has an 'implements' reference that isn't pointing to an abstract entity.`,issue:null})):e.push(new w({id:`${r.id}--${r.implements}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has an 'implements' reference that isn't pointing to an entity of type 'property'.`,issue:null}))}}}}}const t=At(r,{},a);return e.push(...t.errors),e}class at{constructor(a){f(this,"version");f(this,"previousVersion",null);f(this,"createdAt");f(this,"deleted",!1);f(this,"author");this.version=a.version,this.previousVersion=a.previousVersion,this.createdAt=T(a.createdAt).toISOString(),this.deleted=a.deleted,this.author=a.author}metaSync(a){this.deleted=a.deleted!==void 0?a.deleted:this.deleted}}var Pc=(r=>(r.Manual="manual",r.Automatic="automatic",r))(Pc||{}),A=(r=>(r.Added="added",r.Updated="updated",r.Removed="removed",r.Affected="affected",r))(A||{});class b{constructor(a,e,t,i,s=!1,l=""){f(this,"id",m.UUID.uuid());f(this,"seenEntities",[]);f(this,"added",{});f(this,"updated",{});f(this,"removed",{});f(this,"affected",{});f(this,"self",null);f(this,"author");f(this,"timestamp");f(this,"open",!0);f(this,"dirty",!0);f(this,"type","manual");f(this,"autoclose",!1);f(this,"autoCloseActionName","");f(this,"project");if(this.project=a,this.author=e||m.sessionAuthor||"",this.timestamp=t,this.self=i,this.autoclose=s,this.autoCloseActionName=l,this.autoclose&&!this.autoCloseActionName)throw new Error("Auto-close change-set must have an auto-close action name.")}get isEmpty(){return Object.keys(this.added).length===0&&Object.keys(this.updated).length===0&&Object.keys(this.removed).length===0}get isValid(){var a;return!(this.isEmpty&&this.self&&!this.affected[(a=this.self)==null?void 0:a.id])}get list(){return[...Object.values(this.added),...Object.values(this.updated),...Object.values(this.removed)]}get listAdded(){return Object.values(this.added)}get listUpdated(){return Object.values(this.updated)}get listRemoved(){return Object.values(this.removed)}get listAffected(){return Object.values(this.affected)}get addedIds(){return Object.keys(this.added)}get updatedIds(){return Object.keys(this.updated)}get removedIds(){return Object.keys(this.removed)}get affectedIds(){return Object.keys(this.affected)}discardOrphans(){const a=[...this.addedIds,...this.updatedIds],e=this.project.toFlatIds(),t=_i(),i=e.filter(l=>!t.includes(l));a.filter(l=>!i.includes(l)).forEach(l=>{this.remove(l)})}captureAllChangesInVersionInstances(){[...this.addedIds,...this.updatedIds].forEach(e=>{const t=this.project.get(e);if(!t)throw new Error(`Entity with id "${e}" not found in the project state when capturing version for change-set.`);const i=this.get(e);t.version===i.version&&t.captureVersion()}),this.removedIds.forEach(e=>{const t=this.project.getDeleted(e);if(!t)throw new Error(`Entity with id "${e}" not found in the project state when capturing version for change-set.`);const i=this.get(e);t.version===i.version&&t.captureVersion()})}async attemptAutocloseAsync(a,e){var t;return this.autoclose&&this.autoCloseActionName&&this.autoCloseActionName===a&&(this.self&&e===((t=this.self)==null?void 0:t.id)||!this.self)&&await this.closeAsync(),this}async closeAsync(){return!this.isValid&&this.self&&!this.added[this.self.id]&&!this.updated[this.self.id]&&this.removed[this.self.id],this.discardOrphans(),this.recursiveCaptureUpstreamVersions(),this.captureAllChangesInVersionInstances(),this.recursiveCaptureUpstreamVersions(),this.open=!1,this.isEmpty?(console.warn(`Empty change-set (${this.id}) discarded upon closing.`),this.project.discardChangeSet(this),this):(await this.project.closeChangeSet(this),this)}attemptAutoclose(a,e){var t;return this.autoclose&&this.autoCloseActionName&&this.autoCloseActionName===a&&(this.self&&e===((t=this.self)==null?void 0:t.id)||!this.self)&&this.close(),this}recursiveCaptureUpstreamVersions(){[...this.addedIds,...this.updatedIds,...this.removedIds].forEach(e=>{const t=this.get(e),{added:i,updated:s,removed:l,affected:o}=t.recursiveCaptureUpstreamVersions(this.timestamp);for(const d of i)this.add(d,"added");for(const d of s)this.add(d,"updated");for(const d of l)this.add(d,"removed");for(const d of o)this.add(d,"affected")})}close(){if(!this.isValid&&this.self&&!this.added[this.self.id]&&!this.updated[this.self.id]&&this.removed[this.self.id],this.discardOrphans(),this.captureAllChangesInVersionInstances(),this.recursiveCaptureUpstreamVersions(),this.captureAllChangesInVersionInstances(),this.open=!1,this.isEmpty)return console.warn(`Empty change-set (${this.id}) discarded upon closing.`),this.project.discardChangeSet(this),this;if(this.added[this.project.id]&&this.updatedIds.length)throw new Error("No 'updated' entities should be present in the change-set when the project entity is in the 'added' list. New projects can only have newly added entities");if(this.added[this.project.id]&&this.removedIds.length)throw new Error("No 'removed' entities should be present in the change-set when the project entity is in the 'added' list. New projects can only have newly added entities");if(!this.updated[this.project.id]&&!this.added[this.project.id])throw new Error("Change-set must also have the project entity as 'updated' or 'added'. All changes must propagate upstream until the root project entity.");return this.project.closeChangeSet(this),this}get(a){return this.added[a]?this.added[a]:this.updated[a]?this.updated[a]:this.removed[a]?this.removed[a]:null}remove(a){return this.has(a)&&(delete this.added[a],delete this.updated[a],delete this.removed[a],delete this.affected[a],this.seenEntities=this.seenEntities.filter(e=>e!==a)),this}add(a,e){var l,o,d;if(!this.open||!this.dirty)return this;const t=Array.from(new Set([...this.project.getAllBuiltInIds(),..._i()]));if(t.includes(a.id))return this;if(!id(a,{...this.project.instances,...this.project.builtInInstances}).every(u=>!t.includes(u)))return this;if(this.seenEntities.indexOf(a.id)===-1&&this.seenEntities.push(a.id),(e==="updated"||e==="removed")&&!this.has(a.id)){a.increaseVersion(this.timestamp);const{added:u,updated:y,removed:c,affected:I}=a.recursiveCaptureUpstreamVersions(this.timestamp);for(const E of u)this.add(E,"added");for(const E of y)this.add(E,"updated");for(const E of c)this.add(E,"removed");for(const E of I)this.add(E,"affected")}if(e==="added"&&!this.has(a.id)){const{added:u,updated:y,removed:c,affected:I}=a.recursiveCaptureUpstreamVersions(this.timestamp);for(const E of u)this.add(E,"added");for(const E of y)this.add(E,"updated");for(const E of c)this.add(E,"removed");for(const E of I)this.add(E,"affected")}if(e==="removed"){if(this.added[a.id])return delete this.added[a.id],this.seenEntities=this.seenEntities.filter(y=>y!==a.id),delete this.project.deletedInstances[a.id],this;this.updated[a.id]&&delete this.updated[a.id],this.affected[a.id]&&delete this.affected[a.id],a.captureVersion();const u=(l=a.knownVersions)==null?void 0:l.get(a.version);if(!u)throw Error(`Version ${a.version} should have a cached version instance but it wasn't found when adding entity to change-set`);this.removed[a.id]=u}if(e==="added"){if(this.removed[a.id])return this;this.updated[a.id]&&delete this.updated[a.id],this.affected[a.id]&&delete this.affected[a.id],a.captureVersion();const u=(o=a.knownVersions)==null?void 0:o.get(a.version);if(!u)throw Error(`Version ${a.version} should have a cached version instance but it wasn't found when adding entity to change-set`);this.added[a.id]=u}if(e==="updated"){if(this.removed[a.id])return this;if(this.added[a.id])return this;this.affected[a.id]&&delete this.affected[a.id],a.captureVersion();const u=(d=a.knownVersions)==null?void 0:d.get(a.version);if(!u)throw Error(`Version ${a.version} should have a cached version instance but it wasn't found when adding entity to change-set`);this.updated[a.id]=u}if(e==="affected"){if(this.removed[a.id])return this;if(this.added[a.id])return this;if(this.updated[a.id])return this;this.affected[a.id]=a}return this}toJSON(){const a={},e={},t={},i=new Set;for(const s of Object.values(this.added))a[s.id]=s.toShallowJSON();for(const s of Object.values(this.updated))e[s.id]=s.toShallowJSON();for(const s of Object.values(this.removed))t[s.id]=s.toShallowJSON();for(const s of Object.values(this.affected))i.add(s.id);return{added:a,updated:e,removed:t,affected:Array.from(i),self:this.self?this.self.toShallowJSON():null,seenEntities:this.seenEntities}}has(a){return!!this.added[a]||!!this.removed[a]||!!this.updated[a]||!!this.affected[a]}hasAdded(a){return!!this.added[a]}hasUpdated(a){return!!this.updated[a]}hasRemoved(a){return!!this.removed[a]}hasAffected(a){return!!this.affected[a]}}function mq(r){return new Set([...Object.keys(r.added),...Object.keys(r.updated),...Object.keys(r.removed),...Array.from(r.affected)])}var t1=(r=>(r.Implements="implements",r.DataTypeEntity="data-type-entity",r))(t1||{});const Ae=class Ae extends at{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"private");f(this,"abstract");f(this,"index");f(this,"static");f(this,"required");f(this,"constant",!1);f(this,"type",n.Property);f(this,"hidden",!1);f(this,"defaultValue",null);f(this,"dataType",null);f(this,"implements",null);f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description,this.private=e.private,this.abstract=e.abstract,this.index=e.index,this.static=e.static,this.required=e.required||!1,this.hidden=e.hidden||!1,this.constant=e.constant||!1}static new(){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Property,name:"",description:"",dataType:null,implements:null,private:!1,abstract:!1,static:!1,constant:!1,hidden:!1,index:0,required:!1,defaultValue:null,parent:null}}static fromGenerationTarget(e,t){const i=_(e.parent),s=t.get(i);let l=null;if(e.implements){const u=_(e.implements);l=t.get(u)}const o={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,type:n.Property,index:s.properties.length,private:e.private||!1,abstract:e.abstract||!1,static:e.static||!1,required:e.required||!1,constant:e.constant||!1,hidden:!1,description:e.description,defaultValue:null,implements:l,dataType:null,parent:s},d=C(o,t);return d.setParent(s,null),d.initChildren(null),d}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=hq(i,t),o=bc(i,t);return s.push(...l,...o,...ut(i)),{errors:s,modifiedData:i}}get isExtendedProperty(){const e=this.parent.allBasePropertiesFromExtendedAndImplementedEntities.find(t=>t.name===this.name);return!!e&&e.id!==this.id&&!e.abstract}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated, as it would mean moving the '${this.type}' entity to another parent entity.
42
+ Please provide a unique 'name' string.`,severity:D.Error,code:j.NameNotUniqueInScope,issue:null}))}}return e}function f7(r,a){switch(r.type){case n.DefinitionEntity:return Ic(r,a);case n.FunctionDeclaration:return Ec(r,a);case n.VariableDeclaration:return Ac(r,a);case n.Property:return bc(r,a);case n.ArgumentDeclaration:return Rc(r,a);case n.ReturnDeclaration:return Dc(r,a);default:return[]}}function XO(r,a,e){const i=`${Nl(r)}-${a}-id`;return e.instances[i]?m.UUID.uuid():i}function Oc(r,a){let e="",t=null;if(r.parent){const s=a.get(r.parent);s&&(t=s)}let i="";return t&&(i=`${Nl(x(t,a))}-`),e=`${i}${Nl(x(r,a))}-id`,a.instances[e]?m.UUID.uuid():e}function ht(r,a,e="uuid"){return e==="semantic"?XO(x(r,a),r.type,a):m.UUID.uuid()}function QO(r){var l;const a=S3(),e=r.toJSON();a.safeParse(e).success;const i=e1(r);(l=r.dataType)==null||l.validate();const s=[...i];if(r.id==="80c86e1b-caca-4ba5-9b1f-38f72d10e4a3"){const o=de({id:`${r.id}--${F.PropertyImplementsNonAbstact}`,message:`Property "${x(r,r.project)}" with id "${r.id}" implements a non-abstract property "${x(r,r.project)}" with id "${r.id}".`,issue:null,severity:D.Error,code:F.PropertyImplementsNonAbstact,entity:r});s.push(o.error)}return s}function e1(r){const a=[];if(!r.implements)return a;const e=r.implements;if(!e.abstract){const i=de({id:`${r.id}--${F.PropertyImplementsNonAbstact}`,message:`Property "${x(r,r.project)}" with id "${r.id}" implements a non-abstract property "${x(e,r.project)}" with id "${e.id}".`,issue:null,severity:D.Error,code:F.PropertyImplementsNonAbstact,entity:r});a.push(i.error)}if(r.static&&!e.static){const i=de({id:`${r.id}--${F.NonStaticPropertyImplementsStatic}`,message:`Static property "${x(r,r.project)}" with id "${r.id}" implements a non-static property "${x(e,r.project)}" with id "${e.id}".`,issue:null,severity:D.Error,code:F.NonStaticPropertyImplementsStatic,entity:r});a.push(i.error)}if(!r.static&&e.static){const i=de({id:`${r.id}--${F.StaticPropertyImplementsNonStatic}`,message:`Non-static property "${x(r,r.project)}" with id "${r.id}" implements a static property "${x(e,r.project)}" with id "${e.id}".`,issue:null,severity:D.Error,code:F.StaticPropertyImplementsNonStatic,entity:r});a.push(i.error)}if(!Ri(r.dataType,e.dataType)){const i=de({id:`${r.id}--${F.PropertyImplementsIncompatibleType}`,message:`Property "${x(r,r.project)}" with id "${r.id}" implements a property "${x(e,r.project)}" with id "${e.id}" that has an incompatible data type.`,issue:null,severity:D.Error,code:F.PropertyImplementsIncompatibleType,entity:r});a.push(i.error)}return He(r.errors,a)}const y7=Object.freeze(Object.defineProperty({__proto__:null,validate:QO,validateImplementation:e1},Symbol.toStringTag,{value:"Module"}));function h7(r,a){const e=[];if(r.parent){const i=a.get(r.parent);if(!i)e.push(new w({id:`${r.id}--${r.parent}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", is referencing an entity with id "${r.parent}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}));else{const s=rn(i);if(s){const l=i!==s?`The entity of type '${r.type}' with id '${r.id}' have 'parent' with id '${r.parent}' because the entity belongs to a built-in '${s.type}' entity with id '${s.id}' (${x(s,i.project)}) higher up in the tree.`:`The entity of type '${r.type}' with id '${r.id}' have 'parent' with id '${r.parent}' because it is a built-in entity of type ${s.type}.`;e.push(new w({id:`${r.id}--${R.InvalidBuiltInEntityReference}`,code:R.InvalidBuiltInEntityReference,severity:D.Error,message:l,issue:null}))}else if(![n.DefinitionEntity].includes(i.type))e.push(new w({id:`${r.id}--${r.parent}--${R.InvalidParentReference}`,code:R.InvalidParentReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a parent reference that isn't pointing to an entity of type 'definition-entity'.`,issue:null}));else{const o=kt(i).filter(d=>!d.interactive);if(o.length){let d=o.length>1?`The entity of type '${r.type}' with id '${r.id}' can't be added to the 'parent' entity with id '${i.id}' because it extends or implements multiple '${n.BuiltInBaseEntity}' entities that are non-interactive ("${ne(o.map(u=>x(u,u.project)),'", "','" and "')}").`:`The entity of type '${r.type}' with id '${r.id}' can't be added to the 'parent' entity with id '${i.id}' because it extends or implements a '${n.BuiltInBaseEntity}' entity that is non-interactive ("${x(o[0],o[0].project)}").`;d+=`
43
+ ${Qr}`,e.push(new w({id:`${r.id}--${R.NonInteractiveEntityReferenced}`,code:R.NonInteractiveEntityReferenced,severity:D.Error,message:d,issue:null}))}else if(r.implements){const d=a.get(r.implements);if(r.id===r.implements)return e.push(new w({id:`${r.id}--${r.implements}--${R.SelfReference}`,code:R.SelfReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a reference to itself at 'implements'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null})),e;if(!d)e.push(new w({id:`${r.id}--${r.implements}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", is referencing an entity with id "${r.implements}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}));else{const u=i.properties.find(y=>{var c;return((c=y.implements)==null?void 0:c.id)===r.implements});u?e.push(new w({id:`${r.id}--${j.PropertyOverwritesOtherSiblingWithSameImplementation}`,code:j.PropertyOverwritesOtherSiblingWithSameImplementation,severity:D.Error,message:`The property with id "${r.id}" is trying to implement the property with id "${r.implements}", but the parent entity already has a property with id '${u.id}' that implements the same base property.`,issue:null})):[n.Property].includes(d.type)?d.abstract||e.push(new w({id:`${r.id}--${r.implements}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has an 'implements' reference that isn't pointing to an abstract entity.`,issue:null})):e.push(new w({id:`${r.id}--${r.implements}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has an 'implements' reference that isn't pointing to an entity of type 'property'.`,issue:null}))}}}}}const t=At(r,{},a);return e.push(...t.errors),e}class at{constructor(a){f(this,"version");f(this,"previousVersion",null);f(this,"createdAt");f(this,"deleted",!1);f(this,"author");this.version=a.version,this.previousVersion=a.previousVersion,this.createdAt=T(a.createdAt).toISOString(),this.deleted=a.deleted,this.author=a.author}metaSync(a){this.deleted=a.deleted!==void 0?a.deleted:this.deleted}}var Pc=(r=>(r.Manual="manual",r.Automatic="automatic",r))(Pc||{}),A=(r=>(r.Added="added",r.Updated="updated",r.Removed="removed",r.Affected="affected",r))(A||{});class b{constructor(a,e,t,i,s=!1,l=""){f(this,"id",m.UUID.uuid());f(this,"seenEntities",[]);f(this,"added",{});f(this,"updated",{});f(this,"removed",{});f(this,"affected",{});f(this,"self",null);f(this,"author");f(this,"timestamp");f(this,"open",!0);f(this,"dirty",!0);f(this,"type","manual");f(this,"autoclose",!1);f(this,"autoCloseActionName","");f(this,"project");if(this.project=a,this.author=e||m.sessionAuthor||"",this.timestamp=t,this.self=i,this.autoclose=s,this.autoCloseActionName=l,this.autoclose&&!this.autoCloseActionName)throw new Error("Auto-close change-set must have an auto-close action name.")}get isEmpty(){return Object.keys(this.added).length===0&&Object.keys(this.updated).length===0&&Object.keys(this.removed).length===0}get isValid(){var a;return!(this.isEmpty&&this.self&&!this.affected[(a=this.self)==null?void 0:a.id])}get list(){return[...Object.values(this.added),...Object.values(this.updated),...Object.values(this.removed)]}get listAdded(){return Object.values(this.added)}get listUpdated(){return Object.values(this.updated)}get listRemoved(){return Object.values(this.removed)}get listAffected(){return Object.values(this.affected)}get addedIds(){return Object.keys(this.added)}get updatedIds(){return Object.keys(this.updated)}get removedIds(){return Object.keys(this.removed)}get affectedIds(){return Object.keys(this.affected)}discardOrphans(){const a=[...this.addedIds,...this.updatedIds],e=this.project.toFlatIds(),t=_i(),i=e.filter(l=>!t.includes(l));a.filter(l=>!i.includes(l)).forEach(l=>{this.remove(l)})}captureAllChangesInVersionInstances(){[...this.addedIds,...this.updatedIds].forEach(e=>{const t=this.project.get(e);if(!t)throw new Error(`Entity with id "${e}" not found in the project state when capturing version for change-set.`);const i=this.get(e);t.version===i.version&&t.captureVersion()}),this.removedIds.forEach(e=>{const t=this.project.getDeleted(e);if(!t)throw new Error(`Entity with id "${e}" not found in the project state when capturing version for change-set.`);const i=this.get(e);t.version===i.version&&t.captureVersion()})}async attemptAutocloseAsync(a,e){var t;return this.autoclose&&this.autoCloseActionName&&this.autoCloseActionName===a&&(this.self&&e===((t=this.self)==null?void 0:t.id)||!this.self)&&await this.closeAsync(),this}async closeAsync(){return!this.isValid&&this.self&&!this.added[this.self.id]&&!this.updated[this.self.id]&&this.removed[this.self.id],this.discardOrphans(),this.recursiveCaptureUpstreamVersions(),this.captureAllChangesInVersionInstances(),this.recursiveCaptureUpstreamVersions(),this.open=!1,this.isEmpty?(console.warn(`Empty change-set (${this.id}) discarded upon closing.`),this.project.discardChangeSet(this),this):(await this.project.closeChangeSet(this),this)}attemptAutoclose(a,e){var t;return this.autoclose&&this.autoCloseActionName&&this.autoCloseActionName===a&&(this.self&&e===((t=this.self)==null?void 0:t.id)||!this.self)&&this.close(),this}recursiveCaptureUpstreamVersions(){[...this.addedIds,...this.updatedIds,...this.removedIds].forEach(e=>{const t=this.get(e),{added:i,updated:s,removed:l,affected:o}=t.recursiveCaptureUpstreamVersions(this.timestamp);for(const d of i)this.add(d,"added");for(const d of s)this.add(d,"updated");for(const d of l)this.add(d,"removed");for(const d of o)this.add(d,"affected")})}close(){if(!this.isValid&&this.self&&!this.added[this.self.id]&&!this.updated[this.self.id]&&this.removed[this.self.id],this.discardOrphans(),this.captureAllChangesInVersionInstances(),this.recursiveCaptureUpstreamVersions(),this.captureAllChangesInVersionInstances(),this.open=!1,this.isEmpty)return console.warn(`Empty change-set (${this.id}) discarded upon closing.`),this.project.discardChangeSet(this),this;if(this.added[this.project.id]&&this.updatedIds.length)throw new Error("No 'updated' entities should be present in the change-set when the project entity is in the 'added' list. New projects can only have newly added entities");if(this.added[this.project.id]&&this.removedIds.length)throw new Error("No 'removed' entities should be present in the change-set when the project entity is in the 'added' list. New projects can only have newly added entities");if(!this.updated[this.project.id]&&!this.added[this.project.id])throw new Error("Change-set must also have the project entity as 'updated' or 'added'. All changes must propagate upstream until the root project entity.");return this.project.closeChangeSet(this),this}get(a){return this.added[a]?this.added[a]:this.updated[a]?this.updated[a]:this.removed[a]?this.removed[a]:null}remove(a){return this.has(a)&&(delete this.added[a],delete this.updated[a],delete this.removed[a],delete this.affected[a],this.seenEntities=this.seenEntities.filter(e=>e!==a)),this}add(a,e){var l,o,d;if(!this.open||!this.dirty)return this;const t=Array.from(new Set([...this.project.getAllBuiltInIds(),..._i()]));if(t.includes(a.id))return this;if(!id(a,{...this.project.instances,...this.project.builtInInstances}).every(u=>!t.includes(u)))return this;if(this.seenEntities.indexOf(a.id)===-1&&this.seenEntities.push(a.id),(e==="updated"||e==="removed")&&!this.has(a.id)){a.increaseVersion(this.timestamp);const{added:u,updated:y,removed:c,affected:I}=a.recursiveCaptureUpstreamVersions(this.timestamp);for(const E of u)this.add(E,"added");for(const E of y)this.add(E,"updated");for(const E of c)this.add(E,"removed");for(const E of I)this.add(E,"affected")}if(e==="added"&&!this.has(a.id)){const{added:u,updated:y,removed:c,affected:I}=a.recursiveCaptureUpstreamVersions(this.timestamp);for(const E of u)this.add(E,"added");for(const E of y)this.add(E,"updated");for(const E of c)this.add(E,"removed");for(const E of I)this.add(E,"affected")}if(e==="removed"){if(this.added[a.id])return delete this.added[a.id],this.seenEntities=this.seenEntities.filter(y=>y!==a.id),delete this.project.deletedInstances[a.id],this;this.updated[a.id]&&delete this.updated[a.id],this.affected[a.id]&&delete this.affected[a.id],a.captureVersion();const u=(l=a.knownVersions)==null?void 0:l.get(a.version);if(!u)throw Error(`Version ${a.version} should have a cached version instance but it wasn't found when adding entity to change-set`);this.removed[a.id]=u}if(e==="added"){if(this.removed[a.id])return this;this.updated[a.id]&&delete this.updated[a.id],this.affected[a.id]&&delete this.affected[a.id],a.captureVersion();const u=(o=a.knownVersions)==null?void 0:o.get(a.version);if(!u)throw Error(`Version ${a.version} should have a cached version instance but it wasn't found when adding entity to change-set`);this.added[a.id]=u}if(e==="updated"){if(this.removed[a.id])return this;if(this.added[a.id])return this;this.affected[a.id]&&delete this.affected[a.id],a.captureVersion();const u=(d=a.knownVersions)==null?void 0:d.get(a.version);if(!u)throw Error(`Version ${a.version} should have a cached version instance but it wasn't found when adding entity to change-set`);this.updated[a.id]=u}if(e==="affected"){if(this.removed[a.id])return this;if(this.added[a.id])return this;if(this.updated[a.id])return this;this.affected[a.id]=a}return this}toJSON(){const a={},e={},t={},i=new Set;for(const s of Object.values(this.added))a[s.id]=s.toShallowJSON();for(const s of Object.values(this.updated))e[s.id]=s.toShallowJSON();for(const s of Object.values(this.removed))t[s.id]=s.toShallowJSON();for(const s of Object.values(this.affected))i.add(s.id);return{added:a,updated:e,removed:t,affected:Array.from(i),self:this.self?this.self.toShallowJSON():null,seenEntities:this.seenEntities}}has(a){return!!this.added[a]||!!this.removed[a]||!!this.updated[a]||!!this.affected[a]}hasAdded(a){return!!this.added[a]}hasUpdated(a){return!!this.updated[a]}hasRemoved(a){return!!this.removed[a]}hasAffected(a){return!!this.affected[a]}}function m7(r){return new Set([...Object.keys(r.added),...Object.keys(r.updated),...Object.keys(r.removed),...Array.from(r.affected)])}var t1=(r=>(r.Implements="implements",r.DataTypeEntity="data-type-entity",r))(t1||{});const Ae=class Ae extends at{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"private");f(this,"abstract");f(this,"index");f(this,"static");f(this,"required");f(this,"constant",!1);f(this,"type",n.Property);f(this,"hidden",!1);f(this,"defaultValue",null);f(this,"dataType",null);f(this,"implements",null);f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description,this.private=e.private,this.abstract=e.abstract,this.index=e.index,this.static=e.static,this.required=e.required||!1,this.hidden=e.hidden||!1,this.constant=e.constant||!1}static new(){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Property,name:"",description:"",dataType:null,implements:null,private:!1,abstract:!1,static:!1,constant:!1,hidden:!1,index:0,required:!1,defaultValue:null,parent:null}}static fromGenerationTarget(e,t){const i=_(e.parent),s=t.get(i);let l=null;if(e.implements){const u=_(e.implements);l=t.get(u)}const o={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,type:n.Property,index:s.properties.length,private:e.private||!1,abstract:e.abstract||!1,static:e.static||!1,required:e.required||!1,constant:e.constant||!1,hidden:!1,description:e.description,defaultValue:null,implements:l,dataType:null,parent:s},d=C(o,t);return d.setParent(s,null),d.initChildren(null),d}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=h7(i,t),o=bc(i,t);return s.push(...l,...o,...ut(i)),{errors:s,modifiedData:i}}get isExtendedProperty(){const e=this.parent.allBasePropertiesFromExtendedAndImplementedEntities.find(t=>t.name===this.name);return!!e&&e.id!==this.id&&!e.abstract}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated, as it would mean moving the '${this.type}' entity to another parent entity.
44
44
  This is likely an incorrect strategy, either the '${this.type}' entity doesn't need to be updated or it should be deleted and a new one created in the desired parent.`,issue:null})),(e.readsValue||e.writesValue)&&t.push(new w({id:`${this.id}--${j.InvalidObjectStructure}`,code:j.InvalidObjectStructure,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' is not a value reading or writing entity.
45
- ${Fl}`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],i=[],s=[];return Object.values(this.detachedDependents).forEach(l=>{const o=l.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),i.push(...o.removed),s.push(...o.affected)}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];return t==="implements"&&(this.setImplements(null,i),s.push(this)),{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];return t==="implements"&&(this.setImplements(e,i),s.push(this)),{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e,t,i,s,l;return(t=(e=this.implements)==null?void 0:e.subscribeDependents)==null||t.call(e,[{entity:this,field:"implements"}]),(l=(s=(i=this.dataType)==null?void 0:i.entity)==null?void 0:s.subscribeDependents)==null||l.call(s,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ae(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.defaultValue=this.defaultValue,e.dataType=this.dataType,e.implements=this.implements,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent&&this.parent.type!==n.PrimitiveEntity&&this.parent.type!==n.BuiltInBaseEntity){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[I,E]of c.knownVersions)u.set(I,E);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ae(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.defaultValue=o.defaultValue,this.dataType=o.dataType,this.implements=o.implements,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${xt(this.type)} with id '${this.id}' has a parent reference "${l}" which is missing in the project`)}else throw new Error(`${xt(this.type)} with id '${this.id}' is missing a parent reference`);if(this.initialData.implements){const l=_(this.initialData.implements),o=this.project.get(l);o&&(this.setImplements(o,null),e.push(o))}return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.parent.addProperty(this),t.push(this.parent),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setImplements(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-implements"))){var i;return((i=this.implements)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.implements=e,t&&(t==null||t.add(this,A.Updated),t==null||t.attemptAutoclose("set-implements",this.id))),this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=C(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),this.initialData.dataType){const t=C(this.initialData.dataType,this.project);t.setParent(this,null),t.initChildren(e),this.dataType=t}if(this.initialData.implements){const t=C(this.initialData.implements,this.project);this.setImplements(t,null)}return this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.name=e.name||s.name,this.description=e.description||s.description,this.abstract=e.abstract!==void 0?e.abstract:s.abstract,this.private=e.private!==void 0?e.private:s.private,this.index=e.index||(e.index!==0?s.index:0),this.static=e.static!==void 0?e.static:s.static,this.hidden=e.hidden!==void 0?e.hidden:s.hidden,this.constant=e.constant!==void 0?e.constant:s.constant,this.required=e.required!==void 0?e.required:s.required,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=g,...t){return await Ae.repository.APILoad(this.id,...t),this}async APICreate(e=g,...t){return await Ae.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=g,...t){return await Ae.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=g,...t){return await Ae.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=g,...t){return await Ae.repository.APIClone(this.id,...t),this}async APILoadVersion(e=g,t,...i){return await Ae.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:y,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...y),l.push(...c)}),this.defaultValue){const{updated:d,removed:u}=this.defaultValue.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}if(this.dataType){const{updated:d,removed:u}=this.dataType.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}return e||this.parent.type===n.DefinitionEntity&&(this.parent.removeProperty(this),i.push(this.parent)),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.defaultValue){const{updated:o}=this.defaultValue.restore({},e);i.push(...o)}if(this.dataType){const{updated:o}=this.dataType.restore({},e);i.push(...o)}return this.parent.type===n.DefinitionEntity&&(this.parent.addProperty(this),i.push(this.parent)),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this,...((i=this.defaultValue)==null?void 0:i.toFlat(e))||[],...((s=this.dataType)==null?void 0:s.toFlat(e))||[],...this.parent.toFlat(e)])}toFlatIds(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((i=this.defaultValue)==null?void 0:i.toFlatIds(e))||[],...((s=this.dataType)==null?void 0:s.toFlatIds(e))||[],...this.parent.toFlatIds(e)])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,index:this.index,hidden:this.hidden,private:this.private,abstract:this.abstract,required:this.required,constant:this.constant,static:this.static,type:this.type,name:this.name}}toJSON(e=new Set){var t,i,s;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,private:this.private,required:this.required,static:this.static,constant:this.constant,abstract:this.abstract,hidden:this.hidden,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,dataType:((i=this.dataType)==null?void 0:i.toJSON(e))||null,implements:((s=this.implements)==null?void 0:s.toJSON(e))||null,parent:this.parent.toReference()})}toJSONClone(e=q){var i,s,l,o,d,u,y;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:this.type,name:this.name,description:this.description,index:this.index,private:this.private,required:this.required,static:this.static,constant:this.constant,abstract:this.abstract,hidden:this.hidden,defaultValue:((u=this.defaultValue)==null?void 0:u.toJSONClone({...e,newId:null}))||null,dataType:((y=this.dataType)==null?void 0:y.toJSONClone({...e,newId:null}))||null,implements:(()=>{var c;return this.implements&&this.project.getBuiltIn(this.implements.id)?this.implements.toJSON():((c=this.implements)==null?void 0:c.toJSONClone({...e,newId:null}))||null})(),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=q){var i,s,l,o;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,description:this.description,type:this.type,index:this.index,private:this.private,required:this.required,abstract:this.abstract,static:this.static,constant:this.constant,hidden:this.hidden,defaultValue:((s=this.defaultValue)==null?void 0:s.toReference(e))||null,dataType:((l=this.dataType)==null?void 0:l.toReference(e))||null,implements:((o=this.implements)==null?void 0:o.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var i,s,l;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((i=this.defaultValue)==null?void 0:i.toFlatJSON(e))||[],...((s=this.dataType)==null?void 0:s.toFlatJSON(e))||[],...((l=this.implements)==null?void 0:l.toFlatJSON(e))||[],...this.parent.toFlatJSON(e)])}toGenerationTarget(){var e;return{id:this.id,name:this.name,description:this.description,type:this.type,private:this.private,required:this.required,abstract:this.abstract,static:this.static,implements:((e=this.implements)==null?void 0:e.id)||null,parent:this.parent.id}}toFlatGenerationTarget(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((i=this.defaultValue)==null?void 0:i.toFlatGenerationTarget(e))||[],...((s=this.dataType)==null?void 0:s.toFlatGenerationTarget(e))||[]])}clearErrors(){var e,t;return this.errors=[],(e=this.defaultValue)==null||e.clearErrors(),(t=this.dataType)==null||t.clearErrors(),this}validate(){return this.errors=QO(this),this.errors.length,{success:!0,error:null,data:null}}getErrors(){var t,i;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[],...((i=this.dataType)==null?void 0:i.getErrors())||[]]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var E,O;let l=mt(t,this);const o=i||m.UUID.uuid();let d=t||this.parent;const u={hidden:!1,id:o,version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.author)||"1",previousVersion:null,deleted:!1,type:this.type,name:this.name,description:this.description,index:this.index,private:this.private,constant:this.constant,required:this.required,abstract:this.abstract,static:this.static,defaultValue:null,dataType:null,implements:this.implements,parent:d},y=ct(u,l);s&&y.subscribe(),y.setParent(d,null),y.initChildren(e),e==null||e.add(y,A.Added);const c=((E=this.dataType)==null?void 0:E.clone(e,y,m.UUID.uuid(),s))||null;c&&y.setDataType(c);const I=(O=this.defaultValue)==null?void 0:O.clone(e,y,m.UUID.uuid(),s);return y.defaultValue=I||null,this.implements&&(y.implements=this.implements),y.addSelfToProject(null),e==null||e.attemptAutoclose("clone-entity",this.id),y}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}getDataType(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"get-data-type"))){return this.dataType}getDefaultValue(){return this.defaultValue}setDefaultValue(e){return this.defaultValue=e,this}};f(Ae,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(Ae,"type",n.Property),f(Ae,"USER_MANAGED_PARENT_TYPES",[n.DefinitionEntity]),f(Ae,"PARENT_TYPES",[...Ae.USER_MANAGED_PARENT_TYPES,n.PrimitiveEntity,n.BuiltInBaseEntity]),f(Ae,"MUTABLE_BASE_PROPERTIES",["name","description","private","abstract","static","required","constant"]),f(Ae,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Ae,"BASE_PROPERTIES",[...Ae.MUTABLE_BASE_PROPERTIES,...Ae.INMUTABLE_BASE_PROPERTIES]),f(Ae,"MUTABLE_META_PROPERTIES",[...Ae.MUTABLE_BASE_PROPERTIES,"index"]),f(Ae,"INMUTABLE_META_PROPERTIES",[...Ae.INMUTABLE_BASE_PROPERTIES]),f(Ae,"META_PROPERTIES",[...Ae.MUTABLE_META_PROPERTIES,...Ae.INMUTABLE_META_PROPERTIES]),f(Ae,"MUTABLE_UPSTREAM_PROPERTIES",[]),f(Ae,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements"]),f(Ae,"UPSTREAM_PROPERTIES",[...Ae.MUTABLE_UPSTREAM_PROPERTIES,...Ae.INMUTABLE_UPSTREAM_PROPERTIES]),f(Ae,"MUTABLE_DOWNSTREAM_PROPERTIES",["dataType"]),f(Ae,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Ae,"DOWNSTREAM_PROPERTIES",[...Ae.MUTABLE_DOWNSTREAM_PROPERTIES,...Ae.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Ae,"PROPERTIES",[...Ae.META_PROPERTIES,...Ae.UPSTREAM_PROPERTIES,...Ae.DOWNSTREAM_PROPERTIES]);let Ur=Ae;function i1(r){var s;const a=f5(),e=r.toJSON();a.safeParse(e).success,(s=r.dataType)==null||s.validate();const i=[];if(r.id==="iterate-over-employee-list-continue-statement-employee-dto-output-decl-id"){const l=de({id:`${r.id}--${F.PropertyImplementsNonAbstact}`,message:`Property "${x(r,r.project)}" with id "${r.id}" implements a non-abstract property "${x(r,r.project)}" with id "${r.id}".`,issue:null,severity:D.Error,code:F.PropertyImplementsNonAbstact,entity:r});i.push(l.error)}return He(r.errors,i)}const vq=Object.freeze(Object.defineProperty({__proto__:null,validate:i1},Symbol.toStringTag,{value:"Module"}));var r1=(r=>(r.Implements="implements",r.DataTypeEntity="data-type-entity",r))(r1||{});const be=class be extends at{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"index");f(this,"required");f(this,"constant",!0);f(this,"isError");f(this,"type",n.ReturnDeclaration);f(this,"defaultValue",null);f(this,"dataType",null);f(this,"readsValue",null);f(this,"implements",null);f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.index=e.index,this.name=e.name,this.description=e.description,this.required=e.required,this.constant=!0,this.isError=e.isError}static new(){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ReturnDeclaration,name:"",description:"",dataType:null,index:0,required:!1,constant:!0,isError:!1,implements:null,readsValue:null,defaultValue:null,parent:null}}static fromGenerationTarget(e,t){const i=_(e.parent),s=t.get(i);let l=null;if(e.readsValue){const u=_(e.readsValue);l=t.get(u)}const o={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,type:n.ReturnDeclaration,index:s.outputs.length,isError:!1,description:e.description,defaultValue:null,implements:null,required:e.required,constant:!0,readsValue:l,dataType:null,parent:s},d=C(o,t);return d.setParent(s,null),d.initChildren(null),d}static validateGenerationTarget(e,t){var d,u;let i=JSON.parse(JSON.stringify(e));const s=[],l=At(i,{parent:{list:!1,types:[n.ReturnStatement,n.Search,n.BreakStatement,n.ContinueStatement]}},t),o=Dc(i,t);if(i=l.modifiedData,i.parent){const y=t.get(_(i.parent));if(y&&[n.BreakStatement,n.ContinueStatement].includes(y.type)){const c=y,I=c.parent,E=[...I.breakStatements.filter(P=>P.id!==y.id),...I.continueStatements.filter(P=>P.id!==y.id)];if(c.outputs.length)s.push(new w({id:`${i.id}--${j.NoOverlapWithImplementedSignature}`,code:j.NoOverlapWithImplementedSignature,severity:D.Error,message:`Entity of type '${n.ReturnDeclaration}' with id '${i.id}' cannot be added to the parent entity of type '${c.type}' with id '${c.id}'. This '${c.type}' already has return declarations.
45
+ ${Fl}`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],i=[],s=[];return Object.values(this.detachedDependents).forEach(l=>{const o=l.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),i.push(...o.removed),s.push(...o.affected)}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];return t==="implements"&&(this.setImplements(null,i),s.push(this)),{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];return t==="implements"&&(this.setImplements(e,i),s.push(this)),{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e,t,i,s,l;return(t=(e=this.implements)==null?void 0:e.subscribeDependents)==null||t.call(e,[{entity:this,field:"implements"}]),(l=(s=(i=this.dataType)==null?void 0:i.entity)==null?void 0:s.subscribeDependents)==null||l.call(s,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ae(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.defaultValue=this.defaultValue,e.dataType=this.dataType,e.implements=this.implements,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent&&this.parent.type!==n.PrimitiveEntity&&this.parent.type!==n.BuiltInBaseEntity){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[I,E]of c.knownVersions)u.set(I,E);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ae(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.defaultValue=o.defaultValue,this.dataType=o.dataType,this.implements=o.implements,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${xt(this.type)} with id '${this.id}' has a parent reference "${l}" which is missing in the project`)}else throw new Error(`${xt(this.type)} with id '${this.id}' is missing a parent reference`);if(this.initialData.implements){const l=_(this.initialData.implements),o=this.project.get(l);o&&(this.setImplements(o,null),e.push(o))}return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.parent.addProperty(this),t.push(this.parent),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setImplements(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-implements"))){var i;return((i=this.implements)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.implements=e,t&&(t==null||t.add(this,A.Updated),t==null||t.attemptAutoclose("set-implements",this.id))),this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=C(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),this.initialData.dataType){const t=C(this.initialData.dataType,this.project);t.setParent(this,null),t.initChildren(e),this.dataType=t}if(this.initialData.implements){const t=C(this.initialData.implements,this.project);this.setImplements(t,null)}return this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.name=e.name||s.name,this.description=e.description||s.description,this.abstract=e.abstract!==void 0?e.abstract:s.abstract,this.private=e.private!==void 0?e.private:s.private,this.index=e.index||(e.index!==0?s.index:0),this.static=e.static!==void 0?e.static:s.static,this.hidden=e.hidden!==void 0?e.hidden:s.hidden,this.constant=e.constant!==void 0?e.constant:s.constant,this.required=e.required!==void 0?e.required:s.required,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=g,...t){return await Ae.repository.APILoad(this.id,...t),this}async APICreate(e=g,...t){return await Ae.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=g,...t){return await Ae.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=g,...t){return await Ae.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=g,...t){return await Ae.repository.APIClone(this.id,...t),this}async APILoadVersion(e=g,t,...i){return await Ae.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:y,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...y),l.push(...c)}),this.defaultValue){const{updated:d,removed:u}=this.defaultValue.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}if(this.dataType){const{updated:d,removed:u}=this.dataType.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}return e||this.parent.type===n.DefinitionEntity&&(this.parent.removeProperty(this),i.push(this.parent)),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.defaultValue){const{updated:o}=this.defaultValue.restore({},e);i.push(...o)}if(this.dataType){const{updated:o}=this.dataType.restore({},e);i.push(...o)}return this.parent.type===n.DefinitionEntity&&(this.parent.addProperty(this),i.push(this.parent)),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this,...((i=this.defaultValue)==null?void 0:i.toFlat(e))||[],...((s=this.dataType)==null?void 0:s.toFlat(e))||[],...this.parent.toFlat(e)])}toFlatIds(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((i=this.defaultValue)==null?void 0:i.toFlatIds(e))||[],...((s=this.dataType)==null?void 0:s.toFlatIds(e))||[],...this.parent.toFlatIds(e)])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,index:this.index,hidden:this.hidden,private:this.private,abstract:this.abstract,required:this.required,constant:this.constant,static:this.static,type:this.type,name:this.name}}toJSON(e=new Set){var t,i,s;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,private:this.private,required:this.required,static:this.static,constant:this.constant,abstract:this.abstract,hidden:this.hidden,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,dataType:((i=this.dataType)==null?void 0:i.toJSON(e))||null,implements:((s=this.implements)==null?void 0:s.toJSON(e))||null,parent:this.parent.toReference()})}toJSONClone(e=q){var i,s,l,o,d,u,y;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:this.type,name:this.name,description:this.description,index:this.index,private:this.private,required:this.required,static:this.static,constant:this.constant,abstract:this.abstract,hidden:this.hidden,defaultValue:((u=this.defaultValue)==null?void 0:u.toJSONClone({...e,newId:null}))||null,dataType:((y=this.dataType)==null?void 0:y.toJSONClone({...e,newId:null}))||null,implements:(()=>{var c;return this.implements&&this.project.getBuiltIn(this.implements.id)?this.implements.toJSON():((c=this.implements)==null?void 0:c.toJSONClone({...e,newId:null}))||null})(),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=q){var i,s,l,o;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,description:this.description,type:this.type,index:this.index,private:this.private,required:this.required,abstract:this.abstract,static:this.static,constant:this.constant,hidden:this.hidden,defaultValue:((s=this.defaultValue)==null?void 0:s.toReference(e))||null,dataType:((l=this.dataType)==null?void 0:l.toReference(e))||null,implements:((o=this.implements)==null?void 0:o.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var i,s,l;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((i=this.defaultValue)==null?void 0:i.toFlatJSON(e))||[],...((s=this.dataType)==null?void 0:s.toFlatJSON(e))||[],...((l=this.implements)==null?void 0:l.toFlatJSON(e))||[],...this.parent.toFlatJSON(e)])}toGenerationTarget(){var e;return{id:this.id,name:this.name,description:this.description,type:this.type,private:this.private,required:this.required,abstract:this.abstract,static:this.static,implements:((e=this.implements)==null?void 0:e.id)||null,parent:this.parent.id}}toFlatGenerationTarget(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((i=this.defaultValue)==null?void 0:i.toFlatGenerationTarget(e))||[],...((s=this.dataType)==null?void 0:s.toFlatGenerationTarget(e))||[]])}clearErrors(){var e,t;return this.errors=[],(e=this.defaultValue)==null||e.clearErrors(),(t=this.dataType)==null||t.clearErrors(),this}validate(){return this.errors=QO(this),this.errors.length,{success:!0,error:null,data:null}}getErrors(){var t,i;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[],...((i=this.dataType)==null?void 0:i.getErrors())||[]]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var E,O;let l=mt(t,this);const o=i||m.UUID.uuid();let d=t||this.parent;const u={hidden:!1,id:o,version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.author)||"1",previousVersion:null,deleted:!1,type:this.type,name:this.name,description:this.description,index:this.index,private:this.private,constant:this.constant,required:this.required,abstract:this.abstract,static:this.static,defaultValue:null,dataType:null,implements:this.implements,parent:d},y=ct(u,l);s&&y.subscribe(),y.setParent(d,null),y.initChildren(e),e==null||e.add(y,A.Added);const c=((E=this.dataType)==null?void 0:E.clone(e,y,m.UUID.uuid(),s))||null;c&&y.setDataType(c);const I=(O=this.defaultValue)==null?void 0:O.clone(e,y,m.UUID.uuid(),s);return y.defaultValue=I||null,this.implements&&(y.implements=this.implements),y.addSelfToProject(null),e==null||e.attemptAutoclose("clone-entity",this.id),y}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}getDataType(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"get-data-type"))){return this.dataType}getDefaultValue(){return this.defaultValue}setDefaultValue(e){return this.defaultValue=e,this}};f(Ae,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(Ae,"type",n.Property),f(Ae,"USER_MANAGED_PARENT_TYPES",[n.DefinitionEntity]),f(Ae,"PARENT_TYPES",[...Ae.USER_MANAGED_PARENT_TYPES,n.PrimitiveEntity,n.BuiltInBaseEntity]),f(Ae,"MUTABLE_BASE_PROPERTIES",["name","description","private","abstract","static","required","constant"]),f(Ae,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Ae,"BASE_PROPERTIES",[...Ae.MUTABLE_BASE_PROPERTIES,...Ae.INMUTABLE_BASE_PROPERTIES]),f(Ae,"MUTABLE_META_PROPERTIES",[...Ae.MUTABLE_BASE_PROPERTIES,"index"]),f(Ae,"INMUTABLE_META_PROPERTIES",[...Ae.INMUTABLE_BASE_PROPERTIES]),f(Ae,"META_PROPERTIES",[...Ae.MUTABLE_META_PROPERTIES,...Ae.INMUTABLE_META_PROPERTIES]),f(Ae,"MUTABLE_UPSTREAM_PROPERTIES",[]),f(Ae,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements"]),f(Ae,"UPSTREAM_PROPERTIES",[...Ae.MUTABLE_UPSTREAM_PROPERTIES,...Ae.INMUTABLE_UPSTREAM_PROPERTIES]),f(Ae,"MUTABLE_DOWNSTREAM_PROPERTIES",["dataType"]),f(Ae,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Ae,"DOWNSTREAM_PROPERTIES",[...Ae.MUTABLE_DOWNSTREAM_PROPERTIES,...Ae.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Ae,"PROPERTIES",[...Ae.META_PROPERTIES,...Ae.UPSTREAM_PROPERTIES,...Ae.DOWNSTREAM_PROPERTIES]);let Ur=Ae;function i1(r){var s;const a=f5(),e=r.toJSON();a.safeParse(e).success,(s=r.dataType)==null||s.validate();const i=[];if(r.id==="iterate-over-employee-list-continue-statement-employee-dto-output-decl-id"){const l=de({id:`${r.id}--${F.PropertyImplementsNonAbstact}`,message:`Property "${x(r,r.project)}" with id "${r.id}" implements a non-abstract property "${x(r,r.project)}" with id "${r.id}".`,issue:null,severity:D.Error,code:F.PropertyImplementsNonAbstact,entity:r});i.push(l.error)}return He(r.errors,i)}const v7=Object.freeze(Object.defineProperty({__proto__:null,validate:i1},Symbol.toStringTag,{value:"Module"}));var r1=(r=>(r.Implements="implements",r.DataTypeEntity="data-type-entity",r))(r1||{});const be=class be extends at{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"index");f(this,"required");f(this,"constant",!0);f(this,"isError");f(this,"type",n.ReturnDeclaration);f(this,"defaultValue",null);f(this,"dataType",null);f(this,"readsValue",null);f(this,"implements",null);f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.index=e.index,this.name=e.name,this.description=e.description,this.required=e.required,this.constant=!0,this.isError=e.isError}static new(){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ReturnDeclaration,name:"",description:"",dataType:null,index:0,required:!1,constant:!0,isError:!1,implements:null,readsValue:null,defaultValue:null,parent:null}}static fromGenerationTarget(e,t){const i=_(e.parent),s=t.get(i);let l=null;if(e.readsValue){const u=_(e.readsValue);l=t.get(u)}const o={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,type:n.ReturnDeclaration,index:s.outputs.length,isError:!1,description:e.description,defaultValue:null,implements:null,required:e.required,constant:!0,readsValue:l,dataType:null,parent:s},d=C(o,t);return d.setParent(s,null),d.initChildren(null),d}static validateGenerationTarget(e,t){var d,u;let i=JSON.parse(JSON.stringify(e));const s=[],l=At(i,{parent:{list:!1,types:[n.ReturnStatement,n.Search,n.BreakStatement,n.ContinueStatement]}},t),o=Dc(i,t);if(i=l.modifiedData,i.parent){const y=t.get(_(i.parent));if(y&&[n.BreakStatement,n.ContinueStatement].includes(y.type)){const c=y,I=c.parent,E=[...I.breakStatements.filter(P=>P.id!==y.id),...I.continueStatements.filter(P=>P.id!==y.id)];if(c.outputs.length)s.push(new w({id:`${i.id}--${j.NoOverlapWithImplementedSignature}`,code:j.NoOverlapWithImplementedSignature,severity:D.Error,message:`Entity of type '${n.ReturnDeclaration}' with id '${i.id}' cannot be added to the parent entity of type '${c.type}' with id '${c.id}'. This '${c.type}' already has return declarations.
46
46
  ${Uc}`,issue:null}));else{const P=(u=(d=E[0])==null?void 0:d.outputs[0])==null?void 0:u.name;P!==i.name&&s.push(new w({id:`${i.id}--${j.NoOverlapWithImplementedSignature}`,code:j.NoOverlapWithImplementedSignature,severity:D.Error,message:`Entity of type '${n.ReturnDeclaration}' with id '${i.id}' cannot be added to the parent entity of type '${c.type}' with id '${c.id}'. This new 'return-declaration' doesn't have the same name "${P}" as the return declarations on the other statements in the same scope.
47
47
  ${Uc}`,issue:null}))}}else if(y&&y.type===n.ReturnStatement){const c=y.parent;if(c&&lt.includes(c.type)){const I=c.implements;if(I){const E=I.outputs.find(B=>B.name===i.name),O=I.outputs.filter(B=>!y.outputs.find(Z=>Z.type===n.ReturnDeclaration&&Z.name===B.name)),P=y.outputs.filter(B=>B.type===n.ReturnDeclaration),V=P.find(B=>B.name===i.name),M=P.length?`The parent entity already implements the following return declarations: ${ne(P.map(B=>`'${B.id}' (${B.name})`),", "," and ")}.`:"The parent entity does not yet have any implemented return declarations.",G=O.length?`The parent entity is still missing the following returns in the implementation: ${ne(O.map(B=>`'${B.id}' (${B.name})`),", "," and ")}.`:"The parent entity has all the returns it needs implemented.";E?V&&s.push(new w({id:`${i.id}--${j.NoOverlapWithImplementedSignature}`,code:j.NoOverlapWithImplementedSignature,severity:D.Error,message:`Entity of type '${n.ReturnDeclaration}' with id '${i.id}' should not exist in a parent entity of type '${y.type}' with id '${y.id}' that implements a ${n.ActionDescriptor} with fixed outputs.
48
48
  Adding a new return would make the implementation invalid. An return with the same name already exists in the parent entity.
@@ -51,13 +51,13 @@ ${G}`,issue:null})):s.push(new w({id:`${i.id}--${j.NoOverlapWithImplementedSigna
51
51
  Adding a new return would make the implementation invalid. There are no returns in the descriptor with the same name.
52
52
  ${M}
53
53
  ${G}`,issue:null}))}}}}return s.push(...l.errors,...o,...ut(i)),{errors:s,modifiedData:i}}validateGeneratedUpdate(e){const t=[];let i=JSON.parse(JSON.stringify(e));const s=_a(i,this);return i=s.modifiedData,t.push(...s.errors),i.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated, as it would mean moving the '${this.type}' entity to another parent entity.
54
- This is likely an incorrect strategy, either the '${this.type}' entity doesn't need to be updated or it should be deleted and a new one created in the desired parent.`,issue:null})),{errors:t,modifiedData:i}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],i=[],s=[];return Object.values(this.detachedDependents).forEach(l=>{const o=l.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),i.push(...o.removed),s.push(...o.affected)}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];return t==="implements"&&(this.setImplements(null,i),s.push(this)),{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];return t==="implements"&&(this.setImplements(e,i),s.push(this)),{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e,t,i,s,l;return(t=(e=this.implements)==null?void 0:e.subscribeDependents)==null||t.call(e,[{entity:this,field:"implements"}]),(l=(s=(i=this.dataType)==null?void 0:i.entity)==null?void 0:s.subscribeDependents)==null||l.call(s,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new be(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.defaultValue=this.defaultValue,e.dataType=this.dataType,e.readsValue=this.readsValue,e.implements=this.implements,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[I,E]of c.knownVersions)u.set(I,E);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new be(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.defaultValue=o.defaultValue,this.dataType=o.dataType,this.readsValue=o.readsValue,this.implements=o.implements,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.readsValue){const l=_(this.initialData.readsValue),o=this.project.get(l);o&&(this.setValueWriter(o,null),e.push(o))}if(this.initialData.implements){const l=_(this.initialData.implements),o=this.project.get(l);o&&(this.setImplements(o,null),e.push(o))}return Ir.hydrateReadsValue(this),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){var o;const t=[this],i=[],s=[],l=[];return this.isError?this.parent.throws=this:this.parent.addOutputDeclaration(this,e),t.push(this.parent),(o=this.readsValue)==null||o.addValueReader(this,e),this.readsValue&&t.push(this.readsValue),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}propagateChanges(){const e=[this],t=[],i=[],s=[];if(this.parent&&[n.BreakStatement,n.ContinueStatement].includes(this.parent.type)){const l=this.parent.parent,{updated:o,added:d,removed:u}=l.syncChildren();e.push(...o),t.push(...d),i.push(...u)}return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setImplements(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-implements"))){var i;return((i=this.implements)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.implements=e,t&&(t==null||t.add(this,A.Updated),t==null||t.attemptAutoclose("set-implements",this.id))),this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=C(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),this.initialData.dataType&&(this.dataType=C(this.initialData.dataType,this.project),this.dataType.setParent(this,null),this.dataType.initChildren(e)),this.initialData.implements){const t=C(this.initialData.implements,this.project);this.setImplements(t,null)}return Ir.initReadsValue(this),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}setValueWriter(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-value-writer"))){return this.readsValue!==e&&(this.readsValue=e,t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("set-value-writer",this.id),this}removeValueWriter(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-value-writer"))){return this.readsValue&&(this.readsValue=null,e==null||e.add(this,A.Updated)),e==null||e.attemptAutoclose("remove-value-writer",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.index=e.index||(e.index!==0?s.index:0),this.name=e.name||s.name,this.description=e.description||s.description,this.required=e.required!==void 0?e.required:this.required,this.isError=e.isError!==void 0?e.isError:this.isError,this.constant=e.constant!==void 0?e.constant:s.constant,this.required=e.required!==void 0?e.required:s.required,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=g,...t){return await be.repository.APILoad(this.id,...t),this}async APICreate(e=g,...t){return await be.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=g,...t){return await be.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=g,...t){return await be.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=g,...t){return await be.repository.APIClone(this.id,...t),this}async APILoadVersion(e=g,t,...i){return await be.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:y,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...y),l.push(...c)}),this.defaultValue){const{updated:d,removed:u}=this.defaultValue.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}if(this.dataType){const d=this.dataType.remove({ignoreUpstream:!0},t);i.push(...d.updated),s.push(...d.removed)}return t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.defaultValue){const{updated:o}=this.defaultValue.restore({},e);i.push(...o)}if(this.dataType){const o=this.dataType.restore({},e);i.push(...o.updated)}return e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){var i,s,l;return e.has(this.id)?[]:(e.add(this.id),[this,...((i=this.defaultValue)==null?void 0:i.toFlat(e))||[],...((s=this.readsValue)==null?void 0:s.toFlat(e))||[],...((l=this.dataType)==null?void 0:l.toFlat(e))||[]])}toFlatIds(e=new Set){var i,s,l;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((i=this.defaultValue)==null?void 0:i.toFlatIds(e))||[],...((s=this.readsValue)==null?void 0:s.toFlatIds(e))||[],...((l=this.dataType)==null?void 0:l.toFlatIds(e))||[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,index:this.index,required:this.required,constant:this.constant,isError:this.isError,type:this.type,name:this.name}}toJSON(e=new Set){var t,i,s,l;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,description:this.description,type:this.type,index:this.index,required:this.required,constant:!0,isError:this.isError,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,dataType:((i=this.dataType)==null?void 0:i.toJSON(e))||null,implements:((s=this.implements)==null?void 0:s.toJSON(e))||null,readsValue:((l=this.readsValue)==null?void 0:l.toJSON(e))||null,parent:this.parent.toReference()})}toJSONClone(e=q){var i,s,l,o,d,u,y,c,I;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,name:this.name,description:this.description,type:this.type,index:this.index,required:this.required,constant:!0,isError:this.isError,defaultValue:((u=this.defaultValue)==null?void 0:u.toJSONClone({...e,newId:null}))||null,dataType:((y=this.dataType)==null?void 0:y.toJSONClone({...e,newId:null}))||null,implements:((c=this.implements)==null?void 0:c.toJSONClone({...e,newId:null}))||null,readsValue:((I=this.readsValue)==null?void 0:I.toReference({seenEntityMaps:e.seenEntityMaps}))||null,parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=q){var i,s,l,o,d;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,description:this.description,type:this.type,index:this.index,required:this.required,constant:!0,isError:this.isError,defaultValue:((s=this.defaultValue)==null?void 0:s.toReference(e))||null,readsValue:((l=this.readsValue)==null?void 0:l.toReference(e))||null,implements:((o=this.implements)==null?void 0:o.toReference(e))||null,dataType:((d=this.dataType)==null?void 0:d.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var i,s,l;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((i=this.defaultValue)==null?void 0:i.toFlatJSON(e))||[],...((s=this.readsValue)==null?void 0:s.toFlatJSON(e))||[],...((l=this.dataType)==null?void 0:l.toFlatJSON(e))||[]])}toGenerationTarget(){var e;return{id:this.id,name:this.name,description:this.description,type:this.type,isError:this.isError,readsValue:(e=this.readsValue)==null?void 0:e.id,required:this.required,parent:this.parent.id}}toFlatGenerationTarget(e=new Set){var i,s,l;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((i=this.defaultValue)==null?void 0:i.toFlatGenerationTarget(e))||[],...((s=this.readsValue)==null?void 0:s.toFlatGenerationTarget(e))||[],...((l=this.dataType)==null?void 0:l.toFlatGenerationTarget(e))||[]])}clearErrors(){var e,t;return this.errors=[],(e=this.defaultValue)==null||e.clearErrors(),(t=this.dataType)==null||t.clearErrors(),this}validate(){const e=i1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){var t,i;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[],...((i=this.dataType)==null?void 0:i.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){return this.defaultValue||null}setDefaultValue(e){return this.defaultValue=e,this}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var I,E;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.dataType=null,o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const u=ct(o,l);t?u.setParent(t,null):u.setParent(this.parent,null),s&&u.subscribe(),u.initChildren(e),e==null||e.add(u,A.Added);const y=(I=this.dataType)==null?void 0:I.clone(e,u,m.UUID.uuid(),s);u.dataType=y||null;const c=(E=this.defaultValue)==null?void 0:E.clone(e,u,m.UUID.uuid(),s);return u.defaultValue=c||null,e==null||e.attemptAutoclose("clone-entity",this.id),u}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}inferDataType(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"infer-data-type"))){var i;const t=mc(this,e);if(t&&t.parent===this)this.dataType&&this.dataType.merge(t,e);else if(t&&t.parent!==this)if(this.dataType)this.dataType.merge(t,e);else{const s=t.clone(e,this);e==null||e.add(s,A.Added),this.setDataType(s)}return(i=this.dataType)==null||i.metaSync({inferred:!0},e),e==null||e.attemptAutoclose("infer-data-type",this.id),this}getCounterparts(){let e=[];if([n.BreakStatement,n.ContinueStatement].includes(this.parent.type)){const t=this.parent.parent;(!t||t.type!==n.Loop)&&console.error("Parent not loop for return declaration in continue or break statement: ",this.id,"parent:",this.parent.id,"loop:",t==null?void 0:t.id),e=[...t.breakStatements,...t.continueStatements].flatMap(l=>l.outputs).filter(l=>x(l,this.project)===x(this,this.project)&&l.id!==this.id)}else if(this.parent.type===n.ReturnStatement&&[n.FunctionDeclaration,n.GlobalEvent].includes(this.parent.parent.type)&&this.parent.parent.implements){const i=this.parent.parent.returnStatements.flatMap(s=>s.outputs);this.implements?e=i.filter(l=>{var o;return this.implements.id===((o=l.implements)==null?void 0:o.id)}):e=i.filter(l=>x(l,this.project)===x(this,this.project)&&l.id!==this.id)}return e}inferDataTypeFromCounterparts(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"infer-data-type-from-counterparts"))){var s,l,o;const t=this.getCounterparts(),i=t.find(d=>{var u;return(u=d.dataType)==null?void 0:u.isResolved});if(i)this.setDataType(i.dataType),e==null||e.add(this,A.Updated);else for(let d=0;d<t.length;d++){const u=t[d];if((!u.dataType||!u.dataType.isResolved||(s=u.dataType)!=null&&s.inferred)&&u.readsValue&&u.inferDataType(e),(l=u.dataType)!=null&&l.isResolved){this.setDataType(u.dataType),e==null||e.add(this,A.Updated);break}}return(o=this.dataType)==null||o.metaSync({inferred:!0},e),e==null||e.attemptAutoclose("infer-data-type-from-counterparts",this.id),this}getDataType(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"get-data-type"))){var t;return(!this.dataType||!this.dataType.isResolved||(t=this.dataType)!=null&&t.inferred)&&this.readsValue?this.inferDataType(e):this.inferDataTypeFromCounterparts(e),this.dataType}};f(be,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(be,"type",n.ReturnDeclaration),f(be,"USER_MANAGED_PARENT_TYPES",[n.ReturnStatement,n.BreakStatement,n.ContinueStatement]),f(be,"PARENT_TYPES",[...be.USER_MANAGED_PARENT_TYPES]),f(be,"MUTABLE_BASE_PROPERTIES",["name","description","required","isError"]),f(be,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(be,"BASE_PROPERTIES",[...be.MUTABLE_BASE_PROPERTIES,...be.INMUTABLE_BASE_PROPERTIES]),f(be,"MUTABLE_META_PROPERTIES",[...be.MUTABLE_BASE_PROPERTIES,"index"]),f(be,"INMUTABLE_META_PROPERTIES",[...be.INMUTABLE_BASE_PROPERTIES]),f(be,"META_PROPERTIES",[...be.MUTABLE_META_PROPERTIES,...be.INMUTABLE_META_PROPERTIES]),f(be,"MUTABLE_UPSTREAM_PROPERTIES",["readsValue"]),f(be,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),f(be,"UPSTREAM_PROPERTIES",[...be.MUTABLE_UPSTREAM_PROPERTIES,...be.INMUTABLE_UPSTREAM_PROPERTIES]),f(be,"MUTABLE_DOWNSTREAM_PROPERTIES",["dataType","defaultValue"]),f(be,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(be,"DOWNSTREAM_PROPERTIES",[...be.MUTABLE_DOWNSTREAM_PROPERTIES,...be.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(be,"PROPERTIES",[...be.META_PROPERTIES,...be.UPSTREAM_PROPERTIES,...be.DOWNSTREAM_PROPERTIES]);let ai=be;function n1(r){var s;const a=d5(),e=r.toJSON();a.safeParse(e).success,r.outputs.forEach(l=>l.validate()),(s=r.throws)==null||s.validate();const i=[];return He(r.errors,i)}const Tq=Object.freeze(Object.defineProperty({__proto__:null,validate:n1},Symbol.toStringTag,{value:"Module"}));function s1(r){var s;const a=s5(),e=r.toJSON();a.safeParse(e).success,r.outputs.forEach(l=>l.validate()),(s=r.throws)==null||s.validate();const i=[];return He(r.errors,i)}const Iq=Object.freeze(Object.defineProperty({__proto__:null,validate:s1},Symbol.toStringTag,{value:"Module"}));var wc=(r=>(r.Parent="parent",r))(wc||{});const Fe=class Fe extends at{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"x");f(this,"y");f(this,"type",n.ContinueStatement);f(this,"outputs",[]);f(this,"calledBySuccess",[]);f(this,"calledByError",[]);f(this,"calledByEntry",[]);f(this,"throws",null);f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static new(){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ContinueStatement,outputs:[],throws:null,parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],x:0,y:0}}static fromGenerationTarget(e,t){const i=_(e.parent),s=t.get(i),l=e.calledByEntry.map(c=>{const I=_(c);return t.get(I)}),o=e.calledBySuccess.map(c=>{const I=_(c);return t.get(I)}),d=e.calledByError.map(c=>{const I=_(c);return t.get(I)}),u={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ContinueStatement,x:0,y:0,outputs:[],calledBySuccess:o,calledByError:d,calledByEntry:l,throws:null,parent:s},y=C(u,t);return y.setParent(s,null),y.initChildren(null),y}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=At(i,{parent:{list:!1,types:[n.Loop]}},t);return i=l.modifiedData,s.push(...l.errors,...ut(i)),{errors:s,modifiedData:i}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
54
+ This is likely an incorrect strategy, either the '${this.type}' entity doesn't need to be updated or it should be deleted and a new one created in the desired parent.`,issue:null})),{errors:t,modifiedData:i}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],i=[],s=[];return Object.values(this.detachedDependents).forEach(l=>{const o=l.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),i.push(...o.removed),s.push(...o.affected)}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];return t==="implements"&&(this.setImplements(null,i),s.push(this)),{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];return t==="implements"&&(this.setImplements(e,i),s.push(this)),{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e,t,i,s,l;return(t=(e=this.implements)==null?void 0:e.subscribeDependents)==null||t.call(e,[{entity:this,field:"implements"}]),(l=(s=(i=this.dataType)==null?void 0:i.entity)==null?void 0:s.subscribeDependents)==null||l.call(s,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new be(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.defaultValue=this.defaultValue,e.dataType=this.dataType,e.readsValue=this.readsValue,e.implements=this.implements,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[I,E]of c.knownVersions)u.set(I,E);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new be(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.defaultValue=o.defaultValue,this.dataType=o.dataType,this.readsValue=o.readsValue,this.implements=o.implements,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.readsValue){const l=_(this.initialData.readsValue),o=this.project.get(l);o&&(this.setValueWriter(o,null),e.push(o))}if(this.initialData.implements){const l=_(this.initialData.implements),o=this.project.get(l);o&&(this.setImplements(o,null),e.push(o))}return Ir.hydrateReadsValue(this),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){var o;const t=[this],i=[],s=[],l=[];return this.isError?this.parent.throws=this:this.parent.addOutputDeclaration(this,e),t.push(this.parent),(o=this.readsValue)==null||o.addValueReader(this,e),this.readsValue&&t.push(this.readsValue),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}propagateChanges(){const e=[this],t=[],i=[],s=[];if(this.parent&&[n.BreakStatement,n.ContinueStatement].includes(this.parent.type)){const l=this.parent.parent,{updated:o,added:d,removed:u}=l.syncChildren();e.push(...o),t.push(...d),i.push(...u)}return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setImplements(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-implements"))){var i;return((i=this.implements)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.implements=e,t&&(t==null||t.add(this,A.Updated),t==null||t.attemptAutoclose("set-implements",this.id))),this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=C(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),this.initialData.dataType&&(this.dataType=C(this.initialData.dataType,this.project),this.dataType.setParent(this,null),this.dataType.initChildren(e)),this.initialData.implements){const t=C(this.initialData.implements,this.project);this.setImplements(t,null)}return Ir.initReadsValue(this),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}setValueWriter(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-value-writer"))){return this.readsValue!==e&&(this.readsValue=e,t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("set-value-writer",this.id),this}removeValueWriter(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-value-writer"))){return this.readsValue&&(this.readsValue=null,e==null||e.add(this,A.Updated)),e==null||e.attemptAutoclose("remove-value-writer",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.index=e.index||(e.index!==0?s.index:0),this.name=e.name||s.name,this.description=e.description||s.description,this.required=e.required!==void 0?e.required:this.required,this.isError=e.isError!==void 0?e.isError:this.isError,this.constant=e.constant!==void 0?e.constant:s.constant,this.required=e.required!==void 0?e.required:s.required,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=g,...t){return await be.repository.APILoad(this.id,...t),this}async APICreate(e=g,...t){return await be.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=g,...t){return await be.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=g,...t){return await be.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=g,...t){return await be.repository.APIClone(this.id,...t),this}async APILoadVersion(e=g,t,...i){return await be.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:y,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...y),l.push(...c)}),this.defaultValue){const{updated:d,removed:u}=this.defaultValue.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}if(this.dataType){const d=this.dataType.remove({ignoreUpstream:!0},t);i.push(...d.updated),s.push(...d.removed)}return t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.defaultValue){const{updated:o}=this.defaultValue.restore({},e);i.push(...o)}if(this.dataType){const o=this.dataType.restore({},e);i.push(...o.updated)}return e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){var i,s,l;return e.has(this.id)?[]:(e.add(this.id),[this,...((i=this.defaultValue)==null?void 0:i.toFlat(e))||[],...((s=this.readsValue)==null?void 0:s.toFlat(e))||[],...((l=this.dataType)==null?void 0:l.toFlat(e))||[]])}toFlatIds(e=new Set){var i,s,l;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((i=this.defaultValue)==null?void 0:i.toFlatIds(e))||[],...((s=this.readsValue)==null?void 0:s.toFlatIds(e))||[],...((l=this.dataType)==null?void 0:l.toFlatIds(e))||[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,index:this.index,required:this.required,constant:this.constant,isError:this.isError,type:this.type,name:this.name}}toJSON(e=new Set){var t,i,s,l;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,description:this.description,type:this.type,index:this.index,required:this.required,constant:!0,isError:this.isError,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,dataType:((i=this.dataType)==null?void 0:i.toJSON(e))||null,implements:((s=this.implements)==null?void 0:s.toJSON(e))||null,readsValue:((l=this.readsValue)==null?void 0:l.toJSON(e))||null,parent:this.parent.toReference()})}toJSONClone(e=q){var i,s,l,o,d,u,y,c,I;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,name:this.name,description:this.description,type:this.type,index:this.index,required:this.required,constant:!0,isError:this.isError,defaultValue:((u=this.defaultValue)==null?void 0:u.toJSONClone({...e,newId:null}))||null,dataType:((y=this.dataType)==null?void 0:y.toJSONClone({...e,newId:null}))||null,implements:((c=this.implements)==null?void 0:c.toJSONClone({...e,newId:null}))||null,readsValue:((I=this.readsValue)==null?void 0:I.toReference({seenEntityMaps:e.seenEntityMaps}))||null,parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=q){var i,s,l,o,d;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,description:this.description,type:this.type,index:this.index,required:this.required,constant:!0,isError:this.isError,defaultValue:((s=this.defaultValue)==null?void 0:s.toReference(e))||null,readsValue:((l=this.readsValue)==null?void 0:l.toReference(e))||null,implements:((o=this.implements)==null?void 0:o.toReference(e))||null,dataType:((d=this.dataType)==null?void 0:d.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var i,s,l;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((i=this.defaultValue)==null?void 0:i.toFlatJSON(e))||[],...((s=this.readsValue)==null?void 0:s.toFlatJSON(e))||[],...((l=this.dataType)==null?void 0:l.toFlatJSON(e))||[]])}toGenerationTarget(){var e;return{id:this.id,name:this.name,description:this.description,type:this.type,isError:this.isError,readsValue:(e=this.readsValue)==null?void 0:e.id,required:this.required,parent:this.parent.id}}toFlatGenerationTarget(e=new Set){var i,s,l;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((i=this.defaultValue)==null?void 0:i.toFlatGenerationTarget(e))||[],...((s=this.readsValue)==null?void 0:s.toFlatGenerationTarget(e))||[],...((l=this.dataType)==null?void 0:l.toFlatGenerationTarget(e))||[]])}clearErrors(){var e,t;return this.errors=[],(e=this.defaultValue)==null||e.clearErrors(),(t=this.dataType)==null||t.clearErrors(),this}validate(){const e=i1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){var t,i;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[],...((i=this.dataType)==null?void 0:i.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){return this.defaultValue||null}setDefaultValue(e){return this.defaultValue=e,this}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var I,E;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.dataType=null,o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const u=ct(o,l);t?u.setParent(t,null):u.setParent(this.parent,null),s&&u.subscribe(),u.initChildren(e),e==null||e.add(u,A.Added);const y=(I=this.dataType)==null?void 0:I.clone(e,u,m.UUID.uuid(),s);u.dataType=y||null;const c=(E=this.defaultValue)==null?void 0:E.clone(e,u,m.UUID.uuid(),s);return u.defaultValue=c||null,e==null||e.attemptAutoclose("clone-entity",this.id),u}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}inferDataType(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"infer-data-type"))){var i;const t=mc(this,e);if(t&&t.parent===this)this.dataType&&this.dataType.merge(t,e);else if(t&&t.parent!==this)if(this.dataType)this.dataType.merge(t,e);else{const s=t.clone(e,this);e==null||e.add(s,A.Added),this.setDataType(s)}return(i=this.dataType)==null||i.metaSync({inferred:!0},e),e==null||e.attemptAutoclose("infer-data-type",this.id),this}getCounterparts(){let e=[];if([n.BreakStatement,n.ContinueStatement].includes(this.parent.type)){const t=this.parent.parent;(!t||t.type!==n.Loop)&&console.error("Parent not loop for return declaration in continue or break statement: ",this.id,"parent:",this.parent.id,"loop:",t==null?void 0:t.id),e=[...t.breakStatements,...t.continueStatements].flatMap(l=>l.outputs).filter(l=>x(l,this.project)===x(this,this.project)&&l.id!==this.id)}else if(this.parent.type===n.ReturnStatement&&[n.FunctionDeclaration,n.GlobalEvent].includes(this.parent.parent.type)&&this.parent.parent.implements){const i=this.parent.parent.returnStatements.flatMap(s=>s.outputs);this.implements?e=i.filter(l=>{var o;return this.implements.id===((o=l.implements)==null?void 0:o.id)}):e=i.filter(l=>x(l,this.project)===x(this,this.project)&&l.id!==this.id)}return e}inferDataTypeFromCounterparts(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"infer-data-type-from-counterparts"))){var s,l,o;const t=this.getCounterparts(),i=t.find(d=>{var u;return(u=d.dataType)==null?void 0:u.isResolved});if(i)this.setDataType(i.dataType),e==null||e.add(this,A.Updated);else for(let d=0;d<t.length;d++){const u=t[d];if((!u.dataType||!u.dataType.isResolved||(s=u.dataType)!=null&&s.inferred)&&u.readsValue&&u.inferDataType(e),(l=u.dataType)!=null&&l.isResolved){this.setDataType(u.dataType),e==null||e.add(this,A.Updated);break}}return(o=this.dataType)==null||o.metaSync({inferred:!0},e),e==null||e.attemptAutoclose("infer-data-type-from-counterparts",this.id),this}getDataType(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"get-data-type"))){var t;return(!this.dataType||!this.dataType.isResolved||(t=this.dataType)!=null&&t.inferred)&&this.readsValue?this.inferDataType(e):this.inferDataTypeFromCounterparts(e),this.dataType}};f(be,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(be,"type",n.ReturnDeclaration),f(be,"USER_MANAGED_PARENT_TYPES",[n.ReturnStatement,n.BreakStatement,n.ContinueStatement]),f(be,"PARENT_TYPES",[...be.USER_MANAGED_PARENT_TYPES]),f(be,"MUTABLE_BASE_PROPERTIES",["name","description","required","isError"]),f(be,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(be,"BASE_PROPERTIES",[...be.MUTABLE_BASE_PROPERTIES,...be.INMUTABLE_BASE_PROPERTIES]),f(be,"MUTABLE_META_PROPERTIES",[...be.MUTABLE_BASE_PROPERTIES,"index"]),f(be,"INMUTABLE_META_PROPERTIES",[...be.INMUTABLE_BASE_PROPERTIES]),f(be,"META_PROPERTIES",[...be.MUTABLE_META_PROPERTIES,...be.INMUTABLE_META_PROPERTIES]),f(be,"MUTABLE_UPSTREAM_PROPERTIES",["readsValue"]),f(be,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),f(be,"UPSTREAM_PROPERTIES",[...be.MUTABLE_UPSTREAM_PROPERTIES,...be.INMUTABLE_UPSTREAM_PROPERTIES]),f(be,"MUTABLE_DOWNSTREAM_PROPERTIES",["dataType","defaultValue"]),f(be,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(be,"DOWNSTREAM_PROPERTIES",[...be.MUTABLE_DOWNSTREAM_PROPERTIES,...be.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(be,"PROPERTIES",[...be.META_PROPERTIES,...be.UPSTREAM_PROPERTIES,...be.DOWNSTREAM_PROPERTIES]);let ai=be;function n1(r){var s;const a=d5(),e=r.toJSON();a.safeParse(e).success,r.outputs.forEach(l=>l.validate()),(s=r.throws)==null||s.validate();const i=[];return He(r.errors,i)}const T7=Object.freeze(Object.defineProperty({__proto__:null,validate:n1},Symbol.toStringTag,{value:"Module"}));function s1(r){var s;const a=s5(),e=r.toJSON();a.safeParse(e).success,r.outputs.forEach(l=>l.validate()),(s=r.throws)==null||s.validate();const i=[];return He(r.errors,i)}const I7=Object.freeze(Object.defineProperty({__proto__:null,validate:s1},Symbol.toStringTag,{value:"Module"}));var wc=(r=>(r.Parent="parent",r))(wc||{});const Fe=class Fe extends at{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"x");f(this,"y");f(this,"type",n.ContinueStatement);f(this,"outputs",[]);f(this,"calledBySuccess",[]);f(this,"calledByError",[]);f(this,"calledByEntry",[]);f(this,"throws",null);f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static new(){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ContinueStatement,outputs:[],throws:null,parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],x:0,y:0}}static fromGenerationTarget(e,t){const i=_(e.parent),s=t.get(i),l=e.calledByEntry.map(c=>{const I=_(c);return t.get(I)}),o=e.calledBySuccess.map(c=>{const I=_(c);return t.get(I)}),d=e.calledByError.map(c=>{const I=_(c);return t.get(I)}),u={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ContinueStatement,x:0,y:0,outputs:[],calledBySuccess:o,calledByError:d,calledByEntry:l,throws:null,parent:s},y=C(u,t);return y.setParent(s,null),y.initChildren(null),y}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=At(i,{parent:{list:!1,types:[n.Loop]}},t);return i=l.modifiedData,s.push(...l.errors,...ut(i)),{errors:s,modifiedData:i}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
55
55
  If an entity is called by another, they must be in the same scope, which means they have the same parent.
56
56
  You shouldn't have to manually update a 'parent' property.
57
57
  Specifically for continue statements the parent needs to always be the 'loop' entity that contains it.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],i=[],s=[];return Object.values(this.detachedDependents).forEach(l=>{const o=l.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),i.push(...o.removed),s.push(...o.affected)}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Fe(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.outputs=this.outputs,e.throws=this.throws,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[I,E]of c.knownVersions)u.set(I,E);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Fe(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.outputs=o.outputs,this.throws=o.throws,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);return this.initialData.calledByEntry.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.calledByEntry.forEach(o=>{o.addCall(this,e),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this,e),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this,e),t.push(o)}),this.parent.addContinueStatement(this),t.push(this),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}addSuccessCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,A.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,A.Updated),i&&K(this,t),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,A.Updated),i&&K(this,t),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}removeCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected)),!0):!1),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected)),!0):!1),i&&K(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}addOutputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-output-declaration"))){return this.outputs.find(i=>i.id===e.id)||(this.outputs.push(e),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-output-declaration",this.id),this}removeOutputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-output-declaration"))){return this.outputs.find(i=>i.id===e.id)&&(this.outputs=this.outputs.filter(i=>i.id!==e.id),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("remove-output-declaration",this.id),this}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.outputs=this.initialData.outputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.initialData.throws&&(this.throws=C(this.initialData.throws,this.project),this.throws.setParent(this,null),this.throws.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=g,...t){return await Fe.repository.APILoad(this.id,...t),this}async APICreate(e=g,...t){return await Fe.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=g,...t){return await Fe.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=g,...t){return await Fe.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=g,...t){return await Fe.repository.APIClone(this.id,...t),this}async APILoadVersion(e=g,t,...i){return await Fe.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:y,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...y),l.push(...c)}),this.outputs.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.throws){const{updated:d,removed:u}=this.throws.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}return this.parent.removeContinueStatement(this),e||this.calledBy.forEach(d=>{i.push(d),d.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.throws){const{updated:o}=this.throws.restore({},e);i.push(...o)}return this.parent.addContinueStatement(this),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.outputs.flatMap(i=>i.toFlat(e)),...this.calledBy.flatMap(i=>i.toFlat(e)),...this.throws?this.throws.toFlat(e):[]])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.outputs.flatMap(i=>i.toFlatIds(e)),...this.calledBy.flatMap(i=>i.toFlatIds(e)),...this.throws?this.throws.toFlatIds(e):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,calledBySuccess:this.calledBySuccess.map(s=>s.toReference()),calledByError:this.calledByError.map(s=>s.toReference()),calledByEntry:this.calledByEntry.map(s=>s.toReference()),outputs:this.outputs.map(s=>s.toJSON(e)),throws:((t=this.throws)==null?void 0:t.toJSON(e))||null,parent:((i=this.parent)==null?void 0:i.toReference())||null})}toJSONClone(e=q){var i,s,l,o,d,u,y;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,calledBySuccess:this.calledBySuccess.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),outputs:this.outputs.map(c=>c.toJSONClone({...e,newId:null})),throws:((u=this.throws)==null?void 0:u.toJSONClone({...e,newId:null}))||null,parent:((y=this.parent)==null?void 0:y.toReference({seenEntityMaps:e.seenEntityMaps}))||null})}toReference(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=q){var i,s;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,outputs:this.outputs.map(l=>l.toReference(e)),calledBySuccess:this.calledBySuccess.map(l=>l.toReference(e)),calledByError:this.calledByError.map(l=>l.toReference(e)),calledByEntry:this.calledByEntry.map(l=>l.toReference(e)),throws:((s=this.throws)==null?void 0:s.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var i;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.outputs.flatMap(s=>s.toFlatJSON(e)),...this.calledBy.flatMap(s=>s.toFlatJSON(e)),...((i=this.throws)==null?void 0:i.toFlatJSON(e))||[]])}toGenerationTarget(){return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(e=>e.id),calledByError:this.calledByError.map(e=>e.id),calledBySuccess:this.calledBySuccess.map(e=>e.id),parent:this.parent.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.outputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.throws?this.throws.toFlatGenerationTarget(e):[]])}clearErrors(){var e;return this.errors=[],this.outputs.forEach(t=>t.clearErrors()),(e=this.throws)==null||e.clearErrors(),this}validate(){const e=s1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.outputs.flatMap(t=>t.getErrors())]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var E;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.outputs=[];const u=d.split("-id"),y=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=ct(o,l);t?c.setParent(t,null):c.setParent(this.parent,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,A.Added);const I=(E=this.outputs)==null?void 0:E.map((O,P)=>O.clone(e,c,y+"-return-declaration-"+P+"-id",s));return c.outputs=I,this.throws&&(c.throws=this.throws.clone(e,c,y+"-throws-id",s)),e==null||e.attemptAutoclose("clone-entity",this.id),c}};f(Fe,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(Fe,"type",n.ContinueStatement),f(Fe,"USER_MANAGED_PARENT_TYPES",[n.Loop]),f(Fe,"PARENT_TYPES",[...Fe.USER_MANAGED_PARENT_TYPES]),f(Fe,"MUTABLE_BASE_PROPERTIES",[]),f(Fe,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Fe,"BASE_PROPERTIES",[...Fe.MUTABLE_BASE_PROPERTIES,...Fe.INMUTABLE_BASE_PROPERTIES]),f(Fe,"MUTABLE_META_PROPERTIES",["x","y"]),f(Fe,"INMUTABLE_META_PROPERTIES",[...Fe.INMUTABLE_BASE_PROPERTIES]),f(Fe,"META_PROPERTIES",[...Fe.MUTABLE_META_PROPERTIES,...Fe.INMUTABLE_META_PROPERTIES]),f(Fe,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","parent"]),f(Fe,"INMUTABLE_UPSTREAM_PROPERTIES",[]),f(Fe,"UPSTREAM_PROPERTIES",[...Fe.MUTABLE_UPSTREAM_PROPERTIES,...Fe.INMUTABLE_UPSTREAM_PROPERTIES]),f(Fe,"MUTABLE_DOWNSTREAM_PROPERTIES",["outputs","throws"]),f(Fe,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Fe,"DOWNSTREAM_PROPERTIES",[...Fe.MUTABLE_DOWNSTREAM_PROPERTIES,...Fe.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Fe,"PROPERTIES",[...Fe.META_PROPERTIES,...Fe.UPSTREAM_PROPERTIES,...Fe.DOWNSTREAM_PROPERTIES]);let Lt=Fe;var gl=(r=>(r.Parent="parent",r))(gl||{});const nt=class nt extends at{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"x");f(this,"y");f(this,"type",n.ReturnStatement);f(this,"outputs",[]);f(this,"calledBySuccess",[]);f(this,"calledByError",[]);f(this,"calledByEntry",[]);f(this,"throws",null);f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static new(){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ReturnStatement,outputs:[],throws:null,parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],x:0,y:0}}static fromGenerationTarget(e,t){const i=_(e.parent),s=t.get(i),l=e.calledByEntry.map(c=>{const I=_(c);return t.get(I)}),o=e.calledBySuccess.map(c=>{const I=_(c);return t.get(I)}),d=e.calledByError.map(c=>{const I=_(c);return t.get(I)}),u={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ReturnStatement,x:0,y:0,outputs:[],calledBySuccess:o,calledByError:d,calledByEntry:l,throws:null,parent:s},y=C(u,t);return y.setParent(s,null),y.initChildren(null),y}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=At(i,{parent:{list:!1,types:dt}},t);return i=l.modifiedData,s.push(...l.errors,...ut(i)),{errors:s,modifiedData:i}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
58
58
  If an entity is called by another, they must be in the same scope, which means they have the same parent.
59
59
  You shouldn't have to manually update a 'parent' property.
60
- Specifically for return statements the parent needs to always be the 'function-declaration' or 'global-event' that contains it.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],i=[],s=[];return Object.values(this.detachedDependents).forEach(l=>{const o=l.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),i.push(...o.removed),s.push(...o.affected)}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new nt(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.outputs=this.outputs,e.throws=this.throws,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[I,E]of c.knownVersions)u.set(I,E);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new nt(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.outputs=o.outputs,this.throws=o.throws,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);return this.initialData.calledByEntry.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.calledByEntry.forEach(o=>{o.addCall(this,e),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this,e),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this,e),t.push(o)}),this.parent.addReturnStatement(this),t.push(this.parent),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}addSuccessCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,A.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,A.Updated),i&&K(this,t),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,A.Updated),i&&K(this,t),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}removeCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected)),!0):!1),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected)),!0):!1),i&&K(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}addOutputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-output-declaration"))){return this.outputs.find(i=>i.id===e.id)||(this.outputs.push(e),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-output-declaration",this.id),this}removeOutputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-output-declaration"))){return this.outputs.find(i=>i.id===e.id)&&(this.outputs=this.outputs.filter(i=>i.id!==e.id),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("remove-output-declaration",this.id),this}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.outputs=this.initialData.outputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.initialData.throws&&(this.throws=C(this.initialData.throws,this.project),this.throws.setParent(this,null),this.throws.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=g,...t){return await nt.repository.APILoad(this.id,...t),this}async APICreate(e=g,...t){return await nt.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=g,...t){return await nt.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=g,...t){return await nt.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=g,...t){return await nt.repository.APIClone(this.id,...t),this}async APILoadVersion(e=g,t,...i){return await nt.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:y,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...y),l.push(...c)}),this.outputs.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.throws){const{updated:d,removed:u}=this.throws.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}return this.parent.removeReturnStatement(this),e||this.calledBy.forEach(d=>{i.push(d),d.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.throws){const{updated:o}=this.throws.restore({},e);i.push(...o)}return this.parent.addReturnStatement(this),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.outputs.flatMap(i=>i.toFlat(e)),...this.throws?this.throws.toFlat(e):[]])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.outputs.flatMap(i=>i.toFlatIds(e)),...this.throws?this.throws.toFlatIds(e):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,calledBySuccess:this.calledBySuccess.map(s=>s.toReference()),calledByError:this.calledByError.map(s=>s.toReference()),calledByEntry:this.calledByEntry.map(s=>s.toReference()),outputs:this.outputs.map(s=>s.toJSON(e)),parent:((t=this.parent)==null?void 0:t.toReference())||null,throws:((i=this.throws)==null?void 0:i.toJSON(e))||null})}toJSONClone(e=q){var i,s,l,o,d,u,y;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,calledBySuccess:this.calledBySuccess.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),outputs:this.outputs.map(c=>c.toJSONClone({...e,newId:null})),parent:((u=this.parent)==null?void 0:u.toReference({seenEntityMaps:e.seenEntityMaps}))||null,throws:((y=this.throws)==null?void 0:y.toJSONClone({...e,newId:null}))||null})}toReference(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=q){var i,s,l;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,outputs:this.outputs.map(o=>o.toReference(e)),calledBySuccess:this.calledBySuccess.map(o=>o.toReference(e)),calledByError:this.calledByError.map(o=>o.toReference(e)),calledByEntry:this.calledByEntry.map(o=>o.toReference(e)),throws:((s=this.throws)==null?void 0:s.toReference(e))||null,parent:((l=this.parent)==null?void 0:l.toReference(e))||null}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.outputs.flatMap(i=>i.toFlatJSON(e)),...this.throws?this.throws.toFlatJSON(e):[]])}toGenerationTarget(){return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(e=>e.id),calledByError:this.calledByError.map(e=>e.id),calledBySuccess:this.calledBySuccess.map(e=>e.id),parent:this.parent.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.outputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.throws?this.throws.toFlatGenerationTarget(e):[]])}clearErrors(){var e;return this.errors=[],this.outputs.forEach(t=>t.clearErrors()),(e=this.throws)==null||e.clearErrors(),this}validate(){const e=n1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.outputs.flatMap(t=>t.getErrors())]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var E;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.outputs=[];const u=d.split("-id"),y=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=ct(o,l);t?c.setParent(t,null):c.setParent(this.parent,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,A.Added);const I=(E=this.outputs)==null?void 0:E.map((O,P)=>O.clone(e,c,y+"-return-declaration-"+P+"-id",s));return c.outputs=I,this.throws&&(c.throws=this.throws.clone(e,c,y+"-throws-id",s)),e==null||e.attemptAutoclose("clone-entity",this.id),c}};f(nt,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(nt,"type",n.ReturnStatement),f(nt,"USER_MANAGED_PARENT_TYPES",[...dt]),f(nt,"PARENT_TYPES",[...nt.USER_MANAGED_PARENT_TYPES]),f(nt,"MUTABLE_BASE_PROPERTIES",[]),f(nt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(nt,"BASE_PROPERTIES",[...Lt.MUTABLE_BASE_PROPERTIES,...Lt.INMUTABLE_BASE_PROPERTIES]),f(nt,"MUTABLE_META_PROPERTIES",["x","y"]),f(nt,"INMUTABLE_META_PROPERTIES",[...Lt.INMUTABLE_BASE_PROPERTIES]),f(nt,"META_PROPERTIES",[...Lt.MUTABLE_META_PROPERTIES,...Lt.INMUTABLE_META_PROPERTIES]),f(nt,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","parent"]),f(nt,"INMUTABLE_UPSTREAM_PROPERTIES",[]),f(nt,"UPSTREAM_PROPERTIES",[...Lt.MUTABLE_UPSTREAM_PROPERTIES,...Lt.INMUTABLE_UPSTREAM_PROPERTIES]),f(nt,"MUTABLE_DOWNSTREAM_PROPERTIES",["outputs","throws"]),f(nt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(nt,"DOWNSTREAM_PROPERTIES",[...Lt.MUTABLE_DOWNSTREAM_PROPERTIES,...Lt.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(nt,"PROPERTIES",[...ai.META_PROPERTIES,...ai.UPSTREAM_PROPERTIES,...ai.DOWNSTREAM_PROPERTIES]);let gr=nt;function a1(r){const a=sZ(),e=r.toJSON();a.safeParse(e).success;const i=Eq(r),s=Aq(r),l=oi(r);r.inputs.forEach(d=>d.validate()),l.forEach(d=>d.validate());const o=[...i,...s];if(r.id==="getCompanyByIdEndpointReachedEntityEvent"){const d=de({id:`${r.id}--${F.PropertyImplementsNonAbstact}`,message:`Property "${x(r,r.project)}" with id "${r.id}" implements a non-abstract property "${x(r,r.project)}" with id "${r.id}".`,issue:null,severity:D.Error,code:F.PropertyImplementsNonAbstact,entity:r});o.push(d.error)}return He(r.errors,o)}function Eq(r){const a=[];if(!r.calls.length){const e=de({id:`${r.id}--${F.ScopeWithoutLogic}`,message:`Action "${x(r,r.project)}" with id "${r.id}" does not have any logic defined. So it doesn't do anything.`,issue:null,severity:D.Warning,code:F.ScopeWithoutLogic,entity:r});a.push(e.error)}return He(r.errors,a)}function Aq(r){const a=[];return r.implements,He(r.errors,a)}const bq=Object.freeze(Object.defineProperty({__proto__:null,validate:a1},Symbol.toStringTag,{value:"Module"}));var o1=(r=>(r.Implements="implements",r))(o1||{});const Re=class Re extends at{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"x");f(this,"y");f(this,"collapsed");f(this,"private");f(this,"index",null);f(this,"type",n.FunctionDeclaration);f(this,"implements",null);f(this,"inputs",[]);f(this,"calls",[]);f(this,"parent");f(this,"detachedChildren",[]);f(this,"errors",[]);f(this,"project");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description,this.private=e.private,this.collapsed=e.collapsed,this.x=e.x,this.y=e.y,this.index=e.index}static new(){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.FunctionDeclaration,name:"",description:"",collapsed:!1,private:!1,index:null,implements:null,inputs:[],parent:null,calls:[],x:0,y:0}}static fromGenerationTarget(e,t){let i=t;if(e.parent){const d=_(e.parent);i=t.get(d)}let s=null;if(e.implements){const d=_(e.implements);s=t.get(d)}const l={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,type:n.FunctionDeclaration,index:i.type===n.DefinitionEntity?i.methods.length:null,description:e.description,collapsed:!1,private:!1,calls:[],inputs:[],implements:s,x:0,y:0,parent:i},o=C(l,t);return o.setParent(i,null),o.initChildren(null),o}static validateGenerationTarget(e,t){var c;let i=JSON.parse(JSON.stringify(e));const s=[],l=At(i,{parent:{list:!1,types:[n.Project,n.InstalledProject,n.DefinitionEntity,n.Loop],optional:!0},implements:{list:!1,types:[n.ActionDescriptor],optional:!0}},t);i=l.modifiedData;const o=Ec(i,t),d=i.parent?t.get(i.parent):null;if(d&&d.type===n.DefinitionEntity){const I=d,O=kt(I).filter(P=>!P.interactive);if(O.length){let P=O.length>1?`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${I.id}' because it extends or implements multiple '${n.BuiltInBaseEntity}' entities that are non-interactive ("${ne(O.map(V=>x(V,V.project)),'", "','" and "')}").`:`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${I.id}' because it extends or implements a '${n.BuiltInBaseEntity}' entity that is non-interactive ("${x(O[0],O[0].project)}").`;P+=`
60
+ Specifically for return statements the parent needs to always be the 'function-declaration' or 'global-event' that contains it.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],i=[],s=[];return Object.values(this.detachedDependents).forEach(l=>{const o=l.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),i.push(...o.removed),s.push(...o.affected)}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new nt(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.outputs=this.outputs,e.throws=this.throws,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[I,E]of c.knownVersions)u.set(I,E);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new nt(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.outputs=o.outputs,this.throws=o.throws,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);return this.initialData.calledByEntry.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.calledByEntry.forEach(o=>{o.addCall(this,e),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this,e),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this,e),t.push(o)}),this.parent.addReturnStatement(this),t.push(this.parent),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}addSuccessCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,A.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,A.Updated),i&&K(this,t),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,A.Updated),i&&K(this,t),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}removeCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected)),!0):!1),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected)),!0):!1),i&&K(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}addOutputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-output-declaration"))){return this.outputs.find(i=>i.id===e.id)||(this.outputs.push(e),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-output-declaration",this.id),this}removeOutputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-output-declaration"))){return this.outputs.find(i=>i.id===e.id)&&(this.outputs=this.outputs.filter(i=>i.id!==e.id),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("remove-output-declaration",this.id),this}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.outputs=this.initialData.outputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.initialData.throws&&(this.throws=C(this.initialData.throws,this.project),this.throws.setParent(this,null),this.throws.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=g,...t){return await nt.repository.APILoad(this.id,...t),this}async APICreate(e=g,...t){return await nt.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=g,...t){return await nt.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=g,...t){return await nt.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=g,...t){return await nt.repository.APIClone(this.id,...t),this}async APILoadVersion(e=g,t,...i){return await nt.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:y,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...y),l.push(...c)}),this.outputs.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.throws){const{updated:d,removed:u}=this.throws.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}return this.parent.removeReturnStatement(this),e||this.calledBy.forEach(d=>{i.push(d),d.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.throws){const{updated:o}=this.throws.restore({},e);i.push(...o)}return this.parent.addReturnStatement(this),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.outputs.flatMap(i=>i.toFlat(e)),...this.throws?this.throws.toFlat(e):[]])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.outputs.flatMap(i=>i.toFlatIds(e)),...this.throws?this.throws.toFlatIds(e):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,calledBySuccess:this.calledBySuccess.map(s=>s.toReference()),calledByError:this.calledByError.map(s=>s.toReference()),calledByEntry:this.calledByEntry.map(s=>s.toReference()),outputs:this.outputs.map(s=>s.toJSON(e)),parent:((t=this.parent)==null?void 0:t.toReference())||null,throws:((i=this.throws)==null?void 0:i.toJSON(e))||null})}toJSONClone(e=q){var i,s,l,o,d,u,y;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,calledBySuccess:this.calledBySuccess.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),outputs:this.outputs.map(c=>c.toJSONClone({...e,newId:null})),parent:((u=this.parent)==null?void 0:u.toReference({seenEntityMaps:e.seenEntityMaps}))||null,throws:((y=this.throws)==null?void 0:y.toJSONClone({...e,newId:null}))||null})}toReference(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=q){var i,s,l;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,outputs:this.outputs.map(o=>o.toReference(e)),calledBySuccess:this.calledBySuccess.map(o=>o.toReference(e)),calledByError:this.calledByError.map(o=>o.toReference(e)),calledByEntry:this.calledByEntry.map(o=>o.toReference(e)),throws:((s=this.throws)==null?void 0:s.toReference(e))||null,parent:((l=this.parent)==null?void 0:l.toReference(e))||null}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.outputs.flatMap(i=>i.toFlatJSON(e)),...this.throws?this.throws.toFlatJSON(e):[]])}toGenerationTarget(){return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(e=>e.id),calledByError:this.calledByError.map(e=>e.id),calledBySuccess:this.calledBySuccess.map(e=>e.id),parent:this.parent.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.outputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.throws?this.throws.toFlatGenerationTarget(e):[]])}clearErrors(){var e;return this.errors=[],this.outputs.forEach(t=>t.clearErrors()),(e=this.throws)==null||e.clearErrors(),this}validate(){const e=n1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.outputs.flatMap(t=>t.getErrors())]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var E;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.outputs=[];const u=d.split("-id"),y=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=ct(o,l);t?c.setParent(t,null):c.setParent(this.parent,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,A.Added);const I=(E=this.outputs)==null?void 0:E.map((O,P)=>O.clone(e,c,y+"-return-declaration-"+P+"-id",s));return c.outputs=I,this.throws&&(c.throws=this.throws.clone(e,c,y+"-throws-id",s)),e==null||e.attemptAutoclose("clone-entity",this.id),c}};f(nt,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(nt,"type",n.ReturnStatement),f(nt,"USER_MANAGED_PARENT_TYPES",[...dt]),f(nt,"PARENT_TYPES",[...nt.USER_MANAGED_PARENT_TYPES]),f(nt,"MUTABLE_BASE_PROPERTIES",[]),f(nt,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(nt,"BASE_PROPERTIES",[...Lt.MUTABLE_BASE_PROPERTIES,...Lt.INMUTABLE_BASE_PROPERTIES]),f(nt,"MUTABLE_META_PROPERTIES",["x","y"]),f(nt,"INMUTABLE_META_PROPERTIES",[...Lt.INMUTABLE_BASE_PROPERTIES]),f(nt,"META_PROPERTIES",[...Lt.MUTABLE_META_PROPERTIES,...Lt.INMUTABLE_META_PROPERTIES]),f(nt,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","parent"]),f(nt,"INMUTABLE_UPSTREAM_PROPERTIES",[]),f(nt,"UPSTREAM_PROPERTIES",[...Lt.MUTABLE_UPSTREAM_PROPERTIES,...Lt.INMUTABLE_UPSTREAM_PROPERTIES]),f(nt,"MUTABLE_DOWNSTREAM_PROPERTIES",["outputs","throws"]),f(nt,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(nt,"DOWNSTREAM_PROPERTIES",[...Lt.MUTABLE_DOWNSTREAM_PROPERTIES,...Lt.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(nt,"PROPERTIES",[...ai.META_PROPERTIES,...ai.UPSTREAM_PROPERTIES,...ai.DOWNSTREAM_PROPERTIES]);let gr=nt;function a1(r){const a=sZ(),e=r.toJSON();a.safeParse(e).success;const i=E7(r),s=A7(r),l=oi(r);r.inputs.forEach(d=>d.validate()),l.forEach(d=>d.validate());const o=[...i,...s];if(r.id==="getCompanyByIdEndpointReachedEntityEvent"){const d=de({id:`${r.id}--${F.PropertyImplementsNonAbstact}`,message:`Property "${x(r,r.project)}" with id "${r.id}" implements a non-abstract property "${x(r,r.project)}" with id "${r.id}".`,issue:null,severity:D.Error,code:F.PropertyImplementsNonAbstact,entity:r});o.push(d.error)}return He(r.errors,o)}function E7(r){const a=[];if(!r.calls.length){const e=de({id:`${r.id}--${F.ScopeWithoutLogic}`,message:`Action "${x(r,r.project)}" with id "${r.id}" does not have any logic defined. So it doesn't do anything.`,issue:null,severity:D.Warning,code:F.ScopeWithoutLogic,entity:r});a.push(e.error)}return He(r.errors,a)}function A7(r){const a=[];return r.implements,He(r.errors,a)}const b7=Object.freeze(Object.defineProperty({__proto__:null,validate:a1},Symbol.toStringTag,{value:"Module"}));var o1=(r=>(r.Implements="implements",r))(o1||{});const Re=class Re extends at{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"x");f(this,"y");f(this,"collapsed");f(this,"private");f(this,"index",null);f(this,"type",n.FunctionDeclaration);f(this,"implements",null);f(this,"inputs",[]);f(this,"calls",[]);f(this,"parent");f(this,"detachedChildren",[]);f(this,"errors",[]);f(this,"project");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description,this.private=e.private,this.collapsed=e.collapsed,this.x=e.x,this.y=e.y,this.index=e.index}static new(){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.FunctionDeclaration,name:"",description:"",collapsed:!1,private:!1,index:null,implements:null,inputs:[],parent:null,calls:[],x:0,y:0}}static fromGenerationTarget(e,t){let i=t;if(e.parent){const d=_(e.parent);i=t.get(d)}let s=null;if(e.implements){const d=_(e.implements);s=t.get(d)}const l={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,type:n.FunctionDeclaration,index:i.type===n.DefinitionEntity?i.methods.length:null,description:e.description,collapsed:!1,private:!1,calls:[],inputs:[],implements:s,x:0,y:0,parent:i},o=C(l,t);return o.setParent(i,null),o.initChildren(null),o}static validateGenerationTarget(e,t){var c;let i=JSON.parse(JSON.stringify(e));const s=[],l=At(i,{parent:{list:!1,types:[n.Project,n.InstalledProject,n.DefinitionEntity,n.Loop],optional:!0},implements:{list:!1,types:[n.ActionDescriptor],optional:!0}},t);i=l.modifiedData;const o=Ec(i,t),d=i.parent?t.get(i.parent):null;if(d&&d.type===n.DefinitionEntity){const I=d,O=kt(I).filter(P=>!P.interactive);if(O.length){let P=O.length>1?`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${I.id}' because it extends or implements multiple '${n.BuiltInBaseEntity}' entities that are non-interactive ("${ne(O.map(V=>x(V,V.project)),'", "','" and "')}").`:`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${I.id}' because it extends or implements a '${n.BuiltInBaseEntity}' entity that is non-interactive ("${x(O[0],O[0].project)}").`;P+=`
61
61
  ${Qr}`,s.push(new w({id:`${e.id}--${R.NonInteractiveEntityReferenced}`,code:R.NonInteractiveEntityReferenced,severity:D.Error,message:P,issue:null}))}else{const P=I.methods.find(G=>{var B;return((B=G.implements)==null?void 0:B.id)===i.implements});P&&s.push(new w({id:`${i.id}--${j.MethodOverwritesOtherSiblingWithSameImplementation}`,code:j.MethodOverwritesOtherSiblingWithSameImplementation,severity:D.Error,message:`The '${n.FunctionDeclaration}' with id "${i.id}" is trying to implement the '${n.ActionDescriptor}' with id "${i.implements}", but the parent definition-entity already has a ${n.FunctionDeclaration} with id '${P.id}' that implements the same base method.
62
62
  A ${n.FunctionDeclaration} that has a parent of type '${n.DefinitionEntity}' is considered a method of that entity, and cannot implement the same '${n.ActionDescriptor}' more than once.
63
63
  ${n.ActionDescriptor} entities inside a ${n.DefinitionEntity} are considered abstract methods that can be implemented by ${n.FunctionDeclaration} entities inside the same parent.
@@ -67,26 +67,26 @@ If you want to implement a new method, you can create a new 'function-declaratio
67
67
  If you want to modify the existing implementation, you can update the existing method instead, but it will have to match the same base ${n.ActionDescriptor} signature, otherwise the implementation will have a validation error.`,issue:null}))}}else if(d&&d.type===n.Loop){const I=d.body;I&&((c=I.implements)==null?void 0:c.id)===i.implements&&s.push(new w({id:`${i.id}--${j.LoopBodyFunctionOverwrite}`,code:j.LoopBodyFunctionOverwrite,severity:D.Error,message:`The '${n.FunctionDeclaration}' with id "${i.id}" is being added as the 'body' of the ${n.Loop} with id "${d.id}", but the loop already has a function-declaration body. A loop can only have one function-declaration body at a time. You can edit the existing body instead, but it will have to match the same base signature, otherwise the implementation will have a validation error.`,issue:null}))}const u=i.parent&&t.get(i.parent)||t.getBuiltIn(i.parent),y=u?rn(u):null;return y&&s.push(new w({id:`${e.id}--${R.BuiltInEntityParent}`,code:R.BuiltInEntityParent,severity:D.Error,message:`The entity with id '${e.id}' and type '${e.type}', belongs to a built-in system entity "${x(y,t)}" with id '${y.id}', and therefore it cannot be created as it would affect a built in entity, which are inmutable.`,issue:null})),s.push(...l.errors,...o,...ut(i)),{errors:s,modifiedData:i}}get returnStatements(){const e=[];return Object.values(this.detachedDependents).forEach(t=>{t.field===gl.Parent&&t.entity.type===n.ReturnStatement&&!e.includes(t.entity)&&e.push(t.entity)}),e}validateGeneratedUpdate(e){const t=[];return e.parent&&(this.parent.type===n.Project?t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated, as it would mean moving the '${this.type}' entity to another parent entity.
68
68
  This is likely an incorrect strategy because this is a globally declared '${this.type}' entity which can only have the root project as its parent.`,issue:null})):t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated, as it would mean moving the '${this.type}' entity to another parent entity.
69
69
  This is likely an incorrect strategy because this function declaration is a method, since it belongs to a '${this.parent.type}' entity, either the '${this.type}' entity doesn't need to be updated or it should be deleted and a new one created in the desired parent.
70
- Please consider than any updates might affect the overlap with the signature of the parent entity's action descriptors.`,issue:null}))),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],i=[],s=[];return Object.values(this.detachedDependents).forEach(l=>{const o=l.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),i.push(...o.removed),s.push(...o.affected)}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];return t==="implements"&&this.setImplements(null,i),{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];return t==="implements"&&(this.setImplements(e,i),s.push(e)),{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e;return(e=this.implements)==null||e.subscribeDependents([{entity:this,field:"implements"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Re(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.calls=this.calls,e.implements=this.implements,e.detachedChildren=this.detachedChildren,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent&&this.parent.type!==n.PrimitiveEntity&&this.parent.type!==n.BuiltInBaseEntity){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[I,E]of c.knownVersions)u.set(I,E);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Re(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.calls=o.calls,this.implements=o.implements,this.detachedChildren=o.detachedChildren,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${xt(this.type)} with id '${this.id}' has a 'parent' reference "${l}" which is missing in the project`)}else throw new Error(`${xt(this.type)} with id '${this.id}' is missing a 'parent' reference`);if(this.initialData.implements){const l=_(this.initialData.implements),o=this.project.get(l);if(o)this.setImplements(o,null),e.push(o);else if(l)throw new Error(`${xt(this.type)} with id '${this.id}' has a 'implements' reference "${l}" which is missing in the project`)}return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.parent===this.project?this.project.addFunctionDeclaration(this):this.parent.type===n.DefinitionEntity?(this.parent.addMethod(this),t.push(this.parent)):this.parent.type===n.Loop&&(this.parent.setBody(this),t.push(this.parent)),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}replaceDetachedChild(e,t){const i=this.detachedChildren.indexOf(e);return i!==-1&&(this.detachedChildren[i]=t),this}subscribeDetachedChild(e){return this.detachedChildren.includes(e)||this.detachedChildren.push(e),this}addInputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-input-declaration"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input-declaration",this.id),this):(this.inputs.push(e),t==null||t.attemptAutoclose("add-input-declaration",this.id),this)}removeInputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-input-declaration"))){const i=this.inputs.findIndex(s=>s.id===e.id);return i>-1&&(this.inputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-input-declaration",this.id),this}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setImplements(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-implements"))){var i;return((i=this.implements)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.implements=e,t&&(t==null||t.add(this,A.Updated),t==null||t.attemptAutoclose("set-implements",this.id))),this}addCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-call"))){return this.calls.includes(e)||(this.calls.push(e),t==null||t.add(e,A.Affected)),t==null||t.attemptAutoclose("add-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-call"))){const i=this.calls.indexOf(e);return i!==-1&&(this.calls.splice(i,1),t==null||t.add(e,A.Affected)),t==null||t.attemptAutoclose("remove-call",this.id),this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.inputs=this.initialData.inputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.calls=this.initialData.calls.map(t=>{const i=C(t,this.project);return i.addEntryCaller(this,null),[n.BreakStatement,n.ContinueStatement].includes(i.type)?(i.setParent(this.parent,null),i.initChildren(e)):i.type!==n.InternalCall&&(i.setParent(this,null),i.initChildren(e)),i}),this.initialData.implements&&(this.implements=C(this.initialData.implements,this.project)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.name=e.name||s.name,this.description=e.description||s.description,this.private=e.private!==void 0?e.private:this.private,this.index=e.index||(e.index!==0?s.index:0),this.collapsed=e.collapsed!==void 0?e.collapsed:s.collapsed,this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=g,...t){return await Re.repository.APILoad(this.id,...t),this}async APICreate(e=g,...t){return await Re.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=g,...t){return await Re.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=g,...t){return await Re.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=g,...t){return await Re.repository.APIClone(this.id,...t),this}async APILoadVersion(e=g,t,...i){return await Re.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];return t!=null&&t.hasRemoved(this.id)?(t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(u=>{const{updated:y,removed:c,added:I}=u.entity.onDetachedDependencyRemoved(this,u.field,t);i.push(...y),s.push(...c),l.push(...I)}),this.inputs.forEach(u=>{const{updated:y,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...y),s.push(...c)}),oi(this).forEach(u=>{const{updated:y,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...y),s.push(...c)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this})}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.inputs.forEach(d=>{const{updated:u}=d.restore({},e);i.push(...u)}),oi(this).forEach(d=>{const{updated:u}=d.restore({},e);i.push(...u)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.inputs.flatMap(i=>i.toFlat(e)),...this.calls.flatMap(i=>i.toFlat(e)),...this.returnStatements.flatMap(i=>i.toFlat(e)),...this.implements?this.implements.toFlat(e):[]])}toFlatIds(e=new Set){if(e.has(this.id))return[];e.add(this.id);const t=oi(this);return[this.id,...this.inputs.flatMap(s=>s.toFlatIds(e)),...this.calls.flatMap(s=>s.toFlatIds(e)),...this.returnStatements.flatMap(s=>s.toFlatIds(e)),...this.implements?this.implements.toFlatIds(e):[],...t.flatMap(s=>s.toFlatIds(e))]}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,collapsed:this.collapsed,private:this.private,index:this.index,x:this.x,y:this.y,type:this.type,name:this.name}}toJSON(e=new Set){var t;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,x:this.x,y:this.y,collapsed:this.collapsed,private:this.private,calls:this.calls.map(i=>i.toJSON(e)),inputs:this.inputs.map(i=>i.toJSON(e)),implements:((t=this.implements)==null?void 0:t.toJSON(e))||null,parent:this.parent.toReference()})}toJSONClone(e=q){var i,s,l,o,d;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,x:this.x,y:this.y,collapsed:this.collapsed,private:this.private,calls:this.calls.map(u=>u.toJSONClone({...e,newId:null})),inputs:this.inputs.map(u=>u.toJSONClone({...e,newId:null})),implements:(()=>{var u;return this.implements&&this.project.getBuiltIn(this.implements.id)?this.implements.toJSON():(u=this.implements)==null?void 0:u.toJSONClone({...e,newId:null})})(),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=q){var i,s;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,collapsed:this.collapsed,private:this.private,x:this.x,y:this.y,inputs:this.inputs.map(l=>l.toReference(e)),calls:this.calls.map(l=>l.toReference(e)),implements:((s=this.implements)==null?void 0:s.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.inputs.flatMap(i=>i.toFlatJSON(e)),...this.calls.flatMap(i=>i.toFlatJSON(e)),...this.returnStatements.flatMap(i=>i.toFlatJSON(e)),...this.implements?this.implements.toFlatJSON(e):[]])}toGenerationTarget(){var t;const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,name:this.name,description:this.description,type:this.type,private:this.private,implements:((t=this.implements)==null?void 0:t.id)||null,parent:e}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.inputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.calls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.returnStatements.flatMap(i=>i.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.inputs.forEach(e=>e.clearErrors()),this.calls.forEach(e=>e.clearErrors()),this.returnStatements.forEach(e=>e.clearErrors()),this}validate(){const e=a1(this);return this.errors=[...e],{success:!0,error:null,data:this.toJSON()}}getErrors(){const e=oi(this);return[...this.errors,...this.inputs.flatMap(i=>i.getErrors()),...e.flatMap(i=>i.getErrors())]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0,l=!1){var P;let o=mt(t,this);const d=this.toJSON(),u=i||m.UUID.uuid();d.inputs=[],d.calls=[];const y=u.split("-id"),c=y[y.length-1||0]||u;d.id=u,d.version=m.UUID.uuid(),d.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),d.author=(e==null?void 0:e.author)||"1",d.previousVersion=null,d.deleted=!1;const I=ct(d,o);t?I.setParent(t,null):I.setParent(this.parent,null),s&&I.subscribe(),I.initChildren(e),e==null||e.add(I,A.Added);const E=(P=this.inputs)==null?void 0:P.map((V,M)=>V.clone(e,I,c+"-argument-declaration-"+M+"-id",s));return I.inputs=E,l?(oi(this).map((V,M)=>V.clone(e,I,c+"-body-entity-"+M+"-id")),e==null||e.attemptAutoclose("clone-entity",this.id),I):(e==null||e.attemptAutoclose("clone-entity",this.id),I)}getVariableInstances(){return Ye(this).filter(i=>i.type===n.VariableInstance)}getArgument(e){return this.inputs.find(t=>t.id===e)||null}createCall(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"create-call")),t=this.project,i={}){const s={id:i.id||m.UUID.uuid(),version:i.version||m.UUID.uuid(),createdAt:i.createdAt||T().toISOString(),author:i.author||"1",previousVersion:i.previousVersion||null,deleted:i.deleted||!1,type:n.FunctionCall,parent:t.toReference(),successCalls:i.successCalls||[],errorCalls:i.errorCalls||[],inputs:i.inputs||[],outputs:i.outputs||[],error:i.error||null,process:i.process||null,calledBySuccess:i.calledBySuccess||[],calledByError:i.calledByError||[],calledByEntry:i.calledByEntry||[],declaration:this.toJSON(),x:0,y:0},l=C(s,this.project);return l.setParent(t,e),l.initChildren(e),e==null||e.add(l,A.Added),l.hydrateAncestors(),l.afterAllChildrenInitialized(e),t===this.project&&this.project.addFunctionCall(l),e==null||e.attemptAutoclose("create-call",this.id),l}createInternalCall(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"create-internal")),t,i={}){const s={id:i.id||m.UUID.uuid(),version:i.version||m.UUID.uuid(),type:n.InternalCall,parent:t.toReference(),successCalls:i.successCalls||[],deleted:i.deleted||!1,errorCalls:i.errorCalls||[],inputs:i.inputs||[],outputs:i.outputs||[],error:i.error||null,process:i.process||null,calledBySuccess:i.calledBySuccess||[],calledByError:i.calledByError||[],calledByEntry:i.calledByEntry||[],declaration:this.toShallowJSON(),index:t.internalCalls.length},l=C(s,this.project);return l.setParent(t,e),l.initChildren(e),e==null||e.add(l,A.Added),l.hydrateAncestors(),l.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("create-internal",this.id),l}addReturnStatement(e){return this.returnStatements.includes(e)||this.returnStatements.push(e),this}removeReturnStatement(e){const t=this.returnStatements.indexOf(e);return t!==-1&&this.returnStatements.splice(t,1),this}getUniqueReturnDeclarations(){const e=[],i=[...this.returnStatements].flatMap(s=>s.outputs);if(this.implements){const s=this.implements.outputs;return i.forEach(l=>{const o=s.find(u=>u===l.implements),d=e.find(u=>u.implements===l.implements);o&&!d&&e.push(l)}),p(e)}else return i.forEach(s=>{e.find(o=>o===s||x(o,this.project)===x(s,this.project)&&Ri(o.dataType,s.dataType))||e.push(s)}),p(e)}};f(Re,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(Re,"type",n.FunctionDeclaration),f(Re,"USER_MANAGED_PARENT_TYPES",[n.Project,n.InstalledProject,n.DefinitionEntity,n.Loop]),f(Re,"PARENT_TYPES",[...Re.USER_MANAGED_PARENT_TYPES,n.BuiltInBaseEntity,n.PrimitiveEntity]),f(Re,"MUTABLE_BASE_PROPERTIES",["name","description","private"]),f(Re,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Re,"BASE_PROPERTIES",[...Re.MUTABLE_BASE_PROPERTIES,...Re.INMUTABLE_BASE_PROPERTIES]),f(Re,"MUTABLE_META_PROPERTIES",[...Re.MUTABLE_BASE_PROPERTIES,"x","y","index","collapsed"]),f(Re,"INMUTABLE_META_PROPERTIES",[...Re.INMUTABLE_BASE_PROPERTIES]),f(Re,"META_PROPERTIES",[...Re.MUTABLE_META_PROPERTIES,...Re.INMUTABLE_META_PROPERTIES]),f(Re,"MUTABLE_UPSTREAM_PROPERTIES",[]),f(Re,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements"]),f(Re,"UPSTREAM_PROPERTIES",[...Re.MUTABLE_UPSTREAM_PROPERTIES,...Re.INMUTABLE_UPSTREAM_PROPERTIES]),f(Re,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","calls","returnStatements"]),f(Re,"INMUATABLE_DOWNSTREAM_PROPERTIES",[]),f(Re,"DOWNSTREAM_PROPERTIES",[...Re.MUTABLE_DOWNSTREAM_PROPERTIES,...Re.INMUATABLE_DOWNSTREAM_PROPERTIES]),f(Re,"PROPERTIES",[...Re.META_PROPERTIES,...Re.UPSTREAM_PROPERTIES,...Re.DOWNSTREAM_PROPERTIES]);let jr=Re;function l1(r){const a=uS(),e=r.toJSON();a.safeParse(e).success;const i=[];if(r.entity&&r.andChildrenGroup||r.entity&&r.orChildrenGroup||r.andChildrenGroup&&r.orChildrenGroup){const s=de({id:r.id+"--"+F.InvalidPropertiesCombination,message:`Data type with id "${r.id}" has invalid properties combination. Only one of the following properties can be present at the time: 'entity', 'andChildrenGroup' or 'orChildrenGroup'`,issue:null,severity:D.Error,code:F.InvalidPropertiesCombination,entity:r});i.push(s.error)}return He(r.errors,i)}const Rq=Object.freeze(Object.defineProperty({__proto__:null,validate:l1},Symbol.toStringTag,{value:"Module"}));function Dq(r,a){const e=[],t=[n.DefinitionEntity,n.ActionDescriptor,n.Property,n.ArgumentDeclaration,n.ReturnDeclaration,n.VariableDeclaration,n.ValueDescriptor,n.DataType],i=`'${ne(t,"', '","' or '")}'`;if(r.parent)if(r.id===r.parent)e.push(new w({id:`${r.id}--${r.parent}--${R.SelfReference}`,code:R.SelfReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a reference to itself at 'parent'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null}));else{const s=a.get(r.parent);s?t.includes(s.type)||e.push(new w({id:`${r.id}--${r.parent}--${R.InvalidParentReference}`,code:R.InvalidParentReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a parent reference that isn't pointing to an entity of type ${i}.`,issue:null})):e.push(new w({id:`${r.id}--${r.parent}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", is referencing an entity with id "${r.parent}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}else e.push(new w({id:`${r.id}--${j.InvalidObjectStructure}`,code:j.InvalidObjectStructure,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}" is missing a 'parent' reference. The 'parent' of a 'data-type' entity must be a reference to an entity of type ${i}.`,issue:null}));if(r.entity){if(r.id===r.entity)return e.push(new w({id:`${r.id}--${r.entity}--${R.SelfReference}`,code:R.SelfReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a reference to itself at 'entity'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null})),e;const s=a.get(r.entity);s?[n.DefinitionEntity,n.PrimitiveEntity,n.ActionDescriptor,n.BuiltInBaseEntity].includes(s.type)||e.push(new w({id:`${r.id}--${r.entity}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has an 'entity' reference that isn't pointing to an entity of type 'definition-entity', 'primitive-entity', 'action-descriptor' or 'built-in-base-entity'.`,issue:null})):e.push(new w({id:`${r.id}--${r.entity}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", is referencing an entity with id "${r.entity}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}return e}var Cc=(r=>(r.Entity="entity",r))(Cc||{});const De=class De extends at{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"isList",null);f(this,"asType",null);f(this,"type",n.DataType);f(this,"options",null);f(this,"parentRelationType",null);f(this,"like");f(this,"implementationChooseOne",!1);f(this,"inferred",!1);f(this,"entity",null);f(this,"andChildrenGroup",null);f(this,"orChildrenGroup",null);f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);this.initialData=e,this.project=t,this.id=e.id,this.isList=e.isList,this.asType=e.asType,this.options=e.options,this.parentRelationType=e.parentRelationType,this.inferred=e.inferred||!1,this.like=e.like||!1,this.implementationChooseOne=e.implementationChooseOne||!1}static new(){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,entity:null,isList:!1,like:!1,inferred:!1,implementationChooseOne:!1,parentRelationType:null,options:null,asType:null,andChildrenGroup:null,orChildrenGroup:null,parent:null}}static fromGenerationTarget(e,t){const i=_(e.parent),s=t.get(i);let l=null;e.entity&&(l=t.get(e.entity));const o={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,andChildrenGroup:null,orChildrenGroup:null,parentRelationType:e.parentRelationType||null,options:e.options||null,isList:e.isList,like:e.like||!1,inferred:!1,implementationChooseOne:e.implementationChooseOne||!1,entity:l,asType:e.asType,parent:s},d=C(o,t);return d.setParent(s,null),d.initChildren(null),d}static validateGenerationTarget(e,t){var u;let i=JSON.parse(JSON.stringify(e));const s=[],l=Dq(i,t);if(s.push(...l,...ut(i)),i.entity){const y=t.get(i.entity);if(y.type===n.DefinitionEntity){const I=kt(y).filter(E=>!E.interactive);if(I.length){const E=I.length>1?`entities with ids '${ne(I.map(O=>O.id),"', '","' and '")}'`:`entity with id '${I[0].id}'`;s.push(new w({id:`${e.id}--${R.NonInteractiveEntityReferenced}`,code:R.NonInteractiveEntityReferenced,severity:D.Error,message:`The entity with id '${e.id}' and type '${e.type}', cannot reference 'definition-entity' with id '${i.entity}' at 'entity'. The entity extends or implements non-interactive built-in-base-entity ${E}.
70
+ Please consider than any updates might affect the overlap with the signature of the parent entity's action descriptors.`,issue:null}))),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],i=[],s=[];return Object.values(this.detachedDependents).forEach(l=>{const o=l.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),i.push(...o.removed),s.push(...o.affected)}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];return t==="implements"&&this.setImplements(null,i),{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];return t==="implements"&&(this.setImplements(e,i),s.push(e)),{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e;return(e=this.implements)==null||e.subscribeDependents([{entity:this,field:"implements"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Re(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.calls=this.calls,e.implements=this.implements,e.detachedChildren=this.detachedChildren,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent&&this.parent.type!==n.PrimitiveEntity&&this.parent.type!==n.BuiltInBaseEntity){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[I,E]of c.knownVersions)u.set(I,E);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Re(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.calls=o.calls,this.implements=o.implements,this.detachedChildren=o.detachedChildren,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${xt(this.type)} with id '${this.id}' has a 'parent' reference "${l}" which is missing in the project`)}else throw new Error(`${xt(this.type)} with id '${this.id}' is missing a 'parent' reference`);if(this.initialData.implements){const l=_(this.initialData.implements),o=this.project.get(l);if(o)this.setImplements(o,null),e.push(o);else if(l)throw new Error(`${xt(this.type)} with id '${this.id}' has a 'implements' reference "${l}" which is missing in the project`)}return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.parent===this.project?this.project.addFunctionDeclaration(this):this.parent.type===n.DefinitionEntity?(this.parent.addMethod(this),t.push(this.parent)):this.parent.type===n.Loop&&(this.parent.setBody(this),t.push(this.parent)),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}replaceDetachedChild(e,t){const i=this.detachedChildren.indexOf(e);return i!==-1&&(this.detachedChildren[i]=t),this}subscribeDetachedChild(e){return this.detachedChildren.includes(e)||this.detachedChildren.push(e),this}addInputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-input-declaration"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input-declaration",this.id),this):(this.inputs.push(e),t==null||t.attemptAutoclose("add-input-declaration",this.id),this)}removeInputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-input-declaration"))){const i=this.inputs.findIndex(s=>s.id===e.id);return i>-1&&(this.inputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-input-declaration",this.id),this}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setImplements(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-implements"))){var i;return((i=this.implements)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.implements=e,t&&(t==null||t.add(this,A.Updated),t==null||t.attemptAutoclose("set-implements",this.id))),this}addCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-call"))){return this.calls.includes(e)||(this.calls.push(e),t==null||t.add(e,A.Affected)),t==null||t.attemptAutoclose("add-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-call"))){const i=this.calls.indexOf(e);return i!==-1&&(this.calls.splice(i,1),t==null||t.add(e,A.Affected)),t==null||t.attemptAutoclose("remove-call",this.id),this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.inputs=this.initialData.inputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.calls=this.initialData.calls.map(t=>{const i=C(t,this.project);return i.addEntryCaller(this,null),[n.BreakStatement,n.ContinueStatement].includes(i.type)?(i.setParent(this.parent,null),i.initChildren(e)):i.type!==n.InternalCall&&(i.setParent(this,null),i.initChildren(e)),i}),this.initialData.implements&&(this.implements=C(this.initialData.implements,this.project)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.name=e.name||s.name,this.description=e.description||s.description,this.private=e.private!==void 0?e.private:this.private,this.index=e.index||(e.index!==0?s.index:0),this.collapsed=e.collapsed!==void 0?e.collapsed:s.collapsed,this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=g,...t){return await Re.repository.APILoad(this.id,...t),this}async APICreate(e=g,...t){return await Re.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=g,...t){return await Re.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=g,...t){return await Re.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=g,...t){return await Re.repository.APIClone(this.id,...t),this}async APILoadVersion(e=g,t,...i){return await Re.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];return t!=null&&t.hasRemoved(this.id)?(t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(u=>{const{updated:y,removed:c,added:I}=u.entity.onDetachedDependencyRemoved(this,u.field,t);i.push(...y),s.push(...c),l.push(...I)}),this.inputs.forEach(u=>{const{updated:y,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...y),s.push(...c)}),oi(this).forEach(u=>{const{updated:y,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...y),s.push(...c)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this})}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.inputs.forEach(d=>{const{updated:u}=d.restore({},e);i.push(...u)}),oi(this).forEach(d=>{const{updated:u}=d.restore({},e);i.push(...u)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.inputs.flatMap(i=>i.toFlat(e)),...this.calls.flatMap(i=>i.toFlat(e)),...this.returnStatements.flatMap(i=>i.toFlat(e)),...this.implements?this.implements.toFlat(e):[]])}toFlatIds(e=new Set){if(e.has(this.id))return[];e.add(this.id);const t=oi(this);return[this.id,...this.inputs.flatMap(s=>s.toFlatIds(e)),...this.calls.flatMap(s=>s.toFlatIds(e)),...this.returnStatements.flatMap(s=>s.toFlatIds(e)),...this.implements?this.implements.toFlatIds(e):[],...t.flatMap(s=>s.toFlatIds(e))]}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,collapsed:this.collapsed,private:this.private,index:this.index,x:this.x,y:this.y,type:this.type,name:this.name}}toJSON(e=new Set){var t;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,x:this.x,y:this.y,collapsed:this.collapsed,private:this.private,calls:this.calls.map(i=>i.toJSON(e)),inputs:this.inputs.map(i=>i.toJSON(e)),implements:((t=this.implements)==null?void 0:t.toJSON(e))||null,parent:this.parent.toReference()})}toJSONClone(e=q){var i,s,l,o,d;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,x:this.x,y:this.y,collapsed:this.collapsed,private:this.private,calls:this.calls.map(u=>u.toJSONClone({...e,newId:null})),inputs:this.inputs.map(u=>u.toJSONClone({...e,newId:null})),implements:(()=>{var u;return this.implements&&this.project.getBuiltIn(this.implements.id)?this.implements.toJSON():(u=this.implements)==null?void 0:u.toJSONClone({...e,newId:null})})(),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=q){var i,s;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,collapsed:this.collapsed,private:this.private,x:this.x,y:this.y,inputs:this.inputs.map(l=>l.toReference(e)),calls:this.calls.map(l=>l.toReference(e)),implements:((s=this.implements)==null?void 0:s.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.inputs.flatMap(i=>i.toFlatJSON(e)),...this.calls.flatMap(i=>i.toFlatJSON(e)),...this.returnStatements.flatMap(i=>i.toFlatJSON(e)),...this.implements?this.implements.toFlatJSON(e):[]])}toGenerationTarget(){var t;const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,name:this.name,description:this.description,type:this.type,private:this.private,implements:((t=this.implements)==null?void 0:t.id)||null,parent:e}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.inputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.calls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.returnStatements.flatMap(i=>i.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.inputs.forEach(e=>e.clearErrors()),this.calls.forEach(e=>e.clearErrors()),this.returnStatements.forEach(e=>e.clearErrors()),this}validate(){const e=a1(this);return this.errors=[...e],{success:!0,error:null,data:this.toJSON()}}getErrors(){const e=oi(this);return[...this.errors,...this.inputs.flatMap(i=>i.getErrors()),...e.flatMap(i=>i.getErrors())]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0,l=!1){var P;let o=mt(t,this);const d=this.toJSON(),u=i||m.UUID.uuid();d.inputs=[],d.calls=[];const y=u.split("-id"),c=y[y.length-1||0]||u;d.id=u,d.version=m.UUID.uuid(),d.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),d.author=(e==null?void 0:e.author)||"1",d.previousVersion=null,d.deleted=!1;const I=ct(d,o);t?I.setParent(t,null):I.setParent(this.parent,null),s&&I.subscribe(),I.initChildren(e),e==null||e.add(I,A.Added);const E=(P=this.inputs)==null?void 0:P.map((V,M)=>V.clone(e,I,c+"-argument-declaration-"+M+"-id",s));return I.inputs=E,l?(oi(this).map((V,M)=>V.clone(e,I,c+"-body-entity-"+M+"-id")),e==null||e.attemptAutoclose("clone-entity",this.id),I):(e==null||e.attemptAutoclose("clone-entity",this.id),I)}getVariableInstances(){return Ye(this).filter(i=>i.type===n.VariableInstance)}getArgument(e){return this.inputs.find(t=>t.id===e)||null}createCall(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"create-call")),t=this.project,i={}){const s={id:i.id||m.UUID.uuid(),version:i.version||m.UUID.uuid(),createdAt:i.createdAt||T().toISOString(),author:i.author||"1",previousVersion:i.previousVersion||null,deleted:i.deleted||!1,type:n.FunctionCall,parent:t.toReference(),successCalls:i.successCalls||[],errorCalls:i.errorCalls||[],inputs:i.inputs||[],outputs:i.outputs||[],error:i.error||null,process:i.process||null,calledBySuccess:i.calledBySuccess||[],calledByError:i.calledByError||[],calledByEntry:i.calledByEntry||[],declaration:this.toJSON(),x:0,y:0},l=C(s,this.project);return l.setParent(t,e),l.initChildren(e),e==null||e.add(l,A.Added),l.hydrateAncestors(),l.afterAllChildrenInitialized(e),t===this.project&&this.project.addFunctionCall(l),e==null||e.attemptAutoclose("create-call",this.id),l}createInternalCall(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"create-internal")),t,i={}){const s={id:i.id||m.UUID.uuid(),version:i.version||m.UUID.uuid(),type:n.InternalCall,parent:t.toReference(),successCalls:i.successCalls||[],deleted:i.deleted||!1,errorCalls:i.errorCalls||[],inputs:i.inputs||[],outputs:i.outputs||[],error:i.error||null,process:i.process||null,calledBySuccess:i.calledBySuccess||[],calledByError:i.calledByError||[],calledByEntry:i.calledByEntry||[],declaration:this.toShallowJSON(),index:t.internalCalls.length},l=C(s,this.project);return l.setParent(t,e),l.initChildren(e),e==null||e.add(l,A.Added),l.hydrateAncestors(),l.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("create-internal",this.id),l}addReturnStatement(e){return this.returnStatements.includes(e)||this.returnStatements.push(e),this}removeReturnStatement(e){const t=this.returnStatements.indexOf(e);return t!==-1&&this.returnStatements.splice(t,1),this}getUniqueReturnDeclarations(){const e=[],i=[...this.returnStatements].flatMap(s=>s.outputs);if(this.implements){const s=this.implements.outputs;return i.forEach(l=>{const o=s.find(u=>u===l.implements),d=e.find(u=>u.implements===l.implements);o&&!d&&e.push(l)}),p(e)}else return i.forEach(s=>{e.find(o=>o===s||x(o,this.project)===x(s,this.project)&&Ri(o.dataType,s.dataType))||e.push(s)}),p(e)}};f(Re,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(Re,"type",n.FunctionDeclaration),f(Re,"USER_MANAGED_PARENT_TYPES",[n.Project,n.InstalledProject,n.DefinitionEntity,n.Loop]),f(Re,"PARENT_TYPES",[...Re.USER_MANAGED_PARENT_TYPES,n.BuiltInBaseEntity,n.PrimitiveEntity]),f(Re,"MUTABLE_BASE_PROPERTIES",["name","description","private"]),f(Re,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Re,"BASE_PROPERTIES",[...Re.MUTABLE_BASE_PROPERTIES,...Re.INMUTABLE_BASE_PROPERTIES]),f(Re,"MUTABLE_META_PROPERTIES",[...Re.MUTABLE_BASE_PROPERTIES,"x","y","index","collapsed"]),f(Re,"INMUTABLE_META_PROPERTIES",[...Re.INMUTABLE_BASE_PROPERTIES]),f(Re,"META_PROPERTIES",[...Re.MUTABLE_META_PROPERTIES,...Re.INMUTABLE_META_PROPERTIES]),f(Re,"MUTABLE_UPSTREAM_PROPERTIES",[]),f(Re,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements"]),f(Re,"UPSTREAM_PROPERTIES",[...Re.MUTABLE_UPSTREAM_PROPERTIES,...Re.INMUTABLE_UPSTREAM_PROPERTIES]),f(Re,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","calls","returnStatements"]),f(Re,"INMUATABLE_DOWNSTREAM_PROPERTIES",[]),f(Re,"DOWNSTREAM_PROPERTIES",[...Re.MUTABLE_DOWNSTREAM_PROPERTIES,...Re.INMUATABLE_DOWNSTREAM_PROPERTIES]),f(Re,"PROPERTIES",[...Re.META_PROPERTIES,...Re.UPSTREAM_PROPERTIES,...Re.DOWNSTREAM_PROPERTIES]);let jr=Re;function l1(r){const a=uS(),e=r.toJSON();a.safeParse(e).success;const i=[];if(r.entity&&r.andChildrenGroup||r.entity&&r.orChildrenGroup||r.andChildrenGroup&&r.orChildrenGroup){const s=de({id:r.id+"--"+F.InvalidPropertiesCombination,message:`Data type with id "${r.id}" has invalid properties combination. Only one of the following properties can be present at the time: 'entity', 'andChildrenGroup' or 'orChildrenGroup'`,issue:null,severity:D.Error,code:F.InvalidPropertiesCombination,entity:r});i.push(s.error)}return He(r.errors,i)}const R7=Object.freeze(Object.defineProperty({__proto__:null,validate:l1},Symbol.toStringTag,{value:"Module"}));function D7(r,a){const e=[],t=[n.DefinitionEntity,n.ActionDescriptor,n.Property,n.ArgumentDeclaration,n.ReturnDeclaration,n.VariableDeclaration,n.ValueDescriptor,n.DataType],i=`'${ne(t,"', '","' or '")}'`;if(r.parent)if(r.id===r.parent)e.push(new w({id:`${r.id}--${r.parent}--${R.SelfReference}`,code:R.SelfReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a reference to itself at 'parent'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null}));else{const s=a.get(r.parent);s?t.includes(s.type)||e.push(new w({id:`${r.id}--${r.parent}--${R.InvalidParentReference}`,code:R.InvalidParentReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a parent reference that isn't pointing to an entity of type ${i}.`,issue:null})):e.push(new w({id:`${r.id}--${r.parent}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", is referencing an entity with id "${r.parent}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}else e.push(new w({id:`${r.id}--${j.InvalidObjectStructure}`,code:j.InvalidObjectStructure,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}" is missing a 'parent' reference. The 'parent' of a 'data-type' entity must be a reference to an entity of type ${i}.`,issue:null}));if(r.entity){if(r.id===r.entity)return e.push(new w({id:`${r.id}--${r.entity}--${R.SelfReference}`,code:R.SelfReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a reference to itself at 'entity'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null})),e;const s=a.get(r.entity);s?[n.DefinitionEntity,n.PrimitiveEntity,n.ActionDescriptor,n.BuiltInBaseEntity].includes(s.type)||e.push(new w({id:`${r.id}--${r.entity}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has an 'entity' reference that isn't pointing to an entity of type 'definition-entity', 'primitive-entity', 'action-descriptor' or 'built-in-base-entity'.`,issue:null})):e.push(new w({id:`${r.id}--${r.entity}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", is referencing an entity with id "${r.entity}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}return e}var Cc=(r=>(r.Entity="entity",r))(Cc||{});const De=class De extends at{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"isList",null);f(this,"asType",null);f(this,"type",n.DataType);f(this,"options",null);f(this,"parentRelationType",null);f(this,"like");f(this,"implementationChooseOne",!1);f(this,"inferred",!1);f(this,"entity",null);f(this,"andChildrenGroup",null);f(this,"orChildrenGroup",null);f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);this.initialData=e,this.project=t,this.id=e.id,this.isList=e.isList,this.asType=e.asType,this.options=e.options,this.parentRelationType=e.parentRelationType,this.inferred=e.inferred||!1,this.like=e.like||!1,this.implementationChooseOne=e.implementationChooseOne||!1}static new(){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,entity:null,isList:!1,like:!1,inferred:!1,implementationChooseOne:!1,parentRelationType:null,options:null,asType:null,andChildrenGroup:null,orChildrenGroup:null,parent:null}}static fromGenerationTarget(e,t){const i=_(e.parent),s=t.get(i);let l=null;e.entity&&(l=t.get(e.entity));const o={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,andChildrenGroup:null,orChildrenGroup:null,parentRelationType:e.parentRelationType||null,options:e.options||null,isList:e.isList,like:e.like||!1,inferred:!1,implementationChooseOne:e.implementationChooseOne||!1,entity:l,asType:e.asType,parent:s},d=C(o,t);return d.setParent(s,null),d.initChildren(null),d}static validateGenerationTarget(e,t){var u;let i=JSON.parse(JSON.stringify(e));const s=[],l=D7(i,t);if(s.push(...l,...ut(i)),i.entity){const y=t.get(i.entity);if(y.type===n.DefinitionEntity){const I=kt(y).filter(E=>!E.interactive);if(I.length){const E=I.length>1?`entities with ids '${ne(I.map(O=>O.id),"', '","' and '")}'`:`entity with id '${I[0].id}'`;s.push(new w({id:`${e.id}--${R.NonInteractiveEntityReferenced}`,code:R.NonInteractiveEntityReferenced,severity:D.Error,message:`The entity with id '${e.id}' and type '${e.type}', cannot reference 'definition-entity' with id '${i.entity}' at 'entity'. The entity extends or implements non-interactive built-in-base-entity ${E}.
71
71
  ${Qr}`,issue:null}))}}}const o=i.parent&&t.get(i.parent)||t.getBuiltIn(i.parent),d=o?rn(o):null;if(d)s.push(new w({id:`${e.id}--${R.BuiltInEntityParent}`,code:R.BuiltInEntityParent,severity:D.Error,message:`The entity with id '${e.id}' and type '${e.type}', belongs to a built-in system entity "${x(d,t)}" with id '${d.id}', and therefore it cannot be created as it would affect a built in entity, which are inmutable.`,issue:null}));else if(o){const y=o.type,c=[n.Property,n.VariableDeclaration,n.ArgumentDeclaration,n.ReturnDeclaration,n.ValueDescriptor];if(c.includes(y)&&(i.parentRelationType&&s.push(new w({id:`${e.id}--${R.InvalidParentRelationType}`,code:R.InvalidParentRelationType,severity:D.Error,message:`The entity with id '${e.id}' and type '${e.type}', cannot have a 'parentRelationType' property set of type '${y}'.
72
72
  The entitities of type '${ne(c,"', '","' and '")}' can only have one 'data-type' child under the 'dataType' property so no 'parentRelationType' is needed.`,issue:null})),o.dataType)){const I=(u=o.dataType)==null?void 0:u.id;s.push(new w({id:`${e.id}--${R.NewEntityWouldOverriteExisting}`,code:R.NewEntityWouldOverriteExisting,severity:D.Error,message:`The entity with id '${e.id}' and type '${e.type}', cannot be added as a child to the entity with id '${i.parent}' and type '${y}', because it already has a 'data-type' child with id '${I}'.
73
73
  The entitities of type '${ne(c,"', '","' and '")}' can only have one 'data-type' child under the 'dataType' property. You can inspect the existing data-type entity with the 'describe_entity' action. Like so:
74
74
  ${Yi({describe_entity:I})}
75
- Alternatively you can update the entity with 'update' action. Or replace it by first removing it and then creating a new one.`,issue:null}))}y===n.DataType&&(!i.parentRelationType||!(i.parentRelationType===Dt.AndDataTypeGroup||i.parentRelationType===Dt.OrDataTypeGroup))&&s.push(new w({id:`${e.id}--${R.InvalidParentRelationType}`,code:R.InvalidParentRelationType,severity:D.Error,message:`The entity with id '${e.id}' and type '${e.type}', must have a 'parentRelationType' property set to either 'or-data-type-group' or 'and-data-type-group' when being added as a child to an entity of type 'data-type'.`,issue:null}))}return{errors:s,modifiedData:i}}get isGroup(){const e=[...this.andChildrenGroup||[],...this.orChildrenGroup||[]];if(e.length>1){let t=0;for(const i of e)if(i.isResolved&&(t++,t>1))return!0}return!1}get isResolved(){return[n.BuiltInBaseEntity,n.ActionDescriptor].includes(this.parent.type)||rn(this.parent)?!0:!(!this.entity&&!this.isGroup)}validateGeneratedUpdate(e){return{errors:[],modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],i=[],s=[];return Object.values(this.detachedDependents).forEach(l=>{const o=l.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),i.push(...o.removed),s.push(...o.affected)}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];return t==="entity"&&this.setEntity(e),{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];return t==="entity"&&this.setEntity(null),{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e,t;return(t=(e=this.entity)==null?void 0:e.subscribeDependents)==null||t.call(e,[{entity:this,field:"entity"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new De(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.entity=this.entity,e.andChildrenGroup=this.andChildrenGroup,e.orChildrenGroup=this.orChildrenGroup,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[I,E]of c.knownVersions)u.set(I,E);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new De(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.entity=o.entity,this.andChildrenGroup=o.andChildrenGroup,this.orChildrenGroup=o.orChildrenGroup,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.entity){const l=_(this.initialData.entity),o=this.project.get(l);o&&(o.type===n.DefinitionEntity&&o.parent===this||(this.setEntity(o),o.type!==n.BuiltInBaseEntity&&o.type!==n.PrimitiveEntity&&e.push(o)))}return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.parent.type===n.DataType?this.parentRelationType===Dt.AndDataTypeGroup?this.parent.addToAndGroup(this):this.parentRelationType===Dt.OrDataTypeGroup&&this.parent.addToOrGroup(this):this.parent.setDataType(this),t.push(this.parent),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}removeChildGroup(e){if(this.andChildrenGroup){const t=this.andChildrenGroup.findIndex(i=>i.id===e.id);t!==-1&&this.andChildrenGroup.splice(t,1)}if(this.orChildrenGroup){const t=this.orChildrenGroup.findIndex(i=>i.id===e.id);t!==-1&&this.orChildrenGroup.splice(t,1)}return this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){var t,i,s,l;if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.entity)if(this.initialData.entity.type===n.GenericReference){const o=this.project.findSubscribedInstanceFromReference(this.initialData.entity);this.entity=o}else this.entity=C(this.initialData.entity,this.project),((i=(t=this.initialData.entity)==null?void 0:t.parent)==null?void 0:i.id)===this.id&&this.entity.setParent(this,null),(l=(s=this.entity).initChildren)==null||l.call(s,e);return this.initialData.andChildrenGroup&&(this.andChildrenGroup=this.initialData.andChildrenGroup.map(o=>{const d=C(o,this.project);return d.setParent(this,null),d.initChildren(e),d})),this.initialData.orChildrenGroup&&(this.orChildrenGroup=this.initialData.orChildrenGroup.map(o=>{const d=C(o,this.project);return d.setParent(this,null),d.initChildren(e),d})),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.options=e.options||s.options,this.parentRelationType=e.parentRelationType||s.parentRelationType,this.isList=e.isList!==void 0?e.isList:s.isList,this.inferred=e.inferred!==void 0?e.inferred:s.inferred,this.like=e.like!==void 0?e.like:s.like,this.asType=e.asType!==void 0?e.asType:s.asType,this.implementationChooseOne=e.implementationChooseOne!==void 0?e.implementationChooseOne:s.implementationChooseOne,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=g,...t){return await De.repository.APILoad(this.id,...t),this}async APICreate(e=g,...t){return await De.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=g,...t){return await De.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=g,...t){return await De.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=g,...t){return await De.repository.APIClone(this.id,...t),this}async APILoadVersion(e=g,t,...i){return await De.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){var d;const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(u=>{const{updated:y,removed:c,added:I}=u.entity.onDetachedDependencyRemoved(this,u.field,t);i.push(...y),s.push(...c),l.push(...I)}),this.entity&&this.entity.type===n.DefinitionEntity&&this.entity.parent===this){const{updated:u,removed:y}=this.entity.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}if(!e){((d=this.parent)==null?void 0:d.type)===n.DataType&&this.parent.removeChildGroup(this);const u=this.parent;if((u==null?void 0:u.type)===n.DataType){if(this.parentRelationType===Dt.AndDataTypeGroup){if(Array.isArray(u.andChildrenGroup)){const y=u.andChildrenGroup.findIndex(c=>c.id===this.id);y!==-1&&u.andChildrenGroup.splice(y,1)}}else if(this.parentRelationType===Dt.OrDataTypeGroup&&Array.isArray(u.orChildrenGroup)){const y=u.orChildrenGroup.findIndex(c=>c.id===this.id);y!==-1&&u.orChildrenGroup.splice(y,1)}}else{const y=this.parent;y==null||y.removeDataType()}u&&i.push(u)}return t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.entity&&this.entity.type===n.DefinitionEntity&&this.entity.parent===this){const{updated:o}=this.entity.restore({},e);i.push(...o)}if(this.parent.type===n.DataType){const o=this.parent;Array.isArray(o.andChildrenGroup)&&o.andChildrenGroup.push(this)}if(this.parent.type===n.DataType){const o=this.parent;this.parentRelationType===Dt.AndDataTypeGroup?Array.isArray(o.andChildrenGroup)&&o.andChildrenGroup.push(this):this.parentRelationType===Dt.OrDataTypeGroup&&Array.isArray(o.orChildrenGroup)&&o.orChildrenGroup.push(this)}else{const o=this.parent;o.setDataType(this),i.push(o)}return e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){var i,s,l;return e.has(this.id)?[]:(e.add(this.id),[this,...((i=this.andChildrenGroup)==null?void 0:i.flatMap(o=>o.toFlat(e)))||[],...((s=this.orChildrenGroup)==null?void 0:s.flatMap(o=>o.toFlat(e)))||[],...((l=this.entity)==null?void 0:l.toFlat(e))||[]])}toFlatIds(e=new Set){var i,s,l;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((i=this.andChildrenGroup)==null?void 0:i.flatMap(o=>o.toFlatIds(e)))||[],...((s=this.orChildrenGroup)==null?void 0:s.flatMap(o=>o.toFlatIds(e)))||[],...((l=this.entity)==null?void 0:l.toFlatIds(e))||[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,like:this.like,isList:this.isList,inferred:this.inferred,parentRelationType:this.parentRelationType,implementationChooseOne:this.implementationChooseOne,options:this.options,asType:this.asType,type:this.type}}toJSON(e=new Set){var t,i,s,l;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,options:this.options,isList:this.isList,asType:this.asType,like:this.like,inferred:this.inferred,parentRelationType:this.parentRelationType,implementationChooseOne:this.implementationChooseOne,andChildrenGroup:((t=this.andChildrenGroup)==null?void 0:t.map(o=>o.toJSON(e)))||null,orChildrenGroup:((i=this.orChildrenGroup)==null?void 0:i.map(o=>o.toJSON(e)))||null,entity:((s=this.entity)==null?void 0:s.parent)===this?this.entity.toJSON(e):((l=this.entity)==null?void 0:l.toReference())||null,parent:this.parent.toReference()})}toJSONClone(e=q){var i,s,l,o,d,u,y,c,I;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,options:this.options,isList:this.isList,asType:this.asType,like:this.like,inferred:this.inferred,parentRelationType:this.parentRelationType,implementationChooseOne:this.implementationChooseOne,andChildrenGroup:((u=this.andChildrenGroup)==null?void 0:u.map(E=>E.toJSONClone({...e,newId:null})))||null,orChildrenGroup:((y=this.orChildrenGroup)==null?void 0:y.map(E=>E.toJSONClone({...e,newId:null})))||null,entity:((c=this.entity)==null?void 0:c.parent)===this?this.entity.toJSONClone({...e,newId:null}):((I=this.entity)==null?void 0:I.toReference({seenEntityMaps:e.seenEntityMaps}))||null,parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=q){var i,s,l,o;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,isList:this.isList,options:this.options,asType:this.asType,parentRelationType:this.parentRelationType,like:this.like,inferred:this.inferred,implementationChooseOne:this.implementationChooseOne,andChildrenGroup:((s=this.andChildrenGroup)==null?void 0:s.map(d=>d.toReference(e)))||null,orChildrenGroup:((l=this.orChildrenGroup)==null?void 0:l.map(d=>d.toReference(e)))||null,entity:((o=this.entity)==null?void 0:o.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var i,s,l;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((i=this.andChildrenGroup)==null?void 0:i.flatMap(o=>o.toFlatJSON(e)))||[],...((s=this.orChildrenGroup)==null?void 0:s.flatMap(o=>o.toFlatJSON(e)))||[],...((l=this.entity)==null?void 0:l.toFlatJSON(e))||[]])}toGenerationTarget(){var e;return{id:this.id,type:this.type,options:this.options||void 0,isList:this.isList,like:this.like,parentRelationType:this.parentRelationType||void 0,asType:this.asType,entity:((e=this.entity)==null?void 0:e.id)||null,parent:this.parent.id}}toFlatGenerationTarget(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((i=this.andChildrenGroup)==null?void 0:i.flatMap(l=>l.toFlatGenerationTarget(e)))||[],...((s=this.orChildrenGroup)==null?void 0:s.flatMap(l=>l.toFlatGenerationTarget(e)))||[],...this.entity&&this.entity.type==n.DefinitionEntity&&this.entity.parent===this&&this.entity.toFlatGenerationTarget(e)||[]])}clearErrors(){var e,t,i,s;return this.errors=[],(e=this.andChildrenGroup)==null||e.forEach(l=>l.clearErrors()),(t=this.orChildrenGroup)==null||t.forEach(l=>l.clearErrors()),this.inferred&&this.entity&&this.entity.type===n.DefinitionEntity&&((i=this.entity)==null?void 0:i.parent)===this&&((s=this.entity)==null||s.clearErrors()),this}validate(){const e=l1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var E,O,P;let l=mt(t,this),o=t||this.parent;const u={id:i||m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.author)||"1",previousVersion:null,deleted:!1,type:n.DataType,isList:this.isList,asType:this.asType,options:this.options,parentRelationType:this.parentRelationType,like:this.like,inferred:this.inferred,implementationChooseOne:this.implementationChooseOne,andChildrenGroup:null,orChildrenGroup:null,entity:null,parent:o.toReference()},y=ct(u,l);t&&y.setParent(t,null),s&&y.subscribe(),y.initChildren(e),e==null||e.add(y,A.Added);const c=(E=this.andChildrenGroup)==null?void 0:E.map(V=>V.clone(e,y,m.UUID.uuid(),s)),I=(O=this.orChildrenGroup)==null?void 0:O.map(V=>V.clone(e,y,m.UUID.uuid(),s));if(y.andChildrenGroup=c||null,y.orChildrenGroup=I||null,this.entity&&this.entity.type===n.DefinitionEntity&&((P=this.entity)==null?void 0:P.parent)===this){const V=this.entity.clone(e,y,m.UUID.uuid(),s);y.setEntity(V)}else this.entity&&y.setEntity(this.entity);return e==null||e.attemptAutoclose("clone-entity",this.id),y}merge(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"merge-entity"))){const i=[],s=[],l=[],o=[];if(this.asType!==(e==null?void 0:e.asType)&&(this.metaSync({asType:e==null?void 0:e.asType},t),t==null||t.add(this,A.Updated),i.push(this)),this.isList!==!(e!=null&&e.isList)&&(this.metaSync({isList:e==null?void 0:e.isList},t),t==null||t.add(this,A.Updated),i.push(this)),this.like!==(e==null?void 0:e.like)&&(this.metaSync({like:e==null?void 0:e.like},t),t==null||t.add(this,A.Updated),i.push(this)),e!=null&&e.inferred){if(e.entity&&e.entity.type===n.DefinitionEntity&&e.entity.parent===e){const d=e.entity.clone(t,this,m.UUID.uuid(),!0);this.setEntity(d),s.push(d)}else e.entity&&(this.setEntity(e.entity),t==null||t.add(this,A.Updated),i.push(this));this.inferred||(this.metaSync({inferred:!0},t),t==null||t.add(this,A.Updated),i.push(this))}else if(this.inferred){if(this.metaSync({inferred:!1},t),t==null||t.add(this,A.Updated),i.push(this),this.entity&&this.entity.type===n.DefinitionEntity&&this.entity.parent===this){const{updated:d,removed:u}=this.entity.remove({ignoreUpstream:!0},t);l.push(...u),d.push(...d)}e.entity!==this.entity&&(this.setEntity(e.entity),t==null||t.add(this,A.Updated),i.push(this))}else e.entity!==this.entity&&(this.setEntity(e.entity),t==null||t.add(this,A.Updated),i.push(this));return t==null||t.attemptAutoclose("merge-entity",this.id),{updated:p(i),added:p(s),removed:p(l),affected:p(o),self:this}}addToAndGroup(e){return this.andChildrenGroup||(this.andChildrenGroup=[]),this.andChildrenGroup.includes(e)||this.andChildrenGroup.push(e),this}addToOrGroup(e){return this.orChildrenGroup||(this.orChildrenGroup=[]),this.orChildrenGroup.includes(e)||this.orChildrenGroup.push(e),this}setEntity(e){return this.entity=e,this}isObject(){return!!this.entity&&(this.entity.type===n.DefinitionEntity||this.entity.name===L.KeyValue)}hasStrictObjectStructure(){var e;return this.isObject()&&((e=this.entity)==null?void 0:e.type)===n.DefinitionEntity}inferFromInputs(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"infer-data-type-from-inputs"))){var d;const i=[],s=[],l=[],o=[];if(!this.inferred)return t==null||t.attemptAutoclose("infer-data-type-from-inputs",this.id),{updated:[],added:[],removed:[],affected:[],self:this};if(!this.entity&&e.length){const u=x(this.parent,this.project)+" data type definition",y={id:m.UUID.uuid(),type:n.DefinitionEntity,version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:u,description:((d=this.parent)==null?void 0:d.description)||null,static:!0,abstract:!1,properties:[],methods:[],extends:[],implements:[],abstractMethods:[],x:0,y:0,parent:this.toReference()},c=C(y,this.project);c.setParent(this,t),c.initChildren(t),t==null||t.add(c,A.Added),c.metaSync(y,t),this.setEntity(c),t==null||t.add(this,A.Updated)}if(this.entity&&this.entity.type===n.DefinitionEntity&&this.entity.parent!==this&&this.entity.setParent(this,t),this.entity){const{updated:u,added:y,removed:c,affected:I}=this.entity.inferFromInputs(e,t);s.push(...u),i.push(...y),l.push(...c),o.push(...I)}return this.like||this.metaSync({like:!0},t),t==null||t.attemptAutoclose("infer-data-type-from-inputs",this.id),{updated:p(s),added:p(i),removed:p(l),affected:p(o),self:this}}};f(De,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(De,"type",n.DataType),f(De,"USER_MANAGED_PARENT_TYPES",[n.Property,n.ArgumentDeclaration,n.ReturnDeclaration,n.VariableDeclaration,n.ValueDescriptor,n.InputMap,n.OutputMap,n.DataType]),f(De,"PARENT_TYPES",[...De.USER_MANAGED_PARENT_TYPES]),f(De,"MUTABLE_BASE_PROPERTIES",["isList","asType","options","parentRelationType","like"]),f(De,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(De,"BASE_PROPERTIES",[...De.MUTABLE_BASE_PROPERTIES,...De.INMUTABLE_BASE_PROPERTIES]),f(De,"MUTABLE_META_PROPERTIES",[...De.MUTABLE_BASE_PROPERTIES,"inferred"]),f(De,"INMUTABLE_META_PROPERTIES",[...De.INMUTABLE_BASE_PROPERTIES]),f(De,"META_PROPERTIES",[...De.MUTABLE_META_PROPERTIES,...De.INMUTABLE_META_PROPERTIES]),f(De,"MUTABLE_UPSTREAM_PROPERTIES",["entity","parent"]),f(De,"INMUTABLE_UPSTREAM_PROPERTIES",[]),f(De,"UPSTREAM_PROPERTIES",[...De.MUTABLE_UPSTREAM_PROPERTIES,...De.INMUTABLE_UPSTREAM_PROPERTIES]),f(De,"MUTABLE_DOWNSTREAM_PROPERTIES",[]),f(De,"INMUTABLE_DOWNSTREAM_PROPERTIES",["andChildrenGroup","orChildrenGroup"]),f(De,"DOWNSTREAM_PROPERTIES",[...De.MUTABLE_DOWNSTREAM_PROPERTIES,...De.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(De,"PROPERTIES",[...De.META_PROPERTIES,...De.UPSTREAM_PROPERTIES,...De.DOWNSTREAM_PROPERTIES]);let $r=De;function d1(r){var o;const a=J5(),e=r.toJSON();a.safeParse(e).success;const i=Oq(r),s=vr(r),l=[...i,...s];if(r.id==="exec-sequentially-operation-call-id"){const d=de({id:`${r.id}--${F.PropertyImplementsNonAbstact}`,message:`Property "${x(r,r.project)}" with id "${r.id}" implements a non-abstract property "${x(r,r.project)}" with id "${r.id}".`,issue:null,severity:D.Error,code:F.PropertyImplementsNonAbstact,entity:r});l.push(d.error)}return r.outputs.forEach(d=>d.validate()),(o=r.error)==null||o.validate(),He(r.errors,l)}function Oq(r){const a=[];return r.inputs.forEach(e=>{e.validate()}),He(r.errors,a)}const Pq=Object.freeze(Object.defineProperty({__proto__:null,validate:d1},Symbol.toStringTag,{value:"Module"}));var u1=(r=>(r.Parent="parent",r))(u1||{});const Oe=class Oe extends at{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"x");f(this,"y");f(this,"type",n.Operation);f(this,"declaration");f(this,"inputs",[]);f(this,"outputs",[]);f(this,"process",null);f(this,"successCalls",[]);f(this,"errorCalls",[]);f(this,"error",null);f(this,"calledBySuccess",[]);f(this,"calledByError",[]);f(this,"calledByEntry",[]);f(this,"parent");f(this,"errors",[]);f(this,"project");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static new(){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Operation,declaration:null,inputs:[],outputs:[],process:null,error:null,parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],errorCalls:[],successCalls:[],x:0,y:0}}static fromGenerationTarget(e,t){let i=t;if(e.parent){const I=_(e.parent);i=t.get(I)}const s=_(e.declaration),l=t.get(s),o=e.calledByEntry.map(I=>{const E=_(I);return t.get(E)}),d=e.calledBySuccess.map(I=>{const E=_(I);return t.get(E)}),u=e.calledByError.map(I=>{const E=_(I);return t.get(E)}),y={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Operation,declaration:l,calledByEntry:o,calledBySuccess:d,calledByError:u,errorCalls:[],successCalls:[],inputs:[],outputs:[],process:null,error:null,x:0,y:0,parent:i},c=C(y,t);return c.setParent(i,null),c.initChildren(null),c}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=At(i,{parent:{list:!1,types:[...dt,n.Project],optional:!0}},t);i=l.modifiedData,s.push(...l.errors,...ut(i));const o=_(i.declaration);if(o){const d=W1(o,t);s.push(...d)}else{const d=`
75
+ Alternatively you can update the entity with 'update' action. Or replace it by first removing it and then creating a new one.`,issue:null}))}y===n.DataType&&(!i.parentRelationType||!(i.parentRelationType===Dt.AndDataTypeGroup||i.parentRelationType===Dt.OrDataTypeGroup))&&s.push(new w({id:`${e.id}--${R.InvalidParentRelationType}`,code:R.InvalidParentRelationType,severity:D.Error,message:`The entity with id '${e.id}' and type '${e.type}', must have a 'parentRelationType' property set to either 'or-data-type-group' or 'and-data-type-group' when being added as a child to an entity of type 'data-type'.`,issue:null}))}return{errors:s,modifiedData:i}}get isGroup(){const e=[...this.andChildrenGroup||[],...this.orChildrenGroup||[]];if(e.length>1){let t=0;for(const i of e)if(i.isResolved&&(t++,t>1))return!0}return!1}get isResolved(){return[n.BuiltInBaseEntity,n.ActionDescriptor].includes(this.parent.type)||rn(this.parent)?!0:!(!this.entity&&!this.isGroup)}validateGeneratedUpdate(e){return{errors:[],modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],i=[],s=[];return Object.values(this.detachedDependents).forEach(l=>{const o=l.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),i.push(...o.removed),s.push(...o.affected)}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];return t==="entity"&&this.setEntity(e),{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];return t==="entity"&&this.setEntity(null),{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e,t;return(t=(e=this.entity)==null?void 0:e.subscribeDependents)==null||t.call(e,[{entity:this,field:"entity"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new De(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.entity=this.entity,e.andChildrenGroup=this.andChildrenGroup,e.orChildrenGroup=this.orChildrenGroup,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[I,E]of c.knownVersions)u.set(I,E);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new De(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.entity=o.entity,this.andChildrenGroup=o.andChildrenGroup,this.orChildrenGroup=o.orChildrenGroup,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.entity){const l=_(this.initialData.entity),o=this.project.get(l);o&&(o.type===n.DefinitionEntity&&o.parent===this||(this.setEntity(o),o.type!==n.BuiltInBaseEntity&&o.type!==n.PrimitiveEntity&&e.push(o)))}return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.parent.type===n.DataType?this.parentRelationType===Dt.AndDataTypeGroup?this.parent.addToAndGroup(this):this.parentRelationType===Dt.OrDataTypeGroup&&this.parent.addToOrGroup(this):this.parent.setDataType(this),t.push(this.parent),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}removeChildGroup(e){if(this.andChildrenGroup){const t=this.andChildrenGroup.findIndex(i=>i.id===e.id);t!==-1&&this.andChildrenGroup.splice(t,1)}if(this.orChildrenGroup){const t=this.orChildrenGroup.findIndex(i=>i.id===e.id);t!==-1&&this.orChildrenGroup.splice(t,1)}return this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){var t,i,s,l;if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.entity)if(this.initialData.entity.type===n.GenericReference){const o=this.project.findSubscribedInstanceFromReference(this.initialData.entity);this.entity=o}else this.entity=C(this.initialData.entity,this.project),((i=(t=this.initialData.entity)==null?void 0:t.parent)==null?void 0:i.id)===this.id&&this.entity.setParent(this,null),(l=(s=this.entity).initChildren)==null||l.call(s,e);return this.initialData.andChildrenGroup&&(this.andChildrenGroup=this.initialData.andChildrenGroup.map(o=>{const d=C(o,this.project);return d.setParent(this,null),d.initChildren(e),d})),this.initialData.orChildrenGroup&&(this.orChildrenGroup=this.initialData.orChildrenGroup.map(o=>{const d=C(o,this.project);return d.setParent(this,null),d.initChildren(e),d})),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.options=e.options||s.options,this.parentRelationType=e.parentRelationType||s.parentRelationType,this.isList=e.isList!==void 0?e.isList:s.isList,this.inferred=e.inferred!==void 0?e.inferred:s.inferred,this.like=e.like!==void 0?e.like:s.like,this.asType=e.asType!==void 0?e.asType:s.asType,this.implementationChooseOne=e.implementationChooseOne!==void 0?e.implementationChooseOne:s.implementationChooseOne,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=g,...t){return await De.repository.APILoad(this.id,...t),this}async APICreate(e=g,...t){return await De.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=g,...t){return await De.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=g,...t){return await De.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=g,...t){return await De.repository.APIClone(this.id,...t),this}async APILoadVersion(e=g,t,...i){return await De.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){var d;const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(u=>{const{updated:y,removed:c,added:I}=u.entity.onDetachedDependencyRemoved(this,u.field,t);i.push(...y),s.push(...c),l.push(...I)}),this.entity&&this.entity.type===n.DefinitionEntity&&this.entity.parent===this){const{updated:u,removed:y}=this.entity.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}if(!e){((d=this.parent)==null?void 0:d.type)===n.DataType&&this.parent.removeChildGroup(this);const u=this.parent;if((u==null?void 0:u.type)===n.DataType){if(this.parentRelationType===Dt.AndDataTypeGroup){if(Array.isArray(u.andChildrenGroup)){const y=u.andChildrenGroup.findIndex(c=>c.id===this.id);y!==-1&&u.andChildrenGroup.splice(y,1)}}else if(this.parentRelationType===Dt.OrDataTypeGroup&&Array.isArray(u.orChildrenGroup)){const y=u.orChildrenGroup.findIndex(c=>c.id===this.id);y!==-1&&u.orChildrenGroup.splice(y,1)}}else{const y=this.parent;y==null||y.removeDataType()}u&&i.push(u)}return t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.entity&&this.entity.type===n.DefinitionEntity&&this.entity.parent===this){const{updated:o}=this.entity.restore({},e);i.push(...o)}if(this.parent.type===n.DataType){const o=this.parent;Array.isArray(o.andChildrenGroup)&&o.andChildrenGroup.push(this)}if(this.parent.type===n.DataType){const o=this.parent;this.parentRelationType===Dt.AndDataTypeGroup?Array.isArray(o.andChildrenGroup)&&o.andChildrenGroup.push(this):this.parentRelationType===Dt.OrDataTypeGroup&&Array.isArray(o.orChildrenGroup)&&o.orChildrenGroup.push(this)}else{const o=this.parent;o.setDataType(this),i.push(o)}return e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){var i,s,l;return e.has(this.id)?[]:(e.add(this.id),[this,...((i=this.andChildrenGroup)==null?void 0:i.flatMap(o=>o.toFlat(e)))||[],...((s=this.orChildrenGroup)==null?void 0:s.flatMap(o=>o.toFlat(e)))||[],...((l=this.entity)==null?void 0:l.toFlat(e))||[]])}toFlatIds(e=new Set){var i,s,l;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((i=this.andChildrenGroup)==null?void 0:i.flatMap(o=>o.toFlatIds(e)))||[],...((s=this.orChildrenGroup)==null?void 0:s.flatMap(o=>o.toFlatIds(e)))||[],...((l=this.entity)==null?void 0:l.toFlatIds(e))||[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,like:this.like,isList:this.isList,inferred:this.inferred,parentRelationType:this.parentRelationType,implementationChooseOne:this.implementationChooseOne,options:this.options,asType:this.asType,type:this.type}}toJSON(e=new Set){var t,i,s,l;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,options:this.options,isList:this.isList,asType:this.asType,like:this.like,inferred:this.inferred,parentRelationType:this.parentRelationType,implementationChooseOne:this.implementationChooseOne,andChildrenGroup:((t=this.andChildrenGroup)==null?void 0:t.map(o=>o.toJSON(e)))||null,orChildrenGroup:((i=this.orChildrenGroup)==null?void 0:i.map(o=>o.toJSON(e)))||null,entity:((s=this.entity)==null?void 0:s.parent)===this?this.entity.toJSON(e):((l=this.entity)==null?void 0:l.toReference())||null,parent:this.parent.toReference()})}toJSONClone(e=q){var i,s,l,o,d,u,y,c,I;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,options:this.options,isList:this.isList,asType:this.asType,like:this.like,inferred:this.inferred,parentRelationType:this.parentRelationType,implementationChooseOne:this.implementationChooseOne,andChildrenGroup:((u=this.andChildrenGroup)==null?void 0:u.map(E=>E.toJSONClone({...e,newId:null})))||null,orChildrenGroup:((y=this.orChildrenGroup)==null?void 0:y.map(E=>E.toJSONClone({...e,newId:null})))||null,entity:((c=this.entity)==null?void 0:c.parent)===this?this.entity.toJSONClone({...e,newId:null}):((I=this.entity)==null?void 0:I.toReference({seenEntityMaps:e.seenEntityMaps}))||null,parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=q){var i,s,l,o;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,isList:this.isList,options:this.options,asType:this.asType,parentRelationType:this.parentRelationType,like:this.like,inferred:this.inferred,implementationChooseOne:this.implementationChooseOne,andChildrenGroup:((s=this.andChildrenGroup)==null?void 0:s.map(d=>d.toReference(e)))||null,orChildrenGroup:((l=this.orChildrenGroup)==null?void 0:l.map(d=>d.toReference(e)))||null,entity:((o=this.entity)==null?void 0:o.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var i,s,l;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((i=this.andChildrenGroup)==null?void 0:i.flatMap(o=>o.toFlatJSON(e)))||[],...((s=this.orChildrenGroup)==null?void 0:s.flatMap(o=>o.toFlatJSON(e)))||[],...((l=this.entity)==null?void 0:l.toFlatJSON(e))||[]])}toGenerationTarget(){var e;return{id:this.id,type:this.type,options:this.options||void 0,isList:this.isList,like:this.like,parentRelationType:this.parentRelationType||void 0,asType:this.asType,entity:((e=this.entity)==null?void 0:e.id)||null,parent:this.parent.id}}toFlatGenerationTarget(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((i=this.andChildrenGroup)==null?void 0:i.flatMap(l=>l.toFlatGenerationTarget(e)))||[],...((s=this.orChildrenGroup)==null?void 0:s.flatMap(l=>l.toFlatGenerationTarget(e)))||[],...this.entity&&this.entity.type==n.DefinitionEntity&&this.entity.parent===this&&this.entity.toFlatGenerationTarget(e)||[]])}clearErrors(){var e,t,i,s;return this.errors=[],(e=this.andChildrenGroup)==null||e.forEach(l=>l.clearErrors()),(t=this.orChildrenGroup)==null||t.forEach(l=>l.clearErrors()),this.inferred&&this.entity&&this.entity.type===n.DefinitionEntity&&((i=this.entity)==null?void 0:i.parent)===this&&((s=this.entity)==null||s.clearErrors()),this}validate(){const e=l1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var E,O,P;let l=mt(t,this),o=t||this.parent;const u={id:i||m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:(e==null?void 0:e.author)||"1",previousVersion:null,deleted:!1,type:n.DataType,isList:this.isList,asType:this.asType,options:this.options,parentRelationType:this.parentRelationType,like:this.like,inferred:this.inferred,implementationChooseOne:this.implementationChooseOne,andChildrenGroup:null,orChildrenGroup:null,entity:null,parent:o.toReference()},y=ct(u,l);t&&y.setParent(t,null),s&&y.subscribe(),y.initChildren(e),e==null||e.add(y,A.Added);const c=(E=this.andChildrenGroup)==null?void 0:E.map(V=>V.clone(e,y,m.UUID.uuid(),s)),I=(O=this.orChildrenGroup)==null?void 0:O.map(V=>V.clone(e,y,m.UUID.uuid(),s));if(y.andChildrenGroup=c||null,y.orChildrenGroup=I||null,this.entity&&this.entity.type===n.DefinitionEntity&&((P=this.entity)==null?void 0:P.parent)===this){const V=this.entity.clone(e,y,m.UUID.uuid(),s);y.setEntity(V)}else this.entity&&y.setEntity(this.entity);return e==null||e.attemptAutoclose("clone-entity",this.id),y}merge(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"merge-entity"))){const i=[],s=[],l=[],o=[];if(this.asType!==(e==null?void 0:e.asType)&&(this.metaSync({asType:e==null?void 0:e.asType},t),t==null||t.add(this,A.Updated),i.push(this)),this.isList!==!(e!=null&&e.isList)&&(this.metaSync({isList:e==null?void 0:e.isList},t),t==null||t.add(this,A.Updated),i.push(this)),this.like!==(e==null?void 0:e.like)&&(this.metaSync({like:e==null?void 0:e.like},t),t==null||t.add(this,A.Updated),i.push(this)),e!=null&&e.inferred){if(e.entity&&e.entity.type===n.DefinitionEntity&&e.entity.parent===e){const d=e.entity.clone(t,this,m.UUID.uuid(),!0);this.setEntity(d),s.push(d)}else e.entity&&(this.setEntity(e.entity),t==null||t.add(this,A.Updated),i.push(this));this.inferred||(this.metaSync({inferred:!0},t),t==null||t.add(this,A.Updated),i.push(this))}else if(this.inferred){if(this.metaSync({inferred:!1},t),t==null||t.add(this,A.Updated),i.push(this),this.entity&&this.entity.type===n.DefinitionEntity&&this.entity.parent===this){const{updated:d,removed:u}=this.entity.remove({ignoreUpstream:!0},t);l.push(...u),d.push(...d)}e.entity!==this.entity&&(this.setEntity(e.entity),t==null||t.add(this,A.Updated),i.push(this))}else e.entity!==this.entity&&(this.setEntity(e.entity),t==null||t.add(this,A.Updated),i.push(this));return t==null||t.attemptAutoclose("merge-entity",this.id),{updated:p(i),added:p(s),removed:p(l),affected:p(o),self:this}}addToAndGroup(e){return this.andChildrenGroup||(this.andChildrenGroup=[]),this.andChildrenGroup.includes(e)||this.andChildrenGroup.push(e),this}addToOrGroup(e){return this.orChildrenGroup||(this.orChildrenGroup=[]),this.orChildrenGroup.includes(e)||this.orChildrenGroup.push(e),this}setEntity(e){return this.entity=e,this}isObject(){return!!this.entity&&(this.entity.type===n.DefinitionEntity||this.entity.name===L.KeyValue)}hasStrictObjectStructure(){var e;return this.isObject()&&((e=this.entity)==null?void 0:e.type)===n.DefinitionEntity}inferFromInputs(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"infer-data-type-from-inputs"))){var d;const i=[],s=[],l=[],o=[];if(!this.inferred)return t==null||t.attemptAutoclose("infer-data-type-from-inputs",this.id),{updated:[],added:[],removed:[],affected:[],self:this};if(!this.entity&&e.length){const u=x(this.parent,this.project)+" data type definition",y={id:m.UUID.uuid(),type:n.DefinitionEntity,version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:u,description:((d=this.parent)==null?void 0:d.description)||null,static:!0,abstract:!1,properties:[],methods:[],extends:[],implements:[],abstractMethods:[],x:0,y:0,parent:this.toReference()},c=C(y,this.project);c.setParent(this,t),c.initChildren(t),t==null||t.add(c,A.Added),c.metaSync(y,t),this.setEntity(c),t==null||t.add(this,A.Updated)}if(this.entity&&this.entity.type===n.DefinitionEntity&&this.entity.parent!==this&&this.entity.setParent(this,t),this.entity){const{updated:u,added:y,removed:c,affected:I}=this.entity.inferFromInputs(e,t);s.push(...u),i.push(...y),l.push(...c),o.push(...I)}return this.like||this.metaSync({like:!0},t),t==null||t.attemptAutoclose("infer-data-type-from-inputs",this.id),{updated:p(s),added:p(i),removed:p(l),affected:p(o),self:this}}};f(De,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(De,"type",n.DataType),f(De,"USER_MANAGED_PARENT_TYPES",[n.Property,n.ArgumentDeclaration,n.ReturnDeclaration,n.VariableDeclaration,n.ValueDescriptor,n.InputMap,n.OutputMap,n.DataType]),f(De,"PARENT_TYPES",[...De.USER_MANAGED_PARENT_TYPES]),f(De,"MUTABLE_BASE_PROPERTIES",["isList","asType","options","parentRelationType","like"]),f(De,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(De,"BASE_PROPERTIES",[...De.MUTABLE_BASE_PROPERTIES,...De.INMUTABLE_BASE_PROPERTIES]),f(De,"MUTABLE_META_PROPERTIES",[...De.MUTABLE_BASE_PROPERTIES,"inferred"]),f(De,"INMUTABLE_META_PROPERTIES",[...De.INMUTABLE_BASE_PROPERTIES]),f(De,"META_PROPERTIES",[...De.MUTABLE_META_PROPERTIES,...De.INMUTABLE_META_PROPERTIES]),f(De,"MUTABLE_UPSTREAM_PROPERTIES",["entity","parent"]),f(De,"INMUTABLE_UPSTREAM_PROPERTIES",[]),f(De,"UPSTREAM_PROPERTIES",[...De.MUTABLE_UPSTREAM_PROPERTIES,...De.INMUTABLE_UPSTREAM_PROPERTIES]),f(De,"MUTABLE_DOWNSTREAM_PROPERTIES",[]),f(De,"INMUTABLE_DOWNSTREAM_PROPERTIES",["andChildrenGroup","orChildrenGroup"]),f(De,"DOWNSTREAM_PROPERTIES",[...De.MUTABLE_DOWNSTREAM_PROPERTIES,...De.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(De,"PROPERTIES",[...De.META_PROPERTIES,...De.UPSTREAM_PROPERTIES,...De.DOWNSTREAM_PROPERTIES]);let $r=De;function d1(r){var o;const a=J5(),e=r.toJSON();a.safeParse(e).success;const i=O7(r),s=vr(r),l=[...i,...s];if(r.id==="exec-sequentially-operation-call-id"){const d=de({id:`${r.id}--${F.PropertyImplementsNonAbstact}`,message:`Property "${x(r,r.project)}" with id "${r.id}" implements a non-abstract property "${x(r,r.project)}" with id "${r.id}".`,issue:null,severity:D.Error,code:F.PropertyImplementsNonAbstact,entity:r});l.push(d.error)}return r.outputs.forEach(d=>d.validate()),(o=r.error)==null||o.validate(),He(r.errors,l)}function O7(r){const a=[];return r.inputs.forEach(e=>{e.validate()}),He(r.errors,a)}const P7=Object.freeze(Object.defineProperty({__proto__:null,validate:d1},Symbol.toStringTag,{value:"Module"}));var u1=(r=>(r.Parent="parent",r))(u1||{});const Oe=class Oe extends at{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"x");f(this,"y");f(this,"type",n.Operation);f(this,"declaration");f(this,"inputs",[]);f(this,"outputs",[]);f(this,"process",null);f(this,"successCalls",[]);f(this,"errorCalls",[]);f(this,"error",null);f(this,"calledBySuccess",[]);f(this,"calledByError",[]);f(this,"calledByEntry",[]);f(this,"parent");f(this,"errors",[]);f(this,"project");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static new(){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Operation,declaration:null,inputs:[],outputs:[],process:null,error:null,parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],errorCalls:[],successCalls:[],x:0,y:0}}static fromGenerationTarget(e,t){let i=t;if(e.parent){const I=_(e.parent);i=t.get(I)}const s=_(e.declaration),l=t.get(s),o=e.calledByEntry.map(I=>{const E=_(I);return t.get(E)}),d=e.calledBySuccess.map(I=>{const E=_(I);return t.get(E)}),u=e.calledByError.map(I=>{const E=_(I);return t.get(E)}),y={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Operation,declaration:l,calledByEntry:o,calledBySuccess:d,calledByError:u,errorCalls:[],successCalls:[],inputs:[],outputs:[],process:null,error:null,x:0,y:0,parent:i},c=C(y,t);return c.setParent(i,null),c.initChildren(null),c}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=At(i,{parent:{list:!1,types:[...dt,n.Project],optional:!0}},t);i=l.modifiedData,s.push(...l.errors,...ut(i));const o=_(i.declaration);if(o){const d=W1(o,t);s.push(...d)}else{const d=`
76
76
  All built-in 'action-descriptor' entity ids are:
77
77
  - ${t.operationDeclarations.map(u=>`${u.id} (${x(u,t)})`).join(`
78
78
  - `)}.
79
79
  `;s.push(new w({id:`${i.id}--${R.InvalidReference}`,code:R.InvalidReference,severity:D.Error,message:`Entity of type "${n.Operation}" with id "${i.id}", has an invalid reference at the 'declaration' property. The 'declaration' property must be a valid reference to an 'action-descriptor' entity.
80
80
  References can either be an ID string or an object with exacly four properties: 'id', 'entityId', 'entityType', 'type'.${d}`,issue:null}))}return{errors:s,modifiedData:i}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
81
81
  If an entity is called by another, they must be in the same scope, which means they have the same parent.
82
- You shouldn't have to manually update a 'parent' property. The equivalent result is to change its callers, the value writters of its inputs, or the value readers of its outputs.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],i=[],s=[];return Object.values(this.detachedDependents).forEach(l=>{const o=l.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),i.push(...o.removed),s.push(...o.affected)}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Oe(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.process=this.process,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.declaration=this.declaration,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[I,E]of c.knownVersions)u.set(I,E);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Oe(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.error=o.error,this.process=o.process,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.declaration=o.declaration,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.declaration){const l=_(this.initialData.declaration),o=this.project.get(l);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];this.initialized=!0,this.captureVersion();const{updated:o,added:d,removed:u}=this.syncMissingFixedInputs(e),{updated:y,added:c,removed:I}=this.syncMissingFixedOutputs(e),{updated:E,added:O,removed:P}=this.declaration.syncOperationInstance(this,e);return t.push(...o,...y,...E),i.push(...d,...c,...E),s.push(...u,...I,...E),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){var o;const t=[this],i=[],s=[],l=[];return this.parent===this.project&&this.project.addOperation(this),(o=this.process)==null||o.writesValues.forEach(d=>{d.setValueWriter(this.process,e),t.push(d)}),this.successCalls.forEach(d=>{d.addSuccessCaller(this,e),t.push(d)}),this.errorCalls.forEach(d=>{d.addErrorCaller(this,e),t.push(d)}),this.calledBySuccess.forEach(d=>{d.addSuccessCall(this,e),t.push(d)}),this.calledByError.forEach(d=>{d.addErrorCall(this,e),t.push(d)}),this.calledByEntry.forEach(d=>{d.addCall(this,e),t.push(d)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-input"))){const i=this.inputs.findIndex(s=>s.id===e.id);return i>-1&&(this.inputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-input",this.id),this}addInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-input"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input",this.id),this):(this.inputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-input",this.id),this)}addOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-output"))){return this.outputs.includes(e)?(t==null||t.attemptAutoclose("add-output",this.id),this):(this.outputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-output",this.id),this)}removeOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-output"))){const i=this.outputs.findIndex(s=>s.id===e.id);return i>-1&&(this.outputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-output",this.id),this}addValueReader(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-value-reader"))){var i;return this.process&&!this.process.writesValues.includes(e)&&((i=this.process)==null||i.addValueReader(e,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-value-reader",this.id),this}removeValueReader(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-value-reader"))){var i;return this.process&&this.process.writesValues.includes(e)&&((i=this.process)==null||i.removeValueReader(e,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("remove-value-reader",this.id),this}addSuccessCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,A.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,A.Updated),i&&K(this,t),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,A.Updated),i&&K(this,t),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}addErrorCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-call")),i=!1){return this.errorCalls.find(s=>s.id===e.id)||(this.errorCalls.push(e),i&&K(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-call")),i=!1){return this.successCalls.find(s=>s.id===e.id)||(this.successCalls.push(e),i&&K(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-success-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-call")),i=!1){const s=this.successCalls.findIndex(o=>o.id===e.id);s>-1&&(this.successCalls.splice(s,1),t==null||t.add(this,A.Affected));const l=this.errorCalls.findIndex(o=>o.id===e.id);return l>-1&&(this.errorCalls.splice(l,1),t==null||t.add(this,A.Affected)),i&&K(this,t),t==null||t.attemptAutoclose("remove-call",this.id),this}removeCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected)),!0):!1),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected)),!0):!1),i&&K(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setDeclaration(e){return this.declaration=e,this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.declaration=C(this.initialData.declaration,this.project),this.successCalls=this.initialData.successCalls.map(t=>{const i=C(t,this.project);return i.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type)?i.setParent(this.parent.parent,null):i.type!==n.InternalCall&&i.setParent(this.parent,null),i.initChildren(e),i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=C(t,this.project);return i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type)?(i.setParent(this.parent.parent,null),i.initChildren(e)):i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e)),i}),this.inputs=this.initialData.inputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.outputs=this.initialData.outputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.initialData.error&&(this.error=C(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(e)),this.initialData.process&&(this.process=C(this.initialData.process,this.project),this.process.setParent(this,null),this.process.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=g,...t){return await Oe.repository.APILoad(this.id,...t),this}async APICreate(e=g,...t){return await Oe.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=g,...t){return await Oe.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=g,...t){return await Oe.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=g,...t){return await Oe.repository.APIClone(this.id,...t),this}async APILoadVersion(e=g,t,...i){return await Oe.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){var d;const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(u=>{const{updated:y,removed:c,added:I}=u.entity.onDetachedDependencyRemoved(this,u.field,t);i.push(...y),s.push(...c),l.push(...I)}),this.process){const{updated:u,removed:y}=(d=this.process)==null?void 0:d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}if(this.inputs.forEach(u=>{const{updated:y,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...y),s.push(...c)}),this.outputs.forEach(u=>{const{updated:y,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...y),s.push(...c)}),this.error){const{updated:u,removed:y}=this.error.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}return this.successCalls.forEach(u=>{i.push(u),u.removeCaller(this,t)}),this.errorCalls.forEach(u=>{i.push(u),u.removeCaller(this,t)}),e||this.calledBy.forEach(u=>{i.push(u),u.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.process){const{updated:o}=this.process.restore({},e);i.push(...o)}return this.inputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.successCalls.forEach(o=>{i.push(o),o.addSuccessCaller(this,e)}),this.errorCalls.forEach(o=>{i.push(o),o.addErrorCaller(this,e)}),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.successCalls.flatMap(i=>i.toFlat(e)),...this.errorCalls.flatMap(i=>i.toFlat(e)),...this.inputs.flatMap(i=>i.toFlat(e)),...this.outputs.flatMap(i=>i.toFlat(e)),...this.calledBy.flatMap(i=>i.toFlat(e)),...this.process?this.process.toFlat(e):[],...this.error?this.error.toFlat(e):[]])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.successCalls.flatMap(i=>i.toFlatIds(e)),...this.errorCalls.flatMap(i=>i.toFlatIds(e)),...this.inputs.flatMap(i=>i.toFlatIds(e)),...this.outputs.flatMap(i=>i.toFlatIds(e)),...this.process?this.process.toFlatIds(e):[],...this.error?this.error.toFlatIds(e):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,successCalls:this.successCalls.map(s=>s.toJSON(e)),errorCalls:this.errorCalls.map(s=>s.toJSON(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference()),calledByError:this.calledByError.map(s=>s.toReference()),calledByEntry:this.calledByEntry.map(s=>s.toReference()),process:(t=this.process)==null?void 0:t.toJSON(e),declaration:this.declaration.toJSON(e),inputs:this.inputs.map(s=>s.toJSON(e)),outputs:this.outputs.map(s=>s.toJSON(e)),parent:this.parent.toReference(),error:(i=this.error)==null?void 0:i.toJSON(e)})}toJSONClone(e=q){var i,s,l,o,d,u,y;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,successCalls:this.successCalls.map(c=>c.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(c=>c.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),process:(u=this.process)==null?void 0:u.toJSONClone({...e,newId:null}),declaration:this.declaration.toJSON(),inputs:this.inputs.map(c=>c.toJSONClone({...e,newId:null})),outputs:this.outputs.map(c=>c.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps}),error:(y=this.error)==null?void 0:y.toJSONClone({...e,newId:null})})}toReference(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,process:this.process?this.process.toReference(e):null,inputs:this.inputs.map(s=>s.toReference(e)),outputs:this.outputs.map(s=>s.toReference(e)),declaration:this.declaration.toReference(e),successCalls:this.successCalls.map(s=>s.toReference(e)),errorCalls:this.errorCalls.map(s=>s.toReference(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference(e)),calledByError:this.calledByError.map(s=>s.toReference(e)),calledByEntry:this.calledByEntry.map(s=>s.toReference(e)),error:this.error?this.error.toReference(e):null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.process?this.process.toFlatJSON(e):[],...this.successCalls.flatMap(i=>i.toFlatJSON(e)),...this.errorCalls.flatMap(i=>i.toFlatJSON(e)),...this.inputs.flatMap(i=>i.toFlatJSON(e)),...this.outputs.flatMap(i=>i.toFlatJSON(e)),...this.calledBy.flatMap(i=>i.toFlatJSON(e)),...this.error?this.error.toFlatJSON(e):[]])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),declaration:this.declaration.id,parent:e}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.successCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.inputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.outputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.process?this.process.toFlatGenerationTarget(e):[],...this.error?this.error.toFlatGenerationTarget(e):[]])}clearErrors(){var e,t;return this.errors=[],this.inputs.forEach(i=>i.clearErrors()),this.outputs.forEach(i=>i.clearErrors()),this.successCalls.forEach(i=>i.clearErrors()),this.errorCalls.forEach(i=>i.clearErrors()),(e=this.process)==null||e.clearErrors(),(t=this.error)==null||t.clearErrors(),this}validate(){const e=d1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.inputs.flatMap(t=>t.getErrors()),...this.outputs.flatMap(t=>t.getErrors()),...this.error?this.error.getErrors():[],...this.process?this.process.getErrors():[]]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var O,P;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[];const u=d.split("-id"),y=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=ct(o,l);t?c.setParent(t,null):c.setParent(this.parent,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,A.Added);const I=(O=this.inputs)==null?void 0:O.map((V,M)=>V.clone(e,c,y+"-input-map-"+M+"-id",s));c.inputs=I;const E=(P=this.outputs)==null?void 0:P.map((V,M)=>V.clone(e,c,y+"-output-map-"+M+"-id",s));return c.outputs=E,this.error&&(c.error=this.error.clone(e,c,y+"-error-map-id",s)),this.process&&(c.process=this.process.clone(e,c,y+"-process-id",s)),e==null||e.attemptAutoclose("clone-entity",this.id),c}removeUnrecognizedInputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-unrecognized-inputs"))){const t=[],i=[],s=[],l=[];return this.inputs.forEach(o=>{if(!this.declaration.inputs.find(u=>{var y;return u.id===((y=o.declaration)==null?void 0:y.id)})){const u=o.remove({ignoreUpstream:!1},e);s.push(...u.removed),t.push(...u.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}removeUnrecognizedOutputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-unrecognized-outputs"))){const t=[],i=[],s=[],l=[];return this.outputs.forEach(o=>{if(!this.declaration.outputs.find(u=>{var y;return u.id===((y=o.declaration)==null?void 0:y.id)})){const u=o.remove({ignoreUpstream:!1},e);s.push(...u.removed),t.push(...u.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-outputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncMissingFixedInputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const t=[],i=[],s=[],l=[],o=this.declaration.inputs.filter(c=>c.parentRelationType===N.FixedArguments&&!this.inputs.find(I=>{var E;return((E=I.declaration)==null?void 0:E.id)===c.id}));this.inputs.sort((c,I)=>c.index-I.index),o.forEach(c=>{this.inputs.forEach(O=>{O.index>=c.index&&O.metaSync({index:O.index+1},e)});const I={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,declaration:c.toJSON(),readsValue:null,defaultValue:null,index:c.index,name:null,description:null,parent:this.toReference()},E=C(I,this.project);E.setParent(this,e),E.initChildren(e),e==null||e.add(E,A.Added),E.addSelfToProject(e)}),this.inputs.sort((c,I)=>c.index-I.index);const{updated:d,added:u,removed:y}=this.removeUnrecognizedInputs(e);return t.push(...d),i.push(...u),s.push(...y),e==null||e.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncMissingFixedOutputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-missing-fixed-outputs"))){const t=[],i=[],s=[],l=[],o=this.declaration.outputs.filter(c=>c.parentRelationType===N.FixedReturns&&!this.outputs.find(I=>{var E;return((E=I.declaration)==null?void 0:E.id)===c.id}));this.outputs.sort((c,I)=>c.index-I.index),o.forEach(c=>{this.outputs.forEach(O=>{O.index>=c.index&&O.index++});const I={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.OutputMap,declaration:c.toJSON(),defaultValue:null,writesValues:[],index:c.index,parent:this.toReference()},E=C(I,this.project);E.setParent(this,e),E.initChildren(e),e==null||e.add(E,A.Added),E.addSelfToProject(e)}),this.outputs.sort((c,I)=>c.index-I.index);const{updated:d,added:u,removed:y}=this.removeUnrecognizedOutputs(e);return t.push(...d),i.push(...u),s.push(...y),e==null||e.attemptAutoclose("sync-missing-fixed-outputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}};f(Oe,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(Oe,"type",n.Operation),f(Oe,"USER_MANAGED_PARENT_TYPES",[...dt,n.Project]),f(Oe,"PARENT_TYPES",[...Oe.USER_MANAGED_PARENT_TYPES]),f(Oe,"MUTABLE_BASE_PROPERTIES",[]),f(Oe,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Oe,"BASE_PROPERTIES",[...Oe.MUTABLE_BASE_PROPERTIES,...Oe.INMUTABLE_BASE_PROPERTIES]),f(Oe,"MUTABLE_META_PROPERTIES",[...Oe.MUTABLE_BASE_PROPERTIES,"x","y"]),f(Oe,"INMUTABLE_META_PROPERTIES",[...Oe.INMUTABLE_BASE_PROPERTIES]),f(Oe,"META_PROPERTIES",[...Oe.MUTABLE_META_PROPERTIES,...Oe.INMUTABLE_META_PROPERTIES]),f(Oe,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),f(Oe,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),f(Oe,"UPSTREAM_PROPERTIES",[...Oe.MUTABLE_UPSTREAM_PROPERTIES,...Oe.INMUTABLE_UPSTREAM_PROPERTIES]),f(Oe,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","outputs","writesValues","successCalls","errorCalls","error"]),f(Oe,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Oe,"DOWNSTREAM_PROPERTIES",[...Oe.MUTABLE_DOWNSTREAM_PROPERTIES,...Oe.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Oe,"PROPERTIES",[...Oe.META_PROPERTIES,...Oe.UPSTREAM_PROPERTIES,...Oe.DOWNSTREAM_PROPERTIES]);let Gr=Oe;function p1(r){const a=BS(),e=r.toJSON();a.safeParse(e).success;const i=oi(r);r.inputs.forEach(l=>l.validate()),i.forEach(l=>l.validate());const s=[];return He(r.errors,s)}const wq=Object.freeze(Object.defineProperty({__proto__:null,validate:p1},Symbol.toStringTag,{value:"Module"})),Pe=class Pe extends at{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"x");f(this,"y");f(this,"collapsed");f(this,"type",n.GlobalEvent);f(this,"inputs",[]);f(this,"calls",[]);f(this,"parent");f(this,"implements");f(this,"detachedChildren",[]);f(this,"errors",[]);f(this,"project");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description,this.x=e.x,this.y=e.y,this.collapsed=e.collapsed}static new(){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.GlobalEvent,name:"",description:"",collapsed:!1,implements:null,inputs:[],parent:null,calls:[],x:0,y:0}}static fromGenerationTarget(e,t){let i=t;if(e.parent){const d=_(e.parent);i=t.get(d)}let s;e.implements&&(s=t.getBuiltIn(e.implements));const l={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,description:e.description||null,type:n.GlobalEvent,collapsed:!1,calls:[],inputs:[],implements:s,x:0,y:0,parent:i},o=C(l,t);return o.setParent(i,null),o.initChildren(null),o}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=At(i,{},t);if(i=l.modifiedData,s.push(...l.errors,...ut(i)),!e.implements)s.push(new w({id:`${e.id}--${j.InvalidObjectStructure}`,code:j.InvalidObjectStructure,severity:D.Error,message:`Entity of type '${e.type}' with id '${e.id}' is missing the 'implements' property. This property is required for a '${e.type}' entity and must point to one of the built-in action descriptors reserved for 'global-event' entities.
82
+ You shouldn't have to manually update a 'parent' property. The equivalent result is to change its callers, the value writters of its inputs, or the value readers of its outputs.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],i=[],s=[];return Object.values(this.detachedDependents).forEach(l=>{const o=l.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),i.push(...o.removed),s.push(...o.affected)}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Oe(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.process=this.process,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.declaration=this.declaration,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[I,E]of c.knownVersions)u.set(I,E);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Oe(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.error=o.error,this.process=o.process,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.declaration=o.declaration,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.declaration){const l=_(this.initialData.declaration),o=this.project.get(l);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];this.initialized=!0,this.captureVersion();const{updated:o,added:d,removed:u}=this.syncMissingFixedInputs(e),{updated:y,added:c,removed:I}=this.syncMissingFixedOutputs(e),{updated:E,added:O,removed:P}=this.declaration.syncOperationInstance(this,e);return t.push(...o,...y,...E),i.push(...d,...c,...E),s.push(...u,...I,...E),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){var o;const t=[this],i=[],s=[],l=[];return this.parent===this.project&&this.project.addOperation(this),(o=this.process)==null||o.writesValues.forEach(d=>{d.setValueWriter(this.process,e),t.push(d)}),this.successCalls.forEach(d=>{d.addSuccessCaller(this,e),t.push(d)}),this.errorCalls.forEach(d=>{d.addErrorCaller(this,e),t.push(d)}),this.calledBySuccess.forEach(d=>{d.addSuccessCall(this,e),t.push(d)}),this.calledByError.forEach(d=>{d.addErrorCall(this,e),t.push(d)}),this.calledByEntry.forEach(d=>{d.addCall(this,e),t.push(d)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-input"))){const i=this.inputs.findIndex(s=>s.id===e.id);return i>-1&&(this.inputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-input",this.id),this}addInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-input"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input",this.id),this):(this.inputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-input",this.id),this)}addOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-output"))){return this.outputs.includes(e)?(t==null||t.attemptAutoclose("add-output",this.id),this):(this.outputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-output",this.id),this)}removeOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-output"))){const i=this.outputs.findIndex(s=>s.id===e.id);return i>-1&&(this.outputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-output",this.id),this}addValueReader(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-value-reader"))){var i;return this.process&&!this.process.writesValues.includes(e)&&((i=this.process)==null||i.addValueReader(e,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-value-reader",this.id),this}removeValueReader(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-value-reader"))){var i;return this.process&&this.process.writesValues.includes(e)&&((i=this.process)==null||i.removeValueReader(e,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("remove-value-reader",this.id),this}addSuccessCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,A.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,A.Updated),i&&K(this,t),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,A.Updated),i&&K(this,t),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}addErrorCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-call")),i=!1){return this.errorCalls.find(s=>s.id===e.id)||(this.errorCalls.push(e),i&&K(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-call")),i=!1){return this.successCalls.find(s=>s.id===e.id)||(this.successCalls.push(e),i&&K(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-success-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-call")),i=!1){const s=this.successCalls.findIndex(o=>o.id===e.id);s>-1&&(this.successCalls.splice(s,1),t==null||t.add(this,A.Affected));const l=this.errorCalls.findIndex(o=>o.id===e.id);return l>-1&&(this.errorCalls.splice(l,1),t==null||t.add(this,A.Affected)),i&&K(this,t),t==null||t.attemptAutoclose("remove-call",this.id),this}removeCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected)),!0):!1),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected)),!0):!1),i&&K(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setDeclaration(e){return this.declaration=e,this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.declaration=C(this.initialData.declaration,this.project),this.successCalls=this.initialData.successCalls.map(t=>{const i=C(t,this.project);return i.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type)?i.setParent(this.parent.parent,null):i.type!==n.InternalCall&&i.setParent(this.parent,null),i.initChildren(e),i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=C(t,this.project);return i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type)?(i.setParent(this.parent.parent,null),i.initChildren(e)):i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e)),i}),this.inputs=this.initialData.inputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.outputs=this.initialData.outputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.initialData.error&&(this.error=C(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(e)),this.initialData.process&&(this.process=C(this.initialData.process,this.project),this.process.setParent(this,null),this.process.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=g,...t){return await Oe.repository.APILoad(this.id,...t),this}async APICreate(e=g,...t){return await Oe.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=g,...t){return await Oe.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=g,...t){return await Oe.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=g,...t){return await Oe.repository.APIClone(this.id,...t),this}async APILoadVersion(e=g,t,...i){return await Oe.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){var d;const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(u=>{const{updated:y,removed:c,added:I}=u.entity.onDetachedDependencyRemoved(this,u.field,t);i.push(...y),s.push(...c),l.push(...I)}),this.process){const{updated:u,removed:y}=(d=this.process)==null?void 0:d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}if(this.inputs.forEach(u=>{const{updated:y,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...y),s.push(...c)}),this.outputs.forEach(u=>{const{updated:y,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...y),s.push(...c)}),this.error){const{updated:u,removed:y}=this.error.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}return this.successCalls.forEach(u=>{i.push(u),u.removeCaller(this,t)}),this.errorCalls.forEach(u=>{i.push(u),u.removeCaller(this,t)}),e||this.calledBy.forEach(u=>{i.push(u),u.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.process){const{updated:o}=this.process.restore({},e);i.push(...o)}return this.inputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.successCalls.forEach(o=>{i.push(o),o.addSuccessCaller(this,e)}),this.errorCalls.forEach(o=>{i.push(o),o.addErrorCaller(this,e)}),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.successCalls.flatMap(i=>i.toFlat(e)),...this.errorCalls.flatMap(i=>i.toFlat(e)),...this.inputs.flatMap(i=>i.toFlat(e)),...this.outputs.flatMap(i=>i.toFlat(e)),...this.calledBy.flatMap(i=>i.toFlat(e)),...this.process?this.process.toFlat(e):[],...this.error?this.error.toFlat(e):[]])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.successCalls.flatMap(i=>i.toFlatIds(e)),...this.errorCalls.flatMap(i=>i.toFlatIds(e)),...this.inputs.flatMap(i=>i.toFlatIds(e)),...this.outputs.flatMap(i=>i.toFlatIds(e)),...this.process?this.process.toFlatIds(e):[],...this.error?this.error.toFlatIds(e):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,successCalls:this.successCalls.map(s=>s.toJSON(e)),errorCalls:this.errorCalls.map(s=>s.toJSON(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference()),calledByError:this.calledByError.map(s=>s.toReference()),calledByEntry:this.calledByEntry.map(s=>s.toReference()),process:(t=this.process)==null?void 0:t.toJSON(e),declaration:this.declaration.toJSON(e),inputs:this.inputs.map(s=>s.toJSON(e)),outputs:this.outputs.map(s=>s.toJSON(e)),parent:this.parent.toReference(),error:(i=this.error)==null?void 0:i.toJSON(e)})}toJSONClone(e=q){var i,s,l,o,d,u,y;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,successCalls:this.successCalls.map(c=>c.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(c=>c.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),process:(u=this.process)==null?void 0:u.toJSONClone({...e,newId:null}),declaration:this.declaration.toJSON(),inputs:this.inputs.map(c=>c.toJSONClone({...e,newId:null})),outputs:this.outputs.map(c=>c.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps}),error:(y=this.error)==null?void 0:y.toJSONClone({...e,newId:null})})}toReference(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,process:this.process?this.process.toReference(e):null,inputs:this.inputs.map(s=>s.toReference(e)),outputs:this.outputs.map(s=>s.toReference(e)),declaration:this.declaration.toReference(e),successCalls:this.successCalls.map(s=>s.toReference(e)),errorCalls:this.errorCalls.map(s=>s.toReference(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference(e)),calledByError:this.calledByError.map(s=>s.toReference(e)),calledByEntry:this.calledByEntry.map(s=>s.toReference(e)),error:this.error?this.error.toReference(e):null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.process?this.process.toFlatJSON(e):[],...this.successCalls.flatMap(i=>i.toFlatJSON(e)),...this.errorCalls.flatMap(i=>i.toFlatJSON(e)),...this.inputs.flatMap(i=>i.toFlatJSON(e)),...this.outputs.flatMap(i=>i.toFlatJSON(e)),...this.calledBy.flatMap(i=>i.toFlatJSON(e)),...this.error?this.error.toFlatJSON(e):[]])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),declaration:this.declaration.id,parent:e}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.successCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.inputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.outputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.process?this.process.toFlatGenerationTarget(e):[],...this.error?this.error.toFlatGenerationTarget(e):[]])}clearErrors(){var e,t;return this.errors=[],this.inputs.forEach(i=>i.clearErrors()),this.outputs.forEach(i=>i.clearErrors()),this.successCalls.forEach(i=>i.clearErrors()),this.errorCalls.forEach(i=>i.clearErrors()),(e=this.process)==null||e.clearErrors(),(t=this.error)==null||t.clearErrors(),this}validate(){const e=d1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.inputs.flatMap(t=>t.getErrors()),...this.outputs.flatMap(t=>t.getErrors()),...this.error?this.error.getErrors():[],...this.process?this.process.getErrors():[]]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var O,P;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[];const u=d.split("-id"),y=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=ct(o,l);t?c.setParent(t,null):c.setParent(this.parent,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,A.Added);const I=(O=this.inputs)==null?void 0:O.map((V,M)=>V.clone(e,c,y+"-input-map-"+M+"-id",s));c.inputs=I;const E=(P=this.outputs)==null?void 0:P.map((V,M)=>V.clone(e,c,y+"-output-map-"+M+"-id",s));return c.outputs=E,this.error&&(c.error=this.error.clone(e,c,y+"-error-map-id",s)),this.process&&(c.process=this.process.clone(e,c,y+"-process-id",s)),e==null||e.attemptAutoclose("clone-entity",this.id),c}removeUnrecognizedInputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-unrecognized-inputs"))){const t=[],i=[],s=[],l=[];return this.inputs.forEach(o=>{if(!this.declaration.inputs.find(u=>{var y;return u.id===((y=o.declaration)==null?void 0:y.id)})){const u=o.remove({ignoreUpstream:!1},e);s.push(...u.removed),t.push(...u.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}removeUnrecognizedOutputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-unrecognized-outputs"))){const t=[],i=[],s=[],l=[];return this.outputs.forEach(o=>{if(!this.declaration.outputs.find(u=>{var y;return u.id===((y=o.declaration)==null?void 0:y.id)})){const u=o.remove({ignoreUpstream:!1},e);s.push(...u.removed),t.push(...u.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-outputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncMissingFixedInputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const t=[],i=[],s=[],l=[],o=this.declaration.inputs.filter(c=>c.parentRelationType===N.FixedArguments&&!this.inputs.find(I=>{var E;return((E=I.declaration)==null?void 0:E.id)===c.id}));this.inputs.sort((c,I)=>c.index-I.index),o.forEach(c=>{this.inputs.forEach(O=>{O.index>=c.index&&O.metaSync({index:O.index+1},e)});const I={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,declaration:c.toJSON(),readsValue:null,defaultValue:null,index:c.index,name:null,description:null,parent:this.toReference()},E=C(I,this.project);E.setParent(this,e),E.initChildren(e),e==null||e.add(E,A.Added),E.addSelfToProject(e)}),this.inputs.sort((c,I)=>c.index-I.index);const{updated:d,added:u,removed:y}=this.removeUnrecognizedInputs(e);return t.push(...d),i.push(...u),s.push(...y),e==null||e.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncMissingFixedOutputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-missing-fixed-outputs"))){const t=[],i=[],s=[],l=[],o=this.declaration.outputs.filter(c=>c.parentRelationType===N.FixedReturns&&!this.outputs.find(I=>{var E;return((E=I.declaration)==null?void 0:E.id)===c.id}));this.outputs.sort((c,I)=>c.index-I.index),o.forEach(c=>{this.outputs.forEach(O=>{O.index>=c.index&&O.index++});const I={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.OutputMap,declaration:c.toJSON(),defaultValue:null,writesValues:[],index:c.index,parent:this.toReference()},E=C(I,this.project);E.setParent(this,e),E.initChildren(e),e==null||e.add(E,A.Added),E.addSelfToProject(e)}),this.outputs.sort((c,I)=>c.index-I.index);const{updated:d,added:u,removed:y}=this.removeUnrecognizedOutputs(e);return t.push(...d),i.push(...u),s.push(...y),e==null||e.attemptAutoclose("sync-missing-fixed-outputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}};f(Oe,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(Oe,"type",n.Operation),f(Oe,"USER_MANAGED_PARENT_TYPES",[...dt,n.Project]),f(Oe,"PARENT_TYPES",[...Oe.USER_MANAGED_PARENT_TYPES]),f(Oe,"MUTABLE_BASE_PROPERTIES",[]),f(Oe,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Oe,"BASE_PROPERTIES",[...Oe.MUTABLE_BASE_PROPERTIES,...Oe.INMUTABLE_BASE_PROPERTIES]),f(Oe,"MUTABLE_META_PROPERTIES",[...Oe.MUTABLE_BASE_PROPERTIES,"x","y"]),f(Oe,"INMUTABLE_META_PROPERTIES",[...Oe.INMUTABLE_BASE_PROPERTIES]),f(Oe,"META_PROPERTIES",[...Oe.MUTABLE_META_PROPERTIES,...Oe.INMUTABLE_META_PROPERTIES]),f(Oe,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),f(Oe,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),f(Oe,"UPSTREAM_PROPERTIES",[...Oe.MUTABLE_UPSTREAM_PROPERTIES,...Oe.INMUTABLE_UPSTREAM_PROPERTIES]),f(Oe,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","outputs","writesValues","successCalls","errorCalls","error"]),f(Oe,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Oe,"DOWNSTREAM_PROPERTIES",[...Oe.MUTABLE_DOWNSTREAM_PROPERTIES,...Oe.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Oe,"PROPERTIES",[...Oe.META_PROPERTIES,...Oe.UPSTREAM_PROPERTIES,...Oe.DOWNSTREAM_PROPERTIES]);let Gr=Oe;function p1(r){const a=BS(),e=r.toJSON();a.safeParse(e).success;const i=oi(r);r.inputs.forEach(l=>l.validate()),i.forEach(l=>l.validate());const s=[];return He(r.errors,s)}const w7=Object.freeze(Object.defineProperty({__proto__:null,validate:p1},Symbol.toStringTag,{value:"Module"})),Pe=class Pe extends at{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"x");f(this,"y");f(this,"collapsed");f(this,"type",n.GlobalEvent);f(this,"inputs",[]);f(this,"calls",[]);f(this,"parent");f(this,"implements");f(this,"detachedChildren",[]);f(this,"errors",[]);f(this,"project");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description,this.x=e.x,this.y=e.y,this.collapsed=e.collapsed}static new(){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.GlobalEvent,name:"",description:"",collapsed:!1,implements:null,inputs:[],parent:null,calls:[],x:0,y:0}}static fromGenerationTarget(e,t){let i=t;if(e.parent){const d=_(e.parent);i=t.get(d)}let s;e.implements&&(s=t.getBuiltIn(e.implements));const l={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,description:e.description||null,type:n.GlobalEvent,collapsed:!1,calls:[],inputs:[],implements:s,x:0,y:0,parent:i},o=C(l,t);return o.setParent(i,null),o.initChildren(null),o}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=At(i,{},t);if(i=l.modifiedData,s.push(...l.errors,...ut(i)),!e.implements)s.push(new w({id:`${e.id}--${j.InvalidObjectStructure}`,code:j.InvalidObjectStructure,severity:D.Error,message:`Entity of type '${e.type}' with id '${e.id}' is missing the 'implements' property. This property is required for a '${e.type}' entity and must point to one of the built-in action descriptors reserved for 'global-event' entities.
83
83
  ${kl(t)}`,issue:null}));else if(!t.get(e.implements))s.push(new w({id:`${e.id}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:D.Error,message:`Entity of type '${e.type}' with id '${e.id}' has an 'implements' property that isn't found in the project. The 'implements' property must point to one of the built-in action descriptors reserved for 'global-event' entities.
84
84
  ${kl(t)}`,issue:null}));else if(!t.globalEventActionDescriptors.find(u=>u.id===e.implements))s.push(new w({id:`${e.id}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:D.Error,message:`Entity of type '${e.type}' with id '${e.id}' has an 'implements' property that isn't pointing to an action descriptor reserved for 'global-event' entities.
85
85
  ${kl(t)}`,issue:null}));else{const u=t.events.find(y=>y.implements.id===e.implements);u&&s.push(new w({id:`${e.id}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:D.Error,message:`Entity of type '${e.type}' with id '${e.id}' has an 'implements' property that points to an action descriptor that is already implemented by another global event with id '${u.id}' in the project. Each global event must implement a unique action descriptor.
86
- You can attach new logic to the existing 'global-event' but creating a new callable entity that gets called by it.`,issue:null}))}return{errors:s,modifiedData:i}}get returnStatements(){const e=[];return Object.values(this.detachedDependents).forEach(t=>{t.field===gl.Parent&&t.entity.type===n.ReturnStatement&&!e.includes(t.entity)&&e.push(t.entity)}),e}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on an '${this.type}', must be the root project as it is a globally declared entity.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],i=[],s=[];return Object.values(this.detachedDependents).forEach(l=>{const o=l.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),i.push(...o.removed),s.push(...o.affected)}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){return this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Pe(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.calls=this.calls,e.implements=this.implements,e.detachedChildren=this.detachedChildren,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[I,E]of c.knownVersions)u.set(I,E);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Pe(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.calls=o.calls,this.implements=o.implements,this.detachedChildren=o.detachedChildren,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${xt(this.type)} with id '${this.id}' has a parent reference "${l}" which is missing in the project`)}else throw new Error(`${xt(this.type)} with id '${this.id}' is missing a parent reference`);if(this.initialData.implements){const l=_(this.initialData.implements),o=this.project.get(l);if(o)this.setImplements(o,null),e.push(o);else throw new Error(`${xt(this.type)} with id '${this.id}' has a 'implements' reference "${l}" which is missing in the project`)}else throw new Error(`${xt(this.type)} with id '${this.id}' is missing a 'implements' reference`);return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.project.addGlobalEvent(this),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}replaceDetachedChild(e,t){const i=this.detachedChildren.indexOf(e);return i!==-1&&(this.detachedChildren[i]=t),this}subscribeDetachedChild(e){return this.detachedChildren.includes(e)||this.detachedChildren.push(e),this}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setImplements(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-implements"))){var i;return((i=this.implements)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.implements=e,t&&(t==null||t.add(this,A.Updated),t==null||t.attemptAutoclose("set-implements",this.id))),this}addCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-call"))){return this.calls.includes(e)||(this.calls.push(e),t==null||t.add(e,A.Affected)),t==null||t.attemptAutoclose("add-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-call"))){const i=this.calls.indexOf(e);return i!==-1&&(this.calls.splice(i,1),t==null||t.add(e,A.Affected)),t==null||t.attemptAutoclose("remove-call",this.id),this}addInputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-input-declaration"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input-declaration",this.id),this):(this.inputs.push(e),t==null||t.attemptAutoclose("add-input-declaration",this.id),this)}removeInputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-input-declaration"))){const i=this.inputs.findIndex(s=>s.id===e.id);return i>-1&&(this.inputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-input-declaration",this.id),this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.inputs=this.initialData.inputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.calls=this.initialData.calls.map(t=>{const i=C(t,this.project);return i.addEntryCaller(this,null),i.type!==n.InternalCall&&(i.setParent(this,null),i.initChildren(e)),i}),this.implements=C(this.initialData.implements,this.project),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.name=e.name||s.name,this.description=e.description||s.description,this.x=e.x||s.x,this.y=e.y||s.y,this.collapsed=e.collapsed!==void 0?e.collapsed:s.collapsed,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=g,...t){return await Pe.repository.APILoad(this.id,...t),this}async APICreate(e=g,...t){return await Pe.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=g,...t){return await Pe.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=g,...t){return await Pe.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=g,...t){return await Pe.repository.APIClone(this.id,...t),this}async APILoadVersion(e=g,t,...i){return await Pe.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];return t!=null&&t.hasRemoved(this.id)?(t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(u=>{const{updated:y,removed:c,added:I}=u.entity.onDetachedDependencyRemoved(this,u.field,t);i.push(...y),s.push(...c),l.push(...I)}),this.inputs.forEach(u=>{const{updated:y,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...y),s.push(...c)}),oi(this).forEach(u=>{const{updated:y,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...y),s.push(...c)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this})}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.inputs.forEach(d=>{const{updated:u}=d.restore({},e);i.push(...u)}),oi(this).forEach(d=>{const{updated:u}=d.restore({},e);i.push(...u)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.inputs.flatMap(i=>i.toFlat(e)),...this.calls.flatMap(i=>i.toFlat(e)),...this.returnStatements.flatMap(i=>i.toFlat(e)),...this.implements?this.implements.toFlat(e):[]])}toFlatIds(e=new Set){if(e.has(this.id))return[];e.add(this.id);const t=oi(this);return[this.id,...this.inputs.flatMap(s=>s.toFlatIds(e)),...this.calls.flatMap(s=>s.toFlatIds(e)),...this.returnStatements.flatMap(s=>s.toFlatIds(e)),...this.implements?this.implements.toFlatIds(e):[],...t.flatMap(s=>s.toFlatIds(e))]}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,collapsed:this.collapsed,x:this.x,y:this.y,type:this.type,name:this.name}}toJSON(e=new Set){return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,x:this.x,y:this.y,collapsed:this.collapsed,implements:this.implements.toJSON(e),inputs:this.inputs.map(t=>t.toJSON(e)),calls:this.calls.map(t=>t.toJSON(e)),parent:this.parent.toReference()})}toJSONClone(e=q){var i,s,l,o,d;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,x:this.x,y:this.y,collapsed:this.collapsed,implements:this.implements.toJSON(),inputs:this.inputs.map(u=>u.toJSONClone({...e,newId:null})),calls:this.calls.map(u=>u.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,collapsed:this.collapsed,x:this.x,y:this.y,implements:this.implements.toReference(e),inputs:this.inputs.map(s=>s.toReference(e)),calls:this.calls.map(s=>s.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.inputs.flatMap(i=>i.toFlatJSON(e)),...this.calls.flatMap(i=>i.toFlatJSON(e)),...this.returnStatements.flatMap(i=>i.toFlatJSON(e))])}toGenerationTarget(){return{id:this.id,name:this.name,description:this.description||void 0,type:this.type,implements:this.implements.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.inputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.calls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.returnStatements.flatMap(i=>i.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.inputs.forEach(e=>e.clearErrors()),this.calls.forEach(e=>e.clearErrors()),this.returnStatements.forEach(e=>e.clearErrors()),this}validate(){const e=p1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){const e=oi(this);return[...this.errors,...this.inputs.flatMap(i=>i.getErrors()),...e.flatMap(i=>i.getErrors())]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0,l=!1){var P;let o=mt(t,this);const d=this.toJSON(),u=i||m.UUID.uuid();d.inputs=[];const y=u.split("-id"),c=y[y.length-1||0]||u;d.id=u,d.version=m.UUID.uuid(),d.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),d.author=(e==null?void 0:e.author)||"1",d.previousVersion=null,d.deleted=!1;const I=ct(d,o);t?I.setParent(t,null):I.setParent(this.parent,null),s&&I.subscribe(),I.initChildren(e),e==null||e.add(I,A.Added);const E=(P=this.inputs)==null?void 0:P.map((V,M)=>V.clone(e,I,c+"-argument-declaration-"+M+"-id",s));return I.inputs=E,l?(oi(this).map((V,M)=>V.clone(e,I,c+"-body-entity-"+M+"-id")),e==null||e.attemptAutoclose("clone-entity",this.id),I):(e==null||e.attemptAutoclose("clone-entity",this.id),I)}getVariableInstances(){return Ye(this).filter(i=>i.type===n.VariableInstance)}addReturnStatement(e){return this.returnStatements.includes(e)||this.returnStatements.push(e),this}removeReturnStatement(e){const t=this.returnStatements.indexOf(e);return t!==-1&&this.returnStatements.splice(t,1),this}};f(Pe,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(Pe,"type",n.GlobalEvent),f(Pe,"USER_MANAGED_PARENT_TYPES",[n.Project]),f(Pe,"PARENT_TYPES",[...Pe.USER_MANAGED_PARENT_TYPES]),f(Pe,"MUTABLE_BASE_PROPERTIES",["description"]),f(Pe,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Pe,"BASE_PROPERTIES",[...Pe.MUTABLE_BASE_PROPERTIES,...Pe.INMUTABLE_BASE_PROPERTIES]),f(Pe,"MUTABLE_META_PROPERTIES",[...Pe.MUTABLE_BASE_PROPERTIES,"x","y","collapsed"]),f(Pe,"INMUTABLE_META_PROPERTIES",[...Pe.INMUTABLE_BASE_PROPERTIES]),f(Pe,"META_PROPERTIES",[...Pe.MUTABLE_META_PROPERTIES,...Pe.INMUTABLE_META_PROPERTIES]),f(Pe,"MUTABLE_UPSTREAM_PROPERTIES",[]),f(Pe,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements"]),f(Pe,"UPSTREAM_PROPERTIES",[...Pe.MUTABLE_UPSTREAM_PROPERTIES,...Pe.INMUTABLE_UPSTREAM_PROPERTIES]),f(Pe,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","calls","returnStatements"]),f(Pe,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Pe,"DOWNSTREAM_PROPERTIES",[...Pe.MUTABLE_DOWNSTREAM_PROPERTIES,...Pe.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Pe,"PROPERTIES",[...Pe.META_PROPERTIES,...Pe.UPSTREAM_PROPERTIES,...Pe.DOWNSTREAM_PROPERTIES]);let Fr=Pe;function c1(r){var s;const a=v5(),e=r.toJSON();a.safeParse(e).success,r.outputs.forEach(l=>l.validate()),(s=r.throws)==null||s.validate();const i=[];return He(r.errors,i)}const Cq=Object.freeze(Object.defineProperty({__proto__:null,validate:c1},Symbol.toStringTag,{value:"Module"}));var Vc=(r=>(r.Parent="parent",r))(Vc||{});const xe=class xe extends at{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"x");f(this,"y");f(this,"type",n.BreakStatement);f(this,"outputs",[]);f(this,"calledBySuccess",[]);f(this,"calledByError",[]);f(this,"calledByEntry",[]);f(this,"throws",null);f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static new(){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.BreakStatement,outputs:[],calledBySuccess:[],calledByError:[],calledByEntry:[],throws:null,parent:null,x:0,y:0}}static fromGenerationTarget(e,t){const i=_(e.parent),s=t.get(i),l=e.calledByEntry.map(c=>{const I=_(c);return t.get(I)}),o=e.calledBySuccess.map(c=>{const I=_(c);return t.get(I)}),d=e.calledByError.map(c=>{const I=_(c);return t.get(I)}),u={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.BreakStatement,x:0,y:0,outputs:[],calledBySuccess:o,calledByError:d,calledByEntry:l,throws:null,parent:s},y=C(u,t);return y.setParent(s,null),y.initChildren(null),y}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=At(i,{parent:{list:!1,types:[n.Loop]}},t);return i=l.modifiedData,s.push(...l.errors,...ut(i)),{errors:s,modifiedData:i}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
86
+ You can attach new logic to the existing 'global-event' but creating a new callable entity that gets called by it.`,issue:null}))}return{errors:s,modifiedData:i}}get returnStatements(){const e=[];return Object.values(this.detachedDependents).forEach(t=>{t.field===gl.Parent&&t.entity.type===n.ReturnStatement&&!e.includes(t.entity)&&e.push(t.entity)}),e}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on an '${this.type}', must be the root project as it is a globally declared entity.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],i=[],s=[];return Object.values(this.detachedDependents).forEach(l=>{const o=l.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),i.push(...o.removed),s.push(...o.affected)}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){return this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Pe(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.calls=this.calls,e.implements=this.implements,e.detachedChildren=this.detachedChildren,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[I,E]of c.knownVersions)u.set(I,E);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Pe(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.calls=o.calls,this.implements=o.implements,this.detachedChildren=o.detachedChildren,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${xt(this.type)} with id '${this.id}' has a parent reference "${l}" which is missing in the project`)}else throw new Error(`${xt(this.type)} with id '${this.id}' is missing a parent reference`);if(this.initialData.implements){const l=_(this.initialData.implements),o=this.project.get(l);if(o)this.setImplements(o,null),e.push(o);else throw new Error(`${xt(this.type)} with id '${this.id}' has a 'implements' reference "${l}" which is missing in the project`)}else throw new Error(`${xt(this.type)} with id '${this.id}' is missing a 'implements' reference`);return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.project.addGlobalEvent(this),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}replaceDetachedChild(e,t){const i=this.detachedChildren.indexOf(e);return i!==-1&&(this.detachedChildren[i]=t),this}subscribeDetachedChild(e){return this.detachedChildren.includes(e)||this.detachedChildren.push(e),this}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setImplements(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-implements"))){var i;return((i=this.implements)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.implements=e,t&&(t==null||t.add(this,A.Updated),t==null||t.attemptAutoclose("set-implements",this.id))),this}addCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-call"))){return this.calls.includes(e)||(this.calls.push(e),t==null||t.add(e,A.Affected)),t==null||t.attemptAutoclose("add-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-call"))){const i=this.calls.indexOf(e);return i!==-1&&(this.calls.splice(i,1),t==null||t.add(e,A.Affected)),t==null||t.attemptAutoclose("remove-call",this.id),this}addInputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-input-declaration"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input-declaration",this.id),this):(this.inputs.push(e),t==null||t.attemptAutoclose("add-input-declaration",this.id),this)}removeInputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-input-declaration"))){const i=this.inputs.findIndex(s=>s.id===e.id);return i>-1&&(this.inputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-input-declaration",this.id),this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.inputs=this.initialData.inputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.calls=this.initialData.calls.map(t=>{const i=C(t,this.project);return i.addEntryCaller(this,null),i.type!==n.InternalCall&&(i.setParent(this,null),i.initChildren(e)),i}),this.implements=C(this.initialData.implements,this.project),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.name=e.name||s.name,this.description=e.description||s.description,this.x=e.x||s.x,this.y=e.y||s.y,this.collapsed=e.collapsed!==void 0?e.collapsed:s.collapsed,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=g,...t){return await Pe.repository.APILoad(this.id,...t),this}async APICreate(e=g,...t){return await Pe.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=g,...t){return await Pe.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=g,...t){return await Pe.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=g,...t){return await Pe.repository.APIClone(this.id,...t),this}async APILoadVersion(e=g,t,...i){return await Pe.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];return t!=null&&t.hasRemoved(this.id)?(t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(u=>{const{updated:y,removed:c,added:I}=u.entity.onDetachedDependencyRemoved(this,u.field,t);i.push(...y),s.push(...c),l.push(...I)}),this.inputs.forEach(u=>{const{updated:y,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...y),s.push(...c)}),oi(this).forEach(u=>{const{updated:y,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...y),s.push(...c)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this})}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.inputs.forEach(d=>{const{updated:u}=d.restore({},e);i.push(...u)}),oi(this).forEach(d=>{const{updated:u}=d.restore({},e);i.push(...u)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.inputs.flatMap(i=>i.toFlat(e)),...this.calls.flatMap(i=>i.toFlat(e)),...this.returnStatements.flatMap(i=>i.toFlat(e)),...this.implements?this.implements.toFlat(e):[]])}toFlatIds(e=new Set){if(e.has(this.id))return[];e.add(this.id);const t=oi(this);return[this.id,...this.inputs.flatMap(s=>s.toFlatIds(e)),...this.calls.flatMap(s=>s.toFlatIds(e)),...this.returnStatements.flatMap(s=>s.toFlatIds(e)),...this.implements?this.implements.toFlatIds(e):[],...t.flatMap(s=>s.toFlatIds(e))]}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,collapsed:this.collapsed,x:this.x,y:this.y,type:this.type,name:this.name}}toJSON(e=new Set){return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,x:this.x,y:this.y,collapsed:this.collapsed,implements:this.implements.toJSON(e),inputs:this.inputs.map(t=>t.toJSON(e)),calls:this.calls.map(t=>t.toJSON(e)),parent:this.parent.toReference()})}toJSONClone(e=q){var i,s,l,o,d;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,x:this.x,y:this.y,collapsed:this.collapsed,implements:this.implements.toJSON(),inputs:this.inputs.map(u=>u.toJSONClone({...e,newId:null})),calls:this.calls.map(u=>u.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,collapsed:this.collapsed,x:this.x,y:this.y,implements:this.implements.toReference(e),inputs:this.inputs.map(s=>s.toReference(e)),calls:this.calls.map(s=>s.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.inputs.flatMap(i=>i.toFlatJSON(e)),...this.calls.flatMap(i=>i.toFlatJSON(e)),...this.returnStatements.flatMap(i=>i.toFlatJSON(e))])}toGenerationTarget(){return{id:this.id,name:this.name,description:this.description||void 0,type:this.type,implements:this.implements.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.inputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.calls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.returnStatements.flatMap(i=>i.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.inputs.forEach(e=>e.clearErrors()),this.calls.forEach(e=>e.clearErrors()),this.returnStatements.forEach(e=>e.clearErrors()),this}validate(){const e=p1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){const e=oi(this);return[...this.errors,...this.inputs.flatMap(i=>i.getErrors()),...e.flatMap(i=>i.getErrors())]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0,l=!1){var P;let o=mt(t,this);const d=this.toJSON(),u=i||m.UUID.uuid();d.inputs=[];const y=u.split("-id"),c=y[y.length-1||0]||u;d.id=u,d.version=m.UUID.uuid(),d.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),d.author=(e==null?void 0:e.author)||"1",d.previousVersion=null,d.deleted=!1;const I=ct(d,o);t?I.setParent(t,null):I.setParent(this.parent,null),s&&I.subscribe(),I.initChildren(e),e==null||e.add(I,A.Added);const E=(P=this.inputs)==null?void 0:P.map((V,M)=>V.clone(e,I,c+"-argument-declaration-"+M+"-id",s));return I.inputs=E,l?(oi(this).map((V,M)=>V.clone(e,I,c+"-body-entity-"+M+"-id")),e==null||e.attemptAutoclose("clone-entity",this.id),I):(e==null||e.attemptAutoclose("clone-entity",this.id),I)}getVariableInstances(){return Ye(this).filter(i=>i.type===n.VariableInstance)}addReturnStatement(e){return this.returnStatements.includes(e)||this.returnStatements.push(e),this}removeReturnStatement(e){const t=this.returnStatements.indexOf(e);return t!==-1&&this.returnStatements.splice(t,1),this}};f(Pe,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(Pe,"type",n.GlobalEvent),f(Pe,"USER_MANAGED_PARENT_TYPES",[n.Project]),f(Pe,"PARENT_TYPES",[...Pe.USER_MANAGED_PARENT_TYPES]),f(Pe,"MUTABLE_BASE_PROPERTIES",["description"]),f(Pe,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Pe,"BASE_PROPERTIES",[...Pe.MUTABLE_BASE_PROPERTIES,...Pe.INMUTABLE_BASE_PROPERTIES]),f(Pe,"MUTABLE_META_PROPERTIES",[...Pe.MUTABLE_BASE_PROPERTIES,"x","y","collapsed"]),f(Pe,"INMUTABLE_META_PROPERTIES",[...Pe.INMUTABLE_BASE_PROPERTIES]),f(Pe,"META_PROPERTIES",[...Pe.MUTABLE_META_PROPERTIES,...Pe.INMUTABLE_META_PROPERTIES]),f(Pe,"MUTABLE_UPSTREAM_PROPERTIES",[]),f(Pe,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements"]),f(Pe,"UPSTREAM_PROPERTIES",[...Pe.MUTABLE_UPSTREAM_PROPERTIES,...Pe.INMUTABLE_UPSTREAM_PROPERTIES]),f(Pe,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","calls","returnStatements"]),f(Pe,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Pe,"DOWNSTREAM_PROPERTIES",[...Pe.MUTABLE_DOWNSTREAM_PROPERTIES,...Pe.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Pe,"PROPERTIES",[...Pe.META_PROPERTIES,...Pe.UPSTREAM_PROPERTIES,...Pe.DOWNSTREAM_PROPERTIES]);let Fr=Pe;function c1(r){var s;const a=v5(),e=r.toJSON();a.safeParse(e).success,r.outputs.forEach(l=>l.validate()),(s=r.throws)==null||s.validate();const i=[];return He(r.errors,i)}const C7=Object.freeze(Object.defineProperty({__proto__:null,validate:c1},Symbol.toStringTag,{value:"Module"}));var Vc=(r=>(r.Parent="parent",r))(Vc||{});const xe=class xe extends at{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"x");f(this,"y");f(this,"type",n.BreakStatement);f(this,"outputs",[]);f(this,"calledBySuccess",[]);f(this,"calledByError",[]);f(this,"calledByEntry",[]);f(this,"throws",null);f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static new(){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.BreakStatement,outputs:[],calledBySuccess:[],calledByError:[],calledByEntry:[],throws:null,parent:null,x:0,y:0}}static fromGenerationTarget(e,t){const i=_(e.parent),s=t.get(i),l=e.calledByEntry.map(c=>{const I=_(c);return t.get(I)}),o=e.calledBySuccess.map(c=>{const I=_(c);return t.get(I)}),d=e.calledByError.map(c=>{const I=_(c);return t.get(I)}),u={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.BreakStatement,x:0,y:0,outputs:[],calledBySuccess:o,calledByError:d,calledByEntry:l,throws:null,parent:s},y=C(u,t);return y.setParent(s,null),y.initChildren(null),y}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=At(i,{parent:{list:!1,types:[n.Loop]}},t);return i=l.modifiedData,s.push(...l.errors,...ut(i)),{errors:s,modifiedData:i}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
87
87
  If an entity is called by another, they must be in the same scope, which means they have the same parent.
88
88
  You shouldn't have to manually update a 'parent' property.
89
- Specifically for break statements the parent needs to always be the 'loop' entity that contains it.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],i=[],s=[];return Object.values(this.detachedDependents).forEach(l=>{const o=l.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),i.push(...o.removed),s.push(...o.affected)}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new xe(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.outputs=this.outputs,e.throws=this.throws,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[I,E]of c.knownVersions)u.set(I,E);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new xe(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.outputs=o.outputs,this.throws=o.throws,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);return this.initialData.calledByEntry.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(d.addErrorCall(this,null),e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.calledByEntry.forEach(o=>{o.addCall(this,e),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this,e),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this,e),t.push(o)}),this.parent.addBreakStatement(this),t.push(this.parent),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}addSuccessCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,A.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,A.Updated),i&&K(this,t),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,A.Updated),i&&K(this,t),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}removeCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected)),!0):!1),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected)),!0):!1),i&&K(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}addOutputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-output-declaration"))){return this.outputs.find(i=>i.id===e.id)||(this.outputs.push(e),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-output-declaration",this.id),this}removeOutputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-output-declaration"))){return this.outputs.find(i=>i.id===e.id)&&(this.outputs=this.outputs.filter(i=>i.id!==e.id),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("remove-output-declaration",this.id),this}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.outputs=this.initialData.outputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.initialData.throws&&(this.throws=C(this.initialData.throws,this.project),this.throws.setParent(this,null),this.throws.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=g,...t){return await xe.repository.APILoad(this.id,...t),this}async APICreate(e=g,...t){return await xe.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=g,...t){return await xe.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=g,...t){return await xe.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=g,...t){return await xe.repository.APIClone(this.id,...t),this}async APILoadVersion(e=g,t,...i){return await xe.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:y,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...y),l.push(...c)}),this.outputs.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.throws){const{updated:d,removed:u}=this.throws.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}return this.parent.removeBreakStatement(this),e||this.calledBy.forEach(d=>{i.push(d),d.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.throws){const{updated:o}=this.throws.restore({},e);i.push(...o)}return this.parent.addBreakStatement(this),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.outputs.flatMap(i=>i.toFlat(e)),...this.throws?this.throws.toFlat(e):[]])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.outputs.flatMap(i=>i.toFlatIds(e)),...this.throws?this.throws.toFlatIds(e):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,outputs:this.outputs.map(s=>s.toJSON(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference()),calledByError:this.calledByError.map(s=>s.toReference()),calledByEntry:this.calledByEntry.map(s=>s.toReference()),parent:((t=this.parent)==null?void 0:t.toReference())||null,throws:((i=this.throws)==null?void 0:i.toJSON(e))||null})}toJSONClone(e=q){var i,s,l,o,d,u,y;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,outputs:this.outputs.map(c=>c.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),parent:((u=this.parent)==null?void 0:u.toReference({seenEntityMaps:e.seenEntityMaps}))||null,throws:((y=this.throws)==null?void 0:y.toJSONClone({...e,newId:null}))||null})}toReference(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=q){var i,s,l;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,outputs:this.outputs.map(o=>o.toReference(e)),calledBySuccess:this.calledBySuccess.map(o=>o.toReference(e)),calledByError:this.calledByError.map(o=>o.toReference(e)),calledByEntry:this.calledByEntry.map(o=>o.toReference(e)),throws:((s=this.throws)==null?void 0:s.toReference(e))||null,parent:((l=this.parent)==null?void 0:l.toReference(e))||null}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.outputs.flatMap(i=>i.toFlatJSON(e)),...this.throws?this.throws.toFlatJSON(e):[]])}toGenerationTarget(){return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(e=>e.id),calledByError:this.calledByError.map(e=>e.id),calledBySuccess:this.calledBySuccess.map(e=>e.id),parent:this.parent.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.outputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.throws?this.throws.toFlatGenerationTarget(e):[]])}clearErrors(){var e;return this.errors=[],this.outputs.forEach(t=>t.clearErrors()),(e=this.throws)==null||e.clearErrors(),this}validate(){const e=c1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.outputs.flatMap(t=>t.getErrors()),...this.throws?this.throws.getErrors():[]]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var E;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.outputs=[];const u=d.split("-id"),y=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=ct(o,l);t?c.setParent(t,null):c.setParent(this.parent,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,A.Added);const I=(E=this.outputs)==null?void 0:E.map((O,P)=>O.clone(e,c,y+"-return-declaration-"+P+"-id",s));return c.outputs=I,this.throws&&(c.throws=this.throws.clone(e,c,y+"-throws-id",s)),e==null||e.attemptAutoclose("clone-entity",this.id),c}};f(xe,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(xe,"type",n.BreakStatement),f(xe,"USER_MANAGED_PARENT_TYPES",[n.Loop]),f(xe,"PARENT_TYPES",[...xe.USER_MANAGED_PARENT_TYPES]),f(xe,"MUTABLE_BASE_PROPERTIES",[]),f(xe,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(xe,"BASE_PROPERTIES",[...xe.MUTABLE_BASE_PROPERTIES,...xe.INMUTABLE_BASE_PROPERTIES]),f(xe,"MUTABLE_META_PROPERTIES",["x","y"]),f(xe,"INMUTABLE_META_PROPERTIES",[...xe.INMUTABLE_BASE_PROPERTIES]),f(xe,"META_PROPERTIES",[...xe.MUTABLE_META_PROPERTIES,...xe.INMUTABLE_META_PROPERTIES]),f(xe,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","parent"]),f(xe,"INMUTABLE_UPSTREAM_PROPERTIES",[]),f(xe,"UPSTREAM_PROPERTIES",[...xe.MUTABLE_UPSTREAM_PROPERTIES,...xe.INMUTABLE_UPSTREAM_PROPERTIES]),f(xe,"MUTABLE_DOWNSTREAM_PROPERTIES",["outputs","throws"]),f(xe,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(xe,"DOWNSTREAM_PROPERTIES",[...xe.MUTABLE_DOWNSTREAM_PROPERTIES,...xe.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(xe,"PROPERTIES",[...xe.META_PROPERTIES,...xe.UPSTREAM_PROPERTIES,...xe.DOWNSTREAM_PROPERTIES]);let xr=xe;function Bc(r){var l,o;const a=t5(),e=r.toJSON();a.safeParse(e).success,r.inputs.forEach(d=>d.validate()),r.outputs.forEach(d=>d.validate()),(l=r.error)==null||l.validate(),(o=r.body)==null||o.validate();const s=[...vr(r)];return He(r.errors,s)}function Vq(r){return Bc(r)}const Bq=Object.freeze(Object.defineProperty({__proto__:null,validate:Bc,validateListLoop:Vq},Symbol.toStringTag,{value:"Module"}));function f1(r){const a=mD(),e=r.toJSON();a.safeParse(e).success,r.inputs.flatMap(s=>s.validate()),r.outputs.flatMap(s=>s.validate());const i=[];return He(r.errors,i)}const _q=Object.freeze(Object.defineProperty({__proto__:null,validate:f1},Symbol.toStringTag,{value:"Module"}));var y1=(r=>(r.Success="success",r.Error="error",r.Break="break",r.Continue="continue",r.Return="return",r))(y1||{});const we=class we extends at{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"type",n.ActionDescriptor);f(this,"inputs",[]);f(this,"outputs",[]);f(this,"error",null);f(this,"implementation",null);f(this,"parent",null);f(this,"errors",[]);f(this,"project");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"autoexecutable",!1);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description}static new(){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ActionDescriptor,name:"",description:"",error:null,inputs:[],outputs:[],parent:null}}static fromGenerationTarget(e,t){let i=null;if(e.parent){const o=_(e.parent);i=t.get(o)}const s={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,type:n.ActionDescriptor,description:e.description,inputs:[],outputs:[],error:null,parent:i},l=C(s,t);return i&&l.setParent(i,null),l.initChildren(null),l}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=At(i,{parent:{list:!1,types:[n.DefinitionEntity,n.DataType]}},t);i=l.modifiedData;const o=i.parent?t.get(i.parent):null;if(o&&o.type===n.DefinitionEntity){const d=o,y=kt(d).filter(c=>!c.interactive);if(y.length){let c=y.length>1?`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${d.id}' because it extends or implements multiple '${n.BuiltInBaseEntity}' entities that are non-interactive ("${ne(y.map(I=>x(I,I.project)),'", "','" and "')}").`:`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${d.id}' because it extends or implements a '${n.BuiltInBaseEntity}' entity that is non-interactive ("${x(y[0],y[0].project)}").`;c+=`
89
+ Specifically for break statements the parent needs to always be the 'loop' entity that contains it.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],i=[],s=[];return Object.values(this.detachedDependents).forEach(l=>{const o=l.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),i.push(...o.removed),s.push(...o.affected)}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new xe(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.outputs=this.outputs,e.throws=this.throws,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[I,E]of c.knownVersions)u.set(I,E);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new xe(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.outputs=o.outputs,this.throws=o.throws,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);return this.initialData.calledByEntry.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(d.addCall(this,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(d.addSuccessCall(this,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(d.addErrorCall(this,null),e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.calledByEntry.forEach(o=>{o.addCall(this,e),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this,e),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this,e),t.push(o)}),this.parent.addBreakStatement(this),t.push(this.parent),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}addSuccessCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,A.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,A.Updated),i&&K(this,t),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,A.Updated),i&&K(this,t),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}removeCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected)),!0):!1),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected)),!0):!1),i&&K(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}addOutputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-output-declaration"))){return this.outputs.find(i=>i.id===e.id)||(this.outputs.push(e),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-output-declaration",this.id),this}removeOutputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-output-declaration"))){return this.outputs.find(i=>i.id===e.id)&&(this.outputs=this.outputs.filter(i=>i.id!==e.id),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("remove-output-declaration",this.id),this}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.outputs=this.initialData.outputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.initialData.throws&&(this.throws=C(this.initialData.throws,this.project),this.throws.setParent(this,null),this.throws.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=g,...t){return await xe.repository.APILoad(this.id,...t),this}async APICreate(e=g,...t){return await xe.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=g,...t){return await xe.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=g,...t){return await xe.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=g,...t){return await xe.repository.APIClone(this.id,...t),this}async APILoadVersion(e=g,t,...i){return await xe.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:y,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...y),l.push(...c)}),this.outputs.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.throws){const{updated:d,removed:u}=this.throws.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}return this.parent.removeBreakStatement(this),e||this.calledBy.forEach(d=>{i.push(d),d.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.throws){const{updated:o}=this.throws.restore({},e);i.push(...o)}return this.parent.addBreakStatement(this),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.outputs.flatMap(i=>i.toFlat(e)),...this.throws?this.throws.toFlat(e):[]])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.outputs.flatMap(i=>i.toFlatIds(e)),...this.throws?this.throws.toFlatIds(e):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,outputs:this.outputs.map(s=>s.toJSON(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference()),calledByError:this.calledByError.map(s=>s.toReference()),calledByEntry:this.calledByEntry.map(s=>s.toReference()),parent:((t=this.parent)==null?void 0:t.toReference())||null,throws:((i=this.throws)==null?void 0:i.toJSON(e))||null})}toJSONClone(e=q){var i,s,l,o,d,u,y;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,outputs:this.outputs.map(c=>c.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),parent:((u=this.parent)==null?void 0:u.toReference({seenEntityMaps:e.seenEntityMaps}))||null,throws:((y=this.throws)==null?void 0:y.toJSONClone({...e,newId:null}))||null})}toReference(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=q){var i,s,l;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,outputs:this.outputs.map(o=>o.toReference(e)),calledBySuccess:this.calledBySuccess.map(o=>o.toReference(e)),calledByError:this.calledByError.map(o=>o.toReference(e)),calledByEntry:this.calledByEntry.map(o=>o.toReference(e)),throws:((s=this.throws)==null?void 0:s.toReference(e))||null,parent:((l=this.parent)==null?void 0:l.toReference(e))||null}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.outputs.flatMap(i=>i.toFlatJSON(e)),...this.throws?this.throws.toFlatJSON(e):[]])}toGenerationTarget(){return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(e=>e.id),calledByError:this.calledByError.map(e=>e.id),calledBySuccess:this.calledBySuccess.map(e=>e.id),parent:this.parent.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.outputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.throws?this.throws.toFlatGenerationTarget(e):[]])}clearErrors(){var e;return this.errors=[],this.outputs.forEach(t=>t.clearErrors()),(e=this.throws)==null||e.clearErrors(),this}validate(){const e=c1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.outputs.flatMap(t=>t.getErrors()),...this.throws?this.throws.getErrors():[]]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var E;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.outputs=[];const u=d.split("-id"),y=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=ct(o,l);t?c.setParent(t,null):c.setParent(this.parent,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,A.Added);const I=(E=this.outputs)==null?void 0:E.map((O,P)=>O.clone(e,c,y+"-return-declaration-"+P+"-id",s));return c.outputs=I,this.throws&&(c.throws=this.throws.clone(e,c,y+"-throws-id",s)),e==null||e.attemptAutoclose("clone-entity",this.id),c}};f(xe,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(xe,"type",n.BreakStatement),f(xe,"USER_MANAGED_PARENT_TYPES",[n.Loop]),f(xe,"PARENT_TYPES",[...xe.USER_MANAGED_PARENT_TYPES]),f(xe,"MUTABLE_BASE_PROPERTIES",[]),f(xe,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(xe,"BASE_PROPERTIES",[...xe.MUTABLE_BASE_PROPERTIES,...xe.INMUTABLE_BASE_PROPERTIES]),f(xe,"MUTABLE_META_PROPERTIES",["x","y"]),f(xe,"INMUTABLE_META_PROPERTIES",[...xe.INMUTABLE_BASE_PROPERTIES]),f(xe,"META_PROPERTIES",[...xe.MUTABLE_META_PROPERTIES,...xe.INMUTABLE_META_PROPERTIES]),f(xe,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","parent"]),f(xe,"INMUTABLE_UPSTREAM_PROPERTIES",[]),f(xe,"UPSTREAM_PROPERTIES",[...xe.MUTABLE_UPSTREAM_PROPERTIES,...xe.INMUTABLE_UPSTREAM_PROPERTIES]),f(xe,"MUTABLE_DOWNSTREAM_PROPERTIES",["outputs","throws"]),f(xe,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(xe,"DOWNSTREAM_PROPERTIES",[...xe.MUTABLE_DOWNSTREAM_PROPERTIES,...xe.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(xe,"PROPERTIES",[...xe.META_PROPERTIES,...xe.UPSTREAM_PROPERTIES,...xe.DOWNSTREAM_PROPERTIES]);let xr=xe;function Bc(r){var l,o;const a=t5(),e=r.toJSON();a.safeParse(e).success,r.inputs.forEach(d=>d.validate()),r.outputs.forEach(d=>d.validate()),(l=r.error)==null||l.validate(),(o=r.body)==null||o.validate();const s=[...vr(r)];return He(r.errors,s)}function V7(r){return Bc(r)}const B7=Object.freeze(Object.defineProperty({__proto__:null,validate:Bc,validateListLoop:V7},Symbol.toStringTag,{value:"Module"}));function f1(r){const a=mD(),e=r.toJSON();a.safeParse(e).success,r.inputs.flatMap(s=>s.validate()),r.outputs.flatMap(s=>s.validate());const i=[];return He(r.errors,i)}const _7=Object.freeze(Object.defineProperty({__proto__:null,validate:f1},Symbol.toStringTag,{value:"Module"}));var y1=(r=>(r.Success="success",r.Error="error",r.Break="break",r.Continue="continue",r.Return="return",r))(y1||{});const we=class we extends at{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"type",n.ActionDescriptor);f(this,"inputs",[]);f(this,"outputs",[]);f(this,"error",null);f(this,"implementation",null);f(this,"parent",null);f(this,"errors",[]);f(this,"project");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"autoexecutable",!1);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description}static new(){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ActionDescriptor,name:"",description:"",error:null,inputs:[],outputs:[],parent:null}}static fromGenerationTarget(e,t){let i=null;if(e.parent){const o=_(e.parent);i=t.get(o)}const s={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,type:n.ActionDescriptor,description:e.description,inputs:[],outputs:[],error:null,parent:i},l=C(s,t);return i&&l.setParent(i,null),l.initChildren(null),l}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=At(i,{parent:{list:!1,types:[n.DefinitionEntity,n.DataType]}},t);i=l.modifiedData;const o=i.parent?t.get(i.parent):null;if(o&&o.type===n.DefinitionEntity){const d=o,y=kt(d).filter(c=>!c.interactive);if(y.length){let c=y.length>1?`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${d.id}' because it extends or implements multiple '${n.BuiltInBaseEntity}' entities that are non-interactive ("${ne(y.map(I=>x(I,I.project)),'", "','" and "')}").`:`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${d.id}' because it extends or implements a '${n.BuiltInBaseEntity}' entity that is non-interactive ("${x(y[0],y[0].project)}").`;c+=`
90
90
  ${Qr}`,s.push(new w({id:`${e.id}--${R.NonInteractiveEntityReferenced}`,code:R.NonInteractiveEntityReferenced,severity:D.Error,message:c,issue:null}))}}else if(o&&o.type===n.DataType){const d=o;d.entity&&s.push(new w({id:`${e.id}--${R.NewEntityWouldOverriteExisting}`,code:R.NewEntityWouldOverriteExisting,severity:D.Error,message:`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${d.id}' because it already has an 'entity' child. Data type entities can only have one 'entity' as children.
91
91
  You can inspect the existing 'entity' field with the 'describe_entity' action. Like so:
92
92
  ${Yi({describe_entity:d.entity.id})}
@@ -96,19 +96,19 @@ ${Sl(t)}`,issue:null})):s.push(new w({id:`${e.id}--${R.ReferencedEntityNotFound}
96
96
  ${Sl(t)}`,issue:null})):s.push(new w({id:`${e.id}--${j.InvalidObjectStructure}`,code:j.InvalidObjectStructure,severity:D.Error,message:`Entity of type '${e.type}' with id '${e.id}' is missing the 'declaration' property. This property is required for a '${e.type}' entity and must point to one of the built-in action descriptors reserved for '${n.Condition}' entities.
97
97
  ${Sl(t)}`,issue:null})),{errors:s,modifiedData:i}}static fromReturnDeclarationToBodyArgumentDeclarationName(e){return`Previous iteration results of '${x(e,e.project)}'`}static fromBodyArgumentDeclarationToReturnDeclarationName(e){const t=e.name.replace("Previous iteration results of '","");return t.slice(0,t.length-1)}static fromReturnDeclarationToLoopOutputDeclarationName(e){return`Result list of '${x(e,e.project)}'`}static fromLoopOutputDeclarationToReturnDeclarationName(e){const t=e.name.replace("Result list of '","");return t.slice(0,t.length-1)}static fromLoopOutputDeclarationToBodyArgumentDeclarationName(e){return e.name.replace("Result list of '","Previous iteration results of '")}static fromBodyArgumentDeclarationToLoopOutputDeclarationName(e){return e.name.replace("Previous iteration results of '","Result list of '")}get continueStatements(){const e=[];return Object.values(this.detachedDependents).forEach(t=>{t.field===wc.Parent&&t.entity.type===n.ContinueStatement&&!e.includes(t.entity)&&e.push(t.entity)}),e}get breakStatements(){const e=[];return Object.values(this.detachedDependents).forEach(t=>{t.field===Vc.Parent&&t.entity.type===n.BreakStatement&&!e.includes(t.entity)&&e.push(t.entity)}),e}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
98
98
  If an entity is called by another, they must be in the same scope, which means they have the same parent.
99
- You shouldn't have to manually update a 'parent' property. The equivalent result is to change its callers, the value writters of its inputs, or the value readers of its outputs.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],i=[],s=[];return Object.values(this.detachedDependents).forEach(l=>{const o=l.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),i.push(...o.removed),s.push(...o.affected)}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new oe(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.declaration=this.declaration,e.outputsDeclarations=this.outputsDeclarations,e.body=this.body,e.calledByEntry=this.calledByEntry,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.process=this.process,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[I,E]of c.knownVersions)u.set(I,E);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new oe(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.error=o.error,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.declaration=o.declaration,this.outputsDeclarations=o.outputsDeclarations,this.body=o.body,this.calledByEntry=o.calledByEntry,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.process=o.process,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.declaration){const l=_(this.initialData.declaration),o=this.project.get(l);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];this.initialized=!0,this.captureVersion();const{updated:o,added:d,removed:u}=this.syncChildren(e);return t.push(...o),i.push(...d),s.push(...u),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.parent===this.project&&this.project.addLoop(this),this.successCalls.forEach(o=>{o.addSuccessCaller(this,e),t.push(o)}),this.errorCalls.forEach(o=>{o.addErrorCaller(this,e),t.push(o)}),this.calledByEntry.forEach(o=>{o.addCall(this,e),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this,e),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this,e),t.push(o)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-input"))){const i=this.inputs.findIndex(s=>s.id===e.id);return i>-1&&(this.inputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-input",this.id),this}addInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-input"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input",this.id),this):(this.inputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-input",this.id),this)}addOutputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-output-declaration"))){return this.outputsDeclarations.includes(e)?(t==null||t.attemptAutoclose("add-output-declaration",this.id),this):(this.outputsDeclarations.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-output-declaration",this.id),this)}removeOutputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-output-declaration"))){const i=this.outputsDeclarations.findIndex(s=>s.id===e.id);return i>-1&&(this.outputsDeclarations.splice(i,1),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("remove-output-declaration",this.id),this}addOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-output"))){return this.outputs.includes(e)?(t==null||t.attemptAutoclose("add-output",this.id),this):(this.outputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-output",this.id),this)}removeOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-output"))){const i=this.outputs.findIndex(s=>s.id===e.id);return i>-1&&(this.outputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-output",this.id),this}setBody(e){return this.body=e,this}addSuccessCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,A.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,A.Updated),i&&K(this,t),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,A.Updated),i&&K(this,t),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}addErrorCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-call")),i=!1){return this.errorCalls.find(s=>s.id===e.id)||(this.errorCalls.push(e),i&&K(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-call")),i=!1){return this.successCalls.find(s=>s.id===e.id)||(this.successCalls.push(e),i&&K(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-success-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-call")),i=!1){const s=this.successCalls.findIndex(o=>o.id===e.id);s>-1&&(this.successCalls.splice(s,1),t==null||t.add(this,A.Affected));const l=this.errorCalls.findIndex(o=>o.id===e.id);return l>-1&&(this.errorCalls.splice(l,1),t==null||t.add(this,A.Affected)),i&&K(this,t),t==null||t.attemptAutoclose("remove-call",this.id),this}removeCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected)),!0):!1),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected)),!0):!1),i&&K(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}replaceDetachedChild(e,t){const i=this.detachedChildren.indexOf(e);return i!==-1&&(this.detachedChildren[i]=t),this}subscribeDetachedChild(e){return this.detachedChildren.includes(e)||this.detachedChildren.push(e),this}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setDeclaration(e){return this.declaration=e,this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.declaration=C(this.initialData.declaration,this.project),this.successCalls=this.initialData.successCalls.map(t=>{const i=C(t,this.project);return i.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type)?(i.setParent(this.parent.parent,null),i.initChildren(e)):i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e)),i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=C(t,this.project);return i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type)?(i.setParent(this.parent.parent,null),i.initChildren(e)):i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e)),i}),this.inputs=this.initialData.inputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.outputs=this.initialData.outputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.initialData.process&&(this.process=C(this.initialData.process,this.project),this.process.setParent(this,null),this.process.initChildren(e)),this.initialData.body&&(this.body=C(this.initialData.body,this.project),this.body.setParent(this,null),this.body.initChildren(e)),this.initialData.error&&(this.error=C(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=g,...t){return await oe.repository.APILoad(this.id,...t),this}async APICreate(e=g,...t){return await oe.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=g,...t){return await oe.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=g,...t){return await oe.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=g,...t){return await oe.repository.APIClone(this.id,...t),this}async APILoadVersion(e=g,t,...i){return await oe.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:y,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...y),l.push(...c)}),this.inputs.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.outputs.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.body.remove({ignoreUpstream:!0},t),this.error){const{updated:d,removed:u}=this.error.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}return this.successCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),this.errorCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),e||this.calledBy.forEach(d=>{i.push(d),d.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.inputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.body.restore({},e),this.successCalls.forEach(o=>{i.push(o),o.addSuccessCaller(this,e)}),this.errorCalls.forEach(o=>{i.push(o),o.addErrorCaller(this,e)}),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.inputs.flatMap(i=>i.toFlat(e)),...this.outputs.flatMap(i=>i.toFlat(e)),...this.outputsDeclarations.flatMap(i=>i.toFlat(e)),...this.process?this.process.toFlat(e):[],...this.successCalls.flatMap(i=>i.toFlat(e)),...this.errorCalls.flatMap(i=>i.toFlat(e)),...this.error?this.error.toFlat(e):[],...this.body?this.body.toFlat(e):[],...this.continueStatements.flatMap(i=>i.toFlat(e)),...this.breakStatements.flatMap(i=>i.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.inputs.flatMap(i=>i.toFlatIds(e)),...this.outputs.flatMap(i=>i.toFlatIds(e)),...this.process?this.process.toFlatIds(e):[],...this.successCalls.flatMap(i=>i.toFlatIds(e)),...this.errorCalls.flatMap(i=>i.toFlatIds(e)),...this.error?this.error.toFlatIds(e):[],...this.body?this.body.toFlatIds(e):[],...this.continueStatements.flatMap(i=>i.toFlatIds(e)),...this.breakStatements.flatMap(i=>i.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,calledBySuccess:this.calledBySuccess.map(s=>s.toReference()),calledByError:this.calledByError.map(s=>s.toReference()),calledByEntry:this.calledByEntry.map(s=>s.toReference()),process:((t=this.process)==null?void 0:t.toJSON(e))||null,declaration:this.declaration.toJSON(e),inputs:this.inputs.map(s=>s.toJSON(e)),outputs:this.outputs.map(s=>s.toJSON(e)),outputsDeclarations:this.outputsDeclarations.map(s=>s.toJSON(e)),successCalls:this.successCalls.map(s=>s.toJSON(e)),errorCalls:this.errorCalls.map(s=>s.toJSON(e)),error:((i=this.error)==null?void 0:i.toJSON(e))||null,body:this.body.toJSON(e),parent:this.parent.toReference()})}toJSONClone(e=q){var i,s,l,o,d,u,y;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,calledBySuccess:this.calledBySuccess.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),process:((u=this.process)==null?void 0:u.toJSONClone({...e,newId:null}))||null,declaration:this.declaration.toJSON(),inputs:this.inputs.map(c=>c.toJSONClone({...e,newId:null})),outputs:this.outputs.map(c=>c.toJSONClone({...e,newId:null})),outputsDeclarations:this.outputsDeclarations.map(c=>c.toJSONClone({...e,newId:null})),successCalls:this.successCalls.map(c=>c.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(c=>c.toJSONClone({...e,newId:null})),error:((y=this.error)==null?void 0:y.toJSONClone({...e,newId:null}))||null,body:this.body.toJSONClone({...e,newId:null}),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=q){var i,s,l,o,d;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,declaration:((s=this.declaration)==null?void 0:s.toReference(e))||null,body:((l=this.body)==null?void 0:l.toReference(e))||null,inputs:this.inputs.map(u=>u.toReference(e)),outputs:this.outputs.map(u=>u.toReference(e)),outputsDeclarations:this.outputsDeclarations.map(u=>u.toReference(e)),successCalls:this.successCalls.map(u=>u.toReference(e)),errorCalls:this.errorCalls.map(u=>u.toReference(e)),process:((o=this.process)==null?void 0:o.toReference(e))||null,calledBySuccess:this.calledBySuccess.map(u=>u.toReference(e)),calledByError:this.calledByError.map(u=>u.toReference(e)),calledByEntry:this.calledByEntry.map(u=>u.toReference(e)),error:((d=this.error)==null?void 0:d.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var i;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((i=this.body)==null?void 0:i.toFlatJSON(e))||[],...this.successCalls.flatMap(s=>s.toFlatJSON(e)),...this.errorCalls.flatMap(s=>s.toFlatJSON(e)),...this.inputs.flatMap(s=>s.toFlatJSON(e)),...this.outputs.flatMap(s=>s.toFlatJSON(e)),...this.continueStatements.flatMap(s=>s.toFlatJSON(e)),...this.breakStatements.flatMap(s=>s.toFlatJSON(e)),...this.error?this.error.toFlatJSON(e):[],...this.process?this.process.toFlatJSON(e):[]])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),declaration:this.declaration.id,parent:e}}toFlatGenerationTarget(e=new Set){var i;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((i=this.body)==null?void 0:i.toFlatGenerationTarget(e))||[],...this.successCalls.flatMap(s=>s.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(s=>s.toFlatGenerationTarget(e)),...this.inputs.flatMap(s=>s.toFlatGenerationTarget(e)),...this.outputs.flatMap(s=>s.toFlatGenerationTarget(e)),...this.continueStatements.flatMap(s=>s.toFlatGenerationTarget(e)),...this.breakStatements.flatMap(s=>s.toFlatGenerationTarget(e)),...this.error?this.error.toFlatGenerationTarget(e):[],...this.process?this.process.toFlatGenerationTarget(e):[]])}clearErrors(){var e,t;return this.errors=[],this.inputs.forEach(i=>i.clearErrors()),this.outputs.forEach(i=>i.clearErrors()),this.successCalls.forEach(i=>i.clearErrors()),this.errorCalls.forEach(i=>i.clearErrors()),this.continueStatements.forEach(i=>i.clearErrors()),this.breakStatements.forEach(i=>i.clearErrors()),(e=this.process)==null||e.clearErrors(),(t=this.error)==null||t.clearErrors(),this}validate(){const e=Bc(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.inputs.flatMap(t=>t.getErrors()),...this.outputs.flatMap(t=>t.getErrors()),...this.body?this.body.getErrors():[],...this.error?this.error.getErrors():[],...this.process?this.process.getErrors():[]]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var O,P;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[];const u=d.split("-id"),y=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=ct(o,l);t?c.setParent(t,null):c.setParent(this.parent,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,A.Added);const I=(O=this.inputs)==null?void 0:O.map((V,M)=>V.clone(e,c,y+"-input-map-"+M+"-id",s));c.inputs=I;const E=(P=this.outputs)==null?void 0:P.map((V,M)=>V.clone(e,c,y+"-output-map-"+M+"-id",s));return c.outputs=E,this.body&&(c.body=this.body.clone(e,c,y+"-body-id",s,!0)),this.error&&(c.error=this.error.clone(e,c,y+"-error-map-id",s)),this.process&&(c.process=this.process.clone(e,c,y+"-process-id",s)),e==null||e.attemptAutoclose("clone-entity",this.id),c}getVariableInstances(){return this.body?Ye(this.body).filter(i=>i.type===n.VariableInstance):[]}addReturnStatement(e){return lt.includes(this.parent.type)&&this.parent.addReturnStatement(e),this}removeReturnStatement(e){return lt.includes(this.parent.type)&&this.parent.removeReturnStatement(e),this}addBreakStatement(e){return this.breakStatements.includes(e)||this.breakStatements.push(e),this}removeBreakStatement(e){const t=this.breakStatements.indexOf(e);return t!==-1&&this.breakStatements.splice(t,1),this}addContinueStatement(e){return this.continueStatements.includes(e)||this.continueStatements.push(e),this}removeContinueStatement(e){const t=this.continueStatements.indexOf(e);return t!==-1&&this.continueStatements.splice(t,1),this}getUniqueReturnDeclarations(){const e=[];return[...this.breakStatements,...this.continueStatements].forEach(i=>{i.outputs.forEach(l=>{e.find(d=>d===l||x(d,this.project)===x(l,this.project)&&Ri(d.dataType,l.dataType))||e.push(l)})}),p(e)}syncTerminationStatements(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-termination-statements"))){const t=[],i=[],s=[],l=[],o=this.getUniqueReturnDeclarations();return[...this.breakStatements,...this.continueStatements].forEach(u=>{const y=u.outputs,c=o.filter(I=>!y.find(E=>x(I,this.project)===x(E,this.project)&&Ri(I.dataType,E.dataType)));c.length&&(t.push(u),e==null||e.add(u,A.Updated)),c.forEach(I=>{const E=I.clone(e,u);e==null||e.add(E,A.Added),E.addSelfToProject(e),i.push(E)})}),e==null||e.attemptAutoclose("sync-termination-statements",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncBodyInputIndexes(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-body-input-indexes"))){const t=[],i=[],s=[],l=[];return this.body.inputs.sort((d,u)=>d.index-u.index),this.body.inputs.forEach((d,u)=>{d.index!==u&&(d.metaSync({index:u},e),t.push(d))}),e==null||e.attemptAutoclose("sync-body-input-indexes",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncBodyArgumentsDeclarations(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-body-arguments-declarations"))){const t=[],i=[],s=[],l=[],{updated:o,added:d,removed:u}=this.syncFixedBodyArgumentDeclarations(e);t.push(...o),i.push(...d),s.push(...u);const y=this.getUniqueReturnDeclarations(),c=this.body.inputs;y.sort((P,V)=>P.index-V.index),y.forEach(P=>{const V=P.getDataType(e);let G=c.find(fe=>x(fe,this.project)===oe.fromReturnDeclarationToBodyArgumentDeclarationName(P)&&Ri(fe.dataType,P.dataType));if(!G){const fe=oe.fromReturnDeclarationToBodyArgumentDeclarationName(P),Ie={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:fe,description:`Aggretated list of all previously outputted values from each iteration by the output '${x(P,this.project)}'`,defaultValue:null,constant:!0,dataType:null,implements:null,index:P.index,required:P.required,parent:this.body.toReference(),writesValues:[]},X=C(Ie,this.project);X.setParent(this.body,e),X.initChildren(e),e==null||e.add(X,A.Added),X.addSelfToProject(e),i.push(X),G=X}const B=this.body.inputs.find(fe=>fe.index===G.index&&fe!==G),$=this.body.inputs.filter(fe=>fe!==G);let Z=G.index;B&&(Z=Math.max(...$.map(fe=>fe.index))+1),G.index!==Z&&(G.metaSync({index:Z},e),t.push(G));const J=G.getDataType(e);let te=J;if(V)if(!J||!Ri(J,V)){if(!te){const Ie=V.clone(e,G);e==null||e.add(Ie,A.Added),Ie.addSelfToProject(e),te=Ie,i.push(Ie),t.push(G)}const fe=te.merge(V,e);fe.self===te?V.remove({ignoreUpstream:!1},e):fe.self===V&&(te.remove({ignoreUpstream:!1},e),te=V),te.metaSync({isList:!0},e)}else te.isList||(te.metaSync({isList:!0},e),t.push(te));if(!V&&!te){const fe={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,parentRelationType:null,isList:!0,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:G.toReference()},Ie=C(fe,this.project);Ie.metaSync({isList:!0},e),Ie.setParent(G,e),Ie.initChildren(e),e==null||e.add(Ie,A.Added),Ie.addSelfToProject(e),i.push(Ie)}});const{updated:I,added:E,removed:O}=this.removeExtraBodyArgumentDeclarations(e);return t.push(...I),i.push(...E),s.push(...O),e==null||e.attemptAutoclose("sync-body-arguments-declarations",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncOutputsDeclarations(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-outputs-declarations"))){const t=[],i=[],s=[],l=[],o=this.getUniqueReturnDeclarations(),d=this.outputsDeclarations;return o.forEach((y,c)=>{y.index!==c&&(y.metaSync({index:c},e),t.push(y))}),o.forEach(y=>{const c=y.getDataType(e);let E=d.find(V=>x(V,this.project)===oe.fromReturnDeclarationToLoopOutputDeclarationName(y)&&Ri(V.dataType,y.dataType));if(!E){const V=oe.fromReturnDeclarationToLoopOutputDeclarationName(y),M={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ValueDescriptor,name:V,description:`Aggretated list of all previously outputted values from each iteration by the output '${x(y,this.project)}'`,defaultValue:null,dataType:null,index:y.index,required:y.required,parentRelationType:N.FixedReturns,parent:this.toReference()},G=C(M,this.project);G.setParent(this,e),G.initChildren(e),e==null||e.add(G,A.Added),G.addSelfToProject(e),i.push(G),E=G}E.index!==y.index&&(E.metaSync({index:y.index},e),t.push(E));let P=E.getDataType(e);if(c)if(!P||!Ri(P,c)){if(!P){const M=c.clone(e,E);e==null||e.add(M,A.Added),M.addSelfToProject(e),P=M,i.push(M),t.push(E)}const V=P.merge(c,e);V.self===P?c.remove({ignoreUpstream:!1},e):V.self===c&&(P.remove({ignoreUpstream:!1},e),P=c),P.metaSync({isList:!0},e)}else P.isList||(P.metaSync({isList:!0},e),t.push(P));if(!c&&!P){const V={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,parentRelationType:null,isList:!0,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:E.toReference()},M=C(V,this.project);M.metaSync({isList:!0},e),M.setParent(E,e),M.initChildren(e),e==null||e.add(M,A.Added),M.addSelfToProject(e),i.push(M)}}),d.filter(y=>!o.find(I=>x(y,this.project)===oe.fromReturnDeclarationToLoopOutputDeclarationName(I))).forEach(y=>{const{updated:c,removed:I}=y.remove({ignoreUpstream:!1},e);t.push(...c),s.push(...I)}),e==null||e.attemptAutoclose("sync-outputs-declarations",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncOutputMaps(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-extended-properties"))){const t=[],i=[],s=[],l=[],o=this.outputsDeclarations,d=this.outputs;return o.forEach(y=>{var E;let I=d.find(O=>{var P,V;return((P=O.declaration)==null?void 0:P.id)===y.id&&Ri((V=O.declaration)==null?void 0:V.dataType,y.dataType)});if(I)((E=I.declaration)==null?void 0:E.id)!==y.id&&(I.setDeclaration(y),t.push(I));else{const O={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.OutputMap,defaultValue:null,index:y.index,declaration:y.toJSON(),writesValues:[],parent:this.toReference()},P=C(O,this.project);P.setParent(this,e),P.initChildren(e),e==null||e.add(P,A.Added),P.addSelfToProject(e),i.push(P),I=P}I.index!==y.index&&(I.metaSync({index:y.index},e),t.push(I))}),d.filter(y=>!o.find(I=>{var E;return((E=y.declaration)==null?void 0:E.id)===I.id})).forEach(y=>{const{updated:c,removed:I}=y.remove({ignoreUpstream:!1},e);t.push(...c),s.push(...I)}),e==null||e.attemptAutoclose("add-extended-properties",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}createCurrentIterationNumberArgumentDeclaration(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"create-current-iteration-number-argument-declaration"))){const t=[],i=[],s=[],l=[];let d=this.body.inputs.find(I=>{var E;return I.name===oe.CURRENT_ITERATION_NUMBER_ARG_NAME||I.id===((E=this.currentIterationNumberArgumentDeclaration)==null?void 0:E.id)});const u=this.getCurrentIterationNumberBuiltInValueDescriptor();if(!d){const I={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:oe.CURRENT_ITERATION_NUMBER_ARG_NAME,description:"The number of the current iteration",defaultValue:null,constant:!0,dataType:null,implements:u==null?void 0:u.toJSON(),index:this.body.inputs.length,required:!0,parent:this.body.toReference(),writesValues:[]},E=C(I,this.project);E.setParent(this.body,e),E.initChildren(e),e==null||e.add(E,A.Added),E.addSelfToProject(e),i.push(E),d=E}!d.index&&d.index!==0&&(d.metaSync({index:0},e),t.push(d)),(!d.implements||d.implements.id!==u.id)&&(d.setImplements(u,e),t.push(d));let c=d.getDataType(e);if(!c){const I={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,parentRelationType:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:d.toReference()},E=C(I,this.project);E.setParent(d,e),E.initChildren(e),e==null||e.add(E,A.Added),E.addSelfToProject(e),i.push(E),c=E}if(!c.entity||c.entity.type!==n.PrimitiveEntity||c.entity.name!==L.Number||c.entity.id!==k["primitive-entity"].number.id){const I=this.project.getBuiltIn(k["primitive-entity"].number.id);c.setEntity(I),t.push(c)}return this.currentIterationNumberArgumentDeclaration=d,e==null||e.attemptAutoclose("create-current-iteration-number-argument-declaration",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}removeExtraBodyArgumentDeclarations(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-extra-body-argument-declarations"))){const t=[],i=[],s=[],l=[],o=this.body.inputs,d=this.getUniqueReturnDeclarations();return o.filter(y=>y===this.currentIterationNumberArgumentDeclaration||y===this.currentValueArgumentDeclaration?!1:!d.find(I=>x(y,this.project)===oe.fromReturnDeclarationToBodyArgumentDeclarationName(I))).forEach(y=>{const{updated:c,removed:I}=y.remove({ignoreUpstream:!1},e);t.push(...c),s.push(...I)}),e==null||e.attemptAutoclose("remove-extra-body-argument-declarations",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}createCurrentValueInputBasedOnInputMap(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"create-current-value-input-based-on-input-map"))){var y,c,I,E,O;const t=[],i=[],s=[],l=[];switch(this.declaration.id){case Q.List:{const P=this.body.inputs.find(G=>{var B;return((B=G.implements)==null?void 0:B.id)===k[n.Loop][Q.List].body.inputs.currentValue.id}),V=this.inputs.find(G=>{var B;return((B=G.declaration)==null?void 0:B.id)===k[n.Loop][Q.List].inputs.list.id});if(!V)break;const M=this.getCurrentValueBuiltInValueDescriptor();if(P){this.currentValueArgumentDeclaration=P;const G=this.project.get(k[n.Loop][Q.List].inputs.list.id);M&&(!P.implements||P.implements.id!==M.id)&&(P.setImplements(M,e),t.push(P));let $=P.getDataType(e);if(!$){const J={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,parentRelationType:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:G.toReference()},te=C(J,this.project);te.setParent(G,e),te.initChildren(e),e==null||e.add(te,A.Added),te.addSelfToProject(e),i.push(te),$=te}const Z=V.getDataType(e);$.merge(Z,e),$.metaSync({isList:!1},e)}else{const G={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:oe.CURRENT_VALUE_ARG_NAME,description:null,defaultValue:null,index:this.body.inputs.length,constant:!0,required:!0,implements:M,writesValues:[],dataType:null,parent:this.body.toReference()},B=C(G,this.project);B.initChildren(e),B.setParent(this.body,e),e==null||e.add(B,A.Added),B.addSelfToProject(e),M&&(!B.implements||B.implements.id!==M.id)&&(B.setImplements(M,e),t.push(B)),i.push(B),this.currentValueArgumentDeclaration=B}break}case Q.ManualFlow:{this.currentValueArgumentDeclaration=null;break}case Q.Counted:{this.currentValueArgumentDeclaration=null;break}case Q.ObjectKeys:{const P=this.body.inputs.find(G=>{var B;return((B=G.implements)==null?void 0:B.id)===k[n.Loop][Q.ObjectKeys].body.inputs.currentValue.id});if(!this.inputs.find(G=>{var B;return((B=G.declaration)==null?void 0:B.id)===k[n.Loop][Q.ObjectKeys].inputs.object.id}))break;const M=this.getCurrentValueBuiltInValueDescriptor();if(P){this.currentValueArgumentDeclaration=P;const G=this.project.get(k[n.Loop][Q.ObjectKeys].inputs.object.id);M&&(!P.implements||P.implements.id!==M.id)&&(P.setImplements(M),t.push(P));let $=P.getDataType(e);if($){const Z=this.project.getBuiltIn(k["primitive-entity"].string.id);((y=$.entity)==null?void 0:y.id)!==Z.id&&($.setEntity(Z),t.push($))}else{const Z={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,parentRelationType:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:G.toReference()},J=C(Z,this.project);J.setParent(G,e),J.initChildren(e),e==null||e.add(J,A.Added),J.addSelfToProject(e),$=J}}else{const G={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:oe.CURRENT_VALUE_ARG_NAME,description:null,defaultValue:null,index:this.body.inputs.length,constant:!0,required:!0,implements:M,writesValues:[],dataType:null,parent:this.body.toReference()},B=C(G,this.project);B.initChildren(e),B.setParent(this.body,e),e==null||e.add(B,A.Added),B.addSelfToProject(e),M&&(!B.implements||B.implements.id!==M.id)&&(B.setImplements(M,e),t.push(B)),i.push(B),this.currentValueArgumentDeclaration=B}break}case Q.ObjectValues:{const P=this.body.inputs.find(G=>{var B;return((B=G.implements)==null?void 0:B.id)===k[n.Loop][Q.ObjectValues].body.inputs.currentValue.id}),V=this.inputs.find(G=>{var B;return((B=G.declaration)==null?void 0:B.id)===k[n.Loop][Q.ObjectValues].inputs.object.id});if(!V)break;const M=this.getCurrentValueBuiltInValueDescriptor();if(P){this.currentValueArgumentDeclaration=P;const G=this.project.get(k[n.Loop][Q.ObjectValues].inputs.object.id);M&&(!P.implements||P.implements.id!==M.id)&&(P.setImplements(M,e),t.push(P));let $=P.getDataType(e);if($){const Z=V.getDataType(e),J=((I=Z==null?void 0:Z.entity)==null?void 0:I.properties)||[];(E=$.orChildrenGroup)==null||E.forEach(te=>{const{updated:fe,removed:Ie}=te.remove({ignoreUpstream:!1},e);t.push(...fe),s.push(...Ie)}),J.forEach(te=>{if(!te.getDataType(e)){const Ie={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parentRelationType:Dt.OrDataTypeGroup,parent:$.toReference()},X=C(Ie,this.project);X.setParent($,e),X.initChildren(e),e==null||e.add(X,A.Added),X.addSelfToProject(e),i.push(X)}})}else{const Z={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,parentRelationType:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:G.toReference()},J=C(Z,this.project);J.setParent(G,e),J.initChildren(e),e==null||e.add(J,A.Added),J.addSelfToProject(e),$=J;const te=V.getDataType(e);(((c=te==null?void 0:te.entity)==null?void 0:c.properties)||[]).forEach(Ie=>{if(!Ie.getDataType(e)){const le={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parentRelationType:Dt.OrDataTypeGroup,parent:J.toReference()},ei=C(le,this.project);ei.setParent(J,e),ei.initChildren(e),e==null||e.add(ei,A.Added),ei.addSelfToProject(e),i.push(ei)}})}}else{const G={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:oe.CURRENT_VALUE_ARG_NAME,description:null,constant:!0,defaultValue:null,index:this.body.inputs.length,required:!0,implements:M,writesValues:[],dataType:null,parent:this.body.toReference()},B=C(G,this.project);B.initChildren(e),B.setParent(this.body,e),e==null||e.add(B,A.Added),B.addSelfToProject(e),M&&(!B.implements||B.implements.id!==M.id)&&(B.setImplements(M,e),t.push(B)),i.push(B),this.currentValueArgumentDeclaration=B}break}case Q.String:{const P=this.body.inputs.find(G=>{var B;return((B=G.implements)==null?void 0:B.id)===k[n.Loop][Q.String].body.inputs.currentValue.id});if(!this.inputs.find(G=>{var B;return((B=G.declaration)==null?void 0:B.id)===k[n.Loop][Q.String].inputs.string.id}))break;const M=this.getCurrentValueBuiltInValueDescriptor();if(P){this.currentValueArgumentDeclaration=P;const G=this.project.get(k[n.Loop]["string-loop"].inputs.string.id);M&&(!P.implements||P.implements.id!==M.id)&&(P.setImplements(M,e),t.push(P));let $=P.getDataType(e);if($){const Z=this.project.getBuiltIn(k["primitive-entity"].string.id);((O=$.entity)==null?void 0:O.id)!==Z.id&&($.setEntity(Z),t.push($))}else{const Z={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,parentRelationType:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:G.toReference()},J=C(Z,this.project);J.setParent(G,e),J.initChildren(e),e==null||e.add(J,A.Added),J.addSelfToProject(e),i.push(J),$=J}}else{const G={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:oe.CURRENT_VALUE_ARG_NAME,description:null,index:this.body.inputs.length,required:!0,constant:!0,defaultValue:null,implements:M,writesValues:[],dataType:null,parent:this.body.toReference()},B=C(G,this.project);B.initChildren(e),B.setParent(this.body,e),e==null||e.add(B,A.Added),B.addSelfToProject(e),M&&(!B.implements||B.implements.id!==M.id)&&(B.setImplements(M,e),t.push(B)),i.push(B),this.currentValueArgumentDeclaration=B}break}}const{updated:o,added:d,removed:u}=this.removeExtraBodyArgumentDeclarations(e);return t.push(...o),i.push(...d),s.push(...u),e==null||e.attemptAutoclose("create-current-value-input-based-on-input-map",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncFixedBodyArgumentDeclarations(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-fixed-body-argument-declarations"))){const t=[],i=[],s=[],l=[],{updated:o,added:d,removed:u}=this.createCurrentIterationNumberArgumentDeclaration(e);t.push(...o),i.push(...d),s.push(...u);const{updated:y,added:c,removed:I}=this.createCurrentValueInputBasedOnInputMap(e);return t.push(...y),i.push(...c),s.push(...I),e==null||e.attemptAutoclose("sync-fixed-body-argument-declarations",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncInputMaps(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-input-maps"))){const t=[],i=[],s=[],l=[];switch(this.declaration.id){case Q.List:{let o=null;if(this.inputs.forEach(d=>{var u;((u=d.declaration)==null?void 0:u.id)===k[n.Loop]["list-loop"].inputs.list.id?o=d:(d.remove({ignoreUpstream:!1},e),s.push(d))}),o){if(o.declaration.id!==k[n.Loop]["list-loop"].inputs.list.id){const d=this.project.get(k[n.Loop]["list-loop"].inputs.list.id);o.setDeclaration(d),t.push(o)}}else{const d=this.project.get(k[n.Loop]["list-loop"].inputs.list.id),u={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:d.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},y=C(u,this.project);y.initChildren(e),y.setParent(this,e),e==null||e.add(y,A.Added),y.addSelfToProject(e),i.push(y)}break}case Q.ManualFlow:{this.inputs.forEach(o=>{o.remove({ignoreUpstream:!1},e),s.push(o)});break}case Q.Counted:{let o=null;if(this.inputs.forEach(d=>{var u;((u=d.declaration)==null?void 0:u.id)===k[n.Loop]["counted-loop"].inputs.number.id?o=d:(d.remove({ignoreUpstream:!1},e),s.push(d))}),o){if(o.declaration.id!==k[n.Loop]["counted-loop"].inputs.number.id){const d=this.project.get(k[n.Loop]["counted-loop"].inputs.number.id);o.setDeclaration(d),t.push(o)}}else{const d=this.project.get(k[n.Loop]["counted-loop"].inputs.number.id),u={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:d.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},y=C(u,this.project);y.initChildren(e),y.setParent(this,e),e==null||e.add(y,A.Added),y.addSelfToProject(e),i.push(y)}break}case Q.ObjectKeys:{let o=null;if(this.inputs.forEach(d=>{var u;((u=d.declaration)==null?void 0:u.id)===k[n.Loop]["object-keys-loop"].inputs.object.id?o=d:(d.remove({ignoreUpstream:!1},e),s.push(d))}),o){if(o.declaration.id!==k[n.Loop]["object-keys-loop"].inputs.object.id){const d=this.project.get(k[n.Loop]["object-keys-loop"].inputs.object.id);o.setDeclaration(d),t.push(o)}}else{const d=this.project.get(k[n.Loop]["object-keys-loop"].inputs.object.id),u={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:d.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},y=C(u,this.project);y.initChildren(e),y.setParent(this,e),e==null||e.add(y,A.Added),y.addSelfToProject(e),i.push(y)}break}case Q.ObjectValues:{let o=null;if(this.inputs.forEach(d=>{var u;((u=d.declaration)==null?void 0:u.id)===k[n.Loop]["object-values-loop"].inputs.object.id?o=d:(d.remove({ignoreUpstream:!1},e),s.push(d))}),o){if(o.declaration.id!==k[n.Loop]["object-values-loop"].inputs.object.id){const d=this.project.get(k[n.Loop]["object-values-loop"].inputs.object.id);o.setDeclaration(d),t.push(o)}}else{const d=this.project.get(k[n.Loop]["object-values-loop"].inputs.object.id),u={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:d.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},y=C(u,this.project);y.initChildren(e),y.setParent(this,e),e==null||e.add(y,A.Added),y.addSelfToProject(e),i.push(y)}break}case Q.String:{let o=null;if(this.inputs.forEach(d=>{var u;((u=d.declaration)==null?void 0:u.id)===k[n.Loop]["string-loop"].inputs.string.id?o=d:(d.remove({ignoreUpstream:!1},e),s.push(d))}),o){if(o.declaration.id!==k[n.Loop]["string-loop"].inputs.string.id){const d=this.project.get(k[n.Loop]["string-loop"].inputs.string.id);o.setDeclaration(d),t.push(o)}}else{const d=this.project.get(k[n.Loop]["string-loop"].inputs.string.id),u={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:d.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},y=C(u,this.project);y.initChildren(e),y.setParent(this,e),e==null||e.add(y,A.Added),y.addSelfToProject(e),i.push(y)}break}}return e==null||e.attemptAutoclose("sync-input-maps",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}getCurrentValueBuiltInValueDescriptor(){var t;const e=(t=k[n.Loop][this.declaration.id].body.inputs.currentValue)==null?void 0:t.id;return e?this.project.get(e):null}getCurrentIterationNumberBuiltInValueDescriptor(){const e=k[n.Loop][this.declaration.id].body.inputs.iterationNumber.id;return this.project.get(e)}syncBody(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-body"))){var u;const t=[],i=[],s=[],l=[],o=k[n.Loop][this.declaration.id].body.id,d=this.project.getBuiltIn(o);if(this.body)((u=this.body.implements)==null?void 0:u.id)!==d.id&&(this.body.setImplements(d,e),this.body.setParent(this,e),t.push(this.body));else{const y={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.FunctionDeclaration,name:d.name,description:null,inputs:[],index:null,calls:[],collapsed:!1,private:!1,implements:d.toJSON(),x:0,y:0,parent:this.toReference()},c=C(y,this.project);c.initChildren(e),c.setParent(this,e),e==null||e.add(c,A.Added),c.addSelfToProject(e),i.push(c)}return e==null||e.attemptAutoclose("sync-body",this.id),{self:this,updated:p(t),added:p(i),removed:p(s),affected:p(l)}}syncChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-children"))){const t=[],i=[],s=[],l=[],{updated:o,added:d,removed:u}=this.syncBody(e);t.push(...o),i.push(...d),s.push(...u);const{updated:y,added:c,removed:I}=this.syncInputMaps(e);t.push(...y),i.push(...c),s.push(...I);const{updated:E,added:O,removed:P}=this.syncTerminationStatements(e);t.push(...E),i.push(...O),s.push(...P);const{updated:V,added:M,removed:G}=this.syncBodyArgumentsDeclarations(e);t.push(...V),i.push(...M),s.push(...G);const{updated:B,added:$,removed:Z}=this.syncBodyInputIndexes(e);t.push(...B),i.push(...$),s.push(...Z);const{updated:J,added:te,removed:fe}=this.syncOutputsDeclarations(e);t.push(...J),i.push(...te),s.push(...fe);const{updated:Ie,added:X,removed:le}=this.syncOutputMaps(e);return t.push(...Ie),i.push(...X),s.push(...le),e==null||e.attemptAutoclose("sync-children",this.id),{self:this,updated:p(t),added:p(i),removed:p(s),affected:p(l)}}};f(oe,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(oe,"type",n.Loop),f(oe,"USER_MANAGED_PARENT_TYPES",[...dt,n.Project]),f(oe,"PARENT_TYPES",[...Je.USER_MANAGED_PARENT_TYPES]),f(oe,"CURRENT_ITERATION_NUMBER_ARG_NAME","Current iteration number"),f(oe,"CURRENT_VALUE_ARG_NAME","Current value"),f(oe,"MUTABLE_BASE_PROPERTIES",[]),f(oe,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(oe,"BASE_PROPERTIES",[...oe.MUTABLE_BASE_PROPERTIES,...oe.INMUTABLE_BASE_PROPERTIES]),f(oe,"MUTABLE_META_PROPERTIES",[...oe.MUTABLE_BASE_PROPERTIES,"x","y"]),f(oe,"INMUTABLE_META_PROPERTIES",[...oe.INMUTABLE_BASE_PROPERTIES]),f(oe,"META_PROPERTIES",[...oe.MUTABLE_META_PROPERTIES,...oe.INMUTABLE_META_PROPERTIES]),f(oe,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),f(oe,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),f(oe,"UPSTREAM_PROPERTIES",[...oe.MUTABLE_UPSTREAM_PROPERTIES,...oe.INMUTABLE_UPSTREAM_PROPERTIES]),f(oe,"MUTABLE_DOWNSTREAM_PROPERTIES",["body","inputs","outputs","outputsDeclarations","successCalls","errorCalls","error","breakStatements","continueStatements"]),f(oe,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(oe,"DOWNSTREAM_PROPERTIES",[...oe.MUTABLE_DOWNSTREAM_PROPERTIES,...oe.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(oe,"PROPERTIES",[...oe.META_PROPERTIES,...oe.UPSTREAM_PROPERTIES,...oe.DOWNSTREAM_PROPERTIES]);let kr=oe;function m1(r){const a=B5(),e=r.toJSON();a.safeParse(e).success,r.inputs.forEach(l=>l.validate());const s=[...vr(r)];return He(r.errors,s)}const Mq=Object.freeze(Object.defineProperty({__proto__:null,validate:m1},Symbol.toStringTag,{value:"Module"}));var v1=(r=>(r.Parent="parent",r))(v1||{});const ke=class ke extends at{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"x");f(this,"y");f(this,"type",n.Condition);f(this,"successCalls",[]);f(this,"errorCalls",[]);f(this,"declaration");f(this,"inputs",[]);f(this,"calledBySuccess",[]);f(this,"calledByError",[]);f(this,"calledByEntry",[]);f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static new(){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Condition,declaration:null,inputs:[],parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],errorCalls:[],successCalls:[],x:0,y:0}}static fromGenerationTarget(e,t){let i=t;if(e.parent){const c=_(e.parent);i=t.get(c)}const s=e.calledByEntry.map(c=>{const I=_(c);return t.get(I)}),l=e.calledBySuccess.map(c=>{const I=_(c);return t.get(I)}),o=e.calledByError.map(c=>{const I=_(c);return t.get(I)});let d;if(e.declaration){const c=_(e.declaration);d=t.get(c)}const u={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Condition,declaration:d,calledByEntry:s,calledBySuccess:l,calledByError:o,errorCalls:[],successCalls:[],inputs:[],x:0,y:0,parent:i},y=C(u,t);return y.setParent(i,null),y.initChildren(null),y}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=At(i,{parent:{list:!1,types:[...dt,n.Project],optional:!0}},t);return i=l.modifiedData,s.push(...l.errors,...ut(i)),e.declaration?t.get(e.declaration)?t.conditionDeclarations.find(u=>u.id===e.declaration)||s.push(new w({id:`${e.id}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:D.Error,message:`Entity of type '${e.type}' with id '${e.id}' has an 'declaration' property that isn't pointing to an action descriptor reserved for '${n.Condition}' entities.
99
+ You shouldn't have to manually update a 'parent' property. The equivalent result is to change its callers, the value writters of its inputs, or the value readers of its outputs.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],i=[],s=[];return Object.values(this.detachedDependents).forEach(l=>{const o=l.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),i.push(...o.removed),s.push(...o.affected)}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new oe(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.declaration=this.declaration,e.outputsDeclarations=this.outputsDeclarations,e.body=this.body,e.calledByEntry=this.calledByEntry,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.process=this.process,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[I,E]of c.knownVersions)u.set(I,E);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new oe(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.error=o.error,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.declaration=o.declaration,this.outputsDeclarations=o.outputsDeclarations,this.body=o.body,this.calledByEntry=o.calledByEntry,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.process=o.process,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.declaration){const l=_(this.initialData.declaration),o=this.project.get(l);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];this.initialized=!0,this.captureVersion();const{updated:o,added:d,removed:u}=this.syncChildren(e);return t.push(...o),i.push(...d),s.push(...u),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.parent===this.project&&this.project.addLoop(this),this.successCalls.forEach(o=>{o.addSuccessCaller(this,e),t.push(o)}),this.errorCalls.forEach(o=>{o.addErrorCaller(this,e),t.push(o)}),this.calledByEntry.forEach(o=>{o.addCall(this,e),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this,e),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this,e),t.push(o)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-input"))){const i=this.inputs.findIndex(s=>s.id===e.id);return i>-1&&(this.inputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-input",this.id),this}addInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-input"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input",this.id),this):(this.inputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-input",this.id),this)}addOutputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-output-declaration"))){return this.outputsDeclarations.includes(e)?(t==null||t.attemptAutoclose("add-output-declaration",this.id),this):(this.outputsDeclarations.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-output-declaration",this.id),this)}removeOutputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-output-declaration"))){const i=this.outputsDeclarations.findIndex(s=>s.id===e.id);return i>-1&&(this.outputsDeclarations.splice(i,1),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("remove-output-declaration",this.id),this}addOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-output"))){return this.outputs.includes(e)?(t==null||t.attemptAutoclose("add-output",this.id),this):(this.outputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-output",this.id),this)}removeOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-output"))){const i=this.outputs.findIndex(s=>s.id===e.id);return i>-1&&(this.outputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-output",this.id),this}setBody(e){return this.body=e,this}addSuccessCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,A.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,A.Updated),i&&K(this,t),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,A.Updated),i&&K(this,t),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}addErrorCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-call")),i=!1){return this.errorCalls.find(s=>s.id===e.id)||(this.errorCalls.push(e),i&&K(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-call")),i=!1){return this.successCalls.find(s=>s.id===e.id)||(this.successCalls.push(e),i&&K(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-success-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-call")),i=!1){const s=this.successCalls.findIndex(o=>o.id===e.id);s>-1&&(this.successCalls.splice(s,1),t==null||t.add(this,A.Affected));const l=this.errorCalls.findIndex(o=>o.id===e.id);return l>-1&&(this.errorCalls.splice(l,1),t==null||t.add(this,A.Affected)),i&&K(this,t),t==null||t.attemptAutoclose("remove-call",this.id),this}removeCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected)),!0):!1),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected)),!0):!1),i&&K(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}replaceDetachedChild(e,t){const i=this.detachedChildren.indexOf(e);return i!==-1&&(this.detachedChildren[i]=t),this}subscribeDetachedChild(e){return this.detachedChildren.includes(e)||this.detachedChildren.push(e),this}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setDeclaration(e){return this.declaration=e,this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.declaration=C(this.initialData.declaration,this.project),this.successCalls=this.initialData.successCalls.map(t=>{const i=C(t,this.project);return i.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type)?(i.setParent(this.parent.parent,null),i.initChildren(e)):i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e)),i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=C(t,this.project);return i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type)?(i.setParent(this.parent.parent,null),i.initChildren(e)):i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e)),i}),this.inputs=this.initialData.inputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.outputs=this.initialData.outputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.initialData.process&&(this.process=C(this.initialData.process,this.project),this.process.setParent(this,null),this.process.initChildren(e)),this.initialData.body&&(this.body=C(this.initialData.body,this.project),this.body.setParent(this,null),this.body.initChildren(e)),this.initialData.error&&(this.error=C(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=g,...t){return await oe.repository.APILoad(this.id,...t),this}async APICreate(e=g,...t){return await oe.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=g,...t){return await oe.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=g,...t){return await oe.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=g,...t){return await oe.repository.APIClone(this.id,...t),this}async APILoadVersion(e=g,t,...i){return await oe.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:y,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...y),l.push(...c)}),this.inputs.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.outputs.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.body.remove({ignoreUpstream:!0},t),this.error){const{updated:d,removed:u}=this.error.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}return this.successCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),this.errorCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),e||this.calledBy.forEach(d=>{i.push(d),d.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.inputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.body.restore({},e),this.successCalls.forEach(o=>{i.push(o),o.addSuccessCaller(this,e)}),this.errorCalls.forEach(o=>{i.push(o),o.addErrorCaller(this,e)}),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.inputs.flatMap(i=>i.toFlat(e)),...this.outputs.flatMap(i=>i.toFlat(e)),...this.outputsDeclarations.flatMap(i=>i.toFlat(e)),...this.process?this.process.toFlat(e):[],...this.successCalls.flatMap(i=>i.toFlat(e)),...this.errorCalls.flatMap(i=>i.toFlat(e)),...this.error?this.error.toFlat(e):[],...this.body?this.body.toFlat(e):[],...this.continueStatements.flatMap(i=>i.toFlat(e)),...this.breakStatements.flatMap(i=>i.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.inputs.flatMap(i=>i.toFlatIds(e)),...this.outputs.flatMap(i=>i.toFlatIds(e)),...this.process?this.process.toFlatIds(e):[],...this.successCalls.flatMap(i=>i.toFlatIds(e)),...this.errorCalls.flatMap(i=>i.toFlatIds(e)),...this.error?this.error.toFlatIds(e):[],...this.body?this.body.toFlatIds(e):[],...this.continueStatements.flatMap(i=>i.toFlatIds(e)),...this.breakStatements.flatMap(i=>i.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,calledBySuccess:this.calledBySuccess.map(s=>s.toReference()),calledByError:this.calledByError.map(s=>s.toReference()),calledByEntry:this.calledByEntry.map(s=>s.toReference()),process:((t=this.process)==null?void 0:t.toJSON(e))||null,declaration:this.declaration.toJSON(e),inputs:this.inputs.map(s=>s.toJSON(e)),outputs:this.outputs.map(s=>s.toJSON(e)),outputsDeclarations:this.outputsDeclarations.map(s=>s.toJSON(e)),successCalls:this.successCalls.map(s=>s.toJSON(e)),errorCalls:this.errorCalls.map(s=>s.toJSON(e)),error:((i=this.error)==null?void 0:i.toJSON(e))||null,body:this.body.toJSON(e),parent:this.parent.toReference()})}toJSONClone(e=q){var i,s,l,o,d,u,y;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,calledBySuccess:this.calledBySuccess.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),process:((u=this.process)==null?void 0:u.toJSONClone({...e,newId:null}))||null,declaration:this.declaration.toJSON(),inputs:this.inputs.map(c=>c.toJSONClone({...e,newId:null})),outputs:this.outputs.map(c=>c.toJSONClone({...e,newId:null})),outputsDeclarations:this.outputsDeclarations.map(c=>c.toJSONClone({...e,newId:null})),successCalls:this.successCalls.map(c=>c.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(c=>c.toJSONClone({...e,newId:null})),error:((y=this.error)==null?void 0:y.toJSONClone({...e,newId:null}))||null,body:this.body.toJSONClone({...e,newId:null}),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=q){var i,s,l,o,d;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,declaration:((s=this.declaration)==null?void 0:s.toReference(e))||null,body:((l=this.body)==null?void 0:l.toReference(e))||null,inputs:this.inputs.map(u=>u.toReference(e)),outputs:this.outputs.map(u=>u.toReference(e)),outputsDeclarations:this.outputsDeclarations.map(u=>u.toReference(e)),successCalls:this.successCalls.map(u=>u.toReference(e)),errorCalls:this.errorCalls.map(u=>u.toReference(e)),process:((o=this.process)==null?void 0:o.toReference(e))||null,calledBySuccess:this.calledBySuccess.map(u=>u.toReference(e)),calledByError:this.calledByError.map(u=>u.toReference(e)),calledByEntry:this.calledByEntry.map(u=>u.toReference(e)),error:((d=this.error)==null?void 0:d.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var i;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((i=this.body)==null?void 0:i.toFlatJSON(e))||[],...this.successCalls.flatMap(s=>s.toFlatJSON(e)),...this.errorCalls.flatMap(s=>s.toFlatJSON(e)),...this.inputs.flatMap(s=>s.toFlatJSON(e)),...this.outputs.flatMap(s=>s.toFlatJSON(e)),...this.continueStatements.flatMap(s=>s.toFlatJSON(e)),...this.breakStatements.flatMap(s=>s.toFlatJSON(e)),...this.error?this.error.toFlatJSON(e):[],...this.process?this.process.toFlatJSON(e):[]])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),declaration:this.declaration.id,parent:e}}toFlatGenerationTarget(e=new Set){var i;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((i=this.body)==null?void 0:i.toFlatGenerationTarget(e))||[],...this.successCalls.flatMap(s=>s.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(s=>s.toFlatGenerationTarget(e)),...this.inputs.flatMap(s=>s.toFlatGenerationTarget(e)),...this.outputs.flatMap(s=>s.toFlatGenerationTarget(e)),...this.continueStatements.flatMap(s=>s.toFlatGenerationTarget(e)),...this.breakStatements.flatMap(s=>s.toFlatGenerationTarget(e)),...this.error?this.error.toFlatGenerationTarget(e):[],...this.process?this.process.toFlatGenerationTarget(e):[]])}clearErrors(){var e,t;return this.errors=[],this.inputs.forEach(i=>i.clearErrors()),this.outputs.forEach(i=>i.clearErrors()),this.successCalls.forEach(i=>i.clearErrors()),this.errorCalls.forEach(i=>i.clearErrors()),this.continueStatements.forEach(i=>i.clearErrors()),this.breakStatements.forEach(i=>i.clearErrors()),(e=this.process)==null||e.clearErrors(),(t=this.error)==null||t.clearErrors(),this}validate(){const e=Bc(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.inputs.flatMap(t=>t.getErrors()),...this.outputs.flatMap(t=>t.getErrors()),...this.body?this.body.getErrors():[],...this.error?this.error.getErrors():[],...this.process?this.process.getErrors():[]]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var O,P;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[];const u=d.split("-id"),y=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=ct(o,l);t?c.setParent(t,null):c.setParent(this.parent,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,A.Added);const I=(O=this.inputs)==null?void 0:O.map((V,M)=>V.clone(e,c,y+"-input-map-"+M+"-id",s));c.inputs=I;const E=(P=this.outputs)==null?void 0:P.map((V,M)=>V.clone(e,c,y+"-output-map-"+M+"-id",s));return c.outputs=E,this.body&&(c.body=this.body.clone(e,c,y+"-body-id",s,!0)),this.error&&(c.error=this.error.clone(e,c,y+"-error-map-id",s)),this.process&&(c.process=this.process.clone(e,c,y+"-process-id",s)),e==null||e.attemptAutoclose("clone-entity",this.id),c}getVariableInstances(){return this.body?Ye(this.body).filter(i=>i.type===n.VariableInstance):[]}addReturnStatement(e){return lt.includes(this.parent.type)&&this.parent.addReturnStatement(e),this}removeReturnStatement(e){return lt.includes(this.parent.type)&&this.parent.removeReturnStatement(e),this}addBreakStatement(e){return this.breakStatements.includes(e)||this.breakStatements.push(e),this}removeBreakStatement(e){const t=this.breakStatements.indexOf(e);return t!==-1&&this.breakStatements.splice(t,1),this}addContinueStatement(e){return this.continueStatements.includes(e)||this.continueStatements.push(e),this}removeContinueStatement(e){const t=this.continueStatements.indexOf(e);return t!==-1&&this.continueStatements.splice(t,1),this}getUniqueReturnDeclarations(){const e=[];return[...this.breakStatements,...this.continueStatements].forEach(i=>{i.outputs.forEach(l=>{e.find(d=>d===l||x(d,this.project)===x(l,this.project)&&Ri(d.dataType,l.dataType))||e.push(l)})}),p(e)}syncTerminationStatements(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-termination-statements"))){const t=[],i=[],s=[],l=[],o=this.getUniqueReturnDeclarations();return[...this.breakStatements,...this.continueStatements].forEach(u=>{const y=u.outputs,c=o.filter(I=>!y.find(E=>x(I,this.project)===x(E,this.project)&&Ri(I.dataType,E.dataType)));c.length&&(t.push(u),e==null||e.add(u,A.Updated)),c.forEach(I=>{const E=I.clone(e,u);e==null||e.add(E,A.Added),E.addSelfToProject(e),i.push(E)})}),e==null||e.attemptAutoclose("sync-termination-statements",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncBodyInputIndexes(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-body-input-indexes"))){const t=[],i=[],s=[],l=[];return this.body.inputs.sort((d,u)=>d.index-u.index),this.body.inputs.forEach((d,u)=>{d.index!==u&&(d.metaSync({index:u},e),t.push(d))}),e==null||e.attemptAutoclose("sync-body-input-indexes",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncBodyArgumentsDeclarations(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-body-arguments-declarations"))){const t=[],i=[],s=[],l=[],{updated:o,added:d,removed:u}=this.syncFixedBodyArgumentDeclarations(e);t.push(...o),i.push(...d),s.push(...u);const y=this.getUniqueReturnDeclarations(),c=this.body.inputs;y.sort((P,V)=>P.index-V.index),y.forEach(P=>{const V=P.getDataType(e);let G=c.find(fe=>x(fe,this.project)===oe.fromReturnDeclarationToBodyArgumentDeclarationName(P)&&Ri(fe.dataType,P.dataType));if(!G){const fe=oe.fromReturnDeclarationToBodyArgumentDeclarationName(P),Ie={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:fe,description:`Aggretated list of all previously outputted values from each iteration by the output '${x(P,this.project)}'`,defaultValue:null,constant:!0,dataType:null,implements:null,index:P.index,required:P.required,parent:this.body.toReference(),writesValues:[]},X=C(Ie,this.project);X.setParent(this.body,e),X.initChildren(e),e==null||e.add(X,A.Added),X.addSelfToProject(e),i.push(X),G=X}const B=this.body.inputs.find(fe=>fe.index===G.index&&fe!==G),$=this.body.inputs.filter(fe=>fe!==G);let Z=G.index;B&&(Z=Math.max(...$.map(fe=>fe.index))+1),G.index!==Z&&(G.metaSync({index:Z},e),t.push(G));const J=G.getDataType(e);let te=J;if(V)if(!J||!Ri(J,V)){if(!te){const Ie=V.clone(e,G);e==null||e.add(Ie,A.Added),Ie.addSelfToProject(e),te=Ie,i.push(Ie),t.push(G)}const fe=te.merge(V,e);fe.self===te?V.remove({ignoreUpstream:!1},e):fe.self===V&&(te.remove({ignoreUpstream:!1},e),te=V),te.metaSync({isList:!0},e)}else te.isList||(te.metaSync({isList:!0},e),t.push(te));if(!V&&!te){const fe={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,parentRelationType:null,isList:!0,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:G.toReference()},Ie=C(fe,this.project);Ie.metaSync({isList:!0},e),Ie.setParent(G,e),Ie.initChildren(e),e==null||e.add(Ie,A.Added),Ie.addSelfToProject(e),i.push(Ie)}});const{updated:I,added:E,removed:O}=this.removeExtraBodyArgumentDeclarations(e);return t.push(...I),i.push(...E),s.push(...O),e==null||e.attemptAutoclose("sync-body-arguments-declarations",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncOutputsDeclarations(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-outputs-declarations"))){const t=[],i=[],s=[],l=[],o=this.getUniqueReturnDeclarations(),d=this.outputsDeclarations;return o.forEach((y,c)=>{y.index!==c&&(y.metaSync({index:c},e),t.push(y))}),o.forEach(y=>{const c=y.getDataType(e);let E=d.find(V=>x(V,this.project)===oe.fromReturnDeclarationToLoopOutputDeclarationName(y)&&Ri(V.dataType,y.dataType));if(!E){const V=oe.fromReturnDeclarationToLoopOutputDeclarationName(y),M={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ValueDescriptor,name:V,description:`Aggretated list of all previously outputted values from each iteration by the output '${x(y,this.project)}'`,defaultValue:null,dataType:null,index:y.index,required:y.required,parentRelationType:N.FixedReturns,parent:this.toReference()},G=C(M,this.project);G.setParent(this,e),G.initChildren(e),e==null||e.add(G,A.Added),G.addSelfToProject(e),i.push(G),E=G}E.index!==y.index&&(E.metaSync({index:y.index},e),t.push(E));let P=E.getDataType(e);if(c)if(!P||!Ri(P,c)){if(!P){const M=c.clone(e,E);e==null||e.add(M,A.Added),M.addSelfToProject(e),P=M,i.push(M),t.push(E)}const V=P.merge(c,e);V.self===P?c.remove({ignoreUpstream:!1},e):V.self===c&&(P.remove({ignoreUpstream:!1},e),P=c),P.metaSync({isList:!0},e)}else P.isList||(P.metaSync({isList:!0},e),t.push(P));if(!c&&!P){const V={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,parentRelationType:null,isList:!0,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:E.toReference()},M=C(V,this.project);M.metaSync({isList:!0},e),M.setParent(E,e),M.initChildren(e),e==null||e.add(M,A.Added),M.addSelfToProject(e),i.push(M)}}),d.filter(y=>!o.find(I=>x(y,this.project)===oe.fromReturnDeclarationToLoopOutputDeclarationName(I))).forEach(y=>{const{updated:c,removed:I}=y.remove({ignoreUpstream:!1},e);t.push(...c),s.push(...I)}),e==null||e.attemptAutoclose("sync-outputs-declarations",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncOutputMaps(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-extended-properties"))){const t=[],i=[],s=[],l=[],o=this.outputsDeclarations,d=this.outputs;return o.forEach(y=>{var E;let I=d.find(O=>{var P,V;return((P=O.declaration)==null?void 0:P.id)===y.id&&Ri((V=O.declaration)==null?void 0:V.dataType,y.dataType)});if(I)((E=I.declaration)==null?void 0:E.id)!==y.id&&(I.setDeclaration(y),t.push(I));else{const O={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.OutputMap,defaultValue:null,index:y.index,declaration:y.toJSON(),writesValues:[],parent:this.toReference()},P=C(O,this.project);P.setParent(this,e),P.initChildren(e),e==null||e.add(P,A.Added),P.addSelfToProject(e),i.push(P),I=P}I.index!==y.index&&(I.metaSync({index:y.index},e),t.push(I))}),d.filter(y=>!o.find(I=>{var E;return((E=y.declaration)==null?void 0:E.id)===I.id})).forEach(y=>{const{updated:c,removed:I}=y.remove({ignoreUpstream:!1},e);t.push(...c),s.push(...I)}),e==null||e.attemptAutoclose("add-extended-properties",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}createCurrentIterationNumberArgumentDeclaration(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"create-current-iteration-number-argument-declaration"))){const t=[],i=[],s=[],l=[];let d=this.body.inputs.find(I=>{var E;return I.name===oe.CURRENT_ITERATION_NUMBER_ARG_NAME||I.id===((E=this.currentIterationNumberArgumentDeclaration)==null?void 0:E.id)});const u=this.getCurrentIterationNumberBuiltInValueDescriptor();if(!d){const I={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:oe.CURRENT_ITERATION_NUMBER_ARG_NAME,description:"The number of the current iteration",defaultValue:null,constant:!0,dataType:null,implements:u==null?void 0:u.toJSON(),index:this.body.inputs.length,required:!0,parent:this.body.toReference(),writesValues:[]},E=C(I,this.project);E.setParent(this.body,e),E.initChildren(e),e==null||e.add(E,A.Added),E.addSelfToProject(e),i.push(E),d=E}!d.index&&d.index!==0&&(d.metaSync({index:0},e),t.push(d)),(!d.implements||d.implements.id!==u.id)&&(d.setImplements(u,e),t.push(d));let c=d.getDataType(e);if(!c){const I={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,parentRelationType:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:d.toReference()},E=C(I,this.project);E.setParent(d,e),E.initChildren(e),e==null||e.add(E,A.Added),E.addSelfToProject(e),i.push(E),c=E}if(!c.entity||c.entity.type!==n.PrimitiveEntity||c.entity.name!==L.Number||c.entity.id!==k["primitive-entity"].number.id){const I=this.project.getBuiltIn(k["primitive-entity"].number.id);c.setEntity(I),t.push(c)}return this.currentIterationNumberArgumentDeclaration=d,e==null||e.attemptAutoclose("create-current-iteration-number-argument-declaration",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}removeExtraBodyArgumentDeclarations(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-extra-body-argument-declarations"))){const t=[],i=[],s=[],l=[],o=this.body.inputs,d=this.getUniqueReturnDeclarations();return o.filter(y=>y===this.currentIterationNumberArgumentDeclaration||y===this.currentValueArgumentDeclaration?!1:!d.find(I=>x(y,this.project)===oe.fromReturnDeclarationToBodyArgumentDeclarationName(I))).forEach(y=>{const{updated:c,removed:I}=y.remove({ignoreUpstream:!1},e);t.push(...c),s.push(...I)}),e==null||e.attemptAutoclose("remove-extra-body-argument-declarations",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}createCurrentValueInputBasedOnInputMap(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"create-current-value-input-based-on-input-map"))){var y,c,I,E,O;const t=[],i=[],s=[],l=[];switch(this.declaration.id){case Q.List:{const P=this.body.inputs.find(G=>{var B;return((B=G.implements)==null?void 0:B.id)===k[n.Loop][Q.List].body.inputs.currentValue.id}),V=this.inputs.find(G=>{var B;return((B=G.declaration)==null?void 0:B.id)===k[n.Loop][Q.List].inputs.list.id});if(!V)break;const M=this.getCurrentValueBuiltInValueDescriptor();if(P){this.currentValueArgumentDeclaration=P;const G=this.project.get(k[n.Loop][Q.List].inputs.list.id);M&&(!P.implements||P.implements.id!==M.id)&&(P.setImplements(M,e),t.push(P));let $=P.getDataType(e);if(!$){const J={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,parentRelationType:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:G.toReference()},te=C(J,this.project);te.setParent(G,e),te.initChildren(e),e==null||e.add(te,A.Added),te.addSelfToProject(e),i.push(te),$=te}const Z=V.getDataType(e);$.merge(Z,e),$.metaSync({isList:!1},e)}else{const G={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:oe.CURRENT_VALUE_ARG_NAME,description:null,defaultValue:null,index:this.body.inputs.length,constant:!0,required:!0,implements:M,writesValues:[],dataType:null,parent:this.body.toReference()},B=C(G,this.project);B.initChildren(e),B.setParent(this.body,e),e==null||e.add(B,A.Added),B.addSelfToProject(e),M&&(!B.implements||B.implements.id!==M.id)&&(B.setImplements(M,e),t.push(B)),i.push(B),this.currentValueArgumentDeclaration=B}break}case Q.ManualFlow:{this.currentValueArgumentDeclaration=null;break}case Q.Counted:{this.currentValueArgumentDeclaration=null;break}case Q.ObjectKeys:{const P=this.body.inputs.find(G=>{var B;return((B=G.implements)==null?void 0:B.id)===k[n.Loop][Q.ObjectKeys].body.inputs.currentValue.id});if(!this.inputs.find(G=>{var B;return((B=G.declaration)==null?void 0:B.id)===k[n.Loop][Q.ObjectKeys].inputs.object.id}))break;const M=this.getCurrentValueBuiltInValueDescriptor();if(P){this.currentValueArgumentDeclaration=P;const G=this.project.get(k[n.Loop][Q.ObjectKeys].inputs.object.id);M&&(!P.implements||P.implements.id!==M.id)&&(P.setImplements(M),t.push(P));let $=P.getDataType(e);if($){const Z=this.project.getBuiltIn(k["primitive-entity"].string.id);((y=$.entity)==null?void 0:y.id)!==Z.id&&($.setEntity(Z),t.push($))}else{const Z={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,parentRelationType:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:G.toReference()},J=C(Z,this.project);J.setParent(G,e),J.initChildren(e),e==null||e.add(J,A.Added),J.addSelfToProject(e),$=J}}else{const G={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:oe.CURRENT_VALUE_ARG_NAME,description:null,defaultValue:null,index:this.body.inputs.length,constant:!0,required:!0,implements:M,writesValues:[],dataType:null,parent:this.body.toReference()},B=C(G,this.project);B.initChildren(e),B.setParent(this.body,e),e==null||e.add(B,A.Added),B.addSelfToProject(e),M&&(!B.implements||B.implements.id!==M.id)&&(B.setImplements(M,e),t.push(B)),i.push(B),this.currentValueArgumentDeclaration=B}break}case Q.ObjectValues:{const P=this.body.inputs.find(G=>{var B;return((B=G.implements)==null?void 0:B.id)===k[n.Loop][Q.ObjectValues].body.inputs.currentValue.id}),V=this.inputs.find(G=>{var B;return((B=G.declaration)==null?void 0:B.id)===k[n.Loop][Q.ObjectValues].inputs.object.id});if(!V)break;const M=this.getCurrentValueBuiltInValueDescriptor();if(P){this.currentValueArgumentDeclaration=P;const G=this.project.get(k[n.Loop][Q.ObjectValues].inputs.object.id);M&&(!P.implements||P.implements.id!==M.id)&&(P.setImplements(M,e),t.push(P));let $=P.getDataType(e);if($){const Z=V.getDataType(e),J=((I=Z==null?void 0:Z.entity)==null?void 0:I.properties)||[];(E=$.orChildrenGroup)==null||E.forEach(te=>{const{updated:fe,removed:Ie}=te.remove({ignoreUpstream:!1},e);t.push(...fe),s.push(...Ie)}),J.forEach(te=>{if(!te.getDataType(e)){const Ie={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parentRelationType:Dt.OrDataTypeGroup,parent:$.toReference()},X=C(Ie,this.project);X.setParent($,e),X.initChildren(e),e==null||e.add(X,A.Added),X.addSelfToProject(e),i.push(X)}})}else{const Z={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,parentRelationType:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:G.toReference()},J=C(Z,this.project);J.setParent(G,e),J.initChildren(e),e==null||e.add(J,A.Added),J.addSelfToProject(e),$=J;const te=V.getDataType(e);(((c=te==null?void 0:te.entity)==null?void 0:c.properties)||[]).forEach(Ie=>{if(!Ie.getDataType(e)){const le={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parentRelationType:Dt.OrDataTypeGroup,parent:J.toReference()},ei=C(le,this.project);ei.setParent(J,e),ei.initChildren(e),e==null||e.add(ei,A.Added),ei.addSelfToProject(e),i.push(ei)}})}}else{const G={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:oe.CURRENT_VALUE_ARG_NAME,description:null,constant:!0,defaultValue:null,index:this.body.inputs.length,required:!0,implements:M,writesValues:[],dataType:null,parent:this.body.toReference()},B=C(G,this.project);B.initChildren(e),B.setParent(this.body,e),e==null||e.add(B,A.Added),B.addSelfToProject(e),M&&(!B.implements||B.implements.id!==M.id)&&(B.setImplements(M,e),t.push(B)),i.push(B),this.currentValueArgumentDeclaration=B}break}case Q.String:{const P=this.body.inputs.find(G=>{var B;return((B=G.implements)==null?void 0:B.id)===k[n.Loop][Q.String].body.inputs.currentValue.id});if(!this.inputs.find(G=>{var B;return((B=G.declaration)==null?void 0:B.id)===k[n.Loop][Q.String].inputs.string.id}))break;const M=this.getCurrentValueBuiltInValueDescriptor();if(P){this.currentValueArgumentDeclaration=P;const G=this.project.get(k[n.Loop]["string-loop"].inputs.string.id);M&&(!P.implements||P.implements.id!==M.id)&&(P.setImplements(M,e),t.push(P));let $=P.getDataType(e);if($){const Z=this.project.getBuiltIn(k["primitive-entity"].string.id);((O=$.entity)==null?void 0:O.id)!==Z.id&&($.setEntity(Z),t.push($))}else{const Z={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:[],implementationChooseOne:!1,parentRelationType:null,isList:!1,entity:null,asType:!1,like:!1,inferred:!1,andChildrenGroup:[],orChildrenGroup:[],parent:G.toReference()},J=C(Z,this.project);J.setParent(G,e),J.initChildren(e),e==null||e.add(J,A.Added),J.addSelfToProject(e),i.push(J),$=J}}else{const G={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:oe.CURRENT_VALUE_ARG_NAME,description:null,index:this.body.inputs.length,required:!0,constant:!0,defaultValue:null,implements:M,writesValues:[],dataType:null,parent:this.body.toReference()},B=C(G,this.project);B.initChildren(e),B.setParent(this.body,e),e==null||e.add(B,A.Added),B.addSelfToProject(e),M&&(!B.implements||B.implements.id!==M.id)&&(B.setImplements(M,e),t.push(B)),i.push(B),this.currentValueArgumentDeclaration=B}break}}const{updated:o,added:d,removed:u}=this.removeExtraBodyArgumentDeclarations(e);return t.push(...o),i.push(...d),s.push(...u),e==null||e.attemptAutoclose("create-current-value-input-based-on-input-map",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncFixedBodyArgumentDeclarations(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-fixed-body-argument-declarations"))){const t=[],i=[],s=[],l=[],{updated:o,added:d,removed:u}=this.createCurrentIterationNumberArgumentDeclaration(e);t.push(...o),i.push(...d),s.push(...u);const{updated:y,added:c,removed:I}=this.createCurrentValueInputBasedOnInputMap(e);return t.push(...y),i.push(...c),s.push(...I),e==null||e.attemptAutoclose("sync-fixed-body-argument-declarations",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncInputMaps(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-input-maps"))){const t=[],i=[],s=[],l=[];switch(this.declaration.id){case Q.List:{let o=null;if(this.inputs.forEach(d=>{var u;((u=d.declaration)==null?void 0:u.id)===k[n.Loop]["list-loop"].inputs.list.id?o=d:(d.remove({ignoreUpstream:!1},e),s.push(d))}),o){if(o.declaration.id!==k[n.Loop]["list-loop"].inputs.list.id){const d=this.project.get(k[n.Loop]["list-loop"].inputs.list.id);o.setDeclaration(d),t.push(o)}}else{const d=this.project.get(k[n.Loop]["list-loop"].inputs.list.id),u={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:d.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},y=C(u,this.project);y.initChildren(e),y.setParent(this,e),e==null||e.add(y,A.Added),y.addSelfToProject(e),i.push(y)}break}case Q.ManualFlow:{this.inputs.forEach(o=>{o.remove({ignoreUpstream:!1},e),s.push(o)});break}case Q.Counted:{let o=null;if(this.inputs.forEach(d=>{var u;((u=d.declaration)==null?void 0:u.id)===k[n.Loop]["counted-loop"].inputs.number.id?o=d:(d.remove({ignoreUpstream:!1},e),s.push(d))}),o){if(o.declaration.id!==k[n.Loop]["counted-loop"].inputs.number.id){const d=this.project.get(k[n.Loop]["counted-loop"].inputs.number.id);o.setDeclaration(d),t.push(o)}}else{const d=this.project.get(k[n.Loop]["counted-loop"].inputs.number.id),u={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:d.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},y=C(u,this.project);y.initChildren(e),y.setParent(this,e),e==null||e.add(y,A.Added),y.addSelfToProject(e),i.push(y)}break}case Q.ObjectKeys:{let o=null;if(this.inputs.forEach(d=>{var u;((u=d.declaration)==null?void 0:u.id)===k[n.Loop]["object-keys-loop"].inputs.object.id?o=d:(d.remove({ignoreUpstream:!1},e),s.push(d))}),o){if(o.declaration.id!==k[n.Loop]["object-keys-loop"].inputs.object.id){const d=this.project.get(k[n.Loop]["object-keys-loop"].inputs.object.id);o.setDeclaration(d),t.push(o)}}else{const d=this.project.get(k[n.Loop]["object-keys-loop"].inputs.object.id),u={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:d.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},y=C(u,this.project);y.initChildren(e),y.setParent(this,e),e==null||e.add(y,A.Added),y.addSelfToProject(e),i.push(y)}break}case Q.ObjectValues:{let o=null;if(this.inputs.forEach(d=>{var u;((u=d.declaration)==null?void 0:u.id)===k[n.Loop]["object-values-loop"].inputs.object.id?o=d:(d.remove({ignoreUpstream:!1},e),s.push(d))}),o){if(o.declaration.id!==k[n.Loop]["object-values-loop"].inputs.object.id){const d=this.project.get(k[n.Loop]["object-values-loop"].inputs.object.id);o.setDeclaration(d),t.push(o)}}else{const d=this.project.get(k[n.Loop]["object-values-loop"].inputs.object.id),u={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:d.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},y=C(u,this.project);y.initChildren(e),y.setParent(this,e),e==null||e.add(y,A.Added),y.addSelfToProject(e),i.push(y)}break}case Q.String:{let o=null;if(this.inputs.forEach(d=>{var u;((u=d.declaration)==null?void 0:u.id)===k[n.Loop]["string-loop"].inputs.string.id?o=d:(d.remove({ignoreUpstream:!1},e),s.push(d))}),o){if(o.declaration.id!==k[n.Loop]["string-loop"].inputs.string.id){const d=this.project.get(k[n.Loop]["string-loop"].inputs.string.id);o.setDeclaration(d),t.push(o)}}else{const d=this.project.get(k[n.Loop]["string-loop"].inputs.string.id),u={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,name:null,description:null,index:0,declaration:d.toJSON(),readsValue:null,defaultValue:null,parent:this.toReference()},y=C(u,this.project);y.initChildren(e),y.setParent(this,e),e==null||e.add(y,A.Added),y.addSelfToProject(e),i.push(y)}break}}return e==null||e.attemptAutoclose("sync-input-maps",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}getCurrentValueBuiltInValueDescriptor(){var t;const e=(t=k[n.Loop][this.declaration.id].body.inputs.currentValue)==null?void 0:t.id;return e?this.project.get(e):null}getCurrentIterationNumberBuiltInValueDescriptor(){const e=k[n.Loop][this.declaration.id].body.inputs.iterationNumber.id;return this.project.get(e)}syncBody(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-body"))){var u;const t=[],i=[],s=[],l=[],o=k[n.Loop][this.declaration.id].body.id,d=this.project.getBuiltIn(o);if(this.body)((u=this.body.implements)==null?void 0:u.id)!==d.id&&(this.body.setImplements(d,e),this.body.setParent(this,e),t.push(this.body));else{const y={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.FunctionDeclaration,name:d.name,description:null,inputs:[],index:null,calls:[],collapsed:!1,private:!1,implements:d.toJSON(),x:0,y:0,parent:this.toReference()},c=C(y,this.project);c.initChildren(e),c.setParent(this,e),e==null||e.add(c,A.Added),c.addSelfToProject(e),i.push(c)}return e==null||e.attemptAutoclose("sync-body",this.id),{self:this,updated:p(t),added:p(i),removed:p(s),affected:p(l)}}syncChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-children"))){const t=[],i=[],s=[],l=[],{updated:o,added:d,removed:u}=this.syncBody(e);t.push(...o),i.push(...d),s.push(...u);const{updated:y,added:c,removed:I}=this.syncInputMaps(e);t.push(...y),i.push(...c),s.push(...I);const{updated:E,added:O,removed:P}=this.syncTerminationStatements(e);t.push(...E),i.push(...O),s.push(...P);const{updated:V,added:M,removed:G}=this.syncBodyArgumentsDeclarations(e);t.push(...V),i.push(...M),s.push(...G);const{updated:B,added:$,removed:Z}=this.syncBodyInputIndexes(e);t.push(...B),i.push(...$),s.push(...Z);const{updated:J,added:te,removed:fe}=this.syncOutputsDeclarations(e);t.push(...J),i.push(...te),s.push(...fe);const{updated:Ie,added:X,removed:le}=this.syncOutputMaps(e);return t.push(...Ie),i.push(...X),s.push(...le),e==null||e.attemptAutoclose("sync-children",this.id),{self:this,updated:p(t),added:p(i),removed:p(s),affected:p(l)}}};f(oe,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(oe,"type",n.Loop),f(oe,"USER_MANAGED_PARENT_TYPES",[...dt,n.Project]),f(oe,"PARENT_TYPES",[...Je.USER_MANAGED_PARENT_TYPES]),f(oe,"CURRENT_ITERATION_NUMBER_ARG_NAME","Current iteration number"),f(oe,"CURRENT_VALUE_ARG_NAME","Current value"),f(oe,"MUTABLE_BASE_PROPERTIES",[]),f(oe,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(oe,"BASE_PROPERTIES",[...oe.MUTABLE_BASE_PROPERTIES,...oe.INMUTABLE_BASE_PROPERTIES]),f(oe,"MUTABLE_META_PROPERTIES",[...oe.MUTABLE_BASE_PROPERTIES,"x","y"]),f(oe,"INMUTABLE_META_PROPERTIES",[...oe.INMUTABLE_BASE_PROPERTIES]),f(oe,"META_PROPERTIES",[...oe.MUTABLE_META_PROPERTIES,...oe.INMUTABLE_META_PROPERTIES]),f(oe,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),f(oe,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),f(oe,"UPSTREAM_PROPERTIES",[...oe.MUTABLE_UPSTREAM_PROPERTIES,...oe.INMUTABLE_UPSTREAM_PROPERTIES]),f(oe,"MUTABLE_DOWNSTREAM_PROPERTIES",["body","inputs","outputs","outputsDeclarations","successCalls","errorCalls","error","breakStatements","continueStatements"]),f(oe,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(oe,"DOWNSTREAM_PROPERTIES",[...oe.MUTABLE_DOWNSTREAM_PROPERTIES,...oe.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(oe,"PROPERTIES",[...oe.META_PROPERTIES,...oe.UPSTREAM_PROPERTIES,...oe.DOWNSTREAM_PROPERTIES]);let kr=oe;function m1(r){const a=B5(),e=r.toJSON();a.safeParse(e).success,r.inputs.forEach(l=>l.validate());const s=[...vr(r)];return He(r.errors,s)}const M7=Object.freeze(Object.defineProperty({__proto__:null,validate:m1},Symbol.toStringTag,{value:"Module"}));var v1=(r=>(r.Parent="parent",r))(v1||{});const ke=class ke extends at{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"x");f(this,"y");f(this,"type",n.Condition);f(this,"successCalls",[]);f(this,"errorCalls",[]);f(this,"declaration");f(this,"inputs",[]);f(this,"calledBySuccess",[]);f(this,"calledByError",[]);f(this,"calledByEntry",[]);f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static new(){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Condition,declaration:null,inputs:[],parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],errorCalls:[],successCalls:[],x:0,y:0}}static fromGenerationTarget(e,t){let i=t;if(e.parent){const c=_(e.parent);i=t.get(c)}const s=e.calledByEntry.map(c=>{const I=_(c);return t.get(I)}),l=e.calledBySuccess.map(c=>{const I=_(c);return t.get(I)}),o=e.calledByError.map(c=>{const I=_(c);return t.get(I)});let d;if(e.declaration){const c=_(e.declaration);d=t.get(c)}const u={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Condition,declaration:d,calledByEntry:s,calledBySuccess:l,calledByError:o,errorCalls:[],successCalls:[],inputs:[],x:0,y:0,parent:i},y=C(u,t);return y.setParent(i,null),y.initChildren(null),y}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=At(i,{parent:{list:!1,types:[...dt,n.Project],optional:!0}},t);return i=l.modifiedData,s.push(...l.errors,...ut(i)),e.declaration?t.get(e.declaration)?t.conditionDeclarations.find(u=>u.id===e.declaration)||s.push(new w({id:`${e.id}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:D.Error,message:`Entity of type '${e.type}' with id '${e.id}' has an 'declaration' property that isn't pointing to an action descriptor reserved for '${n.Condition}' entities.
100
100
  ${Zl(t)}`,issue:null})):s.push(new w({id:`${e.id}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:D.Error,message:`Entity of type '${e.type}' with id '${e.id}' has an 'declaration' property that isn't found in the project. The 'declaration' property must point to one of the built-in action descriptors reserved for '${n.Condition}' entities.
101
101
  ${Zl(t)}`,issue:null})):s.push(new w({id:`${e.id}--${j.InvalidObjectStructure}`,code:j.InvalidObjectStructure,severity:D.Error,message:`Entity of type '${e.type}' with id '${e.id}' is missing the 'declaration' property. This property is required for a '${e.type}' entity and must point to one of the built-in action descriptors reserved for '${n.Condition}' entities.
102
102
  ${Zl(t)}`,issue:null})),{errors:s,modifiedData:i}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
103
- If an entity is called by another, they must be in the same scope, which means they have the same parent.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],i=[],s=[];return Object.values(this.detachedDependents).forEach(l=>{const o=l.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),i.push(...o.removed),s.push(...o.affected)}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new ke(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.declaration=this.declaration,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[I,E]of c.knownVersions)u.set(I,E);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new ke(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.declaration=o.declaration,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${xt(this.type)} with id '${this.id}' has a parent reference "${l}" which is missing in the project`)}else throw new Error(`${xt(this.type)} with id '${this.id}' is missing a parent reference`);if(this.initialData.declaration){const l=_(this.initialData.declaration),o=this.project.get(l);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];this.initialized=!0,this.captureVersion();const{updated:o,added:d,removed:u}=this.syncMissingFixedInputs(e);return t.push(...o),i.push(...d),s.push(...u),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.parent===this.project&&this.project.addCondition(this),this.successCalls.forEach(o=>{o.addSuccessCaller(this,e),t.push(o)}),this.errorCalls.forEach(o=>{o.addErrorCaller(this,e),t.push(o)}),this.calledByEntry.forEach(o=>{o.addCall(this,e),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this,e),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this,e),t.push(o)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-input"))){const i=this.inputs.findIndex(s=>s.id===e.id);return i>-1&&(this.inputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-input",this.id),this}addInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-input"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input",this.id),this):(this.inputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-input",this.id),this)}addOutput(e){return this}removeOutput(e){return this}addSuccessCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,A.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,A.Updated),i&&K(this,t),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,A.Updated),i&&K(this,t),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}addErrorCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-call")),i=!1){return this.errorCalls.find(s=>s.id===e.id)||(this.errorCalls.push(e),i&&K(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-call")),i=!1){return this.successCalls.find(s=>s.id===e.id)||(this.successCalls.push(e),i&&K(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-success-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-call")),i=!1){const s=this.successCalls.findIndex(o=>o.id===e.id);s>-1&&(this.successCalls.splice(s,1),t==null||t.add(this,A.Affected));const l=this.errorCalls.findIndex(o=>o.id===e.id);return l>-1&&(this.errorCalls.splice(l,1),t==null||t.add(this,A.Affected)),i&&K(this,t),t==null||t.attemptAutoclose("remove-call",this.id),this}removeCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected)),!0):!1),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected)),!0):!1),i&&K(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setDeclaration(e){return this.declaration=e,this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.declaration=C(this.initialData.declaration,this.project),this.successCalls=this.initialData.successCalls.map(t=>{const i=C(t,this.project);return i.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type)?(i.setParent(this.parent.parent,null),i.initChildren(e)):i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e)),i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=C(t,this.project);return i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type)?(i.setParent(this.parent.parent,null),i.initChildren(e)):i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e)),i}),this.inputs=this.initialData.inputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=g,...t){return await ke.repository.APILoad(this.id,...t),this}async APICreate(e=g,...t){return await ke.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=g,...t){return await ke.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=g,...t){return await ke.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=g,...t){return await ke.repository.APIClone(this.id,...t),this}async APILoadVersion(e=g,t,...i){return await ke.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];return t!=null&&t.hasRemoved(this.id)?(t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:y,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...y),l.push(...c)}),this.inputs.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.successCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),this.errorCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),e||this.calledBy.forEach(d=>{i.push(d),d.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this})}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.inputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.successCalls.forEach(o=>{i.push(o),o.addSuccessCaller(this,e)}),this.errorCalls.forEach(o=>{i.push(o),o.addErrorCaller(this,e)}),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.inputs.flatMap(i=>i.toFlat(e)),...this.successCalls.flatMap(i=>i.toFlat(e)),...this.errorCalls.flatMap(i=>i.toFlat(e)),...this.calledBy.flatMap(i=>i.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.inputs.flatMap(i=>i.toFlatIds(e)),...this.successCalls.flatMap(i=>i.toFlatIds(e)),...this.errorCalls.flatMap(i=>i.toFlatIds(e)),...this.calledBy.flatMap(i=>i.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(e=new Set){return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,declaration:this.declaration.toJSON(e),successCalls:this.successCalls.map(t=>t.toJSON(e)),errorCalls:this.errorCalls.map(t=>t.toJSON(e)),calledBySuccess:this.calledBySuccess.map(t=>t.toReference()),calledByError:this.calledByError.map(t=>t.toReference()),calledByEntry:this.calledByEntry.map(t=>t.toReference()),inputs:this.inputs.map(t=>t.toJSON(e)),parent:this.parent.toReference()})}toJSONClone(e=q){var i,s,l,o,d;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,declaration:this.declaration.toJSON(),successCalls:this.successCalls.map(u=>u.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(u=>u.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(u=>u.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(u=>u.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(u=>u.toReference({seenEntityMaps:e.seenEntityMaps})),inputs:this.inputs.map(u=>u.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,declaration:this.declaration.toReference(e),inputs:this.inputs.map(s=>s.toReference(e)),successCalls:this.successCalls.map(s=>s.toReference(e)),errorCalls:this.errorCalls.map(s=>s.toReference(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference(e)),calledByError:this.calledByError.map(s=>s.toReference(e)),calledByEntry:this.calledByEntry.map(s=>s.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.inputs.flatMap(i=>i.toFlatJSON(e)),...this.successCalls.flatMap(i=>i.toFlatJSON(e)),...this.errorCalls.flatMap(i=>i.toFlatJSON(e)),...this.calledBy.flatMap(i=>i.toFlatJSON(e))])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,type:this.type,declaration:this.declaration.id,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),parent:e}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.inputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.successCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(i=>i.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.inputs.forEach(e=>e.clearErrors()),this.successCalls.forEach(e=>e.clearErrors()),this.errorCalls.forEach(e=>e.clearErrors()),this}validate(){const e=m1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.inputs.flatMap(t=>t.getErrors())]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var E;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[];const u=d.split("-id"),y=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=ct(o,l);t?c.setParent(t,null):c.setParent(this.parent,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,A.Added);const I=(E=this.inputs)==null?void 0:E.map((O,P)=>O.clone(e,c,y+"-input-map-"+P+"-id",s));return c.inputs=I,e==null||e.attemptAutoclose("clone-entity",this.id),c}removeUnrecognizedInputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-unrecognized-inputs"))){const t=[],i=[],s=[],l=[];return this.inputs.forEach(o=>{if(!this.declaration.inputs.find(u=>{var y;return u.id===((y=o.declaration)==null?void 0:y.id)})){const u=o.remove({ignoreUpstream:!0},e);s.push(...u.removed),t.push(...u.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncMissingFixedInputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const t=[],i=[],s=[],l=[],o=this.declaration.inputs.filter(c=>c.parentRelationType===N.FixedArguments&&!this.inputs.find(I=>I.declaration.id===c.id));this.inputs.sort((c,I)=>c.index-I.index),o.forEach(c=>{this.inputs.forEach(O=>{O.index>=c.index&&O.metaSync({index:O.index+1})});const I={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,declaration:c.toJSON(),readsValue:null,defaultValue:null,index:c.index,name:null,description:null,parent:this.toReference()},E=C(I,this.project);E.setParent(this,e),E.initChildren(e),e==null||e.add(E,A.Added),E.addSelfToProject(e)}),this.inputs.sort((c,I)=>c.index-I.index);const{updated:d,added:u,removed:y}=this.removeUnrecognizedInputs(e);return t.push(...d),i.push(...u),s.push(...y),e==null||e.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}};f(ke,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(ke,"type",n.Condition),f(ke,"USER_MANAGED_PARENT_TYPES",[...dt,n.Project]),f(ke,"PARENT_TYPES",[...ke.USER_MANAGED_PARENT_TYPES]),f(ke,"MUTABLE_BASE_PROPERTIES",["operator"]),f(ke,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(ke,"BASE_PROPERTIES",[...ke.MUTABLE_BASE_PROPERTIES,...ke.INMUTABLE_BASE_PROPERTIES]),f(ke,"MUTABLE_META_PROPERTIES",["x","y"]),f(ke,"INMUTABLE_META_PROPERTIES",[...ke.INMUTABLE_BASE_PROPERTIES]),f(ke,"META_PROPERTIES",[...ke.MUTABLE_META_PROPERTIES,...ke.INMUTABLE_META_PROPERTIES]),f(ke,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","parent"]),f(ke,"INMUTABLE_UPSTREAM_PROPERTIES",[]),f(ke,"UPSTREAM_PROPERTIES",[...ke.MUTABLE_UPSTREAM_PROPERTIES,...ke.INMUTABLE_UPSTREAM_PROPERTIES]),f(ke,"MUTABLE_DOWNSTREAM_PROPERTIES",["successCalls","errorCalls","inputsDeclarations","inputs"]),f(ke,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(ke,"DOWNSTREAM_PROPERTIES",[...ke.MUTABLE_DOWNSTREAM_PROPERTIES,...ke.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(ke,"PROPERTIES",[...ke.META_PROPERTIES,...ke.UPSTREAM_PROPERTIES,...ke.DOWNSTREAM_PROPERTIES]);let Sr=ke;function T1(r){var o;const a=hS(),e=r.toJSON();a.safeParse(e).success,(o=r.dataType)==null||o.validate(),r.inputs.forEach(d=>d.validate()),r.outputs.forEach(d=>d.validate()),r.internalCalls.forEach(d=>d.validate());const s=[...vr(r)];if(r.id==="random-company-employee-test-variable-id"){const d=de({id:`${r.id}--${F.PropertyImplementsNonAbstact}`,message:`Property "${x(r,r.project)}" with id "${r.id}" implements a non-abstract property "${x(r,r.project)}" with id "${r.id}".`,issue:null,severity:D.Error,code:F.PropertyImplementsNonAbstact,entity:r});s.push(d.error)}if(r.id==="company-dto-variable-one-id"){const d=de({id:`${r.id}--${F.PropertyImplementsNonAbstact}`,message:`Property "${x(r,r.project)}" with id "${r.id}" implements a non-abstract property "${x(r,r.project)}" with id "${r.id}".`,issue:null,severity:D.Error,code:F.PropertyImplementsNonAbstact,entity:r});s.push(d.error)}const l=xc(r);return s.push(...l),He(r.errors,s)}const Nq=Object.freeze(Object.defineProperty({__proto__:null,validate:T1},Symbol.toStringTag,{value:"Module"}));function I1(r){const a=ES(),e=r.toJSON();a.safeParse(e).success,r.inputs.forEach(o=>o.validate()),r.outputs.forEach(o=>o.validate()),r.internalCalls.forEach(o=>o.validate());const s=[...vr(r)];if(r.id==="exec-sequentially-result-variable-id"){const o=de({id:`${r.id}--${F.PropertyImplementsNonAbstact}`,message:`Property "${x(r,r.project)}" with id "${r.id}" implements a non-abstract property "${x(r,r.project)}" with id "${r.id}".`,issue:null,severity:D.Error,code:F.PropertyImplementsNonAbstact,entity:r});s.push(o.error)}const l=xc(r);return s.push(...l),He(r.errors,s)}const Lq=Object.freeze(Object.defineProperty({__proto__:null,validate:I1},Symbol.toStringTag,{value:"Module"}));var _c=(r=>(r.Parent="parent",r.DataTypeEntity="data-type-entity",r.VarDeclaration="var-declaration",r))(_c||{});const Ce=class Ce extends at{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"x");f(this,"y");f(this,"type",n.VariableInstance);f(this,"defaultValue",null);f(this,"writesValues",[]);f(this,"readsValue",null);f(this,"declaration");f(this,"inputs",[]);f(this,"outputs",[]);f(this,"calledBySuccess",[]);f(this,"calledByError",[]);f(this,"calledByEntry",[]);f(this,"successCalls",[]);f(this,"errorCalls",[]);f(this,"internalCalls",[]);f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static new(){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.VariableInstance,declaration:null,internalCalls:[],successCalls:[],errorCalls:[],readsValue:null,writesValues:[],defaultValue:null,inputs:[],outputs:[],parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],x:0,y:0}}static fromGenerationTarget(e,t){let i=t;if(e.parent){const E=_(e.parent);i=t.get(E)}const s=_(e.declaration),l=t.get(s),o=e.calledByEntry.map(E=>{const O=_(E);return t.get(O)}),d=e.calledBySuccess.map(E=>{const O=_(E);return t.get(O)}),u=e.calledByError.map(E=>{const O=_(E);return t.get(O)});let y=null;if(e.readsValue){const E=_(e.readsValue);y=t.get(E)}const c={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.VariableInstance,declaration:l.toReference(),calledByEntry:o,calledBySuccess:d,calledByError:u,defaultValue:null,errorCalls:[],successCalls:[],internalCalls:[],readsValue:y,inputs:[],outputs:[],writesValues:[],x:0,y:0,parent:i},I=C(c,t);return I.setParent(i,null),I.initChildren(null),I}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=At(i,{parent:{list:!1,types:[...dt,n.Project],optional:!0},declaration:{list:!1,types:[n.VariableDeclaration]}},t);return i=l.modifiedData,s.push(...l.errors,...ut(i)),{errors:s,modifiedData:i}}validateGeneratedUpdate(e){const t=[];let i=JSON.parse(JSON.stringify(e));const s=_a(i,this);return i=s.modifiedData,t.push(...s.errors),e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
103
+ If an entity is called by another, they must be in the same scope, which means they have the same parent.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],i=[],s=[];return Object.values(this.detachedDependents).forEach(l=>{const o=l.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),i.push(...o.removed),s.push(...o.affected)}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new ke(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.declaration=this.declaration,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[I,E]of c.knownVersions)u.set(I,E);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new ke(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.declaration=o.declaration,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${xt(this.type)} with id '${this.id}' has a parent reference "${l}" which is missing in the project`)}else throw new Error(`${xt(this.type)} with id '${this.id}' is missing a parent reference`);if(this.initialData.declaration){const l=_(this.initialData.declaration),o=this.project.get(l);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];this.initialized=!0,this.captureVersion();const{updated:o,added:d,removed:u}=this.syncMissingFixedInputs(e);return t.push(...o),i.push(...d),s.push(...u),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.parent===this.project&&this.project.addCondition(this),this.successCalls.forEach(o=>{o.addSuccessCaller(this,e),t.push(o)}),this.errorCalls.forEach(o=>{o.addErrorCaller(this,e),t.push(o)}),this.calledByEntry.forEach(o=>{o.addCall(this,e),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this,e),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this,e),t.push(o)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-input"))){const i=this.inputs.findIndex(s=>s.id===e.id);return i>-1&&(this.inputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-input",this.id),this}addInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-input"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input",this.id),this):(this.inputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-input",this.id),this)}addOutput(e){return this}removeOutput(e){return this}addSuccessCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,A.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,A.Updated),i&&K(this,t),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,A.Updated),i&&K(this,t),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}addErrorCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-call")),i=!1){return this.errorCalls.find(s=>s.id===e.id)||(this.errorCalls.push(e),i&&K(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-call")),i=!1){return this.successCalls.find(s=>s.id===e.id)||(this.successCalls.push(e),i&&K(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-success-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-call")),i=!1){const s=this.successCalls.findIndex(o=>o.id===e.id);s>-1&&(this.successCalls.splice(s,1),t==null||t.add(this,A.Affected));const l=this.errorCalls.findIndex(o=>o.id===e.id);return l>-1&&(this.errorCalls.splice(l,1),t==null||t.add(this,A.Affected)),i&&K(this,t),t==null||t.attemptAutoclose("remove-call",this.id),this}removeCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected)),!0):!1),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected)),!0):!1),i&&K(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setDeclaration(e){return this.declaration=e,this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.declaration=C(this.initialData.declaration,this.project),this.successCalls=this.initialData.successCalls.map(t=>{const i=C(t,this.project);return i.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type)?(i.setParent(this.parent.parent,null),i.initChildren(e)):i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e)),i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=C(t,this.project);return i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type)?(i.setParent(this.parent.parent,null),i.initChildren(e)):i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e)),i}),this.inputs=this.initialData.inputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=g,...t){return await ke.repository.APILoad(this.id,...t),this}async APICreate(e=g,...t){return await ke.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=g,...t){return await ke.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=g,...t){return await ke.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=g,...t){return await ke.repository.APIClone(this.id,...t),this}async APILoadVersion(e=g,t,...i){return await ke.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];return t!=null&&t.hasRemoved(this.id)?(t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:y,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...y),l.push(...c)}),this.inputs.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.successCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),this.errorCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),e||this.calledBy.forEach(d=>{i.push(d),d.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this})}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.inputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.successCalls.forEach(o=>{i.push(o),o.addSuccessCaller(this,e)}),this.errorCalls.forEach(o=>{i.push(o),o.addErrorCaller(this,e)}),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.inputs.flatMap(i=>i.toFlat(e)),...this.successCalls.flatMap(i=>i.toFlat(e)),...this.errorCalls.flatMap(i=>i.toFlat(e)),...this.calledBy.flatMap(i=>i.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.inputs.flatMap(i=>i.toFlatIds(e)),...this.successCalls.flatMap(i=>i.toFlatIds(e)),...this.errorCalls.flatMap(i=>i.toFlatIds(e)),...this.calledBy.flatMap(i=>i.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(e=new Set){return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,declaration:this.declaration.toJSON(e),successCalls:this.successCalls.map(t=>t.toJSON(e)),errorCalls:this.errorCalls.map(t=>t.toJSON(e)),calledBySuccess:this.calledBySuccess.map(t=>t.toReference()),calledByError:this.calledByError.map(t=>t.toReference()),calledByEntry:this.calledByEntry.map(t=>t.toReference()),inputs:this.inputs.map(t=>t.toJSON(e)),parent:this.parent.toReference()})}toJSONClone(e=q){var i,s,l,o,d;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,declaration:this.declaration.toJSON(),successCalls:this.successCalls.map(u=>u.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(u=>u.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(u=>u.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(u=>u.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(u=>u.toReference({seenEntityMaps:e.seenEntityMaps})),inputs:this.inputs.map(u=>u.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,declaration:this.declaration.toReference(e),inputs:this.inputs.map(s=>s.toReference(e)),successCalls:this.successCalls.map(s=>s.toReference(e)),errorCalls:this.errorCalls.map(s=>s.toReference(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference(e)),calledByError:this.calledByError.map(s=>s.toReference(e)),calledByEntry:this.calledByEntry.map(s=>s.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.inputs.flatMap(i=>i.toFlatJSON(e)),...this.successCalls.flatMap(i=>i.toFlatJSON(e)),...this.errorCalls.flatMap(i=>i.toFlatJSON(e)),...this.calledBy.flatMap(i=>i.toFlatJSON(e))])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,type:this.type,declaration:this.declaration.id,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),parent:e}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.inputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.successCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(i=>i.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.inputs.forEach(e=>e.clearErrors()),this.successCalls.forEach(e=>e.clearErrors()),this.errorCalls.forEach(e=>e.clearErrors()),this}validate(){const e=m1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.inputs.flatMap(t=>t.getErrors())]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var E;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[];const u=d.split("-id"),y=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=ct(o,l);t?c.setParent(t,null):c.setParent(this.parent,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,A.Added);const I=(E=this.inputs)==null?void 0:E.map((O,P)=>O.clone(e,c,y+"-input-map-"+P+"-id",s));return c.inputs=I,e==null||e.attemptAutoclose("clone-entity",this.id),c}removeUnrecognizedInputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-unrecognized-inputs"))){const t=[],i=[],s=[],l=[];return this.inputs.forEach(o=>{if(!this.declaration.inputs.find(u=>{var y;return u.id===((y=o.declaration)==null?void 0:y.id)})){const u=o.remove({ignoreUpstream:!0},e);s.push(...u.removed),t.push(...u.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncMissingFixedInputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const t=[],i=[],s=[],l=[],o=this.declaration.inputs.filter(c=>c.parentRelationType===N.FixedArguments&&!this.inputs.find(I=>I.declaration.id===c.id));this.inputs.sort((c,I)=>c.index-I.index),o.forEach(c=>{this.inputs.forEach(O=>{O.index>=c.index&&O.metaSync({index:O.index+1})});const I={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,declaration:c.toJSON(),readsValue:null,defaultValue:null,index:c.index,name:null,description:null,parent:this.toReference()},E=C(I,this.project);E.setParent(this,e),E.initChildren(e),e==null||e.add(E,A.Added),E.addSelfToProject(e)}),this.inputs.sort((c,I)=>c.index-I.index);const{updated:d,added:u,removed:y}=this.removeUnrecognizedInputs(e);return t.push(...d),i.push(...u),s.push(...y),e==null||e.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}};f(ke,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(ke,"type",n.Condition),f(ke,"USER_MANAGED_PARENT_TYPES",[...dt,n.Project]),f(ke,"PARENT_TYPES",[...ke.USER_MANAGED_PARENT_TYPES]),f(ke,"MUTABLE_BASE_PROPERTIES",["operator"]),f(ke,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(ke,"BASE_PROPERTIES",[...ke.MUTABLE_BASE_PROPERTIES,...ke.INMUTABLE_BASE_PROPERTIES]),f(ke,"MUTABLE_META_PROPERTIES",["x","y"]),f(ke,"INMUTABLE_META_PROPERTIES",[...ke.INMUTABLE_BASE_PROPERTIES]),f(ke,"META_PROPERTIES",[...ke.MUTABLE_META_PROPERTIES,...ke.INMUTABLE_META_PROPERTIES]),f(ke,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","parent"]),f(ke,"INMUTABLE_UPSTREAM_PROPERTIES",[]),f(ke,"UPSTREAM_PROPERTIES",[...ke.MUTABLE_UPSTREAM_PROPERTIES,...ke.INMUTABLE_UPSTREAM_PROPERTIES]),f(ke,"MUTABLE_DOWNSTREAM_PROPERTIES",["successCalls","errorCalls","inputsDeclarations","inputs"]),f(ke,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(ke,"DOWNSTREAM_PROPERTIES",[...ke.MUTABLE_DOWNSTREAM_PROPERTIES,...ke.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(ke,"PROPERTIES",[...ke.META_PROPERTIES,...ke.UPSTREAM_PROPERTIES,...ke.DOWNSTREAM_PROPERTIES]);let Sr=ke;function T1(r){var o;const a=hS(),e=r.toJSON();a.safeParse(e).success,(o=r.dataType)==null||o.validate(),r.inputs.forEach(d=>d.validate()),r.outputs.forEach(d=>d.validate()),r.internalCalls.forEach(d=>d.validate());const s=[...vr(r)];if(r.id==="random-company-employee-test-variable-id"){const d=de({id:`${r.id}--${F.PropertyImplementsNonAbstact}`,message:`Property "${x(r,r.project)}" with id "${r.id}" implements a non-abstract property "${x(r,r.project)}" with id "${r.id}".`,issue:null,severity:D.Error,code:F.PropertyImplementsNonAbstact,entity:r});s.push(d.error)}if(r.id==="company-dto-variable-one-id"){const d=de({id:`${r.id}--${F.PropertyImplementsNonAbstact}`,message:`Property "${x(r,r.project)}" with id "${r.id}" implements a non-abstract property "${x(r,r.project)}" with id "${r.id}".`,issue:null,severity:D.Error,code:F.PropertyImplementsNonAbstact,entity:r});s.push(d.error)}const l=xc(r);return s.push(...l),He(r.errors,s)}const N7=Object.freeze(Object.defineProperty({__proto__:null,validate:T1},Symbol.toStringTag,{value:"Module"}));function I1(r){const a=ES(),e=r.toJSON();a.safeParse(e).success,r.inputs.forEach(o=>o.validate()),r.outputs.forEach(o=>o.validate()),r.internalCalls.forEach(o=>o.validate());const s=[...vr(r)];if(r.id==="exec-sequentially-result-variable-id"){const o=de({id:`${r.id}--${F.PropertyImplementsNonAbstact}`,message:`Property "${x(r,r.project)}" with id "${r.id}" implements a non-abstract property "${x(r,r.project)}" with id "${r.id}".`,issue:null,severity:D.Error,code:F.PropertyImplementsNonAbstact,entity:r});s.push(o.error)}const l=xc(r);return s.push(...l),He(r.errors,s)}const L7=Object.freeze(Object.defineProperty({__proto__:null,validate:I1},Symbol.toStringTag,{value:"Module"}));var _c=(r=>(r.Parent="parent",r.DataTypeEntity="data-type-entity",r.VarDeclaration="var-declaration",r))(_c||{});const Ce=class Ce extends at{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"x");f(this,"y");f(this,"type",n.VariableInstance);f(this,"defaultValue",null);f(this,"writesValues",[]);f(this,"readsValue",null);f(this,"declaration");f(this,"inputs",[]);f(this,"outputs",[]);f(this,"calledBySuccess",[]);f(this,"calledByError",[]);f(this,"calledByEntry",[]);f(this,"successCalls",[]);f(this,"errorCalls",[]);f(this,"internalCalls",[]);f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y}static new(){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.VariableInstance,declaration:null,internalCalls:[],successCalls:[],errorCalls:[],readsValue:null,writesValues:[],defaultValue:null,inputs:[],outputs:[],parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],x:0,y:0}}static fromGenerationTarget(e,t){let i=t;if(e.parent){const E=_(e.parent);i=t.get(E)}const s=_(e.declaration),l=t.get(s),o=e.calledByEntry.map(E=>{const O=_(E);return t.get(O)}),d=e.calledBySuccess.map(E=>{const O=_(E);return t.get(O)}),u=e.calledByError.map(E=>{const O=_(E);return t.get(O)});let y=null;if(e.readsValue){const E=_(e.readsValue);y=t.get(E)}const c={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.VariableInstance,declaration:l.toReference(),calledByEntry:o,calledBySuccess:d,calledByError:u,defaultValue:null,errorCalls:[],successCalls:[],internalCalls:[],readsValue:y,inputs:[],outputs:[],writesValues:[],x:0,y:0,parent:i},I=C(c,t);return I.setParent(i,null),I.initChildren(null),I}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=At(i,{parent:{list:!1,types:[...dt,n.Project],optional:!0},declaration:{list:!1,types:[n.VariableDeclaration]}},t);return i=l.modifiedData,s.push(...l.errors,...ut(i)),{errors:s,modifiedData:i}}validateGeneratedUpdate(e){const t=[];let i=JSON.parse(JSON.stringify(e));const s=_a(i,this);return i=s.modifiedData,t.push(...s.errors),e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
104
104
  If an entity is called by another, they must be in the same scope, which means they have the same parent.
105
105
  Specifically for variables, their scope is also calculated from their value readers and value writters.
106
106
  You shouldn't have to manually update a 'parent' property. The equivalent result is to change its value readers, value writters, or callers.`,issue:null})),{errors:t,modifiedData:i}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],i=[],s=[];return Object.values(this.detachedDependents).forEach(l=>{const o=l.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),i.push(...o.removed),s.push(...o.affected)}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}if(t==="var-declaration"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}if(t==="var-declaration"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e,t,i,s;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),(s=(i=(t=this.declaration.dataType)==null?void 0:t.entity)==null?void 0:i.subscribeDependents)==null||s.call(i,[{entity:this,field:"data-type-entity"}]),this.declaration.subscribeDependents([{entity:this,field:"var-declaration"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ce(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.outputs=this.outputs,e.internalCalls=this.internalCalls,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.writesValues=this.writesValues,e.readsValue=this.readsValue,e.defaultValue=this.defaultValue,e.declaration=this.declaration,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[I,E]of c.knownVersions)u.set(I,E);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ce(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.internalCalls=o.internalCalls,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.writesValues=o.writesValues,this.readsValue=o.readsValue,this.defaultValue=o.defaultValue,this.declaration=o.declaration,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.readsValue){const l=_(this.initialData.readsValue),o=this.project.get(l);o&&(this.setValueWriter(o,null),e.push(o))}if(this.initialData.declaration){const l=_(this.initialData.declaration),o=this.project.get(l);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),e.push(d))}),Ir.hydrateReadsValue(this),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){var B;const t=[],i=[],s=[],l=[];this.initialized=!0,this.captureVersion();const{added:o,updated:d,removed:u,affected:y}=this.generateUnusedInputs(e);i.push(...o),t.push(...d),s.push(...u),l.push(...y);const{added:c,updated:I,removed:E,affected:O}=this.generateUnusedOutputs(e);i.push(...c),t.push(...I),s.push(...E),l.push(...O);const{added:P,updated:V,removed:M,affected:G}=this.generateUnusedInternalCalls(e);if(i.push(...P),t.push(...V),s.push(...M),l.push(...G),!this.declaration.dataType||(B=this.declaration.dataType)!=null&&B.inferred){const{added:$,updated:Z,removed:J,affected:te}=this.declaration.inferDataTypeAndSyncInstancesInputsAndOutputs(e);i.push(...$),t.push(...Z),s.push(...J),l.push(...te)}return e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.parent===this.project&&this.project.addVariableInstance(this),this.readsValue&&(this.readsValue.addValueReader(this,e),t.push(this.readsValue)),this.writesValues.forEach(o=>{o.setValueWriter(this,e),t.push(o)}),this.successCalls.forEach(o=>{o.addSuccessCaller(this,e),t.push(o)}),this.errorCalls.forEach(o=>{o.addErrorCaller(this,e),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this,e),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this,e),t.push(o)}),this.calledByEntry.forEach(o=>{o.addCall(this,e),t.push(o)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}get usedInputs(){return this.inputs.filter(e=>e.readsValue||e.defaultValue)}get unusedInputs(){return this.inputs.filter(e=>!e.readsValue&&!e.defaultValue)}get usedOutputs(){return this.outputs.filter(e=>e.writesValues.length)}get unusedOutputs(){return this.outputs.filter(e=>!e.writesValues.length)}get usedInternalCalls(){return this.internalCalls.filter(e=>!!e.calledBy.length)}get unusedInternalCalls(){const e=this.usedInternalCalls;return this.internalCalls.filter(i=>!(e.find(o=>o.id===i.id)||e.find(o=>o.declaration===i.declaration)))}removeInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-input"))){const i=this.inputs.findIndex(s=>s.id===e.id);return i>-1&&(this.inputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-input",this.id),this}addInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-input"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input",this.id),this):(this.inputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-input",this.id),this)}addOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-output"))){return this.outputs.includes(e)?(t==null||t.attemptAutoclose("add-output",this.id),this):(this.outputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-output",this.id),this)}removeOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-output"))){const i=this.outputs.findIndex(s=>s.id===e.id);return i>-1&&(this.outputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-output",this.id),this}addSuccessCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,A.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,A.Updated),i&&K(this,t),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,A.Updated),i&&K(this,t),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}addErrorCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-call")),i=!1){return this.errorCalls.find(s=>s.id===e.id)||(this.errorCalls.push(e),i&&K(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-call")),i=!1){return this.successCalls.find(s=>s.id===e.id)||(this.successCalls.push(e),i&&K(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-success-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-call")),i=!1){const s=this.successCalls.findIndex(o=>o.id===e.id);s>-1&&(this.successCalls.splice(s,1),t==null||t.add(this,A.Affected));const l=this.errorCalls.findIndex(o=>o.id===e.id);return l>-1&&(this.errorCalls.splice(l,1),t==null||t.add(this,A.Affected)),i&&K(this,t),t==null||t.attemptAutoclose("remove-call",this.id),this}removeCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected)),!0):!1),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected)),!0):!1),i&&K(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}addValueReader(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-value-reader"))){return this.writesValues.includes(e)?(t==null||t.attemptAutoclose("add-value-reader",this.id),this):(this.writesValues.push(e),t==null||t.add(this,A.Affected),this)}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=C(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),this.initialData.declaration.type===n.GenericReference){const t=this.project.findSubscribedInstanceFromReference(this.initialData.declaration);if(!t)return this;this.declaration=t}else this.declaration=C(this.initialData.declaration,this.project),this.declaration.setParent(this.parent,null),this.declaration.initChildren(e);return $a.initWritesValues(this,this.parent),Ir.initReadsValue(this),this.initialData.inputs.forEach(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),this.addInput(i,null),i}),this.initialData.outputs.forEach(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),this.addOutput(i,e),i}),this.successCalls=this.initialData.successCalls.map(t=>{const i=C(t,this.project);return i.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type)?(i.setParent(this.parent.parent,null),i.initChildren(e)):i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e)),i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=C(t,this.project);return i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type)?(i.setParent(this.parent.parent,null),i.initChildren(e)):i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e)),i}),this.internalCalls=this.initialData.internalCalls.reduce((t,i)=>{if(i.type===n.GenericReference){const s=this.project.findSubscribedInstanceFromReference(i);if(!s)return t;const l=s;return l.setParent(this,null),[...t,l]}else{const s=C(i,this.project);return s.setParent(this,null),s.initChildren(e),[...t,s]}},[]),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}setValueWriter(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-value-writer"))){return this.readsValue!==e&&(this.readsValue=e,t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("set-value-writer",this.id),this}removeValueWriter(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-value-writer"))){return this.readsValue&&(this.readsValue=null,e==null||e.add(this,A.Updated)),e==null||e.attemptAutoclose("remove-value-writer",this.id),this}removeValueReader(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-value-reader"))){return this.writesValues.includes(e)?(this.writesValues=this.writesValues.filter(i=>i.id!==e.id),t==null||t.add(this,A.Affected),this):(t==null||t.attemptAutoclose("remove-value-reader",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=g,...t){return await Ce.repository.APILoad(this.id,...t),this}async APICreate(e=g,...t){return await Ce.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=g,...t){return await Ce.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=g,...t){return await Ce.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=g,...t){return await Ce.repository.APIClone(this.id,...t),this}async APILoadVersion(e=g,t,...i){return await Ce.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:y,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...y),l.push(...c)}),this.defaultValue){const{updated:d,removed:u}=this.defaultValue.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}return this.readsValue&&(i.push(this.readsValue),this.readsValue.removeValueReader(this,t)),this.writesValues.forEach(d=>{i.push(d),d.setValueWriter(null,t)}),this.inputs.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.outputs.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.successCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),this.errorCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),this.internalCalls.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),e||this.calledBy.forEach(d=>{i.push(d),d.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.defaultValue){const{updated:o}=this.defaultValue.restore({},e);i.push(...o)}return this.readsValue&&(i.push(this.readsValue),this.readsValue.addValueReader(this,e)),this.writesValues.forEach(o=>{i.push(o),o.setValueWriter(this,e)}),this.inputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.successCalls.forEach(o=>{i.push(o),o.addSuccessCaller(this,e)}),this.errorCalls.forEach(o=>{i.push(o),o.addErrorCaller(this,e)}),this.internalCalls.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this,...((i=this.defaultValue)==null?void 0:i.toFlat(e))||[],...this.writesValues.flatMap(l=>l.toFlat(e)),...((s=this.readsValue)==null?void 0:s.toFlat(e))||[],...this.successCalls.flatMap(l=>l.toFlat(e)),...this.errorCalls.flatMap(l=>l.toFlat(e)),...this.inputs.flatMap(l=>l.toFlat(e)),...this.outputs.flatMap(l=>l.toFlat(e)),...this.internalCalls.flatMap(l=>l.toFlat(e))])}toFlatIds(e=new Set){var i;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((i=this.defaultValue)==null?void 0:i.toFlatIds(e))||[],...this.writesValues.flatMap(s=>s.toFlatIds(e)),...this.successCalls.flatMap(s=>s.toFlatIds(e)),...this.errorCalls.flatMap(s=>s.toFlatIds(e)),...this.inputs.flatMap(s=>s.toFlatIds(e)),...this.outputs.flatMap(s=>s.toFlatIds(e)),...this.internalCalls.flatMap(s=>s.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,declaration:this.declaration.toJSON(e),defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,readsValue:((i=this.readsValue)==null?void 0:i.toReference())||null,writesValues:this.writesValues.map(s=>s.toJSON(e)),inputs:this.inputs.map(s=>s.toJSON(e)),outputs:this.outputs.map(s=>s.toJSON(e)),successCalls:this.successCalls.map(s=>s.toJSON(e)),errorCalls:this.errorCalls.map(s=>s.toJSON(e)),internalCalls:this.internalCalls.map(s=>s.toJSON(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference()),calledByError:this.calledByError.map(s=>s.toReference()),calledByEntry:this.calledByEntry.map(s=>s.toReference()),parent:this.parent.toReference(),x:this.x,y:this.y})}toJSONClone(e=q){var i,s,l,o,d,u,y;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,defaultValue:((u=this.defaultValue)==null?void 0:u.toJSONClone({...e,newId:null}))||null,declaration:this.declaration.toReference({seenEntityMaps:e.seenEntityMaps}),readsValue:((y=this.readsValue)==null?void 0:y.toReference({seenEntityMaps:e.seenEntityMaps}))||null,writesValues:this.writesValues.map(c=>c.toJSONClone({...e,newId:null})),inputs:this.inputs.map(c=>c.toJSONClone({...e,newId:null})),outputs:this.outputs.map(c=>c.toJSONClone({...e,newId:null})),successCalls:this.successCalls.map(c=>c.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(c=>c.toJSONClone({...e,newId:null})),internalCalls:this.internalCalls.map(c=>this.calledBy.length||this.readsValue?c.toJSONClone({...e,newId:null}):c.toReference({seenEntityMaps:e.seenEntityMaps})),calledBySuccess:this.calledBySuccess.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps}),x:this.x,y:this.y})}toReference(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=q){var i,s,l,o;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,defaultValue:((s=this.defaultValue)==null?void 0:s.toReference(e))||null,declaration:((l=this.declaration)==null?void 0:l.toReference(e))||null,readsValue:((o=this.readsValue)==null?void 0:o.toReference(e))||null,writesValues:this.writesValues.map(d=>d.toReference(e)),inputs:this.inputs.map(d=>d.toReference(e)),outputs:this.outputs.map(d=>d.toReference(e)),successCalls:this.successCalls.map(d=>d.toReference(e)),errorCalls:this.errorCalls.map(d=>d.toReference(e)),calledBySuccess:this.calledBySuccess.map(d=>d.toReference(e)),calledByError:this.calledByError.map(d=>d.toReference(e)),calledByEntry:this.calledByEntry.map(d=>d.toReference(e)),internalCalls:this.internalCalls.map(d=>d.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((i=this.defaultValue)==null?void 0:i.toFlatJSON(e))||[],...((s=this.declaration)==null?void 0:s.toFlatJSON(e))||[],...this.writesValues.flatMap(l=>l.toFlatJSON(e)),...this.successCalls.flatMap(l=>l.toFlatJSON(e)),...this.errorCalls.flatMap(l=>l.toFlatJSON(e)),...this.inputs.flatMap(l=>l.toFlatJSON(e)),...this.outputs.flatMap(l=>l.toFlatJSON(e)),...this.internalCalls.flatMap(l=>l.toFlatJSON(e)),...this.calledBy.flatMap(l=>l.toFlatJSON(e))])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,type:this.type,declaration:this.declaration.id,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),parent:e}}toFlatGenerationTarget(e=new Set){var i,s,l;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((i=this.defaultValue)==null?void 0:i.toFlatGenerationTarget(e))||[],...((s=this.declaration)==null?void 0:s.toFlatGenerationTarget(e))||[],...((l=this.readsValue)==null?void 0:l.toFlatGenerationTarget(e))||[],...this.writesValues.flatMap(o=>o.toFlatGenerationTarget(e)),...this.successCalls.flatMap(o=>o.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(o=>o.toFlatGenerationTarget(e)),...this.inputs.flatMap(o=>o.toFlatGenerationTarget(e)),...this.outputs.flatMap(o=>o.toFlatGenerationTarget(e)),...this.internalCalls.flatMap(o=>o.toFlatGenerationTarget(e))])}clearErrors(){var e;return this.errors=[],(e=this.defaultValue)==null||e.clearErrors(),this.inputs.forEach(t=>t.clearErrors()),this.outputs.forEach(t=>t.clearErrors()),this.successCalls.forEach(t=>t.clearErrors()),this.errorCalls.forEach(t=>t.clearErrors()),this.internalCalls.forEach(t=>t.clearErrors()),this}validate(){const e=I1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){var t,i;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[],...this.inputs.flatMap(s=>s.getErrors()),...this.internalCalls.flatMap(s=>s.getErrors()),...this.outputs.flatMap(s=>s.getErrors()),...((i=this.readsValue)==null?void 0:i.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){var e;return this.defaultValue||((e=this.declaration)==null?void 0:e.defaultValue)||null}setDefaultValue(e){return this.defaultValue=e,this}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var O,P,V,M;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[],o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const u=ct(o,l);t?u.setParent(t,null):u.setParent(this.parent,null),s&&u.subscribe(),u.initChildren(e),e==null||e.add(u,A.Added);const y=(O=this.defaultValue)==null?void 0:O.clone(e,u,m.UUID.uuid(),s);u.defaultValue=y||null;const c=(P=this.inputs)==null?void 0:P.map(G=>G.clone(e,u,m.UUID.uuid(),s));u.inputs=c;const I=(V=this.outputs)==null?void 0:V.map(G=>G.clone(e,u,m.UUID.uuid(),s));u.outputs=I;const E=(M=this.internalCalls)==null?void 0:M.map(G=>G.clone(e,u,m.UUID.uuid(),s));return u.internalCalls=E,e==null||e.attemptAutoclose("clone-entity",this.id),u}addInternalCall(e){return this.internalCalls.find(t=>t===e)||this.internalCalls.push(e),this}setDeclaration(e){return this.declaration!==e&&(this.declaration=e),this}generateUnusedInputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"generate-unused-inputs"))){const t=[],i=[],s=[],l=[];if(this.declaration.dataType)if(this.declaration.dataType.entity){if([n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type)){const o=[...this.declaration.dataType.entity.properties];o.filter(c=>!c.getDataType(e)).forEach(c=>{const I=this.inputs.find(P=>x(P,this.project)===x(c,this.project));if(!I)return;const E=this.declaration.getMasterInputWithValueWritterFromAllInstances(I);if(!E)return;const O=Ji(E);c.setDataType(O),I.setDeclaration(c)}),o.filter(c=>!this.inputs.find(I=>{var E;return((E=I.declaration)==null?void 0:E.id)===c.id})).forEach(c=>{const I={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,parent:this.toReference(),name:null,description:null,declaration:c,defaultValue:null,index:c.index,readsValue:null},E=C(I,this.project);return E.setParent(this,e),E.initChildren(e),e==null||e.add(E,A.Added),E.suggestion=!0,this.addInput(E,e),E}),this.inputs.filter(c=>!c.declaration).forEach(c=>{const I=o.find(E=>x(E,this.project)===x(c,this.project));I&&c.setDeclaration(I)})}}else return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}generateUnusedOutputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"generate-unused-outputs"))){const t=[],i=[],s=[],l=[];if(this.declaration.dataType)if(this.declaration.dataType.entity)[n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type)&&[...this.declaration.dataType.entity.properties].filter(u=>!this.outputs.find(y=>y.declaration===u)).map(u=>{const y={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.OutputMap,parent:this.toReference(),defaultValue:null,declaration:u,index:u.index,writesValues:[]},c=C(y,this.project);return c.setParent(this,e),c.initChildren(e),e==null||e.add(c,A.Added),c.suggestion=!0,this.addOutput(c,e),c});else return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}generateUnusedInternalCalls(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"generate-unused-internal-calls"))){const t=[],i=[],s=[],l=[];if(this.declaration.dataType)if(this.declaration.dataType.entity)[n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.declaration.dataType.entity.type)&&[...this.declaration.dataType.entity.getAllInteractiveMethods()].filter(u=>!this.internalCalls.find(c=>{var E,O,P,V,M;return(((E=c.declaration)==null?void 0:E.id)||((P=(O=c.initialData)==null?void 0:O.declaration)==null?void 0:P.entityId)||((M=(V=c.initialData)==null?void 0:V.declaration)==null?void 0:M.id))===u.id})).map(u=>{const y=u.createInternalCall(e,this);return e==null||e.add(y,A.Added),y.suggestion=!0,this.addInternalCall(y),y});else return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}getDataType(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"get-data-type"))){var t;return((t=this.declaration)==null?void 0:t.getDataType(e))||null}getUnusedInputs(){return this.inputs.filter(e=>e.suggestion||!e.readsValue&&!e.defaultValue)}getUnusedOutputs(){return this.outputs.filter(e=>e.suggestion||!e.writesValues.length)}getUsedInputs(){return this.inputs.filter(e=>!e.suggestion&&(e.readsValue||e.defaultValue))}getUsedOutputs(){return this.outputs.filter(e=>!e.suggestion&&e.writesValues.length)}};f(Ce,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(Ce,"type",n.VariableInstance),f(Ce,"USER_MANAGED_PARENT_TYPES",[...dt,n.Project]),f(Ce,"PARENT_TYPES",[...Ce.USER_MANAGED_PARENT_TYPES]),f(Ce,"MUTABLE_BASE_PROPERTIES",[]),f(Ce,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Ce,"BASE_PROPERTIES",[...Ce.MUTABLE_BASE_PROPERTIES,...Ce.INMUTABLE_BASE_PROPERTIES]),f(Ce,"MUTABLE_META_PROPERTIES",[...Ce.MUTABLE_BASE_PROPERTIES,"x","y"]),f(Ce,"INMUTABLE_META_PROPERTIES",[...Ce.INMUTABLE_BASE_PROPERTIES]),f(Ce,"META_PROPERTIES",[...Ce.MUTABLE_META_PROPERTIES,...Ce.INMUTABLE_META_PROPERTIES]),f(Ce,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","readsValue"]),f(Ce,"INMUTABLE_UPSTREAM_PROPERTIES",["declaration","parent"]),f(Ce,"UPSTREAM_PROPERTIES",[...Ce.MUTABLE_UPSTREAM_PROPERTIES,...Ce.INMUTABLE_UPSTREAM_PROPERTIES]),f(Ce,"MUTABLE_DOWNSTREAM_PROPERTIES",["writesValues","inputs","outputs","successCalls","errorCalls","internalCalls"]),f(Ce,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Ce,"DOWNSTREAM_PROPERTIES",[...Ce.MUTABLE_DOWNSTREAM_PROPERTIES,...Ce.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Ce,"PROPERTIES",[...Ce.META_PROPERTIES,...Ce.UPSTREAM_PROPERTIES,...Ce.DOWNSTREAM_PROPERTIES]);let Zr=Ce;var E1=(r=>(r.Parent="parent",r.DataTypeEntity="data-type-entity",r))(E1||{});const Ve=class Ve extends at{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"required",!1);f(this,"constant",!1);f(this,"x");f(this,"y");f(this,"type",n.VariableDeclaration);f(this,"defaultValue",null);f(this,"dataType",null);f(this,"writesValues",[]);f(this,"readsValue",null);f(this,"inputs",[]);f(this,"outputs",[]);f(this,"calledBySuccess",[]);f(this,"calledByError",[]);f(this,"calledByEntry",[]);f(this,"successCalls",[]);f(this,"errorCalls",[]);f(this,"internalCalls",[]);f(this,"parent");f(this,"errors",[]);f(this,"project");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description,this.constant=e.constant,this.required=e.required,this.x=e.x,this.y=e.y}static new(){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.VariableDeclaration,name:"",description:"",dataType:null,internalCalls:[],successCalls:[],errorCalls:[],readsValue:null,writesValues:[],defaultValue:null,constant:!1,required:!1,inputs:[],outputs:[],parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],x:0,y:0}}static fromGenerationTarget(e,t){let i=t;if(e.parent){const c=_(e.parent);i=t.get(c)}const s=e.calledByEntry.map(c=>{const I=_(c);return t.get(I)}),l=e.calledBySuccess.map(c=>{const I=_(c);return t.get(I)}),o=e.calledByError.map(c=>{const I=_(c);return t.get(I)});let d=null;if(e.readsValue){const c=_(e.readsValue);d=t.get(c)}const u={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.VariableDeclaration,name:e.name,defaultValue:null,description:e.description,constant:e.constant||!1,required:e.required||!1,calledByEntry:s,calledBySuccess:l,calledByError:o,dataType:null,errorCalls:[],successCalls:[],internalCalls:[],readsValue:d,inputs:[],outputs:[],writesValues:[],x:0,y:0,parent:i},y=C(u,t);return y.setParent(i,null),y.initChildren(null),y}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=At(i,{parent:{list:!1,types:[...dt,n.Project],optional:!0}},t);i=l.modifiedData;const o=Ac(i,t);return s.push(...l.errors,...o,...ut(i)),{errors:s,modifiedData:i}}get variableInstances(){const e=[];return Object.values(this.detachedDependents).forEach(t=>{t.field===_c.VarDeclaration&&!e.includes(t.entity)&&e.push(t.entity)}),e}validateGeneratedUpdate(e){const t=[];let i=JSON.parse(JSON.stringify(e));const s=_a(i,this);return i=s.modifiedData,t.push(...s.errors),e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
107
107
  If an entity is called by another, they must be in the same scope, which means they have the same parent.
108
108
  Specifically for variables, their scope is also calculated from their value readers and value writters.
109
- You shouldn't have to manually update a 'parent' property. The equivalent result is to change its value readers, value writters, or callers.`,issue:null})),{errors:t,modifiedData:i}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],i=[],s=[];return Object.values(this.detachedDependents).forEach(l=>{const o=l.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),i.push(...o.removed),s.push(...o.affected)}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e,t,i,s;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),(s=(i=(t=this.dataType)==null?void 0:t.entity)==null?void 0:i.subscribeDependents)==null||s.call(i,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ve(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.outputs=this.outputs,e.internalCalls=this.internalCalls,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.writesValues=this.writesValues,e.readsValue=this.readsValue,e.defaultValue=this.defaultValue,e.dataType=this.dataType,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[I,E]of c.knownVersions)u.set(I,E);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ve(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.internalCalls=o.internalCalls,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.writesValues=o.writesValues,this.readsValue=o.readsValue,this.defaultValue=o.defaultValue,this.dataType=o.dataType,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.readsValue){const l=_(this.initialData.readsValue),o=this.project.get(l);o&&(this.setValueWriter(o,null),e.push(o))}return this.initialData.calledByEntry.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),e.push(d))}),Ir.hydrateReadsValue(this),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];this.initialized=!0,this.captureVersion();const{added:o,updated:d,removed:u,affected:y}=this.generateUnusedInputs(e);i.push(...o),t.push(...d),s.push(...u),l.push(...y);const{added:c,updated:I,removed:E,affected:O}=this.generateUnusedOutputs(e);i.push(...c),t.push(...I),s.push(...E),l.push(...O);const{added:P,updated:V,removed:M,affected:G}=this.generateUnusedInternalCalls(e);if(i.push(...P),t.push(...V),s.push(...M),l.push(...G),!this.dataType||this.dataType.inferred){const{added:B,updated:$,removed:Z,affected:J}=this.inferDataTypeAndSyncInstancesInputsAndOutputs(e);i.push(...B),t.push(...$),s.push(...Z),l.push(...J)}return e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.parent===this.project&&this.project.addVariableDeclaration(this),this.readsValue&&(this.readsValue.addValueReader(this,e),t.push(this.readsValue)),this.writesValues.forEach(o=>{o.setValueWriter(this,e),t.push(o)}),this.successCalls.forEach(o=>{o.addSuccessCaller(this,e),t.push(o)}),this.errorCalls.forEach(o=>{o.addErrorCaller(this,e),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this,e),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this,e),t.push(o)}),this.calledByEntry.forEach(o=>{o.addCall(this,e),t.push(o)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}get usedInputs(){return this.inputs.filter(e=>e.readsValue||e.defaultValue)}get unusedInputs(){return this.inputs.filter(e=>!e.readsValue&&!e.defaultValue)}get usedOutputs(){return this.outputs.filter(e=>e.writesValues.length)}get unusedOutputs(){return this.outputs.filter(e=>!e.writesValues.length)}get usedInternalCalls(){return this.internalCalls.filter(e=>!!e.calledBy.length)}get unusedInternalCalls(){return this.internalCalls.filter(e=>!e.calledBy.length)}removeInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-input"))){const i=this.inputs.findIndex(s=>s.id===e.id);return i>-1&&(this.inputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-input",this.id),this}addInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-input"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input",this.id),this):(this.inputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-input",this.id),this)}addOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-output"))){return this.outputs.includes(e)?(t==null||t.attemptAutoclose("add-output",this.id),this):(this.outputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-output",this.id),this)}removeOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-output"))){const i=this.outputs.findIndex(s=>s.id===e.id);return i>-1&&(this.outputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-output",this.id),this}addSuccessCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,A.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,A.Updated),i&&K(this,t),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,A.Updated),i&&K(this,t),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}addErrorCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-call")),i=!1){return this.errorCalls.find(s=>s.id===e.id)||(this.errorCalls.push(e),i&&K(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-call")),i=!1){return this.successCalls.find(s=>s.id===e.id)||(this.successCalls.push(e),i&&K(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-success-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-call")),i=!1){const s=this.successCalls.findIndex(o=>o.id===e.id);s>-1&&(this.successCalls.splice(s,1),t==null||t.add(this,A.Affected));const l=this.errorCalls.findIndex(o=>o.id===e.id);return l>-1&&(this.errorCalls.splice(l,1),t==null||t.add(this,A.Affected)),i&&K(this,t),t==null||t.attemptAutoclose("remove-call",this.id),this}removeCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected)),!0):!1),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected)),!0):!1),i&&K(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}addValueReader(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-value-reader"))){return this.writesValues.includes(e)?(t==null||t.attemptAutoclose("add-value-reader",this.id),this):(this.writesValues.push(e),t==null||t.add(this,A.Affected),this)}removeValueReader(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-value-reader"))){return this.writesValues.includes(e)?(this.writesValues=this.writesValues.filter(i=>i.id!==e.id),t==null||t.add(this,A.Affected),this):(t==null||t.attemptAutoclose("remove-value-reader",this.id),this)}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=C(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),this.initialData.dataType&&(this.dataType=C(this.initialData.dataType,this.project),this.dataType.setParent(this,null),this.dataType.initChildren(e)),$a.initWritesValues(this,this.parent),Ir.initReadsValue(this),this.successCalls=this.initialData.successCalls.map(t=>{const i=C(t,this.project);return i.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type)?(i.setParent(this.parent.parent,null),i.initChildren(e)):i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e)),i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=C(t,this.project);return i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type)?(i.setParent(this.parent.parent,null),i.initChildren(e)):i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e)),i}),this.initialData.inputs.forEach(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),this.addInput(i,null),i}),this.initialData.outputs.forEach(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),this.addOutput(i,null),i}),this.initialData.internalCalls.forEach(t=>{if(t.type===n.GenericReference){const s=this.project.findSubscribedInstanceFromReference(t);if(!s)return;s.setParent(this,null),s.initChildren(e),this.addInternalCall(s);return}const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),this.addInternalCall(i),i}),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}setValueWriter(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-value-writer"))){return this.readsValue!==e&&(this.readsValue=e,t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("set-value-writer",this.id),this}removeValueWriter(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-value-writer"))){return this.readsValue&&(this.readsValue=null,e==null||e.add(this,A.Updated)),e==null||e.attemptAutoclose("remove-value-writer",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}getMasterInputWithValueWritterFromAllInstances(e){return p([...this.inputs,...this.variableInstances.flatMap(s=>s.inputs)]).find(s=>x(s,this.project)===x(e,this.project)&&!!s.readsValue)||e}inferDataTypeAndSyncInstancesInputsAndOutputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"infer-data-type-and-sync-instances-inputs-and-outputs"))){var M,G,B,$;const t=[],i=[],s=[],l=[];if(!this.dataType){const Z=C({id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,parentRelationType:null,implementationChooseOne:!1,options:null,isList:!1,andChildrenGroup:null,orChildrenGroup:null,asType:!1,entity:null,like:!0,inferred:!0,parent:this.toReference()},this.project);this.setDataType(Z),Z.setParent(this,e),Z.initChildren(e),e==null||e.add(Z,A.Added),Z.metaSync({inferred:!0,like:!0},e)}if(this.readsValue){const Z=(M=this.readsValue.getDataType(e))==null?void 0:M.clone(e);if(Z){const J=(G=this.dataType)==null?void 0:G.merge(Z,e);this.dataType&&(J==null?void 0:J.self.id)!==this.dataType.id&&this.dataType.remove({ignoreUpstream:!1},e),Z.id!==((B=J==null?void 0:J.self)==null?void 0:B.id)&&Z.remove({ignoreUpstream:!1},e),J!=null&&J.self&&(J.self.metaSync({inferred:!0,like:!0},e),e==null||e.add(J.self,A.Added),this.setDataType(J.self))}return e==null||e.attemptAutoclose("infer-data-type-and-sync-instances-inputs-and-outputs",this.id),{updated:p(i),added:p(t),removed:p(s),affected:p(l),self:this}}const o=p([...this.inputs,...this.variableInstances.flatMap(Z=>Z.inputs)]),d=[];if(o.forEach(Z=>{d.find(te=>x(te,this.project)===x(Z,this.project))||d.push(Z)}),!d.length)return e==null||e.attemptAutoclose("infer-data-type-and-sync-instances-inputs-and-outputs",this.id),{updated:p(i),added:p(t),removed:p(s),affected:p(l),self:this};if(($=this.dataType)==null||$.inferFromInputs(d,e),!this.dataType)return e==null||e.attemptAutoclose("infer-data-type-and-sync-instances-inputs-and-outputs",this.id),{updated:p(i),added:p(t),removed:p(s),affected:p(l),self:this};const{updated:u,added:y,removed:c,affected:I}=this.generateUnusedInputs(e);t.push(...y),i.push(...u),s.push(...c),l.push(...I);const{updated:E,added:O,removed:P,affected:V}=this.generateUnusedOutputs(e);return t.push(...O),i.push(...E),s.push(...P),l.push(...V),this.variableInstances.forEach(Z=>{const{updated:J,added:te,removed:fe,affected:Ie}=Z.generateUnusedInputs(e);t.push(...te),i.push(...J),s.push(...fe),l.push(...Ie);const{updated:X,added:le,removed:ei,affected:Xi}=Z.generateUnusedOutputs(e);t.push(...le),i.push(...X),s.push(...ei),l.push(...Xi)}),e==null||e.attemptAutoclose("infer-data-type-and-sync-instances-inputs-and-outputs",this.id),{updated:p(i),added:p(t),removed:p(s),affected:p(l),self:this}}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.name=e.name||s.name,this.description=e.description||s.description,this.x=e.x||s.x,this.y=e.y||s.y,this.constant=e.constant!==void 0?e.constant:s.constant,this.required=e.required!==void 0?e.required:s.required,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=g,...t){return await Ve.repository.APILoad(this.id,...t),this}async APICreate(e=g,...t){return await Ve.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=g,...t){return await Ve.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=g,...t){return await Ve.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=g,...t){return await Ve.repository.APIClone(this.id,...t),this}async APILoadVersion(e=g,t,...i){return await Ve.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:y,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...y),l.push(...c)}),this.defaultValue){const{updated:d,removed:u}=this.defaultValue.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}if(this.readsValue&&(i.push(this.readsValue),this.readsValue.removeValueReader(this,t)),this.writesValues.forEach(d=>{i.push(d),d.setValueWriter(null,t)}),this.inputs.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.outputs.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.successCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),this.errorCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),this.internalCalls.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.dataType){const{updated:d,removed:u}=this.dataType.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}return e||this.calledBy.forEach(d=>{i.push(d),d.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.defaultValue){const{updated:o}=this.defaultValue.restore({},e);i.push(...o)}if(this.readsValue&&(i.push(this.readsValue),this.readsValue.addValueReader(this,e)),this.writesValues.forEach(o=>{i.push(o),o.setValueWriter(this,e)}),this.inputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.successCalls.forEach(o=>{i.push(o),o.addSuccessCaller(this,e)}),this.errorCalls.forEach(o=>{i.push(o),o.addErrorCaller(this,e)}),this.internalCalls.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.dataType){const{updated:o}=this.dataType.restore({},e);i.push(...o)}return this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){var i,s,l;return e.has(this.id)?[]:(e.add(this.id),[this,...((i=this.defaultValue)==null?void 0:i.toFlat(e))||[],...((s=this.dataType)==null?void 0:s.toFlat(e))||[],...((l=this.readsValue)==null?void 0:l.toFlat(e))||[],...this.writesValues.flatMap(o=>o.toFlat(e)),...this.successCalls.flatMap(o=>o.toFlat(e)),...this.errorCalls.flatMap(o=>o.toFlat(e)),...this.inputs.flatMap(o=>o.toFlat(e)),...this.outputs.flatMap(o=>o.toFlat(e)),...this.internalCalls.flatMap(o=>o.toFlat(e)),...this.calledBy.flatMap(o=>o.toFlat(e))])}toFlatIds(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((i=this.defaultValue)==null?void 0:i.toFlatIds(e))||[],...((s=this.dataType)==null?void 0:s.toFlatIds(e))||[],...this.writesValues.flatMap(l=>l.toFlatIds(e)),...this.successCalls.flatMap(l=>l.toFlatIds(e)),...this.errorCalls.flatMap(l=>l.toFlatIds(e)),...this.inputs.flatMap(l=>l.toFlatIds(e)),...this.outputs.flatMap(l=>l.toFlatIds(e)),...this.internalCalls.flatMap(l=>l.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,required:this.required,constant:this.constant,x:this.x,y:this.y,type:this.type,name:this.name}}toJSON(e=new Set){var t,i,s;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,constant:this.constant,required:this.required,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,dataType:((i=this.dataType)==null?void 0:i.toJSON(e))||null,readsValue:((s=this.readsValue)==null?void 0:s.toReference())||null,writesValues:this.writesValues.map(l=>l.toJSON(e)),inputs:this.inputs.map(l=>l.toJSON(e)),outputs:this.outputs.map(l=>l.toJSON(e)),successCalls:this.successCalls.map(l=>l.toJSON(e)),errorCalls:this.errorCalls.map(l=>l.toJSON(e)),internalCalls:this.internalCalls.map(l=>l.toJSON(e)),calledBySuccess:this.calledBySuccess.map(l=>l.toReference()),calledByError:this.calledByError.map(l=>l.toReference()),calledByEntry:this.calledByEntry.map(l=>l.toReference()),parent:this.parent.toReference(),x:this.x,y:this.y})}toJSONClone(e=q){var i,s,l,o,d,u,y,c;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,defaultValue:((u=this.defaultValue)==null?void 0:u.toJSONClone({...e,newId:null}))||null,dataType:((y=this.dataType)==null?void 0:y.toJSONClone({...e,newId:null}))||null,readsValue:((c=this.readsValue)==null?void 0:c.toReference({seenEntityMaps:e.seenEntityMaps}))||null,writesValues:this.writesValues.map(I=>I.toJSONClone({...e,newId:null})),inputs:this.inputs.map(I=>I.toJSONClone({...e,newId:null})),outputs:this.outputs.map(I=>I.toJSONClone({...e,newId:null})),successCalls:this.successCalls.map(I=>I.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(I=>I.toJSONClone({...e,newId:null})),internalCalls:this.internalCalls.map(I=>this.calledBy.length||this.readsValue?I.toJSONClone({...e,newId:null}):I.toReference({seenEntityMaps:e.seenEntityMaps})),calledBySuccess:this.calledBySuccess.map(I=>I.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(I=>I.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(I=>I.toReference({seenEntityMaps:e.seenEntityMaps})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps}),x:this.x,y:this.y})}toReference(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=q){var i,s,l,o;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,required:this.required,constant:this.constant,x:this.x,y:this.y,defaultValue:((s=this.defaultValue)==null?void 0:s.toReference(e))||null,dataType:((l=this.dataType)==null?void 0:l.toReference(e))||null,readsValue:((o=this.readsValue)==null?void 0:o.toReference(e))||null,writesValues:this.writesValues.map(d=>d.toReference(e)),inputs:this.inputs.map(d=>d.toReference(e)),outputs:this.outputs.map(d=>d.toReference(e)),successCalls:this.successCalls.map(d=>d.toReference(e)),errorCalls:this.errorCalls.map(d=>d.toReference(e)),calledBySuccess:this.calledBySuccess.map(d=>d.toReference(e)),calledByError:this.calledByError.map(d=>d.toReference(e)),calledByEntry:this.calledByEntry.map(d=>d.toReference(e)),internalCalls:this.internalCalls.map(d=>d.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((i=this.defaultValue)==null?void 0:i.toFlatJSON(e))||[],...((s=this.dataType)==null?void 0:s.toFlatJSON(e))||[],...this.writesValues.flatMap(l=>l.toFlatJSON(e)),...this.successCalls.flatMap(l=>l.toFlatJSON(e)),...this.errorCalls.flatMap(l=>l.toFlatJSON(e)),...this.inputs.flatMap(l=>l.toFlatJSON(e)),...this.outputs.flatMap(l=>l.toFlatJSON(e)),...this.internalCalls.flatMap(l=>l.toFlatJSON(e))])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,type:this.type,name:this.name,description:this.description,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),parent:e}}toFlatGenerationTarget(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((i=this.defaultValue)==null?void 0:i.toFlatGenerationTarget(e))||[],...((s=this.dataType)==null?void 0:s.toFlatGenerationTarget(e))||[],...this.writesValues.flatMap(l=>l.toFlatGenerationTarget(e)),...this.successCalls.flatMap(l=>l.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(l=>l.toFlatGenerationTarget(e)),...this.inputs.flatMap(l=>l.toFlatGenerationTarget(e)),...this.outputs.flatMap(l=>l.toFlatGenerationTarget(e)),...this.internalCalls.flatMap(l=>l.toFlatGenerationTarget(e))])}clearErrors(){var e,t;return this.errors=[],this.inputs.forEach(i=>i.clearErrors()),this.outputs.forEach(i=>i.clearErrors()),this.successCalls.forEach(i=>i.clearErrors()),this.errorCalls.forEach(i=>i.clearErrors()),this.internalCalls.forEach(i=>i.clearErrors()),(e=this.dataType)==null||e.clearErrors(),(t=this.defaultValue)==null||t.clearErrors(),this}validate(){const e=T1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){var t,i,s;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[],...((i=this.dataType)==null?void 0:i.getErrors())||[],...this.inputs.flatMap(l=>l.getErrors()),...this.internalCalls.flatMap(l=>l.getErrors()),...this.outputs.flatMap(l=>l.getErrors()),...((s=this.readsValue)==null?void 0:s.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){return this.defaultValue||null}setDefaultValue(e){return this.defaultValue=e,this}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var P,V,M,G,B;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[],o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const u=ct(o,l);t?u.setParent(t,null):u.setParent(this.parent,null),s&&u.subscribe(),u.initChildren(e),e==null||e.add(u,A.Added);const y=(P=this.dataType)==null?void 0:P.clone(e,u,m.UUID.uuid(),s);u.dataType=y||null;const c=(V=this.defaultValue)==null?void 0:V.clone(e,u,m.UUID.uuid(),s);u.defaultValue=c||null;const I=(M=this.inputs)==null?void 0:M.map($=>$.clone(e,u,m.UUID.uuid(),s));u.inputs=I;const E=(G=this.outputs)==null?void 0:G.map($=>$.clone(e,u,m.UUID.uuid(),s));u.outputs=E;const O=(B=this.internalCalls)==null?void 0:B.map($=>$.clone(e,u,m.UUID.uuid(),s));return u.internalCalls=O,e==null||e.attemptAutoclose("clone-entity",this.id),u}addInternalCall(e){return this.internalCalls.find(t=>t===e)||this.internalCalls.push(e),this}createInstance(e=this.project,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"create-instance")),i={}){const s={id:i.id||m.UUID.uuid(),version:i.version||m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.VariableInstance,parent:e.toReference(),defaultValue:i.defaultValue||null,successCalls:i.successCalls||[],errorCalls:i.errorCalls||[],inputs:i.inputs||[],outputs:i.outputs||[],writesValues:i.writesValues||[],internalCalls:i.internalCalls||[],readsValue:i.readsValue||null,calledByEntry:i.calledByEntry||[],calledBySuccess:i.calledBySuccess||[],calledByError:i.calledByError||[],declaration:this.toJSON(),x:0,y:0},l=C(s,this.project);return l.setParent(e,null),l.initChildren(null),t==null||t.add(l,A.Added),e===this.project&&this.project.addVariableInstance(l),t==null||t.attemptAutoclose("create-instance",this.id),l}generateUnusedInputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"generate-unused-inputs"))){const t=[],i=[],s=[],l=[];if(this.dataType)if(this.dataType.entity){if([n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.dataType.entity.type)){const o=[...this.dataType.entity.properties];o.filter(c=>!c.getDataType(e)).forEach(c=>{const I=this.inputs.find(P=>x(P,this.project)===x(c,this.project));if(!I)return;const E=this.getMasterInputWithValueWritterFromAllInstances(I);if(!E)return;const O=Ji(E);c.setDataType(O),I.setDeclaration(c)}),o.filter(c=>!this.inputs.find(I=>{var E;return((E=I.declaration)==null?void 0:E.id)===c.id})).forEach(c=>{const I={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,parent:this.toReference(),name:null,description:null,declaration:c,defaultValue:null,index:c.index,readsValue:null},E=C(I,this.project);return E.setParent(this,e),E.initChildren(e),e==null||e.add(E,A.Added),E.suggestion=!0,this.addInput(E,e),E}),this.inputs.filter(c=>!c.declaration).forEach(c=>{const I=o.find(E=>x(E,this.project)===x(c,this.project));I&&c.setDeclaration(I)})}}else return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}generateUnusedOutputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"generate-unused-outputs"))){const t=[],i=[],s=[],l=[];if(this.dataType)if(this.dataType.entity)[n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.dataType.entity.type)&&[...this.dataType.entity.properties].filter(u=>!this.outputs.find(y=>y.declaration===u)).map(u=>{const y={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.OutputMap,defaultValue:null,parent:this.toReference(),declaration:u,index:u.index,writesValues:[]},c=C(y,this.project);return c.setParent(this,e),c.initChildren(e),e==null||e.add(c,A.Added),c.suggestion=!0,this.addOutput(c,e),c});else return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}generateUnusedInternalCalls(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"generate-unused-internal-calls"))){const t=[],i=[],s=[],l=[];if(this.dataType)if(this.dataType.entity)[n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.dataType.entity.type)&&[...this.dataType.entity.getAllInteractiveMethods()].filter(u=>!this.internalCalls.find(c=>{var E,O,P,V,M;return(((E=c.declaration)==null?void 0:E.id)||((P=(O=c.initialData)==null?void 0:O.declaration)==null?void 0:P.entityId)||((M=(V=c.initialData)==null?void 0:V.declaration)==null?void 0:M.id))===u.id})).map(u=>{const y=u.createInternalCall(e,this);return e==null||e.add(y,A.Added),y.suggestion=!0,this.addInternalCall(y),y});else return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}getDataType(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"get-data-type"))){return(!this.dataType||this.dataType.inferred)&&this.inferDataTypeAndSyncInstancesInputsAndOutputs(e),this.dataType||null}getUnusedInputs(){return this.inputs.filter(e=>e.suggestion||!e.readsValue&&!e.defaultValue)}getUnusedOutputs(){return this.outputs.filter(e=>e.suggestion||!e.writesValues.length)}getUsedInputs(){return this.inputs.filter(e=>!e.suggestion&&(e.readsValue||e.defaultValue))}getUsedOutputs(){return this.outputs.filter(e=>!e.suggestion&&e.writesValues.length)}};f(Ve,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(Ve,"type",n.VariableDeclaration),f(Ve,"USER_MANAGED_PARENT_TYPES",[...dt,n.Project]),f(Ve,"PARENT_TYPES",[...Ve.USER_MANAGED_PARENT_TYPES]),f(Ve,"MUTABLE_BASE_PROPERTIES",["name","description"]),f(Ve,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Ve,"BASE_PROPERTIES",[...Ve.MUTABLE_BASE_PROPERTIES,...Ve.INMUTABLE_BASE_PROPERTIES]),f(Ve,"MUTABLE_META_PROPERTIES",[...Ve.MUTABLE_BASE_PROPERTIES,"x","y"]),f(Ve,"INMUTABLE_META_PROPERTIES",[...Ve.INMUTABLE_BASE_PROPERTIES]),f(Ve,"META_PROPERTIES",[...Ve.MUTABLE_META_PROPERTIES,...Ve.INMUTABLE_META_PROPERTIES]),f(Ve,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","readsValue"]),f(Ve,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","dataType"]),f(Ve,"UPSTREAM_PROPERTIES",[...Ve.MUTABLE_UPSTREAM_PROPERTIES,...Ve.INMUTABLE_UPSTREAM_PROPERTIES]),f(Ve,"MUTABLE_DOWNSTREAM_PROPERTIES",["writesValues","inputs","outputs","successCalls","errorCalls","internalCalls"]),f(Ve,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Ve,"DOWNSTREAM_PROPERTIES",[...Ve.MUTABLE_DOWNSTREAM_PROPERTIES,...Ve.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Ve,"PROPERTIES",[...Ve.META_PROPERTIES,...Ve.UPSTREAM_PROPERTIES,...Ve.DOWNSTREAM_PROPERTIES]);let qr=Ve;function A1(r){var l;const a=L5(),e=r.toJSON();a.safeParse(e).success,r.inputsDeclarations.forEach(o=>o.validate()),r.inputs.forEach(o=>o.validate()),r.outputsDeclarations.forEach(o=>o.validate()),r.outputs.forEach(o=>o.validate()),(l=r.error)==null||l.validate();const s=[...vr(r)];if(r.id==="search-person-by-id-id"){const o=de({id:`${r.id}--${F.PropertyImplementsNonAbstact}`,message:`Property "${x(r,r.project)}" with id "${r.id}" implements a non-abstract property "${x(r,r.project)}" with id "${r.id}".`,issue:null,severity:D.Error,code:F.PropertyImplementsNonAbstact,entity:r});s.push(o.error)}return He(r.errors,s)}const Uq=Object.freeze(Object.defineProperty({__proto__:null,validate:A1},Symbol.toStringTag,{value:"Module"}));var b1=(r=>(r.Parent="parent",r))(b1||{});const We=class We extends at{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"x");f(this,"y");f(this,"query","");f(this,"type",n.Search);f(this,"successCalls",[]);f(this,"errorCalls",[]);f(this,"inputsDeclarations",[]);f(this,"inputs",[]);f(this,"outputsDeclarations",[]);f(this,"outputs",[]);f(this,"calledBySuccess",[]);f(this,"calledByError",[]);f(this,"calledByEntry",[]);f(this,"error",null);f(this,"parent");f(this,"errors",[]);f(this,"project");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y,this.name=e.name,this.query=e.query,this.description=e.description}static new(){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Search,name:"",description:"",inputsDeclarations:[],outputsDeclarations:[],inputs:[],outputs:[],query:"",error:null,parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],errorCalls:[],successCalls:[],x:0,y:0}}static fromGenerationTarget(e,t){let i=t;if(e.parent){const y=_(e.parent);i=t.get(y)}const s=e.calledByEntry.map(y=>{const c=_(y);return t.get(c)}),l=e.calledBySuccess.map(y=>{const c=_(y);return t.get(c)}),o=e.calledByError.map(y=>{const c=_(y);return t.get(c)}),d={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Search,name:e.name,description:e.description,query:e.query,calledByEntry:s,calledBySuccess:l,calledByError:o,errorCalls:[],successCalls:[],inputsDeclarations:[],inputs:[],outputsDeclarations:[],outputs:[],error:null,x:0,y:0,parent:i},u=C(d,t);return u.setParent(i,null),u.initChildren(null),u}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=At(i,{parent:{list:!1,types:[...dt,n.Project],optional:!0}},t);return i=l.modifiedData,s.push(...l.errors,...ut(i)),{errors:s,modifiedData:i}}get resultsAsList(){const e=this.outputsDeclarations[0];if(e){const t=e.getDataType(null);return t?t.isList===!0:!0}return!0}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
109
+ You shouldn't have to manually update a 'parent' property. The equivalent result is to change its value readers, value writters, or callers.`,issue:null})),{errors:t,modifiedData:i}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],i=[],s=[];return Object.values(this.detachedDependents).forEach(l=>{const o=l.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),i.push(...o.removed),s.push(...o.affected)}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e,t,i,s;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),(s=(i=(t=this.dataType)==null?void 0:t.entity)==null?void 0:i.subscribeDependents)==null||s.call(i,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ve(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.outputs=this.outputs,e.internalCalls=this.internalCalls,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.writesValues=this.writesValues,e.readsValue=this.readsValue,e.defaultValue=this.defaultValue,e.dataType=this.dataType,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[I,E]of c.knownVersions)u.set(I,E);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ve(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.internalCalls=o.internalCalls,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.writesValues=o.writesValues,this.readsValue=o.readsValue,this.defaultValue=o.defaultValue,this.dataType=o.dataType,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.readsValue){const l=_(this.initialData.readsValue),o=this.project.get(l);o&&(this.setValueWriter(o,null),e.push(o))}return this.initialData.calledByEntry.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),e.push(d))}),Ir.hydrateReadsValue(this),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];this.initialized=!0,this.captureVersion();const{added:o,updated:d,removed:u,affected:y}=this.generateUnusedInputs(e);i.push(...o),t.push(...d),s.push(...u),l.push(...y);const{added:c,updated:I,removed:E,affected:O}=this.generateUnusedOutputs(e);i.push(...c),t.push(...I),s.push(...E),l.push(...O);const{added:P,updated:V,removed:M,affected:G}=this.generateUnusedInternalCalls(e);if(i.push(...P),t.push(...V),s.push(...M),l.push(...G),!this.dataType||this.dataType.inferred){const{added:B,updated:$,removed:Z,affected:J}=this.inferDataTypeAndSyncInstancesInputsAndOutputs(e);i.push(...B),t.push(...$),s.push(...Z),l.push(...J)}return e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.parent===this.project&&this.project.addVariableDeclaration(this),this.readsValue&&(this.readsValue.addValueReader(this,e),t.push(this.readsValue)),this.writesValues.forEach(o=>{o.setValueWriter(this,e),t.push(o)}),this.successCalls.forEach(o=>{o.addSuccessCaller(this,e),t.push(o)}),this.errorCalls.forEach(o=>{o.addErrorCaller(this,e),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this,e),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this,e),t.push(o)}),this.calledByEntry.forEach(o=>{o.addCall(this,e),t.push(o)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}get usedInputs(){return this.inputs.filter(e=>e.readsValue||e.defaultValue)}get unusedInputs(){return this.inputs.filter(e=>!e.readsValue&&!e.defaultValue)}get usedOutputs(){return this.outputs.filter(e=>e.writesValues.length)}get unusedOutputs(){return this.outputs.filter(e=>!e.writesValues.length)}get usedInternalCalls(){return this.internalCalls.filter(e=>!!e.calledBy.length)}get unusedInternalCalls(){return this.internalCalls.filter(e=>!e.calledBy.length)}removeInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-input"))){const i=this.inputs.findIndex(s=>s.id===e.id);return i>-1&&(this.inputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-input",this.id),this}addInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-input"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input",this.id),this):(this.inputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-input",this.id),this)}addOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-output"))){return this.outputs.includes(e)?(t==null||t.attemptAutoclose("add-output",this.id),this):(this.outputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-output",this.id),this)}removeOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-output"))){const i=this.outputs.findIndex(s=>s.id===e.id);return i>-1&&(this.outputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-output",this.id),this}addSuccessCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,A.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,A.Updated),i&&K(this,t),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,A.Updated),i&&K(this,t),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}addErrorCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-call")),i=!1){return this.errorCalls.find(s=>s.id===e.id)||(this.errorCalls.push(e),i&&K(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-call")),i=!1){return this.successCalls.find(s=>s.id===e.id)||(this.successCalls.push(e),i&&K(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-success-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-call")),i=!1){const s=this.successCalls.findIndex(o=>o.id===e.id);s>-1&&(this.successCalls.splice(s,1),t==null||t.add(this,A.Affected));const l=this.errorCalls.findIndex(o=>o.id===e.id);return l>-1&&(this.errorCalls.splice(l,1),t==null||t.add(this,A.Affected)),i&&K(this,t),t==null||t.attemptAutoclose("remove-call",this.id),this}removeCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected)),!0):!1),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected)),!0):!1),i&&K(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}addValueReader(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-value-reader"))){return this.writesValues.includes(e)?(t==null||t.attemptAutoclose("add-value-reader",this.id),this):(this.writesValues.push(e),t==null||t.add(this,A.Affected),this)}removeValueReader(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-value-reader"))){return this.writesValues.includes(e)?(this.writesValues=this.writesValues.filter(i=>i.id!==e.id),t==null||t.add(this,A.Affected),this):(t==null||t.attemptAutoclose("remove-value-reader",this.id),this)}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=C(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),this.initialData.dataType&&(this.dataType=C(this.initialData.dataType,this.project),this.dataType.setParent(this,null),this.dataType.initChildren(e)),$a.initWritesValues(this,this.parent),Ir.initReadsValue(this),this.successCalls=this.initialData.successCalls.map(t=>{const i=C(t,this.project);return i.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type)?(i.setParent(this.parent.parent,null),i.initChildren(e)):i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e)),i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=C(t,this.project);return i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type)?(i.setParent(this.parent.parent,null),i.initChildren(e)):i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e)),i}),this.initialData.inputs.forEach(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),this.addInput(i,null),i}),this.initialData.outputs.forEach(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),this.addOutput(i,null),i}),this.initialData.internalCalls.forEach(t=>{if(t.type===n.GenericReference){const s=this.project.findSubscribedInstanceFromReference(t);if(!s)return;s.setParent(this,null),s.initChildren(e),this.addInternalCall(s);return}const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),this.addInternalCall(i),i}),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}setValueWriter(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-value-writer"))){return this.readsValue!==e&&(this.readsValue=e,t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("set-value-writer",this.id),this}removeValueWriter(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-value-writer"))){return this.readsValue&&(this.readsValue=null,e==null||e.add(this,A.Updated)),e==null||e.attemptAutoclose("remove-value-writer",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}getMasterInputWithValueWritterFromAllInstances(e){return p([...this.inputs,...this.variableInstances.flatMap(s=>s.inputs)]).find(s=>x(s,this.project)===x(e,this.project)&&!!s.readsValue)||e}inferDataTypeAndSyncInstancesInputsAndOutputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"infer-data-type-and-sync-instances-inputs-and-outputs"))){var M,G,B,$;const t=[],i=[],s=[],l=[];if(!this.dataType){const Z=C({id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,parentRelationType:null,implementationChooseOne:!1,options:null,isList:!1,andChildrenGroup:null,orChildrenGroup:null,asType:!1,entity:null,like:!0,inferred:!0,parent:this.toReference()},this.project);this.setDataType(Z),Z.setParent(this,e),Z.initChildren(e),e==null||e.add(Z,A.Added),Z.metaSync({inferred:!0,like:!0},e)}if(this.readsValue){const Z=(M=this.readsValue.getDataType(e))==null?void 0:M.clone(e);if(Z){const J=(G=this.dataType)==null?void 0:G.merge(Z,e);this.dataType&&(J==null?void 0:J.self.id)!==this.dataType.id&&this.dataType.remove({ignoreUpstream:!1},e),Z.id!==((B=J==null?void 0:J.self)==null?void 0:B.id)&&Z.remove({ignoreUpstream:!1},e),J!=null&&J.self&&(J.self.metaSync({inferred:!0,like:!0},e),e==null||e.add(J.self,A.Added),this.setDataType(J.self))}return e==null||e.attemptAutoclose("infer-data-type-and-sync-instances-inputs-and-outputs",this.id),{updated:p(i),added:p(t),removed:p(s),affected:p(l),self:this}}const o=p([...this.inputs,...this.variableInstances.flatMap(Z=>Z.inputs)]),d=[];if(o.forEach(Z=>{d.find(te=>x(te,this.project)===x(Z,this.project))||d.push(Z)}),!d.length)return e==null||e.attemptAutoclose("infer-data-type-and-sync-instances-inputs-and-outputs",this.id),{updated:p(i),added:p(t),removed:p(s),affected:p(l),self:this};if(($=this.dataType)==null||$.inferFromInputs(d,e),!this.dataType)return e==null||e.attemptAutoclose("infer-data-type-and-sync-instances-inputs-and-outputs",this.id),{updated:p(i),added:p(t),removed:p(s),affected:p(l),self:this};const{updated:u,added:y,removed:c,affected:I}=this.generateUnusedInputs(e);t.push(...y),i.push(...u),s.push(...c),l.push(...I);const{updated:E,added:O,removed:P,affected:V}=this.generateUnusedOutputs(e);return t.push(...O),i.push(...E),s.push(...P),l.push(...V),this.variableInstances.forEach(Z=>{const{updated:J,added:te,removed:fe,affected:Ie}=Z.generateUnusedInputs(e);t.push(...te),i.push(...J),s.push(...fe),l.push(...Ie);const{updated:X,added:le,removed:ei,affected:Xi}=Z.generateUnusedOutputs(e);t.push(...le),i.push(...X),s.push(...ei),l.push(...Xi)}),e==null||e.attemptAutoclose("infer-data-type-and-sync-instances-inputs-and-outputs",this.id),{updated:p(i),added:p(t),removed:p(s),affected:p(l),self:this}}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.name=e.name||s.name,this.description=e.description||s.description,this.x=e.x||s.x,this.y=e.y||s.y,this.constant=e.constant!==void 0?e.constant:s.constant,this.required=e.required!==void 0?e.required:s.required,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=g,...t){return await Ve.repository.APILoad(this.id,...t),this}async APICreate(e=g,...t){return await Ve.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=g,...t){return await Ve.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=g,...t){return await Ve.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=g,...t){return await Ve.repository.APIClone(this.id,...t),this}async APILoadVersion(e=g,t,...i){return await Ve.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:y,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...y),l.push(...c)}),this.defaultValue){const{updated:d,removed:u}=this.defaultValue.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}if(this.readsValue&&(i.push(this.readsValue),this.readsValue.removeValueReader(this,t)),this.writesValues.forEach(d=>{i.push(d),d.setValueWriter(null,t)}),this.inputs.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.outputs.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.successCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),this.errorCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),this.internalCalls.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.dataType){const{updated:d,removed:u}=this.dataType.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}return e||this.calledBy.forEach(d=>{i.push(d),d.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.defaultValue){const{updated:o}=this.defaultValue.restore({},e);i.push(...o)}if(this.readsValue&&(i.push(this.readsValue),this.readsValue.addValueReader(this,e)),this.writesValues.forEach(o=>{i.push(o),o.setValueWriter(this,e)}),this.inputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.successCalls.forEach(o=>{i.push(o),o.addSuccessCaller(this,e)}),this.errorCalls.forEach(o=>{i.push(o),o.addErrorCaller(this,e)}),this.internalCalls.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.dataType){const{updated:o}=this.dataType.restore({},e);i.push(...o)}return this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){var i,s,l;return e.has(this.id)?[]:(e.add(this.id),[this,...((i=this.defaultValue)==null?void 0:i.toFlat(e))||[],...((s=this.dataType)==null?void 0:s.toFlat(e))||[],...((l=this.readsValue)==null?void 0:l.toFlat(e))||[],...this.writesValues.flatMap(o=>o.toFlat(e)),...this.successCalls.flatMap(o=>o.toFlat(e)),...this.errorCalls.flatMap(o=>o.toFlat(e)),...this.inputs.flatMap(o=>o.toFlat(e)),...this.outputs.flatMap(o=>o.toFlat(e)),...this.internalCalls.flatMap(o=>o.toFlat(e)),...this.calledBy.flatMap(o=>o.toFlat(e))])}toFlatIds(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((i=this.defaultValue)==null?void 0:i.toFlatIds(e))||[],...((s=this.dataType)==null?void 0:s.toFlatIds(e))||[],...this.writesValues.flatMap(l=>l.toFlatIds(e)),...this.successCalls.flatMap(l=>l.toFlatIds(e)),...this.errorCalls.flatMap(l=>l.toFlatIds(e)),...this.inputs.flatMap(l=>l.toFlatIds(e)),...this.outputs.flatMap(l=>l.toFlatIds(e)),...this.internalCalls.flatMap(l=>l.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,required:this.required,constant:this.constant,x:this.x,y:this.y,type:this.type,name:this.name}}toJSON(e=new Set){var t,i,s;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,constant:this.constant,required:this.required,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,dataType:((i=this.dataType)==null?void 0:i.toJSON(e))||null,readsValue:((s=this.readsValue)==null?void 0:s.toReference())||null,writesValues:this.writesValues.map(l=>l.toJSON(e)),inputs:this.inputs.map(l=>l.toJSON(e)),outputs:this.outputs.map(l=>l.toJSON(e)),successCalls:this.successCalls.map(l=>l.toJSON(e)),errorCalls:this.errorCalls.map(l=>l.toJSON(e)),internalCalls:this.internalCalls.map(l=>l.toJSON(e)),calledBySuccess:this.calledBySuccess.map(l=>l.toReference()),calledByError:this.calledByError.map(l=>l.toReference()),calledByEntry:this.calledByEntry.map(l=>l.toReference()),parent:this.parent.toReference(),x:this.x,y:this.y})}toJSONClone(e=q){var i,s,l,o,d,u,y,c;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,defaultValue:((u=this.defaultValue)==null?void 0:u.toJSONClone({...e,newId:null}))||null,dataType:((y=this.dataType)==null?void 0:y.toJSONClone({...e,newId:null}))||null,readsValue:((c=this.readsValue)==null?void 0:c.toReference({seenEntityMaps:e.seenEntityMaps}))||null,writesValues:this.writesValues.map(I=>I.toJSONClone({...e,newId:null})),inputs:this.inputs.map(I=>I.toJSONClone({...e,newId:null})),outputs:this.outputs.map(I=>I.toJSONClone({...e,newId:null})),successCalls:this.successCalls.map(I=>I.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(I=>I.toJSONClone({...e,newId:null})),internalCalls:this.internalCalls.map(I=>this.calledBy.length||this.readsValue?I.toJSONClone({...e,newId:null}):I.toReference({seenEntityMaps:e.seenEntityMaps})),calledBySuccess:this.calledBySuccess.map(I=>I.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(I=>I.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(I=>I.toReference({seenEntityMaps:e.seenEntityMaps})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps}),x:this.x,y:this.y})}toReference(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=q){var i,s,l,o;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,required:this.required,constant:this.constant,x:this.x,y:this.y,defaultValue:((s=this.defaultValue)==null?void 0:s.toReference(e))||null,dataType:((l=this.dataType)==null?void 0:l.toReference(e))||null,readsValue:((o=this.readsValue)==null?void 0:o.toReference(e))||null,writesValues:this.writesValues.map(d=>d.toReference(e)),inputs:this.inputs.map(d=>d.toReference(e)),outputs:this.outputs.map(d=>d.toReference(e)),successCalls:this.successCalls.map(d=>d.toReference(e)),errorCalls:this.errorCalls.map(d=>d.toReference(e)),calledBySuccess:this.calledBySuccess.map(d=>d.toReference(e)),calledByError:this.calledByError.map(d=>d.toReference(e)),calledByEntry:this.calledByEntry.map(d=>d.toReference(e)),internalCalls:this.internalCalls.map(d=>d.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((i=this.defaultValue)==null?void 0:i.toFlatJSON(e))||[],...((s=this.dataType)==null?void 0:s.toFlatJSON(e))||[],...this.writesValues.flatMap(l=>l.toFlatJSON(e)),...this.successCalls.flatMap(l=>l.toFlatJSON(e)),...this.errorCalls.flatMap(l=>l.toFlatJSON(e)),...this.inputs.flatMap(l=>l.toFlatJSON(e)),...this.outputs.flatMap(l=>l.toFlatJSON(e)),...this.internalCalls.flatMap(l=>l.toFlatJSON(e))])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,type:this.type,name:this.name,description:this.description,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),parent:e}}toFlatGenerationTarget(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((i=this.defaultValue)==null?void 0:i.toFlatGenerationTarget(e))||[],...((s=this.dataType)==null?void 0:s.toFlatGenerationTarget(e))||[],...this.writesValues.flatMap(l=>l.toFlatGenerationTarget(e)),...this.successCalls.flatMap(l=>l.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(l=>l.toFlatGenerationTarget(e)),...this.inputs.flatMap(l=>l.toFlatGenerationTarget(e)),...this.outputs.flatMap(l=>l.toFlatGenerationTarget(e)),...this.internalCalls.flatMap(l=>l.toFlatGenerationTarget(e))])}clearErrors(){var e,t;return this.errors=[],this.inputs.forEach(i=>i.clearErrors()),this.outputs.forEach(i=>i.clearErrors()),this.successCalls.forEach(i=>i.clearErrors()),this.errorCalls.forEach(i=>i.clearErrors()),this.internalCalls.forEach(i=>i.clearErrors()),(e=this.dataType)==null||e.clearErrors(),(t=this.defaultValue)==null||t.clearErrors(),this}validate(){const e=T1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){var t,i,s;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[],...((i=this.dataType)==null?void 0:i.getErrors())||[],...this.inputs.flatMap(l=>l.getErrors()),...this.internalCalls.flatMap(l=>l.getErrors()),...this.outputs.flatMap(l=>l.getErrors()),...((s=this.readsValue)==null?void 0:s.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){return this.defaultValue||null}setDefaultValue(e){return this.defaultValue=e,this}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var P,V,M,G,B;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[],o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const u=ct(o,l);t?u.setParent(t,null):u.setParent(this.parent,null),s&&u.subscribe(),u.initChildren(e),e==null||e.add(u,A.Added);const y=(P=this.dataType)==null?void 0:P.clone(e,u,m.UUID.uuid(),s);u.dataType=y||null;const c=(V=this.defaultValue)==null?void 0:V.clone(e,u,m.UUID.uuid(),s);u.defaultValue=c||null;const I=(M=this.inputs)==null?void 0:M.map($=>$.clone(e,u,m.UUID.uuid(),s));u.inputs=I;const E=(G=this.outputs)==null?void 0:G.map($=>$.clone(e,u,m.UUID.uuid(),s));u.outputs=E;const O=(B=this.internalCalls)==null?void 0:B.map($=>$.clone(e,u,m.UUID.uuid(),s));return u.internalCalls=O,e==null||e.attemptAutoclose("clone-entity",this.id),u}addInternalCall(e){return this.internalCalls.find(t=>t===e)||this.internalCalls.push(e),this}createInstance(e=this.project,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"create-instance")),i={}){const s={id:i.id||m.UUID.uuid(),version:i.version||m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.VariableInstance,parent:e.toReference(),defaultValue:i.defaultValue||null,successCalls:i.successCalls||[],errorCalls:i.errorCalls||[],inputs:i.inputs||[],outputs:i.outputs||[],writesValues:i.writesValues||[],internalCalls:i.internalCalls||[],readsValue:i.readsValue||null,calledByEntry:i.calledByEntry||[],calledBySuccess:i.calledBySuccess||[],calledByError:i.calledByError||[],declaration:this.toJSON(),x:0,y:0},l=C(s,this.project);return l.setParent(e,null),l.initChildren(null),t==null||t.add(l,A.Added),e===this.project&&this.project.addVariableInstance(l),t==null||t.attemptAutoclose("create-instance",this.id),l}generateUnusedInputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"generate-unused-inputs"))){const t=[],i=[],s=[],l=[];if(this.dataType)if(this.dataType.entity){if([n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.dataType.entity.type)){const o=[...this.dataType.entity.properties];o.filter(c=>!c.getDataType(e)).forEach(c=>{const I=this.inputs.find(P=>x(P,this.project)===x(c,this.project));if(!I)return;const E=this.getMasterInputWithValueWritterFromAllInstances(I);if(!E)return;const O=Ji(E);c.setDataType(O),I.setDeclaration(c)}),o.filter(c=>!this.inputs.find(I=>{var E;return((E=I.declaration)==null?void 0:E.id)===c.id})).forEach(c=>{const I={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,parent:this.toReference(),name:null,description:null,declaration:c,defaultValue:null,index:c.index,readsValue:null},E=C(I,this.project);return E.setParent(this,e),E.initChildren(e),e==null||e.add(E,A.Added),E.suggestion=!0,this.addInput(E,e),E}),this.inputs.filter(c=>!c.declaration).forEach(c=>{const I=o.find(E=>x(E,this.project)===x(c,this.project));I&&c.setDeclaration(I)})}}else return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-inputs",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}generateUnusedOutputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"generate-unused-outputs"))){const t=[],i=[],s=[],l=[];if(this.dataType)if(this.dataType.entity)[n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.dataType.entity.type)&&[...this.dataType.entity.properties].filter(u=>!this.outputs.find(y=>y.declaration===u)).map(u=>{const y={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.OutputMap,defaultValue:null,parent:this.toReference(),declaration:u,index:u.index,writesValues:[]},c=C(y,this.project);return c.setParent(this,e),c.initChildren(e),e==null||e.add(c,A.Added),c.suggestion=!0,this.addOutput(c,e),c});else return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-outputs",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}generateUnusedInternalCalls(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"generate-unused-internal-calls"))){const t=[],i=[],s=[],l=[];if(this.dataType)if(this.dataType.entity)[n.DefinitionEntity,n.PrimitiveEntity,n.BuiltInBaseEntity].includes(this.dataType.entity.type)&&[...this.dataType.entity.getAllInteractiveMethods()].filter(u=>!this.internalCalls.find(c=>{var E,O,P,V,M;return(((E=c.declaration)==null?void 0:E.id)||((P=(O=c.initialData)==null?void 0:O.declaration)==null?void 0:P.entityId)||((M=(V=c.initialData)==null?void 0:V.declaration)==null?void 0:M.id))===u.id})).map(u=>{const y=u.createInternalCall(e,this);return e==null||e.add(y,A.Added),y.suggestion=!0,this.addInternalCall(y),y});else return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:[],updated:[],removed:[],affected:[],self:this};else return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:[],updated:[],removed:[],affected:[],self:this};return e==null||e.attemptAutoclose("generate-unused-internal-calls",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}getDataType(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"get-data-type"))){return(!this.dataType||this.dataType.inferred)&&this.inferDataTypeAndSyncInstancesInputsAndOutputs(e),this.dataType||null}getUnusedInputs(){return this.inputs.filter(e=>e.suggestion||!e.readsValue&&!e.defaultValue)}getUnusedOutputs(){return this.outputs.filter(e=>e.suggestion||!e.writesValues.length)}getUsedInputs(){return this.inputs.filter(e=>!e.suggestion&&(e.readsValue||e.defaultValue))}getUsedOutputs(){return this.outputs.filter(e=>!e.suggestion&&e.writesValues.length)}};f(Ve,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(Ve,"type",n.VariableDeclaration),f(Ve,"USER_MANAGED_PARENT_TYPES",[...dt,n.Project]),f(Ve,"PARENT_TYPES",[...Ve.USER_MANAGED_PARENT_TYPES]),f(Ve,"MUTABLE_BASE_PROPERTIES",["name","description","constant","required"]),f(Ve,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Ve,"BASE_PROPERTIES",[...Ve.MUTABLE_BASE_PROPERTIES,...Ve.INMUTABLE_BASE_PROPERTIES]),f(Ve,"MUTABLE_META_PROPERTIES",[...Ve.MUTABLE_BASE_PROPERTIES,"x","y"]),f(Ve,"INMUTABLE_META_PROPERTIES",[...Ve.INMUTABLE_BASE_PROPERTIES]),f(Ve,"META_PROPERTIES",[...Ve.MUTABLE_META_PROPERTIES,...Ve.INMUTABLE_META_PROPERTIES]),f(Ve,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry","readsValue"]),f(Ve,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","dataType"]),f(Ve,"UPSTREAM_PROPERTIES",[...Ve.MUTABLE_UPSTREAM_PROPERTIES,...Ve.INMUTABLE_UPSTREAM_PROPERTIES]),f(Ve,"MUTABLE_DOWNSTREAM_PROPERTIES",["writesValues","inputs","outputs","successCalls","errorCalls","internalCalls"]),f(Ve,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Ve,"DOWNSTREAM_PROPERTIES",[...Ve.MUTABLE_DOWNSTREAM_PROPERTIES,...Ve.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Ve,"PROPERTIES",[...Ve.META_PROPERTIES,...Ve.UPSTREAM_PROPERTIES,...Ve.DOWNSTREAM_PROPERTIES]);let qr=Ve;function A1(r){var l;const a=L5(),e=r.toJSON();a.safeParse(e).success,r.inputsDeclarations.forEach(o=>o.validate()),r.inputs.forEach(o=>o.validate()),r.outputsDeclarations.forEach(o=>o.validate()),r.outputs.forEach(o=>o.validate()),(l=r.error)==null||l.validate();const s=[...vr(r)];if(r.id==="search-person-by-id-id"){const o=de({id:`${r.id}--${F.PropertyImplementsNonAbstact}`,message:`Property "${x(r,r.project)}" with id "${r.id}" implements a non-abstract property "${x(r,r.project)}" with id "${r.id}".`,issue:null,severity:D.Error,code:F.PropertyImplementsNonAbstact,entity:r});s.push(o.error)}return He(r.errors,s)}const U7=Object.freeze(Object.defineProperty({__proto__:null,validate:A1},Symbol.toStringTag,{value:"Module"}));var b1=(r=>(r.Parent="parent",r))(b1||{});const We=class We extends at{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"x");f(this,"y");f(this,"query","");f(this,"type",n.Search);f(this,"successCalls",[]);f(this,"errorCalls",[]);f(this,"inputsDeclarations",[]);f(this,"inputs",[]);f(this,"outputsDeclarations",[]);f(this,"outputs",[]);f(this,"calledBySuccess",[]);f(this,"calledByError",[]);f(this,"calledByEntry",[]);f(this,"error",null);f(this,"parent");f(this,"errors",[]);f(this,"project");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);this.initialData=e,this.project=t,this.id=e.id,this.x=e.x,this.y=e.y,this.name=e.name,this.query=e.query,this.description=e.description}static new(){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Search,name:"",description:"",inputsDeclarations:[],outputsDeclarations:[],inputs:[],outputs:[],query:"",error:null,parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],errorCalls:[],successCalls:[],x:0,y:0}}static fromGenerationTarget(e,t){let i=t;if(e.parent){const y=_(e.parent);i=t.get(y)}const s=e.calledByEntry.map(y=>{const c=_(y);return t.get(c)}),l=e.calledBySuccess.map(y=>{const c=_(y);return t.get(c)}),o=e.calledByError.map(y=>{const c=_(y);return t.get(c)}),d={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Search,name:e.name,description:e.description,query:e.query,calledByEntry:s,calledBySuccess:l,calledByError:o,errorCalls:[],successCalls:[],inputsDeclarations:[],inputs:[],outputsDeclarations:[],outputs:[],error:null,x:0,y:0,parent:i},u=C(d,t);return u.setParent(i,null),u.initChildren(null),u}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=At(i,{parent:{list:!1,types:[...dt,n.Project],optional:!0}},t);return i=l.modifiedData,s.push(...l.errors,...ut(i)),{errors:s,modifiedData:i}}get resultsAsList(){const e=this.outputsDeclarations[0];if(e){const t=e.getDataType(null);return t?t.isList===!0:!0}return!0}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on a callable entity, is its scope. It scope is auto-calculated implicitly by the its caller.
110
110
  If an entity is called by another, they must be in the same scope, which means they have the same parent.
111
- You shouldn't have to manually update a 'parent' property. The equivalent result is to change its callers, the value writters of its inputs, or the value readers of its outputs.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],i=[],s=[];return Object.values(this.detachedDependents).forEach(l=>{const o=l.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),i.push(...o.removed),s.push(...o.affected)}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new We(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.inputsDeclarations=this.inputsDeclarations,e.outputsDeclarations=this.outputsDeclarations,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.calledByEntry=this.calledByEntry,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[I,E]of c.knownVersions)u.set(I,E);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new We(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.error=o.error,this.inputsDeclarations=o.inputsDeclarations,this.outputsDeclarations=o.outputsDeclarations,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.calledByEntry=o.calledByEntry,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);return this.initialData.calledByEntry.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];this.initialized=!0,this.captureVersion();const{updated:o,added:d,removed:u}=this.syncInputMaps(e);return t.push(...o),i.push(...d),s.push(...u),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.parent===this.project&&this.project.addSearch(this),this.successCalls.forEach(o=>{o.addSuccessCaller(this,e),t.push(o)}),this.errorCalls.forEach(o=>{o.addErrorCaller(this,e),t.push(o)}),this.calledByEntry.forEach(o=>{o.addCall(this,e),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this,e),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this,e),t.push(o)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-input"))){const i=this.inputs.findIndex(l=>l.id===e.id);i>-1&&(this.inputs.splice(i,1),t==null||t.add(this,A.Affected));const s=this.inputsDeclarations.findIndex(l=>{var o;return l.id===((o=e.declaration)==null?void 0:o.id)});return s>-1&&(this.inputsDeclarations.splice(s,1),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("remove-input",this.id),this}addInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-input"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input",this.id),this):(this.inputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-input",this.id),this)}addInputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-input-declaration"))){return this.inputsDeclarations.includes(e)?(t==null||t.attemptAutoclose("add-input-declaration",this.id),this):(this.inputsDeclarations.push(e),this.syncInputMaps(t),t==null||t.attemptAutoclose("add-input-declaration",this.id),this)}removeInputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-input-declaration"))){const i=this.inputsDeclarations.findIndex(s=>s.id===e.id);return i>-1&&(this.inputsDeclarations.splice(i,1),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("remove-input-declaration",this.id),this}addOutputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-output-declaration"))){return this.outputsDeclarations.includes(e)?(t==null||t.attemptAutoclose("add-output-declaration",this.id),this):(this.outputsDeclarations.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-output-declaration",this.id),this)}removeOutputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-output-declaration"))){const i=this.outputsDeclarations.findIndex(s=>s.id===e.id);return i>-1&&(this.outputsDeclarations.splice(i,1),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("remove-output-declaration",this.id),this}addOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-output"))){return this.outputs.includes(e)?(t==null||t.attemptAutoclose("add-output",this.id),this):(this.outputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-output",this.id),this)}removeOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-output"))){const i=this.outputs.findIndex(s=>s.id===e.id);return i>-1&&(this.outputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-output",this.id),this}addSuccessCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,A.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,A.Updated),i&&K(this,t),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,A.Updated),i&&K(this,t),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}addErrorCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-call")),i=!1){return this.errorCalls.find(s=>s.id===e.id)||(this.errorCalls.push(e),i&&K(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-call")),i=!1){return this.successCalls.find(s=>s.id===e.id)||(this.successCalls.push(e),i&&K(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-success-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-call")),i=!1){const s=this.successCalls.findIndex(o=>o.id===e.id);s>-1&&(this.successCalls.splice(s,1),t==null||t.add(this,A.Affected));const l=this.errorCalls.findIndex(o=>o.id===e.id);return l>-1&&(this.errorCalls.splice(l,1),t==null||t.add(this,A.Affected)),i&&K(this,t),t==null||t.attemptAutoclose("remove-call",this.id),this}removeCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected)),!0):!1),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected)),!0):!1),i&&K(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.successCalls=this.initialData.successCalls.map(t=>{const i=C(t,this.project);return[n.BreakStatement,n.ContinueStatement].includes(i.type)?(i.setParent(this.parent.parent,null),i.initChildren(e)):i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e)),i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=C(t,this.project);return i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type)?(i.setParent(this.parent.parent,null),i.initChildren(e)):i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e)),i}),this.inputsDeclarations=this.initialData.inputsDeclarations.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.inputs=this.initialData.inputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.outputsDeclarations=this.initialData.outputsDeclarations.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.outputs=this.initialData.outputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.initialData.error&&(this.error=C(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,this.name=e.name||s.name,this.description=e.description||s.description,e.query!==void 0&&(this.query=e.query),super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=g,...t){return await We.repository.APILoad(this.id,...t),this}async APICreate(e=g,...t){return await We.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=g,...t){return await We.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=g,...t){return await We.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=g,...t){return await We.repository.APIClone(this.id,...t),this}async APILoadVersion(e=g,t,...i){return await We.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:y,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...y),l.push(...c)}),this.inputs.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.inputsDeclarations.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.outputs.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.outputsDeclarations.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.error){const{updated:d,removed:u}=this.error.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}return this.successCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),this.errorCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),e||this.calledBy.forEach(d=>{i.push(d),d.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.inputsDeclarations.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.inputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.outputsDeclarations.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.successCalls.forEach(o=>{i.push(o),o.addSuccessCaller(this,e)}),this.errorCalls.forEach(o=>{i.push(o),o.addErrorCaller(this,e)}),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.successCalls.flatMap(i=>i.toFlat(e)),...this.errorCalls.flatMap(i=>i.toFlat(e)),...this.inputs.flatMap(i=>i.toFlat(e)),...this.inputsDeclarations.flatMap(i=>i.toFlat(e)),...this.outputs.flatMap(i=>i.toFlat(e)),...this.outputsDeclarations.flatMap(i=>i.toFlat(e)),...this.calledBy.flatMap(i=>i.toFlat(e)),...this.error?this.error.toFlat(e):[]])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.successCalls.flatMap(i=>i.toFlatIds(e)),...this.errorCalls.flatMap(i=>i.toFlatIds(e)),...this.inputs.flatMap(i=>i.toFlatIds(e)),...this.inputsDeclarations.flatMap(i=>i.toFlatIds(e)),...this.outputs.flatMap(i=>i.toFlatIds(e)),...this.outputsDeclarations.flatMap(i=>i.toFlatIds(e)),...this.calledBy.flatMap(i=>i.toFlatIds(e)),...this.error?this.error.toFlatIds(e):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,query:this.query,x:this.x,y:this.y,type:this.type,name:this.name}}toJSON(e=new Set){var t;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,query:this.query,description:this.description,x:this.x,y:this.y,successCalls:this.successCalls.map(i=>i.toJSON()),errorCalls:this.errorCalls.map(i=>i.toJSON()),calledBySuccess:this.calledBySuccess.map(i=>i.toReference()),calledByError:this.calledByError.map(i=>i.toReference()),calledByEntry:this.calledByEntry.map(i=>i.toReference()),inputsDeclarations:this.inputsDeclarations.map(i=>i.toJSON()),inputs:this.inputs.map(i=>i.toJSON()),outputsDeclarations:this.outputsDeclarations.map(i=>i.toJSON()),outputs:this.outputs.map(i=>i.toJSON()),error:((t=this.error)==null?void 0:t.toJSON())||null,parent:this.parent.toReference()})}toJSONClone(e=q){var i,s,l,o,d,u;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Search,name:this.name,query:this.query,description:this.description,x:this.x,y:this.y,successCalls:this.successCalls.map(y=>y.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(y=>y.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(y=>y.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(y=>y.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(y=>y.toReference({seenEntityMaps:e.seenEntityMaps})),inputsDeclarations:this.inputsDeclarations.map(y=>y.toJSONClone({...e,newId:null})),inputs:this.inputs.map(y=>y.toJSONClone({...e,newId:null})),outputsDeclarations:this.outputsDeclarations.map(y=>y.toJSONClone({...e,newId:null})),outputs:this.outputs.map(y=>y.toJSONClone({...e,newId:null})),error:((u=this.error)==null?void 0:u.toJSONClone({...e,newId:null}))||null,parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,query:this.query,x:this.x,y:this.y,inputs:this.inputs.map(s=>s.toReference(e)),inputsDeclarations:this.inputsDeclarations.map(s=>s.toReference(e)),outputs:this.outputs.map(s=>s.toReference(e)),outputsDeclarations:this.outputsDeclarations.map(s=>s.toReference(e)),successCalls:this.successCalls.map(s=>s.toReference(e)),errorCalls:this.errorCalls.map(s=>s.toReference(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference(e)),calledByError:this.calledByError.map(s=>s.toReference(e)),calledByEntry:this.calledByEntry.map(s=>s.toReference(e)),error:this.error?this.error.toReference(e):null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.successCalls.flatMap(i=>i.toFlatJSON(e)),...this.errorCalls.flatMap(i=>i.toFlatJSON(e)),...this.inputs.flatMap(i=>i.toFlatJSON(e)),...this.inputsDeclarations.flatMap(i=>i.toFlatJSON(e)),...this.outputs.flatMap(i=>i.toFlatJSON(e)),...this.outputsDeclarations.flatMap(i=>i.toFlatJSON(e)),...this.calledBy.flatMap(i=>i.toFlatJSON(e)),...this.error?this.error.toFlatJSON(e):[]])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,name:this.name,description:this.description,type:this.type,query:this.query,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),parent:e}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.successCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.inputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.inputsDeclarations.flatMap(i=>i.toFlatGenerationTarget(e)),...this.outputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.outputsDeclarations.flatMap(i=>i.toFlatGenerationTarget(e)),...this.error?this.error.toFlatGenerationTarget(e):[]])}clearErrors(){var e;return this.errors=[],this.inputsDeclarations.forEach(t=>t.clearErrors()),this.inputs.forEach(t=>t.clearErrors()),this.outputs.forEach(t=>t.clearErrors()),this.successCalls.forEach(t=>t.clearErrors()),this.errorCalls.forEach(t=>t.clearErrors()),(e=this.error)==null||e.clearErrors(),this}validate(){const e=A1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.inputsDeclarations.flatMap(t=>t.getErrors()),...this.inputs.flatMap(t=>t.getErrors()),...this.outputsDeclarations.flatMap(t=>t.getErrors()),...this.outputs.flatMap(t=>t.getErrors()),...this.error?this.error.getErrors():[]]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var V,M,G,B;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[];const u=d.split("-id"),y=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=ct(o,l);t?c.setParent(t,null):c.setParent(this.parent,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,A.Added);const I=(V=this.inputsDeclarations)==null?void 0:V.map(($,Z)=>$.clone(e,this,y+"-input-declaration-"+Z+"-id",s));c.inputsDeclarations=I;const E=(M=this.outputsDeclarations)==null?void 0:M.map(($,Z)=>$.clone(e,this,y+"-output-declaration-"+Z+"-id",s));c.outputsDeclarations=E;const O=(G=this.inputs)==null?void 0:G.map(($,Z)=>$.clone(e,c,y+"-input-map-"+Z+"-id",s));c.inputs=O;const P=(B=this.outputs)==null?void 0:B.map(($,Z)=>$.clone(e,c,y+"-output-map-"+Z+"-id",s));return c.outputs=P,this.error&&(c.error=this.error.clone(e,c,y+"-error-map-id",s)),e==null||e.attemptAutoclose("clone-entity",this.id),c}syncInputMaps(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-input-maps"))){const t=[],i=[],s=[],l=[];return this.inputsDeclarations.forEach(o=>{if(!this.inputs.find(u=>{var y;return((y=u.declaration)==null?void 0:y.id)===o.id})){const u={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,declaration:o.toJSON(),readsValue:null,defaultValue:null,index:this.inputs.length,name:null,description:null,parent:this.toReference()},y=C(u,this.project);y.setParent(this,e),y.initChildren(e),e==null||e.add(y,A.Added),y.addSelfToProject(e),t.push(this),i.push(y)}}),this.inputs.forEach(o=>{if(!this.inputsDeclarations.find(u=>{var y;return u.id===((y=o.declaration)==null?void 0:y.id)})){const{updated:u,removed:y}=o.remove({ignoreUpstream:!1},e);u.push(...u),s.push(...y)}}),e==null||e.attemptAutoclose("sync-input-maps",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}};f(We,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(We,"type",n.Search),f(We,"USER_MANAGED_PARENT_TYPES",[...dt,n.Project]),f(We,"PARENT_TYPES",[...We.USER_MANAGED_PARENT_TYPES]),f(We,"MUTABLE_BASE_PROPERTIES",["name","description","query"]),f(We,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(We,"BASE_PROPERTIES",[...We.MUTABLE_BASE_PROPERTIES,...We.INMUTABLE_BASE_PROPERTIES]),f(We,"MUTABLE_META_PROPERTIES",[...We.MUTABLE_BASE_PROPERTIES,"x","y"]),f(We,"INMUTABLE_META_PROPERTIES",[...We.INMUTABLE_BASE_PROPERTIES]),f(We,"META_PROPERTIES",[...We.MUTABLE_META_PROPERTIES,...We.INMUTABLE_META_PROPERTIES]),f(We,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),f(We,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),f(We,"UPSTREAM_PROPERTIES",[...We.MUTABLE_UPSTREAM_PROPERTIES,...We.INMUTABLE_UPSTREAM_PROPERTIES]),f(We,"MUTABLE_DOWNSTREAM_PROPERTIES",["successCalls","errorCalls","inputsDeclarations","inputs","outputsDeclarations","outputs","error"]),f(We,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(We,"DOWNSTREAM_PROPERTIES",[...We.MUTABLE_DOWNSTREAM_PROPERTIES,...We.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(We,"PROPERTIES",[...ai.META_PROPERTIES,...ai.UPSTREAM_PROPERTIES,...ai.DOWNSTREAM_PROPERTIES]);let Jr=We;function R1(r){const a=OS(),e=r.toJSON();a.safeParse(e).success,r.functions.forEach(s=>s.validate()),r.events.forEach(s=>s.validate());const i=[];return He(r.errors,i)}const gq=Object.freeze(Object.defineProperty({__proto__:null,validate:R1},Symbol.toStringTag,{value:"Module"})),Se=class Se extends at{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"x");f(this,"y");f(this,"type",n.InstalledProject);f(this,"implements");f(this,"functions",[]);f(this,"events",[]);f(this,"parent");f(this,"errors",[]);f(this,"project");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description,this.x=e.x,this.y=e.y,this.implements=e.implements}static new(){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InstalledProject,name:"",description:"",implements:null,functions:[],events:[],x:0,y:0,parent:null}}static fromGenerationTarget(e,t){const i=t,s={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,type:n.InstalledProject,description:e.description,functions:[],events:[],implements:{entityId:e.implements,version:m.UUID.uuid(),entityType:n.Project,type:n.GenericReference,id:m.UUID.uuid()},x:0,y:0,parent:i},l=C(s,t);return l.setParent(i,null),l.initChildren(null),l}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[];return s.push(...ut(i)),{errors:s,modifiedData:i}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on an installed project, must be the root project as it is a globally declared entity.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],i=[],s=[];return Object.values(this.detachedDependents).forEach(l=>{const o=l.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),i.push(...o.removed),s.push(...o.affected)}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){return this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Se(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.functions=this.functions,e.events=this.events,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[I,E]of c.knownVersions)u.set(I,E);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Se(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.functions=o.functions,this.events=o.events,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.project.addInstalledProject(this),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.functions=this.initialData.functions.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.events=this.initialData.events.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=g,...t){return await Se.repository.APILoad(this.id,...t),this}async APICreate(e=g,...t){return await Se.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=g,...t){return await Se.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=g,...t){return await Se.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=g,...t){return await Se.repository.APIClone(this.id,...t),this}async APILoadVersion(e=g,t,...i){return await Se.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];return t!=null&&t.hasRemoved(this.id)?(t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:y,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...y),l.push(...c)}),this.functions.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!1},t);i.push(...u),s.push(...y)}),this.events.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!1},t);i.push(...u),s.push(...y)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:p(o),self:this})}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.functions.forEach(t=>{t.restore({},e)}),this.events.forEach(t=>{t.restore({},e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.functions.flatMap(i=>i.toFlat(e)),...this.events.flatMap(i=>i.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.functions.flatMap(i=>i.toFlatIds(e)),...this.events.flatMap(i=>i.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,x:this.x,y:this.y,type:this.type,name:this.name}}toJSON(e=new Set){return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,implements:this.implements,functions:this.functions.map(t=>t.toJSON(e)),events:this.events.map(t=>t.toJSON(e)),parent:this.parent.toReference(),x:this.x,y:this.y})}toJSONClone(e=q){var i,s,l,o,d;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,implements:this.implements,functions:this.functions.map(u=>u.toJSONClone({...e,newId:null})),events:this.events.map(u=>u.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps}),x:this.x,y:this.y})}toReference(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,x:this.x,y:this.y,implements:this.implements,functions:this.functions.map(s=>s.toReference(e)),events:this.events.map(s=>s.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.functions.flatMap(i=>i.toFlatJSON(e)),...this.events.flatMap(i=>i.toFlatJSON(e))])}toGenerationTarget(){return{id:this.id,name:this.name,description:this.description,type:this.type,implements:this.implements.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.functions.flatMap(i=>i.toFlatGenerationTarget(e)),...this.events.flatMap(i=>i.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.functions.forEach(e=>e.clearErrors()),this.events.forEach(e=>e.clearErrors()),this}validate(){const e=R1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.functions.flatMap(t=>t.getErrors()),...this.events.flatMap(t=>t.getErrors())]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var O,P;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.functions=[],o.events=[];const u=d.split("-id"),y=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=ct(o,l);t&&c.setParent(t,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,A.Added);const I=(O=this.functions)==null?void 0:O.map((V,M)=>V.clone(e,c,y+"-exported-function-declaration-"+M+"-id",s));c.functions=I;const E=(P=this.events)==null?void 0:P.map((V,M)=>V.clone(e,c,y+"-exported-event-"+M+"-id",s));return c.events=E,e==null||e.attemptAutoclose("clone-entity",this.id),c}};f(Se,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(Se,"type",n.InstalledProject),f(Se,"USER_MANAGED_PARENT_TYPES",[n.Project]),f(Se,"PARENT_TYPES",[...Se.USER_MANAGED_PARENT_TYPES]),f(Se,"MUTABLE_BASE_PROPERTIES",[]),f(Se,"INMUTABLE_BASE_PROPERTIES",["id","version","name","description","type","createdAt","author","previousVersion"]),f(Se,"BASE_PROPERTIES",[...Se.MUTABLE_BASE_PROPERTIES,...Se.INMUTABLE_BASE_PROPERTIES]),f(Se,"MUTABLE_META_PROPERTIES",["x","y"]),f(Se,"INMUTABLE_META_PROPERTIES",[...Se.INMUTABLE_BASE_PROPERTIES]),f(Se,"META_PROPERTIES",[...Se.MUTABLE_META_PROPERTIES,...Se.INMUTABLE_META_PROPERTIES]),f(Se,"MUTABLE_UPSTREAM_PROPERTIES",[]),f(Se,"INMUTABLE_UPSTREAM_PROPERTIES",["implements","parent"]),f(Se,"UPSTREAM_PROPERTIES",[...Se.MUTABLE_UPSTREAM_PROPERTIES,...Se.INMUTABLE_UPSTREAM_PROPERTIES]),f(Se,"MUTABLE_DOWNSTREAM_PROPERTIES",["functions","events"]),f(Se,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Se,"DOWNSTREAM_PROPERTIES",[...Se.MUTABLE_DOWNSTREAM_PROPERTIES,...Se.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Se,"PROPERTIES",[...Se.META_PROPERTIES,...Se.UPSTREAM_PROPERTIES,...Se.DOWNSTREAM_PROPERTIES]);let Wr=Se;function D1(r){var o;const a=$5(),e=r.toJSON();a.safeParse(e).success,r.inputs.forEach(d=>d.validate()),r.outputs.forEach(d=>d.validate()),(o=r.error)==null||o.validate();const i=vr(r),s=O1(r),l=[...i,...s];return He(r.errors,l)}function O1(r){const a=[],e=Ml(r.parent,null),t=e==null?void 0:e.entity;if(!t)a.push(de({id:`${r.id}--${j.InternalCallParentMissingDataType}`,code:j.InternalCallParentMissingDataType,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", belongs to a variable whose data type entity doesn't contain its declaration method (function-declaration) its id "${r.declaration}".`,issue:null,entity:r}).error);else if(![n.DefinitionEntity,n.BuiltInBaseEntity,n.PrimitiveEntity].includes(t.type))a.push(de({id:`${r.id}--${j.InternalCallParentDeclarationEntityInvalidType}`,code:j.InternalCallParentDeclarationEntityInvalidType,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", belongs to a variable whose data type 'entity' is not a definition entity, built-in base entity or primitive entity.
111
+ You shouldn't have to manually update a 'parent' property. The equivalent result is to change its callers, the value writters of its inputs, or the value readers of its outputs.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],i=[],s=[];return Object.values(this.detachedDependents).forEach(l=>{const o=l.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),i.push(...o.removed),s.push(...o.affected)}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="parent"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new We(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.inputsDeclarations=this.inputsDeclarations,e.outputsDeclarations=this.outputsDeclarations,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.calledByEntry=this.calledByEntry,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[I,E]of c.knownVersions)u.set(I,E);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new We(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.error=o.error,this.inputsDeclarations=o.inputsDeclarations,this.outputsDeclarations=o.outputsDeclarations,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.calledByEntry=o.calledByEntry,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);return this.initialData.calledByEntry.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];this.initialized=!0,this.captureVersion();const{updated:o,added:d,removed:u}=this.syncInputMaps(e);return t.push(...o),i.push(...d),s.push(...u),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.parent===this.project&&this.project.addSearch(this),this.successCalls.forEach(o=>{o.addSuccessCaller(this,e),t.push(o)}),this.errorCalls.forEach(o=>{o.addErrorCaller(this,e),t.push(o)}),this.calledByEntry.forEach(o=>{o.addCall(this,e),t.push(o)}),this.calledBySuccess.forEach(o=>{o.addSuccessCall(this,e),t.push(o)}),this.calledByError.forEach(o=>{o.addErrorCall(this,e),t.push(o)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-input"))){const i=this.inputs.findIndex(l=>l.id===e.id);i>-1&&(this.inputs.splice(i,1),t==null||t.add(this,A.Affected));const s=this.inputsDeclarations.findIndex(l=>{var o;return l.id===((o=e.declaration)==null?void 0:o.id)});return s>-1&&(this.inputsDeclarations.splice(s,1),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("remove-input",this.id),this}addInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-input"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input",this.id),this):(this.inputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-input",this.id),this)}addInputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-input-declaration"))){return this.inputsDeclarations.includes(e)?(t==null||t.attemptAutoclose("add-input-declaration",this.id),this):(this.inputsDeclarations.push(e),this.syncInputMaps(t),t==null||t.attemptAutoclose("add-input-declaration",this.id),this)}removeInputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-input-declaration"))){const i=this.inputsDeclarations.findIndex(s=>s.id===e.id);return i>-1&&(this.inputsDeclarations.splice(i,1),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("remove-input-declaration",this.id),this}addOutputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-output-declaration"))){return this.outputsDeclarations.includes(e)?(t==null||t.attemptAutoclose("add-output-declaration",this.id),this):(this.outputsDeclarations.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-output-declaration",this.id),this)}removeOutputDeclaration(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-output-declaration"))){const i=this.outputsDeclarations.findIndex(s=>s.id===e.id);return i>-1&&(this.outputsDeclarations.splice(i,1),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("remove-output-declaration",this.id),this}addOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-output"))){return this.outputs.includes(e)?(t==null||t.attemptAutoclose("add-output",this.id),this):(this.outputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-output",this.id),this)}removeOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-output"))){const i=this.outputs.findIndex(s=>s.id===e.id);return i>-1&&(this.outputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-output",this.id),this}addSuccessCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,A.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,A.Updated),i&&K(this,t),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,A.Updated),i&&K(this,t),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}addErrorCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-call")),i=!1){return this.errorCalls.find(s=>s.id===e.id)||(this.errorCalls.push(e),i&&K(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-call")),i=!1){return this.successCalls.find(s=>s.id===e.id)||(this.successCalls.push(e),i&&K(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-success-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-call")),i=!1){const s=this.successCalls.findIndex(o=>o.id===e.id);s>-1&&(this.successCalls.splice(s,1),t==null||t.add(this,A.Affected));const l=this.errorCalls.findIndex(o=>o.id===e.id);return l>-1&&(this.errorCalls.splice(l,1),t==null||t.add(this,A.Affected)),i&&K(this,t),t==null||t.attemptAutoclose("remove-call",this.id),this}removeCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected)),!0):!1),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected)),!0):!1),i&&K(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.successCalls=this.initialData.successCalls.map(t=>{const i=C(t,this.project);return[n.BreakStatement,n.ContinueStatement].includes(i.type)?(i.setParent(this.parent.parent,null),i.initChildren(e)):i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e)),i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=C(t,this.project);return i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type)?(i.setParent(this.parent.parent,null),i.initChildren(e)):i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e)),i}),this.inputsDeclarations=this.initialData.inputsDeclarations.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.inputs=this.initialData.inputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.outputsDeclarations=this.initialData.outputsDeclarations.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.outputs=this.initialData.outputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.initialData.error&&(this.error=C(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,this.name=e.name||s.name,this.description=e.description||s.description,e.query!==void 0&&(this.query=e.query),super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=g,...t){return await We.repository.APILoad(this.id,...t),this}async APICreate(e=g,...t){return await We.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=g,...t){return await We.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=g,...t){return await We.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=g,...t){return await We.repository.APIClone(this.id,...t),this}async APILoadVersion(e=g,t,...i){return await We.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:y,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...y),l.push(...c)}),this.inputs.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.inputsDeclarations.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.outputs.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.outputsDeclarations.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.error){const{updated:d,removed:u}=this.error.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}return this.successCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),this.errorCalls.forEach(d=>{i.push(d),d.removeCaller(this,t)}),e||this.calledBy.forEach(d=>{i.push(d),d.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.inputsDeclarations.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.inputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.outputsDeclarations.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.successCalls.forEach(o=>{i.push(o),o.addSuccessCaller(this,e)}),this.errorCalls.forEach(o=>{i.push(o),o.addErrorCaller(this,e)}),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.successCalls.flatMap(i=>i.toFlat(e)),...this.errorCalls.flatMap(i=>i.toFlat(e)),...this.inputs.flatMap(i=>i.toFlat(e)),...this.inputsDeclarations.flatMap(i=>i.toFlat(e)),...this.outputs.flatMap(i=>i.toFlat(e)),...this.outputsDeclarations.flatMap(i=>i.toFlat(e)),...this.calledBy.flatMap(i=>i.toFlat(e)),...this.error?this.error.toFlat(e):[]])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.successCalls.flatMap(i=>i.toFlatIds(e)),...this.errorCalls.flatMap(i=>i.toFlatIds(e)),...this.inputs.flatMap(i=>i.toFlatIds(e)),...this.inputsDeclarations.flatMap(i=>i.toFlatIds(e)),...this.outputs.flatMap(i=>i.toFlatIds(e)),...this.outputsDeclarations.flatMap(i=>i.toFlatIds(e)),...this.calledBy.flatMap(i=>i.toFlatIds(e)),...this.error?this.error.toFlatIds(e):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,query:this.query,x:this.x,y:this.y,type:this.type,name:this.name}}toJSON(e=new Set){var t;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,query:this.query,description:this.description,x:this.x,y:this.y,successCalls:this.successCalls.map(i=>i.toJSON()),errorCalls:this.errorCalls.map(i=>i.toJSON()),calledBySuccess:this.calledBySuccess.map(i=>i.toReference()),calledByError:this.calledByError.map(i=>i.toReference()),calledByEntry:this.calledByEntry.map(i=>i.toReference()),inputsDeclarations:this.inputsDeclarations.map(i=>i.toJSON()),inputs:this.inputs.map(i=>i.toJSON()),outputsDeclarations:this.outputsDeclarations.map(i=>i.toJSON()),outputs:this.outputs.map(i=>i.toJSON()),error:((t=this.error)==null?void 0:t.toJSON())||null,parent:this.parent.toReference()})}toJSONClone(e=q){var i,s,l,o,d,u;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.Search,name:this.name,query:this.query,description:this.description,x:this.x,y:this.y,successCalls:this.successCalls.map(y=>y.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(y=>y.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(y=>y.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(y=>y.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(y=>y.toReference({seenEntityMaps:e.seenEntityMaps})),inputsDeclarations:this.inputsDeclarations.map(y=>y.toJSONClone({...e,newId:null})),inputs:this.inputs.map(y=>y.toJSONClone({...e,newId:null})),outputsDeclarations:this.outputsDeclarations.map(y=>y.toJSONClone({...e,newId:null})),outputs:this.outputs.map(y=>y.toJSONClone({...e,newId:null})),error:((u=this.error)==null?void 0:u.toJSONClone({...e,newId:null}))||null,parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,query:this.query,x:this.x,y:this.y,inputs:this.inputs.map(s=>s.toReference(e)),inputsDeclarations:this.inputsDeclarations.map(s=>s.toReference(e)),outputs:this.outputs.map(s=>s.toReference(e)),outputsDeclarations:this.outputsDeclarations.map(s=>s.toReference(e)),successCalls:this.successCalls.map(s=>s.toReference(e)),errorCalls:this.errorCalls.map(s=>s.toReference(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference(e)),calledByError:this.calledByError.map(s=>s.toReference(e)),calledByEntry:this.calledByEntry.map(s=>s.toReference(e)),error:this.error?this.error.toReference(e):null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.successCalls.flatMap(i=>i.toFlatJSON(e)),...this.errorCalls.flatMap(i=>i.toFlatJSON(e)),...this.inputs.flatMap(i=>i.toFlatJSON(e)),...this.inputsDeclarations.flatMap(i=>i.toFlatJSON(e)),...this.outputs.flatMap(i=>i.toFlatJSON(e)),...this.outputsDeclarations.flatMap(i=>i.toFlatJSON(e)),...this.calledBy.flatMap(i=>i.toFlatJSON(e)),...this.error?this.error.toFlatJSON(e):[]])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,name:this.name,description:this.description,type:this.type,query:this.query,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),parent:e}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.successCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.inputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.inputsDeclarations.flatMap(i=>i.toFlatGenerationTarget(e)),...this.outputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.outputsDeclarations.flatMap(i=>i.toFlatGenerationTarget(e)),...this.error?this.error.toFlatGenerationTarget(e):[]])}clearErrors(){var e;return this.errors=[],this.inputsDeclarations.forEach(t=>t.clearErrors()),this.inputs.forEach(t=>t.clearErrors()),this.outputs.forEach(t=>t.clearErrors()),this.successCalls.forEach(t=>t.clearErrors()),this.errorCalls.forEach(t=>t.clearErrors()),(e=this.error)==null||e.clearErrors(),this}validate(){const e=A1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.inputsDeclarations.flatMap(t=>t.getErrors()),...this.inputs.flatMap(t=>t.getErrors()),...this.outputsDeclarations.flatMap(t=>t.getErrors()),...this.outputs.flatMap(t=>t.getErrors()),...this.error?this.error.getErrors():[]]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var V,M,G,B;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[];const u=d.split("-id"),y=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=ct(o,l);t?c.setParent(t,null):c.setParent(this.parent,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,A.Added);const I=(V=this.inputsDeclarations)==null?void 0:V.map(($,Z)=>$.clone(e,this,y+"-input-declaration-"+Z+"-id",s));c.inputsDeclarations=I;const E=(M=this.outputsDeclarations)==null?void 0:M.map(($,Z)=>$.clone(e,this,y+"-output-declaration-"+Z+"-id",s));c.outputsDeclarations=E;const O=(G=this.inputs)==null?void 0:G.map(($,Z)=>$.clone(e,c,y+"-input-map-"+Z+"-id",s));c.inputs=O;const P=(B=this.outputs)==null?void 0:B.map(($,Z)=>$.clone(e,c,y+"-output-map-"+Z+"-id",s));return c.outputs=P,this.error&&(c.error=this.error.clone(e,c,y+"-error-map-id",s)),e==null||e.attemptAutoclose("clone-entity",this.id),c}syncInputMaps(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-input-maps"))){const t=[],i=[],s=[],l=[];return this.inputsDeclarations.forEach(o=>{if(!this.inputs.find(u=>{var y;return((y=u.declaration)==null?void 0:y.id)===o.id})){const u={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,declaration:o.toJSON(),readsValue:null,defaultValue:null,index:this.inputs.length,name:null,description:null,parent:this.toReference()},y=C(u,this.project);y.setParent(this,e),y.initChildren(e),e==null||e.add(y,A.Added),y.addSelfToProject(e),t.push(this),i.push(y)}}),this.inputs.forEach(o=>{if(!this.inputsDeclarations.find(u=>{var y;return u.id===((y=o.declaration)==null?void 0:y.id)})){const{updated:u,removed:y}=o.remove({ignoreUpstream:!1},e);u.push(...u),s.push(...y)}}),e==null||e.attemptAutoclose("sync-input-maps",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}};f(We,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(We,"type",n.Search),f(We,"USER_MANAGED_PARENT_TYPES",[...dt,n.Project]),f(We,"PARENT_TYPES",[...We.USER_MANAGED_PARENT_TYPES]),f(We,"MUTABLE_BASE_PROPERTIES",["name","description","query"]),f(We,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(We,"BASE_PROPERTIES",[...We.MUTABLE_BASE_PROPERTIES,...We.INMUTABLE_BASE_PROPERTIES]),f(We,"MUTABLE_META_PROPERTIES",[...We.MUTABLE_BASE_PROPERTIES,"x","y"]),f(We,"INMUTABLE_META_PROPERTIES",[...We.INMUTABLE_BASE_PROPERTIES]),f(We,"META_PROPERTIES",[...We.MUTABLE_META_PROPERTIES,...We.INMUTABLE_META_PROPERTIES]),f(We,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),f(We,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),f(We,"UPSTREAM_PROPERTIES",[...We.MUTABLE_UPSTREAM_PROPERTIES,...We.INMUTABLE_UPSTREAM_PROPERTIES]),f(We,"MUTABLE_DOWNSTREAM_PROPERTIES",["successCalls","errorCalls","inputsDeclarations","inputs","outputsDeclarations","outputs","error"]),f(We,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(We,"DOWNSTREAM_PROPERTIES",[...We.MUTABLE_DOWNSTREAM_PROPERTIES,...We.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(We,"PROPERTIES",[...ai.META_PROPERTIES,...ai.UPSTREAM_PROPERTIES,...ai.DOWNSTREAM_PROPERTIES]);let Jr=We;function R1(r){const a=OS(),e=r.toJSON();a.safeParse(e).success,r.functions.forEach(s=>s.validate()),r.events.forEach(s=>s.validate());const i=[];return He(r.errors,i)}const g7=Object.freeze(Object.defineProperty({__proto__:null,validate:R1},Symbol.toStringTag,{value:"Module"})),Se=class Se extends at{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"x");f(this,"y");f(this,"type",n.InstalledProject);f(this,"implements");f(this,"functions",[]);f(this,"events",[]);f(this,"parent");f(this,"errors",[]);f(this,"project");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description,this.x=e.x,this.y=e.y,this.implements=e.implements}static new(){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InstalledProject,name:"",description:"",implements:null,functions:[],events:[],x:0,y:0,parent:null}}static fromGenerationTarget(e,t){const i=t,s={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,type:n.InstalledProject,description:e.description,functions:[],events:[],implements:{entityId:e.implements,version:m.UUID.uuid(),entityType:n.Project,type:n.GenericReference,id:m.UUID.uuid()},x:0,y:0,parent:i},l=C(s,t);return l.setParent(i,null),l.initChildren(null),l}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[];return s.push(...ut(i)),{errors:s,modifiedData:i}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on an installed project, must be the root project as it is a globally declared entity.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],i=[],s=[];return Object.values(this.detachedDependents).forEach(l=>{const o=l.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),i.push(...o.removed),s.push(...o.affected)}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){return this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Se(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.functions=this.functions,e.events=this.events,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[I,E]of c.knownVersions)u.set(I,E);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Se(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.functions=o.functions,this.events=o.events,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.project.addInstalledProject(this),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.functions=this.initialData.functions.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.events=this.initialData.events.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=g,...t){return await Se.repository.APILoad(this.id,...t),this}async APICreate(e=g,...t){return await Se.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=g,...t){return await Se.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=g,...t){return await Se.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=g,...t){return await Se.repository.APIClone(this.id,...t),this}async APILoadVersion(e=g,t,...i){return await Se.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];return t!=null&&t.hasRemoved(this.id)?(t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:y,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...y),l.push(...c)}),this.functions.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!1},t);i.push(...u),s.push(...y)}),this.events.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!1},t);i.push(...u),s.push(...y)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:p(o),self:this})}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.functions.forEach(t=>{t.restore({},e)}),this.events.forEach(t=>{t.restore({},e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.functions.flatMap(i=>i.toFlat(e)),...this.events.flatMap(i=>i.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.functions.flatMap(i=>i.toFlatIds(e)),...this.events.flatMap(i=>i.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,x:this.x,y:this.y,type:this.type,name:this.name}}toJSON(e=new Set){return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,implements:this.implements,functions:this.functions.map(t=>t.toJSON(e)),events:this.events.map(t=>t.toJSON(e)),parent:this.parent.toReference(),x:this.x,y:this.y})}toJSONClone(e=q){var i,s,l,o,d;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,implements:this.implements,functions:this.functions.map(u=>u.toJSONClone({...e,newId:null})),events:this.events.map(u=>u.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps}),x:this.x,y:this.y})}toReference(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,x:this.x,y:this.y,implements:this.implements,functions:this.functions.map(s=>s.toReference(e)),events:this.events.map(s=>s.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.functions.flatMap(i=>i.toFlatJSON(e)),...this.events.flatMap(i=>i.toFlatJSON(e))])}toGenerationTarget(){return{id:this.id,name:this.name,description:this.description,type:this.type,implements:this.implements.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.functions.flatMap(i=>i.toFlatGenerationTarget(e)),...this.events.flatMap(i=>i.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.functions.forEach(e=>e.clearErrors()),this.events.forEach(e=>e.clearErrors()),this}validate(){const e=R1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.functions.flatMap(t=>t.getErrors()),...this.events.flatMap(t=>t.getErrors())]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var O,P;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.functions=[],o.events=[];const u=d.split("-id"),y=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=ct(o,l);t&&c.setParent(t,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,A.Added);const I=(O=this.functions)==null?void 0:O.map((V,M)=>V.clone(e,c,y+"-exported-function-declaration-"+M+"-id",s));c.functions=I;const E=(P=this.events)==null?void 0:P.map((V,M)=>V.clone(e,c,y+"-exported-event-"+M+"-id",s));return c.events=E,e==null||e.attemptAutoclose("clone-entity",this.id),c}};f(Se,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(Se,"type",n.InstalledProject),f(Se,"USER_MANAGED_PARENT_TYPES",[n.Project]),f(Se,"PARENT_TYPES",[...Se.USER_MANAGED_PARENT_TYPES]),f(Se,"MUTABLE_BASE_PROPERTIES",[]),f(Se,"INMUTABLE_BASE_PROPERTIES",["id","version","name","description","type","createdAt","author","previousVersion"]),f(Se,"BASE_PROPERTIES",[...Se.MUTABLE_BASE_PROPERTIES,...Se.INMUTABLE_BASE_PROPERTIES]),f(Se,"MUTABLE_META_PROPERTIES",["x","y"]),f(Se,"INMUTABLE_META_PROPERTIES",[...Se.INMUTABLE_BASE_PROPERTIES]),f(Se,"META_PROPERTIES",[...Se.MUTABLE_META_PROPERTIES,...Se.INMUTABLE_META_PROPERTIES]),f(Se,"MUTABLE_UPSTREAM_PROPERTIES",[]),f(Se,"INMUTABLE_UPSTREAM_PROPERTIES",["implements","parent"]),f(Se,"UPSTREAM_PROPERTIES",[...Se.MUTABLE_UPSTREAM_PROPERTIES,...Se.INMUTABLE_UPSTREAM_PROPERTIES]),f(Se,"MUTABLE_DOWNSTREAM_PROPERTIES",["functions","events"]),f(Se,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Se,"DOWNSTREAM_PROPERTIES",[...Se.MUTABLE_DOWNSTREAM_PROPERTIES,...Se.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Se,"PROPERTIES",[...Se.META_PROPERTIES,...Se.UPSTREAM_PROPERTIES,...Se.DOWNSTREAM_PROPERTIES]);let Wr=Se;function D1(r){var o;const a=$5(),e=r.toJSON();a.safeParse(e).success,r.inputs.forEach(d=>d.validate()),r.outputs.forEach(d=>d.validate()),(o=r.error)==null||o.validate();const i=vr(r),s=O1(r),l=[...i,...s];return He(r.errors,l)}function O1(r){const a=[],e=Ml(r.parent,null),t=e==null?void 0:e.entity;if(!t)a.push(de({id:`${r.id}--${j.InternalCallParentMissingDataType}`,code:j.InternalCallParentMissingDataType,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", belongs to a variable whose data type entity doesn't contain its declaration method (function-declaration) its id "${r.declaration}".`,issue:null,entity:r}).error);else if(![n.DefinitionEntity,n.BuiltInBaseEntity,n.PrimitiveEntity].includes(t.type))a.push(de({id:`${r.id}--${j.InternalCallParentDeclarationEntityInvalidType}`,code:j.InternalCallParentDeclarationEntityInvalidType,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", belongs to a variable whose data type 'entity' is not a definition entity, built-in base entity or primitive entity.
112
112
  This variable's data-type has an 'entity' field that references an entity with id '${t.id}' and of type '${t.type}'.`,issue:null,entity:r}).error);else{const i=La(t),s=[];[n.DefinitionEntity,n.BuiltInBaseEntity,n.PrimitiveEntity].includes(t.type)&&s.push(...t.getAllInteractiveMethods());let l="";i?t.methods.length?l=`
113
113
  All 'function-declaration' entities attached as methods to the parent data-type 'entity' field, available to be called as 'internal-calls' in this variable are:
114
114
  - ${t.methods.map(u=>u.id).join(`
@@ -120,7 +120,7 @@ This variable's data-type 'entity' is a ${t.type} which doesn't have any methods
120
120
  Built-in entity types can't have methods attached to them by the user. They are predefined entities that can't be modified. You can reference them as the 'declaration' property on a new 'internal-call' entity in a variable`):t.type===n.DefinitionEntity?l=`
121
121
  This variable's data-type 'entity' is a definition entity which extends or implements a non-interactive 'built-in-base-entity'.s`:t.type===n.BuiltInBaseEntity&&(l=`
122
122
  This variable's data-type 'entity' is a non-interactive 'built-in-base-entity'.s`);const o=s.find(d=>d.id===r.declaration.id);o?o.type!==n.FunctionDeclaration&&a.push(de({id:`${r.id}--${j.InternalCallDeclarationIsNotFunctionDeclaration}`,code:j.InternalCallDeclarationIsNotFunctionDeclaration,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", points to a 'declaration' that isn't a 'function-declaration' entity.
123
- The declaration of the internal-call must be a 'function-declaration' entity which exists as a method in the entity of the data-type of the parent variable.${l}`,issue:null,entity:r}).error):a.push(de({id:`${r.id}--${j.InternalCallDeclarationNotFoundInParentDatatypeEntity}`,code:j.InternalCallDeclarationNotFoundInParentDatatypeEntity,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", belongs to a variable whose data type entity doesn't contain its declaration method (function-declaration) with id "${r.declaration}".${l}`,issue:null,entity:r}).error)}return a}const jq=Object.freeze(Object.defineProperty({__proto__:null,validate:D1,validateParentRelation:O1},Symbol.toStringTag,{value:"Module"}));var P1=(r=>(r.Declaration="declaration",r))(P1||{});const Be=class Be extends at{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"index");f(this,"type",n.InternalCall);f(this,"declaration");f(this,"inputs",[]);f(this,"outputs",[]);f(this,"process",null);f(this,"successCalls",[]);f(this,"errorCalls",[]);f(this,"error",null);f(this,"calledBySuccess",[]);f(this,"calledByError",[]);f(this,"calledByEntry",[]);f(this,"parent");f(this,"project");f(this,"errors",[]);f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.index=e.index}static new(){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InternalCall,declaration:null,inputs:[],outputs:[],process:null,error:null,index:0,parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],errorCalls:[],successCalls:[]}}static fromGenerationTarget(e,t){const i=_(e.parent),s=t.get(i),l=_(e.declaration),o=t.get(l),d=e.calledByEntry.map(E=>{const O=_(E);return t.get(O)}),u=e.calledBySuccess.map(E=>{const O=_(E);return t.get(O)}),y=e.calledByError.map(E=>{const O=_(E);return t.get(O)}),c={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InternalCall,index:s.internalCalls.length,declaration:o.toReference(),calledByEntry:d,calledBySuccess:u,calledByError:y,errorCalls:[],successCalls:[],inputs:[],outputs:[],process:null,error:null,parent:s},I=C(c,t);return I.setParent(s,null),I.initChildren(null),I}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=At(i,{parent:{list:!1,types:tt}},t);i=l.modifiedData;const o=_(i.parent),d=t.get(o);if(d){const u=Ml(d,null),y=u==null?void 0:u.entity;if(!y)s.push(new w({id:`${i.id}--${j.InternalCallParentMissingDataType}`,code:j.InternalCallParentMissingDataType,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", belongs to a variable whose data type entity doesn't contain its declaration method (function-declaration) its id "${i.declaration}".`,issue:null}));else if(![n.DefinitionEntity,n.BuiltInBaseEntity,n.PrimitiveEntity].includes(y.type))s.push(new w({id:`${i.id}--${j.InternalCallParentDeclarationEntityInvalidType}`,code:j.InternalCallParentDeclarationEntityInvalidType,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", belongs to a variable whose data type 'entity' is not a definition entity, built-in base entity or primitive entity.
123
+ The declaration of the internal-call must be a 'function-declaration' entity which exists as a method in the entity of the data-type of the parent variable.${l}`,issue:null,entity:r}).error):a.push(de({id:`${r.id}--${j.InternalCallDeclarationNotFoundInParentDatatypeEntity}`,code:j.InternalCallDeclarationNotFoundInParentDatatypeEntity,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", belongs to a variable whose data type entity doesn't contain its declaration method (function-declaration) with id "${r.declaration}".${l}`,issue:null,entity:r}).error)}return a}const j7=Object.freeze(Object.defineProperty({__proto__:null,validate:D1,validateParentRelation:O1},Symbol.toStringTag,{value:"Module"}));var P1=(r=>(r.Declaration="declaration",r))(P1||{});const Be=class Be extends at{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"index");f(this,"type",n.InternalCall);f(this,"declaration");f(this,"inputs",[]);f(this,"outputs",[]);f(this,"process",null);f(this,"successCalls",[]);f(this,"errorCalls",[]);f(this,"error",null);f(this,"calledBySuccess",[]);f(this,"calledByError",[]);f(this,"calledByEntry",[]);f(this,"parent");f(this,"project");f(this,"errors",[]);f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.index=e.index}static new(){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InternalCall,declaration:null,inputs:[],outputs:[],process:null,error:null,index:0,parent:null,calledByEntry:[],calledBySuccess:[],calledByError:[],errorCalls:[],successCalls:[]}}static fromGenerationTarget(e,t){const i=_(e.parent),s=t.get(i),l=_(e.declaration),o=t.get(l),d=e.calledByEntry.map(E=>{const O=_(E);return t.get(O)}),u=e.calledBySuccess.map(E=>{const O=_(E);return t.get(O)}),y=e.calledByError.map(E=>{const O=_(E);return t.get(O)}),c={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InternalCall,index:s.internalCalls.length,declaration:o.toReference(),calledByEntry:d,calledBySuccess:u,calledByError:y,errorCalls:[],successCalls:[],inputs:[],outputs:[],process:null,error:null,parent:s},I=C(c,t);return I.setParent(s,null),I.initChildren(null),I}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=At(i,{parent:{list:!1,types:tt}},t);i=l.modifiedData;const o=_(i.parent),d=t.get(o);if(d){const u=Ml(d,null),y=u==null?void 0:u.entity;if(!y)s.push(new w({id:`${i.id}--${j.InternalCallParentMissingDataType}`,code:j.InternalCallParentMissingDataType,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", belongs to a variable whose data type entity doesn't contain its declaration method (function-declaration) its id "${i.declaration}".`,issue:null}));else if(![n.DefinitionEntity,n.BuiltInBaseEntity,n.PrimitiveEntity].includes(y.type))s.push(new w({id:`${i.id}--${j.InternalCallParentDeclarationEntityInvalidType}`,code:j.InternalCallParentDeclarationEntityInvalidType,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", belongs to a variable whose data type 'entity' is not a definition entity, built-in base entity or primitive entity.
124
124
  This variable's data-type has an 'entity' field that references an entity with id '${y.id}' and of type '${y.type}'.`,issue:null}));else{const c=La(y);let I="";c?y.methods.length?I=`
125
125
  All 'function-declaration' entities attached as methods to the parent data-type 'entity' field, available to be called as 'internal-calls' in this variable are:
126
126
  - ${y.methods.map(V=>V.id).join(`
@@ -137,7 +137,7 @@ ${Qr}`);const E=i.declaration;if(!t.get(E))s.push(new w({id:`${i.id}--${R.Refere
137
137
  The declaration of the internal-call must be a 'function-declaration' entity which exists as a method in the entity of the data-type of the parent variable.${I}`,issue:null})):s.push(new w({id:`${i.id}--${j.InternalCallDeclarationNotFoundInParentDatatypeEntity}`,code:j.InternalCallDeclarationNotFoundInParentDatatypeEntity,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", belongs to a variable whose data type entity doesn't contain its declaration method (function-declaration) with id "${i.declaration}".${I}`,issue:null}))}}(d.inputs.length||d.outputs.length||d.internalCalls.length)&&s.push(new w({id:`${i.id}--${R.InvalidInternalCallParentRelation}`,code:R.InvalidInternalCallParentRelation,severity:D.Error,message:`Entity of type "${i.type}" with id "${i.id}", can only be added to a variable declaration or variable instance parent if the parent doesn't already have inputs, outputs or other internal calls.
138
138
  If you need a new variable-instance for this, consider using the 'implement_variable_instance' generation action to create one and give it a caller.
139
139
  The you can attach the new internal-call to it.`,issue:null}))}return s.push(...l.errors,...ut(i)),{errors:s,modifiedData:i}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated, as it would mean moving the '${this.type}' entity to another parent entity.
140
- This is likely an incorrect strategy, either the '${this.type}' entity doesn't need to be updated or it should be deleted and a new one created in the desired parent.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],i=[],s=[];return Object.values(this.detachedDependents).forEach(l=>{const o=l.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),i.push(...o.removed),s.push(...o.affected)}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="declaration"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="declaration"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){return this.declaration.subscribeDependents([{entity:this,field:"declaration"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Be(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.process=this.process,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.declaration=this.declaration,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[I,E]of c.knownVersions)u.set(I,E);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Be(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.error=o.error,this.process=o.process,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.declaration=o.declaration,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.declaration){const l=_(this.initialData.declaration),o=this.project.get(l);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];this.initialized=!0,this.captureVersion();const{updated:o,added:d,removed:u}=this.syncMissingFixedInputs(e),{updated:y,added:c,removed:I}=this.syncMissingFixedOutputs(e);return t.push(...o,...y),i.push(...d,...c),s.push(...u,...I),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){var o;const t=[this],i=[],s=[],l=[];return this.parent.addInternalCall(this),t.push(this.parent),(o=this.process)==null||o.writesValues.forEach(d=>{d.setValueWriter(this.process,e),t.push(d)}),this.successCalls.forEach(d=>{d.addSuccessCaller(this,e),t.push(d)}),this.errorCalls.forEach(d=>{d.addErrorCaller(this,e),t.push(d)}),this.calledBySuccess.forEach(d=>{d.addSuccessCall(this,e),t.push(d)}),this.calledByError.forEach(d=>{d.addErrorCall(this,e),t.push(d)}),this.calledByEntry.forEach(d=>{d.addCall(this,e),t.push(d)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-input"))){const i=this.inputs.findIndex(s=>s.id===e.id);return i>-1&&(this.inputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-input",this.id),this}addInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-input"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input",this.id),this):(this.inputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-input",this.id),this)}addOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-output"))){return this.outputs.includes(e)?(t==null||t.attemptAutoclose("add-output",this.id),this):(this.outputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-output",this.id),this)}removeOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-output"))){const i=this.outputs.findIndex(s=>s.id===e.id);return i>-1&&(this.outputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-output",this.id),this}addValueReader(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-value-reader"))){var i;return this.process&&!this.process.writesValues.includes(e)&&((i=this.process)==null||i.addValueReader(e,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-value-reader",this.id),this}removeValueReader(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-value-reader"))){var i;return this.process&&this.process.writesValues.includes(e)&&((i=this.process)==null||i.removeValueReader(e,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("remove-value-reader",this.id),this}addSuccessCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,A.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,A.Updated),i&&K(this,t),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,A.Updated),i&&K(this,t),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}addErrorCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-call")),i=!1){return this.errorCalls.find(s=>s.id===e.id)||(this.errorCalls.push(e),i&&K(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-call")),i=!1){return this.successCalls.find(s=>s.id===e.id)||(this.successCalls.push(e),i&&K(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-success-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-call")),i=!1){const s=this.successCalls.findIndex(o=>o.id===e.id);s>-1&&(this.successCalls.splice(s,1),t==null||t.add(this,A.Affected));const l=this.errorCalls.findIndex(o=>o.id===e.id);return l>-1&&(this.errorCalls.splice(l,1),t==null||t.add(this,A.Affected)),i&&K(this,t),t==null||t.attemptAutoclose("remove-call",this.id),this}removeCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected)),!0):!1),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected)),!0):!1),i&&K(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setDeclaration(e){return this.declaration=e,this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.parent.type!==n.GenericReference){const t=C(this.initialData.parent,this.project);this.setParent(t,null),this.parent.initChildren(e),this.parent.addInternalCall(this);const i=this.calledBy.find(s=>!!s.parent&&dt.includes(s.parent.type));if(i){const s=C(i.parent,this.project);this.parent.setParent(s,null)}else if(!i&&!this.parent.calledBy.length)throw new Error("Parent of internal call parent could not be resolved")}return this.declaration=C(this.initialData.declaration,this.project),this.successCalls=this.initialData.successCalls.map(t=>{const i=C(t,this.project);return i.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type)?(i.setParent(this.parent.parent,null),i.initChildren(e)):i.type!==n.InternalCall&&(i.setParent(this.parent.parent,null),i.initChildren(e)),i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=C(t,this.project);return i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type)?(i.setParent(this.parent.parent.parent,null),i.initChildren(e)):i.type!==n.InternalCall&&(i.setParent(this.parent.parent,null),i.initChildren(e)),i}),this.inputs=this.initialData.inputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.outputs=this.initialData.outputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.initialData.error&&(this.error=C(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(e)),this.initialData.process&&(this.process=C(this.initialData.process,this.project),this.process.setParent(this,null),this.process.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.index=e.index||(e.index!==0?s.index:0),super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=g,...t){return await Be.repository.APILoad(this.id,...t),this}async APICreate(e=g,...t){return await Be.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=g,...t){return await Be.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=g,...t){return await Be.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=g,...t){return await Be.repository.APIClone(this.id,...t),this}async APILoadVersion(e=g,t,...i){return await Be.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){var d;const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(u=>{const{updated:y,removed:c,added:I}=u.entity.onDetachedDependencyRemoved(this,u.field,t);i.push(...y),s.push(...c),l.push(...I)}),this.process){const{updated:u,removed:y}=(d=this.process)==null?void 0:d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}if(this.inputs.forEach(u=>{const{updated:y,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...y),s.push(...c)}),this.outputs.forEach(u=>{const{updated:y,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...y),s.push(...c)}),this.error){const{updated:u,removed:y}=this.error.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}return this.successCalls.forEach(u=>{i.push(u),u.removeCaller(this,t)}),this.errorCalls.forEach(u=>{i.push(u),u.removeCaller(this,t)}),e||this.calledBy.forEach(u=>{i.push(u),u.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.process){const{updated:o}=this.process.restore({},e);i.push(...o)}return this.inputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.successCalls.forEach(o=>{i.push(o),o.addSuccessCaller(this,e)}),this.errorCalls.forEach(o=>{i.push(o),o.addErrorCaller(this,e)}),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.successCalls.flatMap(i=>i.toFlat(e)),...this.errorCalls.flatMap(i=>i.toFlat(e)),...this.inputs.flatMap(i=>i.toFlat(e)),...this.outputs.flatMap(i=>i.toFlat(e)),...this.calledBy.flatMap(i=>i.toFlat(e)),...this.process?this.process.toFlat(e):[],...this.error?this.error.toFlat(e):[],...this.parent.toFlat(e)])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.successCalls.flatMap(i=>i.toFlatIds(e)),...this.errorCalls.flatMap(i=>i.toFlatIds(e)),...this.inputs.flatMap(i=>i.toFlatIds(e)),...this.outputs.flatMap(i=>i.toFlatIds(e)),...this.calledBy.flatMap(i=>i.toFlatIds(e)),...this.process?this.process.toFlatIds(e):[],...this.error?this.error.toFlatIds(e):[],...this.parent.toFlatIds(e)])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,index:this.index,type:this.type}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,index:this.index,successCalls:this.successCalls.map(s=>s.toJSON(e)),errorCalls:this.errorCalls.map(s=>s.toJSON(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference()),calledByError:this.calledByError.map(s=>s.toReference()),calledByEntry:this.calledByEntry.map(s=>s.toReference()),process:(t=this.process)==null?void 0:t.toJSON(e),declaration:this.declaration.toJSON(e),inputs:this.inputs.map(s=>s.toJSON(e)),outputs:this.outputs.map(s=>s.toJSON(e)),parent:this.parent.toReference(),error:(i=this.error)==null?void 0:i.toJSON(e)})}toJSONClone(e=q){var i,s,l,o,d,u,y;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,index:this.index,successCalls:this.successCalls.map(c=>c.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(c=>c.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),process:(u=this.process)==null?void 0:u.toJSONClone({...e,newId:null}),declaration:this.project.getBuiltIn(this.declaration.id)?this.declaration.toJSON():this.declaration.toJSONClone({...e,newId:null}),inputs:this.inputs.map(c=>c.toJSONClone({...e,newId:null})),outputs:this.outputs.map(c=>c.toJSONClone({...e,newId:null})),error:(y=this.error)==null?void 0:y.toJSONClone({...e,newId:null}),parent:this.parent.calledBy.length||this.parent.readsValue?this.parent.toReference({seenEntityMaps:e.seenEntityMaps}):this.parent.toJSONClone({...e,newId:null})})}toReference(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,index:this.index,process:this.process?this.process.toReference(e):null,inputs:this.inputs.map(s=>s.toReference(e)),outputs:this.outputs.map(s=>s.toReference(e)),declaration:this.declaration.toReference(e),successCalls:this.successCalls.map(s=>s.toReference(e)),errorCalls:this.errorCalls.map(s=>s.toReference(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference(e)),calledByError:this.calledByError.map(s=>s.toReference(e)),calledByEntry:this.calledByEntry.map(s=>s.toReference(e)),error:this.error?this.error.toReference(e):null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.process?this.process.toFlatJSON(e):[],...this.successCalls.flatMap(i=>i.toFlatJSON(e)),...this.errorCalls.flatMap(i=>i.toFlatJSON(e)),...this.inputs.flatMap(i=>i.toFlatJSON(e)),...this.outputs.flatMap(i=>i.toFlatJSON(e)),...this.calledBy.flatMap(i=>i.toFlatJSON(e)),...this.error?this.error.toFlatJSON(e):[],...this.parent.toFlatJSON(e)])}toGenerationTarget(){return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(e=>e.id),calledBySuccess:this.calledBySuccess.map(e=>e.id),calledByError:this.calledByError.map(e=>e.id),declaration:this.declaration.id,parent:this.parent.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.process?this.process.toFlatGenerationTarget(e):[],...this.successCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.inputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.outputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.error?this.error.toFlatGenerationTarget(e):[],...this.parent.toFlatGenerationTarget(e)])}clearErrors(){var e,t;return this.errors=[],this.inputs.forEach(i=>i.clearErrors()),this.outputs.forEach(i=>i.clearErrors()),this.successCalls.forEach(i=>i.clearErrors()),this.errorCalls.forEach(i=>i.clearErrors()),(e=this.process)==null||e.clearErrors(),(t=this.error)==null||t.clearErrors(),this}validate(){const e=D1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.inputs.flatMap(t=>t.getErrors()),...this.outputs.flatMap(t=>t.getErrors()),...this.error?this.error.getErrors():[],...this.process?this.process.getErrors():[]]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var O,P;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[];const u=d.split("-id"),y=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid();const c=ct(o,l);t?c.setParent(t,null):c.setParent(this.parent,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,A.Added);const I=(O=this.inputs)==null?void 0:O.map((V,M)=>V.clone(e,c,y+"-input-map-"+M+"-id",s));c.inputs=I;const E=(P=this.outputs)==null?void 0:P.map((V,M)=>V.clone(e,c,y+"-output-map-"+M+"-id",s));return c.outputs=E,this.error&&(c.error=this.error.clone(e,c,y+"-error-map-id",s)),this.process&&(c.process=this.process.clone(e,c,y+"-process-id",s)),e==null||e.attemptAutoclose("clone-entity",this.id),c}removeUnrecognizedInputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-unrecognized-inputs"))){const t=[],i=[],s=[],l=[];return this.inputs.forEach(o=>{if(!this.declaration.inputs.find(u=>{var y;return u.id===((y=o.declaration)==null?void 0:y.id)})){const u=o.remove({ignoreUpstream:!1},e);s.push(...u.removed),t.push(...u.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}removeUnrecognizedOutputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-unrecognized-outputs"))){const t=[],i=[],s=[],l=[];return this.outputs.forEach(o=>{if(!this.declaration.getUniqueReturnDeclarations().find(u=>{var y;return u.id===((y=o.declaration)==null?void 0:y.id)})){const u=o.remove({ignoreUpstream:!1},e);s.push(...u.removed),t.push(...u.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-outputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncMissingFixedInputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const t=[],i=[],s=[],l=[],o=this.declaration.inputs.filter(c=>!this.inputs.find(I=>I.declaration.id===c.id));this.inputs.sort((c,I)=>c.index-I.index),o.forEach(c=>{this.inputs.forEach(O=>{O.index>=c.index&&O.metaSync({index:O.index+1},e)});const I={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,declaration:c.toJSON(),readsValue:null,defaultValue:null,index:c.index,name:null,description:null,parent:this.toReference()},E=C(I,this.project);E.setParent(this,e),E.initChildren(e),e==null||e.add(E,A.Added),E.addSelfToProject(e),i.push(E)}),this.inputs.sort((c,I)=>c.index-I.index);const{updated:d,added:u,removed:y}=this.removeUnrecognizedInputs(e);return t.push(...d),i.push(...u),s.push(...y),e==null||e.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncMissingFixedOutputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-missing-fixed-outputs"))){const t=[],i=[],s=[],l=[],o=[];this.outputs=this.initialData.outputs.map(I=>{const E=C(I,this.project);return o.push(E.index),E.setParent(this,null),E.initChildren(e),E});const d=this.declaration.getUniqueReturnDeclarations().filter(I=>!this.outputs.find(E=>E.declaration.id===I.id));this.outputs.sort((I,E)=>I.index-E.index),d.forEach((I,E)=>{this.outputs.forEach(M=>{M.index>=I.index&&M.index++});const O=o.includes(I.index)?this.outputs.length-1+E:I.index,P={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.OutputMap,declaration:I.toJSON(),defaultValue:null,writesValues:[],index:O,parent:this.toReference()},V=C(P,this.project);V.setParent(this,e),V.initChildren(e),e==null||e.add(V,A.Added),V.addSelfToProject(e)}),this.outputs.sort((I,E)=>I.index-E.index);const{updated:u,added:y,removed:c}=this.removeUnrecognizedOutputs(e);return t.push(...u),i.push(...y),s.push(...c),e==null||e.attemptAutoclose("sync-missing-fixed-outputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}};f(Be,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(Be,"type",n.InternalCall),f(Be,"USER_MANAGED_PARENT_TYPES",[...tt]),f(Be,"PARENT_TYPES",[...Be.USER_MANAGED_PARENT_TYPES]),f(Be,"MUTABLE_BASE_PROPERTIES",[]),f(Be,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Be,"BASE_PROPERTIES",[...Be.MUTABLE_BASE_PROPERTIES,...Be.INMUTABLE_BASE_PROPERTIES]),f(Be,"MUTABLE_META_PROPERTIES",[...Be.MUTABLE_BASE_PROPERTIES,"index"]),f(Be,"INMUTABLE_META_PROPERTIES",[...Be.INMUTABLE_BASE_PROPERTIES]),f(Be,"META_PROPERTIES",[...Be.MUTABLE_META_PROPERTIES,...Be.INMUTABLE_META_PROPERTIES]),f(Be,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),f(Be,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),f(Be,"UPSTREAM_PROPERTIES",[...Be.MUTABLE_UPSTREAM_PROPERTIES,...Be.INMUTABLE_UPSTREAM_PROPERTIES]),f(Be,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","outputs","writesValues","successCalls","errorCalls","error"]),f(Be,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Be,"DOWNSTREAM_PROPERTIES",[...Be.MUTABLE_DOWNSTREAM_PROPERTIES,...Be.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Be,"PROPERTIES",[...Be.META_PROPERTIES,...Be.UPSTREAM_PROPERTIES,...Be.DOWNSTREAM_PROPERTIES]);let zr=Be;function w1(r){const a=k5(),e=r.toJSON();a.safeParse(e).success;const i=[];if(r.id==="exec-sequentially-argument-map-id"){const s=de({id:`${r.id}--${F.PropertyImplementsNonAbstact}`,message:`Property "${x(r,r.project)}" with id "${r.id}" implements a non-abstract property "${x(r,r.project)}" with id "${r.id}".`,issue:null,severity:D.Error,code:F.PropertyImplementsNonAbstact,entity:r});i.push(s.error)}return He(r.errors,i)}const $q=Object.freeze(Object.defineProperty({__proto__:null,validate:w1},Symbol.toStringTag,{value:"Module"}));var C1=(r=>(r.Declaration="declaration",r.DataTypeEntity="data-type-entity",r))(C1||{});const _e=class _e extends at{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"index");f(this,"name",null);f(this,"description",null);f(this,"type",n.InputMap);f(this,"defaultValue",null);f(this,"readsValue",null);f(this,"dataType",null);f(this,"declaration",null);f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.index=e.index,this.name=e.name||null,this.description=e.description||null}static new(){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,name:"",description:"",declaration:null,index:0,readsValue:null,defaultValue:null,parent:null}}static fromGenerationTarget(e,t){const i=_(e.parent),s=t.get(i);let l=null;if(e.declaration){const y=_(e.declaration);l=t.get(y)}let o=null;if(e.readsValue){const y=_(e.readsValue);o=t.get(y)}const d={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name||null,type:n.InputMap,index:(s.inputs||[]).length,description:e.description||null,declaration:l,readsValue:o,defaultValue:null,parent:s},u=C(d,t);return u.setParent(s,null),u.initChildren(null),u}static validateGenerationTarget(e,t){var y;let i=JSON.parse(JSON.stringify(e));const s=[],l=At(i,{parent:{list:!1,types:[...ot,n.InputMap]}},t);i=l.modifiedData;const o=t.get(i.parent),d=i.declaration&&(t.get(i.declaration)||t.getBuiltIn(i.declaration)),u=((o==null?void 0:o.inputs)||[]).find(c=>{var I;return i.declaration&&((I=c.declaration)==null?void 0:I.id)===i.declaration});if(i.declaration?d?[n.Property,n.ArgumentDeclaration,n.ValueDescriptor].includes(d.type)?o&&d.type===n.ArgumentDeclaration&&![n.FunctionCall,n.Search,n.InternalCall].includes(o.type)?s.push(new w({id:`${i.id}--${R.InvalidInputMapDeclaration}`,code:R.InvalidInputMapDeclaration,severity:D.Error,message:`Entity of type '${n.InputMap}' with id '${i.id}' has a 'declaration' property pointing to an entity with type '${n.ArgumentDeclaration}' with id '${i.declaration}'.
140
+ This is likely an incorrect strategy, either the '${this.type}' entity doesn't need to be updated or it should be deleted and a new one created in the desired parent.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],i=[],s=[];return Object.values(this.detachedDependents).forEach(l=>{const o=l.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),i.push(...o.removed),s.push(...o.affected)}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="declaration"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="declaration"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){return this.declaration.subscribeDependents([{entity:this,field:"declaration"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Be(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.process=this.process,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.declaration=this.declaration,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[I,E]of c.knownVersions)u.set(I,E);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Be(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.error=o.error,this.process=o.process,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.declaration=o.declaration,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.declaration){const l=_(this.initialData.declaration),o=this.project.get(l);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];this.initialized=!0,this.captureVersion();const{updated:o,added:d,removed:u}=this.syncMissingFixedInputs(e),{updated:y,added:c,removed:I}=this.syncMissingFixedOutputs(e);return t.push(...o,...y),i.push(...d,...c),s.push(...u,...I),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){var o;const t=[this],i=[],s=[],l=[];return this.parent.addInternalCall(this),t.push(this.parent),(o=this.process)==null||o.writesValues.forEach(d=>{d.setValueWriter(this.process,e),t.push(d)}),this.successCalls.forEach(d=>{d.addSuccessCaller(this,e),t.push(d)}),this.errorCalls.forEach(d=>{d.addErrorCaller(this,e),t.push(d)}),this.calledBySuccess.forEach(d=>{d.addSuccessCall(this,e),t.push(d)}),this.calledByError.forEach(d=>{d.addErrorCall(this,e),t.push(d)}),this.calledByEntry.forEach(d=>{d.addCall(this,e),t.push(d)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-input"))){const i=this.inputs.findIndex(s=>s.id===e.id);return i>-1&&(this.inputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-input",this.id),this}addInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-input"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input",this.id),this):(this.inputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-input",this.id),this)}addOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-output"))){return this.outputs.includes(e)?(t==null||t.attemptAutoclose("add-output",this.id),this):(this.outputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-output",this.id),this)}removeOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-output"))){const i=this.outputs.findIndex(s=>s.id===e.id);return i>-1&&(this.outputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-output",this.id),this}addValueReader(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-value-reader"))){var i;return this.process&&!this.process.writesValues.includes(e)&&((i=this.process)==null||i.addValueReader(e,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-value-reader",this.id),this}removeValueReader(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-value-reader"))){var i;return this.process&&this.process.writesValues.includes(e)&&((i=this.process)==null||i.removeValueReader(e,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("remove-value-reader",this.id),this}addSuccessCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,A.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,A.Updated),i&&K(this,t),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,A.Updated),i&&K(this,t),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}addErrorCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-call")),i=!1){return this.errorCalls.find(s=>s.id===e.id)||(this.errorCalls.push(e),i&&K(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-call")),i=!1){return this.successCalls.find(s=>s.id===e.id)||(this.successCalls.push(e),i&&K(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-success-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-call")),i=!1){const s=this.successCalls.findIndex(o=>o.id===e.id);s>-1&&(this.successCalls.splice(s,1),t==null||t.add(this,A.Affected));const l=this.errorCalls.findIndex(o=>o.id===e.id);return l>-1&&(this.errorCalls.splice(l,1),t==null||t.add(this,A.Affected)),i&&K(this,t),t==null||t.attemptAutoclose("remove-call",this.id),this}removeCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected)),!0):!1),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected)),!0):!1),i&&K(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setDeclaration(e){return this.declaration=e,this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.parent.type!==n.GenericReference){const t=C(this.initialData.parent,this.project);this.setParent(t,null),this.parent.initChildren(e),this.parent.addInternalCall(this);const i=this.calledBy.find(s=>!!s.parent&&dt.includes(s.parent.type));if(i){const s=C(i.parent,this.project);this.parent.setParent(s,null)}else if(!i&&!this.parent.calledBy.length)throw new Error("Parent of internal call parent could not be resolved")}return this.declaration=C(this.initialData.declaration,this.project),this.successCalls=this.initialData.successCalls.map(t=>{const i=C(t,this.project);return i.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type)?(i.setParent(this.parent.parent,null),i.initChildren(e)):i.type!==n.InternalCall&&(i.setParent(this.parent.parent,null),i.initChildren(e)),i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=C(t,this.project);return i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type)?(i.setParent(this.parent.parent.parent,null),i.initChildren(e)):i.type!==n.InternalCall&&(i.setParent(this.parent.parent,null),i.initChildren(e)),i}),this.inputs=this.initialData.inputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.outputs=this.initialData.outputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.initialData.error&&(this.error=C(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(e)),this.initialData.process&&(this.process=C(this.initialData.process,this.project),this.process.setParent(this,null),this.process.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.index=e.index||(e.index!==0?s.index:0),super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=g,...t){return await Be.repository.APILoad(this.id,...t),this}async APICreate(e=g,...t){return await Be.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=g,...t){return await Be.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=g,...t){return await Be.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=g,...t){return await Be.repository.APIClone(this.id,...t),this}async APILoadVersion(e=g,t,...i){return await Be.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){var d;const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(u=>{const{updated:y,removed:c,added:I}=u.entity.onDetachedDependencyRemoved(this,u.field,t);i.push(...y),s.push(...c),l.push(...I)}),this.process){const{updated:u,removed:y}=(d=this.process)==null?void 0:d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}if(this.inputs.forEach(u=>{const{updated:y,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...y),s.push(...c)}),this.outputs.forEach(u=>{const{updated:y,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...y),s.push(...c)}),this.error){const{updated:u,removed:y}=this.error.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}return this.successCalls.forEach(u=>{i.push(u),u.removeCaller(this,t)}),this.errorCalls.forEach(u=>{i.push(u),u.removeCaller(this,t)}),e||this.calledBy.forEach(u=>{i.push(u),u.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.process){const{updated:o}=this.process.restore({},e);i.push(...o)}return this.inputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.successCalls.forEach(o=>{i.push(o),o.addSuccessCaller(this,e)}),this.errorCalls.forEach(o=>{i.push(o),o.addErrorCaller(this,e)}),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.successCalls.flatMap(i=>i.toFlat(e)),...this.errorCalls.flatMap(i=>i.toFlat(e)),...this.inputs.flatMap(i=>i.toFlat(e)),...this.outputs.flatMap(i=>i.toFlat(e)),...this.calledBy.flatMap(i=>i.toFlat(e)),...this.process?this.process.toFlat(e):[],...this.error?this.error.toFlat(e):[],...this.parent.toFlat(e)])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.successCalls.flatMap(i=>i.toFlatIds(e)),...this.errorCalls.flatMap(i=>i.toFlatIds(e)),...this.inputs.flatMap(i=>i.toFlatIds(e)),...this.outputs.flatMap(i=>i.toFlatIds(e)),...this.calledBy.flatMap(i=>i.toFlatIds(e)),...this.process?this.process.toFlatIds(e):[],...this.error?this.error.toFlatIds(e):[],...this.parent.toFlatIds(e)])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,index:this.index,type:this.type}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,index:this.index,successCalls:this.successCalls.map(s=>s.toJSON(e)),errorCalls:this.errorCalls.map(s=>s.toJSON(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference()),calledByError:this.calledByError.map(s=>s.toReference()),calledByEntry:this.calledByEntry.map(s=>s.toReference()),process:(t=this.process)==null?void 0:t.toJSON(e),declaration:this.declaration.toJSON(e),inputs:this.inputs.map(s=>s.toJSON(e)),outputs:this.outputs.map(s=>s.toJSON(e)),parent:this.parent.toReference(),error:(i=this.error)==null?void 0:i.toJSON(e)})}toJSONClone(e=q){var i,s,l,o,d,u,y;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,index:this.index,successCalls:this.successCalls.map(c=>c.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(c=>c.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),process:(u=this.process)==null?void 0:u.toJSONClone({...e,newId:null}),declaration:this.project.getBuiltIn(this.declaration.id)?this.declaration.toJSON():this.declaration.toJSONClone({...e,newId:null}),inputs:this.inputs.map(c=>c.toJSONClone({...e,newId:null})),outputs:this.outputs.map(c=>c.toJSONClone({...e,newId:null})),error:(y=this.error)==null?void 0:y.toJSONClone({...e,newId:null}),parent:this.parent.calledBy.length||this.parent.readsValue?this.parent.toReference({seenEntityMaps:e.seenEntityMaps}):this.parent.toJSONClone({...e,newId:null})})}toReference(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,index:this.index,process:this.process?this.process.toReference(e):null,inputs:this.inputs.map(s=>s.toReference(e)),outputs:this.outputs.map(s=>s.toReference(e)),declaration:this.declaration.toReference(e),successCalls:this.successCalls.map(s=>s.toReference(e)),errorCalls:this.errorCalls.map(s=>s.toReference(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference(e)),calledByError:this.calledByError.map(s=>s.toReference(e)),calledByEntry:this.calledByEntry.map(s=>s.toReference(e)),error:this.error?this.error.toReference(e):null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.process?this.process.toFlatJSON(e):[],...this.successCalls.flatMap(i=>i.toFlatJSON(e)),...this.errorCalls.flatMap(i=>i.toFlatJSON(e)),...this.inputs.flatMap(i=>i.toFlatJSON(e)),...this.outputs.flatMap(i=>i.toFlatJSON(e)),...this.calledBy.flatMap(i=>i.toFlatJSON(e)),...this.error?this.error.toFlatJSON(e):[],...this.parent.toFlatJSON(e)])}toGenerationTarget(){return{id:this.id,type:this.type,calledByEntry:this.calledByEntry.map(e=>e.id),calledBySuccess:this.calledBySuccess.map(e=>e.id),calledByError:this.calledByError.map(e=>e.id),declaration:this.declaration.id,parent:this.parent.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.process?this.process.toFlatGenerationTarget(e):[],...this.successCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.inputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.outputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.error?this.error.toFlatGenerationTarget(e):[],...this.parent.toFlatGenerationTarget(e)])}clearErrors(){var e,t;return this.errors=[],this.inputs.forEach(i=>i.clearErrors()),this.outputs.forEach(i=>i.clearErrors()),this.successCalls.forEach(i=>i.clearErrors()),this.errorCalls.forEach(i=>i.clearErrors()),(e=this.process)==null||e.clearErrors(),(t=this.error)==null||t.clearErrors(),this}validate(){const e=D1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.inputs.flatMap(t=>t.getErrors()),...this.outputs.flatMap(t=>t.getErrors()),...this.error?this.error.getErrors():[],...this.process?this.process.getErrors():[]]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var O,P;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[];const u=d.split("-id"),y=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid();const c=ct(o,l);t?c.setParent(t,null):c.setParent(this.parent,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,A.Added);const I=(O=this.inputs)==null?void 0:O.map((V,M)=>V.clone(e,c,y+"-input-map-"+M+"-id",s));c.inputs=I;const E=(P=this.outputs)==null?void 0:P.map((V,M)=>V.clone(e,c,y+"-output-map-"+M+"-id",s));return c.outputs=E,this.error&&(c.error=this.error.clone(e,c,y+"-error-map-id",s)),this.process&&(c.process=this.process.clone(e,c,y+"-process-id",s)),e==null||e.attemptAutoclose("clone-entity",this.id),c}removeUnrecognizedInputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-unrecognized-inputs"))){const t=[],i=[],s=[],l=[];return this.inputs.forEach(o=>{if(!this.declaration.inputs.find(u=>{var y;return u.id===((y=o.declaration)==null?void 0:y.id)})){const u=o.remove({ignoreUpstream:!1},e);s.push(...u.removed),t.push(...u.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}removeUnrecognizedOutputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-unrecognized-outputs"))){const t=[],i=[],s=[],l=[];return this.outputs.forEach(o=>{if(!this.declaration.getUniqueReturnDeclarations().find(u=>{var y;return u.id===((y=o.declaration)==null?void 0:y.id)})){const u=o.remove({ignoreUpstream:!1},e);s.push(...u.removed),t.push(...u.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-outputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncMissingFixedInputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const t=[],i=[],s=[],l=[],o=this.declaration.inputs.filter(c=>!this.inputs.find(I=>I.declaration.id===c.id));this.inputs.sort((c,I)=>c.index-I.index),o.forEach(c=>{this.inputs.forEach(O=>{O.index>=c.index&&O.metaSync({index:O.index+1},e)});const I={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,declaration:c.toJSON(),readsValue:null,defaultValue:null,index:c.index,name:null,description:null,parent:this.toReference()},E=C(I,this.project);E.setParent(this,e),E.initChildren(e),e==null||e.add(E,A.Added),E.addSelfToProject(e),i.push(E)}),this.inputs.sort((c,I)=>c.index-I.index);const{updated:d,added:u,removed:y}=this.removeUnrecognizedInputs(e);return t.push(...d),i.push(...u),s.push(...y),e==null||e.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncMissingFixedOutputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-missing-fixed-outputs"))){const t=[],i=[],s=[],l=[],o=[];this.outputs=this.initialData.outputs.map(I=>{const E=C(I,this.project);return o.push(E.index),E.setParent(this,null),E.initChildren(e),E});const d=this.declaration.getUniqueReturnDeclarations().filter(I=>!this.outputs.find(E=>E.declaration.id===I.id));this.outputs.sort((I,E)=>I.index-E.index),d.forEach((I,E)=>{this.outputs.forEach(M=>{M.index>=I.index&&M.index++});const O=o.includes(I.index)?this.outputs.length-1+E:I.index,P={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.OutputMap,declaration:I.toJSON(),defaultValue:null,writesValues:[],index:O,parent:this.toReference()},V=C(P,this.project);V.setParent(this,e),V.initChildren(e),e==null||e.add(V,A.Added),V.addSelfToProject(e)}),this.outputs.sort((I,E)=>I.index-E.index);const{updated:u,added:y,removed:c}=this.removeUnrecognizedOutputs(e);return t.push(...u),i.push(...y),s.push(...c),e==null||e.attemptAutoclose("sync-missing-fixed-outputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}};f(Be,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(Be,"type",n.InternalCall),f(Be,"USER_MANAGED_PARENT_TYPES",[...tt]),f(Be,"PARENT_TYPES",[...Be.USER_MANAGED_PARENT_TYPES]),f(Be,"MUTABLE_BASE_PROPERTIES",[]),f(Be,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Be,"BASE_PROPERTIES",[...Be.MUTABLE_BASE_PROPERTIES,...Be.INMUTABLE_BASE_PROPERTIES]),f(Be,"MUTABLE_META_PROPERTIES",[...Be.MUTABLE_BASE_PROPERTIES,"index"]),f(Be,"INMUTABLE_META_PROPERTIES",[...Be.INMUTABLE_BASE_PROPERTIES]),f(Be,"META_PROPERTIES",[...Be.MUTABLE_META_PROPERTIES,...Be.INMUTABLE_META_PROPERTIES]),f(Be,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),f(Be,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),f(Be,"UPSTREAM_PROPERTIES",[...Be.MUTABLE_UPSTREAM_PROPERTIES,...Be.INMUTABLE_UPSTREAM_PROPERTIES]),f(Be,"MUTABLE_DOWNSTREAM_PROPERTIES",["inputs","outputs","writesValues","successCalls","errorCalls","error"]),f(Be,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Be,"DOWNSTREAM_PROPERTIES",[...Be.MUTABLE_DOWNSTREAM_PROPERTIES,...Be.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Be,"PROPERTIES",[...Be.META_PROPERTIES,...Be.UPSTREAM_PROPERTIES,...Be.DOWNSTREAM_PROPERTIES]);let zr=Be;function w1(r){const a=k5(),e=r.toJSON();a.safeParse(e).success;const i=[];if(r.id==="exec-sequentially-argument-map-id"){const s=de({id:`${r.id}--${F.PropertyImplementsNonAbstact}`,message:`Property "${x(r,r.project)}" with id "${r.id}" implements a non-abstract property "${x(r,r.project)}" with id "${r.id}".`,issue:null,severity:D.Error,code:F.PropertyImplementsNonAbstact,entity:r});i.push(s.error)}return He(r.errors,i)}const $7=Object.freeze(Object.defineProperty({__proto__:null,validate:w1},Symbol.toStringTag,{value:"Module"}));var C1=(r=>(r.Declaration="declaration",r.DataTypeEntity="data-type-entity",r))(C1||{});const _e=class _e extends at{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"index");f(this,"name",null);f(this,"description",null);f(this,"type",n.InputMap);f(this,"defaultValue",null);f(this,"readsValue",null);f(this,"dataType",null);f(this,"declaration",null);f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.index=e.index,this.name=e.name||null,this.description=e.description||null}static new(){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,name:"",description:"",declaration:null,index:0,readsValue:null,defaultValue:null,parent:null}}static fromGenerationTarget(e,t){const i=_(e.parent),s=t.get(i);let l=null;if(e.declaration){const y=_(e.declaration);l=t.get(y)}let o=null;if(e.readsValue){const y=_(e.readsValue);o=t.get(y)}const d={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name||null,type:n.InputMap,index:(s.inputs||[]).length,description:e.description||null,declaration:l,readsValue:o,defaultValue:null,parent:s},u=C(d,t);return u.setParent(s,null),u.initChildren(null),u}static validateGenerationTarget(e,t){var y;let i=JSON.parse(JSON.stringify(e));const s=[],l=At(i,{parent:{list:!1,types:[...ot,n.InputMap]}},t);i=l.modifiedData;const o=t.get(i.parent),d=i.declaration&&(t.get(i.declaration)||t.getBuiltIn(i.declaration)),u=((o==null?void 0:o.inputs)||[]).find(c=>{var I;return i.declaration&&((I=c.declaration)==null?void 0:I.id)===i.declaration});if(i.declaration?d?[n.Property,n.ArgumentDeclaration,n.ValueDescriptor].includes(d.type)?o&&d.type===n.ArgumentDeclaration&&![n.FunctionCall,n.Search,n.InternalCall].includes(o.type)?s.push(new w({id:`${i.id}--${R.InvalidInputMapDeclaration}`,code:R.InvalidInputMapDeclaration,severity:D.Error,message:`Entity of type '${n.InputMap}' with id '${i.id}' has a 'declaration' property pointing to an entity with type '${n.ArgumentDeclaration}' with id '${i.declaration}'.
141
141
  The parent entity of type '${o.type}' with id '${o.id}' is not compatible with this type of declaration.
142
142
  Only 'function-call', 'search' and 'internal-call' entities can have input-maps whose 'declaration' points to 'argument-declaration' entities.`,issue:null})):o&&d.type===n.Property&&!tt.includes(o.type)?s.push(new w({id:`${i.id}--${R.InvalidInputMapDeclaration}`,code:R.InvalidInputMapDeclaration,severity:D.Error,message:`Entity of type '${n.InputMap}' with id '${i.id}' has a 'declaration' property pointing to an entity with type '${n.Property}' with id '${i.declaration}'.
143
143
  The parent entity of type '${o.type}' with id '${o.id}' is not compatible with this type of declaration.
@@ -155,7 +155,7 @@ Input maps can only be added to variables which hold an entity with properties.`
155
155
  The entity of the data-type has the following properties that can be reads as input maps, ids: '${ne(O.properties.map(V=>V.id),"', '","' and '")}'`,issue:null})))}else if(ot.filter(c=>tt.includes(c)).includes(o.type)){const I=Yc(o),E=I.find(P=>P.id===i.declaration),O=`The parent entity has the following argument declarations that can be referenced by input-maps, ids: '${ne(I.map(P=>P.id),"', '","' and '")}'`;E||s.push(new w({id:`${i.id}--${j.NoOverlapWithImplementedSignature}`,code:j.NoOverlapWithImplementedSignature,severity:D.Error,message:`Entity of type '${n.InputMap}' with id '${i.id}' cannot be added to the parent entity of type '${o.type}' with id '${o.id}'. The parent entity does not have an 'argument-declaration' with id '${i.declaration}'.
156
156
  You can't add an input-map to an entity that doesn't have a matching 'argument-declaration'.
157
157
  ${O}`,issue:null}))}}return s.push(...l.errors,...ut(i)),{errors:s,modifiedData:i}}validateGeneratedUpdate(e){const t=[];let i=JSON.parse(JSON.stringify(e));const s=_a(i,this);return i=s.modifiedData,t.push(...s.errors),i.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated, as it would mean moving the '${this.type}' entity to another parent entity.
158
- This is likely an incorrect strategy, either the '${this.type}' entity doesn't need to be updated or it should be deleted and a new one created in the desired parent.`,issue:null})),{errors:t,modifiedData:i}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],i=[],s=[];return Object.values(this.detachedDependents).forEach(l=>{const o=l.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),i.push(...o.removed),s.push(...o.affected)}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="declaration"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="declaration"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e,t,i,s,l;return(t=(e=this.declaration)==null?void 0:e.subscribeDependents)==null||t.call(e,[{entity:this,field:"declaration"}]),(l=(s=(i=this.dataType)==null?void 0:i.entity)==null?void 0:s.subscribeDependents)==null||l.call(s,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new _e(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.declaration=this.declaration,e.defaultValue=this.defaultValue,e.readsValue=this.readsValue,e.dataType=this.dataType,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[I,E]of c.knownVersions)u.set(I,E);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new _e(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.declaration=o.declaration,this.defaultValue=o.defaultValue,this.readsValue=o.readsValue,this.dataType=o.dataType,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.readsValue){const l=_(this.initialData.readsValue),o=this.project.get(l);o&&(this.setValueWriter(o,null),e.push(o))}if(this.initialData.declaration){const l=_(this.initialData.declaration),o=this.project.get(l);o&&(this.setDeclaration(o),e.push(o))}return Ir.hydrateReadsValue(this),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){var o,d;const t=[this],i=[],s=[],l=[];if(this.parent.addInput(this,e),t.push(this.parent),(o=this.readsValue)==null||o.addValueReader(this,e),this.readsValue&&t.push(this.readsValue),tt.includes(this.parent.type)&&((d=this.parent.getDataType(e))!=null&&d.inferred)){const u=this.parent.type===n.VariableDeclaration?this.parent:this.parent.declaration,{updated:y,added:c,removed:I,affected:E}=u.inferDataTypeAndSyncInstancesInputsAndOutputs(e);t.push(...y),i.push(...c),s.push(...I),l.push(...E),t.push(u,...u.variableInstances)}return this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}setDeclaration(e){return this.declaration=e,this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=C(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),this.initialData.declaration&&(this.declaration=C(this.initialData.declaration,this.project)),Ir.initReadsValue(this),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}setValueWriter(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-value-writer"))){return this.readsValue!==e&&(this.readsValue=e,t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("set-value-writer",this.id),this}removeValueWriter(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-value-writer"))){return this.readsValue&&(this.readsValue=null,e==null||e.add(this,A.Updated)),e==null||e.attemptAutoclose("remove-value-writer",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.index=e.index||(e.index!==0?s.index:0),this.name=e.name||s.name,this.description=e.description||s.description,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=g,...t){return await _e.repository.APILoad(this.id,...t),this}async APICreate(e=g,...t){return await _e.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=g,...t){return await _e.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=g,...t){return await _e.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=g,...t){return await _e.repository.APIClone(this.id,...t),this}async APILoadVersion(e=g,t,...i){return await _e.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:y,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...y),l.push(...c)}),this.defaultValue){const{updated:d,removed:u}=this.defaultValue.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}return this.readsValue&&(i.push(this.readsValue),this.readsValue.removeValueReader(this,t)),this.defaultValue&&(i.push(this.defaultValue),this.defaultValue.remove({ignoreUpstream:!0},t)),e||(i.push(this.parent),this.parent.removeInput(this,t)),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.defaultValue){const{updated:o}=this.defaultValue.restore({},e);i.push(...o)}return this.readsValue&&(i.push(this.readsValue),this.readsValue.addValueReader(this,e)),this.defaultValue&&(i.push(this.defaultValue),this.defaultValue.restore({},e)),i.push(this.parent),this.parent.addInput(this,e),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.defaultValue?this.defaultValue.toFlat(e):[],...this.dataType?this.dataType.toFlat(e):[],...this.declaration?this.declaration.toFlat(e):[],...this.readsValue?this.readsValue.toFlat(e):[]])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.defaultValue?this.defaultValue.toFlatIds(e):[],...this.dataType?this.dataType.toFlatIds(e):[],...this.declaration?this.declaration.toFlatIds(e):[],...this.readsValue?this.readsValue.toFlatIds(e):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,index:this.index,type:this.type,name:this.name}}toJSON(e=new Set){var t,i,s;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,index:this.index,name:this.name,description:this.description,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,declaration:((i=this.declaration)==null?void 0:i.toJSON(e))||null,readsValue:((s=this.readsValue)==null?void 0:s.toReference())||null,parent:this.parent.toReference()})}toJSONClone(e=q){var i,s,l,o,d,u,y,c,I,E,O;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,index:this.index,name:this.name,description:this.description,defaultValue:((u=this.defaultValue)==null?void 0:u.toJSONClone({...e,newId:null}))||null,declaration:(y=this.declaration)!=null&&y.id&&this.project.getBuiltIn((c=this.declaration)==null?void 0:c.id)?(I=this.declaration)==null?void 0:I.toJSON(e.seenEntities):((E=this.declaration)==null?void 0:E.toJSONClone({...e,newId:null}))||null,readsValue:((O=this.readsValue)==null?void 0:O.toReference({seenEntityMaps:e.seenEntityMaps}))||null,parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=q){var i,s,l,o;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,defaultValue:((s=this.defaultValue)==null?void 0:s.toReference(e))||null,declaration:((l=this.declaration)==null?void 0:l.toReference(e))||null,readsValue:((o=this.readsValue)==null?void 0:o.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.defaultValue?this.defaultValue.toFlatJSON(e):[],...this.dataType?this.dataType.toFlatJSON(e):[],...this.declaration?this.declaration.toFlatJSON(e):[],...this.readsValue?this.readsValue.toFlatJSON(e):[]])}toGenerationTarget(){var e;return{id:this.id,name:this.name||void 0,description:this.description||void 0,type:this.type,declaration:((e=this.declaration)==null?void 0:e.id)||null,parent:this.parent.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.defaultValue?this.defaultValue.toFlatGenerationTarget(e):[],...this.dataType?this.dataType.toFlatGenerationTarget(e):[],...this.readsValue?this.readsValue.toFlatGenerationTarget(e):[],...this.declaration?this.declaration.toFlatGenerationTarget(e):[]])}clearErrors(){var e;return this.errors=[],(e=this.defaultValue)==null||e.clearErrors(),this}validate(){const e=w1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){var t;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){var e;return this.defaultValue||((e=this.declaration)==null?void 0:e.defaultValue)||null}setDefaultValue(e){return this.defaultValue=e,this}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var c;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.defaultValue=null,o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const u=ct(o,l);t?u.setParent(t,null):u.setParent(this.parent,null),s&&u.subscribe(),u.initChildren(e),e==null||e.add(u,A.Added);const y=(c=this.defaultValue)==null?void 0:c.clone(e,u,m.UUID.uuid(),s);return u.defaultValue=y||null,e==null||e.attemptAutoclose("clone-entity",this.id),u}getDataType(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"get-data-type"))){var i;if(this.parent.type===n.Operation)return this.parent.declaration.inferInputMapDataType(this,e).self;if(tt.includes(this.parent.type)){const s=Nn(this.parent),l=s.getDataType(e);(!l||l.inferred)&&s.inferDataTypeAndSyncInstancesInputsAndOutputs(e)}const t=(i=this.declaration)==null?void 0:i.getDataType(e);if(!t){const s=Ji(this,e);if(s)return s}return t||null}};f(_e,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(_e,"type",n.InputMap),f(_e,"USER_MANAGED_PARENT_TYPES",[...ot]),f(_e,"PARENT_TYPES",[..._e.USER_MANAGED_PARENT_TYPES]),f(_e,"MUTABLE_BASE_PROPERTIES",["name","description"]),f(_e,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(_e,"BASE_PROPERTIES",[..._e.MUTABLE_BASE_PROPERTIES,..._e.INMUTABLE_BASE_PROPERTIES]),f(_e,"MUTABLE_META_PROPERTIES",[..._e.MUTABLE_BASE_PROPERTIES,"index"]),f(_e,"INMUTABLE_META_PROPERTIES",[..._e.INMUTABLE_BASE_PROPERTIES]),f(_e,"META_PROPERTIES",[..._e.MUTABLE_META_PROPERTIES,..._e.INMUTABLE_META_PROPERTIES]),f(_e,"MUTABLE_UPSTREAM_PROPERTIES",["readsValue"]),f(_e,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),f(_e,"UPSTREAM_PROPERTIES",[..._e.MUTABLE_UPSTREAM_PROPERTIES,..._e.INMUTABLE_UPSTREAM_PROPERTIES]),f(_e,"MUTABLE_DOWNSTREAM_PROPERTIES",["defaultValue"]),f(_e,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(_e,"DOWNSTREAM_PROPERTIES",[..._e.MUTABLE_DOWNSTREAM_PROPERTIES,..._e.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(_e,"PROPERTIES",[..._e.META_PROPERTIES,..._e.UPSTREAM_PROPERTIES,..._e.DOWNSTREAM_PROPERTIES]);let Wi=_e;class Gq extends Wi{constructor(e,t){super(e,t);f(this,"declaration",null);f(this,"parent");f(this,"errors",[])}toJSON(e=new Set){return super.toJSON(e)}}class Fq extends Wi{constructor(e,t){super(e,t);f(this,"name",null);f(this,"description",null);f(this,"declaration");f(this,"parent");f(this,"errors",[])}toJSON(e=new Set){return super.toJSON(e)}}function V1(r){const a=A5(),e=r.toJSON();a.safeParse(e).success;const i=[];if(r.id==="exec-sequentially-return-map-id"){const s=de({id:`${r.id}--${F.PropertyImplementsNonAbstact}`,message:`Property "${x(r,r.project)}" with id "${r.id}" implements a non-abstract property "${x(r,r.project)}" with id "${r.id}".`,issue:null,severity:D.Error,code:F.PropertyImplementsNonAbstact,entity:r});i.push(s.error)}return He(r.errors,i)}const xq=Object.freeze(Object.defineProperty({__proto__:null,validate:V1},Symbol.toStringTag,{value:"Module"}));var B1=(r=>(r.Declaration="declaration",r.DataTypeEntity="data-type-entity",r))(B1||{});const Me=class Me extends at{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"index");f(this,"type",n.OutputMap);f(this,"parentRelationType");f(this,"defaultValue",null);f(this,"declaration");f(this,"writesValues",[]);f(this,"dataType");f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.index=e.index,this.parentRelationType=e.parentRelationType}static new(){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.OutputMap,declaration:null,writesValues:[],index:0,defaultValue:null,parent:null}}static fromGenerationTarget(e,t){const i=_(e.parent),s=t.get(i);let l;if(e.declaration){const u=_(e.declaration);l=t.get(u)}const o={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.OutputMap,index:(s.outputs||[]).length,defaultValue:null,declaration:l,writesValues:[],parent:s},d=C(o,t);return d.setParent(s,null),d.initChildren(null),d}static validateGenerationTarget(e,t){var d;let i=JSON.parse(JSON.stringify(e));const s=[],l=At(i,{parent:{list:!1,types:ot.filter(u=>u!==n.Condition)},declaration:{list:!1,types:[n.ReturnDeclaration,n.Property]}},t);i=l.modifiedData;const o=t.get(i.parent);if(o&&ot.filter(u=>u!==n.Condition).includes(o.type)){const u=o.outputs.find(y=>y.declaration.id===(i.declaration?_(i.declaration):null));if(u)s.push(new w({id:`${i.id}--${R.OutputOverwrite}`,code:R.OutputOverwrite,severity:D.Error,message:`Entity of type '${n.OutputMap}' with id '${i.id}' cannot be added to the parent entity of type '${o.type}' with id '${o.id}'. The parent already has an output-map with id '${u.id}' that points to the same base 'return-declaration'.
158
+ This is likely an incorrect strategy, either the '${this.type}' entity doesn't need to be updated or it should be deleted and a new one created in the desired parent.`,issue:null})),{errors:t,modifiedData:i}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],i=[],s=[];return Object.values(this.detachedDependents).forEach(l=>{const o=l.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),i.push(...o.removed),s.push(...o.affected)}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="declaration"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="declaration"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e,t,i,s,l;return(t=(e=this.declaration)==null?void 0:e.subscribeDependents)==null||t.call(e,[{entity:this,field:"declaration"}]),(l=(s=(i=this.dataType)==null?void 0:i.entity)==null?void 0:s.subscribeDependents)==null||l.call(s,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new _e(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.declaration=this.declaration,e.defaultValue=this.defaultValue,e.readsValue=this.readsValue,e.dataType=this.dataType,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[I,E]of c.knownVersions)u.set(I,E);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new _e(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.declaration=o.declaration,this.defaultValue=o.defaultValue,this.readsValue=o.readsValue,this.dataType=o.dataType,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.readsValue){const l=_(this.initialData.readsValue),o=this.project.get(l);o&&(this.setValueWriter(o,null),e.push(o))}if(this.initialData.declaration){const l=_(this.initialData.declaration),o=this.project.get(l);o&&(this.setDeclaration(o),e.push(o))}return Ir.hydrateReadsValue(this),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){var o,d;const t=[this],i=[],s=[],l=[];if(this.parent.addInput(this,e),t.push(this.parent),(o=this.readsValue)==null||o.addValueReader(this,e),this.readsValue&&t.push(this.readsValue),tt.includes(this.parent.type)&&((d=this.parent.getDataType(e))!=null&&d.inferred)){const u=this.parent.type===n.VariableDeclaration?this.parent:this.parent.declaration,{updated:y,added:c,removed:I,affected:E}=u.inferDataTypeAndSyncInstancesInputsAndOutputs(e);t.push(...y),i.push(...c),s.push(...I),l.push(...E),t.push(u,...u.variableInstances)}return this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}setDeclaration(e){return this.declaration=e,this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=C(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),this.initialData.declaration&&(this.declaration=C(this.initialData.declaration,this.project)),Ir.initReadsValue(this),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}setValueWriter(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-value-writer"))){return this.readsValue!==e&&(this.readsValue=e,t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("set-value-writer",this.id),this}removeValueWriter(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-value-writer"))){return this.readsValue&&(this.readsValue=null,e==null||e.add(this,A.Updated)),e==null||e.attemptAutoclose("remove-value-writer",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.index=e.index||(e.index!==0?s.index:0),this.name=e.name||s.name,this.description=e.description||s.description,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=g,...t){return await _e.repository.APILoad(this.id,...t),this}async APICreate(e=g,...t){return await _e.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=g,...t){return await _e.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=g,...t){return await _e.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=g,...t){return await _e.repository.APIClone(this.id,...t),this}async APILoadVersion(e=g,t,...i){return await _e.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:y,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...y),l.push(...c)}),this.defaultValue){const{updated:d,removed:u}=this.defaultValue.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}return this.readsValue&&(i.push(this.readsValue),this.readsValue.removeValueReader(this,t)),this.defaultValue&&(i.push(this.defaultValue),this.defaultValue.remove({ignoreUpstream:!0},t)),e||(i.push(this.parent),this.parent.removeInput(this,t)),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.defaultValue){const{updated:o}=this.defaultValue.restore({},e);i.push(...o)}return this.readsValue&&(i.push(this.readsValue),this.readsValue.addValueReader(this,e)),this.defaultValue&&(i.push(this.defaultValue),this.defaultValue.restore({},e)),i.push(this.parent),this.parent.addInput(this,e),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.defaultValue?this.defaultValue.toFlat(e):[],...this.dataType?this.dataType.toFlat(e):[],...this.declaration?this.declaration.toFlat(e):[],...this.readsValue?this.readsValue.toFlat(e):[]])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.defaultValue?this.defaultValue.toFlatIds(e):[],...this.dataType?this.dataType.toFlatIds(e):[],...this.declaration?this.declaration.toFlatIds(e):[],...this.readsValue?this.readsValue.toFlatIds(e):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,index:this.index,type:this.type,name:this.name}}toJSON(e=new Set){var t,i,s;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,index:this.index,name:this.name,description:this.description,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,declaration:((i=this.declaration)==null?void 0:i.toJSON(e))||null,readsValue:((s=this.readsValue)==null?void 0:s.toReference())||null,parent:this.parent.toReference()})}toJSONClone(e=q){var i,s,l,o,d,u,y,c,I,E,O;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,index:this.index,name:this.name,description:this.description,defaultValue:((u=this.defaultValue)==null?void 0:u.toJSONClone({...e,newId:null}))||null,declaration:(y=this.declaration)!=null&&y.id&&this.project.getBuiltIn((c=this.declaration)==null?void 0:c.id)?(I=this.declaration)==null?void 0:I.toJSON(e.seenEntities):((E=this.declaration)==null?void 0:E.toJSONClone({...e,newId:null}))||null,readsValue:((O=this.readsValue)==null?void 0:O.toReference({seenEntityMaps:e.seenEntityMaps}))||null,parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=q){var i,s,l,o;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,defaultValue:((s=this.defaultValue)==null?void 0:s.toReference(e))||null,declaration:((l=this.declaration)==null?void 0:l.toReference(e))||null,readsValue:((o=this.readsValue)==null?void 0:o.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.defaultValue?this.defaultValue.toFlatJSON(e):[],...this.dataType?this.dataType.toFlatJSON(e):[],...this.declaration?this.declaration.toFlatJSON(e):[],...this.readsValue?this.readsValue.toFlatJSON(e):[]])}toGenerationTarget(){var e;return{id:this.id,name:this.name||void 0,description:this.description||void 0,type:this.type,declaration:((e=this.declaration)==null?void 0:e.id)||null,parent:this.parent.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.defaultValue?this.defaultValue.toFlatGenerationTarget(e):[],...this.dataType?this.dataType.toFlatGenerationTarget(e):[],...this.readsValue?this.readsValue.toFlatGenerationTarget(e):[],...this.declaration?this.declaration.toFlatGenerationTarget(e):[]])}clearErrors(){var e;return this.errors=[],(e=this.defaultValue)==null||e.clearErrors(),this}validate(){const e=w1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){var t;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){var e;return this.defaultValue||((e=this.declaration)==null?void 0:e.defaultValue)||null}setDefaultValue(e){return this.defaultValue=e,this}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var c;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.defaultValue=null,o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const u=ct(o,l);t?u.setParent(t,null):u.setParent(this.parent,null),s&&u.subscribe(),u.initChildren(e),e==null||e.add(u,A.Added);const y=(c=this.defaultValue)==null?void 0:c.clone(e,u,m.UUID.uuid(),s);return u.defaultValue=y||null,e==null||e.attemptAutoclose("clone-entity",this.id),u}getDataType(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"get-data-type"))){var i;if(this.parent.type===n.Operation)return this.parent.declaration.inferInputMapDataType(this,e).self;if(tt.includes(this.parent.type)){const s=Nn(this.parent),l=s.getDataType(e);(!l||l.inferred)&&s.inferDataTypeAndSyncInstancesInputsAndOutputs(e)}const t=(i=this.declaration)==null?void 0:i.getDataType(e);if(!t){const s=Ji(this,e);if(s)return s}return t||null}};f(_e,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(_e,"type",n.InputMap),f(_e,"USER_MANAGED_PARENT_TYPES",[...ot]),f(_e,"PARENT_TYPES",[..._e.USER_MANAGED_PARENT_TYPES]),f(_e,"MUTABLE_BASE_PROPERTIES",["name","description"]),f(_e,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(_e,"BASE_PROPERTIES",[..._e.MUTABLE_BASE_PROPERTIES,..._e.INMUTABLE_BASE_PROPERTIES]),f(_e,"MUTABLE_META_PROPERTIES",[..._e.MUTABLE_BASE_PROPERTIES,"index"]),f(_e,"INMUTABLE_META_PROPERTIES",[..._e.INMUTABLE_BASE_PROPERTIES]),f(_e,"META_PROPERTIES",[..._e.MUTABLE_META_PROPERTIES,..._e.INMUTABLE_META_PROPERTIES]),f(_e,"MUTABLE_UPSTREAM_PROPERTIES",["readsValue"]),f(_e,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),f(_e,"UPSTREAM_PROPERTIES",[..._e.MUTABLE_UPSTREAM_PROPERTIES,..._e.INMUTABLE_UPSTREAM_PROPERTIES]),f(_e,"MUTABLE_DOWNSTREAM_PROPERTIES",["defaultValue"]),f(_e,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(_e,"DOWNSTREAM_PROPERTIES",[..._e.MUTABLE_DOWNSTREAM_PROPERTIES,..._e.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(_e,"PROPERTIES",[..._e.META_PROPERTIES,..._e.UPSTREAM_PROPERTIES,..._e.DOWNSTREAM_PROPERTIES]);let Wi=_e;class G7 extends Wi{constructor(e,t){super(e,t);f(this,"declaration",null);f(this,"parent");f(this,"errors",[])}toJSON(e=new Set){return super.toJSON(e)}}class F7 extends Wi{constructor(e,t){super(e,t);f(this,"name",null);f(this,"description",null);f(this,"declaration");f(this,"parent");f(this,"errors",[])}toJSON(e=new Set){return super.toJSON(e)}}function V1(r){const a=A5(),e=r.toJSON();a.safeParse(e).success;const i=[];if(r.id==="exec-sequentially-return-map-id"){const s=de({id:`${r.id}--${F.PropertyImplementsNonAbstact}`,message:`Property "${x(r,r.project)}" with id "${r.id}" implements a non-abstract property "${x(r,r.project)}" with id "${r.id}".`,issue:null,severity:D.Error,code:F.PropertyImplementsNonAbstact,entity:r});i.push(s.error)}return He(r.errors,i)}const x7=Object.freeze(Object.defineProperty({__proto__:null,validate:V1},Symbol.toStringTag,{value:"Module"}));var B1=(r=>(r.Declaration="declaration",r.DataTypeEntity="data-type-entity",r))(B1||{});const Me=class Me extends at{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"index");f(this,"type",n.OutputMap);f(this,"parentRelationType");f(this,"defaultValue",null);f(this,"declaration");f(this,"writesValues",[]);f(this,"dataType");f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.index=e.index,this.parentRelationType=e.parentRelationType}static new(){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.OutputMap,declaration:null,writesValues:[],index:0,defaultValue:null,parent:null}}static fromGenerationTarget(e,t){const i=_(e.parent),s=t.get(i);let l;if(e.declaration){const u=_(e.declaration);l=t.get(u)}const o={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.OutputMap,index:(s.outputs||[]).length,defaultValue:null,declaration:l,writesValues:[],parent:s},d=C(o,t);return d.setParent(s,null),d.initChildren(null),d}static validateGenerationTarget(e,t){var d;let i=JSON.parse(JSON.stringify(e));const s=[],l=At(i,{parent:{list:!1,types:ot.filter(u=>u!==n.Condition)},declaration:{list:!1,types:[n.ReturnDeclaration,n.Property]}},t);i=l.modifiedData;const o=t.get(i.parent);if(o&&ot.filter(u=>u!==n.Condition).includes(o.type)){const u=o.outputs.find(y=>y.declaration.id===(i.declaration?_(i.declaration):null));if(u)s.push(new w({id:`${i.id}--${R.OutputOverwrite}`,code:R.OutputOverwrite,severity:D.Error,message:`Entity of type '${n.OutputMap}' with id '${i.id}' cannot be added to the parent entity of type '${o.type}' with id '${o.id}'. The parent already has an output-map with id '${u.id}' that points to the same base 'return-declaration'.
159
159
  Any value reads can be done with that output-map instead.
160
160
  You can't edit output-map entities as they need to match their return declarations, so you can only choose to read their outputted value if you need it.`,issue:null}));else{const y=i.declaration?t.get(i.declaration):null;if(y&&tt.includes(o.type)){const c=Nn(o),I=c.dataType,E=(d=c.dataType)==null?void 0:d.entity;I?E?E.type===n.ActionDescriptor?s.push(new w({id:`${i.id}--${j.NoOverlapWithImplementedSignature}`,code:j.NoOverlapWithImplementedSignature,severity:D.Error,message:`Entity of type '${n.OutputMap}' with id '${i.id}' cannot be added to the parent entity of type '${o.type}' with id '${o.id}'. The data type of the 'variable-declaration' is a 'action-descriptor' entity.
161
161
  This means it can hold a function-call or operation as its value, to be executed programatically.
@@ -165,7 +165,7 @@ ${gc}`,issue:null})):s.push(new w({id:`${i.id}--${j.NoOverlapWithImplementedSign
165
165
  ${gc}`,issue:null}))}else if(y){const c=o.outputs.find(I=>I.declaration.id===i.declaration);c&&s.push(new w({id:`${i.id}--${R.OutputOverwrite}`,code:R.OutputOverwrite,severity:D.Error,message:`Entity of type '${n.OutputMap}' with id '${i.id}' cannot be added to the parent entity of type '${o.type}' with id '${o.id}'. The parent already has an output-map with id '${c.id}' that points to the same declaration.
166
166
  Any value reads can be done with that output-map instead.
167
167
  You can't edit output-map entities as they need to match their return declarations, so you can only choose to read their outputted value if you need it.`,issue:null}))}}}return s.push(...l.errors,...ut(i)),{errors:s,modifiedData:i}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated, as it would mean moving the '${this.type}' entity to another parent entity.
168
- This is likely an incorrect strategy, either the '${this.type}' entity doesn't need to be updated or it should be deleted and a new one created in the desired parent.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],i=[],s=[];return Object.values(this.detachedDependents).forEach(l=>{const o=l.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),i.push(...o.removed),s.push(...o.affected)}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="declaration"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="declaration"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e,t,i,s,l;return(t=(e=this.declaration)==null?void 0:e.subscribeDependents)==null||t.call(e,[{entity:this,field:"declaration"}]),(l=(s=(i=this.dataType)==null?void 0:i.entity)==null?void 0:s.subscribeDependents)==null||l.call(s,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Me(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.declaration=this.declaration,e.defaultValue=this.defaultValue,e.writesValues=this.writesValues,e.dataType=this.dataType,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[I,E]of c.knownVersions)u.set(I,E);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Me(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.declaration=o.declaration,this.defaultValue=o.defaultValue,this.writesValues=o.writesValues,this.dataType=o.dataType,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.declaration){const l=_(this.initialData.declaration),o=this.project.get(l);if(o)this.setDeclaration(o),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'declaration' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'declaration'`);return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){var o;const t=[this],i=[],s=[],l=[];return this.parentRelationType===$n.Error?tt.includes(this.parent.type)||(this.parent.error=this):((o=this.declaration)==null?void 0:o.id)===k["value-descriptor"][qa.ActionOngoingProcessOutputValue].id?this.parent.process=this:this.parent.addOutput(this,e),this.writesValues.forEach(d=>{d.setValueWriter(this,e),t.push(d)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addValueReader(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-value-reader"))){return this.writesValues.includes(e)?(t==null||t.attemptAutoclose("add-value-reader",this.id),this):(this.writesValues.push(e),t==null||t.add(this,A.Affected),this)}removeValueReader(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-value-reader"))){return this.writesValues.includes(e)?(this.writesValues=this.writesValues.filter(i=>i.id!==e.id),t==null||t.add(this,A.Affected),this):(t==null||t.attemptAutoclose("remove-value-reader",this.id),this)}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}setDeclaration(e){return this.declaration=e,this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=C(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),$a.initWritesValues(this,this.parent.parent),this.initialData.declaration&&(this.declaration=C(this.initialData.declaration,this.project)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.index=e.index||(e.index!==0?s.index:0),this.parentRelationType=e.parentRelationType!==void 0?e.parentRelationType:this.parentRelationType,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=g,...t){return await Me.repository.APILoad(this.id,...t),this}async APICreate(e=g,...t){return await Me.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=g,...t){return await Me.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=g,...t){return await Me.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=g,...t){return await Me.repository.APIClone(this.id,...t),this}async APILoadVersion(e=g,t,...i){return await Me.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:y,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...y),l.push(...c)}),this.defaultValue){const{updated:d,removed:u}=this.defaultValue.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}return this.writesValues.forEach(d=>{i.push(d),d.readsValue=null}),e||(i.push(this.parent),this.parentRelationType===$n.Error?tt.includes(this.parent.type)||(this.parent.error=null):this.parent.removeOutput(this,t)),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.defaultValue){const{updated:o}=this.defaultValue.restore({},e);i.push(...o)}return this.writesValues.forEach(o=>{i.push(o),o.setValueWriter(this,e)}),i.push(this.parent),this.parentRelationType===$n.Error?tt.includes(this.parent.type)||(this.parent.error=this):this.parent.addOutput(this,e),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this,...((i=this.defaultValue)==null?void 0:i.toFlat(e))||[],...((s=this.dataType)==null?void 0:s.toFlat(e))||[],...this.writesValues.flatMap(l=>l.toFlat(e)),...this.declaration?this.declaration.toFlat(e):[]])}toFlatIds(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((i=this.defaultValue)==null?void 0:i.toFlatIds(e))||[],...((s=this.dataType)==null?void 0:s.toFlatIds(e))||[],...this.writesValues.flatMap(l=>l.toFlatIds(e)),...this.declaration?this.declaration.toFlatIds(e):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,index:this.index,type:this.type}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,index:this.index,parentRelationType:this.parentRelationType,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,writesValues:this.writesValues.map(s=>s.toJSON(e)),declaration:((i=this.declaration)==null?void 0:i.toJSON(e))||null,parent:this.parent.toReference()})}toJSONClone(e=q){var i,s,l,o,d,u,y,c,I,E;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,index:this.index,parentRelationType:this.parentRelationType,defaultValue:((u=this.defaultValue)==null?void 0:u.toJSONClone({...e,newId:null}))||null,writesValues:this.writesValues.map(O=>O.toJSONClone({...e,newId:null})),declaration:(y=this.declaration)!=null&&y.id&&this.project.getBuiltIn((c=this.declaration)==null?void 0:c.id)?(I=this.declaration)==null?void 0:I.toJSON(e.seenEntities):((E=this.declaration)==null?void 0:E.toJSONClone({...e,newId:null}))||null,parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=q){var i,s,l;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,index:this.index,parentRelationType:this.parentRelationType,defaultValue:((s=this.defaultValue)==null?void 0:s.toReference(e))||null,declaration:(l=this.declaration)==null?void 0:l.toReference(e),writesValues:this.writesValues.map(o=>o.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((i=this.defaultValue)==null?void 0:i.toFlatJSON(e))||[],...((s=this.dataType)==null?void 0:s.toFlatJSON(e))||[],...this.writesValues.flatMap(l=>l.toFlatJSON(e)),...this.declaration?this.declaration.toFlatJSON(e):[]])}toGenerationTarget(){var e;return{id:this.id,type:this.type,declaration:((e=this.declaration)==null?void 0:e.id)||null,parent:this.parent.id}}toFlatGenerationTarget(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((i=this.defaultValue)==null?void 0:i.toFlatGenerationTarget(e))||[],...((s=this.dataType)==null?void 0:s.toFlatGenerationTarget(e))||[],...this.writesValues.flatMap(l=>l.toFlatGenerationTarget(e)),...this.declaration?this.declaration.toFlatGenerationTarget(e):[]])}clearErrors(){var e;return this.errors=[],(e=this.defaultValue)==null||e.clearErrors(),this}validate(){const e=V1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){var t;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){var e;return this.defaultValue||((e=this.declaration)==null?void 0:e.defaultValue)||null}setDefaultValue(e){return this.defaultValue=e,this}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var I,E;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.id=d;const u=ct(o,l);t?u.setParent(t,null):u.setParent(this.parent,null),s&&u.subscribe(),u.initChildren(e),e==null||e.add(u,A.Added);const y=(I=this.dataType)==null?void 0:I.clone(e,u,m.UUID.uuid(),s);u.dataType=y||null;const c=(E=this.defaultValue)==null?void 0:E.clone(e,u,m.UUID.uuid(),s);return u.defaultValue=c||null,e==null||e.attemptAutoclose("clone-entity",this.id),u}getDataType(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"get-data-type"))){var i;return this.parent.type===n.Operation?this.parent.declaration.inferOutputMapDataType(this,e).self:((i=this.declaration)==null?void 0:i.getDataType(e))||null}};f(Me,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(Me,"type",n.OutputMap),f(Me,"USER_MANAGED_PARENT_TYPES",[...of]),f(Me,"PARENT_TYPES",[...Me.USER_MANAGED_PARENT_TYPES]),f(Me,"MUTABLE_BASE_PROPERTIES",[]),f(Me,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Me,"BASE_PROPERTIES",[...Me.MUTABLE_BASE_PROPERTIES,...Me.INMUTABLE_BASE_PROPERTIES]),f(Me,"MUTABLE_META_PROPERTIES",[...Me.MUTABLE_BASE_PROPERTIES,"index"]),f(Me,"INMUTABLE_META_PROPERTIES",[...Me.INMUTABLE_BASE_PROPERTIES]),f(Me,"META_PROPERTIES",[...Me.MUTABLE_META_PROPERTIES,...Me.INMUTABLE_META_PROPERTIES]),f(Me,"MUTABLE_UPSTREAM_PROPERTIES",[]),f(Me,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),f(Me,"UPSTREAM_PROPERTIES",[...Me.MUTABLE_UPSTREAM_PROPERTIES,...Me.INMUTABLE_UPSTREAM_PROPERTIES]),f(Me,"MUTABLE_DOWNSTREAM_PROPERTIES",["writesValues"]),f(Me,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Me,"DOWNSTREAM_PROPERTIES",[...Me.MUTABLE_DOWNSTREAM_PROPERTIES,...Me.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Me,"PROPERTIES",[...Me.META_PROPERTIES,...Me.UPSTREAM_PROPERTIES,...Me.DOWNSTREAM_PROPERTIES]);let zi=Me;class kq extends zi{constructor(e,t){super(e,t);f(this,"declaration");f(this,"parent");f(this,"errors",[])}toJSON(e=new Set){return super.toJSON(e)}}class Sq extends zi{constructor(e,t){super(e,t);f(this,"declaration");f(this,"parent");f(this,"errors",[])}toJSON(e=new Set){return super.toJSON(e)}}function _1(r){var s;const a=tZ(),e=r.toJSON();a.safeParse(e).success,(s=r.dataType)==null||s.validate();const i=[];if(r.id==="company-dto-func-declaration-argument-dcl-id"){const l=de({id:`${r.id}--${F.PropertyImplementsNonAbstact}`,message:`Property "${x(r,r.project)}" with id "${r.id}" implements a non-abstract property "${x(r,r.project)}" with id "${r.id}".`,issue:null,severity:D.Error,code:F.PropertyImplementsNonAbstact,entity:r});i.push(l.error)}if(r.id==="manual-hello-world-loop-current-iteration-number-output-map-id"){const l=de({id:`${r.id}--${F.PropertyImplementsNonAbstact}`,message:`Property "${x(r,r.project)}" with id "${r.id}" implements a non-abstract property "${x(r,r.project)}" with id "${r.id}".`,issue:null,severity:D.Error,code:F.PropertyImplementsNonAbstact,entity:r});i.push(l.error)}return He(r.errors,i)}const Zq=Object.freeze(Object.defineProperty({__proto__:null,validate:_1},Symbol.toStringTag,{value:"Module"}));var M1=(r=>(r.DataTypeEntity="data-type-entity",r.Implements="implements",r))(M1||{});const Ne=class Ne extends at{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"index");f(this,"required");f(this,"constant",!0);f(this,"type",n.ArgumentDeclaration);f(this,"defaultValue",null);f(this,"dataType",null);f(this,"writesValues",[]);f(this,"implements",null);f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.index=e.index,this.name=e.name,this.description=e.description,this.required=e.required,this.constant=!0}static new(){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:"",description:"",index:0,required:!1,constant:!0,implements:null,dataType:null,defaultValue:null,writesValues:[],parent:null}}static fromGenerationTarget(e,t){const i=_(e.parent),s=t.get(i),l={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,type:n.ArgumentDeclaration,index:s.inputs.length,defaultValue:null,description:e.description,required:e.required,constant:!0,implements:null,dataType:null,writesValues:[],parent:s},o=C(l,t);return o.setParent(s,null),o.initChildren(null),o}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=At(i,{parent:{list:!1,types:[n.FunctionDeclaration,n.Search,n.Condition]}},t);i=l.modifiedData;const o=Rc(i,t);if(i.parent){const d=t.get(_(i.parent));if(d&&lt.includes(d.type)){const u=d.implements;if(u){const y=u.inputs.find(V=>V.name===i.name),c=u.inputs.filter(V=>!d.inputs.find(G=>G.type===n.ArgumentDeclaration&&G.name===V.name)),I=d.inputs.filter(V=>V.type===n.ArgumentDeclaration),E=I.find(V=>V.name===i.name),O=I.length?`The parent entity already implements the following arguments: ${ne(I.map(V=>`'${V.id}' (${V.name})`),", "," and ")}.`:"The parent entity does not yet have any implemented arguments.",P=c.length?`The parent entity is still missing the following arguments in the implementation: ${ne(c.map(V=>`'${V.id}' (${V.name})`),", "," and ")}.`:"The parent entity has all the arguments it needs implemented.";y?E&&s.push(new w({id:`${i.id}--${j.NoOverlapWithImplementedSignature}`,code:j.NoOverlapWithImplementedSignature,severity:D.Error,message:`Entity of type '${n.ArgumentDeclaration}' with id '${i.id}' should not exist in a parent entity of type '${d.type}' with id '${d.id}' that implements a ${n.ActionDescriptor} with fixed arguments.
168
+ This is likely an incorrect strategy, either the '${this.type}' entity doesn't need to be updated or it should be deleted and a new one created in the desired parent.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],i=[],s=[];return Object.values(this.detachedDependents).forEach(l=>{const o=l.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),i.push(...o.removed),s.push(...o.affected)}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="declaration"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="declaration"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e,t,i,s,l;return(t=(e=this.declaration)==null?void 0:e.subscribeDependents)==null||t.call(e,[{entity:this,field:"declaration"}]),(l=(s=(i=this.dataType)==null?void 0:i.entity)==null?void 0:s.subscribeDependents)==null||l.call(s,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Me(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.declaration=this.declaration,e.defaultValue=this.defaultValue,e.writesValues=this.writesValues,e.dataType=this.dataType,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[I,E]of c.knownVersions)u.set(I,E);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Me(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.declaration=o.declaration,this.defaultValue=o.defaultValue,this.writesValues=o.writesValues,this.dataType=o.dataType,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.declaration){const l=_(this.initialData.declaration),o=this.project.get(l);if(o)this.setDeclaration(o),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'declaration' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'declaration'`);return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){var o;const t=[this],i=[],s=[],l=[];return this.parentRelationType===$n.Error?tt.includes(this.parent.type)||(this.parent.error=this):((o=this.declaration)==null?void 0:o.id)===k["value-descriptor"][qa.ActionOngoingProcessOutputValue].id?this.parent.process=this:this.parent.addOutput(this,e),this.writesValues.forEach(d=>{d.setValueWriter(this,e),t.push(d)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addValueReader(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-value-reader"))){return this.writesValues.includes(e)?(t==null||t.attemptAutoclose("add-value-reader",this.id),this):(this.writesValues.push(e),t==null||t.add(this,A.Affected),this)}removeValueReader(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-value-reader"))){return this.writesValues.includes(e)?(this.writesValues=this.writesValues.filter(i=>i.id!==e.id),t==null||t.add(this,A.Affected),this):(t==null||t.attemptAutoclose("remove-value-reader",this.id),this)}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}setDeclaration(e){return this.declaration=e,this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=C(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),$a.initWritesValues(this,this.parent.parent),this.initialData.declaration&&(this.declaration=C(this.initialData.declaration,this.project)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.index=e.index||(e.index!==0?s.index:0),this.parentRelationType=e.parentRelationType!==void 0?e.parentRelationType:this.parentRelationType,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=g,...t){return await Me.repository.APILoad(this.id,...t),this}async APICreate(e=g,...t){return await Me.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=g,...t){return await Me.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=g,...t){return await Me.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=g,...t){return await Me.repository.APIClone(this.id,...t),this}async APILoadVersion(e=g,t,...i){return await Me.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:y,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...y),l.push(...c)}),this.defaultValue){const{updated:d,removed:u}=this.defaultValue.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}return this.writesValues.forEach(d=>{i.push(d),d.readsValue=null}),e||(i.push(this.parent),this.parentRelationType===$n.Error?tt.includes(this.parent.type)||(this.parent.error=null):this.parent.removeOutput(this,t)),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.defaultValue){const{updated:o}=this.defaultValue.restore({},e);i.push(...o)}return this.writesValues.forEach(o=>{i.push(o),o.setValueWriter(this,e)}),i.push(this.parent),this.parentRelationType===$n.Error?tt.includes(this.parent.type)||(this.parent.error=this):this.parent.addOutput(this,e),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this,...((i=this.defaultValue)==null?void 0:i.toFlat(e))||[],...((s=this.dataType)==null?void 0:s.toFlat(e))||[],...this.writesValues.flatMap(l=>l.toFlat(e)),...this.declaration?this.declaration.toFlat(e):[]])}toFlatIds(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((i=this.defaultValue)==null?void 0:i.toFlatIds(e))||[],...((s=this.dataType)==null?void 0:s.toFlatIds(e))||[],...this.writesValues.flatMap(l=>l.toFlatIds(e)),...this.declaration?this.declaration.toFlatIds(e):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,index:this.index,type:this.type}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,index:this.index,parentRelationType:this.parentRelationType,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,writesValues:this.writesValues.map(s=>s.toJSON(e)),declaration:((i=this.declaration)==null?void 0:i.toJSON(e))||null,parent:this.parent.toReference()})}toJSONClone(e=q){var i,s,l,o,d,u,y,c,I,E;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,index:this.index,parentRelationType:this.parentRelationType,defaultValue:((u=this.defaultValue)==null?void 0:u.toJSONClone({...e,newId:null}))||null,writesValues:this.writesValues.map(O=>O.toJSONClone({...e,newId:null})),declaration:(y=this.declaration)!=null&&y.id&&this.project.getBuiltIn((c=this.declaration)==null?void 0:c.id)?(I=this.declaration)==null?void 0:I.toJSON(e.seenEntities):((E=this.declaration)==null?void 0:E.toJSONClone({...e,newId:null}))||null,parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=q){var i,s,l;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,index:this.index,parentRelationType:this.parentRelationType,defaultValue:((s=this.defaultValue)==null?void 0:s.toReference(e))||null,declaration:(l=this.declaration)==null?void 0:l.toReference(e),writesValues:this.writesValues.map(o=>o.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((i=this.defaultValue)==null?void 0:i.toFlatJSON(e))||[],...((s=this.dataType)==null?void 0:s.toFlatJSON(e))||[],...this.writesValues.flatMap(l=>l.toFlatJSON(e)),...this.declaration?this.declaration.toFlatJSON(e):[]])}toGenerationTarget(){var e;return{id:this.id,type:this.type,declaration:((e=this.declaration)==null?void 0:e.id)||null,parent:this.parent.id}}toFlatGenerationTarget(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((i=this.defaultValue)==null?void 0:i.toFlatGenerationTarget(e))||[],...((s=this.dataType)==null?void 0:s.toFlatGenerationTarget(e))||[],...this.writesValues.flatMap(l=>l.toFlatGenerationTarget(e)),...this.declaration?this.declaration.toFlatGenerationTarget(e):[]])}clearErrors(){var e;return this.errors=[],(e=this.defaultValue)==null||e.clearErrors(),this}validate(){const e=V1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){var t;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){var e;return this.defaultValue||((e=this.declaration)==null?void 0:e.defaultValue)||null}setDefaultValue(e){return this.defaultValue=e,this}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var I,E;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.id=d;const u=ct(o,l);t?u.setParent(t,null):u.setParent(this.parent,null),s&&u.subscribe(),u.initChildren(e),e==null||e.add(u,A.Added);const y=(I=this.dataType)==null?void 0:I.clone(e,u,m.UUID.uuid(),s);u.dataType=y||null;const c=(E=this.defaultValue)==null?void 0:E.clone(e,u,m.UUID.uuid(),s);return u.defaultValue=c||null,e==null||e.attemptAutoclose("clone-entity",this.id),u}getDataType(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"get-data-type"))){var i;return this.parent.type===n.Operation?this.parent.declaration.inferOutputMapDataType(this,e).self:((i=this.declaration)==null?void 0:i.getDataType(e))||null}};f(Me,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(Me,"type",n.OutputMap),f(Me,"USER_MANAGED_PARENT_TYPES",[...of]),f(Me,"PARENT_TYPES",[...Me.USER_MANAGED_PARENT_TYPES]),f(Me,"MUTABLE_BASE_PROPERTIES",[]),f(Me,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Me,"BASE_PROPERTIES",[...Me.MUTABLE_BASE_PROPERTIES,...Me.INMUTABLE_BASE_PROPERTIES]),f(Me,"MUTABLE_META_PROPERTIES",[...Me.MUTABLE_BASE_PROPERTIES,"index"]),f(Me,"INMUTABLE_META_PROPERTIES",[...Me.INMUTABLE_BASE_PROPERTIES]),f(Me,"META_PROPERTIES",[...Me.MUTABLE_META_PROPERTIES,...Me.INMUTABLE_META_PROPERTIES]),f(Me,"MUTABLE_UPSTREAM_PROPERTIES",[]),f(Me,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","declaration"]),f(Me,"UPSTREAM_PROPERTIES",[...Me.MUTABLE_UPSTREAM_PROPERTIES,...Me.INMUTABLE_UPSTREAM_PROPERTIES]),f(Me,"MUTABLE_DOWNSTREAM_PROPERTIES",["writesValues"]),f(Me,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Me,"DOWNSTREAM_PROPERTIES",[...Me.MUTABLE_DOWNSTREAM_PROPERTIES,...Me.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Me,"PROPERTIES",[...Me.META_PROPERTIES,...Me.UPSTREAM_PROPERTIES,...Me.DOWNSTREAM_PROPERTIES]);let zi=Me;class k7 extends zi{constructor(e,t){super(e,t);f(this,"declaration");f(this,"parent");f(this,"errors",[])}toJSON(e=new Set){return super.toJSON(e)}}class S7 extends zi{constructor(e,t){super(e,t);f(this,"declaration");f(this,"parent");f(this,"errors",[])}toJSON(e=new Set){return super.toJSON(e)}}function _1(r){var s;const a=tZ(),e=r.toJSON();a.safeParse(e).success,(s=r.dataType)==null||s.validate();const i=[];if(r.id==="company-dto-func-declaration-argument-dcl-id"){const l=de({id:`${r.id}--${F.PropertyImplementsNonAbstact}`,message:`Property "${x(r,r.project)}" with id "${r.id}" implements a non-abstract property "${x(r,r.project)}" with id "${r.id}".`,issue:null,severity:D.Error,code:F.PropertyImplementsNonAbstact,entity:r});i.push(l.error)}if(r.id==="manual-hello-world-loop-current-iteration-number-output-map-id"){const l=de({id:`${r.id}--${F.PropertyImplementsNonAbstact}`,message:`Property "${x(r,r.project)}" with id "${r.id}" implements a non-abstract property "${x(r,r.project)}" with id "${r.id}".`,issue:null,severity:D.Error,code:F.PropertyImplementsNonAbstact,entity:r});i.push(l.error)}return He(r.errors,i)}const Z7=Object.freeze(Object.defineProperty({__proto__:null,validate:_1},Symbol.toStringTag,{value:"Module"}));var M1=(r=>(r.DataTypeEntity="data-type-entity",r.Implements="implements",r))(M1||{});const Ne=class Ne extends at{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"index");f(this,"required");f(this,"constant",!0);f(this,"type",n.ArgumentDeclaration);f(this,"defaultValue",null);f(this,"dataType",null);f(this,"writesValues",[]);f(this,"implements",null);f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestion",!1);this.initialData=e,this.project=t,this.id=e.id,this.index=e.index,this.name=e.name,this.description=e.description,this.required=e.required,this.constant=!0}static new(){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ArgumentDeclaration,name:"",description:"",index:0,required:!1,constant:!0,implements:null,dataType:null,defaultValue:null,writesValues:[],parent:null}}static fromGenerationTarget(e,t){const i=_(e.parent),s=t.get(i),l={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,type:n.ArgumentDeclaration,index:s.inputs.length,defaultValue:null,description:e.description,required:e.required,constant:!0,implements:null,dataType:null,writesValues:[],parent:s},o=C(l,t);return o.setParent(s,null),o.initChildren(null),o}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=At(i,{parent:{list:!1,types:[n.FunctionDeclaration,n.Search,n.Condition]}},t);i=l.modifiedData;const o=Rc(i,t);if(i.parent){const d=t.get(_(i.parent));if(d&&lt.includes(d.type)){const u=d.implements;if(u){const y=u.inputs.find(V=>V.name===i.name),c=u.inputs.filter(V=>!d.inputs.find(G=>G.type===n.ArgumentDeclaration&&G.name===V.name)),I=d.inputs.filter(V=>V.type===n.ArgumentDeclaration),E=I.find(V=>V.name===i.name),O=I.length?`The parent entity already implements the following arguments: ${ne(I.map(V=>`'${V.id}' (${V.name})`),", "," and ")}.`:"The parent entity does not yet have any implemented arguments.",P=c.length?`The parent entity is still missing the following arguments in the implementation: ${ne(c.map(V=>`'${V.id}' (${V.name})`),", "," and ")}.`:"The parent entity has all the arguments it needs implemented.";y?E&&s.push(new w({id:`${i.id}--${j.NoOverlapWithImplementedSignature}`,code:j.NoOverlapWithImplementedSignature,severity:D.Error,message:`Entity of type '${n.ArgumentDeclaration}' with id '${i.id}' should not exist in a parent entity of type '${d.type}' with id '${d.id}' that implements a ${n.ActionDescriptor} with fixed arguments.
169
169
  Adding a new argument would make the implementation invalid. An argument with the same name already exists in the parent entity.
170
170
  ${O}
171
171
  ${P}`,issue:null})):s.push(new w({id:`${i.id}--${j.NoOverlapWithImplementedSignature}`,code:j.NoOverlapWithImplementedSignature,severity:D.Error,message:`Entity of type '${n.ArgumentDeclaration}' with id '${i.id}' should not exist in a parent entity of type '${d.type}' with id '${d.id}' that implements a ${n.ActionDescriptor} with fixed arguments.
@@ -174,7 +174,7 @@ ${O}
174
174
  ${P}`,issue:null}))}}}return s.push(...l.errors,...o,...ut(i)),{errors:s,modifiedData:i}}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated, as it would mean moving the '${this.type}' entity to another parent entity.
175
175
  This is likely an incorrect strategy, either the '${this.type}' entity doesn't need to be updated or it should be deleted and a new one created in the desired parent.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],i=[],s=[];return Object.values(this.detachedDependents).forEach(l=>{const o=l.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),i.push(...o.removed),s.push(...o.affected)}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];return t==="implements"&&(this.setImplements(null,i),s.push(this)),{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];return t==="implements"&&(this.setImplements(e,i),s.push(this)),{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e,t,i,s,l;return(t=(e=this.implements)==null?void 0:e.subscribeDependents)==null||t.call(e,[{entity:this,field:"implements"}]),(l=(s=(i=this.dataType)==null?void 0:i.entity)==null?void 0:s.subscribeDependents)==null||l.call(s,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ne(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.implements=this.implements,e.defaultValue=this.defaultValue,e.dataType=this.dataType,e.writesValues=this.writesValues,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[I,E]of c.knownVersions)u.set(I,E);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ne(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.implements=o.implements,this.defaultValue=o.defaultValue,this.dataType=o.dataType,this.writesValues=o.writesValues,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.implements){const l=_(this.initialData.implements),o=this.project.get(l);o&&(this.setImplements(o,null),e.push(o))}return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];return this.parent.addInputDeclaration(this,e),t.push(this.parent),this.writesValues.forEach(o=>{o.setValueWriter(this,e),t.push(o)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addValueReader(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-value-reader"))){return this.writesValues.includes(e)?(t==null||t.attemptAutoclose("add-value-reader",this.id),this):(this.writesValues.push(e),t==null||t.add(this,A.Affected),this)}removeValueReader(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-value-reader"))){return this.writesValues.includes(e)?(this.writesValues=this.writesValues.filter(i=>i.id!==e.id),t==null||t.add(this,A.Affected),this):(t==null||t.attemptAutoclose("remove-value-reader",this.id),this)}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setImplements(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-implements"))){var i;return((i=this.implements)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.implements=e,t&&(t==null||t.add(this,A.Updated),t==null||t.attemptAutoclose("set-implements",this.id))),this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=C(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),this.initialData.dataType&&(this.dataType=C(this.initialData.dataType,this.project),this.dataType.setParent(this,null),this.dataType.initChildren(e)),this.initialData.implements){const t=C(this.initialData.implements,this.project);this.setImplements(t,null)}return $a.initWritesValues(this,this.parent),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.index=e.index||(e.index!==0?s.index:0),this.name=e.name||s.name,this.description=e.description||s.description,this.required=e.required!==void 0?e.required:this.required,this.constant=!0,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=g,...t){return await Ne.repository.APILoad(this.id,...t),this}async APICreate(e=g,...t){return await Ne.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=g,...t){return await Ne.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=g,...t){return await Ne.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=g,...t){return await Ne.repository.APIClone(this.id,...t),this}async APILoadVersion(e=g,t,...i){return await Ne.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:y,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...y),l.push(...c)}),this.defaultValue){const{updated:d,removed:u}=this.defaultValue.remove({ignoreUpstream:!0},t);i.push(...d),s.push(...u)}if(this.writesValues.forEach(d=>{i.push(d),d.readsValue=null}),e||(i.push(this.parent),this.parent.removeInputDeclaration(this,t)),this.dataType){const d=this.dataType.remove({ignoreUpstream:!0},t);i.push(...d.updated),s.push(...d.removed)}return t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.defaultValue){const{updated:o}=this.defaultValue.restore({},e);i.push(...o)}if(this.writesValues.forEach(o=>{i.push(o),o.setValueWriter(this,e)}),i.push(this.parent),this.parent.addInputDeclaration(this,e),this.dataType){const{updated:o}=this.dataType.restore({},e);i.push(...o)}return e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this,...((i=this.defaultValue)==null?void 0:i.toFlat(e))||[],...this.writesValues.flatMap(l=>l.toFlat(e)),...((s=this.dataType)==null?void 0:s.toFlat(e))||[]])}toFlatIds(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((i=this.defaultValue)==null?void 0:i.toFlatIds(e))||[],...this.writesValues.flatMap(l=>l.toFlatIds(e)),...((s=this.dataType)==null?void 0:s.toFlatIds(e))||[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,index:this.index,required:this.required,constant:!0,type:this.type,name:this.name}}toJSON(e=new Set){var t,i,s;return e instanceof Set?e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,type:this.type,index:this.index,description:this.description,required:this.required,constant:!0,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,dataType:((i=this.dataType)==null?void 0:i.toJSON(e))||null,implements:((s=this.implements)==null?void 0:s.toJSON(e))||null,writesValues:this.writesValues.map(l=>l.toJSON(e)),parent:this.parent.toReference()}):(console.error("ArgumentDeclarationState.toJSON was called without a valid Set of seenEntities.",`
176
176
  Received type: ${typeof e}
177
- `,e),{})}toJSONClone(e=q){var i,s,l,o,d,u,y,c;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,name:this.name,type:this.type,index:this.index,description:this.description,required:this.required,constant:!0,defaultValue:((u=this.defaultValue)==null?void 0:u.toJSONClone({...e,newId:null}))||null,dataType:((y=this.dataType)==null?void 0:y.toJSONClone({...e,newId:null}))||null,implements:((c=this.implements)==null?void 0:c.toJSONClone({...e,newId:null}))||null,writesValues:this.writesValues.map(I=>I.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=q){var i,s,l,o;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,description:this.description,type:this.type,index:this.index,required:this.required,constant:!0,defaultValue:((s=this.defaultValue)==null?void 0:s.toReference(e))||null,writesValues:this.writesValues.map(d=>d.toReference(e)),implements:((l=this.implements)==null?void 0:l.toReference(e))||null,dataType:((o=this.dataType)==null?void 0:o.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((i=this.defaultValue)==null?void 0:i.toFlatJSON(e))||[],...this.writesValues.flatMap(l=>l.toFlatJSON(e)),...((s=this.dataType)==null?void 0:s.toFlatJSON(e))||[]])}toGenerationTarget(){return{id:this.id,name:this.name,description:this.description,type:this.type,required:this.required,constant:!0,parent:this.parent.id}}toFlatGenerationTarget(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((i=this.defaultValue)==null?void 0:i.toFlatGenerationTarget(e))||[],...this.writesValues.flatMap(l=>l.toFlatGenerationTarget(e)),...((s=this.dataType)==null?void 0:s.toFlatGenerationTarget(e))||[]])}clearErrors(){var e,t;return this.errors=[],(e=this.defaultValue)==null||e.clearErrors(),(t=this.dataType)==null||t.clearErrors(),this}validate(){const e=_1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){var t,i;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[],...((i=this.dataType)==null?void 0:i.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){return(this==null?void 0:this.defaultValue)||null}setDefaultValue(e){return this.defaultValue=e,this}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var I,E;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.dataType=null,o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const u=ct(o,l);t?u.setParent(t,null):u.setParent(this.parent,null),s&&u.subscribe(),u.initChildren(e),e==null||e.add(u,A.Added);const y=(I=this.dataType)==null?void 0:I.clone(e,u,m.UUID.uuid(),s);u.dataType=y||null;const c=(E=this.defaultValue)==null?void 0:E.clone(e,u,m.UUID.uuid(),s);return u.defaultValue=c||null,e==null||e.attemptAutoclose("clone-entity",this.id),u}getDataType(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"get-data-type"))){return this.dataType}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}};f(Ne,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(Ne,"type",n.ArgumentDeclaration),f(Ne,"USER_MANAGED_PARENT_TYPES",[...lt]),f(Ne,"PARENT_TYPES",[...Ne.USER_MANAGED_PARENT_TYPES]),f(Ne,"MUTABLE_BASE_PROPERTIES",["name","description","required"]),f(Ne,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Ne,"BASE_PROPERTIES",[...Ne.MUTABLE_BASE_PROPERTIES,...Ne.INMUTABLE_BASE_PROPERTIES]),f(Ne,"MUTABLE_META_PROPERTIES",[...Ne.MUTABLE_BASE_PROPERTIES,"index"]),f(Ne,"INMUTABLE_META_PROPERTIES",[...Ne.INMUTABLE_BASE_PROPERTIES]),f(Ne,"META_PROPERTIES",[...Ne.MUTABLE_META_PROPERTIES,...Ne.INMUTABLE_META_PROPERTIES]),f(Ne,"MUTABLE_UPSTREAM_PROPERTIES",[]),f(Ne,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements"]),f(Ne,"UPSTREAM_PROPERTIES",[...Ne.MUTABLE_UPSTREAM_PROPERTIES,...Ne.INMUTABLE_UPSTREAM_PROPERTIES]),f(Ne,"MUTABLE_DOWNSTREAM_PROPERTIES",["writesValues","dataType","defaultValue"]),f(Ne,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Ne,"DOWNSTREAM_PROPERTIES",[...Ne.MUTABLE_DOWNSTREAM_PROPERTIES,...Ne.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Ne,"PROPERTIES",[...Ne.META_PROPERTIES,...Ne.UPSTREAM_PROPERTIES,...Ne.DOWNSTREAM_PROPERTIES]);let Yr=Ne;function N1(r){const a=Bp(),e=r.toJSON();a.safeParse(e).success;const i=[];return He(r.errors,i)}const qq=Object.freeze(Object.defineProperty({__proto__:null,validate:N1},Symbol.toStringTag,{value:"Module"}));function Jq(r,a){var t,i;const e=[];if(r.parent)if(r.parent){const s=a.get(r.parent);s?[n.InputMap,n.DataType].includes(s.type)?s.type===n.DataType&&s.entity?e.push(new w({id:`${r.id}--${r.parent}--${R.NewEntityWouldOverriteExisting}`,code:R.NewEntityWouldOverriteExisting,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a 'parent' of type 'data-type' which already has an existing default value entity with id "${s.entity.id}".
177
+ `,e),{})}toJSONClone(e=q){var i,s,l,o,d,u,y,c;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,name:this.name,type:this.type,index:this.index,description:this.description,required:this.required,constant:!0,defaultValue:((u=this.defaultValue)==null?void 0:u.toJSONClone({...e,newId:null}))||null,dataType:((y=this.dataType)==null?void 0:y.toJSONClone({...e,newId:null}))||null,implements:((c=this.implements)==null?void 0:c.toJSONClone({...e,newId:null}))||null,writesValues:this.writesValues.map(I=>I.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=q){var i,s,l,o;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,description:this.description,type:this.type,index:this.index,required:this.required,constant:!0,defaultValue:((s=this.defaultValue)==null?void 0:s.toReference(e))||null,writesValues:this.writesValues.map(d=>d.toReference(e)),implements:((l=this.implements)==null?void 0:l.toReference(e))||null,dataType:((o=this.dataType)==null?void 0:o.toReference(e))||null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((i=this.defaultValue)==null?void 0:i.toFlatJSON(e))||[],...this.writesValues.flatMap(l=>l.toFlatJSON(e)),...((s=this.dataType)==null?void 0:s.toFlatJSON(e))||[]])}toGenerationTarget(){return{id:this.id,name:this.name,description:this.description,type:this.type,required:this.required,constant:!0,parent:this.parent.id}}toFlatGenerationTarget(e=new Set){var i,s;return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...((i=this.defaultValue)==null?void 0:i.toFlatGenerationTarget(e))||[],...this.writesValues.flatMap(l=>l.toFlatGenerationTarget(e)),...((s=this.dataType)==null?void 0:s.toFlatGenerationTarget(e))||[]])}clearErrors(){var e,t;return this.errors=[],(e=this.defaultValue)==null||e.clearErrors(),(t=this.dataType)==null||t.clearErrors(),this}validate(){const e=_1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){var t,i;return[...this.errors,...((t=this.defaultValue)==null?void 0:t.getErrors())||[],...((i=this.dataType)==null?void 0:i.getErrors())||[]]}getShallowErrors(){return this.errors}getDefaultValue(){return(this==null?void 0:this.defaultValue)||null}setDefaultValue(e){return this.defaultValue=e,this}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var I,E;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.dataType=null,o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const u=ct(o,l);t?u.setParent(t,null):u.setParent(this.parent,null),s&&u.subscribe(),u.initChildren(e),e==null||e.add(u,A.Added);const y=(I=this.dataType)==null?void 0:I.clone(e,u,m.UUID.uuid(),s);u.dataType=y||null;const c=(E=this.defaultValue)==null?void 0:E.clone(e,u,m.UUID.uuid(),s);return u.defaultValue=c||null,e==null||e.attemptAutoclose("clone-entity",this.id),u}getDataType(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"get-data-type"))){return this.dataType}setDataType(e){return this.dataType=e,this}removeDataType(){return this.dataType=null,this}};f(Ne,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(Ne,"type",n.ArgumentDeclaration),f(Ne,"USER_MANAGED_PARENT_TYPES",[...lt]),f(Ne,"PARENT_TYPES",[...Ne.USER_MANAGED_PARENT_TYPES]),f(Ne,"MUTABLE_BASE_PROPERTIES",["name","description","required","constant"]),f(Ne,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Ne,"BASE_PROPERTIES",[...Ne.MUTABLE_BASE_PROPERTIES,...Ne.INMUTABLE_BASE_PROPERTIES]),f(Ne,"MUTABLE_META_PROPERTIES",[...Ne.MUTABLE_BASE_PROPERTIES,"index"]),f(Ne,"INMUTABLE_META_PROPERTIES",[...Ne.INMUTABLE_BASE_PROPERTIES]),f(Ne,"META_PROPERTIES",[...Ne.MUTABLE_META_PROPERTIES,...Ne.INMUTABLE_META_PROPERTIES]),f(Ne,"MUTABLE_UPSTREAM_PROPERTIES",[]),f(Ne,"INMUTABLE_UPSTREAM_PROPERTIES",["parent","implements"]),f(Ne,"UPSTREAM_PROPERTIES",[...Ne.MUTABLE_UPSTREAM_PROPERTIES,...Ne.INMUTABLE_UPSTREAM_PROPERTIES]),f(Ne,"MUTABLE_DOWNSTREAM_PROPERTIES",["writesValues","dataType","defaultValue"]),f(Ne,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Ne,"DOWNSTREAM_PROPERTIES",[...Ne.MUTABLE_DOWNSTREAM_PROPERTIES,...Ne.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Ne,"PROPERTIES",[...Ne.META_PROPERTIES,...Ne.UPSTREAM_PROPERTIES,...Ne.DOWNSTREAM_PROPERTIES]);let Yr=Ne;function N1(r){const a=Bp(),e=r.toJSON();a.safeParse(e).success;const i=[];return He(r.errors,i)}const q7=Object.freeze(Object.defineProperty({__proto__:null,validate:N1},Symbol.toStringTag,{value:"Module"}));function J7(r,a){var t,i;const e=[];if(r.parent)if(r.parent){const s=a.get(r.parent);s?[n.InputMap,n.DataType].includes(s.type)?s.type===n.DataType&&s.entity?e.push(new w({id:`${r.id}--${r.parent}--${R.NewEntityWouldOverriteExisting}`,code:R.NewEntityWouldOverriteExisting,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a 'parent' of type 'data-type' which already has an existing default value entity with id "${s.entity.id}".
178
178
  Data types can only have one 'literal-value' entity as 'entity'.
179
179
  You can update the existing 'literal-value' with the 'update' action, for example, like so:
180
180
  \`\`\`json
@@ -198,13 +198,13 @@ You can update the existing 'literal-value' with the 'update' action, for exampl
198
198
  }
199
199
  }
200
200
  }\`\`\`
201
- Or 'delete' and then 'post' actions to replace it.`,issue:null})):e.push(new w({id:`${r.id}--${r.parent}--${R.InvalidParentReference}`,code:R.InvalidParentReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a parent reference that isn't pointing to an entity of type 'input-map' or 'data-type'.`,issue:null})):e.push(new w({id:`${r.id}--${r.parent}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", is referencing an entity with id "${r.parent}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}else e.push(new w({id:`${r.id}--${j.InvalidObjectStructure}`,code:j.InvalidObjectStructure,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}" is missing a 'parent' reference. The 'parent' of a literal value entity must be a reference to an entity of type 'input-map' or 'data-type'.`,issue:null}));else return e.push(new w({id:`${r.id}--${j.InvalidObjectStructure}`,code:j.InvalidObjectStructure,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}" is missing a 'parent' reference. The 'parent' of a literal value entity must be a reference to an entity of type 'input-map' or 'data-type'.`,issue:null})),e;if(r.valueAsTypeSingle){const s=[],l=[],o=r.valueAsTypeSingle;Array.isArray(o)?o.forEach(d=>{typeof d=="string"?l.push(d):s.push(d)}):typeof o=="string"?l.push(o):s.push(o),s.forEach(d=>{const u=$l(d);e.push(...u),u.length===0&&l.push(d.entityId)}),l.forEach(d=>{const u=a.get(d);u?[n.DefinitionEntity,n.BuiltInBaseEntity].includes(u.type)||e.push(new w({id:`${r.id}--${d}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has an 'valueAsTypeSingle' reference that isn't pointing to an entity of type 'definition-entity', 'function-declaration' or 'operation'.`,issue:null})):e.push(new w({id:`${r.id}--${d}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", is referencing an entity with id "${d}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))})}return e}var L1=(r=>(r.ValueAsTypeSingle="value-as-type-single",r.ValueAsTypeList="value-as-type-list",r))(L1||{});const Le=class Le extends at{constructor(e,t){super(e);f(this,"initialData");f(this,"type",n.LiteralValue);f(this,"id");f(this,"name");f(this,"autogeneration",null);f(this,"value",null);f(this,"valueAsTypeSingle",null);f(this,"valueAsTypeList",null);f(this,"errors",[]);f(this,"parent");f(this,"standaloneParent");f(this,"project");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"standalone",!1);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.autogeneration=e.autogeneration,this.value=e.value}static new(){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.LiteralValue,name:"",autogeneration:null,value:null,valueAsTypeSingle:null,valueAsTypeList:null,parent:null}}static fromGenerationTarget(e,t){const i=_(e.parent),s=t.get(i);let l=null,o=null;e.valueAsTypeList?Array.isArray(e.valueAsTypeList)&&(o=e.valueAsTypeList.map(y=>t.get(y)||t.getBuiltIn(y))):e.valueAsTypeSingle&&(l=t.get(e.valueAsTypeSingle)||t.getBuiltIn(e.valueAsTypeSingle));const d={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.LiteralValue,name:e.name,autogeneration:e.autogeneration,valueAsTypeSingle:l,valueAsTypeList:o,value:e.value||null,parent:s},u=C(d,t);return u.setParent(s,null),u.initChildren(null),u}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=Jq(i,t);return s.push(...l,...ut(i)),{errors:s,modifiedData:i}}get valueAsType(){return this.valueAsTypeSingle?this.valueAsTypeSingle:this.valueAsTypeList?this.valueAsTypeList:null}get isFinal(){var e;return!!(this.parent.type===n.Property&&(this.parent.constant||(e=this.parent.implements)!=null&&e.constant)||this.parent.type===n.Property&&this.parent.parent.type===n.DefinitionEntity&&!La(this.parent.parent))}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated, as it would mean moving the '${this.type}' entity to another parent entity.
202
- This is likely an incorrect strategy, either the '${this.type}' entity doesn't need to be updated or it should be deleted and a new one created in the desired parent.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],i=[],s=[];return Object.values(this.detachedDependents).forEach(l=>{const o=l.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),i.push(...o.removed),s.push(...o.affected)}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];return t==="value-as-type-single"&&(this.valueAsTypeSingle=null,i==null||i.add(this,A.Updated)),t==="value-as-type-list"&&(this.valueAsTypeList=(this.valueAsTypeList||[]).filter(u=>u.id!==e.id),i==null||i.add(this,A.Updated)),{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];return t==="value-as-type-single"&&(this.valueAsTypeSingle=e,i==null||i.add(this,A.Updated)),t==="value-as-type-list"&&(this.valueAsTypeList=[...Array.isArray(this.valueAsTypeList||[])?this.valueAsTypeList:[],e],i==null||i.add(this,A.Updated)),{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){return!this.valueAsTypeSingle&&!this.valueAsTypeList?this:(this.valueAsTypeList&&Array.isArray(this.valueAsTypeList)?this.valueAsTypeList.forEach(e=>e.subscribeDependents([{entity:this,field:"value-as-type-list"}])):this.valueAsTypeSingle&&this.valueAsTypeSingle.subscribeDependents([{entity:this,field:"value-as-type-single"}]),this)}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Le(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.valueAsTypeSingle=this.valueAsTypeSingle,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[I,E]of c.knownVersions)u.set(I,E);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Le(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.valueAsTypeSingle=o.valueAsTypeSingle,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.valueAsTypeList&&Array.isArray(this.initialData.valueAsTypeList))this.valueAsTypeList=this.valueAsTypeList||[],this.initialData.valueAsTypeList.forEach(l=>{const o=_(l),d=this.project.get(o);d&&this.valueAsTypeList.push(d)});else if(this.initialData.valueAsTypeSingle){const l=_(this.initialData.valueAsTypeSingle),o=this.project.get(l);o&&(this.valueAsTypeSingle=o)}return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){var o,d;const t=[this],i=[],s=[],l=[];return((o=this.parent)==null?void 0:o.type)===n.DataType?this.parent.setEntity(this):(d=this.parent)==null||d.setDefaultValue(this),t.push(this.parent),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setStandaloneParent(e){return this.standaloneParent=e,this}setValueAsType(e){return e?(Array.isArray(e)?this.valueAsTypeList=e:this.valueAsTypeSingle=e,this):(this.valueAsTypeSingle=null,this.valueAsTypeList=null,this)}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.standalone){if(this.initialData.valueAsTypeList&&Array.isArray(this.initialData.valueAsTypeList))this.valueAsTypeList=this.initialData.valueAsTypeList.map(t=>{if(t.type===n.GenericReference){const s=this.project.findSubscribedBuiltInInstanceFromReference(t);if(!s)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${t.entityType}' with id '${t.entityId}' that is not part of the project state.`);return s}const i=this.project.get(t.id);if(!i)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${t.type}' with id '${t.id}' that is not part of the project state.`);return i});else if(this.initialData.valueAsTypeSingle){if(this.initialData.valueAsTypeSingle.type===n.GenericReference){const i=this.project.findSubscribedBuiltInInstanceFromReference(this.initialData.valueAsTypeSingle);if(!i)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${this.initialData.valueAsTypeSingle.entityType}' with id '${this.initialData.valueAsTypeSingle.entityId}' that is not part of the project state.`);return this.valueAsTypeSingle=i,this}const t=this.project.get(this.initialData.valueAsTypeSingle.id);if(!t)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${this.initialData.valueAsTypeSingle.type}' with id '${this.initialData.valueAsTypeSingle.id}' that is not part of the project state.`);this.valueAsTypeSingle=t}return this}if(this.initialData.valueAsTypeList&&Array.isArray(this.initialData.valueAsTypeList))this.valueAsTypeList=this.initialData.valueAsTypeList.map(t=>{if(t.type===n.GenericReference){const s=this.project.findSubscribedBuiltInInstanceFromReference(t);if(!s)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${t.entityType}' with id '${t.entityId}' that is not part of the project state.`);return s}const i=this.project.get(t.id);if(!i)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${t.type}' with id '${t.id}' that is not part of the project state.`);return i});else if(this.initialData.valueAsTypeSingle){if(this.initialData.valueAsTypeSingle.type===n.GenericReference){const i=_(this.initialData.valueAsTypeSingle),s=i?this.project.get(i):null;if(!s)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${this.initialData.valueAsTypeSingle.entityType}' with id '${this.initialData.valueAsTypeSingle.entityId}' that is not part of the project state.`);return this.valueAsTypeSingle=s,this}const t=this.project.get(this.initialData.valueAsTypeSingle.id);if(!t)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${this.initialData.valueAsTypeSingle.type}' with id '${this.initialData.valueAsTypeSingle.id}' that is not part of the project state.`);this.valueAsTypeSingle=t}return this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.name=e.name||s.name,this.autogeneration=e.autogeneration||s.autogeneration,e.value!==void 0&&(this.value=e.value),super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=g,...t){return await Le.repository.APILoad(this.id,...t),this}async APICreate(e=g,...t){return await Le.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=g,...t){return await Le.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=g,...t){return await Le.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=g,...t){return await Le.repository.APIClone(this.id,...t),this}async APILoadVersion(e=g,t,...i){return await Le.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];return t!=null&&t.hasRemoved(this.id)?(t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:y,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...y),l.push(...c)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this})}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.valueAsTypeSingle?this.valueAsTypeSingle.toFlat(e):[],...this.valueAsTypeList&&Array.isArray(this.valueAsTypeList)?this.valueAsTypeList.flatMap(i=>i.toFlat(e)):[]])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.valueAsTypeSingle?this.valueAsTypeSingle.toFlatIds(e):[],...this.valueAsTypeList&&Array.isArray(this.valueAsTypeList)?this.valueAsTypeList.flatMap(i=>i.toFlatIds(e)):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,value:this.value,autogeneration:this.autogeneration,type:this.type,name:this.name}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,autogeneration:this.autogeneration,value:this.value,valueAsTypeSingle:((t=this.valueAsTypeSingle)==null?void 0:t.toJSON(e))||null,valueAsTypeList:Array.isArray(this.valueAsTypeSingle)?this.valueAsTypeSingle.map(s=>s.toJSON(e)):null,parent:(i=this.parent)==null?void 0:i.toReference()})}toJSONClone(e=q){var i,s,l,o,d,u;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,name:this.name,autogeneration:this.autogeneration,value:this.value,valueAsTypeSingle:this.valueAsTypeSingle?this.project.getBuiltIn(this.valueAsTypeSingle.id)?this.valueAsTypeSingle.toJSON():this.valueAsTypeSingle.toJSONClone({...e,newId:null}):null,valueAsTypeList:this.valueAsTypeSingle&&Array.isArray(this.valueAsTypeSingle)?this.valueAsTypeSingle.map(y=>this.project.getBuiltIn(y.id)?y.toJSON():y.toJSONClone({...e,newId:null})):null,parent:(u=this.parent)==null?void 0:u.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=q){var i,s,l;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,valueAsTypeSingle:((s=this.valueAsTypeSingle)==null?void 0:s.toReference(e))||null,valueAsTypeList:Array.isArray(this.valueAsTypeSingle)?this.valueAsTypeSingle.map(o=>o.toReference(e)):null,value:this.value,autogeneration:this.autogeneration,parent:(l=this.parent)==null?void 0:l.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.valueAsTypeSingle?this.valueAsTypeSingle.toFlatJSON(e):[],...this.valueAsTypeList&&Array.isArray(this.valueAsTypeList)?this.valueAsTypeList.flatMap(i=>i.toFlatJSON(e)):[]])}toGenerationTarget(){var e,t;return{id:this.id,type:this.type,name:this.name,valueAsTypeSingle:((e=this.valueAsTypeSingle)==null?void 0:e.id)||null,valueAsTypeList:Array.isArray(this.valueAsTypeSingle)?this.valueAsTypeSingle.map(i=>i.id):null,value:this.value,autogeneration:this.autogeneration,parent:(t=this.parent)==null?void 0:t.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.valueAsTypeSingle?this.valueAsTypeSingle.toFlatGenerationTarget(e):[],...this.valueAsTypeList&&Array.isArray(this.valueAsTypeList)?this.valueAsTypeList.flatMap(i=>i.toFlatGenerationTarget(e)):[]])}clearErrors(){return this.errors=[],this}validate(){const e=N1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const u=ct(o,l);return u.initChildren(e),t&&u.setParent(t,null),e==null||e.add(u,A.Added),s&&u.subscribe(),e==null||e.attemptAutoclose("clone-entity",this.id),u}merge(e){const t=[],i=[],s=[],l=[];return this.valueAsTypeSingle!==(e==null?void 0:e.valueAsTypeSingle)&&(this.setValueAsType(e.valueAsTypeSingle),t.push(this)),this.value!==e.value&&(this.value=e.value,t.push(this)),this.autogeneration!==e.autogeneration&&(this.autogeneration=e.autogeneration,t.push(this)),this.name!==e.name&&(this.name=e.name,t.push(this)),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}};f(Le,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(Le,"type",n.LiteralValue),f(Le,"USER_MANAGED_PARENT_TYPES",[n.DataType,n.InputMap,n.Property,n.ArgumentDeclaration,n.ReturnDeclaration,n.VariableDeclaration,n.VariableInstance,n.ValueDescriptor,n.OutputMap]),f(Le,"PARENT_TYPES",[...Le.USER_MANAGED_PARENT_TYPES]),f(Le,"MUTABLE_BASE_PROPERTIES",["name","autogeneration","value"]),f(Le,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Le,"BASE_PROPERTIES",[...Le.MUTABLE_BASE_PROPERTIES,...Le.INMUTABLE_BASE_PROPERTIES]),f(Le,"MUTABLE_META_PROPERTIES",[...Le.MUTABLE_BASE_PROPERTIES]),f(Le,"INMUTABLE_META_PROPERTIES",[...Le.INMUTABLE_BASE_PROPERTIES]),f(Le,"META_PROPERTIES",[...Le.MUTABLE_META_PROPERTIES,...Le.INMUTABLE_META_PROPERTIES]),f(Le,"MUTABLE_UPSTREAM_PROPERTIES",[]),f(Le,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),f(Le,"UPSTREAM_PROPERTIES",[...Le.MUTABLE_UPSTREAM_PROPERTIES,...Le.INMUTABLE_UPSTREAM_PROPERTIES]),f(Le,"MUTABLE_DOWNSTREAM_PROPERTIES",["valueAsTypeSingle","valueAsTypeList"]),f(Le,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Le,"DOWNSTREAM_PROPERTIES",[...Le.MUTABLE_DOWNSTREAM_PROPERTIES,...Le.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Le,"PROPERTIES",[...Le.META_PROPERTIES,...Le.UPSTREAM_PROPERTIES,...Le.DOWNSTREAM_PROPERTIES]);let Hr=Le;function U1(r){var s;const a=U3(),e=r.toJSON();a.safeParse(e).success,(s=r.dataType)==null||s.validate();const i=[];return He(r.errors,i)}const Wq=Object.freeze(Object.defineProperty({__proto__:null,validate:U1},Symbol.toStringTag,{value:"Module"}));var g1=(r=>(r.DataTypeEntity="data-type-entity",r))(g1||{});const Ue=class Ue extends at{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"index");f(this,"required");f(this,"parentRelationType");f(this,"type",n.ValueDescriptor);f(this,"defaultValue",null);f(this,"dataType",null);f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description,this.index=e.index,this.required=e.required,this.parentRelationType=e.parentRelationType}static new(){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ValueDescriptor,name:"",description:"",dataType:null,index:0,required:!1,parentRelationType:N.FixedArguments,defaultValue:null,parent:null}}static fromGenerationTarget(e,t){const i=e.parent?_(e.parent):null,s=i?t.get(i):null,l=e.parentRelationType===N.FixedArguments?s==null?void 0:s.inputs.length:s==null?void 0:s.outputs.length,o={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,type:n.ValueDescriptor,index:l||0,description:e.description,required:e.required,defaultValue:null,parentRelationType:e.parentRelationType,dataType:null,parent:s},d=C(o,t);return s&&d.setParent(s,null),d.initChildren(null),d}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=At(i,{parent:{list:!1,types:[n.ActionDescriptor]}},t);i=l.modifiedData,s.push(...l.errors,...ut(i));const o=i.parent&&t.get(i.parent),d=o&&rn(o);return d&&d.type===n.ActionDescriptor&&s.push(new w({id:`${e.id}--${R.BuiltInEntityParent}`,code:R.BuiltInEntityParent,severity:D.Error,message:`Entity of type "${e.type}" with id "${e.id}", has a parent that is a built-in entity "${d.name}" of type '${d.type}' with id '${d.id}'.
201
+ Or 'delete' and then 'post' actions to replace it.`,issue:null})):e.push(new w({id:`${r.id}--${r.parent}--${R.InvalidParentReference}`,code:R.InvalidParentReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a parent reference that isn't pointing to an entity of type 'input-map' or 'data-type'.`,issue:null})):e.push(new w({id:`${r.id}--${r.parent}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", is referencing an entity with id "${r.parent}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}else e.push(new w({id:`${r.id}--${j.InvalidObjectStructure}`,code:j.InvalidObjectStructure,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}" is missing a 'parent' reference. The 'parent' of a literal value entity must be a reference to an entity of type 'input-map' or 'data-type'.`,issue:null}));else return e.push(new w({id:`${r.id}--${j.InvalidObjectStructure}`,code:j.InvalidObjectStructure,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}" is missing a 'parent' reference. The 'parent' of a literal value entity must be a reference to an entity of type 'input-map' or 'data-type'.`,issue:null})),e;if(r.valueAsTypeSingle){const s=[],l=[],o=r.valueAsTypeSingle;Array.isArray(o)?o.forEach(d=>{typeof d=="string"?l.push(d):s.push(d)}):typeof o=="string"?l.push(o):s.push(o),s.forEach(d=>{const u=$l(d);e.push(...u),u.length===0&&l.push(d.entityId)}),l.forEach(d=>{const u=a.get(d);u?[n.DefinitionEntity,n.BuiltInBaseEntity].includes(u.type)||e.push(new w({id:`${r.id}--${d}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has an 'valueAsTypeSingle' reference that isn't pointing to an entity of type 'definition-entity', 'function-declaration' or 'operation'.`,issue:null})):e.push(new w({id:`${r.id}--${d}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", is referencing an entity with id "${d}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))})}return e}var L1=(r=>(r.ValueAsTypeSingle="value-as-type-single",r.ValueAsTypeList="value-as-type-list",r))(L1||{});const Le=class Le extends at{constructor(e,t){super(e);f(this,"initialData");f(this,"type",n.LiteralValue);f(this,"id");f(this,"name");f(this,"autogeneration",null);f(this,"value",null);f(this,"valueAsTypeSingle",null);f(this,"valueAsTypeList",null);f(this,"errors",[]);f(this,"parent");f(this,"standaloneParent");f(this,"project");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"standalone",!1);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.autogeneration=e.autogeneration,this.value=e.value}static new(){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.LiteralValue,name:"",autogeneration:null,value:null,valueAsTypeSingle:null,valueAsTypeList:null,parent:null}}static fromGenerationTarget(e,t){const i=_(e.parent),s=t.get(i);let l=null,o=null;e.valueAsTypeList?Array.isArray(e.valueAsTypeList)&&(o=e.valueAsTypeList.map(y=>t.get(y)||t.getBuiltIn(y))):e.valueAsTypeSingle&&(l=t.get(e.valueAsTypeSingle)||t.getBuiltIn(e.valueAsTypeSingle));const d={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.LiteralValue,name:e.name,autogeneration:e.autogeneration,valueAsTypeSingle:l,valueAsTypeList:o,value:e.value||null,parent:s},u=C(d,t);return u.setParent(s,null),u.initChildren(null),u}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=J7(i,t);return s.push(...l,...ut(i)),{errors:s,modifiedData:i}}get valueAsType(){return this.valueAsTypeSingle?this.valueAsTypeSingle:this.valueAsTypeList?this.valueAsTypeList:null}get isFinal(){var e;return!!(this.parent.type===n.Property&&(this.parent.constant||(e=this.parent.implements)!=null&&e.constant)||this.parent.type===n.Property&&this.parent.parent.type===n.DefinitionEntity&&!La(this.parent.parent))}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated, as it would mean moving the '${this.type}' entity to another parent entity.
202
+ This is likely an incorrect strategy, either the '${this.type}' entity doesn't need to be updated or it should be deleted and a new one created in the desired parent.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],i=[],s=[];return Object.values(this.detachedDependents).forEach(l=>{const o=l.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),i.push(...o.removed),s.push(...o.affected)}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];return t==="value-as-type-single"&&(this.valueAsTypeSingle=null,i==null||i.add(this,A.Updated)),t==="value-as-type-list"&&(this.valueAsTypeList=(this.valueAsTypeList||[]).filter(u=>u.id!==e.id),i==null||i.add(this,A.Updated)),{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];return t==="value-as-type-single"&&(this.valueAsTypeSingle=e,i==null||i.add(this,A.Updated)),t==="value-as-type-list"&&(this.valueAsTypeList=[...Array.isArray(this.valueAsTypeList||[])?this.valueAsTypeList:[],e],i==null||i.add(this,A.Updated)),{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){return!this.valueAsTypeSingle&&!this.valueAsTypeList?this:(this.valueAsTypeList&&Array.isArray(this.valueAsTypeList)?this.valueAsTypeList.forEach(e=>e.subscribeDependents([{entity:this,field:"value-as-type-list"}])):this.valueAsTypeSingle&&this.valueAsTypeSingle.subscribeDependents([{entity:this,field:"value-as-type-single"}]),this)}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Le(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.valueAsTypeSingle=this.valueAsTypeSingle,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[I,E]of c.knownVersions)u.set(I,E);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Le(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.valueAsTypeSingle=o.valueAsTypeSingle,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.valueAsTypeList&&Array.isArray(this.initialData.valueAsTypeList))this.valueAsTypeList=this.valueAsTypeList||[],this.initialData.valueAsTypeList.forEach(l=>{const o=_(l),d=this.project.get(o);d&&this.valueAsTypeList.push(d)});else if(this.initialData.valueAsTypeSingle){const l=_(this.initialData.valueAsTypeSingle),o=this.project.get(l);o&&(this.valueAsTypeSingle=o)}return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){var o,d;const t=[this],i=[],s=[],l=[];return((o=this.parent)==null?void 0:o.type)===n.DataType?this.parent.setEntity(this):(d=this.parent)==null||d.setDefaultValue(this),t.push(this.parent),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setStandaloneParent(e){return this.standaloneParent=e,this}setValueAsType(e){return e?(Array.isArray(e)?this.valueAsTypeList=e:this.valueAsTypeSingle=e,this):(this.valueAsTypeSingle=null,this.valueAsTypeList=null,this)}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.standalone){if(this.initialData.valueAsTypeList&&Array.isArray(this.initialData.valueAsTypeList))this.valueAsTypeList=this.initialData.valueAsTypeList.map(t=>{if(t.type===n.GenericReference){const s=this.project.findSubscribedBuiltInInstanceFromReference(t);if(!s)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${t.entityType}' with id '${t.entityId}' that is not part of the project state.`);return s}const i=this.project.get(t.id);if(!i)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${t.type}' with id '${t.id}' that is not part of the project state.`);return i});else if(this.initialData.valueAsTypeSingle){if(this.initialData.valueAsTypeSingle.type===n.GenericReference){const i=this.project.findSubscribedBuiltInInstanceFromReference(this.initialData.valueAsTypeSingle);if(!i)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${this.initialData.valueAsTypeSingle.entityType}' with id '${this.initialData.valueAsTypeSingle.entityId}' that is not part of the project state.`);return this.valueAsTypeSingle=i,this}const t=this.project.get(this.initialData.valueAsTypeSingle.id);if(!t)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${this.initialData.valueAsTypeSingle.type}' with id '${this.initialData.valueAsTypeSingle.id}' that is not part of the project state.`);this.valueAsTypeSingle=t}return this}if(this.initialData.valueAsTypeList&&Array.isArray(this.initialData.valueAsTypeList))this.valueAsTypeList=this.initialData.valueAsTypeList.map(t=>{if(t.type===n.GenericReference){const s=this.project.findSubscribedBuiltInInstanceFromReference(t);if(!s)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${t.entityType}' with id '${t.entityId}' that is not part of the project state.`);return s}const i=this.project.get(t.id);if(!i)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${t.type}' with id '${t.id}' that is not part of the project state.`);return i});else if(this.initialData.valueAsTypeSingle){if(this.initialData.valueAsTypeSingle.type===n.GenericReference){const i=_(this.initialData.valueAsTypeSingle),s=i?this.project.get(i):null;if(!s)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${this.initialData.valueAsTypeSingle.entityType}' with id '${this.initialData.valueAsTypeSingle.entityId}' that is not part of the project state.`);return this.valueAsTypeSingle=s,this}const t=this.project.get(this.initialData.valueAsTypeSingle.id);if(!t)throw new Error(`Standalone entity of type '${this.type}' with id '${this.id}' has a reference to an entity of type '${this.initialData.valueAsTypeSingle.type}' with id '${this.initialData.valueAsTypeSingle.id}' that is not part of the project state.`);this.valueAsTypeSingle=t}return this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.name=e.name||s.name,this.autogeneration=e.autogeneration||s.autogeneration,e.value!==void 0&&(this.value=e.value),super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=g,...t){return await Le.repository.APILoad(this.id,...t),this}async APICreate(e=g,...t){return await Le.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=g,...t){return await Le.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=g,...t){return await Le.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=g,...t){return await Le.repository.APIClone(this.id,...t),this}async APILoadVersion(e=g,t,...i){return await Le.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];return t!=null&&t.hasRemoved(this.id)?(t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:y,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...y),l.push(...c)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this})}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.valueAsTypeSingle?this.valueAsTypeSingle.toFlat(e):[],...this.valueAsTypeList&&Array.isArray(this.valueAsTypeList)?this.valueAsTypeList.flatMap(i=>i.toFlat(e)):[]])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.valueAsTypeSingle?this.valueAsTypeSingle.toFlatIds(e):[],...this.valueAsTypeList&&Array.isArray(this.valueAsTypeList)?this.valueAsTypeList.flatMap(i=>i.toFlatIds(e)):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,value:this.value,autogeneration:this.autogeneration,type:this.type,name:this.name}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,autogeneration:this.autogeneration,value:this.value,valueAsTypeSingle:((t=this.valueAsTypeSingle)==null?void 0:t.toJSON(e))||null,valueAsTypeList:Array.isArray(this.valueAsTypeSingle)?this.valueAsTypeSingle.map(s=>s.toJSON(e)):null,parent:(i=this.parent)==null?void 0:i.toReference()})}toJSONClone(e=q){var i,s,l,o,d,u;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,name:this.name,autogeneration:this.autogeneration,value:this.value,valueAsTypeSingle:this.valueAsTypeSingle?this.project.getBuiltIn(this.valueAsTypeSingle.id)?this.valueAsTypeSingle.toJSON():this.valueAsTypeSingle.toJSONClone({...e,newId:null}):null,valueAsTypeList:this.valueAsTypeSingle&&Array.isArray(this.valueAsTypeSingle)?this.valueAsTypeSingle.map(y=>this.project.getBuiltIn(y.id)?y.toJSON():y.toJSONClone({...e,newId:null})):null,parent:(u=this.parent)==null?void 0:u.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=q){var i,s,l;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,valueAsTypeSingle:((s=this.valueAsTypeSingle)==null?void 0:s.toReference(e))||null,valueAsTypeList:Array.isArray(this.valueAsTypeSingle)?this.valueAsTypeSingle.map(o=>o.toReference(e)):null,value:this.value,autogeneration:this.autogeneration,parent:(l=this.parent)==null?void 0:l.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.valueAsTypeSingle?this.valueAsTypeSingle.toFlatJSON(e):[],...this.valueAsTypeList&&Array.isArray(this.valueAsTypeList)?this.valueAsTypeList.flatMap(i=>i.toFlatJSON(e)):[]])}toGenerationTarget(){var e,t;return{id:this.id,type:this.type,name:this.name,valueAsTypeSingle:((e=this.valueAsTypeSingle)==null?void 0:e.id)||null,valueAsTypeList:Array.isArray(this.valueAsTypeSingle)?this.valueAsTypeSingle.map(i=>i.id):null,value:this.value,autogeneration:this.autogeneration,parent:(t=this.parent)==null?void 0:t.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.valueAsTypeSingle?this.valueAsTypeSingle.toFlatGenerationTarget(e):[],...this.valueAsTypeList&&Array.isArray(this.valueAsTypeList)?this.valueAsTypeList.flatMap(i=>i.toFlatGenerationTarget(e)):[]])}clearErrors(){return this.errors=[],this}validate(){const e=N1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const u=ct(o,l);return u.initChildren(e),t&&u.setParent(t,null),e==null||e.add(u,A.Added),s&&u.subscribe(),e==null||e.attemptAutoclose("clone-entity",this.id),u}merge(e){const t=[],i=[],s=[],l=[];return this.valueAsTypeSingle!==(e==null?void 0:e.valueAsTypeSingle)&&(this.setValueAsType(e.valueAsTypeSingle),t.push(this)),this.value!==e.value&&(this.value=e.value,t.push(this)),this.autogeneration!==e.autogeneration&&(this.autogeneration=e.autogeneration,t.push(this)),this.name!==e.name&&(this.name=e.name,t.push(this)),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}};f(Le,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(Le,"type",n.LiteralValue),f(Le,"USER_MANAGED_PARENT_TYPES",[n.DataType,n.InputMap,n.Property,n.ArgumentDeclaration,n.ReturnDeclaration,n.VariableDeclaration,n.VariableInstance,n.ValueDescriptor,n.OutputMap]),f(Le,"PARENT_TYPES",[...Le.USER_MANAGED_PARENT_TYPES]),f(Le,"MUTABLE_BASE_PROPERTIES",["name","autogeneration","value"]),f(Le,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Le,"BASE_PROPERTIES",[...Le.MUTABLE_BASE_PROPERTIES,...Le.INMUTABLE_BASE_PROPERTIES]),f(Le,"MUTABLE_META_PROPERTIES",[...Le.MUTABLE_BASE_PROPERTIES]),f(Le,"INMUTABLE_META_PROPERTIES",[...Le.INMUTABLE_BASE_PROPERTIES]),f(Le,"META_PROPERTIES",[...Le.MUTABLE_META_PROPERTIES,...Le.INMUTABLE_META_PROPERTIES]),f(Le,"MUTABLE_UPSTREAM_PROPERTIES",[]),f(Le,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),f(Le,"UPSTREAM_PROPERTIES",[...Le.MUTABLE_UPSTREAM_PROPERTIES,...Le.INMUTABLE_UPSTREAM_PROPERTIES]),f(Le,"MUTABLE_DOWNSTREAM_PROPERTIES",["valueAsTypeSingle","valueAsTypeList"]),f(Le,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Le,"DOWNSTREAM_PROPERTIES",[...Le.MUTABLE_DOWNSTREAM_PROPERTIES,...Le.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Le,"PROPERTIES",[...Le.META_PROPERTIES,...Le.UPSTREAM_PROPERTIES,...Le.DOWNSTREAM_PROPERTIES]);let Hr=Le;function U1(r){var s;const a=U3(),e=r.toJSON();a.safeParse(e).success,(s=r.dataType)==null||s.validate();const i=[];return He(r.errors,i)}const W7=Object.freeze(Object.defineProperty({__proto__:null,validate:U1},Symbol.toStringTag,{value:"Module"}));var g1=(r=>(r.DataTypeEntity="data-type-entity",r))(g1||{});const Ue=class Ue extends at{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"index");f(this,"required");f(this,"parentRelationType");f(this,"type",n.ValueDescriptor);f(this,"defaultValue",null);f(this,"dataType",null);f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description,this.index=e.index,this.required=e.required,this.parentRelationType=e.parentRelationType}static new(){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.ValueDescriptor,name:"",description:"",dataType:null,index:0,required:!1,parentRelationType:N.FixedArguments,defaultValue:null,parent:null}}static fromGenerationTarget(e,t){const i=e.parent?_(e.parent):null,s=i?t.get(i):null,l=e.parentRelationType===N.FixedArguments?s==null?void 0:s.inputs.length:s==null?void 0:s.outputs.length,o={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,type:n.ValueDescriptor,index:l||0,description:e.description,required:e.required,defaultValue:null,parentRelationType:e.parentRelationType,dataType:null,parent:s},d=C(o,t);return s&&d.setParent(s,null),d.initChildren(null),d}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=At(i,{parent:{list:!1,types:[n.ActionDescriptor]}},t);i=l.modifiedData,s.push(...l.errors,...ut(i));const o=i.parent&&t.get(i.parent),d=o&&rn(o);return d&&d.type===n.ActionDescriptor&&s.push(new w({id:`${e.id}--${R.BuiltInEntityParent}`,code:R.BuiltInEntityParent,severity:D.Error,message:`Entity of type "${e.type}" with id "${e.id}", has a parent that is a built-in entity "${d.name}" of type '${d.type}' with id '${d.id}'.
203
203
  You can't modify system entities that are built-in.`,issue:null})),o&&o.type===n.ActionDescriptor&&(!i.parentRelationType||!(i.parentRelationType===N.FixedArguments||i.parentRelationType===N.FixedReturns||i.parentRelationType===N.ReturnedError||i.parentRelationType===N.DynamicArgument||i.parentRelationType===N.DynamicReturn)?s.push(new w({id:`${e.id}--${R.InvalidParentRelationType}`,code:R.InvalidParentRelationType,severity:D.Error,message:`The entity with id '${e.id}' and type '${e.type}', must have a 'parentRelationType' property set to either '${N.FixedArguments}', '${N.FixedReturns}', or '${N.ReturnedError}' when being added as a child to an entity of type 'action-descriptor'.`,issue:null})):i.parentRelationType===N.ReturnedError&&o.error&&s.push(new w({id:`${e.id}--${R.NewEntityWouldOverriteExisting}`,code:R.NewEntityWouldOverriteExisting,severity:D.Error,message:`The entity with id '${e.id}' and type '${e.type}', is being added as an error value-descriptor to an entity of type 'action-descriptor' with id '${o.id}', which already has an error value descriptor with id '${o.error.id}'.
204
204
  An action descriptor can only have one error value descriptor child.
205
205
  Either remove the existing error value descriptor or update it with the 'update' action.
206
206
  You can use the 'describe_entity' action to get more information about the existing error value descriptor like so:
207
- ${Yi({describe_entity:o.error.id})}`,issue:null}))),{errors:s,modifiedData:i}}validateGeneratedUpdate(e){return{errors:[],modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],i=[],s=[];return Object.values(this.detachedDependents).forEach(l=>{const o=l.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),i.push(...o.removed),s.push(...o.affected)}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e,t,i;return(i=(t=(e=this.dataType)==null?void 0:e.entity)==null?void 0:t.subscribeDependents)==null||i.call(t,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ue(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.defaultValue=this.defaultValue,e.dataType=this.dataType,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[I,E]of c.knownVersions)u.set(I,E);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ue(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.defaultValue=o.defaultValue,this.dataType=o.dataType,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw console.warn("No parent found for entity",this.initialData),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){var o,d,u,y,c,I,E,O;const t=[this],i=[],s=[],l=[];return this.parentRelationType===N.FixedArguments||this.parentRelationType===N.DynamicArgument?((o=this.parent)==null?void 0:o.type)===n.Search||((d=this.parent)==null?void 0:d.type)===n.Loop?(this.parent.addInputDeclaration(this,e),t.push(this.parent)):((y=(u=this.parent)==null?void 0:u.addInput)==null||y.call(u,this),t.push(this.parent)):this.parentRelationType===N.FixedReturns||this.parentRelationType===N.DynamicReturn?((c=this.parent)==null?void 0:c.type)===n.Search||((I=this.parent)==null?void 0:I.type)===n.Loop?(this.parent.addOutputDeclaration(this,e),t.push(this.parent)):((O=(E=this.parent)==null?void 0:E.addOutput)==null||O.call(E,this),t.push(this.parent)):this.parentRelationType===N.ReturnedError&&this.parent&&(this.parent.error=this,t.push(this.parent)),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=C(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),this.initialData.dataType&&(this.dataType=C(this.initialData.dataType,this.project),this.dataType.setParent(this,null),this.dataType.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.name=e.name||s.name,this.description=e.description||s.description,this.index=e.index||(e.index!==0?s.index:0),this.required=e.required!==void 0?e.required:this.required,this.parentRelationType=e.parentRelationType!==void 0?e.parentRelationType:this.parentRelationType,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=g,...t){return await Ue.repository.APILoad(this.id,...t),this}async APICreate(e=g,...t){return await Ue.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=g,...t){return await Ue.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=g,...t){return await Ue.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=g,...t){return await Ue.repository.APIClone(this.id,...t),this}async APILoadVersion(e=g,t,...i){return await Ue.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){var u,y,c,I,E,O,P;const i=[],s=[],l=[],o=[];if(Array.from(new Set([..._i(),...this.project.getAllBuiltInIds()])).includes(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),console.log("Built-in entity, cannot remove: ",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(V=>{const{updated:M,removed:G,added:B}=V.entity.onDetachedDependencyRemoved(this,V.field,t);i.push(...M),s.push(...G),l.push(...B)}),this.defaultValue){const{updated:V,removed:M}=this.defaultValue.remove({ignoreUpstream:!0},t);i.push(...V),s.push(...M)}if(this.dataType){const{updated:V,removed:M}=this.dataType.remove({ignoreUpstream:!0},t);i.push(...V),s.push(...M)}return e||(((u=this.parent)==null?void 0:u.type)===n.Search?this.parentRelationType===N.FixedReturns||this.parentRelationType===N.DynamicReturn?(y=this.parent)==null||y.removeOutputDeclaration(this,t):this.parentRelationType===N.FixedArguments||this.parentRelationType===N.DynamicArgument?(c=this.parent)==null||c.removeInputDeclaration(this,t):this.parentRelationType===N.ReturnedError&&(this.parent.error=null):((I=this.parent)==null?void 0:I.type)===n.Loop?this.parentRelationType===N.FixedReturns||this.parentRelationType===N.DynamicReturn?(E=this.parent)==null||E.removeOutputDeclaration(this,t):this.parentRelationType===N.ReturnedError&&(this.parent.error=null):this.parentRelationType===N.FixedReturns||this.parentRelationType===N.DynamicReturn?(O=this.parent)==null||O.removeOutput(this,t):(this.parentRelationType===N.FixedArguments||this.parentRelationType===N.DynamicArgument)&&((P=this.parent)==null||P.removeInput(this,t))),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){var o,d,u,y,c,I,E;const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.defaultValue){const{updated:O}=this.defaultValue.restore({},e);i.push(...O)}if(this.dataType){const{updated:O}=this.dataType.restore({},e);i.push(...O)}return((o=this.parent)==null?void 0:o.type)===n.Search?this.parentRelationType===N.FixedReturns||this.parentRelationType===N.DynamicReturn?(d=this.parent)==null||d.addOutputDeclaration(this,e):(this.parentRelationType===N.FixedArguments||this.parentRelationType===N.DynamicArgument)&&((u=this.parent)==null||u.addInputDeclaration(this,e)):((y=this.parent)==null?void 0:y.type)===n.Loop?(this.parentRelationType===N.FixedReturns||this.parentRelationType===N.DynamicReturn)&&((c=this.parent)==null||c.addOutputDeclaration(this,e)):this.parentRelationType===N.FixedReturns||this.parentRelationType===N.DynamicReturn?(I=this.parent)==null||I.addOutput(this,e):(this.parentRelationType===N.FixedArguments||this.parentRelationType===N.DynamicArgument)&&((E=this.parent)==null||E.addInput(this,e)),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){var i;return e.has(this.id)?[]:(e.add(this.id),[this,...((i=this.defaultValue)==null?void 0:i.toFlat(e))||[],...this.dataType?this.dataType.toFlat(e):[]])}toFlatIds(e=new Set){var i;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((i=this.defaultValue)==null?void 0:i.toFlatIds(e))||[],...this.dataType?this.dataType.toFlatIds(e):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,index:this.index,required:this.required,parentRelationType:this.parentRelationType,type:this.type,name:this.name}}toJSON(e=new Set){var t,i,s;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,required:this.required,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,parentRelationType:this.parentRelationType,dataType:((i=this.dataType)==null?void 0:i.toJSON(e))||null,parent:((s=this.parent)==null?void 0:s.toReference())||null})}toJSONClone(e=q){var i,s,l,o,d,u,y,c;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:this.type,name:this.name,description:this.description,index:this.index,required:this.required,defaultValue:((u=this.defaultValue)==null?void 0:u.toJSONClone({...e,newId:null}))||null,parentRelationType:this.parentRelationType,dataType:((y=this.dataType)==null?void 0:y.toJSONClone({...e,newId:null}))||null,parent:((c=this.parent)==null?void 0:c.toReference({seenEntityMaps:e.seenEntityMaps}))||null})}toReference(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=q){var i,s,l,o;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,required:this.required,parentRelationType:this.parentRelationType,defaultValue:((s=this.defaultValue)==null?void 0:s.toReference(e))||null,dataType:((l=this.dataType)==null?void 0:l.toReference(e))||null,parent:((o=this.parent)==null?void 0:o.toReference(e))||null}}toFlatJSON(e=new Set){var i;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((i=this.defaultValue)==null?void 0:i.toFlatJSON(e))||[],...this.dataType?this.dataType.toFlatJSON(e):[]])}toGenerationTarget(){var e;return{id:this.id,name:this.name,description:this.description,type:this.type,required:this.required,parentRelationType:this.parentRelationType,parent:(e=this.parent)==null?void 0:e.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.defaultValue?this.defaultValue.toFlatGenerationTarget(e):[],...this.dataType?this.dataType.toFlatGenerationTarget(e):[]])}clearErrors(){var e,t;return this.errors=[],(e=this.defaultValue)==null||e.clearErrors(),(t=this.dataType)==null||t.clearErrors(),this}validate(){const e=U1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.dataType?this.dataType.getErrors():[]]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var E,O;if(Array.from(new Set([..._i(),...this.project.getAllBuiltInIds()])).includes(this.id))return this;let o=mt(t,this);const d=i||m.UUID.uuid(),u=this.toJSON();u.id=d,u.version=m.UUID.uuid(),u.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),u.author=(e==null?void 0:e.author)||"1",u.previousVersion=null,u.deleted=!1;const y=ct(u,o);t&&y.setParent(t,null),e==null||e.add(y,A.Added),s&&y.subscribe();const c=((E=this.dataType)==null?void 0:E.clone(e,y,m.UUID.uuid(),s))||null;c&&y.setDataType(c);const I=(O=this.defaultValue)==null?void 0:O.clone(e,y,m.UUID.uuid(),s);return y.defaultValue=I||null,e==null||e.attemptAutoclose("clone-entity",this.id),y}getDataType(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"get-data-type"))){return this.dataType||null}setDataType(e){return this.dataType=e,this}getDefaultValue(){return this.defaultValue||null}setDefaultValue(e){return this.defaultValue=e,this}removeDataType(){return this.dataType=null,this}};f(Ue,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(Ue,"type",n.ValueDescriptor),f(Ue,"USER_MANAGED_PARENT_TYPES",[n.ActionDescriptor,n.Loop,n.Search]),f(Ue,"PARENT_TYPES",[...Ue.USER_MANAGED_PARENT_TYPES]),f(Ue,"MUTABLE_BASE_PROPERTIES",["name","description","required"]),f(Ue,"INMUTABLE_BASE_PROPERTIES",["id","version","type","parentRelationType","createdAt","author","previousVersion"]),f(Ue,"BASE_PROPERTIES",[...Ue.MUTABLE_BASE_PROPERTIES,...Ue.INMUTABLE_BASE_PROPERTIES]),f(Ue,"MUTABLE_META_PROPERTIES",[...Ue.MUTABLE_BASE_PROPERTIES,"index"]),f(Ue,"INMUTABLE_META_PROPERTIES",[...Ue.INMUTABLE_BASE_PROPERTIES]),f(Ue,"META_PROPERTIES",[...Ue.MUTABLE_META_PROPERTIES,...Ue.INMUTABLE_META_PROPERTIES]),f(Ue,"MUTABLE_UPSTREAM_PROPERTIES",[]),f(Ue,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),f(Ue,"UPSTREAM_PROPERTIES",[...Ue.MUTABLE_UPSTREAM_PROPERTIES,...Ue.INMUTABLE_UPSTREAM_PROPERTIES]),f(Ue,"MUTABLE_DOWNSTREAM_PROPERTIES",["dataType","defaultValue"]),f(Ue,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Ue,"DOWNSTREAM_PROPERTIES",[...Ue.MUTABLE_DOWNSTREAM_PROPERTIES,...Ue.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Ue,"PROPERTIES",[...Ue.META_PROPERTIES,...Ue.UPSTREAM_PROPERTIES,...Ue.DOWNSTREAM_PROPERTIES]);let mr=Ue;function zq(r,a){if(!r.type&&!r.id)return{errors:[new w({id:`last-generated-entity-payload--${R.MissingTypeProperty}`,message:"Last generated entity payload is missing a 'type' property.",severity:D.Error,code:R.MissingTypeProperty,issue:null}),new w({id:`last-generated-entity-payload--${R.MissingIdProperty}`,message:"Last generated entity payload is missing an 'id' property.",severity:D.Error,code:R.MissingIdProperty,issue:null})],modifiedData:null};if(r.type){if(!r.id)return{errors:[new w({id:`last-generated-entity-payload--${R.MissingIdProperty}`,message:`Last generated entity, with type "${r.type}" is missing an 'id' property.`,severity:D.Error,code:R.MissingIdProperty,issue:null})],modifiedData:null}}else return{errors:[new w({id:`${r.id}--${R.MissingTypeProperty}`,message:`Entity with id "${r.id}" is missing a 'type' property.`,severity:D.Error,code:R.MissingTypeProperty,issue:null})],modifiedData:null};if(r.type===n.GenericReference)return{errors:[new w({id:`${r.id}--${R.RootReference}`,message:`Generic reference entity with id "${r.id}". A generic reference cannot be generated as a standalone entity. Only in the body of another entity.`,severity:D.Error,code:R.RootReference,issue:null})],modifiedData:null};const e=r,t=a.instances[e.id],i=a.builtInInstances[e.id];if(t&&!i&&e.type!==n.GenericReference){let s=`A previously generated entity with id "${e.id}" already exists in the project state.
207
+ ${Yi({describe_entity:o.error.id})}`,issue:null}))),{errors:s,modifiedData:i}}validateGeneratedUpdate(e){return{errors:[],modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],i=[],s=[];return Object.values(this.detachedDependents).forEach(l=>{const o=l.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),i.push(...o.removed),s.push(...o.affected)}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e,t,i;return(i=(t=(e=this.dataType)==null?void 0:e.entity)==null?void 0:t.subscribeDependents)==null||i.call(t,[{entity:this,field:"data-type-entity"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ue(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.defaultValue=this.defaultValue,e.dataType=this.dataType,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[I,E]of c.knownVersions)u.set(I,E);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ue(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.defaultValue=o.defaultValue,this.dataType=o.dataType,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw console.warn("No parent found for entity",this.initialData),new Error(`${this.type} with id '${this.id}' must have a 'parent'`);return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){var o,d,u,y,c,I,E,O;const t=[this],i=[],s=[],l=[];return this.parentRelationType===N.FixedArguments||this.parentRelationType===N.DynamicArgument?((o=this.parent)==null?void 0:o.type)===n.Search||((d=this.parent)==null?void 0:d.type)===n.Loop?(this.parent.addInputDeclaration(this,e),t.push(this.parent)):((y=(u=this.parent)==null?void 0:u.addInput)==null||y.call(u,this),t.push(this.parent)):this.parentRelationType===N.FixedReturns||this.parentRelationType===N.DynamicReturn?((c=this.parent)==null?void 0:c.type)===n.Search||((I=this.parent)==null?void 0:I.type)===n.Loop?(this.parent.addOutputDeclaration(this,e),t.push(this.parent)):((O=(E=this.parent)==null?void 0:E.addOutput)==null||O.call(E,this),t.push(this.parent)):this.parentRelationType===N.ReturnedError&&this.parent&&(this.parent.error=this,t.push(this.parent)),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.initialData.defaultValue&&(this.defaultValue=C(this.initialData.defaultValue,this.project),this.defaultValue.setParent(this,null),this.defaultValue.initChildren(e)),this.initialData.dataType&&(this.dataType=C(this.initialData.dataType,this.project),this.dataType.setParent(this,null),this.dataType.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.name=e.name||s.name,this.description=e.description||s.description,this.index=e.index||(e.index!==0?s.index:0),this.required=e.required!==void 0?e.required:this.required,this.parentRelationType=e.parentRelationType!==void 0?e.parentRelationType:this.parentRelationType,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=g,...t){return await Ue.repository.APILoad(this.id,...t),this}async APICreate(e=g,...t){return await Ue.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=g,...t){return await Ue.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=g,...t){return await Ue.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=g,...t){return await Ue.repository.APIClone(this.id,...t),this}async APILoadVersion(e=g,t,...i){return await Ue.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){var u,y,c,I,E,O,P;const i=[],s=[],l=[],o=[];if(Array.from(new Set([..._i(),...this.project.getAllBuiltInIds()])).includes(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),console.log("Built-in entity, cannot remove: ",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(V=>{const{updated:M,removed:G,added:B}=V.entity.onDetachedDependencyRemoved(this,V.field,t);i.push(...M),s.push(...G),l.push(...B)}),this.defaultValue){const{updated:V,removed:M}=this.defaultValue.remove({ignoreUpstream:!0},t);i.push(...V),s.push(...M)}if(this.dataType){const{updated:V,removed:M}=this.dataType.remove({ignoreUpstream:!0},t);i.push(...V),s.push(...M)}return e||(((u=this.parent)==null?void 0:u.type)===n.Search?this.parentRelationType===N.FixedReturns||this.parentRelationType===N.DynamicReturn?(y=this.parent)==null||y.removeOutputDeclaration(this,t):this.parentRelationType===N.FixedArguments||this.parentRelationType===N.DynamicArgument?(c=this.parent)==null||c.removeInputDeclaration(this,t):this.parentRelationType===N.ReturnedError&&(this.parent.error=null):((I=this.parent)==null?void 0:I.type)===n.Loop?this.parentRelationType===N.FixedReturns||this.parentRelationType===N.DynamicReturn?(E=this.parent)==null||E.removeOutputDeclaration(this,t):this.parentRelationType===N.ReturnedError&&(this.parent.error=null):this.parentRelationType===N.FixedReturns||this.parentRelationType===N.DynamicReturn?(O=this.parent)==null||O.removeOutput(this,t):(this.parentRelationType===N.FixedArguments||this.parentRelationType===N.DynamicArgument)&&((P=this.parent)==null||P.removeInput(this,t))),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){var o,d,u,y,c,I,E;const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.defaultValue){const{updated:O}=this.defaultValue.restore({},e);i.push(...O)}if(this.dataType){const{updated:O}=this.dataType.restore({},e);i.push(...O)}return((o=this.parent)==null?void 0:o.type)===n.Search?this.parentRelationType===N.FixedReturns||this.parentRelationType===N.DynamicReturn?(d=this.parent)==null||d.addOutputDeclaration(this,e):(this.parentRelationType===N.FixedArguments||this.parentRelationType===N.DynamicArgument)&&((u=this.parent)==null||u.addInputDeclaration(this,e)):((y=this.parent)==null?void 0:y.type)===n.Loop?(this.parentRelationType===N.FixedReturns||this.parentRelationType===N.DynamicReturn)&&((c=this.parent)==null||c.addOutputDeclaration(this,e)):this.parentRelationType===N.FixedReturns||this.parentRelationType===N.DynamicReturn?(I=this.parent)==null||I.addOutput(this,e):(this.parentRelationType===N.FixedArguments||this.parentRelationType===N.DynamicArgument)&&((E=this.parent)==null||E.addInput(this,e)),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){var i;return e.has(this.id)?[]:(e.add(this.id),[this,...((i=this.defaultValue)==null?void 0:i.toFlat(e))||[],...this.dataType?this.dataType.toFlat(e):[]])}toFlatIds(e=new Set){var i;return e.has(this.id)?[]:(e.add(this.id),[this.id,...((i=this.defaultValue)==null?void 0:i.toFlatIds(e))||[],...this.dataType?this.dataType.toFlatIds(e):[]])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,index:this.index,required:this.required,parentRelationType:this.parentRelationType,type:this.type,name:this.name}}toJSON(e=new Set){var t,i,s;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,required:this.required,defaultValue:((t=this.defaultValue)==null?void 0:t.toJSON(e))||null,parentRelationType:this.parentRelationType,dataType:((i=this.dataType)==null?void 0:i.toJSON(e))||null,parent:((s=this.parent)==null?void 0:s.toReference())||null})}toJSONClone(e=q){var i,s,l,o,d,u,y,c;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:this.type,name:this.name,description:this.description,index:this.index,required:this.required,defaultValue:((u=this.defaultValue)==null?void 0:u.toJSONClone({...e,newId:null}))||null,parentRelationType:this.parentRelationType,dataType:((y=this.dataType)==null?void 0:y.toJSONClone({...e,newId:null}))||null,parent:((c=this.parent)==null?void 0:c.toReference({seenEntityMaps:e.seenEntityMaps}))||null})}toReference(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=q){var i,s,l,o;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,index:this.index,required:this.required,parentRelationType:this.parentRelationType,defaultValue:((s=this.defaultValue)==null?void 0:s.toReference(e))||null,dataType:((l=this.dataType)==null?void 0:l.toReference(e))||null,parent:((o=this.parent)==null?void 0:o.toReference(e))||null}}toFlatJSON(e=new Set){var i;return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...((i=this.defaultValue)==null?void 0:i.toFlatJSON(e))||[],...this.dataType?this.dataType.toFlatJSON(e):[]])}toGenerationTarget(){var e;return{id:this.id,name:this.name,description:this.description,type:this.type,required:this.required,parentRelationType:this.parentRelationType,parent:(e=this.parent)==null?void 0:e.id}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.defaultValue?this.defaultValue.toFlatGenerationTarget(e):[],...this.dataType?this.dataType.toFlatGenerationTarget(e):[]])}clearErrors(){var e,t;return this.errors=[],(e=this.defaultValue)==null||e.clearErrors(),(t=this.dataType)==null||t.clearErrors(),this}validate(){const e=U1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.dataType?this.dataType.getErrors():[]]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var E,O;if(Array.from(new Set([..._i(),...this.project.getAllBuiltInIds()])).includes(this.id))return this;let o=mt(t,this);const d=i||m.UUID.uuid(),u=this.toJSON();u.id=d,u.version=m.UUID.uuid(),u.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),u.author=(e==null?void 0:e.author)||"1",u.previousVersion=null,u.deleted=!1;const y=ct(u,o);t&&y.setParent(t,null),e==null||e.add(y,A.Added),s&&y.subscribe();const c=((E=this.dataType)==null?void 0:E.clone(e,y,m.UUID.uuid(),s))||null;c&&y.setDataType(c);const I=(O=this.defaultValue)==null?void 0:O.clone(e,y,m.UUID.uuid(),s);return y.defaultValue=I||null,e==null||e.attemptAutoclose("clone-entity",this.id),y}getDataType(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"get-data-type"))){return this.dataType||null}setDataType(e){return this.dataType=e,this}getDefaultValue(){return this.defaultValue||null}setDefaultValue(e){return this.defaultValue=e,this}removeDataType(){return this.dataType=null,this}};f(Ue,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(Ue,"type",n.ValueDescriptor),f(Ue,"USER_MANAGED_PARENT_TYPES",[n.ActionDescriptor,n.Loop,n.Search]),f(Ue,"PARENT_TYPES",[...Ue.USER_MANAGED_PARENT_TYPES]),f(Ue,"MUTABLE_BASE_PROPERTIES",["name","description","required"]),f(Ue,"INMUTABLE_BASE_PROPERTIES",["id","version","type","parentRelationType","createdAt","author","previousVersion"]),f(Ue,"BASE_PROPERTIES",[...Ue.MUTABLE_BASE_PROPERTIES,...Ue.INMUTABLE_BASE_PROPERTIES]),f(Ue,"MUTABLE_META_PROPERTIES",[...Ue.MUTABLE_BASE_PROPERTIES,"index"]),f(Ue,"INMUTABLE_META_PROPERTIES",[...Ue.INMUTABLE_BASE_PROPERTIES]),f(Ue,"META_PROPERTIES",[...Ue.MUTABLE_META_PROPERTIES,...Ue.INMUTABLE_META_PROPERTIES]),f(Ue,"MUTABLE_UPSTREAM_PROPERTIES",[]),f(Ue,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),f(Ue,"UPSTREAM_PROPERTIES",[...Ue.MUTABLE_UPSTREAM_PROPERTIES,...Ue.INMUTABLE_UPSTREAM_PROPERTIES]),f(Ue,"MUTABLE_DOWNSTREAM_PROPERTIES",["dataType","defaultValue"]),f(Ue,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Ue,"DOWNSTREAM_PROPERTIES",[...Ue.MUTABLE_DOWNSTREAM_PROPERTIES,...Ue.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Ue,"PROPERTIES",[...Ue.META_PROPERTIES,...Ue.UPSTREAM_PROPERTIES,...Ue.DOWNSTREAM_PROPERTIES]);let mr=Ue;function z7(r,a){if(!r.type&&!r.id)return{errors:[new w({id:`last-generated-entity-payload--${R.MissingTypeProperty}`,message:"Last generated entity payload is missing a 'type' property.",severity:D.Error,code:R.MissingTypeProperty,issue:null}),new w({id:`last-generated-entity-payload--${R.MissingIdProperty}`,message:"Last generated entity payload is missing an 'id' property.",severity:D.Error,code:R.MissingIdProperty,issue:null})],modifiedData:null};if(r.type){if(!r.id)return{errors:[new w({id:`last-generated-entity-payload--${R.MissingIdProperty}`,message:`Last generated entity, with type "${r.type}" is missing an 'id' property.`,severity:D.Error,code:R.MissingIdProperty,issue:null})],modifiedData:null}}else return{errors:[new w({id:`${r.id}--${R.MissingTypeProperty}`,message:`Entity with id "${r.id}" is missing a 'type' property.`,severity:D.Error,code:R.MissingTypeProperty,issue:null})],modifiedData:null};if(r.type===n.GenericReference)return{errors:[new w({id:`${r.id}--${R.RootReference}`,message:`Generic reference entity with id "${r.id}". A generic reference cannot be generated as a standalone entity. Only in the body of another entity.`,severity:D.Error,code:R.RootReference,issue:null})],modifiedData:null};const e=r,t=a.instances[e.id],i=a.builtInInstances[e.id];if(t&&!i&&e.type!==n.GenericReference){let s=`A previously generated entity with id "${e.id}" already exists in the project state.
208
208
  Are you trying to update that entity?
209
209
  If so, you should use the 'update' action for core mutable metadata properties, or 'delete' and then 'post' again to replace it.
210
210
  If you are trying to create a new entity, please use a different id, for example: "${Oc(e,a)}".`;return{errors:[new w({id:`duplicate--${e.id}--${R.EntityIdNotUnique}`,message:s,severity:D.Error,code:R.EntityIdNotUnique,issue:null})],modifiedData:r}}else if(t&&e.type!==n.GenericReference)return{errors:[new w({id:`${e.id}--${R.EntityIdNotUnique}`,message:`A built in entity with id "${e.id}" already exists. You cannot modify built in entities. If you are trying to create a new entity, please use a different id, for example: "${Oc(e,a)}".`,severity:D.Error,code:R.EntityIdNotUnique,issue:null})],modifiedData:r};switch(e.type){case n.Project:return m.validateGenerationTarget(e,a);case n.DefinitionEntity:return nn.validateGenerationTarget(e,a);case n.Property:return Ur.validateGenerationTarget(e,a);case n.FunctionDeclaration:return jr.validateGenerationTarget(e,a);case n.DataType:return $r.validateGenerationTarget(e,a);case n.Operation:return Gr.validateGenerationTarget(e,a);case n.FunctionCall:return en.validateGenerationTarget(e,a);case n.VariableDeclaration:return qr.validateGenerationTarget(e,a);case n.VariableInstance:return Zr.validateGenerationTarget(e,a);case n.GlobalEvent:return Fr.validateGenerationTarget(e,a);case n.InputMap:return Wi.validateGenerationTarget(e,a);case n.OutputMap:return zi.validateGenerationTarget(e,a);case n.ArgumentDeclaration:return Yr.validateGenerationTarget(e,a);case n.ReturnDeclaration:return ai.validateGenerationTarget(e,a);case n.Loop:return kr.validateGenerationTarget(e,a);case n.Condition:return Sr.validateGenerationTarget(e,a);case n.Search:return Jr.validateGenerationTarget(e,a);case n.InstalledProject:return Wr.validateGenerationTarget(e,a);case n.InternalCall:return zr.validateGenerationTarget(e,a);case n.LiteralValue:return Hr.validateGenerationTarget(e,a);case n.ReturnStatement:return gr.validateGenerationTarget(e,a);case n.BreakStatement:return xr.validateGenerationTarget(e,a);case n.ContinueStatement:return Lt.validateGenerationTarget(e,a);case n.ActionDescriptor:return Je.validateGenerationTarget(e,a);case n.ValueDescriptor:return mr.validateGenerationTarget(e,a);case n.BuiltInBaseEntity:case n.PrimitiveEntity:{const s="Did you mean to generate a",o={[n.BuiltInBaseEntity]:`${s} '${n.DefinitionEntity}' instead?`,[n.PrimitiveEntity]:`${s} '${n.DefinitionEntity}' instead?`}[e.type]||"";return{errors:[new w({id:`${e.id}--${R.BuiltInEntityGenerated}`,message:`Entity with id "${e.id} is of "${e.type}" type and should not be generated. Built in entities can only be referenced by user created entities.
@@ -213,7 +213,7 @@ For entities of type "${r.type}", `;if(e.length>0?i+=`you can update the followi
213
213
  You can also update the following upstream references: `:`
214
214
  But can update the following upstream entity references: `;i+=`${s}'${ne(t,"', '","' and '")}'.`}else i+=e.length>0?`
215
215
  And there are no upstream references that can be updated.`:`
216
- There are no upstream references that can be updated.`;return i}function Yq(r,a){const e=[];let t=!1;if(Ti.includes(a.type)&&e.push(new w({id:`${a.id}--${R.BuiltInEntityGenerated}`,message:`Entity with id "${a.id} is of "${a.type}" type and should not be updated. Built in entities can only be referenced by user created entities.`,severity:D.Error,code:R.BuiltInEntityGenerated,issue:null})),r.id&&(e.push(new w({id:`last-action--${R.InvalidUpdateEntityOperation}`,code:R.InvalidUpdateEntityOperation,severity:D.Error,message:`The 'id' property cannot be updated in the 'update' action payload. The id of the entity is '${r.id}'. Only mutable core metadata properties can be updated, no nested entities or references. You can alternatively delete the entity and create a new one with the updated 'id'.`,issue:null})),t=!0),r.type&&(e.push(new w({id:`last-action--${R.InvalidUpdateEntityOperation}`,code:R.InvalidUpdateEntityOperation,severity:D.Error,message:`The 'type' property cannot be updated in the 'update' action payload. The type of the entity is '${a.type}'. Only mutable core metadata properties can be updated, no nested entities or references. You can alternatively delete the entity and create a new one with the updated 'type'.`,issue:null})),t=!0),e.length)return{errors:e,modifiedData:null,messageAddition:""};if(lt.includes(a.type)?r.calls&&e.push(new w({id:`${a.id}--${R.InvalidInmutablePropertyOverride}`,message:`Entity of type "${a.type}" with id "${a.id}" cannot have the property "calls" updated.
216
+ There are no upstream references that can be updated.`;return i}function Y7(r,a){const e=[];let t=!1;if(Ti.includes(a.type)&&e.push(new w({id:`${a.id}--${R.BuiltInEntityGenerated}`,message:`Entity with id "${a.id} is of "${a.type}" type and should not be updated. Built in entities can only be referenced by user created entities.`,severity:D.Error,code:R.BuiltInEntityGenerated,issue:null})),r.id&&(e.push(new w({id:`last-action--${R.InvalidUpdateEntityOperation}`,code:R.InvalidUpdateEntityOperation,severity:D.Error,message:`The 'id' property cannot be updated in the 'update' action payload. The id of the entity is '${r.id}'. Only mutable core metadata properties can be updated, no nested entities or references. You can alternatively delete the entity and create a new one with the updated 'id'.`,issue:null})),t=!0),r.type&&(e.push(new w({id:`last-action--${R.InvalidUpdateEntityOperation}`,code:R.InvalidUpdateEntityOperation,severity:D.Error,message:`The 'type' property cannot be updated in the 'update' action payload. The type of the entity is '${a.type}'. Only mutable core metadata properties can be updated, no nested entities or references. You can alternatively delete the entity and create a new one with the updated 'type'.`,issue:null})),t=!0),e.length)return{errors:e,modifiedData:null,messageAddition:""};if(lt.includes(a.type)?r.calls&&e.push(new w({id:`${a.id}--${R.InvalidInmutablePropertyOverride}`,message:`Entity of type "${a.type}" with id "${a.id}" cannot have the property "calls" updated.
217
217
  ${Xr}`,severity:D.Error,code:R.InvalidInmutablePropertyOverride,issue:null})):ot.includes(a.type)&&(r.successCalls&&e.push(new w({id:`${a.id}--${R.InvalidInmutablePropertyOverride}`,message:`Entity of type "${a.type}" with id "${a.id}" cannot have the property "successCalls" updated.
218
218
  ${Xr}`,severity:D.Error,code:R.InvalidInmutablePropertyOverride,issue:null})),r.errorCalls&&e.push(new w({id:`${a.id}--${R.InvalidInmutablePropertyOverride}`,message:`Entity of type "${a.type}" with id "${a.id}" cannot have the property "errorCalls" updated.
219
219
  ${Xr}`,severity:D.Error,code:R.InvalidInmutablePropertyOverride,issue:null}))),Mi.includes(a.type)&&(r.calledBy&&e.push(new w({id:`${a.id}--${R.InvalidInmutablePropertyOverride}`,message:`Entity of type "${a.type}" with id "${a.id}" cannot have the property "calledBy" updated.
@@ -226,11 +226,11 @@ All downstream references are managed by the downstream entity. Entities only ma
226
226
  To modify '${V}', target the entity that it points to and its equivalent property.`,severity:D.Error,code:R.InvalidDownstreamPropertyOverride,issue:null})),t=!0)}),(i.INMUTABLE_UPSTREAM_PROPERTIES||[]).forEach(V=>{r[V]&&!Da(r[V])&&(e.push(new w({id:`${a.id}--${R.InvalidInmutablePropertyOverride}`,message:`Entity of type "${a.type}" with id "${a.id}" cannot have the property "${V}" updated. It is an inmutable property that is set only when the entity is created.
227
227
  If you need to update this property, you should delete the entity and create a new one with the updated value.`,severity:D.Error,code:R.InvalidInmutablePropertyOverride,issue:null})),t=!0)});const P=i.PROPERTIES||[];P.length>0&&Object.keys(r).forEach(V=>{P.includes(V)||e.push(new w({id:`${a.id}--${R.UnrecognizedProperty}`,message:`Entity of type "${a.type}" with id "${a.id}" has an unrecognized property "${V}" that will be ignored.`,severity:D.Warning,code:R.UnrecognizedProperty,issue:null}))})}if(e.length)return{errors:e,modifiedData:null,messageAddition:t?jl(a):""};const s=j1(a),l=s==null?void 0:s.partial(),o=l==null?void 0:l.safeParse(r),d={...r,id:a.id,type:a.type},u=Mc(d,o);if(e.push(...u),e.length)return{errors:e,modifiedData:null,messageAddition:t?jl(a):""};const c=a.validateGeneratedUpdate(r);return{errors:[...e,...c.errors],modifiedData:c.modifiedData,messageAddition:t?jl(a):""}}function j1(r){switch(r.type){case n.LiteralValue:return ul();case n.DefinitionEntity:return kp();case n.PrimitiveEntity:return ul();case n.FunctionDeclaration:return Fp();case n.GlobalEvent:return Tl();case n.DataType:return Mp();case n.Property:return mp();case n.FunctionCall:return Dp();case n.Condition:return Op();case n.Operation:return hl();case n.VariableDeclaration:return Lp();case n.VariableInstance:return Up();case n.OutputMap:return Rp();case n.ReturnDeclaration:return Ep();case n.ArgumentDeclaration:return Gp();case n.InputMap:return Vp();case n.Project:return xp();case n.InstalledProject:return AS();case n.ActionDescriptor:return cl();case n.ReturnStatement:return Ip();case n.Loop:return cl();case n.Search:return Pp();case n.ValueDescriptor:return hp();case n.BuiltInBaseEntity:return vp();case n.InternalCall:return Cp();case n.ContinueStatement:return Tp();case n.BreakStatement:return Ap();default:return null}}function $1(r){switch(r.type){case n.LiteralValue:return Y5();case n.DefinitionEntity:return cZ();case n.PrimitiveEntity:return j3();case n.FunctionDeclaration:return rZ();case n.GlobalEvent:return CS();case n.DataType:return lS();case n.Property:return x3();case n.FunctionCall:return R5();case n.Condition:return C5();case n.Operation:return Z5();case n.VariableDeclaration:return fS();case n.VariableInstance:return TS();case n.OutputMap:return I5();case n.ReturnDeclaration:return p5();case n.ArgumentDeclaration:return QS();case n.InputMap:return F5();case n.Project:return lZ();case n.InstalledProject:return RS();case n.ActionDescriptor:return H3();case n.ReturnStatement:return o5();case n.Loop:return Q3();case n.Search:return M5();case n.ValueDescriptor:return N3();case n.BuiltInBaseEntity:return J3();case n.InternalCall:return g5();case n.ContinueStatement:return r5();case n.BreakStatement:return h5();default:return null}}function $l(r){const a=[];Nr(r)||a.push(new w({id:`${r}--${R.InvalidReferenceObjectStructure}`,message:`Reference object with id "${r}" is not an object. References should be objects with exactly 4 properties: 'entityId', 'entityType', 'id', and 'type'.`,severity:D.Error,code:R.InvalidReferenceObjectStructure,issue:null}));const e=r.id||"reference-to--"+(r.entityId||"unknown"),t=`Reference object ${r.id?`with id "${r.id}"`:`to entity with id "${r.entityId}" and type "${r.entityType}"`}`;return r.entityId||a.push(new w({id:`${e}--${R.InvalidReferenceObjectStructure}`,message:`${t} is missing an 'entityId' property.`,severity:D.Error,code:R.InvalidReferenceObjectStructure,issue:null})),r.entityType||a.push(new w({id:`${e}--${R.InvalidReferenceObjectStructure}`,message:`${t} is missing an 'entityType' property.`,severity:D.Error,code:R.InvalidReferenceObjectStructure,issue:null})),r.id||a.push(new w({id:`${e}--${R.MissingIdProperty}`,message:`${t} is missing an 'id' property.`,severity:D.Error,code:R.MissingIdProperty,issue:null})),r.type||a.push(new w({id:`${e}--${R.MissingTypeProperty}`,message:`${t} is missing a 'type' property.`,severity:D.Error,code:R.MissingTypeProperty,issue:null})),a}function Mc(r,a){return a.success?[]:a.error.issues.map(e=>new w({id:`${r.id}--${j.InvalidObjectStructure}`,message:`Entity of type "${r.type}" and with id "${r.id}", has an invalid structure: ${VZ(e).toString().replace("Validation error: ","")}`,severity:D.Error,code:j.InvalidObjectStructure,issue:e}))}function ut(r,a){const e=[],t=$1(r);if(t){const s=t.safeParse(r);e.push(...Mc(r,s))}const i=Ua(r.type);if(i){(i.DOWNSTREAM_PROPERTIES||[]).forEach(o=>{r[o]&&!Da(r[o])&&e.push(new w({id:`${r.id}--${R.InvalidDownstreamPropertyOverride}`,message:`Entity of type "${r.type}" with id "${r.id}" cannot have the property "${o}" set directly. It is a downstream property that points to a downstream nested entity.
228
228
  All downstream references are managed by the downstream entity. Entities only manage their own upstream references.
229
- To modify '${o}', target the entity that it points to and its equivalent property.`,severity:D.Error,code:R.InvalidDownstreamPropertyOverride,issue:null}))});const l=i.PROPERTIES||[];l.length>0&&Object.keys(r).forEach(o=>{l.includes(o)||e.push(new w({id:`${r.id}--${R.UnrecognizedProperty}`,message:`Entity of type "${r.type}" with id "${r.id}" has an unrecognized property "${o}" that will be ignored.`,severity:D.Warning,code:R.UnrecognizedProperty,issue:null}))})}return e}function Hq(r,a){const e=[];if(!r.parent)return e;const t=a.get(r.parent);return t?(Ti.includes(t==null?void 0:t.type)?e.push(new w({id:`${r.id}--${R.BuiltInEntityParent}`,message:`Entity of type "${r.type}" with id "${r.id}" cannot have the parent with id "${t.id}", because it is a built in entity. Built in entities cannot be modified.`,severity:D.Error,code:R.BuiltInEntityParent,issue:null})):t.type===n.ActionDescriptor&&a.get(r.parent)&&e.push(new w({id:`${r.id}--${R.BuiltInEntityParent}`,message:`Entity of type "${r.type}" with id "${r.id}" cannot have the parent with id "${t.id}", because it is a built in entity. Built in entities cannot be modified. Action descriptors are only sometimes built in, other times they are managed by the user.`,severity:D.Error,code:R.BuiltInEntityParent,issue:null})),e):[]}function Nc(r,a,e){const t=[],i=r[a.key];if(!i)return t.push(new w({id:`${r.id}--${a.key}--${j.InvalidObjectStructure}`,message:`Entity of type "${r.type}" with id "${r.id}" is missing a reference to a "${a.key}" entity. The '${a.key}' property of a "${r.type}" entity can be ${ne(a.types,", "," or ")}.`,severity:D.Error,code:j.InvalidObjectStructure,issue:null})),{entityState:null,errors:t};let s=null;if(typeof i=="string")s=i;else{const o=$l(i);t.push(...o),o.length===0&&(s=i.entityId)}if(!s)return{entityState:null,errors:t};if(r.id===s)return t.push(new w({id:`${r.id}--${s}--${R.SelfReference}`,message:`Entity of type "${r.type}" with id "${r.id}", has a reference to itself at '${a.key}'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,severity:D.Error,code:R.SelfReference,issue:null})),{entityState:null,errors:t};const l=e.get(s)||e.getBuiltIn(s);return l?a.types.includes(l.type)||t.push(new w({id:`${r.id}--${s}--${R.InvalidReference}`,message:`Entity of type "${r.type}" with id "${r.id}", has a reference to "${s}" at '${a.key}' that isn't pointing to an entity of type '${ne(a.types,"', '","' or '")}'.`,severity:D.Error,code:R.InvalidReference,issue:null})):t.push(new w({id:`${r.id}--${s}--${R.ReferencedEntityNotFound}`,message:`Entity of type "${r.type}" with id "${r.id}", is referencing an entity with id "${s}" at '${a.key}' that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,severity:D.Error,code:R.ReferencedEntityNotFound,issue:null})),{entityState:l,errors:t}}function Gl(r,a,e){const t=[],i=r[a];return i?Array.isArray(i)?{entities:i.map(l=>{let o=null;if(typeof l=="string")o=l;else{const u=$l(l);t.push(...u),u.length===0&&(o=l.entityId)}if(!o)return{entityState:null,errors:[new w({id:`${r.id}--${a}--${R.InvalidReference}`,message:`Entity of type "${r.type}" with id "${r.id}", has a missing reference at '${a}'. A reference needs to be a 'id' string of an existing entity in the project.`,severity:D.Error,code:R.InvalidReference,issue:null})]};const d=e.get(o)||e.getBuiltIn(o);return d?{entityState:d,errors:[]}:(t.push(new w({id:`${r.id}--${o}--${R.ReferencedEntityNotFound}`,message:`Entity of type "${r.type}" with id "${r.id}", is referencing an entity with id "${o}" at '${a}' that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,severity:D.Error,code:R.ReferencedEntityNotFound,issue:null})),{entityState:null,errors:t})}),errors:[]}:(t.push(new w({id:`${r.id}--${a}--${j.InvalidObjectStructure}`,message:`Entity of type "${r.type}" with id "${r.id}" has an invalid structure for the "${a}" property. It should be an array of references.`,severity:D.Error,code:j.InvalidObjectStructure,issue:null})),{entities:[],errors:t}):(t.push(new w({id:`${r.id}--${a}--${j.InvalidObjectStructure}`,message:`Entity of type "${r.type}" with id "${r.id}" is missing a list of references to "${a}" entities.`,severity:D.Error,code:j.InvalidObjectStructure,issue:null})),{entities:[],errors:t})}function Lc(r,a,e){const t=[],i=Nc(r,a,e);if(i.errors.length>0)return i.errors;if(i.entityState){const s=i.entityState;a.types.includes(s.type)||t.push(new w({id:`${r.id}--${s.id}--${R.InvalidReference}`,code:R.InvalidReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a reference to "${a.key}" that isn't pointing to an entity of type '${ne(a.types,"', '","' or '")}'.`,issue:null})),r.id===s.id&&t.push(new w({id:`${r.id}--${s.id}--${R.SelfReference}`,code:R.SelfReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a reference to itself at '${a.key}'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null}))}return t}function ne(r,a,e){const t=[...r||[]].filter(i=>!!i);if(t.length===1)return t[0];if(t.length===2)return t.join(e);{const i=t.pop();return`${t.join(a)}${e}${i}`}}const Kr=`Pass-through callable entities are entities that need to be called by another caller, then they execute some internal logic and when finished, it can call other callable entities with the "calledBySuccess" property or "calledByError" property based on whether their internal execution was successful or an error ocurred respectively.
230
- All pass-through callable entities are: ${ne(ot,", "," and ")}.`,Ba=`Entry point entities are the entities which start the execution of a logic chain. They are ${ne(lt,", "," and ")}. They aren't explicitly called by any entities. Rather, they can be called implicitly by the system, or as a function-call somewhere else in the case of a function-declaration. `,G1=`Caller entities are entities that can call other entities. Regarless of whether they are entry-point entities or pass-through callable entities. All caller entity types are: ${ne(Ni,", "," and ")}.`,Kq=`Callable entities are entities that can be called by other entities. They can be called by an entry-point, a success caller, or an error caller.
229
+ To modify '${o}', target the entity that it points to and its equivalent property.`,severity:D.Error,code:R.InvalidDownstreamPropertyOverride,issue:null}))});const l=i.PROPERTIES||[];l.length>0&&Object.keys(r).forEach(o=>{l.includes(o)||e.push(new w({id:`${r.id}--${R.UnrecognizedProperty}`,message:`Entity of type "${r.type}" with id "${r.id}" has an unrecognized property "${o}" that will be ignored.`,severity:D.Warning,code:R.UnrecognizedProperty,issue:null}))})}return e}function H7(r,a){const e=[];if(!r.parent)return e;const t=a.get(r.parent);return t?(Ti.includes(t==null?void 0:t.type)?e.push(new w({id:`${r.id}--${R.BuiltInEntityParent}`,message:`Entity of type "${r.type}" with id "${r.id}" cannot have the parent with id "${t.id}", because it is a built in entity. Built in entities cannot be modified.`,severity:D.Error,code:R.BuiltInEntityParent,issue:null})):t.type===n.ActionDescriptor&&a.get(r.parent)&&e.push(new w({id:`${r.id}--${R.BuiltInEntityParent}`,message:`Entity of type "${r.type}" with id "${r.id}" cannot have the parent with id "${t.id}", because it is a built in entity. Built in entities cannot be modified. Action descriptors are only sometimes built in, other times they are managed by the user.`,severity:D.Error,code:R.BuiltInEntityParent,issue:null})),e):[]}function Nc(r,a,e){const t=[],i=r[a.key];if(!i)return t.push(new w({id:`${r.id}--${a.key}--${j.InvalidObjectStructure}`,message:`Entity of type "${r.type}" with id "${r.id}" is missing a reference to a "${a.key}" entity. The '${a.key}' property of a "${r.type}" entity can be ${ne(a.types,", "," or ")}.`,severity:D.Error,code:j.InvalidObjectStructure,issue:null})),{entityState:null,errors:t};let s=null;if(typeof i=="string")s=i;else{const o=$l(i);t.push(...o),o.length===0&&(s=i.entityId)}if(!s)return{entityState:null,errors:t};if(r.id===s)return t.push(new w({id:`${r.id}--${s}--${R.SelfReference}`,message:`Entity of type "${r.type}" with id "${r.id}", has a reference to itself at '${a.key}'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,severity:D.Error,code:R.SelfReference,issue:null})),{entityState:null,errors:t};const l=e.get(s)||e.getBuiltIn(s);return l?a.types.includes(l.type)||t.push(new w({id:`${r.id}--${s}--${R.InvalidReference}`,message:`Entity of type "${r.type}" with id "${r.id}", has a reference to "${s}" at '${a.key}' that isn't pointing to an entity of type '${ne(a.types,"', '","' or '")}'.`,severity:D.Error,code:R.InvalidReference,issue:null})):t.push(new w({id:`${r.id}--${s}--${R.ReferencedEntityNotFound}`,message:`Entity of type "${r.type}" with id "${r.id}", is referencing an entity with id "${s}" at '${a.key}' that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,severity:D.Error,code:R.ReferencedEntityNotFound,issue:null})),{entityState:l,errors:t}}function Gl(r,a,e){const t=[],i=r[a];return i?Array.isArray(i)?{entities:i.map(l=>{let o=null;if(typeof l=="string")o=l;else{const u=$l(l);t.push(...u),u.length===0&&(o=l.entityId)}if(!o)return{entityState:null,errors:[new w({id:`${r.id}--${a}--${R.InvalidReference}`,message:`Entity of type "${r.type}" with id "${r.id}", has a missing reference at '${a}'. A reference needs to be a 'id' string of an existing entity in the project.`,severity:D.Error,code:R.InvalidReference,issue:null})]};const d=e.get(o)||e.getBuiltIn(o);return d?{entityState:d,errors:[]}:(t.push(new w({id:`${r.id}--${o}--${R.ReferencedEntityNotFound}`,message:`Entity of type "${r.type}" with id "${r.id}", is referencing an entity with id "${o}" at '${a}' that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,severity:D.Error,code:R.ReferencedEntityNotFound,issue:null})),{entityState:null,errors:t})}),errors:[]}:(t.push(new w({id:`${r.id}--${a}--${j.InvalidObjectStructure}`,message:`Entity of type "${r.type}" with id "${r.id}" has an invalid structure for the "${a}" property. It should be an array of references.`,severity:D.Error,code:j.InvalidObjectStructure,issue:null})),{entities:[],errors:t}):(t.push(new w({id:`${r.id}--${a}--${j.InvalidObjectStructure}`,message:`Entity of type "${r.type}" with id "${r.id}" is missing a list of references to "${a}" entities.`,severity:D.Error,code:j.InvalidObjectStructure,issue:null})),{entities:[],errors:t})}function Lc(r,a,e){const t=[],i=Nc(r,a,e);if(i.errors.length>0)return i.errors;if(i.entityState){const s=i.entityState;a.types.includes(s.type)||t.push(new w({id:`${r.id}--${s.id}--${R.InvalidReference}`,code:R.InvalidReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a reference to "${a.key}" that isn't pointing to an entity of type '${ne(a.types,"', '","' or '")}'.`,issue:null})),r.id===s.id&&t.push(new w({id:`${r.id}--${s.id}--${R.SelfReference}`,code:R.SelfReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a reference to itself at '${a.key}'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null}))}return t}function ne(r,a,e){const t=[...r||[]].filter(i=>!!i);if(t.length===1)return t[0];if(t.length===2)return t.join(e);{const i=t.pop();return`${t.join(a)}${e}${i}`}}const Kr=`Pass-through callable entities are entities that need to be called by another caller, then they execute some internal logic and when finished, it can call other callable entities with the "calledBySuccess" property or "calledByError" property based on whether their internal execution was successful or an error ocurred respectively.
230
+ All pass-through callable entities are: ${ne(ot,", "," and ")}.`,Ba=`Entry point entities are the entities which start the execution of a logic chain. They are ${ne(lt,", "," and ")}. They aren't explicitly called by any entities. Rather, they can be called implicitly by the system, or as a function-call somewhere else in the case of a function-declaration. `,G1=`Caller entities are entities that can call other entities. Regarless of whether they are entry-point entities or pass-through callable entities. All caller entity types are: ${ne(Ni,", "," and ")}.`,K7=`Callable entities are entities that can be called by other entities. They can be called by an entry-point, a success caller, or an error caller.
231
231
  All callable entity types are: ${ne(Mi,", "," and ")}.`,Xr=`Caller to callee relationships can be updated with the 'add_caller' and 'remove_caller' generation action with the properties: 'callerEntityId', a 'calleeEntityId'. For adding a caller, you can optionally add a boolean property 'fromError' (if the caller calls when an error occured in its execution).
232
232
  Either of these two actions will only affect the one relationship between the given caller and callee and ignore any others present in either entity.`,Uc=`Break and continue statements need to have exactly one 'return-declaration' entity each. It represents the result of the current iteration of the loop. It can have any name and have any 'data-type' but it needs to be identical among all statements in the same loop.
233
- Meaning, if the return declaration in one 'break-statement' is named 'result' and has a 'data-type' of 'number', all other 'break-statements' and 'continue-statements' in the same loop need to have a 'return-declaration' with the same name and 'data-type'.`,Xq=`Return statements need to be identical inside the same scope. For example if a 'return-statement' belongs to a function, with multiple branches of logic, leading to multiple 'return-statement' entities, all of them need to have the exact same amount of 'return-declaration' entities, sharing the same name and an equivalent 'data-type' entity.
233
+ Meaning, if the return declaration in one 'break-statement' is named 'result' and has a 'data-type' of 'number', all other 'break-statements' and 'continue-statements' in the same loop need to have a 'return-declaration' with the same name and 'data-type'.`,X7=`Return statements need to be identical inside the same scope. For example if a 'return-statement' belongs to a function, with multiple branches of logic, leading to multiple 'return-statement' entities, all of them need to have the exact same amount of 'return-declaration' entities, sharing the same name and an equivalent 'data-type' entity.
234
234
  Furthermore, some 'function-declarations' and all 'global-events' might be implementing a base 'action-descriptor' entity, which defines exactly the shape and number of the return declarations.`,gc=`A variable without a data type which reads an-untyped object value, or has object properties written into it as input-map writes, will infere its data-type. This means that a 'data-type' will be created, with an implicitly declared 'definition-entity' as its 'entity' property, defining the structure of the object.
235
235
  This data type entity is what will define which properties are available to be read from the variable or any of its instances as 'output-map' entities.`,Qr=`Entities of type '${n.BuiltInBaseEntity}' that have the 'interactive' property set to false cannot be used programmatically during runtime. They can't be used as data types or instanciated in variables. Their methods can't be called by the code, and are only called by the system in the background. Their properties' values are constant and set only once when declared. They also can't be extended with unrecognized properties or methods that aren't part of the base out-of-the-box entity.`,jc=`Entities that read values from other entities, can be connected with entities that write values to them. Value reading entity types are: '${ne(Er,"', '","' and '")}'.`,F1=`Entities that write values to other entities, can be connected with entities that read values from them. Value writing entity types are: '${ne(Tt,"', '","' and '")}'.`,$c=`A property entity, is neither a value reading, or a value writting entity, but they are often confused with one.
236
236
  A 'property' can have a default value through its nested 'data-type' entity.
@@ -251,7 +251,7 @@ ${$c}`,Gc=`To establish a connection of a reader and writter value during the ge
251
251
  You can use the 'disconnect_values' generation action to remove the connection between two value holding entities in the same way.`,xl=`If an explicit 'parent' isn't given for a callable entity, the scope will be auto-calculated to match the parent scope of the caller entity.
252
252
  If the entity that should be the parent of a callable entity is unclear, you can always skip the 'parent' property and the system will automatically calculate the parent based on the caller entity.`;function Yi(r){return`\`\`\`json
253
253
  ${typeof r=="string"?r:JSON.stringify(r,null,2)}
254
- \`\`\``}function Qq(r,a){let e={};switch(r){case"add_caller":return e.add_caller={callerEntityId:a.callerEntityId,calleeEntityId:a.calleeEntityId},a.fromError&&(e.add_caller.fromError=a.fromError),Yi(e);case"remove_caller":return e.remove_caller={callerEntityId:a.callerEntityId,calleeEntityId:a.calleeEntityId},Yi(e);case"connect_values":return e.connect_values={writerEntityId:a.writerEntityId,readerEntityId:a.readerEntityId},Yi(e);case"disconnect_values":return e.disconnect_values={writerEntityId:a.writerEntityId,readerEntityId:a.readerEntityId},Yi(e);case"update":{const t=`{
254
+ \`\`\``}function Q7(r,a){let e={};switch(r){case"add_caller":return e.add_caller={callerEntityId:a.callerEntityId,calleeEntityId:a.calleeEntityId},a.fromError&&(e.add_caller.fromError=a.fromError),Yi(e);case"remove_caller":return e.remove_caller={callerEntityId:a.callerEntityId,calleeEntityId:a.calleeEntityId},Yi(e);case"connect_values":return e.connect_values={writerEntityId:a.writerEntityId,readerEntityId:a.readerEntityId},Yi(e);case"disconnect_values":return e.disconnect_values={writerEntityId:a.writerEntityId,readerEntityId:a.readerEntityId},Yi(e);case"update":{const t=`{
255
255
  "update": {
256
256
  "entityId": "${a.entityId}",
257
257
  "data": {
@@ -405,4 +405,4 @@ If an entity is called by another, they must be in the same scope, which means t
405
405
  You shouldn't have to manually update a 'parent' property. The equivalent result is to change its callers, the value writters of its inputs, or the value readers of its outputs.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],i=[],s=[];return Object.values(this.detachedDependents).forEach(l=>{const o=l.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),i.push(...o.removed),s.push(...o.affected)}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];if(t==="declaration"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}if(t==="parent"){const{updated:u,added:y,removed:c}=this.remove({ignoreUpstream:!1},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];if(t==="declaration"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}if(t==="parent"){const{updated:u,added:y,removed:c}=this.restore({},i);s.push(...u),l.push(...y),o.push(...c)}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){var e;return(e=this.parent)==null||e.subscribeDependents([{entity:this,field:"parent"}]),this.declaration.subscribeDependents([{entity:this,field:"declaration"}]),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new Ze(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.inputs=this.inputs,e.outputs=this.outputs,e.error=this.error,e.successCalls=this.successCalls,e.errorCalls=this.errorCalls,e.process=this.process,e.declaration=this.declaration,e.calledBySuccess=this.calledBySuccess,e.calledByError=this.calledByError,e.calledByEntry=this.calledByEntry,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[I,E]of c.knownVersions)u.set(I,E);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new Ze(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.inputs=o.inputs,this.outputs=o.outputs,this.error=o.error,this.successCalls=o.successCalls,this.errorCalls=o.errorCalls,this.process=o.process,this.declaration=o.declaration,this.calledBySuccess=o.calledBySuccess,this.calledByError=o.calledByError,this.calledByEntry=o.calledByEntry,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);if(this.initialData.declaration){const l=_(this.initialData.declaration),o=this.project.get(l);o&&(this.setDeclaration(o),e.push(o))}return this.initialData.calledByEntry.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addEntryCaller(d,null),e.push(d))}),this.initialData.calledBySuccess.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addSuccessCaller(d,null),e.push(d))}),this.initialData.calledByError.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addErrorCaller(d,null),e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];this.initialized=!0,this.captureVersion();const{updated:o,added:d,removed:u}=this.syncMissingFixedInputs(e),{updated:y,added:c,removed:I}=this.syncMissingFixedOutputs(e);return t.push(...o,...y),i.push(...d,...c),s.push(...u,...I),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){var o;const t=[this],i=[],s=[],l=[];return this.parent===this.project&&this.project.addFunctionCall(this),(o=this.process)==null||o.writesValues.forEach(d=>{d.setValueWriter(this.process,e),t.push(d)}),this.successCalls.forEach(d=>{d.addSuccessCaller(this,e),t.push(d)}),this.errorCalls.forEach(d=>{d.addErrorCaller(this,e),t.push(d)}),this.calledBySuccess.forEach(d=>{d.addSuccessCall(this,e),t.push(d)}),this.calledByError.forEach(d=>{d.addErrorCall(this,e),t.push(d)}),this.calledByEntry.forEach(d=>{d.addCall(this,e),t.push(d)}),this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get calledBy(){return[...this.calledByEntry,...this.calledBySuccess,...this.calledByError]}removeInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-input"))){const i=this.inputs.findIndex(s=>s.id===e.id);return i>-1&&(this.inputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-input",this.id),this}addInput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-input"))){return this.inputs.includes(e)?(t==null||t.attemptAutoclose("add-input",this.id),this):(this.inputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-input",this.id),this)}addOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-output"))){return this.outputs.includes(e)?(t==null||t.attemptAutoclose("add-output",this.id),this):(this.outputs.push(e),t==null||t.add(this,A.Affected),t==null||t.attemptAutoclose("add-output",this.id),this)}removeOutput(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-output"))){const i=this.outputs.findIndex(s=>s.id===e.id);return i>-1&&(this.outputs.splice(i,1),t&&(t==null||t.add(this,A.Affected))),t==null||t.attemptAutoclose("remove-output",this.id),this}addValueReader(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-value-reader"))){var i;return this.process&&!this.process.writesValues.includes(e)&&((i=this.process)==null||i.addValueReader(e,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-value-reader",this.id),this}removeValueReader(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-value-reader"))){var i;return this.process&&this.process.writesValues.includes(e)&&((i=this.process)==null||i.removeValueReader(e,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("remove-value-reader",this.id),this}addSuccessCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-caller")),i=!1){return this.calledBySuccess.find(s=>s.id===e.id)||(this.calledBySuccess.push(e),t==null||t.add(this,A.Updated),i&&K(this,t)),t==null||t.attemptAutoclose("add-success-caller",this.id),this}addErrorCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-caller")),i=!1){return this.calledByError.find(s=>s.id===e.id)||(this.calledByError.push(e),t==null||t.add(this,A.Updated),i&&K(this,t),t==null||t.attemptAutoclose("add-error-caller",this.id)),this}addEntryCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-entry-caller")),i=!1){return this.calledByEntry.find(s=>s.id===e.id)||(this.calledByEntry.push(e),t==null||t.add(this,A.Updated),i&&K(this,t),t==null||t.attemptAutoclose("add-entry-caller",this.id)),this}addErrorCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-error-call")),i=!1){return this.errorCalls.find(s=>s.id===e.id)||(this.errorCalls.push(e),i&&K(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-error-call",this.id),this}addSuccessCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-success-call")),i=!1){return this.successCalls.find(s=>s.id===e.id)||(this.successCalls.push(e),i&&K(this,t),t==null||t.add(this,A.Affected)),t==null||t.attemptAutoclose("add-success-call",this.id),this}removeCall(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-call")),i=!1){const s=this.successCalls.findIndex(o=>o.id===e.id);s>-1&&(this.successCalls.splice(s,1),t==null||t.add(this,A.Affected));const l=this.errorCalls.findIndex(o=>o.id===e.id);return l>-1&&(this.errorCalls.splice(l,1),t==null||t.add(this,A.Affected)),i&&K(this,t),t==null||t.attemptAutoclose("remove-call",this.id),this}removeCaller(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-caller")),i=!1){return this.calledBySuccess=this.calledBySuccess.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected)),!0):!1),this.calledByError=this.calledByError.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected)),!0):!1),this.calledByEntry=this.calledByEntry.filter(s=>s.id!==e.id?(t&&(t==null||t.add(this,A.Updated),t==null||t.add(s,A.Affected)),!0):!1),i&&K(this,t),t==null||t.attemptAutoclose("remove-caller",this.id),this}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}setDeclaration(e){return this.declaration=e,this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){if(this.initialized||this.startedInitialization)return this;if(this.startedInitialization=!0,this.initialData.declaration.type===n.FunctionDeclaration){const t=C(this.initialData.declaration,this.project);this.declaration=t}else{const t=_(this.initialData.declaration),i=this.project.get(t);this.declaration=i}return this.successCalls=this.initialData.successCalls.map(t=>{const i=C(t,this.project);return i.addSuccessCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type)?(i.setParent(this.parent.parent,null),i.initChildren(e)):i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e)),i}),this.errorCalls=this.initialData.errorCalls.map(t=>{const i=C(t,this.project);return i.addErrorCaller(this),[n.BreakStatement,n.ContinueStatement].includes(i.type)?(i.setParent(this.parent.parent,null),i.initChildren(e)):i.type!==n.InternalCall&&(i.setParent(this.parent,null),i.initChildren(e)),i}),this.inputs=this.initialData.inputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.initialData.process&&(this.process=C(this.initialData.process,this.project),this.process.setParent(this,null),this.process.initChildren(e)),this.initialData.error&&(this.error=C(this.initialData.error,this.project),this.error.setParent(this,null),this.error.initChildren(e)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=g,...t){return await Ze.repository.APILoad(this.id,...t),this}async APICreate(e=g,...t){return await Ze.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=g,...t){return await Ze.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=g,...t){return await Ze.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=g,...t){return await Ze.repository.APIClone(this.id,...t),this}async APILoadVersion(e=g,t,...i){return await Ze.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){var d;const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(u=>{const{updated:y,removed:c,added:I}=u.entity.onDetachedDependencyRemoved(this,u.field,t);i.push(...y),s.push(...c),l.push(...I)}),this.process){const{updated:u,removed:y}=(d=this.process)==null?void 0:d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}if(this.inputs.forEach(u=>{const{updated:y,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...y),s.push(...c)}),this.outputs.forEach(u=>{const{updated:y,removed:c}=u.remove({ignoreUpstream:!0},t);i.push(...y),s.push(...c)}),this.error){const{updated:u,removed:y}=this.error.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}return this.successCalls.forEach(u=>{i.push(u),u.removeCaller(this,t)}),this.errorCalls.forEach(u=>{i.push(u),u.removeCaller(this,t)}),e||this.calledBy.forEach(u=>{i.push(u),u.removeCall(this,t)}),t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];if(e!=null&&e.hasAdded(this.id))return e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.process){const{updated:o}=this.process.restore({},e);i.push(...o)}return this.inputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.outputs.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.successCalls.forEach(o=>{i.push(o),o.addSuccessCaller(this,e)}),this.errorCalls.forEach(o=>{i.push(o),o.addErrorCaller(this,e)}),this.calledBySuccess.forEach(o=>{i.push(o),o.addSuccessCall(this,e)}),this.calledByError.forEach(o=>{i.push(o),o.addErrorCall(this,e)}),this.calledByEntry.forEach(o=>{i.push(o),o.addCall(this,e)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this}}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.successCalls.flatMap(i=>i.toFlat(e)),...this.errorCalls.flatMap(i=>i.toFlat(e)),...this.inputs.flatMap(i=>i.toFlat(e)),...this.outputs.flatMap(i=>i.toFlat(e)),...this.process?this.process.toFlat(e):[],...this.error?this.error.toFlat(e):[],...this.calledBy.flatMap(i=>i.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.successCalls.flatMap(i=>i.toFlatIds(e)),...this.errorCalls.flatMap(i=>i.toFlatIds(e)),...this.inputs.flatMap(i=>i.toFlatIds(e)),...this.outputs.flatMap(i=>i.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,x:this.x,y:this.y,type:this.type}}toJSON(e=new Set){var t,i;return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,successCalls:this.successCalls.map(s=>s.toJSON(e)),errorCalls:this.errorCalls.map(s=>s.toJSON(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference()),calledByError:this.calledByError.map(s=>s.toReference()),calledByEntry:this.calledByEntry.map(s=>s.toReference()),process:(t=this.process)==null?void 0:t.toJSON(e),declaration:this.declaration.toJSON(e),inputs:this.inputs.map(s=>s.toJSON(e)),outputs:this.outputs.map(s=>s.toJSON(e)),parent:this.parent.toReference(),error:(i=this.error)==null?void 0:i.toJSON(e)})}toJSONClone(e=q){var i,s,l,o,d,u,y;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),previousVersion:null,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,successCalls:this.successCalls.map(c=>c.toJSONClone({...e,newId:null})),errorCalls:this.errorCalls.map(c=>c.toJSONClone({...e,newId:null})),calledBySuccess:this.calledBySuccess.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByError:this.calledByError.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),calledByEntry:this.calledByEntry.map(c=>c.toReference({seenEntityMaps:e.seenEntityMaps})),process:(u=this.process)==null?void 0:u.toJSONClone({...e,newId:null}),declaration:this.declaration.toJSONClone({...e,newId:null}),inputs:this.inputs.map(c=>c.toJSONClone({...e,newId:null})),outputs:this.outputs.map(c=>c.toJSONClone({...e,newId:null})),error:(y=this.error)==null?void 0:y.toJSONClone({...e,newId:null}),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,x:this.x,y:this.y,process:this.process?this.process.toReference(e):null,inputs:this.inputs.map(s=>s.toReference(e)),outputs:this.outputs.map(s=>s.toReference(e)),declaration:this.declaration.toReference(e),successCalls:this.successCalls.map(s=>s.toReference(e)),errorCalls:this.errorCalls.map(s=>s.toReference(e)),calledBySuccess:this.calledBySuccess.map(s=>s.toReference(e)),calledByError:this.calledByError.map(s=>s.toReference(e)),calledByEntry:this.calledByEntry.map(s=>s.toReference(e)),error:this.error?this.error.toReference(e):null,parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.successCalls.flatMap(i=>i.toFlatJSON(e)),...this.errorCalls.flatMap(i=>i.toFlatJSON(e)),...this.inputs.flatMap(i=>i.toFlatJSON(e)),...this.outputs.flatMap(i=>i.toFlatJSON(e)),...this.process?this.process.toFlatJSON(e):[],...this.error?this.error.toFlatJSON(e):[]])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,calledByEntry:this.calledByEntry.map(t=>t.id),calledBySuccess:this.calledBySuccess.map(t=>t.id),calledByError:this.calledByError.map(t=>t.id),declaration:this.declaration.id,parent:e}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.successCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.errorCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.inputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.outputs.flatMap(i=>i.toFlatGenerationTarget(e)),...this.process?this.process.toFlatGenerationTarget(e):[],...this.error?this.error.toFlatGenerationTarget(e):[]])}clearErrors(){var e,t;return this.errors=[],this.inputs.forEach(i=>i.clearErrors()),this.outputs.forEach(i=>i.clearErrors()),this.successCalls.forEach(i=>i.clearErrors()),this.errorCalls.forEach(i=>i.clearErrors()),(e=this.process)==null||e.clearErrors(),(t=this.error)==null||t.clearErrors(),this}validate(){const e=Y1(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.inputs.flatMap(t=>t.getErrors()),...this.outputs.flatMap(t=>t.getErrors()),...this.error?this.error.getErrors():[],...this.process?this.process.getErrors():[]]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var O,P;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.inputs=[];const u=d.split("-id"),y=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=ct(o,l);t?c.setParent(t,null):c.setParent(this.parent,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,A.Added);const I=(O=this.inputs)==null?void 0:O.map((V,M)=>V.clone(e,c,y+"-input-map-"+M+"-id",s));c.inputs=I;const E=(P=this.outputs)==null?void 0:P.map((V,M)=>V.clone(e,c,y+"-output-map-"+M+"-id",s));return c.outputs=E,this.error&&(c.error=this.error.clone(e,c,y+"-error-map-id",s)),this.process&&(c.process=this.process.clone(e,c,y+"-process-id",s)),e==null||e.attemptAutoclose("clone-entity",this.id),c}removeUnrecognizedInputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-unrecognized-inputs"))){const t=[],i=[],s=[],l=[];return this.inputs.forEach(o=>{if(!this.declaration.inputs.find(u=>{var y;return u.id===((y=o.declaration)==null?void 0:y.id)})){const u=o.remove({ignoreUpstream:!1},e);s.push(...u.removed),t.push(...u.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-inputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}removeUnrecognizedOutputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-unrecognized-outputs"))){const t=[],i=[],s=[],l=[];return this.outputs.forEach(o=>{if(!this.declaration.getUniqueReturnDeclarations().find(u=>{var y;return u.id===((y=o.declaration)==null?void 0:y.id)})){const u=o.remove({ignoreUpstream:!1},e);s.push(...u.removed),t.push(...u.updated)}}),e==null||e.attemptAutoclose("remove-unrecognized-outputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncMissingFixedInputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-missing-fixed-inputs"))){const t=[],i=[],s=[],l=[],o=this.declaration.inputs.filter(c=>!this.inputs.find(I=>I.declaration.id===c.id));this.inputs.sort((c,I)=>c.index-I.index),o.forEach(c=>{this.inputs.forEach(O=>{O.index>=c.index&&O.metaSync({index:O.index+1},e)});const I={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.InputMap,declaration:c.toJSON(),readsValue:null,defaultValue:null,index:c.index,name:null,description:null,parent:this.toReference()},E=C(I,this.project);E.setParent(this,e),E.initChildren(e),e==null||e.add(E,A.Added),E.addSelfToProject(e),i.push(E)}),this.inputs.sort((c,I)=>c.index-I.index);const{updated:d,added:u,removed:y}=this.removeUnrecognizedInputs(e);return t.push(...d),i.push(...u),s.push(...y),e==null||e.attemptAutoclose("sync-missing-fixed-inputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}syncMissingFixedOutputs(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-missing-fixed-outputs"))){const t=[],i=[],s=[],l=[],o=[];this.outputs=this.initialData.outputs.map(I=>{const E=C(I,this.project);return o.push(E.index),E.setParent(this,null),E.initChildren(e),E});const d=this.declaration.getUniqueReturnDeclarations().filter(I=>!this.outputs.find(E=>E.declaration.id===I.id));this.outputs.sort((I,E)=>I.index-E.index),d.forEach((I,E)=>{this.outputs.forEach(M=>{M.index>=I.index&&M.index++});const O=o.includes(I.index)?this.outputs.length-1+E:I.index,P={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.OutputMap,declaration:I.toJSON(),defaultValue:null,writesValues:[],index:O,parent:this.toReference()},V=C(P,this.project);V.setParent(this,e),V.initChildren(e),e==null||e.add(V,A.Added),V.addSelfToProject(e)}),this.outputs.sort((I,E)=>I.index-E.index);const{updated:u,added:y,removed:c}=this.removeUnrecognizedOutputs(e);return t.push(...u),i.push(...y),s.push(...c),e==null||e.attemptAutoclose("sync-missing-fixed-outputs",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}};f(Ze,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(Ze,"type",n.FunctionCall),f(Ze,"USER_MANAGED_PARENT_TYPES",[...dt,n.Project]),f(Ze,"PARENT_TYPES",[...Ze.USER_MANAGED_PARENT_TYPES]),f(Ze,"MUTABLE_BASE_PROPERTIES",[]),f(Ze,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(Ze,"BASE_PROPERTIES",[...Ze.MUTABLE_BASE_PROPERTIES,...Ze.INMUTABLE_BASE_PROPERTIES]),f(Ze,"MUTABLE_META_PROPERTIES",["x","y"]),f(Ze,"INMUTABLE_META_PROPERTIES",[...Ze.INMUTABLE_BASE_PROPERTIES]),f(Ze,"META_PROPERTIES",[...Ze.MUTABLE_META_PROPERTIES,...Ze.INMUTABLE_META_PROPERTIES]),f(Ze,"MUTABLE_UPSTREAM_PROPERTIES",["calledBySuccess","calledByError","calledByEntry"]),f(Ze,"INMUTABLE_UPSTREAM_PROPERTIES",["declaration","parent"]),f(Ze,"UPSTREAM_PROPERTIES",[...Ze.MUTABLE_UPSTREAM_PROPERTIES,...Ze.INMUTABLE_UPSTREAM_PROPERTIES]),f(Ze,"MUTABLE_DOWNSTREAM_PROPERTIES",["successCalls","errorCalls","writesValues","inputs","outputs","error"]),f(Ze,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(Ze,"DOWNSTREAM_PROPERTIES",[...Ze.MUTABLE_DOWNSTREAM_PROPERTIES,...Ze.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(Ze,"PROPERTIES",[...Ze.META_PROPERTIES,...Ze.UPSTREAM_PROPERTIES,...Ze.DOWNSTREAM_PROPERTIES]);let en=Ze;function kc(r){return r&&typeof r.then=="function"}class ql{constructor(a){f(this,"order",[]);f(this,"flatRecord",{});f(this,"allBuiltInEntityIds",_i());f(this,"onGoingVisits",{});this.flatten(a),this.orderEntities()}flatten(a){const e=new Set(_i()),t=p(U(a,e,{ignoreBuiltInBaseEntities:!0})),i=new Set;for(const s of t)this.flatRecord[s.id]=s,i.add(s.id);this.order=Array.from(i)}moveEntityAfterDependencies(a){const{upstream:e}=Hl(a,this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds});for(const t of Object.keys(e)){const i=this.order.indexOf(t),s=this.order.indexOf(a.id);if(i>s)return this.order.splice(s,1),this.order.splice(i,0,a.id),!0}return!1}orderEntities(){let a=!1;for(let e=0;e<this.order.length;e++){const t=this.order[e],i=this.flatRecord[t];if(this.moveEntityAfterDependencies(i)){a=!0;break}}a&&this.orderEntities()}getUpstreamOngoingDependenciesVisits(a,e){const{upstream:t}=Hl(this.flatRecord[a],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds}),i={};return Object.entries(this.onGoingVisits[e]||{}).forEach(([s,l])=>{Object.keys(t).includes(s)&&(i[s]=l)}),i}getDownstreamOngoingDependenciesVisits(a,e){const t=Object.keys(this.onGoingVisits[e]||{}),i=new Set(t.flatMap(l=>Object.keys(Hl(this.flatRecord[l],this.flatRecord,{ignoreBuiltInBaseEntities:!0,allBuiltInEntityIds:this.allBuiltInEntityIds}).downstream))),s={};return Array.from(i).forEach(l=>{l===a&&(s[l]=this.onGoingVisits[e][l])}),s}async settlePromises(a,e){const t=Object.values(a);t.length&&await Promise.all(t),Object.keys(a).forEach(i=>{delete this.onGoingVisits[e][i]})}visit(a){const e=this.order;for(const t of e)a(this.flatRecord[t],this.flatRecord);return this}reverseVisit(a){const e=this.order.slice().reverse();for(const t of e)a(this.flatRecord[t],this.flatRecord);return this}async visitAsync(a){const e=this.order,t=Math.random().toString(36).substring(7);this.onGoingVisits[t]={};for(const i of e){const s=this.getUpstreamOngoingDependenciesVisits(i,t);Object.keys(s).length&&await this.settlePromises(s,t);const l=a(this.flatRecord[i],this.flatRecord);kc(l)&&(this.onGoingVisits[t][i]=l)}return await this.settlePromises(this.onGoingVisits[t],t),this.onGoingVisits[t]={},this}async reverseVisitAsync(a){const e=this.order.slice().reverse(),t=Math.random().toString(36).substring(7);this.onGoingVisits[t]={};for(const i of e){const s=this.getDownstreamOngoingDependenciesVisits(i,t);Object.keys(s).length&&await this.settlePromises(s,t);const l=a(this.flatRecord[i],this.flatRecord);kc(l)&&(this.onGoingVisits[t][i]=l)}return await this.settlePromises(this.onGoingVisits[t],t),this.onGoingVisits[t]={},this}}function K1(r,a){switch(r.id){case k["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id:{const e=r.project.entities.filter(d=>!!d.implements.find(u=>u.id===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id));if(e.find(d=>!!d.properties.find(u=>{var y;return u.implements&&u.implements.id===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id&&((y=u.getDefaultValue())==null?void 0:y.value)===!0}))){const u=e[0].properties.find(c=>c.implements&&c.implements.id===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id),y=u==null?void 0:u.defaultValue;if(y)y.value=!0;else if(u!=null&&u.dataType){const c={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.LiteralValue,name:L.EntityTemplate,autogeneration:null,value:!0,valueAsTypeSingle:null,valueAsTypeList:null,parent:u==null?void 0:u.dataType.toReference()},I=C(c,r.project);return I.setParent(u==null?void 0:u.dataType,a),I.initChildren(a),a==null||a.add(I,A.Added),I.addSelfToProject(a),{newEntities:[I]}}return{newEntities:[]}}const i=r.project.get(k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id),s=Jl(i,"Main database",a);if(s.errors.length>0)return{newEntities:[]};const l=s.properties.find(d=>d.implements&&d.implements.id===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id),o=l==null?void 0:l.defaultValue;if(o)o.value=!0;else if(l!=null&&l.dataType){const d={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.LiteralValue,name:L.EntityTemplate,autogeneration:null,value:!0,valueAsTypeSingle:null,valueAsTypeList:null,parent:l==null?void 0:l.dataType.toReference()},u=C(d,r.project);u.setParent(l==null?void 0:l.dataType,a),u.initChildren(a),a==null||a.add(u,A.Added),u.addSelfToProject(a)}return{newEntities:[s]}}}return{newEntities:[]}}function X1(r,a){return r.implements.filter(t=>t.type===n.BuiltInBaseEntity).map(t=>{switch(t.id){case k["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.id:{const s=r.project.entities.filter(d=>d.implements.find(u=>u.id===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.id)).find(d=>!!d.properties.find(u=>{var y;return u.implements&&u.implements.id===k["built-in-base-entity"].BUILT_IN_RELATIONAL_DATABASE_ENTITY.properties.default.id&&((y=u.getDefaultValue())==null?void 0:y.value)===!0}));if(!s)return{newEntities:[]};const l=r.properties.find(d=>d.implements&&d.implements.id===k["built-in-base-entity"].BUILT_IN_PERSISTED_ENTITY_ENTITY.properties.database.id),o=l==null?void 0:l.defaultValue;if(l&&(l!=null&&l.dataType)&&!o){const d={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(a==null?void 0:a.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.LiteralValue,name:L.EntityTemplate,autogeneration:null,value:null,valueAsTypeSingle:s,valueAsTypeList:null,parent:l==null?void 0:l.dataType.toReference()},u=C(d,r.project);return u.setParent(l==null?void 0:l.dataType,a),u.initChildren(a),a==null||a.add(u,A.Added),u.addSelfToProject(a),{newEntities:[u]}}return{newEntities:[]}}}}),{newEntities:[]}}function Jl(r,a,e,t){const i=t||m.UUID.uuid(),s=m.UUID.uuid(),l={id:i,version:s,createdAt:(e==null?void 0:e.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:a,type:n.DefinitionEntity,description:null,static:r.static,abstract:!1,properties:[],methods:[],abstractMethods:[],extends:[],implements:[r],x:0,y:0,parent:r.project};K1(r,e);const o=C(l,r.project);return o.hydrateAncestors(),o.addImplementation(r),o.setParent(r.project,e),o.initChildren(e),e==null||e.add(o,A.Added),r.abstractMethods.map(d=>{const u=m.UUID.uuid(),y=d.implementAsFunctionDeclaration(e,o,u);return o.addMethod(y),e==null||e.add(y,A.Added),y}),o.afterAllChildrenInitialized(e),X1(o,e),o}function Sc(r,a){return a.entities.find(i=>{const s=i.properties,l=s.map(c=>c.name),o=r.every(c=>l.includes(c)),d=l.filter(c=>!r.includes(c)),u=s.every(c=>!d.includes(c.name)||!c.required);return o&&u})||null}function Q1(r,a,e,t=Dt.OrDataTypeGroup){const i=[],s=[],l=[],o=[],u={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(e==null?void 0:e.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:null,implementationChooseOne:!1,entity:r.toJSON(),isList:!1,asType:null,andChildrenGroup:null,orChildrenGroup:null,like:!0,inferred:!1,parentRelationType:t,parent:a.toReference()},y=C(u,r.project);return s.push(y),y.setParent(a,e),y.initChildren(e),e==null||e.add(y,A.Added),y.setEntity(r),y.addSelfToProject(e),{updated:p(i),added:p(s),removed:p(l),affected:p(o),self:y}}function Zc(r,a,e,t,i){var u,y,c,I,E,O,P,V;const s=[],l=[],o=[],d=[];switch(typeof r){case"string":let M=!1;const G=new Date(r);if(G instanceof Date&&!isNaN(G.valueOf())&&(M=!0),M){const B=a.project.getBuiltIn(k[n.PrimitiveEntity][L.Date].id);a.setEntity(B);break}else{const B=a.project.getBuiltIn(k[n.PrimitiveEntity][L.String].id);a.setEntity(B);break}case"number":a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][L.Number].id));break;case"boolean":a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][L.Boolean].id));break;case"object":if(r===null){a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][L.Null].id));break}else if(Array.isArray(r))if(a.metaSync({isList:!0},t),r.length>0){const B=r.slice(0,5).filter(Z=>Z!==void 0);if(B.every(Z=>typeof Z==typeof B[0])&&(typeof B[0]!="object"||B[0]===null))switch(typeof B[0]){case"string":a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][L.String].id));break;case"number":a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][L.Number].id));break;case"boolean":a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][L.Boolean].id));break;case"object":a.setEntity(a.project.getBuiltIn(k[n.PrimitiveEntity][L.Null].id));break}else{const Z=[];let J=!1;B.forEach(fe=>{var Ie,X,le,ei;if(Array.isArray(fe)&&(J=!0),typeof fe=="object"&&!Array.isArray(fe)&&fe!==null){const Xi=Wl(fe,a.project,{...e,id:m.UUID.uuid()},t,i);Xi.hasCreated&&Z.push((Ie=Xi.changeSet)==null?void 0:Ie.self),s.push(...(X=Xi.changeSet)==null?void 0:X.updated),l.push(...(le=Xi.changeSet)==null?void 0:le.added),o.push(...(ei=Xi.changeSet)==null?void 0:ei.removed)}});const te=p(Z);if(!te.length&&!J){B.forEach(fe=>{const Ie={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:null,implementationChooseOne:!1,entity:null,isList:!1,asType:null,andChildrenGroup:null,orChildrenGroup:null,like:!0,inferred:!1,parentRelationType:Dt.OrDataTypeGroup,parent:a.toReference()},X=C(Ie,a.project);switch(X.setParent(a,t),X.initChildren(t),t==null||t.add(X,A.Added),X.addSelfToProject(t),typeof fe){case"string":X.setEntity(X.project.getBuiltIn(k[n.PrimitiveEntity][L.String].id));break;case"number":X.setEntity(X.project.getBuiltIn(k[n.PrimitiveEntity][L.Number].id));break;case"boolean":X.setEntity(X.project.getBuiltIn(k[n.PrimitiveEntity][L.Boolean].id));break;case"object":X.setEntity(X.project.getBuiltIn(k[n.PrimitiveEntity][L.Null].id));break}});break}else te.length===1&&!J?a.setEntity(te[0]):B.forEach(fe=>{if(typeof fe=="object"&&!Array.isArray(fe)&&fe!==null){const Ie=Sc(Object.keys(fe),a.project);if(Ie){const X=Q1(Ie||te[0],a,t,Dt.OrDataTypeGroup);s.push(...X.updated),l.push(...X.added),o.push(...X.removed)}}else{const Ie={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,options:null,implementationChooseOne:!1,entity:null,isList:Array.isArray(fe),asType:null,andChildrenGroup:null,orChildrenGroup:null,like:!0,inferred:!1,parentRelationType:Dt.OrDataTypeGroup,parent:a.toReference()},X=C(Ie,a.project);X.setParent(a,t),X.initChildren(t),t==null||t.add(X,A.Added),X.addSelfToProject(t);const le=Zc(fe,X,{...e,id:m.UUID.uuid()},t,i);s.push(...le.updated),l.push(...le.added),o.push(...le.removed)}})}}else{const B=Wl(r[0],a.project,{...e},t,i);a.setEntity((u=B.changeSet)==null?void 0:u.self),s.push(...(y=B.changeSet)==null?void 0:y.updated),l.push(...(c=B.changeSet)==null?void 0:c.added),o.push(...(I=B.changeSet)==null?void 0:I.removed);break}else{const B=Wl(r,a.project,{...e},t,i);a.setEntity((E=B.changeSet)==null?void 0:E.self),s.push(...(O=B.changeSet)==null?void 0:O.updated),l.push(...(P=B.changeSet)==null?void 0:P.added),o.push(...(V=B.changeSet)==null?void 0:V.removed);break}}return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:a}}function Wl(r,a,e,t,i){const s=[],l=[],o=[],d=[],u=Object.keys(r),y=Sc(u,a);if(y)return{hasCreated:!1,changeSet:{updated:[],added:[],removed:[],affected:[],self:y}};const c=i?e.name+" of "+i.name:e.name,E={id:e.id||m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:c,type:n.DefinitionEntity,description:e.description||null,static:e.static||!1,abstract:e.abstract||!1,properties:[],methods:[],abstractMethods:[],extends:[],implements:[],x:0,y:0,parent:a.toReference()},O=C(E,a);return O.setParent(a,t),O.initChildren(t),t==null||t.add(O,A.Added),O.addSelfToProject(t),l.push(O),u.forEach((P,V)=>{const G={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:P,type:n.Property,description:null,static:!1,abstract:!1,defaultValue:null,constant:!1,dataType:null,implements:null,index:V,hidden:!1,private:!1,required:!0,parent:O.toReference()},B=C(G,a);B.setParent(O,t),B.initChildren(t),t==null||t.add(B,A.Added),B.addSelfToProject(t),l.push(B);const $=r[P],J={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||new Date().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DataType,parentRelationType:null,options:null,implementationChooseOne:!1,entity:null,isList:!1,asType:null,andChildrenGroup:null,orChildrenGroup:null,like:!0,inferred:!1,parent:B.toReference()},te=C(J,a);te.setParent(B,t),te.initChildren(t),t==null||t.add(te,A.Added),te.addSelfToProject(t),l.push(te);const fe=Zc($,te,{...e,name:P,id:m.UUID.uuid()},t,i||O);s.push(...fe.updated),l.push(...fe.added),o.push(...fe.removed)}),{hasCreated:!0,changeSet:{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:O}}}function Tr(r,a,e,t){const i=[];return!r.length||!a.length?{errors:i,overlap:!1}:(r.length>a.length?r.forEach(s=>{const l=a.find(d=>d.name===s.name),o=a.find(d=>{var u,y;return!!s.implements&&((u=d.implements)==null?void 0:u.id)===((y=s.implements)==null?void 0:y.id)});if(l){const d=new it({id:s.id+"--"+l.id+"--"+t,message:`Entity of type ${s.type} named "${s.name}" with id "${s.id}" overrides a base ${l.type} ${l.name} with id "${l.id}" that has the same name`,issue:null,severity:D.Error,code:t,entity:s,firstRelationship:l});i.push(d)}if(o){const d=new it({id:s.id+"--"+o.id+"--"+e,message:`Entity of type ${s.type} named "${s.name}" with id "${s.id}" overrides a base ${o.type} ${o.name} with id "${o.id}" that implements the same base descriptor`,issue:null,severity:D.Error,code:e,entity:s,firstRelationship:o});i.push(d)}}):a.forEach(s=>{var d;const l=r.find(u=>u.name===s.name),o=r.find(u=>{var y,c;return!!u.implements&&((y=u.implements)==null?void 0:y.id)===((c=s.implements)==null?void 0:c.id)});if(l){const u=new it({id:l.id+"--"+s.id+"--"+t,message:`Entity of type ${l.type} named "${l.name}" with id "${l.id}" overrides a base entity ${s.name} with id "${s.id}" that has the same name`,issue:null,severity:D.Error,code:t,entity:l,firstRelationship:s});i.push(u)}if(o){const u=new it({id:o.id+"--"+s.id+"--"+e,message:`Entity of type ${o.type} named "${o.name}" with id "${o.id}" overrides a base entity ${s.name} with id "${s.id}" that implements the same base ${(d=o==null?void 0:o.implements)==null?void 0:d.type}`,issue:null,severity:D.Error,code:e,entity:o,firstRelationship:s});i.push(u)}}),{errors:i,overlap:!!i.length})}function oJ(r,a){return r.abstract||(r.properties.forEach(t=>{t.abstract||t.metaSync({abstract:!0},a)}),Object.values(r.detachedDependents).forEach(t=>{t.field===Cc.Entity&&t.entity.remove({ignoreUpstream:!1},a)}),r.metaSync({abstract:!0},a)),r}function lJ(r,a){return r.abstract&&(r.properties.forEach(t=>{t.abstract&&t.metaSync({abstract:!1},a)}),Object.values(r.detachedDependents).forEach(t=>{(t.field===rd.Implements||t.field===rd.Extends)&&t.entity.onDetachedDependencyRemoved(r,t.field,a)}),r.metaSync({abstract:!1},a)),r}function dJ(r,a){return r.static||(r.properties.forEach(t=>{t.static||t.metaSync({static:!0},a)}),r.metaSync({static:!0},a)),r}function uJ(r,a){return r.static&&(r.properties.forEach(t=>{t.static&&t.metaSync({static:!1},a)}),r.metaSync({static:!1},a)),r}function Ds(r,a){const e=Ln(r);if(e.length===0)return{list:[],last:null};let t=null;return{list:e.flatMap(s=>{if(s===a)return t=s,[s];const l=Ds(s,a);return l.last&&(t=l.last),[s,...l.list]}),last:t}}function qc(r){const a=r.calledBy;if(a.length===0)return r.project;const e=a.reduce((t,i)=>{const s=St(i,r.project);return!s||s.type===n.Project?t:t.type===n.Project||Ds(s,t).last?s:(Ds(t,s).last,t)},r.project);return e.type===n.FunctionDeclaration&&e.parent.type===n.Loop?e.parent:e}function K(r,a){var i,s;let e=qc(r);if(r.type===n.InternalCall)(i=r.parent)==null||i.setParent(e,a),(s=r.parent)==null||s.addSelfToProject(a);else if((r.type===n.ContinueStatement||r.type===n.BreakStatement)&&e.type!==n.Loop){r.remove({ignoreUpstream:!1},a);return}else if(r.type===n.ReturnStatement&&!dt.includes(e.type)){r.remove({ignoreUpstream:!1},a);return}else r.setParent(e,a),r.addSelfToProject(a);if(st.includes(r.type))return;qe(r).forEach(l=>{var d,u;const o=qc(l);if(l.type===n.InternalCall)(d=l.parent)==null||d.setParent(o,a),(u=l.parent)==null||u.addSelfToProject(a);else if((l.type===n.ContinueStatement||l.type===n.BreakStatement)&&o.type!==n.Loop){l.remove({ignoreUpstream:!1},a);return}else if(l.type===n.ReturnStatement&&!dt.includes(o.type)){l.remove({ignoreUpstream:!1},a);return}else l.setParent(o,a),l.addSelfToProject(a)})}function eP(r,a,e=new Set){const t=tn(r),i=tn(a),s=t.filter(d=>!i.includes(d)),l=t.filter(d=>i.includes(d)),o=s.reduce((d,u)=>e.has(u.id)?d:(e.add(u.id),p([...d,...eP(u,a,e)])),[]);return p([...l,...o])}function Ma(r,a){const e=Ds(r,a);return e.last===a&&e.list.length>0&&e.list[0]!==a}function pJ(r,a){return!!Ds(r,a).last}function cJ(r){if(lt.includes(r.type))return r;if([...Mi,n.VariableDeclaration].includes(r.type)){const a=r.parent;return lt.includes(a.type)?a:null}return null}function Jc(r,a){if(!r||!a)throw new Error("Both entities must be defined to find a common ancestor");if(r===a)return r;const e=r.parent;if(e){if(e===a)return a;if(e.type===n.Project)return null}else return null;const t=a.parent;if(t){if(t===r)return r;if(t.type===n.Project)return null}else return null;return Jc(e,t)}function wt(r){if(Za.includes(r.type)){if(r.type===n.FunctionDeclaration){const a=r.parent;if(a.type===n.DefinitionEntity)return a;if(a.type===n.Loop)return a}return r}else{const a=r.parent;return a?wt(a):null}}function zl(r,a){const e=Na(r,a);if(!e)return null;if(Za.includes(e.type)){if(e.type===n.FunctionDeclaration){const t=Na(e.parent,a);if(t){if(t.type===n.DefinitionEntity)return t;if(t.type===n.Loop)return t}}return e}else{const t=e.parent?Na(e.parent,a):null;return t?zl(t,a):null}}function tP(r){if(!r)return null;if(Mi.includes(r.type))return r;const a=r.parent;return a?tP(a):null}function iP(r){if(!r)return null;if(ot.includes(r.type))return r;const a=r.parent;return a?iP(a):null}function rP(r){if(!r)return null;if(Ni.includes(r.type))return r;const a=r.parent;return a?rP(a):null}function fJ(r){return r.type===n.VariableDeclaration?[r]:ot.includes(r.type)?[...r.inputs,...r.outputs||[]]:st.includes(r.type)?r.outputs:Gn.includes(r.type)||r.type===n.FunctionDeclaration?r.inputs:[]}function yJ(r){const a=tn(r),e=[],t=[];lf.includes(r.type)&&e.push(...Wc(r));const i=a.filter(s=>{const l=e.includes(s);return l?!1:Mi.includes(s.type)&&!l?(t.push(s),!1):!0});return e.sort((s,l)=>Ma(l,s)?-1:0),t.sort((s,l)=>Ma(l,s)?-1:0),[...e,...t,...i]}function nP(r){return[...r].sort((a,e)=>Ma(e,a)?-1:0)}function hJ(r){const a=nP(r),e=[];return a.forEach(t=>{const i=e[e.length-1];if(i){const s=i[i.length-1];Ma(t,s)?e.push([t]):i.push(t)}else e.push([t])}),e}function Xt(r){const a=r.map(e=>wt(e));return p(a)}function Wc(r){return ot.includes(r.type)?[...Xt(r.successCalls),...Xt(r.errorCalls)]:lt.includes(r.type)?Xt(r.calls):[]}function mJ(r,a){return Wc(r).includes(a)}function zc(r){return r.writesValues||[]}function vJ(r,a){return zc(r).includes(a)}function sP(r){var a;return tt.includes((a=r==null?void 0:r.readsValue)==null?void 0:a.type)?r.readsValue:null}function TJ(r){return r.writesValues}function aP(r=[]){return r.map(sP).filter(a=>!!a)}function Yl(r=[]){return r.map(a=>a.writesValues).flat().filter(a=>tt.includes(a.type))}function oP(r=[]){return r.map(a=>a.readsValue).filter(a=>!!a&&tt.includes(a.type))}function lP(r){return tt.includes(r.type)?r:null}function dP(r){return r.writesValues.map(lP).filter(a=>!!a)}function uP(r=[]){return r.reduce((a,e)=>e.type===n.OutputMap?[...a,...dP(e)]:a,[])}function qe(r){return ot.includes(r.type)?[...Hi(Xt(r.successCalls)),...Hi(Xt(r.errorCalls))]:lt.includes(r.type)?Hi(Xt(r.calls)):[]}function IJ(r){return ot.includes(r.type)?[...Hi(Xt(r.successCalls)),...Hi(Xt(r.errorCalls))]:lt.includes(r.type)?Hi(Xt(r.calls)):[]}function pP(r,a=new Set){return r.writesValues.filter(t=>tt.includes(t.type)&&!a.has(t.id)).reduce((t,i)=>a.has(i.id)?t:[...t,...Ye(i,a)],[])}function cP(r,a=new Set){var t;return(((t=r.readsValue)==null?void 0:t.writesValues)||[]).filter(i=>tt.includes(i.type)&&!a.has(i.id)).reduce((i,s)=>a.has(s.id)?i:[...i,...Ye(s,a)],[])}function Ye(r,a=new Set){if(a.has(r.id))return[];if(r.type===n.ReturnStatement)return oP(r.outputs).reduce((t,i)=>[...t,...Ye(i,a)],[]);if(r.type===n.FunctionCall||r.type===n.Operation||r.type===n.Condition)return[...qe(r).reduce((s,l)=>{const o=wt(l);return[...s,...Ye(o||l,a)]},[]),...aP(r.inputs),...uP(r.outputs)].reduce((s,l)=>[...s,...Ye(l,a)],[]);if(Gn.includes(r.type)){const e=Yl(r.inputs),i=qe(r).reduce((s,l)=>{const o=wt(l);return[...s,...Ye(o||l,a)]},[]);return e.push(...i),e.reduce((s,l)=>[...s,...Ye(l,a)],[])}if(r.type===n.FunctionDeclaration){const e=[...Yl(r.inputs)],i=qe(r).reduce((s,l)=>{const o=wt(l);return[...s,...Ye(o||l,a)]},[]);return e.push(...i),e.reduce((s,l)=>[...s,...Ye(l)],[])}if(tt.includes(r.type)){a.add(r.id);const t=qe(r).reduce((i,s)=>{const l=wt(s);return[...i,...Ye(l||s,a)]},[]);return[r,...t,...cP(r,a),...pP(r,a)]}return[]}function oi(r,a=new Set){return a.has(r.id)?[]:(a.add(r.id),[...tn(r).reduce((i,s)=>[...i,s,...oi(s,a)],[])])}function Hi(r){return r.reduce((a,e)=>e.type===n.ReturnStatement||e.type===n.ContinueStatement||e.type===n.BreakStatement?[...a,e]:[...a,e,...qe(e)],[])}function fP(r){const a=r.entities||[],e=[...a,...r.functions||[],...r.events||[],...r.projects||[]],t=a.reduce((d,u)=>[...d,...u.properties],[]),i=a.reduce((d,u)=>[...d,...u.methods],[]),s=i.reduce((d,u)=>[...d,...Yl(u.inputs),...Hi(Xt(u.calls)),...u.returnStatements],[]),l=r.functions.reduce((d,u)=>[...d,...Hi(Xt(u.calls)),...u.returnStatements],[]),o=r.events.reduce((d,u)=>[...d,...Hi(Xt(u.calls)),...u.returnStatements],[]);return[...e,...t,...i,...s,...l,...o]}function yP(r,a){return a.filter(t=>{if(!t)return!1;switch(t.type){case n.FunctionCall:return t.inputs.find(i=>i.id===r.id)!==void 0||t.outputs.find(i=>i.id===r.id)!==void 0;case n.Condition:return t.successCalls.find(i=>i.id===r.id)!==void 0||t.errorCalls.find(i=>i.id===r.id)!==void 0||t.inputs.find(i=>i.id===r.id)!==void 0;case n.Operation:return t.outputs.find(i=>i.id===r.id)!==void 0;case n.VariableDeclaration:return ot.includes(r.type)?kP(r).find(s=>{var l;return((l=s.readsValue)==null?void 0:l.id)===t.id})!==void 0:!1;case n.DefinitionEntity:return t.properties.find(i=>i.id===r.id)!==void 0||t.methods.find(i=>i.id===r.id)!==void 0;case n.FunctionDeclaration:return t.inputs.find(i=>i.id===r.id)!==void 0||(t.returnStatements.map(i=>i.outputs).flat()||[]).find(i=>i.id===r.id)!==void 0;default:return!1}})}function EJ(r){const a=fP(r.project);return yP(r,a)}function Na(r,a){return r?typeof r=="string"?a[r]:r.type===n.GenericReference?a[r.entityId]:a[r.id]?a[r.id]:null:null}function Hl(r,a={},e={ignoreBuiltInBaseEntities:!1,allBuiltInEntityIds:[]}){if(e.ignoreBuiltInBaseEntities&&(Ti.includes(r.type)||(e.allBuiltInEntityIds||[]).includes(r.id)))return{upstream:{},downstream:{}};const t=r,i=r,s=r,l=r,o=r,d=r,u=r,y=r,c=r,I=r,E=r,O=r,P=r,V=[...P.readsValue?[P.readsValue]:[],...P.declaration?[P.declaration]:[],...(O.calledByEntry||[]).flatMap($=>$),...(O.calledBySuccess||[]).flatMap($=>$),...(O.calledByError||[]).flatMap($=>$),...(s.extends||[]).flatMap($=>$),...I.parent?[I.parent]:[]];Array.isArray(s.implements)?V.push(...s.implements.flatMap($=>$)):c.implements&&V.push(c.implements),o.valueAsTypeList&&Array.isArray(o.valueAsTypeList)&&V.push(...o.valueAsTypeList.flatMap($=>$)),o.valueAsTypeSingle&&V.push(o.valueAsTypeSingle);const M=[...(t.inputs||[]).flatMap($=>$),...(E.inputsDeclarations||[]).flatMap($=>$),...(t.outputs||[]).flatMap($=>$),...(E.outputsDeclarations||[]).flatMap($=>$),...(P.internalCalls||[]).flatMap($=>$),...P.writesValues||[],...O.dataType?[O.dataType]:[],...d.body?[d.body]:[],...O.defaultValue?[O.defaultValue]:[],...(O.successCalls||[]).flatMap($=>$),...(O.errorCalls||[]).flatMap($=>$),...(s.properties||[]).flatMap($=>$),...(s.methods||[]).flatMap($=>$),...(s.abstractMethods||[]).flatMap($=>$),...u.error?[u.error]:[],...u.process?[u.process]:[],...I.throws?[I.throws]:[],...(i.andChildrenGroup||[]).flatMap($=>$),...(i.orChildrenGroup||[]).flatMap($=>$),...(y.entities||[]).flatMap($=>$),...(y.functions||[]).flatMap($=>$),...(y.functionCalls||[]).flatMap($=>$),...(y.events||[]).flatMap($=>$),...(y.conditions||[]).flatMap($=>$),...(y.operations||[]).flatMap($=>$),...(y.loops||[]).flatMap($=>$),...(y.variableDeclarations||[]).flatMap($=>$),...(y.variableInstances||[]).flatMap($=>$),...(y.searches||[]).flatMap($=>$),...(y.projects||[]).flatMap($=>$),...(l.calls||[]).flatMap($=>$)];r.type===n.DataType&&(i.entity&&a[_(i.entity)]&&a[_(i.entity)].parent&&_(a[_(i.entity)].parent)===r.id?M.push(i.entity):i.entity&&V.push(i.entity));const G={},B={};return V.forEach($=>{const Z=_($);if(Z&&e.ignoreBuiltInBaseEntities&&(Ti.includes($.type)||(e.allBuiltInEntityIds||[]).includes(Z)))return;const J=$.version;Z&&(G[Z]=J)}),M.forEach($=>{const Z=_($);if(Z&&e.ignoreBuiltInBaseEntities&&(Ti.includes($.type)||(e.allBuiltInEntityIds||[]).includes(Z)))return;const J=$.version;Z&&(B[Z]=J)}),{upstream:G,downstream:B}}function AJ(r,a){const e=[];if(Mi.includes(r.type)){hi(r).forEach(s=>{const l=zl(s,a);l&&e.push(l)});const i=[...r.inputs||[],...r.outputs||[]].map(s=>{const l=Na(s,a);return l?ZP(l,a):null}).filter(s=>s!==null);e.push(...p(i))}if(tt.includes(r.type)){const t=Kl(r);t&&e.push(t)}return p(e)}function Ln(r){const a=[];if(Mi.includes(r.type)){r.calledBy.forEach(i=>{const s=wt(i);s&&a.push(s)});const t=[...r.inputs||[],...r.outputs||[]].map(i=>Kl(i)).filter(i=>i!==null);a.push(...p(t))}if(tt.includes(r.type)){const e=Kl(r);e&&a.push(e)}return p(a)}function hi(r){return[...r.calledByEntry||[],...r.calledByError||[],...r.calledBySuccess||[]].filter(a=>a.type!==n.GenericReference)}function hP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.ActionDescriptor)throw new Error("Entity must be an action descriptor to be flattened");return[r,...r.inputs.flatMap(t=>U(t,a,e)),...r.outputs.flatMap(t=>U(t,a,e)),...r.error?U(r.error,a,e):[],...r.parent?U(r.parent,a,e):[]]}function mP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.ArgumentDeclaration)throw new Error("Entity must be an argument declaration to be flattened");return[r,...r.defaultValue?U(r.defaultValue,a):[],...r.writesValues.flatMap(t=>U(t,a,e)),...r.dataType?U(r.dataType,a,e):[],...r.parent?U(r.parent,a,e):[]]}function vP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.BreakStatement)throw new Error("Entity must be a break statement to be flattened");return[r,...r.outputs.flatMap(t=>U(t,a,e)),...r.throws?U(r.throws,a,e):[],...(hi(r)||[]).flatMap(t=>U(t,a,e)),...r.parent?U(r.parent,a,e):[]]}function TP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.BuiltInBaseEntity)throw new Error("Entity must be a built-in base entity to be flattened");return[r,...(r.properties||[]).flatMap(t=>U(t,a,e)),...(r.methods||[]).flatMap(t=>U(t,a,e)),...(r.abstractMethods||[]).flatMap(t=>U(t,a,e)),...(r.extends||[]).flatMap(t=>U(t,a,e))]}function IP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.Condition)throw new Error("Entity must be a condition to be flattened");return[r,...(r.inputs||[]).flatMap(t=>U(t,a,e)),...(r.successCalls||[]).flatMap(t=>U(t,a,e)),...(r.errorCalls||[]).flatMap(t=>U(t,a,e)),...(hi(r)||[]).flatMap(t=>U(t,a,e)),...r.parent?U(r.parent,a,e):[]]}function EP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.ContinueStatement)throw new Error("Entity must be a continue statement to be flattened");return[r,...r.outputs.flatMap(t=>U(t,a,e)),...r.throws?U(r.throws,a,e):[],...(hi(r)||[]).flatMap(t=>U(t,a,e)),...r.parent?U(r.parent,a,e):[]]}function AP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.DefinitionEntity)throw new Error("Entity must be a definition entity to be flattened");return[r,...(r.extends||[]).flatMap(t=>U(t,a,e)),...(r.implements||[]).flatMap(t=>U(t,a,e)),...(r.properties||[]).flatMap(t=>U(t,a,e)),...(r.methods||[]).flatMap(t=>U(t,a,e)),...(r.abstractMethods||[]).flatMap(t=>U(t,a,e)),...r.parent?U(r.parent,a,e):[]]}function bP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.DataType)throw new Error("Entity must be a data type to be flattened");return[r,...(r.andChildrenGroup||[]).flatMap(t=>U(t,a,e)),...(r.orChildrenGroup||[]).flatMap(t=>U(t,a,e)),...r.entity?U(r.entity,a,e):[],...r.parent?U(r.parent,a,e):[]]}function RP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.FunctionCall)throw new Error("Entity must be a function call to be flattened");return[r,...(r.inputs||[]).flatMap(t=>U(t,a,e)),...(r.outputs||[]).flatMap(t=>U(t,a,e)),...r.error?U(r.error,a,e):[],...r.process?U(r.process,a,e):[],...(hi(r)||[]).flatMap(t=>U(t,a,e)),...(r.successCalls||[]).flatMap(t=>U(t,a,e)),...(r.errorCalls||[]).flatMap(t=>U(t,a,e)),...r.parent?U(r.parent,a,e):[]]}function DP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.FunctionDeclaration)throw new Error("Entity must be a function declaration to be flattened");return[r,...(r.inputs||[]).flatMap(t=>U(t,a,e)),...(r.calls||[]).flatMap(t=>U(t,a,e)),...r.implements?U(r.implements,a,e):[],...r.parent?U(r.parent,a,e):[]]}function OP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.GlobalEvent)throw new Error("Entity must be a global event to be flattened");return[r,...(r.inputs||[]).flatMap(t=>U(t,a,e)),...(r.calls||[]).flatMap(t=>U(t,a,e)),...r.implements?U(r.implements,a,e):[],...r.parent?U(r.parent,a,e):[]]}function PP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.InputMap)throw new Error("Entity must be an input map to be flattened");return[r,...r.readsValue?U(r.readsValue,a,e):[],...r.declaration?U(r.declaration,a,e):[],...r.defaultValue?U(r.defaultValue,a,e):[],...r.parent?U(r.parent,a,e):[]]}function wP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.InstalledProject)throw new Error("Entity must be an installed project to be flattened");return[r,...(r.functions||[]).flatMap(t=>U(t,a,e)),...(r.events||[]).flatMap(t=>U(t,a,e)),...r.parent?U(r.parent,a,e):[]]}function CP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.InternalCall)throw new Error("Entity must be an internal call to be flattened");return[r,...(r.successCalls||[]).flatMap(t=>U(t,a,e)),...(r.errorCalls||[]).flatMap(t=>U(t,a,e)),...(r.inputs||[]).flatMap(t=>U(t,a,e)),...(r.outputs||[]).flatMap(t=>U(t,a,e)),...(hi(r)||[]).flatMap(t=>U(t,a,e)),...r.error?U(r.error,a,e):[],...r.process?U(r.process,a,e):[],...r.parent?U(r.parent,a,e):[]]}function VP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.LiteralValue)throw new Error("Entity must be a literal value to be flattened");return[r,...r.valueAsTypeSingle?U(r.valueAsTypeSingle,a,e):[],...r.valueAsTypeList&&Array.isArray(r.valueAsTypeList)?r.valueAsTypeList.flatMap(t=>U(t,a,e)):[],...r.parent?U(r.parent,a,e):[]]}function BP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.Loop)throw new Error("Entity must be a loop to be flattened");return[r,...(r.inputs||[]).flatMap(t=>U(t,a,e)),...(r.outputs||[]).flatMap(t=>U(t,a,e)),...(r.successCalls||[]).flatMap(t=>U(t,a,e)),...(r.errorCalls||[]).flatMap(t=>U(t,a,e)),...r.error?U(r.error,a,e):[],...r.process?U(r.process,a,e):[],...r.body?U(r.body,a,e):[],...(hi(r)||[]).flatMap(t=>U(t,a,e)),...r.parent?U(r.parent,a,e):[]]}function _P(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.Operation)throw new Error("Entity must be an operation to be flattened");return[r,...(r.successCalls||[]).flatMap(t=>U(t,a,e)),...(r.errorCalls||[]).flatMap(t=>U(t,a,e)),...(r.inputs||[]).flatMap(t=>U(t,a,e)),...(r.outputs||[]).flatMap(t=>U(t,a,e)),...r.error?U(r.error,a,e):[],...r.process?U(r.process,a,e):[],...(hi(r)||[]).flatMap(t=>U(t,a,e)),...r.parent?U(r.parent,a,e):[]]}function MP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.OutputMap)throw new Error("Entity must be an output map to be flattened");return[r,...(r.writesValues||[]).flatMap(t=>U(t,a,e)),...r.declaration?U(r.declaration,a,e):[],...r.defaultValue?U(r.defaultValue,a,e):[],...r.parent?U(r.parent,a,e):[]]}function NP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.PrimitiveEntity)throw new Error("Entity must be a primitive entity to be flattened");return[r,...(r.properties||[]).flatMap(t=>U(t,a,e)),...(r.methods||[]).flatMap(t=>U(t,a,e)),...(r.abstractMethods||[]).flatMap(t=>U(t,a,e))]}function LP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.Project)throw new Error("Entity must be a project to be flattened");return[r,...(r.entities||[]).flatMap(t=>U(t,a,e)),...(r.functions||[]).flatMap(t=>U(t,a,e)),...(r.events||[]).flatMap(t=>U(t,a,e)),...(r.projects||[]).flatMap(t=>U(t,a,e)),...(r.variableDeclarations||[]).flatMap(t=>U(t,a,e)),...(r.variableInstances||[]).flatMap(t=>U(t,a,e)),...(r.operations||[]).flatMap(t=>U(t,a,e)),...(r.conditions||[]).flatMap(t=>U(t,a,e)),...(r.functionCalls||[]).flatMap(t=>U(t,a,e)),...(r.projects||[]).flatMap(t=>U(t,a,e)),...(r.loops||[]).flatMap(t=>U(t,a,e)),...(r.searches||[]).flatMap(t=>U(t,a,e))]}function UP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.Property)throw new Error("Entity must be a property to be flattened");return[r,...r.defaultValue?U(r.defaultValue,a,e):[],...r.dataType?U(r.dataType,a,e):[],...r.parent?U(r.parent,a,e):[]]}function gP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.ReturnDeclaration)throw new Error("Entity must be a return declaration to be flattened");return[r,...r.readsValue?U(r.readsValue,a,e):[],...r.defaultValue?U(r.defaultValue,a,e):[],...r.dataType?U(r.dataType,a,e):[],...r.parent?U(r.parent,a,e):[]]}function jP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.ReturnStatement)throw new Error("Entity must be a return statement to be flattened");return[r,...(r.outputs||[]).flatMap(t=>U(t,a,e)),...r.throws?U(r.throws,a,e):[],...(hi(r)||[]).flatMap(t=>U(t,a,e)),...r.parent?U(r.parent,a,e):[]]}function $P(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.Search)throw new Error("Entity must be a search to be flattened");return[r,...(r.successCalls||[]).flatMap(t=>U(t,a,e)),...(r.errorCalls||[]).flatMap(t=>U(t,a,e)),...(r.inputsDeclarations||[]).flatMap(t=>U(t,a,e)),...(r.inputs||[]).flatMap(t=>U(t,a,e)),...(r.outputsDeclarations||[]).flatMap(t=>U(t,a,e)),...(r.outputs||[]).flatMap(t=>U(t,a,e)),...r.error?U(r.error,a,e):[],...(hi(r)||[]).flatMap(t=>U(t,a,e)),...r.parent?U(r.parent,a,e):[]]}function GP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.ValueDescriptor)throw new Error("Entity must be a value descriptor to be flattened");return[r,...r.defaultValue?U(r.defaultValue,a,e):[],...r.dataType?U(r.dataType,a,e):[],...r.parent?U(r.parent,a,e):[]]}function FP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.VariableDeclaration)throw new Error("Entity must be a variable declaration to be flattened");return[r,...(r.successCalls||[]).flatMap(t=>U(t,a,e)),...(r.errorCalls||[]).flatMap(t=>U(t,a,e)),...(r.inputs||[]).flatMap(t=>U(t,a,e)),...(r.outputs||[]).flatMap(t=>U(t,a,e)),...(r.internalCalls||[]).flatMap(t=>U(t,a,e)),...(r.writesValues||[]).flatMap(t=>U(t,a,e)),...r.readsValue?U(r.readsValue,a,e):[],...r.defaultValue?U(r.defaultValue,a,e):[],...(hi(r)||[]).flatMap(t=>U(t,a,e)),...r.dataType?U(r.dataType,a,e):[],...r.parent?U(r.parent,a,e):[]]}function xP(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(a.has(r.id))return[];if(a.add(r.id),r.type!==n.VariableInstance)throw new Error("Entity must be a variable instance to be flattened");return[r,...(r.successCalls||[]).flatMap(t=>U(t,a,e)),...(r.errorCalls||[]).flatMap(t=>U(t,a,e)),...(r.inputs||[]).flatMap(t=>U(t,a,e)),...(r.outputs||[]).flatMap(t=>U(t,a,e)),...(r.internalCalls||[]).flatMap(t=>U(t,a,e)),...(r.writesValues||[]).flatMap(t=>U(t,a,e)),...r.readsValue?U(r.readsValue,a,e):[],...r.defaultValue?U(r.defaultValue,a,e):[],...(hi(r)||[]).flatMap(t=>U(t,a,e)),...r.declaration?U(r.declaration,a,e):[],...r.parent?U(r.parent,a,e):[]]}function _i(){const r=new Set,a=oE.flatMap(e=>U(e,r)).map(e=>e.id);if(!a.includes("http-request-error-return-delaration-id"))throw new Error("Built-in base entities must be included in the list");return a}function U(r,a=new Set,e={ignoreBuiltInBaseEntities:!1}){if(!r)throw new Error("Entity must be defined to be flattened");if(r.type===n.GenericReference)return[];if(e.ignoreBuiltInBaseEntities&&(Ti.includes(r.type)||_i().includes(r.id)))return[];if(a.has(r.id))return[];switch(r.type){case n.FunctionCall:return RP(r,a,e);case n.Operation:return _P(r,a,e);case n.Condition:return IP(r,a,e);case n.Loop:return BP(r,a,e);case n.Search:return $P(r,a,e);case n.GlobalEvent:return OP(r,a,e);case n.ReturnStatement:return jP(r,a,e);case n.ContinueStatement:return EP(r,a,e);case n.BreakStatement:return vP(r,a,e);case n.VariableDeclaration:return FP(r,a,e);case n.DefinitionEntity:return AP(r,a,e);case n.FunctionDeclaration:return DP(r,a,e);case n.Project:return LP(r,a,e);case n.ActionDescriptor:return hP(r,a,e);case n.ArgumentDeclaration:return mP(r,a,e);case n.ReturnDeclaration:return gP(r,a,e);case n.ValueDescriptor:return GP(r,a,e);case n.InputMap:return PP(r,a,e);case n.OutputMap:return MP(r,a,e);case n.DataType:return bP(r,a,e);case n.InstalledProject:return wP(r,a,e);case n.InternalCall:return CP(r,a,e);case n.LiteralValue:return VP(r,a,e);case n.Property:return UP(r,a,e);case n.VariableInstance:return xP(r,a,e);case n.BuiltInBaseEntity:return e.ignoreBuiltInBaseEntities?[]:TP(r,a,e);case n.PrimitiveEntity:return e.ignoreBuiltInBaseEntities?[]:NP(r,a,e)}return[]}function Yc(r){return r.type===n.FunctionCall||r.type===n.InternalCall||[n.Operation,n.Condition,n.Loop].includes(r.type)?r.declaration.inputs:r.type===n.FunctionDeclaration||Gn.includes(r.type)?r.inputs:r.type===n.Search?r.inputsDeclarations:[]}function bJ(r,a){return a.type===n.Condition?a.inputs.find(e=>e.declaration.id===r.id):a.type===n.FunctionCall||a.type===n.Operation?a.inputs.find(e=>e.declaration.id===r.id):null}function kP(r){return ot.includes(r.type)?r.inputs:[]}function SP(r){var a;return r.type===n.FunctionCall?((a=r.declaration.returnStatements[0])==null?void 0:a.outputs)||[]:[n.Operation,n.Condition,n.Loop].includes(r.type)?r.declaration.outputs:r.type===n.Search?r.outputsDeclarations:st.includes(r.type)?r.outputs:[]}function RJ(r,a){return a.type===n.Condition?null:a.type===n.FunctionCall||a.type===n.Operation?a.outputs.find(e=>e.declaration.id===r.id):null}function DJ(r){return r.type===n.Condition?[]:ot.includes(r.type)?r.outputs:[]}function Kl(r){const a=r.readsValue;return a?wt(a):null}function ZP(r,a){const e=r.readsValue;return e?zl(e,a):null}function qP(r){const a=r.internalCalls||[];return p(Xt(p(a.flatMap(e=>[...e.successCalls,...e.errorCalls]))))}function Os(r){const a=zc(r),e=[];return a.forEach(t=>{if(tt.includes(t.type))e.push(t);else if(Er.includes(t.type)){const i=t.parent;e.push(i)}}),e}function p(r){const a=new Set;return r.filter(e=>!e||a.has(e.id)?!1:(a.add(e.id),!0))}function tn(r,a=!1){const e=[];if(r.type===n.Project&&e.push(...(r==null?void 0:r.entities)||[],...(r==null?void 0:r.functions)||[],...(r==null?void 0:r.variableDeclarations)||[],...(r==null?void 0:r.variableInstances)||[],...(r==null?void 0:r.searches)||[],...(r==null?void 0:r.loops)||[],...(r==null?void 0:r.operations)||[],...(r==null?void 0:r.conditions)||[],...(r==null?void 0:r.functionCalls)||[],...(r==null?void 0:r.events)||[],...(r==null?void 0:r.projects)||[]),dt.includes(r.type)&&e.push(...(r==null?void 0:r.detachedChildren)||[]),r.type===n.DefinitionEntity){const t=[...r.suggestedMethods,...r.methods].flatMap(i=>i.collapsed&&a?[]:tn(i));e.push(...t)}if(r.type===n.Condition){const t=r.successCalls.map(s=>wt(s)),i=r.errorCalls.map(s=>wt(s));e.push(...t,...i)}if(Gn.includes(r.type)){if(r.collapsed&&a)return[];const t=r.inputs.map(s=>Os(s)).flat(),i=r.calls.map(s=>wt(s));e.push(...p(t),...i)}if(ot.includes(r.type)&&r.type!==n.Condition&&r.type!==n.Loop){const t=r==null?void 0:r.outputs.map(l=>Os(l)).flat(),i=r.successCalls.map(l=>wt(l)),s=r.errorCalls.map(l=>wt(l));e.push(...p(t),...i,...s)}if(tt.includes(r.type)){const t=Os(r),i=qP(r);e.push(...t,...i)}if(r.type===n.Loop){const t=r.outputs.map(l=>Os(l)).flat();if(r.body){const l=tn(r.body,a);e.push(...l)}const i=r.errorCalls.map(l=>wt(l)),s=r.successCalls.map(l=>wt(l));e.push(...p(t),...s,...i)}if(r.type===n.FunctionDeclaration){if(r.collapsed&&a)return[];const t=r.inputs.map(s=>Os(s)).flat(),i=r.calls.map(s=>wt(s));e.push(...p(t),...i)}return p(e)}function JP(r,a=!1){const e=tn(r,a),t=[...e,...e.reduce((i,s)=>[...i,...JP(s,a)],[])];return p(t)}function WP(r){const a=Ln(r),e=[...a,...a.reduce((t,i)=>[...t,...WP(i)],[])];return p(e)}function Xl(r){return r.implements.reduce((a,e)=>e.type===n.DefinitionEntity?[...a,n.DefinitionEntity,...Xl(e),...Ql(e)]:[...a,e.name],[])}function Ql(r){return r.extends.reduce((a,e)=>e.type===n.DefinitionEntity?[...a,n.DefinitionEntity,...Ql(e),...Xl(e)]:[...a,e.name],[])}function Hc(r){return r.extends.reduce((a,e)=>e.type===n.DefinitionEntity?[...a,e,...Hc(e),...Kc(e)]:[...a,e],[])}function Kc(r){return r.implements.reduce((a,e)=>e.type===n.DefinitionEntity?[...a,e,...Kc(e),...Hc(e)]:[...a,e],[])}function Xc(r){return[...Ql(r),...Xl(r)].filter((e,t,i)=>i.indexOf(e)===t)}function zP(r){return r.implements.length===0&&r.extends.length===0?null:r.implements.find(t=>t.type===n.BuiltInBaseEntity&&t.name===z.PERSISTED_ENTITY)?r:[...r.implements,...r.extends].reduce((t,i)=>{if(i.type===n.DefinitionEntity){const s=zP(i);if(s)return s}return t},null)}function OJ(r){const a=r.extends.find(e=>e.type===n.BuiltInBaseEntity);return a&&a.type===n.BuiltInBaseEntity?a:null}function PJ(r){const a=r.implements.find(e=>e.type===n.BuiltInBaseEntity);return a&&a.type===n.BuiltInBaseEntity?a:null}function Qc(r){const a=r.extends.find(e=>e.type===n.DefinitionEntity);return a&&a.type===n.DefinitionEntity?a:null}function kt(r){if(r.type===n.BuiltInBaseEntity)return[r];const a=[...r.implements,...r.extends].reduce((e,t)=>t.type===n.BuiltInBaseEntity?[...e,t]:t.type===n.DefinitionEntity?[...e,...kt(t)]:e,[]);return p(a)}function La(r){return r.type===n.PrimitiveEntity?!0:r.type===n.BuiltInBaseEntity?r.interactive:!kt(r).find(t=>!t.interactive)}function wJ(r){return r.parent===r.project&&r.project.variableDeclarations.includes(r)}function ef(r){return r.parent!==r.project?!1:n.VariableDeclaration===r.type?r.project.variableDeclarations.includes(r):n.VariableInstance===r.type?r.project.variableInstances.includes(r):n.FunctionCall===r.type?r.project.functionCalls.includes(r):n.Condition===r.type?r.project.conditions.includes(r):n.Operation===r.type?r.project.operations.includes(r):n.Loop===r.type?r.project.loops.includes(r):n.Search===r.type?r.project.searches.includes(r):!1}function YP(r){if([...lt,n.DefinitionEntity,n.InstalledProject,n.Project].includes(r.type)||ef(r))return!1;const a=Ln(r);return a.length===0?!0:a.some(e=>YP(e))}function tf(r){return[...lt,n.DefinitionEntity,n.InstalledProject,n.Project].includes(r.type)||ef(r)?!1:Ln(r).length===0}function HP(r,a=0){if(tf(r)){const e=Ln(r);return e.length===0?r:e.map(i=>HP(i,a+1)).reduce((i,s)=>i?s&&s.x<i.x?s:i:s,null)}return null}function KP(r){const a=[];if(tf(r))a.push(r);else return[];return Ln(r).forEach(t=>{a.push(...KP(t))}),a}function XP(r){return r.type===n.FunctionDeclaration&&r.parent!==r.project&&!![n.DefinitionEntity,n.Loop,n.InstalledProject].includes(r.parent.type)}function CJ(r,a){const e=new Map;return r.forEach(t=>{e.set(t.id,t)}),a.forEach(t=>{e.set(t.id,t)}),Array.from(e.values())}function Ua(r){switch(r){case n.DefinitionEntity:return nn;case n.FunctionDeclaration:return jr;case n.VariableDeclaration:return qr;case n.VariableInstance:return Zr;case n.FunctionCall:return en;case n.Operation:return Gr;case n.Condition:return Sr;case n.ReturnStatement:return gr;case n.Loop:return kr;case n.Search:return Jr;case n.InputMap:return Wi;case n.OutputMap:return zi;case n.ArgumentDeclaration:return Yr;case n.ReturnDeclaration:return ai;case n.Property:return Ur;case n.InstalledProject:return Wr;case n.Project:return m;case n.DataType:return $r;case n.GlobalEvent:return Fr;case n.InternalCall:return zr;case n.ValueDescriptor:return mr;case n.BuiltInBaseEntity:return Ki;case n.PrimitiveEntity:return Qt;case n.ActionDescriptor:return Je;case n.LiteralValue:return Hr;case n.ContinueStatement:return Lt;case n.BreakStatement:return xr;default:return null}}function St(r,a){if(dt.includes(r.type))return r;if(Ti.includes(r.type))return null;const e=r.parent;if(!e)return null;if(e.type===n.GenericReference){const t=_(e);if(!t)return null;const i=a.get(t);return i?St(i,a):null}else return e===a?a:St(e,a)}function rf(r,a){if(Ti.includes(r.type)||a.getBuiltIn(r.id))return null;const e=mi(r.parent,a);return e?e===a?dt.includes(r.type)?r:null:e.type===n.DefinitionEntity?r:rf(e,a):null}function ed(r,a,e){if(r===a||a===e||r===e)return!1;const t=St(a.parent,e);return t===r?!0:ed(t,a,e)}var td=(r=>(r.SameBothLocal="same-both-local",r.AInB="a-in-b",r.BInA="b-in-a",r.ParallelInCommonParent="parallel-in-common-parent",r.ParallelInProject="parallel-in-project",r.AIsGlobalBIsNot="a-is-global-b-is-not",r.BIsGlobalAIsNot="b-is-global-a-is-not",r.SameBothGlobal="same-both-global",r))(td||{});function ga(r,a,e){const t=St(r,e),i=St(a,e);if(!t)throw new Error("Could not find scope owner for the entity: "+r.id);if(!i)throw new Error("Could not find scope owner for the entity: "+a.id);if(t===i&&t.type!==n.Project)return{compatible:!0,type:"same-both-local",commonAncestorScope:t};if(t===i&&t.type===n.Project)return{compatible:!0,type:"same-both-global",commonAncestorScope:t};if(t.type===n.Project&&i.type!==n.Project)return{compatible:!1,type:"a-is-global-b-is-not",commonAncestorScope:t};if(t.type!==n.Project&&i.type===n.Project)return{compatible:!1,type:"b-is-global-a-is-not",commonAncestorScope:i};if(ed(t,i,e))return{compatible:!0,type:"b-in-a",commonAncestorScope:t};if(ed(i,t,e))return{compatible:!0,type:"a-in-b",commonAncestorScope:i};const o=Jc(t,i);return o===e?{compatible:!1,type:"parallel-in-project",commonAncestorScope:o}:o?{compatible:!1,type:"parallel-in-common-parent",commonAncestorScope:St(o,e)}:{compatible:!1,type:"parallel-in-project",commonAncestorScope:e}}function QP(r,a,e){const t=ga(r,a,e);if(!t.compatible||t.type!=="same-both-local")return null;if(r===a)return r;let i=St(r.parent,e);if(i){if(i===a)return a;if(i.type===n.Project)return r}else return r;for(;i;){if(i){if(i===a)return a;if(i.type===n.Project)return r}else return r;i=St(i.parent,e)}let s=St(a.parent,e);if(s){if(s===r)return r;if(s.type===n.Project)return a}else return a;for(;s;){if(s){if(s===r)return r;if(s.type===n.Project)return a}else return a;s=St(s.parent,e)}return null}function ew(r){return r.length===0?null:r.length===1?r[0]:r.reduce((e,t)=>{const i=QP(e,t,t.project);return!i||i===t?e:t},r[0])}function mi(r,a){if(!r)return null;let e;return typeof r=="string"?e=r:r.type===n.GenericReference?e=_(r):e=r.id,e===a.id?a:a.get(e)}function rn(r){if(!r)return null;if(Ti.includes(r.type))return r;if(r.type===n.Project)return null;if(r.project.getBuiltIn(r.id))return r;const a=r.parent;return!a||a.type===n.Project?null:rn(a)}function ja(r){const a=[];function e(s,l){return a.some(o=>o.blockedByCaller===s&&o.blockedByCalling===l)}function t(s,l){e(s,l)||a.push({blockedByCaller:s,blockedByCalling:l})}const i=rf(r,r.project);return r.calledBySuccess.forEach(s=>{[...s.successCalls||[]].forEach(d=>{st.includes(d.type)&&d!==r&&(qe(r).find(c=>c===d)||t(s,d))});let o;if(ot.includes(s.type)&&(o=s),o){const d=ja(o);d.reachable||qe(r).find(c=>c===s)||d.blocks.forEach(c=>{t(s,c.blockedByCalling)})}}),r.calledByError.forEach(s=>{[...s.errorCalls||[]].forEach(d=>{st.includes(d.type)&&d!==r&&(qe(r).find(c=>c===d)||t(s,d))});let o;if(ot.includes(s.type)&&(o=s),o){const d=ja(o);d.reachable||qe(r).find(c=>c===s)||d.blocks.forEach(c=>{t(s,c.blockedByCalling)})}}),r.calledByEntry.forEach(s=>{if([...s.calls||[]].forEach(d=>{st.includes(d.type)&&d!==r&&(qe(r).find(c=>c===d)||t(s,d))}),s===i)return;let o;if(s.type===n.FunctionDeclaration){const d=wt(s);if(d.type===n.DefinitionEntity)return;d.type===n.Loop&&(o=d)}if(o){const d=ja(o);d.reachable||d.blocks.forEach(u=>{t(s,u.blockedByCalling)})}}),{reachable:a.length===0,entryPoint:i,blocks:a}}function VJ(r){return Za.includes(r.type)?r.type===n.FunctionDeclaration?!XP(r):!0:!1}function BJ(r){if(n.ActionDescriptor===r.type){if(r.project.operationDeclarations.find(s=>s.id===r.id))return n.Operation;if(r.project.globalEventActionDescriptors.find(s=>s.id===r.id))return n.GlobalEvent;if(r.project.loopDeclarations.find(s=>s.id===r.id))return n.Loop;if(r.project.conditionDeclarations.find(s=>s.id===r.id))return n.Condition}return r.type}function Ps(r,a){if(r.type!==n.DefinitionEntity||r.abstract)return!1;const e=Qc(r)||r;return!!Xc(e).includes(a)}function _J(r){const a=[];return r.entities.forEach(e=>{if(Ps(e,z.PERSISTED_ENTITY)){a.push(e);return}}),p(a)}function MJ(r){const a=[];return r.entities.forEach(e=>{if(Ps(e,z.RELATIONAL_DATABASE)){a.push(e);return}}),p(a)}function NJ(r){return r.type!==n.DefinitionEntity||r.abstract||!Ps(r,z.PERSISTED_ENTITY)?null:(r==null?void 0:r.properties.find(e=>{var t;return((t=e.implements)==null?void 0:t.id)===k[n.BuiltInBaseEntity][z.PERSISTED_ENTITY].properties.primaryKey.id&&!e.abstract}))||null}function LJ(r){if(r.type!==n.DefinitionEntity)return[];if(r.abstract)return[];if(!Ps(r,z.PERSISTED_ENTITY))return[];const a=[],e=r.properties.filter(t=>{var i;return((i=t.implements)==null?void 0:i.id)!==k[n.BuiltInBaseEntity][z.PERSISTED_ENTITY].properties.database.id&&!t.abstract});return a.push(...e),a}function UJ(r){var e;if(!r||r.type!==n.DefinitionEntity||!Ps(r,z.PERSISTED_ENTITY))return null;const a=r.properties.find(t=>{var i;return((i=t.implements)==null?void 0:i.id)===k[n.BuiltInBaseEntity][z.PERSISTED_ENTITY].properties.database.id});return(e=a==null?void 0:a.getDefaultValue())==null?void 0:e.valueAsTypeSingle}function mt(r,a){var t;if(!uf.includes(a.type)||!r)return a.project||null;let e=a.project;return r.type===n.Project?e=r:((t=a.project)==null?void 0:t.id)!==r.project.id&&(e=r.project),e}function gJ(r){switch(r){case n.Project:return m;case n.InstalledProject:return Wr;case n.DefinitionEntity:return nn;case n.FunctionDeclaration:return jr;case n.GlobalEvent:return Fr;case n.VariableInstance:return Zr;case n.VariableDeclaration:return qr;case n.InputMap:return Wi;case n.OutputMap:return zi;case n.Condition:return Sr;case n.Operation:return Gr;case n.FunctionCall:return en;case n.ReturnDeclaration:return ai;case n.ArgumentDeclaration:return Yr;case n.PrimitiveEntity:return Qt;case n.DataType:return $r;case n.Property:return Ur;case n.ActionDescriptor:return Je;case n.ReturnStatement:return gr;case n.ContinueStatement:return Lt;case n.BreakStatement:return xr;case n.Loop:return kr;case n.Search:return Jr;case n.ValueDescriptor:return mr;case n.InternalCall:return zr;case n.LiteralValue:return Hr}return null}function jJ(r){const a={added:{},updated:{},removed:{},affected:[],seenEntities:[],self:r==null?void 0:r.self};return r==null||r.added.forEach(e=>{a.added[e.id]=e}),r==null||r.updated.forEach(e=>{a.updated[e.id]=e}),r==null||r.removed.forEach(e=>{a.removed[e.id]=e}),a.affected=Array.from(new Set(r==null?void 0:r.affected.map(e=>e.id))),a}function pt(r,a){const e=Ua(r.type);return e?!e.MUTABLE_META_PROPERTIES.every(i=>{const s=r[i],l=a[i];return l===void 0||s===l?!0:Array.isArray(s)&&Array.isArray(l)?s.length!==l.length?!1:s.every((o,d)=>o===l[d]):!1}):!1}function id(r,a={}){if(r.type===n.Project)return[];if(!r.parent)return[];const e=_(r.parent);if(!e)return[];const t=a[e];return t?[t.id,...id(t,a)]:[]}function $J(r){const a=[],e=new Set;return[...r.listAdded,...r.listUpdated,...r.listAffected].forEach(t=>{const i=wt(t);!i||e.has(i.id)||(e.add(i.id),a.push(i))}),p(a)}function tw(r){const a=hZ(),e=r.toJSON();a.safeParse(e).success;const i=r.implements.flatMap(y=>GJ(r,y)),s=r.extends.flatMap(y=>FJ(r,y)),l=kJ(r),o=xJ(r);r.methods.flatMap(y=>y.validate());const d=[...i,...s,...l,...o];return He(r.errors,d)}function iw(r,a){const e=a.properties.filter(s=>s.abstract),t=[];let i=[...r.properties];return e.forEach(s=>{const l=i.find(o=>{var d;return((d=o.implements)==null?void 0:d.id)===s.id});l?i=i.filter(o=>o.id!==l.id):t.push(s)}),t}function rw(r,a){const e=a.abstractMethods,t=[];let i=[...r.methods];return e.forEach(s=>{const l=i.find(o=>{var d;return((d=o.implements)==null?void 0:d.id)===s.id});l?i=i.filter(o=>o.id!==l.id):t.push(s)}),t}function GJ(r,a){const e=[];if(!a.abstract){const y=de({id:r.id+"--"+F.ImplementingNonAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is implementing a non-abstract entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.ImplementingNonAbstractEntity,entity:r});return e.push(y.error),e}const t=a.properties.filter(y=>y.abstract),i=[];let s=[...r.properties];t.forEach(y=>{const c=s.find(I=>{var E;return((E=I.implements)==null?void 0:E.id)===y.id});c?s=s.filter(I=>I.id!==c.id):i.push(y)}),i.length&&i.forEach(y=>{const c=de({id:r.id+"--"+F.MissingPropertyImplementation+"--"+y.id,message:`Property "${y.name}" with id "${y.id}" of entity "${a.name}" with id "${a.id}" is not implemented when entity "${r.name}" with id "${r.id}" implements it`,issue:null,severity:D.Error,code:F.MissingPropertyImplementation,entity:r});e.push(c.error)});const l=[];let o=[...r.methods];a.abstractMethods.forEach(y=>{const c=o.find(I=>{var E;return((E=I.implements)==null?void 0:E.id)===y.id});c?o=o.filter(I=>I.id!==c.id):l.push(y)}),l.length&&l.forEach(y=>{const c=de({id:r.id+"--"+F.MissingMethodImplementation+"--"+y.id,message:`Method "${y.name}" with id "${y.id}" of entity "${a.name}" with id "${a.id}" is not implemented when entity "${r.name}" with id "${r.id}" implements it`,issue:null,severity:D.Error,code:F.MissingMethodImplementation,entity:r});e.push(c.error)});const d=[];a.properties.forEach(y=>{const c=s.find(I=>I.name===y.name);c&&d.push([c,y])}),d.length&&d.forEach(([y])=>{const c=de({id:r.id+"--"+j.PropertyOverwritesOtherSiblingWithSameName+"--"+y.id,message:`Property "${y.name}" with id "${y.id}" of entity "${r.name}" with id "${r.id}" overwrites the property with the same name from the base entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:j.PropertyOverwritesOtherSiblingWithSameName,entity:r});e.push(c.error)});const u=[];return a.methods.forEach(y=>{const c=o.find(I=>I.name===y.name);c&&u.push([c,y])}),u.length&&u.forEach(([y])=>{const c=de({id:r.id+"--"+j.MethodOverwritesOtherSiblingWithSameName+"--"+y.id,message:`Method "${y.name}" with id "${y.id}" of entity "${r.name}" with id "${r.id}" overwrites the method with the same name from the base entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:j.MethodOverwritesOtherSiblingWithSameName,entity:r});e.push(c.error)}),e}function FJ(r,a){const e=[],t=[];if(!r.abstract&&a.abstract){const s=de({id:r.id+"--"+a.id+"--"+F.NonAbstractExtendingAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is not-abstract but is extending an abstract entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.NonAbstractExtendingAbstractEntity,entity:r,firstRelationship:a});return e.push(s.error),e}if(r.abstract&&!a.abstract){const s=de({id:r.id+"--"+a.id+"--"+F.AbstractExtendingNonAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is abstract but is extending an non-abstract entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.AbstractExtendingNonAbstractEntity,entity:r,firstRelationship:a});return e.push(s.error),e}r.properties.forEach(s=>{var o;const l=a.properties.find(d=>d.name===s.name);((o=s.implements)==null?void 0:o.id)!==(l==null?void 0:l.id)&&l&&t.push(s)}),t.length&&t.forEach(s=>{const l=de({id:r.id+"--"+j.PropertyOverwritesOtherSiblingWithSameName,message:`Property "${s.name}" with id "${s.id}" of entity "${r.name}" with id "${r.id}" overwrites the property with the same name from the extended entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:j.PropertyOverwritesOtherSiblingWithSameName,entity:r});e.push(l.error)});const i=[];return r.methods.forEach(s=>{var o;const l=a.methods.find(d=>d.name===s.name);((o=s.implements)==null?void 0:o.id)!==(l==null?void 0:l.id)&&l&&i.push(s)}),i.length&&i.forEach(s=>{const l=de({id:r.id+"--"+j.MethodOverwritesOtherSiblingWithSameName,message:`Method "${s.name}" with id "${s.id}" of entity "${r.name}" with id "${r.id}" overwrites the method with the same name from the extended entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:j.MethodOverwritesOtherSiblingWithSameName,entity:r});e.push(l.error)}),e}function xJ(r){const a=[];if(!r.properties.length){const e=de({id:r.id+"--"+F.NoProperties,message:"No properties implemented",issue:null,severity:D.Warning,code:F.NoProperties,entity:r});a.push(e.error)}return r.properties.forEach(e=>{e.validate()}),a}function kJ(r){const a=[];if(r.abstract){if(r.methods.length){const e=de({id:r.id+"--"+F.AbstractEntityWithNonAbstractMethods,message:`Entity "${r.name}" with id "${r.id}" is marked as abstract but has non-abstract methods`,issue:null,severity:D.Error,code:F.AbstractEntityWithNonAbstractMethods,entity:r});a.push(e.error)}if(r.properties.some(e=>!e.abstract)){const e=de({id:r.id+"--"+F.AbstractEntityWithNonAbstractProperties,message:`Entity "${r.name}" with id "${r.id}" is marked as abstract but has non-abstract properties`,issue:null,severity:D.Error,code:F.AbstractEntityWithNonAbstractProperties,entity:r});a.push(e.error),r.properties.forEach(t=>{if(!t.abstract){const i=de({id:r.id+"--"+F.StaticEntityWithNonStaticProperties+"--"+t.id,message:`Property "${t.name}" with id "${t.id}" of entity "${r.name}" with id "${r.id}" is not marked as abstract but the entity is marked as abstract`,issue:null,severity:D.Error,code:F.StaticEntityWithNonStaticProperties,entity:r});a.push(i.error)}})}}else{if(r.abstractMethods.length){const e=de({id:r.id+"--"+F.AbstractPropertyInNonAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is not marked as abstract but has abstract methods`,issue:null,severity:D.Error,code:F.AbstractPropertyInNonAbstractEntity,entity:r});a.push(e.error)}if(r.properties.some(e=>e.abstract)){const e=de({id:r.id+"--"+F.AbstractMethodInNonAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is not marked as abstract but has abstract properties`,issue:null,severity:D.Error,code:F.AbstractMethodInNonAbstractEntity,entity:r});a.push(e.error),r.properties.forEach(t=>{if(t.abstract){const i=de({id:r.id+"--"+F.AbstractMethodInNonAbstractEntity+"--"+t.id,message:`Property "${t.name}" with id "${t.id}" of entity "${r.name}" with id "${r.id}" is marked as abstract but the entity is not marked as abstract`,issue:null,severity:D.Error,code:F.AbstractMethodInNonAbstractEntity,entity:r});a.push(i.error)}})}}if(r.static&&r.properties.some(e=>!e.static)){const e=de({id:r.id+"--"+F.StaticEntityWithNonStaticProperties,message:`Entity "${r.name}" with id "${r.id}" is marked as static but has non-static properties`,issue:null,severity:D.Error,code:F.StaticEntityWithNonStaticProperties,entity:r});a.push(e.error),r.properties.forEach(t=>{if(!t.static){const i=de({id:r.id+"--"+F.NonStaticPropertyInStaticEntity+"--"+t.id,message:`Property "${t.name}" with id "${t.id}" of entity "${r.name}" with id "${r.id}" is not marked as static but the entity is marked as static`,issue:null,severity:D.Error,code:F.NonStaticPropertyInStaticEntity,entity:r});a.push(i.error)}})}return a}function SJ(r,a){const e=[],t=kt(a);if(!a.abstract){const l=new it({id:r.id+"--"+a.id+"--"+F.ImplementingNonAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is implementing a non-abstract built-in entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.ImplementingNonAbstractEntity,entity:r,firstRelationship:a});e.push(l)}const i=r.implements.filter(l=>l.id!==a.id);if(r.abstract){const l=new it({id:r.id+"--"+a.id+"--"+F.AbstractEntityImplements,message:`Entity "${r.name}" with id "${r.id}" is marked as abstract and cannot implement built-in entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.AbstractEntityImplements,entity:r,firstRelationship:a});e.push(l)}if(r.static&&!a.static){const l=new it({id:r.id+"--"+a.id+"--"+F.StaticImplementingNonStaticEntity,message:`Entity "${r.name}" with id "${r.id}" is marked as static and cannot implement non-static built-in entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.StaticImplementingNonStaticEntity,entity:r,firstRelationship:a});e.push(l)}if(!r.static&&a.static){const l=new it({id:r.id+"--"+a.id+"--"+F.NonStaticImplementingStaticEntity,message:`Entity "${r.name}" with id "${r.id}" is not marked as static and cannot implement static built-in entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.NonStaticImplementingStaticEntity,entity:r,firstRelationship:a});e.push(l)}return i.length&&i.forEach(l=>{if(l.type===n.BuiltInBaseEntity){const o=t.filter(d=>d.id!==l.id);o.length&&o.forEach(d=>{if(d.id!==l.id){const u=new it({id:r.id+"--"+d.id+"--"+l.id+"--"+F.ImplementsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is implementing built-in entity "${d.name}" with id "${d.id}" but also implements entity "${l.name}" with id "${l.id}" which is incompatible`,issue:null,severity:D.Error,code:F.ImplementsIncompatibleEntities,entity:r,firstRelationship:d,secondRelationship:l});e.push(u)}})}else{kt(l).forEach(y=>{const c=t.filter(I=>I.id!==y.id);c.length&&c.forEach(I=>{if(I.id!==y.id){const E=new it({id:r.id+"--"+I.id+"--"+y.id+"--"+F.ImplementsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is implementing built-in entity "${I.name}" with id "${I.id}" but also implements entity "${y.name}" with id "${y.id}" which is incompatible`,issue:null,severity:D.Error,code:F.ImplementsIncompatibleEntities,entity:r,firstRelationship:I,secondRelationship:y});e.push(E)}})});const d=Tr(a.ownDeclaredProperties,l.ownDeclaredProperties,j.PropertyOverwritesOtherImplementedEntitysPropertyWithSameImplementation,j.PropertyOverwritesOtherImplementedEntitysPropertyWithSameName);e.push(...d.errors);const u=Tr(a.abstractMethods,[...l.abstractMethods,...l.methods],j.MethodOverwritesOtherImplementedEntitysMethodWithSameImplementation,j.MethodOverwritesOtherImplementedEntitysMethodWithSameName);e.push(...u.errors)}}),p(r.extends.flatMap(l=>kt(l))).forEach(l=>{if(!t.find(o=>o.id===l.id)){const o=new it({id:r.id+"--"+a.id+"--"+l.id+"--"+F.ExtendsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is implementing built-in entity "${a.name}" with id "${a.id}" but also extends entity "${l.name}" with id "${l.id}" which is incompatible`,issue:null,severity:D.Error,code:F.ExtendsIncompatibleEntities,entity:r,firstRelationship:a,secondRelationship:l});e.push(o)}}),e}function ZJ(r,a,e=!1){const t=[],i=kt(a);if(!r.abstract&&a.abstract){const y=de({id:r.id+"--"+a.id+"--"+F.NonAbstractExtendingAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is not-abstract but is extending an abstract entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.NonAbstractExtendingAbstractEntity,entity:r,firstRelationship:a});t.push(y.error)}if(r.abstract&&!a.abstract){const y=de({id:r.id+"--"+a.id+"--"+F.AbstractExtendingNonAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is abstract but is extending an non-abstract entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.AbstractExtendingNonAbstractEntity,entity:r,firstRelationship:a});t.push(y.error)}if(!r.static&&a.static){const y=de({id:r.id+"--"+a.id+"--"+F.NonStaticExtendingStaticEntity,message:`Entity "${r.name}" with id "${r.id}" is not static but is extending a static entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.NonStaticExtendingStaticEntity,entity:r,firstRelationship:a});t.push(y.error)}if(r.static&&!a.static){const y=de({id:r.id+"--"+a.id+"--"+F.StaticExtendingNonStaticEntity,message:`Entity "${r.name}" with id "${r.id}" is static but is extending an non-static entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.StaticExtendingNonStaticEntity,entity:r,firstRelationship:a});t.push(y.error)}if(!La(a)){const y=de({id:r.id+"--"+a.id+"--"+F.ExtendingNonInteractiveEntity,message:`Entity "${r.name}" with id "${r.id}" is extending an non-interactive entity "${a.name}" with id "${a.id}"`,issue:null,severity:D.Error,code:F.ExtendingNonInteractiveEntity,entity:r,firstRelationship:a});t.push(y.error)}const l=r.extends.filter(y=>y.id!==a.id);l.length&&l.forEach(y=>{if(y.type===n.BuiltInBaseEntity){const c=i.filter(I=>I.id!==y.id);c.length&&c.forEach(I=>{if(I.id!==y.id){const E=de({id:r.id+"--"+I.id+"--"+y.id+"--"+F.ExtendsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is extending built-in entity "${I.name}" with id "${I.id}" but also extends entity "${y.name}" with id "${y.id}" which is incompatible`,issue:null,severity:D.Error,code:F.ExtendsIncompatibleEntities,entity:r,firstRelationship:I,secondRelationship:y});t.push(E.error)}})}else{kt(y).forEach(M=>{const G=i.filter(B=>B.id!==M.id);G.length&&G.forEach(B=>{if(B.id!==M.id){const $=new it({id:r.id+"--"+B.id+"--"+M.id+"--"+F.ImplementsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is extending built-in entity "${B.name}" with id "${B.id}" but also extends or implements entity "${M.name}" with id "${M.id}" which is incompatible`,issue:null,severity:D.Error,code:F.ImplementsIncompatibleEntities,entity:r,firstRelationship:B,secondRelationship:M});t.push($)}})});const I=!!kt(y).find(M=>M.id===a.id);let E=[...y.properties];I&&(E=E.filter(M=>!a.properties.find(G=>{var B;return G.id===M.id||G.name===M.name||G.id===((B=M.implements)==null?void 0:B.id)})));let O=[...y.methods];I&&(O=O.filter(M=>!a.methods.find(G=>{var B;return G.id===M.id||G.name===M.name||G.id===((B=M.implements)==null?void 0:B.id)})));const P=Tr(a.ownDeclaredProperties,E,j.PropertyOverwritesOtherExtendedEntitysPropertyWithSameImplementation,j.PropertyOverwritesOtherExtendedEntitysPropertyWithSameName);t.push(...P.errors);const V=Tr(a.abstractMethods,O,j.MethodOverwritesOtherExtendedEntitysMethodWithSameImplementation,j.MethodOverwritesOtherExtendedEntitysMethodWithSameName);t.push(...V.errors)}}),e&&console.log("self.implements.length",r.implements.length),r.implements.length&&r.implements.forEach(y=>{if(y.type===n.BuiltInBaseEntity){const c=i.filter(I=>I.id!==y.id);c.length&&c.forEach(I=>{if(I.id!==y.id){const E=new it({id:r.id+"--"+I.id+"--"+y.id+"--"+F.ImplementsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is implementing built-in entity "${I.name}" with id "${I.id}" but also implements entity "${y.name}" with id "${y.id}" which is incompatible`,issue:null,severity:D.Error,code:F.ImplementsIncompatibleEntities,entity:r,firstRelationship:I,secondRelationship:y});t.push(E)}})}else{kt(y).forEach(O=>{const P=i.filter(V=>V.id!==O.id);P.length&&P.forEach(V=>{if(V.id!==O.id){const M=new it({id:r.id+"--"+V.id+"--"+O.id+"--"+F.ImplementsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is implementing built-in entity "${V.name}" with id "${V.id}" but also implements entity "${O.name}" with id "${O.id}" which is incompatible`,issue:null,severity:D.Error,code:F.ImplementsIncompatibleEntities,entity:r,firstRelationship:V,secondRelationship:O});t.push(M)}})});const I=Tr(a.ownDeclaredProperties,y.ownDeclaredProperties,j.PropertyOverwritesOtherImplementedEntitysPropertyWithSameImplementation,j.PropertyOverwritesOtherImplementedEntitysPropertyWithSameName);t.push(...I.errors);const E=Tr(a.abstractMethods,[...y.abstractMethods,...y.methods],j.MethodOverwritesOtherImplementedEntitysMethodWithSameImplementation,j.MethodOverwritesOtherImplementedEntitysMethodWithSameName);t.push(...E.errors)}});const o=Tr(r.ownDeclaredProperties,a.ownDeclaredProperties,j.PropertyOverwritesOtherSiblingWithSameImplementation,j.PropertyOverwritesOtherSiblingWithSameName);t.push(...o.errors);const d=Tr(a.methods,a.abstractMethods,j.MethodOverwritesOtherSiblingWithSameImplementation,j.MethodOverwritesOtherSiblingWithSameName);return t.push(...d.errors),p(r.extends.flatMap(y=>kt(y))).forEach(y=>{if(!i.find(c=>c.id===y.id)){const c=new it({id:r.id+"--"+a.id+"--"+y.id+"--"+F.ImplementsIncompatibleEntities,message:`Entity "${r.name}" with id "${r.id}" is extending built-in entity "${a.name}" with id "${a.id}" but also extends entity "${y.name}" with id "${y.id}" which is incompatible`,issue:null,severity:D.Error,code:F.ImplementsIncompatibleEntities,entity:r,firstRelationship:a,secondRelationship:y});t.push(c)}}),t}function qJ(r){const a=[];return r.implements.forEach(e=>{if(!e.static){const t=new it({id:r.id+"--"+e.id+"--"+F.StaticImplementingNonStaticEntity,message:`Entity "${r.name}" with id "${r.id}" is static but implements entity "${e.name}" with id "${e.id}" which is non-static`,issue:null,severity:D.Error,code:F.StaticImplementingNonStaticEntity,entity:r,firstRelationship:e});a.push(t)}}),r.extends.forEach(e=>{if(!e.static){const t=new it({id:r.id+"--"+e.id+"--"+F.StaticExtendingNonStaticEntity,message:`Entity "${r.name}" with id "${r.id}" is static but extends entity "${e.name}" with id "${e.id}" which is non-static`,issue:null,severity:D.Error,code:F.StaticExtendingNonStaticEntity,entity:r,firstRelationship:e});a.push(t)}}),a}function JJ(r){const a=[];if(r.implements.length){const e=new it({id:r.id+"--"+F.AbstractEntityImplements,message:`Entity "${r.name}" with id "${r.id}" cannot be marked as abstract because it implements other entities`,issue:null,severity:D.Error,code:F.AbstractEntityImplements,entity:r});a.push(e)}return r.extends.forEach(e=>{if(!e.abstract){const t=new it({id:r.id+"--"+e.id+"--"+F.AbstractExtendingNonAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is abstract but extends entity "${e.name}" with id "${e.id}" which is non-abstract`,issue:null,severity:D.Error,code:F.AbstractExtendingNonAbstractEntity,entity:r,firstRelationship:e});a.push(t)}}),a}function WJ(r){const a=[];return r.extends.forEach(e=>{if(e.static){const t=new it({id:r.id+"--"+e.id+"--"+F.NonStaticExtendingStaticEntity,message:`Entity "${r.name}" with id "${r.id}" is non-static but extends entity "${e.name}" with id "${e.id}" which is static`,issue:null,severity:D.Error,code:F.NonStaticExtendingStaticEntity,entity:r,firstRelationship:e});a.push(t)}}),a}function zJ(r){const a=[];return r.extends.forEach(e=>{if(e.abstract){const t=new it({id:r.id+"--"+e.id+"--"+F.NonAbstractExtendingAbstractEntity,message:`Entity "${r.name}" with id "${r.id}" is non-abstract but extends entity "${e.name}" with id "${e.id}" which is abstract`,issue:null,severity:D.Error,code:F.NonAbstractExtendingAbstractEntity,entity:r,firstRelationship:e});a.push(t)}}),a}const YJ=Object.freeze(Object.defineProperty({__proto__:null,getBaseMethodsNotImplemented:rw,getBasePropertiesNotImplemented:iw,validate:tw,validateCanBecomeAbstract:JJ,validateCanBecomeNonAbstract:zJ,validateCanBecomeNonStatic:WJ,validateCanBecomeStatic:qJ,validateCanExtendEntity:ZJ,validateCanImplementEntity:SJ},Symbol.toStringTag,{value:"Module"}));function HJ(r,a){const e=[];if(r.parent)if(r.id===r.parent)e.push(new w({id:`${r.id}--${r.parent}--${R.SelfReference}`,code:R.SelfReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a reference to itself at 'parent'. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null}));else{const t=a.get(r.parent);t?[n.Project,n.DataType].includes(t.type)||e.push(new w({id:`${r.id}--${r.parent}--${R.InvalidParentReference}`,code:R.InvalidParentReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a parent reference that isn't pointing to an entity of type 'project' or 'data-type'.`,issue:null})):e.push(new w({id:`${r.id}--${r.parent}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", is referencing an entity with id "${r.parent}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}return r.implements&&Array.isArray(r.implements)?r.implements.forEach(t=>{if(r.id===t){e.push(new w({id:`${r.id}--${t}--${R.SelfReference}`,code:R.SelfReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has a reference to itself at one of the 'implements' references. This is not allowed. Change the reference string or the 'entityId' property of the reference object.`,issue:null}));return}const i=a.get(t);i?[n.DefinitionEntity,n.BuiltInBaseEntity].includes(i.type)?i.abstract||e.push(new w({id:`${r.id}--${t}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has an 'implements' reference that isn't pointing to an abstract entity.`,issue:null})):e.push(new w({id:`${r.id}--${t}--${R.InvalidImplementsReference}`,code:R.InvalidImplementsReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has an 'implements' reference that isn't pointing to an entity of type 'definition-entity' or 'built-in-base-entity'.`,issue:null})):e.push(new w({id:`${r.id}--${t}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", is referencing an entity with id "${t}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}):e.push(new w({id:`${r.id}--${j.InvalidObjectStructure}`,code:j.InvalidObjectStructure,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has an 'implements' property that isn't an array.`,issue:null})),r.extends&&Array.isArray(r.extends)&&r.extends.forEach(t=>{const i=a.get(t);i?[n.DefinitionEntity,n.BuiltInBaseEntity].includes(i.type)?i.abstract&&e.push(new w({id:`${r.id}--${t}--${R.InvalidExtendsReference}`,code:R.InvalidExtendsReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has an 'extends' reference that isn't pointing to a non-abstract entity. Did you want to use the property 'implements', which holds a list of references to absract entities, instead?`,issue:null})):e.push(new w({id:`${r.id}--${t}--${R.InvalidExtendsReference}`,code:R.InvalidExtendsReference,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", has an 'extends' reference that isn't pointing to an entity of type 'definition-entity' or 'built-in-base-entity'.`,issue:null})):e.push(new w({id:`${r.id}--${t}--${R.ReferencedEntityNotFound}`,code:R.ReferencedEntityNotFound,severity:D.Error,message:`Entity of type "${r.type}" with id "${r.id}", is referencing an entity with id "${t}" that isn't yet found in the project. Perhaps it should be created first. Or perhaps the ID is incorrect.`,issue:null}))}),e}var rd=(r=>(r.Extends="extends",r.Implements="implements",r))(rd||{});const ge=class ge extends at{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"x");f(this,"y");f(this,"static");f(this,"abstract");f(this,"type",n.DefinitionEntity);f(this,"properties",[]);f(this,"methods",[]);f(this,"abstractMethods",[]);f(this,"extends",[]);f(this,"implements",[]);f(this,"project");f(this,"errors",[]);f(this,"parent");f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"suggestedProperties",[]);f(this,"suggestedMethods",[]);this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.description=e.description,this.x=e.x,this.y=e.y,this.static=e.static,this.abstract=e.abstract}static new(){return{id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:n.DefinitionEntity,name:"",description:"",static:!1,abstract:!1,properties:[],methods:[],abstractMethods:[],extends:[],implements:[],x:0,y:0,parent:null}}static fromGenerationTarget(e,t){let i=t;if(e.parent){const u=_(e.parent);i=t.get(u)}const s=[];e.implements&&e.implements.forEach(u=>{s.push(t.get(u)||t.getBuiltIn(u))});const l=[];e.extends&&e.extends.forEach(u=>{l.push(t.get(u)||t.getBuiltIn(u))});const o={id:e.id,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:e.name,type:n.DefinitionEntity,description:e.description,static:e.static,abstract:e.abstract,properties:[],methods:[],abstractMethods:[],extends:l,implements:s,x:0,y:0,parent:i},d=C(o,t);return d.setParent(i,null),d.initChildren(null),d}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[],l=HJ(i,t),o=Ic(i,t);s.push(...l,...o,...ut(i));const d=i.parent?t.get(i.parent):null;if(d&&d.type===n.DataType){const u=d;u.entity&&s.push(new w({id:`${e.id}--${R.NewEntityWouldOverriteExisting}`,code:R.NewEntityWouldOverriteExisting,severity:D.Error,message:`The entity of type '${e.type}' with id '${e.id}' can't be added to the 'parent' entity with id '${u.id}' because it already has an 'entity' child. Data type entities can only have one 'entity' as children.
406
406
  You can inspect the existing 'entity' field with the 'describe_entity' action. Like so:
407
407
  ${Yi({describe_entity:u.entity.id})}
408
- Alternatively you can update the parent data-type entity with 'update' action to remove the existing value of the field.`,issue:null}))}return{errors:s,modifiedData:i}}get interactive(){return this.implements.length?this.implements.every(e=>e.interactive):!0}get allBasePropertiesFromExtendedAndImplementedEntities(){return p([...this.extends.reduce((e,t)=>[...[...t.ownDeclaredProperties,...t.allBasePropertiesFromExtendedAndImplementedEntities].filter(s=>!s.abstract),...e],[]),...this.implements.reduce((e,t)=>[...[...t.ownDeclaredProperties,...t.allBasePropertiesFromExtendedAndImplementedEntities].filter(s=>!s.abstract),...e],[])])}get extendedPropertiesFromOriginalParents(){return p(this.extends.reduce((e,t)=>{const i=[...t.ownDeclaredProperties,...t.extendedPropertiesFromOriginalParents].filter(s=>!s.abstract);return[...e,...i]},[]))}get implementedPropertiesFromOriginalParents(){return p([...this.extends.reduce((e,t)=>{const i=t.implementedPropertiesFromOriginalParents,s=[...t.ownDeclaredProperties].filter(l=>!!l.abstract&&!i.find(o=>o.name===l.name));return[...i,...s,...e]},[]),...this.implements.reduce((e,t)=>{const i=t.implementedPropertiesFromOriginalParents,s=[...t.ownDeclaredProperties].filter(l=>!!l.abstract&&!i.find(o=>o.name===l.name));return[...i,...s,...e]},[])].filter(e=>!!e.abstract))}get extendedProperties(){return this.properties.filter(e=>e.isExtendedProperty)}get ownDeclaredProperties(){return this.properties.filter(e=>!e.isExtendedProperty)}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on an '${this.type}', must be the root project as it is a globally declared entity.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],i=[],s=[];return Object.values(this.detachedDependents).forEach(l=>{const o=l.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),i.push(...o.removed),s.push(...o.affected)}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];return t==="implements"&&this.removeImplementation(e),t==="extends"&&this.removeExtension(e),{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];return t==="implements"&&this.addImplementation(e),t==="extends"&&this.addExtension(e),{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){return this.implements.forEach(e=>{Ti.includes(e.type)||e.subscribeDependents([{entity:this,field:"implements"}])}),this.extends.forEach(e=>{Ti.includes(e.type)||e.subscribeDependents([{entity:this,field:"extends"}])}),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new ge(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.properties=this.properties,e.methods=this.methods,e.abstractMethods=this.abstractMethods,e.extends=this.extends,e.implements=this.implements,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[I,E]of c.knownVersions)u.set(I,E);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new ge(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.properties=o.properties,this.methods=o.methods,this.abstractMethods=o.abstractMethods,this.extends=o.extends,this.implements=o.implements,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);return this.initialData.extends.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addExtension(d),d.type!==n.BuiltInBaseEntity&&e.push(d))}),this.initialData.implements.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addImplementation(d),d.type!==n.BuiltInBaseEntity&&e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];this.initialized=!0,this.captureVersion();const{updated:o,added:d,removed:u,affected:y}=this.syncImplementationProperties(e);t.push(...o),i.push(...d),s.push(...u),l.push(...y);const{updated:c,added:I,removed:E,affected:O}=this.addExtendedProperties(e);return t.push(...c),i.push(...I),s.push(...E),l.push(...O),this.addSuggestions(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];if(this.parent.type===n.DataType){const o=this.parent;o.entity=this,t.push(o)}else this.project.addDefinitionEntity(this);return this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}addExtension(e){return this.extends.includes(e)||this.extends.push(e),this}removeExtension(e){return this.extends=this.extends.filter(t=>t.id!==e.id),this}addImplementation(e){return this.implements.includes(e)||this.implements.push(e),this}removeImplementation(e){return this.implements=this.implements.filter(t=>t.id!==e.id),this}removeProperty(e){return this.properties=this.properties.filter(t=>t.id!==e.id),this}addMethod(e){return this.methods.includes(e)||(this.methods.push(e),this.suggestedMethods=this.suggestedMethods.filter(t=>t.name!==e.name)),this}removeMethod(e){return this.methods=this.methods.filter(t=>t.id!==e.id),this}addProperty(e){return this.properties.includes(e)||(this.properties.push(e),this.suggestedProperties=this.suggestedProperties.filter(t=>t.name!==e.name)),this}addSuggestedProperty(e){return this.suggestedProperties.includes(e)||this.suggestedProperties.push(e),this}addSuggestedMethod(e){return this.suggestedMethods.includes(e)||this.suggestedMethods.push(e),this}removeSuggestedProperty(e){return this.suggestedProperties=this.suggestedProperties.filter(t=>t.id!==e.id),this}removeSuggestedMethod(e){return this.suggestedMethods=this.suggestedMethods.filter(t=>t.id!==e.id),this}addAbstractMethod(e){return this.abstractMethods.includes(e)||this.abstractMethods.push(e),this}removeAbstractMethod(e){return this.abstractMethods=this.abstractMethods.filter(t=>t.id!==e.id),this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.properties=this.initialData.properties.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.methods=this.initialData.methods.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.abstractMethods=this.initialData.abstractMethods.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.extends=this.initialData.extends.map(t=>C(t,this.project)),this.implements=this.initialData.implements.map(t=>C(t,this.project)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}syncImplementationProperties(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-implementation-properties"))){const t=[],i=[],s=[],l=[],o=this.properties,d=this.implementedPropertiesFromOriginalParents,u=[...this.allBasePropertiesFromExtendedAndImplementedEntities,...o];return d.filter(c=>!u.find(E=>{var O;return((O=E.implements)==null?void 0:O.id)===c.id})).forEach(c=>{if(this.properties.find(P=>{var V;return((V=P.implements)==null?void 0:V.id)===c.id}))return;const E=this.properties.find(P=>P.name===c.name&&!!P.abstract&&!P.implements);if(E){E.implements=c,E.abstract=!1;return}const O=c.clone(e,this,m.UUID.uuid());O.initChildren(e),i.push(O),e==null||e.add(O,A.Added),O.setImplements(c,e),O.metaSync({abstract:!1},e),this.addProperty(O)}),e==null||e.attemptAutoclose("sync-implementation-properties",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addExtendedProperties(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-extended-properties"))){const t=[],i=[],s=[],l=[],o=this.properties,d=this.extendedPropertiesFromOriginalParents,u=d.filter(c=>d.find(E=>{var O;return((O=E.implements)==null?void 0:O.id)===c.id})?!1:!c.abstract),y=new Set(o.map(c=>c.name));return u.forEach(c=>{if(y.has(c.name))return;y.add(c.name);const I=c.clone(e,this,m.UUID.uuid());I.initChildren(e),i.push(I),e==null||e.add(I,A.Added),this.addProperty(I)}),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSuggestions(){return this.implements.forEach(e=>{iw(this,e).forEach(s=>{const l=s.toJSON();l.id=`_suggestion--parent--${this.id}--${s.id}`;const o=C(l,this.project);o.suggestion=!0,o.setParent(this,null),o.initChildren(null),this.addSuggestedProperty(o)}),rw(this,e).forEach(s=>{const l=`_suggestion--parent--${this.id}--${s.id}`,o=s.implementAsFunctionDeclaration(null,this,l),d=C(o,this.project);if(d.suggestion=!0,d.setParent(this,null),d.initChildren(null),this.methods=this.methods.filter(u=>u.id!==l),d.inputs.forEach(u=>{u.suggestion=!0}),d.returnStatements.length){const u=d.returnStatements[0];u.suggestion=!0,u.outputs.forEach(y=>{y.suggestion=!0})}this.addSuggestedMethod(d)})}),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.name=e.name||s.name,this.description=e.description||s.description,this.x=e.x||s.x,this.y=e.y||s.y,this.static=e.static!==void 0?e.static:this.static,this.abstract=e.abstract!==void 0?e.abstract:this.abstract,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=g,...t){return await ge.repository.APILoad(this.id,...t),this}async APICreate(e=g,...t){return await ge.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=g,...t){return await ge.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=g,...t){return await ge.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=g,...t){return await ge.repository.APIClone(this.id,...t),this}async APILoadVersion(e=g,t,...i){return await ge.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:y,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...y),l.push(...c)}),this.properties.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.methods.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.abstractMethods.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.suggestedProperties.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.suggestedMethods.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),!e){if(this.parent.type===n.Project)this.parent.removeDefinitionEntity(this);else if(this.parent.type===n.DataType){const d=this.parent.setEntity(null);i.push(d)}}return t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.properties.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.methods.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.abstractMethods.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.suggestedProperties.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.suggestedMethods.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.extends.flatMap(i=>i.toFlat(e)),...this.implements.flatMap(i=>i.toFlat(e)),...this.properties.flatMap(i=>i.toFlat(e)),...this.methods.flatMap(i=>i.toFlat(e)),...this.abstractMethods.flatMap(i=>i.toFlat(e)),...this.parent.toFlat(e)])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.extends.flatMap(i=>i.toFlatIds(e)),...this.implements.flatMap(i=>i.toFlatIds(e)),...this.properties.flatMap(i=>i.toFlatIds(e)),...this.methods.flatMap(i=>i.toFlatIds(e)),...this.abstractMethods.flatMap(i=>i.toFlatIds(e)),...this.parent.toFlatIds(e)])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,static:this.static,abstract:this.abstract,x:this.x,y:this.y,type:this.type,name:this.name}}toJSON(e=new Set){return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,x:this.x,y:this.y,static:this.static,abstract:this.abstract,properties:this.properties.map(t=>t.toJSON(e)),methods:this.methods.map(t=>t.toJSON(e)),abstractMethods:this.abstractMethods.map(t=>t.toJSON(e)),implements:this.implements.map(t=>t.toJSON(e)),extends:this.extends.map(t=>t.toJSON(e)),parent:this.parent.toReference()})}toJSONClone(e=q){var i,s,l,o,d;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:this.type,name:this.name,description:this.description,x:this.x,y:this.y,static:this.static,abstract:this.abstract,properties:this.properties.map(u=>u.toJSONClone({...e,newId:null})),methods:this.methods.map(u=>u.toJSONClone({...e,newId:null})),abstractMethods:this.abstractMethods.map(u=>u.toJSONClone({...e,newId:null})),implements:this.implements.map(u=>u.type===n.BuiltInBaseEntity?u.toJSON():u.toJSONClone({...e,newId:null})),extends:this.extends.map(u=>u.type===n.BuiltInBaseEntity?u.toJSON():u.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,description:this.description,type:this.type,x:this.x,y:this.y,static:this.static,abstract:this.abstract,properties:this.properties.map(s=>s.toReference(e)),methods:this.methods.map(s=>s.toReference(e)),abstractMethods:this.abstractMethods.map(s=>s.toReference(e)),implements:this.implements.map(s=>s.toReference(e)),extends:this.extends.map(s=>s.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.properties.flatMap(i=>i.toFlatJSON(e)),...this.methods.flatMap(i=>i.toFlatJSON(e)),...this.abstractMethods.flatMap(i=>i.toFlatJSON(e)),...this.implements.flatMap(i=>i.toFlatJSON(e)),...this.extends.flatMap(i=>i.toFlatJSON(e)),...this.parent.toFlatJSON(e)])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,name:this.name,description:this.description,type:this.type,static:this.static,abstract:this.abstract,extends:this.extends.map(t=>t.id),implements:this.implements.map(t=>t.id),parent:e}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.properties.flatMap(i=>i.toFlatGenerationTarget(e)),...this.methods.flatMap(i=>i.toFlatGenerationTarget(e)),...this.abstractMethods.flatMap(i=>i.toFlatGenerationTarget(e)),...this.implements.filter(i=>i.type===n.DefinitionEntity).flatMap(i=>i.toFlatGenerationTarget(e)),...this.implements.filter(i=>i.type===n.DefinitionEntity).flatMap(i=>i.toFlatGenerationTarget(e)),...this.parent.toFlatGenerationTarget(e)])}clearErrors(){return this.errors=[],this.properties.forEach(e=>e.clearErrors()),this.methods.forEach(e=>e.clearErrors()),this.abstractMethods.forEach(e=>e.clearErrors()),this}validate(){return this.errors=tw(this),{success:!0,error:null,data:null}}getErrors(){return[...this.errors,...this.properties.flatMap(t=>t.getErrors()),...this.methods.flatMap(t=>t.getErrors()),...this.abstractMethods.flatMap(t=>t.getErrors())]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var P,V,M;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.properties=[],o.methods=[],o.abstractMethods=[];const u=d.split("-id"),y=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=ct(o,l);t&&c.setParent(t,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,A.Added);const I=(P=this.properties)==null?void 0:P.map(G=>G.clone(e,c,m.UUID.uuid(),s));c.properties=I;const E=(V=this.methods)==null?void 0:V.map((G,B)=>G.clone(e,c,y+"-method-"+B+"-id",s));c.methods=E;const O=(M=this.abstractMethods)==null?void 0:M.map((G,B)=>G.clone(e,c,y+"-abstract-method-"+B+"-id",s));return c.abstractMethods=O,e==null||e.attemptAutoclose("clone-entity",this.id),c}getFunctionDeclaration(e){return this.methods.find(t=>t.id===e)}implement(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"implement-definition-entity")),i){const s=Jl(this,e,t,i);return t==null||t.attemptAutoclose("implement-definition-entity",this.id),s}getAllInteractiveMethods(){const e=this.implements.filter(i=>i.type===n.DefinitionEntity||i.type===n.BuiltInBaseEntity&&i.interactive);return p([...this.methods,...this.extends.flatMap(i=>i.getAllInteractiveMethods()),...e.flatMap(i=>i.getAllInteractiveMethods())])}inferFromInputs(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"infer-definition-entity-from-inputs"))){const i=[],s=[],l=[],o=[];if(this.parent.type!==n.DataType||!this.parent.inferred)return t==null||t.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};const d=[];e.forEach(c=>{d.find(E=>x(E,this.project)===x(c,this.project))||d.push(c)});const u=this.properties.filter(c=>!c.dataType);d.forEach(c=>{var M,G;const I=u.find(B=>x(B,this.project)===x(c,this.project));if(!I)return;const O=Nn(c.parent).getMasterInputWithValueWritterFromAllInstances(c),P=Ji(O,t),V=P==null?void 0:P.clone(t,I,m.UUID.uuid(),!0);if(V){const B=(M=I.dataType)==null?void 0:M.merge(V,t);I.dataType&&(B==null?void 0:B.self.id)!==I.dataType.id&&I.dataType.remove({ignoreUpstream:!1},t),V.id!==((G=B==null?void 0:B.self)==null?void 0:G.id)&&V.remove({ignoreUpstream:!1},t),B!=null&&B.self&&(B.self.metaSync({inferred:!0,like:!0},t),t==null||t.add(B.self,A.Added),I.setDataType(B.self),t==null||t.add(I,A.Updated))}c.setDeclaration(I),t==null||t.add(c,A.Updated)});const y=[];return d.forEach(c=>{if(!c.declaration){y.push(c);return}}),y.length===0?(t==null||t.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(y.forEach(c=>{var B,$,Z,J;const I=this.properties.find(te=>x(te,this.project)===x(c,this.project));if(I){if(c.setDeclaration(I),!I.getDataType(t)){const fe=Nn(c.parent).getMasterInputWithValueWritterFromAllInstances(c),Ie=Ji(fe),X=Ie==null?void 0:Ie.clone(t,I,m.UUID.uuid(),!0);if(X){const le=(B=I.dataType)==null?void 0:B.merge(X,t);I.dataType&&(le==null?void 0:le.self.id)!==I.dataType.id&&I.dataType.remove({ignoreUpstream:!1},t),X.id!==(($=le==null?void 0:le.self)==null?void 0:$.id)&&X.remove({ignoreUpstream:!1},t),le!=null&&le.self&&(le.self.metaSync({inferred:!0,like:!0},t),t==null||t.add(le.self,A.Added),I.setDataType(le.self),t==null||t.add(I,A.Updated))}}return}const E={id:m.UUID.uuid(),type:n.Property,version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:x(c,this.project),description:c.description,defaultValue:null,static:!0,abstract:!1,private:!1,hidden:!1,required:!1,constant:!0,index:c.index,implements:null,dataType:null,parent:this.toReference()},O=C(E,this.project);O.setParent(this,t),O.initChildren(t),t==null||t.add(O,A.Added);const V=Nn(c.parent).getMasterInputWithValueWritterFromAllInstances(c),M=Ji(V),G=M==null?void 0:M.clone(t,O,m.UUID.uuid(),!0);if(G){const te=(Z=O.dataType)==null?void 0:Z.merge(G,t);O.dataType&&(te==null?void 0:te.self.id)!==O.dataType.id&&O.dataType.remove({ignoreUpstream:!1},t),G.id!==((J=te==null?void 0:te.self)==null?void 0:J.id)&&G.remove({ignoreUpstream:!1},t),te!=null&&te.self&&(te.self.metaSync({inferred:!0,like:!0},t),t==null||t.add(te.self,A.Added),O.setDataType(te.self),t==null||t.add(O,A.Updated))}return this.addProperty(O),c.setDeclaration(O),t==null||t.add(c,A.Updated),O}),t==null||t.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:p(i),updated:p(s),removed:p(l),affected:p(o),self:this})}};f(ge,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(ge,"type",n.DefinitionEntity),f(ge,"USER_MANAGED_PARENT_TYPES",[n.Project,n.DataType]),f(ge,"PARENT_TYPES",[...ge.USER_MANAGED_PARENT_TYPES]),f(ge,"MUTABLE_BASE_PROPERTIES",["name","description","static","abstract"]),f(ge,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(ge,"BASE_PROPERTIES",[...ge.MUTABLE_BASE_PROPERTIES,...ge.INMUTABLE_BASE_PROPERTIES]),f(ge,"MUTABLE_META_PROPERTIES",[...ge.MUTABLE_BASE_PROPERTIES,"x","y"]),f(ge,"INMUTABLE_META_PROPERTIES",[...ge.INMUTABLE_BASE_PROPERTIES]),f(ge,"META_PROPERTIES",[...ge.MUTABLE_META_PROPERTIES,...ge.INMUTABLE_META_PROPERTIES]),f(ge,"MUTABLE_UPSTREAM_PROPERTIES",["extends","implements"]),f(ge,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),f(ge,"UPSTREAM_PROPERTIES",[...ge.MUTABLE_UPSTREAM_PROPERTIES,...ge.INMUTABLE_UPSTREAM_PROPERTIES]),f(ge,"MUTABLE_DOWNSTREAM_PROPERTIES",["properties","methods","abstractMethods"]),f(ge,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(ge,"DOWNSTREAM_PROPERTIES",[...ge.MUTABLE_DOWNSTREAM_PROPERTIES,...ge.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(ge,"PROPERTIES",[...ge.META_PROPERTIES,...ge.UPSTREAM_PROPERTIES,...ge.DOWNSTREAM_PROPERTIES]);let nn=ge;function KJ(r){const a=z3(),e=r.toJSON();a.safeParse(e).success;const i=[];return He(r.errors,i)}const Fa=class Fa extends at{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"version");f(this,"name");f(this,"description",null);f(this,"type",n.BuiltInBaseEntity);f(this,"abstract",!1);f(this,"static");f(this,"properties",[]);f(this,"methods",[]);f(this,"abstractMethods",[]);f(this,"extends",[]);f(this,"interactive",!1);f(this,"errors",[]);f(this,"project");this.initialData=this.initialData||e,this.project=this.project||t,this.id=this.id||e.id,this.version=this.version||e.version,this.name=this.name||e.name,this.static=this.static||e.static,this.interactive=this.interactive||e.interactive,this.abstract=e.abstract,this.properties=this.initialData.properties.map(i=>{const s=C(i,this.project);return s.setParent(this,null),s.initChildren(null),s}),this.methods=this.initialData.methods.map(i=>{const s=C(i,this.project);return s.setParent(this,null),s.initChildren(null),s}),this.abstractMethods=this.initialData.abstractMethods.map(i=>{const s=C(i,this.project);return s.setParent(this,null),s.initChildren(null),s}),this.extends=this.initialData.extends.map(i=>C(i,this.project))}get allBasePropertiesFromExtendedAndImplementedEntities(){return p(this.extends.reduce((e,t)=>{const i=[...t.ownDeclaredProperties,...t.allBasePropertiesFromExtendedAndImplementedEntities].filter(s=>!s.abstract);return[...e,...i]},[]))}get extendedPropertiesFromOriginalParents(){return p(this.extends.reduce((e,t)=>{const i=[...t.ownDeclaredProperties,...t.extendedPropertiesFromOriginalParents].filter(s=>!s.abstract);return[...e,...i]},[]))}get implementedPropertiesFromOriginalParents(){return p([...this.extends.reduce((e,t)=>{const i=t.implementedPropertiesFromOriginalParents,s=[...t.ownDeclaredProperties].filter(l=>!!l.abstract&&!i.find(o=>o.name===l.name));return[...i,...s,...e]},[])])}get extendedProperties(){return this.properties.filter(e=>e.isExtendedProperty)}get ownDeclaredProperties(){return this.properties.filter(e=>!e.isExtendedProperty)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}async APILoad(e=g,...t){return await Fa.repository.APILoad(this.id,...t),this}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.properties.flatMap(i=>i.toFlat(e)),...this.methods.flatMap(i=>i.toFlat(e)),...this.abstractMethods.flatMap(i=>i.toFlat(e)),...this.extends.flatMap(i=>i.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.properties.flatMap(i=>i.toFlatIds(e)),...this.methods.flatMap(i=>i.toFlatIds(e)),...this.abstractMethods.flatMap(i=>i.toFlatIds(e)),...this.extends.flatMap(i=>i.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,interactive:this.interactive,abstract:this.abstract,static:this.static,type:this.type,name:this.name}}toJSON(e=new Set){return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,abstract:this.abstract,static:this.static,interactive:this.interactive,properties:this.properties.map(t=>t.toJSON(e)),methods:this.methods.map(t=>t.toJSON(e)),abstractMethods:this.abstractMethods.map(t=>t.toJSON(e)),extends:this.extends.map(t=>t.toJSON(e))})}toReference(e=q){return{id:this.id+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:this.id,version:this.version,entityType:this.type}}toShallowJSON(e=q){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,abstract:this.abstract,static:this.static,interactive:this.interactive,properties:this.properties.map(t=>t.toReference()),methods:this.methods.map(t=>t.toReference()),abstractMethods:this.abstractMethods.map(t=>t.toReference()),extends:this.extends.map(t=>t.toReference())}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.properties.flatMap(i=>i.toFlatJSON(e)),...this.methods.flatMap(i=>i.toFlatJSON(e)),...this.abstractMethods.flatMap(i=>i.toFlatJSON(e))])}toGenerationTarget(){return{id:this.id,type:this.type,name:this.name,description:this.description,static:this.static,abstract:this.abstract,interactive:this.interactive,extends:this.extends.map(e=>e.id)}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.properties.flatMap(i=>i.toFlatGenerationTarget(e)),...this.methods.flatMap(i=>i.toFlatGenerationTarget(e)),...this.abstractMethods.flatMap(i=>i.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.properties.forEach(e=>e.clearErrors()),this.methods.forEach(e=>e.clearErrors()),this.abstractMethods.forEach(e=>e.clearErrors()),this}validate(){const e=KJ(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.properties.flatMap(t=>t.getErrors()),...this.methods.flatMap(t=>t.getErrors()),...this.abstractMethods.flatMap(t=>t.getErrors())]}getShallowErrors(){return this.errors}implement(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),null,!0,"implement-built-in-base-entity")),i){const s=Jl(this,e,t,i);return t==null||t.attemptAutoclose("implement-built-in-base-entity",this.id),s}getAllInteractiveMethods(){const e=[];return this.interactive&&(e.push(...this.methods),this.extends.filter(i=>i.type===n.BuiltInBaseEntity&&i.interactive||i.type===n.PrimitiveEntity).forEach(i=>{i instanceof Fa&&e.push(...i.getAllInteractiveMethods())})),p(e)}};f(Fa,"repository",{APILoad:async(e,...t)=>null});let Ki=Fa;function XJ(r){const a=G3(),e=r.toJSON();a.safeParse(e).success;const i=[];return He(r.errors,i)}const od=class od extends at{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"type",n.PrimitiveEntity);f(this,"static");f(this,"abstract");f(this,"properties",[]);f(this,"methods",[]);f(this,"abstractMethods",[]);f(this,"extends",[]);f(this,"errors",[]);f(this,"project");this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.static=e.static,this.abstract=e.abstract,this.properties=this.initialData.properties.map(i=>{const s=C(i,this.project);return s.setParent(this,null),s.initChildren(null),s}),this.methods=this.initialData.methods.map(i=>{const s=C(i,this.project);return s.parent=this,s}),this.abstractMethods=this.initialData.abstractMethods.map(i=>{const s=C(i,this.project);return s.parent=this,s})}get allBasePropertiesFromExtendedAndImplementedEntities(){return p(this.extends.reduce((e,t)=>{const i=[...t.ownDeclaredProperties,...t.allBasePropertiesFromExtendedAndImplementedEntities].filter(s=>!s.abstract);return[...e,...i]},[]))}get extendedPropertiesFromOriginalParents(){return p(this.extends.reduce((e,t)=>{const i=[...t.ownDeclaredProperties,...t.extendedPropertiesFromOriginalParents].filter(s=>!s.abstract);return[...e,...i]},[]))}get implementedPropertiesFromOriginalParents(){return p([...this.extends.reduce((e,t)=>{const i=t.implementedPropertiesFromOriginalParents,s=[...t.ownDeclaredProperties].filter(l=>!!l.abstract&&!i.find(o=>o.name===l.name));return[...i,...s,...e]},[])])}get extendedProperties(){return this.properties.filter(e=>e.isExtendedProperty)}get ownDeclaredProperties(){return this.properties.filter(e=>!e.isExtendedProperty)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}async APILoad(e=g,...t){return await od.repository.APILoad(this.id,...t),this}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.properties.flatMap(i=>i.toFlat(e)),...this.methods.flatMap(i=>i.toFlat(e)),...this.abstractMethods.flatMap(i=>i.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.properties.flatMap(i=>i.toFlatIds(e)),...this.methods.flatMap(i=>i.toFlatIds(e)),...this.abstractMethods.flatMap(i=>i.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,static:this.static,abstract:this.abstract,type:this.type,name:this.name}}toJSON(e=new Set){return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,static:this.static,abstract:this.abstract,properties:this.properties.map(t=>t.toJSON(e)),methods:this.methods.map(t=>t.toJSON(e)),abstractMethods:this.abstractMethods.map(t=>t.toJSON(e)),extends:this.extends.map(t=>t.toJSON(e))})}toReference(e=q){return{id:this.id+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:this.id,version:this.version,entityType:this.type}}toShallowJSON(e=q){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,abstract:this.abstract,static:this.static,properties:this.properties.map(t=>t.toReference()),methods:this.methods.map(t=>t.toReference()),abstractMethods:this.abstractMethods.map(t=>t.toReference()),extends:this.extends.map(t=>t.toReference())}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.properties.flatMap(i=>i.toFlatJSON(e)),...this.methods.flatMap(i=>i.toFlatJSON(e)),...this.abstractMethods.flatMap(i=>i.toFlatJSON(e))])}toGenerationTarget(){return{id:this.id,type:this.type,name:this.name,description:this.description,static:this.static,abstract:this.abstract,extends:this.extends.map(e=>e.id)}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.properties.flatMap(i=>i.toFlatGenerationTarget(e)),...this.methods.flatMap(i=>i.toFlatGenerationTarget(e)),...this.abstractMethods.flatMap(i=>i.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.properties.forEach(e=>e.clearErrors()),this.methods.forEach(e=>e.clearErrors()),this.abstractMethods.forEach(e=>e.clearErrors()),this}validate(){const e=XJ(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.properties.flatMap(t=>t.getErrors()),...this.methods.flatMap(t=>t.getErrors()),...this.abstractMethods.flatMap(t=>t.getErrors())]}getShallowErrors(){return this.errors}getAllInteractiveMethods(){const e=[];return e.push(...this.methods),this.extends.filter(i=>i.type===n.BuiltInBaseEntity&&i.interactive||i.type===n.PrimitiveEntity).forEach(i=>{i instanceof Ki&&e.push(...i.getAllInteractiveMethods())}),p(e)}};f(od,"repository",{APILoad:async(e,...t)=>null});let Qt=od;function ct(r,a){if(!r)throw new Error("Entity is null");const e=a.get(r.id);switch(r.type){case n.LiteralValue:return e||new Hr(r,a);case n.DefinitionEntity:return e||new nn(r,a);case n.PrimitiveEntity:return e||new Qt(r,a);case n.FunctionDeclaration:return e||new jr(r,a);case n.GlobalEvent:return e||new Fr(r,a);case n.DataType:return e||new $r(r,a);case n.Property:return e||new Ur(r,a);case n.FunctionCall:return e||new en(r,a);case n.Condition:return e||new Sr(r,a);case n.Operation:return e||new Gr(r,a);case n.VariableDeclaration:return e||new qr(r,a);case n.VariableInstance:return e||new Zr(r,a);case n.OutputMap:return e||new zi(r,a);case n.ReturnDeclaration:return e||new ai(r,a);case n.ArgumentDeclaration:return e||new Yr(r,a);case n.InputMap:return e||new Wi(r,a);case n.Project:return e||new m(r);case n.InstalledProject:return e||new Wr(r,a);case n.ActionDescriptor:return e||new Je(r,a);case n.ReturnStatement:return e||new gr(r,a);case n.Loop:return e||new kr(r,a);case n.Search:return e||new Jr(r,a);case n.ValueDescriptor:return e||new mr(r,a);case n.BuiltInBaseEntity:return e||new Ki(r,a);case n.InternalCall:return e||new zr(r,a);case n.ContinueStatement:return e||new Lt(r,a);case n.BreakStatement:return e||new xr(r,a);case n.GenericReference:return a.get(r.entityId);default:throw new Error("Invalid entity type: "+r.type)}}function C(r,a){if(!r)throw new Error("Entity is null");const e=ct(r,a);return e.subscribe(),e}function QJ(r,a){if(!r)throw new Error("Entity is null");switch(r.type){case n.LiteralValue:return Hr.fromGenerationTarget(r,a);case n.DefinitionEntity:return nn.fromGenerationTarget(r,a);case n.FunctionDeclaration:return jr.fromGenerationTarget(r,a);case n.GlobalEvent:return Fr.fromGenerationTarget(r,a);case n.DataType:return $r.fromGenerationTarget(r,a);case n.Property:return Ur.fromGenerationTarget(r,a);case n.FunctionCall:return en.fromGenerationTarget(r,a);case n.Condition:return Sr.fromGenerationTarget(r,a);case n.Operation:return Gr.fromGenerationTarget(r,a);case n.VariableDeclaration:return qr.fromGenerationTarget(r,a);case n.VariableInstance:return Zr.fromGenerationTarget(r,a);case n.OutputMap:return zi.fromGenerationTarget(r,a);case n.ReturnDeclaration:return ai.fromGenerationTarget(r,a);case n.ArgumentDeclaration:return Yr.fromGenerationTarget(r,a);case n.InputMap:return Wi.fromGenerationTarget(r,a);case n.InstalledProject:return Wr.fromGenerationTarget(r,a);case n.ReturnStatement:return gr.fromGenerationTarget(r,a);case n.Loop:return kr.fromGenerationTarget(r,a);case n.Search:return Jr.fromGenerationTarget(r,a);case n.ActionDescriptor:return Je.fromGenerationTarget(r,a);case n.ValueDescriptor:return mr.fromGenerationTarget(r,a);case n.InternalCall:return zr.fromGenerationTarget(r,a);case n.ContinueStatement:return Lt.fromGenerationTarget(r,a);case n.BreakStatement:return xr.fromGenerationTarget(r,a);default:throw new Error("Invalid entity type: "+r.type)}}const q={seenEntityMaps:new Map,seenEntities:new Set,timestamp:T().toISOString()};class nw{constructor(){f(this,"initialData")}}const g={cascade:!1},sw={APILoad:async(r,...a)=>null},eW={APICreate:async(r,...a)=>r,APIUpdate:async(r,...a)=>r,APIDelete:async(r,...a)=>r,APIClone:async(r,...a)=>{},APILoadVersion:async(r,a,...e)=>null,...sw};class tW{}class iW extends nw{}class rW{}class nW{}class sW{}class nf{}class aW extends nf{}class oW extends nf{}class lW{}class Ir{static initReadsValue(a){if(a.initialData.readsValue&&a.initialData.readsValue.type!==n.GenericReference)a.readsValue=C(a.initialData.readsValue,a.project);else if(a.initialData.readsValue&&a.initialData.readsValue.type===n.GenericReference){const e=mi(a.initialData.readsValue,a.project);e&&(a.readsValue=e)}if(a.readsValue){if(tt.includes(a.readsValue.type)){let e=a.parent;dt.includes(e.type)||(e=e.parent);const t=a.type===n.InputMap&&a.parent.type===n.Loop;t&&(e=a.parent.parent),a.readsValue.setParent(e,null),a.readsValue.initChildren(null),!t&&e.detachedChildren.includes(a)?e.replaceDetachedChild(a,a.readsValue):t||e.subscribeDetachedChild(a.readsValue)}a.readsValue.addValueReader(a,null)}return a.readsValue}static hydrateReadsValue(a){if(a.initialData.readsValue&&a.initialData.readsValue.type!==n.GenericReference)a.readsValue=C(a.initialData.readsValue,a.project);else if(a.initialData.readsValue&&a.initialData.readsValue.type===n.GenericReference){const e=mi(a.initialData.readsValue,a.project);e&&(a.readsValue=e)}if(a.readsValue){if(tt.includes(a.readsValue.type)){let e=a.parent;dt.includes(e.type)||(e=e.parent);const t=a.type===n.InputMap&&a.parent.type===n.Loop;t&&(e=a.parent.parent),a.readsValue.setParent(e,null),!t&&e.detachedChildren.includes(a)?e.replaceDetachedChild(a,a.readsValue):t||e.subscribeDetachedChild(a.readsValue)}a.readsValue.addValueReader(a,null)}return a.readsValue}}class $a{static initWritesValues(a,e){const t=a.initialData.writesValues.reduce((s,l)=>{if(l.type===n.GenericReference||a.writesValues.some(d=>d.id===l.id))return s;const o=C(l,a.project);return o.setValueWriter(a,null),tt.includes(o.type)&&(o.setParent(e,null),o.initChildren(null)),[...s,o]},[]),i=[...a.writesValues];return a.writesValues=p([...i,...t]),a.writesValues}}class dW{}const ae=class ae extends at{constructor(e){super(e);f(this,"initialData");f(this,"id");f(this,"type",n.Project);f(this,"name",null);f(this,"description",null);f(this,"x");f(this,"y");f(this,"entities",[]);f(this,"projects",[]);f(this,"functions",[]);f(this,"events",[]);f(this,"variableDeclarations",[]);f(this,"variableInstances",[]);f(this,"conditions",[]);f(this,"operations",[]);f(this,"functionCalls",[]);f(this,"loops",[]);f(this,"searches",[]);f(this,"primitives",[]);f(this,"builtInBaseEntities",[]);f(this,"operationDeclarations",[]);f(this,"globalEventActionDescriptors",[]);f(this,"loopDeclarations",[]);f(this,"loopDeclarationsBodies",[]);f(this,"conditionDeclarations",[]);f(this,"valueDescriptors",[]);f(this,"dataTypes",[]);f(this,"project");f(this,"instances",{});f(this,"builtInInstances",{});f(this,"deletedInstances",{});f(this,"errors",[]);f(this,"references",[]);f(this,"history",[]);f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"onCloseChangeSetCallback",null);this.initialData=e,this.id=e.id,this.name=e.name,this.description=e.description,this.x=0,this.y=0,this.instances[this.id]=this;try{(!ae.UUID||ae.UUID.isBackup)&&(ae.UUID=xo==null?void 0:xo()),ae.UUID||(ae.UUID={isBackup:!0,uuid:()=>Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15),fromUUID:t=>t})}catch(t){console.error("Error initializing UUID module",t),ae.UUID={isBackup:!0,uuid:()=>Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15),fromUUID:i=>i}}}static injectUUIDModule(e){ae.UUID=e}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[];return s.push(...ut(i)),{errors:s,modifiedData:i}}async closePendingCallbacks(){for(let e=0;e<this.history.length;e++){const t=this.history[e];t.dirty&&await t.closeAsync()}}async onCloseChangeSet(e){this.onCloseChangeSetCallback=e,await this.closePendingCallbacks()}async closeChangeSet(e){if(this.onCloseChangeSetCallback){const t=await this.onCloseChangeSetCallback(e);return t.success&&(e.dirty=!1),t}return{success:!1}}toLatestChangeSet(e,t,i,s=!1,l="here-this"){if(!this.history.length)return new b(this,e,t,i,s,l);const o=this.history[this.history.length-1];return o.open?o:this.addChangeSet(new b(this,e,t,i,s,l))}addChangeSet(e){if(!this.history.length)return this.history.push(e),e;const t=this.history.find(l=>l.id===(e==null?void 0:e.id));if(t)return t;const i=this.history.find(l=>l.open);if(i)throw console.log("previouslyStillOpen: ",i),console.log("new change set: ",e),new Error(`There is already an open change-set with id '${i.id}'.`);const s=this.history.findIndex(l=>T(l.timestamp).isBefore(T(e==null?void 0:e.timestamp)));return s===-1?this.history.push(e):this.history.splice(s,0,e),e}discardChangeSet(e){const t=this.history.findIndex(i=>i.id===(e==null?void 0:e.id));return t!==-1&&this.history.splice(t,1),this}undo(){const e=[],t=[],i=[],s=[];return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}redo(){const e=[],t=[],i=[],s=[];return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}async inject(...e){return await Promise.all(e.map(t=>new Promise(async i=>{await t.init(this),i(null)}))),this}validateGeneratedUpdate(e){return{errors:[],modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],i=[],s=[];return Object.values(this.detachedDependents).forEach(l=>{const o=l.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),i.push(...o.removed),s.push(...o.affected)}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){return this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=ae.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new ae(this);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.entities=this.entities,e.projects=this.projects,e.functions=this.functions,e.events=this.events,e.variableDeclarations=this.variableDeclarations,e.variableInstances=this.variableInstances,e.conditions=this.conditions,e.operations=this.operations,e.functionCalls=this.functionCalls,e.loops=this.loops,e.searches=this.searches,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[I,E]of c.knownVersions)u.set(I,E);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new ae(u)}return this.metaSync(o.toShallowJSON(),null),this.entities=o.entities,this.projects=o.projects,this.functions=o.functions,this.events=o.events,this.variableDeclarations=o.variableDeclarations,this.variableInstances=o.variableInstances,this.conditions=o.conditions,this.operations=o.operations,this.functionCalls=o.functionCalls,this.loops=o.loops,this.searches=o.searches,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=null){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),this.validate(),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e){const t=[],i=[],s=[],l=[];return this.subscribe(),this.subscribeToDependencies(),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get instancesList(){return Object.values(this.instances)}isOperationDeclaration(e){return this.operationDeclarations.includes(e)}isGlobalEventActionDescriptor(e){return this.globalEventActionDescriptors.includes(e)}isLoopDeclaration(e){return this.loopDeclarations.includes(e)}isConditionDeclaration(e){return this.conditionDeclarations.includes(e)}initChildren(e=this.project.addChangeSet(new b(this.project,ae.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.entities=this.initialData.entities.map(t=>{const i=C(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.projects=this.initialData.projects.map(t=>{const i=C(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.variableDeclarations=this.initialData.variableDeclarations.map(t=>{const i=C(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.variableInstances=this.initialData.variableInstances.map(t=>{const i=C(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.conditions=this.initialData.conditions.map(t=>{const i=C(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.operations=this.initialData.operations.map(t=>{const i=C(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.functions=this.initialData.functions.map(t=>{const i=C(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.events=this.initialData.events.map(t=>{const i=C(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.functionCalls=this.initialData.functionCalls.map(t=>{const i=C(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.loops=this.initialData.loops.map(t=>{const i=C(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.searches=this.initialData.searches.map(t=>{const i=C(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.attachOrphanReferences(),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribeInstance(e){return(!this.instances[e.id]||this.instances[e.id]!==e)&&(this.instances[e.id]=e),this}subscribeDeletedInstance(e){return(!this.deletedInstances[e.id]||this.deletedInstances[e.id]!==e)&&(this.deletedInstances[e.id]=e),this}subscribeBuiltInInstance(e){return(!this.builtInInstances[e.id]||this.builtInInstances[e.id]!==e)&&(this.builtInInstances[e.id]=e),this}subscribe(){return this}unsubscribe(){return this}unsubscribeInstance(e){return delete this.instances[e.id],this}unsubscribeDeletedInstance(e){return delete this.deletedInstances[e.id],this}findSubscribedBuiltInInstance(e){return this.builtInInstances[e.id]||null}get(e){return this.instances[e]||this.builtInInstances[e]||null}getDeleted(e){return this.deletedInstances[e]||null}getManaged(e){return this.getBuiltIn(e)?null:this.instances[e]||null}getBuiltIn(e){return this.builtInInstances[e]||null}findSubscribedInstanceFromReference(e){return this.instances[e.entityId]||null}findSubscribedBuiltInInstanceFromReference(e){return this.builtInInstances[e.entityId]||null}metaSync(e,t=this.project.addChangeSet(new b(this.project,ae.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.name=e.name||s.name,this.description=e.description||s.description,this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=g,...t){return await ae.repository.APILoad(this.id,...t),this}async APICreate(e=g,...t){return await ae.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=g,...t){return await ae.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=g,...t){return await ae.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=g,...t){return await ae.repository.APIClone(this.id,...t),this}async APILoadVersion(e=g,t,...i){return await ae.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,ae.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){return{added:[],updated:[],removed:[],affected:[],self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,ae.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){return{added:[],updated:[],removed:[],affected:[],self:this}}getAllBuiltInIds(){const e=new Set;return[...this.primitives.flatMap(t=>t.toFlatIds(e)),...this.builtInBaseEntities.flatMap(t=>t.toFlatIds(e)),...this.operationDeclarations.flatMap(t=>t.toFlatIds(e)),...this.globalEventActionDescriptors.flatMap(t=>t.toFlatIds(e)),...this.loopDeclarations.flatMap(t=>t.toFlatIds(e)),...this.conditionDeclarations.flatMap(t=>t.toFlatIds(e)),...this.valueDescriptors.flatMap(t=>t.toFlatIds(e)),...this.dataTypes.flatMap(t=>t.toFlatIds(e))]}getAllBuiltIn(){const e=new Set;return[...this.primitives.flatMap(t=>t.toFlat(e)),...this.builtInBaseEntities.flatMap(t=>t.toFlat(e)),...this.operationDeclarations.flatMap(t=>t.toFlat(e)),...this.globalEventActionDescriptors.flatMap(t=>t.toFlat(e)),...this.loopDeclarations.flatMap(t=>t.toFlat(e)),...this.conditionDeclarations.flatMap(t=>t.toFlat(e)),...this.valueDescriptors.flatMap(t=>t.toFlat(e)),...this.dataTypes.flatMap(t=>t.toFlat(e))]}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.entities.flatMap(i=>i.toFlat(e)),...this.functions.flatMap(i=>i.toFlat(e)),...this.events.flatMap(i=>i.toFlat(e)),...this.projects.flatMap(i=>i.toFlat(e)),...this.variableDeclarations.flatMap(i=>i.toFlat(e)),...this.variableInstances.flatMap(i=>i.toFlat(e)),...this.conditions.flatMap(i=>i.toFlat(e)),...this.operations.flatMap(i=>i.toFlat(e)),...this.functionCalls.flatMap(i=>i.toFlat(e)),...this.loops.flatMap(i=>i.toFlat(e)),...this.searches.flatMap(i=>i.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.entities.flatMap(i=>i.toFlatIds(e)),...this.functions.flatMap(i=>i.toFlatIds(e)),...this.events.flatMap(i=>i.toFlatIds(e)),...this.projects.flatMap(i=>i.toFlatIds(e)),...this.variableDeclarations.flatMap(i=>i.toFlatIds(e)),...this.variableInstances.flatMap(i=>i.toFlatIds(e)),...this.conditions.flatMap(i=>i.toFlatIds(e)),...this.operations.flatMap(i=>i.toFlatIds(e)),...this.functionCalls.flatMap(i=>i.toFlatIds(e)),...this.loops.flatMap(i=>i.toFlatIds(e)),...this.searches.flatMap(i=>i.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,type:this.type,name:this.name}}toJSON(e=new Set){return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,entities:this.entities.map(t=>t.toJSON(e)),variableDeclarations:this.variableDeclarations.map(t=>t.toJSON(e)),variableInstances:this.variableInstances.map(t=>t.toJSON(e)),conditions:this.conditions.map(t=>t.toJSON(e)),operations:this.operations.map(t=>t.toJSON(e)),loops:this.loops.map(t=>t.toJSON(e)),searches:this.searches.map(t=>t.toJSON(e)),functions:this.functions.map(t=>t.toJSON(e)),events:this.events.map(t=>t.toJSON(e)),projects:this.projects.map(t=>t.toJSON(e)),functionCalls:this.functionCalls.map(t=>t.toJSON(e))})}toJSONClone(e={uuidStrategy:"uuid"}){const t=new Map,i=new Set,s=this.getAllBuiltInIds();return Object.keys(this.instances).forEach(l=>{if(s.includes(l)){t.set(l,l);return}t.set(l,ae.UUID.uuid())}),i.add(this.id),{id:t.get(this.id),version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,entities:this.entities.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),projects:this.projects.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),variableDeclarations:this.variableDeclarations.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),variableInstances:this.variableInstances.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),conditions:this.conditions.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),operations:this.operations.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),functions:this.functions.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),events:this.events.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),functionCalls:this.functionCalls.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),loops:this.loops.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),searches:this.searches.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null}))}}toReference(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+ae.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,entities:this.entities.map(s=>s.toReference(e)),functions:this.functions.map(s=>s.toReference(e)),events:this.events.map(s=>s.toReference(e)),projects:this.projects.map(s=>s.toReference(e)),variableDeclarations:this.variableDeclarations.map(s=>s.toReference(e)),variableInstances:this.variableInstances.map(s=>s.toReference(e)),conditions:this.conditions.map(s=>s.toReference(e)),operations:this.operations.map(s=>s.toReference(e)),functionCalls:this.functionCalls.map(s=>s.toReference(e)),loops:this.loops.map(s=>s.toReference(e)),searches:this.searches.map(s=>s.toReference(e))}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.entities.flatMap(i=>i.toFlatJSON(e)),...this.functions.flatMap(i=>i.toFlatJSON(e)),...this.events.flatMap(i=>i.toFlatJSON(e)),...this.projects.flatMap(i=>i.toFlatJSON(e)),...this.variableDeclarations.flatMap(i=>i.toFlatJSON(e)),...this.variableInstances.flatMap(i=>i.toFlatJSON(e)),...this.conditions.flatMap(i=>i.toFlatJSON(e)),...this.operations.flatMap(i=>i.toFlatJSON(e)),...this.functionCalls.flatMap(i=>i.toFlatJSON(e)),...this.loops.flatMap(i=>i.toFlatJSON(e)),...this.searches.flatMap(i=>i.toFlatJSON(e))])}toGenerationTarget(){return{id:this.id,type:this.type,name:this.name,description:this.description}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[...this.entities.flatMap(i=>i.toFlatGenerationTarget(e)),...this.functions.flatMap(i=>i.toFlatGenerationTarget(e)),...this.events.flatMap(i=>i.toFlatGenerationTarget(e)),...this.projects.flatMap(i=>i.toFlatGenerationTarget(e)),...this.variableDeclarations.flatMap(i=>i.toFlatGenerationTarget(e)),...this.variableInstances.flatMap(i=>i.toFlatGenerationTarget(e)),...this.conditions.flatMap(i=>i.toFlatGenerationTarget(e)),...this.operations.flatMap(i=>i.toFlatGenerationTarget(e)),...this.functionCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.loops.flatMap(i=>i.toFlatGenerationTarget(e)),...this.searches.flatMap(i=>i.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.entities.forEach(e=>e.clearErrors()),this.projects.forEach(e=>e.clearErrors()),this.functions.forEach(e=>e.clearErrors()),this.events.forEach(e=>e.clearErrors()),this.variableDeclarations.forEach(e=>e.clearErrors()),this.variableInstances.forEach(e=>e.clearErrors()),this.conditions.forEach(e=>e.clearErrors()),this.operations.forEach(e=>e.clearErrors()),this.functionCalls.forEach(e=>e.clearErrors()),this.loops.forEach(e=>e.clearErrors()),this.searches.forEach(e=>e.clearErrors()),this}validate(){const e=uZ(),t=this.toJSON();return e.safeParse(t),this.validateChildren(),{success:!0,error:null,data:t}}validateChildren(){this.entities.forEach(e=>e.validate()),this.projects.forEach(e=>e.validate()),this.functions.forEach(e=>e.validate()),this.events.forEach(e=>e.validate()),this.variableDeclarations.forEach(e=>e.validate()),this.variableInstances.forEach(e=>e.validate()),this.conditions.forEach(e=>e.validate()),this.operations.forEach(e=>e.validate()),this.functionCalls.forEach(e=>e.validate()),this.loops.forEach(e=>e.validate()),this.searches.forEach(e=>e.validate())}getErrors(){return[...this.errors,...this.entities.flatMap(t=>t.getErrors()),...this.projects.flatMap(t=>t.getErrors()),...this.functions.flatMap(t=>t.getErrors()),...this.events.flatMap(t=>t.getErrors()),...this.variableDeclarations.flatMap(t=>t.getErrors()),...this.variableInstances.flatMap(t=>t.getErrors()),...this.conditions.flatMap(t=>t.getErrors()),...this.operations.flatMap(t=>t.getErrors()),...this.functionCalls.flatMap(t=>t.getErrors()),...this.loops.flatMap(t=>t.getErrors()),...this.searches.flatMap(t=>t.getErrors())]}getShallowErrors(){return this.errors}clone(){return this}getDefinitionEntity(e){return this.entities.find(t=>t.id===e)||null}addDefinitionEntityFromTransfer(e){const t=C(e,this);return this.addDefinitionEntity(t),t}addDefinitionEntity(e){return this.entities.includes(e)||this.entities.push(e),e}addFunctionDeclarationFromTransfer(e){const t=C(e,this);return this.addFunctionDeclaration(t),t}addFunctionDeclaration(e){return this.functions.includes(e)||this.functions.push(e),e}addFunctionCallFromTransfer(e){const t=C(e,this);return this.addFunctionCall(t),t}addFunctionCall(e){return this.functionCalls.includes(e)||this.functionCalls.push(e),e}addVariableDeclarationFromTransfer(e){const t=C(e,this);return this.addVariableDeclaration(t),t}addVariableDeclaration(e){return this.variableDeclarations.includes(e)||this.variableDeclarations.push(e),e}addVariableInstanceFromTransfer(e){const t=C(e,this);return this.addVariableInstance(t),t}addVariableInstance(e){return this.variableInstances.includes(e)||this.variableInstances.push(e),e}addInstalledProjectFromTransfer(e){const t=C(e,this);return this.addInstalledProject(t),this}addInstalledProject(e){return this.projects.includes(e)||this.projects.push(e),this}addGlobalEventFromTransfer(e){const t=C(e,this);return this.addGlobalEvent(t),this}addGlobalEvent(e){return this.events.includes(e)||this.events.push(e),this}addConditionFromTransfer(e){const t=C(e,this);return this.addCondition(t),this}addCondition(e){return this.conditions.includes(e)||this.conditions.push(e),this}addOperationFromTransfer(e){const t=C(e,this);return this.addOperation(t),this}addOperation(e){return this.operations.includes(e)||this.operations.push(e),this}addLoopFromTransfer(e){const t=C(e,this);return this.addLoop(t),this}addLoop(e){return this.loops.includes(e)||this.loops.push(e),this}addSearchFromTransfer(e){const t=C(e,this);return this.addSearch(t),this}addSearch(e){return this.searches.includes(e)||this.searches.push(e),this}removeDefinitionEntity(e){const t=this.entities.findIndex(i=>i.id===e.id);if(t>-1){const i=this.entities[t];return this.entities.splice(t,1),i}return null}removeFunctionDeclaration(e){const t=this.functions.findIndex(i=>i.id===e.id);if(t>-1){const i=this.functions[t];return this.functions.splice(t,1),i}return null}removeExternalProject(e){const t=this.projects.findIndex(i=>i.id===e.id);if(t>-1){const i=this.projects[t];return this.projects.splice(t,1),i}return null}removeGlobalEvent(e){const t=this.events.findIndex(i=>i.id===e.id);if(t>-1){const i=this.events[t];return this.events.splice(t,1),i}return null}removeTopLevelVariableDeclaration(e){if(e.type!==n.VariableDeclaration)return null;const t=this.variableDeclarations.findIndex(i=>i.id===e.id);if(t>-1){const i=this.variableDeclarations[t];return this.variableDeclarations.splice(t,1),i}return null}getEntryPoints(){return[...this.functions,...this.events,...this.entities.flatMap(t=>t.methods)]}getTerminationStatements(){return[...this.getEntryPoints().reduce((t,i)=>{const s=qe(i);return[...t,...s.filter(l=>l.type===n.ReturnStatement||l.type===n.ContinueStatement||l.type===n.BreakStatement)]},[])]}getFunctionDeclaration(e){return this.functions.find(t=>t.id===e)||null}getConditions(){return[...this.conditions,...this.getEntryPoints().reduce((t,i)=>{const s=qe(i);return[...t,...s.filter(l=>l.type===n.Condition)]},[]),...this.functionCalls.reduce((t,i)=>{const s=qe(i);return[...t,...s.filter(l=>l.type===n.Condition)]},[]),...this.operations.reduce((t,i)=>{const s=qe(i);return[...t,...s.filter(l=>l.type===n.Condition)]},[]),...this.loops.reduce((t,i)=>{const s=qe(i);return[...t,...s.filter(l=>l.type===n.Condition)]},[]),...this.searches.reduce((t,i)=>{const s=qe(i);return[...t,...s.filter(l=>l.type===n.Condition)]},[])]}getOperations(){return[...this.operations,...this.getEntryPoints().reduce((t,i)=>{const s=qe(i);return[...t,...s.filter(l=>l.type===n.Operation)]},[]),...this.functionCalls.reduce((t,i)=>{const s=qe(i);return[...t,...s.filter(l=>l.type===n.Operation)]},[]),...this.conditions.reduce((t,i)=>{const s=qe(i);return[...t,...s.filter(l=>l.type===n.Operation)]},[]),...this.loops.reduce((t,i)=>{const s=qe(i);return[...t,...s.filter(l=>l.type===n.Operation)]},[]),...this.searches.reduce((t,i)=>{const s=qe(i);return[...t,...s.filter(l=>l.type===n.Operation)]},[])]}getFunctionCalls(){return[...this.functionCalls,...this.getEntryPoints().reduce((t,i)=>{const s=qe(i);return[...t,...s.filter(l=>l.type===n.FunctionCall)]},[]),...this.conditions.reduce((t,i)=>{const s=qe(i);return[...t,...s.filter(l=>l.type===n.FunctionCall)]},[]),...this.operations.reduce((t,i)=>{const s=qe(i);return[...t,...s.filter(l=>l.type===n.FunctionCall)]},[]),...this.loops.reduce((t,i)=>{const s=qe(i);return[...t,...s.filter(l=>l.type===n.FunctionCall)]},[]),...this.searches.reduce((t,i)=>{const s=qe(i);return[...t,...s.filter(l=>l.type===n.FunctionCall)]},[])]}getVariables(){return[...this.variableDeclarations,...this.getEntryPoints().reduce((t,i)=>{const s=Ye(i);return[...t,...s]},[]),...this.functionCalls.reduce((t,i)=>{const s=Ye(i);return[...t,...s]},[]),...this.conditions.reduce((t,i)=>{const s=Ye(i);return[...t,...s]},[]),...this.operations.reduce((t,i)=>{const s=Ye(i);return[...t,...s]},[]),...this.loops.reduce((t,i)=>{const s=Ye(i);return[...t,...s]},[]),...this.searches.reduce((t,i)=>{const s=Ye(i);return[...t,...s]},[])]}getVariableInstances(){return[...this.variableInstances,...this.getEntryPoints().reduce((t,i)=>{const l=Ye(i).filter(o=>o.type===n.VariableInstance);return[...t,...l]},[]),...this.functionCalls.reduce((t,i)=>{const l=Ye(i).filter(o=>o.type===n.VariableInstance);return[...t,...l]},[]),...this.conditions.reduce((t,i)=>{const l=Ye(i).filter(o=>o.type===n.VariableInstance);return[...t,...l]},[]),...this.operations.reduce((t,i)=>{const l=Ye(i).filter(o=>o.type===n.VariableInstance);return[...t,...l]},[]),...this.loops.reduce((t,i)=>{const l=Ye(i).filter(o=>o.type===n.VariableInstance);return[...t,...l]},[]),...this.searches.reduce((t,i)=>{const l=Ye(i).filter(o=>o.type===n.VariableInstance);return[...t,...l]},[])]}getVariableDeclarations(){return p([...this.variableDeclarations,...this.getEntryPoints().reduce((t,i)=>{const l=Ye(i).filter(o=>o.type===n.VariableDeclaration);return[...t,...l]},[]),...this.functionCalls.reduce((t,i)=>{const l=Ye(i).filter(o=>o.type===n.VariableDeclaration);return[...t,...l]},[]),...this.conditions.reduce((t,i)=>{const l=Ye(i).filter(o=>o.type===n.VariableDeclaration);return[...t,...l]},[]),...this.operations.reduce((t,i)=>{const l=Ye(i).filter(o=>o.type===n.VariableDeclaration);return[...t,...l]},[]),...this.loops.reduce((t,i)=>{const l=Ye(i).filter(o=>o.type===n.VariableDeclaration);return[...t,...l]},[]),...this.searches.reduce((t,i)=>{const l=Ye(i).filter(o=>o.type===n.VariableDeclaration);return[...t,...l]},[])])}getLoops(){return[...this.loops,...this.getEntryPoints().reduce((t,i)=>{const s=qe(i);return[...t,...s.filter(l=>l.type===n.Loop)]},[]),...this.functionCalls.reduce((t,i)=>{const s=qe(i);return[...t,...s.filter(l=>l.type===n.Loop)]},[]),...this.conditions.reduce((t,i)=>{const s=qe(i);return[...t,...s.filter(l=>l.type===n.Loop)]},[]),...this.operations.reduce((t,i)=>{const s=qe(i);return[...t,...s.filter(l=>l.type===n.Loop)]},[]),...this.searches.reduce((t,i)=>{const s=qe(i);return[...t,...s.filter(l=>l.type===n.Loop)]},[])]}getSearches(){return[...this.searches,...this.getEntryPoints().reduce((t,i)=>{const s=qe(i);return[...t,...s.filter(l=>l.type===n.Search)]},[]),...this.functionCalls.reduce((t,i)=>{const s=qe(i);return[...t,...s.filter(l=>l.type===n.Search)]},[]),...this.conditions.reduce((t,i)=>{const s=qe(i);return[...t,...s.filter(l=>l.type===n.Search)]},[]),...this.operations.reduce((t,i)=>{const s=qe(i);return[...t,...s.filter(l=>l.type===n.Search)]},[]),...this.loops.reduce((t,i)=>{const s=qe(i);return[...t,...s.filter(l=>l.type===n.Search)]},[])]}attachOrphanReferences(){const e=this.getVariableInstances(),t=this.getVariableDeclarations();return e.forEach(i=>{if(!i.declaration){const s=i.initialData,l=s.declaration.entityId||s.declaration.id,o=t.find(d=>d.id===l);o&&i.setDeclaration(o)}}),this}getBuiltInPersistedEntity(){return this.builtInBaseEntities.find(e=>e.name===z.PERSISTED_ENTITY)||null}};f(ae,"sessionAuthor","1"),f(ae,"UUID",{isBackup:!0,uuid:()=>Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15),fromUUID:e=>e}),f(ae,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(ae,"type",n.Project),f(ae,"USER_MANAGED_PARENT_TYPES",[]),f(ae,"PARENT_TYPES",[...ae.USER_MANAGED_PARENT_TYPES]),f(ae,"MUTABLE_BASE_PROPERTIES",["name","description"]),f(ae,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(ae,"BASE_PROPERTIES",[...ae.MUTABLE_BASE_PROPERTIES,...ae.INMUTABLE_BASE_PROPERTIES]),f(ae,"MUTABLE_META_PROPERTIES",[...ae.MUTABLE_BASE_PROPERTIES,"x","y"]),f(ae,"INMUTABLE_META_PROPERTIES",[...ae.INMUTABLE_BASE_PROPERTIES]),f(ae,"META_PROPERTIES",[...ae.MUTABLE_META_PROPERTIES,...ae.INMUTABLE_META_PROPERTIES]),f(ae,"MUTABLE_UPSTREAM_PROPERTIES",[]),f(ae,"INMUTABLE_UPSTREAM_PROPERTIES",["primitives","builtInBaseEntities","operationDeclarations","globalEventActionDescriptors","loopDeclarations","builtInInstances"]),f(ae,"UPSTREAM_PROPERTIES",[...ae.MUTABLE_UPSTREAM_PROPERTIES,...ae.INMUTABLE_UPSTREAM_PROPERTIES]),f(ae,"MUTABLE_DOWNSTREAM_PROPERTIES",["entities","projects","functions","events","variableDeclarations","variableInstances","conditions","operations","functionCalls","loops","searches"]),f(ae,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(ae,"DOWNSTREAM_PROPERTIES",[...ae.MUTABLE_DOWNSTREAM_PROPERTIES,...ae.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(ae,"PROPERTIES",[...ae.META_PROPERTIES,...ae.UPSTREAM_PROPERTIES,...ae.DOWNSTREAM_PROPERTIES]);let m=ae;var aw=(r=>(r.PersistChangeSet="persist-change-set",r.CreateSingle="create-single",r.CreateBulk="create-bulk",r.CreateSingleNested="create-single-nested",r.CreateBulkNested="create-bulk-nested",r.Update="update",r.Clone="clone",r.Delete="delete",r.Load="load",r.LoadNested="load-nested",r.LoadVersion="load-version",r))(aw||{});class ow extends Je{constructor(e){super(Oi,e);f(this,"id",Xe.Parallel);f(this,"name",Xe.Parallel);f(this,"description","Execute a list of actions one after the other");f(this,"version","1");f(this,"autoexecutable",!0);f(this,"initialData",Oi);f(this,"type",n.ActionDescriptor);f(this,"inputs",[]);f(this,"outputs",[]);f(this,"error",null);f(this,"project");this.project=e,this.inputs=Oi.inputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(null),i}),this.outputs=Oi.outputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(null),i}),this.error=Oi.error?C(Oi.error,this.project):null}}class lw extends Je{constructor(e){super(qt,e);f(this,"id",qt.id);f(this,"name",qt.name);f(this,"description",qt.description);f(this,"version",qt.version);f(this,"autoexecutable",!1);f(this,"initialData",qt);f(this,"type",n.ActionDescriptor);f(this,"inputs",[]);f(this,"outputs",[]);f(this,"error",null);f(this,"project");this.project=e,this.inputs=qt.inputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(null),i}),this.outputs=qt.outputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(null),i}),this.error=qt.error?C(qt.error,this.project):null}}class dw extends Je{constructor(e){super(nr,e);f(this,"id",Xe.Sequential);f(this,"name",Xe.Sequential);f(this,"description","Execute a list of actions one after the other");f(this,"version","1");f(this,"autoexecutable",!0);f(this,"initialData",nr);f(this,"type",n.ActionDescriptor);f(this,"inputs",[]);f(this,"outputs",[]);f(this,"error",null);f(this,"project");this.project=e,this.inputs=nr.inputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(null),i}),this.outputs=nr.outputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(null),i}),this.error=nr.error?C(nr.error,this.project):null}}class uW extends Je{constructor(a){super(Bs,a)}}class pW extends Je{constructor(a){super(on,a)}}class cW extends Je{constructor(e){super(ln,e);f(this,"autoexecutable",!0)}getEntityToMatchInputMap(e){return e.inputs.find(t=>{var i;return((i=t.declaration)==null?void 0:i.id)===k.operation[Qe.Validate].inputs.entityToMatch.id})||null}getDataToValidateInputMap(e){return e.inputs.find(t=>{var i;return((i=t.declaration)==null?void 0:i.id)===k.operation[Qe.Validate].inputs.dataToValidate.id})||null}getOutputDataOutputMap(e){return e.outputs.find(t=>{var i;return((i=t.declaration)==null?void 0:i.id)===k.operation[Qe.Validate].outputs.outputEntity.id})||null}getEntityToMatch(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"get-entity-to-match-validate-data"))){let i=null;if(e.readsValue){const l=e.readsValue.getDataType(t);l&&l.entity&&l.entity.type===n.DefinitionEntity&&(i=l.entity)}const s=e.getDefaultValue();return!i&&s&&s.valueAsTypeSingle&&!Array.isArray(s.valueAsTypeSingle)&&s.valueAsTypeSingle.type===n.DefinitionEntity&&(i=s.valueAsTypeSingle),i}syncOperationInstance(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-operation-instance-validate-data"))){const i=[],s=[],l=[],o=[],d=this.getEntityToMatchInputMap(e);if(d){const{added:c,updated:I,removed:E,affected:O}=this.syncEntityToMatchInputMapDataType(d,t);i.push(...I),s.push(...c),l.push(...E),o.push(...O)}const u=this.getDataToValidateInputMap(e);if(u){const{added:c,updated:I,removed:E,affected:O}=this.syncDataToValidateInputMapDataType(u,t);i.push(...I),s.push(...c),l.push(...E),o.push(...O)}const y=this.getOutputDataOutputMap(e);if(y){const{added:c,updated:I,removed:E,affected:O}=this.syncOutputDataOutputMapDataType(y,t);i.push(...I),s.push(...c),l.push(...E),o.push(...O)}return t==null||t.attemptAutoclose("sync-operation-instance-validate-data",this.id),{updated:p(i),added:p(s),removed:p(l),affected:p(o),self:e}}syncEntityToMatchInputMapDataType(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-entity-to-match-input-map-data-type"))){var u,y,c;const i=[],s=[],l=[],o=[];if(((u=e.declaration)==null?void 0:u.id)!==k.operation[Qe.Validate].inputs.entityToMatch.id)return t==null||t.attemptAutoclose("sync-entity-to-match-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!e.dataType){const I={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||new Date().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.DataType,parentRelationType:null,options:null,implementationChooseOne:!1,isList:!1,andChildrenGroup:null,orChildrenGroup:null,asType:!0,entity:null,like:!0,inferred:!0,parent:e.toReference()},E=C(I,e.project);E.setParent(e,t),E.initChildren(t),t==null||t.add(E,A.Added),i.push(E),e.setDataType(E)}(y=e.dataType)==null||y.metaSync({inferred:!0,like:!1,asType:!0},t);const d=this.getEntityToMatch(e,t);return(c=e.dataType)==null||c.setEntity(d),e.dataType&&s.push(e.dataType),t==null||t.attemptAutoclose("sync-entity-to-match-input-map-data-type",this.id),{updated:p(s),added:p(i),removed:p(l),affected:p(o),self:e.dataType}}syncDataToValidateInputMapDataType(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-data-to-validate-input-map-data-type"))){var c,I,E;const i=[],s=[],l=[],o=[];if(((c=e.declaration)==null?void 0:c.id)!==k.operation[Qe.Validate].inputs.dataToValidate.id)return t==null||t.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};const d=this.getEntityToMatchInputMap(e.parent);if(!d)return t==null||t.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!this.getEntityToMatch(d,t))return t==null||t.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!e.dataType){const O={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||new Date().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.DataType,parentRelationType:null,options:null,implementationChooseOne:!1,isList:!1,andChildrenGroup:null,orChildrenGroup:null,asType:!1,entity:null,like:!0,inferred:!0,parent:e.toReference()},P=C(O,e.project);P.setParent(e,t),P.initChildren(t),t==null||t.add(P,A.Added),i.push(P),e.setDataType(P)}(I=e.dataType)==null||I.metaSync({inferred:!0,like:!0,asType:!1},t);const y=this.getEntityToMatch(d,t);return(E=e.dataType)==null||E.setEntity(y),e.dataType&&s.push(e.dataType),t==null||t.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:p(s),added:p(i),removed:p(l),affected:p(o),self:e.dataType}}syncOutputDataOutputMapDataType(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-output-data-output-map-data-type"))){var c,I,E;const i=[],s=[],l=[],o=[];if(((c=e.declaration)==null?void 0:c.id)!==k.operation[Qe.Validate].outputs.outputEntity.id)return t==null||t.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};const d=this.getEntityToMatchInputMap(e.parent);if(!d)return t==null||t.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!this.getEntityToMatch(d,t))return t==null||t.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!e.dataType){const O={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||new Date().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.DataType,parentRelationType:null,options:null,implementationChooseOne:!1,isList:!1,andChildrenGroup:null,orChildrenGroup:null,asType:!1,entity:null,like:!0,inferred:!0,parent:e.toReference()},P=C(O,e.project);P.setParent(e,t),P.initChildren(t),t==null||t.add(P,A.Added),i.push(P),e.setDataType(P)}(I=e.dataType)==null||I.metaSync({inferred:!0,like:!0,asType:!1},t);const y=this.getEntityToMatch(d,t);return(E=e.dataType)==null||E.setEntity(y),e.dataType&&s.push(e.dataType),t==null||t.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:p(s),added:p(i),removed:p(l),affected:p(o),self:e.dataType}}inferInputMapDataType(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"infer-input-map-data-type-validate-data"))){var i,s;if(((i=e.declaration)==null?void 0:i.id)===k.operation[Qe.Validate].inputs.entityToMatch.id){const{added:l,updated:o,removed:d,affected:u}=this.syncEntityToMatchInputMapDataType(e,t);return t==null||t.attemptAutoclose("infer-input-map-data-type-validate-data",this.id),{updated:p(o),added:p(l),removed:p(d),affected:p(u),self:e.dataType}}else if(((s=e.declaration)==null?void 0:s.id)===k.operation[Qe.Validate].inputs.dataToValidate.id){const{added:l,updated:o,removed:d,affected:u}=this.syncDataToValidateInputMapDataType(e,t);return t==null||t.attemptAutoclose("infer-input-map-data-type",this.id),{updated:p(o),added:p(l),removed:p(d),affected:p(u),self:e.dataType}}return{updated:[],added:[],removed:[],affected:[],self:null}}inferOutputMapDataType(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"infer-output-map-data-type-validate-data"))){var i;if(((i=e.declaration)==null?void 0:i.id)===k.operation[Qe.Validate].outputs.outputEntity.id){const{added:s,updated:l,removed:o,affected:d}=this.syncOutputDataOutputMapDataType(e,t);return t==null||t.attemptAutoclose("infer-output-map-data-type-validate-data",this.id),{updated:p(l),added:p(s),removed:p(o),affected:p(d),self:e.dataType}}return{updated:[],added:[],removed:[],affected:[],self:null}}}class fW extends Je{constructor(a){super(Id,a)}}class yW extends Je{constructor(a){super(Ad,a)}}class hW extends Je{constructor(a){super(bd,a)}}class mW extends Je{constructor(a){super(Ya,a)}}class vW extends Je{constructor(a){super(Ja,a)}}class TW extends Je{constructor(a){super(Vs,a)}}function IW(r){const a=[new dw(r),new ow(r),new lw(r),new uW(r),new pW(r),new cW(r),new mW(r),new fW(r),new hW(r),new yW(r),new vW(r),new TW(r),new Je(Td,r),new Je(vd,r)];return a.forEach(e=>{e.initChildren(null),r.subscribeBuiltInInstance(e)}),r.operationDeclarations=a,a}class uw extends Ki{constructor(e){super(Ct,e);f(this,"initialData");f(this,"id",z.PERSISTED_ENTITY);f(this,"version","1");f(this,"name",z.PERSISTED_ENTITY);f(this,"description",Ct.description);f(this,"type",n.BuiltInBaseEntity);f(this,"abstract",Ct.abstract);f(this,"static",Ct.static);f(this,"properties",[]);f(this,"methods",[]);f(this,"abstractMethods",[]);f(this,"extends",[]);f(this,"errors",[]);f(this,"project");this.initialData=Ct,this.project=e,this.id=Ct.id,this.version=Ct.version,this.name=Ct.name,this.static=Ct.static,this.abstract=Ct.abstract,this.properties=this.initialData.properties.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(null),i}),this.methods=this.initialData.methods.map(t=>{const i=C(t,this.project);return i.parent=this,i}),this.abstractMethods=this.initialData.abstractMethods.map(t=>{const i=C(t,this.project);return i.parent=this,i}),this.extends=this.initialData.extends.map(t=>C(t,this.project))}}function EW(r){const a=[new uw(r),new Ki(js,r),new Ki(ji,r),new Ki(fo,r)];return a.forEach(e=>{r.subscribeBuiltInInstance(e)}),r.builtInBaseEntities=a,a}function AW(r){const a=[new Qt(se,r),new Qt(er,r),new Qt(ve,r),new Qt(pd,r),new Qt(Ot,r),new Qt(tr,r),new Qt(Li,r),new Qt(ir,r),new Qt(Fn,r)];return a.forEach(e=>{r.subscribeBuiltInInstance(e)}),r.primitives=a,a}function bW(r){const a=[new Je(ho,r)];return a.forEach(e=>{e.initChildren(null),r.subscribeBuiltInInstance(e)}),r.globalEventActionDescriptors=a,a}function RW(r){const a=[new Je(Ls,r),new Je(Ar,r),new Je(Ms,r),new Je(Sn,r),new Je(Zn,r),new Je(ro,r)];a.forEach(t=>{t.initChildren(null),r.subscribeBuiltInInstance(t)}),r.loopDeclarations=a;const e=[new Je(oo,r),new Je(Ns,r),new Je(so,r),new Je(Ud,r),new Je(jd,r),new Je(no,r)];return e.forEach(t=>{t.initChildren(null),r.subscribeBuiltInInstance(t)}),r.loopDeclarationsBodies=e,a}function DW(r){const a=[new mr(mo,r)];return a.forEach(e=>{e.initChildren(null),r.subscribeBuiltInInstance(e)}),r.valueDescriptors=a,a}function OW(r){const a=[new Je(fn,r),new Je(Yn,r)];return a.forEach(e=>{e.initChildren(null),r.subscribeBuiltInInstance(e)}),r.conditionDeclarations=a,a}const Un={},nd={},Ga={empty:!1,enrich:!0,mock:!1,ignoreCache:!1,onFetch:async()=>null,manuallyInit:!1};function pw(r,{enrich:a}={enrich:!0}){const e=r.project,t=r.record,i=new ql(e),s=new Set;t[e.id]=e,s.add(e.id);const l=T().toISOString();Object.values(t).forEach(u=>{!u||i.allBuiltInEntityIds.includes(u.id)||s.add(u.id)}),i.order=Array.from(s),i.flatRecord=t,i.orderEntities();const o=sd(r.project);o.instances[e.id]=o;const d=a?o.addChangeSet(new b(o,"",l,o)):null;return i.visit(u=>{if(u.id===o.id)return;const y=C(u,o);y.hydrateAncestors(),y.addSelfToProject(null)}),a?(i.visit(u=>{const y=o.get(u.id);y&&y.afterAllChildrenInitialized(d)}),o.afterAllChildrenInitialized(d)):ad(o,l).forEach(y=>{y.remove({ignoreUpstream:!0},null)}),o.instancesList.forEach(u=>{u.previousVersion=null}),d==null||d.close(),o}async function PW(r,a=Ga){const e={...Ga,...a};if(e.empty)return{data:{project:{id:r.id,type:n.Project,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:null,description:null,projects:[],entities:[],operations:[],functions:[],variableDeclarations:[],variableInstances:[],functionCalls:[],conditions:[],loops:[],searches:[],events:[]},record:{}}};if(e.mock){const i={...lp};return i.id=r.id,{data:{project:i,record:{}}}}return console.log("Fetching project from external API"),new Promise(async i=>{if(e.onFetch){const s=await e.onFetch(r.id);if(s){i({data:s});return}}else i({data:null})})}function sd(r){const a=new m(r);return AW(a),EW(a),IW(a),bW(a),RW(a),DW(a),OW(a),Array.from(new Set([...a.getAllBuiltInIds(),..._i()])).forEach(t=>{if(!a.builtInInstances[t]&&a.instances[t])a.builtInInstances[t]=a.instances[t],delete a.instances[t];else if(!a.builtInInstances[t])throw new Error(`Built in entity was not properly initialized: ${t}`)}),a}function ad(r,a){return r.instancesList.filter(t=>T(t.createdAt).isAfter(T(a)||!!t.previousVersion))}function wW(r,{enrich:a}={enrich:!0}){const e=new Map,t=Array.from(new Set([...r.getAllBuiltInIds(),..._i()]));Object.keys(r.instances).forEach(u=>{if(t.includes(u)){e.set(u,u);return}const y=r.get(u);if(!id(y,{...r.instances,...r.builtInInstances}).every(E=>!t.includes(E))){e.set(u,u);return}e.set(u,m.UUID.uuid())});const i=T().toISOString(),s=r.toShallowJSON({seenEntityMaps:e});s.previousVersion=null,s.createdAt=i,s.version=m.UUID.uuid();const l=sd(s),o=a?l.addChangeSet(new b(l,"",i,l)):null,d=new ql(r);return d.visit(u=>{const y=u.toShallowJSON({seenEntityMaps:e});u.type===n.ValueDescriptor&&u.name==="Iteration result"&&(console.log("Og entity shallow copy: ",y),console.log("Og entity full: ",u)),y.previousVersion=null,y.createdAt=i,y.version=m.UUID.uuid();const c=C(y,l);c.hydrateAncestors(),c.addSelfToProject(o),o==null||o.add(c,A.Added)}),a?(d.visit(u=>{const y=l.get(e.get(u.id));y&&y.afterAllChildrenInitialized(o)}),l.afterAllChildrenInitialized(o)):ad(l,i).forEach(y=>{y.remove({ignoreUpstream:!0},null)}),l.instancesList.forEach(u=>{u.previousVersion=null}),o==null||o.close(),l}function cw(r,{enrich:a}={enrich:!0}){const e=sd(r),t=T().toISOString(),i=a?e.addChangeSet(new b(e,"",t,e)):null;i&&(i.type=Pc.Automatic);const s=new ql(r);return s.visit(l=>{const o=C(l,e);o.hydrateAncestors(),o.addSelfToProject(i)}),a?(s.visit(l=>{const o=e.get(l.id);o&&o.afterAllChildrenInitialized(i)}),e.afterAllChildrenInitialized(i)):ad(e,t).forEach(o=>{o.remove({ignoreUpstream:!0},null)}),i==null||i.close(),e}async function CW(r,a=Ga){const e={...Ga,...a};if(r.id&&Un[r.id]&&!e.ignoreCache)return Un[r.id];if(r.id&&nd[r.id]&&!e.ignoreCache)return await nd[r.id],Un[r.id];const t=PW(r,e);r.id&&(nd[r.id]=t);const i=await t;if(i.data){let s;return e.mock?s=cw(lp,{enrich:!!e.enrich}):i.data instanceof m?s=i.data:s=pw(i.data,{enrich:!!e.enrich}),Un[r.id]=s,r.id&&delete nd[r.id],s}return null}function VW(r){return Un[r.id]&&delete Un[r.id],null}const BW="test_primitive_entities_export";h.AI_VALUE_CONNECTION_GENERATION_ACTION_EXPLANATION=Gc,h.ALL_BUILT_IN_BASE_ENTITIES=xI,h.ALL_BUILT_IN_CONDITION_ENTITIES=tE,h.ALL_BUILT_IN_GLOBAL_EVENT_ENTITIES=rE,h.ALL_BUILT_IN_LOOP_BODY_ENTITIES=vT,h.ALL_BUILT_IN_LOOP_ENTITIES=mT,h.ALL_BUILT_IN_OPERATION_ENTITIES=C0,h.ALL_BUILT_IN_PRIMITIVE_ENTITIES=mf,h.ALL_BUILT_IN_TOP_LEVEL_ENTITIES=oE,h.ALL_BUILT_IN_VALUE_DESCRIPTORS=aE,h.ActionDescriptorState=Je,h.ActionInputMapState=Fq,h.ActionOutputMapState=Sq,h.AppendToListOperationInputIds=Dh,h.AppendToListOperationOutputIds=Oh,h.ArgumentDeclarationDependencyField=M1,h.ArgumentDeclarationState=Yr,h.BREAK_AND_CONTINUE_STATEMENTS_RETURN_DECLARATIONS_EXPLANATION=Uc,h.BUILT_IN_BASE_ENTITY_IDS=k,h.BUILT_IN_ENTITY_TYPES=Ti,h.BaseCanvasDraggableState=rW,h.BaseEntityNames=z,h.BaseState=iW,h.BaseValueDescriptorIds=qa,h.BreakStatementDependencyField=Vc,h.BreakStatementState=xr,h.BuiltInBaseEntityState=Ki,h.CACHED_PROJECTS_BY_ID=Un,h.CALLABLE_ENTITIES_EXPLANATION=Kq,h.CALLABLE_TYPES=Mi,h.CALLER_ENTITIES_EXPLANATION=G1,h.CALLER_TYPES=Ni,h.CALLS_UPDATE_EXPLANATION=Xr,h.COMPARISON_CONDITIONS=QI,h.CONDITIONS=eE,h.CUSTOM_ENTITY_OPERATIONS=Jm,h.CallableEntityClass=sW,h.CallerEntityClass=nf,h.ChangeSet=b,h.ChangeSetChangeCaptureType=Pc,h.ChangeSetEntityChangeType=A,h.ChildEntityState=nW,h.ComparisonOperatorTypes=yt,h.ConditionDependencyField=v1,h.ConditionState=Sr,h.ContinueStatementDependencyField=wc,h.ContinueStatementState=Lt,h.CreateNewInputIds=Em,h.CreateNewOutputIds=Am,h.DRAGGABLE_CALLABLE_TYPES=ud,h.DRAGGABLE_CALLER_TYPES=lf,h.DRAGGABLE_ELEMENT_TYPES=Za,h.DRAGGABLE_EXECUTABLE_TYPES=vw,h.DRAGGABLE_PASS_THROUGH_CALLABLE_TYPES=Sa,h.DRAGGABLE_PASS_THROUGH_CALLABLE_TYPES_WITH_OUTPUTS=dd,h.DataTypeCompatibilityTypes=bi,h.DataTypeDependencyField=Cc,h.DataTypeParentChildRelation=Dt,h.DataTypeState=$r,h.DefinitionEntityDependencyField=rd,h.DefinitionEntityState=nn,h.EDITABLE_PERSISTANCE_REPOSITORY_DEFAULTS=eW,h.ENTITIES_WITH_VALLUES_EXPLANATION=Fl,h.ENTITY_PERSISTANCE_OPTIONS_DEFAULTS=g,h.ENTITY_RECUSION_OPTIONS_DEFAULTS=q,h.ENTITY_TYPES=Tw,h.ENTITY_WITH_DECLARATION_TYPES=hw,h.ENTITY_WITH_LOGIC_SCOPE_TYPES=dt,h.ENTITY_WITH_NAMES_TYPES=df,h.ENTITY_WITH_PARENT_TYPES=fw,h.ENTITY_WITH_USER_MANAGED_DECLARATION_TYPES=af,h.ENTITY_WITH_USER_MANAGED_SINGLE_IMPLEMENTS_TYPES=yw,h.ENTITY_WITH_VALUE_TYPES=sf,h.ENTRY_POINT_ENTITIES_EXPLANATION=Ba,h.ENTRY_POINT_TYPES=lt,h.EVENT_TYPES=Gn,h.EXECUTABLE_TYPES=mw,h.EXECUTION_OPERATIONS=Im,h.EntityAction=aw,h.EntityError=it,h.EntityErrorSeverity=D,h.EntityGenerationError=w,h.EntityGenerationErrorCode=R,h.EntityInstanceErrorCode=F,h.EntityOperations=Qe,h.EntityType=n,h.EntityWithLogicScopeClass=dW,h.EntityWithValueClass=lW,h.EntryPointEntityClass=aW,h.ExecutionOperations=Xe,h.ExecutionTerminationType=y1,h.FunctionCallDependencyField=H1,h.FunctionCallState=en,h.FunctionDeclarationDependencyField=o1,h.FunctionDeclarationState=jr,h.GET_PROJECT_OPTIONS_DEFAULTS=Ga,h.GLOBAL_EVENT_DECLARATIONS=iE,h.GetLastInListOperationInputIds=ch,h.GetLastInListOperationOutputIds=fh,h.GlobalEventNames=Qi,h.GlobalEventState=Fr,h.HTTPOperations=_t,h.HTTP_OPERATIONS=P0,h.InputMapDependencyField=C1,h.InputMapState=Wi,h.InstalledProjectState=Wr,h.InternalCallDependencyField=P1,h.InternalCallState=zr,h.JoinListOperationInputIds=My,h.JoinListOperationOutputIds=Ny,h.LIST_OPERATIONS=$h,h.ListOperations=he,h.LiteralValueDependencyField=L1,h.LiteralValueState=Hr,h.LoopDependencyField=h1,h.LoopState=kr,h.LoopTypes=Q,h.NON_INTERACTIVE_BASE_ENTITIES_EXPLANATION=Qr,h.NUMBER_OPERATIONS=Jf,h.NumberOperations=et,h.OPERATION_DECLARATIONS=w0,h.OperationDependencyField=u1,h.OperationState=Gr,h.OutputMapDependencyField=B1,h.OutputMapParentChildRelation=$n,h.OutputMapState=zi,h.PARENT_AUTO_CALCULATION_FROM_CALLER_EXPLANATION=xl,h.PASS_THROUGH_CALLABLE_ENTITIES_EXPLANATION=Kr,h.PASS_THROUGH_CALLABLE_TYPES=ot,h.PASS_THROUGH_CALLABLE_TYPES_WITH_OUTPUTS=of,h.PROPERTY_NOT_VALUE_READER_WRITTER_EXPLANATION=$c,h.ParallelExecutionOperation=ow,h.PassThroughCallableEntityClass=oW,h.PersistedEntity=uw,h.PersistedEntityMethods=di,h.PrimitiveEntityState=Qt,h.PrimitiveTypes=L,h.ProjectState=m,h.PropertyDependencyField=t1,h.PropertyState=Ur,h.READ_ONLY_ENTITY_PERSISTANCE_REPOSITORY=sw,h.RETURN_STATEMENT_RETURN_DECLARATIONS_EXPLANATION=Xq,h.ReturnDeclarationDependencyField=r1,h.ReturnDeclarationState=ai,h.ReturnStatementDependencyField=gl,h.ReturnStatementState=gr,h.STANDALONE_CONDITIONS=ZI,h.STRING_OPERATIONS=_y,h.ScopeCompatibilityType=td,h.SearchDependencyField=b1,h.SearchState=Jr,h.SequentialExecutionOperation=dw,h.SequentialExecutionOperationInputIds=am,h.SequentialExecutionOperationOutputIds=om,h.SharedEntityErrorCode=j,h.SharedStateFunctionality=nw,h.SplitListOperationInputIds=zy,h.SplitListOperationOutputIds=Yy,h.StandaloneOperatorTypes=vi,h.StringOperations=Ee,h.TERMINATION_TYPES=st,h.Traverser=ql,h.USER_MANAGED_ENTITY_TYPES=uf,h.UserManagedEntityStateTemplate=tW,h.VALUE_READING_ENTITIES_EXPLANATION=jc,h.VALUE_READING_TYPES=Er,h.VALUE_WRITING_ENTITIES_EXPLANATION=F1,h.VALUE_WRITING_TYPES=Tt,h.VARIABLE_DATA_TYPE_INFERRANCE_EXPLANATION=gc,h.VARIABLE_TYPES=tt,h.ValueAutogenerationType=vt,h.ValueDescriptorDependencyField=g1,h.ValueDescriptorParentChildRelation=N,h.ValueDescriptorState=mr,h.ValueReadingEntityClass=Ir,h.ValueWritingEntityClass=$a,h.VariableDeclarationDependencyField=E1,h.VariableDeclarationState=qr,h.VariableInputMapState=Gq,h.VariableInstanceDependencyField=_c,h.VariableInstanceState=Zr,h.VariableOutputMapState=kq,h.WaitOperation=lw,h.WaitOperationInputIds=Qh,h.WaitOperationOutputIds=em,h.actionDescriptorValidation=_q,h.appendToListOperation=Ya,h.appendToListOperationElementToAppendArgument=Dd,h.appendToListOperationElementToAppendArgumentParentRef=Nh,h.appendToListOperationElementToAppendArgumentRef=Ch,h.appendToListOperationError=jh,h.appendToListOperationErrorParentRef=gh,h.appendToListOperationListArgument=Rd,h.appendToListOperationListArgumentParentRef=Mh,h.appendToListOperationListArgumentRef=Ph,h.appendToListOperationListDataType=wh,h.appendToListOperationResultListDataType=_h,h.appendToListOperationResultListReturn=Uh,h.appendToListOperationResultListReturnParentRef=Lh,h.appendToListOperationResultListReturnRef=Bh,h.appendToListOperationSecondListDataType=Vh,h.applyNewScope=K,h.argumentDeclarationValidation=Zq,h.asGenerationActionExample=Yi,h.booleanPrototype=er,h.breakStatementValidation=Cq,h.calculateNewParentBasedOnCallers=qc,h.capitalizeFirstLetter=xt,h.changeSetJSONRecordToUniqueIds=mq,h.checkAreDataTypesCompatible=Ri,h.checkAreDefinitionEntitiesCompatibleAsDataType=FO,h.checkArePropertiesCompatibleAsDataType=GO,h.checkHasMetadataChanged=pt,h.checkImplementationsOverlap=Tr,h.checkIsBranchDependentButNotDirectlyOnBranch=Ma,h.checkIsBranchDependentOnBranch=pJ,h.checkIsCallableEntityReachable=ja,h.checkIsCanvasEntity=VJ,h.checkIsDetachedBranch=YP,h.checkIsDetachedBranchShallow=tf,h.checkIsGlobalVariable=wJ,h.checkIsGloballyDeclared=ef,h.checkIsMethod=XP,h.checkIsNestedScope=ed,h.checkScopeCompatibility=ga,h.cloneProject=wW,h.conditionValidation=Mq,h.continueStatementValidation=Iq,h.convertToAbstract=oJ,h.convertToNonAbstract=lJ,h.convertToNonStatic=uJ,h.convertToStatic=dJ,h.countedLoopActionDescriptor=Ls,h.countedLoopActionDescriptorDynamicReturnDeclaration=lT,h.countedLoopActionDescriptorDynamicReturnDeclarationParentRef=oT,h.countedLoopActionDescriptorStringArgumentDeclaration=aT,h.countedLoopActionDescriptorStringArgumentDeclarationDataType=nT,h.countedLoopActionDescriptorStringArgumentDeclarationDataTypeDefaultValue=iT,h.countedLoopActionDescriptorStringArgumentDeclarationDataTypeDefaultValueParentRef=tT,h.countedLoopActionDescriptorStringArgumentDeclarationDataTypeParentRef=rT,h.countedLoopActionDescriptorStringArgumentDeclarationParentRef=sT,h.countedLoopBodyActionDescriptor=oo,h.countedLoopBodyActionDescriptorAnyDynamicArgument=fT,h.countedLoopBodyActionDescriptorAnyDynamicArgumentParentRef=cT,h.countedLoopBodyActionDescriptorAnyDynamicReturn=hT,h.countedLoopBodyActionDescriptorAnyDynamicReturnParentRef=yT,h.countedLoopBodyActionDescriptorIterationNumberArgumentDeclaration=Gd,h.countedLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=uT,h.countedLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=dT,h.countedLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=pT,h.createDefinitionEntityFromJSONObject=Wl,h.createEntityError=de,h.createNestedDataTypeForEntity=Q1,h.createNewInstanceOperation=on,h.createNewInstanceOperationEntityToInstanciateArgument=Vm,h.createNewInstanceOperationEntityToInstanciateArgumentRef=Pm,h.createNewInstanceOperationEntityToInstanciateDataType=wm,h.createNewInstanceOperationError=Nm,h.createNewInstanceOperationErrorParentRef=Mm,h.createNewInstanceOperationNewEntityDataArgument=Om,h.createNewInstanceOperationNewEntityDataArgumentDataType=Dm,h.createNewInstanceOperationNewEntityDataArgumentDataTypeParentRef=Rm,h.createNewInstanceOperationNewEntityDataArgumentParentRef=bm,h.createNewInstanceOperationOutputEntityDeclaration=_m,h.createNewInstanceOperationOutputEntityDeclarationParentRef=Bm,h.createNewInstanceOperationRef=Cm,h.createSemanticId=XO,h.createStateFromGenerationTargetType=QJ,h.createStateFromType=ct,h.createStateFromTypeAndSubscribe=C,h.cronJobBuiltInBaseEntity=fo,h.cronJobBuiltInBaseEntityExpressionProperty=GI,h.cronJobBuiltInBaseEntityExpressionPropertyDataTypeRef=Ow,h.cronJobBuiltInBaseEntityExpressionPropertyRef=jI,h.cronJobBuiltInBaseEntityRef=$I,h.cronJobTriggeredFunctionDeclarationBlueprint=Qd,h.cronJobTriggeredFunctionDeclarationBlueprintParentRef=UI,h.dataTypeCompatibilityToErrorExplanation=z1,h.dataTypeValidation=Rq,h.datePrototype=Li,h.dateValueAutogenerationSchema=fp,h.definitionEntityToZodSchema=RE,h.definitionEntityValidation=YJ,h.deletePersistedEntityMethod=Xd,h.deletePersistedEntityMethodParentRef=EI,h.deleteRootProject=VW,h.endpointBuiltInBaseEntity=js,h.endpointBuiltInBaseEntityRef=AT,h.endpointBuiltInBaseEntityRefFour=iI,h.endpointBuiltInBaseEntityRefThree=BT,h.endpointBuiltInBaseEntityRefTwo=PT,h.endpointBuiltInCorsProperty=bT,h.endpointBuiltInCorsPropertyDataType=ET,h.endpointBuiltInCorsPropertyDataTypeRef=TT,h.endpointBuiltInCorsPropertyRef=IT,h.endpointBuiltInMethodProperty=xd,h.endpointBuiltInMethodPropertyDataType=VT,h.endpointBuiltInMethodPropertyDataTypeRef=wT,h.endpointBuiltInMethodPropertyRef=CT,h.endpointBuiltInPathProperty=Fd,h.endpointBuiltInPathPropertyDataType=OT,h.endpointBuiltInPathPropertyDataTypeRef=RT,h.endpointBuiltInPathPropertyRef=DT,h.endpointPathParamsArgumentDeclaration=Sd,h.endpointPathParamsArgumentDeclarationRef=FT,h.endpointPathParamsVariableDataType=xT,h.endpointPathParamsVariableDataTypeRef=GT,h.endpointReachedTriggerActionDescriptor=Yd,h.endpointReachedTriggerActionDescriptorRef=kT,h.endpointReachedTriggerActionDescriptorRefFour=qT,h.endpointReachedTriggerActionDescriptorRefThree=ZT,h.endpointReachedTriggerActionDescriptorRefTwo=ST,h.endpointRequestBodyArgumentDeclaration=qd,h.endpointRequestBodyArgumentDeclarationRef=LT,h.endpointRequestBodyVariableDataType=UT,h.endpointRequestHeadersArgumentDeclaration=kd,h.endpointRequestHeadersArgumentDeclarationRef=MT,h.endpointRequestHeadersVariableDataType=NT,h.endpointRequestHeadersVariableDataTypeRef=_T,h.endpointRequestQueryParamsArgumentDeclaration=Zd,h.endpointRequestQueryParamsArgumentDeclarationRef=jT,h.endpointRequestQueryParamsVariableDataType=$T,h.endpointRequestQueryParamsVariableDataTypeRef=gT,h.endpointResponseBodyDataType=eI,h.endpointResponseBodyReturnDeclaration=zd,h.endpointResponseBodyReturnDeclarationRef=QT,h.endpointResponseCodeDataType=WT,h.endpointResponseCodeReturnDeclaration=Jd,h.endpointResponseCodeReturnDeclarationRef=JT,h.endpointResponseHeadersDataType=KT,h.endpointResponseHeadersDataTypeRef=YT,h.endpointResponseHeadersReturnDeclaration=Wd,h.endpointResponseHeadersReturnDeclarationRef=HT,h.endpointReturnStatementRef=zT,h.endpointReturnStatementRefThree=tI,h.endpointReturnStatementRefTwo=XT,h.enrichFromKnownEntities=Na,h.enumOptionsProperty=hf,h.enumOptionsPropertyDataType=ff,h.enumOptionsPropertyDataTypeRef=pf,h.enumOptionsPropertyRef=cf,h.enumPrototype=tr,h.enumPrototypeRef=yf,h.executionBuiltInBaseEntity=yo,h.executionBuiltInEntityAbortMethod=eu,h.executionBuiltInEntityAbortMethodParentRef=FI,h.filterOutDuplicateEntities=p,h.filterOutDuplicateErrors=B3,h.findEntityFromKeys=Sc,h.findReferenceToSelfInList=yP,h.findReferencesToSelfInProject=EJ,h.flattenActionDescriptor=hP,h.flattenArgumentDeclaration=mP,h.flattenBreakStatement=vP,h.flattenBuiltInBaseEntity=TP,h.flattenCalls=Hi,h.flattenCanvasAncestorsUntil=Ds,h.flattenCondition=IP,h.flattenContinueStatement=EP,h.flattenDataType=bP,h.flattenDefinitionEntity=AP,h.flattenDefinitionEntityExtensionAndImplementationTypes=Xc,h.flattenDefinitionEntityExtensionTypes=Ql,h.flattenDefinitionEntityExtensions=Hc,h.flattenDefinitionEntityImplementations=Kc,h.flattenDefinitionEntityImplementionTypes=Xl,h.flattenDerivedCanvasEntities=oi,h.flattenDetachedBranch=KP,h.flattenElementCalls=qe,h.flattenElementCallsOnTheSameScope=IJ,h.flattenEntity=U,h.flattenFunctionCall=RP,h.flattenFunctionDeclaration=DP,h.flattenGlobalEvent=OP,h.flattenInputMap=PP,h.flattenInstalledProject=wP,h.flattenInternalCall=CP,h.flattenLiteralValue=VP,h.flattenLoop=BP,h.flattenOperation=_P,h.flattenOutputMap=MP,h.flattenPrimitiveEntity=NP,h.flattenProject=LP,h.flattenProjectElements=fP,h.flattenProperty=UP,h.flattenRelatedCanvasElementsOnTheLeft=WP,h.flattenRelatedCanvasElementsOnTheRight=JP,h.flattenReturnDeclaration=gP,h.flattenReturnStatement=jP,h.flattenSearch=$P,h.flattenValueDescriptor=GP,h.flattenVariableDeclaration=FP,h.flattenVariableInstance=xP,h.flattenVariableReads=cP,h.flattenVariableWrites=pP,h.flattenVariables=Ye,h.fromChangeSetToRecordChangeSet=jJ,h.fromZodParseToEntityGenerationErrors=Mc,h.functionCallValidation=aJ,h.functionDeclarationValidation=bq,h.generate=VV,h.generateActionExample=Qq,h.generateExecutionDataType=oq,h.generateIdFromStrategy=ht,h.generateMutablePropertiesExplanation=jl,h.generateRandomBoolean=HE,h.generateRandomDate=wE,h.generateRandomDateAfter=DE,h.generateRandomDateBefore=OE,h.generateRandomDateBetweenRange=PE,h.generateRandomNumber=qE,h.generateRandomNumberAfter=kE,h.generateRandomNumberBefore=SE,h.generateRandomNumberBetweenRange=ZE,h.generateRandomText=YE,h.generateRandomTextAfter=JE,h.generateRandomTextBefore=WE,h.generateRandomTextBetweenRange=zE,h.generateUniqueUUID=xE,h.getAllActionDescriptorsForConditions=Zl,h.getAllActionDescriptorsForGlobalEvents=kl,h.getAllActionDescriptorsForLoops=Sl,h.getAllActionDescriptorsForOperations=rJ,h.getAllBuiltInEntityIds=_i,h.getAllGloballyDeclaredFunctionDeclarationsExplanation=q1,h.getBaseBuiltInEntities=kt,h.getBaseSchemaBasedOnType=j1,h.getBuiltInEntityOwner=rn,h.getCallableEntityReferenceSchema=Pt,h.getCallableEntityTypeSchema=wD,h.getCalledBy=hi,h.getCallerEntityReferenceSchema=LS,h.getCallerEntityTypeSchema=NS,h.getCalls=Wc,h.getCanvasEntitiesDerivedFromInternalCalls=qP,h.getCanvasEntitiesDerivedFromWrites=Os,h.getCanvasEntityDerivedFromValueReadingEntity=Kl,h.getCanvasEntityDerivedFromValueReadingEntityFromTransfer=ZP,h.getCanvasEntityReferenceSchema=KS,h.getCanvasEntityTypeSchema=HS,h.getChildrenEntityWithValues=fJ,h.getColumnProperties=LJ,h.getCommonAncestor=Jc,h.getCommonChildren=eP,h.getDatabaseEntities=MJ,h.getDatabaseEntity=UJ,h.getDeclaration=Nn,h.getDeepestScope=ew,h.getDefinitionEntityExtends=Ps,h.getDraggableCallableEntityReferenceSchema=VD,h.getDraggableCallableEntityTypeSchema=CD,h.getDraggableCallerEntityReferenceSchema=gS,h.getDraggableCallerEntityTypeSchema=US,h.getDraggableExecutableEntityReferenceSchema=FS,h.getDraggableExecutableEntityTypeSchema=GS,h.getDraggablePassThroughCallableEntityReferenceSchema=Rl,h.getDraggablePassThroughCallableEntityTypeSchema=bl,h.getDraggablePlayableEntityReferenceSchema=qS,h.getDraggablePlayableEntityTypeSchema=ZS,h.getEntitiesCreatedSinceInitialization=ad,h.getEntityArgumentDeclarations=Yc,h.getEntityInputMaps=kP,h.getEntityOutputMaps=DJ,h.getEntityReferenceSchema=YS,h.getEntityReturnDeclarations=SP,h.getEntityTypeSchema=zS,h.getEntityWithLogicScopeReferenceSchema=fr,h.getEntityWithLogicScopeTypeSchema=xS,h.getEntityWithValueReferenceSchema=PD,h.getEntityWithValueTypeSchema=MS,h.getEntryPointEntityReferenceSchema=Rt,h.getEntryPointEntityTypeSchema=Mr,h.getEventEntityReferenceSchema=El,h.getEventEntityTypeSchema=Il,h.getExecutableEntityReferenceSchema=$S,h.getExecutableEntityTypeSchema=jS,h.getExtendedBuiltInEntity=OJ,h.getExtendedDefinitionEntity=Qc,h.getGenerationTargetSchemaBasedOnType=$1,h.getHeadIfPartOfDetachedBranch=HP,h.getHighestScope=QP,h.getImplementedBuiltInEntity=PJ,h.getIsInteractive=La,h.getLastInListOperation=bd,h.getLastInListOperationError=Rh,h.getLastInListOperationErrorParentRef=bh,h.getLastInListOperationInputListArgument=Ih,h.getLastInListOperationInputListArgumentParentRef=Th,h.getLastInListOperationInputListArgumentRef=yh,h.getLastInListOperationInputListDataType=hh,h.getLastInListOperationOutputElementDataType=vh,h.getLastInListOperationOutputElementReturn=Ah,h.getLastInListOperationOutputElementReturnParentRef=Eh,h.getLastInListOperationOutputElementReturnRef=mh,h.getLinkedEntitiesFromArgumentDeclaration=TJ,h.getLowestPersistedEntityImplementation=zP,h.getParentCallableEntity=tP,h.getParentCallerEntity=rP,h.getParentCanvasEntities=Xt,h.getParentCanvasEntity=wt,h.getParentCanvasEntityFromTransfer=zl,h.getParentEntryPoint=cJ,h.getParentPassthroughCallableEntity=iP,h.getPassThroughCallableEntityReferenceSchema=rt,h.getPassThroughCallableEntityTypeSchema=Al,h.getPeristedEntities=_J,h.getPlayableEntityReferenceSchema=SS,h.getPlayableEntityTypeSchema=kS,h.getProject=CW,h.getPrototypeByType=Ua,h.getRecusriveParentsIds=id,h.getReferenceEntityId=_,h.getReferencedEntitiesStateOrErrors=Gl,h.getReferencedEntityStateOrErrors=Nc,h.getReferencedIds=Hl,h.getRelatedCanvasElementsOnTheLeft=Ln,h.getRelatedCanvasElementsOnTheLeftFromTransfer=AJ,h.getRelatedCanvasElementsOnTheRight=tn,h.getRootEntryPointScopeOwner=rf,h.getScopeOwner=St,h.getStateClassFromType=gJ,h.getTerminationReferenceSchema=WS,h.getTerminationTypeSchema=JS,h.getTouchedCanvasEntitiesFromChangeSet=$J,h.getUsedArgFromDeclaration=bJ,h.getUsedReturnFromDeclaration=RJ,h.getValueReadingEntityReferenceSchema=OD,h.getValueReadingEntityTypeSchema=cr,h.getValueWritingEntityReferenceSchema=_S,h.getValueWritingEntityTypeSchema=Ea,h.getVariableFromInputMapping=sP,h.getVariableFromReturnVariablePointer=lP,h.getVariableReferenceSchema=_r,h.getVariableTypeSchema=wn,h.getVariablesFromArgumentDeclarations=Yl,h.getVariablesFromInputMaps=aP,h.getVariablesFromOutputMapping=dP,h.getVariablesFromOutputMaps=uP,h.getVariablesFromReturnDeclarations=oP,h.getVariablesInSameOrHigherScope=Tc,h.getWrites=zc,h.globalEventValidation=wq,h.groupCallsBasedOnParallelizableExecution=hJ,h.handleAfterEntityImplementationSideEffects=X1,h.handleBeforeEntityImplementationSideEffects=K1,h.httpRequestBodyArgument=Qa,h.httpRequestBodyArgumentRef=s0,h.httpRequestBodyDataType=a0,h.httpRequestHeadersArgument=Xa,h.httpRequestHeadersArgumentRef=r0,h.httpRequestHeadersDataType=n0,h.httpRequestMethodArgument=Ha,h.httpRequestMethodArgumentRef=t0,h.httpRequestMethodDataType=i0,h.httpRequestMethodDataTypeRef=Qm,h.httpRequestOperation=Bs,h.httpRequestOperationErrorValueDescriptor=Bd,h.httpRequestOperationErrorValueDescriptorDatatype=O0,h.httpRequestOperationErrorValueDescriptorRef=D0,h.httpRequestOperationRef=E0,h.httpRequestOperationRefEight=b0,h.httpRequestOperationRefFive=T0,h.httpRequestOperationRefFour=v0,h.httpRequestOperationRefNine=R0,h.httpRequestOperationRefSeven=A0,h.httpRequestOperationRefSix=I0,h.httpRequestOperationRefThree=m0,h.httpRequestOperationRefTwo=h0,h.httpRequestQueryParamsArgument=Vd,h.httpRequestQueryParamsArgumentRef=Km,h.httpRequestQueryParamsDataType=Xm,h.httpRequestVariableURLArgument=Ka,h.httpRequestVariableURLArgumentRef=Ym,h.httpRequestVariableURLDataType=Hm,h.httpRequestVariableURLDataTypeRef=Wm,h.httpResponseBodyReturnDataType=y0,h.httpResponseBodyReturnDataTypeRef=c0,h.httpResponseBodyReturnReturn=io,h.httpResponseBodyReturnReturnRef=f0,h.httpResponseCodeDataType=l0,h.httpResponseCodeReturn=eo,h.httpResponseCodeReturnRef=o0,h.httpResponseHeadersDataType=p0,h.httpResponseHeadersDataTypeRef=d0,h.httpResponseHeadersReturn=to,h.httpResponseHeadersReturnRef=u0,h.implement=Jl,h.inferArgumentDeclarationDataType=xO,h.inferDataType=Ji,h.inferInputMapDataType=hc,h.inferOutputMapDataType=vc,h.inferPropertyDataType=ZO,h.inferReturnDeclarationDataType=mc,h.inferValueDescriptorDataType=qO,h.inferVariableDeclarationDataType=SO,h.inferVariableInstanceDataType=kO,h.initBaseProjectEntity=sd,h.initProject=cw,h.initProjectFromFetchResult=pw,h.inputMapValidation=$q,h.installedProjectValidation=gq,h.internalCallValidation=jq,h.isPromise=kc,h.iterateOverListActionDescriptorListArgumentDeclaration=sv,h.iterateOverListActionDescriptorListArgumentDeclarationDataType=rv,h.iterateOverListActionDescriptorListArgumentDeclarationDataTypeParentRef=iv,h.iterateOverListActionDescriptorListArgumentDeclarationParentRef=nv,h.iterateOverListLoopActionDescriptor=Ar,h.iterateOverListLoopActionDescriptorDynamicReturnDeclaration=ov,h.iterateOverListLoopActionDescriptorDynamicReturnDeclarationParentRef=av,h.iterateOverListLoopBodyActionDescriptor=Ns,h.iterateOverListLoopBodyActionDescriptorAnyDynamicArgument=mv,h.iterateOverListLoopBodyActionDescriptorAnyDynamicArgumentParentRef=hv,h.iterateOverListLoopBodyActionDescriptorAnyDynamicReturn=Tv,h.iterateOverListLoopBodyActionDescriptorAnyDynamicReturnParentRef=vv,h.iterateOverListLoopBodyActionDescriptorCurrentValueArgumentDeclaration=ao,h.iterateOverListLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataType=dv,h.iterateOverListLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataTypeParentRef=lv,h.iterateOverListLoopBodyActionDescriptorCurrentValueArgumentDeclarationParentRef=uv,h.iterateOverListLoopBodyActionDescriptorIterationNumberArgumentDeclaration=yv,h.iterateOverListLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=cv,h.iterateOverListLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=pv,h.iterateOverListLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=fv,h.iterateOverObjectKeysActionDescriptorObjectArgumentDeclaration=Rv,h.iterateOverObjectKeysActionDescriptorObjectArgumentDeclarationDataType=Av,h.iterateOverObjectKeysActionDescriptorObjectArgumentDeclarationDataTypeParentRef=Ev,h.iterateOverObjectKeysActionDescriptorObjectArgumentDeclarationParentRef=bv,h.iterateOverObjectKeysLoopActionDescriptor=Sn,h.iterateOverObjectKeysLoopActionDescriptorDynamicReturnDeclaration=Ov,h.iterateOverObjectKeysLoopActionDescriptorDynamicReturnDeclarationParentRef=Dv,h.iterateOverObjectKeysLoopBodyActionDescriptor=Ud,h.iterateOverObjectKeysLoopBodyActionDescriptorAnyDynamicArgument=Lv,h.iterateOverObjectKeysLoopBodyActionDescriptorAnyDynamicArgumentParentRef=Nv,h.iterateOverObjectKeysLoopBodyActionDescriptorAnyDynamicReturn=gv,h.iterateOverObjectKeysLoopBodyActionDescriptorAnyDynamicReturnParentRef=Uv,h.iterateOverObjectKeysLoopBodyActionDescriptorCurrentValueArgumentDeclaration=Ld,h.iterateOverObjectKeysLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataType=wv,h.iterateOverObjectKeysLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataTypeParentRef=Pv,h.iterateOverObjectKeysLoopBodyActionDescriptorCurrentValueArgumentDeclarationParentRef=Cv,h.iterateOverObjectKeysLoopBodyActionDescriptorIterationNumberArgumentDeclaration=Mv,h.iterateOverObjectKeysLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=Bv,h.iterateOverObjectKeysLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=Vv,h.iterateOverObjectKeysLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=_v,h.iterateOverObjectValuesActionDescriptorObjectArgumentDeclaration=xv,h.iterateOverObjectValuesActionDescriptorObjectArgumentDeclarationDataType=Gv,h.iterateOverObjectValuesActionDescriptorObjectArgumentDeclarationDataTypeParentRef=$v,h.iterateOverObjectValuesActionDescriptorObjectArgumentDeclarationParentRef=Fv,h.iterateOverObjectValuesLoopActionDescriptor=Zn,h.iterateOverObjectValuesLoopActionDescriptorDynamicReturnDeclaration=Sv,h.iterateOverObjectValuesLoopActionDescriptorDynamicReturnDeclarationParentRef=kv,h.iterateOverObjectValuesLoopBodyActionDescriptor=jd,h.iterateOverObjectValuesLoopBodyActionDescriptorAnyDynamicArgument=Xv,h.iterateOverObjectValuesLoopBodyActionDescriptorAnyDynamicArgumentParentRef=Kv,h.iterateOverObjectValuesLoopBodyActionDescriptorAnyDynamicReturn=eT,h.iterateOverObjectValuesLoopBodyActionDescriptorAnyDynamicReturnParentRef=Qv,h.iterateOverObjectValuesLoopBodyActionDescriptorCurrentValueArgumentDeclaration=gd,h.iterateOverObjectValuesLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataType=qv,h.iterateOverObjectValuesLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataTypeParentRef=Zv,h.iterateOverObjectValuesLoopBodyActionDescriptorCurrentValueArgumentDeclarationParentRef=Jv,h.iterateOverObjectValuesLoopBodyActionDescriptorIterationNumberArgumentDeclaration=Hv,h.iterateOverObjectValuesLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=zv,h.iterateOverObjectValuesLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=Wv,h.iterateOverObjectValuesLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=Yv,h.iterateOverStringActionDescriptorDynamicReturnDeclaration=Z0,h.iterateOverStringActionDescriptorDynamicReturnDeclarationParentRef=S0,h.iterateOverStringActionDescriptorStringArgumentDeclaration=k0,h.iterateOverStringActionDescriptorStringArgumentDeclarationDataType=F0,h.iterateOverStringActionDescriptorStringArgumentDeclarationDataTypeParentRef=G0,h.iterateOverStringActionDescriptorStringArgumentDeclarationParentRef=x0,h.iterateOverStringLoopActionDescriptor=Ms,h.iterateOverStringLoopBodyActionDescriptor=so,h.iterateOverStringLoopBodyActionDescriptorAnyDynamicArgument=X0,h.iterateOverStringLoopBodyActionDescriptorAnyDynamicArgumentParentRef=K0,h.iterateOverStringLoopBodyActionDescriptorAnyDynamicReturn=ev,h.iterateOverStringLoopBodyActionDescriptorAnyDynamicReturnParentRef=Q0,h.iterateOverStringLoopBodyActionDescriptorCurrentValueArgumentDeclaration=Md,h.iterateOverStringLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataType=J0,h.iterateOverStringLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataTypeParentRef=q0,h.iterateOverStringLoopBodyActionDescriptorCurrentValueArgumentDeclarationParentRef=W0,h.iterateOverStringLoopBodyActionDescriptorIterationNumberArgumentDeclaration=Nd,h.iterateOverStringLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=Y0,h.iterateOverStringLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=z0,h.iterateOverStringLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=H0,h.joinListOperation=Id,h.joinListOperationError=Wy,h.joinListOperationErrorParentRef=Jy,h.joinListOperationFirstListArgument=xy,h.joinListOperationFirstListArgumentParentRef=Fy,h.joinListOperationFirstListArgumentRef=Ly,h.joinListOperationFirstListDataType=Uy,h.joinListOperationResultListDataType=Gy,h.joinListOperationResultListReturn=qy,h.joinListOperationResultListReturnParentRef=Zy,h.joinListOperationResultListReturnRef=$y,h.joinListOperationSecondListArgument=Sy,h.joinListOperationSecondListArgumentParentRef=ky,h.joinListOperationSecondListArgumentRef=gy,h.joinListOperationSecondListDataType=jy,h.joinListWithLastSeparator=ne,h.joinStringsOperation=Vs,h.joinStringsOperationDynamicStringArgument=fy,h.joinStringsOperationDynamicStringArgumentParentRef=cy,h.joinStringsOperationDynamicStringArgumentRef=uy,h.joinStringsOperationDynamicStringDataType=py,h.joinStringsOperationError=dy,h.joinStringsOperationErrorParentRef=ly,h.joinStringsOperationFirstStringArgument=Wa,h.joinStringsOperationFirstStringArgumentParentRef=Qf,h.joinStringsOperationFirstStringArgumentRef=Wf,h.joinStringsOperationFirstStringDataType=zf,h.joinStringsOperationResultStringDataType=Xf,h.joinStringsOperationResultStringReturn=Cs,h.joinStringsOperationResultStringReturnParentRef=oy,h.joinStringsOperationResultStringReturnRef=Kf,h.joinStringsOperationSecondStringArgument=za,h.joinStringsOperationSecondStringArgumentParentRef=ay,h.joinStringsOperationSecondStringArgumentRef=Yf,h.joinStringsOperationSecondStringDataType=Hf,h.joinStringsOperationSeparatorStringArgument=sy,h.joinStringsOperationSeparatorStringArgumentParentRef=ny,h.joinStringsOperationSeparatorStringArgumentRef=ey,h.joinStringsOperationSeparatorStringDataType=ry,h.joinStringsOperationSeparatorStringDataTypeDefaultValue=iy,h.joinStringsOperationSeparatorStringDataTypeDefaultValueParentRef=ty,h.keyValuePrototype=Fn,h.literalValudValidation=qq,h.loopValidation=Bq,h.lowercaseFirstLetter=_l,h.manualFlowActionDescriptorDeclarationArgumentDeclaration=_d,h.manualFlowActionDescriptorDeclarationArgumentDeclarationDataType=M0,h.manualFlowActionDescriptorDeclarationArgumentDeclarationDataTypeParentRef=_0,h.manualFlowActionDescriptorDeclarationArgumentDeclarationParentRef=N0,h.manualFlowLoopActionDescriptor=ro,h.manualFlowLoopActionDescriptorDynamicReturnDeclaration=B0,h.manualFlowLoopActionDescriptorDynamicReturnDeclarationParentRef=V0,h.manualFlowLoopBodyActionDescriptor=no,h.manualFlowLoopBodyActionDescriptorAnyDynamicArgument=U0,h.manualFlowLoopBodyActionDescriptorAnyDynamicArgumentParentRef=L0,h.manualFlowLoopBodyActionDescriptorAnyDynamicReturn=j0,h.manualFlowLoopBodyActionDescriptorAnyDynamicReturnParentRef=g0,h.mapActionDescriptorToTypeItRepresents=BJ,h.mergeEntityErrorsList=_3,h.mergeListOfEntities=CJ,h.methodDefaultValue=e0,h.mockClientProject=lp,h.moreThanOrEqualCondition=Yn,h.moreThanOrEqualConditionLeftHandArgument=zI,h.moreThanOrEqualConditionLeftHandArgumentDataType=JI,h.moreThanOrEqualConditionLeftHandArgumentDataTypeParentRef=qI,h.moreThanOrEqualConditionLeftHandArgumentParentRef=WI,h.moreThanOrEqualConditionRightHandArgument=XI,h.moreThanOrEqualConditionRightHandArgumentDataType=HI,h.moreThanOrEqualConditionRightHandArgumentDataTypeParentRef=YI,h.moreThanOrEqualConditionRightHandArgumentParentRef=KI,h.notEmptyCondition=fn,h.notEmptyConditionArgument=SI,h.notEmptyConditionRef=kI,h.nullPrototype=pd,h.numberAdditionOperation=Ja,h.numberAdditionOperationDynamicSummandArgument=Vf,h.numberAdditionOperationDynamicSummandArgumentType=Cf,h.numberAdditionOperationDynamicSummandArgumentTypeParentRef=wf,h.numberAdditionOperationError=Pf,h.numberAdditionOperationErrorParentRef=Of,h.numberAdditionOperationFirstNumberArgument=cd,h.numberAdditionOperationFirstNumberArgumentRef=vf,h.numberAdditionOperationFirstNumberDataType=Tf,h.numberAdditionOperationRef=Rf,h.numberAdditionOperationRefThree=yd,h.numberAdditionOperationRefTwo=Df,h.numberAdditionOperationResultNumberDataType=bf,h.numberAdditionOperationResultNumberReturn=hd,h.numberAdditionOperationResultNumberReturnRef=Af,h.numberAdditionOperationSecondNumberArgument=fd,h.numberAdditionOperationSecondNumberArgumentRef=If,h.numberAdditionOperationSecondNumberDataType=Ef,h.numberPrototype=ve,h.numberSubtractionOperation=vd,h.numberSubtractionOperationDynamicSubtrahendArgument=qf,h.numberSubtractionOperationDynamicSubtrahendArgumentType=Zf,h.numberSubtractionOperationDynamicSubtrahendArgumentTypeParentRef=Sf,h.numberSubtractionOperationError=kf,h.numberSubtractionOperationErrorParentRef=xf,h.numberSubtractionOperationFirstNumberArgument=gf,h.numberSubtractionOperationFirstNumberArgumentRef=Bf,h.numberSubtractionOperationFirstNumberDataType=_f,h.numberSubtractionOperationRef=md,h.numberSubtractionOperationRefThree=Gf,h.numberSubtractionOperationRefTwo=jf,h.numberSubtractionOperationResultNumberDataType=Uf,h.numberSubtractionOperationResultNumberReturn=Ff,h.numberSubtractionOperationResultNumberReturnRef=Lf,h.numberSubtractionOperationSecondNumberArgument=$f,h.numberSubtractionOperationSecondNumberArgumentRef=Mf,h.numberSubtractionOperationSecondNumberDataType=Nf,h.numberValueAutogenerationSchema=cp,h.operationValidation=Pq,h.outputMapValidation=xq,h.parallelExecutionOperation=Oi,h.parallelExecutionOperationError=Xh,h.parallelExecutionOperationErrorParentRef=Kh,h.parallelExecutionOperationListOfExecutionResultsDataType=zh,h.parallelExecutionOperationListOfExecutionResultsReturn=Pd,h.parallelExecutionOperationListOfExecutionResultsReturnRef=Wh,h.parallelExecutionOperationListOfFunctionsArgument=Od,h.parallelExecutionOperationListOfFunctionsArgumentDatatype=Jh,h.parallelExecutionOperationListOfFunctionsArgumentRef=qh,h.parallelExecutionOperationListOfFunctionsBlueprint=Zh,h.parallelExecutionOperationListOfFunctionsBlueprintDynamicInput=kh,h.parallelExecutionOperationListOfFunctionsBlueprintDynamicInputParentRef=xh,h.parallelExecutionOperationListOfFunctionsBlueprintDynamicOutput=Fh,h.parallelExecutionOperationListOfFunctionsBlueprintDynamicOutputParentRef=Gh,h.parallelExecutionOperationListOfFunctionsBlueprintParentRef=Sh,h.parallelExecutionOperationRef=Yh,h.parallelExecutionOperationRefThree=Hh,h.persistedBuiltInBaseEntity=Ct,h.persistedBuiltInBaseEntityDatabaseProperty=Jn,h.persistedBuiltInBaseEntityDatabasePropertyDataType=RI,h.persistedBuiltInBaseEntityDatabasePropertyDataTypeRef=Rw,h.persistedBuiltInBaseEntityDatabasePropertyParentRef=DI,h.persistedBuiltInBaseEntityDatabasePropertyRef=bI,h.persistedBuiltInBaseEntityPrimaryKeyProperty=Wn,h.persistedBuiltInBaseEntityPrimaryKeyPropertyDataType=MI,h.persistedBuiltInBaseEntityPrimaryKeyPropertyNumberDataTypeOption=PI,h.persistedBuiltInBaseEntityPrimaryKeyPropertyNumberDataTypeOptionParentRef=OI,h.persistedBuiltInBaseEntityPrimaryKeyPropertyParentRef=NI,h.persistedBuiltInBaseEntityPrimaryKeyPropertyRef=_I,h.persistedBuiltInBaseEntityPrimaryKeyPropertyStringDataTypeOption=CI,h.persistedBuiltInBaseEntityPrimaryKeyPropertyStringDataTypeOptionParentRef=wI,h.persistedBuiltInBaseEntityPrimaryKeyPropertyUUIDDataTypeOption=BI,h.persistedBuiltInBaseEntityPrimaryKeyPropertyUUIDDataTypeOptionParentRef=VI,h.processOutputGlobalValueDescriptorDataType=sE,h.processOutputGlobalValueDescriptorReturn=mo,h.processOutputGlobalValueDescriptorReturnRef=nE,h.projectPublicationCompletedGlobalEvent=ho,h.propertyToZodSchema=bE,h.propertyValidation=yq,h.relationalDatabaseBuiltInBaseEntity=ji,h.relationalDatabaseBuiltInBaseEntityAutoscalingProperty=Kd,h.relationalDatabaseBuiltInBaseEntityAutoscalingPropertyDataType=TI,h.relationalDatabaseBuiltInBaseEntityAutoscalingPropertyDataTypeRef=vI,h.relationalDatabaseBuiltInBaseEntityAutoscalingPropertyParentRef=II,h.relationalDatabaseBuiltInBaseEntityAutoscalingPropertyRef=mI,h.relationalDatabaseBuiltInBaseEntityDefaultProperty=Hd,h.relationalDatabaseBuiltInBaseEntityDefaultPropertyDataType=hI,h.relationalDatabaseBuiltInBaseEntityDefaultPropertyDataTypeRef=fI,h.relationalDatabaseBuiltInBaseEntityDefaultPropertyRef=yI,h.relationalDatabaseBuiltInBaseEntityIdentifierProperty=lo,h.relationalDatabaseBuiltInBaseEntityIdentifierPropertyDataType=sI,h.relationalDatabaseBuiltInBaseEntityIdentifierPropertyDataTypeRef=rI,h.relationalDatabaseBuiltInBaseEntityIdentifierPropertyRef=nI,h.relationalDatabaseBuiltInBaseEntityMinSizeProperty=co,h.relationalDatabaseBuiltInBaseEntityMinSizePropertyDataType=cI,h.relationalDatabaseBuiltInBaseEntityMinSizePropertyDataTypeRef=uI,h.relationalDatabaseBuiltInBaseEntityMinSizePropertyRef=pI,h.relationalDatabaseBuiltInBaseEntityPasswordProperty=po,h.relationalDatabaseBuiltInBaseEntityPasswordPropertyDataType=dI,h.relationalDatabaseBuiltInBaseEntityPasswordPropertyDataTypeRef=bw,h.relationalDatabaseBuiltInBaseEntityPasswordPropertyRef=lI,h.relationalDatabaseBuiltInBaseEntityRef=qn,h.relationalDatabaseBuiltInBaseEntityUsernameProperty=uo,h.relationalDatabaseBuiltInBaseEntityUsernamePropertyDataType=oI,h.relationalDatabaseBuiltInBaseEntityUsernamePropertyDataTypeRef=Aw,h.relationalDatabaseBuiltInBaseEntityUsernamePropertyRef=aI,h.resolveActionDescriptorName=KO,h.resolveBaseEntityName=WO,h.resolveBuiltInBaseEntityDataTypeLabel=zO,h.resolveClonedEntityProject=mt,h.resolveConditionOperatorLabel=Ul,h.resolveDataType=Ml,h.resolveDataTypeEntityOrNestedChildrenFromLiteralValue=Zc,h.resolveDataTypeLabel=Ll,h.resolveDefinitionEntityDataTypeLabel=cq,h.resolveEntityDataTypeLabel=pq,h.resolveEntityName=x,h.resolveFirstCallsSecond=mJ,h.resolveFirstWritesSecond=vJ,h.resolvePrimaryKeyProperty=NJ,h.resolvePrimitiveEntityName=HO,h.resolveSearchName=YO,h.resolveVariableScope=lq,h.returnDeclarationValidation=vq,h.returnStatementValidation=Tq,h.searchValidation=Uq,h.sequentialExecutionOperation=nr,h.sequentialExecutionOperationError=Tm,h.sequentialExecutionOperationErrorParentRef=vm,h.sequentialExecutionOperationListOfExecutionResultsDataType=ym,h.sequentialExecutionOperationListOfExecutionResultsReturn=Cd,h.sequentialExecutionOperationListOfExecutionResultsReturnParentRef=mm,h.sequentialExecutionOperationListOfExecutionResultsReturnRef=fm,h.sequentialExecutionOperationListOfFunctionsArgument=wd,h.sequentialExecutionOperationListOfFunctionsArgumentDatatype=cm,h.sequentialExecutionOperationListOfFunctionsArgumentParentRef=hm,h.sequentialExecutionOperationListOfFunctionsArgumentRef=pm,h.sequentialExecutionOperationListOfFunctionsBlueprint=um,h.sequentialExecutionOperationListOfFunctionsBlueprintDynamicInput=dm,h.sequentialExecutionOperationListOfFunctionsBlueprintDynamicOutput=lm,h.softDeletePersistedEntityMethod=Dw,h.softDeletePersistedEntityMethodParentRef=LI,h.sortCallsBasedOnExecutionDependencies=nP,h.sortChildrenEntitiesBasedOnExecutionDependencies=yJ,h.splitListOperation=Ad,h.splitListOperationError=ph,h.splitListOperationErrorParentRef=uh,h.splitListOperationFirstOutputListDataType=eh,h.splitListOperationFirstOutputListReturn=ah,h.splitListOperationFirstOutputListReturnParentRef=sh,h.splitListOperationFirstOutputListReturnRef=Ed,h.splitListOperationInputListArgument=ih,h.splitListOperationInputListArgumentParentRef=th,h.splitListOperationInputListArgumentRef=Hy,h.splitListOperationInputListDataType=Ky,h.splitListOperationSecondOutputListDataType=oh,h.splitListOperationSecondOutputListReturn=dh,h.splitListOperationSecondOutputListReturnParentRef=lh,h.splitListOperationSplitIndexArgument=nh,h.splitListOperationSplitIndexArgumentParentRef=rh,h.splitListOperationSplitIndexArgumentRef=Xy,h.splitListOperationSplitIndexDataType=Qy,h.splitStringOperation=Td,h.splitStringOperationError=By,h.splitStringOperationErrorParentRef=Vy,h.splitStringOperationFirstPartResultStringDataType=Iy,h.splitStringOperationFirstPartResultStringReturn=Cy,h.splitStringOperationFirstPartResultStringReturnParentRef=wy,h.splitStringOperationFirstPartResultStringReturnRef=Ty,h.splitStringOperationIndexArgument=Oy,h.splitStringOperationIndexArgumentParentRef=Dy,h.splitStringOperationIndexArgumentRef=my,h.splitStringOperationIndexDataType=vy,h.splitStringOperationSecondPartResultStringDataType=Ay,h.splitStringOperationSecondPartResultStringReturn=Iw,h.splitStringOperationSecondPartResultStringReturnParentRef=Py,h.splitStringOperationSecondPartResultStringReturnRef=Ey,h.splitStringOperationStringArgument=Ry,h.splitStringOperationStringArgumentParentRef=by,h.splitStringOperationStringArgumentRef=yy,h.splitStringOperationStringDataType=hy,h.stringPrototype=se,h.stringValueAutogenerationSchema=pp,h.suggestNewIdForEntity=Oc,h.test_primitive_entities_export=BW,h.toCamelCase=dq,h.toEntityState=mi,h.toKebabCase=JO,h.toLowerCaseKebabCase=Nl,h.toPascalCase=uq,h.untypedDataPrototype=Ot,h.updateErrorsList=He,h.urlDefaultValue=zm,h.uuidPrototype=ir,h.validateArgumentDeclarationName=Rc,h.validateCalledByErrorIdInAction=tJ,h.validateCalledByIdInAction=eJ,h.validateCallers=Z1,h.validateConditionEntityDeclaration=nJ,h.validateDataOperation=ln,h.validateDataOperationDataToValidateArgument=jm,h.validateDataOperationDataToValidateArgumentParentRef=gm,h.validateDataOperationDataToValidateArgumentRef=Lm,h.validateDataOperationDataToValidateDataType=Um,h.validateDataOperationEntityToMatchTypeArgument=xm,h.validateDataOperationEntityToMatchTypeArgumentParentRef=Fm,h.validateDataOperationEntityToMatchTypeArgumentRef=$m,h.validateDataOperationEntityToMatchTypeDataType=Gm,h.validateDataOperationError=qm,h.validateDataOperationErrorParentRef=Zm,h.validateDataOperationOutputEntityDeclaration=Sm,h.validateDataOperationOutputEntityDeclarationParentRef=km,h.validateDefinitionEntityName=Ic,h.validateEntryCaller=S1,h.validateErrorCaller=k1,h.validateFunctionCallDeclaration=J1,h.validateFunctionDeclarationName=Ec,h.validateGeneratedEntityParentIsNotBuiltInEntity=Hq,h.validateGeneration=zq,h.validateGenerationTarget=ut,h.validateGenerationUpdate=Yq,h.validateLoopEntityDeclaration=sJ,h.validateName=fq,h.validateOperationEntityDeclaration=W1,h.validatePropertyName=bc,h.validateReachability=vr,h.validateReadsValueInActionPayload=iJ,h.validateReferenceObject=$l,h.validateReferenceToOne=Lc,h.validateReferences=At,h.validateReturnDeclarationName=Dc,h.validateSuccessCaller=x1,h.validateValueReaderGenerationUpdate=_a,h.validateValueWritter=Fc,h.validateVariableDeclarationName=Ac,h.validateVariableInternalCallUse=xc,h.valueAutogenerationCurrentDateAndTimeSchema=nD,h.valueAutogenerationGenericSchema=nl,h.valueAutogenerationOptions=yp,h.valueAutogenerationOptionsSchema=rD,h.valueAutogenerationRandomBooleanSchema=up,h.valueAutogenerationRandomDateBetweenSchema=fD,h.valueAutogenerationRandomDateFromSchema=pD,h.valueAutogenerationRandomDateSchema=ol,h.valueAutogenerationRandomDateUntilSchema=cD,h.valueAutogenerationRandomNumberBetweenSchema=oD,h.valueAutogenerationRandomNumberFromSchema=sD,h.valueAutogenerationRandomNumberSchema=sl,h.valueAutogenerationRandomNumberUntilSchema=aD,h.valueAutogenerationRandomSchema=fa,h.valueAutogenerationRandomTextBetweenSchema=uD,h.valueAutogenerationRandomTextFromSchema=lD,h.valueAutogenerationRandomTextSchema=al,h.valueAutogenerationRandomTextUntilSchema=dD,h.valueAutogenerationRangeValueTypesSchema=ca,h.valueAutogenerationUniqueSchema=dp,h.valueDescriptorValidation=Wq,h.variableDeclarationValidation=Nq,h.variableInstanceValidation=Lq,h.waitOperation=qt,h.waitOperationMillisecondsNumberArgument=an,h.waitOperationMillisecondsNumberArgumentRef=tm,h.waitOperationMillisecondsNumberDataType=im,h.waitOperationOperationError=sm,h.waitOperationOperationErrorParentRef=nm,h.waitOperationRef=rm,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
408
+ Alternatively you can update the parent data-type entity with 'update' action to remove the existing value of the field.`,issue:null}))}return{errors:s,modifiedData:i}}get interactive(){return this.implements.length?this.implements.every(e=>e.interactive):!0}get allBasePropertiesFromExtendedAndImplementedEntities(){return p([...this.extends.reduce((e,t)=>[...[...t.ownDeclaredProperties,...t.allBasePropertiesFromExtendedAndImplementedEntities].filter(s=>!s.abstract),...e],[]),...this.implements.reduce((e,t)=>[...[...t.ownDeclaredProperties,...t.allBasePropertiesFromExtendedAndImplementedEntities].filter(s=>!s.abstract),...e],[])])}get extendedPropertiesFromOriginalParents(){return p(this.extends.reduce((e,t)=>{const i=[...t.ownDeclaredProperties,...t.extendedPropertiesFromOriginalParents].filter(s=>!s.abstract);return[...e,...i]},[]))}get implementedPropertiesFromOriginalParents(){return p([...this.extends.reduce((e,t)=>{const i=t.implementedPropertiesFromOriginalParents,s=[...t.ownDeclaredProperties].filter(l=>!!l.abstract&&!i.find(o=>o.name===l.name));return[...i,...s,...e]},[]),...this.implements.reduce((e,t)=>{const i=t.implementedPropertiesFromOriginalParents,s=[...t.ownDeclaredProperties].filter(l=>!!l.abstract&&!i.find(o=>o.name===l.name));return[...i,...s,...e]},[])].filter(e=>!!e.abstract))}get extendedProperties(){return this.properties.filter(e=>e.isExtendedProperty)}get ownDeclaredProperties(){return this.properties.filter(e=>!e.isExtendedProperty)}validateGeneratedUpdate(e){const t=[];return e.parent&&t.push(new w({id:`${this.id}--${R.InvalidParentUpdate}`,code:R.InvalidParentUpdate,severity:D.Error,message:`Entity of type '${this.type}' with id '${this.id}' cannot have the 'parent' property updated. The 'parent' on an '${this.type}', must be the root project as it is a globally declared entity.`,issue:null})),{errors:t,modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],i=[],s=[];return Object.values(this.detachedDependents).forEach(l=>{const o=l.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),i.push(...o.removed),s.push(...o.affected)}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];return t==="implements"&&this.removeImplementation(e),t==="extends"&&this.removeExtension(e),{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];return t==="implements"&&this.addImplementation(e),t==="extends"&&this.addExtension(e),{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){return this.implements.forEach(e=>{Ti.includes(e.type)||e.subscribeDependents([{entity:this,field:"implements"}])}),this.extends.forEach(e=>{Ti.includes(e.type)||e.subscribeDependents([{entity:this,field:"extends"}])}),this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=m.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new ge(this,this.project);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.properties=this.properties,e.methods=this.methods,e.abstractMethods=this.abstractMethods,e.extends=this.extends,e.implements=this.implements,e.parent=this.parent,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];if(this.parent){this.parent.increaseVersion(e);const o=this.parent.recursiveCaptureUpstreamVersions(e);t.push(this.parent,...o.updated),i.push(...o.added),s.push(...o.removed)}return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[I,E]of c.knownVersions)u.set(I,E);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new ge(u,this.project)}return this.metaSync(o.toShallowJSON(),null),this.properties=o.properties,this.methods=o.methods,this.abstractMethods=o.abstractMethods,this.extends=o.extends,this.implements=o.implements,this.parent=o.parent,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];if(this.initialData.parent){const l=_(this.initialData.parent),o=this.project.get(l);if(o)this.setParent(o,null),e.push(o);else throw new Error(`${this.type} with id '${this.id}' has a 'parent' reference '${l}' that isn't found in the project`)}else throw new Error(`${this.type} with id '${this.id}' must have a 'parent'`);return this.initialData.extends.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addExtension(d),d.type!==n.BuiltInBaseEntity&&e.push(d))}),this.initialData.implements.forEach(l=>{const o=_(l),d=this.project.get(o);d&&(this.addImplementation(d),d.type!==n.BuiltInBaseEntity&&e.push(d))}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"after-all-children-initialized"))){const t=[],i=[],s=[],l=[];this.initialized=!0,this.captureVersion();const{updated:o,added:d,removed:u,affected:y}=this.syncImplementationProperties(e);t.push(...o),i.push(...d),s.push(...u),l.push(...y);const{updated:c,added:I,removed:E,affected:O}=this.addExtendedProperties(e);return t.push(...c),i.push(...I),s.push(...E),l.push(...O),this.addSuggestions(),e==null||e.attemptAutoclose("after-all-children-initialized",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-self-to-project"))){const t=[this],i=[],s=[],l=[];if(this.parent.type===n.DataType){const o=this.parent;o.entity=this,t.push(o)}else this.project.addDefinitionEntity(this);return this.subscribe(),this.subscribeToDependencies(),e==null||e.attemptAutoclose("add-self-to-project",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}setParent(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"set-parent"))){var i;return((i=this.parent)==null?void 0:i.id)!==(e==null?void 0:e.id)&&(this.parent=e,t&&(t==null||t.add(this,A.Updated),t==null||t.attemptAutoclose("set-parent",this.id))),this}addExtension(e){return this.extends.includes(e)||this.extends.push(e),this}removeExtension(e){return this.extends=this.extends.filter(t=>t.id!==e.id),this}addImplementation(e){return this.implements.includes(e)||this.implements.push(e),this}removeImplementation(e){return this.implements=this.implements.filter(t=>t.id!==e.id),this}removeProperty(e){return this.properties=this.properties.filter(t=>t.id!==e.id),this}addMethod(e){return this.methods.includes(e)||(this.methods.push(e),this.suggestedMethods=this.suggestedMethods.filter(t=>t.name!==e.name)),this}removeMethod(e){return this.methods=this.methods.filter(t=>t.id!==e.id),this}addProperty(e){return this.properties.includes(e)||(this.properties.push(e),this.suggestedProperties=this.suggestedProperties.filter(t=>t.name!==e.name)),this}addSuggestedProperty(e){return this.suggestedProperties.includes(e)||this.suggestedProperties.push(e),this}addSuggestedMethod(e){return this.suggestedMethods.includes(e)||this.suggestedMethods.push(e),this}removeSuggestedProperty(e){return this.suggestedProperties=this.suggestedProperties.filter(t=>t.id!==e.id),this}removeSuggestedMethod(e){return this.suggestedMethods=this.suggestedMethods.filter(t=>t.id!==e.id),this}addAbstractMethod(e){return this.abstractMethods.includes(e)||this.abstractMethods.push(e),this}removeAbstractMethod(e){return this.abstractMethods=this.abstractMethods.filter(t=>t.id!==e.id),this}initChildren(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.properties=this.initialData.properties.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.methods=this.initialData.methods.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.abstractMethods=this.initialData.abstractMethods.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(e),i}),this.extends=this.initialData.extends.map(t=>C(t,this.project)),this.implements=this.initialData.implements.map(t=>C(t,this.project)),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}syncImplementationProperties(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-implementation-properties"))){const t=[],i=[],s=[],l=[],o=this.properties,d=this.implementedPropertiesFromOriginalParents,u=[...this.allBasePropertiesFromExtendedAndImplementedEntities,...o];return d.filter(c=>!u.find(E=>{var O;return((O=E.implements)==null?void 0:O.id)===c.id})).forEach(c=>{if(this.properties.find(P=>{var V;return((V=P.implements)==null?void 0:V.id)===c.id}))return;const E=this.properties.find(P=>P.name===c.name&&!!P.abstract&&!P.implements);if(E){E.implements=c,E.abstract=!1;return}const O=c.clone(e,this,m.UUID.uuid());O.initChildren(e),i.push(O),e==null||e.add(O,A.Added),O.setImplements(c,e),O.metaSync({abstract:!1},e),this.addProperty(O)}),e==null||e.attemptAutoclose("sync-implementation-properties",this.id),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addExtendedProperties(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"add-extended-properties"))){const t=[],i=[],s=[],l=[],o=this.properties,d=this.extendedPropertiesFromOriginalParents,u=d.filter(c=>d.find(E=>{var O;return((O=E.implements)==null?void 0:O.id)===c.id})?!1:!c.abstract),y=new Set(o.map(c=>c.name));return u.forEach(c=>{if(y.has(c.name))return;y.add(c.name);const I=c.clone(e,this,m.UUID.uuid());I.initChildren(e),i.push(I),e==null||e.add(I,A.Added),this.addProperty(I)}),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSuggestions(){return this.implements.forEach(e=>{iw(this,e).forEach(s=>{const l=s.toJSON();l.id=`_suggestion--parent--${this.id}--${s.id}`;const o=C(l,this.project);o.suggestion=!0,o.setParent(this,null),o.initChildren(null),this.addSuggestedProperty(o)}),rw(this,e).forEach(s=>{const l=`_suggestion--parent--${this.id}--${s.id}`,o=s.implementAsFunctionDeclaration(null,this,l),d=C(o,this.project);if(d.suggestion=!0,d.setParent(this,null),d.initChildren(null),this.methods=this.methods.filter(u=>u.id!==l),d.inputs.forEach(u=>{u.suggestion=!0}),d.returnStatements.length){const u=d.returnStatements[0];u.suggestion=!0,u.outputs.forEach(y=>{y.suggestion=!0})}this.addSuggestedMethod(d)})}),this}subscribe(){return this.activeVersion=!0,this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}metaSync(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.name=e.name||s.name,this.description=e.description||s.description,this.x=e.x||s.x,this.y=e.y||s.y,this.static=e.static!==void 0?e.static:this.static,this.abstract=e.abstract!==void 0?e.abstract:this.abstract,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=g,...t){return await ge.repository.APILoad(this.id,...t),this}async APICreate(e=g,...t){return await ge.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=g,...t){return await ge.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=g,...t){return await ge.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=g,...t){return await ge.repository.APIClone(this.id,...t),this}async APILoadVersion(e=g,t,...i){return await ge.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){const i=[],s=[],l=[],o=[];if(t!=null&&t.hasRemoved(this.id))return t==null||t.attemptAutoclose("remove-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this};if(s.push(this),this.unsubscribe(),this.project.subscribeDeletedInstance(this),this.metaSync({deleted:!0},t),Object.values(this.detachedDependents).forEach(d=>{const{updated:u,removed:y,added:c}=d.entity.onDetachedDependencyRemoved(this,d.field,t);i.push(...u),s.push(...y),l.push(...c)}),this.properties.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.methods.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.abstractMethods.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.suggestedProperties.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),this.suggestedMethods.forEach(d=>{const{updated:u,removed:y}=d.remove({ignoreUpstream:!0},t);i.push(...u),s.push(...y)}),!e){if(this.parent.type===n.Project)this.parent.removeDefinitionEntity(this);else if(this.parent.type===n.DataType){const d=this.parent.setEntity(null);i.push(d)}}return t==null||t.attemptAutoclose("remove-entity",this.id),{added:p(l),updated:p(i),removed:p(s),affected:p(o),self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){const t=[],i=[],s=[],l=[];return e!=null&&e.hasAdded(this.id)?(e==null||e.attemptAutoclose("restore-entity",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(this.subscribe(),this.project.unsubscribeDeletedInstance(this),this.metaSync({deleted:!1},e),this.properties.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.methods.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.abstractMethods.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.suggestedProperties.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),this.suggestedMethods.forEach(o=>{const{updated:d}=o.restore({},e);i.push(...d)}),e==null||e.attemptAutoclose("restore-entity",this.id),{added:p(t),updated:p(i),removed:p(s),affected:p(l),self:this})}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.extends.flatMap(i=>i.toFlat(e)),...this.implements.flatMap(i=>i.toFlat(e)),...this.properties.flatMap(i=>i.toFlat(e)),...this.methods.flatMap(i=>i.toFlat(e)),...this.abstractMethods.flatMap(i=>i.toFlat(e)),...this.parent.toFlat(e)])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.extends.flatMap(i=>i.toFlatIds(e)),...this.implements.flatMap(i=>i.toFlatIds(e)),...this.properties.flatMap(i=>i.toFlatIds(e)),...this.methods.flatMap(i=>i.toFlatIds(e)),...this.abstractMethods.flatMap(i=>i.toFlatIds(e)),...this.parent.toFlatIds(e)])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,static:this.static,abstract:this.abstract,x:this.x,y:this.y,type:this.type,name:this.name}}toJSON(e=new Set){return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,x:this.x,y:this.y,static:this.static,abstract:this.abstract,properties:this.properties.map(t=>t.toJSON(e)),methods:this.methods.map(t=>t.toJSON(e)),abstractMethods:this.abstractMethods.map(t=>t.toJSON(e)),implements:this.implements.map(t=>t.toJSON(e)),extends:this.extends.map(t=>t.toJSON(e)),parent:this.parent.toReference()})}toJSONClone(e=q){var i,s,l,o,d;let t;return(i=e.seenEntityMaps)!=null&&i.has(this.id)?t=e.seenEntityMaps.get(this.id):(t=e.newId||ht(this,this.project,e.uuidStrategy),e.seenEntityMaps&&e.seenEntityMaps.set(this.id,t)),(s=e.seenEntities)!=null&&s.has(t)||(l=e.seenEntities)!=null&&l.has(this.id)?this.toReference({seenEntityMaps:e.seenEntityMaps}):((o=e.seenEntities)==null||o.add(t),(d=e.seenEntities)==null||d.add(this.id),{id:t,version:m.UUID.uuid(),createdAt:e.timestamp||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,type:this.type,name:this.name,description:this.description,x:this.x,y:this.y,static:this.static,abstract:this.abstract,properties:this.properties.map(u=>u.toJSONClone({...e,newId:null})),methods:this.methods.map(u=>u.toJSONClone({...e,newId:null})),abstractMethods:this.abstractMethods.map(u=>u.toJSONClone({...e,newId:null})),implements:this.implements.map(u=>u.type===n.BuiltInBaseEntity?u.toJSON():u.toJSONClone({...e,newId:null})),extends:this.extends.map(u=>u.type===n.BuiltInBaseEntity?u.toJSON():u.toJSONClone({...e,newId:null})),parent:this.parent.toReference({seenEntityMaps:e.seenEntityMaps})})}toReference(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,name:this.name,description:this.description,type:this.type,x:this.x,y:this.y,static:this.static,abstract:this.abstract,properties:this.properties.map(s=>s.toReference(e)),methods:this.methods.map(s=>s.toReference(e)),abstractMethods:this.abstractMethods.map(s=>s.toReference(e)),implements:this.implements.map(s=>s.toReference(e)),extends:this.extends.map(s=>s.toReference(e)),parent:this.parent.toReference(e)}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.properties.flatMap(i=>i.toFlatJSON(e)),...this.methods.flatMap(i=>i.toFlatJSON(e)),...this.abstractMethods.flatMap(i=>i.toFlatJSON(e)),...this.implements.flatMap(i=>i.toFlatJSON(e)),...this.extends.flatMap(i=>i.toFlatJSON(e)),...this.parent.toFlatJSON(e)])}toGenerationTarget(){const e=this.parent.type===n.Project?void 0:this.parent.id;return{id:this.id,name:this.name,description:this.description,type:this.type,static:this.static,abstract:this.abstract,extends:this.extends.map(t=>t.id),implements:this.implements.map(t=>t.id),parent:e}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.properties.flatMap(i=>i.toFlatGenerationTarget(e)),...this.methods.flatMap(i=>i.toFlatGenerationTarget(e)),...this.abstractMethods.flatMap(i=>i.toFlatGenerationTarget(e)),...this.implements.filter(i=>i.type===n.DefinitionEntity).flatMap(i=>i.toFlatGenerationTarget(e)),...this.implements.filter(i=>i.type===n.DefinitionEntity).flatMap(i=>i.toFlatGenerationTarget(e)),...this.parent.toFlatGenerationTarget(e)])}clearErrors(){return this.errors=[],this.properties.forEach(e=>e.clearErrors()),this.methods.forEach(e=>e.clearErrors()),this.abstractMethods.forEach(e=>e.clearErrors()),this}validate(){return this.errors=tw(this),{success:!0,error:null,data:null}}getErrors(){return[...this.errors,...this.properties.flatMap(t=>t.getErrors()),...this.methods.flatMap(t=>t.getErrors()),...this.abstractMethods.flatMap(t=>t.getErrors())]}getShallowErrors(){return this.errors}clone(e=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"clone-entity")),t=null,i=null,s=!0){var P,V,M;let l=mt(t,this);const o=this.toJSON(),d=i||m.UUID.uuid();o.properties=[],o.methods=[],o.abstractMethods=[];const u=d.split("-id"),y=u[u.length-1||0]||d;o.id=d,o.version=m.UUID.uuid(),o.createdAt=(e==null?void 0:e.timestamp)||T().toISOString(),o.author=(e==null?void 0:e.author)||"1",o.previousVersion=null,o.deleted=!1;const c=ct(o,l);t&&c.setParent(t,null),s&&c.subscribe(),c.initChildren(e),e==null||e.add(c,A.Added);const I=(P=this.properties)==null?void 0:P.map(G=>G.clone(e,c,m.UUID.uuid(),s));c.properties=I;const E=(V=this.methods)==null?void 0:V.map((G,B)=>G.clone(e,c,y+"-method-"+B+"-id",s));c.methods=E;const O=(M=this.abstractMethods)==null?void 0:M.map((G,B)=>G.clone(e,c,y+"-abstract-method-"+B+"-id",s));return c.abstractMethods=O,e==null||e.attemptAutoclose("clone-entity",this.id),c}getFunctionDeclaration(e){return this.methods.find(t=>t.id===e)}implement(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"implement-definition-entity")),i){const s=Jl(this,e,t,i);return t==null||t.attemptAutoclose("implement-definition-entity",this.id),s}getAllInteractiveMethods(){const e=this.implements.filter(i=>i.type===n.DefinitionEntity||i.type===n.BuiltInBaseEntity&&i.interactive);return p([...this.methods,...this.extends.flatMap(i=>i.getAllInteractiveMethods()),...e.flatMap(i=>i.getAllInteractiveMethods())])}inferFromInputs(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"infer-definition-entity-from-inputs"))){const i=[],s=[],l=[],o=[];if(this.parent.type!==n.DataType||!this.parent.inferred)return t==null||t.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this};const d=[];e.forEach(c=>{d.find(E=>x(E,this.project)===x(c,this.project))||d.push(c)});const u=this.properties.filter(c=>!c.dataType);d.forEach(c=>{var M,G;const I=u.find(B=>x(B,this.project)===x(c,this.project));if(!I)return;const O=Nn(c.parent).getMasterInputWithValueWritterFromAllInstances(c),P=Ji(O,t),V=P==null?void 0:P.clone(t,I,m.UUID.uuid(),!0);if(V){const B=(M=I.dataType)==null?void 0:M.merge(V,t);I.dataType&&(B==null?void 0:B.self.id)!==I.dataType.id&&I.dataType.remove({ignoreUpstream:!1},t),V.id!==((G=B==null?void 0:B.self)==null?void 0:G.id)&&V.remove({ignoreUpstream:!1},t),B!=null&&B.self&&(B.self.metaSync({inferred:!0,like:!0},t),t==null||t.add(B.self,A.Added),I.setDataType(B.self),t==null||t.add(I,A.Updated))}c.setDeclaration(I),t==null||t.add(c,A.Updated)});const y=[];return d.forEach(c=>{if(!c.declaration){y.push(c);return}}),y.length===0?(t==null||t.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:[],updated:[],removed:[],affected:[],self:this}):(y.forEach(c=>{var B,$,Z,J;const I=this.properties.find(te=>x(te,this.project)===x(c,this.project));if(I){if(c.setDeclaration(I),!I.getDataType(t)){const fe=Nn(c.parent).getMasterInputWithValueWritterFromAllInstances(c),Ie=Ji(fe),X=Ie==null?void 0:Ie.clone(t,I,m.UUID.uuid(),!0);if(X){const le=(B=I.dataType)==null?void 0:B.merge(X,t);I.dataType&&(le==null?void 0:le.self.id)!==I.dataType.id&&I.dataType.remove({ignoreUpstream:!1},t),X.id!==(($=le==null?void 0:le.self)==null?void 0:$.id)&&X.remove({ignoreUpstream:!1},t),le!=null&&le.self&&(le.self.metaSync({inferred:!0,like:!0},t),t==null||t.add(le.self,A.Added),I.setDataType(le.self),t==null||t.add(I,A.Updated))}}return}const E={id:m.UUID.uuid(),type:n.Property,version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:x(c,this.project),description:c.description,defaultValue:null,static:!0,abstract:!1,private:!1,hidden:!1,required:!1,constant:!0,index:c.index,implements:null,dataType:null,parent:this.toReference()},O=C(E,this.project);O.setParent(this,t),O.initChildren(t),t==null||t.add(O,A.Added);const V=Nn(c.parent).getMasterInputWithValueWritterFromAllInstances(c),M=Ji(V),G=M==null?void 0:M.clone(t,O,m.UUID.uuid(),!0);if(G){const te=(Z=O.dataType)==null?void 0:Z.merge(G,t);O.dataType&&(te==null?void 0:te.self.id)!==O.dataType.id&&O.dataType.remove({ignoreUpstream:!1},t),G.id!==((J=te==null?void 0:te.self)==null?void 0:J.id)&&G.remove({ignoreUpstream:!1},t),te!=null&&te.self&&(te.self.metaSync({inferred:!0,like:!0},t),t==null||t.add(te.self,A.Added),O.setDataType(te.self),t==null||t.add(O,A.Updated))}return this.addProperty(O),c.setDeclaration(O),t==null||t.add(c,A.Updated),O}),t==null||t.attemptAutoclose("infer-definition-entity-from-inputs",this.id),{added:p(i),updated:p(s),removed:p(l),affected:p(o),self:this})}};f(ge,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(ge,"type",n.DefinitionEntity),f(ge,"USER_MANAGED_PARENT_TYPES",[n.Project,n.DataType]),f(ge,"PARENT_TYPES",[...ge.USER_MANAGED_PARENT_TYPES]),f(ge,"MUTABLE_BASE_PROPERTIES",["name","description","static","abstract"]),f(ge,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(ge,"BASE_PROPERTIES",[...ge.MUTABLE_BASE_PROPERTIES,...ge.INMUTABLE_BASE_PROPERTIES]),f(ge,"MUTABLE_META_PROPERTIES",[...ge.MUTABLE_BASE_PROPERTIES,"x","y"]),f(ge,"INMUTABLE_META_PROPERTIES",[...ge.INMUTABLE_BASE_PROPERTIES]),f(ge,"META_PROPERTIES",[...ge.MUTABLE_META_PROPERTIES,...ge.INMUTABLE_META_PROPERTIES]),f(ge,"MUTABLE_UPSTREAM_PROPERTIES",["extends","implements"]),f(ge,"INMUTABLE_UPSTREAM_PROPERTIES",["parent"]),f(ge,"UPSTREAM_PROPERTIES",[...ge.MUTABLE_UPSTREAM_PROPERTIES,...ge.INMUTABLE_UPSTREAM_PROPERTIES]),f(ge,"MUTABLE_DOWNSTREAM_PROPERTIES",["properties","methods","abstractMethods"]),f(ge,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(ge,"DOWNSTREAM_PROPERTIES",[...ge.MUTABLE_DOWNSTREAM_PROPERTIES,...ge.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(ge,"PROPERTIES",[...ge.META_PROPERTIES,...ge.UPSTREAM_PROPERTIES,...ge.DOWNSTREAM_PROPERTIES]);let nn=ge;function KJ(r){const a=z3(),e=r.toJSON();a.safeParse(e).success;const i=[];return He(r.errors,i)}const Fa=class Fa extends at{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"version");f(this,"name");f(this,"description",null);f(this,"type",n.BuiltInBaseEntity);f(this,"abstract",!1);f(this,"static");f(this,"properties",[]);f(this,"methods",[]);f(this,"abstractMethods",[]);f(this,"extends",[]);f(this,"interactive",!1);f(this,"errors",[]);f(this,"project");this.initialData=this.initialData||e,this.project=this.project||t,this.id=this.id||e.id,this.version=this.version||e.version,this.name=this.name||e.name,this.static=this.static||e.static,this.interactive=this.interactive||e.interactive,this.abstract=e.abstract,this.properties=this.initialData.properties.map(i=>{const s=C(i,this.project);return s.setParent(this,null),s.initChildren(null),s}),this.methods=this.initialData.methods.map(i=>{const s=C(i,this.project);return s.setParent(this,null),s.initChildren(null),s}),this.abstractMethods=this.initialData.abstractMethods.map(i=>{const s=C(i,this.project);return s.setParent(this,null),s.initChildren(null),s}),this.extends=this.initialData.extends.map(i=>C(i,this.project))}get allBasePropertiesFromExtendedAndImplementedEntities(){return p(this.extends.reduce((e,t)=>{const i=[...t.ownDeclaredProperties,...t.allBasePropertiesFromExtendedAndImplementedEntities].filter(s=>!s.abstract);return[...e,...i]},[]))}get extendedPropertiesFromOriginalParents(){return p(this.extends.reduce((e,t)=>{const i=[...t.ownDeclaredProperties,...t.extendedPropertiesFromOriginalParents].filter(s=>!s.abstract);return[...e,...i]},[]))}get implementedPropertiesFromOriginalParents(){return p([...this.extends.reduce((e,t)=>{const i=t.implementedPropertiesFromOriginalParents,s=[...t.ownDeclaredProperties].filter(l=>!!l.abstract&&!i.find(o=>o.name===l.name));return[...i,...s,...e]},[])])}get extendedProperties(){return this.properties.filter(e=>e.isExtendedProperty)}get ownDeclaredProperties(){return this.properties.filter(e=>!e.isExtendedProperty)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}async APILoad(e=g,...t){return await Fa.repository.APILoad(this.id,...t),this}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.properties.flatMap(i=>i.toFlat(e)),...this.methods.flatMap(i=>i.toFlat(e)),...this.abstractMethods.flatMap(i=>i.toFlat(e)),...this.extends.flatMap(i=>i.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.properties.flatMap(i=>i.toFlatIds(e)),...this.methods.flatMap(i=>i.toFlatIds(e)),...this.abstractMethods.flatMap(i=>i.toFlatIds(e)),...this.extends.flatMap(i=>i.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,interactive:this.interactive,abstract:this.abstract,static:this.static,type:this.type,name:this.name}}toJSON(e=new Set){return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,abstract:this.abstract,static:this.static,interactive:this.interactive,properties:this.properties.map(t=>t.toJSON(e)),methods:this.methods.map(t=>t.toJSON(e)),abstractMethods:this.abstractMethods.map(t=>t.toJSON(e)),extends:this.extends.map(t=>t.toJSON(e))})}toReference(e=q){return{id:this.id+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:this.id,version:this.version,entityType:this.type}}toShallowJSON(e=q){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,abstract:this.abstract,static:this.static,interactive:this.interactive,properties:this.properties.map(t=>t.toReference()),methods:this.methods.map(t=>t.toReference()),abstractMethods:this.abstractMethods.map(t=>t.toReference()),extends:this.extends.map(t=>t.toReference())}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.properties.flatMap(i=>i.toFlatJSON(e)),...this.methods.flatMap(i=>i.toFlatJSON(e)),...this.abstractMethods.flatMap(i=>i.toFlatJSON(e))])}toGenerationTarget(){return{id:this.id,type:this.type,name:this.name,description:this.description,static:this.static,abstract:this.abstract,interactive:this.interactive,extends:this.extends.map(e=>e.id)}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.properties.flatMap(i=>i.toFlatGenerationTarget(e)),...this.methods.flatMap(i=>i.toFlatGenerationTarget(e)),...this.abstractMethods.flatMap(i=>i.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.properties.forEach(e=>e.clearErrors()),this.methods.forEach(e=>e.clearErrors()),this.abstractMethods.forEach(e=>e.clearErrors()),this}validate(){const e=KJ(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.properties.flatMap(t=>t.getErrors()),...this.methods.flatMap(t=>t.getErrors()),...this.abstractMethods.flatMap(t=>t.getErrors())]}getShallowErrors(){return this.errors}implement(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),null,!0,"implement-built-in-base-entity")),i){const s=Jl(this,e,t,i);return t==null||t.attemptAutoclose("implement-built-in-base-entity",this.id),s}getAllInteractiveMethods(){const e=[];return this.interactive&&(e.push(...this.methods),this.extends.filter(i=>i.type===n.BuiltInBaseEntity&&i.interactive||i.type===n.PrimitiveEntity).forEach(i=>{i instanceof Fa&&e.push(...i.getAllInteractiveMethods())})),p(e)}};f(Fa,"repository",{APILoad:async(e,...t)=>null});let Ki=Fa;function XJ(r){const a=G3(),e=r.toJSON();a.safeParse(e).success;const i=[];return He(r.errors,i)}const od=class od extends at{constructor(e,t){super(e);f(this,"initialData");f(this,"id");f(this,"name");f(this,"description",null);f(this,"type",n.PrimitiveEntity);f(this,"static");f(this,"abstract");f(this,"properties",[]);f(this,"methods",[]);f(this,"abstractMethods",[]);f(this,"extends",[]);f(this,"errors",[]);f(this,"project");this.initialData=e,this.project=t,this.id=e.id,this.name=e.name,this.static=e.static,this.abstract=e.abstract,this.properties=this.initialData.properties.map(i=>{const s=C(i,this.project);return s.setParent(this,null),s.initChildren(null),s}),this.methods=this.initialData.methods.map(i=>{const s=C(i,this.project);return s.parent=this,s}),this.abstractMethods=this.initialData.abstractMethods.map(i=>{const s=C(i,this.project);return s.parent=this,s})}get allBasePropertiesFromExtendedAndImplementedEntities(){return p(this.extends.reduce((e,t)=>{const i=[...t.ownDeclaredProperties,...t.allBasePropertiesFromExtendedAndImplementedEntities].filter(s=>!s.abstract);return[...e,...i]},[]))}get extendedPropertiesFromOriginalParents(){return p(this.extends.reduce((e,t)=>{const i=[...t.ownDeclaredProperties,...t.extendedPropertiesFromOriginalParents].filter(s=>!s.abstract);return[...e,...i]},[]))}get implementedPropertiesFromOriginalParents(){return p([...this.extends.reduce((e,t)=>{const i=t.implementedPropertiesFromOriginalParents,s=[...t.ownDeclaredProperties].filter(l=>!!l.abstract&&!i.find(o=>o.name===l.name));return[...i,...s,...e]},[])])}get extendedProperties(){return this.properties.filter(e=>e.isExtendedProperty)}get ownDeclaredProperties(){return this.properties.filter(e=>!e.isExtendedProperty)}subscribe(){return this.project.subscribeInstance(this),this}unsubscribe(){return this.project.unsubscribeInstance(this),this}async APILoad(e=g,...t){return await od.repository.APILoad(this.id,...t),this}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.properties.flatMap(i=>i.toFlat(e)),...this.methods.flatMap(i=>i.toFlat(e)),...this.abstractMethods.flatMap(i=>i.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.properties.flatMap(i=>i.toFlatIds(e)),...this.methods.flatMap(i=>i.toFlatIds(e)),...this.abstractMethods.flatMap(i=>i.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,static:this.static,abstract:this.abstract,type:this.type,name:this.name}}toJSON(e=new Set){return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,static:this.static,abstract:this.abstract,properties:this.properties.map(t=>t.toJSON(e)),methods:this.methods.map(t=>t.toJSON(e)),abstractMethods:this.abstractMethods.map(t=>t.toJSON(e)),extends:this.extends.map(t=>t.toJSON(e))})}toReference(e=q){return{id:this.id+"--"+m.UUID.uuid()+"--ref",type:n.GenericReference,entityId:this.id,version:this.version,entityType:this.type}}toShallowJSON(e=q){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,abstract:this.abstract,static:this.static,properties:this.properties.map(t=>t.toReference()),methods:this.methods.map(t=>t.toReference()),abstractMethods:this.abstractMethods.map(t=>t.toReference()),extends:this.extends.map(t=>t.toReference())}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.properties.flatMap(i=>i.toFlatJSON(e)),...this.methods.flatMap(i=>i.toFlatJSON(e)),...this.abstractMethods.flatMap(i=>i.toFlatJSON(e))])}toGenerationTarget(){return{id:this.id,type:this.type,name:this.name,description:this.description,static:this.static,abstract:this.abstract,extends:this.extends.map(e=>e.id)}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toGenerationTarget(),...this.properties.flatMap(i=>i.toFlatGenerationTarget(e)),...this.methods.flatMap(i=>i.toFlatGenerationTarget(e)),...this.abstractMethods.flatMap(i=>i.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.properties.forEach(e=>e.clearErrors()),this.methods.forEach(e=>e.clearErrors()),this.abstractMethods.forEach(e=>e.clearErrors()),this}validate(){const e=XJ(this);return this.errors=e,{success:!0,error:null,data:this.toJSON()}}getErrors(){return[...this.errors,...this.properties.flatMap(t=>t.getErrors()),...this.methods.flatMap(t=>t.getErrors()),...this.abstractMethods.flatMap(t=>t.getErrors())]}getShallowErrors(){return this.errors}getAllInteractiveMethods(){const e=[];return e.push(...this.methods),this.extends.filter(i=>i.type===n.BuiltInBaseEntity&&i.interactive||i.type===n.PrimitiveEntity).forEach(i=>{i instanceof Ki&&e.push(...i.getAllInteractiveMethods())}),p(e)}};f(od,"repository",{APILoad:async(e,...t)=>null});let Qt=od;function ct(r,a){if(!r)throw new Error("Entity is null");const e=a.get(r.id);switch(r.type){case n.LiteralValue:return e||new Hr(r,a);case n.DefinitionEntity:return e||new nn(r,a);case n.PrimitiveEntity:return e||new Qt(r,a);case n.FunctionDeclaration:return e||new jr(r,a);case n.GlobalEvent:return e||new Fr(r,a);case n.DataType:return e||new $r(r,a);case n.Property:return e||new Ur(r,a);case n.FunctionCall:return e||new en(r,a);case n.Condition:return e||new Sr(r,a);case n.Operation:return e||new Gr(r,a);case n.VariableDeclaration:return e||new qr(r,a);case n.VariableInstance:return e||new Zr(r,a);case n.OutputMap:return e||new zi(r,a);case n.ReturnDeclaration:return e||new ai(r,a);case n.ArgumentDeclaration:return e||new Yr(r,a);case n.InputMap:return e||new Wi(r,a);case n.Project:return e||new m(r);case n.InstalledProject:return e||new Wr(r,a);case n.ActionDescriptor:return e||new Je(r,a);case n.ReturnStatement:return e||new gr(r,a);case n.Loop:return e||new kr(r,a);case n.Search:return e||new Jr(r,a);case n.ValueDescriptor:return e||new mr(r,a);case n.BuiltInBaseEntity:return e||new Ki(r,a);case n.InternalCall:return e||new zr(r,a);case n.ContinueStatement:return e||new Lt(r,a);case n.BreakStatement:return e||new xr(r,a);case n.GenericReference:return a.get(r.entityId);default:throw new Error("Invalid entity type: "+r.type)}}function C(r,a){if(!r)throw new Error("Entity is null");const e=ct(r,a);return e.subscribe(),e}function QJ(r,a){if(!r)throw new Error("Entity is null");switch(r.type){case n.LiteralValue:return Hr.fromGenerationTarget(r,a);case n.DefinitionEntity:return nn.fromGenerationTarget(r,a);case n.FunctionDeclaration:return jr.fromGenerationTarget(r,a);case n.GlobalEvent:return Fr.fromGenerationTarget(r,a);case n.DataType:return $r.fromGenerationTarget(r,a);case n.Property:return Ur.fromGenerationTarget(r,a);case n.FunctionCall:return en.fromGenerationTarget(r,a);case n.Condition:return Sr.fromGenerationTarget(r,a);case n.Operation:return Gr.fromGenerationTarget(r,a);case n.VariableDeclaration:return qr.fromGenerationTarget(r,a);case n.VariableInstance:return Zr.fromGenerationTarget(r,a);case n.OutputMap:return zi.fromGenerationTarget(r,a);case n.ReturnDeclaration:return ai.fromGenerationTarget(r,a);case n.ArgumentDeclaration:return Yr.fromGenerationTarget(r,a);case n.InputMap:return Wi.fromGenerationTarget(r,a);case n.InstalledProject:return Wr.fromGenerationTarget(r,a);case n.ReturnStatement:return gr.fromGenerationTarget(r,a);case n.Loop:return kr.fromGenerationTarget(r,a);case n.Search:return Jr.fromGenerationTarget(r,a);case n.ActionDescriptor:return Je.fromGenerationTarget(r,a);case n.ValueDescriptor:return mr.fromGenerationTarget(r,a);case n.InternalCall:return zr.fromGenerationTarget(r,a);case n.ContinueStatement:return Lt.fromGenerationTarget(r,a);case n.BreakStatement:return xr.fromGenerationTarget(r,a);default:throw new Error("Invalid entity type: "+r.type)}}const q={seenEntityMaps:new Map,seenEntities:new Set,timestamp:T().toISOString()};class nw{constructor(){f(this,"initialData")}}const g={cascade:!1},sw={APILoad:async(r,...a)=>null},eW={APICreate:async(r,...a)=>r,APIUpdate:async(r,...a)=>r,APIDelete:async(r,...a)=>r,APIClone:async(r,...a)=>{},APILoadVersion:async(r,a,...e)=>null,...sw};class tW{}class iW extends nw{}class rW{}class nW{}class sW{}class nf{}class aW extends nf{}class oW extends nf{}class lW{}class Ir{static initReadsValue(a){if(a.initialData.readsValue&&a.initialData.readsValue.type!==n.GenericReference)a.readsValue=C(a.initialData.readsValue,a.project);else if(a.initialData.readsValue&&a.initialData.readsValue.type===n.GenericReference){const e=mi(a.initialData.readsValue,a.project);e&&(a.readsValue=e)}if(a.readsValue){if(tt.includes(a.readsValue.type)){let e=a.parent;dt.includes(e.type)||(e=e.parent);const t=a.type===n.InputMap&&a.parent.type===n.Loop;t&&(e=a.parent.parent),a.readsValue.setParent(e,null),a.readsValue.initChildren(null),!t&&e.detachedChildren.includes(a)?e.replaceDetachedChild(a,a.readsValue):t||e.subscribeDetachedChild(a.readsValue)}a.readsValue.addValueReader(a,null)}return a.readsValue}static hydrateReadsValue(a){if(a.initialData.readsValue&&a.initialData.readsValue.type!==n.GenericReference)a.readsValue=C(a.initialData.readsValue,a.project);else if(a.initialData.readsValue&&a.initialData.readsValue.type===n.GenericReference){const e=mi(a.initialData.readsValue,a.project);e&&(a.readsValue=e)}if(a.readsValue){if(tt.includes(a.readsValue.type)){let e=a.parent;dt.includes(e.type)||(e=e.parent);const t=a.type===n.InputMap&&a.parent.type===n.Loop;t&&(e=a.parent.parent),a.readsValue.setParent(e,null),!t&&e.detachedChildren.includes(a)?e.replaceDetachedChild(a,a.readsValue):t||e.subscribeDetachedChild(a.readsValue)}a.readsValue.addValueReader(a,null)}return a.readsValue}}class $a{static initWritesValues(a,e){const t=a.initialData.writesValues.reduce((s,l)=>{if(l.type===n.GenericReference||a.writesValues.some(d=>d.id===l.id))return s;const o=C(l,a.project);return o.setValueWriter(a,null),tt.includes(o.type)&&(o.setParent(e,null),o.initChildren(null)),[...s,o]},[]),i=[...a.writesValues];return a.writesValues=p([...i,...t]),a.writesValues}}class dW{}const ae=class ae extends at{constructor(e){super(e);f(this,"initialData");f(this,"id");f(this,"type",n.Project);f(this,"name",null);f(this,"description",null);f(this,"x");f(this,"y");f(this,"entities",[]);f(this,"projects",[]);f(this,"functions",[]);f(this,"events",[]);f(this,"variableDeclarations",[]);f(this,"variableInstances",[]);f(this,"conditions",[]);f(this,"operations",[]);f(this,"functionCalls",[]);f(this,"loops",[]);f(this,"searches",[]);f(this,"primitives",[]);f(this,"builtInBaseEntities",[]);f(this,"operationDeclarations",[]);f(this,"globalEventActionDescriptors",[]);f(this,"loopDeclarations",[]);f(this,"loopDeclarationsBodies",[]);f(this,"conditionDeclarations",[]);f(this,"valueDescriptors",[]);f(this,"dataTypes",[]);f(this,"project");f(this,"instances",{});f(this,"builtInInstances",{});f(this,"deletedInstances",{});f(this,"errors",[]);f(this,"references",[]);f(this,"history",[]);f(this,"detachedDependents",{});f(this,"knownVersions",null);f(this,"activeVersion",!1);f(this,"initialized",!1);f(this,"startedInitialization",!1);f(this,"onCloseChangeSetCallback",null);this.initialData=e,this.id=e.id,this.name=e.name,this.description=e.description,this.x=0,this.y=0,this.instances[this.id]=this;try{(!ae.UUID||ae.UUID.isBackup)&&(ae.UUID=xo==null?void 0:xo()),ae.UUID||(ae.UUID={isBackup:!0,uuid:()=>Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15),fromUUID:t=>t})}catch(t){console.error("Error initializing UUID module",t),ae.UUID={isBackup:!0,uuid:()=>Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15),fromUUID:i=>i}}}static injectUUIDModule(e){ae.UUID=e}static validateGenerationTarget(e,t){let i=JSON.parse(JSON.stringify(e));const s=[];return s.push(...ut(i)),{errors:s,modifiedData:i}}async closePendingCallbacks(){for(let e=0;e<this.history.length;e++){const t=this.history[e];t.dirty&&await t.closeAsync()}}async onCloseChangeSet(e){this.onCloseChangeSetCallback=e,await this.closePendingCallbacks()}async closeChangeSet(e){if(this.onCloseChangeSetCallback){const t=await this.onCloseChangeSetCallback(e);return t.success&&(e.dirty=!1),t}return{success:!1}}toLatestChangeSet(e,t,i,s=!1,l="here-this"){if(!this.history.length)return new b(this,e,t,i,s,l);const o=this.history[this.history.length-1];return o.open?o:this.addChangeSet(new b(this,e,t,i,s,l))}addChangeSet(e){if(!this.history.length)return this.history.push(e),e;const t=this.history.find(l=>l.id===(e==null?void 0:e.id));if(t)return t;const i=this.history.find(l=>l.open);if(i)throw console.log("previouslyStillOpen: ",i),console.log("new change set: ",e),new Error(`There is already an open change-set with id '${i.id}'.`);const s=this.history.findIndex(l=>T(l.timestamp).isBefore(T(e==null?void 0:e.timestamp)));return s===-1?this.history.push(e):this.history.splice(s,0,e),e}discardChangeSet(e){const t=this.history.findIndex(i=>i.id===(e==null?void 0:e.id));return t!==-1&&this.history.splice(t,1),this}undo(){const e=[],t=[],i=[],s=[];return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}redo(){const e=[],t=[],i=[],s=[];return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}async inject(...e){return await Promise.all(e.map(t=>new Promise(async i=>{await t.init(this),i(null)}))),this}validateGeneratedUpdate(e){return{errors:[],modifiedData:e}}subscribeDependents(e){return e.forEach(t=>{this.detachedDependents[t.entity.id]||(this.detachedDependents[t.entity.id]=t)}),this}syncDependents(){const e=[],t=[],i=[],s=[];return Object.values(this.detachedDependents).forEach(l=>{const o=l.entity.afterAllChildrenInitialized();e.push(...o.updated),t.push(...o.added),i.push(...o.removed),s.push(...o.affected)}),{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}onDetachedDependencyRemoved(e,t,i){const s=[],l=[],o=[],d=[];return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}onDetachedDependencyRestored(e,t,i){const s=[],l=[],o=[],d=[];return{updated:p(s),added:p(l),removed:p(o),affected:p(d),self:this}}subscribeToDependencies(){return this}increaseVersion(e){if(e&&!T(e).isValid())throw new Error(`The shared timestamp '${e}' is not a valid ISO 8601 date string.`);return e&&T(e).isSame(T(this.createdAt))?this:(this.previousVersion=this.version,this.version=ae.UUID.uuid(),this.createdAt=T(e).toISOString()||T().toISOString(),this)}captureVersion(){var t;const e=((t=this.knownVersions)==null?void 0:t.get(this.version))||new ae(this);return e.metaSync(this.toMeta(),null),this.knownVersions=this.knownVersions?this.knownVersions.set(this.version,e):new Map([[this.version,e]]),e.entities=this.entities,e.projects=this.projects,e.functions=this.functions,e.events=this.events,e.variableDeclarations=this.variableDeclarations,e.variableInstances=this.variableInstances,e.conditions=this.conditions,e.operations=this.operations,e.functionCalls=this.functionCalls,e.loops=this.loops,e.searches=this.searches,this}recursiveCaptureUpstreamVersions(e){const t=[],i=[],s=[],l=[];return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}async restoreVersion(e){var d;const t=[],i=[],s=[],l=[];if(this.version===e)return{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this};if(!this.knownVersions){const u=new Map;for(const[y,c]of this.knownVersions||new Map){if(u.set(y,c),c.activeVersion=!1,c.knownVersions)for(const[I,E]of c.knownVersions)u.set(I,E);c.knownVersions=null}}let o=(d=this.knownVersions)==null?void 0:d.get(e);if(!o){const u=await this.APILoadVersion({},e);if(!u)throw new Error(`Version with id '${e}' for entity with id '${this.id}' not found.`);o=new ae(u)}return this.metaSync(o.toShallowJSON(),null),this.entities=o.entities,this.projects=o.projects,this.functions=o.functions,this.events=o.events,this.variableDeclarations=o.variableDeclarations,this.variableInstances=o.variableInstances,this.conditions=o.conditions,this.operations=o.operations,this.functionCalls=o.functionCalls,this.loops=o.loops,this.searches=o.searches,{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}hydrateAncestors(){const e=[],t=[],i=[],s=[];return{updated:p(e),added:p(t),removed:p(i),affected:p(s),self:this}}afterAllChildrenInitialized(e=null){const t=[],i=[],s=[],l=[];return this.initialized=!0,this.captureVersion(),this.validate(),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}addSelfToProject(e){const t=[],i=[],s=[],l=[];return this.subscribe(),this.subscribeToDependencies(),{updated:p(t),added:p(i),removed:p(s),affected:p(l),self:this}}get instancesList(){return Object.values(this.instances)}isOperationDeclaration(e){return this.operationDeclarations.includes(e)}isGlobalEventActionDescriptor(e){return this.globalEventActionDescriptors.includes(e)}isLoopDeclaration(e){return this.loopDeclarations.includes(e)}isConditionDeclaration(e){return this.conditionDeclarations.includes(e)}initChildren(e=this.project.addChangeSet(new b(this.project,ae.sessionAuthor,T().toISOString(),this,!0,"init-children"))){return this.initialized||this.startedInitialization?this:(this.startedInitialization=!0,this.entities=this.initialData.entities.map(t=>{const i=C(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.projects=this.initialData.projects.map(t=>{const i=C(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.variableDeclarations=this.initialData.variableDeclarations.map(t=>{const i=C(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.variableInstances=this.initialData.variableInstances.map(t=>{const i=C(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.conditions=this.initialData.conditions.map(t=>{const i=C(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.operations=this.initialData.operations.map(t=>{const i=C(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.functions=this.initialData.functions.map(t=>{const i=C(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.events=this.initialData.events.map(t=>{const i=C(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.functionCalls=this.initialData.functionCalls.map(t=>{const i=C(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.loops=this.initialData.loops.map(t=>{const i=C(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.searches=this.initialData.searches.map(t=>{const i=C(t,this);return i.setParent(this,null),i.initChildren(e),i}),this.attachOrphanReferences(),this.subscribeToDependencies(),this.afterAllChildrenInitialized(e),e==null||e.attemptAutoclose("init-children",this.id),this)}subscribeInstance(e){return(!this.instances[e.id]||this.instances[e.id]!==e)&&(this.instances[e.id]=e),this}subscribeDeletedInstance(e){return(!this.deletedInstances[e.id]||this.deletedInstances[e.id]!==e)&&(this.deletedInstances[e.id]=e),this}subscribeBuiltInInstance(e){return(!this.builtInInstances[e.id]||this.builtInInstances[e.id]!==e)&&(this.builtInInstances[e.id]=e),this}subscribe(){return this}unsubscribe(){return this}unsubscribeInstance(e){return delete this.instances[e.id],this}unsubscribeDeletedInstance(e){return delete this.deletedInstances[e.id],this}findSubscribedBuiltInInstance(e){return this.builtInInstances[e.id]||null}get(e){return this.instances[e]||this.builtInInstances[e]||null}getDeleted(e){return this.deletedInstances[e]||null}getManaged(e){return this.getBuiltIn(e)?null:this.instances[e]||null}getBuiltIn(e){return this.builtInInstances[e]||null}findSubscribedInstanceFromReference(e){return this.instances[e.entityId]||null}findSubscribedBuiltInInstanceFromReference(e){return this.builtInInstances[e.entityId]||null}metaSync(e,t=this.project.addChangeSet(new b(this.project,ae.sessionAuthor,T().toISOString(),this,!0,"meta-sync"))){const i=pt(this,e),s=this.toMeta();return this.name=e.name||s.name,this.description=e.description||s.description,this.x=e.x||s.x,this.y=e.y||s.y,super.metaSync(e),e.deleted===!0&&!s.deleted?t==null||t.add(this,A.Removed):e.deleted===!1&&s.deleted?t==null||t.add(this,A.Added):i&&(t==null||t.add(this,A.Updated)),t==null||t.attemptAutoclose("meta-sync",this.id),this}async APILoad(e=g,...t){return await ae.repository.APILoad(this.id,...t),this}async APICreate(e=g,...t){return await ae.repository.APICreate(this.toShallowJSON(),...t),this}async APIUpdate(e=g,...t){return await ae.repository.APIUpdate(this.toShallowJSON(),...t),this}async APIDelete(e=g,...t){return await ae.repository.APIDelete(this.toShallowJSON(),...t),this}async APIClone(e=g,...t){return await ae.repository.APIClone(this.id,...t),this}async APILoadVersion(e=g,t,...i){return await ae.repository.APILoadVersion(this.id,t,...i)}remove({ignoreUpstream:e}={ignoreUpstream:!1},t=this.project.addChangeSet(new b(this.project,ae.sessionAuthor,T().toISOString(),this,!0,"remove-entity"))){return{added:[],updated:[],removed:[],affected:[],self:this}}restore({}={},e=this.project.addChangeSet(new b(this.project,ae.sessionAuthor,T().toISOString(),this,!0,"restore-entity"))){return{added:[],updated:[],removed:[],affected:[],self:this}}getAllBuiltInIds(){const e=new Set;return[...this.primitives.flatMap(t=>t.toFlatIds(e)),...this.builtInBaseEntities.flatMap(t=>t.toFlatIds(e)),...this.operationDeclarations.flatMap(t=>t.toFlatIds(e)),...this.globalEventActionDescriptors.flatMap(t=>t.toFlatIds(e)),...this.loopDeclarations.flatMap(t=>t.toFlatIds(e)),...this.conditionDeclarations.flatMap(t=>t.toFlatIds(e)),...this.valueDescriptors.flatMap(t=>t.toFlatIds(e)),...this.dataTypes.flatMap(t=>t.toFlatIds(e))]}getAllBuiltIn(){const e=new Set;return[...this.primitives.flatMap(t=>t.toFlat(e)),...this.builtInBaseEntities.flatMap(t=>t.toFlat(e)),...this.operationDeclarations.flatMap(t=>t.toFlat(e)),...this.globalEventActionDescriptors.flatMap(t=>t.toFlat(e)),...this.loopDeclarations.flatMap(t=>t.toFlat(e)),...this.conditionDeclarations.flatMap(t=>t.toFlat(e)),...this.valueDescriptors.flatMap(t=>t.toFlat(e)),...this.dataTypes.flatMap(t=>t.toFlat(e))]}toFlat(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this,...this.entities.flatMap(i=>i.toFlat(e)),...this.functions.flatMap(i=>i.toFlat(e)),...this.events.flatMap(i=>i.toFlat(e)),...this.projects.flatMap(i=>i.toFlat(e)),...this.variableDeclarations.flatMap(i=>i.toFlat(e)),...this.variableInstances.flatMap(i=>i.toFlat(e)),...this.conditions.flatMap(i=>i.toFlat(e)),...this.operations.flatMap(i=>i.toFlat(e)),...this.functionCalls.flatMap(i=>i.toFlat(e)),...this.loops.flatMap(i=>i.toFlat(e)),...this.searches.flatMap(i=>i.toFlat(e))])}toFlatIds(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.id,...this.entities.flatMap(i=>i.toFlatIds(e)),...this.functions.flatMap(i=>i.toFlatIds(e)),...this.events.flatMap(i=>i.toFlatIds(e)),...this.projects.flatMap(i=>i.toFlatIds(e)),...this.variableDeclarations.flatMap(i=>i.toFlatIds(e)),...this.variableInstances.flatMap(i=>i.toFlatIds(e)),...this.conditions.flatMap(i=>i.toFlatIds(e)),...this.operations.flatMap(i=>i.toFlatIds(e)),...this.functionCalls.flatMap(i=>i.toFlatIds(e)),...this.loops.flatMap(i=>i.toFlatIds(e)),...this.searches.flatMap(i=>i.toFlatIds(e))])}toMeta(){return{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,description:this.description,type:this.type,name:this.name}}toJSON(e=new Set){return e.has(this.id)?this.toReference():(e.add(this.id),{id:this.id,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,entities:this.entities.map(t=>t.toJSON(e)),variableDeclarations:this.variableDeclarations.map(t=>t.toJSON(e)),variableInstances:this.variableInstances.map(t=>t.toJSON(e)),conditions:this.conditions.map(t=>t.toJSON(e)),operations:this.operations.map(t=>t.toJSON(e)),loops:this.loops.map(t=>t.toJSON(e)),searches:this.searches.map(t=>t.toJSON(e)),functions:this.functions.map(t=>t.toJSON(e)),events:this.events.map(t=>t.toJSON(e)),projects:this.projects.map(t=>t.toJSON(e)),functionCalls:this.functionCalls.map(t=>t.toJSON(e))})}toJSONClone(e={uuidStrategy:"uuid"}){const t=new Map,i=new Set,s=this.getAllBuiltInIds();return Object.keys(this.instances).forEach(l=>{if(s.includes(l)){t.set(l,l);return}t.set(l,ae.UUID.uuid())}),i.add(this.id),{id:t.get(this.id),version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,entities:this.entities.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),projects:this.projects.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),variableDeclarations:this.variableDeclarations.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),variableInstances:this.variableInstances.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),conditions:this.conditions.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),operations:this.operations.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),functions:this.functions.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),events:this.events.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),functionCalls:this.functionCalls.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),loops:this.loops.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null})),searches:this.searches.map(l=>l.toJSONClone({...e,seenEntityMaps:t,seenEntities:i,newId:null}))}}toReference(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t+"--"+ae.UUID.uuid()+"--ref",type:n.GenericReference,entityId:t,version:this.version,entityType:this.type}}toShallowJSON(e=q){var i;let t=this.id;return(i=e.seenEntityMaps)!=null&&i.has(this.id)&&(t=e.seenEntityMaps.get(this.id)),{id:t,version:this.version,createdAt:this.createdAt,previousVersion:this.previousVersion,author:this.author,deleted:this.deleted,type:this.type,name:this.name,description:this.description,entities:this.entities.map(s=>s.toReference(e)),functions:this.functions.map(s=>s.toReference(e)),events:this.events.map(s=>s.toReference(e)),projects:this.projects.map(s=>s.toReference(e)),variableDeclarations:this.variableDeclarations.map(s=>s.toReference(e)),variableInstances:this.variableInstances.map(s=>s.toReference(e)),conditions:this.conditions.map(s=>s.toReference(e)),operations:this.operations.map(s=>s.toReference(e)),functionCalls:this.functionCalls.map(s=>s.toReference(e)),loops:this.loops.map(s=>s.toReference(e)),searches:this.searches.map(s=>s.toReference(e))}}toFlatJSON(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[this.toShallowJSON(),...this.entities.flatMap(i=>i.toFlatJSON(e)),...this.functions.flatMap(i=>i.toFlatJSON(e)),...this.events.flatMap(i=>i.toFlatJSON(e)),...this.projects.flatMap(i=>i.toFlatJSON(e)),...this.variableDeclarations.flatMap(i=>i.toFlatJSON(e)),...this.variableInstances.flatMap(i=>i.toFlatJSON(e)),...this.conditions.flatMap(i=>i.toFlatJSON(e)),...this.operations.flatMap(i=>i.toFlatJSON(e)),...this.functionCalls.flatMap(i=>i.toFlatJSON(e)),...this.loops.flatMap(i=>i.toFlatJSON(e)),...this.searches.flatMap(i=>i.toFlatJSON(e))])}toGenerationTarget(){return{id:this.id,type:this.type,name:this.name,description:this.description}}toFlatGenerationTarget(e=new Set){return e.has(this.id)?[]:(e.add(this.id),[...this.entities.flatMap(i=>i.toFlatGenerationTarget(e)),...this.functions.flatMap(i=>i.toFlatGenerationTarget(e)),...this.events.flatMap(i=>i.toFlatGenerationTarget(e)),...this.projects.flatMap(i=>i.toFlatGenerationTarget(e)),...this.variableDeclarations.flatMap(i=>i.toFlatGenerationTarget(e)),...this.variableInstances.flatMap(i=>i.toFlatGenerationTarget(e)),...this.conditions.flatMap(i=>i.toFlatGenerationTarget(e)),...this.operations.flatMap(i=>i.toFlatGenerationTarget(e)),...this.functionCalls.flatMap(i=>i.toFlatGenerationTarget(e)),...this.loops.flatMap(i=>i.toFlatGenerationTarget(e)),...this.searches.flatMap(i=>i.toFlatGenerationTarget(e))])}clearErrors(){return this.errors=[],this.entities.forEach(e=>e.clearErrors()),this.projects.forEach(e=>e.clearErrors()),this.functions.forEach(e=>e.clearErrors()),this.events.forEach(e=>e.clearErrors()),this.variableDeclarations.forEach(e=>e.clearErrors()),this.variableInstances.forEach(e=>e.clearErrors()),this.conditions.forEach(e=>e.clearErrors()),this.operations.forEach(e=>e.clearErrors()),this.functionCalls.forEach(e=>e.clearErrors()),this.loops.forEach(e=>e.clearErrors()),this.searches.forEach(e=>e.clearErrors()),this}validate(){const e=uZ(),t=this.toJSON();return e.safeParse(t),this.validateChildren(),{success:!0,error:null,data:t}}validateChildren(){this.entities.forEach(e=>e.validate()),this.projects.forEach(e=>e.validate()),this.functions.forEach(e=>e.validate()),this.events.forEach(e=>e.validate()),this.variableDeclarations.forEach(e=>e.validate()),this.variableInstances.forEach(e=>e.validate()),this.conditions.forEach(e=>e.validate()),this.operations.forEach(e=>e.validate()),this.functionCalls.forEach(e=>e.validate()),this.loops.forEach(e=>e.validate()),this.searches.forEach(e=>e.validate())}getErrors(){return[...this.errors,...this.entities.flatMap(t=>t.getErrors()),...this.projects.flatMap(t=>t.getErrors()),...this.functions.flatMap(t=>t.getErrors()),...this.events.flatMap(t=>t.getErrors()),...this.variableDeclarations.flatMap(t=>t.getErrors()),...this.variableInstances.flatMap(t=>t.getErrors()),...this.conditions.flatMap(t=>t.getErrors()),...this.operations.flatMap(t=>t.getErrors()),...this.functionCalls.flatMap(t=>t.getErrors()),...this.loops.flatMap(t=>t.getErrors()),...this.searches.flatMap(t=>t.getErrors())]}getShallowErrors(){return this.errors}clone(){return this}getDefinitionEntity(e){return this.entities.find(t=>t.id===e)||null}addDefinitionEntityFromTransfer(e){const t=C(e,this);return this.addDefinitionEntity(t),t}addDefinitionEntity(e){return this.entities.includes(e)||this.entities.push(e),e}addFunctionDeclarationFromTransfer(e){const t=C(e,this);return this.addFunctionDeclaration(t),t}addFunctionDeclaration(e){return this.functions.includes(e)||this.functions.push(e),e}addFunctionCallFromTransfer(e){const t=C(e,this);return this.addFunctionCall(t),t}addFunctionCall(e){return this.functionCalls.includes(e)||this.functionCalls.push(e),e}addVariableDeclarationFromTransfer(e){const t=C(e,this);return this.addVariableDeclaration(t),t}addVariableDeclaration(e){return this.variableDeclarations.includes(e)||this.variableDeclarations.push(e),e}addVariableInstanceFromTransfer(e){const t=C(e,this);return this.addVariableInstance(t),t}addVariableInstance(e){return this.variableInstances.includes(e)||this.variableInstances.push(e),e}addInstalledProjectFromTransfer(e){const t=C(e,this);return this.addInstalledProject(t),this}addInstalledProject(e){return this.projects.includes(e)||this.projects.push(e),this}addGlobalEventFromTransfer(e){const t=C(e,this);return this.addGlobalEvent(t),this}addGlobalEvent(e){return this.events.includes(e)||this.events.push(e),this}addConditionFromTransfer(e){const t=C(e,this);return this.addCondition(t),this}addCondition(e){return this.conditions.includes(e)||this.conditions.push(e),this}addOperationFromTransfer(e){const t=C(e,this);return this.addOperation(t),this}addOperation(e){return this.operations.includes(e)||this.operations.push(e),this}addLoopFromTransfer(e){const t=C(e,this);return this.addLoop(t),this}addLoop(e){return this.loops.includes(e)||this.loops.push(e),this}addSearchFromTransfer(e){const t=C(e,this);return this.addSearch(t),this}addSearch(e){return this.searches.includes(e)||this.searches.push(e),this}removeDefinitionEntity(e){const t=this.entities.findIndex(i=>i.id===e.id);if(t>-1){const i=this.entities[t];return this.entities.splice(t,1),i}return null}removeFunctionDeclaration(e){const t=this.functions.findIndex(i=>i.id===e.id);if(t>-1){const i=this.functions[t];return this.functions.splice(t,1),i}return null}removeExternalProject(e){const t=this.projects.findIndex(i=>i.id===e.id);if(t>-1){const i=this.projects[t];return this.projects.splice(t,1),i}return null}removeGlobalEvent(e){const t=this.events.findIndex(i=>i.id===e.id);if(t>-1){const i=this.events[t];return this.events.splice(t,1),i}return null}removeTopLevelVariableDeclaration(e){if(e.type!==n.VariableDeclaration)return null;const t=this.variableDeclarations.findIndex(i=>i.id===e.id);if(t>-1){const i=this.variableDeclarations[t];return this.variableDeclarations.splice(t,1),i}return null}getEntryPoints(){return[...this.functions,...this.events,...this.entities.flatMap(t=>t.methods)]}getTerminationStatements(){return[...this.getEntryPoints().reduce((t,i)=>{const s=qe(i);return[...t,...s.filter(l=>l.type===n.ReturnStatement||l.type===n.ContinueStatement||l.type===n.BreakStatement)]},[])]}getFunctionDeclaration(e){return this.functions.find(t=>t.id===e)||null}getConditions(){return[...this.conditions,...this.getEntryPoints().reduce((t,i)=>{const s=qe(i);return[...t,...s.filter(l=>l.type===n.Condition)]},[]),...this.functionCalls.reduce((t,i)=>{const s=qe(i);return[...t,...s.filter(l=>l.type===n.Condition)]},[]),...this.operations.reduce((t,i)=>{const s=qe(i);return[...t,...s.filter(l=>l.type===n.Condition)]},[]),...this.loops.reduce((t,i)=>{const s=qe(i);return[...t,...s.filter(l=>l.type===n.Condition)]},[]),...this.searches.reduce((t,i)=>{const s=qe(i);return[...t,...s.filter(l=>l.type===n.Condition)]},[])]}getOperations(){return[...this.operations,...this.getEntryPoints().reduce((t,i)=>{const s=qe(i);return[...t,...s.filter(l=>l.type===n.Operation)]},[]),...this.functionCalls.reduce((t,i)=>{const s=qe(i);return[...t,...s.filter(l=>l.type===n.Operation)]},[]),...this.conditions.reduce((t,i)=>{const s=qe(i);return[...t,...s.filter(l=>l.type===n.Operation)]},[]),...this.loops.reduce((t,i)=>{const s=qe(i);return[...t,...s.filter(l=>l.type===n.Operation)]},[]),...this.searches.reduce((t,i)=>{const s=qe(i);return[...t,...s.filter(l=>l.type===n.Operation)]},[])]}getFunctionCalls(){return[...this.functionCalls,...this.getEntryPoints().reduce((t,i)=>{const s=qe(i);return[...t,...s.filter(l=>l.type===n.FunctionCall)]},[]),...this.conditions.reduce((t,i)=>{const s=qe(i);return[...t,...s.filter(l=>l.type===n.FunctionCall)]},[]),...this.operations.reduce((t,i)=>{const s=qe(i);return[...t,...s.filter(l=>l.type===n.FunctionCall)]},[]),...this.loops.reduce((t,i)=>{const s=qe(i);return[...t,...s.filter(l=>l.type===n.FunctionCall)]},[]),...this.searches.reduce((t,i)=>{const s=qe(i);return[...t,...s.filter(l=>l.type===n.FunctionCall)]},[])]}getVariables(){return[...this.variableDeclarations,...this.getEntryPoints().reduce((t,i)=>{const s=Ye(i);return[...t,...s]},[]),...this.functionCalls.reduce((t,i)=>{const s=Ye(i);return[...t,...s]},[]),...this.conditions.reduce((t,i)=>{const s=Ye(i);return[...t,...s]},[]),...this.operations.reduce((t,i)=>{const s=Ye(i);return[...t,...s]},[]),...this.loops.reduce((t,i)=>{const s=Ye(i);return[...t,...s]},[]),...this.searches.reduce((t,i)=>{const s=Ye(i);return[...t,...s]},[])]}getVariableInstances(){return[...this.variableInstances,...this.getEntryPoints().reduce((t,i)=>{const l=Ye(i).filter(o=>o.type===n.VariableInstance);return[...t,...l]},[]),...this.functionCalls.reduce((t,i)=>{const l=Ye(i).filter(o=>o.type===n.VariableInstance);return[...t,...l]},[]),...this.conditions.reduce((t,i)=>{const l=Ye(i).filter(o=>o.type===n.VariableInstance);return[...t,...l]},[]),...this.operations.reduce((t,i)=>{const l=Ye(i).filter(o=>o.type===n.VariableInstance);return[...t,...l]},[]),...this.loops.reduce((t,i)=>{const l=Ye(i).filter(o=>o.type===n.VariableInstance);return[...t,...l]},[]),...this.searches.reduce((t,i)=>{const l=Ye(i).filter(o=>o.type===n.VariableInstance);return[...t,...l]},[])]}getVariableDeclarations(){return p([...this.variableDeclarations,...this.getEntryPoints().reduce((t,i)=>{const l=Ye(i).filter(o=>o.type===n.VariableDeclaration);return[...t,...l]},[]),...this.functionCalls.reduce((t,i)=>{const l=Ye(i).filter(o=>o.type===n.VariableDeclaration);return[...t,...l]},[]),...this.conditions.reduce((t,i)=>{const l=Ye(i).filter(o=>o.type===n.VariableDeclaration);return[...t,...l]},[]),...this.operations.reduce((t,i)=>{const l=Ye(i).filter(o=>o.type===n.VariableDeclaration);return[...t,...l]},[]),...this.loops.reduce((t,i)=>{const l=Ye(i).filter(o=>o.type===n.VariableDeclaration);return[...t,...l]},[]),...this.searches.reduce((t,i)=>{const l=Ye(i).filter(o=>o.type===n.VariableDeclaration);return[...t,...l]},[])])}getLoops(){return[...this.loops,...this.getEntryPoints().reduce((t,i)=>{const s=qe(i);return[...t,...s.filter(l=>l.type===n.Loop)]},[]),...this.functionCalls.reduce((t,i)=>{const s=qe(i);return[...t,...s.filter(l=>l.type===n.Loop)]},[]),...this.conditions.reduce((t,i)=>{const s=qe(i);return[...t,...s.filter(l=>l.type===n.Loop)]},[]),...this.operations.reduce((t,i)=>{const s=qe(i);return[...t,...s.filter(l=>l.type===n.Loop)]},[]),...this.searches.reduce((t,i)=>{const s=qe(i);return[...t,...s.filter(l=>l.type===n.Loop)]},[])]}getSearches(){return[...this.searches,...this.getEntryPoints().reduce((t,i)=>{const s=qe(i);return[...t,...s.filter(l=>l.type===n.Search)]},[]),...this.functionCalls.reduce((t,i)=>{const s=qe(i);return[...t,...s.filter(l=>l.type===n.Search)]},[]),...this.conditions.reduce((t,i)=>{const s=qe(i);return[...t,...s.filter(l=>l.type===n.Search)]},[]),...this.operations.reduce((t,i)=>{const s=qe(i);return[...t,...s.filter(l=>l.type===n.Search)]},[]),...this.loops.reduce((t,i)=>{const s=qe(i);return[...t,...s.filter(l=>l.type===n.Search)]},[])]}attachOrphanReferences(){const e=this.getVariableInstances(),t=this.getVariableDeclarations();return e.forEach(i=>{if(!i.declaration){const s=i.initialData,l=s.declaration.entityId||s.declaration.id,o=t.find(d=>d.id===l);o&&i.setDeclaration(o)}}),this}getBuiltInPersistedEntity(){return this.builtInBaseEntities.find(e=>e.name===z.PERSISTED_ENTITY)||null}};f(ae,"sessionAuthor","1"),f(ae,"UUID",{isBackup:!0,uuid:()=>Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15),fromUUID:e=>e}),f(ae,"repository",{APICreate:async(e,...t)=>e,APIUpdate:async(e,...t)=>e,APIDelete:async(e,...t)=>e,APIClone:async(e,...t)=>{},APILoad:async(e,...t)=>null,APILoadVersion:async(e,t,...i)=>null}),f(ae,"type",n.Project),f(ae,"USER_MANAGED_PARENT_TYPES",[]),f(ae,"PARENT_TYPES",[...ae.USER_MANAGED_PARENT_TYPES]),f(ae,"MUTABLE_BASE_PROPERTIES",["name","description"]),f(ae,"INMUTABLE_BASE_PROPERTIES",["id","type","version","createdAt","author","previousVersion"]),f(ae,"BASE_PROPERTIES",[...ae.MUTABLE_BASE_PROPERTIES,...ae.INMUTABLE_BASE_PROPERTIES]),f(ae,"MUTABLE_META_PROPERTIES",[...ae.MUTABLE_BASE_PROPERTIES,"x","y"]),f(ae,"INMUTABLE_META_PROPERTIES",[...ae.INMUTABLE_BASE_PROPERTIES]),f(ae,"META_PROPERTIES",[...ae.MUTABLE_META_PROPERTIES,...ae.INMUTABLE_META_PROPERTIES]),f(ae,"MUTABLE_UPSTREAM_PROPERTIES",[]),f(ae,"INMUTABLE_UPSTREAM_PROPERTIES",["primitives","builtInBaseEntities","operationDeclarations","globalEventActionDescriptors","loopDeclarations","builtInInstances"]),f(ae,"UPSTREAM_PROPERTIES",[...ae.MUTABLE_UPSTREAM_PROPERTIES,...ae.INMUTABLE_UPSTREAM_PROPERTIES]),f(ae,"MUTABLE_DOWNSTREAM_PROPERTIES",["entities","projects","functions","events","variableDeclarations","variableInstances","conditions","operations","functionCalls","loops","searches"]),f(ae,"INMUTABLE_DOWNSTREAM_PROPERTIES",[]),f(ae,"DOWNSTREAM_PROPERTIES",[...ae.MUTABLE_DOWNSTREAM_PROPERTIES,...ae.INMUTABLE_DOWNSTREAM_PROPERTIES]),f(ae,"PROPERTIES",[...ae.META_PROPERTIES,...ae.UPSTREAM_PROPERTIES,...ae.DOWNSTREAM_PROPERTIES]);let m=ae;var aw=(r=>(r.PersistChangeSet="persist-change-set",r.CreateSingle="create-single",r.CreateBulk="create-bulk",r.CreateSingleNested="create-single-nested",r.CreateBulkNested="create-bulk-nested",r.Update="update",r.Clone="clone",r.Delete="delete",r.Load="load",r.LoadNested="load-nested",r.LoadVersion="load-version",r))(aw||{});class ow extends Je{constructor(e){super(Oi,e);f(this,"id",Xe.Parallel);f(this,"name",Xe.Parallel);f(this,"description","Execute a list of actions one after the other");f(this,"version","1");f(this,"autoexecutable",!0);f(this,"initialData",Oi);f(this,"type",n.ActionDescriptor);f(this,"inputs",[]);f(this,"outputs",[]);f(this,"error",null);f(this,"project");this.project=e,this.inputs=Oi.inputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(null),i}),this.outputs=Oi.outputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(null),i}),this.error=Oi.error?C(Oi.error,this.project):null}}class lw extends Je{constructor(e){super(qt,e);f(this,"id",qt.id);f(this,"name",qt.name);f(this,"description",qt.description);f(this,"version",qt.version);f(this,"autoexecutable",!1);f(this,"initialData",qt);f(this,"type",n.ActionDescriptor);f(this,"inputs",[]);f(this,"outputs",[]);f(this,"error",null);f(this,"project");this.project=e,this.inputs=qt.inputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(null),i}),this.outputs=qt.outputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(null),i}),this.error=qt.error?C(qt.error,this.project):null}}class dw extends Je{constructor(e){super(nr,e);f(this,"id",Xe.Sequential);f(this,"name",Xe.Sequential);f(this,"description","Execute a list of actions one after the other");f(this,"version","1");f(this,"autoexecutable",!0);f(this,"initialData",nr);f(this,"type",n.ActionDescriptor);f(this,"inputs",[]);f(this,"outputs",[]);f(this,"error",null);f(this,"project");this.project=e,this.inputs=nr.inputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(null),i}),this.outputs=nr.outputs.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(null),i}),this.error=nr.error?C(nr.error,this.project):null}}class uW extends Je{constructor(a){super(Bs,a)}}class pW extends Je{constructor(a){super(on,a)}}class cW extends Je{constructor(e){super(ln,e);f(this,"autoexecutable",!0)}getEntityToMatchInputMap(e){return e.inputs.find(t=>{var i;return((i=t.declaration)==null?void 0:i.id)===k.operation[Qe.Validate].inputs.entityToMatch.id})||null}getDataToValidateInputMap(e){return e.inputs.find(t=>{var i;return((i=t.declaration)==null?void 0:i.id)===k.operation[Qe.Validate].inputs.dataToValidate.id})||null}getOutputDataOutputMap(e){return e.outputs.find(t=>{var i;return((i=t.declaration)==null?void 0:i.id)===k.operation[Qe.Validate].outputs.outputEntity.id})||null}getEntityToMatch(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"get-entity-to-match-validate-data"))){let i=null;if(e.readsValue){const l=e.readsValue.getDataType(t);l&&l.entity&&l.entity.type===n.DefinitionEntity&&(i=l.entity)}const s=e.getDefaultValue();return!i&&s&&s.valueAsTypeSingle&&!Array.isArray(s.valueAsTypeSingle)&&s.valueAsTypeSingle.type===n.DefinitionEntity&&(i=s.valueAsTypeSingle),i}syncOperationInstance(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-operation-instance-validate-data"))){const i=[],s=[],l=[],o=[],d=this.getEntityToMatchInputMap(e);if(d){const{added:c,updated:I,removed:E,affected:O}=this.syncEntityToMatchInputMapDataType(d,t);i.push(...I),s.push(...c),l.push(...E),o.push(...O)}const u=this.getDataToValidateInputMap(e);if(u){const{added:c,updated:I,removed:E,affected:O}=this.syncDataToValidateInputMapDataType(u,t);i.push(...I),s.push(...c),l.push(...E),o.push(...O)}const y=this.getOutputDataOutputMap(e);if(y){const{added:c,updated:I,removed:E,affected:O}=this.syncOutputDataOutputMapDataType(y,t);i.push(...I),s.push(...c),l.push(...E),o.push(...O)}return t==null||t.attemptAutoclose("sync-operation-instance-validate-data",this.id),{updated:p(i),added:p(s),removed:p(l),affected:p(o),self:e}}syncEntityToMatchInputMapDataType(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-entity-to-match-input-map-data-type"))){var u,y,c;const i=[],s=[],l=[],o=[];if(((u=e.declaration)==null?void 0:u.id)!==k.operation[Qe.Validate].inputs.entityToMatch.id)return t==null||t.attemptAutoclose("sync-entity-to-match-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!e.dataType){const I={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||new Date().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.DataType,parentRelationType:null,options:null,implementationChooseOne:!1,isList:!1,andChildrenGroup:null,orChildrenGroup:null,asType:!0,entity:null,like:!0,inferred:!0,parent:e.toReference()},E=C(I,e.project);E.setParent(e,t),E.initChildren(t),t==null||t.add(E,A.Added),i.push(E),e.setDataType(E)}(y=e.dataType)==null||y.metaSync({inferred:!0,like:!1,asType:!0},t);const d=this.getEntityToMatch(e,t);return(c=e.dataType)==null||c.setEntity(d),e.dataType&&s.push(e.dataType),t==null||t.attemptAutoclose("sync-entity-to-match-input-map-data-type",this.id),{updated:p(s),added:p(i),removed:p(l),affected:p(o),self:e.dataType}}syncDataToValidateInputMapDataType(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-data-to-validate-input-map-data-type"))){var c,I,E;const i=[],s=[],l=[],o=[];if(((c=e.declaration)==null?void 0:c.id)!==k.operation[Qe.Validate].inputs.dataToValidate.id)return t==null||t.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};const d=this.getEntityToMatchInputMap(e.parent);if(!d)return t==null||t.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!this.getEntityToMatch(d,t))return t==null||t.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!e.dataType){const O={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||new Date().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.DataType,parentRelationType:null,options:null,implementationChooseOne:!1,isList:!1,andChildrenGroup:null,orChildrenGroup:null,asType:!1,entity:null,like:!0,inferred:!0,parent:e.toReference()},P=C(O,e.project);P.setParent(e,t),P.initChildren(t),t==null||t.add(P,A.Added),i.push(P),e.setDataType(P)}(I=e.dataType)==null||I.metaSync({inferred:!0,like:!0,asType:!1},t);const y=this.getEntityToMatch(d,t);return(E=e.dataType)==null||E.setEntity(y),e.dataType&&s.push(e.dataType),t==null||t.attemptAutoclose("sync-data-to-validate-input-map-data-type",this.id),{updated:p(s),added:p(i),removed:p(l),affected:p(o),self:e.dataType}}syncOutputDataOutputMapDataType(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"sync-output-data-output-map-data-type"))){var c,I,E;const i=[],s=[],l=[],o=[];if(((c=e.declaration)==null?void 0:c.id)!==k.operation[Qe.Validate].outputs.outputEntity.id)return t==null||t.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};const d=this.getEntityToMatchInputMap(e.parent);if(!d)return t==null||t.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!this.getEntityToMatch(d,t))return t==null||t.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:[],added:[],removed:[],affected:[],self:null};if(!e.dataType){const O={id:m.UUID.uuid(),version:m.UUID.uuid(),createdAt:(t==null?void 0:t.timestamp)||new Date().toISOString(),author:"1",previousVersion:null,deleted:!1,type:n.DataType,parentRelationType:null,options:null,implementationChooseOne:!1,isList:!1,andChildrenGroup:null,orChildrenGroup:null,asType:!1,entity:null,like:!0,inferred:!0,parent:e.toReference()},P=C(O,e.project);P.setParent(e,t),P.initChildren(t),t==null||t.add(P,A.Added),i.push(P),e.setDataType(P)}(I=e.dataType)==null||I.metaSync({inferred:!0,like:!0,asType:!1},t);const y=this.getEntityToMatch(d,t);return(E=e.dataType)==null||E.setEntity(y),e.dataType&&s.push(e.dataType),t==null||t.attemptAutoclose("sync-output-data-output-map-data-type",this.id),{updated:p(s),added:p(i),removed:p(l),affected:p(o),self:e.dataType}}inferInputMapDataType(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"infer-input-map-data-type-validate-data"))){var i,s;if(((i=e.declaration)==null?void 0:i.id)===k.operation[Qe.Validate].inputs.entityToMatch.id){const{added:l,updated:o,removed:d,affected:u}=this.syncEntityToMatchInputMapDataType(e,t);return t==null||t.attemptAutoclose("infer-input-map-data-type-validate-data",this.id),{updated:p(o),added:p(l),removed:p(d),affected:p(u),self:e.dataType}}else if(((s=e.declaration)==null?void 0:s.id)===k.operation[Qe.Validate].inputs.dataToValidate.id){const{added:l,updated:o,removed:d,affected:u}=this.syncDataToValidateInputMapDataType(e,t);return t==null||t.attemptAutoclose("infer-input-map-data-type",this.id),{updated:p(o),added:p(l),removed:p(d),affected:p(u),self:e.dataType}}return{updated:[],added:[],removed:[],affected:[],self:null}}inferOutputMapDataType(e,t=this.project.addChangeSet(new b(this.project,m.sessionAuthor,T().toISOString(),this,!0,"infer-output-map-data-type-validate-data"))){var i;if(((i=e.declaration)==null?void 0:i.id)===k.operation[Qe.Validate].outputs.outputEntity.id){const{added:s,updated:l,removed:o,affected:d}=this.syncOutputDataOutputMapDataType(e,t);return t==null||t.attemptAutoclose("infer-output-map-data-type-validate-data",this.id),{updated:p(l),added:p(s),removed:p(o),affected:p(d),self:e.dataType}}return{updated:[],added:[],removed:[],affected:[],self:null}}}class fW extends Je{constructor(a){super(Id,a)}}class yW extends Je{constructor(a){super(Ad,a)}}class hW extends Je{constructor(a){super(bd,a)}}class mW extends Je{constructor(a){super(Ya,a)}}class vW extends Je{constructor(a){super(Ja,a)}}class TW extends Je{constructor(a){super(Vs,a)}}function IW(r){const a=[new dw(r),new ow(r),new lw(r),new uW(r),new pW(r),new cW(r),new mW(r),new fW(r),new hW(r),new yW(r),new vW(r),new TW(r),new Je(Td,r),new Je(vd,r)];return a.forEach(e=>{e.initChildren(null),r.subscribeBuiltInInstance(e)}),r.operationDeclarations=a,a}class uw extends Ki{constructor(e){super(Ct,e);f(this,"initialData");f(this,"id",z.PERSISTED_ENTITY);f(this,"version","1");f(this,"name",z.PERSISTED_ENTITY);f(this,"description",Ct.description);f(this,"type",n.BuiltInBaseEntity);f(this,"abstract",Ct.abstract);f(this,"static",Ct.static);f(this,"properties",[]);f(this,"methods",[]);f(this,"abstractMethods",[]);f(this,"extends",[]);f(this,"errors",[]);f(this,"project");this.initialData=Ct,this.project=e,this.id=Ct.id,this.version=Ct.version,this.name=Ct.name,this.static=Ct.static,this.abstract=Ct.abstract,this.properties=this.initialData.properties.map(t=>{const i=C(t,this.project);return i.setParent(this,null),i.initChildren(null),i}),this.methods=this.initialData.methods.map(t=>{const i=C(t,this.project);return i.parent=this,i}),this.abstractMethods=this.initialData.abstractMethods.map(t=>{const i=C(t,this.project);return i.parent=this,i}),this.extends=this.initialData.extends.map(t=>C(t,this.project))}}function EW(r){const a=[new uw(r),new Ki(js,r),new Ki(ji,r),new Ki(fo,r)];return a.forEach(e=>{r.subscribeBuiltInInstance(e)}),r.builtInBaseEntities=a,a}function AW(r){const a=[new Qt(se,r),new Qt(er,r),new Qt(ve,r),new Qt(pd,r),new Qt(Ot,r),new Qt(tr,r),new Qt(Li,r),new Qt(ir,r),new Qt(Fn,r)];return a.forEach(e=>{r.subscribeBuiltInInstance(e)}),r.primitives=a,a}function bW(r){const a=[new Je(ho,r)];return a.forEach(e=>{e.initChildren(null),r.subscribeBuiltInInstance(e)}),r.globalEventActionDescriptors=a,a}function RW(r){const a=[new Je(Ls,r),new Je(Ar,r),new Je(Ms,r),new Je(Sn,r),new Je(Zn,r),new Je(ro,r)];a.forEach(t=>{t.initChildren(null),r.subscribeBuiltInInstance(t)}),r.loopDeclarations=a;const e=[new Je(oo,r),new Je(Ns,r),new Je(so,r),new Je(Ud,r),new Je(jd,r),new Je(no,r)];return e.forEach(t=>{t.initChildren(null),r.subscribeBuiltInInstance(t)}),r.loopDeclarationsBodies=e,a}function DW(r){const a=[new mr(mo,r)];return a.forEach(e=>{e.initChildren(null),r.subscribeBuiltInInstance(e)}),r.valueDescriptors=a,a}function OW(r){const a=[new Je(fn,r),new Je(Yn,r)];return a.forEach(e=>{e.initChildren(null),r.subscribeBuiltInInstance(e)}),r.conditionDeclarations=a,a}const Un={},nd={},Ga={empty:!1,enrich:!0,mock:!1,ignoreCache:!1,onFetch:async()=>null,manuallyInit:!1};function pw(r,{enrich:a}={enrich:!0}){const e=r.project,t=r.record,i=new ql(e),s=new Set;t[e.id]=e,s.add(e.id);const l=T().toISOString();Object.values(t).forEach(u=>{!u||i.allBuiltInEntityIds.includes(u.id)||s.add(u.id)}),i.order=Array.from(s),i.flatRecord=t,i.orderEntities();const o=sd(r.project);o.instances[e.id]=o;const d=a?o.addChangeSet(new b(o,"",l,o)):null;return i.visit(u=>{if(u.id===o.id)return;const y=C(u,o);y.hydrateAncestors(),y.addSelfToProject(null)}),a?(i.visit(u=>{const y=o.get(u.id);y&&y.afterAllChildrenInitialized(d)}),o.afterAllChildrenInitialized(d)):ad(o,l).forEach(y=>{y.remove({ignoreUpstream:!0},null)}),o.instancesList.forEach(u=>{u.previousVersion=null}),d==null||d.close(),o}async function PW(r,a=Ga){const e={...Ga,...a};if(e.empty)return{data:{project:{id:r.id,type:n.Project,version:m.UUID.uuid(),createdAt:T().toISOString(),author:m.sessionAuthor,previousVersion:null,deleted:!1,name:null,description:null,projects:[],entities:[],operations:[],functions:[],variableDeclarations:[],variableInstances:[],functionCalls:[],conditions:[],loops:[],searches:[],events:[]},record:{}}};if(e.mock){const i={...lp};return i.id=r.id,{data:{project:i,record:{}}}}return console.log("Fetching project from external API"),new Promise(async i=>{if(e.onFetch){const s=await e.onFetch(r.id);if(s){i({data:s});return}}else i({data:null})})}function sd(r){const a=new m(r);return AW(a),EW(a),IW(a),bW(a),RW(a),DW(a),OW(a),Array.from(new Set([...a.getAllBuiltInIds(),..._i()])).forEach(t=>{if(!a.builtInInstances[t]&&a.instances[t])a.builtInInstances[t]=a.instances[t],delete a.instances[t];else if(!a.builtInInstances[t])throw new Error(`Built in entity was not properly initialized: ${t}`)}),a}function ad(r,a){return r.instancesList.filter(t=>T(t.createdAt).isAfter(T(a)||!!t.previousVersion))}function wW(r,{enrich:a}={enrich:!0}){const e=new Map,t=Array.from(new Set([...r.getAllBuiltInIds(),..._i()]));Object.keys(r.instances).forEach(u=>{if(t.includes(u)){e.set(u,u);return}const y=r.get(u);if(!id(y,{...r.instances,...r.builtInInstances}).every(E=>!t.includes(E))){e.set(u,u);return}e.set(u,m.UUID.uuid())});const i=T().toISOString(),s=r.toShallowJSON({seenEntityMaps:e});s.previousVersion=null,s.createdAt=i,s.version=m.UUID.uuid();const l=sd(s),o=a?l.addChangeSet(new b(l,"",i,l)):null,d=new ql(r);return d.visit(u=>{const y=u.toShallowJSON({seenEntityMaps:e});u.type===n.ValueDescriptor&&u.name==="Iteration result"&&(console.log("Og entity shallow copy: ",y),console.log("Og entity full: ",u)),y.previousVersion=null,y.createdAt=i,y.version=m.UUID.uuid();const c=C(y,l);c.hydrateAncestors(),c.addSelfToProject(o),o==null||o.add(c,A.Added)}),a?(d.visit(u=>{const y=l.get(e.get(u.id));y&&y.afterAllChildrenInitialized(o)}),l.afterAllChildrenInitialized(o)):ad(l,i).forEach(y=>{y.remove({ignoreUpstream:!0},null)}),l.instancesList.forEach(u=>{u.previousVersion=null}),o==null||o.close(),l}function cw(r,{enrich:a}={enrich:!0}){const e=sd(r),t=T().toISOString(),i=a?e.addChangeSet(new b(e,"",t,e)):null;i&&(i.type=Pc.Automatic);const s=new ql(r);return s.visit(l=>{const o=C(l,e);o.hydrateAncestors(),o.addSelfToProject(i)}),a?(s.visit(l=>{const o=e.get(l.id);o&&o.afterAllChildrenInitialized(i)}),e.afterAllChildrenInitialized(i)):ad(e,t).forEach(o=>{o.remove({ignoreUpstream:!0},null)}),i==null||i.close(),e}async function CW(r,a=Ga){const e={...Ga,...a};if(r.id&&Un[r.id]&&!e.ignoreCache)return Un[r.id];if(r.id&&nd[r.id]&&!e.ignoreCache)return await nd[r.id],Un[r.id];const t=PW(r,e);r.id&&(nd[r.id]=t);const i=await t;if(i.data){let s;return e.mock?s=cw(lp,{enrich:!!e.enrich}):i.data instanceof m?s=i.data:s=pw(i.data,{enrich:!!e.enrich}),Un[r.id]=s,r.id&&delete nd[r.id],s}return null}function VW(r){return Un[r.id]&&delete Un[r.id],null}const BW="test_primitive_entities_export";h.AI_VALUE_CONNECTION_GENERATION_ACTION_EXPLANATION=Gc,h.ALL_BUILT_IN_BASE_ENTITIES=xI,h.ALL_BUILT_IN_CONDITION_ENTITIES=tE,h.ALL_BUILT_IN_GLOBAL_EVENT_ENTITIES=rE,h.ALL_BUILT_IN_LOOP_BODY_ENTITIES=vT,h.ALL_BUILT_IN_LOOP_ENTITIES=mT,h.ALL_BUILT_IN_OPERATION_ENTITIES=C0,h.ALL_BUILT_IN_PRIMITIVE_ENTITIES=mf,h.ALL_BUILT_IN_TOP_LEVEL_ENTITIES=oE,h.ALL_BUILT_IN_VALUE_DESCRIPTORS=aE,h.ActionDescriptorState=Je,h.ActionInputMapState=F7,h.ActionOutputMapState=S7,h.AppendToListOperationInputIds=Dh,h.AppendToListOperationOutputIds=Oh,h.ArgumentDeclarationDependencyField=M1,h.ArgumentDeclarationState=Yr,h.BREAK_AND_CONTINUE_STATEMENTS_RETURN_DECLARATIONS_EXPLANATION=Uc,h.BUILT_IN_BASE_ENTITY_IDS=k,h.BUILT_IN_ENTITY_TYPES=Ti,h.BaseCanvasDraggableState=rW,h.BaseEntityNames=z,h.BaseState=iW,h.BaseValueDescriptorIds=qa,h.BreakStatementDependencyField=Vc,h.BreakStatementState=xr,h.BuiltInBaseEntityState=Ki,h.CACHED_PROJECTS_BY_ID=Un,h.CALLABLE_ENTITIES_EXPLANATION=K7,h.CALLABLE_TYPES=Mi,h.CALLER_ENTITIES_EXPLANATION=G1,h.CALLER_TYPES=Ni,h.CALLS_UPDATE_EXPLANATION=Xr,h.COMPARISON_CONDITIONS=QI,h.CONDITIONS=eE,h.CUSTOM_ENTITY_OPERATIONS=Jm,h.CallableEntityClass=sW,h.CallerEntityClass=nf,h.ChangeSet=b,h.ChangeSetChangeCaptureType=Pc,h.ChangeSetEntityChangeType=A,h.ChildEntityState=nW,h.ComparisonOperatorTypes=yt,h.ConditionDependencyField=v1,h.ConditionState=Sr,h.ContinueStatementDependencyField=wc,h.ContinueStatementState=Lt,h.CreateNewInputIds=Em,h.CreateNewOutputIds=Am,h.DRAGGABLE_CALLABLE_TYPES=ud,h.DRAGGABLE_CALLER_TYPES=lf,h.DRAGGABLE_ELEMENT_TYPES=Za,h.DRAGGABLE_EXECUTABLE_TYPES=vw,h.DRAGGABLE_PASS_THROUGH_CALLABLE_TYPES=Sa,h.DRAGGABLE_PASS_THROUGH_CALLABLE_TYPES_WITH_OUTPUTS=dd,h.DataTypeCompatibilityTypes=bi,h.DataTypeDependencyField=Cc,h.DataTypeParentChildRelation=Dt,h.DataTypeState=$r,h.DefinitionEntityDependencyField=rd,h.DefinitionEntityState=nn,h.EDITABLE_PERSISTANCE_REPOSITORY_DEFAULTS=eW,h.ENTITIES_WITH_VALLUES_EXPLANATION=Fl,h.ENTITY_PERSISTANCE_OPTIONS_DEFAULTS=g,h.ENTITY_RECUSION_OPTIONS_DEFAULTS=q,h.ENTITY_TYPES=Tw,h.ENTITY_WITH_DECLARATION_TYPES=hw,h.ENTITY_WITH_LOGIC_SCOPE_TYPES=dt,h.ENTITY_WITH_NAMES_TYPES=df,h.ENTITY_WITH_PARENT_TYPES=fw,h.ENTITY_WITH_USER_MANAGED_DECLARATION_TYPES=af,h.ENTITY_WITH_USER_MANAGED_SINGLE_IMPLEMENTS_TYPES=yw,h.ENTITY_WITH_VALUE_TYPES=sf,h.ENTRY_POINT_ENTITIES_EXPLANATION=Ba,h.ENTRY_POINT_TYPES=lt,h.EVENT_TYPES=Gn,h.EXECUTABLE_TYPES=mw,h.EXECUTION_OPERATIONS=Im,h.EntityAction=aw,h.EntityError=it,h.EntityErrorSeverity=D,h.EntityGenerationError=w,h.EntityGenerationErrorCode=R,h.EntityInstanceErrorCode=F,h.EntityOperations=Qe,h.EntityType=n,h.EntityWithLogicScopeClass=dW,h.EntityWithValueClass=lW,h.EntryPointEntityClass=aW,h.ExecutionOperations=Xe,h.ExecutionTerminationType=y1,h.FunctionCallDependencyField=H1,h.FunctionCallState=en,h.FunctionDeclarationDependencyField=o1,h.FunctionDeclarationState=jr,h.GET_PROJECT_OPTIONS_DEFAULTS=Ga,h.GLOBAL_EVENT_DECLARATIONS=iE,h.GetLastInListOperationInputIds=ch,h.GetLastInListOperationOutputIds=fh,h.GlobalEventNames=Qi,h.GlobalEventState=Fr,h.HTTPOperations=_t,h.HTTP_OPERATIONS=P0,h.InputMapDependencyField=C1,h.InputMapState=Wi,h.InstalledProjectState=Wr,h.InternalCallDependencyField=P1,h.InternalCallState=zr,h.JoinListOperationInputIds=My,h.JoinListOperationOutputIds=Ny,h.LIST_OPERATIONS=$h,h.ListOperations=he,h.LiteralValueDependencyField=L1,h.LiteralValueState=Hr,h.LoopDependencyField=h1,h.LoopState=kr,h.LoopTypes=Q,h.NON_INTERACTIVE_BASE_ENTITIES_EXPLANATION=Qr,h.NUMBER_OPERATIONS=Jf,h.NumberOperations=et,h.OPERATION_DECLARATIONS=w0,h.OperationDependencyField=u1,h.OperationState=Gr,h.OutputMapDependencyField=B1,h.OutputMapParentChildRelation=$n,h.OutputMapState=zi,h.PARENT_AUTO_CALCULATION_FROM_CALLER_EXPLANATION=xl,h.PASS_THROUGH_CALLABLE_ENTITIES_EXPLANATION=Kr,h.PASS_THROUGH_CALLABLE_TYPES=ot,h.PASS_THROUGH_CALLABLE_TYPES_WITH_OUTPUTS=of,h.PROPERTY_NOT_VALUE_READER_WRITTER_EXPLANATION=$c,h.ParallelExecutionOperation=ow,h.PassThroughCallableEntityClass=oW,h.PersistedEntity=uw,h.PersistedEntityMethods=di,h.PrimitiveEntityState=Qt,h.PrimitiveTypes=L,h.ProjectState=m,h.PropertyDependencyField=t1,h.PropertyState=Ur,h.READ_ONLY_ENTITY_PERSISTANCE_REPOSITORY=sw,h.RETURN_STATEMENT_RETURN_DECLARATIONS_EXPLANATION=X7,h.ReturnDeclarationDependencyField=r1,h.ReturnDeclarationState=ai,h.ReturnStatementDependencyField=gl,h.ReturnStatementState=gr,h.STANDALONE_CONDITIONS=ZI,h.STRING_OPERATIONS=_y,h.ScopeCompatibilityType=td,h.SearchDependencyField=b1,h.SearchState=Jr,h.SequentialExecutionOperation=dw,h.SequentialExecutionOperationInputIds=am,h.SequentialExecutionOperationOutputIds=om,h.SharedEntityErrorCode=j,h.SharedStateFunctionality=nw,h.SplitListOperationInputIds=zy,h.SplitListOperationOutputIds=Yy,h.StandaloneOperatorTypes=vi,h.StringOperations=Ee,h.TERMINATION_TYPES=st,h.Traverser=ql,h.USER_MANAGED_ENTITY_TYPES=uf,h.UserManagedEntityStateTemplate=tW,h.VALUE_READING_ENTITIES_EXPLANATION=jc,h.VALUE_READING_TYPES=Er,h.VALUE_WRITING_ENTITIES_EXPLANATION=F1,h.VALUE_WRITING_TYPES=Tt,h.VARIABLE_DATA_TYPE_INFERRANCE_EXPLANATION=gc,h.VARIABLE_TYPES=tt,h.ValueAutogenerationType=vt,h.ValueDescriptorDependencyField=g1,h.ValueDescriptorParentChildRelation=N,h.ValueDescriptorState=mr,h.ValueReadingEntityClass=Ir,h.ValueWritingEntityClass=$a,h.VariableDeclarationDependencyField=E1,h.VariableDeclarationState=qr,h.VariableInputMapState=G7,h.VariableInstanceDependencyField=_c,h.VariableInstanceState=Zr,h.VariableOutputMapState=k7,h.WaitOperation=lw,h.WaitOperationInputIds=Qh,h.WaitOperationOutputIds=em,h.actionDescriptorValidation=_7,h.appendToListOperation=Ya,h.appendToListOperationElementToAppendArgument=Dd,h.appendToListOperationElementToAppendArgumentParentRef=Nh,h.appendToListOperationElementToAppendArgumentRef=Ch,h.appendToListOperationError=jh,h.appendToListOperationErrorParentRef=gh,h.appendToListOperationListArgument=Rd,h.appendToListOperationListArgumentParentRef=Mh,h.appendToListOperationListArgumentRef=Ph,h.appendToListOperationListDataType=wh,h.appendToListOperationResultListDataType=_h,h.appendToListOperationResultListReturn=Uh,h.appendToListOperationResultListReturnParentRef=Lh,h.appendToListOperationResultListReturnRef=Bh,h.appendToListOperationSecondListDataType=Vh,h.applyNewScope=K,h.argumentDeclarationValidation=Z7,h.asGenerationActionExample=Yi,h.booleanPrototype=er,h.breakStatementValidation=C7,h.calculateNewParentBasedOnCallers=qc,h.capitalizeFirstLetter=xt,h.changeSetJSONRecordToUniqueIds=m7,h.checkAreDataTypesCompatible=Ri,h.checkAreDefinitionEntitiesCompatibleAsDataType=FO,h.checkArePropertiesCompatibleAsDataType=GO,h.checkHasMetadataChanged=pt,h.checkImplementationsOverlap=Tr,h.checkIsBranchDependentButNotDirectlyOnBranch=Ma,h.checkIsBranchDependentOnBranch=pJ,h.checkIsCallableEntityReachable=ja,h.checkIsCanvasEntity=VJ,h.checkIsDetachedBranch=YP,h.checkIsDetachedBranchShallow=tf,h.checkIsGlobalVariable=wJ,h.checkIsGloballyDeclared=ef,h.checkIsMethod=XP,h.checkIsNestedScope=ed,h.checkScopeCompatibility=ga,h.cloneProject=wW,h.conditionValidation=M7,h.continueStatementValidation=I7,h.convertToAbstract=oJ,h.convertToNonAbstract=lJ,h.convertToNonStatic=uJ,h.convertToStatic=dJ,h.countedLoopActionDescriptor=Ls,h.countedLoopActionDescriptorDynamicReturnDeclaration=lT,h.countedLoopActionDescriptorDynamicReturnDeclarationParentRef=oT,h.countedLoopActionDescriptorStringArgumentDeclaration=aT,h.countedLoopActionDescriptorStringArgumentDeclarationDataType=nT,h.countedLoopActionDescriptorStringArgumentDeclarationDataTypeDefaultValue=iT,h.countedLoopActionDescriptorStringArgumentDeclarationDataTypeDefaultValueParentRef=tT,h.countedLoopActionDescriptorStringArgumentDeclarationDataTypeParentRef=rT,h.countedLoopActionDescriptorStringArgumentDeclarationParentRef=sT,h.countedLoopBodyActionDescriptor=oo,h.countedLoopBodyActionDescriptorAnyDynamicArgument=fT,h.countedLoopBodyActionDescriptorAnyDynamicArgumentParentRef=cT,h.countedLoopBodyActionDescriptorAnyDynamicReturn=hT,h.countedLoopBodyActionDescriptorAnyDynamicReturnParentRef=yT,h.countedLoopBodyActionDescriptorIterationNumberArgumentDeclaration=Gd,h.countedLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=uT,h.countedLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=dT,h.countedLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=pT,h.createDefinitionEntityFromJSONObject=Wl,h.createEntityError=de,h.createNestedDataTypeForEntity=Q1,h.createNewInstanceOperation=on,h.createNewInstanceOperationEntityToInstanciateArgument=Vm,h.createNewInstanceOperationEntityToInstanciateArgumentRef=Pm,h.createNewInstanceOperationEntityToInstanciateDataType=wm,h.createNewInstanceOperationError=Nm,h.createNewInstanceOperationErrorParentRef=Mm,h.createNewInstanceOperationNewEntityDataArgument=Om,h.createNewInstanceOperationNewEntityDataArgumentDataType=Dm,h.createNewInstanceOperationNewEntityDataArgumentDataTypeParentRef=Rm,h.createNewInstanceOperationNewEntityDataArgumentParentRef=bm,h.createNewInstanceOperationOutputEntityDeclaration=_m,h.createNewInstanceOperationOutputEntityDeclarationParentRef=Bm,h.createNewInstanceOperationRef=Cm,h.createSemanticId=XO,h.createStateFromGenerationTargetType=QJ,h.createStateFromType=ct,h.createStateFromTypeAndSubscribe=C,h.cronJobBuiltInBaseEntity=fo,h.cronJobBuiltInBaseEntityExpressionProperty=GI,h.cronJobBuiltInBaseEntityExpressionPropertyDataTypeRef=Ow,h.cronJobBuiltInBaseEntityExpressionPropertyRef=jI,h.cronJobBuiltInBaseEntityRef=$I,h.cronJobTriggeredFunctionDeclarationBlueprint=Qd,h.cronJobTriggeredFunctionDeclarationBlueprintParentRef=UI,h.dataTypeCompatibilityToErrorExplanation=z1,h.dataTypeValidation=R7,h.datePrototype=Li,h.dateValueAutogenerationSchema=fp,h.definitionEntityToZodSchema=RE,h.definitionEntityValidation=YJ,h.deletePersistedEntityMethod=Xd,h.deletePersistedEntityMethodParentRef=EI,h.deleteRootProject=VW,h.endpointBuiltInBaseEntity=js,h.endpointBuiltInBaseEntityRef=AT,h.endpointBuiltInBaseEntityRefFour=iI,h.endpointBuiltInBaseEntityRefThree=BT,h.endpointBuiltInBaseEntityRefTwo=PT,h.endpointBuiltInCorsProperty=bT,h.endpointBuiltInCorsPropertyDataType=ET,h.endpointBuiltInCorsPropertyDataTypeRef=TT,h.endpointBuiltInCorsPropertyRef=IT,h.endpointBuiltInMethodProperty=xd,h.endpointBuiltInMethodPropertyDataType=VT,h.endpointBuiltInMethodPropertyDataTypeRef=wT,h.endpointBuiltInMethodPropertyRef=CT,h.endpointBuiltInPathProperty=Fd,h.endpointBuiltInPathPropertyDataType=OT,h.endpointBuiltInPathPropertyDataTypeRef=RT,h.endpointBuiltInPathPropertyRef=DT,h.endpointPathParamsArgumentDeclaration=Sd,h.endpointPathParamsArgumentDeclarationRef=FT,h.endpointPathParamsVariableDataType=xT,h.endpointPathParamsVariableDataTypeRef=GT,h.endpointReachedTriggerActionDescriptor=Yd,h.endpointReachedTriggerActionDescriptorRef=kT,h.endpointReachedTriggerActionDescriptorRefFour=qT,h.endpointReachedTriggerActionDescriptorRefThree=ZT,h.endpointReachedTriggerActionDescriptorRefTwo=ST,h.endpointRequestBodyArgumentDeclaration=qd,h.endpointRequestBodyArgumentDeclarationRef=LT,h.endpointRequestBodyVariableDataType=UT,h.endpointRequestHeadersArgumentDeclaration=kd,h.endpointRequestHeadersArgumentDeclarationRef=MT,h.endpointRequestHeadersVariableDataType=NT,h.endpointRequestHeadersVariableDataTypeRef=_T,h.endpointRequestQueryParamsArgumentDeclaration=Zd,h.endpointRequestQueryParamsArgumentDeclarationRef=jT,h.endpointRequestQueryParamsVariableDataType=$T,h.endpointRequestQueryParamsVariableDataTypeRef=gT,h.endpointResponseBodyDataType=eI,h.endpointResponseBodyReturnDeclaration=zd,h.endpointResponseBodyReturnDeclarationRef=QT,h.endpointResponseCodeDataType=WT,h.endpointResponseCodeReturnDeclaration=Jd,h.endpointResponseCodeReturnDeclarationRef=JT,h.endpointResponseHeadersDataType=KT,h.endpointResponseHeadersDataTypeRef=YT,h.endpointResponseHeadersReturnDeclaration=Wd,h.endpointResponseHeadersReturnDeclarationRef=HT,h.endpointReturnStatementRef=zT,h.endpointReturnStatementRefThree=tI,h.endpointReturnStatementRefTwo=XT,h.enrichFromKnownEntities=Na,h.enumOptionsProperty=hf,h.enumOptionsPropertyDataType=ff,h.enumOptionsPropertyDataTypeRef=pf,h.enumOptionsPropertyRef=cf,h.enumPrototype=tr,h.enumPrototypeRef=yf,h.executionBuiltInBaseEntity=yo,h.executionBuiltInEntityAbortMethod=eu,h.executionBuiltInEntityAbortMethodParentRef=FI,h.filterOutDuplicateEntities=p,h.filterOutDuplicateErrors=B3,h.findEntityFromKeys=Sc,h.findReferenceToSelfInList=yP,h.findReferencesToSelfInProject=EJ,h.flattenActionDescriptor=hP,h.flattenArgumentDeclaration=mP,h.flattenBreakStatement=vP,h.flattenBuiltInBaseEntity=TP,h.flattenCalls=Hi,h.flattenCanvasAncestorsUntil=Ds,h.flattenCondition=IP,h.flattenContinueStatement=EP,h.flattenDataType=bP,h.flattenDefinitionEntity=AP,h.flattenDefinitionEntityExtensionAndImplementationTypes=Xc,h.flattenDefinitionEntityExtensionTypes=Ql,h.flattenDefinitionEntityExtensions=Hc,h.flattenDefinitionEntityImplementations=Kc,h.flattenDefinitionEntityImplementionTypes=Xl,h.flattenDerivedCanvasEntities=oi,h.flattenDetachedBranch=KP,h.flattenElementCalls=qe,h.flattenElementCallsOnTheSameScope=IJ,h.flattenEntity=U,h.flattenFunctionCall=RP,h.flattenFunctionDeclaration=DP,h.flattenGlobalEvent=OP,h.flattenInputMap=PP,h.flattenInstalledProject=wP,h.flattenInternalCall=CP,h.flattenLiteralValue=VP,h.flattenLoop=BP,h.flattenOperation=_P,h.flattenOutputMap=MP,h.flattenPrimitiveEntity=NP,h.flattenProject=LP,h.flattenProjectElements=fP,h.flattenProperty=UP,h.flattenRelatedCanvasElementsOnTheLeft=WP,h.flattenRelatedCanvasElementsOnTheRight=JP,h.flattenReturnDeclaration=gP,h.flattenReturnStatement=jP,h.flattenSearch=$P,h.flattenValueDescriptor=GP,h.flattenVariableDeclaration=FP,h.flattenVariableInstance=xP,h.flattenVariableReads=cP,h.flattenVariableWrites=pP,h.flattenVariables=Ye,h.fromChangeSetToRecordChangeSet=jJ,h.fromZodParseToEntityGenerationErrors=Mc,h.functionCallValidation=aJ,h.functionDeclarationValidation=b7,h.generate=VV,h.generateActionExample=Q7,h.generateExecutionDataType=o7,h.generateIdFromStrategy=ht,h.generateMutablePropertiesExplanation=jl,h.generateRandomBoolean=HE,h.generateRandomDate=wE,h.generateRandomDateAfter=DE,h.generateRandomDateBefore=OE,h.generateRandomDateBetweenRange=PE,h.generateRandomNumber=qE,h.generateRandomNumberAfter=kE,h.generateRandomNumberBefore=SE,h.generateRandomNumberBetweenRange=ZE,h.generateRandomText=YE,h.generateRandomTextAfter=JE,h.generateRandomTextBefore=WE,h.generateRandomTextBetweenRange=zE,h.generateUniqueUUID=xE,h.getAllActionDescriptorsForConditions=Zl,h.getAllActionDescriptorsForGlobalEvents=kl,h.getAllActionDescriptorsForLoops=Sl,h.getAllActionDescriptorsForOperations=rJ,h.getAllBuiltInEntityIds=_i,h.getAllGloballyDeclaredFunctionDeclarationsExplanation=q1,h.getBaseBuiltInEntities=kt,h.getBaseSchemaBasedOnType=j1,h.getBuiltInEntityOwner=rn,h.getCallableEntityReferenceSchema=Pt,h.getCallableEntityTypeSchema=wD,h.getCalledBy=hi,h.getCallerEntityReferenceSchema=LS,h.getCallerEntityTypeSchema=NS,h.getCalls=Wc,h.getCanvasEntitiesDerivedFromInternalCalls=qP,h.getCanvasEntitiesDerivedFromWrites=Os,h.getCanvasEntityDerivedFromValueReadingEntity=Kl,h.getCanvasEntityDerivedFromValueReadingEntityFromTransfer=ZP,h.getCanvasEntityReferenceSchema=KS,h.getCanvasEntityTypeSchema=HS,h.getChildrenEntityWithValues=fJ,h.getColumnProperties=LJ,h.getCommonAncestor=Jc,h.getCommonChildren=eP,h.getDatabaseEntities=MJ,h.getDatabaseEntity=UJ,h.getDeclaration=Nn,h.getDeepestScope=ew,h.getDefinitionEntityExtends=Ps,h.getDraggableCallableEntityReferenceSchema=VD,h.getDraggableCallableEntityTypeSchema=CD,h.getDraggableCallerEntityReferenceSchema=gS,h.getDraggableCallerEntityTypeSchema=US,h.getDraggableExecutableEntityReferenceSchema=FS,h.getDraggableExecutableEntityTypeSchema=GS,h.getDraggablePassThroughCallableEntityReferenceSchema=Rl,h.getDraggablePassThroughCallableEntityTypeSchema=bl,h.getDraggablePlayableEntityReferenceSchema=qS,h.getDraggablePlayableEntityTypeSchema=ZS,h.getEntitiesCreatedSinceInitialization=ad,h.getEntityArgumentDeclarations=Yc,h.getEntityInputMaps=kP,h.getEntityOutputMaps=DJ,h.getEntityReferenceSchema=YS,h.getEntityReturnDeclarations=SP,h.getEntityTypeSchema=zS,h.getEntityWithLogicScopeReferenceSchema=fr,h.getEntityWithLogicScopeTypeSchema=xS,h.getEntityWithValueReferenceSchema=PD,h.getEntityWithValueTypeSchema=MS,h.getEntryPointEntityReferenceSchema=Rt,h.getEntryPointEntityTypeSchema=Mr,h.getEventEntityReferenceSchema=El,h.getEventEntityTypeSchema=Il,h.getExecutableEntityReferenceSchema=$S,h.getExecutableEntityTypeSchema=jS,h.getExtendedBuiltInEntity=OJ,h.getExtendedDefinitionEntity=Qc,h.getGenerationTargetSchemaBasedOnType=$1,h.getHeadIfPartOfDetachedBranch=HP,h.getHighestScope=QP,h.getImplementedBuiltInEntity=PJ,h.getIsInteractive=La,h.getLastInListOperation=bd,h.getLastInListOperationError=Rh,h.getLastInListOperationErrorParentRef=bh,h.getLastInListOperationInputListArgument=Ih,h.getLastInListOperationInputListArgumentParentRef=Th,h.getLastInListOperationInputListArgumentRef=yh,h.getLastInListOperationInputListDataType=hh,h.getLastInListOperationOutputElementDataType=vh,h.getLastInListOperationOutputElementReturn=Ah,h.getLastInListOperationOutputElementReturnParentRef=Eh,h.getLastInListOperationOutputElementReturnRef=mh,h.getLinkedEntitiesFromArgumentDeclaration=TJ,h.getLowestPersistedEntityImplementation=zP,h.getParentCallableEntity=tP,h.getParentCallerEntity=rP,h.getParentCanvasEntities=Xt,h.getParentCanvasEntity=wt,h.getParentCanvasEntityFromTransfer=zl,h.getParentEntryPoint=cJ,h.getParentPassthroughCallableEntity=iP,h.getPassThroughCallableEntityReferenceSchema=rt,h.getPassThroughCallableEntityTypeSchema=Al,h.getPeristedEntities=_J,h.getPlayableEntityReferenceSchema=SS,h.getPlayableEntityTypeSchema=kS,h.getProject=CW,h.getPrototypeByType=Ua,h.getRecusriveParentsIds=id,h.getReferenceEntityId=_,h.getReferencedEntitiesStateOrErrors=Gl,h.getReferencedEntityStateOrErrors=Nc,h.getReferencedIds=Hl,h.getRelatedCanvasElementsOnTheLeft=Ln,h.getRelatedCanvasElementsOnTheLeftFromTransfer=AJ,h.getRelatedCanvasElementsOnTheRight=tn,h.getRootEntryPointScopeOwner=rf,h.getScopeOwner=St,h.getStateClassFromType=gJ,h.getTerminationReferenceSchema=WS,h.getTerminationTypeSchema=JS,h.getTouchedCanvasEntitiesFromChangeSet=$J,h.getUsedArgFromDeclaration=bJ,h.getUsedReturnFromDeclaration=RJ,h.getValueReadingEntityReferenceSchema=OD,h.getValueReadingEntityTypeSchema=cr,h.getValueWritingEntityReferenceSchema=_S,h.getValueWritingEntityTypeSchema=Ea,h.getVariableFromInputMapping=sP,h.getVariableFromReturnVariablePointer=lP,h.getVariableReferenceSchema=_r,h.getVariableTypeSchema=wn,h.getVariablesFromArgumentDeclarations=Yl,h.getVariablesFromInputMaps=aP,h.getVariablesFromOutputMapping=dP,h.getVariablesFromOutputMaps=uP,h.getVariablesFromReturnDeclarations=oP,h.getVariablesInSameOrHigherScope=Tc,h.getWrites=zc,h.globalEventValidation=w7,h.groupCallsBasedOnParallelizableExecution=hJ,h.handleAfterEntityImplementationSideEffects=X1,h.handleBeforeEntityImplementationSideEffects=K1,h.httpRequestBodyArgument=Qa,h.httpRequestBodyArgumentRef=s0,h.httpRequestBodyDataType=a0,h.httpRequestHeadersArgument=Xa,h.httpRequestHeadersArgumentRef=r0,h.httpRequestHeadersDataType=n0,h.httpRequestMethodArgument=Ha,h.httpRequestMethodArgumentRef=t0,h.httpRequestMethodDataType=i0,h.httpRequestMethodDataTypeRef=Qm,h.httpRequestOperation=Bs,h.httpRequestOperationErrorValueDescriptor=Bd,h.httpRequestOperationErrorValueDescriptorDatatype=O0,h.httpRequestOperationErrorValueDescriptorRef=D0,h.httpRequestOperationRef=E0,h.httpRequestOperationRefEight=b0,h.httpRequestOperationRefFive=T0,h.httpRequestOperationRefFour=v0,h.httpRequestOperationRefNine=R0,h.httpRequestOperationRefSeven=A0,h.httpRequestOperationRefSix=I0,h.httpRequestOperationRefThree=m0,h.httpRequestOperationRefTwo=h0,h.httpRequestQueryParamsArgument=Vd,h.httpRequestQueryParamsArgumentRef=Km,h.httpRequestQueryParamsDataType=Xm,h.httpRequestVariableURLArgument=Ka,h.httpRequestVariableURLArgumentRef=Ym,h.httpRequestVariableURLDataType=Hm,h.httpRequestVariableURLDataTypeRef=Wm,h.httpResponseBodyReturnDataType=y0,h.httpResponseBodyReturnDataTypeRef=c0,h.httpResponseBodyReturnReturn=io,h.httpResponseBodyReturnReturnRef=f0,h.httpResponseCodeDataType=l0,h.httpResponseCodeReturn=eo,h.httpResponseCodeReturnRef=o0,h.httpResponseHeadersDataType=p0,h.httpResponseHeadersDataTypeRef=d0,h.httpResponseHeadersReturn=to,h.httpResponseHeadersReturnRef=u0,h.implement=Jl,h.inferArgumentDeclarationDataType=xO,h.inferDataType=Ji,h.inferInputMapDataType=hc,h.inferOutputMapDataType=vc,h.inferPropertyDataType=ZO,h.inferReturnDeclarationDataType=mc,h.inferValueDescriptorDataType=qO,h.inferVariableDeclarationDataType=SO,h.inferVariableInstanceDataType=kO,h.initBaseProjectEntity=sd,h.initProject=cw,h.initProjectFromFetchResult=pw,h.inputMapValidation=$7,h.installedProjectValidation=g7,h.internalCallValidation=j7,h.isPromise=kc,h.iterateOverListActionDescriptorListArgumentDeclaration=sv,h.iterateOverListActionDescriptorListArgumentDeclarationDataType=rv,h.iterateOverListActionDescriptorListArgumentDeclarationDataTypeParentRef=iv,h.iterateOverListActionDescriptorListArgumentDeclarationParentRef=nv,h.iterateOverListLoopActionDescriptor=Ar,h.iterateOverListLoopActionDescriptorDynamicReturnDeclaration=ov,h.iterateOverListLoopActionDescriptorDynamicReturnDeclarationParentRef=av,h.iterateOverListLoopBodyActionDescriptor=Ns,h.iterateOverListLoopBodyActionDescriptorAnyDynamicArgument=mv,h.iterateOverListLoopBodyActionDescriptorAnyDynamicArgumentParentRef=hv,h.iterateOverListLoopBodyActionDescriptorAnyDynamicReturn=Tv,h.iterateOverListLoopBodyActionDescriptorAnyDynamicReturnParentRef=vv,h.iterateOverListLoopBodyActionDescriptorCurrentValueArgumentDeclaration=ao,h.iterateOverListLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataType=dv,h.iterateOverListLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataTypeParentRef=lv,h.iterateOverListLoopBodyActionDescriptorCurrentValueArgumentDeclarationParentRef=uv,h.iterateOverListLoopBodyActionDescriptorIterationNumberArgumentDeclaration=yv,h.iterateOverListLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=cv,h.iterateOverListLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=pv,h.iterateOverListLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=fv,h.iterateOverObjectKeysActionDescriptorObjectArgumentDeclaration=Rv,h.iterateOverObjectKeysActionDescriptorObjectArgumentDeclarationDataType=Av,h.iterateOverObjectKeysActionDescriptorObjectArgumentDeclarationDataTypeParentRef=Ev,h.iterateOverObjectKeysActionDescriptorObjectArgumentDeclarationParentRef=bv,h.iterateOverObjectKeysLoopActionDescriptor=Sn,h.iterateOverObjectKeysLoopActionDescriptorDynamicReturnDeclaration=Ov,h.iterateOverObjectKeysLoopActionDescriptorDynamicReturnDeclarationParentRef=Dv,h.iterateOverObjectKeysLoopBodyActionDescriptor=Ud,h.iterateOverObjectKeysLoopBodyActionDescriptorAnyDynamicArgument=Lv,h.iterateOverObjectKeysLoopBodyActionDescriptorAnyDynamicArgumentParentRef=Nv,h.iterateOverObjectKeysLoopBodyActionDescriptorAnyDynamicReturn=gv,h.iterateOverObjectKeysLoopBodyActionDescriptorAnyDynamicReturnParentRef=Uv,h.iterateOverObjectKeysLoopBodyActionDescriptorCurrentValueArgumentDeclaration=Ld,h.iterateOverObjectKeysLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataType=wv,h.iterateOverObjectKeysLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataTypeParentRef=Pv,h.iterateOverObjectKeysLoopBodyActionDescriptorCurrentValueArgumentDeclarationParentRef=Cv,h.iterateOverObjectKeysLoopBodyActionDescriptorIterationNumberArgumentDeclaration=Mv,h.iterateOverObjectKeysLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=Bv,h.iterateOverObjectKeysLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=Vv,h.iterateOverObjectKeysLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=_v,h.iterateOverObjectValuesActionDescriptorObjectArgumentDeclaration=xv,h.iterateOverObjectValuesActionDescriptorObjectArgumentDeclarationDataType=Gv,h.iterateOverObjectValuesActionDescriptorObjectArgumentDeclarationDataTypeParentRef=$v,h.iterateOverObjectValuesActionDescriptorObjectArgumentDeclarationParentRef=Fv,h.iterateOverObjectValuesLoopActionDescriptor=Zn,h.iterateOverObjectValuesLoopActionDescriptorDynamicReturnDeclaration=Sv,h.iterateOverObjectValuesLoopActionDescriptorDynamicReturnDeclarationParentRef=kv,h.iterateOverObjectValuesLoopBodyActionDescriptor=jd,h.iterateOverObjectValuesLoopBodyActionDescriptorAnyDynamicArgument=Xv,h.iterateOverObjectValuesLoopBodyActionDescriptorAnyDynamicArgumentParentRef=Kv,h.iterateOverObjectValuesLoopBodyActionDescriptorAnyDynamicReturn=eT,h.iterateOverObjectValuesLoopBodyActionDescriptorAnyDynamicReturnParentRef=Qv,h.iterateOverObjectValuesLoopBodyActionDescriptorCurrentValueArgumentDeclaration=gd,h.iterateOverObjectValuesLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataType=qv,h.iterateOverObjectValuesLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataTypeParentRef=Zv,h.iterateOverObjectValuesLoopBodyActionDescriptorCurrentValueArgumentDeclarationParentRef=Jv,h.iterateOverObjectValuesLoopBodyActionDescriptorIterationNumberArgumentDeclaration=Hv,h.iterateOverObjectValuesLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=zv,h.iterateOverObjectValuesLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=Wv,h.iterateOverObjectValuesLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=Yv,h.iterateOverStringActionDescriptorDynamicReturnDeclaration=Z0,h.iterateOverStringActionDescriptorDynamicReturnDeclarationParentRef=S0,h.iterateOverStringActionDescriptorStringArgumentDeclaration=k0,h.iterateOverStringActionDescriptorStringArgumentDeclarationDataType=F0,h.iterateOverStringActionDescriptorStringArgumentDeclarationDataTypeParentRef=G0,h.iterateOverStringActionDescriptorStringArgumentDeclarationParentRef=x0,h.iterateOverStringLoopActionDescriptor=Ms,h.iterateOverStringLoopBodyActionDescriptor=so,h.iterateOverStringLoopBodyActionDescriptorAnyDynamicArgument=X0,h.iterateOverStringLoopBodyActionDescriptorAnyDynamicArgumentParentRef=K0,h.iterateOverStringLoopBodyActionDescriptorAnyDynamicReturn=ev,h.iterateOverStringLoopBodyActionDescriptorAnyDynamicReturnParentRef=Q0,h.iterateOverStringLoopBodyActionDescriptorCurrentValueArgumentDeclaration=Md,h.iterateOverStringLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataType=J0,h.iterateOverStringLoopBodyActionDescriptorCurrentValueArgumentDeclarationDataTypeParentRef=q0,h.iterateOverStringLoopBodyActionDescriptorCurrentValueArgumentDeclarationParentRef=W0,h.iterateOverStringLoopBodyActionDescriptorIterationNumberArgumentDeclaration=Nd,h.iterateOverStringLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataType=Y0,h.iterateOverStringLoopBodyActionDescriptorIterationNumberArgumentDeclarationDataTypeParentRef=z0,h.iterateOverStringLoopBodyActionDescriptorIterationNumberArgumentDeclarationParentRef=H0,h.joinListOperation=Id,h.joinListOperationError=Wy,h.joinListOperationErrorParentRef=Jy,h.joinListOperationFirstListArgument=xy,h.joinListOperationFirstListArgumentParentRef=Fy,h.joinListOperationFirstListArgumentRef=Ly,h.joinListOperationFirstListDataType=Uy,h.joinListOperationResultListDataType=Gy,h.joinListOperationResultListReturn=qy,h.joinListOperationResultListReturnParentRef=Zy,h.joinListOperationResultListReturnRef=$y,h.joinListOperationSecondListArgument=Sy,h.joinListOperationSecondListArgumentParentRef=ky,h.joinListOperationSecondListArgumentRef=gy,h.joinListOperationSecondListDataType=jy,h.joinListWithLastSeparator=ne,h.joinStringsOperation=Vs,h.joinStringsOperationDynamicStringArgument=fy,h.joinStringsOperationDynamicStringArgumentParentRef=cy,h.joinStringsOperationDynamicStringArgumentRef=uy,h.joinStringsOperationDynamicStringDataType=py,h.joinStringsOperationError=dy,h.joinStringsOperationErrorParentRef=ly,h.joinStringsOperationFirstStringArgument=Wa,h.joinStringsOperationFirstStringArgumentParentRef=Qf,h.joinStringsOperationFirstStringArgumentRef=Wf,h.joinStringsOperationFirstStringDataType=zf,h.joinStringsOperationResultStringDataType=Xf,h.joinStringsOperationResultStringReturn=Cs,h.joinStringsOperationResultStringReturnParentRef=oy,h.joinStringsOperationResultStringReturnRef=Kf,h.joinStringsOperationSecondStringArgument=za,h.joinStringsOperationSecondStringArgumentParentRef=ay,h.joinStringsOperationSecondStringArgumentRef=Yf,h.joinStringsOperationSecondStringDataType=Hf,h.joinStringsOperationSeparatorStringArgument=sy,h.joinStringsOperationSeparatorStringArgumentParentRef=ny,h.joinStringsOperationSeparatorStringArgumentRef=ey,h.joinStringsOperationSeparatorStringDataType=ry,h.joinStringsOperationSeparatorStringDataTypeDefaultValue=iy,h.joinStringsOperationSeparatorStringDataTypeDefaultValueParentRef=ty,h.keyValuePrototype=Fn,h.literalValudValidation=q7,h.loopValidation=B7,h.lowercaseFirstLetter=_l,h.manualFlowActionDescriptorDeclarationArgumentDeclaration=_d,h.manualFlowActionDescriptorDeclarationArgumentDeclarationDataType=M0,h.manualFlowActionDescriptorDeclarationArgumentDeclarationDataTypeParentRef=_0,h.manualFlowActionDescriptorDeclarationArgumentDeclarationParentRef=N0,h.manualFlowLoopActionDescriptor=ro,h.manualFlowLoopActionDescriptorDynamicReturnDeclaration=B0,h.manualFlowLoopActionDescriptorDynamicReturnDeclarationParentRef=V0,h.manualFlowLoopBodyActionDescriptor=no,h.manualFlowLoopBodyActionDescriptorAnyDynamicArgument=U0,h.manualFlowLoopBodyActionDescriptorAnyDynamicArgumentParentRef=L0,h.manualFlowLoopBodyActionDescriptorAnyDynamicReturn=j0,h.manualFlowLoopBodyActionDescriptorAnyDynamicReturnParentRef=g0,h.mapActionDescriptorToTypeItRepresents=BJ,h.mergeEntityErrorsList=_3,h.mergeListOfEntities=CJ,h.methodDefaultValue=e0,h.mockClientProject=lp,h.moreThanOrEqualCondition=Yn,h.moreThanOrEqualConditionLeftHandArgument=zI,h.moreThanOrEqualConditionLeftHandArgumentDataType=JI,h.moreThanOrEqualConditionLeftHandArgumentDataTypeParentRef=qI,h.moreThanOrEqualConditionLeftHandArgumentParentRef=WI,h.moreThanOrEqualConditionRightHandArgument=XI,h.moreThanOrEqualConditionRightHandArgumentDataType=HI,h.moreThanOrEqualConditionRightHandArgumentDataTypeParentRef=YI,h.moreThanOrEqualConditionRightHandArgumentParentRef=KI,h.notEmptyCondition=fn,h.notEmptyConditionArgument=SI,h.notEmptyConditionRef=kI,h.nullPrototype=pd,h.numberAdditionOperation=Ja,h.numberAdditionOperationDynamicSummandArgument=Vf,h.numberAdditionOperationDynamicSummandArgumentType=Cf,h.numberAdditionOperationDynamicSummandArgumentTypeParentRef=wf,h.numberAdditionOperationError=Pf,h.numberAdditionOperationErrorParentRef=Of,h.numberAdditionOperationFirstNumberArgument=cd,h.numberAdditionOperationFirstNumberArgumentRef=vf,h.numberAdditionOperationFirstNumberDataType=Tf,h.numberAdditionOperationRef=Rf,h.numberAdditionOperationRefThree=yd,h.numberAdditionOperationRefTwo=Df,h.numberAdditionOperationResultNumberDataType=bf,h.numberAdditionOperationResultNumberReturn=hd,h.numberAdditionOperationResultNumberReturnRef=Af,h.numberAdditionOperationSecondNumberArgument=fd,h.numberAdditionOperationSecondNumberArgumentRef=If,h.numberAdditionOperationSecondNumberDataType=Ef,h.numberPrototype=ve,h.numberSubtractionOperation=vd,h.numberSubtractionOperationDynamicSubtrahendArgument=qf,h.numberSubtractionOperationDynamicSubtrahendArgumentType=Zf,h.numberSubtractionOperationDynamicSubtrahendArgumentTypeParentRef=Sf,h.numberSubtractionOperationError=kf,h.numberSubtractionOperationErrorParentRef=xf,h.numberSubtractionOperationFirstNumberArgument=gf,h.numberSubtractionOperationFirstNumberArgumentRef=Bf,h.numberSubtractionOperationFirstNumberDataType=_f,h.numberSubtractionOperationRef=md,h.numberSubtractionOperationRefThree=Gf,h.numberSubtractionOperationRefTwo=jf,h.numberSubtractionOperationResultNumberDataType=Uf,h.numberSubtractionOperationResultNumberReturn=Ff,h.numberSubtractionOperationResultNumberReturnRef=Lf,h.numberSubtractionOperationSecondNumberArgument=$f,h.numberSubtractionOperationSecondNumberArgumentRef=Mf,h.numberSubtractionOperationSecondNumberDataType=Nf,h.numberValueAutogenerationSchema=cp,h.operationValidation=P7,h.outputMapValidation=x7,h.parallelExecutionOperation=Oi,h.parallelExecutionOperationError=Xh,h.parallelExecutionOperationErrorParentRef=Kh,h.parallelExecutionOperationListOfExecutionResultsDataType=zh,h.parallelExecutionOperationListOfExecutionResultsReturn=Pd,h.parallelExecutionOperationListOfExecutionResultsReturnRef=Wh,h.parallelExecutionOperationListOfFunctionsArgument=Od,h.parallelExecutionOperationListOfFunctionsArgumentDatatype=Jh,h.parallelExecutionOperationListOfFunctionsArgumentRef=qh,h.parallelExecutionOperationListOfFunctionsBlueprint=Zh,h.parallelExecutionOperationListOfFunctionsBlueprintDynamicInput=kh,h.parallelExecutionOperationListOfFunctionsBlueprintDynamicInputParentRef=xh,h.parallelExecutionOperationListOfFunctionsBlueprintDynamicOutput=Fh,h.parallelExecutionOperationListOfFunctionsBlueprintDynamicOutputParentRef=Gh,h.parallelExecutionOperationListOfFunctionsBlueprintParentRef=Sh,h.parallelExecutionOperationRef=Yh,h.parallelExecutionOperationRefThree=Hh,h.persistedBuiltInBaseEntity=Ct,h.persistedBuiltInBaseEntityDatabaseProperty=Jn,h.persistedBuiltInBaseEntityDatabasePropertyDataType=RI,h.persistedBuiltInBaseEntityDatabasePropertyDataTypeRef=Rw,h.persistedBuiltInBaseEntityDatabasePropertyParentRef=DI,h.persistedBuiltInBaseEntityDatabasePropertyRef=bI,h.persistedBuiltInBaseEntityPrimaryKeyProperty=Wn,h.persistedBuiltInBaseEntityPrimaryKeyPropertyDataType=MI,h.persistedBuiltInBaseEntityPrimaryKeyPropertyNumberDataTypeOption=PI,h.persistedBuiltInBaseEntityPrimaryKeyPropertyNumberDataTypeOptionParentRef=OI,h.persistedBuiltInBaseEntityPrimaryKeyPropertyParentRef=NI,h.persistedBuiltInBaseEntityPrimaryKeyPropertyRef=_I,h.persistedBuiltInBaseEntityPrimaryKeyPropertyStringDataTypeOption=CI,h.persistedBuiltInBaseEntityPrimaryKeyPropertyStringDataTypeOptionParentRef=wI,h.persistedBuiltInBaseEntityPrimaryKeyPropertyUUIDDataTypeOption=BI,h.persistedBuiltInBaseEntityPrimaryKeyPropertyUUIDDataTypeOptionParentRef=VI,h.processOutputGlobalValueDescriptorDataType=sE,h.processOutputGlobalValueDescriptorReturn=mo,h.processOutputGlobalValueDescriptorReturnRef=nE,h.projectPublicationCompletedGlobalEvent=ho,h.propertyToZodSchema=bE,h.propertyValidation=y7,h.relationalDatabaseBuiltInBaseEntity=ji,h.relationalDatabaseBuiltInBaseEntityAutoscalingProperty=Kd,h.relationalDatabaseBuiltInBaseEntityAutoscalingPropertyDataType=TI,h.relationalDatabaseBuiltInBaseEntityAutoscalingPropertyDataTypeRef=vI,h.relationalDatabaseBuiltInBaseEntityAutoscalingPropertyParentRef=II,h.relationalDatabaseBuiltInBaseEntityAutoscalingPropertyRef=mI,h.relationalDatabaseBuiltInBaseEntityDefaultProperty=Hd,h.relationalDatabaseBuiltInBaseEntityDefaultPropertyDataType=hI,h.relationalDatabaseBuiltInBaseEntityDefaultPropertyDataTypeRef=fI,h.relationalDatabaseBuiltInBaseEntityDefaultPropertyRef=yI,h.relationalDatabaseBuiltInBaseEntityIdentifierProperty=lo,h.relationalDatabaseBuiltInBaseEntityIdentifierPropertyDataType=sI,h.relationalDatabaseBuiltInBaseEntityIdentifierPropertyDataTypeRef=rI,h.relationalDatabaseBuiltInBaseEntityIdentifierPropertyRef=nI,h.relationalDatabaseBuiltInBaseEntityMinSizeProperty=co,h.relationalDatabaseBuiltInBaseEntityMinSizePropertyDataType=cI,h.relationalDatabaseBuiltInBaseEntityMinSizePropertyDataTypeRef=uI,h.relationalDatabaseBuiltInBaseEntityMinSizePropertyRef=pI,h.relationalDatabaseBuiltInBaseEntityPasswordProperty=po,h.relationalDatabaseBuiltInBaseEntityPasswordPropertyDataType=dI,h.relationalDatabaseBuiltInBaseEntityPasswordPropertyDataTypeRef=bw,h.relationalDatabaseBuiltInBaseEntityPasswordPropertyRef=lI,h.relationalDatabaseBuiltInBaseEntityRef=qn,h.relationalDatabaseBuiltInBaseEntityUsernameProperty=uo,h.relationalDatabaseBuiltInBaseEntityUsernamePropertyDataType=oI,h.relationalDatabaseBuiltInBaseEntityUsernamePropertyDataTypeRef=Aw,h.relationalDatabaseBuiltInBaseEntityUsernamePropertyRef=aI,h.resolveActionDescriptorName=KO,h.resolveBaseEntityName=WO,h.resolveBuiltInBaseEntityDataTypeLabel=zO,h.resolveClonedEntityProject=mt,h.resolveConditionOperatorLabel=Ul,h.resolveDataType=Ml,h.resolveDataTypeEntityOrNestedChildrenFromLiteralValue=Zc,h.resolveDataTypeLabel=Ll,h.resolveDefinitionEntityDataTypeLabel=c7,h.resolveEntityDataTypeLabel=p7,h.resolveEntityName=x,h.resolveFirstCallsSecond=mJ,h.resolveFirstWritesSecond=vJ,h.resolvePrimaryKeyProperty=NJ,h.resolvePrimitiveEntityName=HO,h.resolveSearchName=YO,h.resolveVariableScope=l7,h.returnDeclarationValidation=v7,h.returnStatementValidation=T7,h.searchValidation=U7,h.sequentialExecutionOperation=nr,h.sequentialExecutionOperationError=Tm,h.sequentialExecutionOperationErrorParentRef=vm,h.sequentialExecutionOperationListOfExecutionResultsDataType=ym,h.sequentialExecutionOperationListOfExecutionResultsReturn=Cd,h.sequentialExecutionOperationListOfExecutionResultsReturnParentRef=mm,h.sequentialExecutionOperationListOfExecutionResultsReturnRef=fm,h.sequentialExecutionOperationListOfFunctionsArgument=wd,h.sequentialExecutionOperationListOfFunctionsArgumentDatatype=cm,h.sequentialExecutionOperationListOfFunctionsArgumentParentRef=hm,h.sequentialExecutionOperationListOfFunctionsArgumentRef=pm,h.sequentialExecutionOperationListOfFunctionsBlueprint=um,h.sequentialExecutionOperationListOfFunctionsBlueprintDynamicInput=dm,h.sequentialExecutionOperationListOfFunctionsBlueprintDynamicOutput=lm,h.softDeletePersistedEntityMethod=Dw,h.softDeletePersistedEntityMethodParentRef=LI,h.sortCallsBasedOnExecutionDependencies=nP,h.sortChildrenEntitiesBasedOnExecutionDependencies=yJ,h.splitListOperation=Ad,h.splitListOperationError=ph,h.splitListOperationErrorParentRef=uh,h.splitListOperationFirstOutputListDataType=eh,h.splitListOperationFirstOutputListReturn=ah,h.splitListOperationFirstOutputListReturnParentRef=sh,h.splitListOperationFirstOutputListReturnRef=Ed,h.splitListOperationInputListArgument=ih,h.splitListOperationInputListArgumentParentRef=th,h.splitListOperationInputListArgumentRef=Hy,h.splitListOperationInputListDataType=Ky,h.splitListOperationSecondOutputListDataType=oh,h.splitListOperationSecondOutputListReturn=dh,h.splitListOperationSecondOutputListReturnParentRef=lh,h.splitListOperationSplitIndexArgument=nh,h.splitListOperationSplitIndexArgumentParentRef=rh,h.splitListOperationSplitIndexArgumentRef=Xy,h.splitListOperationSplitIndexDataType=Qy,h.splitStringOperation=Td,h.splitStringOperationError=By,h.splitStringOperationErrorParentRef=Vy,h.splitStringOperationFirstPartResultStringDataType=Iy,h.splitStringOperationFirstPartResultStringReturn=Cy,h.splitStringOperationFirstPartResultStringReturnParentRef=wy,h.splitStringOperationFirstPartResultStringReturnRef=Ty,h.splitStringOperationIndexArgument=Oy,h.splitStringOperationIndexArgumentParentRef=Dy,h.splitStringOperationIndexArgumentRef=my,h.splitStringOperationIndexDataType=vy,h.splitStringOperationSecondPartResultStringDataType=Ay,h.splitStringOperationSecondPartResultStringReturn=Iw,h.splitStringOperationSecondPartResultStringReturnParentRef=Py,h.splitStringOperationSecondPartResultStringReturnRef=Ey,h.splitStringOperationStringArgument=Ry,h.splitStringOperationStringArgumentParentRef=by,h.splitStringOperationStringArgumentRef=yy,h.splitStringOperationStringDataType=hy,h.stringPrototype=se,h.stringValueAutogenerationSchema=pp,h.suggestNewIdForEntity=Oc,h.test_primitive_entities_export=BW,h.toCamelCase=d7,h.toEntityState=mi,h.toKebabCase=JO,h.toLowerCaseKebabCase=Nl,h.toPascalCase=u7,h.untypedDataPrototype=Ot,h.updateErrorsList=He,h.urlDefaultValue=zm,h.uuidPrototype=ir,h.validateArgumentDeclarationName=Rc,h.validateCalledByErrorIdInAction=tJ,h.validateCalledByIdInAction=eJ,h.validateCallers=Z1,h.validateConditionEntityDeclaration=nJ,h.validateDataOperation=ln,h.validateDataOperationDataToValidateArgument=jm,h.validateDataOperationDataToValidateArgumentParentRef=gm,h.validateDataOperationDataToValidateArgumentRef=Lm,h.validateDataOperationDataToValidateDataType=Um,h.validateDataOperationEntityToMatchTypeArgument=xm,h.validateDataOperationEntityToMatchTypeArgumentParentRef=Fm,h.validateDataOperationEntityToMatchTypeArgumentRef=$m,h.validateDataOperationEntityToMatchTypeDataType=Gm,h.validateDataOperationError=qm,h.validateDataOperationErrorParentRef=Zm,h.validateDataOperationOutputEntityDeclaration=Sm,h.validateDataOperationOutputEntityDeclarationParentRef=km,h.validateDefinitionEntityName=Ic,h.validateEntryCaller=S1,h.validateErrorCaller=k1,h.validateFunctionCallDeclaration=J1,h.validateFunctionDeclarationName=Ec,h.validateGeneratedEntityParentIsNotBuiltInEntity=H7,h.validateGeneration=z7,h.validateGenerationTarget=ut,h.validateGenerationUpdate=Y7,h.validateLoopEntityDeclaration=sJ,h.validateName=f7,h.validateOperationEntityDeclaration=W1,h.validatePropertyName=bc,h.validateReachability=vr,h.validateReadsValueInActionPayload=iJ,h.validateReferenceObject=$l,h.validateReferenceToOne=Lc,h.validateReferences=At,h.validateReturnDeclarationName=Dc,h.validateSuccessCaller=x1,h.validateValueReaderGenerationUpdate=_a,h.validateValueWritter=Fc,h.validateVariableDeclarationName=Ac,h.validateVariableInternalCallUse=xc,h.valueAutogenerationCurrentDateAndTimeSchema=nD,h.valueAutogenerationGenericSchema=nl,h.valueAutogenerationOptions=yp,h.valueAutogenerationOptionsSchema=rD,h.valueAutogenerationRandomBooleanSchema=up,h.valueAutogenerationRandomDateBetweenSchema=fD,h.valueAutogenerationRandomDateFromSchema=pD,h.valueAutogenerationRandomDateSchema=ol,h.valueAutogenerationRandomDateUntilSchema=cD,h.valueAutogenerationRandomNumberBetweenSchema=oD,h.valueAutogenerationRandomNumberFromSchema=sD,h.valueAutogenerationRandomNumberSchema=sl,h.valueAutogenerationRandomNumberUntilSchema=aD,h.valueAutogenerationRandomSchema=fa,h.valueAutogenerationRandomTextBetweenSchema=uD,h.valueAutogenerationRandomTextFromSchema=lD,h.valueAutogenerationRandomTextSchema=al,h.valueAutogenerationRandomTextUntilSchema=dD,h.valueAutogenerationRangeValueTypesSchema=ca,h.valueAutogenerationUniqueSchema=dp,h.valueDescriptorValidation=W7,h.variableDeclarationValidation=N7,h.variableInstanceValidation=L7,h.waitOperation=qt,h.waitOperationMillisecondsNumberArgument=an,h.waitOperationMillisecondsNumberArgumentRef=tm,h.waitOperationMillisecondsNumberDataType=im,h.waitOperationOperationError=sm,h.waitOperationOperationErrorParentRef=nm,h.waitOperationRef=rm,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});